@atlaskit/editor-plugin-card 1.7.0 → 1.8.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/nodeviews/blockCard.js +9 -5
  3. package/dist/cjs/nodeviews/embedCard.js +7 -5
  4. package/dist/cjs/nodeviews/genericCard.js +58 -9
  5. package/dist/cjs/nodeviews/inlineCard.js +10 -6
  6. package/dist/cjs/nodeviews/inlineCardWithAwareness.js +4 -3
  7. package/dist/cjs/pm-plugins/main.js +9 -4
  8. package/dist/cjs/toolbar.js +4 -0
  9. package/dist/es2019/nodeviews/blockCard.js +9 -5
  10. package/dist/es2019/nodeviews/embedCard.js +7 -5
  11. package/dist/es2019/nodeviews/genericCard.js +50 -3
  12. package/dist/es2019/nodeviews/inlineCard.js +10 -6
  13. package/dist/es2019/nodeviews/inlineCardWithAwareness.js +4 -3
  14. package/dist/es2019/pm-plugins/main.js +9 -4
  15. package/dist/es2019/toolbar.js +4 -0
  16. package/dist/esm/nodeviews/blockCard.js +9 -5
  17. package/dist/esm/nodeviews/embedCard.js +7 -5
  18. package/dist/esm/nodeviews/genericCard.js +55 -9
  19. package/dist/esm/nodeviews/inlineCard.js +10 -6
  20. package/dist/esm/nodeviews/inlineCardWithAwareness.js +4 -3
  21. package/dist/esm/pm-plugins/main.js +9 -4
  22. package/dist/esm/toolbar.js +4 -0
  23. package/dist/types/nodeviews/blockCard.d.ts +1 -2
  24. package/dist/types/nodeviews/embedCard.d.ts +1 -2
  25. package/dist/types/nodeviews/genericCard.d.ts +6 -1
  26. package/dist/types/nodeviews/inlineCard.d.ts +1 -2
  27. package/dist/types/nodeviews/inlineCardWithAwareness.d.ts +1 -1
  28. package/dist/types/plugin.d.ts +2 -0
  29. package/dist/types/types.d.ts +2 -1
  30. package/dist/types-ts4.5/nodeviews/blockCard.d.ts +1 -2
  31. package/dist/types-ts4.5/nodeviews/embedCard.d.ts +1 -2
  32. package/dist/types-ts4.5/nodeviews/genericCard.d.ts +6 -1
  33. package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +1 -2
  34. package/dist/types-ts4.5/nodeviews/inlineCardWithAwareness.d.ts +1 -1
  35. package/dist/types-ts4.5/plugin.d.ts +2 -0
  36. package/dist/types-ts4.5/types.d.ts +2 -1
  37. package/package.json +10 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 1.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#92530](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/92530) [`4f0d59f56914`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4f0d59f56914) - The changes here fixes a bug where the toolbar shows smartlink icons when the node does not have a url.
