Files
klz-cables.com/.pnpm-store/v10/files/99/b9439214d289abc93defc7897b35067429f4ca56d32961766159d99357bef84954df7de9f8059e5d9d0f8f618d92f650f97f5c7c6234cd25bbb09a57fcb8fb
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

133 lines
4.2 KiB
Plaintext

'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { CodeEditor } from '../../elements/CodeEditor/index.js';
import { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js';
import { FieldDescription } from '../../fields/FieldDescription/index.js';
import { FieldError } from '../../fields/FieldError/index.js';
import { FieldLabel } from '../../fields/FieldLabel/index.js';
import { useField } from '../../forms/useField/index.js';
import { withCondition } from '../../forms/withCondition/index.js';
import { mergeFieldStyles } from '../mergeFieldStyles.js';
import { fieldBaseClass } from '../shared/index.js';
import './index.scss';
const prismToMonacoLanguageMap = {
js: 'javascript',
ts: 'typescript',
tsx: 'typescript'
};
const baseClass = 'code-field';
const CodeFieldComponent = props => {
const {
field,
field: {
admin: {
className,
description,
editorOptions,
editorProps,
language = 'javascript'
} = {},
label,
localized,
required
},
onMount,
path: pathFromProps,
readOnly,
validate
} = props;
const inputChangeFromRef = React.useRef('formState');
const [recalculatedHeightAt, setRecalculatedHeightAt] = useState(Date.now());
const memoizedValidate = useCallback((value, options) => {
if (typeof validate === 'function') {
return validate(value, {
...options,
required
});
}
}, [validate, required]);
const {
customComponents: {
AfterInput,
BeforeInput,
Description,
Error,
Label
} = {},
disabled,
initialValue,
path,
setValue,
showError,
value: value_0
} = useField({
potentiallyStalePath: pathFromProps,
validate: memoizedValidate
});
const stringValueRef = React.useRef((value_0 || initialValue) !== undefined ? value_0 ?? initialValue : undefined);
const handleChange = useCallback(val => {
if (readOnly || disabled) {
return;
}
inputChangeFromRef.current = 'internalEditor';
try {
setValue(val ? val : null);
stringValueRef.current = val;
} catch (e) {
setValue(val ? val : null);
stringValueRef.current = val;
}
}, [readOnly, disabled, setValue]);
useEffect(() => {
if (inputChangeFromRef.current === 'formState') {
stringValueRef.current = (value_0 || initialValue) !== undefined ? value_0 ?? initialValue : undefined;
setRecalculatedHeightAt(Date.now());
}
inputChangeFromRef.current = 'formState';
}, [initialValue, path, value_0]);
const styles = useMemo(() => mergeFieldStyles(field), [field]);
return /*#__PURE__*/_jsxs("div", {
className: [fieldBaseClass, baseClass, className, showError && 'error', (readOnly || disabled) && 'read-only'].filter(Boolean).join(' '),
style: styles,
children: [/*#__PURE__*/_jsx(RenderCustomComponent, {
CustomComponent: Label,
Fallback: /*#__PURE__*/_jsx(FieldLabel, {
label: label,
localized: localized,
path: path,
required: required
})
}), /*#__PURE__*/_jsxs("div", {
className: `${fieldBaseClass}__wrap`,
children: [/*#__PURE__*/_jsx(RenderCustomComponent, {
CustomComponent: Error,
Fallback: /*#__PURE__*/_jsx(FieldError, {
path: path,
showError: showError
})
}), BeforeInput, /*#__PURE__*/_jsx(CodeEditor, {
defaultLanguage: prismToMonacoLanguageMap[language] || language,
onChange: handleChange,
onMount: onMount,
options: editorOptions,
readOnly: readOnly || disabled,
recalculatedHeightAt: recalculatedHeightAt,
value: stringValueRef.current,
wrapperProps: {
id: `field-${path?.replace(/\./g, '__')}`
},
...(editorProps || {})
}), AfterInput]
}), /*#__PURE__*/_jsx(RenderCustomComponent, {
CustomComponent: Description,
Fallback: /*#__PURE__*/_jsx(FieldDescription, {
description: description,
path: path
})
})]
});
};
export const CodeField = withCondition(CodeFieldComponent);
//# sourceMappingURL=index.js.map