@remotion/studio 4.0.438 → 4.0.440

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/Studio.js +2 -2
  2. package/dist/api/helpers/calc-new-props.js +5 -8
  3. package/dist/api/update-default-props.d.ts +7 -3
  4. package/dist/api/update-default-props.js +7 -21
  5. package/dist/api/visual-control.js +6 -0
  6. package/dist/components/DefaultPropsEditor.d.ts +8 -0
  7. package/dist/components/DefaultPropsEditor.js +15 -0
  8. package/dist/components/Editor.js +0 -14
  9. package/dist/components/EditorContexts.js +6 -3
  10. package/dist/components/KeyboardShortcutsExplainer.js +6 -2
  11. package/dist/components/MenuBuildIndicator.js +1 -0
  12. package/dist/components/MenuToolbar.js +3 -1
  13. package/dist/components/NewComposition/InputDragger.js +2 -2
  14. package/dist/components/NewComposition/RemTextarea.js +4 -0
  15. package/dist/components/ObserveDefaultPropsContext.d.ts +11 -0
  16. package/dist/components/ObserveDefaultPropsContext.js +120 -0
  17. package/dist/components/OptionsPanel.js +90 -28
  18. package/dist/components/RenderModal/CrfSetting.d.ts +1 -1
  19. package/dist/components/RenderModal/DataEditor.d.ts +4 -5
  20. package/dist/components/RenderModal/DataEditor.js +9 -111
  21. package/dist/components/RenderModal/RenderModalJSONPropsEditor.d.ts +1 -1
  22. package/dist/components/RenderModal/RenderModalJSONPropsEditor.js +52 -48
  23. package/dist/components/RenderModal/SchemaEditor/Fieldset.d.ts +0 -1
  24. package/dist/components/RenderModal/SchemaEditor/SchemaEditor.d.ts +4 -9
  25. package/dist/components/RenderModal/SchemaEditor/SchemaEditor.js +2 -61
  26. package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.d.ts +0 -1
  27. package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.js +2 -3
  28. package/dist/components/RenderModal/SchemaEditor/SchemaLabel.d.ts +0 -6
  29. package/dist/components/RenderModal/SchemaEditor/SchemaLabel.js +2 -5
  30. package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.d.ts +3 -1
  31. package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.js +1 -1
  32. package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.d.ts +1 -6
  33. package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.js +15 -26
  34. package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.d.ts +0 -5
  35. package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.js +7 -12
  36. package/dist/components/RenderModal/SchemaEditor/ZodBooleanEditor.d.ts +0 -7
  37. package/dist/components/RenderModal/SchemaEditor/ZodBooleanEditor.js +5 -15
  38. package/dist/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +1 -6
  39. package/dist/components/RenderModal/SchemaEditor/ZodColorEditor.js +30 -28
  40. package/dist/components/RenderModal/SchemaEditor/ZodDateEditor.d.ts +1 -6
  41. package/dist/components/RenderModal/SchemaEditor/ZodDateEditor.js +13 -17
  42. package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.d.ts +0 -5
  43. package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.js +2 -2
  44. package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.d.ts +1 -6
  45. package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.js +13 -28
  46. package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.d.ts +1 -5
  47. package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.js +11 -12
  48. package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.d.ts +1 -5
  49. package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.js +12 -16
  50. package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.d.ts +2 -2
  51. package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.js +1 -2
  52. package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.d.ts +1 -6
  53. package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.js +20 -30
  54. package/dist/components/RenderModal/SchemaEditor/ZodNonEditableValue.d.ts +0 -2
  55. package/dist/components/RenderModal/SchemaEditor/ZodNonEditableValue.js +3 -6
  56. package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.d.ts +0 -5
  57. package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.js +2 -2
  58. package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.d.ts +1 -6
  59. package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.js +16 -21
  60. package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.d.ts +2 -7
  61. package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.js +27 -49
  62. package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.d.ts +0 -5
  63. package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.js +2 -2
  64. package/dist/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +1 -6
  65. package/dist/components/RenderModal/SchemaEditor/ZodOrNullishEditor.js +8 -15
  66. package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.d.ts +1 -6
  67. package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.js +10 -15
  68. package/dist/components/RenderModal/SchemaEditor/ZodStringEditor.d.ts +1 -6
  69. package/dist/components/RenderModal/SchemaEditor/ZodStringEditor.js +13 -17
  70. package/dist/components/RenderModal/SchemaEditor/ZodSwitch.d.ts +3 -6
  71. package/dist/components/RenderModal/SchemaEditor/ZodSwitch.js +27 -27
  72. package/dist/components/RenderModal/SchemaEditor/ZodTextareaEditor.d.ts +0 -5
  73. package/dist/components/RenderModal/SchemaEditor/ZodTextareaEditor.js +45 -17
  74. package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.d.ts +1 -6
  75. package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.js +15 -26
  76. package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.d.ts +0 -5
  77. package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.js +4 -11
  78. package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +0 -5
  79. package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.js +6 -6
  80. package/dist/components/RenderModal/ServerRenderModal.js +9 -3
  81. package/dist/components/RenderModal/WebRenderModal.js +9 -3
  82. package/dist/components/RenderModal/get-default-codecs.d.ts +5 -5
  83. package/dist/components/RenderModal/get-render-modal-warnings.d.ts +1 -2
  84. package/dist/components/RenderModal/get-render-modal-warnings.js +4 -6
  85. package/dist/components/RenderModal/human-readable-codec.d.ts +1 -1
  86. package/dist/components/RenderModal/human-readable-codec.js +3 -0
  87. package/dist/components/RenderModal/out-name-checker.d.ts +1 -1
  88. package/dist/components/RenderQueue/actions.d.ts +2 -3
  89. package/dist/components/RenderQueue/actions.js +1 -13
  90. package/dist/components/Timeline/Timeline.js +1 -1
  91. package/dist/components/Timeline/TimelineExpandedSection.js +7 -1
  92. package/dist/components/Timeline/TimelineFieldRow.d.ts +1 -0
  93. package/dist/components/Timeline/TimelineFieldRow.js +25 -3
  94. package/dist/components/Timeline/TimelineImageInfo.d.ts +5 -0
  95. package/dist/components/Timeline/TimelineImageInfo.js +61 -0
  96. package/dist/components/Timeline/TimelineListItem.js +1 -2
  97. package/dist/components/Timeline/TimelineNumberField.js +4 -6
  98. package/dist/components/Timeline/TimelineRotationField.js +4 -6
  99. package/dist/components/Timeline/TimelineSequence.js +9 -4
  100. package/dist/components/Timeline/TimelineStack/index.js +3 -1
  101. package/dist/components/Timeline/TimelineTracks.js +1 -1
  102. package/dist/components/Timeline/TimelineTranslateField.js +28 -13
  103. package/dist/components/TopPanel.js +10 -5
  104. package/dist/components/UndoRedoButtons.d.ts +2 -0
  105. package/dist/components/UndoRedoButtons.js +116 -0
  106. package/dist/components/VisualControls/VisualControlHandle.js +18 -18
  107. package/dist/components/VisualControls/VisualControlsUndoSync.d.ts +2 -0
  108. package/dist/components/VisualControls/VisualControlsUndoSync.js +23 -0
  109. package/dist/error-overlay/react-overlay/listen-to-runtime-errors.js +0 -1
  110. package/dist/esm/{chunk-ba0scebn.js → chunk-1x2ychmc.js} +4466 -5252
  111. package/dist/esm/index.mjs +25 -28
  112. package/dist/esm/internals.mjs +4466 -5252
  113. package/dist/esm/previewEntry.mjs +4652 -5497
  114. package/dist/esm/renderEntry.mjs +6 -6
  115. package/dist/helpers/client-id.js +13 -1
  116. package/dist/helpers/document-title.d.ts +0 -1
  117. package/dist/helpers/document-title.js +1 -17
  118. package/dist/helpers/render-modal-sections.d.ts +1 -1
  119. package/dist/helpers/timeline-layout.d.ts +1 -1
  120. package/dist/helpers/timeline-layout.js +1 -1
  121. package/dist/hot-middleware-client/client.d.ts +1 -6
  122. package/dist/hot-middleware-client/client.js +22 -73
  123. package/dist/hot-middleware-client/process-update.d.ts +0 -2
  124. package/dist/hot-middleware-client/process-update.js +6 -14
  125. package/dist/icons/redo.d.ts +3 -0
  126. package/dist/icons/redo.js +8 -0
  127. package/dist/icons/undo.d.ts +3 -0
  128. package/dist/icons/undo.js +8 -0
  129. package/dist/renderEntry.js +7 -6
  130. package/dist/visual-controls/VisualControls.js +9 -5
  131. package/dist/visual-controls/get-current-edited-value.js +5 -4
  132. package/dist/visual-controls/visual-control-store.d.ts +7 -0
  133. package/dist/visual-controls/visual-control-store.js +22 -0
  134. package/package.json +9 -9
  135. package/dist/components/GlobalPropsEditorUpdateButton.d.ts +0 -5
  136. package/dist/components/GlobalPropsEditorUpdateButton.js +0 -78
  137. package/dist/components/RenderModal/SchemaEditor/SchemaSaveButton.d.ts +0 -5
  138. package/dist/components/RenderModal/SchemaEditor/SchemaSaveButton.js +0 -18
  139. package/dist/components/RenderModal/SchemaEditor/local-state.d.ts +0 -25
  140. package/dist/components/RenderModal/SchemaEditor/local-state.js +0 -107
