@eifi1/ui-kit 0.45.0 → 0.46.1

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.
Files changed (238) hide show
  1. package/README.md +26 -14
  2. package/dist/admin/admin-area-labels.d.ts +9 -0
  3. package/dist/admin/admin-area-labels.js +5 -1
  4. package/dist/admin/admin-area-labels.js.map +1 -1
  5. package/dist/admin/admin-overview.d.ts +16 -1
  6. package/dist/admin/admin-overview.js +12 -1
  7. package/dist/admin/admin-overview.js.map +1 -1
  8. package/dist/admin/mail-test-card.d.ts +3 -2
  9. package/dist/admin/mail-test-card.js +3 -1
  10. package/dist/admin/mail-test-card.js.map +1 -1
  11. package/dist/admin/user-roster.d.ts +6 -2
  12. package/dist/admin/user-roster.js +7 -3
  13. package/dist/admin/user-roster.js.map +1 -1
  14. package/dist/components/appearance-labels.d.ts +10 -0
  15. package/dist/components/appearance-labels.js +6 -1
  16. package/dist/components/appearance-labels.js.map +1 -1
  17. package/dist/components/data-table-column-settings.js +2 -2
  18. package/dist/components/data-table-column-settings.js.map +1 -1
  19. package/dist/components/data-table-head.js +2 -2
  20. package/dist/components/data-table-head.js.map +1 -1
  21. package/dist/components/data-table-row-actions.d.ts +35 -2
  22. package/dist/components/data-table-row-actions.js +98 -5
  23. package/dist/components/data-table-row-actions.js.map +1 -1
  24. package/dist/components/data-table-shared.js +9 -2
  25. package/dist/components/data-table-shared.js.map +1 -1
  26. package/dist/components/data-table.d.ts +58 -2
  27. package/dist/components/data-table.js +11 -4
  28. package/dist/components/data-table.js.map +1 -1
  29. package/dist/components/date-format-setting.d.ts +29 -0
  30. package/dist/components/date-format-setting.js +36 -0
  31. package/dist/components/date-format-setting.js.map +1 -0
  32. package/dist/components/row-actions.d.ts +12 -5
  33. package/dist/components/row-actions.js +11 -4
  34. package/dist/components/row-actions.js.map +1 -1
  35. package/dist/components/swipeable-row.d.ts +8 -0
  36. package/dist/components/swipeable-row.js.map +1 -1
  37. package/dist/components/tabs.d.ts +3 -2
  38. package/dist/components/tabs.js +1 -1
  39. package/dist/components/tabs.js.map +1 -1
  40. package/dist/components/translation-review-editor.js +1 -0
  41. package/dist/components/translation-review-editor.js.map +1 -1
  42. package/dist/components/translation-review-labels.d.ts +5 -0
  43. package/dist/components/translation-review-labels.js +2 -0
  44. package/dist/components/translation-review-labels.js.map +1 -1
  45. package/dist/components/translation-review.d.ts +18 -8
  46. package/dist/components/translation-review.js +67 -8
  47. package/dist/components/translation-review.js.map +1 -1
  48. package/dist/components/write-lock-labels.js +2 -1
  49. package/dist/components/write-lock-labels.js.map +1 -1
  50. package/dist/components/write-lock.d.ts +33 -3
  51. package/dist/components/write-lock.js +9 -0
  52. package/dist/components/write-lock.js.map +1 -1
  53. package/dist/data-table.d.ts +2 -1
  54. package/dist/data-table.js +2 -0
  55. package/dist/data-table.js.map +1 -1
  56. package/dist/eslint/index.js +1 -1
  57. package/dist/feedback/feedback-row-detail.d.ts +4 -2
  58. package/dist/feedback/feedback-row-detail.js +17 -26
  59. package/dist/feedback/feedback-row-detail.js.map +1 -1
  60. package/dist/feedback/feedback-swipe.d.ts +18 -0
  61. package/dist/feedback/feedback-swipe.js +10 -1
  62. package/dist/feedback/feedback-swipe.js.map +1 -1
  63. package/dist/i18n/german.js +41 -5
  64. package/dist/i18n/german.js.map +1 -1
  65. package/dist/i18n/kit-labels.d.ts +12 -1
  66. package/dist/i18n/kit-labels.js +8 -2
  67. package/dist/i18n/kit-labels.js.map +1 -1
  68. package/dist/i18n/locales/en.js +40 -6
  69. package/dist/i18n/locales/en.js.map +2 -2
  70. package/dist/i18n/locales/es.js +41 -5
  71. package/dist/i18n/locales/es.js.map +1 -1
  72. package/dist/i18n/locales/fr.js +41 -5
  73. package/dist/i18n/locales/fr.js.map +1 -1
  74. package/dist/i18n/locales/hu.js +41 -5
  75. package/dist/i18n/locales/hu.js.map +1 -1
  76. package/dist/i18n/locales/it.js +41 -5
  77. package/dist/i18n/locales/it.js.map +1 -1
  78. package/dist/i18n/locales/zh.js +41 -5
  79. package/dist/i18n/locales/zh.js.map +1 -1
  80. package/dist/i18n/review.js +3 -1
  81. package/dist/i18n/review.js.map +1 -1
  82. package/dist/index.d.ts +17 -4
  83. package/dist/index.js +38 -1
  84. package/dist/index.js.map +1 -1
  85. package/dist/lib/date-format.d.ts +81 -0
  86. package/dist/lib/date-format.js +56 -0
  87. package/dist/lib/date-format.js.map +1 -0
  88. package/dist/lib/format.d.ts +3 -0
  89. package/dist/lib/format.js +5 -4
  90. package/dist/lib/format.js.map +1 -1
  91. package/dist/notifications/device-zone-report.d.ts +34 -0
  92. package/dist/notifications/device-zone-report.js +31 -0
  93. package/dist/notifications/device-zone-report.js.map +1 -0
  94. package/dist/notifications/feedback-notification-types-labels.d.ts +7 -1
  95. package/dist/notifications/feedback-notification-types-labels.js +4 -1
  96. package/dist/notifications/feedback-notification-types-labels.js.map +1 -1
  97. package/dist/notifications/feedback-notification-types.d.ts +24 -5
  98. package/dist/notifications/feedback-notification-types.js +7 -2
  99. package/dist/notifications/feedback-notification-types.js.map +1 -1
  100. package/dist/notifications/notification-bell.d.ts +33 -0
  101. package/dist/notifications/notification-bell.js +74 -0
  102. package/dist/notifications/notification-bell.js.map +1 -0
  103. package/dist/notifications/notification-inbox.d.ts +86 -0
  104. package/dist/notifications/notification-inbox.js +206 -0
  105. package/dist/notifications/notification-inbox.js.map +1 -0
  106. package/dist/notifications/notification-types-setting.d.ts +6 -4
  107. package/dist/notifications/notification-types-setting.js +103 -45
  108. package/dist/notifications/notification-types-setting.js.map +1 -1
  109. package/dist/notifications/notification-types.d.ts +19 -7
  110. package/dist/notifications/notifications-labels.d.ts +44 -8
  111. package/dist/notifications/notifications-labels.js +18 -1
  112. package/dist/notifications/notifications-labels.js.map +1 -1
  113. package/dist/notifications/push-devices-setting.d.ts +20 -3
  114. package/dist/notifications/push-devices-setting.js +93 -33
  115. package/dist/notifications/push-devices-setting.js.map +1 -1
  116. package/dist/notifications/push-worker.d.ts +108 -0
  117. package/dist/notifications/push-worker.js +62 -0
  118. package/dist/notifications/push-worker.js.map +1 -0
  119. package/dist/notifications/quiet-hours-setting.d.ts +29 -17
  120. package/dist/notifications/quiet-hours-setting.js +9 -41
  121. package/dist/notifications/quiet-hours-setting.js.map +1 -1
  122. package/dist/notifications/time-zone-select.d.ts +8 -4
  123. package/dist/notifications/time-zone-select.js +2 -7
  124. package/dist/notifications/time-zone-select.js.map +1 -1
  125. package/dist/notifications/use-push-device.d.ts +4 -17
  126. package/dist/notifications/use-push-device.js +7 -15
  127. package/dist/notifications/use-push-device.js.map +1 -1
  128. package/dist/offline/local-first.d.ts +42 -0
  129. package/dist/offline/local-first.js +53 -0
  130. package/dist/offline/local-first.js.map +1 -0
  131. package/dist/offline/query-persistence.d.ts +26 -1
  132. package/dist/offline/query-persistence.js +27 -23
  133. package/dist/offline/query-persistence.js.map +1 -1
  134. package/dist/offline/service-worker-updates.d.ts +46 -0
  135. package/dist/offline/service-worker-updates.js +39 -0
  136. package/dist/offline/service-worker-updates.js.map +1 -0
  137. package/dist/offline.d.ts +5 -2
  138. package/dist/offline.js +12 -2
  139. package/dist/offline.js.map +1 -1
  140. package/dist/push-worker.d.ts +2 -0
  141. package/dist/push-worker.js +14 -0
  142. package/dist/push-worker.js.map +1 -0
  143. package/dist/shell/account-menu-text-size.d.ts +33 -0
  144. package/dist/shell/account-menu-text-size.js +51 -0
  145. package/dist/shell/account-menu-text-size.js.map +1 -0
  146. package/dist/shell/top-bar-actions.d.ts +6 -2
  147. package/dist/shell/top-bar-actions.js +1 -0
  148. package/dist/shell/top-bar-actions.js.map +1 -1
  149. package/dist/shell.d.ts +2 -0
  150. package/dist/shell.js +2 -0
  151. package/dist/shell.js.map +1 -1
  152. package/dist/sync/db.d.ts +93 -0
  153. package/dist/sync/db.js +33 -0
  154. package/dist/sync/db.js.map +1 -0
  155. package/dist/sync/engine.d.ts +126 -0
  156. package/dist/sync/engine.js +474 -0
  157. package/dist/sync/engine.js.map +1 -0
  158. package/dist/sync/hooks.d.ts +35 -0
  159. package/dist/sync/hooks.js +67 -0
  160. package/dist/sync/hooks.js.map +1 -0
  161. package/dist/sync/testing.d.ts +28 -0
  162. package/dist/sync/testing.js +41 -0
  163. package/dist/sync/testing.js.map +1 -0
  164. package/dist/sync/wire.d.ts +50 -0
  165. package/dist/sync/wire.js +2 -0
  166. package/dist/sync/wire.js.map +1 -0
  167. package/dist/sync.d.ts +7 -0
  168. package/dist/sync.js +25 -0
  169. package/dist/sync.js.map +1 -0
  170. package/dist/tour/tour-labels.js +1 -0
  171. package/dist/tour/tour-labels.js.map +1 -1
  172. package/dist/tour/tour.d.ts +30 -0
  173. package/dist/tour/tour.js +50 -6
  174. package/dist/tour/tour.js.map +1 -1
  175. package/package.json +19 -1
  176. package/src/admin/admin-area-labels.ts +13 -0
  177. package/src/admin/admin-overview.tsx +37 -2
  178. package/src/admin/mail-test-card.tsx +7 -3
  179. package/src/admin/user-roster.tsx +12 -3
  180. package/src/components/appearance-labels.ts +16 -0
  181. package/src/components/data-table-column-settings.tsx +2 -2
  182. package/src/components/data-table-head.tsx +2 -2
  183. package/src/components/data-table-row-actions.tsx +145 -5
  184. package/src/components/data-table-shared.tsx +21 -2
  185. package/src/components/data-table.tsx +68 -6
  186. package/src/components/date-format-setting.tsx +64 -0
  187. package/src/components/row-actions.tsx +33 -9
  188. package/src/components/swipeable-row.tsx +8 -0
  189. package/src/components/tabs.tsx +4 -3
  190. package/src/components/translation-review-editor.tsx +2 -0
  191. package/src/components/translation-review-labels.ts +7 -0
  192. package/src/components/translation-review.tsx +105 -15
  193. package/src/components/write-lock-labels.ts +1 -0
  194. package/src/components/write-lock.tsx +36 -3
  195. package/src/data-table.ts +4 -0
  196. package/src/feedback/feedback-row-detail.tsx +18 -23
  197. package/src/feedback/feedback-swipe.tsx +28 -1
  198. package/src/i18n/german.ts +44 -4
  199. package/src/i18n/kit-labels.tsx +18 -1
  200. package/src/i18n/locales/en.ts +1 -0
  201. package/src/i18n/locales/es.ts +44 -4
  202. package/src/i18n/locales/fr.ts +44 -4
  203. package/src/i18n/locales/hu.ts +44 -4
  204. package/src/i18n/locales/it.ts +44 -4
  205. package/src/i18n/locales/zh.ts +44 -2
  206. package/src/i18n/review.ts +3 -1
  207. package/src/index.ts +50 -1
  208. package/src/lib/date-format.ts +151 -0
  209. package/src/lib/format.ts +10 -4
  210. package/src/notifications/device-zone-report.ts +67 -0
  211. package/src/notifications/feedback-notification-types-labels.ts +10 -1
  212. package/src/notifications/feedback-notification-types.ts +30 -5
  213. package/src/notifications/notification-bell.tsx +116 -0
  214. package/src/notifications/notification-inbox.tsx +314 -0
  215. package/src/notifications/notification-types-setting.tsx +151 -55
  216. package/src/notifications/notification-types.ts +20 -8
  217. package/src/notifications/notifications-labels.ts +72 -12
  218. package/src/notifications/push-devices-setting.tsx +123 -34
  219. package/src/notifications/push-worker.ts +160 -0
  220. package/src/notifications/quiet-hours-setting.tsx +41 -58
  221. package/src/notifications/time-zone-select.tsx +9 -10
  222. package/src/notifications/use-push-device.ts +20 -33
  223. package/src/offline/local-first.ts +100 -0
  224. package/src/offline/query-persistence.ts +57 -24
  225. package/src/offline/service-worker-updates.ts +81 -0
  226. package/src/offline.ts +7 -1
  227. package/src/push-worker.ts +25 -0
  228. package/src/shell/account-menu-text-size.tsx +77 -0
  229. package/src/shell/top-bar-actions.tsx +6 -1
  230. package/src/shell.ts +3 -0
  231. package/src/sync/db.ts +125 -0
  232. package/src/sync/engine.ts +701 -0
  233. package/src/sync/hooks.ts +98 -0
  234. package/src/sync/testing.ts +73 -0
  235. package/src/sync/wire.ts +61 -0
  236. package/src/sync.ts +29 -0
  237. package/src/tour/tour-labels.ts +1 -0
  238. package/src/tour/tour.tsx +100 -7
