@atlaskit/editor-core 193.24.6 → 193.24.18
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/.eslintrc.js +37 -37
- package/CHANGELOG.md +16 -0
- package/architecture/0001-record-architecture-decisions.md +6 -3
- package/architecture/0002-deep-equality-check-for-getsharedstate.md +9 -8
- package/architecture/0003-explicit-plugin-dependencies.md +47 -18
- package/codemods/140.0.0-rc-kraken-fix-type-errors.ts +1 -3
- package/codemods/145.0.0-deprecate-props.ts +1 -3
- package/codemods/172.0.0-transform-smartlinks-prop.ts +1 -3
- package/codemods/175.0.0-rename-unsafe-allowUndoRedoButton-prop.ts +1 -1
- package/codemods/180.1.0-update-to-editor-migration-component.ts +1 -3
- package/codemods/__tests__/next-remove-allow-more-text-colors-prop.ts +29 -31
- package/codemods/__tests__/remove-config-panel-width-prop.ts +29 -31
- package/codemods/__tests__/rename-editor-to-editor-migration-component.ts +43 -45
- package/codemods/__tests__/rename-smartlinks-prop.ts +57 -59
- package/codemods/__tests__/rename-unsafe-allowUndoRedoButtons-prop.ts +43 -43
- package/codemods/__tests__/rename-unsafe-cards-prop.ts +43 -45
- package/codemods/migrates/next-remove-allow-more-text-colors-prop.ts +41 -45
- package/codemods/migrates/remove-config-panel-width-prop.ts +20 -29
- package/codemods/migrates/rename-editor-to-editor-migration-component.ts +20 -24
- package/codemods/migrates/rename-smartlinks-prop.ts +30 -38
- package/codemods/migrates/rename-unsafe-allowUndoRedoButtons-prop.ts +4 -5
- package/codemods/migrates/rename-unsafe-cards-prop.ts +1 -4
- package/codemods/utils.ts +62 -72
- package/dist/cjs/ui/Appearance/Comment/Toolbar.js +3 -3
- package/dist/cjs/ui/AppearanceComponents/Mobile.js +5 -5
- package/dist/cjs/ui/ContentStyles/ai-panels.js +1 -1
- package/dist/cjs/ui/ContentStyles/code-block.js +2 -2
- package/dist/cjs/ui/ContentStyles/date.js +1 -1
- package/dist/cjs/ui/ContentStyles/expand.js +1 -1
- package/dist/cjs/ui/ContentStyles/extension.js +2 -2
- package/dist/cjs/ui/ContentStyles/index.js +6 -6
- package/dist/cjs/ui/ContentStyles/layout.js +1 -1
- package/dist/cjs/ui/ContentStyles/media.js +1 -1
- package/dist/cjs/ui/ContentStyles/panel.js +1 -1
- package/dist/cjs/ui/ContentStyles/status.js +1 -1
- package/dist/cjs/ui/ContentStyles/tasks-and-decisions.js +1 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/ui/Appearance/Comment/Toolbar.js +40 -40
- package/dist/es2019/ui/AppearanceComponents/Mobile.js +5 -5
- package/dist/es2019/ui/ContentStyles/ai-panels.js +80 -80
- package/dist/es2019/ui/ContentStyles/code-block.js +58 -58
- package/dist/es2019/ui/ContentStyles/date.js +19 -19
- package/dist/es2019/ui/ContentStyles/expand.js +98 -98
- package/dist/es2019/ui/ContentStyles/extension.js +154 -159
- package/dist/es2019/ui/ContentStyles/index.js +139 -144
- package/dist/es2019/ui/ContentStyles/layout.js +125 -125
- package/dist/es2019/ui/ContentStyles/media.js +179 -178
- package/dist/es2019/ui/ContentStyles/panel.js +29 -30
- package/dist/es2019/ui/ContentStyles/status.js +30 -32
- package/dist/es2019/ui/ContentStyles/tasks-and-decisions.js +18 -19
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/ui/Appearance/Comment/Toolbar.js +3 -3
- package/dist/esm/ui/AppearanceComponents/Mobile.js +5 -5
- package/dist/esm/ui/ContentStyles/ai-panels.js +1 -1
- package/dist/esm/ui/ContentStyles/code-block.js +2 -2
- package/dist/esm/ui/ContentStyles/date.js +1 -1
- package/dist/esm/ui/ContentStyles/expand.js +1 -1
- package/dist/esm/ui/ContentStyles/extension.js +2 -2
- package/dist/esm/ui/ContentStyles/index.js +6 -6
- package/dist/esm/ui/ContentStyles/layout.js +1 -1
- package/dist/esm/ui/ContentStyles/media.js +1 -1
- package/dist/esm/ui/ContentStyles/panel.js +1 -1
- package/dist/esm/ui/ContentStyles/status.js +1 -1
- package/dist/esm/ui/ContentStyles/tasks-and-decisions.js +1 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/composable-editor/editor.d.ts +1 -1
- package/dist/types/composable-editor/hooks/useProviders.d.ts +1 -1
- package/dist/types/create-editor/create-preset.d.ts +135 -9
- package/dist/types/create-editor/sort-by-order.d.ts +1 -1
- package/dist/types/event-dispatcher/index.d.ts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/presets/default.d.ts +120 -8
- package/dist/types/presets/universal.d.ts +135 -9
- package/dist/types/presets/useUniversalPreset.d.ts +135 -9
- package/dist/types/test-utils.d.ts +1 -1
- package/dist/types/types/browser.d.ts +1 -1
- package/dist/types/types/editor-plugin.d.ts +1 -1
- package/dist/types/types/empty-state-handler.d.ts +1 -1
- package/dist/types/types/feature-flags.d.ts +1 -1
- package/dist/types/types/index.d.ts +3 -3
- package/dist/types/types/pm-config.d.ts +1 -1
- package/dist/types/types/ui-components.d.ts +1 -1
- package/dist/types/ui/Addon/ClickAreaBlock/index.d.ts +1 -1
- package/dist/types/ui/Toolbar/types.d.ts +1 -1
- package/dist/types/utils/action.d.ts +1 -4
- package/dist/types/utils/performance/plugin-performance-report.d.ts +1 -1
- package/dist/types/utils/slice.d.ts +1 -1
- package/dist/types-ts4.5/composable-editor/editor.d.ts +1 -1
- package/dist/types-ts4.5/composable-editor/hooks/useProviders.d.ts +1 -1
- package/dist/types-ts4.5/create-editor/create-preset.d.ts +153 -9
- package/dist/types-ts4.5/create-editor/sort-by-order.d.ts +1 -1
- package/dist/types-ts4.5/event-dispatcher/index.d.ts +2 -2
- package/dist/types-ts4.5/index.d.ts +2 -2
- package/dist/types-ts4.5/presets/default.d.ts +136 -8
- package/dist/types-ts4.5/presets/universal.d.ts +153 -9
- package/dist/types-ts4.5/presets/useUniversalPreset.d.ts +153 -9
- package/dist/types-ts4.5/test-utils.d.ts +1 -1
- package/dist/types-ts4.5/types/browser.d.ts +1 -1
- package/dist/types-ts4.5/types/editor-plugin.d.ts +1 -1
- package/dist/types-ts4.5/types/empty-state-handler.d.ts +1 -1
- package/dist/types-ts4.5/types/feature-flags.d.ts +1 -1
- package/dist/types-ts4.5/types/index.d.ts +3 -3
- package/dist/types-ts4.5/types/pm-config.d.ts +1 -1
- package/dist/types-ts4.5/types/ui-components.d.ts +1 -1
- package/dist/types-ts4.5/ui/Addon/ClickAreaBlock/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/Toolbar/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/performance/plugin-performance-report.d.ts +1 -1
- package/dist/types-ts4.5/utils/slice.d.ts +1 -1
- package/docs/0-intro.tsx +13 -19
- package/docs/1-legacy-editor.tsx +13 -19
- package/docs/4-annotations.tsx +222 -223
- package/package.json +25 -16
- package/report.api.md +448 -473
|
@@ -6,15 +6,13 @@ import { createTransformer } from '../utils';
|
|
|
6
6
|
// This stays as require() since changing to import will trigger a linter error
|
|
7
7
|
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
8
8
|
|
|
9
|
-
const transformer = createTransformer('@atlaskit/editor-core', [
|
|
10
|
-
renameUnsafeCardProp,
|
|
11
|
-
]);
|
|
9
|
+
const transformer = createTransformer('@atlaskit/editor-core', [renameUnsafeCardProp]);
|
|
12
10
|
|
|
13
11
|
describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
defineInlineTest(
|
|
13
|
+
{ default: transformer, parser: 'tsx' },
|
|
14
|
+
{},
|
|
15
|
+
`
|
|
18
16
|
import React from 'react';
|
|
19
17
|
import { Editor } from '@atlaskit/editor-core';
|
|
20
18
|
|
|
@@ -22,7 +20,7 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
22
20
|
<Editor />
|
|
23
21
|
);
|
|
24
22
|
`, // -----
|
|
25
|
-
|
|
23
|
+
`
|
|
26
24
|
import React from 'react';
|
|
27
25
|
import { Editor } from '@atlaskit/editor-core';
|
|
28
26
|
|
|
@@ -30,13 +28,13 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
30
28
|
<Editor />
|
|
31
29
|
);
|
|
32
30
|
`, // -----
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
'rename nothing if UNSAFE_cards prop not set',
|
|
32
|
+
);
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
defineInlineTest(
|
|
35
|
+
{ default: transformer, parser: 'tsx' },
|
|
36
|
+
{},
|
|
37
|
+
`
|
|
40
38
|
import React from 'react';
|
|
41
39
|
import { Editor } from '@atlaskit/editor-core';
|
|
42
40
|
|
|
@@ -44,7 +42,7 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
44
42
|
<Editor smartLinks />
|
|
45
43
|
);
|
|
46
44
|
`, // -----
|
|
47
|
-
|
|
45
|
+
`
|
|
48
46
|
import React from 'react';
|
|
49
47
|
import { Editor } from '@atlaskit/editor-core';
|
|
50
48
|
|
|
@@ -52,13 +50,13 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
52
50
|
<Editor smartLinks />
|
|
53
51
|
);
|
|
54
52
|
`, // -----
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
'rename nothing if boolean prop',
|
|
54
|
+
);
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
defineInlineTest(
|
|
57
|
+
{ default: transformer, parser: 'tsx' },
|
|
58
|
+
{},
|
|
59
|
+
`
|
|
62
60
|
import React from 'react';
|
|
63
61
|
import { Editor } from '@atlaskit/editor-core';
|
|
64
62
|
|
|
@@ -66,7 +64,7 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
66
64
|
<Editor smartLinks={{ provider: Promise.resolve({})}} />
|
|
67
65
|
);
|
|
68
66
|
`, // -----
|
|
69
|
-
|
|
67
|
+
`
|
|
70
68
|
import React from 'react';
|
|
71
69
|
import { Editor } from '@atlaskit/editor-core';
|
|
72
70
|
|
|
@@ -74,13 +72,13 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
74
72
|
<Editor smartLinks={{ provider: Promise.resolve({})}} />
|
|
75
73
|
);
|
|
76
74
|
`, // -----
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
'rename nothing if UNSAFE_cards not found',
|
|
76
|
+
);
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
defineInlineTest(
|
|
79
|
+
{ default: transformer, parser: 'tsx' },
|
|
80
|
+
{},
|
|
81
|
+
`
|
|
84
82
|
import React from 'react';
|
|
85
83
|
import { Editor } from '@atlaskit/editor-core';
|
|
86
84
|
|
|
@@ -88,7 +86,7 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
88
86
|
<Editor UNSAFE_cards={{ provider: Promise.resolve({}), allowEmbeds: true }} />
|
|
89
87
|
);
|
|
90
88
|
`, // -----
|
|
91
|
-
|
|
89
|
+
`
|
|
92
90
|
import React from 'react';
|
|
93
91
|
import { Editor } from '@atlaskit/editor-core';
|
|
94
92
|
|
|
@@ -96,13 +94,13 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
96
94
|
<Editor smartLinks={{ provider: Promise.resolve({}), allowEmbeds: true }} />
|
|
97
95
|
);
|
|
98
96
|
`, // -----
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
'rename UNSAFE_cards to smartLinks and do not change other options',
|
|
98
|
+
);
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
defineInlineTest(
|
|
101
|
+
{ default: transformer, parser: 'tsx' },
|
|
102
|
+
{},
|
|
103
|
+
`
|
|
106
104
|
import React from 'react';
|
|
107
105
|
import { Editor as AKEditor } from '@atlaskit/editor-core';
|
|
108
106
|
|
|
@@ -110,7 +108,7 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
110
108
|
<AKEditor UNSAFE_cards={{ provider: Promise.resolve({}) }} />
|
|
111
109
|
);
|
|
112
110
|
`, // -----
|
|
113
|
-
|
|
111
|
+
`
|
|
114
112
|
import React from 'react';
|
|
115
113
|
import { Editor as AKEditor } from '@atlaskit/editor-core';
|
|
116
114
|
|
|
@@ -118,13 +116,13 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
118
116
|
<AKEditor smartLinks={{ provider: Promise.resolve({}) }} />
|
|
119
117
|
);
|
|
120
118
|
`, // -----
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
'rename UNSAFE_cards to smartLinks when Editor is renamed',
|
|
120
|
+
);
|
|
123
121
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
defineInlineTest(
|
|
123
|
+
{ default: transformer, parser: 'tsx' },
|
|
124
|
+
{},
|
|
125
|
+
`
|
|
128
126
|
import React from 'react';
|
|
129
127
|
|
|
130
128
|
const Editor = (props) => {
|
|
@@ -135,7 +133,7 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
135
133
|
<Editor UNSAFE_cards={{ provider: Promise.resolve({}) }} />
|
|
136
134
|
);
|
|
137
135
|
`, // -----
|
|
138
|
-
|
|
136
|
+
`
|
|
139
137
|
import React from 'react';
|
|
140
138
|
|
|
141
139
|
const Editor = (props) => {
|
|
@@ -146,6 +144,6 @@ describe('Rename UNSAFE_cards to smartLinks', () => {
|
|
|
146
144
|
<Editor UNSAFE_cards={{ provider: Promise.resolve({}) }} />
|
|
147
145
|
);
|
|
148
146
|
`, // -----
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
'rename nothing if UNSAFE_cards for Editor is not from @atlaskit/editor-core',
|
|
148
|
+
);
|
|
151
149
|
});
|
|
@@ -7,49 +7,45 @@ import { findImportFromPackage } from '../utils';
|
|
|
7
7
|
* from `allowTextColor` Editor prop.
|
|
8
8
|
* Ref: ED-15849
|
|
9
9
|
*/
|
|
10
|
-
const createRemoveAllowMoreTextColorsPropTransform = (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
};
|
|
10
|
+
const createRemoveAllowMoreTextColorsPropTransform = (pkg: string, component: string) => {
|
|
11
|
+
return (j: core.JSCodeshift, source: Collection<any>) => {
|
|
12
|
+
// Find regular or renamed imports
|
|
13
|
+
// of <Editor/> component from '@atlaskit/editor-core' package
|
|
14
|
+
const importedNames: string[] = findImportFromPackage(
|
|
15
|
+
j,
|
|
16
|
+
source,
|
|
17
|
+
'@atlaskit/editor-core',
|
|
18
|
+
'Editor',
|
|
19
|
+
);
|
|
20
|
+
// Make the change on all instances of named imports found
|
|
21
|
+
importedNames.forEach((importedComponentName) => {
|
|
22
|
+
// Find `allowTextColor` prop
|
|
23
|
+
const allowTextColorCollection = source.find(j.JSXAttribute, {
|
|
24
|
+
name: {
|
|
25
|
+
type: 'JSXIdentifier',
|
|
26
|
+
name: 'allowTextColor',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
allowTextColorCollection
|
|
30
|
+
.find(j.ObjectProperty, { key: { name: 'allowMoreTextColors' } })
|
|
31
|
+
.forEach((x) => j(x).remove());
|
|
32
|
+
// If the remaining `allowTextColor` prop is an empty object, set `allowTextColor` to `true`.
|
|
33
|
+
allowTextColorCollection.forEach((allowTextColorPath) => {
|
|
34
|
+
j(allowTextColorPath).find(j.ObjectExpression, (objectExpression) => {
|
|
35
|
+
if (objectExpression.properties.length === 0) {
|
|
36
|
+
j(allowTextColorPath).replaceWith(
|
|
37
|
+
j.jsxAttribute(
|
|
38
|
+
j.jsxIdentifier('allowTextColor'),
|
|
39
|
+
j.jsxExpressionContainer(j.booleanLiteral(true)),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
50
47
|
};
|
|
51
|
-
export const removeAllowMoreColorsProp =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
48
|
+
export const removeAllowMoreColorsProp = createRemoveAllowMoreTextColorsPropTransform(
|
|
49
|
+
'@atlaskit/editor-core',
|
|
50
|
+
'Editor',
|
|
51
|
+
);
|
|
@@ -3,37 +3,28 @@ import type { Collection } from 'jscodeshift/src/Collection';
|
|
|
3
3
|
|
|
4
4
|
import { findImportFromPackage } from '../utils';
|
|
5
5
|
|
|
6
|
-
const createRemoveComponentPropTransform = (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
) => {
|
|
11
|
-
return (j: core.JSCodeshift, source: Collection<any>) => {
|
|
12
|
-
// Find regular or renamed imports
|
|
13
|
-
const importedNames: string[] = findImportFromPackage(
|
|
14
|
-
j,
|
|
15
|
-
source,
|
|
16
|
-
pkg,
|
|
17
|
-
component,
|
|
18
|
-
);
|
|
6
|
+
const createRemoveComponentPropTransform = (pkg: string, component: string, propName: string) => {
|
|
7
|
+
return (j: core.JSCodeshift, source: Collection<any>) => {
|
|
8
|
+
// Find regular or renamed imports
|
|
9
|
+
const importedNames: string[] = findImportFromPackage(j, source, pkg, component);
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
// Make the change on all instances of named imports found
|
|
12
|
+
importedNames.forEach((importedComponentName) => {
|
|
13
|
+
source
|
|
14
|
+
.findJSXElements(importedComponentName)
|
|
15
|
+
.find(j.JSXAttribute, {
|
|
16
|
+
name: {
|
|
17
|
+
type: 'JSXIdentifier',
|
|
18
|
+
name: propName,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
.forEach((x) => j(x).remove());
|
|
22
|
+
});
|
|
23
|
+
};
|
|
33
24
|
};
|
|
34
25
|
|
|
35
26
|
export const removeConfigPanelWidthProp = createRemoveComponentPropTransform(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
'@atlaskit/editor-core',
|
|
28
|
+
'ContextPanel',
|
|
29
|
+
'width',
|
|
39
30
|
);
|
|
@@ -6,29 +6,25 @@ import type { Collection } from 'jscodeshift/src/Collection';
|
|
|
6
6
|
* EditorMigrationComponent
|
|
7
7
|
* Ref: ED-16826
|
|
8
8
|
*/
|
|
9
|
-
export const createUpdateEditorToMigrationComponent = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
j.importSpecifier(
|
|
26
|
-
j.identifier('EditorMigrationComponent'),
|
|
27
|
-
currentImport.node.local,
|
|
28
|
-
),
|
|
29
|
-
);
|
|
30
|
-
};
|
|
9
|
+
export const createUpdateEditorToMigrationComponent = (pkg: string, component: string) => {
|
|
10
|
+
return (j: core.JSCodeshift, source: Collection<any>) => {
|
|
11
|
+
source
|
|
12
|
+
.find(j.ImportDeclaration, { source: { value: pkg } })
|
|
13
|
+
.filter(
|
|
14
|
+
(path) =>
|
|
15
|
+
j(path).find(j.ImportSpecifier, {
|
|
16
|
+
imported: { type: 'Identifier', name: component },
|
|
17
|
+
}).length > 0,
|
|
18
|
+
)
|
|
19
|
+
.find(j.ImportSpecifier)
|
|
20
|
+
.filter((path) => path.node.imported.name === component)
|
|
21
|
+
.replaceWith((currentImport) =>
|
|
22
|
+
j.importSpecifier(j.identifier('EditorMigrationComponent'), currentImport.node.local),
|
|
23
|
+
);
|
|
24
|
+
};
|
|
31
25
|
};
|
|
32
26
|
|
|
33
|
-
export const renameEditorToMigrationComponent =
|
|
34
|
-
|
|
27
|
+
export const renameEditorToMigrationComponent = createUpdateEditorToMigrationComponent(
|
|
28
|
+
'@atlaskit/editor-core',
|
|
29
|
+
'Editor',
|
|
30
|
+
);
|
|
@@ -10,47 +10,39 @@ import type { Collection } from 'jscodeshift/src/Collection';
|
|
|
10
10
|
* @param toObjectKey String
|
|
11
11
|
*/
|
|
12
12
|
export const createJSXRenameVariableToNestedKeyTransform = (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
from: string,
|
|
14
|
+
toObjectName: string,
|
|
15
|
+
toObjectKey: string,
|
|
16
16
|
) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
return (j: core.JSCodeshift, source: Collection<any>) => {
|
|
18
|
+
source
|
|
19
|
+
.find(j.JSXAttribute, { name: { type: 'JSXIdentifier', name: from } })
|
|
20
|
+
.forEach((fromAttribute) => {
|
|
21
|
+
// is there an existing destination prop
|
|
22
|
+
const isExistingAttribute =
|
|
23
|
+
source.find(j.JSXAttribute, {
|
|
24
|
+
name: { type: 'JSXIdentifier', name: toObjectName },
|
|
25
|
+
}).length !== 0;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
j.jsxAttribute(
|
|
43
|
-
j.jsxIdentifier(toObjectName),
|
|
44
|
-
j.jsxExpressionContainer(newObject),
|
|
45
|
-
),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
};
|
|
27
|
+
if (
|
|
28
|
+
!isExistingAttribute &&
|
|
29
|
+
fromAttribute.node.value?.type === 'JSXExpressionContainer' &&
|
|
30
|
+
fromAttribute.node.value.expression.type === 'ObjectExpression'
|
|
31
|
+
) {
|
|
32
|
+
const existingProperties = fromAttribute.node.value.expression.properties;
|
|
33
|
+
const newObject = j.objectExpression([
|
|
34
|
+
j.property('init', j.identifier(toObjectKey), j.objectExpression(existingProperties)),
|
|
35
|
+
]);
|
|
36
|
+
fromAttribute.replace(
|
|
37
|
+
j.jsxAttribute(j.jsxIdentifier(toObjectName), j.jsxExpressionContainer(newObject)),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
50
42
|
};
|
|
51
43
|
|
|
52
44
|
export const renameSmartLinksProp = createJSXRenameVariableToNestedKeyTransform(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
'smartLinks',
|
|
46
|
+
'linking',
|
|
47
|
+
'smartLinks',
|
|
56
48
|
);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRenameVariableTransform } from '../utils';
|
|
2
2
|
|
|
3
|
-
export const renameUnsafeAllowUndoRedoButtonsProp =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
);
|
|
3
|
+
export const renameUnsafeAllowUndoRedoButtonsProp = createRenameVariableTransform(
|
|
4
|
+
'UNSAFE_allowUndoRedoButtons',
|
|
5
|
+
'allowUndoRedoButtons',
|
|
6
|
+
);
|
package/codemods/utils.ts
CHANGED
|
@@ -1,44 +1,34 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
API,
|
|
3
|
+
ASTPath,
|
|
4
|
+
default as core,
|
|
5
|
+
FileInfo,
|
|
6
|
+
ImportDeclaration,
|
|
7
|
+
Options,
|
|
8
8
|
} from 'jscodeshift';
|
|
9
9
|
import type { Collection } from 'jscodeshift/src/Collection';
|
|
10
10
|
|
|
11
|
-
function hasImportDeclaration(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
) {
|
|
16
|
-
const imports = source
|
|
17
|
-
.find(j.ImportDeclaration)
|
|
18
|
-
.filter(
|
|
19
|
-
(path: ASTPath<ImportDeclaration>) =>
|
|
20
|
-
path.node.source.value === importPath,
|
|
21
|
-
);
|
|
11
|
+
function hasImportDeclaration(j: core.JSCodeshift, source: Collection<any>, importPath: string) {
|
|
12
|
+
const imports = source
|
|
13
|
+
.find(j.ImportDeclaration)
|
|
14
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === importPath);
|
|
22
15
|
|
|
23
|
-
|
|
16
|
+
return Boolean(imports.length);
|
|
24
17
|
}
|
|
25
18
|
|
|
26
19
|
export const createTransformer =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
) =>
|
|
31
|
-
(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
|
|
32
|
-
const source = j(fileInfo.source);
|
|
20
|
+
(packageName: string, migrations: { (j: core.JSCodeshift, source: Collection<any>): void }[]) =>
|
|
21
|
+
(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
|
|
22
|
+
const source = j(fileInfo.source);
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
if (!hasImportDeclaration(j, source, packageName)) {
|
|
25
|
+
return fileInfo.source;
|
|
26
|
+
}
|
|
37
27
|
|
|
38
|
-
|
|
28
|
+
migrations.forEach((transform) => transform(j, source));
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
return source.toSource(options.printOptions || { quote: 'single' });
|
|
31
|
+
};
|
|
42
32
|
|
|
43
33
|
/**
|
|
44
34
|
* Finds import from a particular path/package matching a particular name.
|
|
@@ -51,45 +41,45 @@ export const createTransformer =
|
|
|
51
41
|
* @returns String[] Array of result names which match the specified importName
|
|
52
42
|
*/
|
|
53
43
|
export const findImportFromPackage = (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
j: core.JSCodeshift,
|
|
45
|
+
source: Collection<any>,
|
|
46
|
+
pkg: string,
|
|
47
|
+
importName: string,
|
|
58
48
|
): string[] => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
49
|
+
// Find regular or renamed imports
|
|
50
|
+
return (
|
|
51
|
+
source
|
|
52
|
+
// find all import statements which import from the given package
|
|
53
|
+
.find(j.ImportDeclaration, {
|
|
54
|
+
source: {
|
|
55
|
+
value: pkg,
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
// narrow down to imports related to 'component'
|
|
59
|
+
.filter(
|
|
60
|
+
(importDeclaration) =>
|
|
61
|
+
j(importDeclaration).find(j.ImportSpecifier, {
|
|
62
|
+
imported: {
|
|
63
|
+
type: 'Identifier',
|
|
64
|
+
name: importName,
|
|
65
|
+
},
|
|
66
|
+
}).length > 0,
|
|
67
|
+
)
|
|
68
|
+
.nodes()
|
|
69
|
+
.map((importDeclaration): string => {
|
|
70
|
+
const importSpecifier = j(importDeclaration)
|
|
71
|
+
.find(j.ImportSpecifier, {
|
|
72
|
+
imported: {
|
|
73
|
+
type: 'Identifier',
|
|
74
|
+
name: importName,
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
.nodes()[0];
|
|
88
78
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
return importSpecifier.local?.name || '';
|
|
80
|
+
})
|
|
81
|
+
.filter((name) => Boolean(name))
|
|
82
|
+
);
|
|
93
83
|
};
|
|
94
84
|
|
|
95
85
|
/**
|
|
@@ -99,9 +89,9 @@ export const findImportFromPackage = (
|
|
|
99
89
|
* @param toName String
|
|
100
90
|
*/
|
|
101
91
|
export const createRenameVariableTransform = (from: string, toName: string) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
92
|
+
return (j: core.JSCodeshift, source: Collection<any>) => {
|
|
93
|
+
source.find(j.Identifier, { name: from }).forEach((x) => {
|
|
94
|
+
x.replace(j.identifier(toName));
|
|
95
|
+
});
|
|
96
|
+
};
|
|
107
97
|
};
|