@@ -7,11 +7,6 @@ export declare const ZodArrayItemEditor: React.FC<{
7
7
  elementSchema: AnyZodSchema;
8
8
  index: number;
9
9
  value: unknown;
10
- defaultValue: unknown;
11
- onSave: UpdaterFunction<unknown[]>;
12
- showSaveButton: boolean;
13
- saving: boolean;
14
- saveDisabledByParent: boolean;
15
10
  mayPad: boolean;
16
11
  mayRemove: boolean;
17
12
  }>;
@@ -5,29 +5,24 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const get_zod_if_possible_1 = require("../../get-zod-if-possible");
7
7
  const ZodSwitch_1 = require("./ZodSwitch");
8
- const ZodArrayItemEditor = ({ elementSchema, onChange, jsonPath, index, value, defaultValue, onSave: onSaveObject, showSaveButton, saving, saveDisabledByParent, mayPad, mayRemove, }) => {
8
+ const ZodArrayItemEditor = ({ elementSchema, onChange, jsonPath, index, value, mayPad, mayRemove }) => {
9
9
  const z = (0, get_zod_if_possible_1.useZodIfPossible)();
10
10
  if (!z) {
11
11
  throw new Error('expected zod');
12
12
  }
13
13
  const onRemove = (0, react_1.useCallback)(() => {
14
- onChange((oldV) => [...oldV.slice(0, index), ...oldV.slice(index + 1)], false, true);
14
+ onChange((oldV) => [...oldV.slice(0, index), ...oldV.slice(index + 1)], {
15
+ shouldSave: true,
16
+ });
15
17
  }, [index, onChange]);
16
- const setValue = (0, react_1.useCallback)((val) => {
18
+ const setValue = (0, react_1.useCallback)((val, { shouldSave }) => {
17
19
  onChange((oldV) => [
18
20
  ...oldV.slice(0, index),
19
21
  typeof val === 'function' ? val(oldV[index]) : val,
20
22
  ...oldV.slice(index + 1),
21
- ], false, false);
23
+ ], { shouldSave });
22
24
  }, [index, onChange]);
23
25
  const newJsonPath = (0, react_1.useMemo)(() => [...jsonPath, index], [index, jsonPath]);
24
- const onSave = (0, react_1.useCallback)((updater) => {
25
- onSaveObject((oldV) => [
26
- ...oldV.slice(0, index),
27
- updater(oldV[index]),
28
- ...oldV.slice(index + 1),
29
- ], false, false);
30
- }, [index, onSaveObject]);
31
- return (jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { jsonPath: newJsonPath, schema: elementSchema, value: value, setValue: setValue, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: mayRemove ? onRemove : null, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }) }));
26
+ return (jsx_runtime_1.jsx("div", { children: jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { jsonPath: newJsonPath, schema: elementSchema, value: value, setValue: setValue, onRemove: mayRemove ? onRemove : null, mayPad: mayPad }) }));
32
27
  };
