@lumesync/studio 0.0.0-stage → 1.0.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/README.md +229 -2
- package/bin/lumesync-studio.js +7 -0
- package/package.json +33 -4
- package/skills/courseware-authoring/SKILL.md +226 -0
- package/skills/courseware-authoring/references/tools.md +133 -0
- package/src/chat/mailbox.js +307 -0
- package/src/cli/main.js +669 -0
- package/src/core/document.js +349 -0
- package/src/core/errors.js +44 -0
- package/src/core/exporter.js +272 -0
- package/src/core/model.js +305 -0
- package/src/core/rules.js +288 -0
- package/src/core/storage.js +616 -0
- package/src/core/transaction.js +250 -0
- package/src/core/validate.js +503 -0
- package/src/core/zip.js +251 -0
- package/src/editing/operations.js +671 -0
- package/src/editing/session.js +838 -0
- package/src/server/http.js +944 -0
- package/src/server/ws.js +128 -0
- package/src/templates/courseware.js +48 -0
- package/src/templates/init.js +374 -0
- package/src/tools/registry.js +487 -0
- package/ui/app.js +2671 -0
- package/ui/home.html +32 -0
- package/ui/home.js +148 -0
- package/ui/index.html +210 -0
- package/ui/shared/edit-model.js +105 -0
- package/ui/shared/quiz-view.js +455 -0
- package/ui/style.css +1161 -0
package/ui/home.html
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN" class="home-root">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>课件主页 · LumeSync Studio</title>
|
|
7
|
+
<link rel="stylesheet" href="/ui/style.css">
|
|
8
|
+
<script src="/ui/home.js" defer></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body class="home-body">
|
|
11
|
+
<header class="home-topbar">
|
|
12
|
+
<a class="brand-line" href="/home" title="课件主页">
|
|
13
|
+
<span class="mark">LS</span>
|
|
14
|
+
<strong>LumeSync Studio</strong>
|
|
15
|
+
</a>
|
|
16
|
+
<span class="home-crumb">课件主页</span>
|
|
17
|
+
<a class="ghost-button home-back" href="/">返回当前课件</a>
|
|
18
|
+
</header>
|
|
19
|
+
<main class="home-main">
|
|
20
|
+
<section class="home-hero">
|
|
21
|
+
<h1>我的课件</h1>
|
|
22
|
+
<p class="muted">这里列出本机编辑过的全部课件。选择一份即可继续查看或编辑,编辑记录与历史都会保留。</p>
|
|
23
|
+
</section>
|
|
24
|
+
<div class="home-toolbar">
|
|
25
|
+
<span id="homeCount" class="muted">正在读取课件库…</span>
|
|
26
|
+
<button id="homeRefresh" class="ghost-button" type="button">刷新</button>
|
|
27
|
+
</div>
|
|
28
|
+
<div id="homeGrid" class="home-grid" aria-live="polite"></div>
|
|
29
|
+
<p id="homeError" class="home-error" hidden></p>
|
|
30
|
+
</main>
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
package/ui/home.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// 课件主页:从 /api/library 读取本机已编辑课件,点击后在当前服务内切换或跳转到已有实例。
|
|
2
|
+
|
|
3
|
+
const grid = document.getElementById('homeGrid');
|
|
4
|
+
const count = document.getElementById('homeCount');
|
|
5
|
+
const errorBox = document.getElementById('homeError');
|
|
6
|
+
const refresh = document.getElementById('homeRefresh');
|
|
7
|
+
let busy = false;
|
|
8
|
+
|
|
9
|
+
function showError(message) {
|
|
10
|
+
errorBox.textContent = message;
|
|
11
|
+
errorBox.hidden = !message;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function hueFor(text) {
|
|
15
|
+
let hash = 0;
|
|
16
|
+
for (const char of String(text)) hash = (hash * 31 + char.codePointAt(0)) % 360;
|
|
17
|
+
return hash;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function formatDate(iso) {
|
|
21
|
+
if (!iso) return '尚未编辑';
|
|
22
|
+
const date = new Date(iso);
|
|
23
|
+
if (Number.isNaN(date.getTime())) return '尚未编辑';
|
|
24
|
+
return new Intl.DateTimeFormat('zh-CN', {
|
|
25
|
+
month: '2-digit',
|
|
26
|
+
day: '2-digit',
|
|
27
|
+
hour: '2-digit',
|
|
28
|
+
minute: '2-digit',
|
|
29
|
+
}).format(date);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function metaLine(item) {
|
|
33
|
+
const parts = [item.subject, item.grade].filter(Boolean);
|
|
34
|
+
if (item.scenes > 0) parts.push(`${item.scenes} 个场景`);
|
|
35
|
+
if (item.durationMin) parts.push(`${item.durationMin} 分钟`);
|
|
36
|
+
return parts.join(' · ') || '未填写课程信息';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createCard(item) {
|
|
40
|
+
const card = document.createElement('article');
|
|
41
|
+
card.className = `home-card${item.current ? ' is-current' : ''}`;
|
|
42
|
+
|
|
43
|
+
const button = document.createElement('button');
|
|
44
|
+
button.type = 'button';
|
|
45
|
+
button.className = 'home-card-open';
|
|
46
|
+
button.setAttribute('aria-label', `${item.current ? '继续编辑' : '打开'}课件:${item.title}`);
|
|
47
|
+
|
|
48
|
+
const cover = document.createElement('div');
|
|
49
|
+
cover.className = 'home-cover';
|
|
50
|
+
cover.style.setProperty('--cover-hue', String(hueFor(item.root)));
|
|
51
|
+
const mark = document.createElement('span');
|
|
52
|
+
mark.className = 'home-cover-mark';
|
|
53
|
+
mark.textContent = item.title.slice(0, 2);
|
|
54
|
+
const status = document.createElement('span');
|
|
55
|
+
status.className = `home-status ${item.running ? 'is-running' : 'is-idle'}`;
|
|
56
|
+
status.textContent = item.current ? '当前课件' : item.running ? '运行中' : '未运行';
|
|
57
|
+
cover.append(mark, status);
|
|
58
|
+
|
|
59
|
+
const body = document.createElement('div');
|
|
60
|
+
body.className = 'home-card-body';
|
|
61
|
+
const title = document.createElement('div');
|
|
62
|
+
title.className = 'home-card-title';
|
|
63
|
+
title.textContent = item.title;
|
|
64
|
+
const meta = document.createElement('div');
|
|
65
|
+
meta.className = 'home-card-meta';
|
|
66
|
+
meta.textContent = metaLine(item);
|
|
67
|
+
|
|
68
|
+
const foot = document.createElement('div');
|
|
69
|
+
foot.className = 'home-card-foot';
|
|
70
|
+
const revision = document.createElement('span');
|
|
71
|
+
revision.textContent = item.revision === null ? 'rev —' : `rev ${item.revision}`;
|
|
72
|
+
const updated = document.createElement('span');
|
|
73
|
+
updated.textContent = formatDate(item.updatedAt);
|
|
74
|
+
foot.append(revision, updated);
|
|
75
|
+
|
|
76
|
+
const pathLine = document.createElement('div');
|
|
77
|
+
pathLine.className = 'home-card-path';
|
|
78
|
+
pathLine.textContent = item.root;
|
|
79
|
+
pathLine.title = item.root;
|
|
80
|
+
|
|
81
|
+
body.append(title, meta, foot, pathLine);
|
|
82
|
+
button.append(cover, body);
|
|
83
|
+
button.addEventListener('click', () => openCourseware(item, card));
|
|
84
|
+
card.append(button);
|
|
85
|
+
return card;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function loadLibrary() {
|
|
89
|
+
if (busy) return;
|
|
90
|
+
busy = true;
|
|
91
|
+
refresh.disabled = true;
|
|
92
|
+
showError('');
|
|
93
|
+
try {
|
|
94
|
+
const response = await fetch('/api/library', { credentials: 'same-origin' });
|
|
95
|
+
const payload = await response.json().catch(() => ({}));
|
|
96
|
+
if (!response.ok) throw new Error(payload?.error?.message ?? `读取失败(HTTP ${response.status})`);
|
|
97
|
+
const items = Array.isArray(payload.items) ? payload.items : [];
|
|
98
|
+
grid.replaceChildren();
|
|
99
|
+
if (items.length === 0) {
|
|
100
|
+
const empty = document.createElement('div');
|
|
101
|
+
empty.className = 'home-empty';
|
|
102
|
+
empty.innerHTML = '还没有编辑过的课件。<br>让 Agent 运行 <code>lumesync-studio start --root ./courseware --init</code> 创建第一份课件后刷新。';
|
|
103
|
+
grid.append(empty);
|
|
104
|
+
count.textContent = '0 份课件';
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
for (const item of items) grid.append(createCard(item));
|
|
108
|
+
count.textContent = `共 ${items.length} 份课件 · 点击卡片打开`;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
showError(error.message);
|
|
111
|
+
count.textContent = '读取课件库失败';
|
|
112
|
+
} finally {
|
|
113
|
+
busy = false;
|
|
114
|
+
refresh.disabled = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function openCourseware(item, card) {
|
|
119
|
+
if (item.current) {
|
|
120
|
+
location.href = '/';
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (card.classList.contains('is-busy')) return;
|
|
124
|
+
card.classList.add('is-busy');
|
|
125
|
+
showError('');
|
|
126
|
+
try {
|
|
127
|
+
const response = await fetch('/api/library/open', {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
credentials: 'same-origin',
|
|
130
|
+
headers: { 'content-type': 'application/json' },
|
|
131
|
+
body: JSON.stringify({ root: item.root }),
|
|
132
|
+
});
|
|
133
|
+
const payload = await response.json().catch(() => ({}));
|
|
134
|
+
if (!response.ok) throw new Error(payload?.error?.message ?? `打开失败(HTTP ${response.status})`);
|
|
135
|
+
// 已有独立 Studio 进程时跳到它的地址,避免两个服务同时写同一课件。
|
|
136
|
+
if (payload.status === 'running' && payload.previewUrl) {
|
|
137
|
+
location.href = payload.previewUrl;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
location.href = '/';
|
|
141
|
+
} catch (error) {
|
|
142
|
+
card.classList.remove('is-busy');
|
|
143
|
+
showError(error.message);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
refresh.addEventListener('click', loadLibrary);
|
|
148
|
+
loadLibrary();
|
package/ui/index.html
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>LumeSync Studio</title>
|
|
7
|
+
<link rel="stylesheet" href="/ui/style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<header class="topbar">
|
|
11
|
+
<a class="brand-line" href="/home" title="返回课件主页">
|
|
12
|
+
<span class="mark">LS</span>
|
|
13
|
+
<strong>LumeSync Studio</strong>
|
|
14
|
+
</a>
|
|
15
|
+
<span id="coursewareTitle" class="muted course-title">未加载课件</span>
|
|
16
|
+
<div class="topbar-tools">
|
|
17
|
+
<button id="undoButton" class="icon-button" type="button" title="撤销 (⌘Z)" aria-label="撤销" disabled>
|
|
18
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="M9 15 3 9l6-6M3 9h12a6 6 0 0 1 0 12h-3"/></svg>
|
|
19
|
+
</button>
|
|
20
|
+
<button id="redoButton" class="icon-button" type="button" title="重做 (⇧⌘Z)" aria-label="重做" disabled>
|
|
21
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="m15 15 6-6-6-6m6 6H9a6 6 0 0 0 0 12h3"/></svg>
|
|
22
|
+
</button>
|
|
23
|
+
<button id="saveButton" class="icon-button" type="button" title="保存 (⌘S)" aria-label="保存">
|
|
24
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linejoin="round" d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><path stroke-linejoin="round" d="M17 21v-8H7v8M7 3v5h8"/></svg>
|
|
25
|
+
</button>
|
|
26
|
+
<button id="settingsButton" class="icon-button" type="button" title="课件设置" aria-label="课件设置">
|
|
27
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="3"/><path stroke-linecap="round" stroke-linejoin="round" d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09a1.65 1.65 0 0 0-1.08-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09a1.65 1.65 0 0 0 1.51-1.08 1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9c0 .66.39 1.26 1 1.51H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
|
|
28
|
+
</button>
|
|
29
|
+
<button id="historyButton" class="icon-button" type="button" title="历史" aria-label="历史">
|
|
30
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path stroke-linecap="round" stroke-linejoin="round" d="M12 7v5l3 2"/></svg>
|
|
31
|
+
</button>
|
|
32
|
+
<button id="chatButton" class="icon-button" type="button" title="AI 对话" aria-label="AI 对话" aria-expanded="false" aria-controls="chatPanel">
|
|
33
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="M21 11.5a8 8 0 0 1-8.5 8L7 21v-3.2A8 8 0 1 1 21 11.5z"/><path stroke-linecap="round" d="M8.5 10.5h7M8.5 14h4.5"/></svg>
|
|
34
|
+
</button>
|
|
35
|
+
<button id="importButton" class="icon-button" type="button" title="导入课件" aria-label="导入课件">
|
|
36
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3"/></svg>
|
|
37
|
+
</button>
|
|
38
|
+
<button id="exportButton" class="icon-button" type="button" title="导出课件" aria-label="导出课件">
|
|
39
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5"/></svg>
|
|
40
|
+
</button>
|
|
41
|
+
<button id="refreshButton" class="icon-button" type="button" title="重新加载" aria-label="重新加载">
|
|
42
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12a7.5 7.5 0 0 1 12.9-5.2L21 10.5M21 4.5v6h-6M19.5 12a7.5 7.5 0 0 1-12.9 5.2L3 13.5M3 19.5v-6h6"/></svg>
|
|
43
|
+
</button>
|
|
44
|
+
<input id="importInput" type="file" accept=".lume,application/zip" hidden>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="topbar-status">
|
|
47
|
+
<span id="revisionBadge" class="badge">rev —</span>
|
|
48
|
+
<span id="statusBadge" class="badge badge-warn">连接中</span>
|
|
49
|
+
</div>
|
|
50
|
+
</header>
|
|
51
|
+
|
|
52
|
+
<main class="layout">
|
|
53
|
+
<aside id="scenePanel" class="panel scene-panel">
|
|
54
|
+
<div class="panel-head">
|
|
55
|
+
<h2>幻灯片</h2>
|
|
56
|
+
<span id="sceneCount" class="muted">0</span>
|
|
57
|
+
</div>
|
|
58
|
+
<ol id="sceneList" class="scene-list"></ol>
|
|
59
|
+
<div class="panel-foot">
|
|
60
|
+
<button id="prevScene" class="icon-button" type="button" title="上一页" aria-label="上一页">
|
|
61
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="m15 18-6-6 6-6"/></svg>
|
|
62
|
+
</button>
|
|
63
|
+
<button id="nextScene" class="icon-button" type="button" title="下一页" aria-label="下一页">
|
|
64
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="m9 18 6-6-6-6"/></svg>
|
|
65
|
+
</button>
|
|
66
|
+
</div>
|
|
67
|
+
</aside>
|
|
68
|
+
|
|
69
|
+
<div id="sceneResizer" class="scene-resizer" role="separator" aria-orientation="vertical"
|
|
70
|
+
aria-label="调整幻灯片栏宽度" tabindex="0" title="拖拽调整宽度,双击恢复默认"></div>
|
|
71
|
+
|
|
72
|
+
<section class="stage">
|
|
73
|
+
<button id="sourceToggle" class="icon-button source-toggle" type="button" title="查看源码" aria-label="查看源码" aria-pressed="false">
|
|
74
|
+
<svg class="source-toggle-code" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="m9 18-6-6 6-6M15 6l6 6-6 6"/></svg>
|
|
75
|
+
<svg class="source-toggle-preview" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><rect x="3" y="4" width="18" height="14" rx="2"/><path stroke-linecap="round" d="M8 21h8M12 18v3"/></svg>
|
|
76
|
+
</button>
|
|
77
|
+
<div id="frameViewport" class="frame-viewport">
|
|
78
|
+
<div id="slideFit" class="slide-fit">
|
|
79
|
+
<iframe id="previewFrame" class="preview-frame is-active" sandbox="allow-scripts" scrolling="no" title="课件预览"></iframe>
|
|
80
|
+
<iframe id="previewFrameBackup" class="preview-frame is-hidden" sandbox="allow-scripts" scrolling="no" title="课件预览缓冲区"></iframe>
|
|
81
|
+
</div>
|
|
82
|
+
<div id="frameEmpty" class="empty-state" hidden>当前没有可预览的场景</div>
|
|
83
|
+
</div>
|
|
84
|
+
<div id="sourceEditor" class="source-editor" hidden>
|
|
85
|
+
<div class="source-bar">
|
|
86
|
+
<span id="sourceName" class="source-name"></span>
|
|
87
|
+
<span id="sourceState" class="muted">编辑后自动渲染</span>
|
|
88
|
+
</div>
|
|
89
|
+
<div class="source-code-shell">
|
|
90
|
+
<pre id="sourceGutter" class="source-gutter" aria-hidden="true"></pre>
|
|
91
|
+
<div id="sourceCodeLayer" class="source-code-layer">
|
|
92
|
+
<pre id="sourceHighlight" class="source-highlight" aria-hidden="true"></pre>
|
|
93
|
+
<textarea id="sourceCode" class="source-code" spellcheck="false" autocomplete="off" wrap="off" placeholder="选择场景后显示源码"></textarea>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
<div id="pickHint" class="pick-hint" hidden>点击预览中的元素,Esc 取消</div>
|
|
98
|
+
<div class="stage-foot">
|
|
99
|
+
<span id="validationLine" class="muted">等待校验结果</span>
|
|
100
|
+
<div class="stage-foot-right">
|
|
101
|
+
<span id="renderLine" class="muted"></span>
|
|
102
|
+
<span id="eventLine" class="muted">无事件</span>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
<div class="notes-pane">
|
|
106
|
+
<div class="notes-head">
|
|
107
|
+
<h2>演讲稿</h2>
|
|
108
|
+
<div class="notes-actions">
|
|
109
|
+
<span id="notesState" class="muted quiz-state"></span>
|
|
110
|
+
<button id="saveNotes" class="ghost-button" type="button">保存讲稿</button>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
<textarea id="notesInput" class="notes-input" placeholder="写下这一页的讲解要点、提问或过渡语…"></textarea>
|
|
114
|
+
</div>
|
|
115
|
+
</section>
|
|
116
|
+
|
|
117
|
+
<div id="inspectorResizer" class="inspector-resizer" role="separator" aria-orientation="vertical"
|
|
118
|
+
aria-label="调整属性面板宽度" tabindex="0" title="拖拽调整宽度,双击恢复默认"></div>
|
|
119
|
+
|
|
120
|
+
<aside id="inspectorPanel" class="panel inspector">
|
|
121
|
+
<div class="panel-head inspector-head">
|
|
122
|
+
<div class="inspector-tabs" role="tablist" aria-label="右侧面板">
|
|
123
|
+
<button id="tabStructure" class="inspector-tab" type="button" role="tab" aria-selected="true" aria-controls="inspectorBody">结构</button>
|
|
124
|
+
<button id="tabProps" class="inspector-tab" type="button" role="tab" aria-selected="false" aria-controls="inspectorBody">属性</button>
|
|
125
|
+
</div>
|
|
126
|
+
<button id="toggleInspector" class="icon-button" type="button" aria-expanded="true" aria-label="收起面板" title="收起面板">
|
|
127
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" stroke-linejoin="round" d="m9 18 6-6-6-6"/></svg>
|
|
128
|
+
</button>
|
|
129
|
+
</div>
|
|
130
|
+
<div id="inspectorBody" class="inspector-body" role="tabpanel"></div>
|
|
131
|
+
</aside>
|
|
132
|
+
</main>
|
|
133
|
+
|
|
134
|
+
<section id="chatPanel" class="chat-panel" hidden aria-label="AI 对话">
|
|
135
|
+
<div class="chat-head">
|
|
136
|
+
<div class="chat-title">
|
|
137
|
+
<strong>AI 对话</strong>
|
|
138
|
+
<span id="chatState" class="muted">Agent 信箱</span>
|
|
139
|
+
</div>
|
|
140
|
+
<div class="chat-actions">
|
|
141
|
+
<button id="chatPick" class="icon-button" type="button" title="选择预览元素" aria-label="选择预览元素" aria-pressed="false">
|
|
142
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="6"/><path stroke-linecap="round" d="M12 2v3M12 19v3M2 12h3M19 12h3"/></svg>
|
|
143
|
+
</button>
|
|
144
|
+
<button id="chatClose" class="icon-button" type="button" title="收起对话" aria-label="收起对话">
|
|
145
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true" focusable="false"><path stroke-linecap="round" d="m6 6 12 12M18 6 6 18"/></svg>
|
|
146
|
+
</button>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
<div id="chatMessages" class="chat-messages" role="log" aria-live="polite"></div>
|
|
150
|
+
<div id="chatSelection" class="chat-selection" hidden></div>
|
|
151
|
+
<form id="chatForm" class="chat-form">
|
|
152
|
+
<textarea id="chatInput" class="chat-input" rows="2" placeholder="描述要修改的内容,Enter 发送,Shift+Enter 换行"></textarea>
|
|
153
|
+
<div class="chat-form-foot">
|
|
154
|
+
<span class="muted">消息进入 Agent 信箱,由启动 Studio 的 Agent 拉取执行。</span>
|
|
155
|
+
<button id="chatSend" class="ghost-button" type="submit">发送</button>
|
|
156
|
+
</div>
|
|
157
|
+
</form>
|
|
158
|
+
</section>
|
|
159
|
+
|
|
160
|
+
<dialog id="settingsDialog" class="dialog">
|
|
161
|
+
<div class="dialog-head">
|
|
162
|
+
<h2>课件设置</h2>
|
|
163
|
+
<button id="closeSettings" class="ghost-button" type="button">关闭</button>
|
|
164
|
+
</div>
|
|
165
|
+
<div id="settingsBody" class="settings-body"></div>
|
|
166
|
+
</dialog>
|
|
167
|
+
|
|
168
|
+
<dialog id="historyDialog" class="dialog">
|
|
169
|
+
<div class="dialog-head">
|
|
170
|
+
<h2>编辑历史</h2>
|
|
171
|
+
<button id="closeHistory" class="ghost-button" type="button">关闭</button>
|
|
172
|
+
</div>
|
|
173
|
+
<ul id="historyList" class="history-list"></ul>
|
|
174
|
+
<div id="historyDiff" class="diff-panel muted">选择一条历史查看 Diff。</div>
|
|
175
|
+
</dialog>
|
|
176
|
+
|
|
177
|
+
<dialog id="confirmDialog" class="dialog">
|
|
178
|
+
<div class="dialog-head">
|
|
179
|
+
<h2>需要确认的高影响修改</h2>
|
|
180
|
+
<button id="cancelConfirm" class="ghost-button" type="button">取消</button>
|
|
181
|
+
</div>
|
|
182
|
+
<div class="confirm-body">
|
|
183
|
+
<p id="confirmReason" class="muted"></p>
|
|
184
|
+
<div id="confirmDiff" class="diff-panel"></div>
|
|
185
|
+
<div class="quiz-actions">
|
|
186
|
+
<button id="confirmApply" class="ghost-button" type="button">确认并提交</button>
|
|
187
|
+
<span id="confirmState" class="muted quiz-state"></span>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
</dialog>
|
|
191
|
+
|
|
192
|
+
<dialog id="importDialog" class="dialog">
|
|
193
|
+
<div class="dialog-head">
|
|
194
|
+
<h2>导入课件</h2>
|
|
195
|
+
<button id="cancelImport" class="ghost-button" type="button">取消</button>
|
|
196
|
+
</div>
|
|
197
|
+
<div class="confirm-body">
|
|
198
|
+
<p id="importSummary" class="muted"></p>
|
|
199
|
+
<p class="hint-warn">导入会用该课件替换当前内容;编辑历史会保留,可在「历史」中撤销。</p>
|
|
200
|
+
<div class="quiz-actions">
|
|
201
|
+
<button id="confirmImport" class="ghost-button" type="button">开始导入</button>
|
|
202
|
+
<span id="importState" class="muted quiz-state"></span>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
</dialog>
|
|
206
|
+
|
|
207
|
+
<script src="/ui/shared/quiz-view.js"></script>
|
|
208
|
+
<script type="module" src="/ui/app.js"></script>
|
|
209
|
+
</body>
|
|
210
|
+
</html>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// 浏览器与测试共用的纯函数:把表单差异转换成显式 Patch 字段。
|
|
2
|
+
// 原则:未编辑的字段不提交,避免 interaction.upsert 替换语义丢失配置。
|
|
3
|
+
|
|
4
|
+
function sameJson(left, right) {
|
|
5
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// 多选答案顺序不构成语义变化;比较前统一排序去重。
|
|
9
|
+
export function answerSignature(answer) {
|
|
10
|
+
if (!answer || typeof answer !== 'object') return null;
|
|
11
|
+
if (typeof answer.choice === 'string') return `choice:${answer.choice.trim()}`;
|
|
12
|
+
if (Array.isArray(answer.choices)) return `choices:${[...new Set(answer.choices.map((value) => String(value).trim()))].sort().join(',')}`;
|
|
13
|
+
if (Array.isArray(answer.blanks)) return `blanks:${answer.blanks.map((value) => String(value).trim()).join('\u001f')}`;
|
|
14
|
+
return JSON.stringify(answer);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function sameAnswer(left, right) {
|
|
18
|
+
return answerSignature(left) === answerSignature(right);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function changedFields(before, next, fields) {
|
|
22
|
+
const patch = {};
|
|
23
|
+
for (const field of fields) {
|
|
24
|
+
if (next[field] !== undefined && !sameJson(next[field], before[field])) patch[field] = next[field];
|
|
25
|
+
}
|
|
26
|
+
return patch;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const POLICY_FIELDS = [
|
|
30
|
+
'maxAttempts', 'lockAfterSubmit', 'showAnswerAfterSubmit', 'showResultAfterSubmit',
|
|
31
|
+
'shuffleOptions', 'timeLimitSec',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export function buildInteractionPatch(view, form) {
|
|
35
|
+
const body = view?.body ?? {};
|
|
36
|
+
const value = {};
|
|
37
|
+
if (form.stem !== undefined && String(form.stem).trim() !== String(body.stem ?? '').trim()) value.stem = form.stem;
|
|
38
|
+
if (form.options !== undefined && !sameJson(form.options, body.options ?? [])) value.options = form.options;
|
|
39
|
+
if (form.explain !== undefined && String(form.explain) !== String(body.explain ?? '')) value.explain = form.explain;
|
|
40
|
+
|
|
41
|
+
const policy = {};
|
|
42
|
+
for (const field of POLICY_FIELDS) {
|
|
43
|
+
if (form.policy?.[field] !== undefined && form.policy[field] !== body.policy?.[field]) policy[field] = form.policy[field];
|
|
44
|
+
}
|
|
45
|
+
if (Object.keys(policy).length > 0) value.policy = policy;
|
|
46
|
+
|
|
47
|
+
const currentAnswer = body.answer ?? null;
|
|
48
|
+
if (form.answer !== undefined && !sameAnswer(form.answer, currentAnswer)) value.answer = form.answer;
|
|
49
|
+
if (form.partialCredit !== undefined && Boolean(form.partialCredit) !== Boolean(body.partialCredit)) {
|
|
50
|
+
value.partialCredit = Boolean(form.partialCredit);
|
|
51
|
+
}
|
|
52
|
+
if (form.answerKeys !== undefined && !sameAnswer(
|
|
53
|
+
{ choices: form.answerKeys },
|
|
54
|
+
{ choices: body.answerKeys ?? [] },
|
|
55
|
+
)) {
|
|
56
|
+
value.answerKeys = form.answerKeys;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const points = Number(form.points);
|
|
60
|
+
const graded = form.graded === undefined ? view?.graded ?? true : Boolean(form.graded);
|
|
61
|
+
const pointsChanged = Number.isFinite(points) && points !== (view?.points ?? 1);
|
|
62
|
+
const gradedChanged = graded !== (view?.graded ?? true);
|
|
63
|
+
return {
|
|
64
|
+
value,
|
|
65
|
+
points: Number.isFinite(points) ? points : view?.points ?? 1,
|
|
66
|
+
graded,
|
|
67
|
+
pointsChanged,
|
|
68
|
+
gradedChanged,
|
|
69
|
+
hasChanges: Object.keys(value).length > 0 || pointsChanged || gradedChanged,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function buildCoursewarePatch(meta, form) {
|
|
74
|
+
const set = changedFields(meta ?? {}, {
|
|
75
|
+
title: form.title,
|
|
76
|
+
subject: form.subject,
|
|
77
|
+
grade: form.grade,
|
|
78
|
+
durationMin: form.durationMin === undefined ? undefined : Number(form.durationMin),
|
|
79
|
+
aspectRatio: form.aspectRatio,
|
|
80
|
+
}, ['title', 'subject', 'grade', 'durationMin', 'aspectRatio']);
|
|
81
|
+
return { set, hasChanges: Object.keys(set).length > 0 };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function buildObjectivesPayload(meta, objectives) {
|
|
85
|
+
const before = Array.isArray(meta?.objectives) ? meta.objectives : [];
|
|
86
|
+
if (sameJson(before, objectives)) return { setObjectives: undefined, hasChanges: false };
|
|
87
|
+
return { setObjectives: objectives, hasChanges: true };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function buildScenePatch(scene, form) {
|
|
91
|
+
const set = changedFields(scene ?? {}, {
|
|
92
|
+
title: form.title,
|
|
93
|
+
phase: form.phase,
|
|
94
|
+
minutes: form.minutes === undefined ? undefined : Number(form.minutes),
|
|
95
|
+
layout: form.layout,
|
|
96
|
+
modes: form.modes,
|
|
97
|
+
notes: form.notes,
|
|
98
|
+
hidden: form.hidden,
|
|
99
|
+
}, ['title', 'phase', 'minutes', 'layout', 'modes', 'notes', 'hidden']);
|
|
100
|
+
return { set, hasChanges: Object.keys(set).length > 0 };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function nextOperationId(prefix = 'ui') {
|
|
104
|
+
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
105
|
+
}
|