@atlaskit/editor-plugin-card 7.1.0 → 7.2.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/nodeviews/genericCard.js +2 -19
  3. package/dist/cjs/nodeviews/inlineCard.js +1 -45
  4. package/dist/cjs/nodeviews/inlineCardWithAwareness.js +34 -18
  5. package/dist/cjs/pm-plugins/main.js +4 -24
  6. package/dist/cjs/ui/{OpenButtonOverlay → HoverLinkOverlay}/index.js +26 -14
  7. package/dist/es2019/nodeviews/genericCard.js +2 -19
  8. package/dist/es2019/nodeviews/inlineCard.js +2 -42
  9. package/dist/es2019/nodeviews/inlineCardWithAwareness.js +34 -18
  10. package/dist/es2019/pm-plugins/main.js +1 -23
  11. package/dist/es2019/ui/{OpenButtonOverlay → HoverLinkOverlay}/index.js +25 -14
  12. package/dist/esm/nodeviews/genericCard.js +2 -19
  13. package/dist/esm/nodeviews/inlineCard.js +2 -46
  14. package/dist/esm/nodeviews/inlineCardWithAwareness.js +34 -18
  15. package/dist/esm/pm-plugins/main.js +3 -23
  16. package/dist/esm/ui/{OpenButtonOverlay → HoverLinkOverlay}/index.js +26 -14
  17. package/dist/types/nodeviews/inlineCard.d.ts +1 -1
  18. package/dist/types/pm-plugins/main.d.ts +0 -2
  19. package/dist/types/ui/HoverLinkOverlay/index.d.ts +9 -0
  20. package/dist/types/ui/{OpenButtonOverlay → HoverLinkOverlay}/types.d.ts +3 -1
  21. package/dist/types/ui/datasourceErrorBoundary.d.ts +1 -1
  22. package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +1 -1
  23. package/dist/types-ts4.5/pm-plugins/main.d.ts +0 -2
  24. package/dist/types-ts4.5/ui/HoverLinkOverlay/index.d.ts +9 -0
  25. package/dist/types-ts4.5/ui/{OpenButtonOverlay → HoverLinkOverlay}/types.d.ts +3 -1
  26. package/dist/types-ts4.5/ui/datasourceErrorBoundary.d.ts +1 -1
  27. package/package.json +5 -8
  28. package/dist/cjs/ui/PanelButtonOverlay/index.js +0 -171
  29. package/dist/cjs/ui/PanelButtonOverlay/types.js +0 -5
  30. package/dist/es2019/ui/PanelButtonOverlay/index.js +0 -148
  31. package/dist/esm/ui/OpenButtonOverlay/types.js +0 -1
  32. package/dist/esm/ui/PanelButtonOverlay/index.js +0 -158
  33. package/dist/esm/ui/PanelButtonOverlay/types.js +0 -1
  34. package/dist/types/ui/OpenButtonOverlay/index.d.ts +0 -9
  35. package/dist/types/ui/PanelButtonOverlay/index.d.ts +0 -9
  36. package/dist/types/ui/PanelButtonOverlay/types.d.ts +0 -7
  37. package/dist/types-ts4.5/ui/OpenButtonOverlay/index.d.ts +0 -9
  38. package/dist/types-ts4.5/ui/PanelButtonOverlay/index.d.ts +0 -9
  39. package/dist/types-ts4.5/ui/PanelButtonOverlay/types.d.ts +0 -7
  40. /package/dist/cjs/ui/{OpenButtonOverlay → HoverLinkOverlay}/types.js +0 -0
  41. /package/dist/es2019/ui/{OpenButtonOverlay → HoverLinkOverlay}/types.js +0 -0
  42. /package/dist/{es2019/ui/PanelButtonOverlay → esm/ui/HoverLinkOverlay}/types.js +0 -0
@@ -1,28 +1,31 @@
1
1
  import React, { memo, useCallback, useMemo, useState } from 'react';
2
2
  import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
4
  import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { getObjectAri, getObjectName, getObjectIconUrl } from '@atlaskit/smart-card';
5
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
7
  import { registerRemoveOverlay } from '../pm-plugins/actions';
7
8
  import { pluginKey } from '../pm-plugins/plugin-key';
8
9
  import { AwarenessWrapper } from '../ui/AwarenessWrapper';
9
- import OpenButtonOverlay from '../ui/OpenButtonOverlay';
10
- import PanelButtonOverlay from '../ui/PanelButtonOverlay';
10
+ import HoverLinkOverlay from '../ui/HoverLinkOverlay';
11
11
  import { InlineCard } from './inlineCard';
