@atlaskit/inline-edit 14.2.4 → 14.3.1
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/CHANGELOG.md +20 -0
- package/dist/cjs/inline-edit.js +1 -1
- package/dist/es2019/inline-edit.js +1 -1
- package/dist/esm/inline-edit.js +1 -1
- package/package.json +11 -13
- package/codemods/12.0.0-lite-mode.ts +0 -15
- package/codemods/__tests__/12.0.0-lite-mode.tsx +0 -405
- package/codemods/__tests__/add-comments-when-validate-found.ts +0 -118
- package/codemods/__tests__/lift-InlineEditStateless-to-default.ts +0 -129
- package/codemods/__tests__/lift-InlineEditableTextField-to-its-entry-point.tsx +0 -82
- package/codemods/__tests__/spread-errorMessage-out-of-fieldProps.tsx +0 -493
- package/codemods/migrates/add-comments-when-validate-found.ts +0 -44
- package/codemods/migrates/lift-InlineEditStateless-to-default.ts +0 -58
- package/codemods/migrates/lift-InlineEditableTextField-to-its-entry-point.ts +0 -41
- package/codemods/migrates/spread-errorMessage-out-of-fieldProps.ts +0 -56
- package/codemods/migrates/utils.ts +0 -94
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { ASTPath, default as core, ImportDeclaration } from 'jscodeshift';
|
|
2
|
-
|
|
3
|
-
import { addCommentToStartOfFile, getDefaultSpecifierName, hasJSXAttributesByName } from './utils';
|
|
4
|
-
|
|
5
|
-
const commentMessage = `We could not automatically convert this code to the new API.
|
|
6
|
-
|
|
7
|
-
This file uses \`inline-edit\`’s \`validate\` prop which previously would use \`react-loadable\` and the \`inline-dialog\` packages. Version 12.0.0 of \`inline-edit\` now no longer includes these dependencies out of the box and instead allows you to compose your own experience.
|
|
8
|
-
|
|
9
|
-
If you are using an editable textfield you can move over to the \`@atlaskit/inline-edit/inline-editable-textfield\` instead which comes with the previous error message behavior.
|
|
10
|
-
|
|
11
|
-
To migrate you can use the \`isInvalid\` and \`errorMessage\` props passed to \`editView\`, like so:
|
|
12
|
-
|
|
13
|
-
\`\`\`ts
|
|
14
|
-
import InlineDialog from '@atlaskit/inline-dialog';
|
|
15
|
-
import InlineEdit from '@atlaskit/inline-edit';
|
|
16
|
-
|
|
17
|
-
const MyEditView = (
|
|
18
|
-
<InlineEdit
|
|
19
|
-
editView={({ errorMessage, isInvalid, ...props }) => (
|
|
20
|
-
<InlineDialog content={errorMessage} isOpen={isInvalid}>
|
|
21
|
-
<Textfield {...props} />
|
|
22
|
-
</InlineDialog>
|
|
23
|
-
)}
|
|
24
|
-
/>
|
|
25
|
-
);
|
|
26
|
-
\`\`\`
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
const addCommentsWhenValidateFound = (j: core.JSCodeshift, source: any) => {
|
|
30
|
-
const defaultSpecifier = getDefaultSpecifierName(j, source, '@atlaskit/inline-edit');
|
|
31
|
-
|
|
32
|
-
if (!defaultSpecifier) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
source.findJSXElements(defaultSpecifier).forEach((element: ASTPath<ImportDeclaration>) => {
|
|
37
|
-
const isValidateDefined = hasJSXAttributesByName(j, element, 'validate');
|
|
38
|
-
if (isValidateDefined) {
|
|
39
|
-
addCommentToStartOfFile({ j, base: source, message: commentMessage });
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default addCommentsWhenValidateFound;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ASTPath,
|
|
3
|
-
default as core,
|
|
4
|
-
ImportDeclaration,
|
|
5
|
-
ImportDefaultSpecifier,
|
|
6
|
-
ImportSpecifier,
|
|
7
|
-
} from 'jscodeshift';
|
|
8
|
-
|
|
9
|
-
import { addCommentToStartOfFile } from './utils';
|
|
10
|
-
|
|
11
|
-
const commentMessage = `We could not automatically convert this code to the new API.
|
|
12
|
-
|
|
13
|
-
This file uses \`InlineEdit\` and \`InlineEditStateless\` at the same time. We've merged these two types since version 12.0.0, and please use the merged version instead.
|
|
14
|
-
`;
|
|
15
|
-
|
|
16
|
-
const elevateComponentToDefault =
|
|
17
|
-
(pkg: string, toPkg: string, innerElementName: string) => (j: core.JSCodeshift, root: any) => {
|
|
18
|
-
const importDeclarations = root
|
|
19
|
-
.find(j.ImportDeclaration)
|
|
20
|
-
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === pkg);
|
|
21
|
-
|
|
22
|
-
const defaultSpecifier = importDeclarations.find(j.ImportDefaultSpecifier).nodes();
|
|
23
|
-
const otherSpecifier = importDeclarations.find(j.ImportSpecifier).nodes();
|
|
24
|
-
|
|
25
|
-
const isImportingStateless =
|
|
26
|
-
otherSpecifier.filter(
|
|
27
|
-
(s: ImportSpecifier) => s.imported && s.imported.name === innerElementName,
|
|
28
|
-
).length > 0;
|
|
29
|
-
|
|
30
|
-
if (defaultSpecifier.length > 0 && isImportingStateless) {
|
|
31
|
-
addCommentToStartOfFile({ j, base: root, message: commentMessage });
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const newDefaultSpecifier = defaultSpecifier.map((s: ImportDefaultSpecifier) => {
|
|
36
|
-
return j.importDeclaration([j.importDefaultSpecifier(s.local)], j.literal(pkg));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const newOtherSpecifiers = otherSpecifier.map((s: ImportSpecifier) => {
|
|
40
|
-
if (s.imported.name === innerElementName) {
|
|
41
|
-
return j.importDeclaration([j.importDefaultSpecifier(s.local)], j.literal(toPkg));
|
|
42
|
-
} else {
|
|
43
|
-
return j.importDeclaration([s], j.literal(pkg));
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
importDeclarations.forEach((path: ASTPath<ImportDeclaration>) => {
|
|
48
|
-
j(path).replaceWith(newDefaultSpecifier);
|
|
49
|
-
j(path).insertBefore(newOtherSpecifiers);
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// eslint-disable-next-line import/no-anonymous-default-export
|
|
54
|
-
export default elevateComponentToDefault(
|
|
55
|
-
'@atlaskit/inline-edit',
|
|
56
|
-
'@atlaskit/inline-edit',
|
|
57
|
-
'InlineEditStateless',
|
|
58
|
-
);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ASTPath,
|
|
3
|
-
default as core,
|
|
4
|
-
ImportDeclaration,
|
|
5
|
-
ImportDefaultSpecifier,
|
|
6
|
-
ImportSpecifier,
|
|
7
|
-
} from 'jscodeshift';
|
|
8
|
-
|
|
9
|
-
const elevateComponentToNewEntryPoint =
|
|
10
|
-
(pkg: string, toPkg: string, innerElementName: string) => (j: core.JSCodeshift, root: any) => {
|
|
11
|
-
const importDeclarations = root
|
|
12
|
-
.find(j.ImportDeclaration)
|
|
13
|
-
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === pkg);
|
|
14
|
-
|
|
15
|
-
const defaultSpecifier = importDeclarations.find(j.ImportDefaultSpecifier).nodes();
|
|
16
|
-
const otherSpecifier = importDeclarations.find(j.ImportSpecifier).nodes();
|
|
17
|
-
|
|
18
|
-
const newDefaultSpecifier = defaultSpecifier.map((s: ImportDefaultSpecifier) => {
|
|
19
|
-
return j.importDeclaration([j.importDefaultSpecifier(s.local)], j.literal(pkg));
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const newOtherSpecifiers = otherSpecifier.map((s: ImportSpecifier) => {
|
|
23
|
-
if (s.imported.name === innerElementName) {
|
|
24
|
-
return j.importDeclaration([j.importDefaultSpecifier(s.local)], j.literal(toPkg));
|
|
25
|
-
} else {
|
|
26
|
-
return j.importDeclaration([s], j.literal(pkg));
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
importDeclarations.forEach((path: ASTPath<ImportDeclaration>) => {
|
|
31
|
-
j(path).replaceWith(newDefaultSpecifier);
|
|
32
|
-
j(path).insertBefore(newOtherSpecifiers);
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// eslint-disable-next-line import/no-anonymous-default-export
|
|
37
|
-
export default elevateComponentToNewEntryPoint(
|
|
38
|
-
'@atlaskit/inline-edit',
|
|
39
|
-
'@atlaskit/inline-edit/inline-editable-textfield',
|
|
40
|
-
'InlineEditableTextfield',
|
|
41
|
-
);
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { type NodePath } from 'ast-types/lib/node-path';
|
|
2
|
-
import type { ASTPath, default as core, ImportDeclaration } from 'jscodeshift';
|
|
3
|
-
|
|
4
|
-
import { getDefaultSpecifierName, getJSXAttributesByName, hasJSXAttributesByName } from './utils';
|
|
5
|
-
|
|
6
|
-
const isConvertable = (arrowFunction: NodePath | null) => {
|
|
7
|
-
return (
|
|
8
|
-
arrowFunction &&
|
|
9
|
-
arrowFunction.value.params.length === 1 &&
|
|
10
|
-
arrowFunction.value.params[0].type === 'Identifier'
|
|
11
|
-
);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const spreadErrorMessage = (j: core.JSCodeshift, source: any) => {
|
|
15
|
-
const defaultSpecifier = getDefaultSpecifierName(j, source, '@atlaskit/inline-edit');
|
|
16
|
-
|
|
17
|
-
if (!defaultSpecifier) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const createObjectProperty = (name: string) => {
|
|
22
|
-
const obj = j.objectProperty(j.identifier(name), j.identifier(name));
|
|
23
|
-
obj.shorthand = true;
|
|
24
|
-
obj.loc = null;
|
|
25
|
-
|
|
26
|
-
return obj;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
source.findJSXElements(defaultSpecifier).forEach((element: ASTPath<ImportDeclaration>) => {
|
|
30
|
-
getJSXAttributesByName(j, element, 'editView').forEach((editView) => {
|
|
31
|
-
const collection = j(editView).find(j.JSXExpressionContainer).find(j.ArrowFunctionExpression);
|
|
32
|
-
|
|
33
|
-
const isValidateDefined = hasJSXAttributesByName(j, element, 'validate');
|
|
34
|
-
const arrowFunction = collection.length > 0 ? collection.get() : null;
|
|
35
|
-
|
|
36
|
-
if (isValidateDefined && isConvertable(arrowFunction)) {
|
|
37
|
-
const name = arrowFunction.value.params[0].name;
|
|
38
|
-
const replacement = j.jsxExpressionContainer(
|
|
39
|
-
j.arrowFunctionExpression(
|
|
40
|
-
[
|
|
41
|
-
j.objectPattern([
|
|
42
|
-
createObjectProperty('errorMessage'),
|
|
43
|
-
j.restProperty(j.identifier(name)),
|
|
44
|
-
]),
|
|
45
|
-
],
|
|
46
|
-
arrowFunction.value.body,
|
|
47
|
-
),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
j(editView).replaceWith(j.jsxAttribute(j.jsxIdentifier('editView'), replacement));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default spreadErrorMessage;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ASTPath,
|
|
3
|
-
default as core,
|
|
4
|
-
ImportDeclaration,
|
|
5
|
-
JSXAttribute,
|
|
6
|
-
Program,
|
|
7
|
-
} from 'jscodeshift';
|
|
8
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
9
|
-
|
|
10
|
-
function addCommentBefore({
|
|
11
|
-
j,
|
|
12
|
-
target,
|
|
13
|
-
message,
|
|
14
|
-
}: {
|
|
15
|
-
j: core.JSCodeshift;
|
|
16
|
-
target: Collection<Node> | Collection<Program> | Collection<ImportDeclaration>;
|
|
17
|
-
message: string;
|
|
18
|
-
}) {
|
|
19
|
-
const content: string = ` TODO: (from codemod) ${message} `;
|
|
20
|
-
target.forEach((path: ASTPath<any>) => {
|
|
21
|
-
path.value.comments = path.value.comments || [];
|
|
22
|
-
|
|
23
|
-
const exists = path.value.comments.find((comment: ASTPath<any>) => comment.value === content);
|
|
24
|
-
|
|
25
|
-
// avoiding duplicates of the same comment
|
|
26
|
-
if (exists) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
path.value.comments.push(j.commentBlock(content));
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function addCommentToStartOfFile({
|
|
35
|
-
j,
|
|
36
|
-
base,
|
|
37
|
-
message,
|
|
38
|
-
}: {
|
|
39
|
-
j: core.JSCodeshift;
|
|
40
|
-
base: Collection<Node>;
|
|
41
|
-
message: string;
|
|
42
|
-
}) {
|
|
43
|
-
addCommentBefore({
|
|
44
|
-
j,
|
|
45
|
-
target: base.find(j.Program),
|
|
46
|
-
message,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getJSXAttributesByName(
|
|
51
|
-
j: core.JSCodeshift,
|
|
52
|
-
element: ASTPath<any>,
|
|
53
|
-
attributeName: string,
|
|
54
|
-
): Collection<JSXAttribute> {
|
|
55
|
-
return j(element)
|
|
56
|
-
.find(j.JSXOpeningElement)
|
|
57
|
-
.find(j.JSXAttribute)
|
|
58
|
-
.filter((attribute) => {
|
|
59
|
-
const matches = j(attribute)
|
|
60
|
-
.find(j.JSXIdentifier)
|
|
61
|
-
.filter((identifier) => identifier.value.name === attributeName);
|
|
62
|
-
return Boolean(matches.length);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const getDefaultSpecifierName = (
|
|
67
|
-
j: core.JSCodeshift,
|
|
68
|
-
base: Collection<any>,
|
|
69
|
-
packageName: string,
|
|
70
|
-
) => {
|
|
71
|
-
const specifiers = base
|
|
72
|
-
.find(j.ImportDeclaration)
|
|
73
|
-
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === packageName)
|
|
74
|
-
.find(j.ImportDefaultSpecifier);
|
|
75
|
-
|
|
76
|
-
if (!specifiers.length) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const hasJSXAttributesByName = (
|
|
84
|
-
j: core.JSCodeshift,
|
|
85
|
-
element: ASTPath<any>,
|
|
86
|
-
attributeName: string,
|
|
87
|
-
) => getJSXAttributesByName(j, element, attributeName).length > 0;
|
|
88
|
-
|
|
89
|
-
export {
|
|
90
|
-
getDefaultSpecifierName,
|
|
91
|
-
getJSXAttributesByName,
|
|
92
|
-
hasJSXAttributesByName,
|
|
93
|
-
addCommentToStartOfFile,
|
|
94
|
-
};
|