@remotion/studio-server 4.0.535 → 4.0.537
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/helpers/resolve-composition-component.d.ts +1 -2
- package/dist/helpers/resolve-composition-component.js +1 -3
- package/dist/preview-server/api-routes.js +2 -0
- package/dist/preview-server/default-props-watchers.d.ts +3 -2
- package/dist/preview-server/default-props-watchers.js +48 -77
- package/dist/preview-server/routes/can-update-default-props.d.ts +9 -3
- package/dist/preview-server/routes/can-update-default-props.js +43 -10
- package/dist/preview-server/routes/insert-basic-captions.js +1 -2
- package/dist/preview-server/routes/insert-composition-element.js +14 -6
- package/dist/preview-server/routes/insert-element.js +1 -2
- package/dist/preview-server/routes/subscribe-to-default-props.js +2 -1
- package/dist/preview-server/routes/unsubscribe-from-sequence-props.d.ts +2 -2
- package/dist/preview-server/routes/unsubscribe-from-sequence-props.js +12 -10
- package/dist/preview-server/routes/unwrap-node.d.ts +3 -0
- package/dist/preview-server/routes/{wrap-jsx-node.js → unwrap-node.js} +24 -23
- package/dist/preview-server/routes/update-default-props.js +15 -15
- package/dist/preview-server/sequence-props-watchers.js +7 -2
- package/dist/preview-server/undo-stack.d.ts +1 -1
- package/package.json +8 -8
- package/dist/canvas-capture/generate-canvas-capture-composition.d.ts +0 -14
- package/dist/canvas-capture/generate-canvas-capture-composition.js +0 -239
- package/dist/codemods/add-effect.d.ts +0 -1
- package/dist/codemods/add-effect.js +0 -8
- package/dist/codemods/apply-codemod-to-file.d.ts +0 -7
- package/dist/codemods/apply-codemod-to-file.js +0 -171
- package/dist/codemods/apply-visual-control.d.ts +0 -8
- package/dist/codemods/apply-visual-control.js +0 -89
- package/dist/codemods/delete-effect.d.ts +0 -1
- package/dist/codemods/delete-effect.js +0 -6
- package/dist/codemods/delete-jsx-node.d.ts +0 -22
- package/dist/codemods/delete-jsx-node.js +0 -17
- package/dist/codemods/delete-jsx-nodes.d.ts +0 -13
- package/dist/codemods/delete-jsx-nodes.js +0 -10
- package/dist/codemods/duplicate-composition.d.ts +0 -2
- package/dist/codemods/duplicate-composition.js +0 -64
- package/dist/codemods/duplicate-effect.d.ts +0 -1
- package/dist/codemods/duplicate-effect.js +0 -6
- package/dist/codemods/duplicate-jsx-node.d.ts +0 -25
- package/dist/codemods/duplicate-jsx-node.js +0 -26
- package/dist/codemods/format-file-content.d.ts +0 -7
- package/dist/codemods/format-file-content.js +0 -80
- package/dist/codemods/format-inline-content.d.ts +0 -18
- package/dist/codemods/format-inline-content.js +0 -78
- package/dist/codemods/insert-video-layers.d.ts +0 -11
- package/dist/codemods/insert-video-layers.js +0 -5
- package/dist/codemods/recast-mods.d.ts +0 -13
- package/dist/codemods/recast-mods.js +0 -902
- package/dist/codemods/reorder-effect.d.ts +0 -1
- package/dist/codemods/reorder-effect.js +0 -5
- package/dist/codemods/reorder-sequence.d.ts +0 -1
- package/dist/codemods/reorder-sequence.js +0 -5
- package/dist/codemods/simple-diff.d.ts +0 -5
- package/dist/codemods/simple-diff.js +0 -39
- package/dist/codemods/split-jsx-sequence.d.ts +0 -27
- package/dist/codemods/split-jsx-sequence.js +0 -19
- package/dist/codemods/split-video-from-audio.d.ts +0 -1
- package/dist/codemods/split-video-from-audio.js +0 -5
- package/dist/codemods/update-default-props.d.ts +0 -1
- package/dist/codemods/update-default-props.js +0 -6
- package/dist/codemods/update-inline-caption-patches.d.ts +0 -1
- package/dist/codemods/update-inline-caption-patches.js +0 -5
- package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.d.ts +0 -1
- package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.js +0 -7
- package/dist/open-browser-shortcut.d.ts +0 -9
- package/dist/open-browser-shortcut.js +0 -121
- package/dist/preview-server/hot-middleware/types.d.ts +0 -2
- package/dist/preview-server/hot-middleware/types.js +0 -2
- package/dist/preview-server/routes/apply-codemod.d.ts +0 -4
- package/dist/preview-server/routes/apply-codemod.js +0 -272
- package/dist/preview-server/routes/delete-jsx-node.d.ts +0 -3
- package/dist/preview-server/routes/delete-jsx-node.js +0 -126
- package/dist/preview-server/routes/delete-jsx-nodes.d.ts +0 -3
- package/dist/preview-server/routes/delete-jsx-nodes.js +0 -137
- package/dist/preview-server/routes/duplicate-jsx-node.d.ts +0 -3
- package/dist/preview-server/routes/duplicate-jsx-node.js +0 -118
- package/dist/preview-server/routes/insert-jsx-element.d.ts +0 -3
- package/dist/preview-server/routes/insert-jsx-element.js +0 -231
- package/dist/preview-server/routes/insert-video-layers.d.ts +0 -3
- package/dist/preview-server/routes/insert-video-layers.js +0 -68
- package/dist/preview-server/routes/split-jsx-sequence.d.ts +0 -3
- package/dist/preview-server/routes/split-jsx-sequence.js +0 -117
- package/dist/preview-server/routes/update-public-license.d.ts +0 -11
- package/dist/preview-server/routes/update-public-license.js +0 -97
- package/dist/preview-server/routes/wrap-jsx-node.d.ts +0 -3
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteJsxNodeHandler = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const renderer_1 = require("@remotion/renderer");
|
|
6
|
-
const delete_jsx_node_1 = require("../../codemods/delete-jsx-node");
|
|
7
|
-
const file_watcher_1 = require("../../file-watcher");
|
|
8
|
-
const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
|
|
9
|
-
const format_log_file_location_1 = require("../format-log-file-location");
|
|
10
|
-
const hmr_timing_1 = require("../hmr-timing");
|
|
11
|
-
const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
|
|
12
|
-
const undo_stack_1 = require("../undo-stack");
|
|
13
|
-
const source_file_write_queue_1 = require("./source-file-write-queue");
|
|
14
|
-
const getDeletedNodeDescription = (nodeLabels) => {
|
|
15
|
-
if (nodeLabels.length === 1) {
|
|
16
|
-
return nodeLabels[0];
|
|
17
|
-
}
|
|
18
|
-
return `${nodeLabels.length} JSX nodes`;
|
|
19
|
-
};
|
|
20
|
-
const deleteJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
21
|
-
return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
|
|
22
|
-
var _a;
|
|
23
|
-
try {
|
|
24
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
25
|
-
detail: null,
|
|
26
|
-
logLevel,
|
|
27
|
-
stage: 'delete-jsx-node-request-start',
|
|
28
|
-
});
|
|
29
|
-
if (nodes.length === 0) {
|
|
30
|
-
throw new Error('No JSX nodes were specified for deletion');
|
|
31
|
-
}
|
|
32
|
-
renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[delete-jsx-node] Received request to delete ${nodes.length} JSX node${nodes.length === 1 ? '' : 's'}`);
|
|
33
|
-
const itemsByFileName = new Map();
|
|
34
|
-
for (const item of nodes) {
|
|
35
|
-
const fileItems = (_a = itemsByFileName.get(item.fileName)) !== null && _a !== void 0 ? _a : [];
|
|
36
|
-
fileItems.push(item);
|
|
37
|
-
itemsByFileName.set(item.fileName, fileItems);
|
|
38
|
-
}
|
|
39
|
-
const updates = await Promise.all([...itemsByFileName.entries()].map(async ([fileName, fileItems]) => {
|
|
40
|
-
const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
41
|
-
remotionRoot,
|
|
42
|
-
fileName,
|
|
43
|
-
action: 'modify',
|
|
44
|
-
});
|
|
45
|
-
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
46
|
-
const { output, nodeLabels, logLines, nodePathRemappings } = await (0, delete_jsx_node_1.deleteJsxNodes)({
|
|
47
|
-
input: fileContents,
|
|
48
|
-
nodePaths: fileItems.map((item) => item.nodePath),
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
absolutePath,
|
|
52
|
-
fileRelativeToRoot,
|
|
53
|
-
fileContents,
|
|
54
|
-
output,
|
|
55
|
-
nodeLabels,
|
|
56
|
-
nodePathRemappings,
|
|
57
|
-
logLine: Math.min(...logLines),
|
|
58
|
-
};
|
|
59
|
-
}));
|
|
60
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
61
|
-
detail: `files=${updates.length}`,
|
|
62
|
-
logLevel,
|
|
63
|
-
stage: 'delete-jsx-node-codemod-complete',
|
|
64
|
-
});
|
|
65
|
-
const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(updates.map((update) => ({
|
|
66
|
-
absolutePath: update.absolutePath,
|
|
67
|
-
remappings: update.nodePathRemappings,
|
|
68
|
-
})), null);
|
|
69
|
-
for (const update of updates) {
|
|
70
|
-
const deletedNodeDescription = getDeletedNodeDescription(update.nodeLabels);
|
|
71
|
-
(0, undo_stack_1.pushToUndoStack)({
|
|
72
|
-
filePath: update.absolutePath,
|
|
73
|
-
oldContents: update.fileContents,
|
|
74
|
-
newContents: null,
|
|
75
|
-
logLevel,
|
|
76
|
-
remotionRoot,
|
|
77
|
-
logLine: update.logLine,
|
|
78
|
-
description: {
|
|
79
|
-
undoMessage: `↩️ Deletion of ${deletedNodeDescription}`,
|
|
80
|
-
redoMessage: `↪️ Deletion of ${deletedNodeDescription}`,
|
|
81
|
-
},
|
|
82
|
-
entryType: 'delete-jsx-node',
|
|
83
|
-
suppressHmrOnFileRestore: false,
|
|
84
|
-
nodePathRemappings: update.nodePathRemappings,
|
|
85
|
-
});
|
|
86
|
-
(0, undo_stack_1.suppressUndoStackInvalidation)(update.absolutePath);
|
|
87
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
88
|
-
detail: `file=${update.fileRelativeToRoot}`,
|
|
89
|
-
logLevel,
|
|
90
|
-
stage: 'source-file-write-start',
|
|
91
|
-
});
|
|
92
|
-
(0, file_watcher_1.writeFileAndNotifyFileWatchers)({
|
|
93
|
-
file: update.absolutePath,
|
|
94
|
-
content: update.output,
|
|
95
|
-
originatorClientId: undefined,
|
|
96
|
-
metadata: { skipSequencePropsUpdate: true },
|
|
97
|
-
});
|
|
98
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
99
|
-
detail: `file=${update.fileRelativeToRoot}`,
|
|
100
|
-
logLevel,
|
|
101
|
-
stage: 'source-file-write-complete',
|
|
102
|
-
});
|
|
103
|
-
const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
|
|
104
|
-
remotionRoot,
|
|
105
|
-
absolutePath: update.absolutePath,
|
|
106
|
-
line: update.logLine,
|
|
107
|
-
});
|
|
108
|
-
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Deleted ${deletedNodeDescription}`);
|
|
109
|
-
renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[delete-jsx-node] Wrote ${update.fileRelativeToRoot}`);
|
|
110
|
-
}
|
|
111
|
-
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
112
|
-
return {
|
|
113
|
-
success: true,
|
|
114
|
-
nodePathMutation,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
return {
|
|
119
|
-
success: false,
|
|
120
|
-
reason: err.message,
|
|
121
|
-
stack: err.stack,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
exports.deleteJsxNodeHandler = deleteJsxNodeHandler;
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteJsxNodesHandler = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const codemods_1 = require("@remotion/codemods");
|
|
6
|
-
const renderer_1 = require("@remotion/renderer");
|
|
7
|
-
const file_watcher_1 = require("../../file-watcher");
|
|
8
|
-
const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
|
|
9
|
-
const format_log_file_location_1 = require("../format-log-file-location");
|
|
10
|
-
const hmr_timing_1 = require("../hmr-timing");
|
|
11
|
-
const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
|
|
12
|
-
const undo_stack_1 = require("../undo-stack");
|
|
13
|
-
const source_file_write_queue_1 = require("./source-file-write-queue");
|
|
14
|
-
const getDeletedNodeDescription = (nodeLabels) => {
|
|
15
|
-
if (nodeLabels.length === 1) {
|
|
16
|
-
return nodeLabels[0];
|
|
17
|
-
}
|
|
18
|
-
return `${nodeLabels.length} JSX nodes`;
|
|
19
|
-
};
|
|
20
|
-
const deleteJsxNodesHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
21
|
-
return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
|
|
22
|
-
var _a;
|
|
23
|
-
try {
|
|
24
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
25
|
-
detail: null,
|
|
26
|
-
logLevel,
|
|
27
|
-
stage: 'delete-jsx-nodes-request-start',
|
|
28
|
-
});
|
|
29
|
-
if (nodes.length === 0) {
|
|
30
|
-
throw new Error('No JSX nodes were specified for deletion');
|
|
31
|
-
}
|
|
32
|
-
renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[delete-jsx-nodes] Received request to delete ${nodes.length} JSX node${nodes.length === 1 ? '' : 's'}`);
|
|
33
|
-
const itemsByFileName = new Map();
|
|
34
|
-
for (const item of nodes) {
|
|
35
|
-
const fileItems = (_a = itemsByFileName.get(item.fileName)) !== null && _a !== void 0 ? _a : [];
|
|
36
|
-
fileItems.push(item);
|
|
37
|
-
itemsByFileName.set(item.fileName, fileItems);
|
|
38
|
-
}
|
|
39
|
-
const updates = await Promise.all([...itemsByFileName.entries()].map(async ([fileName, fileItems]) => {
|
|
40
|
-
var _a;
|
|
41
|
-
var _b;
|
|
42
|
-
const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
43
|
-
remotionRoot,
|
|
44
|
-
fileName,
|
|
45
|
-
action: 'modify',
|
|
46
|
-
});
|
|
47
|
-
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
48
|
-
const result = await (0, codemods_1.deleteJsxNodes)({
|
|
49
|
-
project: {
|
|
50
|
-
files: { [absolutePath]: fileContents },
|
|
51
|
-
rootDir: remotionRoot,
|
|
52
|
-
},
|
|
53
|
-
nodes: fileItems.map((item) => ({
|
|
54
|
-
filePath: absolutePath,
|
|
55
|
-
nodePath: item.nodePath,
|
|
56
|
-
})),
|
|
57
|
-
});
|
|
58
|
-
const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
|
|
59
|
-
const { nodeLabels, logLines } = result.editDetails[0];
|
|
60
|
-
const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath }) => ({ oldNodePath, newNodePath }));
|
|
61
|
-
return {
|
|
62
|
-
absolutePath,
|
|
63
|
-
fileRelativeToRoot,
|
|
64
|
-
fileContents,
|
|
65
|
-
output,
|
|
66
|
-
nodeLabels,
|
|
67
|
-
nodePathRemappings,
|
|
68
|
-
logLine: Math.min(...logLines),
|
|
69
|
-
};
|
|
70
|
-
}));
|
|
71
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
72
|
-
detail: `files=${updates.length}`,
|
|
73
|
-
logLevel,
|
|
74
|
-
stage: 'delete-jsx-nodes-codemod-complete',
|
|
75
|
-
});
|
|
76
|
-
const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(updates.map((update) => ({
|
|
77
|
-
absolutePath: update.absolutePath,
|
|
78
|
-
remappings: update.nodePathRemappings,
|
|
79
|
-
})), null);
|
|
80
|
-
for (const update of updates) {
|
|
81
|
-
const deletedNodeDescription = getDeletedNodeDescription(update.nodeLabels);
|
|
82
|
-
(0, undo_stack_1.pushToUndoStack)({
|
|
83
|
-
filePath: update.absolutePath,
|
|
84
|
-
oldContents: update.fileContents,
|
|
85
|
-
newContents: null,
|
|
86
|
-
logLevel,
|
|
87
|
-
remotionRoot,
|
|
88
|
-
logLine: update.logLine,
|
|
89
|
-
description: {
|
|
90
|
-
undoMessage: `↩️ Deletion of ${deletedNodeDescription}`,
|
|
91
|
-
redoMessage: `↪️ Deletion of ${deletedNodeDescription}`,
|
|
92
|
-
},
|
|
93
|
-
entryType: 'delete-jsx-nodes',
|
|
94
|
-
suppressHmrOnFileRestore: false,
|
|
95
|
-
nodePathRemappings: update.nodePathRemappings,
|
|
96
|
-
});
|
|
97
|
-
(0, undo_stack_1.suppressUndoStackInvalidation)(update.absolutePath);
|
|
98
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
99
|
-
detail: `file=${update.fileRelativeToRoot}`,
|
|
100
|
-
logLevel,
|
|
101
|
-
stage: 'source-file-write-start',
|
|
102
|
-
});
|
|
103
|
-
(0, file_watcher_1.writeFileAndNotifyFileWatchers)({
|
|
104
|
-
file: update.absolutePath,
|
|
105
|
-
content: update.output,
|
|
106
|
-
originatorClientId: undefined,
|
|
107
|
-
metadata: { skipSequencePropsUpdate: true },
|
|
108
|
-
});
|
|
109
|
-
(0, hmr_timing_1.logHmrTiming)({
|
|
110
|
-
detail: `file=${update.fileRelativeToRoot}`,
|
|
111
|
-
logLevel,
|
|
112
|
-
stage: 'source-file-write-complete',
|
|
113
|
-
});
|
|
114
|
-
const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
|
|
115
|
-
remotionRoot,
|
|
116
|
-
absolutePath: update.absolutePath,
|
|
117
|
-
line: update.logLine,
|
|
118
|
-
});
|
|
119
|
-
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Deleted ${deletedNodeDescription}`);
|
|
120
|
-
renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[delete-jsx-nodes] Wrote ${update.fileRelativeToRoot}`);
|
|
121
|
-
}
|
|
122
|
-
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
123
|
-
return {
|
|
124
|
-
success: true,
|
|
125
|
-
nodePathMutation,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
return {
|
|
130
|
-
success: false,
|
|
131
|
-
reason: err.message,
|
|
132
|
-
stack: err.stack,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
exports.deleteJsxNodesHandler = deleteJsxNodesHandler;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.duplicateJsxNodeHandler = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const codemods_1 = require("@remotion/codemods");
|
|
6
|
-
const renderer_1 = require("@remotion/renderer");
|
|
7
|
-
const file_watcher_1 = require("../../file-watcher");
|
|
8
|
-
const resolve_file_inside_project_1 = require("../../helpers/resolve-file-inside-project");
|
|
9
|
-
const format_log_file_location_1 = require("../format-log-file-location");
|
|
10
|
-
const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
|
|
11
|
-
const undo_stack_1 = require("../undo-stack");
|
|
12
|
-
const source_file_write_queue_1 = require("./source-file-write-queue");
|
|
13
|
-
const duplicateJsxNodeHandler = ({ input: { nodes }, remotionRoot, logLevel }) => {
|
|
14
|
-
return (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
|
|
15
|
-
var _a;
|
|
16
|
-
try {
|
|
17
|
-
if (nodes.length === 0) {
|
|
18
|
-
throw new Error('No JSX nodes were specified for duplication');
|
|
19
|
-
}
|
|
20
|
-
renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[duplicate-jsx-node] Received request to duplicate ${nodes.length} JSX node${nodes.length === 1 ? '' : 's'}`);
|
|
21
|
-
const itemsByFileName = new Map();
|
|
22
|
-
for (const item of nodes) {
|
|
23
|
-
const fileItems = (_a = itemsByFileName.get(item.fileName)) !== null && _a !== void 0 ? _a : [];
|
|
24
|
-
fileItems.push(item);
|
|
25
|
-
itemsByFileName.set(item.fileName, fileItems);
|
|
26
|
-
}
|
|
27
|
-
const updates = await Promise.all([...itemsByFileName.entries()].map(async ([fileName, fileItems]) => {
|
|
28
|
-
var _a;
|
|
29
|
-
var _b;
|
|
30
|
-
const { absolutePath, fileRelativeToRoot } = (0, resolve_file_inside_project_1.resolveFileInsideProject)({
|
|
31
|
-
remotionRoot,
|
|
32
|
-
fileName,
|
|
33
|
-
action: 'modify',
|
|
34
|
-
});
|
|
35
|
-
const fileContents = (0, node_fs_1.readFileSync)(absolutePath, 'utf-8');
|
|
36
|
-
const result = await (0, codemods_1.duplicateJsxNodes)({
|
|
37
|
-
project: {
|
|
38
|
-
files: { [absolutePath]: fileContents },
|
|
39
|
-
rootDir: remotionRoot,
|
|
40
|
-
},
|
|
41
|
-
nodes: fileItems.map((item) => ({
|
|
42
|
-
filePath: absolutePath,
|
|
43
|
-
nodePath: item.nodePath,
|
|
44
|
-
})),
|
|
45
|
-
});
|
|
46
|
-
const output = (_b = (_a = result.changes[0]) === null || _a === void 0 ? void 0 : _a.nextContents) !== null && _b !== void 0 ? _b : fileContents;
|
|
47
|
-
const { nodeLabels, logLines } = result.editDetails[0];
|
|
48
|
-
const nodePathRemappings = result.nodePathRemappings.map(({ oldNodePath, newNodePath }) => ({ oldNodePath, newNodePath }));
|
|
49
|
-
return {
|
|
50
|
-
absolutePath,
|
|
51
|
-
fileRelativeToRoot,
|
|
52
|
-
fileContents,
|
|
53
|
-
logLine: Math.min(...logLines),
|
|
54
|
-
nodeLabels,
|
|
55
|
-
nodePathRemappings,
|
|
56
|
-
output,
|
|
57
|
-
};
|
|
58
|
-
}));
|
|
59
|
-
const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)(updates.map((update) => ({
|
|
60
|
-
absolutePath: update.absolutePath,
|
|
61
|
-
remappings: update.nodePathRemappings,
|
|
62
|
-
})), null);
|
|
63
|
-
const duplicatedNodeDescription = nodes.length === 1
|
|
64
|
-
? updates[0].nodeLabels[0]
|
|
65
|
-
: `${nodes.length} JSX nodes`;
|
|
66
|
-
(0, undo_stack_1.pushTransactionToUndoStack)({
|
|
67
|
-
snapshots: updates.map((update) => ({
|
|
68
|
-
filePath: update.absolutePath,
|
|
69
|
-
oldContents: update.fileContents,
|
|
70
|
-
newContents: null,
|
|
71
|
-
logLine: update.logLine,
|
|
72
|
-
nodePathRemappings: update.nodePathRemappings,
|
|
73
|
-
})),
|
|
74
|
-
logLevel,
|
|
75
|
-
remotionRoot,
|
|
76
|
-
description: {
|
|
77
|
-
undoMessage: `↩️ Duplication of ${duplicatedNodeDescription}`,
|
|
78
|
-
redoMessage: `↪️ Duplication of ${duplicatedNodeDescription}`,
|
|
79
|
-
},
|
|
80
|
-
entryType: 'duplicate-jsx-node',
|
|
81
|
-
suppressHmrOnFileRestore: false,
|
|
82
|
-
undoRedoNavigation: null,
|
|
83
|
-
});
|
|
84
|
-
for (const update of updates) {
|
|
85
|
-
(0, undo_stack_1.suppressUndoStackInvalidation)(update.absolutePath);
|
|
86
|
-
(0, file_watcher_1.writeFileAndNotifyFileWatchers)({
|
|
87
|
-
file: update.absolutePath,
|
|
88
|
-
content: update.output,
|
|
89
|
-
originatorClientId: undefined,
|
|
90
|
-
metadata: { skipSequencePropsUpdate: true },
|
|
91
|
-
});
|
|
92
|
-
const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
|
|
93
|
-
remotionRoot,
|
|
94
|
-
absolutePath: update.absolutePath,
|
|
95
|
-
line: update.logLine,
|
|
96
|
-
});
|
|
97
|
-
const fileDescription = update.nodeLabels.length === 1
|
|
98
|
-
? update.nodeLabels[0]
|
|
99
|
-
: `${update.nodeLabels.length} JSX nodes`;
|
|
100
|
-
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Duplicated ${fileDescription}`);
|
|
101
|
-
renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[duplicate-jsx-node] Wrote ${update.fileRelativeToRoot}`);
|
|
102
|
-
}
|
|
103
|
-
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
104
|
-
return {
|
|
105
|
-
success: true,
|
|
106
|
-
nodePathMutation,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
return {
|
|
111
|
-
success: false,
|
|
112
|
-
reason: err.message,
|
|
113
|
-
stack: err.stack,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
exports.duplicateJsxNodeHandler = duplicateJsxNodeHandler;
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.insertJsxElementHandler = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const renderer_1 = require("@remotion/renderer");
|
|
9
|
-
const studio_protocol_1 = require("@remotion/studio-protocol");
|
|
10
|
-
const studio_shared_1 = require("@remotion/studio-shared");
|
|
11
|
-
const file_watcher_1 = require("../../file-watcher");
|
|
12
|
-
const resolve_composition_component_1 = require("../../helpers/resolve-composition-component");
|
|
13
|
-
const format_log_file_location_1 = require("../format-log-file-location");
|
|
14
|
-
const sequence_node_path_mutation_1 = require("../sequence-node-path-mutation");
|
|
15
|
-
const undo_stack_1 = require("../undo-stack");
|
|
16
|
-
const source_file_write_queue_1 = require("./source-file-write-queue");
|
|
17
|
-
const validateDimension = (name, value) => {
|
|
18
|
-
if (!Number.isFinite(value) || value < 1) {
|
|
19
|
-
throw new Error(`${name} must be a positive number`);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const validatePosition = (position) => {
|
|
23
|
-
if (position === null) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (!Number.isFinite(position.x) || !Number.isFinite(position.y)) {
|
|
27
|
-
throw new Error('Position must be finite');
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const isInsideRemotionRoot = ({ fileName, remotionRoot, }) => {
|
|
31
|
-
const relativePath = node_path_1.default.relative(remotionRoot, fileName);
|
|
32
|
-
return !relativePath.startsWith('..') && !node_path_1.default.isAbsolute(relativePath);
|
|
33
|
-
};
|
|
34
|
-
const hasParentDirectorySegment = (fileName) => {
|
|
35
|
-
return fileName.split('/').includes('..');
|
|
36
|
-
};
|
|
37
|
-
const validateCompositionFile = ({ compositionFile, remotionRoot, }) => {
|
|
38
|
-
if (!compositionFile ||
|
|
39
|
-
compositionFile.includes('\0') ||
|
|
40
|
-
compositionFile.includes('\\') ||
|
|
41
|
-
compositionFile.startsWith('/') ||
|
|
42
|
-
hasParentDirectorySegment(compositionFile)) {
|
|
43
|
-
throw new Error('Unsupported composition file');
|
|
44
|
-
}
|
|
45
|
-
const resolved = node_path_1.default.resolve(remotionRoot, compositionFile);
|
|
46
|
-
if (!isInsideRemotionRoot({ fileName: resolved, remotionRoot })) {
|
|
47
|
-
throw new Error('Unsupported composition file');
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const validateElement = (element, remotionRoot) => {
|
|
51
|
-
validatePosition(element.position);
|
|
52
|
-
if (element.type === 'solid') {
|
|
53
|
-
validateDimension('width', element.width);
|
|
54
|
-
validateDimension('height', element.height);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (element.type === 'svg') {
|
|
58
|
-
if (typeof element.markup !== 'string' || element.markup.trim() === '') {
|
|
59
|
-
throw new Error('SVG markup must be a non-empty string');
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (element.type === 'asset') {
|
|
64
|
-
if (element.srcType === 'remote') {
|
|
65
|
-
if (!(0, studio_shared_1.isUrl)(element.src)) {
|
|
66
|
-
throw new Error('Remote asset source must be a URL');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (!element.src || element.src.includes('\\')) {
|
|
70
|
-
throw new Error('Asset path must be a static file path');
|
|
71
|
-
}
|
|
72
|
-
if (element.dimensions) {
|
|
73
|
-
validateDimension('width', element.dimensions.width);
|
|
74
|
-
validateDimension('height', element.dimensions.height);
|
|
75
|
-
}
|
|
76
|
-
if (element.durationInFrames !== null) {
|
|
77
|
-
validateDimension('durationInFrames', element.durationInFrames);
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (element.type === 'component') {
|
|
82
|
-
if (!studio_protocol_1.StudioProtocolInternals.isComponentIdentifier(element.componentName)) {
|
|
83
|
-
throw new Error('Unsupported component name');
|
|
84
|
-
}
|
|
85
|
-
if (!studio_protocol_1.StudioProtocolInternals.isComponentIdentifier(element.importName)) {
|
|
86
|
-
throw new Error('Unsupported component import name');
|
|
87
|
-
}
|
|
88
|
-
if (!studio_protocol_1.StudioProtocolInternals.isComponentImportPath(element.importPath)) {
|
|
89
|
-
throw new Error('Unsupported component import path');
|
|
90
|
-
}
|
|
91
|
-
if (!studio_protocol_1.StudioProtocolInternals.areComponentProps(element.props)) {
|
|
92
|
-
throw new Error('Unsupported component props');
|
|
93
|
-
}
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (element.type === 'composition') {
|
|
97
|
-
if (typeof element.compositionId !== 'string' || !element.compositionId) {
|
|
98
|
-
throw new Error('Unsupported composition ID');
|
|
99
|
-
}
|
|
100
|
-
if (typeof element.compositionFile !== 'string') {
|
|
101
|
-
throw new Error('Unsupported composition file');
|
|
102
|
-
}
|
|
103
|
-
validateCompositionFile({
|
|
104
|
-
compositionFile: element.compositionFile,
|
|
105
|
-
remotionRoot,
|
|
106
|
-
});
|
|
107
|
-
validateDimension('width', element.width);
|
|
108
|
-
validateDimension('height', element.height);
|
|
109
|
-
validateDimension('durationInFrames', element.durationInFrames);
|
|
110
|
-
const parsedProps = JSON.parse(element.serializedResolvedPropsWithCustomSchema);
|
|
111
|
-
if (typeof parsedProps !== 'object' ||
|
|
112
|
-
parsedProps === null ||
|
|
113
|
-
Array.isArray(parsedProps)) {
|
|
114
|
-
throw new Error('Resolved composition props must be an object');
|
|
115
|
-
}
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
throw new Error('Unsupported element type');
|
|
119
|
-
};
|
|
120
|
-
const getElementLabel = (element) => {
|
|
121
|
-
if (element.type === 'solid') {
|
|
122
|
-
return '<Solid>';
|
|
123
|
-
}
|
|
124
|
-
if (element.type === 'svg') {
|
|
125
|
-
return '<Interactive.Svg>';
|
|
126
|
-
}
|
|
127
|
-
if (element.type === 'asset') {
|
|
128
|
-
if (element.assetType === 'image') {
|
|
129
|
-
return '<CanvasImage>';
|
|
130
|
-
}
|
|
131
|
-
if (element.assetType === 'video') {
|
|
132
|
-
return '<Video>';
|
|
133
|
-
}
|
|
134
|
-
if (element.assetType === 'gif') {
|
|
135
|
-
return '<Gif>';
|
|
136
|
-
}
|
|
137
|
-
if (element.assetType === 'animated-image') {
|
|
138
|
-
return '<AnimatedImage>';
|
|
139
|
-
}
|
|
140
|
-
if (element.assetType === 'audio') {
|
|
141
|
-
return '<Audio>';
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (element.type === 'component') {
|
|
145
|
-
return `<${element.componentName}>`;
|
|
146
|
-
}
|
|
147
|
-
if (element.type === 'composition') {
|
|
148
|
-
return `composition "${element.compositionId}"`;
|
|
149
|
-
}
|
|
150
|
-
throw new Error('Unsupported element type');
|
|
151
|
-
};
|
|
152
|
-
const insertJsxElementHandler = ({ input: { compositionFile, compositionId, element, from }, remotionRoot, logLevel, }) => (0, source_file_write_queue_1.withSourceFileWriteQueue)(async () => {
|
|
153
|
-
try {
|
|
154
|
-
validateElement(element, remotionRoot);
|
|
155
|
-
if (from !== null &&
|
|
156
|
-
(!Number.isInteger(from) || !Number.isFinite(from) || from < 0)) {
|
|
157
|
-
throw new Error('from must be a non-negative integer');
|
|
158
|
-
}
|
|
159
|
-
const elementLabel = getElementLabel(element);
|
|
160
|
-
renderer_1.RenderInternals.Log.trace({ indent: false, logLevel }, `[insert-jsx-element] Received request for compositionFile="${compositionFile}" compositionId="${compositionId}" element="${element.type}"`);
|
|
161
|
-
const { fileName, source, oldContents, output, insertedNodePath, logLine, nodePathRemappings, } = await (0, resolve_composition_component_1.insertJsxElementIntoComposition)({
|
|
162
|
-
remotionRoot,
|
|
163
|
-
compositionFile,
|
|
164
|
-
compositionId,
|
|
165
|
-
element,
|
|
166
|
-
from,
|
|
167
|
-
prettierConfigOverride: null,
|
|
168
|
-
sourceFileOverrides: null,
|
|
169
|
-
});
|
|
170
|
-
const nodePathMutation = (0, sequence_node_path_mutation_1.broadcastSequenceNodePathMutation)([
|
|
171
|
-
{
|
|
172
|
-
absolutePath: fileName,
|
|
173
|
-
remappings: nodePathRemappings,
|
|
174
|
-
},
|
|
175
|
-
], insertedNodePath === null
|
|
176
|
-
? null
|
|
177
|
-
: {
|
|
178
|
-
absolutePath: fileName,
|
|
179
|
-
compositionId,
|
|
180
|
-
nodePath: insertedNodePath,
|
|
181
|
-
});
|
|
182
|
-
if (insertedNodePath === null) {
|
|
183
|
-
renderer_1.RenderInternals.Log.warn({ indent: false, logLevel }, 'Could not determine the inserted JSX element node path. Skipping automatic selection.');
|
|
184
|
-
}
|
|
185
|
-
(0, undo_stack_1.pushToUndoStack)({
|
|
186
|
-
filePath: fileName,
|
|
187
|
-
oldContents,
|
|
188
|
-
newContents: output,
|
|
189
|
-
logLevel,
|
|
190
|
-
remotionRoot,
|
|
191
|
-
logLine,
|
|
192
|
-
description: {
|
|
193
|
-
undoMessage: `↩️ Added ${elementLabel}`,
|
|
194
|
-
redoMessage: `↪️ Added ${elementLabel}`,
|
|
195
|
-
},
|
|
196
|
-
entryType: 'insert-jsx-element',
|
|
197
|
-
suppressHmrOnFileRestore: false,
|
|
198
|
-
nodePathRemappings,
|
|
199
|
-
});
|
|
200
|
-
(0, undo_stack_1.suppressUndoStackInvalidation)(fileName);
|
|
201
|
-
(0, file_watcher_1.writeFileAndNotifyFileWatchers)({
|
|
202
|
-
file: fileName,
|
|
203
|
-
content: output,
|
|
204
|
-
originatorClientId: undefined,
|
|
205
|
-
metadata: { skipSequencePropsUpdate: true },
|
|
206
|
-
});
|
|
207
|
-
const locationLabel = (0, format_log_file_location_1.formatLogFileLocation)({
|
|
208
|
-
remotionRoot,
|
|
209
|
-
absolutePath: fileName,
|
|
210
|
-
line: logLine,
|
|
211
|
-
});
|
|
212
|
-
renderer_1.RenderInternals.Log.info({ indent: false, logLevel }, `${(0, source_file_write_queue_1.getCodemodTimingPrefix)(logLevel)}${renderer_1.RenderInternals.chalk.blueBright(`${locationLabel}`)} Added ${elementLabel}`);
|
|
213
|
-
renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel }, `[insert-jsx-element] Wrote ${source}`);
|
|
214
|
-
(0, undo_stack_1.printUndoHint)(logLevel);
|
|
215
|
-
return {
|
|
216
|
-
success: true,
|
|
217
|
-
insertedNodePath: insertedNodePath === null
|
|
218
|
-
? null
|
|
219
|
-
: { absolutePath: fileName, nodePath: insertedNodePath },
|
|
220
|
-
nodePathMutation,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
catch (err) {
|
|
224
|
-
return {
|
|
225
|
-
success: false,
|
|
226
|
-
reason: err.message,
|
|
227
|
-
stack: err.stack,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
exports.insertJsxElementHandler = insertJsxElementHandler;
|