@goodpeanuts/dsh-sui 0.1.1 → 0.1.2-fix.2

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.
@@ -1128,6 +1128,10 @@ window.__ModuleLoader__.load({
1128
1128
  section: "sync",
1129
1129
  query: { view: "backup" }
1130
1130
  };
1131
+ if (match.routeId === FinanceRouteIds.authorization) return {
1132
+ section: "sync",
1133
+ query: { view: "authorization" }
1134
+ };
1131
1135
  if (match.routeId === FinanceRouteIds.setup) return { section: "sync" };
1132
1136
  if (match.routeId === FinanceRouteIds.preferences) return { section: "preferences" };
1133
1137
  const bookId = match.params.bookId;
@@ -1230,6 +1234,7 @@ window.__ModuleLoader__.load({
1230
1234
  };
1231
1235
  }
1232
1236
  function ledgerRouteTarget(route) {
1237
+ if (route.section === "sync" && route.query?.view === "authorization") return { routeId: FinanceRouteIds.authorization };
1233
1238
  if (route.section === "sync" && route.query?.view === "backup") return { routeId: FinanceRouteIds.maintenance };
1234
1239
  if (route.section === "sync" && !route.bookId) return { routeId: FinanceRouteIds.setup };
1235
1240
  if (route.section === "preferences") return { routeId: FinanceRouteIds.preferences };
@@ -1341,6 +1346,7 @@ window.__ModuleLoader__.load({
1341
1346
  } else if (routeId === FinanceRouteIds.sync) set("view", search.get("view"), [
1342
1347
  "changes",
1343
1348
  "valuation",
1349
+ "authorization",
1344
1350
  "backup"
1345
1351
  ].includes(search.get("view") ?? ""));
1346
1352
  else if (routeId === FinanceRouteIds.accounts) set("group", search.get("group"));
@@ -1411,6 +1417,7 @@ window.__ModuleLoader__.load({
1411
1417
  preferences: "finance.ledger.preferences",
1412
1418
  maintenance: "finance.ledger.maintenance",
1413
1419
  setup: "finance.ledger.setup",
1420
+ authorization: "finance.ledger.authorization",
1414
1421
  overview: "finance.ledger.overview",
1415
1422
  transactions: "finance.ledger.transactions",
1416
1423
  transactionDetail: "finance.ledger.transaction-detail",
@@ -10514,6 +10521,229 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
10514
10521
  init_memo_policy();
10515
10522
  }));
10516
10523
  //#endregion
10524
+ //#region ../../packages/finance-ui/src/book-grant.css
10525
+ var init_book_grant$1 = __esmMin((() => {}));
10526
+ //#endregion
10527
+ //#region ../../packages/finance-ui/src/book-grant.tsx
10528
+ /** A contextual switch inside financial UI, never mounted in an ordinary composer. */
10529
+ function BookGrantControl({ subjectId, client, onOpenLedger, disabled = false }) {
10530
+ const [opened, setOpened] = (0, react.useState)(false);
10531
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10532
+ className: "sui-ledger-draft-ui book-grant-control",
10533
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
10534
+ type: "button",
10535
+ className: "book-grant-trigger",
10536
+ "aria-haspopup": "dialog",
10537
+ "aria-expanded": opened,
10538
+ title: "查看或切换本会话使用的账本",
10539
+ disabled,
10540
+ onClick: () => setOpened(true),
10541
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { name: "book" }), "切换账本"]
10542
+ }), opened && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
10543
+ className: "sui-ledger-draft-ui",
10544
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BookGrantDialog, {
10545
+ subjectId,
10546
+ client,
10547
+ onClose: () => setOpened(false),
10548
+ onOpenLedger
10549
+ })
10550
+ }), document.body)]
10551
+ });
10552
+ }
10553
+ function BookGrantDialog({ subjectId, client, onClose, onOpenLedger }) {
10554
+ const dialog = (0, react.useRef)(null);
10555
+ const alive = (0, react.useRef)(true);
10556
+ const running = (0, react.useRef)(false);
10557
+ const [data, setData] = (0, react.useState)(null);
10558
+ const [selected, setSelected] = (0, react.useState)("");
10559
+ const [makeDefault, setMakeDefault] = (0, react.useState)(false);
10560
+ const [busy, setBusy] = (0, react.useState)(false);
10561
+ const [error, setError] = (0, react.useState)("");
10562
+ const load = (0, react.useCallback)(async () => {
10563
+ if (running.current) return;
10564
+ running.current = true;
10565
+ setBusy(true);
10566
+ setError("");
10567
+ setData(null);
10568
+ setMakeDefault(false);
10569
+ try {
10570
+ if (!client.requestBookGrantSelection) throw new Error("请更新插件后重试。");
10571
+ const next = await client.requestBookGrantSelection(subjectId);
10572
+ if (!alive.current) return;
10573
+ setData(next);
10574
+ const preferred = next.grant?.bookId ?? next.defaultBookId;
10575
+ setSelected(next.books.find((book) => book.id === preferred)?.id ?? next.books[0]?.id ?? "");
10576
+ } catch {
10577
+ if (alive.current) setError("无法读取账本授权,请重试。");
10578
+ } finally {
10579
+ running.current = false;
10580
+ if (alive.current) setBusy(false);
10581
+ }
10582
+ }, [client, subjectId]);
10583
+ (0, react.useEffect)(() => {
10584
+ alive.current = true;
10585
+ const element = dialog.current;
10586
+ element.showModal();
10587
+ load();
10588
+ return () => {
10589
+ alive.current = false;
10590
+ element.close();
10591
+ };
10592
+ }, [load]);
10593
+ const finish = async (decision) => {
10594
+ if (running.current) return;
10595
+ if (!data || !client.respondBookGrantSelection) {
10596
+ onClose();
10597
+ return;
10598
+ }
10599
+ running.current = true;
10600
+ setBusy(true);
10601
+ setError("");
10602
+ try {
10603
+ await client.respondBookGrantSelection(subjectId, data.request.id, {
10604
+ decision,
10605
+ ...decision === "confirm" ? {
10606
+ bookId: selected,
10607
+ makeDefault
10608
+ } : {}
10609
+ });
10610
+ window.dispatchEvent(new Event("sui-ledger:finance-updated"));
10611
+ if (alive.current) onClose();
10612
+ } catch (cause) {
10613
+ if (!alive.current) return;
10614
+ if (decision === "cancel") onClose();
10615
+ else if (cause instanceof Error && cause.message === "finance_draft_book_change_blocked") setError("当前会话仍有流水草稿,请先将其加入待入账或移除全部条目,再切换账本。");
10616
+ else setError("授权未完成,账本可能已在其他页面更改。请重新读取后确认。");
10617
+ } finally {
10618
+ running.current = false;
10619
+ if (alive.current) setBusy(false);
10620
+ }
10621
+ };
10622
+ const clearDefault = async () => {
10623
+ if (running.current || !client.setDefaultBook) return;
10624
+ running.current = true;
10625
+ setBusy(true);
10626
+ setError("");
10627
+ try {
10628
+ await client.setDefaultBook(null);
10629
+ if (alive.current) {
10630
+ setData((current) => current && {
10631
+ ...current,
10632
+ defaultBookId: null
10633
+ });
10634
+ setMakeDefault(false);
10635
+ }
10636
+ } catch {
10637
+ if (alive.current) setError("清除默认账本失败,请重试。");
10638
+ } finally {
10639
+ running.current = false;
10640
+ if (alive.current) setBusy(false);
10641
+ }
10642
+ };
10643
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dialog", {
10644
+ ref: dialog,
10645
+ className: "book-grant-dialog",
10646
+ "aria-labelledby": "book-grant-title",
10647
+ onCancel: (event) => {
10648
+ event.preventDefault();
10649
+ finish("cancel");
10650
+ },
10651
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
10652
+ onSubmit: (event) => {
10653
+ event.preventDefault();
10654
+ if (selected && !busy) finish("confirm");
10655
+ },
10656
+ children: [
10657
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
10658
+ id: "book-grant-title",
10659
+ children: "选择会话账本"
10660
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
10661
+ type: "button",
10662
+ tone: "ghost",
10663
+ disabled: busy,
10664
+ "aria-label": "关闭账本授权",
10665
+ onClick: () => void finish("cancel"),
10666
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { name: "close" })
10667
+ })] }),
10668
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "授权后,当前会话可读取所选账本并维护草稿;实际入账仍需单独人工确认。" }),
10669
+ data && data.books.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
10670
+ className: "workset-field",
10671
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "授权账本" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
10672
+ value: selected,
10673
+ disabled: busy,
10674
+ onChange: (event) => setSelected(event.currentTarget.value),
10675
+ children: data.books.map((book) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
10676
+ value: book.id,
10677
+ children: book.name || book.id
10678
+ }, book.id))
10679
+ })]
10680
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
10681
+ className: "book-grant-default",
10682
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
10683
+ type: "checkbox",
10684
+ checked: makeDefault,
10685
+ disabled: busy,
10686
+ onChange: (event) => setMakeDefault(event.currentTarget.checked)
10687
+ }), "设为默认账本,供尚未授权的会话自动使用"]
10688
+ })] }),
10689
+ data && data.books.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10690
+ role: "status",
10691
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "尚无可用账本,请先在账本页面登录并同步。" }), onOpenLedger && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
10692
+ type: "button",
10693
+ disabled: busy,
10694
+ onClick: () => {
10695
+ finish("cancel").then(onOpenLedger);
10696
+ },
10697
+ children: "打开账本"
10698
+ })]
10699
+ }),
10700
+ data?.defaultBookId && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10701
+ className: "book-grant-current-default",
10702
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["默认账本:", data.books.find((book) => book.id === data.defaultBookId)?.name ?? data.defaultBookId] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
10703
+ type: "button",
10704
+ tone: "ghost",
10705
+ disabled: busy,
10706
+ onClick: () => void clearDefault(),
10707
+ children: "清除默认账本"
10708
+ })]
10709
+ }),
10710
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
10711
+ role: "alert",
10712
+ children: error
10713
+ }),
10714
+ busy && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
10715
+ role: "status",
10716
+ children: "正在处理…"
10717
+ }),
10718
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("footer", { children: [
10719
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
10720
+ type: "button",
10721
+ disabled: busy,
10722
+ onClick: () => void finish("cancel"),
10723
+ children: "取消"
10724
+ }),
10725
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
10726
+ type: "button",
10727
+ disabled: busy,
10728
+ onClick: () => void load(),
10729
+ children: "重新读取"
10730
+ }),
10731
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
10732
+ type: "submit",
10733
+ tone: "primary",
10734
+ disabled: busy || !data?.books.length || !selected,
10735
+ children: "确认授权"
10736
+ })
10737
+ ] })
10738
+ ]
10739
+ })
10740
+ });
10741
+ }
10742
+ var init_book_grant = __esmMin((() => {
10743
+ init_src$2();
10744
+ init_book_grant$1();
10745
+ }));
10746
+ //#endregion
10517
10747
  //#region ../../packages/finance-ui/src/draft-view.ts