33
28
  exports.ZodArrayItemEditor = ZodArrayItemEditor;
@@ -1,17 +1,10 @@
1
1
  import React from 'react';
2
- import type { AnyZodSchema } from './zod-schema-type';
3
2
  import type { JSONPath } from './zod-types';
4
3
  import type { UpdaterFunction } from './ZodSwitch';
5
4
  export declare const ZodBooleanEditor: React.FC<{
6
- readonly schema: AnyZodSchema;
7
5
  readonly jsonPath: JSONPath;
8
6
  readonly value: boolean;
9
7
  readonly setValue: UpdaterFunction<boolean>;
10
- readonly defaultValue: boolean;
11
- readonly onSave: UpdaterFunction<boolean>;
12
8
  readonly onRemove: null | (() => void);
13
- readonly showSaveButton: boolean;
14
- readonly saving: boolean;
15
- readonly saveDisabledByParent: boolean;
16
9
  readonly mayPad: boolean;
17
10
  }>;
@@ -5,26 +5,16 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const Checkbox_1 = require("../../Checkbox");
7
7
  const Fieldset_1 = require("./Fieldset");
8
- const local_state_1 = require("./local-state");
9
8
  const SchemaLabel_1 = require("./SchemaLabel");
10
9
  const fullWidth = {
11
10
  width: '100%',
12
11
  };
13
- const ZodBooleanEditor = ({ schema, jsonPath, value, setValue, onSave, defaultValue, onRemove, showSaveButton, saving, saveDisabledByParent, mayPad, }) => {
14
- const { localValue, onChange, reset } = (0, local_state_1.useLocalState)({
15
- schema,
16
- setValue,
17
- unsavedValue: value,
18
- savedValue: defaultValue,
19
- });
12
+ const ZodBooleanEditor = ({ jsonPath, value, setValue, onRemove, mayPad }) => {
20
13
  const onToggle = (0, react_1.useCallback)((e) => {
21
- onChange(() => e.target.checked, false, false);
22
- }, [onChange]);
23
- const save = (0, react_1.useCallback)(() => {
24
- onSave(() => value, false, false);
25
- }, [onSave, value]);
26
- return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
27
- jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: true, saveDisabledByParent: saveDisabledByParent, suffix: null }), jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx(Checkbox_1.Checkbox, { name: jsonPath.join('.'), checked: localValue.value, onChange: onToggle, disabled: false }) })
14
+ setValue(() => e.target.checked, { shouldSave: true });
15
+ }, [setValue]);
16
+ return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
17
+ jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: true, suffix: null }), jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx(Checkbox_1.Checkbox, { name: jsonPath.join('.'), checked: value, onChange: onToggle, disabled: false }) })
28
18
  ] }));
29
19
  };
30
20
  exports.ZodBooleanEditor = ZodBooleanEditor;
@@ -1,17 +1,12 @@
1
1
  import React from 'react';
