@atlaskit/editor-plugin-synced-block 4.6.2 → 4.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 4.6.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8289826cdcae0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8289826cdcae0) -
8
+ [ux] EDITOR-3998 fix sync block copy when copying content inside the bodied sync block
9
+ - Updated dependencies
10
+
3
11
  ## 4.6.2
4
12
 
5
13
  ### Patch Changes
@@ -20,6 +20,7 @@ var _handleBodiedSyncBlockRemoval = require("./utils/handle-bodied-sync-block-re
20
20
  var _ignoreDomEvent = require("./utils/ignore-dom-event");
21
21
  var _selectionDecorations = require("./utils/selection-decorations");
22
22
  var _trackSyncBlocks4 = require("./utils/track-sync-blocks");
23
+ var _utils2 = require("./utils/utils");
23
24
  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; } } }; }
24
25
  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; } }
25
26
  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; }
@@ -140,6 +141,11 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
140
141
  return node;
141
142
  }
142
143
  if (node.type.name === 'bodiedSyncBlock' && node.attrs.resourceId) {
144
+ // if we only selected part of the bodied sync block content,
145
+ // remove the sync block node and only keep the content
146
+ if (!(0, _utils2.sliceFullyContainsNode)(slice, node)) {
147
+ return node.content;
148
+ }
143
149
  showCopiedFlag(api);
144
150
  var newResourceId = syncBlockStore.referenceManager.generateResourceIdForReference(node.attrs.resourceId);
145
151
  // Convert bodiedSyncBlock to syncBlock
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isBodiedSyncBlockNode = exports.findSyncBlockOrBodiedSyncBlock = exports.findSyncBlock = exports.findBodiedSyncBlock = exports.canBeConvertedToSyncBlock = void 0;
6
+ exports.sliceFullyContainsNode = exports.isBodiedSyncBlockNode = exports.findSyncBlockOrBodiedSyncBlock = exports.findSyncBlock = exports.findBodiedSyncBlock = exports.canBeConvertedToSyncBlock = void 0;
7
7
  var _model = require("@atlaskit/editor-prosemirror/model");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _utils = require("@atlaskit/editor-prosemirror/utils");
@@ -86,4 +86,15 @@ var removeBreakoutMarks = function removeBreakoutMarks(content) {
86
86
  }
87
87
  });
88
88
  return _model.Fragment.from(nodes);
89
+ };
90
+ var sliceFullyContainsNode = exports.sliceFullyContainsNode = function sliceFullyContainsNode(slice, node) {
91
+ var _slice$content$firstC, _slice$content$firstC2, _slice$content$lastCh, _slice$content$lastCh2;
92
+ var isFirstChild = ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === node.type && ((_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.attrs.resourceId) === node.attrs.resourceId;
93
+ var isLastChild = ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === node.type && ((_slice$content$lastCh2 = slice.content.lastChild) === null || _slice$content$lastCh2 === void 0 ? void 0 : _slice$content$lastCh2.attrs.resourceId) === node.attrs.resourceId;
94
+ var isOpenAtStart = isFirstChild && slice.openStart > 0;
95
+ var isOpenAtEnd = isLastChild && slice.openEnd > 0;
96
+ if (isOpenAtStart || isOpenAtEnd) {
97
+ return false;
98
+ }
99
+ return true;
89
100
  };
@@ -12,6 +12,7 @@ import { handleBodiedSyncBlockRemoval } from './utils/handle-bodied-sync-block-r
12
12
  import { shouldIgnoreDomEvent } from './utils/ignore-dom-event';
13
13
  import { calculateDecorations } from './utils/selection-decorations';
14
14
  import { hasEditInSyncBlock, trackSyncBlocks } from './utils/track-sync-blocks';
15
+ import { sliceFullyContainsNode } from './utils/utils';
15
16
  export const syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
16
17
  const showCopiedFlag = api => {
17
18
  // Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
@@ -131,6 +132,11 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
131
132
  return node;
132
133
  }
133
134
  if (node.type.name === 'bodiedSyncBlock' && node.attrs.resourceId) {
135
+ // if we only selected part of the bodied sync block content,
136
+ // remove the sync block node and only keep the content
137
+ if (!sliceFullyContainsNode(slice, node)) {
138
+ return node.content;
139
+ }
134
140
  showCopiedFlag(api);
135
141
  const newResourceId = syncBlockStore.referenceManager.generateResourceIdForReference(node.attrs.resourceId);
136
142
  // Convert bodiedSyncBlock to syncBlock
@@ -80,4 +80,15 @@ const removeBreakoutMarks = content => {
80
80
  }
81
81
  });
82
82
  return Fragment.from(nodes);