10518
10748
  /** Session surfaces share one open-note read/poll; archives are never loaded. */
10519
10749
  function draftSource(client, subjectId) {
@@ -10755,9 +10985,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
10755
10985
  role: "status",
10756
10986
  children: [props.validation.issues.length, " 项待检查"]
10757
10987
  }),
10758
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
10988
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
10759
10989
  className: "candidate-head-actions",
10760
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
10990
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BookGrantControl, {
10991
+ subjectId: props.subjectId,
10992
+ client: props.client,
10993
+ disabled: busy || dirty
10994
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
10761
10995
  type: "button",
10762
10996
  className: "draft-icon-btn",
10763
10997
  "data-panel-action": "close",
@@ -10765,7 +10999,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
10765
10999
  disabled: busy,
10766
11000
  onClick: props.onClose,
10767
11001
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { name: "close" })
10768
- })
11002
+ })]
10769
11003
  })
10770
11004
  ]
10771
11005
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -11176,6 +11410,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
11176
11410
  init_web_contracts();
11177
11411
  init_src();
11178
11412
  init_draft_entry_editor();
11413
+ init_book_grant();
11179
11414
  init_draft_view();
11180
11415
  TAB_LABELS = {
11181
11416
  ready: "待处理",
@@ -11229,6 +11464,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
11229
11464
  };
