reifyui 0.13.0 → 0.13.2

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/dist/index.d.ts CHANGED
@@ -465,7 +465,14 @@ export interface PromptOptions extends ConfirmOptions {
465
465
  /** Return an error message to reject, or null/undefined to accept. */
466
466
  validate?: (value: string) => string | null | undefined;
467
467
  }
468
- export interface CreateType { kind: string; label: string; color?: string; icon?: ReactNode; }
468
+ /** A starting point offered under the name for one type (templates): load() resolves to the list,
469
+ * defaultId is preselected when present, and the chosen id comes back as `choice`. */
470
+ export interface CreateChoices {
471
+ label: string;
472
+ load: () => Promise<Array<{ id: string; name: string; description?: string }>> | Array<{ id: string; name: string; description?: string }>;
473
+ defaultId?: string;
474
+ }
475
+ export interface CreateType { kind: string; label: string; color?: string; icon?: ReactNode; choices?: CreateChoices; }
469
476
  export interface CreateOptions extends PromptOptions {
470
477
  types?: CreateType[]; defaultKind?: string;
471
478
  }
@@ -474,7 +481,7 @@ export interface DialogApi {
474
481
  confirm(opts: ConfirmOptions): Promise<boolean>;
475
482
  /** Resolves to the entered string, or null when cancelled. */
476
483
  prompt(opts: PromptOptions): Promise<string | null>;
477
- create(opts: CreateOptions): Promise<{ kind: string; name: string } | null>;
484
+ create(opts: CreateOptions): Promise<{ kind: string; name: string; choice?: string | null } | null>;
478
485
  labels: Required<DialogLabels>;
479
486
  }
480
487
  export const DialogHost: ComponentType<{
@@ -774,3 +781,22 @@ export const TL_MIN_PPS: number;
774
781
  export const TL_MAX_PPS: number;
775
782
  export const TL_DEFAULT_PPS: number;
776
783
  export const TL_HEAD_W: number;
784
+
785
+ // ── Mention model — the pill formats and the pure helpers behind MentionInput, namespaced so a
786
+ // host can write and parse the same text the input does (`mention.CHAT_LINK`, `mention.mentionsOf`).
787
+ export interface MentionFormatSpec { open?: string; close?: string; write?: (item: { id: string; name: string }) => string; pattern?: RegExp }
788
+ export interface MentionItem { id: string; name: string; [key: string]: unknown }
789
+ export interface MentionSegment { type: 'text' | 'mention'; text?: string; id?: string; name?: string }
790
+ export const mention: {
791
+ CURLY: MentionFormatSpec;
792
+ AT: MentionFormatSpec;
793
+ CHAT_LINK: MentionFormatSpec;
794
+ makeResolver(items: MentionItem[]): { get(name: string): MentionItem | undefined; byId(id: string): MentionItem | undefined; names(): string[] };
795
+ parseValue(value: string, format: MentionFormatSpec, resolver: ReturnType<typeof mention.makeResolver>): MentionSegment[];
796
+ serializeSegments(segments: MentionSegment[], format: MentionFormatSpec): string;
797
+ mentionsOf(segments: MentionSegment[]): MentionItem[];
798
+ scoreItem(item: MentionItem, query: string): number;
799
+ searchItems(items: MentionItem[], query: string): MentionItem[];
800
+ groupItems(items: MentionItem[], query: string): Array<{ section: string; items: MentionItem[] }>;
801
+ activeTrigger(textBeforeCaret: string, trigger?: string, maxLen?: number): { query: string; start: number } | null;
802
+ };
package/dist/index.js CHANGED
@@ -9,9 +9,10 @@ import {
9
9
  MentionText,
10
10
  Popover,
11
11
  SheetGrid,
12
+ mentionModel_exports,
12
13
  sheetToAoA,
13
14
  sheetToDelimited
14
- } from "./chunk-EL2DHWOH.js";
15
+ } from "./chunk-G34T6ZLN.js";
15
16
  import {
16
17
  Chevron,
17
18
  CodeBlock,
@@ -1610,14 +1611,35 @@ function CreateBody({ spec, onClose, t, titleId }) {
1610
1611
  const [kind, setKind] = useState6(spec.defaultKind || types[0]?.kind || "");
1611
1612
  const [value, setValue] = useState6(spec.defaultValue ?? "");
1612
1613
  const [err, setErr] = useState6(null);
1614
+ const [lists, setLists] = useState6({});
1613
1615
  const inputId = useId();
1614
1616
  const sel = types.find((x) => x.kind === kind) || types[0] || {};
1617
+ useEffect5(() => {
1618
+ const ch = sel.choices;
1619
+ if (!ch || lists[kind]) return void 0;
1620
+ let dead = false;
1621
+ setLists((m) => ({ ...m, [kind]: { status: "loading", items: [], chosen: ch.defaultId ?? null } }));
1622
+ Promise.resolve().then(() => ch.load()).then((items) => {
1623
+ if (dead) return;
1624
+ const arr = Array.isArray(items) ? items : [];
1625
+ const chosen = arr.some((it) => it.id === ch.defaultId) ? ch.defaultId : arr[0]?.id ?? ch.defaultId ?? null;
1626
+ setLists((m) => ({ ...m, [kind]: { status: "ready", items: arr, chosen } }));
1627
+ }).catch(() => {
1628
+ if (dead) return;
1629
+ setLists((m) => ({ ...m, [kind]: { status: "failed", items: [], chosen: ch.defaultId ?? null } }));
1630
+ });
1631
+ return () => {
1632
+ dead = true;
1633
+ };
1634
+ }, [kind]);
1635
+ const pick = (id) => setLists((m) => ({ ...m, [kind]: { ...m[kind], chosen: id } }));
1615
1636
  const submit = () => {
1616
1637
  if (spec.required !== false && !String(value).trim()) {
1617
1638
  setErr(t.required);
1618
1639
  return;
1619
1640
  }
1620
- onClose({ kind, name: String(value).trim() });
1641
+ const entry = sel.choices ? lists[kind] : null;
1642
+ onClose({ kind, name: String(value).trim(), ...entry ? { choice: entry.chosen } : {} });
1621
1643
  };
1622
1644
  return /* @__PURE__ */ jsxs7(Fragment5, { children: [
1623
1645
  /* @__PURE__ */ jsx8(Header, { title: spec.title, titleId }),
@@ -1657,7 +1679,8 @@ function CreateBody({ spec, onClose, t, titleId }) {
1657
1679
  spellCheck: "false"
1658
1680
  }
1659
1681
  ),
1660
- err ? /* @__PURE__ */ jsx8("div", { className: "rui-dlg-err", children: err }) : null
1682
+ err ? /* @__PURE__ */ jsx8("div", { className: "rui-dlg-err", children: err }) : null,
1683
+ sel.choices ? /* @__PURE__ */ jsx8(ChoiceList, { label: sel.choices.label, entry: lists[kind], onPick: pick }) : null
1661
1684
  ] }),
1662
1685
  /* @__PURE__ */ jsxs7(Footer, { children: [
1663
1686
  /* @__PURE__ */ jsx8("button", { type: "button", className: "rui-dlg-btn rui-dlg-secondary", onClick: () => onClose(null), children: spec.cancelLabel || t.cancel }),
@@ -1665,6 +1688,36 @@ function CreateBody({ spec, onClose, t, titleId }) {
1665
1688
  ] })
1666
1689
  ] });
