
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
slate-vue3
Advanced tools
slate-react library implemented with vue3
npm install slate-vue3
<script setup lang="ts">
import { h } from "vue"
import { Slate, Editable, defaultRenderLeaf, defaultRenderPlaceHolder } from "slate-vue3"
import { createEditor } from "slate-vue3/core"
import { withDOM } from "slate-vue3/dom"
import { withHistory } from "slate-vue3/history"
const initialValue = [
{
type: "paragraph",
children: [{ text: "Let's start"}]
}
]
const renderElement = ({ attributes, children }) => h("p", attributes, children)
const editor = withHistory(withDOM(createEditor(initialValue)))
</script>
<template>
<Slate :editor="editor" :render-element="renderElement" :render-leaf="defaultRenderLeaf"
:render-placeholder="defaultRenderPlaceHolder">
<Editable />
</Slate>
</template>
slate-editor instance, add DOM specific behaviors to the editor
const initialValue: Descendant[] = [{
type: 'paragraph',
children: [ { text: 'This is editable plain text, just like a <textarea>!' } ]
}]
const editor: DOMEditor = withDOM(createEditor(initialValue))
another type of text-level formatting, split text into leaves
function (entry: NodeEntry) => DecoratedRange[]
a function used to render a custom component for a specific type of Element node in the Slate.js document model
export interface RenderElementProps {
children: VNode
element: Element
attributes: HTMLAttributes & {
"data-slate-node": "element"
"data-slate-inline"?: true
"data-slate-void"?: true
dir?: "rtl"
ref: any
};
}
function renderElement (props: RenderElementProps) => VNode
customize the rendering of leaf nodes in the document tree of your Slate editor
export interface RenderLeafProps {
children: VNode
leaf: Text
text: Text
attributes: HTMLAttributes & {
"data-slate-leaf": true
};
}
customize how the placeholder of the Slate.js Editable component is rendered when the editor is empty
export interface RenderPlaceholderProps {
children?: string
attributes: HTMLAttributes & VNodeProps & {
"data-slate-placeholder": boolean
dir?: "rtl"
};
}
customize style of editablearea, you can inherient other HTMLAttribute on it
interface EditableProps extends HTMLAttributes {
role?: string
readOnly: boolean
placeholder?: string
style?: CSSProperties
scrollSelectionIntoView: (
editor: DOMEditor,
domRange: globalThis.Range
) => void
is: string
}
any change in slate will trigger it
const onchange: (event: { operation?: Operation }) => void
slate children change in slate will trigger it
const onvaluechange: (event: { operation?: Operation }) => void
slate selection change in slate will trigger it
const onselectionchange: (event: { operation?: Operation }) => void
Get the current composing state of the editor. It deals with compositionstart, compositionupdate, compositionend events
const useComposing: () => Ref<boolean, boolean>
const composing = useComposing()
Get the current focused state of the editor
const useFocused: () => Ref<boolean, boolean>
const focused = useFocused()
Get the current readOnly state of the editor
const useReadOnly: () => Ref<boolean, boolean>
const readonly = useReadOnly()
Get the current selected state of an element
const useSelected: () => ComputedRef<boolean>
const selected = useSelected()
Get the current editor object from the context. Context whenever changes occur in the editor
const useEditor: () => DOMEditor
const editor = useEditor()
Get the current editor selection from the context
const useSelection: () => ComputedRef<BaseSelection>
const selection = useSelection()
Automatically bind ref to the real node when the component is mounted,This is important when rendering element nodes directly
const useInheritRef: (attribute: VNodeProps) => VNodeProps & {
inheritRef?: VNodeRef
};
const renderElement = (props: RenderElementProps) => {
const { attributes, children, element } = props
switch (element.type) {
case 'image':
return h(ImageComp, { element, ...useInheritRef(attributes) }, () => children)
default:
return h('p', attributes, children)
}
}
This ensures that your rich text is as expected, and slave-vue3 provides some default rendering functions, you can directly use the default rendering behavior
Of coures yes, but we do not recommend it unless you have already configured jsx in the project, as a branch, using the h function directly is already simple enough
Vue uses lazy updates, rendering with components generates additional state, which can cause unexpected results during updates, it would be better to use functions as branches directly
reactive implement
remove immer
other compact
FAQs
slate-react library implemented with vue3
The npm package slate-vue3 receives a total of 112 weekly downloads. As such, slate-vue3 popularity was classified as not popular.
We found that slate-vue3 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.