@pixerate/editor-react 0.90.1 → 0.91.1
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/hooks/useToolBridge.d.cts +3 -3
- package/dist/hooks/useToolBridge.d.ts +3 -3
- package/dist/hooks/useToolRegistryView.d.cts +9 -0
- package/dist/hooks/useToolRegistryView.d.ts +9 -0
- package/dist/index.cjs +533 -513
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +50 -31
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -119,6 +119,7 @@ __export(src_exports, {
|
|
|
119
119
|
useSpreadsheetViewport: () => useSpreadsheetViewport,
|
|
120
120
|
useTableMenu: () => useTableMenu,
|
|
121
121
|
useToolBridge: () => useToolBridge,
|
|
122
|
+
useToolRegistryView: () => useToolRegistryView,
|
|
122
123
|
useTrackChanges: () => useTrackChanges,
|
|
123
124
|
withoutDirty: () => import_editor21.withoutDirty
|
|
124
125
|
});
|
|
@@ -759,19 +760,37 @@ function useToolBridge(registry, options) {
|
|
|
759
760
|
return state;
|
|
760
761
|
}
|
|
761
762
|
|
|
763
|
+
// src/hooks/useToolRegistryView.ts
|
|
764
|
+
var import_react13 = require("react");
|
|
765
|
+
function useToolRegistryView(registry, options = {}) {
|
|
766
|
+
const { toolsets, readOnly, discovery } = options;
|
|
767
|
+
const view = (0, import_react13.useMemo)(
|
|
768
|
+
() => registry ? registry.view({ toolsets, readOnly, discovery }) : null,
|
|
769
|
+
// toolsets is applied below without making a new view, so enabled tools survive.
|
|
770
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
771
|
+
[registry, readOnly, discovery]
|
|
772
|
+
);
|
|
773
|
+
const toolsetsKey = typeof toolsets === "function" ? toolsets : JSON.stringify(toolsets ?? null);
|
|
774
|
+
(0, import_react13.useEffect)(() => {
|
|
775
|
+
view?.setToolsets(toolsets);
|
|
776
|
+
}, [view, toolsetsKey]);
|
|
777
|
+
(0, import_react13.useEffect)(() => () => view?.dispose(), [view]);
|
|
778
|
+
return view;
|
|
779
|
+
}
|
|
780
|
+
|
|
762
781
|
// src/components/EditorContent.tsx
|
|
763
|
-
var
|
|
782
|
+
var import_react14 = require("@tiptap/react");
|
|
764
783
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
765
784
|
var EditorContent = ({
|
|
766
785
|
className,
|
|
767
786
|
editor,
|
|
768
787
|
...props
|
|
769
788
|
}) => {
|
|
770
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
789
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react14.EditorContent, { editor, ...props }) });
|
|
771
790
|
};
|
|
772
791
|
|
|
773
792
|
// src/components/BubbleMenu.tsx
|
|
774
|
-
var
|
|
793
|
+
var import_react15 = require("react");
|
|
775
794
|
var import_react_dom = require("react-dom");
|
|
776
795
|
var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
|
|
777
796
|
var BubbleMenu = ({
|
|
@@ -783,12 +802,12 @@ var BubbleMenu = ({
|
|
|
783
802
|
pluginKey = "bubbleMenu",
|
|
784
803
|
updateDelay
|
|
785
804
|
}) => {
|
|
786
|
-
const menuEl = (0,
|
|
787
|
-
const [mounted, setMounted] = (0,
|
|
805
|
+
const menuEl = (0, import_react15.useRef)(null);
|
|
806
|
+
const [mounted, setMounted] = (0, import_react15.useState)(false);
|
|
788
807
|
if (!menuEl.current && typeof document !== "undefined") {
|
|
789
808
|
menuEl.current = document.createElement("div");
|
|
790
809
|
}
|
|
791
|
-
(0,
|
|
810
|
+
(0, import_react15.useEffect)(() => {
|
|
792
811
|
if (!editor || !menuEl.current || editor.isDestroyed) {
|
|
793
812
|
return;
|
|
794
813
|
}
|
|
@@ -819,7 +838,7 @@ var BubbleMenu = ({
|
|
|
819
838
|
};
|
|
820
839
|
|
|
821
840
|
// src/components/TemplateRenderer.tsx
|
|
822
|
-
var
|
|
841
|
+
var import_react16 = require("react");
|
|
823
842
|
var import_editor6 = require("@pixerate/editor");
|
|
824
843
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
825
844
|
var TemplateRenderer = ({
|
|
@@ -833,11 +852,11 @@ var TemplateRenderer = ({
|
|
|
833
852
|
onTemplateClick,
|
|
834
853
|
onVariableClick
|
|
835
854
|
}) => {
|
|
836
|
-
const displayText = (0,
|
|
855
|
+
const displayText = (0, import_react16.useMemo)(() => {
|
|
837
856
|
if (!resolve || templates.length === 0) return content;
|
|
838
857
|
return (0, import_editor6.resolveTemplates)(content, templates, { bindings });
|
|
839
858
|
}, [content, templates, resolve, bindings]);
|
|
840
|
-
const tokens = (0,
|
|
859
|
+
const tokens = (0, import_react16.useMemo)(() => {
|
|
841
860
|
return (0, import_editor6.evaluatePromptTokens)(displayText, values);
|
|
842
861
|
}, [displayText, values]);
|
|
843
862
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, children: tokens.map((token, index) => {
|
|
@@ -926,7 +945,7 @@ var TemplateRenderer = ({
|
|
|
926
945
|
};
|
|
927
946
|
|
|
928
947
|
// src/components/VariableForm.tsx
|
|
929
|
-
var
|
|
948
|
+
var import_react17 = require("react");
|
|
930
949
|
var import_editor7 = require("@pixerate/editor");
|
|
931
950
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
932
951
|
var VariableForm = ({
|
|
@@ -938,12 +957,12 @@ var VariableForm = ({
|
|
|
938
957
|
onChange,
|
|
939
958
|
className = "flex flex-col gap-3 text-sm"
|
|
940
959
|
}) => {
|
|
941
|
-
const idPrefix = (0,
|
|
942
|
-
const [internal, setInternal] = (0,
|
|
960
|
+
const idPrefix = (0, import_react17.useId)();
|
|
961
|
+
const [internal, setInternal] = (0, import_react17.useState)(
|
|
943
962
|
() => defaultValues ?? {}
|
|
944
963
|
);
|
|
945
964
|
const entered = values ?? internal;
|
|
946
|
-
const fields = (0,
|
|
965
|
+
const fields = (0, import_react17.useMemo)(
|
|
947
966
|
() => (0, import_editor7.getVariableFormFields)(content, { templates, bindings }),
|
|
948
967
|
[content, templates, bindings]
|
|
949
968
|
);
|
|
@@ -1011,26 +1030,26 @@ var VariableForm = ({
|
|
|
1011
1030
|
};
|
|
1012
1031
|
|
|
1013
1032
|
// src/components/MergePreview.tsx
|
|
1014
|
-
var
|
|
1033
|
+
var import_react19 = require("react");
|
|
1015
1034
|
|
|
1016
1035
|
// src/hooks/useMergePreview.ts
|
|
1017
|
-
var
|
|
1036
|
+
var import_react18 = require("react");
|
|
1018
1037
|
var import_editor8 = require("@pixerate/editor");
|
|
1019
1038
|
function useMergePreview(options) {
|
|
1020
1039
|
const { template, templates, bindings, parseOptions } = options;
|
|
1021
|
-
const [sourceText, setSourceTextState] = (0,
|
|
1022
|
-
const [overrides, setOverrides] = (0,
|
|
1023
|
-
const [index, setIndexState] = (0,
|
|
1024
|
-
const [result, setResult] = (0,
|
|
1025
|
-
const source = (0,
|
|
1040
|
+
const [sourceText, setSourceTextState] = (0, import_react18.useState)(options.initialSource ?? "");
|
|
1041
|
+
const [overrides, setOverrides] = (0, import_react18.useState)({});
|
|
1042
|
+
const [index, setIndexState] = (0, import_react18.useState)(0);
|
|
1043
|
+
const [result, setResult] = (0, import_react18.useState)(null);
|
|
1044
|
+
const source = (0, import_react18.useMemo)(
|
|
1026
1045
|
() => (0, import_editor8.parseDataSource)(sourceText, parseOptions),
|
|
1027
1046
|
[sourceText, parseOptions]
|
|
1028
1047
|
);
|
|
1029
|
-
const variables = (0,
|
|
1048
|
+
const variables = (0, import_react18.useMemo)(
|
|
1030
1049
|
() => (0, import_editor8.extractVariables)(template, { templates, bindings }).map((v) => v.name),
|
|
1031
1050
|
[template, templates, bindings]
|
|
1032
1051
|
);
|
|
1033
|
-
const mapping = (0,
|
|
1052
|
+
const mapping = (0, import_react18.useMemo)(() => {
|
|
1034
1053
|
const merged = {
|
|
1035
1054
|
...(0, import_editor8.matchFields)(variables, source.fields).mapping
|
|
1036
1055
|
};
|
|
@@ -1044,29 +1063,29 @@ function useMergePreview(options) {
|
|
|
1044
1063
|
const count = source.records.length;
|
|
1045
1064
|
const current = count === 0 ? 0 : Math.min(index, count - 1);
|
|
1046
1065
|
const record = source.records[current];
|
|
1047
|
-
const values = (0,
|
|
1066
|
+
const values = (0, import_react18.useMemo)(
|
|
1048
1067
|
() => record ? (0, import_editor8.recordToValues)(record, mapping) : {},
|
|
1049
1068
|
[record, mapping]
|
|
1050
1069
|
);
|
|
1051
|
-
const setSourceText = (0,
|
|
1070
|
+
const setSourceText = (0, import_react18.useCallback)((text) => {
|
|
1052
1071
|
setSourceTextState(text);
|
|
1053
1072
|
setIndexState(0);
|
|
1054
1073
|
setResult(null);
|
|
1055
1074
|
}, []);
|
|
1056
|
-
const loadFile = (0,
|
|
1075
|
+
const loadFile = (0, import_react18.useCallback)(
|
|
1057
1076
|
async (file) => setSourceText(await file.text()),
|
|
1058
1077
|
[setSourceText]
|
|
1059
1078
|
);
|
|
1060
|
-
const setIndex = (0,
|
|
1079
|
+
const setIndex = (0, import_react18.useCallback)(
|
|
1061
1080
|
(next) => setIndexState(Math.max(0, Math.min(next, count - 1))),
|
|
1062
1081
|
[count]
|
|
1063
1082
|
);
|
|
1064
|
-
const setFieldMapping = (0,
|
|
1083
|
+
const setFieldMapping = (0, import_react18.useCallback)((variable, field) => {
|
|
1065
1084
|
setOverrides((previous) => ({ ...previous, [variable]: field }));
|
|
1066
1085
|
setResult(null);
|
|
1067
1086
|
}, []);
|
|
1068
|
-
const resetMapping = (0,
|
|
1069
|
-
const merge = (0,
|
|
1087
|
+
const resetMapping = (0, import_react18.useCallback)(() => setOverrides({}), []);
|
|
1088
|
+
const merge = (0, import_react18.useCallback)(() => {
|
|
1070
1089
|
const merged = (0, import_editor8.mergeRecords)(template, source, {
|
|
1071
1090
|
templates,
|
|
1072
1091
|
bindings,
|
|
@@ -1078,7 +1097,7 @@ function useMergePreview(options) {
|
|
|
1078
1097
|
setResult(merged);
|
|
1079
1098
|
return merged;
|
|
1080
1099
|
}, [template, source, templates, bindings, mapping, options.skipIf, options.separator, options.maxOutputs]);
|
|
1081
|
-
const serialize = (0,
|
|
1100
|
+
const serialize = (0, import_react18.useCallback)(
|
|
1082
1101
|
(format) => result ? (0, import_editor8.serializeMergeOutputs)(result.outputs, format, options.separator) : "",
|
|
1083
1102
|
[result, options.separator]
|
|
1084
1103
|
);
|
|
@@ -1131,7 +1150,7 @@ var MergePreview = ({
|
|
|
1131
1150
|
downloadName = "merged",
|
|
1132
1151
|
className = "flex flex-col gap-3 text-sm"
|
|
1133
1152
|
}) => {
|
|
1134
|
-
const id = (0,
|
|
1153
|
+
const id = (0, import_react19.useId)();
|
|
1135
1154
|
const merge = useMergePreview({
|
|
1136
1155
|
template: content,
|
|
1137
1156
|
templates,
|
|
@@ -1142,7 +1161,7 @@ var MergePreview = ({
|
|
|
1142
1161
|
separator,
|
|
1143
1162
|
maxOutputs
|
|
1144
1163
|
});
|
|
1145
|
-
const [copied, setCopied] = (0,
|
|
1164
|
+
const [copied, setCopied] = (0, import_react19.useState)(false);
|
|
1146
1165
|
const { source, result } = merge;
|
|
1147
1166
|
const copy = async () => {
|
|
1148
1167
|
try {
|
|
@@ -1299,11 +1318,11 @@ var MergePreview = ({
|
|
|
1299
1318
|
};
|
|
1300
1319
|
|
|
1301
1320
|
// src/hooks/useOutline.ts
|
|
1302
|
-
var
|
|
1321
|
+
var import_react20 = require("react");
|
|
1303
1322
|
var import_editor9 = require("@pixerate/editor");
|
|
1304
1323
|
function useOutline(editor) {
|
|
1305
|
-
const store = (0,
|
|
1306
|
-
return (0,
|
|
1324
|
+
const store = (0, import_react20.useMemo)(() => (0, import_editor9.createOutlineStore)(editor), [editor]);
|
|
1325
|
+
return (0, import_react20.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
1307
1326
|
}
|
|
1308
1327
|
|
|
1309
1328
|
// src/components/OutlinePanel.tsx
|
|
@@ -1348,12 +1367,12 @@ var OutlinePanel = ({
|
|
|
1348
1367
|
};
|
|
1349
1368
|
|
|
1350
1369
|
// src/hooks/useParagraphStyles.ts
|
|
1351
|
-
var
|
|
1370
|
+
var import_react21 = require("react");
|
|
1352
1371
|
var import_editor11 = require("@pixerate/editor");
|
|
1353
1372
|
function useParagraphStyles(editor) {
|
|
1354
|
-
const store = (0,
|
|
1355
|
-
const snapshot = (0,
|
|
1356
|
-
return (0,
|
|
1373
|
+
const store = (0, import_react21.useMemo)(() => (0, import_editor11.createParagraphStylesStore)(editor), [editor]);
|
|
1374
|
+
const snapshot = (0, import_react21.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
1375
|
+
return (0, import_react21.useMemo)(() => {
|
|
1357
1376
|
const registry = (0, import_editor11.getStyleRegistry)(editor);
|
|
1358
1377
|
const live = () => editor && !editor.isDestroyed ? editor : null;
|
|
1359
1378
|
return {
|
|
@@ -1376,7 +1395,7 @@ function useParagraphStyles(editor) {
|
|
|
1376
1395
|
}
|
|
1377
1396
|
|
|
1378
1397
|
// src/components/StylesGallery.tsx
|
|
1379
|
-
var
|
|
1398
|
+
var import_react22 = require("react");
|
|
1380
1399
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1381
1400
|
var camel = (property) => property.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
1382
1401
|
var keepSelection = (event) => event.preventDefault();
|
|
@@ -1392,9 +1411,9 @@ var StylesGallery = ({
|
|
|
1392
1411
|
onChange
|
|
1393
1412
|
}) => {
|
|
1394
1413
|
const styles = useParagraphStyles(editor);
|
|
1395
|
-
const [open, setOpen] = (0,
|
|
1396
|
-
const [creating, setCreating] = (0,
|
|
1397
|
-
const [name, setName] = (0,
|
|
1414
|
+
const [open, setOpen] = (0, import_react22.useState)(false);
|
|
1415
|
+
const [creating, setCreating] = (0, import_react22.useState)(false);
|
|
1416
|
+
const [name, setName] = (0, import_react22.useState)("");
|
|
1398
1417
|
const list = showAllStyles ? styles.styles : styles.gallery;
|
|
1399
1418
|
const current = styles.currentStyle;
|
|
1400
1419
|
const expanded = variant === "gallery" || open;
|
|
@@ -1510,13 +1529,13 @@ var StylesGallery = ({
|
|
|
1510
1529
|
var import_editor21 = require("@pixerate/editor");
|
|
1511
1530
|
|
|
1512
1531
|
// src/spreadsheet/useSpreadsheetEditor.ts
|
|
1513
|
-
var
|
|
1532
|
+
var import_react23 = require("react");
|
|
1514
1533
|
var import_spreadsheet = require("@pixerate/editor/spreadsheet");
|
|
1515
1534
|
function useSpreadsheetEditor(options = {}) {
|
|
1516
|
-
const optionsRef = (0,
|
|
1535
|
+
const optionsRef = (0, import_react23.useRef)(options);
|
|
1517
1536
|
optionsRef.current = options;
|
|
1518
|
-
const settersRef = (0,
|
|
1519
|
-
const [controller] = (0,
|
|
1537
|
+
const settersRef = (0, import_react23.useRef)({});
|
|
1538
|
+
const [controller] = (0, import_react23.useState)(
|
|
1520
1539
|
() => new import_spreadsheet.SpreadsheetController({
|
|
1521
1540
|
...options,
|
|
1522
1541
|
onDocumentChange: (updated) => {
|
|
@@ -1533,37 +1552,37 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1533
1552
|
}
|
|
1534
1553
|
})
|
|
1535
1554
|
);
|
|
1536
|
-
const [doc, setDoc] = (0,
|
|
1537
|
-
const [activeCell, setActiveCell] = (0,
|
|
1538
|
-
const [selectedRange, setSelectedRange] = (0,
|
|
1539
|
-
const [editingCell, setEditingCell] = (0,
|
|
1540
|
-
const [draftValue, setDraftState] = (0,
|
|
1541
|
-
const [validationPrompt, setValidationPrompt] = (0,
|
|
1555
|
+
const [doc, setDoc] = (0, import_react23.useState)(() => ({ ...controller.document }));
|
|
1556
|
+
const [activeCell, setActiveCell] = (0, import_react23.useState)(controller.activeCell);
|
|
1557
|
+
const [selectedRange, setSelectedRange] = (0, import_react23.useState)(controller.selectedRange);
|
|
1558
|
+
const [editingCell, setEditingCell] = (0, import_react23.useState)(null);
|
|
1559
|
+
const [draftValue, setDraftState] = (0, import_react23.useState)("");
|
|
1560
|
+
const [validationPrompt, setValidationPrompt] = (0, import_react23.useState)(null);
|
|
1542
1561
|
settersRef.current = { setDoc, setActiveCell, setSelectedRange };
|
|
1543
|
-
const setDraftValue = (0,
|
|
1562
|
+
const setDraftValue = (0, import_react23.useCallback)((value) => {
|
|
1544
1563
|
controller.draftValue = value;
|
|
1545
1564
|
setDraftState(value);
|
|
1546
1565
|
}, [controller]);
|
|
1547
|
-
const setCellValue = (0,
|
|
1566
|
+
const setCellValue = (0, import_react23.useCallback)((rowId, colId, raw) => {
|
|
1548
1567
|
controller.setCellValue(rowId, colId, raw);
|
|
1549
1568
|
setDoc({ ...controller.document });
|
|
1550
1569
|
}, [controller]);
|
|
1551
|
-
const selectCell = (0,
|
|
1570
|
+
const selectCell = (0, import_react23.useCallback)((row, col, extendSelection = false) => {
|
|
1552
1571
|
controller.selectCell(row, col, extendSelection);
|
|
1553
1572
|
setActiveCell(controller.activeCell);
|
|
1554
1573
|
setSelectedRange(controller.selectedRange);
|
|
1555
1574
|
}, [controller]);
|
|
1556
|
-
const selectRange = (0,
|
|
1575
|
+
const selectRange = (0, import_react23.useCallback)((range) => {
|
|
1557
1576
|
controller.selectRange(range);
|
|
1558
1577
|
setSelectedRange(controller.selectedRange);
|
|
1559
1578
|
}, [controller]);
|
|
1560
|
-
const startEditing = (0,
|
|
1579
|
+
const startEditing = (0, import_react23.useCallback)((row, col, initialVal) => {
|
|
1561
1580
|
controller.startEditing(row, col, initialVal);
|
|
1562
1581
|
setActiveCell(controller.activeCell);
|
|
1563
1582
|
setEditingCell(controller.editingCell);
|
|
1564
1583
|
setDraftValue(controller.draftValue);
|
|
1565
1584
|
}, [controller]);
|
|
1566
|
-
const syncEditing = (0,
|
|
1585
|
+
const syncEditing = (0, import_react23.useCallback)(() => {
|
|
1567
1586
|
setEditingCell(controller.editingCell);
|
|
1568
1587
|
setDraftValue(controller.draftValue);
|
|
1569
1588
|
setValidationPrompt(controller.validationPrompt);
|
|
@@ -1571,90 +1590,90 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1571
1590
|
setSelectedRange(controller.selectedRange);
|
|
1572
1591
|
setDoc({ ...controller.document });
|
|
1573
1592
|
}, [controller]);
|
|
1574
|
-
const commitEditing = (0,
|
|
1593
|
+
const commitEditing = (0, import_react23.useCallback)((val) => {
|
|
1575
1594
|
const result = controller.commitEditing(val);
|
|
1576
1595
|
syncEditing();
|
|
1577
1596
|
return result;
|
|
1578
1597
|
}, [controller, syncEditing]);
|
|
1579
|
-
const commitCellInput = (0,
|
|
1598
|
+
const commitCellInput = (0, import_react23.useCallback)((rowId, colId, raw) => {
|
|
1580
1599
|
const result = controller.commitCellInput(rowId, colId, raw);
|
|
1581
1600
|
syncEditing();
|
|
1582
1601
|
return result;
|
|
1583
1602
|
}, [controller, syncEditing]);
|
|
1584
|
-
const resolveValidationPrompt = (0,
|
|
1603
|
+
const resolveValidationPrompt = (0, import_react23.useCallback)((action) => {
|
|
1585
1604
|
controller.resolveValidationPrompt(action);
|
|
1586
1605
|
syncEditing();
|
|
1587
1606
|
}, [controller, syncEditing]);
|
|
1588
|
-
const cancelEditing = (0,
|
|
1607
|
+
const cancelEditing = (0, import_react23.useCallback)(() => {
|
|
1589
1608
|
controller.cancelEditing();
|
|
1590
1609
|
setEditingCell(null);
|
|
1591
1610
|
setDraftValue("");
|
|
1592
1611
|
}, [controller]);
|
|
1593
|
-
const moveCursor = (0,
|
|
1612
|
+
const moveCursor = (0, import_react23.useCallback)((dir, extend = false) => {
|
|
1594
1613
|
controller.moveCursor(dir, extend);
|
|
1595
1614
|
setActiveCell(controller.activeCell);
|
|
1596
1615
|
setSelectedRange(controller.selectedRange);
|
|
1597
1616
|
}, [controller]);
|
|
1598
|
-
const insertColumn = (0,
|
|
1617
|
+
const insertColumn = (0, import_react23.useCallback)((index, config) => {
|
|
1599
1618
|
controller.insertColumn(index, config);
|
|
1600
1619
|
setDoc({ ...controller.document });
|
|
1601
1620
|
}, [controller]);
|
|
1602
|
-
const deleteColumn = (0,
|
|
1621
|
+
const deleteColumn = (0, import_react23.useCallback)((colId) => {
|
|
1603
1622
|
controller.deleteColumn(colId);
|
|
1604
1623
|
setDoc({ ...controller.document });
|
|
1605
1624
|
}, [controller]);
|
|
1606
|
-
const insertRow = (0,
|
|
1625
|
+
const insertRow = (0, import_react23.useCallback)((index, config) => {
|
|
1607
1626
|
controller.insertRow(index, config);
|
|
1608
1627
|
setDoc({ ...controller.document });
|
|
1609
1628
|
}, [controller]);
|
|
1610
|
-
const deleteRow = (0,
|
|
1629
|
+
const deleteRow = (0, import_react23.useCallback)((rowId) => {
|
|
1611
1630
|
controller.deleteRow(rowId);
|
|
1612
1631
|
setDoc({ ...controller.document });
|
|
1613
1632
|
}, [controller]);
|
|
1614
|
-
const setColumnWidth = (0,
|
|
1633
|
+
const setColumnWidth = (0, import_react23.useCallback)((colId, width) => {
|
|
1615
1634
|
controller.setColumnWidth(colId, width);
|
|
1616
1635
|
setDoc({ ...controller.document });
|
|
1617
1636
|
}, [controller]);
|
|
1618
|
-
const autoFitColumnWidth = (0,
|
|
1637
|
+
const autoFitColumnWidth = (0, import_react23.useCallback)((colId, customWidth) => {
|
|
1619
1638
|
controller.autoFitColumnWidth(colId, customWidth);
|
|
1620
1639
|
setDoc({ ...controller.document });
|
|
1621
1640
|
}, [controller]);
|
|
1622
|
-
const registerDataSource = (0,
|
|
1641
|
+
const registerDataSource = (0, import_react23.useCallback)((ds) => {
|
|
1623
1642
|
controller.registerDataSource(ds);
|
|
1624
1643
|
setDoc({ ...controller.document });
|
|
1625
1644
|
}, [controller]);
|
|
1626
|
-
const setPrimaryDataSource = (0,
|
|
1645
|
+
const setPrimaryDataSource = (0, import_react23.useCallback)((id) => {
|
|
1627
1646
|
controller.setPrimaryDataSource(id);
|
|
1628
1647
|
setDoc({ ...controller.document });
|
|
1629
1648
|
}, [controller]);
|
|
1630
|
-
const recalculateAll = (0,
|
|
1649
|
+
const recalculateAll = (0, import_react23.useCallback)(() => {
|
|
1631
1650
|
controller.recalculateAll();
|
|
1632
1651
|
setDoc({ ...controller.document });
|
|
1633
1652
|
}, [controller]);
|
|
1634
|
-
const undo = (0,
|
|
1653
|
+
const undo = (0, import_react23.useCallback)(() => {
|
|
1635
1654
|
controller.undo();
|
|
1636
1655
|
setDoc({ ...controller.document });
|
|
1637
1656
|
setActiveCell(controller.activeCell);
|
|
1638
1657
|
setSelectedRange(controller.selectedRange);
|
|
1639
1658
|
}, [controller]);
|
|
1640
|
-
const redo = (0,
|
|
1659
|
+
const redo = (0, import_react23.useCallback)(() => {
|
|
1641
1660
|
controller.redo();
|
|
1642
1661
|
setDoc({ ...controller.document });
|
|
1643
1662
|
setActiveCell(controller.activeCell);
|
|
1644
1663
|
setSelectedRange(controller.selectedRange);
|
|
1645
1664
|
}, [controller]);
|
|
1646
|
-
const tableActions = (0,
|
|
1647
|
-
const viewModel = (0,
|
|
1648
|
-
const sheets = (0,
|
|
1649
|
-
const names = (0,
|
|
1650
|
-
const afterSheetSwitch = (0,
|
|
1665
|
+
const tableActions = (0, import_react23.useMemo)(() => (0, import_spreadsheet.bindSpreadsheetTableActions)(controller), [controller]);
|
|
1666
|
+
const viewModel = (0, import_react23.useMemo)(() => controller.getViewModel(), [controller, doc]);
|
|
1667
|
+
const sheets = (0, import_react23.useMemo)(() => controller.getSheets(), [controller, doc]);
|
|
1668
|
+
const names = (0, import_react23.useMemo)(() => controller.getNames(), [controller, doc]);
|
|
1669
|
+
const afterSheetSwitch = (0, import_react23.useCallback)(() => {
|
|
1651
1670
|
setEditingCell(controller.editingCell);
|
|
1652
1671
|
setDraftValue(controller.draftValue);
|
|
1653
1672
|
setActiveCell(controller.activeCell);
|
|
1654
1673
|
setSelectedRange(controller.selectedRange);
|
|
1655
1674
|
setDoc({ ...controller.document });
|
|
1656
1675
|
}, [controller, setDraftValue]);
|
|
1657
|
-
const workbookActions = (0,
|
|
1676
|
+
const workbookActions = (0, import_react23.useMemo)(
|
|
1658
1677
|
() => ({
|
|
1659
1678
|
setActiveSheet: (idOrName) => {
|
|
1660
1679
|
const changed = controller.setActiveSheet(idOrName);
|
|
@@ -1684,7 +1703,7 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1684
1703
|
}),
|
|
1685
1704
|
[controller, afterSheetSwitch]
|
|
1686
1705
|
);
|
|
1687
|
-
const conditionalFormatOverlay = (0,
|
|
1706
|
+
const conditionalFormatOverlay = (0, import_react23.useMemo)(() => controller.getConditionalFormatOverlay(), [controller, doc]);
|
|
1688
1707
|
return {
|
|
1689
1708
|
document: doc,
|
|
1690
1709
|
activeCell,
|
|
@@ -1746,20 +1765,20 @@ function useSpreadsheetEditor(options = {}) {
|
|
|
1746
1765
|
}
|
|
1747
1766
|
|
|
1748
1767
|
// src/spreadsheet/SpreadsheetEditor.tsx
|
|
1749
|
-
var
|
|
1768
|
+
var import_react32 = require("react");
|
|
1750
1769
|
var import_spreadsheet8 = require("@pixerate/editor/spreadsheet");
|
|
1751
1770
|
|
|
1752
1771
|
// src/spreadsheet/SpreadsheetContextMenu.tsx
|
|
1753
|
-
var
|
|
1772
|
+
var import_react24 = __toESM(require("react"), 1);
|
|
1754
1773
|
var import_spreadsheet2 = require("@pixerate/editor/spreadsheet");
|
|
1755
1774
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1756
1775
|
var VIEWPORT_MARGIN = 4;
|
|
1757
1776
|
var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "Table actions" }) => {
|
|
1758
|
-
const menuRef = (0,
|
|
1759
|
-
const onCloseRef = (0,
|
|
1777
|
+
const menuRef = (0, import_react24.useRef)(null);
|
|
1778
|
+
const onCloseRef = (0, import_react24.useRef)(onClose);
|
|
1760
1779
|
onCloseRef.current = onClose;
|
|
1761
|
-
const [position, setPosition] = (0,
|
|
1762
|
-
(0,
|
|
1780
|
+
const [position, setPosition] = (0, import_react24.useState)({ x, y });
|
|
1781
|
+
(0, import_react24.useLayoutEffect)(() => {
|
|
1763
1782
|
const menu = menuRef.current;
|
|
1764
1783
|
if (!menu || typeof window === "undefined") return;
|
|
1765
1784
|
const { width, height } = menu.getBoundingClientRect();
|
|
@@ -1771,7 +1790,7 @@ var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "
|
|
|
1771
1790
|
);
|
|
1772
1791
|
setPosition((prev) => prev.x === next.x && prev.y === next.y ? prev : next);
|
|
1773
1792
|
}, [x, y, items]);
|
|
1774
|
-
(0,
|
|
1793
|
+
(0, import_react24.useEffect)(() => {
|
|
1775
1794
|
const handlePointer = (e) => {
|
|
1776
1795
|
if (!menuRef.current?.contains(e.target)) onCloseRef.current();
|
|
1777
1796
|
};
|
|
@@ -1801,7 +1820,7 @@ var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "
|
|
|
1801
1820
|
},
|
|
1802
1821
|
onContextMenu: (e) => e.preventDefault(),
|
|
1803
1822
|
onKeyDown: (e) => e.stopPropagation(),
|
|
1804
|
-
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
1823
|
+
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_react24.default.Fragment, { children: [
|
|
1805
1824
|
item.separatorBefore && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { role: "separator", className: "my-1 h-px bg-border" }),
|
|
1806
1825
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1807
1826
|
"button",
|
|
@@ -1826,7 +1845,7 @@ var SpreadsheetContextMenu = ({ items, x, y, onClose, onOpenPanel, ariaLabel = "
|
|
|
1826
1845
|
};
|
|
1827
1846
|
|
|
1828
1847
|
// src/spreadsheet/SpreadsheetGroupRow.tsx
|
|
1829
|
-
var
|
|
1848
|
+
var import_react25 = __toESM(require("react"), 1);
|
|
1830
1849
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1831
1850
|
var formatSummary = (value) => value === null ? "\u2013" : String(value);
|
|
1832
1851
|
var SpreadsheetGroupRow = ({
|
|
@@ -1860,7 +1879,7 @@ var SpreadsheetGroupRow = ({
|
|
|
1860
1879
|
columns.map(({ column }, i) => {
|
|
1861
1880
|
const summary = group.summaries[column.id];
|
|
1862
1881
|
const before = leadingColumns !== void 0 && i === leadingColumns && leftSpace > 0 ? spacer("space:left") : null;
|
|
1863
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1882
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react25.default.Fragment, { children: [
|
|
1864
1883
|
before,
|
|
1865
1884
|
/* @__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: [
|
|
1866
1885
|
group.label,
|
|
@@ -1880,7 +1899,7 @@ var SpreadsheetGroupRow = ({
|
|
|
1880
1899
|
};
|
|
1881
1900
|
|
|
1882
1901
|
// src/spreadsheet/useSpreadsheetTableInteractions.ts
|
|
1883
|
-
var
|
|
1902
|
+
var import_react26 = require("react");
|
|
1884
1903
|
var import_spreadsheet3 = require("@pixerate/editor/spreadsheet");
|
|
1885
1904
|
function gridHasFocus(grid) {
|
|
1886
1905
|
if (!grid || typeof document === "undefined") return false;
|
|
@@ -1889,12 +1908,12 @@ function gridHasFocus(grid) {
|
|
|
1889
1908
|
return !(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement);
|
|
1890
1909
|
}
|
|
1891
1910
|
function useSpreadsheetClipboard(gridRef, state, readOnly) {
|
|
1892
|
-
const stateRef = (0,
|
|
1911
|
+
const stateRef = (0, import_react26.useRef)(state);
|
|
1893
1912
|
stateRef.current = state;
|
|
1894
|
-
const readOnlyRef = (0,
|
|
1913
|
+
const readOnlyRef = (0, import_react26.useRef)(readOnly);
|
|
1895
1914
|
readOnlyRef.current = readOnly;
|
|
1896
|
-
const copiedRef = (0,
|
|
1897
|
-
(0,
|
|
1915
|
+
const copiedRef = (0, import_react26.useRef)(false);
|
|
1916
|
+
(0, import_react26.useEffect)(() => {
|
|
1898
1917
|
if (typeof document === "undefined") return;
|
|
1899
1918
|
const handleCopy = (e) => {
|
|
1900
1919
|
const s = stateRef.current;
|
|
@@ -1917,7 +1936,7 @@ function useSpreadsheetClipboard(gridRef, state, readOnly) {
|
|
|
1917
1936
|
document.removeEventListener("paste", handlePaste);
|
|
1918
1937
|
};
|
|
1919
1938
|
}, [gridRef]);
|
|
1920
|
-
const copyShortcutFallback = (0,
|
|
1939
|
+
const copyShortcutFallback = (0, import_react26.useCallback)(() => {
|
|
1921
1940
|
copiedRef.current = false;
|
|
1922
1941
|
setTimeout(() => {
|
|
1923
1942
|
if (copiedRef.current) return;
|
|
@@ -1929,13 +1948,13 @@ function useSpreadsheetClipboard(gridRef, state, readOnly) {
|
|
|
1929
1948
|
return { copyShortcutFallback };
|
|
1930
1949
|
}
|
|
1931
1950
|
function useFillHandle(state) {
|
|
1932
|
-
const [drag, setDrag] = (0,
|
|
1933
|
-
const dragRef = (0,
|
|
1951
|
+
const [drag, setDrag] = (0, import_react26.useState)(null);
|
|
1952
|
+
const dragRef = (0, import_react26.useRef)(drag);
|
|
1934
1953
|
dragRef.current = drag;
|
|
1935
|
-
const stateRef = (0,
|
|
1954
|
+
const stateRef = (0, import_react26.useRef)(state);
|
|
1936
1955
|
stateRef.current = state;
|
|
1937
1956
|
const dragging = drag !== null;
|
|
1938
|
-
(0,
|
|
1957
|
+
(0, import_react26.useEffect)(() => {
|
|
1939
1958
|
if (!dragging) return;
|
|
1940
1959
|
const handleMouseUp = () => {
|
|
1941
1960
|
const current = dragRef.current;
|
|
@@ -1945,13 +1964,13 @@ function useFillHandle(state) {
|
|
|
1945
1964
|
window.addEventListener("mouseup", handleMouseUp);
|
|
1946
1965
|
return () => window.removeEventListener("mouseup", handleMouseUp);
|
|
1947
1966
|
}, [dragging]);
|
|
1948
|
-
const startFill = (0,
|
|
1967
|
+
const startFill = (0, import_react26.useCallback)((e) => {
|
|
1949
1968
|
e.preventDefault();
|
|
1950
1969
|
e.stopPropagation();
|
|
1951
1970
|
const range = stateRef.current.selectedRange;
|
|
1952
1971
|
if (range) setDrag({ source: (0, import_spreadsheet3.normalizeRange)(range), target: null });
|
|
1953
1972
|
}, []);
|
|
1954
|
-
const extendFill = (0,
|
|
1973
|
+
const extendFill = (0, import_react26.useCallback)((row, col) => {
|
|
1955
1974
|
const current = dragRef.current;
|
|
1956
1975
|
if (!current) return;
|
|
1957
1976
|
setDrag({ source: current.source, target: (0, import_spreadsheet3.computeFillTarget)(current.source, { row, col }) });
|
|
@@ -1960,12 +1979,12 @@ function useFillHandle(state) {
|
|
|
1960
1979
|
}
|
|
1961
1980
|
|
|
1962
1981
|
// src/spreadsheet/SpreadsheetValidationDialog.tsx
|
|
1963
|
-
var
|
|
1982
|
+
var import_react27 = require("react");
|
|
1964
1983
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1965
1984
|
var SpreadsheetValidationDialog = ({ prompt, onResolve }) => {
|
|
1966
1985
|
const style = prompt.result.errorStyle ?? "stop";
|
|
1967
|
-
const firstButton = (0,
|
|
1968
|
-
(0,
|
|
1986
|
+
const firstButton = (0, import_react27.useRef)(null);
|
|
1987
|
+
(0, import_react27.useEffect)(() => {
|
|
1969
1988
|
firstButton.current?.focus();
|
|
1970
1989
|
}, [prompt]);
|
|
1971
1990
|
const buttons = style === "stop" ? [
|
|
@@ -2031,7 +2050,7 @@ var SpreadsheetValidationDialog = ({ prompt, onResolve }) => {
|
|
|
2031
2050
|
};
|
|
2032
2051
|
|
|
2033
2052
|
// src/spreadsheet/SpreadsheetRulePanels.tsx
|
|
2034
|
-
var
|
|
2053
|
+
var import_react28 = require("react");
|
|
2035
2054
|
var import_spreadsheet4 = require("@pixerate/editor/spreadsheet");
|
|
2036
2055
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2037
2056
|
var inputClass = "w-full rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground";
|
|
@@ -2085,18 +2104,18 @@ function RuleSwatch({ rule }) {
|
|
|
2085
2104
|
}
|
|
2086
2105
|
var SpreadsheetConditionalFormatPanel = ({ state, onClose }) => {
|
|
2087
2106
|
const rules = state.document.table?.conditionalFormats ?? [];
|
|
2088
|
-
const [kind, setKind] = (0,
|
|
2089
|
-
const [appliesTo, setAppliesTo] = (0,
|
|
2090
|
-
const [value, setValue] = (0,
|
|
2091
|
-
const [value2, setValue2] = (0,
|
|
2092
|
-
const [text, setText] = (0,
|
|
2093
|
-
const [formula, setFormula] = (0,
|
|
2094
|
-
const [rank, setRank] = (0,
|
|
2095
|
-
const [period, setPeriod] = (0,
|
|
2096
|
-
const [iconSet, setIconSet] = (0,
|
|
2097
|
-
const [color, setColor] = (0,
|
|
2098
|
-
const [styleId, setStyleId] = (0,
|
|
2099
|
-
const preset = (0,
|
|
2107
|
+
const [kind, setKind] = (0, import_react28.useState)("greaterThan");
|
|
2108
|
+
const [appliesTo, setAppliesTo] = (0, import_react28.useState)(() => selectionText(state.selectedRange));
|
|
2109
|
+
const [value, setValue] = (0, import_react28.useState)("");
|
|
2110
|
+
const [value2, setValue2] = (0, import_react28.useState)("");
|
|
2111
|
+
const [text, setText] = (0, import_react28.useState)("");
|
|
2112
|
+
const [formula, setFormula] = (0, import_react28.useState)("=");
|
|
2113
|
+
const [rank, setRank] = (0, import_react28.useState)("10");
|
|
2114
|
+
const [period, setPeriod] = (0, import_react28.useState)("today");
|
|
2115
|
+
const [iconSet, setIconSet] = (0, import_react28.useState)("3TrafficLights1");
|
|
2116
|
+
const [color, setColor] = (0, import_react28.useState)("#638ec6");
|
|
2117
|
+
const [styleId, setStyleId] = (0, import_react28.useState)(import_spreadsheet4.CONDITIONAL_FORMAT_STYLE_PRESETS[0].id);
|
|
2118
|
+
const preset = (0, import_react28.useMemo)(() => import_spreadsheet4.CONDITIONAL_FORMAT_PRESETS.find((p) => p.kind === kind), [kind]);
|
|
2100
2119
|
const ranges = (0, import_spreadsheet4.parseRuleRanges)(appliesTo);
|
|
2101
2120
|
const add = () => {
|
|
2102
2121
|
if (!ranges) return;
|
|
@@ -2180,15 +2199,15 @@ var SpreadsheetConditionalFormatPanel = ({ state, onClose }) => {
|
|
|
2180
2199
|
};
|
|
2181
2200
|
var SpreadsheetDataValidationPanel = ({ state, onClose }) => {
|
|
2182
2201
|
const rules = state.document.table?.dataValidations ?? [];
|
|
2183
|
-
const [type, setType] = (0,
|
|
2184
|
-
const [operator, setOperator] = (0,
|
|
2185
|
-
const [formula1, setFormula1] = (0,
|
|
2186
|
-
const [formula2, setFormula2] = (0,
|
|
2187
|
-
const [errorStyle, setErrorStyle] = (0,
|
|
2188
|
-
const [errorMessage, setErrorMessage] = (0,
|
|
2189
|
-
const [inputMessage, setInputMessage] = (0,
|
|
2190
|
-
const [ignoreBlank, setIgnoreBlank] = (0,
|
|
2191
|
-
const [appliesTo, setAppliesTo] = (0,
|
|
2202
|
+
const [type, setType] = (0, import_react28.useState)("list");
|
|
2203
|
+
const [operator, setOperator] = (0, import_react28.useState)("between");
|
|
2204
|
+
const [formula1, setFormula1] = (0, import_react28.useState)("");
|
|
2205
|
+
const [formula2, setFormula2] = (0, import_react28.useState)("");
|
|
2206
|
+
const [errorStyle, setErrorStyle] = (0, import_react28.useState)("stop");
|
|
2207
|
+
const [errorMessage, setErrorMessage] = (0, import_react28.useState)("");
|
|
2208
|
+
const [inputMessage, setInputMessage] = (0, import_react28.useState)("");
|
|
2209
|
+
const [ignoreBlank, setIgnoreBlank] = (0, import_react28.useState)(true);
|
|
2210
|
+
const [appliesTo, setAppliesTo] = (0, import_react28.useState)(() => selectionText(state.selectedRange));
|
|
2192
2211
|
const ranges = (0, import_spreadsheet4.parseRuleRanges)(appliesTo);
|
|
2193
2212
|
const usesOperator = type === "whole" || type === "decimal" || type === "date" || type === "time" || type === "textLength";
|
|
2194
2213
|
const needsTwo = usesOperator && (operator === "between" || operator === "notBetween");
|
|
@@ -2262,29 +2281,29 @@ var SpreadsheetDataValidationPanel = ({ state, onClose }) => {
|
|
|
2262
2281
|
};
|
|
2263
2282
|
|
|
2264
2283
|
// src/spreadsheet/useSpreadsheetViewport.ts
|
|
2265
|
-
var
|
|
2284
|
+
var import_react29 = require("react");
|
|
2266
2285
|
var import_spreadsheet5 = require("@pixerate/editor/spreadsheet");
|
|
2267
|
-
var useIsomorphicLayoutEffect = typeof window !== "undefined" ?
|
|
2286
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_react29.useLayoutEffect : import_react29.useEffect;
|
|
2268
2287
|
function useSpreadsheetViewport(scrollRef, view, options = {}) {
|
|
2269
|
-
const metrics = (0,
|
|
2288
|
+
const metrics = (0, import_react29.useMemo)(() => (0, import_spreadsheet5.measureSpreadsheetView)(view), [view]);
|
|
2270
2289
|
const virtual = (0, import_spreadsheet5.shouldVirtualizeSpreadsheet)(view, options.virtualize ?? "auto");
|
|
2271
|
-
const [viewport, setViewport] = (0,
|
|
2272
|
-
const windowOptions = (0,
|
|
2290
|
+
const [viewport, setViewport] = (0, import_react29.useState)({ scrollTop: 0, scrollLeft: 0, width: 0, height: 0 });
|
|
2291
|
+
const windowOptions = (0, import_react29.useMemo)(
|
|
2273
2292
|
() => ({ merges: options.merges, overscanRows: options.overscanRows, overscanColumns: options.overscanColumns }),
|
|
2274
2293
|
[options.merges, options.overscanRows, options.overscanColumns]
|
|
2275
2294
|
);
|
|
2276
|
-
const win = (0,
|
|
2295
|
+
const win = (0, import_react29.useMemo)(
|
|
2277
2296
|
() => virtual ? (0, import_spreadsheet5.getSpreadsheetViewWindow)(metrics, viewport, windowOptions) : (0, import_spreadsheet5.fullSpreadsheetViewWindow)(metrics),
|
|
2278
2297
|
[virtual, metrics, viewport, windowOptions]
|
|
2279
2298
|
);
|
|
2280
|
-
const latest = (0,
|
|
2299
|
+
const latest = (0, import_react29.useRef)({ metrics, viewport, virtual, windowOptions });
|
|
2281
2300
|
latest.current = { metrics, viewport, virtual, windowOptions };
|
|
2282
|
-
const readViewport = (0,
|
|
2301
|
+
const readViewport = (0, import_react29.useCallback)(() => {
|
|
2283
2302
|
const el = scrollRef.current;
|
|
2284
2303
|
if (!el) return null;
|
|
2285
2304
|
return { scrollTop: el.scrollTop, scrollLeft: el.scrollLeft, width: el.clientWidth, height: el.clientHeight };
|
|
2286
2305
|
}, [scrollRef]);
|
|
2287
|
-
const updateViewport = (0,
|
|
2306
|
+
const updateViewport = (0, import_react29.useCallback)((next) => {
|
|
2288
2307
|
setViewport((prev) => {
|
|
2289
2308
|
const { metrics: m, virtual: v, windowOptions: o } = latest.current;
|
|
2290
2309
|
if (!v) return prev;
|
|
@@ -2292,7 +2311,7 @@ function useSpreadsheetViewport(scrollRef, view, options = {}) {
|
|
|
2292
2311
|
return same ? prev : next;
|
|
2293
2312
|
});
|
|
2294
2313
|
}, []);
|
|
2295
|
-
const onScroll = (0,
|
|
2314
|
+
const onScroll = (0, import_react29.useCallback)(() => {
|
|
2296
2315
|
const next = readViewport();
|
|
2297
2316
|
if (next) updateViewport(next);
|
|
2298
2317
|
}, [readViewport, updateViewport]);
|
|
@@ -2326,24 +2345,24 @@ function useSpreadsheetViewport(scrollRef, view, options = {}) {
|
|
|
2326
2345
|
}
|
|
2327
2346
|
|
|
2328
2347
|
// src/spreadsheet/FormulaHints.tsx
|
|
2329
|
-
var
|
|
2348
|
+
var import_react30 = require("react");
|
|
2330
2349
|
var import_spreadsheet6 = require("@pixerate/editor/spreadsheet");
|
|
2331
2350
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2332
2351
|
var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
2333
|
-
const [caret, setCaret] = (0,
|
|
2334
|
-
const [focused, setFocused] = (0,
|
|
2335
|
-
const [selected, setSelected] = (0,
|
|
2336
|
-
const [dismissed, setDismissed] = (0,
|
|
2337
|
-
const [position, setPosition] = (0,
|
|
2338
|
-
const pendingCaret = (0,
|
|
2339
|
-
const hints = (0,
|
|
2352
|
+
const [caret, setCaret] = (0, import_react30.useState)(null);
|
|
2353
|
+
const [focused, setFocused] = (0, import_react30.useState)(false);
|
|
2354
|
+
const [selected, setSelected] = (0, import_react30.useState)(0);
|
|
2355
|
+
const [dismissed, setDismissed] = (0, import_react30.useState)(false);
|
|
2356
|
+
const [position, setPosition] = (0, import_react30.useState)(null);
|
|
2357
|
+
const pendingCaret = (0, import_react30.useRef)(null);
|
|
2358
|
+
const hints = (0, import_react30.useMemo)(
|
|
2340
2359
|
() => (0, import_spreadsheet6.getFormulaHints)(value, caret ?? value.length, { limit, names }),
|
|
2341
2360
|
[value, caret, limit, names]
|
|
2342
2361
|
);
|
|
2343
2362
|
const suggestions = dismissed ? [] : hints.suggestions;
|
|
2344
2363
|
const selectedIndex = Math.max(0, Math.min(selected, suggestions.length - 1));
|
|
2345
2364
|
const visible = focused && value.trimStart().startsWith("=") && (suggestions.length > 0 || !!hints.activeCall);
|
|
2346
|
-
const latest = (0,
|
|
2365
|
+
const latest = (0, import_react30.useRef)({ suggestions, selected: selectedIndex, value, caret, onAccept });
|
|
2347
2366
|
latest.current = { suggestions, selected: selectedIndex, value, caret, onAccept };
|
|
2348
2367
|
const accept = (index) => {
|
|
2349
2368
|
const { suggestions: list, value: current, caret: at, onAccept: commit } = latest.current;
|
|
@@ -2353,7 +2372,7 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2353
2372
|
pendingCaret.current = next.caret;
|
|
2354
2373
|
commit(next.value);
|
|
2355
2374
|
};
|
|
2356
|
-
(0,
|
|
2375
|
+
(0, import_react30.useEffect)(() => {
|
|
2357
2376
|
const input = inputRef.current;
|
|
2358
2377
|
if (!input) return;
|
|
2359
2378
|
const syncCaret = () => setCaret(input.selectionStart ?? input.value.length);
|
|
@@ -2403,7 +2422,7 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2403
2422
|
input.removeEventListener("keydown", onKeyDown);
|
|
2404
2423
|
};
|
|
2405
2424
|
}, [inputRef]);
|
|
2406
|
-
(0,
|
|
2425
|
+
(0, import_react30.useLayoutEffect)(() => {
|
|
2407
2426
|
const input = inputRef.current;
|
|
2408
2427
|
const at = pendingCaret.current;
|
|
2409
2428
|
if (!input || at === null || input.value !== value) return;
|
|
@@ -2412,7 +2431,7 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2412
2431
|
setCaret(at);
|
|
2413
2432
|
setSelected(0);
|
|
2414
2433
|
}, [value, inputRef]);
|
|
2415
|
-
(0,
|
|
2434
|
+
(0, import_react30.useLayoutEffect)(() => {
|
|
2416
2435
|
const input = inputRef.current;
|
|
2417
2436
|
if (!visible || !input) return;
|
|
2418
2437
|
const rect = input.getBoundingClientRect();
|
|
@@ -2476,16 +2495,16 @@ var FormulaHints = ({ inputRef, value, onAccept, limit = 8, names }) => {
|
|
|
2476
2495
|
};
|
|
2477
2496
|
|
|
2478
2497
|
// src/spreadsheet/SheetTabs.tsx
|
|
2479
|
-
var
|
|
2498
|
+
var import_react31 = require("react");
|
|
2480
2499
|
var import_spreadsheet7 = require("@pixerate/editor/spreadsheet");
|
|
2481
2500
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2482
2501
|
var SheetTabs = ({ state, readOnly = false, className = "" }) => {
|
|
2483
2502
|
const { controller, sheets } = state;
|
|
2484
|
-
const [renaming, setRenaming] = (0,
|
|
2485
|
-
const [error, setError] = (0,
|
|
2486
|
-
const [menu, setMenu] = (0,
|
|
2487
|
-
const dragFrom = (0,
|
|
2488
|
-
const [dropTarget, setDropTarget] = (0,
|
|
2503
|
+
const [renaming, setRenaming] = (0, import_react31.useState)(null);
|
|
2504
|
+
const [error, setError] = (0, import_react31.useState)(null);
|
|
2505
|
+
const [menu, setMenu] = (0, import_react31.useState)(null);
|
|
2506
|
+
const dragFrom = (0, import_react31.useRef)(null);
|
|
2507
|
+
const [dropTarget, setDropTarget] = (0, import_react31.useState)(null);
|
|
2489
2508
|
const commitRename = (cancelOnError) => {
|
|
2490
2509
|
if (!renaming) return;
|
|
2491
2510
|
const sheet = sheets.find((s) => s.id === renaming.id);
|
|
@@ -2687,21 +2706,21 @@ var SpreadsheetEditor = ({
|
|
|
2687
2706
|
}) => {
|
|
2688
2707
|
const defaultState = useSpreadsheetEditor();
|
|
2689
2708
|
const state = externalState || defaultState;
|
|
2690
|
-
const gridRef = (0,
|
|
2691
|
-
const scrollRef = (0,
|
|
2692
|
-
const formulaBarRef = (0,
|
|
2693
|
-
const cellInputRef = (0,
|
|
2694
|
-
const [resizingColId, setResizingColId] = (0,
|
|
2695
|
-
const [hoveredColId, setHoveredColId] = (0,
|
|
2696
|
-
const [resizeStartX, setResizeStartX] = (0,
|
|
2697
|
-
const [resizeStartWidth, setResizeStartWidth] = (0,
|
|
2709
|
+
const gridRef = (0, import_react32.useRef)(null);
|
|
2710
|
+
const scrollRef = (0, import_react32.useRef)(null);
|
|
2711
|
+
const formulaBarRef = (0, import_react32.useRef)(null);
|
|
2712
|
+
const cellInputRef = (0, import_react32.useRef)(null);
|
|
2713
|
+
const [resizingColId, setResizingColId] = (0, import_react32.useState)(null);
|
|
2714
|
+
const [hoveredColId, setHoveredColId] = (0, import_react32.useState)(null);
|
|
2715
|
+
const [resizeStartX, setResizeStartX] = (0, import_react32.useState)(0);
|
|
2716
|
+
const [resizeStartWidth, setResizeStartWidth] = (0, import_react32.useState)(0);
|
|
2698
2717
|
const view = state.viewModel;
|
|
2699
2718
|
const { window: viewWindow, onScroll: handleGridScroll } = useSpreadsheetViewport(scrollRef, view, {
|
|
2700
2719
|
virtualize,
|
|
2701
2720
|
merges: state.document.table?.merges,
|
|
2702
2721
|
activeCell: state.activeCell
|
|
2703
2722
|
});
|
|
2704
|
-
const columnSlots = (0,
|
|
2723
|
+
const columnSlots = (0, import_react32.useMemo)(() => {
|
|
2705
2724
|
const col = (viewCol) => ({ kind: "col", viewCol });
|
|
2706
2725
|
if (!viewWindow.virtual) return view.columns.map(col);
|
|
2707
2726
|
const slots = view.columns.slice(0, viewWindow.frozenColumns).map(col);
|
|
@@ -2710,11 +2729,11 @@ var SpreadsheetEditor = ({
|
|
|
2710
2729
|
if (viewWindow.rightSpace > 0) slots.push({ kind: "space", key: "space:right", width: viewWindow.rightSpace });
|
|
2711
2730
|
return slots;
|
|
2712
2731
|
}, [view, viewWindow]);
|
|
2713
|
-
const renderedColumns = (0,
|
|
2732
|
+
const renderedColumns = (0, import_react32.useMemo)(
|
|
2714
2733
|
() => columnSlots.flatMap((slot) => slot.kind === "col" ? [slot.viewCol] : []),
|
|
2715
2734
|
[columnSlots]
|
|
2716
2735
|
);
|
|
2717
|
-
const rowSlots = (0,
|
|
2736
|
+
const rowSlots = (0, import_react32.useMemo)(() => {
|
|
2718
2737
|
const row = (viewRow) => ({ kind: "row", viewRow });
|
|
2719
2738
|
if (!viewWindow.virtual) return view.rows.map(row);
|
|
2720
2739
|
const slots = view.rows.slice(0, viewWindow.frozenRows).map(row);
|
|
@@ -2725,16 +2744,16 @@ var SpreadsheetEditor = ({
|
|
|
2725
2744
|
}, [view, viewWindow]);
|
|
2726
2745
|
const { copyShortcutFallback } = useSpreadsheetClipboard(gridRef, state, readOnly);
|
|
2727
2746
|
const { fillTarget, startFill, extendFill } = useFillHandle(state);
|
|
2728
|
-
const [menu, setMenu] = (0,
|
|
2729
|
-
const [panel, setPanel] = (0,
|
|
2730
|
-
const [listMenu, setListMenu] = (0,
|
|
2747
|
+
const [menu, setMenu] = (0, import_react32.useState)(null);
|
|
2748
|
+
const [panel, setPanel] = (0, import_react32.useState)(null);
|
|
2749
|
+
const [listMenu, setListMenu] = (0, import_react32.useState)(null);
|
|
2731
2750
|
const overlay = state.conditionalFormatOverlay;
|
|
2732
2751
|
const filter = state.document.table?.filter;
|
|
2733
|
-
const filteredColIds = (0,
|
|
2752
|
+
const filteredColIds = (0, import_react32.useMemo)(
|
|
2734
2753
|
() => new Set(filter?.enabled ? filter.rules.map((r) => r.colId) : []),
|
|
2735
2754
|
[filter]
|
|
2736
2755
|
);
|
|
2737
|
-
const handleCellContextMenu = (0,
|
|
2756
|
+
const handleCellContextMenu = (0, import_react32.useCallback)((rIdx, cIdx, e) => {
|
|
2738
2757
|
if (readOnly) return;
|
|
2739
2758
|
e.preventDefault();
|
|
2740
2759
|
if (state.editingCell) state.commitEditing();
|
|
@@ -2743,33 +2762,33 @@ var SpreadsheetEditor = ({
|
|
|
2743
2762
|
}
|
|
2744
2763
|
setMenu({ x: e.clientX, y: e.clientY, items: (0, import_spreadsheet8.getSpreadsheetMenuItems)(state.controller, { row: rIdx, col: cIdx }) });
|
|
2745
2764
|
}, [readOnly, state]);
|
|
2746
|
-
const nameSuggestions = (0,
|
|
2765
|
+
const nameSuggestions = (0, import_react32.useMemo)(
|
|
2747
2766
|
() => state.controller.getNameSuggestions(),
|
|
2748
2767
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2749
2768
|
[state.controller, state.document]
|
|
2750
2769
|
);
|
|
2751
|
-
const activeRawValue = (0,
|
|
2770
|
+
const activeRawValue = (0, import_react32.useMemo)(() => {
|
|
2752
2771
|
if (!state.activeCell) return "";
|
|
2753
2772
|
const row = state.document.rows[state.activeCell.row];
|
|
2754
2773
|
const col = state.document.columns[state.activeCell.col];
|
|
2755
2774
|
if (!row || !col) return "";
|
|
2756
2775
|
return state.getCell(row.id, col.id).raw;
|
|
2757
2776
|
}, [state.activeCell, state.document]);
|
|
2758
|
-
const activeSpill = (0,
|
|
2777
|
+
const activeSpill = (0, import_react32.useMemo)(
|
|
2759
2778
|
() => state.activeCell ? state.controller.getSpillAt(state.activeCell.row, state.activeCell.col) : null,
|
|
2760
2779
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2761
2780
|
[state.controller, state.activeCell, state.document]
|
|
2762
2781
|
);
|
|
2763
2782
|
const spillFormula = activeSpill && !activeRawValue && activeSpill.key !== coordKey(state.activeCell) ? activeSpill.formula : "";
|
|
2764
|
-
const coordLabel = (0,
|
|
2783
|
+
const coordLabel = (0, import_react32.useMemo)(() => {
|
|
2765
2784
|
if (!state.activeCell) return "--";
|
|
2766
2785
|
const colName = (0, import_spreadsheet8.indexToColName)(state.activeCell.col);
|
|
2767
2786
|
return `${colName}${state.activeCell.row + 1}`;
|
|
2768
2787
|
}, [state.activeCell]);
|
|
2769
|
-
const [formulaDraft, setFormulaDraft] = (0,
|
|
2788
|
+
const [formulaDraft, setFormulaDraft] = (0, import_react32.useState)(null);
|
|
2770
2789
|
const activeColumn = state.activeCell ? state.document.columns[state.activeCell.col] : void 0;
|
|
2771
2790
|
const formulaBarReadOnly = readOnly || !state.activeCell || !!activeColumn?.readOnly;
|
|
2772
|
-
(0,
|
|
2791
|
+
(0, import_react32.useEffect)(() => {
|
|
2773
2792
|
setFormulaDraft(null);
|
|
2774
2793
|
}, [state.activeCell?.row, state.activeCell?.col]);
|
|
2775
2794
|
const commitFormulaBar = () => {
|
|
@@ -2785,19 +2804,19 @@ var SpreadsheetEditor = ({
|
|
|
2785
2804
|
}
|
|
2786
2805
|
setFormulaDraft(null);
|
|
2787
2806
|
};
|
|
2788
|
-
const handleCellClick = (0,
|
|
2807
|
+
const handleCellClick = (0, import_react32.useCallback)((rIdx, cIdx, e) => {
|
|
2789
2808
|
if (state.editingCell && (state.editingCell.row !== rIdx || state.editingCell.col !== cIdx)) {
|
|
2790
2809
|
state.commitEditing();
|
|
2791
2810
|
}
|
|
2792
2811
|
state.selectCell(rIdx, cIdx, e.shiftKey);
|
|
2793
2812
|
}, [state]);
|
|
2794
|
-
const handleCellDblClick = (0,
|
|
2813
|
+
const handleCellDblClick = (0, import_react32.useCallback)((rIdx, cIdx) => {
|
|
2795
2814
|
if (readOnly) return;
|
|
2796
2815
|
const col = state.document.columns[cIdx];
|
|
2797
2816
|
if (col?.readOnly) return;
|
|
2798
2817
|
state.startEditing(rIdx, cIdx);
|
|
2799
2818
|
}, [readOnly, state]);
|
|
2800
|
-
const handleKeyDown = (0,
|
|
2819
|
+
const handleKeyDown = (0, import_react32.useCallback)((e) => {
|
|
2801
2820
|
if (state.editingCell) {
|
|
2802
2821
|
if (e.key === "Enter") {
|
|
2803
2822
|
e.preventDefault();
|
|
@@ -2869,12 +2888,12 @@ var SpreadsheetEditor = ({
|
|
|
2869
2888
|
}
|
|
2870
2889
|
}
|
|
2871
2890
|
}, [readOnly, state, copyShortcutFallback]);
|
|
2872
|
-
const activeListValues = (0,
|
|
2891
|
+
const activeListValues = (0, import_react32.useMemo)(
|
|
2873
2892
|
() => state.activeCell && !readOnly ? state.controller.getValidationListValues(state.activeCell.row, state.activeCell.col) : null,
|
|
2874
2893
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2875
2894
|
[state.controller, state.activeCell, state.document, readOnly]
|
|
2876
2895
|
);
|
|
2877
|
-
const activeRule = (0,
|
|
2896
|
+
const activeRule = (0, import_react32.useMemo)(
|
|
2878
2897
|
() => state.activeCell ? state.controller.getDataValidationAt(state.activeCell.row, state.activeCell.col) : void 0,
|
|
2879
2898
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2880
2899
|
[state.controller, state.activeCell, state.document]
|
|
@@ -2888,7 +2907,7 @@ var SpreadsheetEditor = ({
|
|
|
2888
2907
|
const rect = td?.getBoundingClientRect();
|
|
2889
2908
|
setListMenu({ x: rect ? rect.left : 0, y: rect ? rect.bottom : 0, row, col, values });
|
|
2890
2909
|
}
|
|
2891
|
-
(0,
|
|
2910
|
+
(0, import_react32.useEffect)(() => {
|
|
2892
2911
|
if (!listMenu) return;
|
|
2893
2912
|
const close = (e) => {
|
|
2894
2913
|
if (!e.target?.closest?.('[aria-label="Allowed values"], .spreadsheet-list-arrow')) setListMenu(null);
|
|
@@ -2911,11 +2930,11 @@ var SpreadsheetEditor = ({
|
|
|
2911
2930
|
else gridRef.current?.focus();
|
|
2912
2931
|
});
|
|
2913
2932
|
};
|
|
2914
|
-
const stateRef = (0,
|
|
2933
|
+
const stateRef = (0, import_react32.useRef)(state);
|
|
2915
2934
|
stateRef.current = state;
|
|
2916
|
-
const onColumnResizeRef = (0,
|
|
2935
|
+
const onColumnResizeRef = (0, import_react32.useRef)(onColumnResize);
|
|
2917
2936
|
onColumnResizeRef.current = onColumnResize;
|
|
2918
|
-
(0,
|
|
2937
|
+
(0, import_react32.useEffect)(() => {
|
|
2919
2938
|
if (!resizingColId) return;
|
|
2920
2939
|
if (typeof document !== "undefined") {
|
|
2921
2940
|
document.body.style.cursor = "col-resize";
|
|
@@ -2966,7 +2985,7 @@ var SpreadsheetEditor = ({
|
|
|
2966
2985
|
window.removeEventListener("mouseup", handleMouseUp);
|
|
2967
2986
|
};
|
|
2968
2987
|
}, [resizingColId, resizeStartX, resizeStartWidth]);
|
|
2969
|
-
const measureElementContentWidth = (0,
|
|
2988
|
+
const measureElementContentWidth = (0, import_react32.useCallback)((el, container) => {
|
|
2970
2989
|
if (typeof document === "undefined") return 0;
|
|
2971
2990
|
let maxW = el.scrollWidth || 0;
|
|
2972
2991
|
const firstChild = el.firstElementChild;
|
|
@@ -3014,7 +3033,7 @@ var SpreadsheetEditor = ({
|
|
|
3014
3033
|
}
|
|
3015
3034
|
return maxW;
|
|
3016
3035
|
}, []);
|
|
3017
|
-
const autoFitColumn = (0,
|
|
3036
|
+
const autoFitColumn = (0, import_react32.useCallback)((colId, colIndex) => {
|
|
3018
3037
|
const col = state.document.columns.find((c) => c.id === colId);
|
|
3019
3038
|
if (!col) return;
|
|
3020
3039
|
let calculatedWidth = 0;
|
|
@@ -3050,12 +3069,12 @@ var SpreadsheetEditor = ({
|
|
|
3050
3069
|
onColumnResize(updatedCol.id, updatedCol.width || 130);
|
|
3051
3070
|
}
|
|
3052
3071
|
}, [state, measureElementContentWidth, onColumnResize]);
|
|
3053
|
-
const handleResizeDblClick = (0,
|
|
3072
|
+
const handleResizeDblClick = (0, import_react32.useCallback)((colId, colIndex, e) => {
|
|
3054
3073
|
e.preventDefault();
|
|
3055
3074
|
e.stopPropagation();
|
|
3056
3075
|
autoFitColumn(colId, colIndex);
|
|
3057
3076
|
}, [autoFitColumn]);
|
|
3058
|
-
const handleHeaderDblClick = (0,
|
|
3077
|
+
const handleHeaderDblClick = (0, import_react32.useCallback)((colId, colIndex, e) => {
|
|
3059
3078
|
const target = e.currentTarget;
|
|
3060
3079
|
if (target) {
|
|
3061
3080
|
const rect = target.getBoundingClientRect();
|
|
@@ -3446,19 +3465,19 @@ var SpreadsheetEditor = ({
|
|
|
3446
3465
|
};
|
|
3447
3466
|
|
|
3448
3467
|
// src/spreadsheet/NameManager.tsx
|
|
3449
|
-
var
|
|
3468
|
+
var import_react33 = require("react");
|
|
3450
3469
|
var import_spreadsheet9 = require("@pixerate/editor/spreadsheet");
|
|
3451
3470
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
3452
3471
|
var EMPTY_DRAFT = { original: null, name: "", refersTo: "=", scope: "", comment: "" };
|
|
3453
3472
|
var NameManager = ({ state, readOnly = false, onClose, className = "" }) => {
|
|
3454
3473
|
const { controller, sheets } = state;
|
|
3455
|
-
const rows = (0,
|
|
3474
|
+
const rows = (0, import_react33.useMemo)(
|
|
3456
3475
|
() => (0, import_spreadsheet9.getNameManagerRows)(controller),
|
|
3457
3476
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3458
3477
|
[controller, state.document, state.names]
|
|
3459
3478
|
);
|
|
3460
|
-
const [draft, setDraft] = (0,
|
|
3461
|
-
const [error, setError] = (0,
|
|
3479
|
+
const [draft, setDraft] = (0, import_react33.useState)(EMPTY_DRAFT);
|
|
3480
|
+
const [error, setError] = (0, import_react33.useState)(null);
|
|
3462
3481
|
const edit = (row) => {
|
|
3463
3482
|
setError(null);
|
|
3464
3483
|
setDraft({
|
|
@@ -3601,7 +3620,7 @@ var NameManager = ({ state, readOnly = false, onClose, className = "" }) => {
|
|
|
3601
3620
|
};
|
|
3602
3621
|
|
|
3603
3622
|
// src/slots.tsx
|
|
3604
|
-
var
|
|
3623
|
+
var import_react34 = require("react");
|
|
3605
3624
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
3606
3625
|
var defaultSlots = {
|
|
3607
3626
|
Button: (props) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
@@ -3623,119 +3642,119 @@ var defaultSlots = {
|
|
|
3623
3642
|
props.onClose && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("button", { type: "button", onClick: props.onClose, className: "opacity-70 hover:opacity-100", children: "\xD7" })
|
|
3624
3643
|
] })
|
|
3625
3644
|
};
|
|
3626
|
-
var EditorSlotsContext = (0,
|
|
3645
|
+
var EditorSlotsContext = (0, import_react34.createContext)(defaultSlots);
|
|
3627
3646
|
function EditorSlotsProvider({ slots, children }) {
|
|
3628
|
-
const mergedSlots = (0,
|
|
3647
|
+
const mergedSlots = (0, import_react34.useMemo)(() => ({ ...defaultSlots, ...slots }), [slots]);
|
|
3629
3648
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(EditorSlotsContext.Provider, { value: mergedSlots, children });
|
|
3630
3649
|
}
|
|
3631
3650
|
function useEditorSlots() {
|
|
3632
|
-
return (0,
|
|
3651
|
+
return (0, import_react34.useContext)(EditorSlotsContext);
|
|
3633
3652
|
}
|
|
3634
3653
|
|
|
3635
3654
|
// src/image-editor/useImageEditor.ts
|
|
3636
|
-
var
|
|
3655
|
+
var import_react35 = require("react");
|
|
3637
3656
|
var import_image_editor = require("@pixerate/editor/image-editor");
|
|
3638
3657
|
function useImageEditor(options = {}) {
|
|
3639
|
-
const controllerRef = (0,
|
|
3658
|
+
const controllerRef = (0, import_react35.useRef)(null);
|
|
3640
3659
|
if (!controllerRef.current) {
|
|
3641
3660
|
controllerRef.current = new import_image_editor.ImageEditorController(options);
|
|
3642
3661
|
}
|
|
3643
3662
|
const controller = controllerRef.current;
|
|
3644
|
-
const [state, setState] = (0,
|
|
3645
|
-
const [historyTicks, setHistoryTicks] = (0,
|
|
3646
|
-
const [histogram, setHistogram] = (0,
|
|
3647
|
-
(0,
|
|
3648
|
-
(0,
|
|
3663
|
+
const [state, setState] = (0, import_react35.useState)(() => controller.getState());
|
|
3664
|
+
const [historyTicks, setHistoryTicks] = (0, import_react35.useState)(0);
|
|
3665
|
+
const [histogram, setHistogram] = (0, import_react35.useState)(() => controller.getHistogram());
|
|
3666
|
+
(0, import_react35.useEffect)(() => controller.subscribeHistogram(setHistogram), [controller]);
|
|
3667
|
+
(0, import_react35.useEffect)(() => {
|
|
3649
3668
|
const unsub = controller.subscribe((next) => {
|
|
3650
3669
|
setState(next);
|
|
3651
3670
|
setHistoryTicks((t) => t + 1);
|
|
3652
3671
|
});
|
|
3653
3672
|
return unsub;
|
|
3654
3673
|
}, [controller]);
|
|
3655
|
-
const loadedImageRef = (0,
|
|
3656
|
-
(0,
|
|
3674
|
+
const loadedImageRef = (0, import_react35.useRef)(options.image);
|
|
3675
|
+
(0, import_react35.useEffect)(() => {
|
|
3657
3676
|
if (options.image === loadedImageRef.current) return;
|
|
3658
3677
|
loadedImageRef.current = options.image;
|
|
3659
3678
|
if (options.image) {
|
|
3660
3679
|
controller.loadImage(options.image);
|
|
3661
3680
|
}
|
|
3662
3681
|
}, [options.image, controller]);
|
|
3663
|
-
const setTool = (0,
|
|
3664
|
-
const setCrop = (0,
|
|
3682
|
+
const setTool = (0, import_react35.useCallback)((tool) => controller.setTool(tool), [controller]);
|
|
3683
|
+
const setCrop = (0, import_react35.useCallback)(
|
|
3665
3684
|
(crop, addToHistory = true) => controller.setCrop(crop, addToHistory),
|
|
3666
3685
|
[controller]
|
|
3667
3686
|
);
|
|
3668
|
-
const applyCropPreset = (0,
|
|
3669
|
-
const resetCrop = (0,
|
|
3670
|
-
const rotate = (0,
|
|
3671
|
-
const setRotation = (0,
|
|
3672
|
-
const flipHorizontal = (0,
|
|
3673
|
-
const flipVertical = (0,
|
|
3674
|
-
const setAdjustments = (0,
|
|
3687
|
+
const applyCropPreset = (0, import_react35.useCallback)((ratio) => controller.applyCropPreset(ratio), [controller]);
|
|
3688
|
+
const resetCrop = (0, import_react35.useCallback)(() => controller.resetCrop(), [controller]);
|
|
3689
|
+
const rotate = (0, import_react35.useCallback)((deg) => controller.rotate(deg), [controller]);
|
|
3690
|
+
const setRotation = (0, import_react35.useCallback)((deg) => controller.setRotation(deg), [controller]);
|
|
3691
|
+
const flipHorizontal = (0, import_react35.useCallback)(() => controller.flipHorizontal(), [controller]);
|
|
3692
|
+
const flipVertical = (0, import_react35.useCallback)(() => controller.flipVertical(), [controller]);
|
|
3693
|
+
const setAdjustments = (0, import_react35.useCallback)(
|
|
3675
3694
|
(partial, commitToHistory = true) => controller.setAdjustments(partial, commitToHistory),
|
|
3676
3695
|
[controller]
|
|
3677
3696
|
);
|
|
3678
|
-
const resetAdjustments = (0,
|
|
3679
|
-
const upgradeProcess = (0,
|
|
3680
|
-
const addAdjustmentLayer = (0,
|
|
3697
|
+
const resetAdjustments = (0, import_react35.useCallback)(() => controller.resetAdjustments(), [controller]);
|
|
3698
|
+
const upgradeProcess = (0, import_react35.useCallback)(() => controller.upgradeProcess(), [controller]);
|
|
3699
|
+
const addAdjustmentLayer = (0, import_react35.useCallback)(
|
|
3681
3700
|
(init, index) => controller.addAdjustmentLayer(init, index),
|
|
3682
3701
|
[controller]
|
|
3683
3702
|
);
|
|
3684
|
-
const updateAdjustmentLayer = (0,
|
|
3703
|
+
const updateAdjustmentLayer = (0, import_react35.useCallback)(
|
|
3685
3704
|
(id, update, commitToHistory = true) => controller.updateAdjustmentLayer(id, update, commitToHistory),
|
|
3686
3705
|
[controller]
|
|
3687
3706
|
);
|
|
3688
|
-
const removeAdjustmentLayer = (0,
|
|
3689
|
-
const moveAdjustmentLayer = (0,
|
|
3690
|
-
const toggleAdjustmentLayer = (0,
|
|
3707
|
+
const removeAdjustmentLayer = (0, import_react35.useCallback)((id) => controller.removeAdjustmentLayer(id), [controller]);
|
|
3708
|
+
const moveAdjustmentLayer = (0, import_react35.useCallback)((id, to) => controller.moveAdjustmentLayer(id, to), [controller]);
|
|
3709
|
+
const toggleAdjustmentLayer = (0, import_react35.useCallback)(
|
|
3691
3710
|
(id, enabled) => controller.toggleAdjustmentLayer(id, enabled),
|
|
3692
3711
|
[controller]
|
|
3693
3712
|
);
|
|
3694
|
-
const setDepthMask = (0,
|
|
3695
|
-
const resetDepthMask = (0,
|
|
3696
|
-
const addAnnotation = (0,
|
|
3697
|
-
const updateAnnotation = (0,
|
|
3713
|
+
const setDepthMask = (0, import_react35.useCallback)((partial) => controller.setDepthMask(partial), [controller]);
|
|
3714
|
+
const resetDepthMask = (0, import_react35.useCallback)(() => controller.resetDepthMask(), [controller]);
|
|
3715
|
+
const addAnnotation = (0, import_react35.useCallback)((ann) => controller.addAnnotation(ann), [controller]);
|
|
3716
|
+
const updateAnnotation = (0, import_react35.useCallback)(
|
|
3698
3717
|
(id, partial, commitToHistory = true) => controller.updateAnnotation(id, partial, commitToHistory),
|
|
3699
3718
|
[controller]
|
|
3700
3719
|
);
|
|
3701
|
-
const removeAnnotation = (0,
|
|
3702
|
-
const clearAnnotations = (0,
|
|
3703
|
-
const selectAnnotation = (0,
|
|
3704
|
-
const undo = (0,
|
|
3705
|
-
const redo = (0,
|
|
3706
|
-
const reset = (0,
|
|
3707
|
-
const zoomIn = (0,
|
|
3708
|
-
const zoomOut = (0,
|
|
3709
|
-
const resetZoom = (0,
|
|
3710
|
-
const setZoom = (0,
|
|
3711
|
-
const setPan = (0,
|
|
3712
|
-
const setComparing = (0,
|
|
3713
|
-
const loadImage = (0,
|
|
3714
|
-
const toDataURL = (0,
|
|
3715
|
-
const toBlob = (0,
|
|
3716
|
-
const toJSON = (0,
|
|
3717
|
-
const loadJSON = (0,
|
|
3718
|
-
const renderMask = (0,
|
|
3720
|
+
const removeAnnotation = (0, import_react35.useCallback)((id) => controller.removeAnnotation(id), [controller]);
|
|
3721
|
+
const clearAnnotations = (0, import_react35.useCallback)(() => controller.clearAnnotations(), [controller]);
|
|
3722
|
+
const selectAnnotation = (0, import_react35.useCallback)((id) => controller.selectAnnotation(id), [controller]);
|
|
3723
|
+
const undo = (0, import_react35.useCallback)(() => controller.undo(), [controller]);
|
|
3724
|
+
const redo = (0, import_react35.useCallback)(() => controller.redo(), [controller]);
|
|
3725
|
+
const reset = (0, import_react35.useCallback)(() => controller.reset(), [controller]);
|
|
3726
|
+
const zoomIn = (0, import_react35.useCallback)((factor) => controller.zoomIn(factor), [controller]);
|
|
3727
|
+
const zoomOut = (0, import_react35.useCallback)((factor) => controller.zoomOut(factor), [controller]);
|
|
3728
|
+
const resetZoom = (0, import_react35.useCallback)(() => controller.resetZoom(), [controller]);
|
|
3729
|
+
const setZoom = (0, import_react35.useCallback)((zoom) => controller.setZoom(zoom), [controller]);
|
|
3730
|
+
const setPan = (0, import_react35.useCallback)((pan) => controller.setPan(pan), [controller]);
|
|
3731
|
+
const setComparing = (0, import_react35.useCallback)((comp) => controller.setComparing(comp), [controller]);
|
|
3732
|
+
const loadImage = (0, import_react35.useCallback)((src) => controller.loadImage(src), [controller]);
|
|
3733
|
+
const toDataURL = (0, import_react35.useCallback)((opts) => controller.toDataURL(opts), [controller]);
|
|
3734
|
+
const toBlob = (0, import_react35.useCallback)((opts) => controller.toBlob(opts), [controller]);
|
|
3735
|
+
const toJSON = (0, import_react35.useCallback)(() => controller.toJSON(), [controller]);
|
|
3736
|
+
const loadJSON = (0, import_react35.useCallback)((data) => controller.loadJSON(data), [controller]);
|
|
3737
|
+
const renderMask = (0, import_react35.useCallback)(
|
|
3719
3738
|
(opts) => controller.renderMask(opts),
|
|
3720
3739
|
[controller]
|
|
3721
3740
|
);
|
|
3722
|
-
const toMaskDataURL = (0,
|
|
3741
|
+
const toMaskDataURL = (0, import_react35.useCallback)(
|
|
3723
3742
|
(opts) => controller.toMaskDataURL(opts),
|
|
3724
3743
|
[controller]
|
|
3725
3744
|
);
|
|
3726
|
-
const toSourceDataURL = (0,
|
|
3745
|
+
const toSourceDataURL = (0, import_react35.useCallback)(
|
|
3727
3746
|
(opts) => controller.toSourceDataURL(opts),
|
|
3728
3747
|
[controller]
|
|
3729
3748
|
);
|
|
3730
|
-
const applyInpaintedImage = (0,
|
|
3749
|
+
const applyInpaintedImage = (0, import_react35.useCallback)(
|
|
3731
3750
|
(newDataUrl, options2) => controller.applyInpaintedImage(newDataUrl, options2),
|
|
3732
3751
|
[controller]
|
|
3733
3752
|
);
|
|
3734
|
-
const applyBackgroundRemovedImage = (0,
|
|
3753
|
+
const applyBackgroundRemovedImage = (0, import_react35.useCallback)(
|
|
3735
3754
|
(newDataUrl, options2) => controller.applyBackgroundRemovedImage(newDataUrl, options2),
|
|
3736
3755
|
[controller]
|
|
3737
3756
|
);
|
|
3738
|
-
return (0,
|
|
3757
|
+
return (0, import_react35.useMemo)(
|
|
3739
3758
|
() => ({
|
|
3740
3759
|
controller,
|
|
3741
3760
|
state,
|
|
@@ -3791,14 +3810,14 @@ function useImageEditor(options = {}) {
|
|
|
3791
3810
|
}
|
|
3792
3811
|
function useImageEffectsTools(registry, controller, options = {}) {
|
|
3793
3812
|
const { id, namespace, readOnly } = options;
|
|
3794
|
-
(0,
|
|
3813
|
+
(0, import_react35.useEffect)(() => {
|
|
3795
3814
|
if (!registry) return;
|
|
3796
3815
|
return registry.register((0, import_image_editor.createImageEffectsToolProvider)(controller, { id, namespace, readOnly }));
|
|
3797
3816
|
}, [registry, controller, id, namespace, readOnly]);
|
|
3798
3817
|
}
|
|
3799
3818
|
|
|
3800
3819
|
// src/image-editor/ImageEditor.tsx
|
|
3801
|
-
var
|
|
3820
|
+
var import_react55 = __toESM(require("react"), 1);
|
|
3802
3821
|
var import_image_editor18 = require("@pixerate/editor/image-editor");
|
|
3803
3822
|
|
|
3804
3823
|
// src/image-editor/ControlSlider.tsx
|
|
@@ -3831,7 +3850,7 @@ var ControlSlider = ({ spec, value, onChange, disabled, label }) => {
|
|
|
3831
3850
|
};
|
|
3832
3851
|
|
|
3833
3852
|
// src/image-editor/Histogram.tsx
|
|
3834
|
-
var
|
|
3853
|
+
var import_react36 = require("react");
|
|
3835
3854
|
var import_image_editor3 = require("@pixerate/editor/image-editor");
|
|
3836
3855
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
3837
3856
|
var FILL = {
|
|
@@ -3843,7 +3862,7 @@ var FILL = {
|
|
|
3843
3862
|
var W = 256;
|
|
3844
3863
|
var Histogram = ({ histogram, channel = "rgb", height = 64, className = "", style }) => {
|
|
3845
3864
|
const channels = channel === "rgb" ? ["luminance", "red", "green", "blue"] : [channel];
|
|
3846
|
-
const paths = (0,
|
|
3865
|
+
const paths = (0, import_react36.useMemo)(
|
|
3847
3866
|
() => histogram && histogram.samples > 0 ? channels.map((c) => ({ c, d: (0, import_image_editor3.histogramPath)(histogram, c, W, height) })) : [],
|
|
3848
3867
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3849
3868
|
[histogram, channel, height]
|
|
@@ -3869,24 +3888,24 @@ var Histogram = ({ histogram, channel = "rgb", height = 64, className = "", styl
|
|
|
3869
3888
|
);
|
|
3870
3889
|
};
|
|
3871
3890
|
function useImageHistogram(controller) {
|
|
3872
|
-
const [histogram, setHistogram] = (0,
|
|
3873
|
-
(0,
|
|
3891
|
+
const [histogram, setHistogram] = (0, import_react36.useState)(() => controller.getHistogram());
|
|
3892
|
+
(0, import_react36.useEffect)(() => controller.subscribeHistogram(setHistogram), [controller]);
|
|
3874
3893
|
return histogram;
|
|
3875
3894
|
}
|
|
3876
3895
|
|
|
3877
3896
|
// src/image-editor/AdjustmentLayersPanel.tsx
|
|
3878
|
-
var
|
|
3897
|
+
var import_react38 = require("react");
|
|
3879
3898
|
var import_image_editor5 = require("@pixerate/editor/image-editor");
|
|
3880
3899
|
|
|
3881
3900
|
// src/image-editor/CurvesEditor.tsx
|
|
3882
|
-
var
|
|
3901
|
+
var import_react37 = require("react");
|
|
3883
3902
|
var import_image_editor4 = require("@pixerate/editor/image-editor");
|
|
3884
3903
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3885
3904
|
var BOX = 256;
|
|
3886
3905
|
var STROKE = { master: "#e2e8f0", red: "#ef4444", green: "#22c55e", blue: "#3b82f6" };
|
|
3887
3906
|
var CurvesEditor = ({ points, onChange, histogram, channel = "master", size = 200 }) => {
|
|
3888
|
-
const svgRef = (0,
|
|
3889
|
-
const [drag, setDrag] = (0,
|
|
3907
|
+
const svgRef = (0, import_react37.useRef)(null);
|
|
3908
|
+
const [drag, setDrag] = (0, import_react37.useState)(null);
|
|
3890
3909
|
const toBox = (e) => {
|
|
3891
3910
|
const rect = svgRef.current?.getBoundingClientRect();
|
|
3892
3911
|
if (!rect || !rect.width || !rect.height) return { x: 0, y: 0 };
|
|
@@ -3985,14 +4004,14 @@ var HueRangeStrip = ({ bounds }) => {
|
|
|
3985
4004
|
};
|
|
3986
4005
|
var AdjustmentLayersPanel = ({ controller, layers: layersProp, histogram }) => {
|
|
3987
4006
|
const follow = layersProp === void 0;
|
|
3988
|
-
const [, setTick] = (0,
|
|
3989
|
-
(0,
|
|
4007
|
+
const [, setTick] = (0, import_react38.useState)(0);
|
|
4008
|
+
(0, import_react38.useEffect)(() => follow ? controller.subscribe(() => setTick((n) => n + 1)) : void 0, [controller, follow]);
|
|
3990
4009
|
const layers = layersProp ?? controller.getAdjustmentLayers();
|
|
3991
|
-
const [newKind, setNewKind] = (0,
|
|
3992
|
-
const [selectedId, setSelectedId] = (0,
|
|
3993
|
-
const [channel, setChannel] = (0,
|
|
3994
|
-
const [range, setRange] = (0,
|
|
3995
|
-
const [tone, setTone] = (0,
|
|
4010
|
+
const [newKind, setNewKind] = (0, import_react38.useState)("curves");
|
|
4011
|
+
const [selectedId, setSelectedId] = (0, import_react38.useState)(null);
|
|
4012
|
+
const [channel, setChannel] = (0, import_react38.useState)("master");
|
|
4013
|
+
const [range, setRange] = (0, import_react38.useState)(-1);
|
|
4014
|
+
const [tone, setTone] = (0, import_react38.useState)("midtones");
|
|
3996
4015
|
const selected = layers.find((l) => l.id === selectedId) ?? null;
|
|
3997
4016
|
const topFirst = [...layers].reverse();
|
|
3998
4017
|
const setParam = (layer, path, value, commit = true) => controller.updateAdjustmentLayer(layer.id, { params: (0, import_image_editor5.setControlPath)(layer.params, path, value) }, commit);
|
|
@@ -4231,19 +4250,19 @@ var AdjustmentLayersPanel = ({ controller, layers: layersProp, histogram }) => {
|
|
|
4231
4250
|
};
|
|
4232
4251
|
|
|
4233
4252
|
// src/image-editor/LayersPanel.tsx
|
|
4234
|
-
var
|
|
4253
|
+
var import_react40 = require("react");
|
|
4235
4254
|
|
|
4236
4255
|
// src/image-editor/LayerEffectsPanel.tsx
|
|
4237
|
-
var
|
|
4256
|
+
var import_react39 = require("react");
|
|
4238
4257
|
var import_image_editor6 = require("@pixerate/editor/image-editor");
|
|
4239
4258
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
4240
4259
|
var button = "px-1.5 py-0.5 rounded text-[10px] bg-slate-800 text-slate-300 hover:text-white disabled:opacity-40";
|
|
4241
4260
|
var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
4242
|
-
const [, setTick] = (0,
|
|
4243
|
-
(0,
|
|
4244
|
-
const [open, setOpen] = (0,
|
|
4245
|
-
const [error, setError] = (0,
|
|
4246
|
-
const commitNext = (0,
|
|
4261
|
+
const [, setTick] = (0, import_react39.useState)(0);
|
|
4262
|
+
(0, import_react39.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
4263
|
+
const [open, setOpen] = (0, import_react39.useState)(null);
|
|
4264
|
+
const [error, setError] = (0, import_react39.useState)(null);
|
|
4265
|
+
const commitNext = (0, import_react39.useRef)(true);
|
|
4247
4266
|
const layer = layerId ? controller.getLayer(layerId) : controller.getActiveLayer();
|
|
4248
4267
|
const model = (0, import_image_editor6.layerEffectsPanel)(layer);
|
|
4249
4268
|
const id = layer?.id;
|
|
@@ -4433,8 +4452,8 @@ var Thumbnail = ({
|
|
|
4433
4452
|
selected,
|
|
4434
4453
|
testId
|
|
4435
4454
|
}) => {
|
|
4436
|
-
const ref = (0,
|
|
4437
|
-
(0,
|
|
4455
|
+
const ref = (0, import_react40.useRef)(null);
|
|
4456
|
+
(0, import_react40.useEffect)(() => {
|
|
4438
4457
|
const canvas = ref.current;
|
|
4439
4458
|
const ctx = canvas?.getContext("2d");
|
|
4440
4459
|
if (!canvas || !ctx || !pixels || typeof ctx.createImageData !== "function") return;
|
|
@@ -4458,14 +4477,14 @@ var Thumbnail = ({
|
|
|
4458
4477
|
);
|
|
4459
4478
|
};
|
|
4460
4479
|
var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "image", effects = true, className }) => {
|
|
4461
|
-
const [, setTick] = (0,
|
|
4462
|
-
(0,
|
|
4463
|
-
const [error, setError] = (0,
|
|
4464
|
-
const [renaming, setRenaming] = (0,
|
|
4465
|
-
const [menu, setMenu] = (0,
|
|
4466
|
-
const [drag, setDrag] = (0,
|
|
4467
|
-
const [psdNotes, setPsdNotes] = (0,
|
|
4468
|
-
const fileInput = (0,
|
|
4480
|
+
const [, setTick] = (0, import_react40.useState)(0);
|
|
4481
|
+
(0, import_react40.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
4482
|
+
const [error, setError] = (0, import_react40.useState)(null);
|
|
4483
|
+
const [renaming, setRenaming] = (0, import_react40.useState)(null);
|
|
4484
|
+
const [menu, setMenu] = (0, import_react40.useState)(null);
|
|
4485
|
+
const [drag, setDrag] = (0, import_react40.useState)(null);
|
|
4486
|
+
const [psdNotes, setPsdNotes] = (0, import_react40.useState)([]);
|
|
4487
|
+
const fileInput = (0, import_react40.useRef)(null);
|
|
4469
4488
|
const psdTask = async (fn) => {
|
|
4470
4489
|
try {
|
|
4471
4490
|
setError(null);
|
|
@@ -4474,7 +4493,7 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
4474
4493
|
setError(err instanceof Error ? err.message : String(err));
|
|
4475
4494
|
}
|
|
4476
4495
|
};
|
|
4477
|
-
const commitNext = (0,
|
|
4496
|
+
const commitNext = (0, import_react40.useRef)(true);
|
|
4478
4497
|
const state = controller.getState();
|
|
4479
4498
|
const rows = (0, import_image_editor7.layerPanelRows)(state.layers, state.activeLayerId);
|
|
4480
4499
|
const active = controller.getActiveLayer();
|
|
@@ -4849,21 +4868,21 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
4849
4868
|
};
|
|
4850
4869
|
|
|
4851
4870
|
// src/image-editor/ImageProviderEffectsPanel.tsx
|
|
4852
|
-
var
|
|
4871
|
+
var import_react46 = __toESM(require("react"), 1);
|
|
4853
4872
|
var import_image_editor8 = require("@pixerate/editor/image-editor");
|
|
4854
4873
|
|
|
4855
4874
|
// src/effects/useEffects.ts
|
|
4856
|
-
var
|
|
4875
|
+
var import_react41 = require("react");
|
|
4857
4876
|
function useEffects(host, provider) {
|
|
4858
|
-
(0,
|
|
4877
|
+
(0, import_react41.useEffect)(() => {
|
|
4859
4878
|
if (!host || !provider) return;
|
|
4860
4879
|
return host.useEffects(provider);
|
|
4861
4880
|
}, [host, provider]);
|
|
4862
4881
|
}
|
|
4863
4882
|
function useEffectDescription(provider, effect) {
|
|
4864
|
-
const [state, setState] = (0,
|
|
4883
|
+
const [state, setState] = (0, import_react41.useState)({ key: "", description: null, error: null });
|
|
4865
4884
|
const key = provider && effect ? `${provider.id}:${effect}` : "";
|
|
4866
|
-
(0,
|
|
4885
|
+
(0, import_react41.useEffect)(() => {
|
|
4867
4886
|
if (!provider || !effect) return;
|
|
4868
4887
|
let live = true;
|
|
4869
4888
|
Promise.resolve().then(() => provider.describe(effect)).then(
|
|
@@ -4878,13 +4897,13 @@ function useEffectDescription(provider, effect) {
|
|
|
4878
4897
|
}
|
|
4879
4898
|
|
|
4880
4899
|
// src/effects/EffectThumbnail.tsx
|
|
4881
|
-
var
|
|
4900
|
+
var import_react42 = require("react");
|
|
4882
4901
|
var import_effects = require("@pixerate/editor/effects");
|
|
4883
4902
|
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
4884
4903
|
function EffectThumbnail({ provider, effect, width = 96, height = 54, className = "" }) {
|
|
4885
|
-
const ref = (0,
|
|
4886
|
-
const [failed, setFailed] = (0,
|
|
4887
|
-
(0,
|
|
4904
|
+
const ref = (0, import_react42.useRef)(null);
|
|
4905
|
+
const [failed, setFailed] = (0, import_react42.useState)(effect.kind === "motion");
|
|
4906
|
+
(0, import_react42.useEffect)(() => {
|
|
4888
4907
|
if (effect.kind === "motion") return;
|
|
4889
4908
|
let live = true;
|
|
4890
4909
|
(0, import_effects.renderEffectThumbnail)(provider, effect, { width, height }).then(
|
|
@@ -4911,16 +4930,16 @@ function EffectThumbnail({ provider, effect, width = 96, height = 54, className
|
|
|
4911
4930
|
}
|
|
4912
4931
|
|
|
4913
4932
|
// src/effects/EffectsBrowser.tsx
|
|
4914
|
-
var
|
|
4933
|
+
var import_react43 = require("react");
|
|
4915
4934
|
var import_effects2 = require("@pixerate/editor/effects");
|
|
4916
4935
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
4917
4936
|
function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, title = "Effects", className = "" }) {
|
|
4918
|
-
const [all, setAll] = (0,
|
|
4919
|
-
const [query, setQuery] = (0,
|
|
4920
|
-
const [category, setCategory] = (0,
|
|
4921
|
-
const [use, setUse] = (0,
|
|
4922
|
-
const [error, setError] = (0,
|
|
4923
|
-
(0,
|
|
4937
|
+
const [all, setAll] = (0, import_react43.useState)([]);
|
|
4938
|
+
const [query, setQuery] = (0, import_react43.useState)("");
|
|
4939
|
+
const [category, setCategory] = (0, import_react43.useState)("");
|
|
4940
|
+
const [use, setUse] = (0, import_react43.useState)("");
|
|
4941
|
+
const [error, setError] = (0, import_react43.useState)(null);
|
|
4942
|
+
(0, import_react43.useEffect)(() => {
|
|
4924
4943
|
if (!provider) return setAll([]);
|
|
4925
4944
|
let live = true;
|
|
4926
4945
|
Promise.resolve().then(() => provider.list()).then(
|
|
@@ -4931,8 +4950,8 @@ function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, titl
|
|
|
4931
4950
|
live = false;
|
|
4932
4951
|
};
|
|
4933
4952
|
}, [provider]);
|
|
4934
|
-
const [found, setFound] = (0,
|
|
4935
|
-
(0,
|
|
4953
|
+
const [found, setFound] = (0, import_react43.useState)([]);
|
|
4954
|
+
(0, import_react43.useEffect)(() => {
|
|
4936
4955
|
if (!provider) return setFound([]);
|
|
4937
4956
|
let live = true;
|
|
4938
4957
|
Promise.resolve().then(() => provider.search(query, { ...category ? { category } : {}, ...use ? { use } : {} })).then((list) => live && setFound(list), () => live && setFound([]));
|
|
@@ -4941,7 +4960,7 @@ function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, titl
|
|
|
4941
4960
|
};
|
|
4942
4961
|
}, [provider, query, category, use]);
|
|
4943
4962
|
const allowed = (e) => (!kinds || kinds.includes(e.kind)) && (uses ? e.kind !== "motion" || uses.includes("motion") : e.kind !== "motion") && (!uses || e.uses.some((u) => uses.includes(u)));
|
|
4944
|
-
const categories = (0,
|
|
4963
|
+
const categories = (0, import_react43.useMemo)(() => [...new Set(all.filter(allowed).map((e) => e.category))], [all, uses, kinds]);
|
|
4945
4964
|
const shown = found.filter(allowed);
|
|
4946
4965
|
if (!provider)
|
|
4947
4966
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: `rounded-md border border-dashed border-border p-3 text-xs text-muted-foreground ${className}`, "data-effects-browser": "", "data-effects-unavailable": "", children: "No effects provider is registered, so effects cannot be added. Effects already in the document are kept." });
|
|
@@ -4989,12 +5008,12 @@ function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, titl
|
|
|
4989
5008
|
}
|
|
4990
5009
|
|
|
4991
5010
|
// src/effects/EffectParameters.tsx
|
|
4992
|
-
var
|
|
5011
|
+
var import_react45 = __toESM(require("react"), 1);
|
|
4993
5012
|
var import_effects3 = require("@pixerate/editor/effects");
|
|
4994
5013
|
var import_parameters2 = require("@pixerate/editor/parameters");
|
|
4995
5014
|
|
|
4996
5015
|
// src/parameters/fields.tsx
|
|
4997
|
-
var
|
|
5016
|
+
var import_react44 = require("react");
|
|
4998
5017
|
var import_parameters = require("@pixerate/editor/parameters");
|
|
4999
5018
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
5000
5019
|
var parameterInputClass = "h-7 w-full min-w-0 rounded-md border border-input bg-background px-2 text-xs text-foreground tabular-nums focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
@@ -5059,7 +5078,7 @@ function ParameterNumberInput({
|
|
|
5059
5078
|
}
|
|
5060
5079
|
function ParameterSlider(props) {
|
|
5061
5080
|
const { field, value, onChange, onGestureStart, onGestureEnd, disabled } = props;
|
|
5062
|
-
const dragging = (0,
|
|
5081
|
+
const dragging = (0, import_react44.useRef)(false);
|
|
5063
5082
|
const end = () => {
|
|
5064
5083
|
if (!dragging.current) return;
|
|
5065
5084
|
dragging.current = false;
|
|
@@ -5152,7 +5171,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
|
|
|
5152
5171
|
);
|
|
5153
5172
|
}
|
|
5154
5173
|
function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd, disabled, id }) {
|
|
5155
|
-
const picking = (0,
|
|
5174
|
+
const picking = (0, import_react44.useRef)(false);
|
|
5156
5175
|
const alpha = !!field.alpha;
|
|
5157
5176
|
const hex = (0, import_parameters.normalizeHexColor)(value, true) ?? "#000000ff";
|
|
5158
5177
|
const rgb = hex.slice(0, 7);
|
|
@@ -5358,10 +5377,10 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
|
|
|
5358
5377
|
// src/effects/EffectParameters.tsx
|
|
5359
5378
|
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
5360
5379
|
function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
|
|
5361
|
-
const fields = (0,
|
|
5362
|
-
const idBase = (0,
|
|
5363
|
-
const gesture =
|
|
5364
|
-
const count =
|
|
5380
|
+
const fields = (0, import_react45.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
|
|
5381
|
+
const idBase = (0, import_react45.useId)();
|
|
5382
|
+
const gesture = import_react45.default.useRef(null);
|
|
5383
|
+
const count = import_react45.default.useRef(0);
|
|
5365
5384
|
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
|
|
5366
5385
|
onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
|
|
5367
5386
|
"select",
|
|
@@ -5432,11 +5451,11 @@ function Controls({
|
|
|
5432
5451
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(EffectParameters, { description, values, onChange, onReset: (k) => onChange(k, description.defaults[k], null), onPreset });
|
|
5433
5452
|
}
|
|
5434
5453
|
function ImageProviderEffectsPanel({ controller, className = "" }) {
|
|
5435
|
-
const [, setTick] = (0,
|
|
5436
|
-
(0,
|
|
5437
|
-
const [browse, setBrowse] = (0,
|
|
5438
|
-
const [message, setMessage] = (0,
|
|
5439
|
-
const [open, setOpen] = (0,
|
|
5454
|
+
const [, setTick] = (0, import_react46.useState)(0);
|
|
5455
|
+
(0, import_react46.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
5456
|
+
const [browse, setBrowse] = (0, import_react46.useState)(null);
|
|
5457
|
+
const [message, setMessage] = (0, import_react46.useState)(null);
|
|
5458
|
+
const [open, setOpen] = (0, import_react46.useState)(null);
|
|
5440
5459
|
const provider = controller.effectsProvider;
|
|
5441
5460
|
const state = controller.getState();
|
|
5442
5461
|
const layer = state.activeLayerId ? (0, import_image_editor8.findLayer)(state.layers, state.activeLayerId)?.layer ?? null : null;
|
|
@@ -5444,7 +5463,7 @@ function ImageProviderEffectsPanel({ controller, className = "" }) {
|
|
|
5444
5463
|
setMessage(null);
|
|
5445
5464
|
Promise.resolve().then(work).catch((e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
5446
5465
|
};
|
|
5447
|
-
const drags =
|
|
5466
|
+
const drags = import_react46.default.useRef(/* @__PURE__ */ new Set());
|
|
5448
5467
|
const commit = (gesture) => {
|
|
5449
5468
|
if (gesture) {
|
|
5450
5469
|
if (!drags.current.has(gesture)) {
|
|
@@ -5540,7 +5559,7 @@ function ImageProviderEffectsPanel({ controller, className = "" }) {
|
|
|
5540
5559
|
}
|
|
5541
5560
|
|
|
5542
5561
|
// src/image-editor/BrushOptionsBar.tsx
|
|
5543
|
-
var
|
|
5562
|
+
var import_react48 = require("react");
|
|
5544
5563
|
var import_image_editor10 = require("@pixerate/editor/image-editor");
|
|
5545
5564
|
var import_image_editor11 = require("@pixerate/editor/image-editor");
|
|
5546
5565
|
|
|
@@ -5548,7 +5567,7 @@ var import_image_editor11 = require("@pixerate/editor/image-editor");
|
|
|
5548
5567
|
var import_image_editor9 = require("@pixerate/editor/image-editor");
|
|
5549
5568
|
|
|
5550
5569
|
// src/paint-editor/PaintGradientEditorView.tsx
|
|
5551
|
-
var
|
|
5570
|
+
var import_react47 = require("react");
|
|
5552
5571
|
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
5553
5572
|
var button2 = "px-2 py-1 rounded text-[11px] bg-slate-800 text-slate-200 hover:bg-slate-700 disabled:opacity-40";
|
|
5554
5573
|
var select = "rounded bg-slate-800 px-1 py-0.5 text-[11px]";
|
|
@@ -5570,7 +5589,7 @@ var PaintGradientEditorView = ({ value, onChange, colors, className, kit }) => {
|
|
|
5570
5589
|
reversePaintGradient,
|
|
5571
5590
|
updatePaintGradientStop
|
|
5572
5591
|
} = kit;
|
|
5573
|
-
const [selected, setSelected] = (0,
|
|
5592
|
+
const [selected, setSelected] = (0, import_react47.useState)(0);
|
|
5574
5593
|
const sel = Math.min(selected, value.stops.length - 1);
|
|
5575
5594
|
const stop = value.stops[sel];
|
|
5576
5595
|
const map = value.map;
|
|
@@ -5677,9 +5696,9 @@ var PaintGradientEditor = (props) => /* @__PURE__ */ (0, import_jsx_runtime29.js
|
|
|
5677
5696
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
5678
5697
|
var chip = (on) => `px-2 py-1 rounded text-[11px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300 hover:text-white"}`;
|
|
5679
5698
|
var BrushOptionsBar = ({ controller, className }) => {
|
|
5680
|
-
const [, setTick] = (0,
|
|
5681
|
-
(0,
|
|
5682
|
-
const [error, setError] = (0,
|
|
5699
|
+
const [, setTick] = (0, import_react48.useState)(0);
|
|
5700
|
+
(0, import_react48.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
5701
|
+
const [error, setError] = (0, import_react48.useState)(null);
|
|
5683
5702
|
const state = controller.getState();
|
|
5684
5703
|
const { brush, foreground, background, mixer, mixerLoad, retouch, cloneSource, paint } = state.paint;
|
|
5685
5704
|
const tool = state.activeTool;
|
|
@@ -5891,18 +5910,18 @@ var BrushOptionsBar = ({ controller, className }) => {
|
|
|
5891
5910
|
};
|
|
5892
5911
|
|
|
5893
5912
|
// src/image-editor/ColorProfilePanel.tsx
|
|
5894
|
-
var
|
|
5913
|
+
var import_react49 = require("react");
|
|
5895
5914
|
var import_image_editor12 = require("@pixerate/editor/image-editor");
|
|
5896
5915
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
5897
5916
|
var chip2 = "px-2 py-1 rounded text-[11px] bg-slate-800 text-slate-300 hover:text-white";
|
|
5898
5917
|
var select2 = "rounded bg-slate-800 px-1 py-0.5 text-[11px] text-slate-200";
|
|
5899
5918
|
var ColorProfilePanel = ({ controller, className }) => {
|
|
5900
|
-
const [, setTick] = (0,
|
|
5901
|
-
(0,
|
|
5902
|
-
const [target, setTarget] = (0,
|
|
5903
|
-
const [intent, setIntent] = (0,
|
|
5904
|
-
const [bpc, setBpc] = (0,
|
|
5905
|
-
const [error, setError] = (0,
|
|
5919
|
+
const [, setTick] = (0, import_react49.useState)(0);
|
|
5920
|
+
(0, import_react49.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
5921
|
+
const [target, setTarget] = (0, import_react49.useState)("display-p3");
|
|
5922
|
+
const [intent, setIntent] = (0, import_react49.useState)("relative");
|
|
5923
|
+
const [bpc, setBpc] = (0, import_react49.useState)(true);
|
|
5924
|
+
const [error, setError] = (0, import_react49.useState)(null);
|
|
5906
5925
|
const view = (0, import_image_editor12.colorPanelView)(controller);
|
|
5907
5926
|
const attempt = (fn) => {
|
|
5908
5927
|
try {
|
|
@@ -5976,7 +5995,7 @@ var ColorProfilePanel = ({ controller, className }) => {
|
|
|
5976
5995
|
};
|
|
5977
5996
|
|
|
5978
5997
|
// src/image-editor/SelectionOptionsBar.tsx
|
|
5979
|
-
var
|
|
5998
|
+
var import_react50 = require("react");
|
|
5980
5999
|
var import_image_editor13 = require("@pixerate/editor/image-editor");
|
|
5981
6000
|
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
5982
6001
|
var MODIFY_OPS = [
|
|
@@ -5995,7 +6014,7 @@ var SelectionOptionsBar = ({
|
|
|
5995
6014
|
quickMask,
|
|
5996
6015
|
className = ""
|
|
5997
6016
|
}) => {
|
|
5998
|
-
const [radius, setRadius] = (0,
|
|
6017
|
+
const [radius, setRadius] = (0, import_react50.useState)(2);
|
|
5999
6018
|
const set = (patch) => onOptionsChange({ ...options, ...patch });
|
|
6000
6019
|
const sel = selection === void 0 ? controller.getSelection() : selection;
|
|
6001
6020
|
const qm = quickMask ?? Boolean(controller.getState().quickMask);
|
|
@@ -6081,17 +6100,17 @@ var SelectionOptionsBar = ({
|
|
|
6081
6100
|
};
|
|
6082
6101
|
|
|
6083
6102
|
// src/image-editor/RefineEdgePanel.tsx
|
|
6084
|
-
var
|
|
6103
|
+
var import_react51 = require("react");
|
|
6085
6104
|
var import_image_editor14 = require("@pixerate/editor/image-editor");
|
|
6086
6105
|
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
6087
6106
|
var DEFAULT_PARAMS = { radius: 8, smartRadius: false, smooth: 0, feather: 0, contrast: 0, shiftEdge: 0 };
|
|
6088
6107
|
var button3 = "px-2 py-1 rounded-md border border-slate-800 bg-slate-950 text-[11px] text-slate-200 hover:text-white disabled:opacity-40";
|
|
6089
6108
|
var RefineEdgePanel = ({ controller, selection, layers, className = "" }) => {
|
|
6090
|
-
const [params, setParams] = (0,
|
|
6091
|
-
const [busy, setBusy] = (0,
|
|
6092
|
-
const [error, setError] = (0,
|
|
6093
|
-
const [layerId, setLayerId] = (0,
|
|
6094
|
-
const [newKind, setNewKind] = (0,
|
|
6109
|
+
const [params, setParams] = (0, import_react51.useState)(DEFAULT_PARAMS);
|
|
6110
|
+
const [busy, setBusy] = (0, import_react51.useState)(false);
|
|
6111
|
+
const [error, setError] = (0, import_react51.useState)(null);
|
|
6112
|
+
const [layerId, setLayerId] = (0, import_react51.useState)("");
|
|
6113
|
+
const [newKind, setNewKind] = (0, import_react51.useState)("hueSaturation");
|
|
6095
6114
|
const sel = selection === void 0 ? controller.getSelection() : selection;
|
|
6096
6115
|
const list = layers ?? controller.getAdjustmentLayers();
|
|
6097
6116
|
const target = list.find((l) => l.id === layerId) ?? list[list.length - 1];
|
|
@@ -6232,14 +6251,14 @@ var RefineEdgePanel = ({ controller, selection, layers, className = "" }) => {
|
|
|
6232
6251
|
};
|
|
6233
6252
|
|
|
6234
6253
|
// src/image-editor/FreeTransformOptionsBar.tsx
|
|
6235
|
-
var
|
|
6254
|
+
var import_react52 = require("react");
|
|
6236
6255
|
var import_image_editor15 = require("@pixerate/editor/image-editor");
|
|
6237
6256
|
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
6238
6257
|
var chip3 = (on) => `px-2 py-1 rounded text-[11px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300 hover:text-white"}`;
|
|
6239
6258
|
var round = (v, unit) => unit === "px" ? Math.round(v * 10) / 10 : Math.round(v * 100) / 100;
|
|
6240
6259
|
var FreeTransformOptionsBar = ({ tool, className }) => {
|
|
6241
|
-
const [, setTick] = (0,
|
|
6242
|
-
(0,
|
|
6260
|
+
const [, setTick] = (0, import_react52.useState)(0);
|
|
6261
|
+
(0, import_react52.useEffect)(() => tool.subscribe(() => setTick((n) => n + 1)), [tool]);
|
|
6243
6262
|
const bar = tool.bar();
|
|
6244
6263
|
if (!tool.active || !bar) return null;
|
|
6245
6264
|
const warp = tool.warpBar();
|
|
@@ -6371,14 +6390,14 @@ var FreeTransformOptionsBar = ({ tool, className }) => {
|
|
|
6371
6390
|
};
|
|
6372
6391
|
|
|
6373
6392
|
// src/image-editor/ShapeOptionsBar.tsx
|
|
6374
|
-
var
|
|
6393
|
+
var import_react53 = require("react");
|
|
6375
6394
|
var import_image_editor16 = require("@pixerate/editor/image-editor");
|
|
6376
6395
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
6377
6396
|
var chip4 = (on) => `px-2 py-1 rounded text-[11px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300 hover:text-white"}`;
|
|
6378
6397
|
var ShapeOptionsBar = ({ controller, options, onChange, className }) => {
|
|
6379
|
-
const [, setTick] = (0,
|
|
6380
|
-
(0,
|
|
6381
|
-
const [error, setError] = (0,
|
|
6398
|
+
const [, setTick] = (0, import_react53.useState)(0);
|
|
6399
|
+
(0, import_react53.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
6400
|
+
const [error, setError] = (0, import_react53.useState)(null);
|
|
6382
6401
|
const active = controller.getActiveLayer();
|
|
6383
6402
|
const shapeId = active?.type === "shape" ? active.id : null;
|
|
6384
6403
|
const set = (change) => {
|
|
@@ -6489,16 +6508,16 @@ var ShapeOptionsBar = ({ controller, options, onChange, className }) => {
|
|
|
6489
6508
|
};
|
|
6490
6509
|
|
|
6491
6510
|
// src/image-editor/TypeOptionsBar.tsx
|
|
6492
|
-
var
|
|
6511
|
+
var import_react54 = require("react");
|
|
6493
6512
|
var import_image_editor17 = require("@pixerate/editor/image-editor");
|
|
6494
6513
|
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
6495
6514
|
var chip5 = (on) => `px-2 py-1 rounded text-[11px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300 hover:text-white"}`;
|
|
6496
6515
|
var ALIGN_LABELS = { left: "Left", center: "Centre", right: "Right", justify: "Justify" };
|
|
6497
6516
|
var TypeOptionsBar = ({ controller, options, onChange, session, className }) => {
|
|
6498
|
-
const [, setTick] = (0,
|
|
6499
|
-
(0,
|
|
6500
|
-
(0,
|
|
6501
|
-
const [error, setError] = (0,
|
|
6517
|
+
const [, setTick] = (0, import_react54.useState)(0);
|
|
6518
|
+
(0, import_react54.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
6519
|
+
(0, import_react54.useEffect)(() => session?.subscribe(() => setTick((n) => n + 1)), [session]);
|
|
6520
|
+
const [error, setError] = (0, import_react54.useState)(null);
|
|
6502
6521
|
const active = controller.getActiveLayer();
|
|
6503
6522
|
const typeId = !session && active?.type === "type" ? active.id : null;
|
|
6504
6523
|
const here = session?.alive ? session.styleHere() : {};
|
|
@@ -6599,29 +6618,29 @@ var ImageEditor = ({
|
|
|
6599
6618
|
return l.type === "pixel" && !!l.generator || l.type === "smart" && !!l.smartFilters?.filters.some((f) => f.kind === "effect") || l.type === "group" && l.children.some(has);
|
|
6600
6619
|
});
|
|
6601
6620
|
const legacyProcess = (0, import_image_editor18.normalizeProcessVersion)(state.adjustments.process) < import_image_editor18.LATEST_PROCESS_VERSION;
|
|
6602
|
-
const canvasRef = (0,
|
|
6603
|
-
const containerRef = (0,
|
|
6604
|
-
const [activeTab, setActiveTab] = (0,
|
|
6605
|
-
const [activeCropRatio, setActiveCropRatio] = (0,
|
|
6606
|
-
const [selectionOptions, setSelectionOptions] = (0,
|
|
6607
|
-
const selectionOptionsRef = (0,
|
|
6621
|
+
const canvasRef = (0, import_react55.useRef)(null);
|
|
6622
|
+
const containerRef = (0, import_react55.useRef)(null);
|
|
6623
|
+
const [activeTab, setActiveTab] = (0, import_react55.useState)("crop");
|
|
6624
|
+
const [activeCropRatio, setActiveCropRatio] = (0, import_react55.useState)(null);
|
|
6625
|
+
const [selectionOptions, setSelectionOptions] = (0, import_react55.useState)(import_image_editor18.DEFAULT_SELECTION_TOOL_OPTIONS);
|
|
6626
|
+
const selectionOptionsRef = (0, import_react55.useRef)(selectionOptions);
|
|
6608
6627
|
selectionOptionsRef.current = selectionOptions;
|
|
6609
|
-
const selectionGestureRef = (0,
|
|
6628
|
+
const selectionGestureRef = (0, import_react55.useRef)(null);
|
|
6610
6629
|
if (!selectionGestureRef.current || selectionGestureRef.current.controller !== controller) {
|
|
6611
6630
|
selectionGestureRef.current = new import_image_editor18.SelectionGesture(controller, () => selectionOptionsRef.current);
|
|
6612
6631
|
}
|
|
6613
|
-
const selectionDraftRef = (0,
|
|
6614
|
-
const [selectionError, setSelectionError] = (0,
|
|
6615
|
-
const paintGestureRef = (0,
|
|
6616
|
-
const paintControllerRef = (0,
|
|
6632
|
+
const selectionDraftRef = (0, import_react55.useRef)(null);
|
|
6633
|
+
const [selectionError, setSelectionError] = (0, import_react55.useState)(null);
|
|
6634
|
+
const paintGestureRef = (0, import_react55.useRef)(null);
|
|
6635
|
+
const paintControllerRef = (0, import_react55.useRef)(controller);
|
|
6617
6636
|
if (!paintGestureRef.current || paintControllerRef.current !== controller) {
|
|
6618
6637
|
paintGestureRef.current = new import_image_editor18.PaintGesture(controller);
|
|
6619
6638
|
paintControllerRef.current = controller;
|
|
6620
6639
|
}
|
|
6621
|
-
const brushCursorRef = (0,
|
|
6622
|
-
const [paintError, setPaintError] = (0,
|
|
6623
|
-
const transformToolRef = (0,
|
|
6624
|
-
const transformControllerRef = (0,
|
|
6640
|
+
const brushCursorRef = (0, import_react55.useRef)(null);
|
|
6641
|
+
const [paintError, setPaintError] = (0, import_react55.useState)(null);
|
|
6642
|
+
const transformToolRef = (0, import_react55.useRef)(null);
|
|
6643
|
+
const transformControllerRef = (0, import_react55.useRef)(controller);
|
|
6625
6644
|
if (!transformToolRef.current || transformControllerRef.current !== controller) {
|
|
6626
6645
|
transformToolRef.current?.cancel();
|
|
6627
6646
|
transformToolRef.current = new import_image_editor18.FreeTransformTool(controller, {
|
|
@@ -6630,33 +6649,33 @@ var ImageEditor = ({
|
|
|
6630
6649
|
transformControllerRef.current = controller;
|
|
6631
6650
|
}
|
|
6632
6651
|
const transformTool = transformToolRef.current;
|
|
6633
|
-
const [, setTransformTick] = (0,
|
|
6634
|
-
const [transformCursor, setTransformCursor] = (0,
|
|
6635
|
-
const [shapeOptions, setShapeOptions] = (0,
|
|
6636
|
-
const shapeOptionsRef = (0,
|
|
6652
|
+
const [, setTransformTick] = (0, import_react55.useState)(0);
|
|
6653
|
+
const [transformCursor, setTransformCursor] = (0, import_react55.useState)("default");
|
|
6654
|
+
const [shapeOptions, setShapeOptions] = (0, import_react55.useState)(import_image_editor18.DEFAULT_SHAPE_TOOL_OPTIONS);
|
|
6655
|
+
const shapeOptionsRef = (0, import_react55.useRef)(shapeOptions);
|
|
6637
6656
|
shapeOptionsRef.current = shapeOptions;
|
|
6638
|
-
const [typeOptions, setTypeOptions] = (0,
|
|
6639
|
-
const typeOptionsRef = (0,
|
|
6657
|
+
const [typeOptions, setTypeOptions] = (0, import_react55.useState)(import_image_editor18.DEFAULT_TYPE_TOOL_OPTIONS);
|
|
6658
|
+
const typeOptionsRef = (0, import_react55.useRef)(typeOptions);
|
|
6640
6659
|
typeOptionsRef.current = typeOptions;
|
|
6641
|
-
const shapeGestureRef = (0,
|
|
6642
|
-
const typeToolRef = (0,
|
|
6643
|
-
const shapeTypeControllerRef = (0,
|
|
6660
|
+
const shapeGestureRef = (0, import_react55.useRef)(null);
|
|
6661
|
+
const typeToolRef = (0, import_react55.useRef)(null);
|
|
6662
|
+
const shapeTypeControllerRef = (0, import_react55.useRef)(controller);
|
|
6644
6663
|
if (!shapeGestureRef.current || !typeToolRef.current || shapeTypeControllerRef.current !== controller) {
|
|
6645
6664
|
typeToolRef.current?.finish();
|
|
6646
6665
|
shapeGestureRef.current = new import_image_editor18.ShapeDrawGesture(controller, () => shapeOptionsRef.current);
|
|
6647
6666
|
typeToolRef.current = new import_image_editor18.TypeToolGesture(controller, () => typeOptionsRef.current);
|
|
6648
6667
|
shapeTypeControllerRef.current = controller;
|
|
6649
6668
|
}
|
|
6650
|
-
const typeInputRef = (0,
|
|
6651
|
-
const [typeSession, setTypeSession] = (0,
|
|
6652
|
-
const [shapeTypeError, setShapeTypeError] = (0,
|
|
6653
|
-
const [inpaintPrompt, setInpaintPrompt] = (0,
|
|
6654
|
-
const [inpaintMaskMode, setInpaintMaskMode] = (0,
|
|
6655
|
-
const [isRemovingBg, setIsRemovingBg] = (0,
|
|
6656
|
-
const [isInpainting, setIsInpainting] = (0,
|
|
6657
|
-
const [aiError, setAiError] = (0,
|
|
6658
|
-
const [aiSuccess, setAiSuccess] = (0,
|
|
6659
|
-
const [aiTarget, setAiTarget] = (0,
|
|
6669
|
+
const typeInputRef = (0, import_react55.useRef)(null);
|
|
6670
|
+
const [typeSession, setTypeSession] = (0, import_react55.useState)(typeToolRef.current.session);
|
|
6671
|
+
const [shapeTypeError, setShapeTypeError] = (0, import_react55.useState)(null);
|
|
6672
|
+
const [inpaintPrompt, setInpaintPrompt] = (0, import_react55.useState)("");
|
|
6673
|
+
const [inpaintMaskMode, setInpaintMaskMode] = (0, import_react55.useState)("annotations");
|
|
6674
|
+
const [isRemovingBg, setIsRemovingBg] = (0, import_react55.useState)(false);
|
|
6675
|
+
const [isInpainting, setIsInpainting] = (0, import_react55.useState)(false);
|
|
6676
|
+
const [aiError, setAiError] = (0, import_react55.useState)(null);
|
|
6677
|
+
const [aiSuccess, setAiSuccess] = (0, import_react55.useState)(null);
|
|
6678
|
+
const [aiTarget, setAiTarget] = (0, import_react55.useState)("auto");
|
|
6660
6679
|
const aiOptions = aiTarget === "auto" ? {} : { target: aiTarget };
|
|
6661
6680
|
const effectiveOnInpaint = onInpaint || aiHooks?.onInpaint;
|
|
6662
6681
|
const effectiveOnRemoveBg = onRemoveBackground || aiHooks?.onRemoveBackground;
|
|
@@ -6719,18 +6738,18 @@ var ImageEditor = ({
|
|
|
6719
6738
|
setIsInpainting(false);
|
|
6720
6739
|
}
|
|
6721
6740
|
};
|
|
6722
|
-
const [activeColor, setActiveColor] = (0,
|
|
6723
|
-
const [strokeWidth, setStrokeWidth] = (0,
|
|
6724
|
-
const [fontSize, setFontSize] = (0,
|
|
6725
|
-
const [textInput, setTextInput] = (0,
|
|
6726
|
-
const draftAnnotationRef = (0,
|
|
6727
|
-
const draftCropRef = (0,
|
|
6728
|
-
const cropDragInfoRef = (0,
|
|
6729
|
-
const annotationDragInfoRef = (0,
|
|
6730
|
-
const isDrawingRef = (0,
|
|
6731
|
-
const currentPathRef = (0,
|
|
6732
|
-
const dragStartPointRef = (0,
|
|
6733
|
-
const renderCanvas = (0,
|
|
6741
|
+
const [activeColor, setActiveColor] = (0, import_react55.useState)("#ef4444");
|
|
6742
|
+
const [strokeWidth, setStrokeWidth] = (0, import_react55.useState)(3);
|
|
6743
|
+
const [fontSize, setFontSize] = (0, import_react55.useState)(24);
|
|
6744
|
+
const [textInput, setTextInput] = (0, import_react55.useState)("");
|
|
6745
|
+
const draftAnnotationRef = (0, import_react55.useRef)(null);
|
|
6746
|
+
const draftCropRef = (0, import_react55.useRef)(null);
|
|
6747
|
+
const cropDragInfoRef = (0, import_react55.useRef)(null);
|
|
6748
|
+
const annotationDragInfoRef = (0, import_react55.useRef)(null);
|
|
6749
|
+
const isDrawingRef = (0, import_react55.useRef)(false);
|
|
6750
|
+
const currentPathRef = (0, import_react55.useRef)([]);
|
|
6751
|
+
const dragStartPointRef = (0, import_react55.useRef)(null);
|
|
6752
|
+
const renderCanvas = (0, import_react55.useCallback)(
|
|
6734
6753
|
async (draftAnnotation, draftCrop) => {
|
|
6735
6754
|
const canvas = canvasRef.current;
|
|
6736
6755
|
const container = containerRef.current;
|
|
@@ -6753,8 +6772,8 @@ var ImageEditor = ({
|
|
|
6753
6772
|
},
|
|
6754
6773
|
[controller, activeTab, transformTool]
|
|
6755
6774
|
);
|
|
6756
|
-
(0,
|
|
6757
|
-
(0,
|
|
6775
|
+
(0, import_react55.useEffect)(() => typeSession?.subscribe(() => void renderCanvas()), [typeSession, renderCanvas]);
|
|
6776
|
+
(0, import_react55.useEffect)(() => {
|
|
6758
6777
|
if (activeTab === "annotate" && state.activeTool === "type") return;
|
|
6759
6778
|
if (typeToolRef.current?.session) {
|
|
6760
6779
|
typeToolRef.current.finish();
|
|
@@ -6789,7 +6808,7 @@ var ImageEditor = ({
|
|
|
6789
6808
|
el.value = "";
|
|
6790
6809
|
}
|
|
6791
6810
|
};
|
|
6792
|
-
(0,
|
|
6811
|
+
(0, import_react55.useEffect)(() => transformTool.subscribe(() => {
|
|
6793
6812
|
setTransformTick((n) => n + 1);
|
|
6794
6813
|
void renderCanvas();
|
|
6795
6814
|
}), [transformTool, renderCanvas]);
|
|
@@ -6832,7 +6851,7 @@ var ImageEditor = ({
|
|
|
6832
6851
|
transformTool.up();
|
|
6833
6852
|
return true;
|
|
6834
6853
|
};
|
|
6835
|
-
(0,
|
|
6854
|
+
(0, import_react55.useEffect)(() => {
|
|
6836
6855
|
if (typeof window === "undefined") return;
|
|
6837
6856
|
const onKey = (e) => {
|
|
6838
6857
|
if (transformTool.key(e)) e.preventDefault();
|
|
@@ -6840,7 +6859,7 @@ var ImageEditor = ({
|
|
|
6840
6859
|
window.addEventListener("keydown", onKey);
|
|
6841
6860
|
return () => window.removeEventListener("keydown", onKey);
|
|
6842
6861
|
}, [transformTool]);
|
|
6843
|
-
(0,
|
|
6862
|
+
(0, import_react55.useEffect)(() => {
|
|
6844
6863
|
const raf = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(cb, 0);
|
|
6845
6864
|
const caf = typeof cancelAnimationFrame !== "undefined" ? cancelAnimationFrame : (id) => clearTimeout(id);
|
|
6846
6865
|
const animId = raf(() => {
|
|
@@ -6848,12 +6867,12 @@ var ImageEditor = ({
|
|
|
6848
6867
|
});
|
|
6849
6868
|
return () => caf(animId);
|
|
6850
6869
|
}, [renderCanvas, state]);
|
|
6851
|
-
(0,
|
|
6870
|
+
(0, import_react55.useEffect)(() => {
|
|
6852
6871
|
if (activeTab === "crop" && editor.state.activeTool !== "crop") {
|
|
6853
6872
|
editor.setTool("crop");
|
|
6854
6873
|
}
|
|
6855
6874
|
}, [activeTab, editor]);
|
|
6856
|
-
(0,
|
|
6875
|
+
(0, import_react55.useEffect)(() => {
|
|
6857
6876
|
const container = containerRef.current;
|
|
6858
6877
|
if (!container) return;
|
|
6859
6878
|
if (typeof ResizeObserver !== "undefined") {
|
|
@@ -6921,7 +6940,7 @@ var ImageEditor = ({
|
|
|
6921
6940
|
if (g.error) setPaintError(g.error);
|
|
6922
6941
|
}
|
|
6923
6942
|
};
|
|
6924
|
-
(0,
|
|
6943
|
+
(0, import_react55.useEffect)(() => {
|
|
6925
6944
|
if (activeTab !== "paint" || typeof window === "undefined") return;
|
|
6926
6945
|
const onKey = (e) => {
|
|
6927
6946
|
if ((0, import_image_editor18.handlePaintShortcut)(controller, e)) e.preventDefault();
|
|
@@ -7684,7 +7703,7 @@ var ImageEditor = ({
|
|
|
7684
7703
|
)
|
|
7685
7704
|
] }),
|
|
7686
7705
|
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Histogram, { histogram: editor.histogram }),
|
|
7687
|
-
import_image_editor18.IMAGE_ADJUSTMENT_CONTROLS.map((spec) => /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
|
|
7706
|
+
import_image_editor18.IMAGE_ADJUSTMENT_CONTROLS.map((spec) => /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_react55.default.Fragment, { children: [
|
|
7688
7707
|
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
|
|
7689
7708
|
ControlSlider,
|
|
7690
7709
|
{
|
|
@@ -8183,7 +8202,7 @@ var ImageEditor = ({
|
|
|
8183
8202
|
};
|
|
8184
8203
|
|
|
8185
8204
|
// src/review/useReview.ts
|
|
8186
|
-
var
|
|
8205
|
+
var import_react56 = require("react");
|
|
8187
8206
|
var import_editor12 = require("@pixerate/editor");
|
|
8188
8207
|
var EMPTY_COMMENTS = Object.freeze({
|
|
8189
8208
|
threads: [],
|
|
@@ -8202,23 +8221,23 @@ function isCommentStore(value) {
|
|
|
8202
8221
|
}
|
|
8203
8222
|
function useComments(source) {
|
|
8204
8223
|
const store = isCommentStore(source) ? source : (0, import_editor12.getCommentStore)(source);
|
|
8205
|
-
const subscribe = (0,
|
|
8224
|
+
const subscribe = (0, import_react56.useCallback)(
|
|
8206
8225
|
(onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe,
|
|
8207
8226
|
[store]
|
|
8208
8227
|
);
|
|
8209
8228
|
const getSnapshot = () => store?.getSnapshot() ?? EMPTY_COMMENTS;
|
|
8210
|
-
const snapshot = (0,
|
|
8211
|
-
return (0,
|
|
8229
|
+
const snapshot = (0, import_react56.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
8230
|
+
return (0, import_react56.useMemo)(() => ({ ...snapshot, store }), [snapshot, store]);
|
|
8212
8231
|
}
|
|
8213
8232
|
function useTrackChanges(editor) {
|
|
8214
8233
|
const store = (0, import_editor12.getTrackChangesStore)(editor ?? null);
|
|
8215
|
-
const subscribe = (0,
|
|
8234
|
+
const subscribe = (0, import_react56.useCallback)(
|
|
8216
8235
|
(onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe,
|
|
8217
8236
|
[store]
|
|
8218
8237
|
);
|
|
8219
8238
|
const getSnapshot = () => store?.getSnapshot() ?? EMPTY_TRACK_CHANGES;
|
|
8220
|
-
const snapshot = (0,
|
|
8221
|
-
return (0,
|
|
8239
|
+
const snapshot = (0, import_react56.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
8240
|
+
return (0, import_react56.useMemo)(() => {
|
|
8222
8241
|
const run = (fn) => () => {
|
|
8223
8242
|
if (editor && !editor.isDestroyed) fn(editor);
|
|
8224
8243
|
};
|
|
@@ -8241,7 +8260,7 @@ function useTrackChanges(editor) {
|
|
|
8241
8260
|
}
|
|
8242
8261
|
|
|
8243
8262
|
// src/review/CommentsPanel.tsx
|
|
8244
|
-
var
|
|
8263
|
+
var import_react57 = require("react");
|
|
8245
8264
|
var import_editor13 = require("@pixerate/editor");
|
|
8246
8265
|
var import_jsx_runtime38 = require("react/jsx-runtime");
|
|
8247
8266
|
var buttonClass2 = "rounded px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50";
|
|
@@ -8257,7 +8276,7 @@ var CommentsPanel = ({
|
|
|
8257
8276
|
emptyMessage = "No comments yet. Select text and add a comment."
|
|
8258
8277
|
}) => {
|
|
8259
8278
|
const { threads, activeThreadId, store } = useComments(storeProp ?? editor);
|
|
8260
|
-
const [showResolved, setShowResolved] = (0,
|
|
8279
|
+
const [showResolved, setShowResolved] = (0, import_react57.useState)(showResolvedInitial);
|
|
8261
8280
|
const author = authorProp ?? (0, import_editor13.getCommentAuthor)(editor) ?? { id: "anonymous", name: "Anonymous" };
|
|
8262
8281
|
const visible = threads.filter((t) => showResolved || !t.resolved);
|
|
8263
8282
|
const resolvedCount = threads.filter((t) => t.resolved).length;
|
|
@@ -8301,7 +8320,7 @@ var CommentThreadCard = ({
|
|
|
8301
8320
|
author,
|
|
8302
8321
|
formatTime
|
|
8303
8322
|
}) => {
|
|
8304
|
-
const [draft, setDraft] = (0,
|
|
8323
|
+
const [draft, setDraft] = (0, import_react57.useState)("");
|
|
8305
8324
|
const isDraft = thread.body === "";
|
|
8306
8325
|
const quote = thread.anchor?.quote ?? thread.lastQuote ?? "";
|
|
8307
8326
|
const live = editor && !editor.isDestroyed ? editor : null;
|
|
@@ -8515,13 +8534,13 @@ var CommentButton = ({
|
|
|
8515
8534
|
);
|
|
8516
8535
|
|
|
8517
8536
|
// src/review/useDocumentCompare.ts
|
|
8518
|
-
var
|
|
8537
|
+
var import_react58 = require("react");
|
|
8519
8538
|
var import_editor14 = require("@pixerate/editor");
|
|
8520
8539
|
function useDocumentCompare(editor, options) {
|
|
8521
|
-
const [summary, setSummary] = (0,
|
|
8522
|
-
const defaults = (0,
|
|
8540
|
+
const [summary, setSummary] = (0, import_react58.useState)(null);
|
|
8541
|
+
const defaults = (0, import_react58.useRef)(options);
|
|
8523
8542
|
defaults.current = options;
|
|
8524
|
-
const compare = (0,
|
|
8543
|
+
const compare = (0, import_react58.useCallback)(
|
|
8525
8544
|
(original, revised, overrides) => {
|
|
8526
8545
|
if (!editor || editor.isDestroyed) return null;
|
|
8527
8546
|
const result = (0, import_editor14.applyDocumentComparison)(editor, original, revised, {
|
|
@@ -8533,8 +8552,8 @@ function useDocumentCompare(editor, options) {
|
|
|
8533
8552
|
},
|
|
8534
8553
|
[editor]
|
|
8535
8554
|
);
|
|
8536
|
-
const clear = (0,
|
|
8537
|
-
return (0,
|
|
8555
|
+
const clear = (0, import_react58.useCallback)(() => setSummary(null), []);
|
|
8556
|
+
return (0, import_react58.useMemo)(() => ({ summary, compare, clear }), [summary, compare, clear]);
|
|
8538
8557
|
}
|
|
8539
8558
|
|
|
8540
8559
|
// src/review/TrackedChangesList.tsx
|
|
@@ -8585,12 +8604,12 @@ var TrackedChangesList = ({
|
|
|
8585
8604
|
};
|
|
8586
8605
|
|
|
8587
8606
|
// src/commands/useCommandPalette.ts
|
|
8588
|
-
var
|
|
8607
|
+
var import_react59 = require("react");
|
|
8589
8608
|
var import_commands2 = require("@pixerate/editor/commands");
|
|
8590
8609
|
function useCommandPalette(registry, options = {}) {
|
|
8591
|
-
const optionsRef = (0,
|
|
8610
|
+
const optionsRef = (0, import_react59.useRef)(options);
|
|
8592
8611
|
optionsRef.current = options;
|
|
8593
|
-
const controller = (0,
|
|
8612
|
+
const controller = (0, import_react59.useMemo)(
|
|
8594
8613
|
() => (0, import_commands2.createCommandPaletteController)(registry, {
|
|
8595
8614
|
context: () => {
|
|
8596
8615
|
const c = optionsRef.current.context;
|
|
@@ -8611,9 +8630,9 @@ function useCommandPalette(registry, options = {}) {
|
|
|
8611
8630
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8612
8631
|
[registry]
|
|
8613
8632
|
);
|
|
8614
|
-
const state = (0,
|
|
8633
|
+
const state = (0, import_react59.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
|
|
8615
8634
|
const { hotkey, hotkeyTarget } = options;
|
|
8616
|
-
(0,
|
|
8635
|
+
(0, import_react59.useEffect)(() => {
|
|
8617
8636
|
if (!hotkey) return;
|
|
8618
8637
|
const target = hotkeyTarget ?? (typeof window !== "undefined" ? window : null);
|
|
8619
8638
|
if (!target) return;
|
|
@@ -8641,13 +8660,13 @@ function useCommandPalette(registry, options = {}) {
|
|
|
8641
8660
|
}
|
|
8642
8661
|
|
|
8643
8662
|
// src/commands/CommandPalette.tsx
|
|
8644
|
-
var
|
|
8663
|
+
var import_react60 = __toESM(require("react"), 1);
|
|
8645
8664
|
var import_jsx_runtime42 = require("react/jsx-runtime");
|
|
8646
8665
|
function HighlightedLabel({ item }) {
|
|
8647
8666
|
if (item.labelIndices.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_jsx_runtime42.Fragment, { children: item.label });
|
|
8648
8667
|
const marked = new Set(item.labelIndices);
|
|
8649
8668
|
return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_jsx_runtime42.Fragment, { children: Array.from(item.label).map(
|
|
8650
|
-
(ch, i) => marked.has(i) ? /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("span", { className: "font-semibold text-foreground", "data-match": "", children: ch }, i) : /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
|
|
8669
|
+
(ch, i) => marked.has(i) ? /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("span", { className: "font-semibold text-foreground", "data-match": "", children: ch }, i) : /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_react60.default.Fragment, { children: ch }, i)
|
|
8651
8670
|
) });
|
|
8652
8671
|
}
|
|
8653
8672
|
var CommandPalette = ({
|
|
@@ -8656,16 +8675,16 @@ var CommandPalette = ({
|
|
|
8656
8675
|
emptyMessage = "No matching commands",
|
|
8657
8676
|
className = ""
|
|
8658
8677
|
}) => {
|
|
8659
|
-
const inputRef = (0,
|
|
8660
|
-
const listRef = (0,
|
|
8661
|
-
const baseId = (0,
|
|
8678
|
+
const inputRef = (0, import_react60.useRef)(null);
|
|
8679
|
+
const listRef = (0, import_react60.useRef)(null);
|
|
8680
|
+
const baseId = (0, import_react60.useId)();
|
|
8662
8681
|
const listId = `${baseId}-list`;
|
|
8663
8682
|
const optionId = (index) => `${baseId}-option-${index}`;
|
|
8664
8683
|
const { open, query, items, activeIndex } = palette;
|
|
8665
|
-
(0,
|
|
8684
|
+
(0, import_react60.useEffect)(() => {
|
|
8666
8685
|
if (open) inputRef.current?.focus();
|
|
8667
8686
|
}, [open]);
|
|
8668
|
-
(0,
|
|
8687
|
+
(0, import_react60.useEffect)(() => {
|
|
8669
8688
|
if (!open) return;
|
|
8670
8689
|
const active = listRef.current?.querySelector('[aria-selected="true"]');
|
|
8671
8690
|
active?.scrollIntoView?.({ block: "nearest" });
|
|
@@ -8741,12 +8760,12 @@ var CommandPalette = ({
|
|
|
8741
8760
|
};
|
|
8742
8761
|
|
|
8743
8762
|
// src/commands/useCommandShortcuts.ts
|
|
8744
|
-
var
|
|
8763
|
+
var import_react61 = require("react");
|
|
8745
8764
|
function useCommandShortcuts(registry, options = {}) {
|
|
8746
|
-
const optionsRef = (0,
|
|
8765
|
+
const optionsRef = (0, import_react61.useRef)(options);
|
|
8747
8766
|
optionsRef.current = options;
|
|
8748
8767
|
const { enabled = true, target } = options;
|
|
8749
|
-
(0,
|
|
8768
|
+
(0, import_react61.useEffect)(() => {
|
|
8750
8769
|
if (!registry || !enabled) return;
|
|
8751
8770
|
const eventTarget = target ?? (typeof window !== "undefined" ? window : null);
|
|
8752
8771
|
if (!eventTarget) return;
|
|
@@ -8764,14 +8783,14 @@ function useCommandShortcuts(registry, options = {}) {
|
|
|
8764
8783
|
}, [registry, enabled, target]);
|
|
8765
8784
|
}
|
|
8766
8785
|
function useRegisterCommands(registry, specs) {
|
|
8767
|
-
(0,
|
|
8786
|
+
(0, import_react61.useEffect)(() => {
|
|
8768
8787
|
if (!registry || !specs || specs.length === 0) return;
|
|
8769
8788
|
return registry.register(specs);
|
|
8770
8789
|
}, [registry, specs]);
|
|
8771
8790
|
}
|
|
8772
8791
|
|
|
8773
8792
|
// src/persistence/useAutosave.ts
|
|
8774
|
-
var
|
|
8793
|
+
var import_react62 = require("react");
|
|
8775
8794
|
var import_persistence = require("@pixerate/editor/persistence");
|
|
8776
8795
|
var IDLE = {
|
|
8777
8796
|
status: "idle",
|
|
@@ -8782,18 +8801,18 @@ var IDLE = {
|
|
|
8782
8801
|
ready: false
|
|
8783
8802
|
};
|
|
8784
8803
|
function useAutosave(options) {
|
|
8785
|
-
const optionsRef = (0,
|
|
8804
|
+
const optionsRef = (0, import_react62.useRef)(options);
|
|
8786
8805
|
optionsRef.current = options;
|
|
8787
8806
|
const { storage, key, history, dirty } = options;
|
|
8788
8807
|
const recover = options.recover !== false;
|
|
8789
8808
|
const flushOnHide = options.flushOnHide !== false;
|
|
8790
8809
|
const ready = options.ready !== false;
|
|
8791
|
-
const [controller, setController] = (0,
|
|
8792
|
-
const [status, setStatus] = (0,
|
|
8793
|
-
const [recovery, setRecovery] = (0,
|
|
8794
|
-
const [pendingRecovery, setPendingRecovery] = (0,
|
|
8795
|
-
const revisionsRef = (0,
|
|
8796
|
-
(0,
|
|
8810
|
+
const [controller, setController] = (0, import_react62.useState)(null);
|
|
8811
|
+
const [status, setStatus] = (0, import_react62.useState)(IDLE);
|
|
8812
|
+
const [recovery, setRecovery] = (0, import_react62.useState)(null);
|
|
8813
|
+
const [pendingRecovery, setPendingRecovery] = (0, import_react62.useState)(recover);
|
|
8814
|
+
const revisionsRef = (0, import_react62.useRef)(null);
|
|
8815
|
+
(0, import_react62.useEffect)(() => {
|
|
8797
8816
|
const revisions = (0, import_persistence.createRevisionTracker)({ history, dirty });
|
|
8798
8817
|
const o = optionsRef.current;
|
|
8799
8818
|
const instance = (0, import_persistence.createAutosaveController)({
|
|
@@ -8836,10 +8855,10 @@ function useAutosave(options) {
|
|
|
8836
8855
|
if (revisionsRef.current === revisions) revisionsRef.current = null;
|
|
8837
8856
|
};
|
|
8838
8857
|
}, [storage, key, history, dirty, recover]);
|
|
8839
|
-
(0,
|
|
8858
|
+
(0, import_react62.useEffect)(() => {
|
|
8840
8859
|
if (controller && ready && !pendingRecovery) controller.ready();
|
|
8841
8860
|
}, [controller, ready, pendingRecovery]);
|
|
8842
|
-
(0,
|
|
8861
|
+
(0, import_react62.useEffect)(() => {
|
|
8843
8862
|
if (!controller || !flushOnHide || typeof window === "undefined") return;
|
|
8844
8863
|
const flush = () => void controller.flushNow();
|
|
8845
8864
|
const onVisibility = () => {
|
|
@@ -8852,25 +8871,25 @@ function useAutosave(options) {
|
|
|
8852
8871
|
document.removeEventListener("visibilitychange", onVisibility);
|
|
8853
8872
|
};
|
|
8854
8873
|
}, [controller, flushOnHide]);
|
|
8855
|
-
const restore = (0,
|
|
8874
|
+
const restore = (0, import_react62.useCallback)(() => {
|
|
8856
8875
|
const snapshot = recovery?.snapshot;
|
|
8857
8876
|
setRecovery(null);
|
|
8858
8877
|
setPendingRecovery(false);
|
|
8859
8878
|
return snapshot;
|
|
8860
8879
|
}, [recovery]);
|
|
8861
|
-
const discard = (0,
|
|
8880
|
+
const discard = (0, import_react62.useCallback)(async () => {
|
|
8862
8881
|
if (controller) await controller.discardRecovery();
|
|
8863
8882
|
setRecovery(null);
|
|
8864
8883
|
setPendingRecovery(false);
|
|
8865
8884
|
}, [controller]);
|
|
8866
|
-
const flushNow = (0,
|
|
8885
|
+
const flushNow = (0, import_react62.useCallback)(async () => {
|
|
8867
8886
|
await controller?.flushNow();
|
|
8868
8887
|
}, [controller]);
|
|
8869
|
-
const markClean = (0,
|
|
8888
|
+
const markClean = (0, import_react62.useCallback)(async () => {
|
|
8870
8889
|
revisionsRef.current?.markSaved();
|
|
8871
8890
|
await controller?.markClean();
|
|
8872
8891
|
}, [controller]);
|
|
8873
|
-
const notifyChange = (0,
|
|
8892
|
+
const notifyChange = (0, import_react62.useCallback)(() => revisionsRef.current?.bump(), []);
|
|
8874
8893
|
return { status, recovery, pendingRecovery, restore, discard, flushNow, markClean, notifyChange, controller };
|
|
8875
8894
|
}
|
|
8876
8895
|
|
|
@@ -8930,17 +8949,17 @@ var RecoveryPrompt = ({
|
|
|
8930
8949
|
};
|
|
8931
8950
|
|
|
8932
8951
|
// src/generation/useGenerationPlan.ts
|
|
8933
|
-
var
|
|
8952
|
+
var import_react63 = require("react");
|
|
8934
8953
|
var import_generation = require("@pixerate/editor/generation");
|
|
8935
8954
|
function useGenerationPlan(request, capabilities, options = {}) {
|
|
8936
8955
|
const key = JSON.stringify([request, capabilities, options]);
|
|
8937
|
-
return (0,
|
|
8956
|
+
return (0, import_react63.useMemo)(() => (0, import_generation.planGenerationRequest)(request, capabilities, options), [key]);
|
|
8938
8957
|
}
|
|
8939
8958
|
function useJobProgress(options) {
|
|
8940
8959
|
const { startedAt, expectedMs, done, now, intervalMs = 1e3 } = options;
|
|
8941
|
-
const [tick, setTick] = (0,
|
|
8960
|
+
const [tick, setTick] = (0, import_react63.useState)(() => Date.now());
|
|
8942
8961
|
const ticking = !done && now === void 0;
|
|
8943
|
-
(0,
|
|
8962
|
+
(0, import_react63.useEffect)(() => {
|
|
8944
8963
|
if (!ticking) return;
|
|
8945
8964
|
setTick(Date.now());
|
|
8946
8965
|
const id = setInterval(() => setTick(Date.now()), Math.max(16, intervalMs));
|
|
@@ -8950,7 +8969,7 @@ function useJobProgress(options) {
|
|
|
8950
8969
|
}
|
|
8951
8970
|
|
|
8952
8971
|
// src/generation/GenerationSettings.tsx
|
|
8953
|
-
var
|
|
8972
|
+
var import_react64 = require("react");
|
|
8954
8973
|
var import_generation2 = require("@pixerate/editor/generation");
|
|
8955
8974
|
var import_jsx_runtime44 = require("react/jsx-runtime");
|
|
8956
8975
|
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";
|
|
@@ -9033,8 +9052,8 @@ var GenerationSettings = ({
|
|
|
9033
9052
|
renderReference,
|
|
9034
9053
|
className = ""
|
|
9035
9054
|
}) => {
|
|
9036
|
-
const baseId = (0,
|
|
9037
|
-
const controls = (0,
|
|
9055
|
+
const baseId = (0, import_react64.useId)();
|
|
9056
|
+
const controls = (0, import_react64.useMemo)(() => (0, import_generation2.getGenerationControls)(capabilities), [capabilities]);
|
|
9038
9057
|
const computed = useGenerationPlan(value, capabilities, { strategy });
|
|
9039
9058
|
const plan = planProp ?? computed;
|
|
9040
9059
|
const slots = (0, import_generation2.getReferenceSlots)(capabilities, value);
|
|
@@ -9129,7 +9148,7 @@ var JobProgress = ({ title, className = "", ...options }) => {
|
|
|
9129
9148
|
};
|
|
9130
9149
|
|
|
9131
9150
|
// src/generation/AssetMentionChips.tsx
|
|
9132
|
-
var
|
|
9151
|
+
var import_react65 = require("react");
|
|
9133
9152
|
var import_generation3 = require("@pixerate/editor/generation");
|
|
9134
9153
|
var import_jsx_runtime46 = require("react/jsx-runtime");
|
|
9135
9154
|
var AssetMentionChips = ({
|
|
@@ -9141,14 +9160,14 @@ var AssetMentionChips = ({
|
|
|
9141
9160
|
renderAsset,
|
|
9142
9161
|
className = ""
|
|
9143
9162
|
}) => {
|
|
9144
|
-
const [open, setOpen] = (0,
|
|
9145
|
-
const rootRef = (0,
|
|
9146
|
-
const chips = (0,
|
|
9163
|
+
const [open, setOpen] = (0, import_react65.useState)(null);
|
|
9164
|
+
const rootRef = (0, import_react65.useRef)(null);
|
|
9165
|
+
const chips = (0, import_react65.useMemo)(
|
|
9147
9166
|
() => (0, import_generation3.describeAssetMentions)((0, import_generation3.findTextMentions)(content), assets, capabilities),
|
|
9148
9167
|
[content, assets, capabilities]
|
|
9149
9168
|
);
|
|
9150
9169
|
const options = roles ?? (capabilities ? (0, import_generation3.getAssetRoleOptions)(capabilities) : (0, import_generation3.defaultAssetRoleOptions)());
|
|
9151
|
-
(0,
|
|
9170
|
+
(0, import_react65.useEffect)(() => {
|
|
9152
9171
|
if (open === null) return;
|
|
9153
9172
|
const onPointer = (event) => {
|
|
9154
9173
|
if (!rootRef.current?.contains(event.target)) setOpen(null);
|
|
@@ -9243,15 +9262,15 @@ var AssetMentionChips = ({
|
|
|
9243
9262
|
};
|
|
9244
9263
|
|
|
9245
9264
|
// src/generation/GenerationHistory.tsx
|
|
9246
|
-
var
|
|
9265
|
+
var import_react66 = require("react");
|
|
9247
9266
|
var import_generation4 = require("@pixerate/editor/generation");
|
|
9248
9267
|
var import_jsx_runtime47 = require("react/jsx-runtime");
|
|
9249
9268
|
function useGenerationRecords(store, filter) {
|
|
9250
|
-
const [records, setRecords] = (0,
|
|
9251
|
-
const [loading, setLoading] = (0,
|
|
9252
|
-
const [error, setError] = (0,
|
|
9269
|
+
const [records, setRecords] = (0, import_react66.useState)([]);
|
|
9270
|
+
const [loading, setLoading] = (0, import_react66.useState)(!!store);
|
|
9271
|
+
const [error, setError] = (0, import_react66.useState)(null);
|
|
9253
9272
|
const filterKey = (0, import_generation4.stableStringify)(filter ?? {});
|
|
9254
|
-
const refresh = (0,
|
|
9273
|
+
const refresh = (0, import_react66.useCallback)(async () => {
|
|
9255
9274
|
if (!store) {
|
|
9256
9275
|
setRecords([]);
|
|
9257
9276
|
setLoading(false);
|
|
@@ -9268,7 +9287,7 @@ function useGenerationRecords(store, filter) {
|
|
|
9268
9287
|
setLoading(false);
|
|
9269
9288
|
}
|
|
9270
9289
|
}, [store, filterKey]);
|
|
9271
|
-
(0,
|
|
9290
|
+
(0, import_react66.useEffect)(() => {
|
|
9272
9291
|
void refresh();
|
|
9273
9292
|
if (!store) return;
|
|
9274
9293
|
return store.subscribe(() => void refresh());
|
|
@@ -9294,15 +9313,15 @@ var GenerationHistory = ({
|
|
|
9294
9313
|
emptyText = "No generations yet.",
|
|
9295
9314
|
className = ""
|
|
9296
9315
|
}) => {
|
|
9297
|
-
const [innerMode, setInnerMode] = (0,
|
|
9316
|
+
const [innerMode, setInnerMode] = (0, import_react66.useState)("exact");
|
|
9298
9317
|
const mode = modeProp ?? innerMode;
|
|
9299
9318
|
const setMode = (next) => {
|
|
9300
9319
|
if (modeProp === void 0) setInnerMode(next);
|
|
9301
9320
|
onModeChange?.(next);
|
|
9302
9321
|
};
|
|
9303
|
-
const options = (0,
|
|
9304
|
-
const results = (0,
|
|
9305
|
-
const models = (0,
|
|
9322
|
+
const options = (0, import_react66.useMemo)(() => ({ templates, capabilities, assets, mode }), [templates, capabilities, assets, mode]);
|
|
9323
|
+
const results = (0, import_react66.useMemo)(() => records.map((record) => (0, import_generation4.recreateRequest)(record, options)), [records, options]);
|
|
9324
|
+
const models = (0, import_react66.useMemo)(
|
|
9306
9325
|
() => capabilities ? Array.isArray(capabilities) ? capabilities : [capabilities] : [],
|
|
9307
9326
|
[capabilities]
|
|
9308
9327
|
);
|
|
@@ -9413,19 +9432,19 @@ var GenerationHistory = ({
|
|
|
9413
9432
|
};
|
|
9414
9433
|
|
|
9415
9434
|
// src/find-replace/useFindReplace.ts
|
|
9416
|
-
var
|
|
9435
|
+
var import_react67 = require("react");
|
|
9417
9436
|
var import_editor16 = require("@pixerate/editor");
|
|
9418
9437
|
var noopUnsubscribe2 = () => {
|
|
9419
9438
|
};
|
|
9420
9439
|
function useFindReplace(editor) {
|
|
9421
9440
|
const store = (0, import_editor16.getFindReplaceStore)(editor ?? null);
|
|
9422
|
-
const subscribe = (0,
|
|
9441
|
+
const subscribe = (0, import_react67.useCallback)(
|
|
9423
9442
|
(onChange) => store ? store.subscribe(() => onChange()) : noopUnsubscribe2,
|
|
9424
9443
|
[store]
|
|
9425
9444
|
);
|
|
9426
9445
|
const getSnapshot = () => store?.getSnapshot() ?? import_editor16.EMPTY_FIND_REPLACE_SNAPSHOT;
|
|
9427
|
-
const snapshot = (0,
|
|
9428
|
-
return (0,
|
|
9446
|
+
const snapshot = (0, import_react67.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
9447
|
+
return (0, import_react67.useMemo)(() => {
|
|
9429
9448
|
const run = (fn) => {
|
|
9430
9449
|
if (editor && !editor.isDestroyed && store) fn(editor);
|
|
9431
9450
|
};
|
|
@@ -9449,7 +9468,7 @@ function useFindReplace(editor) {
|
|
|
9449
9468
|
}
|
|
9450
9469
|
|
|
9451
9470
|
// src/find-replace/FindReplaceBar.tsx
|
|
9452
|
-
var
|
|
9471
|
+
var import_react68 = require("react");
|
|
9453
9472
|
var import_editor17 = require("@pixerate/editor");
|
|
9454
9473
|
var import_jsx_runtime48 = require("react/jsx-runtime");
|
|
9455
9474
|
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";
|
|
@@ -9464,10 +9483,10 @@ var FindReplaceBar = ({
|
|
|
9464
9483
|
onClose
|
|
9465
9484
|
}) => {
|
|
9466
9485
|
const find = useFindReplace(editor);
|
|
9467
|
-
const findInput = (0,
|
|
9468
|
-
const [moreOpen, setMoreOpen] = (0,
|
|
9486
|
+
const findInput = (0, import_react68.useRef)(null);
|
|
9487
|
+
const [moreOpen, setMoreOpen] = (0, import_react68.useState)(false);
|
|
9469
9488
|
const visible = find.available && (alwaysOpen || find.open);
|
|
9470
|
-
(0,
|
|
9489
|
+
(0, import_react68.useEffect)(() => {
|
|
9471
9490
|
if (!visible || find.focusRequest === 0) return;
|
|
9472
9491
|
findInput.current?.focus();
|
|
9473
9492
|
findInput.current?.select();
|
|
@@ -9611,12 +9630,12 @@ var FindReplaceBar = ({
|
|
|
9611
9630
|
};
|
|
9612
9631
|
|
|
9613
9632
|
// src/tables/useTableMenu.ts
|
|
9614
|
-
var
|
|
9633
|
+
var import_react69 = require("react");
|
|
9615
9634
|
var import_editor18 = require("@pixerate/editor");
|
|
9616
9635
|
function useTableMenu(editor) {
|
|
9617
|
-
const store = (0,
|
|
9618
|
-
const snapshot = (0,
|
|
9619
|
-
return (0,
|
|
9636
|
+
const store = (0, import_react69.useMemo)(() => (0, import_editor18.createTableStore)(editor), [editor]);
|
|
9637
|
+
const snapshot = (0, import_react69.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
9638
|
+
return (0, import_react69.useMemo)(
|
|
9620
9639
|
() => ({
|
|
9621
9640
|
...snapshot,
|
|
9622
9641
|
run: (action, params) => (0, import_editor18.runTableAction)(editor, action, params, { focus: true }),
|
|
@@ -9627,7 +9646,7 @@ function useTableMenu(editor) {
|
|
|
9627
9646
|
}
|
|
9628
9647
|
|
|
9629
9648
|
// src/tables/TableToolbar.tsx
|
|
9630
|
-
var
|
|
9649
|
+
var import_react70 = __toESM(require("react"), 1);
|
|
9631
9650
|
var import_editor19 = require("@pixerate/editor");
|
|
9632
9651
|
var import_jsx_runtime49 = require("react/jsx-runtime");
|
|
9633
9652
|
var keepSelection2 = (event) => event.preventDefault();
|
|
@@ -9648,7 +9667,7 @@ var TableToolbar = ({
|
|
|
9648
9667
|
const enabled = status === true;
|
|
9649
9668
|
const active = item.active?.(table);
|
|
9650
9669
|
const separator = index > 0 && items[index - 1].group !== item.group;
|
|
9651
|
-
return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
|
|
9670
|
+
return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_react70.default.Fragment, { children: [
|
|
9652
9671
|
separator && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("span", { className: separatorClassName, "aria-hidden": "true" }),
|
|
9653
9672
|
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
|
|
9654
9673
|
"button",
|
|
@@ -9672,7 +9691,7 @@ var TableToolbar = ({
|
|
|
9672
9691
|
};
|
|
9673
9692
|
|
|
9674
9693
|
// src/tables/InsertTableGrid.tsx
|
|
9675
|
-
var
|
|
9694
|
+
var import_react71 = require("react");
|
|
9676
9695
|
var import_jsx_runtime50 = require("react/jsx-runtime");
|
|
9677
9696
|
var keepSelection3 = (event) => event.preventDefault();
|
|
9678
9697
|
var InsertTableGrid = ({
|
|
@@ -9686,7 +9705,7 @@ var InsertTableGrid = ({
|
|
|
9686
9705
|
onInsert
|
|
9687
9706
|
}) => {
|
|
9688
9707
|
const table = useTableMenu(editor);
|
|
9689
|
-
const [hover, setHover] = (0,
|
|
9708
|
+
const [hover, setHover] = (0, import_react71.useState)(null);
|
|
9690
9709
|
const status = table.actions.insertTable;
|
|
9691
9710
|
const disabled = !editor || !status.enabled;
|
|
9692
9711
|
const insert = (size) => {
|
|
@@ -9753,14 +9772,14 @@ var TableBubbleMenu = ({
|
|
|
9753
9772
|
var import_client = require("react-dom/client");
|
|
9754
9773
|
|
|
9755
9774
|
// src/chart/ChartCanvas.tsx
|
|
9756
|
-
var
|
|
9775
|
+
var import_react73 = require("react");
|
|
9757
9776
|
var import_chart2 = require("@pixerate/editor/chart");
|
|
9758
9777
|
|
|
9759
9778
|
// src/chart/useChartEditor.ts
|
|
9760
|
-
var
|
|
9779
|
+
var import_react72 = require("react");
|
|
9761
9780
|
var import_chart = require("@pixerate/editor/chart");
|
|
9762
9781
|
function useChartState(controller) {
|
|
9763
|
-
return (0,
|
|
9782
|
+
return (0, import_react72.useSyncExternalStore)(controller.subscribe, controller.getState, controller.getState);
|
|
9764
9783
|
}
|
|
9765
9784
|
|
|
9766
9785
|
// src/chart/ChartCanvas.tsx
|
|
@@ -9812,7 +9831,7 @@ function renderChartMark(mark, fontFamily, interactive) {
|
|
|
9812
9831
|
}
|
|
9813
9832
|
}
|
|
9814
9833
|
function ChartPresenceLayer({ presence }) {
|
|
9815
|
-
const { actors } = (0,
|
|
9834
|
+
const { actors } = (0, import_react73.useSyncExternalStore)(presence.subscribe, presence.getState, presence.getState);
|
|
9816
9835
|
return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("g", { "data-chart-presence": "", pointerEvents: "none", children: actors.map((a) => /* @__PURE__ */ (0, import_jsx_runtime52.jsxs)("g", { transform: `translate(${a.x} ${a.y})`, "data-actor": a.id, children: [
|
|
9817
9836
|
/* @__PURE__ */ (0, import_jsx_runtime52.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 }),
|
|
9818
9837
|
/* @__PURE__ */ (0, import_jsx_runtime52.jsxs)("g", { transform: "translate(13 16)", children: [
|
|
@@ -9823,12 +9842,12 @@ function ChartPresenceLayer({ presence }) {
|
|
|
9823
9842
|
}
|
|
9824
9843
|
function ChartCanvas({ controller, width = 640, height = 400, responsive = true, theme, editable = true, measureText, emptyMessage, className, presence, sceneRef }) {
|
|
9825
9844
|
const state = useChartState(controller);
|
|
9826
|
-
const wrapper = (0,
|
|
9827
|
-
const svg = (0,
|
|
9828
|
-
const drag = (0,
|
|
9829
|
-
const [measured, setMeasured] = (0,
|
|
9830
|
-
const [frozen, setFrozen] = (0,
|
|
9831
|
-
(0,
|
|
9845
|
+
const wrapper = (0, import_react73.useRef)(null);
|
|
9846
|
+
const svg = (0, import_react73.useRef)(null);
|
|
9847
|
+
const drag = (0, import_react73.useRef)(null);
|
|
9848
|
+
const [measured, setMeasured] = (0, import_react73.useState)(null);
|
|
9849
|
+
const [frozen, setFrozen] = (0, import_react73.useState)(null);
|
|
9850
|
+
(0, import_react73.useEffect)(() => {
|
|
9832
9851
|
const el = wrapper.current;
|
|
9833
9852
|
if (!responsive || !el || typeof ResizeObserver === "undefined") return;
|
|
9834
9853
|
const observer = new ResizeObserver(([entry]) => {
|
|
@@ -9839,8 +9858,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
9839
9858
|
return () => observer.disconnect();
|
|
9840
9859
|
}, [responsive]);
|
|
9841
9860
|
const sceneWidth = responsive && measured || width;
|
|
9842
|
-
const fullTheme = (0,
|
|
9843
|
-
const scene = (0,
|
|
9861
|
+
const fullTheme = (0, import_react73.useMemo)(() => ({ ...import_chart2.CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
|
|
9862
|
+
const scene = (0, import_react73.useMemo)(
|
|
9844
9863
|
() => (0, import_chart2.layoutChart)(state.spec, {
|
|
9845
9864
|
width: sceneWidth,
|
|
9846
9865
|
height,
|
|
@@ -9856,8 +9875,8 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
9856
9875
|
[state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
|
|
9857
9876
|
);
|
|
9858
9877
|
if (sceneRef) sceneRef.current = scene;
|
|
9859
|
-
const byKey = (0,
|
|
9860
|
-
(0,
|
|
9878
|
+
const byKey = (0, import_react73.useMemo)(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
|
|
9879
|
+
(0, import_react73.useEffect)(() => () => drag.current?.end(), []);
|
|
9861
9880
|
const scenePoint = (e) => (0, import_chart2.chartClientToScene)(scene, svg.current.getBoundingClientRect(), e.clientX, e.clientY);
|
|
9862
9881
|
const onPointerDown = (e) => {
|
|
9863
9882
|
if (!editable || e.button !== 0) return;
|
|
@@ -9915,7 +9934,7 @@ function ChartCanvas({ controller, width = 640, height = 400, responsive = true,
|
|
|
9915
9934
|
}
|
|
9916
9935
|
|
|
9917
9936
|
// src/chart/ChartDataGrid.tsx
|
|
9918
|
-
var
|
|
9937
|
+
var import_react74 = require("react");
|
|
9919
9938
|
var import_chart3 = require("@pixerate/editor/chart");
|
|
9920
9939
|
|
|
9921
9940
|
// src/chart/styles.ts
|
|
@@ -9930,9 +9949,9 @@ var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right t
|
|
|
9930
9949
|
// src/chart/ChartDataGrid.tsx
|
|
9931
9950
|
var import_jsx_runtime53 = require("react/jsx-runtime");
|
|
9932
9951
|
function ChartCommitInput({ value, onCommit, onKeyDown, onBlur, ...rest }) {
|
|
9933
|
-
const [draft, setDraft] = (0,
|
|
9934
|
-
const typing = (0,
|
|
9935
|
-
(0,
|
|
9952
|
+
const [draft, setDraft] = (0, import_react74.useState)(value);
|
|
9953
|
+
const typing = (0, import_react74.useRef)(false);
|
|
9954
|
+
(0, import_react74.useEffect)(() => {
|
|
9936
9955
|
if (!typing.current) setDraft(value);
|
|
9937
9956
|
}, [value]);
|
|
9938
9957
|
const commit = () => {
|
|
@@ -10068,7 +10087,7 @@ function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = fal
|
|
|
10068
10087
|
}
|
|
10069
10088
|
|
|
10070
10089
|
// src/chart/ChartInspector.tsx
|
|
10071
|
-
var
|
|
10090
|
+
var import_react75 = require("react");
|
|
10072
10091
|
var import_chart4 = require("@pixerate/editor/chart");
|
|
10073
10092
|
var import_jsx_runtime54 = require("react/jsx-runtime");
|
|
10074
10093
|
var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
@@ -10233,7 +10252,7 @@ function ErrorBarFields({ controller, series, which, idBase }) {
|
|
|
10233
10252
|
}
|
|
10234
10253
|
function ChartInspector({ controller, sections, className }) {
|
|
10235
10254
|
const { spec, selectedSeries } = useChartState(controller);
|
|
10236
|
-
const idBase = (0,
|
|
10255
|
+
const idBase = (0, import_react75.useId)();
|
|
10237
10256
|
const show = (section) => !sections || sections.includes(section);
|
|
10238
10257
|
const cartesian = (0, import_chart4.isCartesianChart)(spec.type);
|
|
10239
10258
|
const family = (0, import_chart4.chartFamily)(spec);
|
|
@@ -10563,6 +10582,7 @@ function createReactChartNodeView(options = {}) {
|
|
|
10563
10582
|
useSpreadsheetViewport,
|
|
10564
10583
|
useTableMenu,
|
|
10565
10584
|
useToolBridge,
|
|
10585
|
+
useToolRegistryView,
|
|
10566
10586
|
useTrackChanges,
|
|
10567
10587
|
withoutDirty
|
|
10568
10588
|
});
|