@atlaskit/editor-plugin-synced-block 4.2.7 → 4.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/afm-cc/tsconfig.json +9 -0
  3. package/afm-jira/tsconfig.json +10 -1
  4. package/afm-products/tsconfig.json +9 -0
  5. package/dist/cjs/nodeviews/bodiedSyncedBlock.js +27 -5
  6. package/dist/cjs/pm-plugins/main.js +83 -39
  7. package/dist/cjs/pm-plugins/utils/ignore-dom-event.js +30 -0
  8. package/dist/cjs/pm-plugins/utils/track-sync-blocks.js +49 -1
  9. package/dist/cjs/pm-plugins/utils/utils.js +6 -2
  10. package/dist/cjs/syncedBlockPlugin.js +16 -1
  11. package/dist/cjs/types/index.js +12 -0
  12. package/dist/cjs/ui/CreateSyncedBlockButton.js +10 -5
  13. package/dist/cjs/ui/CreateSyncedBlockDropdownItem.js +13 -11
  14. package/dist/cjs/ui/CreateSyncedBlockItem.js +17 -15
  15. package/dist/cjs/ui/DeleteConfirmationModal.js +12 -2
  16. package/dist/cjs/ui/Flag.js +67 -0
  17. package/dist/cjs/ui/floating-toolbar.js +3 -2
  18. package/dist/es2019/nodeviews/bodiedSyncedBlock.js +18 -0
  19. package/dist/es2019/pm-plugins/main.js +89 -40
  20. package/dist/es2019/pm-plugins/utils/ignore-dom-event.js +26 -0
  21. package/dist/es2019/pm-plugins/utils/track-sync-blocks.js +41 -0
  22. package/dist/es2019/pm-plugins/utils/utils.js +6 -2
  23. package/dist/es2019/syncedBlockPlugin.js +18 -2
  24. package/dist/es2019/types/index.js +6 -0
  25. package/dist/es2019/ui/CreateSyncedBlockButton.js +10 -4
  26. package/dist/es2019/ui/CreateSyncedBlockDropdownItem.js +13 -11
  27. package/dist/es2019/ui/CreateSyncedBlockItem.js +18 -14
  28. package/dist/es2019/ui/DeleteConfirmationModal.js +13 -2
  29. package/dist/es2019/ui/Flag.js +66 -0
  30. package/dist/es2019/ui/floating-toolbar.js +3 -2
  31. package/dist/esm/nodeviews/bodiedSyncedBlock.js +27 -5
  32. package/dist/esm/pm-plugins/main.js +85 -41
  33. package/dist/esm/pm-plugins/utils/ignore-dom-event.js +24 -0
  34. package/dist/esm/pm-plugins/utils/track-sync-blocks.js +48 -0
  35. package/dist/esm/pm-plugins/utils/utils.js +6 -2
  36. package/dist/esm/syncedBlockPlugin.js +17 -2
  37. package/dist/esm/types/index.js +6 -0
  38. package/dist/esm/ui/CreateSyncedBlockButton.js +10 -5
  39. package/dist/esm/ui/CreateSyncedBlockDropdownItem.js +13 -11
  40. package/dist/esm/ui/CreateSyncedBlockItem.js +17 -15
  41. package/dist/esm/ui/DeleteConfirmationModal.js +12 -2
  42. package/dist/esm/ui/Flag.js +58 -0
  43. package/dist/esm/ui/floating-toolbar.js +3 -2
  44. package/dist/types/nodeviews/bodiedSyncedBlock.d.ts +1 -1
  45. package/dist/types/pm-plugins/main.d.ts +4 -2
  46. package/dist/types/pm-plugins/utils/ignore-dom-event.d.ts +8 -0
  47. package/dist/types/pm-plugins/utils/track-sync-blocks.d.ts +5 -0
  48. package/dist/types/syncedBlockPluginType.d.ts +5 -1
  49. package/dist/types/types/index.d.ts +11 -0
  50. package/dist/types/ui/DeleteConfirmationModal.d.ts +4 -1
  51. package/dist/types/ui/Flag.d.ts +8 -0
  52. package/dist/types-ts4.5/nodeviews/bodiedSyncedBlock.d.ts +1 -1
  53. package/dist/types-ts4.5/pm-plugins/main.d.ts +4 -2
  54. package/dist/types-ts4.5/pm-plugins/utils/ignore-dom-event.d.ts +8 -0
  55. package/dist/types-ts4.5/pm-plugins/utils/track-sync-blocks.d.ts +5 -0
  56. package/dist/types-ts4.5/syncedBlockPluginType.d.ts +5 -1
  57. package/dist/types-ts4.5/types/index.d.ts +11 -0
  58. package/dist/types-ts4.5/ui/DeleteConfirmationModal.d.ts +4 -1
  59. package/dist/types-ts4.5/ui/Flag.d.ts +8 -0
  60. package/package.json +6 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 4.2.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b7d44770ef1bf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b7d44770ef1bf) -
