@orangelogic/myos-gen1 1.0.0-alpha.3 → 1.0.0-alpha.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.
Files changed (46) hide show
  1. package/NOTICE.md +4 -0
  2. package/README.md +9 -11
  3. package/contracts/dotnet/ReleaseContext.cs +10 -1
  4. package/contracts/dotnet/ReleaseEligibility.cs +27 -0
  5. package/contracts/release/3/README.md +21 -2
  6. package/contracts/release/3/release.ts +10 -0
  7. package/contracts/unit/2/unit.ts +8 -0
  8. package/dist/autocomplete-R6DME2OB.js +158 -0
  9. package/dist/chunk-66SV6MPF.js +737 -0
  10. package/dist/chunk-BTZWYDJT.js +144 -0
  11. package/dist/contracts/release.d.ts +17 -0
  12. package/dist/contracts/unit.d.ts +11 -0
  13. package/dist/date-HIILR4IG.js +74 -0
  14. package/dist/media-IECUTXW5.js +68 -0
  15. package/dist/menu-WZ4WC2IN.js +175 -0
  16. package/dist/rich-text-S76EGP2P.js +149 -0
  17. package/dist/runtime/autocomplete-input.d.ts +8 -0
  18. package/dist/runtime/control-menu.d.ts +3 -4
  19. package/dist/runtime/controls.d.ts +17 -5
  20. package/dist/runtime/date-input.d.ts +5 -0
  21. package/dist/runtime/index.d.ts +1 -0
  22. package/dist/runtime/index.js +60 -1859
  23. package/dist/runtime/lazy-renderers.d.ts +37 -0
  24. package/dist/runtime/menu-panels.d.ts +3 -0
  25. package/dist/runtime/renderer-families.json +126 -0
  26. package/dist/runtime/renderer-loaders.d.ts +6 -0
  27. package/dist/runtime/renderers/autocomplete.d.ts +1 -0
  28. package/dist/runtime/renderers/date.d.ts +1 -0
  29. package/dist/runtime/renderers/media.d.ts +1 -0
  30. package/dist/runtime/renderers/menu.d.ts +2 -0
  31. package/dist/runtime/renderers/rich-text.d.ts +1 -0
  32. package/dist/runtime/renderers/select.d.ts +1 -0
  33. package/dist/runtime/renderers/tab-menu.d.ts +1 -0
  34. package/dist/runtime/renderers/table.d.ts +1 -0
  35. package/dist/runtime/renderers/webcomponent.d.ts +1 -0
  36. package/dist/runtime/renderers/widgets.d.ts +1 -0
  37. package/dist/runtime/select-input.d.ts +5 -0
  38. package/dist/select-D5QBUQE6.js +78 -0
  39. package/dist/tab-menu-PBUFHDEE.js +59 -0
  40. package/dist/table-FELNJICP.js +137 -0
  41. package/dist/webcomponent-5RFJIIY6.js +235 -0
  42. package/dist/widgets-7MLUBX4G.js +81 -0
  43. package/package.json +8 -4
  44. package/PROVENANCE.json +0 -459
  45. package/contracts/fixtures/eligibility.json +0 -3003
  46. package/contracts/fixtures/semver.json +0 -42
package/NOTICE.md ADDED
@@ -0,0 +1,4 @@
1
+ Gen1 provides the Orange Logic native React runtime, component build helpers,
2
+ versioned contracts and schemas. Copyright and license notices in distributed
3
+ source files remain applicable. This notice does not grant redistribution rights
4
+ or change the package's UNLICENSED status.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # @orangelogic/myos-gen1
2
2
 
3
- Native React Gen1 unit runtime, public wire contracts and standalone component build tools. This is infrastructure, not a ported Lit component. It is released with `@orangelogic/design-system-react` at the same version (first joint release: `1.0.0-alpha.2`). React and React DOM are peers; the design system is an exact-version peer.
3
+ Native React Gen1 unit runtime, public wire contracts and standalone component build tools. This is infrastructure, not a ported Lit component. Its design-system runtime is an exact-version peer and may retain its version for a contracts-only release. React and React DOM are peers; the design system is an exact-version peer.
4
4
 
5
- Install the two packages from the configured npm feed and install their React peers:
5
+ After alpha.4.1 is published, install the exact packages from the configured npm feed and their React peers:
6
6
 
