slate-vue3 0.0.25 → 0.0.26

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/License.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Guan-Erjia
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Guan-Erjia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,277 +1,277 @@
1
- [<img src="https://github.com/Guan-Erjia/slate-vue3/blob/master/public/banner.png" />](https://github.com/ianstormtaylor/slate)
2
-
3
- <p align="center">
4
- slate-<a style="color: #087ea4" href="https://react.dev/">react</a> library implemented with <a style="color: #42b883" href="https://vuejs.org/">vue3</a>
5
- </p>
6
-
7
- <p align="center">
8
- <a href="https://unpkg.com/slate-vue3/dist/index.js">
9
- <img src="http://img.badgesize.io/https://unpkg.com/slate-vue3/dist/index.js?compression=gzip&amp;label=size">
10
- </a>
11
- <a href="https://join.slack.com/t/slate-js/shared_invite/zt-f8t986ip-7dA1DyiqPpzootz1snKXkw">
12
- <img src="https://img.shields.io/badge/slack-slate--js-brightgreen.svg?logo=slack">
13
- </a>
14
- <a href="./packages/slate-vue3/package.json">
15
- <img src="https://img.shields.io/npm/v/slate-vue3.svg?maxAge=3600&label=version&colorB=007ec6">
16
- </a>
17
- </p>
18
- <br/>
19
-
20
-
21
- # 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
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
26
-
27
- # How to use?
28
-
29
- ## 1. Install slate-vue3
30
- ```sh
31
- npm install slate-vue3
32
- ```
33
- ## 2. Now, you can use it in vue-sfc :point_right: [**live demo**](https://guan-erjia.github.io/slate-vue3/)
34
- ```vue
35
- <script setup lang="ts">
36
- import { withDOM, Slate, Editable, defaultRenderLeaf, defaultRenderPlaceHolder, createEditor, withHistory } from "slate-vue3"
37
- import { h } from "vue"
38
-
39
- const initialValue = [
40
- {
41
- type: "paragraph",
42
- children: [{ text: "Let's start"}]
43
- }
44
- ]
45
- const renderElement = ({ attributes, children }) => h("p", attributes, children)
46
- const editor = withHistory(withDOM(createEditor(initialValue)))
47
- </script>
48
-
49
- <template>
50
- <Slate :editor="editor" :render-element="renderElement" :render-leaf="defaultRenderLeaf"
51
- :render-placeholder="defaultRenderPlaceHolder">
52
- <Editable />
53
- </Slate>
54
- </template>
55
- ```
56
-
57
- # Component Props
58
- ## Slate
59
- ### editor
60
- > slate-editor instance, add DOM specific behaviors to the editor
61
- ```typescript
62
- const initialValue: Descendant[] = [{
63
- type: 'paragraph',
64
- children: [ { text: 'This is editable plain text, just like a <textarea>!' } ]
65
- }]
66
- const editor: DOMEditor = withDOM(createEditor(initialValue))
67
- ```
68
-
69
- ### decorate
70
- > another type of text-level formatting, split text into leaves
71
- ```typescript
72
- function (entry: NodeEntry) => DecoratedRange[]
73
- ```
74
-
75
- ### renderElement
76
- > a function used to render a custom component for a specific type of Element node in the Slate.js document model
77
- ```typescript
78
- export interface RenderElementProps {
79
- children: VNode
80
- element: Element
81
- attributes: HTMLAttributes & {
82
- "data-slate-node": "element"
83
- "data-slate-inline"?: true
84
- "data-slate-void"?: true
85
- dir?: "rtl"
86
- ref: any
87
- };
88
- }
89
-
90
- function renderElement (props: RenderElementProps) => VNode
91
- ```
92
-
93
- ### renderLeaf
94
- > customize the rendering of leaf nodes in the document tree of your Slate editor
95
- ```typescript
96
- export interface RenderLeafProps {
97
- children: VNode
98
- leaf: Text
99
- text: Text
100
- attributes: HTMLAttributes & {
101
- "data-slate-leaf": true
102
- };
103
- }
104
- ```
105
-
106
- ### renderPlaceholder
107
- > customize how the placeholder of the Slate.js Editable component is rendered when the editor is empty
108
- ```typescript
109
- export interface RenderPlaceholderProps {
110
- children?: string
111
- attributes: HTMLAttributes & VNodeProps & {
112
- "data-slate-placeholder": boolean
113
- dir?: "rtl"
114
- };
115
- }
116
- ```
117
-
118
- ## Editable
119
- > customize style of editablearea, you can inherient other HTMLAttribute on it
120
- ```typescript
121
- export interface EditableProps extends HTMLAttributes {
122
- role?: string
123
- readOnly: boolean
124
- placeholder?: string
125
- style?: CSSProperties
126
- scrollSelectionIntoView: (
127
- editor: DOMEditor,
128
- domRange: globalThis.Range
129
- ) => void
130
- is: string
131
- }
132
- ```
133
-
134
- # Component Emits
135
-
136
- ## onchange
137
- > any change in slate will trigger it
138
- ```typescript
139
- const onchange: (event: Descendant[]) => void
140
- ```
141
-
142
- ## onvaluechange
143
- > slate children change in slate will trigger it
144
- ```typescript
145
- const onvaluechange: (event: Descendant[]) => void
146
- ```
147
-
148
- ## onselectionchange
149
- > slate selection change in slate will trigger it
150
- ```typescript
151
- const onselectionchange: (event: Selection) => void
152
- ```
153
-
154
- # Hooks in slate-vue3
155
-
156
- ## [useComposing](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-composing.ts)
157
- > Get the current composing state of the editor. It deals with compositionstart, compositionupdate, compositionend events
158
- ```typescript
159
- const useComposing: () => Ref<boolean, boolean>
160
-
161
- const composing = useComposing()
162
- ```
163
-
164
- ## [useFocused](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-focus.ts)
165
- > Get the current focused state of the editor
166
- ```typescript
167
- const useFocused: () => Ref<boolean, boolean>
168
-
169
- const focused = useFocused()
170
- ```
171
-
172
- ## [useReadOnly](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-read-only.ts)
173
- > Get the current readOnly state of the editor
174
- ```typescript
175
- const useReadOnly: () => Ref<boolean, boolean>
176
-
177
- const readonly = useReadOnly()
178
- ```
179
-
180
- ## [useSelected](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selected.ts)
181
- > Get the current selected state of an element
182
- ```typescript
183
- const useSelected: () => ComputedRef<boolean>
184
-
185
- const selected = useSelected()
186
- ```
187
-
188
- ## [useEditor](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-editor.ts)
189
- > Get the current editor object from the context. Context whenever changes occur in the editor
190
- ```typescript
191
- const useEditor: () => DOMEditor
192
-
193
- const editor = useEditor()
194
- ```
195
-
196
- ## [useSelection](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selection.ts)
197
- > Get the current editor selection from the context
198
-
199
- ```typescript
200
- const useSelection: () => ComputedRef<BaseSelection>
201
-
202
- const selection = useSelection()
203
- ```
204
-
205
-
206
- ## [useInheritRef](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-inherit-ref.ts)
207
- > Automatically bind ref to the real node when the component is mounted,This is important when rendering element nodes directly
208
- ```typescript
209
- const useInheritRef: (attribute: VNodeProps) => VNodeProps & {
210
- inheritRef?: VNodeRef
211
- };
212
-
213
- const renderElement = (props: RenderElementProps) => {
214
- const { attributes, children, element } = props
215
- switch (element.type) {
216
- case 'image':
217
- return h(ImageComp, { element, ...useInheritRef(attributes) }, () => children)
218
- default:
219
- return h('p', attributes, children)
220
- }
221
- }
222
- ```
223
-
224
- # FAQ
225
- ### 1. Why do I have to pass renderFunction into <Slate /> component ?
226
- 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
227
-
228
- ### 2. Can I use jsx in slate-vue3 ?
229
- 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
230
-
231
- ### 3. Why do rendering functions not use Vue components ?
232
- 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
233
-
234
- # Directory Structure
235
-
236
- - [slate](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate)
237
- slate core logic, update synchronously with slate
238
- - [slate-dom](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-dom)
239
- Implementation of slate on dom, update synchronously with slate-dom
240
- - [slate-vue](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-vue)
241
- Vue components for rendering slate editors
242
- - [slate-history](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-history)
243
- Provide undo redo functions, replace Weakmap to UnProxyWeakmap
244
- - [share-tools](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/share-tools)
245
- for special processing of Proxy data, obtain the raw pointer, isPlainObject declare
246
-
247
- # Compact Slate
248
-
249
- **reactive implement**
250
-
251
- 1. packages/slate/src/interfaces/text.ts 115:115
252
- 2. packages/slate/src/create-editor.ts 94:94
253
- 3. packages/slate/src/transforms-node/set-nodes.ts 18:18
254
- 4. packages/slate/src/interfaces/text.ts 116:116
255
-
256
- **remove immer**
257
-
258
- 1. packages/slate/src/interfaces/node.ts 365:365
259
- 2. packages/slate/src/interfaces/point.ts 103:103
260
- 3. packages/slate/src/interfaces/range.ts 224:224
261
- 4. packages/slate/src/interfaces/transforms/general.ts 322:333
262
-
263
- **rewrite implement for WeakMap**
264
-
265
- 1. packages/share-tools/index.ts
266
- 2. packages/slate-dom/src/utils/weak-maps.ts
267
-
268
- **import types from globalThis in slate-dom**
269
-
270
- 1. packages/slate-dom/src/index.ts
271
- 2. packages/slate-dom/src/plugin/dom-editor.ts
272
- 3. packages/slate-dom/src/utils/dom.ts
273
-
274
- **other compact**
275
-
276
- 1. packages/slate/src/core/normalize-node.ts
277
- 2. packages/slate-dom/src/plugin/dom-editor.ts 421:441
1
+ [<img src="https://github.com/Guan-Erjia/slate-vue3/blob/master/public/banner.png" />](https://github.com/ianstormtaylor/slate)
2
+
3
+ <p align="center">
4
+ slate-<a style="color: #087ea4" href="https://react.dev/">react</a> library implemented with <a style="color: #42b883" href="https://vuejs.org/">vue3</a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://unpkg.com/slate-vue3/dist/index.js">
9
+ <img src="http://img.badgesize.io/https://unpkg.com/slate-vue3/dist/index.js?compression=gzip&amp;label=size">
10
+ </a>
11
+ <a href="https://join.slack.com/t/slate-js/shared_invite/zt-f8t986ip-7dA1DyiqPpzootz1snKXkw">
12
+ <img src="https://img.shields.io/badge/slack-slate--js-brightgreen.svg?logo=slack">
13
+ </a>
14
+ <a href="./packages/slate-vue3/package.json">
15
+ <img src="https://img.shields.io/npm/v/slate-vue3.svg?maxAge=3600&label=version&colorB=007ec6">
16
+ </a>
17
+ </p>
18
+ <br/>
19
+
20
+
21
+ # 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
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
26
+
27
+ # How to use?
28
+
29
+ ## 1. Install slate-vue3
30
+ ```sh
31
+ npm install slate-vue3
32
+ ```
33
+ ## 2. Now, you can use it in vue-sfc :point_right: [**live demo**](https://guan-erjia.github.io/slate-vue3/)
34
+ ```vue
35
+ <script setup lang="ts">
36
+ import { withDOM, Slate, Editable, defaultRenderLeaf, defaultRenderPlaceHolder, createEditor, withHistory } from "slate-vue3"
37
+ import { h } from "vue"
38
+
39
+ const initialValue = [
40
+ {
41
+ type: "paragraph",
42
+ children: [{ text: "Let's start"}]
43
+ }
44
+ ]
45
+ const renderElement = ({ attributes, children }) => h("p", attributes, children)
46
+ const editor = withHistory(withDOM(createEditor(initialValue)))
47
+ </script>
48
+
49
+ <template>
50
+ <Slate :editor="editor" :render-element="renderElement" :render-leaf="defaultRenderLeaf"
51
+ :render-placeholder="defaultRenderPlaceHolder">
52
+ <Editable />
53
+ </Slate>
54
+ </template>
55
+ ```
56
+
57
+ # Component Props
58
+ ## Slate
59
+ ### editor
60
+ > slate-editor instance, add DOM specific behaviors to the editor
61
+ ```typescript
62
+ const initialValue: Descendant[] = [{
63
+ type: 'paragraph',
64
+ children: [ { text: 'This is editable plain text, just like a <textarea>!' } ]
65
+ }]
66
+ const editor: DOMEditor = withDOM(createEditor(initialValue))
67
+ ```
68
+
69
+ ### decorate
70
+ > another type of text-level formatting, split text into leaves
71
+ ```typescript
72
+ function (entry: NodeEntry) => DecoratedRange[]
73
+ ```
74
+
75
+ ### renderElement
76
+ > a function used to render a custom component for a specific type of Element node in the Slate.js document model
77
+ ```typescript
78
+ export interface RenderElementProps {
79
+ children: VNode
80
+ element: Element
81
+ attributes: HTMLAttributes & {
82
+ "data-slate-node": "element"
83
+ "data-slate-inline"?: true
84
+ "data-slate-void"?: true
85
+ dir?: "rtl"
86
+ ref: any
87
+ };
88
+ }
89
+
90
+ function renderElement (props: RenderElementProps) => VNode
91
+ ```
92
+
93
+ ### renderLeaf
94
+ > customize the rendering of leaf nodes in the document tree of your Slate editor
95
+ ```typescript
96
+ export interface RenderLeafProps {
97
+ children: VNode
98
+ leaf: Text
99
+ text: Text
100
+ attributes: HTMLAttributes & {
101
+ "data-slate-leaf": true
102
+ };
103
+ }
104
+ ```
105
+
106
+ ### renderPlaceholder
107
+ > customize how the placeholder of the Slate.js Editable component is rendered when the editor is empty
108
+ ```typescript
109
+ export interface RenderPlaceholderProps {
110
+ children?: string
111
+ attributes: HTMLAttributes & VNodeProps & {
112
+ "data-slate-placeholder": boolean
113
+ dir?: "rtl"
114
+ };
115
+ }
116
+ ```
117
+
118
+ ## Editable
119
+ > customize style of editablearea, you can inherient other HTMLAttribute on it
120
+ ```typescript
121
+ export interface EditableProps extends HTMLAttributes {
122
+ role?: string
123
+ readOnly: boolean
124
+ placeholder?: string
125
+ style?: CSSProperties
126
+ scrollSelectionIntoView: (
127
+ editor: DOMEditor,
128
+ domRange: globalThis.Range
129
+ ) => void
130
+ is: string
131
+ }
132
+ ```
133
+
134
+ # Component Emits
135
+
136
+ ## onchange
137
+ > any change in slate will trigger it
138
+ ```typescript
139
+ const onchange: (event: Descendant[]) => void
140
+ ```
141
+
142
+ ## onvaluechange
143
+ > slate children change in slate will trigger it
144
+ ```typescript
145
+ const onvaluechange: (event: Descendant[]) => void
146
+ ```
147
+
148
+ ## onselectionchange
149
+ > slate selection change in slate will trigger it
150
+ ```typescript
151
+ const onselectionchange: (event: Selection) => void
152
+ ```
153
+
154
+ # Hooks in slate-vue3
155
+
156
+ ## [useComposing](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-composing.ts)
157
+ > Get the current composing state of the editor. It deals with compositionstart, compositionupdate, compositionend events
158
+ ```typescript
159
+ const useComposing: () => Ref<boolean, boolean>
160
+
161
+ const composing = useComposing()
162
+ ```
163
+
164
+ ## [useFocused](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-focus.ts)
165
+ > Get the current focused state of the editor
166
+ ```typescript
167
+ const useFocused: () => Ref<boolean, boolean>
168
+
169
+ const focused = useFocused()
170
+ ```
171
+
172
+ ## [useReadOnly](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-read-only.ts)
173
+ > Get the current readOnly state of the editor
174
+ ```typescript
175
+ const useReadOnly: () => Ref<boolean, boolean>
176
+
177
+ const readonly = useReadOnly()
178
+ ```
179
+
180
+ ## [useSelected](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selected.ts)
181
+ > Get the current selected state of an element
182
+ ```typescript
183
+ const useSelected: () => ComputedRef<boolean>
184
+
185
+ const selected = useSelected()
186
+ ```
187
+
188
+ ## [useEditor](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-editor.ts)
189
+ > Get the current editor object from the context. Context whenever changes occur in the editor
190
+ ```typescript
191
+ const useEditor: () => DOMEditor
192
+
193
+ const editor = useEditor()
194
+ ```
195
+
196
+ ## [useSelection](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selection.ts)
197
+ > Get the current editor selection from the context
198
+
199
+ ```typescript
200
+ const useSelection: () => ComputedRef<BaseSelection>
201
+
202
+ const selection = useSelection()
203
+ ```
204
+
205
+
206
+ ## [useInheritRef](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-inherit-ref.ts)
207
+ > Automatically bind ref to the real node when the component is mounted,This is important when rendering element nodes directly
208
+ ```typescript
209
+ const useInheritRef: (attribute: VNodeProps) => VNodeProps & {
210
+ inheritRef?: VNodeRef
211
+ };
212
+
213
+ const renderElement = (props: RenderElementProps) => {
214
+ const { attributes, children, element } = props
215
+ switch (element.type) {
216
+ case 'image':
217
+ return h(ImageComp, { element, ...useInheritRef(attributes) }, () => children)
218
+ default:
219
+ return h('p', attributes, children)
220
+ }
221
+ }
222
+ ```
223
+
224
+ # FAQ
225
+ ### 1. Why do I have to pass renderFunction into <Slate /> component ?
226
+ 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
227
+
228
+ ### 2. Can I use jsx in slate-vue3 ?
229
+ 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
230
+
231
+ ### 3. Why do rendering functions not use Vue components ?
232
+ 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
233
+
234
+ # Directory Structure
235
+
236
+ - [slate](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate)
237
+ slate core logic, update synchronously with slate
238
+ - [slate-dom](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-dom)
239
+ Implementation of slate on dom, update synchronously with slate-dom
240
+ - [slate-vue](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-vue)
241
+ Vue components for rendering slate editors
242
+ - [slate-history](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/slate-history)
243
+ Provide undo redo functions, replace Weakmap to UnProxyWeakmap
244
+ - [share-tools](https://github.com/Guan-Erjia/slate-vue3/tree/master/packages/share-tools)
245
+ for special processing of Proxy data, obtain the raw pointer, isPlainObject declare
246
+
247
+ # Compact Slate
248
+
249
+ **reactive implement**
250
+
251
+ 1. packages/slate/src/interfaces/text.ts 115:115
252
+ 2. packages/slate/src/create-editor.ts 94:94
253
+ 3. packages/slate/src/transforms-node/set-nodes.ts 18:18
254
+ 4. packages/slate/src/interfaces/text.ts 116:116
255
+
256
+ **remove immer**
257
+
258
+ 1. packages/slate/src/interfaces/node.ts 365:365
259
+ 2. packages/slate/src/interfaces/point.ts 103:103
260
+ 3. packages/slate/src/interfaces/range.ts 224:224
261
+ 4. packages/slate/src/interfaces/transforms/general.ts 322:333
262
+
263
+ **rewrite implement for WeakMap**
264
+
265
+ 1. packages/share-tools/index.ts
266
+ 2. packages/slate-dom/src/utils/weak-maps.ts
267
+
268
+ **import types from globalThis in slate-dom**
269
+
270
+ 1. packages/slate-dom/src/index.ts
271
+ 2. packages/slate-dom/src/plugin/dom-editor.ts
272
+ 3. packages/slate-dom/src/utils/dom.ts
273
+
274
+ **other compact**
275
+
276
+ 1. packages/slate/src/core/normalize-node.ts
277
+ 2. packages/slate-dom/src/plugin/dom-editor.ts 421:441
package/dist/index.d.ts CHANGED
@@ -506,9 +506,6 @@ export declare type DOMText = globalThis.Text;
506
506
 
507
507
  export declare const edges: EditorInterface['edges'];
508
508
 
509
- /**
510
- * Editable.
511
- */
512
509
  export declare const Editable: DefineComponent< {
513
510
  role?: string | undefined;
514
511
  readOnly: boolean;
package/dist/index.js CHANGED
@@ -1792,12 +1792,12 @@ function last$1(array) {
1792
1792
  var length = array == null ? 0 : array.length;
1793
1793
  return length ? array[length - 1] : void 0;
1794
1794
  }
1795
- function parent$1(object, path2) {
1795
+ function parent$2(object, path2) {
1796
1796
  return path2.length < 2 ? object : baseGet(object, baseSlice(path2, 0, -1));
1797
1797
  }
1798
1798
  function baseUnset(object, path2) {
1799
1799
  path2 = castPath(path2, object);
1800
- object = parent$1(object, path2);
1800
+ object = parent$2(object, path2);
1801
1801
  return object == null || delete object[toKey(last$1(path2))];
1802
1802
  }
1803
1803
  function customOmitClone(value) {
@@ -3630,7 +3630,7 @@ const normalize = (editor, options = {}) => {
3630
3630
  }
3631
3631
  });
3632
3632
  };
3633
- const parent = (editor, at, options = {}) => {
3633
+ const parent$1 = (editor, at, options = {}) => {
3634
3634
  const path2 = Editor.path(editor, at, options);
3635
3635
  const parentPath = Path.parent(path2);
3636
3636
  const entry = Editor.node(editor, parentPath);
@@ -5106,7 +5106,7 @@ const createEditor = (children) => {
5106
5106
  node: (...args) => node(editor, ...args),
5107
5107
  nodes: (...args) => nodes(editor, ...args),
5108
5108
  normalize: (...args) => normalize(editor, ...args),
5109
- parent: (...args) => parent(editor, ...args),
5109
+ parent: (...args) => parent$1(editor, ...args),
5110
5110
  path: (...args) => path(editor, ...args),
5111
5111
  pathRef: (...args) => pathRef(editor, ...args),
5112
5112
  pathRefs: (...args) => pathRefs(editor, ...args),
@@ -5148,7 +5148,7 @@ const isDOMElement = (value) => {
5148
5148
  };
5149
5149
  const isDOMNode = (value) => {
5150
5150
  const window2 = getDefaultView(value);
5151
- return !!window2 && value instanceof window2.Node;
5151
+ return !!window2 && (value instanceof window2.Node || value instanceof globalThis.Node);
5152
5152
  };
5153
5153
  const isDOMSelection = (value) => {
5154
5154
  const window2 = value && value.anchorNode && getDefaultView(value.anchorNode);
@@ -7385,9 +7385,9 @@ const useEditor = () => {
7385
7385
  };
7386
7386
  const StringComp = defineComponent({
7387
7387
  name: "slate-string",
7388
- props: ["isLast", "leaf", "parent", "text"],
7388
+ props: ["isLast", "leaf", "element", "text"],
7389
7389
  setup(props) {
7390
- const { isLast, leaf: leaf2, parent: parent2, text } = props;
7390
+ const { isLast, leaf: leaf2, element, text } = props;
7391
7391
  const editor = useEditor();
7392
7392
  const getTextContent = computed(() => {
7393
7393
  const text2 = leaf2.text;
@@ -7395,12 +7395,12 @@ const StringComp = defineComponent({
7395
7395
  });
7396
7396
  const isLineBreak = computed(() => {
7397
7397
  const pathParent = Path.parent(DOMEditor.findPath(editor, text));
7398
- return leaf2.text === "" && parent2.children[parent2.children.length - 1] === text && !editor.isInline(parent2) && Editor.string(editor, pathParent) === "";
7398
+ return leaf2.text === "" && element.children[element.children.length - 1] === text && !editor.isInline(element) && Editor.string(editor, pathParent) === "";
7399
7399
  });
7400
7400
  const zeroStringAttrs = computed(() => {
7401
- const length = Node.string(parent2).length || 0;
7401
+ const length = Node.string(element).length || 0;
7402
7402
  const isMarkPlaceholder = Boolean(leaf2[MARK_PLACEHOLDER_SYMBOL]) || false;
7403
- const isVoidParent = editor.isVoid(parent2);
7403
+ const isVoidParent = editor.isVoid(element);
7404
7404
  if (isVoidParent || isLineBreak.value || leaf2.text === "") {
7405
7405
  return {
7406
7406
  "data-slate-zero-width": isLineBreak.value ? "n" : "z",
@@ -7474,9 +7474,9 @@ const useParentDescoration = () => {
7474
7474
  };
7475
7475
  const TextComp = defineComponent({
7476
7476
  name: "slate-text",
7477
- props: ["text", "parent"],
7477
+ props: ["text", "element"],
7478
7478
  setup(props) {
7479
- const { text, parent: parent2 } = props;
7479
+ const { text, element } = props;
7480
7480
  const editor = useEditor();
7481
7481
  const spanRef = ref();
7482
7482
  const decorate = useDecorate();
@@ -7509,7 +7509,8 @@ const TextComp = defineComponent({
7509
7509
  decorations.value.forEach((dec) => {
7510
7510
  ds.push(Range.intersection(dec, range2));
7511
7511
  });
7512
- return Text.decorations(text, ds.filter(Boolean).length ? ds : []);
7512
+ const filterDs = ds.filter(Boolean);
7513
+ return Text.decorations(text, filterDs.length ? filterDs : []);
7513
7514
  });
7514
7515
  onMounted(() => {
7515
7516
  const key = DOMEditor.findKey(editor, text);
@@ -7530,9 +7531,9 @@ const TextComp = defineComponent({
7530
7531
  }
7531
7532
  });
7532
7533
  const isLastText = computed(() => {
7533
- const isVoid = Editor.isVoid(editor, parent2);
7534
- const isLeafBlock = Element.isElement(parent2) && !editor.isInline(parent2) && Editor.hasInlines(editor, parent2);
7535
- return !isVoid && isLeafBlock && NODE_TO_INDEX.get(text) === parent2.children.length - 1;
7534
+ const isVoid = Editor.isVoid(editor, element);
7535
+ const isLeafBlock = Element.isElement(parent) && !editor.isInline(parent) && Editor.hasInlines(editor, parent);
7536
+ return !isVoid && isLeafBlock && NODE_TO_INDEX.get(text) === element.children.length - 1;
7536
7537
  });
7537
7538
  const renderLeaf = useRenderLeaf();
7538
7539
  return () => h(
@@ -7547,7 +7548,7 @@ const TextComp = defineComponent({
7547
7548
  children: h(StringComp, {
7548
7549
  isLast: isLastText.value && i === leaves.value.length - 1,
7549
7550
  leaf: leaf2,
7550
- parent: parent2,
7551
+ element,
7551
7552
  text,
7552
7553
  key: `${text.text}-${leaf2.text}-${i}`
7553
7554
  })
@@ -7648,7 +7649,7 @@ const ElementComp = defineComponent({
7648
7649
  position: "absolute"
7649
7650
  }
7650
7651
  },
7651
- h(TextComp, { parent: element, text })
7652
+ h(TextComp, { element, text })
7652
7653
  );
7653
7654
  }
7654
7655
  return h(Fragment, ChildrenFC(element, editor));
@@ -7677,7 +7678,7 @@ const ChildrenFC = (element, editor) => renderList(element.children, (child, i)
7677
7678
  const key = DOMEditor.findKey(editor, child);
7678
7679
  NODE_TO_INDEX.set(child, i);
7679
7680
  NODE_TO_PARENT.set(child, element);
7680
- return Element.isElement(child) ? h(ElementComp, { element: child, key: key.id }) : h(TextComp, { text: child, parent: element, key: key.id });
7681
+ return Element.isElement(child) ? h(ElementComp, { element: child, key: key.id }) : h(TextComp, { text: child, element, key: key.id });
7681
7682
  });
7682
7683
  const MUTATION_OBSERVER_CONFIG = {
7683
7684
  subtree: true,
@@ -9263,7 +9264,7 @@ export {
9263
9264
  normalizePoint,
9264
9265
  normalizeRange,
9265
9266
  normalizeStringDiff,
9266
- parent,
9267
+ parent$1 as parent,
9267
9268
  path,
9268
9269
  pathRef,
9269
9270
  pathRefs,
package/package.json CHANGED
@@ -1,68 +1,71 @@
1
- {
2
- "name": "slate-vue3",
3
- "version": "0.0.25",
4
- "type": "module",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "description": "slate-react library implemented with vue3",
9
- "license": "MIT",
10
- "files": [
11
- "dist/"
12
- ],
13
- "scripts": {
14
- "dev": "vite",
15
- "build": "vite build",
16
- "preview": "vite preview",
17
- "build-all": "vite build --mode=lib",
18
- "e2e": "playwright test",
19
- "e2e-ui": "playwright test --ui",
20
- "test": "vitest"
21
- },
22
- "dependencies": {
23
- "direction": "^2.0.1",
24
- "is-hotkey": "^0.2.0",
25
- "lodash-es": "^4.17.21",
26
- "scroll-into-view-if-needed": "^3.1.0"
27
- },
28
- "peerDependencies": {
29
- "vue": "^3.5.13"
30
- },
31
- "devDependencies": {
32
- "@faker-js/faker": "^9.4.0",
33
- "@playwright/test": "^1.50.1",
34
- "@testing-library/vue": "^8.1.0",
35
- "@types/is-hotkey": "^0.1.10",
36
- "@types/is-url": "^1.2.32",
37
- "@types/lodash-es": "^4.17.12",
38
- "@types/node": "^22.13.1",
39
- "@types/prismjs": "^1.26.5",
40
- "@vitejs/plugin-vue": "^5.2.1",
41
- "image-extensions": "^1.1.0",
42
- "is-url": "^1.2.4",
43
- "jsdom": "^26.0.0",
44
- "prismjs": "^1.29.0",
45
- "slate-hyperscript": "^0.100.0",
46
- "typescript": "~5.7.2",
47
- "vite": "^6.2.0",
48
- "vite-plugin-dts": "^4.5.0",
49
- "vitest": "^3.0.5",
50
- "vue-router": "^4.5.0"
51
- },
52
- "keywords": [
53
- "slate-vue3",
54
- "slate-vue",
55
- "slate",
56
- "editor",
57
- "contenteditable",
58
- "richtext",
59
- "rich",
60
- "editable",
61
- "markdown",
62
- "html"
63
- ],
64
- "repository": {
65
- "type": "git",
66
- "url": "git+https://github.com/Guan-Erjia/slate-vue3.git"
67
- }
68
- }
1
+ {
2
+ "name": "slate-vue3",
3
+ "version": "0.0.26",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "description": "slate-react library implemented with vue3",
9
+ "license": "MIT",
10
+ "files": [
11
+ "dist/"
12
+ ],
13
+ "scripts": {
14
+ "dev": "vite",
15
+ "build": "vite build",
16
+ "preview": "vite preview",
17
+ "build-all": "vite build --mode=lib",
18
+ "e2e": "playwright test",
19
+ "e2e-ui": "playwright test --ui",
20
+ "test": "vitest"
21
+ },
22
+ "dependencies": {
23
+ "direction": "^2.0.1",
24
+ "is-hotkey": "^0.2.0",
25
+ "lodash-es": "^4.17.21",
26
+ "scroll-into-view-if-needed": "^3.1.0"
27
+ },
28
+ "peerDependencies": {
29
+ "vue": "^3.5.13"
30
+ },
31
+ "devDependencies": {
32
+ "@faker-js/faker": "^9.4.0",
33
+ "@playwright/test": "^1.50.1",
34
+ "@testing-library/vue": "^8.1.0",
35
+ "@types/is-hotkey": "^0.1.10",
36
+ "@types/is-url": "^1.2.32",
37
+ "@types/lodash-es": "^4.17.12",
38
+ "@types/node": "^22.13.1",
39
+ "@types/prismjs": "^1.26.5",
40
+ "@vitejs/plugin-vue": "^5.2.1",
41
+ "image-extensions": "^1.1.0",
42
+ "is-url": "^1.2.4",
43
+ "jsdom": "^26.0.0",
44
+ "prismjs": "^1.29.0",
45
+ "slate-hyperscript": "^0.100.0",
46
+ "typescript": "~5.7.2",
47
+ "vite": "^6.2.0",
48
+ "vite-plugin-dts": "^4.5.0",
49
+ "vitest": "^3.0.5",
50
+ "vue-router": "^4.5.0"
51
+ },
52
+ "publishConfig": {
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/Guan-Erjia/slate-vue3.git"
58
+ },
59
+ "keywords": [
60
+ "slate-vue3",
61
+ "slate-vue",
62
+ "slate",
63
+ "editor",
64
+ "contenteditable",
65
+ "richtext",
66
+ "rich",
67
+ "editable",
68
+ "markdown",
69
+ "html"
70
+ ]
71
+ }