slate-vue3 0.0.24 → 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/README.md +145 -44
- package/dist/index.d.ts +4 -9
- package/dist/index.js +46 -70
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -3,27 +3,46 @@
|
|
|
3
3
|
<p align="center">
|
|
4
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
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&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>
|
|
6
18
|
<br/>
|
|
7
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
|
+
|
|
8
27
|
# How to use?
|
|
9
28
|
|
|
10
|
-
## 1.
|
|
29
|
+
## 1. Install slate-vue3
|
|
11
30
|
```sh
|
|
12
31
|
npm install slate-vue3
|
|
13
32
|
```
|
|
14
|
-
## 2.
|
|
33
|
+
## 2. Now, you can use it in vue-sfc :point_right: [**live demo**](https://guan-erjia.github.io/slate-vue3/)
|
|
15
34
|
```vue
|
|
16
35
|
<script setup lang="ts">
|
|
17
36
|
import { withDOM, Slate, Editable, defaultRenderLeaf, defaultRenderPlaceHolder, createEditor, withHistory } from "slate-vue3"
|
|
18
|
-
import { h } from "vue"
|
|
37
|
+
import { h } from "vue"
|
|
19
38
|
|
|
20
39
|
const initialValue = [
|
|
21
40
|
{
|
|
22
|
-
type:
|
|
23
|
-
children: [{ text: '
|
|
41
|
+
type: "paragraph",
|
|
42
|
+
children: [{ text: "Let's start"}]
|
|
24
43
|
}
|
|
25
44
|
]
|
|
26
|
-
const renderElement = ({ attributes, children }) => h(
|
|
45
|
+
const renderElement = ({ attributes, children }) => h("p", attributes, children)
|
|
27
46
|
const editor = withHistory(withDOM(createEditor(initialValue)))
|
|
28
47
|
</script>
|
|
29
48
|
|
|
@@ -34,71 +53,151 @@ const editor = withHistory(withDOM(createEditor(initialValue)))
|
|
|
34
53
|
</Slate>
|
|
35
54
|
</template>
|
|
36
55
|
```
|
|
37
|
-
## 3. check out the :point_right:[**live demo**](https://guan-erjia.github.io/slate-vue3/) of all of the examples
|
|
38
|
-

