@atlaskit/smart-card 17.7.6 → 17.7.7
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 +32 -0
- package/dist/cjs/hooks.js +13 -0
- package/dist/cjs/state/hooks-external/useSmartLinkActions.js +71 -0
- package/dist/cjs/utils/mocks.js +7 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/hooks.js +1 -0
- package/dist/es2019/state/hooks-external/useSmartLinkActions.js +42 -0
- package/dist/es2019/utils/mocks.js +5 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/hooks.js +1 -0
- package/dist/esm/state/hooks-external/useSmartLinkActions.js +54 -0
- package/dist/esm/utils/mocks.js +5 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/hooks.d.ts +1 -0
- package/dist/types/state/hooks-external/useSmartLinkActions.d.ts +45 -0
- package/dist/types/utils/mocks.d.ts +5 -0
- package/hooks/package.json +7 -0
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @atlaskit/smart-card
|
|
2
2
|
|
|
3
|
+
## 17.7.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`c01f6404d0c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c01f6404d0c) - Add ability to trigger actions for a Smart Link from outside of the Smart Link card.
|
|
8
|
+
|
|
9
|
+
Example usage:
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { useSmartLinkActions } from '@atlaskit/smart-card/hooks';
|
|
13
|
+
|
|
14
|
+
const ExampleToolbar = () => {
|
|
15
|
+
const actions = useSmartLinkActions({
|
|
16
|
+
url,
|
|
17
|
+
appearance: 'block',
|
|
18
|
+
analyticsHandler: analytics,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<ExampleToolbarWrapper>
|
|
23
|
+
{actions.map((action) => (
|
|
24
|
+
<Tooltip content={action.text}>
|
|
25
|
+
<ExampleToolbarItem key={action.id} onClick={action.invoke}>
|
|
26
|
+
{idToIcon[action.id] ?? action.id}
|
|
27
|
+
</ExampleToolbarItem>
|
|
28
|
+
</Tooltip>
|
|
29
|
+
))}
|
|
30
|
+
</ExampleToolbarWrapper>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
3
35
|
## 17.7.6
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useSmartLinkActions", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _useSmartLinkActions.useSmartLinkActions;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _useSmartLinkActions = require("./state/hooks-external/useSmartLinkActions");
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useSmartLinkActions = useSmartLinkActions;
|
|
9
|
+
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
|
|
12
|
+
var _react = require("react");
|
|
13
|
+
|
|
14
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
15
|
+
|
|
16
|
+
var _block = require("../../extractors/block");
|
|
17
|
+
|
|
18
|
+
var _actions = require("../actions");
|
|
19
|
+
|
|
20
|
+
var _analytics = require("../analytics");
|
|
21
|
+
|
|
22
|
+
var _store = require("../store");
|
|
23
|
+
|
|
24
|
+
var _helpers = require("../helpers");
|
|
25
|
+
|
|
26
|
+
function useSmartLinkActions(_ref) {
|
|
27
|
+
var url = _ref.url,
|
|
28
|
+
appearance = _ref.appearance,
|
|
29
|
+
analyticsHandler = _ref.analyticsHandler,
|
|
30
|
+
_ref$platform = _ref.platform,
|
|
31
|
+
platform = _ref$platform === void 0 ? 'web' : _ref$platform;
|
|
32
|
+
var id = (0, _react.useMemo)(function () {
|
|
33
|
+
return (0, _uuid.default)();
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
var _useState = (0, _react.useState)([]),
|
|
37
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
38
|
+
actions = _useState2[0],
|
|
39
|
+
setActions = _useState2[1];
|
|
40
|
+
|
|
41
|
+
var linkState = (0, _store.useSmartCardState)(url);
|
|
42
|
+
var linkAnalytics = (0, _analytics.useSmartLinkAnalytics)(analyticsHandler);
|
|
43
|
+
var linkActions = (0, _actions.useSmartCardActions)(id, url, linkAnalytics);
|
|
44
|
+
(0, _react.useEffect)(function () {
|
|
45
|
+
if (!linkState.details) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var cardProperties = (0, _block.extractBlockProps)(linkState.details.data, linkState.details.meta, {
|
|
50
|
+
handleInvoke: function handleInvoke(opts) {
|
|
51
|
+
return linkActions.invoke(opts, appearance);
|
|
52
|
+
},
|
|
53
|
+
handleAnalytics: analyticsHandler,
|
|
54
|
+
extensionKey: (0, _helpers.getExtensionKey)(linkState.details)
|
|
55
|
+
}, undefined, platform);
|
|
56
|
+
|
|
57
|
+
if (!cardProperties.actions || cardProperties.actions.length === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var cardActions = cardProperties.actions.map(function (action) {
|
|
62
|
+
return {
|
|
63
|
+
id: action.id,
|
|
64
|
+
text: action.text,
|
|
65
|
+
invoke: action.promise
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
setActions(cardActions);
|
|
69
|
+
}, [linkState, linkActions, analyticsHandler, appearance, platform]);
|
|
70
|
+
return actions;
|
|
71
|
+
}
|
package/dist/cjs/utils/mocks.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.waitFor = exports.mocks = exports.fakeResponse = exports.fakeFactory = void 0;
|
|
8
|
+
exports.waitFor = exports.mocks = exports.mockContext = exports.fakeResponse = exports.fakeFactory = void 0;
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
@@ -27,6 +27,12 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
27
27
|
|
|
28
28
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
29
29
|
|
|
30
|
+
var mockContext = {
|
|
31
|
+
'@vocab': 'https://www.w3.org/ns/activitystreams#',
|
|
32
|
+
atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
|
|
33
|
+
schema: 'http://schema.org/'
|
|
34
|
+
};
|
|
35
|
+
exports.mockContext = mockContext;
|
|
30
36
|
var mocks = {
|
|
31
37
|
success: {
|
|
32
38
|
meta: {
|
package/dist/cjs/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSmartLinkActions } from './state/hooks-external/useSmartLinkActions';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import uuid from 'uuid';
|
|
3
|
+
import { extractBlockProps as extractCardProps } from '../../extractors/block';
|
|
4
|
+
import { useSmartCardActions as useLinkActions } from '../actions';
|
|
5
|
+
import { useSmartLinkAnalytics as useLinkAnalytics } from '../analytics';
|
|
6
|
+
import { useSmartCardState as useLinkState } from '../store';
|
|
7
|
+
import { getExtensionKey } from '../helpers';
|
|
8
|
+
export function useSmartLinkActions({
|
|
9
|
+
url,
|
|
10
|
+
appearance,
|
|
11
|
+
analyticsHandler,
|
|
12
|
+
platform = 'web'
|
|
13
|
+
}) {
|
|
14
|
+
const id = useMemo(() => uuid(), []);
|
|
15
|
+
const [actions, setActions] = useState([]);
|
|
16
|
+
const linkState = useLinkState(url);
|
|
17
|
+
const linkAnalytics = useLinkAnalytics(analyticsHandler);
|
|
18
|
+
const linkActions = useLinkActions(id, url, linkAnalytics);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!linkState.details) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const cardProperties = extractCardProps(linkState.details.data, linkState.details.meta, {
|
|
25
|
+
handleInvoke: opts => linkActions.invoke(opts, appearance),
|
|
26
|
+
handleAnalytics: analyticsHandler,
|
|
27
|
+
extensionKey: getExtensionKey(linkState.details)
|
|
28
|
+
}, undefined, platform);
|
|
29
|
+
|
|
30
|
+
if (!cardProperties.actions || cardProperties.actions.length === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const cardActions = cardProperties.actions.map(action => ({
|
|
35
|
+
id: action.id,
|
|
36
|
+
text: action.text,
|
|
37
|
+
invoke: action.promise
|
|
38
|
+
}));
|
|
39
|
+
setActions(cardActions);
|
|
40
|
+
}, [linkState, linkActions, analyticsHandler, appearance, platform]);
|
|
41
|
+
return actions;
|
|
42
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import CardClient from '../client';
|
|
2
|
+
export const mockContext = {
|
|
3
|
+
'@vocab': 'https://www.w3.org/ns/activitystreams#',
|
|
4
|
+
atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
|
|
5
|
+
schema: 'http://schema.org/'
|
|
6
|
+
};
|
|
2
7
|
export const mocks = {
|
|
3
8
|
success: {
|
|
4
9
|
meta: {
|
package/dist/es2019/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSmartLinkActions } from './state/hooks-external/useSmartLinkActions';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import uuid from 'uuid';
|
|
4
|
+
import { extractBlockProps as extractCardProps } from '../../extractors/block';
|
|
5
|
+
import { useSmartCardActions as useLinkActions } from '../actions';
|
|
6
|
+
import { useSmartLinkAnalytics as useLinkAnalytics } from '../analytics';
|
|
7
|
+
import { useSmartCardState as useLinkState } from '../store';
|
|
8
|
+
import { getExtensionKey } from '../helpers';
|
|
9
|
+
export function useSmartLinkActions(_ref) {
|
|
10
|
+
var url = _ref.url,
|
|
11
|
+
appearance = _ref.appearance,
|
|
12
|
+
analyticsHandler = _ref.analyticsHandler,
|
|
13
|
+
_ref$platform = _ref.platform,
|
|
14
|
+
platform = _ref$platform === void 0 ? 'web' : _ref$platform;
|
|
15
|
+
var id = useMemo(function () {
|
|
16
|
+
return uuid();
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
var _useState = useState([]),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
actions = _useState2[0],
|
|
22
|
+
setActions = _useState2[1];
|
|
23
|
+
|
|
24
|
+
var linkState = useLinkState(url);
|
|
25
|
+
var linkAnalytics = useLinkAnalytics(analyticsHandler);
|
|
26
|
+
var linkActions = useLinkActions(id, url, linkAnalytics);
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
if (!linkState.details) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var cardProperties = extractCardProps(linkState.details.data, linkState.details.meta, {
|
|
33
|
+
handleInvoke: function handleInvoke(opts) {
|
|
34
|
+
return linkActions.invoke(opts, appearance);
|
|
35
|
+
},
|
|
36
|
+
handleAnalytics: analyticsHandler,
|
|
37
|
+
extensionKey: getExtensionKey(linkState.details)
|
|
38
|
+
}, undefined, platform);
|
|
39
|
+
|
|
40
|
+
if (!cardProperties.actions || cardProperties.actions.length === 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var cardActions = cardProperties.actions.map(function (action) {
|
|
45
|
+
return {
|
|
46
|
+
id: action.id,
|
|
47
|
+
text: action.text,
|
|
48
|
+
invoke: action.promise
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
setActions(cardActions);
|
|
52
|
+
}, [linkState, linkActions, analyticsHandler, appearance, platform]);
|
|
53
|
+
return actions;
|
|
54
|
+
}
|
package/dist/esm/utils/mocks.js
CHANGED
|
@@ -11,6 +11,11 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
11
11
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
12
12
|
|
|
13
13
|
import CardClient from '../client';
|
|
14
|
+
export var mockContext = {
|
|
15
|
+
'@vocab': 'https://www.w3.org/ns/activitystreams#',
|
|
16
|
+
atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
|
|
17
|
+
schema: 'http://schema.org/'
|
|
18
|
+
};
|
|
14
19
|
export var mocks = {
|
|
15
20
|
success: {
|
|
16
21
|
meta: {
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSmartLinkActions } from './state/hooks-external/useSmartLinkActions';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { JsonLd } from 'json-ld-types';
|
|
3
|
+
import type { AnalyticsHandler } from '../../utils/types';
|
|
4
|
+
import type { CardAppearance } from '../../view/Card/types';
|
|
5
|
+
export interface LinkAction {
|
|
6
|
+
/**
|
|
7
|
+
* Unique ID for the action.
|
|
8
|
+
* @example `delete-action`
|
|
9
|
+
*/
|
|
10
|
+
id: string;
|
|
11
|
+
/**
|
|
12
|
+
* Text to render for the action.
|
|
13
|
+
* @description Use this in tooltips and UI.
|
|
14
|
+
* @example `Delete`.
|
|
15
|
+
*/
|
|
16
|
+
text: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Promise to invoke on triggering this action.
|
|
19
|
+
* @example Clicking on `Delete` leading to deletion of content.
|
|
20
|
+
*/
|
|
21
|
+
invoke: () => Promise<any>;
|
|
22
|
+
}
|
|
23
|
+
export interface UseSmartLinkActionsOpts {
|
|
24
|
+
/**
|
|
25
|
+
* Smart Link URL for which actions will be invoked.
|
|
26
|
+
* @example https://start.atlassian.com
|
|
27
|
+
*/
|
|
28
|
+
url: string;
|
|
29
|
+
/**
|
|
30
|
+
* Appearance under which these actions will be invoked.
|
|
31
|
+
* @example `block` for card views.
|
|
32
|
+
*/
|
|
33
|
+
appearance: CardAppearance;
|
|
34
|
+
/**
|
|
35
|
+
* Callback for sending analytics events.
|
|
36
|
+
* @description Accepts an analytics payload and fires it to a system.
|
|
37
|
+
*/
|
|
38
|
+
analyticsHandler: AnalyticsHandler;
|
|
39
|
+
/**
|
|
40
|
+
* Platform on which actions are being invoked.
|
|
41
|
+
* @default 'web'
|
|
42
|
+
*/
|
|
43
|
+
platform?: JsonLd.Primitives.Platforms;
|
|
44
|
+
}
|
|
45
|
+
export declare function useSmartLinkActions({ url, appearance, analyticsHandler, platform, }: UseSmartLinkActionsOpts): LinkAction[];
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { JsonLd } from 'json-ld-types';
|
|
2
|
+
export declare const mockContext: {
|
|
3
|
+
readonly '@vocab': "https://www.w3.org/ns/activitystreams#";
|
|
4
|
+
readonly atlassian: "https://schema.atlassian.com/ns/vocabulary#";
|
|
5
|
+
readonly schema: "http://schema.org/";
|
|
6
|
+
};
|
|
2
7
|
export declare const mocks: {
|
|
3
8
|
success: JsonLd.Response<JsonLd.Data.BaseData>;
|
|
4
9
|
notFound: JsonLd.Response<JsonLd.Data.BaseData>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/smart-card",
|
|
3
|
-
"version": "17.7.
|
|
3
|
+
"version": "17.7.7",
|
|
4
4
|
"description": "Smart card component",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -111,6 +111,7 @@
|
|
|
111
111
|
"react-dom": "^16.8.0",
|
|
112
112
|
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
113
113
|
"react-test-renderer": "^16.8.0",
|
|
114
|
+
"ts-jest": "24.3.0",
|
|
114
115
|
"typescript": "3.9.6",
|
|
115
116
|
"xhr-mock": "^2.4.0"
|
|
116
117
|
},
|
|
@@ -119,6 +120,7 @@
|
|
|
119
120
|
"./in-product": "./src/in-product.ts",
|
|
120
121
|
"./client": "./src/client/index.ts",
|
|
121
122
|
"./types": "./src/types.ts",
|
|
123
|
+
"./hooks": "./src/hooks.ts",
|
|
122
124
|
".": "./src/index.ts"
|
|
123
125
|
},
|
|
124
126
|
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
|