8
+ EDITOR-2913 fix error nodetype create cannot create text nodes by filtering out text nodes
9
+
10
+ ## 4.2.8
11
+
12
+ ### Patch Changes
13
+
14
+ - [`63628e69e52e7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/63628e69e52e7) -
15
+ [ux] [EDITOR-2557] Disable sync block creation, edition and deletion in offline mode
16
+ - Updated dependencies
17
+
3
18
  ## 4.2.7
4
19
 
5
20
  ### Patch Changes
@@ -34,6 +34,9 @@
34
34
  {
35
35
  "path": "../../editor-plugin-block-menu/afm-cc/tsconfig.json"
36
36
  },
37
+ {
38
+ "path": "../../editor-plugin-connectivity/afm-cc/tsconfig.json"
39
+ },
37
40
  {
38
41
  "path": "../../editor-plugin-decorations/afm-cc/tsconfig.json"
39
42
  },
@@ -55,6 +58,9 @@
55
58
  {
56
59
  "path": "../../editor-toolbar/afm-cc/tsconfig.json"
57
60
  },
61
+ {
62
+ "path": "../../../design-system/flag/afm-cc/tsconfig.json"
63
+ },
58
64
  {
59
65
  "path": "../../../design-system/icon/afm-cc/tsconfig.json"
60
66
  },
@@ -73,6 +79,9 @@
73
79
  {
74
80
  "path": "../../../design-system/primitives/afm-cc/tsconfig.json"
75
81
  },
82
+ {
83
+ "path": "../../../design-system/tokens/afm-cc/tsconfig.json"
84
+ },
76
85
  {
77
86
  "path": "../../../design-system/tooltip/afm-cc/tsconfig.json"
78
87
  },
@@ -2,7 +2,7 @@
2
2
  "extends": "../../../../tsconfig.entry-points.jira.json",
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
- "outDir": "../../../../../tsDist/@atlaskit__editor-plugin-synced-block/app",
5
+ "outDir": "../../../../../jira/tsDist/@atlaskit__editor-plugin-synced-block/app",
6
6
  "rootDir": "../",
7
7
  "composite": true
8
8
  },
@@ -34,6 +34,9 @@
34
34
  {
35
35
  "path": "../../editor-plugin-block-menu/afm-jira/tsconfig.json"
36
36
  },
37
+ {
38
+ "path": "../../editor-plugin-connectivity/afm-jira/tsconfig.json"
39
+ },
37
40
  {
38
41
  "path": "../../editor-plugin-decorations/afm-jira/tsconfig.json"
39
42
  },
@@ -55,6 +58,9 @@
55
58
  {
56
59
  "path": "../../editor-toolbar/afm-jira/tsconfig.json"
57
60
  },
61
+ {
62
+ "path": "../../../design-system/flag/afm-jira/tsconfig.json"
63
+ },
58
64
  {
59
65
  "path": "../../../design-system/icon/afm-jira/tsconfig.json"
60
66
  },
@@ -73,6 +79,9 @@
73
79
  {
74
80
  "path": "../../../design-system/primitives/afm-jira/tsconfig.json"
75
81
  },
82
+ {
83
+ "path": "../../../design-system/tokens/afm-jira/tsconfig.json"
84
+ },
76
85
  {
77
86
  "path": "../../../design-system/tooltip/afm-jira/tsconfig.json"
78
87
  },
@@ -34,6 +34,9 @@
34
34
  {
35
35
  "path": "../../editor-plugin-block-menu/afm-products/tsconfig.json"
36
36
  },
37
+ {
38
+ "path": "../../editor-plugin-connectivity/afm-products/tsconfig.json"
39
+ },
37
40
  {
38
41
  "path": "../../editor-plugin-decorations/afm-products/tsconfig.json"
39
42
  },
@@ -55,6 +58,9 @@
55
58
  {
56
59
  "path": "../../editor-toolbar/afm-products/tsconfig.json"
57
60
  },
61
+ {
62
+ "path": "../../../design-system/flag/afm-products/tsconfig.json"
63
+ },
58
64
  {
59
65
  "path": "../../../design-system/icon/afm-products/tsconfig.json"
60
66
  },
@@ -73,6 +79,9 @@
73
79
  {
74
80
  "path": "../../../design-system/primitives/afm-products/tsconfig.json"
75
81
  },
82
+ {
83
+ "path": "../../../design-system/tokens/afm-products/tsconfig.json"
84
+ },
76
85
  {
77
86
  "path": "../../../design-system/tooltip/afm-products/tsconfig.json"
78
87
  },
@@ -29,10 +29,25 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
29
29
  (0, _classCallCheck2.default)(this, BodiedSyncBlock);
30
30
  _this = _callSuper(this, BodiedSyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
31
31
  _this.syncBlockStore = props.syncBlockStore;
32
+ _this.api = props.api;
33
+ _this.handleConnectivityModeChange();
32
34
  return _this;
33
35
  }
34
36
  (0, _inherits2.default)(BodiedSyncBlock, _ReactNodeView);
35
37
  return (0, _createClass2.default)(BodiedSyncBlock, [{
38
+ key: "handleConnectivityModeChange",
39
+ value: function handleConnectivityModeChange() {
40
+ var _this$api,
41
+ _this2 = this;
42
+ if ((_this$api = this.api) !== null && _this$api !== void 0 && _this$api.connectivity) {
43
+ this.cleanupConnectivityModeListener = this.api.connectivity.sharedState.onChange(function (_ref) {
44
+ var _this2$contentDOM;
45
+ var nextSharedState = _ref.nextSharedState;
46
+ (_this2$contentDOM = _this2.contentDOM) === null || _this2$contentDOM === void 0 || _this2$contentDOM.setAttribute('contenteditable', nextSharedState.mode === 'online' ? 'true' : 'false');
47
+ });
48
+ }
49
+ }
50
+ }, {
36
51
  key: "createDomRef",
37
52
  value: function createDomRef() {
38
53
  var domRef = document.createElement('div');
@@ -62,13 +77,20 @@ var BodiedSyncBlock = /*#__PURE__*/function (_ReactNodeView) {
62
77
  }
63
78
  return undefined;
64
79
  }
80
+ }, {
81
+ key: "destroy",
82
+ value: function destroy() {
83
+ if (this.cleanupConnectivityModeListener) {
84
+ this.cleanupConnectivityModeListener();
85
+ }
86
+ }
65
87
  }]);
66
88
  }(_reactNodeView.default);
67
- var bodiedSyncBlockNodeView = exports.bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref) {
68
- var pluginOptions = _ref.pluginOptions,
69
- pmPluginFactoryParams = _ref.pmPluginFactoryParams,
70
- api = _ref.api,
71
- syncBlockStore = _ref.syncBlockStore;
89
+ var bodiedSyncBlockNodeView = exports.bodiedSyncBlockNodeView = function bodiedSyncBlockNodeView(_ref2) {
90
+ var pluginOptions = _ref2.pluginOptions,
91
+ pmPluginFactoryParams = _ref2.pmPluginFactoryParams,
92
+ api = _ref2.api,
93
+ syncBlockStore = _ref2.syncBlockStore;
72
94
  return function (node, view, getPos) {
73
95
  var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
74
96
  eventDispatcher = pmPluginFactoryParams.eventDispatcher;
@@ -5,17 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.syncedBlockPluginKey = exports.createPlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
+ var _readOnlyError2 = _interopRequireDefault(require("@babel/runtime/helpers/readOnlyError"));
9
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
10
  var _selection = require("@atlaskit/editor-common/selection");
11
11
  var _syncBlock = require("@atlaskit/editor-common/sync-block");
12
12
  var _state = require("@atlaskit/editor-prosemirror/state");
13
+ var _view = require("@atlaskit/editor-prosemirror/view");
13
14
  var _bodiedLazySyncedBlock = require("../nodeviews/bodiedLazySyncedBlock");
14
15
  var _lazySyncedBlock = require("../nodeviews/lazySyncedBlock");
16
+ var _types = require("../types");
17
+ var _ignoreDomEvent = require("./utils/ignore-dom-event");
15
18
  var _selectionDecorations = require("./utils/selection-decorations");
16
19
  var _trackSyncBlocks2 = require("./utils/track-sync-blocks");
17
- 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; }
18
- 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; }
19
20
  var syncedBlockPluginKey = exports.syncedBlockPluginKey = new _state.PluginKey('syncedBlockPlugin');
20
21
  var createPlugin = exports.createPlugin = function createPlugin(options, pmPluginFactoryParams, syncBlockStore, api) {
21
22
  var _ref = options || {},
@@ -30,25 +31,23 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
30
31
  });
31
32
  syncBlockStore.fetchSyncBlocksData(syncBlockNodes);
32
33
  return {
33
- decorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema)
34
+ selectionDecorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema),
35
+ showFlag: false
34
36
  };
35
37
  },
36
38
  apply: function apply(tr, currentPluginState, oldEditorState) {
39
+ var _meta$showFlag;
37
40
  var meta = tr.getMeta(syncedBlockPluginKey);
38
- if (meta) {
39
- return meta;
40
- }
41
- var newState = currentPluginState;
41
+ var showFlag = currentPluginState.showFlag,
42
+ selectionDecorationSet = currentPluginState.selectionDecorationSet;
43
+ var newDecorationSet = selectionDecorationSet.map(tr.mapping, tr.doc);
42
44
  if (!tr.selection.eq(oldEditorState.selection)) {
43
- newState = _objectSpread(_objectSpread({}, newState), {}, {
44
- decorationSet: (0, _selectionDecorations.calculateDecorations)(tr.doc, tr.selection, tr.doc.type.schema)
45
- });
46
- } else if (newState.decorationSet) {
47
- newState = _objectSpread(_objectSpread({}, newState), {}, {
48
- decorationSet: newState.decorationSet.map(tr.mapping, tr.doc)
49
- });
45
+ newDecorationSet = (0, _selectionDecorations.calculateDecorations)(tr.doc, tr.selection, tr.doc.type.schema);
50
46
  }
51
- return newState;
47
+ return {
48
+ showFlag: (_meta$showFlag = meta === null || meta === void 0 ? void 0 : meta.showFlag) !== null && _meta$showFlag !== void 0 ? _meta$showFlag : showFlag,
49
+ selectionDecorationSet: newDecorationSet
50
+ };
52
51
  }
53
52
  },
54
53
  props: {
@@ -67,14 +66,34 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
67
66
  })
68
67
  },
69
68
  decorations: function decorations(state) {
70
- var pluginState = syncedBlockPluginKey.getState(state);
71
- return pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorationSet;
69
+ var _syncedBlockPluginKey, _syncedBlockPluginKey2, _api$connectivity;
70
+ var selectionDecorationSet = (_syncedBlockPluginKey = (_syncedBlockPluginKey2 = syncedBlockPluginKey.getState(state)) === null || _syncedBlockPluginKey2 === void 0 ? void 0 : _syncedBlockPluginKey2.selectionDecorationSet) !== null && _syncedBlockPluginKey !== void 0 ? _syncedBlockPluginKey : _view.DecorationSet.empty;
71
+ var doc = state.doc;
72
+ var decorations = [];
73
+ if ((api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode) === 'offline') {
74
+ state.doc.descendants(function (node, pos) {
75
+ if (node.type.name === 'bodiedSyncBlock') {
76
+ decorations.push(_view.Decoration.node(pos, pos + node.nodeSize, {
77
+ class: _syncBlock.SyncBlockStateCssClassName.disabledClassName
78
+ }));
79
+ }
80
+ });
81
+ }
82
+ return selectionDecorationSet.add(doc, decorations);
72
83
  },
73
84
  handleClickOn: (0, _selection.createSelectionClickHandler)(['bodiedSyncBlock'], function (target) {
74
85
  return !!target.closest(".".concat(_syncBlock.BodiedSyncBlockSharedCssClassName.prefix));
75
86
  }, {
76
87
  useLongPressSelection: useLongPressSelection
77
- })
88
+ }),
89
+ handleDOMEvents: {
90
+ mouseover: function mouseover(view, event) {
91
+ return (0, _ignoreDomEvent.shouldIgnoreDomEvent)(view, event, api);
92
+ },
93
+ mousedown: function mousedown(view, event) {
94
+ return (0, _ignoreDomEvent.shouldIgnoreDomEvent)(view, event, api);
95
+ }
96
+ }
78
97
  },
79
98
  view: function view(editorView) {
80
99
  syncBlockStore.setEditorView(editorView);
@@ -85,36 +104,61 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
85
104
  };
86
105
  },
87
106
  filterTransaction: function filterTransaction(tr, state) {
107
+ var _api$connectivity2;
108
+ var isOffline = (api === null || api === void 0 || (_api$connectivity2 = api.connectivity) === null || _api$connectivity2 === void 0 || (_api$connectivity2 = _api$connectivity2.sharedState.currentState()) === null || _api$connectivity2 === void 0 ? void 0 : _api$connectivity2.mode) === 'offline';
109
+ var isConfirmedSyncBlockDeletion = Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'));
88
110
  // Ignore transactions that don't change the document
89
111
  // or are from remote (collab) or already confirmed sync block deletion
90
112
  // We only care about local changes that change the document
91
113
  // and are not yet confirmed for sync block deletion
92
- if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.requireConfirmationBeforeDelete()) && !syncBlockStore.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isConfirmedSyncBlockDeletion')) || Boolean(tr.getMeta('isCommitSyncBlockCreation'))) {
114
+ if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.requireConfirmationBeforeDelete()) && !syncBlockStore.hasPendingCreation() || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isCommitSyncBlockCreation')) || !isOffline && isConfirmedSyncBlockDeletion) {
93
115
  return true;
94
116
  }
95
117
  var _trackSyncBlocks = (0, _trackSyncBlocks2.trackSyncBlocks)(syncBlockStore, tr, state),
96
118
  removed = _trackSyncBlocks.removed,
97
119
  added = _trackSyncBlocks.added;
98
- if (removed.length > 0) {
99
- // If there are source sync blocks being removed, and we need to confirm with user before deleting,
100
- // we block the transaction here, and wait for user confirmation to proceed with deletion.
101
- // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
102
- // proceed with deletion.
103
- syncBlockStore.deleteSyncBlocksWithConfirmation(tr, removed);
104
- return false;
105
- }
106
- if (added.length > 0) {
107
- // If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
108
- // we need to intercept the transaction and save it in insert callback so that we only insert it to the document when backend call if backend call is successful
109
- // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
110
- syncBlockStore.registerCreationCallback(function () {
111
- var _api$core;
112
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
113
- return tr.setMeta('isCommitSyncBlockCreation', true);
120
+ if (!isOffline) {
121
+ if (removed.length > 0) {
122
+ // If there are source sync blocks being removed, and we need to confirm with user before deleting,
123
+ // we block the transaction here, and wait for user confirmation to proceed with deletion.
124
+ // See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
125
+ // proceed with deletion.
126
+ syncBlockStore.deleteSyncBlocksWithConfirmation(tr, removed);
127
+ return false;
128
+ }
129
+ if (added.length > 0) {
130
+ // If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
131
+ // we need to intercept the transaction and save it in insert callback so that we only insert it to the document when backend call if backend call is successful
132
+ // The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
133
+ syncBlockStore.registerCreationCallback(function () {
134
+ var _api$core;
135
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
136
+ return tr.setMeta('isCommitSyncBlockCreation', true);
137
+ });
138
+ api === null || api === void 0 || api.core.actions.focus();
114
139
  });
115
- api === null || api === void 0 || api.core.actions.focus();
116
- });
117
- return false;
140
+ return false;
141
+ }
142
+ } else {
143
+ // Disable node deletion/creation/edition in offline mode and trigger an error flag instead
144
+ var errorFlag = false;
145
+ if (isConfirmedSyncBlockDeletion || removed.length > 0) {
146
+ errorFlag = _types.FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE;
147
+ } else if (added.length > 0) {
148
+ errorFlag = _types.FLAG_ID.CANNOT_CREATE_WHEN_OFFLINE;
149
+ } else if ((0, _trackSyncBlocks2.hasEditInSyncBlock)(tr, state)) {
150
+ errorFlag = _types.FLAG_ID.CANNOT_EDIT_WHEN_OFFLINE;
151
+ }
152
+ if (errorFlag) {
153
+ api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
154
+ var tr = _ref2.tr;
155
+ tr.setMeta(syncedBlockPluginKey, {
156
+ showFlag: errorFlag
157
+ });
158
+ return tr;
159
+ });
160
+ return false;
161
+ }
118
162
  }
119
163
  return true;
120
164
  },
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shouldIgnoreDomEvent = void 0;
7
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
8
+ /**
9
+ *
10
+ * @returns true if should ignore event happens within bodiedSyncBlock node when offline
11
+ */
12
+ var shouldIgnoreDomEvent = exports.shouldIgnoreDomEvent = function shouldIgnoreDomEvent(view, event, api) {
13
+ var _api$connectivity, _view$posAtCoords;
14
+ if ((api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode) !== 'offline') {
15
+ return;
16
+ }
17
+ var bodiedSyncBlock = view.state.schema.nodes.bodiedSyncBlock;
18
+ var pos = (_view$posAtCoords = view.posAtCoords({
19
+ left: event.clientX,
20
+ top: event.clientY
21
+ })) === null || _view$posAtCoords === void 0 ? void 0 : _view$posAtCoords.pos;
22
+ if (pos === undefined) {
23
+ return;
24
+ }
25
+ var $pos = view.state.doc.resolve(pos);
26
+ var maybeNode = (0, _utils.findParentNodeOfTypeClosestToPos)($pos, bodiedSyncBlock);
27
+ if (maybeNode) {
28
+ return true;
29
+ }
30
+ };
@@ -3,8 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.trackSyncBlocks = void 0;
6
+ exports.trackSyncBlocks = exports.hasEditInSyncBlock = void 0;
7
7
  var _transform = require("@atlaskit/editor-prosemirror/transform");
8
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
9
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
12
  var trackSyncBlocks = exports.trackSyncBlocks = function trackSyncBlocks(storeManager, tr, state) {
9
13
  var sourceSyncBlockRemoved = {};
10
14
  var sourceSyncBlockAdded = {};
@@ -61,4 +65,48 @@ var trackSyncBlocks = exports.trackSyncBlocks = function trackSyncBlocks(storeMa
61
65
  removed: Object.values(sourceSyncBlockRemoved),
62
66
  added: Object.values(sourceSyncBlockAdded)
63
67
  };
68
+ };
69
+
70
+ /**
71
+ *
72
+ * @returns true if steps modifies children node within bodiedSyncBlock
73
+ */
74
+ var hasEditInSyncBlock = exports.hasEditInSyncBlock = function hasEditInSyncBlock(tr, state) {
75
+ var bodiedSyncBlock = state.schema.nodes.bodiedSyncBlock;
76
+ var _iterator = _createForOfIteratorHelper(tr.steps),
77
+ _step;
78
+ try {
79
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
80
+ var step = _step.value;
81
+ var map = step.getMap();
82
+ var doc = tr.doc;
83
+ var positions = [];
84
+
85
+ // Extract positions from steps dynamically based on applicable properties
86
+ if ('from' in step && typeof step.from === 'number' && 'to' in step && typeof step.to === 'number') {
87
+ var _ref = step,
88
+ from = _ref.from,
89
+ to = _ref.to;
90
+ positions.push(from, to);
91
+ } else if ('pos' in step && typeof step.pos === 'number') {
92
+ var _ref2 = step,
93
+ pos = _ref2.pos;
94
+ positions.push(pos);
95
+ }
96
+ for (var _i = 0, _positions = positions; _i < _positions.length; _i++) {
97
+ var _pos = _positions[_i];
98
+ var newPos = map.map(_pos);
99
+ if (newPos >= 0 && newPos <= doc.content.size) {
100
+ if ((0, _utils.findParentNodeOfTypeClosestToPos)(doc.resolve(newPos), bodiedSyncBlock)) {
101
+ return true;
102
+ }
103
+ }
104
+ }
105
+ }
106
+ } catch (err) {
107
+ _iterator.e(err);
108
+ } finally {
109
+ _iterator.f();
110
+ }
111
+ return false;
64
112
  };
@@ -78,8 +78,12 @@ var removeBreakoutMarks = function removeBreakoutMarks(content) {
78
78
  var filteredMarks = node.marks.filter(function (mark) {
79
79
  return mark.type.name !== 'breakout';
80
80
  });
81
- var newNode = node.type.create(node.attrs, node.content, filteredMarks);
82
- nodes.push(newNode);
81
+ if (node.isText) {
82
+ nodes.push(node);
83
+ } else {
84
+ var newNode = node.type.create(node.attrs, node.content, filteredMarks);
85
+ nodes.push(newNode);
86
+ }
83
87
  });
84
88
  return _model.Fragment.from(nodes);
85
89
  };
@@ -16,6 +16,7 @@ var _editorCommands = require("./editor-commands");
16
16
  var _main = require("./pm-plugins/main");
17
17
  var _blockMenuComponents = require("./ui/block-menu-components");
18
18
  var _DeleteConfirmationModal = require("./ui/DeleteConfirmationModal");
19
+ var _Flag = require("./ui/Flag");
19
20
  var _floatingToolbar = require("./ui/floating-toolbar");
20
21
  var _SyncBlockRefresher = require("./ui/SyncBlockRefresher");
21
22
  var _toolbarComponents = require("./ui/toolbar-components");
@@ -73,6 +74,7 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
73
74
  description: formatMessage(_messages.blockTypeMessages.syncedBlockDescription),
74
75
  priority: 800,
75
76
  keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block', 'auto', 'update', 'excerpt', 'connect'],
77
+ isDisabledOffline: true,
76
78
  keyshortcut: '',
77
79
  lozenge: /*#__PURE__*/_react.default.createElement(_lozenge.default, {
78
80
  appearance: "new"
@@ -99,8 +101,21 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
99
101
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_SyncBlockRefresher.SyncBlockRefresher, {
100
102
  syncBlockStoreManager: syncBlockStore
101
103
  }), /*#__PURE__*/_react.default.createElement(_DeleteConfirmationModal.DeleteConfirmationModal, {
102
- syncBlockStoreManager: syncBlockStore
104
+ syncBlockStoreManager: syncBlockStore,
105
+ api: api
106
+ }), /*#__PURE__*/_react.default.createElement(_Flag.Flag, {
107
+ api: api
103
108
  }));
109
+ },
110
+ getSharedState: function getSharedState(editorState) {
111
+ if (!editorState) {
112
+ return;
113
+ }
114
+ var _syncedBlockPluginKey = _main.syncedBlockPluginKey.getState(editorState),
115
+ showFlag = _syncedBlockPluginKey.showFlag;
116
+ return {
117
+ showFlag: showFlag
118
+ };
104
119
  }
105
120
  };
106
121
  };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FLAG_ID = void 0;
7
+ var FLAG_ID = exports.FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
8
+ FLAG_ID["CANNOT_DELETE_WHEN_OFFLINE"] = "cannot-delete-when-offline";
9
+ FLAG_ID["CANNOT_EDIT_WHEN_OFFLINE"] = "cannot-edit-when-offline";
10
+ FLAG_ID["CANNOT_CREATE_WHEN_OFFLINE"] = "cannot-create-when-offline";
11
+ return FLAG_ID;
12
+ }({});
@@ -17,16 +17,21 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
17
17
  var CreateSyncedBlockButton = exports.CreateSyncedBlockButton = function CreateSyncedBlockButton(_ref) {
18
18
  var api = _ref.api;
19
19
  var intl = (0, _reactIntlNext.useIntl)();
20
- var selection = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selection'], function (states) {
21
- var _states$selectionStat;
22
- return (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection;
23
- });
20
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selection', 'connectivity'], function (states) {
21
+ var _states$selectionStat, _states$connectivityS;
22
+ return {
23
+ selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection,
24
+ mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode
25
+ };
26
+ }),
27
+ selection = _useSharedPluginState.selection,
28
+ mode = _useSharedPluginState.mode;
24
29
 
25
30
  // for toolbar button, we allow both creating a new synced block
26
31
  // and converting existing block to synced block
27
32
  var canBeConverted = Boolean(selection && (0, _utils.canBeConvertedToSyncBlock)(selection));
28
33
  var canInsertEmptyBlock = Boolean(selection === null || selection === void 0 ? void 0 : selection.empty);
29
- var isDisabled = Boolean(!canBeConverted && !canInsertEmptyBlock);
34
+ var isDisabled = Boolean(mode === 'offline' || !canBeConverted && !canInsertEmptyBlock);
30
35
  var onClick = (0, _react.useCallback)(function () {
31
36
  var _api$core, _api$core2;
32
37
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
@@ -19,15 +19,17 @@ var CreateSyncedBlockDropdownItem = function CreateSyncedBlockDropdownItem(_ref)
19
19
  var api = _ref.api;
20
20
  var _useIntl = (0, _reactIntlNext.useIntl)(),
21
21
  formatMessage = _useIntl.formatMessage;
22
- var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selection', 'blockControls'], function (states) {
23
- var _states$selectionStat, _states$blockControls, _states$blockControls2;
22
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['selection', 'blockControls', 'connectivity'], function (states) {
23
+ var _states$selectionStat, _states$blockControls, _states$blockControls2, _states$connectivityS;
24
24
  return {
25
25
  selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection,
26
- menuTriggerByNode: (_states$blockControls = (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.menuTriggerByNode) !== null && _states$blockControls !== void 0 ? _states$blockControls : undefined
26
+ menuTriggerByNode: (_states$blockControls = (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.menuTriggerByNode) !== null && _states$blockControls !== void 0 ? _states$blockControls : undefined,
27
+ mode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode
27
28
  };
28
29
  }),
29
30
  selection = _useSharedPluginState.selection,
30
- menuTriggerByNode = _useSharedPluginState.menuTriggerByNode;
31
+ menuTriggerByNode = _useSharedPluginState.menuTriggerByNode,
32
+ mode = _useSharedPluginState.mode;
31
33
  var isNested = menuTriggerByNode && menuTriggerByNode.rootPos !== menuTriggerByNode.pos;
32
34
  var canBeConverted = (0, _react.useMemo)(function () {
33
35
  return selection && (0, _utils.canBeConvertedToSyncBlock)(selection);
@@ -42,17 +44,17 @@ var CreateSyncedBlockDropdownItem = function CreateSyncedBlockDropdownItem(_ref)
42
44
  closeMenu: true
43
45
  }));
44
46
  };
47
+ var isOffline = mode === 'offline';
45
48
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
46
49
  elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.SyncBlocksIcon, {
47
50
  label: ""
48
51
  }),
49
- onClick: onClick
50
- }, /*#__PURE__*/_react.default.createElement(_compiled.Flex, {
51
- alignItems: "center",
52
- gap: "space.050"
53
- }, /*#__PURE__*/_react.default.createElement(_compiled.Text, null, formatMessage(_messages.blockMenuMessages.createSyncedBlock)), /*#__PURE__*/_react.default.createElement(_lozenge.default, {
54
- appearance: "new"
55
- }, formatMessage(_messages.blockMenuMessages.newLozenge))));
52
+ onClick: onClick,
53
+ isDisabled: isOffline,
54
+ elemAfter: /*#__PURE__*/_react.default.createElement(_lozenge.default, {
55
+ appearance: "new"
56
+ }, formatMessage(_messages.blockMenuMessages.newLozenge))
57
+ }, formatMessage(_messages.blockMenuMessages.createSyncedBlock));
56
58
  };
57
59
  var CopySyncedBlockDropdownItem = function CopySyncedBlockDropdownItem(_ref2) {
58
60
  var api = _ref2.api;