@atlaskit/editor-plugin-block-controls 11.2.7 → 11.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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/pm-plugins/decorations-drag-handle.js +2 -2
- package/dist/cjs/pm-plugins/decorations-quick-insert-button.js +1 -1
- package/dist/cjs/pm-plugins/utils/marks.js +46 -1
- package/dist/es2019/pm-plugins/decorations-drag-handle.js +3 -3
- package/dist/es2019/pm-plugins/decorations-quick-insert-button.js +2 -2
- package/dist/es2019/pm-plugins/utils/marks.js +39 -0
- package/dist/esm/pm-plugins/decorations-drag-handle.js +3 -3
- package/dist/esm/pm-plugins/decorations-quick-insert-button.js +2 -2
- package/dist/esm/pm-plugins/utils/marks.js +45 -0
- package/dist/types/pm-plugins/utils/marks.d.ts +7 -1
- package/dist/types-ts4.5/pm-plugins/utils/marks.d.ts +7 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 11.2.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`f35afb9a5ed6e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f35afb9a5ed6e) -
|
|
8
|
+
Fix getMatchingBlockMarks to check both adjacent siblings before returning marks
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 11.2.8
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 11.2.7
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -57,7 +57,7 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
|
|
|
57
57
|
* Exclude 'breakout' on purpose, so the widgets render at the top of the document to avoid z-index issues
|
|
58
58
|
* Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
|
|
59
59
|
*/
|
|
60
|
-
marks: (0, _expValEquals.expValEquals)('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : (0, _marks.getActiveBlockMarks)(editorState, pos),
|
|
60
|
+
marks: (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true) ? (0, _marks.getMatchingBlockMarks)(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : (0, _expValEquals.expValEquals)('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : (0, _marks.getActiveBlockMarks)(editorState, pos),
|
|
61
61
|
destroy: function destroy(node) {
|
|
62
62
|
unbind && unbind();
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
|
|
|
66
66
|
type: _decorationsCommon.TYPE_HANDLE_DEC,
|
|
67
67
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
68
68
|
testid: "".concat(_decorationsCommon.TYPE_HANDLE_DEC, "-").concat((0, _uuid.default)()),
|
|
69
|
-
marks: (0, _expValEquals.expValEquals)('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : (0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true) ? (0, _marks.getActiveBlockMarks)(editorState, pos) : undefined,
|
|
69
|
+
marks: (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true) ? (0, _marks.getMatchingBlockMarks)(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : (0, _expValEquals.expValEquals)('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : (0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true) ? (0, _marks.getActiveBlockMarks)(editorState, pos) : undefined,
|
|
70
70
|
destroy: function destroy(node) {
|
|
71
71
|
unbind && unbind();
|
|
72
72
|
}
|
|
@@ -44,7 +44,7 @@ var quickInsertButtonDecoration = exports.quickInsertButtonDecoration = function
|
|
|
44
44
|
* Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
|
-
marks: (0, _expValEquals.expValEquals)('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : (0, _marks.getActiveBlockMarks)(editorState, rootPos),
|
|
47
|
+
marks: (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true) ? (0, _marks.getMatchingBlockMarks)(editorState, rootPos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : (0, _expValEquals.expValEquals)('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : (0, _marks.getActiveBlockMarks)(editorState, rootPos),
|
|
48
48
|
destroy: function destroy(_) {
|
|
49
49
|
if ((0, _platformFeatureFlags.fg)('platform_editor_fix_widget_destroy')) {
|
|
50
50
|
nodeViewPortalProviderAPI.remove(key);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getActiveBlockMarks = void 0;
|
|
6
|
+
exports.getMatchingBlockMarks = exports.getActiveBlockMarks = void 0;
|
|
7
7
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
8
8
|
/**
|
|
9
9
|
* Remove this when platform_editor_clean_up_widget_mark_logic is cleaned up.
|
|
@@ -56,4 +56,49 @@ var getActiveBlockMarks = exports.getActiveBlockMarks = function getActiveBlockM
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
return supportedMarks;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** True when `mark` has an equal counterpart (type + attrs) in `marks`. */
|
|
62
|
+
var hasMatchingMark = function hasMatchingMark(mark, marks) {
|
|
63
|
+
var found = mark.type.isInSet(marks);
|
|
64
|
+
return !!found && mark.eq(found);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns supported block marks at `pos` only when both adjacent siblings
|
|
69
|
+
* share the exact same set of those marks. Returns `[]` when they differ,
|
|
70
|
+
* so the widget sits outside all mark wrappers and avoids mis-nesting.
|
|
71
|
+
*/
|
|
72
|
+
var getMatchingBlockMarks = exports.getMatchingBlockMarks = function getMatchingBlockMarks(state, pos, supportedMarkTypes) {
|
|
73
|
+
var _nodeAfter$marks, _nodeBefore$marks;
|
|
74
|
+
var resolvedPos = state.doc.resolve(pos);
|
|
75
|
+
var validMarkTypes = supportedMarkTypes.filter(Boolean);
|
|
76
|
+
var supportedMarks = resolvedPos.marks().filter(function (mark) {
|
|
77
|
+
return validMarkTypes.includes(mark.type);
|
|
78
|
+
});
|
|
79
|
+
if (supportedMarks.length === 0) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
var nodeAfter = resolvedPos.nodeAfter,
|
|
83
|
+
nodeBefore = resolvedPos.nodeBefore;
|
|
84
|
+
var nextMarks = (_nodeAfter$marks = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.marks) !== null && _nodeAfter$marks !== void 0 ? _nodeAfter$marks : [];
|
|
85
|
+
var prevMarks = (_nodeBefore$marks = nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.marks) !== null && _nodeBefore$marks !== void 0 ? _nodeBefore$marks : [];
|
|
86
|
+
var nextSupported = nextMarks.filter(function (m) {
|
|
87
|
+
return validMarkTypes.includes(m.type);
|
|
88
|
+
});
|
|
89
|
+
var allMatchNext = supportedMarks.every(function (m) {
|
|
90
|
+
return hasMatchingMark(m, nextMarks);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// First node — no previous sibling to compare against.
|
|
94
|
+
if (!nodeBefore) {
|
|
95
|
+
return nextSupported.length === supportedMarks.length && allMatchNext ? supportedMarks : [];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// `supportedMarks` already comes from `nodeBefore` (via resolvedPos.marks()).
|
|
99
|
+
// Compare counts to guard against extra supported marks on either side.
|
|
100
|
+
var prevSupported = prevMarks.filter(function (m) {
|
|
101
|
+
return validMarkTypes.includes(m.type);
|
|
102
|
+
});
|
|
103
|
+
return prevSupported.length === nextSupported.length && allMatchNext ? supportedMarks : [];
|
|
59
104
|
};
|
|
@@ -9,7 +9,7 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
|
9
9
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
10
10
|
import { DragHandle, DragHandleWithVisibility } from '../ui/drag-handle';
|
|
11
11
|
import { TYPE_HANDLE_DEC, TYPE_NODE_DEC, unmountDecorations } from './decorations-common';
|
|
12
|
-
import { getActiveBlockMarks } from './utils/marks';
|
|
12
|
+
import { getActiveBlockMarks, getMatchingBlockMarks } from './utils/marks';
|
|
13
13
|
export const emptyParagraphNodeDecorations = () => {
|
|
14
14
|
const anchorName = `--node-anchor-paragraph-0`;
|
|
15
15
|
const style = `anchor-name: ${anchorName}; margin-top: 0px;`;
|
|
@@ -48,7 +48,7 @@ export const dragHandleDecoration = ({
|
|
|
48
48
|
* Exclude 'breakout' on purpose, so the widgets render at the top of the document to avoid z-index issues
|
|
49
49
|
* Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
|
|
50
50
|
*/
|
|
51
|
-
marks: expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, pos),
|
|
51
|
+
marks: expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? getMatchingBlockMarks(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, pos),
|
|
52
52
|
destroy: node => {
|
|
53
53
|
unbind && unbind();
|
|
54
54
|
}
|
|
@@ -57,7 +57,7 @@ export const dragHandleDecoration = ({
|
|
|
57
57
|
type: TYPE_HANDLE_DEC,
|
|
58
58
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
59
59
|
testid: `${TYPE_HANDLE_DEC}-${uuid()}`,
|
|
60
|
-
marks: expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true) ? getActiveBlockMarks(editorState, pos) : undefined,
|
|
60
|
+
marks: expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? getMatchingBlockMarks(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true) ? getActiveBlockMarks(editorState, pos) : undefined,
|
|
61
61
|
destroy: node => {
|
|
62
62
|
unbind && unbind();
|
|
63
63
|
}
|
|
@@ -6,7 +6,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
6
6
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
7
7
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
8
8
|
import { QuickInsertWithVisibility } from '../ui/quick-insert-button';
|
|
9
|
-
import { getActiveBlockMarks } from './utils/marks';
|
|
9
|
+
import { getActiveBlockMarks, getMatchingBlockMarks } from './utils/marks';
|
|
10
10
|
const TYPE_QUICK_INSERT = 'INSERT_BUTTON';
|
|
11
11
|
export const findQuickInsertInsertButtonDecoration = (decorations, from, to) => {
|
|
12
12
|
return decorations.find(from, to, spec => spec.type === TYPE_QUICK_INSERT);
|
|
@@ -35,7 +35,7 @@ export const quickInsertButtonDecoration = ({
|
|
|
35
35
|
* Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
-
marks: expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, rootPos),
|
|
38
|
+
marks: expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? getMatchingBlockMarks(editorState, rootPos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, rootPos),
|
|
39
39
|
destroy: _ => {
|
|
40
40
|
if (fg('platform_editor_fix_widget_destroy')) {
|
|
41
41
|
nodeViewPortalProviderAPI.remove(key);
|
|
@@ -45,4 +45,43 @@ export const getActiveBlockMarks = (state, pos) => {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
return supportedMarks;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** True when `mark` has an equal counterpart (type + attrs) in `marks`. */
|
|
51
|
+
const hasMatchingMark = (mark, marks) => {
|
|
52
|
+
const found = mark.type.isInSet(marks);
|
|
53
|
+
return !!found && mark.eq(found);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns supported block marks at `pos` only when both adjacent siblings
|
|
58
|
+
* share the exact same set of those marks. Returns `[]` when they differ,
|
|
59
|
+
* so the widget sits outside all mark wrappers and avoids mis-nesting.
|
|
60
|
+
*/
|
|
61
|
+
export const getMatchingBlockMarks = (state, pos, supportedMarkTypes) => {
|
|
62
|
+
var _nodeAfter$marks, _nodeBefore$marks;
|
|
63
|
+
const resolvedPos = state.doc.resolve(pos);
|
|
64
|
+
const validMarkTypes = supportedMarkTypes.filter(Boolean);
|
|
65
|
+
const supportedMarks = resolvedPos.marks().filter(mark => validMarkTypes.includes(mark.type));
|
|
66
|
+
if (supportedMarks.length === 0) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const {
|
|
70
|
+
nodeAfter,
|
|
71
|
+
nodeBefore
|
|
72
|
+
} = resolvedPos;
|
|
73
|
+
const nextMarks = (_nodeAfter$marks = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.marks) !== null && _nodeAfter$marks !== void 0 ? _nodeAfter$marks : [];
|
|
74
|
+
const prevMarks = (_nodeBefore$marks = nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.marks) !== null && _nodeBefore$marks !== void 0 ? _nodeBefore$marks : [];
|
|
75
|
+
const nextSupported = nextMarks.filter(m => validMarkTypes.includes(m.type));
|
|
76
|
+
const allMatchNext = supportedMarks.every(m => hasMatchingMark(m, nextMarks));
|
|
77
|
+
|
|
78
|
+
// First node — no previous sibling to compare against.
|
|
79
|
+
if (!nodeBefore) {
|
|
80
|
+
return nextSupported.length === supportedMarks.length && allMatchNext ? supportedMarks : [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// `supportedMarks` already comes from `nodeBefore` (via resolvedPos.marks()).
|
|
84
|
+
// Compare counts to guard against extra supported marks on either side.
|
|
85
|
+
const prevSupported = prevMarks.filter(m => validMarkTypes.includes(m.type));
|
|
86
|
+
return prevSupported.length === nextSupported.length && allMatchNext ? supportedMarks : [];
|
|
48
87
|
};
|
|
@@ -10,7 +10,7 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
|
10
10
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
11
11
|
import { DragHandle, DragHandleWithVisibility } from '../ui/drag-handle';
|
|
12
12
|
import { TYPE_HANDLE_DEC, TYPE_NODE_DEC, unmountDecorations } from './decorations-common';
|
|
13
|
-
import { getActiveBlockMarks } from './utils/marks';
|
|
13
|
+
import { getActiveBlockMarks, getMatchingBlockMarks } from './utils/marks';
|
|
14
14
|
export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
|
|
15
15
|
var anchorName = "--node-anchor-paragraph-0";
|
|
16
16
|
var style = "anchor-name: ".concat(anchorName, "; margin-top: 0px;");
|
|
@@ -49,7 +49,7 @@ export var dragHandleDecoration = function dragHandleDecoration(_ref) {
|
|
|
49
49
|
* Exclude 'breakout' on purpose, so the widgets render at the top of the document to avoid z-index issues
|
|
50
50
|
* Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
|
|
51
51
|
*/
|
|
52
|
-
marks: expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, pos),
|
|
52
|
+
marks: expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? getMatchingBlockMarks(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, pos),
|
|
53
53
|
destroy: function destroy(node) {
|
|
54
54
|
unbind && unbind();
|
|
55
55
|
}
|
|
@@ -58,7 +58,7 @@ export var dragHandleDecoration = function dragHandleDecoration(_ref) {
|
|
|
58
58
|
type: TYPE_HANDLE_DEC,
|
|
59
59
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
60
60
|
testid: "".concat(TYPE_HANDLE_DEC, "-").concat(uuid()),
|
|
61
|
-
marks: expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true) ? getActiveBlockMarks(editorState, pos) : undefined,
|
|
61
|
+
marks: expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? getMatchingBlockMarks(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true) ? getActiveBlockMarks(editorState, pos) : undefined,
|
|
62
62
|
destroy: function destroy(node) {
|
|
63
63
|
unbind && unbind();
|
|
64
64
|
}
|
|
@@ -6,7 +6,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
6
6
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
7
7
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
8
8
|
import { QuickInsertWithVisibility } from '../ui/quick-insert-button';
|
|
9
|
-
import { getActiveBlockMarks } from './utils/marks';
|
|
9
|
+
import { getActiveBlockMarks, getMatchingBlockMarks } from './utils/marks';
|
|
10
10
|
var TYPE_QUICK_INSERT = 'INSERT_BUTTON';
|
|
11
11
|
export var findQuickInsertInsertButtonDecoration = function findQuickInsertInsertButtonDecoration(decorations, from, to) {
|
|
12
12
|
return decorations.find(from, to, function (spec) {
|
|
@@ -36,7 +36,7 @@ export var quickInsertButtonDecoration = function quickInsertButtonDecoration(_r
|
|
|
36
36
|
* Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
marks: expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, rootPos),
|
|
39
|
+
marks: expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? getMatchingBlockMarks(editorState, rootPos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]) : expValEquals('platform_editor_clean_up_widget_mark_logic', 'isEnabled', true) ? [] : getActiveBlockMarks(editorState, rootPos),
|
|
40
40
|
destroy: function destroy(_) {
|
|
41
41
|
if (fg('platform_editor_fix_widget_destroy')) {
|
|
42
42
|
nodeViewPortalProviderAPI.remove(key);
|
|
@@ -51,4 +51,49 @@ export var getActiveBlockMarks = function getActiveBlockMarks(state, pos) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
return supportedMarks;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** True when `mark` has an equal counterpart (type + attrs) in `marks`. */
|
|
57
|
+
var hasMatchingMark = function hasMatchingMark(mark, marks) {
|
|
58
|
+
var found = mark.type.isInSet(marks);
|
|
59
|
+
return !!found && mark.eq(found);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns supported block marks at `pos` only when both adjacent siblings
|
|
64
|
+
* share the exact same set of those marks. Returns `[]` when they differ,
|
|
65
|
+
* so the widget sits outside all mark wrappers and avoids mis-nesting.
|
|
66
|
+
*/
|
|
67
|
+
export var getMatchingBlockMarks = function getMatchingBlockMarks(state, pos, supportedMarkTypes) {
|
|
68
|
+
var _nodeAfter$marks, _nodeBefore$marks;
|
|
69
|
+
var resolvedPos = state.doc.resolve(pos);
|
|
70
|
+
var validMarkTypes = supportedMarkTypes.filter(Boolean);
|
|
71
|
+
var supportedMarks = resolvedPos.marks().filter(function (mark) {
|
|
72
|
+
return validMarkTypes.includes(mark.type);
|
|
73
|
+
});
|
|
74
|
+
if (supportedMarks.length === 0) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
var nodeAfter = resolvedPos.nodeAfter,
|
|
78
|
+
nodeBefore = resolvedPos.nodeBefore;
|
|
79
|
+
var nextMarks = (_nodeAfter$marks = nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.marks) !== null && _nodeAfter$marks !== void 0 ? _nodeAfter$marks : [];
|
|
80
|
+
var prevMarks = (_nodeBefore$marks = nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.marks) !== null && _nodeBefore$marks !== void 0 ? _nodeBefore$marks : [];
|
|
81
|
+
var nextSupported = nextMarks.filter(function (m) {
|
|
82
|
+
return validMarkTypes.includes(m.type);
|
|
83
|
+
});
|
|
84
|
+
var allMatchNext = supportedMarks.every(function (m) {
|
|
85
|
+
return hasMatchingMark(m, nextMarks);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// First node — no previous sibling to compare against.
|
|
89
|
+
if (!nodeBefore) {
|
|
90
|
+
return nextSupported.length === supportedMarks.length && allMatchNext ? supportedMarks : [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// `supportedMarks` already comes from `nodeBefore` (via resolvedPos.marks()).
|
|
94
|
+
// Compare counts to guard against extra supported marks on either side.
|
|
95
|
+
var prevSupported = prevMarks.filter(function (m) {
|
|
96
|
+
return validMarkTypes.includes(m.type);
|
|
97
|
+
});
|
|
98
|
+
return prevSupported.length === nextSupported.length && allMatchNext ? supportedMarks : [];
|
|
54
99
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Mark } from '@atlaskit/editor-prosemirror/model';
|
|
1
|
+
import type { Mark, MarkType } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
/**
|
|
4
4
|
* Remove this when platform_editor_clean_up_widget_mark_logic is cleaned up.
|
|
@@ -17,3 +17,9 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export declare const getActiveBlockMarks: (state: EditorState, pos: number) => Mark[];
|
|
20
|
+
/**
|
|
21
|
+
* Returns supported block marks at `pos` only when both adjacent siblings
|
|
22
|
+
* share the exact same set of those marks. Returns `[]` when they differ,
|
|
23
|
+
* so the widget sits outside all mark wrappers and avoids mis-nesting.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getMatchingBlockMarks: (state: EditorState, pos: number, supportedMarkTypes: MarkType[]) => Mark[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Mark } from '@atlaskit/editor-prosemirror/model';
|
|
1
|
+
import type { Mark, MarkType } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
/**
|
|
4
4
|
* Remove this when platform_editor_clean_up_widget_mark_logic is cleaned up.
|
|
@@ -17,3 +17,9 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export declare const getActiveBlockMarks: (state: EditorState, pos: number) => Mark[];
|
|
20
|
+
/**
|
|
21
|
+
* Returns supported block marks at `pos` only when both adjacent siblings
|
|
22
|
+
* share the exact same set of those marks. Returns `[]` when they differ,
|
|
23
|
+
* so the widget sits outside all mark wrappers and avoids mis-nesting.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getMatchingBlockMarks: (state: EditorState, pos: number, supportedMarkTypes: MarkType[]) => Mark[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "11.2.
|
|
3
|
+
"version": "11.2.9",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
|
|
57
57
|
"@atlaskit/primitives": "^19.0.0",
|
|
58
58
|
"@atlaskit/theme": "^23.2.0",
|
|
59
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
59
|
+
"@atlaskit/tmp-editor-statsig": "^72.1.0",
|
|
60
60
|
"@atlaskit/tokens": "^13.0.0",
|
|
61
61
|
"@atlaskit/tooltip": "^21.2.0",
|
|
62
62
|
"@babel/runtime": "^7.0.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"uuid": "^3.1.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@atlaskit/editor-common": "^114.
|
|
70
|
+
"@atlaskit/editor-common": "^114.13.0",
|
|
71
71
|
"react": "^18.2.0",
|
|
72
72
|
"react-dom": "^18.2.0",
|
|
73
73
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|