@atlaskit/editor-plugin-card 0.14.17 → 0.14.19

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 (31) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/nodeviews/inlineCard.js +16 -18
  3. package/dist/cjs/nodeviews/inlineCardWithAwareness.js +38 -81
  4. package/dist/cjs/pm-plugins/main.js +4 -3
  5. package/dist/cjs/ui/AwarenessWrapper/index.js +107 -0
  6. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/common.js +6 -1
  7. package/dist/cjs/ui/LinkToolbarAppearance.js +2 -2
  8. package/dist/cjs/{common/pulse → ui/Pulse}/index.js +1 -1
  9. package/dist/es2019/nodeviews/inlineCard.js +17 -19
  10. package/dist/es2019/nodeviews/inlineCardWithAwareness.js +35 -75
  11. package/dist/es2019/pm-plugins/main.js +4 -3
  12. package/dist/es2019/ui/AwarenessWrapper/index.js +91 -0
  13. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/common.js +6 -1
  14. package/dist/es2019/ui/LinkToolbarAppearance.js +1 -1
  15. package/dist/es2019/{common/pulse → ui/Pulse}/index.js +1 -1
  16. package/dist/esm/nodeviews/inlineCard.js +16 -18
  17. package/dist/esm/nodeviews/inlineCardWithAwareness.js +35 -80
  18. package/dist/esm/pm-plugins/main.js +4 -3
  19. package/dist/esm/ui/AwarenessWrapper/index.js +99 -0
  20. package/dist/esm/ui/EditorLinkingPlatformAnalytics/common.js +6 -1
  21. package/dist/esm/ui/LinkToolbarAppearance.js +1 -1
  22. package/dist/esm/{common/pulse → ui/Pulse}/index.js +1 -1
  23. package/dist/types/nodeviews/inlineCardWithAwareness.d.ts +2 -3
  24. package/dist/types/ui/AwarenessWrapper/index.d.ts +13 -0
  25. package/dist/types/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +1 -1
  26. package/dist/types-ts4.5/nodeviews/inlineCardWithAwareness.d.ts +2 -3
  27. package/dist/types-ts4.5/ui/AwarenessWrapper/index.d.ts +13 -0
  28. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +1 -1
  29. package/package.json +3 -3
  30. /package/dist/types/{common/pulse → ui/Pulse}/index.d.ts +0 -0
  31. /package/dist/types-ts4.5/{common/pulse → ui/Pulse}/index.d.ts +0 -0
@@ -1,24 +1,9 @@
1
- /** @jsx jsx */
2
- import { memo, useCallback, useMemo, useState } from 'react';
3
- import { css, jsx } from '@emotion/react';
1
+ import React, { memo, useCallback, useMemo, useState } from 'react';
4
2
  import rafSchedule from 'raf-schd';
5
- import { AnalyticsContext } from '@atlaskit/analytics-next';
6
3
  import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
7
4
  import { Card as SmartCard } from '@atlaskit/smart-card';
8
- import useLinkUpgradeDiscoverability from '../common/hooks/useLinkUpgradeDiscoverability';
9
- import { isLocalStorageKeyDiscovered, LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK, LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR, markLocalStorageKeyDiscovered, ONE_DAY_IN_MILLISECONDS } from '../common/local-storage';
10
- import { DiscoveryPulse } from '../common/pulse';
11
5
  import { registerCard, registerRemoveOverlay } from '../pm-plugins/actions';
