@remotion/studio-server 4.0.460 → 4.0.462

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/codemods/update-effect-props/update-effect-props.d.ts +52 -0
  2. package/dist/codemods/update-effect-props/update-effect-props.js +229 -0
  3. package/dist/codemods/update-sequence-props/find-props-to-delete.d.ts +6 -0
  4. package/dist/codemods/update-sequence-props/find-props-to-delete.js +37 -0
  5. package/dist/codemods/update-sequence-props/update-sequence-props.d.ts +35 -0
  6. package/dist/codemods/update-sequence-props/update-sequence-props.js +224 -0
  7. package/dist/codemods/update-sequence-props.d.ts +7 -1
  8. package/dist/codemods/update-sequence-props.js +46 -3
  9. package/dist/index.d.ts +1 -2
  10. package/dist/preview-server/api-routes.js +2 -0
  11. package/dist/preview-server/routes/apply-visual-control-change.js +4 -4
  12. package/dist/preview-server/routes/can-update-effect-props.d.ts +20 -0
  13. package/dist/preview-server/routes/can-update-effect-props.js +146 -0
  14. package/dist/preview-server/routes/can-update-sequence-props.d.ts +26 -6
  15. package/dist/preview-server/routes/can-update-sequence-props.js +82 -35
  16. package/dist/preview-server/routes/delete-jsx-node.js +4 -4
  17. package/dist/preview-server/routes/duplicate-jsx-node.js +4 -4
  18. package/dist/preview-server/routes/log-update.d.ts +13 -2
  19. package/dist/preview-server/routes/log-update.js +56 -30
  20. package/dist/preview-server/routes/log-updates/format-effect-prop-change.d.ts +10 -0
  21. package/dist/preview-server/routes/log-updates/format-effect-prop-change.js +51 -0
  22. package/dist/preview-server/routes/log-updates/format-prop-change.d.ts +9 -0
  23. package/dist/preview-server/routes/log-updates/format-prop-change.js +29 -0
  24. package/dist/preview-server/routes/log-updates/format-side-prop.d.ts +0 -0
  25. package/dist/preview-server/routes/log-updates/format-side-prop.js +1 -0
  26. package/dist/preview-server/routes/log-updates/format-side-props.d.ts +5 -0
  27. package/dist/preview-server/routes/log-updates/format-side-props.js +18 -0
  28. package/dist/preview-server/routes/log-updates/formatting.d.ts +19 -0
  29. package/dist/preview-server/routes/log-updates/formatting.js +67 -0
  30. package/dist/preview-server/routes/log-updates/log-effect-update.d.ts +14 -0
  31. package/dist/preview-server/routes/log-updates/log-effect-update.js +23 -0
  32. package/dist/preview-server/routes/log-updates/log-update.d.ts +15 -0
  33. package/dist/preview-server/routes/log-updates/log-update.js +39 -0
  34. package/dist/preview-server/routes/save-effect-props.d.ts +3 -0
  35. package/dist/preview-server/routes/save-effect-props.js +107 -0
  36. package/dist/preview-server/routes/save-sequence-props.js +82 -87
  37. package/dist/preview-server/routes/subscribe-to-sequence-props.js +4 -3
  38. package/dist/preview-server/routes/unsubscribe-from-sequence-props.js +4 -2
  39. package/dist/preview-server/routes/update-default-props.js +4 -4
  40. package/dist/preview-server/sequence-props-watchers.d.ts +9 -4
  41. package/dist/preview-server/sequence-props-watchers.js +54 -24
  42. package/dist/preview-server/start-server.d.ts +0 -1
  43. package/dist/preview-server/start-server.js +0 -1
  44. package/dist/preview-server/undo-stack.d.ts +3 -1
  45. package/dist/preview-server/undo-stack.js +1 -1
  46. package/dist/routes.js +0 -14
  47. package/dist/start-studio.d.ts +1 -2
  48. package/dist/start-studio.js +1 -2
  49. package/package.json +8 -10
  50. package/dist/codemods/jsx-sequence-context.d.ts +0 -11
  51. package/dist/codemods/jsx-sequence-context.js +0 -68
