@atlaskit/editor-plugin-card 0.2.4 → 0.3.0

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`632edbf1930`](https://bitbucket.org/atlassian/atlassian-frontend/commits/632edbf1930) - Updates card plugin floating toolbar to fire an analytic event when viewed.
8
+
9
+ ## 0.2.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 0.2.4
4
16
 
5
17
  ### Patch Changes
@@ -5,9 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.mountHyperlinkPlugin = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
8
9
  var _react = _interopRequireDefault(require("react"));
9
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
12
  var _HyperlinkToolbarAppearance = require("../ui/HyperlinkToolbarAppearance");
13
+ var _ToolbarViewedEvent = require("../ui/ToolbarViewedEvent");
14
+ var getToolbarViewedItem = function getToolbarViewedItem(link) {
15
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor.toolbar-viewed-event')) {
16
+ return [{
17
+ type: 'custom',
18
+ fallback: [],
19
+ render: function render(editorView) {
20
+ return /*#__PURE__*/_react.default.createElement(_ToolbarViewedEvent.ToolbarViewedEvent, {
21
+ key: "edit.link.menu.viewed",
22
+ url: link,
23
+ display: "url",
24
+ editorView: editorView
25
+ });
26
+ }
27
+ }];
28
+ }
29
+ return [];
30
+ };
11
31
  var mountHyperlinkPlugin = function mountHyperlinkPlugin(pluginInjectionApi, options) {
12
32
  return new _safePlugin.SafePlugin({
13
33
  view: function view(editorView) {
@@ -15,7 +35,7 @@ var mountHyperlinkPlugin = function mountHyperlinkPlugin(pluginInjectionApi, opt
15
35
  var _pluginInjectionApi$d, _pluginInjectionApi$d2;
16
36
  pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.hyperlink) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.actions) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.prependToolbarButtons({
17
37
  items: function items(state, intl, providerFactory, link) {
18
- return [{
38
+ return [].concat((0, _toConsumableArray2.default)(getToolbarViewedItem(link)), [{
19
39
  type: 'custom',
20
40
  fallback: [],
21
41
  render: function render(editorView) {
@@ -33,7 +53,7 @@ var mountHyperlinkPlugin = function mountHyperlinkPlugin(pluginInjectionApi, opt
33
53
  cardActions: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.dependencies.card) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions
34
54
  });
35
55
  }
36
- }];
56
+ }]);
37
57
  },
38
58
  onEscapeCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.hideLinkToolbar,
39
59
  onInsertLinkCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.queueCardsFromChangedTr,
@@ -21,11 +21,13 @@ var _remove = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/remove
21
21
  var _settings = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/settings"));
22
22
  var _unlink = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/unlink"));
23
23
  var _shortcut = _interopRequireDefault(require("@atlaskit/icon/glyph/shortcut"));
24
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
24
25
  var _doc = require("./pm-plugins/doc");
25
26
  var _main = require("./pm-plugins/main");
26
27
  var _EditLinkToolbar = require("./ui/EditLinkToolbar");
27
28
  var _LinkToolbarAppearance = require("./ui/LinkToolbarAppearance");
28
29
  var _SmallerEditIcon = require("./ui/SmallerEditIcon");
30
+ var _ToolbarViewedEvent = require("./ui/ToolbarViewedEvent");
29
31
  var _utils2 = require("./utils");
30
32
  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); }
31
33
  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; }
@@ -172,6 +174,26 @@ var withToolbarMetadata = function withToolbarMetadata(command) {
172
174
  inputMethod: _analytics.INPUT_METHOD.FLOATING_TB
173
175
  });
174
176
  };
