@file-viewer/renderer-spreadsheet 2.1.28 → 2.1.29
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/spreadsheet.d.ts +2 -0
- package/dist/spreadsheet.js +72 -6
- package/package.json +2 -2
package/dist/spreadsheet.d.ts
CHANGED
|
@@ -31,5 +31,7 @@ type EVirtTableConstructor = new (container: HTMLElement, options: {
|
|
|
31
31
|
config: unknown;
|
|
32
32
|
}) => EVirtTableInstance;
|
|
33
33
|
export declare const resolveEVirtTableConstructor: (module: unknown) => EVirtTableConstructor;
|
|
34
|
+
export declare const resolveEVirtTableStyleText: (documentRef: Document) => string;
|
|
35
|
+
export declare const scopeEVirtTableStyleText: (cssText: string, shadow: boolean) => string;
|
|
34
36
|
declare const renderFileViewerSpreadsheet: (buffer: ArrayBuffer, target: HTMLDivElement, _type?: string, context?: FileRenderContext) => Promise<AppWrapper>;
|
|
35
37
|
export default renderFileViewerSpreadsheet;
|
package/dist/spreadsheet.js
CHANGED
|
@@ -4,6 +4,12 @@ import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualSta
|
|
|
4
4
|
import { buildColumns, createTableConfig, detectIndexOffset, getDisplayColumns, getRowHeight, HEADER_HEIGHT, INDEX_COLUMN_WIDTH, normalizeCellStyle, normalizeRowHeight, RESIZABLE_COLUMN_MIN_WIDTH, RESIZABLE_ROW_MIN_HEIGHT, } from './spreadsheet/view.js';
|
|
5
5
|
const EXCEL_IMAGE_SCROLLBAR_GUARD = 18;
|
|
6
6
|
const DEFAULT_SPREADSHEET_WORKER_AUTO_THRESHOLD = 1 * 1024 * 1024;
|
|
7
|
+
const E_VIRT_TABLE_STYLE_MARKERS = [
|
|
8
|
+
'.e-virt-table-container',
|
|
9
|
+
'.e-virt-table-overlayer',
|
|
10
|
+
'.e-virt-table-editor',
|
|
11
|
+
'.e-virt-table-context-menu',
|
|
12
|
+
];
|
|
7
13
|
const spreadsheetStyle = `
|
|
8
14
|
.excel-wrapper{position:relative;width:100%;height:100%;display:flex;flex-direction:column;background:#fff;color:#172033;font-family:Aptos,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif}
|
|
9
15
|
.excel-wrapper *{box-sizing:border-box}
|
|
@@ -84,9 +90,56 @@ export const resolveEVirtTableConstructor = (module) => {
|
|
|
84
90
|
}
|
|
85
91
|
return constructor;
|
|
86
92
|
};
|
|
87
|
-
const
|
|
93
|
+
const isEVirtTableStyleText = (value) => {
|
|
94
|
+
return E_VIRT_TABLE_STYLE_MARKERS.every(marker => value.includes(marker));
|
|
95
|
+
};
|
|
96
|
+
const collectEVirtTableStyleDocuments = (documentRef) => [
|
|
97
|
+
documentRef,
|
|
98
|
+
typeof document === 'undefined' ? null : document,
|
|
99
|
+
].filter((value, index, values) => (!!value && values.indexOf(value) === index));
|
|
100
|
+
const collectStyleElements = (documents) => documents.flatMap(candidateDocument => { var _a; return Array.from(((_a = candidateDocument.head) === null || _a === void 0 ? void 0 : _a.querySelectorAll('style')) || []); });
|
|
101
|
+
let loadedEVirtTableStyleText = '';
|
|
102
|
+
// e-virt-table bundles its complete stylesheet into the ESM entry and injects
|
|
103
|
+
// it into document.head. Head styles do not cross a ShadowRoot boundary, so
|
|
104
|
+
// capture that exact version-matched CSS and install a copy beside the table.
|
|
105
|
+
// Checking independent layout, overlay, editor, and menu selectors avoids
|
|
106
|
+
// mistaking an app's partial compatibility overrides for the vendor sheet.
|
|
107
|
+
export const resolveEVirtTableStyleText = (documentRef) => {
|
|
108
|
+
var _a;
|
|
109
|
+
const styles = collectStyleElements(collectEVirtTableStyleDocuments(documentRef));
|
|
110
|
+
for (let index = styles.length - 1; index >= 0; index -= 1) {
|
|
111
|
+
const cssText = ((_a = styles[index]) === null || _a === void 0 ? void 0 : _a.textContent) || '';
|
|
112
|
+
if (isEVirtTableStyleText(cssText)) {
|
|
113
|
+
return cssText;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return '';
|
|
117
|
+
};
|
|
118
|
+
const loadEVirtTable = async (documentRef) => {
|
|
119
|
+
const documents = collectEVirtTableStyleDocuments(documentRef);
|
|
120
|
+
const stylesBeforeImport = new Set(collectStyleElements(documents));
|
|
88
121
|
const module = await import('e-virt-table/dist/index.es.js');
|
|
89
|
-
|
|
122
|
+
const injectedStyles = collectStyleElements(documents).filter(style => (!stylesBeforeImport.has(style) && isEVirtTableStyleText(style.textContent || '')));
|
|
123
|
+
const injectedStyle = injectedStyles[injectedStyles.length - 1];
|
|
124
|
+
if (injectedStyle) {
|
|
125
|
+
loadedEVirtTableStyleText = injectedStyle.textContent || '';
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
constructor: resolveEVirtTableConstructor(module),
|
|
129
|
+
// The vendor entry injects CSS while its dynamic import is evaluated.
|
|
130
|
+
// Prefer that newly-created node so an app's independently loaded table
|
|
131
|
+
// version cannot be mistaken for the renderer-owned dependency.
|
|
132
|
+
styleText: loadedEVirtTableStyleText || resolveEVirtTableStyleText(documentRef),
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
export const scopeEVirtTableStyleText = (cssText, shadow) => {
|
|
136
|
+
if (!shadow) {
|
|
137
|
+
return cssText;
|
|
138
|
+
}
|
|
139
|
+
// :root inside a shadow stylesheet does not select the document host. Move
|
|
140
|
+
// the vendor custom properties onto both the ShadowRoot host and renderer
|
|
141
|
+
// root while keeping the remaining upstream selectors byte-for-byte.
|
|
142
|
+
return cssText.replace(/:root\s*\{/g, ':host,.excel-wrapper{');
|
|
90
143
|
};
|
|
91
144
|
const getTargetWindow = (target) => {
|
|
92
145
|
return target.ownerDocument.defaultView;
|
|
@@ -350,9 +403,21 @@ const createSpreadsheetWorkerFactory = (target, bufferByteLength, context) => {
|
|
|
350
403
|
}
|
|
351
404
|
};
|
|
352
405
|
};
|
|
353
|
-
const createStyle = (documentRef) => {
|
|
406
|
+
const createStyle = (documentRef, cssText = spreadsheetStyle) => {
|
|
354
407
|
const style = documentRef.createElement('style');
|
|
355
|
-
style.textContent =
|
|
408
|
+
style.textContent = cssText;
|
|
409
|
+
return style;
|
|
410
|
+
};
|
|
411
|
+
const createEVirtTableStyle = (documentRef, target, cssText) => {
|
|
412
|
+
var _a;
|
|
413
|
+
if (!cssText) {
|
|
414
|
+
throw new Error('Unable to resolve the e-virt-table stylesheet for the spreadsheet render surface.');
|
|
415
|
+
}
|
|
416
|
+
const rootNode = target.getRootNode();
|
|
417
|
+
const ShadowRootCtor = (_a = target.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.ShadowRoot;
|
|
418
|
+
const shadow = !!ShadowRootCtor && rootNode instanceof ShadowRootCtor;
|
|
419
|
+
const style = createStyle(documentRef, scopeEVirtTableStyleText(cssText, shadow));
|
|
420
|
+
style.dataset.fileViewerVendorStyle = 'e-virt-table';
|
|
356
421
|
return style;
|
|
357
422
|
};
|
|
358
423
|
const setHidden = (element, hidden) => {
|
|
@@ -434,7 +499,8 @@ const writeSpreadsheetClipboard = async (documentRef, text) => {
|
|
|
434
499
|
const renderFileViewerSpreadsheet = async (buffer, target, _type, context) => {
|
|
435
500
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
436
501
|
const documentRef = target.ownerDocument;
|
|
437
|
-
const
|
|
502
|
+
const loadedEVirtTable = await loadEVirtTable(documentRef);
|
|
503
|
+
const EVirtTable = loadedEVirtTable.constructor;
|
|
438
504
|
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
439
505
|
const zoomEmitter = createZoomChangeEmitter();
|
|
440
506
|
const root = documentRef.createElement('div');
|
|
@@ -495,7 +561,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, _type, context) => {
|
|
|
495
561
|
summary.className = 'summary';
|
|
496
562
|
toolbar.append(sheetTabsBar, summary);
|
|
497
563
|
root.append(loading, error, tableWrapper, toolbar);
|
|
498
|
-
target.replaceChildren(createStyle(documentRef), root);
|
|
564
|
+
target.replaceChildren(createEVirtTableStyle(documentRef, target, loadedEVirtTable.styleText), createStyle(documentRef), root);
|
|
499
565
|
let sheets = [];
|
|
500
566
|
let sheetIndex = 0;
|
|
501
567
|
let errorMessage = '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-spreadsheet",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.29",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone spreadsheet renderer plugin for Flyfish File Viewer powered by styled-exceljs and e-virt-table.",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"LICENSE"
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@file-viewer/core": "2.1.
|
|
71
|
+
"@file-viewer/core": "2.1.29",
|
|
72
72
|
"@xmldom/xmldom": "^0.9.10",
|
|
73
73
|
"e-virt-table": "^1.3.26",
|
|
74
74
|
"jszip": "^3.10.1",
|