@chelone/core 0.6.0 → 0.9.0

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 (255) hide show
  1. package/dist/assistant/assistant-session.d.ts +6 -0
  2. package/dist/assistant/assistant-session.js +204 -181
  3. package/dist/assistant/echo-transport.js +26 -29
  4. package/dist/assistant/http-transport.d.ts +10 -0
  5. package/dist/assistant/http-transport.js +98 -0
  6. package/dist/assistant/types.d.ts +1 -7
  7. package/dist/auth/access-control.d.ts +13 -5
  8. package/dist/auth/access-control.js +25 -21
  9. package/dist/auth/auth-options.d.ts +23 -17
  10. package/dist/auth/auth-options.js +82 -48
  11. package/dist/auth/permission-matrix.d.ts +12 -0
  12. package/dist/auth/permission-matrix.js +67 -0
  13. package/dist/auth/types.d.ts +14 -4
  14. package/dist/block-editor/block-document.d.ts +64 -0
  15. package/dist/block-editor/block-document.js +147 -0
  16. package/dist/block-editor/data-blocks.d.ts +63 -0
  17. package/dist/block-editor/data-blocks.js +117 -0
  18. package/dist/chart/chart-data.js +46 -44
  19. package/dist/command-menu/hotkey.js +58 -47
  20. package/dist/command-menu/recents.d.ts +4 -0
  21. package/dist/command-menu/recents.js +12 -11
  22. package/dist/command-menu/registry.d.ts +9 -5
  23. package/dist/command-menu/registry.js +36 -46
  24. package/dist/controller/calendar-dates.d.ts +12 -0
  25. package/dist/controller/calendar-dates.js +94 -113
  26. package/dist/controller/calendar-events.js +93 -88
  27. package/dist/controller/client-list-controller.d.ts +2 -2
  28. package/dist/controller/client-list-controller.js +251 -254
  29. package/dist/controller/data-table-columns.d.ts +2 -0
  30. package/dist/controller/data-table-columns.js +50 -56
  31. package/dist/controller/deep-equal.d.ts +1 -0
  32. package/dist/controller/deep-equal.js +14 -0
  33. package/dist/controller/filter-toggle.js +36 -44
  34. package/dist/controller/in-place-editor.d.ts +43 -0
  35. package/dist/controller/in-place-editor.js +43 -0
  36. package/dist/controller/infinite-list-controller.js +219 -189
  37. package/dist/controller/inspector.d.ts +55 -0
  38. package/dist/controller/inspector.js +70 -0
  39. package/dist/controller/job-monitor.d.ts +10 -4
  40. package/dist/controller/job-monitor.js +46 -47
  41. package/dist/controller/kanban-board.js +45 -24
  42. package/dist/controller/list-controller.d.ts +8 -5
  43. package/dist/controller/list-controller.js +447 -400
  44. package/dist/controller/list-params.js +96 -87
  45. package/dist/controller/pivot-grid.d.ts +4 -4
  46. package/dist/controller/pivot-grid.js +89 -95
  47. package/dist/controller/prev-next.d.ts +2 -2
  48. package/dist/controller/prev-next.js +74 -54
  49. package/dist/controller/record-controllers.d.ts +14 -6
  50. package/dist/controller/record-controllers.js +288 -257
  51. package/dist/controller/record-diff.d.ts +21 -0
  52. package/dist/controller/record-diff.js +50 -0
  53. package/dist/controller/record-timeline.d.ts +5 -5
  54. package/dist/controller/record-timeline.js +42 -30
  55. package/dist/controller/record-tree.js +57 -47
  56. package/dist/controller/record-workflow.d.ts +38 -16
  57. package/dist/controller/record-workflow.js +85 -64
  58. package/dist/controller/reference-many-controller.d.ts +2 -0
  59. package/dist/controller/reference-many-controller.js +199 -192
  60. package/dist/controller/reference-one-controller.d.ts +1 -1
  61. package/dist/controller/reference-one-controller.js +63 -56
  62. package/dist/controller/saved-queries.js +104 -91
  63. package/dist/controller/translate-fallback.js +10 -6
  64. package/dist/csv/export.d.ts +4 -3
  65. package/dist/csv/export.js +43 -40
  66. package/dist/csv/import-controller.d.ts +4 -0
  67. package/dist/csv/import-controller.js +189 -169
  68. package/dist/csv/match-headers.js +29 -22
  69. package/dist/csv/parse-with.js +60 -54
  70. package/dist/csv/run-import.js +69 -72
  71. package/dist/csv/validate-rows.d.ts +1 -1
  72. package/dist/csv/validate-rows.js +65 -52
  73. package/dist/data/cache-ops.d.ts +5 -4
  74. package/dist/data/cache-ops.js +208 -188
  75. package/dist/data/combine-data-providers.js +25 -23
  76. package/dist/data/data-provider-log.d.ts +45 -0
  77. package/dist/data/data-provider-log.js +93 -0
  78. package/dist/data/errors.js +14 -10
  79. package/dist/data/fake-provider.d.ts +6 -3
  80. package/dist/data/fake-provider.js +135 -114
  81. package/dist/data/fetch-utils.js +61 -44
  82. package/dist/data/filter-branch.d.ts +5 -0
  83. package/dist/data/filter-branch.js +10 -0
  84. package/dist/data/get-many-aggregate.js +84 -76
  85. package/dist/data/http-error.js +17 -12
  86. package/dist/data/keys.js +50 -36
  87. package/dist/data/mutation-options.d.ts +14 -9
  88. package/dist/data/mutation-options.js +93 -109
  89. package/dist/data/query-options.js +73 -68
  90. package/dist/data/remove-empty.d.ts +3 -0
  91. package/dist/data/remove-empty.js +11 -0
  92. package/dist/data/undoable.d.ts +2 -2
  93. package/dist/data/undoable.js +190 -174
  94. package/dist/data/with-lifecycle-callbacks.d.ts +45 -17
  95. package/dist/data/with-lifecycle-callbacks.js +66 -52
  96. package/dist/environment/application-update-store.js +58 -55
  97. package/dist/environment/offline-store.js +21 -21
  98. package/dist/form/array-binding.d.ts +30 -11
  99. package/dist/form/array-binding.js +184 -166
  100. package/dist/form/choice-ids.d.ts +7 -0
  101. package/dist/form/choice-ids.js +11 -0
  102. package/dist/form/choices-controller.d.ts +22 -2
  103. package/dist/form/choices-controller.js +315 -275
  104. package/dist/form/date-format.d.ts +38 -0
  105. package/dist/form/date-format.js +89 -0
  106. package/dist/form/dirty-values.d.ts +2 -2
  107. package/dist/form/dirty-values.js +22 -11
  108. package/dist/form/duration.d.ts +22 -0
  109. package/dist/form/duration.js +49 -0
  110. package/dist/form/edit-create-form.d.ts +12 -5
  111. package/dist/form/edit-create-form.js +243 -188
  112. package/dist/form/event-value.d.ts +6 -0
  113. package/dist/form/event-value.js +17 -0
  114. package/dist/form/field-error.d.ts +14 -0
  115. package/dist/form/field-error.js +28 -0
  116. package/dist/form/field-name.d.ts +20 -0
  117. package/dist/form/field-name.js +6 -0
  118. package/dist/form/filter-form-values.js +63 -49
  119. package/dist/form/form-controller.d.ts +9 -1
  120. package/dist/form/form-controller.js +165 -160
  121. package/dist/form/form-groups.d.ts +4 -3
  122. package/dist/form/form-groups.js +79 -79
  123. package/dist/form/form-handle.d.ts +175 -0
  124. package/dist/form/form-handle.js +68 -0
  125. package/dist/form/input-binding.d.ts +56 -31
  126. package/dist/form/input-binding.js +171 -118
  127. package/dist/form/input-values.d.ts +140 -0
  128. package/dist/form/input-values.js +206 -0
  129. package/dist/form/json-text.d.ts +11 -0
  130. package/dist/form/json-text.js +62 -37
  131. package/dist/form/save-pipeline.d.ts +6 -8
  132. package/dist/form/save-pipeline.js +91 -82
  133. package/dist/form/set-form-values.d.ts +6 -0
  134. package/dist/form/set-form-values.js +10 -0
  135. package/dist/form/source.js +97 -65
  136. package/dist/form/text-of.d.ts +2 -0
  137. package/dist/form/text-of.js +7 -0
  138. package/dist/form/validators.d.ts +58 -19
  139. package/dist/form/validators.js +97 -71
  140. package/dist/geo/bbox.d.ts +5 -4
  141. package/dist/geo/bbox.js +69 -48
  142. package/dist/geo/bounds.d.ts +14 -3
  143. package/dist/geo/bounds.js +98 -68
  144. package/dist/geo/constraints.js +88 -93
  145. package/dist/geo/coordinates.d.ts +10 -0
  146. package/dist/geo/coordinates.js +44 -23
  147. package/dist/geo/editor.d.ts +13 -13
  148. package/dist/geo/editor.js +176 -153
  149. package/dist/geo/geocoding.d.ts +4 -4
  150. package/dist/geo/geocoding.js +38 -41
  151. package/dist/geo/geojson.d.ts +12 -74
  152. package/dist/geo/geojson.js +52 -40
  153. package/dist/geo/geometry-math.d.ts +4 -4
  154. package/dist/geo/geometry-math.js +100 -93
  155. package/dist/geo/index.d.ts +9 -8
  156. package/dist/geo/map-layers.d.ts +42 -7
  157. package/dist/geo/map-layers.js +88 -62
  158. package/dist/geo/map-style.d.ts +12 -0
  159. package/dist/geo/map-style.js +43 -32
  160. package/dist/geo/messages.js +48 -45
  161. package/dist/geo/nominatim.js +88 -80
  162. package/dist/geo/osm-presets.d.ts +4 -3
  163. package/dist/geo/osm-presets.js +108 -86
  164. package/dist/geo/osm-tags.js +14 -12
  165. package/dist/geo/overpass.d.ts +14 -2
  166. package/dist/geo/overpass.js +83 -90
  167. package/dist/geo/shape-value.d.ts +9 -5
  168. package/dist/geo/shape-value.js +169 -146
  169. package/dist/geo/snap-to-roads.d.ts +3 -3
  170. package/dist/geo/snap-to-roads.js +55 -50
  171. package/dist/geo/throttle.js +36 -39
  172. package/dist/guards.d.ts +44 -0
  173. package/dist/guards.js +77 -0
  174. package/dist/i18n/default-messages.js +34 -29
  175. package/dist/i18n/english-messages.d.ts +172 -0
  176. package/dist/i18n/english-messages.js +359 -189
  177. package/dist/i18n/i18n.d.ts +2 -2
  178. package/dist/i18n/i18n.js +47 -60
  179. package/dist/i18n/inflection.d.ts +34 -0
  180. package/dist/i18n/inflection.js +82 -0
  181. package/dist/i18n/messages.d.ts +10 -2
  182. package/dist/i18n/messages.js +17 -4
  183. package/dist/i18n/missing-keys.d.ts +4 -0
  184. package/dist/i18n/missing-keys.js +70 -62
  185. package/dist/i18n/translatable.d.ts +16 -1
  186. package/dist/i18n/translatable.js +40 -47
  187. package/dist/index.d.ts +87 -39
  188. package/dist/index.js +54 -301
  189. package/dist/json/deep-equal.d.ts +8 -0
  190. package/dist/json/deep-equal.js +24 -0
  191. package/dist/json/strip-json-comments.js +38 -42
  192. package/dist/noop.d.ts +2 -0
  193. package/dist/noop.js +4 -0
  194. package/dist/notification/error-message.d.ts +2 -0
  195. package/dist/notification/error-message.js +10 -0
  196. package/dist/notification/notification-store.d.ts +3 -2
  197. package/dist/notification/notification-store.js +41 -45
  198. package/dist/onboarding-tour/placement.d.ts +2 -0
  199. package/dist/onboarding-tour/placement.js +65 -78
  200. package/dist/onboarding-tour/tour-controller.js +46 -54
  201. package/dist/realtime/add-events-for-mutations.js +75 -81
  202. package/dist/realtime/announce-lock.js +16 -13
  203. package/dist/realtime/broadcast-channel-transport.js +65 -59
  204. package/dist/realtime/copy-members.js +22 -14
  205. package/dist/realtime/in-memory-lock-provider.js +40 -48
  206. package/dist/realtime/live.js +95 -101
  207. package/dist/realtime/lock-options.js +16 -16
  208. package/dist/realtime/lock-session.js +91 -78
  209. package/dist/realtime/memory-transport.js +25 -25
  210. package/dist/realtime/presence.js +120 -122
  211. package/dist/realtime/realtime-data-provider.d.ts +10 -0
  212. package/dist/realtime/realtime-data-provider.js +45 -42
  213. package/dist/realtime/reconnect-backoff.js +17 -0
  214. package/dist/realtime/sse-transport.d.ts +31 -0
  215. package/dist/realtime/sse-transport.js +235 -0
  216. package/dist/realtime/status-store.js +23 -28
  217. package/dist/realtime/topic-hub.js +62 -71
  218. package/dist/realtime/topics.js +10 -12
  219. package/dist/realtime/types.js +10 -12
  220. package/dist/realtime/unread-count.js +21 -21
  221. package/dist/realtime/websocket-transport.d.ts +32 -0
  222. package/dist/realtime/websocket-transport.js +306 -0
  223. package/dist/resource/describe-resource.d.ts +2 -0
  224. package/dist/resource/describe-resource.js +247 -219
  225. package/dist/resource/get-at-path.js +29 -14
  226. package/dist/resource/identifier.d.ts +18 -0
  227. package/dist/resource/identifier.js +27 -0
  228. package/dist/resource/record.d.ts +4 -0
  229. package/dist/resource/record.js +10 -0
  230. package/dist/resource/register.d.ts +7 -0
  231. package/dist/resource/registry-store.d.ts +45 -15
  232. package/dist/resource/registry-store.js +67 -60
  233. package/dist/resource/registry.d.ts +10 -0
  234. package/dist/resource/registry.js +8 -4
  235. package/dist/resource/source-path.d.ts +23 -2
  236. package/dist/rich-text/rich-text-extras.d.ts +134 -0
  237. package/dist/rich-text/rich-text-extras.js +181 -0
  238. package/dist/rich-text/rich-text-image.d.ts +124 -0
  239. package/dist/rich-text/rich-text-image.js +163 -0
  240. package/dist/rich-text/rich-text.d.ts +6 -0
  241. package/dist/rich-text/rich-text.js +125 -88
  242. package/dist/router/location.d.ts +24 -4
  243. package/dist/router/location.js +43 -18
  244. package/dist/router/match.js +47 -39
  245. package/dist/router/paths.js +40 -34
  246. package/dist/router/record-from-location.d.ts +1 -1
  247. package/dist/router/record-from-location.js +25 -17
  248. package/dist/store/adapters.js +51 -55
  249. package/dist/store/micro-store.js +57 -59
  250. package/dist/store/shallow-equal.d.ts +12 -0
  251. package/dist/store/shallow-equal.js +20 -0
  252. package/dist/store/store.js +54 -57
  253. package/dist/ui-defaults.d.ts +15 -0
  254. package/dist/ui-defaults.js +17 -0
  255. package/package.json +13 -11
