@atlaskit/editor-common 74.55.2 → 74.56.0

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 (33) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/commands/index.js +7 -0
  3. package/dist/cjs/commands/insert-block.js +60 -0
  4. package/dist/cjs/monitoring/error.js +1 -1
  5. package/dist/cjs/ui/DropList/index.js +1 -1
  6. package/dist/cjs/utils/create-wrap-selection-transaction.js +65 -0
  7. package/dist/cjs/utils/index.js +14 -0
  8. package/dist/cjs/utils/wrap-selection-in.js +25 -0
  9. package/dist/es2019/commands/index.js +2 -1
  10. package/dist/es2019/commands/insert-block.js +55 -0
  11. package/dist/es2019/monitoring/error.js +1 -1
  12. package/dist/es2019/ui/DropList/index.js +1 -1
  13. package/dist/es2019/utils/create-wrap-selection-transaction.js +66 -0
  14. package/dist/es2019/utils/index.js +3 -1
  15. package/dist/es2019/utils/wrap-selection-in.js +19 -0
  16. package/dist/esm/commands/index.js +2 -1
  17. package/dist/esm/commands/insert-block.js +53 -0
  18. package/dist/esm/monitoring/error.js +1 -1
  19. package/dist/esm/ui/DropList/index.js +1 -1
  20. package/dist/esm/utils/create-wrap-selection-transaction.js +60 -0
  21. package/dist/esm/utils/index.js +3 -1
  22. package/dist/esm/utils/wrap-selection-in.js +19 -0
  23. package/dist/types/commands/index.d.ts +1 -1
  24. package/dist/types/commands/insert-block.d.ts +5 -0
  25. package/dist/types/utils/create-wrap-selection-transaction.d.ts +15 -0
  26. package/dist/types/utils/index.d.ts +2 -0
  27. package/dist/types/utils/wrap-selection-in.d.ts +9 -0
  28. package/dist/types-ts4.5/commands/index.d.ts +1 -1
  29. package/dist/types-ts4.5/commands/insert-block.d.ts +5 -0
  30. package/dist/types-ts4.5/utils/create-wrap-selection-transaction.d.ts +15 -0
  31. package/dist/types-ts4.5/utils/index.d.ts +2 -0
  32. package/dist/types-ts4.5/utils/wrap-selection-in.d.ts +9 -0
  33. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 74.56.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`3542bead318`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3542bead318) - Move block type commands to next editor plugin actions
8
+
3
9
  ## 74.55.2
4
10
 
5
11
  ### Patch Changes
@@ -9,10 +9,17 @@ exports.clearEditorContent = exports.changeImageAlignment = void 0;
9
9
  exports.createParagraphAtEnd = createParagraphAtEnd;
10
10
  exports.createToggleBlockMarkOnRange = void 0;
11
11
  exports.findCutBefore = findCutBefore;
12
+ Object.defineProperty(exports, "insertBlock", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _insertBlock.insertBlock;
16
+ }
17
+ });
12
18
  exports.toggleBlockMark = void 0;
13
19
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
20
  var _state = require("@atlaskit/editor-prosemirror/state");
15
21
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
22
+ var _insertBlock = require("./insert-block");
16
23
  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; }
17
24
  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; }
