@remotion/studio-server 4.0.484 → 4.0.486
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/codemods/duplicate-composition.js +8 -0
- package/dist/codemods/recast-mods.js +246 -5
- package/dist/codemods/split-jsx-sequence.d.ts +14 -0
- package/dist/codemods/split-jsx-sequence.js +345 -0
- package/dist/codemods/update-sequence-props/update-sequence-props.d.ts +3 -1
- package/dist/codemods/update-sequence-props/update-sequence-props.js +406 -9
- package/dist/helpers/import-agnostic-node-path.js +30 -4
- package/dist/helpers/resolve-composition-component.d.ts +1 -0
- package/dist/helpers/resolve-composition-component.js +206 -9
- package/dist/preview-server/api-routes.js +2 -0
- package/dist/preview-server/routes/add-effect-keyframe.js +2 -2
- package/dist/preview-server/routes/add-effect.js +56 -53
- package/dist/preview-server/routes/add-keyframes.js +2 -2
- package/dist/preview-server/routes/add-sequence-keyframe.js +2 -2
- package/dist/preview-server/routes/apply-codemod.js +123 -101
- package/dist/preview-server/routes/apply-visual-control-change.js +83 -80
- package/dist/preview-server/routes/can-update-sequence-props.d.ts +13 -1
- package/dist/preview-server/routes/can-update-sequence-props.js +101 -7
- package/dist/preview-server/routes/delete-effect.js +83 -80
- package/dist/preview-server/routes/delete-jsx-node.js +74 -71
- package/dist/preview-server/routes/delete-keyframes.js +2 -2
- package/dist/preview-server/routes/duplicate-effect.js +77 -74
- package/dist/preview-server/routes/duplicate-jsx-node.js +53 -50
- package/dist/preview-server/routes/insert-element.js +2 -2
- package/dist/preview-server/routes/insert-jsx-element.js +53 -4
- package/dist/preview-server/routes/move-keyframes.js +2 -2
- package/dist/preview-server/routes/paste-effects.js +59 -56
- package/dist/preview-server/routes/reorder-effect.js +55 -52
- package/dist/preview-server/routes/reorder-sequence.js +55 -52
- package/dist/preview-server/routes/save-effect-props.js +2 -2
- package/dist/preview-server/routes/save-sequence-props.d.ts +3 -1
- package/dist/preview-server/routes/save-sequence-props.js +208 -24
- package/dist/preview-server/routes/source-file-write-queue.d.ts +1 -0
- package/dist/preview-server/routes/source-file-write-queue.js +11 -0
- package/dist/preview-server/routes/split-jsx-sequence.d.ts +3 -0
- package/dist/preview-server/routes/split-jsx-sequence.js +66 -0
- package/dist/preview-server/routes/update-default-props.js +58 -55
- package/dist/preview-server/routes/update-effect-keyframe-settings.js +2 -2
- package/dist/preview-server/routes/update-sequence-keyframe-settings.js +2 -2
- package/dist/preview-server/undo-stack.d.ts +7 -1
- package/package.json +6 -6
|
@@ -14,6 +14,7 @@ const file_watcher_1 = require("../../file-watcher");
|
|
|
14
14
|
const project_info_1 = require("../project-info");
|
|
15
15
|
const undo_stack_1 = require("../undo-stack");
|
|
16
16
|
const can_update_default_props_1 = require("./can-update-default-props");
|
|
17
|
+
const source_file_write_queue_1 = require("./source-file-write-queue");
|
|
17
18
|
const formatNewCompositionFile = (componentName) => {
|
|
18
19
|
return (0, duplicate_composition_1.formatOutput)(`import React from 'react';
|
|
19
20
|
|
|
@@ -46,6 +47,17 @@ const getCodemodUndoDescription = (codemod) => {
|
|
|
46
47
|
entryType: codemod.type,
|
|
47
48
|
};
|
|
48
49
|
}
|
|
50
|
+
if (codemod.type === 'move-composition-to-folder') {
|
|
51
|
+
const destination = codemod.folderName === null
|
|
52
|
+
? 'to root'
|
|
53
|
+
: `into folder "${codemod.parentName ? `${codemod.parentName}/` : ''}${codemod.folderName}"`;
|
|
54
|
+
const label = `composition "${codemod.idToMove}" ${destination}`;
|
|
55
|
+
return {
|
|
56
|
+
undoMessage: `↩️ Move of ${label}`,
|
|
57
|
+
redoMessage: `↪️ Move of ${label}`,
|
|
58
|
+
entryType: codemod.type,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
49
61
|
if (codemod.type === 'new-composition') {
|
|
50
62
|
return {
|
|
51
63
|
undoMessage: `↩️ Creation of composition "${codemod.newId}"`,
|
|
@@ -61,6 +73,14 @@ const getCodemodUndoDescription = (codemod) => {
|
|
|
61
73
|
entryType: codemod.type,
|
|
62
74
|
};
|
|
63
75
|
}
|
|
76
|
+
if (codemod.type === 'new-folder') {
|
|
77
|
+
const label = `folder "${codemod.parentName ? `${codemod.parentName}/` : ''}${codemod.folderName}"`;
|
|
78
|
+
return {
|
|
79
|
+
undoMessage: `↩️ Creation of ${label}`,
|
|
80
|
+
redoMessage: `↪️ Creation of ${label}`,
|
|
81
|
+
entryType: codemod.type,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
64
84
|
if (codemod.type === 'rename-folder') {
|
|
65
85
|
const oldName = `${codemod.parentName ? `${codemod.parentName}/` : ''}${codemod.folderName}`;
|
|
66
86
|
const newName = `${codemod.parentName ? `${codemod.parentName}/` : ''}${codemod.newName}`;
|
|
@@ -77,110 +97,112 @@ const getCodemodUndoDescription = (codemod) => {
|
|
|
77
97
|
entryType: 'visual-control',
|
|
78
98
|
};
|
|
79
99
|
};
|
|
80
|
-
const applyCodemodHandler =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
(0, can_update_default_props_1.checkIfTypeScriptFile)(filePath);
|
|
91
|
-
const newCompositionComponentFilePath = codemod.type === 'new-composition'
|
|
92
|
-
? node_path_1.default.join(node_path_1.default.dirname(filePath), `${codemod.componentName}.tsx`)
|
|
93
|
-
: null;
|
|
94
|
-
if (codemod.type === 'new-composition' &&
|
|
95
|
-
newCompositionComponentFilePath &&
|
|
96
|
-
(0, node_fs_1.existsSync)(newCompositionComponentFilePath)) {
|
|
97
|
-
throw new Error(`Cannot create ${node_path_1.default.relative(remotionRoot, newCompositionComponentFilePath)} because it already exists`);
|
|
98
|
-
}
|
|
99
|
-
const input = (0, node_fs_1.readFileSync)(filePath, 'utf-8');
|
|
100
|
-
const formatted = await (0, apply_codemod_to_file_1.applyCodemodToFile)({
|
|
101
|
-
filePath,
|
|
102
|
-
codeMod: codemod,
|
|
103
|
-
});
|
|
104
|
-
const diff = (0, simple_diff_1.simpleDiff)({
|
|
105
|
-
oldLines: input.split('\n'),
|
|
106
|
-
newLines: formatted.split('\n'),
|
|
107
|
-
});
|
|
108
|
-
if (!dryRun) {
|
|
109
|
-
const { entryType, undoMessage, redoMessage } = getCodemodUndoDescription(codemod);
|
|
110
|
-
const snapshots = [
|
|
111
|
-
{
|
|
112
|
-
filePath,
|
|
113
|
-
oldContents: input,
|
|
114
|
-
newContents: null,
|
|
115
|
-
logLine: (_a = symbolicatedStack === null || symbolicatedStack === void 0 ? void 0 : symbolicatedStack.originalLineNumber) !== null && _a !== void 0 ? _a : 1,
|
|
116
|
-
},
|
|
117
|
-
];
|
|
118
|
-
let componentFilePath = null;
|
|
119
|
-
let componentFileContents = null;
|
|
120
|
-
if (codemod.type === 'new-composition') {
|
|
121
|
-
componentFilePath = newCompositionComponentFilePath;
|
|
122
|
-
if (componentFilePath === null) {
|
|
123
|
-
throw new Error('Could not determine the new component file path');
|
|
124
|
-
}
|
|
125
|
-
componentFileContents = await formatNewCompositionFile(codemod.componentName);
|
|
126
|
-
snapshots.push({
|
|
127
|
-
filePath: componentFilePath,
|
|
128
|
-
oldContents: null,
|
|
129
|
-
newContents: componentFileContents,
|
|
130
|
-
logLine: 1,
|
|
131
|
-
});
|
|
132
|
-
(0, undo_stack_1.pushTransactionToUndoStack)({
|
|
133
|
-
snapshots,
|
|
134
|
-
logLevel,
|
|
135
|
-
remotionRoot,
|
|
136
|
-
description: {
|
|
137
|
-
undoMessage,
|
|
138
|
-
redoMessage,
|
|
139
|
-
},
|
|
140
|
-
entryType,
|
|
141
|
-
suppressHmrOnFileRestore: false,
|
|
142
|
-
});
|
|
100
|
+
const applyCodemodHandler = ({ input: { codemod, dryRun, symbolicatedStack }, logLevel, remotionRoot, entryPoint, }) => {
|
|
101
|
+
return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
try {
|
|
104
|
+
const time = Date.now();
|
|
105
|
+
const filePath = symbolicatedStack
|
|
106
|
+
? (0, apply_codemod_to_file_1.resolveFilePathFromSymbolicatedStack)(remotionRoot, symbolicatedStack)
|
|
107
|
+
: (await (0, project_info_1.getProjectInfo)(remotionRoot, entryPoint)).rootFile;
|
|
108
|
+
if (!filePath) {
|
|
109
|
+
throw new Error('Cannot find file for composition in project');
|
|
143
110
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
description: {
|
|
153
|
-
undoMessage,
|
|
154
|
-
redoMessage,
|
|
155
|
-
},
|
|
156
|
-
entryType,
|
|
157
|
-
suppressHmrOnFileRestore: false,
|
|
158
|
-
});
|
|
111
|
+
(0, can_update_default_props_1.checkIfTypeScriptFile)(filePath);
|
|
112
|
+
const newCompositionComponentFilePath = codemod.type === 'new-composition'
|
|
113
|
+
? node_path_1.default.join(node_path_1.default.dirname(filePath), `${codemod.componentName}.tsx`)
|
|
114
|
+
: null;
|
|
115
|
+
if (codemod.type === 'new-composition' &&
|
|
116
|
+
newCompositionComponentFilePath &&
|
|
117
|
+
(0, node_fs_1.existsSync)(newCompositionComponentFilePath)) {
|
|
118
|
+
throw new Error(`Cannot create ${node_path_1.default.relative(remotionRoot, newCompositionComponentFilePath)} because it already exists`);
|
|
159
119
|
}
|
|
160
|
-
(0,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
120
|
+
const input = (0, node_fs_1.readFileSync)(filePath, 'utf-8');
|
|
121
|
+
const formatted = await (0, apply_codemod_to_file_1.applyCodemodToFile)({
|
|
122
|
+
filePath,
|
|
123
|
+
codeMod: codemod,
|
|
124
|
+
});
|
|
125
|
+
const diff = (0, simple_diff_1.simpleDiff)({
|
|
126
|
+
oldLines: input.split('\n'),
|
|
127
|
+
newLines: formatted.split('\n'),
|
|
128
|
+
});
|
|
129
|
+
if (!dryRun) {
|
|
130
|
+
const { entryType, undoMessage, redoMessage } = getCodemodUndoDescription(codemod);
|
|
131
|
+
const snapshots = [
|
|
132
|
+
{
|
|
133
|
+
filePath,
|
|
134
|
+
oldContents: input,
|
|
135
|
+
newContents: null,
|
|
136
|
+
logLine: (_a = symbolicatedStack === null || symbolicatedStack === void 0 ? void 0 : symbolicatedStack.originalLineNumber) !== null && _a !== void 0 ? _a : 1,
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
let componentFilePath = null;
|
|
140
|
+
let componentFileContents = null;
|
|
141
|
+
if (codemod.type === 'new-composition') {
|
|
142
|
+
componentFilePath = newCompositionComponentFilePath;
|
|
143
|
+
if (componentFilePath === null) {
|
|
144
|
+
throw new Error('Could not determine the new component file path');
|
|
145
|
+
}
|
|
146
|
+
componentFileContents = await formatNewCompositionFile(codemod.componentName);
|
|
147
|
+
snapshots.push({
|
|
148
|
+
filePath: componentFilePath,
|
|
149
|
+
oldContents: null,
|
|
150
|
+
newContents: componentFileContents,
|
|
151
|
+
logLine: 1,
|
|
152
|
+
});
|
|
153
|
+
(0, undo_stack_1.pushTransactionToUndoStack)({
|
|
154
|
+
snapshots,
|
|
155
|
+
logLevel,
|
|
156
|
+
remotionRoot,
|
|
157
|
+
description: {
|
|
158
|
+
undoMessage,
|
|
159
|
+
redoMessage,
|
|
160
|
+
},
|
|
161
|
+
entryType,
|
|
162
|
+
suppressHmrOnFileRestore: false,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
(0, undo_stack_1.pushToUndoStack)({
|
|
167
|
+
filePath,
|
|
168
|
+
oldContents: input,
|
|
169
|
+
newContents: null,
|
|
170
|
+
logLevel,
|
|
171
|
+
remotionRoot,
|
|
172
|
+
logLine: (_b = symbolicatedStack === null || symbolicatedStack === void 0 ? void 0 : symbolicatedStack.originalLineNumber) !== null && _b !== void 0 ? _b : 1,
|
|
173
|
+
description: {
|
|
174
|
+
undoMessage,
|
|
175
|
+
redoMessage,
|
|
176
|
+
},
|
|
177
|
+
entryType,
|
|
178
|
+
suppressHmrOnFileRestore: false,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
(0, undo_stack_1.suppressUndoStackInvalidation)(filePath);
|
|
182
|
+
if (componentFilePath) {
|
|
183
|
+
(0, undo_stack_1.suppressUndoStackInvalidation)(componentFilePath);
|
|
184
|
+
}
|
|
185
|
+
(0, file_watcher_1.writeFileAndNotifyFileWatchers)(filePath, formatted, undefined);
|
|
186
|
+
if (componentFilePath && componentFileContents !== null) {
|
|
187
|
+
(0, file_watcher_1.writeFileAndNotifyFileWatchers)(componentFilePath, componentFileContents, undefined);
|
|
188
|
+
}
|
|
189
|
+
const end = Date.now() - time;
|
|
190
|
+
const relativePath = node_path_1.default.relative(remotionRoot, filePath);
|
|
191
|
+
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, renderer_1.RenderInternals.chalk.blue(`Edited ${relativePath} in ${end}ms`));
|
|
192
|
+
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
167
193
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
return {
|
|
195
|
+
success: true,
|
|
196
|
+
diff,
|
|
197
|
+
};
|
|
172
198
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
reason: err.message,
|
|
182
|
-
stack: err.stack,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
return {
|
|
201
|
+
success: false,
|
|
202
|
+
reason: err.message,
|
|
203
|
+
stack: err.stack,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
});
|
|
185
207
|
};
|
|
186
208
|
exports.applyCodemodHandler = applyCodemodHandler;
|
|
@@ -46,6 +46,7 @@ const live_events_1 = require("../live-events");
|
|
|
46
46
|
const undo_stack_1 = require("../undo-stack");
|
|
47
47
|
const watch_ignore_next_change_1 = require("../watch-ignore-next-change");
|
|
48
48
|
const log_update_1 = require("./log-updates/log-update");
|
|
49
|
+
const source_file_write_queue_1 = require("./source-file-write-queue");
|
|
49
50
|
const getVisualControlChangeLine = (file, changeId) => {
|
|
50
51
|
let line = 1;
|
|
51
52
|
recast.types.visit(file.program, {
|
|
@@ -66,89 +67,91 @@ const getVisualControlChangeLine = (file, changeId) => {
|
|
|
66
67
|
});
|
|
67
68
|
return line;
|
|
68
69
|
};
|
|
69
|
-
const applyVisualControlHandler =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
70
|
+
const applyVisualControlHandler = ({ input: { fileName, changes }, remotionRoot, logLevel }) => {
|
|
71
|
+
return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
|
|
72
|
+
renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[apply-visual-control] Received request for ${fileName} with ${changes.length} changes`);
|
|
73
|
+
const { absolutePath } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
74
|
+
remotionRoot,
|
|
75
|
+
fileName,
|
|
76
|
+
action: 'apply visual control change to',
|
|
77
|
+
});
|
|
78
|
+
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
79
|
+
const ast = (0, parse_ast_1.parseAst)(fileContents);
|
|
80
|
+
const logLine = changes.length > 0 ? getVisualControlChangeLine(ast, changes[0].id) : 1;
|
|
81
|
+
const { newAst, changesMade } = (0, recast_mods_1.applyCodemod)({
|
|
82
|
+
file: ast,
|
|
83
|
+
codeMod: {
|
|
84
|
+
type: 'apply-visual-control',
|
|
85
|
+
changes,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
if (changesMade.length === 0) {
|
|
89
|
+
throw new Error('No changes were made to the file');
|
|
90
|
+
}
|
|
91
|
+
let output = (0, parse_ast_1.serializeAst)(newAst);
|
|
92
|
+
let formatted = false;
|
|
93
|
+
try {
|
|
94
|
+
const prettier = await Promise.resolve().then(() => __importStar(require('prettier')));
|
|
95
|
+
const { format, resolveConfig, resolveConfigFile } = prettier;
|
|
96
|
+
const configFilePath = await resolveConfigFile();
|
|
97
|
+
if (configFilePath) {
|
|
98
|
+
const prettierConfig = await resolveConfig(configFilePath);
|
|
99
|
+
if (prettierConfig) {
|
|
100
|
+
output = await format(output, {
|
|
101
|
+
...prettierConfig,
|
|
102
|
+
filepath: 'test.tsx',
|
|
103
|
+
plugins: [],
|
|
104
|
+
endOfLine: 'auto',
|
|
105
|
+
});
|
|
106
|
+
formatted = true;
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
suppressHmrOnFileRestore: true,
|
|
124
|
-
});
|
|
125
|
-
(0, undo_stack_1.suppressUndoStackInvalidation)(absolutePath);
|
|
126
|
-
(0, watch_ignore_next_change_1.suppressBundlerUpdateForFile)(absolutePath);
|
|
127
|
-
(0, file_watcher_1.writeFileAndNotifyFileWatchers)(absolutePath, output, undefined);
|
|
128
|
-
(0, live_events_1.waitForLiveEventsListener)().then((listener) => {
|
|
129
|
-
listener.sendEventToClient({
|
|
130
|
-
type: 'visual-control-values-changed',
|
|
131
|
-
values: changes.map((change) => ({
|
|
132
|
-
id: change.id,
|
|
133
|
-
value: change.newValueIsUndefined
|
|
134
|
-
? null
|
|
135
|
-
: JSON.parse(change.newValueSerialized),
|
|
136
|
-
isUndefined: change.newValueIsUndefined,
|
|
137
|
-
})),
|
|
110
|
+
catch (_a) {
|
|
111
|
+
// Prettier not available, use unformatted output
|
|
112
|
+
}
|
|
113
|
+
(0, undo_stack_1.pushToUndoStack)({
|
|
114
|
+
filePath: absolutePath,
|
|
115
|
+
oldContents: fileContents,
|
|
116
|
+
newContents: null,
|
|
117
|
+
logLevel,
|
|
118
|
+
remotionRoot,
|
|
119
|
+
logLine,
|
|
120
|
+
description: {
|
|
121
|
+
undoMessage: '↩️ Visual control change',
|
|
122
|
+
redoMessage: '↪️ Visual control change',
|
|
123
|
+
},
|
|
124
|
+
entryType: 'visual-control',
|
|
125
|
+
suppressHmrOnFileRestore: true,
|
|
138
126
|
});
|
|
127
|
+
(0, undo_stack_1.suppressUndoStackInvalidation)(absolutePath);
|
|
128
|
+
(0, watch_ignore_next_change_1.suppressBundlerUpdateForFile)(absolutePath);
|
|
129
|
+
(0, file_watcher_1.writeFileAndNotifyFileWatchers)(absolutePath, output, undefined);
|
|
130
|
+
(0, live_events_1.waitForLiveEventsListener)().then((listener) => {
|
|
131
|
+
listener.sendEventToClient({
|
|
132
|
+
type: 'visual-control-values-changed',
|
|
133
|
+
values: changes.map((change) => ({
|
|
134
|
+
id: change.id,
|
|
135
|
+
value: change.newValueIsUndefined
|
|
136
|
+
? null
|
|
137
|
+
: JSON.parse(change.newValueSerialized),
|
|
138
|
+
isUndefined: change.newValueIsUndefined,
|
|
139
|
+
})),
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
|
|
143
|
+
remotionRoot,
|
|
144
|
+
absolutePath,
|
|
145
|
+
line: logLine,
|
|
146
|
+
});
|
|
147
|
+
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Applied visual control changes`);
|
|
148
|
+
if (!formatted) {
|
|
149
|
+
(0, log_update_1.warnAboutPrettierOnce)(logLevel);
|
|
150
|
+
}
|
|
151
|
+
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
152
|
+
return {
|
|
153
|
+
success: true,
|
|
154
|
+
};
|
|
139
155
|
});
|
|
140
|
-
const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
|
|
141
|
-
remotionRoot,
|
|
142
|
-
absolutePath,
|
|
143
|
-
line: logLine,
|
|
144
|
-
});
|
|
145
|
-
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Applied visual control changes`);
|
|
146
|
-
if (!formatted) {
|
|
147
|
-
(0, log_update_1.warnAboutPrettierOnce)(logLevel);
|
|
148
|
-
}
|
|
149
|
-
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
150
|
-
return {
|
|
151
|
-
success: true,
|
|
152
|
-
};
|
|
153
156
|
};
|
|
154
157
|
exports.applyVisualControlHandler = applyVisualControlHandler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Expression, File, JSXOpeningElement } from '@babel/types';
|
|
1
|
+
import type { Expression, File, JSXElement, JSXOpeningElement } from '@babel/types';
|
|
2
2
|
import type { SubscribeToSequencePropsResponse } from '@remotion/studio-shared';
|
|
3
3
|
import type { CanUpdateSequencePropsResponseTrue, CanUpdateSequencePropStatus, SequenceNodePath } from 'remotion';
|
|
4
4
|
type StaticValueOptions = {
|
|
@@ -7,7 +7,19 @@ type StaticValueOptions = {
|
|
|
7
7
|
export declare const isStaticValue: (node: Expression, options?: StaticValueOptions) => boolean;
|
|
8
8
|
export declare const extractStaticValue: (node: Expression, options?: StaticValueOptions) => unknown;
|
|
9
9
|
export declare const getComputedStatus: (node: Expression, ast: File) => CanUpdateSequencePropStatus;
|
|
10
|
+
export declare const findJsxElementPathAtNodePath: (ast: File, nodePath: SequenceNodePath) => import("ast-types/lib/node-path").NodePath<N, V> | null;
|
|
10
11
|
export declare const findJsxElementAtNodePath: (ast: File, nodePath: SequenceNodePath) => JSXOpeningElement | null;
|
|
12
|
+
export declare const findJsxElementNodeAtNodePath: (ast: File, nodePath: SequenceNodePath) => JSXElement | null;
|
|
13
|
+
export type StaticJsxTextContent = {
|
|
14
|
+
kind: 'jsx-text';
|
|
15
|
+
value: string;
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'string-expression';
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const getStaticJsxChildrenAttribute: (jsxElement: JSXOpeningElement) => StaticJsxTextContent | null;
|
|
21
|
+
export declare const hasJsxChildrenAttribute: (jsxElement: JSXOpeningElement) => boolean;
|
|
22
|
+
export declare const getStaticJsxTextContent: (jsxElement: JSXElement) => StaticJsxTextContent | null;
|
|
11
23
|
export declare const findNodePathForJsxElement: (ast: File, target: JSXOpeningElement) => SequenceNodePath | null;
|
|
12
24
|
export declare const lineColumnToNodePath: (ast: File, targetLine: number) => SequenceNodePath | null;
|
|
13
25
|
export declare const computeSequencePropsStatusFromContent: ({ fileContents, nodePath, componentIdentity, keys, effects, }: {
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.computeSequencePropsStatusFromFilenameByLine = exports.computeSequencePropsStatus = exports.computeSequencePropsStatusFromContent = exports.lineColumnToNodePath = exports.findNodePathForJsxElement = exports.findJsxElementAtNodePath = exports.getComputedStatus = exports.extractStaticValue = exports.isStaticValue = void 0;
|
|
36
|
+
exports.computeSequencePropsStatusFromFilenameByLine = exports.computeSequencePropsStatus = exports.computeSequencePropsStatusFromContent = exports.lineColumnToNodePath = exports.findNodePathForJsxElement = exports.getStaticJsxTextContent = exports.hasJsxChildrenAttribute = exports.getStaticJsxChildrenAttribute = exports.findJsxElementNodeAtNodePath = exports.findJsxElementAtNodePath = exports.findJsxElementPathAtNodePath = exports.getComputedStatus = exports.extractStaticValue = exports.isStaticValue = void 0;
|
|
37
37
|
const node_fs_1 = require("node:fs");
|
|
38
38
|
const renderer_1 = require("@remotion/renderer");
|
|
39
39
|
const studio_shared_1 = require("@remotion/studio-shared");
|
|
@@ -545,17 +545,88 @@ recastPath, ast) => {
|
|
|
545
545
|
}
|
|
546
546
|
return (0, import_agnostic_node_path_1.toImportAgnosticNodePath)({ ast, nodePath: segments });
|
|
547
547
|
};
|
|
548
|
-
const
|
|
548
|
+
const findJsxElementPathAtNodePath = (ast, nodePath) => {
|
|
549
549
|
const current = (0, get_ast_node_path_1.getAstNodePath)(ast, nodePath);
|
|
550
550
|
if (!current) {
|
|
551
551
|
return null;
|
|
552
552
|
}
|
|
553
553
|
if (recast.types.namedTypes.JSXOpeningElement.check(current.value)) {
|
|
554
|
-
return current
|
|
554
|
+
return current;
|
|
555
555
|
}
|
|
556
556
|
return null;
|
|
557
557
|
};
|
|
558
|
+
exports.findJsxElementPathAtNodePath = findJsxElementPathAtNodePath;
|
|
559
|
+
const findJsxElementAtNodePath = (ast, nodePath) => {
|
|
560
|
+
const current = (0, exports.findJsxElementPathAtNodePath)(ast, nodePath);
|
|
561
|
+
return current ? current.value : null;
|
|
562
|
+
};
|
|
558
563
|
exports.findJsxElementAtNodePath = findJsxElementAtNodePath;
|
|
564
|
+
const findJsxElementNodeAtNodePath = (ast, nodePath) => {
|
|
565
|
+
var _a;
|
|
566
|
+
const current = (0, exports.findJsxElementPathAtNodePath)(ast, nodePath);
|
|
567
|
+
if (!current) {
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
if (recast.types.namedTypes.JSXElement.check((_a = current.parentPath) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
571
|
+
return current.parentPath.value;
|
|
572
|
+
}
|
|
573
|
+
return null;
|
|
574
|
+
};
|
|
575
|
+
exports.findJsxElementNodeAtNodePath = findJsxElementNodeAtNodePath;
|
|
576
|
+
const findJsxChildrenAttribute = (jsxElement) => {
|
|
577
|
+
const childrenAttr = jsxElement.attributes.find((attr) => {
|
|
578
|
+
return (attr.type === 'JSXAttribute' &&
|
|
579
|
+
attr.name.type === 'JSXIdentifier' &&
|
|
580
|
+
attr.name.name === 'children');
|
|
581
|
+
});
|
|
582
|
+
return childrenAttr && childrenAttr.type === 'JSXAttribute'
|
|
583
|
+
? childrenAttr
|
|
584
|
+
: null;
|
|
585
|
+
};
|
|
586
|
+
const getStaticJsxChildrenAttribute = (jsxElement) => {
|
|
587
|
+
const childrenAttr = findJsxChildrenAttribute(jsxElement);
|
|
588
|
+
if (!(childrenAttr === null || childrenAttr === void 0 ? void 0 : childrenAttr.value)) {
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
if (childrenAttr.value.type === 'StringLiteral') {
|
|
592
|
+
return { kind: 'jsx-text', value: childrenAttr.value.value };
|
|
593
|
+
}
|
|
594
|
+
if (childrenAttr.value.type === 'JSXExpressionContainer' &&
|
|
595
|
+
childrenAttr.value.expression.type === 'StringLiteral') {
|
|
596
|
+
return {
|
|
597
|
+
kind: 'string-expression',
|
|
598
|
+
value: childrenAttr.value.expression.value,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
return null;
|
|
602
|
+
};
|
|
603
|
+
exports.getStaticJsxChildrenAttribute = getStaticJsxChildrenAttribute;
|
|
604
|
+
const hasJsxChildrenAttribute = (jsxElement) => findJsxChildrenAttribute(jsxElement) !== null;
|
|
605
|
+
exports.hasJsxChildrenAttribute = hasJsxChildrenAttribute;
|
|
606
|
+
const getStaticJsxTextContent = (jsxElement) => {
|
|
607
|
+
const meaningfulChildren = jsxElement.children.filter((candidate) => {
|
|
608
|
+
return !(candidate.type === 'JSXText' && candidate.value.trim() === '');
|
|
609
|
+
});
|
|
610
|
+
if (meaningfulChildren.length === 0) {
|
|
611
|
+
return { kind: 'jsx-text', value: '' };
|
|
612
|
+
}
|
|
613
|
+
if (meaningfulChildren.length !== 1) {
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
const child = meaningfulChildren[0];
|
|
617
|
+
if (child.type === 'JSXText') {
|
|
618
|
+
return {
|
|
619
|
+
kind: 'jsx-text',
|
|
620
|
+
value: child.value.includes('\n') ? child.value.trim() : child.value,
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
if (child.type === 'JSXExpressionContainer' &&
|
|
624
|
+
child.expression.type === 'StringLiteral') {
|
|
625
|
+
return { kind: 'string-expression', value: child.expression.value };
|
|
626
|
+
}
|
|
627
|
+
return null;
|
|
628
|
+
};
|
|
629
|
+
exports.getStaticJsxTextContent = getStaticJsxTextContent;
|
|
559
630
|
const findNodePathForJsxElement = (ast, target) => {
|
|
560
631
|
let foundPath = null;
|
|
561
632
|
recast.types.visit(ast, {
|
|
@@ -642,10 +713,26 @@ const computeEffectsForJsx = ({ ast, jsxElement, effects, }) => {
|
|
|
642
713
|
keys: effect,
|
|
643
714
|
}));
|
|
644
715
|
};
|
|
645
|
-
const computeSequenceOnlyPropsRecord = ({ jsxElement, ast, keys, }) => {
|
|
716
|
+
const computeSequenceOnlyPropsRecord = ({ jsxElement, jsxElementNode, ast, keys, }) => {
|
|
646
717
|
const allProps = getPropsStatus(jsxElement, ast);
|
|
647
718
|
const filteredProps = {};
|
|
648
719
|
for (const key of keys) {
|
|
720
|
+
if (key === 'children') {
|
|
721
|
+
const staticChildrenAttribute = (0, exports.getStaticJsxChildrenAttribute)(jsxElement);
|
|
722
|
+
if (staticChildrenAttribute) {
|
|
723
|
+
filteredProps[key] = staticStatus(staticChildrenAttribute.value);
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
if ((0, exports.hasJsxChildrenAttribute)(jsxElement)) {
|
|
727
|
+
filteredProps[key] = computedStatus();
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
const staticTextContent = (0, exports.getStaticJsxTextContent)(jsxElementNode);
|
|
731
|
+
filteredProps[key] = staticTextContent
|
|
732
|
+
? staticStatus(staticTextContent.value)
|
|
733
|
+
: computedStatus();
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
649
736
|
const dotIndex = key.indexOf('.');
|
|
650
737
|
if (dotIndex !== -1) {
|
|
651
738
|
filteredProps[key] = getNestedPropStatus(jsxElement, ast, key.slice(0, dotIndex), key.slice(dotIndex + 1));
|
|
@@ -660,9 +747,11 @@ const computeSequenceOnlyPropsRecord = ({ jsxElement, ast, keys, }) => {
|
|
|
660
747
|
return filteredProps;
|
|
661
748
|
};
|
|
662
749
|
const computeSequencePropsStatusFromContent = ({ fileContents, nodePath, componentIdentity, keys, effects, }) => {
|
|
750
|
+
var _a;
|
|
663
751
|
const ast = (0, parse_ast_1.parseAst)(fileContents);
|
|
664
|
-
const
|
|
665
|
-
|
|
752
|
+
const jsxElementNode = (0, exports.findJsxElementNodeAtNodePath)(ast, nodePath);
|
|
753
|
+
const jsxElement = (_a = jsxElementNode === null || jsxElementNode === void 0 ? void 0 : jsxElementNode.openingElement) !== null && _a !== void 0 ? _a : null;
|
|
754
|
+
if (!jsxElement || !jsxElementNode) {
|
|
666
755
|
throw new jsx_element_not_found_at_location_error_1.JsxElementNotFoundAtLocationError();
|
|
667
756
|
}
|
|
668
757
|
if (!(0, jsx_component_identity_1.jsxComponentIdentitiesMatch)({
|
|
@@ -671,7 +760,12 @@ const computeSequencePropsStatusFromContent = ({ fileContents, nodePath, compone
|
|
|
671
760
|
})) {
|
|
672
761
|
throw new jsx_component_identity_1.JsxElementIdentityMismatchError();
|
|
673
762
|
}
|
|
674
|
-
const filteredProps = computeSequenceOnlyPropsRecord({
|
|
763
|
+
const filteredProps = computeSequenceOnlyPropsRecord({
|
|
764
|
+
jsxElement,
|
|
765
|
+
jsxElementNode,
|
|
766
|
+
ast,
|
|
767
|
+
keys,
|
|
768
|
+
});
|
|
675
769
|
const effectsStatuses = computeEffectsForJsx({ ast, jsxElement, effects });
|
|
676
770
|
return {
|
|
677
771
|
canUpdate: true,
|