gbxlxs 0.4.0 → 0.5.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/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.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.2.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';
@@ -133,14 +134,19 @@ export class SheetEditor {
133
134
  this.root = document.createElement('div');
134
135
  this.root.className = `sheets-app${this.dark ? ' dark' : ''}`;
135
136
  this.root.innerHTML = `
137
+ <div class="gbo-head sheets-head">
138
+ <span class="gbo-head__title"></span>
139
+ <span class="gbo-head__sub" hidden></span>
140
+ <span class="gbo-head__status save-status"></span>
141
+ <span class="gbo-head__spacer"></span>
142
+ <span class="gbo-head__actions">
143
+ <label class="gbo-head__auto"><input type="checkbox" class="gbo-head__autosave" />自动保存</label>
144
+ <button type="button" class="gbo-head__btn gbo-head__btn--primary sheets-save" data-act="save">保存</button>
145
+ </span>
146
+ <button type="button" class="gbo-head__btn gbo-head__preview" data-act="preview" title="预览模式" aria-pressed="false">${icon('view', 14)}<span>预览</span></button>
147
+ </div>
136
148
  <div class="sheets-menubar">
137
149
  <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
150
  </div>
145
151
  <div class="sheets-body">
146
152
  <div class="sheet-toolbar-host"></div>
@@ -157,17 +163,19 @@ export class SheetEditor {
157
163
  this.mount.appendChild(this.root);
158
164
  this.menuBarEl = this.root.querySelector('.gbx-menubar');
159
165
  this.menubarRowEl = this.root.querySelector('.sheets-menubar');
160
- this.docNameEl = this.root.querySelector('.doc-name');
161
- this.docPathEl = this.root.querySelector('.doc-path');
166
+ this.docNameEl = this.root.querySelector('.gbo-head__title');
167
+ this.docPathEl = this.root.querySelector('.gbo-head__sub');
162
168
  this.statusEl = this.root.querySelector('.save-status');
163
169
  this.saveBtn = this.root.querySelector('[data-act="save"]');
170
+ this.autosaveEl = this.root.querySelector('.gbo-head__autosave');
171
+ this.previewBtn = this.root.querySelector('[data-act="preview"]');
164
172
  this.toolbarHost = this.root.querySelector('.sheet-toolbar-host');
165
173
  this.formulaHost = this.root.querySelector('.sheet-formula-host');
166
174
  this.gridHost = this.root.querySelector('.sheet-grid-host');
167
175
  this.tabsHost = this.root.querySelector('.sheet-tabs-host');
168
176
  this.statusStateEl = this.root.querySelector('.sb-state');
169
177
  this.statusCalcEl = this.root.querySelector('.sb-calc');
170
- // 只 inert 功能区按钮带与公式栏:选项卡行里的预览按钮要保持可点(选项卡只切视图,放行无写风险)
178
+ // 只 inert 功能区按钮带与公式栏:文档头的预览按钮在 inert 之外,预览档里仍可点「退出预览」
171
179
  this.guard = createReadOnlyGuard(this.root, {
172
180
  editZones: () => [this.root.querySelector('.rb-bar'), this.formulaHost],
173
181
  });
@@ -179,7 +187,7 @@ export class SheetEditor {
179
187
  if (this.readOnly) this.setReadOnly(true);
180
188
  }
181
189
 
182
- /** 显示/隐藏顶部菜单栏那一行(含同行文档名与保存按钮) */
190
+ /** 显示/隐藏顶部菜单栏那一行;文档头(标题/自动保存/保存/预览)不受影响 */
183
191
  setMenuBarVisible(on) {
184
192
  this.menuBarVisible = !!on;
185
193
  this.menubarRowEl.style.display = this.menuBarVisible ? '' : 'none';
@@ -192,7 +200,7 @@ export class SheetEditor {
192
200
  this.renderChrome();
193
201
  }
194
202
 
195
- /** 预览模式:只读 + 收起菜单/功能带/公式栏;同一按钮或 Esc 退出并恢复原档位 */
203
+ /** 预览模式:只读 + 收起菜单/功能带/公式栏;文档头留着,同一按钮或 Esc 退出并恢复原档位 */
196
204
  setPreview(on) {
197
205
  const next = !!on;
198
206
  if (next === this.preview) return;
@@ -200,22 +208,32 @@ export class SheetEditor {
200
208
  this.previewRestore = { readOnly: this.readOnly, menuBar: this.menuBarVisible };
201
209
  this.preview = true;
202
210
  this.root.classList.add('gbx-is-preview');
203
- this.toolbar.setPreview(true);
204
211
  this.setReadOnly(true);
205
212
  this.setMenuBarVisible(false);
206
213
  } else {
207
214
  const restore = this.previewRestore || { readOnly: false, menuBar: true };
208
215
  this.preview = false;
209
216
  this.root.classList.remove('gbx-is-preview');
210
- this.toolbar.setPreview(false);
211
217
  this.setReadOnly(restore.readOnly);
212
218
  this.setMenuBarVisible(restore.menuBar);
213
219
  this.previewRestore = null;
214
220
  }
221
+ this.renderPreviewBtn();
222
+ }
223
+
224
+ /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
225
+ renderPreviewBtn() {
226
+ const active = this.preview;
227
+ this.previewBtn.classList.toggle('gbo-head__preview--on', active);
228
+ this.previewBtn.title = active ? '退出预览' : '预览模式';
229
+ this.previewBtn.setAttribute('aria-pressed', String(active));
230
+ this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
215
231
  }
216
232
 
217
233
  bindEvents() {
218
234
  this.saveBtn.addEventListener('click', () => this.saveNow());
235
+ this.previewBtn.addEventListener('click', () => this.setPreview(!this.preview));
236
+ this.autosaveEl.addEventListener('change', () => this.setAutoSave(this.autosaveEl.checked));
219
237
  this.menuBarEl.addEventListener('click', (event) => {
220
238
  const btn = event.target.closest('[data-menu]');
221
239
  if (!btn) return;
@@ -410,9 +428,10 @@ export class SheetEditor {
410
428
  this.docPathEl.hidden = !path;
411
429
  const status = this.getStatus();
412
430
  this.statusEl.textContent = status.text;
413
- this.statusEl.className = `save-status ${status.kind ? `gbx-is-${status.kind}` : ''}`.trim();
431
+ this.statusEl.className = `gbo-head__status save-status ${status.kind ? `gbx-is-${status.kind}` : ''}`.trim();
414
432
  this.saveBtn.disabled = this.readOnly || !this.canSave();
415
433
  this.saveBtn.classList.toggle('gbx-is-busy', status.text === '保存中…');
434
+ this.autosaveEl.checked = this.getAutoSave();
416
435
  // 只读档只留「视图」菜单(缩放/主题),其余编辑类菜单按钮直接禁用
417
436
  this.menuBarEl.querySelectorAll('[data-menu]').forEach((btn) => {
418
437
  btn.disabled = this.readOnly && btn.dataset.menu !== 'view';
@@ -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
  }
@@ -879,8 +862,6 @@ export class SheetToolbar {
879
862
 
880
863
  render() {
881
864
  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
865
  this.barEl.innerHTML = this.groups()
885
866
  .map((group) => `<div class="rb-group"><div class="rb-grid">${group.items.map((item) => this.renderItem(item)).join('')}</div></div>`)
886
867
  .join('');
@@ -71,33 +71,31 @@
71
71
  }
72
72
 
73
73
  /* ==================== 只读档 ==================== */
74
- .sheets-app.gb-is-readonly .sheet-toolbar-host,
74
+ .sheets-app.gb-is-readonly .sheet-ribbon,
75
75
  .sheets-app.gb-is-readonly .sheet-formula-host { opacity: .55; }
76
76
 
77
77
  /* ==================== 预览模式 ==================== */
78
- /* 只留选项卡行右上的退出按钮、网格与工作表标签;菜单、功能带、公式栏、状态栏与浮层收起 */
78
+ /* 只留文档头(标题 + 退出预览)、网格与工作表标签;菜单、功能带、公式栏、状态栏与浮层收起 */
79
79
  .sheets-app.gbx-is-preview .sheets-menubar,
80
- .sheets-app.gbx-is-preview .rb-bar,
80
+ .sheets-app.gbx-is-preview .sheet-ribbon,
81
81
  .sheets-app.gbx-is-preview .sheet-formula-bar,
82
+ .sheets-app.gbx-is-preview .gbo-head__actions,
82
83
  .sheets-app.gbx-is-preview .sheets-statusbar,
83
84
  .sheets-app.gbx-is-preview .gbx-find,
84
85
  .sheets-app.gbx-is-preview .gbx-filter-panel,
85
86
  .sheets-app.gbx-is-preview .gbx-thread-panel {
86
87
  display: none;
87
88
  }
88
- .sheets-app.gbx-is-preview .rb-tab {
89
- display: none;
90
- }
91
89
 
92
90
  /* ==================== 菜单栏与文档头 ==================== */
93
91
  /* 菜单栏 / 文档头 / 功能区 / 公式栏 / 状态栏 / 页签的视觉由 gbofficeui 统一,
94
92
  这里只保留 xlsx 专属状态与骨架。 */
95
93
 
96
- .sheets-docinfo .save-status.gbx-is-dirty {
94
+ .sheets-head .save-status.gbx-is-dirty {
97
95
  color: var(--gbx-dt-accent);
98
96
  }
99
97
 
100
- .sheets-docinfo .save-status.gbx-is-error {
98
+ .sheets-head .save-status.gbx-is-error {
101
99
  color: var(--gbx-dt-danger);
102
100
  }
103
101
 
@@ -2186,11 +2184,11 @@
2186
2184
  /* ==================== 窄屏 ==================== */
2187
2185
 
2188
2186
  @media (max-width: 760px) {
2189
- .sheets-docinfo .doc-path {
2187
+ .sheets-head .gbo-head__sub {
2190
2188
  display: none;
2191
2189
  }
2192
2190
 
2193
- .sheets-docinfo .doc-name {
2191
+ .sheets-head .gbo-head__title {
2194
2192
  max-width: 140px;
2195
2193
  }
2196
2194