11230
11465
  const readStatus = (path) => request(path, { signal: AbortSignal.timeout(1e4) });
11231
11466
  return {
11467
+ async requestBookGrantSelection(subjectId) {
11468
+ return request(`/finance/subjects/${encodeURIComponent(subjectId)}/grant/selection`, jsonRequest("POST", {}));
11469
+ },
11470
+ async respondBookGrantSelection(subjectId, requestId, response) {
11471
+ return request(`/finance/subjects/${encodeURIComponent(subjectId)}/grant/selection/${encodeURIComponent(requestId)}`, jsonRequest("POST", response));
11472
+ },
11473
+ async setDefaultBook(bookId) {
11474
+ return (await request("/finance/default-book", jsonRequest("PUT", { bookId }))).bookId;
11475
+ },
11232
11476
  async getPreparation(worksetId) {
11233
11477
  return (await readStatus(`/finance/worksets/${encodeURIComponent(worksetId)}/preparation`)).operation;
11234
11478
  },
@@ -11354,6 +11598,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
11354
11598
  description: "备份与恢复。",
11355
11599
  loadPage: loadLedgerPage
11356
11600
  },
11601
+ {
11602
+ id: FinanceRouteIds.authorization,
11603
+ path: "/ledger/authorization",
11604
+ description: "账本授权。",
11605
+ loadPage: loadLedgerPage
11606
+ },
11357
11607
  {
11358
11608
  id: FinanceRouteIds.setup,
11359
11609
  path: "/ledger/setup",
@@ -14397,6 +14647,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14397
14647
  init_transaction_time();
14398
14648
  init_memo_policy();
14399
14649
  init_draft_card();
14650
+ init_book_grant();
14400
14651
  init_ledger_route();
14401
14652
  }));
