@atlaskit/editor-plugin-insert-block 8.7.1 → 8.7.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 +12 -0
- package/dist/cjs/pm-plugins/experiences/toolbar-action-experiences.js +24 -16
- package/dist/cjs/pm-plugins/experiences/toolbar-experience-utils.js +133 -187
- package/dist/es2019/pm-plugins/experiences/toolbar-action-experiences.js +25 -18
- package/dist/es2019/pm-plugins/experiences/toolbar-experience-utils.js +75 -91
- package/dist/esm/pm-plugins/experiences/toolbar-action-experiences.js +25 -17
- package/dist/esm/pm-plugins/experiences/toolbar-experience-utils.js +133 -186
- package/dist/types/pm-plugins/experiences/toolbar-experience-utils.d.ts +26 -13
- package/dist/types-ts4.5/pm-plugins/experiences/toolbar-experience-utils.d.ts +26 -13
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -23,6 +23,7 @@ var getToolbarActionExperiencesPlugin = exports.getToolbarActionExperiencesPlugi
|
|
|
23
23
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
|
|
24
24
|
var editorView;
|
|
25
25
|
var popupTargetEl;
|
|
26
|
+
var lastClickedToolbarButton;
|
|
26
27
|
var getPopupsTarget = function getPopupsTarget() {
|
|
27
28
|
if (!popupTargetEl) {
|
|
28
29
|
var _editorView;
|
|
@@ -37,6 +38,17 @@ var getToolbarActionExperiencesPlugin = exports.getToolbarActionExperiencesPlugi
|
|
|
37
38
|
}
|
|
38
39
|
return null;
|
|
39
40
|
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* For inline popups, returns the button-group ancestor of the clicked toolbar button.
|
|
44
|
+
* This allows inline popup checks to observe only the relevant button-group.
|
|
45
|
+
*/
|
|
46
|
+
var getInlinePopupTarget = function getInlinePopupTarget() {
|
|
47
|
+
if (!lastClickedToolbarButton) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return lastClickedToolbarButton;
|
|
51
|
+
};
|
|
40
52
|
var narrowParentObserveConfig = function narrowParentObserveConfig() {
|
|
41
53
|
var _getParentDOMAtSelect;
|
|
42
54
|
return {
|
|
@@ -71,45 +83,39 @@ var getToolbarActionExperiencesPlugin = exports.getToolbarActionExperiencesPlugi
|
|
|
71
83
|
});
|
|
72
84
|
};
|
|
73
85
|
var createPopupExperience = function createPopupExperience(action, popupSelector) {
|
|
86
|
+
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'editorRoot';
|
|
74
87
|
return new _experiences.Experience(_experiences.EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
75
88
|
action: action,
|
|
76
89
|
actionSubjectId: PRIMARY_TOOLBAR,
|
|
77
90
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
78
91
|
checks: [new _experiences.ExperienceCheckTimeout({
|
|
79
92
|
durationMs: TIMEOUT_DURATION
|
|
80
|
-
}), new _toolbarExperienceUtils.ExperienceCheckPopupMutation(popupSelector, getPopupsTarget, getEditorDom)]
|
|
93
|
+
}), new _toolbarExperienceUtils.ExperienceCheckPopupMutation(popupSelector, type === 'inline' ? getInlinePopupTarget : getPopupsTarget, getEditorDom, type)]
|
|
81
94
|
});
|
|
82
95
|
};
|
|
83
96
|
var experienceButtonMappings = [{
|
|
84
|
-
experience: createPopupExperience('
|
|
97
|
+
experience: createPopupExperience('insert', '[data-testid="popup-wrapper"]', 'inline'),
|
|
98
|
+
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.INSERT
|
|
99
|
+
}, {
|
|
100
|
+
experience: createPopupExperience('emoji', '[data-emoji-picker-container], [data-emoji-picker-container="true"], [data-testid="popup-wrapper"]', 'inline'),
|
|
85
101
|
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.EMOJI
|
|
86
102
|
}, {
|
|
87
|
-
experience: createPopupExperience('media', '[
|
|
103
|
+
experience: createPopupExperience('media', '[data-testid="popup-wrapper"]', 'inline'),
|
|
88
104
|
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.MEDIA
|
|
89
105
|
}, {
|
|
90
|
-
experience:
|
|
91
|
-
action: 'mention',
|
|
92
|
-
actionSubjectId: PRIMARY_TOOLBAR,
|
|
93
|
-
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
94
|
-
checks: [new _experiences.ExperienceCheckTimeout({
|
|
95
|
-
durationMs: TIMEOUT_DURATION
|
|
96
|
-
}), new _experiences.ExperienceCheckDomMutation({
|
|
97
|
-
onDomMutation: _toolbarExperienceUtils.handleTypeAheadOpenDomMutation,
|
|
98
|
-
observeConfig: narrowParentObserveConfig
|
|
99
|
-
})]
|
|
100
|
-
}),
|
|
106
|
+
experience: createPopupExperience('mention', '[data-testid="popup-wrapper"], [data-type-ahead="typeaheadDecoration"]', 'editorRoot'),
|
|
101
107
|
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.MENTION
|
|
102
108
|
}, {
|
|
103
109
|
experience: createNodeInsertExperience('table'),
|
|
104
110
|
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.TABLE
|
|
105
111
|
}, {
|
|
106
|
-
experience: createPopupExperience('tableSelector', '[aria-label*="table size"], [data-testid*="table-selector"]'),
|
|
112
|
+
experience: createPopupExperience('tableSelector', '[aria-label*="table size"], [data-testid*="table-selector"]', 'inline'),
|
|
107
113
|
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.TABLE_SELECTOR
|
|
108
114
|
}, {
|
|
109
115
|
experience: createNodeInsertExperience('layout'),
|
|
110
116
|
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.LAYOUT
|
|
111
117
|
}, {
|
|
112
|
-
experience: createPopupExperience('image', '[
|
|
118
|
+
experience: createPopupExperience('image', '[data-testid="popup-wrapper"]', 'inline'),
|
|
113
119
|
buttonTestId: _toolbar.TOOLBAR_BUTTON_TEST_ID.IMAGE
|
|
114
120
|
}, {
|
|
115
121
|
experience: createNodeInsertExperience('action'),
|
|
@@ -121,6 +127,8 @@ var getToolbarActionExperiencesPlugin = exports.getToolbarActionExperiencesPlugi
|
|
|
121
127
|
experience = _experienceButtonMapp2.experience,
|
|
122
128
|
buttonTestId = _experienceButtonMapp2.buttonTestId;
|
|
123
129
|
if ((0, _toolbarExperienceUtils.isToolbarButtonClick)(target, buttonTestId)) {
|
|
130
|
+
// Store the clicked button so inline popup checks can find its button-group
|
|
131
|
+
lastClickedToolbarButton = target;
|
|
124
132
|
experience.start({
|
|
125
133
|
forceRestart: true
|
|
126
134
|
});
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.isToolbarButtonClick = exports.
|
|
7
|
+
exports.isToolbarButtonClick = exports.handleEditorNodeInsertDomMutation = exports.getParentDOMAtSelection = exports.NODE_INSERT_MARKERS = exports.ExperienceCheckPopupMutation = void 0;
|
|
8
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -13,6 +13,13 @@ var _experiences = require("@atlaskit/editor-common/experiences");
|
|
|
13
13
|
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; } } }; }
|
|
14
14
|
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; } }
|
|
15
15
|
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; }
|
|
16
|
+
/**
|
|
17
|
+
* Popup check type determines how popups are observed based on their DOM location:
|
|
18
|
+
* - 'inline': Popups appearing in toolbar button-groups (emoji, media, table selector, image)
|
|
19
|
+
* - 'editorRoot': Popups attached to editor root (e.g., mention popups)
|
|
20
|
+
* - 'editorContent': Content-level popups or modals in portal containers (e.g., block menu)
|
|
21
|
+
*/
|
|
22
|
+
|
|
16
23
|
/**
|
|
17
24
|
* DOM marker selectors for node types inserted via toolbar actions.
|
|
18
25
|
* Matches outermost wrapper elements set synchronously by ReactNodeView
|
|
@@ -33,62 +40,90 @@ var isToolbarButtonClick = exports.isToolbarButtonClick = function isToolbarButt
|
|
|
33
40
|
}
|
|
34
41
|
return !button.disabled && button.getAttribute('aria-disabled') !== 'true';
|
|
35
42
|
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* ExperienceCheck that observes popup mount point and all its
|
|
39
|
-
* `[data-editor-popup]` children with `{ childList: true }` (no subtree).
|
|
40
|
-
*
|
|
41
|
-
* Detects when a popup containing the given nested element is added to the
|
|
42
|
-
* DOM — either as a new `[data-editor-popup]` direct child, or as content
|
|
43
|
-
* rendered inside an existing `[data-editor-popup]` wrapper.
|
|
44
|
-
*/
|
|
45
|
-
var TYPEAHEAD_DECORATION_SELECTOR = exports.TYPEAHEAD_DECORATION_SELECTOR = '[data-type-ahead="typeaheadDecoration"]';
|
|
46
|
-
var handleTypeAheadOpenDomMutation = exports.handleTypeAheadOpenDomMutation = function handleTypeAheadOpenDomMutation(_ref) {
|
|
47
|
-
var mutations = _ref.mutations;
|
|
48
|
-
var _iterator = _createForOfIteratorHelper(mutations),
|
|
49
|
-
_step;
|
|
50
|
-
try {
|
|
51
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
52
|
-
var mutation = _step.value;
|
|
53
|
-
if (mutation.type !== 'childList') {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
var _iterator2 = _createForOfIteratorHelper(mutation.addedNodes),
|
|
57
|
-
_step2;
|
|
58
|
-
try {
|
|
59
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
60
|
-
var node = _step2.value;
|
|
61
|
-
if (!(node instanceof HTMLElement)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (node.matches(TYPEAHEAD_DECORATION_SELECTOR) || node.querySelector(TYPEAHEAD_DECORATION_SELECTOR)) {
|
|
65
|
-
return {
|
|
66
|
-
status: 'success'
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
} catch (err) {
|
|
71
|
-
_iterator2.e(err);
|
|
72
|
-
} finally {
|
|
73
|
-
_iterator2.f();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} catch (err) {
|
|
77
|
-
_iterator.e(err);
|
|
78
|
-
} finally {
|
|
79
|
-
_iterator.f();
|
|
80
|
-
}
|
|
81
|
-
return undefined;
|
|
82
|
-
};
|
|
83
43
|
var ExperienceCheckPopupMutation = exports.ExperienceCheckPopupMutation = /*#__PURE__*/function () {
|
|
84
44
|
function ExperienceCheckPopupMutation(nestedElementQuery, getTarget, getEditorDom) {
|
|
45
|
+
var type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'editorRoot';
|
|
85
46
|
(0, _classCallCheck2.default)(this, ExperienceCheckPopupMutation);
|
|
86
47
|
(0, _defineProperty2.default)(this, "observers", []);
|
|
87
48
|
this.nestedElementQuery = nestedElementQuery;
|
|
88
49
|
this.getTarget = getTarget;
|
|
89
50
|
this.getEditorDom = getEditorDom;
|
|
51
|
+
this.type = type;
|
|
90
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns the list of DOM elements to observe based on popup type.
|
|
56
|
+
*/
|
|
91
57
|
return (0, _createClass2.default)(ExperienceCheckPopupMutation, [{
|
|
58
|
+
key: "getObserveTargets",
|
|
59
|
+
value: function getObserveTargets() {
|
|
60
|
+
switch (this.type) {
|
|
61
|
+
case 'inline':
|
|
62
|
+
return this.getInlineTargets();
|
|
63
|
+
case 'editorRoot':
|
|
64
|
+
return this.getEditorRootTargets();
|
|
65
|
+
}
|
|
66
|
+
// Should never reach here - all types handled above
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* For 'inline' type: observe only the button-group container.
|
|
72
|
+
* The target passed in should be the button-group (or button within it) from getInlinePopupTarget().
|
|
73
|
+
* Inline popups appear as direct children of button-group elements.
|
|
74
|
+
*/
|
|
75
|
+
}, {
|
|
76
|
+
key: "getInlineTargets",
|
|
77
|
+
value: function getInlineTargets() {
|
|
78
|
+
var target = this.getTarget();
|
|
79
|
+
if (!target) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Walk up to find the button-group container
|
|
84
|
+
var buttonGroup = target.closest('[data-toolbar-component="button-group"]');
|
|
85
|
+
|
|
86
|
+
// Target is already the button-group or button from getInlinePopupTarget()
|
|
87
|
+
// Just observe this single element
|
|
88
|
+
return buttonGroup ? [buttonGroup, target] : [target];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* For 'editorRoot' type: observe the actual editor root container.
|
|
93
|
+
* The editorDom is the ProseMirror element, but popups appear as direct children
|
|
94
|
+
* of the parent .akEditor container. So we observe the parent of editorDom.
|
|
95
|
+
* No portal observation needed.
|
|
96
|
+
*/
|
|
97
|
+
}, {
|
|
98
|
+
key: "getEditorRootTargets",
|
|
99
|
+
value: function getEditorRootTargets() {
|
|
100
|
+
var targets = [];
|
|
101
|
+
var editorDom = this.getEditorDom();
|
|
102
|
+
if (editorDom) {
|
|
103
|
+
// Find the actual editor root (.akEditor) by walking up the DOM
|
|
104
|
+
var editorRoot = editorDom.closest('.akEditor') || editorDom.parentElement;
|
|
105
|
+
if (editorRoot instanceof HTMLElement) {
|
|
106
|
+
targets.push(editorRoot);
|
|
107
|
+
|
|
108
|
+
// Observe existing [data-editor-popup] wrappers
|
|
109
|
+
var wrappers = editorRoot.querySelectorAll('[data-editor-popup]');
|
|
110
|
+
var _iterator = _createForOfIteratorHelper(wrappers),
|
|
111
|
+
_step;
|
|
112
|
+
try {
|
|
113
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
114
|
+
var wrapper = _step.value;
|
|
115
|
+
targets.push(wrapper);
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
_iterator.e(err);
|
|
119
|
+
} finally {
|
|
120
|
+
_iterator.f();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return targets;
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
92
127
|
key: "start",
|
|
93
128
|
value: function start(callback) {
|
|
94
129
|
var _this = this;
|
|
@@ -111,23 +146,24 @@ var ExperienceCheckPopupMutation = exports.ExperienceCheckPopupMutation = /*#__P
|
|
|
111
146
|
}
|
|
112
147
|
var query = this.nestedElementQuery;
|
|
113
148
|
var onMutation = function onMutation(mutations) {
|
|
114
|
-
var
|
|
115
|
-
|
|
149
|
+
var _iterator2 = _createForOfIteratorHelper(mutations),
|
|
150
|
+
_step2;
|
|
116
151
|
try {
|
|
117
|
-
for (
|
|
118
|
-
var mutation =
|
|
152
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
153
|
+
var mutation = _step2.value;
|
|
119
154
|
if (mutation.type !== 'childList') {
|
|
120
155
|
continue;
|
|
121
156
|
}
|
|
122
|
-
var
|
|
123
|
-
|
|
157
|
+
var _iterator3 = _createForOfIteratorHelper(mutation.addedNodes),
|
|
158
|
+
_step3;
|
|
124
159
|
try {
|
|
125
|
-
for (
|
|
126
|
-
var node =
|
|
160
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
161
|
+
var node = _step3.value;
|
|
127
162
|
if (!(node instanceof HTMLElement)) {
|
|
128
163
|
continue;
|
|
129
164
|
}
|
|
130
|
-
|
|
165
|
+
var found = (0, _experiences.popupWithNestedElement)(node, query) || node.matches(query) || !!node.querySelector(query);
|
|
166
|
+
if (found) {
|
|
131
167
|
_this.stop();
|
|
132
168
|
callback({
|
|
133
169
|
status: 'success'
|
|
@@ -136,15 +172,15 @@ var ExperienceCheckPopupMutation = exports.ExperienceCheckPopupMutation = /*#__P
|
|
|
136
172
|
}
|
|
137
173
|
}
|
|
138
174
|
} catch (err) {
|
|
139
|
-
|
|
175
|
+
_iterator3.e(err);
|
|
140
176
|
} finally {
|
|
141
|
-
|
|
177
|
+
_iterator3.f();
|
|
142
178
|
}
|
|
143
179
|
}
|
|
144
180
|
} catch (err) {
|
|
145
|
-
|
|
181
|
+
_iterator2.e(err);
|
|
146
182
|
} finally {
|
|
147
|
-
|
|
183
|
+
_iterator2.f();
|
|
148
184
|
}
|
|
149
185
|
};
|
|
150
186
|
var observe = function observe(el) {
|
|
@@ -154,126 +190,36 @@ var ExperienceCheckPopupMutation = exports.ExperienceCheckPopupMutation = /*#__P
|
|
|
154
190
|
});
|
|
155
191
|
_this.observers.push(observer);
|
|
156
192
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
193
|
+
|
|
194
|
+
// Get type-specific targets and observe them
|
|
195
|
+
var observeTargets = this.getObserveTargets();
|
|
196
|
+
var _iterator4 = _createForOfIteratorHelper(observeTargets),
|
|
197
|
+
_step4;
|
|
160
198
|
try {
|
|
161
|
-
for (
|
|
162
|
-
var
|
|
163
|
-
observe(
|
|
199
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
200
|
+
var observeTarget = _step4.value;
|
|
201
|
+
observe(observeTarget);
|
|
164
202
|
}
|
|
165
203
|
} catch (err) {
|
|
166
|
-
|
|
204
|
+
_iterator4.e(err);
|
|
167
205
|
} finally {
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
var portalContainer = doc.querySelector('.atlaskit-portal-container');
|
|
171
|
-
if (portalContainer instanceof HTMLElement) {
|
|
172
|
-
var observePortal = function observePortal(portal) {
|
|
173
|
-
observe(portal);
|
|
174
|
-
var _iterator6 = _createForOfIteratorHelper(portal.children),
|
|
175
|
-
_step6;
|
|
176
|
-
try {
|
|
177
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
178
|
-
var child = _step6.value;
|
|
179
|
-
if (child instanceof HTMLElement) {
|
|
180
|
-
observe(child);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
} catch (err) {
|
|
184
|
-
_iterator6.e(err);
|
|
185
|
-
} finally {
|
|
186
|
-
_iterator6.f();
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
var containerObserver = new MutationObserver(function (mutations) {
|
|
190
|
-
var _iterator7 = _createForOfIteratorHelper(mutations),
|
|
191
|
-
_step7;
|
|
192
|
-
try {
|
|
193
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
194
|
-
var mutation = _step7.value;
|
|
195
|
-
if (mutation.type !== 'childList') {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
var _iterator8 = _createForOfIteratorHelper(mutation.addedNodes),
|
|
199
|
-
_step8;
|
|
200
|
-
try {
|
|
201
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
202
|
-
var node = _step8.value;
|
|
203
|
-
if (node instanceof HTMLElement) {
|
|
204
|
-
observePortal(node);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
} catch (err) {
|
|
208
|
-
_iterator8.e(err);
|
|
209
|
-
} finally {
|
|
210
|
-
_iterator8.f();
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
} catch (err) {
|
|
214
|
-
_iterator7.e(err);
|
|
215
|
-
} finally {
|
|
216
|
-
_iterator7.f();
|
|
217
|
-
}
|
|
218
|
-
onMutation(mutations);
|
|
219
|
-
});
|
|
220
|
-
containerObserver.observe(portalContainer, {
|
|
221
|
-
childList: true
|
|
222
|
-
});
|
|
223
|
-
this.observers.push(containerObserver);
|
|
224
|
-
var _iterator9 = _createForOfIteratorHelper(portalContainer.querySelectorAll('.atlaskit-portal')),
|
|
225
|
-
_step9;
|
|
226
|
-
try {
|
|
227
|
-
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
228
|
-
var portal = _step9.value;
|
|
229
|
-
observePortal(portal);
|
|
230
|
-
}
|
|
231
|
-
} catch (err) {
|
|
232
|
-
_iterator9.e(err);
|
|
233
|
-
} finally {
|
|
234
|
-
_iterator9.f();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
var editorDom = this.getEditorDom();
|
|
238
|
-
if (editorDom !== null && editorDom !== void 0 && editorDom.parentElement) {
|
|
239
|
-
observe(editorDom.parentElement);
|
|
206
|
+
_iterator4.f();
|
|
240
207
|
}
|
|
241
|
-
|
|
242
|
-
// Two-frame DOM check to handle cases where rendering happens before
|
|
243
|
-
// observers are attached.
|
|
244
|
-
var checkDom = function checkDom() {
|
|
245
|
-
if (doc.querySelector(query)) {
|
|
246
|
-
_this.stop();
|
|
247
|
-
callback({
|
|
248
|
-
status: 'success'
|
|
249
|
-
});
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
requestAnimationFrame(function () {
|
|
253
|
-
if (doc.querySelector(query)) {
|
|
254
|
-
_this.stop();
|
|
255
|
-
callback({
|
|
256
|
-
status: 'success'
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
requestAnimationFrame(checkDom);
|
|
262
208
|
}
|
|
263
209
|
}, {
|
|
264
210
|
key: "stop",
|
|
265
211
|
value: function stop() {
|
|
266
|
-
var
|
|
267
|
-
|
|
212
|
+
var _iterator5 = _createForOfIteratorHelper(this.observers),
|
|
213
|
+
_step5;
|
|
268
214
|
try {
|
|
269
|
-
for (
|
|
270
|
-
var observer =
|
|
215
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
216
|
+
var observer = _step5.value;
|
|
271
217
|
observer.disconnect();
|
|
272
218
|
}
|
|
273
219
|
} catch (err) {
|
|
274
|
-
|
|
220
|
+
_iterator5.e(err);
|
|
275
221
|
} finally {
|
|
276
|
-
|
|
222
|
+
_iterator5.f();
|
|
277
223
|
}
|
|
278
224
|
this.observers = [];
|
|
279
225
|
}
|
|
@@ -349,23 +295,23 @@ var matchesNodeInsertMarker = function matchesNodeInsertMarker(node) {
|
|
|
349
295
|
* 1. Marker-based: checks `addedNodes` against known node insert selectors.
|
|
350
296
|
* 2. Structure-based: detects element add+remove (block-level replacement).
|
|
351
297
|
*/
|
|
352
|
-
var handleEditorNodeInsertDomMutation = exports.handleEditorNodeInsertDomMutation = function handleEditorNodeInsertDomMutation(
|
|
353
|
-
var mutations =
|
|
298
|
+
var handleEditorNodeInsertDomMutation = exports.handleEditorNodeInsertDomMutation = function handleEditorNodeInsertDomMutation(_ref) {
|
|
299
|
+
var mutations = _ref.mutations;
|
|
354
300
|
var hasAddedElement = false;
|
|
355
301
|
var hasRemovedElement = false;
|
|
356
|
-
var
|
|
357
|
-
|
|
302
|
+
var _iterator6 = _createForOfIteratorHelper(mutations),
|
|
303
|
+
_step6;
|
|
358
304
|
try {
|
|
359
|
-
for (
|
|
360
|
-
var mutation =
|
|
305
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
306
|
+
var mutation = _step6.value;
|
|
361
307
|
if (mutation.type !== 'childList') {
|
|
362
308
|
continue;
|
|
363
309
|
}
|
|
364
|
-
var
|
|
365
|
-
|
|
310
|
+
var _iterator7 = _createForOfIteratorHelper(mutation.addedNodes),
|
|
311
|
+
_step7;
|
|
366
312
|
try {
|
|
367
|
-
for (
|
|
368
|
-
var node =
|
|
313
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
314
|
+
var node = _step7.value;
|
|
369
315
|
if (matchesNodeInsertMarker(node)) {
|
|
370
316
|
return {
|
|
371
317
|
status: 'success'
|
|
@@ -376,29 +322,29 @@ var handleEditorNodeInsertDomMutation = exports.handleEditorNodeInsertDomMutatio
|
|
|
376
322
|
}
|
|
377
323
|
}
|
|
378
324
|
} catch (err) {
|
|
379
|
-
|
|
325
|
+
_iterator7.e(err);
|
|
380
326
|
} finally {
|
|
381
|
-
|
|
327
|
+
_iterator7.f();
|
|
382
328
|
}
|
|
383
|
-
var
|
|
384
|
-
|
|
329
|
+
var _iterator8 = _createForOfIteratorHelper(mutation.removedNodes),
|
|
330
|
+
_step8;
|
|
385
331
|
try {
|
|
386
|
-
for (
|
|
387
|
-
var _node =
|
|
332
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
333
|
+
var _node = _step8.value;
|
|
388
334
|
if (_node instanceof HTMLElement) {
|
|
389
335
|
hasRemovedElement = true;
|
|
390
336
|
}
|
|
391
337
|
}
|
|
392
338
|
} catch (err) {
|
|
393
|
-
|
|
339
|
+
_iterator8.e(err);
|
|
394
340
|
} finally {
|
|
395
|
-
|
|
341
|
+
_iterator8.f();
|
|
396
342
|
}
|
|
397
343
|
}
|
|
398
344
|
} catch (err) {
|
|
399
|
-
|
|
345
|
+
_iterator6.e(err);
|
|
400
346
|
} finally {
|
|
401
|
-
|
|
347
|
+
_iterator6.f();
|
|
402
348
|
}
|
|
403
349
|
if (hasAddedElement && hasRemovedElement) {
|
|
404
350
|
return {
|
|
@@ -4,7 +4,7 @@ import { Experience, EXPERIENCE_ID, ExperienceCheckDomMutation, ExperienceCheckT
|
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
5
|
import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
6
6
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
import { ExperienceCheckPopupMutation, getParentDOMAtSelection, handleEditorNodeInsertDomMutation,
|
|
7
|
+
import { ExperienceCheckPopupMutation, getParentDOMAtSelection, handleEditorNodeInsertDomMutation, isToolbarButtonClick } from './toolbar-experience-utils';
|
|
8
8
|
const pluginKey = new PluginKey('toolbarActionExperiences');
|
|
9
9
|
const TIMEOUT_DURATION = 1000;
|
|
10
10
|
const PRIMARY_TOOLBAR = 'primaryToolbar';
|
|
@@ -18,6 +18,7 @@ export const getToolbarActionExperiencesPlugin = ({
|
|
|
18
18
|
}) => {
|
|
19
19
|
let editorView;
|
|
20
20
|
let popupTargetEl;
|
|
21
|
+
let lastClickedToolbarButton;
|
|
21
22
|
const getPopupsTarget = () => {
|
|
22
23
|
if (!popupTargetEl) {
|
|
23
24
|
var _editorView;
|
|
@@ -32,6 +33,17 @@ export const getToolbarActionExperiencesPlugin = ({
|
|
|
32
33
|
}
|
|
33
34
|
return null;
|
|
34
35
|
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* For inline popups, returns the button-group ancestor of the clicked toolbar button.
|
|
39
|
+
* This allows inline popup checks to observe only the relevant button-group.
|
|
40
|
+
*/
|
|
41
|
+
const getInlinePopupTarget = () => {
|
|
42
|
+
if (!lastClickedToolbarButton) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return lastClickedToolbarButton;
|
|
46
|
+
};
|
|
35
47
|
const narrowParentObserveConfig = () => {
|
|
36
48
|
var _getParentDOMAtSelect;
|
|
37
49
|
return {
|
|
@@ -61,44 +73,37 @@ export const getToolbarActionExperiencesPlugin = ({
|
|
|
61
73
|
observeConfig: rootObserveConfig
|
|
62
74
|
})]
|
|
63
75
|
});
|
|
64
|
-
const createPopupExperience = (action, popupSelector) => new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
76
|
+
const createPopupExperience = (action, popupSelector, type = 'editorRoot') => new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
65
77
|
action,
|
|
66
78
|
actionSubjectId: PRIMARY_TOOLBAR,
|
|
67
79
|
dispatchAnalyticsEvent,
|
|
68
80
|
checks: [new ExperienceCheckTimeout({
|
|
69
81
|
durationMs: TIMEOUT_DURATION
|
|
70
|
-
}), new ExperienceCheckPopupMutation(popupSelector, getPopupsTarget, getEditorDom)]
|
|
82
|
+
}), new ExperienceCheckPopupMutation(popupSelector, type === 'inline' ? getInlinePopupTarget : getPopupsTarget, getEditorDom, type)]
|
|
71
83
|
});
|
|
72
84
|
const experienceButtonMappings = [{
|
|
73
|
-
experience: createPopupExperience('
|
|
85
|
+
experience: createPopupExperience('insert', '[data-testid="popup-wrapper"]', 'inline'),
|
|
86
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.INSERT
|
|
87
|
+
}, {
|
|
88
|
+
experience: createPopupExperience('emoji', '[data-emoji-picker-container], [data-emoji-picker-container="true"], [data-testid="popup-wrapper"]', 'inline'),
|
|
74
89
|
buttonTestId: TOOLBAR_BUTTON_TEST_ID.EMOJI
|
|
75
90
|
}, {
|
|
76
|
-
experience: createPopupExperience('media', '[
|
|
91
|
+
experience: createPopupExperience('media', '[data-testid="popup-wrapper"]', 'inline'),
|
|
77
92
|
buttonTestId: TOOLBAR_BUTTON_TEST_ID.MEDIA
|
|
78
93
|
}, {
|
|
79
|
-
experience:
|
|
80
|
-
action: 'mention',
|
|
81
|
-
actionSubjectId: PRIMARY_TOOLBAR,
|
|
82
|
-
dispatchAnalyticsEvent,
|
|
83
|
-
checks: [new ExperienceCheckTimeout({
|
|
84
|
-
durationMs: TIMEOUT_DURATION
|
|
85
|
-
}), new ExperienceCheckDomMutation({
|
|
86
|
-
onDomMutation: handleTypeAheadOpenDomMutation,
|
|
87
|
-
observeConfig: narrowParentObserveConfig
|
|
88
|
-
})]
|
|
89
|
-
}),
|
|
94
|
+
experience: createPopupExperience('mention', '[data-testid="popup-wrapper"], [data-type-ahead="typeaheadDecoration"]', 'editorRoot'),
|
|
90
95
|
buttonTestId: TOOLBAR_BUTTON_TEST_ID.MENTION
|
|
91
96
|
}, {
|
|
92
97
|
experience: createNodeInsertExperience('table'),
|
|
93
98
|
buttonTestId: TOOLBAR_BUTTON_TEST_ID.TABLE
|
|
94
99
|
}, {
|
|
95
|
-
experience: createPopupExperience('tableSelector', '[aria-label*="table size"], [data-testid*="table-selector"]'),
|
|
100
|
+
experience: createPopupExperience('tableSelector', '[aria-label*="table size"], [data-testid*="table-selector"]', 'inline'),
|
|
96
101
|
buttonTestId: TOOLBAR_BUTTON_TEST_ID.TABLE_SELECTOR
|
|
97
102
|
}, {
|
|
98
103
|
experience: createNodeInsertExperience('layout'),
|
|
99
104
|
buttonTestId: TOOLBAR_BUTTON_TEST_ID.LAYOUT
|
|
100
105
|
}, {
|
|
101
|
-
experience: createPopupExperience('image', '[
|
|
106
|
+
experience: createPopupExperience('image', '[data-testid="popup-wrapper"]', 'inline'),
|
|
102
107
|
buttonTestId: TOOLBAR_BUTTON_TEST_ID.IMAGE
|
|
103
108
|
}, {
|
|
104
109
|
experience: createNodeInsertExperience('action'),
|
|
@@ -110,6 +115,8 @@ export const getToolbarActionExperiencesPlugin = ({
|
|
|
110
115
|
buttonTestId
|
|
111
116
|
} of experienceButtonMappings) {
|
|
112
117
|
if (isToolbarButtonClick(target, buttonTestId)) {
|
|
118
|
+
// Store the clicked button so inline popup checks can find its button-group
|
|
119
|
+
lastClickedToolbarButton = target;
|
|
113
120
|
experience.start({
|
|
114
121
|
forceRestart: true
|
|
115
122
|
});
|