@remotion/studio 4.0.438 → 4.0.439
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/Studio.js +2 -2
- package/dist/api/helpers/calc-new-props.js +5 -8
- package/dist/api/update-default-props.d.ts +7 -3
- package/dist/api/update-default-props.js +7 -21
- package/dist/api/visual-control.js +6 -0
- package/dist/components/DefaultPropsEditor.d.ts +8 -0
- package/dist/components/DefaultPropsEditor.js +15 -0
- package/dist/components/Editor.js +0 -14
- package/dist/components/EditorContexts.js +6 -3
- package/dist/components/KeyboardShortcutsExplainer.js +6 -2
- package/dist/components/MenuBuildIndicator.js +1 -0
- package/dist/components/MenuToolbar.js +3 -1
- package/dist/components/NewComposition/InputDragger.js +2 -2
- package/dist/components/NewComposition/RemTextarea.js +4 -0
- package/dist/components/ObserveDefaultPropsContext.d.ts +11 -0
- package/dist/components/ObserveDefaultPropsContext.js +120 -0
- package/dist/components/OptionsPanel.js +90 -28
- package/dist/components/RenderModal/DataEditor.d.ts +4 -5
- package/dist/components/RenderModal/DataEditor.js +9 -111
- package/dist/components/RenderModal/RenderModalJSONPropsEditor.d.ts +1 -1
- package/dist/components/RenderModal/RenderModalJSONPropsEditor.js +52 -48
- package/dist/components/RenderModal/SchemaEditor/Fieldset.d.ts +0 -1
- package/dist/components/RenderModal/SchemaEditor/SchemaEditor.d.ts +4 -9
- package/dist/components/RenderModal/SchemaEditor/SchemaEditor.js +2 -61
- package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.d.ts +0 -1
- package/dist/components/RenderModal/SchemaEditor/SchemaErrorMessages.js +2 -3
- package/dist/components/RenderModal/SchemaEditor/SchemaLabel.d.ts +0 -6
- package/dist/components/RenderModal/SchemaEditor/SchemaLabel.js +2 -5
- package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.d.ts +3 -1
- package/dist/components/RenderModal/SchemaEditor/SchemaSeparationLine.js +1 -1
- package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.js +15 -26
- package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodArrayItemEditor.js +7 -12
- package/dist/components/RenderModal/SchemaEditor/ZodBooleanEditor.d.ts +0 -7
- package/dist/components/RenderModal/SchemaEditor/ZodBooleanEditor.js +5 -15
- package/dist/components/RenderModal/SchemaEditor/ZodColorEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodColorEditor.js +30 -28
- package/dist/components/RenderModal/SchemaEditor/ZodDateEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodDateEditor.js +13 -17
- package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodDefaultEditor.js +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodDiscriminatedUnionEditor.js +13 -28
- package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.d.ts +1 -5
- package/dist/components/RenderModal/SchemaEditor/ZodEffectEditor.js +11 -12
- package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.d.ts +1 -5
- package/dist/components/RenderModal/SchemaEditor/ZodEnumEditor.js +12 -16
- package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.d.ts +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.js +1 -2
- package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodMatrixEditor.js +20 -30
- package/dist/components/RenderModal/SchemaEditor/ZodNonEditableValue.d.ts +0 -2
- package/dist/components/RenderModal/SchemaEditor/ZodNonEditableValue.js +3 -6
- package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodNullableEditor.js +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodNumberEditor.js +16 -21
- package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.d.ts +2 -7
- package/dist/components/RenderModal/SchemaEditor/ZodObjectEditor.js +27 -49
- package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodOptionalEditor.js +2 -2
- package/dist/components/RenderModal/SchemaEditor/ZodOrNullishEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodOrNullishEditor.js +8 -15
- package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodStaticFileEditor.js +10 -15
- package/dist/components/RenderModal/SchemaEditor/ZodStringEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodStringEditor.js +13 -17
- package/dist/components/RenderModal/SchemaEditor/ZodSwitch.d.ts +3 -6
- package/dist/components/RenderModal/SchemaEditor/ZodSwitch.js +27 -27
- package/dist/components/RenderModal/SchemaEditor/ZodTextareaEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodTextareaEditor.js +45 -17
- package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.d.ts +1 -6
- package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.js +15 -26
- package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodTupleItemEditor.js +4 -11
- package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/ZodUnionEditor.js +6 -6
- package/dist/components/RenderModal/ServerRenderModal.js +9 -3
- package/dist/components/RenderModal/WebRenderModal.js +9 -3
- package/dist/components/RenderModal/get-render-modal-warnings.d.ts +1 -2
- package/dist/components/RenderModal/get-render-modal-warnings.js +4 -6
- package/dist/components/RenderQueue/actions.d.ts +1 -2
- package/dist/components/RenderQueue/actions.js +1 -13
- package/dist/components/Timeline/TimelineExpandedSection.js +7 -1
- package/dist/components/Timeline/TimelineFieldRow.d.ts +1 -0
- package/dist/components/Timeline/TimelineFieldRow.js +25 -3
- package/dist/components/Timeline/TimelineNumberField.js +4 -6
- package/dist/components/Timeline/TimelineRotationField.js +4 -6
- package/dist/components/Timeline/TimelineTranslateField.js +28 -13
- package/dist/components/TopPanel.js +10 -5
- package/dist/components/UndoRedoButtons.d.ts +2 -0
- package/dist/components/UndoRedoButtons.js +116 -0
- package/dist/components/VisualControls/VisualControlHandle.js +18 -18
- package/dist/components/VisualControls/VisualControlsUndoSync.d.ts +2 -0
- package/dist/components/VisualControls/VisualControlsUndoSync.js +23 -0
- package/dist/error-overlay/react-overlay/listen-to-runtime-errors.js +0 -1
- package/dist/esm/{chunk-ba0scebn.js → chunk-nnz9f1vq.js} +4233 -5091
- package/dist/esm/index.mjs +25 -28
- package/dist/esm/internals.mjs +4233 -5091
- package/dist/esm/previewEntry.mjs +4427 -5292
- package/dist/esm/renderEntry.mjs +6 -6
- package/dist/helpers/client-id.js +9 -0
- package/dist/helpers/document-title.d.ts +0 -1
- package/dist/helpers/document-title.js +1 -17
- package/dist/hot-middleware-client/process-update.js +6 -14
- package/dist/icons/redo.d.ts +3 -0
- package/dist/icons/redo.js +8 -0
- package/dist/icons/undo.d.ts +3 -0
- package/dist/icons/undo.js +8 -0
- package/dist/renderEntry.js +7 -6
- package/dist/visual-controls/VisualControls.js +9 -5
- package/dist/visual-controls/get-current-edited-value.js +5 -4
- package/dist/visual-controls/visual-control-store.d.ts +7 -0
- package/dist/visual-controls/visual-control-store.js +22 -0
- package/package.json +9 -9
- package/dist/components/GlobalPropsEditorUpdateButton.d.ts +0 -5
- package/dist/components/GlobalPropsEditorUpdateButton.js +0 -78
- package/dist/components/RenderModal/SchemaEditor/SchemaSaveButton.d.ts +0 -5
- package/dist/components/RenderModal/SchemaEditor/SchemaSaveButton.js +0 -18
- package/dist/components/RenderModal/SchemaEditor/local-state.d.ts +0 -25
- package/dist/components/RenderModal/SchemaEditor/local-state.js +0 -107
|
@@ -38,18 +38,14 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const remotion_1 = require("remotion");
|
|
40
40
|
const no_react_1 = require("remotion/no-react");
|
|
41
|
-
const fast_refresh_context_1 = require("../../fast-refresh-context");
|
|
42
41
|
const client_id_1 = require("../../helpers/client-id");
|
|
43
42
|
const colors_1 = require("../../helpers/colors");
|
|
44
43
|
const get_zod_if_possible_1 = require("../get-zod-if-possible");
|
|
45
44
|
const layout_1 = require("../layout");
|
|
46
45
|
const ValidationMessage_1 = require("../NewComposition/ValidationMessage");
|
|
47
|
-
const NotificationCenter_1 = require("../Notifications/NotificationCenter");
|
|
48
|
-
const actions_1 = require("../RenderQueue/actions");
|
|
49
46
|
const SegmentedControl_1 = require("../SegmentedControl");
|
|
50
47
|
const get_render_modal_warnings_1 = require("./get-render-modal-warnings");
|
|
51
48
|
const RenderModalJSONPropsEditor_1 = require("./RenderModalJSONPropsEditor");
|
|
52
|
-
const extract_enum_json_paths_1 = require("./SchemaEditor/extract-enum-json-paths");
|
|
53
49
|
const SchemaEditor_1 = require("./SchemaEditor/SchemaEditor");
|
|
54
50
|
const SchemaErrorMessages_1 = require("./SchemaEditor/SchemaErrorMessages");
|
|
55
51
|
const zod_schema_type_1 = require("./SchemaEditor/zod-schema-type");
|
|
@@ -99,10 +95,15 @@ const getPersistedShowWarningState = () => {
|
|
|
99
95
|
const setPersistedShowWarningState = (val) => {
|
|
100
96
|
localStorage.setItem(persistanceKey, String(Boolean(val)));
|
|
101
97
|
};
|
|
102
|
-
const DataEditor = ({ unresolvedComposition, defaultProps, setDefaultProps,
|
|
98
|
+
const DataEditor = ({ unresolvedComposition, defaultProps, setDefaultProps, propsEditType, canSaveDefaultProps, }) => {
|
|
103
99
|
const [mode, setMode] = (0, react_1.useState)('schema');
|
|
104
100
|
const [showWarning, setShowWarningWithoutPersistance] = (0, react_1.useState)(() => getPersistedShowWarningState());
|
|
105
|
-
const
|
|
101
|
+
const jsonEditorSetValue = (0, react_1.useCallback)((newProps) => {
|
|
102
|
+
setDefaultProps(typeof newProps === 'function' ? newProps : () => newProps, { shouldSave: false });
|
|
103
|
+
}, [setDefaultProps]);
|
|
104
|
+
const onSave = (0, react_1.useCallback)(() => {
|
|
105
|
+
setDefaultProps((p) => p, { shouldSave: true });
|
|
106
|
+
}, [setDefaultProps]);
|
|
106
107
|
const inJSONEditor = mode === 'json';
|
|
107
108
|
const serializedJSON = (0, react_1.useMemo)(() => {
|
|
108
109
|
if (!inJSONEditor) {
|
|
@@ -116,11 +117,7 @@ const DataEditor = ({ unresolvedComposition, defaultProps, setDefaultProps, mayS
|
|
|
116
117
|
});
|
|
117
118
|
}, [inJSONEditor, defaultProps]);
|
|
118
119
|
const cliProps = (0, remotion_1.getInputProps)();
|
|
119
|
-
const [canSaveDefaultPropsObjectState, setCanSaveDefaultProps] = (0, react_1.useState)({
|
|
120
|
-
[unresolvedComposition.id]: get_render_modal_warnings_1.defaultTypeCanSaveState,
|
|
121
|
-
});
|
|
122
120
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
123
|
-
const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
|
|
124
121
|
const schema = (0, react_1.useMemo)(() => {
|
|
125
122
|
if (!z) {
|
|
126
123
|
return 'no-zod';
|
|
@@ -153,56 +150,7 @@ const DataEditor = ({ unresolvedComposition, defaultProps, setDefaultProps, mayS
|
|
|
153
150
|
return val(prevVal);
|
|
154
151
|
});
|
|
155
152
|
}, []);
|
|
156
|
-
const
|
|
157
|
-
return canSaveDefaultPropsObjectState[unresolvedComposition.id]
|
|
158
|
-
? canSaveDefaultPropsObjectState[unresolvedComposition.id]
|
|
159
|
-
: get_render_modal_warnings_1.defaultTypeCanSaveState;
|
|
160
|
-
}, [canSaveDefaultPropsObjectState, unresolvedComposition.id]);
|
|
161
|
-
const showSaveButton = mayShowSaveButton && canSaveDefaultProps.canUpdate;
|
|
162
|
-
const { fastRefreshes } = (0, react_1.useContext)(fast_refresh_context_1.FastRefreshContext);
|
|
163
|
-
const checkIfCanSaveDefaultProps = (0, react_1.useCallback)(async () => {
|
|
164
|
-
try {
|
|
165
|
-
const can = await (0, actions_1.canUpdateDefaultProps)(unresolvedComposition.id, readOnlyStudio);
|
|
166
|
-
if (can.canUpdate) {
|
|
167
|
-
setCanSaveDefaultProps((prevState) => ({
|
|
168
|
-
...prevState,
|
|
169
|
-
[unresolvedComposition.id]: {
|
|
170
|
-
canUpdate: true,
|
|
171
|
-
},
|
|
172
|
-
}));
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
setCanSaveDefaultProps((prevState) => ({
|
|
176
|
-
...prevState,
|
|
177
|
-
[unresolvedComposition.id]: {
|
|
178
|
-
canUpdate: false,
|
|
179
|
-
reason: can.reason,
|
|
180
|
-
determined: true,
|
|
181
|
-
},
|
|
182
|
-
}));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
catch (err) {
|
|
186
|
-
setCanSaveDefaultProps((prevState) => ({
|
|
187
|
-
...prevState,
|
|
188
|
-
[unresolvedComposition.id]: {
|
|
189
|
-
canUpdate: false,
|
|
190
|
-
reason: err.message,
|
|
191
|
-
determined: true,
|
|
192
|
-
},
|
|
193
|
-
}));
|
|
194
|
-
}
|
|
195
|
-
}, [readOnlyStudio, unresolvedComposition.id]);
|
|
196
|
-
(0, react_1.useEffect)(() => {
|
|
197
|
-
checkIfCanSaveDefaultProps();
|
|
198
|
-
}, [checkIfCanSaveDefaultProps]);
|
|
199
|
-
const { previewServerState, subscribeToEvent } = (0, react_1.useContext)(client_id_1.StudioServerConnectionCtx);
|
|
200
|
-
(0, react_1.useEffect)(() => {
|
|
201
|
-
const unsub = subscribeToEvent('root-file-changed', checkIfCanSaveDefaultProps);
|
|
202
|
-
return () => {
|
|
203
|
-
unsub();
|
|
204
|
-
};
|
|
205
|
-
}, [checkIfCanSaveDefaultProps, subscribeToEvent]);
|
|
153
|
+
const { previewServerState } = (0, react_1.useContext)(client_id_1.StudioServerConnectionCtx);
|
|
206
154
|
const modeItems = (0, react_1.useMemo)(() => {
|
|
207
155
|
return [
|
|
208
156
|
{
|
|
@@ -223,56 +171,6 @@ const DataEditor = ({ unresolvedComposition, defaultProps, setDefaultProps, mayS
|
|
|
223
171
|
},
|
|
224
172
|
];
|
|
225
173
|
}, [mode]);
|
|
226
|
-
const onUpdate = (0, react_1.useCallback)(() => {
|
|
227
|
-
if (schema === 'no-zod' || schema === 'no-schema' || z === null) {
|
|
228
|
-
(0, NotificationCenter_1.showNotification)('Cannot update default props: No Zod schema', 2000);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
(0, actions_1.callUpdateDefaultPropsApi)(unresolvedComposition.id, defaultProps, (0, extract_enum_json_paths_1.extractEnumJsonPaths)({ schema, zodRuntime: z, currentPath: [], zodTypes })).then((response) => {
|
|
232
|
-
if (!response.success) {
|
|
233
|
-
(0, NotificationCenter_1.showNotification)(`Cannot update default props: ${response.reason}`, 2000);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}, [schema, z, unresolvedComposition.id, defaultProps, zodTypes]);
|
|
237
|
-
const onSave = (0, react_1.useCallback)((updater) => {
|
|
238
|
-
var _a;
|
|
239
|
-
if (schema === 'no-zod' || schema === 'no-schema' || z === null) {
|
|
240
|
-
(0, NotificationCenter_1.showNotification)('Cannot update default props: No Zod schema', 2000);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
window.remotion_ignoreFastRefreshUpdate = fastRefreshes + 1;
|
|
244
|
-
setSaving(true);
|
|
245
|
-
const newDefaultProps = updater((_a = unresolvedComposition.defaultProps) !== null && _a !== void 0 ? _a : {});
|
|
246
|
-
(0, actions_1.callUpdateDefaultPropsApi)(unresolvedComposition.id, newDefaultProps, (0, extract_enum_json_paths_1.extractEnumJsonPaths)({
|
|
247
|
-
schema,
|
|
248
|
-
zodRuntime: z,
|
|
249
|
-
currentPath: [],
|
|
250
|
-
zodTypes,
|
|
251
|
-
}))
|
|
252
|
-
.then((response) => {
|
|
253
|
-
if (!response.success) {
|
|
254
|
-
// eslint-disable-next-line no-console
|
|
255
|
-
console.log(response.stack);
|
|
256
|
-
(0, NotificationCenter_1.showNotification)(`Cannot update default props: ${response.reason}. See console for more information.`, 2000);
|
|
257
|
-
}
|
|
258
|
-
updateCompositionDefaultProps(unresolvedComposition.id, newDefaultProps);
|
|
259
|
-
})
|
|
260
|
-
.catch((err) => {
|
|
261
|
-
(0, NotificationCenter_1.showNotification)(`Cannot update default props: ${err.message}`, 2000);
|
|
262
|
-
})
|
|
263
|
-
.finally(() => {
|
|
264
|
-
setSaving(false);
|
|
265
|
-
});
|
|
266
|
-
}, [
|
|
267
|
-
schema,
|
|
268
|
-
z,
|
|
269
|
-
zodTypes,
|
|
270
|
-
fastRefreshes,
|
|
271
|
-
setSaving,
|
|
272
|
-
unresolvedComposition.defaultProps,
|
|
273
|
-
unresolvedComposition.id,
|
|
274
|
-
updateCompositionDefaultProps,
|
|
275
|
-
]);
|
|
276
174
|
const connectionStatus = previewServerState.type;
|
|
277
175
|
const warnings = (0, react_1.useMemo)(() => {
|
|
278
176
|
return (0, get_render_modal_warnings_1.getRenderModalWarnings)({
|
|
@@ -326,6 +224,6 @@ const DataEditor = ({ unresolvedComposition, defaultProps, setDefaultProps, mayS
|
|
|
326
224
|
? warnings.map((warning) => (jsx_runtime_1.jsxs(react_1.default.Fragment, { children: [
|
|
327
225
|
jsx_runtime_1.jsx(layout_1.Spacing, { y: 1 }), jsx_runtime_1.jsx(ValidationMessage_1.ValidationMessage, { message: warning, align: "flex-start", type: "warning" })
|
|
328
226
|
] }, warning)))
|
|
329
|
-
: null] }), mode === 'schema' ? (jsx_runtime_1.jsx(SchemaEditor_1.SchemaEditor, {
|
|
227
|
+
: null] }), mode === 'schema' ? (jsx_runtime_1.jsx(SchemaEditor_1.SchemaEditor, { value: defaultProps, setValue: setDefaultProps, schema: schema })) : (jsx_runtime_1.jsx(RenderModalJSONPropsEditor_1.RenderModalJSONPropsEditor, { value: defaultProps !== null && defaultProps !== void 0 ? defaultProps : {}, setValue: jsonEditorSetValue, onSave: onSave, serializedJSON: serializedJSON, defaultProps: unresolvedComposition.defaultProps, schema: schema, compositionId: unresolvedComposition.id }))] }));
|
|
330
228
|
};
|
|
331
229
|
exports.DataEditor = DataEditor;
|
|
@@ -5,8 +5,8 @@ export declare const RenderModalJSONPropsEditor: React.FC<{
|
|
|
5
5
|
readonly value: unknown;
|
|
6
6
|
readonly setValue: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;
|
|
7
7
|
readonly onSave: () => void;
|
|
8
|
-
readonly showSaveButton: boolean;
|
|
9
8
|
readonly serializedJSON: SerializedJSONWithCustomFields | null;
|
|
10
9
|
readonly defaultProps: Record<string, unknown>;
|
|
11
10
|
readonly schema: AnyZodSchema;
|
|
11
|
+
readonly compositionId: string;
|
|
12
12
|
}>;
|
|
@@ -36,10 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.RenderModalJSONPropsEditor = void 0;
|
|
37
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
|
+
const react_2 = require("react");
|
|
39
40
|
const no_react_1 = require("remotion/no-react");
|
|
41
|
+
const client_id_1 = require("../../helpers/client-id");
|
|
40
42
|
const colors_1 = require("../../helpers/colors");
|
|
41
|
-
const document_title_1 = require("../../helpers/document-title");
|
|
42
|
-
const use_keybinding_1 = require("../../helpers/use-keybinding");
|
|
43
43
|
const Button_1 = require("../Button");
|
|
44
44
|
const layout_1 = require("../layout");
|
|
45
45
|
const RemTextarea_1 = require("../NewComposition/RemTextarea");
|
|
@@ -57,6 +57,24 @@ const scrollable = {
|
|
|
57
57
|
flexDirection: 'column',
|
|
58
58
|
flex: 1,
|
|
59
59
|
};
|
|
60
|
+
const parseJS = (value, schema) => {
|
|
61
|
+
try {
|
|
62
|
+
const zodValidation = (0, zod_schema_type_1.zodSafeParse)(schema, value);
|
|
63
|
+
return {
|
|
64
|
+
str: JSON.stringify(value, null, 2),
|
|
65
|
+
value,
|
|
66
|
+
validJSON: true,
|
|
67
|
+
zodValidation,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return {
|
|
72
|
+
str: JSON.stringify(value, null, 2),
|
|
73
|
+
validJSON: false,
|
|
74
|
+
error: e.message,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
60
78
|
const parseJSON = (str, schema) => {
|
|
61
79
|
try {
|
|
62
80
|
const value = no_react_1.NoReactInternals.deserializeJSONWithSpecialTypes(str);
|
|
@@ -67,14 +85,31 @@ const parseJSON = (str, schema) => {
|
|
|
67
85
|
return { str, validJSON: false, error: e.message };
|
|
68
86
|
}
|
|
69
87
|
};
|
|
70
|
-
const RenderModalJSONPropsEditor = ({ setValue, value, defaultProps, onSave,
|
|
88
|
+
const RenderModalJSONPropsEditor = ({ setValue, value, defaultProps, onSave, serializedJSON, schema, compositionId, }) => {
|
|
71
89
|
if (serializedJSON === null) {
|
|
72
90
|
throw new Error('expecting serializedJSON to be defined');
|
|
73
91
|
}
|
|
74
|
-
const
|
|
92
|
+
const { subscribeToEvent } = (0, react_2.useContext)(client_id_1.StudioServerConnectionCtx);
|
|
75
93
|
const [localValue, setLocalValue] = react_1.default.useState(() => {
|
|
76
94
|
return parseJSON(serializedJSON.serializedString, schema);
|
|
77
95
|
});
|
|
96
|
+
(0, react_1.useEffect)(() => {
|
|
97
|
+
const unsub = subscribeToEvent('default-props-updatable-changed', (e) => {
|
|
98
|
+
if (e.type !== 'default-props-updatable-changed') {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (e.compositionId !== compositionId) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const { result } = e;
|
|
105
|
+
if (result.canUpdate) {
|
|
106
|
+
setLocalValue(parseJS(result.currentDefaultProps, schema));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return () => {
|
|
110
|
+
unsub();
|
|
111
|
+
};
|
|
112
|
+
}, [subscribeToEvent, compositionId, schema]);
|
|
78
113
|
const onPretty = (0, react_1.useCallback)(() => {
|
|
79
114
|
if (!localValue.validJSON) {
|
|
80
115
|
return;
|
|
@@ -84,74 +119,43 @@ const RenderModalJSONPropsEditor = ({ setValue, value, defaultProps, onSave, sho
|
|
|
84
119
|
}, [localValue, setLocalValue]);
|
|
85
120
|
const onChange = (0, react_1.useCallback)((e) => {
|
|
86
121
|
const parsed = parseJSON(e.target.value, schema);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
str: e.target.value,
|
|
91
|
-
value: parsed.value,
|
|
92
|
-
validJSON: parsed.validJSON,
|
|
93
|
-
zodValidation: validationResult,
|
|
94
|
-
});
|
|
95
|
-
if (validationResult.success) {
|
|
96
|
-
setValue(parsed.value);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
setLocalValue({
|
|
101
|
-
str: e.target.value,
|
|
102
|
-
validJSON: parsed.validJSON,
|
|
103
|
-
error: parsed.error,
|
|
104
|
-
});
|
|
122
|
+
setLocalValue(parsed);
|
|
123
|
+
if (parsed.validJSON && parsed.zodValidation.success) {
|
|
124
|
+
setValue(parsed.value);
|
|
105
125
|
}
|
|
106
126
|
}, [schema, setValue]);
|
|
127
|
+
const hasError = (0, react_1.useMemo)(() => {
|
|
128
|
+
return !localValue.validJSON || !localValue.zodValidation.success;
|
|
129
|
+
}, [localValue]);
|
|
107
130
|
const hasChanged = (0, react_1.useMemo)(() => {
|
|
108
131
|
return !(0, deep_equal_1.deepEqual)(value, defaultProps);
|
|
109
132
|
}, [defaultProps, value]);
|
|
110
|
-
(0, react_1.useEffect)(() => {
|
|
111
|
-
(0, document_title_1.setUnsavedProps)(hasChanged);
|
|
112
|
-
}, [hasChanged]);
|
|
113
133
|
const onQuickSave = (0, react_1.useCallback)(() => {
|
|
114
|
-
if (hasChanged) {
|
|
134
|
+
if (hasChanged && !hasError) {
|
|
115
135
|
onSave();
|
|
116
136
|
}
|
|
117
|
-
}, [hasChanged, onSave]);
|
|
137
|
+
}, [hasChanged, hasError, onSave]);
|
|
118
138
|
// If schema is changed in code
|
|
119
139
|
(0, react_1.useEffect)(() => {
|
|
120
140
|
setLocalValue(parseJSON(localValue.str, schema));
|
|
121
141
|
}, [localValue.str, schema]);
|
|
122
|
-
(0, react_1.useEffect)(() => {
|
|
123
|
-
const save = keybindings.registerKeybinding({
|
|
124
|
-
event: 'keydown',
|
|
125
|
-
key: 's',
|
|
126
|
-
commandCtrlKey: true,
|
|
127
|
-
callback: onQuickSave,
|
|
128
|
-
preventDefault: true,
|
|
129
|
-
triggerIfInputFieldFocused: true,
|
|
130
|
-
keepRegisteredWhenNotHighestContext: false,
|
|
131
|
-
});
|
|
132
|
-
return () => {
|
|
133
|
-
save.unregister();
|
|
134
|
-
};
|
|
135
|
-
}, [keybindings, onQuickSave, onSave]);
|
|
136
142
|
const reset = (0, react_1.useCallback)(() => {
|
|
137
143
|
setValue(defaultProps);
|
|
138
144
|
setLocalValue(parseJSON(JSON.stringify(defaultProps, null, 2), schema));
|
|
139
145
|
}, [defaultProps, schema, setValue]);
|
|
140
146
|
const textAreaStyle = (0, react_1.useMemo)(() => {
|
|
141
|
-
|
|
142
|
-
if (!fail) {
|
|
147
|
+
if (!hasError) {
|
|
143
148
|
return style;
|
|
144
149
|
}
|
|
145
150
|
return {
|
|
146
151
|
...style,
|
|
147
152
|
borderColor: colors_1.FAIL_COLOR,
|
|
148
153
|
};
|
|
149
|
-
}, [
|
|
154
|
+
}, [hasError]);
|
|
150
155
|
return (jsx_runtime_1.jsxs("div", { style: scrollable, children: [
|
|
151
|
-
jsx_runtime_1.jsx(RemTextarea_1.RemTextarea, { onChange: onChange, value: localValue.str, status: localValue.validJSON ? 'ok' : 'error', style: textAreaStyle }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1 }), localValue.validJSON === false ? (jsx_runtime_1.jsx(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.error, type: "error" })) : localValue.zodValidation.success === false ? (jsx_runtime_1.jsx(ZodErrorMessages_1.ZodErrorMessages, { zodValidationResult: localValue.zodValidation, viewTab: "json" })) : null, jsx_runtime_1.jsx(layout_1.Spacing, { y: 1 }), jsx_runtime_1.jsxs(layout_1.Row, { children: [
|
|
152
|
-
jsx_runtime_1.jsx(Button_1.Button, { disabled: !(hasChanged || !localValue.validJSON), onClick: reset, children: "Reset" }), jsx_runtime_1.jsx(layout_1.Flex, {}), jsx_runtime_1.jsx(Button_1.Button, { disabled: !localValue.validJSON, onClick: onPretty, children: "Format" }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1 })
|
|
153
|
-
|
|
154
|
-
!hasChanged, children: "Save" })) : null] })
|
|
156
|
+
jsx_runtime_1.jsx(RemTextarea_1.RemTextarea, { onChange: onChange, onBlur: onQuickSave, value: localValue.str, status: localValue.validJSON ? 'ok' : 'error', style: textAreaStyle }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1 }), jsx_runtime_1.jsx("div", { "data-testid": "json-props-error", children: localValue.validJSON === false ? (jsx_runtime_1.jsx(ValidationMessage_1.ValidationMessage, { align: "flex-start", message: localValue.error, type: "error" })) : localValue.zodValidation.success === false ? (jsx_runtime_1.jsx(ZodErrorMessages_1.ZodErrorMessages, { zodValidationResult: localValue.zodValidation, viewTab: "json" })) : null }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1 }), jsx_runtime_1.jsxs(layout_1.Row, { children: [
|
|
157
|
+
jsx_runtime_1.jsx(Button_1.Button, { disabled: !(hasChanged || !localValue.validJSON), onClick: reset, children: "Reset" }), jsx_runtime_1.jsx(layout_1.Flex, {}), jsx_runtime_1.jsx(Button_1.Button, { disabled: !localValue.validJSON, onClick: onPretty, children: "Format" }), jsx_runtime_1.jsx(layout_1.Spacing, { x: 1 })
|
|
158
|
+
] })
|
|
155
159
|
] }));
|
|
156
160
|
};
|
|
157
161
|
exports.RenderModalJSONPropsEditor = RenderModalJSONPropsEditor;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { AnyZodSchema
|
|
2
|
+
import type { AnyZodSchema } from './zod-schema-type';
|
|
3
|
+
import type { UpdaterFunction } from './ZodSwitch';
|
|
3
4
|
export declare const SchemaEditor: React.FC<{
|
|
4
5
|
readonly schema: AnyZodSchema;
|
|
5
|
-
readonly
|
|
6
|
-
readonly setValue:
|
|
7
|
-
readonly zodValidationResult: ZodSafeParseResult;
|
|
8
|
-
readonly savedDefaultProps: Record<string, unknown>;
|
|
9
|
-
readonly onSave: (updater: (oldState: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
10
|
-
readonly showSaveButton: boolean;
|
|
11
|
-
readonly saving: boolean;
|
|
12
|
-
readonly saveDisabledByParent: boolean;
|
|
6
|
+
readonly value: Record<string, unknown>;
|
|
7
|
+
readonly setValue: UpdaterFunction<Record<string, unknown>>;
|
|
13
8
|
}>;
|
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SchemaEditor = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const remotion_1 = require("remotion");
|
|
7
|
-
const document_title_1 = require("../../../helpers/document-title");
|
|
8
|
-
const use_keybinding_1 = require("../../../helpers/use-keybinding");
|
|
9
5
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
10
6
|
const is_menu_item_1 = require("../../Menu/is-menu-item");
|
|
11
|
-
const deep_equal_1 = require("./deep-equal");
|
|
12
|
-
const local_state_1 = require("./local-state");
|
|
13
7
|
const SchemaErrorMessages_1 = require("./SchemaErrorMessages");
|
|
14
8
|
const scroll_to_default_props_path_1 = require("./scroll-to-default-props-path");
|
|
15
9
|
const zod_schema_type_1 = require("./zod-schema-type");
|
|
@@ -19,68 +13,15 @@ const scrollable = {
|
|
|
19
13
|
flexDirection: 'column',
|
|
20
14
|
overflowY: 'auto',
|
|
21
15
|
};
|
|
22
|
-
const SchemaEditor = ({ schema,
|
|
23
|
-
const keybindings = (0, use_keybinding_1.useKeybinding)();
|
|
24
|
-
const [revision, setRevision] = (0, react_1.useState)(0);
|
|
25
|
-
const revisionState = (0, react_1.useMemo)(() => {
|
|
26
|
-
return {
|
|
27
|
-
childResetRevision: revision,
|
|
28
|
-
};
|
|
29
|
-
}, [revision]);
|
|
30
|
-
(0, react_1.useEffect)(() => {
|
|
31
|
-
const bumpRevision = () => {
|
|
32
|
-
setRevision((old) => old + 1);
|
|
33
|
-
};
|
|
34
|
-
window.addEventListener(remotion_1.Internals.PROPS_UPDATED_EXTERNALLY, bumpRevision);
|
|
35
|
-
return () => {
|
|
36
|
-
window.removeEventListener(remotion_1.Internals.PROPS_UPDATED_EXTERNALLY, bumpRevision);
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
16
|
+
const SchemaEditor = ({ schema, value, setValue }) => {
|
|
39
17
|
const z = (0, get_zod_if_possible_1.useZodIfPossible)();
|
|
40
18
|
if (!z) {
|
|
41
19
|
throw new Error('expected zod');
|
|
42
20
|
}
|
|
43
|
-
const hasChanged = (0, react_1.useMemo)(() => {
|
|
44
|
-
return !(0, deep_equal_1.deepEqual)(savedDefaultProps, unsavedDefaultProps);
|
|
45
|
-
}, [savedDefaultProps, unsavedDefaultProps]);
|
|
46
|
-
(0, react_1.useEffect)(() => {
|
|
47
|
-
(0, document_title_1.setUnsavedProps)(hasChanged);
|
|
48
|
-
}, [hasChanged]);
|
|
49
|
-
const onQuickSave = (0, react_1.useCallback)(() => {
|
|
50
|
-
if (hasChanged && showSaveButton) {
|
|
51
|
-
onSave(() => {
|
|
52
|
-
return unsavedDefaultProps;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}, [hasChanged, onSave, showSaveButton, unsavedDefaultProps]);
|
|
56
|
-
(0, react_1.useEffect)(() => {
|
|
57
|
-
const save = keybindings.registerKeybinding({
|
|
58
|
-
event: 'keydown',
|
|
59
|
-
key: 's',
|
|
60
|
-
commandCtrlKey: true,
|
|
61
|
-
callback: onQuickSave,
|
|
62
|
-
preventDefault: true,
|
|
63
|
-
triggerIfInputFieldFocused: true,
|
|
64
|
-
keepRegisteredWhenNotHighestContext: true,
|
|
65
|
-
});
|
|
66
|
-
return () => {
|
|
67
|
-
save.unregister();
|
|
68
|
-
};
|
|
69
|
-
}, [keybindings, onQuickSave, onSave]);
|
|
70
21
|
const typeName = (0, zod_schema_type_1.getZodSchemaType)(schema);
|
|
71
|
-
const reset = (0, react_1.useCallback)(() => {
|
|
72
|
-
setValue(savedDefaultProps);
|
|
73
|
-
}, [savedDefaultProps, setValue]);
|
|
74
|
-
if (!zodValidationResult.success) {
|
|
75
|
-
const defaultPropsValid = (0, zod_schema_type_1.zodSafeParse)(schema, savedDefaultProps);
|
|
76
|
-
if (!defaultPropsValid.success) {
|
|
77
|
-
return jsx_runtime_1.jsx(SchemaErrorMessages_1.InvalidDefaultProps, { zodValidationResult: zodValidationResult });
|
|
78
|
-
}
|
|
79
|
-
return (jsx_runtime_1.jsx(SchemaErrorMessages_1.InvalidSchema, { reset: reset, zodValidationResult: zodValidationResult }));
|
|
80
|
-
}
|
|
81
22
|
if (typeName !== 'object') {
|
|
82
23
|
return jsx_runtime_1.jsx(SchemaErrorMessages_1.TopLevelZodValue, { typeReceived: typeName });
|
|
83
24
|
}
|
|
84
|
-
return (jsx_runtime_1.jsx("div", { ref: scroll_to_default_props_path_1.defaultPropsEditorScrollableAreaRef, style: scrollable, className: is_menu_item_1.VERTICAL_SCROLLBAR_CLASSNAME, children: jsx_runtime_1.jsx(
|
|
25
|
+
return (jsx_runtime_1.jsx("div", { ref: scroll_to_default_props_path_1.defaultPropsEditorScrollableAreaRef, style: scrollable, className: is_menu_item_1.VERTICAL_SCROLLBAR_CLASSNAME, children: jsx_runtime_1.jsx(ZodObjectEditor_1.ZodObjectEditor, { discriminatedUnionReplacement: null, value: value, setValue: setValue, jsonPath: [], schema: schema, onRemove: null, mayPad: true }) }));
|
|
85
26
|
};
|
|
86
27
|
exports.SchemaEditor = SchemaEditor;
|
|
@@ -70,10 +70,9 @@ const InvalidDefaultProps = ({ zodValidationResult }) => {
|
|
|
70
70
|
] }));
|
|
71
71
|
};
|
|
72
72
|
exports.InvalidDefaultProps = InvalidDefaultProps;
|
|
73
|
-
const InvalidSchema = ({ zodValidationResult
|
|
73
|
+
const InvalidSchema = ({ zodValidationResult }) => {
|
|
74
74
|
return (jsx_runtime_1.jsxs("div", { style: errorContainer, children: [
|
|
75
|
-
jsx_runtime_1.jsx("div", { style: errorExplanation, children: "The data does not satisfy the schema:" }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx(ZodErrorMessages_1.ZodErrorMessages, { zodValidationResult: zodValidationResult, viewTab: "schema" }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx("div", { style: errorExplanation, children: "Fix the schema using the JSON editor." })
|
|
76
|
-
" that you have defined."] }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx(Button_1.Button, { onClick: reset, children: "Reset props" })
|
|
75
|
+
jsx_runtime_1.jsx("div", { style: errorExplanation, children: "The data does not satisfy the schema:" }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx(ZodErrorMessages_1.ZodErrorMessages, { zodValidationResult: zodValidationResult, viewTab: "schema" }), jsx_runtime_1.jsx(layout_1.Spacing, { y: 1, block: true }), jsx_runtime_1.jsx("div", { style: errorExplanation, children: "Fix the schema using the JSON editor." })
|
|
77
76
|
] }));
|
|
78
77
|
};
|
|
79
78
|
exports.InvalidSchema = InvalidSchema;
|
|
@@ -2,14 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import type { JSONPath } from './zod-types';
|
|
3
3
|
export declare const SchemaLabel: React.FC<{
|
|
4
4
|
readonly jsonPath: JSONPath;
|
|
5
|
-
readonly isDefaultValue: boolean;
|
|
6
|
-
readonly onReset: () => void;
|
|
7
|
-
readonly onSave: () => void;
|
|
8
5
|
readonly onRemove: null | (() => void);
|
|
9
|
-
readonly showSaveButton: boolean;
|
|
10
|
-
readonly saving: boolean;
|
|
11
6
|
readonly valid: boolean;
|
|
12
|
-
readonly saveDisabledByParent: boolean;
|
|
13
7
|
readonly suffix: string | null;
|
|
14
8
|
readonly handleClick: null | (() => void);
|
|
15
9
|
}>;
|
|
@@ -7,8 +7,6 @@ const colors_1 = require("../../../helpers/colors");
|
|
|
7
7
|
const layout_1 = require("../../layout");
|
|
8
8
|
const InlineRemoveButton_1 = require("../InlineRemoveButton");
|
|
9
9
|
const get_schema_label_1 = require("./get-schema-label");
|
|
10
|
-
const SchemaResetButton_1 = require("./SchemaResetButton");
|
|
11
|
-
const SchemaSaveButton_1 = require("./SchemaSaveButton");
|
|
12
10
|
const scroll_to_default_props_path_1 = require("./scroll-to-default-props-path");
|
|
13
11
|
const compactStyles = {
|
|
14
12
|
fontSize: 15,
|
|
@@ -19,9 +17,8 @@ const compactStyles = {
|
|
|
19
17
|
alignItems: 'center',
|
|
20
18
|
flex: 1,
|
|
21
19
|
};
|
|
22
|
-
const SchemaLabel = ({ jsonPath,
|
|
20
|
+
const SchemaLabel = ({ jsonPath, onRemove, valid, suffix, handleClick }) => {
|
|
23
21
|
const [clickableButtonHovered, setClickableButtonHovered] = (0, react_1.useState)(false);
|
|
24
|
-
const disableSave = saving || !valid || saveDisabledByParent;
|
|
25
22
|
const labelStyle = (0, react_1.useMemo)(() => {
|
|
26
23
|
return {
|
|
27
24
|
fontFamily: 'monospace',
|
|
@@ -43,6 +40,6 @@ const SchemaLabel = ({ jsonPath, isDefaultValue, onReset, onSave, showSaveButton
|
|
|
43
40
|
const labelContent = (jsx_runtime_1.jsxs("span", { style: labelStyle, children: [(0, get_schema_label_1.getSchemaLabel)(jsonPath), " ", suffix ? suffix : null] }));
|
|
44
41
|
return (jsx_runtime_1.jsxs("div", { style: compactStyles, className: scroll_to_default_props_path_1.DEFAULT_PROPS_PATH_CLASSNAME, "data-json-path": jsonPath.join('.'), children: [handleClick ? (
|
|
45
42
|
// Minus the padding that a button has (user agent padding-line-start)
|
|
46
|
-
jsx_runtime_1.jsx("button", { onPointerEnter: onClickablePointerEnter, onPointerLeave: onClickablePointerLeave, type: "button", onClick: handleClick, style: { border: 'none', padding: 0 }, children: labelContent })) : (labelContent), jsx_runtime_1.jsx(layout_1.Flex, {}),
|
|
43
|
+
jsx_runtime_1.jsx("button", { onPointerEnter: onClickablePointerEnter, onPointerLeave: onClickablePointerLeave, type: "button", onClick: handleClick, style: { border: 'none', padding: 0 }, children: labelContent })) : (labelContent), jsx_runtime_1.jsx(layout_1.Flex, {}), onRemove ? jsx_runtime_1.jsx(InlineRemoveButton_1.InlineRemoveButton, { onClick: onRemove }) : null] }));
|
|
47
44
|
};
|
|
48
45
|
exports.SchemaLabel = SchemaLabel;
|
|
@@ -3,7 +3,9 @@ import type { AnyZodSchema } from './zod-schema-type';
|
|
|
3
3
|
export declare const VERTICAL_GUIDE_HEIGHT = 24;
|
|
4
4
|
export declare const SchemaSeparationLine: React.FC;
|
|
5
5
|
export declare const SchemaArrayItemSeparationLine: React.FC<{
|
|
6
|
-
readonly onChange: (updater: (oldV: unknown[]) => unknown[],
|
|
6
|
+
readonly onChange: (updater: (oldV: unknown[]) => unknown[], options: {
|
|
7
|
+
shouldSave: boolean;
|
|
8
|
+
}) => void;
|
|
7
9
|
readonly index: number;
|
|
8
10
|
readonly schema: AnyZodSchema;
|
|
9
11
|
readonly showAddButton: boolean;
|
|
@@ -41,7 +41,7 @@ const SchemaArrayItemSeparationLine = ({ onChange, index, schema, isLast, showAd
|
|
|
41
41
|
(0, create_zod_values_1.createZodValues)(arrayElement, z, zodTypes),
|
|
42
42
|
...oldV.slice(index + 1),
|
|
43
43
|
];
|
|
44
|
-
},
|
|
44
|
+
}, { shouldSave: true });
|
|
45
45
|
}, [arrayElement, index, onChange, z, zodTypes]);
|
|
46
46
|
const dynamicAddButtonStyle = (0, react_1.useMemo)(() => {
|
|
47
47
|
return {
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import 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 ZodArrayEditor: 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
|
}>;
|
|
@@ -37,25 +37,20 @@ exports.ZodArrayEditor = void 0;
|
|
|
37
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const get_zod_if_possible_1 = require("../../get-zod-if-possible");
|
|
40
|
-
const create_zod_values_1 = require("./create-zod-values");
|
|
41
|
-
const deep_equal_1 = require("./deep-equal");
|
|
42
40
|
const Fieldset_1 = require("./Fieldset");
|
|
43
|
-
const local_state_1 = require("./local-state");
|
|
44
41
|
const SchemaLabel_1 = require("./SchemaLabel");
|
|
45
42
|
const SchemaSeparationLine_1 = require("./SchemaSeparationLine");
|
|
46
43
|
const SchemaVerticalGuide_1 = require("./SchemaVerticalGuide");
|
|
47
44
|
const zod_schema_type_1 = require("./zod-schema-type");
|
|
45
|
+
const zod_schema_type_2 = require("./zod-schema-type");
|
|
48
46
|
const ZodArrayItemEditor_1 = require("./ZodArrayItemEditor");
|
|
49
47
|
const ZodFieldValidation_1 = require("./ZodFieldValidation");
|
|
50
|
-
const ZodArrayEditor = ({ schema, jsonPath, setValue,
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
setValue,
|
|
55
|
-
savedValue: defaultValue,
|
|
56
|
-
});
|
|
48
|
+
const ZodArrayEditor = ({ schema, jsonPath, setValue, value, onRemove, mayPad }) => {
|
|
49
|
+
const onChange = (0, react_1.useCallback)((updater, { shouldSave }) => {
|
|
50
|
+
setValue(updater, { shouldSave });
|
|
51
|
+
}, [setValue]);
|
|
57
52
|
const [expanded, setExpanded] = (0, react_1.useState)(true);
|
|
58
|
-
const arrayElement = (0,
|
|
53
|
+
const arrayElement = (0, zod_schema_type_2.getArrayElement)(schema);
|
|
59
54
|
const suffix = (0, react_1.useMemo)(() => {
|
|
60
55
|
return expanded ? ' [' : ' [...] ';
|
|
61
56
|
}, [expanded]);
|
|
@@ -63,24 +58,18 @@ const ZodArrayEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSav
|
|
|
63
58
|
if (!z) {
|
|
64
59
|
throw new Error('expected zod');
|
|
65
60
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
return (0, deep_equal_1.deepEqual)(localValue.value, defaultValue);
|
|
69
|
-
}, [defaultValue, localValue]);
|
|
70
|
-
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [
|
|
61
|
+
const zodValidation = (0, react_1.useMemo)(() => (0, zod_schema_type_1.zodSafeParse)(schema, value), [schema, value]);
|
|
62
|
+
return (jsx_runtime_1.jsxs(Fieldset_1.Fieldset, { shouldPad: mayPad, children: [
|
|
71
63
|
jsx_runtime_1.jsx("div", { style: {
|
|
72
64
|
display: 'flex',
|
|
73
65
|
flexDirection: 'row',
|
|
74
|
-
}, children: jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
jsx_runtime_1.jsx(ZodArrayItemEditor_1.ZodArrayItemEditor, { onChange: onChange, value: child, elementSchema: arrayElement, index: i, jsonPath: jsonPath, defaultValue: (_a = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue[i]) !== 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: true }), jsx_runtime_1.jsx(SchemaSeparationLine_1.SchemaArrayItemSeparationLine, { schema: schema, index: i, onChange: onChange, isLast: i === localValue.value.length - 1, showAddButton: true })
|
|
82
|
-
] }, `${i}${localValue.keyStabilityRevision}`));
|
|
83
|
-
}), 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 })
|
|
66
|
+
}, children: jsx_runtime_1.jsx(SchemaLabel_1.SchemaLabel, { jsonPath: jsonPath, onRemove: onRemove, suffix: suffix, valid: zodValidation.success, handleClick: () => setExpanded(!expanded) }) }), expanded ? (jsx_runtime_1.jsxs(SchemaVerticalGuide_1.SchemaVerticalGuide, { isRoot: false, children: [value.map((child, i) => {
|
|
67
|
+
return (
|
|
68
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
69
|
+
jsx_runtime_1.jsxs(react_1.default.Fragment, { children: [
|
|
70
|
+
jsx_runtime_1.jsx(ZodArrayItemEditor_1.ZodArrayItemEditor, { onChange: onChange, value: child, elementSchema: arrayElement, index: i, jsonPath: jsonPath, mayPad: mayPad, mayRemove: true }), jsx_runtime_1.jsx(SchemaSeparationLine_1.SchemaArrayItemSeparationLine, { schema: schema, index: i, onChange: onChange, isLast: i === value.length - 1, showAddButton: true })
|
|
71
|
+
] }, i));
|
|
72
|
+
}), 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, zodValidation: zodValidation })
|
|
84
73
|
] }));
|
|
85
74
|
};
|
|
86
75
|
exports.ZodArrayEditor = ZodArrayEditor;
|