package/dist/i18n/i18n.js CHANGED
@@ -1,68 +1,55 @@
1
+ // src/i18n/i18n.ts
1
2
  function interpolate(template, params) {
2
- if (!params) return template;
3
- return template.replace(
4
- /\{(\w+)\}/g,
5
- (match, name) => name in params ? String(params[name]) : match
6
- );
3
+ if (!params) return template;
4
+ return template.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match);
7
5
  }
8
6
  function resolve(value, locale, params) {
9
- if (typeof value === "string") return interpolate(value, params);
10
- const raw = params?.count ?? params?.smart_count;
11
- const count = typeof raw === "number" ? raw : Number(raw ?? Number.NaN);
12
- if (Number.isNaN(count)) return interpolate(value.other, params);
13
- const category = new Intl.PluralRules(locale).select(count);
14
- return interpolate(value[category] ?? value.other, {
15
- ...params,
16
- count: params?.count ?? raw,
17
- smart_count: params?.smart_count ?? raw
18
- });
7
+ if (typeof value === "string") return interpolate(value, params);
8
+ const raw = params?.count ?? params?.smart_count;
9
+ if (raw === void 0 || raw === null) return interpolate(value.other, params);
10
+ const count = Number(raw);
11
+ if (Number.isNaN(count)) return interpolate(value.other, params);
12
+ return interpolate(value[new Intl.PluralRules(locale).select(count)] ?? value.other, {
13
+ ...params,
14
+ count: params?.count ?? raw,
15
+ smart_count: params?.smart_count ?? raw
16
+ });
19
17
  }
