@remotion/studio 4.0.425 → 4.0.427

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 (81) hide show
  1. package/dist/api/create-composition.d.ts +1 -2
  2. package/dist/api/helpers/calc-new-props.d.ts +1 -2
  3. package/dist/components/AssetSelector.js +1 -1
  4. package/dist/components/AssetSelectorItem.d.ts +1 -0
  5. package/dist/components/AssetSelectorItem.js +9 -8
  6. package/dist/components/InitialCompositionLoader.js +13 -1
  7. package/dist/components/NewComposition/CodemodFooter.d.ts +1 -0
  8. package/dist/components/NewComposition/CodemodFooter.js +4 -2
  9. package/dist/components/NewComposition/DeleteComposition.js +1 -1
  10. package/dist/components/NewComposition/DuplicateComposition.js +5 -1
  11. package/dist/components/NewComposition/RenameComposition.js +1 -1
  12. package/dist/components/RenderModal/DataEditor.d.ts +2 -1
  13. package/dist/components/RenderModal/DataEditor.js +6 -6
  14. package/dist/components/RenderModal/RenderModalJSONPropsEditor.d.ts +2 -2
  15. package/dist/components/RenderModal/RenderModalJSONPropsEditor.js +3 -2
  16. package/dist/components/RenderModal/SchemaEditor/SchemaEditor.d.ts +3 -3
  17. package/dist/components/RenderModal/SchemaEditor/SchemaEditor.js +4 -5
  18. package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.d.ts +3 -3
  19. package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.js +1 -0
  20. package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.d.ts +2 -2
  21. package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.js +4 -3
  22. package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.d.ts +2 -2
  23. package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.js +3 -6
  24. package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.d.ts +2 -1
  25. package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.js +2 -2
  26. package/dist/components/RenderModal/SchemaEditor/ZodBooleanEditor.d.ts +2 -2
  27. package/dist/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +2 -2
  28. package/dist/components/RenderModal/SchemaEditor/ZodDateEditor.d.ts +2 -2
  29. package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.d.ts +3 -3
  30. package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.js +2 -1
  31. package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.d.ts +2 -2
  32. package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.js +18 -18
  33. package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.d.ts +2 -2
  34. package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.js +6 -10
  35. package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.d.ts +2 -2
  36. package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.js +4 -12
  37. package/dist/components/RenderModal/SchemaEditor/ZodErrorMessages.d.ts +2 -2
  38. package/dist/components/RenderModal/SchemaEditor/ZodErrorMessages.js +2 -2
  39. package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.js +4 -3
  40. package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.d.ts +2 -2
  41. package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.js +3 -2
  42. package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.d.ts +2 -2
  43. package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.js +2 -1
  44. package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.d.ts +2 -2
  45. package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.js +49 -21
  46. package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.d.ts +2 -2
  47. package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.js +4 -9
  48. package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.d.ts +2 -2
  49. package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.js +2 -1
  50. package/dist/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +3 -3
  51. package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.d.ts +2 -2
  52. package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.js +0 -10
  53. package/dist/components/RenderModal/SchemaEditor/ZodStringEditor.d.ts +2 -2
  54. package/dist/components/RenderModal/SchemaEditor/ZodSwitch.d.ts +2 -2
  55. package/dist/components/RenderModal/SchemaEditor/ZodSwitch.js +38 -33
  56. package/dist/components/RenderModal/SchemaEditor/ZodTextareaEditor.d.ts +2 -2
  57. package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.d.ts +2 -2
  58. package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.js +3 -6
  59. package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.d.ts +2 -1
  60. package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.js +2 -2
  61. package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +2 -2
  62. package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.js +11 -15
  63. package/dist/components/RenderModal/SchemaEditor/create-zod-values.d.ts +2 -2
  64. package/dist/components/RenderModal/SchemaEditor/create-zod-values.js +108 -110
  65. package/dist/components/RenderModal/SchemaEditor/extract-enum-json-paths.d.ts +3 -3
  66. package/dist/components/RenderModal/SchemaEditor/extract-enum-json-paths.js +72 -87
  67. package/dist/components/RenderModal/SchemaEditor/local-state.d.ts +3 -3
  68. package/dist/components/RenderModal/SchemaEditor/local-state.js +5 -4
  69. package/dist/components/RenderModal/SchemaEditor/zod-schema-type.d.ts +176 -0
  70. package/dist/components/RenderModal/SchemaEditor/zod-schema-type.js +330 -0
  71. package/dist/components/get-zod-if-possible.d.ts +3 -0
  72. package/dist/components/get-zod-if-possible.js +23 -2
  73. package/dist/esm/{chunk-5wcqz8k8.js → chunk-k61xktct.js} +575 -368
  74. package/dist/esm/index.mjs +170 -81
  75. package/dist/esm/internals.mjs +575 -368
  76. package/dist/esm/previewEntry.mjs +575 -368
  77. package/dist/esm/renderEntry.mjs +1 -1
  78. package/dist/index.d.ts +2 -2
  79. package/dist/visual-controls/VisualControls.d.ts +4 -4
  80. package/dist/visual-controls/VisualControls.js +1 -1
  81. package/package.json +10 -10
