@lls-a1/dsh-balance-float 1.1.48 → 1.1.53
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 +116 -235
- package/index.js +8 -15
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -27,12 +27,10 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
const h = React.createElement;
|
|
28
28
|
|
|
29
29
|
const NS = 'balance-float';
|
|
30
|
+
/** The published name DSH's plugin manager lists this bundle under. */
|
|
31
|
+
const PACKAGE_NAME = '@lls-a1/dsh-balance-float';
|
|
30
32
|
const ROUTE = '/balance-float/snapshot';
|
|
31
33
|
const ROUTE_UPDATE = '/balance-float/update';
|
|
32
|
-
const NPM_SPEC = '@lls-a1/dsh-balance-float';
|
|
33
|
-
// Native modal support decides whether the mask lives in the top layer.
|
|
34
|
-
const DIALOG_OK =
|
|
35
|
-
typeof document !== 'undefined' && typeof document.createElement('dialog').showModal === 'function';
|
|
36
34
|
const REPO_URL = 'https://github.com/ming-a1/dsh-balance-float';
|
|
37
35
|
const POS_KEY = 'dsh.balance-float.position';
|
|
38
36
|
// Official top-up page; the balance endpoint has no recharge API, so the
|
|
@@ -112,22 +110,13 @@ window.__ModuleLoader__.load({
|
|
|
112
110
|
history: '近 7 天',
|
|
113
111
|
'history.total': '合计 {total}',
|
|
114
112
|
version: '版本',
|
|
115
|
-
'
|
|
116
|
-
'
|
|
117
|
-
'update.checking': '正在检查…',
|
|
118
|
-
'update.failed': '检查失败',
|
|
119
|
-
'update.found': '发现新版本 v{latest}(当前 v{current})',
|
|
120
|
-
'update.latest': '最新版本 v{current}',
|
|
121
|
-
'update.label.current': '当前',
|
|
122
|
-
'update.label.latest': '最新',
|
|
123
|
-
'update.now': '更新',
|
|
124
|
-
'update.copy': '复制安装链接',
|
|
125
|
-
'update.copied': '已复制 ✓',
|
|
126
|
-
'update.installHint': '复制后到插件管理器里粘贴安装(npm 包名,安装源可选用国内镜像)。',
|
|
127
|
-
'update.later': '稍后',
|
|
128
|
-
'update.retry': '点击重试',
|
|
113
|
+
'version.open': '打开插件页(更新在这里)',
|
|
114
|
+
'version.new': '发现新版本 v{latest},点击打开插件页更新',
|
|
129
115
|
source: '本地账本',
|
|
130
116
|
updated: '更新于 {time}',
|
|
117
|
+
refreshing: '正在刷新',
|
|
118
|
+
refreshDone: '刷新完成',
|
|
119
|
+
refreshFailedShort: '刷新失败',
|
|
131
120
|
refresh: '刷新',
|
|
132
121
|
loading: '读取中…',
|
|
133
122
|
retry: '重试',
|
|
@@ -208,22 +197,13 @@ window.__ModuleLoader__.load({
|
|
|
208
197
|
history: 'Last 7 days',
|
|
209
198
|
'history.total': 'Total {total}',
|
|
210
199
|
version: 'Version',
|
|
211
|
-
'
|
|
212
|
-
'
|
|
213
|
-
'update.checking': 'Checking…',
|
|
214
|
-
'update.failed': 'Update check failed',
|
|
215
|
-
'update.found': 'v{latest} is available (you have v{current})',
|
|
216
|
-
'update.latest': 'Latest version v{current}',
|
|
217
|
-
'update.label.current': 'Current',
|
|
218
|
-
'update.label.latest': 'Latest',
|
|
219
|
-
'update.now': 'Update',
|
|
220
|
-
'update.copy': 'Copy install spec',
|
|
221
|
-
'update.copied': 'Copied ✓',
|
|
222
|
-
'update.installHint': 'Paste this npm package name into the plugin manager to upgrade.',
|
|
223
|
-
'update.later': 'Later',
|
|
224
|
-
'update.retry': 'click to retry',
|
|
200
|
+
'version.open': 'Open the plugin page (updates live there)',
|
|
201
|
+
'version.new': 'v{latest} is available — click to open the plugin page',
|
|
225
202
|
source: 'Local ledger',
|
|
226
203
|
updated: 'Updated {time}',
|
|
204
|
+
refreshing: 'Refreshing',
|
|
205
|
+
refreshDone: 'Refresh complete',
|
|
206
|
+
refreshFailedShort: 'Refresh failed',
|
|
227
207
|
refresh: 'Refresh',
|
|
228
208
|
loading: 'Reading…',
|
|
229
209
|
retry: 'Retry',
|
|
@@ -273,7 +253,7 @@ window.__ModuleLoader__.load({
|
|
|
273
253
|
'.dbf-dot.is-peak{background:var(--dsw-alias-state-error-primary)}',
|
|
274
254
|
'.dbf-dot.is-valley{background:var(--dsw-alias-state-success-primary)}',
|
|
275
255
|
'.dbf-badge{display:inline-flex;align-items:center;gap:5px;padding:1px 7px;border-radius:999px;border:.5px solid var(--dsw-alias-border-l1);background:transparent;font-size:11px;line-height:18px;color:var(--dsw-alias-label-secondary)}',
|
|
276
|
-
'.dbf-card{width:316px;border-radius:calc(var(--dbf-radius,16) * 1px);background:transparent;box-shadow:0 12px 36px rgba(0,0,0,calc(.22 * var(--dbf-shadow,1)));overflow:hidden;font-size:12px;line-height:18px;animation:dbf-open-down .24s cubic-bezier(.22,.61,.36,1) both;display:flex;flex-direction:column;will-change:transform,opacity}',
|
|
256
|
+
'.dbf-card{user-select:none;-webkit-user-select:none;width:316px;border-radius:calc(var(--dbf-radius,16) * 1px);background:transparent;box-shadow:0 12px 36px rgba(0,0,0,calc(.22 * var(--dbf-shadow,1)));overflow:hidden;font-size:12px;line-height:18px;animation:dbf-open-down .24s cubic-bezier(.22,.61,.36,1) both;display:flex;flex-direction:column;will-change:transform,opacity}',
|
|
277
257
|
'.dbf-dir-up .dbf-card{animation-name:dbf-open-up}',
|
|
278
258
|
'.dbf-head{display:flex;align-items:center;gap:8px;padding:9px 11px;background:transparent;border-bottom:.5px solid var(--dsw-alias-border-l1);cursor:grab;user-select:none;touch-action:none}',
|
|
279
259
|
'.dbf-head.is-static{cursor:default}',
|
|
@@ -310,27 +290,6 @@ window.__ModuleLoader__.load({
|
|
|
310
290
|
'.dbf-version-glyph{font-size:10px;opacity:.75}',
|
|
311
291
|
'.dbf-version.has-update{color:var(--dsw-alias-state-error-primary)}',
|
|
312
292
|
'.dbf-version.has-update .dbf-version-glyph{opacity:1}',
|
|
313
|
-
'.dbf-modal{position:fixed;top:0;right:0;bottom:0;left:0;height:100dvh;z-index:10;display:flex;align-items:center;justify-content:center;padding:calc(12px + env(safe-area-inset-top,0px)) 12px calc(12px + env(safe-area-inset-bottom,0px));background:rgba(0,0,0,.45);overscroll-behavior:contain;touch-action:none}',
|
|
314
|
-
'.dbf-dialog{position:fixed;top:0;left:0;width:100vw;height:100dvh;min-width:100vw;min-height:100dvh;max-width:none;max-height:none;margin:0;padding:calc(12px + env(safe-area-inset-top,0px)) 12px calc(12px + env(safe-area-inset-bottom,0px));border:0;box-sizing:border-box;background:transparent;color:inherit;display:flex;align-items:center;justify-content:center;overflow:hidden;overscroll-behavior:contain;outline:none}',
|
|
315
|
-
'.dbf-dialog:focus,.dbf-dialog:focus-visible{outline:none}',
|
|
316
|
-
'.dbf-modal-open{scrollbar-width:none}',
|
|
317
|
-
'.dbf-modal-open ::-webkit-scrollbar{width:0;height:0;display:none}',
|
|
318
|
-
'.dbf-dialog::backdrop{background:rgba(0,0,0,.45)}',
|
|
319
|
-
'.dbf-modal-card{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);width:min(308px,calc(100vw - 24px));margin:0;max-height:calc(100dvh - 24px);overflow:auto;touch-action:auto;overscroll-behavior:contain;padding:16px;border-radius:14px;box-shadow:0 18px 48px rgba(0,0,0,calc(.34 * var(--dbf-shadow,1)));background:var(--dsw-alias-bg-layer-1,Canvas);color:var(--dsw-alias-label-primary,CanvasText)}',
|
|
320
|
-
'.dbf-modal-head{display:flex;align-items:center;gap:8px;margin-bottom:10px}',
|
|
321
|
-
'.dbf-modal-icon{width:22px;height:22px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-overlay));color:var(--dsw-alias-brand-primary,#4d6bfe);font-size:12px;line-height:1}',
|
|
322
|
-
'.dbf-modal-title{font-size:13px;font-weight:600}',
|
|
323
|
-
'.dbf-modal-body{font-size:12px;line-height:18px}',
|
|
324
|
-
'.dbf-modal-note{margin-top:6px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary,currentColor);opacity:.85}',
|
|
325
|
-
'.dbf-modal-versions{display:flex;align-items:center;gap:8px;margin-top:8px}',
|
|
326
|
-
'.dbf-modal-version{display:flex;flex-direction:column;gap:1px;padding:4px 8px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-overlay))}',
|
|
327
|
-
'.dbf-modal-version.is-new{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4d6bfe) 14%,transparent)}',
|
|
328
|
-
'.dbf-modal-version-label{font-size:10px;line-height:13px;color:var(--dsw-alias-label-secondary,currentColor);opacity:.8}',
|
|
329
|
-
'.dbf-modal-version-value{font-size:12px;line-height:17px;font-weight:600;font-variant-numeric:tabular-nums}',
|
|
330
|
-
'.dbf-modal-arrow{color:var(--dsw-alias-label-tertiary)}',
|
|
331
|
-
'.dbf-btn-primary{padding:4px 12px;border:0;border-radius:8px;background:var(--dsw-alias-label-primary,CanvasText);color:var(--dsw-alias-bg-base,Canvas);font:inherit;font-size:12px;font-weight:600;line-height:18px;cursor:pointer}',
|
|
332
|
-
'.dbf-btn-primary:hover{filter:brightness(1.06)}',
|
|
333
|
-
'.dbf-modal-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:12px}',
|
|
334
293
|
'.dbf-fold-head{cursor:pointer;user-select:none}',
|
|
335
294
|
'.dbf-fold-arrow{display:inline-block;width:10px;margin-right:3px;color:var(--dsw-alias-label-tertiary);font-size:9px}',
|
|
336
295
|
'.dbf-fold-head:hover .dbf-row-title{color:var(--dsw-alias-label-primary)}',
|
|
@@ -372,6 +331,9 @@ window.__ModuleLoader__.load({
|
|
|
372
331
|
'.dbf-foot{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:7px 11px;background:transparent;border-top:.5px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:14px}',
|
|
373
332
|
'.dbf-foot-path{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
374
333
|
'.dbf-foot-time{margin-left:auto;white-space:nowrap}',
|
|
334
|
+
'.dbf-foot-time.is-refreshing{color:var(--dsw-alias-state-warn-primary)}',
|
|
335
|
+
'.dbf-foot-time.is-done{color:var(--dsw-alias-state-success-primary)}',
|
|
336
|
+
'.dbf-foot-time.is-failed{color:var(--dsw-alias-state-error-primary)}',
|
|
375
337
|
'.dbf-bubble{position:absolute;top:calc(100% + 8px);left:4px;display:flex;align-items:baseline;gap:6px;padding:5px 12px;border-radius:10px;box-shadow:0 8px 22px rgba(0,0,0,calc(.18 * var(--dbf-shadow,1)));font-size:13px;line-height:19px;white-space:nowrap;pointer-events:none;animation:dbf-flash 3s ease forwards}',
|
|
376
338
|
'.dbf-bubble-label{color:var(--dsw-alias-label-secondary)}',
|
|
377
339
|
'.dbf-bubble-amount{font-weight:600;font-variant-numeric:tabular-nums}',
|
|
@@ -382,7 +344,7 @@ window.__ModuleLoader__.load({
|
|
|
382
344
|
'@keyframes dbf-flash-up{0%{opacity:0;transform:translateY(4px)}12%{opacity:1;transform:translateY(0)}84%{opacity:1;transform:translateY(0)}100%{opacity:0;transform:translateY(2px)}}',
|
|
383
345
|
'.dbf-setting{padding:8px 11px;border-bottom:.5px solid var(--dsw-alias-border-l1)}',
|
|
384
346
|
'.dbf-setting:last-child{border-bottom:0}',
|
|
385
|
-
'.dbf-track{position:relative;height:26px;margin:2px 7px 0;cursor:pointer;touch-action:none;border-radius:6px}',
|
|
347
|
+
'.dbf-track{position:relative;height:26px;margin:2px 7px 0;cursor:pointer;touch-action:none;border-radius:6px;user-select:none;-webkit-user-select:none;-webkit-user-drag:none}',
|
|
386
348
|
'.dbf-track:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:2px}',
|
|
387
349
|
'.dbf-track-rail{position:absolute;left:0;right:0;top:50%;height:4px;transform:translateY(-50%);border-radius:2px;background:var(--dsw-alias-border-l1)}',
|
|
388
350
|
'.dbf-track-fill{position:absolute;left:0;top:50%;height:4px;transform:translateY(-50%);border-radius:2px;background:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
@@ -572,14 +534,16 @@ window.__ModuleLoader__.load({
|
|
|
572
534
|
// The shell can re-mount the overlay when a run starts or stops. Component
|
|
573
535
|
// state is lost then, so the live position lives at module scope too: a
|
|
574
536
|
// remount must not snap the widget back to the stored default.
|
|
575
|
-
const shared = { frame: null, dir: 'up', dock: ''
|
|
537
|
+
const shared = { frame: null, dir: 'up', dock: '' };
|
|
576
538
|
|
|
577
539
|
/** The floating pill and its expanded card. */
|
|
578
540
|
function BalanceFloat(props) {
|
|
579
541
|
const t = props.t;
|
|
542
|
+
const openPluginPage = typeof props.openPluginPage === 'function' ? props.openPluginPage : () => {};
|
|
580
543
|
const [snapshot, setSnapshot] = useState(null);
|
|
581
544
|
const [failure, setFailure] = useState('');
|
|
582
545
|
const [busy, setBusy] = useState(false);
|
|
546
|
+
const [refreshState, setRefreshState] = useState('idle');
|
|
583
547
|
const [open, setOpen] = useState(false);
|
|
584
548
|
const [settingsOpen, setSettingsOpen] = useState(false);
|
|
585
549
|
const [leaving, setLeaving] = useState(false);
|
|
@@ -591,6 +555,7 @@ window.__ModuleLoader__.load({
|
|
|
591
555
|
const dragRef = useRef(null);
|
|
592
556
|
const positionRef = useRef(null);
|
|
593
557
|
const aliveRef = useRef(true);
|
|
558
|
+
const refreshDoneTimer = useRef(null);
|
|
594
559
|
// The per-turn bubble: one flash per settled turn, then it fades itself out.
|
|
595
560
|
const [flash, setFlash] = useState(false);
|
|
596
561
|
// The bubble sits under the pill; near the bottom edge it flips above.
|
|
@@ -601,34 +566,9 @@ window.__ModuleLoader__.load({
|
|
|
601
566
|
const [selectedDay, setSelectedDay] = useState(null);
|
|
602
567
|
// Token buckets are collapsed until asked for.
|
|
603
568
|
const [tokensOpen, setTokensOpen] = useState(false);
|
|
604
|
-
//
|
|
605
|
-
const [update, setUpdate] = useState(
|
|
606
|
-
const [updateOpen, setUpdateOpen] = useState(shared.updateOpen);
|
|
569
|
+
// Auto check: null | {phase, latest, current, hasUpdate}
|
|
570
|
+
const [update, setUpdate] = useState(null);
|
|
607
571
|
const updateCheckedAt = useRef(0);
|
|
608
|
-
const [copied, setCopied] = useState(false);
|
|
609
|
-
const modalRef = useRef(null);
|
|
610
|
-
|
|
611
|
-
// A plain fixed <div> stays inside the shell's stacking context, so the
|
|
612
|
-
// page header kept painting above the mask. showModal() moves the element
|
|
613
|
-
// into the browser top layer, where the ::backdrop always covers the
|
|
614
|
-
// whole viewport — no z-index can beat it.
|
|
615
|
-
useEffect(() => {
|
|
616
|
-
if (update === null || !updateOpen) return undefined;
|
|
617
|
-
const root = document.documentElement;
|
|
618
|
-
root.classList.add('dbf-modal-open');
|
|
619
|
-
return () => root.classList.remove('dbf-modal-open');
|
|
620
|
-
}, [update, updateOpen]);
|
|
621
|
-
|
|
622
|
-
useEffect(() => {
|
|
623
|
-
const element = modalRef.current;
|
|
624
|
-
if (element === null || typeof element.showModal !== 'function' || element.open) return;
|
|
625
|
-
try {
|
|
626
|
-
element.showModal();
|
|
627
|
-
} catch {
|
|
628
|
-
// already open or detached — nothing to do
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
|
|
632
572
|
const flashAtRef = useRef(null);
|
|
633
573
|
const flashTimerRef = useRef(null);
|
|
634
574
|
const leaveTimerRef = useRef(null);
|
|
@@ -642,11 +582,6 @@ window.__ModuleLoader__.load({
|
|
|
642
582
|
useEffect(() => {
|
|
643
583
|
shared.dock = dock;
|
|
644
584
|
}, [dock]);
|
|
645
|
-
useEffect(() => {
|
|
646
|
-
shared.update = update;
|
|
647
|
-
shared.updateOpen = updateOpen;
|
|
648
|
-
}, [update, updateOpen]);
|
|
649
|
-
|
|
650
585
|
// Forces a re-render so the countdown text follows the clock.
|
|
651
586
|
const [, setTick] = useState(0);
|
|
652
587
|
// Host/browser clock offset, so the switch countdown follows the Host.
|
|
@@ -755,46 +690,44 @@ window.__ModuleLoader__.load({
|
|
|
755
690
|
}, 200);
|
|
756
691
|
}, []);
|
|
757
692
|
|
|
758
|
-
/**
|
|
759
|
-
const checkUpdate = useCallback(async (
|
|
760
|
-
|
|
761
|
-
if (showModal) setUpdateOpen(true);
|
|
762
|
-
setUpdate({ phase: 'checking', latest: '', current: '', hasUpdate: false, error: '' });
|
|
763
|
-
updateCheckedAt.current = Date.now();
|
|
693
|
+
/** Silent check so the footer can flag a newer release before you click. */
|
|
694
|
+
const checkUpdate = useCallback(async () => {
|
|
695
|
+
updateCheckedAt.current = Date.now()
|
|
764
696
|
try {
|
|
765
|
-
const response = await fetch(ROUTE_UPDATE
|
|
697
|
+
const response = await fetch(ROUTE_UPDATE, { headers: { accept: 'application/json' }, cache: 'no-store' });
|
|
766
698
|
const body = await response.json();
|
|
767
699
|
if (!aliveRef.current) return;
|
|
768
|
-
if (!response.ok || body?.ok === false)
|
|
769
|
-
setUpdate({ phase: 'error', latest: '', current: body?.current ?? '', hasUpdate: false, error: body?.error ?? 'HTTP ' + response.status });
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
700
|
+
if (!response.ok || body?.ok === false) return;
|
|
772
701
|
setUpdate({
|
|
773
702
|
phase: 'done',
|
|
774
703
|
latest: typeof body.latest === 'string' ? body.latest : '',
|
|
775
704
|
current: typeof body.current === 'string' ? body.current : '',
|
|
776
705
|
hasUpdate: body.hasUpdate === true,
|
|
777
|
-
error: '',
|
|
778
706
|
});
|
|
779
|
-
} catch
|
|
780
|
-
|
|
781
|
-
setUpdate({ phase: 'error', latest: '', current: '', hasUpdate: false, error: error instanceof Error ? error.message : String(error) });
|
|
707
|
+
} catch {
|
|
708
|
+
// Silent: a failed check must not disturb the widget.
|
|
782
709
|
}
|
|
783
710
|
}, []);
|
|
784
711
|
|
|
785
|
-
// Check quietly when the card opens so the hover text already knows, and
|
|
786
|
-
// re-check whenever the local version changed since the last answer.
|
|
787
712
|
useEffect(() => {
|
|
788
713
|
if (!open) return;
|
|
789
|
-
if (
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if (answered && Date.now() - updateCheckedAt.current < 5 * 60 * 1000) return;
|
|
793
|
-
void checkUpdate(false);
|
|
794
|
-
}, [open, update, snapshot?.version, checkUpdate]);
|
|
714
|
+
if (Date.now() - updateCheckedAt.current < 5 * 60 * 1000) return;
|
|
715
|
+
void checkUpdate();
|
|
716
|
+
}, [open, snapshot?.version, checkUpdate]);
|
|
795
717
|
|
|
796
718
|
const load = useCallback(async (manual) => {
|
|
797
|
-
|
|
719
|
+
// Hold the spinner for at least one full turn: a local read returns in
|
|
720
|
+
// a few milliseconds, which otherwise looks like nothing happened.
|
|
721
|
+
const startedAt = Date.now();
|
|
722
|
+
let ok = true;
|
|
723
|
+
if (manual) {
|
|
724
|
+
if (refreshDoneTimer.current !== null) {
|
|
725
|
+
window.clearTimeout(refreshDoneTimer.current);
|
|
726
|
+
refreshDoneTimer.current = null;
|
|
727
|
+
}
|
|
728
|
+
setBusy(true);
|
|
729
|
+
setRefreshState('refreshing');
|
|
730
|
+
}
|
|
798
731
|
try {
|
|
799
732
|
const response = await fetch(ROUTE, { headers: { accept: 'application/json' }, cache: 'no-store' });
|
|
800
733
|
const body = await response.json();
|
|
@@ -815,10 +748,22 @@ window.__ModuleLoader__.load({
|
|
|
815
748
|
}, 3100);
|
|
816
749
|
}
|
|
817
750
|
} catch (error) {
|
|
751
|
+
ok = false;
|
|
818
752
|
if (!aliveRef.current) return;
|
|
819
753
|
setFailure(error instanceof Error && error.message !== '' ? error.message : String(error));
|
|
820
754
|
} finally {
|
|
821
|
-
if (manual && aliveRef.current)
|
|
755
|
+
if (manual && aliveRef.current) {
|
|
756
|
+
const elapsed = Date.now() - startedAt;
|
|
757
|
+
if (elapsed < 700) await new Promise((resolve) => window.setTimeout(resolve, 700 - elapsed));
|
|
758
|
+
if (aliveRef.current) {
|
|
759
|
+
setBusy(false);
|
|
760
|
+
setRefreshState(ok ? 'done' : 'failed');
|
|
761
|
+
refreshDoneTimer.current = window.setTimeout(() => {
|
|
762
|
+
refreshDoneTimer.current = null;
|
|
763
|
+
if (aliveRef.current) setRefreshState('idle');
|
|
764
|
+
}, 2000);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
822
767
|
}
|
|
823
768
|
}, []);
|
|
824
769
|
|
|
@@ -885,6 +830,9 @@ window.__ModuleLoader__.load({
|
|
|
885
830
|
*/
|
|
886
831
|
const startSlider = useCallback(
|
|
887
832
|
(key, max, event) => {
|
|
833
|
+
// Text selection is already disabled in CSS (`user-select:none`), so
|
|
834
|
+
// the default action stays intact: a plain click still focuses the
|
|
835
|
+
// track and only a real pointer move starts a drag.
|
|
888
836
|
const track = event.currentTarget;
|
|
889
837
|
const rect = track.getBoundingClientRect();
|
|
890
838
|
const apply = (clientX) => {
|
|
@@ -892,7 +840,23 @@ window.__ModuleLoader__.load({
|
|
|
892
840
|
changeAppearance(key, clamp(Math.round((ratio * max) / 5) * 5, 0, max));
|
|
893
841
|
};
|
|
894
842
|
apply(event.clientX);
|
|
895
|
-
|
|
843
|
+
|
|
844
|
+
let released = false;
|
|
845
|
+
const releaseCapture = () => {
|
|
846
|
+
if (released) return;
|
|
847
|
+
released = true;
|
|
848
|
+
try {
|
|
849
|
+
if (track.hasPointerCapture?.(event.pointerId) === true) track.releasePointerCapture(event.pointerId);
|
|
850
|
+
} catch {
|
|
851
|
+
// The capture is already gone; nothing to release.
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
try {
|
|
855
|
+
track.setPointerCapture?.(event.pointerId);
|
|
856
|
+
} catch {
|
|
857
|
+
// A pointer that already ended cannot be captured.
|
|
858
|
+
}
|
|
859
|
+
|
|
896
860
|
const onMove = (moveEvent) => {
|
|
897
861
|
if (moveEvent.pointerId !== event.pointerId) return;
|
|
898
862
|
moveEvent.stopImmediatePropagation();
|
|
@@ -908,16 +872,23 @@ window.__ModuleLoader__.load({
|
|
|
908
872
|
window.removeEventListener('pointerup', onEnd, true);
|
|
909
873
|
window.removeEventListener('pointercancel', onEnd, true);
|
|
910
874
|
window.removeEventListener('touchmove', onTouch, true);
|
|
875
|
+
track.removeEventListener('lostpointercapture', onLost);
|
|
876
|
+
releaseCapture();
|
|
911
877
|
};
|
|
912
878
|
const onEnd = (endEvent) => {
|
|
913
879
|
if (endEvent.pointerId !== event.pointerId) return;
|
|
914
880
|
endEvent.stopImmediatePropagation();
|
|
915
881
|
detach();
|
|
916
882
|
};
|
|
883
|
+
// Losing capture (element re-render, browser gesture) must end the
|
|
884
|
+
// drag too, or the window listeners outlive the gesture.
|
|
885
|
+
const onLost = () => detach();
|
|
886
|
+
|
|
917
887
|
window.addEventListener('pointermove', onMove, true);
|
|
918
888
|
window.addEventListener('pointerup', onEnd, true);
|
|
919
889
|
window.addEventListener('pointercancel', onEnd, true);
|
|
920
890
|
window.addEventListener('touchmove', onTouch, { capture: true, passive: false });
|
|
891
|
+
track.addEventListener('lostpointercapture', onLost);
|
|
921
892
|
},
|
|
922
893
|
[changeAppearance],
|
|
923
894
|
);
|
|
@@ -1060,18 +1031,6 @@ window.__ModuleLoader__.load({
|
|
|
1060
1031
|
|
|
1061
1032
|
const dot = h('span', { className: 'dbf-dot ' + (peakActive ? 'is-peak' : 'is-valley'), 'aria-hidden': true });
|
|
1062
1033
|
|
|
1063
|
-
// The version control's hover text reports the last check's outcome.
|
|
1064
|
-
const updateTitle =
|
|
1065
|
-
update === null
|
|
1066
|
-
? t('update.check')
|
|
1067
|
-
: update.phase === 'checking'
|
|
1068
|
-
? t('update.checking')
|
|
1069
|
-
: update.phase === 'error'
|
|
1070
|
-
? t('update.failed') + ' · ' + t('update.retry')
|
|
1071
|
-
: update.hasUpdate
|
|
1072
|
-
? t('update.found', { latest: update.latest, current: update.current }) + ' · ' + t('update.now')
|
|
1073
|
-
: t('update.latest', { current: update.current || snapshot?.version || '—' });
|
|
1074
|
-
|
|
1075
1034
|
// Docked to a side edge: a square ball that only shows the balance.
|
|
1076
1035
|
const docked = appearance.dockBall && dock !== '';
|
|
1077
1036
|
const balanceText = '¥' + money(snapshot?.balance);
|
|
@@ -1483,14 +1442,29 @@ window.__ModuleLoader__.load({
|
|
|
1483
1442
|
'button',
|
|
1484
1443
|
{
|
|
1485
1444
|
type: 'button',
|
|
1486
|
-
className: 'dbf-version' + (update !== null && update.
|
|
1487
|
-
title:
|
|
1488
|
-
|
|
1445
|
+
className: 'dbf-version' + (update !== null && update.hasUpdate ? ' has-update' : ''),
|
|
1446
|
+
title:
|
|
1447
|
+
update !== null && update.hasUpdate
|
|
1448
|
+
? t('version.new', { latest: update.latest })
|
|
1449
|
+
: t('version.open'),
|
|
1450
|
+
onClick: () => openPluginPage(),
|
|
1489
1451
|
},
|
|
1490
1452
|
t('version') + ' v' + (snapshot?.version || '—'),
|
|
1491
|
-
h('span', { className: 'dbf-version-glyph', 'aria-hidden': true }, '
|
|
1453
|
+
h('span', { className: 'dbf-version-glyph', 'aria-hidden': true }, '↗'),
|
|
1454
|
+
),
|
|
1455
|
+
h(
|
|
1456
|
+
'span',
|
|
1457
|
+
{ className: 'dbf-foot-time' + (refreshState !== 'idle' ? ' is-' + refreshState : '') },
|
|
1458
|
+
refreshState === 'refreshing'
|
|
1459
|
+
? t('refreshing')
|
|
1460
|
+
: refreshState === 'done'
|
|
1461
|
+
? t('refreshDone')
|
|
1462
|
+
: refreshState === 'failed'
|
|
1463
|
+
? t('refreshFailedShort')
|
|
1464
|
+
: typeof snapshot?.source?.updatedAt === 'string'
|
|
1465
|
+
? t('updated', { time: clock(Date.parse(snapshot.source.updatedAt)) })
|
|
1466
|
+
: '',
|
|
1492
1467
|
),
|
|
1493
|
-
h('span', { className: 'dbf-foot-time' }, typeof snapshot?.source?.updatedAt === 'string' ? t('updated', { time: clock(Date.parse(snapshot.source.updatedAt)) }) : ''),
|
|
1494
1468
|
);
|
|
1495
1469
|
|
|
1496
1470
|
const body = [];
|
|
@@ -1637,106 +1611,6 @@ window.__ModuleLoader__.load({
|
|
|
1637
1611
|
)
|
|
1638
1612
|
: null;
|
|
1639
1613
|
|
|
1640
|
-
const updateModal =
|
|
1641
|
-
update === null || !updateOpen
|
|
1642
|
-
? null
|
|
1643
|
-
: h(
|
|
1644
|
-
DIALOG_OK ? 'dialog' : 'div',
|
|
1645
|
-
{
|
|
1646
|
-
ref: DIALOG_OK ? modalRef : undefined,
|
|
1647
|
-
className: DIALOG_OK ? 'dbf-dialog' : 'dbf-modal',
|
|
1648
|
-
role: 'dialog',
|
|
1649
|
-
'aria-modal': 'true',
|
|
1650
|
-
'aria-label': t('update.title'),
|
|
1651
|
-
onCancel: (event) => {
|
|
1652
|
-
event.preventDefault();
|
|
1653
|
-
setUpdateOpen(false);
|
|
1654
|
-
},
|
|
1655
|
-
onClick: (event) => {
|
|
1656
|
-
if (event.target === event.currentTarget) setUpdateOpen(false);
|
|
1657
|
-
},
|
|
1658
|
-
},
|
|
1659
|
-
h(
|
|
1660
|
-
'div',
|
|
1661
|
-
{ className: 'dbf-modal-card dbf-surface' },
|
|
1662
|
-
h(
|
|
1663
|
-
'div',
|
|
1664
|
-
{ className: 'dbf-modal-head' },
|
|
1665
|
-
h('span', { className: 'dbf-modal-icon', 'aria-hidden': true }, '⟳'),
|
|
1666
|
-
h('span', { className: 'dbf-modal-title' }, t('update.title')),
|
|
1667
|
-
),
|
|
1668
|
-
update.phase === 'checking'
|
|
1669
|
-
? h('div', { className: 'dbf-modal-body' }, t('update.checking'))
|
|
1670
|
-
: update.phase === 'error'
|
|
1671
|
-
? h(
|
|
1672
|
-
'div',
|
|
1673
|
-
null,
|
|
1674
|
-
h('div', { className: 'dbf-modal-body dbf-error' }, t('update.failed') + ': ' + update.error),
|
|
1675
|
-
h(
|
|
1676
|
-
'div',
|
|
1677
|
-
{ className: 'dbf-modal-actions' },
|
|
1678
|
-
h(
|
|
1679
|
-
'button',
|
|
1680
|
-
{ type: 'button', className: 'dbf-btn-primary', onClick: () => void checkUpdate(true) },
|
|
1681
|
-
t('update.retry'),
|
|
1682
|
-
),
|
|
1683
|
-
),
|
|
1684
|
-
)
|
|
1685
|
-
: update.hasUpdate
|
|
1686
|
-
? h(
|
|
1687
|
-
'div',
|
|
1688
|
-
null,
|
|
1689
|
-
h('div', { className: 'dbf-modal-body' }, t('update.found', { latest: update.latest, current: update.current })),
|
|
1690
|
-
h(
|
|
1691
|
-
'div',
|
|
1692
|
-
{ className: 'dbf-modal-versions' },
|
|
1693
|
-
h(
|
|
1694
|
-
'span',
|
|
1695
|
-
{ className: 'dbf-modal-version' },
|
|
1696
|
-
h('span', { className: 'dbf-modal-version-label' }, t('update.label.current')),
|
|
1697
|
-
h('span', { className: 'dbf-modal-version-value' }, 'v' + (update.current || '—')),
|
|
1698
|
-
),
|
|
1699
|
-
h('span', { className: 'dbf-modal-arrow', 'aria-hidden': true }, '→'),
|
|
1700
|
-
h(
|
|
1701
|
-
'span',
|
|
1702
|
-
{ className: 'dbf-modal-version is-new' },
|
|
1703
|
-
h('span', { className: 'dbf-modal-version-label' }, t('update.label.latest')),
|
|
1704
|
-
h('span', { className: 'dbf-modal-version-value' }, 'v' + update.latest),
|
|
1705
|
-
),
|
|
1706
|
-
),
|
|
1707
|
-
h('div', { className: 'dbf-modal-note' }, t('update.installHint')),
|
|
1708
|
-
h(
|
|
1709
|
-
'div',
|
|
1710
|
-
{ className: 'dbf-modal-actions' },
|
|
1711
|
-
h(
|
|
1712
|
-
'button',
|
|
1713
|
-
{ type: 'button', className: 'dbf-textbtn', onClick: () => setUpdateOpen(false) },
|
|
1714
|
-
t('update.later'),
|
|
1715
|
-
),
|
|
1716
|
-
h(
|
|
1717
|
-
'button',
|
|
1718
|
-
{ type: 'button', className: 'dbf-btn-primary', onClick: () => void copyInstallSpec() },
|
|
1719
|
-
copied ? t('update.copied') : t('update.copy'),
|
|
1720
|
-
),
|
|
1721
|
-
),
|
|
1722
|
-
)
|
|
1723
|
-
: h(
|
|
1724
|
-
'div',
|
|
1725
|
-
null,
|
|
1726
|
-
h('div', { className: 'dbf-modal-body' }, t('update.latest', { current: update.current || snapshot?.version || '—' })),
|
|
1727
|
-
h(
|
|
1728
|
-
'div',
|
|
1729
|
-
{ className: 'dbf-modal-actions' },
|
|
1730
|
-
h(
|
|
1731
|
-
'button',
|
|
1732
|
-
{ type: 'button', className: 'dbf-btn-primary', onClick: () => setUpdateOpen(false) },
|
|
1733
|
-
t('settings.done'),
|
|
1734
|
-
),
|
|
1735
|
-
),
|
|
1736
|
-
),
|
|
1737
|
-
),
|
|
1738
|
-
);
|
|
1739
|
-
|
|
1740
1614
|
const surface = settingsOpen ? settingsPanel : open ? card : pill;
|
|
1741
1615
|
|
|
1742
1616
|
const tree = h(
|
|
@@ -1745,9 +1619,6 @@ window.__ModuleLoader__.load({
|
|
|
1745
1619
|
h('style', { key: 'css' }, STYLE),
|
|
1746
1620
|
surface,
|
|
1747
1621
|
bubble,
|
|
1748
|
-
createPortal !== null && typeof document !== 'undefined' && updateModal !== null
|
|
1749
|
-
? createPortal(updateModal, document.body)
|
|
1750
|
-
: updateModal,
|
|
1751
1622
|
);
|
|
1752
1623
|
return createPortal !== null && typeof document !== 'undefined' ? createPortal(tree, document.body) : tree;
|
|
1753
1624
|
}
|
|
@@ -1759,9 +1630,19 @@ window.__ModuleLoader__.load({
|
|
|
1759
1630
|
function apply(ctx) {
|
|
1760
1631
|
ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'balance-float: dictionaries');
|
|
1761
1632
|
const t = ctx.locale.bind(NS);
|
|
1633
|
+
// The plugin page ships its own update button, so the footer version just
|
|
1634
|
+
// jumps there instead of running a second update flow.
|
|
1635
|
+
const openPluginPage = () => {
|
|
1636
|
+
try {
|
|
1637
|
+
const navigation = ctx.get('pluginNavigation');
|
|
1638
|
+
navigation?.openBundle?.(PACKAGE_NAME);
|
|
1639
|
+
} catch {
|
|
1640
|
+
// plugin manager UI not installed: nothing to open
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1762
1643
|
ctx.slots.inject('shell.overlay', () =>
|
|
1763
1644
|
ctx.slots.register({ name: 'shell.overlay', id: 'balance-float', order: 60, locale: NS }, (props) =>
|
|
1764
|
-
h(MemoBalanceFloat, { ...props, t }),
|
|
1645
|
+
h(MemoBalanceFloat, { ...props, t, openPluginPage }),
|
|
1765
1646
|
),
|
|
1766
1647
|
);
|
|
1767
1648
|
}
|
package/index.js
CHANGED
|
@@ -57,39 +57,32 @@ function isNewer(a, b) {
|
|
|
57
57
|
return false
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/** Cached check against the published
|
|
60
|
+
/** Cached check against the version published on npm. */
|
|
61
61
|
const UPDATE_TTL_MS = 5 * 60 * 1000
|
|
62
|
-
// Only the
|
|
63
|
-
// locally bumped version
|
|
62
|
+
// Only the published version is cached; `current` is re-read every call so a
|
|
63
|
+
// locally bumped version is compared against the fresh one.
|
|
64
64
|
let updateCache = { at: 0, latest: null }
|
|
65
65
|
|
|
66
66
|
async function checkUpdate({ fresh = false } = {}) {
|
|
67
67
|
const now = Date.now()
|
|
68
68
|
const current = packageVersion()
|
|
69
|
-
// A manual click must never be answered from the cache: the published version
|
|
70
|
-
// can change right after a silent check.
|
|
71
69
|
if (!fresh && updateCache.latest !== null && now - updateCache.at < UPDATE_TTL_MS) {
|
|
72
70
|
return { ok: true, current, latest: updateCache.latest, hasUpdate: isNewer(updateCache.latest, current) }
|
|
73
71
|
}
|
|
74
72
|
const controller = new AbortController()
|
|
75
73
|
const timer = setTimeout(() => controller.abort(), 10000)
|
|
76
74
|
try {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
{
|
|
82
|
-
signal: controller.signal,
|
|
83
|
-
headers: { accept: 'application/vnd.github.raw', 'user-agent': 'dsh-balance-float' },
|
|
84
|
-
},
|
|
85
|
-
)
|
|
75
|
+
const response = await fetch('https://registry.npmjs.org/@lls-a1/dsh-balance-float/latest', {
|
|
76
|
+
signal: controller.signal,
|
|
77
|
+
headers: { accept: 'application/json', 'user-agent': 'dsh-balance-float' },
|
|
78
|
+
})
|
|
86
79
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
87
80
|
const pkg = JSON.parse(await response.text())
|
|
88
81
|
const latest = typeof pkg?.version === 'string' ? pkg.version : ''
|
|
89
82
|
if (latest !== '') updateCache = { at: now, latest }
|
|
90
83
|
return { ok: true, current, latest, hasUpdate: latest !== '' && isNewer(latest, current) }
|
|
91
84
|
} catch (error) {
|
|
92
|
-
// Do not cache failures: the next
|
|
85
|
+
// Do not cache failures: the next check retries.
|
|
93
86
|
return { ok: false, current, latest: '', hasUpdate: false, error: error instanceof Error ? error.message : String(error) }
|
|
94
87
|
} finally {
|
|
95
88
|
clearTimeout(timer)
|