@atlaskit/editor-synced-block-renderer 5.9.4 → 5.9.5

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-synced-block-renderer
2
2
 
3
+ ## 5.9.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`6424f86f6390a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6424f86f6390a) -
8
+ Improve Synced Blocks robustness
9
+ - Updated dependencies
10
+
3
11
  ## 5.9.4
4
12
 
5
13
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "getSyncedBlockRenderer", {
15
15
  return _getSyncedBlockRenderer.getSyncedBlockRenderer;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "renderSyncedBlockContent", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _renderSyncedBlockContent.renderSyncedBlockContent;
22
+ }
23
+ });
18
24
  Object.defineProperty(exports, "useMemoizedSyncedBlockNodeComponent", {
19
25
  enumerable: true,
20
26
  get: function get() {
@@ -22,4 +28,5 @@ Object.defineProperty(exports, "useMemoizedSyncedBlockNodeComponent", {
22
28
  }
23
29
  });
24
30
  var _useSyncedBlockNodeComponent = require("./useSyncedBlockNodeComponent");
25
- var _getSyncedBlockRenderer = require("./getSyncedBlockRenderer");
31
+ var _getSyncedBlockRenderer = require("./getSyncedBlockRenderer");
32
+ var _renderSyncedBlockContent = require("./ui/renderSyncedBlockContent");
@@ -14,13 +14,14 @@ var _syncBlock = require("@atlaskit/editor-common/sync-block");
14
14
  var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
15
15
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
16
  var _AKRendererWrapper = require("./AKRendererWrapper");
17
+ var _renderSyncedBlockContent = require("./renderSyncedBlockContent");
17
18
  var _SyncedBlockErrorComponent = require("./SyncedBlockErrorComponent");
18
19
  var _SyncedBlockLoadingState = require("./SyncedBlockLoadingState");
19
20
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
20
21
  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; }
21
22
  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) { (0, _defineProperty2.default)(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; }
22
23
  var SyncedBlockNodeComponentRenderer = exports.SyncedBlockNodeComponentRenderer = function SyncedBlockNodeComponentRenderer(_ref) {
23
- var _syncBlockInstance$da4;
24
+ var _syncBlockInstance$da6;
24
25
  var nodeProps = _ref.nodeProps,
25
26
  syncBlockStoreManager = _ref.syncBlockStoreManager,
26
27
  rendererOptions = _ref.rendererOptions;
@@ -64,6 +65,34 @@ var SyncedBlockNodeComponentRenderer = exports.SyncedBlockNodeComponentRenderer
64
65
  })
65
66
  });
66
67
  }, [rendererOptions, ssrProviders]);
68
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
69
+ var _syncBlockInstance$er, _syncBlockInstance$da, _syncBlockInstance$da2;
70
+ var errorForDisplay = (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
71
+ type: _editorSyncedBlockProvider.SyncBlockError.NotFound,
72
+ reason: (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.deletionReason
73
+ } : {
74
+ type: _editorSyncedBlockProvider.SyncBlockError.Errored,
75
+ reason: !resourceId ? 'missing resource id' : "missing data for block ".concat(resourceId)
76
+ };
77
+ var result = (0, _renderSyncedBlockContent.renderSyncedBlockContent)({
78
+ syncBlockInstance: syncBlockInstance !== null && syncBlockInstance !== void 0 ? syncBlockInstance : undefined,
79
+ isLoading: isLoading,
80
+ rendererOptions: finalRendererOptions,
81
+ providerFactory: providerFactory,
82
+ reloadData: reloadData,
83
+ fireAnalyticsEvent: fireAnalyticsEvent,
84
+ resourceId: resourceId,
85
+ error: errorForDisplay
86
+ });
87
+ if (result.isSuccess) {
88
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
89
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
90
+ className: _syncBlock.SyncBlockSharedCssClassName.renderer
91
+ // eslint-disable-next-line react/jsx-props-no-spreading
92
+ }, (0, _defineProperty2.default)({}, _syncBlock.SyncBlockRendererDataAttributeName, true)), result.element);
93
+ }
94
+ return result.element;
95
+ }
67
96
  if (isLoading && !syncBlockInstance) {
68
97
  return /*#__PURE__*/_react.default.createElement(_SyncedBlockLoadingState.SyncedBlockLoadingState, null);
69
98
  }
@@ -74,16 +103,16 @@ var SyncedBlockNodeComponentRenderer = exports.SyncedBlockNodeComponentRenderer
74
103
  return /*#__PURE__*/_react.default.createElement(_SyncedBlockLoadingState.SyncedBlockLoadingState, null);
75
104
  }
