gbpptx 0.3.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.
@@ -1,4 +1,4 @@
1
- // [文件] gbpptx·顶部菜单栏 —— 与 gbdocs / gbxlxs 一致:左侧菜单栏 + 右侧文档名/保存状态/保存按钮
1
+ // [文件] gbpptx·顶部菜单栏与文档头 —— 与 gbdocx / gbxlxs 一致:菜单栏一行 + 文档头一行(标题/自动保存/保存/预览)
2
2
 
3
3
  import { SHAPE_KINDS, SLIDE_LAYOUTS, TRANSITIONS } from '../../../src/kernel/model.js';
4
4
  import { icon } from './icons.js';
@@ -18,41 +18,74 @@ export class TitleBar {
18
18
  constructor(app) {
19
19
  this.app = app;
20
20
  this.el = el('header', 'pp-topbar');
21
+ this.headEl = el('header', 'gbo-head pp-head');
21
22
  this.build();
23
+ this.buildHead();
22
24
  this.refresh();
23
25
  }
24
26
 
25
27
  build() {
26
28
  const defs = [
27
- ['文件', () => this.fileItems()],
28
- ['编辑', () => this.editItems()],
29
- ['插入', () => this.insertItems()],
30
- ['幻灯片', () => this.slideItems()],
31
- ['放映', () => this.showItems()],
32
- ['审阅', () => this.reviewItems()],
33
- ['视图', () => this.viewItems()],
29
+ ['file', '文件', () => this.fileItems()],
30
+ ['edit', '编辑', () => this.editItems()],
31
+ ['insert', '插入', () => this.insertItems()],
32
+ ['slide', '幻灯片', () => this.slideItems()],
33
+ ['show', '放映', () => this.showItems()],
34
+ ['review', '审阅', () => this.reviewItems()],
35
+ ['view', '视图', () => this.viewItems()],
34
36
  ];
35
37
  const bar = el('div', 'pp-menubar');
36
- for (const [label, items] of defs) {
38
+ for (const [key, label, items] of defs) {
37
39
  const btn = el('button', 'pp-menubar__btn', label);
38
40
  btn.type = 'button';
41
+ btn.dataset.menu = key;
39
42
  btn.addEventListener('click', () => {
40
43
  btn.classList.add('gbp-is-open');
41
44
  openMenu({ anchor: btn, items: items(), onClose: () => btn.classList.remove('gbp-is-open') });
42
45
  });
43
46
  bar.appendChild(btn);
44
47
  }
48
+ this.el.append(bar);
49
+ }
50
+
51
+ buildHead() {
52
+ const title = el('span', 'gbo-head__title');
53
+ const state = el('span', 'gbo-head__sub');
54
+ const spacer = el('span', 'gbo-head__spacer');
55
+
56
+ const auto = el('label', 'gbo-head__auto');
57
+ this.autosaveEl = el('input', 'gbo-head__autosave');
58
+ this.autosaveEl.type = 'checkbox';
59
+ this.autosaveEl.addEventListener('change', () => this.app.setAutosave(this.autosaveEl.checked));
60
+ auto.append(this.autosaveEl, document.createTextNode('自动保存'));
45
61
 
46
- const info = el('div', 'pp-docinfo');
47
- this.nameEl = el('span', 'pp-docinfo__name', '新建演示');
48
- this.stateEl = el('span', 'pp-docinfo__state', '已保存');
49
- this.saveBtn = el('button', 'pp-docinfo__save', '保存');
62
+ this.saveBtn = el('button', 'gbo-head__btn gbo-head__btn--primary', '保存');
50
63
  this.saveBtn.type = 'button';
51
64
  this.saveBtn.title = '保存 (Ctrl+S)';
52
65
  this.saveBtn.addEventListener('click', () => this.app.save());
53
- info.append(this.nameEl, this.stateEl, this.saveBtn);
54
66
 
55
- this.el.append(bar, info);
67
+ const actions = el('span', 'gbo-head__actions');
68
+ actions.append(auto, this.saveBtn);
69
+
70
+ this.previewBtn = el('button', 'gbo-head__btn gbo-head__preview', '预览');
71
+ this.previewBtn.type = 'button';
72
+ this.previewBtn.title = '预览模式';
73
+ this.previewBtn.setAttribute('aria-pressed', 'false');
74
+ this.previewBtn.innerHTML = `${icon('eye', 14)}<span>预览</span>`;
75
+ this.previewBtn.addEventListener('click', () => this.app.setPreview(!this.app.preview));
76
+
77
+ this.nameEl = title;
78
+ this.stateEl = state;
79
+ this.headEl.append(title, state, spacer, actions, this.previewBtn);
80
+ }
81
+
82
+ /** 预览档按钮态:同一位置从「预览」切成「退出预览」 */
83
+ setPreview(on) {
84
+ const active = !!on;
85
+ this.previewBtn.classList.toggle('gbo-head__preview--on', active);
86
+ this.previewBtn.title = active ? '退出预览' : '预览模式';
87
+ this.previewBtn.setAttribute('aria-pressed', String(active));
88
+ this.previewBtn.querySelector('span').textContent = active ? '退出预览' : '预览';
56
89
  }
57
90
 
58
91
  /* ===================== 菜单条目 ===================== */
@@ -60,7 +93,7 @@ export class TitleBar {
60
93
  fileItems() {
61
94
  const app = this.app;
62
95
  const hasSlides = app.snapshot.slides.length > 0;
63
- return [
96
+ const items = [
64
97
  { label: '新建', shortcut: 'Ctrl+N', onClick: () => app.newDoc() },
65
98
  { label: '打开…', shortcut: 'Ctrl+O', onClick: () => app.openFile() },
66
99
  { divided: true },
@@ -74,6 +107,10 @@ export class TitleBar {
74
107
  { divided: true },
75
108
  { label: '关闭', onClick: () => app.closeDocument() },
76
109
  ];
110
+ // 只读档保留导出/打印,其余文件动作会替换或写回文档,一律禁用
111
+ if (!app.readOnly) return items;
112
+ const viewActions = new Set(['导出 PPTX', '导出 PDF', '打印…']);
113
+ return items.map((item) => ({ ...item, disabled: item.disabled || !viewActions.has(item.label) }));
77
114
  }
78
115
 
79
116
  editItems() {
@@ -186,7 +223,7 @@ export class TitleBar {
186
223
  confirmText: '知道了',
187
224
  build: (body) => {
188
225
  const p = el('div', 'pp-about');
189
- p.innerHTML = `${icon('logo', 40)}<h3>挂逼演示 gbpptx</h3><p>真实的 .pptx 读写 + Office 式演示编辑器。</p><p class="pp-backstage__muted">Pptx 文件进入 → 查看/编辑 → 原样导出</p>`;
226
+ p.innerHTML = `${icon('logo', 40)}<h3>挂逼演示 gbpptx</h3><p>真实的 .pptx 读写 + Office 式演示编辑器。</p><p class="pp-muted">Pptx 文件进入 → 查看/编辑 → 原样导出</p>`;
190
227
  body.appendChild(p);
191
228
  },
192
229
  });
@@ -203,6 +240,13 @@ export class TitleBar {
203
240
  ? '未保存'
204
241
  : app.doc.handle ? '已保存' : (app.doc.savedAt ? '已保存副本' : '尚未保存');
205
242
  this.stateEl.classList.toggle('gbp-is-dirty', app.dirty);
206
- this.saveBtn.disabled = !app.snapshot.slides.length;
243
+ this.saveBtn.disabled = app.readOnly || !app.snapshot.slides.length;
244
+ this.autosaveEl.checked = app.autosave;
245
+ this.setPreview(app.preview);
246
+ // 只读档锁掉纯编辑类菜单,放映/视图与文件菜单里的导出/打印照常可用
247
+ const writeMenus = new Set(['edit', 'insert', 'slide', 'review']);
248
+ this.el.querySelectorAll('[data-menu]').forEach((btn) => {
249
+ btn.disabled = app.readOnly && writeMenus.has(btn.dataset.menu);
250
+ });
207
251
  }
208
252
  }
package/web/index.html CHANGED
@@ -7,6 +7,11 @@
7
7
  <link rel="stylesheet" href="/web/styles/tokens.css" />
8
8
  <link rel="stylesheet" href="/web/styles/slides.css" />
9
9
  <link rel="stylesheet" href="/web/styles/office.css" />
10
+ <link rel="stylesheet" href="/vendor/gbofficeui/office-chrome.css" />
11
+ <style>
12
+ /* 独立运行时撑满视口;嵌入宿主由宿主容器给高度,不依赖这条 */
13
+ html, body { height: 100%; margin: 0; }
14
+ </style>
10
15
  <script type="importmap">
11
16
  {
12
17
  "imports": {
package/web/serve.mjs CHANGED
@@ -4,7 +4,8 @@ import { fileURLToPath } from 'node:url';
4
4
  import { startStaticServer } from 'guabiutils/dev-server';
5
5
 
6
6
  const ooxmlSrc = fileURLToPath(new URL('../../gbooxml/src/', import.meta.url));
7
- const utilsSrc = fileURLToPath(new URL('../../guabiutils/src/', import.meta.url));
7
+ const utilsSrc = fileURLToPath(new URL('../../../guabiutils/src/', import.meta.url));
8
+ const officeChrome = fileURLToPath(new URL('../../gbofficeui/styles/', import.meta.url));
8
9
 
9
10
  const { origin } = await startStaticServer({
10
11
  root: fileURLToPath(new URL('..', import.meta.url)),
@@ -13,6 +14,7 @@ const { origin } = await startStaticServer({
13
14
  mounts: [
14
15
  { prefix: '/vendor/gbooxml/', dir: ooxmlSrc },
15
16
  { prefix: '/vendor/guabiutils/', dir: utilsSrc },
17
+ { prefix: '/vendor/gbofficeui/', dir: officeChrome },
16
18
  ],
17
19
  });
18
20