plitejs 0.0.1 → 54.0.0-beta.3
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 +4 -1
- package/README.md +83 -0
- package/dist/annotation-store-metrics-Ccjkef45.js +12 -0
- package/dist/annotations/index.d.ts +2 -0
- package/dist/annotations/index.js +2 -0
- package/dist/authored/index.d.ts +596 -0
- package/dist/authored/index.js +18558 -0
- package/dist/authored-veto-DSnQcHGR.js +6 -0
- package/dist/browser-protocol-pvt4HFF7.js +5 -0
- package/dist/comparison-plan-CEQL0ooW.js +1338 -0
- package/dist/comparison-types-Dt-unJZY.d.ts +179 -0
- package/dist/create-editor-CkHtPWXV.js +1107 -0
- package/dist/diff/index.d.ts +32 -0
- package/dist/diff/index.js +1748 -0
- package/dist/dom/index.d.ts +2 -0
- package/dist/dom/index.js +2 -0
- package/dist/dom-Cgfscvnm.js +9220 -0
- package/dist/editor-owner-IUmkTeXz.js +171 -0
- package/dist/editor-view-lifetime-GJKa_QGh.js +23 -0
- package/dist/history/index.d.ts +170 -0
- package/dist/history/index.js +6718 -0
- package/dist/hyperscript/index.d.ts +2 -0
- package/dist/hyperscript/index.js +2 -0
- package/dist/hyperscript-FPuoArEi.js +299 -0
- package/dist/index-BpQx2UG4.d.ts +1093 -0
- package/dist/index-Cw-oC2ps.d.ts +190 -0
- package/dist/index-DPWyk3lG.d.ts +65 -0
- package/dist/index-DpltOCot.d.ts +9753 -0
- package/dist/index-HPYawTae.d.ts +119 -0
- package/dist/index-K0Za9YXc.d.ts +1246 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +156 -0
- package/dist/mapped-view-store-ld-6uxEU.js +120 -0
- package/dist/native-grouping-input-DMNcsIaW.js +8 -0
- package/dist/pagination/index.d.ts +169 -0
- package/dist/pagination/index.js +2 -0
- package/dist/pagination/react.d.ts +33 -0
- package/dist/pagination/react.js +1509 -0
- package/dist/pagination-D_A8iPJP.js +1021 -0
- package/dist/plugin-DWzkJbnJ.js +50999 -0
- package/dist/range-geometry-BLAHRE11.d.ts +38 -0
- package/dist/range-geometry-BjeLHOnl.js +486 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +7 -0
- package/dist/react/virtualized.d.ts +13 -0
- package/dist/react/virtualized.js +209 -0
- package/dist/react-DZ15gmz2.js +1018 -0
- package/dist/retraction-BMem8Rfk.js +109 -0
- package/dist/src-cT1OTKP_.js +1386 -0
- package/dist/store-Cz2mXyDe.js +704 -0
- package/dist/testing/index.d.ts +183 -0
- package/dist/testing/index.js +96 -0
- package/dist/use-editor-dom-scope-BbMDSCpW.js +28354 -0
- package/dist/yjs/index.d.ts +2 -0
- package/dist/yjs/index.js +2 -0
- package/dist/yjs/react/index.d.ts +26 -0
- package/dist/yjs/react/index.js +85 -0
- package/dist/yjs-DOK-m7kl.js +13413 -0
- package/package.json +191 -43
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as HyperscriptEditorFixture, c as createText, i as createHyperscript, n as HyperscriptCreators, o as createEditor, r as HyperscriptShorthands, s as createEditorFixture, t as jsx } from "../index-HPYawTae.js";
|
|
2
|
+
export { type HyperscriptCreators, type HyperscriptEditorFixture, type HyperscriptShorthands, createEditor, createEditorFixture, createHyperscript, createText, jsx };
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { B as NodeApi, Jt as replace, au as ElementApi, iu as SelectionApi, lu as TextApi, mu as RangeApi } from "./plugin-DWzkJbnJ.js";
|
|
2
|
+
import { a as createEditor$1 } from "./create-editor-CkHtPWXV.js";
|
|
3
|
+
//#region src/hyperscript/tokens.ts
|
|
4
|
+
/**
|
|
5
|
+
* A weak map to hold anchor tokens.
|
|
6
|
+
*/
|
|
7
|
+
const ANCHOR = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
/**
|
|
9
|
+
* A weak map to hold focus tokens.
|
|
10
|
+
*/
|
|
11
|
+
const FOCUS = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
/**
|
|
13
|
+
* All tokens inherit from a single constructor for `instanceof` checking.
|
|
14
|
+
*/
|
|
15
|
+
var Token = class {};
|
|
16
|
+
/**
|
|
17
|
+
* Anchor tokens represent the selection's anchor point.
|
|
18
|
+
*/
|
|
19
|
+
var AnchorToken = class extends Token {
|
|
20
|
+
offset;
|
|
21
|
+
path;
|
|
22
|
+
constructor(props = {}) {
|
|
23
|
+
super();
|
|
24
|
+
const { offset, path } = props;
|
|
25
|
+
this.offset = offset;
|
|
26
|
+
this.path = path;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Focus tokens represent the selection's focus point.
|
|
31
|
+
*/
|
|
32
|
+
var FocusToken = class extends Token {
|
|
33
|
+
offset;
|
|
34
|
+
path;
|
|
35
|
+
constructor(props = {}) {
|
|
36
|
+
super();
|
|
37
|
+
const { offset, path } = props;
|
|
38
|
+
this.offset = offset;
|
|
39
|
+
this.path = path;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Add an anchor token to the end of a text node.
|
|
44
|
+
*/
|
|
45
|
+
const addAnchorToken = (text, token) => {
|
|
46
|
+
const offset = text.text.length;
|
|
47
|
+
ANCHOR.set(text, [offset, token]);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Get the offset if a text node has an associated anchor token.
|
|
51
|
+
*/
|
|
52
|
+
const getAnchorOffset = (text) => ANCHOR.get(text);
|
|
53
|
+
/**
|
|
54
|
+
* Add a focus token to the end of a text node.
|
|
55
|
+
*/
|
|
56
|
+
const addFocusToken = (text, token) => {
|
|
57
|
+
const offset = text.text.length;
|
|
58
|
+
FOCUS.set(text, [offset, token]);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Get the offset if a text node has an associated focus token.
|
|
62
|
+
*/
|
|
63
|
+
const getFocusOffset = (text) => FOCUS.get(text);
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/hyperscript/creators.ts
|
|
66
|
+
/**
|
|
67
|
+
* Resolve the descendants of a node by normalizing the children that can be
|
|
68
|
+
* passed into a hyperscript creator function.
|
|
69
|
+
*/
|
|
70
|
+
const STRINGS = /* @__PURE__ */ new WeakSet();
|
|
71
|
+
const isStringDraft = (value) => TextApi.isText(value) && STRINGS.has(value);
|
|
72
|
+
const resolveDescendants = (children) => {
|
|
73
|
+
const nodes = [];
|
|
74
|
+
const addChild = (child) => {
|
|
75
|
+
if (child == null) return;
|
|
76
|
+
let normalizedChild = child;
|
|
77
|
+
const prev = nodes.at(-1);
|
|
78
|
+
if (typeof normalizedChild === "string") {
|
|
79
|
+
const text = { text: normalizedChild };
|
|
80
|
+
STRINGS.add(text);
|
|
81
|
+
normalizedChild = text;
|
|
82
|
+
}
|
|
83
|
+
if (TextApi.isText(normalizedChild)) if (isStringDraft(prev) && isStringDraft(normalizedChild) && TextApi.equals(prev, normalizedChild, { loose: true })) prev.text += normalizedChild.text;
|
|
84
|
+
else nodes.push(normalizedChild);
|
|
85
|
+
else if (ElementApi.isElement(normalizedChild)) nodes.push(normalizedChild);
|
|
86
|
+
else if (normalizedChild instanceof Token) {
|
|
87
|
+
let n = nodes.at(-1);
|
|
88
|
+
if (!TextApi.isText(n)) {
|
|
89
|
+
addChild("");
|
|
90
|
+
n = nodes.at(-1);
|
|
91
|
+
}
|
|
92
|
+
if (!TextApi.isText(n)) throw new Error("Expected a text node for the selection token");
|
|
93
|
+
if (normalizedChild instanceof AnchorToken) addAnchorToken(n, normalizedChild);
|
|
94
|
+
else if (normalizedChild instanceof FocusToken) addFocusToken(n, normalizedChild);
|
|
95
|
+
} else throw new Error(`Unexpected hyperscript child object: ${JSON.stringify(normalizedChild)}`);
|
|
96
|
+
};
|
|
97
|
+
for (const child of children.flat(Number.POSITIVE_INFINITY)) addChild(child);
|
|
98
|
+
return nodes;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Create an anchor token.
|
|
102
|
+
*/
|
|
103
|
+
function createAnchor(_tagName, attributes, _children) {
|
|
104
|
+
return new AnchorToken(attributes);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Create an anchor and a focus token.
|
|
108
|
+
*/
|
|
109
|
+
function createCursor(_tagName, attributes, _children) {
|
|
110
|
+
return [new AnchorToken(attributes), new FocusToken(attributes)];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create an `Element` object.
|
|
114
|
+
*/
|
|
115
|
+
function createElement(_tagName, attributes, children) {
|
|
116
|
+
return {
|
|
117
|
+
...attributes,
|
|
118
|
+
children: resolveDescendants(children)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a focus token.
|
|
123
|
+
*/
|
|
124
|
+
function createFocus(_tagName, attributes, _children) {
|
|
125
|
+
return new FocusToken(attributes);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create a fragment.
|
|
129
|
+
*/
|
|
130
|
+
function createFragment(_tagName, _attributes, children) {
|
|
131
|
+
return resolveDescendants(children);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create a `Selection` object.
|
|
135
|
+
*/
|
|
136
|
+
function createSelection(_tagName, attributes, children) {
|
|
137
|
+
const anchor = children.find((c) => c instanceof AnchorToken);
|
|
138
|
+
const focus = children.find((c) => c instanceof FocusToken);
|
|
139
|
+
if (!anchor || anchor.offset == null || anchor.path == null) throw new Error("The <selection> hyperscript tag must have an <anchor> tag as a child with `path` and `offset` attributes defined.");
|
|
140
|
+
if (!focus || focus.offset == null || focus.path == null) throw new Error("The <selection> hyperscript tag must have a <focus> tag as a child with `path` and `offset` attributes defined.");
|
|
141
|
+
return {
|
|
142
|
+
...attributes,
|
|
143
|
+
kind: "text",
|
|
144
|
+
anchor: {
|
|
145
|
+
offset: anchor.offset,
|
|
146
|
+
path: anchor.path
|
|
147
|
+
},
|
|
148
|
+
focus: {
|
|
149
|
+
offset: focus.offset,
|
|
150
|
+
path: focus.path
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a `Text` object.
|
|
156
|
+
*/
|
|
157
|
+
function createText(_tagName, attributes, children) {
|
|
158
|
+
const nodes = resolveDescendants(children);
|
|
159
|
+
if (nodes.length > 1) throw new Error(`The <text> hyperscript tag must only contain a single node's worth of children.`);
|
|
160
|
+
let [node] = nodes;
|
|
161
|
+
if (node == null) node = { text: "" };
|
|
162
|
+
if (!TextApi.isText(node)) throw new Error(`
|
|
163
|
+
The <text> hyperscript tag can only contain text content as children.`);
|
|
164
|
+
STRINGS.delete(node);
|
|
165
|
+
Object.assign(node, attributes);
|
|
166
|
+
return node;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Resolve a top-level editor fixture without running editor normalization.
|
|
170
|
+
*/
|
|
171
|
+
const resolveEditorFixture = (children) => {
|
|
172
|
+
const otherChildren = [];
|
|
173
|
+
let selectionChild;
|
|
174
|
+
for (const child of children) if (SelectionApi.isText(child)) selectionChild = child;
|
|
175
|
+
else otherChildren.push(child);
|
|
176
|
+
const descendants = resolveDescendants(otherChildren);
|
|
177
|
+
const selection = {};
|
|
178
|
+
const root = {
|
|
179
|
+
children: descendants,
|
|
180
|
+
type: "root"
|
|
181
|
+
};
|
|
182
|
+
for (const [node, path] of NodeApi.texts(root)) {
|
|
183
|
+
const anchor = getAnchorOffset(node);
|
|
184
|
+
const focus = getFocusOffset(node);
|
|
185
|
+
if (anchor != null) {
|
|
186
|
+
const [offset] = anchor;
|
|
187
|
+
selection.anchor = {
|
|
188
|
+
path,
|
|
189
|
+
offset
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (focus != null) {
|
|
193
|
+
const [offset] = focus;
|
|
194
|
+
selection.focus = {
|
|
195
|
+
path,
|
|
196
|
+
offset
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (selection.anchor && !selection.focus) throw new Error("Hyperscript ranges must have both `<anchor />` and `<focus />` defined if one is defined, but you only defined `<anchor />`. For collapsed selections, use `<cursor />` instead.");
|
|
201
|
+
if (!selection.anchor && selection.focus) throw new Error("Hyperscript ranges must have both `<anchor />` and `<focus />` defined if one is defined, but you only defined `<focus />`. For collapsed selections, use `<cursor />` instead.");
|
|
202
|
+
return {
|
|
203
|
+
children: descendants,
|
|
204
|
+
selection: selectionChild ?? (RangeApi.isRange(selection) ? SelectionApi.text(selection) : null)
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Create a plain editor fixture for a custom hyperscript factory.
|
|
209
|
+
*/
|
|
210
|
+
function createEditorFixture(_tagName, attributes, children) {
|
|
211
|
+
return {
|
|
212
|
+
...attributes,
|
|
213
|
+
...resolveEditorFixture(children)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Create a top-level `Editor` object.
|
|
218
|
+
*/
|
|
219
|
+
const createEditor = (makeEditor) => (_tagName, attributes, children) => {
|
|
220
|
+
const fixture = resolveEditorFixture(children);
|
|
221
|
+
const editor = makeEditor();
|
|
222
|
+
Object.assign(editor, attributes);
|
|
223
|
+
replace(editor, {
|
|
224
|
+
children: fixture.children,
|
|
225
|
+
selection: fixture.selection
|
|
226
|
+
});
|
|
227
|
+
return editor;
|
|
228
|
+
};
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/hyperscript/hyperscript.ts
|
|
231
|
+
/**
|
|
232
|
+
* The default creators for Plite objects.
|
|
233
|
+
*/
|
|
234
|
+
const DEFAULT_CREATORS = {
|
|
235
|
+
anchor: createAnchor,
|
|
236
|
+
cursor: createCursor,
|
|
237
|
+
editor: createEditor(createEditor$1),
|
|
238
|
+
element: createElement,
|
|
239
|
+
focus: createFocus,
|
|
240
|
+
fragment: createFragment,
|
|
241
|
+
selection: createSelection,
|
|
242
|
+
text: createText
|
|
243
|
+
};
|
|
244
|
+
const stripJsxDevelopmentAttributes = (attributes) => {
|
|
245
|
+
const normalized = Object.fromEntries(Object.entries(attributes));
|
|
246
|
+
delete normalized.__self;
|
|
247
|
+
delete normalized.__source;
|
|
248
|
+
return normalized;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Create an editor hyperscript factory with optional custom creators and element
|
|
252
|
+
* shorthands.
|
|
253
|
+
*/
|
|
254
|
+
const createHyperscript = (options) => {
|
|
255
|
+
const elementCreators = normalizeElements(options?.elements);
|
|
256
|
+
const creators = Object.assign({}, DEFAULT_CREATORS, elementCreators, options?.creators);
|
|
257
|
+
return createFactory(creators);
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Create the callable JSX factory from a normalized creator map.
|
|
261
|
+
*/
|
|
262
|
+
const createFactory = (creators) => {
|
|
263
|
+
const jsx = (tagName, attributes, ...children) => {
|
|
264
|
+
const creator = creators[tagName];
|
|
265
|
+
if (!creator) throw new Error(`No hyperscript creator found for tag: <${tagName}>`);
|
|
266
|
+
let normalizedAttributes = {};
|
|
267
|
+
let normalizedChildren = children;
|
|
268
|
+
if (attributes != null) if (typeof attributes !== "object") normalizedChildren = [attributes].concat(normalizedChildren);
|
|
269
|
+
else normalizedAttributes = stripJsxDevelopmentAttributes(attributes);
|
|
270
|
+
normalizedChildren = normalizedChildren.filter((child) => child != null && child !== false).flat();
|
|
271
|
+
return creator(tagName, normalizedAttributes, normalizedChildren);
|
|
272
|
+
};
|
|
273
|
+
return jsx;
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* Normalize a dictionary of element shorthands into creator functions.
|
|
277
|
+
*/
|
|
278
|
+
const normalizeElements = (elements) => {
|
|
279
|
+
const creators = {};
|
|
280
|
+
if (!elements) return creators;
|
|
281
|
+
for (const tagName in elements) {
|
|
282
|
+
if (!Object.hasOwn(elements, tagName)) continue;
|
|
283
|
+
const props = elements[tagName];
|
|
284
|
+
if (typeof props !== "object") throw new Error(`Properties specified for a hyperscript shorthand should be an object, but for the custom element <${tagName}> tag you passed: ${String(props)}`);
|
|
285
|
+
creators[tagName] = (_tagName, attributes, children) => createElement("element", {
|
|
286
|
+
...props,
|
|
287
|
+
...attributes
|
|
288
|
+
}, children);
|
|
289
|
+
}
|
|
290
|
+
return creators;
|
|
291
|
+
};
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/hyperscript/index.ts
|
|
294
|
+
/**
|
|
295
|
+
* The default editor hyperscript factory, without custom tags.
|
|
296
|
+
*/
|
|
297
|
+
const jsx = createHyperscript();
|
|
298
|
+
//#endregion
|
|
299
|
+
export { createText as a, createEditorFixture as i, createHyperscript as n, createEditor as r, jsx as t };
|