76
105
  if (!resourceId || syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data) || syncBlockInstance.data.status === 'deleted') {
77
- var _syncBlockInstance$er, _syncBlockInstance$da, _syncBlockInstance$da2, _syncBlockInstance$er2, _syncBlockInstance$da3;
78
- var errorMessage = (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
106
+ var _syncBlockInstance$er2, _syncBlockInstance$da3, _syncBlockInstance$da4, _syncBlockInstance$er3, _syncBlockInstance$da5;
107
+ var errorMessage = (_syncBlockInstance$er2 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er2 !== void 0 ? _syncBlockInstance$er2 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.status) === 'deleted' ? {
79
108
  type: _editorSyncedBlockProvider.SyncBlockError.NotFound,
80
- reason: (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.deletionReason
109
+ reason: (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.deletionReason
81
110
  } : {
82
111
  type: _editorSyncedBlockProvider.SyncBlockError.Errored,
83
112
  reason: !resourceId ? 'missing resource id' : "missing data for block ".concat(resourceId)
84
113
  };
85
114
  return /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
86
- error: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? errorMessage : (_syncBlockInstance$er2 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er2 !== void 0 ? _syncBlockInstance$er2 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.status) === 'deleted' ? {
115
+ error: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? errorMessage : (_syncBlockInstance$er3 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er3 !== void 0 ? _syncBlockInstance$er3 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da5 = syncBlockInstance.data) === null || _syncBlockInstance$da5 === void 0 ? void 0 : _syncBlockInstance$da5.status) === 'deleted' ? {
87
116
  type: _editorSyncedBlockProvider.SyncBlockError.NotFound
88
117
  } : {
89
118
  type: _editorSyncedBlockProvider.SyncBlockError.Errored
@@ -94,14 +123,14 @@ var SyncedBlockNodeComponentRenderer = exports.SyncedBlockNodeComponentRenderer
94
123
  fireAnalyticsEvent: fireAnalyticsEvent
95
124
  });
96
125
  }
97
- if ((syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.status) === 'unpublished') {
98
- var _syncBlockInstance$da5;
126
+ if ((syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da6 = syncBlockInstance.data) === null || _syncBlockInstance$da6 === void 0 ? void 0 : _syncBlockInstance$da6.status) === 'unpublished') {
127
+ var _syncBlockInstance$da7;
99
128
  return /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
100
129
  error: {
101
130
  type: _editorSyncedBlockProvider.SyncBlockError.Unpublished
102
131
  },
103
132
  resourceId: syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId,
104
- sourceURL: (_syncBlockInstance$da5 = syncBlockInstance.data) === null || _syncBlockInstance$da5 === void 0 ? void 0 : _syncBlockInstance$da5.sourceURL,
133
+ sourceURL: (_syncBlockInstance$da7 = syncBlockInstance.data) === null || _syncBlockInstance$da7 === void 0 ? void 0 : _syncBlockInstance$da7.sourceURL,
105
134
  fireAnalyticsEvent: fireAnalyticsEvent
106
135
  });
107
136
  }
@@ -12,7 +12,9 @@ var _coreUtils = require("@atlaskit/editor-common/core-utils");
12
12
  var _hooks = require("@atlaskit/editor-common/hooks");
13
13
  var _syncBlock = require("@atlaskit/editor-common/sync-block");
14
14
  var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
15
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
16
  var _AKRendererWrapper = require("./AKRendererWrapper");
17
+ var _renderSyncedBlockContent = require("./renderSyncedBlockContent");
16
18
  var _SyncedBlockErrorComponent = require("./SyncedBlockErrorComponent");
17
19
  var _SyncedBlockLoadingState = require("./SyncedBlockLoadingState");
18
20
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
@@ -63,6 +65,20 @@ var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref) {
63
65
  };
64
66
  }),
65
67
  isCollabOffline = _useSharedPluginState.isCollabOffline;
68
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_5')) {
69
+ var _api$analytics2;
70
+ var result = (0, _renderSyncedBlockContent.renderSyncedBlockContent)({
71
+ syncBlockInstance: syncBlockInstance,
72
+ isLoading: isLoading,
73
+ rendererOptions: rendererOptions,
74
+ providerFactory: providerFactory,
75
+ reloadData: reloadData,
76
+ fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent,
77
+ resourceId: syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId,
78
+ isOffline: isCollabOffline
79
+ });
80
+ return result.element;
81
+ }
66
82
 
67
83
  // Show offline error only when collaboration is offline and not in SSR mode
68
84
  // In SSR, we should always attempt to render content
@@ -83,7 +99,7 @@ var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref) {
83
99
  return /*#__PURE__*/_react.default.createElement(_SyncedBlockLoadingState.SyncedBlockLoadingState, null);
84
100
  }
85
101
  if (syncBlockInstance.error || !syncBlockInstance.data || syncBlockInstance.data.status === 'deleted') {
86
- var _syncBlockInstance$er, _syncBlockInstance$da, _api$analytics2;
102
+ var _syncBlockInstance$er, _syncBlockInstance$da, _api$analytics3;
87
103
  return /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
88
104
  error: (_syncBlockInstance$er = syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
89
105
  type: _editorSyncedBlockProvider.SyncBlockError.NotFound
@@ -93,20 +109,20 @@ var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref) {
93
109
  resourceId: syncBlockInstance.resourceId,
94
110
  onRetry: reloadData,
95
111
  isLoading: isLoading,
96
- fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent
112
+ fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent
97
113
  });
98
114
  }
99
115
 
100
116
  // Check for unpublished status
101
117
  if (((_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.status) === 'unpublished') {
102
- var _syncBlockInstance$da3, _api$analytics3;
118
+ var _syncBlockInstance$da3, _api$analytics4;
103
119
  return /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
104
120
  error: {
105
121
  type: _editorSyncedBlockProvider.SyncBlockError.Unpublished
106
122
  },
107
123
  resourceId: syncBlockInstance.resourceId,
108
124
  sourceURL: (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.sourceURL,
109
- fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent
125
+ fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions.fireAnalyticsEvent
110
126
  });
111
127
  }
