@remotion/studio 4.0.290 → 4.0.291

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > @remotion/studio@4.0.290 make /Users/jonathanburger/remotion/packages/studio
3
+ > @remotion/studio@4.0.291 make /Users/jonathanburger/remotion/packages/studio
4
4
  > tsc -d && bun --env-file=../.env.bundle bundle.ts
5
5
 
6
- [88.33ms] Generated.
6
+ [90.47ms] Generated.
@@ -0,0 +1,2 @@
1
+ import type { ZodType } from '../components/get-zod-if-possible';
2
+ export declare const getZodSchemaFromPrimitive: (value: unknown, z: ZodType) => import("zod").ZodString | import("zod").ZodNumber;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getZodSchemaFromPrimitive = void 0;
4
+ const getZodSchemaFromPrimitive = (value, z) => {
5
+ if (typeof value === 'string') {
6
+ return z.string();
7
+ }
8
+ if (typeof value === 'number') {
9
+ return z.number();
10
+ }
11
+ throw new Error('Unknown primitive type');
12
+ };
13
+ exports.getZodSchemaFromPrimitive = getZodSchemaFromPrimitive;
@@ -0,0 +1,7 @@
1
+ import type { z } from 'zod';
2
+ type VisualControl = <T>(key: string, value: T, schema?: z.ZodTypeAny) => T;
3
+ type UseVisualControl = {
4
+ visualControl: VisualControl;
5
+ };
6
+ export declare const useVisualControl: () => UseVisualControl;
7
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useVisualControl = void 0;
4
+ const react_1 = require("react");
5
+ const remotion_1 = require("remotion");
6
+ const get_zod_if_possible_1 = require("../components/get-zod-if-possible");
7
+ const VisualControls_1 = require("../visual-controls/VisualControls");
8
+ const get_zod_schema_from_primitive_1 = require("./get-zod-schema-from-primitive");
9
+ const useVisualControl = () => {
10
+ const { addHook, removeHook, setControl, updateHandles } = (0, react_1.useContext)(VisualControls_1.SetVisualControlsContext);
11
+ const { handles } = (0, react_1.useContext)(VisualControls_1.VisualControlsContext);
12
+ const changed = (0, react_1.useRef)(false);
13
+ const [stack] = (0, react_1.useState)(() => {
14
+ return new Error().stack;
15
+ });
16
+ const [hook] = (0, react_1.useState)(() => {
17
+ return (0, VisualControls_1.makeHook)(stack);
18
+ });
19
+ (0, react_1.useEffect)(() => {
20
+ if (!(0, remotion_1.getRemotionEnvironment)().isStudio) {
21
+ return;
22
+ }
23
+ addHook(hook);
24
+ }, [addHook, hook]);
25
+ (0, react_1.useEffect)(() => {
26
+ return () => {
27
+ removeHook(hook);
28
+ };
29
+ }, [hook, removeHook]);
30
+ (0, react_1.useEffect)(() => {
31
+ if (changed.current) {
32
+ updateHandles();
33
+ changed.current = false;
34
+ }
35
+ }, [updateHandles]);
36
+ const z = (0, get_zod_if_possible_1.useZodIfPossible)();
37
+ return (0, react_1.useMemo)(() => ({
38
+ visualControl(key, value, schema) {
39
+ if (!(0, remotion_1.getRemotionEnvironment)().isStudio) {
40
+ return value;
41
+ }
42
+ if (!z) {
43
+ return value;
44
+ }
45
+ const { same, currentValue } = setControl(hook, key, {
46
+ valueInCode: value,
47
+ unsavedValue: value,
48
+ schema: schema !== null && schema !== void 0 ? schema : (0, get_zod_schema_from_primitive_1.getZodSchemaFromPrimitive)(value, z),
49
+ stack: new Error().stack,
50
+ });
51
+ if (!same) {
52
+ changed.current = true;
53
+ }
54
+ return currentValue;
55
+ },
56
+ }), [handles, hook, setControl, z]);
57
+ };
58
+ exports.useVisualControl = useVisualControl;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import type { z } from 'zod';
3
+ import type { UpdaterFunction } from './ZodSwitch';
4
+ import type { JSONPath } from './zod-types';
5
+ export declare const ZodMatrixEditor: React.FC<{
6
+ readonly schema: z.ZodTypeAny;
7
+ readonly jsonPath: JSONPath;
8
+ readonly value: unknown[];
9
+ readonly defaultValue: unknown[];
10
+ readonly setValue: UpdaterFunction<unknown[]>;
11
+ readonly onSave: UpdaterFunction<unknown[]>;
12
+ readonly showSaveButton: boolean;
13
+ readonly onRemove: null | (() => void);
14
+ readonly saving: boolean;
15
+ readonly saveDisabledByParent: boolean;
16
+ readonly mayPad: boolean;
17
+ }>;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ZodMatrixEditor = void 0;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const get_zod_if_possible_1 = require("../../get-zod-if-possible");
40
+ const Fieldset_1 = require("./Fieldset");
41
+ const SchemaLabel_1 = require("./SchemaLabel");
42
+ const SchemaSeparationLine_1 = require("./SchemaSeparationLine");
43
+ const SchemaVerticalGuide_1 = require("./SchemaVerticalGuide");
44
+ const ZodArrayItemEditor_1 = require("./ZodArrayItemEditor");
45
+ const ZodFieldValidation_1 = require("./ZodFieldValidation");
46
+ const create_zod_values_1 = require("./create-zod-values");
47
+ const deep_equal_1 = require("./deep-equal");
48
+ const local_state_1 = require("./local-state");
49
+ const rowStyle = {
50
+ display: 'flex',
51
+ flexDirection: 'row',
52
+ width: '100%',
53
+ };
54
+ const ZodMatrixEditor = ({ schema, jsonPath, setValue, defaultValue, value, onSave, showSaveButton, onRemove, saving, saveDisabledByParent, mayPad, }) => {
55
+ const { localValue, onChange, RevisionContextProvider, reset } = (0, local_state_1.useLocalState)({
56
+ unsavedValue: value,
57
+ schema,
58
+ setValue,
59
+ savedValue: defaultValue,
60
+ });
61
+ const [expanded, setExpanded] = (0, react_1.useState)(true);
62
+ const def = schema._def;
63
+ const suffix = (0, react_1.useMemo)(() => {
64
+ return expanded ? ' [' : ' [...] ';
65
+ }, [expanded]);
66
+ const z = (0, get_zod_if_possible_1.useZodIfPossible)();
67
+ if (!z) {
68
+ throw new Error('expected zod');
69
+ }
70
+ const zodTypes = (0, get_zod_if_possible_1.useZodTypesIfPossible)();
71
+ const isDefaultValue = (0, react_1.useMemo)(() => {
72
+ return (0, deep_equal_1.deepEqual)(localValue.value, defaultValue);
73
+ }, [defaultValue, localValue]);
74
+ const dimensions = Math.sqrt(localValue.value.length);
75
+ if (!Number.isInteger(dimensions)) {
76
+ throw new Error('Invalid matrix');
77
+ }
78
+ const chunkedItems = (0, react_1.useMemo)(() => {
79
+ return localValue.value.reduce((acc, item, index) => {
80
+ const chunkIndex = Math.floor(index / dimensions);
81
+ acc[chunkIndex] = acc[chunkIndex] || [];
82
+ acc[chunkIndex].push(item);
83
+ return acc;
84
+ }, []);
85
+ }, [localValue.value, dimensions]);
86
+ return ((0, jsx_runtime_1.jsxs)(Fieldset_1.Fieldset, { shouldPad: mayPad, success: localValue.zodValidation.success, children: [(0, jsx_runtime_1.jsx)("div", { style: {
87
+ display: 'flex',
88
+ flexDirection: 'row',
89
+ }, children: (0, jsx_runtime_1.jsx)(SchemaLabel_1.SchemaLabel, { onReset: reset, isDefaultValue: isDefaultValue, jsonPath: jsonPath, onRemove: onRemove, suffix: suffix, onSave: () => {
90
+ onSave(() => localValue.value, false, false);
91
+ }, saveDisabledByParent: saveDisabledByParent, saving: saving, showSaveButton: showSaveButton, valid: localValue.zodValidation.success, handleClick: () => setExpanded(!expanded) }) }), expanded ? ((0, jsx_runtime_1.jsx)(RevisionContextProvider, { children: (0, jsx_runtime_1.jsxs)(SchemaVerticalGuide_1.SchemaVerticalGuide, { isRoot: false, children: [chunkedItems.map((row, rowIndex) => {
92
+ return ((0, jsx_runtime_1.jsx)(react_1.default.Fragment
93
+ // eslint-disable-next-line react/no-array-index-key
94
+ , { children: (0, jsx_runtime_1.jsx)("div", { style: rowStyle, children: row.map((item, _index) => {
95
+ var _a;
96
+ const actualIndex = rowIndex * dimensions + _index;
97
+ return ((0, jsx_runtime_1.jsx)("div", { style: { flex: 1 }, children: (0, 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}`));
98
+ }) }) }, `${rowIndex}${localValue.keyStabilityRevision}`));
99
+ }), value.length === 0 ? ((0, jsx_runtime_1.jsx)(SchemaSeparationLine_1.SchemaArrayItemSeparationLine, { schema: schema, index: 0, onChange: onChange, isLast: true, showAddButton: true })) : null] }) })) : null, (0, jsx_runtime_1.jsx)(ZodFieldValidation_1.ZodFieldValidation, { path: jsonPath, localValue: localValue })] }));
100
+ };
101
+ exports.ZodMatrixEditor = ZodMatrixEditor;
@@ -0,0 +1,3 @@
1
+ export declare const ClickableFileName: ({ stack }: {
2
+ readonly stack: string;
3
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClickableFileName = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const open_in_editor_1 = require("../../helpers/open-in-editor");
7
+ const source_attribution_1 = require("../Timeline/TimelineStack/source-attribution");
8
+ const get_original_stack_trace_1 = require("./get-original-stack-trace");
9
+ const label = {
10
+ fontSize: 13,
11
+ };
12
+ const ClickableFileName = ({ stack }) => {
13
+ const originalFileName = (0, get_original_stack_trace_1.useOriginalFileName)(stack);
14
+ const [titleHovered, setTitleHovered] = (0, react_1.useState)(false);
15
+ const hoverEffect = titleHovered && originalFileName;
16
+ const onTitlePointerEnter = (0, react_1.useCallback)(() => {
17
+ setTitleHovered(true);
18
+ }, []);
19
+ const onTitlePointerLeave = (0, react_1.useCallback)(() => {
20
+ setTitleHovered(false);
21
+ }, []);
22
+ const style = (0, react_1.useMemo)(() => {
23
+ return {
24
+ ...label,
25
+ cursor: originalFileName ? 'pointer' : undefined,
26
+ borderBottom: hoverEffect ? '1px solid #fff' : 'none',
27
+ };
28
+ }, [originalFileName, hoverEffect]);
29
+ const onClick = (0, react_1.useCallback)(async () => {
30
+ if (!originalFileName) {
31
+ return;
32
+ }
33
+ await (0, open_in_editor_1.openOriginalPositionInEditor)(originalFileName);
34
+ }, [originalFileName]);
35
+ return ((0, jsx_runtime_1.jsx)("span", { style: style, onClick: onClick, onPointerEnter: onTitlePointerEnter, onPointerLeave: onTitlePointerLeave, children: originalFileName
36
+ ? (0, source_attribution_1.getOriginalSourceAttribution)(originalFileName)
37
+ : 'Loading...' }));
38
+ };
39
+ exports.ClickableFileName = ClickableFileName;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { VisualControlHook } from '../../visual-controls/VisualControls';
3
+ import { type VisualControlValue } from '../../visual-controls/VisualControls';
4
+ export declare const VisualControlHandle: React.FC<{
5
+ readonly value: VisualControlValue;
6
+ readonly keyName: string;
7
+ readonly hook: VisualControlHook;
8
+ }>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VisualControlHandle = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const VisualControls_1 = require("../../visual-controls/VisualControls");
7
+ const get_current_edited_value_1 = require("../../visual-controls/get-current-edited-value");
8
+ const ZodSwitch_1 = require("../RenderModal/SchemaEditor/ZodSwitch");
9
+ const local_state_1 = require("../RenderModal/SchemaEditor/local-state");
10
+ const get_zod_if_possible_1 = require("../get-zod-if-possible");
11
+ const container = {
12
+ marginBottom: 10,
13
+ };
14
+ const VisualControlHandle = ({ value, keyName, hook }) => {
15
+ const z = (0, get_zod_if_possible_1.useZodIfPossible)();
16
+ if (!z) {
17
+ throw new Error('expected zod');
18
+ }
19
+ const state = (0, react_1.useContext)(VisualControls_1.VisualControlsContext);
20
+ const { updateValue } = (0, react_1.useContext)(VisualControls_1.SetVisualControlsContext);
21
+ const currentValue = (0, get_current_edited_value_1.getVisualControlEditedValue)({
22
+ handles: state.handles,
23
+ hook,
24
+ key: keyName,
25
+ });
26
+ const { localValue, RevisionContextProvider, onChange } = (0, local_state_1.useLocalState)({
27
+ schema: value.schema,
28
+ setValue: (updater) => updateValue(hook, keyName, updater(currentValue)),
29
+ unsavedValue: currentValue,
30
+ savedValue: value.valueInCode,
31
+ });
32
+ return ((0, jsx_runtime_1.jsx)("div", { style: container, children: (0, jsx_runtime_1.jsx)(RevisionContextProvider, { children: (0, jsx_runtime_1.jsx)(ZodSwitch_1.ZodSwitch, { mayPad: true, schema: value.schema, showSaveButton: true, saving: false, saveDisabledByParent: false, onSave: () => undefined, jsonPath: [keyName], value: localValue.value, defaultValue: value.valueInCode, setValue: onChange, onRemove: null }) }) }));
33
+ };
34
+ exports.VisualControlHandle = VisualControlHandle;
@@ -0,0 +1 @@
1
+ export declare const VisualControlsContent: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VisualControlsContent = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const VisualControls_1 = require("../../visual-controls/VisualControls");
7
+ const layout_1 = require("../layout");
8
+ const is_menu_item_1 = require("../Menu/is-menu-item");
9
+ const ClickableFileName_1 = require("./ClickableFileName");
10
+ const VisualControlHandle_1 = require("./VisualControlHandle");
11
+ const Control = ({ hook }) => {
12
+ const { handles } = (0, react_1.useContext)(VisualControls_1.VisualControlsContext);
13
+ const handle = handles[hook.id];
14
+ if (!handle) {
15
+ return null;
16
+ }
17
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(ClickableFileName_1.ClickableFileName, { stack: hook.stack }), (0, jsx_runtime_1.jsx)(layout_1.Spacing, { block: true, y: 1 }), Object.entries(handle).map(([key, value]) => {
18
+ return ((0, jsx_runtime_1.jsx)(VisualControlHandle_1.VisualControlHandle, { keyName: key, value: value, hook: hook }, key));
19
+ })] }, hook.id));
20
+ };
21
+ const container = {
22
+ padding: 12,
23
+ overflowY: 'auto',
24
+ };
25
+ const VisualControlsContent = () => {
26
+ const { hooks: controls } = (0, react_1.useContext)(VisualControls_1.VisualControlsContext);
27
+ return ((0, jsx_runtime_1.jsx)("div", { style: container, className: is_menu_item_1.VERTICAL_SCROLLBAR_CLASSNAME, children: controls.map((hook) => ((0, jsx_runtime_1.jsx)(Control, { hook: hook }, hook.id))) }));
28
+ };
29
+ exports.VisualControlsContent = VisualControlsContent;
@@ -0,0 +1,2 @@
1
+ import type { OriginalPosition } from '../../error-overlay/react-overlay/utils/get-source-map';
2
+ export declare const useOriginalFileName: (stack: string) => OriginalPosition | null;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useOriginalFileName = void 0;
4
+ const react_1 = require("react");
5
+ const get_stack_1 = require("../Timeline/TimelineStack/get-stack");
6
+ const useOriginalFileName = (stack) => {
7
+ const [originalFileName, setOriginalFileName] = (0, react_1.useState)(null);
8
+ (0, react_1.useEffect)(() => {
9
+ if (!stack) {
10
+ return;
11
+ }
12
+ (0, get_stack_1.getOriginalLocationFromStack)(stack, 'visual-control')
13
+ .then((frame) => {
14
+ setOriginalFileName(frame);
15
+ })
16
+ .catch((err) => {
17
+ // eslint-disable-next-line no-console
18
+ console.error('Could not get original location of Sequence', err);
19
+ });
20
+ }, [stack]);
21
+ return originalFileName;
22
+ };
23
+ exports.useOriginalFileName = useOriginalFileName;
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import type { ZodTypeAny } from 'zod';
3
+ export type VisualControlValue = {
4
+ valueInCode: unknown;
5
+ unsavedValue: unknown;
6
+ schema: ZodTypeAny;
7
+ stack: string;
8
+ };
9
+ export type VisualControlHook = {
10
+ id: number;
11
+ stack: string;
12
+ };
13
+ type Handle = Record<string, VisualControlValue>;
14
+ export type Handles = Record<number, Handle>;
15
+ export type VisualControlsContextType = {
16
+ hooks: VisualControlHook[];
17
+ handles: Handles;
18
+ };
19
+ export declare const VisualControlsTabActivatedContext: React.Context<boolean>;
20
+ export type SetVisualControlsContextType = {
21
+ addHook: (hook: VisualControlHook) => void;
22
+ removeHook: (hook: VisualControlHook) => void;
23
+ setControl: (hook: VisualControlHook, key: string, value: VisualControlValue) => {
24
+ same: boolean;
25
+ currentValue: unknown;
26
+ };
27
+ updateHandles: () => void;
28
+ updateValue: (hook: VisualControlHook, key: string, value: unknown) => void;
29
+ };
30
+ export declare const makeHook: (stack: string) => VisualControlHook;
31
+ export declare const VisualControlsContext: React.Context<VisualControlsContextType>;
32
+ export declare const SetVisualControlsContext: React.Context<SetVisualControlsContextType>;
33
+ export declare const VisualControlsProvider: React.FC<{
34
+ readonly children: React.ReactNode;
35
+ }>;
36
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VisualControlsProvider = exports.SetVisualControlsContext = exports.VisualControlsContext = exports.makeHook = exports.VisualControlsTabActivatedContext = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const get_current_edited_value_1 = require("./get-current-edited-value");
7
+ exports.VisualControlsTabActivatedContext = (0, react_1.createContext)(false);
8
+ const makeHook = (stack) => {
9
+ return { id: Math.random(), stack };
10
+ };
11
+ exports.makeHook = makeHook;
12
+ exports.VisualControlsContext = (0, react_1.createContext)({
13
+ hooks: [],
14
+ handles: {},
15
+ });
16
+ exports.SetVisualControlsContext = (0, react_1.createContext)({
17
+ addHook: () => {
18
+ throw new Error('addControl is not implemented');
19
+ },
20
+ removeHook: () => {
21
+ throw new Error('removeControl is not implemented');
22
+ },
23
+ setControl: () => {
24
+ throw new Error('addControl is not implemented');
25
+ },
26
+ updateHandles: () => {
27
+ throw new Error('updateHandles is not implemented');
28
+ },
29
+ updateValue: () => {
30
+ throw new Error('updateValue is not implemented');
31
+ },
32
+ });
33
+ const VisualControlsProvider = ({ children }) => {
34
+ const [hooks, setHooks] = (0, react_1.useState)([]);
35
+ const imperativeHandles = (0, react_1.useRef)({});
36
+ const [handles, setHandles] = (0, react_1.useState)({});
37
+ const [tabActivated, setTabActivated] = (0, react_1.useState)(false);
38
+ const addHook = (0, react_1.useCallback)((hook) => {
39
+ setHooks((prev) => {
40
+ if (prev.find((c) => c.id === hook.id)) {
41
+ return prev;
42
+ }
43
+ return [...prev, hook];
44
+ });
45
+ setTabActivated(true);
46
+ }, [setHooks]);
47
+ const removeHook = (0, react_1.useCallback)((hook) => {
48
+ setHooks((prev) => prev.filter((c) => c !== hook));
49
+ }, [setHooks]);
50
+ const state = (0, react_1.useMemo)(() => {
51
+ return {
52
+ hooks,
53
+ handles,
54
+ };
55
+ }, [hooks, handles]);
56
+ const setControl = (0, react_1.useCallback)((hook, key, value) => {
57
+ var _a, _b, _c, _d, _e, _f;
58
+ const currentSaved = (_c = (_b = (_a = imperativeHandles.current) === null || _a === void 0 ? void 0 : _a[hook.id]) === null || _b === void 0 ? void 0 : _b[key]) === null || _c === void 0 ? void 0 : _c.valueInCode;
59
+ const currentUnsaved = (_f = (_e = (_d = imperativeHandles.current) === null || _d === void 0 ? void 0 : _d[hook.id]) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.unsavedValue;
60
+ if (currentSaved === value.valueInCode) {
61
+ return {
62
+ same: true,
63
+ currentValue: (0, get_current_edited_value_1.getVisualControlEditedValue)({
64
+ hook,
65
+ key,
66
+ handles: imperativeHandles.current,
67
+ }),
68
+ };
69
+ }
70
+ imperativeHandles.current = {
71
+ ...imperativeHandles.current,
72
+ [hook.id]: {
73
+ ...imperativeHandles.current[hook.id],
74
+ [key]: {
75
+ ...value,
76
+ unsavedValue: currentUnsaved !== null && currentUnsaved !== void 0 ? currentUnsaved : value.valueInCode,
77
+ },
78
+ },
79
+ };
80
+ return {
81
+ same: false,
82
+ currentValue: (0, get_current_edited_value_1.getVisualControlEditedValue)({
83
+ hook,
84
+ key,
85
+ handles: imperativeHandles.current,
86
+ }),
87
+ };
88
+ }, []);
89
+ const updateHandles = (0, react_1.useCallback)(() => {
90
+ setHandles(() => {
91
+ return imperativeHandles.current;
92
+ });
93
+ }, []);
94
+ const updateValue = (0, react_1.useCallback)((hook, key, value) => {
95
+ imperativeHandles.current = {
96
+ ...imperativeHandles.current,
97
+ [hook.id]: {
98
+ ...imperativeHandles.current[hook.id],
99
+ [key]: {
100
+ ...imperativeHandles.current[hook.id][key],
101
+ unsavedValue: value,
102
+ },
103
+ },
104
+ };
105
+ updateHandles();
106
+ }, [updateHandles]);
107
+ const setState = (0, react_1.useMemo)(() => {
108
+ return {
109
+ addHook,
110
+ removeHook,
111
+ setControl,
112
+ updateHandles,
113
+ updateValue,
114
+ };
115
+ }, [addHook, removeHook, setControl, updateHandles, updateValue]);
116
+ return ((0, jsx_runtime_1.jsx)(exports.VisualControlsTabActivatedContext.Provider, { value: tabActivated, children: (0, jsx_runtime_1.jsx)(exports.VisualControlsContext.Provider, { value: state, children: (0, jsx_runtime_1.jsx)(exports.SetVisualControlsContext.Provider, { value: setState, children: children }) }) }));
117
+ };
118
+ exports.VisualControlsProvider = VisualControlsProvider;
@@ -0,0 +1,6 @@
1
+ import type { Handles, VisualControlHook } from './VisualControls';
2
+ export declare const getVisualControlEditedValue: ({ handles, hook, key, }: {
3
+ handles: Handles;
4
+ hook: VisualControlHook;
5
+ key: string;
6
+ }) => unknown;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVisualControlEditedValue = void 0;
4
+ const getVisualControlEditedValue = ({ handles, hook, key, }) => {
5
+ var _a, _b, _c;
6
+ // TODO: What if z.null()
7
+ return (_c = (_b = (_a = handles === null || handles === void 0 ? void 0 : handles[hook.id]) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.unsavedValue) !== null && _c !== void 0 ? _c : null;
8
+ };
9
+ exports.getVisualControlEditedValue = getVisualControlEditedValue;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/studio"
4
4
  },
5
5
  "name": "@remotion/studio",
6
- "version": "4.0.290",
6
+ "version": "4.0.291",
7
7
  "description": "APIs for interacting with the Remotion Studio",
8
8
  "main": "dist",
9
9
  "sideEffects": false,
@@ -23,20 +23,20 @@
23
23
  "source-map": "0.7.3",
24
24
  "open": "^8.4.2",
25
25
  "zod": "3.22.3",
26
- "@remotion/player": "4.0.290",
27
- "remotion": "4.0.290",
28
- "@remotion/media-utils": "4.0.290",
29
- "@remotion/media-parser": "4.0.290",
30
- "@remotion/studio-shared": "4.0.290",
31
- "@remotion/renderer": "4.0.290",
32
- "@remotion/zod-types": "4.0.290"
26
+ "remotion": "4.0.291",
27
+ "@remotion/media-utils": "4.0.291",
28
+ "@remotion/player": "4.0.291",
29
+ "@remotion/media-parser": "4.0.291",
30
+ "@remotion/renderer": "4.0.291",
31
+ "@remotion/studio-shared": "4.0.291",
32
+ "@remotion/zod-types": "4.0.291"
33
33
  },
34
34
  "devDependencies": {
35
35
  "react": "19.0.0",
36
36
  "react-dom": "19.0.0",
37
37
  "@types/semver": "^7.3.4",
38
38
  "eslint": "9.19.0",
39
- "@remotion/eslint-config-internal": "4.0.290"
39
+ "@remotion/eslint-config-internal": "4.0.291"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"