@atlaskit/link-create 0.0.2 → 0.0.4
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 +12 -0
- package/dist/cjs/index.js +17 -3
- package/dist/cjs/ui/index.js +16 -2
- package/dist/cjs/ui/main.js +54 -4
- package/dist/cjs/utils.js +94 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/ui/index.js +1 -1
- package/dist/es2019/ui/main.js +50 -3
- package/dist/es2019/utils.js +35 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/ui/index.js +1 -1
- package/dist/esm/ui/main.js +50 -3
- package/dist/esm/utils.js +87 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/ui/index.d.ts +1 -1
- package/dist/types/ui/main.d.ts +9 -2
- package/dist/types/ui/types.d.ts +42 -0
- package/dist/types/utils.d.ts +13 -0
- package/package.json +7 -2
- package/report.api.md +41 -1
- package/tmp/api-report-tmp.d.ts +31 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/link-create
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`09697a312bc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/09697a312bc) - EDM-5657 EDM-5661 Implement Select and Textfield components
|
|
8
|
+
|
|
9
|
+
## 0.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`4b8910b3460`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4b8910b3460) - Add link-create-confluence package
|
|
14
|
+
|
|
3
15
|
## 0.0.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
Object.defineProperty(exports, "Select", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _index.Select;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "TextField", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _index.TextField;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
7
19
|
Object.defineProperty(exports, "default", {
|
|
8
20
|
enumerable: true,
|
|
9
21
|
get: function get() {
|
|
@@ -16,5 +28,7 @@ Object.defineProperty(exports, "useLinkCreateCallback", {
|
|
|
16
28
|
return _index2.useLinkCreateCallback;
|
|
17
29
|
}
|
|
18
30
|
});
|
|
19
|
-
var _index =
|
|
20
|
-
var _index2 = require("./controllers/callback-context/index");
|
|
31
|
+
var _index = _interopRequireWildcard(require("./ui/index"));
|
|
32
|
+
var _index2 = require("./controllers/callback-context/index");
|
|
33
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
34
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/dist/cjs/ui/index.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
Object.defineProperty(exports, "Select", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _main.Select;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "TextField", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _main.TextField;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
7
19
|
Object.defineProperty(exports, "default", {
|
|
8
20
|
enumerable: true,
|
|
9
21
|
get: function get() {
|
|
10
22
|
return _main.default;
|
|
11
23
|
}
|
|
12
24
|
});
|
|
13
|
-
var _main =
|
|
25
|
+
var _main = _interopRequireWildcard(require("./main"));
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/dist/cjs/ui/main.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
8
|
+
exports.Select = Select;
|
|
9
|
+
exports.TextField = TextField;
|
|
7
10
|
exports.default = LinkCreate;
|
|
8
|
-
var
|
|
11
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
|
+
var _react = require("react");
|
|
13
|
+
var _react2 = require("@emotion/react");
|
|
14
|
+
var _form = require("@atlaskit/form");
|
|
9
15
|
var _modalDialog = _interopRequireWildcard(require("@atlaskit/modal-dialog"));
|
|
16
|
+
var _select = _interopRequireDefault(require("@atlaskit/select"));
|
|
17
|
+
var _textfield = _interopRequireDefault(require("@atlaskit/textfield"));
|
|
10
18
|
var _callbackContext = require("../controllers/callback-context");
|
|
11
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -27,12 +35,54 @@ function LinkCreate(_ref) {
|
|
|
27
35
|
if (!chosenOne) {
|
|
28
36
|
throw new Error('Make sure you specified a valid entityKey');
|
|
29
37
|
}
|
|
30
|
-
return (0,
|
|
38
|
+
return (0, _react2.jsx)(_modalDialog.ModalTransition, null, !!active && (0, _react2.jsx)(_modalDialog.default, {
|
|
31
39
|
onClose: onCancel,
|
|
32
40
|
testId: testId
|
|
33
|
-
}, (0,
|
|
41
|
+
}, (0, _react2.jsx)(_modalDialog.ModalHeader, null, (0, _react2.jsx)(_modalDialog.ModalTitle, null, "Create New")), (0, _react2.jsx)(_callbackContext.LinkCreateCallbackProvider, {
|
|
34
42
|
onCreate: onCreate,
|
|
35
43
|
onFailure: onFailure,
|
|
36
44
|
onCancel: onCancel
|
|
37
|
-
}, chosenOne.form)))
|
|
45
|
+
}, chosenOne.form)));
|
|
46
|
+
}
|
|
47
|
+
function Select(_ref2) {
|
|
48
|
+
var name = _ref2.name,
|
|
49
|
+
title = _ref2.title,
|
|
50
|
+
options = _ref2.options,
|
|
51
|
+
defaultOption = _ref2.defaultOption,
|
|
52
|
+
placeholder = _ref2.placeholder;
|
|
53
|
+
return (0, _react2.jsx)(_form.Field, {
|
|
54
|
+
name: name,
|
|
55
|
+
label: title,
|
|
56
|
+
isRequired: true
|
|
57
|
+
}, function (_ref3) {
|
|
58
|
+
var fieldProps = _ref3.fieldProps,
|
|
59
|
+
error = _ref3.error;
|
|
60
|
+
return (0, _react2.jsx)(_react.Fragment, null, error && (0, _react2.jsx)(_form.ErrorMessage, null, error), (0, _react2.jsx)(_select.default, (0, _extends2.default)({}, fieldProps, {
|
|
61
|
+
inputId: "".concat(title, "-input-id"),
|
|
62
|
+
options: options,
|
|
63
|
+
placeholder: placeholder,
|
|
64
|
+
defaultValue: defaultOption
|
|
65
|
+
})));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A text field utilising the Atlaskit Textfield and Field objects from `@atlaskit/form`.
|
|
71
|
+
* Validation is handled by the form as it is on form submission. Any errors returned by
|
|
72
|
+
* the handleSubmit function passed to the form <Form> that have a key matching the `name`
|
|
73
|
+
* of this text field are shown above the field.
|
|
74
|
+
*/
|
|
75
|
+
function TextField(_ref4) {
|
|
76
|
+
var label = _ref4.label,
|
|
77
|
+
name = _ref4.name,
|
|
78
|
+
validationHelpText = _ref4.validationHelpText;
|
|
79
|
+
return (0, _react2.jsx)(_form.Field, {
|
|
80
|
+
name: name,
|
|
81
|
+
label: label,
|
|
82
|
+
isRequired: true
|
|
83
|
+
}, function (_ref5) {
|
|
84
|
+
var fieldProps = _ref5.fieldProps,
|
|
85
|
+
error = _ref5.error;
|
|
86
|
+
return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_textfield.default, fieldProps), !error && (0, _react2.jsx)(_form.HelperMessage, null, validationHelpText), error && (0, _react2.jsx)(_form.ErrorMessage, null, error));
|
|
87
|
+
});
|
|
38
88
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.validateFormData = validateFormData;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
/** Map of field names to errors for that field (or undefined if no error for that field) */
|
|
11
|
+
|
|
12
|
+
function isOption(maybeOption) {
|
|
13
|
+
return maybeOption !== undefined && maybeOption !== null && maybeOption.value !== undefined && typeof maybeOption.value === 'string';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns an object where the keys are names of form fields, and values are a string if the field
|
|
17
|
+
* has an error, or undefined if the field is valid.
|
|
18
|
+
*/
|
|
19
|
+
function validateFormData(_x) {
|
|
20
|
+
return _validateFormData.apply(this, arguments);
|
|
21
|
+
}
|
|
22
|
+
function _validateFormData() {
|
|
23
|
+
_validateFormData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
|
|
24
|
+
var data, validators, map, i, v, fieldName, maybeValue;
|
|
25
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
26
|
+
while (1) {
|
|
27
|
+
switch (_context.prev = _context.next) {
|
|
28
|
+
case 0:
|
|
29
|
+
data = _ref.data, validators = _ref.validators;
|
|
30
|
+
// Run each validator on the input.
|
|
31
|
+
map = {};
|
|
32
|
+
i = 0;
|
|
33
|
+
case 3:
|
|
34
|
+
if (!(i < validators.length)) {
|
|
35
|
+
_context.next = 26;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
v = validators[i];
|
|
39
|
+
fieldName = v.fieldName;
|
|
40
|
+
maybeValue = data[fieldName]; // If maybeValue is undefined, the fieldname of the current validator doesn't exist
|
|
41
|
+
// in our form.
|
|
42
|
+
// Value should always be in form, but if not, check if it's undefined here
|
|
43
|
+
if (!(maybeValue === undefined || maybeValue === null)) {
|
|
44
|
+
_context.next = 9;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return _context.abrupt("continue", 23);
|
|
48
|
+
case 9:
|
|
49
|
+
_context.t0 = typeof maybeValue === 'string';
|
|
50
|
+
if (!_context.t0) {
|
|
51
|
+
_context.next = 14;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
_context.next = 13;
|
|
55
|
+
return v.isInvalid(maybeValue);
|
|
56
|
+
case 13:
|
|
57
|
+
_context.t0 = _context.sent;
|
|
58
|
+
case 14:
|
|
59
|
+
if (!_context.t0) {
|
|
60
|
+
_context.next = 16;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
map[v.fieldName] = v.errorMessage;
|
|
64
|
+
case 16:
|
|
65
|
+
_context.t1 = isOption(maybeValue);
|
|
66
|
+
if (!_context.t1) {
|
|
67
|
+
_context.next = 21;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
_context.next = 20;
|
|
71
|
+
return v.isInvalid(maybeValue.value);
|
|
72
|
+
case 20:
|
|
73
|
+
_context.t1 = _context.sent;
|
|
74
|
+
case 21:
|
|
75
|
+
if (!_context.t1) {
|
|
76
|
+
_context.next = 23;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
map[v.fieldName] = v.errorMessage;
|
|
80
|
+
case 23:
|
|
81
|
+
i++;
|
|
82
|
+
_context.next = 3;
|
|
83
|
+
break;
|
|
84
|
+
case 26:
|
|
85
|
+
return _context.abrupt("return", map);
|
|
86
|
+
case 27:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, _callee);
|
|
92
|
+
}));
|
|
93
|
+
return _validateFormData.apply(this, arguments);
|
|
94
|
+
}
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './ui/index';
|
|
1
|
+
export { default, TextField, Select } from './ui/index';
|
|
2
2
|
export { useLinkCreateCallback } from './controllers/callback-context/index';
|
package/dist/es2019/ui/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './main';
|
|
1
|
+
export { default, TextField, Select } from './main';
|
package/dist/es2019/ui/main.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
/** @jsx jsx */
|
|
3
|
+
import { Fragment } from 'react';
|
|
2
4
|
import { jsx } from '@emotion/react';
|
|
3
|
-
import
|
|
5
|
+
import { ErrorMessage, Field, HelperMessage } from '@atlaskit/form';
|
|
6
|
+
import Modal, { ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
|
|
7
|
+
import AkSelect from '@atlaskit/select';
|
|
8
|
+
import AkTextfield from '@atlaskit/textfield';
|
|
4
9
|
import { LinkCreateCallbackProvider } from '../controllers/callback-context';
|
|
5
10
|
export default function LinkCreate({
|
|
6
11
|
plugins,
|
|
@@ -19,9 +24,51 @@ export default function LinkCreate({
|
|
|
19
24
|
return jsx(ModalTransition, null, !!active && jsx(Modal, {
|
|
20
25
|
onClose: onCancel,
|
|
21
26
|
testId: testId
|
|
22
|
-
}, jsx(
|
|
27
|
+
}, jsx(ModalHeader, null, jsx(ModalTitle, null, "Create New")), jsx(LinkCreateCallbackProvider, {
|
|
23
28
|
onCreate: onCreate,
|
|
24
29
|
onFailure: onFailure,
|
|
25
30
|
onCancel: onCancel
|
|
26
|
-
}, chosenOne.form)))
|
|
31
|
+
}, chosenOne.form)));
|
|
32
|
+
}
|
|
33
|
+
export function Select({
|
|
34
|
+
name,
|
|
35
|
+
title,
|
|
36
|
+
options,
|
|
37
|
+
defaultOption,
|
|
38
|
+
placeholder
|
|
39
|
+
}) {
|
|
40
|
+
return jsx(Field, {
|
|
41
|
+
name: name,
|
|
42
|
+
label: title,
|
|
43
|
+
isRequired: true
|
|
44
|
+
}, ({
|
|
45
|
+
fieldProps,
|
|
46
|
+
error
|
|
47
|
+
}) => jsx(Fragment, null, error && jsx(ErrorMessage, null, error), jsx(AkSelect, _extends({}, fieldProps, {
|
|
48
|
+
inputId: `${title}-input-id`,
|
|
49
|
+
options: options,
|
|
50
|
+
placeholder: placeholder,
|
|
51
|
+
defaultValue: defaultOption
|
|
52
|
+
}))));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A text field utilising the Atlaskit Textfield and Field objects from `@atlaskit/form`.
|
|
57
|
+
* Validation is handled by the form as it is on form submission. Any errors returned by
|
|
58
|
+
* the handleSubmit function passed to the form <Form> that have a key matching the `name`
|
|
59
|
+
* of this text field are shown above the field.
|
|
60
|
+
*/
|
|
61
|
+
export function TextField({
|
|
62
|
+
label,
|
|
63
|
+
name,
|
|
64
|
+
validationHelpText
|
|
65
|
+
}) {
|
|
66
|
+
return jsx(Field, {
|
|
67
|
+
name: name,
|
|
68
|
+
label: label,
|
|
69
|
+
isRequired: true
|
|
70
|
+
}, ({
|
|
71
|
+
fieldProps,
|
|
72
|
+
error
|
|
73
|
+
}) => jsx(Fragment, null, jsx(AkTextfield, fieldProps), !error && jsx(HelperMessage, null, validationHelpText), error && jsx(ErrorMessage, null, error)));
|
|
27
74
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Map of field names to errors for that field (or undefined if no error for that field) */
|
|
2
|
+
|
|
3
|
+
function isOption(maybeOption) {
|
|
4
|
+
return maybeOption !== undefined && maybeOption !== null && maybeOption.value !== undefined && typeof maybeOption.value === 'string';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Returns an object where the keys are names of form fields, and values are a string if the field
|
|
8
|
+
* has an error, or undefined if the field is valid.
|
|
9
|
+
*/
|
|
10
|
+
export async function validateFormData({
|
|
11
|
+
data,
|
|
12
|
+
validators
|
|
13
|
+
}) {
|
|
14
|
+
// Run each validator on the input.
|
|
15
|
+
const map = {};
|
|
16
|
+
for (let i = 0; i < validators.length; i++) {
|
|
17
|
+
const v = validators[i];
|
|
18
|
+
const fieldName = v.fieldName;
|
|
19
|
+
const maybeValue = data[fieldName];
|
|
20
|
+
|
|
21
|
+
// If maybeValue is undefined, the fieldname of the current validator doesn't exist
|
|
22
|
+
// in our form.
|
|
23
|
+
// Value should always be in form, but if not, check if it's undefined here
|
|
24
|
+
if (maybeValue === undefined || maybeValue === null) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (typeof maybeValue === 'string' && (await v.isInvalid(maybeValue))) {
|
|
28
|
+
map[v.fieldName] = v.errorMessage;
|
|
29
|
+
}
|
|
30
|
+
if (isOption(maybeValue) && (await v.isInvalid(maybeValue.value))) {
|
|
31
|
+
map[v.fieldName] = v.errorMessage;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return map;
|
|
35
|
+
}
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './ui/index';
|
|
1
|
+
export { default, TextField, Select } from './ui/index';
|
|
2
2
|
export { useLinkCreateCallback } from './controllers/callback-context/index';
|
package/dist/esm/ui/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './main';
|
|
1
|
+
export { default, TextField, Select } from './main';
|
package/dist/esm/ui/main.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
/** @jsx jsx */
|
|
3
|
+
import { Fragment } from 'react';
|
|
2
4
|
import { jsx } from '@emotion/react';
|
|
3
|
-
import
|
|
5
|
+
import { ErrorMessage, Field, HelperMessage } from '@atlaskit/form';
|
|
6
|
+
import Modal, { ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
|
|
7
|
+
import AkSelect from '@atlaskit/select';
|
|
8
|
+
import AkTextfield from '@atlaskit/textfield';
|
|
4
9
|
import { LinkCreateCallbackProvider } from '../controllers/callback-context';
|
|
5
10
|
export default function LinkCreate(_ref) {
|
|
6
11
|
var plugins = _ref.plugins,
|
|
@@ -20,9 +25,51 @@ export default function LinkCreate(_ref) {
|
|
|
20
25
|
return jsx(ModalTransition, null, !!active && jsx(Modal, {
|
|
21
26
|
onClose: onCancel,
|
|
22
27
|
testId: testId
|
|
23
|
-
}, jsx(
|
|
28
|
+
}, jsx(ModalHeader, null, jsx(ModalTitle, null, "Create New")), jsx(LinkCreateCallbackProvider, {
|
|
24
29
|
onCreate: onCreate,
|
|
25
30
|
onFailure: onFailure,
|
|
26
31
|
onCancel: onCancel
|
|
27
|
-
}, chosenOne.form)))
|
|
32
|
+
}, chosenOne.form)));
|
|
33
|
+
}
|
|
34
|
+
export function Select(_ref2) {
|
|
35
|
+
var name = _ref2.name,
|
|
36
|
+
title = _ref2.title,
|
|
37
|
+
options = _ref2.options,
|
|
38
|
+
defaultOption = _ref2.defaultOption,
|
|
39
|
+
placeholder = _ref2.placeholder;
|
|
40
|
+
return jsx(Field, {
|
|
41
|
+
name: name,
|
|
42
|
+
label: title,
|
|
43
|
+
isRequired: true
|
|
44
|
+
}, function (_ref3) {
|
|
45
|
+
var fieldProps = _ref3.fieldProps,
|
|
46
|
+
error = _ref3.error;
|
|
47
|
+
return jsx(Fragment, null, error && jsx(ErrorMessage, null, error), jsx(AkSelect, _extends({}, fieldProps, {
|
|
48
|
+
inputId: "".concat(title, "-input-id"),
|
|
49
|
+
options: options,
|
|
50
|
+
placeholder: placeholder,
|
|
51
|
+
defaultValue: defaultOption
|
|
52
|
+
})));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A text field utilising the Atlaskit Textfield and Field objects from `@atlaskit/form`.
|
|
58
|
+
* Validation is handled by the form as it is on form submission. Any errors returned by
|
|
59
|
+
* the handleSubmit function passed to the form <Form> that have a key matching the `name`
|
|
60
|
+
* of this text field are shown above the field.
|
|
61
|
+
*/
|
|
62
|
+
export function TextField(_ref4) {
|
|
63
|
+
var label = _ref4.label,
|
|
64
|
+
name = _ref4.name,
|
|
65
|
+
validationHelpText = _ref4.validationHelpText;
|
|
66
|
+
return jsx(Field, {
|
|
67
|
+
name: name,
|
|
68
|
+
label: label,
|
|
69
|
+
isRequired: true
|
|
70
|
+
}, function (_ref5) {
|
|
71
|
+
var fieldProps = _ref5.fieldProps,
|
|
72
|
+
error = _ref5.error;
|
|
73
|
+
return jsx(Fragment, null, jsx(AkTextfield, fieldProps), !error && jsx(HelperMessage, null, validationHelpText), error && jsx(ErrorMessage, null, error));
|
|
74
|
+
});
|
|
28
75
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
/** Map of field names to errors for that field (or undefined if no error for that field) */
|
|
4
|
+
|
|
5
|
+
function isOption(maybeOption) {
|
|
6
|
+
return maybeOption !== undefined && maybeOption !== null && maybeOption.value !== undefined && typeof maybeOption.value === 'string';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns an object where the keys are names of form fields, and values are a string if the field
|
|
10
|
+
* has an error, or undefined if the field is valid.
|
|
11
|
+
*/
|
|
12
|
+
export function validateFormData(_x) {
|
|
13
|
+
return _validateFormData.apply(this, arguments);
|
|
14
|
+
}
|
|
15
|
+
function _validateFormData() {
|
|
16
|
+
_validateFormData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
17
|
+
var data, validators, map, i, v, fieldName, maybeValue;
|
|
18
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
19
|
+
while (1) {
|
|
20
|
+
switch (_context.prev = _context.next) {
|
|
21
|
+
case 0:
|
|
22
|
+
data = _ref.data, validators = _ref.validators;
|
|
23
|
+
// Run each validator on the input.
|
|
24
|
+
map = {};
|
|
25
|
+
i = 0;
|
|
26
|
+
case 3:
|
|
27
|
+
if (!(i < validators.length)) {
|
|
28
|
+
_context.next = 26;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
v = validators[i];
|
|
32
|
+
fieldName = v.fieldName;
|
|
33
|
+
maybeValue = data[fieldName]; // If maybeValue is undefined, the fieldname of the current validator doesn't exist
|
|
34
|
+
// in our form.
|
|
35
|
+
// Value should always be in form, but if not, check if it's undefined here
|
|
36
|
+
if (!(maybeValue === undefined || maybeValue === null)) {
|
|
37
|
+
_context.next = 9;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return _context.abrupt("continue", 23);
|
|
41
|
+
case 9:
|
|
42
|
+
_context.t0 = typeof maybeValue === 'string';
|
|
43
|
+
if (!_context.t0) {
|
|
44
|
+
_context.next = 14;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
_context.next = 13;
|
|
48
|
+
return v.isInvalid(maybeValue);
|
|
49
|
+
case 13:
|
|
50
|
+
_context.t0 = _context.sent;
|
|
51
|
+
case 14:
|
|
52
|
+
if (!_context.t0) {
|
|
53
|
+
_context.next = 16;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
map[v.fieldName] = v.errorMessage;
|
|
57
|
+
case 16:
|
|
58
|
+
_context.t1 = isOption(maybeValue);
|
|
59
|
+
if (!_context.t1) {
|
|
60
|
+
_context.next = 21;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
_context.next = 20;
|
|
64
|
+
return v.isInvalid(maybeValue.value);
|
|
65
|
+
case 20:
|
|
66
|
+
_context.t1 = _context.sent;
|
|
67
|
+
case 21:
|
|
68
|
+
if (!_context.t1) {
|
|
69
|
+
_context.next = 23;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
map[v.fieldName] = v.errorMessage;
|
|
73
|
+
case 23:
|
|
74
|
+
i++;
|
|
75
|
+
_context.next = 3;
|
|
76
|
+
break;
|
|
77
|
+
case 26:
|
|
78
|
+
return _context.abrupt("return", map);
|
|
79
|
+
case 27:
|
|
80
|
+
case "end":
|
|
81
|
+
return _context.stop();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}, _callee);
|
|
85
|
+
}));
|
|
86
|
+
return _validateFormData.apply(this, arguments);
|
|
87
|
+
}
|
package/dist/esm/version.json
CHANGED
package/dist/types/index.d.ts
CHANGED
package/dist/types/ui/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './main';
|
|
1
|
+
export { default, TextField, Select } from './main';
|
package/dist/types/ui/main.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
1
|
import { jsx } from '@emotion/react';
|
|
3
|
-
import { LinkCreateProps } from './types';
|
|
2
|
+
import { LinkCreateProps, SelectProps, TextFieldProps } from './types';
|
|
4
3
|
export default function LinkCreate({ plugins, testId, groupKey, entityKey, onCreate, onFailure, onCancel, active, }: LinkCreateProps): jsx.JSX.Element;
|
|
4
|
+
export declare function Select({ name, title, options, defaultOption, placeholder, }: SelectProps): jsx.JSX.Element;
|
|
5
|
+
/**
|
|
6
|
+
* A text field utilising the Atlaskit Textfield and Field objects from `@atlaskit/form`.
|
|
7
|
+
* Validation is handled by the form as it is on form submission. Any errors returned by
|
|
8
|
+
* the handleSubmit function passed to the form <Form> that have a key matching the `name`
|
|
9
|
+
* of this text field are shown above the field.
|
|
10
|
+
*/
|
|
11
|
+
export declare function TextField({ label, name, validationHelpText }: TextFieldProps): jsx.JSX.Element;
|
package/dist/types/ui/types.d.ts
CHANGED
|
@@ -59,3 +59,45 @@ export interface LinkCreateProps {
|
|
|
59
59
|
*/
|
|
60
60
|
active?: boolean;
|
|
61
61
|
}
|
|
62
|
+
export declare type Validator<FieldName extends string> = {
|
|
63
|
+
/** The field of the form that should be validated (eg. referencing name of TextFieldProps) */
|
|
64
|
+
fieldName: FieldName;
|
|
65
|
+
/** Return true when the given input is invalid */
|
|
66
|
+
isInvalid: (val: string) => Promise<boolean>;
|
|
67
|
+
/** An error message is used to tell a user that the field input is invalid. For example, an error message could be 'Invalid username, needs to be more than 4 characters'. */
|
|
68
|
+
errorMessage: string;
|
|
69
|
+
};
|
|
70
|
+
export interface TextFieldProps {
|
|
71
|
+
/** Name passed to the <Field>.*/
|
|
72
|
+
name: string;
|
|
73
|
+
/** This should be properly internationalization-ed */
|
|
74
|
+
label: string;
|
|
75
|
+
/**
|
|
76
|
+
* Optional text below the textfield explaining any requirements for a valid value.
|
|
77
|
+
* eg. "Must be 4 or more letters"
|
|
78
|
+
*/
|
|
79
|
+
validationHelpText?: string;
|
|
80
|
+
}
|
|
81
|
+
export interface Option {
|
|
82
|
+
/** html `value` attribute to differentiate options */
|
|
83
|
+
value: string;
|
|
84
|
+
/** This should be properly internationalization-ed */
|
|
85
|
+
label: string;
|
|
86
|
+
}
|
|
87
|
+
export interface SelectProps {
|
|
88
|
+
name: string;
|
|
89
|
+
title: string;
|
|
90
|
+
/** Placeholder to go in the select */
|
|
91
|
+
placeholder?: string;
|
|
92
|
+
/** Options available in the select */
|
|
93
|
+
options: Option[];
|
|
94
|
+
/** Default select option */
|
|
95
|
+
defaultOption?: Option;
|
|
96
|
+
}
|
|
97
|
+
export interface FormProps<Fields extends string> {
|
|
98
|
+
/**
|
|
99
|
+
* Each validator will run on form submit. If multiple validators for a given field, the
|
|
100
|
+
* last validator's error will be shown
|
|
101
|
+
*/
|
|
102
|
+
validators: Validator<Fields>[];
|
|
103
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Validator } from './ui/types';
|
|
2
|
+
/** Map of field names to errors for that field (or undefined if no error for that field) */
|
|
3
|
+
export declare type ValidatorResults = {
|
|
4
|
+
[name: string]: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns an object where the keys are names of form fields, and values are a string if the field
|
|
8
|
+
* has an error, or undefined if the field is valid.
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateFormData({ data, validators, }: {
|
|
11
|
+
data: Record<string, unknown>;
|
|
12
|
+
validators: Validator<any>[];
|
|
13
|
+
}): Promise<ValidatorResults>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/link-create",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "The driver component of meta creation flow",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,9 +26,13 @@
|
|
|
26
26
|
".": "./src/index.ts"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@atlaskit/form": "^8.8.4",
|
|
29
30
|
"@atlaskit/modal-dialog": "^12.4.4",
|
|
31
|
+
"@atlaskit/select": "^16.1.3",
|
|
32
|
+
"@atlaskit/textfield": "^5.3.5",
|
|
30
33
|
"@babel/runtime": "^7.0.0",
|
|
31
|
-
"@emotion/react": "^11.7.1"
|
|
34
|
+
"@emotion/react": "^11.7.1",
|
|
35
|
+
"react-select": "^5.4.0"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
38
|
"react": "^16.8.0"
|
|
@@ -40,6 +44,7 @@
|
|
|
40
44
|
"@atlaskit/visual-regression": "*",
|
|
41
45
|
"@atlaskit/webdriver-runner": "*",
|
|
42
46
|
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
47
|
+
"@atlassian/link-create-confluence": "^0.0.2",
|
|
43
48
|
"@testing-library/react": "^12.1.5",
|
|
44
49
|
"react-dom": "^16.8.0",
|
|
45
50
|
"typescript": "4.5.5",
|
package/report.api.md
CHANGED
|
@@ -46,7 +46,7 @@ interface LinkCreateCallbackProviderProps {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// @public (undocumented)
|
|
49
|
-
interface LinkCreatePlugin {
|
|
49
|
+
export interface LinkCreatePlugin {
|
|
50
50
|
form: ReactNode;
|
|
51
51
|
group: Group;
|
|
52
52
|
icon: string;
|
|
@@ -67,6 +67,46 @@ interface LinkCreateProps {
|
|
|
67
67
|
testId?: string;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// @public (undocumented)
|
|
71
|
+
interface Option_2 {
|
|
72
|
+
label: string;
|
|
73
|
+
value: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// @public (undocumented)
|
|
77
|
+
export function Select({
|
|
78
|
+
name,
|
|
79
|
+
title,
|
|
80
|
+
options,
|
|
81
|
+
defaultOption,
|
|
82
|
+
placeholder,
|
|
83
|
+
}: SelectProps): jsx.JSX.Element;
|
|
84
|
+
|
|
85
|
+
// @public (undocumented)
|
|
86
|
+
interface SelectProps {
|
|
87
|
+
defaultOption?: Option_2;
|
|
88
|
+
// (undocumented)
|
|
89
|
+
name: string;
|
|
90
|
+
options: Option_2[];
|
|
91
|
+
placeholder?: string;
|
|
92
|
+
// (undocumented)
|
|
93
|
+
title: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// @public
|
|
97
|
+
export function TextField({
|
|
98
|
+
label,
|
|
99
|
+
name,
|
|
100
|
+
validationHelpText,
|
|
101
|
+
}: TextFieldProps): jsx.JSX.Element;
|
|
102
|
+
|
|
103
|
+
// @public (undocumented)
|
|
104
|
+
interface TextFieldProps {
|
|
105
|
+
label: string;
|
|
106
|
+
name: string;
|
|
107
|
+
validationHelpText?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
70
110
|
// @public (undocumented)
|
|
71
111
|
export const useLinkCreateCallback: () => LinkCreateCallbackProviderProps;
|
|
72
112
|
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ interface LinkCreateCallbackProviderProps {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// @public (undocumented)
|
|
29
|
-
interface LinkCreatePlugin {
|
|
29
|
+
export interface LinkCreatePlugin {
|
|
30
30
|
form: ReactNode;
|
|
31
31
|
group: Group;
|
|
32
32
|
icon: string;
|
|
@@ -47,6 +47,36 @@ interface LinkCreateProps {
|
|
|
47
47
|
testId?: string;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// @public (undocumented)
|
|
51
|
+
interface Option_2 {
|
|
52
|
+
label: string;
|
|
53
|
+
value: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// @public (undocumented)
|
|
57
|
+
export function Select({ name, title, options, defaultOption, placeholder, }: SelectProps): jsx.JSX.Element;
|
|
58
|
+
|
|
59
|
+
// @public (undocumented)
|
|
60
|
+
interface SelectProps {
|
|
61
|
+
defaultOption?: Option_2;
|
|
62
|
+
// (undocumented)
|
|
63
|
+
name: string;
|
|
64
|
+
options: Option_2[];
|
|
65
|
+
placeholder?: string;
|
|
66
|
+
// (undocumented)
|
|
67
|
+
title: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// @public
|
|
71
|
+
export function TextField({ label, name, validationHelpText }: TextFieldProps): jsx.JSX.Element;
|
|
72
|
+
|
|
73
|
+
// @public (undocumented)
|
|
74
|
+
interface TextFieldProps {
|
|
75
|
+
label: string;
|
|
76
|
+
name: string;
|
|
77
|
+
validationHelpText?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
50
80
|
// @public (undocumented)
|
|
51
81
|
export const useLinkCreateCallback: () => LinkCreateCallbackProviderProps;
|
|
52
82
|
|