gbxlxs 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "gbxlxs",
3
- "version": "0.4.0",
4
- "description": "Standalone spreadsheet (XLSX) engine with a self-contained HTML editor: read/write xlsx, workbook model ops, CSV/HTML import-export and a full spreadsheet UI.",
5
- "type": "module",
6
- "license": "MIT",
7
- "sideEffects": [
8
- "**/*.css"
9
- ],
10
- "main": "./src/index.js",
11
- "exports": {
12
- ".": "./src/index.js",
13
- "./ops": "./src/ops.js",
14
- "./session": "./src/session.js",
15
- "./workbook": "./src/workbook/index.js",
16
- "./web/*": "./web/*",
17
- "./package.json": "./package.json"
18
- },
19
- "files": [
20
- "src",
21
- "web",
22
- "LICENSE"
23
- ],
24
- "scripts": {
25
- "start": "node web/serve.mjs",
26
- "test": "node --test test/editing.test.js test/move.test.js test/references.test.js test/session.test.js test/roundtrip.test.js test/scenarios.test.js test/ops-scenarios.test.js test/formula.test.js test/function-search.test.js test/find-replace.test.js test/advanced-filter.test.js test/structured-refs.test.js test/dynamic-array.test.js test/print.test.js test/threaded-comments.test.js test/shapes.test.js test/table-export.test.js test/charts.test.js test/data-tools.test.js test/preservation.test.js test/readonly.test.js"
27
- },
28
- "dependencies": {
29
- "gbooxml": "^0.1.3",
30
- "gbofficeui": "^0.1.0",
31
- "guabiutils": "^0.3.0"
32
- },
33
- "keywords": [
34
- "xlsx",
35
- "excel",
36
- "spreadsheet",
37
- "ooxml",
38
- "workbook",
39
- "editor",
40
- "ui"
41
- ],
42
- "engines": {
43
- "node": ">=18"
44
- }
45
- }
1
+ {
2
+ "name": "gbxlxs",
3
+ "version": "0.5.1",
4
+ "description": "Standalone spreadsheet (XLSX) engine with a self-contained HTML editor: read/write xlsx, workbook model ops, CSV/HTML import-export and a full spreadsheet UI.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": [
8
+ "**/*.css"
9
+ ],
10
+ "main": "./src/index.js",
11
+ "exports": {
12
+ ".": "./src/index.js",
13
+ "./ops": "./src/ops.js",
14
+ "./session": "./src/session.js",
15
+ "./workbook": "./src/workbook/index.js",
16
+ "./web/*": "./web/*",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "src",
21
+ "web",
22
+ "LICENSE"
23
+ ],
24
+ "scripts": {
25
+ "start": "node web/serve.mjs",
26
+ "test": "node --test test/editing.test.js test/move.test.js test/references.test.js test/session.test.js test/roundtrip.test.js test/scenarios.test.js test/ops-scenarios.test.js test/formula.test.js test/function-search.test.js test/find-replace.test.js test/advanced-filter.test.js test/structured-refs.test.js test/dynamic-array.test.js test/print.test.js test/threaded-comments.test.js test/shapes.test.js test/table-export.test.js test/charts.test.js test/data-tools.test.js test/preservation.test.js test/readonly.test.js"
27
+ },
28
+ "dependencies": {
29
+ "gbooxml": "^0.1.3",
30
+ "gbofficeui": "^0.1.0",
31
+ "guabiutils": "^0.3.0"
32
+ },
33
+ "keywords": [
34
+ "xlsx",
35
+ "excel",
36
+ "spreadsheet",
37
+ "ooxml",
38
+ "workbook",
39
+ "editor",
40
+ "ui"
41
+ ],
42
+ "engines": {
43
+ "node": ">=18"
44
+ }
45
+ }
@@ -21,6 +21,7 @@ import { PrintPreview } from './ui/print-preview.js';
21
21
  import { openChartDialog } from './ui/chart-dialog.js';
22
22
  import { openNameManagerDialog, openRemoveDuplicatesDialog, openSubtotalDialog, openTextToColumnsDialog } from './ui/data-dialogs.js';