@@ -0,0 +1,98 @@
1
+ import { useCallback, useEffect, useState, useSyncExternalStore } from "react";
2
+ import { liveQuery } from "dexie";
3
+ import type { SyncStatus } from "../shell/sync-status-indicator";
4
+ import type { SyncDb } from "./db";
5
+ import type { SyncEngine, SyncEngineState } from "./engine";
6
+
7
+ /**
8
+ * Keep `engine` running while it is mounted: started on mount, stopped on unmount or when
9
+ * the engine changes (a company switch builds a new engine on its own database, D15).
10
+ * `null` runs nothing — signed out, or a computer marked shared. Mount once, in the
11
+ * signed-in layout (kastlan's `useHandoverSyncLoop`).
12
+ */
13
+ export function useSyncWorker(engine: SyncEngine | null): void {
14
+ useEffect(() => {
15
+ if (!engine) return;
16
+ engine.start();
17
+ return () => engine.stop();
18
+ }, [engine]);
19
+ }
20
+
21
+ const IDLE: SyncEngineState = {
22
+ phase: "idle",
23
+ online: true,
24
+ counts: { pending: 0, waiting: 0, blocked: 0, rejected: 0 },
25
+ lastSyncedAt: null,
26
+ nextRetryAt: null,
27
+ };
28
+ const noEngine = () => () => undefined;
29
+ const idle = () => IDLE;
30
+
31
+ /**
32
+ * The engine's state as the kit's `SyncStatusIndicator` reads it (§2.3): `pending` = queued
33
+ * and in flight (and the steps' pending), `waitingForPlan` = `waiting`, `blocked` = `blocked`
34
+ * + `rejected`, `lastSyncedAt` from `meta`. `onSync` is "Sync now". Without an engine, an
35
+ * idle status that follows the browser's connection.
36
+ *
37
+ * With a `null` engine (signed out, or a computer marked shared) `status.online` follows
38
+ * `navigator.onLine` and its `online`/`offline` events, so an app may lean on
39
+ * `status.online` for its own offline lock (kastlan's offline write lock) whether or not an
40
+ * engine runs.
41
+ */
42
+ export function useSyncStatus(engine: SyncEngine | null): { status: SyncStatus; onSync: () => Promise<void> } {
43
+ const state = useSyncExternalStore(
44
+ engine ? engine.subscribe : noEngine,
45
+ engine ? engine.getState : idle,
46
+ engine ? engine.getState : idle,
47
+ );
48
+ const browserOnline = useSyncExternalStore(subscribeOnline, readOnline, () => true);
49
+ const onSync = useCallback(async () => {
50
+ await engine?.syncNow();
51
+ }, [engine]);
52
+ const status: SyncStatus = {
53
+ phase: state.phase,
54
+ online: engine ? state.online : browserOnline,
55
+ pending: state.counts.pending,
56
+ waitingForPlan: state.counts.waiting,
57
+ blocked: state.counts.blocked + state.counts.rejected,
58
+ lastSyncedAt: state.lastSyncedAt,
59
+ };
60
+ return { status, onSync };
61
+ }
62
+
63
+ function subscribeOnline(listener: () => void) {
64
+ window.addEventListener("online", listener);
65
+ window.addEventListener("offline", listener);
66
+ return () => {
67
+ window.removeEventListener("online", listener);
68
+ window.removeEventListener("offline", listener);
69
+ };
70
+ }
71
+ const readOnline = () => navigator.onLine !== false;
72
+
73
+ /**
74
+ * A read of the copy that follows every change to it (Dexie's `liveQuery`; kastlan's
75
+ * `useLive`). `deps` names what `query` reads; `query` itself is rebuilt every render.
76
+ * `query` gets the app's own database type (`HandoverDb`). Without a database (not open
77
+ * yet) it answers `isLoading: true`, so a page shows no "empty" before the copy opens.
78
+ */
79
+ export function useSyncQuery<T, D extends SyncDb = SyncDb>(
80
+ db: D | null,
81
+ query: (db: D) => Promise<T>,
82
+ deps: readonly unknown[],
83
+ ): { data: T | undefined; isLoading: boolean } {
84
+ const [state, setState] = useState<{ data: T | undefined; isLoading: boolean }>({ data: undefined, isLoading: true });
85
+ useEffect(() => {
86
+ if (!db) return;
87
+ const subscription = liveQuery(() => query(db)).subscribe({
88
+ next: (data) => setState({ data, isLoading: false }),
89
+ error: () => setState({ data: undefined, isLoading: false }),
90
+ });
91
+ return () => subscription.unsubscribe();
92
+ // `query` is rebuilt every render; `deps` names what it reads.
93
+ // eslint-disable-next-line react-hooks/exhaustive-deps
94
+ }, [db, ...deps]);
95
+ return db ? state : NO_COPY;
96
+ }
97
+
98
+ const NO_COPY = { data: undefined, isLoading: true } as const;
@@ -0,0 +1,73 @@
1
+ import type { SyncRequestBody, SyncResponseBody } from "./wire";
2
+
3
+ /*
4
+ * `@eifi1/ui-kit/sync/testing` — a scripted `/sync` server for an app's tests of the engine
5
+ * (docs/local-first-harmonization.md §2.3). Pass `transport.send` as the engine's `send`.
6
+ * Imports nothing (no Dexie): it is the engine's `send`, not a store.
7
+ */
8
+
9
+ /** One scripted answer: a body, a function of the request, or a failure. */
10
+ export type FakeSyncAnswer =
11
+ | SyncResponseBody
12
+ | ((body: SyncRequestBody) => SyncResponseBody | Promise<SyncResponseBody>)
13
+ | { fail: "offline" }
14
+ | { fail: number; data?: unknown };
15
+
16
+ export interface FakeSyncTransport {
17
+ /** The engine's `send`. */
18
+ send(body: SyncRequestBody, signal?: AbortSignal): Promise<SyncResponseBody>;
19
+ /** Every request received, in order (the body as sent). */
20
+ readonly requests: SyncRequestBody[];
21
+ /** Queue answers for the next requests, in order; past them the default answers. */
22
+ answer(...answers: FakeSyncAnswer[]): void;
23
+ /** The next request meets no connection (an axios-like error with no response). */
24
+ failOffline(): void;
25
+ /** The next request answers `status` (a 5xx, a 402 `{code}`, a 403). */
26
+ failStatus(status: number, data?: unknown): void;
27
+ /** The default answer's server knowledge, raised by one for every request. */
28
+ knowledge: number;
29
+ }
30
+
31
+ /** The error an axios client throws: `isAxiosError`, and `response` only with an answer. */
32
+ function wireError(fail: "offline" | number, data?: unknown): Error {
33
+ const err = new Error(fail === "offline" ? "Network Error" : `Request failed with status code ${fail}`);
34
+ return Object.assign(err, {
35
+ isAxiosError: true,
36
+ response: fail === "offline" ? undefined : { status: fail, data: data ?? {} },
37
+ });
38
+ }
39
+
40
+ /**
41
+ * The default answer echoes every pushed change as applied, with a server id (`pk`, 100 on),
42
+ * and an empty pull besides; `knowledge` goes up by one each request. Script anything else
43
+ * with `answer(...)`, `failOffline()` and `failStatus(...)`.
44
+ */
45
+ export function createFakeSyncTransport(): FakeSyncTransport {
46
+ const script: FakeSyncAnswer[] = [];
47
+ let nextPk = 100;
48
+ const transport: FakeSyncTransport = {
49
+ requests: [],
50
+ knowledge: 0,
51
+ answer: (...answers) => void script.push(...answers),
52
+ failOffline: () => void script.push({ fail: "offline" }),
53
+ failStatus: (status, data) => void script.push({ fail: status, data }),
54
+ async send(body) {
55
+ transport.requests.push(structuredClone(body));
56
+ const next = script.shift();
57
+ if (next && typeof next === "object" && "fail" in next) {
58
+ throw wireError(next.fail, "data" in next ? next.data : undefined);
59
+ }
60
+ if (typeof next === "function") return next(body);
61
+ if (next) return next;
62
+ transport.knowledge += 1;
63
+ return {
64
+ server_knowledge: transport.knowledge,
65
+ changes: body.changes.map((change) => ({ ...change, pk: change.op === "delete" ? null : nextPk++ })),
66
+ rejections: [],
67
+ refused: null,
68
+ page_cursor: null,
69
+ };
70
+ },
71
+ };
72
+ return transport;
73
+ }
@@ -0,0 +1,61 @@
1
+ /*
2
+ * The `/sync` wire as the engine speaks it: server-kit's `eifi1_server_kit.sync` shapes
3
+ * (SyncRequest, SyncResponse, SyncRefusal, SyncRejection, SyncPageCursor; keksdose's, which
4
+ * are canon, D10), plus kastlan's `pk` on a pulled change. Types only.
5
+ */
6
+
7
+ /** One row's delta on the wire. */
8
+ export interface SyncWireChange {
9
+ entity: string;
10
+ id: string;
11
+ op: "upsert" | "delete";
12
+ data?: Record<string, unknown> | null;
13
+ /** The device's edit time on a push (D2). */
14
+ updated_at?: string | null;
15
+ /** The server's id of the row, on a pull (kastlan). */
16
+ pk?: number | null;
17
+ knowledge?: number | null;
18
+ }
19
+
20
+ /** Where a paged pull stopped (server-kit `SyncPageCursor`); handed back as it came. */
21
+ export interface SyncPageCursor {
22
+ entity: string;
23
+ knowledge?: number | null;
24
+ id?: string | null;
25
+ window_end: number;
26
+ }
27
+
28
+ export interface SyncRequestBody {
29
+ scope: string;
30
+ last_knowledge: number;
31
+ changes: SyncWireChange[];
32
+ /** This client keeps refused changes and reads `refused` and `rejections` (D1). */
33
+ refusals: true;
34
+ /** The device's clock as the body is built, fresh for every request (D2 amendment). */
35
+ client_now: string;
36
+ paged?: boolean;
37
+ page_cursor?: SyncPageCursor | null;
38
+ }
39
+
40
+ /** The WHOLE push refused (a lapsed plan): the pull is served all the same. */
41
+ export interface SyncRefusalBody {
42
+ code: string;
43
+ detail: string;
44
+ change_ids: string[];
45
+ }
46
+
47
+ /** One pushed change the server did not apply, with its reason. */
48
+ export interface SyncRejectionBody {
49
+ change_id: string;
50
+ code: string;
51
+ detail: string;
52
+ }
53
+
54
+ export interface SyncResponseBody {
55
+ server_knowledge: number;
56
+ changes: SyncWireChange[];
57
+ refused?: SyncRefusalBody | null;
58
+ rejections?: SyncRejectionBody[];
59
+ /** Set while the pull did not fit one page; `null` on the last page (D12). */
60
+ page_cursor?: SyncPageCursor | null;
61
+ }
package/src/sync.ts ADDED
@@ -0,0 +1,29 @@
1
+ // `@eifi1/ui-kit/sync` — local-first phase 3 (docs/local-first-harmonization.md §2.3, 0.46):
2
+ // the sync engine on a Dexie copy, its worker and status hooks, and the live read of the copy.
3
+ //
4
+ // The only entry point that imports `dexie` — an optional peer for that reason. It never loads
5
+ // `/offline`'s TanStack and idb-keyval peers: the leaf utilities both entries export live in
6
+ // one module of their own (src/offline/local-first.ts). NOT re-exported from the main barrel.
7
+ export { createSyncDb, rowByPk, SYNC_DB_PK_INDEX, SYNC_DB_STORES } from "./sync/db";
8
+ export type { CreateSyncDbOptions, OutboxChange, OutboxStatus, SyncDb, SyncDbUpgrade, SyncedRow, SyncMetaEntry } from "./sync/db";
9
+ export { createSyncEngine, DEFAULT_HOLD_CODES, DEFAULT_SYNC_BACKOFF_MS, releaseSyncEngine, syncEngineFor } from "./sync/engine";
10
+ export type {
11
+ SyncCounts,
12
+ SyncEngine,
13
+ SyncEngineOptions,
14
+ SyncEngineState,
15
+ SyncRoundResult,
16
+ SyncStep,
17
+ SyncStepContext,
18
+ SyncStepResult,
19
+ } from "./sync/engine";
20
+ export { useSyncQuery, useSyncStatus, useSyncWorker } from "./sync/hooks";
21
+ export type {
22
+ SyncPageCursor,
23
+ SyncRefusalBody,
24
+ SyncRejectionBody,
25
+ SyncRequestBody,
26
+ SyncResponseBody,
27
+ SyncWireChange,
28
+ } from "./sync/wire";
29
+ export { isOfflineError, readLocalFirst, stampAfter, uuid5, writeLocalFirst } from "./offline/local-first";
@@ -10,5 +10,6 @@ export const DEFAULT_TOUR_LABELS: TourLabels = {
10
10
  skip: "Skip",
11
11
  done: "Done",
12
12
  awaitClickHint: "Click the highlighted element to continue",
13
+ awaitInputHint: "Enter a value in the highlighted field to continue",
13
14
  step: (c, t) => `${c} / ${t}`,
14
15
  };