18
+ /** Own-property lookup: `"constructor"` or `"toString"` is a missing key, not a function. */
20
19
  function lookup(catalog, key) {
21
- return catalog && Object.hasOwn(catalog, key) ? catalog[key] : void 0;
20
+ return catalog && Object.hasOwn(catalog, key) ? catalog[key] : void 0;
22
21
  }
23
22
  function createI18n(options) {
24
- let locale = options.locale;
25
- const subscribers = /* @__PURE__ */ new Set();
26
- return {
27
- translate(key, ...args) {
28
- const params = args[0];
29
- const own = lookup(options.messages[locale], key);
30
- if (own === void 0 && options.onMissingKey) {
31
- try {
32
- options.onMissingKey(
33
- key,
34
- locale,
35
- typeof params?._ === "string" ? params._ : void 0
36
- );
37
- } catch (error) {
38
- console.error(error);
39
- }
40
- }
41
- const value = own ?? (options.fallbackLocale ? lookup(options.messages[options.fallbackLocale], key) : void 0);
42
- if (value === void 0) {
43
- if (typeof params?._ === "string") return interpolate(params._, params);
44
- return key;
45
- }
46
- return resolve(value, locale, params);
47
- },
48
- getLocale: () => locale,
49
- setLocale(next) {
50
- if (!Object.hasOwn(options.messages, next)) {
51
- throw new Error(
52
- `createI18n: unknown locale "${next}" — available: ${Object.keys(options.messages).join(", ")}`
53
- );
54
- }
55
- if (next === locale) return;
56
- locale = next;
57
- for (const cb of subscribers) cb();
58
- },
59
- getLocales: () => Object.keys(options.messages),
60
- subscribe(callback) {
61
- subscribers.add(callback);
62
- return () => void subscribers.delete(callback);
63
- }
64
- };
23
+ let locale = options.locale;
24
+ const subscribers = /* @__PURE__ */ new Set();
25
+ return {
26
+ translate(key, ...args) {
27
+ const params = args[0];
28
+ const own = lookup(options.messages[locale], key);
29
+ if (own === void 0 && options.onMissingKey) try {
30
+ options.onMissingKey(key, locale, typeof params?._ === "string" ? params._ : void 0);
31
+ } catch (error) {
32
+ console.error(error);
33
+ }
34
+ const value = own ?? (options.fallbackLocale ? lookup(options.messages[options.fallbackLocale], key) : void 0);
35
+ if (value === void 0) {
36
+ if (typeof params?._ === "string") return interpolate(params._, params);
37
+ return key;
38
+ }
39
+ return resolve(value, locale, params);
40
+ },
41
+ getLocale: () => locale,
42
+ setLocale(next) {
43
+ if (!Object.hasOwn(options.messages, next)) throw new Error(`createI18n: unknown locale "${next}" — available: ${Object.keys(options.messages).join(", ")}`);
44
+ if (next === locale) return;
45
+ locale = next;
46
+ for (const cb of subscribers) cb();
47
+ },
48
+ getLocales: () => Object.keys(options.messages),
49
+ subscribe(callback) {
50
+ subscribers.add(callback);
51
+ return () => void subscribers.delete(callback);
52
+ }
53
+ };
65
54
  }
