@proef/common-ui 2.6.42 → 2.6.44
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 +2 -1
- package/dist/esm/v1/capabilities/onepoint-rn/connectInbox.js +6 -0
- package/dist/esm/v1/capabilities/onepoint-rn/connectInbox.js.map +1 -1
- package/dist/esm/v1/capabilities/onepoint-rn/connectOutbox.js.map +1 -1
- package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxes.js +33 -9
- package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxes.js.map +1 -1
- package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxesView.js +345 -91
- package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxesView.js.map +1 -1
- package/dist/style.components.css +2 -2
- package/dist/style.css +2 -2
- package/dist/style.layered.css +2 -2
- package/dist/types/v1/capabilities/onepoint-rn/connectInbox.d.ts +17 -0
- package/dist/types/v1/capabilities/onepoint-rn/connectOutbox.d.ts +4 -0
- package/dist/types/v1/components/feedback/OfflineBoxes/OfflineBoxes.d.ts +6 -5
- package/dist/types/v1/components/feedback/OfflineBoxes/OfflineBoxesView.d.ts +49 -11
- package/dist/types/v1/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -113,7 +113,7 @@ import { ESTILO_AVATAR_PILHA, PessoaComFoto, PilhaAvatares } from "./legacy/comp
|
|
|
113
113
|
import { ErroBridge, pedirAoNativo } from "./v1/capabilities/onepoint-rn/bridge.js";
|
|
114
114
|
import { FilterChips } from "./v1/primitives/display/FilterChips/FilterChips.js";
|
|
115
115
|
import { FontWeight } from "./legacy/constants/FontWeight.js";
|
|
116
|
-
import { INBOX_SAVED_AT_HEADER, connectInbox, inboxSavedAt, inboxStatus, syncInbox, watchInbox } from "./v1/capabilities/onepoint-rn/connectInbox.js";
|
|
116
|
+
import { INBOX_SAVED_AT_HEADER, connectInbox, inboxSavedAt, inboxStatus, readInbox, syncInbox, watchInbox } from "./v1/capabilities/onepoint-rn/connectInbox.js";
|
|
117
117
|
import { InputData, InputHora } from "./legacy/components/atoms/InputData/InputData.js";
|
|
118
118
|
import { Kpi } from "./v1/primitives/display/Kpi/Kpi.js";
|
|
119
119
|
import { LazyLoader } from "./legacy/components/organisms/LazyLoader/LazyLoader.js";
|
|
@@ -378,6 +378,7 @@ export {
|
|
|
378
378
|
orderColumns,
|
|
379
379
|
partialMatchWithUsername,
|
|
380
380
|
pedirAoNativo,
|
|
381
|
+
readInbox,
|
|
381
382
|
richTextContentClasses,
|
|
382
383
|
richTextIsEmpty,
|
|
383
384
|
richTextToPlain,
|
|
@@ -54,6 +54,11 @@ function inboxSavedAt(response) {
|
|
|
54
54
|
const savedAt = response.headers[INBOX_SAVED_AT_HEADER];
|
|
55
55
|
return typeof savedAt === "string" ? savedAt : null;
|
|
56
56
|
}
|
|
57
|
+
async function readInbox(options) {
|
|
58
|
+
const storageId = checkedStorageId(options.storageId, "readInbox");
|
|
59
|
+
if (!dentroDaApp()) return null;
|
|
60
|
+
return pedirAoNativo("inbox.read", { storageId, address: options.address, path: options.path }, BRIDGE_WAIT_MS);
|
|
61
|
+
}
|
|
57
62
|
async function inboxStatus(options) {
|
|
58
63
|
const storageId = checkedStorageId(options.storageId, "inboxStatus");
|
|
59
64
|
const inboxId = checkedInboxId(options.inboxId, "inboxStatus");
|
|
@@ -113,6 +118,7 @@ export {
|
|
|
113
118
|
connectInbox,
|
|
114
119
|
inboxSavedAt,
|
|
115
120
|
inboxStatus,
|
|
121
|
+
readInbox,
|
|
116
122
|
syncInbox,
|
|
117
123
|
watchInbox
|
|
118
124
|
};
|
|
@@ -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; 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 // O cancelamento primeiro, ainda com `error: unknown`. O `isCancel` do axios é um type guard\r\n // (`value is Cancel`) e o `Cancel` é só `{ message }`, forma que o AxiosError também tem: depois\r\n // do `instanceof`, o `!isCancel` tirava o AxiosError ao tipo e sobrava `never` (erro no build).\r\n if (axios.isCancel(error)) return false\r\n if (!(error instanceof AxiosError) || !error.config || error.response) 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;AAItG,MAAI,MAAM,SAAS,KAAK,EAAG,QAAO;AAClC,MAAI,EAAE,iBAAiB,eAAe,CAAC,MAAM,UAAU,MAAM,SAAU,QAAO;AAC9E,QAAM,UAAU,MAAM,OAAO,UAAU,OAAO,YAAA;AAC9C,SAAO,WAAW,SAAS,MAAM,OAAO,UAAU,SAAS,YAAA;AAC7D;AAEA,eAAe,aAAa,KAAoB,WAAmB,QAAmE;AACpI,QAAM,EAAE,SAAS,KAAA,IAAS,eAAe,KAAK,MAAM;AACpD,MAAI;AACJ,MAAI;AACF,aAAS,MAAM,cAAyB,cAAc,EAAE,WAAW,SAAS,KAAA,GAAQ,cAAc;AAAA,EACpG,QAAQ;AACN,WAAO;AAAA,EACT;AACA,MAAI,CAAC,OAAO,MAAO,QAAO;AA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AAA,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\nexport type 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 // O cancelamento primeiro, ainda com `error: unknown`. O `isCancel` do axios é um type guard\r\n // (`value is Cancel`) e o `Cancel` é só `{ message }`, forma que o AxiosError também tem: depois\r\n // do `instanceof`, o `!isCancel` tirava o AxiosError ao tipo e sobrava `never` (erro no build).\r\n if (axios.isCancel(error)) return false\r\n if (!(error instanceof AxiosError) || !error.config || error.response) 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\n/**\r\n * O que a app tem guardado para um pedido (ex: para mostrar a quem usa o que\r\n * está no telemóvel). `address` é o endereço da API por inteiro (com\r\n * `https://`); `path` é o resto. Fora da app, `null`.\r\n */\r\nexport async function readInbox(options: InboxOptions & { address: string; path: string }): Promise<InboxRead | null> {\r\n const storageId = checkedStorageId(options.storageId, 'readInbox')\r\n if (!dentroDaApp()) return null\r\n return pedirAoNativo<InboxRead>('inbox.read', { storageId, address: options.address, path: options.path }, BRIDGE_WAIT_MS)\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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,OAAO,QAAQ,WAAW,OAAA;AAChF;AAEO,SAAS,WAAW,SAAuB,SAAkD;AAClG,QAAM,YAAY,iBAAiB,QAAQ,WAAW,YAAY;AAClE,MAAI,CAAC,cAAe,QAAO,MAAM;AACjC,SAAO,cAAc,SAAS,CAAC,UAAU;AACvC,UAAM,aAAa,SAAS,OAAO,SAAS;AAC5C,QAAI,oBAAoB,UAAU;AAAA,EACpC,CAAC;AACH;AAEA,eAAsB,UACpB,KACA,SACA,YAC6B;AAC7B,QAAM,YAAY,iBAAiB,QAAQ,WAAW,WAAW;AACjE,QAAM,UAAU,eAAe,QAAQ,SAAS,WAAW;AAC3D,MAAI,CAAC,YAAA,KAAiB,SAAS,GAAG,EAAG,QAAO;AAE5C,QAAM,OAAO,QAAQ,KAAK,IAAI,CAAC,QAAQ;AACrC,UAAM,EAAE,SAAS,KAAA,IAAS,eAAe,KAAK,EAAE,SAAS,IAAI,SAAS,SAAS,KAAK,IAAI,MAAM;AAC9F,WAAO,EAAE,SAAS,MAAM,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 = {\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,K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,QAAM,UAAU,OAAO,UAAU,OAAO,YAAA;AACxC,MAAI,CAAC,cAAc,SAAS,MAAM,GAAG;AACnC,UAAM,IAAI,MAAM,8DAA8D,OAAO,YAAA,CAAa,wBAAwB;AAAA,EAC5H;AACA,QAAM,OAAgB,OAAO;AAC7B,MAAI,gBAAgB,YAAY,gBAAgB,QAAQ,gBAAgB,eAAe,YAAY,OAAO,IAAI,GAAG;AAC/G,UAAM,IAAI,MAAM,uFAAuF;AAAA,EACzG;AACA,SAAO,YAAA;AACT;
|
|
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 /** Os cabeçalhos guardados com a escrita (nunca o token). */\r\n headers?: Record<string, string>\r\n /** O que vai ser enviado. */\r\n body?: unknown\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,MAAM,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,QAAQ,OAAO;AAAA,MACf;AAAA,MACA,SAAS,c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,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;"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useRef, useEffect } from "react";
|
|
2
|
+
import { useState, useRef, useEffect, useCallback } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
4
|
import { useOfflineBoxes } from "../../../capabilities/onepoint-rn/useOfflineBoxes.js";
|
|
5
|
+
import { readInbox } from "../../../capabilities/onepoint-rn/connectInbox.js";
|
|
5
6
|
import { useDialogContainer } from "../../overlays/Dialog/Dialog.js";
|
|
6
7
|
import { OfflineBoxesIcon } from "./OfflineBoxesIcon.js";
|
|
7
|
-
import OfflineBoxesView, { DEFAULT_OFFLINE_BOXES_LABELS, percentOf, toSendOf, filled } from "./OfflineBoxesView.js";
|
|
8
|
+
import OfflineBoxesView, { DEFAULT_OFFLINE_BOXES_LABELS, percentOf, toSendOf, INBOX_GREEN, OfflineArrow, OUTBOX_ORANGE, filled } from "./OfflineBoxesView.js";
|
|
9
|
+
function addressAndPathOf(path, address) {
|
|
10
|
+
if (/^https?:\/\//.test(path)) {
|
|
11
|
+
const url = new URL(path);
|
|
12
|
+
return { address: url.origin, path: url.pathname + url.search };
|
|
13
|
+
}
|
|
14
|
+
const base = new URL(address ?? "/", window.location.href).href.replace(/\/$/, "");
|
|
15
|
+
return { address: base, path };
|
|
16
|
+
}
|
|
8
17
|
function OfflineBoxes({ storageId, inboxIds, onRefresh, address, subtitle, describeSaved, describeWrite, labels, className = "" }) {
|
|
9
18
|
const L = { ...DEFAULT_OFFLINE_BOXES_LABELS, ...labels };
|
|
10
19
|
const state = useOfflineBoxes({ storageId, inboxIds });
|
|
@@ -25,6 +34,7 @@ function OfflineBoxes({ storageId, inboxIds, onRefresh, address, subtitle, descr
|
|
|
25
34
|
document.addEventListener("keydown", escape);
|
|
26
35
|
return () => document.removeEventListener("keydown", escape);
|
|
27
36
|
}, [open]);
|
|
37
|
+
const readSaved = useCallback((path) => readInbox({ storageId, ...addressAndPathOf(path, address) }), [storageId, address]);
|
|
28
38
|
if (!state) return null;
|
|
29
39
|
const pct = percentOf(state);
|
|
30
40
|
const pctLabel = pct === null ? "–" : `${pct}%`;
|
|
@@ -37,17 +47,30 @@ function OfflineBoxes({ storageId, inboxIds, onRefresh, address, subtitle, descr
|
|
|
37
47
|
type: "button",
|
|
38
48
|
"aria-haspopup": "dialog",
|
|
39
49
|
"aria-expanded": open,
|
|
40
|
-
"aria-label": `${L.title}: ${pctLabel} · ${filled(L.toSend, { n: toSend })}`,
|
|
50
|
+
"aria-label": `${L.title}: ${L.saved} ${pctLabel} · ${filled(L.toSend, { n: toSend })}`,
|
|
41
51
|
onClick: (e) => {
|
|
42
52
|
e.stopPropagation();
|
|
43
53
|
setOpen(true);
|
|
44
54
|
},
|
|
45
|
-
className: "flex min-h-11 cursor-pointer items-center gap-1.5 rounded-
|
|
55
|
+
className: "flex min-h-11 cursor-pointer items-center gap-1.5 rounded-full border-0 bg-transparent px-1 hover:bg-slate-100 dark:hover:bg-slate-800",
|
|
46
56
|
children: [
|
|
47
|
-
/* @__PURE__ */ jsx(OfflineBoxesIcon, { size:
|
|
48
|
-
/* @__PURE__ */ jsxs("span", { className: "flex
|
|
49
|
-
/* @__PURE__ */
|
|
50
|
-
|
|
57
|
+
/* @__PURE__ */ jsx(OfflineBoxesIcon, { size: 26 }),
|
|
58
|
+
/* @__PURE__ */ jsxs("span", { className: "flex h-7 items-stretch overflow-hidden rounded-full text-[11px] font-black whitespace-nowrap tabular-nums shadow-[0_1px_3px_rgba(0,27,99,0.18)]", children: [
|
|
59
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-0.5 pr-1.5 pl-2 text-white", style: { background: INBOX_GREEN }, children: [
|
|
60
|
+
/* @__PURE__ */ jsx(OfflineArrow, {}),
|
|
61
|
+
pctLabel
|
|
62
|
+
] }),
|
|
63
|
+
/* @__PURE__ */ jsxs(
|
|
64
|
+
"span",
|
|
65
|
+
{
|
|
66
|
+
className: `flex items-center gap-0.5 pr-2 pl-1.5 ${toSend > 0 ? "text-white" : "bg-slate-100 text-slate-500 dark:bg-slate-800 dark:text-slate-400"}`,
|
|
67
|
+
style: toSend > 0 ? { background: OUTBOX_ORANGE } : void 0,
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ jsx(OfflineArrow, { up: true }),
|
|
70
|
+
toSend
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
)
|
|
51
74
|
] })
|
|
52
75
|
]
|
|
53
76
|
}
|
|
@@ -63,7 +86,8 @@ function OfflineBoxes({ storageId, inboxIds, onRefresh, address, subtitle, descr
|
|
|
63
86
|
onRefresh,
|
|
64
87
|
onBack: close,
|
|
65
88
|
describeSaved,
|
|
66
|
-
describeWrite
|
|
89
|
+
describeWrite,
|
|
90
|
+
readSaved
|
|
67
91
|
}
|
|
68
92
|
),
|
|
69
93
|
dialogContainer ?? document.body
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OfflineBoxes.js","sources":["../../../../../../src/v1/components/feedback/OfflineBoxes/OfflineBoxes.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\r\nimport { createPortal } from 'react-dom'\r\nimport { useOfflineBoxes } from '../../../capabilities/onepoint-rn/useOfflineBoxes'\r\nimport { useDialogContainer } from '../../overlays/Dialog/Dialog'\r\nimport OfflineBoxesIcon from './OfflineBoxesIcon'\r\nimport OfflineBoxesView, {\r\n DEFAULT_OFFLINE_BOXES_LABELS,\r\n filled,\r\n percentOf,\r\n toSendOf,\r\n type OfflineBoxesLabels,\r\n type OfflineSavedSummary,\r\n type OfflineWrite,\r\n type OfflineWriteDescription,\r\n} from './OfflineBoxesView'\r\n\r\nexport {\r\n DEFAULT_OFFLINE_BOXES_LABELS,\r\n type OfflineBoxesLabels,\r\n type OfflineSavedItem,\r\n type OfflineSavedSummary,\r\n type OfflineSavedTag,\r\n type OfflineWrite,\r\n type OfflineWriteDescription,\r\n} from './OfflineBoxesView'\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`): os endereços chegam ao `describeSaved` e ao `describeWrite` sem ele à frente. */\r\n address?: string\r\n /** Linha ao lado do título na vista (ex: o nome do ecrã). */\r\n subtitle?: string\r\n /** Transforma os endereços guardados nas linhas que se mostram (ex: uma por OT). Sem ele, mostra os endereços. */\r\n describeSaved?: (paths: string[]) => OfflineSavedSummary\r\n /** Diz o que é cada escrita por enviar (ex: \"Ajuste guardado\"). Sem ele, ou se devolver `null`, mostra método e endereço. */\r\n describeWrite?: (write: OfflineWrite) => OfflineWriteDescription | null\r\n labels?: Partial<OfflineBoxesLabels>\r\n className?: string\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
|
|
1
|
+
{"version":3,"file":"OfflineBoxes.js","sources":["../../../../../../src/v1/components/feedback/OfflineBoxes/OfflineBoxes.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react'\r\nimport { createPortal } from 'react-dom'\r\nimport { useOfflineBoxes } from '../../../capabilities/onepoint-rn/useOfflineBoxes'\r\nimport { readInbox } from '../../../capabilities/onepoint-rn/connectInbox'\r\nimport { useDialogContainer } from '../../overlays/Dialog/Dialog'\r\nimport OfflineBoxesIcon from './OfflineBoxesIcon'\r\nimport OfflineBoxesView, {\r\n DEFAULT_OFFLINE_BOXES_LABELS,\r\n INBOX_GREEN,\r\n OUTBOX_ORANGE,\r\n OfflineArrow,\r\n filled,\r\n percentOf,\r\n toSendOf,\r\n type OfflineBoxesLabels,\r\n type OfflineSavedSummary,\r\n type OfflineWrite,\r\n type OfflineWriteDescription,\r\n} from './OfflineBoxesView'\r\n\r\nexport {\r\n DEFAULT_OFFLINE_BOXES_LABELS,\r\n type OfflineBoxesLabels,\r\n type OfflineSavedItem,\r\n type OfflineSavedPart,\r\n type OfflineSavedSummary,\r\n type OfflineSavedTag,\r\n type OfflineWrite,\r\n type OfflineWriteDescription,\r\n} from './OfflineBoxesView'\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`): os endereços chegam ao `describeSaved` e ao `describeWrite` sem ele à frente. */\r\n address?: string\r\n /** Linha ao lado do título na vista (ex: o nome do ecrã). */\r\n subtitle?: string\r\n /** Transforma os endereços guardados nas linhas que se mostram (ex: uma por OT). Sem ele, mostra os endereços. */\r\n describeSaved?: (paths: string[]) => OfflineSavedSummary\r\n /** Diz o que é cada escrita por enviar (ex: \"Ajuste guardado\"). Sem ele, ou se devolver `null`, mostra método e endereço. */\r\n describeWrite?: (write: OfflineWrite) => OfflineWriteDescription | null\r\n labels?: Partial<OfflineBoxesLabels>\r\n className?: string\r\n}\r\n\r\n/** Um endereço guardado partido no que a app pede: o endereço da API por inteiro e o resto. */\r\nfunction addressAndPathOf(path: string, address: string | undefined): { address: string; path: string } {\r\n if (/^https?:\\/\\//.test(path)) {\r\n const url = new URL(path)\r\n return { address: url.origin, path: url.pathname + url.search }\r\n }\r\n const base = new URL(address ?? '/', window.location.href).href.replace(/\\/$/, '')\r\n return { address: base, path }\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 botão que se põe onde se quiser (ex: à\r\n * direita do título): o ícone e uma pílula com duas metades, a percentagem\r\n * guardada (sobe enquanto a descarga corre) e quantas escritas faltam enviar. Tocar abre a vista inteira\r\n * com o detalhe; nela, tocar numa linha guardada mostra o que está guardado\r\n * por inteiro (JSON). Fora da app OnePoint não aparece.\r\n */\r\nexport default function OfflineBoxes({ storageId, inboxIds, onRefresh, address, subtitle, describeSaved, describeWrite, labels, className = '' }: OfflineBoxesProps) {\r\n const L = { ...DEFAULT_OFFLINE_BOXES_LABELS, ...labels }\r\n const state = useOfflineBoxes({ storageId, inboxIds })\r\n const [open, setOpen] = useState(false)\r\n const triggerRef = useRef<HTMLButtonElement>(null)\r\n const dialogContainer = useDialogContainer()\r\n\r\n const close = () => {\r\n setOpen(false)\r\n triggerRef.current?.focus()\r\n }\r\n\r\n useEffect(() => {\r\n if (!open) return\r\n const escape = (e: KeyboardEvent) => {\r\n if (e.key !== 'Escape') return\r\n setOpen(false)\r\n triggerRef.current?.focus()\r\n }\r\n document.addEventListener('keydown', escape)\r\n return () => document.removeEventListener('keydown', escape)\r\n }, [open])\r\n\r\n const readSaved = useCallback((path: string) => readInbox({ storageId, ...addressAndPathOf(path, address) }), [storageId, address])\r\n\r\n if (!state) return null\r\n\r\n const pct = percentOf(state)\r\n const pctLabel = pct === null ? '–' : `${pct}%`\r\n const toSend = toSendOf(state)\r\n\r\n return (\r\n <div className={`relative inline-flex shrink-0 ${className}`}>\r\n <button\r\n ref={triggerRef}\r\n type=\"button\"\r\n aria-haspopup=\"dialog\"\r\n aria-expanded={open}\r\n aria-label={`${L.title}: ${L.saved} ${pctLabel} · ${filled(L.toSend, { n: toSend })}`}\r\n onClick={(e) => {\r\n e.stopPropagation()\r\n setOpen(true)\r\n }}\r\n className=\"flex min-h-11 cursor-pointer items-center gap-1.5 rounded-full border-0 bg-transparent px-1 hover:bg-slate-100 dark:hover:bg-slate-800\"\r\n >\r\n <OfflineBoxesIcon size={26} />\r\n <span className=\"flex h-7 items-stretch overflow-hidden rounded-full text-[11px] font-black whitespace-nowrap tabular-nums shadow-[0_1px_3px_rgba(0,27,99,0.18)]\">\r\n <span className=\"flex items-center gap-0.5 pr-1.5 pl-2 text-white\" style={{ background: INBOX_GREEN }}>\r\n <OfflineArrow />\r\n {pctLabel}\r\n </span>\r\n <span\r\n className={`flex items-center gap-0.5 pr-2 pl-1.5 ${toSend > 0 ? 'text-white' : 'bg-slate-100 text-slate-500 dark:bg-slate-800 dark:text-slate-400'}`}\r\n style={toSend > 0 ? { background: OUTBOX_ORANGE } : undefined}\r\n >\r\n <OfflineArrow up />\r\n {toSend}\r\n </span>\r\n </span>\r\n </button>\r\n {open &&\r\n createPortal(\r\n <OfflineBoxesView\r\n state={state}\r\n labels={L}\r\n subtitle={subtitle}\r\n address={address}\r\n onRefresh={onRefresh}\r\n onBack={close}\r\n describeSaved={describeSaved}\r\n describeWrite={describeWrite}\r\n readSaved={readSaved}\r\n />,\r\n dialogContainer ?? document.body,\r\n )}\r\n </div>\r\n )\r\n}\r\n\r\nexport { OfflineBoxes }\r\n"],"names":[],"mappings":";;;;;;;;AAmDA,SAAS,iBAAiB,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