slate-vue3 0.13.7 → 0.13.8
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/dist/hyperscript.js +122 -37
- package/dist/slate-hyperscript/creators.d.ts +7 -1
- package/dist/slate-hyperscript/hyperscript.d.ts +3 -2
- package/dist/slate-hyperscript/index.d.ts +4 -2
- package/dist/slate-hyperscript/refs.d.ts +19 -0
- package/dist/slate-hyperscript/tokens.d.ts +29 -19
- package/package.json +2 -2
package/dist/hyperscript.js
CHANGED
|
@@ -2,48 +2,88 @@ import { R as Range, N as Node, T as Text, a as Element, e as isObject } from ".
|
|
|
2
2
|
import { h as createEditor$1 } from "./create-editor-D66_fXbO.js";
|
|
3
3
|
import "vue";
|
|
4
4
|
import { t as toRawWeakMap } from "./index-Ban80MbP.js";
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const ANCHORS = new toRawWeakMap();
|
|
6
|
+
const FOCI = new toRawWeakMap();
|
|
7
|
+
const POINTS = new toRawWeakMap();
|
|
7
8
|
class Token {
|
|
8
|
-
}
|
|
9
|
-
class AnchorToken extends Token {
|
|
10
9
|
offset;
|
|
11
10
|
path;
|
|
11
|
+
ref;
|
|
12
12
|
constructor(props = {}) {
|
|
13
|
-
|
|
14
|
-
const { offset, path } = props;
|
|
13
|
+
const { offset, path, ref } = props;
|
|
15
14
|
this.offset = offset;
|
|
16
15
|
this.path = path;
|
|
16
|
+
if (ref) {
|
|
17
|
+
if (path != null) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"The ref prop of a token cannot be used with the path prop."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
this.ref = ref;
|
|
23
|
+
}
|
|
17
24
|
}
|
|
18
25
|
}
|
|
26
|
+
class AnchorToken extends Token {
|
|
27
|
+
}
|
|
19
28
|
class FocusToken extends Token {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
}
|
|
30
|
+
class PointToken extends Token {
|
|
31
|
+
}
|
|
32
|
+
function addAnchorToken(text, token) {
|
|
33
|
+
const offset = text.text.length;
|
|
34
|
+
let anchors = ANCHORS.get(text);
|
|
35
|
+
if (!anchors) {
|
|
36
|
+
anchors = /* @__PURE__ */ new Set();
|
|
37
|
+
ANCHORS.set(text, anchors);
|
|
27
38
|
}
|
|
39
|
+
anchors.add([offset, token]);
|
|
40
|
+
}
|
|
41
|
+
function getAnchors(text) {
|
|
42
|
+
const anchors = ANCHORS.get(text);
|
|
43
|
+
if (!anchors) return [];
|
|
44
|
+
return Array.from(
|
|
45
|
+
anchors.values(),
|
|
46
|
+
([offset, token]) => new AnchorToken({ ...token, offset })
|
|
47
|
+
);
|
|
28
48
|
}
|
|
29
|
-
|
|
49
|
+
function addFocusToken(text, token) {
|
|
30
50
|
const offset = text.text.length;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
51
|
+
let foci = FOCI.get(text);
|
|
52
|
+
if (!foci) {
|
|
53
|
+
foci = /* @__PURE__ */ new Set();
|
|
54
|
+
FOCI.set(text, foci);
|
|
55
|
+
}
|
|
56
|
+
foci.add([offset, token]);
|
|
57
|
+
}
|
|
58
|
+
function getFoci(text) {
|
|
59
|
+
const foci = FOCI.get(text);
|
|
60
|
+
if (!foci) return [];
|
|
61
|
+
return Array.from(
|
|
62
|
+
foci.values(),
|
|
63
|
+
([offset, token]) => new FocusToken({ ...token, offset })
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
function addPointToken(text, token) {
|
|
37
67
|
const offset = text.text.length;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
68
|
+
let points = POINTS.get(text);
|
|
69
|
+
if (!points) {
|
|
70
|
+
points = /* @__PURE__ */ new Set();
|
|
71
|
+
POINTS.set(text, points);
|
|
72
|
+
}
|
|
73
|
+
points.add([offset, token]);
|
|
74
|
+
}
|
|
75
|
+
function getPoints(text) {
|
|
76
|
+
const points = POINTS.get(text);
|
|
77
|
+
if (!points) return [];
|
|
78
|
+
return Array.from(
|
|
79
|
+
points.values(),
|
|
80
|
+
([offset, token]) => new PointToken({ ...token, offset })
|
|
81
|
+
);
|
|
82
|
+
}
|
|
43
83
|
const STRINGS = /* @__PURE__ */ new WeakSet();
|
|
44
|
-
|
|
84
|
+
function resolveDescendants(children) {
|
|
45
85
|
const nodes = [];
|
|
46
|
-
|
|
86
|
+
function addChild(child) {
|
|
47
87
|
if (child == null) {
|
|
48
88
|
return;
|
|
49
89
|
}
|
|
@@ -72,16 +112,18 @@ const resolveDescendants = (children) => {
|
|
|
72
112
|
addAnchorToken(n, child);
|
|
73
113
|
} else if (child instanceof FocusToken) {
|
|
74
114
|
addFocusToken(n, child);
|
|
115
|
+
} else if (child instanceof PointToken) {
|
|
116
|
+
addPointToken(n, child);
|
|
75
117
|
}
|
|
76
118
|
} else {
|
|
77
119
|
throw new Error(`Unexpected hyperscript child object: ${child}`);
|
|
78
120
|
}
|
|
79
|
-
}
|
|
121
|
+
}
|
|
80
122
|
for (const child of children.flat(Infinity)) {
|
|
81
123
|
addChild(child);
|
|
82
124
|
}
|
|
83
125
|
return nodes;
|
|
84
|
-
}
|
|
126
|
+
}
|
|
85
127
|
function createAnchor(tagName, attributes, children) {
|
|
86
128
|
return new AnchorToken(attributes);
|
|
87
129
|
}
|
|
@@ -97,6 +139,9 @@ function createFocus(tagName, attributes, children) {
|
|
|
97
139
|
function createFragment(tagName, attributes, children) {
|
|
98
140
|
return resolveDescendants(children);
|
|
99
141
|
}
|
|
142
|
+
function createPoint(tagName, attributes, children) {
|
|
143
|
+
return new PointToken(attributes);
|
|
144
|
+
}
|
|
100
145
|
function createSelection(tagName, attributes, children) {
|
|
101
146
|
const anchor = children.find(
|
|
102
147
|
(c) => c instanceof AnchorToken
|
|
@@ -161,15 +206,21 @@ const createEditor = (makeEditor) => (tagName, attributes, children) => {
|
|
|
161
206
|
Object.assign(editor, attributes);
|
|
162
207
|
editor.children = descendants;
|
|
163
208
|
for (const [node, path] of Node.texts(editor)) {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
209
|
+
for (const { ref = selection, offset } of getAnchors(node)) {
|
|
210
|
+
if (offset != null) {
|
|
211
|
+
ref.anchor = { path, offset };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const { ref = selection, offset } of getFoci(node)) {
|
|
215
|
+
if (offset != null) {
|
|
216
|
+
ref.focus = { path, offset };
|
|
217
|
+
}
|
|
169
218
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
219
|
+
for (const { ref, offset } of getPoints(node)) {
|
|
220
|
+
if (ref) {
|
|
221
|
+
ref.offset = offset;
|
|
222
|
+
ref.path = path;
|
|
223
|
+
}
|
|
173
224
|
}
|
|
174
225
|
}
|
|
175
226
|
if (selection.anchor && !selection.focus) {
|
|
@@ -196,6 +247,7 @@ const DEFAULT_CREATORS = {
|
|
|
196
247
|
element: createElement,
|
|
197
248
|
focus: createFocus,
|
|
198
249
|
fragment: createFragment,
|
|
250
|
+
point: createPoint,
|
|
199
251
|
selection: createSelection,
|
|
200
252
|
text: createText
|
|
201
253
|
};
|
|
@@ -244,8 +296,41 @@ const normalizeElements = (elements) => {
|
|
|
244
296
|
}
|
|
245
297
|
return creators;
|
|
246
298
|
};
|
|
299
|
+
class HyperscriptPointRef {
|
|
300
|
+
path;
|
|
301
|
+
offset;
|
|
302
|
+
point() {
|
|
303
|
+
const { path, offset } = this;
|
|
304
|
+
if (path == null || offset == null) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
"A HyperscriptPointRef must be passed as the ref prop of a <point /> tag that is used inside an <editor>."
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
return { path, offset };
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
class HyperscriptRangeRef {
|
|
313
|
+
anchor;
|
|
314
|
+
focus;
|
|
315
|
+
range() {
|
|
316
|
+
const { anchor, focus } = this;
|
|
317
|
+
if (anchor == null) {
|
|
318
|
+
throw new Error(
|
|
319
|
+
"A HyperscriptRangeRef must be passed as the ref prop of an <anchor /> tag that is used inside an <editor>."
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
if (focus == null) {
|
|
323
|
+
throw new Error(
|
|
324
|
+
"A HyperscriptRangeRef must be passed as the ref prop of a <focus /> tag that is used inside an <editor>."
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
return { anchor, focus };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
247
330
|
const jsx = createHyperscript();
|
|
248
331
|
export {
|
|
332
|
+
HyperscriptPointRef,
|
|
333
|
+
HyperscriptRangeRef,
|
|
249
334
|
createEditor,
|
|
250
335
|
createHyperscript,
|
|
251
336
|
createText,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Element, Descendant, Range, Text, Editor } from '../slate/index.ts';
|
|
2
|
-
import { AnchorToken, FocusToken, Token } from './tokens';
|
|
2
|
+
import { AnchorToken, FocusToken, PointToken, Token } from './tokens';
|
|
3
3
|
/**
|
|
4
4
|
* Create an anchor token.
|
|
5
5
|
*/
|
|
@@ -30,6 +30,12 @@ export declare function createFocus(tagName: string, attributes: {
|
|
|
30
30
|
export declare function createFragment(tagName: string, attributes: {
|
|
31
31
|
[key: string]: any;
|
|
32
32
|
}, children: any[]): Descendant[];
|
|
33
|
+
/**
|
|
34
|
+
* Create a point token.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPoint(tagName: string, attributes: {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}, children: any[]): PointToken;
|
|
33
39
|
/**
|
|
34
40
|
* Create a `Selection` object.
|
|
35
41
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createAnchor, createCursor, createElement, createFocus, createFragment, createSelection, createText } from './creators';
|
|
1
|
+
import { createAnchor, createCursor, createElement, createFocus, createPoint, createFragment, createSelection, createText } from './creators';
|
|
2
2
|
/**
|
|
3
3
|
* `HyperscriptCreators` are dictionaries of `HyperscriptCreator` functions
|
|
4
4
|
* keyed by tag name.
|
|
@@ -18,7 +18,7 @@ type HyperscriptShorthands = Record<string, Record<string, any>>;
|
|
|
18
18
|
declare const createHyperscript: (options?: {
|
|
19
19
|
creators?: HyperscriptCreators;
|
|
20
20
|
elements?: HyperscriptShorthands;
|
|
21
|
-
}) => <S extends "anchor" | "focus" | "text" | "selection" | "fragment" | "element" | "editor" | "cursor">(tagName: S, attributes?: object, ...children: any[]) => ReturnType<{
|
|
21
|
+
}) => <S extends "anchor" | "focus" | "text" | "point" | "selection" | "fragment" | "element" | "editor" | "cursor">(tagName: S, attributes?: object, ...children: any[]) => ReturnType<{
|
|
22
22
|
anchor: typeof createAnchor;
|
|
23
23
|
cursor: typeof createCursor;
|
|
24
24
|
editor: (tagName: string, attributes: {
|
|
@@ -27,6 +27,7 @@ declare const createHyperscript: (options?: {
|
|
|
27
27
|
element: typeof createElement;
|
|
28
28
|
focus: typeof createFocus;
|
|
29
29
|
fragment: typeof createFragment;
|
|
30
|
+
point: typeof createPoint;
|
|
30
31
|
selection: typeof createSelection;
|
|
31
32
|
text: typeof createText;
|
|
32
33
|
}[S]>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createHyperscript, HyperscriptCreators, HyperscriptShorthands } from './hyperscript';
|
|
2
2
|
import { createEditor, createText } from './creators';
|
|
3
|
+
import { HyperscriptPointRef, HyperscriptRangeRef } from './refs';
|
|
3
4
|
/**
|
|
4
5
|
* The default hyperscript factory that ships with Slate, without custom tags.
|
|
5
6
|
*/
|
|
6
|
-
declare const jsx: <S extends "anchor" | "focus" | "text" | "selection" | "fragment" | "element" | "editor" | "cursor">(tagName: S, attributes?: object, ...children: any[]) => ReturnType<{
|
|
7
|
+
declare const jsx: <S extends "anchor" | "focus" | "text" | "point" | "selection" | "fragment" | "element" | "editor" | "cursor">(tagName: S, attributes?: object, ...children: any[]) => ReturnType<{
|
|
7
8
|
anchor: typeof import('./creators').createAnchor;
|
|
8
9
|
cursor: typeof import('./creators').createCursor;
|
|
9
10
|
editor: (tagName: string, attributes: {
|
|
@@ -12,7 +13,8 @@ declare const jsx: <S extends "anchor" | "focus" | "text" | "selection" | "fragm
|
|
|
12
13
|
element: typeof import('./creators').createElement;
|
|
13
14
|
focus: typeof import('./creators').createFocus;
|
|
14
15
|
fragment: typeof import('./creators').createFragment;
|
|
16
|
+
point: typeof import('./creators').createPoint;
|
|
15
17
|
selection: typeof import('./creators').createSelection;
|
|
16
18
|
text: typeof createText;
|
|
17
19
|
}[S]>;
|
|
18
|
-
export { jsx, createHyperscript, createEditor, createText, HyperscriptCreators, HyperscriptShorthands, };
|
|
20
|
+
export { jsx, createHyperscript, createEditor, createText, HyperscriptCreators, HyperscriptPointRef, HyperscriptRangeRef, HyperscriptShorthands, };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Path, Point, Range } from '../slate/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Hyperscript point refs can be used to construct arbitrary points using the
|
|
4
|
+
* ref prop of a <point /> tag.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HyperscriptPointRef {
|
|
7
|
+
path?: Path;
|
|
8
|
+
offset?: number;
|
|
9
|
+
point(): Point;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hyperscript range refs can be used to construct arbitrary range using the ref
|
|
13
|
+
* props of <anchor /> and <focus /> tags.
|
|
14
|
+
*/
|
|
15
|
+
export declare class HyperscriptRangeRef {
|
|
16
|
+
anchor?: Point;
|
|
17
|
+
focus?: Point;
|
|
18
|
+
range(): Range;
|
|
19
|
+
}
|
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
import { Path, Text } from '../slate/index.ts';
|
|
2
|
+
import { HyperscriptPointRef, HyperscriptRangeRef } from './refs';
|
|
2
3
|
/**
|
|
3
4
|
* All tokens inherit from a single constructor for `instanceof` checking.
|
|
4
5
|
*/
|
|
5
|
-
export declare class Token {
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Anchor tokens represent the selection's anchor point.
|
|
9
|
-
*/
|
|
10
|
-
export declare class AnchorToken extends Token {
|
|
6
|
+
export declare class Token<Ref = unknown> {
|
|
11
7
|
offset?: number;
|
|
12
8
|
path?: Path;
|
|
9
|
+
ref?: Ref;
|
|
13
10
|
constructor(props?: {
|
|
14
11
|
offset?: number;
|
|
15
12
|
path?: Path;
|
|
13
|
+
ref?: Ref;
|
|
16
14
|
});
|
|
17
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Anchor tokens represent the selection's anchor point.
|
|
18
|
+
*/
|
|
19
|
+
export declare class AnchorToken extends Token<HyperscriptRangeRef> {
|
|
20
|
+
}
|
|
18
21
|
/**
|
|
19
22
|
* Focus tokens represent the selection's focus point.
|
|
20
23
|
*/
|
|
21
|
-
export declare class FocusToken extends Token {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
24
|
+
export declare class FocusToken extends Token<HyperscriptRangeRef> {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A weak map to hold point tokens.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PointToken extends Token<HyperscriptPointRef> {
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Add an anchor token to the end of a text node.
|
|
31
33
|
*/
|
|
32
|
-
export declare
|
|
34
|
+
export declare function addAnchorToken(text: Text, token: AnchorToken): void;
|
|
33
35
|
/**
|
|
34
|
-
* Get the
|
|
36
|
+
* Get the associated anchor tokens for a text node.
|
|
35
37
|
*/
|
|
36
|
-
export declare
|
|
38
|
+
export declare function getAnchors(text: Text): AnchorToken[];
|
|
37
39
|
/**
|
|
38
40
|
* Add a focus token to the end of a text node.
|
|
39
41
|
*/
|
|
40
|
-
export declare
|
|
42
|
+
export declare function addFocusToken(text: Text, token: FocusToken): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get the associated focus tokens for a text node.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getFoci(text: Text): FocusToken[];
|
|
47
|
+
/**
|
|
48
|
+
* Add a point token to the end of a text node.
|
|
49
|
+
*/
|
|
50
|
+
export declare function addPointToken(text: Text, token: PointToken): void;
|
|
41
51
|
/**
|
|
42
|
-
* Get the
|
|
52
|
+
* Get the associated point tokens for a text node.
|
|
43
53
|
*/
|
|
44
|
-
export declare
|
|
54
|
+
export declare function getPoints(text: Text): PointToken[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slate-vue3",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@faker-js/faker": "^10.4.0",
|
|
83
83
|
"@liveblocks/client": "^3.18.2",
|
|
84
84
|
"@liveblocks/yjs": "^3.18.2",
|
|
85
|
-
"@playwright/test": "^1.
|
|
85
|
+
"@playwright/test": "^1.60.0",
|
|
86
86
|
"@testing-library/vue": "^8.1.0",
|
|
87
87
|
"@types/is-hotkey": "^0.1.10",
|
|
88
88
|
"@types/is-url": "^1.2.32",
|