14402
14653
  //#endregion
@@ -15014,6 +15265,53 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15014
15265
  init_local_ledger_helpers();
15015
15266
  }));
15016
15267
  //#endregion
15268
+ //#region ../../packages/finance-ui/src/ledger-sync-tabs.css
15269
+ var init_ledger_sync_tabs$1 = __esmMin((() => {}));
15270
+ //#endregion
15271
+ //#region ../../packages/finance-ui/src/ledger-sync-tabs.tsx
15272
+ function LedgerSyncTabs({ view, bookId, onNavigate, busy = false }) {
15273
+ const element = (0, react.useRef)(null);
15274
+ (0, react.useLayoutEffect)(() => {
15275
+ const nav = element.current;
15276
+ const reveal = () => {
15277
+ const active = nav.querySelector("[aria-current=\"page\"]");
15278
+ if (!active) return;
15279
+ const item = active.getBoundingClientRect(), bounds = nav.getBoundingClientRect();
15280
+ if (item.left < bounds.left) nav.scrollLeft -= bounds.left - item.left;
15281
+ else if (item.right > bounds.right) nav.scrollLeft += item.right - bounds.right;
15282
+ };
15283
+ reveal();
15284
+ const observer = new ResizeObserver(reveal);
15285
+ observer.observe(nav);
15286
+ return () => observer.disconnect();
15287
+ }, [view]);
15288
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
15289
+ ref: element,
15290
+ className: "ledger-sync-tabs",
15291
+ "aria-label": "数据与同步分区",
15292
+ children: [
15293
+ ["status", "同步状态"],
15294
+ ["changes", "流水变更"],
15295
+ ["valuation", "汇率与计算"],
15296
+ ["authorization", "账本授权"],
15297
+ ["backup", "备份与恢复"]
15298
+ ].map(([value, label]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
15299
+ type: "button",
15300
+ "aria-current": view === value ? "page" : void 0,
15301
+ disabled: busy || !bookId && (value === "changes" || value === "valuation"),
15302
+ onClick: () => onNavigate({
15303
+ ...bookId ? { bookId } : {},
15304
+ section: "sync",
15305
+ ...value === "status" ? {} : { query: { view: value } }
15306
+ }),
15307
+ children: label
15308
+ }, value))
15309
+ });
15310
+ }
15311
+ var init_ledger_sync_tabs = __esmMin((() => {
15312
+ init_ledger_sync_tabs$1();
15313
+ }));
15314
+ //#endregion
15017
15315
  //#region ../../packages/finance-ui/src/local-ledger-changes.tsx
