reifyui 0.13.1 → 0.13.3

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.cjs CHANGED
@@ -114,6 +114,7 @@ __export(src_exports, {
114
114
  login: () => login,
115
115
  logout: () => logout,
116
116
  majorTickStep: () => majorTickStep,
117
+ mention: () => mentionModel_exports,
117
118
  packLayout: () => packLayout,
118
119
  parseArgs: () => parseArgs,
119
120
  prettyJson: () => prettyJson,
@@ -2052,14 +2053,35 @@ function CreateBody({ spec, onClose, t, titleId }) {
2052
2053
  const [kind, setKind] = (0, import_react12.useState)(spec.defaultKind || types[0]?.kind || "");
2053
2054
  const [value, setValue] = (0, import_react12.useState)(spec.defaultValue ?? "");
2054
2055
  const [err, setErr] = (0, import_react12.useState)(null);
2056
+ const [lists, setLists] = (0, import_react12.useState)({});
2055
2057
  const inputId = (0, import_react12.useId)();
2056
2058
  const sel = types.find((x) => x.kind === kind) || types[0] || {};
2059
+ (0, import_react12.useEffect)(() => {
2060
+ const ch = sel.choices;
2061
+ if (!ch || lists[kind]) return void 0;
2062
+ let dead = false;
2063
+ setLists((m) => ({ ...m, [kind]: { status: "loading", items: [], chosen: ch.defaultId ?? null } }));
2064
+ Promise.resolve().then(() => ch.load()).then((items) => {
2065
+ if (dead) return;
2066
+ const arr = Array.isArray(items) ? items : [];
2067
+ const chosen = arr.some((it) => it.id === ch.defaultId) ? ch.defaultId : arr[0]?.id ?? ch.defaultId ?? null;
2068
+ setLists((m) => ({ ...m, [kind]: { status: "ready", items: arr, chosen } }));
2069
+ }).catch(() => {
2070
+ if (dead) return;
2071
+ setLists((m) => ({ ...m, [kind]: { status: "failed", items: [], chosen: ch.defaultId ?? null } }));
2072
+ });
2073
+ return () => {
2074
+ dead = true;
2075
+ };
2076
+ }, [kind]);
2077
+ const pick = (id) => setLists((m) => ({ ...m, [kind]: { ...m[kind], chosen: id } }));
2057
2078
  const submit = () => {
2058
2079
  if (spec.required !== false && !String(value).trim()) {
2059
2080
  setErr(t.required);
2060
2081
  return;
2061
2082
  }
2062
- onClose({ kind, name: String(value).trim() });
2083
+ const entry = sel.choices ? lists[kind] : null;
2084
+ onClose({ kind, name: String(value).trim(), ...entry ? { choice: entry.chosen } : {} });
2063
2085
  };
2064
2086
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
2065
2087
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Header, { title: spec.title, titleId }),
@@ -2099,7 +2121,8 @@ function CreateBody({ spec, onClose, t, titleId }) {
2099
2121
  spellCheck: "false"
2100
2122
  }
2101
2123
  ),
2102
- err ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "rui-dlg-err", children: err }) : null
2124
+ err ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "rui-dlg-err", children: err }) : null,
2125
+ sel.choices ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ChoiceList, { label: sel.choices.label, entry: lists[kind], onPick: pick }) : null
2103
2126
  ] }),
2104
2127
  /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Footer, { children: [
2105
2128
  /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", className: "rui-dlg-btn rui-dlg-secondary", onClick: () => onClose(null), children: spec.cancelLabel || t.cancel }),
@@ -2107,6 +2130,36 @@ function CreateBody({ spec, onClose, t, titleId }) {
2107
2130
  ] })
2108
2131
  ] });
2109
2132
  }
2133
+ function ChoiceList({ label, entry, onPick }) {
2134
+ const labelId = (0, import_react12.useId)();
2135
+ const status = entry?.status || "loading";
2136
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "rui-dlg-choices", role: "radiogroup", "aria-labelledby": labelId, children: [
2137
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "rui-dlg-label", id: labelId, children: label }),
2138
+ status === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "rui-dlg-help", children: "Loading" }) : null,
2139
+ status === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "rui-dlg-help", children: "The list could not be loaded. The default will be used." }) : null,
2140
+ status === "ready" && entry.items.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "rui-dlg-choice-list", children: entry.items.map((it) => {
2141
+ const on = it.id === entry.chosen;
2142
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
2143
+ "button",
2144
+ {
2145
+ type: "button",
2146
+ role: "radio",
2147
+ "aria-checked": on,
2148
+ className: `rui-dlg-choice${on ? " is-on" : ""}`,
2149
+ onClick: () => onPick(it.id),
2150
+ children: [
2151
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "rui-dlg-choice-dot", "aria-hidden": "true" }),
2152
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "rui-dlg-choice-text", children: [
2153
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "rui-dlg-choice-name", children: it.name }),
2154
+ it.description ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "rui-dlg-choice-desc", children: it.description }) : null
2155
+ ] })
2156
+ ]
2157
+ },
2158
+ it.id
2159
+ );
2160
+ }) }) : null
2161
+ ] });
2162
+ }
2110
2163
 
2111
2164
  // src/auth/client.js
2112
2165
  var _cfg = {
@@ -2566,6 +2619,20 @@ function Popover(props) {
2566
2619
  }
2567
2620
 
2568
2621
  // src/mention/mentionModel.js
2622
+ var mentionModel_exports = {};
2623
+ __export(mentionModel_exports, {
2624
+ AT: () => AT,
2625
+ CHAT_LINK: () => CHAT_LINK,
2626
+ CURLY: () => CURLY,
2627
+ activeTrigger: () => activeTrigger,
2628
+ groupItems: () => groupItems,
2629
+ makeResolver: () => makeResolver,
2630
+ mentionsOf: () => mentionsOf,
2631
+ parseValue: () => parseValue,
2632
+ scoreItem: () => scoreItem,
2633
+ searchItems: () => searchItems,
2634
+ serializeSegments: () => serializeSegments
2635
+ });
2569
2636
  var CURLY = Object.freeze({ open: "{{", close: "}}" });
2570
2637
  var AT = Object.freeze({ open: "@", close: "" });
2571
2638
  var CHAT_LINK = Object.freeze({