112
128
  var syncBlockDoc = {
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.renderSyncedBlockContent = renderSyncedBlockContent;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _coreUtils = require("@atlaskit/editor-common/core-utils");
10
+ var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
11
+ var _AKRendererWrapper = require("./AKRendererWrapper");
12
+ var _SyncedBlockErrorComponent = require("./SyncedBlockErrorComponent");
13
+ var _SyncedBlockLoadingState = require("./SyncedBlockLoadingState");
14
+ /**
15
+ * Shared rendering logic for synced block content used by both
16
+ * SyncedBlockRenderer (editor mode) and SyncedBlockNodeComponentRenderer (renderer mode).
17
+ *
18
+ * Handles the common branching: loading -> SSR error -> error/deleted -> unpublished -> success.
19
+ * Returns null if the caller should handle rendering itself (e.g. wrapping in a container div).
20
+ */
21
+ function renderSyncedBlockContent(_ref) {
22
+ var _syncBlockInstance$da2;
23
+ var syncBlockInstance = _ref.syncBlockInstance,
24
+ isLoading = _ref.isLoading,
25
+ rendererOptions = _ref.rendererOptions,
26
+ providerFactory = _ref.providerFactory,
27
+ reloadData = _ref.reloadData,
28
+ fireAnalyticsEvent = _ref.fireAnalyticsEvent,
29
+ resourceId = _ref.resourceId,
30
+ isOffline = _ref.isOffline,
31
+ error = _ref.error;
32
+ var isSSRMode = (0, _coreUtils.isSSR)();
33
+ if (isOffline && !isSSRMode) {
34
+ return {
35
+ element: /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
36
+ error: {
37
+ type: _editorSyncedBlockProvider.SyncBlockError.Offline
38
+ }
39
+ }),
40
+ isSuccess: false
41
+ };
42
+ }
43
+ if (isLoading && !syncBlockInstance) {
44
+ return {
45
+ element: /*#__PURE__*/_react.default.createElement(_SyncedBlockLoadingState.SyncedBlockLoadingState, null),
46
+ isSuccess: false
47
+ };
48
+ }
49
+ if (isSSRMode && syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error) {
50
+ return {
51
+ element: /*#__PURE__*/_react.default.createElement(_SyncedBlockLoadingState.SyncedBlockLoadingState, null),
52
+ isSuccess: false
53
+ };
54
+ }
55
+ if (!resourceId || syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data) || syncBlockInstance.data.status === 'deleted') {
56
+ var _ref2, _syncBlockInstance$da;
57
+ var errorToDisplay = (_ref2 = error !== null && error !== void 0 ? error : syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _ref2 !== void 0 ? _ref2 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
58
+ type: _editorSyncedBlockProvider.SyncBlockError.NotFound
59
+ } : {
60
+ type: _editorSyncedBlockProvider.SyncBlockError.Errored
61
+ };
62
+ return {
63
+ element: /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
64
+ error: errorToDisplay,
65
+ resourceId: resourceId,
66
+ onRetry: reloadData,
67
+ isLoading: isLoading,
68
+ fireAnalyticsEvent: fireAnalyticsEvent
69
+ }),
70
+ isSuccess: false
71
+ };
72
+ }
73
+ if ((syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.status) === 'unpublished') {
74
+ var _syncBlockInstance$da3;
75
+ return {
76
+ element: /*#__PURE__*/_react.default.createElement(_SyncedBlockErrorComponent.SyncedBlockErrorComponent, {
77
+ error: {
78
+ type: _editorSyncedBlockProvider.SyncBlockError.Unpublished
79
+ },
80
+ resourceId: resourceId,
81
+ sourceURL: (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.sourceURL,
82
+ fireAnalyticsEvent: fireAnalyticsEvent
83
+ }),
84
+ isSuccess: false
85
+ };
86
+ }
87
+ var syncBlockDoc = {
88
+ content: syncBlockInstance.data.content,
89
+ version: 1,
90
+ type: 'doc'
91
+ };
92
+ return {
93
+ element: /*#__PURE__*/_react.default.createElement(_AKRendererWrapper.AKRendererWrapper, {
94
+ doc: syncBlockDoc,
95
+ dataProviders: providerFactory,
96
+ options: rendererOptions
97
+ }),
98
+ isSuccess: true
99
+ };
100
+ }
@@ -1,3 +1,4 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
2
  export { getSyncBlockNodesFromDoc, useMemoizedSyncedBlockNodeComponent } from './useSyncedBlockNodeComponent';
