dsh-prompt-pool 1.0.1 → 1.0.3

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.
Files changed (2) hide show
  1. package/client.js +221 -45
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -18,13 +18,15 @@ window.__ModuleLoader__.load({
18
18
 
19
19
  const NS = 'prompt-pool';
20
20
  const STORAGE_KEY = 'dsh.prompt-pool.v1';
21
+ /** One pre-migration copy of the stored payload, written before the first rewrite. */
22
+ const BACKUP_KEY = STORAGE_KEY + '.backup';
21
23
  /** The sidebar tool tab this plugin owns; it also names the open tab. */
22
24
  const SIDEBAR_TAB_ID = 'prompt-pool:pool';
23
25
  /** Native right-sidebar registry identity (DSH 0.2) and the page kind it opens. */
24
26
  const NATIVE_TAB_ID = 'dsh-prompt-pool';
25
27
  const NATIVE_TAB_KIND = 'prompt-pool';
26
28
  /** Shown in the settings about card; keep in step with plugin/package.json. */
27
- const PLUGIN_VERSION = '1.0.1';
29
+ const PLUGIN_VERSION = '1.0.3';
28
30
  const PLUGIN_AUTHOR = 'GanttShen';
29
31
  /** Replace once the public repository exists; the row hides while it is empty. */
30
32
  const PLUGIN_REPO = 'https://github.com/Ganttfly/dsh-prompt-pool';
@@ -201,7 +203,7 @@ window.__ModuleLoader__.load({
201
203
  'tray.release': '发送',
202
204
  'tray.clear': '清空',
203
205
  'tray.clearTitle': '清空待发送队列',
204
- 'tray.clearConfirm': '队列里的 {n} 条会被一起移出,这个操作不能撤销。',
206
+ 'tray.clearConfirm': '队列里的 {n} 条会被一起移出。',
205
207
  'tray.clearAction': '清空',
206
208
  'tray.empty': '还没选中任何条目,点左侧「+」加入',
207
209
  'tray.remove': '移出',
@@ -218,6 +220,7 @@ window.__ModuleLoader__.load({
218
220
  'confirm.cancel': '再想想',
219
221
  'status.saved': '已存入池子',
220
222
  'status.savedPartial': '已存入池子,但这 {n} 个附件没有一起保存',
223
+ 'status.storageFailed': '保存失败:浏览器存储不可写(可能已满)。改动只在当前页面有效。',
221
224
  'status.nothing': '草稿是空的,先写点什么',
222
225
  'status.emptyBody': '内容不能是空的',
223
226
  'status.inserted': '已插入到输入框',
@@ -228,6 +231,7 @@ window.__ModuleLoader__.load({
228
231
  'status.releaseStopped': '已释放 {n} 条,其余 {rest} 条没发出去:输入框繁忙或内容被改动',
229
232
  'status.draftBusy': '输入框里还有内容,先清空或存进池子再释放',
230
233
  'status.deleted': '已删除「{title}」',
234
+ 'status.cleared': '已清空 {n} 条待发送',
231
235
  'status.undo': '撤销',
232
236
  'status.releasing': '正在释放 {n} 条…',
233
237
  };
@@ -371,7 +375,7 @@ window.__ModuleLoader__.load({
371
375
  'tray.release': 'Send',
372
376
  'tray.clear': 'Clear',
373
377
  'tray.clearTitle': 'Clear the send queue',
374
- 'tray.clearConfirm': 'All {n} queued items are removed at once. This cannot be undone.',
378
+ 'tray.clearConfirm': 'All {n} queued items are removed at once.',
375
379
  'tray.clearAction': 'Clear',
376
380
  'tray.empty': 'Nothing selected yet — use the + control on a row',
377
381
  'tray.remove': 'Remove',
@@ -388,6 +392,7 @@ window.__ModuleLoader__.load({
388
392
  'confirm.cancel': 'Not yet',
389
393
  'status.saved': 'Saved to the pool',
390
394
  'status.savedPartial': 'Saved to the pool; {n} attachment(s) were not captured',
395
+ 'status.storageFailed': 'Could not save: browser storage is unwritable (possibly full). Changes last only for this page.',
391
396
  'status.nothing': 'The composer is empty',
392
397
  'status.emptyBody': 'The content cannot be empty',
393
398
  'status.inserted': 'Inserted into the composer',
@@ -398,6 +403,7 @@ window.__ModuleLoader__.load({
398
403
  'status.releaseStopped': 'Released {n}; {rest} left because the composer was busy or edited',
399
404
  'status.draftBusy': 'The composer still has text. Clear it or save it to the pool first.',
400
405
  'status.deleted': 'Deleted this item',
406
+ 'status.cleared': 'Cleared {n} queued items',
401
407
  'status.undo': 'Undo',
402
408
  'status.releasing': 'Releasing {n}…',
403
409
  };
@@ -462,6 +468,12 @@ window.__ModuleLoader__.load({
462
468
  };
463
469
  }
464
470
 
471
+ /**
472
+ * Whether the last write reached localStorage. Both views surface this,
473
+ * because a full quota would otherwise look like a successful save.
474
+ */
475
+ const storageState = createStore({ failed: false });
476
+
465
477
  function uid() {
466
478
  try {
467
479
  return crypto.randomUUID();
@@ -614,6 +626,61 @@ window.__ModuleLoader__.load({
614
626
  );
615
627
  }
616
628
 
629
+ function deleteImageBlobs(ids) {
630
+ const list = (Array.isArray(ids) ? ids : []).filter((id) => typeof id === 'string' && id);
631
+ if (list.length === 0) return Promise.resolve(true);
632
+ return openImageDb().then(
633
+ (db) =>
634
+ new Promise((resolve, reject) => {
635
+ const tx = db.transaction(IMAGE_STORE, 'readwrite');
636
+ const store = tx.objectStore(IMAGE_STORE);
637
+ for (const id of list) store.delete(id);
638
+ tx.oncomplete = () => resolve(true);
639
+ tx.onerror = () => reject(tx.error || new Error('image-delete-failed'));
640
+ tx.onabort = () => reject(tx.error || new Error('image-delete-failed'));
641
+ }),
642
+ );
643
+ }
644
+
645
+ /** Drop bytes the editor added but never saved; stored images stay. */
646
+ function discardUnsavedImages(edited, stored) {
647
+ const keep = new Set(((stored && stored.images) || []).map((image) => image.id));
648
+ const drop = ((edited && edited.images) || []).map((image) => image.id).filter((imageId) => !keep.has(imageId));
649
+ if (drop.length > 0) deleteImageBlobs(drop).catch(() => {});
650
+ }
651
+
652
+ /**
653
+ * Every image id the pool still points at. Duplicated items and queued
654
+ * copies share ids, so an id is garbage only when nothing references it.
655
+ */
656
+ function referencedImageIds() {
657
+ const keep = new Set();
658
+ const state = pool.get();
659
+ for (const item of state.items) for (const image of item.images || []) keep.add(image.id);
660
+ for (const entry of state.tray) for (const image of entry.images || []) keep.add(image.id);
661
+ return keep;
662
+ }
663
+
664
+ /**
665
+ * Delete blobs nothing references, once per page load. This also clears the
666
+ * bytes of items deleted earlier, which cannot be freed immediately because
667
+ * the delete offers an undo.
668
+ */
669
+ function sweepImageBlobs() {
670
+ return new Promise((resolve, reject) => {
671
+ openImageDb().then((db) => {
672
+ const tx = db.transaction(IMAGE_STORE, 'readonly');
673
+ const request = tx.objectStore(IMAGE_STORE).getAllKeys();
674
+ request.onsuccess = () => resolve(request.result || []);
675
+ request.onerror = () => reject(request.error || new Error('image-read-failed'));
676
+ }, reject);
677
+ }).then((keys) => {
678
+ const keep = referencedImageIds();
679
+ const drop = keys.filter((key) => !keep.has(key));
680
+ return drop.length > 0 ? deleteImageBlobs(drop) : null;
681
+ });
682
+ }
683
+
617
684
  /** A small data-URL thumbnail keeps the list rendering synchronous. */
618
685
  function makeImageThumb(file) {
619
686
  return new Promise((resolve) => {
@@ -763,10 +830,19 @@ window.__ModuleLoader__.load({
763
830
  }
764
831
 
765
832
 
766
- /** The one read path: item → canonical group id. */
833
+ /**
834
+ * The one read path: item → canonical group id. Older pools predate the
835
+ * group id and stored pinned / categoryId (`cat:<id>`) / kind instead, so
836
+ * map those once on load rather than dropping the user's classification.
837
+ */
767
838
  function groupOf(item) {
768
839
  const group = item && typeof item.group === 'string' ? item.group : '';
769
- return group && familyOf(group) ? group : BUILTIN_GROUP.note;
840
+ if (group && familyOf(group)) return group;
841
+ const categoryId = item && typeof item.categoryId === 'string' ? item.categoryId : '';
842
+ if (categoryId) return 'custom:' + categoryId.replace(/^cat:/, '');
843
+ if (item && item.pinned === true) return BUILTIN_GROUP.oftenuse;
844
+ if (item && item.kind === 'snippet') return BUILTIN_GROUP.template;
845
+ return BUILTIN_GROUP.note;
770
846
  }
771
847
 
772
848
  /** The one write path: canonical group id → item. */
@@ -831,9 +907,9 @@ window.__ModuleLoader__.load({
831
907
  onAdd: (name) => {
832
908
  const created = poolActions.addCategory(name);
833
909
  if (!created) return;
834
- // Folded custom groups share one tab, so aim at that tab instead.
835
- const folded = normalizeSettings(pool.get().settings).customNested;
836
- setTab(folded ? 'nested:custom' : 'custom:' + created.id);
910
+ // Folded groups share one tab; a hidden family has no tab to aim at.
911
+ const mode = normalizeSettings(pool.get().settings).display.custom;
912
+ setTab(mode === 'nested' ? 'nested:custom' : mode === 'hidden' ? 'all' : 'custom:' + created.id);
837
913
  },
838
914
  onRename: (id, name) => {
839
915
  if (id.indexOf('custom:') === 0) poolActions.renameCategory(id.slice(7), name);
@@ -1155,34 +1231,25 @@ window.__ModuleLoader__.load({
1155
1231
  if (!raw) {
1156
1232
  // Brand-new install only: an existing (even empty) pool is never reseeded.
1157
1233
  const seeded = seededPool();
1158
- try {
1159
- localStorage.setItem(STORAGE_KEY, JSON.stringify(seeded));
1160
- } catch (_error) {
1161
- /* storage unavailable: keep the in-memory copy only */
1162
- }
1234
+ persist(seeded);
1163
1235
  return seeded;
1164
1236
  }
1165
1237
  const parsed = JSON.parse(raw);
1166
1238
  const storedVersion = parsed && typeof parsed.version === 'number' ? parsed.version : 1;
1167
1239
  if (storedVersion < POOL_VERSION) {
1168
- // The shape changed and this build does not migrate: start from the seeds.
1169
- const reset = seededPool();
1240
+ // Keep the payload this build first saw: normalization is lossy, and the
1241
+ // backup is the only way back if an older shape maps differently.
1170
1242
  try {
1171
- localStorage.setItem(STORAGE_KEY, JSON.stringify(reset));
1243
+ localStorage.setItem(BACKUP_KEY, raw);
1172
1244
  } catch (_error) {
1173
- /* storage unavailable: keep the in-memory copy only */
1245
+ /* the backup is best effort; the pool itself still loads */
1174
1246
  }
1175
- return reset;
1176
1247
  }
1177
1248
  const pool = normalizePool(parsed);
1178
1249
  const level = Number(pool.seeded) || 0;
1179
- if (level >= SEED_LEVEL) return pool;
1180
- const migrated = { ...pool, items: [...pool.items, ...seedItems(pool.items, level)], seeded: SEED_LEVEL };
1181
- try {
1182
- localStorage.setItem(STORAGE_KEY, JSON.stringify(migrated));
1183
- } catch (_error) {
1184
- /* storage unavailable: keep the in-memory copy only */
1185
- }
1250
+ if (storedVersion >= POOL_VERSION && level >= SEED_LEVEL) return pool;
1251
+ const migrated = level >= SEED_LEVEL ? pool : { ...pool, items: [...pool.items, ...seedItems(pool.items, level)], seeded: SEED_LEVEL };
1252
+ persist(migrated);
1186
1253
  return migrated;
1187
1254
  } catch (_error) {
1188
1255
  return emptyPool();
@@ -1215,6 +1282,14 @@ window.__ModuleLoader__.load({
1215
1282
  return window[POOL_SINGLETON];
1216
1283
  })();
1217
1284
 
1285
+ // Clear orphaned image bytes once the pool is readable; the delay keeps the
1286
+ // first paint cheap and lets another window finish its own load.
1287
+ if (typeof window !== 'undefined' && typeof indexedDB !== 'undefined' && typeof window.setTimeout === 'function') {
1288
+ window.setTimeout(() => {
1289
+ sweepImageBlobs().catch(() => {});
1290
+ }, 5000);
1291
+ }
1292
+
1218
1293
  const ui = createStore({ open: false });
1219
1294
 
1220
1295
  /**
@@ -1341,15 +1416,19 @@ window.__ModuleLoader__.load({
1341
1416
 
1342
1417
  const bridge = (() => {
1343
1418
  const create = () => {
1344
- let handler = null;
1419
+ const handlers = [];
1345
1420
  return {
1346
1421
  listen(fn) {
1347
- handler = fn;
1422
+ handlers.push(fn);
1348
1423
  return () => {
1349
- if (handler === fn) handler = null;
1424
+ const at = handlers.lastIndexOf(fn);
1425
+ if (at >= 0) handlers.splice(at, 1);
1350
1426
  };
1351
1427
  },
1352
1428
  request(command) {
1429
+ // The newest mounted panel owns the composer; an older one takes
1430
+ // over again when the newer unmounts.
1431
+ const handler = handlers[handlers.length - 1];
1353
1432
  if (!handler) return { ok: false, reason: 'unavailable' };
1354
1433
  try {
1355
1434
  return handler(command) || { ok: true };
@@ -1367,8 +1446,10 @@ window.__ModuleLoader__.load({
1367
1446
  function persist(next) {
1368
1447
  try {
1369
1448
  localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
1449
+ if (storageState.get().failed) storageState.set({ failed: false });
1370
1450
  } catch (_error) {
1371
- /* storage unavailable: keep the session copy only */
1451
+ // The in-memory copy stays usable, but both views now say it is not saved.
1452
+ if (!storageState.get().failed) storageState.set({ failed: true });
1372
1453
  }
1373
1454
  }
1374
1455
 
@@ -1395,10 +1476,21 @@ window.__ModuleLoader__.load({
1395
1476
  });
1396
1477
  },
1397
1478
  patch(id, fields) {
1479
+ const before = pool.get().items.find((item) => item.id === id);
1398
1480
  mutate((state) => ({
1399
1481
  ...state,
1400
1482
  items: state.items.map((item) => (item.id === id ? { ...item, ...fields, updatedAt: Date.now() } : item)),
1401
1483
  }));
1484
+ // Saving is the point of no return for an image removed in the editor.
1485
+ // A duplicate or a queued copy may share the id, so drop it only when
1486
+ // nothing else points at it any more.
1487
+ if (before && Array.isArray(fields.images)) {
1488
+ const keep = new Set(fields.images.map((image) => image.id));
1489
+ const drop = (before.images || []).map((image) => image.id).filter((imageId) => !keep.has(imageId));
1490
+ const used = referencedImageIds();
1491
+ const garbage = drop.filter((imageId) => !used.has(imageId));
1492
+ if (garbage.length > 0) deleteImageBlobs(garbage).catch(() => {});
1493
+ }
1402
1494
  },
1403
1495
 
1404
1496
  addCategory(name) {
@@ -1491,8 +1583,25 @@ window.__ModuleLoader__.load({
1491
1583
  return { ...state, tray };
1492
1584
  });
1493
1585
  },
1494
- setTray(entries) {
1495
- mutate((state) => ({ ...state, tray: entries.slice() }));
1586
+ /** Drop exactly these entries, so a release cannot overwrite concurrent edits. */
1587
+ removeTrayKeys(keys) {
1588
+ const drop = new Set(keys);
1589
+ mutate((state) => {
1590
+ const next = state.tray.filter((entry) => !drop.has(entry.key));
1591
+ if (next.length === state.tray.length) return null;
1592
+ return { ...state, tray: next };
1593
+ });
1594
+ },
1595
+ /** Put cleared entries back in front; anything queued since stays behind them. */
1596
+ restoreTray(entries) {
1597
+ const restore = Array.isArray(entries) ? entries : [];
1598
+ if (restore.length === 0) return;
1599
+ mutate((state) => {
1600
+ const present = new Set(state.tray.map((entry) => entry.key));
1601
+ const missing = restore.filter((entry) => !present.has(entry.key));
1602
+ if (missing.length === 0) return null;
1603
+ return { ...state, tray: [...missing, ...state.tray] };
1604
+ });
1496
1605
  },
1497
1606
  clearTray() {
1498
1607
  mutate((state) => (state.tray.length === 0 ? null : { ...state, tray: [] }));
@@ -1503,6 +1612,10 @@ window.__ModuleLoader__.load({
1503
1612
  return useSyncExternalStore(pool.subscribe, pool.get, pool.get);
1504
1613
  }
1505
1614
 
1615
+ function useStorageState() {
1616
+ return useSyncExternalStore(storageState.subscribe, storageState.get, storageState.get);
1617
+ }
1618
+
1506
1619
  function useUiState() {
1507
1620
  return useSyncExternalStore(ui.subscribe, ui.get, ui.get);
1508
1621
  }
@@ -2029,6 +2142,7 @@ window.__ModuleLoader__.load({
2029
2142
  function PromptPoolPage(props) {
2030
2143
  useLocaleTick();
2031
2144
  const state = usePoolState();
2145
+ const storage = useStorageState();
2032
2146
  const queueCollapsed = state.settings && state.settings.queueCollapsed === true;
2033
2147
  const workspaces = useWorkspaceDir();
2034
2148
  const sessionHint = useSessionDir().sessionId;
@@ -2068,6 +2182,8 @@ window.__ModuleLoader__.load({
2068
2182
  statusTimer.current = window.setTimeout(() => setStatus(null), 5000);
2069
2183
  }, []);
2070
2184
  useEffect(() => () => window.clearTimeout(statusTimer.current), []);
2185
+ // A failed write outranks a transient toast: the change is not saved.
2186
+ const notice = status || (storage.failed ? { kind: 'error', text: translate('status.storageFailed') } : null);
2071
2187
  const trayRef = useRef(null);
2072
2188
  const trayCount = state.tray.length;
2073
2189
  const lastTrayCount = useRef(trayCount);
@@ -2286,6 +2402,19 @@ window.__ModuleLoader__.load({
2286
2402
  setEditing({ id: item.id, group, title: '', body: '', images: [] });
2287
2403
  };
2288
2404
 
2405
+ /**
2406
+ * Cancel drops an item the editor created and never saved, so no empty
2407
+ * row is left behind; an existing item keeps its stored content.
2408
+ */
2409
+ const cancelEdit = () => {
2410
+ const current = editing;
2411
+ setEditing(null);
2412
+ if (!current) return;
2413
+ const stored = pool.get().items.find((item) => item.id === current.id);
2414
+ discardUnsavedImages(current, stored);
2415
+ if (stored && !stored.body.trim() && !(stored.images && stored.images.length > 0)) poolActions.remove(stored.id);
2416
+ };
2417
+
2289
2418
  const rowOf = (item, index) => {
2290
2419
  if (editing && editing.id === item.id) {
2291
2420
  return h(
@@ -2353,7 +2482,7 @@ window.__ModuleLoader__.load({
2353
2482
  : null,
2354
2483
  ),
2355
2484
  h('span', { className: 'pp-grow' }),
2356
- h('button', { type: 'button', className: 'pp-mini', onClick: () => setEditing(null) }, translate('row.cancel')),
2485
+ h('button', { type: 'button', className: 'pp-mini', onClick: cancelEdit }, translate('row.cancel')),
2357
2486
  h('button', { type: 'button', className: 'pp-primary', onClick: save }, translate('row.save')),
2358
2487
  ),
2359
2488
  );
@@ -2484,8 +2613,18 @@ window.__ModuleLoader__.load({
2484
2613
  ? h(TrayClearConfirm, {
2485
2614
  count: state.tray.length,
2486
2615
  onConfirm: () => {
2616
+ const entries = pool.get().tray.slice();
2487
2617
  poolActions.clearTray();
2488
2618
  setConfirmClear(false);
2619
+ if (entries.length === 0) return;
2620
+ flash({
2621
+ kind: 'info',
2622
+ text: translate('status.cleared', { n: entries.length }),
2623
+ undo: () => {
2624
+ poolActions.restoreTray(entries);
2625
+ setStatus(null);
2626
+ },
2627
+ });
2489
2628
  },
2490
2629
  onCancel: () => setConfirmClear(false),
2491
2630
  })
@@ -2544,19 +2683,19 @@ window.__ModuleLoader__.load({
2544
2683
  h(
2545
2684
  'div',
2546
2685
  { className: 'pp-queue-dock' },
2547
- status
2686
+ notice
2548
2687
  ? h(
2549
2688
  'div',
2550
- { className: 'pp-status pp-status-float', 'data-kind': status.kind || 'info' },
2551
- h('span', null, status.text),
2552
- status.undo
2689
+ { className: 'pp-status pp-status-float', 'data-kind': notice.kind || 'info' },
2690
+ h('span', null, notice.text),
2691
+ notice.undo
2553
2692
  ? h(
2554
2693
  'button',
2555
2694
  {
2556
2695
  type: 'button',
2557
2696
  className: 'pp-link',
2558
2697
  onClick: () => {
2559
- status.undo();
2698
+ notice.undo();
2560
2699
  },
2561
2700
  },
2562
2701
  translate('status.undo'),
@@ -3234,6 +3373,7 @@ window.__ModuleLoader__.load({
3234
3373
  function PromptPoolPanel(props) {
3235
3374
  useLocaleTick();
3236
3375
  const state = usePoolState();
3376
+ const storage = useStorageState();
3237
3377
  const view = useUiState();
3238
3378
  const workspaces = useWorkspaceDir();
3239
3379
  const sessionHint = useSessionDir().sessionId;
@@ -3310,6 +3450,9 @@ window.__ModuleLoader__.load({
3310
3450
  }, []);
3311
3451
  useEffect(() => () => window.clearTimeout(statusTimer.current), []);
3312
3452
 
3453
+ // A failed write outranks a transient toast: the change is not saved.
3454
+ const notice = status || (storage.failed ? { kind: 'error', text: translate('status.storageFailed') } : null);
3455
+
3313
3456
  const confirmCategoryDelete = () => {
3314
3457
  const target = pendingCategory;
3315
3458
  setPendingCategory(null);
@@ -3576,6 +3719,8 @@ window.__ModuleLoader__.load({
3576
3719
  const group = groupForTab(tab, inWorkspace && wsActive ? 'workspace:' + wsActive.slice(3) : '');
3577
3720
  // The new row must land on a visible list, so plain tabs switch to the kind tab.
3578
3721
  if (!inWorkspace && !familyOf(tab)) setTab(group);
3722
+ // A search would filter the brand-new empty row out of the list.
3723
+ setQuery('');
3579
3724
  const item = poolActions.add({
3580
3725
  id: uid(),
3581
3726
  group,
@@ -3588,6 +3733,19 @@ window.__ModuleLoader__.load({
3588
3733
  setEditing({ id: item.id, group, title: '', body: '', images: [] });
3589
3734
  };
3590
3735
 
3736
+ /**
3737
+ * Cancel drops an item the editor created and never saved, so no empty
3738
+ * row is left behind; an existing item keeps its stored content.
3739
+ */
3740
+ const cancelEdit = () => {
3741
+ const current = editing;
3742
+ setEditing(null);
3743
+ if (!current) return;
3744
+ const stored = pool.get().items.find((item) => item.id === current.id);
3745
+ discardUnsavedImages(current, stored);
3746
+ if (stored && !stored.body.trim() && !(stored.images && stored.images.length > 0)) poolActions.remove(stored.id);
3747
+ };
3748
+
3591
3749
  const startEdit = (item) => setEditing({ id: item.id, group: groupOf(item), title: item.title, body: item.body, images: normalizeImages(item.images) });
3592
3750
 
3593
3751
  const saveEdit = () => {
@@ -3645,11 +3803,17 @@ window.__ModuleLoader__.load({
3645
3803
  setBusy(true);
3646
3804
  setStatus({ kind: 'info', text: translate('status.releasing', { n: entries.length }) });
3647
3805
  let sent = 0;
3806
+ // Keys finished by this run; the queue is filtered by key afterwards so
3807
+ // rows queued (or removed) meanwhile are not overwritten.
3808
+ const done = [];
3648
3809
  try {
3649
3810
  for (const entry of entries) {
3650
3811
  const body = typeof entry.body === 'string' ? entry.body : '';
3651
3812
  const images = normalizeImages(entry.images);
3652
- if (!body.trim() && images.length === 0) continue;
3813
+ if (!body.trim() && images.length === 0) {
3814
+ done.push(entry.key);
3815
+ continue;
3816
+ }
3653
3817
  const clear = await waitFor(() => draftRef.current.trim() === '' && phaseRef.current === 'plain', 2500);
3654
3818
  if (!clear) break;
3655
3819
  try {
@@ -3688,6 +3852,7 @@ window.__ModuleLoader__.load({
3688
3852
  }
3689
3853
  await waitFor(() => phaseRef.current === 'plain', 1500);
3690
3854
  sent += 1;
3855
+ done.push(entry.key);
3691
3856
  }
3692
3857
  } catch (error) {
3693
3858
  flash({ kind: 'error', text: String((error && error.message) || error) });
@@ -3695,7 +3860,7 @@ window.__ModuleLoader__.load({
3695
3860
  busyRef.current = false;
3696
3861
  setBusy(false);
3697
3862
  }
3698
- poolActions.setTray(entries.slice(sent));
3863
+ poolActions.removeTrayKeys(done);
3699
3864
  flash(
3700
3865
  sent === entries.length
3701
3866
  ? { kind: 'ok', text: translate('status.released', { n: sent }) }
@@ -3770,7 +3935,7 @@ window.__ModuleLoader__.load({
3770
3935
  : null,
3771
3936
  ),
3772
3937
  h('span', { className: 'pp-grow' }),
3773
- h('button', { type: 'button', className: 'pp-mini', onClick: () => setEditing(null) }, translate('row.cancel')),
3938
+ h('button', { type: 'button', className: 'pp-mini', onClick: cancelEdit }, translate('row.cancel')),
3774
3939
  h('button', { type: 'button', className: 'pp-primary', onClick: saveEdit }, translate('row.save')),
3775
3940
  ),
3776
3941
  );
@@ -3801,6 +3966,7 @@ window.__ModuleLoader__.load({
3801
3966
  onClick: () => poolActions.move(item.id, 1),
3802
3967
  }),
3803
3968
  h(IconButton, { name: 'edit', label: translate('row.edit'), onClick: () => startEdit(item) }),
3969
+ h(IconButton, { name: 'copy', label: translate('row.duplicate'), onClick: () => poolActions.duplicateItem(item.id) }),
3804
3970
  h(IconButton, { name: 'trash', label: translate('row.delete'), danger: true, onClick: () => setPendingDelete(item) }),
3805
3971
  ),
3806
3972
  );
@@ -3983,8 +4149,18 @@ window.__ModuleLoader__.load({
3983
4149
  ? h(TrayClearConfirm, {
3984
4150
  count: tray.length,
3985
4151
  onConfirm: () => {
4152
+ const entries = pool.get().tray.slice();
3986
4153
  poolActions.clearTray();
3987
4154
  setConfirmClear(false);
4155
+ if (entries.length === 0) return;
4156
+ flash({
4157
+ kind: 'info',
4158
+ text: translate('status.cleared', { n: entries.length }),
4159
+ undo: () => {
4160
+ poolActions.restoreTray(entries);
4161
+ setStatus(null);
4162
+ },
4163
+ });
3988
4164
  },
3989
4165
  onCancel: () => setConfirmClear(false),
3990
4166
  })
@@ -4043,19 +4219,19 @@ window.__ModuleLoader__.load({
4043
4219
  h(
4044
4220
  'div',
4045
4221
  { className: 'pp-panel-dock' },
4046
- status
4222
+ notice
4047
4223
  ? h(
4048
4224
  'div',
4049
- { className: 'pp-status pp-status-float', 'data-kind': status.kind || 'info' },
4050
- h('span', null, status.text),
4051
- status.undo
4225
+ { className: 'pp-status pp-status-float', 'data-kind': notice.kind || 'info' },
4226
+ h('span', null, notice.text),
4227
+ notice.undo
4052
4228
  ? h(
4053
4229
  'button',
4054
4230
  {
4055
4231
  type: 'button',
4056
4232
  className: 'pp-link',
4057
4233
  onClick: () => {
4058
- status.undo();
4234
+ notice.undo();
4059
4235
  },
4060
4236
  },
4061
4237
  translate('status.undo'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-prompt-pool",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "private": false,
5
5
  "description": "A prompt staging pool beside the DSH composer: capture drafts, arrange a playlist, release it into the queue.",
6
6
  "license": "MIT",