@remotion/cli 4.0.0-alpha.217 → 4.0.0-alpha10
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 +11 -6
- package/dist/better-opn/index.js +3 -3
- package/dist/chalk/index.d.ts +45 -54
- package/dist/chalk/index.js +2 -135
- package/dist/codemods/stringify-with-path.d.ts +5 -0
- package/dist/codemods/stringify-with-path.js +44 -0
- package/dist/codemods/update-default-props.d.ts +4 -2
- package/dist/codemods/update-default-props.js +3 -18
- package/dist/color-math.d.ts +2 -2
- package/dist/color-math.js +5 -3
- package/dist/compositions.js +1 -0
- package/dist/config/image-format.d.ts +1 -1
- package/dist/config/index.d.ts +2 -2
- package/dist/config/log.d.ts +1 -3
- package/dist/config/log.js +2 -9
- package/dist/convert-entry-point-to-serve-url.js +2 -2
- package/dist/download-progress.d.ts +1 -1
- package/dist/download-progress.js +1 -4
- package/dist/editor/components/CanvasOrLoading.d.ts +5 -0
- package/dist/editor/components/CanvasOrLoading.js +66 -0
- package/dist/editor/components/CheckboardToggle.js +2 -1
- package/dist/editor/components/CompositionSelectorItem.js +2 -2
- package/dist/editor/components/CurrentCompositionSideEffects.js +3 -3
- package/dist/editor/components/InitialCompositionLoader.js +1 -1
- package/dist/editor/components/InlineAction.d.ts +6 -4
- package/dist/editor/components/InlineAction.js +7 -8
- package/dist/editor/components/LoopToggle.js +2 -1
- package/dist/editor/components/Menu/MenuItem.js +1 -1
- package/dist/editor/components/Menu/SubMenu.js +1 -1
- package/dist/editor/components/Menu/styles.d.ts +1 -0
- package/dist/editor/components/Menu/styles.js +6 -1
- package/dist/editor/components/MenuBuildIndicator.js +20 -1
- package/dist/editor/components/MenuToolbar.js +15 -3
- package/dist/editor/components/Modals.js +2 -2
- package/dist/editor/components/NewComposition/ComboBox.js +20 -5
- package/dist/editor/components/NewComposition/InputDragger.js +3 -2
- package/dist/editor/components/NewComposition/MenuContent.d.ts +1 -0
- package/dist/editor/components/NewComposition/MenuContent.js +12 -4
- package/dist/editor/components/Notifications/ServerDisconnected.js +2 -2
- package/dist/editor/components/OpenEditorButton.d.ts +2 -0
- package/dist/editor/components/OpenEditorButton.js +52 -0
- package/dist/editor/components/PlayPause.js +4 -2
- package/dist/editor/components/PreviewToolbar.js +2 -2
- package/dist/editor/components/QuickSwitcher/algolia-search.js +1 -1
- package/dist/editor/components/RenderButton.d.ts +1 -5
- package/dist/editor/components/RenderButton.js +48 -21
- package/dist/editor/components/RenderModal/CliCopyButton.js +51 -14
- package/dist/editor/components/RenderModal/CrfSetting.d.ts +0 -1
- package/dist/editor/components/RenderModal/CrfSetting.js +0 -1
- package/dist/editor/components/RenderModal/DataEditor.d.ts +21 -0
- package/dist/editor/components/RenderModal/DataEditor.js +287 -0
- package/dist/editor/components/RenderModal/EnforceAudioTrackSetting.js +3 -2
- package/dist/editor/components/RenderModal/InfoBubble.js +2 -1
- package/dist/editor/components/RenderModal/InfoTooltip.d.ts +1 -0
- package/dist/editor/components/RenderModal/InfoTooltip.js +6 -5
- package/dist/editor/components/RenderModal/InlineEyeIcon.js +6 -3
- package/dist/editor/components/RenderModal/InlineRemoveButton.js +6 -1
- package/dist/editor/components/RenderModal/MutedSetting.js +3 -2
- package/dist/editor/components/RenderModal/OptionExplainer.js +14 -3
- package/dist/editor/components/RenderModal/RenderModal.d.ts +7 -3
- package/dist/editor/components/RenderModal/RenderModal.js +108 -49
- package/dist/editor/components/RenderModal/RenderModalAdvanced.js +0 -2
- package/dist/editor/components/RenderModal/RenderModalAudio.js +1 -1
- package/dist/editor/components/RenderModal/RenderModalBasic.d.ts +3 -2
- package/dist/editor/components/RenderModal/RenderModalBasic.js +4 -3
- package/dist/editor/components/RenderModal/RenderModalData.d.ts +16 -4
- package/dist/editor/components/RenderModal/RenderModalData.js +109 -42
- package/dist/editor/components/RenderModal/RenderModalJSONPropsEditor.d.ts +14 -0
- package/dist/editor/components/RenderModal/{RenderModalJSONInputPropsEditor.js → RenderModalJSONPropsEditor.js} +51 -30
- package/dist/editor/components/RenderModal/RenderModalPicture.d.ts +2 -2
- package/dist/editor/components/RenderModal/RenderModalPicture.js +2 -4
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaEditor.d.ts +6 -4
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaEditor.js +4 -4
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.d.ts +4 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.js +15 -6
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaLabel.d.ts +5 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaLabel.js +5 -4
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaResetButton.js +6 -1
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaSaveButton.d.ts +1 -0
- package/dist/editor/components/RenderModal/SchemaEditor/SchemaSaveButton.js +7 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.js +19 -29
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayItemEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodArrayItemEditor.js +4 -4
- package/dist/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodBooleanEditor.js +7 -7
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodColorEditor.js +23 -66
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDateEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDateEditor.js +13 -21
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDefaultEditor.d.ts +17 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodDefaultEditor.js +10 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.d.ts +4 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEffectEditor.js +20 -19
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEnumEditor.d.ts +4 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodEnumEditor.js +12 -26
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNonEditableValue.d.ts +1 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNonEditableValue.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNullableEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNullableEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNumberEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodNumberEditor.js +16 -32
- package/dist/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.d.ts +7 -4
- package/dist/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.js +18 -11
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOptionalEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOptionalEditor.js +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodOrNullishEditor.js +44 -11
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStaticFileEditor.d.ts +17 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStaticFileEditor.js +59 -0
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStringEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodStringEditor.js +12 -23
- package/dist/editor/components/RenderModal/SchemaEditor/ZodSwitch.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodSwitch.js +32 -21
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +5 -2
- package/dist/editor/components/RenderModal/SchemaEditor/ZodUnionEditor.js +6 -6
- package/dist/editor/components/RenderModal/SchemaEditor/create-zod-values.d.ts +2 -2
- package/dist/editor/components/RenderModal/SchemaEditor/create-zod-values.js +22 -22
- package/dist/editor/components/RenderModal/SchemaEditor/deep-equal.d.ts +1 -0
- package/dist/editor/components/RenderModal/SchemaEditor/deep-equal.js +27 -0
- package/dist/editor/components/RenderModal/SchemaEditor/extract-enum-json-paths.d.ts +3 -0
- package/dist/editor/components/RenderModal/SchemaEditor/extract-enum-json-paths.js +126 -0
- package/dist/editor/components/RenderModal/SchemaEditor/input-props-serialization.d.ts +14 -0
- package/dist/editor/components/RenderModal/SchemaEditor/input-props-serialization.js +42 -0
- package/dist/editor/components/RenderModal/SchemaEditor/local-state.d.ts +16 -0
- package/dist/editor/components/RenderModal/SchemaEditor/local-state.js +38 -0
- package/dist/editor/components/RenderModal/get-render-modal-warnings.d.ts +9 -1
- package/dist/editor/components/RenderModal/get-render-modal-warnings.js +42 -8
- package/dist/editor/components/RenderModal/human-readable-codec.d.ts +1 -1
- package/dist/editor/components/RenderModal/layout.js +3 -0
- package/dist/editor/components/RenderModal/out-name-checker.js +1 -11
- package/dist/editor/components/RenderQueue/RenderQueueItemCancelButton.js +5 -1
- package/dist/editor/components/RenderQueue/RenderQueueOpenInFolder.js +5 -1
- package/dist/editor/components/RenderQueue/RenderQueueRemoveItem.js +5 -1
- package/dist/editor/components/RenderQueue/RenderQueueRepeat.js +5 -1
- package/dist/editor/components/RenderQueue/actions.d.ts +4 -3
- package/dist/editor/components/RenderQueue/actions.js +8 -3
- package/dist/editor/components/RenderQueue/index.js +9 -2
- package/dist/editor/components/RightPanel.js +8 -5
- package/dist/editor/components/SidebarCollapserControls.js +22 -9
- package/dist/editor/components/SidebarRenderButton.d.ts +6 -0
- package/dist/editor/components/{RenderToolbarIcon.js → SidebarRenderButton.js} +27 -41
- package/dist/editor/components/Spinner.d.ts +5 -0
- package/dist/editor/components/Spinner.js +41 -0
- package/dist/editor/components/Tabs/index.js +12 -14
- package/dist/editor/components/Timeline/Timeline.js +3 -1
- package/dist/editor/components/Timeline/TimelinePlayCursorSyncer.js +4 -3
- package/dist/editor/components/Timeline/TimelineSequence.js +8 -6
- package/dist/editor/components/TimelineInOutToggle.js +2 -4
- package/dist/editor/components/TopPanel.js +2 -2
- package/dist/editor/components/UpdateCheck.js +2 -1
- package/dist/editor/components/get-zod-if-possible.d.ts +3 -3
- package/dist/editor/components/get-zod-if-possible.js +11 -11
- package/dist/editor/helpers/calculate-timeline.js +1 -1
- package/dist/editor/helpers/client-id.d.ts +2 -2
- package/dist/editor/helpers/client-id.js +5 -5
- package/dist/editor/helpers/colors.d.ts +4 -2
- package/dist/editor/helpers/colors.js +4 -2
- package/dist/editor/helpers/get-timeline-sequence-layout.d.ts +2 -2
- package/dist/editor/helpers/is-composition-still.d.ts +3 -2
- package/dist/editor/helpers/is-current-selected-still.js +3 -4
- package/dist/editor/helpers/use-file-existence.js +1 -1
- package/dist/editor/helpers/use-menu-structure.js +1 -1
- package/dist/editor/icons/media-volume.js +2 -1
- package/dist/editor/icons/render.d.ts +1 -0
- package/dist/editor/icons/render.js +1 -1
- package/dist/editor/state/modals.d.ts +3 -1
- package/dist/entry-point.js +17 -17
- package/dist/event-source-events.d.ts +2 -0
- package/dist/event-source.js +2 -2
- package/dist/ffmpeg.js +14 -5
- package/dist/file-watcher.js +5 -5
- package/dist/get-cli-options.d.ts +3 -3
- package/dist/get-cli-options.js +4 -4
- package/dist/get-composition-id.d.ts +14 -2
- package/dist/get-composition-id.js +32 -8
- package/dist/get-composition-with-dimension-override.d.ts +13 -2
- package/dist/get-composition-with-dimension-override.js +12 -2
- package/dist/get-config-file-name.js +6 -6
- package/dist/get-env.js +10 -10
- package/dist/get-filename.js +1 -0
- package/dist/get-input-props.d.ts +1 -1
- package/dist/get-input-props.js +9 -9
- package/dist/get-network-address.js +2 -2
- package/dist/handle-common-errors.d.ts +2 -1
- package/dist/handle-common-errors.js +2 -2
- package/dist/index.d.ts +41 -19
- package/dist/index.js +9 -6
- package/dist/list-of-remotion-packages.js +2 -1
- package/dist/load-config.js +8 -8
- package/dist/log.d.ts +5 -5
- package/dist/log.js +3 -42
- package/dist/parse-command-line.d.ts +1 -0
- package/dist/preview-server/api-types.d.ts +3 -3
- package/dist/preview-server/dev-middleware/compatible-api.d.ts +2 -2
- package/dist/preview-server/dev-middleware/middleware.d.ts +1 -1
- package/dist/preview-server/dev-middleware/middleware.js +7 -7
- package/dist/preview-server/dev-middleware/range-parser.d.ts +1 -1
- package/dist/preview-server/dev-middleware/setup-hooks.js +2 -2
- package/dist/preview-server/error-overlay/react-overlay/utils/get-file-source.js +5 -5
- package/dist/preview-server/error-overlay/react-overlay/utils/open-in-editor.js +17 -17
- package/dist/preview-server/error-overlay/remotion-overlay/CalculateMetadataErrorExplainer.d.ts +2 -0
- package/dist/preview-server/error-overlay/remotion-overlay/CalculateMetadataErrorExplainer.js +18 -0
- package/dist/preview-server/error-overlay/remotion-overlay/CodeFrame.js +30 -12
- package/dist/preview-server/error-overlay/remotion-overlay/ErrorDisplay.d.ts +4 -0
- package/dist/preview-server/error-overlay/remotion-overlay/ErrorDisplay.js +5 -2
- package/dist/preview-server/error-overlay/remotion-overlay/ErrorLoader.d.ts +4 -0
- package/dist/preview-server/error-overlay/remotion-overlay/ErrorLoader.js +5 -5
- package/dist/preview-server/error-overlay/remotion-overlay/ErrorTitle.d.ts +1 -0
- package/dist/preview-server/error-overlay/remotion-overlay/ErrorTitle.js +4 -3
- package/dist/preview-server/error-overlay/remotion-overlay/HelpLink.js +2 -1
- package/dist/preview-server/error-overlay/remotion-overlay/Overlay.js +1 -1
- package/dist/preview-server/error-overlay/remotion-overlay/Retry.d.ts +4 -0
- package/dist/preview-server/error-overlay/remotion-overlay/Retry.js +9 -0
- package/dist/preview-server/file-existence-watchers.js +3 -3
- package/dist/preview-server/get-absolute-public-dir.js +3 -3
- package/dist/preview-server/get-package-manager.js +3 -3
- package/dist/preview-server/handler.d.ts +1 -1
- package/dist/preview-server/hot-middleware/index.d.ts +1 -1
- package/dist/preview-server/hot-middleware/index.js +2 -2
- package/dist/preview-server/live-events.d.ts +1 -1
- package/dist/preview-server/parse-body.d.ts +1 -1
- package/dist/preview-server/project-info.js +5 -5
- package/dist/preview-server/public-folder.js +8 -8
- package/dist/preview-server/render-queue/job.d.ts +11 -2
- package/dist/preview-server/render-queue/make-retry-payload.js +5 -1
- package/dist/preview-server/render-queue/open-directory-in-finder.js +8 -8
- package/dist/preview-server/render-queue/process-still.js +1 -0
- package/dist/preview-server/render-queue/queue.js +4 -4
- package/dist/preview-server/routes/can-update-default-props.js +3 -2
- package/dist/preview-server/routes/update-default-props.d.ts +2 -2
- package/dist/preview-server/routes/update-default-props.js +26 -15
- package/dist/preview-server/routes.d.ts +3 -2
- package/dist/preview-server/routes.js +10 -10
- package/dist/preview-server/serve-static.d.ts +1 -1
- package/dist/preview-server/serve-static.js +7 -7
- package/dist/preview-server/start-server.js +3 -3
- package/dist/preview.js +6 -4
- package/dist/print-error.d.ts +2 -1
- package/dist/print-error.js +8 -5
- package/dist/print-help.js +1 -1
- package/dist/progress-bar.d.ts +5 -4
- package/dist/progress-bar.js +42 -29
- package/dist/render-flows/render.d.ts +1 -1
- package/dist/render-flows/render.js +62 -35
- package/dist/render-flows/still.d.ts +3 -2
- package/dist/render-flows/still.js +34 -28
- package/dist/resolve-from.js +5 -5
- package/dist/setup-cache.d.ts +2 -1
- package/dist/setup-cache.js +10 -6
- package/dist/should-use-non-overlaying-logger.d.ts +4 -0
- package/dist/should-use-non-overlaying-logger.js +12 -0
- package/dist/show-compositions-picker.d.ts +8 -0
- package/dist/show-compositions-picker.js +51 -0
- package/dist/still.js +1 -0
- package/dist/studio.d.ts +1 -0
- package/dist/studio.js +140 -0
- package/dist/upgrade.js +2 -2
- package/dist/user-passed-output-location.d.ts +3 -2
- package/dist/user-passed-output-location.js +10 -5
- package/dist/versions.js +2 -2
- package/dist/watch-root-file.d.ts +1 -0
- package/dist/watch-root-file.js +22 -0
- package/package.json +89 -88
- package/styles/styles.css +4 -5
- package/dist/editor/components/CollapsableOptions.d.ts +0 -6
- package/dist/editor/components/CollapsableOptions.js +0 -35
- package/dist/editor/components/RenderModal/RenderModalJSONInputPropsEditor.d.ts +0 -10
- package/dist/editor/components/RenderModal/SchemaEditor/date-serialization.d.ts +0 -2
- package/dist/editor/components/RenderModal/SchemaEditor/date-serialization.js +0 -21
- package/dist/editor/components/RenderToolbarIcon.d.ts +0 -2
- package/dist/editor/icons/RenderStillIcon.d.ts +0 -3
- package/dist/editor/icons/RenderStillIcon.js +0 -8
|
@@ -9,21 +9,20 @@ const layout_1 = require("../../layout");
|
|
|
9
9
|
const ComboBox_1 = require("../../NewComposition/ComboBox");
|
|
10
10
|
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
11
11
|
const layout_2 = require("../layout");
|
|
12
|
+
const local_state_1 = require("./local-state");
|
|
12
13
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
13
14
|
const container = {
|
|
14
15
|
width: '100%',
|
|
15
16
|
};
|
|
16
|
-
const ZodEnumEditor = ({ schema, jsonPath, compact, setValue
|
|
17
|
+
const ZodEnumEditor = ({ schema, jsonPath, compact, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, }) => {
|
|
17
18
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
18
19
|
if (!z) {
|
|
19
20
|
throw new Error('expected zod');
|
|
20
21
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
revision: 0,
|
|
26
|
-
};
|
|
22
|
+
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
23
|
+
schema,
|
|
24
|
+
setValue,
|
|
25
|
+
value,
|
|
27
26
|
});
|
|
28
27
|
const def = schema._def;
|
|
29
28
|
const typeName = def.typeName;
|
|
@@ -31,22 +30,9 @@ const ZodEnumEditor = ({ schema, jsonPath, compact, setValue: updateValue, defau
|
|
|
31
30
|
throw new Error('expected enum');
|
|
32
31
|
}
|
|
33
32
|
const isRoot = jsonPath.length === 0;
|
|
34
|
-
const onChange = (0, react_1.useCallback)((updater) => {
|
|
35
|
-
setLocalValue((oldLocalState) => {
|
|
36
|
-
const newValue = updater(oldLocalState.value);
|
|
37
|
-
const safeParse = schema.safeParse(newValue);
|
|
38
|
-
if (safeParse.success) {
|
|
39
|
-
updateValue(updater);
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
value: newValue,
|
|
43
|
-
zodValidation: safeParse,
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
}, [schema, updateValue]);
|
|
47
33
|
const reset = (0, react_1.useCallback)(() => {
|
|
48
|
-
|
|
49
|
-
}, [defaultValue,
|
|
34
|
+
setLocalValue(() => defaultValue, true);
|
|
35
|
+
}, [defaultValue, setLocalValue]);
|
|
50
36
|
const comboBoxValues = (0, react_1.useMemo)(() => {
|
|
51
37
|
return def.values.map((option) => {
|
|
52
38
|
return {
|
|
@@ -56,17 +42,17 @@ const ZodEnumEditor = ({ schema, jsonPath, compact, setValue: updateValue, defau
|
|
|
56
42
|
keyHint: null,
|
|
57
43
|
leftItem: option === value ? (0, jsx_runtime_1.jsx)(Checkmark_1.Checkmark, {}) : null,
|
|
58
44
|
onClick: (id) => {
|
|
59
|
-
|
|
45
|
+
setLocalValue(() => id, false);
|
|
60
46
|
},
|
|
61
47
|
quickSwitcherLabel: null,
|
|
62
48
|
subMenu: null,
|
|
63
49
|
type: 'item',
|
|
64
50
|
};
|
|
65
51
|
});
|
|
66
|
-
}, [def.values,
|
|
52
|
+
}, [def.values, setLocalValue, value]);
|
|
67
53
|
const save = (0, react_1.useCallback)(() => {
|
|
68
|
-
onSave(() => value);
|
|
54
|
+
onSave(() => value, false);
|
|
69
55
|
}, [onSave, value]);
|
|
70
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { onSave: save, showSaveButton: showSaveButton, isDefaultValue: value === defaultValue, compact: compact, onReset: reset, jsonPath: jsonPath, onRemove: onRemove }), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: (0, jsx_runtime_1.jsx)(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: value, title: value }) }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] }));
|
|
56
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { onSave: save, showSaveButton: showSaveButton, isDefaultValue: value === defaultValue, compact: compact, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: !localValue.zodValidation.success }), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: (0, jsx_runtime_1.jsx)(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: value, title: value }) }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] }));
|
|
71
57
|
};
|
|
72
58
|
exports.ZodEnumEditor = ZodEnumEditor;
|
|
@@ -19,9 +19,9 @@ const wideEmptyLabel = {
|
|
|
19
19
|
...emptyLabel,
|
|
20
20
|
lineHeight: '37px',
|
|
21
21
|
};
|
|
22
|
-
const ZonNonEditableValue = ({ jsonPath, label, compact, showSaveButton }) => {
|
|
22
|
+
const ZonNonEditableValue = ({ jsonPath, label, compact, showSaveButton, saving }) => {
|
|
23
23
|
const save = (0, react_1.useCallback)(() => undefined, []);
|
|
24
24
|
const reset = (0, react_1.useCallback)(() => undefined, []);
|
|
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 }) })] }));
|
|
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, saving: saving, valid: true, saveDisabledByParent: true }), (0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsx)("em", { style: compact ? emptyLabel : wideEmptyLabel, children: label }) })] }));
|
|
26
26
|
};
|
|
27
27
|
exports.ZonNonEditableValue = ZonNonEditableValue;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodNullableEditor: React.FC<{
|
|
5
6
|
showSaveButton: boolean;
|
|
6
7
|
jsonPath: JSONPath;
|
|
@@ -8,7 +9,9 @@ export declare const ZodNullableEditor: React.FC<{
|
|
|
8
9
|
value: unknown;
|
|
9
10
|
defaultValue: unknown;
|
|
10
11
|
schema: z.ZodTypeAny;
|
|
11
|
-
setValue:
|
|
12
|
-
onSave:
|
|
12
|
+
setValue: UpdaterFunction<unknown>;
|
|
13
|
+
onSave: UpdaterFunction<unknown>;
|
|
13
14
|
onRemove: null | (() => void);
|
|
15
|
+
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
14
17
|
}>;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ZodNullableEditor = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const ZodOrNullishEditor_1 = require("./ZodOrNullishEditor");
|
|
6
|
-
const ZodNullableEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, }) => {
|
|
6
|
+
const ZodNullableEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
7
7
|
const { innerType } = schema._def;
|
|
8
|
-
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: null }));
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: null, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
9
9
|
};
|
|
10
10
|
exports.ZodNullableEditor = ZodNullableEditor;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodNumberEditor: React.FC<{
|
|
5
6
|
schema: z.ZodTypeAny;
|
|
6
7
|
jsonPath: JSONPath;
|
|
7
8
|
value: number;
|
|
8
|
-
setValue:
|
|
9
|
+
setValue: UpdaterFunction<number>;
|
|
9
10
|
compact: boolean;
|
|
10
11
|
defaultValue: number;
|
|
11
|
-
onSave:
|
|
12
|
+
onSave: UpdaterFunction<number>;
|
|
12
13
|
onRemove: null | (() => void);
|
|
13
14
|
showSaveButton: boolean;
|
|
15
|
+
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
14
17
|
}>;
|
|
@@ -7,6 +7,7 @@ const layout_1 = require("../../layout");
|
|
|
7
7
|
const InputDragger_1 = require("../../NewComposition/InputDragger");
|
|
8
8
|
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
9
9
|
const layout_2 = require("../layout");
|
|
10
|
+
const local_state_1 = require("./local-state");
|
|
10
11
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
11
12
|
const fullWidth = {
|
|
12
13
|
width: '100%',
|
|
@@ -47,42 +48,25 @@ const getStep = (schema) => {
|
|
|
47
48
|
}
|
|
48
49
|
return multipleStep.value;
|
|
49
50
|
};
|
|
50
|
-
const ZodNumberEditor = ({ jsonPath, value, schema, setValue, onSave, compact, defaultValue, onRemove, showSaveButton, }) => {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
51
|
+
const ZodNumberEditor = ({ jsonPath, value, schema, setValue, onSave, compact, defaultValue, onRemove, showSaveButton, saving, saveDisabledByParent, }) => {
|
|
52
|
+
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
53
|
+
value,
|
|
54
|
+
schema,
|
|
55
|
+
setValue,
|
|
56
56
|
});
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
value: newValue,
|
|
61
|
-
zodValidation: safeParse,
|
|
62
|
-
};
|
|
63
|
-
setLocalValue(newLocalState);
|
|
64
|
-
if (safeParse.success) {
|
|
65
|
-
setValue(Number(newValue));
|
|
66
|
-
}
|
|
67
|
-
}, [schema, setValue]);
|
|
68
|
-
const onValueChange = (0, react_1.useCallback)((newValue) => {
|
|
69
|
-
const safeParse = schema.safeParse(newValue);
|
|
70
|
-
const newLocalState = {
|
|
71
|
-
value: String(newValue),
|
|
72
|
-
zodValidation: safeParse,
|
|
73
|
-
};
|
|
74
|
-
setLocalValue(newLocalState);
|
|
75
|
-
if (safeParse.success) {
|
|
76
|
-
setValue(newValue);
|
|
77
|
-
}
|
|
78
|
-
}, [schema, setValue]);
|
|
57
|
+
const onNumberChange = (0, react_1.useCallback)((newValue) => {
|
|
58
|
+
setLocalValue(() => newValue, false);
|
|
59
|
+
}, [setLocalValue]);
|
|
79
60
|
const isDefault = value === defaultValue;
|
|
80
61
|
const reset = (0, react_1.useCallback)(() => {
|
|
81
|
-
|
|
82
|
-
}, [defaultValue,
|
|
62
|
+
setLocalValue(() => defaultValue, true);
|
|
63
|
+
}, [defaultValue, setLocalValue]);
|
|
64
|
+
const onTextChange = (0, react_1.useCallback)((newValue) => {
|
|
65
|
+
setLocalValue(() => Number(newValue), false);
|
|
66
|
+
}, [setLocalValue]);
|
|
83
67
|
const save = (0, react_1.useCallback)(() => {
|
|
84
|
-
onSave(() => value);
|
|
68
|
+
onSave(() => value, false);
|
|
85
69
|
}, [onSave, value]);
|
|
86
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: isDefault, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(InputDragger_1.InputDragger, { type: 'number', value: localValue.value, style: fullWidth, status: localValue.zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onTextChange:
|
|
70
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: isDefault, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(InputDragger_1.InputDragger, { type: 'number', value: localValue.value, style: fullWidth, status: localValue.zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onTextChange: onTextChange, onValueChange: onNumberChange, min: getMinValue(schema), max: getMaxValue(schema), step: getStep(schema), rightAlign: false }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] })] }));
|
|
87
71
|
};
|
|
88
72
|
exports.ZodNumberEditor = ZodNumberEditor;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodObjectEditor: React.FC<{
|
|
5
6
|
schema: z.ZodTypeAny;
|
|
6
7
|
jsonPath: JSONPath;
|
|
7
|
-
value: unknown
|
|
8
|
-
defaultValue: unknown
|
|
9
|
-
setValue:
|
|
8
|
+
value: Record<string, unknown>;
|
|
9
|
+
defaultValue: Record<string, unknown>;
|
|
10
|
+
setValue: UpdaterFunction<Record<string, unknown>>;
|
|
10
11
|
compact: boolean;
|
|
11
|
-
onSave:
|
|
12
|
+
onSave: UpdaterFunction<Record<string, unknown>>;
|
|
12
13
|
showSaveButton: boolean;
|
|
13
14
|
onRemove: null | (() => void);
|
|
15
|
+
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
14
17
|
}>;
|
|
@@ -6,6 +6,7 @@ const react_1 = require("react");
|
|
|
6
6
|
const colors_1 = require("../../../helpers/colors");
|
|
7
7
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
8
8
|
const layout_1 = require("../layout");
|
|
9
|
+
const local_state_1 = require("./local-state");
|
|
9
10
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
10
11
|
const ZodSwitch_1 = require("./ZodSwitch");
|
|
11
12
|
const container = {
|
|
@@ -18,12 +19,16 @@ const fieldset = {
|
|
|
18
19
|
borderRadius: 4,
|
|
19
20
|
borderColor: colors_1.INPUT_BORDER_COLOR_UNHOVERED,
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
-
const ZodObjectEditor = ({ schema, jsonPath, setValue, value, compact, defaultValue, onSave, showSaveButton, onRemove, }) => {
|
|
22
|
+
const ZodObjectEditor = ({ schema, jsonPath, setValue, value, compact, defaultValue, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
23
23
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
24
24
|
if (!z) {
|
|
25
25
|
throw new Error('expected zod');
|
|
26
26
|
}
|
|
27
|
+
const { localValue, onChange } = (0, local_state_1.useLocalState)({
|
|
28
|
+
schema,
|
|
29
|
+
setValue,
|
|
30
|
+
value,
|
|
31
|
+
});
|
|
27
32
|
const def = schema._def;
|
|
28
33
|
const typeName = def.typeName;
|
|
29
34
|
if (typeName !== z.ZodFirstPartyTypeKind.ZodObject) {
|
|
@@ -40,25 +45,27 @@ const ZodObjectEditor = ({ schema, jsonPath, setValue, value, compact, defaultVa
|
|
|
40
45
|
}
|
|
41
46
|
return { paddingTop };
|
|
42
47
|
}, [isRoot, paddingTop]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
const onRes = (0, react_1.useCallback)(() => {
|
|
49
|
+
onChange(() => defaultValue, true);
|
|
50
|
+
}, [defaultValue, onChange]);
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: style, children: (0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsxs)(Element, { style: fieldset, children: [isRoot ? null : ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaFieldsetLabel, { isDefaultValue: true, onReset: onRes, jsonPath: jsonPath, onRemove: onRemove })), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: keys.map((key) => {
|
|
52
|
+
return ((0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { jsonPath: [...jsonPath, key], schema: shape[key], value: localValue.value[key],
|
|
46
53
|
// In case of null | {a: string, b: string} type, we need to fallback to the default value
|
|
47
|
-
defaultValue: (
|
|
48
|
-
|
|
54
|
+
defaultValue: (defaultValue !== null && defaultValue !== void 0 ? defaultValue : value)[key], setValue: (val, forceApply) => {
|
|
55
|
+
onChange((oldVal) => {
|
|
49
56
|
return {
|
|
50
57
|
...oldVal,
|
|
51
58
|
[key]: typeof val === 'function' ? val(oldVal[key]) : val,
|
|
52
59
|
};
|
|
53
|
-
});
|
|
54
|
-
}, onSave: (val) => {
|
|
60
|
+
}, forceApply);
|
|
61
|
+
}, onSave: (val, forceApply) => {
|
|
55
62
|
onSave((oldVal) => {
|
|
56
63
|
return {
|
|
57
64
|
...oldVal,
|
|
58
65
|
[key]: typeof val === 'function' ? val(oldVal[key]) : val,
|
|
59
66
|
};
|
|
60
|
-
});
|
|
61
|
-
}, onRemove: null, compact: compact, showSaveButton: showSaveButton }, key));
|
|
67
|
+
}, forceApply);
|
|
68
|
+
}, onRemove: null, compact: compact, showSaveButton: showSaveButton, saving: saving, saveDisabledByParent: saveDisabledByParent }, key));
|
|
62
69
|
}) })] }) }) }));
|
|
63
70
|
};
|
|
64
71
|
exports.ZodObjectEditor = ZodObjectEditor;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodOptionalEditor: React.FC<{
|
|
5
6
|
showSaveButton: boolean;
|
|
6
7
|
jsonPath: JSONPath;
|
|
@@ -8,7 +9,9 @@ export declare const ZodOptionalEditor: React.FC<{
|
|
|
8
9
|
value: unknown;
|
|
9
10
|
defaultValue: unknown;
|
|
10
11
|
schema: z.ZodTypeAny;
|
|
11
|
-
setValue:
|
|
12
|
-
onSave:
|
|
12
|
+
setValue: UpdaterFunction<unknown>;
|
|
13
|
+
onSave: UpdaterFunction<unknown>;
|
|
13
14
|
onRemove: null | (() => void);
|
|
15
|
+
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
14
17
|
}>;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ZodOptionalEditor = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const ZodOrNullishEditor_1 = require("./ZodOrNullishEditor");
|
|
6
|
-
const ZodOptionalEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, }) => {
|
|
6
|
+
const ZodOptionalEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
7
7
|
const { innerType } = schema._def;
|
|
8
|
-
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: undefined }));
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(ZodOrNullishEditor_1.ZodOrNullishEditor, { compact: compact, defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: undefined, saving: saving, saveDisabledByParent: saveDisabledByParent }));
|
|
9
9
|
};
|
|
10
10
|
exports.ZodOptionalEditor = ZodOptionalEditor;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodOrNullishEditor: React.FC<{
|
|
5
6
|
showSaveButton: boolean;
|
|
6
7
|
jsonPath: JSONPath;
|
|
@@ -8,8 +9,10 @@ export declare const ZodOrNullishEditor: React.FC<{
|
|
|
8
9
|
value: unknown;
|
|
9
10
|
defaultValue: unknown;
|
|
10
11
|
schema: z.ZodTypeAny;
|
|
11
|
-
setValue:
|
|
12
|
-
onSave:
|
|
12
|
+
setValue: UpdaterFunction<unknown>;
|
|
13
|
+
onSave: UpdaterFunction<unknown>;
|
|
13
14
|
onRemove: null | (() => void);
|
|
14
15
|
nullishValue: null | undefined;
|
|
16
|
+
saving: boolean;
|
|
17
|
+
saveDisabledByParent: boolean;
|
|
15
18
|
}>;
|
|
@@ -25,28 +25,61 @@ const checkBoxWrapper = {
|
|
|
25
25
|
alignItems: 'center',
|
|
26
26
|
marginTop: '5px',
|
|
27
27
|
};
|
|
28
|
-
const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, nullishValue, }) => {
|
|
28
|
+
const ZodOrNullishEditor = ({ jsonPath, compact, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, nullishValue, saving, saveDisabledByParent, }) => {
|
|
29
29
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
30
30
|
if (!z) {
|
|
31
31
|
throw new Error('expected zod');
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
|
|
34
34
|
const isChecked = value === nullishValue;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const [localNonNullishValueValue, setLocalNonNullishValue] = (0, react_1.useState)(() => {
|
|
36
|
+
return {
|
|
37
|
+
value,
|
|
38
|
+
zodValidation: value === nullishValue
|
|
39
|
+
? { success: true, data: value }
|
|
40
|
+
: schema.safeParse(value),
|
|
41
|
+
};
|
|
42
|
+
});
|
|
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]);
|
|
38
56
|
const onCheckBoxChange = (0, react_1.useCallback)((e) => {
|
|
39
57
|
const val = e.target.checked
|
|
40
58
|
? nullishValue
|
|
41
|
-
:
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
: localNonNullishValueValue.value === nullishValue
|
|
60
|
+
? (0, create_zod_values_1.createZodValues)(schema, z, zodTypes)
|
|
61
|
+
: localNonNullishValueValue.value;
|
|
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
|
+
]);
|
|
44
77
|
const reset = (0, react_1.useCallback)(() => {
|
|
45
|
-
onValueChange(defaultValue);
|
|
78
|
+
onValueChange(() => defaultValue, true);
|
|
46
79
|
}, [defaultValue, onValueChange]);
|
|
47
80
|
const save = (0, react_1.useCallback)(() => {
|
|
48
|
-
onSave(() => value);
|
|
81
|
+
onSave(() => value, false);
|
|
49
82
|
}, [onSave, value]);
|
|
50
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [value === nullishValue ? ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove })) : ((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) })] })] }));
|
|
83
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [value === nullishValue ? ((0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { isDefaultValue: value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, compact: compact, onRemove: onRemove, saving: saving, valid: localNonNullishValueValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent })) : ((0, jsx_runtime_1.jsx)("div", { style: fullWidth, children: (0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { value: value, setValue: onValueChange, jsonPath: jsonPath, schema: schema, compact: compact, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: saveDisabledByParent }) })), (0, jsx_runtime_1.jsxs)("div", { style: checkBoxWrapper, children: [(0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { checked: isChecked, onChange: onCheckBoxChange, disabled: false }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)("div", { style: labelStyle, children: String(nullishValue) })] })] }));
|
|
51
84
|
};
|
|
52
85
|
exports.ZodOrNullishEditor = ZodOrNullishEditor;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
5
|
+
export declare const ZodStaticFileEditor: React.FC<{
|
|
6
|
+
schema: z.ZodTypeAny;
|
|
7
|
+
jsonPath: JSONPath;
|
|
8
|
+
value: string;
|
|
9
|
+
defaultValue: string;
|
|
10
|
+
setValue: UpdaterFunction<string>;
|
|
11
|
+
onSave: (updater: (oldState: string) => string) => void;
|
|
12
|
+
compact: boolean;
|
|
13
|
+
showSaveButton: boolean;
|
|
14
|
+
onRemove: null | (() => void);
|
|
15
|
+
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZodStaticFileEditor = 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 Checkmark_1 = require("../../../icons/Checkmark");
|
|
8
|
+
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
9
|
+
const layout_1 = require("../../layout");
|
|
10
|
+
const ComboBox_1 = require("../../NewComposition/ComboBox");
|
|
11
|
+
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
12
|
+
const layout_2 = require("../layout");
|
|
13
|
+
const local_state_1 = require("./local-state");
|
|
14
|
+
const SchemaLabel_1 = require("./SchemaLabel");
|
|
15
|
+
const container = {
|
|
16
|
+
width: '100%',
|
|
17
|
+
};
|
|
18
|
+
const ZodStaticFileEditor = ({ schema, jsonPath, compact, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, }) => {
|
|
19
|
+
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
20
|
+
if (!z) {
|
|
21
|
+
throw new Error('expected zod');
|
|
22
|
+
}
|
|
23
|
+
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
24
|
+
schema,
|
|
25
|
+
setValue,
|
|
26
|
+
value,
|
|
27
|
+
});
|
|
28
|
+
const def = schema._def;
|
|
29
|
+
const typeName = def.typeName;
|
|
30
|
+
if (typeName !== z.ZodFirstPartyTypeKind.ZodString) {
|
|
31
|
+
throw new Error('expected enum');
|
|
32
|
+
}
|
|
33
|
+
const isRoot = jsonPath.length === 0;
|
|
34
|
+
const reset = (0, react_1.useCallback)(() => {
|
|
35
|
+
setLocalValue(() => defaultValue, true);
|
|
36
|
+
}, [defaultValue, setLocalValue]);
|
|
37
|
+
const comboBoxValues = (0, react_1.useMemo)(() => {
|
|
38
|
+
return (0, remotion_1.getStaticFiles)().map((option) => {
|
|
39
|
+
return {
|
|
40
|
+
value: option.src,
|
|
41
|
+
label: option.name,
|
|
42
|
+
id: option.src,
|
|
43
|
+
keyHint: null,
|
|
44
|
+
leftItem: option.src === value ? (0, jsx_runtime_1.jsx)(Checkmark_1.Checkmark, {}) : null,
|
|
45
|
+
onClick: (id) => {
|
|
46
|
+
setLocalValue(() => id, false);
|
|
47
|
+
},
|
|
48
|
+
quickSwitcherLabel: null,
|
|
49
|
+
subMenu: null,
|
|
50
|
+
type: 'item',
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}, [setLocalValue, value]);
|
|
54
|
+
const save = (0, react_1.useCallback)(() => {
|
|
55
|
+
onSave(() => value);
|
|
56
|
+
}, [onSave, value]);
|
|
57
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { onSave: save, showSaveButton: showSaveButton, isDefaultValue: localValue.value === defaultValue, compact: compact, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent }), (0, jsx_runtime_1.jsx)("div", { style: isRoot ? undefined : container, children: (0, jsx_runtime_1.jsx)(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: localValue.value, title: value }) }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { x: 1 }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] }));
|
|
58
|
+
};
|
|
59
|
+
exports.ZodStaticFileEditor = ZodStaticFileEditor;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
4
5
|
export declare const ZodStringEditor: React.FC<{
|
|
5
6
|
schema: z.ZodTypeAny;
|
|
6
7
|
jsonPath: JSONPath;
|
|
7
8
|
value: string;
|
|
8
9
|
defaultValue: string;
|
|
9
|
-
setValue:
|
|
10
|
-
onSave:
|
|
10
|
+
setValue: UpdaterFunction<string>;
|
|
11
|
+
onSave: UpdaterFunction<string>;
|
|
11
12
|
onRemove: null | (() => void);
|
|
12
13
|
compact: boolean;
|
|
13
14
|
showSaveButton: boolean;
|
|
15
|
+
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
14
17
|
}>;
|
|
@@ -8,41 +8,30 @@ const layout_1 = require("../../layout");
|
|
|
8
8
|
const RemInput_1 = require("../../NewComposition/RemInput");
|
|
9
9
|
const ValidationMessage_1 = require("../../NewComposition/ValidationMessage");
|
|
10
10
|
const layout_2 = require("../layout");
|
|
11
|
+
const local_state_1 = require("./local-state");
|
|
11
12
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
12
13
|
const fullWidth = {
|
|
13
14
|
width: '100%',
|
|
14
15
|
};
|
|
15
|
-
const ZodStringEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, compact, onSave, onRemove, }) => {
|
|
16
|
+
const ZodStringEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, compact, onSave, onRemove, saving, saveDisabledByParent, }) => {
|
|
16
17
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
17
18
|
if (!z) {
|
|
18
19
|
throw new Error('expected zod');
|
|
19
20
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
21
|
+
const { localValue, onChange: setLocalValue } = (0, local_state_1.useLocalState)({
|
|
22
|
+
schema,
|
|
23
|
+
setValue,
|
|
24
|
+
value,
|
|
25
25
|
});
|
|
26
|
-
const onValueChange = (0, react_1.useCallback)((newValue) => {
|
|
27
|
-
const safeParse = schema.safeParse(newValue);
|
|
28
|
-
const newLocalState = {
|
|
29
|
-
value: newValue,
|
|
30
|
-
zodValidation: safeParse,
|
|
31
|
-
};
|
|
32
|
-
setLocalValue(newLocalState);
|
|
33
|
-
if (safeParse.success) {
|
|
34
|
-
setValue(newValue);
|
|
35
|
-
}
|
|
36
|
-
}, [schema, setValue]);
|
|
37
26
|
const onChange = (0, react_1.useCallback)((e) => {
|
|
38
|
-
|
|
39
|
-
}, [
|
|
27
|
+
setLocalValue(() => e.target.value, false);
|
|
28
|
+
}, [setLocalValue]);
|
|
40
29
|
const reset = (0, react_1.useCallback)(() => {
|
|
41
|
-
|
|
42
|
-
}, [defaultValue,
|
|
30
|
+
setLocalValue(() => defaultValue, true);
|
|
31
|
+
}, [defaultValue, setLocalValue]);
|
|
43
32
|
const save = (0, react_1.useCallback)(() => {
|
|
44
|
-
onSave(() => value);
|
|
33
|
+
onSave(() => value, false);
|
|
45
34
|
}, [onSave, value]);
|
|
46
|
-
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { compact: compact, isDefaultValue: value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(RemInput_1.RemotionInput, { value: localValue.value, status: localValue.zodValidation
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: compact ? layout_2.narrowOption : layout_2.optionRow, children: [(0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { compact: compact, isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent }), (0, jsx_runtime_1.jsxs)("div", { style: fullWidth, children: [(0, jsx_runtime_1.jsx)(RemInput_1.RemotionInput, { value: localValue.value, status: localValue.zodValidation ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, rightAlign: false }), !localValue.zodValidation.success && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(layout_1.Spacing, { y: 1, block: true }), (0, jsx_runtime_1.jsx)(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" })] }))] })] }));
|
|
47
36
|
};
|
|
48
37
|
exports.ZodStringEditor = ZodStringEditor;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import type { JSONPath } from './zod-types';
|
|
4
|
+
export declare type UpdaterFunction<T> = (updater: (oldValue: T) => T, forceApply: boolean) => void;
|
|
4
5
|
export declare const ZodSwitch: React.FC<{
|
|
5
6
|
schema: z.ZodTypeAny;
|
|
6
7
|
jsonPath: JSONPath;
|
|
7
8
|
value: unknown;
|
|
8
9
|
defaultValue: unknown;
|
|
9
|
-
setValue:
|
|
10
|
-
onSave:
|
|
10
|
+
setValue: UpdaterFunction<unknown>;
|
|
11
|
+
onSave: UpdaterFunction<unknown>;
|
|
11
12
|
compact: boolean;
|
|
12
13
|
showSaveButton: boolean;
|
|
13
14
|
onRemove: null | (() => void);
|
|
15
|
+
saving: boolean;
|
|
16
|
+
saveDisabledByParent: boolean;
|
|
14
17
|
}>;
|