66
- export {
67
- createI18n
68
- };
55
+ export { createI18n };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Clean-room reimplementation of the SUBSET of the `inflection` package the
3
+ * ra-core label helpers rely on. Chelone carries no `inflection` dependency, so
4
+ * these three small helpers cover exactly what `useGetResourceLabel` /
5
+ * `useTranslateLabel` need:
6
+ *
7
+ * - `humanize(text)` — ra-core `humanize`: strip a trailing `_id`, replace
8
+ * underscores with spaces, lowercase, and capitalize the first letter. Does
9
+ * NOT split camelCase (parity: `humanize('authorName') === 'Authorname'`).
10
+ * - `humanizeField(source)` — ra-core `transform(['underscore','humanize'])`:
11
+ * camelCase-aware, so `firstName` → `First name`. Used for field labels.
12
+ * - `pluralize(word, count)` — ra-core `inflect(word, count)`: singular for
13
+ * `count === 1`, plural otherwise. Covers the regular English rules plus a
14
+ * small irregular set. Full parity with `inflection`'s complete irregular
15
+ * table is a documented non-goal (the fallback only fires when a translation
16
+ * key AND an `options.label` are both absent).
17
+ */
18
+ /**
19
+ * ra-core `humanize`: strip a trailing `_id`, underscores → spaces, lowercase,
20
+ * capitalize the first letter. Deliberately does NOT split camelCase.
21
+ */
22
+ export declare function humanize(text: string): string;
23
+ /**
24
+ * ra-core `transform(source, ['underscore','humanize'])`: camelCase-aware
25
+ * humanization for field labels. `firstName` → `First name`, `full_name` →
26
+ * `Full name`, `author name` → `Author name`.
27
+ */
28
+ export declare function humanizeField(source: string): string;
29
+ /**
30
+ * ra-core `inflect(word, count)`: singularize when `count === 1`, pluralize
31
+ * otherwise. Case-preserving only for the first letter (the caller humanizes
32
+ * afterward, so casing beyond that does not matter here).
33
+ */
34
+ export declare function pluralize(word: string, count?: number): string;
@@ -0,0 +1,82 @@
1
+ // src/i18n/inflection.ts
2
+ /**
3
+ * Clean-room reimplementation of the SUBSET of the `inflection` package the
4
+ * ra-core label helpers rely on. Chelone carries no `inflection` dependency, so
5
+ * these three small helpers cover exactly what `useGetResourceLabel` /
6
+ * `useTranslateLabel` need:
7
+ *
8
+ * - `humanize(text)` — ra-core `humanize`: strip a trailing `_id`, replace
9
+ * underscores with spaces, lowercase, and capitalize the first letter. Does
10
+ * NOT split camelCase (parity: `humanize('authorName') === 'Authorname'`).
11
+ * - `humanizeField(source)` — ra-core `transform(['underscore','humanize'])`:
12
+ * camelCase-aware, so `firstName` → `First name`. Used for field labels.
13
+ * - `pluralize(word, count)` — ra-core `inflect(word, count)`: singular for
14
+ * `count === 1`, plural otherwise. Covers the regular English rules plus a
15
+ * small irregular set. Full parity with `inflection`'s complete irregular
16
+ * table is a documented non-goal (the fallback only fires when a translation
17
+ * key AND an `options.label` are both absent).
18
+ */
19
+ /** Capitalize the first character; leave the rest untouched. */
20
+ function capitalizeFirst(text) {
21
+ return text.length === 0 ? text : text.charAt(0).toUpperCase() + text.slice(1);
22
+ }
23
+ /**
24
+ * Convert a camelCase / snake_case identifier to lowercase underscore form:
25
+ * `firstName` → `first_name`, `full_name` → `full_name`.
26
+ */
27
+ function underscore(text) {
28
+ return text.replace(/([a-z\d])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
29
+ }
30
+ /**
31
+ * ra-core `humanize`: strip a trailing `_id`, underscores → spaces, lowercase,
32
+ * capitalize the first letter. Deliberately does NOT split camelCase.
33
+ */
34
+ function humanize(text) {
35
+ return capitalizeFirst(text.replace(/_id$/, "").replace(/_+/g, " ").trim().toLowerCase());
36
+ }
37
+ /**
38
+ * ra-core `transform(source, ['underscore','humanize'])`: camelCase-aware
39
+ * humanization for field labels. `firstName` → `First name`, `full_name` →
40
+ * `Full name`, `author name` → `Author name`.
41
+ */
42
+ function humanizeField(source) {
43
+ return humanize(underscore(source));
44
+ }
45
+ var IRREGULARS = [
46
+ ["person", "people"],
47
+ ["child", "children"],
48
+ ["man", "men"],
49
+ ["woman", "women"],
50
+ ["mouse", "mice"],
51
+ ["foot", "feet"],
52
+ ["tooth", "teeth"],
53
+ ["goose", "geese"]
54
+ ];
55
+ /** Regular English plural of a lowercase word (idempotent on plurals). */
56
+ function toPlural(word) {
57
+ for (const [singular, plural] of IRREGULARS) if (word === singular || word === plural) return plural;
58
+ const singular = toSingular(word);
59
+ if (/[^aeiou]y$/.test(singular)) return `${singular.slice(0, -1)}ies`;
60
+ if (/(s|x|z|ch|sh)$/.test(singular)) return `${singular}es`;
61
+ return `${singular}s`;
62
+ }
63
+ /** Regular English singular of a lowercase word. */
64
+ function toSingular(word) {
65
+ for (const [singular, plural] of IRREGULARS) {
66
+ if (word === plural) return singular;
67
+ if (word === singular) return singular;
68
+ }
69
+ if (/ies$/.test(word)) return `${word.slice(0, -3)}y`;
70
+ if (/(ss|x|z|ch|sh)es$/.test(word)) return word.slice(0, -2);
71
+ if (/s$/.test(word) && !/ss$/.test(word)) return word.slice(0, -1);
72
+ return word;
73
+ }
74
+ /**
75
+ * ra-core `inflect(word, count)`: singularize when `count === 1`, pluralize
76
+ * otherwise. Case-preserving only for the first letter (the caller humanizes
77
+ * afterward, so casing beyond that does not matter here).
78
+ */
79
+ function pluralize(word, count = 2) {
80
+ return count === 1 ? toSingular(word) : toPlural(word);
81
+ }
82
+ export { humanize, humanizeField, pluralize };
@@ -4,6 +4,12 @@ export type PluralMessage = Partial<Record<Intl.LDMLPluralRule, string>> & {
4
4
  };
5
5
  export type MessageValue = string | PluralMessage;
6
6
  export type MessageCatalog = Record<string, MessageValue>;
7
+ /** The values a message placeholder takes; one type for typed catalogs and the erased view. */
8
+ export type TranslateParamValues = Record<string, string | number>;
9
+ /** Boundary narrowing for `unknown` input: keeps the string and number entries of a plain object, `undefined` for anything else. */
10
+ export declare function pickTranslateParamValues(value: unknown): TranslateParamValues | undefined;
11
+ /** Drops absent values: an `undefined` param would otherwise render as the text "undefined". */
12
+ export declare function definedParams(params: Record<string, string | number | undefined>): TranslateParamValues;
7
13
  /** Identity helper pinning literal keys AND literal template strings (for param inference). */
8
14
  export declare function defineMessages<const T extends MessageCatalog>(catalog: T): T;
9
15
  export type MessageKey<TCatalog extends MessageCatalog> = keyof TCatalog & string;
@@ -16,9 +22,11 @@ type ParamsObject<T extends string> = [ExtractParams<T>] extends [never] ? undef
16
22
  * Required params for a message value: placeholder names for plain strings;
17
23
  * plural messages additionally require `count` (drives Intl.PluralRules).
18
24
  */
19
- export type TranslateParams<TValue extends MessageValue> = TValue extends string ? ParamsObject<TValue> : TValue extends PluralMessage ? ([ExtractParams<TValue["other"]>] extends [never] ? unknown : {
25
+ export type TranslateParams<TValue extends MessageValue> = TValue extends string ? ParamsObject<TValue> : TValue extends PluralMessage ? [ExtractParams<TValue["other"]>] extends [never] ? {
26
+ count: number;
27
+ } : {
20
28
  [K in ExtractParams<TValue["other"]>]: string | number;
21
- }) & {
29
+ } & {
22
30
  count: number;
23
31
  } : never;
24
32
  export {};
@@ -1,6 +1,19 @@
1
+ // src/i18n/messages.ts
2
+ /** Boundary narrowing for `unknown` input: keeps the string and number entries of a plain object, `undefined` for anything else. */
3
+ function pickTranslateParamValues(value) {
4
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return;
5
+ const picked = {};
6
+ for (const [name, entry] of Object.entries(value)) if (typeof entry === "string" || typeof entry === "number") picked[name] = entry;
7
+ return picked;
8
+ }
9
+ /** Drops absent values: an `undefined` param would otherwise render as the text "undefined". */
10
+ function definedParams(params) {
11
+ const defined = {};
12
+ for (const [name, value] of Object.entries(params)) if (value !== void 0) defined[name] = value;
13
+ return defined;
14
+ }
15
+ /** Identity helper pinning literal keys AND literal template strings (for param inference). */
1
16
  function defineMessages(catalog) {
2
- return catalog;
17
+ return catalog;
3
18
  }
4
- export {
5
- defineMessages
6
- };
19
+ export { defineMessages, definedParams, pickTranslateParamValues };
@@ -1,3 +1,7 @@
1
+ /** Every key the i18n key editor labels itself with. The panel never lists these. */
2
+ export declare const OWN_KEY_PREFIX = "chelone.i18n_key_editor.";
3
+ /** How long its export button shows `Copied`. */
4
+ export declare const COPIED_MS = 1500;
1
5
  export interface MissingKeyEntry {
2
6
  key: string;
3
7
  fallback: string | undefined;
@@ -1,64 +1,72 @@
1
- const NO_ENTRIES = [];
1
+ // src/i18n/missing-keys.ts
2
+ /** Every key the i18n key editor labels itself with. The panel never lists these. */
3
+ var OWN_KEY_PREFIX = "chelone.i18n_key_editor.";
4
+ /** How long its export button shows `Copied`. */
5
+ var COPIED_MS = 1500;
6
+ var NO_ENTRIES = [];
2
7
  function createMissingKeyStore() {
3
- const byLocale = /* @__PURE__ */ new Map();
4
- const snapshots = /* @__PURE__ */ new Map();
5
- const subscribers = /* @__PURE__ */ new Set();
6
- let scheduled = false;
7
- const changed = (locale) => {
8
- snapshots.delete(locale);
9
- if (scheduled) return;
10
- scheduled = true;
11
- queueMicrotask(() => {
12
- scheduled = false;
13
- for (const cb of [...subscribers]) cb();
14
- });
15
- };
16
- const getEntries = (locale) => {
17
- const cached = snapshots.get(locale);
18
- if (cached) return cached;
19
- const entries = byLocale.get(locale);
20
- if (!entries?.size) return NO_ENTRIES;
21
- const snapshot = [...entries.values()];
22
- snapshots.set(locale, snapshot);
23
- return snapshot;
24
- };
25
- return {
26
- record(key, locale, fallback) {
27
- let entries = byLocale.get(locale);
28
- if (!entries) {
29
- entries = /* @__PURE__ */ new Map();
30
- byLocale.set(locale, entries);
31
- }
32
- if (entries.has(key)) return;
33
- entries.set(key, { key, fallback, translation: "" });
34
- changed(locale);
35
- },
36
- getEntries,
37
- setTranslation(locale, key, text) {
38
- const entries = byLocale.get(locale);
39
- const entry = entries?.get(key);
40
- if (!entries || !entry || entry.translation === text) return;
41
- entries.set(key, { ...entry, translation: text });
42
- changed(locale);
43
- },
44
- clear(locale) {
45
- if (!byLocale.get(locale)?.size) return;
46
- byLocale.delete(locale);
47
- changed(locale);
48
- },
49
- toJson(locale) {
50
- const out = /* @__PURE__ */ new Map();
51
- for (const { key, translation } of getEntries(locale)) {
52
- if (translation.trim() !== "") out.set(key, translation);
53
- }
54
- return JSON.stringify(Object.fromEntries(out), null, 2);
55
- },
56
- subscribe(callback) {
57
- subscribers.add(callback);
58
- return () => void subscribers.delete(callback);
59
- }
60
- };
8
+ const byLocale = /* @__PURE__ */ new Map();
9
+ const snapshots = /* @__PURE__ */ new Map();
10
+ const subscribers = /* @__PURE__ */ new Set();
11
+ let scheduled = false;
12
+ const changed = (locale) => {
13
+ snapshots.delete(locale);
14
+ if (scheduled) return;
15
+ scheduled = true;
16
+ queueMicrotask(() => {
17
+ scheduled = false;
18
+ for (const cb of [...subscribers]) cb();
19
+ });
20
+ };
21
+ const getEntries = (locale) => {
22
+ const cached = snapshots.get(locale);
23
+ if (cached) return cached;
24
+ const entries = byLocale.get(locale);
25
+ if (!entries?.size) return NO_ENTRIES;
26
+ const snapshot = [...entries.values()];
27
+ snapshots.set(locale, snapshot);
28
+ return snapshot;
29
+ };
30
+ return {
31
+ record(key, locale, fallback) {
32
+ let entries = byLocale.get(locale);
33
+ if (!entries) {
34
+ entries = /* @__PURE__ */ new Map();
35
+ byLocale.set(locale, entries);
36
+ }
37
+ if (entries.has(key)) return;
38
+ entries.set(key, {
39
+ key,
40
+ fallback,
41
+ translation: ""
42
+ });
43
+ changed(locale);
44
+ },
45
+ getEntries,
46
+ setTranslation(locale, key, text) {
47
+ const entries = byLocale.get(locale);
48
+ const entry = entries?.get(key);
49
+ if (!entries || !entry || entry.translation === text) return;
50
+ entries.set(key, {
51
+ ...entry,
52
+ translation: text
53
+ });
54
+ changed(locale);
55
+ },
56
+ clear(locale) {
57
+ if (!byLocale.get(locale)?.size) return;
58
+ byLocale.delete(locale);
59
+ changed(locale);
60
+ },
61
+ toJson(locale) {
62
+ const out = /* @__PURE__ */ new Map();
63
+ for (const { key, translation } of getEntries(locale)) if (translation.trim() !== "") out.set(key, translation);
64
+ return JSON.stringify(Object.fromEntries(out), null, 2);
65
+ },
66
+ subscribe(callback) {
67
+ subscribers.add(callback);
68
+ return () => void subscribers.delete(callback);
69
+ }
70
+ };
61
71
  }
62
- export {
63
- createMissingKeyStore
64
- };
72
+ export { COPIED_MS, OWN_KEY_PREFIX, createMissingKeyStore };
@@ -19,6 +19,20 @@ export interface TranslatableController {
19
19
  * form values themselves stay in the form; this only tracks the selection.
20
20
  */
21
21
  export declare function createTranslatableController(options: TranslatableOptions): TranslatableController;
22
+ type LocalizedField<V> = V extends (...args: never[]) => unknown ? V : V extends Date ? V : V extends readonly (infer Item)[] ? LocalizedField<Item>[] : V extends Record<string, string> ? string : V extends object ? RecordForLocale<V> : V;
23
+ /**
24
+ * What `getRecordForLocale` makes of `T`: a field typed `Record<string, string>`
25
+ * becomes `string`, an array maps its items, any other object maps its fields,
26
+ * and every other type stays. The root is never replaced.
27
+ *
28
+ * A nested `{ a: string; b: string }` field reads as a translation map here,
29
+ * though at run time only `locales` tells the two apart. A map without the
30
+ * selected locale is also left as it is at run time, so its type is the
31
+ * translated one only for a locale the data covers.
32
+ */
33
+ export type RecordForLocale<T> = {
34
+ [K in keyof T]: LocalizedField<T[K]>;
35
+ };
22
36
  /**
23
37
  * A copy of `record` where every object holding `locale` as an own key is
24
38
  * replaced by its value at that key, at any depth and inside arrays. Nodes
@@ -29,4 +43,5 @@ export declare function createTranslatableController(options: TranslatableOption
29
43
  * (`id` is Indonesian), so pass `locales` to also keep objects that have other
30
44
  * keys, such as a nested `{ id, name }` reference, from being read as a map.
31
45
  */
32
- export declare function getRecordForLocale<T extends object | null | undefined>(record: T, locale: string, locales?: readonly string[]): T extends object ? Record<string, unknown> : T;
46
+ export declare function getRecordForLocale<T extends object | null | undefined>(record: T, locale: string, locales?: readonly string[]): T extends object ? RecordForLocale<T> : T;
47
+ export {};
@@ -1,56 +1,49 @@
1
+ import { isPlainObject } from "../guards.js";
1
2
  import { createMicroStore } from "../store/micro-store.js";
3
+ // src/i18n/translatable.ts
4
+ /**
5
+ * The state behind a multi-locale editor: which locale is on screen. The
6
+ * form values themselves stay in the form; this only tracks the selection.
7
+ */
2
8
  function createTranslatableController(options) {
3
- const { locales, defaultLocale } = options;
4
- const first = locales[0];
5
- if (first === void 0) {
6
- throw new Error("A translatable controller needs at least one locale");
7
- }
8
- const store = createMicroStore({
9
- locales,
10
- selectedLocale: defaultLocale !== void 0 && locales.includes(defaultLocale) ? defaultLocale : first
11
- });
12
- return {
13
- getSnapshot: store.getSnapshot,
14
- subscribe: store.subscribe,
15
- destroy: store.destroy,
16
- selectLocale(locale) {
17
- if (!locales.includes(locale)) {
18
- throw new Error(
19
- `Locale "${locale}" is not one of: ${locales.join(", ")}`
20
- );
21
- }
22
- store.setState({ selectedLocale: locale });
23
- }
24
- };
25
- }
26
- function isPlainObject(value) {
27
- if (typeof value !== "object" || value === null) return false;
28
- const proto = Object.getPrototypeOf(value);
29
- return proto === Object.prototype || proto === null;
9
+ const { locales, defaultLocale } = options;
10
+ const first = locales[0];
11
+ if (first === void 0) throw new Error("A translatable controller needs at least one locale");
12
+ const store = createMicroStore({
13
+ locales,
14
+ selectedLocale: defaultLocale !== void 0 && locales.includes(defaultLocale) ? defaultLocale : first
15
+ });
16
+ return {
17
+ getSnapshot: store.getSnapshot,
18
+ subscribe: store.subscribe,
19
+ destroy: store.destroy,
20
+ selectLocale(locale) {
21
+ if (!locales.includes(locale)) throw new Error(`Locale "${locale}" is not one of: ${locales.join(", ")}`);
22
+ store.setState({ selectedLocale: locale });
23
+ }
24
+ };
30
25
  }
31
26
  function pick(node, locale, locales, isRoot) {
32
- if (Array.isArray(node)) {
33
- return node.map((item) => pick(item, locale, locales, false));
34
- }
35
- if (!isPlainObject(node)) return node;
36
- if (!isRoot && isTranslationMap(node, locale, locales)) {
37
- return pick(node[locale], locale, locales, false);
38
- }
39
- return Object.fromEntries(
40
- Object.entries(node).map(([key, value]) => [
41
- key,
42
- pick(value, locale, locales, false)
43
- ])
44
- );
27
+ if (Array.isArray(node)) return node.map((item) => pick(item, locale, locales, false));
28
+ if (!isPlainObject(node)) return node;
29
+ if (!isRoot && isTranslationMap(node, locale, locales)) return pick(node[locale], locale, locales, false);
30
+ return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, pick(value, locale, locales, false)]));
45
31
  }
46
32
  function isTranslationMap(node, locale, locales) {
47
- if (!Object.hasOwn(node, locale)) return false;
48
- return !locales || Object.keys(node).every((key) => locales.includes(key));
33
+ if (!Object.hasOwn(node, locale)) return false;
34
+ return !locales || Object.keys(node).every((key) => locales.includes(key));
49
35
  }
36
+ /**
37
+ * A copy of `record` where every object holding `locale` as an own key is
38
+ * replaced by its value at that key, at any depth and inside arrays. Nodes
39
+ * without the key are kept as they are, so a record missing the locale still
40
+ * shows the translatable object.
41
+ *
42
+ * The record itself is never replaced. A locale code can equal a field name
43
+ * (`id` is Indonesian), so pass `locales` to also keep objects that have other
44
+ * keys, such as a nested `{ id, name }` reference, from being read as a map.
45
+ */
50
46
  function getRecordForLocale(record, locale, locales) {
51
- return pick(record, locale, locales, true);
47
+ return pick(record, locale, locales, true);
52
48
  }
53
- export {
54
- createTranslatableController,
55
- getRecordForLocale
56
- };
49
+ export { createTranslatableController, getRecordForLocale };