8
+
9
+ ## 1.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#89840](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/89840) [`9f256dde75e9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9f256dde75e9) - [ux] Implement onClickCallback plugin option to editor-plugin-card, allowing a callback to be executed when a smartlink is clicked, used by CCFE for live view to open smartlinks on-click
14
+
15
+ ### Patch Changes
16
+
17
+ - [#91106](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91106) [`b6ffa30186b9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b6ffa30186b9) - Bump ADF-schema package to version 35.0.0
18
+ - Updated dependencies
19
+
3
20
  ## 1.7.0
4
21
 
5
22
  ### Minor Changes
@@ -35,7 +35,6 @@ var BlockCardComponent = exports.BlockCardComponent = /*#__PURE__*/function (_Re
35
35
  args[_key] = arguments[_key];
36
36
  }
37
37
  _this = _super.call.apply(_super, [this].concat(args));
38
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClick", function () {});
39
38
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onResolve", function (data) {
40
39
  var _this$props = _this.props,
41
40
  getPos = _this$props.getPos,
@@ -96,7 +95,8 @@ var BlockCardComponent = exports.BlockCardComponent = /*#__PURE__*/function (_Re
96
95
  cardContext = _this$props2.cardContext,
97
96
  platform = _this$props2.platform,
98
97
  actionOptions = _this$props2.actionOptions,
99
- showServerActions = _this$props2.showServerActions;
98
+ showServerActions = _this$props2.showServerActions,
99
+ onClick = _this$props2.onClick;
100
100
  var _node$attrs = node.attrs,
101
101
  url = _node$attrs.url,
102
102
  data = _node$attrs.data;
@@ -106,7 +106,7 @@ var BlockCardComponent = exports.BlockCardComponent = /*#__PURE__*/function (_Re
106
106
  data: data,
107
107
  container: this.scrollContainer,
108
108
  appearance: "block",
109
- onClick: this.onClick,
109
+ onClick: onClick,
110
110
  onResolve: this.onResolve,
111
111
  onError: this.onError,
112
112
  platform: platform,
@@ -170,14 +170,18 @@ var BlockCard = exports.BlockCard = /*#__PURE__*/function (_ReactNodeView) {
170
170
  var _this$reactComponentP = this.reactComponentProps,
171
171
  platform = _this$reactComponentP.platform,
172
172
  actionOptions = _this$reactComponentP.actionOptions,
173
- showServerActions = _this$reactComponentP.showServerActions;
173
+ showServerActions = _this$reactComponentP.showServerActions,
174
+ pluginInjectionApi = _this$reactComponentP.pluginInjectionApi,
175
+ onClickCallback = _this$reactComponentP.onClickCallback;
174
176
  return /*#__PURE__*/_react.default.createElement(WrappedBlockCard, {
175
177
  node: this.node,
176
178
  view: this.view,
177
179
  getPos: this.getPos,
178
180
  platform: platform,
179
181
  actionOptions: actionOptions,
180
- showServerActions: showServerActions
182
+ showServerActions: showServerActions,
183
+ pluginInjectionApi: pluginInjectionApi,
184
+ onClickCallback: onClickCallback
181
185
  });
182
186
  }
183
187
  }]);
@@ -111,7 +111,6 @@ var EmbedCardComponent = exports.EmbedCardComponent = /*#__PURE__*/function (_Re
111
111
  }
112
112
  _this = _super.call.apply(_super, [this].concat(args));
113
113
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "embedIframeRef", /*#__PURE__*/_react.default.createRef());
114
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClick", function () {});
115
114
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
116
115
  hasPreview: true
117
116
  });
@@ -272,7 +271,8 @@ var EmbedCardComponent = exports.EmbedCardComponent = /*#__PURE__*/function (_Re
272
271
  getPos = _this$props.getPos,
273
272
  pluginInjectionApi = _this$props.pluginInjectionApi,
274
273
  actionOptions = _this$props.actionOptions,
275
- showServerActions = _this$props.showServerActions;
274
+ showServerActions = _this$props.showServerActions,
275
+ onClick = _this$props.onClick;
276
276
  var _node$attrs = node.attrs,
277
277
  url = _node$attrs.url,
278
278
  pctWidth = _node$attrs.width,
@@ -303,7 +303,7 @@ var EmbedCardComponent = exports.EmbedCardComponent = /*#__PURE__*/function (_Re
303
303
  key: url,
304
304
  url: url,
305
305
  appearance: "embed",
306
- onClick: this.onClick,
306
+ onClick: onClick,
307
307
  onResolve: this.onResolve,
308
308
  onError: this.onError,
309
309
  frameStyle: "show",
@@ -389,7 +389,8 @@ var EmbedCard = exports.EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
389
389
  platform = _this$reactComponentP.platform,
390
390
  fullWidthMode = _this$reactComponentP.fullWidthMode,
391
391
  dispatchAnalyticsEvent = _this$reactComponentP.dispatchAnalyticsEvent,
392
- pluginInjectionApi = _this$reactComponentP.pluginInjectionApi;
392
+ pluginInjectionApi = _this$reactComponentP.pluginInjectionApi,
393
+ onClickCallback = _this$reactComponentP.onClickCallback;
393
394
  return /*#__PURE__*/_react.default.createElement(WrappedBlockCard, {
394
395
  node: this.node,
395
396
  view: this.view,
@@ -399,7 +400,8 @@ var EmbedCard = exports.EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
399
400
  platform: platform,
400
401
  fullWidthMode: fullWidthMode,
401
402
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
402
- pluginInjectionApi: pluginInjectionApi
403
+ pluginInjectionApi: pluginInjectionApi,
404
+ onClickCallback: onClickCallback
403
405
  });
404
406
  }
405
407
  }]);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