3
- export { getSyncedBlockRenderer } from './getSyncedBlockRenderer';
3
+ export { getSyncedBlockRenderer } from './getSyncedBlockRenderer';
4
+ export { renderSyncedBlockContent } from './ui/renderSyncedBlockContent';
@@ -4,6 +4,7 @@ import { SyncBlockSharedCssClassName, SyncBlockRendererDataAttributeName, handle
4
4
  import { SyncBlockError, useFetchSyncBlockData } from '@atlaskit/editor-synced-block-provider';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
6
  import { AKRendererWrapper } from './AKRendererWrapper';
7
+ import { renderSyncedBlockContent } from './renderSyncedBlockContent';
7
8
  import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
8
9
  import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
9
10
  export const SyncedBlockNodeComponentRenderer = ({
@@ -11,7 +12,7 @@ export const SyncedBlockNodeComponentRenderer = ({
11
12
  syncBlockStoreManager,
12
13
  rendererOptions
13
14
  }) => {
14
- var _syncBlockInstance$da4;
15
+ var _syncBlockInstance$da6;
15
16
  const {
16
17
  resourceId,
17
18
  localId,
@@ -57,6 +58,36 @@ export const SyncedBlockNodeComponentRenderer = ({
57
58
  }
58
59
  };
59
60
  }, [rendererOptions, ssrProviders]);
61
+ if (fg('platform_synced_block_patch_5')) {
62
+ var _syncBlockInstance$er, _syncBlockInstance$da, _syncBlockInstance$da2;
63
+ const errorForDisplay = (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
64
+ type: SyncBlockError.NotFound,
65
+ reason: (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.deletionReason
66
+ } : {
67
+ type: SyncBlockError.Errored,
68
+ reason: !resourceId ? 'missing resource id' : `missing data for block ${resourceId}`
69
+ };
70
+ const result = renderSyncedBlockContent({
71
+ syncBlockInstance: syncBlockInstance !== null && syncBlockInstance !== void 0 ? syncBlockInstance : undefined,
72
+ isLoading,
73
+ rendererOptions: finalRendererOptions,
74
+ providerFactory,
75
+ reloadData,
76
+ fireAnalyticsEvent,
77
+ resourceId,
78
+ error: errorForDisplay
79
+ });
80
+ if (result.isSuccess) {
81
+ return /*#__PURE__*/React.createElement("div", {
82
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
83
+ className: SyncBlockSharedCssClassName.renderer
84
+ // eslint-disable-next-line react/jsx-props-no-spreading
85
+ ,
86
+ [SyncBlockRendererDataAttributeName]: true
87
+ }, result.element);
88
+ }
89
+ return result.element;
90
+ }
60
91
  if (isLoading && !syncBlockInstance) {
61
92
  return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
62
93
  }
@@ -67,16 +98,16 @@ export const SyncedBlockNodeComponentRenderer = ({
67
98
  return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
68
99
  }
69
100
  if (!resourceId || syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data) || syncBlockInstance.data.status === 'deleted') {
70
- var _syncBlockInstance$er, _syncBlockInstance$da, _syncBlockInstance$da2, _syncBlockInstance$er2, _syncBlockInstance$da3;
71
- const errorMessage = (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
101
+ var _syncBlockInstance$er2, _syncBlockInstance$da3, _syncBlockInstance$da4, _syncBlockInstance$er3, _syncBlockInstance$da5;
102
+ const errorMessage = (_syncBlockInstance$er2 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er2 !== void 0 ? _syncBlockInstance$er2 : (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.status) === 'deleted' ? {
72
103
  type: SyncBlockError.NotFound,
73
- reason: (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.deletionReason
104
+ reason: (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.deletionReason
74
105
  } : {
75
106
  type: SyncBlockError.Errored,
76
107
  reason: !resourceId ? 'missing resource id' : `missing data for block ${resourceId}`
77
108
  };
78
109
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
79
- error: fg('platform_synced_block_patch_3') ? errorMessage : (_syncBlockInstance$er2 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er2 !== void 0 ? _syncBlockInstance$er2 : (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.status) === 'deleted' ? {
110
+ error: fg('platform_synced_block_patch_3') ? errorMessage : (_syncBlockInstance$er3 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er3 !== void 0 ? _syncBlockInstance$er3 : (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da5 = syncBlockInstance.data) === null || _syncBlockInstance$da5 === void 0 ? void 0 : _syncBlockInstance$da5.status) === 'deleted' ? {
80
111
  type: SyncBlockError.NotFound
81
112
  } : {
82
113
  type: SyncBlockError.Errored
@@ -87,14 +118,14 @@ export const SyncedBlockNodeComponentRenderer = ({
87
118
  fireAnalyticsEvent: fireAnalyticsEvent
88
119
  });
89
120
  }
90
- if ((syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.status) === 'unpublished') {
91
- var _syncBlockInstance$da5;
121
+ if ((syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da6 = syncBlockInstance.data) === null || _syncBlockInstance$da6 === void 0 ? void 0 : _syncBlockInstance$da6.status) === 'unpublished') {
122
+ var _syncBlockInstance$da7;
92
123
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
93
124
  error: {
94
125
  type: SyncBlockError.Unpublished
95
126
  },
96
127
  resourceId: syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId,
97
- sourceURL: (_syncBlockInstance$da5 = syncBlockInstance.data) === null || _syncBlockInstance$da5 === void 0 ? void 0 : _syncBlockInstance$da5.sourceURL,
128
+ sourceURL: (_syncBlockInstance$da7 = syncBlockInstance.data) === null || _syncBlockInstance$da7 === void 0 ? void 0 : _syncBlockInstance$da7.sourceURL,
98
129
  fireAnalyticsEvent: fireAnalyticsEvent
99
130
  });
100
131
  }
@@ -3,7 +3,9 @@ import { isSSR } from '@atlaskit/editor-common/core-utils';
3
3
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
4
  import { handleSSRErrorsAnalytics } from '@atlaskit/editor-common/sync-block';
5
5
  import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { AKRendererWrapper } from './AKRendererWrapper';
8
+ import { renderSyncedBlockContent } from './renderSyncedBlockContent';
7
9
  import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
8
10
  import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
9
11
  const SyncedBlockRendererComponent = ({
@@ -56,6 +58,20 @@ const SyncedBlockRendererComponent = ({
56
58
  }) => ({
57
59
  isCollabOffline: (connectivityState === null || connectivityState === void 0 ? void 0 : connectivityState.mode) === 'collab-offline'
58
60
  }));
61
+ if (fg('platform_synced_block_patch_5')) {
62
+ var _api$analytics2;
63
+ const result = renderSyncedBlockContent({
64
+ syncBlockInstance,
65
+ isLoading,
66
+ rendererOptions,
67
+ providerFactory,
68
+ reloadData,
69
+ fireAnalyticsEvent: api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent,
70
+ resourceId: syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId,
71
+ isOffline: isCollabOffline
72
+ });
73
+ return result.element;
74
+ }
59
75
 
60
76
  // Show offline error only when collaboration is offline and not in SSR mode
61
77
  // In SSR, we should always attempt to render content
@@ -76,7 +92,7 @@ const SyncedBlockRendererComponent = ({
76
92
  return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
77
93
  }
78
94
  if (syncBlockInstance.error || !syncBlockInstance.data || syncBlockInstance.data.status === 'deleted') {
79
- var _syncBlockInstance$er, _syncBlockInstance$da, _api$analytics2;
95
+ var _syncBlockInstance$er, _syncBlockInstance$da, _api$analytics3;
80
96
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
81
97
  error: (_syncBlockInstance$er = syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
82
98
  type: SyncBlockError.NotFound
@@ -86,20 +102,20 @@ const SyncedBlockRendererComponent = ({
86
102
  resourceId: syncBlockInstance.resourceId,
87
103
  onRetry: reloadData,
88
104
  isLoading: isLoading,
89
- fireAnalyticsEvent: api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent
105
+ fireAnalyticsEvent: api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent
90
106
  });
91
107
  }
92
108
 
93
109
  // Check for unpublished status
94
110
  if (((_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.status) === 'unpublished') {
95
- var _syncBlockInstance$da3, _api$analytics3;
111
+ var _syncBlockInstance$da3, _api$analytics4;
96
112
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
97
113
  error: {
98
114
  type: SyncBlockError.Unpublished
99
115
  },
100
116
  resourceId: syncBlockInstance.resourceId,
101
117
  sourceURL: (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.sourceURL,
102
- fireAnalyticsEvent: api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent
118
+ fireAnalyticsEvent: api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions.fireAnalyticsEvent
103
119
  });
104
120
  }
105
121
  const syncBlockDoc = {
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import { isSSR } from '@atlaskit/editor-common/core-utils';
3
+ import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
4
+ import { AKRendererWrapper } from './AKRendererWrapper';
5
+ import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
6
+ import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
7
+ /**
8
+ * Shared rendering logic for synced block content used by both
9
+ * SyncedBlockRenderer (editor mode) and SyncedBlockNodeComponentRenderer (renderer mode).
10
+ *
11
+ * Handles the common branching: loading -> SSR error -> error/deleted -> unpublished -> success.
12
+ * Returns null if the caller should handle rendering itself (e.g. wrapping in a container div).
13
+ */
14
+ export function renderSyncedBlockContent({
15
+ syncBlockInstance,
16
+ isLoading,
17
+ rendererOptions,
18
+ providerFactory,
19
+ reloadData,
20
+ fireAnalyticsEvent,
21
+ resourceId,
22
+ isOffline,
23
+ error
24
+ }) {
25
+ var _syncBlockInstance$da2;
26
+ const isSSRMode = isSSR();
27
+ if (isOffline && !isSSRMode) {
28
+ return {
29
+ element: /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
30
+ error: {
31
+ type: SyncBlockError.Offline
32
+ }
33
+ }),
34
+ isSuccess: false
35
+ };
36
+ }
37
+ if (isLoading && !syncBlockInstance) {
38
+ return {
39
+ element: /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null),
40
+ isSuccess: false
41
+ };
42
+ }
43
+ if (isSSRMode && syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error) {
44
+ return {
45
+ element: /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null),
46
+ isSuccess: false
47
+ };
48
+ }
49
+ if (!resourceId || syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data) || syncBlockInstance.data.status === 'deleted') {
50
+ var _ref, _syncBlockInstance$da;
51
+ const errorToDisplay = (_ref = error !== null && error !== void 0 ? error : syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _ref !== void 0 ? _ref : (syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
52
+ type: SyncBlockError.NotFound
53
+ } : {
54
+ type: SyncBlockError.Errored
55
+ };
56
+ return {
57
+ element: /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
58
+ error: errorToDisplay,
59
+ resourceId: resourceId,
60
+ onRetry: reloadData,
61
+ isLoading: isLoading,
62
+ fireAnalyticsEvent: fireAnalyticsEvent
63
+ }),
64
+ isSuccess: false
65
+ };
66
+ }
67
+ if ((syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.status) === 'unpublished') {
68
+ var _syncBlockInstance$da3;
69
+ return {
70
+ element: /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
71
+ error: {
72
+ type: SyncBlockError.Unpublished
73
+ },
74
+ resourceId: resourceId,
75
+ sourceURL: (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.sourceURL,
76
+ fireAnalyticsEvent: fireAnalyticsEvent
77
+ }),
78
+ isSuccess: false
79
+ };
80
+ }
81
+ const syncBlockDoc = {
82
+ content: syncBlockInstance.data.content,
83
+ version: 1,
84
+ type: 'doc'
85
+ };
86
+ return {
87
+ element: /*#__PURE__*/React.createElement(AKRendererWrapper, {
88
+ doc: syncBlockDoc,
89
+ dataProviders: providerFactory,
90
+ options: rendererOptions
91
+ }),
92
+ isSuccess: true
93
+ };
94
+ }
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
2
  export { getSyncBlockNodesFromDoc, useMemoizedSyncedBlockNodeComponent } from './useSyncedBlockNodeComponent';
3
- export { getSyncedBlockRenderer } from './getSyncedBlockRenderer';
3
+ export { getSyncedBlockRenderer } from './getSyncedBlockRenderer';
4
+ export { renderSyncedBlockContent } from './ui/renderSyncedBlockContent';
@@ -8,10 +8,11 @@ import { SyncBlockSharedCssClassName, SyncBlockRendererDataAttributeName, handle
8
8
  import { SyncBlockError, useFetchSyncBlockData } from '@atlaskit/editor-synced-block-provider';
9
9
  import { fg } from '@atlaskit/platform-feature-flags';
10
10
  import { AKRendererWrapper } from './AKRendererWrapper';
11
+ import { renderSyncedBlockContent } from './renderSyncedBlockContent';
11
12
  import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
12
13
  import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
13
14
  export var SyncedBlockNodeComponentRenderer = function SyncedBlockNodeComponentRenderer(_ref) {
14
- var _syncBlockInstance$da4;
15
+ var _syncBlockInstance$da6;
15
16
  var nodeProps = _ref.nodeProps,
16
17
  syncBlockStoreManager = _ref.syncBlockStoreManager,
17
18
  rendererOptions = _ref.rendererOptions;
@@ -55,6 +56,34 @@ export var SyncedBlockNodeComponentRenderer = function SyncedBlockNodeComponentR
55
56
  })
56
57
  });
57
58
  }, [rendererOptions, ssrProviders]);
59
+ if (fg('platform_synced_block_patch_5')) {
60
+ var _syncBlockInstance$er, _syncBlockInstance$da, _syncBlockInstance$da2;
61
+ var errorForDisplay = (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
62
+ type: SyncBlockError.NotFound,
63
+ reason: (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.deletionReason
64
+ } : {
65
+ type: SyncBlockError.Errored,
66
+ reason: !resourceId ? 'missing resource id' : "missing data for block ".concat(resourceId)
67
+ };
68
+ var result = renderSyncedBlockContent({
69
+ syncBlockInstance: syncBlockInstance !== null && syncBlockInstance !== void 0 ? syncBlockInstance : undefined,
70
+ isLoading: isLoading,
71
+ rendererOptions: finalRendererOptions,
72
+ providerFactory: providerFactory,
73
+ reloadData: reloadData,
74
+ fireAnalyticsEvent: fireAnalyticsEvent,
75
+ resourceId: resourceId,
76
+ error: errorForDisplay
77
+ });
78
+ if (result.isSuccess) {
79
+ return /*#__PURE__*/React.createElement("div", _extends({
80
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
81
+ className: SyncBlockSharedCssClassName.renderer
82
+ // eslint-disable-next-line react/jsx-props-no-spreading
83
+ }, _defineProperty({}, SyncBlockRendererDataAttributeName, true)), result.element);
84
+ }
85
+ return result.element;
86
+ }
58
87
  if (isLoading && !syncBlockInstance) {
59
88
  return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
60
89
  }
@@ -65,16 +94,16 @@ export var SyncedBlockNodeComponentRenderer = function SyncedBlockNodeComponentR
65
94
  return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
66
95
  }
67
96
  if (!resourceId || syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data) || syncBlockInstance.data.status === 'deleted') {
68
- var _syncBlockInstance$er, _syncBlockInstance$da, _syncBlockInstance$da2, _syncBlockInstance$er2, _syncBlockInstance$da3;
69
- var errorMessage = (_syncBlockInstance$er = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
97
+ var _syncBlockInstance$er2, _syncBlockInstance$da3, _syncBlockInstance$da4, _syncBlockInstance$er3, _syncBlockInstance$da5;
98
+ var errorMessage = (_syncBlockInstance$er2 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er2 !== void 0 ? _syncBlockInstance$er2 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.status) === 'deleted' ? {
70
99
  type: SyncBlockError.NotFound,
71
- reason: (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.deletionReason
100
+ reason: (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.deletionReason
72
101
  } : {
73
102
  type: SyncBlockError.Errored,
74
103
  reason: !resourceId ? 'missing resource id' : "missing data for block ".concat(resourceId)
75
104
  };
76
105
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
77
- error: fg('platform_synced_block_patch_3') ? errorMessage : (_syncBlockInstance$er2 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er2 !== void 0 ? _syncBlockInstance$er2 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.status) === 'deleted' ? {
106
+ error: fg('platform_synced_block_patch_3') ? errorMessage : (_syncBlockInstance$er3 = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _syncBlockInstance$er3 !== void 0 ? _syncBlockInstance$er3 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da5 = syncBlockInstance.data) === null || _syncBlockInstance$da5 === void 0 ? void 0 : _syncBlockInstance$da5.status) === 'deleted' ? {
78
107
  type: SyncBlockError.NotFound
79
108
  } : {
80
109
  type: SyncBlockError.Errored
@@ -85,14 +114,14 @@ export var SyncedBlockNodeComponentRenderer = function SyncedBlockNodeComponentR
85
114
  fireAnalyticsEvent: fireAnalyticsEvent
86
115
  });
87
116
  }
88
- if ((syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.status) === 'unpublished') {
89
- var _syncBlockInstance$da5;
117
+ if ((syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da6 = syncBlockInstance.data) === null || _syncBlockInstance$da6 === void 0 ? void 0 : _syncBlockInstance$da6.status) === 'unpublished') {
118
+ var _syncBlockInstance$da7;
90
119
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
91
120
  error: {
92
121
  type: SyncBlockError.Unpublished
93
122
  },
94
123
  resourceId: syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId,
95
- sourceURL: (_syncBlockInstance$da5 = syncBlockInstance.data) === null || _syncBlockInstance$da5 === void 0 ? void 0 : _syncBlockInstance$da5.sourceURL,
124
+ sourceURL: (_syncBlockInstance$da7 = syncBlockInstance.data) === null || _syncBlockInstance$da7 === void 0 ? void 0 : _syncBlockInstance$da7.sourceURL,
96
125
  fireAnalyticsEvent: fireAnalyticsEvent
97
126
  });
98
127
  }
@@ -6,7 +6,9 @@ import { isSSR } from '@atlaskit/editor-common/core-utils';
6
6
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
7
7
  import { handleSSRErrorsAnalytics } from '@atlaskit/editor-common/sync-block';
8
8
  import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
9
10
  import { AKRendererWrapper } from './AKRendererWrapper';
11
+ import { renderSyncedBlockContent } from './renderSyncedBlockContent';
10
12
  import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
11
13
  import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
12
14
  var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref) {
@@ -54,6 +56,20 @@ var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref) {
54
56
  };