15018
15316
  function LedgerChanges({ bookId, refreshKey, onNavigate }) {
15019
15317
  const fetchImpl = useLedgerFetch();
@@ -17781,36 +18079,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17781
18079
  const relevant = syncRecordsWithLiveOperation(syncRecords, book.id, liveSyncRecord);
17782
18080
  const latest = [...relevant].filter((item) => syncStatusKind(item.status) === "complete").sort((left, right) => String(right.completedAt).localeCompare(String(left.completedAt)))[0];
17783
18081
  const view = route.query?.view === "changes" || route.query?.view === "valuation" ? route.query.view : "status";
17784
- const tabs = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
17785
- className: "ledger-sync-tabs",
17786
- "aria-label": "数据与同步分区",
17787
- children: [
17788
- {
17789
- value: "status",
17790
- label: "同步状态"
17791
- },
17792
- {
17793
- value: "changes",
17794
- label: "流水变更"
17795
- },
17796
- {
17797
- value: "valuation",
17798
- label: "汇率与计算"
17799
- },
17800
- {
17801
- value: "backup",
17802
- label: "备份与恢复"
17803
- }
17804
- ].map((tab) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
17805
- type: "button",
17806
- "aria-current": view === tab.value ? "page" : void 0,
17807
- onClick: () => onNavigate({
17808
- bookId: book.id,
17809
- section: "sync",
17810
- ...tab.value === "status" ? {} : { query: { view: tab.value } }
17811
- }),
17812
- children: tab.label
17813
- }, tab.value))
18082
+ const tabs = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LedgerSyncTabs, {
18083
+ view,
18084
+ bookId: book.id,
18085
+ onNavigate
17814
18086
  });
17815
18087
  if (view === "changes") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17816
18088
  className: "ledger-page ledger-changes-page",
@@ -18625,6 +18897,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18625
18897
  init_finance_client();
18626
18898
  init_local_ledger_helpers();
18627
18899
  init_local_ledger_visuals();
18900
+ init_ledger_sync_tabs();
18628
18901
  init_local_ledger_changes();
18629
18902
  init_account_period();
18630
18903
  PAGE_SIZE = 15;
@@ -20081,25 +20354,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20081
20354
  className: "page-head",
20082
20355
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: "数据与同步" })
20083
20356
  }),
20084
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
20085
- className: "ledger-sync-tabs",
20086
- "aria-label": "数据与同步分区",
20087
- children: [
20088
- ["status", "同步状态"],
20089
- ["changes", "流水变更"],
20090
- ["valuation", "汇率与计算"],
20091
- ["backup", "备份与恢复"]
20092
- ].map(([view, label]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
20093
- type: "button",
20094
- "aria-current": view === "backup" ? "page" : void 0,
20095
- disabled: view !== "backup" && view !== "status" && !bookId || !!busy,
20096
- onClick: () => onNavigate({
20097
- ...bookId ? { bookId } : {},
20098
- section: "sync",
20099
- ...view === "status" ? {} : { query: { view } }
20100
- }),
20101
- children: label
20102
- }, view))
20357
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LedgerSyncTabs, {
20358
+ view: "backup",
20359
+ bookId,
20360
+ onNavigate,
20361
+ busy: Boolean(busy)
20103
20362
  }),
20104
20363
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20105
20364
  className: "backup-action-row",
@@ -20263,6 +20522,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20263
20522
  }
