slate-vue3 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,235 +17,73 @@
17
17
  </p>
18
18
  <br/>
19
19
 
20
-
21
20
  # Why use it?
22
- 1. :sparkles: Highly customizable features, use slate core at the bottom level
23
- 2. :zap: The latest version of the core, use vue to reduce the number of re-renderings
21
+
22
+ 1. :sparkles: Highly customizable features, use slate core at the bottom level
23
+ 2. :zap: The latest version of the core, use vue to reduce the number of re-renderings
24
24
  3. :coffee: This library provides the same usage as slate-react, design tends to be stable
25
- 4. :point_right: Check out the [**live demo**](https://guan-erjia.github.io/slate-vue3/) of all of the examples
25
+ 4. :point_right: Check out the [**live demo**](https://guan-erjia.github.io/slate-vue3/examples) of all of the examples
26
26
 
27
27
  # How to use?
28
28
 
29
29
  ## 1. Install slate-vue3
30
+
30
31
  ```sh
31
32
  npm install slate-vue3
32
33
  ```
33
- ## 2. Now, you can use it in vue-sfc :point_right: [**live demo**](https://guan-erjia.github.io/slate-vue3/)
34
+
35
+ ## 2. Now, you can use it in vue-sfc :point_right: [**live demo**](https://guan-erjia.github.io/slate-vue3/examples/rich-text)
36
+
34
37
  ```vue
35
38
  <script setup lang="ts">
36
- import { h } from "vue"
37
- import { Slate, Editable, defaultRenderLeaf, defaultRenderPlaceHolder } from "slate-vue3"
38
- import { createEditor } from "slate-vue3/core"
39
- import { withDOM } from "slate-vue3/dom"
40
- import { withHistory } from "slate-vue3/history"
39
+ import { h } from "vue";
40
+ import {
41
+ Slate,
42
+ Editable,
43
+ defaultRenderLeaf,
44
+ defaultRenderPlaceHolder,
45
+ } from "slate-vue3";
46
+ import { createEditor } from "slate-vue3/core";
47
+ import { withDOM } from "slate-vue3/dom";
48
+ import { withHistory } from "slate-vue3/history";
41
49
 
42
50
  const initialValue = [
43
51
  {
44
52
  type: "paragraph",
45
- children: [{ text: "Let's start"}]
46
- }
47
- ]
48
- const renderElement = ({ attributes, children }) => h("p", attributes, children)
49
- const editor = withHistory(withDOM(createEditor(initialValue)))
53
+ children: [{ text: "Let's start" }],
54
+ },
55
+ ];
56
+ const renderElement = ({ attributes, children }) =>
57
+ h("p", attributes, children);
58
+ const editor = withHistory(withDOM(createEditor()));
59
+ editor.children = initialValue;
50
60
  </script>
51
61
 
52
62
  <template>
53
- <Slate :editor="editor" :render-element="renderElement" :render-leaf="defaultRenderLeaf"
54
- :render-placeholder="defaultRenderPlaceHolder">
63
+ <Slate
64
+ :editor="editor"
65
+ :render-element="renderElement"
66
+ :render-leaf="defaultRenderLeaf"
67
+ :render-placeholder="defaultRenderPlaceHolder"
68
+ >
55
69
  <Editable />
56
70
  </Slate>
57
71
  </template>
58
72
  ```
59
73
 
60
- # Component Props
61
- ## Slate
62
- ### editor
63
- > slate-editor instance, add DOM specific behaviors to the editor
64
- ```typescript
65
- const initialValue: Descendant[] = [{
66
- type: 'paragraph',
67
- children: [ { text: 'This is editable plain text, just like a <textarea>!' } ]
68
- }]
69
- const editor: DOMEditor = withDOM(createEditor(initialValue))
70
- ```
71
-
72
- ### decorate
73
- > another type of text-level formatting, split text into leaves
74
- ```typescript
75
- function (entry: NodeEntry) => DecoratedRange[]
76
- ```
77
-
78
- ### renderElement
79
- > a function used to render a custom component for a specific type of Element node in the Slate.js document model
80
- ```typescript
81
- export interface RenderElementProps {
82
- children: VNode
83
- element: Element
84
- attributes: HTMLAttributes & {
85
- "data-slate-node": "element"
86
- "data-slate-inline"?: true
87
- "data-slate-void"?: true
88
- dir?: "rtl"
89
- ref: any
90
- };
91
- }
92
-
93
- function renderElement (props: RenderElementProps) => VNode
94
- ```
95
-
96
- ### renderLeaf
97
- > customize the rendering of leaf nodes in the document tree of your Slate editor
98
- ```typescript
99
- export interface RenderLeafProps {
100
- children: VNode
101
- leaf: Text
102
- text: Text
103
- attributes: HTMLAttributes & {
104
- "data-slate-leaf": true
105
- };
106
- }
107
- ```
108
-
109
- ### renderPlaceholder
110
- > customize how the placeholder of the Slate.js Editable component is rendered when the editor is empty
111
- ```typescript
112
- export interface RenderPlaceholderProps {
113
- children?: string
114
- attributes: HTMLAttributes & VNodeProps & {
115
- "data-slate-placeholder": boolean
116
- dir?: "rtl"
117
- };
118
- }
119
- ```
120
-
121
- ## Editable
122
- > customize style of editablearea, you can inherient other HTMLAttribute on it
123
- ```typescript
124
- interface EditableProps extends HTMLAttributes {
125
- role?: string
126
- readOnly: boolean
127
- placeholder?: string
128
- style?: CSSProperties
129
- scrollSelectionIntoView: (
130
- editor: DOMEditor,
131
- domRange: globalThis.Range
132
- ) => void
133
- is: string
134
- }
135
- ```
136
-
137
- # Component Emits
138
-
139
- ## onchange
140
- > any change in slate will trigger it
141
- ```typescript
142
- const onchange: (event: { operation?: Operation }) => void
143
- ```
144
-
145
- ## onvaluechange
146
- > slate children change in slate will trigger it
147
- ```typescript
148
- const onvaluechange: (event: { operation?: Operation }) => void
149
- ```
150
-
151
- ## onselectionchange
152
- > slate selection change in slate will trigger it
153
- ```typescript
154
- const onselectionchange: (event: { operation?: Operation }) => void
155
- ```
156
-
157
- # Hooks in slate-vue3
158
-
159
- ## [useComposing](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-composing.ts)
160
- > Get the current composing state of the editor. It deals with compositionstart, compositionupdate, compositionend events
161
- ```typescript
162
- const useComposing: () => Ref<boolean, boolean>
163
-
164
- const composing = useComposing()
165
- ```
166
-
167
- ## [useFocused](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-focus.ts)
168
- > Get the current focused state of the editor
169
- ```typescript
170
- const useFocused: () => Ref<boolean, boolean>
171
-
172
- const focused = useFocused()
173
- ```
174
-
175
- ## [useReadOnly](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-read-only.ts)
176
- > Get the current readOnly state of the editor
177
- ```typescript
178
- const useReadOnly: () => Ref<boolean, boolean>
179
-
180
- const readonly = useReadOnly()
181
- ```
182
-
183
- ## [useSelected](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selected.ts)
184
- > Get the current selected state of an element
185
- ```typescript
186
- const useSelected: () => ComputedRef<boolean>
187
-
188
- const selected = useSelected()
189
- ```
190
-
191
- ## [useEditor](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-editor.ts)
192
- > Get the current editor object from the context. Context whenever changes occur in the editor
193
- ```typescript
194
- const useEditor: () => DOMEditor
195
-
196
- const editor = useEditor()
197
- ```
198
-
199
- ## [useSelection](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selection.ts)
200
- > Get the current editor selection from the context
201
-
202
- ```typescript
203
- const useSelection: () => ComputedRef<BaseSelection>
204
-
205
- const selection = useSelection()
206
- ```
207
-
208
-
209
- ## [useInheritRef](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-inherit-ref.ts)
210
- > Automatically bind ref to the real node when the component is mounted,This is important when rendering element nodes directly
211
- ```typescript
212
- const useInheritRef: (attribute: VNodeProps) => VNodeProps
213
-
214
- const renderElement = (props: RenderElementProps) => {
215
- const { attributes, children, element } = props
216
- switch (element.type) {
217
- case 'image':
218
- return h(ImageComp, { element, ...useInheritRef(attributes) }, () => children)
219
- default:
220
- return h('p', attributes, children)
221
- }
222
- }
223
- ```
224
-
225
74
  # FAQ
75
+
226
76
  ### 1. Why do I have to pass renderFunction into <Slate /> component ?
227
- 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
77
+
78
+ This ensures that your rich text is as expected, and slate-vue3 provides some default rendering functions, you can directly use the default rendering behavior
228
79
 
229
80
  ### 2. Can I use jsx in slate-vue3 ?
81
+
230
82
  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
231
83
 
232
84
  ### 3. Why do rendering functions not use Vue components ?
233
- 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
234
-
235
- # Directory Structure
236
85
 
237
- - [slate](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate)
238
- slate core logic, update synchronously with slate
239
- - [slate-dom](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-dom)
240
- Implementation of slate on dom, update synchronously with slate-dom
241
- - [slate-vue](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-vue)
242
- Vue components for rendering slate editors
243
- - [slate-history](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-history)
244
- Same with slate-history
245
- - [slate-hyperscript](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-hyperscript)
246
- Same with slate-history
247
- - [share-tools](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/share-tools)
248
- for special processing of Proxy data, obtain the raw pointer, isPlainObject declare
86
+ 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
249
87
 
250
88
  # Compact Slate
251
89
 
package/dist/core.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a6, a7, a8, d, e, f, a, h, aj, c, i, j, k, ap, ak, l, m, o, p, q, g, b, r, t, u, v, w, x, aq, y, a9, z, A, B, C, D, E, F, G, H, I, J, aa, K, ab, al, ac, L, M, N, O, n, P, S, Q, R, V, T, U, W, X, _, Y, Z, $, ad, am, ae, a0, an, ao, a5, s, af, a1, a2, a3, ag, ah, a4, ai } from "./create-editor-BFFWnObb.js";
1
+ import { a6, a7, a8, d, e, f, a, h, aj, c, i, j, k, ap, ak, l, m, o, p, q, g, b, r, t, u, v, w, x, aq, y, a9, z, A, B, C, D, E, F, G, H, I, J, aa, K, ab, al, ac, L, M, N, O, n, P, S, Q, R, V, T, U, W, X, _, Y, Z, $, ad, am, ae, a0, an, ao, a5, s, af, a1, a2, a3, ag, ah, a4, ai } from "./create-editor-C4ZucdMc.js";
2
2
  import { E as E2, a as a10, N as N2, O as O2, P as P2, b as b2, R as R2, S as S2, T as T2, c as c2, i as i2 } from "./batch-dirty-paths-X-eP3GRL.js";
3
3
  import { L as L2, S as S3 } from "./location-CeJ1rJSq.js";
4
4
  export {
@@ -2393,9 +2393,9 @@ const wrapNodes = (editor, element, options = {}) => {
2393
2393
  }
2394
2394
  });