55
57
  }),
56
58
  isCollabOffline = _useSharedPluginState.isCollabOffline;
59
+ if (fg('platform_synced_block_patch_5')) {
60
+ var _api$analytics2;
61
+ var result = renderSyncedBlockContent({
62
+ syncBlockInstance: syncBlockInstance,
63
+ isLoading: isLoading,
64
+ rendererOptions: rendererOptions,
65
+ providerFactory: providerFactory,
66
+ reloadData: reloadData,
67
+ fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent,
68
+ resourceId: syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId,
69
+ isOffline: isCollabOffline
70
+ });
71
+ return result.element;
72
+ }
57
73
 
58
74
  // Show offline error only when collaboration is offline and not in SSR mode
59
75
  // In SSR, we should always attempt to render content
@@ -74,7 +90,7 @@ var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref) {
74
90
  return /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null);
75
91
  }
76
92
  if (syncBlockInstance.error || !syncBlockInstance.data || syncBlockInstance.data.status === 'deleted') {
77
- var _syncBlockInstance$er, _syncBlockInstance$da, _api$analytics2;
93
+ var _syncBlockInstance$er, _syncBlockInstance$da, _api$analytics3;
78
94
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
79
95
  error: (_syncBlockInstance$er = syncBlockInstance.error) !== null && _syncBlockInstance$er !== void 0 ? _syncBlockInstance$er : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
80
96
  type: SyncBlockError.NotFound
@@ -84,20 +100,20 @@ var SyncedBlockRendererComponent = function SyncedBlockRendererComponent(_ref) {
84
100
  resourceId: syncBlockInstance.resourceId,
85
101
  onRetry: reloadData,
86
102
  isLoading: isLoading,
87
- fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent
103
+ fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent
88
104
  });