20264
20523
  var BASE, post;
20265
20524
  var init_backup_recovery = __esmMin((() => {
20525
+ init_ledger_sync_tabs();
20266
20526
  init_ledger_transport();
20267
20527
  init_src$2();
20268
20528
  init_backup_recovery$1();
@@ -22105,6 +22365,174 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
22105
22365
  };
22106
22366
  }));
22107
22367
  //#endregion
22368
+ //#region ../../packages/finance-ui/src/book-authorization.css
22369
+ var init_book_authorization$1 = __esmMin((() => {}));
22370
+ //#endregion
22371
+ //#region ../../packages/finance-ui/src/book-authorization.tsx
22372
+ /** Profile-wide opt-in. It does not mint grants just because a chat is opened. */
22373
+ function BookAuthorizationPage({ client, books, bookId, onNavigate }) {
22374
+ const [current, setCurrent] = (0, react.useState)(null);
22375
+ const [selected, setSelected] = (0, react.useState)("");
22376
+ const [remember, setRemember] = (0, react.useState)(false);
22377
+ const [loading, setLoading] = (0, react.useState)(true);
22378
+ const [busy, setBusy] = (0, react.useState)(false);
22379
+ const [error, setError] = (0, react.useState)("");
22380
+ const [notice, setNotice] = (0, react.useState)("");
22381
+ const alive = (0, react.useRef)(true), locked = (0, react.useRef)(false);
22382
+ const [reload, setReload] = (0, react.useState)(0);
22383
+ (0, react.useEffect)(() => {
22384
+ let active = true;
22385
+ alive.current = true;
22386
+ setLoading(true);
22387
+ setError("");
22388
+ client.getDefaultBook().then((value) => {
22389
+ if (!active) return;
22390
+ setCurrent(value);
22391
+ setRemember(Boolean(value));
22392
+ setSelected(books.find((book) => book.id === value)?.id ?? books.find((book) => book.id === bookId)?.id ?? books[0]?.id ?? "");
22393
+ }).catch(() => {
22394
+ if (active) setError("无法读取账本授权,请重试。");
22395
+ }).finally(() => {
22396
+ if (active) setLoading(false);
22397
+ });
22398
+ return () => {
22399
+ active = false;
22400
+ alive.current = false;
22401
+ };
22402
+ }, [
22403
+ client,
22404
+ books,
22405
+ bookId,
22406
+ reload
22407
+ ]);
22408
+ const save = async (value) => {
22409
+ if (locked.current || !client.setDefaultBook) return;
22410
+ locked.current = true;
22411
+ setBusy(true);
22412
+ setError("");
22413
+ setNotice("");
22414
+ try {
22415
+ await client.setDefaultBook(value);
22416
+ if (!alive.current) return;
22417
+ setCurrent(value);
22418
+ setRemember(Boolean(value));
22419
+ setNotice(value ? "授权已保存,后续会话使用财务功能时将自动使用此账本。" : "已停止为新会话自动授权;已有会话的授权与草稿不受影响。");
22420
+ window.dispatchEvent(new Event("sui-ledger:finance-updated"));
22421
+ } catch {
22422
+ if (alive.current) setError("保存账本授权失败,请重新读取后重试。");
22423
+ } finally {
22424
+ locked.current = false;
22425
+ if (alive.current) setBusy(false);
22426
+ }
22427
+ };
22428
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
22429
+ className: "ledger-page book-authorization-page",
22430
+ children: [
22431
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
22432
+ className: "page-head",
22433
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: "数据与同步" })
22434
+ }),
22435
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LedgerSyncTabs, {
22436
+ view: "authorization",
22437
+ bookId,
22438
+ onNavigate,
22439
+ busy
22440
+ }),
22441
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
22442
+ className: "book-authorization-settings",
22443
+ "aria-labelledby": "book-authorization-title",
22444
+ children: [
22445
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
22446
+ id: "book-authorization-title",
22447
+ children: "账本授权"
22448
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
22449
+ className: "book-authorization-status",
22450
+ children: loading ? "正在读取" : current ? "已授权" : "未设置"
22451
+ })] }),
22452
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "选择默认账本,之后使用财务功能时无需重复授权。" }),
22453
+ loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
22454
+ role: "status",
22455
+ children: "正在读取账本授权…"
22456
+ }) : books.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "尚无可用账本,请先登录并同步。" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
22457
+ type: "button",
22458
+ onClick: () => onNavigate({ section: "sync" }),
22459
+ children: "登录并同步账本"
22460
+ })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
22461
+ onSubmit: (event) => {
22462
+ event.preventDefault();
22463
+ if (!busy && (remember ? selected : current)) save(remember ? selected : null);
22464
+ },
22465
+ children: [
22466
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
22467
+ className: "book-authorization-field",
22468
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "默认账本" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
22469
+ value: selected,
22470
+ disabled: busy || Boolean(error),
22471
+ onChange: (event) => setSelected(event.currentTarget.value),
22472
+ children: books.map((book) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
22473
+ value: book.id,
22474
+ children: book.name || book.id
22475
+ }, book.id))
22476
+ })]
22477
+ }),
22478
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
22479
+ className: "book-authorization-remember",
22480
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
22481
+ type: "checkbox",
22482
+ checked: remember,
22483
+ disabled: busy || Boolean(error),
22484
+ onChange: (event) => setRemember(event.currentTarget.checked)
22485
+ }), "后续会话使用财务功能时自动使用此账本"]
22486
+ }),
22487
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
22488
+ className: "book-authorization-note",
22489
+ children: "仅在使用财务功能时读取账本。实际入账仍需人工确认。"
22490
+ }),
22491
+ current && !books.some((book) => book.id === current) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
22492
+ role: "status",
22493
+ children: "原授权账本暂不可用,请重新选择可用账本。"
22494
+ }),
22495
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("footer", { children: [current && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
22496
+ type: "button",
22497
+ disabled: busy,
22498
+ onClick: () => void save(null),
22499
+ children: "停止自动授权"
22500
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
22501
+ type: "submit",
22502
+ tone: "primary",
22503
+ disabled: busy || (remember ? !selected : !current) || Boolean(error) || !client.setDefaultBook,
22504
+ children: current ? "保存更改" : "确认授权"
22505
+ })] })
22506
+ ]
22507
+ }),
22508
+ busy && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
22509
+ role: "status",
22510
+ children: "正在保存…"
22511
+ }),
22512
+ notice && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
22513
+ role: "status",
22514
+ children: notice
22515
+ }),
22516
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
22517
+ role: "alert",
22518
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: error }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
22519
+ type: "button",
22520
+ disabled: busy,
22521
+ onClick: () => setReload((value) => value + 1),
22522
+ children: "重新读取"
22523
+ })]
22524
+ })
22525
+ ]
22526
+ })
22527
+ ]
22528
+ });
22529
+ }
22530
+ var init_book_authorization = __esmMin((() => {
22531
+ init_src$2();
22532
+ init_ledger_sync_tabs();
22533
+ init_book_authorization$1();
22534
+ }));
22535
+ //#endregion
22108
22536
  //#region ../../packages/finance-ui/src/first-run-setup.css
