@proef/common-ui 2.6.34 → 2.6.35

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/dist/esm/index.js CHANGED
@@ -52,6 +52,8 @@ import { default as default49 } from "./legacy/components/ui/MenuAcoes.js";
52
52
  import { default as default50 } from "./legacy/components/molecules/Modal/Modal.js";
53
53
  import { default as default51 } from "./legacy/components/molecules/MultiTagPicker/MultiTagPicker.js";
54
54
  import { default as default52 } from "./legacy/pages/NotFound/NotFound.js";
55
+ import { DEFAULT_OFFLINE_BOXES_LABELS, OfflineBoxes } from "./v1/components/feedback/OfflineBoxes/OfflineBoxes.js";
56
+ import { OfflineBoxesIcon } from "./v1/components/feedback/OfflineBoxes/OfflineBoxesIcon.js";
55
57
  import { default as default53 } from "./v1/components/layout/Page/Page.js";
56
58
  import { default as default54 } from "./v1/components/layout/PageHeader/PageHeader.js";
57
59
  import { default as default55 } from "./v1/components/tables/PaginatedTable/PaginatedTable.js";
@@ -107,7 +109,7 @@ import { ESTILO_AVATAR_PILHA, PessoaComFoto, PilhaAvatares } from "./legacy/comp
107
109
  import { ErroBridge, pedirAoNativo } from "./v1/capabilities/onepoint-rn/bridge.js";
108
110
  import { FilterChips } from "./v1/primitives/display/FilterChips/FilterChips.js";
109
111
  import { FontWeight } from "./legacy/constants/FontWeight.js";
110
- import { INBOX_SAVED_AT_HEADER, connectInbox, inboxSavedAt, inboxStatus, syncInbox } from "./v1/capabilities/onepoint-rn/connectInbox.js";
112
+ import { INBOX_SAVED_AT_HEADER, connectInbox, inboxSavedAt, inboxStatus, syncInbox, watchInbox } from "./v1/capabilities/onepoint-rn/connectInbox.js";
111
113
  import { InputData, InputHora } from "./legacy/components/atoms/InputData/InputData.js";
112
114
  import { Kpi } from "./v1/primitives/display/Kpi/Kpi.js";
113
115
  import { LazyLoader } from "./legacy/components/organisms/LazyLoader/LazyLoader.js";
@@ -137,6 +139,7 @@ import { useApi } from "./legacy/hooks/useApi.js";
137
139
  import { useBarraEstadoNaApp } from "./v1/capabilities/onepoint-rn/useBarraEstadoNaApp.js";
138
140
  import { useIsDark } from "./v1/capabilities/theme/useIsDark.js";
139
141
  import { useMenuLateralNaApp } from "./v1/capabilities/onepoint-rn/useMenuLateralNaApp.js";
142
+ import { useOfflineBoxes } from "./v1/capabilities/onepoint-rn/useOfflineBoxes.js";
140
143
  import { useOrientacaoNaApp } from "./v1/capabilities/onepoint-rn/useOrientacaoNaApp.js";
