@remotion/cli 4.0.0-alpha13 → 4.0.0-alpha16
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/ansi/ansi-diff.d.ts +1 -1
- package/dist/benchmark.js +29 -14
- package/dist/cleanup-before-quit.js +3 -0
- package/dist/composition-prompts.d.ts +2 -2
- package/dist/compositions.js +8 -7
- package/dist/config/concurrency.d.ts +1 -1
- package/dist/config/index.d.ts +2 -2
- package/dist/config/jpeg-quality.d.ts +1 -1
- package/dist/config/jpeg-quality.js +1 -1
- package/dist/config/number-of-gif-loops.d.ts +1 -1
- package/dist/config/override-webpack.d.ts +1 -1
- package/dist/config/scale.d.ts +1 -1
- package/dist/config/user-agent.d.ts +1 -1
- package/dist/editor/components/CanvasOrLoading.js +3 -0
- package/dist/editor/components/Checkbox.d.ts +1 -0
- package/dist/editor/components/Checkbox.js +2 -2
- package/dist/editor/components/CompositionSelectorItem.d.ts +1 -1
- package/dist/editor/components/InlineAction.d.ts +1 -1
- package/dist/editor/components/Menu/MenuItem.d.ts +2 -2
- package/dist/editor/components/Menu/MenuSubItem.d.ts +1 -1
- package/dist/editor/components/NewComposition/ComboBox.d.ts +4 -4
- package/dist/editor/components/NewComposition/CopyHint.js +1 -1
- package/dist/editor/components/NewComposition/InputDragger.d.ts +1 -1
- package/dist/editor/components/NewComposition/RemInput.d.ts +3 -3
- package/dist/editor/components/NewComposition/RemInputTypeColor.d.ts +2 -1
- package/dist/editor/components/NewComposition/RemInputTypeColor.js +1 -1
- package/dist/editor/components/NewComposition/RemTextarea.d.ts +1 -1
- package/dist/editor/components/Notifications/NotificationCenter.d.ts +2 -2
- package/dist/editor/components/QuickSwitcher/NoResults.d.ts +1 -1
- package/dist/editor/components/QuickSwitcher/QuickSwitcherResult.d.ts +2 -2
- package/dist/editor/components/RenderModal/DataEditor.d.ts +2 -3
- package/dist/editor/components/RenderModal/DataEditor.js +14 -5
- package/dist/editor/components/RenderModal/EnforceAudioTrackSetting.js +1 -1
- package/dist/editor/components/RenderModal/MutedSetting.js +1 -1
- package/dist/editor/components/RenderModal/RenderModal.d.ts +1 -1
- package/dist/editor/components/RenderModal/RenderModal.js +2 -2
- package/dist/editor/components/RenderModal/RenderModalAdvanced.d.ts +1 -1
- package/dist/editor/components/RenderModal/RenderModalAdvanced.js +1 -1
- package/dist/editor/components/RenderModal/RenderModalAudio.js +1 -1
- package/dist/editor/components/RenderModal/RenderModalGif.js +1 -1
- package/dist/editor/components/RenderModal/RenderModalInput.d.ts +1 -1
- package/dist/editor/components/RenderModal/RenderModalJSONPropsEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/RenderModalPicture.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/Fieldset.d.ts +7 -0
- package/dist/editor/components/RenderModal/SchemaEditor/Fieldset.js +26 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaEditor.d.ts +0 -1
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaEditor.js +2 -3
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.js +1 -3
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaLabel.d.ts +1 -7
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaLabel.js +14 -22
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaSeparationLine.d.ts +2 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaSeparationLine.js +11 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaVerticalGuide.d.ts +5 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaVerticalGuide.js +13 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.js +51 -42
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayItemEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayItemEditor.js +5 -5
- package/dist/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.d.ts +3 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.js +14 -13
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.js +12 -14
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDateEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDateEditor.js +9 -15
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDefaultEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDefaultEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.js +5 -30
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEnumEditor.d.ts +0 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEnumEditor.js +8 -11
- package/dist/editor/components/RenderModal/SchemaEditor/ZodFieldValidation.d.ts +7 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodFieldValidation.js +27 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNonEditableValue.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNonEditableValue.js +3 -3
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNullableEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNullableEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNumberEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNumberEditor.js +10 -13
- package/dist/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.js +39 -45
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOptionalEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOptionalEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +2 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.js +13 -48
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStaticFileEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStaticFileEditor.js +7 -10
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStringEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStringEditor.js +8 -11
- package/dist/editor/components/RenderModal/SchemaEditor/ZodSwitch.d.ts +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodSwitch.js +21 -21
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.js +6 -6
- package/dist/editor/components/RenderModal/SchemaEditor/deep-equal.js +3 -0
- package/dist/editor/components/RenderModal/SchemaEditor/extract-enum-json-paths.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/get-schema-label.js +3 -3
- package/dist/editor/components/RenderModal/SchemaEditor/input-props-serialization.d.ts +1 -1
- package/dist/editor/components/RenderModal/SchemaEditor/local-state.d.ts +10 -5
- package/dist/editor/components/RenderModal/SchemaEditor/local-state.js +56 -15
- package/dist/editor/components/RenderModal/SchemaEditor/zod-types.d.ts +1 -1
- package/dist/editor/components/RenderModal/get-render-modal-warnings.d.ts +1 -1
- package/dist/editor/components/RenderModal/layout.d.ts +0 -1
- package/dist/editor/components/RenderModal/layout.js +1 -7
- package/dist/editor/components/RenderQueue/actions.d.ts +2 -1
- package/dist/editor/components/RenderQueue/actions.js +7 -2
- package/dist/editor/components/RenderQueue/context.d.ts +1 -1
- package/dist/editor/components/RightPanel.d.ts +1 -1
- package/dist/editor/components/RightPanel.js +1 -1
- package/dist/editor/components/SegmentedControl.d.ts +1 -1
- package/dist/editor/components/SegmentedControl.js +2 -0
- package/dist/editor/components/Splitter/SplitterContext.d.ts +3 -3
- package/dist/editor/components/Timeline/LoopedIndicator.js +6 -6
- package/dist/editor/components/Timeline/TimelineWidthProvider.d.ts +1 -1
- package/dist/editor/components/Timeline/TimelineZoomControls.js +1 -1
- package/dist/editor/components/Timeline/timeline-state-reducer.d.ts +2 -2
- package/dist/editor/components/UpdateCheck.d.ts +1 -1
- package/dist/editor/components/UpdateCheck.js +2 -4
- package/dist/editor/components/get-zod-if-possible.d.ts +2 -2
- package/dist/editor/helpers/client-id.d.ts +1 -1
- package/dist/editor/helpers/colors.d.ts +1 -1
- package/dist/editor/helpers/get-timeline-sequence-sort-key.d.ts +3 -3
- package/dist/editor/helpers/persist-open-folders.d.ts +1 -1
- package/dist/editor/helpers/render-modal-sections.d.ts +1 -1
- package/dist/editor/helpers/use-menu-structure.d.ts +1 -1
- package/dist/editor/icons/plus.d.ts +3 -1
- package/dist/editor/icons/plus.js +2 -2
- package/dist/editor/state/checkerboard.d.ts +1 -1
- package/dist/editor/state/editor-zoom-gestures.d.ts +1 -1
- package/dist/editor/state/folders.d.ts +1 -1
- package/dist/editor/state/highest-z-index.d.ts +1 -1
- package/dist/editor/state/in-out.d.ts +2 -2
- package/dist/editor/state/keybindings.d.ts +4 -4
- package/dist/editor/state/modals.d.ts +4 -4
- package/dist/editor/state/preview-size.d.ts +1 -1
- package/dist/editor/state/sidebar.d.ts +3 -3
- package/dist/editor/state/timeline-ref.d.ts +1 -1
- package/dist/event-source-events.d.ts +1 -1
- package/dist/file-watcher.d.ts +1 -1
- package/dist/get-cli-options.d.ts +1 -1
- package/dist/get-composition-id.d.ts +10 -11
- package/dist/get-composition-id.js +9 -6
- package/dist/get-composition-with-dimension-override.d.ts +4 -4
- package/dist/get-composition-with-dimension-override.js +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/log.d.ts +1 -0
- package/dist/parse-command-line.d.ts +1 -1
- package/dist/preview-server/api-routes.js +2 -0
- package/dist/preview-server/api-types.d.ts +5 -4
- package/dist/preview-server/dev-middleware/get-paths.d.ts +1 -1
- package/dist/preview-server/dev-middleware/middleware.d.ts +1 -1
- package/dist/preview-server/dev-middleware/range-parser.d.ts +2 -2
- package/dist/preview-server/dev-middleware/types.d.ts +1 -1
- package/dist/preview-server/error-overlay/react-overlay/effects/map-error-to-react-stack.d.ts +1 -1
- package/dist/preview-server/error-overlay/react-overlay/effects/proxy-console.d.ts +3 -3
- package/dist/preview-server/error-overlay/react-overlay/effects/unhandled-error.d.ts +1 -1
- package/dist/preview-server/error-overlay/react-overlay/effects/unhandled-rejection.d.ts +1 -1
- package/dist/preview-server/error-overlay/react-overlay/listen-to-runtime-errors.d.ts +1 -1
- package/dist/preview-server/error-overlay/react-overlay/utils/get-source-map.js +1 -0
- package/dist/preview-server/error-overlay/react-overlay/utils/open-in-editor.d.ts +2 -2
- package/dist/preview-server/error-overlay/react-overlay/utils/stack-frame.d.ts +4 -4
- package/dist/preview-server/error-overlay/remotion-overlay/ErrorDisplay.d.ts +1 -1
- package/dist/preview-server/error-overlay/remotion-overlay/Overlay.d.ts +2 -2
- package/dist/preview-server/error-overlay/remotion-overlay/get-help-link.d.ts +1 -1
- package/dist/preview-server/get-package-manager.d.ts +2 -2
- package/dist/preview-server/hot-middleware/client.d.ts +1 -1
- package/dist/preview-server/hot-middleware/types.d.ts +4 -4
- package/dist/preview-server/live-events.d.ts +1 -1
- package/dist/preview-server/live-events.js +10 -1
- package/dist/preview-server/project-info.d.ts +1 -1
- package/dist/preview-server/render-queue/job.d.ts +30 -21
- package/dist/preview-server/render-queue/process-still.js +1 -2
- package/dist/preview-server/routes/update-available.d.ts +3 -0
- package/dist/preview-server/routes/update-available.js +9 -0
- package/dist/preview-server/routes.js +1 -11
- package/dist/preview-server/update-available.d.ts +2 -10
- package/dist/progress-bar.d.ts +4 -4
- package/dist/progress-bar.js +3 -2
- package/dist/progress-types.d.ts +4 -4
- package/dist/render-flows/render.js +35 -28
- package/dist/render-flows/still.d.ts +1 -1
- package/dist/render-flows/still.js +23 -10
- package/dist/required-chromium-options.d.ts +2 -2
- package/dist/server-ready-comment.d.ts +1 -1
- package/dist/server-ready-comment.js +2 -2
- package/dist/setup-cache.js +10 -0
- package/dist/show-compositions-picker.d.ts +1 -1
- package/dist/step.d.ts +1 -1
- package/dist/studio.js +3 -3
- package/dist/truthy.d.ts +1 -1
- package/package.json +10 -12
|
@@ -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,
|
|
6
|
+
const ZodOptionalEditor = ({ jsonPath, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
|
|
7
7
|
const { innerType } = schema._def;
|
|
8
|
-
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, {
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: schema, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: undefined, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad, innerSchema: innerType }));
|
|
9
9
|
};
|
|
10
10
|
exports.ZodOptionalEditor = ZodOptionalEditor;
|
|
@@ -5,14 +5,15 @@ import type { UpdaterFunction } from './ZodSwitch';
|
|
|
5
5
|
export declare const ZodOrNullishEditor: React.FC<{
|
|
6
6
|
showSaveButton: boolean;
|
|
7
7
|
jsonPath: JSONPath;
|
|
8
|
-
compact: boolean;
|
|
9
8
|
value: unknown;
|
|
10
9
|
defaultValue: unknown;
|
|
11
10
|
schema: z.ZodTypeAny;
|
|
11
|
+
innerSchema: z.ZodTypeAny;
|
|
12
12
|
setValue: UpdaterFunction<unknown>;
|
|
13
13
|
onSave: UpdaterFunction<unknown>;
|
|
14
14
|
onRemove: null | (() => void);
|
|
15
15
|
nullishValue: null | undefined;
|
|
16
16
|
saving: boolean;
|
|
17
17
|
saveDisabledByParent: boolean;
|
|
18
|
+
mayPad: boolean;
|
|
18
19
|
}>;
|
|
@@ -10,76 +10,41 @@ const layout_1 = require("../../layout");
|
|
|
10
10
|
const create_zod_values_1 = require("./create-zod-values");
|
|
11
11
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
12
12
|
const ZodSwitch_1 = require("./ZodSwitch");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
};
|
|
13
|
+
const Fieldset_1 = require("./Fieldset");
|
|
14
|
+
const local_state_1 = require("./local-state");
|
|
16
15
|
const labelStyle = {
|
|
17
16
|
fontFamily: 'sans-serif',
|
|
18
17
|
fontSize: 14,
|
|
19
18
|
color: colors_1.LIGHT_TEXT,
|
|
20
19
|
};
|
|
21
20
|
const checkBoxWrapper = {
|
|
22
|
-
margin: '2px',
|
|
23
21
|
display: 'flex',
|
|
24
22
|
flexDirection: 'row',
|
|
25
23
|
alignItems: 'center',
|
|
26
24
|
marginTop: '5px',
|
|
27
25
|
};
|
|
28
|
-
const ZodOrNullishEditor = ({ jsonPath,
|
|
26
|
+
const ZodOrNullishEditor = ({ jsonPath, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, nullishValue, saving, saveDisabledByParent, mayPad, innerSchema, }) => {
|
|
29
27
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
30
28
|
if (!z) {
|
|
31
29
|
throw new Error('expected zod');
|
|
32
30
|
}
|
|
33
31
|
const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
|
|
34
32
|
const isChecked = value === nullishValue;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
: schema.safeParse(value),
|
|
41
|
-
};
|
|
33
|
+
const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
|
|
34
|
+
schema,
|
|
35
|
+
setValue,
|
|
36
|
+
value,
|
|
37
|
+
defaultValue,
|
|
42
38
|
});
|
|
43
|
-
const onValueChange = (0, react_1.useCallback)((updater) => {
|
|
44
|
-
setLocalNonNullishValue((oldState) => {
|
|
45
|
-
const newValue = updater(oldState.value);
|
|
46
|
-
if (newValue === nullishValue) {
|
|
47
|
-
return oldState;
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
value: newValue,
|
|
51
|
-
zodValidation: schema.safeParse(newValue),
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
setValue(updater, false);
|
|
55
|
-
}, [nullishValue, schema, setValue]);
|
|
56
39
|
const onCheckBoxChange = (0, react_1.useCallback)((e) => {
|
|
57
40
|
const val = e.target.checked
|
|
58
41
|
? nullishValue
|
|
59
|
-
:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (val !== nullishValue) {
|
|
63
|
-
setLocalNonNullishValue({
|
|
64
|
-
value: val,
|
|
65
|
-
zodValidation: schema.safeParse(val),
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
onValueChange(() => val, false);
|
|
69
|
-
}, [
|
|
70
|
-
localNonNullishValueValue,
|
|
71
|
-
nullishValue,
|
|
72
|
-
onValueChange,
|
|
73
|
-
schema,
|
|
74
|
-
z,
|
|
75
|
-
zodTypes,
|
|
76
|
-
]);
|
|
77
|
-
const reset = (0, react_1.useCallback)(() => {
|
|
78
|
-
onValueChange(() => defaultValue, true);
|
|
79
|
-
}, [defaultValue, onValueChange]);
|
|
42
|
+
: (0, create_zod_values_1.createZodValues)(innerSchema, z, zodTypes);
|
|
43
|
+
setLocalValue(() => val, false, false);
|
|
44
|
+
}, [innerSchema, nullishValue, setLocalValue, z, zodTypes]);
|
|
80
45
|
const save = (0, react_1.useCallback)(() => {
|
|
81
|
-
onSave(() => value, false);
|
|
46
|
+
onSave(() => value, false, false);
|
|
82
47
|
}, [onSave, value]);
|
|
83
|
-
return ((0, jsx_runtime_1.jsxs)(
|
|
48
|
+
return ((0, jsx_runtime_1.jsxs)(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [localValue.value === nullishValue ? ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null })) : ((0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { value: localValue.value, setValue: setLocalValue, jsonPath: jsonPath, schema: innerSchema, defaultValue: value, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: false })), (0, jsx_runtime_1.jsxs)("div", { style: checkBoxWrapper, children: [(0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { checked: isChecked, onChange: onCheckBoxChange, disabled: false, name: jsonPath.join('.') }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)("div", { style: labelStyle, children: String(nullishValue) })] })] }));
|
|
84
49
|
};
|
|
85
50
|
exports.ZodOrNullishEditor = ZodOrNullishEditor;
|
|
@@ -9,9 +9,9 @@ export declare const ZodStaticFileEditor: React.FC<{
|
|
|
9
9
|
defaultValue: string;
|
|
10
10
|
setValue: UpdaterFunction<string>;
|
|
11
11
|
onSave: (updater: (oldState: string) => string) => void;
|
|
12
|
-
compact: boolean;
|
|
13
12
|
showSaveButton: boolean;
|
|
14
13
|
onRemove: null | (() => void);
|
|
15
14
|
saving: boolean;
|
|
16
15
|
saveDisabledByParent: boolean;
|
|
16
|
+
mayPad: boolean;
|
|
17
17
|
}>;
|
|
@@ -6,24 +6,24 @@ const react_1 = require("react");
|
|
|
6
6
|
const remotion_1 = require("remotion");
|
|
7
7
|
const Checkmark_1 = require("../../../icons/Checkmark");
|
|
8
8
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
9
|
-
const layout_1 = require("../../layout");
|
|
10
9
|
const ComboBox_1 = require("../../NewComposition/ComboBox");
|
|
11
|
-
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
12
|
-
const layout_2 = require("../layout");
|
|
13
10
|
const local_state_1 = require("./local-state");
|
|
14
11
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
12
|
+
const Fieldset_1 = require("./Fieldset");
|
|
13
|
+
const ZodFieldValidation_1 = require("./ZodFieldValidation");
|
|
15
14
|
const container = {
|
|
16
15
|
width: '100%',
|
|
17
16
|
};
|
|
18
|
-
const ZodStaticFileEditor = ({ schema, jsonPath,
|
|
17
|
+
const ZodStaticFileEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
|
|
19
18
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
20
19
|
if (!z) {
|
|
21
20
|
throw new Error('expected zod');
|
|
22
21
|
}
|
|
23
|
-
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
22
|
+
const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
|
|
24
23
|
schema,
|
|
25
24
|
setValue,
|
|
26
25
|
value,
|
|
26
|
+
defaultValue,
|
|
27
27
|
});
|
|
28
28
|
const def = schema._def;
|
|
29
29
|
const typeName = def.typeName;
|
|
@@ -31,9 +31,6 @@ const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue, defaultValue
|
|
|
31
31
|
throw new Error('expected enum');
|
|
32
32
|
}
|
|
33
33
|
const isRoot = jsonPath.length === 0;
|
|
34
|
-
const reset = (0, react_1.useCallback)(() => {
|
|
35
|
-
setLocalValue(() => defaultValue, true);
|
|
36
|
-
}, [defaultValue, setLocalValue]);
|
|
37
34
|
const comboBoxValues = (0, react_1.useMemo)(() => {
|
|
38
35
|
return (0, remotion_1.getStaticFiles)().map((option) => {
|
|
39
36
|
return {
|
|
@@ -43,7 +40,7 @@ const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue, defaultValue
|
|
|
43
40
|
keyHint: null,
|
|
44
41
|
leftItem: option.src === value ? (0, jsx_runtime_1.jsx)(Checkmark_1.Checkmark, {}) : null,
|
|
45
42
|
onClick: (id) => {
|
|
46
|
-
setLocalValue(() => id, false);
|
|
43
|
+
setLocalValue(() => id, false, false);
|
|
47
44
|
},
|
|
48
45
|
quickSwitcherLabel: null,
|
|
49
46
|
subMenu: null,
|
|
@@ -54,6 +51,6 @@ const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue, defaultValue
|
|
|
54
51
|
const save = (0, react_1.useCallback)(() => {
|
|
55
52
|
onSave(() => value);
|
|
56
53
|
}, [onSave, value]);
|
|
57
|
-
return ((0, jsx_runtime_1.jsxs)(
|
|
54
|
+
return ((0, jsx_runtime_1.jsxs)(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { onSave: save, showSaveButton: showSaveButton, isDefaultValue: localValue.value === defaultValue, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), (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 }) }), (0, jsx_runtime_1.jsx)(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })] }));
|
|
58
55
|
};
|
|
59
56
|
exports.ZodStaticFileEditor = ZodStaticFileEditor;
|
|
@@ -10,8 +10,8 @@ export declare const ZodStringEditor: React.FC<{
|
|
|
10
10
|
setValue: UpdaterFunction<string>;
|
|
11
11
|
onSave: UpdaterFunction<string>;
|
|
12
12
|
onRemove: null | (() => void);
|
|
13
|
-
compact: boolean;
|
|
14
13
|
showSaveButton: boolean;
|
|
15
14
|
saving: boolean;
|
|
16
15
|
saveDisabledByParent: boolean;
|
|
16
|
+
mayPad: boolean;
|
|
17
17
|
}>;
|
|
@@ -4,34 +4,31 @@ exports.ZodStringEditor = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
7
|
-
const layout_1 = require("../../layout");
|
|
8
7
|
const RemInput_1 = require("../../NewComposition/RemInput");
|
|
9
|
-
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
10
|
-
const layout_2 = require("../layout");
|
|
11
8
|
const local_state_1 = require("./local-state");
|
|
12
9
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
10
|
+
const Fieldset_1 = require("./Fieldset");
|
|
11
|
+
const ZodFieldValidation_1 = require("./ZodFieldValidation");
|
|
13
12
|
const fullWidth = {
|
|
14
13
|
width: '100%',
|
|
15
14
|
};
|
|
16
|
-
const ZodStringEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema,
|
|
15
|
+
const ZodStringEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, onSave, onRemove, saving, saveDisabledByParent, mayPad, }) => {
|
|
17
16
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
18
17
|
if (!z) {
|
|
19
18
|
throw new Error('expected zod');
|
|
20
19
|
}
|
|
21
|
-
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
20
|
+
const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
|
|
22
21
|
schema,
|
|
23
22
|
setValue,
|
|
24
23
|
value,
|
|
24
|
+
defaultValue,
|
|
25
25
|
});
|
|
26
26
|
const onChange = (0, react_1.useCallback)((e) => {
|
|
27
|
-
setLocalValue(() => e.target.value, false);
|
|
27
|
+
setLocalValue(() => e.target.value, false, false);
|
|
28
28
|
}, [setLocalValue]);
|
|
29
|
-
const reset = (0, react_1.useCallback)(() => {
|
|
30
|
-
setLocalValue(() => defaultValue, true);
|
|
31
|
-
}, [defaultValue, setLocalValue]);
|
|
32
29
|
const save = (0, react_1.useCallback)(() => {
|
|
33
|
-
onSave(() => value, false);
|
|
30
|
+
onSave(() => value, false, false);
|
|
34
31
|
}, [onSave, value]);
|
|
35
|
-
return ((0, jsx_runtime_1.jsxs)(
|
|
32
|
+
return ((0, jsx_runtime_1.jsxs)(Fieldset_1.Fieldset, { shouldPad: mayPad, success: false, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), (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, name: jsonPath.join('.') }), (0, jsx_runtime_1.jsx)(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })] })] }));
|
|
36
33
|
};
|
|
37
34
|
exports.ZodStringEditor = ZodStringEditor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
-
export
|
|
4
|
+
export type UpdaterFunction<T> = (updater: (oldValue: T) => T, forceApply: boolean, increment: boolean) => void;
|
|
5
5
|
export declare const ZodSwitch: React.FC<{
|
|
6
6
|
schema: z.ZodTypeAny;
|
|
7
7
|
jsonPath: JSONPath;
|
|
@@ -9,9 +9,9 @@ export declare const ZodSwitch: React.FC<{
|
|
|
9
9
|
defaultValue: unknown;
|
|
10
10
|
setValue: UpdaterFunction<unknown>;
|
|
11
11
|
onSave: UpdaterFunction<unknown>;
|
|
12
|
-
compact: boolean;
|
|
13
12
|
showSaveButton: boolean;
|
|
14
13
|
onRemove: null | (() => void);
|
|
15
14
|
saving: boolean;
|
|
16
15
|
saveDisabledByParent: boolean;
|
|
16
|
+
mayPad: boolean;
|
|
17
17
|
}>;
|
|
@@ -18,7 +18,7 @@ const ZodOptionalEditor_1 = require("./ZodOptionalEditor");
|
|
|
18
18
|
const ZodStaticFileEditor_1 = require("./ZodStaticFileEditor");
|
|
19
19
|
const ZodStringEditor_1 = require("./ZodStringEditor");
|
|
20
20
|
const ZodUnionEditor_1 = require("./ZodUnionEditor");
|
|
21
|
-
const ZodSwitch = ({ schema, jsonPath,
|
|
21
|
+
const ZodSwitch = ({ schema, jsonPath, value, setValue, defaultValue, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
|
|
22
22
|
const def = schema._def;
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
24
|
const typeName = def.typeName;
|
|
@@ -29,64 +29,64 @@ const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, o
|
|
|
29
29
|
const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
|
|
30
30
|
// TODO: (Maybe?) enable saving of inserted input props by cmd+s /ctrl + s (also for JSON view)
|
|
31
31
|
if (typeName === z.ZodFirstPartyTypeKind.ZodObject) {
|
|
32
|
-
return ((0, jsx_runtime_1.jsx)(ZodObjectEditor_1.ZodObjectEditor, { setValue: setValue, value: value, defaultValue: defaultValue, jsonPath: jsonPath, schema: schema,
|
|
32
|
+
return ((0, jsx_runtime_1.jsx)(ZodObjectEditor_1.ZodObjectEditor, { setValue: setValue, value: value, defaultValue: defaultValue, jsonPath: jsonPath, schema: schema, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
33
33
|
}
|
|
34
34
|
if (typeName === z.ZodFirstPartyTypeKind.ZodString) {
|
|
35
35
|
if (value.startsWith(window.remotion_staticBase)) {
|
|
36
|
-
return ((0, jsx_runtime_1.jsx)(ZodStaticFileEditor_1.ZodStaticFileEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema,
|
|
36
|
+
return ((0, jsx_runtime_1.jsx)(ZodStaticFileEditor_1.ZodStaticFileEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
37
37
|
}
|
|
38
|
-
return ((0, jsx_runtime_1.jsx)(ZodStringEditor_1.ZodStringEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema,
|
|
38
|
+
return ((0, jsx_runtime_1.jsx)(ZodStringEditor_1.ZodStringEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
39
39
|
}
|
|
40
40
|
if (typeName === z.ZodFirstPartyTypeKind.ZodDate) {
|
|
41
|
-
return ((0, jsx_runtime_1.jsx)(ZodDateEditor_1.ZodDateEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema,
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(ZodDateEditor_1.ZodDateEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
42
42
|
}
|
|
43
43
|
if (typeName === z.ZodFirstPartyTypeKind.ZodNumber) {
|
|
44
|
-
return ((0, jsx_runtime_1.jsx)(ZodNumberEditor_1.ZodNumberEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema,
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(ZodNumberEditor_1.ZodNumberEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
45
45
|
}
|
|
46
46
|
if (typeName === z.ZodFirstPartyTypeKind.ZodBoolean) {
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)(ZodBooleanEditor_1.ZodBooleanEditor, { value: value, setValue: setValue, jsonPath: jsonPath,
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(ZodBooleanEditor_1.ZodBooleanEditor, { value: value, setValue: setValue, jsonPath: jsonPath, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad, schema: schema }));
|
|
48
48
|
}
|
|
49
49
|
if (typeName === z.ZodFirstPartyTypeKind.ZodUndefined) {
|
|
50
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, {
|
|
50
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, showSaveButton: showSaveButton, label: 'undefined', saving: saving, mayPad: mayPad }));
|
|
51
51
|
}
|
|
52
52
|
if (typeName === z.ZodFirstPartyTypeKind.ZodNull) {
|
|
53
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, {
|
|
53
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, showSaveButton: showSaveButton, label: 'null', saving: saving, mayPad: mayPad }));
|
|
54
54
|
}
|
|
55
55
|
if (typeName === z.ZodFirstPartyTypeKind.ZodAny) {
|
|
56
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, {
|
|
56
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, showSaveButton: showSaveButton, label: 'any (not editable)', saving: saving, mayPad: mayPad }));
|
|
57
57
|
}
|
|
58
58
|
if (typeName === z.ZodFirstPartyTypeKind.ZodBigInt) {
|
|
59
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, {
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, showSaveButton: showSaveButton, label: 'BigInt (not editable)', saving: saving, mayPad: mayPad }));
|
|
60
60
|
}
|
|
61
61
|
if (typeName === z.ZodFirstPartyTypeKind.ZodUnknown) {
|
|
62
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, {
|
|
62
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, showSaveButton: showSaveButton, label: 'unknown (not editable)', saving: saving, mayPad: mayPad }));
|
|
63
63
|
}
|
|
64
64
|
if (typeName === z.ZodFirstPartyTypeKind.ZodArray) {
|
|
65
|
-
return ((0, jsx_runtime_1.jsx)(ZodArrayEditor_1.ZodArrayEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema,
|
|
65
|
+
return ((0, jsx_runtime_1.jsx)(ZodArrayEditor_1.ZodArrayEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
66
66
|
}
|
|
67
67
|
if (typeName === z.ZodFirstPartyTypeKind.ZodEnum) {
|
|
68
|
-
return ((0, jsx_runtime_1.jsx)(ZodEnumEditor_1.ZodEnumEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema,
|
|
68
|
+
return ((0, jsx_runtime_1.jsx)(ZodEnumEditor_1.ZodEnumEditor, { setValue: setValue, value: value, jsonPath: jsonPath, schema: schema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving }));
|
|
69
69
|
}
|
|
70
70
|
if (typeName === z.ZodFirstPartyTypeKind.ZodEffects) {
|
|
71
71
|
if (zodTypes &&
|
|
72
72
|
schema._def.description ===
|
|
73
73
|
zodTypes.ZodZypesInternals.REMOTION_COLOR_BRAND) {
|
|
74
|
-
return ((0, jsx_runtime_1.jsx)(ZodColorEditor_1.ZodColorEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema,
|
|
74
|
+
return ((0, jsx_runtime_1.jsx)(ZodColorEditor_1.ZodColorEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, onSave: onSave, defaultValue: defaultValue, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
75
75
|
}
|
|
76
|
-
return ((0, jsx_runtime_1.jsx)(ZodEffectEditor_1.ZodEffectEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema,
|
|
76
|
+
return ((0, jsx_runtime_1.jsx)(ZodEffectEditor_1.ZodEffectEditor, { value: value, setValue: setValue, jsonPath: jsonPath, schema: schema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, mayPad: mayPad }));
|
|
77
77
|
}
|
|
78
78
|
if (typeName === z.ZodFirstPartyTypeKind.ZodUnion) {
|
|
79
|
-
return ((0, jsx_runtime_1.jsx)(ZodUnionEditor_1.ZodUnionEditor, { schema: schema, showSaveButton: showSaveButton, jsonPath: jsonPath,
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(ZodUnionEditor_1.ZodUnionEditor, { schema: schema, showSaveButton: showSaveButton, jsonPath: jsonPath, value: value, defaultValue: defaultValue, setValue: setValue, onSave: onSave, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
80
80
|
}
|
|
81
81
|
if (typeName === z.ZodFirstPartyTypeKind.ZodOptional) {
|
|
82
|
-
return ((0, jsx_runtime_1.jsx)(ZodOptionalEditor_1.ZodOptionalEditor, {
|
|
82
|
+
return ((0, jsx_runtime_1.jsx)(ZodOptionalEditor_1.ZodOptionalEditor, { jsonPath: jsonPath, showSaveButton: showSaveButton, defaultValue: defaultValue, value: value, setValue: setValue, onSave: onSave, onRemove: onRemove, schema: schema, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
83
83
|
}
|
|
84
84
|
if (typeName === z.ZodFirstPartyTypeKind.ZodNullable) {
|
|
85
|
-
return ((0, jsx_runtime_1.jsx)(ZodNullableEditor_1.ZodNullableEditor, {
|
|
85
|
+
return ((0, jsx_runtime_1.jsx)(ZodNullableEditor_1.ZodNullableEditor, { jsonPath: jsonPath, showSaveButton: showSaveButton, defaultValue: defaultValue, value: value, setValue: setValue, onSave: onSave, onRemove: onRemove, schema: schema, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
86
86
|
}
|
|
87
87
|
if (typeName === z.ZodFirstPartyTypeKind.ZodDefault) {
|
|
88
|
-
return ((0, jsx_runtime_1.jsx)(ZodDefaultEditor_1.ZodDefaultEditor, {
|
|
88
|
+
return ((0, jsx_runtime_1.jsx)(ZodDefaultEditor_1.ZodDefaultEditor, { jsonPath: jsonPath, showSaveButton: showSaveButton, defaultValue: defaultValue, value: value, setValue: setValue, onSave: onSave, onRemove: onRemove, schema: schema, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
89
89
|
}
|
|
90
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, {
|
|
90
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, showSaveButton: showSaveButton, label: `${typeName} (not editable)`, saving: saving, mayPad: mayPad }));
|
|
91
91
|
};
|
|
92
92
|
exports.ZodSwitch = ZodSwitch;
|
|
@@ -5,7 +5,6 @@ import type { UpdaterFunction } from './ZodSwitch';
|
|
|
5
5
|
export declare const ZodUnionEditor: React.FC<{
|
|
6
6
|
showSaveButton: boolean;
|
|
7
7
|
jsonPath: JSONPath;
|
|
8
|
-
compact: boolean;
|
|
9
8
|
value: unknown;
|
|
10
9
|
defaultValue: unknown;
|
|
11
10
|
schema: z.ZodTypeAny;
|
|
@@ -14,4 +13,5 @@ export declare const ZodUnionEditor: React.FC<{
|
|
|
14
13
|
onRemove: null | (() => void);
|
|
15
14
|
saving: boolean;
|
|
16
15
|
saveDisabledByParent: boolean;
|
|
16
|
+
mayPad: boolean;
|
|
17
17
|
}>;
|
|
@@ -24,26 +24,26 @@ const findNull = (value, zodType) => {
|
|
|
24
24
|
otherSchemaIsAlsoNullish,
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
|
-
const ZodUnionEditor = ({ jsonPath,
|
|
27
|
+
const ZodUnionEditor = ({ jsonPath, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
|
|
28
28
|
const { options } = schema._def;
|
|
29
29
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
30
30
|
if (!z) {
|
|
31
31
|
throw new Error('expected zod');
|
|
32
32
|
}
|
|
33
33
|
if (options.length > 2) {
|
|
34
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union with more than 2 options not editable',
|
|
34
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union with more than 2 options not editable', showSaveButton: showSaveButton, saving: saving, mayPad: mayPad }));
|
|
35
35
|
}
|
|
36
36
|
if (options.length < 2) {
|
|
37
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union with less than 2 options not editable',
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union with less than 2 options not editable', showSaveButton: showSaveButton, saving: saving, mayPad: mayPad }));
|
|
38
38
|
}
|
|
39
39
|
const nullResult = findNull(options, z);
|
|
40
40
|
if (!nullResult) {
|
|
41
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union only editable with 1 value being null',
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union only editable with 1 value being null', showSaveButton: showSaveButton, saving: saving, mayPad: mayPad }));
|
|
42
42
|
}
|
|
43
43
|
const { otherSchema, nullishValue, otherSchemaIsAlsoNullish } = nullResult;
|
|
44
44
|
if (otherSchemaIsAlsoNullish) {
|
|
45
|
-
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Not editable - both union values are nullish',
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Not editable - both union values are nullish', showSaveButton: showSaveButton, saving: saving, mayPad: mayPad }));
|
|
46
46
|
}
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, {
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: schema, innerSchema: otherSchema, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: nullishValue, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
|
|
48
48
|
};
|
|
49
49
|
exports.ZodUnionEditor = ZodUnionEditor;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodType } from '../../get-zod-if-possible';
|
|
2
|
-
export
|
|
2
|
+
export type EnumPath = (string | number)[];
|
|
3
3
|
export declare const extractEnumJsonPaths: (schema: Zod.ZodTypeAny, zodRuntime: ZodType, currentPath: (string | number)[]) => (string | number)[][];
|
|
@@ -6,10 +6,10 @@ const getSchemaLabel = (jsonPath) => {
|
|
|
6
6
|
if (typeof lastKey === 'number') {
|
|
7
7
|
const secondLastKey = jsonPath[jsonPath.length - 2];
|
|
8
8
|
if (typeof secondLastKey === 'undefined') {
|
|
9
|
-
return `[${lastKey}]
|
|
9
|
+
return `[${lastKey}]:`;
|
|
10
10
|
}
|
|
11
|
-
return `${
|
|
11
|
+
return `${lastKey}:`;
|
|
12
12
|
}
|
|
13
|
-
return lastKey
|
|
13
|
+
return `${lastKey}:`;
|
|
14
14
|
};
|
|
15
15
|
exports.getSchemaLabel = getSchemaLabel;
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { z } from 'zod';
|
|
2
3
|
import type { UpdaterFunction } from './ZodSwitch';
|
|
3
|
-
|
|
4
|
+
export type LocalState<T> = {
|
|
4
5
|
value: T;
|
|
5
6
|
zodValidation: z.SafeParseReturnType<unknown, unknown>;
|
|
6
|
-
|
|
7
|
+
keyStabilityRevision: number;
|
|
7
8
|
};
|
|
8
|
-
export declare const useLocalState: <T>({ value, schema, setValue, }: {
|
|
9
|
+
export declare const useLocalState: <T>({ value, schema, setValue, defaultValue, }: {
|
|
9
10
|
value: T;
|
|
10
11
|
schema: z.ZodTypeAny;
|
|
11
12
|
setValue: UpdaterFunction<T>;
|
|
13
|
+
defaultValue: T;
|
|
12
14
|
}) => {
|
|
13
15
|
localValue: LocalState<T>;
|
|
14
|
-
onChange: (updater: (oldV: T) => T, forceApply: boolean) => void;
|
|
16
|
+
onChange: (updater: (oldV: T) => T, forceApply: boolean, increment: boolean) => void;
|
|
17
|
+
reset: () => void;
|
|
18
|
+
RevisionContextProvider: ({ children }: {
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
}) => JSX.Element;
|
|
15
21
|
};
|
|
16
|
-
export {};
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLocalState = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const deep_equal_1 = require("./deep-equal");
|
|
6
|
-
const
|
|
7
|
+
const RevisionContext = (0, react_1.createContext)({
|
|
8
|
+
childResetRevision: 0,
|
|
9
|
+
});
|
|
10
|
+
const useLocalState = ({ value, schema, setValue, defaultValue, }) => {
|
|
11
|
+
const parentRevision = (0, react_1.useContext)(RevisionContext).childResetRevision;
|
|
12
|
+
const [resetRevision, setResetRevision] = (0, react_1.useState)(0);
|
|
7
13
|
const [localValue, setLocalValue] = (0, react_1.useState)(() => {
|
|
8
|
-
return {
|
|
9
|
-
value,
|
|
10
|
-
zodValidation: schema.safeParse(value),
|
|
11
|
-
revision: 0,
|
|
12
|
-
};
|
|
14
|
+
return {};
|
|
13
15
|
});
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const currentLocalValue = (0, react_1.useMemo)(() => {
|
|
17
|
+
var _a;
|
|
18
|
+
return ((_a = localValue[parentRevision]) !== null && _a !== void 0 ? _a : {
|
|
19
|
+
value: defaultValue,
|
|
20
|
+
keyStabilityRevision: 0,
|
|
21
|
+
zodValidation: schema.safeParse(value),
|
|
22
|
+
});
|
|
23
|
+
}, [defaultValue, localValue, parentRevision, schema, value]);
|
|
24
|
+
const stateRef = (0, react_1.useRef)(currentLocalValue);
|
|
25
|
+
stateRef.current = currentLocalValue;
|
|
26
|
+
const onChange = (0, react_1.useCallback)(
|
|
27
|
+
// Increment is to regenerate `key` attributes in array items,
|
|
28
|
+
// so should increment when changing array items
|
|
29
|
+
(updater, forceApply, increment) => {
|
|
17
30
|
const newValue = updater(stateRef.current.value);
|
|
18
31
|
const isSame = (0, deep_equal_1.deepEqual)(newValue, stateRef.current.value);
|
|
19
32
|
if (isSame) {
|
|
@@ -21,18 +34,46 @@ const useLocalState = ({ value, schema, setValue, }) => {
|
|
|
21
34
|
}
|
|
22
35
|
const safeParse = schema.safeParse(newValue);
|
|
23
36
|
if (safeParse.success || forceApply) {
|
|
24
|
-
setValue(updater, forceApply);
|
|
37
|
+
setValue(updater, forceApply, increment);
|
|
25
38
|
}
|
|
26
|
-
setLocalValue((
|
|
39
|
+
setLocalValue(() => {
|
|
27
40
|
const newState = {
|
|
28
|
-
|
|
41
|
+
keyStabilityRevision: currentLocalValue.keyStabilityRevision + (increment ? 1 : 0),
|
|
29
42
|
value: newValue,
|
|
30
43
|
zodValidation: safeParse,
|
|
31
44
|
};
|
|
32
45
|
stateRef.current = newState;
|
|
33
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
...localValue,
|
|
48
|
+
[parentRevision]: newState,
|
|
49
|
+
};
|
|
34
50
|
});
|
|
35
|
-
}, [
|
|
36
|
-
|
|
51
|
+
}, [
|
|
52
|
+
currentLocalValue.keyStabilityRevision,
|
|
53
|
+
localValue,
|
|
54
|
+
parentRevision,
|
|
55
|
+
schema,
|
|
56
|
+
setValue,
|
|
57
|
+
]);
|
|
58
|
+
const contextValue = (0, react_1.useMemo)(() => {
|
|
59
|
+
return {
|
|
60
|
+
childResetRevision: resetRevision,
|
|
61
|
+
};
|
|
62
|
+
}, [resetRevision]);
|
|
63
|
+
const reset = (0, react_1.useCallback)(() => {
|
|
64
|
+
// Only need to do key stability for arrays, but
|
|
65
|
+
// since user is not editing right now, should be fine
|
|
66
|
+
onChange(() => defaultValue, true, true);
|
|
67
|
+
setResetRevision((old) => old + 1);
|
|
68
|
+
}, [defaultValue, onChange]);
|
|
69
|
+
const RevisionContextProvider = (0, react_1.useCallback)(({ children }) => {
|
|
70
|
+
return ((0, jsx_runtime_1.jsx)(RevisionContext.Provider, { value: contextValue, children: children }));
|
|
71
|
+
}, [contextValue]);
|
|
72
|
+
return {
|
|
73
|
+
localValue: currentLocalValue,
|
|
74
|
+
onChange,
|
|
75
|
+
reset,
|
|
76
|
+
RevisionContextProvider,
|
|
77
|
+
};
|
|
37
78
|
};
|
|
38
79
|
exports.useLocalState = useLocalState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type JSONPath = (string | number)[];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
export declare const optionRow: React.CSSProperties;
|
|
3
|
-
export declare const narrowOption: React.CSSProperties;
|
|
4
3
|
export declare const label: React.CSSProperties;
|
|
5
4
|
export declare const rightRow: React.CSSProperties;
|
|
6
5
|
export declare const input: React.CSSProperties;
|