@atlaskit/editor-plugin-card 0.2.5 → 0.3.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 (106) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/pm-plugins/analytics/events-from-tr.js +3 -3
  3. package/dist/cjs/pm-plugins/doc.js +9 -9
  4. package/dist/cjs/pm-plugins/keymap.js +7 -7
  5. package/dist/cjs/pm-plugins/main.js +9 -9
  6. package/dist/cjs/pm-plugins/mountHyperlink.js +22 -2
  7. package/dist/cjs/pm-plugins/plugin-key.js +2 -2
  8. package/dist/cjs/toolbar.js +39 -17
  9. package/dist/cjs/ui/CardContextProvider.js +45 -0
  10. package/dist/cjs/ui/DatasourceModal/index.js +2 -2
  11. package/dist/cjs/ui/EditLinkToolbar.js +2 -2
  12. package/dist/cjs/ui/EditorAnalyticsContext.js +32 -0
  13. package/dist/cjs/ui/EditorSmartCardEventsNext.js +3 -14
  14. package/dist/cjs/ui/LayoutButton/utils.js +2 -2
  15. package/dist/cjs/ui/LinkToolbarAppearance.js +3 -3
  16. package/dist/cjs/ui/ResizableEmbedCard.js +4 -4
  17. package/dist/cjs/ui/ToolbarViewedEvent.js +73 -0
  18. package/dist/cjs/utils.js +2 -2
  19. package/dist/cjs/version.json +1 -1
  20. package/dist/es2019/pm-plugins/analytics/events-from-tr.js +1 -1
  21. package/dist/es2019/pm-plugins/doc.js +2 -2
  22. package/dist/es2019/pm-plugins/keymap.js +3 -3
  23. package/dist/es2019/pm-plugins/main.js +2 -2
  24. package/dist/es2019/pm-plugins/mountHyperlink.js +18 -1
  25. package/dist/es2019/pm-plugins/plugin-key.js +1 -1
  26. package/dist/es2019/toolbar.js +23 -3
  27. package/dist/es2019/ui/CardContextProvider.js +19 -0
  28. package/dist/es2019/ui/DatasourceModal/index.js +1 -1
  29. package/dist/es2019/ui/EditLinkToolbar.js +1 -1
  30. package/dist/es2019/ui/EditorAnalyticsContext.js +25 -0
  31. package/dist/es2019/ui/EditorSmartCardEventsNext.js +4 -15
  32. package/dist/es2019/ui/LayoutButton/utils.js +1 -1
  33. package/dist/es2019/ui/LinkToolbarAppearance.js +1 -1
  34. package/dist/es2019/ui/ResizableEmbedCard.js +1 -1
  35. package/dist/es2019/ui/ToolbarViewedEvent.js +62 -0
  36. package/dist/es2019/utils.js +1 -1
  37. package/dist/es2019/version.json +1 -1
  38. package/dist/esm/pm-plugins/analytics/events-from-tr.js +1 -1
  39. package/dist/esm/pm-plugins/doc.js +2 -2
  40. package/dist/esm/pm-plugins/keymap.js +3 -3
  41. package/dist/esm/pm-plugins/main.js +2 -2
  42. package/dist/esm/pm-plugins/mountHyperlink.js +22 -2
  43. package/dist/esm/pm-plugins/plugin-key.js +1 -1
  44. package/dist/esm/toolbar.js +26 -4
  45. package/dist/esm/ui/CardContextProvider.js +36 -0
  46. package/dist/esm/ui/DatasourceModal/index.js +1 -1
  47. package/dist/esm/ui/EditLinkToolbar.js +1 -1
  48. package/dist/esm/ui/EditorAnalyticsContext.js +24 -0
  49. package/dist/esm/ui/EditorSmartCardEventsNext.js +4 -15
  50. package/dist/esm/ui/LayoutButton/utils.js +1 -1
  51. package/dist/esm/ui/LinkToolbarAppearance.js +1 -1
  52. package/dist/esm/ui/ResizableEmbedCard.js +1 -1
  53. package/dist/esm/ui/ToolbarViewedEvent.js +62 -0
  54. package/dist/esm/utils.js +1 -1
  55. package/dist/esm/version.json +1 -1
  56. package/dist/types/nodeviews/datasource.d.ts +2 -2
  57. package/dist/types/nodeviews/embedCard.d.ts +1 -1
  58. package/dist/types/nodeviews/genericCard.d.ts +2 -2
  59. package/dist/types/pm-plugins/actions.d.ts +1 -1
  60. package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +1 -1
  61. package/dist/types/pm-plugins/analytics/types.d.ts +1 -1
  62. package/dist/types/pm-plugins/analytics/utils.d.ts +2 -2
  63. package/dist/types/pm-plugins/doc.d.ts +3 -3
  64. package/dist/types/pm-plugins/plugin-key.d.ts +1 -1
  65. package/dist/types/pm-plugins/shouldReplaceLink.d.ts +1 -1
  66. package/dist/types/pm-plugins/util/resolve.d.ts +1 -1
  67. package/dist/types/pm-plugins/util/state.d.ts +1 -1
  68. package/dist/types/ui/CardContextProvider.d.ts +19 -0
  69. package/dist/types/ui/DatasourceModal/ModalWithState.d.ts +1 -1
  70. package/dist/types/ui/DatasourceModal/index.d.ts +1 -1
  71. package/dist/types/ui/EditLinkToolbar.d.ts +2 -2
  72. package/dist/types/ui/EditorAnalyticsContext.d.ts +10 -0
  73. package/dist/types/ui/EditorSmartCardEvents.d.ts +1 -1
  74. package/dist/types/ui/EditorSmartCardEventsNext.d.ts +1 -1
  75. package/dist/types/ui/HyperlinkToolbarAppearance.d.ts +2 -2
  76. package/dist/types/ui/LayoutButton/types.d.ts +1 -1
  77. package/dist/types/ui/LayoutButton/utils.d.ts +1 -1
  78. package/dist/types/ui/LinkToolbarAppearance.d.ts +2 -2
  79. package/dist/types/ui/ToolbarViewedEvent.d.ts +11 -0
  80. package/dist/types/utils.d.ts +2 -2
  81. package/dist/types-ts4.5/nodeviews/datasource.d.ts +2 -2
  82. package/dist/types-ts4.5/nodeviews/embedCard.d.ts +1 -1
  83. package/dist/types-ts4.5/nodeviews/genericCard.d.ts +2 -2
  84. package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -1
  85. package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +1 -1
  86. package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +1 -1
  87. package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +2 -2
  88. package/dist/types-ts4.5/pm-plugins/doc.d.ts +3 -3
  89. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +1 -1
  90. package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +1 -1
  91. package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +1 -1
  92. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +1 -1
  93. package/dist/types-ts4.5/ui/CardContextProvider.d.ts +19 -0
  94. package/dist/types-ts4.5/ui/DatasourceModal/ModalWithState.d.ts +1 -1
  95. package/dist/types-ts4.5/ui/DatasourceModal/index.d.ts +1 -1
  96. package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +2 -2
  97. package/dist/types-ts4.5/ui/EditorAnalyticsContext.d.ts +10 -0
  98. package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +1 -1
  99. package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +1 -1
  100. package/dist/types-ts4.5/ui/HyperlinkToolbarAppearance.d.ts +2 -2
  101. package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +1 -1
  102. package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +1 -1
  103. package/dist/types-ts4.5/ui/LinkToolbarAppearance.d.ts +2 -2
  104. package/dist/types-ts4.5/ui/ToolbarViewedEvent.d.ts +11 -0
  105. package/dist/types-ts4.5/utils.d.ts +2 -2
  106. package/package.json +10 -12