83
+ };
84
+ export const sliceFullyContainsNode = (slice, node) => {
85
+ var _slice$content$firstC, _slice$content$firstC2, _slice$content$lastCh, _slice$content$lastCh2;
86
+ const isFirstChild = ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === node.type && ((_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.attrs.resourceId) === node.attrs.resourceId;
87
+ const isLastChild = ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === node.type && ((_slice$content$lastCh2 = slice.content.lastChild) === null || _slice$content$lastCh2 === void 0 ? void 0 : _slice$content$lastCh2.attrs.resourceId) === node.attrs.resourceId;
88
+ const isOpenAtStart = isFirstChild && slice.openStart > 0;
89
+ const isOpenAtEnd = isLastChild && slice.openEnd > 0;
90
+ if (isOpenAtStart || isOpenAtEnd) {
91
+ return false;
92
+ }
93
+ return true;
83
94
  };
@@ -18,6 +18,7 @@ import { handleBodiedSyncBlockRemoval } from './utils/handle-bodied-sync-block-r
18
18
  import { shouldIgnoreDomEvent } from './utils/ignore-dom-event';
19
19
  import { calculateDecorations } from './utils/selection-decorations';
20
20
  import { hasEditInSyncBlock, trackSyncBlocks } from './utils/track-sync-blocks';
21
+ import { sliceFullyContainsNode } from './utils/utils';
21
22
  export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
22
23
  var showCopiedFlag = function showCopiedFlag(api) {
23
24
  // Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
@@ -133,6 +134,11 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
133
134
  return node;
134
135
  }
135
136
  if (node.type.name === 'bodiedSyncBlock' && node.attrs.resourceId) {
137
+ // if we only selected part of the bodied sync block content,
138
+ // remove the sync block node and only keep the content
139
+ if (!sliceFullyContainsNode(slice, node)) {
140
+ return node.content;
141
+ }
136
142
  showCopiedFlag(api);
137
143
  var newResourceId = syncBlockStore.referenceManager.generateResourceIdForReference(node.attrs.resourceId);
138
144
  // Convert bodiedSyncBlock to syncBlock
@@ -80,4 +80,15 @@ var removeBreakoutMarks = function removeBreakoutMarks(content) {
80
80
  }
81
81
  });
82
82
  return Fragment.from(nodes);
83
+ };
84
+ export var sliceFullyContainsNode = function sliceFullyContainsNode(slice, node) {
85
+ var _slice$content$firstC, _slice$content$firstC2, _slice$content$lastCh, _slice$content$lastCh2;
86
+ var isFirstChild = ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === node.type && ((_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.attrs.resourceId) === node.attrs.resourceId;
87
+ var isLastChild = ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === node.type && ((_slice$content$lastCh2 = slice.content.lastChild) === null || _slice$content$lastCh2 === void 0 ? void 0 : _slice$content$lastCh2.attrs.resourceId) === node.attrs.resourceId;
88
+ var isOpenAtStart = isFirstChild && slice.openStart > 0;
89
+ var isOpenAtEnd = isLastChild && slice.openEnd > 0;
90
+ if (isOpenAtStart || isOpenAtEnd) {
91
+ return false;
92
+ }
93
+ return true;
83
94
  };
@@ -1,5 +1,5 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
- import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
2
+ import type { NodeType, Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
3
3
  import { type Selection } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
5
  export declare const findSyncBlock: (schema: Schema, selection: Selection) => ContentNodeWithPos | undefined;
@@ -20,3 +20,4 @@ export interface SyncBlockConversionInfo {
20
20
  * or false if conversion is not possible
21
21
  */
22
22
  export declare const canBeConvertedToSyncBlock: (selection: Selection) => SyncBlockConversionInfo | false;
23
+ export declare const sliceFullyContainsNode: (slice: Slice, node: PMNode) => boolean;
@@ -1,5 +1,5 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
- import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
2
+ import type { NodeType, Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
3
3
  import { type Selection } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
5
  export declare const findSyncBlock: (schema: Schema, selection: Selection) => ContentNodeWithPos | undefined;
@@ -20,3 +20,4 @@ export interface SyncBlockConversionInfo {
20
20
  * or false if conversion is not possible
21
21
  */
22
22
  export declare const canBeConvertedToSyncBlock: (selection: Selection) => SyncBlockConversionInfo | false;
23
+ export declare const sliceFullyContainsNode: (slice: Slice, node: PMNode) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "4.6.2",
3
+ "version": "4.6.3",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,7 +29,7 @@
29
29
  "atlaskit:src": "src/index.ts",
30
30
  "dependencies": {
31
31
  "@atlaskit/adf-schema": "^51.5.0",
32
- "@atlaskit/button": "23.8.1",
32
+ "@atlaskit/button": "23.9.0",
33
33
  "@atlaskit/editor-json-transformer": "^8.31.0",
34
34
  "@atlaskit/editor-plugin-analytics": "^6.2.0",
35
35
  "@atlaskit/editor-plugin-block-menu": "^5.2.0",
@@ -48,7 +48,7 @@
48
48
  "@atlaskit/lozenge": "^13.2.0",
49
49
  "@atlaskit/modal-dialog": "^14.9.0",
50
50
  "@atlaskit/primitives": "^16.4.0",
51
- "@atlaskit/tmp-editor-statsig": "^15.15.0",
51
+ "@atlaskit/tmp-editor-statsig": "^16.0.0",
52
52
  "@atlaskit/tokens": "8.6.1",
53
53
  "@atlaskit/tooltip": "^20.11.0",
54
54
  "@atlaskit/visually-hidden": "^3.0.0",