7
7
  ```sh
8
- npm install --save-exact @orangelogic/myos-gen1@1.0.0-alpha.2 @orangelogic/design-system-react@1.0.0-alpha.2 react@19.3.0 react-dom@19.3.0
8
+ npm install --save-exact @orangelogic/myos-gen1@1.0.0-alpha.4.1 @orangelogic/design-system-react@1.0.0-alpha.4 react@19.3.0 react-dom@19.3.0
9
9
  npm install --save-dev --save-exact @types/react@19.3.0 @types/react-dom@19.3.0
10
10
  ```
11
11
 
@@ -39,19 +39,17 @@ Run `npx --no-install gen1-build` in that folder, or call `buildComponent({root}
39
39
  | `./contracts/unit` | All original unit types, public values and vocabulary |
40
40
  | `./contracts/release` | All original release, eligibility, slot and host wire types |
41
41
  | `./contracts/semver` | Original strict SemVer implementation |
42
- | `./build` / `gen1-build` | `buildComponent({root})` replaces repository-wide `buildComponents({selected,changed})`; G2 owns component enumeration and changed-build scheduling |
42
+ | `./build` / `gen1-build` | `buildComponent({root})` builds one component; callers own component enumeration and changed-build scheduling |
43
43
  | `./boundaries` | Original boundary primitives; standalone builds use `checkBoundaries(root,{entry})` |
44
44
  | `./components`, `./demo` | Descriptor/mount and data-only demo helpers |
45
45
  | `./sync-contracts` | `syncGen1Contracts` checks source synchronization; `copyGen1Contracts({destination,check})` copies or verifies an installed package’s served contracts |
46
- | `./protocols/*` | Served contracts, e.g. `protocols/unit/1/unit.ts`, `protocols/unit/2/unit.ts`, release/3 schemas and fixtures |
46
+ | `./protocols/*` | Served contracts, e.g. `protocols/unit/1/unit.ts`, `protocols/unit/2/unit.ts`, release/3 schemas; development fixtures are excluded |
47
47
  | `./runtime/styles.css` | Runtime CSS for explicit host stylesheet handling |
48
48
 
49
- Protocol 1 is frozen byte-for-byte; protocol 2 is copied unchanged. See `PROVENANCE.json` for source commit and byte hashes, and `api-map.json` for every original public export. Runtime CSS passes through CSS Modules while preserving the established `uic-*` hooks used by existing components. Heavy engines remain lazy inside the design-system controls.
49
+ Protocol 1 is frozen byte-for-byte; protocol 2 is copied unchanged. See `NOTICE.md` for attribution and `api-map.json` for the public export mapping. Runtime CSS passes through CSS Modules while preserving the established `uic-*` hooks used by existing components. Heavy engines remain lazy inside the design-system controls.
50
50
 
51
- The components repository retains component implementations, registry publication, release-manifest construction, preview routing and product acceptance. G2 must replace relative runtime/contract imports, remove its runtime workspace and rebuild orchestration, copy served contracts from these package exports, update registry validators to admit the shared runtime specifier and transitive graph, and update the gen1-port skill. Previously per-component omitted-control stand-ins disappear: the shared runtime exposes the full supported control closure. Registry admission and per-mount byte/node caps must be checked against that closure. No protocol, authorization or CSP relaxation is implied.
51
+ Consumers own component implementations, registry publication, release manifests and preview routing. Use the package's served contracts, admit the shared runtime and its transitive graph in the host loader, and retain registry admission and per-mount byte/node limits. No protocol, authorization or CSP relaxation is implied.
52
52
 
53
- Source and runtime API behavior are preserved except the documented build/distribution changes. These author checks do not constitute independent acceptance or Cortex product integration approval.
53
+ The scroll binding resolves its owning control through native display:contents wrappers and ignores nested control scrolls. Use `discoverComponents(componentProjectRoot)` with an explicit project root; standalone builds use `checkBoundaries`, while `checkLayout` remains the legacy bare-component layout checker. The emitted stylesheet is `mount.css`; Release assembly should consume `mount.css` and include it in the source-digest recipe.
54
54
 
55
- The scroll binding resolves its owning control through native display:contents wrappers and ignores nested control scrolls. Use `discoverComponents(componentProjectRoot)` with an explicit project root; standalone builds use `checkBoundaries`, while `checkLayout` remains the legacy bare-component layout checker. The emitted stylesheet is `mount.css`; G2 release assembly must update its old `styles.css` input and source-digest recipe.
56
-
57
- G2 reconciliation preserves V01 runtime fixes and F2B scaffold isolation, including their tests. `buildComponent({root, project})` accepts an explicit shared dependency manifest for bare first-party components; source ownership remains confined to `root`. Standalone consumers omit `project`. The distribution includes `protocols/dotnet/*` for the registry's project reference.
55
+ `buildComponent({root, project})` accepts an explicit shared dependency manifest for bare first-party components; source ownership remains confined to `root`. Standalone consumers omit `project`. The distribution includes `protocols/dotnet/*` for the registry's project reference.
@@ -21,7 +21,16 @@ public sealed record RegistryEvidence(bool Authenticated);
21
21
  public sealed record ProvenanceEvidence(
22
22
  bool Authenticated, ReleaseIdentity? Identity, ReleaseDigests? Digests, string? AudienceSha256,
23
23
  Approval? Approval, bool IsOrangeLogicAuthored, bool OfficialDefault,
24
- bool CodeReviewVerified, bool SecurityReviewVerified, bool ExemptionVerified);
24
+ bool CodeReviewVerified, bool SecurityReviewVerified, bool ExemptionVerified,
25
+ [property: System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
26
+ ManualStableAttestation? ManualStable = null);
27
+
28
+ /// <summary>Registry-issued Staff endorsement of exact unchanged source bytes. It grants neither review nor official coverage.</summary>
29
+ public sealed record ManualStableAttestation(
30
+ string? Format, ReleaseIdentity? SourceIdentity, ReleaseDigests? SourceDigests,
31
+ ReleaseIdentity? TargetIdentity, ReleaseDigests? TargetDigests, string? AudienceSha256,
32
+ ExecutionPrivilege Ceiling, long PolicyVersion, string? ActorIssuer, string? ActorSubject,
33
+ DateTimeOffset PromotedAtUtc, string? Reason, bool StaffAuthorized);
25
34
 
26
35
  /// <summary>Authenticated watermark plus conservative monotonic age; receipt time never replaces issue time.</summary>
27
36
  public sealed record RevocationEvidence(
@@ -87,6 +87,8 @@ public static class ReleaseEligibility
87
87
  !Enum.IsDefined(a.Ceiling) || a.Ceiling == ExecutionPrivilege.Unknown ||
88
88
  PrivilegeRank(c.Privilege) > PrivilegeRank(a.Ceiling)) return false;
89
89
  if (r.Audience!.Kind == "restrictedOLAlternative" && !p.IsOrangeLogicAuthored) return false;
90
+ if (a.ExemptionId == "manual-stable:1" || p.ManualStable is not null)
91
+ return ManualStableProofAccepts(r, p, c.Evidence.EvaluatedAtUtc);
90
92
  // The trusted host supplies a channel only after checking current site opt-in and signed membership.
91
93
  if (a.ExemptionId?.StartsWith("channel:", StringComparison.Ordinal) == true)
92
94
  return Text(allowedChannel) && a.ExemptionId == "channel:" + allowedChannel &&
@@ -101,6 +103,31 @@ public static class ReleaseEligibility
101
103
  (a.SecurityReviewId is null || (Text(a.SecurityReviewId) && p.SecurityReviewVerified));
102
104
  }
103
105
 
106
+ /// <summary>Checks only a manual attestation's binding and truthfulness. Call Evaluate for audience, privilege, availability and revocation.</summary>
107
+ public static bool ManualStableProofAccepts(ReleasePolicy r, ProvenanceEvidence p, DateTimeOffset now)
108
+ {
109
+ var a = r.Approval!;
110
+ var m = p.ManualStable;
111
+ return a is not null && ValidIdentity(r.Identity) && Digests(r.Digests) && Hash(r.AudienceSha256) &&
112
+ p.Authenticated && p.Identity == r.Identity && p.Digests == r.Digests && p.Approval == a &&
113
+ p.AudienceSha256 == r.AudienceSha256 && a.Digests == r.Digests && a.AudienceSha256 == r.AudienceSha256 &&
114
+ Positive(a.Revision) && Positive(a.PolicyVersion) && Enum.IsDefined(a.Ceiling) && a.Ceiling != ExecutionPrivilege.Unknown &&
115
+ a.ExemptionId == "manual-stable:1" && m is not null && m.Format == "orangelogic.gen1.manual-stable/1" &&
116
+ m.StaffAuthorized && Text(m.ActorIssuer) && Text(m.ActorSubject) &&
117
+ Utc(m.PromotedAtUtc) && m.PromotedAtUtc <= now && m.Reason is { Length: <= 1024 } && !m.Reason.Any(char.IsControl) &&
118
+ ValidIdentity(m.SourceIdentity) && StrictSemVersion.Parse(m.SourceIdentity!.Version!).IsPrerelease &&
119
+ m.SourceIdentity!.PackageId == r.Identity!.PackageId && m.TargetIdentity == r.Identity &&
120
+ !StrictSemVersion.Parse(r.Identity!.Version!).IsPrerelease && !r.Identity.Version!.Contains('+') &&
121
+ Digests(m.SourceDigests) && m.TargetDigests == r.Digests &&
122
+ m.SourceDigests!.Release != r.Digests!.Release && m.SourceDigests.Manifest != r.Digests.Manifest &&
123
+ m.SourceDigests.Source == r.Digests.Source && m.SourceDigests.Build == r.Digests.Build &&
124
+ m.SourceDigests.Artifact == r.Digests.Artifact && m.SourceDigests.Authorship == r.Digests.Authorship &&
125
+ m.AudienceSha256 == r.AudienceSha256 && m.Ceiling == a.Ceiling && m.PolicyVersion == a.PolicyVersion &&
126
+ !r.OfficialDefault && !p.OfficialDefault && !p.IsOrangeLogicAuthored &&
127
+ !p.CodeReviewVerified && !p.SecurityReviewVerified && !p.ExemptionVerified &&
128
+ a.CodeReviewId is null && a.SecurityReviewId is null;
129
+ }
130
+
104
131
  private static bool Fresh(ExecutionContext c)
105
132
  {
106
133
  var f = c.Evidence!.Revocation;
@@ -28,8 +28,27 @@ demo code reachable from production. The independent build gate verifies actual
28
28
  bytes, provenance, recipes, toolchains and policy evidence. Passing the schema
29
29
  does not establish those facts or authorize publication.
30
30
 
31
- Development seeding only; production publication pending R-SCAN/R-INSTAUTH, see
32
- 42CND6/42CLL6. The source-build runner is parked; built-bundle publication is disabled.
31
+ Authenticated channel prerelease bundles use the registry channel validator. Reviewed stable
32
+ publication still requires the source pipeline, whose runner is parked. Existing eligible channel
33
+ releases may use the distinct manual stable policy capability below; arbitrary stable bundle
34
+ uploads remain refused.
33
35
 
34
36
 
35
37
  Published releases may carry one optional non-executable `source` asset: path `source.zip`, content type `application/zip`, SHA-256 and `bytes` (1 to 8,388,608). Gen1 additionally requires empty `imports` and `resources`; source is an independent root outside both executable graphs. The registry verifies its bytes and rejects an archive that is not a plain set of regular files with safe relative paths. Manifests keep the entry (their digests and approvals cover it), but it has no asset URL, the normal asset routes deny it, and Cortex ignores it. Only Link sessions at `/api/packages/{id}/versions/{version}/source.zip` and authenticated `GetComponentSource(packageId, version)` MCP calls can download it. Existing releases without source remain valid.
38
+
39
+ ## Manual stable policy capability 1
40
+
41
+ The server policy adds optional `ProvenanceEvidence.manualStable` with format
42
+ `orangelogic.gen1.manual-stable/1`; it is omitted for existing reviewed/channel projections.
43
+ The attestation binds source/target identities and all digests, audience digest, capability ceiling,
44
+ policy version, authenticated Staff actor, UTC time and reason. Its approval uses `manual-stable:1`.
45
+ Review IDs remain null and code/security/exemption verification, Orange Logic authorship and
46
+ official-default flags remain false. The shared evaluator requires the complete proof and preserves
47
+ all ordinary eligibility checks. Manual evidence cannot satisfy official coverage.
48
+
49
+ This changes server policy capability only; component protocols, slots and release-manifest schema
50
+ versions stay unchanged. Older strict consumers reject the new property and can reject the entire
51
+ package response. Consumers must update the shared evaluator and adapter before using manual tags.
52
+ The registry must derive and verify the preserved audience and ceiling from immutable source policy,
53
+ not from a caller-supplied attestation. `ManualStableProofAccepts` checks the attestation only;
54
+ `Evaluate` remains required for actual consumption (audience, privilege, freshness and revocation).
@@ -37,6 +37,16 @@ export interface ProvenanceEvidence {
37
37
  readonly authenticated: boolean; readonly identity: ReleaseIdentity; readonly digests: ReleaseDigests; readonly audienceSha256: string;
38
38
  readonly approval: Approval; readonly isOrangeLogicAuthored: boolean; readonly officialDefault: boolean;
39
39
  readonly codeReviewVerified: boolean; readonly securityReviewVerified: boolean; readonly exemptionVerified: boolean;
40
+ readonly manualStable?: ManualStableAttestation | null;
41
+ }
42
+ /** Registry-issued manual Staff endorsement; never independent review or official coverage. */
43
+ export interface ManualStableAttestation {
44
+ readonly format: 'orangelogic.gen1.manual-stable/1';
45
+ readonly sourceIdentity: ReleaseIdentity; readonly sourceDigests: ReleaseDigests;
46
+ readonly targetIdentity: ReleaseIdentity; readonly targetDigests: ReleaseDigests;
47
+ readonly audienceSha256: string; readonly ceiling: ExecutionPrivilege; readonly policyVersion: number;
48
+ readonly actorIssuer: string; readonly actorSubject: string; readonly promotedAtUtc: string;
49
+ readonly reason: string; readonly staffAuthorized: boolean;
40
50
  }