89
105
  }
90
106
 
91
107
  // Check for unpublished status
92
108
  if (((_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.status) === 'unpublished') {
93
- var _syncBlockInstance$da3, _api$analytics3;
109
+ var _syncBlockInstance$da3, _api$analytics4;
94
110
  return /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
95
111
  error: {
96
112
  type: SyncBlockError.Unpublished
97
113
  },
98
114
  resourceId: syncBlockInstance.resourceId,
99
115
  sourceURL: (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.sourceURL,
100
- fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.fireAnalyticsEvent
116
+ fireAnalyticsEvent: api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions.fireAnalyticsEvent
101
117
  });
102
118
  }
103
119
  var syncBlockDoc = {
@@ -0,0 +1,93 @@
1
+ import React from 'react';
2
+ import { isSSR } from '@atlaskit/editor-common/core-utils';
3
+ import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
4
+ import { AKRendererWrapper } from './AKRendererWrapper';
5
+ import { SyncedBlockErrorComponent } from './SyncedBlockErrorComponent';
6
+ import { SyncedBlockLoadingState } from './SyncedBlockLoadingState';
7
+ /**
8
+ * Shared rendering logic for synced block content used by both
9
+ * SyncedBlockRenderer (editor mode) and SyncedBlockNodeComponentRenderer (renderer mode).
10
+ *
11
+ * Handles the common branching: loading -> SSR error -> error/deleted -> unpublished -> success.
12
+ * Returns null if the caller should handle rendering itself (e.g. wrapping in a container div).
13
+ */
14
+ export function renderSyncedBlockContent(_ref) {
15
+ var _syncBlockInstance$da2;
16
+ var syncBlockInstance = _ref.syncBlockInstance,
17
+ isLoading = _ref.isLoading,
18
+ rendererOptions = _ref.rendererOptions,
19
+ providerFactory = _ref.providerFactory,
20
+ reloadData = _ref.reloadData,
21
+ fireAnalyticsEvent = _ref.fireAnalyticsEvent,
22
+ resourceId = _ref.resourceId,
23
+ isOffline = _ref.isOffline,
24
+ error = _ref.error;
25
+ var isSSRMode = isSSR();
26
+ if (isOffline && !isSSRMode) {
27
+ return {
28
+ element: /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
29
+ error: {
30
+ type: SyncBlockError.Offline
31
+ }
32
+ }),
33
+ isSuccess: false
34
+ };
35
+ }
36
+ if (isLoading && !syncBlockInstance) {
37
+ return {
38
+ element: /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null),
39
+ isSuccess: false
40
+ };
41
+ }
42
+ if (isSSRMode && syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error) {
43
+ return {
44
+ element: /*#__PURE__*/React.createElement(SyncedBlockLoadingState, null),
45
+ isSuccess: false
46
+ };
47
+ }
48
+ if (!resourceId || syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.error || !(syncBlockInstance !== null && syncBlockInstance !== void 0 && syncBlockInstance.data) || syncBlockInstance.data.status === 'deleted') {
49
+ var _ref2, _syncBlockInstance$da;
50
+ var errorToDisplay = (_ref2 = error !== null && error !== void 0 ? error : syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error) !== null && _ref2 !== void 0 ? _ref2 : (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.status) === 'deleted' ? {
51
+ type: SyncBlockError.NotFound
52
+ } : {
53
+ type: SyncBlockError.Errored
54
+ };
55
+ return {
56
+ element: /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
57
+ error: errorToDisplay,
58
+ resourceId: resourceId,
59
+ onRetry: reloadData,
60
+ isLoading: isLoading,
61
+ fireAnalyticsEvent: fireAnalyticsEvent
62
+ }),
63
+ isSuccess: false
64
+ };
65
+ }
66
+ if ((syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.status) === 'unpublished') {
67
+ var _syncBlockInstance$da3;
68
+ return {
69
+ element: /*#__PURE__*/React.createElement(SyncedBlockErrorComponent, {
70
+ error: {
71
+ type: SyncBlockError.Unpublished
72
+ },
73
+ resourceId: resourceId,
74
+ sourceURL: (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.sourceURL,
75
+ fireAnalyticsEvent: fireAnalyticsEvent
76
+ }),
77
+ isSuccess: false
78
+ };
79
+ }
80
+ var syncBlockDoc = {
81
+ content: syncBlockInstance.data.content,
82
+ version: 1,
83
+ type: 'doc'
84
+ };
85
+ return {
86
+ element: /*#__PURE__*/React.createElement(AKRendererWrapper, {
87
+ doc: syncBlockDoc,
88
+ dataProviders: providerFactory,
89
+ options: rendererOptions
90
+ }),
91
+ isSuccess: true
92
+ };
93
+ }
@@ -1,3 +1,4 @@
1
1
  export { getSyncBlockNodesFromDoc, useMemoizedSyncedBlockNodeComponent, type GetSyncedBlockNodeComponentProps, } from './useSyncedBlockNodeComponent';
