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,209 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { L as useRootNodeKeys, R as useSelectionPaths, S as createInitialViewportIndexes, Ut as useEditorContext, n as useEditorHostScrollElement, s as EditableViewportSurface, u as SurfaceRoot, x as createEditableViewportPlan, z as useTopLevelSelectionIndex, zt as useEditorReadOnly } from "../use-editor-dom-scope-BbMDSCpW.js";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { flushSync } from "react-dom";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { defaultRangeExtractor, useVirtualizer } from "@tanstack/react-virtual";
|
|
7
|
+
//#region src/react/virtualized/use-virtualized-root-plan.ts
|
|
8
|
+
const SCROLLABLE_OVERFLOW_PATTERN = /(auto|scroll|overlay)/;
|
|
9
|
+
const TOP_LEVEL_NATIVE_SCROLLBAR_DRAG_OVERSCAN = 96;
|
|
10
|
+
const SCROLLBAR_POINTER_HIT_SLOP = 24;
|
|
11
|
+
const parseCSSPixels = (value) => {
|
|
12
|
+
if (!value || value === "auto" || value === "none") return 0;
|
|
13
|
+
const parsed = Number.parseFloat(value);
|
|
14
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
15
|
+
};
|
|
16
|
+
const getElementViewportHeight = (element, fallback) => {
|
|
17
|
+
if (!element) return fallback;
|
|
18
|
+
if (element.clientHeight > 0) return element.clientHeight;
|
|
19
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
20
|
+
const height = parseCSSPixels(style?.height);
|
|
21
|
+
if (height > 0) return height;
|
|
22
|
+
const maxHeight = parseCSSPixels(style?.maxHeight);
|
|
23
|
+
return maxHeight > 0 ? maxHeight : fallback;
|
|
24
|
+
};
|
|
25
|
+
const isVerticalScrollbarPointer = (event, element) => {
|
|
26
|
+
const rect = element.getBoundingClientRect();
|
|
27
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
28
|
+
const borderLeftWidth = parseCSSPixels(style?.borderLeftWidth);
|
|
29
|
+
const scrollbarWidth = Math.max(0, element.offsetWidth - element.clientWidth);
|
|
30
|
+
const gutterSize = Math.max(scrollbarWidth, SCROLLBAR_POINTER_HIT_SLOP);
|
|
31
|
+
const scrollbarOnLeft = element.clientLeft > borderLeftWidth + 1 || scrollbarWidth === 0 && style?.direction === "rtl";
|
|
32
|
+
const start = scrollbarOnLeft ? rect.left : rect.right - gutterSize;
|
|
33
|
+
const end = scrollbarOnLeft ? rect.left + gutterSize : rect.right;
|
|
34
|
+
return event.clientX >= start && event.clientX <= end;
|
|
35
|
+
};
|
|
36
|
+
const canUseElementAsVirtualizerScrollRoot = (element) => {
|
|
37
|
+
if (!element) return false;
|
|
38
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
39
|
+
const overflow = `${style?.overflow ?? ""} ${style?.overflowY ?? ""}`;
|
|
40
|
+
const hasScrollableOverflow = SCROLLABLE_OVERFLOW_PATTERN.test(overflow);
|
|
41
|
+
const hasBoundedHeight = element.clientHeight > 0 || parseCSSPixels(style?.height) > 0 || parseCSSPixels(style?.maxHeight) > 0;
|
|
42
|
+
return hasScrollableOverflow && hasBoundedHeight;
|
|
43
|
+
};
|
|
44
|
+
const getVirtualizerScrollElement = (element) => {
|
|
45
|
+
let current = element;
|
|
46
|
+
while (current) {
|
|
47
|
+
if (canUseElementAsVirtualizerScrollRoot(current)) return current;
|
|
48
|
+
current = current.parentElement;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
const createRetainedRangeExtractor = ({ count, retainedIndexes }) => (range) => {
|
|
53
|
+
const indexes = new Set(defaultRangeExtractor(range));
|
|
54
|
+
retainedIndexes.forEach((index) => {
|
|
55
|
+
if (typeof index === "number" && index >= 0 && index < count) indexes.add(index);
|
|
56
|
+
});
|
|
57
|
+
return [...indexes].sort((left, right) => left - right);
|
|
58
|
+
};
|
|
59
|
+
const useVirtualizedRootPlan = ({ options, promotedTopLevelIndex, rootElement, scrollElement, selectionPaths, selectedTopLevelIndex, topLevelNodeKeys }) => {
|
|
60
|
+
const { estimatedBlockSize, overscan } = options;
|
|
61
|
+
const count = topLevelNodeKeys.length;
|
|
62
|
+
const selectedEndpointIndexes = React.useMemo(() => selectionPaths?.map((path) => path[0]).filter((index) => typeof index === "number") ?? [], [selectionPaths]);
|
|
63
|
+
const retainedIndexes = React.useMemo(() => [
|
|
64
|
+
...selectedEndpointIndexes,
|
|
65
|
+
selectedTopLevelIndex,
|
|
66
|
+
promotedTopLevelIndex
|
|
67
|
+
], [
|
|
68
|
+
promotedTopLevelIndex,
|
|
69
|
+
selectedEndpointIndexes,
|
|
70
|
+
selectedTopLevelIndex
|
|
71
|
+
]);
|
|
72
|
+
const [nativeScrollbarDrag, setNativeScrollbarDrag] = React.useState(false);
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
if (!scrollElement) return void 0;
|
|
75
|
+
const start = (event) => {
|
|
76
|
+
if (!isVerticalScrollbarPointer(event, scrollElement)) return;
|
|
77
|
+
flushSync(() => setNativeScrollbarDrag(true));
|
|
78
|
+
};
|
|
79
|
+
const stop = () => setNativeScrollbarDrag(false);
|
|
80
|
+
scrollElement.addEventListener("pointerdown", start);
|
|
81
|
+
scrollElement.ownerDocument.addEventListener("pointerup", stop);
|
|
82
|
+
scrollElement.ownerDocument.addEventListener("pointercancel", stop);
|
|
83
|
+
return () => {
|
|
84
|
+
scrollElement.removeEventListener("pointerdown", start);
|
|
85
|
+
scrollElement.ownerDocument.removeEventListener("pointerup", stop);
|
|
86
|
+
scrollElement.ownerDocument.removeEventListener("pointercancel", stop);
|
|
87
|
+
};
|
|
88
|
+
}, [scrollElement]);
|
|
89
|
+
const effectiveOverscan = nativeScrollbarDrag ? Math.max(overscan, TOP_LEVEL_NATIVE_SCROLLBAR_DRAG_OVERSCAN) : overscan;
|
|
90
|
+
const rangeExtractor = React.useMemo(() => createRetainedRangeExtractor({
|
|
91
|
+
count,
|
|
92
|
+
retainedIndexes
|
|
93
|
+
}), [count, retainedIndexes]);
|
|
94
|
+
const estimateSize = React.useCallback(() => estimatedBlockSize, [estimatedBlockSize]);
|
|
95
|
+
const virtualizer = useVirtualizer({
|
|
96
|
+
count,
|
|
97
|
+
enabled: scrollElement != null,
|
|
98
|
+
estimateSize,
|
|
99
|
+
getItemKey: (index) => topLevelNodeKeys[index] ?? index,
|
|
100
|
+
getScrollElement: () => scrollElement,
|
|
101
|
+
initialRect: {
|
|
102
|
+
height: getElementViewportHeight(scrollElement, estimatedBlockSize * 8),
|
|
103
|
+
width: scrollElement?.clientWidth || rootElement?.clientWidth || 1024
|
|
104
|
+
},
|
|
105
|
+
overscan: effectiveOverscan,
|
|
106
|
+
rangeExtractor
|
|
107
|
+
});
|
|
108
|
+
const virtualItems = scrollElement ? virtualizer.getVirtualItems() : createInitialViewportIndexes({
|
|
109
|
+
count,
|
|
110
|
+
retainedIndexes
|
|
111
|
+
}).map((index) => ({
|
|
112
|
+
index,
|
|
113
|
+
size: estimatedBlockSize,
|
|
114
|
+
start: index * estimatedBlockSize
|
|
115
|
+
}));
|
|
116
|
+
const measureElement = React.useCallback((element) => {
|
|
117
|
+
virtualizer.measureElement(element);
|
|
118
|
+
if (!element) return;
|
|
119
|
+
const index = Number(element.dataset.index);
|
|
120
|
+
if (Number.isInteger(index)) virtualizer.resizeItem(index, element.offsetHeight);
|
|
121
|
+
}, [virtualizer]);
|
|
122
|
+
const itemsByIndex = new Map(virtualItems.map((item) => [item.index, item]));
|
|
123
|
+
retainedIndexes.forEach((index) => {
|
|
124
|
+
if (typeof index === "number" && index >= 0 && index < count && !itemsByIndex.has(index)) itemsByIndex.set(index, {
|
|
125
|
+
index,
|
|
126
|
+
size: estimatedBlockSize,
|
|
127
|
+
start: index * estimatedBlockSize
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
const indexes = [...itemsByIndex.keys()];
|
|
131
|
+
const scrollToPath = (path, align = "auto") => {
|
|
132
|
+
const index = path[0];
|
|
133
|
+
if (typeof index !== "number" || index < 0 || index >= count) return false;
|
|
134
|
+
if (!scrollElement) return false;
|
|
135
|
+
virtualizer.scrollToIndex(index, { align });
|
|
136
|
+
return true;
|
|
137
|
+
};
|
|
138
|
+
return createEditableViewportPlan({
|
|
139
|
+
coordinateSpace: "flow",
|
|
140
|
+
indexes,
|
|
141
|
+
measureElement,
|
|
142
|
+
scrollToPath,
|
|
143
|
+
sizeAtIndex: (index) => itemsByIndex.get(index)?.size ?? estimatedBlockSize,
|
|
144
|
+
startAtIndex: (index) => itemsByIndex.get(index)?.start ?? index * estimatedBlockSize,
|
|
145
|
+
topLevelNodeKeys,
|
|
146
|
+
totalSize: scrollElement ? virtualizer.getTotalSize() : count * estimatedBlockSize
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/react/virtualized.tsx
|
|
151
|
+
const assertOptions = ({ estimatedBlockSize, overscan }) => {
|
|
152
|
+
if (!Number.isFinite(estimatedBlockSize) || estimatedBlockSize <= 0) throw new RangeError("estimatedBlockSize must be a positive finite number");
|
|
153
|
+
if (!Number.isInteger(overscan) || overscan < 0) throw new RangeError("overscan must be a nonnegative integer");
|
|
154
|
+
};
|
|
155
|
+
const VirtualizedEditableInner = ({ estimatedBlockSize = 32, overscan = 2, ref: forwardedRef, ...props }) => {
|
|
156
|
+
assertOptions({
|
|
157
|
+
estimatedBlockSize,
|
|
158
|
+
overscan
|
|
159
|
+
});
|
|
160
|
+
const [rootElement, setRootElement] = React.useState(null);
|
|
161
|
+
const [promotedTopLevelIndex, setPromotedTopLevelIndex] = React.useState(null);
|
|
162
|
+
const topLevelNodeKeys = useRootNodeKeys();
|
|
163
|
+
const selectionPaths = useSelectionPaths(true);
|
|
164
|
+
const selectedTopLevelIndex = useTopLevelSelectionIndex(true);
|
|
165
|
+
const hostScrollElement = useEditorHostScrollElement(useEditorContext());
|
|
166
|
+
const scrollElement = React.useMemo(() => hostScrollElement ?? getVirtualizerScrollElement(rootElement), [hostScrollElement, rootElement]);
|
|
167
|
+
const plan = useVirtualizedRootPlan({
|
|
168
|
+
options: React.useMemo(() => ({
|
|
169
|
+
estimatedBlockSize,
|
|
170
|
+
overscan
|
|
171
|
+
}), [estimatedBlockSize, overscan]),
|
|
172
|
+
promotedTopLevelIndex,
|
|
173
|
+
rootElement,
|
|
174
|
+
scrollElement,
|
|
175
|
+
selectedTopLevelIndex,
|
|
176
|
+
selectionPaths,
|
|
177
|
+
topLevelNodeKeys
|
|
178
|
+
});
|
|
179
|
+
const viewportPlan = React.useMemo(() => ({
|
|
180
|
+
...plan,
|
|
181
|
+
requestMount: (index) => setPromotedTopLevelIndex(index)
|
|
182
|
+
}), [plan]);
|
|
183
|
+
const ref = React.useCallback((element) => {
|
|
184
|
+
setRootElement(element);
|
|
185
|
+
if (typeof forwardedRef === "function") forwardedRef(element);
|
|
186
|
+
else if (forwardedRef) forwardedRef.current = element;
|
|
187
|
+
}, [forwardedRef]);
|
|
188
|
+
return /* @__PURE__ */ jsx(EditableViewportSurface, {
|
|
189
|
+
...props,
|
|
190
|
+
ref,
|
|
191
|
+
viewportPlan
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
/** Render one explicitly virtualized Plite root. */
|
|
195
|
+
const VirtualizedEditable = ({ root, ...props }) => {
|
|
196
|
+
if (root === "main") throw new Error("Omit root to render the primary editable.");
|
|
197
|
+
const inheritedReadOnly = useEditorReadOnly();
|
|
198
|
+
const editor = useEditorContext();
|
|
199
|
+
const readOnly = props.readOnly || inheritedReadOnly;
|
|
200
|
+
const editable = /* @__PURE__ */ jsx(VirtualizedEditableInner, { ...props });
|
|
201
|
+
return root === void 0 ? editable : /* @__PURE__ */ jsx(SurfaceRoot, {
|
|
202
|
+
editor,
|
|
203
|
+
readOnly,
|
|
204
|
+
root,
|
|
205
|
+
children: editable
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
//#endregion
|
|
209
|
+
export { VirtualizedEditable };
|