@linxin666/dsh-client-ui-task-board 0.3.9 → 0.3.10

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/lib/client.js CHANGED
@@ -1767,8 +1767,21 @@ window.__ModuleLoader__.load({
1767
1767
  function dictionary() {
1768
1768
  return (typeof document !== "undefined" ? document.documentElement.lang : "zh").toLowerCase().startsWith("en") ? en : zh;
1769
1769
  }
1770
+ /**
1771
+ * SDK translate seat wired by the browser apply() once ctx.locale is bound
1772
+ * (setRuntimeTranslate). When present it reads the ACTIVE locale at call
1773
+ * time, so plain-DOM surfaces (sidebar row, toggles) follow a runtime
1774
+ * language switch; the document-language pick above stays only as the
1775
+ * unwired fallback (locale service absent, module-scope early callers).
1776
+ */
1777
+ let runtimeT;
1778
+ /** Wire the SDK translate seat; pass undefined to restore the document-language pick. */
1779
+ function setRuntimeTranslate(t) {
1780
+ runtimeT = t;
1781
+ }
1770
1782
  /** Translate a key with optional {name} template params. */
1771
1783
  function t(key, params) {
1784
+ if (runtimeT !== void 0) return runtimeT(key, params);
1772
1785
  let text = dictionary()[key];
1773
1786
  if (params !== void 0) for (const [name, value] of Object.entries(params)) text = text.replaceAll(`{${name}}`, value);
1774
1787
  return text;
@@ -3283,11 +3296,19 @@ window.__ModuleLoader__.load({
3283
3296
  * Mount the board React tree into the center column and bind its visibility
3284
3297
  * to the controller's boardOpen state.
3285
3298
  * @param controller - the board controller driving the view.
3299
+ * @param locale - locale-change source; when given, re-renders a mounted board
3300
+ * on a Language switch.
3286
3301
  * @returns disposer unmounting the tree and restoring the column.
3287
3302
  */
3288
- function mountBoard(controller) {
3303
+ function mountBoard(controller, locale) {
3289
3304
  let root;
3290
3305
  let container;
3306
+ let unsubscribeLocale;
3307
+ try {
3308
+ unsubscribeLocale = locale?.subscribe(() => {
3309
+ if (root !== void 0) root.render(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TaskBoard, { controller }));
3310
+ });
3311
+ } catch {}
3291
3312
  const ensure = () => {
3292
3313
  if (container !== void 0) {
3293
3314
  if (container.isConnected) return;
@@ -3340,6 +3361,7 @@ window.__ModuleLoader__.load({
3340
3361
  document.removeEventListener(ACTIVATE_EVENT, onOtherActivate);
3341
3362
  waitObserver.disconnect();
3342
3363
  unsubscribe();
3364
+ unsubscribeLocale?.();
3343
3365
  document.documentElement.removeAttribute(ACTIVE_ATTR);
3344
3366
  root?.unmount();
3345
3367
  root = void 0;
@@ -3371,11 +3393,23 @@ window.__ModuleLoader__.load({
3371
3393
  entry.setAttribute("data-dsh-part", "sidebar-entry");
3372
3394
  }
3373
3395
  entry.className = options.css["entry"] ?? "";
3374
- entry.setAttribute("aria-label", options.label());
3375
- if (options.tooltip !== void 0) entry.setAttribute("title", options.tooltip());
3376
- entry.innerHTML = "<span class=\"" + (options.css["entryIcon"] ?? "") + "\">" + options.icon + "</span><span class=\"" + (options.css["entryLabel"] ?? "") + "\">" + options.label() + "</span>";
3396
+ const labelSpan = document.createElement("span");
3397
+ labelSpan.className = options.css["entryLabel"] ?? "";
3398
+ const iconSpan = document.createElement("span");
3399
+ iconSpan.className = options.css["entryIcon"] ?? "";
3400
+ iconSpan.innerHTML = options.icon;
3401
+ entry.append(iconSpan, labelSpan);
3402
+ const applyLabel = () => {
3403
+ entry.setAttribute("aria-label", options.label());
3404
+ if (options.tooltip !== void 0) entry.setAttribute("title", options.tooltip());
3405
+ labelSpan.textContent = options.label();
3406
+ };
3407
+ applyLabel();
3377
3408
  entry.addEventListener("click", options.onToggle);
3378
- return entry;
3409
+ return {
3410
+ entry,
3411
+ applyLabel
3412
+ };
3379
3413
  }
3380
3414
  /** Re-insert the entry after the New Session row (before the browser region). */
3381
3415
  function placeEntry(root, entry, options) {
@@ -3398,9 +3432,13 @@ window.__ModuleLoader__.load({
3398
3432
  */
3399
3433
  function mountSidebarEntry$1(options) {
3400
3434
  if (typeof document !== "undefined" && document.querySelector(options.rowSelector) !== null) return () => {};
3401
- const entry = createEntry(options);
3435
+ const { entry, applyLabel } = createEntry(options);
3402
3436
  let root;
3403
3437
  let placed = false;
3438
+ let unsubscribeRefresh;
3439
+ if (options.refresh !== void 0) try {
3440
+ unsubscribeRefresh = options.refresh.subscribe(applyLabel);
3441
+ } catch {}
3404
3442
  const tryPlace = () => {
3405
3443
  if (root !== void 0 && !root.isConnected) {
3406
3444
  rootObserver.disconnect();
@@ -3449,6 +3487,7 @@ window.__ModuleLoader__.load({
3449
3487
  return () => {
3450
3488
  waitObserver.disconnect();
3451
3489
  rootObserver.disconnect();
3490
+ unsubscribeRefresh?.();
3452
3491
  unsubscribeActive?.();
3453
3492
  entry.remove();
3454
3493
  };
@@ -3463,9 +3502,11 @@ window.__ModuleLoader__.load({
3463
3502
  * Mount the sidebar entry, waiting for the shell to render and self-healing
3464
3503
  * on later React re-renders.
3465
3504
  * @param controller - the board controller the entry toggles.
3505
+ * @param locale - locale-change source; when given, re-applies the label on
3506
+ * a Language switch (the plain-DOM row otherwise keeps the mount-time copy).
3466
3507
  * @returns disposer removing the entry and its observers.
3467
3508
  */
3468
- function mountSidebarEntry(controller) {
3509
+ function mountSidebarEntry(controller, locale) {
3469
3510
  return mountSidebarEntry$1({
3470
3511
  rowAttribute: "data-dsh-taskboard-entry",
3471
3512
  rowSelector: ENTRY_SELECTOR,
@@ -3473,6 +3514,7 @@ window.__ModuleLoader__.load({
3473
3514
  icon: ICON,
3474
3515
  css: board_module_css_default,
3475
3516
  label: () => t("entry.label"),
3517
+ refresh: locale === void 0 ? void 0 : { subscribe: (listener) => locale.subscribe(listener) },
3476
3518
  onToggle: () => {
3477
3519
  controller.toggleBoard();
3478
3520
  },
@@ -4421,7 +4463,7 @@ window.__ModuleLoader__.load({
4421
4463
  /** The building package's version, when the bundle carries it. */
4422
4464
  function bakedVersion() {
4423
4465
  try {
4424
- return "0.3.9";
4466
+ return "0.3.10";
4425
4467
  } catch {
4426
4468
  return;
4427
4469
  }
@@ -4562,6 +4604,9 @@ window.__ModuleLoader__.load({
4562
4604
  return () => {};
4563
4605
  }
4564
4606
  }, "task-board: dictionaries");
4607
+ try {
4608
+ setRuntimeTranslate(ctx.locale.bind(NS));
4609
+ } catch {}
4565
4610
  const settingsScope = (ctx.get("webUiSettings") ?? ctx.settingsScope).bind({ namespace: TASK_BOARD_NS });
4566
4611
  const settingsCard = new TaskBoardSettingsCardController(settingsScope);
4567
4612
  ctx.slots.inject("web-ui.plugin.item", () => {
@@ -4626,8 +4671,8 @@ window.__ModuleLoader__.load({
4626
4671
  pushPresetOptions();
4627
4672
  }));
4628
4673
  try {
4629
- disposers.push(mountSidebarEntry(controller));
4630
- disposers.push(mountBoard(controller));
4674
+ disposers.push(mountSidebarEntry(controller, ctx.locale));
4675
+ disposers.push(mountBoard(controller, ctx.locale));
4631
4676
  } catch (error) {
4632
4677
  console.error("[dsh-task-board] mount failed:", error);
4633
4678
  }