177
+ var getToolbarViewedItem = function getToolbarViewedItem(url, display) {
178
+ if (!url) {
179
+ return [];
180
+ }
181
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor.toolbar-viewed-event')) {
182
+ return [{
183
+ type: 'custom',
184
+ fallback: [],
185
+ render: function render(editorView) {
186
+ return /*#__PURE__*/_react.default.createElement(_ToolbarViewedEvent.ToolbarViewedEvent, {
187
+ key: "edit.link.menu.viewed",
188
+ url: url,
189
+ display: display,
190
+ editorView: editorView
191
+ });
192
+ }
193
+ }];
194
+ }
195
+ return [];
196
+ };
175
197
  var generateToolbarItems = function generateToolbarItems(state, featureFlags, intl, providerFactory, cardOptions, platform, linkPicker, pluginInjectionApi) {
176
198
  return function (node) {
177
199
  var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4, _pluginInjectionApi$d5, _node$attrs, _node$attrs2, _node$attrs2$datasour;
@@ -271,7 +293,7 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
271
293
  // This code will be executed only for appearances such as "inline", "block" & "embed"
272
294
  // For url appearance, please see HyperlinkToolbarAppearanceProps
273
295
  if (currentAppearance) {
274
- toolbarItems.unshift({
296
+ toolbarItems.unshift.apply(toolbarItems, (0, _toConsumableArray2.default)(getToolbarViewedItem(url, currentAppearance)).concat([{
275
297
  type: 'custom',
276
298
  fallback: [],
277
299
  render: function render(editorView) {
@@ -291,7 +313,7 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
291
313
  }
292
314
  }, {
293
315
  type: 'separator'
294
- });
316
+ }]));
295
317
  }
296
318
  return toolbarItems;
297
319
  }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CardContextProvider = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
11
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _react = _interopRequireDefault(require("react"));
15
+ var _propTypes = _interopRequireDefault(require("prop-types"));
16
+ 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); }; }
17
+ 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; } }
18
+ /**
19
+ * Provides the link provider context via the legacy context adapter
20
+ * and children render function
21
+ */
22
+ // eslint-disable-next-line @repo/internal/react/no-class-components
23
+ var CardContextProvider = /*#__PURE__*/function (_React$Component) {
24
+ (0, _inherits2.default)(CardContextProvider, _React$Component);
25
+ var _super = _createSuper(CardContextProvider);
26
+ function CardContextProvider() {
27
+ (0, _classCallCheck2.default)(this, CardContextProvider);
28
+ return _super.apply(this, arguments);
29
+ }
30
+ (0, _createClass2.default)(CardContextProvider, [{
31
+ key: "render",
32
+ value: function render() {
33
+ var _this$context$context;
34
+ var cardContext = this.context.contextAdapter ? (_this$context$context = this.context.contextAdapter.card) === null || _this$context$context === void 0 ? void 0 : _this$context$context.value : undefined;
35
+ return this.props.children({
36
+ cardContext: cardContext
37
+ });
38
+ }
39
+ }]);
40
+ return CardContextProvider;
41
+ }(_react.default.Component);
42
+ exports.CardContextProvider = CardContextProvider;
43
+ (0, _defineProperty2.default)(CardContextProvider, "contextTypes", {
44
+ contextAdapter: _propTypes.default.object
45
+ });
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.EditorAnalyticsContext = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _analyticsNext = require("@atlaskit/analytics-next");
10
+ var _utils = require("@atlaskit/editor-common/utils");
11
+ var _state = require("../pm-plugins/util/state");
12
+ /**
13
+ * Provides location attribute to child events
14
+ */
15
+ var EditorAnalyticsContext = function EditorAnalyticsContext(_ref) {
16
+ var _getPluginState;
17
+ var editorView = _ref.editorView,
18
+ children = _ref.children;
19
+ var editorAppearance = editorView ? (_getPluginState = (0, _state.getPluginState)(editorView.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance : undefined;
20
+ var analyticsEditorAppearance = (0, _utils.getAnalyticsEditorAppearance)(editorAppearance);
21
+ var analyticsData = {
22
+ attributes: {
23
+ location: analyticsEditorAppearance
24
+ },
25
+ // Below is added for the future implementation of Linking Platform namespaced analytic context
26
+ location: analyticsEditorAppearance
27
+ };
28
+ return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsContext, {
29
+ data: analyticsData
30
+ }, children);
31
+ };
32
+ exports.EditorAnalyticsContext = EditorAnalyticsContext;
@@ -16,10 +16,9 @@ var _react = _interopRequireWildcard(require("react"));
16
16
  var _propTypes = _interopRequireDefault(require("prop-types"));
17
17
  var _analyticsNext = require("@atlaskit/analytics-next");
18
18
  var _analytics = require("@atlaskit/editor-common/analytics");
19
- var _utils = require("@atlaskit/editor-common/utils");
20
19
  var _linkAnalytics = require("@atlaskit/link-analytics");
21
20
  var _actions = require("../pm-plugins/actions");
22
- var _state = require("../pm-plugins/util/state");
21
+ var _EditorAnalyticsContext = require("./EditorAnalyticsContext");
23
22
  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); }
24
23
  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; }
25
24
  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); }; }
