
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
slate-vue3
Advanced tools
slate-react library implemented with vue3
npm install slate-vue3
<script setup lang="ts">
import { withDOM, Slate, Editable, defaultRenderLeaf, defaultRenderPlaceHolder, createEditor, withHistory } from "slate-vue3"
import { h } from "vue"
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
export 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: Descendant[]) => void
slate children change in slate will trigger it
const onvaluechange: (event: Descendant[]) => void
slate selection change in slate will trigger it
const onselectionchange: (event: Selection) => 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
rewrite implement for WeakMap
import types from globalThis in slate-dom
other compact
FAQs
slate-react library implemented with vue3
The npm package slate-vue3 receives a total of 100 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.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.