2
- import type { AnyZodSchema } from './zod-schema-type';
2
+ import { type AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  import type { UpdaterFunction } from './ZodSwitch';
5
5
  export declare const ZodColorEditor: React.FC<{
6
6
  readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: string;
9
- readonly defaultValue: string;
10
9
  readonly setValue: UpdaterFunction<string>;
11
- readonly onSave: UpdaterFunction<string>;
12
10
  readonly onRemove: null | (() => void);
13
- readonly showSaveButton: boolean;
14
- readonly saving: boolean;
15
- readonly saveDisabledByParent: boolean;
16
11
  readonly mayPad: boolean;
17
12
  }>;
@@ -10,13 +10,13 @@ const InputDragger_1 = require("../../NewComposition/InputDragger");
10
10
  const RemInput_1 = require("../../NewComposition/RemInput");
11
11
  const RemInputTypeColor_1 = require("../../NewComposition/RemInputTypeColor");
12
12
  const Fieldset_1 = require("./Fieldset");
13
- const local_state_1 = require("./local-state");
14
13
  const SchemaLabel_1 = require("./SchemaLabel");
14
+ const zod_schema_type_1 = require("./zod-schema-type");
15
15
  const ZodFieldValidation_1 = require("./ZodFieldValidation");
16
16
  const fullWidth = {
17
17
  width: '100%',
18
18
  };
19
- const ZodColorEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, onSave, onRemove, saving, saveDisabledByParent, mayPad, }) => {
19
+ const ZodColorEditor = ({ jsonPath, value, setValue, schema, onRemove, mayPad }) => {
20
20
  const z = (0, get_zod_if_possible_1.useZodIfPossible)();
21
21
  if (!z) {
22
22
  throw new Error('expected zod');
@@ -25,30 +25,28 @@ const ZodColorEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValu
25
25
  if (!zodTypes) {
26
26
  throw new Error('expected zod color');
27
27
  }
28
- const { localValue, onChange: onValueChange, reset, } = (0, local_state_1.useLocalState)({
29
- schema,
30
- setValue,
31
- unsavedValue: value,
32
- savedValue: defaultValue,
33
- });
34
- const { a, b, g, r } = localValue.zodValidation.success
35
- ? zodTypes.ZodZypesInternals.parseColor(localValue.value)
28
+ const localValue = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
29
+ const { a, b, g, r } = localValue.success
30
+ ? zodTypes.ZodZypesInternals.parseColor(value)
36
31
  : { a: 1, b: 0, g: 0, r: 0 };
37
32
  const onChange = (0, react_1.useCallback)((e) => {
38
33
  const newColor = (0, color_math_1.colorWithNewOpacity)(e.target.value, Math.round(a), zodTypes);
39
- onValueChange(() => newColor, false, false);
40
- }, [a, onValueChange, zodTypes]);
34
+ setValue(() => newColor, { shouldSave: false });
35
+ }, [a, setValue, zodTypes]);
36
+ const onColorBlur = (0, react_1.useCallback)(() => {
37
+ setValue(() => value, { shouldSave: true });
38
+ }, [setValue, value]);
41
39
  const onTextChange = (0, react_1.useCallback)((e) => {
42
40
  const newValue = e.target.value;
43
- onValueChange(() => newValue, false, false);
44
- }, [onValueChange]);
45
- const save = (0, react_1.useCallback)(() => {
46
- onSave(() => value, false, false);
47
- }, [onSave, value]);
41
+ setValue(() => newValue, { shouldSave: false });
42
+ }, [setValue]);
43
+ const onTextBlur = (0, react_1.useCallback)(() => {
44
+ setValue(() => value, { shouldSave: true });
45
+ }, [setValue, value]);
48
46
  const rgb = `#${r.toString(16).padStart(2, '0')}${g
49
47
  .toString(16)
50
48
  .padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
51
- const status = localValue.zodValidation.success ? 'ok' : 'error';
49
+ const status = localValue.success ? 'ok' : 'error';
52
50
  const colorPicker = (0, react_1.useMemo)(() => {
53
51
  return {
54
52
  height: 39,
@@ -57,20 +55,24 @@ const ZodColorEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValu
57
55
  };
58
56
  }, []);
59
57
  const onOpacityChange = (0, react_1.useCallback)((newValue) => {
60
- const newColor = (0, color_math_1.colorWithNewOpacity)(localValue.value, Math.round((Number(newValue) / 100) * 255), zodTypes);
61
- onValueChange(() => newColor, false, false);
62
- }, [localValue.value, onValueChange, zodTypes]);
58
+ const newColor = (0, color_math_1.colorWithNewOpacity)(value, Math.round((Number(newValue) / 100) * 255), zodTypes);
59
+ setValue(() => newColor, { shouldSave: true });
60
+ }, [setValue, value, zodTypes]);
63
61
  const onOpacityValueChange = (0, react_1.useCallback)((newValue) => {
64
- const newColor = (0, color_math_1.colorWithNewOpacity)(localValue.value, Math.round((Number(newValue) / 100) * 255), zodTypes);
65
- onValueChange(() => newColor, false, false);
66
- }, [localValue.value, onValueChange, zodTypes]);
67
- return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
68
- jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value === defaultValue, jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
62
+ const newColor = (0, color_math_1.colorWithNewOpacity)(value, Math.round((Number(newValue) / 100) * 255), zodTypes);
63
+ setValue(() => newColor, { shouldSave: false });
64
+ }, [setValue, value, zodTypes]);
65
+ const onOpacityValueChangeEnd = (0, react_1.useCallback)((newValue) => {
66
+ const newColor = (0, color_math_1.colorWithNewOpacity)(value, Math.round((Number(newValue) / 100) * 255), zodTypes);
67
+ setValue(() => newColor, { shouldSave: true });
68
+ }, [setValue, value, zodTypes]);
69
+ return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
70
+ jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: localValue.success, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
69
71
  jsx_runtime_1.jsxs(layout_1.Row, { align: "center", children: [
70
72
  jsx_runtime_1.jsx("div", { style: colorPicker, children: jsx_runtime_1.jsx(RemInputTypeColor_1.RemInputTypeColor, { type: "color", style: {
71
73
  height: 39,
72
- }, value: rgb, onChange: onChange, className: "__remotion_color_picker", status: status, name: jsonPath.join('.') }) }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1, block: true }), jsx_runtime_1.jsx(RemInput_1.RemotionInput, { value: localValue.value, status: status, placeholder: jsonPath.join('.'), onChange: onTextChange, rightAlign: false }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1 }), 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))}%`, rightAlign: false })
73
- ] }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
74
+ }, value: rgb, onChange: onChange, onBlur: onColorBlur, className: "__remotion_color_picker", status: status, name: jsonPath.join('.') }) }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1, block: true }), jsx_runtime_1.jsx(RemInput_1.RemotionInput, { value: value, status: status, placeholder: jsonPath.join('.'), onChange: onTextChange, onBlur: onTextBlur, rightAlign: false }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1 }), jsx_runtime_1.jsx(InputDragger_1.InputDragger, { onTextChange: onOpacityChange, onValueChange: onOpacityValueChange, onValueChangeEnd: onOpacityValueChangeEnd, status: status, value: (a / 255) * 100, min: 0, max: 100, step: 1, formatter: (v) => `${Math.round(Number(v))}%`, rightAlign: false })
75
+ ] }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: localValue })
74
76
  ] })
