slate-vue3 0.3.5 → 0.4.1
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 +7 -35
- package/dist/{batch-dirty-paths-DdGxRyrT.js → batch-dirty-paths-1Ahs6kkr.js} +23 -8
- package/dist/core.js +3 -3
- package/dist/{create-editor-BLBmZQoI.js → create-editor-UR4aFGAf.js} +2 -2
- package/dist/dom.js +3 -3
- package/dist/history.js +1 -1
- package/dist/{hotkeys-CmyQAN4Q.js → hotkeys-BSLjSKb9.js} +1 -1
- package/dist/hyperscript.js +2 -2
- package/dist/index.js +12 -8
- package/dist/{location-BQJIMGOU.js → location-MosjNIh-.js} +1 -1
- package/dist/slate/interfaces/text.d.ts +11 -1
- package/dist/slate-vue/components/slate.d.ts +7 -1
- package/dist/slate-vue/components/utils.d.ts +10 -4
- package/dist/slate-vue/hooks/use-render.d.ts +2 -1
- package/dist/slate-vue/index.d.ts +1 -2
- package/dist/slate-vue/utils/constants.d.ts +1 -0
- package/dist/slate-vue/utils/interface.d.ts +22 -3
- package/dist/{use-focused-C0jEAq2w.js → use-focused-BlttbYui.js} +61 -39
- package/dist/yjs.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/slate-vue3?activeTab=code">
|
|
9
|
-
<img src="https://img.shields.io/npm/unpacked-size/slate-vue3">
|
|
10
9
|
<img src="https://img.shields.io/bundlephobia/min/slate-vue3">
|
|
11
10
|
</a>
|
|
12
11
|
<a href="https://join.slack.com/t/slate-js/shared_invite/zt-f8t986ip-7dA1DyiqPpzootz1snKXkw">
|
|
@@ -38,13 +37,7 @@ npm install slate-vue3
|
|
|
38
37
|
|
|
39
38
|
```vue
|
|
40
39
|
<script setup lang="ts">
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
Slate,
|
|
44
|
-
Editable,
|
|
45
|
-
defaultRenderLeaf,
|
|
46
|
-
defaultRenderPlaceHolder,
|
|
47
|
-
} from "slate-vue3";
|
|
40
|
+
import { Slate, Editable, } from "slate-vue3";
|
|
48
41
|
import { createEditor } from "slate-vue3/core";
|
|
49
42
|
import { withDOM } from "slate-vue3/dom";
|
|
50
43
|
import { withHistory } from "slate-vue3/history";
|
|
@@ -55,19 +48,12 @@ const initialValue = [
|
|
|
55
48
|
children: [{ text: "Let's start" }],
|
|
56
49
|
},
|
|
57
50
|
];
|
|
58
|
-
const renderElement = ({ attributes, children }) =>
|
|
59
|
-
h("p", attributes, children);
|
|
60
51
|
const editor = withHistory(withDOM(createEditor()));
|
|
61
52
|
editor.children = initialValue;
|
|
62
53
|
</script>
|
|
63
54
|
|
|
64
55
|
<template>
|
|
65
|
-
<Slate
|
|
66
|
-
:editor="editor"
|
|
67
|
-
:render-element="renderElement"
|
|
68
|
-
:render-leaf="defaultRenderLeaf"
|
|
69
|
-
:render-placeholder="defaultRenderPlaceHolder"
|
|
70
|
-
>
|
|
56
|
+
<Slate :editor="editor">
|
|
71
57
|
<Editable />
|
|
72
58
|
</Slate>
|
|
73
59
|
</template>
|
|
@@ -113,11 +99,11 @@ Due to the complexity of maintaining multiple packages and the lack of reusabili
|
|
|
113
99
|
|
|
114
100
|
| **Package** | **Version** | **Description** |
|
|
115
101
|
| :------------------------------------------------------- | --------------------------------------------------------------------------------: | :----------------------------------------------- |
|
|
116
|
-
| [`slate-vue3/core`](./packages/slate) |  |  |  |  |  |  | slate's core data model logic. |
|
|
103
|
+
| [`slate-vue3/dom`](./packages/slate-dom) |  | DOM implementation of slate |
|
|
104
|
+
| [`slate-vue3/history`](./packages/slate-history) |  | a plugin that adds undo/redo history to slate. |
|
|
105
|
+
| [`slate-vue3/hyperscript`](./packages/slate-hyperscript) |  | a hyperscript tool to write JSX slate documents! |
|
|
106
|
+
| [`slate-vue3/yjs`](./packages/slate-yjs) |  | integration of `slate-yjs` |
|
|
121
107
|
|
|
122
108
|
<br />
|
|
123
109
|
|
|
@@ -128,17 +114,3 @@ Welcome to provide suggestions on the issue, it would be even better if **`PR`**
|
|
|
128
114
|
`slate-vue3` is [MIT-licensed](./License.md).
|
|
129
115
|
|
|
130
116
|
<br/>
|
|
131
|
-
|
|
132
|
-
### FAQ
|
|
133
|
-
|
|
134
|
-
##### 1. Why do I have to pass renderFunction into <Slate /> component ?
|
|
135
|
-
|
|
136
|
-
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
|
|
137
|
-
|
|
138
|
-
##### 2. Can I use jsx in slate-vue3 ?
|
|
139
|
-
|
|
140
|
-
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
|
|
141
|
-
|
|
142
|
-
##### 3. Why do rendering functions not use vue components ?
|
|
143
|
-
|
|
144
|
-
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
|
|
@@ -2151,7 +2151,9 @@ const Text = {
|
|
|
2151
2151
|
return true;
|
|
2152
2152
|
},
|
|
2153
2153
|
decorations(node, decorations) {
|
|
2154
|
-
let leaves = [
|
|
2154
|
+
let leaves = [
|
|
2155
|
+
{ leaf: { ...node } }
|
|
2156
|
+
];
|
|
2155
2157
|
for (const dec of decorations) {
|
|
2156
2158
|
const { anchor, focus, merge: mergeDecoration, ...rest } = dec;
|
|
2157
2159
|
const [start, end] = Range.edges(dec);
|
|
@@ -2160,16 +2162,17 @@ const Text = {
|
|
|
2160
2162
|
const decorationStart = start.offset;
|
|
2161
2163
|
const decorationEnd = end.offset;
|
|
2162
2164
|
const merge = mergeDecoration ?? Object.assign;
|
|
2163
|
-
for (const leaf of leaves) {
|
|
2165
|
+
for (const { leaf } of leaves) {
|
|
2166
|
+
const { length } = leaf.text;
|
|
2164
2167
|
const leafStart = leafEnd;
|
|
2165
|
-
leafEnd +=
|
|
2168
|
+
leafEnd += length;
|
|
2166
2169
|
if (decorationStart <= leafStart && leafEnd <= decorationEnd) {
|
|
2167
2170
|
merge(leaf, rest);
|
|
2168
|
-
next.push(leaf);
|
|
2171
|
+
next.push({ leaf });
|
|
2169
2172
|
continue;
|
|
2170
2173
|
}
|
|
2171
2174
|
if (decorationStart !== decorationEnd && (decorationStart === leafEnd || decorationEnd === leafStart) || decorationStart > leafEnd || decorationEnd < leafStart || decorationEnd === leafStart && leafStart !== 0) {
|
|
2172
|
-
next.push(leaf);
|
|
2175
|
+
next.push({ leaf });
|
|
2173
2176
|
continue;
|
|
2174
2177
|
}
|
|
2175
2178
|
let middle = leaf;
|
|
@@ -2177,25 +2180,37 @@ const Text = {
|
|
|
2177
2180
|
let after;
|
|
2178
2181
|
if (decorationEnd < leafEnd) {
|
|
2179
2182
|
const off = decorationEnd - leafStart;
|
|
2180
|
-
after = { ...middle, text: middle.text.slice(off) };
|
|
2183
|
+
after = { leaf: { ...middle, text: middle.text.slice(off) } };
|
|
2181
2184
|
middle = { ...middle, text: middle.text.slice(0, off) };
|
|
2182
2185
|
}
|
|
2183
2186
|
if (decorationStart > leafStart) {
|
|
2184
2187
|
const off = decorationStart - leafStart;
|
|
2185
|
-
before = { ...middle, text: middle.text.slice(0, off) };
|
|
2188
|
+
before = { leaf: { ...middle, text: middle.text.slice(0, off) } };
|
|
2186
2189
|
middle = { ...middle, text: middle.text.slice(off) };
|
|
2187
2190
|
}
|
|
2188
2191
|
merge(middle, rest);
|
|
2189
2192
|
if (before) {
|
|
2190
2193
|
next.push(before);
|
|
2191
2194
|
}
|
|
2192
|
-
next.push(middle);
|
|
2195
|
+
next.push({ leaf: middle });
|
|
2193
2196
|
if (after) {
|
|
2194
2197
|
next.push(after);
|
|
2195
2198
|
}
|
|
2196
2199
|
}
|
|
2197
2200
|
leaves = next;
|
|
2198
2201
|
}
|
|
2202
|
+
if (leaves.length > 1) {
|
|
2203
|
+
let currentOffset = 0;
|
|
2204
|
+
for (const [index, item] of leaves.entries()) {
|
|
2205
|
+
const start = currentOffset;
|
|
2206
|
+
const end = start + item.leaf.text.length;
|
|
2207
|
+
const position = { start, end };
|
|
2208
|
+
if (index === 0) position.isFirst = true;
|
|
2209
|
+
if (index === leaves.length - 1) position.isLast = true;
|
|
2210
|
+
item.position = position;
|
|
2211
|
+
currentOffset = end;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2199
2214
|
return leaves;
|
|
2200
2215
|
}
|
|
2201
2216
|
};
|
package/dist/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
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-
|
|
3
|
-
import { L as L2, S as S3 } from "./location-
|
|
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-UR4aFGAf.js";
|
|
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-1Ahs6kkr.js";
|
|
3
|
+
import { L as L2, S as S3 } from "./location-MosjNIh-.js";
|
|
4
4
|
export {
|
|
5
5
|
E2 as Editor,
|
|
6
6
|
a10 as Element,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as Path, b as Point, R as Range, E as Editor, D as DIRTY_PATHS, e as DIRTY_PATH_KEYS, f as isBatchingDirtyPaths, c as Transforms, F as FLUSHING, T as Text, N as Node, a as Element, g as NORMALIZING, h as PATH_REFS, j as POINT_REFS, k as RANGE_REFS, l as cloneDeep, m as getDefaultInsertLocation, S as Scrubber, n as batchDirtyPaths } from "./batch-dirty-paths-
|
|
1
|
+
import { P as Path, b as Point, R as Range, E as Editor, D as DIRTY_PATHS, e as DIRTY_PATH_KEYS, f as isBatchingDirtyPaths, c as Transforms, F as FLUSHING, T as Text, N as Node, a as Element, g as NORMALIZING, h as PATH_REFS, j as POINT_REFS, k as RANGE_REFS, l as cloneDeep, m as getDefaultInsertLocation, S as Scrubber, n as batchDirtyPaths } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
2
2
|
import { reactive } from "vue";
|
|
3
|
-
import { S as Span } from "./location-
|
|
3
|
+
import { S as Span } from "./location-MosjNIh-.js";
|
|
4
4
|
const PathRef = {
|
|
5
5
|
transform(ref, op) {
|
|
6
6
|
const { current, affinity } = ref;
|
package/dist/dom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as DOMEditor, E as EDITOR_TO_KEY_TO_ELEMENT, a as EDITOR_TO_USER_MARKS, b as EDITOR_TO_USER_SELECTION, N as NODE_TO_KEY, i as isDOMText, g as getPlainText, c as getSlateFragmentAttribute, d as EDITOR_TO_ON_CHANGE } from "./hotkeys-
|
|
2
|
-
import { C, F, G, J, H, B, I, u, L, v, w, M, x, O, z, y, A, K, P, Q, R, S, e, f, h, j, k, l, m, o, p, q, r, s, t, n } from "./hotkeys-
|
|
3
|
-
import { E as Editor, R as Range, a as Element, c as Transforms, P as Path, N as Node } from "./batch-dirty-paths-
|
|
1
|
+
import { D as DOMEditor, E as EDITOR_TO_KEY_TO_ELEMENT, a as EDITOR_TO_USER_MARKS, b as EDITOR_TO_USER_SELECTION, N as NODE_TO_KEY, i as isDOMText, g as getPlainText, c as getSlateFragmentAttribute, d as EDITOR_TO_ON_CHANGE } from "./hotkeys-BSLjSKb9.js";
|
|
2
|
+
import { C, F, G, J, H, B, I, u, L, v, w, M, x, O, z, y, A, K, P, Q, R, S, e, f, h, j, k, l, m, o, p, q, r, s, t, n } from "./hotkeys-BSLjSKb9.js";
|
|
3
|
+
import { E as Editor, R as Range, a as Element, c as Transforms, P as Path, N as Node } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
4
4
|
import "vue";
|
|
5
5
|
const doRectsIntersect = (rect, compareRect) => {
|
|
6
6
|
const middle = (compareRect.top + compareRect.bottom) / 2;
|
package/dist/history.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as isPlainObject, O as Operation, t as toRawWeakMap, E as Editor, c as Transforms, P as Path } from "./batch-dirty-paths-
|
|
1
|
+
import { d as isPlainObject, O as Operation, t as toRawWeakMap, E as Editor, c as Transforms, P as Path } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
2
2
|
import "vue";
|
|
3
3
|
const History = {
|
|
4
4
|
/**
|
|
@@ -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 { t as toRawWeakMap, R as Range, E as Editor, S as Scrubber, a as Element, c as Transforms } from "./batch-dirty-paths-
|
|
5
|
+
import { t as toRawWeakMap, R as Range, E as Editor, S as Scrubber, a as Element, c as Transforms } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
6
6
|
import "vue";
|
|
7
7
|
const getDefaultView = (value) => {
|
|
8
8
|
return value && value.ownerDocument && value.ownerDocument.defaultView || null;
|
package/dist/hyperscript.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
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
|
-
import { t as toRawWeakMap, R as Range, N as Node, T as Text, a as Element, d as isPlainObject } from "./batch-dirty-paths-
|
|
5
|
-
import { c as createEditor$1 } from "./create-editor-
|
|
4
|
+
import { t as toRawWeakMap, R as Range, N as Node, T as Text, a as Element, d as isPlainObject } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
5
|
+
import { c as createEditor$1 } from "./create-editor-UR4aFGAf.js";
|
|
6
6
|
import "vue";
|
|
7
7
|
const ANCHOR = new toRawWeakMap();
|
|
8
8
|
const FOCUS = new toRawWeakMap();
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as SLATE_USE_SELECTED, a as SLATE_STATE_SELECTION } from "./use-focused-
|
|
2
|
-
import {
|
|
1
|
+
import { S as SLATE_USE_SELECTED, a as SLATE_STATE_SELECTION } from "./use-focused-BlttbYui.js";
|
|
2
|
+
import { g, D, c, e, f, d, E, b, u, j, h, i } from "./use-focused-BlttbYui.js";
|
|
3
3
|
import { inject } from "vue";
|
|
4
|
-
import { t } from "./batch-dirty-paths-
|
|
4
|
+
import { t } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
5
5
|
const useSelected = () => {
|
|
6
6
|
const selected = inject(SLATE_USE_SELECTED);
|
|
7
7
|
if (selected === void 0) {
|
|
@@ -34,16 +34,20 @@ const useInheritRef = (attribute) => {
|
|
|
34
34
|
return attribute;
|
|
35
35
|
};
|
|
36
36
|
export {
|
|
37
|
+
g as DEFAULT_DECORATE_FN,
|
|
38
|
+
D as DEFAULT_ELEMENT_RENDER,
|
|
39
|
+
c as DEFAULT_LEAF_RENDER,
|
|
40
|
+
e as DEFAULT_PLACEHOLDER_RENDER,
|
|
41
|
+
f as DEFAULT_SCROLL_INTO_VIEW,
|
|
42
|
+
d as DEFAULT_TEXT_RENDER,
|
|
37
43
|
E as Editable,
|
|
38
44
|
b as Slate,
|
|
39
|
-
d as defaultRenderLeaf,
|
|
40
|
-
c as defaultRenderPlaceHolder,
|
|
41
45
|
t as toRawWeakMap,
|
|
42
46
|
u as useComposing,
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
j as useEditor,
|
|
48
|
+
h as useFocused,
|
|
45
49
|
useInheritRef,
|
|
46
|
-
|
|
50
|
+
i as useReadOnly,
|
|
47
51
|
useSelected,
|
|
48
52
|
useSelection
|
|
49
53
|
};
|
|
@@ -7,8 +7,15 @@ import { ExtendedType } from '../types/custom-types';
|
|
|
7
7
|
*/
|
|
8
8
|
export interface BaseText {
|
|
9
9
|
text: string;
|
|
10
|
+
decoration?: number[];
|
|
10
11
|
}
|
|
11
12
|
export type Text = ExtendedType<'Text', BaseText>;
|
|
13
|
+
export interface LeafPosition {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
isFirst?: true;
|
|
17
|
+
isLast?: true;
|
|
18
|
+
}
|
|
12
19
|
export interface TextEqualsOptions {
|
|
13
20
|
loose?: boolean;
|
|
14
21
|
}
|
|
@@ -49,6 +56,9 @@ export interface TextInterface {
|
|
|
49
56
|
/**
|
|
50
57
|
* Get the leaves for a text node given decorations.
|
|
51
58
|
*/
|
|
52
|
-
decorations: (node: Text, decorations: DecoratedRange[]) =>
|
|
59
|
+
decorations: (node: Text, decorations: DecoratedRange[]) => {
|
|
60
|
+
leaf: Text;
|
|
61
|
+
position?: LeafPosition;
|
|
62
|
+
}[];
|
|
53
63
|
}
|
|
54
64
|
export declare const Text: TextInterface;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { VNode } from 'vue';
|
|
2
2
|
import { DecoratedRange, NodeEntry } from '../../slate/index.ts';
|
|
3
|
-
import { RenderElementProps, RenderLeafProps, RenderPlaceholderProps } from '../utils/interface';
|
|
3
|
+
import { RenderElementProps, RenderLeafProps, RenderPlaceholderProps, RenderTextProps } from '../utils/interface';
|
|
4
4
|
import { DOMEditor } from '../../slate-dom/index.ts';
|
|
5
5
|
export declare const Slate: import('vue').DefineComponent<{
|
|
6
6
|
editor: DOMEditor;
|
|
7
7
|
decorate: (entry: NodeEntry) => DecoratedRange[];
|
|
8
8
|
renderElement: (props: RenderElementProps) => VNode;
|
|
9
9
|
renderLeaf: (props: RenderLeafProps) => VNode;
|
|
10
|
+
renderText?: ((props: RenderTextProps) => VNode) | undefined;
|
|
10
11
|
renderPlaceholder: (props: RenderPlaceholderProps) => VNode;
|
|
11
12
|
}, () => VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
12
13
|
[key: string]: any;
|
|
@@ -15,6 +16,7 @@ export declare const Slate: import('vue').DefineComponent<{
|
|
|
15
16
|
decorate: (entry: NodeEntry) => DecoratedRange[];
|
|
16
17
|
renderElement: (props: RenderElementProps) => VNode;
|
|
17
18
|
renderLeaf: (props: RenderLeafProps) => VNode;
|
|
19
|
+
renderText?: ((props: RenderTextProps) => VNode) | undefined;
|
|
18
20
|
renderPlaceholder: (props: RenderPlaceholderProps) => VNode;
|
|
19
21
|
}> & Readonly<{
|
|
20
22
|
onChange?: ((...args: any[]) => any) | undefined;
|
|
@@ -22,4 +24,8 @@ export declare const Slate: import('vue').DefineComponent<{
|
|
|
22
24
|
onValuechange?: ((...args: any[]) => any) | undefined;
|
|
23
25
|
}>, {
|
|
24
26
|
decorate: Function;
|
|
27
|
+
renderElement: Function;
|
|
28
|
+
renderLeaf: Function;
|
|
29
|
+
renderText: Function;
|
|
30
|
+
renderPlaceholder: Function;
|
|
25
31
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Editor } from '../../slate/index.ts';
|
|
2
2
|
import { DOMEditor } from '../../slate-dom/index.ts';
|
|
3
|
-
import { RenderLeafProps, RenderPlaceholderProps } from '../utils/interface';
|
|
3
|
+
import { RenderElementProps, RenderTextProps, RenderLeafProps, RenderPlaceholderProps } from '../utils/interface';
|
|
4
4
|
/**
|
|
5
5
|
* Check if an event is overrided by a handler.
|
|
6
6
|
*/
|
|
@@ -17,11 +17,17 @@ export declare const handleNativeHistoryEvents: (editor: Editor, event: InputEve
|
|
|
17
17
|
/**
|
|
18
18
|
* A default implement to scroll dom range into view.
|
|
19
19
|
*/
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
20
|
+
export declare const DEFAULT_SCROLL_INTO_VIEW: (editor: DOMEditor, domRange: globalThis.Range) => void;
|
|
21
|
+
export declare const DEFAULT_ELEMENT_RENDER: ({ attributes, children, }: RenderElementProps) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
22
22
|
[key: string]: any;
|
|
23
23
|
}>;
|
|
24
|
-
export declare const
|
|
24
|
+
export declare const DEFAULT_LEAF_RENDER: ({ attributes, children, }: RenderLeafProps) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const DEFAULT_TEXT_RENDER: ({ attributes, children, }: RenderTextProps) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const DEFAULT_PLACEHOLDER_RENDER: ({ attributes, children, }: RenderPlaceholderProps) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
25
31
|
[key: string]: any;
|
|
26
32
|
}>;
|
|
27
33
|
export declare const DEFAULT_DECORATE_FN: () => never[];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ComputedRef, Ref, VNode } from 'vue';
|
|
2
|
-
import { RenderElementProps, RenderPlaceholderProps, RenderLeafProps } from '../utils/interface';
|
|
2
|
+
import { RenderElementProps, RenderPlaceholderProps, RenderLeafProps, RenderTextProps } from '../utils/interface';
|
|
3
3
|
import { BasePoint } from '../../slate/index.ts';
|
|
4
4
|
export declare const useRenderElement: () => (props: RenderElementProps) => VNode;
|
|
5
5
|
export declare const useRenderLeaf: () => (props: RenderLeafProps) => VNode;
|
|
6
6
|
export declare const useRenderPlaceholder: () => (props: RenderPlaceholderProps) => VNode;
|
|
7
|
+
export declare const useRenderText: () => (props: RenderTextProps) => VNode;
|
|
7
8
|
export declare const useChangeEffect: (fn: () => void) => Ref<number, number>;
|
|
8
9
|
export declare const useMarkPlaceholder: () => ComputedRef<{
|
|
9
10
|
anchor: BasePoint;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export type { RenderElementProps, RenderLeafProps, RenderPlaceholderProps, } from './utils/interface';
|
|
2
2
|
export { Slate } from './components/slate';
|
|
3
3
|
export { Editable } from './components/editable';
|
|
4
|
-
export {
|
|
5
|
-
export { defaultRenderPlaceHolder } from './components/utils';
|
|
4
|
+
export { DEFAULT_ELEMENT_RENDER, DEFAULT_LEAF_RENDER, DEFAULT_TEXT_RENDER, DEFAULT_PLACEHOLDER_RENDER, DEFAULT_SCROLL_INTO_VIEW, DEFAULT_DECORATE_FN, } from './components/utils';
|
|
6
5
|
export { useComposing } from './hooks/use-composing';
|
|
7
6
|
export { useFocused } from './hooks/use-focused';
|
|
8
7
|
export { useReadOnly } from './hooks/use-read-only';
|
|
@@ -9,5 +9,6 @@ export declare const SLATE_STATE_SELECTION: unique symbol;
|
|
|
9
9
|
export declare const SLATE_INNER_RENDER_ELEMENT: unique symbol;
|
|
10
10
|
export declare const SLATE_INNER_RENDER_LEAF: unique symbol;
|
|
11
11
|
export declare const SLATE_INNER_RENDER_PLACEHOLDER: unique symbol;
|
|
12
|
+
export declare const SLATE_INNER_RENDER_TEXT: unique symbol;
|
|
12
13
|
export declare const SLATE_INNER_CHANGE_EFFECT_INJECT: unique symbol;
|
|
13
14
|
export declare const SLATE_INNER_MARK_PLACEHOLDER: unique symbol;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Text, Element } from '../../slate/index.ts';
|
|
2
|
-
import { HTMLAttributes, VNode, VNodeProps } from 'vue';
|
|
1
|
+
import { Text, Element, LeafPosition } from '../../slate/index.ts';
|
|
2
|
+
import { HTMLAttributes, VNode, VNodeChild, VNodeProps, VNodeRef } from 'vue';
|
|
3
3
|
/**
|
|
4
4
|
* The props that get passed to renderPlaceholder
|
|
5
5
|
*/
|
|
@@ -15,11 +15,19 @@ export interface RenderPlaceholderProps {
|
|
|
15
15
|
*/
|
|
16
16
|
export interface RenderLeafProps {
|
|
17
17
|
children: VNode;
|
|
18
|
+
/**
|
|
19
|
+
* The leaf node with any applied decorations.
|
|
20
|
+
* If no decorations are applied, it will be identical to the `text` property.
|
|
21
|
+
*/
|
|
18
22
|
leaf: Text;
|
|
19
23
|
text: Text;
|
|
20
24
|
attributes: HTMLAttributes & {
|
|
21
25
|
"data-slate-leaf": true;
|
|
22
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* The position of the leaf within the Text node, only present when the text node is split by decorations.
|
|
29
|
+
*/
|
|
30
|
+
leafPosition?: LeafPosition;
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
25
33
|
* `RenderElementProps` are passed to the `renderElement` handler.
|
|
@@ -32,6 +40,17 @@ export interface RenderElementProps {
|
|
|
32
40
|
"data-slate-inline"?: true;
|
|
33
41
|
"data-slate-void"?: true;
|
|
34
42
|
dir?: "rtl";
|
|
35
|
-
ref:
|
|
43
|
+
ref: VNodeRef;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* `RenderTextProps` are passed to the `renderText` handler.
|
|
48
|
+
*/
|
|
49
|
+
export interface RenderTextProps {
|
|
50
|
+
text: Text;
|
|
51
|
+
children: VNodeChild[];
|
|
52
|
+
attributes: {
|
|
53
|
+
'data-slate-node': 'text';
|
|
54
|
+
ref: VNodeRef;
|
|
36
55
|
};
|
|
37
56
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { h, defineComponent, provide, ref, computed, onMounted, onUnmounted, renderSlot, inject, watch, renderList, Fragment, useAttrs, reactive, toRaw } from "vue";
|
|
2
|
-
import { R as Range, N as Node, S as Scrubber, T as Text, P as Path, E as Editor, a as Element, c as Transforms } from "./batch-dirty-paths-
|
|
3
|
-
import {
|
|
2
|
+
import { R as Range, N as Node, S as Scrubber, T as Text, P as Path, E as Editor, a as Element, c as Transforms } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
3
|
+
import { I as IS_ANDROID, p as isDOMNode, D as DOMEditor, P as MARK_PLACEHOLDER_SYMBOL, d as EDITOR_TO_ON_CHANGE, x as IS_IOS, E as EDITOR_TO_KEY_TO_ELEMENT, J as ELEMENT_TO_NODE, Q as NODE_TO_ELEMENT, R as NODE_TO_INDEX, S as NODE_TO_PARENT, y as IS_WEBKIT, e as applyStringDiff, q as isDOMSelection, n as normalizeStringDiff, O as IS_READ_ONLY, h as getDefaultView, G as EDITOR_TO_WINDOW, F as EDITOR_TO_ELEMENT, H as HAS_BEFORE_INPUT_SUPPORT, C as CAN_USE_DOM, f as getActiveElement, j as getSelection, M as IS_FOCUSED, r as isPlainTextOnlyPaste, L as IS_COMPOSING, B as Hotkeys, u as IS_CHROME, v as IS_FIREFOX, w as IS_FIREFOX_LEGACY, A as IS_WECHATBROWSER, z as IS_UC_MOBILE, a as EDITOR_TO_USER_MARKS, o as isDOMElement, b as EDITOR_TO_USER_SELECTION } from "./hotkeys-BSLjSKb9.js";
|
|
4
4
|
const SLATE_USE_EDITOR = Symbol("SLATE_USE_EDITOR");
|
|
5
5
|
const SLATE_USE_DECORATE = Symbol("SLATE_USE_DECORATE");
|
|
6
6
|
const SLATE_USE_SELECTED = Symbol("SLATE_USE_SELECTED");
|
|
@@ -11,6 +11,7 @@ const SLATE_STATE_SELECTION = Symbol("SLATE_STATE_SELECTION");
|
|
|
11
11
|
const SLATE_INNER_RENDER_ELEMENT = Symbol("SLATE_INNER_RENDER_ELEMENT");
|
|
12
12
|
const SLATE_INNER_RENDER_LEAF = Symbol("SLATE_INNER_RENDER_LEAF");
|
|
13
13
|
const SLATE_INNER_RENDER_PLACEHOLDER = Symbol("SLATE_INNER_RENDER_PLACEHOLDER");
|
|
14
|
+
const SLATE_INNER_RENDER_TEXT = Symbol("SLATE_INNER_RENDER_TEXT");
|
|
14
15
|
const SLATE_INNER_CHANGE_EFFECT_INJECT = Symbol("SLATE_INNER_CHANGE_EFFECT_INJECT");
|
|
15
16
|
const SLATE_INNER_MARK_PLACEHOLDER = Symbol("SLATE_INNER_MARK_PLACEHOLDER");
|
|
16
17
|
const t = (t2) => "object" == typeof t2 && null != t2 && 1 === t2.nodeType, e$1 = (t2, e2) => (!e2 || "hidden" !== t2) && ("visible" !== t2 && "clip" !== t2), n = (t2, n2) => {
|
|
@@ -120,7 +121,7 @@ const handleNativeHistoryEvents = (editor, event) => {
|
|
|
120
121
|
editor.redo();
|
|
121
122
|
}
|
|
122
123
|
};
|
|
123
|
-
const
|
|
124
|
+
const DEFAULT_SCROLL_INTO_VIEW = (editor, domRange) => {
|
|
124
125
|
if (domRange.getBoundingClientRect && (!editor.selection || editor.selection && Range.isCollapsed(editor.selection))) {
|
|
125
126
|
const leafEl = domRange.startContainer.parentElement;
|
|
126
127
|
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange);
|
|
@@ -130,19 +131,22 @@ const defaultScrollSelectionIntoView = (editor, domRange) => {
|
|
|
130
131
|
delete leafEl.getBoundingClientRect;
|
|
131
132
|
}
|
|
132
133
|
};
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
134
|
+
const DEFAULT_ELEMENT_RENDER = ({
|
|
135
|
+
attributes,
|
|
136
|
+
children
|
|
137
|
+
}) => h("p", attributes, children);
|
|
138
|
+
const DEFAULT_LEAF_RENDER = ({
|
|
139
|
+
attributes,
|
|
140
|
+
children
|
|
141
|
+
}) => h("span", attributes, children);
|
|
142
|
+
const DEFAULT_TEXT_RENDER = ({
|
|
143
|
+
attributes,
|
|
144
|
+
children
|
|
145
|
+
}) => h("span", attributes, children);
|
|
146
|
+
const DEFAULT_PLACEHOLDER_RENDER = ({
|
|
147
|
+
attributes,
|
|
148
|
+
children
|
|
149
|
+
}) => h("span", attributes, [children, IS_ANDROID ? h("br") : void 0]);
|
|
146
150
|
const DEFAULT_DECORATE_FN = () => [];
|
|
147
151
|
const Slate = defineComponent({
|
|
148
152
|
name: "slate-editor",
|
|
@@ -158,19 +162,23 @@ const Slate = defineComponent({
|
|
|
158
162
|
},
|
|
159
163
|
renderElement: {
|
|
160
164
|
type: Function,
|
|
161
|
-
|
|
165
|
+
default: DEFAULT_ELEMENT_RENDER
|
|
162
166
|
},
|
|
163
167
|
renderLeaf: {
|
|
164
168
|
type: Function,
|
|
165
|
-
|
|
169
|
+
default: DEFAULT_LEAF_RENDER
|
|
170
|
+
},
|
|
171
|
+
renderText: {
|
|
172
|
+
type: Function,
|
|
173
|
+
default: DEFAULT_TEXT_RENDER
|
|
166
174
|
},
|
|
167
175
|
renderPlaceholder: {
|
|
168
176
|
type: Function,
|
|
169
|
-
|
|
177
|
+
default: DEFAULT_PLACEHOLDER_RENDER
|
|
170
178
|
}
|
|
171
179
|
},
|
|
172
180
|
setup(props, { slots, emit }) {
|
|
173
|
-
const { editor, decorate, renderElement, renderLeaf, renderPlaceholder } = props;
|
|
181
|
+
const { editor, decorate, renderElement, renderLeaf, renderPlaceholder, renderText } = props;
|
|
174
182
|
if (!Node.isNodeList(editor.children)) {
|
|
175
183
|
throw new Error(
|
|
176
184
|
`[Slate] initialValue is invalid! Expected a list of elements but got: ${Scrubber.stringify(
|
|
@@ -182,6 +190,7 @@ const Slate = defineComponent({
|
|
|
182
190
|
provide(SLATE_USE_DECORATE, decorate);
|
|
183
191
|
provide(SLATE_INNER_RENDER_ELEMENT, renderElement);
|
|
184
192
|
provide(SLATE_INNER_RENDER_LEAF, renderLeaf);
|
|
193
|
+
provide(SLATE_INNER_RENDER_TEXT, renderText);
|
|
185
194
|
provide(SLATE_INNER_RENDER_PLACEHOLDER, renderPlaceholder);
|
|
186
195
|
const isFocus = ref(DOMEditor.isFocused(editor));
|
|
187
196
|
const selection = computed(() => editor.selection);
|
|
@@ -329,6 +338,17 @@ const useRenderPlaceholder = () => {
|
|
|
329
338
|
}
|
|
330
339
|
return PLACEHOLDER_RENDER;
|
|
331
340
|
};
|
|
341
|
+
const useRenderText = () => {
|
|
342
|
+
const TEXT_RENDER = inject(
|
|
343
|
+
SLATE_INNER_RENDER_TEXT
|
|
344
|
+
);
|
|
345
|
+
if (TEXT_RENDER === void 0) {
|
|
346
|
+
throw new Error(
|
|
347
|
+
`The \`useRenderText\` hook must be used inside the <Slate> component's context.`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
return TEXT_RENDER;
|
|
351
|
+
};
|
|
332
352
|
const useChangeEffect = (fn) => {
|
|
333
353
|
const CHANGE_EFFECT_INJECT = inject(
|
|
334
354
|
SLATE_INNER_CHANGE_EFFECT_INJECT
|
|
@@ -361,7 +381,7 @@ const TextComp = defineComponent({
|
|
|
361
381
|
const markPlaceholder = useMarkPlaceholder();
|
|
362
382
|
const leaves = computed(() => {
|
|
363
383
|
if (decorate === DEFAULT_DECORATE_FN) {
|
|
364
|
-
return [text];
|
|
384
|
+
return [{ leaf: text }];
|
|
365
385
|
}
|
|
366
386
|
const elemPath = DOMEditor.findPath(editor, element);
|
|
367
387
|
const textPath = DOMEditor.findPath(editor, text);
|
|
@@ -398,25 +418,27 @@ const TextComp = defineComponent({
|
|
|
398
418
|
return !isVoid && isLeafBlock && NODE_TO_INDEX.get(text) === element.children.length - 1;
|
|
399
419
|
});
|
|
400
420
|
const renderLeaf = useRenderLeaf();
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
421
|
+
const renderText = useRenderText();
|
|
422
|
+
return () => renderText({
|
|
423
|
+
text,
|
|
424
|
+
attributes: { "data-slate-node": "text", ref: spanRef },
|
|
425
|
+
children: renderList(
|
|
405
426
|
leaves.value,
|
|
406
427
|
(leaf, i) => renderLeaf({
|
|
407
428
|
text,
|
|
408
|
-
leaf,
|
|
429
|
+
leaf: leaf.leaf,
|
|
430
|
+
leafPosition: leaf.position,
|
|
409
431
|
attributes: { "data-slate-leaf": true },
|
|
410
432
|
children: h(StringComp, {
|
|
411
433
|
text,
|
|
412
434
|
element,
|
|
413
|
-
leaf,
|
|
435
|
+
leaf: leaf.leaf,
|
|
414
436
|
isLast: isLastText.value && i === leaves.value.length - 1,
|
|
415
|
-
key: `${text.text}-${leaf.text}-${i}`
|
|
437
|
+
key: `${text.text}-${leaf.leaf.text}-${i}`
|
|
416
438
|
})
|
|
417
439
|
})
|
|
418
440
|
)
|
|
419
|
-
);
|
|
441
|
+
});
|
|
420
442
|
}
|
|
421
443
|
});
|
|
422
444
|
const useReadOnly = () => {
|
|
@@ -864,7 +886,7 @@ const Editable = defineComponent({
|
|
|
864
886
|
scrollSelectionIntoView: {
|
|
865
887
|
type: Function,
|
|
866
888
|
required: false,
|
|
867
|
-
default:
|
|
889
|
+
default: DEFAULT_SCROLL_INTO_VIEW
|
|
868
890
|
},
|
|
869
891
|
placeholder: { type: String },
|
|
870
892
|
readOnly: {
|
|
@@ -1092,10 +1114,6 @@ const Editable = defineComponent({
|
|
|
1092
1114
|
const deferredOperations = ref([]);
|
|
1093
1115
|
const onBeforeinput = (event) => {
|
|
1094
1116
|
var _a, _b, _c, _d, _e;
|
|
1095
|
-
const isInputEvent = event instanceof InputEvent;
|
|
1096
|
-
if (!isInputEvent) {
|
|
1097
|
-
return;
|
|
1098
|
-
}
|
|
1099
1117
|
if (HAS_BEFORE_INPUT_SUPPORT) {
|
|
1100
1118
|
handleNativeHistoryEvents(editor, event);
|
|
1101
1119
|
const el = DOMEditor.toDOMNode(editor, editor);
|
|
@@ -1763,14 +1781,18 @@ const useFocused = () => {
|
|
|
1763
1781
|
return isFocus;
|
|
1764
1782
|
};
|
|
1765
1783
|
export {
|
|
1784
|
+
DEFAULT_ELEMENT_RENDER as D,
|
|
1766
1785
|
Editable as E,
|
|
1767
1786
|
SLATE_USE_SELECTED as S,
|
|
1768
1787
|
SLATE_STATE_SELECTION as a,
|
|
1769
1788
|
Slate as b,
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1789
|
+
DEFAULT_LEAF_RENDER as c,
|
|
1790
|
+
DEFAULT_TEXT_RENDER as d,
|
|
1791
|
+
DEFAULT_PLACEHOLDER_RENDER as e,
|
|
1792
|
+
DEFAULT_SCROLL_INTO_VIEW as f,
|
|
1793
|
+
DEFAULT_DECORATE_FN as g,
|
|
1794
|
+
useFocused as h,
|
|
1795
|
+
useReadOnly as i,
|
|
1796
|
+
useEditor as j,
|
|
1775
1797
|
useComposing as u
|
|
1776
1798
|
};
|
package/dist/yjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { d as isPlainObject, T as Text, N as Node, P as Path, E as Editor, t as toRawWeakMap, c as Transforms, R as Range } from "./batch-dirty-paths-
|
|
1
|
+
import { d as isPlainObject, T as Text, N as Node, P as Path, E as Editor, t as toRawWeakMap, c as Transforms, R as Range } from "./batch-dirty-paths-1Ahs6kkr.js";
|
|
2
2
|
import { toRaw, ref, onMounted, onUnmounted, watch, onUpdated, computed } from "vue";
|
|
3
3
|
import { XmlText, YTextEvent, createRelativePositionFromTypeIndex, createAbsolutePositionFromRelativePosition, createRelativePositionFromJSON, decodeRelativePosition, encodeRelativePosition, UndoManager, compareRelativePositions } from "yjs";
|
|
4
|
-
import { L as Location } from "./location-
|
|
5
|
-
import {
|
|
6
|
-
import { D as DOMEditor } from "./hotkeys-
|
|
4
|
+
import { L as Location } from "./location-MosjNIh-.js";
|
|
5
|
+
import { j as useEditor, h as useFocused } from "./use-focused-BlttbYui.js";
|
|
6
|
+
import { D as DOMEditor } from "./hotkeys-BSLjSKb9.js";
|
|
7
7
|
function deepEquals(node, another) {
|
|
8
8
|
for (const key in node) {
|
|
9
9
|
const a = node[key];
|