@atlaskit/editor-plugin-card 12.3.17 → 12.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 12.3.18
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8d4d473fe4cd8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8d4d473fe4cd8) -
8
+ Only reload cached smartlinks when the url changes and we sucessfully got the data from cache
9
+ - Updated dependencies
10
+
3
11
  ## 12.3.17
4
12
 
5
13
  ### Patch Changes
@@ -16,7 +16,6 @@ var _analytics = require("@atlaskit/editor-common/analytics");
16
16
  var _hooks = require("@atlaskit/editor-common/hooks");
17
17
  var _ui = require("@atlaskit/editor-common/ui");
18
18
  var _smartCard = require("@atlaskit/smart-card");
19
- var _hooks2 = require("@atlaskit/smart-card/hooks");
20
19
  var _ssr = require("@atlaskit/smart-card/ssr");
21
20
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
22
21
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
@@ -29,7 +28,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
29
28
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
30
29
 
31
30
  var InlineCard = exports.InlineCard = /*#__PURE__*/(0, _react.memo)(function (_ref) {
32
- var _cardContext$value3;
31
+ var _cardContext$value;
33
32
  var node = _ref.node,
34
33
  cardContext = _ref.cardContext,
35
34
  actionOptions = _ref.actionOptions,
@@ -49,9 +48,11 @@ var InlineCard = exports.InlineCard = /*#__PURE__*/(0, _react.memo)(function (_r
49
48
  data = _node$attrs.data;
50
49
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
51
50
  var refId = (0, _react.useRef)((0, _v.default)());
52
- var reload = (0, _hooks2.useSmartLinkReload)({
53
- url: url
54
- });
51
+ var _ref2 = (cardContext === null || cardContext === void 0 || (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store) || {},
52
+ getSmartlinkState = _ref2.getState;
53
+ var cardState = getSmartlinkState === null || getSmartlinkState === void 0 ? void 0 : getSmartlinkState()[url || ''];
54
+ var cardStatus = cardState === null || cardState === void 0 ? void 0 : cardState.status;
55
+ (0, _hooks.useSmartCardReloadAfterCache)(url, cardStatus, isPageSSRed || false);
55
56
  (0, _react.useEffect)(function () {
56
57
  var id = refId.current;
57
58
  return function () {
@@ -62,14 +63,6 @@ var InlineCard = exports.InlineCard = /*#__PURE__*/(0, _react.memo)(function (_r
62
63
  view.dispatch(tr);
63
64
  };
64
65
  }, [getPos, view]);
65
- (0, _react.useEffect)(function () {
66
- var _cardContext$value;
67
- // if we render from cache, we want to make sure we reload the data in the background
68
- 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()[url || ''];
69
- if ((0, _expValEquals.expValEquals)('platform_editor_smartlink_local_cache', 'isEnabled', true) && !isPageSSRed && (cardState === null || cardState === void 0 ? void 0 : cardState.status) === 'resolved') {
70
- reload();
71
- }
72
- });
73
66
  var scrollContainer = (0, _react.useMemo)(
74
67
  // Ignored via go/ees005
75
68
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
@@ -114,8 +107,8 @@ var InlineCard = exports.InlineCard = /*#__PURE__*/(0, _react.memo)(function (_r
114
107
  var handleOnClick = (0, _react.useCallback)(function (event) {
115
108
  if (event.metaKey || event.ctrlKey) {
116
109
  var _pluginInjectionApi$a;
117
- var _ref2 = (_pluginInjectionApi$a = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.analytics) !== null && _pluginInjectionApi$a !== void 0 ? _pluginInjectionApi$a : {},
118
- editorAnalyticsApi = _ref2.actions;
110
+ var _ref3 = (_pluginInjectionApi$a = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.analytics) !== null && _pluginInjectionApi$a !== void 0 ? _pluginInjectionApi$a : {},
111
+ editorAnalyticsApi = _ref3.actions;
119
112
  (0, _toolbar.visitCardLinkAnalytics)(editorAnalyticsApi, _analytics.INPUT_METHOD.META_CLICK)(view.state, view.dispatch);
120
113
  window.open(url, '_blank');
121
114
  } else {
@@ -125,9 +118,7 @@ var InlineCard = exports.InlineCard = /*#__PURE__*/(0, _react.memo)(function (_r
125
118
  }, [propsOnClick, url, view, pluginInjectionApi]);
126
119
  var onClick = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? handleOnClick : propsOnClick;
127
120
  var card = (0, _react.useMemo)(function () {
128
- var _cardContext$value2;
129
- var cardState = cardContext === null || cardContext === void 0 || (_cardContext$value2 = cardContext.value) === null || _cardContext$value2 === void 0 || (_cardContext$value2 = _cardContext$value2.store) === null || _cardContext$value2 === void 0 ? void 0 : _cardContext$value2.getState()[url || ''];
130
- if ((isPageSSRed || (0, _expValEquals.expValEquals)('platform_editor_smartlink_local_cache', 'isEnabled', true) && cardState) && url) {
121
+ if ((isPageSSRed || cardState && (0, _expValEquals.expValEquals)('platform_editor_smartlink_local_cache', 'isEnabled', true)) && url) {
131
122
  return /*#__PURE__*/_react.default.createElement(_ssr.CardSSR, {
132
123
  key: url,
133
124
  url: url,
@@ -160,7 +151,7 @@ var InlineCard = exports.InlineCard = /*#__PURE__*/(0, _react.memo)(function (_r
160
151
  hoverPreviewOptions: hoverPreviewOptions,
161
152
  disablePreviewPanel: disablePreviewPanel
162
153
  });
163
- }, [url, data, onClick, scrollContainer, onResolve, onError, useAlternativePreloader, actionOptions, isHovered, showHoverPreview, hoverPreviewOptions, isPageSSRed, disablePreviewPanel, cardContext === null || cardContext === void 0 || (_cardContext$value3 = cardContext.value) === null || _cardContext$value3 === void 0 ? void 0 : _cardContext$value3.store]);
154
+ }, [url, data, onClick, scrollContainer, onResolve, onError, useAlternativePreloader, actionOptions, isHovered, showHoverPreview, hoverPreviewOptions, isPageSSRed, disablePreviewPanel, cardState]);
164
155
 
165
156
  // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
166
157
  // otherwise if we got data, we can render the card directly since it doesn't need the Provider
@@ -217,8 +208,8 @@ function InlineCardNodeView(props) {
217
208
  // eslint-disable-next-line react/jsx-props-no-spreading
218
209
  }, enableInlineUpgradeFeatures && (0, _utils.getAwarenessProps)(view.state, getPos, allowEmbeds, allowBlockCards, mode === 'view'))), CompetitorPromptComponent);
219
210
  }
220
- var inlineCardNodeView = exports.inlineCardNodeView = function inlineCardNodeView(_ref3) {
221
- var inlineCardViewProducer = _ref3.inlineCardViewProducer;
211
+ var inlineCardNodeView = exports.inlineCardNodeView = function inlineCardNodeView(_ref4) {
212
+ var inlineCardViewProducer = _ref4.inlineCardViewProducer;
222
213
  return function (node, view, getPos, decorations) {
223
214
  return inlineCardViewProducer(node, view, getPos, decorations);
224
215
  };
@@ -4,10 +4,9 @@ import rafSchedule from 'raf-schd';
4
4
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
5
5
  import uuid from 'uuid/v4';
6
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
7
+ import { useSharedPluginStateWithSelector, useSmartCardReloadAfterCache } from '@atlaskit/editor-common/hooks';
8
8
  import { UnsupportedInline, findOverflowScrollParent } from '@atlaskit/editor-common/ui';
9
9
  import { Card as SmartCard } from '@atlaskit/smart-card';
10
- import { useSmartLinkReload } from '@atlaskit/smart-card/hooks';
11
10
  import { CardSSR } from '@atlaskit/smart-card/ssr';
12
11
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
12
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -32,16 +31,19 @@ export const InlineCard = /*#__PURE__*/memo(({
32
31
  pluginInjectionApi,
33
32
  disablePreviewPanel
34
33
  }) => {
35
- var _cardContext$value3;
34
+ var _cardContext$value;
36
35
  const {
37
36
  url,
38
37
  data
39
38
  } = node.attrs;
40
39
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
41
40
  const refId = useRef(uuid());
42
- const reload = useSmartLinkReload({
43
- url
44
- });
41
+ const {
42
+ getState: getSmartlinkState
43
+ } = (cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store) || {};
44
+ const cardState = getSmartlinkState === null || getSmartlinkState === void 0 ? void 0 : getSmartlinkState()[url || ''];
45
+ const cardStatus = cardState === null || cardState === void 0 ? void 0 : cardState.status;
46
+ useSmartCardReloadAfterCache(url, cardStatus, isPageSSRed || false);
45
47
  useEffect(() => {
46
48
  const id = refId.current;
47
49
  return () => {
@@ -54,14 +56,6 @@ export const InlineCard = /*#__PURE__*/memo(({
54
56
  view.dispatch(tr);
55
57
  };
56
58
  }, [getPos, view]);
57
- useEffect(() => {
58
- var _cardContext$value, _cardContext$value$st;
59
- // if we render from cache, we want to make sure we reload the data in the background
60
- 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()[url || ''];
61
- if (expValEquals('platform_editor_smartlink_local_cache', 'isEnabled', true) && !isPageSSRed && (cardState === null || cardState === void 0 ? void 0 : cardState.status) === 'resolved') {
62
- reload();
63
- }
64
- });
65
59
  const scrollContainer = useMemo(
66
60
  // Ignored via go/ees005
67
61
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
@@ -120,9 +114,7 @@ export const InlineCard = /*#__PURE__*/memo(({
120
114
  }, [propsOnClick, url, view, pluginInjectionApi]);
121
115
  const onClick = editorExperiment('platform_editor_controls', 'variant1') ? handleOnClick : propsOnClick;
122
116
  const card = useMemo(() => {
123
- var _cardContext$value2, _cardContext$value2$s;
124
- const cardState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value2 = cardContext.value) === null || _cardContext$value2 === void 0 ? void 0 : (_cardContext$value2$s = _cardContext$value2.store) === null || _cardContext$value2$s === void 0 ? void 0 : _cardContext$value2$s.getState()[url || ''];
125
- if ((isPageSSRed || expValEquals('platform_editor_smartlink_local_cache', 'isEnabled', true) && cardState) && url) {
117
+ if ((isPageSSRed || cardState && expValEquals('platform_editor_smartlink_local_cache', 'isEnabled', true)) && url) {
126
118
  return /*#__PURE__*/React.createElement(CardSSR, {
127
119
  key: url,
128
120
  url: url,
@@ -155,7 +147,7 @@ export const InlineCard = /*#__PURE__*/memo(({
155
147
  hoverPreviewOptions: hoverPreviewOptions,
156
148
  disablePreviewPanel: disablePreviewPanel
157
149
  });
158
- }, [url, data, onClick, scrollContainer, onResolve, onError, useAlternativePreloader, actionOptions, isHovered, showHoverPreview, hoverPreviewOptions, isPageSSRed, disablePreviewPanel, cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$value3 = cardContext.value) === null || _cardContext$value3 === void 0 ? void 0 : _cardContext$value3.store]);
150
+ }, [url, data, onClick, scrollContainer, onResolve, onError, useAlternativePreloader, actionOptions, isHovered, showHoverPreview, hoverPreviewOptions, isPageSSRed, disablePreviewPanel, cardState]);
159
151
 
160
152
  // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
161
153
  // otherwise if we got data, we can render the card directly since it doesn't need the Provider
@@ -4,10 +4,9 @@ import rafSchedule from 'raf-schd';
4
4
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
5
5
  import uuid from 'uuid/v4';
6
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
7
+ import { useSharedPluginStateWithSelector, useSmartCardReloadAfterCache } from '@atlaskit/editor-common/hooks';
8
8
  import { UnsupportedInline, findOverflowScrollParent } from '@atlaskit/editor-common/ui';
9
9
  import { Card as SmartCard } from '@atlaskit/smart-card';
10
- import { useSmartLinkReload } from '@atlaskit/smart-card/hooks';
11
10
  import { CardSSR } from '@atlaskit/smart-card/ssr';
12
11
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
12
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -17,7 +16,7 @@ import { visitCardLinkAnalytics } from '../ui/toolbar';
17
16
  import { Card } from './genericCard';
18
17
  import { InlineCardWithAwareness } from './inlineCardWithAwareness';
19
18
  export var InlineCard = /*#__PURE__*/memo(function (_ref) {
20
- var _cardContext$value3;
19
+ var _cardContext$value;
21
20
  var node = _ref.node,
22
21
  cardContext = _ref.cardContext,
23
22
  actionOptions = _ref.actionOptions,
@@ -37,9 +36,11 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
37
36
  data = _node$attrs.data;
38
37
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
39
38
  var refId = useRef(uuid());
40
- var reload = useSmartLinkReload({
41
- url: url
42
- });
39
+ var _ref2 = (cardContext === null || cardContext === void 0 || (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store) || {},
40
+ getSmartlinkState = _ref2.getState;
41
+ var cardState = getSmartlinkState === null || getSmartlinkState === void 0 ? void 0 : getSmartlinkState()[url || ''];
42
+ var cardStatus = cardState === null || cardState === void 0 ? void 0 : cardState.status;
43
+ useSmartCardReloadAfterCache(url, cardStatus, isPageSSRed || false);
43
44
  useEffect(function () {
44
45
  var id = refId.current;
45
46
  return function () {
@@ -50,14 +51,6 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
50
51
  view.dispatch(tr);
51
52
  };
52
53
  }, [getPos, view]);
53
- useEffect(function () {
54
- var _cardContext$value;
55
- // if we render from cache, we want to make sure we reload the data in the background
56
- 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()[url || ''];
57
- if (expValEquals('platform_editor_smartlink_local_cache', 'isEnabled', true) && !isPageSSRed && (cardState === null || cardState === void 0 ? void 0 : cardState.status) === 'resolved') {
58
- reload();
59
- }
60
- });
61
54
  var scrollContainer = useMemo(
62
55
  // Ignored via go/ees005
63
56
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
@@ -102,8 +95,8 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
102
95
  var handleOnClick = useCallback(function (event) {
103
96
  if (event.metaKey || event.ctrlKey) {
104
97
  var _pluginInjectionApi$a;
105
- var _ref2 = (_pluginInjectionApi$a = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.analytics) !== null && _pluginInjectionApi$a !== void 0 ? _pluginInjectionApi$a : {},
106
- editorAnalyticsApi = _ref2.actions;
98
+ var _ref3 = (_pluginInjectionApi$a = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.analytics) !== null && _pluginInjectionApi$a !== void 0 ? _pluginInjectionApi$a : {},
99
+ editorAnalyticsApi = _ref3.actions;
107
100
  visitCardLinkAnalytics(editorAnalyticsApi, INPUT_METHOD.META_CLICK)(view.state, view.dispatch);
108
101
  window.open(url, '_blank');
109
102
  } else {
@@ -113,9 +106,7 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
113
106
  }, [propsOnClick, url, view, pluginInjectionApi]);
114
107
  var onClick = editorExperiment('platform_editor_controls', 'variant1') ? handleOnClick : propsOnClick;
115
108
  var card = useMemo(function () {
116
- var _cardContext$value2;
117
- var cardState = cardContext === null || cardContext === void 0 || (_cardContext$value2 = cardContext.value) === null || _cardContext$value2 === void 0 || (_cardContext$value2 = _cardContext$value2.store) === null || _cardContext$value2 === void 0 ? void 0 : _cardContext$value2.getState()[url || ''];
118
- if ((isPageSSRed || expValEquals('platform_editor_smartlink_local_cache', 'isEnabled', true) && cardState) && url) {
109
+ if ((isPageSSRed || cardState && expValEquals('platform_editor_smartlink_local_cache', 'isEnabled', true)) && url) {
119
110
  return /*#__PURE__*/React.createElement(CardSSR, {
120
111
  key: url,
121
112
  url: url,
@@ -148,7 +139,7 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
148
139
  hoverPreviewOptions: hoverPreviewOptions,
149
140
  disablePreviewPanel: disablePreviewPanel
150
141
  });
151
- }, [url, data, onClick, scrollContainer, onResolve, onError, useAlternativePreloader, actionOptions, isHovered, showHoverPreview, hoverPreviewOptions, isPageSSRed, disablePreviewPanel, cardContext === null || cardContext === void 0 || (_cardContext$value3 = cardContext.value) === null || _cardContext$value3 === void 0 ? void 0 : _cardContext$value3.store]);
142
+ }, [url, data, onClick, scrollContainer, onResolve, onError, useAlternativePreloader, actionOptions, isHovered, showHoverPreview, hoverPreviewOptions, isPageSSRed, disablePreviewPanel, cardState]);
152
143
 
153
144
  // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
154
145
  // otherwise if we got data, we can render the card directly since it doesn't need the Provider
@@ -205,8 +196,8 @@ export function InlineCardNodeView(props) {
205
196
  // eslint-disable-next-line react/jsx-props-no-spreading
206
197
  }, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards, mode === 'view'))), CompetitorPromptComponent);
207
198
  }
208
- export var inlineCardNodeView = function inlineCardNodeView(_ref3) {
209
- var inlineCardViewProducer = _ref3.inlineCardViewProducer;
199
+ export var inlineCardNodeView = function inlineCardNodeView(_ref4) {
200
+ var inlineCardViewProducer = _ref4.inlineCardViewProducer;
210
201
  return function (node, view, getPos, decorations) {
211
202
  return inlineCardViewProducer(node, view, getPos, decorations);
212
203
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "12.3.17",
3
+ "version": "12.3.18",
4
4
  "description": "Card plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "atlaskit:src": "src/index.ts",
31
31
  "dependencies": {
32
- "@atlaskit/adf-schema": "^52.0.0",
32
+ "@atlaskit/adf-schema": "^52.1.0",
33
33
  "@atlaskit/analytics-next": "^11.1.0",
34
34
  "@atlaskit/custom-steps": "^0.16.0",
35
35
  "@atlaskit/editor-plugin-analytics": "^7.0.0",
@@ -61,7 +61,7 @@
61
61
  "@atlaskit/prosemirror-history": "^0.2.0",
62
62
  "@atlaskit/smart-card": "^43.25.0",
63
63
  "@atlaskit/theme": "^21.0.0",
64
- "@atlaskit/tmp-editor-statsig": "^32.0.0",
64
+ "@atlaskit/tmp-editor-statsig": "^32.5.0",
65
65
  "@atlaskit/tokens": "^11.0.0",
66
66
  "@babel/runtime": "^7.0.0",
67
67
  "@emotion/react": "^11.7.1",
@@ -71,7 +71,7 @@
71
71
  "uuid": "^3.1.0"
72
72
  },
73
73
  "peerDependencies": {
74
- "@atlaskit/editor-common": "^111.20.0",
74
+ "@atlaskit/editor-common": "^111.23.0",
75
75
  "@atlaskit/link-provider": "^4.2.0",
76
76
  "react": "^18.2.0",
77
77
  "react-intl-next": "npm:react-intl@^5.18.1"