@@ -11,14 +11,15 @@ const SchemaLabel_1 = require("./SchemaLabel");
11
11
  const ZodObjectEditor_1 = require("./ZodObjectEditor");
12
12
  const create_zod_values_1 = require("./create-zod-values");
13
13
  const local_state_1 = require("./local-state");
14
+ const zod_schema_type_1 = require("./zod-schema-type");
14
15
  const ZodDiscriminatedUnionEditor = ({ schema, setValue, showSaveButton, saving, value, defaultValue, saveDisabledByParent, onSave, mayPad, jsonPath, onRemove, }) => {
15
16
  const z = (0, get_zod_if_possible_1.useZodIfPossible)();
16
17
  if (!z) {
17
18
  throw new Error('expected zod');
18
19
  }
19
20
  const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
20
- const typedSchema = schema._def;
21
- const options = (0, react_1.useMemo)(() => [...typedSchema.optionsMap.keys()], [typedSchema.optionsMap]);
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]);
22
23
  const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
23
24
  schema,
24
25
  setValue,
@@ -32,9 +33,13 @@ const ZodDiscriminatedUnionEditor = ({ schema, setValue, showSaveButton, saving,
32
33
  label: option,
33
34
  id: option,
34
35
  keyHint: null,
35
- leftItem: option === value[typedSchema.discriminator] ? jsx_runtime_1.jsx(Checkmark_1.Checkmark, {}) : null,
36
+ leftItem: option === value[discriminator] ? jsx_runtime_1.jsx(Checkmark_1.Checkmark, {}) : null,
36
37
  onClick: () => {
37
- const val = (0, create_zod_values_1.createZodValues)(typedSchema.optionsMap.get(option), z, zodTypes);
38
+ const optionSchema = (0, zod_schema_type_1.getDiscriminatedOption)(schema, option);
39
+ if (!optionSchema) {
40
+ throw new Error(`No schema found for discriminator value: ${option}`);
41
+ }
42
+ const val = (0, create_zod_values_1.createZodValues)(optionSchema, z, zodTypes);
38
43
  setLocalValue(() => val, false, false);
39
44
  },
40
45
  quickSwitcherLabel: null,
@@ -42,24 +47,15 @@ const ZodDiscriminatedUnionEditor = ({ schema, setValue, showSaveButton, saving,
42
47
  type: 'item',
43
48
  };
44
49
  });
45
- }, [
46
- options,
47
- setLocalValue,
48
- typedSchema.discriminator,
49
- typedSchema.optionsMap,
50
- value,
51
- z,
52
- zodTypes,
53
- ]);
50
+ }, [options, setLocalValue, discriminator, schema, value, z, zodTypes]);
54
51
  const save = (0, react_1.useCallback)(() => {
55
52
  onSave(() => value, false, false);
56
53
  }, [onSave, value]);
57
54
  const discriminatedUnionReplacement = (0, react_1.useMemo)(() => {
58
55
  return {
59
- discriminator: typedSchema.discriminator,
56
+ discriminator,
60
57
  markup: (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: true, children: [
61
- jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { handleClick: null, isDefaultValue: localValue.value[typedSchema.discriminator] ===
62
- defaultValue[typedSchema.discriminator], jsonPath: [...jsonPath, typedSchema.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[typedSchema.discriminator] })
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] })
63
59
  ] }, 'replacement')),
64
60
  };