1667
1690
  }
1691
+ function ChoiceList({ label, entry, onPick }) {
1692
+ const labelId = useId();
1693
+ const status = entry?.status || "loading";
1694
+ return /* @__PURE__ */ jsxs7("div", { className: "rui-dlg-choices", role: "radiogroup", "aria-labelledby": labelId, children: [
1695
+ /* @__PURE__ */ jsx8("div", { className: "rui-dlg-label", id: labelId, children: label }),
1696
+ status === "loading" ? /* @__PURE__ */ jsx8("div", { className: "rui-dlg-help", children: "Loading" }) : null,
1697
+ status === "failed" ? /* @__PURE__ */ jsx8("div", { className: "rui-dlg-help", children: "The list could not be loaded. The default will be used." }) : null,
1698
+ status === "ready" && entry.items.length > 0 ? /* @__PURE__ */ jsx8("div", { className: "rui-dlg-choice-list", children: entry.items.map((it) => {
1699
+ const on = it.id === entry.chosen;
1700
+ return /* @__PURE__ */ jsxs7(
1701
+ "button",
1702
+ {
1703
+ type: "button",
1704
+ role: "radio",
1705
+ "aria-checked": on,
1706
+ className: `rui-dlg-choice${on ? " is-on" : ""}`,
1707
+ onClick: () => onPick(it.id),
1708
+ children: [
1709
+ /* @__PURE__ */ jsx8("span", { className: "rui-dlg-choice-dot", "aria-hidden": "true" }),
1710
+ /* @__PURE__ */ jsxs7("span", { className: "rui-dlg-choice-text", children: [
1711
+ /* @__PURE__ */ jsx8("span", { className: "rui-dlg-choice-name", children: it.name }),
1712
+ it.description ? /* @__PURE__ */ jsx8("span", { className: "rui-dlg-choice-desc", children: it.description }) : null
1713
+ ] })
1714
+ ]
1715
+ },
1716
+ it.id
1717
+ );
1718
+ }) }) : null
1719
+ ] });
1720
+ }
1668
1721
 
1669
1722
  // src/auth/client.js
1670
1723
  var _cfg = {
@@ -3831,6 +3884,7 @@ export {
3831
3884
  login,
3832
3885
  logout,
3833
3886
  majorTickStep,
3887
+ mentionModel_exports as mention,
3834
3888
  packLayout,
3835
3889
  parseArgs,
3836
3890
  prettyJson,