@zeyos/zx 4.4.0 → 5.2.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 (252) hide show
  1. package/CHANGELOG.md +447 -0
  2. package/README.md +44 -11
  3. package/dist/types/components/account-menu/account-menu.d.ts +8 -0
  4. package/dist/types/components/activity-list/activity-list.d.ts +31 -1
  5. package/dist/types/components/app-icon/app-icon.d.ts +14 -2
  6. package/dist/types/components/app-sidebar/app-sidebar.d.ts +293 -17
  7. package/dist/types/components/avatar/avatar.d.ts +46 -7
  8. package/dist/types/components/badge/badge.d.ts +21 -1
  9. package/dist/types/components/button/button.d.ts +15 -0
  10. package/dist/types/components/calendar/calendar.d.ts +67 -5
  11. package/dist/types/components/card-view/card-view.d.ts +7 -4
  12. package/dist/types/components/card-view/record-card.d.ts +11 -0
  13. package/dist/types/components/chart/chart.d.ts +10 -0
  14. package/dist/types/components/checklist/checklist.d.ts +9 -0
  15. package/dist/types/components/code-editor/code-editor.d.ts +6 -17
  16. package/dist/types/components/context-menu/context-menu.d.ts +6 -2
  17. package/dist/types/components/data-filter/data-filter.d.ts +4 -4
  18. package/dist/types/components/datebox/date-range-box.d.ts +5 -1
  19. package/dist/types/components/datebox/datebox.d.ts +7 -2
  20. package/dist/types/components/dialog/dialog.d.ts +46 -6
  21. package/dist/types/components/dropdown/dropdown.d.ts +24 -9
  22. package/dist/types/components/entity-ref/entity-ref.d.ts +2 -2
  23. package/dist/types/components/field/field.d.ts +54 -2
  24. package/dist/types/components/fieldset/external-adapter.d.ts +83 -0
  25. package/dist/types/components/fieldset/fieldset.d.ts +26 -1
  26. package/dist/types/components/file-item/file-item.d.ts +34 -6
  27. package/dist/types/components/file-list/file-list.d.ts +35 -3
  28. package/dist/types/components/filter/filter.d.ts +127 -3
  29. package/dist/types/components/filter-panel/filter-panel.d.ts +36 -7
  30. package/dist/types/components/form/form.d.ts +12 -1
  31. package/dist/types/components/kanban-view/kanban-card.d.ts +8 -0
  32. package/dist/types/components/launcher/launcher.d.ts +268 -15
  33. package/dist/types/components/list-toolbar/list-toolbar.d.ts +16 -7
  34. package/dist/types/components/menu-button/menu-button.d.ts +39 -5
  35. package/dist/types/components/message/message.d.ts +132 -17
  36. package/dist/types/components/modal/modal.d.ts +43 -2
  37. package/dist/types/components/module-bar/module-bar.d.ts +395 -0
  38. package/dist/types/components/pagination/pagination.d.ts +17 -3
  39. package/dist/types/components/select/color.d.ts +12 -0
  40. package/dist/types/components/select/glyphs.d.ts +124 -0
  41. package/dist/types/components/select/select.d.ts +17 -3
  42. package/dist/types/components/sheet/sheet.d.ts +15 -0
  43. package/dist/types/components/stat-tile/stat-tile.d.ts +16 -5
  44. package/dist/types/components/tabbox/tabbox.d.ts +9 -0
  45. package/dist/types/components/table/table.d.ts +311 -18
  46. package/dist/types/components/tag-picker/tag-picker.d.ts +21 -4
  47. package/dist/types/components/tree/tree.d.ts +13 -0
  48. package/dist/types/components/view/record-view.d.ts +59 -2
  49. package/dist/types/components/view-settings/view-settings.d.ts +879 -0
  50. package/dist/types/components/workspace-switcher/workspace-switcher.d.ts +327 -0
  51. package/dist/types/core/breakpoint.d.ts +1 -1
  52. package/dist/types/core/component.d.ts +12 -2
  53. package/dist/types/core/i18n.d.ts +27 -3
  54. package/dist/types/core/icons.d.ts +23 -25
  55. package/dist/types/core/keyboard.d.ts +98 -1
  56. package/dist/types/core/messages.d.ts +382 -0
  57. package/dist/types/core/motion.d.ts +59 -0
  58. package/dist/types/core/overlay-host.d.ts +42 -1
  59. package/dist/types/core/overlay-stack.d.ts +260 -0
  60. package/dist/types/index.d.ts +10 -5
  61. package/dist/types/internal/app-rail.d.ts +38 -0
  62. package/dist/types/internal/menu-items.d.ts +71 -3
  63. package/dist/types/zeyos/connect.d.ts +6 -0
  64. package/dist/types/zeyos/form.d.ts +50 -9
  65. package/dist/types/zeyos/index.d.ts +2 -1
  66. package/dist/types/zeyos/launcher.d.ts +9 -0
  67. package/dist/types/zeyos/module-bar.d.ts +176 -0
  68. package/dist/types/zeyos/query.d.ts +110 -5
  69. package/dist/types/zeyos/schema.d.ts +24 -1
  70. package/dist/types/zeyos/table.d.ts +345 -22
  71. package/dist/types/zeyos/view.d.ts +26 -2
  72. package/dist/zx-zeyos.esm.js +6178 -1008
  73. package/dist/zx-zeyos.esm.min.js +53 -5
  74. package/dist/zx.css +2861 -827
  75. package/dist/zx.esm.js +8909 -1480
  76. package/dist/zx.esm.min.js +55 -7
  77. package/dist/zx.global.js +8911 -1482
  78. package/dist/zx.global.min.js +55 -7
  79. package/dist/zx.min.css +1 -1
  80. package/docs/api.json +1079 -117
  81. package/docs/llms.md +956 -154
  82. package/docs/llms.txt +9 -5
  83. package/package.json +1 -1
  84. package/src/components/account-menu/account-menu.css +35 -10
  85. package/src/components/account-menu/account-menu.js +12 -0
  86. package/src/components/activity-item/activity-item.css +1 -1
  87. package/src/components/activity-item/activity-item.js +3 -0
  88. package/src/components/activity-list/activity-list.css +38 -3
  89. package/src/components/activity-list/activity-list.js +61 -1
  90. package/src/components/app-icon/app-icon.css +14 -3
  91. package/src/components/app-icon/app-icon.js +11 -1
  92. package/src/components/app-rail/app-rail.css +59 -79
  93. package/src/components/app-sidebar/app-sidebar.css +304 -168
  94. package/src/components/app-sidebar/app-sidebar.js +667 -46
  95. package/src/components/aurora/aurora.css +5 -3
  96. package/src/components/avatar/avatar.css +32 -7
  97. package/src/components/avatar/avatar.js +72 -8
  98. package/src/components/badge/badge.css +54 -2
  99. package/src/components/badge/badge.js +29 -2
  100. package/src/components/breadcrumb/breadcrumb.css +1 -1
  101. package/src/components/button/button.css +67 -9
  102. package/src/components/button/button.js +38 -0
  103. package/src/components/calendar/calendar.css +47 -47
  104. package/src/components/calendar/calendar.js +26 -52
  105. package/src/components/card/card.css +4 -4
  106. package/src/components/card-view/card-view.css +14 -12
  107. package/src/components/card-view/card-view.js +13 -9
  108. package/src/components/card-view/record-card.js +14 -3
  109. package/src/components/chart/chart.css +4 -1
  110. package/src/components/chart/chart.js +12 -0
  111. package/src/components/check-button/check-button.css +10 -2
  112. package/src/components/checklist/checklist.css +9 -2
  113. package/src/components/checklist/checklist.js +11 -5
  114. package/src/components/checklist/field-adapter.js +3 -1
  115. package/src/components/code-editor/code-editor.css +7 -6
  116. package/src/components/code-editor/code-editor.js +19 -1
  117. package/src/components/code-editor/field-adapter.js +9 -2
  118. package/src/components/context-menu/context-menu.css +9 -4
  119. package/src/components/context-menu/context-menu.js +8 -2
  120. package/src/components/copy/copy-button.css +6 -0
  121. package/src/components/copy/copy-input.css +9 -4
  122. package/src/components/data-filter/data-filter.css +5 -4
  123. package/src/components/data-filter/data-filter.js +2 -2
  124. package/src/components/date-picker/date-picker.css +6 -6
  125. package/src/components/date-picker/date-range-picker.css +3 -3
  126. package/src/components/date-picker/time-picker.css +3 -3
  127. package/src/components/datebox/date-range-box.css +79 -2
  128. package/src/components/datebox/date-range-box.js +13 -2
  129. package/src/components/datebox/datebox.css +79 -2
  130. package/src/components/datebox/datebox.js +13 -2
  131. package/src/components/dialog/dialog.css +26 -0
  132. package/src/components/dialog/dialog.js +99 -17
  133. package/src/components/dock/dock.css +5 -4
  134. package/src/components/dropdown/dropdown.css +1 -1
  135. package/src/components/dropdown/dropdown.js +159 -72
  136. package/src/components/empty-state/empty-state.css +2 -2
  137. package/src/components/entity-ref/entity-ref.css +1 -1
  138. package/src/components/entity-ref/entity-ref.js +1 -1
  139. package/src/components/field/field.css +28 -9
  140. package/src/components/field/field.js +101 -29
  141. package/src/components/field-upload/field-upload.css +1 -1
  142. package/src/components/fieldset/external-adapter.js +363 -0
  143. package/src/components/fieldset/fieldset.css +5 -3
  144. package/src/components/fieldset/fieldset.js +38 -64
  145. package/src/components/file-item/file-item.js +144 -10
  146. package/src/components/file-list/file-list.js +144 -21
  147. package/src/components/filter/filter.css +86 -2
  148. package/src/components/filter/filter.js +307 -11
  149. package/src/components/filter-panel/filter-panel.css +1 -1
  150. package/src/components/filter-panel/filter-panel.js +149 -32
  151. package/src/components/finder/finder.css +16 -14
  152. package/src/components/form/form.css +5 -4
  153. package/src/components/form/form.js +11 -2
  154. package/src/components/grid/grid.css +1 -1
  155. package/src/components/groupbox/groupbox.css +1 -1
  156. package/src/components/kanban-view/kanban-card.js +11 -3
  157. package/src/components/kanban-view/kanban-view.css +42 -18
  158. package/src/components/kanban-view/kanban-view.js +9 -6
  159. package/src/components/launcher/launcher.css +108 -26
  160. package/src/components/launcher/launcher.js +530 -42
  161. package/src/components/list-toolbar/list-toolbar.css +13 -8
  162. package/src/components/list-toolbar/list-toolbar.js +40 -14
  163. package/src/components/master-panel/master-panel.css +2 -0
  164. package/src/components/master-panel/master-panel.js +0 -1
  165. package/src/components/menu-button/menu-button.css +72 -4
  166. package/src/components/menu-button/menu-button.js +160 -18
  167. package/src/components/message/message.css +33 -3
  168. package/src/components/message/message.js +264 -22
  169. package/src/components/modal/modal.css +1 -1
  170. package/src/components/modal/modal.js +83 -15
  171. package/src/components/module-bar/module-bar.css +486 -0
  172. package/src/components/module-bar/module-bar.js +1074 -0
  173. package/src/components/multi-value-editor/multi-value-editor.css +1 -1
  174. package/src/components/navigation-bar/navigation-bar.css +18 -9
  175. package/src/components/number-field/field-adapter.js +3 -1
  176. package/src/components/number-field/number-field.css +70 -0
  177. package/src/components/number-field/number-field.js +2 -0
  178. package/src/components/pagination/pagination.css +13 -11
  179. package/src/components/pagination/pagination.js +20 -4
  180. package/src/components/panel/panel.css +4 -3
  181. package/src/components/questionnaire/questionnaire.css +4 -4
  182. package/src/components/rating/field-adapter.js +2 -1
  183. package/src/components/rating/rating.css +8 -1
  184. package/src/components/search/search.css +4 -1
  185. package/src/components/select/color.js +22 -0
  186. package/src/components/select/field-adapter.js +2 -0
  187. package/src/components/select/glyphs.js +165 -0
  188. package/src/components/select/select.css +138 -45
  189. package/src/components/select/select.js +92 -47
  190. package/src/components/sheet/sheet.css +12 -9
  191. package/src/components/sheet/sheet.js +74 -32
  192. package/src/components/slider/field-adapter.js +6 -1
  193. package/src/components/slider/slider.css +18 -4
  194. package/src/components/slider/slider.js +1 -1
  195. package/src/components/sort-control/sort-control.css +4 -1
  196. package/src/components/split-view/split-view.css +1 -1
  197. package/src/components/stat-tile/stat-tile.css +42 -47
  198. package/src/components/stat-tile/stat-tile.js +17 -6
  199. package/src/components/stepper/stepper.css +1 -1
  200. package/src/components/tabbox/tabbox.css +41 -32
  201. package/src/components/tabbox/tabbox.js +5 -1
  202. package/src/components/table/table.css +187 -37
  203. package/src/components/table/table.js +718 -73
  204. package/src/components/tag-picker/field-adapter.js +2 -1
  205. package/src/components/tag-picker/tag-picker.css +83 -5
  206. package/src/components/tag-picker/tag-picker.js +25 -8
  207. package/src/components/timebox/timebox.css +22 -2
  208. package/src/components/toggle/toggle.css +12 -1
  209. package/src/components/toolbar/toolbar.js +2 -2
  210. package/src/components/tooltip/tooltip.css +4 -0
  211. package/src/components/tooltip/tooltip.js +44 -19
  212. package/src/components/tree/tree.css +26 -17
  213. package/src/components/tree/tree.js +31 -0
  214. package/src/components/value-list/value-list.css +3 -3
  215. package/src/components/view/record-view.css +1 -1
  216. package/src/components/view/record-view.js +178 -18
  217. package/src/components/view-settings/view-settings.css +285 -0
  218. package/src/components/view-settings/view-settings.js +1830 -0
  219. package/src/components/workspace-switcher/workspace-switcher.css +188 -0
  220. package/src/components/workspace-switcher/workspace-switcher.js +463 -0
  221. package/src/core/breakpoint.js +1 -1
  222. package/src/core/component.js +88 -17
  223. package/src/core/fontawesome.js +5 -1
  224. package/src/core/i18n.js +47 -4
  225. package/src/core/icons.js +204 -61
  226. package/src/core/keyboard.js +206 -11
  227. package/src/core/messages.js +427 -0
  228. package/src/core/motion.js +147 -0
  229. package/src/core/overlay-host.js +77 -3
  230. package/src/core/overlay-stack.js +487 -0
  231. package/src/core/position.js +22 -3
  232. package/src/index.js +10 -5
  233. package/src/internal/app-rail.js +135 -55
  234. package/src/internal/menu-items.js +61 -3
  235. package/src/zeyos/connect.js +6 -2
  236. package/src/zeyos/form.js +69 -27
  237. package/src/zeyos/index.js +4 -1
  238. package/src/zeyos/launcher.js +8 -3
  239. package/src/zeyos/module-bar.js +181 -0
  240. package/src/zeyos/query.js +197 -13
  241. package/src/zeyos/schema.js +144 -27
  242. package/src/zeyos/table.js +287 -84
  243. package/src/zeyos/view.js +49 -93
  244. package/styles/base.css +72 -1
  245. package/styles/icons.css +11 -1
  246. package/styles/print.css +1 -1
  247. package/styles/tokens/dark.css +117 -37
  248. package/styles/tokens/global.css +121 -27
  249. package/styles/tokens/semantic.css +140 -43
  250. package/styles/tokens/themes.css +7 -6
  251. package/styles/zx.css +3 -1
  252. package/styles/tokens/density.css +0 -9