65
61
  }, [
@@ -75,11 +71,15 @@ const ZodDiscriminatedUnionEditor = ({ schema, setValue, showSaveButton, saving,
75
71
  saveDisabledByParent,
76
72
  saving,
77
73
  showSaveButton,
78
- typedSchema.discriminator,
74
+ discriminator,
79
75
  value,
80
76
  ]);
77
+ const currentOptionSchema = (0, zod_schema_type_1.getDiscriminatedOption)(schema, value[discriminator]);
78
+ if (!currentOptionSchema) {
79
+ throw new Error('No matching option found for discriminated union');
80
+ }
81
81
  return (jsx_runtime_1.jsx(ZodObjectEditor_1.ZodObjectEditor
82
82
  // 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: typedSchema.optionsMap.get(value[typedSchema.discriminator]), setValue: setLocalValue, showSaveButton: showSaveButton, unsavedValue: value, discriminatedUnionReplacement: discriminatedUnionReplacement }, value[typedSchema.discriminator]));
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]));
84
84
  };
85
85
  exports.ZodDiscriminatedUnionEditor = ZodDiscriminatedUnionEditor;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
3
2
  import type { UpdaterFunction } from './ZodSwitch';
3
+ import type { AnyZodSchema } from './zod-schema-type';
4
4
  import type { JSONPath } from './zod-types';
5
5
  export declare const ZodEffectEditor: React.FC<{
6
- readonly schema: z.ZodTypeAny;
6
+ readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: unknown;
9
9
  readonly setValue: UpdaterFunction<unknown>;
@@ -2,18 +2,18 @@
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 get_zod_if_possible_1 = require("../../get-zod-if-possible");
6
5
  const Fieldset_1 = require("./Fieldset");
7
6
  const ZodFieldValidation_1 = require("./ZodFieldValidation");
8
7
  const ZodSwitch_1 = require("./ZodSwitch");
9
8
  const local_state_1 = require("./local-state");
9
+ const zod_schema_type_1 = require("./zod-schema-type");
10
10
  const fullWidth = {
11
11
  width: '100%',
12
12
  };
13
13
  const ZodEffectEditor = ({ schema, jsonPath, value, setValue: updateValue, defaultValue, onSave, onRemove, showSaveButton, saving, mayPad, }) => {
14
- const z = (0, get_zod_if_possible_1.useZodIfPossible)();
15
- if (!z) {
16
- throw new Error('expected zod');
14
+ const typeName = (0, zod_schema_type_1.getZodSchemaType)(schema);
15
+ if (typeName !== 'effects') {
16
+ throw new Error('expected effect');
17
17
  }
18
18
  const { localValue, onChange } = (0, local_state_1.useLocalState)({
19
19
  unsavedValue: value,
@@ -21,13 +21,9 @@ const ZodEffectEditor = ({ schema, jsonPath, value, setValue: updateValue, defau
21
21
  setValue: updateValue,
22
22
  savedValue: defaultValue,
23
23
  });
24
- const def = schema._def;
25
- const typeName = def.typeName;
26
- if (typeName !== z.ZodFirstPartyTypeKind.ZodEffects) {
27
- throw new Error('expected effect');
28
- }
24
+ const innerSchema = (0, zod_schema_type_1.getEffectsInner)(schema);
29
25
  return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
30
- jsx_runtime_1.jsx("div", { style: fullWidth, children: jsx_runtime_1.jsx(ZodSwitch_1.ZodSwitch, { value: value, setValue: onChange, jsonPath: jsonPath, schema: def.schema, 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 })
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 })
31
27
  ] }));
32
28
  };
33
29
  exports.ZodEffectEditor = ZodEffectEditor;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
3
2
  import type { UpdaterFunction } from './ZodSwitch';
3
+ import type { AnyZodSchema } from './zod-schema-type';
4
4
  import type { JSONPath } from './zod-types';
5
5
  export declare const ZodEnumEditor: React.FC<{
6
- readonly schema: z.ZodTypeAny;
6
+ readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: string;
9
9
  readonly defaultValue: string;
@@ -5,33 +5,25 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const Checkmark_1 = require("../../../icons/Checkmark");
7
7
  const ComboBox_1 = require("../../NewComposition/ComboBox");
8
- const get_zod_if_possible_1 = require("../../get-zod-if-possible");
9
8
  const Fieldset_1 = require("./Fieldset");
10
9
  const SchemaLabel_1 = require("./SchemaLabel");
11
10
  const ZodFieldValidation_1 = require("./ZodFieldValidation");
12
11
  const local_state_1 = require("./local-state");
12
+ const zod_schema_type_1 = require("./zod-schema-type");
13
13
  const container = {
14
14
  width: '100%',
15
15
  };
16
16
  const ZodEnumEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, }) => {
17
- const z = (0, get_zod_if_possible_1.useZodIfPossible)();
18
- if (!z) {
19
- throw new Error('expected zod');
20
- }
21
17
  const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
22
18
  schema,
23
19
  setValue,
24
20
  unsavedValue: value,
25
21
  savedValue: defaultValue,
26
22
  });
