@orangelogic/myos-gen1 1.0.0-alpha.2 → 1.0.0-alpha.4

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 (36) hide show
  1. package/contracts/unit/2/unit.ts +8 -0
  2. package/dist/autocomplete-R6DME2OB.js +158 -0
  3. package/dist/chunk-66SV6MPF.js +737 -0
  4. package/dist/chunk-BTZWYDJT.js +144 -0
  5. package/dist/contracts/unit.d.ts +11 -0
  6. package/dist/date-HIILR4IG.js +74 -0
  7. package/dist/media-IECUTXW5.js +68 -0
  8. package/dist/menu-WZ4WC2IN.js +175 -0
  9. package/dist/rich-text-S76EGP2P.js +149 -0
  10. package/dist/runtime/autocomplete-input.d.ts +8 -0
  11. package/dist/runtime/control-menu.d.ts +3 -4
  12. package/dist/runtime/controls.d.ts +17 -5
  13. package/dist/runtime/date-input.d.ts +5 -0
  14. package/dist/runtime/index.d.ts +1 -0
  15. package/dist/runtime/index.js +60 -1859
  16. package/dist/runtime/lazy-renderers.d.ts +37 -0
  17. package/dist/runtime/menu-panels.d.ts +3 -0
  18. package/dist/runtime/renderer-families.json +126 -0
  19. package/dist/runtime/renderer-loaders.d.ts +6 -0
  20. package/dist/runtime/renderers/autocomplete.d.ts +1 -0
  21. package/dist/runtime/renderers/date.d.ts +1 -0
  22. package/dist/runtime/renderers/media.d.ts +1 -0
  23. package/dist/runtime/renderers/menu.d.ts +2 -0
  24. package/dist/runtime/renderers/rich-text.d.ts +1 -0
  25. package/dist/runtime/renderers/select.d.ts +1 -0
  26. package/dist/runtime/renderers/tab-menu.d.ts +1 -0
  27. package/dist/runtime/renderers/table.d.ts +1 -0
  28. package/dist/runtime/renderers/webcomponent.d.ts +1 -0
  29. package/dist/runtime/renderers/widgets.d.ts +1 -0
  30. package/dist/runtime/select-input.d.ts +5 -0
  31. package/dist/select-D5QBUQE6.js +78 -0
  32. package/dist/tab-menu-PBUFHDEE.js +59 -0
  33. package/dist/table-FELNJICP.js +137 -0
  34. package/dist/webcomponent-5RFJIIY6.js +235 -0
  35. package/dist/widgets-7MLUBX4G.js +81 -0
  36. package/package.json +4 -4
@@ -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
+ };