@atlaskit/editor-common 74.44.0 → 74.45.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 (47) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/mark/commands.js +21 -26
  3. package/dist/cjs/media-single/constants.js +3 -1
  4. package/dist/cjs/media-single/index.js +6 -0
  5. package/dist/cjs/monitoring/error.js +1 -1
  6. package/dist/cjs/selection/index.js +36 -0
  7. package/dist/cjs/selection/utils.js +46 -1
  8. package/dist/cjs/ui/DropList/index.js +1 -1
  9. package/dist/cjs/utils/index.js +150 -0
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/mark/commands.js +21 -28
  12. package/dist/es2019/mark/index.js +1 -1
  13. package/dist/es2019/media-single/constants.js +1 -0
  14. package/dist/es2019/media-single/index.js +1 -1
  15. package/dist/es2019/monitoring/error.js +1 -1
  16. package/dist/es2019/selection/index.js +1 -1
  17. package/dist/es2019/selection/utils.js +52 -1
  18. package/dist/es2019/ui/DropList/index.js +1 -1
  19. package/dist/es2019/utils/index.js +139 -1
  20. package/dist/es2019/version.json +1 -1
  21. package/dist/esm/mark/commands.js +21 -26
  22. package/dist/esm/mark/index.js +1 -1
  23. package/dist/esm/media-single/constants.js +1 -0
  24. package/dist/esm/media-single/index.js +1 -1
  25. package/dist/esm/monitoring/error.js +1 -1
  26. package/dist/esm/selection/index.js +1 -1
  27. package/dist/esm/selection/utils.js +40 -1
  28. package/dist/esm/ui/DropList/index.js +1 -1
  29. package/dist/esm/utils/index.js +141 -1
  30. package/dist/esm/version.json +1 -1
  31. package/dist/types/mark/commands.d.ts +4 -4
  32. package/dist/types/mark/index.d.ts +1 -1
  33. package/dist/types/media-single/constants.d.ts +1 -0
  34. package/dist/types/media-single/index.d.ts +1 -1
  35. package/dist/types/selection/index.d.ts +1 -1
  36. package/dist/types/selection/utils.d.ts +9 -2
  37. package/dist/types/utils/index.d.ts +17 -0
  38. package/dist/types/utils/input-rules.d.ts +3 -2
  39. package/dist/types-ts4.5/mark/commands.d.ts +4 -4
  40. package/dist/types-ts4.5/mark/index.d.ts +1 -1
  41. package/dist/types-ts4.5/media-single/constants.d.ts +1 -0
  42. package/dist/types-ts4.5/media-single/index.d.ts +1 -1
  43. package/dist/types-ts4.5/selection/index.d.ts +1 -1
  44. package/dist/types-ts4.5/selection/utils.d.ts +9 -2
  45. package/dist/types-ts4.5/utils/index.d.ts +17 -0
  46. package/dist/types-ts4.5/utils/input-rules.d.ts +3 -2
  47. package/package.json +1 -1
@@ -1,3 +1,5 @@
1
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { GapCursorSelection } from './gap-cursor/selection';
1
3
  export const isSelectionAtStartOfNode = ($pos, parentNode) => {
2
4
  if (!parentNode) {
3
5
  return false;
@@ -27,4 +29,53 @@ export const isSelectionAtEndOfNode = ($pos, parentNode) => {
27
29
  }
28
30
  }
29
31
  return true;
30
- };
32
+ };
33
+ export function atTheEndOfDoc(state) {
34
+ const {
35
+ selection,
36
+ doc
37
+ } = state;
38
+ return doc.nodeSize - selection.$to.pos - 2 === selection.$to.depth;
39
+ }
40
+ export function atTheBeginningOfDoc(state) {
41
+ const {
42
+ selection
43
+ } = state;
44
+ return selection.$from.pos === selection.$from.depth;
45
+ }
46
+ export function atTheEndOfBlock(state) {
47
+ const {
48
+ selection
49
+ } = state;
50
+ const {
51
+ $to
52
+ } = selection;
53
+ if (selection instanceof GapCursorSelection) {
54
+ return false;
55
+ }
56
+ if (selection instanceof NodeSelection && selection.node.isBlock) {
57
+ return true;
58
+ }
59
+ return endPositionOfParent($to) === $to.pos + 1;
60
+ }
61
+ export function atTheBeginningOfBlock(state) {
62
+ const {
63
+ selection
64
+ } = state;
65
+ const {
66
+ $from
67
+ } = selection;
68
+ if (selection instanceof GapCursorSelection) {
69
+ return false;
70
+ }
71
+ if (selection instanceof NodeSelection && selection.node.isBlock) {
72
+ return true;
73
+ }
74
+ return startPositionOfParent($from) === $from.pos;
75
+ }
76
+ export function startPositionOfParent(resolvedPos) {
77
+ return resolvedPos.start(resolvedPos.depth);
78
+ }
79
+ export function endPositionOfParent(resolvedPos) {
80
+ return resolvedPos.end(resolvedPos.depth) + 1;
81
+ }
@@ -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.44.0";
11
+ const packageVersion = "74.45.0";
12
12
  const halfFocusRing = 1;