package/src/tour/tour.tsx CHANGED
@@ -48,6 +48,34 @@ export interface TourStep {
48
48
  * first, then the tour steps forward on a microtask. The spotlight hole stays
49
49
  * click-through to the target; the rest of the page does not. */
50
50
  awaitClick?: boolean;
51
+ /**
52
+ * The spotlighted control is for USING, not only for looking at (0.46, keksdose live
53
+ * #436): the layers it opens sit above the scrim and work. A plain step's overlay is
54
+ * `z-[60]`, over every kit layer, so a field whose number pad (`NumberPadSheet`), a
55
+ * select's menu or a popover opens at `z-50` opened UNDER the shields, where nothing
56
+ * could be tapped. Here the overlay drops to `z-[45]`: still over the top bar and the
57
+ * page (`z-40` and below, still dimmed and shielded), under every `z-50` layer the
58
+ * target opens — so an app's own layer wants `z-50` or more to clear it. Keys pressed
59
+ * in the target or in such a layer are theirs (Escape closes the pad, arrows walk a
60
+ * list); from the card the tour's keys work as on any step. The overlay is not
61
+ * `aria-modal` then, and carries `data-tour-interactive`.
62
+ *
63
+ * The card is in the same layer as the scrim, so an open pad or sheet may cover it
64
+ * until it closes. Requires `target`. A `HoverMenu` (`z-40`, the top bar's menus) stays
65
+ * under the scrim: point an `awaitClick` step at its trigger instead.
66
+ */
67
+ interactive?: boolean;
68
+ /**
69
+ * Advance once a value was ENTERED in the spotlighted control (0.46, keksdose live
70
+ * #436) — `awaitClick` for a field. Implies `interactive`. Counted when focus leaves
71
+ * the target (the number pad's Done, a Tab, a tap elsewhere), or Enter is pressed in
72
+ * it, and one of its fields (`input`, `textarea`, `select`: the target itself or
73
+ * inside it) then holds another value than when the step began; a native `change`
74
+ * (a select, a checkbox) counts at once. The card swaps Next for `awaitInputHint`,
75
+ * as for `awaitClick`. A picker whose value is not a field's (the kit's `Select`
76
+ * button) has nothing to compare: call `useTour().next()` from its `onChange`.
77
+ */
78
+ awaitInput?: boolean;
51
79
  /** Runs before the step is shown — e.g. navigate to a route, open a panel.
52
80
  * May be async; the step waits for it, then locates the target. */
53
81
  beforeStep?: () => void | Promise<void>;
@@ -60,6 +88,8 @@ export interface TourLabels {
60
88
  done: string;
61
89
  /** Shown in place of the Next button on an `awaitClick` step. */
62
90
  awaitClickHint: string;
91
+ /** Shown in place of the Next button on an `awaitInput` step (0.46). */
92
+ awaitInputHint: string;
63
93
  /** Step counter, e.g. (2, 7) => "2 / 7". */
64
94
  step: (current: number, total: number) => string;
65
95
  }
@@ -479,6 +509,48 @@ function TourOverlay({
479
509
  return () => el.removeEventListener("click", onClick);
480
510
  }, [ready, spotted, index, step, onNext]);
481
511
 
512
+ // An interactive step (see `TourStep.interactive`): only while the target is lit — a
513
+ // step whose target is missing centres its card over a full scrim, modal as ever.
514
+ const interactive = spotted && !!step.target && !!(step.interactive || step.awaitInput);
515
+
516
+ // awaitInput: advance once the target's fields hold another value than when the step
517
+ // was armed, checked when focus leaves the target or Enter is pressed in it — on the
518
+ // next macrotask, after the field's own blur/Enter commit has rendered. A value the
519
+ // number pad typed fires no native `change`, so comparing is what catches it.
520
+ useEffect(() => {
521
+ if (!ready || !spotted || !step.awaitInput || !step.target) return;
522
+ const el = queryVisibleTarget(step.target) as HTMLElement | null;
523
+ if (!el) return;
524
+ const read = () => fieldValues(el);
525
+ const before = read();
526
+ let timer = 0;
527
+ let done = false;
528
+ const check = () => {
529
+ window.clearTimeout(timer);
530
+ timer = window.setTimeout(() => {
531
+ if (done || read() === before) return;
532
+ done = true;
533
+ onNext();
534
+ }, 0);
535
+ };
536
+ const onFocusOut = (e: FocusEvent) => {
537
+ if (e.relatedTarget instanceof Node && el.contains(e.relatedTarget)) return;
538
+ check();
539
+ };
540
+ const onKeyDown = (e: KeyboardEvent) => {
541
+ if (e.key === "Enter") check();
542
+ };
543
+ el.addEventListener("focusout", onFocusOut);
544
+ el.addEventListener("keydown", onKeyDown);
545
+ el.addEventListener("change", check);
546
+ return () => {
547
+ window.clearTimeout(timer);
548
+ el.removeEventListener("focusout", onFocusOut);
549
+ el.removeEventListener("keydown", onKeyDown);
550
+ el.removeEventListener("change", check);
551
+ };
552
+ }, [ready, spotted, index, step, onNext]);
553
+
482
554
  // Keyboard: Esc skips, Enter and the reading-direction arrow advance (→ in LTR,
483
555
  // ← in RTL), the other arrow goes back. On awaitClick steps Enter is ignored (it
484
556
  // would fire the target's click AND advance) — the forward arrow stays as an escape
@@ -490,12 +562,18 @@ function TourOverlay({
490
562
  // The same goes for arrows in a text field a step's `action` might contain.
491
563
  useEffect(() => {
492
564
  const onKey = (e: KeyboardEvent) => {
565
+ // On an interactive step a key pressed in the target, or in a layer it opened (the
566
+ // number pad's Escape, a menu's arrows), is the page's. The card's and the bare
567
+ // page's (focus on <body>) stay the tour's.
568
+ if (interactive && e.target instanceof Node && e.target !== document.body && !rootRef.current?.contains(e.target)) {
569
+ return;
570
+ }
493
571
  if (e.key === "Escape") {
494
572
  onSkip();
495
573
  return;
496
574
  }
497
575
  if (e.key === "Enter") {
498
- if (step.awaitClick || ownsKey(e.target, "Enter")) return;
576
+ if (step.awaitClick || step.awaitInput || ownsKey(e.target, "Enter")) return;
499
577
  e.preventDefault();
500
578
  onNext();
501
579
  return;
@@ -512,7 +590,7 @@ function TourOverlay({
512
590
  };
513
591
  document.addEventListener("keydown", onKey);
514
592
  return () => document.removeEventListener("keydown", onKey);
515
- }, [isFirst, step, onNext, onPrev, onSkip]);
593
+ }, [isFirst, step, interactive, onNext, onPrev, onSkip]);
516
594
 
517
595
  if (!ready) return null;
518
596
 
@@ -532,9 +610,12 @@ function TourOverlay({
532
610
  return createPortal(
533
611
  <div
534
612
  ref={rootRef}
535
- className="pointer-events-none fixed inset-0 z-[60]"
613
+ // z-[45] on an interactive step: over the top bar (z-40), under the z-50 layers the
614
+ // target opens. See `TourStep.interactive`.
615
+ className={cn("pointer-events-none fixed inset-0", interactive ? "z-[45]" : "z-[60]")}
536
616
  role="dialog"
537
- aria-modal="true"
617
+ aria-modal={interactive ? undefined : "true"}
618
+ data-tour-interactive={interactive ? "" : undefined}
538
619
  aria-label={step.title}
539
620
  dir={dir}
540
621
  >
@@ -590,6 +671,18 @@ function TourOverlay({
590
671
  );
591
672
  }
592
673
 
674
+ /** The values of the fields at or inside `el`, as one string to compare (`awaitInput`). */
675
+ function fieldValues(el: Element): string {
676
+ const fields = el.matches("input,textarea,select") ? [el] : Array.from(el.querySelectorAll("input,textarea,select"));
677
+ return fields
678
+ .map((f) =>
679
+ f instanceof HTMLInputElement && (f.type === "checkbox" || f.type === "radio")
680
+ ? String(f.checked)
681
+ : (f as HTMLInputElement).value,
682
+ )
683
+ .join("\u0000");
684
+ }
685
+
593
686
  /** Does the focused element handle `key` itself? Enter on a button or link, and any
594
687
  * editing key in a text field or select, is the control's — not the tour's. */
595
688
  function ownsKey(target: EventTarget | null, key: string): boolean {
@@ -792,16 +885,16 @@ function TourCard({
792
885
  way forward on any step whose anchor happens not to be rendered
793
886
  for this user (a guest sees no "add account" button), leaving the
794
887
  undocumented ArrowRight key as the sole escape. */}
795
- {!(step.awaitClick && step.target && rect) && (
888
+ {!((step.awaitClick || step.awaitInput) && step.target && rect) && (
796
889
  <Button variant="brand" onClick={onNext} className={cn("px-2.5 py-1 text-xs")}>
797
890
  {isLast ? labels.done : labels.next}
798
891
  </Button>
799
892
  )}
800
893
  </div>
801
894
  </div>
802
- {step.awaitClick && step.target && rect && (
895
+ {(step.awaitClick || step.awaitInput) && step.target && rect && (
803
896
  <div className="text-center text-xs italic text-placeholder">
804
- {labels.awaitClickHint}
897
+ {step.awaitInput && !step.awaitClick ? labels.awaitInputHint : labels.awaitClickHint}
805
898
  </div>
806
899
  )}
807
900
  </div>