@atlaskit/editor-plugin-rule 30.0.1 → 30.0.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 +18 -0
- package/dist/cjs/node-views/RuleNodeView.js +74 -0
- package/dist/cjs/pm-plugins/main.js +36 -0
- package/dist/cjs/rulePlugin.js +7 -2
- package/dist/cjs/ui/DividerOptions.js +57 -4
- package/dist/es2019/node-views/RuleNodeView.js +57 -0
- package/dist/es2019/pm-plugins/main.js +21 -0
- package/dist/es2019/rulePlugin.js +5 -1
- package/dist/es2019/ui/DividerOptions.js +58 -4
- package/dist/esm/node-views/RuleNodeView.js +67 -0
- package/dist/esm/pm-plugins/main.js +30 -0
- package/dist/esm/rulePlugin.js +7 -2
- package/dist/esm/ui/DividerOptions.js +58 -5
- package/dist/types/node-views/RuleNodeView.d.ts +13 -0
- package/dist/types/pm-plugins/main.d.ts +3 -0
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-rule
|
|
2
2
|
|
|
3
|
+
## 30.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`16d59dad238c4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/16d59dad238c4) -
|
|
8
|
+
[EDITOR-8351] fix focus ring and arrow-key behaviour for the divider options dropdown menu behind
|
|
9
|
+
`platform_editor_lovability_dividers` and `platform_editor_lovability_dividers_patch_1`.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 30.0.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`8632ab245f251`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8632ab245f251) -
|
|
17
|
+
[ux] [EDITOR-8977] introduce rule node view to update the selected state for dividers behind
|
|
18
|
+
`platform_editor_lovability_dividers`
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 30.0.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.RuleNodeView = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _bindEventListener = require("bind-event-listener");
|
|
12
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
13
|
+
var ruleNodeViewAttribute = 'data-rule-node-view';
|
|
14
|
+
var RuleNodeView = exports.RuleNodeView = /*#__PURE__*/function () {
|
|
15
|
+
function RuleNodeView(node, view) {
|
|
16
|
+
var _this = this;
|
|
17
|
+
(0, _classCallCheck2.default)(this, RuleNodeView);
|
|
18
|
+
// when there is only 1 rule node on the page and it is not editable, clicking on it does not focus the editor and Cmd+C/ Ctrl+C shortcut will not work. this mouse down listener adds focus to the editor.
|
|
19
|
+
(0, _defineProperty2.default)(this, "handleMousedown", function () {
|
|
20
|
+
if (!_this.view.hasFocus()) {
|
|
21
|
+
_this.view.focus();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
this.node = node;
|
|
25
|
+
this.view = view;
|
|
26
|
+
var dom = this.view.dom.ownerDocument.createElement('div');
|
|
27
|
+
this.dom = dom;
|
|
28
|
+
dom.setAttribute(ruleNodeViewAttribute, '');
|
|
29
|
+
dom.setAttribute('contenteditable', 'inherit');
|
|
30
|
+
this.unbindMousedown = (0, _bindEventListener.bind)(dom, {
|
|
31
|
+
type: 'mousedown',
|
|
32
|
+
listener: this.handleMousedown
|
|
33
|
+
});
|
|
34
|
+
this.update(node);
|
|
35
|
+
}
|
|
36
|
+
return (0, _createClass2.default)(RuleNodeView, [{
|
|
37
|
+
key: "update",
|
|
38
|
+
value: function update(node) {
|
|
39
|
+
if (node.type !== this.node.type) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (this.dom.firstChild && node.sameMarkup(this.node)) {
|
|
43
|
+
this.node = node;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
var toDOM = node.type.spec.toDOM;
|
|
47
|
+
if (!toDOM) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
var _DOMSerializer$render = _model.DOMSerializer.renderSpec(this.view.dom.ownerDocument, toDOM(node)),
|
|
51
|
+
dom = _DOMSerializer$render.dom;
|
|
52
|
+
if (dom instanceof HTMLElement) {
|
|
53
|
+
dom.contentEditable = 'false';
|
|
54
|
+
}
|
|
55
|
+
if (this.dom.firstChild) {
|
|
56
|
+
this.dom.replaceChild(dom, this.dom.firstChild);
|
|
57
|
+
} else {
|
|
58
|
+
this.dom.appendChild(dom);
|
|
59
|
+
}
|
|
60
|
+
this.node = node;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "ignoreMutation",
|
|
65
|
+
value: function ignoreMutation() {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "destroy",
|
|
70
|
+
value: function destroy() {
|
|
71
|
+
this.unbindMousedown();
|
|
72
|
+
}
|
|
73
|
+
}]);
|
|
74
|
+
}();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.createPlugin = void 0;
|
|
7
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
9
|
+
var _RuleNodeView = require("../node-views/RuleNodeView");
|
|
10
|
+
var selectRuleOnClick = (0, _selection.createSelectionClickHandler)(['rule'], function (target) {
|
|
11
|
+
return !!target.closest('[data-rule-node-view]');
|
|
12
|
+
}, {
|
|
13
|
+
useLongPressSelection: false
|
|
14
|
+
});
|
|
15
|
+
var createPlugin = exports.createPlugin = function createPlugin() {
|
|
16
|
+
return new _safePlugin.SafePlugin({
|
|
17
|
+
props: {
|
|
18
|
+
nodeViews: {
|
|
19
|
+
rule: function rule(node, view) {
|
|
20
|
+
return new _RuleNodeView.RuleNodeView(node, view);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
handleClickOn: function handleClickOn(view) {
|
|
24
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
25
|
+
args[_key - 1] = arguments[_key];
|
|
26
|
+
}
|
|
27
|
+
var handled = selectRuleOnClick.apply(void 0, [view].concat(args));
|
|
28
|
+
if (handled && view.editable) {
|
|
29
|
+
view.focus();
|
|
30
|
+
}
|
|
31
|
+
return handled;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var _default = exports.default = createPlugin;
|
package/dist/cjs/rulePlugin.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.rulePlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
10
|
var _react = _interopRequireDefault(require("react"));
|
|
10
11
|
var _rule = require("@atlaskit/adf-schema/rule");
|
|
11
12
|
var _enums = require("@atlaskit/editor-common/analytics/types/enums");
|
|
@@ -16,6 +17,7 @@ var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
|
16
17
|
var _commands = require("./pm-plugins/commands");
|
|
17
18
|
var _inputRule = _interopRequireDefault(require("./pm-plugins/input-rule"));
|
|
18
19
|
var _keymap = _interopRequireDefault(require("./pm-plugins/keymap"));
|
|
20
|
+
var _main = _interopRequireDefault(require("./pm-plugins/main"));
|
|
19
21
|
var _getRuleQuickInsertComponents = require("./ui/quick-insert/getRuleQuickInsertComponents");
|
|
20
22
|
var _toolbar = require("./ui/toolbar");
|
|
21
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; }
|
|
@@ -45,7 +47,10 @@ var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
|
|
|
45
47
|
insertHorizontalRule: (0, _commands.insertHorizontalRule)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
|
|
46
48
|
},
|
|
47
49
|
pmPlugins: function pmPlugins() {
|
|
48
|
-
return [{
|
|
50
|
+
return [].concat((0, _toConsumableArray2.default)((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers') ? [{
|
|
51
|
+
name: 'ruleNodeView',
|
|
52
|
+
plugin: _main.default
|
|
53
|
+
}] : []), [{
|
|
49
54
|
name: 'ruleInputRule',
|
|
50
55
|
plugin: function plugin(_ref2) {
|
|
51
56
|
var _api$analytics2;
|
|
@@ -58,7 +63,7 @@ var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
|
|
|
58
63
|
var _api$analytics3;
|
|
59
64
|
return (0, _keymap.default)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
60
65
|
}
|
|
61
|
-
}];
|
|
66
|
+
}]);
|
|
62
67
|
},
|
|
63
68
|
pluginsOptions: _objectSpread(_objectSpread({}, (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers') ? {
|
|
64
69
|
floatingToolbar: function floatingToolbar(state, intl) {
|
|
@@ -13,9 +13,11 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
13
13
|
var _reactIntl = require("react-intl");
|
|
14
14
|
var _button = _interopRequireDefault(require("@atlaskit/button/icon/button"));
|
|
15
15
|
var _rule = require("@atlaskit/editor-common/messages/rule");
|
|
16
|
+
var _ReactEditorViewContext = _interopRequireDefault(require("@atlaskit/editor-common/ui-react/ReactEditorViewContext"));
|
|
16
17
|
var _strokeWeightLarge = _interopRequireDefault(require("@atlaskit/icon/core/stroke-weight-large"));
|
|
17
18
|
var _strokeWeightMedium = _interopRequireDefault(require("@atlaskit/icon/core/stroke-weight-medium"));
|
|
18
19
|
var _strokeWeightSmall = _interopRequireDefault(require("@atlaskit/icon/core/stroke-weight-small"));
|
|
20
|
+
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
19
21
|
var _box = require("@atlaskit/primitives/compiled/box");
|
|
20
22
|
var _text = require("@atlaskit/primitives/compiled/text");
|
|
21
23
|
var _constants = require("./constants");
|
|
@@ -32,6 +34,7 @@ var styles = {
|
|
|
32
34
|
dividerOptionsButtonContainer: "_1rjc1b66"
|
|
33
35
|
};
|
|
34
36
|
var dividerOptionsButtonStyles = null;
|
|
37
|
+
var dividerOptionsButtonStylesOld = null;
|
|
35
38
|
var SmallWeightIcon = function SmallWeightIcon(iconProps) {
|
|
36
39
|
return /*#__PURE__*/_react.default.createElement(_strokeWeightSmall.default, {
|
|
37
40
|
color: "var(--ds-icon-subtle, #505258)",
|
|
@@ -89,21 +92,25 @@ var styleOptionRows = [
|
|
|
89
92
|
value: 'fade'
|
|
90
93
|
}]];
|
|
91
94
|
var DividerOptionButton = function DividerOptionButton(_ref) {
|
|
92
|
-
var
|
|
95
|
+
var autoFocus = _ref.autoFocus,
|
|
96
|
+
icon = _ref.icon,
|
|
93
97
|
isSelected = _ref.isSelected,
|
|
94
98
|
label = _ref.label,
|
|
99
|
+
onKeyDownCapture = _ref.onKeyDownCapture,
|
|
95
100
|
onSelect = _ref.onSelect,
|
|
96
101
|
value = _ref.value;
|
|
97
102
|
var handleClick = (0, _react.useCallback)(function () {
|
|
98
103
|
return onSelect === null || onSelect === void 0 ? void 0 : onSelect(value);
|
|
99
104
|
}, [onSelect, value]);
|
|
100
105
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
101
|
-
className: (0, _runtime.ax)(["_2rko1mok
|
|
106
|
+
className: (0, _runtime.ax)(["_2rko1mok _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq", !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers_patch_1') && "_1reo15vq _18m915vq"])
|
|
102
107
|
}, /*#__PURE__*/_react.default.createElement(_button.default, {
|
|
108
|
+
autoFocus: autoFocus,
|
|
103
109
|
icon: icon,
|
|
104
110
|
isSelected: isSelected,
|
|
105
111
|
label: label,
|
|
106
|
-
onClick: handleClick
|
|
112
|
+
onClick: handleClick,
|
|
113
|
+
onKeyDownCapture: onKeyDownCapture
|
|
107
114
|
}));
|
|
108
115
|
};
|
|
109
116
|
var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
|
|
@@ -113,10 +120,50 @@ var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
|
|
|
113
120
|
weight = _ref2.weight;
|
|
114
121
|
var _useIntl = (0, _reactIntl.useIntl)(),
|
|
115
122
|
formatMessage = _useIntl.formatMessage;
|
|
123
|
+
var _useContext = (0, _react.useContext)(_ReactEditorViewContext.default),
|
|
124
|
+
popupsMountPoint = _useContext.popupsMountPoint;
|
|
125
|
+
var containerRef = (0, _react.useRef)(null);
|
|
126
|
+
var handleKeyDown = (0, _react.useCallback)(function (event) {
|
|
127
|
+
var _containerRef$current, _containerRef$current2, _buttons$nextIndex;
|
|
128
|
+
var buttons = Array.from((_containerRef$current = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.querySelectorAll('button')) !== null && _containerRef$current !== void 0 ? _containerRef$current : []);
|
|
129
|
+
var index = buttons.indexOf(event.currentTarget);
|
|
130
|
+
if (index === -1) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
var columns = weightOptions.length;
|
|
134
|
+
var row = Math.floor(index / columns);
|
|
135
|
+
var column = index % columns;
|
|
136
|
+
var rows = [weightOptions].concat(styleOptionRows);
|
|
137
|
+
var nextIndex;
|
|
138
|
+
switch (event.key) {
|
|
139
|
+
case 'ArrowDown':
|
|
140
|
+
case 'ArrowUp':
|
|
141
|
+
{
|
|
142
|
+
var nextRow = (row + (event.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length;
|
|
143
|
+
nextIndex = nextRow * columns + Math.min(column, rows[nextRow].length - 1);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'ArrowRight':
|
|
147
|
+
nextIndex = (index + 1) % buttons.length;
|
|
148
|
+
break;
|
|
149
|
+
case 'ArrowLeft':
|
|
150
|
+
nextIndex = (index - 1 + buttons.length) % buttons.length;
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
event.stopPropagation();
|
|
157
|
+
(_buttons$nextIndex = buttons[nextIndex]) === null || _buttons$nextIndex === void 0 || _buttons$nextIndex.focus();
|
|
158
|
+
}, []);
|
|
116
159
|
var selectedStyle = style !== null && style !== void 0 ? style : _constants.DEFAULT_DIVIDER_STYLE;
|
|
117
160
|
var selectedWeight = weight !== null && weight !== void 0 ? weight : _constants.DEFAULT_DIVIDER_WEIGHT;
|
|
161
|
+
var isPatchEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers_patch_1');
|
|
118
162
|
return /*#__PURE__*/_react.default.createElement(_box.Box, {
|
|
119
|
-
xcss: styles.container
|
|
163
|
+
xcss: styles.container,
|
|
164
|
+
ref: isPatchEnabled ? containerRef : undefined,
|
|
165
|
+
role: isPatchEnabled ? 'group' : undefined,
|
|
166
|
+
"aria-label": isPatchEnabled ? formatMessage(_rule.ruleMessages.dividerOptions) : undefined
|
|
120
167
|
}, /*#__PURE__*/_react.default.createElement(_box.Box, {
|
|
121
168
|
xcss: styles.section
|
|
122
169
|
}, /*#__PURE__*/_react.default.createElement(_text.Text, {
|
|
@@ -132,9 +179,14 @@ var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
|
|
|
132
179
|
value = _ref3.value;
|
|
133
180
|
return /*#__PURE__*/_react.default.createElement(DividerOptionButton, {
|
|
134
181
|
key: value,
|
|
182
|
+
autoFocus:
|
|
183
|
+
// when there is no custom mount point, Dropdown sends ArrowDown
|
|
184
|
+
// on keyboard open so autofocusing is not required.
|
|
185
|
+
isPatchEnabled && Boolean(popupsMountPoint) && value === weightOptions[0].value,
|
|
135
186
|
icon: icon,
|
|
136
187
|
isSelected: selectedWeight === value,
|
|
137
188
|
label: formatMessage(label),
|
|
189
|
+
onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
|
|
138
190
|
onSelect: onWeightChange,
|
|
139
191
|
value: value
|
|
140
192
|
});
|
|
@@ -158,6 +210,7 @@ var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
|
|
|
158
210
|
icon: icon,
|
|
159
211
|
isSelected: selectedStyle === value,
|
|
160
212
|
label: formatMessage(label),
|
|
213
|
+
onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
|
|
161
214
|
onSelect: onStyleChange,
|
|
162
215
|
value: value
|
|
163
216
|
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
const ruleNodeViewAttribute = 'data-rule-node-view';
|
|
5
|
+
export class RuleNodeView {
|
|
6
|
+
constructor(node, view) {
|
|
7
|
+
// when there is only 1 rule node on the page and it is not editable, clicking on it does not focus the editor and Cmd+C/ Ctrl+C shortcut will not work. this mouse down listener adds focus to the editor.
|
|
8
|
+
_defineProperty(this, "handleMousedown", () => {
|
|
9
|
+
if (!this.view.hasFocus()) {
|
|
10
|
+
this.view.focus();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
this.node = node;
|
|
14
|
+
this.view = view;
|
|
15
|
+
const dom = this.view.dom.ownerDocument.createElement('div');
|
|
16
|
+
this.dom = dom;
|
|
17
|
+
dom.setAttribute(ruleNodeViewAttribute, '');
|
|
18
|
+
dom.setAttribute('contenteditable', 'inherit');
|
|
19
|
+
this.unbindMousedown = bind(dom, {
|
|
20
|
+
type: 'mousedown',
|
|
21
|
+
listener: this.handleMousedown
|
|
22
|
+
});
|
|
23
|
+
this.update(node);
|
|
24
|
+
}
|
|
25
|
+
update(node) {
|
|
26
|
+
if (node.type !== this.node.type) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (this.dom.firstChild && node.sameMarkup(this.node)) {
|
|
30
|
+
this.node = node;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
const toDOM = node.type.spec.toDOM;
|
|
34
|
+
if (!toDOM) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const {
|
|
38
|
+
dom
|
|
39
|
+
} = DOMSerializer.renderSpec(this.view.dom.ownerDocument, toDOM(node));
|
|
40
|
+
if (dom instanceof HTMLElement) {
|
|
41
|
+
dom.contentEditable = 'false';
|
|
42
|
+
}
|
|
43
|
+
if (this.dom.firstChild) {
|
|
44
|
+
this.dom.replaceChild(dom, this.dom.firstChild);
|
|
45
|
+
} else {
|
|
46
|
+
this.dom.appendChild(dom);
|
|
47
|
+
}
|
|
48
|
+
this.node = node;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
ignoreMutation() {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
destroy() {
|
|
55
|
+
this.unbindMousedown();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { RuleNodeView } from '../node-views/RuleNodeView';
|
|
4
|
+
const selectRuleOnClick = createSelectionClickHandler(['rule'], target => !!target.closest('[data-rule-node-view]'), {
|
|
5
|
+
useLongPressSelection: false
|
|
6
|
+
});
|
|
7
|
+
export const createPlugin = () => new SafePlugin({
|
|
8
|
+
props: {
|
|
9
|
+
nodeViews: {
|
|
10
|
+
rule: (node, view) => new RuleNodeView(node, view)
|
|
11
|
+
},
|
|
12
|
+
handleClickOn(view, ...args) {
|
|
13
|
+
const handled = selectRuleOnClick(view, ...args);
|
|
14
|
+
if (handled && view.editable) {
|
|
15
|
+
view.focus();
|
|
16
|
+
}
|
|
17
|
+
return handled;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export default createPlugin;
|
|
@@ -12,6 +12,7 @@ import inputRulePlugin from './pm-plugins/input-rule';
|
|
|
12
12
|
// Ignored via go/ees005
|
|
13
13
|
// eslint-disable-next-line import/no-named-as-default
|
|
14
14
|
import keymapPlugin from './pm-plugins/keymap';
|
|
15
|
+
import ruleNodeViewPlugin from './pm-plugins/main';
|
|
15
16
|
import { getRuleQuickInsertComponents } from './ui/quick-insert/getRuleQuickInsertComponents';
|
|
16
17
|
import { getToolbarConfig } from './ui/toolbar';
|
|
17
18
|
export const rulePlugin = ({
|
|
@@ -37,7 +38,10 @@ export const rulePlugin = ({
|
|
|
37
38
|
insertHorizontalRule: insertHorizontalRule(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
|
|
38
39
|
},
|
|
39
40
|
pmPlugins() {
|
|
40
|
-
return [{
|
|
41
|
+
return [...(isExperimentEnabled('platform_editor_lovability_dividers') ? [{
|
|
42
|
+
name: 'ruleNodeView',
|
|
43
|
+
plugin: ruleNodeViewPlugin
|
|
44
|
+
}] : []), {
|
|
41
45
|
name: 'ruleInputRule',
|
|
42
46
|
plugin: ({
|
|
43
47
|
schema
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.2 */
|
|
2
2
|
import "./DividerOptions.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
-
import React, { useCallback } from 'react';
|
|
4
|
+
import React, { useCallback, useContext, useRef } from 'react';
|
|
5
5
|
import { useIntl } from 'react-intl';
|
|
6
6
|
import IconButton from '@atlaskit/button/icon/button';
|
|
7
7
|
import { ruleMessages as messages } from '@atlaskit/editor-common/messages/rule';
|
|
8
|
+
import ReactEditorViewContext from '@atlaskit/editor-common/ui-react/ReactEditorViewContext';
|
|
8
9
|
import StrokeWeightLargeIcon from '@atlaskit/icon/core/stroke-weight-large';
|
|
9
10
|
import StrokeWeightMediumIcon from '@atlaskit/icon/core/stroke-weight-medium';
|
|
10
11
|
import StrokeWeightSmallIcon from '@atlaskit/icon/core/stroke-weight-small';
|
|
12
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
11
13
|
import { Box } from '@atlaskit/primitives/compiled/box';
|
|
12
14
|
import { Text } from '@atlaskit/primitives/compiled/text';
|
|
13
15
|
import { DEFAULT_DIVIDER_STYLE, DEFAULT_DIVIDER_WEIGHT } from './constants';
|
|
@@ -23,6 +25,7 @@ const styles = {
|
|
|
23
25
|
dividerOptionsButtonContainer: "_1rjc1b66"
|
|
24
26
|
};
|
|
25
27
|
const dividerOptionsButtonStyles = null;
|
|
28
|
+
const dividerOptionsButtonStylesOld = null;
|
|
26
29
|
const SmallWeightIcon = iconProps => /*#__PURE__*/React.createElement(StrokeWeightSmallIcon, {
|
|
27
30
|
color: "var(--ds-icon-subtle, #505258)",
|
|
28
31
|
label: iconProps.label
|
|
@@ -74,20 +77,24 @@ const styleOptionRows = [
|
|
|
74
77
|
value: 'fade'
|
|
75
78
|
}]];
|
|
76
79
|
const DividerOptionButton = ({
|
|
80
|
+
autoFocus,
|
|
77
81
|
icon,
|
|
78
82
|
isSelected,
|
|
79
83
|
label,
|
|
84
|
+
onKeyDownCapture,
|
|
80
85
|
onSelect,
|
|
81
86
|
value
|
|
82
87
|
}) => {
|
|
83
88
|
const handleClick = useCallback(() => onSelect === null || onSelect === void 0 ? void 0 : onSelect(value), [onSelect, value]);
|
|
84
89
|
return /*#__PURE__*/React.createElement("div", {
|
|
85
|
-
className: ax(["_2rko1mok
|
|
90
|
+
className: ax(["_2rko1mok _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq", !isExperimentEnabled('platform_editor_lovability_dividers_patch_1') && "_1reo15vq _18m915vq"])
|
|
86
91
|
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
92
|
+
autoFocus: autoFocus,
|
|
87
93
|
icon: icon,
|
|
88
94
|
isSelected: isSelected,
|
|
89
95
|
label: label,
|
|
90
|
-
onClick: handleClick
|
|
96
|
+
onClick: handleClick,
|
|
97
|
+
onKeyDownCapture: onKeyDownCapture
|
|
91
98
|
}));
|
|
92
99
|
};
|
|
93
100
|
export const DividerOptions = ({
|
|
@@ -99,10 +106,51 @@ export const DividerOptions = ({
|
|
|
99
106
|
const {
|
|
100
107
|
formatMessage
|
|
101
108
|
} = useIntl();
|
|
109
|
+
const {
|
|
110
|
+
popupsMountPoint
|
|
111
|
+
} = useContext(ReactEditorViewContext);
|
|
112
|
+
const containerRef = useRef(null);
|
|
113
|
+
const handleKeyDown = useCallback(event => {
|
|
114
|
+
var _containerRef$current, _containerRef$current2, _buttons$nextIndex;
|
|
115
|
+
const buttons = Array.from((_containerRef$current = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.querySelectorAll('button')) !== null && _containerRef$current !== void 0 ? _containerRef$current : []);
|
|
116
|
+
const index = buttons.indexOf(event.currentTarget);
|
|
117
|
+
if (index === -1) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const columns = weightOptions.length;
|
|
121
|
+
const row = Math.floor(index / columns);
|
|
122
|
+
const column = index % columns;
|
|
123
|
+
const rows = [weightOptions, ...styleOptionRows];
|
|
124
|
+
let nextIndex;
|
|
125
|
+
switch (event.key) {
|
|
126
|
+
case 'ArrowDown':
|
|
127
|
+
case 'ArrowUp':
|
|
128
|
+
{
|
|
129
|
+
const nextRow = (row + (event.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length;
|
|
130
|
+
nextIndex = nextRow * columns + Math.min(column, rows[nextRow].length - 1);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case 'ArrowRight':
|
|
134
|
+
nextIndex = (index + 1) % buttons.length;
|
|
135
|
+
break;
|
|
136
|
+
case 'ArrowLeft':
|
|
137
|
+
nextIndex = (index - 1 + buttons.length) % buttons.length;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
event.stopPropagation();
|
|
144
|
+
(_buttons$nextIndex = buttons[nextIndex]) === null || _buttons$nextIndex === void 0 ? void 0 : _buttons$nextIndex.focus();
|
|
145
|
+
}, []);
|
|
102
146
|
const selectedStyle = style !== null && style !== void 0 ? style : DEFAULT_DIVIDER_STYLE;
|
|
103
147
|
const selectedWeight = weight !== null && weight !== void 0 ? weight : DEFAULT_DIVIDER_WEIGHT;
|
|
148
|
+
const isPatchEnabled = isExperimentEnabled('platform_editor_lovability_dividers_patch_1');
|
|
104
149
|
return /*#__PURE__*/React.createElement(Box, {
|
|
105
|
-
xcss: styles.container
|
|
150
|
+
xcss: styles.container,
|
|
151
|
+
ref: isPatchEnabled ? containerRef : undefined,
|
|
152
|
+
role: isPatchEnabled ? 'group' : undefined,
|
|
153
|
+
"aria-label": isPatchEnabled ? formatMessage(messages.dividerOptions) : undefined
|
|
106
154
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
107
155
|
xcss: styles.section
|
|
108
156
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
@@ -118,9 +166,14 @@ export const DividerOptions = ({
|
|
|
118
166
|
value
|
|
119
167
|
}) => /*#__PURE__*/React.createElement(DividerOptionButton, {
|
|
120
168
|
key: value,
|
|
169
|
+
autoFocus:
|
|
170
|
+
// when there is no custom mount point, Dropdown sends ArrowDown
|
|
171
|
+
// on keyboard open so autofocusing is not required.
|
|
172
|
+
isPatchEnabled && Boolean(popupsMountPoint) && value === weightOptions[0].value,
|
|
121
173
|
icon: icon,
|
|
122
174
|
isSelected: selectedWeight === value,
|
|
123
175
|
label: formatMessage(label),
|
|
176
|
+
onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
|
|
124
177
|
onSelect: onWeightChange,
|
|
125
178
|
value: value
|
|
126
179
|
}))))), /*#__PURE__*/React.createElement(Box, {
|
|
@@ -142,6 +195,7 @@ export const DividerOptions = ({
|
|
|
142
195
|
icon: icon,
|
|
143
196
|
isSelected: selectedStyle === value,
|
|
144
197
|
label: formatMessage(label),
|
|
198
|
+
onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
|
|
145
199
|
onSelect: onStyleChange,
|
|
146
200
|
value: value
|
|
147
201
|
})))))));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import { bind } from 'bind-event-listener';
|
|
5
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
6
|
+
var ruleNodeViewAttribute = 'data-rule-node-view';
|
|
7
|
+
export var RuleNodeView = /*#__PURE__*/function () {
|
|
8
|
+
function RuleNodeView(node, view) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
_classCallCheck(this, RuleNodeView);
|
|
11
|
+
// when there is only 1 rule node on the page and it is not editable, clicking on it does not focus the editor and Cmd+C/ Ctrl+C shortcut will not work. this mouse down listener adds focus to the editor.
|
|
12
|
+
_defineProperty(this, "handleMousedown", function () {
|
|
13
|
+
if (!_this.view.hasFocus()) {
|
|
14
|
+
_this.view.focus();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
this.node = node;
|
|
18
|
+
this.view = view;
|
|
19
|
+
var dom = this.view.dom.ownerDocument.createElement('div');
|
|
20
|
+
this.dom = dom;
|
|
21
|
+
dom.setAttribute(ruleNodeViewAttribute, '');
|
|
22
|
+
dom.setAttribute('contenteditable', 'inherit');
|
|
23
|
+
this.unbindMousedown = bind(dom, {
|
|
24
|
+
type: 'mousedown',
|
|
25
|
+
listener: this.handleMousedown
|
|
26
|
+
});
|
|
27
|
+
this.update(node);
|
|
28
|
+
}
|
|
29
|
+
return _createClass(RuleNodeView, [{
|
|
30
|
+
key: "update",
|
|
31
|
+
value: function update(node) {
|
|
32
|
+
if (node.type !== this.node.type) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (this.dom.firstChild && node.sameMarkup(this.node)) {
|
|
36
|
+
this.node = node;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
var toDOM = node.type.spec.toDOM;
|
|
40
|
+
if (!toDOM) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
var _DOMSerializer$render = DOMSerializer.renderSpec(this.view.dom.ownerDocument, toDOM(node)),
|
|
44
|
+
dom = _DOMSerializer$render.dom;
|
|
45
|
+
if (dom instanceof HTMLElement) {
|
|
46
|
+
dom.contentEditable = 'false';
|
|
47
|
+
}
|
|
48
|
+
if (this.dom.firstChild) {
|
|
49
|
+
this.dom.replaceChild(dom, this.dom.firstChild);
|
|
50
|
+
} else {
|
|
51
|
+
this.dom.appendChild(dom);
|
|
52
|
+
}
|
|
53
|
+
this.node = node;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "ignoreMutation",
|
|
58
|
+
value: function ignoreMutation() {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "destroy",
|
|
63
|
+
value: function destroy() {
|
|
64
|
+
this.unbindMousedown();
|
|
65
|
+
}
|
|
66
|
+
}]);
|
|
67
|
+
}();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { RuleNodeView } from '../node-views/RuleNodeView';
|
|
4
|
+
var selectRuleOnClick = createSelectionClickHandler(['rule'], function (target) {
|
|
5
|
+
return !!target.closest('[data-rule-node-view]');
|
|
6
|
+
}, {
|
|
7
|
+
useLongPressSelection: false
|
|
8
|
+
});
|
|
9
|
+
export var createPlugin = function createPlugin() {
|
|
10
|
+
return new SafePlugin({
|
|
11
|
+
props: {
|
|
12
|
+
nodeViews: {
|
|
13
|
+
rule: function rule(node, view) {
|
|
14
|
+
return new RuleNodeView(node, view);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
handleClickOn: function handleClickOn(view) {
|
|
18
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
19
|
+
args[_key - 1] = arguments[_key];
|
|
20
|
+
}
|
|
21
|
+
var handled = selectRuleOnClick.apply(void 0, [view].concat(args));
|
|
22
|
+
if (handled && view.editable) {
|
|
23
|
+
view.focus();
|
|
24
|
+
}
|
|
25
|
+
return handled;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export default createPlugin;
|
package/dist/esm/rulePlugin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
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; }
|
|
3
4
|
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; }
|
|
4
5
|
import React from 'react';
|
|
@@ -15,6 +16,7 @@ import inputRulePlugin from './pm-plugins/input-rule';
|
|
|
15
16
|
// Ignored via go/ees005
|
|
16
17
|
// eslint-disable-next-line import/no-named-as-default
|
|
17
18
|
import keymapPlugin from './pm-plugins/keymap';
|
|
19
|
+
import ruleNodeViewPlugin from './pm-plugins/main';
|
|
18
20
|
import { getRuleQuickInsertComponents } from './ui/quick-insert/getRuleQuickInsertComponents';
|
|
19
21
|
import { getToolbarConfig } from './ui/toolbar';
|
|
20
22
|
export var rulePlugin = function rulePlugin(_ref) {
|
|
@@ -39,7 +41,10 @@ export var rulePlugin = function rulePlugin(_ref) {
|
|
|
39
41
|
insertHorizontalRule: insertHorizontalRule(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
|
|
40
42
|
},
|
|
41
43
|
pmPlugins: function pmPlugins() {
|
|
42
|
-
return [{
|
|
44
|
+
return [].concat(_toConsumableArray(isExperimentEnabled('platform_editor_lovability_dividers') ? [{
|
|
45
|
+
name: 'ruleNodeView',
|
|
46
|
+
plugin: ruleNodeViewPlugin
|
|
47
|
+
}] : []), [{
|
|
43
48
|
name: 'ruleInputRule',
|
|
44
49
|
plugin: function plugin(_ref2) {
|
|
45
50
|
var _api$analytics2;
|
|
@@ -52,7 +57,7 @@ export var rulePlugin = function rulePlugin(_ref) {
|
|
|
52
57
|
var _api$analytics3;
|
|
53
58
|
return keymapPlugin(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
54
59
|
}
|
|
55
|
-
}];
|
|
60
|
+
}]);
|
|
56
61
|
},
|
|
57
62
|
pluginsOptions: _objectSpread(_objectSpread({}, isExperimentEnabled('platform_editor_lovability_dividers') ? {
|
|
58
63
|
floatingToolbar: function floatingToolbar(state, intl) {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.2 */
|
|
2
2
|
import "./DividerOptions.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
-
import React, { useCallback } from 'react';
|
|
4
|
+
import React, { useCallback, useContext, useRef } from 'react';
|
|
5
5
|
import { useIntl } from 'react-intl';
|
|
6
6
|
import IconButton from '@atlaskit/button/icon/button';
|
|
7
7
|
import { ruleMessages as messages } from '@atlaskit/editor-common/messages/rule';
|
|
8
|
+
import ReactEditorViewContext from '@atlaskit/editor-common/ui-react/ReactEditorViewContext';
|
|
8
9
|
import StrokeWeightLargeIcon from '@atlaskit/icon/core/stroke-weight-large';
|
|
9
10
|
import StrokeWeightMediumIcon from '@atlaskit/icon/core/stroke-weight-medium';
|
|
10
11
|
import StrokeWeightSmallIcon from '@atlaskit/icon/core/stroke-weight-small';
|
|
12
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
11
13
|
import { Box } from '@atlaskit/primitives/compiled/box';
|
|
12
14
|
import { Text } from '@atlaskit/primitives/compiled/text';
|
|
13
15
|
import { DEFAULT_DIVIDER_STYLE, DEFAULT_DIVIDER_WEIGHT } from './constants';
|
|
@@ -23,6 +25,7 @@ var styles = {
|
|
|
23
25
|
dividerOptionsButtonContainer: "_1rjc1b66"
|
|
24
26
|
};
|
|
25
27
|
var dividerOptionsButtonStyles = null;
|
|
28
|
+
var dividerOptionsButtonStylesOld = null;
|
|
26
29
|
var SmallWeightIcon = function SmallWeightIcon(iconProps) {
|
|
27
30
|
return /*#__PURE__*/React.createElement(StrokeWeightSmallIcon, {
|
|
28
31
|
color: "var(--ds-icon-subtle, #505258)",
|
|
@@ -80,21 +83,25 @@ var styleOptionRows = [
|
|
|
80
83
|
value: 'fade'
|
|
81
84
|
}]];
|
|
82
85
|
var DividerOptionButton = function DividerOptionButton(_ref) {
|
|
83
|
-
var
|
|
86
|
+
var autoFocus = _ref.autoFocus,
|
|
87
|
+
icon = _ref.icon,
|
|
84
88
|
isSelected = _ref.isSelected,
|
|
85
89
|
label = _ref.label,
|
|
90
|
+
onKeyDownCapture = _ref.onKeyDownCapture,
|
|
86
91
|
onSelect = _ref.onSelect,
|
|
87
92
|
value = _ref.value;
|
|
88
93
|
var handleClick = useCallback(function () {
|
|
89
94
|
return onSelect === null || onSelect === void 0 ? void 0 : onSelect(value);
|
|
90
95
|
}, [onSelect, value]);
|
|
91
96
|
return /*#__PURE__*/React.createElement("div", {
|
|
92
|
-
className: ax(["_2rko1mok
|
|
97
|
+
className: ax(["_2rko1mok _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq", !isExperimentEnabled('platform_editor_lovability_dividers_patch_1') && "_1reo15vq _18m915vq"])
|
|
93
98
|
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
99
|
+
autoFocus: autoFocus,
|
|
94
100
|
icon: icon,
|
|
95
101
|
isSelected: isSelected,
|
|
96
102
|
label: label,
|
|
97
|
-
onClick: handleClick
|
|
103
|
+
onClick: handleClick,
|
|
104
|
+
onKeyDownCapture: onKeyDownCapture
|
|
98
105
|
}));
|
|
99
106
|
};
|
|
100
107
|
export var DividerOptions = function DividerOptions(_ref2) {
|
|
@@ -104,10 +111,50 @@ export var DividerOptions = function DividerOptions(_ref2) {
|
|
|
104
111
|
weight = _ref2.weight;
|
|
105
112
|
var _useIntl = useIntl(),
|
|
106
113
|
formatMessage = _useIntl.formatMessage;
|
|
114
|
+
var _useContext = useContext(ReactEditorViewContext),
|
|
115
|
+
popupsMountPoint = _useContext.popupsMountPoint;
|
|
116
|
+
var containerRef = useRef(null);
|
|
117
|
+
var handleKeyDown = useCallback(function (event) {
|
|
118
|
+
var _containerRef$current, _containerRef$current2, _buttons$nextIndex;
|
|
119
|
+
var buttons = Array.from((_containerRef$current = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.querySelectorAll('button')) !== null && _containerRef$current !== void 0 ? _containerRef$current : []);
|
|
120
|
+
var index = buttons.indexOf(event.currentTarget);
|
|
121
|
+
if (index === -1) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
var columns = weightOptions.length;
|
|
125
|
+
var row = Math.floor(index / columns);
|
|
126
|
+
var column = index % columns;
|
|
127
|
+
var rows = [weightOptions].concat(styleOptionRows);
|
|
128
|
+
var nextIndex;
|
|
129
|
+
switch (event.key) {
|
|
130
|
+
case 'ArrowDown':
|
|
131
|
+
case 'ArrowUp':
|
|
132
|
+
{
|
|
133
|
+
var nextRow = (row + (event.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length;
|
|
134
|
+
nextIndex = nextRow * columns + Math.min(column, rows[nextRow].length - 1);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case 'ArrowRight':
|
|
138
|
+
nextIndex = (index + 1) % buttons.length;
|
|
139
|
+
break;
|
|
140
|
+
case 'ArrowLeft':
|
|
141
|
+
nextIndex = (index - 1 + buttons.length) % buttons.length;
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
event.stopPropagation();
|
|
148
|
+
(_buttons$nextIndex = buttons[nextIndex]) === null || _buttons$nextIndex === void 0 || _buttons$nextIndex.focus();
|
|
149
|
+
}, []);
|
|
107
150
|
var selectedStyle = style !== null && style !== void 0 ? style : DEFAULT_DIVIDER_STYLE;
|
|
108
151
|
var selectedWeight = weight !== null && weight !== void 0 ? weight : DEFAULT_DIVIDER_WEIGHT;
|
|
152
|
+
var isPatchEnabled = isExperimentEnabled('platform_editor_lovability_dividers_patch_1');
|
|
109
153
|
return /*#__PURE__*/React.createElement(Box, {
|
|
110
|
-
xcss: styles.container
|
|
154
|
+
xcss: styles.container,
|
|
155
|
+
ref: isPatchEnabled ? containerRef : undefined,
|
|
156
|
+
role: isPatchEnabled ? 'group' : undefined,
|
|
157
|
+
"aria-label": isPatchEnabled ? formatMessage(messages.dividerOptions) : undefined
|
|
111
158
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
112
159
|
xcss: styles.section
|
|
113
160
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
@@ -123,9 +170,14 @@ export var DividerOptions = function DividerOptions(_ref2) {
|
|
|
123
170
|
value = _ref3.value;
|
|
124
171
|
return /*#__PURE__*/React.createElement(DividerOptionButton, {
|
|
125
172
|
key: value,
|
|
173
|
+
autoFocus:
|
|
174
|
+
// when there is no custom mount point, Dropdown sends ArrowDown
|
|
175
|
+
// on keyboard open so autofocusing is not required.
|
|
176
|
+
isPatchEnabled && Boolean(popupsMountPoint) && value === weightOptions[0].value,
|
|
126
177
|
icon: icon,
|
|
127
178
|
isSelected: selectedWeight === value,
|
|
128
179
|
label: formatMessage(label),
|
|
180
|
+
onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
|
|
129
181
|
onSelect: onWeightChange,
|
|
130
182
|
value: value
|
|
131
183
|
});
|
|
@@ -149,6 +201,7 @@ export var DividerOptions = function DividerOptions(_ref2) {
|
|
|
149
201
|
icon: icon,
|
|
150
202
|
isSelected: selectedStyle === value,
|
|
151
203
|
label: formatMessage(label),
|
|
204
|
+
onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
|
|
152
205
|
onSelect: onStyleChange,
|
|
153
206
|
value: value
|
|
154
207
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
export declare class RuleNodeView implements NodeView {
|
|
4
|
+
dom: Node;
|
|
5
|
+
private node;
|
|
6
|
+
private readonly view;
|
|
7
|
+
private readonly handleMousedown;
|
|
8
|
+
private readonly unbindMousedown;
|
|
9
|
+
constructor(node: PMNode, view: EditorView);
|
|
10
|
+
update(node: PMNode): boolean;
|
|
11
|
+
ignoreMutation(): boolean;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-rule",
|
|
3
|
-
"version": "30.0.
|
|
3
|
+
"version": "30.0.3",
|
|
4
4
|
"description": "Rule plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,14 +37,16 @@
|
|
|
37
37
|
"@atlaskit/tokens": "^20.9.0",
|
|
38
38
|
"@babel/runtime": "^7.0.0",
|
|
39
39
|
"@compiled/react": "^1.0.2",
|
|
40
|
+
"bind-event-listener": "^3.0.0",
|
|
40
41
|
"react-intl": "^7.0.0"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
|
-
"@atlaskit/editor-common": "^134.
|
|
44
|
+
"@atlaskit/editor-common": "^134.5.0",
|
|
44
45
|
"react": "^18.2.0 || ^19.2.0",
|
|
45
46
|
"react-dom": "^18.2.0 || ^19.2.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
49
|
+
"@atlaskit/editor-common": "^134.5.0",
|
|
48
50
|
"@testing-library/react": "^16.3.0",
|
|
49
51
|
"react": "^19.2.0",
|
|
50
52
|
"react-dom": "^19.2.0"
|