@w100n/documents 0.3.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SheetView-3XTEV2VT.css +319 -0
- package/dist/SheetView-3XTEV2VT.css.map +1 -0
- package/dist/SheetView-JYH2ZUZF.js +928 -0
- package/dist/SheetView-JYH2ZUZF.js.map +1 -0
- package/dist/TextEditor-X3X62R46.js +982 -0
- package/dist/TextEditor-X3X62R46.js.map +1 -0
- package/dist/caveat-cyrillic-XVO43JCM.woff2 +0 -0
- package/dist/caveat-latin-IUBKKMHQ.woff2 +0 -0
- package/dist/caveat-latin-ext-5S7R5SZN.woff2 +0 -0
- package/dist/chunk-CE3AADY6.js +3447 -0
- package/dist/chunk-CE3AADY6.js.map +1 -0
- package/dist/chunk-ISOOUYLI.js +150 -0
- package/dist/chunk-ISOOUYLI.js.map +1 -0
- package/dist/{chunk-KEV4R7W5.js → chunk-K364NAYP.js} +4 -1
- package/dist/chunk-K364NAYP.js.map +1 -0
- package/dist/chunk-QDH7EZAF.js +27 -0
- package/dist/chunk-QDH7EZAF.js.map +1 -0
- package/dist/chunk-SVRYWMES.js +196 -0
- package/dist/chunk-SVRYWMES.js.map +1 -0
- package/dist/chunk-TDP6OJET.js +31 -0
- package/dist/chunk-TDP6OJET.js.map +1 -0
- package/dist/chunk-TNSN4ZQ5.js +2909 -0
- package/dist/chunk-TNSN4ZQ5.js.map +1 -0
- package/dist/collab.cjs +6312 -0
- package/dist/collab.cjs.map +1 -0
- package/dist/collab.d.cts +39 -0
- package/dist/collab.d.ts +39 -0
- package/dist/collab.js +30 -0
- package/dist/collab.js.map +1 -0
- package/dist/grid-EI5JNZAA.js +88 -0
- package/dist/grid-EI5JNZAA.js.map +1 -0
- package/dist/index.cjs +12265 -407
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +3448 -214
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +145 -7
- package/dist/index.d.ts +145 -7
- package/dist/index.js +3469 -340
- package/dist/index.js.map +1 -1
- package/dist/memory.cjs +59 -7
- package/dist/memory.cjs.map +1 -1
- package/dist/memory.d.cts +7 -2
- package/dist/memory.d.ts +7 -2
- package/dist/memory.js +57 -8
- package/dist/memory.js.map +1 -1
- package/dist/pdfWrite-EM6GJDBF.js +76 -0
- package/dist/pdfWrite-EM6GJDBF.js.map +1 -0
- package/dist/types-B5oF25dn.d.cts +165 -0
- package/dist/types-B5oF25dn.d.ts +165 -0
- package/dist/write-DaVtTJCS.d.cts +6 -0
- package/dist/write-DaVtTJCS.d.ts +6 -0
- package/package.json +45 -3
- package/dist/chunk-KEV4R7W5.js.map +0 -1
- package/dist/types-DiEpNWSu.d.cts +0 -59
- package/dist/types-DiEpNWSu.d.ts +0 -59
|
@@ -0,0 +1,928 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
useLive
|
|
4
|
+
} from "./chunk-SVRYWMES.js";
|
|
5
|
+
import {
|
|
6
|
+
SheetRefusal,
|
|
7
|
+
build,
|
|
8
|
+
canon,
|
|
9
|
+
extras,
|
|
10
|
+
fnv,
|
|
11
|
+
fresh,
|
|
12
|
+
insert,
|
|
13
|
+
made,
|
|
14
|
+
move,
|
|
15
|
+
notesOf,
|
|
16
|
+
parts,
|
|
17
|
+
pieces,
|
|
18
|
+
props,
|
|
19
|
+
readSheet,
|
|
20
|
+
rebase,
|
|
21
|
+
resize,
|
|
22
|
+
sheetOf,
|
|
23
|
+
sheetTexts,
|
|
24
|
+
spot,
|
|
25
|
+
strip,
|
|
26
|
+
worksheets,
|
|
27
|
+
writeSheet
|
|
28
|
+
} from "./chunk-CE3AADY6.js";
|
|
29
|
+
import {
|
|
30
|
+
rove,
|
|
31
|
+
useRestore
|
|
32
|
+
} from "./chunk-TDP6OJET.js";
|
|
33
|
+
import "./chunk-TNSN4ZQ5.js";
|
|
34
|
+
import {
|
|
35
|
+
span
|
|
36
|
+
} from "./chunk-ISOOUYLI.js";
|
|
37
|
+
|
|
38
|
+
// src/sheets/SheetView.tsx
|
|
39
|
+
import { useEffect, useRef, useState } from "react";
|
|
40
|
+
import {
|
|
41
|
+
ArrowDownAZ,
|
|
42
|
+
ArrowDownZA,
|
|
43
|
+
Baseline,
|
|
44
|
+
BetweenHorizontalEnd,
|
|
45
|
+
BetweenHorizontalStart,
|
|
46
|
+
BetweenVerticalEnd,
|
|
47
|
+
BetweenVerticalStart,
|
|
48
|
+
Bold,
|
|
49
|
+
ChevronDown,
|
|
50
|
+
Funnel,
|
|
51
|
+
Grid2x2,
|
|
52
|
+
Italic,
|
|
53
|
+
PaintBucket,
|
|
54
|
+
PanelBottom,
|
|
55
|
+
Redo2,
|
|
56
|
+
Save,
|
|
57
|
+
Search,
|
|
58
|
+
Snowflake,
|
|
59
|
+
Square,
|
|
60
|
+
SquareDashed,
|
|
61
|
+
StickyNote,
|
|
62
|
+
Strikethrough,
|
|
63
|
+
TableCellsMerge,
|
|
64
|
+
TableCellsSplit,
|
|
65
|
+
TableColumnsSplit,
|
|
66
|
+
TableRowsSplit,
|
|
67
|
+
TextAlignCenter,
|
|
68
|
+
TextAlignEnd,
|
|
69
|
+
TextAlignStart,
|
|
70
|
+
TextWrap,
|
|
71
|
+
Underline,
|
|
72
|
+
Undo2,
|
|
73
|
+
WifiOff
|
|
74
|
+
} from "lucide-react";
|
|
75
|
+
|
|
76
|
+
// src/sheets/bind.ts
|
|
77
|
+
import { ICommandService, IUndoRedoService, IUniverInstanceService, mergeWorksheetSnapshotWithDefault } from "@univerjs/core";
|
|
78
|
+
import { SheetLazyExecuteScheduleService } from "@univerjs/sheets";
|
|
79
|
+
|
|
80
|
+
// src/sheets/engine.ts
|
|
81
|
+
var quiet = /* @__PURE__ */ new Set([
|
|
82
|
+
"sheet.mutation.set-worksheet-row-auto-height",
|
|
83
|
+
"sheet.mutation.mark-dirty-filter-change",
|
|
84
|
+
"sheet.mutation.re-calc-filter",
|
|
85
|
+
"sheet.mutation.toggle-note-popup",
|
|
86
|
+
"sheet.mutation.update-note-position",
|
|
87
|
+
"sheet.mutation.empty",
|
|
88
|
+
"sheet.mutation.set-zoom-ratio"
|
|
89
|
+
]);
|
|
90
|
+
var mutation = 2;
|
|
91
|
+
var allowed = (rights, id) => rights.edit || quiet.has(id) || rights.comment && /\.(update|remove|delete)-note$|note-popup$/.test(id);
|
|
92
|
+
function track(api, model, rights, onDirty) {
|
|
93
|
+
const lines = model.lines;
|
|
94
|
+
const ours = (p) => p?.unitId === model.book.id;
|
|
95
|
+
const before = api.addEvent(api.Event.BeforeCommandExecute, (e) => {
|
|
96
|
+
if (e.type !== mutation || e.options?.onlyLocal || e.options?.fromCollab || !ours(e.params)) return;
|
|
97
|
+
if (!allowed(rights, e.id)) e.cancel = true;
|
|
98
|
+
});
|
|
99
|
+
const after = api.addEvent(api.Event.CommandExecuted, (e) => {
|
|
100
|
+
if (e.type !== mutation || e.options?.onlyLocal || e.options?.fromCollab || !ours(e.params)) return;
|
|
101
|
+
const p = e.params ?? {};
|
|
102
|
+
const l = p.subUnitId ? lines[p.subUnitId] : void 0;
|
|
103
|
+
const span2 = (r, rows) => r ? rows ? r.endRow - r.startRow + 1 : r.endColumn - r.startColumn + 1 : 0;
|
|
104
|
+
if (e.id === "sheet.mutation.insert-sheet" && p.sheet) {
|
|
105
|
+
lines[p.sheet.id] = { rows: Array.from({ length: p.sheet.rowCount ?? 1e3 }, () => fresh("n")), cols: Array.from({ length: p.sheet.columnCount ?? 26 }, () => fresh("n")) };
|
|
106
|
+
} else if (e.id === "sheet.mutation.remove-sheet" && p.subUnitId) delete lines[p.subUnitId];
|
|
107
|
+
else if (l) {
|
|
108
|
+
if (e.id === "sheet.mutation.insert-row") insert(l.rows, p.range.startRow, span2(p.range, true), "n");
|
|
109
|
+
else if (e.id === "sheet.mutation.remove-rows") l.rows.splice(p.range.startRow, span2(p.range, true));
|
|
110
|
+
else if (e.id === "sheet.mutation.move-rows") move(l.rows, p.sourceRange.startRow, span2(p.sourceRange, true), p.targetRange.startRow);
|
|
111
|
+
else if (e.id === "sheet.mutation.insert-col") insert(l.cols, p.range.startColumn, span2(p.range, false), "n");
|
|
112
|
+
else if (e.id === "sheet.mutation.remove-col") l.cols.splice(p.range.startColumn, span2(p.range, false));
|
|
113
|
+
else if (e.id === "sheet.mutation.move-columns") move(l.cols, p.sourceRange.startColumn, span2(p.sourceRange, false), p.targetRange.startColumn);
|
|
114
|
+
else if (e.id === "sheet.mutation.set-worksheet-row-count" && p.rowCount) resize(l.rows, p.rowCount, "n");
|
|
115
|
+
else if (e.id === "sheet.mutation.set-worksheet-column-count" && p.columnCount) resize(l.cols, p.columnCount, "n");
|
|
116
|
+
}
|
|
117
|
+
if (!quiet.has(e.id)) onDirty();
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
before.dispose();
|
|
121
|
+
after.dispose();
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function snapshot(api, model) {
|
|
125
|
+
const wb = api.getActiveWorkbook();
|
|
126
|
+
const book = wb.save();
|
|
127
|
+
const lines = Object.fromEntries(book.sheetOrder.map((sid) => {
|
|
128
|
+
const l = model.lines[sid] ?? { rows: [], cols: [] };
|
|
129
|
+
const sheet = book.sheets[sid];
|
|
130
|
+
const rows = [...l.rows], cols = [...l.cols];
|
|
131
|
+
resize(rows, sheet.rowCount ?? rows.length, "n");
|
|
132
|
+
resize(cols, sheet.columnCount ?? cols.length, "n");
|
|
133
|
+
return [sid, { rows, cols }];
|
|
134
|
+
}));
|
|
135
|
+
return { ...model, book, lines, active: wb.getActiveSheet().getSheetId() };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/sheets/bind.ts
|
|
139
|
+
var setters = [
|
|
140
|
+
["name", "sheet.mutation.set-worksheet-name", "name", ""],
|
|
141
|
+
["hidden", "sheet.mutation.set-worksheet-hidden", "hidden", 0],
|
|
142
|
+
["tabColor", "sheet.mutation.set-tab-color", "color", ""],
|
|
143
|
+
["showGridlines", "sheet.mutation.toggle-gridlines", "showGridlines", 1],
|
|
144
|
+
["rightToLeft", "sheet.mutation.set-worksheet-right-to-left", "rightToLeft", 0],
|
|
145
|
+
["freeze", "sheet.mutation.set-frozen", "", { startRow: -1, startColumn: -1, xSplit: 0, ySplit: 0 }]
|
|
146
|
+
];
|
|
147
|
+
var closed = /\.command\.(.*filter-(range|criteria)|.*toggle-filter|.*sheet-filter|.*data-?validation.*|.*defined-name|.*protection)$/i;
|
|
148
|
+
function bind(api, injector, doc, model, edit) {
|
|
149
|
+
const unit = model.book.id;
|
|
150
|
+
const wb = injector.get(IUniverInstanceService).getUnit(unit);
|
|
151
|
+
const { order, sheets, styles, values } = parts(doc);
|
|
152
|
+
const lines = model.lines;
|
|
153
|
+
const me = {};
|
|
154
|
+
let open = true;
|
|
155
|
+
const looks = wb.getStyles();
|
|
156
|
+
const commands = injector.get(ICommandService);
|
|
157
|
+
const run = (id, params) => commands.hasCommand(id) && commands.syncExecuteCommand(id, { unitId: unit, ...params }, { fromCollab: true });
|
|
158
|
+
const ws = (sid) => wb.getSheetBySheetId(sid);
|
|
159
|
+
const at = /* @__PURE__ */ new Map();
|
|
160
|
+
const index = (sid) => at.get(sid) ?? at.set(sid, { rows: new Map(lines[sid].rows.map((id, i) => [id, i])), cols: new Map(lines[sid].cols.map((id, i) => [id, i])) }).get(sid);
|
|
161
|
+
const live = (sid) => !!sid && !!lines[sid] && sheets.has(sid) && !!wb.getSheetBySheetId(sid);
|
|
162
|
+
const look = (s) => {
|
|
163
|
+
const style = typeof s === "string" ? looks.get(s) : s;
|
|
164
|
+
if (!style || !Object.keys(style).length) return void 0;
|
|
165
|
+
const text = canon(style);
|
|
166
|
+
if (typeof s === "string" && styles.has(s) && canon(styles.get(s)) === text) return s;
|
|
167
|
+
const id = `y${fnv(new TextEncoder().encode(text)).toString(36)}`;
|
|
168
|
+
if (!styles.has(id)) styles.set(id, style);
|
|
169
|
+
return id;
|
|
170
|
+
};
|
|
171
|
+
const cellOf = (sid, r, c) => {
|
|
172
|
+
const raw = ws(sid).getCellRaw(r, c);
|
|
173
|
+
if (!raw) return null;
|
|
174
|
+
const f = raw.f || (raw.si ? api.getWorkbook(unit).getSheetBySheetId(sid).getRange(r, c).getFormula() : "");
|
|
175
|
+
const out = f ? { f } : strip({ v: raw.v, t: raw.t });
|
|
176
|
+
if (raw.p) out.p = raw.p;
|
|
177
|
+
const s = look(raw.s);
|
|
178
|
+
if (s) out.s = s;
|
|
179
|
+
return Object.keys(out).length ? out : null;
|
|
180
|
+
};
|
|
181
|
+
const put = (sid, r, c) => {
|
|
182
|
+
const row = lines[sid].rows[r], col = lines[sid].cols[c];
|
|
183
|
+
if (row === void 0 || col === void 0) return;
|
|
184
|
+
const { cells } = pieces(sheets.get(sid));
|
|
185
|
+
const key = spot(row, col);
|
|
186
|
+
const next = cellOf(sid, r, c), was = cells.get(key);
|
|
187
|
+
if (canon(next) === canon(was)) return;
|
|
188
|
+
if (next) cells.set(key, next);
|
|
189
|
+
else cells.delete(key);
|
|
190
|
+
if (next?.f !== was?.f) values.delete(`${sid}:${key}`);
|
|
191
|
+
};
|
|
192
|
+
const each = (m, fn) => {
|
|
193
|
+
for (const [r, line] of Object.entries(m ?? {})) for (const c of Object.keys(line ?? {})) fn(+r, +c);
|
|
194
|
+
};
|
|
195
|
+
const putRow = (sid, r) => {
|
|
196
|
+
const id = lines[sid].rows[r];
|
|
197
|
+
const raw = ws(sid).getRowManager().getRow(r);
|
|
198
|
+
const { rowData } = pieces(sheets.get(sid));
|
|
199
|
+
const next = raw ? strip({ h: raw.h, hd: raw.hd || void 0, ia: raw.ia, s: look(raw.s) }) : {};
|
|
200
|
+
if (id === void 0 || canon(next) === canon(rowData.get(id) ?? {})) return;
|
|
201
|
+
if (Object.keys(next).length) rowData.set(id, next);
|
|
202
|
+
else rowData.delete(id);
|
|
203
|
+
};
|
|
204
|
+
const putCol = (sid, c) => {
|
|
205
|
+
const id = lines[sid].cols[c];
|
|
206
|
+
const raw = ws(sid).getColumnManager().getColumn(c);
|
|
207
|
+
const { colData } = pieces(sheets.get(sid));
|
|
208
|
+
const next = raw ? strip({ w: raw.w, hd: raw.hd || void 0, s: look(raw.s) }) : {};
|
|
209
|
+
if (id === void 0 || canon(next) === canon(colData.get(id) ?? {})) return;
|
|
210
|
+
if (Object.keys(next).length) colData.set(id, next);
|
|
211
|
+
else colData.delete(id);
|
|
212
|
+
};
|
|
213
|
+
const merges = (sid) => {
|
|
214
|
+
const l = lines[sid];
|
|
215
|
+
const { merges: kept } = pieces(sheets.get(sid));
|
|
216
|
+
const want = new Set(ws(sid).getMergeData().map((b) => [l.rows[b.startRow], l.cols[b.startColumn], l.rows[b.endRow], l.cols[b.endColumn]].join(":")));
|
|
217
|
+
for (const k of [...kept.keys()]) if (!want.has(k)) kept.delete(k);
|
|
218
|
+
for (const k of want) if (!kept.has(k)) kept.set(k, 1);
|
|
219
|
+
};
|
|
220
|
+
const notes = (sid) => {
|
|
221
|
+
const l = lines[sid];
|
|
222
|
+
const { notes: kept } = pieces(sheets.get(sid));
|
|
223
|
+
const want = new Map(api.getWorkbook(unit).getSheetBySheetId(sid).getNotes().map((n) => [spot(l.rows[n.row], l.cols[n.col]), { note: n.note, width: n.width, height: n.height }]));
|
|
224
|
+
for (const k of [...kept.keys()]) if (!want.has(k)) kept.delete(k);
|
|
225
|
+
for (const [k, n] of want) if (canon(kept.get(k)) !== canon(n)) kept.set(k, n);
|
|
226
|
+
};
|
|
227
|
+
const prop = (sid, name) => {
|
|
228
|
+
const m = sheets.get(sid);
|
|
229
|
+
const empty = setters.find((x) => x[0] === name)[3];
|
|
230
|
+
const now = ws(sid).getConfig()[name] ?? empty;
|
|
231
|
+
if (canon(m.get(name) ?? empty) === canon(now)) return;
|
|
232
|
+
if (canon(now) === canon(empty)) m.delete(name);
|
|
233
|
+
else m.set(name, now);
|
|
234
|
+
};
|
|
235
|
+
const fit = (list, now) => {
|
|
236
|
+
if (list.length > now.length) list.delete(now.length, list.length - now.length);
|
|
237
|
+
else if (list.length < now.length) list.push(now.slice(list.length));
|
|
238
|
+
};
|
|
239
|
+
const resync = (sid) => {
|
|
240
|
+
const l = lines[sid];
|
|
241
|
+
const { cells } = pieces(sheets.get(sid));
|
|
242
|
+
const seen = /* @__PURE__ */ new Set();
|
|
243
|
+
ws(sid).getCellMatrix().forValue((r, c) => {
|
|
244
|
+
put(sid, r, c);
|
|
245
|
+
seen.add(spot(l.rows[r], l.cols[c]));
|
|
246
|
+
});
|
|
247
|
+
const { rows, cols } = index(sid);
|
|
248
|
+
for (const k of [...cells.keys()]) if (!seen.has(k) && rows.has(k.split(":")[0]) && cols.has(k.split(":")[1])) cells.delete(k);
|
|
249
|
+
l.rows.forEach((_, r) => putRow(sid, r));
|
|
250
|
+
l.cols.forEach((_, c) => putCol(sid, c));
|
|
251
|
+
merges(sid);
|
|
252
|
+
notes(sid);
|
|
253
|
+
props.forEach((name) => prop(sid, name));
|
|
254
|
+
};
|
|
255
|
+
const write = (id, p) => {
|
|
256
|
+
const sid = p.subUnitId ?? p.sheetId;
|
|
257
|
+
if (id === "sheet.mutation.insert-sheet" && p.sheet && lines[p.sheet.id]) {
|
|
258
|
+
const added = p.sheet.id;
|
|
259
|
+
sheets.set(added, made(ws(added).getConfig(), lines[added]));
|
|
260
|
+
order.insert(Math.min(p.index ?? order.length, order.length), [added]);
|
|
261
|
+
return resync(added);
|
|
262
|
+
}
|
|
263
|
+
if (id === "sheet.mutation.remove-sheet" && sid) {
|
|
264
|
+
at.delete(sid);
|
|
265
|
+
sheets.delete(sid);
|
|
266
|
+
const i = order.toArray().indexOf(sid);
|
|
267
|
+
if (i >= 0) order.delete(i, 1);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (id === "sheet.mutation.set-worksheet-order" && sid) {
|
|
271
|
+
const i = order.toArray().indexOf(sid);
|
|
272
|
+
if (i >= 0) order.delete(i, 1);
|
|
273
|
+
return order.insert(Math.min(p.toOrder ?? 0, order.length), [sid]);
|
|
274
|
+
}
|
|
275
|
+
if (id === "sheet.mutation.move-range" && p.from && p.to) {
|
|
276
|
+
if (live(p.from.subUnitId)) each(p.from.value, (r, c) => put(p.from.subUnitId, r, c));
|
|
277
|
+
if (live(p.to.subUnitId)) each(p.to.value, (r, c) => put(p.to.subUnitId, r, c));
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!live(sid)) return;
|
|
281
|
+
const { rows, cols } = pieces(sheets.get(sid));
|
|
282
|
+
const l = lines[sid];
|
|
283
|
+
const count = (r, row) => row ? r.endRow - r.startRow + 1 : r.endColumn - r.startColumn + 1;
|
|
284
|
+
const shift = (list, from, n, to) => {
|
|
285
|
+
const ids = list.slice(from, from + n);
|
|
286
|
+
list.delete(from, n);
|
|
287
|
+
list.insert(to > from ? to - n : to, ids);
|
|
288
|
+
at.delete(sid);
|
|
289
|
+
};
|
|
290
|
+
switch (id) {
|
|
291
|
+
case "sheet.mutation.set-range-values":
|
|
292
|
+
return each(p.cellValue, (r, c) => put(sid, r, c));
|
|
293
|
+
case "sheet.mutation.reorder-range":
|
|
294
|
+
for (let r = p.range.startRow; r <= p.range.endRow; r++) for (let c = p.range.startColumn; c <= p.range.endColumn; c++) put(sid, r, c);
|
|
295
|
+
return;
|
|
296
|
+
case "sheet.mutation.insert-row":
|
|
297
|
+
rows.insert(p.range.startRow, l.rows.slice(p.range.startRow, p.range.endRow + 1));
|
|
298
|
+
at.delete(sid);
|
|
299
|
+
for (let r = p.range.startRow; r <= p.range.endRow; r++) putRow(sid, r);
|
|
300
|
+
return;
|
|
301
|
+
case "sheet.mutation.insert-col":
|
|
302
|
+
cols.insert(p.range.startColumn, l.cols.slice(p.range.startColumn, p.range.endColumn + 1));
|
|
303
|
+
at.delete(sid);
|
|
304
|
+
for (let c = p.range.startColumn; c <= p.range.endColumn; c++) putCol(sid, c);
|
|
305
|
+
return;
|
|
306
|
+
case "sheet.mutation.remove-rows":
|
|
307
|
+
at.delete(sid);
|
|
308
|
+
return rows.delete(p.range.startRow, count(p.range, true));
|
|
309
|
+
case "sheet.mutation.remove-col":
|
|
310
|
+
at.delete(sid);
|
|
311
|
+
return cols.delete(p.range.startColumn, count(p.range, false));
|
|
312
|
+
case "sheet.mutation.move-rows":
|
|
313
|
+
return shift(rows, p.sourceRange.startRow, count(p.sourceRange, true), p.targetRange.startRow);
|
|
314
|
+
case "sheet.mutation.move-columns":
|
|
315
|
+
return shift(cols, p.sourceRange.startColumn, count(p.sourceRange, false), p.targetRange.startColumn);
|
|
316
|
+
case "sheet.mutation.set-worksheet-row-count":
|
|
317
|
+
at.delete(sid);
|
|
318
|
+
return fit(rows, l.rows);
|
|
319
|
+
case "sheet.mutation.set-worksheet-column-count":
|
|
320
|
+
at.delete(sid);
|
|
321
|
+
return fit(cols, l.cols);
|
|
322
|
+
case "sheet.mutation.set-worksheet-row-height":
|
|
323
|
+
case "sheet.mutation.set-worksheet-row-is-auto-height":
|
|
324
|
+
case "sheet.mutation.set-row-hidden":
|
|
325
|
+
case "sheet.mutation.set-row-visible":
|
|
326
|
+
for (const r of p.ranges ?? []) for (let i = r.startRow; i <= r.endRow; i++) putRow(sid, i);
|
|
327
|
+
return;
|
|
328
|
+
case "sheet.mutation.set-worksheet-col-width":
|
|
329
|
+
case "sheet.mutation.set-col-hidden":
|
|
330
|
+
case "sheet.mutation.set-col-visible":
|
|
331
|
+
for (const r of p.ranges ?? []) for (let i = r.startColumn; i <= r.endColumn; i++) putCol(sid, i);
|
|
332
|
+
return;
|
|
333
|
+
case "sheet.mutation.set-row-data":
|
|
334
|
+
return Object.keys(p.rowData ?? {}).forEach((r) => putRow(sid, +r));
|
|
335
|
+
case "sheet.mutation.set-col-data":
|
|
336
|
+
return Object.keys(p.columnData ?? {}).forEach((c) => putCol(sid, +c));
|
|
337
|
+
case "sheet.mutation.add-worksheet-merge":
|
|
338
|
+
case "sheet.mutation.remove-worksheet-merge":
|
|
339
|
+
return merges(sid);
|
|
340
|
+
case "sheet.mutation.update-note":
|
|
341
|
+
case "sheet.mutation.remove-note":
|
|
342
|
+
case "sheet.mutation.update-note-position":
|
|
343
|
+
return notes(sid);
|
|
344
|
+
default: {
|
|
345
|
+
const setter = setters.find((x) => x[1] === id);
|
|
346
|
+
if (setter) prop(sid, setter[0]);
|
|
347
|
+
else if (!quiet.has(id)) resync(sid);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
const computed = (p) => {
|
|
352
|
+
const sid = p.subUnitId;
|
|
353
|
+
if (!live(sid)) return;
|
|
354
|
+
each(p.cellValue, (r, c) => {
|
|
355
|
+
const raw = ws(sid).getCellRaw(r, c);
|
|
356
|
+
const row = lines[sid].rows[r], col = lines[sid].cols[c];
|
|
357
|
+
if (!raw?.f && !raw?.si || row === void 0 || col === void 0) return;
|
|
358
|
+
const key = `${sid}:${spot(row, col)}`, next = { v: raw.v ?? null, t: raw.t ?? null };
|
|
359
|
+
if (canon(values.get(key)) !== canon(next)) values.set(key, next);
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
const refuse = api.addEvent(api.Event.BeforeCommandExecute, (e) => {
|
|
363
|
+
if (edit && e.type === 0 && closed.test(e.id)) e.cancel = true;
|
|
364
|
+
});
|
|
365
|
+
const local = api.addEvent(api.Event.CommandExecuted, (e) => {
|
|
366
|
+
const p = e.params ?? {};
|
|
367
|
+
if (e.type !== 2 || p.unitId !== unit || e.options?.fromCollab || !edit) return;
|
|
368
|
+
if (e.options?.onlyLocal) {
|
|
369
|
+
if (e.options.applyFormulaCalculationResult) doc.transact(() => computed(p), me);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
doc.transact(() => write(e.id, p), me);
|
|
373
|
+
});
|
|
374
|
+
const lazy = commands.onMutationExecutedForCollab((e, options) => {
|
|
375
|
+
if (!edit || !options?.syncOnly || e.id !== "sheet.mutation.copy-worksheet-end") return;
|
|
376
|
+
const sid = e.params.subUnitId;
|
|
377
|
+
const wait = () => open && (injector.get(SheetLazyExecuteScheduleService).hasPendingTasks() ? setTimeout(wait, 100) : live(sid) && doc.transact(() => resync(sid), me));
|
|
378
|
+
wait();
|
|
379
|
+
});
|
|
380
|
+
const full = (sid, key, x) => {
|
|
381
|
+
if (!x) return null;
|
|
382
|
+
const kept = x.f ? values.get(`${sid}:${key}`) : void 0;
|
|
383
|
+
return { v: (x.f ? kept?.v : x.v) ?? null, t: (x.f ? kept?.t : x.t) ?? void 0, f: x.f ?? null, si: null, p: x.p ?? null, s: x.s ? styles.get(x.s) ?? null : null };
|
|
384
|
+
};
|
|
385
|
+
const cellsTo = (sid, keys) => {
|
|
386
|
+
const { cells } = pieces(sheets.get(sid));
|
|
387
|
+
const { rows, cols } = index(sid);
|
|
388
|
+
const cellValue = {};
|
|
389
|
+
for (const key of keys) {
|
|
390
|
+
const [row, col] = key.split(":");
|
|
391
|
+
const r = rows.get(row), c = cols.get(col);
|
|
392
|
+
if (r !== void 0 && c !== void 0) (cellValue[r] ?? (cellValue[r] = {}))[c] = full(sid, key, cells.get(key));
|
|
393
|
+
}
|
|
394
|
+
if (Object.keys(cellValue).length) run("sheet.mutation.set-range-values", { subUnitId: sid, cellValue, isOverrideStyle: true });
|
|
395
|
+
};
|
|
396
|
+
const linesTo = (sid, ids, row) => {
|
|
397
|
+
const { rowData, colData } = pieces(sheets.get(sid));
|
|
398
|
+
const map = row ? index(sid).rows : index(sid).cols;
|
|
399
|
+
const info = {}, sizes = {};
|
|
400
|
+
const ranges = [];
|
|
401
|
+
for (const id of ids) {
|
|
402
|
+
const i = map.get(id);
|
|
403
|
+
if (i === void 0) continue;
|
|
404
|
+
const x = (row ? rowData : colData).get(id);
|
|
405
|
+
const s = x?.s ? styles.get(x.s) : void 0;
|
|
406
|
+
info[i] = x ? row ? { h: x.h, hd: x.hd, ia: x.ia, s } : { w: x.w, hd: x.hd, s } : null;
|
|
407
|
+
const size = row ? x?.h : x?.w;
|
|
408
|
+
if (size !== void 0) sizes[i] = size;
|
|
409
|
+
ranges.push({ startRow: row ? i : 0, endRow: row ? i : 0, startColumn: row ? 0 : i, endColumn: row ? 0 : i });
|
|
410
|
+
}
|
|
411
|
+
if (!ranges.length) return;
|
|
412
|
+
if (row) {
|
|
413
|
+
run("sheet.mutation.set-row-data", { subUnitId: sid, rowData: info });
|
|
414
|
+
run("sheet.mutation.set-worksheet-row-height", { subUnitId: sid, ranges, rowHeight: sizes });
|
|
415
|
+
} else {
|
|
416
|
+
run("sheet.mutation.set-col-data", { subUnitId: sid, columnData: info });
|
|
417
|
+
run("sheet.mutation.set-worksheet-col-width", { subUnitId: sid, ranges, colWidth: sizes });
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const mergesTo = (sid) => {
|
|
421
|
+
const { merges: kept } = pieces(sheets.get(sid));
|
|
422
|
+
const { rows, cols } = index(sid);
|
|
423
|
+
const want = [...kept.keys()].map((k) => k.split(":")).map(([r0, c0, r1, c1]) => ({ startRow: rows.get(r0), startColumn: cols.get(c0), endRow: rows.get(r1), endColumn: cols.get(c1) })).filter((b) => [b.startRow, b.startColumn, b.endRow, b.endColumn].every((n) => n !== void 0));
|
|
424
|
+
const has = ws(sid).getMergeData().map((b) => ({ startRow: b.startRow, startColumn: b.startColumn, endRow: b.endRow, endColumn: b.endColumn }));
|
|
425
|
+
const gone = has.filter((b) => !want.some((w) => canon(w) === canon(b))), added = want.filter((w) => !has.some((b) => canon(w) === canon(b)));
|
|
426
|
+
if (gone.length) run("sheet.mutation.remove-worksheet-merge", { subUnitId: sid, ranges: gone });
|
|
427
|
+
if (added.length) run("sheet.mutation.add-worksheet-merge", { subUnitId: sid, ranges: added });
|
|
428
|
+
};
|
|
429
|
+
const notesTo = (sid) => {
|
|
430
|
+
const want = notesOf(sheets.get(sid), lines[sid]);
|
|
431
|
+
const shown = api.getWorkbook(unit).getSheetBySheetId(sid).getNotes();
|
|
432
|
+
for (const n of shown) if (!want.some((w) => w.row === n.row && w.col === n.col)) run("sheet.mutation.remove-note", { sheetId: sid, noteId: n.id, row: n.row, col: n.col });
|
|
433
|
+
for (const w of want) {
|
|
434
|
+
const n = shown.find((x) => x.row === w.row && x.col === w.col);
|
|
435
|
+
if (!n || n.note !== w.note || n.width !== w.width || n.height !== w.height) run("sheet.mutation.update-note", { sheetId: sid, row: w.row, col: w.col, note: { note: w.note, width: w.width, height: w.height } });
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
const shape = () => {
|
|
439
|
+
const want = [...new Set(order.toArray())].filter((sid) => sheets.has(sid));
|
|
440
|
+
for (const sheet of wb.getSheets()) {
|
|
441
|
+
const sid = sheet.getSheetId();
|
|
442
|
+
if (want.includes(sid)) continue;
|
|
443
|
+
if (wb.getActiveSheet().getSheetId() === sid) {
|
|
444
|
+
const other = want.find((x) => wb.getSheetBySheetId(x));
|
|
445
|
+
if (other) api.syncExecuteCommand("sheet.operation.set-worksheet-active", { unitId: unit, subUnitId: other });
|
|
446
|
+
}
|
|
447
|
+
run("sheet.mutation.remove-sheet", { subUnitId: sid });
|
|
448
|
+
delete lines[sid];
|
|
449
|
+
at.delete(sid);
|
|
450
|
+
}
|
|
451
|
+
want.forEach((sid, i) => {
|
|
452
|
+
if (wb.getSheetBySheetId(sid)) return;
|
|
453
|
+
const { rows, cols } = pieces(sheets.get(sid));
|
|
454
|
+
lines[sid] = { rows: rows.toArray(), cols: cols.toArray() };
|
|
455
|
+
run("sheet.mutation.insert-sheet", { index: Math.min(i, wb.getSheets().length), sheet: mergeWorksheetSnapshotWithDefault(sheetOf(doc, sid, lines[sid])), styles: styles.toJSON() });
|
|
456
|
+
notesTo(sid);
|
|
457
|
+
});
|
|
458
|
+
want.forEach((sid, i) => {
|
|
459
|
+
const now = wb.getSheetOrders().indexOf(sid);
|
|
460
|
+
if (now >= 0 && now !== i) run("sheet.mutation.set-worksheet-order", { subUnitId: sid, fromOrder: now, toOrder: i });
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
const move2 = (sid, delta, row) => {
|
|
464
|
+
const added = /* @__PURE__ */ new Set();
|
|
465
|
+
if (!delta) return added;
|
|
466
|
+
const list = row ? lines[sid].rows : lines[sid].cols;
|
|
467
|
+
let i = 0;
|
|
468
|
+
for (const d of delta) {
|
|
469
|
+
if (d.retain) i += d.retain;
|
|
470
|
+
if (d.delete) {
|
|
471
|
+
const end = i + d.delete - 1;
|
|
472
|
+
if (row) run("sheet.mutation.remove-rows", { subUnitId: sid, range: { startRow: i, endRow: end, startColumn: 0, endColumn: lines[sid].cols.length - 1, rangeType: 1 } });
|
|
473
|
+
else run("sheet.mutation.remove-col", { subUnitId: sid, range: { startRow: 0, endRow: lines[sid].rows.length - 1, startColumn: i, endColumn: end, rangeType: 2 } });
|
|
474
|
+
list.splice(i, d.delete);
|
|
475
|
+
}
|
|
476
|
+
if (d.insert) {
|
|
477
|
+
const ids = d.insert;
|
|
478
|
+
const end = i + ids.length - 1;
|
|
479
|
+
if (row) run("sheet.mutation.insert-row", { subUnitId: sid, range: { startRow: i, endRow: end, startColumn: 0, endColumn: lines[sid].cols.length - 1 } });
|
|
480
|
+
else run("sheet.mutation.insert-col", { subUnitId: sid, range: { startRow: 0, endRow: lines[sid].rows.length - 1, startColumn: i, endColumn: end } });
|
|
481
|
+
list.splice(i, 0, ...ids);
|
|
482
|
+
ids.forEach((id) => added.add(id));
|
|
483
|
+
i += ids.length;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
at.delete(sid);
|
|
487
|
+
return added;
|
|
488
|
+
};
|
|
489
|
+
const remote = (events, tr) => {
|
|
490
|
+
if (tr.origin === me) return;
|
|
491
|
+
const touched = /* @__PURE__ */ new Map();
|
|
492
|
+
let reshaped = false;
|
|
493
|
+
for (const e of events) {
|
|
494
|
+
const t = e.target;
|
|
495
|
+
if (t === sheets || t === order) {
|
|
496
|
+
reshaped = true;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const owner = t.parent === sheets ? t : t.parent?.parent === sheets ? t.parent : null;
|
|
500
|
+
const sid = owner && [...sheets.entries()].find(([, m2]) => m2 === owner)?.[0];
|
|
501
|
+
if (!owner || !sid) continue;
|
|
502
|
+
if (!touched.has(sid)) touched.set(sid, { rows: null, cols: null, cells: /* @__PURE__ */ new Set(), rowData: /* @__PURE__ */ new Set(), colData: /* @__PURE__ */ new Set(), marks: false, props: /* @__PURE__ */ new Set() });
|
|
503
|
+
const s = touched.get(sid);
|
|
504
|
+
const m = owner;
|
|
505
|
+
const keys = [...e.changes.keys.keys()];
|
|
506
|
+
if (t === owner) keys.forEach((k) => s.props.add(k));
|
|
507
|
+
else if (t === m.get("rows")) s.rows = e.changes.delta;
|
|
508
|
+
else if (t === m.get("cols")) s.cols = e.changes.delta;
|
|
509
|
+
else if (t === m.get("cells")) keys.forEach((k) => s.cells.add(k));
|
|
510
|
+
else if (t === m.get("rowData")) keys.forEach((k) => s.rowData.add(k));
|
|
511
|
+
else if (t === m.get("colData")) keys.forEach((k) => s.colData.add(k));
|
|
512
|
+
else s.marks = true;
|
|
513
|
+
}
|
|
514
|
+
let structural = false;
|
|
515
|
+
if (reshaped) {
|
|
516
|
+
const before = wb.getSheets().length;
|
|
517
|
+
shape();
|
|
518
|
+
structural = before !== wb.getSheets().length;
|
|
519
|
+
}
|
|
520
|
+
for (const [sid, s] of touched) {
|
|
521
|
+
if (!live(sid)) continue;
|
|
522
|
+
const rows = move2(sid, s.rows, true), cols = move2(sid, s.cols, false);
|
|
523
|
+
if (s.rows || s.cols) structural = true;
|
|
524
|
+
for (const [name, id, key, empty] of setters) if (s.props.has(name)) {
|
|
525
|
+
const v = sheets.get(sid).get(name) ?? empty;
|
|
526
|
+
run(id, { subUnitId: sid, ...key ? { [key]: v } : v });
|
|
527
|
+
}
|
|
528
|
+
const keys = new Set(s.cells);
|
|
529
|
+
if (rows.size || cols.size) {
|
|
530
|
+
for (const k of pieces(sheets.get(sid)).cells.keys()) if (rows.has(k.split(":")[0]) || cols.has(k.split(":")[1])) keys.add(k);
|
|
531
|
+
}
|
|
532
|
+
linesTo(sid, /* @__PURE__ */ new Set([...s.rowData, ...rows]), true);
|
|
533
|
+
linesTo(sid, /* @__PURE__ */ new Set([...s.colData, ...cols]), false);
|
|
534
|
+
cellsTo(sid, keys);
|
|
535
|
+
if (s.marks || s.rows || s.cols) {
|
|
536
|
+
mergesTo(sid);
|
|
537
|
+
notesTo(sid);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (structural) injector.get(IUndoRedoService).clearUndoRedo(unit);
|
|
541
|
+
};
|
|
542
|
+
parts(doc).book.observeDeep(remote);
|
|
543
|
+
return () => {
|
|
544
|
+
open = false;
|
|
545
|
+
refuse.dispose();
|
|
546
|
+
local.dispose();
|
|
547
|
+
lazy.dispose();
|
|
548
|
+
parts(doc).book.unobserveDeep(remote);
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// src/sheets/SheetView.tsx
|
|
553
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
554
|
+
function SheetView({ bytes, name, kind, rights, language, theme, onChange, onSaveRequest, guard, host, together, documentId = "", onSaved }) {
|
|
555
|
+
const t = sheetTexts[language];
|
|
556
|
+
const box = useRef(null);
|
|
557
|
+
const live = useRef(null);
|
|
558
|
+
const room = useLive(together ? host : void 0, documentId, kind, bytes, void 0, language, rights.edit && !!onSaveRequest, onSaved);
|
|
559
|
+
const shared = room?.ready ? room.wire : null;
|
|
560
|
+
const waiting = !!room && !shared && !room.late && !room.denied;
|
|
561
|
+
const [phase, setPhase] = useState("loading");
|
|
562
|
+
const [attempt, setAttempt] = useState(0);
|
|
563
|
+
const [dirty, setDirty] = useState(false);
|
|
564
|
+
const [saving, setSaving] = useState("idle");
|
|
565
|
+
const [refusal, setRefusal] = useState(null);
|
|
566
|
+
const [pop, setPop] = useState(null);
|
|
567
|
+
const [look, setLook] = useState(null);
|
|
568
|
+
const edit = rights.edit && !!onSaveRequest && (!room || !!shared && !room.readonly);
|
|
569
|
+
const notes = !edit && rights.comment && !!onSaveRequest && !room;
|
|
570
|
+
useEffect(() => {
|
|
571
|
+
if (waiting) return;
|
|
572
|
+
let gone = false;
|
|
573
|
+
let stop = () => {
|
|
574
|
+
};
|
|
575
|
+
let model;
|
|
576
|
+
let moved = false;
|
|
577
|
+
const change = () => {
|
|
578
|
+
moved = true;
|
|
579
|
+
};
|
|
580
|
+
try {
|
|
581
|
+
model = shared ? extras(shared.doc, build(shared.doc)) : readSheet(bytes, kind);
|
|
582
|
+
} catch {
|
|
583
|
+
setPhase("failed");
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
shared?.doc.on("update", change);
|
|
587
|
+
setPhase("loading");
|
|
588
|
+
setDirty(false);
|
|
589
|
+
const families = new Set([model.book.defaultStyle, ...Object.values(model.book.styles)].map((s) => typeof s === "object" ? s?.ff : null).filter(Boolean));
|
|
590
|
+
const fonts = Promise.race([Promise.all([...families].flatMap((f) => ["", "bold ", "italic "].map((w) => document.fonts.load(`${w}11pt "${f}"`).catch(() => [])))), new Promise((r) => setTimeout(r, 800))]);
|
|
591
|
+
Promise.all([import("./grid-EI5JNZAA.js"), fonts]).then(([{ grid, marks }]) => {
|
|
592
|
+
if (gone) return;
|
|
593
|
+
shared?.doc.off("update", change);
|
|
594
|
+
if (shared && moved) model = extras(shared.doc, build(shared.doc));
|
|
595
|
+
if (kind === "csv") model.book.sheets.s1.name = name.replace(/\.[^.]+$/, "") || "Sheet1";
|
|
596
|
+
const host2 = box.current.appendChild(document.createElement("div"));
|
|
597
|
+
host2.className = "w100n-sheet-host";
|
|
598
|
+
const view = grid(host2, language, theme === "dark", edit);
|
|
599
|
+
const { univer, univerAPI: api2 } = view;
|
|
600
|
+
const wb = api2.createWorkbook(model.book);
|
|
601
|
+
if (model.active) wb.setActiveSheet(model.active);
|
|
602
|
+
if (!edit) wb.setEditable(false);
|
|
603
|
+
const state = { api: api2, model, original: bytes, changes: 0 };
|
|
604
|
+
const untrack = track(api2, model, { view: true, comment: notes, edit }, () => {
|
|
605
|
+
state.changes++;
|
|
606
|
+
if (state.changes === 1 && !shared) {
|
|
607
|
+
setDirty(true);
|
|
608
|
+
onChange?.(true);
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
const unbind = shared ? bind(api2, univer.__getInjector(), shared.doc, model, edit) : () => {
|
|
612
|
+
};
|
|
613
|
+
const people = shared?.link.awareness;
|
|
614
|
+
if (shared) {
|
|
615
|
+
people?.setLocalStateField("user", shared.user);
|
|
616
|
+
state.marks = marks(view);
|
|
617
|
+
}
|
|
618
|
+
let frame = 0;
|
|
619
|
+
let last = "";
|
|
620
|
+
const refresh = () => {
|
|
621
|
+
frame = 0;
|
|
622
|
+
const range2 = api2.getActiveWorkbook()?.getActiveRange();
|
|
623
|
+
if (!range2) return;
|
|
624
|
+
const s = range2.getCellStyleData() ?? {};
|
|
625
|
+
const here = { sheet: range2.getSheetId(), range: span(range2.getRange()) };
|
|
626
|
+
if (people && JSON.stringify(here) !== last) {
|
|
627
|
+
last = JSON.stringify(here);
|
|
628
|
+
people.setLocalStateField("selection", here);
|
|
629
|
+
}
|
|
630
|
+
setLook({ bl: s.bl === 1, it: s.it === 1, ul: !!s.ul?.s, st: !!s.st?.s, ht: s.ht ?? 0, tb: s.tb === 3, merged: range2.isMerged() || range2.isPartOfMerge(), n: s.n?.pattern ?? "General", cl: s.cl?.rgb ?? "", bg: s.bg?.rgb ?? "" });
|
|
631
|
+
};
|
|
632
|
+
const later = () => {
|
|
633
|
+
if (!frame) frame = requestAnimationFrame(refresh);
|
|
634
|
+
};
|
|
635
|
+
const selection = wb.onSelectionChange(later);
|
|
636
|
+
const commands = api2.addEvent(api2.Event.CommandExecuted, later);
|
|
637
|
+
live.current = state;
|
|
638
|
+
stop = () => {
|
|
639
|
+
unbind();
|
|
640
|
+
state.marks?.dispose();
|
|
641
|
+
untrack();
|
|
642
|
+
selection.dispose();
|
|
643
|
+
commands.dispose();
|
|
644
|
+
cancelAnimationFrame(frame);
|
|
645
|
+
host2.hidden = true;
|
|
646
|
+
setTimeout(() => {
|
|
647
|
+
univer.dispose();
|
|
648
|
+
host2.remove();
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
setPhase("ready");
|
|
652
|
+
}).catch(() => {
|
|
653
|
+
if (!gone) setPhase("failed");
|
|
654
|
+
});
|
|
655
|
+
return () => {
|
|
656
|
+
gone = true;
|
|
657
|
+
shared?.doc.off("update", change);
|
|
658
|
+
stop();
|
|
659
|
+
live.current = null;
|
|
660
|
+
};
|
|
661
|
+
}, [bytes, kind, attempt, shared, waiting]);
|
|
662
|
+
useEffect(() => {
|
|
663
|
+
live.current?.marks?.show((room?.people ?? []).flatMap((p) => !p.me && p.selection ? [{ ...p.selection, color: p.color }] : []));
|
|
664
|
+
}, [room?.people, phase]);
|
|
665
|
+
useEffect(() => {
|
|
666
|
+
live.current?.api.toggleDarkMode(theme === "dark");
|
|
667
|
+
}, [theme]);
|
|
668
|
+
useEffect(() => {
|
|
669
|
+
live.current?.api.setLocale(language === "pl" ? "plPL" : "enUS");
|
|
670
|
+
}, [language]);
|
|
671
|
+
const pending = room ? room.pending : dirty;
|
|
672
|
+
const unsent = room ? room.unsynced && edit : dirty;
|
|
673
|
+
useEffect(() => {
|
|
674
|
+
if (!unsent) return;
|
|
675
|
+
const stop = (e) => e.preventDefault();
|
|
676
|
+
window.addEventListener("beforeunload", stop);
|
|
677
|
+
return () => window.removeEventListener("beforeunload", stop);
|
|
678
|
+
}, [unsent]);
|
|
679
|
+
const save = async () => {
|
|
680
|
+
const l = live.current;
|
|
681
|
+
if (room) {
|
|
682
|
+
if (!l || !edit || !room.online || !room.pending || saving === "busy") return false;
|
|
683
|
+
setSaving("busy");
|
|
684
|
+
setRefusal(null);
|
|
685
|
+
await l.api.getFormula().onCalculationResultApplied(5e3).catch(() => {
|
|
686
|
+
});
|
|
687
|
+
const ok = await room.save();
|
|
688
|
+
setSaving(ok ? "done" : "failed");
|
|
689
|
+
return ok;
|
|
690
|
+
}
|
|
691
|
+
if (!l || !onSaveRequest || saving === "busy") return false;
|
|
692
|
+
setSaving("busy");
|
|
693
|
+
setRefusal(null);
|
|
694
|
+
const seen = l.changes;
|
|
695
|
+
try {
|
|
696
|
+
const model = snapshot(l.api, l.model);
|
|
697
|
+
const out = writeSheet(l.original, model, kind);
|
|
698
|
+
await onSaveRequest(out, t.editedNote);
|
|
699
|
+
const ids = kind === "csv" ? [] : worksheets(out);
|
|
700
|
+
rebase(l.model, model.lines, Object.fromEntries(model.book.sheetOrder.map((sid, i) => [sid, ids[i] ?? i + 1])));
|
|
701
|
+
l.original = out;
|
|
702
|
+
if (l.changes === seen) {
|
|
703
|
+
l.changes = 0;
|
|
704
|
+
setDirty(false);
|
|
705
|
+
onChange?.(false);
|
|
706
|
+
}
|
|
707
|
+
setSaving("done");
|
|
708
|
+
return true;
|
|
709
|
+
} catch (e) {
|
|
710
|
+
setRefusal(e instanceof SheetRefusal ? e : null);
|
|
711
|
+
setSaving("failed");
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
useEffect(() => {
|
|
716
|
+
if (!guard || room || !dirty) return;
|
|
717
|
+
guard.current = save;
|
|
718
|
+
return () => {
|
|
719
|
+
guard.current = null;
|
|
720
|
+
};
|
|
721
|
+
});
|
|
722
|
+
useRestore(pop !== null);
|
|
723
|
+
const api = () => live.current?.api;
|
|
724
|
+
const run = (id, params) => {
|
|
725
|
+
void api()?.executeCommand(id, params);
|
|
726
|
+
setPop(null);
|
|
727
|
+
};
|
|
728
|
+
const range = () => api()?.getActiveWorkbook()?.getActiveRange();
|
|
729
|
+
const sheet = () => api()?.getActiveWorkbook()?.getActiveSheet();
|
|
730
|
+
const keys = (e) => {
|
|
731
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "s") {
|
|
732
|
+
e.preventDefault();
|
|
733
|
+
e.stopPropagation();
|
|
734
|
+
if (edit || notes) void save();
|
|
735
|
+
}
|
|
736
|
+
if (e.key === "Escape" && pop) {
|
|
737
|
+
e.stopPropagation();
|
|
738
|
+
setPop(null);
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
const tool = (Icon, label, onClick, pressed) => /* @__PURE__ */ jsx("button", { type: "button", "aria-label": label, title: label, "aria-pressed": pressed, disabled: phase !== "ready", onClick, children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": true }) });
|
|
742
|
+
const gap = /* @__PURE__ */ jsx("span", { className: "w100n-sheet-gap" });
|
|
743
|
+
const anchor = (key, trigger, body) => /* @__PURE__ */ jsxs("span", { className: "w100n-sheet-anchor", children: [
|
|
744
|
+
trigger,
|
|
745
|
+
pop === key && /* @__PURE__ */ jsx("span", { className: "w100n-sheet-pop", role: "dialog", children: body })
|
|
746
|
+
] });
|
|
747
|
+
const opener = (key, Icon, label, bar) => /* @__PURE__ */ jsxs("button", { type: "button", "aria-label": label, title: label, "aria-expanded": pop === key, disabled: phase !== "ready", onClick: () => setPop(pop === key ? null : key), children: [
|
|
748
|
+
/* @__PURE__ */ jsx(Icon, { "aria-hidden": true }),
|
|
749
|
+
bar !== void 0 && /* @__PURE__ */ jsx("i", { className: "w100n-sheet-bar", style: { background: bar || "currentColor" } })
|
|
750
|
+
] });
|
|
751
|
+
const currency = language === "pl" ? '#,##0.00 "z\u0142"' : language === "uk" ? '#,##0.00 "\u20B4"' : '"$"#,##0.00';
|
|
752
|
+
const formats = [
|
|
753
|
+
[t.general, "General"],
|
|
754
|
+
[t.number, "#,##0.00"],
|
|
755
|
+
[t.percent, "0.00%"],
|
|
756
|
+
[t.currency, currency],
|
|
757
|
+
[`${t.currency} \u20AC`, '#,##0.00 "\u20AC"'],
|
|
758
|
+
[t.date, language === "en" ? "mm/dd/yyyy" : "dd.mm.yyyy"],
|
|
759
|
+
[t.time, "hh:mm"],
|
|
760
|
+
[t.text, "@"]
|
|
761
|
+
];
|
|
762
|
+
const shown = formats.find(([, p]) => p === look?.n)?.[0] ?? (look && look.n !== "General" ? look.n : t.general);
|
|
763
|
+
const border = (type) => {
|
|
764
|
+
range()?.setBorder(type, type === "none" ? 0 : 1, "#000000");
|
|
765
|
+
setPop(null);
|
|
766
|
+
};
|
|
767
|
+
const lines = (rows) => {
|
|
768
|
+
const r = range()?.getRange();
|
|
769
|
+
const ws = sheet();
|
|
770
|
+
if (!r || !ws) return;
|
|
771
|
+
if (rows) ws.deleteRows(r.startRow, r.endRow - r.startRow + 1);
|
|
772
|
+
else ws.deleteColumns(r.startColumn, r.endColumn - r.startColumn + 1);
|
|
773
|
+
};
|
|
774
|
+
const swatches = (list, pick, none, reset, current) => /* @__PURE__ */ jsxs("span", { className: "w100n-sheet-swatches", children: [
|
|
775
|
+
list.map((c, i) => /* @__PURE__ */ jsx("button", { type: "button", "aria-label": c, "aria-pressed": current.toLowerCase() === c, onClick: () => pick(c), children: /* @__PURE__ */ jsx("i", { style: { background: c } }) }, i)),
|
|
776
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "w100n-sheet-none", onClick: reset, children: none })
|
|
777
|
+
] });
|
|
778
|
+
return /* @__PURE__ */ jsxs("div", { className: "w100n-sheet", "data-theme": theme, onKeyDownCapture: keys, children: [
|
|
779
|
+
/* @__PURE__ */ jsxs("div", { className: "w100n-sheet-ribbon", role: "toolbar", "aria-label": t.tools, onKeyDown: rove, onPointerDown: (e) => {
|
|
780
|
+
if (e.target.closest("button")) e.preventDefault();
|
|
781
|
+
}, children: [
|
|
782
|
+
/* @__PURE__ */ jsxs("div", { className: "w100n-sheet-tools", children: [
|
|
783
|
+
edit && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
784
|
+
tool(Undo2, t.undo, () => void api()?.undo()),
|
|
785
|
+
tool(Redo2, t.redo, () => void api()?.redo()),
|
|
786
|
+
gap,
|
|
787
|
+
anchor(
|
|
788
|
+
"format",
|
|
789
|
+
/* @__PURE__ */ jsxs(
|
|
790
|
+
"button",
|
|
791
|
+
{
|
|
792
|
+
type: "button",
|
|
793
|
+
className: "w100n-sheet-picker",
|
|
794
|
+
"aria-label": t.format,
|
|
795
|
+
title: t.format,
|
|
796
|
+
"aria-expanded": pop === "format",
|
|
797
|
+
disabled: phase !== "ready",
|
|
798
|
+
onClick: () => setPop(pop === "format" ? null : "format"),
|
|
799
|
+
children: [
|
|
800
|
+
/* @__PURE__ */ jsx("span", { children: shown }),
|
|
801
|
+
/* @__PURE__ */ jsx(ChevronDown, { "aria-hidden": true })
|
|
802
|
+
]
|
|
803
|
+
}
|
|
804
|
+
),
|
|
805
|
+
/* @__PURE__ */ jsx("span", { className: "w100n-sheet-list", children: formats.map(([label, pattern], i) => /* @__PURE__ */ jsxs(
|
|
806
|
+
"button",
|
|
807
|
+
{
|
|
808
|
+
type: "button",
|
|
809
|
+
"aria-selected": look?.n === pattern,
|
|
810
|
+
onClick: () => {
|
|
811
|
+
range()?.setNumberFormat(pattern);
|
|
812
|
+
setPop(null);
|
|
813
|
+
},
|
|
814
|
+
children: [
|
|
815
|
+
label,
|
|
816
|
+
/* @__PURE__ */ jsx("small", { children: pattern === "General" ? "" : pattern })
|
|
817
|
+
]
|
|
818
|
+
},
|
|
819
|
+
i
|
|
820
|
+
)) })
|
|
821
|
+
),
|
|
822
|
+
gap,
|
|
823
|
+
tool(Bold, t.bold, () => run("sheet.command.set-range-bold"), look?.bl),
|
|
824
|
+
tool(Italic, t.italic, () => run("sheet.command.set-range-italic"), look?.it),
|
|
825
|
+
tool(Underline, t.underline, () => run("sheet.command.set-range-underline"), look?.ul),
|
|
826
|
+
tool(Strikethrough, t.strike, () => run("sheet.command.set-range-stroke"), look?.st),
|
|
827
|
+
anchor(
|
|
828
|
+
"text",
|
|
829
|
+
opener("text", Baseline, t.textColour, look?.cl ?? ""),
|
|
830
|
+
swatches(
|
|
831
|
+
["#0f172a", "#475569", "#dc2626", "#ea580c", "#ca8a04", "#16a34a", "#0891b2", "#2563eb", "#7c3aed", "#db2777"],
|
|
832
|
+
(c) => run("sheet.command.set-range-text-color", { value: c }),
|
|
833
|
+
t.automatic,
|
|
834
|
+
() => run("sheet.command.reset-range-text-color"),
|
|
835
|
+
look?.cl ?? ""
|
|
836
|
+
)
|
|
837
|
+
),
|
|
838
|
+
anchor(
|
|
839
|
+
"fill",
|
|
840
|
+
opener("fill", PaintBucket, t.fill, look?.bg ?? ""),
|
|
841
|
+
swatches(
|
|
842
|
+
["#fee2e2", "#ffedd5", "#fef9c3", "#dcfce7", "#cffafe", "#dbeafe", "#ede9fe", "#fce7f3", "#f1f5f9", "#cbd5e1"],
|
|
843
|
+
(c) => run("sheet.command.set-background-color", { value: c }),
|
|
844
|
+
t.noFill,
|
|
845
|
+
() => run("sheet.command.reset-background-color"),
|
|
846
|
+
look?.bg ?? ""
|
|
847
|
+
)
|
|
848
|
+
),
|
|
849
|
+
anchor(
|
|
850
|
+
"border",
|
|
851
|
+
opener("border", Grid2x2, t.borders),
|
|
852
|
+
/* @__PURE__ */ jsx("span", { className: "w100n-sheet-list", children: [[Grid2x2, t.borderAll, "all"], [Square, t.borderOuter, "outside"], [PanelBottom, t.borderBottom, "bottom"], [SquareDashed, t.borderNone, "none"]].map(([Icon, label, type]) => /* @__PURE__ */ jsxs("button", { type: "button", onClick: () => border(type), children: [
|
|
853
|
+
/* @__PURE__ */ jsx(Icon, { "aria-hidden": true }),
|
|
854
|
+
label
|
|
855
|
+
] }, type)) })
|
|
856
|
+
),
|
|
857
|
+
gap,
|
|
858
|
+
tool(TextAlignStart, t.alignLeft, () => run("sheet.command.set-horizontal-text-align", { value: 1 }), look?.ht === 1),
|
|
859
|
+
tool(TextAlignCenter, t.alignCenter, () => run("sheet.command.set-horizontal-text-align", { value: 2 }), look?.ht === 2),
|
|
860
|
+
tool(TextAlignEnd, t.alignRight, () => run("sheet.command.set-horizontal-text-align", { value: 3 }), look?.ht === 3),
|
|
861
|
+
tool(TextWrap, t.wrap, () => run("sheet.command.set-text-wrap", { value: look?.tb ? 1 : 3 }), look?.tb),
|
|
862
|
+
look?.merged ? tool(TableCellsSplit, t.unmerge, () => run("sheet.command.remove-worksheet-merge"), true) : tool(TableCellsMerge, t.merge, () => run("sheet.command.add-worksheet-merge-all")),
|
|
863
|
+
gap,
|
|
864
|
+
tool(BetweenHorizontalStart, t.rowAbove, () => run("sheet.command.insert-row-before")),
|
|
865
|
+
tool(BetweenHorizontalEnd, t.rowBelow, () => run("sheet.command.insert-row-after")),
|
|
866
|
+
tool(BetweenVerticalStart, t.columnLeft, () => run("sheet.command.insert-col-before")),
|
|
867
|
+
tool(BetweenVerticalEnd, t.columnRight, () => run("sheet.command.insert-col-after")),
|
|
868
|
+
tool(TableRowsSplit, t.deleteRows, () => lines(true)),
|
|
869
|
+
tool(TableColumnsSplit, t.deleteColumns, () => lines(false)),
|
|
870
|
+
anchor(
|
|
871
|
+
"freeze",
|
|
872
|
+
opener("freeze", Snowflake, t.freeze),
|
|
873
|
+
/* @__PURE__ */ jsxs("span", { className: "w100n-sheet-list", children: [
|
|
874
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
|
|
875
|
+
sheet()?.setFrozenRows(1);
|
|
876
|
+
setPop(null);
|
|
877
|
+
}, children: t.freezeRow }),
|
|
878
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
|
|
879
|
+
sheet()?.setFrozenColumns(1);
|
|
880
|
+
setPop(null);
|
|
881
|
+
}, children: t.freezeColumn }),
|
|
882
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => run("sheet.command.set-selection-frozen"), children: t.freezeHere }),
|
|
883
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
|
|
884
|
+
sheet()?.cancelFreeze();
|
|
885
|
+
setPop(null);
|
|
886
|
+
}, children: t.freezeNone })
|
|
887
|
+
] })
|
|
888
|
+
),
|
|
889
|
+
gap,
|
|
890
|
+
tool(ArrowDownAZ, t.sortUp, () => run("sheet.command.sort-range-asc")),
|
|
891
|
+
tool(ArrowDownZA, t.sortDown, () => run("sheet.command.sort-range-desc")),
|
|
892
|
+
!room && tool(Funnel, t.filter, () => run("sheet.command.smart-toggle-filter")),
|
|
893
|
+
gap
|
|
894
|
+
] }),
|
|
895
|
+
(edit || notes) && tool(StickyNote, t.note, () => run("sheet.operation.add-note-popup")),
|
|
896
|
+
tool(Search, t.find, () => run("ui.operation.open-find-dialog"))
|
|
897
|
+
] }),
|
|
898
|
+
/* @__PURE__ */ jsxs("span", { className: "w100n-sheet-end", children: [
|
|
899
|
+
room && (room.ready ? !room.online : room.late || room.denied) && /* @__PURE__ */ jsxs("span", { className: "w100n-text-live", title: room.denied ? void 0 : t.offlineHint, children: [
|
|
900
|
+
/* @__PURE__ */ jsx(WifiOff, { "aria-hidden": true }),
|
|
901
|
+
room.denied ? t.liveOff : t.offline
|
|
902
|
+
] }),
|
|
903
|
+
room && room.people.length > 0 && /* @__PURE__ */ jsx("span", { className: "w100n-text-people", role: "group", "aria-label": t.people, children: room.people.map((p) => /* @__PURE__ */ jsx("span", { className: "w100n-text-face", title: p.me ? `${p.name} (${t.you})` : p.name, style: { "--face": p.color }, children: p.avatarUrl ? /* @__PURE__ */ jsx("img", { src: p.avatarUrl, alt: "" }) : p.name.slice(0, 1).toUpperCase() }, p.id)) }),
|
|
904
|
+
!edit && /* @__PURE__ */ jsx("span", { className: "w100n-docs-badge", children: notes ? t.notesOnly : t.viewOnly }),
|
|
905
|
+
saving === "failed" && /* @__PURE__ */ jsx("span", { className: "w100n-sheet-muted", role: "alert", children: refusal ? t.refused[refusal.code].replace("{sheet}", refusal.sheet) : t.saveFailed }),
|
|
906
|
+
(edit || notes) && /* @__PURE__ */ jsxs("button", { type: "button", className: "w100n-docs-action", disabled: !pending || saving === "busy" || phase !== "ready" || !!room && !room.online, onClick: () => void save(), children: [
|
|
907
|
+
/* @__PURE__ */ jsx(Save, { "aria-hidden": true }),
|
|
908
|
+
saving === "busy" ? t.saving : !pending && saving === "done" ? t.saved : t.save
|
|
909
|
+
] })
|
|
910
|
+
] })
|
|
911
|
+
] }),
|
|
912
|
+
/* @__PURE__ */ jsxs("div", { className: "w100n-sheet-stage", onPointerDown: () => setPop(null), children: [
|
|
913
|
+
/* @__PURE__ */ jsx("div", { ref: box, className: "w100n-sheet-grid" }),
|
|
914
|
+
phase !== "ready" && /* @__PURE__ */ jsx("div", { className: "w100n-sheet-cover", children: phase === "loading" ? /* @__PURE__ */ jsx("span", { children: t.loading }) : /* @__PURE__ */ jsxs("span", { children: [
|
|
915
|
+
t.failed,
|
|
916
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "w100n-docs-action", onClick: () => setAttempt((n) => n + 1), children: t.retry })
|
|
917
|
+
] }) })
|
|
918
|
+
] })
|
|
919
|
+
] });
|
|
920
|
+
}
|
|
921
|
+
var SheetView_default = SheetView;
|
|
922
|
+
export {
|
|
923
|
+
SheetView,
|
|
924
|
+
SheetView_default as default,
|
|
925
|
+
readSheet,
|
|
926
|
+
writeSheet
|
|
927
|
+
};
|
|
928
|
+
//# sourceMappingURL=SheetView-JYH2ZUZF.js.map
|