@jayyuen66/dsh-dir-prep-organize 0.1.6 → 0.1.7

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/client.js CHANGED
@@ -7,8 +7,9 @@ window.__ModuleLoader__.load({
7
7
  let exports = module.exports;
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
9
  let react = require("react");
10
+ let zod = require("zod");
10
11
  // node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
11
- function e(e) {
12
+ function e$1(e) {
12
13
  return typeof e == `object` && !!e && !Array.isArray(e);
13
14
  }
14
15
  // src/templates.ts
@@ -63,7 +64,7 @@ function uniqueEntryId(candidate, index, seen) {
63
64
  * 返回 undefined 表示该条应被剔除。 */
64
65
  function normalizeEntry(item, index, seen) {
65
66
  let result;
66
- if (e(item)) {
67
+ if (e$1(item)) {
67
68
  const { id, name, description, text, group, emoji } = item;
68
69
  const nextName = trimField(name);
69
70
  const nextText = trimField(text);
@@ -155,7 +156,7 @@ const CARD_STYLES = [
155
156
  ".dpi-btn-err:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,currentColor)}",
156
157
  ".dpi-spin{animation:dpi-rotate .8s linear infinite}",
157
158
  "@keyframes dpi-rotate{to{transform:rotate(360deg)}}",
158
- "@media (prefers-reduced-motion:reduce){.dpi-spin{animation:none}.dpi-btn,.dpic-card,.dpic-chevron{transition:none}}",
159
+ "@media (prefers-reduced-motion:reduce){.dpi-spin{animation:none}.dpi-btn{transition:none}}",
159
160
  ".dpi-wrap{position:relative;display:inline-flex;isolation:isolate}",
160
161
  ".dpi-menu{position:absolute;bottom:calc(100% + 6px);right:0;z-index:50;min-width:224px;max-height:340px;overflow-y:auto;background:var(--dsw-menu-surface-fill,transparent);backdrop-filter:var(--dsw-menu-backdrop-filter,none);border:0;border-radius:10px;padding:4px;display:flex;flex-direction:column;gap:2px;box-shadow:var(--dsw-elevation-panel,none)}",
161
162
  ".dpi-item{appearance:none;border:none;background:transparent;color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;line-height:1.4;text-align:left;border-radius:6px;padding:8px 10px;cursor:pointer;white-space:nowrap}",
@@ -167,50 +168,28 @@ const CARD_STYLES = [
167
168
  ".dpi-split .dpi-caret svg{width:10px;height:10px}",
168
169
  ".dpi-group{padding:2px 0}",
169
170
  ".dpi-grouph{font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary,inherit);padding:6px 10px 2px;letter-spacing:.02em}",
170
- ".dpic-card{border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-3,transparent);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}",
171
- ".dpic-card:hover{border-color:var(--dsw-alias-label-dimmed,currentColor)}",
172
- ".dpic-card-open{background:var(--dsw-alias-bg-layer-2,transparent);border-color:var(--dsw-alias-label-dimmed,currentColor)}",
173
- ".dpic-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}",
174
- ".dpic-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}",
175
- ".dpic-title{color:var(--dsw-alias-label-primary,inherit);font-size:15px;font-weight:600;line-height:1.4}",
176
- ".dpic-cardsub{color:var(--dsw-alias-label-tertiary,inherit);font-size:13px;line-height:1.5}",
177
- ".dpic-chevron{color:var(--dsw-alias-label-tertiary,inherit);flex:none;transition:transform .16s}",
178
- ".dpic-chevron-open{transform:rotate(180deg)}",
179
- ".dpic-body{border-top:1px solid var(--dsw-alias-border-l2,currentColor);margin:0 16px;padding:8px 0 12px;list-style:none}",
180
171
  ".dpic-row{padding:10px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}",
172
+ ".dpic-name{flex:1;min-width:0}",
173
+ ".dpic-rowhead .dpic-name{width:auto}",
174
+ ".dpic-rowhead .dpic-emoji{width:44px;flex:none;text-align:center}",
175
+ ".dpic-rowhead .dpic-group{width:84px;flex:none}",
176
+ ".dpic-desc{width:100%;margin-top:6px}",
177
+ ".dpic-text{width:100%;margin-top:6px}",
178
+ ".dpic-importpath{flex:1;min-width:0}",
179
+ ".dpic-rowhead .dpic-importpath{width:auto}",
180
+ ".dpic-del{flex:none}",
181
+ ".dpic-toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:8px 0}",
181
182
  ".dpic-rowhead{display:flex;gap:8px;align-items:center}",
182
183
  ".dpic-idx{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);flex:none;min-width:26px}",
183
- ".dpic-name,.dpic-text,.dpic-emoji,.dpic-group,.dpic-desc,.dpic-importpath{box-sizing:border-box;font:inherit;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px}",
184
- ".dpic-name{flex:1;min-width:0;font-size:12px;padding:6px 8px}",
185
- ".dpic-del{appearance:none;border:1px solid var(--dsw-alias-border-l2,currentColor);background:transparent;color:var(--dsw-alias-label-tertiary,inherit);font:inherit;font-size:12px;border-radius:6px;padding:4px 8px;cursor:pointer;flex:none}",
186
- ".dpic-del:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,currentColor);color:var(--dsw-alias-state-error-primary,currentColor)}",
187
- ".dpic-del:disabled{opacity:.55;cursor:not-allowed}",
188
- ".dpic-header:focus-visible,.dpic-del:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:1px}",
189
- ".dpic-text{width:100%;font-size:12px;line-height:1.6;padding:8px;margin-top:6px;min-height:96px;resize:vertical}",
190
- ".dpic-name:focus,.dpic-text:focus,.dpic-emoji:focus,.dpic-group:focus,.dpic-desc:focus,.dpic-importpath:focus{outline:none;border-color:var(--dsw-alias-brand-primary,currentColor)}",
191
- ".dpic-name:focus-visible,.dpic-text:focus-visible,.dpic-emoji:focus-visible,.dpic-group:focus-visible,.dpic-desc:focus-visible,.dpic-importpath:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:1px}",
192
- ".dpic-emoji{width:44px;flex:none;font-size:13px;text-align:center;padding:6px 4px}",
193
- ".dpic-group{width:84px;flex:none;font-size:12px;padding:6px 8px}",
194
- ".dpic-desc{width:100%;font-size:12px;padding:6px 8px;margin-top:6px}",
195
184
  ".dpic-importrow{padding:12px 0;border-bottom:1px dashed var(--dsw-alias-border-l2,currentColor)}",
196
- ".dpic-importpath{flex:1;min-width:0;font-size:12px;padding:6px 8px}",
197
- ".dpic-foot{display:flex;gap:8px;align-items:center;padding-top:10px;flex-wrap:wrap}",
198
- ".dpic-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2,currentColor);background:var(--dsw-alias-bg-layer-1,transparent);color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px;border-radius:8px;padding:6px 10px;cursor:pointer}",
199
- ".dpic-btn:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,currentColor);background:var(--dsw-alias-bg-layer-2,transparent)}",
200
- ".dpic-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,currentColor);outline-offset:1px}",
201
- ".dpic-btn:disabled{opacity:.55;cursor:not-allowed}",
202
- ".dpic-btn-primary{background:var(--dsw-alias-brand-primary,currentColor);border-color:var(--dsw-alias-brand-primary,currentColor);color:var(--dsw-alias-label-primary-foreground,#fff)}",
203
- ".dpic-btn-primary:hover:not(:disabled){background:var(--dsw-alias-brand-primary,currentColor);border-color:var(--dsw-alias-brand-primary,currentColor);filter:brightness(.92)}",
204
- ".dpic-btn-danger{color:var(--dsw-alias-state-error-primary,currentColor)}",
205
- ".dpic-btn-danger:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,currentColor)}",
206
185
  ".dpic-hint{font-size:12px;color:var(--dsw-alias-label-tertiary,inherit);line-height:1.5;padding-top:6px}",
207
186
  ".dpic-err{color:var(--dsw-alias-state-error-primary,currentColor)}"
208
187
  ].join("\n");
209
188
  // src/ui-messages.ts
210
189
  const UI_MESSAGES = {
211
190
  zh: {
212
- cardTitle: "模板库(输入框「模板」下拉与「润色」▾ 共用)",
213
- cardDescription: "输入框「模板」下拉与「润色」▾ 角色菜单共用这一份列表,空表即回落到内置精选角色集(生成自插件 agents/ 角色库)。留空点「导入角色」可一键导入内置全部;填路径则按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。",
191
+ rolesSection: "角色库",
192
+ rolesHint: "输入框「模板」下拉与「润色」▾ 角色菜单共用这一份列表,空表即回落到内置精选角色集(生成自插件 agents/ 角色库)。留空点「导入角色」可一键导入内置全部;填路径则按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。",
214
193
  statusReadOnly: "设置源不可写:编辑已禁用;下拉仍按当前列表生效。",
215
194
  statusNotReady: "设置源未就绪:显示当前生效列表,就绪后可编辑。",
216
195
  addTemplate: "+ 新增模板",
@@ -287,18 +266,21 @@ const UI_MESSAGES = {
287
266
  organizeNoTemplates: "无模板可选作角色风格",
288
267
  organizeRoleItem: "以「{name}」的风格润色",
289
268
  organizeWriteBackUnavailable: "输入框动作不可用,无法写回",
290
- templatesIdleTitle: "选择一条模板插入输入框(空则填入,非空则空一行追加;按分组展示)",
269
+ organizeWriteBackStale: "输入框内容已变化,润色结果未写回",
270
+ organizeBusyTitle: "输入框正在提交,暂不能润色",
271
+ templatesIdleTitle: "选择一条模板插入光标处(按分组展示)",
291
272
  templatesBrokenTitle: "输入框动作不可用,无法插入",
273
+ templatesBusyTitle: "输入框正在提交,暂不能插入模板",
292
274
  templatesGroupCommon: "通用",
293
275
  templatesAria: "插入模板",
294
- templatesEmptyHint: "无模板:在设置页「模板库」中添加或恢复默认",
276
+ templatesEmptyHint: "无模板:在设置页「角色库」中添加或恢复默认",
295
277
  builtinLoading: "正在载入内置角色模板…",
296
278
  builtinFailed: "内置模板加载失败:{message}",
297
279
  builtinRetry: "重试"
298
280
  },
299
281
  en: {
300
- cardTitle: "Template library (shared by the \"Template\" dropdown and the \"Polish\" ▾ menu)",
301
- cardDescription: "The input-box \"Template\" dropdown and the \"Polish\" ▾ role menu share this one list; an empty list falls back to the built-in curated role set (generated from this plugin's agents/ role library). Leave the path empty and press \"Import roles\" to import the whole built-in library; an explicit path is allowed within \"session cwd + built-in role library + the import allowed directories below\". Press \"Save\" after editing — it survives restarts.",
282
+ rolesSection: "Role library",
283
+ rolesHint: "The input-box \"Template\" dropdown and the \"Polish\" ▾ role menu share this one list; an empty list falls back to the built-in curated role set (generated from this plugin's agents/ role library). Leave the path empty and press \"Import roles\" to import the whole built-in library; an explicit path is allowed within \"session cwd + built-in role library + the import allowed directories below\". Press \"Save\" after editing — it survives restarts.",
302
284
  statusReadOnly: "Settings source is read-only: editing is disabled; the dropdown still uses the current list.",
303
285
  statusNotReady: "Settings source is not ready yet: showing the list currently in effect, editing unlocks once it is ready.",
304
286
  addTemplate: "+ Add template",
@@ -375,33 +357,36 @@ const UI_MESSAGES = {
375
357
  organizeNoTemplates: "No templates available as a role style",
376
358
  organizeRoleItem: "Polish in the style of \"{name}\"",
377
359
  organizeWriteBackUnavailable: "Input-box actions unavailable; cannot write back",
378
- templatesIdleTitle: "Pick a template to insert into the input box (an empty draft is filled, a non-empty one gets a blank line plus the template; shown grouped)",
360
+ organizeWriteBackStale: "The input box changed; the polished text was not applied",
361
+ organizeBusyTitle: "The input box is submitting; cannot polish right now",
362
+ templatesIdleTitle: "Pick a template to insert at the caret (shown grouped)",
379
363
  templatesBrokenTitle: "Input-box actions unavailable; cannot insert",
364
+ templatesBusyTitle: "The input box is submitting; cannot insert a template",
380
365
  templatesGroupCommon: "General",
381
366
  templatesAria: "Insert a template",
382
- templatesEmptyHint: "No templates: add or restore defaults under \"Template library\" in the settings page",
367
+ templatesEmptyHint: "No templates: add or restore defaults under \"Role library\" in the settings page",
383
368
  builtinLoading: "Loading built-in role templates…",
384
369
  builtinFailed: "Failed to load built-in templates: {message}",
385
370
  builtinRetry: "Retry"
386
371
  }
387
372
  };
388
373
  // node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
389
- function t(e) {
374
+ function t$1(e) {
390
375
  let t = Object.getOwnPropertyDescriptor(e, `message`);
391
376
  return t !== void 0 && `value` in t && typeof t.value == `string` ? t.value : void 0;
392
377
  }
393
- function n(e, r) {
378
+ function n$1(e, r) {
394
379
  if (r.has(e)) return `<circular cause>`;
395
380
  r.add(e);
396
381
  try {
397
382
  if (!(e instanceof Error)) {
398
383
  if (typeof e == `object` && e) {
399
- let n = t(e);
384
+ let n = t$1(e);
400
385
  if (n !== void 0 && n !== ``) return n;
401
386
  }
402
387
  return String(e);
403
388
  }
404
- let i = e.message === `` ? e.name : e.message, a = typeof globalThis.AggregateError == `function` && e instanceof AggregateError && e.errors.length > 0 ? ` [${e.errors.map((e) => n(e, r)).join(`; `)}]` : ``, o = e.cause === void 0 || e.cause === null ? `` : n(e.cause, r);
389
+ let i = e.message === `` ? e.name : e.message, a = typeof globalThis.AggregateError == `function` && e instanceof AggregateError && e.errors.length > 0 ? ` [${e.errors.map((e) => n$1(e, r)).join(`; `)}]` : ``, o = e.cause === void 0 || e.cause === null ? `` : n$1(e.cause, r);
405
390
  return `${i}${a}${o === `` || o === i ? `` : `: ${o}`}`;
406
391
  } catch {
407
392
  return `<unrenderable value>`;
@@ -409,8 +394,165 @@ function n(e, r) {
409
394
  r.delete(e);
410
395
  }
411
396
  }
412
- function r(e) {
413
- return n(e, /* @__PURE__ */ new Set());
397
+ function r$1(e) {
398
+ return n$1(e, /* @__PURE__ */ new Set());
399
+ }
400
+ // node_modules/@jayyuen66/dsh-plugin-shared/dist/card-ui.js
401
+ const c = `
402
+ .dsu-form{display:flex;flex-direction:column}
403
+ .dsu-section{margin-top:24px;padding-top:24px;border-top:.5px solid var(--dsw-alias-border-l1)}
404
+ .dsu-form>.dsu-section:first-child{margin-top:0;padding-top:0;border-top:0}
405
+ .dsu-sectionTitle{margin:0;font-size:15px;font-weight:600;line-height:1.4;color:var(--dsw-alias-label-primary)}
406
+ .dsu-sectionHint{margin:4px 0 0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
407
+ .dsu-statusbar{display:flex;flex-wrap:wrap;gap:4px 8px;margin-top:8px;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
408
+ .dsu-field{display:grid;grid-template-columns:minmax(0,1fr) minmax(240px,360px);column-gap:32px;align-items:center;padding:12px 0;border-top:.5px solid var(--dsw-alias-border-l2)}
409
+ .dsu-fieldMeta{display:flex;flex-direction:column;gap:4px;min-width:0}
410
+ .dsu-labelRow{display:flex;align-items:center;gap:6px;min-width:0}
411
+ .dsu-label{font-size:13px;font-weight:500;line-height:1.5;color:var(--dsw-alias-label-primary)}
412
+ .dsu-labelMono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px}
413
+ .dsu-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
414
+ .dsu-control{min-width:0;display:flex;align-items:center;gap:8px}
415
+ .dsu-fieldWide{grid-template-columns:minmax(0,1fr);align-items:start}
416
+ .dsu-fieldWide .dsu-control{width:100%;max-width:720px;margin-top:2px}
417
+ .dsu-help{display:inline-flex;align-items:center;gap:6px;min-width:0}
418
+ .dsu-helpBtn{appearance:none;border:0;background:transparent;padding:0;width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary);cursor:help;border-radius:50%;flex:none}
419
+ .dsu-help:hover .dsu-helpBtn,.dsu-helpBtn:focus-visible{color:var(--dsw-alias-label-primary)}
420
+ .dsu-helpBtn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
421
+ .dsu-tip{position:fixed;z-index:60;box-sizing:border-box;max-width:min(340px,calc(100vw - 16px));max-height:calc(100vh - 16px);overflow:auto;overflow-wrap:anywhere;padding:10px 12px;border-radius:10px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);box-shadow:0 12px 32px rgb(0 0 0 / 45%);font-size:12px;line-height:1.6;font-weight:400;color:var(--dsw-alias-label-secondary)}
422
+ .dsu-input{width:100%;height:34px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font:inherit;font-size:13px}
423
+ .dsu-input:focus-visible{outline:none;border-color:var(--dsw-alias-state-business-primary)}
424
+ .dsu-input[aria-invalid="true"]{border-color:var(--dsw-alias-state-error-primary)}
425
+ .dsu-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
426
+ .dsu-input::placeholder{color:var(--dsw-alias-label-tertiary)}
427
+ .dsu-textarea{height:auto;min-height:96px;padding:8px 12px;line-height:1.6;resize:vertical}
428
+ .dsu-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
429
+ .dsu-numberWrap{display:flex;flex-direction:column;gap:4px;width:100%;min-width:0}
430
+ .dsu-number{display:flex;align-items:center;gap:8px;min-width:0}
431
+ .dsu-number .dsu-input{min-width:0}
432
+ .dsu-unit{flex:none;font-size:12px;color:var(--dsw-alias-label-tertiary)}
433
+ .dsu-error{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-error-primary)}
434
+ .dsu-switch{appearance:none;width:36px;height:20px;border-radius:999px;border:0;padding:2px;background:var(--dsw-alias-border-l3);display:flex;align-items:center;cursor:pointer;flex:none;transition:background-color .16s}
435
+ .dsu-knob{width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-primary);transition:transform .16s,background-color .16s}
436
+ .dsu-switch[aria-checked="true"]{background:var(--dsw-alias-label-primary)}
437
+ .dsu-switch[aria-checked="true"] .dsu-knob{transform:translateX(16px);background:var(--dsw-alias-label-primary-foreground)}
438
+ .dsu-switch:disabled{opacity:.4;cursor:not-allowed}
439
+ .dsu-switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}
440
+ .dsu-selectWrap{position:relative;width:100%;min-width:0}
441
+ .dsu-select{display:flex;align-items:center;justify-content:space-between;gap:8px;text-align:left;cursor:pointer}
442
+ .dsu-select[aria-expanded="true"]{border-color:var(--dsw-alias-state-business-primary)}
443
+ .dsu-selectValue{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
444
+ .dsu-chevron{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .16s}
445
+ .dsu-select[aria-expanded="true"] .dsu-chevron{transform:rotate(180deg)}
446
+ .dsu-menu{position:fixed;z-index:70;padding:4px;background:var(--dsw-alias-bg-layer-2);border:.5px solid var(--dsw-alias-border-l3);border-radius:12px;box-shadow:0 12px 32px rgb(0 0 0 / 50%);max-height:280px;overflow:auto}
447
+ .dsu-option{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.4;width:100%;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 10px;border-radius:8px;cursor:pointer;text-align:left}
448
+ .dsu-option:hover,.dsu-option[data-active="true"]{background:var(--dsw-alias-bg-layer-3)}
449
+ .dsu-option:disabled{color:var(--dsw-alias-label-tertiary);cursor:not-allowed}
450
+ .dsu-option:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
451
+ .dsu-optionGroup{padding:6px 10px 2px;font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary)}
452
+ .dsu-check{opacity:0;flex:none}
453
+ .dsu-option[aria-selected="true"] .dsu-check{opacity:1}
454
+ .dsu-savebar{display:flex;align-items:center;gap:8px;padding:12px 0;margin-top:24px;border-top:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-base)}
455
+ .dsu-savebar[data-dirty="true"]{position:sticky;bottom:0;z-index:2;box-shadow:0 -12px 24px rgb(0 0 0 / 35%)}
456
+ .dsu-btn{appearance:none;border:.5px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;line-height:1.5;border-radius:var(--dsw-radius-md);padding:5px 14px;cursor:pointer;transition:background-color .12s,border-color .12s,color .12s,filter .12s}
457
+ .dsu-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-border-l3)}
458
+ .dsu-btn:active:not(:disabled){background:var(--dsw-alias-bg-layer-1)}
459
+ .dsu-btn:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
460
+ .dsu-btn:disabled{opacity:.4;cursor:not-allowed}
461
+ .dsu-btnPrimary{background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
462
+ .dsu-btnPrimary:hover:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.9)}
463
+ .dsu-btnPrimary:active:not(:disabled){background:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-primary);filter:brightness(.84)}
464
+ .dsu-btnDanger{color:var(--dsw-alias-state-error-primary)}
465
+ .dsu-btnDanger:hover:not(:disabled){color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary);background:var(--dsw-alias-bg-layer-2)}
466
+ .dsu-status{margin-left:auto;font-size:12px;color:var(--dsw-alias-label-tertiary)}
467
+ .dsu-statusError{color:var(--dsw-alias-state-error-primary)}
468
+ .dsu-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(200px,100%),1fr));gap:0 24px}
469
+ .dsu-grid>.dsu-field{display:flex;flex-direction:column;align-items:stretch;gap:6px;padding:10px 0;border-top:.5px solid var(--dsw-alias-border-l1)}
470
+ .dsu-grid>.dsu-field .dsu-control{width:100%}
471
+ @media (max-width:640px){
472
+ .dsu-field{grid-template-columns:minmax(0,1fr);align-items:start}
473
+ .dsu-control{width:100%;max-width:720px}
474
+ .dsu-section{margin-top:20px;padding-top:20px}
475
+ }
476
+ @media (prefers-reduced-motion:reduce){
477
+ .dsu-switch,.dsu-knob,.dsu-chevron,.dsu-btn{transition:none}
478
+ }
479
+ `;
480
+ function u(t) {
481
+ return (0, react.createElement)(`div`, { className: `dsu-form` }, t.children);
482
+ }
483
+ function d(t) {
484
+ return (0, react.createElement)(`section`, { className: `dsu-section` }, (0, react.createElement)(`h2`, { className: `dsu-sectionTitle` }, t.title), t.hint === void 0 ? null : (0, react.createElement)(`p`, { className: `dsu-sectionHint` }, t.hint), t.children);
485
+ }
486
+ function S(t) {
487
+ let n = !t.writable || t.busy || !t.dirty, r;
488
+ return r = t.error === null ? t.writable ? t.dirty ? t.dirtyLabel : t.cleanLabel : t.readOnlyLabel : t.error, (0, react.createElement)(`div`, {
489
+ className: `dsu-savebar`,
490
+ "data-dirty": t.dirty
491
+ }, (0, react.createElement)(`button`, {
492
+ type: `button`,
493
+ className: `dsu-btn dsu-btnPrimary`,
494
+ "data-field": `save`,
495
+ disabled: n,
496
+ onClick: t.onSave
497
+ }, t.busy ? t.savingLabel : t.saveLabel), (0, react.createElement)(`button`, {
498
+ type: `button`,
499
+ className: `dsu-btn`,
500
+ "data-field": `discard`,
501
+ disabled: n,
502
+ onClick: t.onDiscard
503
+ }, t.revertLabel), (0, react.createElement)(`span`, { className: t.error === null ? `dsu-status` : `dsu-status dsu-statusError` }, r));
504
+ }
505
+ // src/input-writeback.ts
506
+ /**
507
+ * 输入框异步写回的凭据与判定。
508
+ *
509
+ * 润色结果是整稿替换:发起时记下会话、草稿版本与输入动作面,返回时用**最新一帧**
510
+ * 核对。任一项在途中变了(用户继续编辑、宿主进入提交期、会话被切换、组件重挂成
511
+ * 另一份 facade),结果都不许落地——宁可报「未写回」,也不能覆盖用户后来的输入。
512
+ * 模板走插入语义(captureInsertion + insertText),由宿主按发起的选区做版本校验。
513
+ */
514
+ /** 宿主是否给了整稿替换面(润色结果最后落到 setDraft)。 */
515
+ function hasDraftFace(actions) {
516
+ return actions !== void 0 && typeof actions.setDraft === "function";
517
+ }
518
+ /** 宿主是否给了版本校验插入面(模板走这一对,不整稿覆盖)。 */
519
+ function hasInsertFace(actions) {
520
+ return actions !== void 0 && typeof actions.captureInsertion === "function" && typeof actions.insertText === "function";
521
+ }
522
+ /** 提交期(`phase !== "plain"`)也算失效:发送成功后编辑器会被清空,失败时原稿要留着,
523
+ * 两种情况下在途的润色结果都不该再写进草稿。 */
524
+ function useWriteBack(input, messages) {
525
+ const latest = (0, react.useRef)(input);
526
+ const active = (0, react.useRef)(void 0);
527
+ (0, react.useEffect)(() => {
528
+ latest.current = input;
529
+ const ticket = active.current;
530
+ if (ticket === void 0) return;
531
+ if (ticket.sessionId !== input.sessionId || ticket.actions !== input.actions || input.phase !== "plain") ticket.invalidated = true;
532
+ }, [input]);
533
+ return {
534
+ begin: () => {
535
+ const ticket = {
536
+ sessionId: latest.current.sessionId,
537
+ draftRev: latest.current.draftRev,
538
+ actions: latest.current.actions,
539
+ invalidated: false
540
+ };
541
+ active.current = ticket;
542
+ return ticket;
543
+ },
544
+ finish: (ticket) => {
545
+ if (active.current === ticket) active.current = void 0;
546
+ },
547
+ commit: (content, ticket) => {
548
+ const { actions } = latest.current;
549
+ if (!hasDraftFace(actions)) throw new Error(messages.unavailable);
550
+ let liveRev = latest.current.draftRev;
551
+ if (hasInsertFace(actions)) liveRev = actions.captureInsertion().draftRev;
552
+ if (ticket.invalidated || liveRev !== ticket.draftRev) throw new Error(messages.stale);
553
+ actions.setDraft(content);
554
+ }
555
+ };
414
556
  }
415
557
  // src/remote.ts
416
558
  /** Typert Remote 命名空间(client 半这一侧的唯一一枚)。
@@ -421,12 +563,31 @@ function r(e) {
421
563
  const DIR_PREP_NAMESPACE = "dirPrepOrganize";
422
564
  const DIR_PREP_SERVICE_KEY = `remote.${DIR_PREP_NAMESPACE}`;
423
565
  const PACKAGE_NAME = "@jayyuen66/dsh-dir-prep-organize";
566
+ /** strict codec 的统一出口:失败交给 zod 的 `prettifyError`,读到的是一份带字段路径的说明。 */
567
+ function parseOrThrow(schema, value) {
568
+ const parsed = schema.safeParse(value);
569
+ if (!parsed.success) throw new TypeError(zod.z.prettifyError(parsed.error));
570
+ return parsed.data;
571
+ }
572
+ const SESSION_MESSAGE = "session request requires a string sessionId";
573
+ const SESSION_SCHEMA = zod.z.object({ sessionId: zod.z.string({ error: SESSION_MESSAGE }) }, { error: SESSION_MESSAGE });
574
+ const ORGANIZE_MESSAGE = "organize request requires string sessionId, prompt and entriesSummary";
575
+ const ORGANIZE_SCHEMA = zod.z.object({
576
+ sessionId: zod.z.string({ error: ORGANIZE_MESSAGE }),
577
+ prompt: zod.z.string({ error: ORGANIZE_MESSAGE }),
578
+ entriesSummary: zod.z.string({ error: ORGANIZE_MESSAGE }),
579
+ roleText: zod.z.string({ error: "organize request roleText must be a string when present" }).optional()
580
+ }, { error: ORGANIZE_MESSAGE });
581
+ const IMPORT_MESSAGE = "import request requires string path and sessionId";
582
+ const IMPORT_SCHEMA = zod.z.object({
583
+ path: zod.z.string({ error: IMPORT_MESSAGE }),
584
+ sessionId: zod.z.string({ error: IMPORT_MESSAGE })
585
+ }, { error: IMPORT_MESSAGE });
424
586
  const SESSION_CODEC = {
425
587
  mode: "strict",
426
588
  typeSymbol: `${PACKAGE_NAME}#session-request`,
427
589
  create: () => ({ parse(value) {
428
- if (!e(value) || typeof value["sessionId"] !== "string") throw new TypeError("session request requires a string sessionId");
429
- return { sessionId: value["sessionId"] };
590
+ return parseOrThrow(SESSION_SCHEMA, value);
430
591
  } })
431
592
  };
432
593
  const DIR_PREP_DESCRIPTORS = [
@@ -481,14 +642,14 @@ const DIR_PREP_DESCRIPTORS = [
481
642
  mode: "strict",
482
643
  typeSymbol: `${PACKAGE_NAME}#organize-request`,
483
644
  create: () => ({ parse(value) {
484
- if (!e(value) || typeof value["sessionId"] !== "string" || typeof value["prompt"] !== "string" || typeof value["entriesSummary"] !== "string") throw new TypeError("organize request requires string sessionId, prompt and entriesSummary");
485
- const { roleText } = value;
486
- if (roleText !== void 0 && typeof roleText !== "string") throw new TypeError("organize request roleText must be a string when present");
487
- return {
488
- sessionId: value["sessionId"],
489
- prompt: value["prompt"],
490
- entriesSummary: value["entriesSummary"],
491
- ...roleText === void 0 ? {} : { roleText }
645
+ const request = parseOrThrow(ORGANIZE_SCHEMA, value);
646
+ return request.roleText === void 0 ? {
647
+ sessionId: request.sessionId,
648
+ prompt: request.prompt,
649
+ entriesSummary: request.entriesSummary
650
+ } : {
651
+ ...request,
652
+ roleText: request.roleText
492
653
  };
493
654
  } })
494
655
  }
@@ -509,24 +670,20 @@ const DIR_PREP_DESCRIPTORS = [
509
670
  mode: "strict",
510
671
  typeSymbol: `${PACKAGE_NAME}#import-request`,
511
672
  create: () => ({ parse(value) {
512
- if (!e(value) || typeof value["path"] !== "string" || typeof value["sessionId"] !== "string") throw new TypeError("import request requires string path and sessionId");
513
- return {
514
- path: value["path"],
515
- sessionId: value["sessionId"]
516
- };
673
+ return parseOrThrow(IMPORT_SCHEMA, value);
517
674
  } })
518
675
  }
519
676
  }],
520
677
  result: { mode: "src-json" }
521
678
  }
522
679
  ];
523
- const isMounter = (value) => e(value) && typeof value["$mount"] === "function";
524
- const isNamespace = (value) => e(value) && typeof value["defaults"] === "function" && typeof value["context"] === "function" && typeof value["model"] === "function" && typeof value["organize"] === "function" && typeof value["importTemplates"] === "function";
680
+ const isMounter = (value) => e$1(value) && typeof value["$mount"] === "function";
681
+ const isNamespace = (value) => e$1(value) && typeof value["defaults"] === "function" && typeof value["context"] === "function" && typeof value["model"] === "function" && typeof value["organize"] === "function" && typeof value["importTemplates"] === "function";
525
682
  const unwrap = (raw) => {
526
- if (!e(raw) || typeof raw["ok"] !== "boolean") throw new TypeError("Typert Remote 应答不是 RemoteResult:缺少布尔字段 ok");
683
+ if (!e$1(raw) || typeof raw["ok"] !== "boolean") throw new TypeError("Typert Remote 应答不是 RemoteResult:缺少布尔字段 ok");
527
684
  if (!raw["ok"]) {
528
685
  const { error } = raw;
529
- if (!e(error) || typeof error["code"] !== "string" || typeof error["message"] !== "string") throw new TypeError("Typert Remote 应答的 error 分支缺 code/message");
686
+ if (!e$1(error) || typeof error["code"] !== "string" || typeof error["message"] !== "string") throw new TypeError("Typert Remote 应答的 error 分支缺 code/message");
530
687
  throw new Error(`${error["code"]}: ${error["message"]}`);
531
688
  }
532
689
  if (!("value" in raw)) throw new TypeError("Typert Remote 应答的 ok 分支缺 value 字段");
@@ -591,7 +748,7 @@ const CLASS_ROW_HEAD = "dpic-rowhead";
591
748
  const CLASS_IMPORT_PATH = "dpic-importpath";
592
749
  const SLOT_INPUT_RIGHT = "conversation.input.right";
593
750
  function parseDirEntry(raw) {
594
- const { name, isDir, sizeBytes, snippet } = e(raw) ? raw : {};
751
+ const { name, isDir, sizeBytes, snippet } = e$1(raw) ? raw : {};
595
752
  return {
596
753
  name: typeof name === "string" ? name : "",
597
754
  isDir: isDir === true,
@@ -622,7 +779,7 @@ function skipCountsOf(skips) {
622
779
  ];
623
780
  }
624
781
  function parseContextResponse(raw) {
625
- const rec = e(raw) ? raw : {};
782
+ const rec = e$1(raw) ? raw : {};
626
783
  const { ok, truncated, entries } = rec;
627
784
  const parsedEntries = Array.isArray(entries) ? entries.map((entry) => parseDirEntry(entry)) : void 0;
628
785
  return {
@@ -634,7 +791,7 @@ function parseContextResponse(raw) {
634
791
  };
635
792
  }
636
793
  function parseModelResponse(raw) {
637
- const rec = e(raw) ? raw : {};
794
+ const rec = e$1(raw) ? raw : {};
638
795
  return {
639
796
  ok: rec["ok"] === true,
640
797
  ...spreadIfDefined(optionalString(rec, "error"), "error"),
@@ -644,7 +801,7 @@ function parseModelResponse(raw) {
644
801
  };
645
802
  }
646
803
  function parseOrganizeResponse(raw) {
647
- const rec = e(raw) ? raw : {};
804
+ const rec = e$1(raw) ? raw : {};
648
805
  return {
649
806
  ok: rec["ok"] === true,
650
807
  ...spreadIfDefined(optionalString(rec, "error"), "error"),
@@ -672,14 +829,14 @@ function formatImportSkips(t, skips) {
672
829
  return parts.length === 0 ? "" : t("skipSummary", { list: parts.join(t("skipSeparator")) });
673
830
  }
674
831
  function parseImportResponse(raw) {
675
- const { ok, error, count, truncated, skipped, entries } = e(raw) ? raw : {};
832
+ const { ok, error, count, truncated, skipped, entries } = e$1(raw) ? raw : {};
676
833
  const parsedEntries = Array.isArray(entries) ? sanitizeTemplateList(entries) : void 0;
677
834
  return {
678
835
  ok: ok === true,
679
836
  ...typeof error === "string" ? { error } : {},
680
837
  ...typeof count === "number" ? { count } : {},
681
838
  ...truncated === true ? { truncated: true } : {},
682
- ...e(skipped) ? { skipped: parseImportSkips(skipped) } : {},
839
+ ...e$1(skipped) ? { skipped: parseImportSkips(skipped) } : {},
683
840
  ...parsedEntries === void 0 ? {} : { entries: parsedEntries }
684
841
  };
685
842
  }
@@ -755,7 +912,7 @@ async function loadBuiltinTemplates() {
755
912
  let settled;
756
913
  try {
757
914
  const body = await within(requireReader().defaults(), REMOTE_TIMEOUT_MS);
758
- const payload = e(body) ? body : void 0;
915
+ const payload = e$1(body) ? body : void 0;
759
916
  const okKey = "ok";
760
917
  const templatesKey = "templates";
761
918
  const rawReason = payload?.["error"];
@@ -772,7 +929,7 @@ async function loadBuiltinTemplates() {
772
929
  settled = {
773
930
  phase: "error",
774
931
  list: [],
775
- error: r(error)
932
+ error: r$1(error)
776
933
  };
777
934
  } finally {
778
935
  if (builtinGeneration === generation) builtinInflight = null;
@@ -799,7 +956,7 @@ function builtinStatusRow(snap, t) {
799
956
  };
800
957
  const retryButton = (0, react.createElement)("button", {
801
958
  type: "button",
802
- className: "dpic-btn",
959
+ className: "dsu-btn",
803
960
  "data-field": "dpi-builtin-retry",
804
961
  onClick: () => {
805
962
  loadBuiltinTemplates();
@@ -941,11 +1098,6 @@ function rootsPersistError(t, persisted, expected, action) {
941
1098
  });
942
1099
  return message;
943
1100
  }
944
- function applyTemplateToDraft(current, template) {
945
- const base = typeof current === "string" ? current.trimEnd() : "";
946
- if (base.length === 0) return template;
947
- return `${base}\n\n${template}`;
948
- }
949
1101
  /** 菜单项文字:有 emoji 就前缀一个(emoji 是用户自填的视觉标记,空串 = 不显示)。 */
950
1102
  function templateItemLabel(tpl) {
951
1103
  return `${tpl.emoji === "" ? "" : `${tpl.emoji} `}${tpl.name}`;
@@ -963,7 +1115,7 @@ function groupTemplatesBy(templates, t) {
963
1115
  bucket.push(tpl);
964
1116
  buckets.set(key, bucket);
965
1117
  }
966
- return [...buckets.entries()].map(([group, items]) => ({
1118
+ return Array.from(buckets.entries(), ([group, items]) => ({
967
1119
  group,
968
1120
  items
969
1121
  }));
@@ -1075,7 +1227,7 @@ async function runOrganizeClick(args) {
1075
1227
  writeDraft(content);
1076
1228
  } catch (error) {
1077
1229
  if (seq.current !== mySeq) return;
1078
- setFailed(error instanceof LocalizedOrganizeError ? t(error.messageKey, error.params) : r(error));
1230
+ setFailed(error instanceof LocalizedOrganizeError ? t(error.messageKey, error.params) : r$1(error));
1079
1231
  if (flashTimer.current !== null) clearTimeout(flashTimer.current);
1080
1232
  flashTimer.current = setTimeout(() => {
1081
1233
  setFailed(void 0);
@@ -1148,6 +1300,24 @@ function createOrganizeRoleMenu(ui) {
1148
1300
  }
1149
1301
  }, `${tpl.emoji === "" ? "" : `${tpl.emoji} `}${t("organizeRoleItem", { name: tpl.name })}`)));
1150
1302
  }
1303
+ /** 主键的三态外观:失败 > 在途 > 空闲(三者互斥,按同一优先级判)。 */
1304
+ function organizeBadge(failed, loading, t) {
1305
+ if (failed !== void 0) return {
1306
+ icon: (0, react.createElement)(FailIcon),
1307
+ label: t("organizeFailedShort"),
1308
+ state: "error"
1309
+ };
1310
+ if (loading) return {
1311
+ icon: (0, react.createElement)(SpinIcon),
1312
+ label: t("organizeLoading"),
1313
+ state: "loading"
1314
+ };
1315
+ return {
1316
+ icon: (0, react.createElement)(TidyIcon),
1317
+ label: t("organizeIdle"),
1318
+ state: "idle"
1319
+ };
1320
+ }
1151
1321
  function createOrganizeButton() {
1152
1322
  return function OrganizeButton(props) {
1153
1323
  const [loading, setLoading] = (0, react.useState)(false);
@@ -1158,8 +1328,19 @@ function createOrganizeButton() {
1158
1328
  const flashTimer = (0, react.useRef)(null);
1159
1329
  const wrapRef = (0, react.useRef)(null);
1160
1330
  const draft = props.useInput === void 0 ? "" : props.useInput((state) => state.draft) ?? "";
1331
+ const draftRev = props.useInput === void 0 ? 0 : props.useInput((state) => state.draftRev);
1332
+ const phase = props.useInput === void 0 ? "plain" : props.useInput((state) => state.phase);
1161
1333
  const snap = props.useCard((state) => state);
1162
1334
  const { templates } = snap;
1335
+ const writeBack = useWriteBack({
1336
+ sessionId: props.sessionId ?? "",
1337
+ actions: props.inputActions,
1338
+ draftRev,
1339
+ phase
1340
+ }, {
1341
+ unavailable: props.t(NO_WRITE_BACK_TITLE_KEY),
1342
+ stale: props.t("organizeWriteBackStale")
1343
+ });
1163
1344
  useMenuDismiss(menuOpen, wrapRef, () => {
1164
1345
  setMenuOpen(false);
1165
1346
  });
@@ -1168,56 +1349,46 @@ function createOrganizeButton() {
1168
1349
  if (flashTimer.current !== null) clearTimeout(flashTimer.current);
1169
1350
  }, []);
1170
1351
  async function handleOrganize(roleText) {
1171
- await runOrganizeClick({
1172
- t: props.t,
1173
- loading,
1174
- inFlight,
1175
- seq,
1176
- prompt: draft,
1177
- sessionId: props.sessionId ?? "",
1178
- timeoutMs: organizeFetchTimeoutMs(snap.organizeTimeoutMs),
1179
- roleText,
1180
- setLoading,
1181
- setMenuOpen,
1182
- setFailed,
1183
- flashTimer,
1184
- writeDraft: (content) => {
1185
- const actions = props.inputActions;
1186
- if (actions === void 0 || typeof actions.setDraft !== "function") throw new Error(props.t("organizeWriteBackUnavailable"));
1187
- actions.setDraft(content);
1188
- }
1189
- });
1352
+ const ticket = writeBack.begin();
1353
+ try {
1354
+ await runOrganizeClick({
1355
+ t: props.t,
1356
+ loading,
1357
+ inFlight,
1358
+ seq,
1359
+ prompt: draft,
1360
+ sessionId: props.sessionId ?? "",
1361
+ timeoutMs: organizeFetchTimeoutMs(snap.organizeTimeoutMs),
1362
+ roleText,
1363
+ setLoading,
1364
+ setMenuOpen,
1365
+ setFailed,
1366
+ flashTimer,
1367
+ writeDraft: (content) => {
1368
+ writeBack.commit(content, ticket);
1369
+ }
1370
+ });
1371
+ } finally {
1372
+ writeBack.finish(ticket);
1373
+ }
1190
1374
  }
1191
1375
  function openMenu() {
1192
1376
  if (!snap.fromSettings) loadBuiltinTemplates();
1193
1377
  setMenuOpen((prev) => !prev);
1194
1378
  }
1195
- let icon;
1196
- let label;
1197
- let state;
1198
- if (failed !== void 0) {
1199
- icon = (0, react.createElement)(FailIcon);
1200
- label = props.t("organizeFailedShort");
1201
- state = "error";
1202
- } else if (loading) {
1203
- icon = (0, react.createElement)(SpinIcon);
1204
- label = props.t("organizeLoading");
1205
- state = "loading";
1206
- } else {
1207
- icon = (0, react.createElement)(TidyIcon);
1208
- label = props.t("organizeIdle");
1209
- state = "idle";
1210
- }
1211
- const canWrite = props.inputActions !== void 0 && typeof props.inputActions.setDraft === "function";
1379
+ const badge = organizeBadge(failed, loading, props.t);
1380
+ const replaceable = hasDraftFace(props.inputActions);
1381
+ const canWrite = replaceable && phase === "plain";
1212
1382
  let errTitle = props.t("organizeIdleTitle");
1213
1383
  if (failed !== void 0) errTitle = props.t("organizeFailedTitle", { message: failed });
1214
- else if (!canWrite) errTitle = props.t(NO_WRITE_BACK_TITLE_KEY);
1384
+ else if (!replaceable) errTitle = props.t(NO_WRITE_BACK_TITLE_KEY);
1385
+ else if (phase !== "plain") errTitle = props.t("organizeBusyTitle");
1215
1386
  const ui = {
1216
1387
  t: props.t,
1217
1388
  errTitle,
1218
- icon,
1219
- label,
1220
- state,
1389
+ icon: badge.icon,
1390
+ label: badge.label,
1391
+ state: badge.state,
1221
1392
  errClass: failed === void 0 ? "" : " dpi-btn-err",
1222
1393
  directItemLabel: props.t("organizeDirectItem"),
1223
1394
  noTemplatesLabel: props.t("organizeNoTemplates"),
@@ -1239,7 +1410,7 @@ function createTemplateButton() {
1239
1410
  return function TemplateButton(props) {
1240
1411
  const [open, setOpen] = (0, react.useState)(false);
1241
1412
  const wrapRef = (0, react.useRef)(null);
1242
- const draft = props.useInput === void 0 ? "" : props.useInput((state) => state.draft) ?? "";
1413
+ const phase = props.useInput === void 0 ? "plain" : props.useInput((state) => state.phase);
1243
1414
  const snap = props.useCard((state) => state);
1244
1415
  const { templates } = snap;
1245
1416
  useMenuDismiss(open, wrapRef, () => {
@@ -1248,11 +1419,14 @@ function createTemplateButton() {
1248
1419
  function pick(text) {
1249
1420
  setOpen(false);
1250
1421
  const actions = props.inputActions;
1251
- if (actions === void 0 || typeof actions.setDraft !== "function") return;
1252
- actions.setDraft(applyTemplateToDraft(draft, text));
1422
+ if (!hasInsertFace(actions)) return;
1423
+ actions.insertText(text, actions.captureInsertion());
1253
1424
  }
1254
- const canWrite = props.inputActions !== void 0 && typeof props.inputActions.setDraft === "function";
1255
- const title = canWrite ? props.t("templatesIdleTitle") : props.t("templatesBrokenTitle");
1425
+ const insertable = hasInsertFace(props.inputActions);
1426
+ const canWrite = insertable && phase === "plain";
1427
+ let title = props.t("templatesBrokenTitle");
1428
+ if (canWrite) title = props.t("templatesIdleTitle");
1429
+ else if (insertable) title = props.t("templatesBusyTitle");
1256
1430
  const grouped = groupTemplatesBy(templates, props.t);
1257
1431
  const emptyHintLabel = props.t("templatesEmptyHint");
1258
1432
  const builtinRow = builtinStatusRow(snap, props.t);
@@ -1310,7 +1484,7 @@ function createTemplateRowElement(view) {
1310
1484
  const indexMark = (0, react.createElement)("span", { className: "dpic-idx" }, `#${rowNum}`);
1311
1485
  const emojiInput = (0, react.createElement)("input", {
1312
1486
  type: "text",
1313
- className: "dpic-emoji",
1487
+ className: "dpic-emoji dsu-input",
1314
1488
  value: values.emoji,
1315
1489
  placeholder: EMOJI_PLACEHOLDER,
1316
1490
  disabled,
@@ -1323,7 +1497,7 @@ function createTemplateRowElement(view) {
1323
1497
  });
1324
1498
  const nameInput = (0, react.createElement)("input", {
1325
1499
  type: "text",
1326
- className: "dpic-name",
1500
+ className: "dpic-name dsu-input",
1327
1501
  value: values.name,
1328
1502
  placeholder: t("rowPlaceholderName"),
1329
1503
  disabled,
@@ -1335,7 +1509,7 @@ function createTemplateRowElement(view) {
1335
1509
  });
1336
1510
  const groupInput = (0, react.createElement)("input", {
1337
1511
  type: "text",
1338
- className: "dpic-group",
1512
+ className: "dpic-group dsu-input",
1339
1513
  value: values.group,
1340
1514
  placeholder: t("rowPlaceholderGroup"),
1341
1515
  disabled,
@@ -1348,7 +1522,7 @@ function createTemplateRowElement(view) {
1348
1522
  });
1349
1523
  const deleteButton = (0, react.createElement)("button", {
1350
1524
  type: "button",
1351
- className: "dpic-del",
1525
+ className: "dpic-del dsu-btn dsu-btnDanger",
1352
1526
  disabled,
1353
1527
  title: t("rowDeleteTitle"),
1354
1528
  onClick: () => {
@@ -1357,7 +1531,7 @@ function createTemplateRowElement(view) {
1357
1531
  }, t("rowDelete"));
1358
1532
  const descriptionInput = (0, react.createElement)("input", {
1359
1533
  type: "text",
1360
- className: "dpic-desc",
1534
+ className: "dpic-desc dsu-input",
1361
1535
  value: values.description,
1362
1536
  placeholder: t("rowPlaceholderDescription"),
1363
1537
  disabled,
@@ -1368,7 +1542,7 @@ function createTemplateRowElement(view) {
1368
1542
  onBlur: view.onBlur
1369
1543
  });
1370
1544
  const textArea = (0, react.createElement)("textarea", {
1371
- className: "dpic-text",
1545
+ className: "dpic-text dsu-input dsu-textarea dsu-mono",
1372
1546
  value: values.text,
1373
1547
  rows: 6,
1374
1548
  placeholder: t("rowPlaceholderText"),
@@ -1379,7 +1553,7 @@ function createTemplateRowElement(view) {
1379
1553
  },
1380
1554
  onBlur: view.onBlur
1381
1555
  });
1382
- return (0, react.createElement)("li", { className: "dpic-row" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, indexMark, emojiInput, nameInput, groupInput, deleteButton), descriptionInput, textArea);
1556
+ return (0, react.createElement)("div", { className: "dpic-row" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, indexMark, emojiInput, nameInput, groupInput, deleteButton), descriptionInput, textArea);
1383
1557
  }
1384
1558
  function TemplateRow(props) {
1385
1559
  const { t } = props;
@@ -1478,7 +1652,7 @@ function ImportPanel(props) {
1478
1652
  skips: skipNote
1479
1653
  }));
1480
1654
  } catch (error) {
1481
- setImportError(r(error));
1655
+ setImportError(r$1(error));
1482
1656
  } finally {
1483
1657
  setImportBusy(false);
1484
1658
  }
@@ -1486,7 +1660,7 @@ function ImportPanel(props) {
1486
1660
  const canImport = props.editable && !importBusy;
1487
1661
  const importPathInput = (0, react.createElement)("input", {
1488
1662
  type: "text",
1489
- className: CLASS_IMPORT_PATH,
1663
+ className: `${CLASS_IMPORT_PATH} dsu-input`,
1490
1664
  value: importPath,
1491
1665
  placeholder: t("importPlaceholder"),
1492
1666
  disabled: !canImport,
@@ -1500,7 +1674,7 @@ function ImportPanel(props) {
1500
1674
  });
1501
1675
  const importBtn = (0, react.createElement)("button", {
1502
1676
  type: "button",
1503
- className: "dpic-btn",
1677
+ className: "dsu-btn",
1504
1678
  disabled: !canImport,
1505
1679
  title: t("importBtnTitle"),
1506
1680
  onClick: onImport
@@ -1508,7 +1682,7 @@ function ImportPanel(props) {
1508
1682
  const importMsgEl = importMsg === "" ? null : (0, react.createElement)("div", { className: "dpic-hint" }, importMsg);
1509
1683
  const importErrorEl = importError === "" ? null : (0, react.createElement)("div", { className: "dpic-hint dpic-err" }, `${t("importErrorPrefix")}${importError}`);
1510
1684
  const importHintEl = (0, react.createElement)("div", { className: "dpic-hint" }, t("importHint"));
1511
- return (0, react.createElement)("li", { className: "dpic-importrow" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, importPathInput, importBtn), importMsgEl, importErrorEl, importHintEl);
1685
+ return (0, react.createElement)("div", { className: "dpic-importrow" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, importPathInput, importBtn), importMsgEl, importErrorEl, importHintEl);
1512
1686
  }
1513
1687
  function AllowRootsPanel(props) {
1514
1688
  const { t } = props;
@@ -1521,7 +1695,7 @@ function AllowRootsPanel(props) {
1521
1695
  const rowAria = t("rootsAriaRow", { index: index + 1 });
1522
1696
  const rowInput = (0, react.createElement)("input", {
1523
1697
  type: "text",
1524
- className: CLASS_IMPORT_PATH,
1698
+ className: `${CLASS_IMPORT_PATH} dsu-input`,
1525
1699
  value: root,
1526
1700
  placeholder: ROOT_PATH_PLACEHOLDER,
1527
1701
  disabled: props.disabled,
@@ -1533,7 +1707,7 @@ function AllowRootsPanel(props) {
1533
1707
  });
1534
1708
  const rowButton = (0, react.createElement)("button", {
1535
1709
  type: "button",
1536
- className: "dpic-del",
1710
+ className: "dpic-del dsu-btn dsu-btnDanger",
1537
1711
  disabled: props.disabled,
1538
1712
  title: removeTitle,
1539
1713
  onClick: () => {
@@ -1551,7 +1725,7 @@ function AllowRootsPanel(props) {
1551
1725
  const addLabel = t("rootsAdd");
1552
1726
  const addInput = (0, react.createElement)("input", {
1553
1727
  type: "text",
1554
- className: CLASS_IMPORT_PATH,
1728
+ className: `${CLASS_IMPORT_PATH} dsu-input`,
1555
1729
  value: pending,
1556
1730
  placeholder: addPlaceholder,
1557
1731
  disabled: props.disabled,
@@ -1568,7 +1742,7 @@ function AllowRootsPanel(props) {
1568
1742
  });
1569
1743
  const addButton = (0, react.createElement)("button", {
1570
1744
  type: "button",
1571
- className: "dpic-btn",
1745
+ className: "dsu-btn",
1572
1746
  disabled: !canAdd,
1573
1747
  title: addTitle,
1574
1748
  onClick: () => {
@@ -1577,34 +1751,22 @@ function AllowRootsPanel(props) {
1577
1751
  }
1578
1752
  }, addLabel);
1579
1753
  const addRow = (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, addInput, addButton);
1580
- return (0, react.createElement)("li", {
1754
+ return (0, react.createElement)("div", {
1581
1755
  className: "dpic-importrow",
1582
1756
  "data-field": "allow-roots"
1583
1757
  }, (0, react.createElement)("div", { className: "dpic-hint" }, t("rootsHeading")), rows, addRow, (0, react.createElement)("div", { className: "dpic-hint" }, t("rootsHint")));
1584
1758
  }
1585
- function CardFootBar(props) {
1586
- const { foot, editable, anythingDirty, busy, confirmReset } = props;
1587
- return (0, react.createElement)("li", { className: "dpic-foot" }, (0, react.createElement)("button", {
1759
+ /** 工具条:新增角色与恢复默认(保存/撤销交给卡片底部统一的 SaveBar)。 */
1760
+ function CardToolbar(props) {
1761
+ const { foot, editable, busy, confirmReset } = props;
1762
+ return (0, react.createElement)("div", { className: "dpic-toolbar" }, (0, react.createElement)("button", {
1588
1763
  type: "button",
1589
- className: "dpic-btn",
1764
+ className: "dsu-btn",
1590
1765
  disabled: !editable,
1591
1766
  onClick: props.onAdd
1592
1767
  }, foot.add), (0, react.createElement)("button", {
1593
1768
  type: "button",
1594
- className: "dpic-btn dpic-btn-primary",
1595
- "data-field": "save",
1596
- disabled: !editable || !anythingDirty || busy,
1597
- title: anythingDirty ? foot.saveTitleDirty : foot.saveTitleClean,
1598
- onClick: props.onSave
1599
- }, busy ? foot.saving : foot.save), (0, react.createElement)("button", {
1600
- type: "button",
1601
- className: "dpic-btn",
1602
- "data-field": "discard",
1603
- disabled: !editable || !anythingDirty || busy,
1604
- onClick: props.onDiscard
1605
- }, foot.revert), (0, react.createElement)("button", {
1606
- type: "button",
1607
- className: "dpic-btn dpic-btn-danger",
1769
+ className: "dsu-btn dsu-btnDanger",
1608
1770
  disabled: !editable || busy,
1609
1771
  title: foot.resetTitle,
1610
1772
  onClick: props.onReset
@@ -1629,28 +1791,6 @@ function cardStatusHint(snap, t) {
1629
1791
  else hint = t("statusNotReady");
1630
1792
  return hint;
1631
1793
  }
1632
- function createCardHeader(view) {
1633
- const { t, open, setOpen } = view;
1634
- const headTitle = (0, react.createElement)("div", { className: "dpic-title" }, t("cardTitle"));
1635
- const headDesc = (0, react.createElement)("div", { className: "dpic-cardsub" }, t("cardDescription"));
1636
- const headBlock = (0, react.createElement)("div", { className: "dpic-head" }, headTitle, headDesc);
1637
- const chevronPath = (0, react.createElement)("path", svgPathProps("M3 5l4 4 4-4", true));
1638
- const chevron = (0, react.createElement)("svg", {
1639
- width: 14,
1640
- height: 14,
1641
- viewBox: "0 0 14 14",
1642
- "aria-hidden": true,
1643
- className: `dpic-chevron${open ? " dpic-chevron-open" : ""}`
1644
- }, chevronPath);
1645
- return (0, react.createElement)("button", {
1646
- type: "button",
1647
- className: "dpic-header",
1648
- "aria-expanded": open,
1649
- onClick: () => {
1650
- setOpen((prev) => !prev);
1651
- }
1652
- }, headBlock, chevron);
1653
- }
1654
1794
  function createDraftActions(t, draft, rootsDraft, setDraft, setRootsDraft) {
1655
1795
  function onCommit(id, fields) {
1656
1796
  setDraft(draft.map((tpl) => tpl.id === id ? {
@@ -1705,7 +1845,7 @@ function createPersistActions(args) {
1705
1845
  const { t, editable, dirty, rootsDirty, anythingDirty, confirmReset, templates, allowRoots, draft, rootsDraft, set, unset, readBack, setDraft, setDraftFor, setRootsDraft, setBusy, setSaveError, setConfirmReset } = args;
1706
1846
  function reportError(err) {
1707
1847
  console.error("[dir-prep-organize] templates settings write failed:", err);
1708
- setSaveError(r(err));
1848
+ setSaveError(r$1(err));
1709
1849
  }
1710
1850
  async function onSave() {
1711
1851
  if (!editable || !anythingDirty) return;
@@ -1765,12 +1905,39 @@ function createPersistActions(args) {
1765
1905
  onReset
1766
1906
  };
1767
1907
  }
1768
- /** 展开态正文(状态行 + 模板行表 + 卡底动作条 + 导入面 + 允许目录面 + 底部提示)。 */
1908
+ /** 卡片正文:状态提示 + 工具条 + 角色行表 + 导入面 + 允许目录面 + 保存条。 */
1769
1909
  function createCardBody(view) {
1770
1910
  const { t, statusHint, draft, rootsDraft, foot, editable, anythingDirty, busy, confirmReset, saveError } = view;
1771
1911
  const { onCommit, onDelete, onAdd, onImported, onRootChange, onRootDelete, onRootAdd } = view.draftActions;
1772
1912
  const { onSave, onDiscard, onReset } = view.persistActions;
1773
- return (0, react.createElement)("ul", { className: "dpic-body" }, statusHint === "" ? null : (0, react.createElement)("li", { className: "dpic-hint" }, statusHint), draft.map((tpl, idx) => (0, react.createElement)(TemplateRow, {
1913
+ const footHint = (0, react.createElement)("p", { className: "dpic-hint" }, t("footHint"));
1914
+ const saveBar = (0, react.createElement)(S, {
1915
+ dirty: anythingDirty,
1916
+ busy,
1917
+ writable: editable,
1918
+ error: saveError === "" ? null : `${t("saveFailed")}${saveError}`,
1919
+ saveLabel: t("save"),
1920
+ savingLabel: t("saving"),
1921
+ revertLabel: t("revert"),
1922
+ dirtyLabel: t("saveTitleDirty"),
1923
+ cleanLabel: t("saveTitleClean"),
1924
+ readOnlyLabel: t("statusReadOnly"),
1925
+ onSave: () => {
1926
+ onSave();
1927
+ },
1928
+ onDiscard
1929
+ });
1930
+ return (0, react.createElement)(u, null, statusHint === "" ? null : (0, react.createElement)("p", { className: "dpic-hint" }, statusHint), (0, react.createElement)(d, {
1931
+ title: t("rolesSection"),
1932
+ hint: t("rolesHint")
1933
+ }, (0, react.createElement)(CardToolbar, {
1934
+ foot,
1935
+ editable,
1936
+ busy,
1937
+ confirmReset,
1938
+ onAdd,
1939
+ onReset
1940
+ }), draft.map((tpl, idx) => (0, react.createElement)(TemplateRow, {
1774
1941
  key: tpl.id,
1775
1942
  t,
1776
1943
  index: idx,
@@ -1778,17 +1945,7 @@ function createCardBody(view) {
1778
1945
  disabled: !editable || busy,
1779
1946
  onCommit,
1780
1947
  onDelete
1781
- })), (0, react.createElement)(CardFootBar, {
1782
- foot,
1783
- editable,
1784
- anythingDirty,
1785
- busy,
1786
- confirmReset,
1787
- onAdd,
1788
- onSave,
1789
- onDiscard,
1790
- onReset
1791
- }), (0, react.createElement)(ImportPanel, {
1948
+ })), (0, react.createElement)(ImportPanel, {
1792
1949
  t,
1793
1950
  editable: editable && !busy,
1794
1951
  onImported
@@ -1799,11 +1956,10 @@ function createCardBody(view) {
1799
1956
  onChangeRoot: onRootChange,
1800
1957
  onDeleteRoot: onRootDelete,
1801
1958
  onAddRoot: onRootAdd
1802
- }), (0, react.createElement)("li", { className: "dpic-hint" }, t("footHint")), saveError === "" ? null : (0, react.createElement)("li", { className: "dpic-hint dpic-err" }, `${t("saveFailed")}${saveError}`));
1959
+ }), footHint), saveBar);
1803
1960
  }
1804
1961
  function TemplatesCard(props) {
1805
1962
  const { t } = props;
1806
- const [open, setOpen] = (0, react.useState)(false);
1807
1963
  const [confirmReset, setConfirmReset] = (0, react.useState)(false);
1808
1964
  const [saveError, setSaveError] = (0, react.useState)("");
1809
1965
  const [busy, setBusy] = (0, react.useState)(false);
@@ -1843,34 +1999,7 @@ function TemplatesCard(props) {
1843
1999
  const dirty = JSON.stringify(draft) !== JSON.stringify(templates);
1844
2000
  const rootsDirty = JSON.stringify(sanitizeAllowRoots(rootsDraft)) !== JSON.stringify(snap.allowRoots);
1845
2001
  const anythingDirty = dirty || rootsDirty;
1846
- const draftActions = createDraftActions(t, draft, rootsDraft, setDraft, setRootsDraft);
1847
- const persistActions = createPersistActions({
1848
- t,
1849
- editable,
1850
- dirty,
1851
- rootsDirty,
1852
- anythingDirty,
1853
- confirmReset,
1854
- templates,
1855
- allowRoots: snap.allowRoots,
1856
- draft,
1857
- rootsDraft,
1858
- set: props.set,
1859
- unset: props.unset,
1860
- readBack: props.readBack,
1861
- setDraft,
1862
- setDraftFor,
1863
- setRootsDraft,
1864
- setBusy,
1865
- setSaveError,
1866
- setConfirmReset
1867
- });
1868
- const headerBtn = createCardHeader({
1869
- t,
1870
- open,
1871
- setOpen
1872
- });
1873
- const bodyList = open ? createCardBody({
2002
+ return createCardBody({
1874
2003
  t,
1875
2004
  statusHint,
1876
2005
  draft,
@@ -1881,10 +2010,29 @@ function TemplatesCard(props) {
1881
2010
  busy,
1882
2011
  confirmReset,
1883
2012
  saveError,
1884
- draftActions,
1885
- persistActions
1886
- }) : null;
1887
- return (0, react.createElement)("li", { className: `dpic-card${open ? " dpic-card-open" : ""}` }, headerBtn, bodyList);
2013
+ draftActions: createDraftActions(t, draft, rootsDraft, setDraft, setRootsDraft),
2014
+ persistActions: createPersistActions({
2015
+ t,
2016
+ editable,
2017
+ dirty,
2018
+ rootsDirty,
2019
+ anythingDirty,
2020
+ confirmReset,
2021
+ templates,
2022
+ allowRoots: snap.allowRoots,
2023
+ draft,
2024
+ rootsDraft,
2025
+ set: props.set,
2026
+ unset: props.unset,
2027
+ readBack: props.readBack,
2028
+ setDraft,
2029
+ setDraftFor,
2030
+ setRootsDraft,
2031
+ setBusy,
2032
+ setSaveError,
2033
+ setConfirmReset
2034
+ })
2035
+ });
1888
2036
  }
1889
2037
  const inject = [
1890
2038
  "slots",
@@ -1920,7 +2068,7 @@ function injectDock(ctx, store, t) {
1920
2068
  };
1921
2069
  });
1922
2070
  }
1923
- /** 注入设置页的「模板库」卡(插件自带卡片,宿主不再生成自动表单页)。
2071
+ /** 注入设置页的「角色库」卡(插件自带卡片,宿主不再生成自动表单页)。
1924
2072
  * 这张卡管的就是「模板」下拉与「润色」▾ 共用的那一份列表。
1925
2073
  *
1926
2074
  * scope 作为参数传进来而不是就地取:卡片 inject 闭包里的 set/unset 必须落到
@@ -1950,7 +2098,7 @@ function apply(ctx) {
1950
2098
  ctx.effect(() => {
1951
2099
  const tag = document.createElement("style");
1952
2100
  tag.id = "dir-prep-organize-css";
1953
- tag.textContent = CARD_STYLES;
2101
+ tag.textContent = `${CARD_STYLES}\n${c}`;
1954
2102
  document.head.append(tag);
1955
2103
  return () => {
1956
2104
  tag.remove();
@@ -1964,7 +2112,6 @@ function apply(ctx) {
1964
2112
  injectCard(ctx, store, t, scope);
1965
2113
  }
1966
2114
  exports.apply = apply;
1967
- exports.applyTemplateToDraft = applyTemplateToDraft;
1968
2115
  exports.builtinTemplatesSnapshot = builtinTemplatesSnapshot;
1969
2116
  exports.formatContextSummary = formatContextSummary;
1970
2117
  exports.formatImportSkips = formatImportSkips;