@@ -180,7 +179,6 @@ var EditorSmartCardEventsNext = /*#__PURE__*/function (_React$PureComponent) {
180
179
  (0, _createClass2.default)(EditorSmartCardEventsNext, [{
181
180
  key: "render",
182
181
  value: function render() {
183
- var _getPluginState;
184
182
  var cardContext = this.context.contextAdapter.card;
185
183
 
186
184
  /**
@@ -191,19 +189,10 @@ var EditorSmartCardEventsNext = /*#__PURE__*/function (_React$PureComponent) {
191
189
  if (!cardContext) {
192
190
  return null;
193
191
  }
194
- var editorAppearance = (_getPluginState = (0, _state.getPluginState)(this.props.editorView.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance;
195
- var analyticsEditorAppearance = (0, _utils.getAnalyticsEditorAppearance)(editorAppearance);
196
- var analyticsData = {
197
- attributes: {
198
- location: analyticsEditorAppearance
199
- },
200
- // Below is added for the future implementation of Linking Platform namespaced analytic context
201
- location: analyticsEditorAppearance
202
- };
203
192
  return /*#__PURE__*/_react.default.createElement(cardContext.Provider, {
204
193
  value: cardContext.value
205
- }, /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsContext, {
206
- data: analyticsData
194
+ }, /*#__PURE__*/_react.default.createElement(_EditorAnalyticsContext.EditorAnalyticsContext, {
195
+ editorView: this.props.editorView
207
196
  }, /*#__PURE__*/_react.default.createElement(EventsBinding, this.props)));
208
197
  }
209
198
  }]);
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.ToolbarViewedEvent = void 0;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _analyticsNext = require("@atlaskit/analytics-next");
12
+ var _resolvedAttributes = require("@atlaskit/link-analytics/resolved-attributes");
13
+ var _CardContextProvider = require("./CardContextProvider");
14
+ var _EditorAnalyticsContext = require("./EditorAnalyticsContext");
15
+ 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); }
16
+ 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; }
17
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
+ var getResolvedAttributesFromStore = function getResolvedAttributesFromStore(url, display, store) {
20
+ if (!store) {
21
+ return {};
22
+ }
23
+ var urlState = store.getState()[url];
24
+ var displayCategory = display === 'url' ? 'link' : undefined;
25
+ return (0, _resolvedAttributes.getResolvedAttributes)({
26
+ url: url,
27
+ displayCategory: displayCategory
28
+ }, urlState === null || urlState === void 0 ? void 0 : urlState.details);
29
+ };
30
+
31
+ /**
32
+ * Handles firing the toolbar viewed event
33
+ */
34
+ var ToolbarViewedEventBase = function ToolbarViewedEventBase(_ref) {
35
+ var url = _ref.url,
36
+ display = _ref.display,
37
+ cardContext = _ref.cardContext;
38
+ var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
39
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
40
+ var store = cardContext === null || cardContext === void 0 ? void 0 : cardContext.store;
41
+ (0, _react.useEffect)(function () {
42
+ createAnalyticsEvent({
43
+ action: 'viewed',
44
+ actionSubject: 'inlineDialog',
45
+ actionSubjectId: 'editLinkToolbar',
46
+ eventType: 'ui',
47
+ attributes: _objectSpread(_objectSpread({}, getResolvedAttributesFromStore(url, display, store)), {}, {
48
+ display: display
49
+ })
50
+ }).fire('media');
51
+ }, [createAnalyticsEvent, display, url, store]);
52
+ return null;
53
+ };
54
+
55
+ /**
56
+ * Provides analytics context and card context
57
+ */
58
+ var ToolbarViewedEvent = function ToolbarViewedEvent(_ref2) {
59
+ var url = _ref2.url,
60
+ display = _ref2.display,
61
+ editorView = _ref2.editorView;
62
+ return /*#__PURE__*/_react.default.createElement(_EditorAnalyticsContext.EditorAnalyticsContext, {
63
+ editorView: editorView
64
+ }, /*#__PURE__*/_react.default.createElement(_CardContextProvider.CardContextProvider, null, function (_ref3) {
65
+ var cardContext = _ref3.cardContext;
66
+ return url ? /*#__PURE__*/_react.default.createElement(ToolbarViewedEventBase, {
67
+ url: url,
68
+ display: display,
69
+ cardContext: cardContext
70
+ }) : null;
71
+ }));
72
+ };
73
+ exports.ToolbarViewedEvent = ToolbarViewedEvent;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,13 +1,30 @@
1
1
  import React from 'react';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
4
  import { HyperlinkToolbarAppearance } from '../ui/HyperlinkToolbarAppearance';
5
+ import { ToolbarViewedEvent } from '../ui/ToolbarViewedEvent';
6
+ const getToolbarViewedItem = link => {
7
+ if (getBooleanFF('platform.linking-platform.editor.toolbar-viewed-event')) {
8
+ return [{
9
+ type: 'custom',
10
+ fallback: [],
11
+ render: editorView => /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
12
+ key: "edit.link.menu.viewed",
13
+ url: link,
14
+ display: "url",
15
+ editorView: editorView
16
+ })
17
+ }];
18
+ }
19
+ return [];
20
+ };
4
21
  export const mountHyperlinkPlugin = (pluginInjectionApi, options) => {
5
22
  return new SafePlugin({
6
23
  view(editorView) {
7
24
  requestAnimationFrame(() => {
8
25
  var _pluginInjectionApi$d, _pluginInjectionApi$d2;
9
26
  pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.hyperlink) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.actions) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.prependToolbarButtons({
10
- items: (state, intl, providerFactory, link) => [{
27
+ items: (state, intl, providerFactory, link) => [...getToolbarViewedItem(link), {
11
28
  type: 'custom',
12
29
  fallback: [],
13
30
  render: editorView => {
@@ -11,11 +11,13 @@ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
11
11
  import CogIcon from '@atlaskit/icon/glyph/editor/settings';
12
12
  import UnlinkIcon from '@atlaskit/icon/glyph/editor/unlink';
13
13
  import OpenIcon from '@atlaskit/icon/glyph/shortcut';
14
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
15
  import { changeSelectedCardToText } from './pm-plugins/doc';
15
16
  import { pluginKey } from './pm-plugins/main';
16
17
  import { buildEditLinkToolbar, editDatasource, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
17
18
  import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
18
19
  import { SmallerEditIcon } from './ui/SmallerEditIcon';
20
+ import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
19
21
  import { appearanceForNodeType, displayInfoForCard, findCardInfo, titleUrlPairFromNode } from './utils';
20
22
  export const removeCard = editorAnalyticsApi => commandWithMetadata((state, dispatch) => {
21
23
  if (!(state.selection instanceof NodeSelection)) {
@@ -161,6 +163,24 @@ const buildAlignmentOptions = (state, intl, widthPluginDependencyApi, analyticsA
161
163
  const withToolbarMetadata = command => commandWithMetadata(command, {
162
164
  inputMethod: INPUT_METHOD.FLOATING_TB
163
165
  });
166
+ const getToolbarViewedItem = (url, display) => {
167
+ if (!url) {
168
+ return [];
169
+ }
170
+ if (getBooleanFF('platform.linking-platform.editor.toolbar-viewed-event')) {
171
+ return [{
172
+ type: 'custom',
173
+ fallback: [],
174
+ render: editorView => /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
175
+ key: "edit.link.menu.viewed",
176
+ url: url,
177
+ display: display,
178
+ editorView: editorView
179
+ })
180
+ }];
181
+ }
182
+ return [];
183
+ };
164
184
  const generateToolbarItems = (state, featureFlags, intl, providerFactory, cardOptions, platform, linkPicker, pluginInjectionApi) => node => {
165
185
  var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4, _pluginInjectionApi$d5, _node$attrs, _node$attrs2, _node$attrs2$datasour;
166
186
  const {
@@ -267,7 +287,7 @@ const generateToolbarItems = (state, featureFlags, intl, providerFactory, cardOp
267
287
  // This code will be executed only for appearances such as "inline", "block" & "embed"
268
288
  // For url appearance, please see HyperlinkToolbarAppearanceProps
269
289
  if (currentAppearance) {
270
- toolbarItems.unshift({
290
+ toolbarItems.unshift(...getToolbarViewedItem(url, currentAppearance), {
271
291
  type: 'custom',
272
292
  fallback: [],
273
293
  render: editorView => /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
@@ -0,0 +1,19 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ /**
5
+ * Provides the link provider context via the legacy context adapter
6
+ * and children render function
7
+ */ // eslint-disable-next-line @repo/internal/react/no-class-components
8
+ export class CardContextProvider extends React.Component {
9
+ render() {
10
+ var _this$context$context;
11
+ const cardContext = this.context.contextAdapter ? (_this$context$context = this.context.contextAdapter.card) === null || _this$context$context === void 0 ? void 0 : _this$context$context.value : undefined;
12
+ return this.props.children({
13
+ cardContext
14
+ });
15
+ }
16
+ }
17
+ _defineProperty(CardContextProvider, "contextTypes", {
18
+ contextAdapter: PropTypes.object
19
+ });
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
3
+ import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
4
+ import { getPluginState } from '../pm-plugins/util/state';
5
+ /**
6
+ * Provides location attribute to child events
7
+ */
8
+ export const EditorAnalyticsContext = ({
9
+ editorView,
10
+ children
11
+ }) => {
12
+ var _getPluginState;
13
+ const editorAppearance = editorView ? (_getPluginState = getPluginState(editorView.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance : undefined;
14
+ const analyticsEditorAppearance = getAnalyticsEditorAppearance(editorAppearance);
15
+ const analyticsData = {
16
+ attributes: {
17
+ location: analyticsEditorAppearance
18
+ },
19
+ // Below is added for the future implementation of Linking Platform namespaced analytic context
20
+ location: analyticsEditorAppearance
21
+ };
22
+ return /*#__PURE__*/React.createElement(AnalyticsContext, {
23
+ data: analyticsData
24
+ }, children);
25
+ };
@@ -1,12 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React, { useEffect, useMemo } from 'react';
3
3
  import PropTypes from 'prop-types';
4
- import { AnalyticsContext, UIAnalyticsEvent } from '@atlaskit/analytics-next';
4
+ import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
5
5
  import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
- import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
7
6
  import { useSmartLinkLifecycleAnalytics } from '@atlaskit/link-analytics';
8
7
  import { registerSmartCardEventsNext } from '../pm-plugins/actions';
9
- import { getPluginState } from '../pm-plugins/util/state';
8
+ import { EditorAnalyticsContext } from './EditorAnalyticsContext';
10
9
  /**
11
10
  * If the metadata is for a history event,
12
11
  * returns undo/redo instead of instead of what fn(metadata) would have otherwise
@@ -167,7 +166,6 @@ export const EventsBinding = ({
167
166
  // eslint-disable-next-line @repo/internal/react/no-class-components
168
167
  export class EditorSmartCardEventsNext extends React.PureComponent {
169
168
  render() {
170
- var _getPluginState;
171
169
  const cardContext = this.context.contextAdapter.card;
172
170
 
173
171
  /**
@@ -178,19 +176,10 @@ export class EditorSmartCardEventsNext extends React.PureComponent {
178
176
  if (!cardContext) {
179
177
  return null;
180
178
  }
181
- const editorAppearance = (_getPluginState = getPluginState(this.props.editorView.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance;
182
- const analyticsEditorAppearance = getAnalyticsEditorAppearance(editorAppearance);
183
- const analyticsData = {
184
- attributes: {
185
- location: analyticsEditorAppearance
186
- },
187
- // Below is added for the future implementation of Linking Platform namespaced analytic context
188
- location: analyticsEditorAppearance
189
- };
190
179
  return /*#__PURE__*/React.createElement(cardContext.Provider, {
191
180
  value: cardContext.value
192
- }, /*#__PURE__*/React.createElement(AnalyticsContext, {
193
- data: analyticsData
181
+ }, /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
182
+ editorView: this.props.editorView
194
183
  }, /*#__PURE__*/React.createElement(EventsBinding, this.props)));
195
184
  }
196
185
  }
@@ -0,0 +1,62 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
+ import { getResolvedAttributes } from '@atlaskit/link-analytics/resolved-attributes';
4
+ import { CardContextProvider } from './CardContextProvider';
5
+ import { EditorAnalyticsContext } from './EditorAnalyticsContext';
6
+ const getResolvedAttributesFromStore = (url, display, store) => {
7
+ if (!store) {
8
+ return {};
9
+ }
10
+ const urlState = store.getState()[url];
11
+ const displayCategory = display === 'url' ? 'link' : undefined;
12
+ return getResolvedAttributes({
13
+ url,
14
+ displayCategory
15
+ }, urlState === null || urlState === void 0 ? void 0 : urlState.details);
16
+ };
17
+
18
+ /**
19
+ * Handles firing the toolbar viewed event
20
+ */
21
+ const ToolbarViewedEventBase = ({
22
+ url,
23
+ display,
24
+ cardContext
25
+ }) => {
26
+ const {
27
+ createAnalyticsEvent
28
+ } = useAnalyticsEvents();
29
+ const store = cardContext === null || cardContext === void 0 ? void 0 : cardContext.store;
30
+ useEffect(() => {
31
+ createAnalyticsEvent({
32
+ action: 'viewed',
33
+ actionSubject: 'inlineDialog',
34
+ actionSubjectId: 'editLinkToolbar',
35
+ eventType: 'ui',
36
+ attributes: {
37
+ ...getResolvedAttributesFromStore(url, display, store),
38
+ display
39
+ }
40
+ }).fire('media');
41
+ }, [createAnalyticsEvent, display, url, store]);
42
+ return null;
43
+ };
44
+
45
+ /**
46
+ * Provides analytics context and card context
47
+ */
48
+ export const ToolbarViewedEvent = ({
49
+ url,
50
+ display,
51
+ editorView
52
+ }) => {
53
+ return /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
54
+ editorView: editorView
55
+ }, /*#__PURE__*/React.createElement(CardContextProvider, null, ({
56
+ cardContext
57
+ }) => url ? /*#__PURE__*/React.createElement(ToolbarViewedEventBase, {
58
+ url: url,
59
+ display: display,
60
+ cardContext: cardContext
61
+ }) : null));
62
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,6 +1,26 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import React from 'react';
2
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
5
  import { HyperlinkToolbarAppearance } from '../ui/HyperlinkToolbarAppearance';
6
+ import { ToolbarViewedEvent } from '../ui/ToolbarViewedEvent';
7
+ var getToolbarViewedItem = function getToolbarViewedItem(link) {
8
+ if (getBooleanFF('platform.linking-platform.editor.toolbar-viewed-event')) {
9
+ return [{
10
+ type: 'custom',
11
+ fallback: [],
12
+ render: function render(editorView) {
13
+ return /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
14
+ key: "edit.link.menu.viewed",
15
+ url: link,
16
+ display: "url",
17
+ editorView: editorView
18
+ });
19
+ }
20
+ }];
21
+ }
22
+ return [];
23
+ };
4
24
  export var mountHyperlinkPlugin = function mountHyperlinkPlugin(pluginInjectionApi, options) {
5
25
  return new SafePlugin({
6
26
  view: function view(editorView) {
@@ -8,7 +28,7 @@ export var mountHyperlinkPlugin = function mountHyperlinkPlugin(pluginInjectionA
8
28
  var _pluginInjectionApi$d, _pluginInjectionApi$d2;
9
29
  pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.hyperlink) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.actions) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.prependToolbarButtons({
10
30
  items: function items(state, intl, providerFactory, link) {
11
- return [{
31
+ return [].concat(_toConsumableArray(getToolbarViewedItem(link)), [{
12
32
  type: 'custom',
13
33
  fallback: [],
14
34
  render: function render(editorView) {
@@ -26,7 +46,7 @@ export var mountHyperlinkPlugin = function mountHyperlinkPlugin(pluginInjectionA
26
46
  cardActions: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.dependencies.card) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions
27
47
  });
28
48
  }
29
- }];
49
+ }]);
30
50
  },
31
51
  onEscapeCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.hideLinkToolbar,
32
52
  onInsertLinkCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.queueCardsFromChangedTr,
@@ -15,11 +15,13 @@ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
15
15
  import CogIcon from '@atlaskit/icon/glyph/editor/settings';
16
16
  import UnlinkIcon from '@atlaskit/icon/glyph/editor/unlink';
17
17
  import OpenIcon from '@atlaskit/icon/glyph/shortcut';
18
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
18
19
  import { changeSelectedCardToText } from './pm-plugins/doc';
19
20
  import { pluginKey } from './pm-plugins/main';
20
21
  import { buildEditLinkToolbar, editDatasource, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
21
22
  import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
22
23
  import { SmallerEditIcon } from './ui/SmallerEditIcon';
24
+ import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
23
25
  import { appearanceForNodeType, displayInfoForCard, findCardInfo, titleUrlPairFromNode } from './utils';
24
26
  export var removeCard = function removeCard(editorAnalyticsApi) {
25
27
  return commandWithMetadata(function (state, dispatch) {
@@ -158,6 +160,26 @@ var withToolbarMetadata = function withToolbarMetadata(command) {
158
160
  inputMethod: INPUT_METHOD.FLOATING_TB
159
161
  });
160
162
  };
163
+ var getToolbarViewedItem = function getToolbarViewedItem(url, display) {
164
+ if (!url) {
165
+ return [];
166
+ }
167
+ if (getBooleanFF('platform.linking-platform.editor.toolbar-viewed-event')) {
168
+ return [{
169
+ type: 'custom',
170
+ fallback: [],
171
+ render: function render(editorView) {
172
+ return /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
173
+ key: "edit.link.menu.viewed",
174
+ url: url,
175
+ display: display,
176
+ editorView: editorView
177
+ });
178
+ }
179
+ }];
180
+ }
181
+ return [];
182
+ };
161
183
  var generateToolbarItems = function generateToolbarItems(state, featureFlags, intl, providerFactory, cardOptions, platform, linkPicker, pluginInjectionApi) {
162
184
  return function (node) {
163
185
  var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4, _pluginInjectionApi$d5, _node$attrs, _node$attrs2, _node$attrs2$datasour;
@@ -257,7 +279,7 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
257
279
  // This code will be executed only for appearances such as "inline", "block" & "embed"
258
280
  // For url appearance, please see HyperlinkToolbarAppearanceProps
259
281
  if (currentAppearance) {
260
- toolbarItems.unshift({
282
+ toolbarItems.unshift.apply(toolbarItems, _toConsumableArray(getToolbarViewedItem(url, currentAppearance)).concat([{
261
283
  type: 'custom',
262
284
  fallback: [],
263
285
  render: function render(editorView) {
@@ -277,7 +299,7 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
277
299
  }
278
300
  }, {
279
301
  type: 'separator'
280
- });
302
+ }]));
281
303
  }
282
304
  return toolbarItems;
283
305
  }
@@ -0,0 +1,36 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _inherits from "@babel/runtime/helpers/inherits";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+ 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; } }
9
+ import React from 'react';
10
+ import PropTypes from 'prop-types';
11
+ /**
12
+ * Provides the link provider context via the legacy context adapter
13
+ * and children render function
14
+ */ // eslint-disable-next-line @repo/internal/react/no-class-components
15
+ export var CardContextProvider = /*#__PURE__*/function (_React$Component) {
16
+ _inherits(CardContextProvider, _React$Component);
17
+ var _super = _createSuper(CardContextProvider);
18
+ function CardContextProvider() {
19
+ _classCallCheck(this, CardContextProvider);
20
+ return _super.apply(this, arguments);
21
+ }
22
+ _createClass(CardContextProvider, [{
23
+ key: "render",
24
+ value: function render() {
25
+ var _this$context$context;
26
+ var cardContext = this.context.contextAdapter ? (_this$context$context = this.context.contextAdapter.card) === null || _this$context$context === void 0 ? void 0 : _this$context$context.value : undefined;
27
+ return this.props.children({
28
+ cardContext: cardContext
29
+ });
30
+ }
31
+ }]);
32
+ return CardContextProvider;
33
+ }(React.Component);
34
+ _defineProperty(CardContextProvider, "contextTypes", {
35
+ contextAdapter: PropTypes.object
36
+ });
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
3
+ import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
4
+ import { getPluginState } from '../pm-plugins/util/state';
5
+ /**
6
+ * Provides location attribute to child events
7
+ */
8
+ export var EditorAnalyticsContext = function EditorAnalyticsContext(_ref) {
9
+ var _getPluginState;
10
+ var editorView = _ref.editorView,
11
+ children = _ref.children;
12
+ var editorAppearance = editorView ? (_getPluginState = getPluginState(editorView.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance : undefined;
13
+ var analyticsEditorAppearance = getAnalyticsEditorAppearance(editorAppearance);
14
+ var analyticsData = {
15
+ attributes: {
16
+ location: analyticsEditorAppearance
17
+ },
18
+ // Below is added for the future implementation of Linking Platform namespaced analytic context
19
+ location: analyticsEditorAppearance
20
+ };
21
+ return /*#__PURE__*/React.createElement(AnalyticsContext, {
22
+ data: analyticsData
23
+ }, children);
24
+ };
@@ -8,12 +8,11 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
8
8
  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; } }
9
9
  import React, { useEffect, useMemo } from 'react';
10
10
  import PropTypes from 'prop-types';
11
- import { AnalyticsContext, UIAnalyticsEvent } from '@atlaskit/analytics-next';
11
+ import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
12
12
  import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
13
- import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
14
13
  import { useSmartLinkLifecycleAnalytics } from '@atlaskit/link-analytics';
15
14
  import { registerSmartCardEventsNext } from '../pm-plugins/actions';
16
- import { getPluginState } from '../pm-plugins/util/state';
15
+ import { EditorAnalyticsContext } from './EditorAnalyticsContext';
17
16
  /**
18
17
  * If the metadata is for a history event,
19
18
  * returns undo/redo instead of instead of what fn(metadata) would have otherwise
@@ -169,7 +168,6 @@ export var EditorSmartCardEventsNext = /*#__PURE__*/function (_React$PureCompone
169
168
  _createClass(EditorSmartCardEventsNext, [{
170
169
  key: "render",
171
170
  value: function render() {
172
- var _getPluginState;
173
171
  var cardContext = this.context.contextAdapter.card;
174
172
 
175
173
  /**
@@ -180,19 +178,10 @@ export var EditorSmartCardEventsNext = /*#__PURE__*/function (_React$PureCompone
180
178
  if (!cardContext) {
181
179
  return null;
182
180
  }
183
- var editorAppearance = (_getPluginState = getPluginState(this.props.editorView.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance;
184
- var analyticsEditorAppearance = getAnalyticsEditorAppearance(editorAppearance);
185
- var analyticsData = {
186
- attributes: {
187
- location: analyticsEditorAppearance
188
- },
189
- // Below is added for the future implementation of Linking Platform namespaced analytic context
190
- location: analyticsEditorAppearance
191
- };
192
181
  return /*#__PURE__*/React.createElement(cardContext.Provider, {
193
182
  value: cardContext.value
194
- }, /*#__PURE__*/React.createElement(AnalyticsContext, {
195
- data: analyticsData
183
+ }, /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
184
+ editorView: this.props.editorView
196
185
  }, /*#__PURE__*/React.createElement(EventsBinding, this.props)));
197
186
  }
198
187
  }]);
@@ -0,0 +1,62 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ import React, { useEffect } from 'react';
5
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
6
+ import { getResolvedAttributes } from '@atlaskit/link-analytics/resolved-attributes';
7
+ import { CardContextProvider } from './CardContextProvider';
8
+ import { EditorAnalyticsContext } from './EditorAnalyticsContext';
9
+ var getResolvedAttributesFromStore = function getResolvedAttributesFromStore(url, display, store) {
10
+ if (!store) {
11
+ return {};
12
+ }
13
+ var urlState = store.getState()[url];
14
+ var displayCategory = display === 'url' ? 'link' : undefined;
15
+ return getResolvedAttributes({
16
+ url: url,
17
+ displayCategory: displayCategory
18
+ }, urlState === null || urlState === void 0 ? void 0 : urlState.details);
19
+ };
20
+
21
+ /**
22
+ * Handles firing the toolbar viewed event
23
+ */
24
+ var ToolbarViewedEventBase = function ToolbarViewedEventBase(_ref) {
25
+ var url = _ref.url,
26
+ display = _ref.display,
27
+ cardContext = _ref.cardContext;
28
+ var _useAnalyticsEvents = useAnalyticsEvents(),
29
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
30
+ var store = cardContext === null || cardContext === void 0 ? void 0 : cardContext.store;
31
+ useEffect(function () {
32
+ createAnalyticsEvent({
33
+ action: 'viewed',
34
+ actionSubject: 'inlineDialog',
35
+ actionSubjectId: 'editLinkToolbar',
36
+ eventType: 'ui',
37
+ attributes: _objectSpread(_objectSpread({}, getResolvedAttributesFromStore(url, display, store)), {}, {
38
+ display: display
39
+ })
40
+ }).fire('media');
41
+ }, [createAnalyticsEvent, display, url, store]);
42
+ return null;
43
+ };
44
+
45
+ /**
46
+ * Provides analytics context and card context
47
+ */
48
+ export var ToolbarViewedEvent = function ToolbarViewedEvent(_ref2) {
49
+ var url = _ref2.url,
50
+ display = _ref2.display,
51
+ editorView = _ref2.editorView;
52
+ return /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
53
+ editorView: editorView
54
+ }, /*#__PURE__*/React.createElement(CardContextProvider, null, function (_ref3) {
55
+ var cardContext = _ref3.cardContext;
56
+ return url ? /*#__PURE__*/React.createElement(ToolbarViewedEventBase, {
57
+ url: url,
58
+ display: display,
59
+ cardContext: cardContext
60
+ }) : null;
61
+ }));
62
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import type { CardContext } from '@atlaskit/link-provider';
4
+ type CardContextProviderProps = {
5
+ children: ({ cardContext }: {
6
+ cardContext?: CardContext;
7
+ }) => React.ReactNode;
8
+ };
9
+ /**
10
+ * Provides the link provider context via the legacy context adapter
11
+ * and children render function
12
+ */
13
+ export declare class CardContextProvider extends React.Component<CardContextProviderProps, {}> {
14
+ static contextTypes: {
15
+ contextAdapter: PropTypes.Requireable<object>;
16
+ };
17
+ render(): React.ReactNode;
18
+ }
19
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { EditorView } from 'prosemirror-view';
3
+ export type EditorAnalyticsContextProps = {
4
+ editorView?: EditorView;
5
+ children: React.ReactNode;
6
+ };
7
+ /**
8
+ * Provides location attribute to child events
9
+ */
10
+ export declare const EditorAnalyticsContext: ({ editorView, children, }: EditorAnalyticsContextProps) => JSX.Element;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { EditorAnalyticsContextProps } from './EditorAnalyticsContext';
3
+ type ToolbarViewedEventProps = {
4
+ url?: string;
5
+ display: string | null;
6
+ };
7
+ /**
8
+ * Provides analytics context and card context
9
+ */
10
+ export declare const ToolbarViewedEvent: ({ url, display, editorView, }: ToolbarViewedEventProps & Omit<EditorAnalyticsContextProps, 'children'>) => JSX.Element;
11
+ export {};
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import type { CardContext } from '@atlaskit/link-provider';
4
+ type CardContextProviderProps = {
5
+ children: ({ cardContext }: {
6
+ cardContext?: CardContext;
7
+ }) => React.ReactNode;
8
+ };
9
+ /**
10
+ * Provides the link provider context via the legacy context adapter
11
+ * and children render function
12
+ */
13
+ export declare class CardContextProvider extends React.Component<CardContextProviderProps, {}> {
14
+ static contextTypes: {
15
+ contextAdapter: PropTypes.Requireable<object>;
16
+ };
17
+ render(): React.ReactNode;
18
+ }
19
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { EditorView } from 'prosemirror-view';
3
+ export type EditorAnalyticsContextProps = {
4
+ editorView?: EditorView;
5
+ children: React.ReactNode;
6
+ };
7
+ /**
8
+ * Provides location attribute to child events
9
+ */
10
+ export declare const EditorAnalyticsContext: ({ editorView, children, }: EditorAnalyticsContextProps) => JSX.Element;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { EditorAnalyticsContextProps } from './EditorAnalyticsContext';
3
+ type ToolbarViewedEventProps = {
4
+ url?: string;
5
+ display: string | null;
6
+ };
7
+ /**
8
+ * Provides analytics context and card context
9
+ */
10
+ export declare const ToolbarViewedEvent: ({ url, display, editorView, }: ToolbarViewedEventProps & Omit<EditorAnalyticsContextProps, 'children'>) => JSX.Element;
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Card plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,9 +31,9 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/adf-schema": "^26.1.0",
34
+ "@atlaskit/adf-schema": "^26.4.0",
35
35
  "@atlaskit/analytics-next": "^9.1.0",
36
- "@atlaskit/editor-common": "^74.26.0",
36
+ "@atlaskit/editor-common": "^74.29.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^0.1.0",
38
38
  "@atlaskit/editor-plugin-decorations": "^0.1.0",
39
39
  "@atlaskit/editor-plugin-feature-flags": "^0.1.0",
@@ -41,11 +41,12 @@
41
41
  "@atlaskit/editor-plugin-grid": "^0.1.0",
42
42
  "@atlaskit/editor-plugin-hyperlink": "^0.2.0",
43
43
  "@atlaskit/editor-plugin-width": "^0.1.0",
44
- "@atlaskit/editor-shared-styles": "^2.4.0",
44
+ "@atlaskit/editor-shared-styles": "^2.5.0",
45
45
  "@atlaskit/icon": "^21.12.0",
46
46
  "@atlaskit/link-analytics": "^8.2.0",
47
- "@atlaskit/link-datasource": "^0.29.0",
48
- "@atlaskit/smart-card": "^26.9.0",
47
+ "@atlaskit/link-datasource": "^0.30.0",
48
+ "@atlaskit/platform-feature-flags": "^0.2.0",
49
+ "@atlaskit/smart-card": "^26.12.0",
49
50
  "@atlaskit/theme": "^12.5.0",
50
51
  "@atlaskit/tokens": "^1.13.0",
51
52
  "@babel/runtime": "^7.0.0",
@@ -69,7 +70,7 @@
69
70
  "devDependencies": {
70
71
  "@atlaskit/activity-provider": "^2.4.0",
71
72
  "@atlaskit/editor-test-helpers": "^18.9.0",
72
- "@atlaskit/link-test-helpers": "^4.2.0",
73
+ "@atlaskit/link-test-helpers": "^6.0.0",
73
74
  "@atlaskit/media-test-helpers": "^33.0.0",
74
75
  "@atlaskit/ssr": "*",
75
76
  "@atlaskit/util-data-test": "^17.8.0",
@@ -121,6 +122,9 @@
121
122
  "platform-feature-flags": {
122
123
  "platform.linking-platform.datasource-jira_issues": {
123
124
  "type": "boolean"
125
+ },
126
+ "platform.linking-platform.editor.toolbar-viewed-event": {
127
+ "type": "boolean"
124
128
  }
125
129
  }
126
130
  }