@@ -13,16 +14,45 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
13
14
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
15
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- var _react = _interopRequireDefault(require("react"));
17
+ var _react = _interopRequireWildcard(require("react"));
17
18
  var _propTypes = _interopRequireDefault(require("prop-types"));
18
19
  var _adfSchema = require("@atlaskit/adf-schema");
19
20
  var _analyticsNext = require("@atlaskit/analytics-next");
21
+ var _hooks = require("@atlaskit/editor-common/hooks");
20
22
  var _utils = require("@atlaskit/editor-common/utils");
23
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
21
24
  var _doc = require("../pm-plugins/doc");
22
25
  var _state = require("../pm-plugins/util/state");
23
26
  var _utils2 = require("../utils");
27
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
28
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
24
29
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
30
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
31
+ var WithClickHandler = function WithClickHandler(_ref) {
32
+ var pluginInjectionApi = _ref.pluginInjectionApi,
33
+ url = _ref.url,
34
+ onClickCallback = _ref.onClickCallback,
35
+ children = _ref.children;
36
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['editorViewMode']),
37
+ editorViewModeState = _useSharedPluginState.editorViewModeState;
38
+ var onClick = (0, _react.useCallback)(function (event) {
39
+ if (typeof onClickCallback === 'function') {
40
+ try {
41
+ onClickCallback({
42
+ event: event,
43
+ url: url
44
+ });
45
+ } catch (_unused) {}
46
+ }
47
+ }, [url, onClickCallback]);
48
+
49
+ // Setting `onClick` to `undefined` ensures clicks on smartcards navigate to the URL.
50
+ // If in view mode and not overriding with onClickCallback option, then allow smartlinks to navigate on click.
51
+ var allowNavigation = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' && !onClickCallback;
52
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children({
53
+ onClick: allowNavigation ? undefined : onClick
54
+ }));
55
+ };
26
56
  function Card(SmartCardComponent, UnsupportedComponent) {
27
57
  var _class;
28
58
  return _class = /*#__PURE__*/function (_React$Component) {
@@ -38,12 +68,17 @@ function Card(SmartCardComponent, UnsupportedComponent) {
38
68
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
39
69
  isError: false
40
70
  });
71
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClick", function () {});
41
72
  return _this;
42
73
  }
43
74
  (0, _createClass2.default)(_class, [{
44
75
  key: "render",
45
76
  value: function render() {
46
- var _getPluginState;
77
+ var _getPluginState,
78
+ _this2 = this;
79
+ var _this$props = this.props,
80
+ pluginInjectionApi = _this$props.pluginInjectionApi,
81
+ onClickCallback = _this$props.onClickCallback;
47
82
  var _titleUrlPairFromNode = (0, _utils2.titleUrlPairFromNode)(this.props.node),
48
83
  url = _titleUrlPairFromNode.url;
49
84
  if (url && !(0, _adfSchema.isSafeUrl)(url)) {
@@ -72,10 +107,24 @@ function Card(SmartCardComponent, UnsupportedComponent) {
72
107
  // Below is added for the future implementation of Linking Platform namespaced analytics context
73
108
  location: analyticsEditorAppearance
74
109
  }
75
- }, /*#__PURE__*/_react.default.createElement(SmartCardComponent, (0, _extends2.default)({
110
+ }, (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.on-click-callback') ? /*#__PURE__*/_react.default.createElement(WithClickHandler, {
111
+ pluginInjectionApi: pluginInjectionApi,
112
+ onClickCallback: onClickCallback,
113
+ url: url
114
+ }, function (_ref2) {
115
+ var onClick = _ref2.onClick;
116
+ return /*#__PURE__*/_react.default.createElement(SmartCardComponent, (0, _extends2.default)({
117
+ key: url,
118
+ cardContext: cardContext
119
+ }, _this2.props, {
120
+ onClick: onClick
121
+ }));
122
+ }) : /*#__PURE__*/_react.default.createElement(SmartCardComponent, (0, _extends2.default)({
76
123
  key: url,
77
124
  cardContext: cardContext
78
- }, this.props)));
125
+ }, this.props, {
126
+ onClick: this.onClick
127
+ })));
79
128
  }