12
12
  const selector = states => {
13
- var _states$editorViewMod;
13
+ var _states$editorViewMod, _states$selectionStat;
14
14
  return {
15
- mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
15
+ mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode,
16
+ selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection
16
17
  };
17
18
  };
18
19
  const useSharedState = sharedPluginStateHookMigratorFactory(pluginInjectionApi => {
19
- return useSharedPluginStateWithSelector(pluginInjectionApi, ['editorViewMode'], selector);
20
+ return useSharedPluginStateWithSelector(pluginInjectionApi, ['selection', 'editorViewMode'], selector);
20
21
  }, pluginInjectionApi => {
21
22
  const {
23
+ selectionState,
22
24
  editorViewModeState
23
- } = useSharedPluginState(pluginInjectionApi, ['editorViewMode']);
25
+ } = useSharedPluginState(pluginInjectionApi, ['selection', 'editorViewMode']);
24
26
  return {
25
- mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode
27
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
28
+ selection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection
26
29
  };
27
30
  });
28
31
  export const InlineCardWithAwareness = /*#__PURE__*/memo(({
@@ -67,11 +70,14 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
67
70
  }
68
71
  }, [isOverlayEnabled]);
69
72
  const {
70
- mode
73
+ mode,
74
+ selection
71
75
  } = useSharedState(pluginInjectionApi);
76
+ const floatingToolbarNode = selection instanceof NodeSelection && selection.node;
77
+ const showHoverPreview = floatingToolbarNode !== node && fg('platform_editor_preview_panel_linking');
72
78
  const innerCardWithOpenButtonOverlay = useMemo(() => {
73
79
  var _pluginInjectionApi$a;
74
- return /*#__PURE__*/React.createElement(OpenButtonOverlay, {
80
+ return /*#__PURE__*/React.createElement(HoverLinkOverlay, {
75
81
  isVisible: isResolvedViewRendered,
76
82
  url: node.attrs.url,
77
83
  editorAppearance: editorAppearance,
@@ -88,9 +94,10 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
88
94
  cardContext: cardContext,
89
95
  isHovered: isHovered,
90
96
  isPageSSRed: isPageSSRed,
91
- pluginInjectionApi: pluginInjectionApi
97
+ pluginInjectionApi: pluginInjectionApi,
98
+ showHoverPreview: showHoverPreview
92
99
  }));
93
- }, [isResolvedViewRendered, node, editorAppearance, view, getPos, useAlternativePreloader, actionOptions, onResolve, onClick, cardContext, isHovered, isPageSSRed, pluginInjectionApi]);
100
+ }, [isResolvedViewRendered, node, editorAppearance, view, getPos, useAlternativePreloader, actionOptions, onResolve, onClick, cardContext, isHovered, isPageSSRed, pluginInjectionApi, showHoverPreview]);
94
101
  const innerCardOriginal = useMemo(() => /*#__PURE__*/React.createElement(InlineCard, {
95
102
  node: node,
96
103
  view: view,
@@ -102,18 +109,19 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
102
109
  cardContext: cardContext,
103
110
  isHovered: isHovered,
104
111
  isPageSSRed: isPageSSRed,
105
- pluginInjectionApi: pluginInjectionApi
106
- }), [actionOptions, cardContext, getPos, isHovered, node, onClick, onResolve, useAlternativePreloader, view, isPageSSRed, pluginInjectionApi]);
112
+ pluginInjectionApi: pluginInjectionApi,
113
+ showHoverPreview: showHoverPreview
114
+ }), [actionOptions, cardContext, getPos, isHovered, node, onClick, onResolve, useAlternativePreloader, view, isPageSSRed, pluginInjectionApi, showHoverPreview]);
107
115
  const shouldShowOpenButtonOverlay = useMemo(() => {
108
116
  const shouldShowOpenButtonOverlayInChomeless = editorAppearance === 'chromeless';
109
- return (mode === 'edit' || editorAppearance === 'comment' || shouldShowOpenButtonOverlayInChomeless) && editorExperiment('platform_editor_controls', 'variant1');
117
+ return (mode === 'edit' || editorAppearance === 'comment' || shouldShowOpenButtonOverlayInChomeless) && (editorExperiment('platform_editor_controls', 'variant1') || fg('platform_editor_preview_panel_linking'));
110
118
  }, [mode, editorAppearance]);
111
119
  let innerCard = shouldShowOpenButtonOverlay ? innerCardWithOpenButtonOverlay : innerCardOriginal;
