saibo-kanban 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +14 -1
- package/bin/import.mjs +66 -0
- package/client.js +72 -3
- package/index.js +34 -0
- package/lib/import-map.js +145 -0
- package/lib/xlsx.js +157 -0
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
- 导入改为页面操作:看板面板 → 「导入 xlsx」→ 选文件 → 预览数量 → 确认导入。
|
|
6
|
+
- 导入映射抽到 `lib/import-map.js`,页面与 CLI 共用;导入按「范围 + 标题」去重。
|
|
7
|
+
|
|
8
|
+
## 0.4.0
|
|
9
|
+
|
|
10
|
+
- 新增 xlsx 导入:`node bin/import.mjs --xlsx <文件> [--dry-run]`。
|
|
11
|
+
- 任务主表 → 归档历史条目(done)
|
|
12
|
+
- 长期滚动项 → 活跃条目(TODO→待办、PARTIAL/FIX→进行中、BLOCKED→受阻、暂缓→待规划)
|
|
13
|
+
- 节点说明 → 一条 design 资产
|
|
14
|
+
- 零依赖 XLSX 读取器(`lib/xlsx.js`,只读 ZIP + sharedStrings,不装任何包)。
|
|
15
|
+
- 看板 Tab 调到「对话」左边(order -10)。
|
|
16
|
+
|
|
3
17
|
## 0.3.1
|
|
4
18
|
|
|
5
19
|
- 入口改到顶部视图导航(`conversation.view`),像记忆插件的「记忆 / 技能 / 待办」那样以 Tab 出现,不再占左侧导航。
|
package/README.md
CHANGED
|
@@ -63,6 +63,19 @@ node bin/board.mjs show <id>
|
|
|
63
63
|
node bin/board.mjs brief
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
**页面导入(推荐)**
|
|
67
|
+
|
|
68
|
+
看板面板 → 右上角「导入 xlsx」→ 选择文件 → 看预览(主表 / 滚动项 / 节点说明各多少条)→ 确认导入。
|
|
69
|
+
|
|
70
|
+
**命令行导入**
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run
|
|
74
|
+
node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
主表进归档(历史台账),长期滚动项进活跃列,节点说明合成一条 design 资产;重复条目按「范围 + 标题」跳过。
|
|
78
|
+
|
|
66
79
|
## 工具
|
|
67
80
|
|
|
68
81
|
| 工具 | 作用 |
|
|
@@ -80,7 +93,7 @@ node bin/board.mjs brief
|
|
|
80
93
|
- [x] 0.1.0 骨架
|
|
81
94
|
- [x] 0.2.0 核心 + 工具
|
|
82
95
|
- [x] 0.3.0 DSH 内页面(表格 / 看板 / 收件箱)+ 回滚
|
|
83
|
-
- [
|
|
96
|
+
- [x] 0.4.0 xlsx 导入(列映射 + 预览 + 冲突报告)
|
|
84
97
|
- [ ] 0.5.0 brief 注入与复用统计
|
|
85
98
|
|
|
86
99
|
## 开发
|
package/bin/import.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 命令行导入(页面导入之外的备用入口)。
|
|
4
|
+
*
|
|
5
|
+
* node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run
|
|
6
|
+
* node bin/import.mjs --xlsx "..." --data-dir "C:\...\.dsh\saibo_kanban"
|
|
7
|
+
*
|
|
8
|
+
* 页面操作是主路径:看板面板 → 导入 → 选择 xlsx。
|
|
9
|
+
*/
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { readXlsx } from '../lib/xlsx.js';
|
|
12
|
+
import { buildImport, describeImport } from '../lib/import-map.js';
|
|
13
|
+
import { Store, defaultDataDir } from '../store.js';
|
|
14
|
+
import { normalizeKinds } from '../core.js';
|
|
15
|
+
|
|
16
|
+
const argv = process.argv.slice(2);
|
|
17
|
+
const flags = {};
|
|
18
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
19
|
+
const a = argv[i];
|
|
20
|
+
if (a.startsWith('--')) {
|
|
21
|
+
const key = a.slice(2);
|
|
22
|
+
const next = argv[i + 1];
|
|
23
|
+
if (next !== undefined && !next.startsWith('--')) { flags[key] = next; i += 1; }
|
|
24
|
+
else flags[key] = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const file = flags.xlsx;
|
|
28
|
+
if (!file) {
|
|
29
|
+
console.error('用法: node bin/import.mjs --xlsx <文件> [--dry-run] [--data-dir <目录>]');
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const sheets = readXlsx(file);
|
|
34
|
+
const plan = buildImport(sheets);
|
|
35
|
+
const desc = describeImport(plan);
|
|
36
|
+
console.log(`文件:${file}`);
|
|
37
|
+
console.log(`主表 ${desc.main} 条(归档,done)`);
|
|
38
|
+
console.log(`滚动项 ${desc.rolling} 条(活跃)`);
|
|
39
|
+
console.log(`节点说明:${desc.notes} 条`);
|
|
40
|
+
console.log('状态分布:', desc.byStatus);
|
|
41
|
+
console.log('样例:');
|
|
42
|
+
for (const s of desc.samples) console.log(' -', s.status, '|', s.scope, '|', s.title);
|
|
43
|
+
|
|
44
|
+
if (flags['dry-run'] === true) {
|
|
45
|
+
console.log('\n--dry-run:不写入。');
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const dataDir = flags['data-dir'] || defaultDataDir();
|
|
50
|
+
const store = new Store({ dataDir, kinds: normalizeKinds(null) }).load();
|
|
51
|
+
const existing = new Set([...store.items.values()].map(i => `${i.scope}|${i.title}`));
|
|
52
|
+
let imported = 0;
|
|
53
|
+
let skipped = 0;
|
|
54
|
+
const write = (item, note) => {
|
|
55
|
+
if (existing.has(`${item.scope}|${item.title}`)) { skipped += 1; return; }
|
|
56
|
+
const created = store.record({
|
|
57
|
+
title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
|
|
58
|
+
}, { by: 'human', note });
|
|
59
|
+
if (item.archived) store.archive(created.id, { by: 'human', note: '导入历史台账' });
|
|
60
|
+
existing.add(`${item.scope}|${item.title}`);
|
|
61
|
+
imported += 1;
|
|
62
|
+
};
|
|
63
|
+
for (const item of plan.main) write(item, '导入:任务主表');
|
|
64
|
+
for (const item of plan.rolling) write(item, '导入:长期滚动项');
|
|
65
|
+
if (plan.notes) write(plan.notes, '导入:节点说明');
|
|
66
|
+
console.log(`\n已导入 ${imported} 条,跳过重复 ${skipped} 条 → ${path.join(dataDir, 'records.jsonl')}`);
|
package/client.js
CHANGED
|
@@ -23,8 +23,17 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
const kindLabel = id => (KINDS.find(k => k.id === id) || { label: id }).label;
|
|
24
24
|
const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
const
|
|
26
|
+
function toBase64(buf) {
|
|
27
|
+
const bytes = new Uint8Array(buf);
|
|
28
|
+
let s = '';
|
|
29
|
+
const chunk = 0x8000;
|
|
30
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
31
|
+
s += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk));
|
|
32
|
+
}
|
|
33
|
+
return btoa(s);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function api(method, args) { const res = await fetch('/saibo-kanban/api', {
|
|
28
37
|
method: 'POST',
|
|
29
38
|
headers: { 'content-type': 'application/json' },
|
|
30
39
|
body: JSON.stringify({ method, args: args || {} })
|
|
@@ -86,6 +95,14 @@ window.__ModuleLoader__.load({
|
|
|
86
95
|
.sk-toast { position:absolute; left:50%; bottom:18px; transform:translateX(-50%); background:var(--dsw-alias-label-primary,#17181a); color:var(--dsw-alias-bg-base,#fff); padding:8px 14px; border-radius:9px; font-size:12.5px; z-index:9; }
|
|
87
96
|
.sk-empty { padding:40px; text-align:center; color:var(--dsw-alias-label-secondary,#6b7280); }
|
|
88
97
|
.sk-rail { display:flex; align-items:center; justify-content:center; }
|
|
98
|
+
.sk-modal { position:absolute; inset:0; background:rgba(15,18,25,.35); display:flex; align-items:center; justify-content:center; z-index:8; }
|
|
99
|
+
.sk-dialog { width:min(520px,92%); background:var(--dsw-alias-bg-layer-1,#fff); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:12px; box-shadow:0 18px 48px rgba(16,24,40,.22); padding:16px; display:flex; flex-direction:column; gap:10px; }
|
|
100
|
+
.sk-dialog h3 { margin:0; font-size:15px; }
|
|
101
|
+
.sk-dialog .hint { color:var(--dsw-alias-label-secondary,#6b7280); font-size:12px; line-height:1.6; }
|
|
102
|
+
.sk-dialog .row { display:flex; gap:8px; justify-content:flex-end; }
|
|
103
|
+
.sk-dialog input[type=file] { font:inherit; font-size:12.5px; }
|
|
104
|
+
.sk-kv { display:flex; gap:12px; flex-wrap:wrap; font-size:12.5px; }
|
|
105
|
+
.sk-kv b { font-weight:650; }
|
|
89
106
|
`;
|
|
90
107
|
|
|
91
108
|
function Panel() {
|
|
@@ -99,6 +116,10 @@ window.__ModuleLoader__.load({
|
|
|
99
116
|
const [overCol, setOverCol] = useState(null);
|
|
100
117
|
const [toast, setToast] = useState('');
|
|
101
118
|
const [busy, setBusy] = useState(false);
|
|
119
|
+
const [imp, setImp] = useState(null);
|
|
120
|
+
const [impBusy, setImpBusy] = useState(false);
|
|
121
|
+
const [impError, setImpError] = useState('');
|
|
122
|
+
const fileRef = useRef(null);
|
|
102
123
|
const toastTimer = useRef(null);
|
|
103
124
|
|
|
104
125
|
const say = useCallback(msg => {
|
|
@@ -168,6 +189,24 @@ window.__ModuleLoader__.load({
|
|
|
168
189
|
h('input', {
|
|
169
190
|
className: 'sk-search', placeholder: '搜索标题 / 编号 / 范围',
|
|
170
191
|
value: query, onChange: e => setQuery(e.target.value)
|
|
192
|
+
}),
|
|
193
|
+
h('button', { className: 'sk-btn', onClick: () => fileRef.current && fileRef.current.click() }, '导入 xlsx'),
|
|
194
|
+
h('input', {
|
|
195
|
+
ref: fileRef, type: 'file', accept: '.xlsx', style: { display: 'none' },
|
|
196
|
+
onChange: async e => {
|
|
197
|
+
const file = e.target.files && e.target.files[0];
|
|
198
|
+
e.target.value = '';
|
|
199
|
+
if (!file) return;
|
|
200
|
+
setImpBusy(true); setImpError('');
|
|
201
|
+
try {
|
|
202
|
+
const buf = await file.arrayBuffer();
|
|
203
|
+
const data = toBase64(buf);
|
|
204
|
+
const r = await api('import.preview', { data });
|
|
205
|
+
setImp({ name: file.name, data, summary: r.summary });
|
|
206
|
+
} catch (err) {
|
|
207
|
+
setImp({ name: file.name, data: null, summary: null, error: err.message });
|
|
208
|
+
} finally { setImpBusy(false); }
|
|
209
|
+
}
|
|
171
210
|
})
|
|
172
211
|
);
|
|
173
212
|
|
|
@@ -331,10 +370,40 @@ window.__ModuleLoader__.load({
|
|
|
331
370
|
)
|
|
332
371
|
) : null;
|
|
333
372
|
|
|
373
|
+
const importDialog = imp ? h('div', { className: 'sk-modal' },
|
|
374
|
+
h('div', { className: 'sk-dialog' },
|
|
375
|
+
h('h3', null, '导入 ' + (imp.name || 'xlsx')),
|
|
376
|
+
imp.error ? h('div', { className: 'hint', style: { color: 'var(--dsw-alias-state-error-primary,#dc2626)' } }, imp.error) : null,
|
|
377
|
+
imp.summary ? h('div', { className: 'sk-kv' },
|
|
378
|
+
h('span', null, '主表 ', h('b', null, String(imp.summary.main)), ' 条(归档)'),
|
|
379
|
+
h('span', null, '滚动项 ', h('b', null, String(imp.summary.rolling)), ' 条(活跃)'),
|
|
380
|
+
h('span', null, '节点说明 ', h('b', null, String(imp.summary.notes)), ' 条')
|
|
381
|
+
) : h('div', { className: 'hint' }, impBusy ? '解析中…' : ''),
|
|
382
|
+
imp.summary ? h('div', { className: 'hint' },
|
|
383
|
+
Object.entries(imp.summary.byStatus || {}).map(([k, v]) => k + ' ' + v).join(' · ')) : null,
|
|
384
|
+
h('div', { className: 'row' },
|
|
385
|
+
h('button', { className: 'sk-btn', onClick: () => { setImp(null); setImpError(''); } }, '取消'),
|
|
386
|
+
imp.summary ? h('button', {
|
|
387
|
+
className: 'sk-btn primary',
|
|
388
|
+
onClick: async () => {
|
|
389
|
+
setImpBusy(true); setImpError('');
|
|
390
|
+
try {
|
|
391
|
+
const r = await api('import.apply', { data: imp.data });
|
|
392
|
+
setImp(null); await load();
|
|
393
|
+
say('已导入 ' + r.imported + ' 条,跳过重复 ' + r.skipped + ' 条');
|
|
394
|
+
} catch (err) { setImpError(err.message); }
|
|
395
|
+
finally { setImpBusy(false); }
|
|
396
|
+
}
|
|
397
|
+
}, impBusy ? '导入中…' : '确认导入') : null
|
|
398
|
+
)
|
|
399
|
+
)
|
|
400
|
+
) : null;
|
|
401
|
+
|
|
334
402
|
return h('div', { className: 'sk', style: { position: 'relative' } },
|
|
335
403
|
h('style', null, CSS),
|
|
336
404
|
head,
|
|
337
405
|
h('div', { className: 'sk-body' }, error ? h('div', { className: 'sk-empty', style: { color: 'var(--dsw-alias-state-error-primary,#dc2626)' } }, error) : content),
|
|
406
|
+
importDialog,
|
|
338
407
|
drawer,
|
|
339
408
|
toast ? h('div', { className: 'sk-toast' }, toast) : null
|
|
340
409
|
);
|
|
@@ -365,7 +434,7 @@ window.__ModuleLoader__.load({
|
|
|
365
434
|
ctx.slots.inject('conversation.view', () => ctx.slots.register({
|
|
366
435
|
name: 'conversation.view',
|
|
367
436
|
id: 'saibo-kanban',
|
|
368
|
-
order:
|
|
437
|
+
order: -10,
|
|
369
438
|
label: '看板'
|
|
370
439
|
}, Panel));
|
|
371
440
|
}
|
package/index.js
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import { Store, defaultDataDir } from './store.js';
|
|
9
9
|
import { createTools } from './tools.js';
|
|
10
10
|
import { normalizeKinds } from './core.js';
|
|
11
|
+
import { readXlsxBuffer } from './lib/xlsx.js';
|
|
12
|
+
import { buildImport, describeImport } from './lib/import-map.js';
|
|
11
13
|
|
|
12
14
|
export const inject = ['tools', 'webServer'];
|
|
13
15
|
|
|
@@ -96,6 +98,14 @@ function dispatch(store, method, args) {
|
|
|
96
98
|
case 'brief': {
|
|
97
99
|
return { markdown: store.brief({}) };
|
|
98
100
|
}
|
|
101
|
+
case 'import.preview': {
|
|
102
|
+
const plan = buildImport(readXlsxBuffer(decodeData(args.data)));
|
|
103
|
+
return { summary: describeImport(plan) };
|
|
104
|
+
}
|
|
105
|
+
case 'import.apply': {
|
|
106
|
+
const plan = buildImport(readXlsxBuffer(decodeData(args.data)));
|
|
107
|
+
return applyPlan(store, plan);
|
|
108
|
+
}
|
|
99
109
|
default:
|
|
100
110
|
throw new Error(`未知方法: ${method}`);
|
|
101
111
|
}
|
|
@@ -117,6 +127,30 @@ function publicItem(item) {
|
|
|
117
127
|
};
|
|
118
128
|
}
|
|
119
129
|
|
|
130
|
+
function decodeData(data) {
|
|
131
|
+
if (typeof data !== 'string' || data.length < 16) throw new Error('没有收到文件内容');
|
|
132
|
+
return Buffer.from(data, 'base64');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function applyPlan(store, plan) {
|
|
136
|
+
const existing = new Set([...store.items.values()].map(i => `${i.scope}|${i.title}`));
|
|
137
|
+
let imported = 0;
|
|
138
|
+
let skipped = 0;
|
|
139
|
+
const write = (item, note) => {
|
|
140
|
+
if (existing.has(`${item.scope}|${item.title}`)) { skipped += 1; return; }
|
|
141
|
+
const created = store.record({
|
|
142
|
+
title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
|
|
143
|
+
}, { by: 'human', note });
|
|
144
|
+
if (item.archived) store.archive(created.id, { by: 'human', note: '导入历史台账' });
|
|
145
|
+
existing.add(`${item.scope}|${item.title}`);
|
|
146
|
+
imported += 1;
|
|
147
|
+
};
|
|
148
|
+
for (const item of plan.main) write(item, '导入:任务主表');
|
|
149
|
+
for (const item of plan.rolling) write(item, '导入:长期滚动项');
|
|
150
|
+
if (plan.notes) write(plan.notes, '导入:节点说明');
|
|
151
|
+
return { imported, skipped, summary: describeImport(plan) };
|
|
152
|
+
}
|
|
153
|
+
|
|
120
154
|
function readJsonBody(req) {
|
|
121
155
|
return new Promise((resolve, reject) => {
|
|
122
156
|
let body = '';
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* import-map.js — xlsx 工作表 → 看板条目的映射规则。
|
|
3
|
+
*
|
|
4
|
+
* CLI 和页面共用这一份,避免两边规则漂移。
|
|
5
|
+
*/
|
|
6
|
+
import { STATUSES } from '../core.js';
|
|
7
|
+
|
|
8
|
+
export const STATUS_MAP = {
|
|
9
|
+
DONE: 'done',
|
|
10
|
+
'DONE(描述修正)': 'done',
|
|
11
|
+
'DONE(已覆盖)': 'done',
|
|
12
|
+
TODO: 'todo',
|
|
13
|
+
PARTIAL: 'in_progress',
|
|
14
|
+
FIX: 'in_progress',
|
|
15
|
+
BLOCKED: 'blocked',
|
|
16
|
+
暂缓: 'backlog'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
|
|
20
|
+
|
|
21
|
+
function headerIndex(rows, name) {
|
|
22
|
+
for (let i = 0; i < Math.min(rows.length, 5); i += 1) {
|
|
23
|
+
if ((rows[i] || []).some(v => String(v).trim() === name)) return i;
|
|
24
|
+
}
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function col(rows, headerRow, name) {
|
|
29
|
+
const row = rows[headerRow] || [];
|
|
30
|
+
for (let i = 0; i < row.length; i += 1) if (String(row[i]).trim() === name) return i;
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function cell(row, idx) {
|
|
35
|
+
if (idx < 0) return '';
|
|
36
|
+
const v = row[idx];
|
|
37
|
+
return v === undefined || v === null ? '' : String(v).trim();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function mapMain(rows) {
|
|
41
|
+
const h = headerIndex(rows, '编号');
|
|
42
|
+
const cId = col(rows, h, '编号');
|
|
43
|
+
const cGroup = col(rows, h, '分组');
|
|
44
|
+
const cTitle = col(rows, h, '名称');
|
|
45
|
+
const cBody = col(rows, h, '详细说明');
|
|
46
|
+
const cStatus = col(rows, h, '状态');
|
|
47
|
+
const cType = col(rows, h, '类型');
|
|
48
|
+
const out = [];
|
|
49
|
+
for (let i = h + 1; i < rows.length; i += 1) {
|
|
50
|
+
const title = cell(rows[i], cTitle);
|
|
51
|
+
if (!title) continue;
|
|
52
|
+
out.push({
|
|
53
|
+
title,
|
|
54
|
+
body: [
|
|
55
|
+
cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
|
|
56
|
+
cell(rows[i], cType) ? `类型:${cell(rows[i], cType)}` : '',
|
|
57
|
+
cell(rows[i], cBody)
|
|
58
|
+
].filter(Boolean).join('\n'),
|
|
59
|
+
kind: 'task',
|
|
60
|
+
scope: cell(rows[i], cGroup),
|
|
61
|
+
status: STATUS_MAP[cell(rows[i], cStatus)] || 'done',
|
|
62
|
+
archived: true,
|
|
63
|
+
ext: cell(rows[i], cId)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function mapRolling(rows) {
|
|
70
|
+
const h = headerIndex(rows, '编号');
|
|
71
|
+
const cId = col(rows, h, '编号');
|
|
72
|
+
const cGroup = col(rows, h, '分组');
|
|
73
|
+
const cTitle = col(rows, h, '名称');
|
|
74
|
+
const cBody = col(rows, h, '详细说明');
|
|
75
|
+
const cStatus = col(rows, h, '状态');
|
|
76
|
+
const cPri = col(rows, h, '优先级');
|
|
77
|
+
const cRoll = col(rows, h, '滚动次数');
|
|
78
|
+
const cFirst = col(rows, h, '首次来源');
|
|
79
|
+
const cLast = col(rows, h, '最近来源');
|
|
80
|
+
const out = [];
|
|
81
|
+
for (let i = h + 1; i < rows.length; i += 1) {
|
|
82
|
+
const title = cell(rows[i], cTitle);
|
|
83
|
+
if (!title) continue;
|
|
84
|
+
out.push({
|
|
85
|
+
title,
|
|
86
|
+
body: [
|
|
87
|
+
cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
|
|
88
|
+
cell(rows[i], cBody),
|
|
89
|
+
cell(rows[i], cPri) ? `优先级:${cell(rows[i], cPri)}` : '',
|
|
90
|
+
cell(rows[i], cRoll) ? `滚动次数:${cell(rows[i], cRoll)}` : '',
|
|
91
|
+
cell(rows[i], cFirst) ? `首次来源:${cell(rows[i], cFirst)}` : '',
|
|
92
|
+
cell(rows[i], cLast) ? `最近来源:${cell(rows[i], cLast)}` : ''
|
|
93
|
+
].filter(Boolean).join('\n'),
|
|
94
|
+
kind: 'task',
|
|
95
|
+
scope: cell(rows[i], cGroup),
|
|
96
|
+
status: STATUS_MAP[cell(rows[i], cStatus)] || 'todo',
|
|
97
|
+
archived: false,
|
|
98
|
+
ext: cell(rows[i], cId)
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function mapNotes(rows) {
|
|
105
|
+
const text = rows.map(r => cell(r, 0)).join('\n').trim();
|
|
106
|
+
if (!text) return null;
|
|
107
|
+
const firstLine = text.split('\n').find(l => l.trim()) || '节点说明';
|
|
108
|
+
return {
|
|
109
|
+
title: firstLine.replace(/^#+\s*/, '').slice(0, 120),
|
|
110
|
+
body: text,
|
|
111
|
+
kind: 'design',
|
|
112
|
+
scope: '设计',
|
|
113
|
+
status: 'done',
|
|
114
|
+
archived: false,
|
|
115
|
+
ext: 'nodes'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 把工作簿整理成待导入集合。 */
|
|
120
|
+
export function buildImport(sheets) {
|
|
121
|
+
const byName = new Map(sheets.map(s => [s.name, s.rows]));
|
|
122
|
+
const mainRows = byName.get('任务主表') || sheets[0]?.rows || [];
|
|
123
|
+
const rollingRows = byName.get('长期滚动项') || sheets[1]?.rows || [];
|
|
124
|
+
const notesRows = byName.get('节点说明') || sheets[2]?.rows || [];
|
|
125
|
+
return {
|
|
126
|
+
main: mapMain(mainRows),
|
|
127
|
+
rolling: mapRolling(rollingRows),
|
|
128
|
+
notes: mapNotes(notesRows)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function describeImport({ main, rolling, notes }) {
|
|
133
|
+
const byStatus = {};
|
|
134
|
+
for (const item of rolling) {
|
|
135
|
+
const label = statusLabel(item.status);
|
|
136
|
+
byStatus[label] = (byStatus[label] || 0) + 1;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
main: main.length,
|
|
140
|
+
rolling: rolling.length,
|
|
141
|
+
notes: notes ? 1 : 0,
|
|
142
|
+
byStatus,
|
|
143
|
+
samples: rolling.slice(0, 5).map(r => ({ title: r.title, scope: r.scope, status: r.status }))
|
|
144
|
+
};
|
|
145
|
+
}
|
package/lib/xlsx.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xlsx.js — 零依赖的最小 XLSX 读取器。
|
|
3
|
+
*
|
|
4
|
+
* 只做导入需要的事:读 ZIP 中央目录,拿 sharedStrings 和工作表 XML,
|
|
5
|
+
* 还原成二维数组。支持内联字符串、共享字符串、数字、布尔和公式缓存值。
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import zlib from 'node:zlib';
|
|
9
|
+
|
|
10
|
+
const EOCD = 0x06054b50;
|
|
11
|
+
const CEN = 0x02014b50;
|
|
12
|
+
const LOC = 0x04034b50;
|
|
13
|
+
|
|
14
|
+
function findEocd(buf) {
|
|
15
|
+
const start = Math.max(0, buf.length - 66000);
|
|
16
|
+
for (let i = buf.length - 22; i >= start; i -= 1) {
|
|
17
|
+
if (buf.readUInt32LE(i) === EOCD) return i;
|
|
18
|
+
}
|
|
19
|
+
throw new Error('不是有效的 xlsx(找不到 ZIP 目录)');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function readEntries(buf) {
|
|
23
|
+
const eocd = findEocd(buf);
|
|
24
|
+
const total = buf.readUInt16LE(eocd + 10);
|
|
25
|
+
const cdOffset = buf.readUInt32LE(eocd + 16);
|
|
26
|
+
const entries = new Map();
|
|
27
|
+
let p = cdOffset;
|
|
28
|
+
for (let i = 0; i < total; i += 1) {
|
|
29
|
+
if (buf.readUInt32LE(p) !== CEN) throw new Error('ZIP 中央目录损坏');
|
|
30
|
+
const method = buf.readUInt16LE(p + 10);
|
|
31
|
+
const compSize = buf.readUInt32LE(p + 20);
|
|
32
|
+
const nameLen = buf.readUInt16LE(p + 28);
|
|
33
|
+
const extraLen = buf.readUInt16LE(p + 30);
|
|
34
|
+
const commentLen = buf.readUInt16LE(p + 32);
|
|
35
|
+
const localOffset = buf.readUInt32LE(p + 42);
|
|
36
|
+
const name = buf.toString('utf8', p + 46, p + 46 + nameLen);
|
|
37
|
+
entries.set(name, { method, compSize, localOffset });
|
|
38
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
39
|
+
}
|
|
40
|
+
return entries;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readFile(buf, entries, name) {
|
|
44
|
+
const entry = entries.get(name);
|
|
45
|
+
if (!entry) return null;
|
|
46
|
+
const p = entry.localOffset;
|
|
47
|
+
if (buf.readUInt32LE(p) !== LOC) throw new Error(`ZIP 本地头损坏: ${name}`);
|
|
48
|
+
const nameLen = buf.readUInt16LE(p + 26);
|
|
49
|
+
const extraLen = buf.readUInt16LE(p + 28);
|
|
50
|
+
const start = p + 30 + nameLen + extraLen;
|
|
51
|
+
const data = buf.subarray(start, start + entry.compSize);
|
|
52
|
+
if (entry.method === 0) return data.toString('utf8');
|
|
53
|
+
if (entry.method === 8) return zlib.inflateRawSync(data).toString('utf8');
|
|
54
|
+
throw new Error(`不支持的压缩方式 ${entry.method}: ${name}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const decode = s => s
|
|
58
|
+
.replace(/</g, '<')
|
|
59
|
+
.replace(/>/g, '>')
|
|
60
|
+
.replace(/"/g, '"')
|
|
61
|
+
.replace(/'/g, "'")
|
|
62
|
+
.replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(Number(n)))
|
|
63
|
+
.replace(/&/g, '&');
|
|
64
|
+
|
|
65
|
+
function xmlText(xml) {
|
|
66
|
+
const parts = [];
|
|
67
|
+
const re = /<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/g;
|
|
68
|
+
let m;
|
|
69
|
+
while ((m = re.exec(xml)) !== null) parts.push(decode(m[1]));
|
|
70
|
+
return parts.join('');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readSharedStrings(xml) {
|
|
74
|
+
if (!xml) return [];
|
|
75
|
+
const out = [];
|
|
76
|
+
const re = /<si(?:\s[^>]*)?>([\s\S]*?)<\/si>/g;
|
|
77
|
+
let m;
|
|
78
|
+
while ((m = re.exec(xml)) !== null) out.push(xmlText(m[1]));
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function colIndex(ref) {
|
|
83
|
+
const letters = ref.replace(/\d+/g, '');
|
|
84
|
+
let n = 0;
|
|
85
|
+
for (const ch of letters) n = n * 26 + (ch.charCodeAt(0) - 64);
|
|
86
|
+
return n - 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function readSheet(xml, shared) {
|
|
90
|
+
const rows = [];
|
|
91
|
+
const rowRe = /<row[^>]*r="(\d+)"[^>]*>([\s\S]*?)<\/row>/g;
|
|
92
|
+
let rm;
|
|
93
|
+
while ((rm = rowRe.exec(xml)) !== null) {
|
|
94
|
+
const rowIndex = Number(rm[1]) - 1;
|
|
95
|
+
const cells = [];
|
|
96
|
+
const cellRe = /<c([^>]*)>([\s\S]*?)<\/c>/g;
|
|
97
|
+
let cm;
|
|
98
|
+
while ((cm = cellRe.exec(rm[2])) !== null) {
|
|
99
|
+
const attrs = cm[1];
|
|
100
|
+
const body = cm[2];
|
|
101
|
+
const refMatch = /r="([A-Z]+)\d+"/.exec(attrs);
|
|
102
|
+
const idx = refMatch ? colIndex(refMatch[1]) : cells.length;
|
|
103
|
+
const type = /t="([^"]+)"/.exec(attrs);
|
|
104
|
+
let value = '';
|
|
105
|
+
if (type && type[1] === 's') {
|
|
106
|
+
const v = /<v>([\s\S]*?)<\/v>/.exec(body);
|
|
107
|
+
value = v ? (shared[Number(v[1])] ?? '') : '';
|
|
108
|
+
} else if (type && type[1] === 'inlineStr') {
|
|
109
|
+
value = xmlText(body);
|
|
110
|
+
} else if (type && (type[1] === 'str' || type[1] === 'b')) {
|
|
111
|
+
const v = /<v>([\s\S]*?)<\/v>/.exec(body);
|
|
112
|
+
value = v ? decode(v[1]) : '';
|
|
113
|
+
} else {
|
|
114
|
+
const v = /<v>([\s\S]*?)<\/v>/.exec(body);
|
|
115
|
+
value = v ? decode(v[1]) : '';
|
|
116
|
+
}
|
|
117
|
+
cells[idx] = value;
|
|
118
|
+
}
|
|
119
|
+
rows[rowIndex] = cells;
|
|
120
|
+
}
|
|
121
|
+
for (let i = 0; i < rows.length; i += 1) if (!rows[i]) rows[i] = [];
|
|
122
|
+
return rows;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 读取工作簿,返回 [{ name, rows }],rows 为二维字符串数组。 */
|
|
126
|
+
export function readXlsx(file) {
|
|
127
|
+
return readXlsxBuffer(fs.readFileSync(file));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** 从内存读取工作簿(页面导入用)。 */
|
|
131
|
+
export function readXlsxBuffer(buf) {
|
|
132
|
+
const entries = readEntries(buf);
|
|
133
|
+
const shared = readSharedStrings(readFile(buf, entries, 'xl/sharedStrings.xml'));
|
|
134
|
+
const workbook = readFile(buf, entries, 'xl/workbook.xml');
|
|
135
|
+
const rels = readFile(buf, entries, 'xl/_rels/workbook.xml.rels');
|
|
136
|
+
if (!workbook || !rels) throw new Error('缺少 workbook.xml 或 rels');
|
|
137
|
+
|
|
138
|
+
const relMap = new Map();
|
|
139
|
+
const relRe = /<Relationship[^>]*Id="([^"]+)"[^>]*Target="([^"]+)"[^>]*\/>/g;
|
|
140
|
+
let rm;
|
|
141
|
+
while ((rm = relRe.exec(rels)) !== null) {
|
|
142
|
+
relMap.set(rm[1], rm[2].replace(/^\/?xl\//, ''));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const sheets = [];
|
|
146
|
+
const sheetRe = /<sheet[^>]*name="([^"]*)"[^>]*r:id="([^"]+)"[^>]*\/>/g;
|
|
147
|
+
let sm;
|
|
148
|
+
while ((sm = sheetRe.exec(workbook)) !== null) {
|
|
149
|
+
const name = decode(sm[1]);
|
|
150
|
+
const target = relMap.get(sm[2]);
|
|
151
|
+
if (!target) continue;
|
|
152
|
+
const xml = readFile(buf, entries, 'xl/' + target);
|
|
153
|
+
if (!xml) continue;
|
|
154
|
+
sheets.push({ name, rows: readSheet(xml, shared) });
|
|
155
|
+
}
|
|
156
|
+
return sheets;
|
|
157
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saibo-kanban",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "AI 与人共用的活看板:草稿进收件箱、人做分拣、字段级修订可回滚,零 token 纠错。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"core.js",
|
|
31
31
|
"store.js",
|
|
32
32
|
"tools.js",
|
|
33
|
+
"lib",
|
|
33
34
|
"bin",
|
|
34
35
|
"cordis.patch.yml",
|
|
35
36
|
"locale/*.json",
|
|
@@ -53,7 +54,8 @@
|
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|
|
55
56
|
"check": "node --check index.js && node --check core.js && node --check store.js && node --check tools.js",
|
|
56
|
-
"test": "node test/run.mjs"
|
|
57
|
+
"test": "node test/run.mjs",
|
|
58
|
+
"import": "node bin/import.mjs"
|
|
57
59
|
},
|
|
58
60
|
"repository": {
|
|
59
61
|
"type": "git",
|