@@ -1,4 +1,4 @@
1
- import { dateToUnixSeconds, unixSecondsToDate } from './query.js';
1
+ import { calendarZone, dateToUnixSeconds, normalizeTimeZone, unixSecondsToDate } from './query.js';
2
2
 
3
3
  /** @typedef {Record<string, unknown>} FieldMeta */
4
4
  /**
@@ -11,6 +11,13 @@ import { dateToUnixSeconds, unixSecondsToDate } from './query.js';
11
11
  * @property {string[]} [fields] Curated allow-list; its order becomes the output order.
12
12
  * @property {string[]} [exclude] Field ids to omit.
13
13
  * @property {Record<string, string>} [labels] Per-field label overrides.
14
+ * @property {Record<string, string>} [formats] Per-field semantic format overrides (`date`,
15
+ * `datetime`, `money`, or any registered key). The schema types a timestamp only by its storage,
16
+ * so this is how a Unix-second field the built-in rules misread is declared a calendar day
17
+ * (`date`) or an instant (`datetime`).
18
+ * @property {string} [timeZone] IANA time zone of the ZeyOS instance, such as `Europe/Vienna`.
19
+ * Date-only fields store midnight of a calendar day in this zone; it is copied onto every field's
20
+ * metadata as `timeZone`. Defaults to the runtime's own zone.
14
21
  */
