@servicetitan/dte-unlayer 0.143.0 → 0.145.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.
@@ -1 +1 @@
1
- {"version":3,"file":"LookupValueControl.d.ts","sourceRoot":"","sources":["../../src/display-conditions/LookupValueControl.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,uBAAuB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAqBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,EAC/B,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,KAAK,GACR,EAAE,QAAQ,CAAC,uBAAuB,CAAC,2CA8HnC"}
1
+ {"version":3,"file":"LookupValueControl.d.ts","sourceRoot":"","sources":["../../src/display-conditions/LookupValueControl.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,uBAAuB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAiCD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,EAC/B,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,KAAK,GACR,EAAE,QAAQ,CAAC,uBAAuB,CAAC,2CAyJnC"}
@@ -7,6 +7,16 @@ const toOption = (option)=>({
7
7
  id: option.key,
8
8
  label: option.label
9
9
  });
10
+ /*
11
+ * Searchable sources return nothing until the user types, which would make the
12
+ * dropdown show its built-in "No match found" empty state on open — confusing
13
+ * before any search has happened. Render a disabled hint instead so the list is
14
+ * never mistaken for "no results".
15
+ */ const SEARCH_HINT_OPTION = {
16
+ id: '__lookup_search_hint__',
17
+ label: 'Start typing to search…',
18
+ disabled: true
19
+ };
10
20
  const sanitizeNumericInput = (raw)=>{
11
21
  let value = raw.replaceAll(/[^0-9.-]/g, '');
12
22
  const isNegative = value.startsWith('-');
@@ -31,13 +41,40 @@ const sanitizeNumericInput = (raw)=>{
31
41
  * re-searches and re-selects.
32
42
  */ export function LookupValueControl({ fieldType, lookupSource, onChange, value }) {
33
43
  const { loadOptions, options, resolveOptions, status } = useLookupOptions(lookupSource);
34
- const staticSelected = useMemo(()=>{
35
- var _options_filter_map_;
36
- return (_options_filter_map_ = options.filter((option)=>option.key === value).map(toOption)[0]) !== null && _options_filter_map_ !== void 0 ? _options_filter_map_ : null;
44
+ const staticOptions = useMemo(()=>options.map(toOption), [
45
+ options
46
+ ]);
47
+ /*
48
+ * Fall back to the raw value so a saved key that the host omits from its list
49
+ * (e.g. an inactive/renamed option) still shows on edit instead of vanishing.
50
+ */ const staticSelected = useMemo(()=>{
51
+ if (!value) {
52
+ return null;
53
+ }
54
+ var _staticOptions_find;
55
+ return (_staticOptions_find = staticOptions.find((option)=>String(option.id) === value)) !== null && _staticOptions_find !== void 0 ? _staticOptions_find : {
56
+ id: value,
57
+ label: value
58
+ };
37
59
  }, [
38
- options,
60
+ staticOptions,
39
61
  value
40
62
  ]);
63
+ /*
64
+ * Ensure the saved value is present in the list so it is visible/selectable
65
+ * even when the host did not return it.
66
+ */ const staticOptionsWithSelected = useMemo(()=>{
67
+ if (staticSelected && !staticOptions.some((option)=>String(option.id) === String(staticSelected.id))) {
68
+ return [
69
+ staticSelected,
70
+ ...staticOptions
71
+ ];
72
+ }
73
+ return staticOptions;
74
+ }, [
75
+ staticOptions,
76
+ staticSelected
77
+ ]);
41
78
  const [searchableSelected, setSearchableSelected] = useState(value ? {
42
79
  id: value,
43
80
  label: value
@@ -94,6 +131,11 @@ const sanitizeNumericInput = (raw)=>{
94
131
  resolveOptions
95
132
  ]);
96
133
  const handleLoadOptions = useCallback(async (query)=>{
134
+ if (!query.trim()) {
135
+ return [
136
+ SEARCH_HINT_OPTION
137
+ ];
138
+ }
97
139
  const result = await loadOptions(query);
98
140
  return result.map(toOption);
99
141
  }, [
@@ -116,7 +158,7 @@ const sanitizeNumericInput = (raw)=>{
116
158
  size: "small",
117
159
  label: "Value",
118
160
  placeholder: "Search value...",
119
- options: options.map(toOption),
161
+ options: staticOptionsWithSelected,
120
162
  value: staticSelected,
121
163
  onSelectedOptionChange: (option)=>onChange(option ? String(option.id) : '')
122
164
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/display-conditions/LookupValueControl.tsx"],"sourcesContent":["import { TextField } from '@servicetitan/anvil2';\nimport { SelectField, SelectFieldOption, SelectFieldSync } from '@servicetitan/anvil2/beta';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { LookupOption } from './lookupOptionsController';\nimport { useLookupOptions } from './useLookupOptions';\n\nexport interface LookupValueControlProps {\n value: string;\n fieldType: 'number' | 'string';\n /** The selected data point's `options.fieldLookupSource`; empty -> free-text input. */\n lookupSource?: string;\n onChange: (value: string) => void;\n}\n\nconst toOption = (option: LookupOption): SelectFieldOption => ({\n id: option.key,\n label: option.label,\n});\n\nconst sanitizeNumericInput = (raw: string): string => {\n let value = raw.replaceAll(/[^0-9.-]/g, '');\n const isNegative = value.startsWith('-');\n value = value.replaceAll('-', '');\n if (isNegative) {\n value = `-${value}`;\n }\n const firstDot = value.indexOf('.');\n if (firstDot >= 0) {\n value = `${value.slice(0, firstDot + 1)}${value.slice(firstDot + 1).replaceAll('.', '')}`;\n }\n return value;\n};\n\n/**\n * Renders the value control for a single condition based on the field's lookup source:\n * - `static` -> full list returned by the host, filtered locally (`SelectFieldSync`).\n * - `searchable` -> host searches per typed query (`SelectField` + `loadOptions`).\n * - `idle`/`fallback`/`loading` -> free-text input (never block the user).\n *\n * Unlayer persists conditions as a Nunjucks string, so a saved searchable value\n * has no stored label — we display the saved key as the label until the user\n * re-searches and re-selects.\n */\nexport function LookupValueControl({\n fieldType,\n lookupSource,\n onChange,\n value,\n}: Readonly<LookupValueControlProps>) {\n const { loadOptions, options, resolveOptions, status } = useLookupOptions(lookupSource);\n\n const staticSelected = useMemo<SelectFieldOption | null>(\n () => options.filter(option => option.key === value).map(toOption)[0] ?? null,\n [options, value],\n );\n\n const [searchableSelected, setSearchableSelected] = useState<SelectFieldOption | null>(\n value ? { id: value, label: value } : null,\n );\n\n // Tracks the key we've already turned into a human-readable label so we don't re-resolve it.\n const resolvedKeyRef = useRef<string | null>(null);\n\n useEffect(() => {\n setSearchableSelected(prev => {\n if (!value) {\n return null;\n }\n if (prev?.id === value) {\n return prev;\n }\n return { id: value, label: value };\n });\n }, [value]);\n\n // On open (or when a saved searchable value appears), ask the host to resolve key -> label.\n useEffect(() => {\n if (status !== 'searchable' || !value) {\n resolvedKeyRef.current = null;\n return;\n }\n if (resolvedKeyRef.current === value) {\n return;\n }\n\n let cancelled = false;\n resolveOptions([value]).then(result => {\n if (cancelled) {\n return;\n }\n const match = result.find(option => option.key === value);\n if (match) {\n resolvedKeyRef.current = value;\n setSearchableSelected({ id: match.key, label: match.label });\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [status, value, resolveOptions]);\n\n const handleLoadOptions = useCallback(\n async (query: string) => {\n const result = await loadOptions(query);\n return result.map(toOption);\n },\n [loadOptions],\n );\n\n if (status === 'loading') {\n return (\n <TextField\n label=\"Value\"\n size=\"small\"\n flex={1}\n disabled\n value=\"\"\n placeholder=\"\"\n aria-label=\"Value\"\n />\n );\n }\n\n if (status === 'static') {\n return (\n <SelectFieldSync\n flex={1}\n size=\"small\"\n label=\"Value\"\n placeholder=\"Search value...\"\n options={options.map(toOption)}\n value={staticSelected}\n onSelectedOptionChange={option => onChange(option ? String(option.id) : '')}\n />\n );\n }\n\n if (status === 'searchable') {\n return (\n <SelectField\n flex={1}\n size=\"small\"\n label=\"Value\"\n placeholder=\"Type to search...\"\n initialLoad=\"open\"\n loadOptions={handleLoadOptions}\n value={searchableSelected}\n onSelectedOptionChange={option => {\n resolvedKeyRef.current = option ? String(option.id) : null;\n setSearchableSelected(option);\n onChange(option ? String(option.id) : '');\n }}\n />\n );\n }\n\n // idle / fallback (no source, empty, error, or timeout) -> free text.\n const handleTextChange = (raw: string) => {\n onChange(fieldType === 'number' ? sanitizeNumericInput(raw) : raw);\n };\n\n return (\n <TextField\n label=\"Value\"\n size=\"small\"\n flex={1}\n value={value}\n onChange={e => handleTextChange(e.target.value)}\n placeholder={fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...'}\n aria-label=\"Value\"\n {...(fieldType === 'number' && { inputMode: 'decimal' })}\n />\n );\n}\n"],"names":["TextField","SelectField","SelectFieldSync","useCallback","useEffect","useMemo","useRef","useState","useLookupOptions","toOption","option","id","key","label","sanitizeNumericInput","raw","value","replaceAll","isNegative","startsWith","firstDot","indexOf","slice","LookupValueControl","fieldType","lookupSource","onChange","loadOptions","options","resolveOptions","status","staticSelected","filter","map","searchableSelected","setSearchableSelected","resolvedKeyRef","prev","current","cancelled","then","result","match","find","handleLoadOptions","query","size","flex","disabled","placeholder","aria-label","onSelectedOptionChange","String","initialLoad","handleTextChange","e","target","inputMode"],"mappings":";AAAA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,WAAW,EAAqBC,eAAe,QAAQ,4BAA4B;AAC5F,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE1E,SAASC,gBAAgB,QAAQ,qBAAqB;AAUtD,MAAMC,WAAW,CAACC,SAA6C,CAAA;QAC3DC,IAAID,OAAOE,GAAG;QACdC,OAAOH,OAAOG,KAAK;IACvB,CAAA;AAEA,MAAMC,uBAAuB,CAACC;IAC1B,IAAIC,QAAQD,IAAIE,UAAU,CAAC,aAAa;IACxC,MAAMC,aAAaF,MAAMG,UAAU,CAAC;IACpCH,QAAQA,MAAMC,UA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;YAC1C;;IAGZ;IAEA,sEAAsE;IACtE,MAAM2C,mBAAmB,CAACvC;QACtBW,SAASF,cAAc,WAAWV,qBAAqBC,OAAOA;IAClE;IAEA,qBACI,KAACf;QACGa,OAAM;QACNiC,MAAK;QACLC,MAAM;QACN/B,OAAOA;QACPU,UAAU6B,CAAAA,IAAKD,iBAAiBC,EAAEC,MAAM,CAACxC,KAAK;QAC9CiC,aAAazB,cAAc,WAAW,aAAa;QACnD0B,cAAW;QACV,GAAI1B,cAAc,YAAY;YAAEiC,WAAW;QAAU,CAAC;;AAGnE"}
1
+ {"version":3,"sources":["../../src/display-conditions/LookupValueControl.tsx"],"sourcesContent":["import { TextField } from '@servicetitan/anvil2';\nimport { SelectField, SelectFieldOption, SelectFieldSync } from '@servicetitan/anvil2/beta';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { LookupOption } from './lookupOptionsController';\nimport { useLookupOptions } from './useLookupOptions';\n\nexport interface LookupValueControlProps {\n value: string;\n fieldType: 'number' | 'string';\n /** The selected data point's `options.fieldLookupSource`; empty -> free-text input. */\n lookupSource?: string;\n onChange: (value: string) => void;\n}\n\nconst toOption = (option: LookupOption): SelectFieldOption => ({\n id: option.key,\n label: option.label,\n});\n\n/*\n * Searchable sources return nothing until the user types, which would make the\n * dropdown show its built-in \"No match found\" empty state on open — confusing\n * before any search has happened. Render a disabled hint instead so the list is\n * never mistaken for \"no results\".\n */\nconst SEARCH_HINT_OPTION: SelectFieldOption = {\n id: '__lookup_search_hint__',\n label: 'Start typing to search…',\n disabled: true,\n};\n\nconst sanitizeNumericInput = (raw: string): string => {\n let value = raw.replaceAll(/[^0-9.-]/g, '');\n const isNegative = value.startsWith('-');\n value = value.replaceAll('-', '');\n if (isNegative) {\n value = `-${value}`;\n }\n const firstDot = value.indexOf('.');\n if (firstDot >= 0) {\n value = `${value.slice(0, firstDot + 1)}${value.slice(firstDot + 1).replaceAll('.', '')}`;\n }\n return value;\n};\n\n/**\n * Renders the value control for a single condition based on the field's lookup source:\n * - `static` -> full list returned by the host, filtered locally (`SelectFieldSync`).\n * - `searchable` -> host searches per typed query (`SelectField` + `loadOptions`).\n * - `idle`/`fallback`/`loading` -> free-text input (never block the user).\n *\n * Unlayer persists conditions as a Nunjucks string, so a saved searchable value\n * has no stored label — we display the saved key as the label until the user\n * re-searches and re-selects.\n */\nexport function LookupValueControl({\n fieldType,\n lookupSource,\n onChange,\n value,\n}: Readonly<LookupValueControlProps>) {\n const { loadOptions, options, resolveOptions, status } = useLookupOptions(lookupSource);\n\n const staticOptions = useMemo<SelectFieldOption[]>(() => options.map(toOption), [options]);\n\n /*\n * Fall back to the raw value so a saved key that the host omits from its list\n * (e.g. an inactive/renamed option) still shows on edit instead of vanishing.\n */\n const staticSelected = useMemo<SelectFieldOption | null>(() => {\n if (!value) {\n return null;\n }\n return (\n staticOptions.find(option => String(option.id) === value) ?? { id: value, label: value }\n );\n }, [staticOptions, value]);\n\n /*\n * Ensure the saved value is present in the list so it is visible/selectable\n * even when the host did not return it.\n */\n const staticOptionsWithSelected = useMemo<SelectFieldOption[]>(() => {\n if (\n staticSelected &&\n !staticOptions.some(option => String(option.id) === String(staticSelected.id))\n ) {\n return [staticSelected, ...staticOptions];\n }\n return staticOptions;\n }, [staticOptions, staticSelected]);\n\n const [searchableSelected, setSearchableSelected] = useState<SelectFieldOption | null>(\n value ? { id: value, label: value } : null,\n );\n\n // Tracks the key we've already turned into a human-readable label so we don't re-resolve it.\n const resolvedKeyRef = useRef<string | null>(null);\n\n useEffect(() => {\n setSearchableSelected(prev => {\n if (!value) {\n return null;\n }\n if (prev?.id === value) {\n return prev;\n }\n return { id: value, label: value };\n });\n }, [value]);\n\n // On open (or when a saved searchable value appears), ask the host to resolve key -> label.\n useEffect(() => {\n if (status !== 'searchable' || !value) {\n resolvedKeyRef.current = null;\n return;\n }\n if (resolvedKeyRef.current === value) {\n return;\n }\n\n let cancelled = false;\n resolveOptions([value]).then(result => {\n if (cancelled) {\n return;\n }\n const match = result.find(option => option.key === value);\n if (match) {\n resolvedKeyRef.current = value;\n setSearchableSelected({ id: match.key, label: match.label });\n }\n });\n\n return () => {\n cancelled = true;\n };\n }, [status, value, resolveOptions]);\n\n const handleLoadOptions = useCallback(\n async (query: string) => {\n if (!query.trim()) {\n return [SEARCH_HINT_OPTION];\n }\n const result = await loadOptions(query);\n return result.map(toOption);\n },\n [loadOptions],\n );\n\n if (status === 'loading') {\n return (\n <TextField\n label=\"Value\"\n size=\"small\"\n flex={1}\n disabled\n value=\"\"\n placeholder=\"\"\n aria-label=\"Value\"\n />\n );\n }\n\n if (status === 'static') {\n return (\n <SelectFieldSync\n flex={1}\n size=\"small\"\n label=\"Value\"\n placeholder=\"Search value...\"\n options={staticOptionsWithSelected}\n value={staticSelected}\n onSelectedOptionChange={option => onChange(option ? String(option.id) : '')}\n />\n );\n }\n\n if (status === 'searchable') {\n return (\n <SelectField\n flex={1}\n size=\"small\"\n label=\"Value\"\n placeholder=\"Type to search...\"\n initialLoad=\"open\"\n loadOptions={handleLoadOptions}\n value={searchableSelected}\n onSelectedOptionChange={option => {\n resolvedKeyRef.current = option ? String(option.id) : null;\n setSearchableSelected(option);\n onChange(option ? String(option.id) : '');\n }}\n />\n );\n }\n\n // idle / fallback (no source, empty, error, or timeout) -> free text.\n const handleTextChange = (raw: string) => {\n onChange(fieldType === 'number' ? sanitizeNumericInput(raw) : raw);\n };\n\n return (\n <TextField\n label=\"Value\"\n size=\"small\"\n flex={1}\n value={value}\n onChange={e => handleTextChange(e.target.value)}\n placeholder={fieldType === 'number' ? 'e.g. 1.5' : 'Enter value...'}\n aria-label=\"Value\"\n {...(fieldType === 'number' && { inputMode: 'decimal' })}\n />\n );\n}\n"],"names":["TextField","SelectField","SelectFieldSync","useCallback","useEffect","useMemo","useRef","useState","useLookupOptions","toOption","option","id","key","label","SEARCH_HINT_OPTION","disabled","sanitizeNumericInput","raw","value","replaceAll","isNegative","startsWith","firstDot","indexOf","slice","LookupValueControl","fieldType","lookupSource","onChange","loadOptions","options","resolveOptions","status","staticOptions","map","staticSelected","find","String","staticOptionsWithSelected","some","searchableSelected","setSearchableSelected","resolvedKeyRef","prev","current","cancelled","then","result","match","handleLoadOptions","query","trim","size","flex","placeholder","aria-label","onSelectedOptionChange","initialLoad","handleTextChange","e","target","inputMode"],"mappings":";AAAA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,WAAW,EAAqBC,eAAe,QAAQ,4BAA4B;AAC5F,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE1E,SAASC,gBAAgB,QAAQ,qBAAqB;AAUtD,MAAMC,WAAW,CAACC,SAA6C,CAAA;QAC3DC,IAAID,OAAOE,GAAG;QACdC,OAAOH,OAAOG,KAAK;IACvB,CAAA;AAEA;;;;;CAKC,GACD,MAAMC,qBAAwC;IAC1CH,IAAI;IACJE,OAAO;IACPE,UAAU;AACd;AAEA,MAAMC,uBAAuB,CAACC;IAC1B,IAAIC,QAAQD,IAAIE,UAAU,CAAC,aAAa;IACxC,MAAMC,aAAaF,MAAMG,UAAU,CAAC;IACpCH,QAAQA,MAAMC,UAAU,CAAC,KAAK;IAC9B,IAAIC,YAAY;QACZF,QAAQ,CAAC,CAAC,EAAEA,OAAO;IACvB;IACA,MAAMI,WAAWJ,MAAMK,OAAO,CAAC;IAC/B,IAAID,YAAY,GAAG;QACfJ,QAAQ,GAAGA,MAAMM,KAAK,CAAC,GAAGF,WAAW,KAAKJ,MAAMM,KAAK,CAACF,WAAW,GAAGH,UAAU,CAAC,KAAK,KAAK;IAC7F;IACA,OAAOD;AACX;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASO,mBAAmB,EAC/BC,SAAS,EACTC,YAAY,EACZC,QAAQ,EACRV,KAAK,EAC2B;IAChC,MAAM,EAAEW,WAAW,EAAEC,OAAO,EAAEC,cAAc,EAAEC,MAAM,EAAE,GAAGxB,iBAAiBmB;IAE1E,MAAMM,g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M+C,mBAAmB,CAACzC;QACtBW,SAASF,cAAc,WAAWV,qBAAqBC,OAAOA;IAClE;IAEA,qBACI,KAACjB;QACGa,OAAM;QACNuC,MAAK;QACLC,MAAM;QACNnC,OAAOA;QACPU,UAAU+B,CAAAA,IAAKD,iBAAiBC,EAAEC,MAAM,CAAC1C,KAAK;QAC9CoC,aAAa5B,cAAc,WAAW,aAAa;QACnD6B,cAAW;QACV,GAAI7B,cAAc,YAAY;YAAEmC,WAAW;QAAU,CAAC;;AAGnE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/dte-unlayer",
3
- "version": "0.143.0",
3
+ "version": "0.145.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -17,6 +17,18 @@ const toOption = (option: LookupOption): SelectFieldOption => ({
17
17
  label: option.label,
18
18
  });
19
19
 
20
+ /*
21
+ * Searchable sources return nothing until the user types, which would make the
22
+ * dropdown show its built-in "No match found" empty state on open — confusing
23
+ * before any search has happened. Render a disabled hint instead so the list is
24
+ * never mistaken for "no results".
25
+ */
26
+ const SEARCH_HINT_OPTION: SelectFieldOption = {
27
+ id: '__lookup_search_hint__',
28
+ label: 'Start typing to search…',
29
+ disabled: true,
30
+ };
31
+
20
32
  const sanitizeNumericInput = (raw: string): string => {
21
33
  let value = raw.replaceAll(/[^0-9.-]/g, '');
22
34
  const isNegative = value.startsWith('-');
@@ -49,10 +61,34 @@ export function LookupValueControl({
49
61
  }: Readonly<LookupValueControlProps>) {
50
62
  const { loadOptions, options, resolveOptions, status } = useLookupOptions(lookupSource);
51
63
 
52
- const staticSelected = useMemo<SelectFieldOption | null>(
53
- () => options.filter(option => option.key === value).map(toOption)[0] ?? null,
54
- [options, value],
55
- );
64
+ const staticOptions = useMemo<SelectFieldOption[]>(() => options.map(toOption), [options]);
65
+
66
+ /*
67
+ * Fall back to the raw value so a saved key that the host omits from its list
68
+ * (e.g. an inactive/renamed option) still shows on edit instead of vanishing.
69
+ */
70
+ const staticSelected = useMemo<SelectFieldOption | null>(() => {
71
+ if (!value) {
72
+ return null;
73
+ }
74
+ return (
75
+ staticOptions.find(option => String(option.id) === value) ?? { id: value, label: value }
76
+ );
77
+ }, [staticOptions, value]);
78
+
79
+ /*
80
+ * Ensure the saved value is present in the list so it is visible/selectable
81
+ * even when the host did not return it.
82
+ */
83
+ const staticOptionsWithSelected = useMemo<SelectFieldOption[]>(() => {
84
+ if (
85
+ staticSelected &&
86
+ !staticOptions.some(option => String(option.id) === String(staticSelected.id))
87
+ ) {
88
+ return [staticSelected, ...staticOptions];
89
+ }
90
+ return staticOptions;
91
+ }, [staticOptions, staticSelected]);
56
92
 
57
93
  const [searchableSelected, setSearchableSelected] = useState<SelectFieldOption | null>(
58
94
  value ? { id: value, label: value } : null,
@@ -102,6 +138,9 @@ export function LookupValueControl({
102
138
 
103
139
  const handleLoadOptions = useCallback(
104
140
  async (query: string) => {
141
+ if (!query.trim()) {
142
+ return [SEARCH_HINT_OPTION];
143
+ }
105
144
  const result = await loadOptions(query);
106
145
  return result.map(toOption);
107
146
  },
@@ -129,7 +168,7 @@ export function LookupValueControl({
129
168
  size="small"
130
169
  label="Value"
131
170
  placeholder="Search value..."
132
- options={options.map(toOption)}
171
+ options={staticOptionsWithSelected}
133
172
  value={staticSelected}
134
173
  onSelectedOptionChange={option => onChange(option ? String(option.id) : '')}
135
174
  />