112
120
  if (fg('platform_editor_preview_panel_linking')) {
113
121
  var _cardContext$value, _cardContext$value$st;
114
122
  const cardState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : (_cardContext$value$st = _cardContext$value.store) === null || _cardContext$value$st === void 0 ? void 0 : _cardContext$value$st.getState()[node.attrs.url];
115
123
  if (cardState) {
116
- var _cardContext$value2, _cardContext$value2$i, _cardContext$value3;
124
+ var _cardContext$value2, _cardContext$value2$i, _cardContext$value3, _pluginInjectionApi$a2;
117
125
  const ari = getObjectAri(cardState.details);
118
126
  const name = getObjectName(cardState.details);
119
127
  const iconUrl = getObjectIconUrl(cardState.details);
@@ -121,8 +129,11 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
121
129
  ari
122
130
  }));
123
131
  const openPreviewPanel = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value3 = cardContext.value) === null || _cardContext$value3 === void 0 ? void 0 : _cardContext$value3.openPreviewPanel;
124
- const handleOpenGlancePanelClick = () => {
132
+ const handleOpenGlancePanelClick = event => {
125
133
  if (openPreviewPanel && isPanelAvailable) {
134
+ // Prevent anchor default behaviour(click to open the anchor link)
135
+ // When glance panel is available, let openPreviewPanel handle it
136
+ event.preventDefault();
126
137
  openPreviewPanel({
127
138
  url: node.attrs.url,
128
139
  ari,
@@ -131,9 +142,13 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
131
142
  });
132
143
  }
133
144
  };
134
- const innerCardWithPanelButtonOverlay = /*#__PURE__*/React.createElement(PanelButtonOverlay, {
145
+ const innerCardWithPanelButtonOverlay = /*#__PURE__*/React.createElement(HoverLinkOverlay, {
135
146
  isVisible: isResolvedViewRendered,
147
+ url: node.attrs.url,
136
148
  editorAppearance: editorAppearance,
149
+ editorAnalyticsApi: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions,
150
+ view: view,
151
+ showPanelButton: !!isPanelAvailable,
137
152
  onClick: handleOpenGlancePanelClick
138
153
  }, /*#__PURE__*/React.createElement(InlineCard, {
139
154
  node: node,
@@ -146,7 +161,8 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
146
161
  cardContext: cardContext,
147
162
  isHovered: isHovered,
148
163
  isPageSSRed: isPageSSRed,
149
- pluginInjectionApi: pluginInjectionApi
164
+ pluginInjectionApi: pluginInjectionApi,
165
+ showHoverPreview: showHoverPreview
150
166
  }));
151
167
  innerCard = isPanelAvailable && openPreviewPanel ? innerCardWithPanelButtonOverlay : innerCard;
152
168
  }
@@ -5,7 +5,6 @@ import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/st
5
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
6
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
7
7
  import { DATASOURCE_DEFAULT_LAYOUT } from '@atlaskit/linking-common';
8
- import { fg } from '@atlaskit/platform-feature-flags';
9
8
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
10
9
  import { lazyBlockCardView } from '../nodeviews/lazy-block-card';
11
10
  import { lazyEmbedCardView } from '../nodeviews/lazy-embed-card';
@@ -20,19 +19,6 @@ import { handleProvider, resolveWithProvider } from './util/resolve';
20
19
  import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
21
20
  import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from './utils';
22
21
  const LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK = 'smart-link-upgrade-pulse';
23
- export const ALLOW_EVENTS_CLASSNAME = 'card-plugin-element-allow-events';
24
- export const stopEvent = event => {
25
- if (!fg('linking_platform_smart_links_in_live_pages')) {
26
- return false;
27
- }
28
- const target = event.target;
29
- // Stop events from propogating to prose-mirror and selecting the node and/or
30
- // opening the toolbar, unless a parent of the target has a defined className
31
- if (target instanceof HTMLElement && target.closest(`.${ALLOW_EVENTS_CLASSNAME}`)) {
32
- return false;
33
- }
34
- return true;
35
- };
36
22
  const handleAwarenessOverlay = view => {
37
23
  const currentState = getPluginState(view.state);
38
24
  const overlayCandidatePos = currentState === null || currentState === void 0 ? void 0 : currentState.overlayCandidatePosition;
@@ -56,8 +42,6 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
56
42
  allowEmbeds,
57
43
  allowBlockCards,
58
44
  onClickCallback,
59
- // @ts-ignore Temporary solution to check for Live Page editor.
60
- __livePage,
61
45
  isPageSSRed,
62
46
  CompetitorPrompt
63
47
  } = options;
@@ -73,15 +57,9 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
73
57
  allowBlockCards,
74
58
  pluginInjectionApi,
75
59
  onClickCallback,
76
- __livePage,
77
60
  isPageSSRed,
78
61
  CompetitorPrompt
79
- },
80
- ...(__livePage && fg('linking_platform_smart_links_in_live_pages') && {
81
- extraNodeViewProps: {
82
- stopEvent
83
- }
84
- })
62
+ }
85
63
  });
