@sustaina/shared-ui 1.25.0 → 1.26.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.
package/dist/index.d.mts CHANGED
@@ -568,6 +568,7 @@ type FormulaEditorProps = {
568
568
  onSelectSuggestion?: (token: FormulaTokenAttributes, config: FormulaTokenConfig) => void;
569
569
  field?: ControllerRenderProps<any, any>;
570
570
  fieldState?: ControllerFieldState;
571
+ mode?: "edit" | "display";
571
572
  };
572
573
 
573
574
  declare const FormulaEditor: React__default.FC<FormulaEditorProps>;
package/dist/index.d.ts CHANGED
@@ -568,6 +568,7 @@ type FormulaEditorProps = {
568
568
  onSelectSuggestion?: (token: FormulaTokenAttributes, config: FormulaTokenConfig) => void;
569
569
  field?: ControllerRenderProps<any, any>;
570
570
  fieldState?: ControllerFieldState;
571
+ mode?: "edit" | "display";
571
572
  };
572
573
 
573
574
  declare const FormulaEditor: React__default.FC<FormulaEditorProps>;
package/dist/index.js CHANGED
@@ -6305,7 +6305,8 @@ var FormulaEditor = ({
6305
6305
  onChange,
6306
6306
  onSelectSuggestion,
6307
6307
  field,
6308
- fieldState
6308
+ fieldState,
6309
+ mode = "edit"
6309
6310
  }) => {
6310
6311
  const [isExpanded, setIsExpanded] = React4.useState(false);
6311
6312
  const lastEmittedValueRef = React4.useRef(null);
@@ -6322,27 +6323,22 @@ var FormulaEditor = ({
6322
6323
  const prefixMap = React4.useMemo(() => buildPrefixMap(normalizedConfigs), [normalizedConfigs]);
6323
6324
  const configLookup = React4.useMemo(() => {
6324
6325
  const lookup = /* @__PURE__ */ new Map();
6325
- normalizedConfigs.forEach((config) => {
6326
- lookup.set(config.prefix, config);
6327
- });
6326
+ normalizedConfigs.forEach((config) => lookup.set(config.prefix, config));
6328
6327
  return lookup;
6329
6328
  }, [normalizedConfigs]);
6330
6329
  const allowedOperators = React4.useMemo(() => operators.map((operator) => operator.value), [operators]);
6331
6330
  const displayError = errorMessage ?? fieldState?.error?.message;
6332
6331
  const hasError = Boolean(displayError);
6333
- const isInteractionDisabled = Boolean(disabled || loading);
6332
+ const isEditorReadOnly = mode === "display";
6333
+ const isEditorDisabled = disabled || loading || isEditorReadOnly;
6334
6334
  const convertValueToContent = React4.useCallback(
6335
6335
  (input) => {
6336
6336
  if (!input) return "";
6337
6337
  const trimmed = input.trim();
6338
6338
  if (!trimmed) return "";
6339
6339
  const parsedJSON = tryParseJSON(trimmed);
6340
- if (parsedJSON && parsedJSON.type === "doc") {
6341
- return parsedJSON;
6342
- }
6343
- if (looksLikeHTML(trimmed)) {
6344
- return input;
6345
- }
6340
+ if (parsedJSON && parsedJSON.type === "doc") return parsedJSON;
6341
+ if (looksLikeHTML(trimmed)) return input;
6346
6342
  return buildDocFromRaw(input, prefixMap, configLookup);
6347
6343
  },
6348
6344
  [configLookup, prefixMap]
@@ -6373,7 +6369,7 @@ var FormulaEditor = ({
6373
6369
  hasError ? "border border-destructive" : "border focus-visible:border-ring",
6374
6370
  "w-full rounded-lg bg-white px-4 py-3",
6375
6371
  "overflow-y-auto whitespace-pre-wrap wrap-break-word focus:outline-none",
6376
- isInteractionDisabled && "pointer-events-none opacity-60",
6372
+ isEditorDisabled && "pointer-events-none",
6377
6373
  editorClassName
6378
6374
  ),
6379
6375
  ...loading ? { "aria-busy": "true" } : {}
@@ -6382,8 +6378,8 @@ var FormulaEditor = ({
6382
6378
  });
6383
6379
  React4.useEffect(() => {
6384
6380
  if (!editor) return;
6385
- editor.setEditable(!isInteractionDisabled);
6386
- }, [editor, isInteractionDisabled]);
6381
+ editor.setEditable(!isEditorDisabled);
6382
+ }, [editor, isEditorDisabled]);
6387
6383
  React4.useEffect(() => {
6388
6384
  if (!editor || resolvedContent === void 0) return;
6389
6385
  if (ignorePropValueRef.current && typeof value === "string" && value === lastEmittedValueRef.current) {
@@ -6417,9 +6413,7 @@ var FormulaEditor = ({
6417
6413
  className: "relative",
6418
6414
  "aria-busy": loading,
6419
6415
  onFocus: () => {
6420
- if (editor && !editor.isFocused) {
6421
- editor.chain().focus().run();
6422
- }
6416
+ if (editor && !editor.isFocused) editor.chain().focus().run();
6423
6417
  },
6424
6418
  children: [
6425
6419
  /* @__PURE__ */ jsxRuntime.jsx(react.EditorContent, { editor }),
@@ -6431,14 +6425,14 @@ var FormulaEditor = ({
6431
6425
  spinnerClassName: "size-6 text-sus-blue-3"
6432
6426
  }
6433
6427
  ),
6434
- /* @__PURE__ */ jsxRuntime.jsx(
6428
+ !isEditorReadOnly && /* @__PURE__ */ jsxRuntime.jsx(
6435
6429
  Button,
6436
6430
  {
6437
6431
  type: "button",
6438
6432
  variant: "ghost",
6439
6433
  size: "icon",
6440
6434
  className: "absolute bottom-2 right-4 h-6 w-6 rounded-full bg-white shadow",
6441
- disabled: isInteractionDisabled,
6435
+ disabled: isEditorDisabled,
6442
6436
  onClick: () => setIsExpanded((prev) => !prev),
6443
6437
  children: isExpanded ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Minimize2, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize2, { className: "h-4 w-4" })
6444
6438
  }
@@ -6447,13 +6441,13 @@ var FormulaEditor = ({
6447
6441
  }
6448
6442
  ),
6449
6443
  hasError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-destructive", role: "alert", children: displayError }),
6450
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap justify-end gap-2 py-2", children: operators.map((operator) => /* @__PURE__ */ jsxRuntime.jsx(
6444
+ mode === "edit" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap justify-end gap-2 py-2", children: operators.map((operator) => /* @__PURE__ */ jsxRuntime.jsx(
6451
6445
  Button,
6452
6446
  {
6453
6447
  type: "button",
6454
6448
  onClick: () => insertOperator(operator.value),
6455
6449
  className: "min-w-10 rounded-sm px-3 bg-sus-blue-3",
6456
- disabled: isInteractionDisabled,
6450
+ disabled: isEditorDisabled,
6457
6451
  children: operator.label
6458
6452
  },
6459
6453
  operator.value