@atlaskit/smart-card 17.3.1 → 17.3.2
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 +6 -0
- package/dist/cjs/constants.js +15 -1
- package/dist/cjs/extractors/flexible/index.js +2 -0
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/FlexibleCard/components/blocks/utils.js +15 -3
- package/dist/cjs/view/FlexibleCard/components/elements/index.js +3 -1
- package/dist/cjs/view/FlexibleCard/components/elements/text/index.js +6 -2
- package/dist/cjs/view/FlexibleCard/components/elements/utils.js +14 -0
- package/dist/es2019/constants.js +14 -1
- package/dist/es2019/extractors/flexible/index.js +3 -1
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/FlexibleCard/components/blocks/utils.js +27 -4
- package/dist/es2019/view/FlexibleCard/components/elements/index.js +1 -0
- package/dist/es2019/view/FlexibleCard/components/elements/text/index.js +5 -3
- package/dist/es2019/view/FlexibleCard/components/elements/utils.js +15 -0
- package/dist/esm/constants.js +14 -1
- package/dist/esm/extractors/flexible/index.js +3 -1
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/FlexibleCard/components/blocks/utils.js +14 -4
- package/dist/esm/view/FlexibleCard/components/elements/index.js +1 -0
- package/dist/esm/view/FlexibleCard/components/elements/text/index.js +7 -2
- package/dist/esm/view/FlexibleCard/components/elements/utils.js +14 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/state/flexible-ui-context/types.d.ts +3 -2
- package/dist/types/view/FlexibleCard/components/blocks/utils.d.ts +4 -2
- package/dist/types/view/FlexibleCard/components/elements/index.d.ts +1 -0
- package/dist/types/view/FlexibleCard/components/elements/text/types.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/constants.js
CHANGED
|
@@ -60,7 +60,20 @@ exports.SmartLinkTheme = SmartLinkTheme;
|
|
|
60
60
|
SmartLinkTheme["Link"] = "link";
|
|
61
61
|
})(SmartLinkTheme || (exports.SmartLinkTheme = SmartLinkTheme = {}));
|
|
62
62
|
|
|
63
|
-
var SmartLinkWidth;
|
|
63
|
+
var SmartLinkWidth; // When adding an element...
|
|
64
|
+
// 1) Create base element if it doesn't already existed.
|
|
65
|
+
// Base element are inside src/view/FlexibleCard/components/elements.
|
|
66
|
+
// E.g. Badge,DateTime, Icon, Lozenge, etc.
|
|
67
|
+
// 2) Update FlexibleUiContext with the new prop for data representing
|
|
68
|
+
// the element, preferably with the same name as the element itself.
|
|
69
|
+
// (src/state/flexible-ui-context/types.ts)
|
|
70
|
+
// 3) Update Flexible UI extractor (src/extractors/flexible/index.ts)
|
|
71
|
+
// 4) Set base element and data mapping.
|
|
72
|
+
// (src/view/FlexibleCard/components/elements/utils.tsx)
|
|
73
|
+
// 5) Create element. (src/view/FlexibleCard/components/elements/index.ts)
|
|
74
|
+
// 6) Update element ElementDisplaySchema for inline/block display
|
|
75
|
+
// (src/view/FlexibleCard/components/blocks/utils.tsx)
|
|
76
|
+
|
|
64
77
|
exports.SmartLinkWidth = SmartLinkWidth;
|
|
65
78
|
|
|
66
79
|
(function (SmartLinkWidth) {
|
|
@@ -82,6 +95,7 @@ exports.ElementName = ElementName;
|
|
|
82
95
|
ElementName["ModifiedOn"] = "ModifiedOn";
|
|
83
96
|
ElementName["Priority"] = "Priority";
|
|
84
97
|
ElementName["ProgrammingLanguage"] = "ProgrammingLanguage";
|
|
98
|
+
ElementName["Snippet"] = "Snippet";
|
|
85
99
|
ElementName["State"] = "State";
|
|
86
100
|
ElementName["SubscriberCount"] = "SubscriberCount";
|
|
87
101
|
ElementName["Title"] = "Title";
|
|
@@ -43,6 +43,8 @@ var extractFlexibleUiContext = function extractFlexibleUiContext(response, rende
|
|
|
43
43
|
modifiedOn: (0, _extractDateUpdated.extractDateUpdated)(data),
|
|
44
44
|
priority: (0, _extractPriority.default)(data),
|
|
45
45
|
programmingLanguage: (0, _utils.extractProgrammingLanguage)(data),
|
|
46
|
+
snippet: (0, _primitives.extractSummary)(data) || undefined,
|
|
47
|
+
// Explicitly set here to remove an empty string
|
|
46
48
|
state: (0, _lozenge.extractLozenge)(data),
|
|
47
49
|
subscriberCount: (0, _utils.extractSubscriberCount)(data),
|
|
48
50
|
title: (0, _primitives.extractTitle)(data) || url,
|
package/dist/cjs/version.json
CHANGED
|
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
exports.renderElementItems = exports.renderChildren = exports.renderActionItems = exports.getGapSize = exports.getBaseStyles = void 0;
|
|
10
|
+
exports.renderElementItems = exports.renderChildren = exports.renderActionItems = exports.getGapSize = exports.getBaseStyles = exports.ElementDisplaySchema = void 0;
|
|
11
11
|
|
|
12
12
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
13
|
|
|
@@ -17,6 +17,8 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
17
17
|
|
|
18
18
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
19
19
|
|
|
20
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
+
|
|
20
22
|
var _react = _interopRequireDefault(require("react"));
|
|
21
23
|
|
|
22
24
|
var _core = require("@emotion/core");
|
|
@@ -36,12 +38,15 @@ var _elementGroup = _interopRequireDefault(require("./element-group"));
|
|
|
36
38
|
var _excluded = ["name"],
|
|
37
39
|
_excluded2 = ["name"];
|
|
38
40
|
|
|
39
|
-
var _templateObject, _templateObject2, _templateObject3;
|
|
41
|
+
var _ElementDisplaySchema, _templateObject, _templateObject2, _templateObject3;
|
|
40
42
|
|
|
41
43
|
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); }
|
|
42
44
|
|
|
43
45
|
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; }
|
|
44
46
|
|
|
47
|
+
var ElementDisplaySchema = (_ElementDisplaySchema = {}, (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.AuthorGroup, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.CollaboratorGroup, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.CommentCount, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.CreatedBy, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.CreatedOn, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.LinkIcon, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.ModifiedBy, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.ModifiedOn, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.Priority, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.ProgrammingLanguage, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.Snippet, ['block']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.State, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.SubscriberCount, ['inline']), (0, _defineProperty2.default)(_ElementDisplaySchema, _constants.ElementName.Title, ['inline']), _ElementDisplaySchema);
|
|
48
|
+
exports.ElementDisplaySchema = ElementDisplaySchema;
|
|
49
|
+
|
|
45
50
|
var getDirectionStyles = function getDirectionStyles(direction) {
|
|
46
51
|
switch (direction) {
|
|
47
52
|
case _constants.SmartLinkDirection.Vertical:
|
|
@@ -82,6 +87,12 @@ var isActionGroup = function isActionGroup(node) {
|
|
|
82
87
|
return /*#__PURE__*/_react.default.isValidElement(node) && node.type === _actionGroup.default;
|
|
83
88
|
};
|
|
84
89
|
|
|
90
|
+
var isElementDisplayValid = function isElementDisplayValid(name, display) {
|
|
91
|
+
var _ElementDisplaySchema2, _ElementDisplaySchema3;
|
|
92
|
+
|
|
93
|
+
return (_ElementDisplaySchema2 = (_ElementDisplaySchema3 = ElementDisplaySchema[name]) === null || _ElementDisplaySchema3 === void 0 ? void 0 : _ElementDisplaySchema3.includes(display)) !== null && _ElementDisplaySchema2 !== void 0 ? _ElementDisplaySchema2 : false;
|
|
94
|
+
};
|
|
95
|
+
|
|
85
96
|
var isElementNull = function isElementNull(children) {
|
|
86
97
|
return Boolean(children.type() === null);
|
|
87
98
|
};
|
|
@@ -108,12 +119,13 @@ exports.renderChildren = renderChildren;
|
|
|
108
119
|
|
|
109
120
|
var renderElementItems = function renderElementItems() {
|
|
110
121
|
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
122
|
+
var display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'inline';
|
|
111
123
|
var elements = items.reduce(function (acc, curr, idx) {
|
|
112
124
|
var name = curr.name,
|
|
113
125
|
props = (0, _objectWithoutProperties2.default)(curr, _excluded);
|
|
114
126
|
var Element = Elements[name];
|
|
115
127
|
|
|
116
|
-
if (Element) {
|
|
128
|
+
if (Element && isElementDisplayValid(name, display)) {
|
|
117
129
|
var element = /*#__PURE__*/_react.default.createElement(Element, (0, _extends2.default)({
|
|
118
130
|
key: idx
|
|
119
131
|
}, props));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Title = exports.SubscriberCount = exports.State = exports.ProgrammingLanguage = exports.Priority = exports.ModifiedOn = exports.ModifiedBy = exports.LinkIcon = exports.CreatedOn = exports.CreatedBy = exports.CommentCount = exports.CollaboratorGroup = exports.AuthorGroup = void 0;
|
|
6
|
+
exports.Title = exports.SubscriberCount = exports.State = exports.Snippet = exports.ProgrammingLanguage = exports.Priority = exports.ModifiedOn = exports.ModifiedBy = exports.LinkIcon = exports.CreatedOn = exports.CreatedBy = exports.CommentCount = exports.CollaboratorGroup = exports.AuthorGroup = void 0;
|
|
7
7
|
|
|
8
8
|
var _utils = require("./utils");
|
|
9
9
|
|
|
@@ -32,6 +32,8 @@ var Priority = (0, _utils.createElement)(_constants.ElementName.Priority);
|
|
|
32
32
|
exports.Priority = Priority;
|
|
33
33
|
var ProgrammingLanguage = (0, _utils.createElement)(_constants.ElementName.ProgrammingLanguage);
|
|
34
34
|
exports.ProgrammingLanguage = ProgrammingLanguage;
|
|
35
|
+
var Snippet = (0, _utils.createElement)(_constants.ElementName.Snippet);
|
|
36
|
+
exports.Snippet = Snippet;
|
|
35
37
|
var State = (0, _utils.createElement)(_constants.ElementName.State);
|
|
36
38
|
exports.State = State;
|
|
37
39
|
var SubscriberCount = (0, _utils.createElement)(_constants.ElementName.SubscriberCount);
|
|
@@ -19,10 +19,14 @@ var _token = require("../../../../../utils/token");
|
|
|
19
19
|
|
|
20
20
|
var _templateObject;
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var getStyles = function getStyles(maxLines) {
|
|
23
|
+
return (0, _core.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n color: ", ";\n font-size: 0.75rem;\n line-height: 1rem;\n ", "\n"])), _token.tokens.text, (0, _utils.getTruncateStyles)(maxLines));
|
|
24
|
+
};
|
|
23
25
|
|
|
24
26
|
var Text = function Text(_ref) {
|
|
25
27
|
var content = _ref.content,
|
|
28
|
+
_ref$maxLines = _ref.maxLines,
|
|
29
|
+
maxLines = _ref$maxLines === void 0 ? 1 : _ref$maxLines,
|
|
26
30
|
message = _ref.message,
|
|
27
31
|
_ref$testId = _ref.testId,
|
|
28
32
|
testId = _ref$testId === void 0 ? 'smart-element-text' : _ref$testId;
|
|
@@ -32,7 +36,7 @@ var Text = function Text(_ref) {
|
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
return (0, _core.jsx)("span", {
|
|
35
|
-
css:
|
|
39
|
+
css: getStyles(maxLines),
|
|
36
40
|
"data-smart-element-text": true,
|
|
37
41
|
"data-testid": testId
|
|
38
42
|
}, (0, _utils.getFormattedMessage)(message) || content);
|
|
@@ -63,6 +63,11 @@ var elementMappings = (_elementMappings = {}, (0, _defineProperty2.default)(_ele
|
|
|
63
63
|
props: {
|
|
64
64
|
icon: _constants.IconType.ProgrammingLanguage
|
|
65
65
|
}
|
|
66
|
+
}), (0, _defineProperty2.default)(_elementMappings, _constants.ElementName.Snippet, {
|
|
67
|
+
component: _text.default,
|
|
68
|
+
props: {
|
|
69
|
+
maxLines: 3
|
|
70
|
+
}
|
|
66
71
|
}), (0, _defineProperty2.default)(_elementMappings, _constants.ElementName.State, {
|
|
67
72
|
component: _lozenge.default
|
|
68
73
|
}), (0, _defineProperty2.default)(_elementMappings, _constants.ElementName.SubscriberCount, {
|
|
@@ -113,6 +118,9 @@ var getData = function getData(elementName, contextKey, context) {
|
|
|
113
118
|
case _constants.ElementName.ModifiedOn:
|
|
114
119
|
return toDateTimeProps('modified', context.modifiedOn);
|
|
115
120
|
|
|
121
|
+
case _constants.ElementName.Snippet:
|
|
122
|
+
return toTextProps(data);
|
|
123
|
+
|
|
116
124
|
case _constants.ElementName.Title:
|
|
117
125
|
return toLinkProps(context.title, context.url);
|
|
118
126
|
|
|
@@ -158,6 +166,12 @@ var toLinkProps = function toLinkProps(text, url) {
|
|
|
158
166
|
} : undefined;
|
|
159
167
|
};
|
|
160
168
|
|
|
169
|
+
var toTextProps = function toTextProps(content) {
|
|
170
|
+
return content ? {
|
|
171
|
+
content: content
|
|
172
|
+
} : undefined;
|
|
173
|
+
};
|
|
174
|
+
|
|
161
175
|
var createElement = function createElement(name) {
|
|
162
176
|
var _ref = elementMappings[name] || {},
|
|
163
177
|
BaseElement = _ref.component,
|
package/dist/es2019/constants.js
CHANGED
|
@@ -48,7 +48,19 @@ export let SmartLinkTheme;
|
|
|
48
48
|
SmartLinkTheme["Link"] = "link";
|
|
49
49
|
})(SmartLinkTheme || (SmartLinkTheme = {}));
|
|
50
50
|
|
|
51
|
-
export let SmartLinkWidth;
|
|
51
|
+
export let SmartLinkWidth; // When adding an element...
|
|
52
|
+
// 1) Create base element if it doesn't already existed.
|
|
53
|
+
// Base element are inside src/view/FlexibleCard/components/elements.
|
|
54
|
+
// E.g. Badge,DateTime, Icon, Lozenge, etc.
|
|
55
|
+
// 2) Update FlexibleUiContext with the new prop for data representing
|
|
56
|
+
// the element, preferably with the same name as the element itself.
|
|
57
|
+
// (src/state/flexible-ui-context/types.ts)
|
|
58
|
+
// 3) Update Flexible UI extractor (src/extractors/flexible/index.ts)
|
|
59
|
+
// 4) Set base element and data mapping.
|
|
60
|
+
// (src/view/FlexibleCard/components/elements/utils.tsx)
|
|
61
|
+
// 5) Create element. (src/view/FlexibleCard/components/elements/index.ts)
|
|
62
|
+
// 6) Update element ElementDisplaySchema for inline/block display
|
|
63
|
+
// (src/view/FlexibleCard/components/blocks/utils.tsx)
|
|
52
64
|
|
|
53
65
|
(function (SmartLinkWidth) {
|
|
54
66
|
SmartLinkWidth["FitToContent"] = "fit-to-content";
|
|
@@ -68,6 +80,7 @@ export let ElementName;
|
|
|
68
80
|
ElementName["ModifiedOn"] = "ModifiedOn";
|
|
69
81
|
ElementName["Priority"] = "Priority";
|
|
70
82
|
ElementName["ProgrammingLanguage"] = "ProgrammingLanguage";
|
|
83
|
+
ElementName["Snippet"] = "Snippet";
|
|
71
84
|
ElementName["State"] = "State";
|
|
72
85
|
ElementName["SubscriberCount"] = "SubscriberCount";
|
|
73
86
|
ElementName["Title"] = "Title";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractLink, extractTitle } from '../common/primitives';
|
|
1
|
+
import { extractLink, extractSummary, extractTitle } from '../common/primitives';
|
|
2
2
|
import { extractLozenge } from '../common/lozenge';
|
|
3
3
|
import { extractLinkIcon } from './icon';
|
|
4
4
|
import { extractCommentCount, extractCreatedBy, extractModifiedBy, extractProgrammingLanguage, extractSubscriberCount } from './utils';
|
|
@@ -26,6 +26,8 @@ const extractFlexibleUiContext = (response, renderers) => {
|
|
|
26
26
|
modifiedOn: extractDateUpdated(data),
|
|
27
27
|
priority: extractPriority(data),
|
|
28
28
|
programmingLanguage: extractProgrammingLanguage(data),
|
|
29
|
+
snippet: extractSummary(data) || undefined,
|
|
30
|
+
// Explicitly set here to remove an empty string
|
|
29
31
|
state: extractLozenge(data),
|
|
30
32
|
subscriberCount: extractSubscriberCount(data),
|
|
31
33
|
title: extractTitle(data) || url,
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { css } from '@emotion/core';
|
|
4
|
-
import { SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
4
|
+
import { ElementName, SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
5
5
|
import * as Elements from '../elements';
|
|
6
6
|
import * as Actions from '../actions';
|
|
7
7
|
import { isFlexibleUiElement } from '../../../../utils/flexible';
|
|
8
8
|
import ActionGroup from './action-group';
|
|
9
|
-
import ElementGroup from './element-group';
|
|
9
|
+
import ElementGroup from './element-group'; // Determine whether the element can be display as inline/block.
|
|
10
|
+
|
|
11
|
+
export const ElementDisplaySchema = {
|
|
12
|
+
[ElementName.AuthorGroup]: ['inline'],
|
|
13
|
+
[ElementName.CollaboratorGroup]: ['inline'],
|
|
14
|
+
[ElementName.CommentCount]: ['inline'],
|
|
15
|
+
[ElementName.CreatedBy]: ['inline'],
|
|
16
|
+
[ElementName.CreatedOn]: ['inline'],
|
|
17
|
+
[ElementName.LinkIcon]: ['inline'],
|
|
18
|
+
[ElementName.ModifiedBy]: ['inline'],
|
|
19
|
+
[ElementName.ModifiedOn]: ['inline'],
|
|
20
|
+
[ElementName.Priority]: ['inline'],
|
|
21
|
+
[ElementName.ProgrammingLanguage]: ['inline'],
|
|
22
|
+
[ElementName.Snippet]: ['block'],
|
|
23
|
+
[ElementName.State]: ['inline'],
|
|
24
|
+
[ElementName.SubscriberCount]: ['inline'],
|
|
25
|
+
[ElementName.Title]: ['inline']
|
|
26
|
+
};
|
|
10
27
|
|
|
11
28
|
const getDirectionStyles = direction => {
|
|
12
29
|
switch (direction) {
|
|
@@ -62,6 +79,12 @@ export const getBaseStyles = (direction, size) => css`
|
|
|
62
79
|
|
|
63
80
|
const isActionGroup = node => /*#__PURE__*/React.isValidElement(node) && node.type === ActionGroup;
|
|
64
81
|
|
|
82
|
+
const isElementDisplayValid = (name, display) => {
|
|
83
|
+
var _ElementDisplaySchema, _ElementDisplaySchema2;
|
|
84
|
+
|
|
85
|
+
return (_ElementDisplaySchema = (_ElementDisplaySchema2 = ElementDisplaySchema[name]) === null || _ElementDisplaySchema2 === void 0 ? void 0 : _ElementDisplaySchema2.includes(display)) !== null && _ElementDisplaySchema !== void 0 ? _ElementDisplaySchema : false;
|
|
86
|
+
};
|
|
87
|
+
|
|
65
88
|
const isElementNull = children => {
|
|
66
89
|
return Boolean(children.type() === null);
|
|
67
90
|
};
|
|
@@ -81,7 +104,7 @@ export const renderChildren = (children, size) => React.Children.map(children, c
|
|
|
81
104
|
|
|
82
105
|
return child;
|
|
83
106
|
});
|
|
84
|
-
export const renderElementItems = (items = []) => {
|
|
107
|
+
export const renderElementItems = (items = [], display = 'inline') => {
|
|
85
108
|
const elements = items.reduce((acc, curr, idx) => {
|
|
86
109
|
const {
|
|
87
110
|
name,
|
|
@@ -89,7 +112,7 @@ export const renderElementItems = (items = []) => {
|
|
|
89
112
|
} = curr;
|
|
90
113
|
const Element = Elements[name];
|
|
91
114
|
|
|
92
|
-
if (Element) {
|
|
115
|
+
if (Element && isElementDisplayValid(name, display)) {
|
|
93
116
|
const element = /*#__PURE__*/React.createElement(Element, _extends({
|
|
94
117
|
key: idx
|
|
95
118
|
}, props));
|
|
@@ -13,6 +13,7 @@ export const ModifiedBy = createElement(ElementName.ModifiedBy);
|
|
|
13
13
|
export const ModifiedOn = createElement(ElementName.ModifiedOn);
|
|
14
14
|
export const Priority = createElement(ElementName.Priority);
|
|
15
15
|
export const ProgrammingLanguage = createElement(ElementName.ProgrammingLanguage);
|
|
16
|
+
export const Snippet = createElement(ElementName.Snippet);
|
|
16
17
|
export const State = createElement(ElementName.State);
|
|
17
18
|
export const SubscriberCount = createElement(ElementName.SubscriberCount);
|
|
18
19
|
export const Title = createElement(ElementName.Title);
|
|
@@ -3,15 +3,17 @@ import React from 'react';
|
|
|
3
3
|
import { css, jsx } from '@emotion/core';
|
|
4
4
|
import { getFormattedMessage, getTruncateStyles } from '../../utils';
|
|
5
5
|
import { tokens } from '../../../../../utils/token';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
const getStyles = maxLines => css`
|
|
7
8
|
color: ${tokens.text};
|
|
8
9
|
font-size: 0.75rem;
|
|
9
10
|
line-height: 1rem;
|
|
10
|
-
${getTruncateStyles(
|
|
11
|
+
${getTruncateStyles(maxLines)}
|
|
11
12
|
`;
|
|
12
13
|
|
|
13
14
|
const Text = ({
|
|
14
15
|
content,
|
|
16
|
+
maxLines = 1,
|
|
15
17
|
message,
|
|
16
18
|
testId = 'smart-element-text'
|
|
17
19
|
}) => {
|
|
@@ -20,7 +22,7 @@ const Text = ({
|
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
return jsx("span", {
|
|
23
|
-
css:
|
|
25
|
+
css: getStyles(maxLines),
|
|
24
26
|
"data-smart-element-text": true,
|
|
25
27
|
"data-testid": testId
|
|
26
28
|
}, getFormattedMessage(message) || content);
|
|
@@ -41,6 +41,12 @@ const elementMappings = {
|
|
|
41
41
|
icon: IconType.ProgrammingLanguage
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
+
[ElementName.Snippet]: {
|
|
45
|
+
component: Text,
|
|
46
|
+
props: {
|
|
47
|
+
maxLines: 3
|
|
48
|
+
}
|
|
49
|
+
},
|
|
44
50
|
[ElementName.State]: {
|
|
45
51
|
component: Lozenge
|
|
46
52
|
},
|
|
@@ -96,6 +102,9 @@ const getData = (elementName, contextKey, context) => {
|
|
|
96
102
|
case ElementName.ModifiedOn:
|
|
97
103
|
return toDateTimeProps('modified', context.modifiedOn);
|
|
98
104
|
|
|
105
|
+
case ElementName.Snippet:
|
|
106
|
+
return toTextProps(data);
|
|
107
|
+
|
|
99
108
|
case ElementName.Title:
|
|
100
109
|
return toLinkProps(context.title, context.url);
|
|
101
110
|
|
|
@@ -141,6 +150,12 @@ const toLinkProps = (text, url) => {
|
|
|
141
150
|
} : undefined;
|
|
142
151
|
};
|
|
143
152
|
|
|
153
|
+
const toTextProps = content => {
|
|
154
|
+
return content ? {
|
|
155
|
+
content
|
|
156
|
+
} : undefined;
|
|
157
|
+
};
|
|
158
|
+
|
|
144
159
|
export const createElement = name => {
|
|
145
160
|
const {
|
|
146
161
|
component: BaseElement,
|
package/dist/esm/constants.js
CHANGED
|
@@ -48,7 +48,19 @@ export var SmartLinkTheme;
|
|
|
48
48
|
SmartLinkTheme["Link"] = "link";
|
|
49
49
|
})(SmartLinkTheme || (SmartLinkTheme = {}));
|
|
50
50
|
|
|
51
|
-
export var SmartLinkWidth;
|
|
51
|
+
export var SmartLinkWidth; // When adding an element...
|
|
52
|
+
// 1) Create base element if it doesn't already existed.
|
|
53
|
+
// Base element are inside src/view/FlexibleCard/components/elements.
|
|
54
|
+
// E.g. Badge,DateTime, Icon, Lozenge, etc.
|
|
55
|
+
// 2) Update FlexibleUiContext with the new prop for data representing
|
|
56
|
+
// the element, preferably with the same name as the element itself.
|
|
57
|
+
// (src/state/flexible-ui-context/types.ts)
|
|
58
|
+
// 3) Update Flexible UI extractor (src/extractors/flexible/index.ts)
|
|
59
|
+
// 4) Set base element and data mapping.
|
|
60
|
+
// (src/view/FlexibleCard/components/elements/utils.tsx)
|
|
61
|
+
// 5) Create element. (src/view/FlexibleCard/components/elements/index.ts)
|
|
62
|
+
// 6) Update element ElementDisplaySchema for inline/block display
|
|
63
|
+
// (src/view/FlexibleCard/components/blocks/utils.tsx)
|
|
52
64
|
|
|
53
65
|
(function (SmartLinkWidth) {
|
|
54
66
|
SmartLinkWidth["FitToContent"] = "fit-to-content";
|
|
@@ -68,6 +80,7 @@ export var ElementName;
|
|
|
68
80
|
ElementName["ModifiedOn"] = "ModifiedOn";
|
|
69
81
|
ElementName["Priority"] = "Priority";
|
|
70
82
|
ElementName["ProgrammingLanguage"] = "ProgrammingLanguage";
|
|
83
|
+
ElementName["Snippet"] = "Snippet";
|
|
71
84
|
ElementName["State"] = "State";
|
|
72
85
|
ElementName["SubscriberCount"] = "SubscriberCount";
|
|
73
86
|
ElementName["Title"] = "Title";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractLink, extractTitle } from '../common/primitives';
|
|
1
|
+
import { extractLink, extractSummary, extractTitle } from '../common/primitives';
|
|
2
2
|
import { extractLozenge } from '../common/lozenge';
|
|
3
3
|
import { extractLinkIcon } from './icon';
|
|
4
4
|
import { extractCommentCount, extractCreatedBy, extractModifiedBy, extractProgrammingLanguage, extractSubscriberCount } from './utils';
|
|
@@ -26,6 +26,8 @@ var extractFlexibleUiContext = function extractFlexibleUiContext(response, rende
|
|
|
26
26
|
modifiedOn: extractDateUpdated(data),
|
|
27
27
|
priority: extractPriority(data),
|
|
28
28
|
programmingLanguage: extractProgrammingLanguage(data),
|
|
29
|
+
snippet: extractSummary(data) || undefined,
|
|
30
|
+
// Explicitly set here to remove an empty string
|
|
29
31
|
state: extractLozenge(data),
|
|
30
32
|
subscriberCount: extractSubscriberCount(data),
|
|
31
33
|
title: extractTitle(data) || url,
|
package/dist/esm/version.json
CHANGED
|
@@ -2,19 +2,22 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
2
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
4
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
6
|
var _excluded = ["name"],
|
|
6
7
|
_excluded2 = ["name"];
|
|
7
8
|
|
|
8
|
-
var _templateObject, _templateObject2, _templateObject3;
|
|
9
|
+
var _ElementDisplaySchema, _templateObject, _templateObject2, _templateObject3;
|
|
9
10
|
|
|
10
11
|
import React from 'react';
|
|
11
12
|
import { css } from '@emotion/core';
|
|
12
|
-
import { SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
13
|
+
import { ElementName, SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
13
14
|
import * as Elements from '../elements';
|
|
14
15
|
import * as Actions from '../actions';
|
|
15
16
|
import { isFlexibleUiElement } from '../../../../utils/flexible';
|
|
16
17
|
import ActionGroup from './action-group';
|
|
17
|
-
import ElementGroup from './element-group';
|
|
18
|
+
import ElementGroup from './element-group'; // Determine whether the element can be display as inline/block.
|
|
19
|
+
|
|
20
|
+
export var ElementDisplaySchema = (_ElementDisplaySchema = {}, _defineProperty(_ElementDisplaySchema, ElementName.AuthorGroup, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CollaboratorGroup, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CommentCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CreatedBy, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CreatedOn, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.LinkIcon, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ModifiedBy, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ModifiedOn, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.Priority, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ProgrammingLanguage, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.Snippet, ['block']), _defineProperty(_ElementDisplaySchema, ElementName.State, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.SubscriberCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.Title, ['inline']), _ElementDisplaySchema);
|
|
18
21
|
|
|
19
22
|
var getDirectionStyles = function getDirectionStyles(direction) {
|
|
20
23
|
switch (direction) {
|
|
@@ -51,6 +54,12 @@ var isActionGroup = function isActionGroup(node) {
|
|
|
51
54
|
return /*#__PURE__*/React.isValidElement(node) && node.type === ActionGroup;
|
|
52
55
|
};
|
|
53
56
|
|
|
57
|
+
var isElementDisplayValid = function isElementDisplayValid(name, display) {
|
|
58
|
+
var _ElementDisplaySchema2, _ElementDisplaySchema3;
|
|
59
|
+
|
|
60
|
+
return (_ElementDisplaySchema2 = (_ElementDisplaySchema3 = ElementDisplaySchema[name]) === null || _ElementDisplaySchema3 === void 0 ? void 0 : _ElementDisplaySchema3.includes(display)) !== null && _ElementDisplaySchema2 !== void 0 ? _ElementDisplaySchema2 : false;
|
|
61
|
+
};
|
|
62
|
+
|
|
54
63
|
var isElementNull = function isElementNull(children) {
|
|
55
64
|
return Boolean(children.type() === null);
|
|
56
65
|
};
|
|
@@ -74,13 +83,14 @@ export var renderChildren = function renderChildren(children, size) {
|
|
|
74
83
|
};
|
|
75
84
|
export var renderElementItems = function renderElementItems() {
|
|
76
85
|
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
86
|
+
var display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'inline';
|
|
77
87
|
var elements = items.reduce(function (acc, curr, idx) {
|
|
78
88
|
var name = curr.name,
|
|
79
89
|
props = _objectWithoutProperties(curr, _excluded);
|
|
80
90
|
|
|
81
91
|
var Element = Elements[name];
|
|
82
92
|
|
|
83
|
-
if (Element) {
|
|
93
|
+
if (Element && isElementDisplayValid(name, display)) {
|
|
84
94
|
var element = /*#__PURE__*/React.createElement(Element, _extends({
|
|
85
95
|
key: idx
|
|
86
96
|
}, props));
|
|
@@ -13,6 +13,7 @@ export var ModifiedBy = createElement(ElementName.ModifiedBy);
|
|
|
13
13
|
export var ModifiedOn = createElement(ElementName.ModifiedOn);
|
|
14
14
|
export var Priority = createElement(ElementName.Priority);
|
|
15
15
|
export var ProgrammingLanguage = createElement(ElementName.ProgrammingLanguage);
|
|
16
|
+
export var Snippet = createElement(ElementName.Snippet);
|
|
16
17
|
export var State = createElement(ElementName.State);
|
|
17
18
|
export var SubscriberCount = createElement(ElementName.SubscriberCount);
|
|
18
19
|
export var Title = createElement(ElementName.Title);
|
|
@@ -7,10 +7,15 @@ import React from 'react';
|
|
|
7
7
|
import { css, jsx } from '@emotion/core';
|
|
8
8
|
import { getFormattedMessage, getTruncateStyles } from '../../utils';
|
|
9
9
|
import { tokens } from '../../../../../utils/token';
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
var getStyles = function getStyles(maxLines) {
|
|
12
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n color: ", ";\n font-size: 0.75rem;\n line-height: 1rem;\n ", "\n"])), tokens.text, getTruncateStyles(maxLines));
|
|
13
|
+
};
|
|
11
14
|
|
|
12
15
|
var Text = function Text(_ref) {
|
|
13
16
|
var content = _ref.content,
|
|
17
|
+
_ref$maxLines = _ref.maxLines,
|
|
18
|
+
maxLines = _ref$maxLines === void 0 ? 1 : _ref$maxLines,
|
|
14
19
|
message = _ref.message,
|
|
15
20
|
_ref$testId = _ref.testId,
|
|
16
21
|
testId = _ref$testId === void 0 ? 'smart-element-text' : _ref$testId;
|
|
@@ -20,7 +25,7 @@ var Text = function Text(_ref) {
|
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
return jsx("span", {
|
|
23
|
-
css:
|
|
28
|
+
css: getStyles(maxLines),
|
|
24
29
|
"data-smart-element-text": true,
|
|
25
30
|
"data-testid": testId
|
|
26
31
|
}, getFormattedMessage(message) || content);
|
|
@@ -36,6 +36,11 @@ var elementMappings = (_elementMappings = {}, _defineProperty(_elementMappings,
|
|
|
36
36
|
props: {
|
|
37
37
|
icon: IconType.ProgrammingLanguage
|
|
38
38
|
}
|
|
39
|
+
}), _defineProperty(_elementMappings, ElementName.Snippet, {
|
|
40
|
+
component: Text,
|
|
41
|
+
props: {
|
|
42
|
+
maxLines: 3
|
|
43
|
+
}
|
|
39
44
|
}), _defineProperty(_elementMappings, ElementName.State, {
|
|
40
45
|
component: Lozenge
|
|
41
46
|
}), _defineProperty(_elementMappings, ElementName.SubscriberCount, {
|
|
@@ -86,6 +91,9 @@ var getData = function getData(elementName, contextKey, context) {
|
|
|
86
91
|
case ElementName.ModifiedOn:
|
|
87
92
|
return toDateTimeProps('modified', context.modifiedOn);
|
|
88
93
|
|
|
94
|
+
case ElementName.Snippet:
|
|
95
|
+
return toTextProps(data);
|
|
96
|
+
|
|
89
97
|
case ElementName.Title:
|
|
90
98
|
return toLinkProps(context.title, context.url);
|
|
91
99
|
|
|
@@ -131,6 +139,12 @@ var toLinkProps = function toLinkProps(text, url) {
|
|
|
131
139
|
} : undefined;
|
|
132
140
|
};
|
|
133
141
|
|
|
142
|
+
var toTextProps = function toTextProps(content) {
|
|
143
|
+
return content ? {
|
|
144
|
+
content: content
|
|
145
|
+
} : undefined;
|
|
146
|
+
};
|
|
147
|
+
|
|
134
148
|
export var createElement = function createElement(name) {
|
|
135
149
|
var _ref = elementMappings[name] || {},
|
|
136
150
|
BaseElement = _ref.component,
|
|
@@ -2,6 +2,8 @@ import { LinkLozenge } from '../../extractors/common/lozenge/types';
|
|
|
2
2
|
import { LinkPerson } from '../../extractors/common/person/types';
|
|
3
3
|
import { IconType } from '../../constants';
|
|
4
4
|
export declare type FlexibleUiDataContext = {
|
|
5
|
+
authorGroup?: LinkPerson[];
|
|
6
|
+
collaboratorGroup?: LinkPerson[];
|
|
5
7
|
commentCount?: number;
|
|
6
8
|
createdBy?: string;
|
|
7
9
|
createdOn?: string;
|
|
@@ -10,12 +12,11 @@ export declare type FlexibleUiDataContext = {
|
|
|
10
12
|
modifiedOn?: string;
|
|
11
13
|
priority?: Icon;
|
|
12
14
|
programmingLanguage?: string;
|
|
15
|
+
snippet?: string;
|
|
13
16
|
subscriberCount?: number;
|
|
14
17
|
state?: LinkLozenge;
|
|
15
18
|
title?: string;
|
|
16
19
|
url?: string;
|
|
17
|
-
authorGroup?: LinkPerson[];
|
|
18
|
-
collaboratorGroup?: LinkPerson[];
|
|
19
20
|
};
|
|
20
21
|
export declare type Icon = {
|
|
21
22
|
icon?: IconType;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SerializedStyles } from '@emotion/core';
|
|
3
3
|
import { ActionItem, ElementItem } from './types';
|
|
4
|
-
import { SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
4
|
+
import { ElementName, SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
5
|
+
export declare type ElementDisplaySchemaType = 'inline' | 'block';
|
|
6
|
+
export declare const ElementDisplaySchema: Record<ElementName, ElementDisplaySchemaType[]>;
|
|
5
7
|
export declare const getGapSize: (size: SmartLinkSize) => number;
|
|
6
8
|
export declare const getBaseStyles: (direction: SmartLinkDirection, size: SmartLinkSize) => SerializedStyles;
|
|
7
9
|
export declare const renderChildren: (children: React.ReactNode, size: SmartLinkSize) => React.ReactNode;
|
|
8
|
-
export declare const renderElementItems: (items?: ElementItem[]) => React.ReactNode | undefined;
|
|
10
|
+
export declare const renderElementItems: (items?: ElementItem[], display?: ElementDisplaySchemaType) => React.ReactNode | undefined;
|
|
9
11
|
export declare const renderActionItems: (items?: ActionItem[], size?: SmartLinkSize) => React.ReactNode | undefined;
|
|
@@ -16,6 +16,7 @@ export declare const ModifiedBy: import("react").FC<TextProps>;
|
|
|
16
16
|
export declare const ModifiedOn: import("react").FC<DateTimeProps>;
|
|
17
17
|
export declare const Priority: import("react").FC<BadgeProps>;
|
|
18
18
|
export declare const ProgrammingLanguage: import("react").FC<BadgeProps>;
|
|
19
|
+
export declare const Snippet: import("react").FC<TextProps>;
|
|
19
20
|
export declare const State: import("react").FC<LozengeProps>;
|
|
20
21
|
export declare const SubscriberCount: import("react").FC<BadgeProps>;
|
|
21
22
|
export declare const Title: import("react").FC<LinkProps>;
|