15
22
 
16
23
  /**
@@ -22,6 +29,49 @@ import { dateToUnixSeconds, unixSecondsToDate } from './query.js';
22
29
  */
23
30
  export const TYPE_MAP = Object.create(null);
24
31
 
32
+ /**
33
+ * Unix-second fields ZeyOS stores as calendar days (midnight in the instance's zone) rather than
34
+ * instants: document and due dates, validity ranges, birthdays. `date` counts only when indexed —
35
+ * the unindexed ones (`imports`, `couponcodes`) record when something happened.
36
+ */
37
+ const DATE_ONLY_FIELDS = new Set(['date', 'duedate', 'birthdate', 'datefrom', 'dateto', 'datecancel', 'lastbilling']);
38
+
39
+ /**
40
+ * Fields with a date-only name that hold instants on their resource: appointment and event times,
41
+ * and when a stream record, comment, or document version was written.
42
+ */
43
+ const INSTANT_FIELDS = new Set([
44
+ 'appointments.datefrom', 'appointments.dateto', 'events.datefrom', 'events.dateto',
45
+ 'comments.date', 'documentversions.date', 'records.date'
46
+ ]);
47
+
48
+ /** Readable words for the ZeyOS enum constants that run several words together. */
49
+ const ENUM_WORDS = Object.freeze({
50
+ AWAITINGACCEPTANCE: 'awaiting acceptance',
51
+ AWAITINGAPPROVAL: 'awaiting approval',
52
+ BILLINGONLY: 'billing only',
53
+ CUSTOMERANDSUPPLIER: 'customer and supplier',
54
+ FEEDBACKREQUIRED: 'feedback required',
55
+ INEVALUATION: 'in evaluation',
56
+ INNEGOTIATION: 'in negotiation',
57
+ INREVISION: 'in revision',
58
+ NOSTOCK: 'no stock',
59
+ NOTSTARTED: 'not started',
60
+ PARTLYDELIVERED: 'partly delivered',
61
+ PARTLYINVOICED: 'partly invoiced',
62
+ PARTLYORDERED: 'partly ordered',
63
+ PARTLYPAID: 'partly paid',
64
+ PROCUREMENTONLY: 'procurement only',
65
+ REMOTECALL: 'remote call',
66
+ SERIALSANDCHARGES: 'serials and charges'
67
+ });
68
+
69
+ /** Labels for a priority field whose schema carries no enum. */
70
+ const PRIORITY_LABELS = Object.freeze({ 0: 'Lowest', 1: 'Low', 2: 'Medium', 3: 'High', 4: 'Highest' });
71
+
72
+ /** An enum name in the constant style ZeyOS uses for stored values (`INVOICED`, `BILLING_QUOTE`). */
73
+ const ENUM_CONSTANT = /^[A-Z][A-Z\d]*(?:_[A-Z\d]+)*$/;
74
+
25
75
  const warnedUnknownTypes = new Set();