2
2
  export { getSyncedBlockRenderer } from './getSyncedBlockRenderer';
3
3
  export type { SyncedBlockNodeProps } from './ui/SyncedBlockNodeComponentRenderer';
4
+ export { renderSyncedBlockContent, type RenderSyncedBlockContentParams, } from './ui/renderSyncedBlockContent';
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import type { RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
3
+ import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
4
+ import { type SyncBlockInstance } from '@atlaskit/editor-synced-block-provider';
5
+ import type { SyncedBlockRendererOptions } from '../types';
6
+ export type RenderSyncedBlockContentParams = {
7
+ error?: SyncBlockInstance['error'];
8
+ fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void;
9
+ isLoading: boolean;
10
+ isOffline?: boolean;
11
+ providerFactory: ProviderFactory | undefined;
12
+ reloadData?: () => void;
13
+ rendererOptions: SyncedBlockRendererOptions | undefined;
14
+ resourceId?: string;
15
+ syncBlockInstance: SyncBlockInstance | null | undefined;
16
+ };
17
+ /**
18
+ * Shared rendering logic for synced block content used by both
19
+ * SyncedBlockRenderer (editor mode) and SyncedBlockNodeComponentRenderer (renderer mode).
20
+ *
21
+ * Handles the common branching: loading -> SSR error -> error/deleted -> unpublished -> success.
22
+ * Returns null if the caller should handle rendering itself (e.g. wrapping in a container div).
23
+ */
24
+ export declare function renderSyncedBlockContent({ syncBlockInstance, isLoading, rendererOptions, providerFactory, reloadData, fireAnalyticsEvent, resourceId, isOffline, error, }: RenderSyncedBlockContentParams): {
25
+ element: React.JSX.Element;
26
+ isSuccess: boolean;
27
+ };
@@ -1,3 +1,4 @@
1
1
  export { getSyncBlockNodesFromDoc, useMemoizedSyncedBlockNodeComponent, type GetSyncedBlockNodeComponentProps, } from './useSyncedBlockNodeComponent';
2
2
  export { getSyncedBlockRenderer } from './getSyncedBlockRenderer';
3
3
  export type { SyncedBlockNodeProps } from './ui/SyncedBlockNodeComponentRenderer';
4
+ export { renderSyncedBlockContent, type RenderSyncedBlockContentParams, } from './ui/renderSyncedBlockContent';
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import type { RendererSyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
3
+ import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
4
+ import { type SyncBlockInstance } from '@atlaskit/editor-synced-block-provider';
5
+ import type { SyncedBlockRendererOptions } from '../types';
6
+ export type RenderSyncedBlockContentParams = {
7
+ error?: SyncBlockInstance['error'];
8
+ fireAnalyticsEvent?: (payload: RendererSyncBlockEventPayload) => void;
9
+ isLoading: boolean;
10
+ isOffline?: boolean;
11
+ providerFactory: ProviderFactory | undefined;
12
+ reloadData?: () => void;
13
+ rendererOptions: SyncedBlockRendererOptions | undefined;
14
+ resourceId?: string;
15
+ syncBlockInstance: SyncBlockInstance | null | undefined;
16
+ };
17
+ /**
18
+ * Shared rendering logic for synced block content used by both
19
+ * SyncedBlockRenderer (editor mode) and SyncedBlockNodeComponentRenderer (renderer mode).
20
+ *
21
+ * Handles the common branching: loading -> SSR error -> error/deleted -> unpublished -> success.
22
+ * Returns null if the caller should handle rendering itself (e.g. wrapping in a container div).
23
+ */
24
+ export declare function renderSyncedBlockContent({ syncBlockInstance, isLoading, rendererOptions, providerFactory, reloadData, fireAnalyticsEvent, resourceId, isOffline, error, }: RenderSyncedBlockContentParams): {
25
+ element: React.JSX.Element;
26
+ isSuccess: boolean;
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-synced-block-renderer",
3
- "version": "5.9.4",
3
+ "version": "5.9.5",
4
4
  "description": "SyncedBlockRenderer for @atlaskit/editor-plugin-synced-block",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,7 +38,7 @@
38
38
  "@atlaskit/image": "^3.0.0",
39
39
  "@atlaskit/platform-feature-flags": "^1.1.0",
40
40
  "@atlaskit/primitives": "^18.0.0",
41
- "@atlaskit/renderer": "^126.12.0",
41
+ "@atlaskit/renderer": "^126.13.0",
42
42
  "@atlaskit/spinner": "^19.0.0",
43
43
  "@atlaskit/tokens": "^11.0.0",
44
44
  "@atlaskit/tooltip": "^20.14.0",
@@ -94,6 +94,9 @@
94
94
  },
95
95
  "platform_synced_block_patch_4": {
96
96
  "type": "boolean"
97
+ },
98
+ "platform_synced_block_patch_5": {
99
+ "type": "boolean"
97
100
  }
98
101
  }
99
102
  }