PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.3.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.3.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / extend / deprecated / styles / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.3.2, at gutenberg/extend/deprecated/styles/index.js

99 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { cloneDeep, merge } from 'lodash';
2
3 import camelCaseToDash from '../../../utils/camel-case-to-dash';
4
5 function fixStylesPropNames(styles) {
6 if (typeof styles === 'object') {
7 const clonedStyles = cloneDeep(styles);
8
9 const result = {};
10
11 Object.keys(clonedStyles).forEach((k) => {
12 result[camelCaseToDash(k)] = fixStylesPropNames(clonedStyles[k]);
13 });
14
15 return result;
16 }
17
18 return styles;
19 }
20
21 /**
22 * Migrate Custom Styles.
23 *
24 * @param props
25 */
26 export default function migrate(props) {
27 const { attributes } = props;
28 const {
29 ghostkitId,
30 ghostkitClassname,
31 ghostkitStyles,
32 ghostkitCustomCSS,
33 ghostkitPosition,
34 ghostkitSpacings,
35 ghostkitFrame,
36 } = attributes;
37
38 const result = {};
39
40 // Migration to new attribute.
41 if (
42 ghostkitId ||
43 ghostkitClassname ||
44 ghostkitStyles ||
45 ghostkitCustomCSS ||
46 ghostkitPosition ||
47 ghostkitSpacings ||
48 ghostkitFrame
49 ) {
50 // Clean old attributes.
51 result.ghostkitId = undefined;
52 result.ghostkitClassname = undefined;
53 result.ghostkitStyles = undefined;
54 result.ghostkitCustomCSS = undefined;
55 result.ghostkitPosition = undefined;
56 result.ghostkitSpacings = undefined;
57 result.ghostkitFrame = undefined;
58
59 const ghostkitData = cloneDeep(attributes?.ghostkit || {});
60
61 // ID.
62 if (ghostkitId && !ghostkitData?.id) {
63 ghostkitData.id = ghostkitId;
64 }
65
66 // Custom CSS.
67 if (ghostkitCustomCSS && !ghostkitData?.styles?.custom) {
68 if (typeof ghostkitData?.styles === 'undefined') {
69 ghostkitData.styles = {};
70 }
71
72 ghostkitData.styles.custom = ghostkitCustomCSS;
73 }
74
75 // Styles.
76 if (ghostkitStyles && Object.keys(ghostkitStyles).length) {
77 if (typeof ghostkitData?.styles === 'undefined') {
78 ghostkitData.styles = {};
79 }
80
81 Object.keys(ghostkitStyles).forEach((k) => {
82 ghostkitData.styles = merge(
83 ghostkitData.styles,
84 ghostkitStyles[k]
85 );
86 });
87 }
88
89 // Convert styles props to dash-case.
90 if (ghostkitData.styles) {
91 ghostkitData.styles = fixStylesPropNames(ghostkitData.styles);
92 }
93
94 result.ghostkit = ghostkitData;
95 }
96
97 return result;
98 }
99