@coco-vexel/coco-office-editor 1.0.0 → 1.0.2
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/README.md +33 -1
- package/THIRD_PARTY_NOTICES.md +3 -3
- package/dist/index.cjs +352 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +353 -101
- package/dist/index.js.map +1 -1
- package/dist/{model-DB6aN6uJ.d.cts → model-DNNBhhCB.d.cts} +4 -3
- package/dist/{model-DB6aN6uJ.d.ts → model-DNNBhhCB.d.ts} +4 -3
- package/dist/{native-B6B649CC.d.ts → native-OrEUvS8p.d.ts} +5 -1
- package/dist/native-TMv552dv.d.cts +317 -0
- package/dist/native-TMv552dv.d.ts +317 -0
- package/dist/{native-Ct9nN06K.d.cts → native-f2y3N8N5.d.cts} +5 -1
- package/dist/ppt-native.cjs +129 -59
- package/dist/ppt-native.cjs.map +1 -1
- package/dist/ppt-native.d.cts +1 -1
- package/dist/ppt-native.d.ts +1 -1
- package/dist/ppt-native.js +130 -60
- package/dist/ppt-native.js.map +1 -1
- package/dist/ppt.cjs +129 -58
- package/dist/ppt.cjs.map +1 -1
- package/dist/ppt.d.cts +3 -306
- package/dist/ppt.d.ts +3 -306
- package/dist/ppt.js +130 -60
- package/dist/ppt.js.map +1 -1
- package/dist/read-only-1_LQCO1d.d.cts +7 -0
- package/dist/read-only-1_LQCO1d.d.ts +7 -0
- package/dist/spreadsheet.cjs +114 -17
- package/dist/spreadsheet.cjs.map +1 -1
- package/dist/spreadsheet.d.cts +15 -3
- package/dist/spreadsheet.d.ts +15 -3
- package/dist/spreadsheet.js +114 -18
- package/dist/spreadsheet.js.map +1 -1
- package/dist/word-editing.d.cts +1 -1
- package/dist/word-editing.d.ts +1 -1
- package/dist/word-native.cjs +132 -23
- package/dist/word-native.cjs.map +1 -1
- package/dist/word-native.d.cts +2 -2
- package/dist/word-native.d.ts +2 -2
- package/dist/word-native.js +132 -23
- package/dist/word-native.js.map +1 -1
- package/dist/word-prosemirror.d.cts +1 -1
- package/dist/word-prosemirror.d.ts +1 -1
- package/dist/word.cjs +145 -23
- package/dist/word.cjs.map +1 -1
- package/dist/word.d.cts +5 -4
- package/dist/word.d.ts +5 -4
- package/dist/word.js +145 -24
- package/dist/word.js.map +1 -1
- package/package.json +10 -10
- package/src/styles/editor.css +1 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Raised when a document mutation is attempted while an editor is read-only. */
|
|
2
|
+
declare class EditorReadOnlyError extends Error {
|
|
3
|
+
readonly code = "EDITOR_READ_ONLY";
|
|
4
|
+
constructor(editor: 'word' | 'spreadsheet' | 'ppt');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { EditorReadOnlyError as E };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Raised when a document mutation is attempted while an editor is read-only. */
|
|
2
|
+
declare class EditorReadOnlyError extends Error {
|
|
3
|
+
readonly code = "EDITOR_READ_ONLY";
|
|
4
|
+
constructor(editor: 'word' | 'spreadsheet' | 'ppt');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { EditorReadOnlyError as E };
|
package/dist/spreadsheet.cjs
CHANGED
|
@@ -22,8 +22,31 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
24
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
25
37
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
26
38
|
|
|
39
|
+
// src/read-only.ts
|
|
40
|
+
var _EditorReadOnlyError = class _EditorReadOnlyError extends Error {
|
|
41
|
+
constructor(editor) {
|
|
42
|
+
super(`${editor} editor is read-only`);
|
|
43
|
+
__publicField(this, "code", "EDITOR_READ_ONLY");
|
|
44
|
+
this.name = "EditorReadOnlyError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__name(_EditorReadOnlyError, "EditorReadOnlyError");
|
|
48
|
+
var EditorReadOnlyError = _EditorReadOnlyError;
|
|
49
|
+
|
|
27
50
|
// src/spreadsheet/types.ts
|
|
28
51
|
function rowColumnKey(row, column) {
|
|
29
52
|
return `${row}:${column}`;
|
|
@@ -1603,17 +1626,20 @@ __name(spreadsheetSortRows, "spreadsheetSortRows");
|
|
|
1603
1626
|
|
|
1604
1627
|
// src/spreadsheet/runtime.ts
|
|
1605
1628
|
var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
1606
|
-
constructor(state) {
|
|
1629
|
+
constructor(state, options = {}) {
|
|
1607
1630
|
__publicField(this, "state", state);
|
|
1608
1631
|
__publicField(this, "activeTransaction", null);
|
|
1609
1632
|
__publicField(this, "activeTransactionSource", null);
|
|
1610
1633
|
__publicField(this, "transactionNeedsRefresh", false);
|
|
1634
|
+
__publicField(this, "readOnlyValue");
|
|
1635
|
+
this.readOnlyValue = options.readOnly === true;
|
|
1611
1636
|
}
|
|
1612
1637
|
static async fromZip(bytes, options = {}) {
|
|
1613
|
-
const
|
|
1614
|
-
|
|
1638
|
+
const _a = options, { readOnly } = _a, loadOptions = __objRest(_a, ["readOnly"]);
|
|
1639
|
+
const workbook = await excel.ExcelWorkbook.fromZip(bytes, loadOptions);
|
|
1640
|
+
return _SpreadsheetEditorRuntime.fromWorkbook(workbook, { readOnly });
|
|
1615
1641
|
}
|
|
1616
|
-
static async fromWorkbook(workbook) {
|
|
1642
|
+
static async fromWorkbook(workbook, options = {}) {
|
|
1617
1643
|
const model = await workbook.toModel();
|
|
1618
1644
|
const firstSheet = model.sheets[0];
|
|
1619
1645
|
if (!firstSheet) throw new Error("SpreadsheetEditorRuntime: workbook has no sheets");
|
|
@@ -1626,9 +1652,17 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
1626
1652
|
formulaResults,
|
|
1627
1653
|
formulaEngine,
|
|
1628
1654
|
activeSheet: buildSpreadsheetSheetRenderModel(firstSheet, model.styles, { formulaResults })
|
|
1629
|
-
});
|
|
1655
|
+
}, options);
|
|
1656
|
+
}
|
|
1657
|
+
isReadOnly() {
|
|
1658
|
+
return this.readOnlyValue;
|
|
1659
|
+
}
|
|
1660
|
+
setReadOnly(readOnly) {
|
|
1661
|
+
if (this.activeTransaction) throw new Error("SpreadsheetEditorRuntime: cannot change read-only state during a transaction");
|
|
1662
|
+
this.readOnlyValue = readOnly;
|
|
1630
1663
|
}
|
|
1631
1664
|
workbook() {
|
|
1665
|
+
this.assertWritable();
|
|
1632
1666
|
return this.state.workbook;
|
|
1633
1667
|
}
|
|
1634
1668
|
model() {
|
|
@@ -1641,24 +1675,27 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
1641
1675
|
return this.state.activeSheet;
|
|
1642
1676
|
}
|
|
1643
1677
|
canUndo() {
|
|
1644
|
-
return this.state.workbook.history().canUndo();
|
|
1678
|
+
return !this.readOnlyValue && this.state.workbook.history().canUndo();
|
|
1645
1679
|
}
|
|
1646
1680
|
canRedo() {
|
|
1647
|
-
return this.state.workbook.history().canRedo();
|
|
1681
|
+
return !this.readOnlyValue && this.state.workbook.history().canRedo();
|
|
1648
1682
|
}
|
|
1649
1683
|
async undo() {
|
|
1684
|
+
this.assertWritable();
|
|
1650
1685
|
const result = await this.state.workbook.history().undo();
|
|
1651
1686
|
if (!result) return null;
|
|
1652
1687
|
await this.refresh();
|
|
1653
1688
|
return result;
|
|
1654
1689
|
}
|
|
1655
1690
|
async redo() {
|
|
1691
|
+
this.assertWritable();
|
|
1656
1692
|
const result = await this.state.workbook.history().redo();
|
|
1657
1693
|
if (!result) return null;
|
|
1658
1694
|
await this.refresh();
|
|
1659
1695
|
return result;
|
|
1660
1696
|
}
|
|
1661
1697
|
async runUserTransaction(options, run) {
|
|
1698
|
+
this.assertWritable();
|
|
1662
1699
|
return this.runScopedTransaction(
|
|
1663
1700
|
"user",
|
|
1664
1701
|
(apply) => this.state.workbook.history().runGroup(__spreadProps(__spreadValues({}, options), { source: "user" }), apply),
|
|
@@ -1666,6 +1703,7 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
1666
1703
|
);
|
|
1667
1704
|
}
|
|
1668
1705
|
async runAgentTransaction(options, run) {
|
|
1706
|
+
this.assertWritable();
|
|
1669
1707
|
return this.runScopedTransaction(
|
|
1670
1708
|
"agent",
|
|
1671
1709
|
(apply) => this.state.workbook.history().runAgentGroup(options, apply),
|
|
@@ -2221,6 +2259,7 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
2221
2259
|
);
|
|
2222
2260
|
}
|
|
2223
2261
|
async runUserMutation(options, mutate) {
|
|
2262
|
+
this.assertWritable();
|
|
2224
2263
|
if (this.activeTransaction) {
|
|
2225
2264
|
await mutate(this.activeTransaction);
|
|
2226
2265
|
this.transactionNeedsRefresh = true;
|
|
@@ -2237,6 +2276,7 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
2237
2276
|
);
|
|
2238
2277
|
}
|
|
2239
2278
|
async runWorksheetStructureMutation(recordAgentMutation, mutate) {
|
|
2279
|
+
this.assertWritable();
|
|
2240
2280
|
if (this.activeTransactionSource === "agent" && this.activeTransaction) {
|
|
2241
2281
|
await recordAgentMutation(this.activeTransaction);
|
|
2242
2282
|
this.transactionNeedsRefresh = true;
|
|
@@ -2251,6 +2291,7 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
2251
2291
|
return (_a = (await this.state.workbook.worksheets.getItem(this.state.activeSheetName).getRange(address).styleIds())[0]) == null ? void 0 : _a[0];
|
|
2252
2292
|
}
|
|
2253
2293
|
async runScopedTransaction(source, execute, run) {
|
|
2294
|
+
this.assertWritable();
|
|
2254
2295
|
if (this.activeTransaction) {
|
|
2255
2296
|
await run();
|
|
2256
2297
|
this.transactionNeedsRefresh = true;
|
|
@@ -2278,6 +2319,9 @@ var _SpreadsheetEditorRuntime = class _SpreadsheetEditorRuntime {
|
|
|
2278
2319
|
this.transactionNeedsRefresh = previousNeedsRefresh;
|
|
2279
2320
|
}
|
|
2280
2321
|
}
|
|
2322
|
+
assertWritable() {
|
|
2323
|
+
if (this.readOnlyValue) throw new EditorReadOnlyError("spreadsheet");
|
|
2324
|
+
}
|
|
2281
2325
|
cellEditHistoryGroup(label, address, options) {
|
|
2282
2326
|
var _a;
|
|
2283
2327
|
const base = { label };
|
|
@@ -2775,6 +2819,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2775
2819
|
__publicField(this, "lastStateKey", "");
|
|
2776
2820
|
__publicField(this, "transactionDepth", 0);
|
|
2777
2821
|
__publicField(this, "transactionChanged", false);
|
|
2822
|
+
__publicField(this, "readOnlyValue");
|
|
2778
2823
|
__publicField(this, "handleClick", /* @__PURE__ */ __name((event) => {
|
|
2779
2824
|
if (this.eventPathContains(event, this.contextMenu) || this.eventPathContains(event, this.filterMenu)) return;
|
|
2780
2825
|
if (this.filterMenu.style.display === "block") this.hideFilterMenu();
|
|
@@ -2794,6 +2839,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2794
2839
|
const hit = this.viewport.hitTest(this.eventPoint(event));
|
|
2795
2840
|
if (hit.kind !== "cell" && hit.kind !== "rowHeader" && hit.kind !== "columnHeader") return;
|
|
2796
2841
|
if (hit.kind === "cell" && hit.row === 1 && this.isFilterIconHit(hit.column, event)) {
|
|
2842
|
+
if (this.isReadOnly()) return;
|
|
2797
2843
|
this.openFilterMenu(hit.column, event.clientX, event.clientY);
|
|
2798
2844
|
event.preventDefault();
|
|
2799
2845
|
return;
|
|
@@ -2810,6 +2856,10 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2810
2856
|
}, "handleClick"));
|
|
2811
2857
|
__publicField(this, "handleFilterMenuClick", /* @__PURE__ */ __name((event) => {
|
|
2812
2858
|
var _a;
|
|
2859
|
+
if (this.isReadOnly()) {
|
|
2860
|
+
this.hideFilterMenu();
|
|
2861
|
+
return;
|
|
2862
|
+
}
|
|
2813
2863
|
const target = event.target;
|
|
2814
2864
|
const action = (_a = target.closest("[data-filter-action]")) == null ? void 0 : _a.dataset.filterAction;
|
|
2815
2865
|
if (!action || this.filterMenuColumn === null) return;
|
|
@@ -2835,6 +2885,10 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2835
2885
|
const hit = this.viewport.hitTest(this.eventPoint(event));
|
|
2836
2886
|
if (hit.kind !== "cell") return;
|
|
2837
2887
|
this.selectionState = expandSelectionForMergedRanges(createSelection(hit.row, hit.column), this.runtime().activeSheet());
|
|
2888
|
+
if (this.isReadOnly()) {
|
|
2889
|
+
this.render();
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2838
2892
|
this.openCellEditor();
|
|
2839
2893
|
event.preventDefault();
|
|
2840
2894
|
}, "handleDoubleClick"));
|
|
@@ -2849,6 +2903,11 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2849
2903
|
const chartHit = this.chartAtPoint(point);
|
|
2850
2904
|
if (chartHit) {
|
|
2851
2905
|
this.selectedChartIndex = chartHit.chartIndex;
|
|
2906
|
+
if (this.isReadOnly()) {
|
|
2907
|
+
this.render();
|
|
2908
|
+
event.preventDefault();
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2852
2911
|
this.chartDrag = {
|
|
2853
2912
|
chartIndex: chartHit.chartIndex,
|
|
2854
2913
|
pointer: point,
|
|
@@ -2862,7 +2921,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2862
2921
|
}
|
|
2863
2922
|
this.selectedChartIndex = null;
|
|
2864
2923
|
const resizeHandle = hitSpreadsheetResizeHandle(this.layout, this.viewport.viewports, point);
|
|
2865
|
-
if (resizeHandle) {
|
|
2924
|
+
if (resizeHandle && !this.isReadOnly()) {
|
|
2866
2925
|
this.resizeDrag = startSpreadsheetResizeDrag(resizeHandle, event);
|
|
2867
2926
|
this.host.setPointerCapture(event.pointerId);
|
|
2868
2927
|
this.host.style.cursor = resizeHandle.kind === "column" ? "col-resize" : "row-resize";
|
|
@@ -2872,7 +2931,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2872
2931
|
}
|
|
2873
2932
|
const selectionRange = normalizeSelectionRange(this.selectionState.range);
|
|
2874
2933
|
const fillHandle = (_a = this.renderer) == null ? void 0 : _a.fillHandleRect(this.layout, this.viewport, selectionRange);
|
|
2875
|
-
if (fillHandle && containsPoint2(fillHandle, point) && supportsSpreadsheetAutoFill(this.runtime().activeSheet(), selectionRange)) {
|
|
2934
|
+
if (!this.isReadOnly() && fillHandle && containsPoint2(fillHandle, point) && supportsSpreadsheetAutoFill(this.runtime().activeSheet(), selectionRange)) {
|
|
2876
2935
|
this.autoFillDrag = { source: selectionRange, preview: null };
|
|
2877
2936
|
this.host.setPointerCapture(event.pointerId);
|
|
2878
2937
|
event.preventDefault();
|
|
@@ -2909,7 +2968,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
2909
2968
|
return;
|
|
2910
2969
|
}
|
|
2911
2970
|
if (!this.resizeDrag && !this.autoFillDrag && !this.selecting && !this.editingCell) {
|
|
2912
|
-
const resizeHandle = hitSpreadsheetResizeHandle(this.layout, this.viewport.viewports, this.eventPoint(event));
|
|
2971
|
+
const resizeHandle = this.isReadOnly() ? null : hitSpreadsheetResizeHandle(this.layout, this.viewport.viewports, this.eventPoint(event));
|
|
2913
2972
|
this.host.style.cursor = resizeHandle ? resizeHandle.kind === "column" ? "col-resize" : "row-resize" : "";
|
|
2914
2973
|
}
|
|
2915
2974
|
if (this.resizeDrag) {
|
|
@@ -3006,6 +3065,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3006
3065
|
if (this.editingCell) return;
|
|
3007
3066
|
const { row, column } = this.selectionState.active;
|
|
3008
3067
|
if (event.key === "F2" || event.key === "Enter") {
|
|
3068
|
+
if (this.isReadOnly()) return;
|
|
3009
3069
|
event.preventDefault();
|
|
3010
3070
|
this.openCellEditor();
|
|
3011
3071
|
return;
|
|
@@ -3037,6 +3097,10 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3037
3097
|
}, "handleCopy"));
|
|
3038
3098
|
__publicField(this, "handlePaste", /* @__PURE__ */ __name((event) => {
|
|
3039
3099
|
var _a, _b, _c, _d, _e;
|
|
3100
|
+
if (this.isReadOnly()) {
|
|
3101
|
+
event.preventDefault();
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3040
3104
|
const text = (_b = (_a = event.clipboardData) == null ? void 0 : _a.getData("text/plain")) != null ? _b : "";
|
|
3041
3105
|
if (!text) return;
|
|
3042
3106
|
event.preventDefault();
|
|
@@ -3080,7 +3144,11 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3080
3144
|
}
|
|
3081
3145
|
if (hit.kind !== "cell" && hit.kind !== "rowHeader" && hit.kind !== "columnHeader") return;
|
|
3082
3146
|
event.preventDefault();
|
|
3083
|
-
this.renderContextMenu(
|
|
3147
|
+
this.renderContextMenu(
|
|
3148
|
+
event.clientX,
|
|
3149
|
+
event.clientY,
|
|
3150
|
+
this.isReadOnly() ? void 0 : hit.kind === "columnHeader" ? hit.column : void 0
|
|
3151
|
+
);
|
|
3084
3152
|
}, "handleContextMenu"));
|
|
3085
3153
|
__publicField(this, "handleDocumentPointerDown", /* @__PURE__ */ __name((event) => {
|
|
3086
3154
|
const path = event.composedPath();
|
|
@@ -3095,6 +3163,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3095
3163
|
this.setScroll(next.x, next.y);
|
|
3096
3164
|
}, "handleWheel"));
|
|
3097
3165
|
var _a;
|
|
3166
|
+
this.readOnlyValue = options.readOnly === true;
|
|
3098
3167
|
host.replaceChildren();
|
|
3099
3168
|
this.renderRoot = options.styleIsolation === "none" ? host : (_a = host.shadowRoot) != null ? _a : host.attachShadow({ mode: "open" });
|
|
3100
3169
|
this.renderRoot.replaceChildren();
|
|
@@ -3222,6 +3291,24 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3222
3291
|
if (!this.runtimeValue) throw new Error("SpreadsheetEditor: workbook is not loaded");
|
|
3223
3292
|
return this.runtimeValue;
|
|
3224
3293
|
}
|
|
3294
|
+
isReadOnly() {
|
|
3295
|
+
return this.readOnlyValue;
|
|
3296
|
+
}
|
|
3297
|
+
setReadOnly(readOnly) {
|
|
3298
|
+
if (this.disposed || this.isReadOnly() === readOnly) return;
|
|
3299
|
+
this.cellEditor.cancel();
|
|
3300
|
+
this.resizeDrag = null;
|
|
3301
|
+
this.autoFillDrag = null;
|
|
3302
|
+
this.chartDrag = null;
|
|
3303
|
+
this.selecting = false;
|
|
3304
|
+
this.hideResizeGuide();
|
|
3305
|
+
this.hideContextMenu();
|
|
3306
|
+
this.hideFilterMenu();
|
|
3307
|
+
this.runtime().setReadOnly(readOnly);
|
|
3308
|
+
this.readOnlyValue = readOnly;
|
|
3309
|
+
this.host.setAttribute("aria-readonly", String(readOnly));
|
|
3310
|
+
this.render();
|
|
3311
|
+
}
|
|
3225
3312
|
selection() {
|
|
3226
3313
|
return this.selectionState;
|
|
3227
3314
|
}
|
|
@@ -3390,8 +3477,10 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3390
3477
|
if (previous) await previous.dispose();
|
|
3391
3478
|
this.runtimeValue = await SpreadsheetEditorRuntime.fromZip(bytes, {
|
|
3392
3479
|
workbookId: this.options.workbookId,
|
|
3393
|
-
mode: "inline"
|
|
3480
|
+
mode: "inline",
|
|
3481
|
+
readOnly: this.readOnlyValue
|
|
3394
3482
|
});
|
|
3483
|
+
this.host.setAttribute("aria-readonly", String(this.isReadOnly()));
|
|
3395
3484
|
this.renderTabs();
|
|
3396
3485
|
this.render();
|
|
3397
3486
|
}
|
|
@@ -3484,13 +3573,14 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3484
3573
|
this.scroll
|
|
3485
3574
|
);
|
|
3486
3575
|
renderer.resize(width, height);
|
|
3487
|
-
|
|
3488
|
-
renderer.
|
|
3576
|
+
const headerFiltersEnabled = this.options.enableHeaderFilters === true && !this.isReadOnly();
|
|
3577
|
+
renderer.setHeaderFiltersEnabled(headerFiltersEnabled);
|
|
3578
|
+
renderer.setHeaderFilterColumns(headerFiltersEnabled ? Array.from({ length: layout.columnCount }, (_, index) => index + 1) : null);
|
|
3489
3579
|
renderer.setActiveHeaderFilterColumns(Array.from(this.columnFilters.keys()));
|
|
3490
3580
|
renderer.render(layout, viewport);
|
|
3491
3581
|
const selectionRange = normalizeSelectionRange(this.selectionState.range);
|
|
3492
3582
|
renderer.renderSelection(layout, viewport, selectionRange, {
|
|
3493
|
-
showFillHandle: supportsSpreadsheetAutoFill(runtime.activeSheet(), selectionRange)
|
|
3583
|
+
showFillHandle: !this.isReadOnly() && supportsSpreadsheetAutoFill(runtime.activeSheet(), selectionRange)
|
|
3494
3584
|
});
|
|
3495
3585
|
this.updateCellEditorPosition();
|
|
3496
3586
|
if ((_a = this.autoFillDrag) == null ? void 0 : _a.preview) {
|
|
@@ -3540,7 +3630,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3540
3630
|
textAlign: "center",
|
|
3541
3631
|
font: "13px Arial, sans-serif",
|
|
3542
3632
|
lineHeight: "1.4",
|
|
3543
|
-
cursor: ((_c = this.chartDrag) == null ? void 0 : _c.chartIndex) === chartIndex ? "grabbing" : "move",
|
|
3633
|
+
cursor: this.isReadOnly() ? "default" : ((_c = this.chartDrag) == null ? void 0 : _c.chartIndex) === chartIndex ? "grabbing" : "move",
|
|
3544
3634
|
border: this.selectedChartIndex === chartIndex ? "2px solid #2563eb" : "1px dashed #94a3b8",
|
|
3545
3635
|
boxShadow: this.selectedChartIndex === chartIndex ? "0 0 0 1px rgba(37, 99, 235, 0.18)" : "none"
|
|
3546
3636
|
});
|
|
@@ -3603,7 +3693,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3603
3693
|
this.resizeGuide.style.display = "none";
|
|
3604
3694
|
}
|
|
3605
3695
|
renderContextMenu(x, y, columnHeader) {
|
|
3606
|
-
const items = [
|
|
3696
|
+
const items = this.isReadOnly() ? [{ label: "Copy", action: /* @__PURE__ */ __name(() => this.copySelection(), "action") }] : [
|
|
3607
3697
|
{ label: "Undo", disabled: !this.canUndo(), action: /* @__PURE__ */ __name(() => this.undo(), "action") },
|
|
3608
3698
|
{ label: "Redo", disabled: !this.canRedo(), action: /* @__PURE__ */ __name(() => this.redo(), "action") },
|
|
3609
3699
|
{ label: "Copy", action: /* @__PURE__ */ __name(() => this.copySelection(), "action") },
|
|
@@ -3732,6 +3822,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3732
3822
|
await this.sortColumn(this.selectionState.active.column, direction);
|
|
3733
3823
|
}
|
|
3734
3824
|
async filterColumn(column, values) {
|
|
3825
|
+
this.assertWritable();
|
|
3735
3826
|
if (values === null) this.columnFilters.delete(column);
|
|
3736
3827
|
else this.columnFilters.set(column, [...values]);
|
|
3737
3828
|
await this.applyColumnFilters();
|
|
@@ -3837,6 +3928,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3837
3928
|
}
|
|
3838
3929
|
openCellEditor() {
|
|
3839
3930
|
var _a, _b;
|
|
3931
|
+
if (this.isReadOnly()) return;
|
|
3840
3932
|
if (!this.layout || !this.viewport) return;
|
|
3841
3933
|
const cell = this.selectionState.active;
|
|
3842
3934
|
const viewport = this.viewport.findViewport({
|
|
@@ -3876,6 +3968,7 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3876
3968
|
this.editingCellStyle = null;
|
|
3877
3969
|
this.formulaReferenceRanges = [];
|
|
3878
3970
|
if (!cell) return;
|
|
3971
|
+
this.assertWritable();
|
|
3879
3972
|
const address = excel.formatCellAddress(cell.row, cell.column);
|
|
3880
3973
|
if (value.startsWith("=")) await this.runtime().setCellFormula(address, value.slice(1), { mergeUndo: true });
|
|
3881
3974
|
else await this.runtime().setCellValue(address, coerceEditorValue(value), { mergeUndo: true });
|
|
@@ -3886,6 +3979,9 @@ var _NativeSpreadsheetEditor = class _NativeSpreadsheetEditor {
|
|
|
3886
3979
|
const rect = this.host.getBoundingClientRect();
|
|
3887
3980
|
return { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
3888
3981
|
}
|
|
3982
|
+
assertWritable() {
|
|
3983
|
+
if (this.isReadOnly()) throw new EditorReadOnlyError("spreadsheet");
|
|
3984
|
+
}
|
|
3889
3985
|
eventPathContains(event, node) {
|
|
3890
3986
|
return event.composedPath().includes(node);
|
|
3891
3987
|
}
|
|
@@ -4210,6 +4306,7 @@ function formulaReferenceCell(value) {
|
|
|
4210
4306
|
}
|
|
4211
4307
|
__name(formulaReferenceCell, "formulaReferenceCell");
|
|
4212
4308
|
|
|
4309
|
+
exports.EditorReadOnlyError = EditorReadOnlyError;
|
|
4213
4310
|
exports.SPREADSHEET_COLUMN_RESIZE_MIN = SPREADSHEET_COLUMN_RESIZE_MIN;
|
|
4214
4311
|
exports.SPREADSHEET_RESIZE_HIT_TOLERANCE = SPREADSHEET_RESIZE_HIT_TOLERANCE;
|
|
4215
4312
|
exports.SPREADSHEET_ROW_RESIZE_MIN = SPREADSHEET_ROW_RESIZE_MIN;
|