22109
22537
  var init_first_run_setup$1 = __esmMin((() => {}));
22110
22538
  //#endregion
@@ -22176,34 +22604,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
22176
22604
  className: "page-head",
22177
22605
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: showTabs ? "数据与同步" : "连接随手记账本" })
22178
22606
  }),
22179
- showTabs && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("nav", {
22180
- className: "ledger-sync-tabs",
22181
- "aria-label": "数据与同步分区",
22182
- children: [
22183
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
22184
- type: "button",
22185
- "aria-current": "page",
22186
- children: "同步状态"
22187
- }),
22188
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
22189
- type: "button",
22190
- disabled: true,
22191
- children: "流水变更"
22192
- }),
22193
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
22194
- type: "button",
22195
- disabled: true,
22196
- children: "汇率与计算"
22197
- }),
22198
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
22199
- type: "button",
22200
- onClick: () => onNavigate({
22201
- section: "sync",
22202
- query: { view: "backup" }
22203
- }),
22204
- children: "备份与恢复"
22205
- })
22206
- ]
22607
+ showTabs && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LedgerSyncTabs, {
22608
+ view: "status",
22609
+ onNavigate,
22610
+ busy
22207
22611
  }),
22208
22612
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
22209
22613
  className: "ledger-card first-run-card",
