@remotion/cli 4.0.0-alpha8 → 4.0.0-alpha9
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/codemods/update-default-props.d.ts +1 -1
- package/dist/codemods/update-default-props.js +0 -1
- package/dist/editor/components/CheckboardToggle.js +2 -1
- package/dist/editor/components/InlineAction.d.ts +1 -1
- package/dist/editor/components/InlineAction.js +6 -3
- package/dist/editor/components/LoopToggle.js +2 -1
- package/dist/editor/components/Menu/MenuItem.js +1 -1
- package/dist/editor/components/Menu/SubMenu.js +1 -1
- package/dist/editor/components/NewComposition/ComboBox.js +19 -4
- package/dist/editor/components/NewComposition/InputDragger.js +3 -2
- package/dist/editor/components/NewComposition/MenuContent.d.ts +1 -0
- package/dist/editor/components/NewComposition/MenuContent.js +11 -3
- package/dist/editor/components/RenderModal/EnforceAudioTrackSetting.js +3 -2
- package/dist/editor/components/RenderModal/MutedSetting.js +3 -2
- package/dist/editor/components/RenderModal/RenderModal.d.ts +1 -1
- package/dist/editor/components/RenderModal/RenderModal.js +6 -4
- package/dist/editor/components/RenderModal/RenderModalAdvanced.js +0 -2
- package/dist/editor/components/RenderModal/RenderModalAudio.js +1 -1
- package/dist/editor/components/RenderModal/RenderModalBasic.js +3 -2
- package/dist/editor/components/RenderModal/RenderModalData.d.ts +3 -3
- package/dist/editor/components/RenderModal/RenderModalData.js +16 -5
- package/dist/editor/components/RenderModal/RenderModalJSONPropsEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaEditor.d.ts +5 -4
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaEditor.js +4 -4
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.d.ts +3 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.js +6 -2
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaLabel.d.ts +4 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaLabel.js +5 -4
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaSaveButton.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaSaveButton.js +4 -4
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.d.ts +1 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.js +38 -26
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayItemEditor.d.ts +4 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayItemEditor.js +4 -4
- package/dist/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.d.ts +2 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.js +7 -7
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +2 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.js +17 -60
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDateEditor.d.ts +2 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDateEditor.js +10 -18
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.d.ts +3 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.js +6 -19
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEnumEditor.js +12 -26
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNonEditableValue.js +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNullableEditor.d.ts +4 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNullableEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNumberEditor.d.ts +2 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNumberEditor.js +15 -34
- package/dist/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.d.ts +6 -4
- package/dist/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.js +17 -10
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOptionalEditor.d.ts +4 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOptionalEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +4 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.js +6 -6
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStaticFileEditor.d.ts +1 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStaticFileEditor.js +11 -25
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStringEditor.d.ts +2 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStringEditor.js +12 -23
- package/dist/editor/components/RenderModal/SchemaEditor/ZodSwitch.d.ts +3 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodSwitch.js +12 -12
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +4 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/local-state.d.ts +16 -0
- package/dist/editor/components/RenderModal/SchemaEditor/local-state.js +44 -0
- package/dist/editor/components/RenderModal/out-name-checker.js +1 -11
- package/dist/editor/components/RenderQueue/actions.d.ts +3 -3
- package/dist/editor/components/RightPanel.js +3 -3
- package/dist/editor/components/Tabs/index.js +12 -14
- package/dist/editor/components/Timeline/TimelineSequence.js +2 -2
- package/dist/editor/components/TimelineInOutToggle.js +2 -1
- package/dist/editor/components/UpdateCheck.js +2 -1
- package/dist/editor/helpers/colors.d.ts +2 -0
- package/dist/editor/helpers/colors.js +3 -1
- package/dist/editor/icons/media-volume.js +2 -1
- package/dist/editor/state/modals.d.ts +1 -1
- package/dist/get-cli-options.d.ts +1 -1
- package/dist/get-input-props.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/list-of-remotion-packages.js +1 -0
- package/dist/preview-server/api-types.d.ts +2 -2
- package/dist/preview-server/error-overlay/remotion-overlay/HelpLink.js +2 -1
- package/dist/preview-server/render-queue/job.d.ts +9 -2
- package/dist/preview-server/render-queue/make-retry-payload.js +1 -1
- package/dist/preview-server/render-queue/queue.js +0 -1
- package/dist/preview-server/routes/update-default-props.d.ts +2 -2
- package/dist/preview-server/routes/update-default-props.js +23 -13
- package/dist/preview-server/routes.d.ts +2 -1
- package/dist/preview-server/start-server.js +1 -1
- package/dist/render-flows/render.d.ts +1 -1
- package/dist/render-flows/still.d.ts +1 -1
- package/package.json +13 -11
- package/styles/styles.css +4 -5
|
@@ -7,6 +7,7 @@ const layout_1 = require("../../layout");
|
|
|
7
7
|
const InputDragger_1 = require("../../NewComposition/InputDragger");
|
|
8
8
|
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
9
9
|
const layout_2 = require("../layout");
|
|
10
|
+
const local_state_1 = require("./local-state");
|
|
10
11
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
11
12
|
const fullWidth = {
|
|
12
13
|
width: '100%',
|
|
@@ -47,45 +48,25 @@ const getStep = (schema) => {
|
|
|
47
48
|
}
|
|
48
49
|
return multipleStep.value;
|
|
49
50
|
};
|
|
50
|
-
const ZodNumberEditor = ({ jsonPath, value, schema, setValue, onSave, compact, defaultValue, onRemove, showSaveButton, saving, }) => {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
51
|
+
const ZodNumberEditor = ({ jsonPath, value, schema, setValue, onSave, compact, defaultValue, onRemove, showSaveButton, saving, saveDisabledByParent, }) => {
|
|
52
|
+
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
53
|
+
value,
|
|
54
|
+
schema,
|
|
55
|
+
setValue,
|
|
56
56
|
});
|
|
57
|
-
const onChange = (0, react_1.useCallback)((newValue) => {
|
|
58
|
-
const safeParse = schema.safeParse(Number(newValue));
|
|
59
|
-
const newLocalState = {
|
|
60
|
-
value: newValue,
|
|
61
|
-
zodValidation: safeParse,
|
|
62
|
-
};
|
|
63
|
-
setLocalValue(newLocalState);
|
|
64
|
-
if (safeParse.success) {
|
|
65
|
-
setValue(() => Number(newValue));
|
|
66
|
-
}
|
|
67
|
-
}, [schema, setValue]);
|
|
68
|
-
const onValueChange = (0, react_1.useCallback)((newValue, forceApply) => {
|
|
69
|
-
const safeParse = schema.safeParse(newValue);
|
|
70
|
-
const newLocalState = {
|
|
71
|
-
value: String(newValue),
|
|
72
|
-
zodValidation: safeParse,
|
|
73
|
-
};
|
|
74
|
-
setLocalValue(newLocalState);
|
|
75
|
-
if (safeParse.success || forceApply) {
|
|
76
|
-
setValue(() => newValue);
|
|
77
|
-
}
|
|
78
|
-
}, [schema, setValue]);
|
|
79
57
|
const onNumberChange = (0, react_1.useCallback)((newValue) => {
|
|
80
|
-
|
|
81
|
-
}, [
|
|
58
|
+
setLocalValue(() => newValue, false);
|
|
59
|
+
}, [setLocalValue]);
|
|
82
60
|
const isDefault = value === defaultValue;
|
|
83
61
|
const reset = (0, react_1.useCallback)(() => {
|
|
84
|
-
|
|
85
|
-
}, [defaultValue,
|
|
62
|
+
setLocalValue(() => defaultValue, true);
|
|
63
|
+
}, [defaultValue, setLocalValue]);
|
|
64
|
+
const onTextChange = (0, react_1.useCallback)((newValue) => {
|
|
65
|
+
setLocalValue(() => Number(newValue), false);
|
|
66
|
+
}, [setLocalValue]);
|
|
86
67
|
const save = (0, react_1.useCallback)(() => {
|
|
87
|
-
onSave(() => value);
|
|
68
|
+
onSave(() => value, false);
|
|
88
69
|
}, [onSave, value]);
|
|
89
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: isDefault, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove, saving: saving }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(InputDragger_1.InputDragger, { type: 'number', value: localValue.value, style: fullWidth, status: localValue.zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onTextChange:
|
|
70
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: isDefault, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, 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: getMinValue(schema), max: getMaxValue(schema), step: getStep(schema), rightAlign: false }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] })] }));
|
|
90
71
|
};
|
|
91
72
|
exports.ZodNumberEditor = ZodNumberEditor;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodObjectEditor: React.FC<{
|
|
5
6
|
schema: z.ZodTypeAny;
|
|
6
7
|
jsonPath: JSONPath;
|
|
7
|
-
value: unknown
|
|
8
|
-
defaultValue: unknown
|
|
9
|
-
setValue:
|
|
8
|
+
value: Record<string, unknown>;
|
|
9
|
+
defaultValue: Record<string, unknown>;
|
|
10
|
+
setValue: UpdaterFunction<Record<string, unknown>>;
|
|
10
11
|
compact: boolean;
|
|
11
|
-
onSave:
|
|
12
|
+
onSave: UpdaterFunction<Record<string, unknown>>;
|
|
12
13
|
showSaveButton: boolean;
|
|
13
14
|
onRemove: null | (() => void);
|
|
14
15
|
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
15
17
|
}>;
|
|
@@ -6,6 +6,7 @@ const react_1 = require("react");
|
|
|
6
6
|
const colors_1 = require("../../../helpers/colors");
|
|
7
7
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
8
8
|
const layout_1 = require("../layout");
|
|
9
|
+
const local_state_1 = require("./local-state");
|
|
9
10
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
10
11
|
const ZodSwitch_1 = require("./ZodSwitch");
|
|
11
12
|
const container = {
|
|
@@ -18,12 +19,16 @@ const fieldset = {
|
|
|
18
19
|
borderRadius: 4,
|
|
19
20
|
borderColor: colors_1.INPUT_BORDER_COLOR_UNHOVERED,
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
-
const ZodObjectEditor = ({ schema, jsonPath, setValue, value, compact, defaultValue, onSave, showSaveButton, onRemove, saving, }) => {
|
|
22
|
+
const ZodObjectEditor = ({ schema, jsonPath, setValue, value, compact, defaultValue, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
23
23
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
24
24
|
if (!z) {
|
|
25
25
|
throw new Error('expected zod');
|
|
26
26
|
}
|
|
27
|
+
const { localValue, onChange } = (0, local_state_1.useLocalState)({
|
|
28
|
+
schema,
|
|
29
|
+
setValue,
|
|
30
|
+
value,
|
|
31
|
+
});
|
|
27
32
|
const def = schema._def;
|
|
28
33
|
const typeName = def.typeName;
|
|
29
34
|
if (typeName !== z.ZodFirstPartyTypeKind.ZodObject) {
|
|
@@ -40,25 +45,27 @@ const ZodObjectEditor = ({ schema, jsonPath, setValue, value, compact, defaultVa
|
|
|
40
45
|
}
|
|
41
46
|
return { paddingTop };
|
|
42
47
|
}, [isRoot, paddingTop]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
const onRes = (0, react_1.useCallback)(() => {
|
|
49
|
+
onChange(() => defaultValue, true);
|
|
50
|
+
}, [defaultValue, onChange]);
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: style, children: (0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsxs)(Element, { style: fieldset, children: [isRoot ? null : ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaFieldsetLabel, { isDefaultValue: true, onReset: onRes, jsonPath: jsonPath, onRemove: onRemove })), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: keys.map((key) => {
|
|
52
|
+
return ((0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { jsonPath: [...jsonPath, key], schema: shape[key], value: localValue.value[key],
|
|
46
53
|
// In case of null | {a: string, b: string} type, we need to fallback to the default value
|
|
47
|
-
defaultValue: (
|
|
54
|
+
defaultValue: (defaultValue !== null && defaultValue !== void 0 ? defaultValue : value)[key], setValue: (val, forceApply) => {
|
|
48
55
|
setValue((oldVal) => {
|
|
49
56
|
return {
|
|
50
57
|
...oldVal,
|
|
51
58
|
[key]: typeof val === 'function' ? val(oldVal[key]) : val,
|
|
52
59
|
};
|
|
53
|
-
});
|
|
54
|
-
}, onSave: (val) => {
|
|
60
|
+
}, forceApply);
|
|
61
|
+
}, onSave: (val, forceApply) => {
|
|
55
62
|
onSave((oldVal) => {
|
|
56
63
|
return {
|
|
57
64
|
...oldVal,
|
|
58
65
|
[key]: typeof val === 'function' ? val(oldVal[key]) : val,
|
|
59
66
|
};
|
|
60
|
-
});
|
|
61
|
-
}, onRemove: null, compact: compact, showSaveButton: showSaveButton, saving: saving }, key));
|
|
67
|
+
}, forceApply);
|
|
68
|
+
}, onRemove: null, compact: compact, showSaveButton: showSaveButton, saving: saving, saveDisabledByParent: saveDisabledByParent }, key));
|
|
62
69
|
}) })] }) }) }));
|
|
63
70
|
};
|
|
64
71
|
exports.ZodObjectEditor = ZodObjectEditor;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodOptionalEditor: React.FC<{
|
|
5
6
|
showSaveButton: boolean;
|
|
6
7
|
jsonPath: JSONPath;
|
|
@@ -8,8 +9,9 @@ export declare const ZodOptionalEditor: React.FC<{
|
|
|
8
9
|
value: unknown;
|
|
9
10
|
defaultValue: unknown;
|
|
10
11
|
schema: z.ZodTypeAny;
|
|
11
|
-
setValue:
|
|
12
|
-
onSave:
|
|
12
|
+
setValue: UpdaterFunction<unknown>;
|
|
13
|
+
onSave: UpdaterFunction<unknown>;
|
|
13
14
|
onRemove: null | (() => void);
|
|
14
15
|
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
15
17
|
}>;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ZodOptionalEditor = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const ZodOrNullishEditor_1 = require("./ZodOrNullishEditor");
|
|
6
|
-
const ZodOptionalEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, }) => {
|
|
6
|
+
const ZodOptionalEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
7
7
|
const { innerType } = schema._def;
|
|
8
|
-
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: undefined, saving: saving }));
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: undefined, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
9
9
|
};
|
|
10
10
|
exports.ZodOptionalEditor = ZodOptionalEditor;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodOrNullishEditor: React.FC<{
|
|
5
6
|
showSaveButton: boolean;
|
|
6
7
|
jsonPath: JSONPath;
|
|
@@ -8,9 +9,10 @@ export declare const ZodOrNullishEditor: React.FC<{
|
|
|
8
9
|
value: unknown;
|
|
9
10
|
defaultValue: unknown;
|
|
10
11
|
schema: z.ZodTypeAny;
|
|
11
|
-
setValue:
|
|
12
|
-
onSave:
|
|
12
|
+
setValue: UpdaterFunction<unknown>;
|
|
13
|
+
onSave: UpdaterFunction<unknown>;
|
|
13
14
|
onRemove: null | (() => void);
|
|
14
15
|
nullishValue: null | undefined;
|
|
15
16
|
saving: boolean;
|
|
17
|
+
saveDisabledByParent: boolean;
|
|
16
18
|
}>;
|
|
@@ -25,7 +25,7 @@ const checkBoxWrapper = {
|
|
|
25
25
|
alignItems: 'center',
|
|
26
26
|
marginTop: '5px',
|
|
27
27
|
};
|
|
28
|
-
const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, nullishValue, saving, }) => {
|
|
28
|
+
const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, nullishValue, saving, saveDisabledByParent, }) => {
|
|
29
29
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
30
30
|
if (!z) {
|
|
31
31
|
throw new Error('expected zod');
|
|
@@ -51,7 +51,7 @@ const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defau
|
|
|
51
51
|
zodValidation: schema.safeParse(newValue),
|
|
52
52
|
};
|
|
53
53
|
});
|
|
54
|
-
setValue(updater);
|
|
54
|
+
setValue(updater, false);
|
|
55
55
|
}, [nullishValue, schema, setValue]);
|
|
56
56
|
const onCheckBoxChange = (0, react_1.useCallback)((e) => {
|
|
57
57
|
const val = e.target.checked
|
|
@@ -65,7 +65,7 @@ const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defau
|
|
|
65
65
|
zodValidation: schema.safeParse(val),
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
onValueChange(() => val);
|
|
68
|
+
onValueChange(() => val, false);
|
|
69
69
|
}, [
|
|
70
70
|
localNonNullishValueValue,
|
|
71
71
|
nullishValue,
|
|
@@ -75,11 +75,11 @@ const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defau
|
|
|
75
75
|
zodTypes,
|
|
76
76
|
]);
|
|
77
77
|
const reset = (0, react_1.useCallback)(() => {
|
|
78
|
-
onValueChange(() => defaultValue);
|
|
78
|
+
onValueChange(() => defaultValue, true);
|
|
79
79
|
}, [defaultValue, onValueChange]);
|
|
80
80
|
const save = (0, react_1.useCallback)(() => {
|
|
81
|
-
onSave(() => value);
|
|
81
|
+
onSave(() => value, false);
|
|
82
82
|
}, [onSave, value]);
|
|
83
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [value === nullishValue ? ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove, saving: saving })) : ((0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { value: value, setValue: onValueChange, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }) })), (0, jsx_runtime_1.jsxs)("div", { style: checkBoxWrapper, children: [(0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { checked: isChecked, onChange: onCheckBoxChange, disabled: false }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)("div", { style: labelStyle, children: String(nullishValue) })] })] }));
|
|
83
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [value === nullishValue ? ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove, saving: saving, valid: localNonNullishValueValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent })) : ((0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { value: value, setValue: onValueChange, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }) })), (0, jsx_runtime_1.jsxs)("div", { style: checkBoxWrapper, children: [(0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { checked: isChecked, onChange: onCheckBoxChange, disabled: false }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)("div", { style: labelStyle, children: String(nullishValue) })] })] }));
|
|
84
84
|
};
|
|
85
85
|
exports.ZodOrNullishEditor = ZodOrNullishEditor;
|
|
@@ -10,21 +10,20 @@ const layout_1 = require("../../layout");
|
|
|
10
10
|
const ComboBox_1 = require("../../NewComposition/ComboBox");
|
|
11
11
|
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
12
12
|
const layout_2 = require("../layout");
|
|
13
|
+
const local_state_1 = require("./local-state");
|
|
13
14
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
14
15
|
const container = {
|
|
15
16
|
width: '100%',
|
|
16
17
|
};
|
|
17
|
-
const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue
|
|
18
|
+
const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
18
19
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
19
20
|
if (!z) {
|
|
20
21
|
throw new Error('expected zod');
|
|
21
22
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
revision: 0,
|
|
27
|
-
};
|
|
23
|
+
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
24
|
+
schema,
|
|
25
|
+
setValue,
|
|
26
|
+
value,
|
|
28
27
|
});
|
|
29
28
|
const def = schema._def;
|
|
30
29
|
const typeName = def.typeName;
|
|
@@ -32,22 +31,9 @@ const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue: updateValue,
|
|
|
32
31
|
throw new Error('expected enum');
|
|
33
32
|
}
|
|
34
33
|
const isRoot = jsonPath.length === 0;
|
|
35
|
-
const onChange = (0, react_1.useCallback)((updater, forceApply) => {
|
|
36
|
-
setLocalValue((oldLocalState) => {
|
|
37
|
-
const newValue = updater(oldLocalState.value);
|
|
38
|
-
const safeParse = schema.safeParse(newValue);
|
|
39
|
-
if (safeParse.success || forceApply) {
|
|
40
|
-
updateValue(updater);
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
value: newValue,
|
|
44
|
-
zodValidation: safeParse,
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
}, [schema, updateValue]);
|
|
48
34
|
const reset = (0, react_1.useCallback)(() => {
|
|
49
|
-
|
|
50
|
-
}, [defaultValue,
|
|
35
|
+
setLocalValue(() => defaultValue, true);
|
|
36
|
+
}, [defaultValue, setLocalValue]);
|
|
51
37
|
const comboBoxValues = (0, react_1.useMemo)(() => {
|
|
52
38
|
return (0, remotion_1.getStaticFiles)().map((option) => {
|
|
53
39
|
return {
|
|
@@ -57,17 +43,17 @@ const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue: updateValue,
|
|
|
57
43
|
keyHint: null,
|
|
58
44
|
leftItem: option.src === value ? (0, jsx_runtime_1.jsx)(Checkmark_1.Checkmark, {}) : null,
|
|
59
45
|
onClick: (id) => {
|
|
60
|
-
|
|
46
|
+
setLocalValue(() => id, false);
|
|
61
47
|
},
|
|
62
48
|
quickSwitcherLabel: null,
|
|
63
49
|
subMenu: null,
|
|
64
50
|
type: 'item',
|
|
65
51
|
};
|
|
66
52
|
});
|
|
67
|
-
}, [
|
|
53
|
+
}, [setLocalValue, value]);
|
|
68
54
|
const save = (0, react_1.useCallback)(() => {
|
|
69
55
|
onSave(() => value);
|
|
70
56
|
}, [onSave, value]);
|
|
71
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { onSave: save, showSaveButton: showSaveButton, isDefaultValue: value === defaultValue, compact: compact, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving }), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: (0, jsx_runtime_1.jsx)(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: localValue.value, title: value }) }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] }));
|
|
57
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { onSave: save, showSaveButton: showSaveButton, isDefaultValue: localValue.value === defaultValue, compact: compact, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent }), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: (0, jsx_runtime_1.jsx)(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: localValue.value, title: value }) }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] }));
|
|
72
58
|
};
|
|
73
59
|
exports.ZodStaticFileEditor = ZodStaticFileEditor;
|
|
@@ -8,9 +8,10 @@ export declare const ZodStringEditor: React.FC<{
|
|
|
8
8
|
value: string;
|
|
9
9
|
defaultValue: string;
|
|
10
10
|
setValue: UpdaterFunction<string>;
|
|
11
|
-
onSave:
|
|
11
|
+
onSave: UpdaterFunction<string>;
|
|
12
12
|
onRemove: null | (() => void);
|
|
13
13
|
compact: boolean;
|
|
14
14
|
showSaveButton: boolean;
|
|
15
15
|
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
16
17
|
}>;
|
|
@@ -8,41 +8,30 @@ const layout_1 = require("../../layout");
|
|
|
8
8
|
const RemInput_1 = require("../../NewComposition/RemInput");
|
|
9
9
|
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
10
10
|
const layout_2 = require("../layout");
|
|
11
|
+
const local_state_1 = require("./local-state");
|
|
11
12
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
12
13
|
const fullWidth = {
|
|
13
14
|
width: '100%',
|
|
14
15
|
};
|
|
15
|
-
const ZodStringEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, compact, onSave, onRemove, saving, }) => {
|
|
16
|
+
const ZodStringEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, compact, onSave, onRemove, saving, saveDisabledByParent, }) => {
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
21
|
+
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
22
|
+
schema,
|
|
23
|
+
setValue,
|
|
24
|
+
value,
|
|
25
25
|
});
|
|
26
|
-
const onValueChange = (0, react_1.useCallback)((newValue, forceApply) => {
|
|
27
|
-
const safeParse = schema.safeParse(newValue);
|
|
28
|
-
const newLocalState = {
|
|
29
|
-
value: newValue,
|
|
30
|
-
zodValidation: safeParse,
|
|
31
|
-
};
|
|
32
|
-
setLocalValue(newLocalState);
|
|
33
|
-
if (safeParse.success || forceApply) {
|
|
34
|
-
setValue(() => newValue);
|
|
35
|
-
}
|
|
36
|
-
}, [schema, setValue]);
|
|
37
26
|
const onChange = (0, react_1.useCallback)((e) => {
|
|
38
|
-
|
|
39
|
-
}, [
|
|
27
|
+
setLocalValue(() => e.target.value, false);
|
|
28
|
+
}, [setLocalValue]);
|
|
40
29
|
const reset = (0, react_1.useCallback)(() => {
|
|
41
|
-
|
|
42
|
-
}, [defaultValue,
|
|
30
|
+
setLocalValue(() => defaultValue, true);
|
|
31
|
+
}, [defaultValue, setLocalValue]);
|
|
43
32
|
const save = (0, react_1.useCallback)(() => {
|
|
44
|
-
onSave(() => value);
|
|
33
|
+
onSave(() => value, false);
|
|
45
34
|
}, [onSave, value]);
|
|
46
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { compact: compact, isDefaultValue: value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(RemInput_1.RemotionInput, { value: localValue.value, status: localValue.zodValidation
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { compact: compact, isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(RemInput_1.RemotionInput, { value: localValue.value, status: localValue.zodValidation ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, rightAlign: false }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] })] }));
|
|
47
36
|
};
|
|
48
37
|
exports.ZodStringEditor = ZodStringEditor;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
-
export declare type UpdaterFunction<T> = (updater: (oldValue: T) => T) => void;
|
|
4
|
+
export declare type UpdaterFunction<T> = (updater: (oldValue: T) => T, forceApply: boolean) => void;
|
|
5
5
|
export declare const ZodSwitch: React.FC<{
|
|
6
6
|
schema: z.ZodTypeAny;
|
|
7
7
|
jsonPath: JSONPath;
|
|
8
8
|
value: unknown;
|
|
9
9
|
defaultValue: unknown;
|
|
10
10
|
setValue: UpdaterFunction<unknown>;
|
|
11
|
-
onSave:
|
|
11
|
+
onSave: UpdaterFunction<unknown>;
|
|
12
12
|
compact: boolean;
|
|
13
13
|
showSaveButton: boolean;
|
|
14
14
|
onRemove: null | (() => void);
|
|
15
15
|
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
16
17
|
}>;
|
|
@@ -17,7 +17,7 @@ const ZodOptionalEditor_1 = require("./ZodOptionalEditor");
|
|
|
17
17
|
const ZodStaticFileEditor_1 = require("./ZodStaticFileEditor");
|
|
18
18
|
const ZodStringEditor_1 = require("./ZodStringEditor");
|
|
19
19
|
const ZodUnionEditor_1 = require("./ZodUnionEditor");
|
|
20
|
-
const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, onSave, showSaveButton, onRemove, saving, }) => {
|
|
20
|
+
const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
21
21
|
const def = schema._def;
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
23
|
const typeName = def.typeName;
|
|
@@ -28,22 +28,22 @@ const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, o
|
|
|
28
28
|
const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
|
|
29
29
|
// TODO: (Maybe?) enable saving of inserted input props by cmd+s /ctrl + s (also for JSON view)
|
|
30
30
|
if (typeName === z.ZodFirstPartyTypeKind.ZodObject) {
|
|
31
|
-
return ((0, jsx_runtime_1.jsx)(ZodObjectEditor_1.ZodObjectEditor, { setValue: setValue, value: value, defaultValue: defaultValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(ZodObjectEditor_1.ZodObjectEditor, { setValue: setValue, value: value, defaultValue: defaultValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
32
32
|
}
|
|
33
33
|
if (typeName === z.ZodFirstPartyTypeKind.ZodString) {
|
|
34
34
|
if (value.startsWith(window.remotion_staticBase)) {
|
|
35
|
-
return ((0, jsx_runtime_1.jsx)(ZodStaticFileEditor_1.ZodStaticFileEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)(ZodStaticFileEditor_1.ZodStaticFileEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
36
36
|
}
|
|
37
|
-
return ((0, jsx_runtime_1.jsx)(ZodStringEditor_1.ZodStringEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(ZodStringEditor_1.ZodStringEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
38
38
|
}
|
|
39
39
|
if (typeName === z.ZodFirstPartyTypeKind.ZodDate) {
|
|
40
|
-
return ((0, jsx_runtime_1.jsx)(ZodDateEditor_1.ZodDateEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
40
|
+
return ((0, jsx_runtime_1.jsx)(ZodDateEditor_1.ZodDateEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
41
41
|
}
|
|
42
42
|
if (typeName === z.ZodFirstPartyTypeKind.ZodNumber) {
|
|
43
|
-
return ((0, jsx_runtime_1.jsx)(ZodNumberEditor_1.ZodNumberEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(ZodNumberEditor_1.ZodNumberEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
44
44
|
}
|
|
45
45
|
if (typeName === z.ZodFirstPartyTypeKind.ZodBoolean) {
|
|
46
|
-
return ((0, jsx_runtime_1.jsx)(ZodBooleanEditor_1.ZodBooleanEditor, { value: value, setValue: setValue, jsonPath: jsonPath, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(ZodBooleanEditor_1.ZodBooleanEditor, { value: value, setValue: setValue, jsonPath: jsonPath, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
47
47
|
}
|
|
48
48
|
if (typeName === z.ZodFirstPartyTypeKind.ZodUndefined) {
|
|
49
49
|
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, label: 'undefined', saving: saving }));
|
|
@@ -61,7 +61,7 @@ const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, o
|
|
|
61
61
|
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, label: 'unknown (not editable)', saving: saving }));
|
|
62
62
|
}
|
|
63
63
|
if (typeName === z.ZodFirstPartyTypeKind.ZodArray) {
|
|
64
|
-
return ((0, jsx_runtime_1.jsx)(ZodArrayEditor_1.ZodArrayEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
64
|
+
return ((0, jsx_runtime_1.jsx)(ZodArrayEditor_1.ZodArrayEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
65
65
|
}
|
|
66
66
|
if (typeName === z.ZodFirstPartyTypeKind.ZodEnum) {
|
|
67
67
|
return ((0, jsx_runtime_1.jsx)(ZodEnumEditor_1.ZodEnumEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
@@ -70,18 +70,18 @@ const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, o
|
|
|
70
70
|
if (zodTypes &&
|
|
71
71
|
schema._def.description ===
|
|
72
72
|
zodTypes.ZodZypesInternals.REMOTION_COLOR_BRAND) {
|
|
73
|
-
return ((0, jsx_runtime_1.jsx)(ZodColorEditor_1.ZodColorEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
73
|
+
return ((0, jsx_runtime_1.jsx)(ZodColorEditor_1.ZodColorEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
74
74
|
}
|
|
75
75
|
return ((0, jsx_runtime_1.jsx)(ZodEffectEditor_1.ZodEffectEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
76
76
|
}
|
|
77
77
|
if (typeName === z.ZodFirstPartyTypeKind.ZodUnion) {
|
|
78
|
-
return ((0, jsx_runtime_1.jsx)(ZodUnionEditor_1.ZodUnionEditor, { schema: schema, showSaveButton: showSaveButton, jsonPath: jsonPath, compact: compact, value: value, defaultValue: defaultValue, setValue: setValue, onSave: onSave, onRemove: onRemove, saving: saving }));
|
|
78
|
+
return ((0, jsx_runtime_1.jsx)(ZodUnionEditor_1.ZodUnionEditor, { schema: schema, showSaveButton: showSaveButton, jsonPath: jsonPath, compact: compact, value: value, defaultValue: defaultValue, setValue: setValue, onSave: onSave, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
79
79
|
}
|
|
80
80
|
if (typeName === z.ZodFirstPartyTypeKind.ZodOptional) {
|
|
81
|
-
return ((0, jsx_runtime_1.jsx)(ZodOptionalEditor_1.ZodOptionalEditor, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, defaultValue: defaultValue, value: value, setValue: setValue, onSave: onSave, onRemove: onRemove, schema: schema, saving: saving }));
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(ZodOptionalEditor_1.ZodOptionalEditor, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, defaultValue: defaultValue, value: value, setValue: setValue, onSave: onSave, onRemove: onRemove, schema: schema, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
82
82
|
}
|
|
83
83
|
if (typeName === z.ZodFirstPartyTypeKind.ZodNullable) {
|
|
84
|
-
return ((0, jsx_runtime_1.jsx)(ZodNullableEditor_1.ZodNullableEditor, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, defaultValue: defaultValue, value: value, setValue: setValue, onSave: onSave, onRemove: onRemove, schema: schema, saving: saving }));
|
|
84
|
+
return ((0, jsx_runtime_1.jsx)(ZodNullableEditor_1.ZodNullableEditor, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, defaultValue: defaultValue, value: value, setValue: setValue, onSave: onSave, onRemove: onRemove, schema: schema, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
85
85
|
}
|
|
86
86
|
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, label: `${typeName} (not editable)`, saving: saving }));
|
|
87
87
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodUnionEditor: React.FC<{
|
|
5
6
|
showSaveButton: boolean;
|
|
6
7
|
jsonPath: JSONPath;
|
|
@@ -8,8 +9,9 @@ export declare const ZodUnionEditor: React.FC<{
|
|
|
8
9
|
value: unknown;
|
|
9
10
|
defaultValue: unknown;
|
|
10
11
|
schema: z.ZodTypeAny;
|
|
11
|
-
setValue:
|
|
12
|
-
onSave:
|
|
12
|
+
setValue: UpdaterFunction<unknown>;
|
|
13
|
+
onSave: UpdaterFunction<unknown>;
|
|
13
14
|
onRemove: null | (() => void);
|
|
14
15
|
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
15
17
|
}>;
|
|
@@ -24,7 +24,7 @@ const findNull = (value, zodType) => {
|
|
|
24
24
|
otherSchemaIsAlsoNullish,
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
|
-
const ZodUnionEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, }) => {
|
|
27
|
+
const ZodUnionEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
28
28
|
const { options } = schema._def;
|
|
29
29
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
30
30
|
if (!z) {
|
|
@@ -44,6 +44,6 @@ const ZodUnionEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultVa
|
|
|
44
44
|
if (otherSchemaIsAlsoNullish) {
|
|
45
45
|
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Not editable - both union values are nullish', compact: compact, showSaveButton: showSaveButton, saving: saving }));
|
|
46
46
|
}
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: otherSchema, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: nullishValue, saving: saving }));
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: otherSchema, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: nullishValue, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
48
48
|
};
|
|
49
49
|
exports.ZodUnionEditor = ZodUnionEditor;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
3
|
+
declare type LocalState<T> = {
|
|
4
|
+
value: T;
|
|
5
|
+
zodValidation: z.SafeParseReturnType<unknown, unknown>;
|
|
6
|
+
revision: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const useLocalState: <T>({ value, schema, setValue, }: {
|
|
9
|
+
value: T;
|
|
10
|
+
schema: z.ZodTypeAny;
|
|
11
|
+
setValue: UpdaterFunction<T>;
|
|
12
|
+
}) => {
|
|
13
|
+
localValue: LocalState<T>;
|
|
14
|
+
onChange: (updater: (oldV: T) => T, forceApply: boolean) => void;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocalState = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useLocalState = ({ value, schema, setValue, }) => {
|
|
6
|
+
const [localValue, setLocalValue] = (0, react_1.useState)(() => {
|
|
7
|
+
return {
|
|
8
|
+
value,
|
|
9
|
+
zodValidation: schema.safeParse(value),
|
|
10
|
+
revision: 0,
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
const stateRef = (0, react_1.useRef)(localValue);
|
|
14
|
+
stateRef.current = localValue;
|
|
15
|
+
const onChange = (0, react_1.useCallback)((updater, forceApply) => {
|
|
16
|
+
const newValue = updater(stateRef.current.value);
|
|
17
|
+
const safeParse = schema.safeParse(newValue);
|
|
18
|
+
if (safeParse.success || forceApply) {
|
|
19
|
+
setValue(updater, forceApply);
|
|
20
|
+
setLocalValue((oldLocalState) => {
|
|
21
|
+
const newState = {
|
|
22
|
+
revision: oldLocalState.revision + 1,
|
|
23
|
+
value: newValue,
|
|
24
|
+
zodValidation: safeParse,
|
|
25
|
+
};
|
|
26
|
+
stateRef.current = newState;
|
|
27
|
+
return newState;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
setLocalValue((oldLocalState) => {
|
|
32
|
+
const newState = {
|
|
33
|
+
revision: oldLocalState.revision + 1,
|
|
34
|
+
value: newValue,
|
|
35
|
+
zodValidation: safeParse,
|
|
36
|
+
};
|
|
37
|
+
stateRef.current = newState;
|
|
38
|
+
return newState;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}, [schema, setValue]);
|
|
42
|
+
return { localValue, onChange };
|
|
43
|
+
};
|
|
44
|
+
exports.useLocalState = useLocalState;
|