26
76
 
27
77
  /**
@@ -74,7 +124,8 @@ export function fieldToZxField(meta) {
74
124
  /**
75
125
  * Converts normalized ZeyOS field metadata to a Zx Table column configuration. Renderers return
76
126
  * strings only (never DOM): references/enums show labels, numeric columns are right-aligned,
77
- * booleans show a check, and Unix seconds are formatted as dates.
127
+ * booleans show a check, and Unix seconds are formatted as dates — a date-only field as the
128
+ * calendar day it names in `meta.timeZone`, with no time; a date-time field with its time.
78
129
  * @param {FieldMeta} meta Normalized metadata containing at least `id` or `name`.
79
130
  * @returns {Record<string, unknown>} Plain Zx Table column descriptor.
80
131
  */
@@ -94,6 +145,8 @@ export function fieldToZxColumn(meta) {
94
145
  * client returns names from `schema.fields(resource)` and definitions from
95
146
  * `schema.describe(resource).fields`; embedded `enum` data is authoritative. A compatible
96
147
  * `schema.enums(resource, field)` is used when supplied by another client version/stub.
148
+ * `formats` overrides a field's semantic `format`, and `timeZone` is validated once and copied
149
+ * onto every field.
97
150
  * @param {Record<string, any>} client Injected `@zeyos/client` instance.
98
151
  * @param {string} resource Schema resource name such as `tickets`.
99
152
  * @param {ResolveFieldOptions} [opts={}] Curation options.
@@ -119,6 +172,8 @@ export function resolveFields(client, resource, opts = {}) {
119
172
  const requested = Array.isArray(opts.fields) ? opts.fields.map(String) : [...available.keys()];
120
173
  const excluded = new Set(Array.isArray(opts.exclude) ? opts.exclude.map(String) : []);
121
174
  const labels = opts.labels && typeof opts.labels === 'object' ? opts.labels : {};
175
+ const formats = opts.formats && typeof opts.formats === 'object' ? opts.formats : {};
176
+ const timeZone = normalizeTimeZone(opts.timeZone);
122
177
  const result = [];
123
178
 
124
179
  for (const id of requested) {
@@ -131,6 +186,8 @@ export function resolveFields(client, resource, opts = {}) {
131
186
  if (meta.enum == null) meta.enum = enumValues;
132
187
  }
133
188
  if (Object.prototype.hasOwnProperty.call(labels, id)) meta.label = String(labels[id]);
189
+ if (Object.prototype.hasOwnProperty.call(formats, id) && formats[id]) meta.format = String(formats[id]);
190
+ if (timeZone) meta.timeZone = timeZone;
134
191
  result.push(meta);
135
192
  }
136
193
  return result;
@@ -164,7 +221,7 @@ const enumColumn = {
164
221
  };
165
222
  const priorityColumn = {
166
223
  field: { type: 'zxselect', props: { preset: 'priority' } },
167
- column: (meta) => ({ render: enumRenderer(meta, priorityOptions()) })
224
+ column: (meta) => ({ render: enumRenderer(meta, PRIORITY_LABELS) })
168
225
  };
169
226
  const percentColumn = {
170
227
  field: { type: 'float', props: { min: 0, max: 100 } },
@@ -212,10 +269,13 @@ for (const type of ['email', 'tel', 'url', 'uri']) {
212
269
  function dateStrategy(type) {
213
270
  return {
214
271
  field: { type },
215
- column: (meta) => ({
216
- render: (row) => formatUnixDate(rowValue(row, meta), type === 'datetime'),
217
- sortValue: (row) => unixSortValue(rowValue(row, meta))
218
- })
272
+ column: (meta) => {
273
+ const format = type === 'datetime' ? instantFormatter() : calendarDayFormatter(meta.timeZone);
274
+ return {
275
+ render: (row) => format(rowValue(row, meta)),
276
+ sortValue: (row) => unixSortValue(rowValue(row, meta))
277
+ };
278
+ }
219
279
  };
220
280
  }
221
281
 
@@ -241,9 +301,8 @@ function strategyKey(meta) {
241
301
 
242
302
  const raw = normalizeType(meta.type);
243
303
  if (raw === 'bigint' || raw === 'int64') {
244
- const id = String(meta.id).toLowerCase();
245
- if (id === 'date' && meta.indexed) return 'date';
246
- if (/(?:date|time)$/.test(id)) return 'datetime';
304
+ const temporal = timestampKind(meta);
305
+ if (temporal) return temporal;
247
306
  }
248
307
  if (isLongText(meta, raw)) return 'longtext';
249
308
  if (raw && TYPE_MAP[raw]) return raw;
@@ -255,6 +314,22 @@ function strategyKey(meta) {
255
314
  return raw || semantic;
256
315
  }
257
316
 
317
+ /**
318
+ * Tells a calendar-day timestamp from an instant by the field's name and resource, since the schema
319
+ * types both as `bigint`.
320
+ * @param {FieldMeta} meta
321
+ * @returns {'date'|'datetime'|null}
322
+ */
323
+ function timestampKind(meta) {
324
+ const id = String(meta.id).toLowerCase();
325
+ const resource = String(meta.resource ?? '').toLowerCase();
326
+ if (DATE_ONLY_FIELDS.has(id) && !INSTANT_FIELDS.has(`${resource}.${id}`)) {
327
+ if (id !== 'date' || meta.indexed) return 'date';
328
+ }
329
+ if (INSTANT_FIELDS.has(`${resource}.${id}`) || /(?:date|time)$|^lastmodified$/.test(id)) return 'datetime';
330
+ return null;
331
+ }
332
+
258
333
  /** @param {FieldMeta} meta @returns {FieldMeta & {id: string}} */
259
334
  function normalizeMeta(meta) {
260
335
  if (!meta || typeof meta !== 'object' || Array.isArray(meta)) throw new TypeError('Field metadata must be an object');
@@ -362,31 +437,41 @@ function normalizeEnumOptions(values) {
362
437
  return Object.fromEntries(values.map((entry, index) => {
363
438
  if (Array.isArray(entry)) {
364
439
  const [value = index, label = value] = entry;
365
- return [String(value), String(label)];
440
+ return [String(value), enumLabel(label)];
366
441
  }
367
442
  if (entry && typeof entry === 'object') {
368
443
  const value = entry.value ?? entry.id ?? index;
369
- return [String(value), String(entry.label ?? entry.name ?? value)];
444
+ return [String(value), entry.label != null ? String(entry.label) : enumLabel(entry.name ?? value)];
370
445
  }
371
- return [String(index), String(entry)];
446
+ return [String(index), enumLabel(entry)];
372
447
  }));
373
448
  }
374
449
  if (values && typeof values === 'object') {
375
- return Object.fromEntries(Object.entries(values).map(([value, label]) => [value, String(label)]));
450
+ return Object.fromEntries(Object.entries(values).map(([value, label]) => [value, enumLabel(label)]));
376
451
  }
377
452
  return {};
378
453
  }
379
454
 
455
+ /**
456
+ * Turns a stored enum name into its label. A label the schema gives (`{value, label}`) never reaches
457
+ * this; what does is usually a constant such as `INVOICED` or `PARTLYPAID_CANCELLED`, shown in
458
+ * sentence case with its words separated ("Invoiced", "Partly paid cancelled"). Anything else is
459
+ * already a label and is kept as it is.
460
+ * @param {unknown} name Stored enum name.
461
+ * @returns {string}
462
+ */
463
+ function enumLabel(name) {
464
+ const text = String(name ?? '');
465
+ if (!ENUM_CONSTANT.test(text)) return text;
466
+ const words = text.split('_').map((part) => ENUM_WORDS[part] ?? part.toLowerCase()).join(' ');
467
+ return words.charAt(0).toUpperCase() + words.slice(1);
468
+ }
469
+
380
470
  /** @param {FieldMeta} meta @returns {'optionlist'|'select'} */
381
471
  function enumFieldType(meta) {
382
472
  return Object.keys(enumOptions(meta)).length <= 5 ? 'optionlist' : 'select';
383
473
  }
384
474
 
385
- /** @returns {Record<string, string>} */
386
- function priorityOptions() {
387
- return { '0': 'LOWEST', '1': 'LOW', '2': 'MEDIUM', '3': 'HIGH', '4': 'HIGHEST' };
388
- }
389
-
390
475
  /** @param {FieldMeta} meta @param {Record<string, string>} [fallback] @returns {(row: Record<string, unknown>) => string} */
391
476
  function enumRenderer(meta, fallback = {}) {
392
477
  const labels = { ...fallback, ...enumOptions(meta) };
@@ -426,17 +511,49 @@ function formatPercent(value) {
426
511
  return number == null ? '' : `${new Intl.NumberFormat().format(number)}%`;
427
512
  }
428
513
 
429
- /** @param {unknown} value @param {boolean} includeTime @returns {string} */
430
- function formatUnixDate(value, includeTime) {
431
- if (value == null || value === '') return '';
514
+ /**
515
+ * Formats a date-time field: the instant, in the viewer's zone, with its time.
516
+ * @returns {(value: unknown) => string}
517
+ */
518
+ function instantFormatter() {
519
+ const formatter = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
520
+ return (value) => {
521
+ const date = timestampDate(value);
522
+ return date ? formatter.format(date) : '';
523
+ };
524
+ }
525
+
526
+ /**
527
+ * Formats a date-only field: the calendar day the stored midnight names in the instance's zone,
528
+ * with no time, so neither the viewer's zone nor daylight saving can move it.
529
+ * @param {unknown} timeZone Instance zone from the field metadata; the runtime's own when absent.
530
+ * @returns {(value: unknown) => string}
531
+ */
532
+ function calendarDayFormatter(timeZone) {
533
+ const zone = calendarZone(/** @type {string|undefined} */ (timeZone ?? undefined));
534
+ // The day is formatted as a UTC date so the formatter cannot shift it a second time.
535
+ const formatter = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeZone: 'UTC' });
536
+ return (value) => {
537
+ const date = timestampDate(value);
538
+ if (!date) return '';
539
+ // A Date value is already a local calendar day (a form's own value, say); seconds are stored.
540
+ const { year, month, day } = value instanceof Date
541
+ ? { year: date.getFullYear(), month: date.getMonth(), day: date.getDate() }
542
+ : zone.dayOf(date.getTime());
543
+ const utc = new Date(0);
544
+ utc.setUTCFullYear(year, month, day);
545
+ return formatter.format(utc);
546
+ };
547
+ }
548
+
549
+ /** @param {unknown} value Unix seconds or a Date. @returns {Date|null} */
550
+ function timestampDate(value) {
551
+ if (value == null || value === '') return null;
432
552
  try {
433
553
  const date = value instanceof Date ? value : unixSecondsToDate(/** @type {number|string} */ (value));
434
- if (!date || !Number.isFinite(date.getTime())) return '';
435
- return new Intl.DateTimeFormat(undefined, includeTime
436
- ? { dateStyle: 'medium', timeStyle: 'short' }
437
- : { dateStyle: 'medium' }).format(date);
554
+ return date && Number.isFinite(date.getTime()) ? date : null;
438
555
  } catch {
439
- return '';
556
+ return null;
440
557
  }
441
558
  }
442
559