18
25
  function addParagraphAtEnd(tr) {
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.insertBlock = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
9
+ var insertBlock = function insertBlock(state, nodeType, start, end, attrs) {
10
+ // To ensure that match is done after HardBreak.
11
+ var _state$schema$nodes = state.schema.nodes,
12
+ hardBreak = _state$schema$nodes.hardBreak,
13
+ codeBlock = _state$schema$nodes.codeBlock,
14
+ listItem = _state$schema$nodes.listItem;
15
+ var $pos = state.doc.resolve(start);
16
+ if ($pos.nodeAfter.type !== hardBreak) {
17
+ return null;
18
+ }
19
+
20
+ // To ensure no nesting is done. (unless we're inserting a codeBlock inside lists)
21
+ if ($pos.depth > 1 && !(nodeType === codeBlock && (0, _utils.hasParentNodeOfType)(listItem)(state.selection))) {
22
+ return null;
23
+ }
24
+
25
+ // Split at the start of autoformatting and delete formatting characters.
26
+ var tr = state.tr.delete(start, end).split(start);
27
+ var currentNode = tr.doc.nodeAt(start + 1);
28
+
29
+ // If node has more content split at the end of autoformatting.
30
+ var nodeHasMoreContent = false;
31
+ tr.doc.nodesBetween(start, start + currentNode.nodeSize, function (node, pos) {
32
+ if (!nodeHasMoreContent && node.type === hardBreak) {
33
+ nodeHasMoreContent = true;
34
+ tr = tr.split(pos + 1).delete(pos, pos + 1);
35
+ }
36
+ });
37
+ if (nodeHasMoreContent) {
38
+ currentNode = tr.doc.nodeAt(start + 1);
39
+ }
40
+
41
+ // Create new node and fill with content of current node.
42
+ var _state$schema$nodes2 = state.schema.nodes,
43
+ blockquote = _state$schema$nodes2.blockquote,
44
+ paragraph = _state$schema$nodes2.paragraph;
45
+ var content;
46
+ var depth;
47
+ if (nodeType === blockquote) {
48
+ depth = 3;
49
+ content = [paragraph.create({}, currentNode.content)];
50
+ } else {
51
+ depth = 2;
52
+ content = currentNode.content;
53
+ }
54
+ var newNode = nodeType.create(attrs, content);
55
+
56
+ // Add new node.
57
+ tr = tr.setSelection(new _state.NodeSelection(tr.doc.resolve(start + 1))).replaceSelectionWith(newNode).setSelection(new _state.TextSelection(tr.doc.resolve(start + depth)));
58
+ return tr;
59
+ };
60
+ exports.insertBlock = insertBlock;
@@ -16,7 +16,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
18
18
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
19
- var packageVersion = "74.55.2";
19
+ var packageVersion = "74.56.0";
20
20
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
21
21
  // Remove URL as it has UGC
22
22
  // TODO: Sanitise the URL instead of just removing it
@@ -24,7 +24,7 @@ var _templateObject, _templateObject2, _templateObject3;
24
24
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
25
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /** @jsx jsx */
26
26
  var packageName = "@atlaskit/editor-common";
27
- var packageVersion = "74.55.2";
27
+ var packageVersion = "74.56.0";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var DropList = /*#__PURE__*/function (_Component) {
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createWrapSelectionTransaction = createWrapSelectionTransaction;
7
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
8
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
9
+ var _editorCoreUtils = require("./editor-core-utils");
10
+ /**
11
+ * This function creates a new transaction that wraps the current selection
12
+ * in the specified node type if it results in a valid transaction.
13
+ * If not valid, it performs a safe insert operation.
14
+ *
15
+ * Example of when wrapping might not be valid is when attempting to wrap
16
+ * content that is already inside a panel with another panel
17
+ */
18
+ function createWrapSelectionTransaction(_ref) {
19
+ var state = _ref.state,
20
+ type = _ref.type,
21
+ nodeAttributes = _ref.nodeAttributes;
22
+ var tr = state.tr;
23
+ var _state$schema$marks = state.schema.marks,
24
+ alignment = _state$schema$marks.alignment,
25
+ indentation = _state$schema$marks.indentation;
26
+
27
+ /** Alignment or Indentation is not valid inside block types */
28
+ var removeAlignTr = (0, _editorCoreUtils.removeBlockMarks)(state, [alignment, indentation]);
29
+ tr = removeAlignTr || tr;
30
+
31
+ /**Get range and wrapping needed for the selection*/
32
+ var _getWrappingOptions = getWrappingOptions(state, type, nodeAttributes),
33
+ range = _getWrappingOptions.range,
34
+ wrapping = _getWrappingOptions.wrapping;
35
+ if (wrapping) {
36
+ tr.wrap(range, wrapping).scrollIntoView();
37
+ } else {
38
+ /** We always want to append a block type */
39
+ (0, _utils.safeInsert)(type.createAndFill(nodeAttributes))(tr).scrollIntoView();
40
+ }
41
+ return tr;
42
+ }
43
+ function getWrappingOptions(state, type, nodeAttributes) {
44
+ var _state$selection = state.selection,
45
+ $from = _state$selection.$from,
46
+ $to = _state$selection.$to;
47
+ var range = $from.blockRange($to);
48
+ var isAllowedChild = true;
49
+ /**
50
+ * Added a check to avoid wrapping codeblock
51
+ */
52
+ if (state.selection.empty) {
53
+ state.doc.nodesBetween($from.pos, $to.pos, function (node) {
54
+ if (!isAllowedChild) {
55
+ return false;
56
+ }
57
+ return isAllowedChild = node.type !== state.schema.nodes.codeBlock;
58
+ });
59
+ }
60
+ var wrapping = isAllowedChild && range && (0, _transform.findWrapping)(range, type, nodeAttributes);
61
+ return {
62
+ range: range,
63
+ wrapping: wrapping
64
+ };
65
+ }
@@ -275,6 +275,12 @@ Object.defineProperty(exports, "createRule", {
275
275
  return _inputRules.createRule;
276
276
  }
277
277
  });
278
+ Object.defineProperty(exports, "createWrapSelectionTransaction", {
279
+ enumerable: true,
280
+ get: function get() {
281
+ return _createWrapSelectionTransaction.createWrapSelectionTransaction;
282
+ }
283
+ });
278
284
  Object.defineProperty(exports, "createWrappingJoinRule", {
279
285
  enumerable: true,
280
286
  get: function get() {
@@ -1003,6 +1009,12 @@ Object.defineProperty(exports, "withImageLoader", {
1003
1009
  return _imageLoader.withImageLoader;
1004
1010
  }
1005
1011
  });
1012
+ Object.defineProperty(exports, "wrapSelectionIn", {
1013
+ enumerable: true,
1014
+ get: function get() {
1015
+ return _wrapSelectionIn.wrapSelectionIn;
1016
+ }
1017
+ });
1006
1018
  var _utils = require("@atlaskit/editor-prosemirror/utils");
1007
1019
  var _annotation = require("./annotation");
1008
1020
  var _macro = require("./macro");
@@ -1054,6 +1066,8 @@ var _getPerformanceTiming = require("./performance/get-performance-timing");
1054
1066
  var _countNodes = require("./count-nodes");
1055
1067
  var _inputRules = require("./input-rules");
1056
1068
  var _dedupe = require("./dedupe");
1069
+ var _createWrapSelectionTransaction = require("./create-wrap-selection-transaction");
1070
+ var _wrapSelectionIn = require("./wrap-selection-in");
1057
1071
  // prosemirror-history does not export its plugin key
1058
1072
  var pmHistoryPluginKey = 'history$';
1059
1073
  exports.pmHistoryPluginKey = pmHistoryPluginKey;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.wrapSelectionIn = wrapSelectionIn;
7
+ var _createWrapSelectionTransaction = require("./create-wrap-selection-transaction");
8
+ /**
9
+ * Function will add wrapping node.
10
+ * 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
11
+ * 2. If current block can not be wrapped inside wrapping block it will create a new block below selection,
12
+ * and set selection on it.
13
+ */
14
+ function wrapSelectionIn(type) {
15
+ return function (state, dispatch) {
16
+ var tr = (0, _createWrapSelectionTransaction.createWrapSelectionTransaction)({
17
+ state: state,
18
+ type: type
19
+ });
20
+ if (dispatch) {
21
+ dispatch(tr);
22
+ }
23
+ return true;
24
+ };
25
+ }
@@ -136,4 +136,5 @@ export function findCutBefore($pos) {
136
136
  }
137
137
  }
138
138
  return null;
139
- }
139
+ }
140
+ export { insertBlock } from './insert-block';
@@ -0,0 +1,55 @@
1
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
3
+ export const insertBlock = (state, nodeType, start, end, attrs) => {
4
+ // To ensure that match is done after HardBreak.
5
+ const {
6
+ hardBreak,
7
+ codeBlock,
8
+ listItem
9
+ } = state.schema.nodes;
10
+ const $pos = state.doc.resolve(start);
11
+ if ($pos.nodeAfter.type !== hardBreak) {
12
+ return null;
13
+ }
14
+
15
+ // To ensure no nesting is done. (unless we're inserting a codeBlock inside lists)
16
+ if ($pos.depth > 1 && !(nodeType === codeBlock && hasParentNodeOfType(listItem)(state.selection))) {
17
+ return null;
18
+ }
19
+
20
+ // Split at the start of autoformatting and delete formatting characters.
21
+ let tr = state.tr.delete(start, end).split(start);
22
+ let currentNode = tr.doc.nodeAt(start + 1);
23
+
24
+ // If node has more content split at the end of autoformatting.
25
+ let nodeHasMoreContent = false;
26
+ tr.doc.nodesBetween(start, start + currentNode.nodeSize, (node, pos) => {
27
+ if (!nodeHasMoreContent && node.type === hardBreak) {
28
+ nodeHasMoreContent = true;
29
+ tr = tr.split(pos + 1).delete(pos, pos + 1);
30
+ }
31
+ });
32
+ if (nodeHasMoreContent) {
33
+ currentNode = tr.doc.nodeAt(start + 1);
34
+ }
35
+
36
+ // Create new node and fill with content of current node.
37
+ const {
38
+ blockquote,
39
+ paragraph
40
+ } = state.schema.nodes;
41
+ let content;
42
+ let depth;
43
+ if (nodeType === blockquote) {
44
+ depth = 3;
45
+ content = [paragraph.create({}, currentNode.content)];
46
+ } else {
47
+ depth = 2;
48
+ content = currentNode.content;
49
+ }
50
+ const newNode = nodeType.create(attrs, content);
51
+
52
+ // Add new node.
53
+ tr = tr.setSelection(new NodeSelection(tr.doc.resolve(start + 1))).replaceSelectionWith(newNode).setSelection(new TextSelection(tr.doc.resolve(start + depth)));
54
+ return tr;
55
+ };
@@ -1,6 +1,6 @@
1
1
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
2
2
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
3
- const packageVersion = "74.55.2";
3
+ const packageVersion = "74.56.0";
4
4
  const sanitiseSentryEvents = (data, _hint) => {
5
5
  // Remove URL as it has UGC
6
6
  // TODO: Sanitise the URL instead of just removing it
@@ -8,7 +8,7 @@ import { themed } from '@atlaskit/theme/components';
8
8
  import { borderRadius } from '@atlaskit/theme/constants';
9
9
  import Layer from '../Layer';
10
10
  const packageName = "@atlaskit/editor-common";
11
- const packageVersion = "74.55.2";
11
+ const packageVersion = "74.56.0";
12
12
  const halfFocusRing = 1;
13
13
  const dropOffset = '0, 8';
14
14
  class DropList extends Component {
@@ -0,0 +1,66 @@
1
+ import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
2
+ import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
3
+ import { removeBlockMarks } from './editor-core-utils';
4
+
5
+ /**
6
+ * This function creates a new transaction that wraps the current selection
7
+ * in the specified node type if it results in a valid transaction.
8
+ * If not valid, it performs a safe insert operation.
9
+ *
10
+ * Example of when wrapping might not be valid is when attempting to wrap
11
+ * content that is already inside a panel with another panel
12
+ */
13
+ export function createWrapSelectionTransaction({
14
+ state,
15
+ type,
16
+ nodeAttributes
17
+ }) {
18
+ let {
19
+ tr
20
+ } = state;
21
+ const {
22
+ alignment,
23
+ indentation
24
+ } = state.schema.marks;
25
+
26
+ /** Alignment or Indentation is not valid inside block types */
27
+ const removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
28
+ tr = removeAlignTr || tr;
29
+
30
+ /**Get range and wrapping needed for the selection*/
31
+ const {
32
+ range,
33
+ wrapping
34
+ } = getWrappingOptions(state, type, nodeAttributes);
35
+ if (wrapping) {
36
+ tr.wrap(range, wrapping).scrollIntoView();
37
+ } else {
38
+ /** We always want to append a block type */
39
+ safeInsert(type.createAndFill(nodeAttributes))(tr).scrollIntoView();
40
+ }
41
+ return tr;
42
+ }
43
+ function getWrappingOptions(state, type, nodeAttributes) {
44
+ const {
45
+ $from,
46
+ $to
47
+ } = state.selection;
48
+ const range = $from.blockRange($to);
49
+ let isAllowedChild = true;
50
+ /**
51
+ * Added a check to avoid wrapping codeblock
52
+ */
53
+ if (state.selection.empty) {
54
+ state.doc.nodesBetween($from.pos, $to.pos, node => {
55
+ if (!isAllowedChild) {
56
+ return false;
57
+ }
58
+ return isAllowedChild = node.type !== state.schema.nodes.codeBlock;
59
+ });
60
+ }
61
+ const wrapping = isAllowedChild && range && findWrapping(range, type, nodeAttributes);
62
+ return {
63
+ range,
64
+ wrapping
65
+ };
66
+ }
@@ -193,4 +193,6 @@ export function isNodeEmpty(node) {
193
193
  });
194
194
  return !nonBlock.length && !block.filter(childNode => !!childNode.childCount && !(childNode.childCount === 1 && isEmptyParagraph(childNode.firstChild)) || childNode.isAtom).length;
195
195
  }
