@a3s-lab/office 0.12.0 → 0.13.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/README.md +99 -6
- package/dist/0~1403.js +20 -12
- package/dist/0~2805.js +241 -241
- package/dist/0~4980.js +1 -1
- package/dist/0~5050.js +1 -20
- package/dist/0~5093.js +547 -547
- package/dist/0~7048.js +31 -29
- package/dist/0~document-editor.js +694 -90
- package/dist/0~pdf-viewer.js +41 -10
- package/dist/0~presentation-editor.js +8 -6
- package/dist/0~spreadsheet-editor.js +11528 -10094
- package/dist/0~work-document-import-worker-client.js +237 -0
- package/dist/0~work-docx-export.js +1 -1
- package/dist/0~work-docx-import.js +1 -1
- package/dist/0~work-docx-large-document-import.js +559 -0
- package/dist/0~work-office-diagnostics.js +46 -32
- package/dist/4104.js +4092 -3210
- package/dist/432.js +51 -7
- package/dist/4476.js +201 -7
- package/dist/5184.js +24 -2
- package/dist/{8928.js → 6282.js} +2338 -93
- package/dist/8715.js +895 -888
- package/dist/9356.js +3 -1
- package/dist/core.js +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/features/work/editors/document-editor-support.d.ts +1 -9
- package/dist/internal/features/work/editors/document-external-content.d.ts +1 -1
- package/dist/internal/features/work/editors/presentation-slide-canvas.d.ts +3 -1
- package/dist/internal/features/work/editors/presentation-slide-thumbnail.d.ts +3 -2
- package/dist/internal/features/work/editors/presentation-thumbnail-rail.d.ts +2 -1
- package/dist/internal/features/work/editors/presentation-workspace.d.ts +2 -1
- package/dist/internal/features/work/editors/spreadsheet-border-ribbon.d.ts +5 -0
- package/dist/internal/features/work/editors/spreadsheet-calculation-projection.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-border-command.d.ts +3 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-border.d.ts +14 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-fill-command.d.ts +3 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-fill.d.ts +12 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-range.d.ts +14 -0
- package/dist/internal/features/work/editors/spreadsheet-command-catalog.d.ts +159 -0
- package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +8 -4
- package/dist/internal/features/work/editors/spreadsheet-editor-support.d.ts +8 -2
- package/dist/internal/features/work/editors/spreadsheet-home-format-ribbon.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-in-place-workbook-sync.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-operation-projection.d.ts +14 -0
- package/dist/internal/features/work/editors/spreadsheet-structure-selection.d.ts +7 -0
- package/dist/internal/features/work/editors/use-document-pagination.d.ts +5 -0
- package/dist/internal/features/work/editors/use-presentation-design-commands.d.ts +2 -1
- package/dist/internal/features/work/editors/use-spreadsheet-workbook-sync.d.ts +2 -1
- package/dist/internal/features/work/spreadsheet-history-value.d.ts +1 -0
- package/dist/internal/features/work/spreadsheet-sparse.d.ts +6 -1
- package/dist/internal/features/work/work-document-chunk-geometry.d.ts +28 -0
- package/dist/internal/features/work/work-document-chunk-node.d.ts +23 -0
- package/dist/internal/features/work/work-document-extensions.d.ts +1 -0
- package/dist/internal/features/work/work-document-html-fingerprint.d.ts +15 -0
- package/dist/internal/features/work/work-document-import-worker-client.d.ts +13 -0
- package/dist/internal/features/work/work-document-import-worker-protocol.d.ts +36 -0
- package/dist/internal/features/work/work-document-import.worker.d.ts +1 -0
- package/dist/internal/features/work/work-document-incremental-layout.d.ts +1 -1
- package/dist/internal/features/work/work-document-integrity-index.d.ts +14 -0
- package/dist/internal/features/work/work-document-lazy-block.d.ts +3 -0
- package/dist/internal/features/work/work-document-lazy-html.d.ts +21 -0
- package/dist/internal/features/work/work-document-lazy-model.d.ts +29 -0
- package/dist/internal/features/work/work-document-lazy-pagination-measurement.d.ts +3 -0
- package/dist/internal/features/work/work-document-lazy-preview.d.ts +21 -0
- package/dist/internal/features/work/work-document-lazy-update.d.ts +14 -0
- package/dist/internal/features/work/work-document-model.d.ts +18 -2
- package/dist/internal/features/work/work-document-page-surface-registry.d.ts +16 -0
- package/dist/internal/features/work/work-document-pagination-dom.d.ts +1 -0
- package/dist/internal/features/work/work-document-pagination-types.d.ts +1 -0
- package/dist/internal/features/work/work-document-pagination.d.ts +1 -1
- package/dist/internal/features/work/work-document-text-statistics.d.ts +25 -0
- package/dist/internal/features/work/work-document-windowing.d.ts +23 -0
- package/dist/internal/features/work/work-docx-large-document-import.d.ts +35 -0
- package/dist/internal/features/work/work-docx-large-document-parser.d.ts +29 -0
- package/dist/internal/features/work/work-file-import.d.ts +5 -0
- package/dist/internal/features/work/work-file-io.d.ts +3 -3
- package/dist/internal/features/work/work-file-kind.d.ts +5 -0
- package/dist/internal/features/work/work-office-diagnostics.d.ts +10 -1
- package/dist/internal/features/work/work-ooxml-package.d.ts +8 -0
- package/dist/internal/features/work/work-presentation-layouts.d.ts +7 -1
- package/dist/internal/features/work/work-repository.d.ts +1 -0
- package/dist/internal/features/work/work-spreadsheet-compatibility-summary.d.ts +10 -0
- package/dist/internal/features/work/work-spreadsheet-file-export.d.ts +2 -0
- package/dist/internal/features/work/work-spreadsheet-file-import.d.ts +3 -0
- package/dist/internal/features/work/work-spreadsheet-import-diagnostics.d.ts +2 -0
- package/dist/internal/features/work/work-spreadsheet-import-worker-client.d.ts +6 -0
- package/dist/internal/features/work/work-spreadsheet-import-worker-protocol.d.ts +32 -0
- package/dist/internal/features/work/work-spreadsheet-import.worker.d.ts +1 -0
- package/dist/internal/features/work/work-spreadsheet-matrix-profile.d.ts +64 -0
- package/dist/internal/features/work/work-spreadsheet-package-scan-worker-client.d.ts +6 -0
- package/dist/internal/features/work/work-spreadsheet-package-scan-worker-protocol.d.ts +49 -0
- package/dist/internal/features/work/work-spreadsheet-package-scan.worker.d.ts +1 -0
- package/dist/internal/features/work/work-xlsx-formula-diagnostics.d.ts +3 -1
- package/dist/internal/features/work/work-xlsx-formulas.d.ts +2 -1
- package/dist/internal/features/work/work-xlsx-interop.d.ts +6 -5
- package/dist/internal/features/work/work-xlsx-pivot-diagnostics.d.ts +2 -1
- package/dist/internal/features/work/work-xlsx-plain-fast-path.d.ts +54 -0
- package/dist/internal/features/work/work-xlsx-style-gate.d.ts +1 -0
- package/dist/internal/features/work/work-xlsx-worksheet-scan.d.ts +12 -0
- package/dist/internal/features/work/work-xlsx-worksheet.d.ts +12 -0
- package/dist/office-kernel.wasm +0 -0
- package/dist/office-kernel.worker.js +31 -29
- package/dist/react.d.ts +7 -1
- package/dist/styles.css +440 -3
- package/dist/work-document-import.worker.js +558 -0
- package/dist/work-spreadsheet-import.worker.js +24745 -0
- package/dist/work-spreadsheet-import.worker.js.LICENSE.txt +3 -0
- package/dist/work-spreadsheet-package-scan.worker.js +4157 -0
- package/dist/work-spreadsheet-package-scan.worker.js.LICENSE.txt +11 -0
- package/docs/latest/en/browser-editor-architecture.md +351 -15
- package/package.json +19 -1
package/dist/432.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useRef } from "react";
|
|
3
|
-
import { LoaderCircle } from "lucide-react";
|
|
4
3
|
import { OfficeCollaborationError as WorkOfficeCollaborationError } from "./9787.js";
|
|
5
4
|
function StateView({ icon, title, description, descriptionTitle, actions, children, tone = 'neutral', size = 'standard', role, className = '' }) {
|
|
6
5
|
return /*#__PURE__*/ jsxs("div", {
|
|
@@ -34,13 +33,36 @@ function WorkEditorLoadingState({ title }) {
|
|
|
34
33
|
className: "work-editor-loading",
|
|
35
34
|
size: "compact",
|
|
36
35
|
role: "status",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
size: 20
|
|
40
|
-
}),
|
|
36
|
+
tone: "info",
|
|
37
|
+
icon: /*#__PURE__*/ jsx(EditorLoadingVisual, {}),
|
|
41
38
|
title: title
|
|
42
39
|
});
|
|
43
40
|
}
|
|
41
|
+
function EditorLoadingVisual() {
|
|
42
|
+
return /*#__PURE__*/ jsxs("span", {
|
|
43
|
+
className: "work-editor-loading-visual",
|
|
44
|
+
"aria-hidden": "true",
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ jsx("span", {
|
|
47
|
+
className: "work-editor-loading-focus"
|
|
48
|
+
}),
|
|
49
|
+
/*#__PURE__*/ jsxs("span", {
|
|
50
|
+
className: "work-editor-loading-page",
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ jsx("span", {
|
|
53
|
+
className: "work-editor-loading-line work-editor-loading-line--accent"
|
|
54
|
+
}),
|
|
55
|
+
/*#__PURE__*/ jsx("span", {
|
|
56
|
+
className: "work-editor-loading-line"
|
|
57
|
+
}),
|
|
58
|
+
/*#__PURE__*/ jsx("span", {
|
|
59
|
+
className: "work-editor-loading-line work-editor-loading-line--short"
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
44
66
|
const OfficeCollaborationPresenceContext = /*#__PURE__*/ createContext(null);
|
|
45
67
|
function OfficeCollaborationPresenceProvider({ children, presence }) {
|
|
46
68
|
const navigatorRef = useRef(null);
|
|
@@ -218,8 +240,30 @@ const officeEditorLoaders = {
|
|
|
218
240
|
presentation: loadPresentationEditor,
|
|
219
241
|
pdf: loadPdfViewer
|
|
220
242
|
};
|
|
221
|
-
|
|
222
|
-
|
|
243
|
+
const officeRuntimeAssetPreloads = new Map();
|
|
244
|
+
async function preloadOfficeEditor(kind, options = {}) {
|
|
245
|
+
const editor = officeEditorLoaders[kind]();
|
|
246
|
+
if ('pdf' !== kind || true !== options.preloadRuntimeAssets) return void await editor;
|
|
247
|
+
await Promise.all([
|
|
248
|
+
editor,
|
|
249
|
+
preloadOfficeRuntimeAsset(options.pdfWasmUrl ?? defaultPdfiumWasmUrl)
|
|
250
|
+
]);
|
|
251
|
+
}
|
|
252
|
+
async function preloadOfficeRuntimeAsset(url) {
|
|
253
|
+
if ("u" < typeof document || 'function' != typeof fetch) return;
|
|
254
|
+
const cached = officeRuntimeAssetPreloads.get(url);
|
|
255
|
+
if (cached) return cached;
|
|
256
|
+
const preload = Promise.resolve().then(()=>fetch(url, {
|
|
257
|
+
cache: 'force-cache',
|
|
258
|
+
credentials: 'same-origin'
|
|
259
|
+
})).then(async (response)=>{
|
|
260
|
+
if (!response.ok) throw new Error(`Unable to preload the Office runtime asset: ${url}`);
|
|
261
|
+
await response.arrayBuffer();
|
|
262
|
+
}).catch(()=>{
|
|
263
|
+
officeRuntimeAssetPreloads.delete(url);
|
|
264
|
+
});
|
|
265
|
+
officeRuntimeAssetPreloads.set(url, preload);
|
|
266
|
+
await preload;
|
|
223
267
|
}
|
|
224
268
|
const defaultPdfiumWasmUrl = new URL('./pdfium.wasm', import.meta.url).href;
|
|
225
269
|
const defaultOfficeKernelWasmUrl = new URL('./office-kernel.wasm', import.meta.url).href;
|
package/dist/4476.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { initializeWorkOfficeCollaborationMetadata, assertWorkOfficeCollaborationEditable, OfficeCollaborationError as WorkOfficeCollaborationError, readOfficeCollaborationMetadata as readWorkOfficeCollaborationMetadata, registerWorkOfficeCollaborationInitializer, markWorkOfficeCollaborationInitialized, assertWorkOfficeCollaborationOrigin } from "./9787.js";
|
|
2
2
|
import { OFFICE_KERNEL_SPREADSHEET_MAX_ROWS } from "./5184.js";
|
|
3
3
|
import { workOfficeCollaborationJsonEqual, canonicalWorkOfficeCollaborationJson, isWorkOfficeCollaborationRecord, cloneWorkOfficeCollaborationJson } from "./4650.js";
|
|
4
|
-
import { sparseMatrixColumnCount, sparseArrayEntries as spreadsheet_sparse_sparseArrayEntries,
|
|
4
|
+
import { sparseMatrixColumnCount, cloneSparseMatrix, sparseArrayEntries as spreadsheet_sparse_sparseArrayEntries, sparseArrayIndexes, formatSpreadsheetCellRanges, parseSpreadsheetCellRanges as work_spreadsheet_ranges_parseSpreadsheetCellRanges } from "./8715.js";
|
|
5
5
|
import { patchWorkOfficeCollaborationFlatJsonMap, readWorkOfficeCollaborationFlatJsonMap } from "./7060.js";
|
|
6
6
|
import * as __rspack_external_yjs from "yjs";
|
|
7
7
|
const MAX_POPULATED_CELLS = 1000000;
|
|
@@ -1284,6 +1284,195 @@ function assertInitializedSpreadsheetSession(session) {
|
|
|
1284
1284
|
if (metadata?.initialized) return;
|
|
1285
1285
|
throw new WorkOfficeCollaborationError('office.collaboration.not_initialized', 'The Spreadsheet collaboration session has not been initialized.');
|
|
1286
1286
|
}
|
|
1287
|
+
const spreadsheetFormulaHistoryIgnoredKeys = new Set([
|
|
1288
|
+
'ct',
|
|
1289
|
+
'm',
|
|
1290
|
+
'v'
|
|
1291
|
+
]);
|
|
1292
|
+
function sameSpreadsheetHistoryValue(left, right) {
|
|
1293
|
+
if (left === right) return true;
|
|
1294
|
+
if (null === left || null === right || typeof left !== typeof right) return false;
|
|
1295
|
+
const leftFormulaCell = spreadsheetFormulaCell(left);
|
|
1296
|
+
const rightFormulaCell = spreadsheetFormulaCell(right);
|
|
1297
|
+
if (leftFormulaCell || rightFormulaCell) return Boolean(leftFormulaCell && rightFormulaCell && sameSpreadsheetFormulaHistoryCell(leftFormulaCell, rightFormulaCell));
|
|
1298
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
1299
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
1300
|
+
const leftKeys = Object.keys(left).filter((key)=>void 0 !== left[Number(key)]);
|
|
1301
|
+
const rightKeys = Object.keys(right).filter((key)=>void 0 !== right[Number(key)]);
|
|
1302
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key)=>Object.hasOwn(right, key) && sameSpreadsheetHistoryValue(left[Number(key)], right[Number(key)]));
|
|
1303
|
+
}
|
|
1304
|
+
if ('object' != typeof left || 'object' != typeof right) return false;
|
|
1305
|
+
const leftRecord = left;
|
|
1306
|
+
const rightRecord = right;
|
|
1307
|
+
const leftKeys = Object.keys(leftRecord).filter((key)=>void 0 !== leftRecord[key]);
|
|
1308
|
+
const rightKeys = Object.keys(rightRecord).filter((key)=>void 0 !== rightRecord[key]);
|
|
1309
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key)=>sameSpreadsheetHistoryValue(leftRecord[key], rightRecord[key]));
|
|
1310
|
+
}
|
|
1311
|
+
function spreadsheetFormulaCell(value) {
|
|
1312
|
+
return value && 'object' == typeof value && 'string' == typeof value.f ? value : null;
|
|
1313
|
+
}
|
|
1314
|
+
function sameSpreadsheetFormulaHistoryCell(left, right) {
|
|
1315
|
+
const leftRecord = left;
|
|
1316
|
+
const rightRecord = right;
|
|
1317
|
+
const leftKeys = Object.keys(leftRecord).filter((key)=>!spreadsheetFormulaHistoryIgnoredKeys.has(key) && void 0 !== leftRecord[key]);
|
|
1318
|
+
const rightKeys = Object.keys(rightRecord).filter((key)=>!spreadsheetFormulaHistoryIgnoredKeys.has(key) && void 0 !== rightRecord[key]);
|
|
1319
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key)=>sameSpreadsheetHistoryValue(leftRecord[key], rightRecord[key])) && sameSpreadsheetHistoryValue(spreadsheetFormulaHistoryCellType(left.ct), spreadsheetFormulaHistoryCellType(right.ct));
|
|
1320
|
+
}
|
|
1321
|
+
function spreadsheetFormulaHistoryCellType(cellType) {
|
|
1322
|
+
if (!cellType) return;
|
|
1323
|
+
const { fa, t: _type, ...retainedCellType } = cellType;
|
|
1324
|
+
const normalized = {
|
|
1325
|
+
...retainedCellType,
|
|
1326
|
+
...fa && 'General' !== fa ? {
|
|
1327
|
+
fa
|
|
1328
|
+
} : {}
|
|
1329
|
+
};
|
|
1330
|
+
return Object.keys(normalized).length ? normalized : void 0;
|
|
1331
|
+
}
|
|
1332
|
+
const SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY = '__a3sShownCommentCells';
|
|
1333
|
+
const spreadsheetMatrixProfiles = new WeakMap();
|
|
1334
|
+
function freezeImportedSpreadsheetCell(cell) {
|
|
1335
|
+
freezeObject(cell.mc);
|
|
1336
|
+
freezeObject(cell.ct?.s);
|
|
1337
|
+
freezeObject(cell.ct);
|
|
1338
|
+
freezeObject(cell.ps);
|
|
1339
|
+
freezeObject(cell.hl);
|
|
1340
|
+
freezeObject(cell.spl);
|
|
1341
|
+
return Object.freeze(cell);
|
|
1342
|
+
}
|
|
1343
|
+
function registerImportedSpreadsheetMatrix(data, options) {
|
|
1344
|
+
data.length = Math.max(data.length, options.rowCount);
|
|
1345
|
+
data[0] ??= [];
|
|
1346
|
+
for (const rowIndex of sparseArrayIndexes(data)){
|
|
1347
|
+
const row = data[rowIndex];
|
|
1348
|
+
if (row) {
|
|
1349
|
+
row.length = Math.max(row.length, options.columnCount);
|
|
1350
|
+
Object.freeze(row);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
registerSpreadsheetMatrixProfile(data, options);
|
|
1354
|
+
}
|
|
1355
|
+
function registerDerivedSpreadsheetMatrix(data, source, changes) {
|
|
1356
|
+
const sourceProfile = spreadsheetMatrixProfiles.get(source);
|
|
1357
|
+
if (!sourceProfile?.fortuneReady) return false;
|
|
1358
|
+
const formulaCells = new Map(sourceProfile.formulaCells.map(({ column, row })=>[
|
|
1359
|
+
spreadsheetCoordinateKey(row, column),
|
|
1360
|
+
{
|
|
1361
|
+
column,
|
|
1362
|
+
row
|
|
1363
|
+
}
|
|
1364
|
+
]));
|
|
1365
|
+
const shownCommentCells = new Map(sourceProfile.shownCommentCells.map(({ c, r })=>[
|
|
1366
|
+
spreadsheetCoordinateKey(r, c),
|
|
1367
|
+
{
|
|
1368
|
+
c,
|
|
1369
|
+
r
|
|
1370
|
+
}
|
|
1371
|
+
]));
|
|
1372
|
+
let populatedCellCount = sourceProfile.populatedCellCount;
|
|
1373
|
+
let protectionCellKey = sourceProfile.protectionCellKey;
|
|
1374
|
+
let protectionCells;
|
|
1375
|
+
for (const { column, current, previous, row } of changes){
|
|
1376
|
+
const coordinateKey = spreadsheetCoordinateKey(row, column);
|
|
1377
|
+
if (null == previous && null != current) populatedCellCount += 1;
|
|
1378
|
+
if (null != previous && null == current) populatedCellCount -= 1;
|
|
1379
|
+
if (current?.f) formulaCells.set(coordinateKey, {
|
|
1380
|
+
column,
|
|
1381
|
+
row
|
|
1382
|
+
});
|
|
1383
|
+
else formulaCells.delete(coordinateKey);
|
|
1384
|
+
if (current?.ps?.isShow) shownCommentCells.set(coordinateKey, {
|
|
1385
|
+
c: column,
|
|
1386
|
+
r: row
|
|
1387
|
+
});
|
|
1388
|
+
else shownCommentCells.delete(coordinateKey);
|
|
1389
|
+
if (spreadsheetProtectionSignature(previous) !== spreadsheetProtectionSignature(current)) {
|
|
1390
|
+
protectionCells ??= spreadsheetProtectionCells(protectionCellKey);
|
|
1391
|
+
const signature = spreadsheetProtectionSignature(current);
|
|
1392
|
+
if (null === signature) protectionCells.delete(coordinateKey);
|
|
1393
|
+
else protectionCells.set(coordinateKey, signature);
|
|
1394
|
+
}
|
|
1395
|
+
const changedRow = data[row];
|
|
1396
|
+
if (changedRow && !Object.isFrozen(changedRow)) Object.freeze(changedRow);
|
|
1397
|
+
}
|
|
1398
|
+
if (protectionCells) protectionCellKey = Array.from(protectionCells, ([coordinate, value])=>({
|
|
1399
|
+
coordinate,
|
|
1400
|
+
value
|
|
1401
|
+
})).sort((left, right)=>compareSpreadsheetCoordinates(left.coordinate, right.coordinate)).map(({ coordinate, value })=>`${coordinate}:${value}`).join(',');
|
|
1402
|
+
registerSpreadsheetMatrixProfile(data, {
|
|
1403
|
+
columnCount: Math.max(sourceProfile.columnCount, ...changes.map(({ column, row })=>Math.max(column + 1, data[row]?.length ?? 0))),
|
|
1404
|
+
formulaCells: Array.from(formulaCells.values()).sort(compareSpreadsheetCells),
|
|
1405
|
+
fortuneReady: true,
|
|
1406
|
+
populatedCellCount: Math.max(0, populatedCellCount),
|
|
1407
|
+
protectionCellKey,
|
|
1408
|
+
rowCount: Math.max(sourceProfile.rowCount, data.length, ...changes.map(({ row })=>row + 1)),
|
|
1409
|
+
shownCommentCells: Array.from(shownCommentCells.values()).sort((left, right)=>left.r - right.r || left.c - right.c)
|
|
1410
|
+
}, {
|
|
1411
|
+
historyRoot: sourceProfile.historyRoot,
|
|
1412
|
+
historyState: changes.some(({ current, previous })=>!sameSpreadsheetHistoryValue(current, previous)) ? Object.freeze({}) : sourceProfile.historyState
|
|
1413
|
+
});
|
|
1414
|
+
return true;
|
|
1415
|
+
}
|
|
1416
|
+
function spreadsheetMatrixProfile(data) {
|
|
1417
|
+
return data ? spreadsheetMatrixProfiles.get(data) : void 0;
|
|
1418
|
+
}
|
|
1419
|
+
function attachSpreadsheetShownCommentCells(data, cells) {
|
|
1420
|
+
Object.defineProperty(data, SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY, {
|
|
1421
|
+
configurable: false,
|
|
1422
|
+
enumerable: false,
|
|
1423
|
+
value: cells,
|
|
1424
|
+
writable: false
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
function registerSpreadsheetMatrixProfile(data, options, history) {
|
|
1428
|
+
const initialHistoryState = Object.freeze({});
|
|
1429
|
+
const profile = Object.freeze({
|
|
1430
|
+
columnCount: options.columnCount,
|
|
1431
|
+
formulaCells: Object.freeze(options.formulaCells.map((cell)=>Object.freeze({
|
|
1432
|
+
...cell
|
|
1433
|
+
}))),
|
|
1434
|
+
fortuneReady: options.fortuneReady,
|
|
1435
|
+
historyRoot: history?.historyRoot ?? initialHistoryState,
|
|
1436
|
+
historyState: history?.historyState ?? initialHistoryState,
|
|
1437
|
+
populatedCellCount: options.populatedCellCount,
|
|
1438
|
+
protectionCellKey: options.protectionCellKey,
|
|
1439
|
+
rowCount: options.rowCount,
|
|
1440
|
+
shownCommentCells: Object.freeze(options.shownCommentCells.map((cell)=>Object.freeze({
|
|
1441
|
+
...cell
|
|
1442
|
+
})))
|
|
1443
|
+
});
|
|
1444
|
+
attachSpreadsheetShownCommentCells(data, profile.shownCommentCells);
|
|
1445
|
+
Object.freeze(data);
|
|
1446
|
+
spreadsheetMatrixProfiles.set(data, profile);
|
|
1447
|
+
}
|
|
1448
|
+
function spreadsheetProtectionCells(value) {
|
|
1449
|
+
const cells = new Map();
|
|
1450
|
+
for (const entry of value.split(',')){
|
|
1451
|
+
if (!entry) continue;
|
|
1452
|
+
const separator = entry.indexOf(':');
|
|
1453
|
+
if (!(separator <= 0)) cells.set(entry.slice(0, separator), entry.slice(separator + 1));
|
|
1454
|
+
}
|
|
1455
|
+
return cells;
|
|
1456
|
+
}
|
|
1457
|
+
function spreadsheetProtectionSignature(cell) {
|
|
1458
|
+
const hidden = cell?.hi;
|
|
1459
|
+
if (cell?.lo === void 0 && void 0 === hidden) return null;
|
|
1460
|
+
return `${cell?.lo ?? ''}:${hidden ?? ''}`;
|
|
1461
|
+
}
|
|
1462
|
+
function spreadsheetCoordinateKey(row, column) {
|
|
1463
|
+
return `${row}_${column}`;
|
|
1464
|
+
}
|
|
1465
|
+
function compareSpreadsheetCoordinates(left, right) {
|
|
1466
|
+
const [leftRow = 0, leftColumn = 0] = left.split('_').map(Number);
|
|
1467
|
+
const [rightRow = 0, rightColumn = 0] = right.split('_').map(Number);
|
|
1468
|
+
return leftRow - rightRow || leftColumn - rightColumn;
|
|
1469
|
+
}
|
|
1470
|
+
function compareSpreadsheetCells(left, right) {
|
|
1471
|
+
return left.row - right.row || left.column - right.column;
|
|
1472
|
+
}
|
|
1473
|
+
function freezeObject(value) {
|
|
1474
|
+
if (value && 'object' == typeof value) Object.freeze(value);
|
|
1475
|
+
}
|
|
1287
1476
|
const DEFAULT_PROTECTION_HINT = '此工作表已受保护。若要更改锁定的单元格,请先取消工作表保护。';
|
|
1288
1477
|
function defaultSheetProtectionAuthority(enabled = false) {
|
|
1289
1478
|
return {
|
|
@@ -1443,12 +1632,17 @@ function unlockedCellCount(sheet) {
|
|
|
1443
1632
|
function spreadsheetProtectionKey(sheets) {
|
|
1444
1633
|
return sheets.map((sheet)=>{
|
|
1445
1634
|
const authority = sheetProtectionAuthority(sheet);
|
|
1446
|
-
const
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1635
|
+
const profile = spreadsheetMatrixProfile(sheet.data);
|
|
1636
|
+
let protectionCellKey = profile?.protectionCellKey;
|
|
1637
|
+
if (void 0 === protectionCellKey) {
|
|
1638
|
+
const cells = [];
|
|
1639
|
+
for (const [row, values] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [column, cell] of spreadsheet_sparse_sparseArrayEntries(values)){
|
|
1640
|
+
const hidden = cell?.hi;
|
|
1641
|
+
if (cell?.lo !== void 0 || void 0 !== hidden) cells.push(`${row}_${column}:${cell?.lo ?? ''}:${hidden ?? ''}`);
|
|
1642
|
+
}
|
|
1643
|
+
protectionCellKey = cells.join(',');
|
|
1450
1644
|
}
|
|
1451
|
-
return `${sheet.id ?? sheet.name}:${JSON.stringify(authority)}:${
|
|
1645
|
+
return `${sheet.id ?? sheet.name}:${JSON.stringify(authority)}:${protectionCellKey}`;
|
|
1452
1646
|
}).join('|');
|
|
1453
1647
|
}
|
|
1454
1648
|
function editableRangeCellCount(ranges) {
|
|
@@ -2022,4 +2216,4 @@ function boundedInteger(value, minimum, maximum, fallback) {
|
|
|
2022
2216
|
function boundedNumber(value, minimum, maximum, fallback) {
|
|
2023
2217
|
return 'number' == typeof value && Number.isFinite(value) && value >= minimum && value <= maximum ? value : fallback;
|
|
2024
2218
|
}
|
|
2025
|
-
export { DEFAULT_PROTECTION_HINT, SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS, SPREADSHEET_CONDITIONAL_ICON_SETS, createWorkOfficeSpreadsheetCollaborationBinding as createOfficeSpreadsheetCollaborationBinding, defaultSpreadsheetColorScaleThresholds, defaultSpreadsheetConditionalIconThresholds, defaultSpreadsheetDataBarOptions, drawSpreadsheetConditionalIcon, editableRangeCellCount, editableRangeRequiresCredentials, effectiveSpreadsheetPageSetup, importedSheetProtectionAuthority, initializeWorkOfficeSpreadsheetCollaboration as initializeOfficeSpreadsheetCollaboration, isSpreadsheetConditionalComparisonOperator, isSpreadsheetConditionalIconSetName, normalizeSheetProtectionAuthority, normalizeSpreadsheetConditionalIconSetFormat, normalizeSpreadsheetConditionalVisualOptions, normalizeSpreadsheetPaperSize, protectedSheetCount, readWorkOfficeSpreadsheetCollaboration as readOfficeSpreadsheetCollaboration, replaceWorkOfficeSpreadsheetCollaboration as replaceOfficeSpreadsheetCollaboration, sheetHasProtectionState, sheetProtectionAuthority, spreadsheetConditionalComparisonNeedsUpperValue, spreadsheetConditionalIconForValue, spreadsheetConditionalIconSetCount, spreadsheetConditionalThresholdValue, spreadsheetConditionalThresholdsEqual, spreadsheetProtectionKey, unlockedCellCount, withEditableRange, withSheetProtection, withSheetSelectionPermissions, withoutEditableRange };
|
|
2219
|
+
export { DEFAULT_PROTECTION_HINT, SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS, SPREADSHEET_CONDITIONAL_ICON_SETS, attachSpreadsheetShownCommentCells, createWorkOfficeSpreadsheetCollaborationBinding as createOfficeSpreadsheetCollaborationBinding, defaultSpreadsheetColorScaleThresholds, defaultSpreadsheetConditionalIconThresholds, defaultSpreadsheetDataBarOptions, drawSpreadsheetConditionalIcon, editableRangeCellCount, editableRangeRequiresCredentials, effectiveSpreadsheetPageSetup, freezeImportedSpreadsheetCell, importedSheetProtectionAuthority, initializeWorkOfficeSpreadsheetCollaboration as initializeOfficeSpreadsheetCollaboration, isSpreadsheetConditionalComparisonOperator, isSpreadsheetConditionalIconSetName, normalizeSheetProtectionAuthority, normalizeSpreadsheetConditionalIconSetFormat, normalizeSpreadsheetConditionalVisualOptions, normalizeSpreadsheetPaperSize, protectedSheetCount, readWorkOfficeSpreadsheetCollaboration as readOfficeSpreadsheetCollaboration, registerDerivedSpreadsheetMatrix, registerImportedSpreadsheetMatrix, replaceWorkOfficeSpreadsheetCollaboration as replaceOfficeSpreadsheetCollaboration, sameSpreadsheetHistoryValue, sheetHasProtectionState, sheetProtectionAuthority, spreadsheetConditionalComparisonNeedsUpperValue, spreadsheetConditionalIconForValue, spreadsheetConditionalIconSetCount, spreadsheetConditionalThresholdValue, spreadsheetConditionalThresholdsEqual, spreadsheetMatrixProfile, spreadsheetProtectionKey, unlockedCellCount, withEditableRange, withSheetProtection, withSheetSelectionPermissions, withoutEditableRange };
|
package/dist/5184.js
CHANGED
|
@@ -470,6 +470,7 @@ function serializeUtf8Xml(document) {
|
|
|
470
470
|
}
|
|
471
471
|
class OoxmlPackage {
|
|
472
472
|
zip;
|
|
473
|
+
textCache = new Map();
|
|
473
474
|
constructor(zip){
|
|
474
475
|
this.zip = zip;
|
|
475
476
|
}
|
|
@@ -483,9 +484,18 @@ class OoxmlPackage {
|
|
|
483
484
|
return Object.keys(this.zip.files).filter((path)=>path.startsWith(prefix) && !this.zip.files[path]?.dir);
|
|
484
485
|
}
|
|
485
486
|
async text(partPath) {
|
|
487
|
+
const cached = this.textCache.get(partPath);
|
|
488
|
+
if (cached) return cached;
|
|
486
489
|
const entry = this.zip.file(partPath);
|
|
487
490
|
if (!entry) throw new Error(`Office package part is missing: ${partPath}`);
|
|
488
|
-
|
|
491
|
+
const pending = entry.async('uint8array').then((bytes)=>decodeXmlBytes(bytes, partPath));
|
|
492
|
+
this.textCache.set(partPath, pending);
|
|
493
|
+
try {
|
|
494
|
+
return await pending;
|
|
495
|
+
} catch (error) {
|
|
496
|
+
this.textCache.delete(partPath);
|
|
497
|
+
throw error;
|
|
498
|
+
}
|
|
489
499
|
}
|
|
490
500
|
async xml(partPath) {
|
|
491
501
|
return parseXml(await this.text(partPath), partPath);
|
|
@@ -519,6 +529,18 @@ function parseXml(source, label = 'Office XML') {
|
|
|
519
529
|
if (error) throw new Error(`${label} is not valid XML: ${error.textContent?.trim() || 'parse error'}`);
|
|
520
530
|
return document;
|
|
521
531
|
}
|
|
532
|
+
const xmlElementPatterns = new Map();
|
|
533
|
+
function xmlContainsAnyElement(source, localNames) {
|
|
534
|
+
if (!source || !localNames.length) return false;
|
|
535
|
+
const key = localNames.join('\u0000');
|
|
536
|
+
let pattern = xmlElementPatterns.get(key);
|
|
537
|
+
if (!pattern) {
|
|
538
|
+
const alternatives = localNames.map((name)=>name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
|
|
539
|
+
pattern = new RegExp(`<(?:[A-Za-z_][\\w.-]*:)?(?:${alternatives})(?=[\\s/>])`);
|
|
540
|
+
xmlElementPatterns.set(key, pattern);
|
|
541
|
+
}
|
|
542
|
+
return pattern.test(source);
|
|
543
|
+
}
|
|
522
544
|
function attribute(element, name) {
|
|
523
545
|
const direct = element.getAttribute(name);
|
|
524
546
|
if (null !== direct) return direct;
|
|
@@ -624,4 +646,4 @@ new TextEncoder();
|
|
|
624
646
|
function isOfficeKernelSpreadsheetError(value) {
|
|
625
647
|
return 'string' == typeof value && spreadsheetErrors.has(value);
|
|
626
648
|
}
|
|
627
|
-
export { OFFICE_KERNEL_SPREADSHEET_MAX_ROWS, OoxmlPackage, WORK_TEMPLATES as officeTemplates, attribute, bytesToDataUrl, childPath, contentTypeForPart, createWorkArtifact as createArtifact, createWorkId as createOfficeId, decodeXmlBytes, descendants, directChild, directChildren, firstDescendant, isOfficeKernelSpreadsheetError, parseXml, resolvePartTarget, serializeUtf8Xml, xmlNamespacePrefix };
|
|
649
|
+
export { OFFICE_KERNEL_SPREADSHEET_MAX_ROWS, OoxmlPackage, WORK_TEMPLATES as officeTemplates, attribute, bytesToDataUrl, childPath, contentTypeForPart, createWorkArtifact as createArtifact, createWorkId as createOfficeId, decodeXmlBytes, descendants, directChild, directChildren, firstDescendant, isOfficeKernelSpreadsheetError, parseXml, resolvePartTarget, serializeUtf8Xml, xmlContainsAnyElement, xmlNamespacePrefix };
|