@atlaskit/editor-plugin-card 6.0.0 → 6.0.2

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.
@@ -1,5 +1,6 @@
1
1
  import React, { memo, useCallback, useMemo, useState } from 'react';
2
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
2
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
3
4
  import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
6
  import { registerRemoveOverlay } from '../pm-plugins/actions';
@@ -7,6 +8,19 @@ import { pluginKey } from '../pm-plugins/plugin-key';
7
8
  import { AwarenessWrapper } from '../ui/AwarenessWrapper';
8
9
  import OpenButtonOverlay from '../ui/OpenButtonOverlay';
9
10
  import { InlineCard } from './inlineCard';
11
+ const useSharedState = sharedPluginStateHookMigratorFactory(pluginInjectionApi => {
12
+ const {
13
+ editorViewModeState
14
+ } = useSharedPluginState(pluginInjectionApi, ['editorViewMode']);
15
+ return {
16
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode
17
+ };
18
+ }, pluginInjectionApi => {
19
+ const mode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
20
+ return {
21
+ mode
22
+ };
23
+ });
10
24
  export const InlineCardWithAwareness = /*#__PURE__*/memo(({
11
25
  node,
12
26
  cardContext,
@@ -52,8 +66,8 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
52
66
  }
53
67
  }, [isOverlayEnabled]);
54
68
  const {
55
- editorViewModeState
56
- } = useSharedPluginState(pluginInjectionApi, ['editorViewMode']);
69
+ mode
70
+ } = useSharedState(pluginInjectionApi);
57
71
  const innerCardWithOpenButtonOverlay = useMemo(() => /*#__PURE__*/React.createElement(OpenButtonOverlay, {
58
72
  isVisible: isResolvedViewRendered,
59
73
  url: node.attrs.url,
@@ -86,8 +100,8 @@ export const InlineCardWithAwareness = /*#__PURE__*/memo(({
86
100
  }), [actionOptions, cardContext, getPos, isHovered, node, onClick, onResolve, useAlternativePreloader, view, isPageSSRed]);
87
101
  const shouldShowOpenButtonOverlay = useMemo(() => {
88
102
  const shouldShowOpenButtonOverlayInChomeless = editorAppearance === 'chromeless' && fg('platform_editor_controls_patch_8');
89
- return ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'edit' || editorAppearance === 'comment' && fg('platform_editor_controls_patch_6') || shouldShowOpenButtonOverlayInChomeless) && editorExperiment('platform_editor_controls', 'variant1');
90
- }, [editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode, editorAppearance]);
103
+ return (mode === 'edit' || editorAppearance === 'comment' && fg('platform_editor_controls_patch_6') || shouldShowOpenButtonOverlayInChomeless) && editorExperiment('platform_editor_controls', 'variant1');
104
+ }, [mode, editorAppearance]);
91
105
  const innerCard = shouldShowOpenButtonOverlay ? innerCardWithOpenButtonOverlay : innerCardOriginal;
92
106
  const getPosFunction = typeof getPos === 'function' ? getPos : undefined;
93
107
  const placeholderUniqId = (getPosFunction === null || getPosFunction === void 0 ? void 0 : getPosFunction()) || 0;
@@ -1,24 +1,42 @@
1
1
  import React from 'react';
2
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
2
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
3
4
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, CONFLUENCE_SEARCH_DATASOURCE_ID, ConfluenceSearchConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
4
5
  import { EditorSmartCardProviderValueGuard, useSmartLinkContext } from '@atlaskit/link-provider';
6
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
7
  import { DatasourceErrorBoundary } from '../datasourceErrorBoundary';
6
8
  import { DatasourceModal } from './index';
