@pixerate/editor-react 0.39.0 → 0.41.0
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/canvas/index.cjs +516 -312
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +142 -6
- package/dist/canvas/index.d.ts +142 -6
- package/dist/canvas/index.js +203 -0
- package/dist/canvas/index.js.map +1 -1
- package/dist/chart/index.cjs +60 -6
- package/dist/chart/index.cjs.map +1 -1
- package/dist/chart/index.js +1 -1
- package/dist/{chunk-IYHD5Q65.js → chunk-SIEOYRHX.js} +68 -7
- package/dist/chunk-SIEOYRHX.js.map +1 -0
- package/dist/index.cjs +499 -418
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +53 -27
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-IYHD5Q65.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -108,6 +108,7 @@ __export(src_exports, {
|
|
|
108
108
|
useSpreadsheetEditor: () => useSpreadsheetEditor,
|
|
109
109
|
useSpreadsheetViewport: () => useSpreadsheetViewport,
|
|
110
110
|
useTableMenu: () => useTableMenu,
|
|
111
|
+
useToolBridge: () => useToolBridge,
|
|
111
112
|
useTrackChanges: () => useTrackChanges,
|
|
112
113
|
withoutDirty: () => import_editor21.withoutDirty
|
|
113
114
|
});
|
|
@@ -723,19 +724,44 @@ function useAgentToolProvider(registry, provider) {
|
|
|
723
724
|
}, [registry, provider]);
|
|
724
725
|
}
|
|
725
726
|
|
|
727
|
+
// src/hooks/useToolBridge.ts
|
|
728
|
+
var import_react12 = require("react");
|
|
729
|
+
var import_tools = require("@pixerate/editor/tools");
|
|
730
|
+
function useToolBridge(registry, options) {
|
|
731
|
+
const [state, setState] = (0, import_react12.useState)({ status: "off", editorId: null });
|
|
732
|
+
const key = options ? JSON.stringify([options.url, options.token, options.name, options.kind, options.reconnect]) : null;
|
|
733
|
+
(0, import_react12.useEffect)(() => {
|
|
734
|
+
if (!registry || !options) {
|
|
735
|
+
setState({ status: "off", editorId: null });
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
let connection;
|
|
739
|
+
connection = (0, import_tools.connectToolBridge)(registry, {
|
|
740
|
+
...options,
|
|
741
|
+
onStatus: (status, detail) => {
|
|
742
|
+
setState({ status, detail, editorId: connection?.editorId ?? null });
|
|
743
|
+
options.onStatus?.(status, detail);
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
setState({ status: connection.status, editorId: null });
|
|
747
|
+
return () => connection?.close();
|
|
748
|
+
}, [registry, key]);
|
|
749
|
+
return state;
|
|
750
|
+
}
|
|
751
|
+
|
|
726
752
|
// src/components/EditorContent.tsx
|
|
727
|
-
var
|
|
753
|
+
var import_react13 = require("@tiptap/react");
|
|
728
754
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
729
755
|
var EditorContent = ({
|
|
730
756
|
className,
|
|
731
757
|
editor,
|
|
732
758
|
...props
|
|
733
759
|
}) => {
|
|
734
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
760
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react13.EditorContent, { editor, ...props }) });
|
|
735
761
|
};
|
|
736
762
|
|
|
737
763
|
// src/components/BubbleMenu.tsx
|
|
738
|
-
var
|
|
764
|
+
var import_react14 = require("react");
|
|
739
765
|
var import_react_dom = require("react-dom");
|
|
740
766
|
var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
|
|
741
767
|
var BubbleMenu = ({
|
|
@@ -747,12 +773,12 @@ var BubbleMenu = ({
|
|
|
747
773
|
pluginKey = "bubbleMenu",
|
|
748
774
|
updateDelay
|
|
749
775
|
}) => {
|
|
750
|
-
const menuEl = (0,
|
|
751
|
-
const [mounted, setMounted] = (0,
|
|
776
|
+
const menuEl = (0, import_react14.useRef)(null);
|
|
777
|
+
const [mounted, setMounted] = (0, import_react14.useState)(false);
|
|
752
778
|
if (!menuEl.current && typeof document !== "undefined") {
|
|
753
779
|
menuEl.current = document.createElement("div");
|
|
754
780
|
}
|
|
755
|
-
(0,
|
|
781
|
+
(0, import_react14.useEffect)(() => {
|
|
756
782
|
if (!editor || !menuEl.current || editor.isDestroyed) {
|
|
757
783
|
return;
|
|
758
784
|
}
|
|
@@ -783,7 +809,7 @@ var BubbleMenu = ({
|
|
|
783
809
|
};
|
|
784
810
|
|
|
785
811
|
// src/components/TemplateRenderer.tsx
|
|
786
|
-
var
|
|
812
|
+
var import_react15 = require("react");
|
|
787
813
|
var import_editor6 = require("@pixerate/editor");
|
|
788
814
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
789
815
|
var TemplateRenderer = ({
|
|
@@ -797,11 +823,11 @@ var TemplateRenderer = ({
|
|
|
797
823
|
onTemplateClick,
|
|
798
824
|
onVariableClick
|
|
799
825
|
}) => {
|
|
800
|
-
const displayText = (0,
|
|
826
|
+
const displayText = (0, import_react15.useMemo)(() => {
|
|
801
827
|
if (!resolve || templates.length === 0) return content;
|
|
802
828
|
return (0, import_editor6.resolveTemplates)(content, templates, { bindings });
|
|
803
829
|
}, [content, templates, resolve, bindings]);
|
|
804
|
-
const tokens = (0,
|
|
830
|
+
const tokens = (0, import_react15.useMemo)(() => {
|
|
805
831
|
return (0, import_editor6.evaluatePromptTokens)(displayText, values);
|
|
806
832
|
}, [displayText, values]);
|
|
807
833
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, children: tokens.map((token, index) => {
|
|
@@ -890,7 +916,7 @@ var TemplateRenderer = ({
|
|
|
890
916
|
};
|
|
891
917
|
|
|
892
918
|
// src/components/VariableForm.tsx
|
|
893
|
-
var
|
|
919
|
+
var import_react16 = require("react");
|
|
894
920
|
var import_editor7 = require("@pixerate/editor");
|
|
895
921
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
896
922
|
var VariableForm = ({
|
|
@@ -902,12 +928,12 @@ var VariableForm = ({
|
|
|
902
928
|
onChange,
|
|
903
929
|
className = "flex flex-col gap-3 text-sm"
|
|
904
930
|
}) => {
|
|
905
|
-
const idPrefix = (0,
|
|
906
|
-
const [internal, setInternal] = (0,
|
|
931
|
+
const idPrefix = (0, import_react16.useId)();
|
|
932
|
+
const [internal, setInternal] = (0, import_react16.useState)(
|
|
907
933
|
() => defaultValues ?? {}
|
|
908
934
|
);
|
|
909
935
|
const entered = values ?? internal;
|
|
910
|
-
const fields = (0,
|
|
936
|
+
const fields = (0, import_react16.useMemo)(
|
|
911
937
|
() => (0, import_editor7.getVariableFormFields)(content, { templates, bindings }),
|
|
912
938
|
[content, templates, bindings]
|
|
913
939
|
);
|
|
@@ -975,26 +1001,26 @@ var VariableForm = ({
|
|
|
975
1001
|
};
|
|
976
1002
|
|
|
977
1003
|
// src/components/MergePreview.tsx
|
|
978
|
-
var
|
|
1004
|
+
var import_react18 = require("react");
|
|
979
1005
|
|
|
980
1006
|
// src/hooks/useMergePreview.ts
|
|
981
|
-
var
|
|
1007
|
+
var import_react17 = require("react");
|
|
982
1008
|
var import_editor8 = require("@pixerate/editor");
|
|
983
1009
|
function useMergePreview(options) {
|
|
984
1010
|
const { template, templates, bindings, parseOptions } = options;
|
|
985
|
-
const [sourceText, setSourceTextState] = (0,
|
|
986
|
-
const [overrides, setOverrides] = (0,
|
|
987
|
-
const [index, setIndexState] = (0,
|
|
988
|
-
const [result, setResult] = (0,
|
|
989
|
-
const source = (0,
|
|
1011
|
+
const [sourceText, setSourceTextState] = (0, import_react17.useState)(options.initialSource ?? "");
|
|
1012
|
+
const [overrides, setOverrides] = (0, import_react17.useState)({});
|
|
1013
|
+
const [index, setIndexState] = (0, import_react17.useState)(0);
|
|
1014
|
+
const [result, setResult] = (0, import_react17.useState)(null);
|
|
1015
|
+
const source = (0, import_react17.useMemo)(
|
|
990
1016
|
() => (0, import_editor8.parseDataSource)(sourceText, parseOptions),
|
|
991
1017
|
[sourceText, parseOptions]
|
|
992
1018
|
);
|
|
993
|
-
const variables = (0,
|
|
1019
|
+
const variables = (0, import_react17.useMemo)(
|
|
994
1020
|
() => (0, import_editor8.extractVariables)(template, { templates, bindings }).map((v) => v.name),
|
|
995
1021
|
[template, templates, bindings]
|
|
996
1022
|
);
|
|
997
|
-
const mapping = (0,
|
|
1023
|
+
const mapping = (0, import_react17.useMemo)(() => {
|
|
998
1024
|
const merged = {
|
|
999
1025
|
...(0, import_editor8.matchFields)(variables, source.fields).mapping
|
|
1000
1026
|
};
|
|
@@ -1008,29 +1034,29 @@ function useMergePreview(options) {
|
|
|
1008
1034
|
const count = source.records.length;
|
|
1009
1035
|
const current = count === 0 ? 0 : Math.min(index, count - 1);
|
|
1010
1036
|
const record = source.records[current];
|
|
1011
|
-
const values = (0,
|
|
1037
|
+
const values = (0, import_react17.useMemo)(
|
|
1012
1038
|
() => record ? (0, import_editor8.recordToValues)(record, mapping) : {},
|
|
1013
1039
|
[record, mapping]
|
|
1014
1040
|
);
|
|
1015
|
-
const setSourceText = (0,
|
|
1041
|
+
const setSourceText = (0, import_react17.useCallback)((text) => {
|
|
1016
1042
|
setSourceTextState(text);
|
|
1017
1043
|
setIndexState(0);
|
|
1018
1044
|
setResult(null);
|
|
1019
1045
|
}, []);
|
|
1020
|
-
const loadFile = (0,
|
|
1046
|
+
const loadFile = (0, import_react17.useCallback)(
|
|
1021
1047
|
async (file) => setSourceText(await file.text()),
|
|
1022
1048
|
[setSourceText]
|
|
1023
1049
|
);
|
|
1024
|
-
const setIndex = (0,
|
|
1050
|
+
const setIndex = (0, import_react17.useCallback)(
|
|
1025
1051
|
(next) => setIndexState(Math.max(0, Math.min(next, count - 1))),
|
|
1026
1052
|
[count]
|
|
1027
1053
|
);
|
|
1028
|
-
const setFieldMapping = (0,
|
|
1054
|
+
const setFieldMapping = (0, import_react17.useCallback)((variable, field) => {
|
|
1029
1055
|
setOverrides((previous) => ({ ...previous, [variable]: field }));
|
|
1030
1056
|
setResult(null);
|
|
1031
1057
|
}, []);
|
|
1032
|
-
const resetMapping = (0,
|
|
1033
|
-
const merge = (0,
|
|
1058
|
+
const resetMapping = (0, import_react17.useCallback)(() => setOverrides({}), []);
|
|
1059
|
+
const merge = (0, import_react17.useCallback)(() => {
|
|
1034
1060
|
const merged = (0, import_editor8.mergeRecords)(template, source, {
|
|
1035
1061
|
templates,
|
|
1036
1062
|
bindings,
|
|
@@ -1042,7 +1068,7 @@ function useMergePreview(options) {
|
|
|
1042
1068
|
setResult(merged);
|
|
1043
1069
|
return merged;
|
|
1044
1070
|
}, [template, source, templates, bindings, mapping, options.skipIf, options.separator, options.maxOutputs]);
|
|
1045
|
-
const serialize = (0,
|
|
1071
|
+
const serialize = (0, import_react17.useCallback)(
|
|
1046
1072
|
(format) => result ? (0, import_editor8.serializeMergeOutputs)(result.outputs, format, options.separator) : "",
|
|
1047
1073
|
[result, options.separator]
|
|
1048
1074
|
);
|
|
@@ -1095,7 +1121,7 @@ var MergePreview = ({
|
|
|
1095
1121
|
downloadName = "merged",
|
|
1096
1122
|
className = "flex flex-col gap-3 text-sm"
|
|
1097
1123
|
}) => {
|
|
1098
|
-
const id = (0,
|
|
1124
|
+
const id = (0, import_react18.useId)();
|
|
1099
1125
|
const merge = useMergePreview({
|
|
1100
1126
|
template: content,
|
|
1101
1127
|
templates,
|
|
@@ -1106,7 +1132,7 @@ var MergePreview = ({
|
|
|
1106
1132
|
separator,
|
|
1107
1133
|
maxOutputs
|
|
1108
1134
|
});
|
|
1109
|
-
const [copied, setCopied] = (0,
|
|
1135
|
+
const [copied, setCopied] = (0, import_react18.useState)(false);
|
|
1110
1136
|
const { source, result } = merge;
|
|
1111
1137
|
const copy = async () => {
|
|
1112
1138
|
try {
|
|
@@ -1263,11 +1289,11 @@ var MergePreview = ({
|
|
|
1263
1289
|
};
|
|
1264
1290
|
|
|
1265
1291
|
// src/hooks/useOutline.ts
|
|
1266
|
-
var
|
|
1292
|
+
var import_react19 = require("react");
|
|
1267
1293
|
var import_editor9 = require("@pixerate/editor");
|
|
1268
1294
|
function useOutline(editor) {
|
|
1269
|
-
const store = (0,
|
|
1270
|
-
return (0,
|
|
1295
|
+
const store = (0, import_react19.useMemo)(() => (0, import_editor9.createOutlineStore)(editor), [editor]);
|
|
1296
|
+
return (0, import_react19.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
1271
1297
|
}
|
|
1272
1298
|
|
|
1273
1299
|
// src/components/OutlinePanel.tsx
|
|
@@ -1312,12 +1338,12 @@ var OutlinePanel = ({
|
|
|
1312
1338
|
};
|
|
1313
1339
|
|
|
1314
1340
|
// src/hooks/useParagraphStyles.ts
|
|
1315
|
-
var
|
|
1341
|
+
var import_react20 = require("react");
|
|
1316
1342
|
var import_editor11 = require("@pixerate/editor");
|
|
1317
1343
|
function useParagraphStyles(editor) {
|
|
1318
|
-
const store = (0,
|
|
1319
|
-
const snapshot = (0,
|
|
1320
|
-
return (0,
|
|
1344
|
+
const store = (0, import_react20.useMemo)(() => (0, import_editor11.createParagraphStylesStore)(editor), [editor]);
|
|
1345
|
+
const snapshot = (0, import_react20.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
1346
|
+
return (0, import_react20.useMemo)(() => {
|
|
1321
1347
|
const registry = (0, import_editor11.getStyleRegistry)(editor);
|
|
1322
1348
|
const live = () => editor && !editor.isDestroyed ? editor : null;
|
|
1323
1349
|
return {
|
|
@@ -1340,7 +1366,7 @@ function useParagraphStyles(editor) {
|
|
|
1340
1366
|
}
|
|
1341
1367
|
|
|
1342
1368
|
// src/components/StylesGallery.tsx
|
|
1343
|
-
var
|
|
1369
|
+
var import_react21 = require("react");
|
|
1344
1370
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1345
1371
|
var camel = (property) => property.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
1346
1372
|
var keepSelection = (event) => event.preventDefault();
|
|
@@ -1356,9 +1382,9 @@ var StylesGallery = ({
|
|
|
1356
1382
|
onChange
|
|
1357
1383
|
}) => {
|
|
1358
1384
|
const styles = useParagraphStyles(editor);
|
|
1359
|
-
const [open, setOpen] = (0,
|
|
1360
|
-
const [creating, setCreating] = (0,
|
|
1361
|
-
const [name, setName] = (0,
|
|
1385
|
+
const [open, setOpen] = (0, import_react21.useState)(false);
|
|
1386
|
+
const [creating, setCreating] = (0, import_react21.useState)(false);
|
|
1387
|
+
const [name, setName] = (0, import_react21.useState)("");
|
|
1362
1388
|
const list = showAllStyles ? styles.styles : styles.gallery;
|
|
1363
1389
|
const current = styles.currentStyle;
|
|
1364
1390
|
const expanded = variant === "gallery" || open;
|
|
@@ -1474,13 +1500,13 @@ var StylesGallery = ({
|
|
|
1474
1500
|
var import_editor21 = require("@pixerate/editor");
|
|
1475
1501
|
|
|
1476
1502
|
// src/spreadsheet/useSpreadsheetEditor.ts
|
|
1477
|
-
var
|
|
1503
|
+
var import_react22 = require("react");
|
|
1478
1504
|
var import_spreadsheet = require("@pixerate/editor/spreadsheet");
|
|
1479
1505
|
function useSpreadsheetEditor(options = {}) {
|
|
1480
|
-
const optionsRef = (0,
|
|
1506
|
+
const optionsRef = (0, import_react22.useRef)(options);
|
|
1481
1507
|
optionsRef.current = options;
|
|
1482
|
-
const settersRef = (0,
|
|
1483
|
-
const [controller] = (0,
|
|
1508
|
+
const settersRef = (0, import_react22.useRef)({});
|
|
1509
|
+
const [controller] = (0, import_react22.useState)(
|
|
1484
1510
|
() => new import_spreadsheet.SpreadsheetController({
|
|
1485
1511
|
...options,
|
|
1486
1512
|
onDocumentChange: (updated) => {
|
|
@@ -1497,37 +1523,37 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1497
1523
|
}
|
|
1498
1524
|
})
|
|
1499
1525
|
);
|
|
1500
|
-
const [doc, setDoc] = (0,
|
|
1501
|
-
const [activeCell, setActiveCell] = (0,
|
|
1502
|
-
const [selectedRange, setSelectedRange] = (0,
|
|
1503
|
-
const [editingCell, setEditingCell] = (0,
|
|
1504
|
-
const [draftValue, setDraftState] = (0,
|
|
1505
|
-
const [validationPrompt, setValidationPrompt] = (0,
|
|
1526
|
+
const [doc, setDoc] = (0, import_react22.useState)(() => ({ ...controller.document }));
|
|
1527
|
+
const [activeCell, setActiveCell] = (0, import_react22.useState)(controller.activeCell);
|
|
1528
|
+
const [selectedRange, setSelectedRange] = (0, import_react22.useState)(controller.selectedRange);
|
|
1529
|
+
const [editingCell, setEditingCell] = (0, import_react22.useState)(null);
|
|
1530
|
+
const [draftValue, setDraftState] = (0, import_react22.useState)("");
|
|
1531
|
+
const [validationPrompt, setValidationPrompt] = (0, import_react22.useState)(null);
|
|
1506
1532
|
settersRef.current = { setDoc, setActiveCell, setSelectedRange };
|
|
1507
|
-
const setDraftValue = (0,
|
|
1533
|
+
const setDraftValue = (0, import_react22.useCallback)((value) => {
|
|
1508
1534
|
controller.draftValue = value;
|
|
1509
1535
|
setDraftState(value);
|
|
1510
1536
|
}, [controller]);
|
|
1511
|
-
const setCellValue = (0,
|
|
1537
|
+
const setCellValue = (0, import_react22.useCallback)((rowId, colId, raw) => {
|
|
1512
1538
|
controller.setCellValue(rowId, colId, raw);
|
|
1513
1539
|
setDoc({ ...controller.document });
|
|
1514
1540
|
}, [controller]);
|
|
1515
|
-
const selectCell = (0,
|
|
1541
|
+
const selectCell = (0, import_react22.useCallback)((row, col, extendSelection = false) => {
|
|
1516
1542
|
controller.selectCell(row, col, extendSelection);
|
|
1517
1543
|
setActiveCell(controller.activeCell);
|
|
1518
1544
|
setSelectedRange(controller.selectedRange);
|
|
1519
1545
|
}, [controller]);
|
|
1520
|
-
const selectRange = (0,
|
|
1546
|
+
const selectRange = (0, import_react22.useCallback)((range) => {
|
|
1521
1547
|
controller.selectRange(range);
|
|
1522
1548
|
setSelectedRange(controller.selectedRange);
|
|
1523
1549
|
}, [controller]);
|
|
1524
|
-
const startEditing = (0,
|
|
1550
|
+
const startEditing = (0, import_react22.useCallback)((row, col, initialVal) => {
|
|
1525
1551
|
controller.startEditing(row, col, initialVal);
|
|
1526
1552
|
setActiveCell(controller.activeCell);
|
|
1527
1553
|
setEditingCell(controller.editingCell);
|
|
1528
1554
|
setDraftValue(controller.draftValue);
|
|
1529
1555
|
}, [controller]);
|
|
1530
|
-
const syncEditing = (0,
|
|
1556
|
+
const syncEditing = (0, import_react22.useCallback)(() => {
|
|
1531
1557
|
setEditingCell(controller.editingCell);
|
|
1532
1558
|
setDraftValue(controller.draftValue);
|
|
1533
1559
|
setValidationPrompt(controller.validationPrompt);
|
|
@@ -1535,90 +1561,90 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1535
1561
|
setSelectedRange(controller.selectedRange);
|
|
1536
1562
|
setDoc({ ...controller.document });
|
|
1537
1563
|
}, [controller]);
|
|
1538
|
-
const commitEditing = (0,
|
|
1564
|
+
const commitEditing = (0, import_react22.useCallback)((val) => {
|
|
1539
1565
|
const result = controller.commitEditing(val);
|
|
1540
1566
|
syncEditing();
|
|
1541
1567
|
return result;
|
|
1542
1568
|
}, [controller, syncEditing]);
|
|
1543
|
-
const commitCellInput = (0,
|
|
1569
|
+
const commitCellInput = (0, import_react22.useCallback)((rowId, colId, raw) => {
|
|
1544
1570
|
const result = controller.commitCellInput(rowId, colId, raw);
|
|
1545
1571
|
syncEditing();
|
|
1546
1572
|
return result;
|
|
1547
1573
|
}, [controller, syncEditing]);
|
|
1548
|
-
const resolveValidationPrompt = (0,
|
|
1574
|
+
const resolveValidationPrompt = (0, import_react22.useCallback)((action) => {
|
|
1549
1575
|
controller.resolveValidationPrompt(action);
|
|
1550
1576
|
syncEditing();
|
|
1551
1577
|
}, [controller, syncEditing]);
|
|
1552
|
-
const cancelEditing = (0,
|
|
1578
|
+
const cancelEditing = (0, import_react22.useCallback)(() => {
|
|
1553
1579
|
controller.cancelEditing();
|
|
1554
1580
|
setEditingCell(null);
|
|
1555
1581
|
setDraftValue("");
|
|
1556
1582
|
}, [controller]);
|
|
1557
|
-
const moveCursor = (0,
|
|
1583
|
+
const moveCursor = (0, import_react22.useCallback)((dir, extend = false) => {
|
|
1558
1584
|
controller.moveCursor(dir, extend);
|
|
1559
1585
|
setActiveCell(controller.activeCell);
|
|
1560
1586
|
setSelectedRange(controller.selectedRange);
|
|
1561
1587
|
}, [controller]);
|
|
1562
|
-
const insertColumn = (0,
|
|
1588
|
+
const insertColumn = (0, import_react22.useCallback)((index, config) => {
|
|
1563
1589
|
controller.insertColumn(index, config);
|
|
1564
1590
|
setDoc({ ...controller.document });
|
|
1565
1591
|
}, [controller]);
|
|
1566
|
-
const deleteColumn = (0,
|
|
1592
|
+
const deleteColumn = (0, import_react22.useCallback)((colId) => {
|
|
1567
1593
|
controller.deleteColumn(colId);
|
|
1568
1594
|
setDoc({ ...controller.document });
|
|
1569
1595
|
}, [controller]);
|
|
1570
|
-
const insertRow = (0,
|
|
1596
|
+
const insertRow = (0, import_react22.useCallback)((index, config) => {
|
|
1571
1597
|
controller.insertRow(index, config);
|
|
1572
1598
|
setDoc({ ...controller.document });
|
|
1573
1599
|
}, [controller]);
|
|
1574
|
-
const deleteRow = (0,
|
|
1600
|
+
const deleteRow = (0, import_react22.useCallback)((rowId) => {
|
|
1575
1601
|
controller.deleteRow(rowId);
|
|
1576
1602
|
setDoc({ ...controller.document });
|
|
1577
1603
|
}, [controller]);
|
|
1578
|
-
const setColumnWidth = (0,
|
|
1604
|
+
const setColumnWidth = (0, import_react22.useCallback)((colId, width) => {
|
|
1579
1605
|
controller.setColumnWidth(colId, width);
|
|
1580
1606
|
setDoc({ ...controller.document });
|
|
1581
1607
|
}, [controller]);
|
|
1582
|
-
const autoFitColumnWidth = (0,
|
|
1608
|
+
const autoFitColumnWidth = (0, import_react22.useCallback)((colId, customWidth) => {
|
|
1583
1609
|
controller.autoFitColumnWidth(colId, customWidth);
|
|
1584
1610
|
setDoc({ ...controller.document });
|
|
1585
1611
|
}, [controller]);
|
|
1586
|
-
const registerDataSource = (0,
|
|
1612
|
+
const registerDataSource = (0, import_react22.useCallback)((ds) => {
|
|
1587
1613
|
controller.registerDataSource(ds);
|
|
1588
1614
|
setDoc({ ...controller.document });
|
|
1589
1615
|
}, [controller]);
|
|
1590
|
-
const setPrimaryDataSource = (0,
|
|
1616
|
+
const setPrimaryDataSource = (0, import_react22.useCallback)((id) => {
|
|
1591
1617
|
controller.setPrimaryDataSource(id);
|
|
1592
1618
|
setDoc({ ...controller.document });
|
|
1593
1619
|
}, [controller]);
|
|
1594
|
-
const recalculateAll = (0,
|
|
1620
|
+
const recalculateAll = (0, import_react22.useCallback)(() => {
|
|
1595
1621
|
controller.recalculateAll();
|
|
1596
1622
|
setDoc({ ...controller.document });
|
|
1597
1623
|
}, [controller]);
|
|
1598
|
-
const undo = (0,
|
|
1624
|
+
const undo = (0, import_react22.useCallback)(() => {
|
|
1599
1625
|
controller.undo();
|
|
1600
1626
|
setDoc({ ...controller.document });
|
|
1601
1627
|
setActiveCell(controller.activeCell);
|
|
1602
1628
|
setSelectedRange(controller.selectedRange);
|
|
1603
1629
|
}, [controller]);
|
|
1604
|
-
const redo = (0,
|
|
1630
|
+
const redo = (0, import_react22.useCallback)(() => {
|
|
1605
1631
|
controller.redo();
|
|
1606
1632
|
setDoc({ ...controller.document });
|
|
1607
1633
|
setActiveCell(controller.activeCell);
|
|
1608
1634
|
setSelectedRange(controller.selectedRange);
|
|
1609
1635
|
}, [controller]);
|
|
1610
|
-
const tableActions = (0,
|
|
1611
|
-
const viewModel = (0,
|
|
1612
|
-
const sheets = (0,
|
|
1613
|
-
const names = (0,
|
|
1614
|
-
const afterSheetSwitch = (0,
|
|
1636
|
+
const tableActions = (0, import_react22.useMemo)(() => (0, import_spreadsheet.bindSpreadsheetTableActions)(controller), [controller]);
|
|
1637
|
+
const viewModel = (0, import_react22.useMemo)(() => controller.getViewModel(), [controller, doc]);
|
|
1638
|
+
const sheets = (0, import_react22.useMemo)(() => controller.getSheets(), [controller, doc]);
|
|
1639
|
+
const names = (0, import_react22.useMemo)(() => controller.getNames(), [controller, doc]);
|
|
1640
|
+
const afterSheetSwitch = (0, import_react22.useCallback)(() => {
|
|
1615
1641
|
setEditingCell(controller.editingCell);
|
|
1616
1642
|
setDraftValue(controller.draftValue);
|
|
1617
1643
|
setActiveCell(controller.activeCell);
|
|
1618
1644
|
setSelectedRange(controller.selectedRange);
|
|
1619
1645
|
setDoc({ ...controller.document });
|
|
1620
1646
|
}, [controller, setDraftValue]);
|
|
1621
|
-
const workbookActions = (0,
|
|
1647
|
+
const workbookActions = (0, import_react22.useMemo)(
|
|
1622
1648
|
() => ({
|
|
1623
1649
|
setActiveSheet: (idOrName) => {
|
|
1624
1650
|
const changed = controller.setActiveSheet(idOrName);
|
|
@@ -1648,7 +1674,7 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1648
1674
|
}),
|
|
1649
1675
|
[controller, afterSheetSwitch]
|
|
1650
1676
|
);
|
|
1651
|
-
const conditionalFormatOverlay = (0,
|
|
1677
|
+
const conditionalFormatOverlay = (0, import_react22.useMemo)(() => controller.getConditionalFormatOverlay(), [controller, doc]);
|
|
1652
1678
|
return {
|
|
1653
1679
|
document: doc,
|
|
1654
1680
|
activeCell,
|
|
@@ -1710,20 +1736,20 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1710
1736
|
}
|
|
1711
1737
|
|
|
1712
1738
|
// src/spreadsheet/SpreadsheetEditor.tsx
|
|
1713
|
-
var
|
|
1739
|
+
var import_react31 = require("react");
|
|
1714
1740
|
var import_spreadsheet8 = require("@pixerate/editor/spreadsheet");
|
|
1715
1741
|
|
|
1716
1742
|
// src/spreadsheet/SpreadsheetContextMenu.tsx
|
|
1717
|
-
var
|
|
1743
|
+
var import_react23 = __toESM(require("react"), 1);
|
|
1718
1744
|
var import_spreadsheet2 = require("@pixerate/editor/spreadsheet");
|
|
1719
1745
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1720
1746
|
var VIEWPORT_MARGIN = 4;
|
|
1721
1747
|
var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "Table actions" }) => {
|
|
1722
|
-
const menuRef = (0,
|
|
1723
|
-
const onCloseRef = (0,
|
|
1748
|
+
const menuRef = (0, import_react23.useRef)(null);
|
|
1749
|
+
const onCloseRef = (0, import_react23.useRef)(onClose);
|
|
1724
1750
|
onCloseRef.current = onClose;
|
|
1725
|
-
const [position, setPosition] = (0,
|
|
1726
|
-
(0,
|
|
1751
|
+
const [position, setPosition] = (0, import_react23.useState)({ x, y });
|
|
1752
|
+
(0, import_react23.useLayoutEffect)(() => {
|
|
1727
1753
|
const menu = menuRef.current;
|
|
1728
1754
|
if (!menu || typeof window === "undefined") return;
|
|
1729
1755
|
const { width, height } = menu.getBoundingClientRect();
|
|
@@ -1735,7 +1761,7 @@ var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "
|
|
|
1735
1761
|
);
|
|
1736
1762
|
setPosition((prev) => prev.x === next.x && prev.y === next.y ? prev : next);
|
|
1737
1763
|
}, [x, y, items]);
|
|
1738
|
-
(0,
|
|
1764
|
+
(0, import_react23.useEffect)(() => {
|
|
1739
1765
|
const handlePointer = (e) => {
|
|
1740
1766
|
if (!menuRef.current?.contains(e.target)) onCloseRef.current();
|
|
1741
1767
|
};
|
|
@@ -1765,7 +1791,7 @@ var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "
|
|
|
1765
1791
|
},
|
|
1766
1792
|
onContextMenu: (e) => e.preventDefault(),
|
|
1767
1793
|
onKeyDown: (e) => e.stopPropagation(),
|
|
1768
|
-
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1794
|
+
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react23.default.Fragment, { children: [
|
|
1769
1795
|
item.separatorBefore && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { role: "separator", className: "my-1 h-px bg-border" }),
|
|
1770
1796
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1771
1797
|
"button",
|
|
@@ -1790,7 +1816,7 @@ var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "
|
|
|
1790
1816
|
};
|
|
1791
1817
|
|
|
1792
1818
|
// src/spreadsheet/SpreadsheetGroupRow.tsx
|
|
1793
|
-
var
|
|
1819
|
+
var import_react24 = __toESM(require("react"), 1);
|
|
1794
1820
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1795
1821
|
var formatSummary = (value) => value === null ? "\u2013" : String(value);
|
|
1796
1822
|
var SpreadsheetGroupRow = ({
|
|
@@ -1824,7 +1850,7 @@ var SpreadsheetGroupRow = ({
|
|
|
1824
1850
|
columns.map(({ column }, i) => {
|
|
1825
1851
|
const summary = group.summaries[column.id];
|
|
1826
1852
|
const before = leadingColumns !== void 0 && i === leadingColumns && leftSpace > 0 ? spacer("space:left") : null;
|
|
1827
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1853
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react24.default.Fragment, { children: [
|
|
1828
1854
|
before,
|
|
1829
1855
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { className: "border-r border-border px-2 py-1 truncate max-w-0 text-foreground", style: { maxWidth: 0, overflow: "hidden" }, children: column.id === labelColId ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "truncate", children: [
|
|
1830
1856
|
group.label,
|
|
@@ -1844,7 +1870,7 @@ var SpreadsheetGroupRow = ({
|
|
|
1844
1870
|
};
|
|
1845
1871
|
|
|
1846
1872
|
// src/spreadsheet/useSpreadsheetTableInteractions.ts
|
|
1847
|
-
var
|
|
1873
|
+
var import_react25 = require("react");
|
|
1848
1874
|
var import_spreadsheet3 = require("@pixerate/editor/spreadsheet");
|
|
1849
1875
|
function gridHasFocus(grid) {
|
|
1850
1876
|
if (!grid || typeof document === "undefined") return false;
|
|
@@ -1853,12 +1879,12 @@ function gridHasFocus(grid) {
|
|
|
1853
1879
|
return !(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement);
|
|
1854
1880
|
}
|
|
1855
1881
|
function useSpreadsheetClipboard(gridRef, state, readOnly) {
|
|
1856
|
-
const stateRef = (0,
|
|
1882
|
+
const stateRef = (0, import_react25.useRef)(state);
|
|
1857
1883
|
stateRef.current = state;
|
|
1858
|
-
const readOnlyRef = (0,
|
|
1884
|
+
const readOnlyRef = (0, import_react25.useRef)(readOnly);
|
|
1859
1885
|
readOnlyRef.current = readOnly;
|
|
1860
|
-
const copiedRef = (0,
|
|
1861
|
-
(0,
|
|
1886
|
+
const copiedRef = (0, import_react25.useRef)(false);
|
|
1887
|
+
(0, import_react25.useEffect)(() => {
|
|
1862
1888
|
if (typeof document === "undefined") return;
|
|
1863
1889
|
const handleCopy = (e) => {
|
|
1864
1890
|
const s = stateRef.current;
|
|
@@ -1881,7 +1907,7 @@ function useSpreadsheetClipboard(gridRef, state, readOnly) {
|
|
|
1881
1907
|
document.removeEventListener("paste", handlePaste);
|
|
1882
1908
|
};
|
|
1883
1909
|
}, [gridRef]);
|
|
1884
|
-
const copyShortcutFallback = (0,
|
|
1910
|
+
const copyShortcutFallback = (0, import_react25.useCallback)(() => {
|
|
1885
1911
|
copiedRef.current = false;
|
|
1886
1912
|
setTimeout(() => {
|
|
1887
1913
|
if (copiedRef.current) return;
|
|
@@ -1893,13 +1919,13 @@ function useSpreadsheetClipboard(gridRef, state, readOnly) {
|
|
|
1893
1919
|
return { copyShortcutFallback };
|
|
1894
1920
|
}
|
|
1895
1921
|
function useFillHandle(state) {
|
|
1896
|
-
const [drag, setDrag] = (0,
|
|
1897
|
-
const dragRef = (0,
|
|
1922
|
+
const [drag, setDrag] = (0, import_react25.useState)(null);
|
|
1923
|
+
const dragRef = (0, import_react25.useRef)(drag);
|
|
1898
1924
|
dragRef.current = drag;
|
|
1899
|
-
const stateRef = (0,
|
|
1925
|
+
const stateRef = (0, import_react25.useRef)(state);
|
|
1900
1926
|
stateRef.current = state;
|
|
1901
1927
|
const dragging = drag !== null;
|
|
1902
|
-
(0,
|
|
1928
|
+
(0, import_react25.useEffect)(() => {
|
|
1903
1929
|
if (!dragging) return;
|
|
1904
1930
|
const handleMouseUp = () => {
|
|
1905
1931
|
const current = dragRef.current;
|
|
@@ -1909,13 +1935,13 @@ function useFillHandle(state) {
|
|
|
1909
1935
|
window.addEventListener("mouseup", handleMouseUp);
|
|
1910
1936
|
return () => window.removeEventListener("mouseup", handleMouseUp);
|
|
1911
1937
|
}, [dragging]);
|
|
1912
|
-
const startFill = (0,
|
|
1938
|
+
const startFill = (0, import_react25.useCallback)((e) => {
|
|
1913
1939
|
e.preventDefault();
|
|
1914
1940
|
e.stopPropagation();
|
|
1915
1941
|
const range = stateRef.current.selectedRange;
|
|
1916
1942
|
if (range) setDrag({ source: (0, import_spreadsheet3.normalizeRange)(range), target: null });
|
|
1917
1943
|
}, []);
|
|
1918
|
-
const extendFill = (0,
|
|
1944
|
+
const extendFill = (0, import_react25.useCallback)((row, col) => {
|
|
1919
1945
|
const current = dragRef.current;
|
|
1920
1946
|
if (!current) return;
|
|
1921
1947
|
setDrag({ source: current.source, target: (0, import_spreadsheet3.computeFillTarget)(current.source, { row, col }) });
|
|
@@ -1924,12 +1950,12 @@ function useFillHandle(state) {
|
|
|
1924
1950
|
}
|
|
1925
1951
|
|
|
1926
1952
|
// src/spreadsheet/SpreadsheetValidationDialog.tsx
|
|
1927
|
-
var
|
|
1953
|
+
var import_react26 = require("react");
|
|
1928
1954
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1929
1955
|
var SpreadsheetValidationDialog = ({ prompt, onResolve }) => {
|
|
1930
1956
|
const style = prompt.result.errorStyle ?? "stop";
|
|
1931
|
-
const firstButton = (0,
|
|
1932
|
-
(0,
|
|
1957
|
+
const firstButton = (0, import_react26.useRef)(null);
|
|
1958
|
+
(0, import_react26.useEffect)(() => {
|
|
1933
1959
|
firstButton.current?.focus();
|
|
1934
1960
|
}, [prompt]);
|
|
1935
1961
|
const buttons = style === "stop" ? [
|
|
@@ -1995,7 +2021,7 @@ var SpreadsheetValidationDialog = ({ prompt, onResolve }) => {
|
|
|
1995
2021
|
};
|
|
1996
2022
|
|
|
1997
2023
|
// src/spreadsheet/SpreadsheetRulePanels.tsx
|
|
1998
|
-
var
|
|
2024
|
+
var import_react27 = require("react");
|
|
1999
2025
|
var import_spreadsheet4 = require("@pixerate/editor/spreadsheet");
|
|
2000
2026
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2001
2027
|
var inputClass = "w-full rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground";
|
|
@@ -2049,18 +2075,18 @@ function RuleSwatch({ rule }) {
|
|
|
2049
2075
|
}
|
|
2050
2076
|
var SpreadsheetConditionalFormatPanel = ({ state, onClose }) => {
|
|
2051
2077
|
const rules = state.document.table?.conditionalFormats ?? [];
|
|
2052
|
-
const [kind, setKind] = (0,
|
|
2053
|
-
const [appliesTo, setAppliesTo] = (0,
|
|
2054
|
-
const [value, setValue] = (0,
|
|
2055
|
-
const [value2, setValue2] = (0,
|
|
2056
|
-
const [text, setText] = (0,
|
|
2057
|
-
const [formula, setFormula] = (0,
|
|
2058
|
-
const [rank, setRank] = (0,
|
|
2059
|
-
const [period, setPeriod] = (0,
|
|
2060
|
-
const [iconSet, setIconSet] = (0,
|
|
2061
|
-
const [color, setColor] = (0,
|
|
2062
|
-
const [styleId, setStyleId] = (0,
|
|
2063
|
-
const preset = (0,
|
|
2078
|
+
const [kind, setKind] = (0, import_react27.useState)("greaterThan");
|
|
2079
|
+
const [appliesTo, setAppliesTo] = (0, import_react27.useState)(() => selectionText(state.selectedRange));
|
|
2080
|
+
const [value, setValue] = (0, import_react27.useState)("");
|
|
2081
|
+
const [value2, setValue2] = (0, import_react27.useState)("");
|
|
2082
|
+
const [text, setText] = (0, import_react27.useState)("");
|
|
2083
|
+
const [formula, setFormula] = (0, import_react27.useState)("=");
|
|
2084
|
+
const [rank, setRank] = (0, import_react27.useState)("10");
|
|
2085
|
+
const [period, setPeriod] = (0, import_react27.useState)("today");
|
|
2086
|
+
const [iconSet, setIconSet] = (0, import_react27.useState)("3TrafficLights1");
|
|
2087
|
+
const [color, setColor] = (0, import_react27.useState)("#638ec6");
|
|
2088
|
+
const [styleId, setStyleId] = (0, import_react27.useState)(import_spreadsheet4.CONDITIONAL_FORMAT_STYLE_PRESETS[0].id);
|
|
2089
|
+
const preset = (0, import_react27.useMemo)(() => import_spreadsheet4.CONDITIONAL_FORMAT_PRESETS.find((p) => p.kind === kind), [kind]);
|
|
2064
2090
|
const ranges = (0, import_spreadsheet4.parseRuleRanges)(appliesTo);
|
|
2065
2091
|
const add = () => {
|
|
2066
2092
|
if (!ranges) return;
|
|
@@ -2144,15 +2170,15 @@ var SpreadsheetConditionalFormatPanel = ({ state, onClose }) => {
|
|
|
2144
2170
|
};
|
|
2145
2171
|
var SpreadsheetDataValidationPanel = ({ state, onClose }) => {
|
|
2146
2172
|
const rules = state.document.table?.dataValidations ?? [];
|
|
2147
|
-
const [type, setType] = (0,
|
|
2148
|
-
const [operator, setOperator] = (0,
|
|
2149
|
-
const [formula1, setFormula1] = (0,
|
|
2150
|
-
const [formula2, setFormula2] = (0,
|
|
2151
|
-
const [errorStyle, setErrorStyle] = (0,
|
|
2152
|
-
const [errorMessage, setErrorMessage] = (0,
|
|
2153
|
-
const [inputMessage, setInputMessage] = (0,
|
|
2154
|
-
const [ignoreBlank, setIgnoreBlank] = (0,
|
|
2155
|
-
const [appliesTo, setAppliesTo] = (0,
|
|
2173
|
+
const [type, setType] = (0, import_react27.useState)("list");
|
|
2174
|
+
const [operator, setOperator] = (0, import_react27.useState)("between");
|
|
2175
|
+
const [formula1, setFormula1] = (0, import_react27.useState)("");
|
|
2176
|
+
const [formula2, setFormula2] = (0, import_react27.useState)("");
|
|
2177
|
+
const [errorStyle, setErrorStyle] = (0, import_react27.useState)("stop");
|
|
2178
|
+
const [errorMessage, setErrorMessage] = (0, import_react27.useState)("");
|
|
2179
|
+
const [inputMessage, setInputMessage] = (0, import_react27.useState)("");
|
|
2180
|
+
const [ignoreBlank, setIgnoreBlank] = (0, import_react27.useState)(true);
|
|
2181
|
+
const [appliesTo, setAppliesTo] = (0, import_react27.useState)(() => selectionText(state.selectedRange));
|
|
2156
2182
|
const ranges = (0, import_spreadsheet4.parseRuleRanges)(appliesTo);
|
|
2157
2183
|
const usesOperator = type === "whole" || type === "decimal" || type === "date" || type === "time" || type === "textLength";
|
|
2158
2184
|
const needsTwo = usesOperator && (operator === "between" || operator === "notBetween");
|
|
@@ -2226,29 +2252,29 @@ var SpreadsheetDataValidationPanel = ({ state, onClose }) => {
|
|
|
2226
2252
|
};
|
|
2227
2253
|
|
|
2228
2254
|
// src/spreadsheet/useSpreadsheetViewport.ts
|
|
2229
|
-
var
|
|
2255
|
+
var import_react28 = require("react");
|
|
2230
2256
|
var import_spreadsheet5 = require("@pixerate/editor/spreadsheet");
|
|
2231
|
-
var useIsomorphicLayoutEffect = typeof window !== "undefined" ?
|
|
2257
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_react28.useLayoutEffect : import_react28.useEffect;
|
|
2232
2258
|
function useSpreadsheetViewport(scrollRef, view, options = {}) {
|
|
2233
|
-
const metrics = (0,
|
|
2259
|
+
const metrics = (0, import_react28.useMemo)(() => (0, import_spreadsheet5.measureSpreadsheetView)(view), [view]);
|
|
2234
2260
|
const virtual = (0, import_spreadsheet5.shouldVirtualizeSpreadsheet)(view, options.virtualize ?? "auto");
|
|
2235
|
-
const [viewport, setViewport] = (0,
|
|
2236
|
-
const windowOptions = (0,
|
|
2261
|
+
const [viewport, setViewport] = (0, import_react28.useState)({ scrollTop: 0, scrollLeft: 0, width: 0, height: 0 });
|
|
2262
|
+
const windowOptions = (0, import_react28.useMemo)(
|
|
2237
2263
|
() => ({ merges: options.merges, overscanRows: options.overscanRows, overscanColumns: options.overscanColumns }),
|
|
2238
2264
|
[options.merges, options.overscanRows, options.overscanColumns]
|
|
2239
2265
|
);
|
|
2240
|
-
const win = (0,
|
|
2266
|
+
const win = (0, import_react28.useMemo)(
|
|
2241
2267
|
() => virtual ? (0, import_spreadsheet5.getSpreadsheetViewWindow)(metrics, viewport, windowOptions) : (0, import_spreadsheet5.fullSpreadsheetViewWindow)(metrics),
|
|
2242
2268
|
[virtual, metrics, viewport, windowOptions]
|
|
2243
2269
|
);
|
|
2244
|
-
const latest = (0,
|
|
2270
|
+
const latest = (0, import_react28.useRef)({ metrics, viewport, virtual, windowOptions });
|
|
2245
2271
|
latest.current = { metrics, viewport, virtual, windowOptions };
|
|
2246
|
-
const readViewport = (0,
|
|
2272
|
+
const readViewport = (0, import_react28.useCallback)(() => {
|
|
2247
2273
|
const el = scrollRef.current;
|
|
2248
2274
|
if (!el) return null;
|
|
2249
2275
|
return { scrollTop: el.scrollTop, scrollLeft: el.scrollLeft, width: el.clientWidth, height: el.clientHeight };
|
|
2250
2276
|
}, [scrollRef]);
|
|
2251
|
-
const updateViewport = (0,
|
|
2277
|
+
const updateViewport = (0, import_react28.useCallback)((next) => {
|
|
2252
2278
|
setViewport((prev) => {
|
|
2253
2279
|
const { metrics: m, virtual: v, windowOptions: o } = latest.current;
|
|
2254
2280
|
if (!v) return prev;
|
|
@@ -2256,7 +2282,7 @@ function useSpreadsheetViewport(scrollRef, view, options = {}) {
|
|
|
2256
2282
|
return same ? prev : next;
|
|
2257
2283
|
});
|
|
2258
2284
|
}, []);
|
|
2259
|
-
const onScroll = (0,
|
|
2285
|
+
const onScroll = (0, import_react28.useCallback)(() => {
|
|
2260
2286
|
const next = readViewport();
|
|
2261
2287
|
if (next) updateViewport(next);
|
|
2262
2288
|
}, [readViewport, updateViewport]);
|
|
@@ -2290,24 +2316,24 @@ function useSpreadsheetViewport(scrollRef, view, options = {}) {
|
|
|
2290
2316
|
}
|
|
2291
2317
|
|
|
2292
2318
|
// src/spreadsheet/FormulaHints.tsx
|
|
2293
|
-
var
|
|
2319
|
+
var import_react29 = require("react");
|
|
2294
2320
|
var import_spreadsheet6 = require("@pixerate/editor/spreadsheet");
|
|
2295
2321
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2296
2322
|
var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
2297
|
-
const [caret, setCaret] = (0,
|
|
2298
|
-
const [focused, setFocused] = (0,
|
|
2299
|
-
const [selected, setSelected] = (0,
|
|
2300
|
-
const [dismissed, setDismissed] = (0,
|
|
2301
|
-
const [position, setPosition] = (0,
|
|
2302
|
-
const pendingCaret = (0,
|
|
2303
|
-
const hints = (0,
|
|
2323
|
+
const [caret, setCaret] = (0, import_react29.useState)(null);
|
|
2324
|
+
const [focused, setFocused] = (0, import_react29.useState)(false);
|
|
2325
|
+
const [selected, setSelected] = (0, import_react29.useState)(0);
|
|
2326
|
+
const [dismissed, setDismissed] = (0, import_react29.useState)(false);
|
|
2327
|
+
const [position, setPosition] = (0, import_react29.useState)(null);
|
|
2328
|
+
const pendingCaret = (0, import_react29.useRef)(null);
|
|
2329
|
+
const hints = (0, import_react29.useMemo)(
|
|
2304
2330
|
() => (0, import_spreadsheet6.getFormulaHints)(value, caret ?? value.length, { limit, names }),
|
|
2305
2331
|
[value, caret, limit, names]
|
|
2306
2332
|
);
|
|
2307
2333
|
const suggestions = dismissed ? [] : hints.suggestions;
|
|
2308
2334
|
const selectedIndex = Math.max(0, Math.min(selected, suggestions.length - 1));
|
|
2309
2335
|
const visible = focused && value.trimStart().startsWith("=") && (suggestions.length > 0 || !!hints.activeCall);
|
|
2310
|
-
const latest = (0,
|
|
2336
|
+
const latest = (0, import_react29.useRef)({ suggestions, selected: selectedIndex, value, caret, onAccept });
|
|
2311
2337
|
latest.current = { suggestions, selected: selectedIndex, value, caret, onAccept };
|
|
2312
2338
|
const accept = (index) => {
|
|
2313
2339
|
const { suggestions: list, value: current, caret: at, onAccept: commit } = latest.current;
|
|
@@ -2317,7 +2343,7 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2317
2343
|
pendingCaret.current = next.caret;
|
|
2318
2344
|
commit(next.value);
|
|
2319
2345
|
};
|
|
2320
|
-
(0,
|
|
2346
|
+
(0, import_react29.useEffect)(() => {
|
|
2321
2347
|
const input = inputRef.current;
|
|
2322
2348
|
if (!input) return;
|
|
2323
2349
|
const syncCaret = () => setCaret(input.selectionStart ?? input.value.length);
|
|
@@ -2367,7 +2393,7 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2367
2393
|
input.removeEventListener("keydown", onKeyDown);
|
|
2368
2394
|
};
|
|
2369
2395
|
}, [inputRef]);
|
|
2370
|
-
(0,
|
|
2396
|
+
(0, import_react29.useLayoutEffect)(() => {
|
|
2371
2397
|
const input = inputRef.current;
|
|
2372
2398
|
const at = pendingCaret.current;
|
|
2373
2399
|
if (!input || at === null || input.value !== value) return;
|
|
@@ -2376,7 +2402,7 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2376
2402
|
setCaret(at);
|
|
2377
2403
|
setSelected(0);
|
|
2378
2404
|
}, [value, inputRef]);
|
|
2379
|
-
(0,
|
|
2405
|
+
(0, import_react29.useLayoutEffect)(() => {
|
|
2380
2406
|
const input = inputRef.current;
|
|
2381
2407
|
if (!visible || !input) return;
|
|
2382
2408
|
const rect = input.getBoundingClientRect();
|
|
@@ -2440,16 +2466,16 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2440
2466
|
};
|
|
2441
2467
|
|
|
2442
2468
|
// src/spreadsheet/SheetTabs.tsx
|
|
2443
|
-
var
|
|
2469
|
+
var import_react30 = require("react");
|
|
2444
2470
|
var import_spreadsheet7 = require("@pixerate/editor/spreadsheet");
|
|
2445
2471
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2446
2472
|
var SheetTabs = ({ state, readOnly = false, className = "" }) => {
|
|
2447
2473
|
const { controller, sheets } = state;
|
|
2448
|
-
const [renaming, setRenaming] = (0,
|
|
2449
|
-
const [error, setError] = (0,
|
|
2450
|
-
const [menu, setMenu] = (0,
|
|
2451
|
-
const dragFrom = (0,
|
|
2452
|
-
const [dropTarget, setDropTarget] = (0,
|
|
2474
|
+
const [renaming, setRenaming] = (0, import_react30.useState)(null);
|
|
2475
|
+
const [error, setError] = (0, import_react30.useState)(null);
|
|
2476
|
+
const [menu, setMenu] = (0, import_react30.useState)(null);
|
|
2477
|
+
const dragFrom = (0, import_react30.useRef)(null);
|
|
2478
|
+
const [dropTarget, setDropTarget] = (0, import_react30.useState)(null);
|
|
2453
2479
|
const commitRename = (cancelOnError) => {
|
|
2454
2480
|
if (!renaming) return;
|
|
2455
2481
|
const sheet = sheets.find((s) => s.id === renaming.id);
|
|
@@ -2651,21 +2677,21 @@ var SpreadsheetEditor = ({
|
|
|
2651
2677
|
}) => {
|
|
2652
2678
|
const defaultState = useSpreadsheetEditor();
|
|
2653
2679
|
const state = externalState || defaultState;
|
|
2654
|
-
const gridRef = (0,
|
|
2655
|
-
const scrollRef = (0,
|
|
2656
|
-
const formulaBarRef = (0,
|
|
2657
|
-
const cellInputRef = (0,
|
|
2658
|
-
const [resizingColId, setResizingColId] = (0,
|
|
2659
|
-
const [hoveredColId, setHoveredColId] = (0,
|
|
2660
|
-
const [resizeStartX, setResizeStartX] = (0,
|
|
2661
|
-
const [resizeStartWidth, setResizeStartWidth] = (0,
|
|
2680
|
+
const gridRef = (0, import_react31.useRef)(null);
|
|
2681
|
+
const scrollRef = (0, import_react31.useRef)(null);
|
|
2682
|
+
const formulaBarRef = (0, import_react31.useRef)(null);
|
|
2683
|
+
const cellInputRef = (0, import_react31.useRef)(null);
|
|
2684
|
+
const [resizingColId, setResizingColId] = (0, import_react31.useState)(null);
|
|
2685
|
+
const [hoveredColId, setHoveredColId] = (0, import_react31.useState)(null);
|
|
2686
|
+
const [resizeStartX, setResizeStartX] = (0, import_react31.useState)(0);
|
|
2687
|
+
const [resizeStartWidth, setResizeStartWidth] = (0, import_react31.useState)(0);
|
|
2662
2688
|
const view = state.viewModel;
|
|
2663
2689
|
const { window: viewWindow, onScroll: handleGridScroll } = useSpreadsheetViewport(scrollRef, view, {
|
|
2664
2690
|
virtualize,
|
|
2665
2691
|
merges: state.document.table?.merges,
|
|
2666
2692
|
activeCell: state.activeCell
|
|
2667
2693
|
});
|
|
2668
|
-
const columnSlots = (0,
|
|
2694
|
+
const columnSlots = (0, import_react31.useMemo)(() => {
|
|
2669
2695
|
const col = (viewCol) => ({ kind: "col", viewCol });
|
|
2670
2696
|
if (!viewWindow.virtual) return view.columns.map(col);
|
|
2671
2697
|
const slots = view.columns.slice(0, viewWindow.frozenColumns).map(col);
|
|
@@ -2674,11 +2700,11 @@ var SpreadsheetEditor = ({
|
|
|
2674
2700
|
if (viewWindow.rightSpace > 0) slots.push({ kind: "space", key: "space:right", width: viewWindow.rightSpace });
|
|
2675
2701
|
return slots;
|
|
2676
2702
|
}, [view, viewWindow]);
|
|
2677
|
-
const renderedColumns = (0,
|
|
2703
|
+
const renderedColumns = (0, import_react31.useMemo)(
|
|
2678
2704
|
() => columnSlots.flatMap((slot) => slot.kind === "col" ? [slot.viewCol] : []),
|
|
2679
2705
|
[columnSlots]
|
|
2680
2706
|
);
|
|
2681
|
-
const rowSlots = (0,
|
|
2707
|
+
const rowSlots = (0, import_react31.useMemo)(() => {
|
|
2682
2708
|
const row = (viewRow) => ({ kind: "row", viewRow });
|
|
2683
2709
|
if (!viewWindow.virtual) return view.rows.map(row);
|
|
2684
2710
|
const slots = view.rows.slice(0, viewWindow.frozenRows).map(row);
|
|
@@ -2689,16 +2715,16 @@ var SpreadsheetEditor = ({
|
|
|
2689
2715
|
}, [view, viewWindow]);
|
|
2690
2716
|
const { copyShortcutFallback } = useSpreadsheetClipboard(gridRef, state, readOnly);
|
|
2691
2717
|
const { fillTarget, startFill, extendFill } = useFillHandle(state);
|
|
2692
|
-
const [menu, setMenu] = (0,
|
|
2693
|
-
const [panel, setPanel] = (0,
|
|
2694
|
-
const [listMenu, setListMenu] = (0,
|
|
2718
|
+
const [menu, setMenu] = (0, import_react31.useState)(null);
|
|
2719
|
+
const [panel, setPanel] = (0, import_react31.useState)(null);
|
|
2720
|
+
const [listMenu, setListMenu] = (0, import_react31.useState)(null);
|
|
2695
2721
|
const overlay = state.conditionalFormatOverlay;
|
|
2696
2722
|
const filter = state.document.table?.filter;
|
|
2697
|
-
const filteredColIds = (0,
|
|
2723
|
+
const filteredColIds = (0, import_react31.useMemo)(
|
|
2698
2724
|
() => new Set(filter?.enabled ? filter.rules.map((r) => r.colId) : []),
|
|
2699
2725
|
[filter]
|
|
2700
2726
|
);
|
|
2701
|
-
const handleCellContextMenu = (0,
|
|
2727
|
+
const handleCellContextMenu = (0, import_react31.useCallback)((rIdx, cIdx, e) => {
|
|
2702
2728
|
if (readOnly) return;
|
|
2703
2729
|
e.preventDefault();
|
|
2704
2730
|
if (state.editingCell) state.commitEditing();
|
|
@@ -2707,33 +2733,33 @@ var SpreadsheetEditor = ({
|
|
|
2707
2733
|
}
|
|
2708
2734
|
setMenu({ x: e.clientX, y: e.clientY, items: (0, import_spreadsheet8.getSpreadsheetMenuItems)(state.controller, { row: rIdx, col: cIdx }) });
|
|
2709
2735
|
}, [readOnly, state]);
|
|
2710
|
-
const nameSuggestions = (0,
|
|
2736
|
+
const nameSuggestions = (0, import_react31.useMemo)(
|
|
2711
2737
|
() => state.controller.getNameSuggestions(),
|
|
2712
2738
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2713
2739
|
[state.controller, state.document]
|
|
2714
2740
|
);
|
|
2715
|
-
const activeRawValue = (0,
|
|
2741
|
+
const activeRawValue = (0, import_react31.useMemo)(() => {
|
|
2716
2742
|
if (!state.activeCell) return "";
|
|
2717
2743
|
const row = state.document.rows[state.activeCell.row];
|
|
2718
2744
|
const col = state.document.columns[state.activeCell.col];
|
|
2719
2745
|
if (!row || !col) return "";
|
|
2720
2746
|
return state.getCell(row.id, col.id).raw;
|
|
2721
2747
|
}, [state.activeCell, state.document]);
|
|
2722
|
-
const activeSpill = (0,
|
|
2748
|
+
const activeSpill = (0, import_react31.useMemo)(
|
|
2723
2749
|
() => state.activeCell ? state.controller.getSpillAt(state.activeCell.row, state.activeCell.col) : null,
|
|
2724
2750
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2725
2751
|
[state.controller, state.activeCell, state.document]
|
|
2726
2752
|
);
|
|
2727
2753
|
const spillFormula = activeSpill && !activeRawValue && activeSpill.key !== coordKey(state.activeCell) ? activeSpill.formula : "";
|
|
2728
|
-
const coordLabel = (0,
|
|
2754
|
+
const coordLabel = (0, import_react31.useMemo)(() => {
|
|
2729
2755
|
if (!state.activeCell) return "--";
|
|
2730
2756
|
const colName = (0, import_spreadsheet8.indexToColName)(state.activeCell.col);
|
|
2731
2757
|
return `${colName}${state.activeCell.row + 1}`;
|
|
2732
2758
|
}, [state.activeCell]);
|
|
2733
|
-
const [formulaDraft, setFormulaDraft] = (0,
|
|
2759
|
+
const [formulaDraft, setFormulaDraft] = (0, import_react31.useState)(null);
|
|
2734
2760
|
const activeColumn = state.activeCell ? state.document.columns[state.activeCell.col] : void 0;
|
|
2735
2761
|
const formulaBarReadOnly = readOnly || !state.activeCell || !!activeColumn?.readOnly;
|
|
2736
|
-
(0,
|
|
2762
|
+
(0, import_react31.useEffect)(() => {
|
|
2737
2763
|
setFormulaDraft(null);
|
|
2738
2764
|
}, [state.activeCell?.row, state.activeCell?.col]);
|
|
2739
2765
|
const commitFormulaBar = () => {
|
|
@@ -2749,19 +2775,19 @@ var SpreadsheetEditor = ({
|
|
|
2749
2775
|
}
|
|
2750
2776
|
setFormulaDraft(null);
|
|
2751
2777
|
};
|
|
2752
|
-
const handleCellClick = (0,
|
|
2778
|
+
const handleCellClick = (0, import_react31.useCallback)((rIdx, cIdx, e) => {
|
|
2753
2779
|
if (state.editingCell && (state.editingCell.row !== rIdx || state.editingCell.col !== cIdx)) {
|
|
2754
2780
|
state.commitEditing();
|
|
2755
2781
|
}
|
|
2756
2782
|
state.selectCell(rIdx, cIdx, e.shiftKey);
|
|
2757
2783
|
}, [state]);
|
|
2758
|
-
const handleCellDblClick = (0,
|
|
2784
|
+
const handleCellDblClick = (0, import_react31.useCallback)((rIdx, cIdx) => {
|
|
2759
2785
|
if (readOnly) return;
|
|
2760
2786
|
const col = state.document.columns[cIdx];
|
|
2761
2787
|
if (col?.readOnly) return;
|
|
2762
2788
|
state.startEditing(rIdx, cIdx);
|
|
2763
2789
|
}, [readOnly, state]);
|
|
2764
|
-
const handleKeyDown = (0,
|
|
2790
|
+
const handleKeyDown = (0, import_react31.useCallback)((e) => {
|
|
2765
2791
|
if (state.editingCell) {
|
|
2766
2792
|
if (e.key === "Enter") {
|
|
2767
2793
|
e.preventDefault();
|
|
@@ -2833,12 +2859,12 @@ var SpreadsheetEditor = ({
|
|
|
2833
2859
|
}
|
|
2834
2860
|
}
|
|
2835
2861
|
}, [readOnly, state, copyShortcutFallback]);
|
|
2836
|
-
const activeListValues = (0,
|
|
2862
|
+
const activeListValues = (0, import_react31.useMemo)(
|
|
2837
2863
|
() => state.activeCell && !readOnly ? state.controller.getValidationListValues(state.activeCell.row, state.activeCell.col) : null,
|
|
2838
2864
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2839
2865
|
[state.controller, state.activeCell, state.document, readOnly]
|
|
2840
2866
|
);
|
|
2841
|
-
const activeRule = (0,
|
|
2867
|
+
const activeRule = (0, import_react31.useMemo)(
|
|
2842
2868
|
() => state.activeCell ? state.controller.getDataValidationAt(state.activeCell.row, state.activeCell.col) : void 0,
|
|
2843
2869
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2844
2870
|
[state.controller, state.activeCell, state.document]
|
|
@@ -2852,7 +2878,7 @@ var SpreadsheetEditor = ({
|
|
|
2852
2878
|
const rect = td?.getBoundingClientRect();
|
|
2853
2879
|
setListMenu({ x: rect ? rect.left : 0, y: rect ? rect.bottom : 0, row, col, values });
|
|
2854
2880
|
}
|
|
2855
|
-
(0,
|
|
2881
|
+
(0, import_react31.useEffect)(() => {
|
|
2856
2882
|
if (!listMenu) return;
|
|
2857
2883
|
const close = (e) => {
|
|
2858
2884
|
if (!e.target?.closest?.('[aria-label="Allowed values"], .spreadsheet-list-arrow')) setListMenu(null);
|
|
@@ -2875,11 +2901,11 @@ var SpreadsheetEditor = ({
|
|
|
2875
2901
|
else gridRef.current?.focus();
|
|
2876
2902
|
});
|
|
2877
2903
|
};
|
|
2878
|
-
const stateRef = (0,
|
|
2904
|
+
const stateRef = (0, import_react31.useRef)(state);
|
|
2879
2905
|
stateRef.current = state;
|
|
2880
|
-
const onColumnResizeRef = (0,
|
|
2906
|
+
const onColumnResizeRef = (0, import_react31.useRef)(onColumnResize);
|
|
2881
2907
|
onColumnResizeRef.current = onColumnResize;
|
|
2882
|
-
(0,
|
|
2908
|
+
(0, import_react31.useEffect)(() => {
|
|
2883
2909
|
if (!resizingColId) return;
|
|
2884
2910
|
if (typeof document !== "undefined") {
|
|
2885
2911
|
document.body.style.cursor = "col-resize";
|
|
@@ -2930,7 +2956,7 @@ var SpreadsheetEditor = ({
|
|
|
2930
2956
|
window.removeEventListener("mouseup", handleMouseUp);
|
|
2931
2957
|
};
|
|
2932
2958
|
}, [resizingColId, resizeStartX, resizeStartWidth]);
|
|
2933
|
-
const measureElementContentWidth = (0,
|
|
2959
|
+
const measureElementContentWidth = (0, import_react31.useCallback)((el, container) => {
|
|
2934
2960
|
if (typeof document === "undefined") return 0;
|
|
2935
2961
|
let maxW = el.scrollWidth || 0;
|
|
2936
2962
|
const firstChild = el.firstElementChild;
|
|
@@ -2978,7 +3004,7 @@ var SpreadsheetEditor = ({
|
|
|
2978
3004
|
}
|
|
2979
3005
|
return maxW;
|
|
2980
3006
|
}, []);
|
|
2981
|
-
const autoFitColumn = (0,
|
|
3007
|
+
const autoFitColumn = (0, import_react31.useCallback)((colId, colIndex) => {
|
|
2982
3008
|
const col = state.document.columns.find((c) => c.id === colId);
|
|
2983
3009
|
if (!col) return;
|
|
2984
3010
|
let calculatedWidth = 0;
|
|
@@ -3014,12 +3040,12 @@ var SpreadsheetEditor = ({
|
|
|
3014
3040
|
onColumnResize(updatedCol.id, updatedCol.width || 130);
|
|
3015
3041
|
}
|
|
3016
3042
|
}, [state, measureElementContentWidth, onColumnResize]);
|
|
3017
|
-
const handleResizeDblClick = (0,
|
|
3043
|
+
const handleResizeDblClick = (0, import_react31.useCallback)((colId, colIndex, e) => {
|
|
3018
3044
|
e.preventDefault();
|
|
3019
3045
|
e.stopPropagation();
|
|
3020
3046
|
autoFitColumn(colId, colIndex);
|
|
3021
3047
|
}, [autoFitColumn]);
|
|
3022
|
-
const handleHeaderDblClick = (0,
|
|
3048
|
+
const handleHeaderDblClick = (0, import_react31.useCallback)((colId, colIndex, e) => {
|
|
3023
3049
|
const target = e.currentTarget;
|
|
3024
3050
|
if (target) {
|
|
3025
3051
|
const rect = target.getBoundingClientRect();
|
|
@@ -3410,19 +3436,19 @@ var SpreadsheetEditor = ({
|
|
|
3410
3436
|
};
|
|
3411
3437
|
|
|
3412
3438
|
// src/spreadsheet/NameManager.tsx
|
|
3413
|
-
var
|
|
3439
|
+
var import_react32 = require("react");
|
|
3414
3440
|
var import_spreadsheet9 = require("@pixerate/editor/spreadsheet");
|
|
3415
3441
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
3416
3442
|
var EMPTY_DRAFT = { original: null, name: "", refersTo: "=", scope: "", comment: "" };
|
|
3417
3443
|
var NameManager = ({ state, readOnly = false, onClose, className = "" }) => {
|
|
3418
3444
|
const { controller, sheets } = state;
|
|
3419
|
-
const rows = (0,
|
|
3445
|
+
const rows = (0, import_react32.useMemo)(
|
|
3420
3446
|
() => (0, import_spreadsheet9.getNameManagerRows)(controller),
|
|
3421
3447
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3422
3448
|
[controller, state.document, state.names]
|
|
3423
3449
|
);
|
|
3424
|
-
const [draft, setDraft] = (0,
|
|
3425
|
-
const [error, setError] = (0,
|
|
3450
|
+
const [draft, setDraft] = (0, import_react32.useState)(EMPTY_DRAFT);
|
|
3451
|
+
const [error, setError] = (0, import_react32.useState)(null);
|
|
3426
3452
|
const edit = (row) => {
|
|
3427
3453
|
setError(null);
|
|
3428
3454
|
setDraft({
|
|
@@ -3565,7 +3591,7 @@ var NameManager = ({ state, readOnly = false, onClose, className = "" }) => {
|
|
|
3565
3591
|
};
|
|
3566
3592
|
|
|
3567
3593
|
// src/slots.tsx
|
|
3568
|
-
var
|
|
3594
|
+
var import_react33 = require("react");
|
|
3569
3595
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
3570
3596
|
var defaultSlots = {
|
|
3571
3597
|
Button: (props) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
@@ -3587,119 +3613,119 @@ var defaultSlots = {
|
|
|
3587
3613
|
props.onClose && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("button", { type: "button", onClick: props.onClose, className: "opacity-70 hover:opacity-100", children: "\xD7" })
|
|
3588
3614
|
] })
|
|
3589
3615
|
};
|
|
3590
|
-
var EditorSlotsContext = (0,
|
|
3616
|
+
var EditorSlotsContext = (0, import_react33.createContext)(defaultSlots);
|
|
3591
3617
|
function EditorSlotsProvider({ slots, children }) {
|
|
3592
|
-
const mergedSlots = (0,
|
|
3618
|
+
const mergedSlots = (0, import_react33.useMemo)(() => ({ ...defaultSlots, ...slots }), [slots]);
|
|
3593
3619
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(EditorSlotsContext.Provider, { value: mergedSlots, children });
|
|
3594
3620
|
}
|
|
3595
3621
|
function useEditorSlots() {
|
|
3596
|
-
return (0,
|
|
3622
|
+
return (0, import_react33.useContext)(EditorSlotsContext);
|
|
3597
3623
|
}
|
|
3598
3624
|
|
|
3599
3625
|
// src/image-editor/useImageEditor.ts
|
|
3600
|
-
var
|
|
3626
|
+
var import_react34 = require("react");
|
|
3601
3627
|
var import_image_editor = require("@pixerate/editor/image-editor");
|
|
3602
3628
|
function useImageEditor(options = {}) {
|
|
3603
|
-
const controllerRef = (0,
|
|
3629
|
+
const controllerRef = (0, import_react34.useRef)(null);
|
|
3604
3630
|
if (!controllerRef.current) {
|
|
3605
3631
|
controllerRef.current = new import_image_editor.ImageEditorController(options);
|
|
3606
3632
|
}
|
|
3607
3633
|
const controller = controllerRef.current;
|
|
3608
|
-
const [state, setState] = (0,
|
|
3609
|
-
const [historyTicks, setHistoryTicks] = (0,
|
|
3610
|
-
const [histogram, setHistogram] = (0,
|
|
3611
|
-
(0,
|
|
3612
|
-
(0,
|
|
3634
|
+
const [state, setState] = (0, import_react34.useState)(() => controller.getState());
|
|
3635
|
+
const [historyTicks, setHistoryTicks] = (0, import_react34.useState)(0);
|
|
3636
|
+
const [histogram, setHistogram] = (0, import_react34.useState)(() => controller.getHistogram());
|
|
3637
|
+
(0, import_react34.useEffect)(() => controller.subscribeHistogram(setHistogram), [controller]);
|
|
3638
|
+
(0, import_react34.useEffect)(() => {
|
|
3613
3639
|
const unsub = controller.subscribe((next) => {
|
|
3614
3640
|
setState(next);
|
|
3615
3641
|
setHistoryTicks((t) => t + 1);
|
|
3616
3642
|
});
|
|
3617
3643
|
return unsub;
|
|
3618
3644
|
}, [controller]);
|
|
3619
|
-
const loadedImageRef = (0,
|
|
3620
|
-
(0,
|
|
3645
|
+
const loadedImageRef = (0, import_react34.useRef)(options.image);
|
|
3646
|
+
(0, import_react34.useEffect)(() => {
|
|
3621
3647
|
if (options.image === loadedImageRef.current) return;
|
|
3622
3648
|
loadedImageRef.current = options.image;
|
|
3623
3649
|
if (options.image) {
|
|
3624
3650
|
controller.loadImage(options.image);
|
|
3625
3651
|
}
|
|
3626
3652
|
}, [options.image, controller]);
|
|
3627
|
-
const setTool = (0,
|
|
3628
|
-
const setCrop = (0,
|
|
3653
|
+
const setTool = (0, import_react34.useCallback)((tool) => controller.setTool(tool), [controller]);
|
|
3654
|
+
const setCrop = (0, import_react34.useCallback)(
|
|
3629
3655
|
(crop, addToHistory = true) => controller.setCrop(crop, addToHistory),
|
|
3630
3656
|
[controller]
|
|
3631
3657
|
);
|
|
3632
|
-
const applyCropPreset = (0,
|
|
3633
|
-
const resetCrop = (0,
|
|
3634
|
-
const rotate = (0,
|
|
3635
|
-
const setRotation = (0,
|
|
3636
|
-
const flipHorizontal = (0,
|
|
3637
|
-
const flipVertical = (0,
|
|
3638
|
-
const setAdjustments = (0,
|
|
3658
|
+
const applyCropPreset = (0, import_react34.useCallback)((ratio) => controller.applyCropPreset(ratio), [controller]);
|
|
3659
|
+
const resetCrop = (0, import_react34.useCallback)(() => controller.resetCrop(), [controller]);
|
|
3660
|
+
const rotate = (0, import_react34.useCallback)((deg) => controller.rotate(deg), [controller]);
|
|
3661
|
+
const setRotation = (0, import_react34.useCallback)((deg) => controller.setRotation(deg), [controller]);
|
|
3662
|
+
const flipHorizontal = (0, import_react34.useCallback)(() => controller.flipHorizontal(), [controller]);
|
|
3663
|
+
const flipVertical = (0, import_react34.useCallback)(() => controller.flipVertical(), [controller]);
|
|
3664
|
+
const setAdjustments = (0, import_react34.useCallback)(
|
|
3639
3665
|
(partial, commitToHistory = true) => controller.setAdjustments(partial, commitToHistory),
|
|
3640
3666
|
[controller]
|
|
3641
3667
|
);
|
|
3642
|
-
const resetAdjustments = (0,
|
|
3643
|
-
const upgradeProcess = (0,
|
|
3644
|
-
const addAdjustmentLayer = (0,
|
|
3668
|
+
const resetAdjustments = (0, import_react34.useCallback)(() => controller.resetAdjustments(), [controller]);
|
|
3669
|
+
const upgradeProcess = (0, import_react34.useCallback)(() => controller.upgradeProcess(), [controller]);
|
|
3670
|
+
const addAdjustmentLayer = (0, import_react34.useCallback)(
|
|
3645
3671
|
(init, index) => controller.addAdjustmentLayer(init, index),
|
|
3646
3672
|
[controller]
|
|
3647
3673
|
);
|
|
3648
|
-
const updateAdjustmentLayer = (0,
|
|
3674
|
+
const updateAdjustmentLayer = (0, import_react34.useCallback)(
|
|
3649
3675
|
(id, update, commitToHistory = true) => controller.updateAdjustmentLayer(id, update, commitToHistory),
|
|
3650
3676
|
[controller]
|
|
3651
3677
|
);
|
|
3652
|
-
const removeAdjustmentLayer = (0,
|
|
3653
|
-
const moveAdjustmentLayer = (0,
|
|
3654
|
-
const toggleAdjustmentLayer = (0,
|
|
3678
|
+
const removeAdjustmentLayer = (0, import_react34.useCallback)((id) => controller.removeAdjustmentLayer(id), [controller]);
|
|
3679
|
+
const moveAdjustmentLayer = (0, import_react34.useCallback)((id, to) => controller.moveAdjustmentLayer(id, to), [controller]);
|
|
3680
|
+
const toggleAdjustmentLayer = (0, import_react34.useCallback)(
|
|
3655
3681
|
(id, enabled) => controller.toggleAdjustmentLayer(id, enabled),
|
|
3656
3682
|
[controller]
|
|
3657
3683
|
);
|
|
3658
|
-
const setDepthMask = (0,
|
|
3659
|
-
const resetDepthMask = (0,
|
|
3660
|
-
const addAnnotation = (0,
|
|
3661
|
-
const updateAnnotation = (0,
|
|
3684
|
+
const setDepthMask = (0, import_react34.useCallback)((partial) => controller.setDepthMask(partial), [controller]);
|
|
3685
|
+
const resetDepthMask = (0, import_react34.useCallback)(() => controller.resetDepthMask(), [controller]);
|
|
3686
|
+
const addAnnotation = (0, import_react34.useCallback)((ann) => controller.addAnnotation(ann), [controller]);
|
|
3687
|
+
const updateAnnotation = (0, import_react34.useCallback)(
|
|
3662
3688
|
(id, partial, commitToHistory = true) => controller.updateAnnotation(id, partial, commitToHistory),
|
|
3663
3689
|
[controller]
|
|
3664
3690
|
);
|
|
3665
|
-
const removeAnnotation = (0,
|
|
3666
|
-
const clearAnnotations = (0,
|
|
3667
|
-
const selectAnnotation = (0,
|
|
3668
|
-
const undo = (0,
|
|
3669
|
-
const redo = (0,
|
|
3670
|
-
const reset = (0,
|
|
3671
|
-
const zoomIn = (0,
|
|
3672
|
-
const zoomOut = (0,
|
|
3673
|
-
const resetZoom = (0,
|
|
3674
|
-
const setZoom = (0,
|
|
3675
|
-
const setPan = (0,
|
|
3676
|
-
const setComparing = (0,
|
|
3677
|
-
const loadImage = (0,
|
|
3678
|
-
const toDataURL = (0,
|
|
3679
|
-
const toBlob = (0,
|
|
3680
|
-
const toJSON = (0,
|
|
3681
|
-
const loadJSON = (0,
|
|
3682
|
-
const renderMask = (0,
|
|
3691
|
+
const removeAnnotation = (0, import_react34.useCallback)((id) => controller.removeAnnotation(id), [controller]);
|
|
3692
|
+
const clearAnnotations = (0, import_react34.useCallback)(() => controller.clearAnnotations(), [controller]);
|
|
3693
|
+
const selectAnnotation = (0, import_react34.useCallback)((id) => controller.selectAnnotation(id), [controller]);
|
|
3694
|
+
const undo = (0, import_react34.useCallback)(() => controller.undo(), [controller]);
|
|
3695
|
+
const redo = (0, import_react34.useCallback)(() => controller.redo(), [controller]);
|
|
3696
|
+
const reset = (0, import_react34.useCallback)(() => controller.reset(), [controller]);
|
|
3697
|
+
const zoomIn = (0, import_react34.useCallback)((factor) => controller.zoomIn(factor), [controller]);
|
|
3698
|
+
const zoomOut = (0, import_react34.useCallback)((factor) => controller.zoomOut(factor), [controller]);
|
|
3699
|
+
const resetZoom = (0, import_react34.useCallback)(() => controller.resetZoom(), [controller]);
|
|
3700
|
+
const setZoom = (0, import_react34.useCallback)((zoom) => controller.setZoom(zoom), [controller]);
|
|
3701
|
+
const setPan = (0, import_react34.useCallback)((pan) => controller.setPan(pan), [controller]);
|
|
3702
|
+
const setComparing = (0, import_react34.useCallback)((comp) => controller.setComparing(comp), [controller]);
|
|
3703
|
+
const loadImage = (0, import_react34.useCallback)((src) => controller.loadImage(src), [controller]);
|
|
3704
|
+
const toDataURL = (0, import_react34.useCallback)((opts) => controller.toDataURL(opts), [controller]);
|
|
3705
|
+
const toBlob = (0, import_react34.useCallback)((opts) => controller.toBlob(opts), [controller]);
|
|
3706
|
+
const toJSON = (0, import_react34.useCallback)(() => controller.toJSON(), [controller]);
|
|
3707
|
+
const loadJSON = (0, import_react34.useCallback)((data) => controller.loadJSON(data), [controller]);
|
|
3708
|
+
const renderMask = (0, import_react34.useCallback)(
|
|
3683
3709
|
(opts) => controller.renderMask(opts),
|
|
3684
3710
|
[controller]
|
|
3685
3711
|
);
|
|
3686
|
-
const toMaskDataURL = (0,
|
|
3712
|
+
const toMaskDataURL = (0, import_react34.useCallback)(
|
|
3687
3713
|
(opts) => controller.toMaskDataURL(opts),
|
|
3688
3714
|
[controller]
|
|
3689
3715
|
);
|
|
3690
|
-
const toSourceDataURL = (0,
|
|
3716
|
+
const toSourceDataURL = (0, import_react34.useCallback)(
|
|
3691
3717
|
(opts) => controller.toSourceDataURL(opts),
|
|
3692
3718
|
[controller]
|
|
3693
3719
|
);
|
|
3694
|
-
const applyInpaintedImage = (0,
|
|
3720
|
+
const applyInpaintedImage = (0, import_react34.useCallback)(
|
|
3695
3721
|
(newDataUrl) => controller.applyInpaintedImage(newDataUrl),
|
|
3696
3722
|
[controller]
|
|
3697
3723
|
);
|
|
3698
|
-
const applyBackgroundRemovedImage = (0,
|
|
3724
|
+
const applyBackgroundRemovedImage = (0, import_react34.useCallback)(
|
|
3699
3725
|
(newDataUrl) => controller.applyBackgroundRemovedImage(newDataUrl),
|
|
3700
3726
|
[controller]
|
|
3701
3727
|
);
|
|
3702
|
-
return (0,
|
|
3728
|
+
return (0, import_react34.useMemo)(
|
|
3703
3729
|
() => ({
|
|
3704
3730
|
controller,
|
|
3705
3731
|
state,
|
|
@@ -3755,7 +3781,7 @@ function useImageEditor(options = {}) {
|
|
|
3755
3781
|
}
|
|
3756
3782
|
|
|
3757
3783
|
// src/image-editor/ImageEditor.tsx
|
|
3758
|
-
var
|
|
3784
|
+
var import_react40 = __toESM(require("react"), 1);
|
|
3759
3785
|
var import_image_editor8 = require("@pixerate/editor/image-editor");
|
|
3760
3786
|
|
|
3761
3787
|
// src/image-editor/ControlSlider.tsx
|
|
@@ -3788,7 +3814,7 @@ var ControlSlider = ({ spec, value, onChange, disabled, label }) => {
|
|
|
3788
3814
|
};
|
|
3789
3815
|
|
|
3790
3816
|
// src/image-editor/Histogram.tsx
|
|
3791
|
-
var
|
|
3817
|
+
var import_react35 = require("react");
|
|
3792
3818
|
var import_image_editor3 = require("@pixerate/editor/image-editor");
|
|
3793
3819
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
3794
3820
|
var FILL = {
|
|
@@ -3800,7 +3826,7 @@ var FILL = {
|
|
|
3800
3826
|
var W = 256;
|
|
3801
3827
|
var Histogram = ({ histogram, channel = "rgb", height = 64, className = "", style }) => {
|
|
3802
3828
|
const channels = channel === "rgb" ? ["luminance", "red", "green", "blue"] : [channel];
|
|
3803
|
-
const paths = (0,
|
|
3829
|
+
const paths = (0, import_react35.useMemo)(
|
|
3804
3830
|
() => histogram && histogram.samples > 0 ? channels.map((c) => ({ c, d: (0, import_image_editor3.histogramPath)(histogram, c, W, height) })) : [],
|
|
3805
3831
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3806
3832
|
[histogram, channel, height]
|
|
@@ -3826,24 +3852,24 @@ var Histogram = ({ histogram, channel = "rgb", height = 64, className = "", styl
|
|
|
3826
3852
|
);
|
|
3827
3853
|
};
|
|
3828
3854
|
function useImageHistogram(controller) {
|
|
3829
|
-
const [histogram, setHistogram] = (0,
|
|
3830
|
-
(0,
|
|
3855
|
+
const [histogram, setHistogram] = (0, import_react35.useState)(() => controller.getHistogram());
|
|
3856
|
+
(0, import_react35.useEffect)(() => controller.subscribeHistogram(setHistogram), [controller]);
|
|
3831
3857
|
return histogram;
|
|
3832
3858
|
}
|
|
3833
3859
|
|
|
3834
3860
|
// src/image-editor/AdjustmentLayersPanel.tsx
|
|
3835
|
-
var
|
|
3861
|
+
var import_react37 = require("react");
|
|
3836
3862
|
var import_image_editor5 = require("@pixerate/editor/image-editor");
|
|
3837
3863
|
|
|
3838
3864
|
// src/image-editor/CurvesEditor.tsx
|
|
3839
|
-
var
|
|
3865
|
+
var import_react36 = require("react");
|
|
3840
3866
|
var import_image_editor4 = require("@pixerate/editor/image-editor");
|
|
3841
3867
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3842
3868
|
var BOX = 256;
|
|
3843
3869
|
var STROKE = { master: "#e2e8f0", red: "#ef4444", green: "#22c55e", blue: "#3b82f6" };
|
|
3844
3870
|
var CurvesEditor = ({ points, onChange, histogram, channel = "master", size = 200 }) => {
|
|
3845
|
-
const svgRef = (0,
|
|
3846
|
-
const [drag, setDrag] = (0,
|
|
3871
|
+
const svgRef = (0, import_react36.useRef)(null);
|
|
3872
|
+
const [drag, setDrag] = (0, import_react36.useState)(null);
|
|
3847
3873
|
const toBox = (e) => {
|
|
3848
3874
|
const rect = svgRef.current?.getBoundingClientRect();
|
|
3849
3875
|
if (!rect || !rect.width || !rect.height) return { x: 0, y: 0 };
|
|
@@ -3942,14 +3968,14 @@ var HueRangeStrip = ({ bounds }) => {
|
|
|
3942
3968
|
};
|
|
3943
3969
|
var AdjustmentLayersPanel = ({ controller, layers: layersProp, histogram }) => {
|
|
3944
3970
|
const follow = layersProp === void 0;
|
|
3945
|
-
const [, setTick] = (0,
|
|
3946
|
-
(0,
|
|
3971
|
+
const [, setTick] = (0, import_react37.useState)(0);
|
|
3972
|
+
(0, import_react37.useEffect)(() => follow ? controller.subscribe(() => setTick((n) => n + 1)) : void 0, [controller, follow]);
|
|
3947
3973
|
const layers = layersProp ?? controller.getAdjustmentLayers();
|
|
3948
|
-
const [newKind, setNewKind] = (0,
|
|
3949
|
-
const [selectedId, setSelectedId] = (0,
|
|
3950
|
-
const [channel, setChannel] = (0,
|
|
3951
|
-
const [range, setRange] = (0,
|
|
3952
|
-
const [tone, setTone] = (0,
|
|
3974
|
+
const [newKind, setNewKind] = (0, import_react37.useState)("curves");
|
|
3975
|
+
const [selectedId, setSelectedId] = (0, import_react37.useState)(null);
|
|
3976
|
+
const [channel, setChannel] = (0, import_react37.useState)("master");
|
|
3977
|
+
const [range, setRange] = (0, import_react37.useState)(-1);
|
|
3978
|
+
const [tone, setTone] = (0, import_react37.useState)("midtones");
|
|
3953
3979
|
const selected = layers.find((l) => l.id === selectedId) ?? null;
|
|
3954
3980
|
const topFirst = [...layers].reverse();
|
|
3955
3981
|
const setParam = (layer, path, value, commit = true) => controller.updateAdjustmentLayer(layer.id, { params: (0, import_image_editor5.setControlPath)(layer.params, path, value) }, commit);
|
|
@@ -4188,7 +4214,7 @@ var AdjustmentLayersPanel = ({ controller, layers: layersProp, histogram }) => {
|
|
|
4188
4214
|
};
|
|
4189
4215
|
|
|
4190
4216
|
// src/image-editor/SelectionOptionsBar.tsx
|
|
4191
|
-
var
|
|
4217
|
+
var import_react38 = require("react");
|
|
4192
4218
|
var import_image_editor6 = require("@pixerate/editor/image-editor");
|
|
4193
4219
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
4194
4220
|
var MODIFY_OPS = [
|
|
@@ -4207,7 +4233,7 @@ var SelectionOptionsBar = ({
|
|
|
4207
4233
|
quickMask,
|
|
4208
4234
|
className = ""
|
|
4209
4235
|
}) => {
|
|
4210
|
-
const [radius, setRadius] = (0,
|
|
4236
|
+
const [radius, setRadius] = (0, import_react38.useState)(2);
|
|
4211
4237
|
const set = (patch) => onOptionsChange({ ...options, ...patch });
|
|
4212
4238
|
const sel = selection === void 0 ? controller.getSelection() : selection;
|
|
4213
4239
|
const qm = quickMask ?? Boolean(controller.getState().quickMask);
|
|
@@ -4277,17 +4303,17 @@ var SelectionOptionsBar = ({
|
|
|
4277
4303
|
};
|
|
4278
4304
|
|
|
4279
4305
|
// src/image-editor/RefineEdgePanel.tsx
|
|
4280
|
-
var
|
|
4306
|
+
var import_react39 = require("react");
|
|
4281
4307
|
var import_image_editor7 = require("@pixerate/editor/image-editor");
|
|
4282
4308
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
4283
4309
|
var DEFAULT_PARAMS = { radius: 8, smartRadius: false, smooth: 0, feather: 0, contrast: 0, shiftEdge: 0 };
|
|
4284
4310
|
var button = "px-2 py-1 rounded-md border border-slate-800 bg-slate-950 text-[11px] text-slate-200 hover:text-white disabled:opacity-40";
|
|
4285
4311
|
var RefineEdgePanel = ({ controller, selection, layers, className = "" }) => {
|
|
4286
|
-
const [params, setParams] = (0,
|
|
4287
|
-
const [busy, setBusy] = (0,
|
|
4288
|
-
const [error, setError] = (0,
|
|
4289
|
-
const [layerId, setLayerId] = (0,
|
|
4290
|
-
const [newKind, setNewKind] = (0,
|
|
4312
|
+
const [params, setParams] = (0, import_react39.useState)(DEFAULT_PARAMS);
|
|
4313
|
+
const [busy, setBusy] = (0, import_react39.useState)(false);
|
|
4314
|
+
const [error, setError] = (0, import_react39.useState)(null);
|
|
4315
|
+
const [layerId, setLayerId] = (0, import_react39.useState)("");
|
|
4316
|
+
const [newKind, setNewKind] = (0, import_react39.useState)("hueSaturation");
|
|
4291
4317
|
const sel = selection === void 0 ? controller.getSelection() : selection;
|
|
4292
4318
|
const list = layers ?? controller.getAdjustmentLayers();
|
|
4293
4319
|
const target = list.find((l) => l.id === layerId) ?? list[list.length - 1];
|
|
@@ -4444,25 +4470,25 @@ var ImageEditor = ({
|
|
|
4444
4470
|
const editor = externalEditor || internalEditor;
|
|
4445
4471
|
const { state, controller } = editor;
|
|
4446
4472
|
const legacyProcess = (0, import_image_editor8.normalizeProcessVersion)(state.adjustments.process) < import_image_editor8.LATEST_PROCESS_VERSION;
|
|
4447
|
-
const canvasRef = (0,
|
|
4448
|
-
const containerRef = (0,
|
|
4449
|
-
const [activeTab, setActiveTab] = (0,
|
|
4450
|
-
const [activeCropRatio, setActiveCropRatio] = (0,
|
|
4451
|
-
const [selectionOptions, setSelectionOptions] = (0,
|
|
4452
|
-
const selectionOptionsRef = (0,
|
|
4473
|
+
const canvasRef = (0, import_react40.useRef)(null);
|
|
4474
|
+
const containerRef = (0, import_react40.useRef)(null);
|
|
4475
|
+
const [activeTab, setActiveTab] = (0, import_react40.useState)("crop");
|
|
4476
|
+
const [activeCropRatio, setActiveCropRatio] = (0, import_react40.useState)(null);
|
|
4477
|
+
const [selectionOptions, setSelectionOptions] = (0, import_react40.useState)(import_image_editor8.DEFAULT_SELECTION_TOOL_OPTIONS);
|
|
4478
|
+
const selectionOptionsRef = (0, import_react40.useRef)(selectionOptions);
|
|
4453
4479
|
selectionOptionsRef.current = selectionOptions;
|
|
4454
|
-
const selectionGestureRef = (0,
|
|
4480
|
+
const selectionGestureRef = (0, import_react40.useRef)(null);
|
|
4455
4481
|
if (!selectionGestureRef.current || selectionGestureRef.current.controller !== controller) {
|
|
4456
4482
|
selectionGestureRef.current = new import_image_editor8.SelectionGesture(controller, () => selectionOptionsRef.current);
|
|
4457
4483
|
}
|
|
4458
|
-
const selectionDraftRef = (0,
|
|
4459
|
-
const [selectionError, setSelectionError] = (0,
|
|
4460
|
-
const [inpaintPrompt, setInpaintPrompt] = (0,
|
|
4461
|
-
const [inpaintMaskMode, setInpaintMaskMode] = (0,
|
|
4462
|
-
const [isRemovingBg, setIsRemovingBg] = (0,
|
|
4463
|
-
const [isInpainting, setIsInpainting] = (0,
|
|
4464
|
-
const [aiError, setAiError] = (0,
|
|
4465
|
-
const [aiSuccess, setAiSuccess] = (0,
|
|
4484
|
+
const selectionDraftRef = (0, import_react40.useRef)(null);
|
|
4485
|
+
const [selectionError, setSelectionError] = (0, import_react40.useState)(null);
|
|
4486
|
+
const [inpaintPrompt, setInpaintPrompt] = (0, import_react40.useState)("");
|
|
4487
|
+
const [inpaintMaskMode, setInpaintMaskMode] = (0, import_react40.useState)("annotations");
|
|
4488
|
+
const [isRemovingBg, setIsRemovingBg] = (0, import_react40.useState)(false);
|
|
4489
|
+
const [isInpainting, setIsInpainting] = (0, import_react40.useState)(false);
|
|
4490
|
+
const [aiError, setAiError] = (0, import_react40.useState)(null);
|
|
4491
|
+
const [aiSuccess, setAiSuccess] = (0, import_react40.useState)(null);
|
|
4466
4492
|
const effectiveOnInpaint = onInpaint || aiHooks?.onInpaint;
|
|
4467
4493
|
const effectiveOnRemoveBg = onRemoveBackground || aiHooks?.onRemoveBackground;
|
|
4468
4494
|
const handleRemoveBackground = async () => {
|
|
@@ -4524,18 +4550,18 @@ var ImageEditor = ({
|
|
|
4524
4550
|
setIsInpainting(false);
|
|
4525
4551
|
}
|
|
4526
4552
|
};
|
|
4527
|
-
const [activeColor, setActiveColor] = (0,
|
|
4528
|
-
const [strokeWidth, setStrokeWidth] = (0,
|
|
4529
|
-
const [fontSize, setFontSize] = (0,
|
|
4530
|
-
const [textInput, setTextInput] = (0,
|
|
4531
|
-
const draftAnnotationRef = (0,
|
|
4532
|
-
const draftCropRef = (0,
|
|
4533
|
-
const cropDragInfoRef = (0,
|
|
4534
|
-
const annotationDragInfoRef = (0,
|
|
4535
|
-
const isDrawingRef = (0,
|
|
4536
|
-
const currentPathRef = (0,
|
|
4537
|
-
const dragStartPointRef = (0,
|
|
4538
|
-
const renderCanvas = (0,
|
|
4553
|
+
const [activeColor, setActiveColor] = (0, import_react40.useState)("#ef4444");
|
|
4554
|
+
const [strokeWidth, setStrokeWidth] = (0, import_react40.useState)(3);
|
|
4555
|
+
const [fontSize, setFontSize] = (0, import_react40.useState)(24);
|
|
4556
|
+
const [textInput, setTextInput] = (0, import_react40.useState)("");
|
|
4557
|
+
const draftAnnotationRef = (0, import_react40.useRef)(null);
|
|
4558
|
+
const draftCropRef = (0, import_react40.useRef)(null);
|
|
4559
|
+
const cropDragInfoRef = (0, import_react40.useRef)(null);
|
|
4560
|
+
const annotationDragInfoRef = (0, import_react40.useRef)(null);
|
|
4561
|
+
const isDrawingRef = (0, import_react40.useRef)(false);
|
|
4562
|
+
const currentPathRef = (0, import_react40.useRef)([]);
|
|
4563
|
+
const dragStartPointRef = (0, import_react40.useRef)(null);
|
|
4564
|
+
const renderCanvas = (0, import_react40.useCallback)(
|
|
4539
4565
|
async (draftAnnotation, draftCrop) => {
|
|
4540
4566
|
const canvas = canvasRef.current;
|
|
4541
4567
|
const container = containerRef.current;
|
|
@@ -4555,7 +4581,7 @@ var ImageEditor = ({
|
|
|
4555
4581
|
},
|
|
4556
4582
|
[controller, activeTab]
|
|
4557
4583
|
);
|
|
4558
|
-
(0,
|
|
4584
|
+
(0, import_react40.useEffect)(() => {
|
|
4559
4585
|
const raf = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(cb, 0);
|
|
4560
4586
|
const caf = typeof cancelAnimationFrame !== "undefined" ? cancelAnimationFrame : (id) => clearTimeout(id);
|
|
4561
4587
|
const animId = raf(() => {
|
|
@@ -4563,12 +4589,12 @@ var ImageEditor = ({
|
|
|
4563
4589
|
});
|
|
4564
4590
|
return () => caf(animId);
|
|
4565
4591
|
}, [renderCanvas, state]);
|
|
4566
|
-
(0,
|
|
4592
|
+
(0, import_react40.useEffect)(() => {
|
|
4567
4593
|
if (activeTab === "crop" && editor.state.activeTool !== "crop") {
|
|
4568
4594
|
editor.setTool("crop");
|
|
4569
4595
|
}
|
|
4570
4596
|
}, [activeTab, editor]);
|
|
4571
|
-
(0,
|
|
4597
|
+
(0, import_react40.useEffect)(() => {
|
|
4572
4598
|
const container = containerRef.current;
|
|
4573
4599
|
if (!container) return;
|
|
4574
4600
|
if (typeof ResizeObserver !== "undefined") {
|
|
@@ -5264,7 +5290,7 @@ var ImageEditor = ({
|
|
|
5264
5290
|
)
|
|
5265
5291
|
] }),
|
|
5266
5292
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Histogram, { histogram: editor.histogram }),
|
|
5267
|
-
import_image_editor8.IMAGE_ADJUSTMENT_CONTROLS.map((spec) => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
|
|
5293
|
+
import_image_editor8.IMAGE_ADJUSTMENT_CONTROLS.map((spec) => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_react40.default.Fragment, { children: [
|
|
5268
5294
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
5269
5295
|
ControlSlider,
|
|
5270
5296
|
{
|
|
@@ -5670,7 +5696,7 @@ var ImageEditor = ({
|
|
|
5670
5696
|
};
|
|
5671
5697
|
|
|
5672
5698
|
// src/review/useReview.ts
|
|
5673
|
-
var
|
|
5699
|
+
var import_react41 = require("react");
|
|
5674
5700
|
var import_editor12 = require("@pixerate/editor");
|
|
5675
5701
|
var EMPTY_COMMENTS = Object.freeze({
|
|
5676
5702
|
threads: [],
|
|
@@ -5689,23 +5715,23 @@ function isCommentStore(value) {
|
|
|
5689
5715
|
}
|
|
5690
5716
|
function useComments(source) {
|
|
5691
5717
|
const store = isCommentStore(source) ? source : (0, import_editor12.getCommentStore)(source);
|
|
5692
|
-
const subscribe = (0,
|
|
5718
|
+
const subscribe = (0, import_react41.useCallback)(
|
|
5693
5719
|
(onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe,
|
|
5694
5720
|
[store]
|
|
5695
5721
|
);
|
|
5696
5722
|
const getSnapshot = () => store?.getSnapshot() ?? EMPTY_COMMENTS;
|
|
5697
|
-
const snapshot = (0,
|
|
5698
|
-
return (0,
|
|
5723
|
+
const snapshot = (0, import_react41.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
5724
|
+
return (0, import_react41.useMemo)(() => ({ ...snapshot, store }), [snapshot, store]);
|
|
5699
5725
|
}
|
|
5700
5726
|
function useTrackChanges(editor) {
|
|
5701
5727
|
const store = (0, import_editor12.getTrackChangesStore)(editor ?? null);
|
|
5702
|
-
const subscribe = (0,
|
|
5728
|
+
const subscribe = (0, import_react41.useCallback)(
|
|
5703
5729
|
(onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe,
|
|
5704
5730
|
[store]
|
|
5705
5731
|
);
|
|
5706
5732
|
const getSnapshot = () => store?.getSnapshot() ?? EMPTY_TRACK_CHANGES;
|
|
5707
|
-
const snapshot = (0,
|
|
5708
|
-
return (0,
|
|
5733
|
+
const snapshot = (0, import_react41.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
5734
|
+
return (0, import_react41.useMemo)(() => {
|
|
5709
5735
|
const run = (fn) => () => {
|
|
5710
5736
|
if (editor && !editor.isDestroyed) fn(editor);
|
|
5711
5737
|
};
|
|
@@ -5728,7 +5754,7 @@ function useTrackChanges(editor) {
|
|
|
5728
5754
|
}
|
|
5729
5755
|
|
|
5730
5756
|
// src/review/CommentsPanel.tsx
|
|
5731
|
-
var
|
|
5757
|
+
var import_react42 = require("react");
|
|
5732
5758
|
var import_editor13 = require("@pixerate/editor");
|
|
5733
5759
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
5734
5760
|
var buttonClass2 = "rounded px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50";
|
|
@@ -5744,7 +5770,7 @@ var CommentsPanel = ({
|
|
|
5744
5770
|
emptyMessage = "No comments yet. Select text and add a comment."
|
|
5745
5771
|
}) => {
|
|
5746
5772
|
const { threads, activeThreadId, store } = useComments(storeProp ?? editor);
|
|
5747
|
-
const [showResolved, setShowResolved] = (0,
|
|
5773
|
+
const [showResolved, setShowResolved] = (0, import_react42.useState)(showResolvedInitial);
|
|
5748
5774
|
const author = authorProp ?? (0, import_editor13.getCommentAuthor)(editor) ?? { id: "anonymous", name: "Anonymous" };
|
|
5749
5775
|
const visible = threads.filter((t) => showResolved || !t.resolved);
|
|
5750
5776
|
const resolvedCount = threads.filter((t) => t.resolved).length;
|
|
@@ -5788,7 +5814,7 @@ var CommentThreadCard = ({
|
|
|
5788
5814
|
author,
|
|
5789
5815
|
formatTime
|
|
5790
5816
|
}) => {
|
|
5791
|
-
const [draft, setDraft] = (0,
|
|
5817
|
+
const [draft, setDraft] = (0, import_react42.useState)("");
|
|
5792
5818
|
const isDraft = thread.body === "";
|
|
5793
5819
|
const quote = thread.anchor?.quote ?? thread.lastQuote ?? "";
|
|
5794
5820
|
const live = editor && !editor.isDestroyed ? editor : null;
|
|
@@ -6002,13 +6028,13 @@ var CommentButton = ({
|
|
|
6002
6028
|
);
|
|
6003
6029
|
|
|
6004
6030
|
// src/review/useDocumentCompare.ts
|
|
6005
|
-
var
|
|
6031
|
+
var import_react43 = require("react");
|
|
6006
6032
|
var import_editor14 = require("@pixerate/editor");
|
|
6007
6033
|
function useDocumentCompare(editor, options) {
|
|
6008
|
-
const [summary, setSummary] = (0,
|
|
6009
|
-
const defaults = (0,
|
|
6034
|
+
const [summary, setSummary] = (0, import_react43.useState)(null);
|
|
6035
|
+
const defaults = (0, import_react43.useRef)(options);
|
|
6010
6036
|
defaults.current = options;
|
|
6011
|
-
const compare = (0,
|
|
6037
|
+
const compare = (0, import_react43.useCallback)(
|
|
6012
6038
|
(original, revised, overrides) => {
|
|
6013
6039
|
if (!editor || editor.isDestroyed) return null;
|
|
6014
6040
|
const result = (0, import_editor14.applyDocumentComparison)(editor, original, revised, {
|
|
@@ -6020,8 +6046,8 @@ function useDocumentCompare(editor, options) {
|
|
|
6020
6046
|
},
|
|
6021
6047
|
[editor]
|
|
6022
6048
|
);
|
|
6023
|
-
const clear = (0,
|
|
6024
|
-
return (0,
|
|
6049
|
+
const clear = (0, import_react43.useCallback)(() => setSummary(null), []);
|
|
6050
|
+
return (0, import_react43.useMemo)(() => ({ summary, compare, clear }), [summary, compare, clear]);
|
|
6025
6051
|
}
|
|
6026
6052
|
|
|
6027
6053
|
// src/review/TrackedChangesList.tsx
|
|
@@ -6072,12 +6098,12 @@ var TrackedChangesList = ({
|
|
|
6072
6098
|
};
|
|
6073
6099
|
|
|
6074
6100
|
// src/commands/useCommandPalette.ts
|
|
6075
|
-
var
|
|
6101
|
+
var import_react44 = require("react");
|
|
6076
6102
|
var import_commands2 = require("@pixerate/editor/commands");
|
|
6077
6103
|
function useCommandPalette(registry, options = {}) {
|
|
6078
|
-
const optionsRef = (0,
|
|
6104
|
+
const optionsRef = (0, import_react44.useRef)(options);
|
|
6079
6105
|
optionsRef.current = options;
|
|
6080
|
-
const controller = (0,
|
|
6106
|
+
const controller = (0, import_react44.useMemo)(
|
|
6081
6107
|
() => (0, import_commands2.createCommandPaletteController)(registry, {
|
|
6082
6108
|
context: () => {
|
|
6083
6109
|
const c = optionsRef.current.context;
|
|
@@ -6098,9 +6124,9 @@ function useCommandPalette(registry, options = {}) {
|
|
|
6098
6124
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6099
6125
|
[registry]
|
|
6100
6126
|
);
|
|
6101
|
-
const state = (0,
|
|
6127
|
+
const state = (0, import_react44.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
|
|
6102
6128
|
const { hotkey, hotkeyTarget } = options;
|
|
6103
|
-
(0,
|
|
6129
|
+
(0, import_react44.useEffect)(() => {
|
|
6104
6130
|
if (!hotkey) return;
|
|
6105
6131
|
const target = hotkeyTarget ?? (typeof window !== "undefined" ? window : null);
|
|
6106
6132
|
if (!target) return;
|
|
@@ -6128,13 +6154,13 @@ function useCommandPalette(registry, options = {}) {
|
|
|
6128
6154
|
}
|
|
6129
6155
|
|
|
6130
6156
|
// src/commands/CommandPalette.tsx
|
|
6131
|
-
var
|
|
6157
|
+
var import_react45 = __toESM(require("react"), 1);
|
|
6132
6158
|
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
6133
6159
|
function HighlightedLabel({ item }) {
|
|
6134
6160
|
if (item.labelIndices.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children: item.label });
|
|
6135
6161
|
const marked = new Set(item.labelIndices);
|
|
6136
6162
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children: Array.from(item.label).map(
|
|
6137
|
-
(ch, i) => marked.has(i) ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "font-semibold text-foreground", "data-match": "", children: ch }, i) : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
6163
|
+
(ch, i) => marked.has(i) ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "font-semibold text-foreground", "data-match": "", children: ch }, i) : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_react45.default.Fragment, { children: ch }, i)
|
|
6138
6164
|
) });
|
|
6139
6165
|
}
|
|
6140
6166
|
var CommandPalette = ({
|
|
@@ -6143,16 +6169,16 @@ var CommandPalette = ({
|
|
|
6143
6169
|
emptyMessage = "No matching commands",
|
|
6144
6170
|
className = ""
|
|
6145
6171
|
}) => {
|
|
6146
|
-
const inputRef = (0,
|
|
6147
|
-
const listRef = (0,
|
|
6148
|
-
const baseId = (0,
|
|
6172
|
+
const inputRef = (0, import_react45.useRef)(null);
|
|
6173
|
+
const listRef = (0, import_react45.useRef)(null);
|
|
6174
|
+
const baseId = (0, import_react45.useId)();
|
|
6149
6175
|
const listId = `${baseId}-list`;
|
|
6150
6176
|
const optionId = (index) => `${baseId}-option-${index}`;
|
|
6151
6177
|
const { open, query, items, activeIndex } = palette;
|
|
6152
|
-
(0,
|
|
6178
|
+
(0, import_react45.useEffect)(() => {
|
|
6153
6179
|
if (open) inputRef.current?.focus();
|
|
6154
6180
|
}, [open]);
|
|
6155
|
-
(0,
|
|
6181
|
+
(0, import_react45.useEffect)(() => {
|
|
6156
6182
|
if (!open) return;
|
|
6157
6183
|
const active = listRef.current?.querySelector('[aria-selected="true"]');
|
|
6158
6184
|
active?.scrollIntoView?.({ block: "nearest" });
|
|
@@ -6228,12 +6254,12 @@ var CommandPalette = ({
|
|
|
6228
6254
|
};
|
|
6229
6255
|
|
|
6230
6256
|
// src/commands/useCommandShortcuts.ts
|
|
6231
|
-
var
|
|
6257
|
+
var import_react46 = require("react");
|
|
6232
6258
|
function useCommandShortcuts(registry, options = {}) {
|
|
6233
|
-
const optionsRef = (0,
|
|
6259
|
+
const optionsRef = (0, import_react46.useRef)(options);
|
|
6234
6260
|
optionsRef.current = options;
|
|
6235
6261
|
const { enabled = true, target } = options;
|
|
6236
|
-
(0,
|
|
6262
|
+
(0, import_react46.useEffect)(() => {
|
|
6237
6263
|
if (!registry || !enabled) return;
|
|
6238
6264
|
const eventTarget = target ?? (typeof window !== "undefined" ? window : null);
|
|
6239
6265
|
if (!eventTarget) return;
|
|
@@ -6251,14 +6277,14 @@ function useCommandShortcuts(registry, options = {}) {
|
|
|
6251
6277
|
}, [registry, enabled, target]);
|
|
6252
6278
|
}
|
|
6253
6279
|
function useRegisterCommands(registry, specs) {
|
|
6254
|
-
(0,
|
|
6280
|
+
(0, import_react46.useEffect)(() => {
|
|
6255
6281
|
if (!registry || !specs || specs.length === 0) return;
|
|
6256
6282
|
return registry.register(specs);
|
|
6257
6283
|
}, [registry, specs]);
|
|
6258
6284
|
}
|
|
6259
6285
|
|
|
6260
6286
|
// src/persistence/useAutosave.ts
|
|
6261
|
-
var
|
|
6287
|
+
var import_react47 = require("react");
|
|
6262
6288
|
var import_persistence = require("@pixerate/editor/persistence");
|
|
6263
6289
|
var IDLE = {
|
|
6264
6290
|
status: "idle",
|
|
@@ -6269,18 +6295,18 @@ var IDLE = {
|
|
|
6269
6295
|
ready: false
|
|
6270
6296
|
};
|
|
6271
6297
|
function useAutosave(options) {
|
|
6272
|
-
const optionsRef = (0,
|
|
6298
|
+
const optionsRef = (0, import_react47.useRef)(options);
|
|
6273
6299
|
optionsRef.current = options;
|
|
6274
6300
|
const { storage, key, history, dirty } = options;
|
|
6275
6301
|
const recover = options.recover !== false;
|
|
6276
6302
|
const flushOnHide = options.flushOnHide !== false;
|
|
6277
6303
|
const ready = options.ready !== false;
|
|
6278
|
-
const [controller, setController] = (0,
|
|
6279
|
-
const [status, setStatus] = (0,
|
|
6280
|
-
const [recovery, setRecovery] = (0,
|
|
6281
|
-
const [pendingRecovery, setPendingRecovery] = (0,
|
|
6282
|
-
const revisionsRef = (0,
|
|
6283
|
-
(0,
|
|
6304
|
+
const [controller, setController] = (0, import_react47.useState)(null);
|
|
6305
|
+
const [status, setStatus] = (0, import_react47.useState)(IDLE);
|
|
6306
|
+
const [recovery, setRecovery] = (0, import_react47.useState)(null);
|
|
6307
|
+
const [pendingRecovery, setPendingRecovery] = (0, import_react47.useState)(recover);
|
|
6308
|
+
const revisionsRef = (0, import_react47.useRef)(null);
|
|
6309
|
+
(0, import_react47.useEffect)(() => {
|
|
6284
6310
|
const revisions = (0, import_persistence.createRevisionTracker)({ history, dirty });
|
|
6285
6311
|
const o = optionsRef.current;
|
|
6286
6312
|
const instance = (0, import_persistence.createAutosaveController)({
|
|
@@ -6323,10 +6349,10 @@ function useAutosave(options) {
|
|
|
6323
6349
|
if (revisionsRef.current === revisions) revisionsRef.current = null;
|
|
6324
6350
|
};
|
|
6325
6351
|
}, [storage, key, history, dirty, recover]);
|
|
6326
|
-
(0,
|
|
6352
|
+
(0, import_react47.useEffect)(() => {
|
|
6327
6353
|
if (controller && ready && !pendingRecovery) controller.ready();
|
|
6328
6354
|
}, [controller, ready, pendingRecovery]);
|
|
6329
|
-
(0,
|
|
6355
|
+
(0, import_react47.useEffect)(() => {
|
|
6330
6356
|
if (!controller || !flushOnHide || typeof window === "undefined") return;
|
|
6331
6357
|
const flush = () => void controller.flushNow();
|
|
6332
6358
|
const onVisibility = () => {
|
|
@@ -6339,25 +6365,25 @@ function useAutosave(options) {
|
|
|
6339
6365
|
document.removeEventListener("visibilitychange", onVisibility);
|
|
6340
6366
|
};
|
|
6341
6367
|
}, [controller, flushOnHide]);
|
|
6342
|
-
const restore = (0,
|
|
6368
|
+
const restore = (0, import_react47.useCallback)(() => {
|
|
6343
6369
|
const snapshot = recovery?.snapshot;
|
|
6344
6370
|
setRecovery(null);
|
|
6345
6371
|
setPendingRecovery(false);
|
|
6346
6372
|
return snapshot;
|
|
6347
6373
|
}, [recovery]);
|
|
6348
|
-
const discard = (0,
|
|
6374
|
+
const discard = (0, import_react47.useCallback)(async () => {
|
|
6349
6375
|
if (controller) await controller.discardRecovery();
|
|
6350
6376
|
setRecovery(null);
|
|
6351
6377
|
setPendingRecovery(false);
|
|
6352
6378
|
}, [controller]);
|
|
6353
|
-
const flushNow = (0,
|
|
6379
|
+
const flushNow = (0, import_react47.useCallback)(async () => {
|
|
6354
6380
|
await controller?.flushNow();
|
|
6355
6381
|
}, [controller]);
|
|
6356
|
-
const markClean = (0,
|
|
6382
|
+
const markClean = (0, import_react47.useCallback)(async () => {
|
|
6357
6383
|
revisionsRef.current?.markSaved();
|
|
6358
6384
|
await controller?.markClean();
|
|
6359
6385
|
}, [controller]);
|
|
6360
|
-
const notifyChange = (0,
|
|
6386
|
+
const notifyChange = (0, import_react47.useCallback)(() => revisionsRef.current?.bump(), []);
|
|
6361
6387
|
return { status, recovery, pendingRecovery, restore, discard, flushNow, markClean, notifyChange, controller };
|
|
6362
6388
|
}
|
|
6363
6389
|
|
|
@@ -6417,17 +6443,17 @@ var RecoveryPrompt = ({
|
|
|
6417
6443
|
};
|
|
6418
6444
|
|
|
6419
6445
|
// src/generation/useGenerationPlan.ts
|
|
6420
|
-
var
|
|
6446
|
+
var import_react48 = require("react");
|
|
6421
6447
|
var import_generation = require("@pixerate/editor/generation");
|
|
6422
6448
|
function useGenerationPlan(request, capabilities, options = {}) {
|
|
6423
6449
|
const key = JSON.stringify([request, capabilities, options]);
|
|
6424
|
-
return (0,
|
|
6450
|
+
return (0, import_react48.useMemo)(() => (0, import_generation.planGenerationRequest)(request, capabilities, options), [key]);
|
|
6425
6451
|
}
|
|
6426
6452
|
function useJobProgress(options) {
|
|
6427
6453
|
const { startedAt, expectedMs, done, now, intervalMs = 1e3 } = options;
|
|
6428
|
-
const [tick, setTick] = (0,
|
|
6454
|
+
const [tick, setTick] = (0, import_react48.useState)(() => Date.now());
|
|
6429
6455
|
const ticking = !done && now === void 0;
|
|
6430
|
-
(0,
|
|
6456
|
+
(0, import_react48.useEffect)(() => {
|
|
6431
6457
|
if (!ticking) return;
|
|
6432
6458
|
setTick(Date.now());
|
|
6433
6459
|
const id = setInterval(() => setTick(Date.now()), Math.max(16, intervalMs));
|
|
@@ -6437,7 +6463,7 @@ function useJobProgress(options) {
|
|
|
6437
6463
|
}
|
|
6438
6464
|
|
|
6439
6465
|
// src/generation/GenerationSettings.tsx
|
|
6440
|
-
var
|
|
6466
|
+
var import_react49 = require("react");
|
|
6441
6467
|
var import_generation2 = require("@pixerate/editor/generation");
|
|
6442
6468
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
6443
6469
|
var inputClass2 = "w-full rounded-md border border-border bg-background px-2 py-1 text-sm outline-none focus:ring-1 focus:ring-ring";
|
|
@@ -6520,8 +6546,8 @@ var GenerationSettings = ({
|
|
|
6520
6546
|
renderReference,
|
|
6521
6547
|
className = ""
|
|
6522
6548
|
}) => {
|
|
6523
|
-
const baseId = (0,
|
|
6524
|
-
const controls = (0,
|
|
6549
|
+
const baseId = (0, import_react49.useId)();
|
|
6550
|
+
const controls = (0, import_react49.useMemo)(() => (0, import_generation2.getGenerationControls)(capabilities), [capabilities]);
|
|
6525
6551
|
const computed = useGenerationPlan(value, capabilities, { strategy });
|
|
6526
6552
|
const plan = planProp ?? computed;
|
|
6527
6553
|
const slots = (0, import_generation2.getReferenceSlots)(capabilities, value);
|
|
@@ -6616,7 +6642,7 @@ var JobProgress = ({ title, className = "", ...options }) => {
|
|
|
6616
6642
|
};
|
|
6617
6643
|
|
|
6618
6644
|
// src/generation/AssetMentionChips.tsx
|
|
6619
|
-
var
|
|
6645
|
+
var import_react50 = require("react");
|
|
6620
6646
|
var import_generation3 = require("@pixerate/editor/generation");
|
|
6621
6647
|
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
6622
6648
|
var AssetMentionChips = ({
|
|
@@ -6628,14 +6654,14 @@ var AssetMentionChips = ({
|
|
|
6628
6654
|
renderAsset,
|
|
6629
6655
|
className = ""
|
|
6630
6656
|
}) => {
|
|
6631
|
-
const [open, setOpen] = (0,
|
|
6632
|
-
const rootRef = (0,
|
|
6633
|
-
const chips = (0,
|
|
6657
|
+
const [open, setOpen] = (0, import_react50.useState)(null);
|
|
6658
|
+
const rootRef = (0, import_react50.useRef)(null);
|
|
6659
|
+
const chips = (0, import_react50.useMemo)(
|
|
6634
6660
|
() => (0, import_generation3.describeAssetMentions)((0, import_generation3.findTextMentions)(content), assets, capabilities),
|
|
6635
6661
|
[content, assets, capabilities]
|
|
6636
6662
|
);
|
|
6637
6663
|
const options = roles ?? (capabilities ? (0, import_generation3.getAssetRoleOptions)(capabilities) : (0, import_generation3.defaultAssetRoleOptions)());
|
|
6638
|
-
(0,
|
|
6664
|
+
(0, import_react50.useEffect)(() => {
|
|
6639
6665
|
if (open === null) return;
|
|
6640
6666
|
const onPointer = (event) => {
|
|
6641
6667
|
if (!rootRef.current?.contains(event.target)) setOpen(null);
|
|
@@ -6730,15 +6756,15 @@ var AssetMentionChips = ({
|
|
|
6730
6756
|
};
|
|
6731
6757
|
|
|
6732
6758
|
// src/generation/GenerationHistory.tsx
|
|
6733
|
-
var
|
|
6759
|
+
var import_react51 = require("react");
|
|
6734
6760
|
var import_generation4 = require("@pixerate/editor/generation");
|
|
6735
6761
|
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
6736
6762
|
function useGenerationRecords(store, filter) {
|
|
6737
|
-
const [records, setRecords] = (0,
|
|
6738
|
-
const [loading, setLoading] = (0,
|
|
6739
|
-
const [error, setError] = (0,
|
|
6763
|
+
const [records, setRecords] = (0, import_react51.useState)([]);
|
|
6764
|
+
const [loading, setLoading] = (0, import_react51.useState)(!!store);
|
|
6765
|
+
const [error, setError] = (0, import_react51.useState)(null);
|
|
6740
6766
|
const filterKey = (0, import_generation4.stableStringify)(filter ?? {});
|
|
6741
|
-
const refresh = (0,
|
|
6767
|
+
const refresh = (0, import_react51.useCallback)(async () => {
|
|
6742
6768
|
if (!store) {
|
|
6743
6769
|
setRecords([]);
|
|
6744
6770
|
setLoading(false);
|
|
@@ -6755,7 +6781,7 @@ function useGenerationRecords(store, filter) {
|
|
|
6755
6781
|
setLoading(false);
|
|
6756
6782
|
}
|
|
6757
6783
|
}, [store, filterKey]);
|
|
6758
|
-
(0,
|
|
6784
|
+
(0, import_react51.useEffect)(() => {
|
|
6759
6785
|
void refresh();
|
|
6760
6786
|
if (!store) return;
|
|
6761
6787
|
return store.subscribe(() => void refresh());
|
|
@@ -6781,15 +6807,15 @@ var GenerationHistory = ({
|
|
|
6781
6807
|
emptyText = "No generations yet.",
|
|
6782
6808
|
className = ""
|
|
6783
6809
|
}) => {
|
|
6784
|
-
const [innerMode, setInnerMode] = (0,
|
|
6810
|
+
const [innerMode, setInnerMode] = (0, import_react51.useState)("exact");
|
|
6785
6811
|
const mode = modeProp ?? innerMode;
|
|
6786
6812
|
const setMode = (next) => {
|
|
6787
6813
|
if (modeProp === void 0) setInnerMode(next);
|
|
6788
6814
|
onModeChange?.(next);
|
|
6789
6815
|
};
|
|
6790
|
-
const options = (0,
|
|
6791
|
-
const results = (0,
|
|
6792
|
-
const models = (0,
|
|
6816
|
+
const options = (0, import_react51.useMemo)(() => ({ templates, capabilities, assets, mode }), [templates, capabilities, assets, mode]);
|
|
6817
|
+
const results = (0, import_react51.useMemo)(() => records.map((record) => (0, import_generation4.recreateRequest)(record, options)), [records, options]);
|
|
6818
|
+
const models = (0, import_react51.useMemo)(
|
|
6793
6819
|
() => capabilities ? Array.isArray(capabilities) ? capabilities : [capabilities] : [],
|
|
6794
6820
|
[capabilities]
|
|
6795
6821
|
);
|
|
@@ -6900,19 +6926,19 @@ var GenerationHistory = ({
|
|
|
6900
6926
|
};
|
|
6901
6927
|
|
|
6902
6928
|
// src/find-replace/useFindReplace.ts
|
|
6903
|
-
var
|
|
6929
|
+
var import_react52 = require("react");
|
|
6904
6930
|
var import_editor16 = require("@pixerate/editor");
|
|
6905
6931
|
var noopUnsubscribe2 = () => {
|
|
6906
6932
|
};
|
|
6907
6933
|
function useFindReplace(editor) {
|
|
6908
6934
|
const store = (0, import_editor16.getFindReplaceStore)(editor ?? null);
|
|
6909
|
-
const subscribe = (0,
|
|
6935
|
+
const subscribe = (0, import_react52.useCallback)(
|
|
6910
6936
|
(onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe2,
|
|
6911
6937
|
[store]
|
|
6912
6938
|
);
|
|
6913
6939
|
const getSnapshot = () => store?.getSnapshot() ?? import_editor16.EMPTY_FIND_REPLACE_SNAPSHOT;
|
|
6914
|
-
const snapshot = (0,
|
|
6915
|
-
return (0,
|
|
6940
|
+
const snapshot = (0, import_react52.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
6941
|
+
return (0, import_react52.useMemo)(() => {
|
|
6916
6942
|
const run = (fn) => {
|
|
6917
6943
|
if (editor && !editor.isDestroyed && store) fn(editor);
|
|
6918
6944
|
};
|
|
@@ -6936,7 +6962,7 @@ function useFindReplace(editor) {
|
|
|
6936
6962
|
}
|
|
6937
6963
|
|
|
6938
6964
|
// src/find-replace/FindReplaceBar.tsx
|
|
6939
|
-
var
|
|
6965
|
+
var import_react53 = require("react");
|
|
6940
6966
|
var import_editor17 = require("@pixerate/editor");
|
|
6941
6967
|
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
6942
6968
|
var inputClass3 = "min-w-0 flex-1 rounded border border-input bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring";
|
|
@@ -6951,10 +6977,10 @@ var FindReplaceBar = ({
|
|
|
6951
6977
|
onClose
|
|
6952
6978
|
}) => {
|
|
6953
6979
|
const find = useFindReplace(editor);
|
|
6954
|
-
const findInput = (0,
|
|
6955
|
-
const [moreOpen, setMoreOpen] = (0,
|
|
6980
|
+
const findInput = (0, import_react53.useRef)(null);
|
|
6981
|
+
const [moreOpen, setMoreOpen] = (0, import_react53.useState)(false);
|
|
6956
6982
|
const visible = find.available && (alwaysOpen || find.open);
|
|
6957
|
-
(0,
|
|
6983
|
+
(0, import_react53.useEffect)(() => {
|
|
6958
6984
|
if (!visible || find.focusRequest === 0) return;
|
|
6959
6985
|
findInput.current?.focus();
|
|
6960
6986
|
findInput.current?.select();
|
|
@@ -7098,12 +7124,12 @@ var FindReplaceBar = ({
|
|
|
7098
7124
|
};
|
|
7099
7125
|
|
|
7100
7126
|
// src/tables/useTableMenu.ts
|
|
7101
|
-
var
|
|
7127
|
+
var import_react54 = require("react");
|
|
7102
7128
|
var import_editor18 = require("@pixerate/editor");
|
|
7103
7129
|
function useTableMenu(editor) {
|
|
7104
|
-
const store = (0,
|
|
7105
|
-
const snapshot = (0,
|
|
7106
|
-
return (0,
|
|
7130
|
+
const store = (0, import_react54.useMemo)(() => (0, import_editor18.createTableStore)(editor), [editor]);
|
|
7131
|
+
const snapshot = (0, import_react54.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
7132
|
+
return (0, import_react54.useMemo)(
|
|
7107
7133
|
() => ({
|
|
7108
7134
|
...snapshot,
|
|
7109
7135
|
run: (action, params) => (0, import_editor18.runTableAction)(editor, action, params, { focus: true }),
|
|
@@ -7114,7 +7140,7 @@ function useTableMenu(editor) {
|
|
|
7114
7140
|
}
|
|
7115
7141
|
|
|
7116
7142
|
// src/tables/TableToolbar.tsx
|
|
7117
|
-
var
|
|
7143
|
+
var import_react55 = __toESM(require("react"), 1);
|
|
7118
7144
|
var import_editor19 = require("@pixerate/editor");
|
|
7119
7145
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
7120
7146
|
var keepSelection2 = (event) => event.preventDefault();
|
|
@@ -7135,7 +7161,7 @@ var TableToolbar = ({
|
|
|
7135
7161
|
const enabled = status === true;
|
|
7136
7162
|
const active = item.active?.(table);
|
|
7137
7163
|
const separator = index > 0 && items[index - 1].group !== item.group;
|
|
7138
|
-
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
|
|
7164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_react55.default.Fragment, { children: [
|
|
7139
7165
|
separator && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: separatorClassName, "aria-hidden": "true" }),
|
|
7140
7166
|
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
|
7141
7167
|
"button",
|
|
@@ -7159,7 +7185,7 @@ var TableToolbar = ({
|
|
|
7159
7185
|
};
|
|
7160
7186
|
|
|
7161
7187
|
// src/tables/InsertTableGrid.tsx
|
|
7162
|
-
var
|
|
7188
|
+
var import_react56 = require("react");
|
|
7163
7189
|
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
7164
7190
|
var keepSelection3 = (event) => event.preventDefault();
|
|
7165
7191
|
var InsertTableGrid = ({
|
|
@@ -7173,7 +7199,7 @@ var InsertTableGrid = ({
|
|
|
7173
7199
|
onInsert
|
|
7174
7200
|
}) => {
|
|
7175
7201
|
const table = useTableMenu(editor);
|
|
7176
|
-
const [hover, setHover] = (0,
|
|
7202
|
+
const [hover, setHover] = (0, import_react56.useState)(null);
|
|
7177
7203
|
const status = table.actions.insertTable;
|
|
7178
7204
|
const disabled = !editor || !status.enabled;
|
|
7179
7205
|
const insert = (size) => {
|
|
@@ -7240,14 +7266,14 @@ var TableBubbleMenu = ({
|
|
|
7240
7266
|
var import_client = require("react-dom/client");
|
|
7241
7267
|
|
|
7242
7268
|
// src/chart/ChartCanvas.tsx
|
|
7243
|
-
var
|
|
7269
|
+
var import_react58 = require("react");
|
|
7244
7270
|
var import_chart2 = require("@pixerate/editor/chart");
|
|
7245
7271
|
|
|
7246
7272
|
// src/chart/useChartEditor.ts
|
|
7247
|
-
var
|
|
7273
|
+
var import_react57 = require("react");
|
|
7248
7274
|
var import_chart = require("@pixerate/editor/chart");
|
|
7249
7275
|
function useChartState(controller) {
|
|
7250
|
-
return (0,
|
|
7276
|
+
return (0, import_react57.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
|
|
7251
7277
|
}
|
|
7252
7278
|
|
|
7253
7279
|
// src/chart/ChartCanvas.tsx
|
|
@@ -7299,7 +7325,7 @@ function renderChartMark(mark, fontFamily, interactive) {
|
|
|
7299
7325
|
}
|
|
7300
7326
|
}
|
|
7301
7327
|
function ChartPresenceLayer({ presence }) {
|
|
7302
|
-
const { actors } = (0,
|
|
7328
|
+
const { actors } = (0, import_react58.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
|
|
7303
7329
|
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("g", { "data-chart-presence": "", pointerEvents: "none", children: actors.map((a) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("g", { transform: `translate(${a.x} ${a.y})`, "data-actor": a.id, children: [
|
|
7304
7330
|
/* @__PURE__ */ (0, import_jsx_runtime38.jsx)("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 }, transform: a.pressed ? "scale(0.9)" : void 0 }),
|
|
7305
7331
|
/* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("g", { transform: "translate(13 16)", children: [
|
|
@@ -7310,12 +7336,12 @@ function ChartPresenceLayer({ presence }) {
|
|
|
7310
7336
|
}
|
|
7311
7337
|
function ChartCanvas({ controller, width = 640, height = 400, responsive = true, theme, editable = true, measureText, emptyMessage, className, presence, sceneRef }) {
|
|
7312
7338
|
const state = useChartState(controller);
|
|
7313
|
-
const wrapper = (0,
|
|
7314
|
-
const svg = (0,
|
|
7315
|
-
const drag = (0,
|
|
7316
|
-
const [measured, setMeasured] = (0,
|
|
7317
|
-
const [frozen, setFrozen] = (0,
|
|
7318
|
-
(0,
|
|
7339
|
+
const wrapper = (0, import_react58.useRef)(null);
|
|
7340
|
+
const svg = (0, import_react58.useRef)(null);
|
|
7341
|
+
const drag = (0, import_react58.useRef)(null);
|
|
7342
|
+
const [measured, setMeasured] = (0, import_react58.useState)(null);
|
|
7343
|
+
const [frozen, setFrozen] = (0, import_react58.useState)(null);
|
|
7344
|
+
(0, import_react58.useEffect)(() => {
|
|
7319
7345
|
const el = wrapper.current;
|
|
7320
7346
|
if (!responsive || !el || typeof ResizeObserver === "undefined") return;
|
|
7321
7347
|
const observer = new ResizeObserver(([entry]) => {
|
|
@@ -7326,8 +7352,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
7326
7352
|
return () => observer.disconnect();
|
|
7327
7353
|
}, [responsive]);
|
|
7328
7354
|
const sceneWidth = responsive && measured || width;
|
|
7329
|
-
const fullTheme = (0,
|
|
7330
|
-
const scene = (0,
|
|
7355
|
+
const fullTheme = (0, import_react58.useMemo)(() => ({ ...import_chart2.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
|
|
7356
|
+
const scene = (0, import_react58.useMemo)(
|
|
7331
7357
|
() => (0, import_chart2.layoutChart)(state.spec, {
|
|
7332
7358
|
width: sceneWidth,
|
|
7333
7359
|
height,
|
|
@@ -7343,8 +7369,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
7343
7369
|
[state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
|
|
7344
7370
|
);
|
|
7345
7371
|
if (sceneRef) sceneRef.current = scene;
|
|
7346
|
-
const byKey = (0,
|
|
7347
|
-
(0,
|
|
7372
|
+
const byKey = (0, import_react58.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
|
|
7373
|
+
(0, import_react58.useEffect)(() => () => drag.current?.end(), []);
|
|
7348
7374
|
const scenePoint = (e) => (0, import_chart2.chartClientToScene)(scene, svg.current.getBoundingClientRect(), e.clientX, e.clientY);
|
|
7349
7375
|
const onPointerDown = (e) => {
|
|
7350
7376
|
if (!editable || e.button !== 0) return;
|
|
@@ -7402,7 +7428,7 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
7402
7428
|
}
|
|
7403
7429
|
|
|
7404
7430
|
// src/chart/ChartDataGrid.tsx
|
|
7405
|
-
var
|
|
7431
|
+
var import_react59 = require("react");
|
|
7406
7432
|
var import_chart3 = require("@pixerate/editor/chart");
|
|
7407
7433
|
|
|
7408
7434
|
// src/chart/styles.ts
|
|
@@ -7417,9 +7443,9 @@ var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right t
|
|
|
7417
7443
|
// src/chart/ChartDataGrid.tsx
|
|
7418
7444
|
var import_jsx_runtime39 = require("react/jsx-runtime");
|
|
7419
7445
|
function ChartCommitInput({ value, onCommit, onKeyDown, onBlur, ...rest }) {
|
|
7420
|
-
const [draft, setDraft] = (0,
|
|
7421
|
-
const typing = (0,
|
|
7422
|
-
(0,
|
|
7446
|
+
const [draft, setDraft] = (0, import_react59.useState)(value);
|
|
7447
|
+
const typing = (0, import_react59.useRef)(false);
|
|
7448
|
+
(0, import_react59.useEffect)(() => {
|
|
7423
7449
|
if (!typing.current) setDraft(value);
|
|
7424
7450
|
}, [value]);
|
|
7425
7451
|
const commit = () => {
|
|
@@ -7555,7 +7581,7 @@ function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = fal
|
|
|
7555
7581
|
}
|
|
7556
7582
|
|
|
7557
7583
|
// src/chart/ChartInspector.tsx
|
|
7558
|
-
var
|
|
7584
|
+
var import_react60 = require("react");
|
|
7559
7585
|
var import_chart4 = require("@pixerate/editor/chart");
|
|
7560
7586
|
var import_jsx_runtime40 = require("react/jsx-runtime");
|
|
7561
7587
|
var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
@@ -7574,7 +7600,7 @@ function Toggle({ label, checked, onChange, name }) {
|
|
|
7574
7600
|
function Select({ id, value, options, onChange, name, labels }) {
|
|
7575
7601
|
return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("select", { id, className: chartInputClass, value, "data-option": name, onChange: (e) => onChange(e.currentTarget.value), children: options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: o, children: labels?.[o] ?? cap(o) }, o)) });
|
|
7576
7602
|
}
|
|
7577
|
-
function AxisSection({ controller, axis, value, idBase, horizontal, numeric = false }) {
|
|
7603
|
+
function AxisSection({ controller, axis, value, idBase, horizontal, numeric = false, scales = false }) {
|
|
7578
7604
|
const set = (patch) => controller.setAxis(axis, patch);
|
|
7579
7605
|
const setFormat = (patch) => set({ format: { ...value.format, ...patch } });
|
|
7580
7606
|
const bound = (key2) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
@@ -7607,9 +7633,22 @@ function AxisSection({ controller, axis, value, idBase, horizontal, numeric = fa
|
|
|
7607
7633
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Title", htmlFor: `${idBase}-${axis}-title`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${idBase}-${axis}-title`, value: value.title, "data-option": `${axis}Axis.title`, className: chartInputClass, onCommit: (title) => void set({ title }) }) }),
|
|
7608
7634
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
7609
7635
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Grid lines", name: `${key}.gridlines`, checked: value.gridlines, onChange: (gridlines) => set({ gridlines }) }),
|
|
7610
|
-
axis === "x" && !numeric && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Dates", name: "xAxis.kind", checked: value.kind === "date", onChange: (dates) => set({ kind: dates ? "date" : void 0 }) })
|
|
7636
|
+
axis === "x" && !numeric && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Dates", name: "xAxis.kind", checked: value.kind === "date", onChange: (dates) => set({ kind: dates ? "date" : void 0 }) }),
|
|
7637
|
+
scales && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Reverse", name: `${key}.reverse`, checked: !!value.reverse, onChange: (reverse) => set({ reverse }) }),
|
|
7638
|
+
scales && valueAxis && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Log scale", name: `${key}.scale`, checked: value.scale === "log", onChange: (log) => set({ scale: log ? "log" : "linear" }) })
|
|
7611
7639
|
] }),
|
|
7612
|
-
valueAxis && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "
|
|
7640
|
+
scales && valueAxis && value.scale === "log" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Log base", htmlFor: `${idBase}-${axis}-log-base`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7641
|
+
ChartCommitInput,
|
|
7642
|
+
{
|
|
7643
|
+
id: `${idBase}-${axis}-log-base`,
|
|
7644
|
+
value: String(value.logBase ?? 10),
|
|
7645
|
+
inputMode: "decimal",
|
|
7646
|
+
"data-option": `${key}.logBase`,
|
|
7647
|
+
className: chartInputClass,
|
|
7648
|
+
onCommit: (text) => set({ logBase: text.trim() === "" ? void 0 : Number(text) }).ok
|
|
7649
|
+
}
|
|
7650
|
+
) }),
|
|
7651
|
+
valueAxis && value.scale !== "log" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Step", htmlFor: `${idBase}-${axis}-step`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7613
7652
|
ChartCommitInput,
|
|
7614
7653
|
{
|
|
7615
7654
|
id: `${idBase}-${axis}-step`,
|
|
@@ -7667,9 +7706,47 @@ function AxisSection({ controller, axis, value, idBase, horizontal, numeric = fa
|
|
|
7667
7706
|
] })
|
|
7668
7707
|
] });
|
|
7669
7708
|
}
|
|
7709
|
+
function ErrorBarFields({ controller, series, which, idBase }) {
|
|
7710
|
+
const bars = series[which];
|
|
7711
|
+
const key = `series.${which}`;
|
|
7712
|
+
const id = `${idBase}-${which}`;
|
|
7713
|
+
const values = which === "xErrorBars" ? series.x ?? [] : series.values;
|
|
7714
|
+
const set = (next) => controller.updateSeries(series.id, { [which]: next });
|
|
7715
|
+
const patch = (p) => bars && set({ ...bars, ...p });
|
|
7716
|
+
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "space-y-1.5", "data-section": which === "errorBars" ? "error-bars" : "x-error-bars", children: [
|
|
7717
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: which === "errorBars" ? "Error bars" : "X error bars", htmlFor: `${id}-type`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("select", { id: `${id}-type`, className: chartInputClass, value: bars?.type ?? "", "data-option": `${key}.type`, onChange: (e) => set((0, import_chart4.chartErrorBarsOfType)(e.currentTarget.value, bars, values)), children: [
|
|
7718
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: "", children: "None" }),
|
|
7719
|
+
import_chart4.CHART_ERROR_BAR_TYPES.map((t) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: t, children: import_chart4.CHART_ERROR_BAR_LABELS[t] }, t))
|
|
7720
|
+
] }) }),
|
|
7721
|
+
bars && (bars.type === "fixed" || bars.type === "percent" || bars.type === "stddev") && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: bars.type === "percent" ? "Percent" : bars.type === "stddev" ? "Deviations" : "Amount", htmlFor: `${id}-value`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${id}-value`, value: String(bars.value ?? (0, import_chart4.defaultChartErrorBarValue)(bars.type)), inputMode: "decimal", "data-option": `${key}.value`, className: chartInputClass, onCommit: (text) => !!patch({ value: text.trim() === "" ? void 0 : Number(text) })?.ok }) }),
|
|
7722
|
+
bars?.type === "custom" && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
|
|
7723
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Plus", htmlFor: `${id}-plus`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ChartCommitInput, { id: `${id}-plus`, value: (0, import_chart4.formatChartAmountList)(bars.plus), placeholder: "1, 2, -, 0.5", "data-option": `${key}.plus`, className: chartInputClass, onCommit: (text) => !!patch({ plus: (0, import_chart4.parseChartAmountList)(text) })?.ok }) }),
|
|
7724
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Field, { label: "Minus", htmlFor: `${id}-minus`, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
|
|
7725
|
+
ChartCommitInput,
|
|
7726
|
+
{
|
|
7727
|
+
id: `${id}-minus`,
|
|
7728
|
+
value: (0, import_chart4.formatChartAmountList)(bars.minus),
|
|
7729
|
+
placeholder: "Same as plus",
|
|
7730
|
+
"data-option": `${key}.minus`,
|
|
7731
|
+
className: chartInputClass,
|
|
7732
|
+
onCommit: (text) => {
|
|
7733
|
+
const next = { ...bars };
|
|
7734
|
+
if (text.trim()) next.minus = (0, import_chart4.parseChartAmountList)(text);
|
|
7735
|
+
else delete next.minus;
|
|
7736
|
+
return set(next).ok;
|
|
7737
|
+
}
|
|
7738
|
+
}
|
|
7739
|
+
) })
|
|
7740
|
+
] }),
|
|
7741
|
+
bars && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
7742
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("select", { className: `${chartInputClass} flex-1`, "aria-label": "Error bar direction", value: bars.direction ?? "both", "data-option": `${key}.direction`, onChange: (e) => patch({ direction: e.currentTarget.value }), children: import_chart4.CHART_ERROR_BAR_DIRECTIONS.map((d) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("option", { value: d, children: d === "both" ? "Both ways" : d === "plus" ? "Plus only" : "Minus only" }, d)) }),
|
|
7743
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Toggle, { label: "Caps", name: `${key}.cap`, checked: bars.cap !== false, onChange: (cap2) => patch({ cap: cap2 }) })
|
|
7744
|
+
] })
|
|
7745
|
+
] });
|
|
7746
|
+
}
|
|
7670
7747
|
function ChartInspector({ controller, sections, className }) {
|
|
7671
7748
|
const { spec, selectedSeries } = useChartState(controller);
|
|
7672
|
-
const idBase = (0,
|
|
7749
|
+
const idBase = (0, import_react60.useId)();
|
|
7673
7750
|
const show = (section) => !sections || sections.includes(section);
|
|
7674
7751
|
const cartesian = (0, import_chart4.isCartesianChart)(spec.type);
|
|
7675
7752
|
const family = (0, import_chart4.chartFamily)(spec);
|
|
@@ -7680,6 +7757,7 @@ function ChartInspector({ controller, sections, className }) {
|
|
|
7680
7757
|
const hasBars = cartesian && types.includes("bar");
|
|
7681
7758
|
const hasLines = cartesian && types.some((t) => t === "line" || t === "area");
|
|
7682
7759
|
const seriesIndex = selectedSeries ? spec.series.findIndex((s) => s.id === selectedSeries.id) : -1;
|
|
7760
|
+
const scales = family === "cartesian" || family === "xy";
|
|
7683
7761
|
return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: `space-y-3 text-xs ${className ?? ""}`, "data-chart-inspector": "", children: [
|
|
7684
7762
|
show("type") && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: chartSectionClass, "data-section": "type", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "grid grid-cols-3 gap-0.5 rounded-md bg-muted p-0.5", role: "radiogroup", "aria-label": "Chart type", children: import_chart4.CHART_TYPES.map((type) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", role: "radio", "aria-checked": spec.type === type, "data-chart-type": type, className: chartSegmentClass(spec.type === type), onClick: () => controller.setType(type), children: import_chart4.CHART_TYPE_LABELS[type] }, type)) }) }),
|
|
7685
7763
|
show("style") && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": "style", children: [
|
|
@@ -7750,9 +7828,9 @@ function ChartInspector({ controller, sections, className }) {
|
|
|
7750
7828
|
spec.legend.show && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "flex gap-0.5 rounded-md bg-muted p-0.5", children: import_chart4.CHART_LEGEND_POSITIONS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("button", { type: "button", "aria-pressed": spec.legend.position === p, "data-option": `legend.${p}`, className: chartSegmentClass(spec.legend.position === p), onClick: () => controller.setLegend({ position: p }), children: cap(p) }, p)) })
|
|
7751
7829
|
] }),
|
|
7752
7830
|
show("axes") && hasAxes && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, { children: [
|
|
7753
|
-
family !== "box" && family !== "histogram" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "x", value: spec.xAxis, idBase, horizontal: spec.orientation === "horizontal", numeric: family === "xy" }),
|
|
7754
|
-
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "y", value: spec.yAxis, idBase, horizontal: spec.orientation === "horizontal" }),
|
|
7755
|
-
usesSecondary && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "y2", value: spec.yAxis2, idBase, horizontal: spec.orientation === "horizontal" })
|
|
7831
|
+
family !== "box" && family !== "histogram" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "x", value: spec.xAxis, idBase, horizontal: spec.orientation === "horizontal", numeric: family === "xy", scales }),
|
|
7832
|
+
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "y", value: spec.yAxis, idBase, horizontal: spec.orientation === "horizontal", scales }),
|
|
7833
|
+
usesSecondary && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(AxisSection, { controller, axis: "y2", value: spec.yAxis2, idBase, horizontal: spec.orientation === "horizontal", scales })
|
|
7756
7834
|
] }),
|
|
7757
7835
|
show("series") && selectedSeries && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: chartSectionClass, "data-section": "series", "data-series-id": selectedSeries.id, children: [
|
|
7758
7836
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("h4", { className: "text-xs font-semibold text-foreground", children: "Series" }),
|
|
@@ -7801,6 +7879,8 @@ function ChartInspector({ controller, sections, className }) {
|
|
|
7801
7879
|
]
|
|
7802
7880
|
}
|
|
7803
7881
|
) }),
|
|
7882
|
+
scales && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ErrorBarFields, { controller, series: selectedSeries, which: "errorBars", idBase }),
|
|
7883
|
+
family === "xy" && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ErrorBarFields, { controller, series: selectedSeries, which: "xErrorBars", idBase }),
|
|
7804
7884
|
(0, import_chart4.chartSupportsTrendlines)(spec.type, spec.stacking) && /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "space-y-1", "data-section": "trendlines", children: [
|
|
7805
7885
|
(selectedSeries.trendlines ?? []).map((t, i) => /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "flex items-center gap-1", "data-trendline": i, children: [
|
|
7806
7886
|
/* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "flex-1 truncate text-muted-foreground", children: (0, import_chart4.chartTrendlineName)(t, selectedSeries.name) }),
|
|
@@ -7985,6 +8065,7 @@ function createReactChartNodeView(options = {}) {
|
|
|
7985
8065
|
useSpreadsheetEditor,
|
|
7986
8066
|
useSpreadsheetViewport,
|
|
7987
8067
|
useTableMenu,
|
|
8068
|
+
useToolBridge,
|
|
7988
8069
|
useTrackChanges,
|
|
7989
8070
|
withoutDirty
|
|
7990
8071
|
});
|