23
23
  import { notify } from './ui/notify.js';
24
+ import { icon } from './ui/icons.js';
24
25
  import { bindCtrlWheelZoom, createReadOnlyGuard, debounce, downloadBlob, isReadOnlyViewKey, isTypingTarget } from 'guabiutils';
25
26
  import { formulaSuggest } from './ui/formula-suggest.js';
26
27
  import { XLSX_MIME, openXlsxFile, saveXlsxFile, saveXlsxAs } from './ui/file-io.js';
@@ -73,6 +74,7 @@ export class SheetEditor {
73
74
  this.menuBarVisible = !options.hideMenuBar;
74
75
  this.preview = false;
75
76
  this.previewRestore = null;
77
+ this.pageFullscreen = false;
76
78
  this.active = !this.embedded;
77
79
  this.ready = false;
78
80
  this.saving = false;
@@ -133,14 +135,20 @@ export class SheetEditor {
133
135
  this.root = document.createElement('div');
134
136
  this.root.className = `sheets-app${this.dark ? ' dark' : ''}`;
135
137
  this.root.innerHTML = `
138
+ <div class="gbo-head sheets-head">
139
+ <span class="gbo-head__title"></span>
140
+ <span class="gbo-head__sub" hidden></span>
141
+ <span class="gbo-head__status save-status"></span>
142
+ <span class="gbo-head__spacer"></span>
143
+ <span class="gbo-head__actions">
144
+ <label class="gbo-head__auto"><input type="checkbox" class="gbo-head__autosave" />自动保存</label>
145
+ <button type="button" class="gbo-head__btn gbo-head__btn--primary sheets-save" data-act="save">保存</button>
146
+ </span>
147
+ <button type="button" class="gbo-head__btn gbo-head__preview" data-act="preview" title="预览模式" aria-pressed="false">${icon('view', 14)}<span>预览</span></button>
148
+ <button type="button" class="gbo-head__btn gbo-head__preview" data-act="fullscreen" title="全屏" aria-pressed="false">${icon('fullscreen', 14)}<span>全屏</span></button>
149
+ </div>
136
150
  <div class="sheets-menubar">
137
151
  <div class="gbx-menubar">${MENU_LABELS.map((m) => `<button type="button" class="gbx-menubar-btn" data-menu="${m.key}">${m.label}</button>`).join('')}</div>
138
- <div class="sheets-docinfo">
139
- <span class="doc-name"></span>
140
- <span class="doc-path"></span>
141
- <span class="save-status"></span>
142
- <button type="button" class="gbx-btn gbx-btn-primary gbx-btn-sm sheets-save" data-act="save">保存</button>
143
- </div>
144
152
  </div>
145
153
  <div class="sheets-body">
146
154
  <div class="sheet-toolbar-host"></div>
@@ -157,17 +165,20 @@ export class SheetEditor {
157
165
  this.mount.appendChild(this.root);
158
166
  this.menuBarEl = this.root.querySelector('.gbx-menubar');
159
167
  this.menubarRowEl = this.root.querySelector('.sheets-menubar');
160
- this.docNameEl = this.root.querySelector('.doc-name');
161
- this.docPathEl = this.root.querySelector('.doc-path');
168
+ this.docNameEl = this.root.querySelector('.gbo-head__title');
169
+ this.docPathEl = this.root.querySelector('.gbo-head__sub');
162
170
  this.statusEl = this.root.querySelector('.save-status');
163
171
  this.saveBtn = this.root.querySelector('[data-act="save"]');
172
+ this.autosaveEl = this.root.querySelector('.gbo-head__autosave');
173
+ this.previewBtn = this.root.querySelector('[data-act="preview"]');
174
+ this.fullscreenBtn = this.root.querySelector('[data-act="fullscreen"]');
164
175
  this.toolbarHost = this.root.querySelector('.sheet-toolbar-host');
165
176
  this.formulaHost = this.root.querySelector('.sheet-formula-host');
166
177
  this.gridHost = this.root.querySelector('.sheet-grid-host');
167
178
  this.tabsHost = this.root.querySelector('.sheet-tabs-host');
168
179
  this.statusStateEl = this.root.querySelector('.sb-state');
169
180
  this.statusCalcEl = this.root.querySelector('.sb-calc');
170
- // 只 inert 功能区按钮带与公式栏:选项卡行里的预览按钮要保持可点(选项卡只切视图,放行无写风险)
181
+ // 只 inert 功能区按钮带与公式栏:文档头的预览按钮在 inert 之外,预览档里仍可点「退出预览」
171
182
  this.guard = createReadOnlyGuard(this.root, {
172
183
  editZones: () => [this.root.querySelector('.rb-bar'), this.formulaHost],
173
184
  });
@@ -179,7 +190,7 @@ export class SheetEditor {
179
190
  if (this.readOnly) this.setReadOnly(true);
180
191
  }
181
192
 
182
- /** 显示/隐藏顶部菜单栏那一行(含同行文档名与保存按钮) */
193
+ /** 显示/隐藏顶部菜单栏那一行;文档头(标题/自动保存/保存/预览)不受影响 */
183
194
  setMenuBarVisible(on) {
184
195
  this.menuBarVisible = !!on;
185
196
  this.menubarRowEl.style.display = this.menuBarVisible ? '' : 'none';
@@ -192,7 +203,7 @@ export class SheetEditor {
192
203
  this.renderChrome();
193
204
  }
194
205
 
195
- /** 预览模式:只读 + 收起菜单/功能带/公式栏;同一按钮或 Esc 退出并恢复原档位 */
206
+ /** 预览模式:只读 + 收起菜单/功能带/公式栏;文档头留着,同一按钮或 Esc 退出并恢复原档位 */
196
207
  setPreview(on) {
197
208
  const next = !!on;
198
209
  if (next === this.preview) return;
@@ -200,22 +211,63 @@ export class SheetEditor {
200
211
  this.previewRestore = { readOnly: this.readOnly, menuBar: this.menuBarVisible };
201
212
  this.preview = true;
202
213
  this.root.classList.add('gbx-is-preview');
203
- this.toolbar.setPreview(true);
204
214
  this.setReadOnly(true);
205
215
  this.setMenuBarVisible(false);
206
216
  } else {
207
217
  const restore = this.previewRestore || { readOnly: false, menuBar: true };
208
218
  this.preview = false;
209
219
  this.root.classList.remove('gbx-is-preview');
210
- this.toolbar.setPreview(false);
211
220
  this.setReadOnly(restore.readOnly);
212
221
  this.setMenuBarVisible(restore.menuBar);
213
222
  this.previewRestore = null;
214
223
  }
224
+ this.renderPreviewBtn();
225
+ }
226
+
227
+ /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
228
+ renderPreviewBtn() {
229
+ const active = this.preview;
230
+ this.previewBtn.classList.toggle('gbo-head__preview--on', active);
231
+ this.previewBtn.title = active ? '退出预览' : '预览模式';
232
+ this.previewBtn.setAttribute('aria-pressed', String(active));
233
+ this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
234
+ }
235
+
236
+ /** 全屏/恢复:整个表格应用铺满网页(页面内覆盖;不用原生 Fullscreen,
237
+ * 否则 append 到 body 的菜单/弹窗在全屏层外不可见) */
238
+ toggleFullscreen() {
239
+ this.setPageFullscreen(!this.pageFullscreen);
240
+ }
241
+
242
+ setPageFullscreen(on) {
243
+ this.pageFullscreen = !!on;
244
+ this.root.classList.toggle('gbx-is-pagefullscreen', this.pageFullscreen);
245
+ if (this.pageFullscreen) document.addEventListener('keydown', this.onFullscreenEsc, true);
246
+ else document.removeEventListener('keydown', this.onFullscreenEsc, true);
247
+ this.renderFullscreenBtn();
248
+ // 视图选项卡里的同名入口跟着换选中态
249
+ this.toolbar?.render?.();
250
+ }
251
+
252
+ renderFullscreenBtn() {
253
+ const active = this.pageFullscreen;
254
+ this.fullscreenBtn.title = active ? '退出全屏' : '全屏';
255
+ this.fullscreenBtn.setAttribute('aria-pressed', String(active));
256
+ this.fullscreenBtn.innerHTML = `${icon(active ? 'fullscreenExit' : 'fullscreen', 14)}<span>${active ? '恢复' : '全屏'}</span>`;
215
257
  }
216
258
 
217
259
  bindEvents() {
218
260
  this.saveBtn.addEventListener('click', () => this.saveNow());
261
+ this.previewBtn.addEventListener('click', () => this.setPreview(!this.preview));
262
+ this.fullscreenBtn.addEventListener('click', () => this.toggleFullscreen());
263
+ this.onFullscreenEsc = (event) => {
264
+ if (event.key !== 'Escape' || !this.pageFullscreen) return;
265
+ // 菜单/弹窗开着时先交给它们自己关,别一按 Esc 就退出全屏
266
+ if (document.querySelector('.gbx-menu, .gbx-modal-mask, .gbx-prompt')) return;
267
+ event.stopPropagation();
268
+ this.setPageFullscreen(false);
269
+ };
270
+ this.autosaveEl.addEventListener('change', () => this.setAutoSave(this.autosaveEl.checked));
219
271
  this.menuBarEl.addEventListener('click', (event) => {
220
272
  const btn = event.target.closest('[data-menu]');
221
273
  if (!btn) return;
@@ -410,9 +462,10 @@ export class SheetEditor {
410
462
  this.docPathEl.hidden = !path;
411
463
  const status = this.getStatus();
412
464
  this.statusEl.textContent = status.text;
413
- this.statusEl.className = `save-status ${status.kind ? `gbx-is-${status.kind}` : ''}`.trim();
465
+ this.statusEl.className = `gbo-head__status save-status ${status.kind ? `gbx-is-${status.kind}` : ''}`.trim();
414
466
  this.saveBtn.disabled = this.readOnly || !this.canSave();
415
467
  this.saveBtn.classList.toggle('gbx-is-busy', status.text === '保存中…');
468
+ this.autosaveEl.checked = this.getAutoSave();
416
469
  // 只读档只留「视图」菜单(缩放/主题),其余编辑类菜单按钮直接禁用
417
470
  this.menuBarEl.querySelectorAll('[data-menu]').forEach((btn) => {
418
471
  btn.disabled = this.readOnly && btn.dataset.menu !== 'view';
@@ -992,6 +1045,7 @@ export class SheetEditor {
992
1045
  document.removeEventListener('mousedown', this.onPointerDown, true);
993
1046
  document.removeEventListener('mouseup', this.onPointerUp, true);
994
1047
  document.removeEventListener('keydown', this.onKeydown);
1048
+ document.removeEventListener('keydown', this.onFullscreenEsc, true);
995
1049
  this.root.removeEventListener('paste', this.onPaste);
996
1050
  this.unbindWheelZoom?.();
997
1051
  window.removeEventListener('beforeunload', this.onBeforeUnload);
@@ -53,7 +53,7 @@ export class SheetToolbar {
53
53
  this.uid = `gbxtb${++toolbarSeq}`;
54
54
  this.fontListId = `${this.uid}-fonts`;
55
55
  this.sizeListId = `${this.uid}-sizes`;
56
- this.mount.className = 'sheet-ribbon';
56
+ this.mount.classList.add('sheet-ribbon');
57
57
  this.mount.innerHTML = `
58
58
  <div class="rb-tabs"></div>
59
59
  <div class="rb-bar"></div>
@@ -62,14 +62,6 @@ export class SheetToolbar {
62
62
  `;
63
63
  this.tabsEl = this.mount.querySelector('.rb-tabs');
64
64
  this.barEl = this.mount.querySelector('.rb-bar');
65
- this.previewBtn = document.createElement('button');
66
- this.previewBtn.type = 'button';
67
- this.previewBtn.className = 'rb-preview';
68
- this.previewBtn.title = '预览模式';
69
- this.previewBtn.setAttribute('aria-pressed', 'false');
70
- this.previewBtn.innerHTML = `${icon('view', 14)}<span>预览</span>`;
71
- this.previewBtn.addEventListener('click', () => this.app.setPreview(!this.app.preview));
72
- this.tabsEl.appendChild(this.previewBtn);
73
65
  this.tabsEl.addEventListener('click', (event) => {
74
66
  const btn = event.target.closest('[data-tab]');
75
67
  if (!btn) return;
@@ -94,15 +86,6 @@ export class SheetToolbar {
94
86
  return this.app.commands;
95
87
  }
96
88
 
97
- /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
98
- setPreview(on) {
99
- const active = !!on;
100
- this.previewBtn.classList.toggle('on', active);
101
- this.previewBtn.title = active ? '退出预览' : '预览模式';
102
- this.previewBtn.setAttribute('aria-pressed', String(active));
103
- this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
104
- }
105
-
106
89
  get selection() {
107
90
  return this.app.selection;
108
91
  }
@@ -799,13 +782,11 @@ export class SheetToolbar {
799
782
  key: 'fullscreen',
800
783
  kind: 'sel',
801
784
  icon: 'fullscreen',
802
- label: '全屏',
785
+ label: () => (this.app.pageFullscreen ? '恢复' : '全屏'),
803
786
  tip: '全屏显示',
804
787
  grid: [2, 2],
805
- onClick: () => {
806
- if (document.fullscreenElement) document.exitFullscreen();
807
- else document.documentElement.requestFullscreen();
808
- },
788
+ active: () => this.app.pageFullscreen,
789
+ onClick: () => this.app.toggleFullscreen(),
809
790
  },
810
791
  ],
811
792
  },
@@ -879,8 +860,6 @@ export class SheetToolbar {
879
860
 
880
861
  render() {
881
862
  this.tabsEl.innerHTML = TABS.map((t) => `<button type="button" class="rb-tab${t.key === this.tab ? ' on' : ''}" data-tab="${t.key}">${t.label}</button>`).join('');
882
- // 预览按钮不参与 tab 重绘:每次重建后补回行尾,避免 render 把它冲掉
883
- this.tabsEl.appendChild(this.previewBtn);
884
863
  this.barEl.innerHTML = this.groups()
885
864
  .map((group) => `<div class="rb-group"><div class="rb-grid">${group.items.map((item) => this.renderItem(item)).join('')}</div></div>`)
886
865
  .join('');
@@ -37,6 +37,7 @@ const paths = {
37
37
  cf: '<rect x="3.8" y="3.8" width="7.2" height="7.2" rx="1.2" fill="currentColor"/><rect x="13" y="3.8" width="7.2" height="7.2" rx="1.2" fill="currentColor" opacity="0.4"/><rect x="3.8" y="13" width="7.2" height="7.2" rx="1.2" fill="currentColor" opacity="0.4"/><rect x="13" y="13" width="7.2" height="7.2" rx="1.2" fill="currentColor" opacity="0.7"/>',
38
38
  freeze: '<rect x="3.5" y="3.5" width="17" height="17" rx="1" fill="none" stroke="currentColor" stroke-width="1.6"/><rect x="4.5" y="4.5" width="15" height="4.6" fill="currentColor" opacity="0.35"/><path d="M3.5 9.1h17" fill="none" stroke="currentColor" stroke-width="1.6"/>',
39
39
  fullscreen: '<path d="M3.5 3.5h7v2.4H5.9v4.6H3.5zM13.5 3.5h7v7h-2.4V5.9h-4.6zM3.5 13.5h2.4v4.6h4.6v2.4h-7zM18.1 13.5h2.4v7h-7v-2.4h4.6z"/>',
40
+ fullscreenExit: '<path d="M3.5 9.5h6v-6H7.1v3.6H3.5zM14.5 9.5h6V7.1h-3.6V3.5h-2.4zM3.5 14.5h3.6v3.6h2.4v-6h-6zM20.5 14.5h-6v6h2.4v-3.6h3.6z"/>',
40
41
  check: '<path d="M9.6 16.2 5.4 12l-1.5 1.5 5.7 5.7L20 8.7 18.5 7.2z"/>',
41
42
  close: '<path d="M6.4 5 5 6.4 10.6 12 5 17.6 6.4 19 12 13.4 17.6 19 19 17.6 13.4 12 19 6.4 17.6 5 12 10.6z"/>',
42
43
  chevronRight: '<path d="M9.2 4.6 16.6 12l-7.4 7.4-1.6-1.6L13.4 12 7.6 6.2z"/>',
@@ -39,6 +39,16 @@
39
39
  color: var(--gbx-dt-text);
40
40
  }
41
41
 
42
+ /* 页面内全屏态:整个表格应用铺满视口(文档头留着,恢复按钮在同一位置) */
43
+ .sheets-app.gbx-is-pagefullscreen {
44
+ position: fixed;
45
+ inset: 0;
46
+ z-index: 500;
47
+ width: 100%;
48
+ height: 100%;
49
+ background: var(--gbx-dt-surface);
50
+ }
51
+
42
52
  .sheets-app.dark {
43
53
  --gbx-sg-bg: #1e1f22;
44
54
  --gbx-sg-text: #d9dce1;
@@ -71,33 +81,31 @@
71
81
  }
72
82
 
73
83
  /* ==================== 只读档 ==================== */
74
- .sheets-app.gb-is-readonly .sheet-toolbar-host,
84
+ .sheets-app.gb-is-readonly .sheet-ribbon,
75
85
  .sheets-app.gb-is-readonly .sheet-formula-host { opacity: .55; }
76
86
 
77
87
  /* ==================== 预览模式 ==================== */
78
- /* 只留选项卡行右上的退出按钮、网格与工作表标签;菜单、功能带、公式栏、状态栏与浮层收起 */
88
+ /* 只留文档头(标题 + 退出预览)、网格与工作表标签;菜单、功能带、公式栏、状态栏与浮层收起 */
79
89
  .sheets-app.gbx-is-preview .sheets-menubar,
80
- .sheets-app.gbx-is-preview .rb-bar,
90
+ .sheets-app.gbx-is-preview .sheet-ribbon,
81
91
  .sheets-app.gbx-is-preview .sheet-formula-bar,
92
+ .sheets-app.gbx-is-preview .gbo-head__actions,
82
93
  .sheets-app.gbx-is-preview .sheets-statusbar,
83
94
  .sheets-app.gbx-is-preview .gbx-find,
84
95
  .sheets-app.gbx-is-preview .gbx-filter-panel,
85
96
  .sheets-app.gbx-is-preview .gbx-thread-panel {
86
97
  display: none;
87
98
  }
88
- .sheets-app.gbx-is-preview .rb-tab {
89
- display: none;
90
- }
91
99
 
92
100
  /* ==================== 菜单栏与文档头 ==================== */
93
101
  /* 菜单栏 / 文档头 / 功能区 / 公式栏 / 状态栏 / 页签的视觉由 gbofficeui 统一,
94
102
  这里只保留 xlsx 专属状态与骨架。 */
95
103
 
96
- .sheets-docinfo .save-status.gbx-is-dirty {
104
+ .sheets-head .save-status.gbx-is-dirty {
97
105
  color: var(--gbx-dt-accent);
98
106
  }
99
107
 
100
- .sheets-docinfo .save-status.gbx-is-error {
108
+ .sheets-head .save-status.gbx-is-error {
101
109
  color: var(--gbx-dt-danger);
102
110
  }
103
111
 
@@ -2186,11 +2194,11 @@
2186
2194
  /* ==================== 窄屏 ==================== */
2187
2195
 
2188
2196
  @media (max-width: 760px) {
2189
- .sheets-docinfo .doc-path {
2197
+ .sheets-head .gbo-head__sub {
2190
2198
  display: none;
2191
2199
  }
2192
2200
 
2193
- .sheets-docinfo .doc-name {
2201
+ .sheets-head .gbo-head__title {
2194
2202
  max-width: 140px;
2195
2203
  }
2196
2204