Skip to content

🎥 Make videos programmatically with React

reset

Jonny Burger673536c8bf2e
diff --git a/packages/studio/src/components/OptionsPanel.tsx b/packages/studio/src/components/OptionsPanel.tsx
index 4255fd684b..9f94adb033 100644
--- a/packages/studio/src/components/OptionsPanel.tsx
+++ b/packages/studio/src/components/OptionsPanel.tsx
@@ -15,7 +15,9 @@ import {VisualControlsTabActivatedContext} from '../visual-controls/VisualContro
import {DefaultPropsEditor} from './DefaultPropsEditor';
import {useZodIfPossible, useZodTypesIfPossible} from './get-zod-if-possible';
import {showNotification} from './Notifications/NotificationCenter';
+import {deepEqual} from './RenderModal/SchemaEditor/deep-equal';
import {extractEnumJsonPaths} from './RenderModal/SchemaEditor/extract-enum-json-paths';
+import {SchemaResetButton} from './RenderModal/SchemaEditor/SchemaResetButton';
import type {AnyZodSchema} from './RenderModal/SchemaEditor/zod-schema-type';
import type {UpdaterFunction} from './RenderModal/SchemaEditor/ZodSwitch';
import {RenderQueue} from './RenderQueue';
@@ -171,6 +173,10 @@ export const OptionsPanel: React.FC<{
const saveToFile = useCallback(
(updater: (old: Record<string, unknown>) => Record<string, unknown>) => {
+ if (readOnlyStudio) {
+ return;
+ }
+
if (
schema === 'no-zod' ||
schema === 'no-schema' ||
@@ -213,7 +219,7 @@ export const OptionsPanel: React.FC<{
showNotification(`Cannot update default props: ${err.message}`, 2000);
});
},
- [composition, currentDefaultProps, schema, z, zodTypes],
+ [composition, currentDefaultProps, readOnlyStudio, schema, z, zodTypes],
);
const compositionId = useMemo(() => {
@@ -224,6 +230,26 @@ export const OptionsPanel: React.FC<{
return composition?.defaultProps ?? {};
}, [composition?.defaultProps]);
+ const hasLocalModifications = useMemo(() => {
+ if (!readOnlyStudio || !composition || !composition.defaultProps) {
+ return false;
+ }
+
+ return !deepEqual(composition.defaultProps, currentDefaultProps);
+ }, [readOnlyStudio, composition, currentDefaultProps]);
+
+ const resetToOriginal = useCallback(() => {
+ if (!composition) {
+ return;
+ }
+
+ updateProps({
+ id: composition.id,
+ defaultProps: (composition.defaultProps ?? {}) as Record<string, unknown>,
+ newProps: (composition.defaultProps ?? {}) as Record<string, unknown>,
+ });
+ }, [composition, updateProps]);
+
const setDefaultProps: UpdaterFunction<Record<string, unknown>> = useCallback(
(updater, {shouldSave}) => {
updateProps({
@@ -257,6 +283,9 @@ export const OptionsPanel: React.FC<{
style={{justifyContent: 'space-between'}}
>
Props
+ {hasLocalModifications ? (
+ <SchemaResetButton onClick={resetToOriginal} />
+ ) : null}
</Tab>
{renderingAvailable ? (
<RendersTab
diff --git a/packages/studio/src/components/RenderModal/SchemaEditor/SchemaResetButton.tsx b/packages/studio/src/components/RenderModal/SchemaEditor/SchemaResetButton.tsx
new file mode 100644
index 0000000000..f5e21fea71
--- /dev/null
+++ b/packages/studio/src/components/RenderModal/SchemaEditor/SchemaResetButton.tsx
@@ -0,0 +1,25 @@
+import React, {useCallback} from 'react';
+import type {RenderInlineAction} from '../../InlineAction';
+import {InlineAction} from '../../InlineAction';
+
+const icon: React.CSSProperties = {
+ height: 14,
+ color: 'currentColor',
+};
+
+export const SchemaResetButton: React.FC<{
+ readonly onClick: () => void;
+}> = ({onClick}) => {
+ const renderAction: RenderInlineAction = useCallback((color) => {
+ return (
+ <svg style={icon} viewBox="0 0 512 512">
+ <path
+ fill={color}
+ d="M48.5 224H40c-13.3 0-24-10.7-24-24V72c0-9.7 5.8-18.5 14.8-22.2s19.3-1.7 26.2 5.2L98.6 96.6c87.6-86.5 228.7-86.2 315.8 1c87.5 87.5 87.5 229.3 0 316.8s-229.3 87.5-316.8 0c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0c62.5 62.5 163.8 62.5 226.3 0s62.5-163.8 0-226.3c-62.2-62.2-162.7-62.5-225.3-1L185 183c6.9 6.9 8.9 17.2 5.2 26.2s-12.5 14.8-22.2 14.8H48.5z"
+ />
+ </svg>
+ );
+ }, []);
+
+ return <InlineAction renderAction={renderAction} onClick={onClick} />;
+};