@remotion/studio 4.0.298 → 4.0.301

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,7 +0,0 @@
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 {};
@@ -1,57 +0,0 @@
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 changed = (0, react_1.useRef)(false);
12
- const [stack] = (0, react_1.useState)(() => {
13
- return new Error().stack;
14
- });
15
- const [hook] = (0, react_1.useState)(() => {
16
- return (0, VisualControls_1.makeHook)(stack);
17
- });
18
- (0, react_1.useEffect)(() => {
19
- if (!(0, remotion_1.getRemotionEnvironment)().isStudio) {
20
- return;
21
- }
22
- addHook(hook);
23
- }, [addHook, hook]);
24
- (0, react_1.useEffect)(() => {
25
- return () => {
26
- removeHook(hook);
27
- };
28
- }, [hook, removeHook]);
29
- (0, react_1.useEffect)(() => {
30
- if (changed.current) {
31
- updateHandles();
32
- changed.current = false;
33
- }
34
- }, [updateHandles]);
35
- const z = (0, get_zod_if_possible_1.useZodIfPossible)();
36
- return (0, react_1.useMemo)(() => ({
37
- visualControl(key, value, schema) {
38
- if (!(0, remotion_1.getRemotionEnvironment)().isStudio) {
39
- return value;
40
- }
41
- if (!z) {
42
- return value;
43
- }
44
- const { same, currentValue } = setControl(hook, key, {
45
- valueInCode: value,
46
- unsavedValue: value,
47
- schema: schema !== null && schema !== void 0 ? schema : (0, get_zod_schema_from_primitive_1.getZodSchemaFromPrimitive)(value, z),
48
- stack: new Error().stack,
49
- });
50
- if (!same) {
51
- changed.current = true;
52
- }
53
- return currentValue;
54
- },
55
- }), [hook, setControl, z]);
56
- };
57
- exports.useVisualControl = useVisualControl;
@@ -1,7 +0,0 @@
1
- import type { z } from 'zod';
2
- type VisualControl = <T>(key: string, value: T, schema?: z.ZodTypeAny) => T;
3
- type UseVisualControls = {
4
- visualControl: VisualControl;
5
- };
6
- export declare const useVisualControls: () => UseVisualControls;
7
- export {};
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useVisualControls = 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 useVisualControls = () => {
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 changedRef = (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 (changedRef.current) {
32
- updateHandles();
33
- changedRef.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 { changed, currentValue } = setControl(hook, key, {
46
- valueInCode: value,
47
- schema: schema !== null && schema !== void 0 ? schema : (0, get_zod_schema_from_primitive_1.getZodSchemaFromPrimitive)(value, z),
48
- stack: new Error().stack,
49
- });
50
- if (changed) {
51
- changedRef.current = true;
52
- }
53
- return currentValue;
54
- },
55
- }), [hook, setControl, handles, z]);
56
- };
57
- exports.useVisualControls = useVisualControls;