@remotion/studio-server 4.0.469 → 4.0.471
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/add-effect.d.ts +15 -0
- package/dist/codemods/add-effect.js +231 -0
- package/dist/codemods/delete-effect.d.ts +18 -0
- package/dist/codemods/delete-effect.js +95 -21
- package/dist/codemods/delete-jsx-node.d.ts +10 -0
- package/dist/codemods/delete-jsx-node.js +38 -14
- package/dist/codemods/reorder-effect.d.ts +13 -0
- package/dist/codemods/reorder-effect.js +61 -0
- package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.d.ts +4 -0
- package/dist/codemods/update-keyframes/ensure-imports-and-frame-hook.js +152 -0
- package/dist/codemods/update-keyframes/update-keyframes.d.ts +12 -0
- package/dist/codemods/update-keyframes/update-keyframes.js +116 -31
- package/dist/codemods/update-sequence-props/update-sequence-props.d.ts +32 -10
- package/dist/codemods/update-sequence-props/update-sequence-props.js +39 -7
- package/dist/helpers/open-in-editor.d.ts +2 -2
- package/dist/helpers/open-in-editor.js +35 -2
- package/dist/helpers/resolve-composition-component.d.ts +15 -0
- package/dist/helpers/resolve-composition-component.js +269 -31
- package/dist/index.d.ts +2 -1
- package/dist/preview-server/api-routes.js +20 -0
- package/dist/preview-server/routes/add-effect-keyframe.d.ts +3 -0
- package/dist/preview-server/routes/add-effect-keyframe.js +91 -0
- package/dist/preview-server/routes/add-effect.d.ts +3 -0
- package/dist/preview-server/routes/add-effect.js +68 -0
- package/dist/preview-server/routes/add-sequence-keyframe.d.ts +3 -0
- package/dist/preview-server/routes/add-sequence-keyframe.js +87 -0
- package/dist/preview-server/routes/apply-codemod.js +1 -0
- package/dist/preview-server/routes/apply-visual-control-change.js +1 -0
- package/dist/preview-server/routes/can-update-sequence-props.d.ts +1 -0
- package/dist/preview-server/routes/can-update-sequence-props.js +48 -14
- package/dist/preview-server/routes/composition-component-info.d.ts +3 -0
- package/dist/preview-server/routes/composition-component-info.js +26 -0
- package/dist/preview-server/routes/delete-effect-keyframe.d.ts +3 -0
- package/dist/preview-server/routes/delete-effect-keyframe.js +89 -0
- package/dist/preview-server/routes/delete-effect.js +76 -37
- package/dist/preview-server/routes/delete-jsx-node.js +67 -36
- package/dist/preview-server/routes/delete-keyframes.d.ts +13 -0
- package/dist/preview-server/routes/delete-keyframes.js +263 -0
- package/dist/preview-server/routes/delete-sequence-keyframe.d.ts +3 -0
- package/dist/preview-server/routes/delete-sequence-keyframe.js +82 -0
- package/dist/preview-server/routes/duplicate-jsx-node.js +1 -0
- package/dist/preview-server/routes/insert-jsx-element.d.ts +3 -0
- package/dist/preview-server/routes/insert-jsx-element.js +79 -0
- package/dist/preview-server/routes/open-in-editor.d.ts +4 -0
- package/dist/preview-server/routes/open-in-editor.js +40 -0
- package/dist/preview-server/routes/register-client-render.d.ts +3 -0
- package/dist/preview-server/routes/register-client-render.js +11 -0
- package/dist/preview-server/routes/reorder-effect.d.ts +3 -0
- package/dist/preview-server/routes/reorder-effect.js +67 -0
- package/dist/preview-server/routes/save-effect-props.js +1 -0
- package/dist/preview-server/routes/save-sequence-props.js +158 -72
- package/dist/preview-server/routes/subscribe-to-sequence-props.js +2 -1
- package/dist/preview-server/routes/unregister-client-render.d.ts +4 -0
- package/dist/preview-server/routes/unregister-client-render.js +11 -0
- package/dist/preview-server/routes/update-default-props.js +1 -0
- package/dist/preview-server/sequence-props-watchers.d.ts +2 -1
- package/dist/preview-server/sequence-props-watchers.js +22 -2
- package/dist/preview-server/start-server.d.ts +1 -0
- package/dist/preview-server/start-server.js +1 -0
- package/dist/preview-server/undo-stack.d.ts +35 -4
- package/dist/preview-server/undo-stack.js +130 -42
- package/dist/preview-server/validate-same-origin.d.ts +2 -0
- package/dist/preview-server/validate-same-origin.js +13 -0
- package/dist/routes.d.ts +2 -1
- package/dist/routes.js +9 -136
- package/dist/start-studio.d.ts +2 -1
- package/dist/start-studio.js +2 -1
- package/package.json +6 -6
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SequenceNodePath } from 'remotion';
|
|
2
|
+
export declare const addEffect: ({ input, sequenceNodePath, effectName, effectImportPath, effectConfig, prettierConfigOverride, }: {
|
|
3
|
+
input: string;
|
|
4
|
+
sequenceNodePath: SequenceNodePath;
|
|
5
|
+
effectName: string;
|
|
6
|
+
effectImportPath: string;
|
|
7
|
+
effectConfig: Record<string, unknown>;
|
|
8
|
+
prettierConfigOverride?: Record<string, unknown> | null | undefined;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
output: string;
|
|
11
|
+
formatted: boolean;
|
|
12
|
+
effectLabel: string;
|
|
13
|
+
nodeLabel: string;
|
|
14
|
+
logLine: number;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.addEffect = void 0;
|
|
37
|
+
const studio_shared_1 = require("@remotion/studio-shared");
|
|
38
|
+
const recast = __importStar(require("recast"));
|
|
39
|
+
const can_update_sequence_props_1 = require("../preview-server/routes/can-update-sequence-props");
|
|
40
|
+
const format_file_content_1 = require("./format-file-content");
|
|
41
|
+
const parse_ast_1 = require("./parse-ast");
|
|
42
|
+
const update_effect_props_1 = require("./update-effect-props/update-effect-props");
|
|
43
|
+
const b = recast.types.builders;
|
|
44
|
+
const identifierRegex = /^[A-Za-z_$][0-9A-Za-z_$]*$/;
|
|
45
|
+
const assertValidEffect = ({ effectName, effectImportPath, }) => {
|
|
46
|
+
if (!identifierRegex.test(effectName)) {
|
|
47
|
+
throw new Error(`Invalid effect name "${effectName}"`);
|
|
48
|
+
}
|
|
49
|
+
const allowedImport = effectImportPath.startsWith('@remotion/effects/') ||
|
|
50
|
+
effectImportPath === '@remotion/light-leaks' ||
|
|
51
|
+
effectImportPath === '@remotion/starburst';
|
|
52
|
+
if (!allowedImport) {
|
|
53
|
+
throw new Error(`Unsupported effect import "${effectImportPath}"`);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const parseValueExpression = (value) => {
|
|
57
|
+
const code = `a = ${(0, studio_shared_1.stringifyDefaultProps)({ props: value, enumPaths: [] })}`;
|
|
58
|
+
const ast = (0, parse_ast_1.parseAst)(code);
|
|
59
|
+
const stmt = ast.program.body[0];
|
|
60
|
+
if (stmt.type !== 'ExpressionStatement' ||
|
|
61
|
+
stmt.expression.type !== 'AssignmentExpression') {
|
|
62
|
+
throw new Error('Failed to parse effect config value');
|
|
63
|
+
}
|
|
64
|
+
return stmt.expression.right;
|
|
65
|
+
};
|
|
66
|
+
const getImportedName = (specifier) => {
|
|
67
|
+
if (specifier.imported.type === 'Identifier') {
|
|
68
|
+
return specifier.imported.name;
|
|
69
|
+
}
|
|
70
|
+
return specifier.imported.value;
|
|
71
|
+
};
|
|
72
|
+
const declarationBindsName = (declaration, name) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (declaration.type === 'ClassDeclaration') {
|
|
75
|
+
return ((_a = declaration.id) === null || _a === void 0 ? void 0 : _a.name) === name;
|
|
76
|
+
}
|
|
77
|
+
if (declaration.type === 'FunctionDeclaration') {
|
|
78
|
+
return ((_b = declaration.id) === null || _b === void 0 ? void 0 : _b.name) === name;
|
|
79
|
+
}
|
|
80
|
+
return declaration.declarations.some((variableDeclaration) => {
|
|
81
|
+
return (variableDeclaration.id.type === 'Identifier' &&
|
|
82
|
+
variableDeclaration.id.name === name);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const hasTopLevelBinding = ({ ast, name }) => {
|
|
86
|
+
return ast.program.body.some((node) => {
|
|
87
|
+
var _a;
|
|
88
|
+
if (node.type === 'FunctionDeclaration' ||
|
|
89
|
+
node.type === 'ClassDeclaration' ||
|
|
90
|
+
node.type === 'VariableDeclaration') {
|
|
91
|
+
return declarationBindsName(node, name);
|
|
92
|
+
}
|
|
93
|
+
if (node.type === 'ExportNamedDeclaration' &&
|
|
94
|
+
node.declaration &&
|
|
95
|
+
(node.declaration.type === 'FunctionDeclaration' ||
|
|
96
|
+
node.declaration.type === 'ClassDeclaration' ||
|
|
97
|
+
node.declaration.type === 'VariableDeclaration')) {
|
|
98
|
+
return declarationBindsName(node.declaration, name);
|
|
99
|
+
}
|
|
100
|
+
if (node.type !== 'ImportDeclaration') {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return (_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.some((specifier) => {
|
|
104
|
+
var _a;
|
|
105
|
+
return ((_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) === name;
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const insertImportDeclaration = (ast, importDeclaration) => {
|
|
110
|
+
const { body } = ast.program;
|
|
111
|
+
let lastImportIndex = -1;
|
|
112
|
+
for (let i = 0; i < body.length; i++) {
|
|
113
|
+
if (body[i].type === 'ImportDeclaration') {
|
|
114
|
+
lastImportIndex = i;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
body.splice(lastImportIndex + 1, 0, importDeclaration);
|
|
118
|
+
};
|
|
119
|
+
const getAvailableLocalName = ({ ast, effectName, }) => {
|
|
120
|
+
if (!hasTopLevelBinding({ ast, name: effectName })) {
|
|
121
|
+
return effectName;
|
|
122
|
+
}
|
|
123
|
+
const base = `${effectName}Effect`;
|
|
124
|
+
if (!hasTopLevelBinding({ ast, name: base })) {
|
|
125
|
+
return base;
|
|
126
|
+
}
|
|
127
|
+
for (let i = 2; i < 100; i++) {
|
|
128
|
+
const candidate = `${base}${i}`;
|
|
129
|
+
if (!hasTopLevelBinding({ ast, name: candidate })) {
|
|
130
|
+
return candidate;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
throw new Error(`Cannot find a local name for ${effectName}`);
|
|
134
|
+
};
|
|
135
|
+
const ensureEffectImport = ({ ast, effectName, effectImportPath, }) => {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
var _d;
|
|
138
|
+
let importDeclaration = null;
|
|
139
|
+
for (const node of ast.program.body) {
|
|
140
|
+
if (node.type !== 'ImportDeclaration' ||
|
|
141
|
+
node.source.value !== effectImportPath) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
importDeclaration = node;
|
|
145
|
+
const matchingSpecifier = (_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find((importSpecifier) => {
|
|
146
|
+
return (importSpecifier.type === 'ImportSpecifier' &&
|
|
147
|
+
getImportedName(importSpecifier) === effectName);
|
|
148
|
+
});
|
|
149
|
+
if ((_b = matchingSpecifier === null || matchingSpecifier === void 0 ? void 0 : matchingSpecifier.local) === null || _b === void 0 ? void 0 : _b.name) {
|
|
150
|
+
return matchingSpecifier.local.name;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const localName = getAvailableLocalName({ ast, effectName });
|
|
154
|
+
const imported = b.identifier(effectName);
|
|
155
|
+
const local = localName === effectName ? null : b.identifier(localName);
|
|
156
|
+
const specifier = b.importSpecifier(imported, local);
|
|
157
|
+
if (importDeclaration &&
|
|
158
|
+
!((_c = importDeclaration.specifiers) === null || _c === void 0 ? void 0 : _c.some((importSpecifier) => importSpecifier.type === 'ImportNamespaceSpecifier'))) {
|
|
159
|
+
importDeclaration.specifiers = [
|
|
160
|
+
...((_d = importDeclaration.specifiers) !== null && _d !== void 0 ? _d : []),
|
|
161
|
+
specifier,
|
|
162
|
+
];
|
|
163
|
+
return localName;
|
|
164
|
+
}
|
|
165
|
+
const newImport = b.importDeclaration([], b.stringLiteral(effectImportPath));
|
|
166
|
+
newImport.specifiers = [specifier];
|
|
167
|
+
insertImportDeclaration(ast, newImport);
|
|
168
|
+
return localName;
|
|
169
|
+
};
|
|
170
|
+
const getEffectsArray = (attr) => {
|
|
171
|
+
if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
|
|
172
|
+
throw new Error('Cannot add effect: effects prop is not an array');
|
|
173
|
+
}
|
|
174
|
+
const expr = attr.value.expression;
|
|
175
|
+
if (expr.type !== 'ArrayExpression') {
|
|
176
|
+
throw new Error('Cannot add effect: effects prop is not an array');
|
|
177
|
+
}
|
|
178
|
+
return expr;
|
|
179
|
+
};
|
|
180
|
+
const makeEffectsAttr = (array) => {
|
|
181
|
+
return b.jsxAttribute(b.jsxIdentifier('effects'), b.jsxExpressionContainer(array));
|
|
182
|
+
};
|
|
183
|
+
const makeConfigObjectExpression = (config) => {
|
|
184
|
+
return b.objectExpression(Object.entries(config).map(([key, value]) => {
|
|
185
|
+
const keyNode = identifierRegex.test(key)
|
|
186
|
+
? b.identifier(key)
|
|
187
|
+
: b.stringLiteral(key);
|
|
188
|
+
return b.objectProperty(keyNode, parseValueExpression(value));
|
|
189
|
+
}));
|
|
190
|
+
};
|
|
191
|
+
const getJsxTagLabel = (name) => {
|
|
192
|
+
if (name.type === 'JSXIdentifier') {
|
|
193
|
+
return `<${name.name}>`;
|
|
194
|
+
}
|
|
195
|
+
return 'element';
|
|
196
|
+
};
|
|
197
|
+
const addEffect = async ({ input, sequenceNodePath, effectName, effectImportPath, effectConfig, prettierConfigOverride, }) => {
|
|
198
|
+
var _a;
|
|
199
|
+
var _b, _c;
|
|
200
|
+
assertValidEffect({ effectName, effectImportPath });
|
|
201
|
+
const ast = (0, parse_ast_1.parseAst)(input);
|
|
202
|
+
const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
|
|
203
|
+
if (!jsx) {
|
|
204
|
+
throw new Error('Could not find a JSX element at the specified location to add effect');
|
|
205
|
+
}
|
|
206
|
+
const localName = ensureEffectImport({ ast, effectName, effectImportPath });
|
|
207
|
+
const effectCall = b.callExpression(b.identifier(localName), [
|
|
208
|
+
makeConfigObjectExpression(effectConfig),
|
|
209
|
+
]);
|
|
210
|
+
const attr = (0, update_effect_props_1.findEffectsAttr)((_b = jsx.attributes) !== null && _b !== void 0 ? _b : []);
|
|
211
|
+
if (attr) {
|
|
212
|
+
getEffectsArray(attr).elements.push(effectCall);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const effectsArray = b.arrayExpression([effectCall]);
|
|
216
|
+
jsx.attributes.push(makeEffectsAttr(effectsArray));
|
|
217
|
+
}
|
|
218
|
+
const finalFile = (0, parse_ast_1.serializeAst)(ast);
|
|
219
|
+
const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
|
|
220
|
+
input: finalFile,
|
|
221
|
+
prettierConfigOverride,
|
|
222
|
+
});
|
|
223
|
+
return {
|
|
224
|
+
output,
|
|
225
|
+
formatted,
|
|
226
|
+
effectLabel: `${effectName}()`,
|
|
227
|
+
nodeLabel: getJsxTagLabel(jsx.name),
|
|
228
|
+
logLine: (_c = (_a = jsx.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _c !== void 0 ? _c : 1,
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
exports.addEffect = addEffect;
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import type { SequenceNodePath } from 'remotion';
|
|
2
|
+
export type EffectDeletionTarget = {
|
|
3
|
+
sequenceNodePath: SequenceNodePath;
|
|
4
|
+
} & ({
|
|
5
|
+
type: 'single-effect';
|
|
6
|
+
effectIndex: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'all-effects';
|
|
9
|
+
});
|
|
10
|
+
export declare const deleteEffects: ({ input, effects, prettierConfigOverride, }: {
|
|
11
|
+
input: string;
|
|
12
|
+
effects: EffectDeletionTarget[];
|
|
13
|
+
prettierConfigOverride?: Record<string, unknown> | null | undefined;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
output: string;
|
|
16
|
+
formatted: boolean;
|
|
17
|
+
effectLabels: string[];
|
|
18
|
+
logLines: number[];
|
|
19
|
+
}>;
|
|
2
20
|
export declare const deleteEffect: ({ input, sequenceNodePath, effectIndex, prettierConfigOverride, }: {
|
|
3
21
|
input: string;
|
|
4
22
|
sequenceNodePath: SequenceNodePath;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteEffect = void 0;
|
|
3
|
+
exports.deleteEffect = exports.deleteEffects = void 0;
|
|
4
4
|
const can_update_sequence_props_1 = require("../preview-server/routes/can-update-sequence-props");
|
|
5
5
|
const format_file_content_1 = require("./format-file-content");
|
|
6
6
|
const parse_ast_1 = require("./parse-ast");
|
|
@@ -15,28 +15,88 @@ const getEffectsArray = (attr) => {
|
|
|
15
15
|
}
|
|
16
16
|
return expr;
|
|
17
17
|
};
|
|
18
|
-
const
|
|
18
|
+
const getAllEffectLabels = (effectsArray, attr) => {
|
|
19
|
+
if (effectsArray.elements.length === 0) {
|
|
20
|
+
throw new Error('Cannot delete effect: no effects found');
|
|
21
|
+
}
|
|
22
|
+
const elements = (0, update_effect_props_1.enumerateEffectArrayElements)(effectsArray);
|
|
23
|
+
return {
|
|
24
|
+
effectLabels: elements.map((effect) => effect.kind === 'call' ? `${effect.callee}()` : 'effect'),
|
|
25
|
+
logLines: elements.map((effect) => {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
var _d, _e, _f;
|
|
28
|
+
return effect.kind === 'call'
|
|
29
|
+
? ((_e = (_d = (_a = effect.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _d !== void 0 ? _d : (_b = attr.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _e !== void 0 ? _e : 1)
|
|
30
|
+
: ((_f = (_c = attr.loc) === null || _c === void 0 ? void 0 : _c.start.line) !== null && _f !== void 0 ? _f : 1);
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const deleteEffects = async ({ input, effects, prettierConfigOverride, }) => {
|
|
19
35
|
var _a, _b;
|
|
20
36
|
var _c, _d, _e;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!jsx) {
|
|
24
|
-
throw new Error('Could not find a JSX element at the specified location to delete effect');
|
|
37
|
+
if (effects.length === 0) {
|
|
38
|
+
throw new Error('No effects were specified for deletion');
|
|
25
39
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
const ast = (0, parse_ast_1.parseAst)(input);
|
|
41
|
+
const deletionsByAttr = new Map();
|
|
42
|
+
for (const effect of effects) {
|
|
43
|
+
const { sequenceNodePath } = effect;
|
|
44
|
+
const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
|
|
45
|
+
if (!jsx) {
|
|
46
|
+
throw new Error('Could not find a JSX element at the specified location to delete effect');
|
|
47
|
+
}
|
|
48
|
+
const attr = (0, update_effect_props_1.findEffectsAttr)((_c = jsx.attributes) !== null && _c !== void 0 ? _c : []);
|
|
49
|
+
if (!attr) {
|
|
50
|
+
throw new Error('Could not find effects on the target JSX element');
|
|
51
|
+
}
|
|
52
|
+
const effectsArray = getEffectsArray(attr);
|
|
53
|
+
const existingDeletion = deletionsByAttr.get(attr);
|
|
54
|
+
const deletion = existingDeletion !== null && existingDeletion !== void 0 ? existingDeletion : {
|
|
55
|
+
jsxAttributes: jsx.attributes,
|
|
56
|
+
attr,
|
|
57
|
+
effectsArray,
|
|
58
|
+
allEffects: false,
|
|
59
|
+
effectIndices: new Set(),
|
|
60
|
+
effectLabels: [],
|
|
61
|
+
logLines: [],
|
|
62
|
+
};
|
|
63
|
+
deletionsByAttr.set(attr, deletion);
|
|
64
|
+
if (effect.type === 'all-effects') {
|
|
65
|
+
const { effectLabels, logLines } = getAllEffectLabels(effectsArray, attr);
|
|
66
|
+
deletion.allEffects = true;
|
|
67
|
+
deletion.effectIndices.clear();
|
|
68
|
+
deletion.effectLabels = effectLabels;
|
|
69
|
+
deletion.logLines = logLines;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const { effectIndex } = effect;
|
|
73
|
+
if (deletion.allEffects || deletion.effectIndices.has(effectIndex)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const found = (0, update_effect_props_1.findEffectCallExpression)({ attr, effectIndex });
|
|
77
|
+
if (found.kind === 'error') {
|
|
78
|
+
throw new Error(`Cannot delete effect: ${found.reason}`);
|
|
79
|
+
}
|
|
80
|
+
deletion.effectIndices.add(effectIndex);
|
|
81
|
+
deletion.effectLabels.push(`${found.callee}()`);
|
|
82
|
+
deletion.logLines.push((_e = (_d = (_a = found.call.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _d !== void 0 ? _d : (_b = jsx.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _e !== void 0 ? _e : 1);
|
|
34
83
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
84
|
+
for (const deletion of deletionsByAttr.values()) {
|
|
85
|
+
if (deletion.allEffects) {
|
|
86
|
+
const attrIndex = deletion.jsxAttributes.indexOf(deletion.attr);
|
|
87
|
+
if (attrIndex !== -1) {
|
|
88
|
+
deletion.jsxAttributes.splice(attrIndex, 1);
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
for (const effectIndex of [...deletion.effectIndices].sort((a, b) => b - a)) {
|
|
93
|
+
deletion.effectsArray.elements.splice(effectIndex, 1);
|
|
94
|
+
}
|
|
95
|
+
if (deletion.effectsArray.elements.length === 0) {
|
|
96
|
+
const attrIndex = deletion.jsxAttributes.indexOf(deletion.attr);
|
|
97
|
+
if (attrIndex !== -1) {
|
|
98
|
+
deletion.jsxAttributes.splice(attrIndex, 1);
|
|
99
|
+
}
|
|
40
100
|
}
|
|
41
101
|
}
|
|
42
102
|
const finalFile = (0, parse_ast_1.serializeAst)(ast);
|
|
@@ -47,8 +107,22 @@ const deleteEffect = async ({ input, sequenceNodePath, effectIndex, prettierConf
|
|
|
47
107
|
return {
|
|
48
108
|
output,
|
|
49
109
|
formatted,
|
|
50
|
-
|
|
51
|
-
|
|
110
|
+
effectLabels: [...deletionsByAttr.values()].flatMap((deletion) => deletion.effectLabels),
|
|
111
|
+
logLines: [...deletionsByAttr.values()].flatMap((deletion) => deletion.logLines),
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
exports.deleteEffects = deleteEffects;
|
|
115
|
+
const deleteEffect = async ({ input, sequenceNodePath, effectIndex, prettierConfigOverride, }) => {
|
|
116
|
+
const { output, formatted, effectLabels, logLines } = await (0, exports.deleteEffects)({
|
|
117
|
+
input,
|
|
118
|
+
effects: [{ type: 'single-effect', sequenceNodePath, effectIndex }],
|
|
119
|
+
prettierConfigOverride,
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
output,
|
|
123
|
+
formatted,
|
|
124
|
+
effectLabel: effectLabels[0],
|
|
125
|
+
logLine: logLines[0],
|
|
52
126
|
};
|
|
53
127
|
};
|
|
54
128
|
exports.deleteEffect = deleteEffect;
|
|
@@ -4,6 +4,16 @@ import type { SequenceNodePath } from 'remotion';
|
|
|
4
4
|
export declare const getJsxElementTagLabel: (element: JSXElement) => string;
|
|
5
5
|
export declare const findJsxElementPathForDeletion: (ast: File, nodePath: SequenceNodePath) => import("ast-types/lib/node-path").NodePath<N, V> | null;
|
|
6
6
|
export declare const deleteJsxElementAtPath: (jsxPath: import("ast-types/lib/node-path").NodePath<N, V>) => void;
|
|
7
|
+
export declare const deleteJsxNodes: ({ input, nodePaths, prettierConfigOverride, }: {
|
|
8
|
+
input: string;
|
|
9
|
+
nodePaths: SequenceNodePath[];
|
|
10
|
+
prettierConfigOverride?: Record<string, unknown> | null | undefined;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
output: string;
|
|
13
|
+
formatted: boolean;
|
|
14
|
+
nodeLabels: string[];
|
|
15
|
+
logLines: number[];
|
|
16
|
+
}>;
|
|
7
17
|
export declare const deleteJsxNode: ({ input, nodePath, prettierConfigOverride, }: {
|
|
8
18
|
input: string;
|
|
9
19
|
nodePath: SequenceNodePath;
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.deleteJsxNode = exports.deleteJsxElementAtPath = exports.findJsxElementPathForDeletion = exports.getJsxElementTagLabel = void 0;
|
|
36
|
+
exports.deleteJsxNode = exports.deleteJsxNodes = exports.deleteJsxElementAtPath = exports.findJsxElementPathForDeletion = exports.getJsxElementTagLabel = void 0;
|
|
37
37
|
const recast = __importStar(require("recast"));
|
|
38
38
|
const get_ast_node_path_1 = require("../helpers/get-ast-node-path");
|
|
39
39
|
const format_file_content_1 = require("./format-file-content");
|
|
@@ -287,18 +287,28 @@ const deleteJsxElementAtPath = (jsxPath) => {
|
|
|
287
287
|
jsxPath.replace(b.nullLiteral());
|
|
288
288
|
};
|
|
289
289
|
exports.deleteJsxElementAtPath = deleteJsxElementAtPath;
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
290
|
+
const deleteJsxNodes = async ({ input, nodePaths, prettierConfigOverride, }) => {
|
|
291
|
+
if (nodePaths.length === 0) {
|
|
292
|
+
throw new Error('No JSX nodes were specified for deletion');
|
|
293
|
+
}
|
|
293
294
|
const ast = (0, parse_ast_1.parseAst)(input);
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
295
|
+
const pathsToDelete = nodePaths.map((nodePath) => {
|
|
296
|
+
var _a, _b;
|
|
297
|
+
var _c, _d;
|
|
298
|
+
const jsxPath = (0, exports.findJsxElementPathForDeletion)(ast, nodePath);
|
|
299
|
+
if (!jsxPath) {
|
|
300
|
+
throw new Error('Could not find a JSX element at the specified location to delete');
|
|
301
|
+
}
|
|
302
|
+
const jsxElement = jsxPath.node;
|
|
303
|
+
return {
|
|
304
|
+
jsxPath,
|
|
305
|
+
nodeLabel: (0, exports.getJsxElementTagLabel)(jsxElement),
|
|
306
|
+
logLine: (_d = (_c = (_a = jsxElement.openingElement.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _c !== void 0 ? _c : (_b = jsxElement.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _d !== void 0 ? _d : 1,
|
|
307
|
+
};
|
|
308
|
+
});
|
|
309
|
+
for (const { jsxPath } of pathsToDelete) {
|
|
310
|
+
(0, exports.deleteJsxElementAtPath)(jsxPath);
|
|
311
|
+
}
|
|
302
312
|
const finalFile = (0, parse_ast_1.serializeAst)(ast);
|
|
303
313
|
const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
|
|
304
314
|
input: finalFile,
|
|
@@ -307,8 +317,22 @@ const deleteJsxNode = async ({ input, nodePath, prettierConfigOverride, }) => {
|
|
|
307
317
|
return {
|
|
308
318
|
output,
|
|
309
319
|
formatted,
|
|
310
|
-
nodeLabel,
|
|
311
|
-
logLine,
|
|
320
|
+
nodeLabels: pathsToDelete.map(({ nodeLabel }) => nodeLabel),
|
|
321
|
+
logLines: pathsToDelete.map(({ logLine }) => logLine),
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
exports.deleteJsxNodes = deleteJsxNodes;
|
|
325
|
+
const deleteJsxNode = async ({ input, nodePath, prettierConfigOverride, }) => {
|
|
326
|
+
const { output, formatted, nodeLabels, logLines } = await (0, exports.deleteJsxNodes)({
|
|
327
|
+
input,
|
|
328
|
+
nodePaths: [nodePath],
|
|
329
|
+
prettierConfigOverride,
|
|
330
|
+
});
|
|
331
|
+
return {
|
|
332
|
+
output,
|
|
333
|
+
formatted,
|
|
334
|
+
nodeLabel: nodeLabels[0],
|
|
335
|
+
logLine: logLines[0],
|
|
312
336
|
};
|
|
313
337
|
};
|
|
314
338
|
exports.deleteJsxNode = deleteJsxNode;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SequenceNodePath } from 'remotion';
|
|
2
|
+
export declare const reorderEffect: ({ input, sequenceNodePath, fromIndex, toIndex, prettierConfigOverride, }: {
|
|
3
|
+
input: string;
|
|
4
|
+
sequenceNodePath: SequenceNodePath;
|
|
5
|
+
fromIndex: number;
|
|
6
|
+
toIndex: number;
|
|
7
|
+
prettierConfigOverride?: Record<string, unknown> | null | undefined;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
output: string;
|
|
10
|
+
formatted: boolean;
|
|
11
|
+
effectLabel: string;
|
|
12
|
+
logLine: number;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reorderEffect = void 0;
|
|
4
|
+
const can_update_sequence_props_1 = require("../preview-server/routes/can-update-sequence-props");
|
|
5
|
+
const format_file_content_1 = require("./format-file-content");
|
|
6
|
+
const parse_ast_1 = require("./parse-ast");
|
|
7
|
+
const update_effect_props_1 = require("./update-effect-props/update-effect-props");
|
|
8
|
+
const getEffectsArray = (attr) => {
|
|
9
|
+
if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
|
|
10
|
+
throw new Error('Cannot reorder effect: effects prop is not an array');
|
|
11
|
+
}
|
|
12
|
+
const expr = attr.value.expression;
|
|
13
|
+
if (expr.type !== 'ArrayExpression') {
|
|
14
|
+
throw new Error('Cannot reorder effect: effects prop is not an array');
|
|
15
|
+
}
|
|
16
|
+
return expr;
|
|
17
|
+
};
|
|
18
|
+
const reorderEffect = async ({ input, sequenceNodePath, fromIndex, toIndex, prettierConfigOverride, }) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
var _c, _d, _e;
|
|
21
|
+
const ast = (0, parse_ast_1.parseAst)(input);
|
|
22
|
+
const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
|
|
23
|
+
if (!jsx) {
|
|
24
|
+
throw new Error('Could not find a JSX element at the specified location to reorder effect');
|
|
25
|
+
}
|
|
26
|
+
const attr = (0, update_effect_props_1.findEffectsAttr)((_c = jsx.attributes) !== null && _c !== void 0 ? _c : []);
|
|
27
|
+
if (!attr) {
|
|
28
|
+
throw new Error('Could not find effects on the target JSX element');
|
|
29
|
+
}
|
|
30
|
+
const effectsArray = getEffectsArray(attr);
|
|
31
|
+
const elements = (0, update_effect_props_1.enumerateEffectArrayElements)(effectsArray);
|
|
32
|
+
if (fromIndex < 0 || fromIndex >= elements.length) {
|
|
33
|
+
throw new Error('Cannot reorder effect: source index not-found');
|
|
34
|
+
}
|
|
35
|
+
if (toIndex < 0 || toIndex >= elements.length) {
|
|
36
|
+
throw new Error('Cannot reorder effect: target index not-found');
|
|
37
|
+
}
|
|
38
|
+
const target = elements[fromIndex];
|
|
39
|
+
if (target.kind !== 'call') {
|
|
40
|
+
throw new Error('Cannot reorder effect: source effect is not-call-expression');
|
|
41
|
+
}
|
|
42
|
+
if (fromIndex !== toIndex) {
|
|
43
|
+
const [moved] = effectsArray.elements.splice(fromIndex, 1);
|
|
44
|
+
if (!moved) {
|
|
45
|
+
throw new Error('Cannot reorder effect: source effect is not-call-expression');
|
|
46
|
+
}
|
|
47
|
+
effectsArray.elements.splice(toIndex, 0, moved);
|
|
48
|
+
}
|
|
49
|
+
const finalFile = (0, parse_ast_1.serializeAst)(ast);
|
|
50
|
+
const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
|
|
51
|
+
input: finalFile,
|
|
52
|
+
prettierConfigOverride,
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
output,
|
|
56
|
+
formatted,
|
|
57
|
+
effectLabel: `${target.callee}()`,
|
|
58
|
+
logLine: (_e = (_d = (_a = target.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _d !== void 0 ? _d : (_b = jsx.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _e !== void 0 ? _e : 1,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.reorderEffect = reorderEffect;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { File } from '@babel/types';
|
|
2
|
+
export declare const findEnclosingFunctionPath: (path: import("ast-types/lib/node-path").NodePath<N, V>) => import("ast-types/lib/node-path").NodePath<N, V> | null;
|
|
3
|
+
export declare const ensureRemotionImports: (ast: File, names: ReadonlySet<string>) => void;
|
|
4
|
+
export declare const ensureUseCurrentFrameHook: (functionPath: import("ast-types/lib/node-path").NodePath<N, V>) => void;
|