@atlaskit/editor-plugin-selection-extension 1.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 +1 -0
- package/LICENSE.md +11 -0
- package/README.md +30 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/selectionExtensionPlugin.js +100 -0
- package/dist/cjs/selectionExtensionPluginType.js +5 -0
- package/dist/cjs/ui/toolbar/SelectionExtensionDropdownMenu.js +40 -0
- package/dist/cjs/ui/toolbar/SelectionExtensionDropdownMenuButton.js +20 -0
- package/dist/cjs/ui/toolbar/SelectionExtensionItems.js +61 -0
- package/dist/es2019/index.js +4 -0
- package/dist/es2019/selectionExtensionPlugin.js +100 -0
- package/dist/es2019/selectionExtensionPluginType.js +1 -0
- package/dist/es2019/ui/toolbar/SelectionExtensionDropdownMenu.js +25 -0
- package/dist/es2019/ui/toolbar/SelectionExtensionDropdownMenuButton.js +14 -0
- package/dist/es2019/ui/toolbar/SelectionExtensionItems.js +45 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/selectionExtensionPlugin.js +93 -0
- package/dist/esm/selectionExtensionPluginType.js +1 -0
- package/dist/esm/ui/toolbar/SelectionExtensionDropdownMenu.js +30 -0
- package/dist/esm/ui/toolbar/SelectionExtensionDropdownMenuButton.js +13 -0
- package/dist/esm/ui/toolbar/SelectionExtensionItems.js +53 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/selectionExtensionPlugin.d.ts +2 -0
- package/dist/types/selectionExtensionPluginType.d.ts +33 -0
- package/dist/types/ui/toolbar/SelectionExtensionDropdownMenu.d.ts +26 -0
- package/dist/types/ui/toolbar/SelectionExtensionDropdownMenuButton.d.ts +8 -0
- package/dist/types/ui/toolbar/SelectionExtensionItems.d.ts +22 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/selectionExtensionPlugin.d.ts +2 -0
- package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +33 -0
- package/dist/types-ts4.5/ui/toolbar/SelectionExtensionDropdownMenu.d.ts +26 -0
- package/dist/types-ts4.5/ui/toolbar/SelectionExtensionDropdownMenuButton.d.ts +8 -0
- package/dist/types-ts4.5/ui/toolbar/SelectionExtensionItems.d.ts +22 -0
- package/package.json +101 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-selection-extension
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2023 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
|
4
|
+
compliance with the License. You may obtain a copy of the License at
|
|
5
|
+
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
|
9
|
+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
10
|
+
implied. See the License for the specific language governing permissions and limitations under the
|
|
11
|
+
License.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Editor plugin selection extension
|
|
2
|
+
|
|
3
|
+
Selection Extension plugin for confluence
|
|
4
|
+
|
|
5
|
+
**Note:** This component is designed for internal Atlassian development.
|
|
6
|
+
External contributors will be able to use this component but will not be able to submit issues.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
---
|
|
10
|
+
- **Install** - *yarn add @atlaskit/editor-plugin-selection-extension*
|
|
11
|
+
- **npm** - [@atlaskit/editor-plugin-selection-extension](https://www.npmjs.com/package/@atlaskit/editor-plugin-selection-extension)
|
|
12
|
+
- **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-selection-extension)
|
|
13
|
+
- **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-selection-extension/dist/)
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
---
|
|
17
|
+
**Internal use only**
|
|
18
|
+
|
|
19
|
+
@atlaskit/editor-plugin-selection-extension is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
|
|
20
|
+
|
|
21
|
+
Direct use of this component is not supported.
|
|
22
|
+
|
|
23
|
+
Please see [Atlaskit - Editor plugin analytics](https://atlaskit.atlassian.com/packages/editor/editor-plugin-selection-extension) for documentation and examples for this package.
|
|
24
|
+
|
|
25
|
+
## Support
|
|
26
|
+
---
|
|
27
|
+
For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
|
|
28
|
+
## License
|
|
29
|
+
---
|
|
30
|
+
Please see [Atlassian Frontend - License](https://developer.atlassian.com/cloud/framework/atlassian-frontend/#license) for more licensing information.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "selectionExtensionPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _selectionExtensionPlugin.selectionExtensionPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _selectionExtensionPlugin = require("./selectionExtensionPlugin");
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.selectionExtensionPlugin = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _SelectionExtensionItems = require("./ui/toolbar/SelectionExtensionItems");
|
|
10
|
+
var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
11
|
+
var api = _ref.api,
|
|
12
|
+
config = _ref.config;
|
|
13
|
+
return {
|
|
14
|
+
name: 'selectionExtension',
|
|
15
|
+
pluginsOptions: {
|
|
16
|
+
selectionToolbar: function selectionToolbar(state) {
|
|
17
|
+
var _api$editorViewMode;
|
|
18
|
+
if (!config) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var pageModes = config.pageModes,
|
|
22
|
+
extensions = config.extensions;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Extensions Config Validation
|
|
26
|
+
*
|
|
27
|
+
* Check whether plugin contains any selection extensions
|
|
28
|
+
*/
|
|
29
|
+
if (!extensions || extensions.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Content Mode Validation
|
|
35
|
+
*
|
|
36
|
+
* Check if pageModes is provided and matches against current content mode
|
|
37
|
+
*
|
|
38
|
+
* TODO: This will eventially transition from mode to contentMode
|
|
39
|
+
*/
|
|
40
|
+
var editorContentMode = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode;
|
|
41
|
+
if (pageModes) {
|
|
42
|
+
// Early Exit: consumer has set pageModes but editorContentMode is undefined
|
|
43
|
+
if (!editorContentMode) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Simplify traversion of pageModes which can be string or array of strings
|
|
48
|
+
var showOnModesCollection = Array.isArray(pageModes) ? pageModes : [pageModes];
|
|
49
|
+
|
|
50
|
+
// Early Exit: consumer has set pageModes but current editorContentMode is not in the collection
|
|
51
|
+
if (!showOnModesCollection.includes(editorContentMode)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
var handleOnExtensionClick = function handleOnExtensionClick(extension) {
|
|
56
|
+
var selection = state.selection;
|
|
57
|
+
var from = selection.from,
|
|
58
|
+
to = selection.to;
|
|
59
|
+
var text = state.doc.textBetween(from, to, '\n');
|
|
60
|
+
|
|
61
|
+
// TODO: Probably some validator logic here
|
|
62
|
+
extension.onClick({
|
|
63
|
+
text: text,
|
|
64
|
+
selection: {
|
|
65
|
+
from: from,
|
|
66
|
+
to: to
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Renders custom dropdown menu with active selection extensions
|
|
73
|
+
*/
|
|
74
|
+
var selectionExtensionDropdown = {
|
|
75
|
+
type: 'custom',
|
|
76
|
+
supportsViewMode: true,
|
|
77
|
+
render: function render(view) {
|
|
78
|
+
var _api$analytics;
|
|
79
|
+
if (!view) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionItems.SelectionExtensionItems, {
|
|
83
|
+
api: api,
|
|
84
|
+
editorView: view,
|
|
85
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
|
|
86
|
+
extensions: extensions,
|
|
87
|
+
onExtensionClick: handleOnExtensionClick
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
fallback: []
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
isToolbarAbove: true,
|
|
94
|
+
items: [selectionExtensionDropdown],
|
|
95
|
+
rank: -6
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.SelectionExtensionDropdownMenu = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _reactIntlNext = require("react-intl-next");
|
|
12
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
13
|
+
var _SelectionExtensionDropdownMenuButton = require("./SelectionExtensionDropdownMenuButton");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
var SelectionExtensionDropdownMenuComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
17
|
+
var items = _ref.items,
|
|
18
|
+
onItemActivated = _ref.onItemActivated;
|
|
19
|
+
var _useState = (0, _react.useState)(false),
|
|
20
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
21
|
+
isMenuOpen = _useState2[0],
|
|
22
|
+
setIsMenuOpen = _useState2[1];
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement(_uiMenu.DropdownMenuWithKeyboardNavigation, {
|
|
24
|
+
section: {
|
|
25
|
+
hasSeparator: true
|
|
26
|
+
},
|
|
27
|
+
isOpen: isMenuOpen,
|
|
28
|
+
items: items,
|
|
29
|
+
fitHeight: 188,
|
|
30
|
+
fitWidth: 136,
|
|
31
|
+
onItemActivated: onItemActivated,
|
|
32
|
+
"data-testid": "selection-extension-dropdown-menu"
|
|
33
|
+
}, /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownMenuButton.SelectionExtensionDropdownMenuButton, {
|
|
34
|
+
"data-testid": "selection-extension-dropdown-button",
|
|
35
|
+
onClick: function onClick() {
|
|
36
|
+
return setIsMenuOpen(!isMenuOpen);
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
40
|
+
var SelectionExtensionDropdownMenu = exports.SelectionExtensionDropdownMenu = (0, _reactIntlNext.injectIntl)(SelectionExtensionDropdownMenuComponent);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SelectionExtensionDropdownMenuButton = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactIntlNext = require("react-intl-next");
|
|
10
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
11
|
+
var _apps = _interopRequireDefault(require("@atlaskit/icon/core/apps"));
|
|
12
|
+
var SelectionExtensionDropdownMenuButtonComponent = function SelectionExtensionDropdownMenuButtonComponent(_ref) {
|
|
13
|
+
var onClick = _ref.onClick;
|
|
14
|
+
return /*#__PURE__*/_react.default.createElement(_uiMenu.ToolbarButton, {
|
|
15
|
+
onClick: onClick
|
|
16
|
+
}, /*#__PURE__*/_react.default.createElement(_apps.default, {
|
|
17
|
+
label: "selection extension dropdown"
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
var SelectionExtensionDropdownMenuButton = exports.SelectionExtensionDropdownMenuButton = (0, _reactIntlNext.injectIntl)(SelectionExtensionDropdownMenuButtonComponent);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.SelectionExtensionItemsComponent = exports.SelectionExtensionItems = void 0;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _reactIntlNext = require("react-intl-next");
|
|
12
|
+
var _uuid = require("uuid");
|
|
13
|
+
var _SelectionExtensionDropdownMenu = require("./SelectionExtensionDropdownMenu");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
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; }
|
|
17
|
+
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; } /**
|
|
18
|
+
* @jsxRuntime classic
|
|
19
|
+
* @jsx
|
|
20
|
+
*/
|
|
21
|
+
var transformExtensionsToItems = function transformExtensionsToItems(extensions) {
|
|
22
|
+
var extensionToItems = extensions.map(function (extension) {
|
|
23
|
+
return {
|
|
24
|
+
content: extension.name,
|
|
25
|
+
value: {
|
|
26
|
+
name: extension.id
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
return [{
|
|
31
|
+
items: extensionToItems
|
|
32
|
+
}];
|
|
33
|
+
};
|
|
34
|
+
var SelectionExtensionItemsComponent = exports.SelectionExtensionItemsComponent = function SelectionExtensionItemsComponent(_ref) {
|
|
35
|
+
var extensions = _ref.extensions,
|
|
36
|
+
onExtensionClick = _ref.onExtensionClick;
|
|
37
|
+
var extensionsWithIdentifier = (0, _react.useMemo)(function () {
|
|
38
|
+
return extensions.map(function (extension) {
|
|
39
|
+
return _objectSpread(_objectSpread({}, extension), {}, {
|
|
40
|
+
id: (0, _uuid.v4)()
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}, [extensions]);
|
|
44
|
+
var items = (0, _react.useMemo)(function () {
|
|
45
|
+
return transformExtensionsToItems(extensionsWithIdentifier);
|
|
46
|
+
}, [extensionsWithIdentifier]);
|
|
47
|
+
var handleOnItemActivated = function handleOnItemActivated(_ref2) {
|
|
48
|
+
var item = _ref2.item;
|
|
49
|
+
var extension = extensionsWithIdentifier.find(function (ext) {
|
|
50
|
+
return ext.id === item.value.name;
|
|
51
|
+
});
|
|
52
|
+
if (extension) {
|
|
53
|
+
onExtensionClick(extension);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return /*#__PURE__*/_react.default.createElement(_SelectionExtensionDropdownMenu.SelectionExtensionDropdownMenu, {
|
|
57
|
+
items: items,
|
|
58
|
+
onItemActivated: handleOnItemActivated
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
var SelectionExtensionItems = exports.SelectionExtensionItems = (0, _reactIntlNext.injectIntl)(SelectionExtensionItemsComponent);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SelectionExtensionItems } from './ui/toolbar/SelectionExtensionItems';
|
|
3
|
+
export const selectionExtensionPlugin = ({
|
|
4
|
+
api,
|
|
5
|
+
config
|
|
6
|
+
}) => {
|
|
7
|
+
return {
|
|
8
|
+
name: 'selectionExtension',
|
|
9
|
+
pluginsOptions: {
|
|
10
|
+
selectionToolbar: state => {
|
|
11
|
+
var _api$editorViewMode, _api$editorViewMode$s;
|
|
12
|
+
if (!config) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const {
|
|
16
|
+
pageModes,
|
|
17
|
+
extensions
|
|
18
|
+
} = config;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Extensions Config Validation
|
|
22
|
+
*
|
|
23
|
+
* Check whether plugin contains any selection extensions
|
|
24
|
+
*/
|
|
25
|
+
if (!extensions || extensions.length === 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Content Mode Validation
|
|
31
|
+
*
|
|
32
|
+
* Check if pageModes is provided and matches against current content mode
|
|
33
|
+
*
|
|
34
|
+
* TODO: This will eventially transition from mode to contentMode
|
|
35
|
+
*/
|
|
36
|
+
const editorContentMode = api === null || api === void 0 ? void 0 : (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : (_api$editorViewMode$s = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode$s === void 0 ? void 0 : _api$editorViewMode$s.mode;
|
|
37
|
+
if (pageModes) {
|
|
38
|
+
// Early Exit: consumer has set pageModes but editorContentMode is undefined
|
|
39
|
+
if (!editorContentMode) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Simplify traversion of pageModes which can be string or array of strings
|
|
44
|
+
const showOnModesCollection = Array.isArray(pageModes) ? pageModes : [pageModes];
|
|
45
|
+
|
|
46
|
+
// Early Exit: consumer has set pageModes but current editorContentMode is not in the collection
|
|
47
|
+
if (!showOnModesCollection.includes(editorContentMode)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const handleOnExtensionClick = extension => {
|
|
52
|
+
const {
|
|
53
|
+
selection
|
|
54
|
+
} = state;
|
|
55
|
+
const {
|
|
56
|
+
from,
|
|
57
|
+
to
|
|
58
|
+
} = selection;
|
|
59
|
+
const text = state.doc.textBetween(from, to, '\n');
|
|
60
|
+
|
|
61
|
+
// TODO: Probably some validator logic here
|
|
62
|
+
extension.onClick({
|
|
63
|
+
text,
|
|
64
|
+
selection: {
|
|
65
|
+
from,
|
|
66
|
+
to
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Renders custom dropdown menu with active selection extensions
|
|
73
|
+
*/
|
|
74
|
+
const selectionExtensionDropdown = {
|
|
75
|
+
type: 'custom',
|
|
76
|
+
supportsViewMode: true,
|
|
77
|
+
render: view => {
|
|
78
|
+
var _api$analytics;
|
|
79
|
+
if (!view) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return /*#__PURE__*/React.createElement(SelectionExtensionItems, {
|
|
83
|
+
api: api,
|
|
84
|
+
editorView: view,
|
|
85
|
+
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
|
|
86
|
+
extensions: extensions,
|
|
87
|
+
onExtensionClick: handleOnExtensionClick
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
fallback: []
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
isToolbarAbove: true,
|
|
94
|
+
items: [selectionExtensionDropdown],
|
|
95
|
+
rank: -6
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { injectIntl } from 'react-intl-next';
|
|
3
|
+
import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
import { SelectionExtensionDropdownMenuButton } from './SelectionExtensionDropdownMenuButton';
|
|
5
|
+
const SelectionExtensionDropdownMenuComponent = /*#__PURE__*/React.memo(({
|
|
6
|
+
items,
|
|
7
|
+
onItemActivated
|
|
8
|
+
}) => {
|
|
9
|
+
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
10
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
11
|
+
section: {
|
|
12
|
+
hasSeparator: true
|
|
13
|
+
},
|
|
14
|
+
isOpen: isMenuOpen,
|
|
15
|
+
items: items,
|
|
16
|
+
fitHeight: 188,
|
|
17
|
+
fitWidth: 136,
|
|
18
|
+
onItemActivated: onItemActivated,
|
|
19
|
+
"data-testid": "selection-extension-dropdown-menu"
|
|
20
|
+
}, /*#__PURE__*/React.createElement(SelectionExtensionDropdownMenuButton, {
|
|
21
|
+
"data-testid": "selection-extension-dropdown-button",
|
|
22
|
+
onClick: () => setIsMenuOpen(!isMenuOpen)
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
export const SelectionExtensionDropdownMenu = injectIntl(SelectionExtensionDropdownMenuComponent);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { injectIntl } from 'react-intl-next';
|
|
3
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
import AppsIcon from '@atlaskit/icon/core/apps';
|
|
5
|
+
const SelectionExtensionDropdownMenuButtonComponent = ({
|
|
6
|
+
onClick
|
|
7
|
+
}) => {
|
|
8
|
+
return /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
9
|
+
onClick: onClick
|
|
10
|
+
}, /*#__PURE__*/React.createElement(AppsIcon, {
|
|
11
|
+
label: "selection extension dropdown"
|
|
12
|
+
}));
|
|
13
|
+
};
|
|
14
|
+
export const SelectionExtensionDropdownMenuButton = injectIntl(SelectionExtensionDropdownMenuButtonComponent);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
|
+
import { injectIntl } from 'react-intl-next';
|
|
8
|
+
import { v4 as uuid } from 'uuid';
|
|
9
|
+
import { SelectionExtensionDropdownMenu } from './SelectionExtensionDropdownMenu';
|
|
10
|
+
const transformExtensionsToItems = extensions => {
|
|
11
|
+
const extensionToItems = extensions.map(extension => {
|
|
12
|
+
return {
|
|
13
|
+
content: extension.name,
|
|
14
|
+
value: {
|
|
15
|
+
name: extension.id
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
return [{
|
|
20
|
+
items: extensionToItems
|
|
21
|
+
}];
|
|
22
|
+
};
|
|
23
|
+
export const SelectionExtensionItemsComponent = ({
|
|
24
|
+
extensions,
|
|
25
|
+
onExtensionClick
|
|
26
|
+
}) => {
|
|
27
|
+
const extensionsWithIdentifier = useMemo(() => extensions.map(extension => ({
|
|
28
|
+
...extension,
|
|
29
|
+
id: uuid()
|
|
30
|
+
})), [extensions]);
|
|
31
|
+
const items = useMemo(() => transformExtensionsToItems(extensionsWithIdentifier), [extensionsWithIdentifier]);
|
|
32
|
+
const handleOnItemActivated = ({
|
|
33
|
+
item
|
|
34
|
+
}) => {
|
|
35
|
+
const extension = extensionsWithIdentifier.find(ext => ext.id === item.value.name);
|
|
36
|
+
if (extension) {
|
|
37
|
+
onExtensionClick(extension);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return /*#__PURE__*/React.createElement(SelectionExtensionDropdownMenu, {
|
|
41
|
+
items: items,
|
|
42
|
+
onItemActivated: handleOnItemActivated
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export const SelectionExtensionItems = injectIntl(SelectionExtensionItemsComponent);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SelectionExtensionItems } from './ui/toolbar/SelectionExtensionItems';
|
|
3
|
+
export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
|
|
4
|
+
var api = _ref.api,
|
|
5
|
+
config = _ref.config;
|
|
6
|
+
return {
|
|
7
|
+
name: 'selectionExtension',
|
|
8
|
+
pluginsOptions: {
|
|
9
|
+
selectionToolbar: function selectionToolbar(state) {
|
|
10
|
+
var _api$editorViewMode;
|
|
11
|
+
if (!config) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
var pageModes = config.pageModes,
|
|
15
|
+
extensions = config.extensions;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extensions Config Validation
|
|
19
|
+
*
|
|
20
|
+
* Check whether plugin contains any selection extensions
|
|
21
|
+
*/
|
|
22
|
+
if (!extensions || extensions.length === 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Content Mode Validation
|
|
28
|
+
*
|
|
29
|
+
* Check if pageModes is provided and matches against current content mode
|
|
30
|
+
*
|
|
31
|
+
* TODO: This will eventially transition from mode to contentMode
|
|
32
|
+
*/
|
|
33
|
+
var editorContentMode = api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode;
|
|
34
|
+
if (pageModes) {
|
|
35
|
+
// Early Exit: consumer has set pageModes but editorContentMode is undefined
|
|
36
|
+
if (!editorContentMode) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Simplify traversion of pageModes which can be string or array of strings
|
|
41
|
+
var showOnModesCollection = Array.isArray(pageModes) ? pageModes : [pageModes];
|
|
42
|
+
|
|
43
|
+
// Early Exit: consumer has set pageModes but current editorContentMode is not in the collection
|
|
44
|
+
if (!showOnModesCollection.includes(editorContentMode)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var handleOnExtensionClick = function handleOnExtensionClick(extension) {
|
|
49
|
+
var selection = state.selection;
|
|
50
|
+
var from = selection.from,
|
|
51
|
+
to = selection.to;
|
|
52
|
+
var text = state.doc.textBetween(from, to, '\n');
|
|
53
|
+
|
|
54
|
+
// TODO: Probably some validator logic here
|
|
55
|
+
extension.onClick({
|
|
56
|
+
text: text,
|
|
57
|
+
selection: {
|
|
58
|
+
from: from,
|
|
59
|
+
to: to
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Renders custom dropdown menu with active selection extensions
|
|
66
|
+
*/
|
|
67
|
+
var selectionExtensionDropdown = {
|
|
68
|
+
type: 'custom',
|
|
69
|
+
supportsViewMode: true,
|
|
70
|
+
render: function render(view) {
|
|
71
|
+
var _api$analytics;
|
|
72
|
+
if (!view) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return /*#__PURE__*/React.createElement(SelectionExtensionItems, {
|
|
76
|
+
api: api,
|
|
77
|
+
editorView: view,
|
|
78
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
|
|
79
|
+
extensions: extensions,
|
|
80
|
+
onExtensionClick: handleOnExtensionClick
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
fallback: []
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
isToolbarAbove: true,
|
|
87
|
+
items: [selectionExtensionDropdown],
|
|
88
|
+
rank: -6
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { injectIntl } from 'react-intl-next';
|
|
4
|
+
import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/editor-common/ui-menu';
|
|
5
|
+
import { SelectionExtensionDropdownMenuButton } from './SelectionExtensionDropdownMenuButton';
|
|
6
|
+
var SelectionExtensionDropdownMenuComponent = /*#__PURE__*/React.memo(function (_ref) {
|
|
7
|
+
var items = _ref.items,
|
|
8
|
+
onItemActivated = _ref.onItemActivated;
|
|
9
|
+
var _useState = useState(false),
|
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
+
isMenuOpen = _useState2[0],
|
|
12
|
+
setIsMenuOpen = _useState2[1];
|
|
13
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
14
|
+
section: {
|
|
15
|
+
hasSeparator: true
|
|
16
|
+
},
|
|
17
|
+
isOpen: isMenuOpen,
|
|
18
|
+
items: items,
|
|
19
|
+
fitHeight: 188,
|
|
20
|
+
fitWidth: 136,
|
|
21
|
+
onItemActivated: onItemActivated,
|
|
22
|
+
"data-testid": "selection-extension-dropdown-menu"
|
|
23
|
+
}, /*#__PURE__*/React.createElement(SelectionExtensionDropdownMenuButton, {
|
|
24
|
+
"data-testid": "selection-extension-dropdown-button",
|
|
25
|
+
onClick: function onClick() {
|
|
26
|
+
return setIsMenuOpen(!isMenuOpen);
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
30
|
+
export var SelectionExtensionDropdownMenu = injectIntl(SelectionExtensionDropdownMenuComponent);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { injectIntl } from 'react-intl-next';
|
|
3
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
import AppsIcon from '@atlaskit/icon/core/apps';
|
|
5
|
+
var SelectionExtensionDropdownMenuButtonComponent = function SelectionExtensionDropdownMenuButtonComponent(_ref) {
|
|
6
|
+
var onClick = _ref.onClick;
|
|
7
|
+
return /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
8
|
+
onClick: onClick
|
|
9
|
+
}, /*#__PURE__*/React.createElement(AppsIcon, {
|
|
10
|
+
label: "selection extension dropdown"
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
export var SelectionExtensionDropdownMenuButton = injectIntl(SelectionExtensionDropdownMenuButtonComponent);
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* @jsxRuntime classic
|
|
6
|
+
* @jsx
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React, { useMemo } from 'react';
|
|
10
|
+
import { injectIntl } from 'react-intl-next';
|
|
11
|
+
import { v4 as uuid } from 'uuid';
|
|
12
|
+
import { SelectionExtensionDropdownMenu } from './SelectionExtensionDropdownMenu';
|
|
13
|
+
var transformExtensionsToItems = function transformExtensionsToItems(extensions) {
|
|
14
|
+
var extensionToItems = extensions.map(function (extension) {
|
|
15
|
+
return {
|
|
16
|
+
content: extension.name,
|
|
17
|
+
value: {
|
|
18
|
+
name: extension.id
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
return [{
|
|
23
|
+
items: extensionToItems
|
|
24
|
+
}];
|
|
25
|
+
};
|
|
26
|
+
export var SelectionExtensionItemsComponent = function SelectionExtensionItemsComponent(_ref) {
|
|
27
|
+
var extensions = _ref.extensions,
|
|
28
|
+
onExtensionClick = _ref.onExtensionClick;
|
|
29
|
+
var extensionsWithIdentifier = useMemo(function () {
|
|
30
|
+
return extensions.map(function (extension) {
|
|
31
|
+
return _objectSpread(_objectSpread({}, extension), {}, {
|
|
32
|
+
id: uuid()
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}, [extensions]);
|
|
36
|
+
var items = useMemo(function () {
|
|
37
|
+
return transformExtensionsToItems(extensionsWithIdentifier);
|
|
38
|
+
}, [extensionsWithIdentifier]);
|
|
39
|
+
var handleOnItemActivated = function handleOnItemActivated(_ref2) {
|
|
40
|
+
var item = _ref2.item;
|
|
41
|
+
var extension = extensionsWithIdentifier.find(function (ext) {
|
|
42
|
+
return ext.id === item.value.name;
|
|
43
|
+
});
|
|
44
|
+
if (extension) {
|
|
45
|
+
onExtensionClick(extension);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return /*#__PURE__*/React.createElement(SelectionExtensionDropdownMenu, {
|
|
49
|
+
items: items,
|
|
50
|
+
onItemActivated: handleOnItemActivated
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
export var SelectionExtensionItems = injectIntl(SelectionExtensionItemsComponent);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
3
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
+
import type { ContentMode, EditorViewModePlugin, ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
|
+
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
6
|
+
export type MenuItemsType = Array<{
|
|
7
|
+
items: MenuItem[];
|
|
8
|
+
}>;
|
|
9
|
+
export type SelectionExtensionContract = {
|
|
10
|
+
name: string;
|
|
11
|
+
onClick: (params: {
|
|
12
|
+
text: string;
|
|
13
|
+
selection: {
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
};
|
|
17
|
+
}) => void;
|
|
18
|
+
validator?: (value: unknown) => boolean;
|
|
19
|
+
};
|
|
20
|
+
type SelectionExtensionModes = ViewMode | ContentMode;
|
|
21
|
+
type SelectionExtensionPluginConfiguration = {
|
|
22
|
+
pageModes?: SelectionExtensionModes | SelectionExtensionModes[];
|
|
23
|
+
extensions?: SelectionExtensionContract[];
|
|
24
|
+
};
|
|
25
|
+
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
26
|
+
pluginConfiguration: SelectionExtensionPluginConfiguration | undefined;
|
|
27
|
+
dependencies: [
|
|
28
|
+
OptionalPlugin<AnalyticsPlugin>,
|
|
29
|
+
OptionalPlugin<EditorViewModePlugin>,
|
|
30
|
+
SelectionToolbarPlugin
|
|
31
|
+
];
|
|
32
|
+
}>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import { type MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
import { type MenuItemsType } from '../../selectionExtensionPluginType';
|
|
5
|
+
export type SelectionExtensionDropdownMenuProps = {
|
|
6
|
+
items: MenuItemsType;
|
|
7
|
+
onItemActivated?: (attrs: {
|
|
8
|
+
item: MenuItem;
|
|
9
|
+
shouldCloseMenu?: boolean;
|
|
10
|
+
}) => void;
|
|
11
|
+
} & WrappedComponentProps;
|
|
12
|
+
export declare const SelectionExtensionDropdownMenu: React.FC<import("react-intl-next").WithIntlProps<{
|
|
13
|
+
items: MenuItemsType;
|
|
14
|
+
onItemActivated?: ((attrs: {
|
|
15
|
+
item: MenuItem;
|
|
16
|
+
shouldCloseMenu?: boolean;
|
|
17
|
+
}) => void) | undefined;
|
|
18
|
+
} & WrappedComponentProps>> & {
|
|
19
|
+
WrappedComponent: React.ComponentType<{
|
|
20
|
+
items: MenuItemsType;
|
|
21
|
+
onItemActivated?: ((attrs: {
|
|
22
|
+
item: MenuItem;
|
|
23
|
+
shouldCloseMenu?: boolean;
|
|
24
|
+
}) => void) | undefined;
|
|
25
|
+
} & WrappedComponentProps>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
type SelectionExtensionDropdownMenuButtonProps = React.ComponentProps<typeof ToolbarButton> & WrappedComponentProps;
|
|
5
|
+
export declare const SelectionExtensionDropdownMenuButton: React.FC<import("react-intl-next").WithIntlProps<SelectionExtensionDropdownMenuButtonProps>> & {
|
|
6
|
+
WrappedComponent: React.ComponentType<SelectionExtensionDropdownMenuButtonProps>;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
7
|
+
import { type EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
8
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
9
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
10
|
+
import type { SelectionExtensionPlugin, SelectionExtensionContract } from '../../selectionExtensionPluginType';
|
|
11
|
+
type SelectionExtensionItemsProps = {
|
|
12
|
+
editorView: EditorView;
|
|
13
|
+
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
14
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
15
|
+
extensions: SelectionExtensionContract[];
|
|
16
|
+
onExtensionClick: (extension: SelectionExtensionContract) => void;
|
|
17
|
+
} & WrappedComponentProps;
|
|
18
|
+
export declare const SelectionExtensionItemsComponent: ({ extensions, onExtensionClick, }: SelectionExtensionItemsProps) => React.JSX.Element;
|
|
19
|
+
export declare const SelectionExtensionItems: React.FC<import("react-intl-next").WithIntlProps<SelectionExtensionItemsProps>> & {
|
|
20
|
+
WrappedComponent: React.ComponentType<SelectionExtensionItemsProps>;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
3
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
+
import type { ContentMode, EditorViewModePlugin, ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
|
+
import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
|
|
6
|
+
export type MenuItemsType = Array<{
|
|
7
|
+
items: MenuItem[];
|
|
8
|
+
}>;
|
|
9
|
+
export type SelectionExtensionContract = {
|
|
10
|
+
name: string;
|
|
11
|
+
onClick: (params: {
|
|
12
|
+
text: string;
|
|
13
|
+
selection: {
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
};
|
|
17
|
+
}) => void;
|
|
18
|
+
validator?: (value: unknown) => boolean;
|
|
19
|
+
};
|
|
20
|
+
type SelectionExtensionModes = ViewMode | ContentMode;
|
|
21
|
+
type SelectionExtensionPluginConfiguration = {
|
|
22
|
+
pageModes?: SelectionExtensionModes | SelectionExtensionModes[];
|
|
23
|
+
extensions?: SelectionExtensionContract[];
|
|
24
|
+
};
|
|
25
|
+
export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
|
|
26
|
+
pluginConfiguration: SelectionExtensionPluginConfiguration | undefined;
|
|
27
|
+
dependencies: [
|
|
28
|
+
OptionalPlugin<AnalyticsPlugin>,
|
|
29
|
+
OptionalPlugin<EditorViewModePlugin>,
|
|
30
|
+
SelectionToolbarPlugin
|
|
31
|
+
];
|
|
32
|
+
}>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import { type MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
import { type MenuItemsType } from '../../selectionExtensionPluginType';
|
|
5
|
+
export type SelectionExtensionDropdownMenuProps = {
|
|
6
|
+
items: MenuItemsType;
|
|
7
|
+
onItemActivated?: (attrs: {
|
|
8
|
+
item: MenuItem;
|
|
9
|
+
shouldCloseMenu?: boolean;
|
|
10
|
+
}) => void;
|
|
11
|
+
} & WrappedComponentProps;
|
|
12
|
+
export declare const SelectionExtensionDropdownMenu: React.FC<import("react-intl-next").WithIntlProps<{
|
|
13
|
+
items: MenuItemsType;
|
|
14
|
+
onItemActivated?: ((attrs: {
|
|
15
|
+
item: MenuItem;
|
|
16
|
+
shouldCloseMenu?: boolean;
|
|
17
|
+
}) => void) | undefined;
|
|
18
|
+
} & WrappedComponentProps>> & {
|
|
19
|
+
WrappedComponent: React.ComponentType<{
|
|
20
|
+
items: MenuItemsType;
|
|
21
|
+
onItemActivated?: ((attrs: {
|
|
22
|
+
item: MenuItem;
|
|
23
|
+
shouldCloseMenu?: boolean;
|
|
24
|
+
}) => void) | undefined;
|
|
25
|
+
} & WrappedComponentProps>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
4
|
+
type SelectionExtensionDropdownMenuButtonProps = React.ComponentProps<typeof ToolbarButton> & WrappedComponentProps;
|
|
5
|
+
export declare const SelectionExtensionDropdownMenuButton: React.FC<import("react-intl-next").WithIntlProps<SelectionExtensionDropdownMenuButtonProps>> & {
|
|
6
|
+
WrappedComponent: React.ComponentType<SelectionExtensionDropdownMenuButtonProps>;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
7
|
+
import { type EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
8
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
9
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
10
|
+
import type { SelectionExtensionPlugin, SelectionExtensionContract } from '../../selectionExtensionPluginType';
|
|
11
|
+
type SelectionExtensionItemsProps = {
|
|
12
|
+
editorView: EditorView;
|
|
13
|
+
api: ExtractInjectionAPI<SelectionExtensionPlugin> | undefined;
|
|
14
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
15
|
+
extensions: SelectionExtensionContract[];
|
|
16
|
+
onExtensionClick: (extension: SelectionExtensionContract) => void;
|
|
17
|
+
} & WrappedComponentProps;
|
|
18
|
+
export declare const SelectionExtensionItemsComponent: ({ extensions, onExtensionClick, }: SelectionExtensionItemsProps) => React.JSX.Element;
|
|
19
|
+
export declare const SelectionExtensionItems: React.FC<import("react-intl-next").WithIntlProps<SelectionExtensionItemsProps>> & {
|
|
20
|
+
WrappedComponent: React.ComponentType<SelectionExtensionItemsProps>;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-selection-extension",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
|
|
5
|
+
"author": "Atlassian Pty Ltd",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org/"
|
|
9
|
+
},
|
|
10
|
+
"atlassian": {
|
|
11
|
+
"team": "Editor: Core Experiences",
|
|
12
|
+
"runReact18": true,
|
|
13
|
+
"website": {
|
|
14
|
+
"name": "EditorPluginSelectionExtension",
|
|
15
|
+
"category": "Layout and structure"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend-monorepo",
|
|
19
|
+
"main": "dist/cjs/index.js",
|
|
20
|
+
"module": "dist/esm/index.js",
|
|
21
|
+
"module:es2019": "dist/es2019/index.js",
|
|
22
|
+
"types": "dist/types/index.d.ts",
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
">=4.5 <5.4": {
|
|
25
|
+
"*": [
|
|
26
|
+
"dist/types-ts4.5/*",
|
|
27
|
+
"dist/types-ts4.5/index.d.ts"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"*.compiled.css"
|
|
33
|
+
],
|
|
34
|
+
"atlaskit:src": "src/index.ts",
|
|
35
|
+
"af:exports": {
|
|
36
|
+
".": "./src/index.ts"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@atlaskit/editor-common": "^99.9.0",
|
|
40
|
+
"@atlaskit/editor-plugin-analytics": "^1.10.2",
|
|
41
|
+
"@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
|
|
42
|
+
"@atlaskit/editor-plugin-selection-toolbar": "^1.6.1",
|
|
43
|
+
"@atlaskit/editor-prosemirror": "6.2.1",
|
|
44
|
+
"@atlaskit/icon": "^23.4.0",
|
|
45
|
+
"@atlaskit/primitives": "^13.3.0",
|
|
46
|
+
"@babel/runtime": "^7.0.0",
|
|
47
|
+
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
48
|
+
"uuid": "^3.1.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": "^16.8.0 || ^17.0.0 || ~18.2.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@af/integration-testing": "*",
|
|
55
|
+
"@af/visual-regression": "*",
|
|
56
|
+
"@atlaskit/ssr": "*",
|
|
57
|
+
"@atlaskit/visual-regression": "*",
|
|
58
|
+
"@testing-library/react": "^13.4.0",
|
|
59
|
+
"react-dom": "^18.2.0",
|
|
60
|
+
"typescript": "~5.4.2",
|
|
61
|
+
"wait-for-expect": "^1.2.0"
|
|
62
|
+
},
|
|
63
|
+
"techstack": {
|
|
64
|
+
"@atlassian/frontend": {
|
|
65
|
+
"code-structure": [
|
|
66
|
+
"editor-plugin"
|
|
67
|
+
],
|
|
68
|
+
"import-structure": [
|
|
69
|
+
"atlassian-conventions"
|
|
70
|
+
],
|
|
71
|
+
"circular-dependencies": [
|
|
72
|
+
"file-and-folder-level"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"@repo/internal": {
|
|
76
|
+
"dom-events": "use-bind-event-listener",
|
|
77
|
+
"analytics": [
|
|
78
|
+
"analytics-next"
|
|
79
|
+
],
|
|
80
|
+
"design-tokens": [
|
|
81
|
+
"color"
|
|
82
|
+
],
|
|
83
|
+
"theming": [
|
|
84
|
+
"react-context"
|
|
85
|
+
],
|
|
86
|
+
"ui-components": [
|
|
87
|
+
"lite-mode"
|
|
88
|
+
],
|
|
89
|
+
"deprecation": [
|
|
90
|
+
"no-deprecated-imports"
|
|
91
|
+
],
|
|
92
|
+
"styling": [
|
|
93
|
+
"static",
|
|
94
|
+
"compiled"
|
|
95
|
+
],
|
|
96
|
+
"imports": [
|
|
97
|
+
"import-no-extraneous-disable-for-examples-and-docs"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|