@powerhousedao/powerhouse-vetra-packages 6.2.3-dev.8 → 6.2.3-dev.80
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/browser/document-models/index.js +2 -1
- package/dist/browser/documents-cxt8RRxe.js +18 -0
- package/dist/browser/documents-cxt8RRxe.js.map +1 -0
- package/dist/browser/{editor-6T4WF2og.js → editor-DXAJ8Mqb.js} +761 -277
- package/dist/browser/editor-DXAJ8Mqb.js.map +1 -0
- package/dist/browser/{editor-DHysndk4.js → editor-Dmpkd8pQ.js} +4 -5
- package/dist/browser/{editor-DHysndk4.js.map → editor-Dmpkd8pQ.js.map} +1 -1
- package/dist/browser/editors/document-model-editor/module.js +1 -1
- package/dist/browser/editors/document-model-editor/module.js.map +1 -1
- package/dist/browser/editors/generic-drive-explorer/index.js +4 -324
- package/dist/browser/editors/generic-drive-explorer/index.js.map +1 -1
- package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
- package/dist/browser/editors/generic-drive-explorer/module.js.map +1 -1
- package/dist/browser/{folder-view-DTewe8q8.js → folder-view-CwIU4XEe.js} +17 -12
- package/dist/browser/folder-view-CwIU4XEe.js.map +1 -0
- package/dist/browser/graphql-editor-CGxwONKl.js +103 -0
- package/dist/browser/graphql-editor-CGxwONKl.js.map +1 -0
- package/dist/browser/hooks-D15NCia0.js +126 -0
- package/dist/browser/hooks-D15NCia0.js.map +1 -0
- package/dist/browser/index.js +6 -703
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/json-editor--jgLEwP2.js +55 -0
- package/dist/browser/json-editor--jgLEwP2.js.map +1 -0
- package/dist/browser/{schema-context-ZyeclQwy.js → schema-context-CC_WFs1x.js} +10 -6
- package/dist/browser/schema-context-CC_WFs1x.js.map +1 -0
- package/dist/browser/{state-schemas-CpcWN_Qo.js → state-schemas-DSY44MOd.js} +28 -19
- package/dist/browser/state-schemas-DSY44MOd.js.map +1 -0
- package/dist/{browser/dist-BAJ5nRDl.js → node/bundle-mjs-Cuu3DEfT.mjs} +1251 -822
- package/dist/node/bundle-mjs-Cuu3DEfT.mjs.map +1 -0
- package/dist/node/document-models/index.mjs +2 -1
- package/dist/node/{graphql-BfAoPeWM.mjs → documents-CNInCxpO.mjs} +66 -50
- package/dist/node/documents-CNInCxpO.mjs.map +1 -0
- package/dist/node/editor-C54qhQLX.mjs +4762 -0
- package/dist/node/editor-C54qhQLX.mjs.map +1 -0
- package/dist/node/{editor-DPv5LEug.mjs → editor-NwTlNx8z.mjs} +4 -5
- package/dist/node/{editor-DPv5LEug.mjs.map → editor-NwTlNx8z.mjs.map} +1 -1
- package/dist/node/editors/document-model-editor/module.mjs +1 -1
- package/dist/node/editors/document-model-editor/module.mjs.map +1 -1
- package/dist/node/editors/generic-drive-explorer/index.mjs +26 -21
- package/dist/node/editors/generic-drive-explorer/index.mjs.map +1 -1
- package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
- package/dist/node/editors/generic-drive-explorer/module.mjs.map +1 -1
- package/dist/node/folder-view-CkCNU8A_.mjs +966 -0
- package/dist/node/folder-view-CkCNU8A_.mjs.map +1 -0
- package/dist/node/{graphql-editor-D0CHQeCL.mjs → graphql-editor--ZZPvvGh.mjs} +5130 -63
- package/dist/node/graphql-editor--ZZPvvGh.mjs.map +1 -0
- package/dist/node/{hooks-D0DcS3MV.mjs → hooks-DI7akiay.mjs} +824 -444
- package/dist/node/{hooks-D0DcS3MV.mjs.map → hooks-DI7akiay.mjs.map} +1 -1
- package/dist/node/index.mjs +45 -97
- package/dist/node/index.mjs.map +1 -1
- package/dist/{browser/json-editor-xI_oaxyT.js → node/json-editor-gYEyOVXY.mjs} +8 -9
- package/dist/node/{json-editor-Ckaem6ky.mjs.map → json-editor-gYEyOVXY.mjs.map} +1 -1
- package/dist/node/rolldown-runtime-Bl3dcgcQ.mjs +16 -0
- package/dist/node/{schema-context-DL8jhi_d.mjs → schema-context-DTb0xqgJ.mjs} +9 -6
- package/dist/node/schema-context-DTb0xqgJ.mjs.map +1 -0
- package/dist/node/state-schemas-Ciq9kway.mjs +1071 -0
- package/dist/node/state-schemas-Ciq9kway.mjs.map +1 -0
- package/package.json +26 -23
- package/style.css +2 -0
- package/dist/browser/assets/entry-DSBtQnit.js +0 -314
- package/dist/browser/assets/projection-entry-Bem3exmO.js +0 -404
- package/dist/browser/button-CuO8Gh3v.js +0 -696
- package/dist/browser/button-CuO8Gh3v.js.map +0 -1
- package/dist/browser/connect-5NZDVmbb.js +0 -14328
- package/dist/browser/connect-5NZDVmbb.js.map +0 -1
- package/dist/browser/dist-1yB-AuT-.js +0 -4641
- package/dist/browser/dist-1yB-AuT-.js.map +0 -1
- package/dist/browser/dist-B4FWbuEM.js +0 -4148
- package/dist/browser/dist-B4FWbuEM.js.map +0 -1
- package/dist/browser/dist-BAJ5nRDl.js.map +0 -1
- package/dist/browser/document-drive-CrvzV1D4.js +0 -8319
- package/dist/browser/document-drive-CrvzV1D4.js.map +0 -1
- package/dist/browser/documents-J_l59mSV.js +0 -6188
- package/dist/browser/documents-J_l59mSV.js.map +0 -1
- package/dist/browser/editor-6T4WF2og.js.map +0 -1
- package/dist/browser/folder-view-DTewe8q8.js.map +0 -1
- package/dist/browser/graphql-editor-C2EtXqb9.js +0 -11698
- package/dist/browser/graphql-editor-C2EtXqb9.js.map +0 -1
- package/dist/browser/hooks-KKcNp2X0.js +0 -24213
- package/dist/browser/hooks-KKcNp2X0.js.map +0 -1
- package/dist/browser/json-editor-xI_oaxyT.js.map +0 -1
- package/dist/browser/lib-CPkPeg_u.js +0 -209
- package/dist/browser/lib-CPkPeg_u.js.map +0 -1
- package/dist/browser/parser-CkF6Qt8V.js +0 -2553
- package/dist/browser/parser-CkF6Qt8V.js.map +0 -1
- package/dist/browser/printer-CEYr4JOg.js +0 -604
- package/dist/browser/printer-CEYr4JOg.js.map +0 -1
- package/dist/browser/schema-context-ZyeclQwy.js.map +0 -1
- package/dist/browser/state-schemas-CpcWN_Qo.js.map +0 -1
- package/dist/node/button-Da7CxMn7.mjs +0 -678
- package/dist/node/button-Da7CxMn7.mjs.map +0 -1
- package/dist/node/connect-cjzsd2cR.mjs +0 -15022
- package/dist/node/connect-cjzsd2cR.mjs.map +0 -1
- package/dist/node/dist-C30J_pcg.mjs +0 -4649
- package/dist/node/dist-C30J_pcg.mjs.map +0 -1
- package/dist/node/dist-CzYOpeXN.mjs +0 -2711
- package/dist/node/dist-CzYOpeXN.mjs.map +0 -1
- package/dist/node/dist-DT7jI9ol.mjs +0 -4148
- package/dist/node/dist-DT7jI9ol.mjs.map +0 -1
- package/dist/node/document-drive-BByBwg-I.mjs +0 -8336
- package/dist/node/document-drive-BByBwg-I.mjs.map +0 -1
- package/dist/node/documents-DCf53bzO.mjs +0 -747
- package/dist/node/documents-DCf53bzO.mjs.map +0 -1
- package/dist/node/editor-B4vhYrmV.mjs +0 -1809
- package/dist/node/editor-B4vhYrmV.mjs.map +0 -1
- package/dist/node/folder-view-BhackcXO.mjs +0 -232
- package/dist/node/folder-view-BhackcXO.mjs.map +0 -1
- package/dist/node/graphql-BfAoPeWM.mjs.map +0 -1
- package/dist/node/graphql-editor-D0CHQeCL.mjs.map +0 -1
- package/dist/node/json-editor-Ckaem6ky.mjs +0 -154
- package/dist/node/main-BhH_ajBM.mjs +0 -745
- package/dist/node/main-BhH_ajBM.mjs.map +0 -1
- package/dist/node/schema-context-DL8jhi_d.mjs.map +0 -1
- package/dist/node/state-schemas-B1SNl8Ob.mjs +0 -299
- package/dist/node/state-schemas-B1SNl8Ob.mjs.map +0 -1
|
@@ -0,0 +1,966 @@
|
|
|
1
|
+
import { t as twMerge } from "./bundle-mjs-Cuu3DEfT.mjs";
|
|
2
|
+
import * as React$1 from "react";
|
|
3
|
+
import React, { useRef, useState } from "react";
|
|
4
|
+
import { CreateDocumentWithTypeModal, FileItem, FolderItem, Icon, PowerhouseButton, useWindowSize } from "@powerhousedao/design-system/connect";
|
|
5
|
+
import { addDocument, isFileNodeKind, isFolderNodeKind, preloadEditorModule, useAllowedDocumentModelModules, useDisabledEditors, useEditorModules, useNodesInSelectedDriveOrFolder, useParentFolderForSelectedNode, useSelectedDriveSafe, useSelectedFolder, useSetSelectedNode, useStudioMode, useUserPermissions } from "@powerhousedao/reactor-browser";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { flushSync } from "react-dom";
|
|
8
|
+
//#region editors/generic-drive-explorer/utils/select-creatable-modules.ts
|
|
9
|
+
/**
|
|
10
|
+
* The modules a user may pick from when creating a new document. Outside
|
|
11
|
+
* studio mode only the latest version of each document type is offered: new
|
|
12
|
+
* documents should never start on an outdated schema. Builders testing
|
|
13
|
+
* migrations run in studio mode and still get every version.
|
|
14
|
+
*/
|
|
15
|
+
function selectCreatableModules(modules, studioMode) {
|
|
16
|
+
if (studioMode) return [...modules];
|
|
17
|
+
const latestByType = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const module of modules) {
|
|
19
|
+
const id = module.documentModel.global.id;
|
|
20
|
+
const current = latestByType.get(id);
|
|
21
|
+
if (!current || (module.version ?? 1) > (current.version ?? 1)) latestByType.set(id, module);
|
|
22
|
+
}
|
|
23
|
+
return [...latestByType.values()];
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region editors/generic-drive-explorer/components/create-document.tsx
|
|
27
|
+
function toDocumentTypeOption(doc, studioMode) {
|
|
28
|
+
const spec = doc.documentModel.global;
|
|
29
|
+
return {
|
|
30
|
+
documentType: spec.id,
|
|
31
|
+
name: spec.name,
|
|
32
|
+
version: studioMode ? doc.version : void 0,
|
|
33
|
+
description: spec.description
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function CreateDocument() {
|
|
37
|
+
const [showModal, setShowModal] = useState(false);
|
|
38
|
+
const setSelectedNode = useSetSelectedNode();
|
|
39
|
+
const { isAllowedToCreateDocuments } = useUserPermissions();
|
|
40
|
+
const allowedDocumentModelModules = useAllowedDocumentModelModules();
|
|
41
|
+
const editorModules = useEditorModules();
|
|
42
|
+
const disabledEditors = useDisabledEditors() ?? [];
|
|
43
|
+
const [selectedDrive] = useSelectedDriveSafe();
|
|
44
|
+
const selectedFolder = useSelectedFolder();
|
|
45
|
+
const parentFolder = useParentFolderForSelectedNode();
|
|
46
|
+
const DRIVE_CONTAINER_TYPES = ["powerhouse/document-drive", "powerhouse/reactor-drive"];
|
|
47
|
+
const studioMode = useStudioMode() ?? false;
|
|
48
|
+
const visibleDocumentModelModules = selectCreatableModules(allowedDocumentModelModules ?? [], studioMode).filter((module) => {
|
|
49
|
+
const id = module.documentModel.global.id;
|
|
50
|
+
return !DRIVE_CONTAINER_TYPES.includes(id) && !disabledEditors.includes(id);
|
|
51
|
+
});
|
|
52
|
+
const preloadEditorsForType = (documentType) => editorModules?.filter((editorModule) => editorModule.documentTypes.includes(documentType)).forEach((editorModule) => {
|
|
53
|
+
preloadEditorModule(editorModule);
|
|
54
|
+
});
|
|
55
|
+
const handleCreate = async ({ name, documentType, version }) => {
|
|
56
|
+
setShowModal(false);
|
|
57
|
+
if (!selectedDrive) return;
|
|
58
|
+
try {
|
|
59
|
+
const node = await addDocument(selectedDrive.header.id, name, documentType, selectedFolder?.id ?? parentFolder?.id, void 0, void 0, void 0, version);
|
|
60
|
+
setSelectedNode(node);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("Failed to create document:", error);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (!isAllowedToCreateDocuments) return null;
|
|
66
|
+
if (!visibleDocumentModelModules.length) return null;
|
|
67
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(PowerhouseButton, {
|
|
68
|
+
className: "py-2",
|
|
69
|
+
color: "blue",
|
|
70
|
+
icon: /* @__PURE__ */ jsx(Icon, {
|
|
71
|
+
name: "Plus",
|
|
72
|
+
size: 14
|
|
73
|
+
}),
|
|
74
|
+
onClick: () => setShowModal(true),
|
|
75
|
+
size: "small",
|
|
76
|
+
children: "Create New Document"
|
|
77
|
+
}), /* @__PURE__ */ jsx(CreateDocumentWithTypeModal, {
|
|
78
|
+
documentTypes: visibleDocumentModelModules.map((module) => toDocumentTypeOption(module, studioMode)),
|
|
79
|
+
onCreate: (input) => void handleCreate(input),
|
|
80
|
+
onOpenChange: setShowModal,
|
|
81
|
+
onTypeSelected: preloadEditorsForType,
|
|
82
|
+
open: showModal
|
|
83
|
+
})] });
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region ../../node_modules/.pnpm/@tanstack+virtual-core@3.13.19/node_modules/@tanstack/virtual-core/dist/esm/utils.js
|
|
87
|
+
function memo$1(getDeps, fn, opts) {
|
|
88
|
+
let deps = opts.initialDeps ?? [];
|
|
89
|
+
let result;
|
|
90
|
+
let isInitial = true;
|
|
91
|
+
function memoizedFunction() {
|
|
92
|
+
var _a, _b, _c;
|
|
93
|
+
let depTime;
|
|
94
|
+
if (opts.key && ((_a = opts.debug) == null ? void 0 : _a.call(opts))) depTime = Date.now();
|
|
95
|
+
const newDeps = getDeps();
|
|
96
|
+
if (!(newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep))) return result;
|
|
97
|
+
deps = newDeps;
|
|
98
|
+
let resultTime;
|
|
99
|
+
if (opts.key && ((_b = opts.debug) == null ? void 0 : _b.call(opts))) resultTime = Date.now();
|
|
100
|
+
result = fn(...newDeps);
|
|
101
|
+
if (opts.key && ((_c = opts.debug) == null ? void 0 : _c.call(opts))) {
|
|
102
|
+
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
103
|
+
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
104
|
+
const resultFpsPercentage = resultEndTime / 16;
|
|
105
|
+
const pad = (str, num) => {
|
|
106
|
+
str = String(str);
|
|
107
|
+
while (str.length < num) str = " " + str;
|
|
108
|
+
return str;
|
|
109
|
+
};
|
|
110
|
+
console.info(`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
|
|
111
|
+
font-size: .6rem;
|
|
112
|
+
font-weight: bold;
|
|
113
|
+
color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
|
|
114
|
+
}
|
|
115
|
+
if ((opts == null ? void 0 : opts.onChange) && !(isInitial && opts.skipInitialOnChange)) opts.onChange(result);
|
|
116
|
+
isInitial = false;
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
memoizedFunction.updateDeps = (newDeps) => {
|
|
120
|
+
deps = newDeps;
|
|
121
|
+
};
|
|
122
|
+
return memoizedFunction;
|
|
123
|
+
}
|
|
124
|
+
function notUndefined(value, msg) {
|
|
125
|
+
if (value === void 0) throw new Error(`Unexpected undefined${msg ? `: ${msg}` : ""}`);
|
|
126
|
+
else return value;
|
|
127
|
+
}
|
|
128
|
+
const approxEqual = (a, b) => Math.abs(a - b) < 1.01;
|
|
129
|
+
const debounce = (targetWindow, fn, ms) => {
|
|
130
|
+
let timeoutId;
|
|
131
|
+
return function(...args) {
|
|
132
|
+
targetWindow.clearTimeout(timeoutId);
|
|
133
|
+
timeoutId = targetWindow.setTimeout(() => fn.apply(this, args), ms);
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region ../../node_modules/.pnpm/@tanstack+virtual-core@3.13.19/node_modules/@tanstack/virtual-core/dist/esm/index.js
|
|
138
|
+
const getRect = (element) => {
|
|
139
|
+
const { offsetWidth, offsetHeight } = element;
|
|
140
|
+
return {
|
|
141
|
+
width: offsetWidth,
|
|
142
|
+
height: offsetHeight
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
const defaultKeyExtractor = (index) => index;
|
|
146
|
+
const defaultRangeExtractor = (range) => {
|
|
147
|
+
const start = Math.max(range.startIndex - range.overscan, 0);
|
|
148
|
+
const end = Math.min(range.endIndex + range.overscan, range.count - 1);
|
|
149
|
+
const arr = [];
|
|
150
|
+
for (let i = start; i <= end; i++) arr.push(i);
|
|
151
|
+
return arr;
|
|
152
|
+
};
|
|
153
|
+
const observeElementRect = (instance, cb) => {
|
|
154
|
+
const element = instance.scrollElement;
|
|
155
|
+
if (!element) return;
|
|
156
|
+
const targetWindow = instance.targetWindow;
|
|
157
|
+
if (!targetWindow) return;
|
|
158
|
+
const handler = (rect) => {
|
|
159
|
+
const { width, height } = rect;
|
|
160
|
+
cb({
|
|
161
|
+
width: Math.round(width),
|
|
162
|
+
height: Math.round(height)
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
handler(getRect(element));
|
|
166
|
+
if (!targetWindow.ResizeObserver) return () => {};
|
|
167
|
+
const observer = new targetWindow.ResizeObserver((entries) => {
|
|
168
|
+
const run = () => {
|
|
169
|
+
const entry = entries[0];
|
|
170
|
+
if (entry == null ? void 0 : entry.borderBoxSize) {
|
|
171
|
+
const box = entry.borderBoxSize[0];
|
|
172
|
+
if (box) {
|
|
173
|
+
handler({
|
|
174
|
+
width: box.inlineSize,
|
|
175
|
+
height: box.blockSize
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
handler(getRect(element));
|
|
181
|
+
};
|
|
182
|
+
instance.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
|
|
183
|
+
});
|
|
184
|
+
observer.observe(element, { box: "border-box" });
|
|
185
|
+
return () => {
|
|
186
|
+
observer.unobserve(element);
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const addEventListenerOptions = { passive: true };
|
|
190
|
+
const supportsScrollend = typeof window == "undefined" ? true : "onscrollend" in window;
|
|
191
|
+
const observeElementOffset = (instance, cb) => {
|
|
192
|
+
const element = instance.scrollElement;
|
|
193
|
+
if (!element) return;
|
|
194
|
+
const targetWindow = instance.targetWindow;
|
|
195
|
+
if (!targetWindow) return;
|
|
196
|
+
let offset = 0;
|
|
197
|
+
const fallback = instance.options.useScrollendEvent && supportsScrollend ? () => void 0 : debounce(targetWindow, () => {
|
|
198
|
+
cb(offset, false);
|
|
199
|
+
}, instance.options.isScrollingResetDelay);
|
|
200
|
+
const createHandler = (isScrolling) => () => {
|
|
201
|
+
const { horizontal, isRtl } = instance.options;
|
|
202
|
+
offset = horizontal ? element["scrollLeft"] * (isRtl && -1 || 1) : element["scrollTop"];
|
|
203
|
+
fallback();
|
|
204
|
+
cb(offset, isScrolling);
|
|
205
|
+
};
|
|
206
|
+
const handler = createHandler(true);
|
|
207
|
+
const endHandler = createHandler(false);
|
|
208
|
+
element.addEventListener("scroll", handler, addEventListenerOptions);
|
|
209
|
+
const registerScrollendEvent = instance.options.useScrollendEvent && supportsScrollend;
|
|
210
|
+
if (registerScrollendEvent) element.addEventListener("scrollend", endHandler, addEventListenerOptions);
|
|
211
|
+
return () => {
|
|
212
|
+
element.removeEventListener("scroll", handler);
|
|
213
|
+
if (registerScrollendEvent) element.removeEventListener("scrollend", endHandler);
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
const measureElement = (element, entry, instance) => {
|
|
217
|
+
if (entry == null ? void 0 : entry.borderBoxSize) {
|
|
218
|
+
const box = entry.borderBoxSize[0];
|
|
219
|
+
if (box) return Math.round(box[instance.options.horizontal ? "inlineSize" : "blockSize"]);
|
|
220
|
+
}
|
|
221
|
+
return element[instance.options.horizontal ? "offsetWidth" : "offsetHeight"];
|
|
222
|
+
};
|
|
223
|
+
const elementScroll = (offset, { adjustments = 0, behavior }, instance) => {
|
|
224
|
+
var _a, _b;
|
|
225
|
+
const toOffset = offset + adjustments;
|
|
226
|
+
(_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null || _b.call(_a, {
|
|
227
|
+
[instance.options.horizontal ? "left" : "top"]: toOffset,
|
|
228
|
+
behavior
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
var Virtualizer = class {
|
|
232
|
+
constructor(opts) {
|
|
233
|
+
this.unsubs = [];
|
|
234
|
+
this.scrollElement = null;
|
|
235
|
+
this.targetWindow = null;
|
|
236
|
+
this.isScrolling = false;
|
|
237
|
+
this.currentScrollToIndex = null;
|
|
238
|
+
this.measurementsCache = [];
|
|
239
|
+
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
240
|
+
this.laneAssignments = /* @__PURE__ */ new Map();
|
|
241
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
242
|
+
this.prevLanes = void 0;
|
|
243
|
+
this.lanesChangedFlag = false;
|
|
244
|
+
this.lanesSettling = false;
|
|
245
|
+
this.scrollRect = null;
|
|
246
|
+
this.scrollOffset = null;
|
|
247
|
+
this.scrollDirection = null;
|
|
248
|
+
this.scrollAdjustments = 0;
|
|
249
|
+
this.elementsCache = /* @__PURE__ */ new Map();
|
|
250
|
+
this.observer = /* @__PURE__ */ (() => {
|
|
251
|
+
let _ro = null;
|
|
252
|
+
const get = () => {
|
|
253
|
+
if (_ro) return _ro;
|
|
254
|
+
if (!this.targetWindow || !this.targetWindow.ResizeObserver) return null;
|
|
255
|
+
return _ro = new this.targetWindow.ResizeObserver((entries) => {
|
|
256
|
+
entries.forEach((entry) => {
|
|
257
|
+
const run = () => {
|
|
258
|
+
this._measureElement(entry.target, entry);
|
|
259
|
+
};
|
|
260
|
+
this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
disconnect: () => {
|
|
266
|
+
var _a;
|
|
267
|
+
(_a = get()) == null || _a.disconnect();
|
|
268
|
+
_ro = null;
|
|
269
|
+
},
|
|
270
|
+
observe: (target) => {
|
|
271
|
+
var _a;
|
|
272
|
+
return (_a = get()) == null ? void 0 : _a.observe(target, { box: "border-box" });
|
|
273
|
+
},
|
|
274
|
+
unobserve: (target) => {
|
|
275
|
+
var _a;
|
|
276
|
+
return (_a = get()) == null ? void 0 : _a.unobserve(target);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
})();
|
|
280
|
+
this.range = null;
|
|
281
|
+
this.setOptions = (opts2) => {
|
|
282
|
+
Object.entries(opts2).forEach(([key, value]) => {
|
|
283
|
+
if (typeof value === "undefined") delete opts2[key];
|
|
284
|
+
});
|
|
285
|
+
this.options = {
|
|
286
|
+
debug: false,
|
|
287
|
+
initialOffset: 0,
|
|
288
|
+
overscan: 1,
|
|
289
|
+
paddingStart: 0,
|
|
290
|
+
paddingEnd: 0,
|
|
291
|
+
scrollPaddingStart: 0,
|
|
292
|
+
scrollPaddingEnd: 0,
|
|
293
|
+
horizontal: false,
|
|
294
|
+
getItemKey: defaultKeyExtractor,
|
|
295
|
+
rangeExtractor: defaultRangeExtractor,
|
|
296
|
+
onChange: () => {},
|
|
297
|
+
measureElement,
|
|
298
|
+
initialRect: {
|
|
299
|
+
width: 0,
|
|
300
|
+
height: 0
|
|
301
|
+
},
|
|
302
|
+
scrollMargin: 0,
|
|
303
|
+
gap: 0,
|
|
304
|
+
indexAttribute: "data-index",
|
|
305
|
+
initialMeasurementsCache: [],
|
|
306
|
+
lanes: 1,
|
|
307
|
+
isScrollingResetDelay: 150,
|
|
308
|
+
enabled: true,
|
|
309
|
+
isRtl: false,
|
|
310
|
+
useScrollendEvent: false,
|
|
311
|
+
useAnimationFrameWithResizeObserver: false,
|
|
312
|
+
...opts2
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
this.notify = (sync) => {
|
|
316
|
+
var _a, _b;
|
|
317
|
+
(_b = (_a = this.options).onChange) == null || _b.call(_a, this, sync);
|
|
318
|
+
};
|
|
319
|
+
this.maybeNotify = memo$1(() => {
|
|
320
|
+
this.calculateRange();
|
|
321
|
+
return [
|
|
322
|
+
this.isScrolling,
|
|
323
|
+
this.range ? this.range.startIndex : null,
|
|
324
|
+
this.range ? this.range.endIndex : null
|
|
325
|
+
];
|
|
326
|
+
}, (isScrolling) => {
|
|
327
|
+
this.notify(isScrolling);
|
|
328
|
+
}, {
|
|
329
|
+
key: process.env.NODE_ENV !== "production" && "maybeNotify",
|
|
330
|
+
debug: () => this.options.debug,
|
|
331
|
+
initialDeps: [
|
|
332
|
+
this.isScrolling,
|
|
333
|
+
this.range ? this.range.startIndex : null,
|
|
334
|
+
this.range ? this.range.endIndex : null
|
|
335
|
+
]
|
|
336
|
+
});
|
|
337
|
+
this.cleanup = () => {
|
|
338
|
+
this.unsubs.filter(Boolean).forEach((d) => d());
|
|
339
|
+
this.unsubs = [];
|
|
340
|
+
this.observer.disconnect();
|
|
341
|
+
this.scrollElement = null;
|
|
342
|
+
this.targetWindow = null;
|
|
343
|
+
};
|
|
344
|
+
this._didMount = () => {
|
|
345
|
+
return () => {
|
|
346
|
+
this.cleanup();
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
this._willUpdate = () => {
|
|
350
|
+
var _a;
|
|
351
|
+
const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
|
|
352
|
+
if (this.scrollElement !== scrollElement) {
|
|
353
|
+
this.cleanup();
|
|
354
|
+
if (!scrollElement) {
|
|
355
|
+
this.maybeNotify();
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
this.scrollElement = scrollElement;
|
|
359
|
+
if (this.scrollElement && "ownerDocument" in this.scrollElement) this.targetWindow = this.scrollElement.ownerDocument.defaultView;
|
|
360
|
+
else this.targetWindow = ((_a = this.scrollElement) == null ? void 0 : _a.window) ?? null;
|
|
361
|
+
this.elementsCache.forEach((cached) => {
|
|
362
|
+
this.observer.observe(cached);
|
|
363
|
+
});
|
|
364
|
+
this.unsubs.push(this.options.observeElementRect(this, (rect) => {
|
|
365
|
+
this.scrollRect = rect;
|
|
366
|
+
this.maybeNotify();
|
|
367
|
+
}));
|
|
368
|
+
this.unsubs.push(this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
369
|
+
this.scrollAdjustments = 0;
|
|
370
|
+
this.scrollDirection = isScrolling ? this.getScrollOffset() < offset ? "forward" : "backward" : null;
|
|
371
|
+
this.scrollOffset = offset;
|
|
372
|
+
this.isScrolling = isScrolling;
|
|
373
|
+
this.maybeNotify();
|
|
374
|
+
}));
|
|
375
|
+
this._scrollToOffset(this.getScrollOffset(), {
|
|
376
|
+
adjustments: void 0,
|
|
377
|
+
behavior: void 0
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
this.getSize = () => {
|
|
382
|
+
if (!this.options.enabled) {
|
|
383
|
+
this.scrollRect = null;
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
this.scrollRect = this.scrollRect ?? this.options.initialRect;
|
|
387
|
+
return this.scrollRect[this.options.horizontal ? "width" : "height"];
|
|
388
|
+
};
|
|
389
|
+
this.getScrollOffset = () => {
|
|
390
|
+
if (!this.options.enabled) {
|
|
391
|
+
this.scrollOffset = null;
|
|
392
|
+
return 0;
|
|
393
|
+
}
|
|
394
|
+
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
|
|
395
|
+
return this.scrollOffset;
|
|
396
|
+
};
|
|
397
|
+
this.getFurthestMeasurement = (measurements, index) => {
|
|
398
|
+
const furthestMeasurementsFound = /* @__PURE__ */ new Map();
|
|
399
|
+
const furthestMeasurements = /* @__PURE__ */ new Map();
|
|
400
|
+
for (let m = index - 1; m >= 0; m--) {
|
|
401
|
+
const measurement = measurements[m];
|
|
402
|
+
if (furthestMeasurementsFound.has(measurement.lane)) continue;
|
|
403
|
+
const previousFurthestMeasurement = furthestMeasurements.get(measurement.lane);
|
|
404
|
+
if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) furthestMeasurements.set(measurement.lane, measurement);
|
|
405
|
+
else if (measurement.end < previousFurthestMeasurement.end) furthestMeasurementsFound.set(measurement.lane, true);
|
|
406
|
+
if (furthestMeasurementsFound.size === this.options.lanes) break;
|
|
407
|
+
}
|
|
408
|
+
return furthestMeasurements.size === this.options.lanes ? Array.from(furthestMeasurements.values()).sort((a, b) => {
|
|
409
|
+
if (a.end === b.end) return a.index - b.index;
|
|
410
|
+
return a.end - b.end;
|
|
411
|
+
})[0] : void 0;
|
|
412
|
+
};
|
|
413
|
+
this.getMeasurementOptions = memo$1(() => [
|
|
414
|
+
this.options.count,
|
|
415
|
+
this.options.paddingStart,
|
|
416
|
+
this.options.scrollMargin,
|
|
417
|
+
this.options.getItemKey,
|
|
418
|
+
this.options.enabled,
|
|
419
|
+
this.options.lanes
|
|
420
|
+
], (count, paddingStart, scrollMargin, getItemKey, enabled, lanes) => {
|
|
421
|
+
if (this.prevLanes !== void 0 && this.prevLanes !== lanes) this.lanesChangedFlag = true;
|
|
422
|
+
this.prevLanes = lanes;
|
|
423
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
424
|
+
return {
|
|
425
|
+
count,
|
|
426
|
+
paddingStart,
|
|
427
|
+
scrollMargin,
|
|
428
|
+
getItemKey,
|
|
429
|
+
enabled,
|
|
430
|
+
lanes
|
|
431
|
+
};
|
|
432
|
+
}, { key: false });
|
|
433
|
+
this.getMeasurements = memo$1(() => [this.getMeasurementOptions(), this.itemSizeCache], ({ count, paddingStart, scrollMargin, getItemKey, enabled, lanes }, itemSizeCache) => {
|
|
434
|
+
if (!enabled) {
|
|
435
|
+
this.measurementsCache = [];
|
|
436
|
+
this.itemSizeCache.clear();
|
|
437
|
+
this.laneAssignments.clear();
|
|
438
|
+
return [];
|
|
439
|
+
}
|
|
440
|
+
if (this.laneAssignments.size > count) {
|
|
441
|
+
for (const index of this.laneAssignments.keys()) if (index >= count) this.laneAssignments.delete(index);
|
|
442
|
+
}
|
|
443
|
+
if (this.lanesChangedFlag) {
|
|
444
|
+
this.lanesChangedFlag = false;
|
|
445
|
+
this.lanesSettling = true;
|
|
446
|
+
this.measurementsCache = [];
|
|
447
|
+
this.itemSizeCache.clear();
|
|
448
|
+
this.laneAssignments.clear();
|
|
449
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
450
|
+
}
|
|
451
|
+
if (this.measurementsCache.length === 0 && !this.lanesSettling) {
|
|
452
|
+
this.measurementsCache = this.options.initialMeasurementsCache;
|
|
453
|
+
this.measurementsCache.forEach((item) => {
|
|
454
|
+
this.itemSizeCache.set(item.key, item.size);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
const min = this.lanesSettling ? 0 : this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
|
|
458
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
459
|
+
if (this.lanesSettling && this.measurementsCache.length === count) this.lanesSettling = false;
|
|
460
|
+
const measurements = this.measurementsCache.slice(0, min);
|
|
461
|
+
const laneLastIndex = new Array(lanes).fill(void 0);
|
|
462
|
+
for (let m = 0; m < min; m++) {
|
|
463
|
+
const item = measurements[m];
|
|
464
|
+
if (item) laneLastIndex[item.lane] = m;
|
|
465
|
+
}
|
|
466
|
+
for (let i = min; i < count; i++) {
|
|
467
|
+
const key = getItemKey(i);
|
|
468
|
+
const cachedLane = this.laneAssignments.get(i);
|
|
469
|
+
let lane;
|
|
470
|
+
let start;
|
|
471
|
+
if (cachedLane !== void 0 && this.options.lanes > 1) {
|
|
472
|
+
lane = cachedLane;
|
|
473
|
+
const prevIndex = laneLastIndex[lane];
|
|
474
|
+
const prevInLane = prevIndex !== void 0 ? measurements[prevIndex] : void 0;
|
|
475
|
+
start = prevInLane ? prevInLane.end + this.options.gap : paddingStart + scrollMargin;
|
|
476
|
+
} else {
|
|
477
|
+
const furthestMeasurement = this.options.lanes === 1 ? measurements[i - 1] : this.getFurthestMeasurement(measurements, i);
|
|
478
|
+
start = furthestMeasurement ? furthestMeasurement.end + this.options.gap : paddingStart + scrollMargin;
|
|
479
|
+
lane = furthestMeasurement ? furthestMeasurement.lane : i % this.options.lanes;
|
|
480
|
+
if (this.options.lanes > 1) this.laneAssignments.set(i, lane);
|
|
481
|
+
}
|
|
482
|
+
const measuredSize = itemSizeCache.get(key);
|
|
483
|
+
const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
|
|
484
|
+
const end = start + size;
|
|
485
|
+
measurements[i] = {
|
|
486
|
+
index: i,
|
|
487
|
+
start,
|
|
488
|
+
size,
|
|
489
|
+
end,
|
|
490
|
+
key,
|
|
491
|
+
lane
|
|
492
|
+
};
|
|
493
|
+
laneLastIndex[lane] = i;
|
|
494
|
+
}
|
|
495
|
+
this.measurementsCache = measurements;
|
|
496
|
+
return measurements;
|
|
497
|
+
}, {
|
|
498
|
+
key: process.env.NODE_ENV !== "production" && "getMeasurements",
|
|
499
|
+
debug: () => this.options.debug
|
|
500
|
+
});
|
|
501
|
+
this.calculateRange = memo$1(() => [
|
|
502
|
+
this.getMeasurements(),
|
|
503
|
+
this.getSize(),
|
|
504
|
+
this.getScrollOffset(),
|
|
505
|
+
this.options.lanes
|
|
506
|
+
], (measurements, outerSize, scrollOffset, lanes) => {
|
|
507
|
+
return this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
|
|
508
|
+
measurements,
|
|
509
|
+
outerSize,
|
|
510
|
+
scrollOffset,
|
|
511
|
+
lanes
|
|
512
|
+
}) : null;
|
|
513
|
+
}, {
|
|
514
|
+
key: process.env.NODE_ENV !== "production" && "calculateRange",
|
|
515
|
+
debug: () => this.options.debug
|
|
516
|
+
});
|
|
517
|
+
this.getVirtualIndexes = memo$1(() => {
|
|
518
|
+
let startIndex = null;
|
|
519
|
+
let endIndex = null;
|
|
520
|
+
const range = this.calculateRange();
|
|
521
|
+
if (range) {
|
|
522
|
+
startIndex = range.startIndex;
|
|
523
|
+
endIndex = range.endIndex;
|
|
524
|
+
}
|
|
525
|
+
this.maybeNotify.updateDeps([
|
|
526
|
+
this.isScrolling,
|
|
527
|
+
startIndex,
|
|
528
|
+
endIndex
|
|
529
|
+
]);
|
|
530
|
+
return [
|
|
531
|
+
this.options.rangeExtractor,
|
|
532
|
+
this.options.overscan,
|
|
533
|
+
this.options.count,
|
|
534
|
+
startIndex,
|
|
535
|
+
endIndex
|
|
536
|
+
];
|
|
537
|
+
}, (rangeExtractor, overscan, count, startIndex, endIndex) => {
|
|
538
|
+
return startIndex === null || endIndex === null ? [] : rangeExtractor({
|
|
539
|
+
startIndex,
|
|
540
|
+
endIndex,
|
|
541
|
+
overscan,
|
|
542
|
+
count
|
|
543
|
+
});
|
|
544
|
+
}, {
|
|
545
|
+
key: process.env.NODE_ENV !== "production" && "getVirtualIndexes",
|
|
546
|
+
debug: () => this.options.debug
|
|
547
|
+
});
|
|
548
|
+
this.indexFromElement = (node) => {
|
|
549
|
+
const attributeName = this.options.indexAttribute;
|
|
550
|
+
const indexStr = node.getAttribute(attributeName);
|
|
551
|
+
if (!indexStr) {
|
|
552
|
+
console.warn(`Missing attribute name '${attributeName}={index}' on measured element.`);
|
|
553
|
+
return -1;
|
|
554
|
+
}
|
|
555
|
+
return parseInt(indexStr, 10);
|
|
556
|
+
};
|
|
557
|
+
this._measureElement = (node, entry) => {
|
|
558
|
+
const index = this.indexFromElement(node);
|
|
559
|
+
const item = this.measurementsCache[index];
|
|
560
|
+
if (!item) return;
|
|
561
|
+
const key = item.key;
|
|
562
|
+
const prevNode = this.elementsCache.get(key);
|
|
563
|
+
if (prevNode !== node) {
|
|
564
|
+
if (prevNode) this.observer.unobserve(prevNode);
|
|
565
|
+
this.observer.observe(node);
|
|
566
|
+
this.elementsCache.set(key, node);
|
|
567
|
+
}
|
|
568
|
+
if (node.isConnected) this.resizeItem(index, this.options.measureElement(node, entry, this));
|
|
569
|
+
};
|
|
570
|
+
this.resizeItem = (index, size) => {
|
|
571
|
+
const item = this.measurementsCache[index];
|
|
572
|
+
if (!item) return;
|
|
573
|
+
const delta = size - (this.itemSizeCache.get(item.key) ?? item.size);
|
|
574
|
+
if (delta !== 0) {
|
|
575
|
+
if (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(item, delta, this) : item.start < this.getScrollOffset() + this.scrollAdjustments) {
|
|
576
|
+
if (process.env.NODE_ENV !== "production" && this.options.debug) console.info("correction", delta);
|
|
577
|
+
this._scrollToOffset(this.getScrollOffset(), {
|
|
578
|
+
adjustments: this.scrollAdjustments += delta,
|
|
579
|
+
behavior: void 0
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
this.pendingMeasuredCacheIndexes.push(item.index);
|
|
583
|
+
this.itemSizeCache = new Map(this.itemSizeCache.set(item.key, size));
|
|
584
|
+
this.notify(false);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
this.measureElement = (node) => {
|
|
588
|
+
if (!node) {
|
|
589
|
+
this.elementsCache.forEach((cached, key) => {
|
|
590
|
+
if (!cached.isConnected) {
|
|
591
|
+
this.observer.unobserve(cached);
|
|
592
|
+
this.elementsCache.delete(key);
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
this._measureElement(node, void 0);
|
|
598
|
+
};
|
|
599
|
+
this.getVirtualItems = memo$1(() => [this.getVirtualIndexes(), this.getMeasurements()], (indexes, measurements) => {
|
|
600
|
+
const virtualItems = [];
|
|
601
|
+
for (let k = 0, len = indexes.length; k < len; k++) {
|
|
602
|
+
const measurement = measurements[indexes[k]];
|
|
603
|
+
virtualItems.push(measurement);
|
|
604
|
+
}
|
|
605
|
+
return virtualItems;
|
|
606
|
+
}, {
|
|
607
|
+
key: process.env.NODE_ENV !== "production" && "getVirtualItems",
|
|
608
|
+
debug: () => this.options.debug
|
|
609
|
+
});
|
|
610
|
+
this.getVirtualItemForOffset = (offset) => {
|
|
611
|
+
const measurements = this.getMeasurements();
|
|
612
|
+
if (measurements.length === 0) return;
|
|
613
|
+
return notUndefined(measurements[findNearestBinarySearch(0, measurements.length - 1, (index) => notUndefined(measurements[index]).start, offset)]);
|
|
614
|
+
};
|
|
615
|
+
this.getMaxScrollOffset = () => {
|
|
616
|
+
if (!this.scrollElement) return 0;
|
|
617
|
+
if ("scrollHeight" in this.scrollElement) return this.options.horizontal ? this.scrollElement.scrollWidth - this.scrollElement.clientWidth : this.scrollElement.scrollHeight - this.scrollElement.clientHeight;
|
|
618
|
+
else {
|
|
619
|
+
const doc = this.scrollElement.document.documentElement;
|
|
620
|
+
return this.options.horizontal ? doc.scrollWidth - this.scrollElement.innerWidth : doc.scrollHeight - this.scrollElement.innerHeight;
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
this.getOffsetForAlignment = (toOffset, align, itemSize = 0) => {
|
|
624
|
+
if (!this.scrollElement) return 0;
|
|
625
|
+
const size = this.getSize();
|
|
626
|
+
const scrollOffset = this.getScrollOffset();
|
|
627
|
+
if (align === "auto") align = toOffset >= scrollOffset + size ? "end" : "start";
|
|
628
|
+
if (align === "center") toOffset += (itemSize - size) / 2;
|
|
629
|
+
else if (align === "end") toOffset -= size;
|
|
630
|
+
const maxOffset = this.getMaxScrollOffset();
|
|
631
|
+
return Math.max(Math.min(maxOffset, toOffset), 0);
|
|
632
|
+
};
|
|
633
|
+
this.getOffsetForIndex = (index, align = "auto") => {
|
|
634
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
635
|
+
const item = this.measurementsCache[index];
|
|
636
|
+
if (!item) return;
|
|
637
|
+
const size = this.getSize();
|
|
638
|
+
const scrollOffset = this.getScrollOffset();
|
|
639
|
+
if (align === "auto") {
|
|
640
|
+
if (item.end >= scrollOffset + size - this.options.scrollPaddingEnd) align = "end";
|
|
641
|
+
else if (item.start <= scrollOffset + this.options.scrollPaddingStart) align = "start";
|
|
642
|
+
else return [scrollOffset, align];
|
|
643
|
+
}
|
|
644
|
+
if (align === "end" && index === this.options.count - 1) return [this.getMaxScrollOffset(), align];
|
|
645
|
+
const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
|
|
646
|
+
return [this.getOffsetForAlignment(toOffset, align, item.size), align];
|
|
647
|
+
};
|
|
648
|
+
this.isDynamicMode = () => this.elementsCache.size > 0;
|
|
649
|
+
this.scrollToOffset = (toOffset, { align = "start", behavior } = {}) => {
|
|
650
|
+
if (behavior === "smooth" && this.isDynamicMode()) console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");
|
|
651
|
+
this._scrollToOffset(this.getOffsetForAlignment(toOffset, align), {
|
|
652
|
+
adjustments: void 0,
|
|
653
|
+
behavior
|
|
654
|
+
});
|
|
655
|
+
};
|
|
656
|
+
this.scrollToIndex = (index, { align: initialAlign = "auto", behavior } = {}) => {
|
|
657
|
+
if (behavior === "smooth" && this.isDynamicMode()) console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");
|
|
658
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
659
|
+
this.currentScrollToIndex = index;
|
|
660
|
+
let attempts = 0;
|
|
661
|
+
const maxAttempts = 10;
|
|
662
|
+
const tryScroll = (currentAlign) => {
|
|
663
|
+
if (!this.targetWindow) return;
|
|
664
|
+
const offsetInfo = this.getOffsetForIndex(index, currentAlign);
|
|
665
|
+
if (!offsetInfo) {
|
|
666
|
+
console.warn("Failed to get offset for index:", index);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const [offset, align] = offsetInfo;
|
|
670
|
+
this._scrollToOffset(offset, {
|
|
671
|
+
adjustments: void 0,
|
|
672
|
+
behavior
|
|
673
|
+
});
|
|
674
|
+
this.targetWindow.requestAnimationFrame(() => {
|
|
675
|
+
if (!this.targetWindow) return;
|
|
676
|
+
const verify = () => {
|
|
677
|
+
if (this.currentScrollToIndex !== index) return;
|
|
678
|
+
const currentOffset = this.getScrollOffset();
|
|
679
|
+
const afterInfo = this.getOffsetForIndex(index, align);
|
|
680
|
+
if (!afterInfo) {
|
|
681
|
+
console.warn("Failed to get offset for index:", index);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (!approxEqual(afterInfo[0], currentOffset)) scheduleRetry(align);
|
|
685
|
+
};
|
|
686
|
+
if (this.isDynamicMode()) this.targetWindow.requestAnimationFrame(verify);
|
|
687
|
+
else verify();
|
|
688
|
+
});
|
|
689
|
+
};
|
|
690
|
+
const scheduleRetry = (align) => {
|
|
691
|
+
if (!this.targetWindow) return;
|
|
692
|
+
if (this.currentScrollToIndex !== index) return;
|
|
693
|
+
attempts++;
|
|
694
|
+
if (attempts < maxAttempts) {
|
|
695
|
+
if (process.env.NODE_ENV !== "production" && this.options.debug) console.info("Schedule retry", attempts, maxAttempts);
|
|
696
|
+
this.targetWindow.requestAnimationFrame(() => tryScroll(align));
|
|
697
|
+
} else console.warn(`Failed to scroll to index ${index} after ${maxAttempts} attempts.`);
|
|
698
|
+
};
|
|
699
|
+
tryScroll(initialAlign);
|
|
700
|
+
};
|
|
701
|
+
this.scrollBy = (delta, { behavior } = {}) => {
|
|
702
|
+
if (behavior === "smooth" && this.isDynamicMode()) console.warn("The `smooth` scroll behavior is not fully supported with dynamic size.");
|
|
703
|
+
this._scrollToOffset(this.getScrollOffset() + delta, {
|
|
704
|
+
adjustments: void 0,
|
|
705
|
+
behavior
|
|
706
|
+
});
|
|
707
|
+
};
|
|
708
|
+
this.getTotalSize = () => {
|
|
709
|
+
var _a;
|
|
710
|
+
const measurements = this.getMeasurements();
|
|
711
|
+
let end;
|
|
712
|
+
if (measurements.length === 0) end = this.options.paddingStart;
|
|
713
|
+
else if (this.options.lanes === 1) end = ((_a = measurements[measurements.length - 1]) == null ? void 0 : _a.end) ?? 0;
|
|
714
|
+
else {
|
|
715
|
+
const endByLane = Array(this.options.lanes).fill(null);
|
|
716
|
+
let endIndex = measurements.length - 1;
|
|
717
|
+
while (endIndex >= 0 && endByLane.some((val) => val === null)) {
|
|
718
|
+
const item = measurements[endIndex];
|
|
719
|
+
if (endByLane[item.lane] === null) endByLane[item.lane] = item.end;
|
|
720
|
+
endIndex--;
|
|
721
|
+
}
|
|
722
|
+
end = Math.max(...endByLane.filter((val) => val !== null));
|
|
723
|
+
}
|
|
724
|
+
return Math.max(end - this.options.scrollMargin + this.options.paddingEnd, 0);
|
|
725
|
+
};
|
|
726
|
+
this._scrollToOffset = (offset, { adjustments, behavior }) => {
|
|
727
|
+
this.options.scrollToFn(offset, {
|
|
728
|
+
behavior,
|
|
729
|
+
adjustments
|
|
730
|
+
}, this);
|
|
731
|
+
};
|
|
732
|
+
this.measure = () => {
|
|
733
|
+
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
734
|
+
this.laneAssignments = /* @__PURE__ */ new Map();
|
|
735
|
+
this.notify(false);
|
|
736
|
+
};
|
|
737
|
+
this.setOptions(opts);
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
741
|
+
while (low <= high) {
|
|
742
|
+
const middle = (low + high) / 2 | 0;
|
|
743
|
+
const currentValue = getCurrentValue(middle);
|
|
744
|
+
if (currentValue < value) low = middle + 1;
|
|
745
|
+
else if (currentValue > value) high = middle - 1;
|
|
746
|
+
else return middle;
|
|
747
|
+
}
|
|
748
|
+
if (low > 0) return low - 1;
|
|
749
|
+
else return 0;
|
|
750
|
+
};
|
|
751
|
+
function calculateRange({ measurements, outerSize, scrollOffset, lanes }) {
|
|
752
|
+
const lastIndex = measurements.length - 1;
|
|
753
|
+
const getOffset = (index) => measurements[index].start;
|
|
754
|
+
if (measurements.length <= lanes) return {
|
|
755
|
+
startIndex: 0,
|
|
756
|
+
endIndex: lastIndex
|
|
757
|
+
};
|
|
758
|
+
let startIndex = findNearestBinarySearch(0, lastIndex, getOffset, scrollOffset);
|
|
759
|
+
let endIndex = startIndex;
|
|
760
|
+
if (lanes === 1) while (endIndex < lastIndex && measurements[endIndex].end < scrollOffset + outerSize) endIndex++;
|
|
761
|
+
else if (lanes > 1) {
|
|
762
|
+
const endPerLane = Array(lanes).fill(0);
|
|
763
|
+
while (endIndex < lastIndex && endPerLane.some((pos) => pos < scrollOffset + outerSize)) {
|
|
764
|
+
const item = measurements[endIndex];
|
|
765
|
+
endPerLane[item.lane] = item.end;
|
|
766
|
+
endIndex++;
|
|
767
|
+
}
|
|
768
|
+
const startPerLane = Array(lanes).fill(scrollOffset + outerSize);
|
|
769
|
+
while (startIndex >= 0 && startPerLane.some((pos) => pos >= scrollOffset)) {
|
|
770
|
+
const item = measurements[startIndex];
|
|
771
|
+
startPerLane[item.lane] = item.start;
|
|
772
|
+
startIndex--;
|
|
773
|
+
}
|
|
774
|
+
startIndex = Math.max(0, startIndex - startIndex % lanes);
|
|
775
|
+
endIndex = Math.min(lastIndex, endIndex + (lanes - 1 - endIndex % lanes));
|
|
776
|
+
}
|
|
777
|
+
return {
|
|
778
|
+
startIndex,
|
|
779
|
+
endIndex
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
//#endregion
|
|
783
|
+
//#region ../../node_modules/.pnpm/@tanstack+react-virtual@3.13.19_react-dom@19.2.6_react@19.2.6__react@19.2.6/node_modules/@tanstack/react-virtual/dist/esm/index.js
|
|
784
|
+
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React$1.useLayoutEffect : React$1.useEffect;
|
|
785
|
+
function useVirtualizerBase({ useFlushSync = true, ...options }) {
|
|
786
|
+
const rerender = React$1.useReducer(() => ({}), {})[1];
|
|
787
|
+
const resolvedOptions = {
|
|
788
|
+
...options,
|
|
789
|
+
onChange: (instance2, sync) => {
|
|
790
|
+
var _a;
|
|
791
|
+
if (useFlushSync && sync) flushSync(rerender);
|
|
792
|
+
else rerender();
|
|
793
|
+
(_a = options.onChange) == null || _a.call(options, instance2, sync);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
const [instance] = React$1.useState(() => new Virtualizer(resolvedOptions));
|
|
797
|
+
instance.setOptions(resolvedOptions);
|
|
798
|
+
useIsomorphicLayoutEffect(() => {
|
|
799
|
+
return instance._didMount();
|
|
800
|
+
}, []);
|
|
801
|
+
useIsomorphicLayoutEffect(() => {
|
|
802
|
+
return instance._willUpdate();
|
|
803
|
+
});
|
|
804
|
+
return instance;
|
|
805
|
+
}
|
|
806
|
+
function useVirtualizer(options) {
|
|
807
|
+
return useVirtualizerBase({
|
|
808
|
+
observeElementRect,
|
|
809
|
+
observeElementOffset,
|
|
810
|
+
scrollToFn: elementScroll,
|
|
811
|
+
...options
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
//#endregion
|
|
815
|
+
//#region editors/generic-drive-explorer/components/file-content-view.tsx
|
|
816
|
+
const GAP = 8;
|
|
817
|
+
const ITEM_WIDTH = 256;
|
|
818
|
+
const ITEM_HEIGHT = 48;
|
|
819
|
+
const USED_SPACE = 420;
|
|
820
|
+
function FileContentView() {
|
|
821
|
+
const parentRef = useRef(null);
|
|
822
|
+
const availableWidth = useWindowSize().innerWidth - USED_SPACE;
|
|
823
|
+
const fileNodes = useNodesInSelectedDriveOrFolder().filter((n) => isFileNodeKind(n));
|
|
824
|
+
const columnCount = Math.floor(availableWidth / 264) || 1;
|
|
825
|
+
const rowVirtualizer = useVirtualizer({
|
|
826
|
+
count: Math.ceil(fileNodes.length / columnCount),
|
|
827
|
+
getScrollElement: () => parentRef.current,
|
|
828
|
+
estimateSize: (index) => {
|
|
829
|
+
if (index > 0) return 56;
|
|
830
|
+
return ITEM_HEIGHT;
|
|
831
|
+
},
|
|
832
|
+
overscan: 5
|
|
833
|
+
});
|
|
834
|
+
const columnVirtualizer = useVirtualizer({
|
|
835
|
+
horizontal: true,
|
|
836
|
+
count: columnCount,
|
|
837
|
+
getScrollElement: () => parentRef.current,
|
|
838
|
+
estimateSize: (index) => {
|
|
839
|
+
if (index > 0) return 264;
|
|
840
|
+
return ITEM_WIDTH;
|
|
841
|
+
},
|
|
842
|
+
overscan: 5
|
|
843
|
+
});
|
|
844
|
+
const getItemIndex = (rowIndex, columnIndex) => rowIndex * columnCount + columnIndex;
|
|
845
|
+
const getItem = (rowIndex, columnIndex) => {
|
|
846
|
+
const index = getItemIndex(rowIndex, columnIndex);
|
|
847
|
+
return fileNodes[index] || null;
|
|
848
|
+
};
|
|
849
|
+
if (fileNodes.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
850
|
+
className: "mb-8 text-sm text-muted-foreground",
|
|
851
|
+
children: "No documents or files 📄"
|
|
852
|
+
});
|
|
853
|
+
const renderItem = (rowIndex, columnIndex) => {
|
|
854
|
+
const fileNode = getItem(rowIndex, columnIndex);
|
|
855
|
+
if (!fileNode) return null;
|
|
856
|
+
return /* @__PURE__ */ jsx("div", {
|
|
857
|
+
style: { marginLeft: columnIndex === 0 ? 0 : GAP },
|
|
858
|
+
children: /* @__PURE__ */ jsx(FileItem, { fileNode }, fileNode.id)
|
|
859
|
+
});
|
|
860
|
+
};
|
|
861
|
+
return /* @__PURE__ */ jsx("div", {
|
|
862
|
+
ref: parentRef,
|
|
863
|
+
style: {
|
|
864
|
+
width: `100%`,
|
|
865
|
+
overflow: "auto"
|
|
866
|
+
},
|
|
867
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
868
|
+
style: {
|
|
869
|
+
height: `${rowVirtualizer.getTotalSize()}px`,
|
|
870
|
+
width: `${columnVirtualizer.getTotalSize()}px`,
|
|
871
|
+
position: "relative"
|
|
872
|
+
},
|
|
873
|
+
children: rowVirtualizer.getVirtualItems().map((virtualRow) => /* @__PURE__ */ jsx(React.Fragment, { children: columnVirtualizer.getVirtualItems().map((virtualColumn) => /* @__PURE__ */ jsx("div", {
|
|
874
|
+
style: {
|
|
875
|
+
position: "absolute",
|
|
876
|
+
top: 0,
|
|
877
|
+
left: 0,
|
|
878
|
+
marginTop: virtualRow.index === 0 ? 0 : GAP,
|
|
879
|
+
width: `${virtualColumn.size}px`,
|
|
880
|
+
height: `${ITEM_HEIGHT}px`,
|
|
881
|
+
overflow: "hidden",
|
|
882
|
+
transform: `translateX(${virtualColumn.start}px) translateY(${virtualRow.start}px)`
|
|
883
|
+
},
|
|
884
|
+
children: renderItem(virtualRow.index, virtualColumn.index)
|
|
885
|
+
}, virtualColumn.key)) }, virtualRow.key))
|
|
886
|
+
})
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region editors/generic-drive-explorer/components/layout.tsx
|
|
891
|
+
function DriveLayout({ children, className, ...props }) {
|
|
892
|
+
return /* @__PURE__ */ jsx(DriveLayout.Container, {
|
|
893
|
+
className,
|
|
894
|
+
...props,
|
|
895
|
+
children
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
DriveLayout.Container = function DriveLayoutContainer({ children, className, containerProps, ...props }) {
|
|
899
|
+
return /* @__PURE__ */ jsx("div", {
|
|
900
|
+
className: twMerge("flex grow flex-col overflow-auto", className),
|
|
901
|
+
...containerProps,
|
|
902
|
+
...props,
|
|
903
|
+
children
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
DriveLayout.Header = function DriveLayoutHeader({ children, className, containerProps, ...props }) {
|
|
907
|
+
return /* @__PURE__ */ jsx("div", {
|
|
908
|
+
className: twMerge("flex-0", className),
|
|
909
|
+
...containerProps,
|
|
910
|
+
...props,
|
|
911
|
+
children
|
|
912
|
+
});
|
|
913
|
+
};
|
|
914
|
+
DriveLayout.Content = function DriveLayoutContent({ children, className, containerProps, ...props }) {
|
|
915
|
+
return /* @__PURE__ */ jsx("div", {
|
|
916
|
+
className: twMerge("mb-5 flex-1 px-4", className),
|
|
917
|
+
...containerProps,
|
|
918
|
+
...props,
|
|
919
|
+
children
|
|
920
|
+
});
|
|
921
|
+
};
|
|
922
|
+
DriveLayout.ContentSection = function DriveLayoutContentSection({ title, actions, children, className, containerProps, ...props }) {
|
|
923
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
924
|
+
className: twMerge(className),
|
|
925
|
+
...containerProps,
|
|
926
|
+
...props,
|
|
927
|
+
children: [(title || actions) && /* @__PURE__ */ jsxs("div", {
|
|
928
|
+
className: "mb-4 flex items-center justify-between gap-3",
|
|
929
|
+
children: [title && /* @__PURE__ */ jsx("div", {
|
|
930
|
+
className: "text-base font-semibold text-foreground",
|
|
931
|
+
children: title
|
|
932
|
+
}), actions]
|
|
933
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
934
|
+
className: "flex flex-wrap gap-2",
|
|
935
|
+
children
|
|
936
|
+
})]
|
|
937
|
+
});
|
|
938
|
+
};
|
|
939
|
+
//#endregion
|
|
940
|
+
//#region editors/generic-drive-explorer/components/folder-view.tsx
|
|
941
|
+
function FolderView(props) {
|
|
942
|
+
const { className } = props;
|
|
943
|
+
const folderNodes = useNodesInSelectedDriveOrFolder().filter((n) => isFolderNodeKind(n));
|
|
944
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
945
|
+
className: twMerge("rounded-md border-2 border-transparent p-2", className),
|
|
946
|
+
children: [/* @__PURE__ */ jsx(DriveLayout.ContentSection, {
|
|
947
|
+
title: "Folders",
|
|
948
|
+
className: "mb-4",
|
|
949
|
+
children: folderNodes.length > 0 ? folderNodes.map((folderNode) => /* @__PURE__ */ jsx(FolderItem, { folderNode }, folderNode.id)) : /* @__PURE__ */ jsx("div", {
|
|
950
|
+
className: "mb-8 text-sm text-muted-foreground",
|
|
951
|
+
children: "No documents or files 📄"
|
|
952
|
+
})
|
|
953
|
+
}), /* @__PURE__ */ jsx(DriveLayout.ContentSection, {
|
|
954
|
+
title: "Documents and files",
|
|
955
|
+
actions: /* @__PURE__ */ jsx(CreateDocument, {}),
|
|
956
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
957
|
+
className: "w-full",
|
|
958
|
+
children: /* @__PURE__ */ jsx(FileContentView, {})
|
|
959
|
+
})
|
|
960
|
+
})]
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
//#endregion
|
|
964
|
+
export { CreateDocument as i, DriveLayout as n, FileContentView as r, FolderView as t };
|
|
965
|
+
|
|
966
|
+
//# sourceMappingURL=folder-view-CkCNU8A_.mjs.map
|