27
- const def = schema._def;
28
- const typeName = def.typeName;
29
- if (typeName !== z.ZodFirstPartyTypeKind.ZodEnum) {
30
- throw new Error('expected enum');
31
- }
23
+ const enumValues = (0, zod_schema_type_1.getEnumValues)(schema);
32
24
  const isRoot = jsonPath.length === 0;
33
25
  const comboBoxValues = (0, react_1.useMemo)(() => {
34
- return def.values.map((option) => {
26
+ return enumValues.map((option) => {
35
27
  return {
36
28
  value: option,
37
29
  label: option,
@@ -46,7 +38,7 @@ const ZodEnumEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave
46
38
  type: 'item',
47
39
  };
48
40
  });
49
- }, [def.values, setLocalValue, value]);
41
+ }, [enumValues, setLocalValue, value]);
50
42
  const save = (0, react_1.useCallback)(() => {
51
43
  onSave(() => value, false, false);
52
44
  }, [onSave, value]);
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
2
+ import type { ZodSafeParseResult } from './zod-schema-type';
3
3
  export declare const ZodErrorMessages: React.FC<{
4
- readonly zodValidationResult: z.SafeParseReturnType<unknown, unknown>;
4
+ readonly zodValidationResult: ZodSafeParseResult;
5
5
  readonly viewTab: 'schema' | 'json';
6
6
  }>;
@@ -37,12 +37,12 @@ const ZodErrorMessages = ({ zodValidationResult, viewTab }) => {
37
37
  };
38
38
  }, []);