9
+ const useSharedState = sharedPluginStateHookMigratorFactory(pluginInjectionApi => {
10
+ const showDatasourceModal = useSharedPluginStateSelector(pluginInjectionApi, 'card.showDatasourceModal');
11
+ const datasourceModalType = useSharedPluginStateSelector(pluginInjectionApi, 'card.datasourceModalType');
12
+ return {
13
+ cardState: undefined,
14
+ showDatasourceModal,
15
+ datasourceModalType
16
+ };
17
+ }, pluginInjectionApi => {
18
+ const {
19
+ cardState
20
+ } = useSharedPluginState(pluginInjectionApi, ['card']);
21
+ return {
22
+ cardState,
23
+ showDatasourceModal: cardState === null || cardState === void 0 ? void 0 : cardState.showDatasourceModal,
24
+ datasourceModalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType
25
+ };
26
+ });
7
27
  const ModalWithState = ({
8
28
  api,
9
29
  editorView
10
30
  }) => {
11
31
  const cardContext = useSmartLinkContext();
12
32
  const {
13
- cardState
14
- } = useSharedPluginState(api, ['card']);
15
- if (!cardState) {
16
- return null;
17
- }
18
- const {
33
+ cardState,
19
34
  showDatasourceModal,
20
35
  datasourceModalType
21
- } = cardState;
36
+ } = useSharedState(api);
37
+ if (!cardState && editorExperiment('platform_editor_usesharedpluginstateselector', false)) {
38
+ return null;
39
+ }
22
40
  if (!showDatasourceModal || !datasourceModalType) {
23
41
  return null;
24
42
  }
@@ -3,6 +3,7 @@ import { appearancePropsMap } from '@atlaskit/editor-common/card';
3
3
  import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
4
4
  import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlaskit/editor-common/ui-menu';
5
5
  import ChevronDownIcon from '@atlaskit/icon/utility/migration/chevron-down';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { Flex } from '@atlaskit/primitives/compiled';
7
8
  import { LinkAppearanceMenu } from './LinkToolbarAppearanceDropdown';
8
9
  const CustomHyperlinkDropdown = props => {
@@ -68,7 +69,7 @@ const CustomHyperlinkDropdown = props => {
68
69
  return null;
69
70
  }
70
71
  const dispatchCommand = fn => {
71
- fn && fn(editorView && editorView.state, editorView && editorView.dispatch);
72
+ fn && fn(editorView && editorView.state, editorView && editorView.dispatch, fg('platform_editor_controls_patch_9') ? editorView : undefined);
72
73
  // Refocus the view to ensure the editor has focus
73
74
  if (editorView && !editorView.hasFocus()) {
74
75
  editorView.focus();
@@ -7,9 +7,10 @@ import { useCallback, useMemo } from 'react';
7
7
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
8
  import { css, jsx } from '@emotion/react';
9
9
  import { injectIntl } from 'react-intl-next';
10
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
10
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
11
11
  import { Popup } from '@atlaskit/editor-common/ui';
12
12
  import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
13
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
13
14
  import { getNextBreakoutMode, getTitle } from '@atlaskit/editor-common/utils';
14
15
  import GrowHorizontalIcon from '@atlaskit/icon/core/migration/grow-horizontal--editor-expand';
15
16
  import ShrinkHorizontalIcon from '@atlaskit/icon/core/migration/shrink-horizontal--editor-collapse';
@@ -71,6 +72,22 @@ export const LayoutButton = ({
71
72
  })
72
73
  }));
73
74
  };
