@object-ui/fields 17.2.0 → 17.3.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 +592 -0
- package/dist/__tests__/cell-truncation.test.d.ts +0 -0
- package/dist/__tests__/field-carrier-sdui.test.d.ts +0 -0
- package/dist/__tests__/widget-aria-invalid-e2e.test.d.ts +0 -0
- package/dist/__tests__/widget-aria-invalid-registry-e2e.test.d.ts +0 -0
- package/dist/__tests__/widget-dom-leak-e2e.test.d.ts +0 -0
- package/dist/index.cjs +5 -5
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2881 -2566
- package/dist/widgets/AddressField.d.ts +1 -1
- package/dist/widgets/AddressField.uniqueIds.test.d.ts +0 -0
- package/dist/widgets/AvatarField.d.ts +1 -1
- package/dist/widgets/CharacterCount.d.ts +56 -0
- package/dist/widgets/CheckboxesField.d.ts +1 -1
- package/dist/widgets/CodeField.d.ts +1 -1
- package/dist/widgets/ColorField.d.ts +1 -1
- package/dist/widgets/CurrencyField.d.ts +1 -1
- package/dist/widgets/EmailField.d.ts +1 -1
- package/dist/widgets/FileField.d.ts +1 -1
- package/dist/widgets/FilterConditionField.d.ts +1 -1
- package/dist/widgets/FullscreenFieldEditor.d.ts +155 -0
- package/dist/widgets/GeolocationField.d.ts +1 -1
- package/dist/widgets/GeolocationField.uniqueIds.test.d.ts +0 -0
- package/dist/widgets/ImageField.d.ts +1 -1
- package/dist/widgets/LocationField.d.ts +1 -1
- package/dist/widgets/LookupField.d.ts +1 -1
- package/dist/widgets/LookupField.gateHintLabel.test.d.ts +8 -0
- package/dist/widgets/MultiSelectField.d.ts +1 -1
- package/dist/widgets/ObjectField.d.ts +1 -1
- package/dist/widgets/ObjectRefField.d.ts +1 -1
- package/dist/widgets/OptionsEmptyState.d.ts +45 -0
- package/dist/widgets/OptionsEmptyState.no-provider.test.d.ts +0 -0
- package/dist/widgets/OptionsEmptyState.test.d.ts +0 -0
- package/dist/widgets/PercentField.d.ts +1 -1
- package/dist/widgets/PhoneField.d.ts +1 -1
- package/dist/widgets/QRCodeField.d.ts +1 -1
- package/dist/widgets/RadioField.d.ts +1 -1
- package/dist/widgets/RatingField.d.ts +1 -1
- package/dist/widgets/RecipientPickerField.d.ts +1 -1
- package/dist/widgets/RecordPickerDialog.d.ts +17 -1
- package/dist/widgets/RecordPickerDialog.filterOptions.test.d.ts +8 -0
- package/dist/widgets/RecordPickerDialog.selectLabel.test.d.ts +8 -0
- package/dist/widgets/RichTextField.d.ts +19 -1
- package/dist/widgets/TagsField.d.ts +1 -1
- package/dist/widgets/TagsField.placeholder.no-provider.test.d.ts +0 -0
- package/dist/widgets/TagsField.placeholder.test.d.ts +0 -0
- package/dist/widgets/TextAreaField.d.ts +44 -5
- package/dist/widgets/UrlField.d.ts +1 -1
- package/dist/widgets/__tests__/FullscreenFieldEditor.i18n.test.d.ts +0 -0
- package/dist/widgets/__tests__/FullscreenFieldEditor.no-provider.test.d.ts +0 -0
- package/dist/widgets/__tests__/RichTextField.fullscreenDisabled.test.d.ts +0 -0
- package/dist/widgets/__tests__/RichTextField.mobileFullscreen.test.d.ts +0 -0
- package/dist/widgets/__tests__/TextAreaField.characterCount.announcements.test.d.ts +0 -0
- package/dist/widgets/__tests__/TextAreaField.characterCount.i18n.test.d.ts +0 -0
- package/dist/widgets/__tests__/TextAreaField.characterCount.no-provider.test.d.ts +0 -0
- package/dist/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.d.ts +0 -0
- package/dist/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.d.ts +0 -0
- package/dist/widgets/__tests__/TextAreaField.fullscreenDisabled.test.d.ts +0 -0
- package/dist/widgets/__tests__/TextAreaField.mobileFullscreen.test.d.ts +0 -0
- package/dist/widgets/toDomProps.d.ts +91 -0
- package/dist/widgets/types.d.ts +128 -33
- package/dist/withFieldCarrier.d.ts +56 -0
- package/package.json +13 -13
- package/src/__tests__/cell-truncation.test.tsx +96 -0
- package/src/__tests__/field-carrier-sdui.test.tsx +169 -0
- package/src/__tests__/spec-symbol-batch7.test.ts +29 -15
- package/src/__tests__/validation-feedback.test.tsx +22 -13
- package/src/__tests__/widget-aria-invalid-e2e.test.tsx +265 -0
- package/src/__tests__/widget-aria-invalid-registry-e2e.test.tsx +338 -0
- package/src/__tests__/widget-dom-leak-e2e.test.tsx +598 -0
- package/src/__tests__/widget-props-contract.test.tsx +22 -9
- package/src/index.tsx +74 -26
- package/src/widgets/AddressField.tsx +31 -12
- package/src/widgets/AddressField.uniqueIds.test.tsx +92 -0
- package/src/widgets/AvatarField.tsx +9 -2
- package/src/widgets/BooleanField.tsx +3 -3
- package/src/widgets/CharacterCount.tsx +263 -0
- package/src/widgets/CheckboxesField.tsx +31 -14
- package/src/widgets/CodeField.tsx +9 -2
- package/src/widgets/ColorField.tsx +11 -2
- package/src/widgets/CurrencyField.tsx +5 -4
- package/src/widgets/DateField.tsx +2 -2
- package/src/widgets/DateTimeField.tsx +2 -2
- package/src/widgets/EmailField.tsx +5 -5
- package/src/widgets/FileField.tsx +13 -3
- package/src/widgets/FilterConditionField.tsx +11 -0
- package/src/widgets/FormulaField.tsx +1 -1
- package/src/widgets/FullscreenFieldEditor.tsx +271 -0
- package/src/widgets/GeolocationField.tsx +21 -6
- package/src/widgets/GeolocationField.uniqueIds.test.tsx +88 -0
- package/src/widgets/GridField.tsx +1 -1
- package/src/widgets/ImageField.tsx +9 -2
- package/src/widgets/LocationField.tsx +9 -2
- package/src/widgets/LookupField.gateHintLabel.test.tsx +135 -0
- package/src/widgets/LookupField.tsx +41 -6
- package/src/widgets/MasterDetailField.tsx +1 -1
- package/src/widgets/MultiSelectField.tsx +30 -14
- package/src/widgets/NumberField.tsx +3 -3
- package/src/widgets/ObjectField.tsx +17 -8
- package/src/widgets/ObjectRefField.tsx +10 -0
- package/src/widgets/OptionsEmptyState.no-provider.test.tsx +88 -0
- package/src/widgets/OptionsEmptyState.test.tsx +169 -0
- package/src/widgets/OptionsEmptyState.tsx +83 -0
- package/src/widgets/PasswordField.tsx +3 -3
- package/src/widgets/PeoplePicker.tsx +7 -1
- package/src/widgets/PercentField.tsx +5 -4
- package/src/widgets/PhoneField.tsx +5 -5
- package/src/widgets/QRCodeField.tsx +9 -2
- package/src/widgets/RadioField.tsx +24 -14
- package/src/widgets/RatingField.tsx +18 -3
- package/src/widgets/RecipientPickerField.tsx +18 -0
- package/src/widgets/RecordPickerDialog.filterOptions.test.tsx +611 -0
- package/src/widgets/RecordPickerDialog.selectLabel.test.tsx +112 -0
- package/src/widgets/RecordPickerDialog.tsx +173 -8
- package/src/widgets/RichTextField.tsx +151 -24
- package/src/widgets/SelectField.tsx +48 -17
- package/src/widgets/SliderField.tsx +1 -1
- package/src/widgets/SummaryField.tsx +1 -1
- package/src/widgets/TagsField.placeholder.no-provider.test.tsx +68 -0
- package/src/widgets/TagsField.placeholder.test.tsx +95 -0
- package/src/widgets/TagsField.tsx +23 -2
- package/src/widgets/TextAreaField.tsx +171 -93
- package/src/widgets/TextField.tsx +3 -3
- package/src/widgets/TimeField.tsx +2 -2
- package/src/widgets/UrlField.tsx +5 -5
- package/src/widgets/UserField.tsx +1 -1
- package/src/widgets/VectorField.tsx +1 -1
- package/src/widgets/__tests__/FullscreenFieldEditor.i18n.test.tsx +248 -0
- package/src/widgets/__tests__/FullscreenFieldEditor.no-provider.test.tsx +116 -0
- package/src/widgets/__tests__/RichTextField.fullscreenDisabled.test.tsx +244 -0
- package/src/widgets/__tests__/RichTextField.mobileFullscreen.test.tsx +195 -0
- package/src/widgets/__tests__/TextAreaField.characterCount.announcements.test.tsx +417 -0
- package/src/widgets/__tests__/TextAreaField.characterCount.i18n.test.tsx +287 -0
- package/src/widgets/__tests__/TextAreaField.characterCount.no-provider.test.tsx +160 -0
- package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.tsx +161 -0
- package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.tsx +346 -0
- package/src/widgets/__tests__/TextAreaField.fullscreenDisabled.test.tsx +246 -0
- package/src/widgets/__tests__/TextAreaField.mobileFullscreen.test.tsx +175 -0
- package/src/widgets/toDomProps.ts +175 -0
- package/src/widgets/types.ts +135 -35
- package/src/widgets/useFieldTranslation.ts +60 -0
- package/src/withFieldCarrier.tsx +75 -0
|
@@ -0,0 +1,91 @@
|
|
|
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 RUNTIME EXECUTOR of the "DOM pass-through" section of
|
|
10
|
+
* {@link FieldWidgetComponentProps} (objectui#3291).
|
|
11
|
+
*
|
|
12
|
+
* ## The defect
|
|
13
|
+
*
|
|
14
|
+
* Field widgets forwarded their leftover props to a control with a bare
|
|
15
|
+
* spread — `const { inputType, ...domProps } = props as any; <Input
|
|
16
|
+
* {...domProps} />`. Whatever a host handed the widget therefore became a DOM
|
|
17
|
+
* attribute. Measured on `origin/main`, a real form + a real widget:
|
|
18
|
+
*
|
|
19
|
+
* ```
|
|
20
|
+
* <input placeholder="PH-f" zzcanary="CANARY-STR" zzcanaryobj="[object Object]"
|
|
21
|
+
* zzcanarynum="42" id="…" type="text" value="" name="f">
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The `[object Object]` this issue is named for is an authored field-config
|
|
25
|
+
* key being `String()`-ed onto an attribute. React 19 does not warn: an
|
|
26
|
+
* all-lowercase unknown attribute is passed through in complete silence, which
|
|
27
|
+
* is why this survived so long.
|
|
28
|
+
*
|
|
29
|
+
* ## Why a whitelist, and not a list of keys to drop
|
|
30
|
+
*
|
|
31
|
+
* The biggest leak source is not any NAMED renderer prop — it is the open tail
|
|
32
|
+
* of author-supplied keys. The form renderer destructures a fixed set of known
|
|
33
|
+
* keys and forwards `...fieldProps` verbatim
|
|
34
|
+
* (`components/src/renderers/form/form.tsx`), and `SchemaRenderer` is wider
|
|
35
|
+
* still: it spreads the whole authored node as props and has no strip layer at
|
|
36
|
+
* all, so on the SDUI path a widget's own spread is the ONLY line of defence.
|
|
37
|
+
*
|
|
38
|
+
* A blacklist enumerating today's renderer-only keys (`error`, `emptyHint`,
|
|
39
|
+
* `dataSource`, `dependentValues`, `dependsOn`, `options`, `inputType`, …)
|
|
40
|
+
* would pass every one of the canaries above and would not stop the next
|
|
41
|
+
* authored key either. Only "keep the known-safe set, drop the rest" closes
|
|
42
|
+
* it, which is what this function does.
|
|
43
|
+
*
|
|
44
|
+
* ## Declared = enforced
|
|
45
|
+
*
|
|
46
|
+
* {@link FieldWidgetComponentProps} already DECLARES the closed set of keys a
|
|
47
|
+
* widget may receive, and {@link FieldWidgetDomProps} names the subset that may
|
|
48
|
+
* legitimately reach a DOM element (objectui#3221). Until now that was a
|
|
49
|
+
* type-level claim a widget could violate at runtime simply by spreading. This
|
|
50
|
+
* function is that declaration's executable form, and TWO compile-time
|
|
51
|
+
* assertions below bind them in both directions — forwarding an undeclared key
|
|
52
|
+
* and declaring an unforwarded DOM key are each a compile error. Neither
|
|
53
|
+
* direction can drift silently.
|
|
54
|
+
*
|
|
55
|
+
* ## Deliberately NOT forwarded
|
|
56
|
+
*
|
|
57
|
+
* `role` and other HTML global attributes are absent because the contract does
|
|
58
|
+
* not declare them. They reached the DOM before this change only through the
|
|
59
|
+
* open spread. If a field node should be able to author one, DECLARE it on
|
|
60
|
+
* `FieldWidgetComponentProps` first and add it here — do not reopen the spread
|
|
61
|
+
* (AGENTS.md #0.1: fix the contract, never widen the consumer).
|
|
62
|
+
*/
|
|
63
|
+
declare const DOM_PASS_THROUGH_KEYS: readonly ["id", "name", "autoFocus", "tabIndex", "onBlur", "onFocus", "onClick", "className", "disabled"];
|
|
64
|
+
type DomPassThroughKey = (typeof DOM_PASS_THROUGH_KEYS)[number];
|
|
65
|
+
/** The subset of `P` this helper forwards, with each key's declared type. */
|
|
66
|
+
export type DomProps<P> = Pick<P, Extract<keyof P, DomPassThroughKey>> & {
|
|
67
|
+
[K in Extract<keyof P, `data-${string}` | `aria-${string}`>]: P[K];
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Keep only what may legitimately become a DOM attribute, and drop everything
|
|
71
|
+
* else — renderer plumbing, and any extra key an author put on the field
|
|
72
|
+
* config or SDUI node.
|
|
73
|
+
*
|
|
74
|
+
* Replaces the bare `{...props}` spread in every field widget that renders a
|
|
75
|
+
* host element:
|
|
76
|
+
*
|
|
77
|
+
* ```tsx
|
|
78
|
+
* // before — forwards whatever it was handed
|
|
79
|
+
* const { inputType, ...domProps } = props as any;
|
|
80
|
+
* return <Input {...domProps} … />;
|
|
81
|
+
*
|
|
82
|
+
* // after
|
|
83
|
+
* return <Input {...toDomProps(props)} … />;
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* Semantic props a widget INTERPRETS (`value`, `onChange`, `field`,
|
|
87
|
+
* `readonly`, `error`, …) are read from `props` as before; this function only
|
|
88
|
+
* governs what gets spread.
|
|
89
|
+
*/
|
|
90
|
+
export declare function toDomProps<P extends object>(props: P): DomProps<P>;
|
|
91
|
+
export {};
|
package/dist/widgets/types.d.ts
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
import { AriaAttributes, FocusEventHandler, MouseEventHandler } from 'react';
|
|
2
2
|
import { DependsOnInput, FieldMetadata } from '@object-ui/types';
|
|
3
|
+
/**
|
|
4
|
+
* DOM pass-through: what a widget's `...props` spread may legitimately put on
|
|
5
|
+
* the element it renders.
|
|
6
|
+
*
|
|
7
|
+
* A NAMED type rather than an inline block of {@link FieldWidgetComponentProps}
|
|
8
|
+
* so the compiler can bind it to its runtime executor in BOTH directions
|
|
9
|
+
* (objectui#3291). `toDomProps` asserts:
|
|
10
|
+
*
|
|
11
|
+
* - every key it forwards is declared on the widget contract — deleting one
|
|
12
|
+
* here without deleting it there is a compile error;
|
|
13
|
+
* - every key of THIS type is one it forwards — adding one here without
|
|
14
|
+
* adding it to `DOM_PASS_THROUGH_KEYS` is a compile error too.
|
|
15
|
+
*
|
|
16
|
+
* The second direction is the one that matters for the failure mode this repo
|
|
17
|
+
* treats as first-class: DECLARED BUT NOT DELIVERED (objectui#3290's
|
|
18
|
+
* `aria-required` that never reached a control, objectui#3222's validation slot
|
|
19
|
+
* nobody produced). Without it, a key added here would type-check, read as
|
|
20
|
+
* supported, and silently never reach the DOM — and the leak test cannot see
|
|
21
|
+
* that class of bug, because it looks for attributes that ARRIVE, not for ones
|
|
22
|
+
* that go missing.
|
|
23
|
+
*
|
|
24
|
+
* `className` and `disabled` are deliberately NOT here. They are DOM-legal and
|
|
25
|
+
* `toDomProps` does forward them, but they are declared on the controlled-input
|
|
26
|
+
* block of {@link FieldWidgetComponentProps} because widgets also INTERPRET
|
|
27
|
+
* them (className is composed with the widget's own classes; disabled is OR-ed
|
|
28
|
+
* with readonly). They are therefore bound in the forward direction only.
|
|
29
|
+
*
|
|
30
|
+
* `AriaAttributes` and the `data-${string}` family are matched by prefix at
|
|
31
|
+
* runtime rather than key-by-key, so they are intersected in separately.
|
|
32
|
+
*
|
|
33
|
+
* Adding a key here is a contract change: say who produces it and who reads it.
|
|
34
|
+
*/
|
|
35
|
+
export type FieldWidgetDomProps = {
|
|
36
|
+
id?: string;
|
|
37
|
+
/** react-hook-form's field name, spread in by the form renderer. */
|
|
38
|
+
name?: string;
|
|
39
|
+
autoFocus?: boolean;
|
|
40
|
+
tabIndex?: number;
|
|
41
|
+
onBlur?: FocusEventHandler<HTMLElement>;
|
|
42
|
+
onFocus?: FocusEventHandler<HTMLElement>;
|
|
43
|
+
onClick?: MouseEventHandler<HTMLElement>;
|
|
44
|
+
};
|
|
3
45
|
/**
|
|
4
46
|
* Props every field widget in this package receives at RUNTIME.
|
|
5
47
|
*
|
|
@@ -13,13 +55,27 @@ import { DependsOnInput, FieldMetadata } from '@object-ui/types';
|
|
|
13
55
|
* the widgets in this directory actually implement, against
|
|
14
56
|
* `@object-ui/types`'s much richer `FieldMetadata`.
|
|
15
57
|
*
|
|
16
|
-
* The two are NOT interchangeable,
|
|
17
|
-
*
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
58
|
+
* The two are NOT interchangeable, but they no longer disagree on the
|
|
59
|
+
* validation slot: this type used to call it `errorMessage` while the spec
|
|
60
|
+
* calls it `error`, so a widget written to the published contract read
|
|
61
|
+
* `undefined` forever. objectui#3222 resolved that in the direction the
|
|
62
|
+
* contract points — the slot below IS the spec's `error`, and the form
|
|
63
|
+
* renderer now produces it (see `error`'s own doc comment). Reading
|
|
64
|
+
* `props.required` off this type is still a compile error rather than a
|
|
65
|
+
* silent `any`; that key is deliberately NOT lowered here (see below).
|
|
66
|
+
*
|
|
67
|
+
* ## Why `required` is still absent, though the spec declares it
|
|
68
|
+
*
|
|
69
|
+
* The required MARKER is drawn exactly once, by the form renderer's
|
|
70
|
+
* `<FormLabel>` (the `*` with `aria-label="required"`, which the label
|
|
71
|
+
* association folds into the control's accessible name). Handing `required`
|
|
72
|
+
* to widgets would give that marker a second possible author, and the very
|
|
73
|
+
* next AI-written widget draws its own asterisk — the same double-display
|
|
74
|
+
* failure that keeps the validation TEXT out of the widget below. The a11y
|
|
75
|
+
* state a widget genuinely could carry is `aria-required` on the input, and
|
|
76
|
+
* that needs no new key at all: `AriaAttributes` is already part of this type
|
|
77
|
+
* and every widget already forwards it to its control. Tracked separately;
|
|
78
|
+
* do not add `required` here to "align" without that decision.
|
|
23
79
|
*
|
|
24
80
|
* ## Why there is no `[key: string]: any` (objectui#3221)
|
|
25
81
|
*
|
|
@@ -39,37 +95,66 @@ import { DependsOnInput, FieldMetadata } from '@object-ui/types';
|
|
|
39
95
|
* is expressed as a template-literal index signature, which — unlike
|
|
40
96
|
* `[key: string]` — leaves `keyof` finite, so an undeclared prop still fails.
|
|
41
97
|
*
|
|
98
|
+
* ## Why there is no `schema` (objectui#3233)
|
|
99
|
+
*
|
|
100
|
+
* `schema` used to be declared here as a SECOND carrier for what `field`
|
|
101
|
+
* already means — `SchemaRenderer` handed the SDUI node down as `schema`, the
|
|
102
|
+
* form renderer forwarded `schema={props.field || props.schema || props}`
|
|
103
|
+
* *alongside* `field`, and ~30 widgets resolved their config as
|
|
104
|
+
* `field || schema`. One concept, two keys, two producers: exactly the
|
|
105
|
+
* consumer-side tolerance AGENTS.md #0.1 forbids, and exactly the shape that
|
|
106
|
+
* lets an AI-written widget pick the wrong spelling and still "work" under one
|
|
107
|
+
* host while reading `undefined` under another.
|
|
108
|
+
*
|
|
109
|
+
* v17 converged it at the PRODUCERS. `field` is the only carrier a widget ever
|
|
110
|
+
* sees; the SDUI node → `field` translation happens once, in this package's
|
|
111
|
+
* registry adapter (`withFieldCarrier`), not ~30 times in the widgets. Reading
|
|
112
|
+
* `props.schema` is now a compile error rather than a silent second contract.
|
|
113
|
+
*
|
|
42
114
|
* Adding a key here is a contract change: say who produces it and who reads it.
|
|
43
115
|
*/
|
|
44
116
|
export type FieldWidgetComponentProps<T = any> = {
|
|
45
117
|
value: T;
|
|
46
118
|
onChange: (val: T) => void;
|
|
47
119
|
/**
|
|
48
|
-
* The field's metadata
|
|
49
|
-
*
|
|
120
|
+
* The field's metadata, and the SINGLE carrier for it (objectui#3233).
|
|
121
|
+
*
|
|
122
|
+
* Deliberately the looser `@object-ui/types` shape rather than the spec's,
|
|
123
|
+
* to avoid a circular dependency for now.
|
|
124
|
+
*
|
|
125
|
+
* Every host produces it: the form renderer's `renderFieldComponent`, the
|
|
126
|
+
* inline-edit hosts (`FieldEditWidget`), `ActionParamDialog` /
|
|
127
|
+
* `BulkActionDialog`, and — since #3233 — the registry adapter that adapts
|
|
128
|
+
* `SchemaRenderer`'s SDUI node onto this contract (`withFieldCarrier` in
|
|
129
|
+
* `packages/fields/src/withFieldCarrier.tsx`). A widget reads `props.field`
|
|
130
|
+
* and nothing else; there is no second key to check.
|
|
50
131
|
*/
|
|
51
132
|
field: FieldMetadata;
|
|
52
133
|
readonly?: boolean;
|
|
53
134
|
disabled?: boolean;
|
|
54
135
|
className?: string;
|
|
55
|
-
|
|
136
|
+
/**
|
|
137
|
+
* The active validation message for this field, named as
|
|
138
|
+
* `@objectstack/spec/ui`'s `FieldWidgetPropsSchema` names it (objectui#3222).
|
|
139
|
+
*
|
|
140
|
+
* **Producer**: the form renderer, from react-hook-form's
|
|
141
|
+
* `fieldState.error?.message` (`packages/components/src/renderers/form/
|
|
142
|
+
* form.tsx`). Before #3222 nothing in the repo produced it under EITHER
|
|
143
|
+
* spelling, so the seven widgets computing `aria-invalid={!!errorMessage}`
|
|
144
|
+
* were computing it from a permanent `undefined` — `aria-invalid` was never
|
|
145
|
+
* once set and a screen reader was never told the field had failed.
|
|
146
|
+
*
|
|
147
|
+
* **Consumer**: a widget reads this ONLY to drive `aria-invalid` on the
|
|
148
|
+
* control it renders. The message TEXT stays with the form renderer's
|
|
149
|
+
* `<FormMessage/>`; a widget that also renders it double-displays it.
|
|
150
|
+
*/
|
|
151
|
+
error?: string;
|
|
56
152
|
/**
|
|
57
153
|
* Upload widgets (`file`/`image`) fire this when their in-progress state
|
|
58
154
|
* flips, so a host can block submit until a presigned upload settles. Other
|
|
59
155
|
* widgets ignore it.
|
|
60
156
|
*/
|
|
61
157
|
onUploadingChange?: (uploading: boolean) => void;
|
|
62
|
-
/**
|
|
63
|
-
* The raw authored node the widget was rendered from. Two hosts supply it:
|
|
64
|
-
* `SchemaRenderer` (`<Component schema={schema} {...schema} />`) and the
|
|
65
|
-
* form renderer's `renderFieldComponent` (`schema={props.field || ...}`),
|
|
66
|
-
* which is why ~25 widgets read `field || schema` for their config.
|
|
67
|
-
*
|
|
68
|
-
* This is a second carrier for what `field` already means, i.e. a de-facto
|
|
69
|
-
* second contract (AGENTS.md #0.1) — declared here so it is at least
|
|
70
|
-
* visible; converging the two is tracked separately.
|
|
71
|
-
*/
|
|
72
|
-
schema?: FieldMetadata | Record<string, unknown>;
|
|
73
158
|
/**
|
|
74
159
|
* DataSource for widgets that query records (lookup / user / object-ref /
|
|
75
160
|
* recipient-picker / grid). Injected by the form renderer for the field
|
|
@@ -93,9 +178,27 @@ export type FieldWidgetComponentProps<T = any> = {
|
|
|
93
178
|
*/
|
|
94
179
|
dependsOn?: DependsOnInput;
|
|
95
180
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
181
|
+
* Controlling-field name → its human LABEL, for widgets that have to NAME a
|
|
182
|
+
* sibling field in user-visible copy (the dependent-lookup gate hint).
|
|
183
|
+
*
|
|
184
|
+
* Only the form renderer knows a field's label — the widget sees its own
|
|
185
|
+
* metadata and a `depends_on` list of API names. Without this map the gate
|
|
186
|
+
* sentence interpolated the raw API name into every locale, `en` included
|
|
187
|
+
* ("Select crm_account first"), which is an internal identifier leaking into
|
|
188
|
+
* the UI, not merely an untranslated word (objectstack#5407). This is the
|
|
189
|
+
* lookup-side counterpart of `emptyHint`, which the form already resolves to
|
|
190
|
+
* labels for the fixed-option widgets. A name with no entry falls back to
|
|
191
|
+
* itself, so a host that passes nothing renders exactly what it did before.
|
|
192
|
+
*/
|
|
193
|
+
dependsOnLabels?: Record<string, string>;
|
|
194
|
+
/**
|
|
195
|
+
* Hint shown when an option list cannot be filled — typically a
|
|
196
|
+
* dependency-gated list still waiting on its controlling field (#2284).
|
|
197
|
+
* Forwarded by the form renderer, which resolves the controlling fields to
|
|
198
|
+
* their human LABELS. **When supplied it wins**; the option widgets fall back
|
|
199
|
+
* to their own translated copy only when a host computed none (objectui#3231
|
|
200
|
+
* — they used to discard this prop and always render their own hardcoded
|
|
201
|
+
* English). See `OptionsEmptyState`, the single consumer.
|
|
99
202
|
*/
|
|
100
203
|
emptyHint?: string;
|
|
101
204
|
/**
|
|
@@ -114,15 +217,7 @@ export type FieldWidgetComponentProps<T = any> = {
|
|
|
114
217
|
* user had typed. Also declarable on the field metadata.
|
|
115
218
|
*/
|
|
116
219
|
onCreateNew?: (searchQuery: string) => void;
|
|
117
|
-
|
|
118
|
-
/** react-hook-form's field name, spread in by the form renderer. */
|
|
119
|
-
name?: string;
|
|
120
|
-
autoFocus?: boolean;
|
|
121
|
-
tabIndex?: number;
|
|
122
|
-
onBlur?: FocusEventHandler<HTMLElement>;
|
|
123
|
-
onFocus?: FocusEventHandler<HTMLElement>;
|
|
124
|
-
onClick?: MouseEventHandler<HTMLElement>;
|
|
125
|
-
} & AriaAttributes & {
|
|
220
|
+
} & FieldWidgetDomProps & AriaAttributes & {
|
|
126
221
|
/**
|
|
127
222
|
* Arbitrary `data-*` attributes (test ids, analytics hooks). Open by design,
|
|
128
223
|
* but a template-literal key — `keyof` stays finite, so this does NOT
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Adapt `SchemaRenderer`'s SDUI carrier onto the field-widget contract —
|
|
4
|
+
* objectui#3233, the producer-side half of retiring `schema` from
|
|
5
|
+
* {@link import('./widgets/types').FieldWidgetComponentProps}.
|
|
6
|
+
*
|
|
7
|
+
* ## Why this exists
|
|
8
|
+
*
|
|
9
|
+
* Two kinds of host render a registered field widget, and they name the
|
|
10
|
+
* metadata differently *for good reason*:
|
|
11
|
+
*
|
|
12
|
+
* - the **form renderer** (`renderFieldComponent` in
|
|
13
|
+
* `@object-ui/components`), the inline-edit hosts (`FieldEditWidget`) and
|
|
14
|
+
* the action dialogs pass **`field`** — the field metadata they already
|
|
15
|
+
* hold;
|
|
16
|
+
* - **`SchemaRenderer`** (`@object-ui/react`) passes **`schema`** — the
|
|
17
|
+
* authored node. That key is the UNIVERSAL SDUI contract *every* registered
|
|
18
|
+
* component receives (`element:*`, `page:*`, `object-grid`,
|
|
19
|
+
* `ReportRenderer` …). It is not being retired and must not be: it is what
|
|
20
|
+
* the renderer means by "the node you were rendered from".
|
|
21
|
+
*
|
|
22
|
+
* What WAS wrong is that both keys reached the widget, so ~30 widgets resolved
|
|
23
|
+
* their config as `field || schema` — one concept under two spellings, a second
|
|
24
|
+
* de-facto contract on the widget side (AGENTS.md #0.1) and precisely the shape
|
|
25
|
+
* that lets an AI-written widget pick one spelling and appear to work under one
|
|
26
|
+
* host while reading `undefined` under the other.
|
|
27
|
+
*
|
|
28
|
+
* The translation belongs at the seam, exactly once: here. Downstream `field`
|
|
29
|
+
* is the only carrier, and a widget reading `props.schema` no longer compiles.
|
|
30
|
+
*
|
|
31
|
+
* ## Guarantee
|
|
32
|
+
*
|
|
33
|
+
* Payload-preserving by construction: the node is forwarded **by reference**,
|
|
34
|
+
* so a widget's `field` is the very object it used to read through `schema`.
|
|
35
|
+
* `field` wins when a host supplies both (the form path always does, and it
|
|
36
|
+
* holds the resolved metadata rather than the raw node).
|
|
37
|
+
*
|
|
38
|
+
* `schema` is *consumed* here rather than forwarded — with the key gone from
|
|
39
|
+
* the contract, passing it on would only reach the DOM as a stray attribute
|
|
40
|
+
* through a widget's `...props` spread.
|
|
41
|
+
*
|
|
42
|
+
* ## For widget authors outside this repo
|
|
43
|
+
*
|
|
44
|
+
* Registering a widget raw means `SchemaRenderer` hands it `schema` and no
|
|
45
|
+
* `field`. Wrap it once at registration and the widget only ever implements
|
|
46
|
+
* `FieldWidgetComponentProps`:
|
|
47
|
+
*
|
|
48
|
+
* ```tsx
|
|
49
|
+
* import { withFieldCarrier } from '@object-ui/fields';
|
|
50
|
+
*
|
|
51
|
+
* ComponentRegistry.register('color', withFieldCarrier(ColorPickerField), {
|
|
52
|
+
* namespace: 'field',
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function withFieldCarrier<P extends object>(FieldWidget: React.ComponentType<P>): React.FC<Record<string, any>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/fields",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.3.0",
|
|
4
4
|
"description": "Field renderers and registry for Object UI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,30 +24,30 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@objectstack/spec": "^17.0.0-rc.
|
|
27
|
+
"@objectstack/spec": "^17.0.0-rc.2",
|
|
28
28
|
"clsx": "^2.1.1",
|
|
29
|
-
"lucide-react": "^1.
|
|
29
|
+
"lucide-react": "^1.28.0",
|
|
30
30
|
"react-markdown": "^10.1.0",
|
|
31
31
|
"rehype-sanitize": "^6.0.0",
|
|
32
32
|
"remark-gfm": "^4.0.1",
|
|
33
33
|
"tailwind-merge": "^3.6.0",
|
|
34
|
-
"@object-ui/components": "17.
|
|
35
|
-
"@object-ui/core": "17.
|
|
36
|
-
"@object-ui/i18n": "17.
|
|
37
|
-
"@object-ui/providers": "17.
|
|
38
|
-
"@object-ui/react": "17.
|
|
39
|
-
"@object-ui/types": "17.
|
|
34
|
+
"@object-ui/components": "17.3.0",
|
|
35
|
+
"@object-ui/core": "17.3.0",
|
|
36
|
+
"@object-ui/i18n": "17.3.0",
|
|
37
|
+
"@object-ui/providers": "17.3.0",
|
|
38
|
+
"@object-ui/react": "17.3.0",
|
|
39
|
+
"@object-ui/types": "17.3.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "^18.0.0 || ^19.0.0",
|
|
43
43
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/react": "19.2.
|
|
47
|
-
"@types/react-dom": "19.2.
|
|
48
|
-
"@vitejs/plugin-react": "^6.0.
|
|
46
|
+
"@types/react": "19.2.18",
|
|
47
|
+
"@types/react-dom": "19.2.4",
|
|
48
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
49
49
|
"typescript": "^6.0.3",
|
|
50
|
-
"vite": "^8.
|
|
50
|
+
"vite": "^8.2.0",
|
|
51
51
|
"vite-plugin-dts": "^5.0.3"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression for objectstack-ai/objectui#3466: single-line cell renderers
|
|
3
|
+
* emitted a BARE INLINE `span.truncate`. An inline box has no width box, so
|
|
4
|
+
* `overflow:hidden` / `text-overflow:ellipsis` never engage — the value
|
|
5
|
+
* rendered at full content width and its tail was silently clipped by
|
|
6
|
+
* whatever ancestor happened to clip (the record-detail card edge), with no
|
|
7
|
+
* ellipsis and no way to read the full text (the detail row's `title` is the
|
|
8
|
+
* inline-edit hint, not the value). Same mechanism as the JSON cell fix in
|
|
9
|
+
* objectui#2578.
|
|
10
|
+
*
|
|
11
|
+
* Pin: every single-line value renderer emits a BLOCK-level, `max-w-full`
|
|
12
|
+
* truncating span that carries the full text in `title` (so hovering the
|
|
13
|
+
* value shows the full text, taking precedence over any ancestor `title`).
|
|
14
|
+
*/
|
|
15
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
16
|
+
import { render, screen } from '@testing-library/react';
|
|
17
|
+
import '@testing-library/jest-dom';
|
|
18
|
+
import React from 'react';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
TextCellRenderer,
|
|
22
|
+
LookupCellRenderer,
|
|
23
|
+
UserCellRenderer,
|
|
24
|
+
FileCellRenderer,
|
|
25
|
+
SelectCellRenderer,
|
|
26
|
+
} from '../index';
|
|
27
|
+
import { SchemaRendererProvider } from '@object-ui/react';
|
|
28
|
+
|
|
29
|
+
const LONG =
|
|
30
|
+
'A remarkably long referenced-record title that a detail card column can never fit on a single line without an ellipsis';
|
|
31
|
+
|
|
32
|
+
/** The block-level truncation contract every single-line value span must meet. */
|
|
33
|
+
function expectTruncating(el: HTMLElement, fullText: string) {
|
|
34
|
+
expect(el).toHaveClass('block', 'max-w-full', 'truncate');
|
|
35
|
+
expect(el).toHaveAttribute('title', fullText);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('cell renderers truncate for real and expose the full text (issue #3466)', () => {
|
|
39
|
+
it('TextCellRenderer: block-level truncating span with title fallback', () => {
|
|
40
|
+
render(<TextCellRenderer value={LONG} field={{ type: 'text' } as any} />);
|
|
41
|
+
expectTruncating(screen.getByText(LONG), LONG);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('LookupCellRenderer: expanded record object', () => {
|
|
45
|
+
const ds = { find: vi.fn(), findOne: vi.fn() } as any;
|
|
46
|
+
render(
|
|
47
|
+
<SchemaRendererProvider dataSource={ds}>
|
|
48
|
+
<LookupCellRenderer
|
|
49
|
+
value={{ id: 'rec1', name: LONG }}
|
|
50
|
+
field={{ type: 'lookup', reference_to: 'obj_a' } as any}
|
|
51
|
+
/>
|
|
52
|
+
</SchemaRendererProvider>,
|
|
53
|
+
);
|
|
54
|
+
expectTruncating(screen.getByText(LONG), LONG);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('LookupCellRenderer: primitive non-opaque value', () => {
|
|
58
|
+
const ds = { find: vi.fn(), findOne: vi.fn() } as any;
|
|
59
|
+
render(
|
|
60
|
+
<SchemaRendererProvider dataSource={ds}>
|
|
61
|
+
<LookupCellRenderer value={LONG} field={{ type: 'lookup' } as any} />
|
|
62
|
+
</SchemaRendererProvider>,
|
|
63
|
+
);
|
|
64
|
+
expectTruncating(screen.getByText(LONG), LONG);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('UserCellRenderer: display name beside the avatar', () => {
|
|
68
|
+
render(<UserCellRenderer value={{ name: LONG }} field={{ type: 'user' } as any} />);
|
|
69
|
+
expectTruncating(screen.getByText(LONG), LONG);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('FileCellRenderer: single file name', () => {
|
|
73
|
+
render(<FileCellRenderer value={{ name: LONG }} field={{ type: 'file' } as any} />);
|
|
74
|
+
expectTruncating(screen.getByText(LONG), LONG);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('SelectCellRenderer (dot): bounded container with title, shrinkable label', () => {
|
|
78
|
+
render(
|
|
79
|
+
<SelectCellRenderer
|
|
80
|
+
value="opt1"
|
|
81
|
+
field={{
|
|
82
|
+
type: 'select',
|
|
83
|
+
appearance: 'dot',
|
|
84
|
+
options: [{ value: 'opt1', label: LONG }],
|
|
85
|
+
} as any}
|
|
86
|
+
/>,
|
|
87
|
+
);
|
|
88
|
+
const label = screen.getByText(LONG);
|
|
89
|
+
// The label shrinks inside the dot row; the row itself is width-bounded
|
|
90
|
+
// and carries the full text on hover.
|
|
91
|
+
expect(label).toHaveClass('min-w-0', 'truncate');
|
|
92
|
+
const row = label.parentElement!;
|
|
93
|
+
expect(row).toHaveClass('max-w-full');
|
|
94
|
+
expect(row).toHaveAttribute('title', LONG);
|
|
95
|
+
});
|
|
96
|
+
});
|