@phis/ui 0.7.4 → 0.7.5
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/components/controls/phi-form-control.js +1 -0
- package/components/controls/phi-options-provider.d.ts +14 -1
- package/components/controls/phi-options-provider.js +73 -2
- package/components/widgets/client/shared/phi-choice-controller.js +22 -15
- package/package.json +1 -1
- package/plugins/runtime-modules/builder/clients/inspector-config-field.js +11 -6
- package/plugins/runtime-modules/core/widgets/cascader/client.js +13 -12
- package/plugins/runtime-modules/core/widgets/checkbox-group/client.js +5 -4
- package/plugins/runtime-modules/core/widgets/multi-select/client.js +6 -4
|
@@ -101,6 +101,7 @@ function PhiResolvedFormFieldControl({ id, provider, field, label, description,
|
|
|
101
101
|
sourceConfig,
|
|
102
102
|
searchDraft,
|
|
103
103
|
formValues,
|
|
104
|
+
selectedValues: value,
|
|
104
105
|
});
|
|
105
106
|
/*
|
|
106
107
|
* A required parent changed, so what this field holds was chosen from a list that no longer applies.
|
|
@@ -44,6 +44,17 @@ export type PhiControlOptionsProviderContext<TValue extends string | number = st
|
|
|
44
44
|
* knowing which field supplies it or where that field lives.
|
|
45
45
|
*/
|
|
46
46
|
dependencies: Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* The values the control holds right now: one for a single choice, every one for a multiple choice,
|
|
49
|
+
* none while nothing is chosen.
|
|
50
|
+
*
|
|
51
|
+
* For a provider that answers with one page of a longer list. What the field holds need not be on
|
|
52
|
+
* that page, and a control that cannot find a value among its options shows the raw value -- an id
|
|
53
|
+
* instead of a name. Such a provider loads the names of these values alongside the page. Not part of
|
|
54
|
+
* the default load key: a provider that answers with everything it has would ask again on every
|
|
55
|
+
* choice for nothing, so one that needs them takes them into `resolveLoadKey` itself.
|
|
56
|
+
*/
|
|
57
|
+
selected: readonly TValue[];
|
|
47
58
|
/**
|
|
48
59
|
* The reader's language and the Site's time zone (`usePhiIntlLocale`, `usePhiIntlTimeZone`), for a
|
|
49
60
|
* provider whose option labels are words, amounts or dates. The hook puts both into every load key,
|
|
@@ -109,7 +120,7 @@ export declare function createPhiStaticControlOptionsProviderClient<TValue exten
|
|
|
109
120
|
export declare function PhiControlOptionsProviderIsolationBoundary({ children }: {
|
|
110
121
|
children: ReactNode;
|
|
111
122
|
}): import("react").FunctionComponentElement<import("react").ProviderProps<ReadonlyMap<`${string}/${string}`, AnyOptionsProviderRegistration>>>;
|
|
112
|
-
export declare function usePhiControlOptionsProvider<TValue extends string | number = string>({ options, optionsProvider, sourceConfig, searchDraft, formValues, }: {
|
|
123
|
+
export declare function usePhiControlOptionsProvider<TValue extends string | number = string>({ options, optionsProvider, sourceConfig, searchDraft, formValues, selectedValues, }: {
|
|
113
124
|
options?: readonly {
|
|
114
125
|
value: TValue;
|
|
115
126
|
label?: string;
|
|
@@ -130,6 +141,8 @@ export declare function usePhiControlOptionsProvider<TValue extends string | num
|
|
|
130
141
|
* passes none, and a `form` dependency simply has no value there.
|
|
131
142
|
*/
|
|
132
143
|
formValues?: Record<string, unknown> | null;
|
|
144
|
+
/** What the control holds -- one value, a list, or nothing -- as it holds it; read into `selected`. */
|
|
145
|
+
selectedValues?: unknown;
|
|
133
146
|
}): PhiResolvedControlOptions<TValue> & {
|
|
134
147
|
search: PhiControlOptionsSearchState;
|
|
135
148
|
};
|
|
@@ -8,6 +8,9 @@ const PhiControlOptionsProviderRegistryContext = createContext(EMPTY_OPTIONS_PRO
|
|
|
8
8
|
const EMPTY_PROVIDER_SNAPSHOT = null;
|
|
9
9
|
/** Shared, so a provider without dependencies keeps the same object across renders. */
|
|
10
10
|
const EMPTY_DEPENDENCY_VALUES = Object.freeze({});
|
|
11
|
+
/** Shared for the same reason: a control that holds nothing hands every provider the same list. */
|
|
12
|
+
const EMPTY_SELECTED_VALUES = Object.freeze([]);
|
|
13
|
+
const EMPTY_REMEMBERED_OPTIONS = new Map();
|
|
11
14
|
/** One pause, not one request per keystroke. */
|
|
12
15
|
const PHI_OPTIONS_SEARCH_DEBOUNCE_MS = 250;
|
|
13
16
|
const IN_FLIGHT_PROVIDER_LOADS = new WeakMap();
|
|
@@ -45,6 +48,41 @@ function normalizeStaticOptions(options) {
|
|
|
45
48
|
parentValue: option.parentValue,
|
|
46
49
|
}));
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* What a control holds, as `selected`: read here once, like the search policy. `null` and the `""` a
|
|
53
|
+
* cleared select reports are no value, and only a string or a number can be an option's value.
|
|
54
|
+
*/
|
|
55
|
+
function readSelectedValues(value) {
|
|
56
|
+
const entries = Array.isArray(value) ? value : [value];
|
|
57
|
+
return entries.filter((entry) => (typeof entry === "string" && entry !== "") || (typeof entry === "number" && Number.isFinite(entry)));
|
|
58
|
+
}
|
|
59
|
+
function areSameControlOptions(left, right) {
|
|
60
|
+
const leftEntries = Object.entries(left);
|
|
61
|
+
return leftEntries.length === Object.keys(right).length
|
|
62
|
+
&& leftEntries.every(([key, entry]) => Object.is(entry, right[key]));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The last option seen for each chosen value; a value no longer chosen is forgotten. Answers with
|
|
66
|
+
* `remembered` itself while nothing changed -- by content, as a resolver may build options afresh -- so
|
|
67
|
+
* storing it during the render does not render again.
|
|
68
|
+
*/
|
|
69
|
+
function rememberSelectedOptions(remembered, selected, options) {
|
|
70
|
+
if (selected.length === 0) {
|
|
71
|
+
return remembered.size === 0 ? remembered : EMPTY_REMEMBERED_OPTIONS;
|
|
72
|
+
}
|
|
73
|
+
const next = new Map();
|
|
74
|
+
for (const value of selected) {
|
|
75
|
+
const known = options.find((option) => option.value === value) ?? remembered.get(value);
|
|
76
|
+
if (known)
|
|
77
|
+
next.set(value, known);
|
|
78
|
+
}
|
|
79
|
+
const unchanged = next.size === remembered.size
|
|
80
|
+
&& [...next].every(([value, option]) => {
|
|
81
|
+
const previous = remembered.get(value);
|
|
82
|
+
return previous !== undefined && (previous === option || areSameControlOptions(previous, option));
|
|
83
|
+
});
|
|
84
|
+
return unchanged ? remembered : next;
|
|
85
|
+
}
|
|
48
86
|
export function readPhiControlOptionsProviderParam(provider, key) {
|
|
49
87
|
const value = provider?.params?.[key];
|
|
50
88
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
@@ -130,9 +168,14 @@ export function createPhiStaticControlOptionsProviderClient(registration) {
|
|
|
130
168
|
export function PhiControlOptionsProviderIsolationBoundary({ children }) {
|
|
131
169
|
return createElement(PhiControlOptionsProviderRegistryContext.Provider, { value: EMPTY_OPTIONS_PROVIDER_REGISTRY }, children);
|
|
132
170
|
}
|
|
133
|
-
export function usePhiControlOptionsProvider({ options, optionsProvider, sourceConfig, searchDraft = "", formValues, }) {
|
|
171
|
+
export function usePhiControlOptionsProvider({ options, optionsProvider, sourceConfig, searchDraft = "", formValues, selectedValues, }) {
|
|
134
172
|
const registry = useContext(PhiControlOptionsProviderRegistryContext);
|
|
135
173
|
const staticOptions = useMemo(() => normalizeStaticOptions(options), [options]);
|
|
174
|
+
// Keyed by content, so a value list built afresh on every render is still the same `selected`.
|
|
175
|
+
const selectedKey = JSON.stringify(readSelectedValues(selectedValues));
|
|
176
|
+
const selected = useMemo(() => selectedKey === "[]"
|
|
177
|
+
? EMPTY_SELECTED_VALUES
|
|
178
|
+
: Object.freeze(JSON.parse(selectedKey)), [selectedKey]);
|
|
136
179
|
/*
|
|
137
180
|
* The declared search policy, applied in one place. A field states whether its provider can be
|
|
138
181
|
* searched and from how many characters; the load mode states who narrows the list. Debouncing lives
|
|
@@ -188,6 +231,8 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
|
|
|
188
231
|
// keystroke, so taking the search into account is the searching provider's own decision.
|
|
189
232
|
search,
|
|
190
233
|
dependencies: dependencyValues,
|
|
234
|
+
// Not in the default load key either: a provider that answers with all it has must not reload per choice.
|
|
235
|
+
selected,
|
|
191
236
|
locale,
|
|
192
237
|
timeZone,
|
|
193
238
|
snapshot: providerSnapshot,
|
|
@@ -241,7 +286,7 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
|
|
|
241
286
|
providerLoadKey,
|
|
242
287
|
registeredProvider,
|
|
243
288
|
]);
|
|
244
|
-
|
|
289
|
+
const resolved = useMemo(() => {
|
|
245
290
|
if (!optionsProvider?.providerKey) {
|
|
246
291
|
return { options: staticOptions, search: searchState };
|
|
247
292
|
}
|
|
@@ -278,6 +323,7 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
|
|
|
278
323
|
sourceConfig,
|
|
279
324
|
search,
|
|
280
325
|
dependencies: dependencyValues,
|
|
326
|
+
selected,
|
|
281
327
|
locale,
|
|
282
328
|
timeZone,
|
|
283
329
|
snapshot: providerSnapshot,
|
|
@@ -290,6 +336,7 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
|
|
|
290
336
|
searchState,
|
|
291
337
|
dependenciesSatisfied,
|
|
292
338
|
dependencyValues,
|
|
339
|
+
selected,
|
|
293
340
|
locale,
|
|
294
341
|
timeZone,
|
|
295
342
|
asyncData,
|
|
@@ -301,4 +348,28 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
|
|
|
301
348
|
sourceConfig,
|
|
302
349
|
staticOptions,
|
|
303
350
|
]);
|
|
351
|
+
/*
|
|
352
|
+
* A chosen value keeps the option it was last seen with, for every provider: any answer can leave it
|
|
353
|
+
* out -- the empty list while a new search loads, the next page -- and the control would show the raw
|
|
354
|
+
* value. Added to the list, because the Select finds a chosen value's label among `options`. Filtering
|
|
355
|
+
* locally, the Select hides it like any option that does not match; where the provider answered the
|
|
356
|
+
* search (`filterLocally: false`) it stays at the end, marked as chosen -- the price of keeping its
|
|
357
|
+
* name, and a multiple choice shows its tags while the person types. Stored during the render, so the
|
|
358
|
+
* label survives the very render that drops it; empty until an option resolved, on the server as on
|
|
359
|
+
* the client, so hydration matches.
|
|
360
|
+
*/
|
|
361
|
+
const [rememberedOptions, setRememberedOptions] = useState(EMPTY_REMEMBERED_OPTIONS);
|
|
362
|
+
const nextRememberedOptions = rememberSelectedOptions(rememberedOptions, selected, resolved.options);
|
|
363
|
+
if (nextRememberedOptions !== rememberedOptions) {
|
|
364
|
+
setRememberedOptions(nextRememberedOptions);
|
|
365
|
+
}
|
|
366
|
+
return useMemo(() => {
|
|
367
|
+
const missing = selected
|
|
368
|
+
.filter((value) => !resolved.options.some((option) => option.value === value))
|
|
369
|
+
.flatMap((value) => {
|
|
370
|
+
const option = nextRememberedOptions.get(value);
|
|
371
|
+
return option ? [option] : [];
|
|
372
|
+
});
|
|
373
|
+
return missing.length === 0 ? resolved : { ...resolved, options: [...resolved.options, ...missing] };
|
|
374
|
+
}, [nextRememberedOptions, resolved, selected]);
|
|
304
375
|
}
|
|
@@ -7,18 +7,26 @@ import { isPhiStackSignalMessage, PHI_STACK_META_SIGNAL_CHANNEL, readPhiStackSig
|
|
|
7
7
|
import { usePhiSignalListener } from "../../../runtime/runtime-signal-bus";
|
|
8
8
|
import { usePhiControlSignalController } from "./phi-control-signals";
|
|
9
9
|
import { usePhiControlOptionsProvider } from "../../../controls/phi-options-provider";
|
|
10
|
+
/**
|
|
11
|
+
* What a choice holds, as far as known before its options resolve: a configured value is the fallback a
|
|
12
|
+
* pick holds against. Without one the fallback is the provider's own answer, so only a pick is told.
|
|
13
|
+
*/
|
|
14
|
+
function readPhiChoiceHeldValue(picked, configuredValue) {
|
|
15
|
+
if (configuredValue == null)
|
|
16
|
+
return picked?.value;
|
|
17
|
+
return picked?.source === configuredValue ? picked.value : configuredValue;
|
|
18
|
+
}
|
|
10
19
|
export function usePhiChoiceController({ config, signalsEnabled = true, typeKey, defaultKey, sender, }) {
|
|
20
|
+
// A pick, held against the fallback it replaced; declared first so the provider hears it.
|
|
21
|
+
const [picked, setPicked] = useState(null);
|
|
11
22
|
const resolvedOptions = usePhiControlOptionsProvider({
|
|
12
23
|
options: config?.options,
|
|
13
24
|
optionsProvider: config?.optionsProvider,
|
|
25
|
+
selectedValues: readPhiChoiceHeldValue(picked, config?.value),
|
|
14
26
|
});
|
|
15
27
|
const fallbackValue = config?.value ?? resolvedOptions.value ?? resolvedOptions.options.at(0)?.value ?? "";
|
|
16
28
|
const readOnly = config?.readOnly === true;
|
|
17
|
-
const
|
|
18
|
-
source: fallbackValue,
|
|
19
|
-
value: fallbackValue,
|
|
20
|
-
}));
|
|
21
|
-
const value = state.source === fallbackValue ? state.value : fallbackValue;
|
|
29
|
+
const value = picked?.source === fallbackValue ? picked.value : fallbackValue;
|
|
22
30
|
/*
|
|
23
31
|
* Options a sender replaced, held against the configured list they replaced. When the configuration
|
|
24
32
|
* brings a different list, that one is what the Control was given last, so the sent one steps aside.
|
|
@@ -38,7 +46,7 @@ export function usePhiChoiceController({ config, signalsEnabled = true, typeKey,
|
|
|
38
46
|
initialDisabled: config?.disabled === true,
|
|
39
47
|
initialReadOnly: readOnly,
|
|
40
48
|
clearValue: fallbackValue,
|
|
41
|
-
onSetValue: (nextValue) =>
|
|
49
|
+
onSetValue: (nextValue) => setPicked({ source: fallbackValue, value: nextValue }),
|
|
42
50
|
onReceiveCapability: (capabilityId, signal) => {
|
|
43
51
|
if (capabilityId !== "options") {
|
|
44
52
|
return false;
|
|
@@ -55,7 +63,7 @@ export function usePhiChoiceController({ config, signalsEnabled = true, typeKey,
|
|
|
55
63
|
if (readOnly) {
|
|
56
64
|
return;
|
|
57
65
|
}
|
|
58
|
-
|
|
66
|
+
setPicked({
|
|
59
67
|
source: fallbackValue,
|
|
60
68
|
value: nextValue,
|
|
61
69
|
});
|
|
@@ -84,19 +92,18 @@ function mapPhiStackSlotsToChoiceOptions(message) {
|
|
|
84
92
|
}));
|
|
85
93
|
}
|
|
86
94
|
export function usePhiStackChoiceController({ config, signalsEnabled = true, typeKey, defaultKey, sender, }) {
|
|
95
|
+
// A pick, held against the fallback it replaced; declared first so the provider hears it.
|
|
96
|
+
const [picked, setPicked] = useState(null);
|
|
87
97
|
const resolvedOptions = usePhiControlOptionsProvider({
|
|
88
98
|
options: config?.options,
|
|
89
99
|
optionsProvider: config?.optionsProvider,
|
|
100
|
+
selectedValues: readPhiChoiceHeldValue(picked, config?.value),
|
|
90
101
|
});
|
|
91
102
|
const stackMode = config?.valueMode === "stack-slot-index";
|
|
92
103
|
const fallbackValue = config?.value ?? resolvedOptions.value ?? resolvedOptions.options.at(0)?.value ?? "";
|
|
93
104
|
const readOnly = config?.readOnly === true;
|
|
94
|
-
const [state, setState] = useState(() => ({
|
|
95
|
-
source: fallbackValue,
|
|
96
|
-
value: fallbackValue,
|
|
97
|
-
}));
|
|
98
105
|
const [stackOptions, setStackOptions] = useState([]);
|
|
99
|
-
const value =
|
|
106
|
+
const value = picked?.source === fallbackValue ? picked.value : fallbackValue;
|
|
100
107
|
const stackMetaListenRoute = findPhiSignalRoutesByCapabilityId(config?.signalRoutes?.listens, "stackMeta")[0] ?? null;
|
|
101
108
|
/*
|
|
102
109
|
* The Stack this Choice follows: the one its `stackMeta` request is addressed to. Every Stack answers
|
|
@@ -114,7 +121,7 @@ export function usePhiStackChoiceController({ config, signalsEnabled = true, typ
|
|
|
114
121
|
initialDisabled: config?.disabled === true,
|
|
115
122
|
initialReadOnly: readOnly,
|
|
116
123
|
clearValue: fallbackValue,
|
|
117
|
-
onSetValue: (nextValue) =>
|
|
124
|
+
onSetValue: (nextValue) => setPicked({ source: fallbackValue, value: nextValue }),
|
|
118
125
|
coerceValue: (nextValue) => (typeof nextValue === "string" ? nextValue : nextValue == null ? "" : String(nextValue)),
|
|
119
126
|
});
|
|
120
127
|
const emitControlCapability = controlSignals.emitCapability;
|
|
@@ -140,7 +147,7 @@ export function usePhiStackChoiceController({ config, signalsEnabled = true, typ
|
|
|
140
147
|
}
|
|
141
148
|
setStackOptions(mapPhiStackSlotsToChoiceOptions(message) ?? []);
|
|
142
149
|
const nextValue = String(message.value.activeSlotIndex);
|
|
143
|
-
|
|
150
|
+
setPicked((current) => current?.source === fallbackValue && current.value === nextValue
|
|
144
151
|
? current
|
|
145
152
|
: { source: fallbackValue, value: nextValue });
|
|
146
153
|
}, useMemo(() => ({
|
|
@@ -151,7 +158,7 @@ export function usePhiStackChoiceController({ config, signalsEnabled = true, typ
|
|
|
151
158
|
if (readOnly) {
|
|
152
159
|
return;
|
|
153
160
|
}
|
|
154
|
-
|
|
161
|
+
setPicked({
|
|
155
162
|
source: fallbackValue,
|
|
156
163
|
value: nextValue,
|
|
157
164
|
});
|
package/package.json
CHANGED
|
@@ -332,27 +332,32 @@ function PhiInspectorChoiceFieldControl({ field, config, value, defaultValue, di
|
|
|
332
332
|
// The Inspector's own fields declare searchability too -- the navigation pickers have said
|
|
333
333
|
// `search: { enabled: true }` for a while -- so the raw text goes to the hook here as well.
|
|
334
334
|
const [searchDraft, setSearchDraft] = useState("");
|
|
335
|
+
// What the field holds, read once for the provider and for the control below.
|
|
336
|
+
const multiple = field.mode === "multiple" || field.valueType === "string[]";
|
|
337
|
+
const emptyOptionValue = field.emptyOption?.value;
|
|
338
|
+
const selectedValues = multiple ? readInspectorChoiceMultiValue(value, defaultValue) : [];
|
|
339
|
+
const selectedValue = multiple
|
|
340
|
+
? undefined
|
|
341
|
+
: value == null
|
|
342
|
+
? emptyOptionValue ?? readInspectorChoiceSingleValue(undefined, defaultValue)
|
|
343
|
+
: readInspectorChoiceSingleValue(value, defaultValue);
|
|
335
344
|
const providerResult = usePhiControlOptionsProvider({
|
|
336
345
|
options: staticOptions,
|
|
337
346
|
optionsProvider: field.filter?.widgetType ? null : field.optionsProvider,
|
|
338
347
|
sourceConfig: field.filter?.widgetType ? null : config,
|
|
339
348
|
searchDraft,
|
|
349
|
+
selectedValues: multiple ? selectedValues : selectedValue,
|
|
340
350
|
});
|
|
341
351
|
const renderChoiceRow = (control) => renderPhiInspectorConfigFieldControl(field, _jsxs(PhiFlexControl, { vertical: true, gap: 4, style: { minWidth: 0, width: "100%" }, children: [control, providerResult.warning ? (_jsx(PhiTypographyControl, { type: "warning", children: providerResult.warning })) : null] }));
|
|
342
352
|
const resolvedOptions = useMemo(() => resolveInspectorChoiceOptions(field, widgetReferenceOptions, providerResult.options), [field, providerResult.options, widgetReferenceOptions]);
|
|
343
353
|
const cascader = useMemo(() => field.presentation === "cascader" ? buildPhiInspectorChoiceCascader(resolvedOptions) : null, [field.presentation, resolvedOptions]);
|
|
344
|
-
if (
|
|
345
|
-
const selectedValues = readInspectorChoiceMultiValue(value, defaultValue);
|
|
354
|
+
if (multiple) {
|
|
346
355
|
const options = selectedValues.reduce((items, entry) => ensureInspectorChoiceOption(items, entry), resolvedOptions);
|
|
347
356
|
return renderChoiceRow(_jsx(PhiMultiSelectControl, { value: selectedValues, options: options, placeholder: field.placeholder, allowCustom: field.allowCustom, disabled: disabled || !onChange, style: { width: "100%" }, onChange: (nextValues) => onChange?.({
|
|
348
357
|
[field.key]: nextValues,
|
|
349
358
|
...(field.patchOnChange ?? {}),
|
|
350
359
|
}) }));
|
|
351
360
|
}
|
|
352
|
-
const emptyOptionValue = field.emptyOption?.value;
|
|
353
|
-
const selectedValue = value == null
|
|
354
|
-
? emptyOptionValue ?? readInspectorChoiceSingleValue(undefined, defaultValue)
|
|
355
|
-
: readInspectorChoiceSingleValue(value, defaultValue);
|
|
356
361
|
/*
|
|
357
362
|
* The options as a hierarchy by their `parentValue`. Every level can be chosen -- a Folder that holds
|
|
358
363
|
* others is a Folder too -- and what is stored is the chosen option's own value. The empty option is
|
|
@@ -8,20 +8,21 @@ import { usePhiControlOptionsProvider } from "../../../../../components/controls
|
|
|
8
8
|
export function PhiCascaderWidget({ config, signalsEnabled = true, }) {
|
|
9
9
|
const { token } = usePhiConfig();
|
|
10
10
|
const minWidth = token.controlHeight * 6;
|
|
11
|
+
const separator = config?.separator ?? "/";
|
|
12
|
+
const rootValue = config?.rootValue ?? "/";
|
|
13
|
+
const normalize = config?.normalize ?? "raw";
|
|
14
|
+
const normalizeFallback = (raw) => normalizePhiCascaderValue(normalizePhiCascaderValue(raw), { separator, rootValue, normalize });
|
|
15
|
+
// A pick, held against the fallback it replaced; declared first so the provider hears what is held.
|
|
16
|
+
// Without a configured value the fallback is the provider's own answer, so only a pick is told.
|
|
17
|
+
const [picked, setPicked] = useState(null);
|
|
18
|
+
const configuredValue = config?.value == null ? null : normalizeFallback(config.value);
|
|
11
19
|
const resolvedOptions = usePhiControlOptionsProvider({
|
|
12
20
|
options: config?.options,
|
|
13
21
|
optionsProvider: config?.optionsProvider,
|
|
22
|
+
selectedValues: configuredValue == null || picked?.source === configuredValue ? picked?.value : configuredValue,
|
|
14
23
|
});
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const rootValue = config?.rootValue ?? "/";
|
|
18
|
-
const normalize = config?.normalize ?? "raw";
|
|
19
|
-
const normalizedFallbackValue = normalizePhiCascaderValue(fallbackValue, { separator, rootValue, normalize });
|
|
20
|
-
const [state, setState] = useState(() => ({
|
|
21
|
-
source: normalizedFallbackValue,
|
|
22
|
-
value: normalizedFallbackValue,
|
|
23
|
-
}));
|
|
24
|
-
const value = state.source === normalizedFallbackValue ? state.value : normalizedFallbackValue;
|
|
24
|
+
const normalizedFallbackValue = normalizeFallback(config?.value ?? resolvedOptions.value);
|
|
25
|
+
const value = picked?.source === normalizedFallbackValue ? picked.value : normalizedFallbackValue;
|
|
25
26
|
const controlSignals = usePhiControlSignalController({
|
|
26
27
|
key: config?.key ?? "cascader",
|
|
27
28
|
signalRoutes: config?.signalRoutes,
|
|
@@ -31,7 +32,7 @@ export function PhiCascaderWidget({ config, signalsEnabled = true, }) {
|
|
|
31
32
|
initialDisabled: config?.disabled === true,
|
|
32
33
|
initialReadOnly: config?.readOnly === true,
|
|
33
34
|
clearValue: config?.allowRoot === false ? normalizedFallbackValue : rootValue,
|
|
34
|
-
onSetValue: (nextValue) =>
|
|
35
|
+
onSetValue: (nextValue) => setPicked({
|
|
35
36
|
source: normalizedFallbackValue,
|
|
36
37
|
value: normalizePhiCascaderValue(nextValue, { separator, rootValue, normalize }),
|
|
37
38
|
}),
|
|
@@ -42,7 +43,7 @@ export function PhiCascaderWidget({ config, signalsEnabled = true, }) {
|
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
45
|
const normalizedNextValue = normalizePhiCascaderValue(nextValue, { separator, rootValue, normalize });
|
|
45
|
-
|
|
46
|
+
setPicked({
|
|
46
47
|
source: normalizedFallbackValue,
|
|
47
48
|
value: normalizedNextValue,
|
|
48
49
|
});
|
|
@@ -9,14 +9,15 @@ function equalValues(left, right) {
|
|
|
9
9
|
return left.length === right.length && left.every((entry, index) => entry === right[index]);
|
|
10
10
|
}
|
|
11
11
|
export function PhiCheckboxGroupWidget({ config, value: controlledValue, disabled, readOnly, signalsEnabled = true, onChange, }) {
|
|
12
|
-
const resolvedOptions = usePhiControlOptionsProvider({
|
|
13
|
-
options: config?.options,
|
|
14
|
-
optionsProvider: config?.optionsProvider,
|
|
15
|
-
});
|
|
16
12
|
const fallbackValue = useMemo(() => controlledValue ?? config?.value ?? [], [config?.value, controlledValue]);
|
|
17
13
|
const fallbackKey = fallbackValue.join("\u001f");
|
|
18
14
|
const [state, setState] = useState(() => ({ sourceKey: fallbackKey, value: fallbackValue }));
|
|
19
15
|
const value = state.sourceKey === fallbackKey ? state.value : fallbackValue;
|
|
16
|
+
const resolvedOptions = usePhiControlOptionsProvider({
|
|
17
|
+
options: config?.options,
|
|
18
|
+
optionsProvider: config?.optionsProvider,
|
|
19
|
+
selectedValues: value,
|
|
20
|
+
});
|
|
20
21
|
const controlSignals = usePhiControlSignalController({
|
|
21
22
|
key: config?.key ?? "checkbox-group",
|
|
22
23
|
signalRoutes: config?.signalRoutes,
|
|
@@ -39,10 +39,6 @@ export function PhiMultiSelectWidget({ config, signalsEnabled = true, value: con
|
|
|
39
39
|
const { token } = usePhiConfig();
|
|
40
40
|
const minWidth = token.controlHeight * 5;
|
|
41
41
|
const valueType = config?.valueType ?? "enum[]";
|
|
42
|
-
const resolvedOptions = usePhiControlOptionsProvider({
|
|
43
|
-
options: config?.options,
|
|
44
|
-
optionsProvider: config?.optionsProvider,
|
|
45
|
-
});
|
|
46
42
|
const fallbackValue = useMemo(() => normalizeMultiSelectValue(controlledValue ?? config?.value ?? [], valueType), [config?.value, controlledValue, valueType]);
|
|
47
43
|
const fallbackValueKey = `${valueType}:${fallbackValue.join("\u001f")}`;
|
|
48
44
|
const [state, setState] = useState(() => ({
|
|
@@ -50,6 +46,12 @@ export function PhiMultiSelectWidget({ config, signalsEnabled = true, value: con
|
|
|
50
46
|
value: fallbackValue,
|
|
51
47
|
}));
|
|
52
48
|
const value = state.sourceKey === fallbackValueKey ? state.value : fallbackValue;
|
|
49
|
+
const resolvedOptions = usePhiControlOptionsProvider({
|
|
50
|
+
options: config?.options,
|
|
51
|
+
optionsProvider: config?.optionsProvider,
|
|
52
|
+
// As the Select is handed them, so they meet the options the way the Select's own lookup does.
|
|
53
|
+
selectedValues: valuesToSelectValues(value),
|
|
54
|
+
});
|
|
53
55
|
const maxTagCount = config?.maxTagCount === "responsive" && value.length <= 1
|
|
54
56
|
? undefined
|
|
55
57
|
: config?.maxTagCount;
|