196
- export { dedupe } from './dedupe';
196
+ export { dedupe } from './dedupe';
197
+ export { createWrapSelectionTransaction } from './create-wrap-selection-transaction';
198
+ export { wrapSelectionIn } from './wrap-selection-in';
@@ -0,0 +1,19 @@
1
+ import { createWrapSelectionTransaction } from './create-wrap-selection-transaction';
2
+ /**
3
+ * Function will add wrapping node.
4
+ * 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
5
+ * 2. If current block can not be wrapped inside wrapping block it will create a new block below selection,
6
+ * and set selection on it.
7
+ */
8
+ export function wrapSelectionIn(type) {
9
+ return function (state, dispatch) {
10
+ let tr = createWrapSelectionTransaction({
11
+ state,
12
+ type
13
+ });
14
+ if (dispatch) {
15
+ dispatch(tr);
16
+ }
17
+ return true;
18
+ };
19
+ }
@@ -134,4 +134,5 @@ export function findCutBefore($pos) {
134
134
  }
135
135
  }
136
136
  return null;
137
- }
137
+ }
138
+ export { insertBlock } from './insert-block';
@@ -0,0 +1,53 @@
1
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
3
+ export var insertBlock = function insertBlock(state, nodeType, start, end, attrs) {
4
+ // To ensure that match is done after HardBreak.
5
+ var _state$schema$nodes = state.schema.nodes,
6
+ hardBreak = _state$schema$nodes.hardBreak,
7
+ codeBlock = _state$schema$nodes.codeBlock,
8
+ listItem = _state$schema$nodes.listItem;
9
+ var $pos = state.doc.resolve(start);
10
+ if ($pos.nodeAfter.type !== hardBreak) {
11
+ return null;
12
+ }
13
+
14
+ // To ensure no nesting is done. (unless we're inserting a codeBlock inside lists)
15
+ if ($pos.depth > 1 && !(nodeType === codeBlock && hasParentNodeOfType(listItem)(state.selection))) {
16
+ return null;
17
+ }
18
+
19
+ // Split at the start of autoformatting and delete formatting characters.
20
+ var tr = state.tr.delete(start, end).split(start);
21
+ var currentNode = tr.doc.nodeAt(start + 1);
22
+
23
+ // If node has more content split at the end of autoformatting.
24
+ var nodeHasMoreContent = false;
25
+ tr.doc.nodesBetween(start, start + currentNode.nodeSize, function (node, pos) {
26
+ if (!nodeHasMoreContent && node.type === hardBreak) {
27
+ nodeHasMoreContent = true;
28
+ tr = tr.split(pos + 1).delete(pos, pos + 1);
29
+ }
30
+ });
31
+ if (nodeHasMoreContent) {
32
+ currentNode = tr.doc.nodeAt(start + 1);
33
+ }
34
+
35
+ // Create new node and fill with content of current node.
36
+ var _state$schema$nodes2 = state.schema.nodes,
37
+ blockquote = _state$schema$nodes2.blockquote,
38
+ paragraph = _state$schema$nodes2.paragraph;
39
+ var content;
40
+ var depth;
41
+ if (nodeType === blockquote) {
42
+ depth = 3;
43
+ content = [paragraph.create({}, currentNode.content)];
44
+ } else {
45
+ depth = 2;
46
+ content = currentNode.content;
47
+ }
48
+ var newNode = nodeType.create(attrs, content);
49
+
50
+ // Add new node.
51
+ tr = tr.setSelection(new NodeSelection(tr.doc.resolve(start + 1))).replaceSelectionWith(newNode).setSelection(new TextSelection(tr.doc.resolve(start + depth)));
52
+ return tr;
53
+ };
@@ -6,7 +6,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
6
6
  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) { _defineProperty(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; }
7
7
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
8
8
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
9
- var packageVersion = "74.55.2";
9
+ var packageVersion = "74.56.0";
10
10
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
11
11
  // Remove URL as it has UGC
12
12
  // TODO: Sanitise the URL instead of just removing it
@@ -18,7 +18,7 @@ import { themed } from '@atlaskit/theme/components';
18
18
  import { borderRadius } from '@atlaskit/theme/constants';
19
19
  import Layer from '../Layer';
20
20
  var packageName = "@atlaskit/editor-common";
21
- var packageVersion = "74.55.2";
21
+ var packageVersion = "74.56.0";
22
22
  var halfFocusRing = 1;
23
23
  var dropOffset = '0, 8';
24
24
  var DropList = /*#__PURE__*/function (_Component) {
@@ -0,0 +1,60 @@
1
+ import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
2
+ import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
3
+ import { removeBlockMarks } from './editor-core-utils';
4
+
5
+ /**
6
+ * This function creates a new transaction that wraps the current selection
7
+ * in the specified node type if it results in a valid transaction.
8
+ * If not valid, it performs a safe insert operation.
9
+ *
10
+ * Example of when wrapping might not be valid is when attempting to wrap
11
+ * content that is already inside a panel with another panel
12
+ */
13
+ export function createWrapSelectionTransaction(_ref) {
14
+ var state = _ref.state,
15
+ type = _ref.type,
16
+ nodeAttributes = _ref.nodeAttributes;
17
+ var tr = state.tr;
18
+ var _state$schema$marks = state.schema.marks,
19
+ alignment = _state$schema$marks.alignment,
20
+ indentation = _state$schema$marks.indentation;
21
+
22
+ /** Alignment or Indentation is not valid inside block types */
23
+ var removeAlignTr = removeBlockMarks(state, [alignment, indentation]);
24
+ tr = removeAlignTr || tr;
25
+
26
+ /**Get range and wrapping needed for the selection*/
27
+ var _getWrappingOptions = getWrappingOptions(state, type, nodeAttributes),
28
+ range = _getWrappingOptions.range,
29
+ wrapping = _getWrappingOptions.wrapping;
30
+ if (wrapping) {
31
+ tr.wrap(range, wrapping).scrollIntoView();
32
+ } else {
33
+ /** We always want to append a block type */
34
+ safeInsert(type.createAndFill(nodeAttributes))(tr).scrollIntoView();
35
+ }
36
+ return tr;
37
+ }
38
+ function getWrappingOptions(state, type, nodeAttributes) {
39
+ var _state$selection = state.selection,
40
+ $from = _state$selection.$from,
41
+ $to = _state$selection.$to;
42
+ var range = $from.blockRange($to);
43
+ var isAllowedChild = true;
44
+ /**
45
+ * Added a check to avoid wrapping codeblock
46
+ */
47
+ if (state.selection.empty) {
48
+ state.doc.nodesBetween($from.pos, $to.pos, function (node) {
49
+ if (!isAllowedChild) {
50
+ return false;
51
+ }
52
+ return isAllowedChild = node.type !== state.schema.nodes.codeBlock;
53
+ });
54
+ }
55
+ var wrapping = isAllowedChild && range && findWrapping(range, type, nodeAttributes);
56
+ return {
57
+ range: range,
58
+ wrapping: wrapping
59
+ };
60
+ }
@@ -199,4 +199,6 @@ export function isNodeEmpty(node) {
199
199
  return !!childNode.childCount && !(childNode.childCount === 1 && isEmptyParagraph(childNode.firstChild)) || childNode.isAtom;
200
200
  }).length;
201
201
  }