75
+ const useSharedState = sharedPluginStateHookMigratorFactory(pluginInjectionApi => {
76
+ const layout = useSharedPluginStateSelector(pluginInjectionApi, 'card.layout');
77
+ const datasourceTableRef = useSharedPluginStateSelector(pluginInjectionApi, 'card.datasourceTableRef');
78
+ return {
79
+ layout,
80
+ datasourceTableRef
81
+ };
82
+ }, pluginInjectionApi => {
83
+ const {
84
+ cardState
85
+ } = useSharedPluginState(pluginInjectionApi, ['card']);
86
+ return {
87
+ layout: cardState === null || cardState === void 0 ? void 0 : cardState.layout,
88
+ datasourceTableRef: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceTableRef
89
+ };
90
+ });
74
91
  const LayoutButtonWrapper = ({
75
92
  editorView,
76
93
  mountPoint,
@@ -80,24 +97,18 @@ const LayoutButtonWrapper = ({
80
97
  api
81
98
  }) => {
82
99
  var _node$attrs;
83
- const {
84
- cardState
85
- } = useSharedPluginState(api, ['card']);
86
100
  const {
87
101
  node,
88
102
  pos
89
103
  } = getDatasource(editorView);
104
+ const {
105
+ layout = (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) || undefined,
106
+ datasourceTableRef
107
+ } = useSharedState(api);
90
108
  const isDatasource = isDatasourceNode(node);
91
109
  if (!isDatasource) {
92
110
  return null;
93
111
  }
94
-
95
- // If layout doesn't exist in ADF it returns null, we want to change to undefined
96
- // which results in default parameter value being used in LayoutButton.
97
- const {
98
- datasourceTableRef,
99
- layout = (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) || undefined
100
- } = cardState !== null && cardState !== void 0 ? cardState : {};
101
112
  const onLayoutChange = layout => {
102
113
  var _getDatasource$node;
103
114
  if (pos === undefined) {
@@ -319,6 +319,28 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
319
319
  type: 'separator'
320
320
  }] : [];
321
321
  const openLinkInputMethod = fg('platform_editor_controls_patch_analytics') ? INPUT_METHOD.FLOATING_TB : INPUT_METHOD.TOOLBAR;
322
+ const editButtonItems = cardOptions.allowDatasource && fg('platform_editor_controls_patch_9') ? [{
323
+ type: 'custom',
324
+ fallback: [],
325
+ render: editorView => /*#__PURE__*/React.createElement(EditToolbarButton, {
326
+ key: "edit-toolbar-item",
327
+ url: url,
328
+ intl: intl,
329
+ editorAnalyticsApi: editorAnalyticsApi,
330
+ editorView: editorView,
331
+ onLinkEditClick: getEditLinkCallback(editorAnalyticsApi, true),
332
+ currentAppearance: currentAppearance
333
+ })
334
+ }] : [{
335
+ id: 'editor.link.edit',
336
+ type: 'button',
337
+ selected: false,
338
+ metadata: metadata,
339
+ title: intl.formatMessage(linkToolbarMessages.editLink),
340
+ icon: EditIcon,
341
+ testId: 'link-toolbar-edit-link-button',
342
+ onClick: getEditLinkCallback(editorAnalyticsApi, true)
343
+ }];
322
344
  const toolbarItems = editorExperiment('platform_editor_controls', 'control') ? [...editItems, ...commentItems, {
323
345
  id: 'editor.link.openLink',
324
346
  type: 'button',
@@ -358,16 +380,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
358
380
  onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, false),
359
381
  title: intl.formatMessage(commonMessages.remove),
360
382
  onClick: withToolbarMetadata(removeCard(editorAnalyticsApi))
361
- }] : [{
362
- id: 'editor.link.edit',
363
- type: 'button',
364
- selected: false,
365
- metadata: metadata,
366
- title: intl.formatMessage(linkToolbarMessages.editLink),
367
- icon: EditIcon,
368
- testId: 'link-toolbar-edit-link-button',
369
- onClick: getEditLinkCallback(editorAnalyticsApi, true)
370
- }, ...(fg('platform_editor_controls_patch_6') ? [] : [{
383
+ }] : [...editButtonItems, ...(fg('platform_editor_controls_patch_6') ? [] : [{
371
384
  type: 'separator'
372
385
  }]), ...getUnlinkButtonGroup(state, intl, node, inlineCard, editorAnalyticsApi), {
373
386
  id: 'editor.link.openLink',
@@ -15,15 +15,35 @@ import React from 'react';
15
15
  import rafSchedule from 'raf-schd';
16
16
  import uuid from 'uuid/v4';
17
17
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
18
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
18
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
19
19
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
20
20
  import { findOverflowScrollParent, MediaSingle as RichMediaWrapper, UnsupportedBlock } from '@atlaskit/editor-common/ui';
21
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
21
22
  import { floatingLayouts, isRichMediaInsideOfBlockNode } from '@atlaskit/editor-common/utils';
22
23
  import { DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
23
24
  import { EmbedResizeMessageListener, Card as SmartCard } from '@atlaskit/smart-card';
24
25
  import { registerCard, removeCard as _removeCard } from '../pm-plugins/actions';
25
26
  import ResizableEmbedCard from '../ui/ResizableEmbedCard';
26
27
  import { Card } from './genericCard';
28
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
29
+ var lineLength = useSharedPluginStateSelector(pluginInjectionApi, 'width.lineLength');
30
+ var width = useSharedPluginStateSelector(pluginInjectionApi, 'width.width');
31
+ var editorDisabled = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled');
32
+ return {
33
+ widthStateLineLength: lineLength || 0,
34
+ widthStateWidth: width || 0,
35
+ editorDisabled: editorDisabled
36
+ };
37
+ }, function (pluginInjectionApi) {
38
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['width', 'editorDisabled']),
39
+ widthState = _useSharedPluginState.widthState,
40
+ editorDisabledState = _useSharedPluginState.editorDisabledState;
41
+ return {
42
+ widthStateLineLength: (widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || 0,
43
+ widthStateWidth: (widthState === null || widthState === void 0 ? void 0 : widthState.width) || 0,
44
+ editorDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled
45
+ };
46
+ });
27
47
  var CardInner = function CardInner(_ref) {
28
48
  var pluginInjectionApi = _ref.pluginInjectionApi,
29
49
  getPosSafely = _ref.getPosSafely,
@@ -39,11 +59,10 @@ var CardInner = function CardInner(_ref) {
39
59
  heightAlone = _ref.heightAlone,
40
60
  cardProps = _ref.cardProps,
41
61
  dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
42
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['width', 'editorDisabled']),
43
- widthState = _useSharedPluginState.widthState,
44
- editorDisabledState = _useSharedPluginState.editorDisabledState;
45
- var widthStateLineLength = (widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || 0;
46
- var widthStateWidth = (widthState === null || widthState === void 0 ? void 0 : widthState.width) || 0;
62
+ var _useSharedState = useSharedState(pluginInjectionApi),
63
+ widthStateLineLength = _useSharedState.widthStateLineLength,
64
+ widthStateWidth = _useSharedState.widthStateWidth,
65
+ editorDisabled = _useSharedState.editorDisabled;
47
66
  var pos = getPosSafely();
48
67
  if (pos === undefined) {
49
68
  return null;
@@ -96,7 +115,7 @@ var CardInner = function CardInner(_ref) {
96
115
  displayGrid: displayGrid,
97
116
  updateSize: updateSize,
98
117
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
99
- isResizeDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled
118
+ isResizeDisabled: editorDisabled
100
119
  }), smartCard);
101
120
  };
102
121
  // eslint-disable-next-line @repo/internal/react/no-class-components
@@ -10,21 +10,34 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
10
10
  import React, { useCallback } from 'react';
11
11
  import { isSafeUrl } from '@atlaskit/adf-schema';
12
12
  import { AnalyticsContext } from '@atlaskit/analytics-next';
13
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
13
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
14
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
14
15
  import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
15
16
  import { fg } from '@atlaskit/platform-feature-flags';
16
17
  import { changeSelectedCardToLinkFallback } from '../pm-plugins/doc';
17
18
  import { getPluginState } from '../pm-plugins/util/state';
18
19
  import { titleUrlPairFromNode } from '../pm-plugins/utils';
19
20
  import { WithCardContext } from '../ui/WithCardContext';
21
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
22
+ var mode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
23
+ return {
24
+ mode: mode
25
+ };
26
+ }, function (pluginInjectionApi) {
27
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
28
+ editorViewModeState = _useSharedPluginState.editorViewModeState;
29
+ return {
30
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode
31
+ };
32
+ });
20
33
  var WithClickHandler = function WithClickHandler(_ref) {
21
34
  var pluginInjectionApi = _ref.pluginInjectionApi,
22
35
  url = _ref.url,
23
36
  onClickCallback = _ref.onClickCallback,
24
37
  children = _ref.children,
25
38
  __livePage = _ref.__livePage;
26
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
27
- editorViewModeState = _useSharedPluginState.editorViewModeState;
39
+ var _useSharedState = useSharedState(pluginInjectionApi),
40
+ mode = _useSharedState.mode;
28
41
  var onClick = useCallback(function (event) {
29
42
  if (typeof onClickCallback === 'function') {
30
43
  try {
@@ -53,7 +66,7 @@ var WithClickHandler = function WithClickHandler(_ref) {
53
66
 
54
67
  // Setting `onClick` to `undefined` ensures clicks on smartcards navigate to the URL.
55
68
  // If in view mode and not overriding with onClickCallback option, then allow smartlinks to navigate on click.
56
- var allowNavigation = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' && !onClickCallback;
69
+ var allowNavigation = mode === 'view' && !onClickCallback;
57
70
  return /*#__PURE__*/React.createElement(React.Fragment, null, children({
58
71
  onClick: allowNavigation ? undefined : onClick
59
72
  }));
@@ -3,9 +3,10 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import rafSchedule from 'raf-schd';
5
5
  import uuid from 'uuid/v4';
6
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
7
  import { handleNavigation } from '@atlaskit/editor-common/link';
8
8
  import { findOverflowScrollParent, UnsupportedInline } from '@atlaskit/editor-common/ui';
9
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
9
10
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
10
11
  import { fg } from '@atlaskit/platform-feature-flags';
11
12
  import { Card as SmartCard } from '@atlaskit/smart-card';
@@ -125,6 +126,22 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
125
126
  });
126
127
  var WrappedInlineCardWithAwareness = Card(InlineCardWithAwareness, UnsupportedInline);
127
128
  var WrappedInlineCard = Card(InlineCard, UnsupportedInline);
129
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
130
+ var mode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
131
+ var selection = useSharedPluginStateSelector(pluginInjectionApi, 'selection.selection');
132
+ return {
133
+ mode: mode,
134
+ selection: selection
135
+ };
136
+ }, function (pluginInjectionApi) {
137
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['selection', 'editorViewMode']),
138
+ selectionState = _useSharedPluginState.selectionState,
139
+ editorViewModeState = _useSharedPluginState.editorViewModeState;
140
+ return {
141
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
142
+ selection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection
143
+ };
144
+ });
128
145
  export function InlineCardNodeView(props) {
129
146
  var useAlternativePreloader = props.useAlternativePreloader,
130
147
  node = props.node,
@@ -142,10 +159,10 @@ export function InlineCardNodeView(props) {
142
159
  _useState2 = _slicedToArray(_useState, 2),
143
160
  isOverlayHovered = _useState2[0],
144
161
  setIsOverlayHovered = _useState2[1];
145
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['selection', 'editorViewMode']),
146
- editorViewModeState = _useSharedPluginState.editorViewModeState,
147
- selectionState = _useSharedPluginState.selectionState;
148
- var floatingToolbarNode = (selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection) instanceof NodeSelection && (selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection.node);
162
+ var _useSharedState = useSharedState(pluginInjectionApi),
163
+ mode = _useSharedState.mode,
164
+ selection = _useSharedState.selection;
165
+ var floatingToolbarNode = selection instanceof NodeSelection && selection.node;
149
166
  if (__livePage && fg('linking_platform_smart_links_in_live_pages')) {
150
167
  var showHoverPreview = floatingToolbarNode !== node;
151
168
  var livePagesHoverCardFadeInDelay = 800;
@@ -163,7 +180,7 @@ export function InlineCardNodeView(props) {
163
180
  },
164
181
  isPageSSRed: isPageSSRed
165
182
  });
166
- return (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? inlineCard : /*#__PURE__*/React.createElement(OverlayWrapper, {
183
+ return mode === 'view' ? inlineCard : /*#__PURE__*/React.createElement(OverlayWrapper, {
167
184
  targetElementPos: getPos(),
168
185
  view: view,
169
186
  isHoveredCallback: setIsOverlayHovered,
@@ -190,7 +207,7 @@ export function InlineCardNodeView(props) {
190
207
  appearance: "inline"
191
208
  // Ignored via go/ees005
192
209
  // eslint-disable-next-line react/jsx-props-no-spreading
193
- }, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards, !editorExperiment('live_pages_graceful_edit', 'control') ? true : (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view')));
210
+ }, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards, !editorExperiment('live_pages_graceful_edit', 'control') ? true : mode === 'view')));
194
211
  }
195
212
  export var inlineCardNodeView = function inlineCardNodeView(_ref2) {
196
213
  var inlineCardViewProducer = _ref2.inlineCardViewProducer;
@@ -1,6 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import React, { memo, useCallback, useMemo, useState } from 'react';
3
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
4
5
  import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
7
  import { registerRemoveOverlay } from '../pm-plugins/actions';
@@ -8,6 +9,18 @@ import { pluginKey } from '../pm-plugins/plugin-key';
8
9
  import { AwarenessWrapper } from '../ui/AwarenessWrapper';
9
10
  import OpenButtonOverlay from '../ui/OpenButtonOverlay';
10
11
  import { InlineCard } from './inlineCard';
12
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
13
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
14
+ editorViewModeState = _useSharedPluginState.editorViewModeState;
15
+ return {
16
+ mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode
17
+ };
18
+ }, function (pluginInjectionApi) {
19
+ var mode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
20
+ return {
21
+ mode: mode
22
+ };
23
+ });
11
24
  export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
12
25
  var _pluginInjectionApi$c, _pluginInjectionApi$a;
13
26
  var node = _ref.node,
@@ -63,8 +76,8 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
63
76
  setIsHovered(isHovered);
64
77
  }
65
78
  }, [isOverlayEnabled]);
66
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
67
- editorViewModeState = _useSharedPluginState.editorViewModeState;
79
+ var _useSharedState = useSharedState(pluginInjectionApi),
80
+ mode = _useSharedState.mode;
68
81
  var innerCardWithOpenButtonOverlay = useMemo(function () {
69
82
  return /*#__PURE__*/React.createElement(OpenButtonOverlay, {
70
83
  isVisible: isResolvedViewRendered,
@@ -101,8 +114,8 @@ export var InlineCardWithAwareness = /*#__PURE__*/memo(function (_ref) {
101
114
  }, [actionOptions, cardContext, getPos, isHovered, node, onClick, onResolve, useAlternativePreloader, view, isPageSSRed]);
102
115
  var shouldShowOpenButtonOverlay = useMemo(function () {
103
116
  var shouldShowOpenButtonOverlayInChomeless = editorAppearance === 'chromeless' && fg('platform_editor_controls_patch_8');
104
- return ((editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'edit' || editorAppearance === 'comment' && fg('platform_editor_controls_patch_6') || shouldShowOpenButtonOverlayInChomeless) && editorExperiment('platform_editor_controls', 'variant1');
105
- }, [editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode, editorAppearance]);
117
+ return (mode === 'edit' || editorAppearance === 'comment' && fg('platform_editor_controls_patch_6') || shouldShowOpenButtonOverlayInChomeless) && editorExperiment('platform_editor_controls', 'variant1');
118
+ }, [mode, editorAppearance]);
106
119
  var innerCard = shouldShowOpenButtonOverlay ? innerCardWithOpenButtonOverlay : innerCardOriginal;
107
120
  var getPosFunction = typeof getPos === 'function' ? getPos : undefined;
108
121
  var placeholderUniqId = (getPosFunction === null || getPosFunction === void 0 ? void 0 : getPosFunction()) || 0;
@@ -1,20 +1,39 @@
1
1
  import React from 'react';
2
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
2
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
3
4
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, CONFLUENCE_SEARCH_DATASOURCE_ID, ConfluenceSearchConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
4
5
  import { EditorSmartCardProviderValueGuard, useSmartLinkContext } from '@atlaskit/link-provider';
6
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
7
  import { DatasourceErrorBoundary } from '../datasourceErrorBoundary';
6
8
  import { DatasourceModal } from './index';
9
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
10
+ var showDatasourceModal = useSharedPluginStateSelector(pluginInjectionApi, 'card.showDatasourceModal');
11
+ var datasourceModalType = useSharedPluginStateSelector(pluginInjectionApi, 'card.datasourceModalType');
12
+ return {
13
+ cardState: undefined,
14
+ showDatasourceModal: showDatasourceModal,
15
+ datasourceModalType: datasourceModalType
16
+ };
17
+ }, function (pluginInjectionApi) {
18
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['card']),
19
+ cardState = _useSharedPluginState.cardState;
20
+ return {
21
+ cardState: cardState,
22
+ showDatasourceModal: cardState === null || cardState === void 0 ? void 0 : cardState.showDatasourceModal,
23
+ datasourceModalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType
24
+ };
25
+ });
7
26
  var ModalWithState = function ModalWithState(_ref) {
8
27
  var api = _ref.api,
9
28
  editorView = _ref.editorView;
10
29
  var cardContext = useSmartLinkContext();
11
- var _useSharedPluginState = useSharedPluginState(api, ['card']),
12
- cardState = _useSharedPluginState.cardState;
13
- if (!cardState) {
30
+ var _useSharedState = useSharedState(api),
31
+ cardState = _useSharedState.cardState,
32
+ showDatasourceModal = _useSharedState.showDatasourceModal,
33
+ datasourceModalType = _useSharedState.datasourceModalType;
34
+ if (!cardState && editorExperiment('platform_editor_usesharedpluginstateselector', false)) {
14
35
  return null;
15
36
  }
16
- var showDatasourceModal = cardState.showDatasourceModal,
17
- datasourceModalType = cardState.datasourceModalType;
18
37
  if (!showDatasourceModal || !datasourceModalType) {
19
38
  return null;
20
39
  }
@@ -6,6 +6,7 @@ import { appearancePropsMap } from '@atlaskit/editor-common/card';
6
6
  import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
7
7
  import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlaskit/editor-common/ui-menu';
8
8
  import ChevronDownIcon from '@atlaskit/icon/utility/migration/chevron-down';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
9
10
  import { Flex } from '@atlaskit/primitives/compiled';
10
11
  import { LinkAppearanceMenu } from './LinkToolbarAppearanceDropdown';
11
12
  var CustomHyperlinkDropdown = function CustomHyperlinkDropdown(props) {
@@ -138,7 +139,7 @@ var CustomHyperlinkDropdown = function CustomHyperlinkDropdown(props) {
138
139
  return null;
139
140
  }
140
141
  var dispatchCommand = function dispatchCommand(fn) {
141
- fn && fn(editorView && editorView.state, editorView && editorView.dispatch);
142
+ fn && fn(editorView && editorView.state, editorView && editorView.dispatch, fg('platform_editor_controls_patch_9') ? editorView : undefined);
142
143
  // Refocus the view to ensure the editor has focus
143
144
  if (editorView && !editorView.hasFocus()) {
144
145
  editorView.focus();
@@ -10,9 +10,10 @@ import { useCallback, useMemo } from 'react';
10
10
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
11
11
  import { css, jsx } from '@emotion/react';
12
12
  import { injectIntl } from 'react-intl-next';
13
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
13
+ import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
14
14
  import { Popup } from '@atlaskit/editor-common/ui';
15
15
  import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
16
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
16
17
  import { getNextBreakoutMode, getTitle } from '@atlaskit/editor-common/utils';
17
18
  import GrowHorizontalIcon from '@atlaskit/icon/core/migration/grow-horizontal--editor-expand';
18
19
  import ShrinkHorizontalIcon from '@atlaskit/icon/core/migration/shrink-horizontal--editor-collapse';
@@ -73,6 +74,21 @@ export var LayoutButton = function LayoutButton(_ref) {
73
74
  })
74
75
  }));
75
76
  };
77
+ var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
78
+ var layout = useSharedPluginStateSelector(pluginInjectionApi, 'card.layout');
79
+ var datasourceTableRef = useSharedPluginStateSelector(pluginInjectionApi, 'card.datasourceTableRef');
80
+ return {
81
+ layout: layout,
82
+ datasourceTableRef: datasourceTableRef
83
+ };
84
+ }, function (pluginInjectionApi) {
85
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['card']),
86
+ cardState = _useSharedPluginState.cardState;
87
+ return {
88
+ layout: cardState === null || cardState === void 0 ? void 0 : cardState.layout,
89
+ datasourceTableRef: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceTableRef
90
+ };
91
+ });
76
92
  var LayoutButtonWrapper = function LayoutButtonWrapper(_ref2) {
77
93
  var _node$attrs;
78
94
  var editorView = _ref2.editorView,
@@ -81,22 +97,17 @@ var LayoutButtonWrapper = function LayoutButtonWrapper(_ref2) {
81
97
  boundariesElement = _ref2.boundariesElement,
82
98
  intl = _ref2.intl,
83
99
  api = _ref2.api;
84
- var _useSharedPluginState = useSharedPluginState(api, ['card']),
85
- cardState = _useSharedPluginState.cardState;
86
100
  var _getDatasource = getDatasource(editorView),
87
101
  node = _getDatasource.node,
88
102
  pos = _getDatasource.pos;
103
+ var _useSharedState = useSharedState(api),
104
+ _useSharedState$layou = _useSharedState.layout,
105
+ layout = _useSharedState$layou === void 0 ? (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) || undefined : _useSharedState$layou,
106
+ datasourceTableRef = _useSharedState.datasourceTableRef;
89
107
  var isDatasource = isDatasourceNode(node);
90
108
  if (!isDatasource) {
91
109
  return null;
92
110
  }
93
-
94
- // If layout doesn't exist in ADF it returns null, we want to change to undefined
95
- // which results in default parameter value being used in LayoutButton.
96
- var _ref3 = cardState !== null && cardState !== void 0 ? cardState : {},
97
- datasourceTableRef = _ref3.datasourceTableRef,
98
- _ref3$layout = _ref3.layout,
99
- layout = _ref3$layout === void 0 ? (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) || undefined : _ref3$layout;
100
111
  var onLayoutChange = function onLayoutChange(layout) {
101
112
  var _getDatasource$node;
102
113
  if (pos === undefined) {
@@ -315,6 +315,30 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
315
315
  type: 'separator'
316
316
  }] : [];
317
317
  var openLinkInputMethod = fg('platform_editor_controls_patch_analytics') ? INPUT_METHOD.FLOATING_TB : INPUT_METHOD.TOOLBAR;
318
+ var editButtonItems = cardOptions.allowDatasource && fg('platform_editor_controls_patch_9') ? [{
319
+ type: 'custom',
320
+ fallback: [],
321
+ render: function render(editorView) {
322
+ return /*#__PURE__*/React.createElement(EditToolbarButton, {
323
+ key: "edit-toolbar-item",
324
+ url: url,
325
+ intl: intl,
326
+ editorAnalyticsApi: editorAnalyticsApi,
327
+ editorView: editorView,
328
+ onLinkEditClick: getEditLinkCallback(editorAnalyticsApi, true),
329
+ currentAppearance: currentAppearance
330
+ });
331
+ }
332
+ }] : [{
333
+ id: 'editor.link.edit',
334
+ type: 'button',
335
+ selected: false,
336
+ metadata: metadata,
337
+ title: intl.formatMessage(linkToolbarMessages.editLink),
338
+ icon: EditIcon,
339
+ testId: 'link-toolbar-edit-link-button',
340
+ onClick: getEditLinkCallback(editorAnalyticsApi, true)
341
+ }];
318
342
  var toolbarItems = editorExperiment('platform_editor_controls', 'control') ? [].concat(editItems, commentItems, [_objectSpread({
319
343
  id: 'editor.link.openLink',
320
344
  type: 'button',
@@ -353,16 +377,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
353
377
  onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, false),
354
378
  title: intl.formatMessage(commonMessages.remove),
355
379
  onClick: withToolbarMetadata(removeCard(editorAnalyticsApi))
356
- }]) : [{
357
- id: 'editor.link.edit',
358
- type: 'button',
359
- selected: false,
360
- metadata: metadata,
361
- title: intl.formatMessage(linkToolbarMessages.editLink),
362
- icon: EditIcon,
363
- testId: 'link-toolbar-edit-link-button',
364
- onClick: getEditLinkCallback(editorAnalyticsApi, true)
365
- }].concat(_toConsumableArray(fg('platform_editor_controls_patch_6') ? [] : [{
380
+ }]) : [].concat(editButtonItems, _toConsumableArray(fg('platform_editor_controls_patch_6') ? [] : [{
366
381
  type: 'separator'
367
382
  }]), _toConsumableArray(getUnlinkButtonGroup(state, intl, node, inlineCard, editorAnalyticsApi)), [_objectSpread({
368
383
  id: 'editor.link.openLink',