@@ -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,
@@ -1,2 +1,2 @@
1
- import { PluginKey } from 'prosemirror-state';
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
2
  export var pluginKey = new PluginKey('cardPlugin');
@@ -3,23 +3,25 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  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; }
4
4
  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; }
5
5
  import React from 'react';
6
- import { NodeSelection } from 'prosemirror-state';
7
- import { findDomRefAtPos, removeSelectedNode } from 'prosemirror-utils';
8
6
  import { isSafeUrl } from '@atlaskit/adf-schema';
9
7
  import { ACTION, ACTION_SUBJECT, buildOpenedSettingsPayload, buildVisitedLinkPayload, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
10
8
  import { buildLayoutButtons, commandWithMetadata } from '@atlaskit/editor-common/card';
11
9
  import commonMessages, { linkMessages, linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
12
10
  import { FLOATING_TOOLBAR_LINKPICKER_CLASSNAME, richMediaClassName } from '@atlaskit/editor-common/styles';
13
11
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
12
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
13
+ import { findDomRefAtPos, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
14
14
  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
+ });
@@ -1,6 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import React, { useCallback } from 'react';
3
- import { NodeSelection } from 'prosemirror-state';
3
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
5
5
  import { hideDatasourceModal } from '../../pm-plugins/actions';
6
6
  import { insertDatasource, updateExistingDatasource } from '../../pm-plugins/doc';
@@ -8,13 +8,13 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
8
  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); }; }