13
13
  const dropOffset = '0, 8';
14
14
  class DropList extends Component {
@@ -1,9 +1,11 @@
1
+ import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
1
2
  export { canApplyAnnotationOnRange, getAnnotationIdsFromRange } from './annotation';
2
3
  export { getExtensionLozengeData } from './macro';
3
4
  export { default as browser } from './browser';
4
5
  export { default as ErrorReporter } from './error-reporter';
5
6
  export { isPastDate, timestampToIsoFormat, timestampToString, timestampToTaskContext, timestampToUTCDate, todayTimestampInUTC } from './date';
6
7
  export { isElementInTableCell, isTextSelection, isLastItemMediaGroup, setNodeSelection, setTextSelection, nonNullable, stepAddsOneOf, stepHasSlice, extractSliceFromStep, isValidPosition, isEmptyParagraph, isInLayoutColumn, removeBlockMarks, filterChildrenBetween } from './editor-core-utils';
8
+ import { isEmptyParagraph } from './editor-core-utils';
7
9
  export { withImageLoader } from './imageLoader';
8
10
  export { absoluteBreakoutWidth, calcBreakoutWidth, calcWideWidth, breakoutConsts, calculateBreakoutStyles, calcBreakoutWidthPx, getNextBreakoutMode, getTitle } from './breakout';
9
11
  export { findChangedNodesFromTransaction, validNode, validateNodes, isType, isParagraph, isText, isLinkMark, SelectedState, isNodeSelectedOrInRange, isSupportedInParent, isMediaNode, isNodeBeforeMediaNode } from './nodes';
@@ -51,4 +53,140 @@ export function shallowEqual(obj1 = {}, obj2 = {}) {
51
53
  const keys2 = Object.keys(obj2);
52
54
  return keys1.length === keys2.length && keys1.reduce((acc, key) => acc && obj1[key] === obj2[key], true);
53
55
  }
54
- export { inputRuleWithAnalytics, createWrappingJoinRule, createRule } from './input-rules';
56
+ export { inputRuleWithAnalytics, createWrappingJoinRule, createRule } from './input-rules';
57
+ export function isSelectionInsideLastNodeInDocument(selection) {
58
+ const docNode = selection.$anchor.node(0);
59
+ const rootNode = selection.$anchor.node(1);
60
+ return docNode.lastChild === rootNode;
61
+ }
62
+ export const isInListItem = state => {
63
+ return hasParentNodeOfType(state.schema.nodes.listItem)(state.selection);
64
+ };
65
+
66
+ /**
67
+ * Find the farthest node given a condition
68
+ * @param predicate Function to check the node
69
+ */
70
+ export const findFarthestParentNode = predicate => $pos => {
71
+ let candidate = null;
72
+ for (let i = $pos.depth; i > 0; i--) {
73
+ const node = $pos.node(i);
74
+ if (predicate(node)) {
75
+ candidate = {
76
+ pos: i > 0 ? $pos.before(i) : 0,
77
+ start: $pos.start(i),
78
+ depth: i,
79
+ node
80
+ };
81
+ }
82
+ }
83
+ return candidate;
84
+ };
85
+ export const insideTableCell = state => {
86
+ const {
87
+ tableCell,
88
+ tableHeader
89
+ } = state.schema.nodes;
90
+ return hasParentNodeOfType([tableCell, tableHeader])(state.selection);
91
+ };
92
+
93
+ /**
94
+ * Traverse the document until an "ancestor" is found. Any nestable block can be an ancestor.
95
+ */
96
+ function findAncestorPosition(doc, pos) {
97
+ const nestableBlocks = ['blockquote', 'bulletList', 'orderedList'];
98
+ if (pos.depth === 1) {
99
+ return pos;
100
+ }
101
+ let node = pos.node(pos.depth);
102
+ let newPos = pos;
103
+ while (pos.depth >= 1) {
104
+ pos = doc.resolve(pos.before(pos.depth));
105
+ node = pos.node(pos.depth);
106
+ if (node && nestableBlocks.indexOf(node.type.name) !== -1) {
107
+ newPos = pos;
108
+ }
109
+ }
110
+ return newPos;
111
+ }
112
+ export function checkNodeDown(selection, doc, filter) {
113
+ const ancestorDepth = findAncestorPosition(doc, selection.$to).depth;
114
+
115
+ // Top level node
116
+ if (ancestorDepth === 0) {
117
+ return false;
118
+ }
119
+ const res = doc.resolve(selection.$to.after(ancestorDepth));
120
+ return res.nodeAfter ? filter(res.nodeAfter) : false;
121
+ }
122
+ export const isEmptyNode = schema => {
123
+ const {
124
+ doc,
125
+ paragraph,
126
+ codeBlock,
127
+ blockquote,
128
+ panel,
129
+ heading,
130
+ listItem,
131
+ bulletList,
132
+ orderedList,
133
+ taskList,
134
+ taskItem,
135
+ decisionList,
136
+ decisionItem,
137
+ media,
138
+ mediaGroup,
139
+ mediaSingle
140
+ } = schema.nodes;
141
+ const innerIsEmptyNode = node => {
142
+ switch (node.type) {
143
+ case media:
144
+ case mediaGroup:
145
+ case mediaSingle:
146
+ return false;
147
+ case paragraph:
148
+ case codeBlock:
149
+ case heading:
150
+ case taskItem:
151
+ case decisionItem:
152
+ return node.content.size === 0;
153
+ case blockquote:
154
+ case panel:
155
+ case listItem:
156
+ return node.content.size === 2 && innerIsEmptyNode(node.content.firstChild);
157
+ case bulletList:
158
+ case orderedList:
159
+ return node.content.size === 4 && innerIsEmptyNode(node.content.firstChild);
160
+ case taskList:
161
+ case decisionList:
162
+ return node.content.size === 2 && innerIsEmptyNode(node.content.firstChild);
163
+ case doc:
164
+ let isEmpty = true;
165
+ node.content.forEach(child => {
166
+ isEmpty = isEmpty && innerIsEmptyNode(child);
167
+ });
168
+ return isEmpty;
169
+ default:
170
+ return isNodeEmpty(node);
171
+ }
172
+ };
173
+ return innerIsEmptyNode;
174
+ };
175
+
176
+ /**
177
+ * Checks if a node has any content. Ignores node that only contain empty block nodes.
178
+ */
179
+ export function isNodeEmpty(node) {
180
+ if (node && node.textContent) {
181
+ return false;
182
+ }
183
+ if (!node || !node.childCount || node.childCount === 1 && isEmptyParagraph(node.firstChild)) {
184
+ return true;
185
+ }
186
+ const block = [];
187
+ const nonBlock = [];
188
+ node.forEach(child => {
189
+ child.isInline ? nonBlock.push(child) : block.push(child);
190
+ });
191
+ return !nonBlock.length && !block.filter(childNode => !!childNode.childCount && !(childNode.childCount === 1 && isEmptyParagraph(childNode.firstChild)) || childNode.isAtom).length;
192
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.44.0",
3
+ "version": "74.45.0",
4
4
  "sideEffects": false
5
5
  }
@@ -119,19 +119,19 @@ var entireSelectionContainsMark = function entireSelectionContainsMark(mark, doc
119
119
  return onlyContainsMark;
120
120
  };
121
121
  var toggleMarkInRange = function toggleMarkInRange(mark) {
122
- return function (state, dispatch) {
123
- var tr = state.tr;
124
- if (state.selection instanceof CellSelection) {
122
+ return function (_ref2) {
123
+ var tr = _ref2.tr;
124
+ if (tr.selection instanceof CellSelection) {
125
125
  var removeMark = true;
126
126
  var cells = [];
127
- state.selection.forEachCell(function (cell, cellPos) {
127
+ tr.selection.forEachCell(function (cell, cellPos) {
128
128
  cells.push({
129
129
  node: cell,
130
130
  pos: cellPos
131
131
  });
132
132
  var from = cellPos;
133
133
  var to = cellPos + cell.nodeSize;
134
- removeMark && (removeMark = entireSelectionContainsMark(mark, state.doc, from, to));
134
+ removeMark && (removeMark = entireSelectionContainsMark(mark, tr.doc, from, to));
135
135
  });
136
136
  for (var i = cells.length - 1; i >= 0; i--) {
137
137
  var cell = cells[i];
@@ -140,51 +140,46 @@ var toggleMarkInRange = function toggleMarkInRange(mark) {
140
140
  applyMarkOnRange(from, to, removeMark, mark, tr);
141
141
  }
142
142
  } else {
143
- var _state$selection = state.selection,
144
- $from = _state$selection.$from,
145
- $to = _state$selection.$to;
143
+ var _tr$selection = tr.selection,
144
+ $from = _tr$selection.$from,
145
+ $to = _tr$selection.$to;
146
146
  // We decide to remove the mark only if the entire selection contains the mark
147
147
  // Examples with *bold* text
148
148
  // Scenario 1: Selection contains both bold and non-bold text -> bold entire selection
149
149
  // Scenario 2: Selection contains only bold text -> un-bold entire selection
150
150
  // Scenario 3: Selection contains no bold text -> bold entire selection
151
- var _removeMark = entireSelectionContainsMark(mark, state.doc, $from.pos, $to.pos);
151
+ var _removeMark = entireSelectionContainsMark(mark, tr.doc, $from.pos, $to.pos);
152
152
  applyMarkOnRange($from.pos, $to.pos, _removeMark, mark, tr);
153
153
  }
154
154
  if (tr.docChanged) {
155
- if (dispatch) {
156
- dispatch(tr);
157
- }
158
- return true;
155
+ return tr;
159
156
  }
160
- return false;
157
+ return null;
161
158
  };
162
159
  };
163
160
 
164
161
  /**
165
- * A wrapper over the default toggleMark, except when we have a selection
166
- * we only toggle marks on text nodes rather than inline nodes.
162
+ * A custom version of the ProseMirror toggleMark, where we only toggle marks
163
+ * on text nodes in the selection rather than all inline nodes.
167
164
  * @param markType
168
165
  * @param attrs
169
166
  */
170
167
  export var toggleMark = function toggleMark(markType, attrs) {
171
- return function (state, dispatch) {
168
+ return function (_ref3) {
169
+ var tr = _ref3.tr;
172
170
  var mark = markType.create(attrs);
173
171
 
174
172
  // For cursor selections we can use the default behaviour.
175
- if (state.selection instanceof TextSelection && state.selection.$cursor) {
176
- var tr = state.tr;
177
- if (mark.isInSet(state.storedMarks || state.selection.$cursor.marks())) {
173
+ if (tr.selection instanceof TextSelection && tr.selection.$cursor) {
174
+ if (mark.isInSet(tr.storedMarks || tr.selection.$cursor.marks())) {
178
175
  tr.removeStoredMark(mark);
179
176
  } else {
180
177
  tr.addStoredMark(mark);
181
178
  }
182
- if (dispatch) {
183
- dispatch(tr);
184
- return true;
185
- }
186
- return false;
179
+ return tr;
187
180
  }
188
- return toggleMarkInRange(mark)(state, dispatch);
181
+ return toggleMarkInRange(mark)({
182
+ tr: tr
183
+ });
189
184
  };
190
185
  };
@@ -1,2 +1,2 @@
1
- export { transformSmartCharsMentionsAndEmojis, applyMarkOnRange, toggleMark, filterChildrenBetween } from './commands';
1
+ export { transformSmartCharsMentionsAndEmojis, applyMarkOnRange, filterChildrenBetween, toggleMark } from './commands';
2
2
  export { anyMarkActive } from './text-formatting';
@@ -5,6 +5,7 @@ export var MEDIA_SINGLE_HANDLE_MARGIN = 12;
5
5
  export var MEDIA_SINGLE_GUTTER_SIZE = MEDIA_SINGLE_HANDLE_MARGIN * 2;
6
6
  export var DEFAULT_IMAGE_WIDTH = 250;
7
7
  export var DEFAULT_IMAGE_HEIGHT = 200;
8
+ export var MEDIA_SINGLE_RESIZE_THROTTLE_TIME = 100;
8
9
  export var Layout = /*#__PURE__*/function (Layout) {
9
10
  Layout["FULL_WIDTH"] = "full-width";
10
11
  Layout["WIDE"] = "wide";
@@ -1,2 +1,2 @@
1
- export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts } from './constants';
1
+ export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, MEDIA_SINGLE_RESIZE_THROTTLE_TIME, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts } from './constants';
2
2
  export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, roundToNearest } from './utils';
@@ -6,7 +6,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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.44.0";
9
+ var packageVersion = "74.45.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
@@ -1,4 +1,4 @@
1
1
  export { RelativeSelectionPos } from './types';
2
2
  export { GapCursorSelection, Side, JSON_ID, GapBookmark } from './gap-cursor/selection';
3
3
  export { isIgnored, isValidTargetNode } from './gap-cursor/utils';
4
- export { isSelectionAtStartOfNode, isSelectionAtEndOfNode } from './utils';
4
+ export { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, atTheEndOfDoc, endPositionOfParent, isSelectionAtEndOfNode, isSelectionAtStartOfNode, startPositionOfParent } from './utils';
@@ -1,3 +1,5 @@
1
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { GapCursorSelection } from './gap-cursor/selection';
1
3
  export var isSelectionAtStartOfNode = function isSelectionAtStartOfNode($pos, parentNode) {
2
4
  if (!parentNode) {
3
5
  return false;
@@ -27,4 +29,41 @@ export var isSelectionAtEndOfNode = function isSelectionAtEndOfNode($pos, parent
27
29
  }
28
30
  }
29
31
  return true;
30
- };
32
+ };
33
+ export function atTheEndOfDoc(state) {
34
+ var selection = state.selection,
35
+ doc = state.doc;
36
+ return doc.nodeSize - selection.$to.pos - 2 === selection.$to.depth;
37
+ }
38
+ export function atTheBeginningOfDoc(state) {
39
+ var selection = state.selection;
40
+ return selection.$from.pos === selection.$from.depth;
41
+ }
42
+ export function atTheEndOfBlock(state) {
43
+ var selection = state.selection;
44
+ var $to = selection.$to;
45
+ if (selection instanceof GapCursorSelection) {
46
+ return false;
47
+ }
48
+ if (selection instanceof NodeSelection && selection.node.isBlock) {
49
+ return true;
50
+ }
51
+ return endPositionOfParent($to) === $to.pos + 1;
52
+ }
53
+ export function atTheBeginningOfBlock(state) {
54
+ var selection = state.selection;
55
+ var $from = selection.$from;
56
+ if (selection instanceof GapCursorSelection) {
57
+ return false;
58
+ }
59
+ if (selection instanceof NodeSelection && selection.node.isBlock) {
60
+ return true;
61
+ }
62
+ return startPositionOfParent($from) === $from.pos;
63
+ }
64
+ export function startPositionOfParent(resolvedPos) {
65
+ return resolvedPos.start(resolvedPos.depth);
66
+ }
67
+ export function endPositionOfParent(resolvedPos) {
68
+ return resolvedPos.end(resolvedPos.depth) + 1;
69
+ }
@@ -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.44.0";
21
+ var packageVersion = "74.45.0";
22
22
  var halfFocusRing = 1;
23
23
  var dropOffset = '0, 8';
24
24
  var DropList = /*#__PURE__*/function (_Component) {
@@ -1,9 +1,11 @@
1
+ import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
1
2
  export { canApplyAnnotationOnRange, getAnnotationIdsFromRange } from './annotation';
2
3
  export { getExtensionLozengeData } from './macro';
3
4
  export { default as browser } from './browser';
4
5
  export { default as ErrorReporter } from './error-reporter';
5
6
  export { isPastDate, timestampToIsoFormat, timestampToString, timestampToTaskContext, timestampToUTCDate, todayTimestampInUTC } from './date';
6
7
  export { isElementInTableCell, isTextSelection, isLastItemMediaGroup, setNodeSelection, setTextSelection, nonNullable, stepAddsOneOf, stepHasSlice, extractSliceFromStep, isValidPosition, isEmptyParagraph, isInLayoutColumn, removeBlockMarks, filterChildrenBetween } from './editor-core-utils';
8
+ import { isEmptyParagraph } from './editor-core-utils';
7
9
  export { withImageLoader } from './imageLoader';
8
10
  export { absoluteBreakoutWidth, calcBreakoutWidth, calcWideWidth, breakoutConsts, calculateBreakoutStyles, calcBreakoutWidthPx, getNextBreakoutMode, getTitle } from './breakout';
9
11
  export { findChangedNodesFromTransaction, validNode, validateNodes, isType, isParagraph, isText, isLinkMark, SelectedState, isNodeSelectedOrInRange, isSupportedInParent, isMediaNode, isNodeBeforeMediaNode } from './nodes';
@@ -55,4 +57,142 @@ export function shallowEqual() {
55
57
  return acc && obj1[key] === obj2[key];
56
58
  }, true);
57
59
  }
58
- export { inputRuleWithAnalytics, createWrappingJoinRule, createRule } from './input-rules';
60
+ export { inputRuleWithAnalytics, createWrappingJoinRule, createRule } from './input-rules';
61
+ export function isSelectionInsideLastNodeInDocument(selection) {
62
+ var docNode = selection.$anchor.node(0);
63
+ var rootNode = selection.$anchor.node(1);
64
+ return docNode.lastChild === rootNode;
65
+ }
66
+ export var isInListItem = function isInListItem(state) {
67
+ return hasParentNodeOfType(state.schema.nodes.listItem)(state.selection);
68
+ };
69
+
70
+ /**
71
+ * Find the farthest node given a condition
72
+ * @param predicate Function to check the node
73
+ */
74
+ export var findFarthestParentNode = function findFarthestParentNode(predicate) {
75
+ return function ($pos) {
76
+ var candidate = null;
77
+ for (var i = $pos.depth; i > 0; i--) {
78
+ var _node = $pos.node(i);
79
+ if (predicate(_node)) {
80
+ candidate = {
81
+ pos: i > 0 ? $pos.before(i) : 0,
82
+ start: $pos.start(i),
83
+ depth: i,
84
+ node: _node
85
+ };
86
+ }
87
+ }
88
+ return candidate;
89
+ };
90
+ };
91
+ export var insideTableCell = function insideTableCell(state) {
92
+ var _state$schema$nodes = state.schema.nodes,
93
+ tableCell = _state$schema$nodes.tableCell,
94
+ tableHeader = _state$schema$nodes.tableHeader;
95
+ return hasParentNodeOfType([tableCell, tableHeader])(state.selection);
96
+ };
97
+
98
+ /**
99
+ * Traverse the document until an "ancestor" is found. Any nestable block can be an ancestor.
100
+ */
101
+ function findAncestorPosition(doc, pos) {
102
+ var nestableBlocks = ['blockquote', 'bulletList', 'orderedList'];
103
+ if (pos.depth === 1) {
104
+ return pos;
105
+ }
106
+ var node = pos.node(pos.depth);
107
+ var newPos = pos;
108
+ while (pos.depth >= 1) {
109
+ pos = doc.resolve(pos.before(pos.depth));
110
+ node = pos.node(pos.depth);
111
+ if (node && nestableBlocks.indexOf(node.type.name) !== -1) {
112
+ newPos = pos;
113
+ }
114
+ }
115
+ return newPos;
116
+ }
117
+ export function checkNodeDown(selection, doc, filter) {
118
+ var ancestorDepth = findAncestorPosition(doc, selection.$to).depth;
119
+
120
+ // Top level node
121
+ if (ancestorDepth === 0) {
122
+ return false;
123
+ }
124
+ var res = doc.resolve(selection.$to.after(ancestorDepth));
125
+ return res.nodeAfter ? filter(res.nodeAfter) : false;
126
+ }
127
+ export var isEmptyNode = function isEmptyNode(schema) {
128
+ var _schema$nodes = schema.nodes,
129
+ doc = _schema$nodes.doc,
130
+ paragraph = _schema$nodes.paragraph,
131
+ codeBlock = _schema$nodes.codeBlock,
132
+ blockquote = _schema$nodes.blockquote,
133
+ panel = _schema$nodes.panel,
134
+ heading = _schema$nodes.heading,
135
+ listItem = _schema$nodes.listItem,
136
+ bulletList = _schema$nodes.bulletList,
137
+ orderedList = _schema$nodes.orderedList,
138
+ taskList = _schema$nodes.taskList,
139
+ taskItem = _schema$nodes.taskItem,
140
+ decisionList = _schema$nodes.decisionList,
141
+ decisionItem = _schema$nodes.decisionItem,
142
+ media = _schema$nodes.media,
143
+ mediaGroup = _schema$nodes.mediaGroup,
144
+ mediaSingle = _schema$nodes.mediaSingle;
145
+ var innerIsEmptyNode = function innerIsEmptyNode(node) {
146
+ switch (node.type) {
147
+ case media:
148
+ case mediaGroup:
149
+ case mediaSingle:
150
+ return false;
151
+ case paragraph:
152
+ case codeBlock:
153
+ case heading:
154
+ case taskItem:
155
+ case decisionItem:
156
+ return node.content.size === 0;
157
+ case blockquote:
158
+ case panel:
159
+ case listItem:
160
+ return node.content.size === 2 && innerIsEmptyNode(node.content.firstChild);
161
+ case bulletList:
162
+ case orderedList:
163
+ return node.content.size === 4 && innerIsEmptyNode(node.content.firstChild);
164
+ case taskList:
165
+ case decisionList:
166
+ return node.content.size === 2 && innerIsEmptyNode(node.content.firstChild);
167
+ case doc:
168
+ var isEmpty = true;
169
+ node.content.forEach(function (child) {
170
+ isEmpty = isEmpty && innerIsEmptyNode(child);
171
+ });
172
+ return isEmpty;
173
+ default:
174
+ return isNodeEmpty(node);
175
+ }
176
+ };
177
+ return innerIsEmptyNode;
178
+ };
179
+
180
+ /**
181
+ * Checks if a node has any content. Ignores node that only contain empty block nodes.
182
+ */
183
+ export function isNodeEmpty(node) {
184
+ if (node && node.textContent) {
185
+ return false;
186
+ }
187
+ if (!node || !node.childCount || node.childCount === 1 && isEmptyParagraph(node.firstChild)) {
188
+ return true;
189
+ }
190
+ var block = [];
191
+ var nonBlock = [];
192
+ node.forEach(function (child) {
193
+ child.isInline ? nonBlock.push(child) : block.push(child);
194
+ });
195
+ return !nonBlock.length && !block.filter(function (childNode) {
196
+ return !!childNode.childCount && !(childNode.childCount === 1 && isEmptyParagraph(childNode.firstChild)) || childNode.isAtom;
197
+ }).length;
198
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.44.0",
3
+ "version": "74.45.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import type { Mark, MarkType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
- import type { Command } from '../types';
3
+ import type { PluginCommand } from '../types';
4
4
  export declare function filterChildrenBetween(doc: PMNode, from: number, to: number, predicate: (node: PMNode, pos: number, parent: PMNode | null) => boolean | undefined): {
5
5
  node: PMNode;
6
6
  pos: number;
@@ -8,11 +8,11 @@ export declare function filterChildrenBetween(doc: PMNode, from: number, to: num
8
8
  export declare const transformSmartCharsMentionsAndEmojis: (from: number, to: number, tr: Transaction) => void;
9
9
  export declare const applyMarkOnRange: (from: number, to: number, removeMark: boolean, mark: Mark, tr: Transaction) => Transaction;
10
10
  /**
11
- * A wrapper over the default toggleMark, except when we have a selection
12
- * we only toggle marks on text nodes rather than inline nodes.
11
+ * A custom version of the ProseMirror toggleMark, where we only toggle marks
12
+ * on text nodes in the selection rather than all inline nodes.
13
13
  * @param markType
14
14
  * @param attrs
15
15
  */
16
16
  export declare const toggleMark: (markType: MarkType, attrs?: {
17
17
  [key: string]: any;
18
- } | undefined) => Command;
18
+ } | undefined) => PluginCommand;
@@ -1,2 +1,2 @@
1
- export { transformSmartCharsMentionsAndEmojis, applyMarkOnRange, toggleMark, filterChildrenBetween, } from './commands';
1
+ export { transformSmartCharsMentionsAndEmojis, applyMarkOnRange, filterChildrenBetween, toggleMark, } from './commands';
2
2
  export { anyMarkActive } from './text-formatting';
@@ -6,6 +6,7 @@ export declare const MEDIA_SINGLE_HANDLE_MARGIN = 12;
6
6
  export declare const MEDIA_SINGLE_GUTTER_SIZE: number;
7
7
  export declare const DEFAULT_IMAGE_WIDTH = 250;
8
8
  export declare const DEFAULT_IMAGE_HEIGHT = 200;
9
+ export declare const MEDIA_SINGLE_RESIZE_THROTTLE_TIME = 100;
9
10
  export declare enum Layout {
10
11
  FULL_WIDTH = "full-width",
11
12
  WIDE = "wide",
@@ -1,2 +1,2 @@
1
- export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts, } from './constants';
1
+ export { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, MEDIA_SINGLE_GUTTER_SIZE, MEDIA_SINGLE_RESIZE_THROTTLE_TIME, Layout as MediaSingleLayout, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, wrappedLayouts, } from './constants';
2
2
  export { getMediaSinglePixelWidth, calcMediaSinglePixelWidth, calcMediaSingleMaxWidth, getMediaSingleInitialWidth, calculateOffsetLeft, roundToNearest, } from './utils';
@@ -2,4 +2,4 @@ export { RelativeSelectionPos } from './types';
2
2
  export type { SelectionPluginState, EditorSelectionAPI } from './types';
3
3
  export { GapCursorSelection, Side, JSON_ID, GapBookmark, } from './gap-cursor/selection';
4
4
  export { isIgnored, isValidTargetNode } from './gap-cursor/utils';
5
- export { isSelectionAtStartOfNode, isSelectionAtEndOfNode } from './utils';
5
+ export { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, atTheEndOfDoc, endPositionOfParent, isSelectionAtEndOfNode, isSelectionAtStartOfNode, startPositionOfParent, } from './utils';
@@ -1,4 +1,11 @@
1
- import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
- import { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
1
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
3
4
  export declare const isSelectionAtStartOfNode: ($pos: ResolvedPos, parentNode?: ContentNodeWithPos) => boolean;
4
5
  export declare const isSelectionAtEndOfNode: ($pos: ResolvedPos, parentNode?: ContentNodeWithPos) => boolean;
6
+ export declare function atTheEndOfDoc(state: EditorState): boolean;
7
+ export declare function atTheBeginningOfDoc(state: EditorState): boolean;
8
+ export declare function atTheEndOfBlock(state: EditorState): boolean;
9
+ export declare function atTheBeginningOfBlock(state: EditorState): boolean;
10
+ export declare function startPositionOfParent(resolvedPos: ResolvedPos): number;
11
+ export declare function endPositionOfParent(resolvedPos: ResolvedPos): number;