@remotion/studio 4.0.438 → 4.0.440
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/Studio.js +2 -2
- package/dist/api/helpers/calc-new-props.js +5 -8
- package/dist/api/update-default-props.d.ts +7 -3
- package/dist/api/update-default-props.js +7 -21
- package/dist/api/visual-control.js +6 -0
- package/dist/components/DefaultPropsEditor.d.ts +8 -0
- package/dist/components/DefaultPropsEditor.js +15 -0
- package/dist/components/Editor.js +0 -14
- package/dist/components/EditorContexts.js +6 -3
- package/dist/components/KeyboardShortcutsExplainer.js +6 -2
- package/dist/components/MenuBuildIndicator.js +1 -0
- package/dist/components/MenuToolbar.js +3 -1
- package/dist/components/NewComposition/InputDragger.js +2 -2
- package/dist/components/NewComposition/RemTextarea.js +4 -0
- package/dist/components/ObserveDefaultPropsContext.d.ts +11 -0
- package/dist/components/ObserveDefaultPropsContext.js +120 -0
- package/dist/components/OptionsPanel.js +90 -28
- package/dist/components/RenderModal/CrfSetting.d.ts +1 -1
- package/dist/components/RenderModal/DataEditor.d.ts +4 -5
- package/dist/components/RenderModal/DataEditor.js +9 -111
- package/dist/components/RenderModal/RenderModalJSONPropsEditor.d.ts +1 -1
- package/dist/components/RenderModal/RenderModalJSONPropsEditor.js +52 -48
- package/dist/components/RenderModal/SchemaEditor/Fieldset.d.ts +0 -1
- package/dist/components/RenderModal/SchemaEditor/SchemaEditor.d.ts +4 -9
- package/dist/components/RenderModal/SchemaEditor/SchemaEditor.js +2 -61
- package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.d.ts +0 -1
- package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.js +2 -3
- package/dist/components/RenderModal/SchemaEditor/SchemaLabel.d.ts +0 -6
- package/dist/components/RenderModal/SchemaEditor/SchemaLabel.js +2 -5
- package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.d.ts +3 -1
- package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.js +1 -1
- package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.js +15 -26
- package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.js +7 -12
- package/dist/components/RenderModal/SchemaEditor/ZodBooleanEditor.d.ts +0 -7
- package/dist/components/RenderModal/SchemaEditor/ZodBooleanEditor.js +5 -15
- package/dist/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodColorEditor.js +30 -28
- package/dist/components/RenderModal/SchemaEditor/ZodDateEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodDateEditor.js +13 -17
- package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.js +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.js +13 -28
- package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.d.ts +1 -5
- package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.js +11 -12
- package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.d.ts +1 -5
- package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.js +12 -16
- package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.d.ts +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.js +1 -2
- package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.js +20 -30
- package/dist/components/RenderModal/SchemaEditor/ZodNonEditableValue.d.ts +0 -2
- package/dist/components/RenderModal/SchemaEditor/ZodNonEditableValue.js +3 -6
- package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.js +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.js +16 -21
- package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.d.ts +2 -7
- package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.js +27 -49
- package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.js +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodOrNullishEditor.js +8 -15
- package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.js +10 -15
- package/dist/components/RenderModal/SchemaEditor/ZodStringEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodStringEditor.js +13 -17
- package/dist/components/RenderModal/SchemaEditor/ZodSwitch.d.ts +3 -6
- package/dist/components/RenderModal/SchemaEditor/ZodSwitch.js +27 -27
- package/dist/components/RenderModal/SchemaEditor/ZodTextareaEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodTextareaEditor.js +45 -17
- package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.js +15 -26
- package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.js +4 -11
- package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.js +6 -6
- package/dist/components/RenderModal/ServerRenderModal.js +9 -3
- package/dist/components/RenderModal/WebRenderModal.js +9 -3
- package/dist/components/RenderModal/get-default-codecs.d.ts +5 -5
- package/dist/components/RenderModal/get-render-modal-warnings.d.ts +1 -2
- package/dist/components/RenderModal/get-render-modal-warnings.js +4 -6
- package/dist/components/RenderModal/human-readable-codec.d.ts +1 -1
- package/dist/components/RenderModal/human-readable-codec.js +3 -0
- package/dist/components/RenderModal/out-name-checker.d.ts +1 -1
- package/dist/components/RenderQueue/actions.d.ts +2 -3
- package/dist/components/RenderQueue/actions.js +1 -13
- package/dist/components/Timeline/Timeline.js +1 -1
- package/dist/components/Timeline/TimelineExpandedSection.js +7 -1
- package/dist/components/Timeline/TimelineFieldRow.d.ts +1 -0
- package/dist/components/Timeline/TimelineFieldRow.js +25 -3
- package/dist/components/Timeline/TimelineImageInfo.d.ts +5 -0
- package/dist/components/Timeline/TimelineImageInfo.js +61 -0
- package/dist/components/Timeline/TimelineListItem.js +1 -2
- package/dist/components/Timeline/TimelineNumberField.js +4 -6
- package/dist/components/Timeline/TimelineRotationField.js +4 -6
- package/dist/components/Timeline/TimelineSequence.js +9 -4
- package/dist/components/Timeline/TimelineStack/index.js +3 -1
- package/dist/components/Timeline/TimelineTracks.js +1 -1
- package/dist/components/Timeline/TimelineTranslateField.js +28 -13
- package/dist/components/TopPanel.js +10 -5
- package/dist/components/UndoRedoButtons.d.ts +2 -0
- package/dist/components/UndoRedoButtons.js +116 -0
- package/dist/components/VisualControls/VisualControlHandle.js +18 -18
- package/dist/components/VisualControls/VisualControlsUndoSync.d.ts +2 -0
- package/dist/components/VisualControls/VisualControlsUndoSync.js +23 -0
- package/dist/error-overlay/react-overlay/listen-to-runtime-errors.js +0 -1
- package/dist/esm/{chunk-ba0scebn.js → chunk-1x2ychmc.js} +4466 -5252
- package/dist/esm/index.mjs +25 -28
- package/dist/esm/internals.mjs +4466 -5252
- package/dist/esm/previewEntry.mjs +4652 -5497
- package/dist/esm/renderEntry.mjs +6 -6
- package/dist/helpers/client-id.js +13 -1
- package/dist/helpers/document-title.d.ts +0 -1
- package/dist/helpers/document-title.js +1 -17
- package/dist/helpers/render-modal-sections.d.ts +1 -1
- package/dist/helpers/timeline-layout.d.ts +1 -1
- package/dist/helpers/timeline-layout.js +1 -1
- package/dist/hot-middleware-client/client.d.ts +1 -6
- package/dist/hot-middleware-client/client.js +22 -73
- package/dist/hot-middleware-client/process-update.d.ts +0 -2
- package/dist/hot-middleware-client/process-update.js +6 -14
- package/dist/icons/redo.d.ts +3 -0
- package/dist/icons/redo.js +8 -0
- package/dist/icons/undo.d.ts +3 -0
- package/dist/icons/undo.js +8 -0
- package/dist/renderEntry.js +7 -6
- package/dist/visual-controls/VisualControls.js +9 -5
- package/dist/visual-controls/get-current-edited-value.js +5 -4
- package/dist/visual-controls/visual-control-store.d.ts +7 -0
- package/dist/visual-controls/visual-control-store.js +22 -0
- package/package.json +9 -9
- package/dist/components/GlobalPropsEditorUpdateButton.d.ts +0 -5
- package/dist/components/GlobalPropsEditorUpdateButton.js +0 -78
- package/dist/components/RenderModal/SchemaEditor/SchemaSaveButton.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/SchemaSaveButton.js +0 -18
- package/dist/components/RenderModal/SchemaEditor/local-state.d.ts +0 -25
- package/dist/components/RenderModal/SchemaEditor/local-state.js +0 -107
|
@@ -36,15 +36,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.ZodMatrixEditor = void 0;
|
|
37
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
|
+
const react_2 = require("react");
|
|
39
40
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
40
|
-
const create_zod_values_1 = require("./create-zod-values");
|
|
41
|
-
const deep_equal_1 = require("./deep-equal");
|
|
42
41
|
const Fieldset_1 = require("./Fieldset");
|
|
43
|
-
const local_state_1 = require("./local-state");
|
|
44
42
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
45
43
|
const SchemaSeparationLine_1 = require("./SchemaSeparationLine");
|
|
46
44
|
const SchemaVerticalGuide_1 = require("./SchemaVerticalGuide");
|
|
47
45
|
const zod_schema_type_1 = require("./zod-schema-type");
|
|
46
|
+
const zod_schema_type_2 = require("./zod-schema-type");
|
|
48
47
|
const ZodArrayItemEditor_1 = require("./ZodArrayItemEditor");
|
|
49
48
|
const ZodFieldValidation_1 = require("./ZodFieldValidation");
|
|
50
49
|
const rowStyle = {
|
|
@@ -52,15 +51,13 @@ const rowStyle = {
|
|
|
52
51
|
flexDirection: 'row',
|
|
53
52
|
width: '100%',
|
|
54
53
|
};
|
|
55
|
-
const ZodMatrixEditor = ({ schema, jsonPath, setValue,
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
savedValue: defaultValue,
|
|
61
|
-
});
|
|
54
|
+
const ZodMatrixEditor = ({ schema, jsonPath, setValue, value, onRemove, mayPad }) => {
|
|
55
|
+
const onChange = (0, react_2.useCallback)((updater, { shouldSave }) => {
|
|
56
|
+
setValue(updater, { shouldSave });
|
|
57
|
+
}, [setValue]);
|
|
58
|
+
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
|
|
62
59
|
const [expanded, setExpanded] = (0, react_1.useState)(true);
|
|
63
|
-
const arrayElement = (0,
|
|
60
|
+
const arrayElement = (0, zod_schema_type_2.getArrayElement)(schema);
|
|
64
61
|
const suffix = (0, react_1.useMemo)(() => {
|
|
65
62
|
return expanded ? ' [' : ' [...] ';
|
|
66
63
|
}, [expanded]);
|
|
@@ -68,34 +65,27 @@ const ZodMatrixEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSa
|
|
|
68
65
|
if (!z) {
|
|
69
66
|
throw new Error('expected zod');
|
|
70
67
|
}
|
|
71
|
-
const
|
|
72
|
-
const isDefaultValue = (0, react_1.useMemo)(() => {
|
|
73
|
-
return (0, deep_equal_1.deepEqual)(localValue.value, defaultValue);
|
|
74
|
-
}, [defaultValue, localValue]);
|
|
75
|
-
const dimensions = Math.sqrt(localValue.value.length);
|
|
68
|
+
const dimensions = Math.sqrt(value.length);
|
|
76
69
|
if (!Number.isInteger(dimensions)) {
|
|
77
70
|
throw new Error('Invalid matrix');
|
|
78
71
|
}
|
|
79
72
|
const chunkedItems = (0, react_1.useMemo)(() => {
|
|
80
|
-
return
|
|
73
|
+
return value.reduce((acc, item, index) => {
|
|
81
74
|
const chunkIndex = Math.floor(index / dimensions);
|
|
82
75
|
acc[chunkIndex] = acc[chunkIndex] || [];
|
|
83
76
|
acc[chunkIndex].push(item);
|
|
84
77
|
return acc;
|
|
85
78
|
}, []);
|
|
86
|
-
}, [
|
|
87
|
-
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad,
|
|
88
|
-
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return (jsx_runtime_1.jsx("div", { style: { flex: 1 }, children: jsx_runtime_1.jsx(ZodArrayItemEditor_1.ZodArrayItemEditor, { onChange: onChange, value: item, elementSchema: arrayElement, index: actualIndex, jsonPath: jsonPath, defaultValue: (_a = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue[actualIndex]) !== null && _a !== void 0 ? _a : (0, create_zod_values_1.createZodValues)(arrayElement, z, zodTypes), onSave: onSave, showSaveButton: showSaveButton, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad, mayRemove: false }) }, `${_index}${localValue.keyStabilityRevision}`));
|
|
97
|
-
}) }) }, `${rowIndex}${localValue.keyStabilityRevision}`));
|
|
98
|
-
}), value.length === 0 ? (jsx_runtime_1.jsx(SchemaSeparationLine_1.SchemaArrayItemSeparationLine, { schema: schema, index: 0, onChange: onChange, isLast: true, showAddButton: true })) : null] }) })) : null, jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
|
|
79
|
+
}, [value, dimensions]);
|
|
80
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
|
|
81
|
+
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { jsonPath: jsonPath, onRemove: onRemove, suffix: suffix, valid: zodValidation.success, handleClick: () => setExpanded(!expanded) }), expanded ? (jsx_runtime_1.jsxs(SchemaVerticalGuide_1.SchemaVerticalGuide, { isRoot: false, children: [chunkedItems.map((row, rowIndex) => {
|
|
82
|
+
return (jsx_runtime_1.jsx(react_1.default.Fragment
|
|
83
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
84
|
+
, { children: jsx_runtime_1.jsx("div", { style: rowStyle, children: row.map((item, _index) => {
|
|
85
|
+
const actualIndex = rowIndex * dimensions + _index;
|
|
86
|
+
return (jsx_runtime_1.jsx("div", { style: { flex: 1 }, children: jsx_runtime_1.jsx(ZodArrayItemEditor_1.ZodArrayItemEditor, { onChange: onChange, value: item, elementSchema: arrayElement, index: actualIndex, jsonPath: jsonPath, mayPad: mayPad, mayRemove: false }) }, _index));
|
|
87
|
+
}) }) }, rowIndex));
|
|
88
|
+
}), value.length === 0 ? (jsx_runtime_1.jsx(SchemaSeparationLine_1.SchemaArrayItemSeparationLine, { schema: schema, index: 0, onChange: onChange, isLast: true, showAddButton: true })) : null] })) : null, jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
|
|
99
89
|
] }));
|
|
100
90
|
};
|
|
101
91
|
exports.ZodMatrixEditor = ZodMatrixEditor;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZonNonEditableValue = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
5
|
const colors_1 = require("../../../helpers/colors");
|
|
7
6
|
const Fieldset_1 = require("./Fieldset");
|
|
8
7
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
@@ -19,11 +18,9 @@ const wideEmptyLabel = {
|
|
|
19
18
|
...emptyLabel,
|
|
20
19
|
lineHeight: '37px',
|
|
21
20
|
};
|
|
22
|
-
const ZonNonEditableValue = ({ jsonPath, label,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: true, children: [
|
|
26
|
-
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: true, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: null, saving: saving, valid: true, saveDisabledByParent: true, suffix: null }), jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx("em", { style: wideEmptyLabel, children: label }) })
|
|
21
|
+
const ZonNonEditableValue = ({ jsonPath, label, mayPad }) => {
|
|
22
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
|
|
23
|
+
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: null, valid: true, suffix: null }), jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx("em", { style: wideEmptyLabel, children: label }) })
|
|
27
24
|
] }));
|
|
28
25
|
};
|
|
29
26
|
exports.ZonNonEditableValue = ZonNonEditableValue;
|
|
@@ -2,15 +2,10 @@ import type { AnyZodSchema } from './zod-schema-type';
|
|
|
2
2
|
import type { JSONPath } from './zod-types';
|
|
3
3
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
4
|
export declare const ZodNullableEditor: React.FC<{
|
|
5
|
-
showSaveButton: boolean;
|
|
6
5
|
jsonPath: JSONPath;
|
|
7
6
|
value: unknown;
|
|
8
|
-
defaultValue: unknown;
|
|
9
7
|
schema: AnyZodSchema;
|
|
10
8
|
setValue: UpdaterFunction<unknown>;
|
|
11
|
-
onSave: UpdaterFunction<unknown>;
|
|
12
9
|
onRemove: null | (() => void);
|
|
13
|
-
saving: boolean;
|
|
14
|
-
saveDisabledByParent: boolean;
|
|
15
10
|
mayPad: boolean;
|
|
16
11
|
}>;
|
|
@@ -4,8 +4,8 @@ exports.ZodNullableEditor = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const zod_schema_type_1 = require("./zod-schema-type");
|
|
6
6
|
const ZodOrNullishEditor_1 = require("./ZodOrNullishEditor");
|
|
7
|
-
const ZodNullableEditor = ({ jsonPath, schema, setValue,
|
|
7
|
+
const ZodNullableEditor = ({ jsonPath, schema, setValue, value, onRemove, mayPad }) => {
|
|
8
8
|
const innerType = (0, zod_schema_type_1.getInnerType)(schema);
|
|
9
|
-
return (jsx_runtime_1.jsx(ZodOrNullishEditor_1.ZodOrNullishEditor, {
|
|
9
|
+
return (jsx_runtime_1.jsx(ZodOrNullishEditor_1.ZodOrNullishEditor, { jsonPath: jsonPath, onRemove: onRemove, schema: schema, innerSchema: innerType, setValue: setValue, value: value, nullishValue: null, mayPad: mayPad }));
|
|
10
10
|
};
|
|
11
11
|
exports.ZodNullableEditor = ZodNullableEditor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type AnyZodSchema } from './zod-schema-type';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
4
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
5
5
|
export declare const ZodNumberEditor: React.FC<{
|
|
@@ -7,11 +7,6 @@ export declare const ZodNumberEditor: React.FC<{
|
|
|
7
7
|
readonly jsonPath: JSONPath;
|
|
8
8
|
readonly value: number;
|
|
9
9
|
readonly setValue: UpdaterFunction<number>;
|
|
10
|
-
readonly defaultValue: number;
|
|
11
|
-
readonly onSave: UpdaterFunction<number>;
|
|
12
10
|
readonly onRemove: null | (() => void);
|
|
13
|
-
readonly showSaveButton: boolean;
|
|
14
|
-
readonly saving: boolean;
|
|
15
|
-
readonly saveDisabledByParent: boolean;
|
|
16
11
|
readonly mayPad: boolean;
|
|
17
12
|
}>;
|
|
@@ -3,35 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ZodNumberEditor = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const InputDragger_1 = require("../../NewComposition/InputDragger");
|
|
7
8
|
const Fieldset_1 = require("./Fieldset");
|
|
8
|
-
const local_state_1 = require("./local-state");
|
|
9
9
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
10
10
|
const zod_number_constraints_1 = require("./zod-number-constraints");
|
|
11
|
+
const zod_schema_type_1 = require("./zod-schema-type");
|
|
11
12
|
const ZodFieldValidation_1 = require("./ZodFieldValidation");
|
|
12
13
|
const fullWidth = {
|
|
13
14
|
width: '100%',
|
|
14
15
|
};
|
|
15
|
-
const ZodNumberEditor = ({ jsonPath, value, schema, setValue,
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
}, [
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const save = (0, react_1.useCallback)(() => {
|
|
30
|
-
onSave(() => value, false, false);
|
|
31
|
-
}, [onSave, value]);
|
|
32
|
-
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
|
|
33
|
-
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: isDefault, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
|
|
34
|
-
jsx_runtime_1.jsx(InputDragger_1.InputDragger, { type: 'number', value: localValue.value, style: fullWidth, status: localValue.zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onTextChange: onTextChange, onValueChange: onNumberChange, min: (0, zod_number_constraints_1.getZodNumberMinimum)(schema), max: (0, zod_number_constraints_1.getZodNumberMaximum)(schema), step: (0, zod_number_constraints_1.getZodNumberStep)(schema), rightAlign: false }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
|
|
16
|
+
const ZodNumberEditor = ({ jsonPath, value, schema, setValue, onRemove, mayPad }) => {
|
|
17
|
+
const onNumberChange = (0, react_2.useCallback)((newValue) => {
|
|
18
|
+
setValue(() => newValue, { shouldSave: false });
|
|
19
|
+
}, [setValue]);
|
|
20
|
+
const onNumberChangeEnd = (0, react_2.useCallback)((newValue) => {
|
|
21
|
+
setValue(() => newValue, { shouldSave: true });
|
|
22
|
+
}, [setValue]);
|
|
23
|
+
const onTextChange = (0, react_2.useCallback)((newValue) => {
|
|
24
|
+
setValue(() => Number(newValue), { shouldSave: true });
|
|
25
|
+
}, [setValue]);
|
|
26
|
+
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
|
|
27
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
|
|
28
|
+
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
|
|
29
|
+
jsx_runtime_1.jsx(InputDragger_1.InputDragger, { type: 'number', value: value, style: fullWidth, status: zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onTextChange: onTextChange, onValueChange: onNumberChange, onValueChangeEnd: onNumberChangeEnd, min: (0, zod_number_constraints_1.getZodNumberMinimum)(schema), max: (0, zod_number_constraints_1.getZodNumberMaximum)(schema), step: (0, zod_number_constraints_1.getZodNumberStep)(schema), rightAlign: false }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
|
|
35
30
|
] })
|
|
36
31
|
] }));
|
|
37
32
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type AnyZodSchema } from './zod-schema-type';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
4
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
5
5
|
export type ObjectDiscrimatedUnionReplacement = {
|
|
@@ -9,14 +9,9 @@ export type ObjectDiscrimatedUnionReplacement = {
|
|
|
9
9
|
export declare const ZodObjectEditor: React.FC<{
|
|
10
10
|
readonly schema: AnyZodSchema;
|
|
11
11
|
readonly jsonPath: JSONPath;
|
|
12
|
-
readonly
|
|
13
|
-
readonly savedValue: Record<string, unknown>;
|
|
12
|
+
readonly value: Record<string, unknown>;
|
|
14
13
|
readonly setValue: UpdaterFunction<Record<string, unknown>>;
|
|
15
|
-
readonly onSave: UpdaterFunction<Record<string, unknown>>;
|
|
16
|
-
readonly showSaveButton: boolean;
|
|
17
14
|
readonly onRemove: null | (() => void);
|
|
18
|
-
readonly saving: boolean;
|
|
19
|
-
readonly saveDisabledByParent: boolean;
|
|
20
15
|
readonly mayPad: boolean;
|
|
21
16
|
readonly discriminatedUnionReplacement: ObjectDiscrimatedUnionReplacement | null;
|
|
22
17
|
}>;
|
|
@@ -35,68 +35,46 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ZodObjectEditor = void 0;
|
|
37
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
-
const react_1 =
|
|
38
|
+
const react_1 = require("react");
|
|
39
|
+
const react_2 = __importStar(require("react"));
|
|
39
40
|
const layout_1 = require("../layout");
|
|
40
|
-
const deep_equal_1 = require("./deep-equal");
|
|
41
41
|
const Fieldset_1 = require("./Fieldset");
|
|
42
|
-
const local_state_1 = require("./local-state");
|
|
43
42
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
44
43
|
const SchemaSeparationLine_1 = require("./SchemaSeparationLine");
|
|
45
44
|
const SchemaVerticalGuide_1 = require("./SchemaVerticalGuide");
|
|
46
45
|
const zod_schema_type_1 = require("./zod-schema-type");
|
|
46
|
+
const zod_schema_type_2 = require("./zod-schema-type");
|
|
47
47
|
const ZodSwitch_1 = require("./ZodSwitch");
|
|
48
|
-
const ZodObjectEditor = ({ schema, jsonPath, setValue,
|
|
49
|
-
const [expanded, setExpanded] = (0,
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
savedValue,
|
|
55
|
-
});
|
|
56
|
-
const typeName = (0, zod_schema_type_1.getZodSchemaType)(schema);
|
|
48
|
+
const ZodObjectEditor = ({ schema, jsonPath, setValue, value, onRemove, mayPad, discriminatedUnionReplacement, }) => {
|
|
49
|
+
const [expanded, setExpanded] = (0, react_2.useState)(true);
|
|
50
|
+
const onChange = (0, react_1.useCallback)((updater, { shouldSave }) => {
|
|
51
|
+
setValue(updater, { shouldSave });
|
|
52
|
+
}, [setValue]);
|
|
53
|
+
const typeName = (0, zod_schema_type_2.getZodSchemaType)(schema);
|
|
57
54
|
if (typeName !== 'object') {
|
|
58
55
|
throw new Error('expected object');
|
|
59
56
|
}
|
|
60
|
-
const shape = (0,
|
|
57
|
+
const shape = (0, zod_schema_type_2.getObjectShape)(schema);
|
|
61
58
|
const keys = Object.keys(shape);
|
|
62
59
|
const isRoot = jsonPath.length === 0;
|
|
63
|
-
const
|
|
64
|
-
return (0, deep_equal_1.deepEqual)(localValue.value, savedValue);
|
|
65
|
-
}, [savedValue, localValue]);
|
|
66
|
-
const suffix = (0, react_1.useMemo)(() => {
|
|
60
|
+
const suffix = (0, react_2.useMemo)(() => {
|
|
67
61
|
return expanded ? ' {' : ' {...}';
|
|
68
62
|
}, [expanded]);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
[key]: typeof val === 'function'
|
|
86
|
-
? val(oldVal[key])
|
|
87
|
-
: val,
|
|
88
|
-
};
|
|
89
|
-
}, forceApply, false);
|
|
90
|
-
}, onSave: (val, forceApply) => {
|
|
91
|
-
onSave((oldVal) => {
|
|
92
|
-
return {
|
|
93
|
-
...oldVal,
|
|
94
|
-
[key]: typeof val === 'function'
|
|
95
|
-
? val(oldVal[key])
|
|
96
|
-
: val,
|
|
97
|
-
};
|
|
98
|
-
}, forceApply, false);
|
|
99
|
-
}, onRemove: null, showSaveButton: showSaveButton, saving: saving, saveDisabledByParent: saveDisabledByParent }), i === keys.length - 1 ? null : jsx_runtime_1.jsx(SchemaSeparationLine_1.SchemaSeparationLine, {})] }, key));
|
|
100
|
-
}) }) })) : null, isRoot || !expanded ? null : jsx_runtime_1.jsx("div", { style: layout_1.fieldsetLabel, children: '}' })] }));
|
|
63
|
+
const zodValidation = (0, react_2.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
|
|
64
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: !isRoot && mayPad, children: [isRoot ? null : (jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { jsonPath: jsonPath, onRemove: onRemove, suffix: suffix, valid: zodValidation.success, handleClick: () => setExpanded(!expanded) })), expanded ? (jsx_runtime_1.jsx(SchemaVerticalGuide_1.SchemaVerticalGuide, { isRoot: isRoot, children: keys.map((key, i) => {
|
|
65
|
+
if (discriminatedUnionReplacement &&
|
|
66
|
+
key === discriminatedUnionReplacement.discriminator) {
|
|
67
|
+
return discriminatedUnionReplacement.markup;
|
|
68
|
+
}
|
|
69
|
+
return (jsx_runtime_1.jsxs(react_2.default.Fragment, { children: [
|
|
70
|
+
jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { mayPad: true, jsonPath: [...jsonPath, key], schema: shape[key], value: value[key], setValue: (val, { shouldSave }) => {
|
|
71
|
+
onChange((oldVal) => {
|
|
72
|
+
return {
|
|
73
|
+
...oldVal,
|
|
74
|
+
[key]: typeof val === 'function' ? val(oldVal[key]) : val,
|
|
75
|
+
};
|
|
76
|
+
}, { shouldSave });
|
|
77
|
+
}, onRemove: null }), i === keys.length - 1 ? null : jsx_runtime_1.jsx(SchemaSeparationLine_1.SchemaSeparationLine, {})] }, key));
|
|
78
|
+
}) })) : null, isRoot || !expanded ? null : jsx_runtime_1.jsx("div", { style: layout_1.fieldsetLabel, children: '}' })] }));
|
|
101
79
|
};
|
|
102
80
|
exports.ZodObjectEditor = ZodObjectEditor;
|
|
@@ -2,15 +2,10 @@ import type { AnyZodSchema } from './zod-schema-type';
|
|
|
2
2
|
import type { JSONPath } from './zod-types';
|
|
3
3
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
4
|
export declare const ZodOptionalEditor: React.FC<{
|
|
5
|
-
showSaveButton: boolean;
|
|
6
5
|
jsonPath: JSONPath;
|
|
7
6
|
value: unknown;
|
|
8
|
-
defaultValue: unknown;
|
|
9
7
|
schema: AnyZodSchema;
|
|
10
8
|
setValue: UpdaterFunction<unknown>;
|
|
11
|
-
onSave: UpdaterFunction<unknown>;
|
|
12
9
|
onRemove: null | (() => void);
|
|
13
|
-
saving: boolean;
|
|
14
|
-
saveDisabledByParent: boolean;
|
|
15
10
|
mayPad: boolean;
|
|
16
11
|
}>;
|
|
@@ -4,8 +4,8 @@ exports.ZodOptionalEditor = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const zod_schema_type_1 = require("./zod-schema-type");
|
|
6
6
|
const ZodOrNullishEditor_1 = require("./ZodOrNullishEditor");
|
|
7
|
-
const ZodOptionalEditor = ({ jsonPath, schema, setValue,
|
|
7
|
+
const ZodOptionalEditor = ({ jsonPath, schema, setValue, value, onRemove, mayPad }) => {
|
|
8
8
|
const innerType = (0, zod_schema_type_1.getInnerType)(schema);
|
|
9
|
-
return (jsx_runtime_1.jsx(ZodOrNullishEditor_1.ZodOrNullishEditor, {
|
|
9
|
+
return (jsx_runtime_1.jsx(ZodOrNullishEditor_1.ZodOrNullishEditor, { jsonPath: jsonPath, onRemove: onRemove, schema: schema, setValue: setValue, value: value, nullishValue: undefined, mayPad: mayPad, innerSchema: innerType }));
|
|
10
10
|
};
|
|
11
11
|
exports.ZodOptionalEditor = ZodOptionalEditor;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyZodSchema } from './zod-schema-type';
|
|
2
2
|
import type { JSONPath } from './zod-types';
|
|
3
3
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
4
|
export declare const ZodOrNullishEditor: React.FC<{
|
|
5
|
-
showSaveButton: boolean;
|
|
6
5
|
jsonPath: JSONPath;
|
|
7
6
|
value: unknown;
|
|
8
|
-
defaultValue: unknown;
|
|
9
7
|
schema: AnyZodSchema;
|
|
10
8
|
innerSchema: AnyZodSchema;
|
|
11
9
|
setValue: UpdaterFunction<unknown>;
|
|
12
|
-
onSave: UpdaterFunction<unknown>;
|
|
13
10
|
onRemove: null | (() => void);
|
|
14
11
|
nullishValue: null | undefined;
|
|
15
|
-
saving: boolean;
|
|
16
|
-
saveDisabledByParent: boolean;
|
|
17
12
|
mayPad: boolean;
|
|
18
13
|
}>;
|
|
@@ -3,14 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ZodOrNullishEditor = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const colors_1 = require("../../../helpers/colors");
|
|
7
8
|
const Checkbox_1 = require("../../Checkbox");
|
|
8
9
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
9
10
|
const layout_1 = require("../../layout");
|
|
10
11
|
const create_zod_values_1 = require("./create-zod-values");
|
|
11
12
|
const Fieldset_1 = require("./Fieldset");
|
|
12
|
-
const local_state_1 = require("./local-state");
|
|
13
13
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
14
|
+
const zod_schema_type_1 = require("./zod-schema-type");
|
|
14
15
|
const ZodSwitch_1 = require("./ZodSwitch");
|
|
15
16
|
const labelStyle = {
|
|
16
17
|
fontFamily: 'sans-serif',
|
|
@@ -23,29 +24,21 @@ const checkBoxWrapper = {
|
|
|
23
24
|
alignItems: 'center',
|
|
24
25
|
marginTop: '5px',
|
|
25
26
|
};
|
|
26
|
-
const ZodOrNullishEditor = ({ jsonPath, schema, setValue,
|
|
27
|
+
const ZodOrNullishEditor = ({ jsonPath, schema, setValue, value, onRemove, nullishValue, mayPad, innerSchema, }) => {
|
|
27
28
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
28
29
|
if (!z) {
|
|
29
30
|
throw new Error('expected zod');
|
|
30
31
|
}
|
|
31
32
|
const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
|
|
32
33
|
const isChecked = value === nullishValue;
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
setValue,
|
|
36
|
-
unsavedValue: value,
|
|
37
|
-
savedValue: defaultValue,
|
|
38
|
-
});
|
|
39
|
-
const onCheckBoxChange = (0, react_1.useCallback)((e) => {
|
|
34
|
+
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
|
|
35
|
+
const onCheckBoxChange = (0, react_2.useCallback)((e) => {
|
|
40
36
|
const val = e.target.checked
|
|
41
37
|
? nullishValue
|
|
42
38
|
: (0, create_zod_values_1.createZodValues)(innerSchema, z, zodTypes);
|
|
43
|
-
|
|
44
|
-
}, [innerSchema, nullishValue,
|
|
45
|
-
|
|
46
|
-
onSave(() => value, false, false);
|
|
47
|
-
}, [onSave, value]);
|
|
48
|
-
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [localValue.value === nullishValue ? (jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null })) : (jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { value: localValue.value, setValue: setLocalValue, jsonPath: jsonPath, schema: innerSchema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: false })), jsx_runtime_1.jsxs("div", { style: checkBoxWrapper, children: [
|
|
39
|
+
setValue(() => val, { shouldSave: true });
|
|
40
|
+
}, [innerSchema, nullishValue, setValue, z, zodTypes]);
|
|
41
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [value === nullishValue ? (jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null })) : (jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { value: value, setValue: setValue, jsonPath: jsonPath, schema: innerSchema, onRemove: onRemove, mayPad: false })), jsx_runtime_1.jsxs("div", { style: checkBoxWrapper, children: [
|
|
49
42
|
jsx_runtime_1.jsx(Checkbox_1.Checkbox, { checked: isChecked, onChange: onCheckBoxChange, disabled: false, name: jsonPath.join('.') }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1 }), jsx_runtime_1.jsx("div", { style: labelStyle, children: String(nullishValue) })
|
|
50
43
|
] })
|
|
51
44
|
] }));
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type AnyZodSchema } from './zod-schema-type';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
4
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
5
5
|
export declare const ZodStaticFileEditor: React.FC<{
|
|
6
6
|
readonly schema: AnyZodSchema;
|
|
7
7
|
readonly jsonPath: JSONPath;
|
|
8
8
|
readonly value: string;
|
|
9
|
-
readonly defaultValue: string;
|
|
10
9
|
readonly setValue: UpdaterFunction<string>;
|
|
11
|
-
readonly onSave: (updater: (oldState: string) => string) => void;
|
|
12
|
-
readonly showSaveButton: boolean;
|
|
13
10
|
readonly onRemove: null | (() => void);
|
|
14
|
-
readonly saving: boolean;
|
|
15
|
-
readonly saveDisabledByParent: boolean;
|
|
16
11
|
readonly mayPad: boolean;
|
|
17
12
|
}>;
|
|
@@ -7,19 +7,17 @@ const Checkmark_1 = require("../../../icons/Checkmark");
|
|
|
7
7
|
const ComboBox_1 = require("../../NewComposition/ComboBox");
|
|
8
8
|
const use_static_files_1 = require("../../use-static-files");
|
|
9
9
|
const Fieldset_1 = require("./Fieldset");
|
|
10
|
-
const local_state_1 = require("./local-state");
|
|
11
10
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
11
|
+
const zod_schema_type_1 = require("./zod-schema-type");
|
|
12
12
|
const ZodFieldValidation_1 = require("./ZodFieldValidation");
|
|
13
13
|
const container = {
|
|
14
14
|
width: '100%',
|
|
15
15
|
};
|
|
16
|
-
const ZodStaticFileEditor = ({ schema, jsonPath, setValue,
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
savedValue: defaultValue,
|
|
22
|
-
});
|
|
16
|
+
const ZodStaticFileEditor = ({ schema, jsonPath, setValue, value, onRemove, mayPad }) => {
|
|
17
|
+
const onChange = (0, react_1.useCallback)((updater, { shouldSave }) => {
|
|
18
|
+
setValue(updater, { shouldSave });
|
|
19
|
+
}, [setValue]);
|
|
20
|
+
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
|
|
23
21
|
const isRoot = jsonPath.length === 0;
|
|
24
22
|
const staticFiles = (0, use_static_files_1.useStaticFiles)();
|
|
25
23
|
const comboBoxValues = (0, react_1.useMemo)(() => {
|
|
@@ -31,19 +29,16 @@ const ZodStaticFileEditor = ({ schema, jsonPath, setValue, defaultValue, value,
|
|
|
31
29
|
keyHint: null,
|
|
32
30
|
leftItem: option.src === value ? jsx_runtime_1.jsx(Checkmark_1.Checkmark, {}) : null,
|
|
33
31
|
onClick: (id) => {
|
|
34
|
-
|
|
32
|
+
onChange(() => id, { shouldSave: true });
|
|
35
33
|
},
|
|
36
34
|
quickSwitcherLabel: null,
|
|
37
35
|
subMenu: null,
|
|
38
36
|
type: 'item',
|
|
39
37
|
};
|
|
40
38
|
});
|
|
41
|
-
}, [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}, [onSave, value]);
|
|
45
|
-
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
|
|
46
|
-
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, onSave: save, showSaveButton: showSaveButton, isDefaultValue: localValue.value === defaultValue, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), jsx_runtime_1.jsx("div", { style: isRoot ? undefined : container, children: jsx_runtime_1.jsx(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: localValue.value, title: value }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
|
|
39
|
+
}, [onChange, staticFiles, value]);
|
|
40
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
|
|
41
|
+
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsx("div", { style: isRoot ? undefined : container, children: jsx_runtime_1.jsx(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: value, title: value }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
|
|
47
42
|
] }));
|
|
48
43
|
};
|
|
49
44
|
exports.ZodStaticFileEditor = ZodStaticFileEditor;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type AnyZodSchema } from './zod-schema-type';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
4
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
5
5
|
export declare const ZodStringEditor: React.FC<{
|
|
6
6
|
readonly schema: AnyZodSchema;
|
|
7
7
|
readonly jsonPath: JSONPath;
|
|
8
8
|
readonly value: string;
|
|
9
|
-
readonly defaultValue: string;
|
|
10
9
|
readonly setValue: UpdaterFunction<string>;
|
|
11
|
-
readonly onSave: UpdaterFunction<string>;
|
|
12
10
|
readonly onRemove: null | (() => void);
|
|
13
|
-
readonly showSaveButton: boolean;
|
|
14
|
-
readonly saving: boolean;
|
|
15
|
-
readonly saveDisabledByParent: boolean;
|
|
16
11
|
readonly mayPad: boolean;
|
|
17
12
|
}>;
|
|
@@ -3,35 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ZodStringEditor = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
7
8
|
const RemInput_1 = require("../../NewComposition/RemInput");
|
|
8
9
|
const Fieldset_1 = require("./Fieldset");
|
|
9
|
-
const local_state_1 = require("./local-state");
|
|
10
10
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
11
|
+
const zod_schema_type_1 = require("./zod-schema-type");
|
|
11
12
|
const ZodFieldValidation_1 = require("./ZodFieldValidation");
|
|
12
13
|
const fullWidth = {
|
|
13
14
|
width: '100%',
|
|
14
15
|
};
|
|
15
|
-
const ZodStringEditor = ({ jsonPath, value, setValue,
|
|
16
|
+
const ZodStringEditor = ({ jsonPath, value, setValue, schema, onRemove, mayPad }) => {
|
|
16
17
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
17
18
|
if (!z) {
|
|
18
19
|
throw new Error('expected zod');
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
setValue,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
onSave(() => value, false, false);
|
|
31
|
-
}, [onSave, value]);
|
|
32
|
-
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: false, children: [
|
|
33
|
-
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
|
|
34
|
-
jsx_runtime_1.jsx(RemInput_1.RemotionInput, { value: localValue.value, status: localValue.zodValidation ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, rightAlign: false, name: jsonPath.join('.') }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
|
|
21
|
+
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
|
|
22
|
+
const onChange = (0, react_2.useCallback)((e) => {
|
|
23
|
+
setValue(() => e.target.value, { shouldSave: false });
|
|
24
|
+
}, [setValue]);
|
|
25
|
+
const onBlur = (0, react_2.useCallback)(() => {
|
|
26
|
+
setValue(() => value, { shouldSave: true });
|
|
27
|
+
}, [setValue, value]);
|
|
28
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
|
|
29
|
+
jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
|
|
30
|
+
jsx_runtime_1.jsx(RemInput_1.RemotionInput, { value: value, status: zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, onBlur: onBlur, rightAlign: false, name: jsonPath.join('.') }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
|
|
35
31
|
] })
|
|
36
32
|
] }));
|
|
37
33
|
};
|