75
77
  ] }));
76
78
  };
@@ -1,17 +1,12 @@
1
1
  import React from 'react';
2
- import type { AnyZodSchema } from './zod-schema-type';
2
+ import { type AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  import type { UpdaterFunction } from './ZodSwitch';
5
5
  export declare const ZodDateEditor: React.FC<{
6
6
  readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: Date;
9
- readonly defaultValue: Date;
10
9
  readonly setValue: UpdaterFunction<Date>;
11
- readonly onSave: UpdaterFunction<Date>;
12
10
  readonly onRemove: null | (() => void);
13
- readonly showSaveButton: boolean;
14
- readonly saving: boolean;
15
- readonly saveDisabledByParent: boolean;
16
11
  readonly mayPad: boolean;
17
12
  }>;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZodDateEditor = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const react_2 = require("react");
6
7
  const colors_1 = require("../../../helpers/colors");
7
8
  const layout_1 = require("../../layout");
8
9
  const RemInput_1 = require("../../NewComposition/RemInput");
9
10
  const Fieldset_1 = require("./Fieldset");
10
- const local_state_1 = require("./local-state");
11
11
  const SchemaLabel_1 = require("./SchemaLabel");
12
+ const zod_schema_type_1 = require("./zod-schema-type");
12
13
  const ZodFieldValidation_1 = require("./ZodFieldValidation");
13
14
  const fullWidth = {
14
15
  width: '100%',
@@ -43,23 +44,18 @@ const formatDate = (date) => {
43
44
  .padStart(3, '0')}`;
44
45
  return formattedDate;
45
46
  };
46
- const ZodDateEditor = ({ jsonPath, value, setValue, showSaveButton, defaultValue, schema, onSave, onRemove, saving, saveDisabledByParent, mayPad, }) => {
47
- const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
48
- schema,
49
- setValue,
50
- unsavedValue: value,
51
- savedValue: defaultValue,
52
- });
53
- const onChange = (0, react_1.useCallback)((e) => {
47
+ const ZodDateEditor = ({ jsonPath, value, setValue, schema, onRemove, mayPad }) => {
48
+ const onChange = (0, react_2.useCallback)((e) => {
54
49
  // React does not support e.target.valueAsDate :(
55
- setLocalValue(() => new Date(e.target.value), false, false);
56
- }, [setLocalValue]);
57
- const save = (0, react_1.useCallback)(() => {
58
- onSave(() => value, false, false);
59
- }, [onSave, value]);
60
- return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
61
- jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value.getTime() === defaultValue.getTime(), jsonPath: jsonPath, onReset: reset, onSave: save, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: saveDisabledByParent, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
62
- jsx_runtime_1.jsx(RemInput_1.RemotionInput, { value: formatDate(localValue.value), type: "datetime-local", status: localValue.zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, style: inputStyle, rightAlign: false }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx("div", { style: explainer, children: "Date is in local format" }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
50
+ setValue(() => new Date(e.target.value), { shouldSave: false });
51
+ }, [setValue]);
52
+ const onBlur = (0, react_2.useCallback)(() => {
53
+ setValue((v) => v, { shouldSave: true });
54
+ }, [setValue]);
55
+ const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
56
+ return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
57
+ jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsxs("div", { style: fullWidth, children: [
58
+ jsx_runtime_1.jsx(RemInput_1.RemotionInput, { value: formatDate(value), type: "datetime-local", status: zodValidation.success ? 'ok' : 'error', placeholder: jsonPath.join('.'), onChange: onChange, onBlur: onBlur, style: inputStyle, rightAlign: false }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx("div", { style: explainer, children: "Date is in local format" }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
63
59
  ] })
64
60
  ] }));
65
61
  };
@@ -3,15 +3,10 @@ import type { AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  import type { UpdaterFunction } from './ZodSwitch';
5
5
  export declare const ZodDefaultEditor: React.FC<{
6
- readonly showSaveButton: boolean;
7
6
  readonly jsonPath: JSONPath;
8
7
  readonly value: unknown;
9
- readonly defaultValue: unknown;
10
8
  readonly schema: AnyZodSchema;
11
9
  readonly setValue: UpdaterFunction<unknown>;
12
- readonly onSave: UpdaterFunction<unknown>;
13
10
  readonly onRemove: null | (() => void);
14
- readonly saving: boolean;
15
- readonly saveDisabledByParent: boolean;
16
11
  readonly mayPad: boolean;
17
12
  }>;
@@ -4,8 +4,8 @@ exports.ZodDefaultEditor = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const zod_schema_type_1 = require("./zod-schema-type");
6
6
  const ZodSwitch_1 = require("./ZodSwitch");
7
- const ZodDefaultEditor = ({ jsonPath, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
7
+ const ZodDefaultEditor = ({ jsonPath, schema, setValue, value, onRemove, mayPad }) => {
8
8
  const innerType = (0, zod_schema_type_1.getInnerType)(schema);
9
- return (jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
9
+ return (jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { jsonPath: jsonPath, onRemove: onRemove, schema: innerType, setValue: setValue, value: value, mayPad: mayPad }));
10
10
  };
11
11
  exports.ZodDefaultEditor = ZodDefaultEditor;
@@ -1,16 +1,11 @@
1
- import type { AnyZodSchema } from './zod-schema-type';
1
+ import { type AnyZodSchema } from './zod-schema-type';
2
2
  import type { JSONPath } from './zod-types';
3
3
  import type { UpdaterFunction } from './ZodSwitch';
4
4
  export declare const ZodDiscriminatedUnionEditor: React.FC<{
5
5
  schema: AnyZodSchema;
6
6
  setValue: UpdaterFunction<Record<string, unknown>>;
7
7
  value: Record<string, unknown>;
8
- defaultValue: Record<string, unknown>;
9
8
  mayPad: boolean;
10
9
  jsonPath: JSONPath;
11
10
  onRemove: null | (() => void);
12
- onSave: UpdaterFunction<unknown>;
13
- showSaveButton: boolean;
14
- saving: boolean;
15
- saveDisabledByParent: boolean;
16
11
  }>;
@@ -8,24 +8,18 @@ const get_zod_if_possible_1 = require("../../get-zod-if-possible");
8
8
  const ComboBox_1 = require("../../NewComposition/ComboBox");
9
9
  const create_zod_values_1 = require("./create-zod-values");
10
10
  const Fieldset_1 = require("./Fieldset");
11
- const local_state_1 = require("./local-state");
12
11
  const SchemaLabel_1 = require("./SchemaLabel");
13
12
  const zod_schema_type_1 = require("./zod-schema-type");
13
+ const zod_schema_type_2 = require("./zod-schema-type");
14
14
  const ZodObjectEditor_1 = require("./ZodObjectEditor");
15
- const ZodDiscriminatedUnionEditor = ({ schema, setValue, showSaveButton, saving, value, defaultValue, saveDisabledByParent, onSave, mayPad, jsonPath, onRemove, }) => {
15
+ const ZodDiscriminatedUnionEditor = ({ schema, setValue, value, mayPad, jsonPath, onRemove }) => {
16
16
  const z = (0, get_zod_if_possible_1.useZodIfPossible)();
17
17
  if (!z) {
18
18
  throw new Error('expected zod');
19
19
  }
20
20
  const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
21
- const discriminator = (0, zod_schema_type_1.getDiscriminator)(schema);
22
- const options = (0, react_1.useMemo)(() => (0, zod_schema_type_1.getDiscriminatedOptionKeys)(schema), [schema]);
23
- const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
24
- schema,
25
- setValue,
26
- unsavedValue: value,
27
- savedValue: defaultValue,
28
- });
21
+ const discriminator = (0, zod_schema_type_2.getDiscriminator)(schema);
22
+ const options = (0, react_1.useMemo)(() => (0, zod_schema_type_2.getDiscriminatedOptionKeys)(schema), [schema]);
29
23
  const comboBoxValues = (0, react_1.useMemo)(() => {
30
24
  return options.map((option) => {
31
25
  return {
@@ -35,51 +29,42 @@ const ZodDiscriminatedUnionEditor = ({ schema, setValue, showSaveButton, saving,
35
29
  keyHint: null,
36
30
  leftItem: option === value[discriminator] ? jsx_runtime_1.jsx(Checkmark_1.Checkmark, {}) : null,
37
31
  onClick: () => {
38
- const optionSchema = (0, zod_schema_type_1.getDiscriminatedOption)(schema, option);
32
+ const optionSchema = (0, zod_schema_type_2.getDiscriminatedOption)(schema, option);
39
33
  if (!optionSchema) {
40
34
  throw new Error(`No schema found for discriminator value: ${option}`);
41
35
  }
42
36
  const val = (0, create_zod_values_1.createZodValues)(optionSchema, z, zodTypes);
43
- setLocalValue(() => val, false, false);
37
+ setValue(() => val, { shouldSave: true });
44
38
  },
45
39
  quickSwitcherLabel: null,
46
40
  subMenu: null,
47
41
  type: 'item',
48
42
  };
49
43
  });
50
- }, [options, setLocalValue, discriminator, schema, value, z, zodTypes]);
51
- const save = (0, react_1.useCallback)(() => {
52
- onSave(() => value, false, false);
53
- }, [onSave, value]);
44
+ }, [options, setValue, discriminator, schema, value, z, zodTypes]);
45
+ const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
54
46
  const discriminatedUnionReplacement = (0, react_1.useMemo)(() => {
55
47
  return {
56
48
  discriminator,
57
- markup: (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: true, children: [
58
- jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value[discriminator] === defaultValue[discriminator], jsonPath: [...jsonPath, discriminator], onRemove: onRemove, onReset: reset, onSave: save, saveDisabledByParent: saveDisabledByParent, saving: saving, showSaveButton: showSaveButton, suffix: null, valid: localValue.zodValidation.success }), jsx_runtime_1.jsx(ComboBox_1.Combobox, { title: "Select type", values: comboBoxValues, selectedId: value[discriminator] })
49
+ markup: (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
50
+ jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: [...jsonPath, discriminator], onRemove: onRemove, suffix: null, valid: zodValidation.success }), jsx_runtime_1.jsx(ComboBox_1.Combobox, { title: "Select type", values: comboBoxValues, selectedId: value[discriminator] })
59
51
  ] }, 'replacement')),
60
52
  };
61
53
  }, [
62
54
  comboBoxValues,
63
- defaultValue,
64
55
  jsonPath,
65
- localValue.value,
66
- localValue.zodValidation.success,
67
56
  mayPad,
68
57
  onRemove,
69
- reset,
70
- save,
71
- saveDisabledByParent,
72
- saving,
73
- showSaveButton,
74
58
  discriminator,
75
59
  value,
60
+ zodValidation.success,
76
61
  ]);
77
- const currentOptionSchema = (0, zod_schema_type_1.getDiscriminatedOption)(schema, value[discriminator]);
62
+ const currentOptionSchema = (0, zod_schema_type_2.getDiscriminatedOption)(schema, value[discriminator]);
78
63
  if (!currentOptionSchema) {
79
64
  throw new Error('No matching option found for discriminated union');
80
65
  }
81
66
  return (jsx_runtime_1.jsx(ZodObjectEditor_1.ZodObjectEditor
82
67
  // Re-render the object editor when the discriminator changes
83
- , { jsonPath: jsonPath, mayPad: mayPad, savedValue: defaultValue, onRemove: onRemove, onSave: onSave, saveDisabledByParent: saveDisabledByParent, saving: saving, schema: currentOptionSchema, setValue: setLocalValue, showSaveButton: showSaveButton, unsavedValue: value, discriminatedUnionReplacement: discriminatedUnionReplacement }, value[discriminator]));
68
+ , { jsonPath: jsonPath, mayPad: mayPad, onRemove: onRemove, schema: currentOptionSchema, setValue: setValue, value: value, discriminatedUnionReplacement: discriminatedUnionReplacement }, value[discriminator]));
84
69
  };
85
70
  exports.ZodDiscriminatedUnionEditor = ZodDiscriminatedUnionEditor;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { AnyZodSchema } from './zod-schema-type';
2
+ import { type AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  import type { UpdaterFunction } from './ZodSwitch';
5
5
  export declare const ZodEffectEditor: React.FC<{
@@ -7,10 +7,6 @@ export declare const ZodEffectEditor: React.FC<{
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: unknown;
9
9
  readonly setValue: UpdaterFunction<unknown>;
10
- readonly defaultValue: unknown;
11
- readonly onSave: UpdaterFunction<unknown>;
12
- readonly showSaveButton: boolean;
13
10
  readonly onRemove: null | (() => void);
14
- readonly saving: boolean;
15
11
  readonly mayPad: boolean;
16
12
  }>;
@@ -2,28 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZodEffectEditor = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
5
6
  const Fieldset_1 = require("./Fieldset");
6
- const local_state_1 = require("./local-state");
7
7
  const zod_schema_type_1 = require("./zod-schema-type");
8
+ const zod_schema_type_2 = require("./zod-schema-type");
8
9
  const ZodFieldValidation_1 = require("./ZodFieldValidation");
9
10
  const ZodSwitch_1 = require("./ZodSwitch");
10
11
  const fullWidth = {
11
12
  width: '100%',
12
13
  };
13
- const ZodEffectEditor = ({ schema, jsonPath, value, setValue: updateValue, defaultValue, onSave, onRemove, showSaveButton, saving, mayPad, }) => {
14
- const typeName = (0, zod_schema_type_1.getZodSchemaType)(schema);
14
+ const ZodEffectEditor = ({ schema, jsonPath, value, setValue: updateValue, onRemove, mayPad }) => {
15
+ const typeName = (0, zod_schema_type_2.getZodSchemaType)(schema);
15
16
  if (typeName !== 'effects') {
16
17
  throw new Error('expected effect');
17
18
  }
18
- const { localValue, onChange } = (0, local_state_1.useLocalState)({
19
- unsavedValue: value,
20
- schema,
21
- setValue: updateValue,
22
- savedValue: defaultValue,
23
- });
24
- const innerSchema = (0, zod_schema_type_1.getEffectsInner)(schema);
25
- return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
26
- jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { value: value, setValue: onChange, jsonPath: jsonPath, schema: innerSchema, defaultValue: defaultValue, onSave: onSave, showSaveButton: showSaveButton, onRemove: onRemove, saving: saving, saveDisabledByParent: !localValue.zodValidation.success, mayPad: false }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
19
+ const onChange = (0, react_1.useCallback)((updater, { shouldSave }) => {
20
+ updateValue(updater, { shouldSave });
21
+ }, [updateValue]);
22
+ const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
23
+ const innerSchema = (0, zod_schema_type_2.getEffectsInner)(schema);
24
+ return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
25
+ jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { value: value, setValue: onChange, jsonPath: jsonPath, schema: innerSchema, onRemove: onRemove, mayPad: false }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
27
26
  ] }));
28
27
  };
29
28
  exports.ZodEffectEditor = ZodEffectEditor;
@@ -1,15 +1,11 @@
1
1
  import React from 'react';
2
- import type { AnyZodSchema } from './zod-schema-type';
2
+ import { type AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  import type { UpdaterFunction } from './ZodSwitch';
5
5
  export declare const ZodEnumEditor: React.FC<{
6
6
  readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: string;
9
- readonly defaultValue: string;
10
9
  readonly setValue: UpdaterFunction<string>;
11
- readonly onSave: UpdaterFunction<string>;
12
- readonly showSaveButton: boolean;
13
10
  readonly onRemove: null | (() => void);
14
- readonly saving: boolean;
15
11
  }>;
@@ -3,24 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZodEnumEditor = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const react_2 = require("react");
6
7
  const Checkmark_1 = require("../../../icons/Checkmark");
7
8
  const ComboBox_1 = require("../../NewComposition/ComboBox");
8
9
  const Fieldset_1 = require("./Fieldset");
9
- const local_state_1 = require("./local-state");
10
10
  const SchemaLabel_1 = require("./SchemaLabel");
11
11
  const zod_schema_type_1 = require("./zod-schema-type");
12
+ const zod_schema_type_2 = require("./zod-schema-type");
12
13
  const ZodFieldValidation_1 = require("./ZodFieldValidation");
13
14
  const container = {
14
15
  width: '100%',
15
16
  };
16
- const ZodEnumEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, }) => {
17
- const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
18
- schema,
19
- setValue,
20
- unsavedValue: value,
21
- savedValue: defaultValue,
22
- });
23
- const enumValues = (0, zod_schema_type_1.getEnumValues)(schema);
17
+ const ZodEnumEditor = ({ schema, jsonPath, setValue, value, onRemove }) => {
18
+ const onChange = (0, react_2.useCallback)((updater, { shouldSave }) => {
19
+ setValue(updater, { shouldSave });
20
+ }, [setValue]);
21
+ const enumValues = (0, zod_schema_type_2.getEnumValues)(schema);
24
22
  const isRoot = jsonPath.length === 0;
25
23
  const comboBoxValues = (0, react_1.useMemo)(() => {
26
24
  return enumValues.map((option) => {
@@ -31,19 +29,17 @@ const ZodEnumEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave
31
29
  keyHint: null,
32
30
  leftItem: option === value ? jsx_runtime_1.jsx(Checkmark_1.Checkmark, {}) : null,
33
31
  onClick: (id) => {
34
- setLocalValue(() => id, false, false);
32
+ onChange(() => id, { shouldSave: true });
35
33
  },
36
34
  quickSwitcherLabel: null,
37
35
  subMenu: null,
38
36
  type: 'item',
39
37
  };
40
38
  });
41
- }, [enumValues, setLocalValue, value]);
42
- const save = (0, react_1.useCallback)(() => {
43
- onSave(() => value, false, false);
44
- }, [onSave, value]);
45
- return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: true, success: localValue.zodValidation.success, children: [
46
- jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, onSave: save, showSaveButton: showSaveButton, isDefaultValue: localValue.value === defaultValue, onReset: reset, jsonPath: jsonPath, onRemove: onRemove, saving: saving, valid: localValue.zodValidation.success, saveDisabledByParent: !localValue.zodValidation.success, suffix: null }), jsx_runtime_1.jsx("div", { style: isRoot ? undefined : container, children: jsx_runtime_1.jsx(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: value, title: value }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
39
+ }, [enumValues, onChange, value]);
40
+ const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
41
+ return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: true, children: [
42
+ jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, jsonPath: jsonPath, onRemove: onRemove, valid: zodValidation.success, suffix: null }), jsx_runtime_1.jsx("div", { style: isRoot ? undefined : container, children: jsx_runtime_1.jsx(ComboBox_1.Combobox, { values: comboBoxValues, selectedId: value, title: value }) }), jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, zodValidation: zodValidation })
47
43
  ] }));
48
44
  };
49
45
  exports.ZodEnumEditor = ZodEnumEditor;
@@ -1,6 +1,6 @@
1
- import type { LocalState } from './local-state';
1
+ import type { ZodSafeParseResult } from './zod-schema-type';
2
2
  import type { JSONPath } from './zod-types';
3
3
  export declare const ZodFieldValidation: React.FC<{
4
- localValue: LocalState<unknown>;
4
+ zodValidation: ZodSafeParseResult;
5
5
  path: JSONPath;
6
6
  }>;
@@ -16,8 +16,7 @@ const stackTrace = {
16
16
  const stackTraceLabel = {
17
17
  fontSize: 14,
18
18
  };
19
- const ZodFieldValidation = ({ localValue, path }) => {
20
- const { zodValidation } = localValue;
19
+ const ZodFieldValidation = ({ zodValidation, path }) => {
21
20
  if (zodValidation.success) {
22
21
  return null;
23
22
  }
@@ -1,17 +1,12 @@
1
1
  import React from 'react';
2
- import type { AnyZodSchema } from './zod-schema-type';
2
+ import { type AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  import type { UpdaterFunction } from './ZodSwitch';
5
5
  export declare const ZodMatrixEditor: React.FC<{
6
6
  readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: unknown[];
9
- readonly defaultValue: unknown[];
10
9
  readonly setValue: UpdaterFunction<unknown[]>;
11
- readonly onSave: UpdaterFunction<unknown[]>;
12
- readonly showSaveButton: boolean;
13
10
  readonly onRemove: null | (() => void);
14
- readonly saving: boolean;
15
- readonly saveDisabledByParent: boolean;
16
11
  readonly mayPad: boolean;
17
12
  }>;