86
64
  return new SafePlugin({
87
65
  state: {
@@ -11,6 +11,7 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
11
11
  import { cardMessages } from '@atlaskit/editor-common/messages';
12
12
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
13
13
  import LinkExternalIcon from '@atlaskit/icon/core/link-external';
14
+ import PanelRightIcon from '@atlaskit/icon/core/panel-right';
14
15
  // eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
15
16
  import { Anchor, Box, Text, xcss } from '@atlaskit/primitives';
16
17
  import { visitCardLinkAnalytics } from '../toolbar';
@@ -57,31 +58,33 @@ const MIN_AVAILABLE_SPACE_WITH_LABEL_OVERLAY = 45;
57
58
  const ICON_WIDTH = 16;
58
59
  const DEFAULT_OPEN_TEXT_WIDTH = 28; // Default open text width in English
59
60
 
60
- const OpenButtonOverlay = ({
61
+ const HoverLinkOverlay = ({
61
62
  children,
62
63
  isVisible = false,
63
64
  url,
64
65
  editorAppearance,
65
66
  editorAnalyticsApi,
66
- view
67
+ view,
68
+ onClick,
69
+ showPanelButton = false
67
70
  }) => {
68
71
  const {
69
72
  formatMessage
70
73
  } = useIntl();
71
- const label = formatMessage(cardMessages.openButtonTitle);
74
+ const label = showPanelButton ? formatMessage(cardMessages.panelButtonTitle) : formatMessage(cardMessages.openButtonTitle);
72
75
  const containerRef = useRef(null);
73
- const openButtonRef = useRef(null);
76
+ const hoverLinkButtonRef = useRef(null);
74
77
  const hiddenTextRef = useRef(null);
75
78
  const [showLabel, setShowLabel] = useState(true);
76
79
  const [isHovered, setHovered] = useState(false);
77
80
  const openTextWidthRef = useRef(null);
78
81
  useLayoutEffect(() => {
79
- var _containerRef$current, _openButtonRef$curren;
82
+ var _containerRef$current, _hoverLinkButtonRef$c;
80
83
  if (!isVisible || !isHovered) {
81
84
  return;
82
85
  }
83
86
  const cardWidth = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.offsetWidth;
84
- const openButtonWidth = (_openButtonRef$curren = openButtonRef.current) === null || _openButtonRef$curren === void 0 ? void 0 : _openButtonRef$curren.offsetWidth;
87
+ const openButtonWidth = (_hoverLinkButtonRef$c = hoverLinkButtonRef.current) === null || _hoverLinkButtonRef$c === void 0 ? void 0 : _hoverLinkButtonRef$c.offsetWidth;
85
88
 
86
89
  // Get the hidden text width
87
90
  if (!openTextWidthRef.current) {
@@ -116,13 +119,19 @@ const OpenButtonOverlay = ({
116
119
  }
117
120
  };
118
121
  const handleDoubleClick = () => {
119
- sendVisitLinkAnalytics(INPUT_METHOD.DOUBLE_CLICK);
122
+ if (!showPanelButton) {
123
+ sendVisitLinkAnalytics(INPUT_METHOD.DOUBLE_CLICK);
120
124
 
121
- // Double click opens the link in a new tab
122
- window.open(url, '_blank');
125
+ // Double click opens the link in a new tab
126
+ window.open(url, '_blank');
127
+ }
123
128
  };
124
- const handleClick = () => {
125
- sendVisitLinkAnalytics(INPUT_METHOD.BUTTON);
129
+ const handleClick = event => {
130
+ if (showPanelButton && onClick) {
131
+ onClick(event);
132
+ } else {
133
+ sendVisitLinkAnalytics(INPUT_METHOD.BUTTON);
134
+ }
126
135
  };
127
136
  return (
128
137
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
@@ -140,7 +149,7 @@ const OpenButtonOverlay = ({
140
149
  size: "small",
141
150
  maxLines: 1
142
151
  }, label)), isHovered && jsx(Anchor, {
143
- ref: openButtonRef,
152
+ ref: hoverLinkButtonRef,
144
153
  xcss: linkStyles,
145
154
  href: url,
146
155
  target: "_blank",
@@ -151,7 +160,9 @@ const OpenButtonOverlay = ({
151
160
  }, jsx(Box, {
152
161
  xcss: iconWrapperStyles,
153
162
  "data-inlinecard-button-overlay": "icon-wrapper-line-height"
154
- }, jsx(LinkExternalIcon, {
163
+ }, showPanelButton ? jsx(PanelRightIcon, {
164
+ label: ""
165
+ }) : jsx(LinkExternalIcon, {
155
166
  label: ""
156
167
  })), showLabel && jsx(Text, {
157
168
  size: "small",
@@ -160,4 +171,4 @@ const OpenButtonOverlay = ({
160
171
  }, label)))
161
172
  );
162
173
  };
163
- export default OpenButtonOverlay;
174
+ export default HoverLinkOverlay;
@@ -37,8 +37,7 @@ var WithClickHandler = function WithClickHandler(_ref) {
37
37
  var pluginInjectionApi = _ref.pluginInjectionApi,
38
38
  url = _ref.url,
39
39
  onClickCallback = _ref.onClickCallback,
40
- children = _ref.children,
41
- __livePage = _ref.__livePage;
40
+ children = _ref.children;
42
41
  var _useSharedState = useSharedState(pluginInjectionApi),
43
42
  mode = _useSharedState.mode;
44
43
  var onClick = useCallback(function (event) {
@@ -51,21 +50,6 @@ var WithClickHandler = function WithClickHandler(_ref) {
51
50
  } catch (_unused) {}
52
51
  }
53
52
  }, [url, onClickCallback]);
54
- if (fg('linking_platform_smart_links_in_live_pages')) {
55
- // Ignored via go/ees007
56
- // eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
57
- /**
58
- * @todo: Add a check to determine if we're currently in a live page once ED-23920 and plugin
59
- * is complete. The logic for which should allow navigation if we're in a live page and no callback
60
- * has been provided. E.g.
61
- *
62
- * const allowNavigation = isLivePage && !onClickCallback;
63
- */
64
- var _allowNavigation = __livePage && !onClickCallback;
65
- return /*#__PURE__*/React.createElement(React.Fragment, null, children({
66
- onClick: _allowNavigation ? undefined : onClick
67
- }));
68
- }
69
53
 
70
54
  // Setting `onClick` to `undefined` ensures clicks on smartcards navigate to the URL.
71
55
  // If in view mode and not overriding with onClickCallback option, then allow smartlinks to navigate on click.
@@ -142,8 +126,7 @@ export function Card(SmartCardComponent, UnsupportedComponent) {
142
126
  }, /*#__PURE__*/React.createElement(WithClickHandler, {
143
127
  pluginInjectionApi: pluginInjectionApi,
144
128
  onClickCallback: onClickCallback,
145
- url: url,
146
- __livePage: this.props.__livePage
129
+ url: url
147
130
  }, function (_ref2) {
148
131
  var onClick = _ref2.onClick;
149
132
  return /*#__PURE__*/React.createElement(WithCardContext, null, function (cardContext) {
@@ -1,20 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
4
3
  import rafSchedule from 'raf-schd';
5
4
  import uuid from 'uuid/v4';
6
5
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
6
  import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
8
- import { handleNavigation } from '@atlaskit/editor-common/link';
9
7
  import { UnsupportedInline, findOverflowScrollParent } from '@atlaskit/editor-common/ui';
10
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
11
8
  import { fg } from '@atlaskit/platform-feature-flags';
12
9
  import { Card as SmartCard } from '@atlaskit/smart-card';
13
10
  import { CardSSR } from '@atlaskit/smart-card/ssr';
14
11
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
15
12
  import { registerCard, removeCard } from '../pm-plugins/actions';
16
13
  import { getAwarenessProps } from '../pm-plugins/utils';
17
- import OverlayWrapper from '../ui/ConfigureOverlay';
18
14
  import { visitCardLinkAnalytics } from '../ui/toolbar';
19
15
  import { Card } from './genericCard';
20
16
  import { InlineCardWithAwareness } from './inlineCardWithAwareness';
@@ -142,7 +138,6 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
142
138
  }, card) : data ? card : null;
143
139
  });
144
140
  var WrappedInlineCardWithAwareness = Card(InlineCardWithAwareness, UnsupportedInline);
145
- var WrappedInlineCard = Card(InlineCard, UnsupportedInline);
146
141
  var selector = function selector(states) {
147
142
  var _states$editorViewMod, _states$selectionStat;
148
143
  return {
@@ -178,54 +173,15 @@ export function InlineCardNodeView(props) {
178
173
  enableInlineUpgradeFeatures = props.enableInlineUpgradeFeatures,
179
174
  pluginInjectionApi = props.pluginInjectionApi,
180
175
  onClickCallback = props.onClickCallback,
181
- __livePage = props.__livePage,
182
176
  isPageSSRed = props.isPageSSRed,
183
177
  CompetitorPrompt = props.CompetitorPrompt;
184
- var _useState = useState(false),
185
- _useState2 = _slicedToArray(_useState, 2),
186
- isOverlayHovered = _useState2[0],
187
- setIsOverlayHovered = _useState2[1];
188
178
  var _useSharedState = useSharedState(pluginInjectionApi),
189
- mode = _useSharedState.mode,
190
- selection = _useSharedState.selection;
191
- var floatingToolbarNode = selection instanceof NodeSelection && selection.node;
179
+ mode = _useSharedState.mode;
192
180
  var url = node.attrs.url;
193
181
  var CompetitorPromptComponent = CompetitorPrompt && url ? /*#__PURE__*/React.createElement(CompetitorPrompt, {
194
182
  sourceUrl: url,
195
183
  linkType: "inline"
196
184
  }) : null;
197
- if (__livePage && fg('linking_platform_smart_links_in_live_pages')) {
198
- var showHoverPreview = floatingToolbarNode !== node;
199
- var livePagesHoverCardFadeInDelay = 800;
200
- var inlineCard = /*#__PURE__*/React.createElement(WrappedInlineCard, {
201
- isHovered: isOverlayHovered,
202
- node: node,
203
- view: view,
204
- getPos: getPos,
205
- actionOptions: actionOptions,
206
- useAlternativePreloader: useAlternativePreloader,
207
- onClickCallback: onClickCallback,
208
- showHoverPreview: showHoverPreview,
209
- hoverPreviewOptions: {
210
- fadeInDelay: livePagesHoverCardFadeInDelay
211
- },
212
- isPageSSRed: isPageSSRed
213
- });
214
- return mode === 'view' ? inlineCard : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(OverlayWrapper, {
215
- targetElementPos: getPos(),
216
- view: view,
217
- isHoveredCallback: setIsOverlayHovered,
218
- onOpenLinkClick: function onOpenLinkClick(event) {
219
- var _pluginInjectionApi$a2;
220
- handleNavigation({
221
- fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.fireAnalyticsEvent,
222
- onClickCallback: onClickCallback,
223
- url: url,
224
- event: event
225
- });
226
- }
227
- }, inlineCard), fg('prompt_whiteboard_competitor_link_gate') && CompetitorPromptComponent);
228
- }
229
185
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, _extends({
230
186
  node: node,
231
187
  view: view,
@@ -1,28 +1,31 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import React, { memo, useCallback, useMemo, useState } from 'react';
3
3
  import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
4
5
  import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { getObjectAri, getObjectName, getObjectIconUrl } from '@atlaskit/smart-card';
6
7
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
7
8
  import { registerRemoveOverlay } from '../pm-plugins/actions';
8
9
  import { pluginKey } from '../pm-plugins/plugin-key';
9
10
  import { AwarenessWrapper } from '../ui/AwarenessWrapper';
10
- import OpenButtonOverlay from '../ui/OpenButtonOverlay';
11
- import PanelButtonOverlay from '../ui/PanelButtonOverlay';
11
+ import HoverLinkOverlay from '../ui/HoverLinkOverlay';
12
12
  import { InlineCard } from './inlineCard';
13
13
  var selector = function selector(states) {
14
- var _states$editorViewMod;
14
+ var _states$editorViewMod, _states$selectionStat;
15
15
  return {
16
- mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
16
+ mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode,
17
+ selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection
17
18
  };
18
19
  };
19
20
  var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
20
- return useSharedPluginStateWithSelector(pluginInjectionApi, ['editorViewMode'], selector);
21
+ return useSharedPluginStateWithSelector(pluginInjectionApi, ['selection', 'editorViewMode'], selector);
21
22
  }, function (pluginInjectionApi) {
22
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
23
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['selection', 'editorViewMode']),
24
+ selectionState = _useSharedPluginState.selectionState,
23
25
  editorViewModeState = _useSharedPluginState.editorViewModeState;
24
26
  return {
25
- mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode
27
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
28
+ selection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection
26
29
  };
27
30
  });
28
31
  export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
@@ -79,10 +82,13 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
79
82
  }
80
83
  }, [isOverlayEnabled]);
81
84
  var _useSharedState = useSharedState(pluginInjectionApi),
82
- mode = _useSharedState.mode;
85
+ mode = _useSharedState.mode,
86
+ selection = _useSharedState.selection;
87
+ var floatingToolbarNode = selection instanceof NodeSelection && selection.node;
88
+ var showHoverPreview = floatingToolbarNode !== node && fg('platform_editor_preview_panel_linking');
83
89
  var innerCardWithOpenButtonOverlay = useMemo(function () {
84
90
  var _pluginInjectionApi$a;
85
- return /*#__PURE__*/React.createElement(OpenButtonOverlay, {
91
+ return /*#__PURE__*/React.createElement(HoverLinkOverlay, {
86
92
  isVisible: isResolvedViewRendered,
87
93
  url: node.attrs.url,
88
94
  editorAppearance: editorAppearance,
@@ -99,9 +105,10 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
99
105
  cardContext: cardContext,
100
106
  isHovered: isHovered,
101
107
  isPageSSRed: isPageSSRed,
102
- pluginInjectionApi: pluginInjectionApi
108
+ pluginInjectionApi: pluginInjectionApi,
109
+ showHoverPreview: showHoverPreview
103
110
  }));
104
- }, [isResolvedViewRendered, node, editorAppearance, view, getPos, useAlternativePreloader, actionOptions, onResolve, onClick, cardContext, isHovered, isPageSSRed, pluginInjectionApi]);
111
+ }, [isResolvedViewRendered, node, editorAppearance, view, getPos, useAlternativePreloader, actionOptions, onResolve, onClick, cardContext, isHovered, isPageSSRed, pluginInjectionApi, showHoverPreview]);
105
112
  var innerCardOriginal = useMemo(function () {
106
113
  return /*#__PURE__*/React.createElement(InlineCard, {
107
114
  node: node,
@@ -114,19 +121,20 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
114
121
  cardContext: cardContext,
115
122
  isHovered: isHovered,
116
123
  isPageSSRed: isPageSSRed,
117
- pluginInjectionApi: pluginInjectionApi
124
+ pluginInjectionApi: pluginInjectionApi,
125
+ showHoverPreview: showHoverPreview
118
126
  });
119
- }, [actionOptions, cardContext, getPos, isHovered, node, onClick, onResolve, useAlternativePreloader, view, isPageSSRed, pluginInjectionApi]);
127
+ }, [actionOptions, cardContext, getPos, isHovered, node, onClick, onResolve, useAlternativePreloader, view, isPageSSRed, pluginInjectionApi, showHoverPreview]);
120
128
  var shouldShowOpenButtonOverlay = useMemo(function () {
121
129
  var shouldShowOpenButtonOverlayInChomeless = editorAppearance === 'chromeless';
122
- return (mode === 'edit' || editorAppearance === 'comment' || shouldShowOpenButtonOverlayInChomeless) && editorExperiment('platform_editor_controls', 'variant1');
130
+ return (mode === 'edit' || editorAppearance === 'comment' || shouldShowOpenButtonOverlayInChomeless) && (editorExperiment('platform_editor_controls', 'variant1') || fg('platform_editor_preview_panel_linking'));
123
131
  }, [mode, editorAppearance]);
124
132
  var innerCard = shouldShowOpenButtonOverlay ? innerCardWithOpenButtonOverlay : innerCardOriginal;
125
133
  if (fg('platform_editor_preview_panel_linking')) {
126
134
  var _cardContext$value;
127
135
  var cardState = cardContext === null || cardContext === void 0 || (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 || (_cardContext$value = _cardContext$value.store) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.getState()[node.attrs.url];
128
136
  if (cardState) {
129
- var _cardContext$value2, _cardContext$value2$i, _cardContext$value3;
137
+ var _cardContext$value2, _cardContext$value2$i, _cardContext$value3, _pluginInjectionApi$a2;
130
138
  var ari = getObjectAri(cardState.details);
131
139
  var name = getObjectName(cardState.details);
132
140
  var iconUrl = getObjectIconUrl(cardState.details);
@@ -134,8 +142,11 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
134
142
  ari: ari
135
143
  }));
136
144
  var openPreviewPanel = cardContext === null || cardContext === void 0 || (_cardContext$value3 = cardContext.value) === null || _cardContext$value3 === void 0 ? void 0 : _cardContext$value3.openPreviewPanel;
137
- var handleOpenGlancePanelClick = function handleOpenGlancePanelClick() {
145
+ var handleOpenGlancePanelClick = function handleOpenGlancePanelClick(event) {
138
146
  if (openPreviewPanel && isPanelAvailable) {
147
+ // Prevent anchor default behaviour(click to open the anchor link)
148
+ // When glance panel is available, let openPreviewPanel handle it
149
+ event.preventDefault();
139
150
  openPreviewPanel({
140
151
  url: node.attrs.url,
141
152
  ari: ari,
@@ -144,9 +155,13 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
144
155
  });
145
156
  }
146
157
  };
147
- var innerCardWithPanelButtonOverlay = /*#__PURE__*/React.createElement(PanelButtonOverlay, {
158
+ var innerCardWithPanelButtonOverlay = /*#__PURE__*/React.createElement(HoverLinkOverlay, {
148
159
  isVisible: isResolvedViewRendered,
160
+ url: node.attrs.url,
149
161
  editorAppearance: editorAppearance,
162
+ editorAnalyticsApi: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions,
163
+ view: view,
164
+ showPanelButton: !!isPanelAvailable,
150
165
  onClick: handleOpenGlancePanelClick
151
166
  }, /*#__PURE__*/React.createElement(InlineCard, {
152
167
  node: node,
@@ -159,7 +174,8 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
159
174
  cardContext: cardContext,
160
175
  isHovered: isHovered,
161
176
  isPageSSRed: isPageSSRed,
162
- pluginInjectionApi: pluginInjectionApi
177
+ pluginInjectionApi: pluginInjectionApi,
178
+ showHoverPreview: showHoverPreview
163
179
  }));
164
180
  innerCard = isPanelAvailable && openPreviewPanel ? innerCardWithPanelButtonOverlay : innerCard;
165
181
  }
@@ -1,5 +1,5 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  import rafSchedule from 'raf-schd';
@@ -9,7 +9,6 @@ import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/st
9
9
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
10
10
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
11
11
  import { DATASOURCE_DEFAULT_LAYOUT } from '@atlaskit/linking-common';
12
- import { fg } from '@atlaskit/platform-feature-flags';
13
12
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
14
13
  import { lazyBlockCardView } from '../nodeviews/lazy-block-card';
15
14
  import { lazyEmbedCardView } from '../nodeviews/lazy-embed-card';
@@ -24,19 +23,6 @@ import { handleProvider, resolveWithProvider } from './util/resolve';
24
23
  import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
25
24
  import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from './utils';
26
25
  var LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK = 'smart-link-upgrade-pulse';
27
- export var ALLOW_EVENTS_CLASSNAME = 'card-plugin-element-allow-events';
28
- export var stopEvent = function stopEvent(event) {
29
- if (!fg('linking_platform_smart_links_in_live_pages')) {
30
- return false;
31
- }
32
- var target = event.target;
33
- // Stop events from propogating to prose-mirror and selecting the node and/or
34
- // opening the toolbar, unless a parent of the target has a defined className
35
- if (target instanceof HTMLElement && target.closest(".".concat(ALLOW_EVENTS_CLASSNAME))) {
36
- return false;
37
- }
38
- return true;
39
- };
40
26
  var handleAwarenessOverlay = function handleAwarenessOverlay(view) {
41
27
  var currentState = getPluginState(view.state);
42
28
  var overlayCandidatePos = currentState === null || currentState === void 0 ? void 0 : currentState.overlayCandidatePosition;
@@ -60,11 +46,10 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
60
46
  allowEmbeds = options.allowEmbeds,
61
47
  allowBlockCards = options.allowBlockCards,
62
48
  onClickCallback = options.onClickCallback,
63
- __livePage = options.__livePage,
64
49
  isPageSSRed = options.isPageSSRed,
65
50
  CompetitorPrompt = options.CompetitorPrompt;
66
51
  var enableInlineUpgradeFeatures = !!showUpgradeDiscoverability;
67
- var inlineCardViewProducer = getInlineNodeViewProducer(_objectSpread({
52
+ var inlineCardViewProducer = getInlineNodeViewProducer({
68
53
  pmPluginFactoryParams: pmPluginFactoryParams,
69
54
  Component: InlineCardNodeView,
70
55
  extraComponentProps: {
@@ -75,15 +60,10 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
75
60
  allowBlockCards: allowBlockCards,
76
61
  pluginInjectionApi: pluginInjectionApi,
77
62
  onClickCallback: onClickCallback,
78
- __livePage: __livePage,
79
63
  isPageSSRed: isPageSSRed,
80
64
  CompetitorPrompt: CompetitorPrompt
81
65
  }
82
- }, __livePage && fg('linking_platform_smart_links_in_live_pages') && {
83
- extraNodeViewProps: {
84
- stopEvent: stopEvent
85
- }
86
- }));
66
+ });
87
67
  return new SafePlugin({
88
68
  state: {
89
69
  init: function init() {