@mdbase-dev/ui 0.2.7 → 0.2.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.
@@ -1,6 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from "react";
3
+ import { ConfirmDialog } from "./ConfirmDialog.js";
3
4
  import { i18n, useLocaleRevision } from "./i18n.js";
5
+ const ACTIVE_POLL_MS = 3_000;
6
+ const WAITING_POLL_MS = 10_000;
7
+ const DAY_MS = 24 * 60 * 60 * 1_000;
8
+ const BLOCKED_STORAGE_PREFIX = "mdbase:mode-blocked:";
4
9
  function read(value) {
5
10
  if (!value || typeof value !== "object") return null;
6
11
  const v = value;
@@ -9,9 +14,181 @@ function read(value) {
9
14
  if (!v.change || typeof v.change !== "object") return null;
10
15
  const c = v.change;
11
16
  if (c.target_mode !== "private" && c.target_mode !== "cloud_copy" || typeof c.phase !== "string") return null;
17
+ if (c.source_mode !== undefined && c.source_mode !== "private" && c.source_mode !== "cloud_copy") return null;
12
18
  }
13
19
  return v;
14
20
  }
21
+ function errorCodeOf(error) {
22
+ if (!error || typeof error !== "object") return undefined;
23
+ const e = error;
24
+ if (e.details && typeof e.details === "object" && "code" in e.details && typeof e.details.code === "string") {
25
+ return e.details.code;
26
+ }
27
+ if (typeof e.reason === "string") return e.reason;
28
+ if (typeof e.code === "string" && e.code !== "http_error") return e.code;
29
+ return undefined;
30
+ }
31
+ function classifyModeError(error) {
32
+ const code = errorCodeOf(error);
33
+ if (code === "not_confirmed") return "not_confirmed";
34
+ if (code === "keyed_owner_required") return "keyed_owner_required";
35
+ if (code === "mode_abandoned") return "mode_abandoned";
36
+ if (code === "mode_switch_unavailable") return "mode_switch_unavailable";
37
+ if (code === "mode_already_published") return "mode_already_published";
38
+ if (code === "mode_rekey_observed") return "mode_rekey_observed";
39
+ const text = error instanceof Error ? error.message : typeof error === "string" ? error : "";
40
+ if (/\bnot_confirmed\b|not confirmed on this computer/i.test(text)) return "not_confirmed";
41
+ if (/\bkeyed_owner_required\b|owner device holding this collection['’]s trusted key/i.test(text)) return "keyed_owner_required";
42
+ if (/\bmode_abandoned\b/i.test(text)) return "mode_abandoned";
43
+ if (/\bmode_switch_unavailable\b|switching this collection isn['’]t available yet/i.test(text)) return "mode_switch_unavailable";
44
+ if (/\bmode_already_published\b/i.test(text)) return "mode_already_published";
45
+ if (/\bmode_rekey_observed\b/i.test(text)) return "mode_rekey_observed";
46
+ return "unknown";
47
+ }
48
+ function readBlocked(collectionId) {
49
+ try {
50
+ const raw = globalThis.sessionStorage?.getItem(`${BLOCKED_STORAGE_PREFIX}${collectionId}`);
51
+ if (!raw) return null;
52
+ const parsed = JSON.parse(raw);
53
+ if (!parsed || !Array.isArray(parsed.devices)) return null;
54
+ const devices = parsed.devices.filter(v => typeof v === "string" && v.length > 0);
55
+ if (!devices.length) return null;
56
+ const names = blockedNames(parsed.names, devices);
57
+ return {
58
+ ...(typeof parsed.requestId === "string" ? {
59
+ requestId: parsed.requestId
60
+ } : {}),
61
+ devices,
62
+ ...(names ? {
63
+ names
64
+ } : {})
65
+ };
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+ /** Display names the daemon passed through from the server, limited to the blocked IDs. */
71
+ function blockedNames(value, devices) {
72
+ if (!value || typeof value !== "object") return undefined;
73
+ const names = Object.fromEntries(devices.flatMap(id => {
74
+ const name = value[id];
75
+ return typeof name === "string" && name.trim() ? [[id, name.trim().slice(0, 80)]] : [];
76
+ }));
77
+ return Object.keys(names).length ? names : undefined;
78
+ }
79
+ function writeBlocked(collectionId, entry) {
80
+ try {
81
+ const key = `${BLOCKED_STORAGE_PREFIX}${collectionId}`;
82
+ if (!entry || !entry.devices.length) globalThis.sessionStorage?.removeItem(key);else globalThis.sessionStorage?.setItem(key, JSON.stringify(entry));
83
+ } catch {
84
+ // Storage may be unavailable in restricted contexts; in-memory state still works.
85
+ }
86
+ }
87
+ function blockedStillApplies(entry, status) {
88
+ if (!entry || !entry.devices.length || !status) return false;
89
+ if (status.current_mode === "private" && !status.change) return false;
90
+ if (!status.change) return entry.requestId === undefined;
91
+ if (status.change.phase !== "waiting_for_device" && status.change.phase !== "waiting_for_devices") return false;
92
+ if (entry.requestId && status.change.request_id && entry.requestId !== status.change.request_id) return false;
93
+ return true;
94
+ }
95
+ function shortDeviceId(id) {
96
+ return id.length > 8 ? id.slice(0, 8) : id;
97
+ }
98
+ function activeLocale() {
99
+ return i18n.locale === "pt" ? "pt-BR" : i18n.locale === "zh" ? "zh-CN" : i18n.locale;
100
+ }
101
+ function formatFinishTime(retryAt, nowMs) {
102
+ const targetMs = Date.parse(retryAt);
103
+ if (!Number.isFinite(targetMs)) return null;
104
+ const remainingMs = targetMs - nowMs;
105
+ if (remainingMs <= 0) {
106
+ return i18n._(
107
+ /** i18n */
108
+ {
109
+ id: "FzKDwV",
110
+ message: "Older app connections have expired. Finishing automatically\u2026",
111
+ context: "Collection storage mode"
112
+ });
113
+ }
114
+ const date = new Date(targetMs);
115
+ const locale = activeLocale();
116
+ if (remainingMs < DAY_MS) {
117
+ const minutes = Math.max(1, Math.ceil(remainingMs / 60_000));
118
+ const time = new Intl.DateTimeFormat(locale, {
119
+ timeStyle: "short"
120
+ }).format(date);
121
+ return i18n._(
122
+ /** i18n */
123
+ {
124
+ id: "U0ICYY",
125
+ message: "Expected to finish in about {minutes, plural, one {# minute} other {# minutes}} (around {time}).",
126
+ context: "Collection storage mode",
127
+ values: {
128
+ minutes: minutes,
129
+ time: time
130
+ }
131
+ });
132
+ }
133
+ const dateTime = new Intl.DateTimeFormat(locale, {
134
+ dateStyle: "short",
135
+ timeStyle: "short"
136
+ }).format(date);
137
+ return i18n._(
138
+ /** i18n */
139
+ {
140
+ id: "ssf0iE",
141
+ message: "Expected to finish around {dateTime}.",
142
+ context: "Collection storage mode",
143
+ values: {
144
+ dateTime: dateTime
145
+ }
146
+ });
147
+ }
148
+ function errorText(kind) {
149
+ switch (kind) {
150
+ case "keyed_owner_required":
151
+ return i18n._(
152
+ /** i18n */
153
+ {
154
+ id: "Htl4Ay",
155
+ message: "Use a device that holds this collection\u2019s key to switch its storage mode.",
156
+ context: "Collection storage mode"
157
+ });
158
+ case "mode_abandoned":
159
+ return i18n._(
160
+ /** i18n */
161
+ {
162
+ id: "wQHQ4B",
163
+ message: "This collection can\u2019t switch modes until the stopped switch to Private finishes recovering. Revoke the device that started it so your other owner devices replace the collection key.",
164
+ context: "Collection storage mode"
165
+ });
166
+ case "mode_already_published":
167
+ return i18n._(
168
+ /** i18n */
169
+ {
170
+ id: "Y0lvt7",
171
+ message: "This switch has already started publishing and can no longer be cancelled.",
172
+ context: "Collection storage mode"
173
+ });
174
+ case "mode_rekey_observed":
175
+ return i18n._(
176
+ /** i18n */
177
+ {
178
+ id: "Dsfk12",
179
+ message: "Another device has already replaced the collection key. Refresh status to see the latest state.",
180
+ context: "Collection storage mode"
181
+ });
182
+ case "unknown":
183
+ return i18n._(
184
+ /** i18n */
185
+ {
186
+ id: "Iu3ZPh",
187
+ message: "We couldn\u2019t confirm progress. Refresh, then retry. An interrupted switch may already have started.",
188
+ context: "Collection storage mode"
189
+ });
190
+ }
191
+ }
15
192
  /** Owner controls only. Visibility follows actual executor registration, not a
16
193
  * mode flag. Browser intent cannot produce native key/source consent. */
17
194
  export function CollectionModeControl({
@@ -19,54 +196,148 @@ export function CollectionModeControl({
19
196
  load,
20
197
  change,
21
198
  cancel,
22
- native = false
199
+ abandon,
200
+ native = false,
201
+ deviceNames,
202
+ initialStatus,
203
+ onModeChange,
204
+ onStatusChange
23
205
  }) {
24
206
  useLocaleRevision();
25
- const [status, setStatus] = useState(null);
207
+ const [status, setStatus] = useState(() => read(initialStatus));
26
208
  const [busy, setBusy] = useState(false);
27
- const [failure, setFailure] = useState(false);
28
- const [step, setStep] = useState(null);
209
+ const [errorKind, setErrorKind] = useState(null);
210
+ const [loadFailed, setLoadFailed] = useState(false);
211
+ const [blocked, setBlocked] = useState(() => readBlocked(collectionId));
212
+ const [stepRetryAt, setStepRetryAt] = useState(undefined);
213
+ const [abandonOpen, setAbandonOpen] = useState(false);
214
+ const [abandonError, setAbandonError] = useState(null);
215
+ const [now, setNow] = useState(() => Date.now());
29
216
  const intent = useRef(null);
30
217
  const generation = useRef(0);
218
+ const settledMode = useRef(read(initialStatus)?.change ? null : read(initialStatus)?.current_mode ?? null);
219
+ const hadPending = useRef(Boolean(read(initialStatus)?.change && read(initialStatus)?.change?.phase !== "abandoned"));
220
+ const abandonTrigger = useRef(null);
31
221
  // Callback identity changes with parent renders; it must not restart I/O.
32
222
  const callbacks = useRef({
33
223
  load,
34
224
  change,
35
- cancel
225
+ cancel,
226
+ abandon,
227
+ onModeChange,
228
+ onStatusChange
36
229
  });
37
230
  callbacks.current = {
38
231
  load,
39
232
  change,
40
- cancel
233
+ cancel,
234
+ abandon,
235
+ onModeChange,
236
+ onStatusChange
41
237
  };
238
+ function applyStatus(next, incomingBlocked) {
239
+ setStatus(next);
240
+ setNow(Date.now());
241
+ callbacks.current.onStatusChange?.(next);
242
+ if (!next) return;
243
+ const isAbandoned = next.change?.phase === "abandoned";
244
+ const isPending = Boolean(next.change && !isAbandoned);
245
+ if (!isPending) intent.current = null;
246
+ if (next.change?.phase !== "waiting_for_token_expiry") setStepRetryAt(undefined);
247
+ if (incomingBlocked !== undefined) {
248
+ setBlocked(incomingBlocked);
249
+ writeBlocked(collectionId, incomingBlocked);
250
+ } else {
251
+ setBlocked(current => {
252
+ if (blockedStillApplies(current, next)) return current;
253
+ writeBlocked(collectionId, null);
254
+ return null;
255
+ });
256
+ }
257
+ const previousMode = settledMode.current;
258
+ const wasPending = hadPending.current;
259
+ hadPending.current = isPending;
260
+ if (!isPending) {
261
+ settledMode.current = next.current_mode;
262
+ if (wasPending && (!next.change || isAbandoned) || previousMode !== null && previousMode !== next.current_mode) {
263
+ callbacks.current.onModeChange?.(next.current_mode);
264
+ }
265
+ }
266
+ }
42
267
  useEffect(() => {
43
268
  const active = ++generation.current;
44
- setStatus(null);
45
- setStep(null);
46
- setFailure(false);
269
+ const seeded = read(initialStatus);
270
+ setStatus(seeded);
271
+ setErrorKind(null);
272
+ setLoadFailed(false);
47
273
  setBusy(false);
274
+ setStepRetryAt(undefined);
275
+ setAbandonOpen(false);
276
+ setAbandonError(null);
277
+ setNow(Date.now());
278
+ const storedBlocked = readBlocked(collectionId);
279
+ setBlocked(seeded && !blockedStillApplies(storedBlocked, seeded) ? null : storedBlocked);
48
280
  intent.current = null;
281
+ settledMode.current = seeded && !seeded.change ? seeded.current_mode : null;
282
+ hadPending.current = Boolean(seeded?.change && seeded.change.phase !== "abandoned");
49
283
  void callbacks.current.load().then(value => {
50
- if (generation.current === active) setStatus(read(value));
51
- }).catch(() => {});
284
+ if (generation.current !== active) return;
285
+ setLoadFailed(false);
286
+ applyStatus(read(value));
287
+ }).catch(error => {
288
+ if (generation.current !== active || !seeded) return;
289
+ const kind = classifyModeError(error);
290
+ if (kind === "mode_switch_unavailable") applyStatus(null, null);else if (kind !== "not_confirmed") {
291
+ setLoadFailed(true);
292
+ setErrorKind(kind);
293
+ }
294
+ });
52
295
  return () => {
53
296
  ++generation.current;
54
297
  };
55
298
  }, [collectionId]);
299
+ const pendingPhase = status?.change && !["complete", "cancelled", "abandoned"].includes(status.change.phase) ? status.change.phase : null;
300
+ useEffect(() => {
301
+ if (!pendingPhase) return;
302
+ const active = generation.current;
303
+ const intervalMs = pendingPhase === "finishing" || pendingPhase === "publishing_policy" ? ACTIVE_POLL_MS : WAITING_POLL_MS;
304
+ let cancelled = false;
305
+ let timer;
306
+ const schedule = () => {
307
+ timer = setTimeout(async () => {
308
+ if (cancelled || active !== generation.current) return;
309
+ try {
310
+ const next = read(await callbacks.current.load());
311
+ if (cancelled || active !== generation.current) return;
312
+ if (next) applyStatus(next);
313
+ } catch {
314
+ // Background poll stays quiet and retries on the next interval.
315
+ }
316
+ if (!cancelled && active === generation.current) schedule();
317
+ }, intervalMs);
318
+ };
319
+ schedule();
320
+ return () => {
321
+ cancelled = true;
322
+ if (timer !== undefined) clearTimeout(timer);
323
+ };
324
+ }, [collectionId, pendingPhase]);
56
325
  async function refresh() {
57
326
  const active = generation.current;
58
327
  setBusy(true);
59
- setFailure(false);
328
+ setErrorKind(null);
329
+ setLoadFailed(false);
60
330
  try {
61
331
  const next = read(await callbacks.current.load());
62
332
  if (active !== generation.current) return;
63
- setStatus(next);
64
- if (next && !next.change) {
65
- setStep(null);
66
- intent.current = null;
333
+ applyStatus(next);
334
+ } catch (error) {
335
+ if (active !== generation.current) return;
336
+ const kind = classifyModeError(error);
337
+ if (kind === "mode_switch_unavailable") applyStatus(null, null);else if (kind !== "not_confirmed") {
338
+ setLoadFailed(true);
339
+ setErrorKind(kind);
67
340
  }
68
- } catch {
69
- if (active === generation.current) setFailure(true);
70
341
  } finally {
71
342
  if (active === generation.current) setBusy(false);
72
343
  }
@@ -78,17 +349,50 @@ export function CollectionModeControl({
78
349
  id: crypto.randomUUID()
79
350
  };
80
351
  setBusy(true);
81
- setFailure(false);
352
+ setErrorKind(null);
353
+ setLoadFailed(false);
354
+ setBlocked(null);
355
+ writeBlocked(collectionId, null);
356
+ setStepRetryAt(undefined);
82
357
  try {
83
358
  const result = await callbacks.current.change(target, intent.current.id);
84
359
  if (active !== generation.current) return;
360
+ const step = result && typeof result === "object" ? result : null;
361
+ const devices = step?.phase === "waiting_for_devices" && Array.isArray(step.devices) ? step.devices.filter(v => typeof v === "string" && v.length > 0) : [];
362
+ const retry = typeof step?.retry_at === "string" ? step.retry_at : undefined;
85
363
  const next = read(await callbacks.current.load());
86
364
  if (active !== generation.current) return;
87
- setStatus(next);
88
- if (next && !next.change) intent.current = null;
89
- setStep(result && typeof result === "object" ? result : null);
90
- } catch {
91
- if (active === generation.current) setFailure(true);
365
+ const names = blockedNames(step?.device_names, devices);
366
+ const nextBlocked = devices.length > 0 ? {
367
+ ...(next?.change?.request_id ? {
368
+ requestId: next.change.request_id
369
+ } : {}),
370
+ devices,
371
+ ...(names ? {
372
+ names
373
+ } : {})
374
+ } : null;
375
+ setStepRetryAt(retry);
376
+ applyStatus(next, nextBlocked);
377
+ } catch (error) {
378
+ if (active !== generation.current) return;
379
+ const kind = classifyModeError(error);
380
+ if (kind === "not_confirmed") {
381
+ if (!status?.change) intent.current = null;
382
+ setErrorKind(null);
383
+ } else if (kind === "mode_switch_unavailable") {
384
+ applyStatus(null, null);
385
+ } else if (kind === "mode_abandoned") {
386
+ setErrorKind("mode_abandoned");
387
+ void callbacks.current.load().then(value => {
388
+ if (active === generation.current) {
389
+ const next = read(value);
390
+ if (next) applyStatus(next, null);
391
+ }
392
+ }).catch(() => undefined);
393
+ } else {
394
+ setErrorKind(kind);
395
+ }
92
396
  } finally {
93
397
  if (active === generation.current) setBusy(false);
94
398
  }
@@ -97,16 +401,65 @@ export function CollectionModeControl({
97
401
  if (!status?.change?.request_id || !callbacks.current.cancel) return;
98
402
  const active = generation.current;
99
403
  setBusy(true);
100
- setFailure(false);
404
+ setErrorKind(null);
101
405
  try {
102
406
  await callbacks.current.cancel(status.change.target_mode, status.change.request_id);
103
407
  const next = read(await callbacks.current.load());
104
408
  if (active !== generation.current) return;
105
- setStatus(next);
106
- setStep(null);
409
+ setStepRetryAt(undefined);
410
+ intent.current = null;
411
+ applyStatus(next, null);
412
+ } catch (error) {
413
+ if (active !== generation.current) return;
414
+ const kind = classifyModeError(error);
415
+ if (kind === "mode_switch_unavailable") {
416
+ applyStatus(null, null);
417
+ } else if (kind === "mode_already_published") {
418
+ setErrorKind("mode_already_published");
419
+ void callbacks.current.load().then(value => {
420
+ if (active === generation.current) {
421
+ const next = read(value);
422
+ if (next) applyStatus(next);
423
+ }
424
+ }).catch(() => undefined);
425
+ } else if (kind !== "not_confirmed") {
426
+ setErrorKind(kind);
427
+ }
428
+ } finally {
429
+ if (active === generation.current) setBusy(false);
430
+ }
431
+ }
432
+ async function abandonPending() {
433
+ if (!status?.change?.request_id || !callbacks.current.abandon) return;
434
+ const active = generation.current;
435
+ setBusy(true);
436
+ setErrorKind(null);
437
+ setAbandonError(null);
438
+ try {
439
+ await callbacks.current.abandon(status.change.request_id);
440
+ const next = read(await callbacks.current.load());
441
+ if (active !== generation.current) return;
442
+ setStepRetryAt(undefined);
107
443
  intent.current = null;
108
- } catch {
109
- if (active === generation.current) setFailure(true);
444
+ setAbandonOpen(false);
445
+ applyStatus(next, null);
446
+ } catch (error) {
447
+ if (active !== generation.current) return;
448
+ const kind = classifyModeError(error);
449
+ if (kind === "mode_switch_unavailable") {
450
+ setAbandonOpen(false);
451
+ applyStatus(null, null);
452
+ } else if (kind === "mode_rekey_observed") {
453
+ setAbandonError("mode_rekey_observed");
454
+ void callbacks.current.load().then(value => {
455
+ if (active === generation.current) {
456
+ const next = read(value);
457
+ if (next) applyStatus(next);
458
+ }
459
+ }).catch(() => undefined);
460
+ } else if (kind !== "not_confirmed") {
461
+ setAbandonError(kind);
462
+ }
110
463
  } finally {
111
464
  if (active === generation.current) setBusy(false);
112
465
  }
@@ -116,9 +469,108 @@ export function CollectionModeControl({
116
469
  // leaving Private first would consume their switch, so nothing is offered.
117
470
  const abandoned = status.change?.phase === "abandoned";
118
471
  const pending = abandoned ? null : status.change;
119
- const target = pending?.target_mode ?? (status.current_mode === "private" ? "cloud_copy" : "private");
120
- const blocked = step?.phase === "waiting_for_devices" && Array.isArray(step.devices) ? step.devices.filter(v => typeof v === "string") : [];
121
- const retryAt = typeof step?.retry_at === "string" ? step.retry_at : typeof pending?.retry_at === "string" ? pending.retry_at : undefined;
472
+ // GET /mode flips current_mode to cloud_copy at Private->Cloud /prepare before
473
+ // services are keyed, so keep showing the source mode while a switch is pending.
474
+ const displayedMode = pending ? pending.source_mode ?? (pending.target_mode === "private" ? "cloud_copy" : "private") : status.current_mode;
475
+ const target = pending?.target_mode ?? (displayedMode === "private" ? "cloud_copy" : "private");
476
+ const blockedIds = blocked?.devices ?? [];
477
+ const retryAt = pending?.phase === "waiting_for_token_expiry" ? pending.retry_at ?? stepRetryAt : undefined;
478
+ const finishLine = retryAt ? formatFinishTime(retryAt, now) : null;
479
+ const needsNativeConsent = Boolean(pending && native && (pending.phase === "waiting_for_device" || pending.phase === "waiting_for_devices"));
480
+ const canCancel = Boolean(cancel && pending?.request_id && ["waiting_for_device", "waiting_for_devices", "waiting_for_token_expiry"].includes(pending.phase));
481
+ const canAbandon = Boolean(abandon && pending?.request_id && pending.target_mode === "private" && pending.phase === "finishing");
482
+ const canRefresh = Boolean(loadFailed || errorKind === "unknown" || errorKind === "mode_rekey_observed");
483
+ const showPrimaryAction = !abandoned && (!pending || needsNativeConsent);
484
+ const hasActions = showPrimaryAction || canCancel || canAbandon || canRefresh;
485
+ let progressLine = null;
486
+ if (pending) {
487
+ const toPrivate = pending.target_mode === "private";
488
+ if (blockedIds.length > 0 || pending.phase === "waiting_for_devices") {
489
+ progressLine = toPrivate ? i18n._(
490
+ /** i18n */
491
+ {
492
+ id: "swnigJ",
493
+ message: "Switching to Private \u2014 waiting for older devices to update.",
494
+ context: "Collection storage mode"
495
+ }) : i18n._(
496
+ /** i18n */
497
+ {
498
+ id: "wdSJ6X",
499
+ message: "Switching to Cloud copy \u2014 waiting for older devices to update.",
500
+ context: "Collection storage mode"
501
+ });
502
+ } else if (pending.phase === "waiting_for_token_expiry") {
503
+ progressLine = toPrivate ? i18n._(
504
+ /** i18n */
505
+ {
506
+ id: "1O7ZGT",
507
+ message: "Switching to Private \u2014 waiting for older app connections to expire.",
508
+ context: "Collection storage mode"
509
+ }) : i18n._(
510
+ /** i18n */
511
+ {
512
+ id: "K1IjiM",
513
+ message: "Switching to Cloud copy \u2014 waiting for older app connections to expire.",
514
+ context: "Collection storage mode"
515
+ });
516
+ } else if (pending.phase === "waiting_for_device") {
517
+ progressLine = native ? toPrivate ? i18n._(
518
+ /** i18n */
519
+ {
520
+ id: "lmAFgn",
521
+ message: "Switching to Private \u2014 confirm on this computer to start.",
522
+ context: "Collection storage mode"
523
+ }) : i18n._(
524
+ /** i18n */
525
+ {
526
+ id: "bEqOgt",
527
+ message: "Switching to Cloud copy \u2014 confirm on this computer to start.",
528
+ context: "Collection storage mode"
529
+ }) : toPrivate ? i18n._(
530
+ /** i18n */
531
+ {
532
+ id: "GwUW04",
533
+ message: "Switching to Private \u2014 open mdbase connect on one of your computers to confirm.",
534
+ context: "Collection storage mode"
535
+ }) : i18n._(
536
+ /** i18n */
537
+ {
538
+ id: "ceB3qW",
539
+ message: "Switching to Cloud copy \u2014 open mdbase connect on one of your computers to confirm.",
540
+ context: "Collection storage mode"
541
+ });
542
+ } else if (pending.phase === "publishing_policy") {
543
+ progressLine = toPrivate ? i18n._(
544
+ /** i18n */
545
+ {
546
+ id: "sKv_Rk",
547
+ message: "Switching to Private \u2014 publishing the new storage mode.",
548
+ context: "Collection storage mode"
549
+ }) : i18n._(
550
+ /** i18n */
551
+ {
552
+ id: "iE1bsk",
553
+ message: "Switching to Cloud copy \u2014 publishing the new storage mode.",
554
+ context: "Collection storage mode"
555
+ });
556
+ } else if (toPrivate) {
557
+ progressLine = i18n._(
558
+ /** i18n */
559
+ {
560
+ id: "_trB1U",
561
+ message: "Switching to Private \u2014 finishing and updating your collection key. This finishes automatically while an owner device is online.",
562
+ context: "Collection storage mode"
563
+ });
564
+ } else {
565
+ progressLine = i18n._(
566
+ /** i18n */
567
+ {
568
+ id: "Fwd5Xq",
569
+ message: "Switching to Cloud copy \u2014 finishing. This usually takes a few seconds.",
570
+ context: "Collection storage mode"
571
+ });
572
+ }
573
+ }
122
574
  return _jsxs("section", {
123
575
  className: "mdbase-collection-mode",
124
576
  "aria-label": i18n._(
@@ -137,32 +589,48 @@ export function CollectionModeControl({
137
589
  message: "Storage mode",
138
590
  context: "Collection storage mode"
139
591
  })
140
- }), _jsx("p", {
141
- children: status.current_mode === "private" ? i18n._(
592
+ }), _jsxs("p", {
593
+ className: "mdbase-collection-mode-current",
594
+ children: [_jsx("strong", {
595
+ children: displayedMode === "private" ? i18n._(
596
+ /** i18n */
597
+ {
598
+ id: "EIDHh1",
599
+ message: "Private",
600
+ context: "Collection storage mode"
601
+ }) : i18n._(
602
+ /** i18n */
603
+ {
604
+ id: "oKQdii",
605
+ message: "Cloud copy",
606
+ context: "Collection storage mode"
607
+ })
608
+ }), " — ", displayedMode === "private" ? i18n._(
142
609
  /** i18n */
143
610
  {
144
- id: "EIDHh1",
145
- message: "Private",
611
+ id: "b05lwE",
612
+ message: "Only your devices can read it. Web apps work only while one of your devices is online.",
146
613
  context: "Collection storage mode"
147
614
  }) : i18n._(
148
615
  /** i18n */
149
616
  {
150
- id: "oKQdii",
151
- message: "Cloud copy",
617
+ id: "ymlBTn",
618
+ message: "mdbase keeps a copy it can read, so web apps and agents work while your devices are off.",
152
619
  context: "Collection storage mode"
153
- })
154
- }), _jsx("p", {
620
+ })]
621
+ }), !abandoned && !pending && _jsx("p", {
622
+ className: "mdbase-collection-mode-note",
155
623
  children: target === "private" ? i18n._(
156
624
  /** i18n */
157
625
  {
158
- id: "FHz4md",
159
- message: "Only your devices can read new content after the switch finishes. mdbase may still be able to read older content.",
626
+ id: "r5-LWH",
627
+ message: "Switching to Private: only your devices can read new content; mdbase may still be able to read older content. Apps connected to this collection will need to be reconnected afterwards.",
160
628
  context: "Collection storage mode"
161
629
  }) : i18n._(
162
630
  /** i18n */
163
631
  {
164
- id: "bcDV8T",
165
- message: "mdbase will be able to read the collection, including its existing history, and serve it while your devices are off.",
632
+ id: "y9KarW",
633
+ message: "Switching to Cloud copy: mdbase will be able to read the collection, including its history. Apps connected to this collection will need to be reconnected afterwards.",
166
634
  context: "Collection storage mode"
167
635
  })
168
636
  }), abandoned && _jsx("p", {
@@ -170,79 +638,59 @@ export function CollectionModeControl({
170
638
  children: i18n._(
171
639
  /** i18n */
172
640
  {
173
- id: "2lgBZ8",
174
- message: "The switch to Private didn\u2019t finish. Revoke the device that started it. Your other owner devices will then replace the collection key.",
641
+ id: "JMpqzG",
642
+ message: "The switch to Private was stopped. This collection is Private on its previous key. Revoke the device that started the switch so your other owner devices replace the key automatically.",
175
643
  context: "Collection storage mode"
176
644
  })
177
- }), pending && _jsx("p", {
178
- role: "status",
179
- children: blocked.length > 0 ? i18n._(
180
- /** i18n */
181
- {
182
- id: "3w1RWH",
183
- message: "Waiting for devices to update.",
184
- context: "Collection storage mode"
185
- }) : pending.phase === "waiting_for_token_expiry" ? i18n._(
186
- /** i18n */
187
- {
188
- id: "lx5IrT",
189
- message: "Waiting for older device connections to expire. Cloud copy remains on until the switch finishes.",
190
- context: "Collection storage mode"
191
- }) : pending.phase === "waiting_for_device" ? i18n._(
192
- /** i18n */
193
- {
194
- id: "3FYCb9",
195
- message: "Open mdbase connect on one of the owner's devices to finish the switch.",
196
- context: "Collection storage mode"
197
- }) : i18n._(
198
- /** i18n */
199
- {
200
- id: "13DGsZ",
201
- message: "Finishing the switch. Keep the owner device connected.",
202
- context: "Collection storage mode"
203
- })
204
- }), retryAt && Number.isFinite(Date.parse(retryAt)) && _jsx("p", {
205
- children: _jsx("time", {
206
- dateTime: retryAt,
207
- children: i18n._(
208
- /** i18n */
209
- {
210
- id: "ejJPcY",
211
- message: "Continue after {0}.",
212
- context: "Collection storage mode",
213
- values: {
214
- 0: new Date(retryAt).toLocaleString()
215
- }
645
+ }), progressLine && _jsxs("div", {
646
+ className: "mdbase-collection-mode-status",
647
+ children: [_jsx("p", {
648
+ role: "status",
649
+ children: progressLine
650
+ }), retryAt && finishLine && _jsx("p", {
651
+ className: "mdbase-collection-mode-note",
652
+ children: _jsx("time", {
653
+ dateTime: retryAt,
654
+ children: finishLine
216
655
  })
217
- })
218
- }), blocked.length > 0 && _jsxs("div", {
656
+ })]
657
+ }), blockedIds.length > 0 && _jsxs("div", {
658
+ className: "mdbase-collection-mode-blocked",
219
659
  role: "status",
220
660
  children: [_jsx("p", {
661
+ className: "mdbase-collection-mode-note",
221
662
  children: i18n._(
222
663
  /** i18n */
223
664
  {
224
- id: "YQ2gus",
225
- message: "Update or revoke these devices before continuing:",
665
+ id: "qesgsv",
666
+ message: "Update mdbase on these devices or remove them before trying again:",
226
667
  context: "Collection storage mode"
227
668
  })
228
669
  }), _jsx("ul", {
229
- children: blocked.map(id => _jsx("li", {
230
- children: _jsx("code", {
231
- children: id
232
- })
233
- }, id))
670
+ children: blockedIds.map(id => {
671
+ const name = blocked?.names?.[id] ?? deviceNames?.[id];
672
+ const shortId = shortDeviceId(id);
673
+ return _jsx("li", {
674
+ title: id,
675
+ children: name ?? i18n._(
676
+ /** i18n */
677
+ {
678
+ id: "1EK0iv",
679
+ message: "Device {shortId}",
680
+ context: "Collection storage mode",
681
+ values: {
682
+ shortId: shortId
683
+ }
684
+ })
685
+ }, id);
686
+ })
234
687
  })]
235
- }), failure && _jsx("p", {
688
+ }), errorKind && _jsx("p", {
236
689
  role: "alert",
237
- children: i18n._(
238
- /** i18n */
239
- {
240
- id: "Iu3ZPh",
241
- message: "We couldn\u2019t confirm progress. Refresh, then retry. An interrupted switch may already have started.",
242
- context: "Collection storage mode"
243
- })
244
- }), _jsxs("div", {
245
- children: [!abandoned && (!pending || native) && _jsx("button", {
690
+ children: errorText(errorKind)
691
+ }), hasActions && _jsxs("div", {
692
+ className: "mdbase-collection-mode-actions",
693
+ children: [showPrimaryAction && _jsx("button", {
246
694
  type: "button",
247
695
  className: "mdbase-button",
248
696
  disabled: busy,
@@ -253,7 +701,7 @@ export function CollectionModeControl({
253
701
  id: "3xE-Bk",
254
702
  message: "Working\u2026",
255
703
  context: "Collection storage mode"
256
- }) : pending ? i18n._(
704
+ }) : needsNativeConsent ? i18n._(
257
705
  /** i18n */
258
706
  {
259
707
  id: "JKLDUc",
@@ -272,7 +720,7 @@ export function CollectionModeControl({
272
720
  message: "Turn on Cloud copy",
273
721
  context: "Collection storage mode"
274
722
  })
275
- }), cancel && pending?.request_id && ["waiting_for_device", "waiting_for_token_expiry"].includes(pending.phase) && _jsx("button", {
723
+ }), canCancel && _jsx("button", {
276
724
  type: "button",
277
725
  className: "mdbase-button is-tertiary",
278
726
  disabled: busy,
@@ -284,7 +732,23 @@ export function CollectionModeControl({
284
732
  message: "Cancel switch",
285
733
  context: "Collection storage mode"
286
734
  })
287
- }), _jsx("button", {
735
+ }), canAbandon && _jsx("button", {
736
+ ref: abandonTrigger,
737
+ type: "button",
738
+ className: "mdbase-button is-tertiary is-danger",
739
+ disabled: busy,
740
+ onClick: () => {
741
+ setAbandonError(null);
742
+ setAbandonOpen(true);
743
+ },
744
+ children: i18n._(
745
+ /** i18n */
746
+ {
747
+ id: "rJbBs-",
748
+ message: "Stop this switch",
749
+ context: "Collection storage mode"
750
+ })
751
+ }), canRefresh && _jsx("button", {
288
752
  type: "button",
289
753
  className: "mdbase-button is-tertiary",
290
754
  disabled: busy,
@@ -297,6 +761,47 @@ export function CollectionModeControl({
297
761
  context: "Collection storage mode"
298
762
  })
299
763
  })]
764
+ }), canAbandon && _jsx(ConfirmDialog, {
765
+ open: abandonOpen,
766
+ returnFocusRef: abandonTrigger,
767
+ busy: busy,
768
+ title: i18n._(
769
+ /** i18n */
770
+ {
771
+ id: "Jhhs6y",
772
+ message: "Stop this switch to Private?",
773
+ context: "Collection storage mode"
774
+ }),
775
+ consequence: i18n._(
776
+ /** i18n */
777
+ {
778
+ id: "YDgBZJ",
779
+ message: "Use this only if the device that started the switch is lost and can\u2019t finish. The collection stays Private on its current key, and your other owner devices replace the key automatically once you revoke the lost device.",
780
+ context: "Collection storage mode"
781
+ }),
782
+ confirmLabel: i18n._(
783
+ /** i18n */
784
+ {
785
+ id: "rJbBs-",
786
+ message: "Stop this switch",
787
+ context: "Collection storage mode"
788
+ }),
789
+ pendingLabel: i18n._(
790
+ /** i18n */
791
+ {
792
+ id: "FSKDRq",
793
+ message: "Stopping\u2026",
794
+ context: "Collection storage mode"
795
+ }),
796
+ onClose: () => {
797
+ setAbandonError(null);
798
+ setAbandonOpen(false);
799
+ },
800
+ onConfirm: () => abandonPending(),
801
+ children: abandonError && _jsx("p", {
802
+ role: "alert",
803
+ children: errorText(abandonError)
804
+ })
300
805
  })]
301
806
  });
302
807
  }