39
39
  if (viewTab === 'json') {
40
- return (jsx_runtime_1.jsx("div", { children: zodValidationResult.error.errors.map((error) => {
40
+ return (jsx_runtime_1.jsx("div", { children: zodValidationResult.error.issues.map((error) => {
41
41
  return (jsx_runtime_1.jsxs("div", { style: style, children: [
42
42
  jsx_runtime_1.jsx(ValidationMessage_1.WarningTriangle, { style: triangleStyle }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1 }), error.path.length === 0 ? 'Root' : error.path.join('.'), ":", ' ', error.message] }, error.path.join('.')));
43
43
  }) }));
44
44
  }
45
- return (jsx_runtime_1.jsx("div", { children: zodValidationResult.error.errors.map((error) => {
45
+ return (jsx_runtime_1.jsx("div", { children: zodValidationResult.error.issues.map((error) => {
46
46
  return (jsx_runtime_1.jsxs("div", { style: style, children: ["-", ' ', jsx_runtime_1.jsx("code", { style: code, children: error.path.length === 0 ? 'Root' : error.path.join('.') }),
47
47
  ": ", error.message] }, error.path.join('.')));
48
48
  }) }));
@@ -17,12 +17,13 @@ const stackTraceLabel = {
17
17
  fontSize: 14,
18
18
  };
19
19
  const ZodFieldValidation = ({ localValue, path }) => {
20
- if (localValue.zodValidation.success) {
20
+ const { zodValidation } = localValue;
21
+ if (zodValidation.success) {
21
22
  return null;
22
23
  }
23
24
  return (jsx_runtime_1.jsxs("div", { style: legend, children: [
24
- jsx_runtime_1.jsx(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.zodValidation.error.format()._errors[0], type: "error" }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 0.5 }), jsx_runtime_1.jsx(InfoBubble_1.InfoBubble, { title: "Zod validation failure", children: jsx_runtime_1.jsxs("div", { style: stackTrace, children: [
25
- jsx_runtime_1.jsx("div", { style: stackTraceLabel, children: "Zod Validation has failed:" }), localValue.zodValidation.error.errors.map((error, index) => (
25
+ jsx_runtime_1.jsx(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: zodValidation.error.format()._errors[0], type: "error" }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 0.5 }), jsx_runtime_1.jsx(InfoBubble_1.InfoBubble, { title: "Zod validation failure", children: jsx_runtime_1.jsxs("div", { style: stackTrace, children: [
26
+ jsx_runtime_1.jsx("div", { style: stackTraceLabel, children: "Zod Validation has failed:" }), zodValidation.error.issues.map((error, index) => (
26
27
  // eslint-disable-next-line react/no-array-index-key
27
28
  jsx_runtime_1.jsxs("div", { style: stackTraceLabel, children: ["Type: ", error.code, " ",
28
29
  jsx_runtime_1.jsx("br", {}),
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
3
2
  import type { UpdaterFunction } from './ZodSwitch';
3
+ import type { AnyZodSchema } from './zod-schema-type';
4
4
  import type { JSONPath } from './zod-types';
5
5
  export declare const ZodMatrixEditor: React.FC<{
6
- readonly schema: z.ZodTypeAny;
6
+ readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: unknown[];
9
9
  readonly defaultValue: unknown[];
@@ -46,6 +46,7 @@ const ZodFieldValidation_1 = require("./ZodFieldValidation");
46
46
  const create_zod_values_1 = require("./create-zod-values");
47
47
  const deep_equal_1 = require("./deep-equal");
48
48
  const local_state_1 = require("./local-state");
49
+ const zod_schema_type_1 = require("./zod-schema-type");
49
50
  const rowStyle = {
50
51
  display: 'flex',
51
52
  flexDirection: 'row',
@@ -59,7 +60,7 @@ const ZodMatrixEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSa
59
60
  savedValue: defaultValue,
60
61
  });
61
62
  const [expanded, setExpanded] = (0, react_1.useState)(true);
62
- const def = schema._def;
63
+ const arrayElement = (0, zod_schema_type_1.getArrayElement)(schema);
63
64
  const suffix = (0, react_1.useMemo)(() => {
64
65
  return expanded ? ' [' : ' [...] ';
65
66
  }, [expanded]);
@@ -92,7 +93,7 @@ const ZodMatrixEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSa
92
93
  , { children: jsx_runtime_1.jsx("div", { style: rowStyle, children: row.map((item, _index) => {
93
94
  var _a;
94
95
  const actualIndex = rowIndex * dimensions + _index;
95
- return (jsx_runtime_1.jsx("div", { style: { flex: 1 }, children: jsx_runtime_1.jsx(ZodArrayItemEditor_1.ZodArrayItemEditor, { onChange: onChange, value: item, def: def, index: actualIndex, jsonPath: jsonPath, defaultValue: (_a = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue[actualIndex]) !== null && _a !== void 0 ? _a : (0, create_zod_values_1.createZodValues)(def.type, z, zodTypes), onSave: onSave, showSaveButton: showSaveButton, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad, mayRemove: false }) }, `${_index}${localValue.keyStabilityRevision}`));
96
+ return (jsx_runtime_1.jsx("div", { style: { flex: 1 }, children: jsx_runtime_1.jsx(ZodArrayItemEditor_1.ZodArrayItemEditor, { onChange: onChange, value: item, elementSchema: arrayElement, index: actualIndex, jsonPath: jsonPath, defaultValue: (_a = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue[actualIndex]) !== null && _a !== void 0 ? _a : (0, create_zod_values_1.createZodValues)(arrayElement, z, zodTypes), onSave: onSave, showSaveButton: showSaveButton, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad, mayRemove: false }) }, `${_index}${localValue.keyStabilityRevision}`));
96
97
  }) }) }, `${rowIndex}${localValue.keyStabilityRevision}`));
97
98
  }), value.length === 0 ? (jsx_runtime_1.jsx(SchemaSeparationLine_1.SchemaArrayItemSeparationLine, { schema: schema, index: 0, onChange: onChange, isLast: true, showAddButton: true })) : null] }) })) : null, jsx_runtime_1.jsx(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })
98
99
  ] }));
@@ -1,12 +1,12 @@
1
- import type { z } from 'zod';
2
1
  import type { UpdaterFunction } from './ZodSwitch';
2
+ import type { AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  export declare const ZodNullableEditor: React.FC<{
5
5
  showSaveButton: boolean;
6
6
  jsonPath: JSONPath;
7
7
  value: unknown;
8
8
  defaultValue: unknown;
9
- schema: z.ZodTypeAny;
9
+ schema: AnyZodSchema;
10
10
  setValue: UpdaterFunction<unknown>;
11
11
  onSave: UpdaterFunction<unknown>;
12
12
  onRemove: null | (() => void);
@@ -3,8 +3,9 @@ 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 zod_schema_type_1 = require("./zod-schema-type");
6
7
  const ZodNullableEditor = ({ jsonPath, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
7
- const { innerType } = schema._def;
8
+ const innerType = (0, zod_schema_type_1.getInnerType)(schema);
8
9
  return (jsx_runtime_1.jsx(ZodOrNullishEditor_1.ZodOrNullishEditor, { defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: schema, innerSchema: innerType, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: null, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad }));
9
10
  };
10
11
  exports.ZodNullableEditor = ZodNullableEditor;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
3
2
  import type { UpdaterFunction } from './ZodSwitch';
3
+ import type { AnyZodSchema } from './zod-schema-type';
4
4
  import type { JSONPath } from './zod-types';
5
5
  export declare const ZodNumberEditor: React.FC<{
6
- readonly schema: z.ZodTypeAny;
6
+ readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: number;
9
9
  readonly setValue: UpdaterFunction<number>;
@@ -8,44 +8,72 @@ const Fieldset_1 = require("./Fieldset");
8
8
  const SchemaLabel_1 = require("./SchemaLabel");
9
9
  const ZodFieldValidation_1 = require("./ZodFieldValidation");
10
10
  const local_state_1 = require("./local-state");
11
+ const zod_schema_type_1 = require("./zod-schema-type");
11
12
  const fullWidth = {
12
13
  width: '100%',
13
14
  };
14
15
  const getMinValue = (schema) => {
15
- const minCheck = schema._def.checks.find((c) => c.kind === 'min');
16
- if (!minCheck) {
16
+ var _a;
17
+ const { checks } = (0, zod_schema_type_1.getZodDef)(schema);
18
+ if (!checks)
17
19
  return -Infinity;
20
+ if ((0, zod_schema_type_1.isZodV3Schema)(schema)) {
21
+ // v3: {kind: "min", value: 0, inclusive: true}
22
+ const minCheck = checks.find((c) => c.kind === 'min');
23
+ if (!minCheck || !minCheck.inclusive)
24
+ return -Infinity;
25
+ return minCheck.value;
18
26
  }
19
- if (minCheck.kind !== 'min') {
20
- throw new Error('Expected min check');
27
+ // v4: check objects with _zod.def = {check: "greater_than", value: 0, inclusive: true}
28
+ for (const c of checks) {
29
+ const def = (_a = c._zod) === null || _a === void 0 ? void 0 : _a.def;
30
+ if ((def === null || def === void 0 ? void 0 : def.check) === 'greater_than' && def.inclusive) {
31
+ return def.value;
32
+ }
21
33
  }
22
- if (!minCheck.inclusive) {
23
- return -Infinity;
24
- }
25
- return minCheck.value;
34
+ return -Infinity;
26
35
  };
27
36
  const getMaxValue = (schema) => {
28
- const maxCheck = schema._def.checks.find((c) => c.kind === 'max');
29
- if (!maxCheck) {
37
+ var _a;
38
+ const { checks } = (0, zod_schema_type_1.getZodDef)(schema);
39
+ if (!checks)
30
40
  return Infinity;
41
+ if ((0, zod_schema_type_1.isZodV3Schema)(schema)) {
42
+ // v3: {kind: "max", value: 100, inclusive: true}
43
+ const maxCheck = checks.find((c) => c.kind === 'max');
44
+ if (!maxCheck || !maxCheck.inclusive)
45
+ return Infinity;
46
+ return maxCheck.value;
31
47
  }
32
- if (maxCheck.kind !== 'max') {
33
- throw new Error('Expected max check');
34
- }
35
- if (!maxCheck.inclusive) {
36
- return Infinity;
48
+ // v4: check objects with _zod.def = {check: "less_than", value: 100, inclusive: true}
49
+ for (const c of checks) {
50
+ const def = (_a = c._zod) === null || _a === void 0 ? void 0 : _a.def;
51
+ if ((def === null || def === void 0 ? void 0 : def.check) === 'less_than' && def.inclusive) {
52
+ return def.value;
53
+ }
37
54
  }
38
- return maxCheck.value;
55
+ return Infinity;
39
56
  };
40
57
  const getStep = (schema) => {
41
- const multipleStep = schema._def.checks.find((c) => c.kind === 'multipleOf');
42
- if (!multipleStep) {
58
+ var _a;
59
+ const { checks } = (0, zod_schema_type_1.getZodDef)(schema);
60
+ if (!checks)
43
61
  return undefined;
62
+ if ((0, zod_schema_type_1.isZodV3Schema)(schema)) {
63
+ // v3: {kind: "multipleOf", value: 5}
64
+ const multipleStep = checks.find((c) => c.kind === 'multipleOf');
65
+ if (!multipleStep)
66
+ return undefined;
67
+ return multipleStep.value;
44
68
  }
45
- if (multipleStep.kind !== 'multipleOf') {
46
- throw new Error('Expected multipleOf check');
69
+ // v4: check objects with _zod.def = {check: "multiple_of", value: 5}
70
+ for (const c of checks) {
71
+ const def = (_a = c._zod) === null || _a === void 0 ? void 0 : _a.def;
72
+ if ((def === null || def === void 0 ? void 0 : def.check) === 'multiple_of') {
73
+ return def.value;
74
+ }
47
75
  }
48
- return multipleStep.value;
76
+ return undefined;
49
77
  };
50
78
  const ZodNumberEditor = ({ jsonPath, value, schema, setValue, onSave, defaultValue, onRemove, showSaveButton, saving, saveDisabledByParent, mayPad, }) => {
51
79
  const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
@@ -1,13 +1,13 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
3
2
  import type { UpdaterFunction } from './ZodSwitch';
3
+ import type { AnyZodSchema } from './zod-schema-type';
4
4
  import type { JSONPath } from './zod-types';
5
5
  export type ObjectDiscrimatedUnionReplacement = {
6
6
  discriminator: string;
7
7
  markup: React.ReactNode;
8
8
  };
9
9
  export declare const ZodObjectEditor: React.FC<{
10
- readonly schema: z.ZodTypeAny;
10
+ readonly schema: AnyZodSchema;
11
11
  readonly jsonPath: JSONPath;
12
12
  readonly unsavedValue: Record<string, unknown>;
13
13
  readonly savedValue: Record<string, unknown>;
@@ -36,7 +36,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.ZodObjectEditor = void 0;
37
37
  const jsx_runtime_1 = require("react/jsx-runtime");
38
38
  const react_1 = __importStar(require("react"));
39
- const get_zod_if_possible_1 = require("../../get-zod-if-possible");
40
39
  const layout_1 = require("../layout");
41
40
  const Fieldset_1 = require("./Fieldset");
42
41
  const SchemaLabel_1 = require("./SchemaLabel");
@@ -45,11 +44,8 @@ const SchemaVerticalGuide_1 = require("./SchemaVerticalGuide");
45
44
  const ZodSwitch_1 = require("./ZodSwitch");
46
45
  const deep_equal_1 = require("./deep-equal");
47
46
  const local_state_1 = require("./local-state");
47
+ const zod_schema_type_1 = require("./zod-schema-type");
48
48
  const ZodObjectEditor = ({ schema, jsonPath, setValue, unsavedValue, savedValue, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, discriminatedUnionReplacement, }) => {
49
- const z = (0, get_zod_if_possible_1.useZodIfPossible)();
50
- if (!z) {
51
- throw new Error('expected zod');
52
- }
53
49
  const [expanded, setExpanded] = (0, react_1.useState)(true);
54
50
  const { localValue, onChange, RevisionContextProvider, reset } = (0, local_state_1.useLocalState)({
55
51
  schema,
@@ -57,12 +53,11 @@ const ZodObjectEditor = ({ schema, jsonPath, setValue, unsavedValue, savedValue,
57
53
  unsavedValue,
58
54
  savedValue,
59
55
  });
60
- const def = schema._def;
61
- const typeName = def.typeName;
62
- if (typeName !== z.ZodFirstPartyTypeKind.ZodObject) {
56
+ const typeName = (0, zod_schema_type_1.getZodSchemaType)(schema);
57
+ if (typeName !== 'object') {
63
58
  throw new Error('expected object');
64
59
  }
65
- const shape = def.shape();
60
+ const shape = (0, zod_schema_type_1.getObjectShape)(schema);
66
61
  const keys = Object.keys(shape);
67
62
  const isRoot = jsonPath.length === 0;
68
63
  const isDefaultValue = (0, react_1.useMemo)(() => {
@@ -1,12 +1,12 @@
1
- import type { z } from 'zod';
2
1
  import type { UpdaterFunction } from './ZodSwitch';
2
+ import type { AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  export declare const ZodOptionalEditor: React.FC<{
5
5
  showSaveButton: boolean;
6
6
  jsonPath: JSONPath;
7
7
  value: unknown;
8
8
  defaultValue: unknown;
9
- schema: z.ZodTypeAny;
9
+ schema: AnyZodSchema;
10
10
  setValue: UpdaterFunction<unknown>;
11
11
  onSave: UpdaterFunction<unknown>;
12
12
  onRemove: null | (() => void);
@@ -3,8 +3,9 @@ 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 zod_schema_type_1 = require("./zod-schema-type");
6
7
  const ZodOptionalEditor = ({ jsonPath, schema, setValue, onSave, defaultValue, value, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
7
- const { innerType } = schema._def;
8
+ const innerType = (0, zod_schema_type_1.getInnerType)(schema);
8
9
  return (jsx_runtime_1.jsx(ZodOrNullishEditor_1.ZodOrNullishEditor, { defaultValue: defaultValue, jsonPath: jsonPath, onRemove: onRemove, onSave: onSave, schema: schema, setValue: setValue, showSaveButton: showSaveButton, value: value, nullishValue: undefined, saving: saving, saveDisabledByParent: saveDisabledByParent, mayPad: mayPad, innerSchema: innerType }));
9
10
  };
10
11
  exports.ZodOptionalEditor = ZodOptionalEditor;
@@ -1,13 +1,13 @@
1
- import type { z } from 'zod';
2
1
  import type { UpdaterFunction } from './ZodSwitch';
2
+ import type { AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  export declare const ZodOrNullishEditor: React.FC<{
5
5
  showSaveButton: boolean;
6
6
  jsonPath: JSONPath;
7
7
  value: unknown;
8
8
  defaultValue: unknown;
9
- schema: z.ZodTypeAny;
10
- innerSchema: z.ZodTypeAny;
9
+ schema: AnyZodSchema;
10
+ innerSchema: AnyZodSchema;
11
11
  setValue: UpdaterFunction<unknown>;
12
12
  onSave: UpdaterFunction<unknown>;
13
13
  onRemove: null | (() => void);
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
3
2
  import type { UpdaterFunction } from './ZodSwitch';
3
+ import type { AnyZodSchema } from './zod-schema-type';
4
4
  import type { JSONPath } from './zod-types';
5
5
  export declare const ZodStaticFileEditor: React.FC<{
6
- readonly schema: z.ZodTypeAny;
6
+ readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: string;
9
9
  readonly defaultValue: string;
@@ -5,7 +5,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const Checkmark_1 = require("../../../icons/Checkmark");
7
7
  const ComboBox_1 = require("../../NewComposition/ComboBox");
8
- const get_zod_if_possible_1 = require("../../get-zod-if-possible");
9
8
  const use_static_files_1 = require("../../use-static-files");
10
9
  const Fieldset_1 = require("./Fieldset");
11
10
  const SchemaLabel_1 = require("./SchemaLabel");
@@ -15,21 +14,12 @@ const container = {
15
14
  width: '100%',
16
15
  };
17
16
  const ZodStaticFileEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
18
- const z = (0, get_zod_if_possible_1.useZodIfPossible)();
19
- if (!z) {
20
- throw new Error('expected zod');
21
- }
22
17
  const { localValue, onChange: setLocalValue, reset, } = (0, local_state_1.useLocalState)({
23
18
  schema,
24
19
  setValue,
25
20
  unsavedValue: value,
26
21
  savedValue: defaultValue,
27
22
  });
28
- const def = schema._def;
29
- const typeName = def.typeName;
30
- if (typeName !== z.ZodFirstPartyTypeKind.ZodString) {
31
- throw new Error('expected enum');
32
- }
33
23
  const isRoot = jsonPath.length === 0;
34
24
  const staticFiles = (0, use_static_files_1.useStaticFiles)();
35
25
  const comboBoxValues = (0, react_1.useMemo)(() => {
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
3
2
  import type { UpdaterFunction } from './ZodSwitch';
3
+ import type { AnyZodSchema } from './zod-schema-type';
4
4
  import type { JSONPath } from './zod-types';
5
5
  export declare const ZodStringEditor: React.FC<{
6
- readonly schema: z.ZodTypeAny;
6
+ readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: string;
9
9
  readonly defaultValue: string;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import type { z } from 'zod';
2
+ import type { AnyZodSchema } from './zod-schema-type';
3
3
  import type { JSONPath } from './zod-types';
4
4
  export type UpdaterFunction<T> = (updater: (oldValue: T) => T, forceApply: boolean, increment: boolean) => void;
5
5
  export declare const ZodSwitch: React.FC<{
6
- readonly schema: z.ZodTypeAny;
6
+ readonly schema: AnyZodSchema;
7
7
  readonly jsonPath: JSONPath;
8
8
  readonly value: unknown;
9
9
  readonly defaultValue: unknown;