@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.
- package/CHANGELOG.md +447 -0
- package/README.md +44 -11
- package/dist/types/components/account-menu/account-menu.d.ts +8 -0
- package/dist/types/components/activity-list/activity-list.d.ts +31 -1
- package/dist/types/components/app-icon/app-icon.d.ts +14 -2
- package/dist/types/components/app-sidebar/app-sidebar.d.ts +293 -17
- package/dist/types/components/avatar/avatar.d.ts +46 -7
- package/dist/types/components/badge/badge.d.ts +21 -1
- package/dist/types/components/button/button.d.ts +15 -0
- package/dist/types/components/calendar/calendar.d.ts +67 -5
- package/dist/types/components/card-view/card-view.d.ts +7 -4
- package/dist/types/components/card-view/record-card.d.ts +11 -0
- package/dist/types/components/chart/chart.d.ts +10 -0
- package/dist/types/components/checklist/checklist.d.ts +9 -0
- package/dist/types/components/code-editor/code-editor.d.ts +6 -17
- package/dist/types/components/context-menu/context-menu.d.ts +6 -2
- package/dist/types/components/data-filter/data-filter.d.ts +4 -4
- package/dist/types/components/datebox/date-range-box.d.ts +5 -1
- package/dist/types/components/datebox/datebox.d.ts +7 -2
- package/dist/types/components/dialog/dialog.d.ts +46 -6
- package/dist/types/components/dropdown/dropdown.d.ts +24 -9
- package/dist/types/components/entity-ref/entity-ref.d.ts +2 -2
- package/dist/types/components/field/field.d.ts +54 -2
- package/dist/types/components/fieldset/external-adapter.d.ts +83 -0
- package/dist/types/components/fieldset/fieldset.d.ts +26 -1
- package/dist/types/components/file-item/file-item.d.ts +34 -6
- package/dist/types/components/file-list/file-list.d.ts +35 -3
- package/dist/types/components/filter/filter.d.ts +127 -3
- package/dist/types/components/filter-panel/filter-panel.d.ts +36 -7
- package/dist/types/components/form/form.d.ts +12 -1
- package/dist/types/components/kanban-view/kanban-card.d.ts +8 -0
- package/dist/types/components/launcher/launcher.d.ts +268 -15
- package/dist/types/components/list-toolbar/list-toolbar.d.ts +16 -7
- package/dist/types/components/menu-button/menu-button.d.ts +39 -5
- package/dist/types/components/message/message.d.ts +132 -17
- package/dist/types/components/modal/modal.d.ts +43 -2
- package/dist/types/components/module-bar/module-bar.d.ts +395 -0
- package/dist/types/components/pagination/pagination.d.ts +17 -3
- package/dist/types/components/select/color.d.ts +12 -0
- package/dist/types/components/select/glyphs.d.ts +124 -0
- package/dist/types/components/select/select.d.ts +17 -3
- package/dist/types/components/sheet/sheet.d.ts +15 -0
- package/dist/types/components/stat-tile/stat-tile.d.ts +16 -5
- package/dist/types/components/tabbox/tabbox.d.ts +9 -0
- package/dist/types/components/table/table.d.ts +311 -18
- package/dist/types/components/tag-picker/tag-picker.d.ts +21 -4
- package/dist/types/components/tree/tree.d.ts +13 -0
- package/dist/types/components/view/record-view.d.ts +59 -2
- package/dist/types/components/view-settings/view-settings.d.ts +879 -0
- package/dist/types/components/workspace-switcher/workspace-switcher.d.ts +327 -0
- package/dist/types/core/breakpoint.d.ts +1 -1
- package/dist/types/core/component.d.ts +12 -2
- package/dist/types/core/i18n.d.ts +27 -3
- package/dist/types/core/icons.d.ts +23 -25
- package/dist/types/core/keyboard.d.ts +98 -1
- package/dist/types/core/messages.d.ts +382 -0
- package/dist/types/core/motion.d.ts +59 -0
- package/dist/types/core/overlay-host.d.ts +42 -1
- package/dist/types/core/overlay-stack.d.ts +260 -0
- package/dist/types/index.d.ts +10 -5
- package/dist/types/internal/app-rail.d.ts +38 -0
- package/dist/types/internal/menu-items.d.ts +71 -3
- package/dist/types/zeyos/connect.d.ts +6 -0
- package/dist/types/zeyos/form.d.ts +50 -9
- package/dist/types/zeyos/index.d.ts +2 -1
- package/dist/types/zeyos/launcher.d.ts +9 -0
- package/dist/types/zeyos/module-bar.d.ts +176 -0
- package/dist/types/zeyos/query.d.ts +110 -5
- package/dist/types/zeyos/schema.d.ts +24 -1
- package/dist/types/zeyos/table.d.ts +345 -22
- package/dist/types/zeyos/view.d.ts +26 -2
- package/dist/zx-zeyos.esm.js +6178 -1008
- package/dist/zx-zeyos.esm.min.js +53 -5
- package/dist/zx.css +2861 -827
- package/dist/zx.esm.js +8909 -1480
- package/dist/zx.esm.min.js +55 -7
- package/dist/zx.global.js +8911 -1482
- package/dist/zx.global.min.js +55 -7
- package/dist/zx.min.css +1 -1
- package/docs/api.json +1079 -117
- package/docs/llms.md +956 -154
- package/docs/llms.txt +9 -5
- package/package.json +1 -1
- package/src/components/account-menu/account-menu.css +35 -10
- package/src/components/account-menu/account-menu.js +12 -0
- package/src/components/activity-item/activity-item.css +1 -1
- package/src/components/activity-item/activity-item.js +3 -0
- package/src/components/activity-list/activity-list.css +38 -3
- package/src/components/activity-list/activity-list.js +61 -1
- package/src/components/app-icon/app-icon.css +14 -3
- package/src/components/app-icon/app-icon.js +11 -1
- package/src/components/app-rail/app-rail.css +59 -79
- package/src/components/app-sidebar/app-sidebar.css +304 -168
- package/src/components/app-sidebar/app-sidebar.js +667 -46
- package/src/components/aurora/aurora.css +5 -3
- package/src/components/avatar/avatar.css +32 -7
- package/src/components/avatar/avatar.js +72 -8
- package/src/components/badge/badge.css +54 -2
- package/src/components/badge/badge.js +29 -2
- package/src/components/breadcrumb/breadcrumb.css +1 -1
- package/src/components/button/button.css +67 -9
- package/src/components/button/button.js +38 -0
- package/src/components/calendar/calendar.css +47 -47
- package/src/components/calendar/calendar.js +26 -52
- package/src/components/card/card.css +4 -4
- package/src/components/card-view/card-view.css +14 -12
- package/src/components/card-view/card-view.js +13 -9
- package/src/components/card-view/record-card.js +14 -3
- package/src/components/chart/chart.css +4 -1
- package/src/components/chart/chart.js +12 -0
- package/src/components/check-button/check-button.css +10 -2
- package/src/components/checklist/checklist.css +9 -2
- package/src/components/checklist/checklist.js +11 -5
- package/src/components/checklist/field-adapter.js +3 -1
- package/src/components/code-editor/code-editor.css +7 -6
- package/src/components/code-editor/code-editor.js +19 -1
- package/src/components/code-editor/field-adapter.js +9 -2
- package/src/components/context-menu/context-menu.css +9 -4
- package/src/components/context-menu/context-menu.js +8 -2
- package/src/components/copy/copy-button.css +6 -0
- package/src/components/copy/copy-input.css +9 -4
- package/src/components/data-filter/data-filter.css +5 -4
- package/src/components/data-filter/data-filter.js +2 -2
- package/src/components/date-picker/date-picker.css +6 -6
- package/src/components/date-picker/date-range-picker.css +3 -3
- package/src/components/date-picker/time-picker.css +3 -3
- package/src/components/datebox/date-range-box.css +79 -2
- package/src/components/datebox/date-range-box.js +13 -2
- package/src/components/datebox/datebox.css +79 -2
- package/src/components/datebox/datebox.js +13 -2
- package/src/components/dialog/dialog.css +26 -0
- package/src/components/dialog/dialog.js +99 -17
- package/src/components/dock/dock.css +5 -4
- package/src/components/dropdown/dropdown.css +1 -1
- package/src/components/dropdown/dropdown.js +159 -72
- package/src/components/empty-state/empty-state.css +2 -2
- package/src/components/entity-ref/entity-ref.css +1 -1
- package/src/components/entity-ref/entity-ref.js +1 -1
- package/src/components/field/field.css +28 -9
- package/src/components/field/field.js +101 -29
- package/src/components/field-upload/field-upload.css +1 -1
- package/src/components/fieldset/external-adapter.js +363 -0
- package/src/components/fieldset/fieldset.css +5 -3
- package/src/components/fieldset/fieldset.js +38 -64
- package/src/components/file-item/file-item.js +144 -10
- package/src/components/file-list/file-list.js +144 -21
- package/src/components/filter/filter.css +86 -2
- package/src/components/filter/filter.js +307 -11
- package/src/components/filter-panel/filter-panel.css +1 -1
- package/src/components/filter-panel/filter-panel.js +149 -32
- package/src/components/finder/finder.css +16 -14
- package/src/components/form/form.css +5 -4
- package/src/components/form/form.js +11 -2
- package/src/components/grid/grid.css +1 -1
- package/src/components/groupbox/groupbox.css +1 -1
- package/src/components/kanban-view/kanban-card.js +11 -3
- package/src/components/kanban-view/kanban-view.css +42 -18
- package/src/components/kanban-view/kanban-view.js +9 -6
- package/src/components/launcher/launcher.css +108 -26
- package/src/components/launcher/launcher.js +530 -42
- package/src/components/list-toolbar/list-toolbar.css +13 -8
- package/src/components/list-toolbar/list-toolbar.js +40 -14
- package/src/components/master-panel/master-panel.css +2 -0
- package/src/components/master-panel/master-panel.js +0 -1
- package/src/components/menu-button/menu-button.css +72 -4
- package/src/components/menu-button/menu-button.js +160 -18
- package/src/components/message/message.css +33 -3
- package/src/components/message/message.js +264 -22
- package/src/components/modal/modal.css +1 -1
- package/src/components/modal/modal.js +83 -15
- package/src/components/module-bar/module-bar.css +486 -0
- package/src/components/module-bar/module-bar.js +1074 -0
- package/src/components/multi-value-editor/multi-value-editor.css +1 -1
- package/src/components/navigation-bar/navigation-bar.css +18 -9
- package/src/components/number-field/field-adapter.js +3 -1
- package/src/components/number-field/number-field.css +70 -0
- package/src/components/number-field/number-field.js +2 -0
- package/src/components/pagination/pagination.css +13 -11
- package/src/components/pagination/pagination.js +20 -4
- package/src/components/panel/panel.css +4 -3
- package/src/components/questionnaire/questionnaire.css +4 -4
- package/src/components/rating/field-adapter.js +2 -1
- package/src/components/rating/rating.css +8 -1
- package/src/components/search/search.css +4 -1
- package/src/components/select/color.js +22 -0
- package/src/components/select/field-adapter.js +2 -0
- package/src/components/select/glyphs.js +165 -0
- package/src/components/select/select.css +138 -45
- package/src/components/select/select.js +92 -47
- package/src/components/sheet/sheet.css +12 -9
- package/src/components/sheet/sheet.js +74 -32
- package/src/components/slider/field-adapter.js +6 -1
- package/src/components/slider/slider.css +18 -4
- package/src/components/slider/slider.js +1 -1
- package/src/components/sort-control/sort-control.css +4 -1
- package/src/components/split-view/split-view.css +1 -1
- package/src/components/stat-tile/stat-tile.css +42 -47
- package/src/components/stat-tile/stat-tile.js +17 -6
- package/src/components/stepper/stepper.css +1 -1
- package/src/components/tabbox/tabbox.css +41 -32
- package/src/components/tabbox/tabbox.js +5 -1
- package/src/components/table/table.css +187 -37
- package/src/components/table/table.js +718 -73
- package/src/components/tag-picker/field-adapter.js +2 -1
- package/src/components/tag-picker/tag-picker.css +83 -5
- package/src/components/tag-picker/tag-picker.js +25 -8
- package/src/components/timebox/timebox.css +22 -2
- package/src/components/toggle/toggle.css +12 -1
- package/src/components/toolbar/toolbar.js +2 -2
- package/src/components/tooltip/tooltip.css +4 -0
- package/src/components/tooltip/tooltip.js +44 -19
- package/src/components/tree/tree.css +26 -17
- package/src/components/tree/tree.js +31 -0
- package/src/components/value-list/value-list.css +3 -3
- package/src/components/view/record-view.css +1 -1
- package/src/components/view/record-view.js +178 -18
- package/src/components/view-settings/view-settings.css +285 -0
- package/src/components/view-settings/view-settings.js +1830 -0
- package/src/components/workspace-switcher/workspace-switcher.css +188 -0
- package/src/components/workspace-switcher/workspace-switcher.js +463 -0
- package/src/core/breakpoint.js +1 -1
- package/src/core/component.js +88 -17
- package/src/core/fontawesome.js +5 -1
- package/src/core/i18n.js +47 -4
- package/src/core/icons.js +204 -61
- package/src/core/keyboard.js +206 -11
- package/src/core/messages.js +427 -0
- package/src/core/motion.js +147 -0
- package/src/core/overlay-host.js +77 -3
- package/src/core/overlay-stack.js +487 -0
- package/src/core/position.js +22 -3
- package/src/index.js +10 -5
- package/src/internal/app-rail.js +135 -55
- package/src/internal/menu-items.js +61 -3
- package/src/zeyos/connect.js +6 -2
- package/src/zeyos/form.js +69 -27
- package/src/zeyos/index.js +4 -1
- package/src/zeyos/launcher.js +8 -3
- package/src/zeyos/module-bar.js +181 -0
- package/src/zeyos/query.js +197 -13
- package/src/zeyos/schema.js +144 -27
- package/src/zeyos/table.js +287 -84
- package/src/zeyos/view.js +49 -93
- package/styles/base.css +72 -1
- package/styles/icons.css +11 -1
- package/styles/print.css +1 -1
- package/styles/tokens/dark.css +117 -37
- package/styles/tokens/global.css +121 -27
- package/styles/tokens/semantic.css +140 -43
- package/styles/tokens/themes.css +7 -6
- package/styles/zx.css +3 -1
- package/styles/tokens/density.css +0 -9
package/src/zeyos/schema.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
217
|
-
|
|
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
|
|
245
|
-
if (
|
|
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),
|
|
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
|
|
444
|
+
return [String(value), entry.label != null ? String(entry.label) : enumLabel(entry.name ?? value)];
|
|
370
445
|
}
|
|
371
|
-
return [String(index),
|
|
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,
|
|
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
|
-
/**
|
|
430
|
-
|
|
431
|
-
|
|
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
|
-
|
|
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
|
|