@object-ui/fields 17.6.0 → 18.0.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 +6228 -0
- package/README.md +251 -9
- package/dist/FieldEditWidget.d.ts +54 -6
- package/dist/coerceToSafeValue.d.ts +54 -0
- package/dist/currency.d.ts +1 -1
- package/dist/fieldHelpText.d.ts +41 -0
- package/dist/index.cjs +5 -5
- package/dist/index.css +68 -5
- package/dist/index.d.ts +446 -69
- package/dist/index.js +5326 -3443
- package/dist/resolveActionParams.d.ts +259 -0
- package/dist/widgets/AvatarField.d.ts +19 -3
- package/dist/widgets/BooleanField.d.ts +1 -1
- package/dist/widgets/DateField.d.ts +1 -1
- package/dist/widgets/DateTimeField.d.ts +1 -1
- package/dist/widgets/FilterConditionField.d.ts +21 -7
- package/dist/widgets/FormulaField.d.ts +41 -0
- package/dist/widgets/GeolocationField.d.ts +9 -3
- package/dist/widgets/GridField.d.ts +73 -101
- package/dist/widgets/LocationField.d.ts +30 -3
- package/dist/widgets/LookupField.d.ts +8 -0
- package/dist/widgets/NumberField.d.ts +1 -1
- package/dist/widgets/ObjectField.d.ts +9 -2
- package/dist/widgets/OptionsEmptyState.d.ts +29 -5
- package/dist/widgets/PasswordField.d.ts +14 -0
- package/dist/widgets/PeoplePicker.d.ts +17 -2
- package/dist/widgets/PercentField.d.ts +2 -1
- package/dist/widgets/PersonRow.d.ts +13 -2
- package/dist/widgets/RecipientPickerField.d.ts +75 -0
- package/dist/widgets/RecordPickerDialog.d.ts +31 -12
- package/dist/widgets/RegistryRefField.d.ts +77 -0
- package/dist/widgets/RichTextField.d.ts +1 -1
- package/dist/widgets/SelectionTray.d.ts +13 -2
- package/dist/widgets/SummaryField.d.ts +30 -0
- package/dist/widgets/TextField.d.ts +1 -1
- package/dist/widgets/TimeField.d.ts +1 -1
- package/dist/widgets/booleanValueLabel.d.ts +18 -0
- package/dist/widgets/date-picker/DatePickerField.d.ts +40 -0
- package/dist/widgets/date-picker/localeDateText.d.ts +39 -0
- package/dist/widgets/deriveLookupColumns.d.ts +1 -1
- package/dist/widgets/file-affordance.d.ts +63 -0
- package/dist/widgets/file-refused.d.ts +17 -0
- package/dist/widgets/file-size-guard.d.ts +5 -23
- package/dist/widgets/file-value.d.ts +49 -9
- package/dist/widgets/longTextCarrierHandoff.d.ts +35 -0
- package/dist/widgets/lookupColumnDisplay.d.ts +26 -9
- package/dist/widgets/nativeDateValue.d.ts +9 -27
- package/dist/widgets/number-format.d.ts +137 -0
- package/dist/widgets/numberBadInput.d.ts +135 -0
- package/dist/widgets/objectRefLabel.d.ts +16 -0
- package/dist/widgets/personDisplay.d.ts +22 -4
- package/dist/widgets/recipientKinds.d.ts +85 -0
- package/dist/widgets/richTextDisplay.d.ts +32 -13
- package/dist/widgets/searchOffer.d.ts +8 -0
- package/dist/widgets/toDomProps.d.ts +26 -4
- package/dist/widgets/toHostGroupProps.d.ts +53 -0
- package/dist/widgets/toHostProps.d.ts +105 -0
- package/dist/widgets/types.d.ts +11 -3
- package/dist/widgets/upload-error-message.d.ts +6 -0
- package/dist/widgets/uploadingScope.d.ts +142 -0
- package/dist/widgets/useCascadingOptions.d.ts +3 -2
- package/dist/widgets/useRecordQuery.d.ts +17 -2
- package/dist/widgets/useUploadingSignal.d.ts +8 -0
- package/package.json +11 -12
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The display text for a native-shaped value (`YYYY-MM-DD`, or
|
|
10
|
+
* `YYYY-MM-DDTHH:mm` when `withTime`). `''` for an empty or unreadable value.
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatLocaleDateText(value: string, locale: string, withTime: boolean): string;
|
|
13
|
+
/**
|
|
14
|
+
* The pattern the text box expects, for its placeholder: the locale's own
|
|
15
|
+
* order and separators with `YYYY` / `MM` / `DD` (and `HH` / `mm`) in place of
|
|
16
|
+
* the digits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function localeDatePattern(locale: string, withTime: boolean): string;
|
|
19
|
+
/**
|
|
20
|
+
* Reads what was typed into the text box.
|
|
21
|
+
*
|
|
22
|
+
* Returns `''` for blank text, the native-shaped value for a real day (and a
|
|
23
|
+
* real clock time when `withTime`), and `null` for text that names no real
|
|
24
|
+
* date. Accepted:
|
|
25
|
+
*
|
|
26
|
+
* - the locale's own digit order, with any separators (`10/16/2026` in `en`,
|
|
27
|
+
* `2026/10/16` in `zh`, `16.10.2026` in `de`);
|
|
28
|
+
* - an ISO date `2026-10-16`, in every locale (a four-digit first group is
|
|
29
|
+
* read as the year);
|
|
30
|
+
* - a two-digit year, read in this century;
|
|
31
|
+
* - with `withTime`: an hour and minute after the date, 24-hour, or 12-hour
|
|
32
|
+
* with `AM` / `PM` or the locale's own afternoon marker. With no time, the
|
|
33
|
+
* time is midnight.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseLocaleDateText(text: string, locale: string, withTime: boolean): string | null;
|
|
36
|
+
/** The local calendar day of `d` as `YYYY-MM-DD`. */
|
|
37
|
+
export declare function toLocalDay(d: Date): string;
|
|
38
|
+
/** Local midnight of a `YYYY-MM-DD` day, for the calendar to select. */
|
|
39
|
+
export declare function fromLocalDay(day: string): Date | undefined;
|
|
@@ -24,7 +24,7 @@ interface ObjectSchemaLike {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Derive sensible Record Picker columns from a referenced object's schema when
|
|
27
|
-
* a lookup field declares no explicit `
|
|
27
|
+
* a lookup field declares no explicit `lookupColumns`.
|
|
28
28
|
*
|
|
29
29
|
* Priority:
|
|
30
30
|
* 1. The referenced object's ADR-0085 `highlightFields` — the canonical
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FileValueView } from './file-value.js';
|
|
3
|
+
/**
|
|
4
|
+
* The translated label and hint for a file the reader may not open
|
|
5
|
+
* (objectui#12339): a value that arrived as the refused marker
|
|
6
|
+
* `{ id, metadataRefused: true }` carries no name of its own, and drawing the
|
|
7
|
+
* generic `fields.file.fileFallback` for it would read as an ordinary file.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useRestrictedFileText(): {
|
|
10
|
+
label: string;
|
|
11
|
+
hint: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The restricted state of one file value (`view.metadataRefused`): a lock
|
|
15
|
+
* and the translated "Restricted file" label instead of a name, and ⛔ no
|
|
16
|
+
* thumbnail — no MIME type was served, so there is nothing to decide one on.
|
|
17
|
+
*
|
|
18
|
+
* It stays an anchor to the view's id-derived URL: whether this reader may
|
|
19
|
+
* download the file is the download endpoint's own decision, and it may
|
|
20
|
+
* answer `403 FILE_DOWNLOAD_DENIED`. The accessible name is the visible
|
|
21
|
+
* label; the hint rides on `title`.
|
|
22
|
+
*
|
|
23
|
+
* `compact` draws the lock alone, for a cell or tile that has no room for
|
|
24
|
+
* the label — the label then becomes the anchor's `aria-label`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function RestrictedFileAffordance({ view, className, compact, icon, }: {
|
|
27
|
+
view: FileValueView;
|
|
28
|
+
className?: string;
|
|
29
|
+
compact?: boolean;
|
|
30
|
+
/** Suppressed where the row already draws its own icon to the left. */
|
|
31
|
+
icon?: boolean;
|
|
32
|
+
}): React.ReactElement;
|
|
33
|
+
/**
|
|
34
|
+
* One file: a keyboard-reachable view/download link when it resolves, and the
|
|
35
|
+
* caller's own `fallback` text when it does not.
|
|
36
|
+
*
|
|
37
|
+
* The anchor's accessible name is the file NAME, carried as its link text, so
|
|
38
|
+
* this needs no `aria-label` and therefore no new translation key — the name
|
|
39
|
+
* itself already comes off the i18n channel at every call site (a value that
|
|
40
|
+
* carries no name of its own falls back to `fields.file.fileFallback`).
|
|
41
|
+
*
|
|
42
|
+
* `target="_blank"` + `rel="noopener noreferrer"` mirrors `UrlCellRenderer`,
|
|
43
|
+
* and the click is `stopPropagation`-guarded so opening a file from inside a
|
|
44
|
+
* grid row does not also trigger row navigation — the same guard
|
|
45
|
+
* `ImageCellRenderer` puts on its thumbnail.
|
|
46
|
+
*
|
|
47
|
+
* ⛔ No `download` attribute: whether the browser views the file inline or
|
|
48
|
+
* saves it is the storage endpoint's decision, signed into the
|
|
49
|
+
* `content-disposition` it returns. Forcing one of the two here would override
|
|
50
|
+
* a choice the platform already makes per file.
|
|
51
|
+
*/
|
|
52
|
+
export declare function FileValueAffordance({ view, fallback, className, icon, }: {
|
|
53
|
+
view: FileValueView;
|
|
54
|
+
/**
|
|
55
|
+
* What to draw when the value resolves to no URL. Required rather than
|
|
56
|
+
* defaulted: every call site already had a text rendering of its own, and a
|
|
57
|
+
* default here would quietly replace one of them.
|
|
58
|
+
*/
|
|
59
|
+
fallback: React.ReactNode;
|
|
60
|
+
className?: string;
|
|
61
|
+
/** Suppressed where the row already draws its own icon or thumbnail. */
|
|
62
|
+
icon?: boolean;
|
|
63
|
+
}): React.ReactElement;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FileRefusedValue } from '@objectstack/spec/data';
|
|
2
|
+
/**
|
|
3
|
+
* Is this value the platform's refused marker `{ id, metadataRefused: true }`?
|
|
4
|
+
*
|
|
5
|
+
* Judged by the spec's own closed `FileRefusedValueSchema`, not by a second
|
|
6
|
+
* hand-written shape here: an object with any other key is not the marker,
|
|
7
|
+
* and reads through `readFileValue`'s ordinary object arm.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isFileRefusedValue(value: unknown): value is FileRefusedValue;
|
|
10
|
+
/**
|
|
11
|
+
* One element of a field value as an editable widget re-submits it beside or
|
|
12
|
+
* after an edit (append, remove, crop): the refused marker is reduced to its
|
|
13
|
+
* bare `sys_file` id — the stored form — and ⛔ never sent back as the marker
|
|
14
|
+
* object, which is a read form no record write accepts. Every other element
|
|
15
|
+
* passes through untouched, as before.
|
|
16
|
+
*/
|
|
17
|
+
export declare function fileValueForResubmit(value: unknown): unknown;
|
|
@@ -1,28 +1,10 @@
|
|
|
1
|
+
import { TranslateFn } from '@object-ui/i18n';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (objectui#
|
|
4
|
-
*
|
|
5
|
-
* Why this is shared rather than mirrored per widget: the guard is the only
|
|
6
|
-
* thing standing between a declared `maxSize` and a real `presigned → PUT →
|
|
7
|
-
* complete` round trip, and `paramToField` copies `maxSize` onto the field
|
|
8
|
-
* config for **every** param type regardless of which widget ends up rendering
|
|
9
|
-
* it. So a widget that re-derives the check drifts silently — the image param
|
|
10
|
-
* shipped receiving the constraint and never reading it, while the file param
|
|
11
|
-
* rejected the identical pick, and nothing failed until QA drove the two side by
|
|
12
|
-
* side. One exported function makes the difference visible: a widget either
|
|
13
|
-
* calls it or conspicuously does not.
|
|
14
|
-
*
|
|
15
|
-
* Both widgets deliberately share the `fields.file.exceedsMaxSize` key too. The
|
|
16
|
-
* sentence names a file and a limit and says nothing file-widget-specific, it is
|
|
17
|
-
* already translated in all 11 built-in locales, and a parallel `fields.image.*`
|
|
18
|
-
* twin would be the same sentence maintained twice — drifting the moment one
|
|
19
|
-
* translator rewords one of them.
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* Minimal shape of the i18next `t` this module needs, matching the established
|
|
23
|
-
* `TranslateFn` pattern in `app-shell/src/providers/writeWarningToast`.
|
|
3
|
+
* Minimal shape of the i18next `t` this module needs — RE-EXPORTED from its one
|
|
4
|
+
* authority in `@object-ui/i18n`, never re-declared (objectui#8261). The
|
|
5
|
+
* sibling widgets that import it from here keep doing so; no import path moves.
|
|
24
6
|
*/
|
|
25
|
-
export type TranslateFn
|
|
7
|
+
export type { TranslateFn } from '@object-ui/i18n';
|
|
26
8
|
/**
|
|
27
9
|
* The rejection message for a pick that exceeds `maxSize`, or `null` when the
|
|
28
10
|
* pick is within the limit — so a caller reads it as `if (err) reject`.
|
|
@@ -3,12 +3,28 @@ import { isFileIdToken } from '@objectstack/spec/data';
|
|
|
3
3
|
export interface FileValueView {
|
|
4
4
|
/** `sys_file` id, when the value carries one. */
|
|
5
5
|
id?: string;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Best available display name: the value's own, else the caller's
|
|
8
|
+
* `fallbackName`. Empty only when the caller passed an empty fallback to ask
|
|
9
|
+
* for "no name" (the image cell does, so a nameless image reaches its
|
|
10
|
+
* translated alt — objectui#10493).
|
|
11
|
+
*/
|
|
7
12
|
name: string;
|
|
8
13
|
/** Resolvable URL, when the value carries one. A bare reference does not. */
|
|
9
14
|
url?: string;
|
|
10
15
|
size?: number;
|
|
11
16
|
mimeType?: string;
|
|
17
|
+
/**
|
|
18
|
+
* `true` when the value is the platform's refused marker
|
|
19
|
+
* `{ id, metadataRefused: true }` (`FileRefusedValueSchema`): the reader may
|
|
20
|
+
* read the record but not this file's `sys_file` metadata, so no name, size,
|
|
21
|
+
* MIME type or URL was served. The view still carries `id` and the
|
|
22
|
+
* id-derived `url` — the download endpoint judges its own access and may
|
|
23
|
+
* answer `403 FILE_DOWNLOAD_DENIED` — but a renderer draws a restricted
|
|
24
|
+
* state rather than a generic file chip, and never attempts a thumbnail
|
|
25
|
+
* (objectui#12339). Absent on every other form.
|
|
26
|
+
*/
|
|
27
|
+
metadataRefused?: true;
|
|
12
28
|
/** The value as it arrived, so callers can pass it through untouched. */
|
|
13
29
|
raw: unknown;
|
|
14
30
|
}
|
|
@@ -29,9 +45,8 @@ export interface FileValueView {
|
|
|
29
45
|
* Why it matters that this one is shared rather than duplicated: the regex is a
|
|
30
46
|
* WIRE decision. Widening it server-side (say, ids grow past 64 chars) while a
|
|
31
47
|
* copy here keeps the old bound turns every new id into "not a reference", and
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* regex.
|
|
48
|
+
* `fileValueForSubmit` then refuses every upload as incomplete — loud, but
|
|
49
|
+
* pointing at the adapter while the cause is a regex two packages away.
|
|
35
50
|
*/
|
|
36
51
|
export { isFileIdToken };
|
|
37
52
|
/**
|
|
@@ -75,13 +90,38 @@ export interface UploadResultLike {
|
|
|
75
90
|
meta?: Record<string, unknown>;
|
|
76
91
|
}
|
|
77
92
|
/**
|
|
78
|
-
*
|
|
93
|
+
* A completed upload that surfaced no `sys_file` id, refused at the point of
|
|
94
|
+
* submit (objectui#7699).
|
|
79
95
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
96
|
+
* The adapter reported success, so this is not a transport failure and the
|
|
97
|
+
* widgets do not quote an adapter message for it: what the user needs to know
|
|
98
|
+
* is that the field was NOT changed. Named — `name` and `code` — so a caller
|
|
99
|
+
* can tell it from a thrown network error without reading the message, and
|
|
100
|
+
* carrying the file's name so a host that reports it can say which pick.
|
|
83
101
|
*/
|
|
84
|
-
export declare
|
|
102
|
+
export declare class UploadIncompleteError extends Error {
|
|
103
|
+
readonly code: "UPLOAD_INCOMPLETE";
|
|
104
|
+
/** The pick's own name when the caller knew it, else the adapter's stored object name. */
|
|
105
|
+
readonly fileName: string;
|
|
106
|
+
constructor(fileName: string);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* What to store in the field for a completed upload: the bare `sys_file` id
|
|
110
|
+
* the adapter surfaced in `meta.fileId` — the reference form, the only form
|
|
111
|
+
* the stored contract admits.
|
|
112
|
+
*
|
|
113
|
+
* Throws {@link UploadIncompleteError} when the adapter surfaced no id-shaped
|
|
114
|
+
* `fileId`. ⛔ There is no fallback: the inline blob this function used to
|
|
115
|
+
* build in that case (`{ name, original_name, size, mime_type, url }`) is a
|
|
116
|
+
* shape no deployment's stored contract accepts, and a client that sent it
|
|
117
|
+
* turned a successful-looking upload into a save the backend refused (see the
|
|
118
|
+
* module header's "Submitting"). The callers catch the refusal per pick and
|
|
119
|
+
* render it in the same error row a transport failure lands in.
|
|
120
|
+
*
|
|
121
|
+
* @param originalName the pick's own file name, used to name the refusal;
|
|
122
|
+
* the adapter's stored object name stands in when the caller has none.
|
|
123
|
+
*/
|
|
124
|
+
export declare function fileValueForSubmit(result: UploadResultLike, originalName?: string): string;
|
|
85
125
|
/**
|
|
86
126
|
* The display view of a just-completed upload.
|
|
87
127
|
*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The key a HOST writes onto a long-text widget's `field` carrier at runtime —
|
|
10
|
+
* wider than the shape an author may WRITE, on purpose (objectui#12242,
|
|
11
|
+
* maintainer ruling A, under AGENTS.md #0.1 and the objectui#6356 pattern).
|
|
12
|
+
*
|
|
13
|
+
* `mobile_fullscreen` is a projection of the FORM-level setting
|
|
14
|
+
* `ObjectFormSchema.mobile.fullscreenLongText`. Its one producer is
|
|
15
|
+
* `ObjectForm` (`@object-ui/plugin-form`), which stamps it onto the carrier
|
|
16
|
+
* the form renderer hands each long-text widget (`f.field || f`) while it
|
|
17
|
+
* builds the form. Its consumers are `TextAreaField` and `RichTextField` here,
|
|
18
|
+
* which read it off `field` and nowhere else (objectui#3245), and the form
|
|
19
|
+
* renderer's built-in `textarea` branch in `@object-ui/components`, which
|
|
20
|
+
* reads it off its own props. Nobody authors it: `@objectstack/spec`'s
|
|
21
|
+
* `FieldSchema` refuses the key by name, so no published object can carry it,
|
|
22
|
+
* and `@object-ui/types`' field metadata types no longer declare it.
|
|
23
|
+
*
|
|
24
|
+
* ⛔ Deliberately NOT exported from this package's index, and ⛔ never to be
|
|
25
|
+
* added back to `@object-ui/types`: the authoring face refuses the key, and a
|
|
26
|
+
* public type naming it would invite the spelling that face refuses.
|
|
27
|
+
*/
|
|
28
|
+
export interface LongTextCarrierHandoff {
|
|
29
|
+
/**
|
|
30
|
+
* Draw the fullscreen-edit affordance (an "expand" button opening a
|
|
31
|
+
* full-height dialog) beside the inline editor. Absent when the form did
|
|
32
|
+
* not opt in.
|
|
33
|
+
*/
|
|
34
|
+
mobile_fullscreen?: boolean;
|
|
35
|
+
}
|
|
@@ -23,7 +23,7 @@ export type SchemaOption = {
|
|
|
23
23
|
/** Translate a schema field's options through the shared i18n option path. */
|
|
24
24
|
export type OptionTranslator = (objectName: string, fieldName: string, options: SchemaOption[]) => SchemaOption[];
|
|
25
25
|
/**
|
|
26
|
-
* Normalise a
|
|
26
|
+
* Normalise a lookupColumns entry (string | LookupColumnDef) into a
|
|
27
27
|
* concrete LookupColumnDef object.
|
|
28
28
|
*/
|
|
29
29
|
export declare function normalizeColumn(col: string | LookupColumnDef): LookupColumnDef;
|
|
@@ -56,11 +56,11 @@ export declare function resolveSchemaOptions(meta: {
|
|
|
56
56
|
* referenced object's schema (`fieldsMeta`) the same way the list view enriches
|
|
57
57
|
* its columns. This is what lets a `select` column resolve its option label
|
|
58
58
|
* (options + i18n) instead of title-casing the raw value (#3333), and what
|
|
59
|
-
* carries `reference`
|
|
59
|
+
* carries `reference` through to the lookup cell renderer so
|
|
60
60
|
* an unresolved foreign-key id resolves to a name (#5492).
|
|
61
61
|
*
|
|
62
62
|
* Columns whose def carries no `type` inherit the schema field's type, so
|
|
63
|
-
* string-authored `
|
|
63
|
+
* string-authored `lookupColumns` format identically to object-authored ones.
|
|
64
64
|
*/
|
|
65
65
|
export declare function buildLookupColumnDescriptors(columns: LookupColumnDef[], fieldsMeta: Record<string, any> | undefined, objectName: string, translateOptions: OptionTranslator): Record<string, any>;
|
|
66
66
|
export interface LookupColumnRenderContext {
|
|
@@ -68,9 +68,21 @@ export interface LookupColumnRenderContext {
|
|
|
68
68
|
descriptors: Record<string, any>;
|
|
69
69
|
/** Type-aware renderer resolver; when absent every cell degrades to text. */
|
|
70
70
|
cellRenderer?: LookupCellRendererResolver;
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The referenced object's schema. When given, the display column renders the
|
|
73
|
+
* record's title through `@object-ui/core`'s `getRecordDisplayName`, the same
|
|
74
|
+
* call the lookup dropdown's option label and the read cell make
|
|
75
|
+
* (objectui#10486).
|
|
76
|
+
*/
|
|
77
|
+
objectSchema?: Record<string, unknown> | null;
|
|
78
|
+
/**
|
|
79
|
+
* The lookup field's DECLARED display field, handed to the resolver as its
|
|
80
|
+
* `titleField`. `undefined` when the field declares none: the `name` default
|
|
81
|
+
* the display column is keyed on is a guess, and a guess never outranks the
|
|
82
|
+
* referenced object's own declarations.
|
|
83
|
+
*/
|
|
84
|
+
titleField?: string;
|
|
85
|
+
/** The column the record title stands in for (the display column's key). */
|
|
74
86
|
displayField?: string;
|
|
75
87
|
/** Locale for the plain-text `$date` fallback. */
|
|
76
88
|
displayLocale?: string;
|
|
@@ -79,9 +91,14 @@ export interface LookupColumnRenderContext {
|
|
|
79
91
|
* Render one column of one candidate record.
|
|
80
92
|
*
|
|
81
93
|
* Order:
|
|
82
|
-
* 1.
|
|
83
|
-
*
|
|
84
|
-
*
|
|
94
|
+
* 1. the record title, for the display column only and only when the
|
|
95
|
+
* referenced object's schema is given: `getRecordDisplayName` with the
|
|
96
|
+
* lookup's declared display field as its `titleField`, i.e. the field's
|
|
97
|
+
* own `displayField`, then the object's `nameField`, then its deprecated
|
|
98
|
+
* `titleFormat` template, then type-aware derivation (ADR-0079; the lookup
|
|
99
|
+
* branch of objectui#9436's ruling C1). The resolver's own floor
|
|
100
|
+
* (`Untitled` / `Record #<id>`) is not a title here, so a record with
|
|
101
|
+
* nothing nameable falls through to step 2 and keeps its column's value.
|
|
85
102
|
* 2. the type-aware cell renderer for the column's field descriptor.
|
|
86
103
|
* 3. a plain-text fallback for columns with no descriptor / no resolver.
|
|
87
104
|
*
|
|
@@ -6,32 +6,14 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Value adapters for the native date/time controls (objectui#3127).
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* They live in `@object-ui/core` (`utils/native-date-value.ts`), next to the
|
|
12
|
+
* `isRealCalendarDate` judgement they share, so `@object-ui/components`' data
|
|
13
|
+
* table can use the same set without a package cycle (objectui#10625). This
|
|
14
|
+
* module re-exports them unchanged, so every importer here, and the public
|
|
15
|
+
* `@object-ui/fields` barrel, names the same symbols as before. The design
|
|
16
|
+
* notes (the round trip, the shape kept in form state, the impossible stored
|
|
17
|
+
* day) are in the `core` module's header.
|
|
15
18
|
*/
|
|
16
|
-
export
|
|
17
|
-
/**
|
|
18
|
-
* Stored value → `<input type="datetime-local">` value (`YYYY-MM-DDTHH:mm`),
|
|
19
|
-
* expressed in the viewer's local wall clock — the same instant the detail
|
|
20
|
-
* page shows, so opening the editor never appears to move the time.
|
|
21
|
-
*
|
|
22
|
-
* A value that is ALREADY a zone-less local datetime is truncated to minutes
|
|
23
|
-
* in place instead of being round-tripped through `Date`, which would
|
|
24
|
-
* reinterpret it and then re-render it, twice risking an off-by-a-zone shift.
|
|
25
|
-
*/
|
|
26
|
-
export declare function toDateTimeInputValue(value: unknown): string;
|
|
27
|
-
/**
|
|
28
|
-
* `<input type="datetime-local">` value → stored value (ISO-8601, UTC).
|
|
29
|
-
*
|
|
30
|
-
* The control hands us a zone-less local wall clock; `new Date()` reads that
|
|
31
|
-
* form as local time, which is the inverse of what `toDateTimeInputValue`
|
|
32
|
-
* wrote — the pair is what keeps read and write on one basis.
|
|
33
|
-
*
|
|
34
|
-
* An unparseable string is returned untouched rather than blanked: dropping a
|
|
35
|
-
* value the user can see in the box would be a data loss dressed up as a fix.
|
|
36
|
-
*/
|
|
37
|
-
export declare function fromDateTimeInputValue(value: string): string;
|
|
19
|
+
export { toDateInputValue, toDateTimeInputValue, fromDateTimeInputValue, isImpossibleStoredDay, } from '@object-ui/core';
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { FieldMetadata } from '@object-ui/types';
|
|
2
|
+
import { PercentScale } from '@objectstack/spec/data';
|
|
3
|
+
/**
|
|
4
|
+
* Format a numeric value the way the `number` field declaring it says to
|
|
5
|
+
* display it.
|
|
6
|
+
*
|
|
7
|
+
* @param value the numeric value. Callers decide what counts as empty or as
|
|
8
|
+
* not a number before calling: this formats a number, it does
|
|
9
|
+
* not judge one.
|
|
10
|
+
* @param field the field metadata; its `type`, `scale` and `useGrouping` are
|
|
11
|
+
* the inputs read.
|
|
12
|
+
* @param locale the display locale tag, from `useDisplayLocale()`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatNumberFieldValue(value: number, field: FieldMetadata, locale: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The display width of a currency amount: the resolved currency's own ISO 4217
|
|
17
|
+
* minor-unit count (2 for USD / CNY, 0 for JPY, 3 for KWD), or the historical 2
|
|
18
|
+
* when no currency is resolved, since there is then no minor unit to ask about.
|
|
19
|
+
*
|
|
20
|
+
* A currency's decimal places are the CURRENCY's, not a field setting: the
|
|
21
|
+
* maintainer ruling recorded on objectstack-ai/objectstack#19910 (batch #218
|
|
22
|
+
* item 2), executed by objectui#10276. ⛔ Not the field-level `precision` (the
|
|
23
|
+
* TOTAL digit count of a decimal(p, s) column), ⛔ not `scale` (taken off the
|
|
24
|
+
* `currency` type by ruling B on objectstack-ai/objectstack#19629) and ⛔ not
|
|
25
|
+
* `currencyConfig.precision`. `CurrencyField`'s comment beside its call carries
|
|
26
|
+
* the full reasoning.
|
|
27
|
+
*
|
|
28
|
+
* One function, so the width a currency amount is DISPLAYED at
|
|
29
|
+
* ({@link formatCurrency}) and the width `CurrencyField` EDITS it at (its
|
|
30
|
+
* `step` and its blur rounding) cannot part.
|
|
31
|
+
*/
|
|
32
|
+
export declare function currencyDisplayWidth(currency: string | undefined): number;
|
|
33
|
+
/**
|
|
34
|
+
* Format a currency amount: the ONE call every display face of a `currency`
|
|
35
|
+
* field makes. `CurrencyCellRenderer` in a table, `CurrencyField`'s read-only
|
|
36
|
+
* branch in a form, and every face that takes the cell's formatter by
|
|
37
|
+
* reference all reach it, so they agree by construction (objectui#11444).
|
|
38
|
+
*
|
|
39
|
+
* When `currency` is undefined the amount is a plain number with thousands
|
|
40
|
+
* separators and no symbol. Silently assuming USD for unconfigured currency
|
|
41
|
+
* fields was the #1 source of "why is my RMB amount showing as dollars?" bug
|
|
42
|
+
* reports.
|
|
43
|
+
*
|
|
44
|
+
* The width is the DECLARED one, {@link currencyDisplayWidth}, for every
|
|
45
|
+
* amount: `$3,456.00`, `$3,456.50`, `¥3,456`, `KWD 3,456.000`. Triage ruled
|
|
46
|
+
* that the protocol's convention is the declared width (objectui#11444, comment
|
|
47
|
+
* 5946462862), the family's one width source (ruling A′, `resolveFieldScale`),
|
|
48
|
+
* and retired the objectui#4033 whole-amount trimming this function used to
|
|
49
|
+
* apply: a whole amount dropped its fraction (`$3,456`, `KWD 3,456`) while the
|
|
50
|
+
* read-only form showed the same amount at the currency's width (`$3,456.00`),
|
|
51
|
+
* so one stored value read two ways.
|
|
52
|
+
*
|
|
53
|
+
* ONE width for both `Intl` bounds, never a range (objectui#4332). The symbol
|
|
54
|
+
* branch once passed `minimumFractionDigits: 0` against a larger maximum, and
|
|
55
|
+
* `Intl` then emits the SHORTEST representation in range, so a genuine cents
|
|
56
|
+
* value of `.50` printed as `.5` (`$1,234.5`).
|
|
57
|
+
*
|
|
58
|
+
* The width is the CURRENCY's own minor-unit count, not a literal 2
|
|
59
|
+
* (objectui#4361). Passing 2 for every currency on earth overrode what `Intl`
|
|
60
|
+
* already knows: a yen amount was printed with cents it does not have
|
|
61
|
+
* (`¥1,234.50`) and a dinar amount one digit short (`KWD 1.50`).
|
|
62
|
+
*
|
|
63
|
+
* Deliberately passes NO `scale` to `formatDisplayNumber`: `scale: 0` without a
|
|
64
|
+
* currency reads as an ordinal there and drops the grouping separators
|
|
65
|
+
* (objectui#4033), and an amount is never an ordinal.
|
|
66
|
+
*/
|
|
67
|
+
export declare function formatCurrency(value: number, currency?: string, locale?: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* The storage scale a percent FACE reads a field's stored number at: the
|
|
70
|
+
* spec's `percentScaleOf` (`@objectstack/spec/data`) by reference, plus the
|
|
71
|
+
* one type the percent cell draws that the spec does not answer for
|
|
72
|
+
* (objectui#11475).
|
|
73
|
+
*
|
|
74
|
+
* `PercentCellRenderer` reads it, and so does every face that renders the
|
|
75
|
+
* cell's number for the same field (the grid footer, the record detail chip,
|
|
76
|
+
* the gantt tooltip, the mobile card, the object metric tile), so one stored
|
|
77
|
+
* value reads one magnitude on all of them. ⛔ None of them reads the storage
|
|
78
|
+
* off the VALUE: a magnitude guess cannot tell a fraction-stored `1` (100%)
|
|
79
|
+
* from one percentage point.
|
|
80
|
+
*
|
|
81
|
+
* - **`percent`, and a textual field the `format: 'percent'` hint promotes to
|
|
82
|
+
* the percent cell:** `percentScaleOf` asked about `percent`, the face's own
|
|
83
|
+
* type, with the field's declared `max`. A percent field stores a fraction
|
|
84
|
+
* unless it declares a `max` above 1. Asking about `percent` rather than the
|
|
85
|
+
* bag's own `type` is what lets a promoted textual field, or a bag whose
|
|
86
|
+
* `type` was rewritten to the renderer key, read by the percent convention
|
|
87
|
+
* too; it is the same reason `PercentField` asks `resolveFieldScale` about
|
|
88
|
+
* `percent`. `percentScaleOf` answers every percent field, so the result is
|
|
89
|
+
* never `undefined`.
|
|
90
|
+
* - **`progress`: `whole`, stated here.** The spec's `percentScaleOf` answers
|
|
91
|
+
* `undefined` for it (it keys on `percent` alone), so the spec states no
|
|
92
|
+
* percent storage for a `progress` field, and an undeclared key follows the
|
|
93
|
+
* implementation: the one editor a `progress` field has, `SliderField`,
|
|
94
|
+
* stores the slider's position on a `0`–`100` range unless the field
|
|
95
|
+
* declares other bounds, and every first-party `progress` field declares
|
|
96
|
+
* `min: 0, max: 100`. So its number IS percentage points.
|
|
97
|
+
*
|
|
98
|
+
* @param field the field definition the face holds. Only `type` and `max`
|
|
99
|
+
* are read, and a `max` that is not a number is not a
|
|
100
|
+
* declaration.
|
|
101
|
+
*/
|
|
102
|
+
export declare function percentCellScale(field: {
|
|
103
|
+
type?: string;
|
|
104
|
+
max?: unknown;
|
|
105
|
+
} | null | undefined): PercentScale;
|
|
106
|
+
/**
|
|
107
|
+
* Render a percent on a value ALREADY in display magnitude (`80` means 80%):
|
|
108
|
+
* the ONE rendering call every display face of a `percent` field makes.
|
|
109
|
+
* `formatPercent` (the table cell, and every face that takes the cell's
|
|
110
|
+
* formatter by reference) and `PercentField`'s read-only branch in a form both
|
|
111
|
+
* end here, so
|
|
112
|
+
* the locale's percent convention, the grouping and the width cannot part
|
|
113
|
+
* between them (objectui#11444). The read-only face printed
|
|
114
|
+
* `toDisplay(value).toFixed(scale)` plus a literal `%`: a `scale: 2` field
|
|
115
|
+
* holding `0.25` read `25.00%` in a `de` form while its cell read `25,00 %`.
|
|
116
|
+
*
|
|
117
|
+
* The SCALING is the caller's, and it is a separate statement on purpose:
|
|
118
|
+
* both callers scale at the storage the field DECLARES, read through the
|
|
119
|
+
* spec's `percentScaleOf` (a fraction unless the field declares a `max` above
|
|
120
|
+
* 1, the rule the edit input writes by). `formatPercent` takes it as its
|
|
121
|
+
* `percentScale` argument, which the cell answers with
|
|
122
|
+
* {@link percentCellScale}; `PercentField` asks `percentScaleOf` itself, so
|
|
123
|
+
* its read-only text and its input never show one stored value at two
|
|
124
|
+
* magnitudes. Until objectui#11475 the cell guessed the storage from the
|
|
125
|
+
* value's magnitude instead, so a fraction-stored `1` (100%) read `100%` in a
|
|
126
|
+
* read-only form and `1%` in its cell, and a whole-stored `0.5` read `0.5%`
|
|
127
|
+
* and `50%`.
|
|
128
|
+
* ⛔ Do not add a caller with a scaling rule of its own, and ⛔ never one keyed
|
|
129
|
+
* on the column's NAME: objectui#9452 removed exactly that from
|
|
130
|
+
* `PercentCellRenderer`.
|
|
131
|
+
*
|
|
132
|
+
* @param displayValue the percentage points to render.
|
|
133
|
+
* @param precision the decimal places, fixed at both bounds: the width the
|
|
134
|
+
* caller resolved (`resolveFieldScale`, ruling A′).
|
|
135
|
+
* @param locale the display locale tag, from `useDisplayLocale()`.
|
|
136
|
+
*/
|
|
137
|
+
export declare function formatPercentPoints(displayValue: number, precision: number, locale?: string): string;
|