@remotion/studio 4.0.431 → 4.0.432

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 (37) hide show
  1. package/dist/Studio.d.ts +1 -0
  2. package/dist/Studio.js +4 -4
  3. package/dist/components/AssetSelectorItem.js +6 -8
  4. package/dist/components/NewComposition/DuplicateComposition.js +1 -4
  5. package/dist/components/RenderModal/SchemaEditor/SchemaLabel.js +1 -3
  6. package/dist/components/RenderModal/SchemaEditor/ZodArrayEditor.js +1 -3
  7. package/dist/components/RenderModal/SchemaEditor/ZodFieldValidation.js +1 -3
  8. package/dist/components/RenderModal/SchemaEditor/ZodTupleEditor.js +1 -3
  9. package/dist/components/RenderModal/WebRenderModal.d.ts +1 -1
  10. package/dist/components/RenderModal/WebRenderModal.js +55 -26
  11. package/dist/components/RenderModal/WebRenderModalAudio.d.ts +2 -0
  12. package/dist/components/RenderModal/WebRenderModalAudio.js +11 -5
  13. package/dist/components/RenderModal/WebRenderModalBasic.js +35 -35
  14. package/dist/components/RenderQueue/ClientRenderQueueProcessor.js +3 -3
  15. package/dist/components/RenderQueue/client-side-render-types.d.ts +1 -1
  16. package/dist/components/Timeline/TimelineExpandedSection.js +11 -147
  17. package/dist/components/Timeline/TimelineFieldRow.d.ts +8 -0
  18. package/dist/components/Timeline/TimelineFieldRow.js +78 -0
  19. package/dist/components/Timeline/TimelineListItem.js +6 -17
  20. package/dist/components/Timeline/TimelineSchemaField.d.ts +2 -1
  21. package/dist/components/Timeline/TimelineSchemaField.js +4 -6
  22. package/dist/components/Timeline/use-resolved-stack.d.ts +2 -0
  23. package/dist/components/Timeline/use-resolved-stack.js +54 -0
  24. package/dist/components/Timeline/use-sequence-props-subscription.d.ts +3 -0
  25. package/dist/components/Timeline/use-sequence-props-subscription.js +130 -0
  26. package/dist/error-overlay/react-overlay/utils/get-source-map.d.ts +5 -0
  27. package/dist/esm/{chunk-3msfwcwh.js → chunk-t28xqw5n.js} +1932 -1795
  28. package/dist/esm/internals.mjs +1932 -1795
  29. package/dist/esm/previewEntry.mjs +1915 -1777
  30. package/dist/esm/renderEntry.mjs +5 -2
  31. package/dist/helpers/get-timeline-sequence-layout.js +3 -3
  32. package/dist/helpers/timeline-layout.d.ts +2 -2
  33. package/dist/helpers/timeline-layout.js +2 -2
  34. package/dist/internals.d.ts +1 -0
  35. package/dist/previewEntry.js +1 -1
  36. package/dist/renderEntry.js +3 -3
  37. package/package.json +10 -10
@@ -3,12 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TimelineExpandedSection = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
- const remotion_1 = require("remotion");
7
- const client_id_1 = require("../../helpers/client-id");
8
6
  const colors_1 = require("../../helpers/colors");
9
7
  const timeline_layout_1 = require("../../helpers/timeline-layout");
