🎥 Make videos programmatically with React
format prop changes
Jonny Burgerb9ddd0943058
diff --git a/packages/studio-server/src/preview-server/routes/log-updates/format-prop-change.ts b/packages/studio-server/src/preview-server/routes/log-updates/format-prop-change.tsnew file mode 100644index 0000000000..490fe2c7bd--- /dev/null+++ b/packages/studio-server/src/preview-server/routes/log-updates/format-prop-change.ts@@ -0,0 +1,75 @@+import {+ colorEnabled,+ formatSideProps,+ type PropDelta,+} from './format-side-props';+import {+ attrName,+ colorValue,+ equals,+ punctuation,+ strikeThrough,+} from './formatting';++// Format key={value} with Monokai syntax highlighting+const formatSimpleProp = (key: string, value: string) => {+ return `${attrName(key)}${equals('=')}${punctuation('{')}${colorValue(value)}${punctuation('}')}`;+};++// Format parentKey={{childKey: value}} with Monokai syntax highlighting+const formatNestedProp = (+ parentKey: string,+ childKey: string,+ value: string,+) => {+ return `${attrName(parentKey)}${equals('=')}${punctuation('{{')}${punctuation(childKey)}${punctuation(':')} ${colorValue(value)}${punctuation('}}')}`;+};++export const formatPropChange = ({+ key,+ oldValueString,+ newValueString,+ defaultValueString,+ removedProps,+ addedProps,+}: {+ key: string;+ oldValueString: string;+ newValueString: string;+ defaultValueString: string | null;+ removedProps: PropDelta[];+ addedProps: PropDelta[];+}) => {+ const suffix = formatSideProps({removedProps, addedProps});++ if (!colorEnabled()) {+ const dotIdx = key.indexOf('.');+ if (dotIdx === -1) {+ return `${key}={${oldValueString}} \u2192 ${key}={${newValueString}}${suffix}`;+ }++ const parent = key.slice(0, dotIdx);+ const child = key.slice(dotIdx + 1);+ return `${parent}={{${child}: ${oldValueString}}} \u2192 ${parent}={{${child}: ${newValueString}}}${suffix}`;+ }++ const dotIndex = key.indexOf('.');+ const formatProp = (value: string) =>+ dotIndex === -1+ ? formatSimpleProp(key, value)+ : formatNestedProp(+ key.slice(0, dotIndex),+ key.slice(dotIndex + 1),+ value,+ );++ if (defaultValueString !== null && newValueString === defaultValueString) {+ return `${strikeThrough(formatProp(oldValueString))}${suffix}`;+ }++ if (defaultValueString !== null && oldValueString === defaultValueString) {+ return `${formatProp(newValueString)}${suffix}`;+ }++ return `${formatProp(oldValueString)} \u2192 ${formatProp(newValueString)}${suffix}`;+};diff --git a/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.ts b/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.tsindex 7b81f3d163..9d44136859 100644--- a/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.ts+++ b/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.ts@@ -12,7 +12,7 @@ export type PropDelta = {valueString: string;};-const colorEnabled = () => RenderInternals.chalk.enabled();+export const colorEnabled = () => RenderInternals.chalk.enabled();// Format key={value} with Monokai syntax highlightingconst formatSimpleProp = (key: string, value: string) => {diff --git a/packages/studio-server/src/preview-server/routes/log-updates/log-update.ts b/packages/studio-server/src/preview-server/routes/log-updates/log-update.tsindex 255de3181d..8ff516d54d 100644--- a/packages/studio-server/src/preview-server/routes/log-updates/log-update.ts+++ b/packages/studio-server/src/preview-server/routes/log-updates/log-update.ts@@ -1,13 +1,7 @@import {RenderInternals} from '@remotion/renderer';import type {LogLevel} from '@remotion/renderer';-import {formatSideProps, type PropDelta} from './format-side-props';-import {- attrName,- colorValue,- equals,- punctuation,- strikeThrough,-} from './formatting';+import {formatPropChange} from './format-prop-change';+import {type PropDelta} from './format-side-props';let warnedAboutPrettier = false;@@ -37,71 +31,6 @@ export const normalizeQuotes = (str: string): string => {return str;};-const colorEnabled = () => RenderInternals.chalk.enabled();--// Format key={value} with Monokai syntax highlighting-const formatSimpleProp = (key: string, value: string) => {- return `${attrName(key)}${equals('=')}${punctuation('{')}${colorValue(value)}${punctuation('}')}`;-};--// Format parentKey={{childKey: value}} with Monokai syntax highlighting-const formatNestedProp = (- parentKey: string,- childKey: string,- value: string,-) => {- return `${attrName(parentKey)}${equals('=')}${punctuation('{{')}${punctuation(childKey)}${punctuation(':')} ${colorValue(value)}${punctuation('}}')}`;-};--export const formatPropChange = ({- key,- oldValueString,- newValueString,- defaultValueString,- removedProps,- addedProps,-}: {- key: string;- oldValueString: string;- newValueString: string;- defaultValueString: string | null;- removedProps: PropDelta[];- addedProps: PropDelta[];-}) => {- const suffix = formatSideProps({removedProps, addedProps});-- if (!colorEnabled()) {- const dotIdx = key.indexOf('.');- if (dotIdx === -1) {- return `${key}={${oldValueString}} \u2192 ${key}={${newValueString}}${suffix}`;- }-- const parent = key.slice(0, dotIdx);- const child = key.slice(dotIdx + 1);- return `${parent}={{${child}: ${oldValueString}}} \u2192 ${parent}={{${child}: ${newValueString}}}${suffix}`;- }-- const dotIndex = key.indexOf('.');- const formatProp = (value: string) =>- dotIndex === -1- ? formatSimpleProp(key, value)- : formatNestedProp(- key.slice(0, dotIndex),- key.slice(dotIndex + 1),- value,- );-- if (defaultValueString !== null && newValueString === defaultValueString) {- return `${strikeThrough(formatProp(oldValueString))}${suffix}`;- }-- if (defaultValueString !== null && oldValueString === defaultValueString) {- return `${formatProp(newValueString)}${suffix}`;- }-- return `${formatProp(oldValueString)} \u2192 ${formatProp(newValueString)}${suffix}`;-};-export const logUpdate = ({fileRelativeToRoot,line,diff --git a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts b/packages/studio-server/src/preview-server/routes/save-sequence-props.tsindex 7f81b81b97..93cd1567a8 100644--- a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts+++ b/packages/studio-server/src/preview-server/routes/save-sequence-props.ts@@ -15,11 +15,8 @@ import {} from '../undo-stack';import {suppressBundlerUpdateForFile} from '../watch-ignore-next-change';import {computeSequencePropsStatus} from './can-update-sequence-props';-import {- formatPropChange,- logUpdate,- normalizeQuotes,-} from './log-updates/log-update';+import {formatPropChange} from './log-updates/format-prop-change';+import {logUpdate, normalizeQuotes} from './log-updates/log-update';export const saveSequencePropsHandler: ApiHandler<SaveSequencePropsRequest,diff --git a/packages/studio-server/src/test/log-update.test.ts b/packages/studio-server/src/test/log-update.test.tsindex 7ea7009102..4e8c03a2b5 100644--- a/packages/studio-server/src/test/log-update.test.ts+++ b/packages/studio-server/src/test/log-update.test.ts@@ -8,6 +8,7 @@ import path from 'node:path';import {RenderInternals} from '@remotion/renderer';import {Internals} from 'remotion';import {updateSequenceProps} from '../codemods/update-sequence-props/update-sequence-props';+import {formatPropChange} from '../preview-server/routes/log-updates/format-prop-change';import {attrName,equals,@@ -17,7 +18,6 @@ import {stringValue,} from '../preview-server/routes/log-updates/formatting';import {- formatPropChange,logUpdate,normalizeQuotes,} from '../preview-server/routes/log-updates/log-update';