80
129
  }, {
81
130
  key: "componentDidCatch",
@@ -91,11 +140,11 @@ function Card(SmartCardComponent, UnsupportedComponent) {
91
140
  this.setState({
92
141
  isError: true
93
142
  });
94
- var _this$props = this.props,
95
- view = _this$props.view,
96
- node = _this$props.node,
97
- getPos = _this$props.getPos,
98
- pluginInjectionApi = _this$props.pluginInjectionApi;
143
+ var _this$props2 = this.props,
144
+ view = _this$props2.view,
145
+ node = _this$props2.node,
146
+ getPos = _this$props2.getPos,
147
+ pluginInjectionApi = _this$props2.pluginInjectionApi;
99
148
  var _titleUrlPairFromNode2 = (0, _utils2.titleUrlPairFromNode)(node),
100
149
  url = _titleUrlPairFromNode2.url;
101
150
  if (!getPos || typeof getPos === 'boolean') {
@@ -38,7 +38,6 @@ var InlineCardComponent = exports.InlineCardComponent = /*#__PURE__*/function (_
38
38
  args[_key] = arguments[_key];
39
39
  }
40
40
  _this = _super.call.apply(_super, [this].concat(args));
41
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClick", function () {});
42
41
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onResolve", function (data) {
43
42
  var _this$props = _this.props,
44
43
  getPos = _this$props.getPos,
@@ -92,7 +91,8 @@ var InlineCardComponent = exports.InlineCardComponent = /*#__PURE__*/function (_
92
91
  cardContext = _this$props2.cardContext,
93
92
  actionOptions = _this$props2.actionOptions,
94
93
  showServerActions = _this$props2.showServerActions,
95
- useAlternativePreloader = _this$props2.useAlternativePreloader;
94
+ useAlternativePreloader = _this$props2.useAlternativePreloader,
95
+ onClick = _this$props2.onClick;
96
96
  var _node$attrs = node.attrs,
97
97
  url = _node$attrs.url,
98
98
  data = _node$attrs.data;
@@ -103,7 +103,7 @@ var InlineCardComponent = exports.InlineCardComponent = /*#__PURE__*/function (_
103
103
  url: url,
104
104
  data: data,
105
105
  appearance: "inline",
106
- onClick: this.onClick,
106
+ onClick: onClick,
107
107
  container: this.scrollContainer,
108
108
  onResolve: this.onResolve,
109
109
  onError: this.onError,
@@ -135,7 +135,8 @@ function InlineCardNodeView(props) {
135
135
  allowEmbeds = props.allowEmbeds,
136
136
  allowBlockCards = props.allowBlockCards,
137
137
  enableInlineUpgradeFeatures = props.enableInlineUpgradeFeatures,
138
- pluginInjectionApi = props.pluginInjectionApi;
138
+ pluginInjectionApi = props.pluginInjectionApi,
139
+ onClickCallback = props.onClickCallback;
139
140
  if (!(0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.inline-switcher')) {
140
141
  return /*#__PURE__*/_react.default.createElement(WrappedInlineCard, {
141
142
  node: node,
@@ -143,7 +144,9 @@ function InlineCardNodeView(props) {
143
144
  getPos: getPos,
144
145
  actionOptions: actionOptions,
145
146
  showServerActions: showServerActions,
146
- useAlternativePreloader: useAlternativePreloader
147
+ useAlternativePreloader: useAlternativePreloader,
148
+ pluginInjectionApi: pluginInjectionApi,
149
+ onClickCallback: onClickCallback
147
150
  });
148
151
  }
149
152
  return /*#__PURE__*/_react.default.createElement(WrappedInlineCardWithAwareness, (0, _extends2.default)({
@@ -153,7 +156,8 @@ function InlineCardNodeView(props) {
153
156
  actionOptions: actionOptions,
154
157
  showServerActions: showServerActions,
155
158
  useAlternativePreloader: useAlternativePreloader,
156
- pluginInjectionApi: pluginInjectionApi
159
+ pluginInjectionApi: pluginInjectionApi,
160
+ onClickCallback: onClickCallback
157
161
  }, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards)));
158
162
  }
159
163
  var getAwarenessProps = function getAwarenessProps(editorState, getPos, allowEmbeds, allowBlockCards) {
@@ -27,7 +27,8 @@ var InlineCard = function InlineCard(_ref) {
27
27
  isPulseEnabled = _ref.isPulseEnabled,
28
28
  pluginInjectionApi = _ref.pluginInjectionApi,
29
29
  _ref$isSelected = _ref.isSelected,
30
- isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected;
30
+ isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
31
+ onClick = _ref.onClick;
31
32
  var _node$attrs = node.attrs,
32
33
  url = _node$attrs.url,
33
34
  data = _node$attrs.data;
@@ -105,7 +106,7 @@ var InlineCard = function InlineCard(_ref) {
105
106
  url: url,
106
107
  data: data,
107
108
  appearance: "inline",
108
- onClick: function onClick() {},
109
+ onClick: onClick,
109
110
  container: scrollContainer,
110
111
  onResolve: onResolve,
111
112
  onError: onError,
@@ -114,7 +115,7 @@ var InlineCard = function InlineCard(_ref) {
114
115
  showServerActions: showServerActions,
115
116
  isHovered: isHovered
116
117
  });
117
- }, [data, isHovered, onError, onResolve, scrollContainer, url, useAlternativePreloader, actionOptions, showServerActions]);
118
+ }, [data, isHovered, onError, onResolve, scrollContainer, url, useAlternativePreloader, actionOptions, showServerActions, onClick]);
118
119
  var card = (0, _react.useMemo)(function () {
119
120
  return isOverlayEnabled || isPulseEnabled ? /*#__PURE__*/_react.default.createElement(_AwarenessWrapper.AwarenessWrapper, {
120
121
  isOverlayEnabled: isOverlayEnabled,
@@ -59,7 +59,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
59
59
  cardPluginEvents = options.cardPluginEvents,
60
60
  showUpgradeDiscoverability = options.showUpgradeDiscoverability,
61
61
  allowEmbeds = options.allowEmbeds,
62
- allowBlockCards = options.allowBlockCards;
62
+ allowBlockCards = options.allowBlockCards,
63
+ onClickCallback = options.onClickCallback;
63
64
  var enableInlineUpgradeFeatures = !!showUpgradeDiscoverability && platform !== 'mobile';
64
65
  var shouldUseUpgradeFeatures = (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.inline-switcher') && enableInlineUpgradeFeatures;
65
66
  var inlineCardViewProducer = (0, _reactNodeView.getInlineNodeViewProducer)({
@@ -72,7 +73,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
72
73
  enableInlineUpgradeFeatures: enableInlineUpgradeFeatures,
73
74
  allowEmbeds: allowEmbeds,
74
75
  allowBlockCards: allowBlockCards,
75
- pluginInjectionApi: pluginInjectionApi
76
+ pluginInjectionApi: pluginInjectionApi,
77
+ onClickCallback: onClickCallback
76
78
  }
77
79
  });
78
80
  return new _safePlugin.SafePlugin({
@@ -234,7 +236,9 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
234
236
  var reactComponentProps = {
235
237
  platform: platform,
236
238
  actionOptions: actionOptions,
237
- showServerActions: showServerActions
239
+ showServerActions: showServerActions,
240
+ pluginInjectionApi: pluginInjectionApi,
241
+ onClickCallback: options.onClickCallback
238
242
  };
239
243
  var hasIntlContext = true;
240
244
  var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
@@ -272,7 +276,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
272
276
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
273
277
  pluginInjectionApi: pluginInjectionApi,
274
278
  actionOptions: actionOptions,
275
- showServerActions: showServerActions
279
+ showServerActions: showServerActions,
280
+ onClickCallback: options.onClickCallback
276
281
  };
277
282
  var hasIntlContext = true;
278
283
  return new _embedCard.EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
@@ -398,6 +398,10 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
398
398
  });
399
399
  }
400
400
  var canShowMainToolbar = function canShowMainToolbar() {
401
+ // we do not show smart-link or the datasource icons when the node does not have a url to resolve
402
+ if (!metadata.url) {
403
+ return false;
404
+ }
401
405
  if (
402
406
  // FF that controls visibily of the additional toolbar buttons
403
407
  !(0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-appearance-toolbar')) {
@@ -13,7 +13,6 @@ import { Card } from './genericCard';
13
13
  export class BlockCardComponent extends React.PureComponent {
14
14
  constructor(...args) {
15
15
  super(...args);
16
- _defineProperty(this, "onClick", () => {});
17
16
  _defineProperty(this, "onResolve", data => {
18
17
  const {
19
18
  getPos,
@@ -75,7 +74,8 @@ export class BlockCardComponent extends React.PureComponent {
75
74
  cardContext,
76
75
  platform,
77
76
  actionOptions,
78
- showServerActions
77
+ showServerActions,
78
+ onClick
79
79
  } = this.props;
80
80
  const {
81
81
  url,
@@ -87,7 +87,7 @@ export class BlockCardComponent extends React.PureComponent {
87
87
  data: data,
88
88
  container: this.scrollContainer,
89
89
  appearance: "block",
90
- onClick: this.onClick,
90
+ onClick: onClick,
91
91
  onResolve: this.onResolve,
92
92
  onError: this.onError,
93
93
  platform: platform,
@@ -135,7 +135,9 @@ export class BlockCard extends ReactNodeView {
135
135
  const {
136
136
  platform,
137
137
  actionOptions,
138
- showServerActions
138
+ showServerActions,
139
+ pluginInjectionApi,
140
+ onClickCallback
139
141
  } = this.reactComponentProps;
140
142
  return /*#__PURE__*/React.createElement(WrappedBlockCard, {
141
143
  node: this.node,
@@ -143,7 +145,9 @@ export class BlockCard extends ReactNodeView {
143
145
  getPos: this.getPos,
144
146
  platform: platform,
145
147
  actionOptions: actionOptions,
146
- showServerActions: showServerActions
148
+ showServerActions: showServerActions,
149
+ pluginInjectionApi: pluginInjectionApi,
150
+ onClickCallback: onClickCallback
147
151
  });
148
152
  }
149
153
  }
@@ -88,7 +88,6 @@ export class EmbedCardComponent extends React.PureComponent {
88
88
  constructor(...args) {
89
89
  super(...args);
90
90
  _defineProperty(this, "embedIframeRef", /*#__PURE__*/React.createRef());
91
- _defineProperty(this, "onClick", () => {});
92
91
  _defineProperty(this, "state", {
93
92
  hasPreview: true
94
93
  });
@@ -258,7 +257,8 @@ export class EmbedCardComponent extends React.PureComponent {
258
257
  getPos,
259
258
  pluginInjectionApi,
260
259
  actionOptions,
261
- showServerActions
260
+ showServerActions,
261
+ onClick
262
262
  } = this.props;
263
263
  let {
264
264
  url,
@@ -292,7 +292,7 @@ export class EmbedCardComponent extends React.PureComponent {
292
292
  key: url,
293
293
  url: url,
294
294
  appearance: "embed",
295
- onClick: this.onClick,
295
+ onClick: onClick,
296
296
  onResolve: this.onResolve,
297
297
  onError: this.onError,
298
298
  frameStyle: "show",
@@ -364,7 +364,8 @@ export class EmbedCard extends ReactNodeView {
364
364
  platform,
365
365
  fullWidthMode,
366
366
  dispatchAnalyticsEvent,
367
- pluginInjectionApi
367
+ pluginInjectionApi,
368
+ onClickCallback
368
369
  } = this.reactComponentProps;
369
370
  return /*#__PURE__*/React.createElement(WrappedBlockCard, {
370
371
  node: this.node,
@@ -375,7 +376,8 @@ export class EmbedCard extends ReactNodeView {
375
376
  platform: platform,
376
377
  fullWidthMode: fullWidthMode,
377
378
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
378
- pluginInjectionApi: pluginInjectionApi
379
+ pluginInjectionApi: pluginInjectionApi,
380
+ onClickCallback: onClickCallback
379
381
  });
380
382
  }
381
383
  }
@@ -1,13 +1,42 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import React from 'react';
3
+ import React, { useCallback } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import { isSafeUrl } from '@atlaskit/adf-schema';
6
6
  import { AnalyticsContext } from '@atlaskit/analytics-next';
7
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
8
  import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
10
  import { changeSelectedCardToLinkFallback } from '../pm-plugins/doc';
9
11
  import { getPluginState } from '../pm-plugins/util/state';
10
12
  import { titleUrlPairFromNode } from '../utils';
13
+ const WithClickHandler = ({
14
+ pluginInjectionApi,
15
+ url,
16
+ onClickCallback,
17
+ children
18
+ }) => {
19
+ const {
20
+ editorViewModeState
21
+ } = useSharedPluginState(pluginInjectionApi, ['editorViewMode']);
22
+ const onClick = useCallback(event => {
23
+ if (typeof onClickCallback === 'function') {
24
+ try {
25
+ onClickCallback({
26
+ event,
27
+ url
28
+ });
29
+ } catch {}
30
+ }
31
+ }, [url, onClickCallback]);
32
+
33
+ // Setting `onClick` to `undefined` ensures clicks on smartcards navigate to the URL.
34
+ // If in view mode and not overriding with onClickCallback option, then allow smartlinks to navigate on click.
35
+ const allowNavigation = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' && !onClickCallback;
36
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children({
37
+ onClick: allowNavigation ? undefined : onClick
38
+ }));
39
+ };
11
40
  export function Card(SmartCardComponent, UnsupportedComponent) {
12
41
  var _class;
13
42
  return _class = class extends React.Component {
@@ -16,9 +45,14 @@ export function Card(SmartCardComponent, UnsupportedComponent) {
16
45
  _defineProperty(this, "state", {
17
46
  isError: false
18
47
  });
48
+ _defineProperty(this, "onClick", () => {});
19
49
  }
20
50
  render() {
21
51
  var _getPluginState;
52
+ const {
53
+ pluginInjectionApi,
54
+ onClickCallback
55
+ } = this.props;
22
56
  const {
23
57
  url
24
58
  } = titleUrlPairFromNode(this.props.node);
@@ -48,10 +82,23 @@ export function Card(SmartCardComponent, UnsupportedComponent) {
48
82
  // Below is added for the future implementation of Linking Platform namespaced analytics context
49
83
  location: analyticsEditorAppearance
50
84
  }
51
- }, /*#__PURE__*/React.createElement(SmartCardComponent, _extends({
85
+ }, getBooleanFF('platform.linking-platform.smart-card.on-click-callback') ? /*#__PURE__*/React.createElement(WithClickHandler, {
86
+ pluginInjectionApi: pluginInjectionApi,
87
+ onClickCallback: onClickCallback,
88
+ url: url
89
+ }, ({
90
+ onClick
91
+ }) => /*#__PURE__*/React.createElement(SmartCardComponent, _extends({
92
+ key: url,
93
+ cardContext: cardContext
94
+ }, this.props, {
95
+ onClick: onClick
96
+ }))) : /*#__PURE__*/React.createElement(SmartCardComponent, _extends({
52
97
  key: url,
53
98
  cardContext: cardContext
54
- }, this.props)));
99
+ }, this.props, {
100
+ onClick: this.onClick
101
+ })));
55
102
  }
56
103
  componentDidCatch(error) {
57
104
  const maybeAPIError = error;
@@ -16,7 +16,6 @@ import { InlineCardWithAwareness } from './inlineCardWithAwareness';
16
16
  export class InlineCardComponent extends React.PureComponent {
17
17
  constructor(...args) {
18
18
  super(...args);
19
- _defineProperty(this, "onClick", () => {});
20
19
  _defineProperty(this, "onResolve", data => {
21
20
  const {
22
21
  getPos,
@@ -72,7 +71,8 @@ export class InlineCardComponent extends React.PureComponent {
72
71
  cardContext,
73
72
  actionOptions,
74
73
  showServerActions,
75
- useAlternativePreloader
74
+ useAlternativePreloader,
75
+ onClick
76
76
  } = this.props;
77
77
  const {
78
78
  url,
@@ -85,7 +85,7 @@ export class InlineCardComponent extends React.PureComponent {
85
85
  url: url,
86
86
  data: data,
87
87
  appearance: "inline",
88
- onClick: this.onClick,
88
+ onClick: onClick,
89
89
  container: this.scrollContainer,
90
90
  onResolve: this.onResolve,
91
91
  onError: this.onError,
@@ -116,7 +116,8 @@ export function InlineCardNodeView(props) {
116
116
  allowEmbeds,
117
117
  allowBlockCards,
118
118
  enableInlineUpgradeFeatures,
119
- pluginInjectionApi
119
+ pluginInjectionApi,
120
+ onClickCallback
120
121
  } = props;
121
122
  if (!getBooleanFF('platform.linking-platform.smart-card.inline-switcher')) {
122
123
  return /*#__PURE__*/React.createElement(WrappedInlineCard, {
@@ -125,7 +126,9 @@ export function InlineCardNodeView(props) {
125
126
  getPos: getPos,
126
127
  actionOptions: actionOptions,
127
128
  showServerActions: showServerActions,
128
- useAlternativePreloader: useAlternativePreloader
129
+ useAlternativePreloader: useAlternativePreloader,
130
+ pluginInjectionApi: pluginInjectionApi,
131
+ onClickCallback: onClickCallback
129
132
  });
130
133
  }
131
134
  return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, _extends({
@@ -135,7 +138,8 @@ export function InlineCardNodeView(props) {
135
138
  actionOptions: actionOptions,
136
139
  showServerActions: showServerActions,
137
140
  useAlternativePreloader: useAlternativePreloader,
138
- pluginInjectionApi: pluginInjectionApi
141
+ pluginInjectionApi: pluginInjectionApi,
142
+ onClickCallback: onClickCallback
139
143
  }, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards)));
140
144
  }
141
145
  const getAwarenessProps = (editorState, getPos, allowEmbeds, allowBlockCards) => {
@@ -15,7 +15,8 @@ const InlineCard = ({
15
15
  isOverlayEnabled,
16
16
  isPulseEnabled,
17
17
  pluginInjectionApi,
18
- isSelected = false
18
+ isSelected = false,
19
+ onClick
19
20
  }) => {
20
21
  const {
21
22
  url,
@@ -85,7 +86,7 @@ const InlineCard = ({
85
86
  url: url,
86
87
  data: data,
87
88
  appearance: "inline",
88
- onClick: () => {},
89
+ onClick: onClick,
89
90
  container: scrollContainer,
90
91
  onResolve: onResolve,
91
92
  onError: onError,
@@ -93,7 +94,7 @@ const InlineCard = ({
93
94
  actionOptions: actionOptions,
94
95
  showServerActions: showServerActions,
95
96
  isHovered: isHovered
96
- }), [data, isHovered, onError, onResolve, scrollContainer, url, useAlternativePreloader, actionOptions, showServerActions]);
97
+ }), [data, isHovered, onError, onResolve, scrollContainer, url, useAlternativePreloader, actionOptions, showServerActions, onClick]);
97
98
  const card = useMemo(() => {
98
99
  return isOverlayEnabled || isPulseEnabled ? /*#__PURE__*/React.createElement(AwarenessWrapper, {
99
100
  isOverlayEnabled: isOverlayEnabled,