@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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6265,7 +6265,8 @@ var FormulaEditor = ({
|
|
|
6265
6265
|
onChange,
|
|
6266
6266
|
onSelectSuggestion,
|
|
6267
6267
|
field,
|
|
6268
|
-
fieldState
|
|
6268
|
+
fieldState,
|
|
6269
|
+
mode = "edit"
|
|
6269
6270
|
}) => {
|
|
6270
6271
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
6271
6272
|
const lastEmittedValueRef = useRef(null);
|
|
@@ -6282,27 +6283,22 @@ var FormulaEditor = ({
|
|
|
6282
6283
|
const prefixMap = useMemo(() => buildPrefixMap(normalizedConfigs), [normalizedConfigs]);
|
|
6283
6284
|
const configLookup = useMemo(() => {
|
|
6284
6285
|
const lookup = /* @__PURE__ */ new Map();
|
|
6285
|
-
normalizedConfigs.forEach((config) =>
|
|
6286
|
-
lookup.set(config.prefix, config);
|
|
6287
|
-
});
|
|
6286
|
+
normalizedConfigs.forEach((config) => lookup.set(config.prefix, config));
|
|
6288
6287
|
return lookup;
|
|
6289
6288
|
}, [normalizedConfigs]);
|
|
6290
6289
|
const allowedOperators = useMemo(() => operators.map((operator) => operator.value), [operators]);
|
|
6291
6290
|
const displayError = errorMessage ?? fieldState?.error?.message;
|
|
6292
6291
|
const hasError = Boolean(displayError);
|
|
6293
|
-
const
|
|
6292
|
+
const isEditorReadOnly = mode === "display";
|
|
6293
|
+
const isEditorDisabled = disabled || loading || isEditorReadOnly;
|
|
6294
6294
|
const convertValueToContent = useCallback(
|
|
6295
6295
|
(input) => {
|
|
6296
6296
|
if (!input) return "";
|
|
6297
6297
|
const trimmed = input.trim();
|
|
6298
6298
|
if (!trimmed) return "";
|
|
6299
6299
|
const parsedJSON = tryParseJSON(trimmed);
|
|
6300
|
-
if (parsedJSON && parsedJSON.type === "doc")
|
|
6301
|
-
|
|
6302
|
-
}
|
|
6303
|
-
if (looksLikeHTML(trimmed)) {
|
|
6304
|
-
return input;
|
|
6305
|
-
}
|
|
6300
|
+
if (parsedJSON && parsedJSON.type === "doc") return parsedJSON;
|
|
6301
|
+
if (looksLikeHTML(trimmed)) return input;
|
|
6306
6302
|
return buildDocFromRaw(input, prefixMap, configLookup);
|
|
6307
6303
|
},
|
|
6308
6304
|
[configLookup, prefixMap]
|
|
@@ -6333,7 +6329,7 @@ var FormulaEditor = ({
|
|
|
6333
6329
|
hasError ? "border border-destructive" : "border focus-visible:border-ring",
|
|
6334
6330
|
"w-full rounded-lg bg-white px-4 py-3",
|
|
6335
6331
|
"overflow-y-auto whitespace-pre-wrap wrap-break-word focus:outline-none",
|
|
6336
|
-
|
|
6332
|
+
isEditorDisabled && "pointer-events-none",
|
|
6337
6333
|
editorClassName
|
|
6338
6334
|
),
|
|
6339
6335
|
...loading ? { "aria-busy": "true" } : {}
|
|
@@ -6342,8 +6338,8 @@ var FormulaEditor = ({
|
|
|
6342
6338
|
});
|
|
6343
6339
|
useEffect(() => {
|
|
6344
6340
|
if (!editor) return;
|
|
6345
|
-
editor.setEditable(!
|
|
6346
|
-
}, [editor,
|
|
6341
|
+
editor.setEditable(!isEditorDisabled);
|
|
6342
|
+
}, [editor, isEditorDisabled]);
|
|
6347
6343
|
useEffect(() => {
|
|
6348
6344
|
if (!editor || resolvedContent === void 0) return;
|
|
6349
6345
|
if (ignorePropValueRef.current && typeof value === "string" && value === lastEmittedValueRef.current) {
|
|
@@ -6377,9 +6373,7 @@ var FormulaEditor = ({
|
|
|
6377
6373
|
className: "relative",
|
|
6378
6374
|
"aria-busy": loading,
|
|
6379
6375
|
onFocus: () => {
|
|
6380
|
-
if (editor && !editor.isFocused)
|
|
6381
|
-
editor.chain().focus().run();
|
|
6382
|
-
}
|
|
6376
|
+
if (editor && !editor.isFocused) editor.chain().focus().run();
|
|
6383
6377
|
},
|
|
6384
6378
|
children: [
|
|
6385
6379
|
/* @__PURE__ */ jsx(EditorContent, { editor }),
|
|
@@ -6391,14 +6385,14 @@ var FormulaEditor = ({
|
|
|
6391
6385
|
spinnerClassName: "size-6 text-sus-blue-3"
|
|
6392
6386
|
}
|
|
6393
6387
|
),
|
|
6394
|
-
/* @__PURE__ */ jsx(
|
|
6388
|
+
!isEditorReadOnly && /* @__PURE__ */ jsx(
|
|
6395
6389
|
Button,
|
|
6396
6390
|
{
|
|
6397
6391
|
type: "button",
|
|
6398
6392
|
variant: "ghost",
|
|
6399
6393
|
size: "icon",
|
|
6400
6394
|
className: "absolute bottom-2 right-4 h-6 w-6 rounded-full bg-white shadow",
|
|
6401
|
-
disabled:
|
|
6395
|
+
disabled: isEditorDisabled,
|
|
6402
6396
|
onClick: () => setIsExpanded((prev) => !prev),
|
|
6403
6397
|
children: isExpanded ? /* @__PURE__ */ jsx(Minimize2, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Maximize2, { className: "h-4 w-4" })
|
|
6404
6398
|
}
|
|
@@ -6407,13 +6401,13 @@ var FormulaEditor = ({
|
|
|
6407
6401
|
}
|
|
6408
6402
|
),
|
|
6409
6403
|
hasError && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", role: "alert", children: displayError }),
|
|
6410
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap justify-end gap-2 py-2", children: operators.map((operator) => /* @__PURE__ */ jsx(
|
|
6404
|
+
mode === "edit" && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap justify-end gap-2 py-2", children: operators.map((operator) => /* @__PURE__ */ jsx(
|
|
6411
6405
|
Button,
|
|
6412
6406
|
{
|
|
6413
6407
|
type: "button",
|
|
6414
6408
|
onClick: () => insertOperator(operator.value),
|
|
6415
6409
|
className: "min-w-10 rounded-sm px-3 bg-sus-blue-3",
|
|
6416
|
-
disabled:
|
|
6410
|
+
disabled: isEditorDisabled,
|
|
6417
6411
|
children: operator.label
|
|
6418
6412
|
},
|
|
6419
6413
|
operator.value
|