9
9
  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; } }
10
10
  import React from 'react';
11
- import { NodeSelection } from 'prosemirror-state';
12
11
  import { ACTION, buildEditLinkPayload, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
13
12
  import { commandWithMetadata } from '@atlaskit/editor-common/card';
14
13
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
15
14
  import { HyperlinkAddToolbar as HyperlinkToolbar } from '@atlaskit/editor-common/link';
16
15
  import { linkToolbarMessages } from '@atlaskit/editor-common/messages';
17
16
  import { LINKPICKER_HEIGHT_IN_PX, RECENT_SEARCH_HEIGHT_IN_PX, RECENT_SEARCH_WIDTH_IN_PX, withOuterListeners } from '@atlaskit/editor-common/ui';
17
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
18
18
  import { JIRA_LIST_OF_LINKS_DATASOURCE_ID } from '@atlaskit/link-datasource';
19
19
  import { hideLinkToolbar as _hideLinkToolbar, showDatasourceModal, showLinkToolbar } from '../pm-plugins/actions';
20
20
  import { changeSelectedCardToLink, updateCard } from '../pm-plugins/doc';
@@ -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
  }]);
@@ -1,4 +1,4 @@
1
- import { findSelectedNodeOfType } from 'prosemirror-utils';
1
+ import { findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
2
  export var getDatasource = function getDatasource(editorView) {
3
3
  var _findSelectedNodeOfTy;
4
4
  var _editorView$state = editorView.state,
@@ -11,11 +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
  import React from 'react';
13
13
  import PropTypes from 'prop-types';
14
- import { Fragment } from 'prosemirror-model';
15
14
  import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
16
15
  import { commandWithMetadata, getButtonGroupOption, LinkToolbarButtonGroup } from '@atlaskit/editor-common/card';
17
16
  import nodeNames, { cardMessages as messages } from '@atlaskit/editor-common/messages';
18
17
  import { isSupportedInParent } from '@atlaskit/editor-common/utils';
18
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
19
19
  // eslint-disable-next-line @repo/internal/react/no-class-components
20
20
  export var LinkToolbarAppearance = /*#__PURE__*/function (_React$Component) {
21
21
  _inherits(LinkToolbarAppearance, _React$Component);
@@ -13,9 +13,9 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
13
13
  /** @jsx jsx */
14
14
  import React from 'react';
15
15
  import { jsx } from '@emotion/react';
16
- import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from 'prosemirror-utils';
17
16
  import { embedSpacingStyles } from '@atlaskit/editor-common/styles';
18
17
  import { calcColumnsFromPx, calcMediaPxWidth, calcPctFromPx, calcPxFromColumns, handleSides, imageAlignmentMap, Resizer, snapTo, wrappedLayouts, wrapperStyle } from '@atlaskit/editor-common/ui';
18
+ import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
19
19
  import { akEditorBreakoutPadding, akEditorMediaResizeHandlerPaddingWide, akEditorWideLayoutWidth, breakoutWideScaleRatio, DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
20
20
  import { embedHeaderHeight } from '@atlaskit/smart-card';
21
21
  // eslint-disable-next-line @repo/internal/react/no-class-components
@@ -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
+ };
package/dist/esm/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { NodeSelection } from 'prosemirror-state';
1
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { pluginKey } from './pm-plugins/plugin-key';
3
3
  export var appearanceForNodeType = function appearanceForNodeType(spec) {
4
4
  if (spec.name === 'inlineCard') {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "0.2.5",
3
+ "version": "0.3.1",
4
4
  "sideEffects": false
5
5
  }
@@ -2,12 +2,12 @@
2
2
  import React from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import PropTypes from 'prop-types';
5
- import { Node as PMNode } from 'prosemirror-model';
6
- import { EditorView } from 'prosemirror-view';
7
5
  import { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
8
6
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
9
7
  import ReactNodeView, { getPosHandler, ReactComponentProps } from '@atlaskit/editor-common/react-node-view';
10
8
  import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
9
+ import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
10
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
11
11
  import type { cardPlugin } from '../index';
12
12
  import { DatasourceTableLayout } from '../ui/LayoutButton/types';
13
13
  interface DatasourceProps extends ReactComponentProps {
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { Node as PMNode } from 'prosemirror-model';
4
3
  import { RichMediaLayout } from '@atlaskit/adf-schema';
5
4
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
5
+ import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
6
6
  import { SmartCardProps } from './genericCard';
7
7
  export type EmbedCardState = {
8
8
  hasPreview: boolean;
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
- import { Node as PMNode } from 'prosemirror-model';
3
- import { EditorView } from 'prosemirror-view';
4
2
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
5
3
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
6
4
  import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
7
5
  import { getPosHandler, ReactComponentProps } from '@atlaskit/editor-common/react-node-view';
8
6
  import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
7
+ import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
8
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
9
9
  import { SmartCardContext } from '@atlaskit/link-provider';
10
10
  import { CardPlatform } from '@atlaskit/smart-card';
11
11
  import type { cardPlugin } from '../index';
@@ -1,6 +1,6 @@
1
- import { Transaction } from 'prosemirror-state';
2
1
  import { CardProvider } from '@atlaskit/editor-common/provider-factory';
3
2
  import type { DatasourceModalType } from '@atlaskit/editor-common/types';
3
+ import { Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import { SmartLinkEvents } from '@atlaskit/smart-card';
5
5
  import { CardInfo, CardPluginAction, Request, SmartLinkEventsNext } from '../types';
6
6
  import { DatasourceTableLayout } from '../ui/LayoutButton/types';
@@ -1,4 +1,4 @@
1
- import { EditorState, ReadonlyTransaction, Transaction } from 'prosemirror-state';
1
+ import { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  import { LifecycleEvent } from '../../types';
3
3
  import { Link } from './types';
4
4
  export declare const findChangedLinks: (tr: Transaction | ReadonlyTransaction, state: EditorState) => {
@@ -1,4 +1,4 @@
1
- import { Mark, Node } from 'prosemirror-model';
1
+ import { Mark, Node } from '@atlaskit/editor-prosemirror/model';
2
2
  export type Link = {
3
3
  type: 'node';
4
4
  pos: number;
@@ -1,5 +1,5 @@
1
- import { Node, Schema } from 'prosemirror-model';
2
- import { ReadonlyTransaction, Transaction } from 'prosemirror-state';
1
+ import { Node, Schema } from '@atlaskit/editor-prosemirror/model';
2
+ import { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Link } from './types';
4
4
  /**
5
5
  * Whether a node is a "link" node, ie inline card, block card, embed card
@@ -1,11 +1,11 @@
1
- import { Node } from 'prosemirror-model';
2
- import { EditorState, Transaction } from 'prosemirror-state';
3
- import { EditorView } from 'prosemirror-view';
4
1
  import type { CreateUIAnalyticsEvent, UIAnalyticsEvent } from '@atlaskit/analytics-next';
5
2
  import { ACTION, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
3
  import type { CardReplacementInputMethod } from '@atlaskit/editor-common/card';
7
4
  import { CardAdf, CardAppearance, DatasourceAdf } from '@atlaskit/editor-common/provider-factory';
8
5
  import type { Command } from '@atlaskit/editor-common/types';
6
+ import { Node } from '@atlaskit/editor-prosemirror/model';
7
+ import { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
8
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
9
9
  import type { InlineCardAdf } from '@atlaskit/smart-card';
10
10
  import { Request } from '../types';
11
11
  export declare const replaceQueuedUrlWithCard: (url: string, cardData: CardAdf | DatasourceAdf, analyticsAction?: ACTION, editorAnalyticsApi?: EditorAnalyticsAPI, createAnalyticsEvent?: CreateUIAnalyticsEvent) => Command;
@@ -1,3 +1,3 @@
1
- import { PluginKey } from 'prosemirror-state';
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
2
  import { CardPluginState } from '../types';
3
3
  export declare const pluginKey: PluginKey<CardPluginState>;
@@ -1,2 +1,2 @@
1
- import { Node } from 'prosemirror-model';
1
+ import { Node } from '@atlaskit/editor-prosemirror/model';
2
2
  export declare function shouldReplaceLink(node: Node, compareLinkText?: boolean, compareToUrl?: string): boolean;
@@ -1,8 +1,8 @@
1
- import { EditorView } from 'prosemirror-view';
2
1
  import { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
3
2
  import { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
3
  import { CardOptions } from '@atlaskit/editor-common/card';
5
4
  import { CardProvider, DatasourceAdf } from '@atlaskit/editor-common/provider-factory';
5
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
6
6
  import { Request } from '../../types';
7
7
  export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf | DatasourceAdf>;
8
8
  export declare const handleProvider: (_: 'cardProvider', provider: Promise<CardProvider> | undefined, view: EditorView) => void;
@@ -1,4 +1,4 @@
1
- import { EditorState, ReadonlyTransaction } from 'prosemirror-state';
1
+ import { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
2
2
  import { CardPluginState, Request } from '../../types';
3
3
  export declare const getPluginState: (editorState: EditorState) => CardPluginState | undefined;
4
4
  export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState, tr: ReadonlyTransaction) => {
@@ -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 {};
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { EditorView } from 'prosemirror-view';
3
2
  import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { cardPlugin } from '../../plugin';
5
5
  declare const ModalWithState: ({ api, editorView, }: {
6
6
  api: ExtractInjectionAPI<typeof cardPlugin> | undefined;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { EditorView } from 'prosemirror-view';
3
2
  import { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
3
  import { DatasourceModalType } from '@atlaskit/editor-common/types';
4
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  type DatasourceModalProps = {
6
6
  view: EditorView;
7
7
  editorAnalyticsApi?: EditorAnalyticsAPI;
@@ -1,6 +1,4 @@
1
1
  import React from 'react';
2
- import { Node } from 'prosemirror-model';
3
- import { EditorView } from 'prosemirror-view';
4
2
  import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
5
3
  import { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
4
  import { HyperlinkAddToolbarProps } from '@atlaskit/editor-common/link';
@@ -8,6 +6,8 @@ import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
8
6
  import type { Command, ExtractInjectionAPI, FloatingToolbarConfig, FloatingToolbarItem, LinkInputType, LinkPickerOptions } from '@atlaskit/editor-common/types';
9
7
  import { FeatureFlags } from '@atlaskit/editor-common/types';
10
8
  import type { ForceFocusSelector } from '@atlaskit/editor-plugin-floating-toolbar';
9
+ import { Node } from '@atlaskit/editor-prosemirror/model';
10
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
11
11
  import type { cardPlugin } from '../plugin';
12
12
  interface InjectionAPI {
13
13
  pluginInjectionApi: ExtractInjectionAPI<typeof cardPlugin> | undefined;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { EditorView } from '@atlaskit/editor-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;
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { EditorView } from 'prosemirror-view';
2
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
3
3
  export declare const EditorSmartCardEvents: FC<{
4
4
  editorView: EditorView;
5
5
  }>;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { EditorView } from 'prosemirror-view';
3
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  type AnalyticsBindingsProps = {
5
5
  editorView: EditorView;
6
6
  };
@@ -1,11 +1,11 @@
1
1
  import { Component } from 'react';
2
- import { EditorState } from 'prosemirror-state';
3
- import { EditorView } from 'prosemirror-view';
4
2
  import { IntlShape } from 'react-intl-next';
5
3
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
4
  import { CardOptions } from '@atlaskit/editor-common/card';
7
5
  import type { CardPluginActions } from '@atlaskit/editor-common/card';
8
6
  import { CardProvider, ProviderFactory } from '@atlaskit/editor-common/provider-factory';
7
+ import { EditorState } from '@atlaskit/editor-prosemirror/state';
8
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
9
9
  import { CardPlatform } from '@atlaskit/smart-card';
10
10
  export interface HyperlinkToolbarAppearanceProps {
11
11
  intl: IntlShape;
@@ -1,6 +1,6 @@
1
- import { EditorView } from 'prosemirror-view';
2
1
  import { IntlShape } from 'react-intl-next';
3
2
  import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { cardPlugin } from '../../index';
5
5
  export type DatasourceTableLayout = 'full-width' | 'center' | 'wide';
6
6
  export type LayoutButtonProps = {
@@ -1,4 +1,4 @@
1
- import { EditorView } from 'prosemirror-view';
1
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
2
2
  export declare const getDatasource: (editorView: EditorView) => import("prosemirror-utils").ContentNodeWithPos | {
3
3
  node: undefined;
4
4
  pos: undefined;