@remotion/cli 4.0.0-alpha.130 → 4.0.0-alpha.185
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/benchmark.js +2 -2
- package/dist/codemods/update-default-props.js +7 -8
- package/dist/color-math.d.ts +1 -0
- package/dist/color-math.js +12 -0
- package/dist/config/ffmpeg-executable.d.ts +5 -0
- package/dist/config/ffmpeg-executable.js +21 -0
- package/dist/config/image-format.d.ts +1 -1
- package/dist/config/index.d.ts +7 -3
- package/dist/config/index.js +7 -4
- package/dist/config/jpeg-quality.d.ts +2 -0
- package/dist/config/jpeg-quality.js +17 -0
- package/dist/config/log.d.ts +1 -1
- package/dist/editor/components/Canvas.js +1 -4
- package/dist/editor/components/CheckerboardProvider.d.ts +4 -0
- package/dist/editor/components/CheckerboardProvider.js +24 -0
- package/dist/editor/components/CollapsedCompositionSelector.d.ts +4 -0
- package/dist/editor/components/CollapsedCompositionSelector.js +39 -0
- package/dist/editor/components/EditorContexts.js +7 -71
- package/dist/editor/components/KeyboardShortcutsExplainer.js +1 -1
- package/dist/editor/components/MediaVolumeProvider.d.ts +4 -0
- package/dist/editor/components/MediaVolumeProvider.js +25 -0
- package/dist/editor/components/Menu/MenuSubItem.js +14 -1
- package/dist/editor/components/Menu/styles.d.ts +2 -0
- package/dist/editor/components/Menu/styles.js +9 -2
- package/dist/editor/components/MenuToolbar.js +2 -1
- package/dist/editor/components/Modals.js +1 -1
- package/dist/editor/components/ModalsProvider.d.ts +4 -0
- package/dist/editor/components/ModalsProvider.js +17 -0
- package/dist/editor/components/NewComposition/ComboBox.js +22 -13
- package/dist/editor/components/NewComposition/InputDragger.js +1 -1
- package/dist/editor/components/NewComposition/MenuContent.js +7 -1
- package/dist/editor/components/NewComposition/RemInput.d.ts +1 -1
- package/dist/editor/components/NewComposition/RemInputTypeColor.d.ts +8 -0
- package/dist/editor/components/NewComposition/RemInputTypeColor.js +53 -0
- package/dist/editor/components/PlayerEmitterContext.d.ts +4 -0
- package/dist/editor/components/PlayerEmitterContext.js +11 -0
- package/dist/editor/components/QuickSwitcher/QuickSwitcherContent.js +1 -0
- package/dist/editor/components/RenderButton.js +2 -3
- package/dist/editor/components/RenderModal/JpegQualitySetting.d.ts +2 -2
- package/dist/editor/components/RenderModal/JpegQualitySetting.js +4 -4
- package/dist/editor/components/RenderModal/RenderModal.d.ts +1 -1
- package/dist/editor/components/RenderModal/RenderModal.js +13 -13
- package/dist/editor/components/RenderModal/RenderModalAdvanced.js +2 -0
- package/dist/editor/components/RenderModal/RenderModalAudio.js +0 -2
- package/dist/editor/components/RenderModal/RenderModalData.d.ts +1 -1
- package/dist/editor/components/RenderModal/RenderModalData.js +52 -6
- package/dist/editor/components/RenderModal/RenderModalJSONInputPropsEditor.d.ts +2 -0
- package/dist/editor/components/RenderModal/RenderModalJSONInputPropsEditor.js +25 -3
- package/dist/editor/components/RenderModal/RenderModalPicture.d.ts +2 -2
- package/dist/editor/components/RenderModal/RenderModalPicture.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaEditor.js +2 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaLabel.js +1 -4
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.js +12 -3
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +14 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.js +108 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEnumEditor.js +0 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNonEditableValue.js +5 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.js +4 -1
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +15 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.js +45 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodSwitch.js +8 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +14 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.js +45 -0
- package/dist/editor/components/RenderModal/SchemaEditor/create-zod-values.d.ts +2 -0
- package/dist/editor/components/RenderModal/SchemaEditor/create-zod-values.js +153 -0
- package/dist/editor/components/RenderModal/human-readable-codec.d.ts +1 -1
- package/dist/editor/components/RenderModal/out-name-checker.js +2 -1
- package/dist/editor/components/RenderQueue/actions.d.ts +5 -4
- package/dist/editor/components/RenderQueue/actions.js +11 -5
- package/dist/editor/components/RenderToolbarIcon.js +4 -2
- package/dist/editor/components/RendersTab.js +3 -3
- package/dist/editor/components/RichTimelineToggle.d.ts +2 -0
- package/dist/editor/components/RichTimelineToggle.js +29 -0
- package/dist/editor/components/RightPanel.js +3 -9
- package/dist/editor/components/SetTimelineInOutProvider.d.ts +4 -0
- package/dist/editor/components/SetTimelineInOutProvider.js +19 -0
- package/dist/editor/components/SidebarCollapserControls.d.ts +2 -0
- package/dist/editor/components/SidebarCollapserControls.js +122 -0
- package/dist/editor/components/SidebarContent.d.ts +5 -0
- package/dist/editor/components/SidebarContent.js +53 -0
- package/dist/editor/components/SizeSelector.js +1 -1
- package/dist/editor/components/Tabs/index.d.ts +1 -0
- package/dist/editor/components/Tabs/index.js +12 -5
- package/dist/editor/components/Tabs/vertical.d.ts +12 -0
- package/dist/editor/components/Tabs/vertical.js +57 -0
- package/dist/editor/components/Thumbnail.d.ts +8 -0
- package/dist/editor/components/Thumbnail.js +76 -0
- package/dist/editor/components/TopPanel.d.ts +1 -0
- package/dist/editor/components/TopPanel.js +19 -24
- package/dist/editor/components/ZoomGesturesProvider.d.ts +4 -0
- package/dist/editor/components/ZoomGesturesProvider.js +24 -0
- package/dist/editor/components/layout.d.ts +1 -0
- package/dist/editor/components/layout.js +5 -4
- package/dist/editor/helpers/colors.d.ts +1 -1
- package/dist/editor/helpers/use-compact-ui.d.ts +1 -0
- package/dist/editor/helpers/use-compact-ui.js +18 -0
- package/dist/editor/helpers/use-menu-structure.js +10 -22
- package/dist/editor/icons/film.d.ts +3 -0
- package/dist/editor/icons/film.js +8 -0
- package/dist/editor/icons/render.d.ts +3 -0
- package/dist/editor/icons/render.js +5 -1
- package/dist/editor/icons/save.d.ts +2 -0
- package/dist/editor/icons/save.js +8 -0
- package/dist/editor/icons/timeline.d.ts +3 -0
- package/dist/editor/icons/timeline.js +9 -0
- package/dist/editor/state/modals.d.ts +1 -1
- package/dist/editor/state/rich-timeline.d.ts +9 -0
- package/dist/editor/state/rich-timeline.js +17 -0
- package/dist/editor/state/sidebar.d.ts +6 -5
- package/dist/editor/state/sidebar.js +35 -21
- package/dist/get-cli-options.d.ts +3 -3
- package/dist/get-cli-options.js +1 -1
- package/dist/get-render-media-options.d.ts +8 -0
- package/dist/get-render-media-options.js +55 -0
- package/dist/index.d.ts +9 -9
- package/dist/install.d.ts +2 -0
- package/dist/install.js +36 -0
- package/dist/parse-command-line.d.ts +1 -0
- package/dist/parse-command-line.js +5 -1
- package/dist/preview-server/api-routes.js +2 -0
- package/dist/preview-server/api-types.d.ts +2 -1
- package/dist/preview-server/render-queue/job.d.ts +13 -4
- package/dist/preview-server/render-queue/make-retry-payload.js +2 -2
- package/dist/preview-server/render-queue/process-still.js +1 -1
- package/dist/preview-server/render-queue/process-video.js +1 -1
- package/dist/preview-server/routes/add-render.js +2 -2
- package/dist/preview-server/routes/can-update-default-props.d.ts +4 -0
- package/dist/preview-server/routes/can-update-default-props.js +39 -0
- package/dist/preview-server/routes/update-default-props.js +3 -1
- package/dist/preview-server/routes.js +2 -2
- package/dist/print-help.js +2 -2
- package/dist/render-flows/render.d.ts +2 -2
- package/dist/render-flows/render.js +3 -3
- package/dist/render-flows/still.d.ts +2 -2
- package/dist/render-flows/still.js +2 -2
- package/dist/render.js +2 -2
- package/dist/still.js +2 -2
- package/package.json +7 -7
- package/styles/styles.css +6 -0
- package/dist/editor/components/RenderModal/SchemaEditor/schema-serialization.d.ts +0 -2
- package/dist/editor/components/RenderModal/SchemaEditor/schema-serialization.js +0 -21
|
@@ -27,6 +27,7 @@ exports.RenderModalJSONInputPropsEditor = void 0;
|
|
|
27
27
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
28
|
const react_1 = __importStar(require("react"));
|
|
29
29
|
const Button_1 = require("../../../preview-server/error-overlay/remotion-overlay/Button");
|
|
30
|
+
const use_keybinding_1 = require("../../helpers/use-keybinding");
|
|
30
31
|
const layout_1 = require("../layout");
|
|
31
32
|
const RemTextarea_1 = require("../NewComposition/RemTextarea");
|
|
32
33
|
const ValidationMessage_1 = require("../NewComposition/ValidationMessage");
|
|
@@ -58,7 +59,8 @@ const scrollable = {
|
|
|
58
59
|
flex: 1,
|
|
59
60
|
};
|
|
60
61
|
// TODO: Note if custom 'remotion-date:' pattern has been used
|
|
61
|
-
const RenderModalJSONInputPropsEditor = ({ setValue, value, zodValidationResult, switchToSchema, onSave }) => {
|
|
62
|
+
const RenderModalJSONInputPropsEditor = ({ setValue, value, zodValidationResult, switchToSchema, onSave, valBeforeSafe, showSaveButton, }) => {
|
|
63
|
+
const keybindings = (0, use_keybinding_1.useKeybinding)();
|
|
62
64
|
const [localValue, setLocalValue] = react_1.default.useState(() => {
|
|
63
65
|
return parseJSON((0, date_serialization_1.serializeJSONWithDate)(value, 2));
|
|
64
66
|
});
|
|
@@ -89,8 +91,28 @@ const RenderModalJSONInputPropsEditor = ({ setValue, value, zodValidationResult,
|
|
|
89
91
|
setValue(parsed.value);
|
|
90
92
|
}
|
|
91
93
|
}, [setValue]);
|
|
92
|
-
|
|
94
|
+
const hasChanged = (0, react_1.useMemo)(() => {
|
|
95
|
+
return value && JSON.stringify(value) !== JSON.stringify(valBeforeSafe);
|
|
96
|
+
}, [valBeforeSafe, value]);
|
|
97
|
+
const onQuickSave = (0, react_1.useCallback)(() => {
|
|
98
|
+
if (hasChanged) {
|
|
99
|
+
onSave();
|
|
100
|
+
}
|
|
101
|
+
}, [hasChanged, onSave]);
|
|
102
|
+
(0, react_1.useEffect)(() => {
|
|
103
|
+
const save = keybindings.registerKeybinding({
|
|
104
|
+
event: 'keydown',
|
|
105
|
+
key: 's',
|
|
106
|
+
commandCtrlKey: true,
|
|
107
|
+
callback: onQuickSave,
|
|
108
|
+
preventDefault: true,
|
|
109
|
+
triggerIfInputFieldFocused: true,
|
|
110
|
+
});
|
|
111
|
+
return () => {
|
|
112
|
+
save.unregister();
|
|
113
|
+
};
|
|
114
|
+
}, [keybindings, onQuickSave, onSave]);
|
|
93
115
|
// TODO: Indicate saving progress
|
|
94
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: scrollable, children: [(0, jsx_runtime_1.jsx)(RemTextarea_1.RemTextarea, { onChange: onChange, value: localValue.str, status: localValue.validJSON ? 'ok' : 'error', style: style }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1 }), localValue.validJSON === false ? ((0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.error, type: "error" })) : zodValidationResult.success === false ? ((0, jsx_runtime_1.jsx)("button", { type: "button", style: schemaButton, onClick: switchToSchema, children: (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: "Does not match schema", type: "warning" }) })) : null, (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1 }), (0, jsx_runtime_1.jsxs)(layout_1.Row, { children: [(0, jsx_runtime_1.jsx)(Button_1.Button, { disabled: !localValue.validJSON, onClick: onPretty, children: "Format JSON" }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(Button_1.Button, { onClick: onSave, disabled: !zodValidationResult.success, children: "Save" })] })] }));
|
|
116
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: scrollable, children: [(0, jsx_runtime_1.jsx)(RemTextarea_1.RemTextarea, { onChange: onChange, value: localValue.str, status: localValue.validJSON ? 'ok' : 'error', style: style }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1 }), localValue.validJSON === false ? ((0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.error, type: "error" })) : zodValidationResult.success === false ? ((0, jsx_runtime_1.jsx)("button", { type: "button", style: schemaButton, onClick: switchToSchema, children: (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: "Does not match schema", type: "warning" }) })) : null, (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1 }), (0, jsx_runtime_1.jsxs)(layout_1.Row, { children: [(0, jsx_runtime_1.jsx)(Button_1.Button, { disabled: !localValue.validJSON, onClick: onPretty, children: "Format JSON" }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(Button_1.Button, { onClick: onSave, disabled: !zodValidationResult.success || !hasChanged || !showSaveButton, children: "Save" })] })] }));
|
|
95
117
|
};
|
|
96
118
|
exports.RenderModalJSONInputPropsEditor = RenderModalJSONInputPropsEditor;
|
|
@@ -15,8 +15,8 @@ export declare const RenderModalPicture: React.FC<{
|
|
|
15
15
|
qualityControlType: QualityControl;
|
|
16
16
|
videoImageFormat: VideoImageFormat;
|
|
17
17
|
stillImageFormat: StillImageFormat;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
setJpegQuality: React.Dispatch<React.SetStateAction<number>>;
|
|
19
|
+
jpegQuality: number;
|
|
20
20
|
maxCrf: number;
|
|
21
21
|
minCrf: number;
|
|
22
22
|
setCrf: React.Dispatch<React.SetStateAction<number>>;
|
|
@@ -19,7 +19,7 @@ const qualityControlModes = ['crf', 'bitrate'];
|
|
|
19
19
|
const container = {
|
|
20
20
|
flex: 1,
|
|
21
21
|
};
|
|
22
|
-
const RenderModalPicture = ({ renderMode, scale, setScale, pixelFormat, setPixelFormat, imageFormatOptions, setQualityControl, qualityControlType, videoImageFormat,
|
|
22
|
+
const RenderModalPicture = ({ renderMode, scale, setScale, pixelFormat, setPixelFormat, imageFormatOptions, setQualityControl, qualityControlType, videoImageFormat, setJpegQuality, jpegQuality, maxCrf, minCrf, setCrf, shouldDisplayCrfOption, setCustomTargetVideoBitrateValue, crf, customTargetVideoBitrate, stillImageFormat, }) => {
|
|
23
23
|
const pixelFormatOptions = (0, react_1.useMemo)(() => {
|
|
24
24
|
return client_1.BrowserSafeApis.validPixelFormats.map((option) => {
|
|
25
25
|
return {
|
|
@@ -49,7 +49,7 @@ const RenderModalPicture = ({ renderMode, scale, setScale, pixelFormat, setPixel
|
|
|
49
49
|
const onTargetVideoBitrateChanged = (0, react_1.useCallback)((e) => {
|
|
50
50
|
setCustomTargetVideoBitrateValue(e.target.value);
|
|
51
51
|
}, [setCustomTargetVideoBitrateValue]);
|
|
52
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: container, children: [renderMode === 'video' ? ((0, jsx_runtime_1.jsxs)("div", { style: layout_1.optionRow, children: [(0, jsx_runtime_1.jsx)("div", { style: layout_1.label, children: "Image Format" }), (0, jsx_runtime_1.jsx)("div", { style: layout_1.rightRow, children: (0, jsx_runtime_1.jsx)(SegmentedControl_1.SegmentedControl, { items: imageFormatOptions, needsWrapping: false }) })] })) : null, renderMode === 'video' && videoImageFormat === 'jpeg' && ((0, jsx_runtime_1.jsx)(JpegQualitySetting_1.JpegQualitySetting, {
|
|
52
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: container, children: [renderMode === 'video' ? ((0, jsx_runtime_1.jsxs)("div", { style: layout_1.optionRow, children: [(0, jsx_runtime_1.jsx)("div", { style: layout_1.label, children: "Image Format" }), (0, jsx_runtime_1.jsx)("div", { style: layout_1.rightRow, children: (0, jsx_runtime_1.jsx)(SegmentedControl_1.SegmentedControl, { items: imageFormatOptions, needsWrapping: false }) })] })) : null, renderMode === 'video' && videoImageFormat === 'jpeg' && ((0, jsx_runtime_1.jsx)(JpegQualitySetting_1.JpegQualitySetting, { jpegQuality: jpegQuality, setJpegQuality: setJpegQuality })), renderMode === 'still' && stillImageFormat === 'jpeg' && ((0, jsx_runtime_1.jsx)(JpegQualitySetting_1.JpegQualitySetting, { jpegQuality: jpegQuality, setJpegQuality: setJpegQuality })), renderMode === 'video' ? (0, jsx_runtime_1.jsx)(RenderModalHr_1.RenderModalHr, {}) : null, renderMode === 'video' ? ((0, jsx_runtime_1.jsxs)("div", { style: layout_1.optionRow, children: [(0, jsx_runtime_1.jsx)("div", { style: layout_1.label, children: "Quality control" }), (0, jsx_runtime_1.jsx)("div", { style: layout_1.rightRow, children: (0, jsx_runtime_1.jsx)(SegmentedControl_1.SegmentedControl, { items: qualityControlOptions, needsWrapping: true }) })] })) : null, shouldDisplayCrfOption &&
|
|
53
53
|
qualityControlType === 'crf' &&
|
|
54
54
|
renderMode !== 'still' ? ((0, jsx_runtime_1.jsx)(CrfSetting_1.CrfSetting, { crf: crf, min: minCrf, max: maxCrf, setCrf: setCrf, option: client_1.BrowserSafeApis.options.crfOption })) : null, qualityControlType === 'bitrate' && renderMode !== 'still' ? ((0, jsx_runtime_1.jsxs)("div", { style: layout_1.optionRow, children: [(0, jsx_runtime_1.jsx)("div", { style: layout_1.label, children: "Target video bitrate" }), (0, jsx_runtime_1.jsx)(InfoBubble_1.InfoBubble, { title: "Learn more about this option", children: (0, jsx_runtime_1.jsx)(OptionExplainer_1.OptionExplainer, { option: client_1.BrowserSafeApis.options.videoBitrate }) }), (0, jsx_runtime_1.jsx)("div", { style: layout_1.rightRow, children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(RemInput_1.RemotionInput, { style: layout_1.input, value: customTargetVideoBitrate, onChange: onTargetVideoBitrateChanged, status: "ok" }) }) })] })) : null, renderMode === 'video' ? (0, jsx_runtime_1.jsx)(RenderModalHr_1.RenderModalHr, {}) : null, (0, jsx_runtime_1.jsx)(ScaleSetting_1.ScaleSetting, { scale: scale, setScale: setScale }), renderMode === 'video' ? (0, jsx_runtime_1.jsx)(RenderModalHr_1.RenderModalHr, {}) : null, renderMode === 'video' ? ((0, jsx_runtime_1.jsxs)("div", { style: layout_1.optionRow, children: [(0, jsx_runtime_1.jsx)("div", { style: layout_1.label, children: "Pixel format" }), (0, jsx_runtime_1.jsx)("div", { style: layout_1.rightRow, children: (0, jsx_runtime_1.jsx)(ComboBox_1.Combobox, { values: pixelFormatOptions, selectedId: pixelFormat, title: "Pixel Format" }) })] })) : null] }));
|
|
55
55
|
};
|
|
@@ -58,6 +58,8 @@ const SchemaEditor = ({ schema, value, setValue, zodValidationResult, compact, d
|
|
|
58
58
|
}
|
|
59
59
|
const defaultPropsValid = schema.safeParse(defaultProps);
|
|
60
60
|
if (!defaultPropsValid.success) {
|
|
61
|
+
// TODO: Layout is not nice
|
|
62
|
+
// TODO: Does not react to when schema is updated
|
|
61
63
|
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { style: errorExplanation, children: ["The schema can not be edited because the", ' ', (0, jsx_runtime_1.jsx)("code", { style: codeSnippet, children: "defaultProps" }), " prop in the", ' ', (0, jsx_runtime_1.jsx)("code", { style: codeSnippet, children: '<Composition>' }), " is not valid:"] }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(ZodErrorMessages_1.ZodErrorMessages, { zodValidationResult: zodValidationResult }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsxs)("div", { style: errorExplanation, children: ["Fix the schema by changing the", ' ', (0, jsx_runtime_1.jsx)("code", { style: codeSnippet, children: "defaultProps" }), " prop in your composition so it does not give a type error."] })] }));
|
|
62
64
|
}
|
|
63
65
|
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { style: errorExplanation, children: "The data does not satisfy the schema:" }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(ZodErrorMessages_1.ZodErrorMessages, { zodValidationResult: zodValidationResult }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)("div", { style: errorExplanation, children: "Fix the schema using the JSON editor." }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsxs)("div", { style: errorExplanation, children: ["Alternatively, reset the data to the ", (0, jsx_runtime_1.jsx)("code", { children: "defaultProps" }), " that you have defined."] }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(Button_1.Button, { onClick: reset, children: "Reset props" })] }));
|
|
@@ -13,7 +13,6 @@ const commonStyles = {
|
|
|
13
13
|
fontSize: 15,
|
|
14
14
|
color: colors_1.LIGHT_TEXT,
|
|
15
15
|
fontFamily: 'sans-serif',
|
|
16
|
-
lineHeight: '40px',
|
|
17
16
|
};
|
|
18
17
|
const compactStyles = {
|
|
19
18
|
...commonStyles,
|
|
@@ -24,14 +23,12 @@ const compactStyles = {
|
|
|
24
23
|
const wideStyles = {
|
|
25
24
|
...commonStyles,
|
|
26
25
|
width: layout_2.label.width,
|
|
27
|
-
display: 'flex',
|
|
28
|
-
flexDirection: 'row',
|
|
29
|
-
alignItems: 'center',
|
|
30
26
|
};
|
|
31
27
|
const labelStyle = {
|
|
32
28
|
fontFamily: 'monospace',
|
|
33
29
|
fontSize: 14,
|
|
34
30
|
color: colors_1.LIGHT_TEXT,
|
|
31
|
+
lineHeight: '40px',
|
|
35
32
|
};
|
|
36
33
|
const SchemaLabel = ({ jsonPath, isDefaultValue, onReset, onSave, showSaveButton, compact, onRemove, }) => {
|
|
37
34
|
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? compactStyles : wideStyles, children: [(0, jsx_runtime_1.jsx)("span", { style: labelStyle, children: (0, get_schema_label_1.getSchemaLabel)(jsonPath) }), compact ? (0, jsx_runtime_1.jsx)(layout_1.Flex, {}) : (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), isDefaultValue ? null : (0, jsx_runtime_1.jsx)(SchemaResetButton_1.SchemaResetButton, { onClick: onReset }), isDefaultValue ? null : showSaveButton ? ((0, jsx_runtime_1.jsx)(SchemaSaveButton_1.SchemaSaveButton, { onClick: onSave })) : null, onRemove ? (0, jsx_runtime_1.jsx)(InlineRemoveButton_1.InlineRemoveButton, { onClick: onRemove }) : null] }));
|
|
@@ -4,10 +4,12 @@ exports.ZodArrayEditor = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const remotion_1 = require("remotion");
|
|
7
|
+
const Button_1 = require("../../../../preview-server/error-overlay/remotion-overlay/Button");
|
|
7
8
|
const colors_1 = require("../../../helpers/colors");
|
|
8
9
|
const layout_1 = require("../../layout");
|
|
9
10
|
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
10
11
|
const layout_2 = require("../layout");
|
|
12
|
+
const create_zod_values_1 = require("./create-zod-values");
|
|
11
13
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
12
14
|
const ZodArrayItemEditor_1 = require("./ZodArrayItemEditor");
|
|
13
15
|
const container = {
|
|
@@ -16,7 +18,7 @@ const container = {
|
|
|
16
18
|
const fullWidth = {
|
|
17
19
|
width: '100%',
|
|
18
20
|
};
|
|
19
|
-
// TODO: Ability to
|
|
21
|
+
// TODO: Ability to revert a change (e.g entry deletion )
|
|
20
22
|
const ZodArrayEditor = ({ schema, jsonPath, compact, setValue: updateValue, defaultValue, value, onSave, showSaveButton, onRemove, }) => {
|
|
21
23
|
const [localValue, setLocalValue] = (0, react_1.useState)(() => {
|
|
22
24
|
return {
|
|
@@ -45,6 +47,7 @@ const ZodArrayEditor = ({ schema, jsonPath, compact, setValue: updateValue, defa
|
|
|
45
47
|
setLocalValue((oldLocalState) => {
|
|
46
48
|
const newValue = updater(oldLocalState.value);
|
|
47
49
|
const safeParse = schema.safeParse(newValue);
|
|
50
|
+
// TODO: This logs an error to the console
|
|
48
51
|
if (safeParse.success) {
|
|
49
52
|
updateValue(updater);
|
|
50
53
|
}
|
|
@@ -61,10 +64,16 @@ const ZodArrayEditor = ({ schema, jsonPath, compact, setValue: updateValue, defa
|
|
|
61
64
|
}
|
|
62
65
|
return { paddingTop };
|
|
63
66
|
}, [isRoot, paddingTop]);
|
|
67
|
+
const onAdd = (0, react_1.useCallback)(() => {
|
|
68
|
+
onChange((oldV) => {
|
|
69
|
+
return [...oldV, (0, create_zod_values_1.createZodValues)(def.type)];
|
|
70
|
+
}, true);
|
|
71
|
+
}, [def.type, onChange]);
|
|
64
72
|
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, { jsonPath: jsonPath, onRemove: onRemove })), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: localValue.value.map((child, i) => {
|
|
73
|
+
var _a;
|
|
65
74
|
return ((0, jsx_runtime_1.jsx)(ZodArrayItemEditor_1.ZodArrayItemEditor
|
|
66
75
|
// eslint-disable-next-line react/no-array-index-key
|
|
67
|
-
, { onChange: onChange, value: child, def: def, index: i, jsonPath: jsonPath, compact: compact, defaultValue: defaultValue[i], onSave: onSave, showSaveButton: showSaveButton }, `${i}${localValue.revision}`));
|
|
68
|
-
}) }), !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-end", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] }) }) }));
|
|
76
|
+
, { onChange: onChange, value: child, def: def, index: i, jsonPath: jsonPath, compact: compact, defaultValue: (_a = defaultValue[i]) !== null && _a !== void 0 ? _a : child, onSave: onSave, showSaveButton: showSaveButton }, `${i}${localValue.revision}`));
|
|
77
|
+
}) }), !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-end", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] })), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(Button_1.Button, { onClick: onAdd, children: "+ Add item" })] }) }) }));
|
|
69
78
|
};
|
|
70
79
|
exports.ZodArrayEditor = ZodArrayEditor;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { z } from 'remotion';
|
|
3
|
+
import type { JSONPath } from './zod-types';
|
|
4
|
+
export declare const ZodColorEditor: React.FC<{
|
|
5
|
+
schema: z.ZodTypeAny;
|
|
6
|
+
jsonPath: JSONPath;
|
|
7
|
+
value: string;
|
|
8
|
+
defaultValue: string;
|
|
9
|
+
setValue: React.Dispatch<React.SetStateAction<string>>;
|
|
10
|
+
onSave: (updater: (oldNum: unknown) => string) => void;
|
|
11
|
+
onRemove: null | (() => void);
|
|
12
|
+
compact: boolean;
|
|
13
|
+
showSaveButton: boolean;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZodColorEditor = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const remotion_1 = require("remotion");
|
|
7
|
+
const color_math_1 = require("../../../../color-math");
|
|
8
|
+
const layout_1 = require("../../layout");
|
|
9
|
+
const InputDragger_1 = require("../../NewComposition/InputDragger");
|
|
10
|
+
const RemInput_1 = require("../../NewComposition/RemInput");
|
|
11
|
+
const RemInputTypeColor_1 = require("../../NewComposition/RemInputTypeColor");
|
|
12
|
+
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
13
|
+
const layout_2 = require("../layout");
|
|
14
|
+
const SchemaLabel_1 = require("./SchemaLabel");
|
|
15
|
+
const fullWidth = {
|
|
16
|
+
width: '100%',
|
|
17
|
+
};
|
|
18
|
+
const ZodColorEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, compact, onSave, onRemove, }) => {
|
|
19
|
+
const [localValue, setLocalValue] = (0, react_1.useState)(() => {
|
|
20
|
+
return {
|
|
21
|
+
value,
|
|
22
|
+
zodValidation: schema.safeParse(value),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const onValueChange = (0, react_1.useCallback)((newValue) => {
|
|
26
|
+
const safeParse = schema.safeParse(newValue);
|
|
27
|
+
const newLocalState = {
|
|
28
|
+
value: newValue,
|
|
29
|
+
zodValidation: safeParse,
|
|
30
|
+
};
|
|
31
|
+
setLocalValue(newLocalState);
|
|
32
|
+
if (safeParse.success) {
|
|
33
|
+
setValue(newValue);
|
|
34
|
+
}
|
|
35
|
+
}, [schema, setValue]);
|
|
36
|
+
const { a, b, g, r } = localValue.zodValidation.success
|
|
37
|
+
? remotion_1.Internals.parseColor(localValue.value)
|
|
38
|
+
: { a: 1, b: 0, g: 0, r: 0 };
|
|
39
|
+
const onChange = (0, react_1.useCallback)((e) => {
|
|
40
|
+
const newColor = (0, color_math_1.colorWithNewOpacity)(e.target.value, Math.round(a));
|
|
41
|
+
const safeParse = schema.safeParse(newColor);
|
|
42
|
+
const newLocalState = {
|
|
43
|
+
value: newColor,
|
|
44
|
+
zodValidation: safeParse,
|
|
45
|
+
};
|
|
46
|
+
setLocalValue(newLocalState);
|
|
47
|
+
if (safeParse.success) {
|
|
48
|
+
setValue(newColor);
|
|
49
|
+
}
|
|
50
|
+
}, [a, schema, setValue]);
|
|
51
|
+
const onTextChange = (0, react_1.useCallback)((e) => {
|
|
52
|
+
const newValue = e.target.value;
|
|
53
|
+
const safeParse = schema.safeParse(newValue);
|
|
54
|
+
const newLocalState = {
|
|
55
|
+
value: newValue,
|
|
56
|
+
zodValidation: safeParse,
|
|
57
|
+
};
|
|
58
|
+
setLocalValue(newLocalState);
|
|
59
|
+
if (safeParse.success) {
|
|
60
|
+
setValue(newValue);
|
|
61
|
+
}
|
|
62
|
+
}, [schema, setValue]);
|
|
63
|
+
const reset = (0, react_1.useCallback)(() => {
|
|
64
|
+
onValueChange(defaultValue);
|
|
65
|
+
}, [defaultValue, onValueChange]);
|
|
66
|
+
const save = (0, react_1.useCallback)(() => {
|
|
67
|
+
onSave(() => value);
|
|
68
|
+
}, [onSave, value]);
|
|
69
|
+
const rgb = `#${r.toString(16).padStart(2, '0')}${g
|
|
70
|
+
.toString(16)
|
|
71
|
+
.padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
|
|
72
|
+
const status = localValue.zodValidation.success ? 'ok' : 'error';
|
|
73
|
+
const colorPicker = (0, react_1.useMemo)(() => {
|
|
74
|
+
return {
|
|
75
|
+
height: 39,
|
|
76
|
+
width: 45,
|
|
77
|
+
display: 'inline-block',
|
|
78
|
+
};
|
|
79
|
+
}, []);
|
|
80
|
+
const onOpacityChange = (0, react_1.useCallback)((newValue) => {
|
|
81
|
+
const newColor = (0, color_math_1.colorWithNewOpacity)(localValue.value, Math.round((Number(newValue) / 100) * 255));
|
|
82
|
+
const safeParse = schema.safeParse(newColor);
|
|
83
|
+
const newLocalState = {
|
|
84
|
+
value: newColor,
|
|
85
|
+
zodValidation: safeParse,
|
|
86
|
+
};
|
|
87
|
+
setLocalValue(newLocalState);
|
|
88
|
+
if (safeParse.success) {
|
|
89
|
+
setValue(newColor);
|
|
90
|
+
}
|
|
91
|
+
}, [localValue.value, schema, setValue]);
|
|
92
|
+
const onOpacityValueChange = (0, react_1.useCallback)((newValue) => {
|
|
93
|
+
const newColor = (0, color_math_1.colorWithNewOpacity)(localValue.value, Math.round((Number(newValue) / 100) * 255));
|
|
94
|
+
const safeParse = schema.safeParse(newColor);
|
|
95
|
+
const newLocalState = {
|
|
96
|
+
value: String(newColor),
|
|
97
|
+
zodValidation: safeParse,
|
|
98
|
+
};
|
|
99
|
+
setLocalValue(newLocalState);
|
|
100
|
+
if (safeParse.success) {
|
|
101
|
+
setValue(newColor);
|
|
102
|
+
}
|
|
103
|
+
}, [localValue.value, schema, setValue]);
|
|
104
|
+
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 }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsxs)(layout_1.Row, { align: "center", children: [(0, jsx_runtime_1.jsx)("div", { style: colorPicker, children: (0, jsx_runtime_1.jsx)(RemInputTypeColor_1.RemInputTypeColor, { type: "color", style: {
|
|
105
|
+
height: 39,
|
|
106
|
+
}, value: rgb, onChange: onChange, className: "__remotion_color_picker", status: status }) }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1, block: true }), (0, jsx_runtime_1.jsx)(RemInput_1.RemotionInput, { value: localValue.value, status: status, placeholder: jsonPath.join('.'), onChange: onTextChange }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(InputDragger_1.InputDragger, { onTextChange: onOpacityChange, onValueChange: onOpacityValueChange, status: status, value: (a / 255) * 100, min: 0, max: 100, step: 1, formatter: (v) => `${Math.round(Number(v))}%` })] }), !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-end", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] })] }));
|
|
107
|
+
};
|
|
108
|
+
exports.ZodColorEditor = ZodColorEditor;
|
|
@@ -13,7 +13,6 @@ const SchemaLabel_1 = require("./SchemaLabel");
|
|
|
13
13
|
const container = {
|
|
14
14
|
width: '100%',
|
|
15
15
|
};
|
|
16
|
-
// TODO: Long values break the layout
|
|
17
16
|
const ZodEnumEditor = ({ schema, jsonPath, compact, setValue: updateValue, defaultValue, value, onSave, showSaveButton, onRemove, }) => {
|
|
18
17
|
const [localValue, setLocalValue] = (0, react_1.useState)(() => {
|
|
19
18
|
return {
|
|
@@ -15,9 +15,13 @@ const emptyLabel = {
|
|
|
15
15
|
fontFamily: 'sans-serif',
|
|
16
16
|
fontSize: 14,
|
|
17
17
|
};
|
|
18
|
+
const wideEmptyLabel = {
|
|
19
|
+
...emptyLabel,
|
|
20
|
+
lineHeight: '37px',
|
|
21
|
+
};
|
|
18
22
|
const ZonNonEditableValue = ({ jsonPath, label, compact, showSaveButton }) => {
|
|
19
23
|
const save = (0, react_1.useCallback)(() => undefined, []);
|
|
20
24
|
const reset = (0, react_1.useCallback)(() => undefined, []);
|
|
21
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_1.narrowOption : layout_1.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: true, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: null }), (0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsx)("em", { style: emptyLabel, children: label }) })] }));
|
|
25
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_1.narrowOption : layout_1.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: true, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: null }), (0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsx)("em", { style: compact ? emptyLabel : wideEmptyLabel, children: label }) })] }));
|
|
22
26
|
};
|
|
23
27
|
exports.ZonNonEditableValue = ZonNonEditableValue;
|
|
@@ -37,7 +37,10 @@ const ZodObjectEditor = ({ schema, jsonPath, setValue, value, compact, defaultVa
|
|
|
37
37
|
return { paddingTop };
|
|
38
38
|
}, [isRoot, paddingTop]);
|
|
39
39
|
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, { jsonPath: jsonPath, onRemove: onRemove })), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: keys.map((key) => {
|
|
40
|
-
|
|
40
|
+
var _a;
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { jsonPath: [...jsonPath, key], schema: shape[key], value: value[key],
|
|
42
|
+
// In case of null | {a: string, b: string} type, we need to fallback to the default value
|
|
43
|
+
defaultValue: ((_a = defaultValue) !== null && _a !== void 0 ? _a : value)[key], setValue: (val) => {
|
|
41
44
|
setValue((oldVal) => {
|
|
42
45
|
return {
|
|
43
46
|
...oldVal,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { z } from 'remotion';
|
|
3
|
+
import type { JSONPath } from './zod-types';
|
|
4
|
+
export declare const ZodOrNullishEditor: React.FC<{
|
|
5
|
+
showSaveButton: boolean;
|
|
6
|
+
jsonPath: JSONPath;
|
|
7
|
+
compact: boolean;
|
|
8
|
+
value: unknown;
|
|
9
|
+
defaultValue: unknown;
|
|
10
|
+
schema: z.ZodTypeAny;
|
|
11
|
+
setValue: React.Dispatch<React.SetStateAction<unknown>>;
|
|
12
|
+
onSave: (updater: (oldNum: unknown) => unknown) => void;
|
|
13
|
+
onRemove: null | (() => void);
|
|
14
|
+
nullishValue: null | undefined;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZodOrNullishEditor = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const colors_1 = require("../../../helpers/colors");
|
|
7
|
+
const Checkbox_1 = require("../../Checkbox");
|
|
8
|
+
const layout_1 = require("../../layout");
|
|
9
|
+
const create_zod_values_1 = require("./create-zod-values");
|
|
10
|
+
const SchemaLabel_1 = require("./SchemaLabel");
|
|
11
|
+
const ZodSwitch_1 = require("./ZodSwitch");
|
|
12
|
+
const fullWidth = {
|
|
13
|
+
width: '100%',
|
|
14
|
+
};
|
|
15
|
+
const labelStyle = {
|
|
16
|
+
fontFamily: 'sans-serif',
|
|
17
|
+
fontSize: 14,
|
|
18
|
+
color: colors_1.LIGHT_TEXT,
|
|
19
|
+
};
|
|
20
|
+
const checkBoxWrapper = {
|
|
21
|
+
margin: '2px',
|
|
22
|
+
display: 'flex',
|
|
23
|
+
flexDirection: 'row',
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
marginTop: '5px',
|
|
26
|
+
};
|
|
27
|
+
const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, nullishValue, }) => {
|
|
28
|
+
const isChecked = value === nullishValue;
|
|
29
|
+
const onValueChange = (0, react_1.useCallback)((newValue) => {
|
|
30
|
+
setValue(newValue);
|
|
31
|
+
}, [setValue]);
|
|
32
|
+
const onCheckBoxChange = (0, react_1.useCallback)((e) => {
|
|
33
|
+
console.log({ schema, newVal: (0, create_zod_values_1.createZodValues)(schema) });
|
|
34
|
+
const val = e.target.checked ? nullishValue : (0, create_zod_values_1.createZodValues)(schema);
|
|
35
|
+
onValueChange(val);
|
|
36
|
+
}, [nullishValue, onValueChange, schema]);
|
|
37
|
+
const reset = (0, react_1.useCallback)(() => {
|
|
38
|
+
onValueChange(defaultValue);
|
|
39
|
+
}, [defaultValue, onValueChange]);
|
|
40
|
+
const save = (0, react_1.useCallback)(() => {
|
|
41
|
+
onSave(() => value);
|
|
42
|
+
}, [onSave, value]);
|
|
43
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [value === null ? ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove })) : ((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 }) })), (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) })] })] }));
|
|
44
|
+
};
|
|
45
|
+
exports.ZodOrNullishEditor = ZodOrNullishEditor;
|
|
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const remotion_1 = require("remotion");
|
|
6
6
|
const ZodArrayEditor_1 = require("./ZodArrayEditor");
|
|
7
7
|
const ZodBooleanEditor_1 = require("./ZodBooleanEditor");
|
|
8
|
+
const ZodColorEditor_1 = require("./ZodColorEditor");
|
|
8
9
|
const ZodDateEditor_1 = require("./ZodDateEditor");
|
|
9
10
|
const ZodEffectEditor_1 = require("./ZodEffectEditor");
|
|
10
11
|
const ZodEnumEditor_1 = require("./ZodEnumEditor");
|
|
@@ -12,6 +13,7 @@ const ZodNonEditableValue_1 = require("./ZodNonEditableValue");
|
|
|
12
13
|
const ZodNumberEditor_1 = require("./ZodNumberEditor");
|
|
13
14
|
const ZodObjectEditor_1 = require("./ZodObjectEditor");
|
|
14
15
|
const ZodStringEditor_1 = require("./ZodStringEditor");
|
|
16
|
+
const ZodUnionEditor_1 = require("./ZodUnionEditor");
|
|
15
17
|
const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, onSave, showSaveButton, onRemove, }) => {
|
|
16
18
|
const def = schema._def;
|
|
17
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -54,8 +56,14 @@ const ZodSwitch = ({ schema, jsonPath, compact, value, setValue, defaultValue, o
|
|
|
54
56
|
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 }));
|
|
55
57
|
}
|
|
56
58
|
if (typeName === remotion_1.z.ZodFirstPartyTypeKind.ZodEffects) {
|
|
59
|
+
if (schema._def.description === remotion_1.Internals.REMOTION_COLOR_BRAND) {
|
|
60
|
+
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 }));
|
|
61
|
+
}
|
|
57
62
|
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 }));
|
|
58
63
|
}
|
|
64
|
+
if (typeName === remotion_1.z.ZodFirstPartyTypeKind.ZodUnion) {
|
|
65
|
+
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 }));
|
|
66
|
+
}
|
|
59
67
|
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { compact: compact, jsonPath: jsonPath, showSaveButton: showSaveButton, label: `${typeName} (not editable)` }));
|
|
60
68
|
};
|
|
61
69
|
exports.ZodSwitch = ZodSwitch;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { z } from 'remotion';
|
|
3
|
+
import type { JSONPath } from './zod-types';
|
|
4
|
+
export declare const ZodUnionEditor: React.FC<{
|
|
5
|
+
showSaveButton: boolean;
|
|
6
|
+
jsonPath: JSONPath;
|
|
7
|
+
compact: boolean;
|
|
8
|
+
value: unknown;
|
|
9
|
+
defaultValue: unknown;
|
|
10
|
+
schema: z.ZodTypeAny;
|
|
11
|
+
setValue: React.Dispatch<React.SetStateAction<unknown>>;
|
|
12
|
+
onSave: (updater: (oldNum: unknown) => unknown) => void;
|
|
13
|
+
onRemove: null | (() => void);
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZodUnionEditor = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const remotion_1 = require("remotion");
|
|
6
|
+
const ZodNonEditableValue_1 = require("./ZodNonEditableValue");
|
|
7
|
+
const ZodOrNullishEditor_1 = require("./ZodOrNullishEditor");
|
|
8
|
+
const findNull = (value) => {
|
|
9
|
+
const nullIndex = value.findIndex((v) => v._def.typeName === remotion_1.z.ZodFirstPartyTypeKind.ZodNull ||
|
|
10
|
+
v._def.typeName === remotion_1.z.ZodFirstPartyTypeKind.ZodUndefined);
|
|
11
|
+
if (nullIndex === -1) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const nullishValue = value[nullIndex]._def.typeName === remotion_1.z.ZodFirstPartyTypeKind.ZodNull
|
|
15
|
+
? null
|
|
16
|
+
: undefined;
|
|
17
|
+
const otherSchema = value[nullIndex === 0 ? 1 : 0];
|
|
18
|
+
const otherSchemaIsAlsoNullish = otherSchema._def.typeName === remotion_1.z.ZodFirstPartyTypeKind.ZodNull ||
|
|
19
|
+
otherSchema._def.typeName === remotion_1.z.ZodFirstPartyTypeKind.ZodUndefined;
|
|
20
|
+
return {
|
|
21
|
+
nullIndex,
|
|
22
|
+
nullishValue,
|
|
23
|
+
otherSchema,
|
|
24
|
+
otherSchemaIsAlsoNullish,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const ZodUnionEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, }) => {
|
|
28
|
+
const { options } = schema._def;
|
|
29
|
+
if (options.length > 2) {
|
|
30
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union with more than 2 options not editable', compact: compact, showSaveButton: showSaveButton }));
|
|
31
|
+
}
|
|
32
|
+
if (options.length < 2) {
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union with less than 2 options not editable', compact: compact, showSaveButton: showSaveButton }));
|
|
34
|
+
}
|
|
35
|
+
const nullResult = findNull(options);
|
|
36
|
+
if (!nullResult) {
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Union only editable with 1 value being null', compact: compact, showSaveButton: showSaveButton }));
|
|
38
|
+
}
|
|
39
|
+
const { otherSchema, nullishValue, otherSchemaIsAlsoNullish } = nullResult;
|
|
40
|
+
if (otherSchemaIsAlsoNullish) {
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(ZodNonEditableValue_1.ZonNonEditableValue, { jsonPath: jsonPath, label: 'Not editable - both union values are nullish', compact: compact, showSaveButton: showSaveButton }));
|
|
42
|
+
}
|
|
43
|
+
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 }));
|
|
44
|
+
};
|
|
45
|
+
exports.ZodUnionEditor = ZodUnionEditor;
|