10
- const call_api_1 = require("../call-api");
11
- const TimelineSchemaField_1 = require("./TimelineSchemaField");
8
+ const TimelineFieldRow_1 = require("./TimelineFieldRow");
12
9
  const expandedSectionBase = {
13
10
  color: 'white',
14
11
  fontFamily: 'Arial, Helvetica, sans-serif',
@@ -19,33 +16,10 @@ const expandedSectionBase = {
19
16
  paddingRight: 10,
20
17
  borderBottom: `1px solid ${colors_1.TIMELINE_TRACK_SEPARATOR}`,
21
18
  };
22
- const fieldRow = {
23
- display: 'flex',
24
- alignItems: 'center',
25
- gap: 8,
26
- };
27
- const fieldName = {
28
- fontSize: 12,
29
- };
30
- const fieldLabelRow = {
31
- flex: 1,
32
- display: 'flex',
33
- flexDirection: 'row',
34
- alignItems: 'center',
35
- gap: 6,
36
- };
37
- const TimelineFieldRow = ({ field, onSave, onDragValueChange, onDragEnd, propStatus }) => {
38
- var _a, _b;
39
- return (jsx_runtime_1.jsxs("div", { style: { ...fieldRow, height: field.rowHeight }, children: [
40
- jsx_runtime_1.jsx("div", { style: fieldLabelRow, children: jsx_runtime_1.jsx("span", { style: fieldName, children: (_a = field.description) !== null && _a !== void 0 ? _a : field.key }) }), jsx_runtime_1.jsx(TimelineSchemaField_1.TimelineFieldValue, { field: field, propStatus: propStatus, onSave: onSave, onDragValueChange: onDragValueChange, onDragEnd: onDragEnd, canUpdate: (_b = propStatus === null || propStatus === void 0 ? void 0 : propStatus.canUpdate) !== null && _b !== void 0 ? _b : false })
41
- ] }));
42
- };
43
19
  const TimelineExpandedSection = ({ sequence, originalLocation }) => {
44
20
  var _a;
45
- var _b, _c, _d, _e;
46
- const [propStatuses, setPropStatuses] = (0, react_1.useState)(null);
47
- const { previewServerState: state, subscribeToEvent } = (0, react_1.useContext)(client_id_1.StudioServerConnectionCtx);
48
- const clientId = state.type === 'connected' ? state.clientId : undefined;
21
+ var _b;
22
+ const overrideId = (_b = (_a = sequence.controls) === null || _a === void 0 ? void 0 : _a.overrideId) !== null && _b !== void 0 ? _b : sequence.id;
49
23
  const schemaFields = (0, react_1.useMemo)(() => (0, timeline_layout_1.getSchemaFields)(sequence.controls), [sequence.controls]);
50
24
  const validatedLocation = (0, react_1.useMemo)(() => {
51
25
  var _a;
@@ -60,126 +34,16 @@ const TimelineExpandedSection = ({ sequence, originalLocation }) => {
60
34
  column: (_a = originalLocation.column) !== null && _a !== void 0 ? _a : 0,
61
35
  };
62
36
  }, [originalLocation]);
63
- const locationSource = (_b = validatedLocation === null || validatedLocation === void 0 ? void 0 : validatedLocation.source) !== null && _b !== void 0 ? _b : null;
64
- const locationLine = (_c = validatedLocation === null || validatedLocation === void 0 ? void 0 : validatedLocation.line) !== null && _c !== void 0 ? _c : null;
65
- const locationColumn = (_d = validatedLocation === null || validatedLocation === void 0 ? void 0 : validatedLocation.column) !== null && _d !== void 0 ? _d : null;
66
- const schemaKeysString = (0, react_1.useMemo)(() => (schemaFields ? schemaFields.map((f) => f.key).join(',') : null), [schemaFields]);
67
- const currentLocationSource = (0, react_1.useRef)(locationSource);
68
- currentLocationSource.current = locationSource;
69
- const currentLocationLine = (0, react_1.useRef)(locationLine);
70
- currentLocationLine.current = locationLine;
71
- const currentLocationColumn = (0, react_1.useRef)(locationColumn);
72
- currentLocationColumn.current = locationColumn;
73
- (0, react_1.useEffect)(() => {
74
- if (!clientId ||
75
- !locationSource ||
76
- !locationLine ||
77
- locationColumn === null ||
78
- !schemaKeysString) {
79
- setPropStatuses(null);
80
- return;
81
- }
82
- const keys = schemaKeysString.split(',');
83
- (0, call_api_1.callApi)('/api/subscribe-to-sequence-props', {
84
- fileName: locationSource,
85
- line: locationLine,
86
- column: locationColumn,
87
- keys,
88
- clientId,
89
- })
90
- .then((result) => {
91
- if (currentLocationSource.current !== locationSource ||
92
- currentLocationLine.current !== locationLine ||
93
- currentLocationColumn.current !== locationColumn) {
94
- return;
95
- }
96
- if (result.canUpdate) {
97
- setPropStatuses(result.props);
98
- }
99
- else {
100
- setPropStatuses(null);
101
- }
102
- })
103
- .catch(() => {
104
- setPropStatuses(null);
105
- });
106
- return () => {
107
- (0, call_api_1.callApi)('/api/unsubscribe-from-sequence-props', {
108
- fileName: locationSource,
109
- line: locationLine,
110
- column: locationColumn,
111
- clientId,
112
- }).catch(() => {
113
- // Ignore unsubscribe errors
114
- });
115
- };
116
- }, [
117
- clientId,
118
- locationSource,
119
- locationLine,
120
- locationColumn,
121
- schemaKeysString,
122
- ]);
123
- (0, react_1.useEffect)(() => {
124
- if (!locationSource || !locationLine || locationColumn === null) {
125
- return;
126
- }
127
- const listener = (event) => {
128
- if (event.type !== 'sequence-props-updated') {
129
- return;
130
- }
131
- if (event.fileName !== currentLocationSource.current ||
132
- event.line !== currentLocationLine.current ||
133
- event.column !== currentLocationColumn.current) {
134
- return;
135
- }
136
- if (event.result.canUpdate) {
137
- setPropStatuses(event.result.props);
138
- }
139
- else {
140
- setPropStatuses(null);
141
- }
142
- };
143
- const unsub = subscribeToEvent('sequence-props-updated', listener);
144
- return () => {
145
- unsub();
146
- };
147
- }, [locationSource, locationLine, locationColumn, subscribeToEvent]);
148
37
  const expandedHeight = (0, react_1.useMemo)(() => (0, timeline_layout_1.getExpandedTrackHeight)(sequence.controls), [sequence.controls]);
149
- const { setOverride, clearOverrides } = (0, react_1.useContext)(remotion_1.Internals.SequenceControlOverrideContext);
150
- const onSave = (0, react_1.useCallback)((key, value) => {
151
- if (!propStatuses || !validatedLocation) {
152
- return Promise.reject(new Error('Cannot save'));
153
- }
154
- const status = propStatuses[key];
155
- if (!status || !status.canUpdate) {
156
- return Promise.reject(new Error('Cannot save'));
157
- }
158
- const field = schemaFields === null || schemaFields === void 0 ? void 0 : schemaFields.find((f) => f.key === key);
159
- const defaultValue = field && field.fieldSchema.default !== undefined
160
- ? JSON.stringify(field.fieldSchema.default)
161
- : null;
162
- return (0, call_api_1.callApi)('/api/save-sequence-props', {
163
- fileName: validatedLocation.source,
164
- line: validatedLocation.line,
165
- column: validatedLocation.column,
166
- key,
167
- value: JSON.stringify(value),
168
- enumPaths: [],
169
- defaultValue,
170
- }).then(() => undefined);
171
- }, [propStatuses, validatedLocation, schemaFields]);
172
- const overrideId = (_e = (_a = sequence.controls) === null || _a === void 0 ? void 0 : _a.overrideId) !== null && _e !== void 0 ? _e : sequence.id;
173
- const onDragValueChange = (0, react_1.useCallback)((key, value) => {
174
- setOverride(overrideId, key, value);
175
- }, [setOverride, overrideId]);
176
- const onDragEnd = (0, react_1.useCallback)(() => {
177
- clearOverrides(overrideId);
178
- }, [clearOverrides, overrideId]);
179
- return (jsx_runtime_1.jsx("div", { style: { ...expandedSectionBase, height: expandedHeight }, children: schemaFields
38
+ const style = (0, react_1.useMemo)(() => {
39
+ return {
40
+ ...expandedSectionBase,
41
+ height: expandedHeight,
42
+ };
43
+ }, [expandedHeight]);
44
+ return (jsx_runtime_1.jsx("div", { style: style, children: schemaFields
180
45
  ? schemaFields.map((field) => {
181
- var _a;
182
- return (jsx_runtime_1.jsx(TimelineFieldRow, { field: field, propStatus: (_a = propStatuses === null || propStatuses === void 0 ? void 0 : propStatuses[field.key]) !== null && _a !== void 0 ? _a : null, onSave: onSave, onDragValueChange: onDragValueChange, onDragEnd: onDragEnd }, field.key));
46
+ return (jsx_runtime_1.jsx(TimelineFieldRow_1.TimelineFieldRow, { field: field, overrideId: overrideId, validatedLocation: validatedLocation }, field.key));
183
47
  })
184
48
  : 'No schema' }));
185
49
  };
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { CodePosition } from '../../error-overlay/react-overlay/utils/get-source-map';
3
+ import type { SchemaFieldInfo } from '../../helpers/timeline-layout';
4
+ export declare const TimelineFieldRow: React.FC<{
5
+ readonly field: SchemaFieldInfo;
6
+ readonly overrideId: string;
7
+ readonly validatedLocation: CodePosition | null;
8
+ }>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimelineFieldRow = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const remotion_1 = require("remotion");
7
+ const call_api_1 = require("../call-api");
8
+ const TimelineSchemaField_1 = require("./TimelineSchemaField");
9
+ const fieldRow = {
10
+ display: 'flex',
11
+ alignItems: 'center',
12
+ gap: 8,
13
+ paddingLeft: 24,
14
+ };
15
+ const fieldName = {
16
+ fontSize: 12,
17
+ color: 'rgba(255, 255, 255, 0.8)',
18
+ };
19
+ const fieldLabelRow = {
20
+ flex: 1,
21
+ display: 'flex',
22
+ flexDirection: 'row',
23
+ alignItems: 'center',
24
+ gap: 6,
25
+ };
26
+ const TimelineFieldRow = ({ field, overrideId, validatedLocation }) => {
27
+ var _a, _b, _c, _d;
28
+ const { setDragOverrides, clearDragOverrides, dragOverrides, codeValues: allPropStatuses, } = (0, react_1.useContext)(remotion_1.Internals.VisualModeOverridesContext);
29
+ const propStatuses = ((_a = allPropStatuses[overrideId]) !== null && _a !== void 0 ? _a : null);
30
+ const propStatus = (_b = propStatuses === null || propStatuses === void 0 ? void 0 : propStatuses[field.key]) !== null && _b !== void 0 ? _b : null;
31
+ const dragOverrideValue = (0, react_1.useMemo)(() => {
32
+ var _a;
33
+ return ((_a = dragOverrides[overrideId]) !== null && _a !== void 0 ? _a : {})[field.key];
34
+ }, [dragOverrides, overrideId, field.key]);
35
+ const effectiveValue = remotion_1.Internals.getEffectiveVisualModeValue({
36
+ codeValue: propStatus,
37
+ runtimeValue: field.currentValue,
38
+ dragOverrideValue,
39
+ defaultValue: field.fieldSchema.default,
40
+ });
41
+ const onSave = (0, react_1.useCallback)((key, value) => {
42
+ if (!propStatuses || !validatedLocation) {
43
+ return Promise.reject(new Error('Cannot save'));
44
+ }
45
+ const status = propStatuses[key];
46
+ if (!status || !status.canUpdate) {
47
+ return Promise.reject(new Error('Cannot save'));
48
+ }
49
+ const defaultValue = field.fieldSchema.default !== undefined
50
+ ? JSON.stringify(field.fieldSchema.default)
51
+ : null;
52
+ return (0, call_api_1.callApi)('/api/save-sequence-props', {
53
+ fileName: validatedLocation.source,
54
+ line: validatedLocation.line,
55
+ column: validatedLocation.column,
56
+ key,
57
+ value: JSON.stringify(value),
58
+ enumPaths: [],
59
+ defaultValue,
60
+ }).then(() => undefined);
61
+ }, [propStatuses, validatedLocation, field.fieldSchema.default]);
62
+ const onDragValueChange = (0, react_1.useCallback)((key, value) => {
63
+ setDragOverrides(overrideId, key, value);
64
+ }, [setDragOverrides, overrideId]);
65
+ const onDragEnd = (0, react_1.useCallback)(() => {
66
+ clearDragOverrides(overrideId);
67
+ }, [clearDragOverrides, overrideId]);
68
+ const style = (0, react_1.useMemo)(() => {
69
+ return {
70
+ ...fieldRow,
71
+ height: field.rowHeight,
72
+ };
73
+ }, [field.rowHeight]);
74
+ return (jsx_runtime_1.jsxs("div", { style: style, children: [
75
+ jsx_runtime_1.jsx("div", { style: fieldLabelRow, children: jsx_runtime_1.jsx("span", { style: fieldName, children: (_c = field.description) !== null && _c !== void 0 ? _c : field.key }) }), jsx_runtime_1.jsx(TimelineSchemaField_1.TimelineFieldValue, { field: field, propStatus: propStatus, onSave: onSave, onDragValueChange: onDragValueChange, onDragEnd: onDragEnd, canUpdate: (_d = propStatus === null || propStatus === void 0 ? void 0 : propStatus.canUpdate) !== null && _d !== void 0 ? _d : false, effectiveValue: effectiveValue })
76
+ ] }));
77
+ };
78
+ exports.TimelineFieldRow = TimelineFieldRow;
@@ -11,7 +11,8 @@ const ExpandedTracksProvider_1 = require("../ExpandedTracksProvider");
11
11
  const TimelineExpandedSection_1 = require("./TimelineExpandedSection");
12
12
  const TimelineLayerEye_1 = require("./TimelineLayerEye");
13
13
  const TimelineStack_1 = require("./TimelineStack");
14
- const get_stack_1 = require("./TimelineStack/get-stack");
14
+ const use_resolved_stack_1 = require("./use-resolved-stack");
15
+ const use_sequence_props_subscription_1 = require("./use-sequence-props-subscription");
15
16
  const SPACING = 5;
16
17
  const space = {
17
18
  width: SPACING,
@@ -36,27 +37,15 @@ const arrowButton = {
36
37
  lineHeight: 1,
37
38
  };
38
39
  const TimelineListItem = ({ nestedDepth, sequence, isCompact }) => {
39
- var _a;
40
+ var _a, _b;
40
41
  const { previewServerState } = (0, react_1.useContext)(client_id_1.StudioServerConnectionCtx);
41
42
  const visualModeEnabled = Boolean(process.env.EXPERIMENTAL_VISUAL_MODE_ENABLED) &&
42
43
  previewServerState.type === 'connected';
43
44
  const { hidden, setHidden } = (0, react_1.useContext)(remotion_1.Internals.SequenceVisibilityToggleContext);
44
45
  const { expandedTracks, toggleTrack } = (0, react_1.useContext)(ExpandedTracksProvider_1.ExpandedTracksContext);
45
- const [originalLocation, setOriginalLocation] = (0, react_1.useState)(null);
46
- (0, react_1.useEffect)(() => {
47
- if (!sequence.stack) {
48
- return;
49
- }
50
- (0, get_stack_1.getOriginalLocationFromStack)(sequence.stack, 'sequence')
51
- .then((frame) => {
52
- setOriginalLocation(frame);
53
- })
54
- .catch((err) => {
55
- // eslint-disable-next-line no-console
56
- console.error('Could not get original location of Sequence', err);
57
- });
58
- }, [sequence.stack]);
59
- const isExpanded = visualModeEnabled && ((_a = expandedTracks[sequence.id]) !== null && _a !== void 0 ? _a : false);
46
+ const originalLocation = (0, use_resolved_stack_1.useResolvedStack)((_a = sequence.stack) !== null && _a !== void 0 ? _a : null);
47
+ (0, use_sequence_props_subscription_1.useSequencePropsSubscription)(sequence, originalLocation);
48
+ const isExpanded = visualModeEnabled && ((_b = expandedTracks[sequence.id]) !== null && _b !== void 0 ? _b : false);
60
49
  const onToggleExpand = (0, react_1.useCallback)(() => {
61
50
  toggleTrack(sequence.id);
62
51
  }, [sequence.id, toggleTrack]);
@@ -1,5 +1,5 @@
1
- import type { CanUpdateSequencePropStatus } from '@remotion/studio-shared';
2
1
  import React from 'react';
2
+ import type { CanUpdateSequencePropStatus } from 'remotion';
3
3
  import type { SchemaFieldInfo } from '../../helpers/timeline-layout';
4
4
  export declare const TimelineFieldValue: React.FC<{
5
5
  readonly field: SchemaFieldInfo;
@@ -8,6 +8,7 @@ export declare const TimelineFieldValue: React.FC<{
8
8
  readonly onDragEnd: () => void;
9
9
  readonly canUpdate: boolean;
10
10
  readonly propStatus: CanUpdateSequencePropStatus | null;
11
+ readonly effectiveValue: unknown;
11
12
  }>;
12
13
  export declare const TimelineFieldSavingSpinner: React.FC<{
13
14
  readonly saving: boolean;
@@ -73,8 +73,7 @@ const TimelineBooleanField = ({ field, codeValue, canUpdate, onSave }) => {
73
73
  }, [canUpdate, onSave, field.key, checked]);
74
74
  return (jsx_runtime_1.jsx("div", { style: checkboxContainer, children: jsx_runtime_1.jsx(Checkbox_1.Checkbox, { checked: checked, onChange: onChange, name: field.key, disabled: !canUpdate }) }));
75
75
  };
76
- const TimelineFieldValue = ({ field, onSave, onDragValueChange, onDragEnd, propStatus, canUpdate }) => {
77
- var _a, _b;
76
+ const TimelineFieldValue = ({ field, onSave, onDragValueChange, onDragEnd, propStatus, canUpdate, effectiveValue, }) => {
78
77
  const wrapperStyle = canUpdate === null || canUpdate === false
79
78
  ? notEditableBackground
80
79
  : undefined;
@@ -87,14 +86,13 @@ const TimelineFieldValue = ({ field, onSave, onDragValueChange, onDragEnd, propS
87
86
  if (propStatus === null) {
88
87
  return (jsx_runtime_1.jsx("span", { style: { ...notEditableBackground }, children: jsx_runtime_1.jsx("span", { style: unsupportedLabel, children: "error" }) }));
89
88
  }
90
- const effectiveCodeValue = (_b = (_a = propStatus.codeValue) !== null && _a !== void 0 ? _a : field.currentValue) !== null && _b !== void 0 ? _b : field.fieldSchema.default;
91
89
  if (field.typeName === 'number') {
92
- return (jsx_runtime_1.jsx("span", { style: wrapperStyle, children: jsx_runtime_1.jsx(TimelineNumberField, { field: field, codeValue: effectiveCodeValue, canUpdate: canUpdate, onSave: onSave, onDragValueChange: onDragValueChange, onDragEnd: onDragEnd }) }));
90
+ return (jsx_runtime_1.jsx("span", { style: wrapperStyle, children: jsx_runtime_1.jsx(TimelineNumberField, { field: field, codeValue: effectiveValue, canUpdate: canUpdate, onSave: onSave, onDragValueChange: onDragValueChange, onDragEnd: onDragEnd }) }));
93
91
  }
94
92
  if (field.typeName === 'boolean') {
95
- return (jsx_runtime_1.jsx("span", { style: wrapperStyle, children: jsx_runtime_1.jsx(TimelineBooleanField, { field: field, codeValue: effectiveCodeValue, canUpdate: canUpdate, onSave: onSave }) }));
93
+ return (jsx_runtime_1.jsx("span", { style: wrapperStyle, children: jsx_runtime_1.jsx(TimelineBooleanField, { field: field, codeValue: effectiveValue, canUpdate: canUpdate, onSave: onSave }) }));
96
94
  }
97
- return (jsx_runtime_1.jsx("span", { style: { ...unsupportedLabel, fontStyle: 'normal' }, children: String(effectiveCodeValue) }));
95
+ return (jsx_runtime_1.jsx("span", { style: { ...unsupportedLabel, fontStyle: 'normal' }, children: String(effectiveValue) }));
98
96
  };
99
97
  exports.TimelineFieldValue = TimelineFieldValue;
100
98
  const TimelineFieldSavingSpinner = ({ saving }) => {
@@ -0,0 +1,2 @@
1
+ import type { ResolvedStackLocation } from 'remotion';
2
+ export declare const useResolvedStack: (stack: string | null) => ResolvedStackLocation | null;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useResolvedStack = void 0;
4
+ const react_1 = require("react");
5
+ const remotion_1 = require("remotion");
6
+ const get_stack_1 = require("./TimelineStack/get-stack");
7
+ const resolvedCache = new Map();
8
+ const inFlight = new Set();
9
+ const subscribers = new Map();
10
+ const useResolvedStack = (stack) => {
11
+ const updateResolvedStackTrace = (0, react_1.useContext)(remotion_1.Internals.SequenceStackTracesUpdateContext);
12
+ const [value, setValue] = (0, react_1.useState)(() => {
13
+ var _a;
14
+ if (!stack) {
15
+ return null;
16
+ }
17
+ return (_a = resolvedCache.get(stack)) !== null && _a !== void 0 ? _a : null;
18
+ });
19
+ (0, react_1.useEffect)(() => {
20
+ if (!stack) {
21
+ return;
22
+ }
23
+ if (resolvedCache.has(stack)) {
24
+ setValue(resolvedCache.get(stack));
25
+ return;
26
+ }
27
+ if (!subscribers.has(stack)) {
28
+ subscribers.set(stack, new Set());
29
+ }
30
+ const subs = subscribers.get(stack);
31
+ subs.add(setValue);
32
+ if (!inFlight.has(stack)) {
33
+ inFlight.add(stack);
34
+ (0, get_stack_1.getOriginalLocationFromStack)(stack, 'sequence')
35
+ .then((frame) => {
36
+ resolvedCache.set(stack, frame);
37
+ updateResolvedStackTrace(stack, frame);
38
+ subs.forEach((fn) => fn(frame));
39
+ })
40
+ .catch((err) => {
41
+ // eslint-disable-next-line no-console
42
+ console.error('Could not get original location of Sequence', err);
43
+ })
44
+ .finally(() => {
45
+ inFlight.delete(stack);
46
+ });
47
+ }
48
+ return () => {
49
+ subs.delete(setValue);
50
+ };
51
+ }, [stack, updateResolvedStackTrace]);
52
+ return value;
53
+ };
54
+ exports.useResolvedStack = useResolvedStack;
@@ -0,0 +1,3 @@
1
+ import type { TSequence } from 'remotion';
2
+ import type { OriginalPosition } from '../../error-overlay/react-overlay/utils/get-source-map';
3
+ export declare const useSequencePropsSubscription: (sequence: TSequence, originalLocation: OriginalPosition | null) => void;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSequencePropsSubscription = void 0;
4
+ const react_1 = require("react");
5
+ const remotion_1 = require("remotion");
6
+ const client_id_1 = require("../../helpers/client-id");
7
+ const timeline_layout_1 = require("../../helpers/timeline-layout");
8
+ const call_api_1 = require("../call-api");
9
+ const useSequencePropsSubscription = (sequence, originalLocation) => {
10
+ var _a;
11
+ var _b, _c, _d, _e;
12
+ const { setCodeValues } = (0, react_1.useContext)(remotion_1.Internals.VisualModeOverridesContext);
13
+ const overrideId = (_b = (_a = sequence.controls) === null || _a === void 0 ? void 0 : _a.overrideId) !== null && _b !== void 0 ? _b : null;
14
+ const setPropStatusesForSequence = (0, react_1.useCallback)((statuses) => {
15
+ if (!overrideId) {
16
+ return;
17
+ }
18
+ setCodeValues(overrideId, statuses);
19
+ }, [overrideId, setCodeValues]);
20
+ const { previewServerState: state, subscribeToEvent } = (0, react_1.useContext)(client_id_1.StudioServerConnectionCtx);
21
+ const clientId = state.type === 'connected' ? state.clientId : undefined;
22
+ const schemaFields = (0, react_1.useMemo)(() => (0, timeline_layout_1.getSchemaFields)(sequence.controls), [sequence.controls]);
23
+ const schemaKeysString = (0, react_1.useMemo)(() => (schemaFields ? schemaFields.map((f) => f.key).join(',') : null), [schemaFields]);
24
+ const validatedLocation = (0, react_1.useMemo)(() => {
25
+ var _a;
26
+ if (!originalLocation ||
27
+ !originalLocation.source ||
28
+ !originalLocation.line) {
29
+ return null;
30
+ }
31
+ return {
32
+ source: originalLocation.source,
33
+ line: originalLocation.line,
34
+ column: (_a = originalLocation.column) !== null && _a !== void 0 ? _a : 0,
35
+ };
36
+ }, [originalLocation]);
37
+ const locationSource = (_c = validatedLocation === null || validatedLocation === void 0 ? void 0 : validatedLocation.source) !== null && _c !== void 0 ? _c : null;
38
+ const locationLine = (_d = validatedLocation === null || validatedLocation === void 0 ? void 0 : validatedLocation.line) !== null && _d !== void 0 ? _d : null;
39
+ const locationColumn = (_e = validatedLocation === null || validatedLocation === void 0 ? void 0 : validatedLocation.column) !== null && _e !== void 0 ? _e : null;
40
+ const currentLocationSource = (0, react_1.useRef)(locationSource);
41
+ currentLocationSource.current = locationSource;
42
+ const currentLocationLine = (0, react_1.useRef)(locationLine);
43
+ currentLocationLine.current = locationLine;
44
+ const currentLocationColumn = (0, react_1.useRef)(locationColumn);
45
+ currentLocationColumn.current = locationColumn;
46
+ (0, react_1.useEffect)(() => {
47
+ if (!clientId ||
48
+ !locationSource ||
49
+ !locationLine ||
50
+ locationColumn === null ||
51
+ !schemaKeysString) {
52
+ setPropStatusesForSequence(null);
53
+ return;
54
+ }
55
+ const keys = schemaKeysString.split(',');
56
+ (0, call_api_1.callApi)('/api/subscribe-to-sequence-props', {
57
+ fileName: locationSource,
58
+ line: locationLine,
59
+ column: locationColumn,
60
+ keys,
61
+ clientId,
62
+ })
63
+ .then((result) => {
64
+ if (currentLocationSource.current !== locationSource ||
65
+ currentLocationLine.current !== locationLine ||
66
+ currentLocationColumn.current !== locationColumn) {
67
+ return;
68
+ }
69
+ if (result.canUpdate) {
70
+ setPropStatusesForSequence(result.props);
71
+ }
72
+ else {
73
+ setPropStatusesForSequence(null);
74
+ }
75
+ })
76
+ .catch(() => {
77
+ setPropStatusesForSequence(null);
78
+ });
79
+ return () => {
80
+ setPropStatusesForSequence(null);
81
+ (0, call_api_1.callApi)('/api/unsubscribe-from-sequence-props', {
82
+ fileName: locationSource,
83
+ line: locationLine,
84
+ column: locationColumn,
85
+ clientId,
86
+ }).catch(() => {
87
+ // Ignore unsubscribe errors
88
+ });
89
+ };
90
+ }, [
91
+ clientId,
92
+ locationSource,
93
+ locationLine,
94
+ locationColumn,
95
+ schemaKeysString,
96
+ setPropStatusesForSequence,
97
+ ]);
98
+ (0, react_1.useEffect)(() => {
99
+ if (!locationSource || !locationLine || locationColumn === null) {
100
+ return;
101
+ }
102
+ const listener = (event) => {
103
+ if (event.type !== 'sequence-props-updated') {
104
+ return;
105
+ }
106
+ if (event.fileName !== currentLocationSource.current ||
107
+ event.line !== currentLocationLine.current ||
108
+ event.column !== currentLocationColumn.current) {
109
+ return;
110
+ }
111
+ if (event.result.canUpdate) {
112
+ setPropStatusesForSequence(event.result.props);
113
+ }
114
+ else {
115
+ setPropStatusesForSequence(null);
116
+ }
117
+ };
118
+ const unsub = subscribeToEvent('sequence-props-updated', listener);
119
+ return () => {
120
+ unsub();
121
+ };
122
+ }, [
123
+ locationSource,
124
+ locationLine,
125
+ locationColumn,
126
+ subscribeToEvent,
127
+ setPropStatusesForSequence,
128
+ ]);
129
+ };
130
+ exports.useSequencePropsSubscription = useSequencePropsSubscription;
@@ -4,5 +4,10 @@ export type OriginalPosition = {
4
4
  column: number | null;
5
5
  source: string | null;
6
6
  };
7
+ export type CodePosition = {
8
+ line: number;
9
+ column: number;
10
+ source: string;
11
+ };
7
12
  export declare const getOriginalPosition: (source_map: SourceMapConsumer, line: number, column: number) => OriginalPosition;
8
13
  export declare function getSourceMap(fileUri: string, fileContents: string): Promise<SourceMapConsumer | null>;