2395
2395
  };
2396
- const createEditor = (children) => {
2396
+ const createEditor = () => {
2397
2397
  const editor = reactive({
2398
- children,
2398
+ children: [],
2399
2399
  operations: [],
2400
2400
  selection: null,
2401
2401
  marks: null,
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import { t as toRawWeakMap, T as Text, R as Range, N as Node, a as Element, d as isPlainObject } from "./batch-dirty-paths-X-eP3GRL.js";
5
- import { c as createEditor$1 } from "./create-editor-BFFWnObb.js";
5
+ import { c as createEditor$1 } from "./create-editor-C4ZucdMc.js";
6
6
  import "vue";
7
7
  const ANCHOR = new toRawWeakMap();
8
8
  const FOCUS = new toRawWeakMap();
@@ -155,7 +155,7 @@ const createEditor = (makeEditor) => (tagName, attributes, children) => {
155
155
  }
156
156
  const descendants = resolveDescendants(otherChildren);
157
157
  const selection = {};
158
- const editor = makeEditor(descendants);
158
+ const editor = makeEditor();
159
159
  Object.assign(editor, attributes);
160
160
  editor.children = descendants;
161
161
  for (const [node, path] of Node.texts(editor)) {
@@ -1,5 +1,5 @@
1
- import { Editor, Descendant } from './';
1
+ import { Editor } from './';
2
2
  /**
3
3
  * Create a new Slate `Editor` object.
4
4
  */
5
- export declare const createEditor: (children: Descendant[]) => Editor;
5
+ export declare const createEditor: () => Editor;
@@ -45,6 +45,6 @@ export declare function createText(tagName: string, attributes: {
45
45
  /**
46
46
  * Create a top-level `Editor` object.
47
47
  */
48
- export declare const createEditor: (makeEditor: (desc: Descendant[]) => Editor) => (tagName: string, attributes: {
48
+ export declare const createEditor: (makeEditor: () => Editor) => (tagName: string, attributes: {
49
49
  [key: string]: any;
50
50
  }, children: any[]) => Editor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slate-vue3",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -67,11 +67,9 @@
67
67
  "vue": "^3.5.13"
68
68
  },
69
69
  "devDependencies": {
70
+ "@faker-js/faker": "^9.6.0",
70
71
  "@liveblocks/client": "^2.21.0",
71
72
  "@liveblocks/yjs": "^2.21.0",
72
- "y-protocols": "^1.0.6",
73
- "yjs": "^13.6.24",
74
- "@faker-js/faker": "^9.6.0",
75
73
  "@playwright/test": "^1.50.1",
76
74
  "@testing-library/vue": "^8.1.0",
77
75
  "@types/is-hotkey": "^0.1.10",
@@ -84,11 +82,17 @@
84
82
  "is-url": "^1.2.4",
85
83
  "jsdom": "^26.0.0",
86
84
  "prismjs": "^1.30.0",
85
+ "remark-gfm": "^4.0.1",
86
+ "remark-parse": "^11.0.0",
87
+ "remark-slate-transformer": "^0.9.0",
87
88
  "typescript": "~5.8.2",
89
+ "unified": "^11.0.5",
88
90
  "vite": "^6.2.3",
89
91
  "vite-plugin-dts": "^4.5.0",
90
92
  "vitest": "^3.0.5",
91
- "vue-router": "^4.5.0"
93
+ "vue-router": "^4.5.0",
94
+ "y-protocols": "^1.0.6",
95
+ "yjs": "^13.6.24"
92
96
  },
93
97
  "publishConfig": {
94
98
  "registry": "https://registry.npmjs.org/"
@@ -97,6 +101,7 @@
97
101
  "type": "git",
98
102
  "url": "git+https://github.com/Guan-Erjia/slate-vue3.git"
99
103
  },
104
+ "homepage": "https://guan-erjia.github.io/slate-vue3",
100
105
  "keywords": [
101
106
  "slate-vue3",
102
107
  "slate-vue",