@@ -22311,6 +22715,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
22311
22715
  });
22312
22716
  }
22313
22717
  var init_first_run_setup = __esmMin((() => {
22718
+ init_ledger_sync_tabs();
22314
22719
  init_src$2();
22315
22720
  init_ledger_sync_progress();
22316
22721
  init_session_recovery();
@@ -22375,7 +22780,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
22375
22780
  return () => controller.abort();
22376
22781
  }, [fetchImpl]);
22377
22782
  (0, react.useEffect)(() => {
22378
- if (loading || props.route.section === "preferences" || props.route.query?.view === "backup") return;
22783
+ if (loading || props.route.section === "preferences" || ["backup", "authorization"].includes(props.route.query?.view ?? "")) return;
22379
22784
  if (books.length === 0) return;
22380
22785
  const requestedBook = props.route.bookId;
22381
22786
  if (requestedBook && !books.some((item) => item.id === requestedBook)) return;
@@ -22487,6 +22892,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
22487
22892
  }) : section === "preferences" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PersonalPreferencesPage, {
22488
22893
  onDirtyChange: setPreferencesDirty,
22489
22894
  onSavingChange: setPreferencesSaving
22895
+ }) : section === "sync" && props.route.query?.view === "authorization" && !loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BookAuthorizationPage, {
22896
+ client: props.financeClient,
22897
+ books,
22898
+ bookId: bookId || void 0,
22899
+ onNavigate: props.onNavigate
22490
22900
  }) : loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LedgerState, {
22491
22901
  icon: "refresh",
22492
22902
  title: "正在读取账本",
@@ -22611,6 +23021,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
22611
23021
  init_local_ledger_visuals();
22612
23022
  init_backup_recovery();
22613
23023
  init_service_records_page();
23024
+ init_book_authorization();
22614
23025
  init_first_run_setup();
22615
23026
  LEDGER_BOOK_KEY = "sui-ledger.local-ledger.book";
22616
23027
  LEDGER_SECTION_KEY = "sui-ledger.local-ledger.section";
@@ -22698,6 +23109,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
22698
23109
  description: "备份与恢复。",
22699
23110
  loadPage: stubLoadPage
22700
23111
  },
23112
+ {
23113
+ id: FinanceRouteIds.authorization,
23114
+ path: "/ledger/authorization",
23115
+ ownerModuleId: OWNER_MODULE_ID,
23116
+ description: "账本授权。",
23117
+ loadPage: stubLoadPage
23118
+ },
22701
23119
  {
22702
23120
  id: FinanceRouteIds.setup,
22703
23121
  path: "/ledger/setup",
@@ -23539,6 +23957,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
23539
23957
  function DraftAddToolview({ block }) {
23540
23958
  const result = asRecord(parseResult(block));
23541
23959
  const counts = asRecord(result?.counts);
23960
+ const state = blockState(block);
23542
23961
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Frame, {
23543
23962
  title: "流水草稿 · 追加",
23544
23963
  block,
@@ -23564,7 +23983,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
23564
23983
  }) : null,
23565
23984
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
23566
23985
  k: "提示",
23567
- v: blockState(block) === "ok" && result?.draftId ? "已加到会话草稿便签,可从输入框上方的草稿图标打开;未入账。" : "尚未追加成功,请查看调用结果。"
23986
+ v: blockState(block) === "ok" && result?.draftId ? "已加到会话草稿便签,可从输入框上方的草稿图标打开;未入账。" : state === "running" || state === "preparing" ? "正在处理,请稍候。" : "尚未追加成功,请查看调用结果。"
23568
23987
  })
23569
23988
  ]
23570
23989
  });