@@ -0,0 +1,52 @@
1
+ import type { ArrayExpression, CallExpression, JSXAttribute } from '@babel/types';
2
+ import type { SequenceNodePath } from 'remotion';
3
+ export type EffectPropUpdate = {
4
+ key: string;
5
+ value: unknown;
6
+ defaultValue: unknown | null;
7
+ };
8
+ export type UpdateEffectPropsResult = {
9
+ output: string;
10
+ formatted: boolean;
11
+ oldValueString: string;
12
+ logLine: number;
13
+ effectCallee: string;
14
+ };
15
+ export type EffectArrayElement = {
16
+ kind: 'call';
17
+ callee: string;
18
+ node: CallExpression;
19
+ } | {
20
+ kind: 'unsupported';
21
+ reason: 'not-call-expression' | 'spread';
22
+ };
23
+ export declare const enumerateEffectArrayElements: (arr: ArrayExpression) => EffectArrayElement[];
24
+ export declare const findEffectCallExpression: ({ attr, effectIndex, }: {
25
+ attr: JSXAttribute;
26
+ effectIndex: number;
27
+ }) => {
28
+ kind: "ok";
29
+ call: CallExpression;
30
+ callee: string;
31
+ } | {
32
+ kind: "error";
33
+ reason: "not-call-expression" | "not-found";
34
+ };
35
+ export declare const updateEffectPropsAst: ({ input, sequenceNodePath, effectIndex, update, }: {
36
+ input: string;
37
+ sequenceNodePath: SequenceNodePath;
38
+ effectIndex: number;
39
+ update: EffectPropUpdate;
40
+ }) => {
41
+ serialized: string;
42
+ oldValueString: string;
43
+ logLine: number;
44
+ effectCallee: string;
45
+ };
46
+ export declare const updateEffectProps: ({ input, sequenceNodePath, effectIndex, update, prettierConfigOverride, }: {
47
+ input: string;
48
+ sequenceNodePath: SequenceNodePath;
49
+ effectIndex: number;
50
+ update: EffectPropUpdate;
51
+ prettierConfigOverride?: Record<string, unknown> | null | undefined;
52
+ }) => Promise<UpdateEffectPropsResult>;
@@ -0,0 +1,229 @@
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.updateEffectProps = exports.updateEffectPropsAst = exports.findEffectCallExpression = exports.enumerateEffectArrayElements = 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 b = recast.types.builders;
43
+ const parseValueExpression = (value) => {
44
+ const code = `a = ${(0, studio_shared_1.stringifyDefaultProps)({ props: value, enumPaths: [] })}`;
45
+ const ast = (0, parse_ast_1.parseAst)(code);
46
+ const stmt = ast.program.body[0];
47
+ if (stmt.type !== 'ExpressionStatement' ||
48
+ stmt.expression.type !== 'AssignmentExpression') {
49
+ throw new Error('Failed to parse effect prop value expression');
50
+ }
51
+ return stmt.expression.right;
52
+ };
53
+ const findExperimentalEffectsAttr = (attrs) => {
54
+ for (const attr of attrs) {
55
+ if (attr.type !== 'JSXAttribute') {
56
+ continue;
57
+ }
58
+ const a = attr;
59
+ if (a.name.type === 'JSXIdentifier' &&
60
+ a.name.name === '_experimentalEffects') {
61
+ return a;
62
+ }
63
+ }
64
+ return null;
65
+ };
66
+ const getCalleeName = (call) => {
67
+ const { callee } = call;
68
+ if (callee.type === 'Identifier') {
69
+ return callee.name;
70
+ }
71
+ if (callee.type === 'MemberExpression' &&
72
+ !callee.computed &&
73
+ callee.property.type === 'Identifier') {
74
+ return callee.property.name;
75
+ }
76
+ return null;
77
+ };
78
+ const enumerateEffectArrayElements = (arr) => {
79
+ const out = [];
80
+ for (const el of arr.elements) {
81
+ if (el === null) {
82
+ out.push({ kind: 'unsupported', reason: 'not-call-expression' });
83
+ continue;
84
+ }
85
+ if (el.type === 'SpreadElement') {
86
+ out.push({ kind: 'unsupported', reason: 'spread' });
87
+ continue;
88
+ }
89
+ if (el.type !== 'CallExpression') {
90
+ out.push({ kind: 'unsupported', reason: 'not-call-expression' });
91
+ continue;
92
+ }
93
+ const call = el;
94
+ const callee = getCalleeName(call);
95
+ if (callee === null) {
96
+ out.push({ kind: 'unsupported', reason: 'not-call-expression' });
97
+ continue;
98
+ }
99
+ out.push({ kind: 'call', callee, node: call });
100
+ }
101
+ return out;
102
+ };
103
+ exports.enumerateEffectArrayElements = enumerateEffectArrayElements;
104
+ const findEffectCallExpression = ({ attr, effectIndex, }) => {
105
+ if (!attr.value || attr.value.type !== 'JSXExpressionContainer') {
106
+ return { kind: 'error', reason: 'not-call-expression' };
107
+ }
108
+ const expr = attr.value.expression;
109
+ if (expr.type !== 'ArrayExpression') {
110
+ return { kind: 'error', reason: 'not-call-expression' };
111
+ }
112
+ const elements = (0, exports.enumerateEffectArrayElements)(expr);
113
+ if (effectIndex < 0 || effectIndex >= elements.length) {
114
+ return { kind: 'error', reason: 'not-found' };
115
+ }
116
+ const target = elements[effectIndex];
117
+ if (target.kind !== 'call') {
118
+ return { kind: 'error', reason: 'not-call-expression' };
119
+ }
120
+ return { kind: 'ok', call: target.node, callee: target.callee };
121
+ };
122
+ exports.findEffectCallExpression = findEffectCallExpression;
123
+ const findObjectProperty = (objExpr, propertyName) => {
124
+ const propIndex = objExpr.properties.findIndex((p) => p.type === 'ObjectProperty' &&
125
+ ((p.key.type === 'Identifier' && p.key.name === propertyName) ||
126
+ (p.key.type === 'StringLiteral' &&
127
+ p.key.value === propertyName)));
128
+ return {
129
+ propIndex,
130
+ prop: propIndex !== -1
131
+ ? objExpr.properties[propIndex]
132
+ : undefined,
133
+ };
134
+ };
135
+ const updateEffectPropsAst = ({ input, sequenceNodePath, effectIndex, update, }) => {
136
+ var _a, _b, _c, _d;
137
+ var _e, _f, _g, _h, _j;
138
+ const ast = (0, parse_ast_1.parseAst)(input);
139
+ const jsx = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, sequenceNodePath);
140
+ if (!jsx) {
141
+ throw new Error('Could not find a JSX element at the specified location to update effects');
142
+ }
143
+ const attr = findExperimentalEffectsAttr((_e = jsx.attributes) !== null && _e !== void 0 ? _e : []);
144
+ if (!attr) {
145
+ throw new Error('Could not find _experimentalEffects on the target JSX element');
146
+ }
147
+ const found = (0, exports.findEffectCallExpression)({
148
+ attr,
149
+ effectIndex,
150
+ });
151
+ if (found.kind === 'error') {
152
+ throw new Error(`Cannot update effect prop: ${found.reason}`);
153
+ }
154
+ const { call, callee: effectCallee } = found;
155
+ const isDefault = update.defaultValue !== null &&
156
+ JSON.stringify(update.value) === JSON.stringify(update.defaultValue);
157
+ let objExpr;
158
+ if (call.arguments.length === 0) {
159
+ if (isDefault) {
160
+ return {
161
+ serialized: (0, parse_ast_1.serializeAst)(ast),
162
+ oldValueString: '',
163
+ logLine: (_g = (_f = (_a = call.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _f !== void 0 ? _f : (_b = jsx.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _g !== void 0 ? _g : 1,
164
+ effectCallee,
165
+ };
166
+ }
167
+ objExpr = b.objectExpression([]);
168
+ call.arguments.push(objExpr);
169
+ }
170
+ else if (call.arguments[0].type !== 'ObjectExpression') {
171
+ throw new Error('Cannot update effect prop: computed');
172
+ }
173
+ else {
174
+ objExpr = call.arguments[0];
175
+ }
176
+ const { prop } = findObjectProperty(objExpr, update.key);
177
+ let oldValueString = '';
178
+ if (prop) {
179
+ oldValueString = recast.print(prop.value).code;
180
+ }
181
+ else if (update.defaultValue !== null) {
182
+ oldValueString = JSON.stringify(update.defaultValue);
183
+ }
184
+ if (isDefault) {
185
+ if (prop) {
186
+ const idx = objExpr.properties.indexOf(prop);
187
+ if (idx !== -1) {
188
+ objExpr.properties.splice(idx, 1);
189
+ }
190
+ }
191
+ }
192
+ else {
193
+ const newValueExpr = parseValueExpression(update.value);
194
+ if (prop) {
195
+ prop.value = newValueExpr;
196
+ }
197
+ else {
198
+ objExpr.properties.push(b.objectProperty(b.identifier(update.key), newValueExpr));
199
+ }
200
+ }
201
+ const logLine = (_j = (_h = (_c = call.loc) === null || _c === void 0 ? void 0 : _c.start.line) !== null && _h !== void 0 ? _h : (_d = jsx.loc) === null || _d === void 0 ? void 0 : _d.start.line) !== null && _j !== void 0 ? _j : 1;
202
+ return {
203
+ serialized: (0, parse_ast_1.serializeAst)(ast),
204
+ oldValueString,
205
+ logLine,
206
+ effectCallee,
207
+ };
208
+ };
209
+ exports.updateEffectPropsAst = updateEffectPropsAst;
210
+ const updateEffectProps = async ({ input, sequenceNodePath, effectIndex, update, prettierConfigOverride, }) => {
211
+ const { serialized, oldValueString, logLine, effectCallee } = (0, exports.updateEffectPropsAst)({
212
+ input,
213
+ sequenceNodePath,
214
+ effectIndex,
215
+ update,
216
+ });
217
+ const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
218
+ input: serialized,
219
+ prettierConfigOverride,
220
+ });
221
+ return {
222
+ output,
223
+ oldValueString,
224
+ formatted,
225
+ logLine,
226
+ effectCallee,
227
+ };
228
+ };
229
+ exports.updateEffectProps = updateEffectProps;
@@ -0,0 +1,6 @@
1
+ import type { SequenceSchema } from 'remotion';
2
+ export declare const findPropsToDelete: ({ schema, key, value, }: {
3
+ schema: SequenceSchema;
4
+ key: string;
5
+ value: unknown;
6
+ }) => string[];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findPropsToDelete = void 0;
4
+ const findPropsToDelete = ({ schema, key, value, }) => {
5
+ const fieldSchema = schema[key];
6
+ if (!fieldSchema) {
7
+ throw new Error('Key ' + JSON.stringify(key) + ' not found in schema');
8
+ }
9
+ if (typeof value !== 'string') {
10
+ throw new Error('Value must be a string, but is ' + JSON.stringify(value));
11
+ }
12
+ if (fieldSchema.type !== 'enum') {
13
+ throw new Error('Key ' + JSON.stringify(key) + ' is not an enum');
14
+ }
15
+ const currentVariant = fieldSchema.variants[value];
16
+ if (!currentVariant) {
17
+ throw new Error('Value for ' +
18
+ JSON.stringify(key) +
19
+ ' must be one of ' +
20
+ Object.keys(fieldSchema.variants)
21
+ .map((v) => JSON.stringify(v))
22
+ .join(', ') +
23
+ ', got ' +
24
+ JSON.stringify(value));
25
+ }
26
+ const otherVariants = Object.keys(fieldSchema.variants).filter((v) => v !== value);
27
+ const otherKeys = new Set();
28
+ for (const variant of otherVariants) {
29
+ const otherVariant = fieldSchema.variants[variant];
30
+ const keys = Object.keys(otherVariant);
31
+ for (const k of keys) {
32
+ otherKeys.add(k);
33
+ }
34
+ }
35
+ return [...otherKeys];
36
+ };
37
+ exports.findPropsToDelete = findPropsToDelete;
@@ -0,0 +1,35 @@
1
+ import type { SequenceNodePath } from 'remotion';
2
+ import type { SequenceSchema } from 'remotion';
3
+ export type SequencePropUpdate = {
4
+ key: string;
5
+ value: unknown;
6
+ defaultValue: unknown | null;
7
+ };
8
+ export type RemovedProp = {
9
+ key: string;
10
+ valueString: string;
11
+ };
12
+ export declare const updateSequencePropsAst: ({ input, nodePath, updates, schema, }: {
13
+ input: string;
14
+ nodePath: SequenceNodePath;
15
+ updates: SequencePropUpdate[];
16
+ schema: SequenceSchema;
17
+ }) => {
18
+ serialized: string;
19
+ oldValueStrings: string[];
20
+ logLine: number;
21
+ removedProps: RemovedProp[];
22
+ };
23
+ export declare const updateSequenceProps: ({ input, nodePath, updates, schema, prettierConfigOverride, }: {
24
+ input: string;
25
+ nodePath: SequenceNodePath;
26
+ updates: SequencePropUpdate[];
27
+ schema: SequenceSchema;
28
+ prettierConfigOverride?: Record<string, unknown> | null | undefined;
29
+ }) => Promise<{
30
+ output: string;
31
+ oldValueStrings: string[];
32
+ formatted: boolean;
33
+ logLine: number;
34
+ removedProps: RemovedProp[];
35
+ }>;
@@ -0,0 +1,224 @@
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.updateSequenceProps = exports.updateSequencePropsAst = void 0;
37
+ const recast = __importStar(require("recast"));
38
+ const no_react_1 = require("remotion/no-react");
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_nested_prop_1 = require("../update-nested-prop");
43
+ const b = recast.types.builders;
44
+ const removeVariantKey = ({ node, variantKey, }) => {
45
+ var _a;
46
+ const dotIndex = variantKey.indexOf('.');
47
+ if (dotIndex === -1) {
48
+ const idx = (_a = node.attributes) === null || _a === void 0 ? void 0 : _a.findIndex((a) => a.type === 'JSXAttribute' &&
49
+ a.name.type === 'JSXIdentifier' &&
50
+ a.name.name === variantKey);
51
+ if (idx !== undefined && idx !== -1 && node.attributes) {
52
+ node.attributes.splice(idx, 1);
53
+ }
54
+ return;
55
+ }
56
+ (0, update_nested_prop_1.updateNestedProp)({
57
+ node,
58
+ parentKey: variantKey.slice(0, dotIndex),
59
+ childKey: variantKey.slice(dotIndex + 1),
60
+ value: undefined,
61
+ defaultValue: null,
62
+ isDefault: true,
63
+ });
64
+ };
65
+ const snapshotTopLevelAttrs = (node) => {
66
+ var _a;
67
+ const result = new Map();
68
+ for (const a of (_a = node.attributes) !== null && _a !== void 0 ? _a : []) {
69
+ if (a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier') {
70
+ const { name } = a.name;
71
+ const printed = recast
72
+ .print(a)
73
+ .code.replace(/\s+/g, ' ')
74
+ .replace(/,(\s*[}\]])/g, '$1')
75
+ .trim();
76
+ const prefix = `${name}=`;
77
+ let valueOnly = printed.startsWith(prefix)
78
+ ? printed.slice(prefix.length)
79
+ : printed;
80
+ if (valueOnly.startsWith('{') && valueOnly.endsWith('}')) {
81
+ valueOnly = valueOnly.slice(1, -1).trim();
82
+ }
83
+ result.set(name, valueOnly);
84
+ }
85
+ }
86
+ return result;
87
+ };
88
+ const updateSequencePropsAst = ({ input, nodePath, updates, schema, }) => {
89
+ var _a, _b, _c;
90
+ var _d, _e;
91
+ const ast = (0, parse_ast_1.parseAst)(input);
92
+ const node = (0, can_update_sequence_props_1.findJsxElementAtNodePath)(ast, nodePath);
93
+ if (!node) {
94
+ throw new Error('Could not find a JSX element at the specified line to update');
95
+ }
96
+ const logLine = (_d = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _d !== void 0 ? _d : 1;
97
+ const oldValueStrings = [];
98
+ const initialAttrs = snapshotTopLevelAttrs(node);
99
+ const updatedTopLevelKeys = new Set(updates.map(({ key }) => {
100
+ const dot = key.indexOf('.');
101
+ return dot === -1 ? key : key.slice(0, dot);
102
+ }));
103
+ for (const { key, value, defaultValue } of updates) {
104
+ let oldValueString = '';
105
+ const isDefault = defaultValue !== null &&
106
+ JSON.stringify(value) === JSON.stringify(defaultValue);
107
+ const dotIndex = key.indexOf('.');
108
+ const isNested = dotIndex !== -1;
109
+ const parentKey = isNested ? key.slice(0, dotIndex) : key;
110
+ const childKey = isNested ? key.slice(dotIndex + 1) : '';
111
+ if (isNested) {
112
+ oldValueString = (0, update_nested_prop_1.updateNestedProp)({
113
+ node,
114
+ parentKey,
115
+ childKey,
116
+ value,
117
+ defaultValue,
118
+ isDefault,
119
+ });
120
+ }
121
+ else {
122
+ const attrIndex = (_b = node.attributes) === null || _b === void 0 ? void 0 : _b.findIndex((a) => {
123
+ if (a.type === 'JSXSpreadAttribute') {
124
+ return false;
125
+ }
126
+ if (a.name.type === 'JSXNamespacedName') {
127
+ return false;
128
+ }
129
+ return a.name.name === key;
130
+ });
131
+ const attr = attrIndex !== undefined && attrIndex !== -1
132
+ ? (_c = node.attributes) === null || _c === void 0 ? void 0 : _c[attrIndex]
133
+ : undefined;
134
+ if (attr && attr.type !== 'JSXSpreadAttribute' && attr.value) {
135
+ const printed = recast.print(attr.value).code;
136
+ // Strip JSX expression container braces, e.g. "{30}" -> "30"
137
+ oldValueString =
138
+ printed.startsWith('{') && printed.endsWith('}')
139
+ ? printed.slice(1, -1)
140
+ : printed;
141
+ }
142
+ else if (attr && attr.type !== 'JSXSpreadAttribute' && !attr.value) {
143
+ // JSX shorthand like `loop` (no value) is implicitly `true`
144
+ oldValueString = 'true';
145
+ }
146
+ else if (!attr && defaultValue !== null) {
147
+ oldValueString = JSON.stringify(defaultValue);
148
+ }
149
+ if (isDefault) {
150
+ if (attr && attr.type !== 'JSXSpreadAttribute' && node.attributes) {
151
+ node.attributes.splice(attrIndex, 1);
152
+ }
153
+ }
154
+ else {
155
+ const parsed = (0, update_nested_prop_1.parseValueExpression)(value);
156
+ const newValue = value === true ? null : b.jsxExpressionContainer(parsed);
157
+ if (!attr || attr.type === 'JSXSpreadAttribute') {
158
+ const newAttr = b.jsxAttribute(b.jsxIdentifier(key), newValue);
159
+ if (!node.attributes) {
160
+ node.attributes = [];
161
+ }
162
+ node.attributes.push(newAttr);
163
+ }
164
+ else {
165
+ attr.value = newValue;
166
+ }
167
+ }
168
+ }
169
+ oldValueStrings.push(oldValueString);
170
+ if (!isNested) {
171
+ const fieldSchema = schema[key];
172
+ if (fieldSchema && fieldSchema.type === 'enum') {
173
+ const propsToDelete = no_react_1.NoReactInternals.findPropsToDelete({
174
+ schema,
175
+ key,
176
+ value,
177
+ });
178
+ for (const propToDelete of propsToDelete) {
179
+ removeVariantKey({ node, variantKey: propToDelete });
180
+ }
181
+ }
182
+ }
183
+ }
184
+ const finalAttrNames = new Set();
185
+ for (const a of (_e = node.attributes) !== null && _e !== void 0 ? _e : []) {
186
+ if (a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier') {
187
+ finalAttrNames.add(a.name.name);
188
+ }
189
+ }
190
+ const removedProps = [];
191
+ for (const [name, valueString] of initialAttrs) {
192
+ if (finalAttrNames.has(name) || updatedTopLevelKeys.has(name)) {
193
+ continue;
194
+ }
195
+ removedProps.push({ key: name, valueString });
196
+ }
197
+ return {
198
+ serialized: (0, parse_ast_1.serializeAst)(ast),
199
+ oldValueStrings,
200
+ logLine,
201
+ removedProps,
202
+ };
203
+ };
204
+ exports.updateSequencePropsAst = updateSequencePropsAst;
205
+ const updateSequenceProps = async ({ input, nodePath, updates, schema, prettierConfigOverride, }) => {
206
+ const { serialized, oldValueStrings, logLine, removedProps } = (0, exports.updateSequencePropsAst)({
207
+ input,
208
+ nodePath,
209
+ updates,
210
+ schema,
211
+ });
212
+ const { output, formatted } = await (0, format_file_content_1.formatFileContent)({
213
+ input: serialized,
214
+ prettierConfigOverride,
215
+ });
216
+ return {
217
+ output,
218
+ oldValueStrings,
219
+ formatted,
220
+ logLine,
221
+ removedProps,
222
+ };
223
+ };
224
+ exports.updateSequenceProps = updateSequenceProps;
@@ -5,15 +5,20 @@ export type SequencePropUpdate = {
5
5
  value: unknown;
6
6
  defaultValue: unknown | null;
7
7
  };
8
+ export type RemovedProp = {
9
+ key: string;
10
+ valueString: string;
11
+ };
8
12
  export declare const updateSequencePropsAst: ({ input, nodePath, updates, schema, }: {
9
13
  input: string;
10
14
  nodePath: SequenceNodePath;
11
15
  updates: SequencePropUpdate[];
12
- schema?: SequenceSchema | undefined;
16
+ schema: SequenceSchema;
13
17
  }) => {
14
18
  serialized: string;
15
19
  oldValueStrings: string[];
16
20
  logLine: number;
21
+ removedProps: RemovedProp[];
17
22
  };
18
23
  export declare const updateSequenceProps: ({ input, nodePath, updates, schema, prettierConfigOverride, }: {
19
24
  input: string;
@@ -26,4 +31,5 @@ export declare const updateSequenceProps: ({ input, nodePath, updates, schema, p
26
31
  oldValueStrings: string[];
27
32
  formatted: boolean;
28
33
  logLine: number;
34
+ removedProps: RemovedProp[];
29
35
  }>;