@atlaskit/editor-plugin-rule 17.0.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/pm-plugins/commands.js +25 -1
- package/dist/cjs/pm-plugins/input-rule.js +1 -1
- package/dist/cjs/rulePlugin.js +10 -5
- package/dist/cjs/ui/toolbar.js +74 -0
- package/dist/es2019/pm-plugins/commands.js +24 -0
- package/dist/es2019/pm-plugins/input-rule.js +1 -1
- package/dist/es2019/rulePlugin.js +4 -0
- package/dist/es2019/ui/toolbar.js +70 -0
- package/dist/esm/pm-plugins/commands.js +24 -0
- package/dist/esm/pm-plugins/input-rule.js +1 -1
- package/dist/esm/rulePlugin.js +10 -2
- package/dist/esm/ui/toolbar.js +67 -0
- package/dist/types/pm-plugins/commands.d.ts +4 -2
- package/dist/types/pm-plugins/input-rule.d.ts +1 -1
- package/dist/types/rulePluginType.d.ts +5 -1
- package/dist/types/ui/toolbar.d.ts +5 -0
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-rule
|
|
2
2
|
|
|
3
|
+
## 18.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 17.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`0e5685af71a8f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0e5685af71a8f) -
|
|
14
|
+
[ux] [EDITOR-8350] This change adds a feature-gated floating toolbar for divider nodes behind
|
|
15
|
+
platform_editor_lovability_dividers, with Copy and Delete buttons.
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 17.0.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.insertHorizontalRule = void 0;
|
|
6
|
+
exports.removeHorizontalRule = exports.insertHorizontalRule = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
7
8
|
var _inputRule = require("./input-rule");
|
|
9
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
8
10
|
var insertHorizontalRule = exports.insertHorizontalRule = function insertHorizontalRule(editorAnalyticsAPI) {
|
|
9
11
|
return function (inputMethod) {
|
|
10
12
|
return function (state, dispatch) {
|
|
@@ -18,4 +20,26 @@ var insertHorizontalRule = exports.insertHorizontalRule = function insertHorizon
|
|
|
18
20
|
return false;
|
|
19
21
|
};
|
|
20
22
|
};
|
|
23
|
+
};
|
|
24
|
+
var removeHorizontalRule = exports.removeHorizontalRule = function removeHorizontalRule(editorAnalyticsAPI) {
|
|
25
|
+
return function (state, dispatch) {
|
|
26
|
+
var rule = state.schema.nodes.rule;
|
|
27
|
+
if (!(0, _utils.findSelectedNodeOfType)(rule)(state.selection)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (dispatch) {
|
|
31
|
+
var deleteTr = (0, _utils.removeSelectedNode)(state.tr);
|
|
32
|
+
var payload = {
|
|
33
|
+
action: _analytics.ACTION.DELETED,
|
|
34
|
+
actionSubject: _analytics.ACTION_SUBJECT.DIVIDER,
|
|
35
|
+
attributes: {
|
|
36
|
+
inputMethod: _analytics.INPUT_METHOD.FLOATING_TB
|
|
37
|
+
},
|
|
38
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
39
|
+
};
|
|
40
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(deleteTr);
|
|
41
|
+
dispatch(deleteTr);
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
21
45
|
};
|
|
@@ -50,7 +50,7 @@ var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(sta
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
// eslint-disable-next-line require-unicode-regexp
|
|
53
|
-
var HORIZONTAL_RULE_AUTOFORMAT_REGEX = /^(
|
|
53
|
+
var HORIZONTAL_RULE_AUTOFORMAT_REGEX = /^(---|\*\*\*)$/;
|
|
54
54
|
function inputRulePlugin(schema, editorAnalyticsAPI) {
|
|
55
55
|
var rules = [];
|
|
56
56
|
if (schema.nodes.rule) {
|
package/dist/cjs/rulePlugin.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.rulePlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
9
|
var _react = _interopRequireDefault(require("react"));
|
|
9
10
|
var _rule = require("@atlaskit/adf-schema/rule");
|
|
10
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
@@ -16,12 +17,12 @@ var _commands = require("./pm-plugins/commands");
|
|
|
16
17
|
var _inputRule = _interopRequireDefault(require("./pm-plugins/input-rule"));
|
|
17
18
|
var _keymap = _interopRequireDefault(require("./pm-plugins/keymap"));
|
|
18
19
|
var _getRuleQuickInsertComponents = require("./ui/quick-insert/getRuleQuickInsertComponents");
|
|
19
|
-
|
|
20
|
+
var _toolbar = require("./ui/toolbar");
|
|
21
|
+
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; }
|
|
22
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // Ignored via go/ees005
|
|
20
23
|
// eslint-disable-next-line import/no-named-as-default
|
|
21
|
-
|
|
22
24
|
// Ignored via go/ees005
|
|
23
25
|
// eslint-disable-next-line import/no-named-as-default
|
|
24
|
-
|
|
25
26
|
var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
|
|
26
27
|
var _api$analytics;
|
|
27
28
|
var api = _ref.api;
|
|
@@ -59,7 +60,11 @@ var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
|
|
|
59
60
|
}
|
|
60
61
|
}];
|
|
61
62
|
},
|
|
62
|
-
pluginsOptions: {
|
|
63
|
+
pluginsOptions: _objectSpread(_objectSpread({}, (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers') ? {
|
|
64
|
+
floatingToolbar: function floatingToolbar(state, intl) {
|
|
65
|
+
return (0, _toolbar.getToolbarConfig)(state, intl, api);
|
|
66
|
+
}
|
|
67
|
+
} : {}), {}, {
|
|
63
68
|
quickInsert: isRegisteredSlashCommandEnabled ? undefined : function (_ref3) {
|
|
64
69
|
var formatMessage = _ref3.formatMessage;
|
|
65
70
|
return [{
|
|
@@ -88,6 +93,6 @@ var rulePlugin = exports.rulePlugin = function rulePlugin(_ref) {
|
|
|
88
93
|
}
|
|
89
94
|
}];
|
|
90
95
|
}
|
|
91
|
-
}
|
|
96
|
+
})
|
|
92
97
|
};
|
|
93
98
|
};
|
|
@@ -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.getToolbarConfig = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
12
|
+
var _messages = _interopRequireDefault(require("@atlaskit/editor-common/messages"));
|
|
13
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
14
|
+
var _copy = _interopRequireDefault(require("@atlaskit/icon/core/copy"));
|
|
15
|
+
var _delete = _interopRequireDefault(require("@atlaskit/icon/core/delete"));
|
|
16
|
+
var _commands = require("../pm-plugins/commands");
|
|
17
|
+
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; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
var getToolbarItems = function getToolbarItems(formatMessage, ruleNodeType, api) {
|
|
20
|
+
var _api$decorations, _api$analytics;
|
|
21
|
+
var hoverDecoration = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions.hoverDecoration;
|
|
22
|
+
var hoverDecorationProps = function hoverDecorationProps(className) {
|
|
23
|
+
return {
|
|
24
|
+
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
|
|
25
|
+
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, false, className),
|
|
26
|
+
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
|
|
27
|
+
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, false, className)
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var items = [];
|
|
31
|
+
var overflowMenuItems = [{
|
|
32
|
+
type: 'overflow-dropdown',
|
|
33
|
+
options: [_objectSpread({
|
|
34
|
+
title: formatMessage(_messages.default.copyToClipboard),
|
|
35
|
+
icon: /*#__PURE__*/_react.default.createElement(_copy.default, {
|
|
36
|
+
label: ""
|
|
37
|
+
}),
|
|
38
|
+
onClick: function onClick() {
|
|
39
|
+
var _api$core, _api$floatingToolbar;
|
|
40
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$floatingToolbar = api.floatingToolbar) === null || _api$floatingToolbar === void 0 ? void 0 : _api$floatingToolbar.commands.copyNode(ruleNodeType, _analytics.INPUT_METHOD.FLOATING_TB));
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}, hoverDecorationProps(_editorSharedStyles.akEditorSelectedNodeClassName)), _objectSpread({
|
|
44
|
+
title: formatMessage(_messages.default.delete),
|
|
45
|
+
icon: /*#__PURE__*/_react.default.createElement(_delete.default, {
|
|
46
|
+
label: ""
|
|
47
|
+
}),
|
|
48
|
+
onClick: (0, _commands.removeHorizontalRule)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
|
|
49
|
+
}, hoverDecorationProps())]
|
|
50
|
+
}];
|
|
51
|
+
items.push.apply(items, overflowMenuItems);
|
|
52
|
+
return items;
|
|
53
|
+
};
|
|
54
|
+
var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(state, intl, api) {
|
|
55
|
+
var formatMessage = intl.formatMessage;
|
|
56
|
+
var selection = state.selection;
|
|
57
|
+
var rule = state.schema.nodes.rule;
|
|
58
|
+
var isRuleSelection = (0, _utils.findSelectedNodeOfType)(state.schema.nodes.rule)(state.selection);
|
|
59
|
+
if (!isRuleSelection) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
var getDomRef = function getDomRef(editorView) {
|
|
63
|
+
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
64
|
+
var element = (0, _utils.findDomRefAtPos)(selection.from, domAtPos);
|
|
65
|
+
return element;
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
title: 'Divider floating controls',
|
|
69
|
+
getDomRef: getDomRef,
|
|
70
|
+
nodeType: [rule],
|
|
71
|
+
items: getToolbarItems(formatMessage, rule, api),
|
|
72
|
+
scrollable: true
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
1
2
|
import { createHorizontalRule } from './input-rule';
|
|
3
|
+
import { findSelectedNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
2
4
|
export const insertHorizontalRule = editorAnalyticsAPI => inputMethod => (state, dispatch) => {
|
|
3
5
|
const tr = createHorizontalRule(state, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
|
|
4
6
|
if (tr) {
|
|
@@ -8,4 +10,26 @@ export const insertHorizontalRule = editorAnalyticsAPI => inputMethod => (state,
|
|
|
8
10
|
return true;
|
|
9
11
|
}
|
|
10
12
|
return false;
|
|
13
|
+
};
|
|
14
|
+
export const removeHorizontalRule = editorAnalyticsAPI => (state, dispatch) => {
|
|
15
|
+
const {
|
|
16
|
+
rule
|
|
17
|
+
} = state.schema.nodes;
|
|
18
|
+
if (!findSelectedNodeOfType(rule)(state.selection)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (dispatch) {
|
|
22
|
+
const deleteTr = removeSelectedNode(state.tr);
|
|
23
|
+
const payload = {
|
|
24
|
+
action: ACTION.DELETED,
|
|
25
|
+
actionSubject: ACTION_SUBJECT.DIVIDER,
|
|
26
|
+
attributes: {
|
|
27
|
+
inputMethod: INPUT_METHOD.FLOATING_TB
|
|
28
|
+
},
|
|
29
|
+
eventType: EVENT_TYPE.TRACK
|
|
30
|
+
};
|
|
31
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(payload)(deleteTr);
|
|
32
|
+
dispatch(deleteTr);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
11
35
|
};
|
|
@@ -47,7 +47,7 @@ const createHorizontalRuleAutoformat = (state, start, end, editorAnalyticsAPI) =
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
// eslint-disable-next-line require-unicode-regexp
|
|
50
|
-
const HORIZONTAL_RULE_AUTOFORMAT_REGEX = /^(
|
|
50
|
+
const HORIZONTAL_RULE_AUTOFORMAT_REGEX = /^(---|\*\*\*)$/;
|
|
51
51
|
export function inputRulePlugin(schema, editorAnalyticsAPI) {
|
|
52
52
|
const rules = [];
|
|
53
53
|
if (schema.nodes.rule) {
|
|
@@ -13,6 +13,7 @@ import inputRulePlugin from './pm-plugins/input-rule';
|
|
|
13
13
|
// eslint-disable-next-line import/no-named-as-default
|
|
14
14
|
import keymapPlugin from './pm-plugins/keymap';
|
|
15
15
|
import { getRuleQuickInsertComponents } from './ui/quick-insert/getRuleQuickInsertComponents';
|
|
16
|
+
import { getToolbarConfig } from './ui/toolbar';
|
|
16
17
|
export const rulePlugin = ({
|
|
17
18
|
api
|
|
18
19
|
}) => {
|
|
@@ -53,6 +54,9 @@ export const rulePlugin = ({
|
|
|
53
54
|
}];
|
|
54
55
|
},
|
|
55
56
|
pluginsOptions: {
|
|
57
|
+
...(isExperimentEnabled('platform_editor_lovability_dividers') ? {
|
|
58
|
+
floatingToolbar: (state, intl) => getToolbarConfig(state, intl, api)
|
|
59
|
+
} : {}),
|
|
56
60
|
quickInsert: isRegisteredSlashCommandEnabled ? undefined : ({
|
|
57
61
|
formatMessage
|
|
58
62
|
}) => [{
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
+
import commonMessages from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
|
|
6
|
+
import CopyIcon from '@atlaskit/icon/core/copy';
|
|
7
|
+
import DeleteIcon from '@atlaskit/icon/core/delete';
|
|
8
|
+
import { removeHorizontalRule } from '../pm-plugins/commands';
|
|
9
|
+
const getToolbarItems = (formatMessage, ruleNodeType, api) => {
|
|
10
|
+
var _api$decorations, _api$analytics;
|
|
11
|
+
const hoverDecoration = api === null || api === void 0 ? void 0 : (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions.hoverDecoration;
|
|
12
|
+
const hoverDecorationProps = className => ({
|
|
13
|
+
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
|
|
14
|
+
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, false, className),
|
|
15
|
+
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
|
|
16
|
+
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, false, className)
|
|
17
|
+
});
|
|
18
|
+
const items = [];
|
|
19
|
+
const overflowMenuItems = [{
|
|
20
|
+
type: 'overflow-dropdown',
|
|
21
|
+
options: [{
|
|
22
|
+
title: formatMessage(commonMessages.copyToClipboard),
|
|
23
|
+
icon: /*#__PURE__*/React.createElement(CopyIcon, {
|
|
24
|
+
label: ""
|
|
25
|
+
}),
|
|
26
|
+
onClick: () => {
|
|
27
|
+
var _api$core, _api$floatingToolbar;
|
|
28
|
+
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$floatingToolbar = api.floatingToolbar) === null || _api$floatingToolbar === void 0 ? void 0 : _api$floatingToolbar.commands.copyNode(ruleNodeType, INPUT_METHOD.FLOATING_TB));
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
...hoverDecorationProps(akEditorSelectedNodeClassName)
|
|
32
|
+
}, {
|
|
33
|
+
title: formatMessage(commonMessages.delete),
|
|
34
|
+
icon: /*#__PURE__*/React.createElement(DeleteIcon, {
|
|
35
|
+
label: ""
|
|
36
|
+
}),
|
|
37
|
+
onClick: removeHorizontalRule(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
|
|
38
|
+
...hoverDecorationProps()
|
|
39
|
+
}]
|
|
40
|
+
}];
|
|
41
|
+
items.push(...overflowMenuItems);
|
|
42
|
+
return items;
|
|
43
|
+
};
|
|
44
|
+
export const getToolbarConfig = (state, intl, api) => {
|
|
45
|
+
const {
|
|
46
|
+
formatMessage
|
|
47
|
+
} = intl;
|
|
48
|
+
const {
|
|
49
|
+
selection
|
|
50
|
+
} = state;
|
|
51
|
+
const {
|
|
52
|
+
rule
|
|
53
|
+
} = state.schema.nodes;
|
|
54
|
+
const isRuleSelection = findSelectedNodeOfType(state.schema.nodes.rule)(state.selection);
|
|
55
|
+
if (!isRuleSelection) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const getDomRef = editorView => {
|
|
59
|
+
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
60
|
+
const element = findDomRefAtPos(selection.from, domAtPos);
|
|
61
|
+
return element;
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
title: 'Divider floating controls',
|
|
65
|
+
getDomRef,
|
|
66
|
+
nodeType: [rule],
|
|
67
|
+
items: getToolbarItems(formatMessage, rule, api),
|
|
68
|
+
scrollable: true
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
1
2
|
import { createHorizontalRule } from './input-rule';
|
|
3
|
+
import { findSelectedNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
2
4
|
export var insertHorizontalRule = function insertHorizontalRule(editorAnalyticsAPI) {
|
|
3
5
|
return function (inputMethod) {
|
|
4
6
|
return function (state, dispatch) {
|
|
@@ -12,4 +14,26 @@ export var insertHorizontalRule = function insertHorizontalRule(editorAnalyticsA
|
|
|
12
14
|
return false;
|
|
13
15
|
};
|
|
14
16
|
};
|
|
17
|
+
};
|
|
18
|
+
export var removeHorizontalRule = function removeHorizontalRule(editorAnalyticsAPI) {
|
|
19
|
+
return function (state, dispatch) {
|
|
20
|
+
var rule = state.schema.nodes.rule;
|
|
21
|
+
if (!findSelectedNodeOfType(rule)(state.selection)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (dispatch) {
|
|
25
|
+
var deleteTr = removeSelectedNode(state.tr);
|
|
26
|
+
var payload = {
|
|
27
|
+
action: ACTION.DELETED,
|
|
28
|
+
actionSubject: ACTION_SUBJECT.DIVIDER,
|
|
29
|
+
attributes: {
|
|
30
|
+
inputMethod: INPUT_METHOD.FLOATING_TB
|
|
31
|
+
},
|
|
32
|
+
eventType: EVENT_TYPE.TRACK
|
|
33
|
+
};
|
|
34
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(deleteTr);
|
|
35
|
+
dispatch(deleteTr);
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
15
39
|
};
|
|
@@ -43,7 +43,7 @@ var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(sta
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
// eslint-disable-next-line require-unicode-regexp
|
|
46
|
-
var HORIZONTAL_RULE_AUTOFORMAT_REGEX = /^(
|
|
46
|
+
var HORIZONTAL_RULE_AUTOFORMAT_REGEX = /^(---|\*\*\*)$/;
|
|
47
47
|
export function inputRulePlugin(schema, editorAnalyticsAPI) {
|
|
48
48
|
var rules = [];
|
|
49
49
|
if (schema.nodes.rule) {
|
package/dist/esm/rulePlugin.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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
|
+
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; }
|
|
1
4
|
import React from 'react';
|
|
2
5
|
import { rule, ruleWithLocalId } from '@atlaskit/adf-schema/rule';
|
|
3
6
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
@@ -13,6 +16,7 @@ import inputRulePlugin from './pm-plugins/input-rule';
|
|
|
13
16
|
// eslint-disable-next-line import/no-named-as-default
|
|
14
17
|
import keymapPlugin from './pm-plugins/keymap';
|
|
15
18
|
import { getRuleQuickInsertComponents } from './ui/quick-insert/getRuleQuickInsertComponents';
|
|
19
|
+
import { getToolbarConfig } from './ui/toolbar';
|
|
16
20
|
export var rulePlugin = function rulePlugin(_ref) {
|
|
17
21
|
var _api$analytics;
|
|
18
22
|
var api = _ref.api;
|
|
@@ -50,7 +54,11 @@ export var rulePlugin = function rulePlugin(_ref) {
|
|
|
50
54
|
}
|
|
51
55
|
}];
|
|
52
56
|
},
|
|
53
|
-
pluginsOptions: {
|
|
57
|
+
pluginsOptions: _objectSpread(_objectSpread({}, isExperimentEnabled('platform_editor_lovability_dividers') ? {
|
|
58
|
+
floatingToolbar: function floatingToolbar(state, intl) {
|
|
59
|
+
return getToolbarConfig(state, intl, api);
|
|
60
|
+
}
|
|
61
|
+
} : {}), {}, {
|
|
54
62
|
quickInsert: isRegisteredSlashCommandEnabled ? undefined : function (_ref3) {
|
|
55
63
|
var formatMessage = _ref3.formatMessage;
|
|
56
64
|
return [{
|
|
@@ -79,6 +87,6 @@ export var rulePlugin = function rulePlugin(_ref) {
|
|
|
79
87
|
}
|
|
80
88
|
}];
|
|
81
89
|
}
|
|
82
|
-
}
|
|
90
|
+
})
|
|
83
91
|
};
|
|
84
92
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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
|
+
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
|
+
import React from 'react';
|
|
5
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
7
|
+
import commonMessages from '@atlaskit/editor-common/messages';
|
|
8
|
+
import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
|
|
9
|
+
import CopyIcon from '@atlaskit/icon/core/copy';
|
|
10
|
+
import DeleteIcon from '@atlaskit/icon/core/delete';
|
|
11
|
+
import { removeHorizontalRule } from '../pm-plugins/commands';
|
|
12
|
+
var getToolbarItems = function getToolbarItems(formatMessage, ruleNodeType, api) {
|
|
13
|
+
var _api$decorations, _api$analytics;
|
|
14
|
+
var hoverDecoration = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions.hoverDecoration;
|
|
15
|
+
var hoverDecorationProps = function hoverDecorationProps(className) {
|
|
16
|
+
return {
|
|
17
|
+
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
|
|
18
|
+
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, false, className),
|
|
19
|
+
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, true, className),
|
|
20
|
+
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(ruleNodeType, false, className)
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
var items = [];
|
|
24
|
+
var overflowMenuItems = [{
|
|
25
|
+
type: 'overflow-dropdown',
|
|
26
|
+
options: [_objectSpread({
|
|
27
|
+
title: formatMessage(commonMessages.copyToClipboard),
|
|
28
|
+
icon: /*#__PURE__*/React.createElement(CopyIcon, {
|
|
29
|
+
label: ""
|
|
30
|
+
}),
|
|
31
|
+
onClick: function onClick() {
|
|
32
|
+
var _api$core, _api$floatingToolbar;
|
|
33
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$floatingToolbar = api.floatingToolbar) === null || _api$floatingToolbar === void 0 ? void 0 : _api$floatingToolbar.commands.copyNode(ruleNodeType, INPUT_METHOD.FLOATING_TB));
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}, hoverDecorationProps(akEditorSelectedNodeClassName)), _objectSpread({
|
|
37
|
+
title: formatMessage(commonMessages.delete),
|
|
38
|
+
icon: /*#__PURE__*/React.createElement(DeleteIcon, {
|
|
39
|
+
label: ""
|
|
40
|
+
}),
|
|
41
|
+
onClick: removeHorizontalRule(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
|
|
42
|
+
}, hoverDecorationProps())]
|
|
43
|
+
}];
|
|
44
|
+
items.push.apply(items, overflowMenuItems);
|
|
45
|
+
return items;
|
|
46
|
+
};
|
|
47
|
+
export var getToolbarConfig = function getToolbarConfig(state, intl, api) {
|
|
48
|
+
var formatMessage = intl.formatMessage;
|
|
49
|
+
var selection = state.selection;
|
|
50
|
+
var rule = state.schema.nodes.rule;
|
|
51
|
+
var isRuleSelection = findSelectedNodeOfType(state.schema.nodes.rule)(state.selection);
|
|
52
|
+
if (!isRuleSelection) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
var getDomRef = function getDomRef(editorView) {
|
|
56
|
+
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
57
|
+
var element = findDomRefAtPos(selection.from, domAtPos);
|
|
58
|
+
return element;
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
title: 'Divider floating controls',
|
|
62
|
+
getDomRef: getDomRef,
|
|
63
|
+
nodeType: [rule],
|
|
64
|
+
items: getToolbarItems(formatMessage, rule, api),
|
|
65
|
+
scrollable: true
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
3
|
-
export declare const insertHorizontalRule: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Command;
|
|
4
|
+
export declare const insertHorizontalRule: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: INPUT_METHOD.ELEMENT_BROWSER | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Command;
|
|
5
|
+
export declare const removeHorizontalRule: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
@@ -3,6 +3,6 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
5
5
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
-
export declare const createHorizontalRule: (state: EditorState, start: number, end: number, inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Transaction | null;
|
|
6
|
+
export declare const createHorizontalRule: (state: EditorState, start: number, end: number, inputMethod: INPUT_METHOD.ELEMENT_BROWSER | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Transaction | null;
|
|
7
7
|
export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
|
|
8
8
|
export default inputRulePlugin;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
4
|
+
import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-toolbar';
|
|
3
5
|
import type { UiControlRegistryPlugin } from '@atlaskit/editor-plugin-ui-control-registry';
|
|
4
6
|
import type { insertHorizontalRule } from './pm-plugins/commands';
|
|
5
7
|
type RulePluginDependencies = [
|
|
6
8
|
OptionalPlugin<AnalyticsPlugin>,
|
|
7
|
-
OptionalPlugin<UiControlRegistryPlugin
|
|
9
|
+
OptionalPlugin<UiControlRegistryPlugin>,
|
|
10
|
+
OptionalPlugin<DecorationsPlugin>,
|
|
11
|
+
OptionalPlugin<FloatingToolbarPlugin>
|
|
8
12
|
];
|
|
9
13
|
export type RulePlugin = NextEditorPlugin<'rule', {
|
|
10
14
|
actions: {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IntlShape } from 'react-intl';
|
|
2
|
+
import type { ExtractInjectionAPI, FloatingToolbarConfig } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { RulePlugin } from '../rulePluginType';
|
|
5
|
+
export declare const getToolbarConfig: (state: EditorState, intl: IntlShape, api?: ExtractInjectionAPI<RulePlugin>) => FloatingToolbarConfig | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-rule",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.0",
|
|
4
4
|
"description": "Rule plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
"atlaskit:src": "src/index.ts",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@atlaskit/adf-schema": "^57.4.0",
|
|
23
|
-
"@atlaskit/editor-plugin-analytics": "^
|
|
24
|
-
"@atlaskit/editor-plugin-
|
|
23
|
+
"@atlaskit/editor-plugin-analytics": "^18.0.0",
|
|
24
|
+
"@atlaskit/editor-plugin-floating-toolbar": "^20.0.0",
|
|
25
|
+
"@atlaskit/editor-plugin-ui-control-registry": "^12.0.0",
|
|
25
26
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
27
|
+
"@atlaskit/editor-shared-styles": "^4.2.0",
|
|
26
28
|
"@atlaskit/icon": "^37.6.0",
|
|
27
29
|
"@atlaskit/platform-feature-experiments": "^0.3.0",
|
|
28
30
|
"@atlaskit/platform-feature-flags": "^2.2.0",
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
"react-intl": "^7.0.0"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^
|
|
36
|
+
"@atlaskit/editor-common": "^122.0.0",
|
|
35
37
|
"react": "^18.2.0 || ^19.2.0",
|
|
36
38
|
"react-dom": "^18.2.0 || ^19.2.0"
|
|
37
39
|
},
|