202
- export { dedupe } from './dedupe';
202
+ export { dedupe } from './dedupe';
203
+ export { createWrapSelectionTransaction } from './create-wrap-selection-transaction';
204
+ export { wrapSelectionIn } from './wrap-selection-in';
@@ -0,0 +1,19 @@
1
+ import { createWrapSelectionTransaction } from './create-wrap-selection-transaction';
2
+ /**
3
+ * Function will add wrapping node.
4
+ * 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
5
+ * 2. If current block can not be wrapped inside wrapping block it will create a new block below selection,
6
+ * and set selection on it.
7
+ */
8
+ export function wrapSelectionIn(type) {
9
+ return function (state, dispatch) {
10
+ var tr = createWrapSelectionTransaction({
11
+ state: state,
12
+ type: type
13
+ });
14
+ if (dispatch) {
15
+ dispatch(tr);
16
+ }
17
+ return true;
18
+ };
19
+ }
@@ -16,4 +16,4 @@ export declare const createToggleBlockMarkOnRange: <T extends {} = object>(markT
16
16
  export declare const toggleBlockMark: <T extends {} = object>(markType: MarkType, getAttrs: (prevAttrs?: T | undefined, node?: PMNode) => false | T | undefined, allowedBlocks?: NodeType[] | ((schema: Schema, node: PMNode, parent: PMNode | null) => boolean) | undefined) => Command;
17
17
  export declare const clearEditorContent: Command;
18
18
  export declare function findCutBefore($pos: ResolvedPos): ResolvedPos | null;
19
- export {};
19
+ export { insertBlock } from './insert-block';
@@ -0,0 +1,5 @@
1
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const insertBlock: (state: EditorState, nodeType: NodeType, start: number, end: number, attrs?: {
4
+ [key: string]: any;
5
+ } | undefined) => Transaction | null;
@@ -0,0 +1,15 @@
1
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ /**
4
+ * This function creates a new transaction that wraps the current selection
5
+ * in the specified node type if it results in a valid transaction.
6
+ * If not valid, it performs a safe insert operation.
7
+ *
8
+ * Example of when wrapping might not be valid is when attempting to wrap
9
+ * content that is already inside a panel with another panel
10
+ */
11
+ export declare function createWrapSelectionTransaction({ state, type, nodeAttributes, }: {
12
+ state: EditorState;
13
+ type: NodeType;
14
+ nodeAttributes?: Record<string, any>;
15
+ }): import("prosemirror-state").Transaction;
@@ -80,3 +80,5 @@ export declare const isEmptyNode: (schema: Schema) => (node: PMNode) => boolean;
80
80
  */
81
81
  export declare function isNodeEmpty(node?: PMNode): boolean;
82
82
  export { dedupe } from './dedupe';
83
+ export { createWrapSelectionTransaction } from './create-wrap-selection-transaction';
84
+ export { wrapSelectionIn } from './wrap-selection-in';
@@ -0,0 +1,9 @@
1
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Command } from '../types';
3
+ /**
4
+ * Function will add wrapping node.
5
+ * 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
6
+ * 2. If current block can not be wrapped inside wrapping block it will create a new block below selection,
7
+ * and set selection on it.
8
+ */
9
+ export declare function wrapSelectionIn(type: NodeType): Command;
@@ -16,4 +16,4 @@ export declare const createToggleBlockMarkOnRange: <T extends {} = object>(markT
16
16
  export declare const toggleBlockMark: <T extends {} = object>(markType: MarkType, getAttrs: (prevAttrs?: T | undefined, node?: PMNode) => false | T | undefined, allowedBlocks?: NodeType[] | ((schema: Schema, node: PMNode, parent: PMNode | null) => boolean) | undefined) => Command;
17
17
  export declare const clearEditorContent: Command;
18
18
  export declare function findCutBefore($pos: ResolvedPos): ResolvedPos | null;
19
- export {};
19
+ export { insertBlock } from './insert-block';
@@ -0,0 +1,5 @@
1
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const insertBlock: (state: EditorState, nodeType: NodeType, start: number, end: number, attrs?: {
4
+ [key: string]: any;
5
+ } | undefined) => Transaction | null;
@@ -0,0 +1,15 @@
1
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ /**
4
+ * This function creates a new transaction that wraps the current selection
5
+ * in the specified node type if it results in a valid transaction.
6
+ * If not valid, it performs a safe insert operation.
7
+ *
8
+ * Example of when wrapping might not be valid is when attempting to wrap
9
+ * content that is already inside a panel with another panel
10
+ */
11
+ export declare function createWrapSelectionTransaction({ state, type, nodeAttributes, }: {
12
+ state: EditorState;
13
+ type: NodeType;
14
+ nodeAttributes?: Record<string, any>;
15
+ }): import("prosemirror-state").Transaction;
@@ -80,3 +80,5 @@ export declare const isEmptyNode: (schema: Schema) => (node: PMNode) => boolean;
80
80
  */
81
81
  export declare function isNodeEmpty(node?: PMNode): boolean;
82
82
  export { dedupe } from './dedupe';
83
+ export { createWrapSelectionTransaction } from './create-wrap-selection-transaction';
84
+ export { wrapSelectionIn } from './wrap-selection-in';
@@ -0,0 +1,9 @@
1
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Command } from '../types';
3
+ /**
4
+ * Function will add wrapping node.
5
+ * 1. If currently selected blocks can be wrapped in the wrapper type it will wrap them.
6
+ * 2. If current block can not be wrapped inside wrapping block it will create a new block below selection,
7
+ * and set selection on it.
8
+ */
9
+ export declare function wrapSelectionIn(type: NodeType): Command;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.55.2",
3
+ "version": "74.56.0",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"