12
- import InlineCardOverlay from '../ui/InlineCardOverlay';
13
- import { getResolvedAttributesFromStore } from '../utils';
14
- // editor adds a standard line-height that is bigger than an inline smart link
15
- // due to that the link has a bit of white space around it, which doesn't look right when there is pulse around it
16
- const loaderWrapperStyles = css({
17
- // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
18
- '.loader-wrapper': {
19
- lineHeight: 'normal'
20
- }
21
- });
6
+ import { AwarenessWrapper } from '../ui/AwarenessWrapper';
22
7
  const InlineCard = ({
23
8
  node,
24
9
  cardContext,
@@ -31,44 +16,13 @@ const InlineCard = ({
31
16
  pluginInjectionApi,
32
17
  isSelected = false
33
18
  }) => {
34
- var _cardContext$value2;
35
19
  const {
36
20
  url,
37
21
  data
38
22
  } = node.attrs;
39
-
40
- // BEGIN: Awareness (To be revisited in EDM-8508)
41
23
  const [isHovered, setIsHovered] = useState(false);
42
24
  const [isInserted, setIsInserted] = useState(false);
43
25
  const [isResolvedViewRendered, setIsResolvedViewRendered] = useState(false);
44
- const linkPosition = useMemo(() => {
45
- if (!getPos || typeof getPos === 'boolean') {
46
- return undefined;
47
- }
48
- const pos = getPos();
49
- return typeof pos === 'number' ? pos : undefined;
50
- }, [getPos]);
51
- const {
52
- shouldShowLinkPulse,
53
- shouldShowToolbarPulse,
54
- shouldShowLinkOverlay,
55
- isLinkMostRecentlyInserted
56
- } = useLinkUpgradeDiscoverability({
57
- url,
58
- linkPosition: linkPosition || -1,
59
- cardContext: cardContext === null || cardContext === void 0 ? void 0 : cardContext.value,
60
- pluginInjectionApi,
61
- isOverlayEnabled,
62
- isPulseEnabled
63
- });
64
-
65
- // If the toolbar pulse has not yet been invalidated and this is a case where we will be showing it,
66
- // we need to invalidate the link pulse too. Toolbar pulse will be invalidated in the corresponding component.
67
- if (isSelected && shouldShowToolbarPulse && !isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR)) {
68
- markLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
69
- }
70
- // END: Awareness
71
-
72
26
  const scrollContainer = useMemo(() => findOverflowScrollParent(view.dom) || undefined, [view.dom]);
73
27
  const onResolve = useCallback(data => {
74
28
  if (!getPos || typeof getPos === 'boolean') {
@@ -98,8 +52,7 @@ const InlineCard = ({
98
52
  if (title) {
99
53
  setIsResolvedViewRendered(true);
100
54
  }
101
- setIsInserted(isLinkMostRecentlyInserted);
102
- }, [view, getPos, isLinkMostRecentlyInserted]);
55
+ }, [view, getPos]);
103
56
  const onError = useCallback(data => {
104
57
  const {
105
58
  url,
@@ -112,7 +65,21 @@ const InlineCard = ({
112
65
  url
113
66
  });
114
67
  }, [onResolve]);
115
- const innerCard = useMemo(() => jsx(SmartCard, {
68
+
69
+ // Begin Upgrade Awareness related code
70
+ const markMostRecentlyInsertedLink = useCallback(isLinkMostRecentlyInserted => {
71
+ if (isOverlayEnabled) {
72
+ setIsInserted(isLinkMostRecentlyInserted);
73
+ }
74
+ }, [isOverlayEnabled]);
75
+ const setOverlayHoveredStyles = useCallback(isHovered => {
76
+ if (isOverlayEnabled) {
77
+ setIsHovered(isHovered);
78
+ }
79
+ }, [isOverlayEnabled]);
80
+ // End Upgrade Awareness related code
81
+
82
+ const innerCard = useMemo(() => /*#__PURE__*/React.createElement(SmartCard, {
116
83
  key: url,
117
84
  url: url,
118
85
  data: data,
@@ -125,35 +92,28 @@ const InlineCard = ({
125
92
  showServerActions: showServerActions,
126
93
  isHovered: isHovered
127
94
  }), [data, isHovered, onError, onResolve, scrollContainer, showServerActions, url, useAlternativePreloader]);
128
-
129
- // BEGIN: Awareness (To be revisited in EDM-8508)
130
- const cardWithOverlay = useMemo(() => shouldShowLinkOverlay ? jsx(InlineCardOverlay, {
131
- isSelected: isSelected,
132
- isVisible: isResolvedViewRendered && (isInserted || isHovered || isSelected),
133
- onMouseEnter: () => setIsHovered(true),
134
- onMouseLeave: () => setIsHovered(false),
135
- url: url
136
- }, innerCard) : innerCard, [innerCard, isHovered, isResolvedViewRendered, isSelected, isInserted, shouldShowLinkOverlay, url]);
137
95
  const card = useMemo(() => {
138
- var _cardContext$value;
139
- return jsx("span", {
140
- css: shouldShowLinkPulse && loaderWrapperStyles,
96
+ return isOverlayEnabled || isPulseEnabled ? /*#__PURE__*/React.createElement(AwarenessWrapper, {
97
+ isOverlayEnabled: isOverlayEnabled,
98
+ isPulseEnabled: isPulseEnabled,
99
+ cardContext: cardContext,
100
+ getPos: getPos,
101
+ isHovered: isHovered,
102
+ isInserted: isInserted,
103
+ url: url,
104
+ isSelected: isSelected,
105
+ isResolvedViewRendered: isResolvedViewRendered,
106
+ markMostRecentlyInsertedLink: markMostRecentlyInsertedLink,
107
+ pluginInjectionApi: pluginInjectionApi,
108
+ setOverlayHoveredStyles: setOverlayHoveredStyles
109
+ }, innerCard) : /*#__PURE__*/React.createElement("span", {
141
110
  className: "card"
142
- }, shouldShowLinkPulse ? jsx(AnalyticsContext, {
143
- data: {
144
- attributes: getResolvedAttributesFromStore(url, 'inline', cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store)
145
- }
146
- }, jsx(DiscoveryPulse, {
147
- localStorageKey: LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK,
148
- localStorageKeyExpirationInMs: ONE_DAY_IN_MILLISECONDS,
149
- discoveryMode: "start"
150
- }, cardWithOverlay)) : cardWithOverlay);
151
- }, [shouldShowLinkPulse, cardWithOverlay, url, cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value2 = cardContext.value) === null || _cardContext$value2 === void 0 ? void 0 : _cardContext$value2.store]);
152
- // END: Awareness
111
+ }, innerCard);
112
+ }, [cardContext, getPos, innerCard, isHovered, isInserted, isOverlayEnabled, isPulseEnabled, isResolvedViewRendered, isSelected, markMostRecentlyInsertedLink, pluginInjectionApi, setOverlayHoveredStyles, url]);
153
113
 
154
114
  // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
155
115
  // otherwise if we got data, we can render the card directly since it doesn't need the Provider
156
- return cardContext && cardContext.value ? jsx(cardContext.Provider, {
116
+ return cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
157
117
  value: cardContext.value
158
118
  }, card) : data ? card : null;
159
119
  };
@@ -45,6 +45,7 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
45
45
  allowBlockCards
46
46
  } = options;
47
47
  const enableInlineUpgradeFeatures = !!showUpgradeDiscoverability && platform !== 'mobile';
48
+ const shouldUseUpgradeFeatures = getBooleanFF('platform.linking-platform.smart-card.inline-switcher') && enableInlineUpgradeFeatures;
48
49
  const inlineCardViewProducer = getInlineNodeViewProducer({
49
50
  pmPluginFactoryParams,
50
51
  Component: InlineCardNodeView,
@@ -88,7 +89,7 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
88
89
  if (!meta) {
89
90
  return pluginStateWithUpdatedPos;
90
91
  }
91
- if (!getBooleanFF('platform.linking-platform.smart-card.inline-switcher')) {
92
+ if (!shouldUseUpgradeFeatures) {
92
93
  return reducer(pluginStateWithUpdatedPos, meta);
93
94
  }
94
95
  const newState = reducer(pluginStateWithUpdatedPos, meta);
@@ -96,7 +97,7 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
96
97
  // the code below is related to the "Inline Switcher" project, for more information pls see EDM-7984
97
98
  const isSingleInlineLink = (pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$requests = pluginState.requests) === null || _pluginState$requests === void 0 ? void 0 : _pluginState$requests.length) === 1 && pluginState.requests[0].appearance === 'inline';
98
99
  const isSmartLinkPulseDiscovered = isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
99
- if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures || !isSingleInlineLink) {
100
+ if (meta.type !== 'RESOLVE' || !isSingleInlineLink) {
100
101
  return newState;
101
102
  }
102
103
  const linkPosition = pluginState.requests[0].pos;
@@ -246,7 +247,7 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
246
247
  return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
247
248
  }
248
249
  },
249
- ...(getBooleanFF('platform.linking-platform.smart-card.inline-switcher') && {
250
+ ...(shouldUseUpgradeFeatures && {
250
251
  handleKeyDown: view => {
251
252
  handleAwarenessOverlay(view);
252
253
  return false;
@@ -0,0 +1,91 @@
1
+ /** @jsx jsx */
2
+ import { useCallback, useEffect, useMemo, useState } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
5
+ import useLinkUpgradeDiscoverability from '../../common/hooks/useLinkUpgradeDiscoverability';
6
+ import { isLocalStorageKeyDiscovered, LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK, LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR, markLocalStorageKeyDiscovered, ONE_DAY_IN_MILLISECONDS } from '../../common/local-storage';
7
+ import { getResolvedAttributesFromStore } from '../../utils';
8
+ import InlineCardOverlay from '../InlineCardOverlay';
9
+ import { DiscoveryPulse } from '../Pulse';
10
+ // editor adds a standard line-height that is bigger than an inline smart link
11
+ // due to that the link has a bit of white space around it, which doesn't look right when there is pulse around it
12
+ const loaderWrapperStyles = css({
13
+ // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
14
+ '.loader-wrapper': {
15
+ lineHeight: 'normal'
16
+ }
17
+ });
18
+ export const AwarenessWrapper = ({
19
+ cardContext,
20
+ children,
21
+ getPos,
22
+ isInserted,
23
+ isOverlayEnabled,
24
+ isSelected,
25
+ isResolvedViewRendered,
26
+ isPulseEnabled,
27
+ markMostRecentlyInsertedLink,
28
+ pluginInjectionApi,
29
+ setOverlayHoveredStyles,
30
+ url
31
+ }) => {
32
+ var _cardContext$value2;
33
+ const [isHovered, setIsHovered] = useState(false);
34
+ const linkPosition = useMemo(() => {
35
+ if (!getPos || typeof getPos === 'boolean') {
36
+ return undefined;
37
+ }
38
+ const pos = getPos();
39
+ return typeof pos === 'number' ? pos : undefined;
40
+ }, [getPos]);
41
+ const {
42
+ shouldShowLinkPulse,
43
+ shouldShowToolbarPulse,
44
+ shouldShowLinkOverlay,
45
+ isLinkMostRecentlyInserted
46
+ } = useLinkUpgradeDiscoverability({
47
+ url,
48
+ linkPosition: linkPosition || -1,
49
+ cardContext: cardContext === null || cardContext === void 0 ? void 0 : cardContext.value,
50
+ pluginInjectionApi,
51
+ isOverlayEnabled,
52
+ isPulseEnabled
53
+ });
54
+
55
+ // If the toolbar pulse has not yet been invalidated and this is a case where we will be showing it,
56
+ // we need to invalidate the link pulse too. Toolbar pulse will be invalidated in the corresponding component.
57
+ if (isSelected && shouldShowToolbarPulse && !isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR)) {
58
+ markLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
59
+ }
60
+ useEffect(() => {
61
+ if (shouldShowLinkOverlay && isLinkMostRecentlyInserted) {
62
+ markMostRecentlyInsertedLink(true);
63
+ }
64
+ }, [isLinkMostRecentlyInserted, markMostRecentlyInsertedLink, shouldShowLinkOverlay]);
65
+ const handleOverlayChange = useCallback(isHovered => {
66
+ setIsHovered(isHovered);
67
+ setOverlayHoveredStyles(isHovered);
68
+ }, [setOverlayHoveredStyles]);
69
+ const cardWithOverlay = useMemo(() => shouldShowLinkOverlay ? jsx(InlineCardOverlay, {
70
+ isSelected: isSelected,
71
+ isVisible: isResolvedViewRendered && (isInserted || isHovered || isSelected),
72
+ onMouseEnter: () => handleOverlayChange(true),
73
+ onMouseLeave: () => handleOverlayChange(false),
74
+ url: url
75
+ }, children) : children, [shouldShowLinkOverlay, isSelected, isResolvedViewRendered, isInserted, isHovered, url, children, handleOverlayChange]);
76
+ return useMemo(() => {
77
+ var _cardContext$value;
78
+ return jsx("span", {
79
+ css: shouldShowLinkPulse && loaderWrapperStyles,
80
+ className: "card"
81
+ }, shouldShowLinkPulse ? jsx(AnalyticsContext, {
82
+ data: {
83
+ attributes: getResolvedAttributesFromStore(url, 'inline', cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store)
84
+ }
85
+ }, jsx(DiscoveryPulse, {
86
+ localStorageKey: LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK,
87
+ localStorageKeyExpirationInMs: ONE_DAY_IN_MILLISECONDS,
88
+ discoveryMode: "start"
89
+ }, cardWithOverlay)) : cardWithOverlay);
90
+ }, [shouldShowLinkPulse, url, cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value2 = cardContext.value) === null || _cardContext$value2 === void 0 ? void 0 : _cardContext$value2.store, cardWithOverlay]);
91
+ };
@@ -21,8 +21,11 @@ const withHistoryMethod = fn => {
21
21
  };
22
22
  };
23
23
  export const getMethod = withHistoryMethod(({
24
- inputMethod
24
+ inputMethod,
25
+ sourceEvent
25
26
  }) => {
27
+ var _inputMethod, _payload, _payload$attributes;
28
+ inputMethod = (_inputMethod = inputMethod) !== null && _inputMethod !== void 0 ? _inputMethod : sourceEvent === null || sourceEvent === void 0 ? void 0 : (_payload = sourceEvent.payload) === null || _payload === void 0 ? void 0 : (_payload$attributes = _payload.attributes) === null || _payload$attributes === void 0 ? void 0 : _payload$attributes.inputMethod;
26
29
  switch (inputMethod) {
27
30
  case INPUT_METHOD.CLIPBOARD:
28
31
  return 'editor_paste';
@@ -35,6 +38,8 @@ export const getMethod = withHistoryMethod(({
35
38
  return 'linkpicker_searchResult';
36
39
  case INPUT_METHOD.MANUAL:
37
40
  return 'linkpicker_manual';
41
+ case INPUT_METHOD.DATASOURCE:
42
+ return 'datasource_config';
38
43
  default:
39
44
  return 'unknown';
40
45
  }
@@ -8,9 +8,9 @@ import nodeNames, { cardMessages as messages } from '@atlaskit/editor-common/mes
8
8
  import { isSupportedInParent } from '@atlaskit/editor-common/utils';
9
9
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
10
10
  import { LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR } from '../common/local-storage';
11
- import { DiscoveryPulse } from '../common/pulse';
12
11
  import { shouldRenderToolbarPulse } from '../toolbar';
13
12
  import { getResolvedAttributesFromStore } from '../utils';
13
+ import { DiscoveryPulse } from './Pulse';
14
14
  // eslint-disable-next-line @repo/internal/react/no-class-components
15
15
  export class LinkToolbarAppearance extends React.Component {
16
16
  constructor(...args) {
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback, useEffect } from 'react';
2
2
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
3
  import { Pulse } from '@atlaskit/linking-common';
4
- import { isLocalStorageKeyDiscovered, markLocalStorageKeyDiscovered } from '../local-storage';
4
+ import { isLocalStorageKeyDiscovered, markLocalStorageKeyDiscovered } from '../../common/local-storage';
5
5
  export const DiscoveryPulse = ({
6
6
  children,
7
7
  localStorageKey,
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
3
  import _createClass from "@babel/runtime/helpers/createClass";
3
4
  import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
@@ -116,7 +117,6 @@ _defineProperty(InlineCardComponent, "contextTypes", {
116
117
  var WrappedInlineCard = Card(InlineCardComponent, UnsupportedInline);
117
118
  var WrappedInlineCardWithAwareness = Card(InlineCardWithAwareness, UnsupportedInline);
118
119
  export function InlineCardNodeView(props) {
119
- var _view$state$selection, _view$state$selection2;
120
120
  var useAlternativePreloader = props.useAlternativePreloader,
121
121
  node = props.node,
122
122
  view = props.view,
@@ -135,26 +135,24 @@ export function InlineCardNodeView(props) {
135
135
  useAlternativePreloader: useAlternativePreloader
136
136
  });
137
137
  }
138
-
139
- // BEGIN: Awareness (To be revisited in EDM-8508)
140
- var editorState = view.state;
141
- var linkPosition = getPos && typeof getPos() === 'number' ? getPos() : undefined;
142
- var canBeUpgradedToEmbed = !!linkPosition && allowEmbeds ? isEmbedSupportedAtPosition(linkPosition, editorState, 'inline') : false;
143
- var canBeUpgradedToBlock = !!linkPosition && allowBlockCards ? isBlockSupportedAtPosition(linkPosition, editorState, 'inline') : false;
144
- var isPulseEnabled = enableInlineUpgradeFeatures && canBeUpgradedToEmbed;
145
- var isOverlayEnabled = enableInlineUpgradeFeatures && (canBeUpgradedToEmbed || canBeUpgradedToBlock);
146
- var isSelected = view.state.selection instanceof NodeSelection && ((_view$state$selection = view.state.selection) === null || _view$state$selection === void 0 || (_view$state$selection = _view$state$selection.node) === null || _view$state$selection === void 0 ? void 0 : _view$state$selection.type) === view.state.schema.nodes.inlineCard && ((_view$state$selection2 = view.state.selection) === null || _view$state$selection2 === void 0 ? void 0 : _view$state$selection2.from) === getPos();
147
- // END: Awareness
148
-
149
- return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, {
138
+ return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, _extends({
150
139
  node: node,
151
140
  view: view,
152
141
  getPos: getPos,
153
142
  showServerActions: showServerActions,
154
143
  useAlternativePreloader: useAlternativePreloader,
155
- isOverlayEnabled: isOverlayEnabled,
156
- isPulseEnabled: isPulseEnabled,
157
- pluginInjectionApi: pluginInjectionApi,
144
+ pluginInjectionApi: pluginInjectionApi
145
+ }, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards)));
146
+ }
147
+ var getAwarenessProps = function getAwarenessProps(editorState, getPos, allowEmbeds, allowBlockCards) {
148
+ var _editorState$selectio, _editorState$selectio2;
149
+ var linkPosition = getPos && typeof getPos() === 'number' ? getPos() : undefined;
150
+ var canBeUpgradedToEmbed = !!linkPosition && allowEmbeds ? isEmbedSupportedAtPosition(linkPosition, editorState, 'inline') : false;
151
+ var canBeUpgradedToBlock = !!linkPosition && allowBlockCards ? isBlockSupportedAtPosition(linkPosition, editorState, 'inline') : false;
152
+ var isSelected = editorState.selection instanceof NodeSelection && ((_editorState$selectio = editorState.selection) === null || _editorState$selectio === void 0 || (_editorState$selectio = _editorState$selectio.node) === null || _editorState$selectio === void 0 ? void 0 : _editorState$selectio.type) === editorState.schema.nodes.inlineCard && ((_editorState$selectio2 = editorState.selection) === null || _editorState$selectio2 === void 0 ? void 0 : _editorState$selectio2.from) === getPos();
153
+ return {
154
+ isPulseEnabled: canBeUpgradedToEmbed,
155
+ isOverlayEnabled: canBeUpgradedToEmbed || canBeUpgradedToBlock,
158
156
  isSelected: isSelected
159
- });
160
- }
157
+ };
158
+ };
@@ -1,27 +1,11 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- /** @jsx jsx */
3
- import { memo, useCallback, useMemo, useState } from 'react';
4
- import { css, jsx } from '@emotion/react';
2
+ import React, { memo, useCallback, useMemo, useState } from 'react';
5
3
  import rafSchedule from 'raf-schd';
6
- import { AnalyticsContext } from '@atlaskit/analytics-next';
7
4
  import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
8
5
  import { Card as SmartCard } from '@atlaskit/smart-card';
9
- import useLinkUpgradeDiscoverability from '../common/hooks/useLinkUpgradeDiscoverability';
10
- import { isLocalStorageKeyDiscovered, LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK, LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR, markLocalStorageKeyDiscovered, ONE_DAY_IN_MILLISECONDS } from '../common/local-storage';
11
- import { DiscoveryPulse } from '../common/pulse';
12
6
  import { registerCard, registerRemoveOverlay } from '../pm-plugins/actions';
13
- import InlineCardOverlay from '../ui/InlineCardOverlay';
14
- import { getResolvedAttributesFromStore } from '../utils';
15
- // editor adds a standard line-height that is bigger than an inline smart link
16
- // due to that the link has a bit of white space around it, which doesn't look right when there is pulse around it
17
- var loaderWrapperStyles = css({
18
- // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
19
- '.loader-wrapper': {
20
- lineHeight: 'normal'
21
- }
22
- });
7
+ import { AwarenessWrapper } from '../ui/AwarenessWrapper';
23
8
  var InlineCard = function InlineCard(_ref) {
24
- var _cardContext$value2;
25
9
  var node = _ref.node,
26
10
  cardContext = _ref.cardContext,
27
11
  showServerActions = _ref.showServerActions,
@@ -36,8 +20,6 @@ var InlineCard = function InlineCard(_ref) {
36
20
  var _node$attrs = node.attrs,
37
21
  url = _node$attrs.url,
38
22
  data = _node$attrs.data;
39
-
40
- // BEGIN: Awareness (To be revisited in EDM-8508)
41
23
  var _useState = useState(false),
42
24
  _useState2 = _slicedToArray(_useState, 2),
43
25
  isHovered = _useState2[0],
@@ -50,33 +32,6 @@ var InlineCard = function InlineCard(_ref) {
50
32
  _useState6 = _slicedToArray(_useState5, 2),
51
33
  isResolvedViewRendered = _useState6[0],
52
34
  setIsResolvedViewRendered = _useState6[1];
53
- var linkPosition = useMemo(function () {
54
- if (!getPos || typeof getPos === 'boolean') {
55
- return undefined;
56
- }
57
- var pos = getPos();
58
- return typeof pos === 'number' ? pos : undefined;
59
- }, [getPos]);
60
- var _useLinkUpgradeDiscov = useLinkUpgradeDiscoverability({
61
- url: url,
62
- linkPosition: linkPosition || -1,
63
- cardContext: cardContext === null || cardContext === void 0 ? void 0 : cardContext.value,
64
- pluginInjectionApi: pluginInjectionApi,
65
- isOverlayEnabled: isOverlayEnabled,
66
- isPulseEnabled: isPulseEnabled
67
- }),
68
- shouldShowLinkPulse = _useLinkUpgradeDiscov.shouldShowLinkPulse,
69
- shouldShowToolbarPulse = _useLinkUpgradeDiscov.shouldShowToolbarPulse,
70
- shouldShowLinkOverlay = _useLinkUpgradeDiscov.shouldShowLinkOverlay,
71
- isLinkMostRecentlyInserted = _useLinkUpgradeDiscov.isLinkMostRecentlyInserted;
72
-
73
- // If the toolbar pulse has not yet been invalidated and this is a case where we will be showing it,
74
- // we need to invalidate the link pulse too. Toolbar pulse will be invalidated in the corresponding component.
75
- if (isSelected && shouldShowToolbarPulse && !isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR)) {
76
- markLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
77
- }
78
- // END: Awareness
79
-
80
35
  var scrollContainer = useMemo(function () {
81
36
  return findOverflowScrollParent(view.dom) || undefined;
82
37
  }, [view.dom]);
@@ -108,8 +63,7 @@ var InlineCard = function InlineCard(_ref) {
108
63
  if (title) {
109
64
  setIsResolvedViewRendered(true);
110
65
  }
111
- setIsInserted(isLinkMostRecentlyInserted);
112
- }, [view, getPos, isLinkMostRecentlyInserted]);
66
+ }, [view, getPos]);
113
67
  var onError = useCallback(function (data) {
114
68
  var url = data.url,
115
69
  err = data.err;
@@ -120,8 +74,22 @@ var InlineCard = function InlineCard(_ref) {
120
74
  url: url
121
75
  });
122
76
  }, [onResolve]);
77
+
78
+ // Begin Upgrade Awareness related code
79
+ var markMostRecentlyInsertedLink = useCallback(function (isLinkMostRecentlyInserted) {
80
+ if (isOverlayEnabled) {
81
+ setIsInserted(isLinkMostRecentlyInserted);
82
+ }
83
+ }, [isOverlayEnabled]);
84
+ var setOverlayHoveredStyles = useCallback(function (isHovered) {
85
+ if (isOverlayEnabled) {
86
+ setIsHovered(isHovered);
87
+ }
88
+ }, [isOverlayEnabled]);
89
+ // End Upgrade Awareness related code
90
+
123
91
  var innerCard = useMemo(function () {
124
- return jsx(SmartCard, {
92
+ return /*#__PURE__*/React.createElement(SmartCard, {
125
93
  key: url,
126
94
  url: url,
127
95
  data: data,
@@ -135,41 +103,28 @@ var InlineCard = function InlineCard(_ref) {
135
103
  isHovered: isHovered
136
104
  });
137
105
  }, [data, isHovered, onError, onResolve, scrollContainer, showServerActions, url, useAlternativePreloader]);
138
-
139
- // BEGIN: Awareness (To be revisited in EDM-8508)
140
- var cardWithOverlay = useMemo(function () {
141
- return shouldShowLinkOverlay ? jsx(InlineCardOverlay, {
142
- isSelected: isSelected,
143
- isVisible: isResolvedViewRendered && (isInserted || isHovered || isSelected),
144
- onMouseEnter: function onMouseEnter() {
145
- return setIsHovered(true);
146
- },
147
- onMouseLeave: function onMouseLeave() {
148
- return setIsHovered(false);
149
- },
150
- url: url
151
- }, innerCard) : innerCard;
152
- }, [innerCard, isHovered, isResolvedViewRendered, isSelected, isInserted, shouldShowLinkOverlay, url]);
153
106
  var card = useMemo(function () {
154
- var _cardContext$value;
155
- return jsx("span", {
156
- css: shouldShowLinkPulse && loaderWrapperStyles,
107
+ return isOverlayEnabled || isPulseEnabled ? /*#__PURE__*/React.createElement(AwarenessWrapper, {
108
+ isOverlayEnabled: isOverlayEnabled,
109
+ isPulseEnabled: isPulseEnabled,
110
+ cardContext: cardContext,
111
+ getPos: getPos,
112
+ isHovered: isHovered,
113
+ isInserted: isInserted,
114
+ url: url,
115
+ isSelected: isSelected,
116
+ isResolvedViewRendered: isResolvedViewRendered,
117
+ markMostRecentlyInsertedLink: markMostRecentlyInsertedLink,
118
+ pluginInjectionApi: pluginInjectionApi,
119
+ setOverlayHoveredStyles: setOverlayHoveredStyles
120
+ }, innerCard) : /*#__PURE__*/React.createElement("span", {
157
121
  className: "card"
158
- }, shouldShowLinkPulse ? jsx(AnalyticsContext, {
159
- data: {
160
- attributes: getResolvedAttributesFromStore(url, 'inline', cardContext === null || cardContext === void 0 || (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store)
161
- }
162
- }, jsx(DiscoveryPulse, {
163
- localStorageKey: LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK,
164
- localStorageKeyExpirationInMs: ONE_DAY_IN_MILLISECONDS,
165
- discoveryMode: "start"
166
- }, cardWithOverlay)) : cardWithOverlay);
167
- }, [shouldShowLinkPulse, cardWithOverlay, url, cardContext === null || cardContext === void 0 || (_cardContext$value2 = cardContext.value) === null || _cardContext$value2 === void 0 ? void 0 : _cardContext$value2.store]);
168
- // END: Awareness
122
+ }, innerCard);
123
+ }, [cardContext, getPos, innerCard, isHovered, isInserted, isOverlayEnabled, isPulseEnabled, isResolvedViewRendered, isSelected, markMostRecentlyInsertedLink, pluginInjectionApi, setOverlayHoveredStyles, url]);
169
124
 
170
125
  // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
171
126
  // otherwise if we got data, we can render the card directly since it doesn't need the Provider
172
- return cardContext && cardContext.value ? jsx(cardContext.Provider, {
127
+ return cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
173
128
  value: cardContext.value
174
129
  }, card) : data ? card : null;
175
130
  };
@@ -48,6 +48,7 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
48
48
  allowEmbeds = options.allowEmbeds,
49
49
  allowBlockCards = options.allowBlockCards;
50
50
  var enableInlineUpgradeFeatures = !!showUpgradeDiscoverability && platform !== 'mobile';
51
+ var shouldUseUpgradeFeatures = getBooleanFF('platform.linking-platform.smart-card.inline-switcher') && enableInlineUpgradeFeatures;
51
52
  var inlineCardViewProducer = getInlineNodeViewProducer({
52
53
  pmPluginFactoryParams: pmPluginFactoryParams,
53
54
  Component: InlineCardNodeView,
@@ -91,7 +92,7 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
91
92
  if (!meta) {
92
93
  return pluginStateWithUpdatedPos;
93
94
  }
94
- if (!getBooleanFF('platform.linking-platform.smart-card.inline-switcher')) {
95
+ if (!shouldUseUpgradeFeatures) {
95
96
  return reducer(pluginStateWithUpdatedPos, meta);
96
97
  }
97
98
  var newState = reducer(pluginStateWithUpdatedPos, meta);
@@ -99,7 +100,7 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
99
100
  // the code below is related to the "Inline Switcher" project, for more information pls see EDM-7984
100
101
  var isSingleInlineLink = (pluginState === null || pluginState === void 0 || (_pluginState$requests = pluginState.requests) === null || _pluginState$requests === void 0 ? void 0 : _pluginState$requests.length) === 1 && pluginState.requests[0].appearance === 'inline';
101
102
  var isSmartLinkPulseDiscovered = isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
102
- if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures || !isSingleInlineLink) {
103
+ if (meta.type !== 'RESOLVE' || !isSingleInlineLink) {
103
104
  return newState;
104
105
  }
105
106
  var linkPosition = pluginState.requests[0].pos;
@@ -241,7 +242,7 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
241
242
  return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
242
243
  }
243
244
  }
244
- }, getBooleanFF('platform.linking-platform.smart-card.inline-switcher') && {
245
+ }, shouldUseUpgradeFeatures && {
245
246
  handleKeyDown: function handleKeyDown(view) {
246
247
  handleAwarenessOverlay(view);
247
248
  return false;