141
144
  export {
142
145
  default3 as Acronym,
@@ -190,6 +193,7 @@ export {
190
193
  DEFAULT_DAY_TIMELINE_LABELS,
191
194
  DEFAULT_DROPDOWN_MENU_LABELS,
192
195
  DEFAULT_LIST_FINDER_LABELS,
196
+ DEFAULT_OFFLINE_BOXES_LABELS,
193
197
  DEFAULT_STEPS_LABELS,
194
198
  DEFAULT_TABLE_LABELS,
195
199
  default19 as DataTable,
@@ -272,6 +276,8 @@ export {
272
276
  default52 as NotFoundPage,
273
277
  Notice,
274
278
  OUTBOX_SAVED_MESSAGE,
279
+ OfflineBoxes,
280
+ OfflineBoxesIcon,
275
281
  OutboxSavedError,
276
282
  PALETA,
277
283
  default53 as Page,
@@ -392,10 +398,12 @@ export {
392
398
  useDialogContainer,
393
399
  useIsDark,
394
400
  useMenuLateralNaApp,
401
+ useOfflineBoxes,
395
402
  useOrientacaoNaApp,
396
403
  useSocket,
397
404
  useTheme,
398
405
  useToast,
406
+ watchInbox,
399
407
  watchOutbox
400
408
  };
401
409
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -63,10 +63,31 @@ function countIn(event, field) {
63
63
  const count = Reflect.get(event, field);
64
64
  return typeof count === "number" ? count : 0;
65
65
  }
66
- function progressFor(event, storageId, inboxId) {
66
+ function eventFor(event, storageId) {
67
67
  if (typeof event !== "object" || event === null) return null;
68
- if (Reflect.get(event, "storageId") !== storageId || Reflect.get(event, "inboxId") !== inboxId) return null;
69
- return { total: countIn(event, "total"), ready: countIn(event, "ready"), failed: countIn(event, "failed") };
68
+ const inboxId = Reflect.get(event, "inboxId");
69
+ if (Reflect.get(event, "storageId") !== storageId || typeof inboxId !== "string") return null;
70
+ const finishedAt = Reflect.get(event, "finishedAt");
71
+ return {
72
+ inboxId,
73
+ total: countIn(event, "total"),
74
+ ready: countIn(event, "ready"),
75
+ failed: countIn(event, "failed"),
76
+ finishedAt: typeof finishedAt === "string" ? finishedAt : null
77
+ };
78
+ }
79
+ function progressFor(event, storageId, inboxId) {
80
+ const inboxEvent = eventFor(event, storageId);
81
+ if (!inboxEvent || inboxEvent.inboxId !== inboxId) return null;
82
+ return { total: inboxEvent.total, ready: inboxEvent.ready, failed: inboxEvent.failed };
83
+ }
84
+ function watchInbox(options, onEvent) {
85
+ const storageId = checkedStorageId(options.storageId, "watchInbox");
86
+ if (!dentroDaApp()) return () => void 0;
87
+ return onNativeEvent("inbox", (carga) => {
88
+ const inboxEvent = eventFor(carga, storageId);
89
+ if (inboxEvent) onEvent(inboxEvent);
90
+ });
70
91
  }
71
92
  async function syncInbox(api, options, onProgress) {
72
93
  const storageId = checkedStorageId(options.storageId, "syncInbox");
@@ -91,6 +112,7 @@ export {
91
112
  connectInbox,
92
113
  inboxSavedAt,
93
114
  inboxStatus,
94
- syncInbox
115
+ syncInbox,
116
+ watchInbox
95
117
  };
96
118
  //# sourceMappingURL=connectInbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectInbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectInbox.ts"],"sourcesContent":["import axios, { AxiosError } from 'axios'\r\nimport type { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoInbox = 'inbox.read' | 'inbox.state' | 'inbox.sync'\r\n\r\nexport type InboxTier = 'account' | 'device'\r\n\r\nexport type InboxEach = {\r\n id: string\r\n stamp?: string\r\n list?: string\r\n paths: string[]\r\n}\r\n\r\nexport type InboxBundle = {\r\n ids: string\r\n list: string\r\n id: string\r\n parts: Record<string, string>\r\n since?: { param: string; from: string }\r\n missing?: { param: string }\r\n}\r\n\r\nexport type InboxGet = { path: string; tier?: InboxTier } & ({ each?: InboxEach; bundle?: never } | { bundle: InboxBundle; each?: never })\r\n\r\nexport type InboxOptions = { storageId: string | undefined }\r\n\r\nexport type InboxConnectOptions = InboxOptions & { paused?: () => boolean }\r\n\r\nexport type InboxSyncOptions = InboxOptions & { inboxId: string; tier: InboxTier; gets: InboxGet[] }\r\n\r\nexport type InboxProgress = { total: number; ready: number; failed: number }\r\n\r\nexport type InboxStatus = InboxProgress & { finishedAt: string | null }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n inbox?: false\r\n }\r\n}\r\n\r\nexport const INBOX_SAVED_AT_HEADER = 'x-inbox-saved-at'\r\n\r\nconst INBOX_ID_FORMAT = /^[a-z0-9]+(-[a-z0-9]+)*$/\r\nconst BRIDGE_WAIT_MS = 30_000\r\nconst SYNC_WAIT_MS = 30 * 60_000\r\n\r\ntype InboxRead = { found: false } | { found: true; status: number; body: unknown; savedAt: string }\r\n\r\nfunction checkedInboxId(inboxId: string, caller: string): string {\r\n if (INBOX_ID_FORMAT.test(inboxId)) return inboxId\r\n throw new Error(`${caller}: inboxId \"${inboxId}\" is not valid; use lowercase letters, digits and hyphens, such as ajustes`)\r\n}\r\n\r\nconst pausedChecks = new WeakMap<AxiosInstance, () => boolean>()\r\n\r\nfunction isPaused(api: AxiosInstance): boolean {\r\n const paused = pausedChecks.get(api)\r\n return paused ? paused() : false\r\n}\r\n\r\nfunction answersFromInbox(error: unknown): error is AxiosError & { config: InternalAxiosRequestConfig } {\r\n if (!(error instanceof AxiosError) || !error.config || error.response || axios.isCancel(error)) return false\r\n const method = (error.config.method ?? 'get').toLowerCase()\r\n return method === 'get' && error.config.inbox !== false && dentroDaApp()\r\n}\r\n\r\nasync function storedAnswer(api: AxiosInstance, storageId: string, config: InternalAxiosRequestConfig): Promise<AxiosResponse | null> {\r\n const { address, path } = addressAndPath(api, config)\r\n let stored: InboxRead\r\n try {\r\n stored = await pedirAoNativo<InboxRead>('inbox.read', { storageId, address, path }, BRIDGE_WAIT_MS)\r\n } catch {\r\n return null\r\n }\r\n if (!stored.found) return null\r\n return {\r\n data: stored.body,\r\n status: stored.status,\r\n statusText: '',\r\n headers: { [INBOX_SAVED_AT_HEADER]: stored.savedAt },\r\n config,\r\n request: {},\r\n }\r\n}\r\n\r\nexport function connectInbox(api: AxiosInstance, options: InboxConnectOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectInbox')\r\n if (options.paused) pausedChecks.set(api, options.paused)\r\n api.interceptors.response.use(undefined, async (error: unknown) => {\r\n if (!answersFromInbox(error) || isPaused(api)) throw error\r\n const answer = await storedAnswer(api, storageId, error.config)\r\n if (!answer) throw error\r\n return answer\r\n })\r\n}\r\n\r\nexport function inboxSavedAt(response: AxiosResponse): string | null {\r\n const savedAt: unknown = response.headers[INBOX_SAVED_AT_HEADER]\r\n return typeof savedAt === 'string' ? savedAt : null\r\n}\r\n\r\nexport async function inboxStatus(options: InboxOptions & { inboxId: string }): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'inboxStatus')\r\n const inboxId = checkedInboxId(options.inboxId, 'inboxStatus')\r\n if (!dentroDaApp()) return null\r\n return pedirAoNativo<InboxStatus>('inbox.state', { storageId, inboxId }, BRIDGE_WAIT_MS)\r\n}\r\n\r\nfunction countIn(event: object, field: keyof InboxProgress): number {\r\n const count: unknown = Reflect.get(event, field)\r\n return typeof count === 'number' ? count : 0\r\n}\r\n\r\nfunction progressFor(event: unknown, storageId: string, inboxId: string): InboxProgress | null {\r\n if (typeof event !== 'object' || event === null) return null\r\n if (Reflect.get(event, 'storageId') !== storageId || Reflect.get(event, 'inboxId') !== inboxId) return null\r\n return { total: countIn(event, 'total'), ready: countIn(event, 'ready'), failed: countIn(event, 'failed') }\r\n}\r\n\r\nexport async function syncInbox(\r\n api: AxiosInstance,\r\n options: InboxSyncOptions,\r\n onProgress?: (progress: InboxProgress) => void,\r\n): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'syncInbox')\r\n const inboxId = checkedInboxId(options.inboxId, 'syncInbox')\r\n if (!dentroDaApp() || isPaused(api)) return null\r\n\r\n const gets = options.gets.map((get) => {\r\n const { address, path } = addressAndPath(api, { baseURL: api.defaults.baseURL, url: get.path })\r\n return { address, path, tier: get.tier ?? options.tier, each: get.each, bundle: get.bundle }\r\n })\r\n const stop = onNativeEvent('inbox', (carga) => {\r\n const progress = progressFor(carga, storageId, inboxId)\r\n if (progress && onProgress) onProgress(progress)\r\n })\r\n try {\r\n return await pedirAoNativo<InboxStatus>('inbox.sync', { storageId, inboxId, gets }, SYNC_WAIT_MS)\r\n } finally {\r\n stop()\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;AA6CO,MAAM,wBAAwB;AAErC,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,eAAe,KAAK;AAI1B,SAAS,eAAe,SAAiB,QAAwB;AAC/D,MAAI,gBAAgB,KAAK,OAAO,EAAG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c,SAAS,CAAC,UAAU;AAC7C,UAAM,WAAW,YAAY,OAAO,WAAW,OAAO;AACtD,QAAI,YAAY,WAAY,YAAW,QAAQ;AAAA,EACjD,CAAC;AACD,MAAI;AACF,WAAO,MAAM,cAA2B,cAAc,EAAE,WAAW,SAAS,KAAA,GAAQ,YAAY;AAAA,EAClG,UAAA;AACE,SAAA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"connectInbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectInbox.ts"],"sourcesContent":["import axios, { AxiosError } from 'axios'\r\nimport type { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoInbox = 'inbox.read' | 'inbox.state' | 'inbox.sync'\r\n\r\nexport type InboxTier = 'account' | 'device'\r\n\r\nexport type InboxEach = {\r\n id: string\r\n stamp?: string\r\n list?: string\r\n paths: string[]\r\n}\r\n\r\nexport type InboxBundle = {\r\n ids: string\r\n list: string\r\n id: string\r\n parts: Record<string, string>\r\n since?: { param: string; from: string }\r\n missing?: { param: string }\r\n}\r\n\r\nexport type InboxGet = { path: string; tier?: InboxTier } & ({ each?: InboxEach; bundle?: never } | { bundle: InboxBundle; each?: never })\r\n\r\nexport type InboxOptions = { storageId: string | undefined }\r\n\r\nexport type InboxConnectOptions = InboxOptions & { paused?: () => boolean }\r\n\r\nexport type InboxSyncOptions = InboxOptions & { inboxId: string; tier: InboxTier; gets: InboxGet[] }\r\n\r\nexport type InboxProgress = { total: number; ready: number; failed: number }\r\n\r\nexport type InboxStatus = InboxProgress & { finishedAt: string | null; saved?: string[] }\r\n\r\nexport type InboxEvent = InboxProgress & { inboxId: string; finishedAt: string | null }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n inbox?: false\r\n }\r\n}\r\n\r\nexport const INBOX_SAVED_AT_HEADER = 'x-inbox-saved-at'\r\n\r\nconst INBOX_ID_FORMAT = /^[a-z0-9]+(-[a-z0-9]+)*$/\r\nconst BRIDGE_WAIT_MS = 30_000\r\nconst SYNC_WAIT_MS = 30 * 60_000\r\n\r\ntype InboxRead = { found: false } | { found: true; status: number; body: unknown; savedAt: string }\r\n\r\nfunction checkedInboxId(inboxId: string, caller: string): string {\r\n if (INBOX_ID_FORMAT.test(inboxId)) return inboxId\r\n throw new Error(`${caller}: inboxId \"${inboxId}\" is not valid; use lowercase letters, digits and hyphens, such as ajustes`)\r\n}\r\n\r\nconst pausedChecks = new WeakMap<AxiosInstance, () => boolean>()\r\n\r\nfunction isPaused(api: AxiosInstance): boolean {\r\n const paused = pausedChecks.get(api)\r\n return paused ? paused() : false\r\n}\r\n\r\nfunction answersFromInbox(error: unknown): error is AxiosError & { config: InternalAxiosRequestConfig } {\r\n if (!(error instanceof AxiosError) || !error.config || error.response || axios.isCancel(error)) return false\r\n const method = (error.config.method ?? 'get').toLowerCase()\r\n return method === 'get' && error.config.inbox !== false && dentroDaApp()\r\n}\r\n\r\nasync function storedAnswer(api: AxiosInstance, storageId: string, config: InternalAxiosRequestConfig): Promise<AxiosResponse | null> {\r\n const { address, path } = addressAndPath(api, config)\r\n let stored: InboxRead\r\n try {\r\n stored = await pedirAoNativo<InboxRead>('inbox.read', { storageId, address, path }, BRIDGE_WAIT_MS)\r\n } catch {\r\n return null\r\n }\r\n if (!stored.found) return null\r\n return {\r\n data: stored.body,\r\n status: stored.status,\r\n statusText: '',\r\n headers: { [INBOX_SAVED_AT_HEADER]: stored.savedAt },\r\n config,\r\n request: {},\r\n }\r\n}\r\n\r\nexport function connectInbox(api: AxiosInstance, options: InboxConnectOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectInbox')\r\n if (options.paused) pausedChecks.set(api, options.paused)\r\n api.interceptors.response.use(undefined, async (error: unknown) => {\r\n if (!answersFromInbox(error) || isPaused(api)) throw error\r\n const answer = await storedAnswer(api, storageId, error.config)\r\n if (!answer) throw error\r\n return answer\r\n })\r\n}\r\n\r\nexport function inboxSavedAt(response: AxiosResponse): string | null {\r\n const savedAt: unknown = response.headers[INBOX_SAVED_AT_HEADER]\r\n return typeof savedAt === 'string' ? savedAt : null\r\n}\r\n\r\nexport async function inboxStatus(options: InboxOptions & { inboxId: string }): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'inboxStatus')\r\n const inboxId = checkedInboxId(options.inboxId, 'inboxStatus')\r\n if (!dentroDaApp()) return null\r\n return pedirAoNativo<InboxStatus>('inbox.state', { storageId, inboxId }, BRIDGE_WAIT_MS)\r\n}\r\n\r\nfunction countIn(event: object, field: keyof InboxProgress): number {\r\n const count: unknown = Reflect.get(event, field)\r\n return typeof count === 'number' ? count : 0\r\n}\r\n\r\nfunction eventFor(event: unknown, storageId: string): InboxEvent | null {\r\n if (typeof event !== 'object' || event === null) return null\r\n const inboxId: unknown = Reflect.get(event, 'inboxId')\r\n if (Reflect.get(event, 'storageId') !== storageId || typeof inboxId !== 'string') return null\r\n const finishedAt: unknown = Reflect.get(event, 'finishedAt')\r\n return {\r\n inboxId,\r\n total: countIn(event, 'total'),\r\n ready: countIn(event, 'ready'),\r\n failed: countIn(event, 'failed'),\r\n finishedAt: typeof finishedAt === 'string' ? finishedAt : null,\r\n }\r\n}\r\n\r\nfunction progressFor(event: unknown, storageId: string, inboxId: string): InboxProgress | null {\r\n const inboxEvent = eventFor(event, storageId)\r\n if (!inboxEvent || inboxEvent.inboxId !== inboxId) return null\r\n return { total: inboxEvent.total, ready: inboxEvent.ready, failed: inboxEvent.failed }\r\n}\r\n\r\nexport function watchInbox(options: InboxOptions, onEvent: (event: InboxEvent) => void): () => void {\r\n const storageId = checkedStorageId(options.storageId, 'watchInbox')\r\n if (!dentroDaApp()) return () => undefined\r\n return onNativeEvent('inbox', (carga) => {\r\n const inboxEvent = eventFor(carga, storageId)\r\n if (inboxEvent) onEvent(inboxEvent)\r\n })\r\n}\r\n\r\nexport async function syncInbox(\r\n api: AxiosInstance,\r\n options: InboxSyncOptions,\r\n onProgress?: (progress: InboxProgress) => void,\r\n): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'syncInbox')\r\n const inboxId = checkedInboxId(options.inboxId, 'syncInbox')\r\n if (!dentroDaApp() || isPaused(api)) return null\r\n\r\n const gets = options.gets.map((get) => {\r\n const { address, path } = addressAndPath(api, { baseURL: api.defaults.baseURL, url: get.path })\r\n return { address, path, tier: get.tier ?? options.tier, each: get.each, bundle: get.bundle }\r\n })\r\n const stop = onNativeEvent('inbox', (carga) => {\r\n const progress = progressFor(carga, storageId, inboxId)\r\n if (progress && onProgress) onProgress(progress)\r\n })\r\n try {\r\n return await pedirAoNativo<InboxStatus>('inbox.sync', { storageId, inboxId, gets }, SYNC_WAIT_MS)\r\n } finally {\r\n stop()\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;AA+CO,MAAM,wBAAwB;AAErC,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,eAAe,KAAK;AAI1B,SAAS,eAAe,SAAiB,QAAwB;AAC/D,MAAI,gBAAgB,KAAK,OAAO,EAAG,QAAO;AAC1C,QAAM,IAAI,MAAM,GAAG,MAAM,cAAc,OAAO,4EAA4E;AAC5H;AAEA,MAAM,mCAAmB,QAAA;AAEzB,SAAS,SAAS,KAA6B;AAC7C,QAAM,SAAS,aAAa,IAAI,GAAG;AACnC,SAAO,SAAS,WAAW;AAC7B;AAEA,SAAS,iBAAiB,OAA8E;AACtG,MAAI,EAAE,iBAAiB,eAAe,CAAC,MAAM,UAAU,MAAM,YAAY,MAAM,SAAS,KAAK,EAAG,QAAO;AACvG,QAAM,UAAU,MAAM,OAAO,UAAU,OAAO,YAAA;AAC9C,SAAO,WAAW,SAAS,MAAM,OAAO,UAAU,SAAS,YAAA;AAC7D;AAEA,eAAe,aAAa,KAAoB,WAAmB,QAAmE;AACpI,QAA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AM,MAAM,IAAI,QAAQ,QAAQ,MAAM,MAAM,IAAI,MAAM,QAAQ,IAAI,OAAA;AAAA,EACtF,CAAC;AACD,QAAM,OAAO,cAAc,SAAS,CAAC,UAAU;AAC7C,UAAM,WAAW,YAAY,OAAO,WAAW,OAAO;AACtD,QAAI,YAAY,WAAY,YAAW,QAAQ;AAAA,EACjD,CAAC;AACD,MAAI;AACF,WAAO,MAAM,cAA2B,cAAc,EAAE,WAAW,SAAS,KAAA,GAAQ,YAAY;AAAA,EAClG,UAAA;AACE,SAAA;AAAA,EACF;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"connectOutbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectOutbox.ts"],"sourcesContent":["import { AxiosError, AxiosHeaders } from 'axios'\r\nimport type { AxiosAdapter, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { ErroBridge, onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoOutbox = 'outbox.send' | 'outbox.watch'\r\n\r\nconst WRITE_METHODS = ['post', 'put', 'patch', 'delete']\r\nconst BRIDGE_WAIT_MS = 30_000\r\n\r\nexport const OUTBOX_SAVED_MESSAGE = 'Guardado no telemóvel. Será enviado quando a ligação voltar.'\r\n\r\nexport type OutboxOptions = { storageId: string | undefined }\r\n\r\nexport type OutboxRequestOptions = { expiresAt?: string | Date }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n outbox?: true | OutboxRequestOptions\r\n }\r\n}\r\n\r\ntype OutboxReply =\r\n | { outcome: 'delivered' | 'rejected'; status: number; body: unknown }\r\n | { outcome: 'saved'; id: string }\r\n\r\nexport class OutboxSavedError extends Error {\r\n readonly outboxActionId: string | null\r\n\r\n constructor(outboxActionId: string | null) {\r\n super(OUTBOX_SAVED_MESSAGE)\r\n this.name = 'OutboxSavedError'\r\n this.outboxActionId = outboxActionId\r\n }\r\n}\r\n\r\nexport function isOutboxSaved(error: unknown): error is OutboxSavedError {\r\n return error instanceof OutboxSavedError\r\n}\r\n\r\nfunction stringHeaders(config: InternalAxiosRequestConfig): Record<string, string> {\r\n const headers: Record<string, string> = {}\r\n for (const [name, value] of Object.entries(AxiosHeaders.from(config.headers).toJSON())) {\r\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') headers[name] = String(value)\r\n }\r\n return headers\r\n}\r\n\r\nasync function replyOf(carga: unknown): Promise<OutboxReply> {\r\n try {\r\n return await pedirAoNativo<OutboxReply>('outbox.send', carga, BRIDGE_WAIT_MS)\r\n } catch (error) {\r\n if (error instanceof ErroBridge && error.codigo === 'expirou') throw new OutboxSavedError(null)\r\n throw error\r\n }\r\n}\r\n\r\nfunction expiryOf(config: InternalAxiosRequestConfig): string | undefined {\r\n const expiresAt = config.outbox === true ? undefined : config.outbox?.expiresAt\r\n return expiresAt instanceof Date ? expiresAt.toISOString() : expiresAt\r\n}\r\n\r\nfunction outboxAdapter(api: AxiosInstance, storageId: string): AxiosAdapter {\r\n return async (config) => {\r\n const { address, path } = addressAndPath(api, config)\r\n const reply = await replyOf({\r\n storageId,\r\n address,\r\n method: config.method,\r\n path,\r\n headers: stringHeaders(config),\r\n body: config.data,\r\n expiresAt: expiryOf(config),\r\n })\r\n if (reply.outcome === 'saved') throw new OutboxSavedError(reply.id)\r\n\r\n const response: AxiosResponse = {\r\n data: reply.body,\r\n status: reply.status,\r\n statusText: '',\r\n headers: {},\r\n config,\r\n request: {},\r\n }\r\n const accepted = config.validateStatus ? config.validateStatus(reply.status) : reply.outcome === 'delivered'\r\n if (accepted) return response\r\n throw new AxiosError(\r\n `Request failed with status code ${reply.status}`,\r\n reply.status >= 500 ? AxiosError.ERR_BAD_RESPONSE : AxiosError.ERR_BAD_REQUEST,\r\n config,\r\n response.request,\r\n response,\r\n )\r\n }\r\n}\r\n\r\nfunction goesThroughOutbox(config: InternalAxiosRequestConfig): boolean {\r\n if (!config.outbox) return false\r\n const method = (config.method ?? 'get').toLowerCase()\r\n if (!WRITE_METHODS.includes(method)) {\r\n throw new Error(`connectOutbox: only writes go through the Outbox, and this ${method.toUpperCase()} is marked with outbox`)\r\n }\r\n const data: unknown = config.data\r\n if (data instanceof FormData || data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {\r\n throw new Error('connectOutbox: files do not go through the Outbox yet; send this write without outbox')\r\n }\r\n return dentroDaApp()\r\n}\r\n\r\nexport type OutboxState = 'pending' | 'sending' | 'delivered' | 'rejected' | 'expired' | 'deleted'\r\n\r\nexport type OutboxActionStatus = { id: string; state: OutboxState; createdAt?: string; reason?: string }\r\n\r\nexport type OutboxWatch = { actions: OutboxActionStatus[]; stop: () => void }\r\n\r\nconst WATCH_WAIT_MS = 10_000\r\n\r\nfunction statusFor(carga: unknown, storageId: string): OutboxActionStatus | null {\r\n if (typeof carga !== 'object' || carga === null) return null\r\n const { storageId: of, ...status } = carga as OutboxActionStatus & { storageId?: string }\r\n return of === storageId ? status : null\r\n}\r\n\r\nexport async function watchOutbox(options: OutboxOptions, onChange: (status: OutboxActionStatus) => void): Promise<OutboxWatch> {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n if (!dentroDaApp()) return { actions: [], stop: () => undefined }\r\n const stop = onNativeEvent('outbox', (carga) => {\r\n const status = statusFor(carga, storageId)\r\n if (status) onChange(status)\r\n })\r\n try {\r\n const actions = await pedirAoNativo<OutboxActionStatus[]>('outbox.watch', { storageId }, WATCH_WAIT_MS)\r\n return { actions, stop }\r\n } catch (error) {\r\n stop()\r\n throw error\r\n }\r\n}\r\n\r\nexport function connectOutbox(api: AxiosInstance, options: OutboxOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n const adapter = outboxAdapter(api, storageId)\r\n api.interceptors.request.use((config) => {\r\n if (goesThroughOutbox(config)) config.adapter = adapter\r\n return config\r\n })\r\n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UAAU,CAAC,UAAU;AAC9C,UAAM,SAAS,UAAU,OAAO,SAAS;AACzC,QAAI,iBAAiB,MAAM;AAAA,EAC7B,CAAC;AACD,MAAI;AACF,UAAM,UAAU,MAAM,cAAoC,gBAAgB,EAAE,UAAA,GAAa,aAAa;AACtG,WAAO,EAAE,SAAS,KAAA;AAAA,EACpB,SAAS,OAAO;AACd,SAAA;AACA,UAAM;AAAA,EACR;AACF;AAEO,SAAS,cAAc,KAAoB,SAA8B;AAC9E,QAAM,YAAY,iBAAiB,QAAQ,WAAW,eAAe;AACrE,QAAM,UAAU,cAAc,KAAK,SAAS;AAC5C,MAAI,aAAa,QAAQ,IAAI,CAAC,WAAW;AACvC,QAAI,kBAAkB,MAAM,EAAG,QAAO,UAAU;AAChD,WAAO;AAAA,EACT,CAAC;AACH;"}
1
+ {"version":3,"file":"connectOutbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectOutbox.ts"],"sourcesContent":["import { AxiosError, AxiosHeaders } from 'axios'\r\nimport type { AxiosAdapter, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { ErroBridge, onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoOutbox = 'outbox.send' | 'outbox.watch'\r\n\r\nconst WRITE_METHODS = ['post', 'put', 'patch', 'delete']\r\nconst BRIDGE_WAIT_MS = 30_000\r\n\r\nexport const OUTBOX_SAVED_MESSAGE = 'Guardado no telemóvel. Será enviado quando a ligação voltar.'\r\n\r\nexport type OutboxOptions = { storageId: string | undefined }\r\n\r\nexport type OutboxRequestOptions = { expiresAt?: string | Date }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n outbox?: true | OutboxRequestOptions\r\n }\r\n}\r\n\r\ntype OutboxReply =\r\n | { outcome: 'delivered' | 'rejected'; status: number; body: unknown }\r\n | { outcome: 'saved'; id: string }\r\n\r\nexport class OutboxSavedError extends Error {\r\n readonly outboxActionId: string | null\r\n\r\n constructor(outboxActionId: string | null) {\r\n super(OUTBOX_SAVED_MESSAGE)\r\n this.name = 'OutboxSavedError'\r\n this.outboxActionId = outboxActionId\r\n }\r\n}\r\n\r\nexport function isOutboxSaved(error: unknown): error is OutboxSavedError {\r\n return error instanceof OutboxSavedError\r\n}\r\n\r\nfunction stringHeaders(config: InternalAxiosRequestConfig): Record<string, string> {\r\n const headers: Record<string, string> = {}\r\n for (const [name, value] of Object.entries(AxiosHeaders.from(config.headers).toJSON())) {\r\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') headers[name] = String(value)\r\n }\r\n return headers\r\n}\r\n\r\nasync function replyOf(carga: unknown): Promise<OutboxReply> {\r\n try {\r\n return await pedirAoNativo<OutboxReply>('outbox.send', carga, BRIDGE_WAIT_MS)\r\n } catch (error) {\r\n if (error instanceof ErroBridge && error.codigo === 'expirou') throw new OutboxSavedError(null)\r\n throw error\r\n }\r\n}\r\n\r\nfunction expiryOf(config: InternalAxiosRequestConfig): string | undefined {\r\n const expiresAt = config.outbox === true ? undefined : config.outbox?.expiresAt\r\n return expiresAt instanceof Date ? expiresAt.toISOString() : expiresAt\r\n}\r\n\r\nfunction outboxAdapter(api: AxiosInstance, storageId: string): AxiosAdapter {\r\n return async (config) => {\r\n const { address, path } = addressAndPath(api, config)\r\n const reply = await replyOf({\r\n storageId,\r\n address,\r\n method: config.method,\r\n path,\r\n headers: stringHeaders(config),\r\n body: config.data,\r\n expiresAt: expiryOf(config),\r\n })\r\n if (reply.outcome === 'saved') throw new OutboxSavedError(reply.id)\r\n\r\n const response: AxiosResponse = {\r\n data: reply.body,\r\n status: reply.status,\r\n statusText: '',\r\n headers: {},\r\n config,\r\n request: {},\r\n }\r\n const accepted = config.validateStatus ? config.validateStatus(reply.status) : reply.outcome === 'delivered'\r\n if (accepted) return response\r\n throw new AxiosError(\r\n `Request failed with status code ${reply.status}`,\r\n reply.status >= 500 ? AxiosError.ERR_BAD_RESPONSE : AxiosError.ERR_BAD_REQUEST,\r\n config,\r\n response.request,\r\n response,\r\n )\r\n }\r\n}\r\n\r\nfunction goesThroughOutbox(config: InternalAxiosRequestConfig): boolean {\r\n if (!config.outbox) return false\r\n const method = (config.method ?? 'get').toLowerCase()\r\n if (!WRITE_METHODS.includes(method)) {\r\n throw new Error(`connectOutbox: only writes go through the Outbox, and this ${method.toUpperCase()} is marked with outbox`)\r\n }\r\n const data: unknown = config.data\r\n if (data instanceof FormData || data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {\r\n throw new Error('connectOutbox: files do not go through the Outbox yet; send this write without outbox')\r\n }\r\n return dentroDaApp()\r\n}\r\n\r\nexport type OutboxState = 'pending' | 'sending' | 'delivered' | 'rejected' | 'expired' | 'deleted'\r\n\r\nexport type OutboxActionStatus = {\r\n id: string\r\n state: OutboxState\r\n createdAt?: string\r\n reason?: string\r\n method?: string\r\n path?: string\r\n}\r\n\r\nexport type OutboxWatch = { actions: OutboxActionStatus[]; stop: () => void }\r\n\r\nconst WATCH_WAIT_MS = 10_000\r\n\r\nfunction statusFor(carga: unknown, storageId: string): OutboxActionStatus | null {\r\n if (typeof carga !== 'object' || carga === null) return null\r\n const { storageId: of, ...status } = carga as OutboxActionStatus & { storageId?: string }\r\n return of === storageId ? status : null\r\n}\r\n\r\nexport async function watchOutbox(options: OutboxOptions, onChange: (status: OutboxActionStatus) => void): Promise<OutboxWatch> {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n if (!dentroDaApp()) return { actions: [], stop: () => undefined }\r\n const stop = onNativeEvent('outbox', (carga) => {\r\n const status = statusFor(carga, storageId)\r\n if (status) onChange(status)\r\n })\r\n try {\r\n const actions = await pedirAoNativo<OutboxActionStatus[]>('outbox.watch', { storageId }, WATCH_WAIT_MS)\r\n return { actions, stop }\r\n } catch (error) {\r\n stop()\r\n throw error\r\n }\r\n}\r\n\r\nexport function connectOutbox(api: AxiosInstance, options: OutboxOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n const adapter = outboxAdapter(api, storageId)\r\n api.interceptors.request.use((config) => {\r\n if (goesThroughOutbox(config)) config.adapter = adapter\r\n return config\r\n })\r\n}\r\n"],"names":[],"mappings":";;;;;AASA,MAAM,gBAAgB,CAAC,QAAQ,OAAO,SAAS,QAAQ;AACvD,MAAM,iBAAiB;AAEhB,MAAM,uBAAuB;AAgB7B,MAAM,yBAAyB,MAAM;AAAA,EAG1C,YAAY,gBAA+B;AACzC,UAAM,oBAAoB;AAC1B,SAAK,OAAO;AACZ,SAAK,iBAAiB;AAAA,EACxB;AACF;AAEO,SAAS,cAAc,OAA2C;AACvE,SAAO,iBAAiB;AAC1B;AAEA,SAAS,cAAc,QAA4D;AACjF,QAAM,UAAkC,CAAA;AACxC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,aAAa,KAAK,OAAO,OAAO,EAAE,OAAA,CAAQ,GAAG;AACtF,QAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,SAAQ,IAAI,IAAI,OAAO,KAAK;AAAA,EACxH;AACA,SAAO;AACT;AAEA,eAAe,QAAQ,OAAsC;AAC3D,MAAI;AACF,WAAO,MAAM,cAA2B,eAAe,OAAO,cAAc;AAAA,EAC9E,SAAS,OAAO;AACd,QAAI,iBAAiB,cAAc,MAAM,WAAW,UAAW,OAAM,IAAI,iBAAiB,IAAI;AAC9F,UAAM;AAAA,EACR;AACF;AAEA,SAAS,SAAS,QAAwD;AACxE,QAAM,YAAY,OAAO,WAAW,OAAO,SAAY,OAAO,QAAQ;AACtE,SAAO,qBAAqB,OAAO,UAAU,YAAA,IAAgB;AAC/D;AAEA,SAAS,cAAc,KAAoB,WAAiC;AAC1E,SAAO,OAAO,WAAW;AACvB,UAAM,EAAE,SAAS,KAAA,IAAS,eAAe,KAAK,MAAM;AACpD,UAAM,QAAQ,MAA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AAEA,eAAsB,YAAY,SAAwB,UAAsE;AAC9H,QAAM,YAAY,iBAAiB,QAAQ,WAAW,eAAe;AACrE,MAAI,CAAC,YAAA,EAAe,QAAO,EAAE,SAAS,IAAI,MAAM,MAAM,OAAA;AACtD,QAAM,OAAO,cAAc,UAAU,CAAC,UAAU;AAC9C,UAAM,SAAS,UAAU,OAAO,SAAS;AACzC,QAAI,iBAAiB,MAAM;AAAA,EAC7B,CAAC;AACD,MAAI;AACF,UAAM,UAAU,MAAM,cAAoC,gBAAgB,EAAE,UAAA,GAAa,aAAa;AACtG,WAAO,EAAE,SAAS,KAAA;AAAA,EACpB,SAAS,OAAO;AACd,SAAA;AACA,UAAM;AAAA,EACR;AACF;AAEO,SAAS,cAAc,KAAoB,SAA8B;AAC9E,QAAM,YAAY,iBAAiB,QAAQ,WAAW,eAAe;AACrE,QAAM,UAAU,cAAc,KAAK,SAAS;AAC5C,MAAI,aAAa,QAAQ,IAAI,CAAC,WAAW;AACvC,QAAI,kBAAkB,MAAM,EAAG,QAAO,UAAU;AAChD,WAAO;AAAA,EACT,CAAC;AACH;"}
@@ -0,0 +1,103 @@
1
+ import { useState, useEffect, useMemo } from "react";
2
+ import { watchInbox, inboxStatus } from "./connectInbox.js";
3
+ import { watchOutbox } from "./connectOutbox.js";
4
+ import { dentroDaApp } from "./dentroDaApp.js";
5
+ const STILL_WAITING = ["pending", "sending", "rejected"];
6
+ async function statusOrNothing(storageId, inboxId) {
7
+ try {
8
+ return await inboxStatus({ storageId, inboxId });
9
+ } catch {
10
+ return null;
11
+ }
12
+ }
13
+ function latest(dates) {
14
+ const known = dates.filter((date) => date !== null);
15
+ if (!known.length) return null;
16
+ return known.reduce((a, b) => a > b ? a : b);
17
+ }
18
+ function mergedAction(actions, change) {
19
+ const known = actions.find((action) => action.id === change.id);
20
+ const others = actions.filter((action) => action.id !== change.id);
21
+ if (!STILL_WAITING.includes(change.state)) return others;
22
+ return [...others, { ...known, ...change, method: change.method ?? known?.method, path: change.path ?? known?.path }];
23
+ }
24
+ function useOfflineBoxes({ storageId, inboxIds }) {
25
+ const inApp = dentroDaApp();
26
+ const inboxKey = inboxIds.join(",");
27
+ const [saved, setSaved] = useState({});
28
+ const [live, setLive] = useState({});
29
+ const [actions, setActions] = useState([]);
30
+ useEffect(() => {
31
+ if (!inApp) return;
32
+ let current = true;
33
+ const ids = inboxKey.split(",").filter(Boolean);
34
+ const load = async (inboxId) => {
35
+ const status = await statusOrNothing(storageId, inboxId);
36
+ if (current && status) setSaved((before) => ({ ...before, [inboxId]: status }));
37
+ };
38
+ for (const inboxId of ids) void load(inboxId);
39
+ const stop = watchInbox({ storageId }, (event) => {
40
+ if (!ids.includes(event.inboxId)) return;
41
+ if (event.finishedAt === null) {
42
+ setLive((before) => ({ ...before, [event.inboxId]: event }));
43
+ return;
44
+ }
45
+ setLive((before) => {
46
+ const rest = { ...before };
47
+ delete rest[event.inboxId];
48
+ return rest;
49
+ });
50
+ void load(event.inboxId);
51
+ });
52
+ return () => {
53
+ current = false;
54
+ stop();
55
+ };
56
+ }, [inApp, storageId, inboxKey]);
57
+ useEffect(() => {
58
+ if (!inApp) return;
59
+ let current = true;
60
+ let stop = () => void 0;
61
+ const start = async () => {
62
+ try {
63
+ const watch = await watchOutbox({ storageId }, (change) => {
64
+ if (current) setActions((before) => mergedAction(before, change));
65
+ });
66
+ stop = watch.stop;
67
+ if (!current) {
68
+ stop();
69
+ return;
70
+ }
71
+ setActions(watch.actions.filter((action) => STILL_WAITING.includes(action.state)));
72
+ } catch {
73
+ setActions([]);
74
+ }
75
+ };
76
+ void start();
77
+ return () => {
78
+ current = false;
79
+ stop();
80
+ };
81
+ }, [inApp, storageId]);
82
+ return useMemo(() => {
83
+ if (!inApp) return null;
84
+ const ids = inboxKey.split(",").filter(Boolean);
85
+ const parts = [];
86
+ for (const inboxId of ids) {
87
+ const part = live[inboxId] ?? saved[inboxId];
88
+ if (part) parts.push(part);
89
+ }
90
+ const inbox = {
91
+ total: parts.reduce((sum, part) => sum + part.total, 0),
92
+ ready: parts.reduce((sum, part) => sum + part.ready, 0),
93
+ failed: parts.reduce((sum, part) => sum + part.failed, 0),
94
+ finishedAt: latest(ids.map((inboxId) => saved[inboxId]?.finishedAt ?? null)),
95
+ saved: [...new Set(ids.flatMap((inboxId) => saved[inboxId]?.saved ?? []))]
96
+ };
97
+ return { inbox, downloading: ids.some((inboxId) => inboxId in live), waiting: actions };
98
+ }, [inApp, inboxKey, live, saved, actions]);
99
+ }
100
+ export {
101
+ useOfflineBoxes
102
+ };
103
+ //# sourceMappingURL=useOfflineBoxes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOfflineBoxes.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/useOfflineBoxes.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react'\r\nimport { inboxStatus, watchInbox, type InboxEvent, type InboxProgress, type InboxStatus } from './connectInbox'\r\nimport { watchOutbox, type OutboxActionStatus } from './connectOutbox'\r\nimport { dentroDaApp } from './dentroDaApp'\r\n\r\nexport type OfflineBoxesOptions = { storageId: string | undefined; inboxIds: string[] }\r\n\r\nexport type OfflineBoxesState = {\r\n inbox: InboxStatus & { saved: string[] }\r\n downloading: boolean\r\n waiting: OutboxActionStatus[]\r\n}\r\n\r\nconst STILL_WAITING: OutboxActionStatus['state'][] = ['pending', 'sending', 'rejected']\r\n\r\nasync function statusOrNothing(storageId: string | undefined, inboxId: string): Promise<InboxStatus | null> {\r\n try {\r\n return await inboxStatus({ storageId, inboxId })\r\n } catch {\r\n return null\r\n }\r\n}\r\n\r\nfunction latest(dates: (string | null)[]): string | null {\r\n const known = dates.filter((date): date is string => date !== null)\r\n if (!known.length) return null\r\n return known.reduce((a, b) => (a > b ? a : b))\r\n}\r\n\r\nfunction mergedAction(actions: OutboxActionStatus[], change: OutboxActionStatus): OutboxActionStatus[] {\r\n const known = actions.find((action) => action.id === change.id)\r\n const others = actions.filter((action) => action.id !== change.id)\r\n if (!STILL_WAITING.includes(change.state)) return others\r\n return [...others, { ...known, ...change, method: change.method ?? known?.method, path: change.path ?? known?.path }]\r\n}\r\n\r\nexport function useOfflineBoxes({ storageId, inboxIds }: OfflineBoxesOptions): OfflineBoxesState | null {\r\n const inApp = dentroDaApp()\r\n const inboxKey = inboxIds.join(',')\r\n const [saved, setSaved] = useState<Record<string, InboxStatus>>({})\r\n const [live, setLive] = useState<Record<string, InboxEvent>>({})\r\n const [actions, setActions] = useState<OutboxActionStatus[]>([])\r\n\r\n useEffect(() => {\r\n if (!inApp) return\r\n let current = true\r\n const ids = inboxKey.split(',').filter(Boolean)\r\n const load = async (inboxId: string) => {\r\n const status = await statusOrNothing(storageId, inboxId)\r\n if (current && status) setSaved((before) => ({ ...before, [inboxId]: status }))\r\n }\r\n for (const inboxId of ids) void load(inboxId)\r\n const stop = watchInbox({ storageId }, (event) => {\r\n if (!ids.includes(event.inboxId)) return\r\n if (event.finishedAt === null) {\r\n setLive((before) => ({ ...before, [event.inboxId]: event }))\r\n return\r\n }\r\n setLive((before) => {\r\n const rest = { ...before }\r\n delete rest[event.inboxId]\r\n return rest\r\n })\r\n void load(event.inboxId)\r\n })\r\n return () => {\r\n current = false\r\n stop()\r\n }\r\n }, [inApp, storageId, inboxKey])\r\n\r\n useEffect(() => {\r\n if (!inApp) return\r\n let current = true\r\n let stop: () => void = () => undefined\r\n const start = async () => {\r\n try {\r\n const watch = await watchOutbox({ storageId }, (change) => {\r\n if (current) setActions((before) => mergedAction(before, change))\r\n })\r\n stop = watch.stop\r\n if (!current) {\r\n stop()\r\n return\r\n }\r\n setActions(watch.actions.filter((action) => STILL_WAITING.includes(action.state)))\r\n } catch {\r\n setActions([])\r\n }\r\n }\r\n void start()\r\n return () => {\r\n current = false\r\n stop()\r\n }\r\n }, [inApp, storageId])\r\n\r\n return useMemo(() => {\r\n if (!inApp) return null\r\n const ids = inboxKey.split(',').filter(Boolean)\r\n const parts: InboxProgress[] = []\r\n for (const inboxId of ids) {\r\n const part = live[inboxId] ?? saved[inboxId]\r\n if (part) parts.push(part)\r\n }\r\n const inbox = {\r\n total: parts.reduce((sum, part) => sum + part.total, 0),\r\n ready: parts.reduce((sum, part) => sum + part.ready, 0),\r\n failed: parts.reduce((sum, part) => sum + part.failed, 0),\r\n finishedAt: latest(ids.map((inboxId) => saved[inboxId]?.finishedAt ?? null)),\r\n saved: [...new Set(ids.flatMap((inboxId) => saved[inboxId]?.saved ?? []))],\r\n }\r\n return { inbox, downloading: ids.some((inboxId) => inboxId in live), waiting: actions }\r\n }, [inApp, inboxKey, live, saved, actions])\r\n}\r\n"],"names":[],"mappings":";;;;AAaA,MAAM,gBAA+C,CAAC,WAAW,WAAW,UAAU;AAEtF,eAAe,gBAAgB,WAA+B,SAA8C;AAC1G,MAAI;AACF,WAAO,MAAM,YAAY,EAAE,WAAW,SAAS;AAAA,EACjD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,OAAO,OAAyC;AACvD,QAAM,QAAQ,MAAM,OAAO,CAAC,SAAyB,SAAS,IAAI;AAClE,MAAI,CAAC,MAAM,OAAQ,QAAO;AAC1B,SAAO,MAAM,OAAO,CAAC,GAAG,MAAO,IAAI,IAAI,IAAI,CAAE;AAC/C;AAEA,SAAS,aAAa,SAA+B,QAAkD;AACrG,QAAM,QAAQ,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,OAAO,EAAE;AAC9D,QAAM,SAAS,QAAQ,OAAO,CAAC,WAAW,OAAO,OAAO,OAAO,EAAE;AACjE,MAAI,CAAC,cAAc,SAAS,OAAO,KAAK,EAAG,QAAO;AAClD,SAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,OAAO,GAAG,QAAQ,QAAQ,OAAO,UAAU,OAAO,QAAQ,MAAM,OAAO,QAAQ,OAAO,MAAM;AACtH;AAEO,SAAS,gBAAgB,EAAE,WAAW,YAA2D;AACtG,QAAM,QAAQ,YAAA;AACd,QAAM,WAAW,SAAS,KAAK,GAAG;AAClC,QAAM,CAAC,OAAO,Q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} from "react/jsx-runtime";
2
+ import { useId, useEffect } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { useFloatingPanel } from "../../../capabilities/overlay/useFloatingPanel.js";
5
+ import { useOfflineBoxes } from "../../../capabilities/onepoint-rn/useOfflineBoxes.js";
6
+ import { useDialogContainer } from "../../overlays/Dialog/Dialog.js";
7
+ import { OfflineBoxesIcon } from "./OfflineBoxesIcon.js";
8
+ const DEFAULT_OFFLINE_BOXES_LABELS = {
9
+ title: "Offline",
10
+ saved: "Saved on this phone",
11
+ waiting: "Waiting to send",
12
+ toSend: "{n} to send",
13
+ downloading: "Downloading: {ready} / {total}",
14
+ savedAt: "{ready} / {total} · saved at {time}",
15
+ nothingSaved: "Nothing saved yet",
16
+ failed: "{n} failed. What was already saved is still available.",
17
+ savedList: "What is saved ({n})",
18
+ nothingWaiting: "Nothing waiting to send.",
19
+ refresh: "Refresh",
20
+ close: "Close",
21
+ pending: "Waiting for a connection",
22
+ sending: "Sending…",
23
+ rejected: "Refused"
24
+ };
25
+ function filled(template, values) {
26
+ return template.replace(/\{(\w+)\}/g, (whole, name) => name in values ? String(values[name]) : whole);
27
+ }
28
+ function clock(iso) {
29
+ return new Date(iso).toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
30
+ }
31
+ function shownPath(saved, address) {
32
+ if (!address) return saved;
33
+ const base = new URL(address, window.location.href).href.replace(/\/$/, "");
34
+ return saved.startsWith(base) ? saved.slice(base.length) || "/" : saved;
35
+ }
36
+ const STATE_TONE = {
37
+ pending: "text-orange-700 dark:text-orange-300",
38
+ sending: "text-proef-blue dark:text-sky-300",
39
+ rejected: "text-red-700 dark:text-red-300"
40
+ };
41
+ function OfflineBoxes({ storageId, inboxIds, onRefresh, address, labels, className = "" }) {
42
+ const L = { ...DEFAULT_OFFLINE_BOXES_LABELS, ...labels };
43
+ const state = useOfflineBoxes({ storageId, inboxIds });
44
+ const p = useFloatingPanel("right");
45
+ const dialogContainer = useDialogContainer();
46
+ const panelId = useId();
47
+ useEffect(() => {
48
+ if (!p.open) return;
49
+ const escape = (e) => {
50
+ if (e.key !== "Escape") return;
51
+ p.close();
52
+ p.triggerRef.current?.focus();
53
+ };
54
+ document.addEventListener("keydown", escape);
55
+ return () => document.removeEventListener("keydown", escape);
56
+ }, [p]);
57
+ if (!state) return null;
58
+ const { inbox, downloading, waiting } = state;
59
+ const pct = inbox.total > 0 ? Math.round(inbox.ready / inbox.total * 100) : null;
60
+ const pctLabel = pct === null ? "–" : `${pct}%`;
61
+ const toSend = waiting.filter((action) => action.state !== "rejected").length;
62
+ const inboxLine = downloading ? filled(L.downloading, { ready: inbox.ready, total: inbox.total }) : inbox.finishedAt ? filled(L.savedAt, { ready: inbox.ready, total: inbox.total, time: clock(inbox.finishedAt) }) : L.nothingSaved;
63
+ const stateLabel = (action) => action.state === "sending" ? L.sending : action.state === "rejected" ? L.rejected : L.pending;
64
+ return /* @__PURE__ */ jsxs("div", { className: `relative inline-flex shrink-0 ${className}`, children: [
65
+ /* @__PURE__ */ jsxs(
66
+ "button",
67
+ {
68
+ ref: p.triggerRef,
69
+ type: "button",
70
+ "aria-haspopup": "dialog",
71
+ "aria-expanded": p.open,
72
+ "aria-controls": p.open ? panelId : void 0,
73
+ "aria-label": `${L.title}: ${pctLabel} · ${filled(L.toSend, { n: toSend })}`,
74
+ onClick: (e) => {
75
+ e.stopPropagation();
76
+ p.setOpen((open) => !open);
77
+ },
78
+ className: "flex min-h-11 cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent px-1.5 text-left hover:bg-slate-100 dark:hover:bg-slate-800",
79
+ children: [
80
+ /* @__PURE__ */ jsx(OfflineBoxesIcon, { size: 28 }),
81
+ /* @__PURE__ */ jsxs("span", { className: "flex flex-col leading-tight whitespace-nowrap", children: [
82
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-extrabold tabular-nums text-emerald-700 dark:text-emerald-300", children: pctLabel }),
83
+ toSend > 0 && /* @__PURE__ */ jsx("span", { className: "text-[11px] font-bold text-orange-700 dark:text-orange-300", children: filled(L.toSend, { n: toSend }) })
84
+ ] })
85
+ ]
86
+ }
87
+ ),
88
+ p.open && createPortal(
89
+ /* @__PURE__ */ jsxs(
90
+ "div",
91
+ {
92
+ ref: p.panelRef,
93
+ id: panelId,
94
+ role: "dialog",
95
+ "aria-label": L.title,
96
+ style: p.style,
97
+ onClick: (e) => e.stopPropagation(),
98
+ className: "fixed z-[60] flex max-h-[70vh] w-80 flex-col overflow-auto rounded-xl border border-slate-200 bg-white text-sm text-slate-800 shadow-lg dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",
99
+ children: [
100
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 pt-3", children: [
101
+ /* @__PURE__ */ jsx("h2", { className: "m-0 text-base font-extrabold", children: L.title }),
102
+ /* @__PURE__ */ jsx(
103
+ "button",
104
+ {
105
+ type: "button",
106
+ "aria-label": L.close,
107
+ onClick: () => {
108
+ p.close();
109
+ p.triggerRef.current?.focus();
110
+ },
111
+ className: "-mr-2 flex h-11 w-11 cursor-pointer items-center justify-center rounded-lg border-0 bg-transparent text-slate-500 hover:bg-slate-100 dark:hover:bg-slate-800",
112
+ children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M4 4l8 8M12 4l-8 8", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" }) })
113
+ }
114
+ )
115
+ ] }),
116
+ /* @__PURE__ */ jsxs("section", { className: "flex flex-col gap-2 border-b border-slate-100 px-4 pt-1 pb-4 dark:border-slate-800", children: [
117
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
118
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-[11px] font-bold tracking-wider text-slate-500 uppercase dark:text-slate-400", children: [
119
+ /* @__PURE__ */ jsx("span", { className: "h-2.5 w-2.5 rounded-[3px] bg-[#19C99B]" }),
120
+ L.saved
121
+ ] }),
122
+ /* @__PURE__ */ jsx("span", { className: "text-2xl font-extrabold tabular-nums text-emerald-700 dark:text-emerald-300", children: pctLabel })
123
+ ] }),
124
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
125
+ /* @__PURE__ */ jsx("span", { className: "tabular-nums text-slate-600 dark:text-slate-300", children: inboxLine }),
126
+ onRefresh && /* @__PURE__ */ jsxs(
127
+ "button",
128
+ {
129
+ type: "button",
130
+ disabled: downloading,
131
+ onClick: onRefresh,
132
+ className: "flex h-9 cursor-pointer items-center gap-1.5 rounded-full border border-slate-300 bg-white px-3 text-[13px] font-semibold text-proef-navy disabled:cursor-default disabled:opacity-50 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100",
133
+ children: [
134
+ /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5v3h-3", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" }) }),
135
+ L.refresh
136
+ ]
137
+ }
138
+ )
139
+ ] }),
140
+ !downloading && inbox.failed > 0 && /* @__PURE__ */ jsx("p", { className: "m-0 text-[13px] text-orange-800 dark:text-orange-300", children: filled(L.failed, { n: inbox.failed }) }),
141
+ inbox.saved.length > 0 && /* @__PURE__ */ jsxs("details", { className: "text-[13px]", children: [
142
+ /* @__PURE__ */ jsx("summary", { className: "cursor-pointer py-1 font-semibold text-slate-700 dark:text-slate-200", children: filled(L.savedList, { n: inbox.saved.length }) }),
143
+ /* @__PURE__ */ jsx("ul", { className: "m-0 mt-1 max-h-48 list-none overflow-auto p-0 font-mono text-xs text-slate-600 dark:text-slate-300", children: inbox.saved.map((saved) => /* @__PURE__ */ jsx("li", { className: "truncate py-0.5", children: shownPath(saved, address) }, saved)) })
144
+ ] })
145
+ ] }),
146
+ /* @__PURE__ */ jsxs("section", { className: "flex flex-col gap-2 px-4 pt-3 pb-4", children: [
147
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-[11px] font-bold tracking-wider text-slate-500 uppercase dark:text-slate-400", children: [
148
+ /* @__PURE__ */ jsx("span", { className: "h-2.5 w-2.5 rounded-[3px] bg-[#EA6A12]" }),
149
+ L.waiting
150
+ ] }),
151
+ waiting.length === 0 ? /* @__PURE__ */ jsx("p", { className: "m-0 text-[13px] text-slate-600 dark:text-slate-300", children: L.nothingWaiting }) : /* @__PURE__ */ jsx("ul", { className: "m-0 list-none p-0", children: waiting.map((action) => /* @__PURE__ */ jsxs("li", { className: "flex items-start gap-2 border-t border-slate-100 py-2 dark:border-slate-800", children: [
152
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [
153
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-xs break-all text-slate-800 dark:text-slate-100", children: action.method && action.path ? `${action.method} ${action.path}` : action.id }),
154
+ /* @__PURE__ */ jsxs("span", { className: `text-xs ${STATE_TONE[action.state] ?? ""}`, children: [
155
+ stateLabel(action),
156
+ action.state === "rejected" && action.reason ? ` · ${action.reason}` : ""
157
+ ] })
158
+ ] }),
159
+ action.createdAt && /* @__PURE__ */ jsx("span", { className: "text-xs tabular-nums text-slate-500", children: clock(action.createdAt) })
160
+ ] }, action.id)) })
161
+ ] })
162
+ ]
163
+ }
164
+ ),
165
+ dialogContainer ?? document.body
166
+ )
167
+ ] });
168
+ }
169
+ export {
170
+ DEFAULT_OFFLINE_BOXES_LABELS,
171
+ OfflineBoxes,
172
+ OfflineBoxes as default
173
+ };
174
+ //# sourceMappingURL=OfflineBoxes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OfflineBoxes.js","sources":["../../../../../../src/v1/components/feedback/OfflineBoxes/OfflineBoxes.tsx"],"sourcesContent":["import React, { useEffect, useId } from 'react'\r\nimport { createPortal } from 'react-dom'\r\nimport { useFloatingPanel } from '../../../capabilities/overlay/useFloatingPanel'\r\nimport { useOfflineBoxes } from '../../../capabilities/onepoint-rn/useOfflineBoxes'\r\nimport type { OutboxActionStatus } from '../../../capabilities/onepoint-rn/connectOutbox'\r\nimport { useDialogContainer } from '../../overlays/Dialog/Dialog'\r\nimport OfflineBoxesIcon from './OfflineBoxesIcon'\r\n\r\nexport interface OfflineBoxesLabels {\r\n /** Título do painel. */\r\n title: string\r\n /** Secção da Inbox. */\r\n saved: string\r\n /** Secção da Outbox. */\r\n waiting: string\r\n /** Ao lado do ícone, com `{n}`. */\r\n toSend: string\r\n /** A descarregar, com `{ready}` e `{total}`. */\r\n downloading: string\r\n /** Última descarga, com `{ready}`, `{total}` e `{time}`. */\r\n savedAt: string\r\n /** Ainda nada guardado. */\r\n nothingSaved: string\r\n /** Falharam pedidos, com `{n}`. */\r\n failed: string\r\n /** Lista do que está guardado, com `{n}`. */\r\n savedList: string\r\n /** Nada por enviar. */\r\n nothingWaiting: string\r\n refresh: string\r\n close: string\r\n pending: string\r\n sending: string\r\n rejected: string\r\n}\r\n\r\nexport const DEFAULT_OFFLINE_BOXES_LABELS: OfflineBoxesLabels = {\r\n title: 'Offline',\r\n saved: 'Saved on this phone',\r\n waiting: 'Waiting to send',\r\n toSend: '{n} to send',\r\n downloading: 'Downloading: {ready} / {total}',\r\n savedAt: '{ready} / {total} · saved at {time}',\r\n nothingSaved: 'Nothing saved yet',\r\n failed: '{n} failed. What was already saved is still available.',\r\n savedList: 'What is saved ({n})',\r\n nothingWaiting: 'Nothing waiting to send.',\r\n refresh: 'Refresh',\r\n close: 'Close',\r\n pending: 'Waiting for a connection',\r\n sending: 'Sending…',\r\n rejected: 'Refused',\r\n}\r\n\r\nexport interface OfflineBoxesProps {\r\n /** O mesmo `storageId` do `connectOutbox` e do `connectInbox`. */\r\n storageId: string | undefined\r\n /** As inboxes que este sítio mostra (ex: `['ajustes']`). Somam-se. */\r\n inboxIds: string[]\r\n /** O que o botão Atualizar faz (ex: chamar o `syncInbox`). Sem ele, não há botão. */\r\n onRefresh?: () => void\r\n /** Endereço da API (`api.defaults.baseURL`), para mostrar o que está guardado sem ele à frente. */\r\n address?: string\r\n labels?: Partial<OfflineBoxesLabels>\r\n className?: string\r\n}\r\n\r\nfunction filled(template: string, values: Record<string, string | number>): string {\r\n return template.replace(/\\{(\\w+)\\}/g, (whole, name: string) => (name in values ? String(values[name]) : whole))\r\n}\r\n\r\nfunction clock(iso: string): string {\r\n return new Date(iso).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })\r\n}\r\n\r\nfunction shownPath(saved: string, address: string | undefined): string {\r\n if (!address) return saved\r\n const base = new URL(address, window.location.href).href.replace(/\\/$/, '')\r\n return saved.startsWith(base) ? saved.slice(base.length) || '/' : saved\r\n}\r\n\r\nconst STATE_TONE: Record<string, string> = {\r\n pending: 'text-orange-700 dark:text-orange-300',\r\n sending: 'text-proef-blue dark:text-sky-300',\r\n rejected: 'text-red-700 dark:text-red-300',\r\n}\r\n\r\n/**\r\n * O que a app tem guardado para usar sem rede (Inbox, verde) e o que tem por\r\n * enviar (Outbox, laranja), num ícone que se põe onde se quiser (ex: à\r\n * direita do título). Ao lado, a percentagem guardada, que sobe enquanto a\r\n * descarga corre, e quantas escritas faltam enviar. Tocar abre o painel com o\r\n * detalhe. Fora da app OnePoint não aparece.\r\n */\r\nexport default function OfflineBoxes({ storageId, inboxIds, onRefresh, address, labels, className = '' }: OfflineBoxesProps) {\r\n const L = { ...DEFAULT_OFFLINE_BOXES_LABELS, ...labels }\r\n const state = useOfflineBoxes({ storageId, inboxIds })\r\n const p = useFloatingPanel('right')\r\n const dialogContainer = useDialogContainer()\r\n const panelId = useId()\r\n\r\n useEffect(() => {\r\n if (!p.open) return\r\n const escape = (e: KeyboardEvent) => {\r\n if (e.key !== 'Escape') return\r\n p.close()\r\n p.triggerRef.current?.focus()\r\n }\r\n document.addEventListener('keydown', escape)\r\n return () => document.removeEventListener('keydown', escape)\r\n }, [p])\r\n\r\n if (!state) return null\r\n\r\n const { inbox, downloading, waiting } = state\r\n const pct = inbox.total > 0 ? Math.round((inbox.ready / inbox.total) * 100) : null\r\n const pctLabel = pct === null ? '–' : `${pct}%`\r\n const toSend = waiting.filter((action) => action.state !== 'rejected').length\r\n const inboxLine = downloading\r\n ? filled(L.downloading, { ready: inbox.ready, total: inbox.total })\r\n : inbox.finishedAt\r\n ? filled(L.savedAt, { ready: inbox.ready, total: inbox.total, time: clock(inbox.finishedAt) })\r\n : L.nothingSaved\r\n const stateLabel = (action: OutboxActionStatus) =>\r\n action.state === 'sending' ? L.sending : action.state === 'rejected' ? L.rejected : L.pending\r\n\r\n return (\r\n <div className={`relative inline-flex shrink-0 ${className}`}>\r\n <button\r\n ref={p.triggerRef}\r\n type=\"button\"\r\n aria-haspopup=\"dialog\"\r\n aria-expanded={p.open}\r\n aria-controls={p.open ? panelId : undefined}\r\n aria-label={`${L.title}: ${pctLabel} · ${filled(L.toSend, { n: toSend })}`}\r\n onClick={(e) => {\r\n e.stopPropagation()\r\n p.setOpen((open) => !open)\r\n }}\r\n className=\"flex min-h-11 cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent px-1.5 text-left hover:bg-slate-100 dark:hover:bg-slate-800\"\r\n >\r\n <OfflineBoxesIcon size={28} />\r\n <span className=\"flex flex-col leading-tight whitespace-nowrap\">\r\n <span className=\"text-xs font-extrabold tabular-nums text-emerald-700 dark:text-emerald-300\">{pctLabel}</span>\r\n {toSend > 0 && <span className=\"text-[11px] font-bold text-orange-700 dark:text-orange-300\">{filled(L.toSend, { n: toSend })}</span>}\r\n </span>\r\n </button>\r\n {p.open &&\r\n createPortal(\r\n <div\r\n ref={p.panelRef}\r\n id={panelId}\r\n role=\"dialog\"\r\n aria-label={L.title}\r\n style={p.style}\r\n onClick={(e) => e.stopPropagation()}\r\n className=\"fixed z-[60] flex max-h-[70vh] w-80 flex-col overflow-auto rounded-xl border border-slate-200 bg-white text-sm text-slate-800 shadow-lg dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100\"\r\n >\r\n <div className=\"flex items-center justify-between px-4 pt-3\">\r\n <h2 className=\"m-0 text-base font-extrabold\">{L.title}</h2>\r\n <button\r\n type=\"button\"\r\n aria-label={L.close}\r\n onClick={() => {\r\n p.close()\r\n p.triggerRef.current?.focus()\r\n }}\r\n className=\"-mr-2 flex h-11 w-11 cursor-pointer items-center justify-center rounded-lg border-0 bg-transparent text-slate-500 hover:bg-slate-100 dark:hover:bg-slate-800\"\r\n >\r\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M4 4l8 8M12 4l-8 8\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" /></svg>\r\n </button>\r\n </div>\r\n\r\n <section className=\"flex flex-col gap-2 border-b border-slate-100 px-4 pt-1 pb-4 dark:border-slate-800\">\r\n <div className=\"flex items-center justify-between\">\r\n <span className=\"flex items-center gap-2 text-[11px] font-bold tracking-wider text-slate-500 uppercase dark:text-slate-400\">\r\n <span className=\"h-2.5 w-2.5 rounded-[3px] bg-[#19C99B]\" />\r\n {L.saved}\r\n </span>\r\n <span className=\"text-2xl font-extrabold tabular-nums text-emerald-700 dark:text-emerald-300\">{pctLabel}</span>\r\n </div>\r\n <div className=\"flex items-center justify-between gap-2\">\r\n <span className=\"tabular-nums text-slate-600 dark:text-slate-300\">{inboxLine}</span>\r\n {onRefresh && (\r\n <button\r\n type=\"button\"\r\n disabled={downloading}\r\n onClick={onRefresh}\r\n className=\"flex h-9 cursor-pointer items-center gap-1.5 rounded-full border border-slate-300 bg-white px-3 text-[13px] font-semibold text-proef-navy disabled:cursor-default disabled:opacity-50 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-100\"\r\n >\r\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5v3h-3\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" /></svg>\r\n {L.refresh}\r\n </button>\r\n )}\r\n </div>\r\n {!downloading && inbox.failed > 0 && <p className=\"m-0 text-[13px] text-orange-800 dark:text-orange-300\">{filled(L.failed, { n: inbox.failed })}</p>}\r\n {inbox.saved.length > 0 && (\r\n <details className=\"text-[13px]\">\r\n <summary className=\"cursor-pointer py-1 font-semibold text-slate-700 dark:text-slate-200\">{filled(L.savedList, { n: inbox.saved.length })}</summary>\r\n <ul className=\"m-0 mt-1 max-h-48 list-none overflow-auto p-0 font-mono text-xs text-slate-600 dark:text-slate-300\">\r\n {inbox.saved.map((saved) => (\r\n <li key={saved} className=\"truncate py-0.5\">{shownPath(saved, address)}</li>\r\n ))}\r\n </ul>\r\n </details>\r\n )}\r\n </section>\r\n\r\n <section className=\"flex flex-col gap-2 px-4 pt-3 pb-4\">\r\n <span className=\"flex items-center gap-2 text-[11px] font-bold tracking-wider text-slate-500 uppercase dark:text-slate-400\">\r\n <span className=\"h-2.5 w-2.5 rounded-[3px] bg-[#EA6A12]\" />\r\n {L.waiting}\r\n </span>\r\n {waiting.length === 0 ? (\r\n <p className=\"m-0 text-[13px] text-slate-600 dark:text-slate-300\">{L.nothingWaiting}</p>\r\n ) : (\r\n <ul className=\"m-0 list-none p-0\">\r\n {waiting.map((action) => (\r\n <li key={action.id} className=\"flex items-start gap-2 border-t border-slate-100 py-2 dark:border-slate-800\">\r\n <span className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\r\n <span className=\"font-mono text-xs break-all text-slate-800 dark:text-slate-100\">\r\n {action.method && action.path ? `${action.method} ${action.path}` : action.id}\r\n </span>\r\n <span className={`text-xs ${STATE_TONE[action.state] ?? ''}`}>\r\n {stateLabel(action)}\r\n {action.state === 'rejected' && action.reason ? ` · ${action.reason}` : ''}\r\n </span>\r\n </span>\r\n {action.createdAt && <span className=\"text-xs tabular-nums text-slate-500\">{clock(action.createdAt)}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