41
51
  export interface RevocationEvidence {
42
52
  readonly authenticated: boolean; readonly policyRevision: number;
@@ -145,6 +145,8 @@ export interface Presentation { readonly theme: 'light' | 'dark'; readonly local
145
145
  export interface AutocompleteCell { readonly text: string; readonly image?: string }
146
146
  export interface AutocompleteOption { readonly value: string; readonly label: string; readonly cells?: readonly AutocompleteCell[] }
147
147
  export interface AutocompleteResult { readonly options: readonly AutocompleteOption[]; readonly headers?: readonly string[]; readonly widths?: readonly number[] }
148
+ /** A design-system icon font family and its release-relative stylesheet, e.g. `assets/fonts/fontawesome.css`. */
149
+ export interface IconFontRequest { readonly family: 'outlined-core' | 'outlined' | 'fontawesome' | 'rounded' | 'sharp'; readonly stylesheet: string }
148
150
  export interface HostBridge {
149
151
  readonly unitId: string; readonly presentation: Presentation;
150
152
  getValue(unitId: string, controlId: string): InputValue | undefined;
@@ -153,6 +155,12 @@ export interface HostBridge {
153
155
  setValue(unitId: string, controlId: string, value: InputValue): void;
154
156
  fire(unitId: string, controlId: string, trigger: Trigger, options?: FireOptions): boolean;
155
157
  autocomplete(unitId: string, controlId: string, term: string): Promise<AutocompleteResult>;
158
+ /**
159
+ * Optional on-demand icon fonts. A host that leaves the design system's `assets/fonts/*.css` nodes out of a mount's
160
+ * eager set loads the requested stylesheet node and its fonts on first use, verified against the delivery graph, and
161
+ * resolves once the `@font-face` is registered on the document. Older hosts omit it and load fonts eagerly.
162
+ */
163
+ loadIconFont?(request: IconFontRequest): Promise<void>;
156
164
  /** Subscribe to replacement public units; returned unsubscribe and dispose must be idempotent. */
157
165
  subscribe(unitId: string, listener: (unit: Unit) => void): () => void;
158
166
  dispose(): void;
@@ -0,0 +1,158 @@
1
+ import {
2
+ CREATE_ENTRY_VALUE,
3
+ Text,
4
+ inputAccessibility
5
+ } from "./chunk-66SV6MPF.js";
6
+ import {
7
+ useFire,
8
+ useInputValue
9
+ } from "./chunk-BTZWYDJT.js";
10
+
11
+ // packages/gen1/src/runtime/autocomplete-input.tsx
12
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
13
+ import { CxAvatar } from "@orangelogic/design-system-react/avatar";
14
+ import { CxButton } from "@orangelogic/design-system-react/button";
15
+ import { CxDynamicSelect } from "@orangelogic/design-system-react/dynamic-select";
16
+ import { CxIcon } from "@orangelogic/design-system-react/icon";
17
+ import { useDesignSystem } from "@orangelogic/design-system-react/foundation";
18
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
19
+ function creationOption(control, term, options) {
20
+ const typed = term.trim().toLowerCase();
21
+ if (!control.allowCreation || !typed) return null;
22
+ const matched = options.some((option) => [option.label, ...(option.cells ?? []).map((cell) => cell.text)].some((text) => text.trim().toLowerCase() === typed));
23
+ return matched ? null : { value: CREATE_ENTRY_VALUE, label: (control.creationLabel ?? "").replace("[TEXT]", term.trim()) };
24
+ }
25
+ function asAutocompleteResult(result) {
26
+ if (Array.isArray(result)) return { options: result };
27
+ return { ...result, options: Array.isArray(result?.options) ? result.options : [] };
28
+ }
29
+ function resultLayout(result) {
30
+ const count = Math.max(result.headers?.length ?? 0, 0, ...result.options.map((option) => option.cells?.length ?? 0));
31
+ const indexes = Array.from({ length: count }, (_, index) => index);
32
+ const avatarColumn = indexes.find((index) => result.options.some((option) => option.cells?.[index]?.image) && result.options.every((option) => !option.cells?.[index]?.text)) ?? -1;
33
+ const textColumns = indexes.filter((index) => index !== avatarColumn);
34
+ return textColumns.length > 1 ? { headers: result.headers ?? [], widths: result.widths ?? [], textColumns, avatarColumn } : null;
35
+ }
36
+ var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
37
+ function Highlight({ text, term }) {
38
+ const words = term.trim().split(/\s+/).filter(Boolean).map(escapeRegExp);
39
+ if (!words.length || !text) return /* @__PURE__ */ jsx(Fragment, { children: text });
40
+ return /* @__PURE__ */ jsx(Fragment, { children: text.split(new RegExp(`(${words.join("|")})`, "gi")).map((part, index) => index % 2 ? /* @__PURE__ */ jsx("strong", { children: part }, index) : part) });
41
+ }
42
+ function resultColumns(layout, term) {
43
+ const [first] = layout.textColumns;
44
+ return layout.textColumns.map((index) => ({
45
+ field: `c${index}`,
46
+ header: layout.headers[index] ?? "",
47
+ flex: (layout.widths[index] || 1) + (index === first && layout.avatarColumn >= 0 ? layout.widths[layout.avatarColumn] || 0 : 0),
48
+ render: (option) => {
49
+ if (option.value === CREATE_ENTRY_VALUE) {
50
+ return index === first ? /* @__PURE__ */ jsxs("span", { className: "uic-result-cell", children: [
51
+ /* @__PURE__ */ jsx(CxIcon, { name: "add_circle", className: "uic-result-create-icon" }),
52
+ /* @__PURE__ */ jsx("span", { children: option.label })
53
+ ] }) : null;
54
+ }
55
+ const text = option.cells?.[index]?.text ?? (index === first ? option.label : "");
56
+ const image = index === first && layout.avatarColumn >= 0 ? option.cells?.[layout.avatarColumn]?.image : void 0;
57
+ return /* @__PURE__ */ jsxs("span", { className: "uic-result-cell", children: [
58
+ index === first && layout.avatarColumn >= 0 && /* @__PURE__ */ jsx(CxAvatar, { image: image ?? "", label: text, "aria-hidden": "true", className: "uic-result-avatar" }),
59
+ /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(Highlight, { text, term }) })
60
+ ] });
61
+ }
62
+ }));
63
+ }
64
+ function AutocompleteInput({ control, unit, ctx }) {
65
+ const { messages } = useDesignSystem();
66
+ const select = useRef(null);
67
+ const creationText = useRef("");
68
+ const search = !!ctx.searchPickers?.has(control.id);
69
+ useEffect(() => {
70
+ if (!search) return;
71
+ ctx.onPickerFocusReady?.(() => select.current?.focus());
72
+ select.current?.focus();
73
+ return () => ctx.onPickerFocusReady?.(null);
74
+ }, [search, ctx]);
75
+ const [value, setValue] = useInputValue(ctx.host, unit.id, control.id, unit.inputs[control.id]);
76
+ const fire = useFire(ctx.host, unit.id, unit.triggers);
77
+ const selections = control.multiple && Array.isArray(value) ? value : void 0;
78
+ const [layout, setLayout] = useState(null);
79
+ const [term, setTerm] = useState("");
80
+ const api = useCallback(async ({ searchTerm } = {}) => {
81
+ const result = asAutocompleteResult(await ctx.host.autocomplete(unit.id, control.id, searchTerm ?? ""));
82
+ const creation = creationOption(control, searchTerm ?? "", result.options);
83
+ if (creation) creationText.current = (searchTerm ?? "").trim();
84
+ const next = result.options.length ? resultLayout(result) : void 0;
85
+ if (next !== void 0) setLayout((current) => JSON.stringify(next) === JSON.stringify(current) ? current : next);
86
+ setTerm(searchTerm ?? "");
87
+ const retained = (selections ?? []).filter((selection) => !result.options.some((option) => option.value === selection.value)).map((selection) => ({ value: selection.value, label: selection.text }));
88
+ return { data: [...retained, ...result.options, ...creation ? [creation] : []].map((option) => ({ ...option })), hasMore: false };
89
+ }, [ctx.host, unit.id, control, selections]);
90
+ const columns = useMemo(() => layout ? resultColumns(layout, term) : void 0, [layout, term]);
91
+ return /* @__PURE__ */ jsx(
92
+ CxDynamicSelect,
93
+ {
94
+ ...inputAccessibility(control),
95
+ noOptionText: messages.noOptions ?? "",
96
+ ref: select,
97
+ size: search ? "small" : void 0,
98
+ columns,
99
+ iconName: search ? "search" : void 0,
100
+ noExpandIcon: search,
101
+ suffix: control.optionLabel && unit.triggers[control.id]?.includes("option") ? /* @__PURE__ */ jsx(
102
+ CxButton,
103
+ {
104
+ variant: "text",
105
+ disabled: control.disabled || control.readOnly,
106
+ "data-control-id": control.id,
107
+ onMouseDown: (event) => event.preventDefault(),
108
+ onClick: (event) => {
109
+ event.preventDefault();
110
+ event.stopPropagation();
111
+ const text = select.current?.searchTerm ?? term;
112
+ setValue({ text, value: typeof value === "object" && "text" in value && value.text === text ? value.value : "" });
113
+ fire(control.id, "option", { domEvent: event.nativeEvent });
114
+ },
115
+ children: /* @__PURE__ */ jsx(Text, { value: control.optionLabel, html: control.html })
116
+ }
117
+ ) : void 0,
118
+ borderless: search,
119
+ rootProps: { className: search ? "uic-search" : void 0 },
120
+ hoist: true,
121
+ "data-control-id": control.id,
122
+ label: control.label ? /* @__PURE__ */ jsx(Text, { value: control.label, html: control.html }) : void 0,
123
+ helpText: control.warning || control.description,
124
+ placeholder: control.placeholder,
125
+ value: control.multiple ? (selections ?? []).map((selection) => selection.value) : typeof value === "object" && "text" in value ? value.value : "",
126
+ multiple: control.multiple,
127
+ getOptionLabel: control.multiple ? (option) => {
128
+ const id = option?.dataset.value;
129
+ return selections?.find((selection) => selection.value === id)?.text ?? select.current?.options.find((entry) => entry.value === id)?.label ?? "";
130
+ } : void 0,
131
+ useSearchTerm: true,
132
+ clearable: true,
133
+ allowFreetext: control.freeText,
134
+ required: control.required,
135
+ disabled: control.disabled || control.readOnly,
136
+ api,
137
+ onValueChange: (detail) => {
138
+ if (control.multiple) {
139
+ if (control.disabled || control.readOnly || detail.reason === "reset") return;
140
+ const ids = Array.isArray(detail.value) ? detail.value : detail.value ? [detail.value] : [];
141
+ const next2 = ids.includes("") ? [] : [...new Set(ids)].map((id) => {
142
+ const previous = selections?.find((selection) => selection.value === id);
143
+ return { text: previous?.text ?? select.current?.options.find((option) => option.value === id)?.label ?? id, value: id };
144
+ });
145
+ setValue(next2);
146
+ return;
147
+ }
148
+ const next = detail.serializedValue ?? String(detail.value ?? "");
149
+ const text = next === CREATE_ENTRY_VALUE ? creationText.current : detail.selectedOption?.label ?? detail.displayValue ?? next;
150
+ setValue({ text: next ? text : "", value: next });
151
+ fire(control.id, next ? "select" : "clear");
152
+ }
153
+ }
154
+ );
155
+ }
156
+ export {
157
+ AutocompleteInput
158
+ };