|
|
39
56
|
|
|
40
|
-
#
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
```
|
|
44
68
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
```
|
|
48
105
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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>
|
|
52
160
|
|
|
53
161
|
const composing = useComposing()
|
|
54
162
|
```
|
|
55
163
|
|
|
56
164
|
## [useFocused](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-focus.ts)
|
|
57
|
-
> Get the current focused state of the editor
|
|
58
|
-
|
|
59
|
-
const useFocused
|
|
60
|
-
```javascript
|
|
61
|
-
import { useFocused } from 'slate-vue3'
|
|
165
|
+
> Get the current focused state of the editor
|
|
166
|
+
```typescript
|
|
167
|
+
const useFocused: () => Ref<boolean, boolean>
|
|
62
168
|
|
|
63
169
|
const focused = useFocused()
|
|
64
170
|
```
|
|
65
171
|
|
|
66
172
|
## [useReadOnly](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-read-only.ts)
|
|
67
|
-
> Get the current readOnly state of the editor
|
|
68
|
-
|
|
69
|
-
const useReadOnly
|
|
70
|
-
```javascript
|
|
71
|
-
import { useReadOnly } from 'slate-vue3'
|
|
173
|
+
> Get the current readOnly state of the editor
|
|
174
|
+
```typescript
|
|
175
|
+
const useReadOnly: () => Ref<boolean, boolean>
|
|
72
176
|
|
|
73
177
|
const readonly = useReadOnly()
|
|
74
178
|
```
|
|
75
179
|
|
|
76
180
|
## [useSelected](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selected.ts)
|
|
77
|
-
> Get the current selected state of an element
|
|
78
|
-
|
|
79
|
-
const useSelected
|
|
80
|
-
```javascript
|
|
81
|
-
import { useSelected } from 'slate-vue3'
|
|
181
|
+
> Get the current selected state of an element
|
|
182
|
+
```typescript
|
|
183
|
+
const useSelected: () => ComputedRef<boolean>
|
|
82
184
|
|
|
83
185
|
const selected = useSelected()
|
|
84
186
|
```
|
|
85
187
|
|
|
86
188
|
## [useEditor](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-editor.ts)
|
|
87
|
-
> Get the current editor object from the context. Context whenever changes occur in the editor
|
|
88
|
-
|
|
89
|
-
const useEditor
|
|
90
|
-
```javascript
|
|
91
|
-
import { useEditor } from 'slate-vue3'
|
|
189
|
+
> Get the current editor object from the context. Context whenever changes occur in the editor
|
|
190
|
+
```typescript
|
|
191
|
+
const useEditor: () => DOMEditor
|
|
92
192
|
|
|
93
193
|
const editor = useEditor()
|
|
94
194
|
```
|
|
95
195
|
|
|
96
196
|
## [useSelection](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-selection.ts)
|
|
97
|
-
> Get the current editor selection from the context
|
|
197
|
+
> Get the current editor selection from the context
|
|
98
198
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
import { useSelection } from 'slate-vue3'
|
|
199
|
+
```typescript
|
|
200
|
+
const useSelection: () => ComputedRef<BaseSelection>
|
|
102
201
|
|
|
103
202
|
const selection = useSelection()
|
|
104
203
|
```
|
|
@@ -106,9 +205,11 @@ const selection = useSelection()
|
|
|
106
205
|
|
|
107
206
|
## [useInheritRef](https://github.com/Guan-Erjia/slate-vue3/blob/master/packages/slate-vue/src/hooks/use-inherit-ref.ts)
|
|
108
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
|
+
};
|
|
109
212
|
|
|
110
|
-
const useInheritRef : ( attribute: HTMLAttributes ) => HTMLAttributes
|
|
111
|
-
```javascript
|
|
112
213
|
const renderElement = (props: RenderElementProps) => {
|
|
113
214
|
const { attributes, children, element } = props
|
|
114
215
|
switch (element.type) {
|
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;
|
|
@@ -1563,12 +1560,6 @@ export declare const IS_FOCUSED: toRawWeakMap<Editor, boolean>;
|
|
|
1563
1560
|
|
|
1564
1561
|
export declare const IS_IOS: boolean;
|
|
1565
1562
|
|
|
1566
|
-
/**
|
|
1567
|
-
* Two weak maps that allow us rebuild a path given a node. They are populated
|
|
1568
|
-
* at render time such that after a render occurs we can always backtrack.
|
|
1569
|
-
*/
|
|
1570
|
-
export declare const IS_NODE_MAP_DIRTY: toRawWeakMap<Editor, boolean>;
|
|
1571
|
-
|
|
1572
1563
|
/**
|
|
1573
1564
|
* Weak maps for storing editor-related state.
|
|
1574
1565
|
*/
|
|
@@ -1726,6 +1717,10 @@ export { Node_2 as Node }
|
|
|
1726
1717
|
|
|
1727
1718
|
export declare const NODE_TO_ELEMENT: toRawWeakMap<Node_2, HTMLElement>;
|
|
1728
1719
|
|
|
1720
|
+
/**
|
|
1721
|
+
* Two weak maps that allow us rebuild a path given a node. They are populated
|
|
1722
|
+
* at render time such that after a render occurs we can always backtrack.
|
|
1723
|
+
*/
|
|
1729
1724
|
export declare const NODE_TO_INDEX: toRawWeakMap<Node_2, number>;
|
|
1730
1725
|
|
|
1731
1726
|
export declare const NODE_TO_KEY: toRawWeakMap<Node_2, Key>;
|
package/dist/index.js
CHANGED
|
@@ -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
|
var _a, _b;
|
|
5
|
-
import { isProxy, toRaw, nextTick, reactive, defineComponent, provide, ref, computed, onMounted, onUnmounted, renderSlot, inject, onBeforeUpdate, onBeforeUnmount, h, watch, renderList, onUpdated, useAttrs, getCurrentInstance } from "vue";
|
|
5
|
+
import { isProxy, toRaw, nextTick, reactive, defineComponent, provide, ref, computed, onMounted, onUnmounted, renderSlot, inject, onBeforeUpdate, onBeforeUnmount, h, watch, renderList, Fragment, onUpdated, useAttrs, getCurrentInstance } from "vue";
|
|
6
6
|
const SLATE_USE_EDITOR = Symbol("SLATE_USE_EDITOR");
|
|
7
7
|
const SLATE_USE_DECORATE = Symbol("SLATE_USE_DECORATE");
|
|
8
8
|
const SLATE_USE_SELECTED = Symbol("SLATE_USE_SELECTED");
|
|
@@ -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$
|
|
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$
|
|
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);
|
|
@@ -5315,7 +5315,6 @@ class Key {
|
|
|
5315
5315
|
this.id = `${n$1++}`;
|
|
5316
5316
|
}
|
|
5317
5317
|
}
|
|
5318
|
-
const IS_NODE_MAP_DIRTY = new toRawWeakMap();
|
|
5319
5318
|
const NODE_TO_INDEX = new toRawWeakMap();
|
|
5320
5319
|
const NODE_TO_PARENT = new toRawWeakMap();
|
|
5321
5320
|
const EDITOR_TO_WINDOW = new toRawWeakMap();
|
|
@@ -6304,15 +6303,6 @@ const withDOM = (editor, clipboardFormatKey = "x-slate-fragment") => {
|
|
|
6304
6303
|
}
|
|
6305
6304
|
}
|
|
6306
6305
|
apply2(op);
|
|
6307
|
-
switch (op.type) {
|
|
6308
|
-
case "insert_node":
|
|
6309
|
-
case "remove_node":
|
|
6310
|
-
case "merge_node":
|
|
6311
|
-
case "move_node":
|
|
6312
|
-
case "split_node": {
|
|
6313
|
-
IS_NODE_MAP_DIRTY.set(e2, true);
|
|
6314
|
-
}
|
|
6315
|
-
}
|
|
6316
6306
|
for (const [path2, key] of matches) {
|
|
6317
6307
|
const [node2] = Editor.node(e2, path2);
|
|
6318
6308
|
NODE_TO_KEY.set(node2, key);
|
|
@@ -7008,9 +6998,6 @@ function createAndroidInputManager({
|
|
|
7008
6998
|
clearTimeout(flushTimeoutId);
|
|
7009
6999
|
flushTimeoutId = null;
|
|
7010
7000
|
}
|
|
7011
|
-
if (IS_NODE_MAP_DIRTY.get(editor)) {
|
|
7012
|
-
return;
|
|
7013
|
-
}
|
|
7014
7001
|
const { inputType: type } = event;
|
|
7015
7002
|
let targetRange2 = null;
|
|
7016
7003
|
const data = event.dataTransfer || event.data || void 0;
|
|
@@ -7398,9 +7385,9 @@ const useEditor = () => {
|
|
|
7398
7385
|
};
|
|
7399
7386
|
const StringComp = defineComponent({
|
|
7400
7387
|
name: "slate-string",
|
|
7401
|
-
props: ["isLast", "leaf", "
|
|
7388
|
+
props: ["isLast", "leaf", "element", "text"],
|
|
7402
7389
|
setup(props) {
|
|
7403
|
-
const { isLast, leaf: leaf2,
|
|
7390
|
+
const { isLast, leaf: leaf2, element, text } = props;
|
|
7404
7391
|
const editor = useEditor();
|
|
7405
7392
|
const getTextContent = computed(() => {
|
|
7406
7393
|
const text2 = leaf2.text;
|
|
@@ -7408,12 +7395,12 @@ const StringComp = defineComponent({
|
|
|
7408
7395
|
});
|
|
7409
7396
|
const isLineBreak = computed(() => {
|
|
7410
7397
|
const pathParent = Path.parent(DOMEditor.findPath(editor, text));
|
|
7411
|
-
return leaf2.text === "" &&
|
|
7398
|
+
return leaf2.text === "" && element.children[element.children.length - 1] === text && !editor.isInline(element) && Editor.string(editor, pathParent) === "";
|
|
7412
7399
|
});
|
|
7413
7400
|
const zeroStringAttrs = computed(() => {
|
|
7414
|
-
const length = Node.string(
|
|
7401
|
+
const length = Node.string(element).length || 0;
|
|
7415
7402
|
const isMarkPlaceholder = Boolean(leaf2[MARK_PLACEHOLDER_SYMBOL]) || false;
|
|
7416
|
-
const isVoidParent = editor.isVoid(
|
|
7403
|
+
const isVoidParent = editor.isVoid(element);
|
|
7417
7404
|
if (isVoidParent || isLineBreak.value || leaf2.text === "") {
|
|
7418
7405
|
return {
|
|
7419
7406
|
"data-slate-zero-width": isLineBreak.value ? "n" : "z",
|
|
@@ -7487,9 +7474,9 @@ const useParentDescoration = () => {
|
|
|
7487
7474
|
};
|
|
7488
7475
|
const TextComp = defineComponent({
|
|
7489
7476
|
name: "slate-text",
|
|
7490
|
-
props: ["text", "
|
|
7477
|
+
props: ["text", "element"],
|
|
7491
7478
|
setup(props) {
|
|
7492
|
-
const { text,
|
|
7479
|
+
const { text, element } = props;
|
|
7493
7480
|
const editor = useEditor();
|
|
7494
7481
|
const spanRef = ref();
|
|
7495
7482
|
const decorate = useDecorate();
|
|
@@ -7522,7 +7509,8 @@ const TextComp = defineComponent({
|
|
|
7522
7509
|
decorations.value.forEach((dec) => {
|
|
7523
7510
|
ds.push(Range.intersection(dec, range2));
|
|
7524
7511
|
});
|
|
7525
|
-
|
|
7512
|
+
const filterDs = ds.filter(Boolean);
|
|
7513
|
+
return Text.decorations(text, filterDs.length ? filterDs : []);
|
|
7526
7514
|
});
|
|
7527
7515
|
onMounted(() => {
|
|
7528
7516
|
const key = DOMEditor.findKey(editor, text);
|
|
@@ -7543,9 +7531,9 @@ const TextComp = defineComponent({
|
|
|
7543
7531
|
}
|
|
7544
7532
|
});
|
|
7545
7533
|
const isLastText = computed(() => {
|
|
7546
|
-
const isVoid = Editor.isVoid(editor,
|
|
7547
|
-
const isLeafBlock = Element.isElement(
|
|
7548
|
-
return !isVoid && isLeafBlock && NODE_TO_INDEX.get(text) ===
|
|
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;
|
|
7549
7537
|
});
|
|
7550
7538
|
const renderLeaf = useRenderLeaf();
|
|
7551
7539
|
return () => h(
|
|
@@ -7560,7 +7548,7 @@ const TextComp = defineComponent({
|
|
|
7560
7548
|
children: h(StringComp, {
|
|
7561
7549
|
isLast: isLastText.value && i === leaves.value.length - 1,
|
|
7562
7550
|
leaf: leaf2,
|
|
7563
|
-
|
|
7551
|
+
element,
|
|
7564
7552
|
text,
|
|
7565
7553
|
key: `${text.text}-${leaf2.text}-${i}`
|
|
7566
7554
|
})
|
|
@@ -7661,10 +7649,10 @@ const ElementComp = defineComponent({
|
|
|
7661
7649
|
position: "absolute"
|
|
7662
7650
|
}
|
|
7663
7651
|
},
|
|
7664
|
-
h(TextComp, {
|
|
7652
|
+
h(TextComp, { element, text })
|
|
7665
7653
|
);
|
|
7666
7654
|
}
|
|
7667
|
-
return h(
|
|
7655
|
+
return h(Fragment, ChildrenFC(element, editor));
|
|
7668
7656
|
});
|
|
7669
7657
|
const decorate = useDecorate();
|
|
7670
7658
|
const parentDs = useParentDescoration();
|
|
@@ -7686,21 +7674,11 @@ const ElementComp = defineComponent({
|
|
|
7686
7674
|
});
|
|
7687
7675
|
}
|
|
7688
7676
|
});
|
|
7689
|
-
const
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
onUpdated(() => {
|
|
7695
|
-
IS_NODE_MAP_DIRTY.set(editor, false);
|
|
7696
|
-
});
|
|
7697
|
-
return () => renderList(props.node.children, (child, i) => {
|
|
7698
|
-
const key = DOMEditor.findKey(editor, child);
|
|
7699
|
-
NODE_TO_INDEX.set(child, i);
|
|
7700
|
-
NODE_TO_PARENT.set(child, props.node);
|
|
7701
|
-
return Element.isElement(child) ? h(ElementComp, { element: child, key: key.id }) : h(TextComp, { text: child, parent: props.node, key: key.id });
|
|
7702
|
-
});
|
|
7703
|
-
}
|
|
7677
|
+
const ChildrenFC = (element, editor) => renderList(element.children, (child, i) => {
|
|
7678
|
+
const key = DOMEditor.findKey(editor, child);
|
|
7679
|
+
NODE_TO_INDEX.set(child, i);
|
|
7680
|
+
NODE_TO_PARENT.set(child, element);
|
|
7681
|
+
return Element.isElement(child) ? h(ElementComp, { element: child, key: key.id }) : h(TextComp, { text: child, element, key: key.id });
|
|
7704
7682
|
});
|
|
7705
7683
|
const MUTATION_OBSERVER_CONFIG = {
|
|
7706
7684
|
subtree: true,
|
|
@@ -7941,6 +7919,7 @@ const style = {
|
|
|
7941
7919
|
WebkitUserModify: IS_WEBKIT ? "inherit" : void 0
|
|
7942
7920
|
};
|
|
7943
7921
|
const PlaceholderComp = defineComponent({
|
|
7922
|
+
name: "slate-placeholder",
|
|
7944
7923
|
props: ["placeholder", "onPlaceholderResize"],
|
|
7945
7924
|
setup(props) {
|
|
7946
7925
|
const editor = useEditor();
|
|
@@ -8276,29 +8255,27 @@ const Editable = defineComponent({
|
|
|
8276
8255
|
if (editor.marks) {
|
|
8277
8256
|
native = false;
|
|
8278
8257
|
}
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
native = false;
|
|
8288
|
-
}
|
|
8258
|
+
const { anchor } = selection;
|
|
8259
|
+
const [node2, offset] = DOMEditor.toDOMPoint(editor, anchor);
|
|
8260
|
+
const anchorNode = (_a2 = node2.parentElement) == null ? void 0 : _a2.closest("a");
|
|
8261
|
+
const window2 = DOMEditor.getWindow(editor);
|
|
8262
|
+
if (native && anchorNode && DOMEditor.hasDOMNode(editor, anchorNode)) {
|
|
8263
|
+
const lastText = window2 == null ? void 0 : window2.document.createTreeWalker(anchorNode, NodeFilter.SHOW_TEXT).lastChild();
|
|
8264
|
+
if (lastText === node2 && ((_b2 = lastText.textContent) == null ? void 0 : _b2.length) === offset) {
|
|
8265
|
+
native = false;
|
|
8289
8266
|
}
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8267
|
+
}
|
|
8268
|
+
if (native && node2.parentElement && ((_c = window2 == null ? void 0 : window2.getComputedStyle(node2.parentElement)) == null ? void 0 : _c.whiteSpace) === "pre") {
|
|
8269
|
+
const block = Editor.above(editor, {
|
|
8270
|
+
at: anchor.path,
|
|
8271
|
+
match: (n2) => Element.isElement(n2) && Editor.isBlock(editor, n2)
|
|
8272
|
+
});
|
|
8273
|
+
if (block && Node.string(block[0]).includes(" ")) {
|
|
8274
|
+
native = false;
|
|
8298
8275
|
}
|
|
8299
8276
|
}
|
|
8300
8277
|
}
|
|
8301
|
-
if (
|
|
8278
|
+
if (!inputType.startsWith("delete") || inputType.startsWith("deleteBy")) {
|
|
8302
8279
|
const [targetRange2] = event.getTargetRanges();
|
|
8303
8280
|
if (targetRange2) {
|
|
8304
8281
|
const range2 = DOMEditor.toSlateRange(editor, targetRange2, {
|
|
@@ -8906,7 +8883,7 @@ const Editable = defineComponent({
|
|
|
8906
8883
|
onPaste
|
|
8907
8884
|
},
|
|
8908
8885
|
[
|
|
8909
|
-
|
|
8886
|
+
ChildrenFC(editor, editor),
|
|
8910
8887
|
h(PlaceholderComp, {
|
|
8911
8888
|
placeholder,
|
|
8912
8889
|
onPlaceholderResize
|
|
@@ -9187,7 +9164,6 @@ export {
|
|
|
9187
9164
|
IS_FIREFOX_LEGACY,
|
|
9188
9165
|
IS_FOCUSED,
|
|
9189
9166
|
IS_IOS,
|
|
9190
|
-
IS_NODE_MAP_DIRTY,
|
|
9191
9167
|
IS_READ_ONLY,
|
|
9192
9168
|
IS_UC_MOBILE,
|
|
9193
9169
|
IS_WEBKIT,
|
|
@@ -9288,7 +9264,7 @@ export {
|
|
|
9288
9264
|
normalizePoint,
|
|
9289
9265
|
normalizeRange,
|
|
9290
9266
|
normalizeStringDiff,
|
|
9291
|
-
parent,
|
|
9267
|
+
parent$1 as parent,
|
|
9292
9268
|
path,
|
|
9293
9269
|
pathRef,
|
|
9294
9270
|
pathRefs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slate-vue3",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -49,6 +49,13 @@
|
|
|
49
49
|
"vitest": "^3.0.5",
|
|
50
50
|
"vue-router": "^4.5.0"
|
|
51
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
|
+
},
|
|
52
59
|
"keywords": [
|
|
53
60
|
"slate-vue3",
|
|
54
61
|
"slate-vue",
|
|
@@ -60,9 +67,5 @@
|
|
|
60
67
|
"editable",
|
|
61
68
|
"markdown",
|
|
62
69
|
"html"
|
|
63
|
-
]
|
|
64
|
-
"repository": {
|
|
65
|
-
"type": "git",
|
|
66
|
-
"url": "git+https://github.com/Guan-Erjia/slate-vue3.git"
|
|
67
|
-
}
|
|
70
|
+
]
|
|
68
71
|
}
|