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