dsh-ppt 0.13.0 → 0.15.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/CHANGELOG.md +17 -0
- package/README.en.md +50 -47
- package/README.md +52 -48
- package/docs/COACHING.md +44 -0
- package/docs/DATA.md +43 -0
- package/docs/USAGE.en.md +196 -196
- package/docs/USAGE.md +218 -217
- package/docs/VALIDATION.md +4 -0
- package/docs/validation/0.8.0.md +10 -10
- package/docs/validation-0.14.0.md +24 -0
- package/docs/validation-0.15.0.md +25 -0
- package/lib/client.js +613 -326
- package/lib/coaching-model.d.ts +12 -0
- package/lib/coaching-model.js +93 -0
- package/lib/coaching.d.ts +197 -0
- package/lib/coaching.js +317 -0
- package/lib/execution.d.ts +3 -0
- package/lib/execution.js +11 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -1
- package/lib/tools.js +27 -0
- package/lib/types.d.ts +43 -0
- package/lib/workbench-language.js +2 -0
- package/lib/workbench.d.ts +4 -0
- package/lib/workbench.js +68 -10
- package/package.json +5 -3
- package/skills/dsh-ppt/SKILL.md +80 -76
- package/skills/dsh-ppt/package.json +11 -11
- package/skills/dsh-ppt/references/advanced.md +41 -41
- package/skills/dsh-ppt/references/data.md +67 -0
- package/skills/dsh-ppt/references/syntax.md +43 -43
- package/skills/dsh-ppt/references/troubleshooting.md +19 -19
- package/skills/dsh-ppt/scripts/build-deck.mjs +3 -0
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +574 -538
- package/skills/dsh-ppt/scripts/deck-core.mjs +2388 -2380
- package/skills/dsh-ppt/scripts/deck-data-math.mjs +76 -0
- package/skills/dsh-ppt/scripts/deck-data-view.mjs +113 -0
- package/skills/dsh-ppt/scripts/deck-data.mjs +190 -0
- package/skills/dsh-ppt/scripts/deck-delivery.mjs +104 -104
- package/skills/dsh-ppt/scripts/deck-render.mjs +270 -270
package/lib/client.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// Browser source, distributed directly. tsc deliberately does not rewrite this file.
|
|
2
|
-
window.__ModuleLoader__.load({ id: 'dsh-ppt', factory: require => {
|
|
1
|
+
// Browser source, distributed directly. tsc deliberately does not rewrite this file.
|
|
2
|
+
window.__ModuleLoader__.load({ id: 'dsh-ppt', factory: require => {
|
|
3
3
|
const React = require('react');
|
|
4
4
|
var __FR_KEY = "dsh-first-run:dsh-ppt:v1";
|
|
5
5
|
var __FR_TITLE = "演示文稿 · 首次使用(4 步)";
|
|
6
|
-
var __FR_TITLE_EN = "Presentations · First steps";
|
|
7
|
-
var __FR_STEPS_EN = [{title:"Choose a theme",body:"Choose from swiss, velvet, data, soft and bold before building your presentation."},{title:"Provide actual material",body:"Give the assistant your points, data and tables. It produces an editable PPTX and an HTML presentation.",tryIt:"Turn this quarterly update into eight slides using the data theme."},{title:"Review in the browser",body:"Step through the HTML preview, then edit text, images and speaker notes in this panel."},{title:"Check the final slides",body:"Review the final PPTX in PowerPoint or WPS, or use the optional renderer to check fonts and layout before delivery."}];
|
|
6
|
+
var __FR_TITLE_EN = "Presentations · First steps";
|
|
7
|
+
var __FR_STEPS_EN = [{title:"Choose a theme",body:"Choose from swiss, velvet, data, soft and bold before building your presentation."},{title:"Provide actual material",body:"Give the assistant your points, data and tables. It produces an editable PPTX and an HTML presentation.",tryIt:"Turn this quarterly update into eight slides using the data theme."},{title:"Review in the browser",body:"Step through the HTML preview, then edit text, images and speaker notes in this panel."},{title:"Check the final slides",body:"Review the final PPTX in PowerPoint or WPS, or use the optional renderer to check fonts and layout before delivery."}];
|
|
8
8
|
var __FR_STEPS = [{"title":"先选主题","body":"内置 5 套主题(swiss / velvet / data / soft / bold),先定风格再生成内容。"},{"title":"给内容,不给空话","body":"把要点、数据、表格直接给助手,它会排成幻灯片并同时产出 PPTX 与网页版。","tryIt":"把这份季度总结做成 8 页汇报,用 data 主题"},{"title":"先在浏览器里过一遍","body":"网页版可直接翻页预览,确认排版没问题再导出。"},{"title":"导出后看图核对","body":"渲染成图检查一遍再交付,避免字体缺失或溢出。"}];
|
|
9
9
|
|
|
10
10
|
// ---- first-run guide (shared snippet; keep in sync across plugins) ----
|
|
@@ -37,48 +37,48 @@ function __frEnsureCss() {
|
|
|
37
37
|
}
|
|
38
38
|
function __frRead() { try { return localStorage.getItem(__FR_KEY) === 'done'; } catch (e) { return false; } }
|
|
39
39
|
function __frWrite() { try { localStorage.setItem(__FR_KEY, 'done'); } catch (e) {} }
|
|
40
|
-
function __FirstRunCard(props) {
|
|
41
|
-
useLanguage(props?.locale || localeService);
|
|
42
|
-
var english = languageOf(props?.locale || localeService) === 'en';
|
|
43
|
-
var steps = english ? __FR_STEPS_EN : __FR_STEPS;
|
|
44
|
-
var text = (zh, en) => english ? en : zh;
|
|
40
|
+
function __FirstRunCard(props) {
|
|
41
|
+
useLanguage(props?.locale || localeService);
|
|
42
|
+
var english = languageOf(props?.locale || localeService) === 'en';
|
|
43
|
+
var steps = english ? __FR_STEPS_EN : __FR_STEPS;
|
|
44
|
+
var text = (zh, en) => english ? en : zh;
|
|
45
45
|
var doneState = React.useState(__frRead);
|
|
46
46
|
var done = doneState[0], setDone = doneState[1];
|
|
47
47
|
var idxState = React.useState(0);
|
|
48
48
|
var index = idxState[0], setIndex = idxState[1];
|
|
49
49
|
React.useEffect(function () { __frEnsureCss(); }, []);
|
|
50
50
|
if (done) return null;
|
|
51
|
-
var step = steps[index];
|
|
52
|
-
var last = index >= steps.length - 1;
|
|
51
|
+
var step = steps[index];
|
|
52
|
+
var last = index >= steps.length - 1;
|
|
53
53
|
var close = function () { __frWrite(); setDone(true); };
|
|
54
54
|
var kids = [
|
|
55
55
|
React.createElement('div', { className: 'fr-head', key: 'h' },
|
|
56
56
|
React.createElement('span', { className: 'fr-dot' }),
|
|
57
|
-
React.createElement('span', { className: 'fr-title' }, english ? __FR_TITLE_EN : __FR_TITLE),
|
|
58
|
-
React.createElement('span', { className: 'fr-count' }, (index + 1) + ' / ' + steps.length)),
|
|
57
|
+
React.createElement('span', { className: 'fr-title' }, english ? __FR_TITLE_EN : __FR_TITLE),
|
|
58
|
+
React.createElement('span', { className: 'fr-count' }, (index + 1) + ' / ' + steps.length)),
|
|
59
59
|
React.createElement('div', { className: 'fr-step', key: 't' }, step.title),
|
|
60
60
|
React.createElement('div', { className: 'fr-body', key: 'b' }, step.body),
|
|
61
61
|
];
|
|
62
62
|
if (step.tryIt) kids.push(React.createElement('div', { className: 'fr-try', key: 'y' },
|
|
63
|
-
React.createElement('span', null, text('可以直接说', 'Try saying')),
|
|
64
|
-
React.createElement('code', null, text('「', '“') + step.tryIt + text('」', '”'))));
|
|
65
|
-
var buttons = [React.createElement('div', { className: 'fr-progress', key: 'p' }, steps.map(function (_, i) {
|
|
63
|
+
React.createElement('span', null, text('可以直接说', 'Try saying')),
|
|
64
|
+
React.createElement('code', null, text('「', '“') + step.tryIt + text('」', '”'))));
|
|
65
|
+
var buttons = [React.createElement('div', { className: 'fr-progress', key: 'p' }, steps.map(function (_, i) {
|
|
66
66
|
return React.createElement('span', { key: i, className: 'fr-seg' + (i <= index ? ' on' : '') });
|
|
67
67
|
}))];
|
|
68
|
-
buttons.push(React.createElement('button', { className: 'fr-btn ghost', type: 'button', onClick: close, key: 's' }, text('跳过', 'Skip')));
|
|
69
|
-
if (index > 0) buttons.push(React.createElement('button', { className: 'fr-btn', type: 'button', key: 'prev', onClick: function () { setIndex(index - 1); } }, text('上一步', 'Back')));
|
|
70
|
-
buttons.push(React.createElement('button', { className: 'fr-btn primary', type: 'button', key: 'next', onClick: function () { if (last) close(); else setIndex(index + 1); } }, last ? text('开始使用', 'Start') : text('下一步', 'Next')));
|
|
68
|
+
buttons.push(React.createElement('button', { className: 'fr-btn ghost', type: 'button', onClick: close, key: 's' }, text('跳过', 'Skip')));
|
|
69
|
+
if (index > 0) buttons.push(React.createElement('button', { className: 'fr-btn', type: 'button', key: 'prev', onClick: function () { setIndex(index - 1); } }, text('上一步', 'Back')));
|
|
70
|
+
buttons.push(React.createElement('button', { className: 'fr-btn primary', type: 'button', key: 'next', onClick: function () { if (last) close(); else setIndex(index + 1); } }, last ? text('开始使用', 'Start') : text('下一步', 'Next')));
|
|
71
71
|
kids.push(React.createElement('div', { className: 'fr-bar', key: 'bar' }, buttons));
|
|
72
72
|
return React.createElement('div', { className: 'fr-card' }, kids);
|
|
73
73
|
}
|
|
74
74
|
function __withFirstRun(Component) {
|
|
75
75
|
return function FirstRunWrapped(props) {
|
|
76
|
-
return React.createElement(React.Fragment, null, React.createElement(__FirstRunCard, props), React.createElement(Component, props));
|
|
76
|
+
return React.createElement(React.Fragment, null, React.createElement(__FirstRunCard, props), React.createElement(Component, props));
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
// ---- end first-run guide ----
|
|
80
|
-
|
|
81
|
-
const { useState, useEffect, useRef, useMemo } = React;
|
|
80
|
+
|
|
81
|
+
const { useState, useEffect, useRef, useMemo } = React;
|
|
82
82
|
const h = React.createElement;
|
|
83
83
|
|
|
84
84
|
// Interface language follows DSH; user content and stored records keep their original text.
|
|
@@ -102,21 +102,21 @@ const EN = Object.freeze({
|
|
|
102
102
|
"内容没有变化。": "No changes to save.",
|
|
103
103
|
"已保存,HTML、PPTX 和工程文件已同步更新。": "Saved. HTML, PPTX and project files were updated together.",
|
|
104
104
|
"页面顺序已更新,可撤销。": "Slides reordered. You can undo this change.",
|
|
105
|
-
"复制本页": "Duplicate slide",
|
|
106
|
-
"删除本页": "Delete slide",
|
|
107
|
-
"页面已复制,图片、图表和备注一并保留,可撤销。": "Slide duplicated with its images, charts and notes. You can undo this change.",
|
|
108
|
-
"页面已删除,可撤销。": "Slide deleted. You can undo this change.",
|
|
105
|
+
"复制本页": "Duplicate slide",
|
|
106
|
+
"删除本页": "Delete slide",
|
|
107
|
+
"页面已复制,图片、图表和备注一并保留,可撤销。": "Slide duplicated with its images, charts and notes. You can undo this change.",
|
|
108
|
+
"页面已删除,可撤销。": "Slide deleted. You can undo this change.",
|
|
109
109
|
"已撤销上次修改。": "Last change undone.",
|
|
110
110
|
"当前 PPTX 已生成逐页图片,请查看画面。": "Slide images were rendered from the current PPTX. Review each slide.",
|
|
111
111
|
"正在渲染最终 PPTX,较大文件可能需要几分钟…": "Rendering the final PPTX. Large files may take a few minutes…",
|
|
112
112
|
"已请求下载,请查看浏览器的下载列表。": "Download requested. Check your browser’s downloads.",
|
|
113
|
-
"请选择 5 MiB 以内的 PNG 或 JPEG 图片。": "Choose a PNG or JPEG image up to 5 MiB.",
|
|
113
|
+
"请选择 5 MiB 以内的 PNG 或 JPEG 图片。": "Choose a PNG or JPEG image up to 5 MiB.",
|
|
114
114
|
"无法读取图片,请重试。": "Could not read the image. Try again.",
|
|
115
|
-
"正在读取图片,切换页面会取消本次读取。": "Reading the image. Switching slides cancels this upload.",
|
|
116
|
-
"图片已载入,保存后生效。": "Image loaded. Save this slide to apply it.",
|
|
117
|
-
"下载讲稿 Markdown": "Download speaker notes",
|
|
118
|
-
"另存副本": "Save a copy",
|
|
119
|
-
"副本已保存,原文件保留。副本从工程生成,不包含 Office 手工修改。": "Copy saved. Original files are preserved. The copy is rebuilt from the project and does not include external Office edits.",
|
|
115
|
+
"正在读取图片,切换页面会取消本次读取。": "Reading the image. Switching slides cancels this upload.",
|
|
116
|
+
"图片已载入,保存后生效。": "Image loaded. Save this slide to apply it.",
|
|
117
|
+
"下载讲稿 Markdown": "Download speaker notes",
|
|
118
|
+
"另存副本": "Save a copy",
|
|
119
|
+
"副本已保存,原文件保留。副本从工程生成,不包含 Office 手工修改。": "Copy saved. Original files are preserved. The copy is rebuilt from the project and does not include external Office edits.",
|
|
120
120
|
"演示文稿编辑": "Presentation editor",
|
|
121
121
|
"修改本插件生成的成品,保存时同步更新 HTML、可编辑 PPTX 和工程文件。": "Edit presentations generated by this plugin. Saving updates the HTML, editable PPTX and project file together.",
|
|
122
122
|
"载入最新版本,保留我的输入": "Load latest and keep my input",
|
|
@@ -191,306 +191,593 @@ function useLanguage(locale) {
|
|
|
191
191
|
const [, rerender] = useState(0);
|
|
192
192
|
useEffect(() => { const update = () => rerender(n => n + 1); update(); return locale?.subscribe?.(update); }, [locale]);
|
|
193
193
|
}
|
|
194
|
-
|
|
195
|
-
const ROUTE = 'api/dsh-ppt/workbench';
|
|
196
|
-
const fields = [['title', '标题'], ['subtitle', '副标题'], ['kicker', '眉题'], ['text', '正文'], ['bullets', '要点(每行一条)'], ['notes', '演讲备注']];
|
|
197
|
-
const css = `
|
|
198
|
-
.pptw {
|
|
199
|
-
.pptw *{box-sizing:border-box}.pptw h2{font-size:22px;margin:0}.pptw h3{font-size:16px;margin:12px 0 6px}
|
|
200
|
-
.pptw .muted{color:var(--fg-muted,#66768a);font-size:13px}.pptw .tools{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0;align-items:center}
|
|
201
|
-
.pptw button{font:inherit;border:1px solid var(--border,#ccd8e5);border-radius:9px;background:var(--bg-surface,#fff);color:inherit;padding:7px 12px;cursor:pointer;text-align:left;white-space:normal}
|
|
202
|
-
.pptw button.primary{background:#245ee9;border-color:#245ee9;color:#fff}.pptw button:disabled{opacity:.45;cursor:default}
|
|
203
|
-
.pptw input:not([type=file]),.pptw textarea,.pptw select{font:inherit;color:inherit;width:100%;background:var(--bg,#fff);border:1px solid var(--border,#c9d5e4);border-radius:8px;padding:8px 10px}
|
|
204
|
-
.pptw textarea{resize:vertical}.pptw label{display:block;margin:8px 0 3px}.pptw .layout{display:grid;grid-template-columns:minmax(130px,190px) minmax(0,1fr);gap:14px}
|
|
205
|
-
.pptw .pages{display:flex;flex-direction:column;gap:5px;max-height:480px;overflow:auto}.pptw .pages button[aria-current=true]{background:#245ee9;color:#fff}
|
|
206
|
-
.pptw .preview{border:1px solid var(--border,#ced8e6);border-radius:12px;overflow:hidden;background:#f0f4fa;aspect-ratio:16/9;position:relative}
|
|
207
|
-
.pptw iframe{position:absolute;inset:0;width:100%;height:100%;border:0}.pptw .render-page{width:100%;display:block}
|
|
208
|
-
.pptw .notice{border-radius:9px;padding:10px 12px;margin:10px 0;background
|
|
209
|
-
.pptw .card{border:1px solid var(--border,#d5dfeb);border-radius:12px;padding:12px;margin:10px 0;background:var(--bg-surface,#fff)}
|
|
210
|
-
.pptw .
|
|
211
|
-
.pptw .
|
|
212
|
-
.pptw :
|
|
213
|
-
.pptw .
|
|
214
|
-
.pptw .
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
e.preventDefault();e.stopImmediatePropagation();
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
194
|
+
|
|
195
|
+
const ROUTE = 'api/dsh-ppt/workbench';
|
|
196
|
+
const fields = [['title', '标题'], ['subtitle', '副标题'], ['kicker', '眉题'], ['text', '正文'], ['bullets', '要点(每行一条)'], ['notes', '演讲备注']];
|
|
197
|
+
const css = `
|
|
198
|
+
.pptw {--fg:var(--dsw-alias-label-primary,#27354b);--fg-muted:var(--dsw-alias-label-tertiary,#66768a);--bg:var(--dsw-alias-bg-layer-1,#fff);--bg-surface:var(--dsw-alias-bg-layer-2,#fff);--border:var(--dsw-alias-border-l3,#ccd8e5);color:var(--fg);font:14px/1.6 system-ui,sans-serif;min-width:0;max-width:1140px;margin:0 auto;padding:8px}
|
|
199
|
+
.pptw *{box-sizing:border-box}.pptw h2{font-size:22px;margin:0}.pptw h3{font-size:16px;margin:12px 0 6px}
|
|
200
|
+
.pptw .muted{color:var(--fg-muted,#66768a);font-size:13px}.pptw .tools{display:flex;gap:8px;flex-wrap:wrap;margin:12px 0;align-items:center}
|
|
201
|
+
.pptw button{font:inherit;border:1px solid var(--border,#ccd8e5);border-radius:9px;background:var(--bg-surface,#fff);color:inherit;padding:7px 12px;cursor:pointer;text-align:left;white-space:normal}
|
|
202
|
+
.pptw button.primary{background:#245ee9;border-color:#245ee9;color:#fff}.pptw button:disabled{opacity:.45;cursor:default}
|
|
203
|
+
.pptw input:not([type=file]),.pptw textarea,.pptw select{font:inherit;color:inherit;width:100%;background:var(--bg,#fff);border:1px solid var(--border,#c9d5e4);border-radius:8px;padding:8px 10px}
|
|
204
|
+
.pptw textarea{resize:vertical}.pptw label{display:block;margin:8px 0 3px}.pptw .layout{display:grid;grid-template-columns:minmax(130px,190px) minmax(0,1fr);gap:14px}
|
|
205
|
+
.pptw .pages{display:flex;flex-direction:column;gap:5px;max-height:480px;overflow:auto}.pptw .pages button[aria-current=true]{background:#245ee9;color:#fff}
|
|
206
|
+
.pptw .preview{border:1px solid var(--border,#ced8e6);border-radius:12px;overflow:hidden;background:#f0f4fa;aspect-ratio:16/9;position:relative}
|
|
207
|
+
.pptw iframe{position:absolute;inset:0;width:100%;height:100%;border:0}.pptw .render-page{width:100%;display:block}
|
|
208
|
+
.pptw .notice{border-radius:9px;padding:10px 12px;margin:10px 0;background:color-mix(in srgb,#5686fe 12%,var(--bg-surface));color:var(--fg);overflow-wrap:anywhere}.pptw .error{background:color-mix(in srgb,#f25a5a 14%,var(--bg-surface))}
|
|
209
|
+
.pptw .card{border:1px solid var(--border,#d5dfeb);border-radius:12px;padding:12px;margin:10px 0;background:var(--bg-surface,#fff)}
|
|
210
|
+
.pptw .coaching{margin-top:24px}.pptw .coaching-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 14px}
|
|
211
|
+
.pptw .coaching label.choice{display:flex;gap:8px;align-items:flex-start}.pptw .coaching input[type=checkbox]{width:auto;flex:none;margin-top:5px}
|
|
212
|
+
.pptw .coaching pre{white-space:pre-wrap;overflow-wrap:anywhere;font:inherit;margin:6px 0}.pptw .coaching blockquote{margin:8px 0;padding-left:12px;border-left:3px solid var(--border,#ccd8e5);overflow-wrap:anywhere}
|
|
213
|
+
.pptw .coaching .card{overflow-wrap:anywhere}.pptw .coaching .before-after{display:grid;grid-template-columns:1fr 1fr;gap:12px}
|
|
214
|
+
.pptw .project-list{display:flex;flex-direction:column;gap:8px}.pptw .project-list button{display:block;width:100%}
|
|
215
|
+
.pptw .file{font-size:12px;overflow-wrap:anywhere}.pptw .image-preview{width:100%;max-height:160px;object-fit:contain;background:#edf2f8;border-radius:8px}
|
|
216
|
+
.pptw :focus-visible{outline:3px solid #78a8ff;outline-offset:2px}.pptw .dirty{color:#986114;font-size:13px}
|
|
217
|
+
.pptw .badge-dirty{color:#986114;font-size:11px;font-weight:600;padding:2px 8px;border-radius:999px;background:rgba(245,158,11,.14);border:1px solid rgba(245,158,11,.35);margin-left:4px}
|
|
218
|
+
.pptw .notice button{margin-left:8px;padding:2px 9px;border-radius:6px;border:1px solid currentColor;background:transparent;color:inherit;font-size:12px;cursor:pointer}
|
|
219
|
+
[role=dialog]:has(.pptw){width:min(1200px,calc(100vw - 48px))!important;max-width:1200px!important}
|
|
220
|
+
@media(max-width:700px){.pptw .layout{grid-template-columns:1fr}.pptw .pages{max-height:180px}.pptw .preview{min-height:190px}.pptw{padding:3px}
|
|
221
|
+
.pptw .coaching-grid,.pptw .coaching .before-after{grid-template-columns:1fr}
|
|
222
|
+
[role=dialog]:has(.pptw){width:100%!important;max-width:100%!important;flex-direction:column!important}
|
|
223
|
+
[role=dialog]:has(.pptw)>nav+div{min-width:0;width:100%}
|
|
224
|
+
[role=dialog]:has(.pptw)>nav+div>div:has(.pptw){padding:12px!important;min-width:0}
|
|
225
|
+
[role=dialog]:has(.pptw) nav{width:100%!important;flex-basis:auto!important;border-right:0;max-height:170px;overflow:auto}
|
|
226
|
+
[role=dialog]:has(.pptw) nav>div:has(>button){display:flex;flex-direction:row!important;flex-wrap:wrap;flex-shrink:0;gap:4px}
|
|
227
|
+
}`;
|
|
228
|
+
|
|
229
|
+
async function action(body, signal) {
|
|
230
|
+
const response = await fetch(new URL(ROUTE, document.baseURI), { method: 'POST', credentials: 'same-origin', signal,
|
|
231
|
+
headers: { 'content-type': 'application/json', 'x-dsh-ppt-action': '1' }, body: JSON.stringify(body) });
|
|
232
|
+
let value;
|
|
233
|
+
try { value = await response.json(); } catch { throw new Error(t("无法读取服务响应,请检查插件是否加载")) }
|
|
234
|
+
if (!response.ok || value.ok === false) { const localized = languageOf() === 'en' ? value.messageEn || englishError(value.message, response.status) : value.message; const hint = languageOf() === 'en' ? value.installationHintEn : value.installationHint; const error = new Error((localized || t("操作未完成")) + (hint ? '\n' + hint : '')); error.status = response.status; throw error; }
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
function draftFor(slide) {
|
|
238
|
+
const source={...slide,...slide.dataTemplate};
|
|
239
|
+
return { title: source.title || '', subtitle: source.subtitle || '', kicker: source.kicker || '', text: source.text || '',
|
|
240
|
+
bullets: (source.bullets || []).join('\n'), notes: source.notes || '' };
|
|
241
|
+
}
|
|
242
|
+
function editorHtml(html, nonce) {
|
|
243
|
+
const bridge = `<style>#hud,#delivery-bar,#review-panel,#progress,#notes-panel,#help-panel,#toast,#blank{display:none!important}.slide-frame{pointer-events:none!important}.slide-frame .slide{pointer-events:auto!important}</style><script>(function(){const nonce=${JSON.stringify(nonce)};
|
|
244
|
+
function tell(field){parent.postMessage({type:'dsh-ppt-select',nonce:nonce,field:field},'*')}
|
|
245
|
+
document.addEventListener('keydown',function(e){
|
|
246
|
+
if(e.target.closest('#data-panel'))return;
|
|
247
|
+
var mod=e.ctrlKey||e.metaKey;
|
|
248
|
+
if(mod&&(e.key==='s'||e.key==='S')){e.preventDefault();e.stopImmediatePropagation();parent.postMessage({type:'dsh-ppt-shortcut',nonce:nonce,key:'save'},'*');return}
|
|
249
|
+
if(e.key==='Escape'){e.preventDefault();e.stopImmediatePropagation();parent.postMessage({type:'dsh-ppt-shortcut',nonce:nonce,key:'escape'},'*');return}
|
|
250
|
+
if(e.altKey&&(e.key==='ArrowLeft'||e.key==='ArrowRight')){e.preventDefault();e.stopImmediatePropagation();parent.postMessage({type:'dsh-ppt-shortcut',nonce:nonce,key:e.key==='ArrowLeft'?'prev':'next'},'*');return}
|
|
251
|
+
e.stopImmediatePropagation();if(e.key!=='Tab')e.preventDefault()
|
|
252
|
+
},true);
|
|
253
|
+
document.addEventListener('touchstart',function(e){e.stopImmediatePropagation()},true);
|
|
254
|
+
document.addEventListener('touchend',function(e){e.stopImmediatePropagation()},true);
|
|
255
|
+
document.addEventListener('wheel',function(e){e.stopImmediatePropagation()},{capture:true,passive:true});
|
|
256
|
+
document.addEventListener('click',function(e){if(e.target.closest('#data-panel,.data-number,.data-chart-trace'))return;const n=e.target.closest('h1,h2,.subtitle,.kicker,.statement-title,.quote-text,.quote-attr,li');if(!n)return;
|
|
257
|
+
e.preventDefault();e.stopImmediatePropagation();let field=n.matches('li')?'bullets':n.matches('.subtitle,.quote-attr')?'subtitle':n.matches('.kicker')?'kicker':'title';tell(field)},true);
|
|
258
|
+
window.addEventListener('message',function(e){if(e.source!==parent||e.data?.nonce!==nonce)return;if(e.data.type==='dsh-ppt-jump')window.__dshPpt?.jump(e.data.page);if(e.data.type==='dsh-ppt-data-set'&&window.__dshData){window.__dshData.setParameters(e.data.parameters);const state=window.__dshData.getState();parent.postMessage({type:'dsh-ppt-data',nonce,parameters:e.data.parameters,valid:state.valid,command:e.data.command},'*')}});
|
|
259
|
+
if(window.__dshData)window.__dshData.onChange=function(parameters,dirty,valid){parent.postMessage({type:'dsh-ppt-data',nonce,parameters,dirty,valid},'*')};
|
|
260
|
+
})();<\/script>`;
|
|
261
|
+
const policy = `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src data:; connect-src 'none'; form-action 'none'">`;
|
|
262
|
+
// Presenter code contains a quoted </body>; only append at the document end.
|
|
263
|
+
return html.replace(/<head>/i, '<head>' + policy).replace(/<\/body>(\s*<\/html>\s*)$/i, bridge + '</body>$1');
|
|
264
|
+
}
|
|
265
|
+
function createImageLoader() {
|
|
266
|
+
let current = null;
|
|
267
|
+
function cancel() {
|
|
268
|
+
const reader = current; current = null;
|
|
269
|
+
if (reader?.readyState === 1) reader.abort();
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
cancel,
|
|
273
|
+
get pending() { return current !== null; },
|
|
274
|
+
read(file, success, failure) {
|
|
275
|
+
cancel(); const reader = new FileReader(); current = reader;
|
|
276
|
+
const settle = callback => { if (current !== reader) return; current = null; callback(); };
|
|
277
|
+
reader.onload = () => settle(() => success(String(reader.result)));
|
|
278
|
+
reader.onerror = () => settle(failure);
|
|
279
|
+
reader.onabort = () => { if (current === reader) current = null; };
|
|
280
|
+
try { reader.readAsDataURL(file); } catch { settle(failure); }
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function CoachingPanel({ project, selected, blocked, onAdopt, onChoose }) {
|
|
285
|
+
const L = (zh, en) => languageOf() === 'en' ? en : zh;
|
|
286
|
+
const [mode, setMode] = useState(''), [routes, setRoutes] = useState([]), [route, setRoute] = useState('');
|
|
287
|
+
const [difficulty, setDifficulty] = useState('normal'), [audience, setAudience] = useState('general'), [limit, setLimit] = useState(1);
|
|
288
|
+
const [scope, setScope] = useState('all'), [material, setMaterial] = useState(''), [run, setRun] = useState(null), [history, setHistory] = useState([]);
|
|
289
|
+
const [answer, setAnswer] = useState(''), [patches, setPatches] = useState([]), [backups, setBackups] = useState([]);
|
|
290
|
+
const [busy, setBusy] = useState(false), [error, setError] = useState(''), [notice, setNotice] = useState('');
|
|
291
|
+
const active = useRef(null), alive = useRef(true), current = useRef(null), runRef = useRef(null), reading = useRef(0);
|
|
292
|
+
current.current = { project, selected, blocked }; runRef.current = run;
|
|
293
|
+
const stale = !!run && (run.stale || run.revision !== project.revision);
|
|
294
|
+
const maxCalls = mode === 'review' ? limit : limit + 1;
|
|
295
|
+
const modeName = value => value === 'review' ? L('AI 预审', 'AI review') : L('模拟答辩', 'Rehearsal');
|
|
296
|
+
const statusName = value => ({ ready: L('等待下一步', 'Ready'), busy: L('正在调用模型', 'Calling model'), paused: L('已暂停', 'Paused'), complete: L('已结束', 'Finished') })[value] || value;
|
|
297
|
+
const kindName = value => ({ expression: L('表达建议', 'Expression'), logic: L('逻辑问题', 'Logic'), evidence: L('证据缺口', 'Missing evidence') })[value];
|
|
298
|
+
function accept(value) { if (alive.current) { runRef.current = value; setRun(value); } }
|
|
299
|
+
const request = (operation, data = {}, signal) => action({ operation: 'coach-' + operation, id: current.current.project.id, expectedRevision: current.current.project.revision, ...data }, signal);
|
|
300
|
+
async function refresh(signal) { const value = await request('list', {}, signal); if (alive.current) setHistory(value.runs); }
|
|
301
|
+
useEffect(() => {
|
|
302
|
+
alive.current = true;
|
|
303
|
+
return () => {
|
|
304
|
+
alive.current = false; reading.current++;
|
|
305
|
+
if (active.current) {
|
|
306
|
+
active.current.abort();
|
|
307
|
+
const item = runRef.current;
|
|
308
|
+
if (item) void request('stop', { runId: item.id }).catch(() => {});
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}, []);
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
if (!run || run.status !== 'busy' || busy) return;
|
|
314
|
+
const controller = new AbortController();
|
|
315
|
+
const timer = setInterval(() => { void request('get', { runId: run.id }, controller.signal).then(value => { if (!controller.signal.aborted) accept(value.run); }).catch(() => {}); }, 750);
|
|
316
|
+
return () => { clearInterval(timer); controller.abort(); };
|
|
317
|
+
}, [run?.id, run?.status, busy]);
|
|
318
|
+
async function task(work) {
|
|
319
|
+
if (active.current) return;
|
|
320
|
+
const controller = new AbortController(); active.current = controller;
|
|
321
|
+
setBusy(true); setError(''); setNotice('');
|
|
322
|
+
try { await work(controller.signal); }
|
|
323
|
+
catch (e) {
|
|
324
|
+
if (!alive.current) return;
|
|
325
|
+
if (!controller.signal.aborted) setError(e.message || L('操作失败', 'Operation failed'));
|
|
326
|
+
const item = runRef.current;
|
|
327
|
+
if (item) { try { accept((await request('get', { runId: item.id })).run); } catch { /* Keep visible results. */ } }
|
|
328
|
+
} finally {
|
|
329
|
+
if (active.current === controller) active.current = null;
|
|
330
|
+
if (alive.current) setBusy(false);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function configure(value) {
|
|
334
|
+
if (active.current || !canLeave()) return;
|
|
335
|
+
setMode(value); setLimit(value === 'review' ? 1 : 3); accept(null); setPatches([]); setBackups([]); setAnswer('');
|
|
336
|
+
return task(async signal => {
|
|
337
|
+
const results = await Promise.allSettled([request('options', {}, signal), refresh(signal)]);
|
|
338
|
+
if (signal.aborted || !alive.current) return;
|
|
339
|
+
const available = results[0];
|
|
340
|
+
if (available.status === 'rejected') throw available.reason;
|
|
341
|
+
const models = available.value.routes;
|
|
342
|
+
setRoutes(models);
|
|
343
|
+
const preferred = models.findIndex(r => r.provider === project.modelRoute?.provider && r.model === project.modelRoute?.model);
|
|
344
|
+
setRoute(models.length ? String(Math.max(0, preferred)) : '');
|
|
345
|
+
if (!models.length) setNotice(L('先在 DSH 的模型设置中配置可用模型,再点“刷新模型”。成品仍可直接下载。', 'Configure a model in DSH, then refresh models. Your finished files remain available.'));
|
|
346
|
+
if (results[1].status === 'rejected') throw results[1].reason;
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function canLeave() {
|
|
350
|
+
const item = runRef.current, question = item?.questions.at(-1);
|
|
351
|
+
return !(item?.mode === 'practice' && question && !question.feedback && answer.trim() && answer.trim() !== (question.answer || '')) || window.confirm(L('当前回答尚未提交,离开会丢失。继续吗?', 'Your answer has not been submitted and will be lost. Continue?'));
|
|
352
|
+
}
|
|
353
|
+
async function advance(item, signal, response) {
|
|
354
|
+
let next = (await request('step', { runId: item.id, confirmed: true, ...(response === undefined ? {} : { answer: response }) }, signal)).run;
|
|
355
|
+
accept(next);
|
|
356
|
+
// Only this explicit Start click authorizes the configured review rounds.
|
|
357
|
+
while (next.mode === 'review' && next.status === 'ready' && !next.stale && !signal.aborted && current.current.project.revision === next.revision) {
|
|
358
|
+
next = (await request('step', { runId: next.id, confirmed: true }, signal)).run; accept(next);
|
|
359
|
+
}
|
|
360
|
+
await refresh(signal);
|
|
361
|
+
if (alive.current && response !== undefined) setAnswer('');
|
|
362
|
+
}
|
|
363
|
+
function start() {
|
|
364
|
+
if (current.current.blocked) return;
|
|
365
|
+
return task(async signal => {
|
|
366
|
+
const model = routes[Number(route)]; if (!model) throw new Error(L('请选择模型', 'Choose a model'));
|
|
367
|
+
reading.current++;
|
|
368
|
+
const item = (await request('create', { confirmed: true, mode, ...model, difficulty, audience, limit, material,
|
|
369
|
+
language: languageOf(), ...(scope === 'current' ? { slideId: current.current.selected } : {}) }, signal)).run;
|
|
370
|
+
accept(item); await advance(item, signal);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
function stop() {
|
|
374
|
+
active.current?.abort();
|
|
375
|
+
if (runRef.current) void request('stop', { runId: runRef.current.id }).then(value => accept(value.run)).catch(e => { if (alive.current) setError(e.message); });
|
|
376
|
+
setNotice(L('已请求停止。已完成的结果保留,本次调用仍可能计费。', 'Stop requested. Completed results are kept; the current call may still be billed.'));
|
|
377
|
+
}
|
|
378
|
+
function finish() { return task(async signal => { accept((await request('finish', { runId: run.id }, signal)).run); await refresh(signal); }); }
|
|
379
|
+
function openReport(id) { if (!canLeave()) return; return task(async signal => { const value = (await request('get', { runId: id }, signal)).run; accept(value); setMode(value.mode); setAnswer(value.questions.at(-1)?.answer || ''); setPatches([]); setBackups([]); }); }
|
|
380
|
+
function removeReport() {
|
|
381
|
+
if (!window.confirm(L('删除这次本地演练记录?幻灯片成品不受影响。', 'Delete this local rehearsal record? Presentation files are kept.'))) return;
|
|
382
|
+
return task(async signal => { await request('delete', { runId: run.id }, signal); accept(null); await refresh(signal); });
|
|
383
|
+
}
|
|
384
|
+
function exportReport() {
|
|
385
|
+
const url = new URL('api/dsh-ppt/download', document.baseURI);
|
|
386
|
+
for (const [key, value] of Object.entries({ id: project.id, kind: 'coaching', revision: project.revision, run: run.id })) url.searchParams.set(key, String(value));
|
|
387
|
+
const link = document.createElement('a'); link.href = url.href; link.download = ''; link.hidden = true; document.body.append(link); link.click(); link.remove();
|
|
388
|
+
}
|
|
389
|
+
function applySelected() {
|
|
390
|
+
if (current.current.blocked || stale) return;
|
|
391
|
+
return task(async signal => {
|
|
392
|
+
const value = await request('apply', { runId: run.id, confirmed: true, selected: patches, backup: backups }, signal);
|
|
393
|
+
if (alive.current) onAdopt(value.project);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
async function uploadMaterial(event) {
|
|
397
|
+
const file = event.target.files?.[0]; event.target.value = ''; if (!file) return;
|
|
398
|
+
const ticket = ++reading.current;
|
|
399
|
+
if (!/\.(txt|md)$/i.test(file.name) || file.size > 100000) { setError(L('请选择 100 KB 以内的 TXT / Markdown 文件。', 'Choose a TXT / Markdown file up to 100 KB.')); return; }
|
|
400
|
+
try {
|
|
401
|
+
const value = await file.text();
|
|
402
|
+
if (!alive.current || ticket !== reading.current) return;
|
|
403
|
+
if (value.length > 20000) throw new Error(L('补充材料最多 20000 字符。', 'Supporting material: up to 20,000 characters.'));
|
|
404
|
+
setMaterial(value); setError('');
|
|
405
|
+
} catch (e) { if (alive.current && ticket === reading.current) setError(e.message); }
|
|
406
|
+
}
|
|
407
|
+
function toggle(set, values, id) { set(values.includes(id) ? values.filter(v => v !== id) : [...values, id]); }
|
|
408
|
+
function pageButton(id) {
|
|
409
|
+
const index = project.slides.findIndex(s => s.id === id);
|
|
410
|
+
return h('button', { disabled: blocked || index < 0, onClick: () => onChoose(id) }, L('查看第 ' + (index + 1) + ' 页', 'View slide ' + (index + 1)));
|
|
411
|
+
}
|
|
412
|
+
function source(card) { return card.reference ? h('blockquote', null, h('small', { className: 'muted' }, card.reference === 'material' ? L('补充材料中的原文', 'Quote from supporting material') : L('幻灯片中的原文', 'Quote from slides')), h('pre', null, card.quote)) : h('p', { className: 'muted' }, L('未匹配到材料原文,请核对或补充依据。', 'No matching source quote. Verify or add supporting evidence.')); }
|
|
413
|
+
const last = run?.questions.at(-1);
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
if (!last || last.feedback || !answer.trim() || answer.trim() === (last.answer || '')) return;
|
|
416
|
+
const warn = event => { event.preventDefault(); event.returnValue = ''; };
|
|
417
|
+
window.addEventListener('beforeunload', warn); return () => window.removeEventListener('beforeunload', warn);
|
|
418
|
+
}, [run?.id, last?.id, last?.feedback, last?.answer, answer]);
|
|
419
|
+
return h('section', { className: 'card coaching', 'aria-label': L('可选演练', 'Optional rehearsal'), onKeyDown: e => { if (e.key === 'Escape' || (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') { e.stopPropagation(); if (e.key.toLowerCase() === 's') e.preventDefault(); } } },
|
|
420
|
+
h('h3', null, L('想再准备充分一点?', 'Want to prepare further?')),
|
|
421
|
+
h('p', { className: 'muted' }, L('成品已可下载。以下两项按需开启,不影响直接交付。', 'Your files are ready to download. Both options below are optional.')),
|
|
422
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy, 'aria-pressed': mode === 'review', onClick: () => configure('review') }, L('AI 预审', 'AI review')), h('button', { disabled: busy, 'aria-pressed': mode === 'practice', onClick: () => configure('practice') }, L('模拟答辩', 'Rehearsal')),
|
|
423
|
+
mode && h('button', { disabled: busy, onClick: () => { if (canLeave()) { setMode(''); accept(null); setAnswer(''); } } }, L('收起', 'Collapse'))),
|
|
424
|
+
mode && h(React.Fragment, null,
|
|
425
|
+
error && h('div', { role: 'alert', className: 'notice error' }, error),
|
|
426
|
+
notice && h('div', { role: 'status', className: 'notice' }, notice),
|
|
427
|
+
busy && h('div', { role: 'status', className: 'tools' }, L('正在处理…可以继续预览或下载成品。', 'Working… You can still preview or download your presentation.'), h('button', { onClick: stop }, L('停止', 'Stop'))),
|
|
428
|
+
!run && h(React.Fragment, null,
|
|
429
|
+
h('p', null, mode === 'review' ? L('AI 根据材料模拟质疑与回答,最多保留 5 个值得改进的问题。', 'AI simulates questions and answers based on your material, keeping up to five useful findings.') : L('AI 一次问一题,你来回答;可随时结束并整理已完成的问答。', 'AI asks one question at a time. You answer and can finish at any point.')),
|
|
430
|
+
h('div', { className: 'coaching-grid' },
|
|
431
|
+
h('label', null, L('模型', 'Model'), h('select', { 'aria-label': L('演练模型', 'Rehearsal model'), value: route, disabled: busy, onChange: e => setRoute(e.target.value) }, !routes.length && h('option', { value: '' }, L('暂无可用模型', 'No configured model')), routes.map((r, i) => h('option', { key: i, value: i }, r.label)))),
|
|
432
|
+
h('label', null, L('听众', 'Audience'), h('select', { 'aria-label': L('听众', 'Audience'), value: audience, disabled: busy, onChange: e => setAudience(e.target.value) }, [['general', L('一般听众', 'General audience')], ['management', L('管理层 / 客户', 'Management / clients')], ['academic', L('答辩评委', 'Academic panel')]].map(([v, label]) => h('option', { key: v, value: v }, label)))),
|
|
433
|
+
h('label', null, L('提问强度', 'Difficulty'), h('select', { 'aria-label': L('提问强度', 'Difficulty'), value: difficulty, disabled: busy, onChange: e => setDifficulty(e.target.value) }, [['gentle', L('温和', 'Gentle')], ['normal', L('普通', 'Normal')], ['strict', L('严格', 'Strict')]].map(([v, label]) => h('option', { key: v, value: v }, label)))),
|
|
434
|
+
h('label', null, mode === 'review' ? L('预审轮数', 'Review rounds') : L('答辩题数', 'Questions'), h('select', { 'aria-label': mode === 'review' ? L('预审轮数', 'Review rounds') : L('答辩题数', 'Questions'), value: limit, disabled: busy, onChange: e => setLimit(Number(e.target.value)) }, Array.from({ length: mode === 'review' ? 3 : 5 }, (_, i) => h('option', { key: i, value: i + 1 }, String(i + 1))))),
|
|
435
|
+
h('label', null, L('检查范围', 'Scope'), h('select', { 'aria-label': L('检查范围', 'Scope'), value: scope, disabled: busy, onChange: e => setScope(e.target.value) }, h('option', { value: 'all' }, L('整个工程', 'Whole presentation')), h('option', { value: 'current' }, L('当前页', 'Current slide'))))),
|
|
436
|
+
h('label', { htmlFor: 'ppt-coach-material' }, L('补充材料(可选)', 'Supporting material (optional)')),
|
|
437
|
+
h('textarea', { id: 'ppt-coach-material', rows: 3, maxLength: 20000, value: material, disabled: busy, onChange: e => { reading.current++; setMaterial(e.target.value); } }),
|
|
438
|
+
h('label', null, L('或导入 TXT / Markdown', 'Or import TXT / Markdown'), h('input', { type: 'file', accept: '.txt,.md,text/plain,text/markdown', disabled: busy, onChange: uploadMaterial })),
|
|
439
|
+
h('p', { className: 'muted' }, L('将所选页面的文字、图表数据、备注及补充材料发送给所选 DSH 模型,不发送图片文件。最多 ' + maxCalls + ' 次插件调用;模型服务自身的重试与计费规则仍适用。', 'Sends selected slide text, chart data, notes and supporting material to the chosen DSH model. Image files are excluded. Up to ' + maxCalls + ' plugin calls; provider retry and billing rules still apply.')),
|
|
440
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy || blocked || !routes.length, onClick: start }, mode === 'review' ? L('开始 AI 预审', 'Start AI review') : L('开始模拟答辩', 'Start rehearsal')), h('button', { disabled: busy, onClick: () => configure(mode) }, L('刷新模型', 'Refresh models'))),
|
|
441
|
+
blocked && h('p', { className: 'muted' }, L('请先保存或取消幻灯片修改。', 'Save or cancel slide edits first.'))),
|
|
442
|
+
run && h(React.Fragment, null,
|
|
443
|
+
h('h3', null, modeName(run.mode) + ' · ' + statusName(run.status)),
|
|
444
|
+
h('p', { className: 'muted' }, L('修订 ', 'Revision ') + run.revision + ' · ' + run.route.provider + ' / ' + run.route.model + ' · ' + L('调用 ', 'Calls ') + run.usedCalls + '/' + run.maxCalls),
|
|
445
|
+
h('p', { className: 'muted' }, L('AI 意见不等于事实核验,也不代表真实听众的评价。请先看原文与改动,再决定是否采纳。', 'AI suggestions are not fact checks or predictions of audience feedback. Compare sources and edits before adopting them.')),
|
|
446
|
+
stale && h('div', { role: 'alert', className: 'notice' }, L('工程已经修改。旧报告仍可导出,但不能继续调用或采纳;请重新开始。', 'The presentation changed. You can export this report, but cannot continue or apply it. Start a new rehearsal.')),
|
|
447
|
+
run.error && h('p', { className: 'muted' }, languageOf() === 'en' ? run.error.split(' / ').at(-1) : run.error.split(' / ')[0]),
|
|
448
|
+
run.findings.map(f => {
|
|
449
|
+
const slide = project.slides.find(s => s.id === f.slideId);
|
|
450
|
+
return h('article', { key: f.id, className: 'card' }, h('strong', null, kindName(f.kind) + ' · ' + f.issue), h('div', { className: 'tools' }, pageButton(f.slideId)),
|
|
451
|
+
h('p', null, f.question), h('p', null, f.answer), h('p', null, f.suggestion), source(f),
|
|
452
|
+
f.patch && h(React.Fragment, null, h('details', null, h('summary', null, L('比较原文和建议', 'Compare before and after')), Object.entries(f.patch).map(([key, value]) => h('div', { key }, h('strong', null, t(fields.find(([name]) => name === key)?.[1] || key)), h('div', { className: 'before-after' }, h('div', null, h('small', null, L('原文', 'Before')), h('pre', null, Array.isArray(slide?.[key]) ? slide[key].join('\n') : slide?.[key] || '')), h('div', null, h('small', null, L('建议', 'After')), h('pre', null, Array.isArray(value) ? value.join('\n') : value)))))),
|
|
453
|
+
h('label', { className: 'choice' }, h('input', { type: 'checkbox', disabled: busy || stale, checked: patches.includes(f.id), onChange: () => toggle(setPatches, patches, f.id) }), L('采纳这项表达修改', 'Adopt this expression edit'))),
|
|
454
|
+
h('label', { className: 'choice' }, h('input', { type: 'checkbox', disabled: busy || stale, checked: backups.includes(f.id), onChange: () => toggle(setBackups, backups, f.id) }), L('选为备用问答页', 'Add as a backup Q&A slide')));
|
|
455
|
+
}),
|
|
456
|
+
run.mode === 'review' && run.status === 'complete' && !run.findings.length && h('p', null, L('本次未提出明显问题。仍建议检查事实、字体和最终 PPTX。', 'No findings this time. Still check facts, fonts and the final PPTX.')),
|
|
457
|
+
run.questions.map((q, i) => h('article', { key: q.id, className: 'card' }, h('strong', null, (i + 1) + '. ' + q.question), h('div', { className: 'tools' }, pageButton(q.slideId)), q.answer && h('p', null, L('你的回答:', 'Your answer: ') + q.answer), q.feedback && h('p', null, q.feedback), q.needsEvidence && h('p', { className: 'muted' }, L('待补充依据', 'Evidence needed')), source(q),
|
|
458
|
+
q.answer && h('label', { className: 'choice' }, h('input', { type: 'checkbox', disabled: busy || stale, checked: backups.includes(q.id), onChange: () => toggle(setBackups, backups, q.id) }), L('选为备用问答页', 'Add as a backup Q&A slide')))),
|
|
459
|
+
run.mode === 'practice' && last && !last.feedback && run.status !== 'complete' && !stale && h(React.Fragment, null,
|
|
460
|
+
h('label', { htmlFor: 'ppt-coach-answer' }, L('你的回答', 'Your answer')), h('textarea', { id: 'ppt-coach-answer', maxLength: 4000, rows: 4, value: answer, disabled: busy, onChange: e => setAnswer(e.target.value) }),
|
|
461
|
+
h('button', { disabled: busy || blocked || !answer.trim() || run.usedCalls >= run.maxCalls, onClick: () => task(signal => advance(run, signal, answer)) }, L('提交回答,继续', 'Submit answer and continue'))),
|
|
462
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy, onClick: exportReport }, L('下载问答与材料清单', 'Download Q&A and evidence checklist')),
|
|
463
|
+
h('button', { disabled: busy || blocked || stale || !(patches.length + backups.length), onClick: applySelected }, L('将所选内容保存为副本', 'Save selected changes as a copy')),
|
|
464
|
+
run.status !== 'complete' && h('button', { disabled: busy || run.status === 'busy', onClick: finish }, L('结束并整理已有结果', 'Finish with current results')),
|
|
465
|
+
h('button', { disabled: busy, onClick: () => configure(run.mode) }, L('重新开始', 'Start again')),
|
|
466
|
+
h('button', { disabled: busy || run.status === 'busy', onClick: removeReport }, L('删除本次记录', 'Delete this record'))),
|
|
467
|
+
h('p', { className: 'muted' }, L('采纳后会生成新副本,原稿保留;副本中可“撤销上次修改”。备用页包含 AI 演练标记,请核对后再对外展示。', 'Adoption creates a copy and keeps the original. Undo last change also works in the copy. Backup slides identify AI rehearsal content; verify before presenting.'))),
|
|
468
|
+
history.length > 0 && h('details', null, h('summary', null, L('本机历史记录(', 'Local history (') + history.length + L(')', ')')), h('div', { className: 'project-list' }, history.map(item => h('button', { key: item.id, disabled: busy, onClick: () => openReport(item.id) }, modeName(item.mode) + ' · ' + L('修订 ', 'Revision ') + item.revision + ' · ' + new Date(item.createdAt).toLocaleString(languageOf() === 'en' ? 'en-US' : 'zh-CN')))))));
|
|
469
|
+
}
|
|
470
|
+
const dataCss=`.pptw .data-workbench{margin-top:18px}.pptw .data-workbench details{margin:12px 0}.pptw .data-workbench summary{cursor:pointer;font-weight:600}.pptw .data-workbench pre,.pptw .data-workbench code{white-space:pre-wrap;overflow-wrap:anywhere;font-size:13px;max-height:220px;overflow:auto}.pptw .data-input-row{margin:15px 0}.pptw .data-input-controls{display:grid;grid-template-columns:minmax(0,1fr) 115px;gap:12px;align-items:center}.pptw .data-input-controls input[type=range]{accent-color:var(--dsw-alias-brand-primary,#2563eb)}.pptw .data-before-after{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px}.pptw .data-before-after pre{padding:10px;border:1px solid var(--dsw-alias-divider-default,#b8c0cc);border-radius:8px}.pptw .data-copy{display:flex;gap:8px;align-items:center}.pptw .data-copy input{width:auto}@media(max-width:640px){.pptw .data-before-after{grid-template-columns:minmax(0,1fr)}.pptw .data-input-controls{grid-template-columns:minmax(0,1fr) 100px}}`;
|
|
471
|
+
function DataPanel({project,blocked,incoming,onParameters,onDirty,onBusy,onAdopt,onChoose,onDownload}) {
|
|
472
|
+
const L=(zh,en)=>languageOf()==='en'?en:zh,model=project.dataModel;
|
|
473
|
+
const baseline=Object.fromEntries(model.metrics.filter(m=>m.kind==='input').map(m=>[m.id,String(m.value)]));
|
|
474
|
+
const [parameters,setParameters]=useState(baseline),[updates,setUpdates]=useState({}),[sourceId,setSourceId]=useState(model.sources[0]?.id||'');
|
|
475
|
+
const [metricId,setMetricId]=useState(model.metrics[0]?.id||''),[preview,setPreview]=useState(null),[error,setError]=useState(''),[busy,setBusy]=useState(false),[valid,setValid]=useState(true),[saveAs,setSaveAs]=useState(true),[readingFile,setReadingFile]=useState(false);
|
|
476
|
+
const pending=useRef(null),alive=useRef(true),reading=useRef(0),latest=useRef(''),guard=useRef(false);
|
|
477
|
+
const numeric=Object.fromEntries(Object.entries(parameters).map(([id,value])=>[id,value.trim()===''?null:Number(value)]));
|
|
478
|
+
const inputsValid=model.metrics.filter(m=>m.kind==='input').every(m=>typeof numeric[m.id]==='number'&&Number.isFinite(numeric[m.id])&&numeric[m.id]>=m.min&&numeric[m.id]<=m.max&&Math.abs((numeric[m.id]-m.min)/m.step-Math.round((numeric[m.id]-m.min)/m.step))<=1e-6);
|
|
479
|
+
const body={parameters:numeric,sourceUpdates:Object.values(updates)},signature=JSON.stringify(body);latest.current=signature;
|
|
480
|
+
const changed=readingFile||!valid||Object.entries(baseline).some(([id,value])=>Number(parameters[id])!==Number(value)||parameters[id].trim()==='')||Object.keys(updates).length>0;
|
|
481
|
+
useEffect(()=>{onDirty(changed);return()=>onDirty(false);},[changed]);
|
|
482
|
+
useEffect(()=>{setPreview(null);},[signature]);
|
|
483
|
+
useEffect(()=>{if(incoming){setParameters(Object.fromEntries(Object.entries(incoming.parameters).map(([id,value])=>[id,Number.isFinite(value)?String(value):''])));setValid(incoming.valid!==false);}},[incoming]);
|
|
484
|
+
useEffect(()=>{alive.current=true;return()=>{alive.current=false;reading.current++;pending.current?.abort();onBusy(false);};},[]);
|
|
485
|
+
function changeParameter(id,value){const next={...parameters,[id]:value};setParameters(next);setValid(true);setPreview(null);setError('');onParameters(Object.fromEntries(Object.entries(next).map(([key,raw])=>[key,raw.trim()===''?NaN:Number(raw)])));}
|
|
486
|
+
function reset(){reading.current++;setParameters(baseline);setUpdates({});setPreview(null);setError('');setValid(true);onParameters(Object.fromEntries(Object.entries(baseline).map(([id,value])=>[id,Number(value)])));}
|
|
487
|
+
async function task(work){
|
|
488
|
+
if(guard.current||blocked||readingFile)return;guard.current=true;setBusy(true);onBusy(true);setError('');
|
|
489
|
+
const controller=new AbortController();pending.current=controller;
|
|
490
|
+
try{await work(controller.signal);}catch(reason){if(alive.current&&!controller.signal.aborted)setError(reason.message||L('操作失败','Operation failed'));}
|
|
491
|
+
finally{pending.current=null;guard.current=false;if(alive.current){setBusy(false);onBusy(false);}}
|
|
492
|
+
}
|
|
493
|
+
function inspect(){const sent=signature;return task(async signal=>{const value=await action({operation:'data-preview',id:project.id,expectedRevision:project.revision,...body},signal);if(alive.current&&latest.current===sent)setPreview({...value,signature:sent});});}
|
|
494
|
+
function apply(){if(!preview||preview.signature!==signature)return;const sent=signature;return task(async signal=>{const value=await action({operation:'data-apply',id:project.id,expectedRevision:project.revision,...body,confirmed:true,previewToken:preview.token,saveAs},signal);if(alive.current&&latest.current===sent){onDirty(false);onAdopt(value.project);}});}
|
|
495
|
+
async function importSource(event){
|
|
496
|
+
const file=event.target.files?.[0];event.target.value='';if(!file)return;const stamp=++reading.current,target=sourceId;
|
|
497
|
+
if(file.size>1024*1024||!['csv','tsv','txt','md'].includes(file.name.split('.').at(-1)?.toLowerCase())){setError(L('请选择 1 MiB 内的 CSV、TSV、TXT 或 Markdown。','Choose CSV, TSV, TXT or Markdown up to 1 MiB.'));return;}
|
|
498
|
+
setReadingFile(true);try{const content=await file.text();if(!alive.current||stamp!==reading.current)return;const ext=file.name.split('.').at(-1).toLowerCase();setUpdates(old=>({...old,[target]:{id:target,format:ext==='csv'||ext==='tsv'?ext:'text',content}}));setPreview(null);setError('');}catch{if(alive.current)setError(L('无法读取材料,请重试。','Could not read source. Try again.'));}finally{if(alive.current)setReadingFile(false);}
|
|
499
|
+
}
|
|
500
|
+
async function importScenario(event){
|
|
501
|
+
const file=event.target.files?.[0];event.target.value='';if(!file)return;const stamp=++reading.current;
|
|
502
|
+
setReadingFile(true);
|
|
503
|
+
try{
|
|
504
|
+
if(file.size>32000)throw new Error(L('推演参数文件过大。','Scenario parameter file is too large.'));
|
|
505
|
+
const packet=JSON.parse(await file.text());if(!alive.current||stamp!==reading.current)return;
|
|
506
|
+
if(packet.schemaVersion!==1||packet.deckId!==project.deckId||packet.revision!==project.revision||packet.fingerprint!==model.fingerprint||!packet.parameters||typeof packet.parameters!=='object'||Array.isArray(packet.parameters)||Object.keys(packet.parameters).some(id=>!Object.hasOwn(baseline,id))||Object.values(packet.parameters).some(value=>typeof value!=='number'||!Number.isFinite(value)))throw new Error(L('参数来自其他工程、旧版本或格式无效,请重新导出。','Scenario is stale, belongs to another project, or is invalid. Export it again.'));
|
|
507
|
+
const next={...baseline,...Object.fromEntries(Object.entries(packet.parameters).map(([id,value])=>[id,String(value)]))};setParameters(next);setValid(true);setPreview(null);onParameters(Object.fromEntries(Object.entries(next).map(([id,value])=>[id,Number(value)])));setError('');
|
|
508
|
+
}catch(reason){if(alive.current)setError(reason.message);}finally{if(alive.current)setReadingFile(false);}
|
|
509
|
+
}
|
|
510
|
+
const metric=model.metrics.find(m=>m.id===metricId),source=model.sources.find(s=>s.id===sourceId),replacement=updates[sourceId];
|
|
511
|
+
const format=(value,m)=>new Intl.NumberFormat(languageOf()==='en'?'en-US':'zh-CN',{style:m.format.style==='percent'?'percent':'decimal',minimumFractionDigits:m.format.digits,maximumFractionDigits:m.format.digits}).format(value)+(m.format.unit||'');
|
|
512
|
+
const display=value=>typeof value==='string'?value:JSON.stringify(value,null,2),disabled=busy||blocked||readingFile;
|
|
513
|
+
return h('section',{className:'card data-workbench','aria-label':L('数据溯源与现场推演','Data lineage and what-if')},
|
|
514
|
+
h('style',null,dataCss),
|
|
515
|
+
h('h3',null,L('数据溯源与现场推演','Data lineage and what-if')),
|
|
516
|
+
h('p',{className:'muted'},L('点预览中的数字可追问来源。只有明确声明的假设可调;来源不等于事实已核验。','Click numbers in the preview to inspect their lineage. Only declared assumptions are adjustable. Lineage is not factual verification.')),
|
|
517
|
+
h('details',null,h('summary',null,L('数字来自哪里','Where the numbers come from')),
|
|
518
|
+
h('label',null,L('指标','Metric'),h('select',{value:metricId,disabled,onChange:event=>setMetricId(event.target.value)},model.metrics.map(m=>h('option',{key:m.id,value:m.id},m.label+' ['+m.id+']')))),
|
|
519
|
+
metric&&h('div',{className:'data-evidence'},h('strong',null,metric.label+' = '+format(model.values[metric.id],metric)),
|
|
520
|
+
metric.kind==='source'?h(React.Fragment,null,h('p',null,metric.evidence.name+' · '+metric.evidence.locator),h('pre',null,metric.evidence.excerpt),h('details',null,h('summary',null,L('来源快照校验值','Source snapshot checksum')),h('code',null,metric.evidence.sha256))):metric.kind==='input'?h('p',null,L('用户假设','User assumption')+(metric.note?' · '+metric.note:'')):h(React.Fragment,null,h('pre',null,'= '+metric.formula),h('div',{className:'tools'},metric.dependencies.map(id=>h('button',{key:id,disabled,onClick:()=>setMetricId(id)},model.metrics.find(m=>m.id===id).label))))),
|
|
521
|
+
h('button',{disabled:disabled||changed,onClick:()=>onDownload('data')},L('下载溯源与假设报告','Download lineage and assumptions'))),
|
|
522
|
+
model.metrics.some(m=>m.kind==='input')&&h('details',{open:true},h('summary',null,L('现场推演参数','What-if assumptions')),
|
|
523
|
+
model.metrics.filter(m=>m.kind==='input').map(m=>h('div',{key:m.id,className:'data-input-row'},h('label',{htmlFor:'ppt-data-'+m.id},m.label,h('small',{className:'muted'},' · '+L('假设','Assumption')+(m.note?' · '+m.note:''))),h('div',{className:'data-input-controls'},h('input',{type:'range',min:m.min,max:m.max,step:m.step,value:Number(parameters[m.id]),disabled,'aria-label':m.label+' '+L('滑杆','slider'),onChange:event=>changeParameter(m.id,event.target.value)}),h('input',{id:'ppt-data-'+m.id,type:'number',min:m.min,max:m.max,step:m.step,value:parameters[m.id],disabled,onChange:event=>changeParameter(m.id,event.target.value)})))),
|
|
524
|
+
h('label',null,L('导入离线 HTML 保存的推演参数','Import scenario parameters saved in offline HTML'),h('input',{type:'file',accept:'.json,application/json',disabled,onChange:importScenario}))),
|
|
525
|
+
model.sources.length>0&&h('details',null,h('summary',null,L('更新来源材料','Update source material')),
|
|
526
|
+
h('p',{className:'muted'},L('先导入或粘贴新材料,预览影响后再确认;不会自动监视或修改原文件。表格可从 Excel 导出 CSV。','Import or paste new material, then preview the impact before confirming. Original source files are not watched or modified. Export Excel tables as CSV.')),
|
|
527
|
+
h('label',null,L('替换来源','Replace source'),h('select',{value:sourceId,disabled,onChange:event=>setSourceId(event.target.value)},model.sources.map(s=>h('option',{key:s.id,value:s.id},s.name)))),
|
|
528
|
+
h('label',null,L('导入替换材料','Import replacement material'),h('input',{type:'file',accept:source?.kind==='table'?'.csv,.tsv':'.txt,.md',disabled,onChange:importSource})),
|
|
529
|
+
source?.kind==='table'&&h('label',null,L('分隔格式','Delimiter format'),h('select',{value:replacement?.format||'csv',disabled,onChange:event=>{setUpdates(old=>({...old,[sourceId]:{id:sourceId,format:event.target.value,content:replacement?.content||''}}));setPreview(null);}},h('option',{value:'csv'},'CSV'),h('option',{value:'tsv'},'TSV'))),
|
|
530
|
+
h('label',null,L('或粘贴内容','Or paste content'),h('textarea',{rows:4,maxLength:1048576,value:replacement?.content??'',disabled,onChange:event=>{setUpdates(old=>({...old,[sourceId]:{id:sourceId,format:source.kind==='table'?replacement?.format||'csv':'text',content:event.target.value}}));setPreview(null);setError('');}})),
|
|
531
|
+
replacement&&h('button',{disabled,onClick:()=>{setUpdates(old=>{const next={...old};delete next[sourceId];return next;});setPreview(null);}},L('取消此来源更新','Cancel this source update'))),
|
|
532
|
+
changed&&h('p',{className:'dirty',role:'status'},L('推演或材料尚未保存,当前 PPTX 仍是已保存版本。先预览差异并确认,或恢复参数后下载。','Unsaved scenario or source changes. The PPTX still contains saved values. Preview and confirm, or reset before downloading.')),
|
|
533
|
+
(!valid||!inputsValid)&&h('p',{className:'notice error',role:'alert'},L('参数无法计算,请检查范围、步长或除零,再恢复或修改。','Cannot calculate these parameters. Check ranges, steps or division by zero; adjust or reset.')),
|
|
534
|
+
error&&h('p',{className:'notice error',role:'alert'},error),
|
|
535
|
+
h('div',{className:'tools'},h('button',{disabled:disabled||!changed||!valid||!inputsValid,onClick:inspect},L('预览差异','Preview changes')),h('button',{disabled:disabled||!changed,onClick:reset},L('恢复已保存数据','Reset to saved data'))),
|
|
536
|
+
preview&&preview.signature===signature&&h('div',{className:'data-diff'},h('h4',null,L('确认前核对','Review before confirming')),
|
|
537
|
+
!preview.changed?h('p',null,L('内容没有变化。','No content changes.')):h(React.Fragment,null,
|
|
538
|
+
h('ul',null,preview.changes.map(change=>h('li',{key:change.id},h('strong',null,change.label+': '),change.beforeText+' → '+change.afterText,change.before===change.after&&' · '+L('来源已更新','Source updated')))),
|
|
539
|
+
h('h4',null,L('受影响页面','Affected slides')),
|
|
540
|
+
!preview.affectedSlides.length&&h('p',{className:'muted'},L('指标尚未绑定到页面,只更新数据模型。','Metrics are not bound to slides; only the data model changes.')),
|
|
541
|
+
preview.affectedSlides.map(slide=>h('details',{key:slide.id},h('summary',null,(slide.page)+'. '+slide.title),h('button',{disabled,onClick:()=>onChoose(slide.id)},L('查看页面','View slide')),slide.evidenceChanged&&h('p',null,L('关联的来源快照有变化。','A linked source snapshot changed.')),slide.fields.map(field=>h('div',{key:field.field},h('strong',null,t(fields.find(([key])=>key===field.field)?.[1]||field.field)),h('div',{className:'data-before-after'},h('pre',null,L('之前:','Before: ')+display(field.before)),h('pre',null,L('之后:','After: ')+display(field.after))))))),
|
|
542
|
+
h('label',{className:'data-copy'},h('input',{type:'checkbox',checked:saveAs,disabled,onChange:event=>setSaveAs(event.target.checked)}),L('保存为新副本,保留原稿(推荐)','Save a new copy and keep the original (recommended)')),
|
|
543
|
+
h('p',{className:'muted'},L('PPTX 保存确认后的静态结果,并附公式、来源和假设;HTML 保留交互。JSON 工程包含导入的完整材料,分享前请检查。','PPTX saves confirmed static results with formulas, sources and assumptions; HTML retains interaction. The JSON project contains full imported material; review it before sharing.')),
|
|
544
|
+
h('button',{className:'primary',disabled:disabled||!valid||!inputsValid,onClick:apply},saveAs?L('确认并保存推演副本','Confirm and save scenario copy'):L('确认并更新当前工程','Confirm and update this project')))));
|
|
545
|
+
}
|
|
546
|
+
function Workbench({ locale } = {}) {
|
|
277
547
|
useLanguage(locale);
|
|
278
|
-
const [projects, setProjects] = useState([]), [project, setProject] = useState(null), [selected, setSelected] = useState('');
|
|
279
|
-
const [draft, setDraft] = useState({}), [image, setImage] = useState(null), [dirty, setDirty] = useState(false);
|
|
280
|
-
const [
|
|
281
|
-
const [
|
|
282
|
-
const [
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
548
|
+
const [projects, setProjects] = useState([]), [project, setProject] = useState(null), [selected, setSelected] = useState('');
|
|
549
|
+
const [draft, setDraft] = useState({}), [image, setImage] = useState(null), [dirty, setDirty] = useState(false);
|
|
550
|
+
const [dataDirty,setDataDirty]=useState(false),[incomingData,setIncomingData]=useState(null);
|
|
551
|
+
const [busy, setBusy] = useState(false), [job, setJob] = useState(''), [message, setMessage] = useState(''), [error, setError] = useState('');
|
|
552
|
+
const [mode, setMode] = useState('html'), [raster, setRaster] = useState('');
|
|
553
|
+
const [conflict, setConflict] = useState(false), [overlaps, setOverlaps] = useState([]);
|
|
554
|
+
const frame = useRef(null), previewBox = useRef(null), fieldRefs = useRef({}), alive = useRef(true), operations = useRef(new Set());
|
|
555
|
+
const imageLoader = useRef(null);
|
|
556
|
+
if (!imageLoader.current) imageLoader.current = createImageLoader();
|
|
557
|
+
const imagePending = imageLoader.current.pending;
|
|
558
|
+
const nonce = useRef(crypto.randomUUID());
|
|
559
|
+
const dataCommand=useRef(0);
|
|
560
|
+
const previewDocument = useMemo(() => project?.html ? editorHtml(project.html, nonce.current) : '', [project?.html]);
|
|
561
|
+
const index = project ? Math.max(0, project.slides.findIndex(s => s.id === selected)) : 0;
|
|
562
|
+
const slide = project?.slides[index];
|
|
563
|
+
function adopt(next, preferred) {
|
|
564
|
+
imageLoader.current.cancel();
|
|
565
|
+
nonce.current=crypto.randomUUID();setDataDirty(false);setIncomingData(null);
|
|
566
|
+
setProject(next);
|
|
567
|
+
const row = next.slides.find(s => s.id === preferred) || next.slides[0];
|
|
568
|
+
setSelected(row.id); setDraft(draftFor(row)); setImage(null); setDirty(false); setRaster(''); setOverlaps([]);
|
|
569
|
+
if (!next.render) setMode('html');
|
|
570
|
+
}
|
|
571
|
+
async function perform(work, success, label = t("正在处理,请稍候…")) {
|
|
572
|
+
setBusy(true); setJob(label); setError(''); setMessage(''); setConflict(false);
|
|
573
|
+
const controller = new AbortController(); operations.current.add(controller);
|
|
574
|
+
try { const result = await work(controller.signal); if (alive.current && success) success(result); }
|
|
575
|
+
catch (e) { if (alive.current) { setError(e.message || t("操作失败")); setConflict(e.status === 409); } }
|
|
576
|
+
finally { operations.current.delete(controller); if (alive.current) setBusy(false); }
|
|
577
|
+
}
|
|
578
|
+
function refreshList() { return perform(signal => action({ operation: 'list' }, signal), value => setProjects(value.projects)); }
|
|
579
|
+
useEffect(() => {
|
|
580
|
+
alive.current = true; const abort = new AbortController();
|
|
581
|
+
action({ operation: 'list' }, abort.signal).then(value => { if (alive.current) setProjects(value.projects) }).catch(e => { if (!abort.signal.aborted) setError(e.message) });
|
|
582
|
+
return () => { alive.current = false; abort.abort(); imageLoader.current.cancel(); for (const operation of operations.current) operation.abort(); };
|
|
583
|
+
}, []);
|
|
584
|
+
useEffect(() => {
|
|
585
|
+
function receive(event) {
|
|
313
586
|
if (event.source !== frame.current?.contentWindow || event.data?.nonce !== nonce.current || mode !== 'html') return;
|
|
587
|
+
if(event.data.type==='dsh-ppt-data'){if(typeof event.data.command==='number'&&event.data.command!==dataCommand.current)return;setIncomingData({parameters:event.data.parameters,valid:event.data.valid});return;}
|
|
314
588
|
if (event.data.type === 'dsh-ppt-shortcut') { handleShortcut(event.data.key); return; }
|
|
315
589
|
if (event.data.type !== 'dsh-ppt-select') return;
|
|
316
|
-
const key = event.data.field;
|
|
317
|
-
const field = fields.find(([field]) => field === key);
|
|
590
|
+
const key = event.data.field;
|
|
591
|
+
const field = fields.find(([field]) => field === key);
|
|
318
592
|
if (field) { fieldRefs.current[key]?.focus(); fieldRefs.current[key]?.scrollIntoView({ block: 'nearest' }); setMessage(t("已定位到") + t(field[1]) + t(",在字段中修改后保存。")); }
|
|
319
|
-
}
|
|
320
|
-
window.addEventListener('message', receive); return () => window.removeEventListener('message', receive);
|
|
321
|
-
}, [mode, project, dirty, busy, imagePending, index, selected, draft, image]);
|
|
322
|
-
useEffect(() => {
|
|
323
|
-
if (mode !== 'html' || !project || !previewBox.current) return;
|
|
324
|
-
// Align iframe edges/dimensions when the host uses fractional text metrics.
|
|
325
|
-
const box = previewBox.current;
|
|
326
|
-
function align() {
|
|
327
|
-
const target = frame.current; if (!target) return;
|
|
328
|
-
const r = box.getBoundingClientRect(), x = r.x + box.clientLeft, y = r.y + box.clientTop;
|
|
329
|
-
target.style.width = box.clientWidth + 'px'; target.style.height = box.clientHeight + 'px';
|
|
330
|
-
target.style.transform = 'translate(' + (Math.ceil(x) - x) + 'px,' + (Math.ceil(y) - y) + 'px)';
|
|
331
|
-
}
|
|
332
|
-
align(); const observer = new ResizeObserver(align); observer.observe(box);
|
|
333
|
-
window.addEventListener('scroll', align, true);
|
|
334
|
-
return () => { observer.disconnect(); window.removeEventListener('scroll', align, true); };
|
|
335
|
-
}, [mode, !!project]);
|
|
336
|
-
function jump() { frame.current?.contentWindow?.postMessage({ type: 'dsh-ppt-jump', nonce: nonce.current, page: index }, '*'); }
|
|
337
|
-
useEffect(() => { jump(); }, [index, project?.revision, mode]);
|
|
338
|
-
useEffect(() => {
|
|
339
|
-
if (mode !== 'pptx' || !project?.render) return;
|
|
340
|
-
const abort = new AbortController(); setRaster('');
|
|
341
|
-
action({ operation: 'page', id: project.id, page: index + 1 }, abort.signal).then(value => setRaster(value.data)).catch(e => { if (!abort.signal.aborted) setError(e.message) });
|
|
342
|
-
return () => abort.abort();
|
|
343
|
-
}, [mode, index, project?.revision]);
|
|
344
|
-
function handleShortcut(key) {
|
|
345
|
-
if
|
|
346
|
-
if (key === '
|
|
347
|
-
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (event.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
function
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
function
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return perform(signal => action({ operation, id: project.id, expectedRevision: project.revision,
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
function
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
if (
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
h('div', { className: '
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
h('div', { className: '
|
|
483
|
-
|
|
593
|
+
}
|
|
594
|
+
window.addEventListener('message', receive); return () => window.removeEventListener('message', receive);
|
|
595
|
+
}, [mode, project, dirty, busy, imagePending, index, selected, draft, image, dataDirty]);
|
|
596
|
+
useEffect(() => {
|
|
597
|
+
if (mode !== 'html' || !project || !previewBox.current) return;
|
|
598
|
+
// Align iframe edges/dimensions when the host uses fractional text metrics.
|
|
599
|
+
const box = previewBox.current;
|
|
600
|
+
function align() {
|
|
601
|
+
const target = frame.current; if (!target) return;
|
|
602
|
+
const r = box.getBoundingClientRect(), x = r.x + box.clientLeft, y = r.y + box.clientTop;
|
|
603
|
+
target.style.width = box.clientWidth + 'px'; target.style.height = box.clientHeight + 'px';
|
|
604
|
+
target.style.transform = 'translate(' + (Math.ceil(x) - x) + 'px,' + (Math.ceil(y) - y) + 'px)';
|
|
605
|
+
}
|
|
606
|
+
align(); const observer = new ResizeObserver(align); observer.observe(box);
|
|
607
|
+
window.addEventListener('scroll', align, true);
|
|
608
|
+
return () => { observer.disconnect(); window.removeEventListener('scroll', align, true); };
|
|
609
|
+
}, [mode, !!project]);
|
|
610
|
+
function jump() { frame.current?.contentWindow?.postMessage({ type: 'dsh-ppt-jump', nonce: nonce.current, page: index }, '*'); }
|
|
611
|
+
useEffect(() => { jump(); }, [index, project?.revision, mode]);
|
|
612
|
+
useEffect(() => {
|
|
613
|
+
if (mode !== 'pptx' || !project?.render) return;
|
|
614
|
+
const abort = new AbortController(); setRaster('');
|
|
615
|
+
action({ operation: 'page', id: project.id, page: index + 1 }, abort.signal).then(value => setRaster(value.data)).catch(e => { if (!abort.signal.aborted) setError(e.message) });
|
|
616
|
+
return () => abort.abort();
|
|
617
|
+
}, [mode, index, project?.revision]);
|
|
618
|
+
function handleShortcut(key) {
|
|
619
|
+
if(dataDirty)return;
|
|
620
|
+
if (key === 'save') { if (project && dirty && !busy && !imagePending) save(); return; }
|
|
621
|
+
if (key === 'escape') {
|
|
622
|
+
if (!project || busy || imagePending) return;
|
|
623
|
+
if (dirty) {
|
|
624
|
+
if (!window.confirm(t("有未保存修改,确定取消吗?"))) return;
|
|
625
|
+
setDraft(draftFor(slide)); setImage(null); setDirty(false); setError(''); setMessage(t("已取消未保存的修改。"));
|
|
626
|
+
} else {
|
|
627
|
+
imageLoader.current.cancel(); setProject(null); refreshList();
|
|
628
|
+
}
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
if (key === 'prev' || key === 'next') {
|
|
632
|
+
if (!project || busy || dirty || imagePending) return;
|
|
633
|
+
const next = index + (key === 'next' ? 1 : -1);
|
|
634
|
+
if (next >= 0 && next < project.slides.length) choose(project.slides[next]);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
useEffect(() => {
|
|
638
|
+
function onKey(event) {
|
|
639
|
+
if (event.isComposing || event.defaultPrevented) return;
|
|
640
|
+
if (event.key === 'Escape' && event.target && event.target.tagName === 'SELECT') return;
|
|
641
|
+
const mod = event.ctrlKey || event.metaKey;
|
|
642
|
+
if (mod && (event.key === 's' || event.key === 'S')) {
|
|
643
|
+
if (!project) return;
|
|
644
|
+
event.preventDefault(); handleShortcut('save'); return;
|
|
645
|
+
}
|
|
646
|
+
if (event.key === 'Escape') {
|
|
647
|
+
if (!project || busy || imagePending) return;
|
|
648
|
+
event.preventDefault(); handleShortcut('escape'); return;
|
|
649
|
+
}
|
|
650
|
+
if (event.altKey && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
|
|
651
|
+
if (!project || busy || dirty || imagePending) return;
|
|
652
|
+
event.preventDefault(); handleShortcut(event.key === 'ArrowRight' ? 'next' : 'prev');
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
document.addEventListener('keydown', onKey);
|
|
656
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
657
|
+
}, [project, dirty, busy, imagePending, index, selected, draft, image, dataDirty]);
|
|
658
|
+
useEffect(() => {
|
|
659
|
+
if (!dirty && !dataDirty) return;
|
|
660
|
+
function warn(event) { event.preventDefault(); event.returnValue = t("有未保存修改,离开页面会丢失。"); }
|
|
661
|
+
window.addEventListener('beforeunload', warn);
|
|
662
|
+
return () => window.removeEventListener('beforeunload', warn);
|
|
663
|
+
}, [dirty,dataDirty]);
|
|
664
|
+
function open(id) { return perform(signal => action({ operation: 'open', id }, signal), value => { adopt(value.project); setMessage(t("点击预览里的文字,或在下方修改字段。")); }); }
|
|
665
|
+
function keepInputsAndReload() {
|
|
666
|
+
const original = draftFor(slide), keys = fields.filter(([key]) => draft[key] !== original[key]).map(([key]) => key), pending = { ...draft }, pendingImage = image;
|
|
667
|
+
return perform(signal => action({ operation: 'open', id: project.id }, signal), value => {
|
|
668
|
+
const row = value.project.slides.find(s => s.id === selected);
|
|
669
|
+
if (!row) { setError(t("当前页已被删除,输入仍保留,请复制需要的内容后取消修改。")); return; }
|
|
670
|
+
const latest = draftFor(row), merged = { ...latest }, shared = [];
|
|
671
|
+
for (const key of keys) { merged[key] = pending[key]; if (latest[key] !== original[key] && latest[key] !== pending[key]) shared.push({ key, latest: latest[key], yours: pending[key] }); }
|
|
672
|
+
adopt(value.project, selected); setDraft(merged); setImage(pendingImage); setDirty(keys.length > 0 || !!pendingImage); setOverlaps(shared);
|
|
673
|
+
setMessage(t("已载入最新版本并保留你的修改,请核对后再保存。"));
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
function choose(row) { if (dirty || busy) return; imageLoader.current.cancel(); setSelected(row.id); setDraft(draftFor(row)); setImage(null); setMessage(''); }
|
|
677
|
+
function save(saveAs = false) {
|
|
678
|
+
if(dataDirty)return;
|
|
679
|
+
const original = draftFor(slide), patch = {};
|
|
680
|
+
for (const [key] of fields) if (draft[key] !== original[key]) patch[key] = key === 'bullets' ? draft[key].split('\n').map(v => v.trim()).filter(Boolean) : draft[key];
|
|
681
|
+
if (image) patch.image = { src: image.src, alt: image.alt, fit: image.fit, caption: image.caption };
|
|
682
|
+
return perform(signal => action({ operation: 'edit', id: project.id, expectedRevision: project.revision, slide: slide.id, patch, saveAs }, signal), value => {
|
|
683
|
+
adopt(value.project, slide.id); setMessage(saveAs ? t("副本已保存,原文件保留。副本从工程生成,不包含 Office 手工修改。") : value.changed === false ? t("内容没有变化。") : t("已保存,HTML、PPTX 和工程文件已同步更新。"));
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
function move(delta) {
|
|
687
|
+
if(dataDirty)return;
|
|
688
|
+
const order = project.slides.map(s => s.id); [order[index], order[index + delta]] = [order[index + delta], order[index]];
|
|
689
|
+
return perform(signal => action({ operation: 'edit', id: project.id, expectedRevision: project.revision, order }, signal), value => { adopt(value.project, slide.id); setMessage(t("页面顺序已更新,可撤销。")); });
|
|
690
|
+
}
|
|
691
|
+
function structure(operation) {
|
|
692
|
+
if(dataDirty)return;
|
|
693
|
+
return perform(signal => action({ operation, id: project.id, expectedRevision: project.revision, slide: slide.id }, signal), value => {
|
|
694
|
+
adopt(value.project, value.selected);
|
|
695
|
+
setMessage(operation === 'duplicate' ? t("页面已复制,图片、图表和备注一并保留,可撤销。") : t("页面已删除,可撤销。"));
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
function undo() { if(dataDirty)return;return perform(signal => action({ operation: 'undo', id: project.id, expectedRevision: project.revision }, signal), value => { adopt(value.project, selected); setMessage(t("已撤销上次修改。")); }); }
|
|
699
|
+
function render() {
|
|
700
|
+
if(dataDirty)return;
|
|
701
|
+
return perform(signal => action({ operation: 'render', id: project.id, expectedRevision: project.revision }, signal), value => { adopt(value.project, selected); setMode('pptx'); setMessage(t("当前 PPTX 已生成逐页图片,请查看画面。")); }, t("正在渲染最终 PPTX,较大文件可能需要几分钟…"));
|
|
702
|
+
}
|
|
703
|
+
function download(kind) {
|
|
704
|
+
if(dataDirty)return;
|
|
705
|
+
const url = new URL('api/dsh-ppt/download', document.baseURI);
|
|
706
|
+
url.searchParams.set('id', project.id); url.searchParams.set('kind', kind); url.searchParams.set('revision', String(project.revision));
|
|
707
|
+
// An authenticated attachment response keeps the click's user gesture and
|
|
708
|
+
// works in WebViews whose native download handler cannot read blob URLs.
|
|
709
|
+
const link = document.createElement('a'); link.href = url.href; link.download = '';
|
|
710
|
+
link.hidden = true; document.body.append(link); link.click(); link.remove();
|
|
711
|
+
setMessage(t("已请求下载,请查看浏览器的下载列表。"));
|
|
712
|
+
}
|
|
713
|
+
function copyExample() {
|
|
714
|
+
const text = t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。");
|
|
715
|
+
try { navigator.clipboard?.writeText(text).then(() => setMessage(t("已复制示例"))).catch(() => {}); } catch (_) { /* ignore */ }
|
|
716
|
+
}
|
|
717
|
+
function upload(event) {
|
|
718
|
+
const file = event.target.files?.[0]; event.target.value = ''; if (!file) return;
|
|
719
|
+
imageLoader.current.cancel(); setMessage(''); setError('');
|
|
720
|
+
if (!['image/png', 'image/jpeg'].includes(file.type) || file.size > 5 * 1024 * 1024) { setError(t("请选择 5 MiB 以内的 PNG 或 JPEG 图片。")); return; }
|
|
721
|
+
imageLoader.current.read(file, data => {
|
|
722
|
+
if (!alive.current) return;
|
|
723
|
+
setImage({ src: data, alt: slide.image?.alt || file.name.replace(/\.[^.]+$/, ''), caption: slide.image?.caption || '', fit: slide.image?.fit || 'contain', name: file.name });
|
|
724
|
+
setDirty(true); setError(''); setMessage(t("图片已载入,保存后生效。"));
|
|
725
|
+
}, () => { if (alive.current) { setError(t("无法读取图片,请重试。")); setMessage(''); } });
|
|
726
|
+
if (imageLoader.current.pending) setMessage(t("正在读取图片,切换页面会取消本次读取。"));
|
|
727
|
+
}
|
|
728
|
+
const currentImage = image?.src || (slide?.image?.assetId && project.assets[slide.image.assetId]?.data);
|
|
729
|
+
return h('div', { className: 'pptw', 'aria-busy': busy ? 'true' : undefined }, h('style', null, css),
|
|
730
|
+
h('h2', null, t("演示文稿编辑")), h('p', { className: 'muted' }, t("修改本插件生成的成品,保存时同步更新 HTML、可编辑 PPTX 和工程文件。")),
|
|
731
|
+
h('p', { className: 'muted' }, t("快捷键:Ctrl/⌘+S 保存 · Esc 取消或返回 · Alt+←/→ 切换页面")),
|
|
732
|
+
error && h('div', { role: 'alert', className: 'notice error' }, error, ' ', h('button', { disabled: busy || dataDirty, onClick: () => project ? open(project.id) : refreshList() }, t("重试"))),
|
|
733
|
+
conflict && project && h('button', { disabled: busy || dataDirty, onClick: keepInputsAndReload }, t("载入最新版本,保留我的输入")),
|
|
734
|
+
message && h('div', { role: 'status', className: 'notice' }, message),
|
|
735
|
+
busy && h('div', { role: 'status', className: 'muted' }, job),
|
|
736
|
+
!project ? h(React.Fragment, null,
|
|
737
|
+
h('div', { className: 'tools' }, h('button', { onClick: refreshList, disabled: busy }, t("刷新项目"))),
|
|
738
|
+
projects.length ? h('div', { className: 'project-list' }, projects.map(row => h('button', { key: row.id, onClick: () => open(row.id), disabled: busy }, h('strong', null, row.title), h('div', { className: 'file muted' }, row.path)))) :
|
|
739
|
+
h('div', { className: 'card' }, h('h3', null, t("还没有可以编辑的项目")), h('p', null, t("先在对话中让助手生成演示文稿。已有项目可以让助手调用 ppt_check 检查一次,它会出现在这里。")), h('p', { className: 'muted' }, t("示例:请把这份材料制作成可直接交付的演示文稿,生成 HTML、PPTX 和工程文件。")), h('div', { className: 'tools' }, h('button', { onClick: copyExample }, t("复制示例"))))
|
|
740
|
+
) : h(React.Fragment, null,
|
|
741
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy || dirty || dataDirty, onClick: () => { imageLoader.current.cancel(); setImage(null); setProject(null); refreshList(); } }, t("返回项目")), h('strong', null, project.title), (dirty||dataDirty) && h('span', { className: 'badge-dirty', role: 'status' }, t("未保存")), h('span', { className: 'muted' }, project.slides.length + t(" 页 · 修订 ") + project.revision)),
|
|
742
|
+
h('div', { className: 'layout' },
|
|
743
|
+
h('div', null, h('h3', null, t("页面")), h('div', { className: 'pages' }, project.slides.map((row, i) => h('button', { key: row.id, 'aria-current': row.id === selected ? 'true' : undefined, disabled: busy || dirty, onClick: () => choose(row) }, (i + 1) + '. ' + (row.title || t("未命名页"))))),
|
|
744
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy || dirty || imagePending || dataDirty || index === 0, onClick: () => move(-1) }, t("上移")), h('button', { disabled: busy || dirty || imagePending || dataDirty || index === project.slides.length - 1, onClick: () => move(1) }, t("下移")),
|
|
745
|
+
h('button', { disabled: busy || dirty || imagePending || dataDirty || project.slides.length >= 120, onClick: () => structure('duplicate') }, t("复制本页")),
|
|
746
|
+
h('button', { disabled: busy || dirty || imagePending || dataDirty || project.slides.length <= 1, onClick: () => structure('remove') }, t("删除本页")))),
|
|
747
|
+
h('div', null,
|
|
748
|
+
h('div', { className: 'tools' }, h('button', { disabled: busy || dataDirty, 'aria-pressed': mode === 'html', onClick: () => setMode('html') }, t("HTML 预览")),
|
|
749
|
+
h('button', { disabled: busy || dataDirty || !project.render, 'aria-pressed': mode === 'pptx', onClick: () => setMode('pptx') }, t("最终 PPTX 预览")),
|
|
750
|
+
h('button', { disabled: busy || dirty || imagePending || dataDirty, onClick: render }, t("渲染当前 PPTX"))),
|
|
751
|
+
h('div', { className: 'preview', ref: previewBox }, mode === 'html' ? (project.html ? h('iframe', { ref: frame, title: t("演示文稿 HTML 预览"), sandbox: 'allow-scripts', srcDoc: previewDocument, onLoad: jump }) : h('p', null, t("此项目尚无 HTML,请保存一次生成预览。"))) : raster ? h('img', { className: 'render-page', src: raster, alt: t("最终 PPTX 第 ") + (index + 1) + t(" 页渲染结果") }) : h('p', null, t("正在载入当前页渲染…"))),
|
|
752
|
+
h('p', { className: 'muted' }, mode === 'html' ? t("这是 HTML 放映预览。最终 PPTX 的字体和排版请用上方渲染检查。点击文字可定位编辑字段。") : t("这是当前 PPTX 文件的实际渲染图片,仍需检查每页画面;PowerPoint / WPS 可能因字体环境而不同。")),
|
|
753
|
+
project.render?.missingFonts?.length ? h('div', { role: 'alert', className: 'notice error' }, t("渲染引擎报告缺失字体:") + project.render.missingFonts.join('、') + t("。请替换为目标电脑可用字体后重新渲染。")) : null,
|
|
754
|
+
h('div', { className: 'card' }, h('h3', null, t("编辑第 ") + (index + 1) + t(" 页")),
|
|
755
|
+
dirty && h('p', { className: 'dirty' }, t("有未保存修改,请先保存或取消,再切换页面。")),
|
|
756
|
+
overlaps.length ? h('div', { className: 'notice' }, h('strong', null, t("这些字段也被修改过,请比较后决定是否保存:")), overlaps.map(row => h('div', { key: row.key }, h('strong', null, t(fields.find(([key]) => key === row.key)[1])), h('p', null, t("最新版本:") + row.latest), h('p', null, t("你的修改:") + row.yours)))) : null,
|
|
757
|
+
fields.filter(([key]) => key === 'title' || key === 'notes' || key === 'bullets' && (slide.layout === 'bullets' || slide.bullets?.length > 0) || key !== 'bullets' && (slide[key] || key === 'subtitle' && ['cover','section','closing','quote'].includes(slide.layout) || key === 'kicker' && ['cover','section','closing'].includes(slide.layout))).map(([key, label]) => h('div', { key }, h('label', { htmlFor: 'pptw-' + key }, t(label)), h(key === 'title' || key === 'kicker' ? 'input' : 'textarea', { id: 'pptw-' + key, ref: el => { fieldRefs.current[key] = el }, disabled: busy || dataDirty, value: draft[key] || '', rows: key === 'bullets' ? 4 : 2, maxLength: 8000, onChange: e => { setDraft({ ...draft, [key]: e.target.value }); setDirty(true); } }))),
|
|
758
|
+
h('label', { htmlFor: 'pptw-image' }, slide.image ? t("替换图片(PNG / JPEG)") : t("添加图片(会改为图文布局)")),
|
|
759
|
+
h('input', { id: 'pptw-image', type: 'file', accept: 'image/png,image/jpeg', disabled: busy || dataDirty, onChange: upload }),
|
|
760
|
+
currentImage && h('img', { className: 'image-preview', src: currentImage, alt: image?.alt || slide.image?.alt || t("当前图片") }),
|
|
761
|
+
image && h(React.Fragment, null, h('p', { className: 'muted' }, t("已选择:") + image.name), h('label', { htmlFor: 'pptw-alt' }, t("图片说明")), h('input', { id: 'pptw-alt', value: image.alt, disabled: busy || dataDirty, onChange: e => setImage({ ...image, alt: e.target.value }) }), h('label', { htmlFor: 'pptw-fit' }, t("图片适应方式")), h('select', { id: 'pptw-fit', value: image.fit, disabled: busy || dataDirty, onChange: e => setImage({ ...image, fit: e.target.value }) }, h('option', { value: 'contain' }, t("完整显示")), h('option', { value: 'cover' }, t("填满并裁切")))),
|
|
762
|
+
h('div', { className: 'tools' }, h('button', { className: 'primary', 'aria-keyshortcuts': 'Control+S Meta+S', disabled: busy || dataDirty || imagePending || !dirty, onClick: () => save() }, t("保存此页")), h('button', { 'aria-keyshortcuts': 'Control+Shift+S Meta+Shift+S', disabled: busy || dataDirty || imagePending, onClick: () => save(true) }, t("另存副本")), h('button', { 'aria-keyshortcuts': 'Escape', disabled: busy || (!dirty && !imagePending), onClick: () => { imageLoader.current.cancel(); setDraft(draftFor(slide)); setImage(null); setDirty(false); setError(''); setMessage(''); setConflict(false); setOverlaps([]); } }, t("取消修改")), h('button', { disabled: busy || dirty || imagePending || dataDirty || !project.undoAvailable, onClick: undo }, t("撤销上次修改")))),
|
|
763
|
+
h('details', { className: 'card' }, h('summary', null, t("质量提醒(") + (project.quality.warningCount + project.quality.errorCount) + (languageOf() === 'en' ? ')' : ')')), (project.quality.issues || []).map((issue, i) => h('p', { key: i }, (issue.slide > 0 ? t("第 ") + issue.slide + t(" 页:") : "") + (languageOf() === 'en' ? issue.messageEn : issue.message) + (languageOf() === 'en' ? ' ' : ';') + (languageOf() === 'en' ? issue.suggestionEn : issue.suggestion)))),
|
|
484
764
|
h('p', { className: 'muted' }, t("成品包包含 PPTX、HTML 和工程文件。请先保存修改,再下载最新版本。")),
|
|
485
|
-
h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || dirty || imagePending, onClick: () => download('bundle') }, t("下载成品包 ZIP")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('pptx') }, t("下载最新 PPTX")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('html') }, t("下载 HTML")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('notes') }, t("下载讲稿 Markdown")), h('button', { disabled: busy || dirty || imagePending, onClick: () => download('json') }, t("备份工程")))
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
765
|
+
h('div', { className: 'tools' }, h('button', { className: 'primary', disabled: busy || dirty || imagePending || dataDirty, onClick: () => download('bundle') }, t("下载成品包 ZIP")), h('button', { disabled: busy || dirty || imagePending || dataDirty, onClick: () => download('pptx') }, t("下载最新 PPTX")), h('button', { disabled: busy || dirty || imagePending || dataDirty, onClick: () => download('html') }, t("下载 HTML")), h('button', { disabled: busy || dirty || imagePending || dataDirty, onClick: () => download('notes') }, t("下载讲稿 Markdown")), h('button', { disabled: busy || dirty || imagePending || dataDirty, onClick: () => download('json') }, t("备份工程"))),
|
|
766
|
+
project.dataModel&&mode!=='html'&&h('p',{className:'notice'},languageOf()==='en'?'Switch to HTML preview to adjust assumptions and inspect live data.':'切换到 HTML 预览后可调整假设并查看数据联动。'),
|
|
767
|
+
project.dataModel&&h(DataPanel,{key:project.id+':'+project.revision,project,blocked:busy||dirty||imagePending||mode!=='html',incoming:incomingData,
|
|
768
|
+
onParameters:parameters=>frame.current?.contentWindow?.postMessage({type:'dsh-ppt-data-set',nonce:nonce.current,parameters,command:++dataCommand.current},'*'),onDirty:setDataDirty,onBusy:value=>{setBusy(value);setJob(languageOf()==='en'?'Updating presentation data…':'正在核对并更新数据…');},
|
|
769
|
+
onAdopt:next=>{adopt(next,selected);setMessage(languageOf()==='en'?'Saved confirmed data. HTML, PPTX and project are synchronized; undo is available.':'已保存确认后的数据,HTML、PPTX 和工程已同步,可撤销。');},onChoose:id=>choose(project.slides.find(s=>s.id===id)),onDownload:download}),
|
|
770
|
+
h(CoachingPanel, { key: project.id, project, selected, blocked: busy || dirty || imagePending || dataDirty,
|
|
771
|
+
onChoose: id => { choose(project.slides.find(s => s.id === id)); previewBox.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }); },
|
|
772
|
+
onAdopt: next => { adopt(next, selected); setMessage(languageOf() === 'en' ? 'Saved to a new copy. The original is kept; you can undo the adopted changes in this copy.' : '已保存为新副本,原稿保留;可在当前副本中撤销采纳的修改。'); } })
|
|
773
|
+
)
|
|
774
|
+
)
|
|
775
|
+
)
|
|
776
|
+
);
|
|
777
|
+
}
|
|
491
778
|
function apply(ctx) {
|
|
492
779
|
try { localeService = ctx.get?.('locale') || ctx.locale; } catch { localeService = ctx.locale; }
|
|
493
780
|
ctx.slots.inject('settings.section', () => ctx.slots.register({ name: 'settings.section', id: 'dsh-ppt', order: 58, label: () => t("演示文稿"), inject: () => ({ locale: localeService }) }, __withFirstRun(Workbench)));
|
|
494
|
-
}
|
|
495
|
-
return { inject: ['slots', 'locale'], apply, __internals: { draftFor, editorHtml, createImageLoader } };
|
|
496
|
-
} });
|
|
781
|
+
}
|
|
782
|
+
return { inject: ['slots', 'locale'], apply, __internals: { draftFor, editorHtml, createImageLoader } };
|
|
783
|
+
} });
|