@atlaskit/editor-plugin-panel 0.1.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/.eslintrc.js +18 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +30 -0
- package/dist/cjs/actions.js +125 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/message.js +44 -0
- package/dist/cjs/nodeviews/panel.js +94 -0
- package/dist/cjs/plugin.js +215 -0
- package/dist/cjs/pm-plugins/keymaps.js +81 -0
- package/dist/cjs/pm-plugins/main.js +28 -0
- package/dist/cjs/toolbar.js +293 -0
- package/dist/cjs/types.js +8 -0
- package/dist/cjs/utils.js +53 -0
- package/dist/es2019/actions.js +116 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/message.js +38 -0
- package/dist/es2019/nodeviews/panel.js +82 -0
- package/dist/es2019/plugin.js +191 -0
- package/dist/es2019/pm-plugins/keymaps.js +82 -0
- package/dist/es2019/pm-plugins/main.js +21 -0
- package/dist/es2019/toolbar.js +279 -0
- package/dist/es2019/types.js +2 -0
- package/dist/es2019/utils.js +48 -0
- package/dist/esm/actions.js +116 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/message.js +38 -0
- package/dist/esm/nodeviews/panel.js +87 -0
- package/dist/esm/plugin.js +208 -0
- package/dist/esm/pm-plugins/keymaps.js +74 -0
- package/dist/esm/pm-plugins/main.js +22 -0
- package/dist/esm/toolbar.js +286 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils.js +46 -0
- package/dist/types/actions.d.ts +12 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/message.d.ts +37 -0
- package/dist/types/nodeviews/panel.d.ts +36 -0
- package/dist/types/plugin.d.ts +17 -0
- package/dist/types/pm-plugins/keymaps.d.ts +3 -0
- package/dist/types/pm-plugins/main.d.ts +11 -0
- package/dist/types/toolbar.d.ts +15 -0
- package/dist/types/types.d.ts +21 -0
- package/dist/types/utils.d.ts +5 -0
- package/dist/types-ts4.5/actions.d.ts +12 -0
- package/dist/types-ts4.5/index.d.ts +3 -0
- package/dist/types-ts4.5/message.d.ts +37 -0
- package/dist/types-ts4.5/nodeviews/panel.d.ts +36 -0
- package/dist/types-ts4.5/plugin.d.ts +17 -0
- package/dist/types-ts4.5/pm-plugins/keymaps.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +11 -0
- package/dist/types-ts4.5/toolbar.d.ts +15 -0
- package/dist/types-ts4.5/types.d.ts +21 -0
- package/dist/types-ts4.5/utils.d.ts +5 -0
- package/package.json +102 -0
- package/report.api.md +74 -0
- package/tmp/api-report-tmp.d.ts +44 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
4
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
5
|
+
'@typescript-eslint/ban-types': [
|
|
6
|
+
'error',
|
|
7
|
+
{
|
|
8
|
+
types: {
|
|
9
|
+
'React.FC':
|
|
10
|
+
'Please use types directly on props instead, and explicitly define children if required',
|
|
11
|
+
'React.FunctionalComponent':
|
|
12
|
+
'Please use types directly on props instead, and explicitly define children if required',
|
|
13
|
+
},
|
|
14
|
+
extendDefaults: false,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
};
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-panel
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Editor plugin panel
|
|
2
|
+
|
|
3
|
+
Panel plugin for @atlaskit/editor-core
|
|
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-panel*
|
|
11
|
+
- **npm** - [@atlaskit/editor-plugin-panel](https://www.npmjs.com/package/@atlaskit/editor-plugin-panel)
|
|
12
|
+
- **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-panel)
|
|
13
|
+
- **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-panel/dist/)
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
---
|
|
17
|
+
**Internal use only**
|
|
18
|
+
|
|
19
|
+
@atlaskit/editor-plugin-panel 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 panel](https://atlaskit.atlassian.com/packages/editor/editor-plugin-panel) 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://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#License) for more licensing information.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.changePanelType = void 0;
|
|
8
|
+
exports.insertPanelWithAnalytics = insertPanelWithAnalytics;
|
|
9
|
+
exports.removePanel = void 0;
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
12
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
|
+
var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
|
|
14
|
+
var _panel = require("@atlaskit/editor-common/panel");
|
|
15
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
16
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
17
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
18
|
+
var _utils3 = require("./utils");
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
var removePanel = exports.removePanel = function removePanel(editorAnalyticsAPI) {
|
|
22
|
+
return function (state, dispatch) {
|
|
23
|
+
var nodes = state.schema.nodes,
|
|
24
|
+
tr = state.tr;
|
|
25
|
+
var payload = {
|
|
26
|
+
action: _analytics.ACTION.DELETED,
|
|
27
|
+
actionSubject: _analytics.ACTION_SUBJECT.PANEL,
|
|
28
|
+
attributes: {
|
|
29
|
+
inputMethod: _analytics.INPUT_METHOD.TOOLBAR
|
|
30
|
+
},
|
|
31
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
32
|
+
};
|
|
33
|
+
var deleteTr = tr;
|
|
34
|
+
if ((0, _utils2.findSelectedNodeOfType)(nodes.panel)(tr.selection)) {
|
|
35
|
+
deleteTr = (0, _utils2.removeSelectedNode)(tr);
|
|
36
|
+
} else if ((0, _utils2.findParentNodeOfType)(nodes.panel)(tr.selection)) {
|
|
37
|
+
deleteTr = (0, _utils2.removeParentNodeOfType)(nodes.panel)(tr);
|
|
38
|
+
}
|
|
39
|
+
if (!deleteTr) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (dispatch) {
|
|
43
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(deleteTr);
|
|
44
|
+
dispatch(deleteTr);
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var changePanelType = exports.changePanelType = function changePanelType(editorAnalyticsAPI) {
|
|
50
|
+
return function (panelType) {
|
|
51
|
+
var panelOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
52
|
+
var allowCustomPanel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
53
|
+
return function (state, dispatch) {
|
|
54
|
+
var nodes = state.schema.nodes,
|
|
55
|
+
tr = state.tr;
|
|
56
|
+
var panelNode = (0, _utils3.findPanel)(state);
|
|
57
|
+
if (panelNode === undefined) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
var newType = panelType;
|
|
61
|
+
var previousType = panelNode.node.attrs.panelType;
|
|
62
|
+
var newTr;
|
|
63
|
+
if (allowCustomPanel) {
|
|
64
|
+
var previousColor = panelNode.node.attrs.panelType === 'custom' ? panelNode.node.attrs.panelColor || 'none' : (0, _panel.getPanelTypeBackgroundNoTokens)(previousType);
|
|
65
|
+
var previousIcon = panelNode.node.attrs.panelIcon;
|
|
66
|
+
var previousIconId = panelNode.node.attrs.panelIconId;
|
|
67
|
+
var previousIconText = panelNode.node.attrs.panelIconText;
|
|
68
|
+
var newPanelOptions = _objectSpread({
|
|
69
|
+
color: previousColor,
|
|
70
|
+
emoji: previousIcon,
|
|
71
|
+
emojiId: previousIconId,
|
|
72
|
+
emojiText: previousIconText
|
|
73
|
+
}, panelOptions);
|
|
74
|
+
newTr = tr.setNodeMarkup(panelNode.pos, nodes.panel, {
|
|
75
|
+
panelIcon: newPanelOptions.emoji,
|
|
76
|
+
panelIconId: newPanelOptions.emojiId,
|
|
77
|
+
panelIconText: newPanelOptions.emojiText,
|
|
78
|
+
panelColor: newPanelOptions.color,
|
|
79
|
+
panelType: panelType
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
newTr = tr.setNodeMarkup(panelNode.pos, nodes.panel, {
|
|
83
|
+
panelType: panelType
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
var payload = {
|
|
87
|
+
action: _analytics.ACTION.CHANGED_TYPE,
|
|
88
|
+
actionSubject: _analytics.ACTION_SUBJECT.PANEL,
|
|
89
|
+
attributes: {
|
|
90
|
+
newType: newType,
|
|
91
|
+
previousType: previousType
|
|
92
|
+
},
|
|
93
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Select the panel if it was previously selected
|
|
97
|
+
var newTrWithSelection = state.selection instanceof _state.NodeSelection && state.selection.node.type.name === 'panel' ? newTr.setSelection(new _state.NodeSelection(tr.doc.resolve(panelNode.pos))) : newTr;
|
|
98
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(newTrWithSelection);
|
|
99
|
+
newTrWithSelection.setMeta('scrollIntoView', false);
|
|
100
|
+
if (dispatch) {
|
|
101
|
+
dispatch(newTrWithSelection);
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
function insertPanelWithAnalytics(inputMethod, analyticsAPI) {
|
|
108
|
+
return (0, _editorAnalytics.withAnalytics)(analyticsAPI, {
|
|
109
|
+
action: _analytics.ACTION.INSERTED,
|
|
110
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
111
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
|
|
112
|
+
attributes: {
|
|
113
|
+
inputMethod: inputMethod,
|
|
114
|
+
panelType: _adfSchema.PanelType.INFO // only info panels can be inserted via this action
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
118
|
+
})(function (state, dispatch) {
|
|
119
|
+
var nodes = state.schema.nodes;
|
|
120
|
+
if (nodes.panel && nodes.paragraph) {
|
|
121
|
+
return (0, _utils.wrapSelectionIn)(nodes.panel)(state, dispatch);
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "panelPlugin", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _plugin.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.messages = void 0;
|
|
7
|
+
var _reactIntlNext = require("react-intl-next");
|
|
8
|
+
var messages = exports.messages = (0, _reactIntlNext.defineMessages)({
|
|
9
|
+
info: {
|
|
10
|
+
id: 'fabric.editor.info',
|
|
11
|
+
defaultMessage: 'Info',
|
|
12
|
+
description: 'Panels provide a way to highlight text. The info panel has a blue background.'
|
|
13
|
+
},
|
|
14
|
+
note: {
|
|
15
|
+
id: 'fabric.editor.note',
|
|
16
|
+
defaultMessage: 'Note',
|
|
17
|
+
description: 'Panels provide a way to highlight text. The note panel has a purple background.'
|
|
18
|
+
},
|
|
19
|
+
success: {
|
|
20
|
+
id: 'fabric.editor.success',
|
|
21
|
+
defaultMessage: 'Success',
|
|
22
|
+
description: 'Panels provide a way to highlight text. The success panel has a green background.'
|
|
23
|
+
},
|
|
24
|
+
warning: {
|
|
25
|
+
id: 'fabric.editor.warning',
|
|
26
|
+
defaultMessage: 'Warning',
|
|
27
|
+
description: 'Panels provide a way to highlight text. The warning panel has a yellow background.'
|
|
28
|
+
},
|
|
29
|
+
error: {
|
|
30
|
+
id: 'fabric.editor.error',
|
|
31
|
+
defaultMessage: 'Error',
|
|
32
|
+
description: 'Panels provide a way to highlight text. The error panel has a red background.'
|
|
33
|
+
},
|
|
34
|
+
emoji: {
|
|
35
|
+
id: 'fabric.editor.panel.emoji',
|
|
36
|
+
defaultMessage: 'Add emoji',
|
|
37
|
+
description: 'Select the panel icon'
|
|
38
|
+
},
|
|
39
|
+
backgroundColor: {
|
|
40
|
+
id: 'fabric.editor.panel.backgroundColor',
|
|
41
|
+
defaultMessage: 'Background color',
|
|
42
|
+
description: 'Select the panel background color.'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.panelIcons = exports.getPanelNodeView = exports.PanelIcon = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
12
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
13
|
+
var _emoji = require("@atlaskit/editor-common/emoji");
|
|
14
|
+
var _icons = require("@atlaskit/editor-common/icons");
|
|
15
|
+
var _panel = require("@atlaskit/editor-common/panel");
|
|
16
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
17
|
+
var _consts = require("@atlaskit/editor-shared-styles/consts");
|
|
18
|
+
var _hint = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/hint"));
|
|
19
|
+
var _utils = require("../utils");
|
|
20
|
+
var panelIcons = exports.panelIcons = {
|
|
21
|
+
info: _icons.PanelInfoIcon,
|
|
22
|
+
success: _icons.PanelSuccessIcon,
|
|
23
|
+
note: _icons.PanelNoteIcon,
|
|
24
|
+
tip: _hint.default,
|
|
25
|
+
warning: _icons.PanelWarningIcon,
|
|
26
|
+
error: _icons.PanelErrorIcon,
|
|
27
|
+
custom: _icons.PanelInfoIcon
|
|
28
|
+
};
|
|
29
|
+
var PanelIcon = exports.PanelIcon = function PanelIcon(props) {
|
|
30
|
+
var allowCustomPanel = props.allowCustomPanel,
|
|
31
|
+
providerFactory = props.providerFactory,
|
|
32
|
+
_props$panelAttribute = props.panelAttributes,
|
|
33
|
+
panelType = _props$panelAttribute.panelType,
|
|
34
|
+
panelIcon = _props$panelAttribute.panelIcon,
|
|
35
|
+
panelIconId = _props$panelAttribute.panelIconId,
|
|
36
|
+
panelIconText = _props$panelAttribute.panelIconText;
|
|
37
|
+
if (allowCustomPanel && panelIcon && panelType === _adfSchema.PanelType.CUSTOM) {
|
|
38
|
+
return /*#__PURE__*/_react.default.createElement(_emoji.Emoji, {
|
|
39
|
+
providers: providerFactory,
|
|
40
|
+
shortName: panelIcon,
|
|
41
|
+
id: panelIconId,
|
|
42
|
+
fallback: panelIconText,
|
|
43
|
+
showTooltip: false,
|
|
44
|
+
allowTextFallback: false,
|
|
45
|
+
fitToHeight: _consts.akEditorCustomIconSize
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
var Icon = panelIcons[panelType];
|
|
49
|
+
return /*#__PURE__*/_react.default.createElement(Icon, {
|
|
50
|
+
label: "Panel ".concat(panelType)
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
var PanelNodeView = /*#__PURE__*/function () {
|
|
54
|
+
function PanelNodeView(node, view, getPos, pluginOptions, providerFactory) {
|
|
55
|
+
(0, _classCallCheck2.default)(this, PanelNodeView);
|
|
56
|
+
this.providerFactory = providerFactory;
|
|
57
|
+
this.pluginOptions = pluginOptions;
|
|
58
|
+
this.view = view;
|
|
59
|
+
this.node = node;
|
|
60
|
+
var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, (0, _utils.panelAttrsToDom)(node.attrs, pluginOptions.allowCustomPanel || false)),
|
|
61
|
+
dom = _DOMSerializer$render.dom,
|
|
62
|
+
contentDOM = _DOMSerializer$render.contentDOM;
|
|
63
|
+
this.getPos = getPos;
|
|
64
|
+
this.dom = dom;
|
|
65
|
+
this.contentDOM = contentDOM;
|
|
66
|
+
this.icon = this.dom.querySelector(".".concat(_panel.PanelSharedCssClassName.icon));
|
|
67
|
+
if (!this.icon) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// set contentEditable as false to be able to select the custom panels with keyboard
|
|
71
|
+
this.icon.contentEditable = 'false';
|
|
72
|
+
_reactDom.default.render( /*#__PURE__*/_react.default.createElement(PanelIcon, {
|
|
73
|
+
allowCustomPanel: pluginOptions.allowCustomPanel,
|
|
74
|
+
panelAttributes: node.attrs,
|
|
75
|
+
providerFactory: this.providerFactory
|
|
76
|
+
}), this.icon);
|
|
77
|
+
}
|
|
78
|
+
(0, _createClass2.default)(PanelNodeView, [{
|
|
79
|
+
key: "ignoreMutation",
|
|
80
|
+
value: function ignoreMutation(mutation) {
|
|
81
|
+
// ignore mutation if it caused by the icon.
|
|
82
|
+
var isIcon = mutation.target === this.icon || mutation.target.parentNode === this.icon;
|
|
83
|
+
// ignore mutation if it caused by the lazy load emoji inside icon.
|
|
84
|
+
var isInsideIcon = this.icon.contains(mutation.target);
|
|
85
|
+
return isIcon || isInsideIcon;
|
|
86
|
+
}
|
|
87
|
+
}]);
|
|
88
|
+
return PanelNodeView;
|
|
89
|
+
}();
|
|
90
|
+
var getPanelNodeView = exports.getPanelNodeView = function getPanelNodeView(pluginOptions, providerFactory) {
|
|
91
|
+
return function (node, view, getPos) {
|
|
92
|
+
return new PanelNodeView(node, view, getPos, pluginOptions, providerFactory);
|
|
93
|
+
};
|
|
94
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
12
|
+
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
13
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
14
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
15
|
+
var _actions = require("./actions");
|
|
16
|
+
var _keymaps = _interopRequireDefault(require("./pm-plugins/keymaps"));
|
|
17
|
+
var _main = require("./pm-plugins/main");
|
|
18
|
+
var _toolbar = require("./toolbar");
|
|
19
|
+
var panelPlugin = function panelPlugin(_ref) {
|
|
20
|
+
var _ref$config = _ref.config,
|
|
21
|
+
options = _ref$config === void 0 ? {} : _ref$config,
|
|
22
|
+
api = _ref.api;
|
|
23
|
+
return {
|
|
24
|
+
name: 'panel',
|
|
25
|
+
nodes: function nodes() {
|
|
26
|
+
var panelNode = (0, _adfSchema.panel)(!!options.allowCustomPanel);
|
|
27
|
+
return [{
|
|
28
|
+
name: 'panel',
|
|
29
|
+
node: panelNode
|
|
30
|
+
}];
|
|
31
|
+
},
|
|
32
|
+
pmPlugins: function pmPlugins() {
|
|
33
|
+
return [{
|
|
34
|
+
name: 'panel',
|
|
35
|
+
plugin: function plugin(_ref2) {
|
|
36
|
+
var providerFactory = _ref2.providerFactory,
|
|
37
|
+
dispatch = _ref2.dispatch;
|
|
38
|
+
return (0, _main.createPlugin)(dispatch, providerFactory, options);
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
name: 'panelKeyMap',
|
|
42
|
+
plugin: function plugin() {
|
|
43
|
+
return (0, _keymaps.default)();
|
|
44
|
+
}
|
|
45
|
+
}];
|
|
46
|
+
},
|
|
47
|
+
actions: {
|
|
48
|
+
insertPanel: function insertPanel(inputMethod) {
|
|
49
|
+
var _api$analytics;
|
|
50
|
+
return (0, _actions.insertPanelWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
pluginsOptions: {
|
|
54
|
+
quickInsert: function quickInsert(_ref3) {
|
|
55
|
+
var formatMessage = _ref3.formatMessage;
|
|
56
|
+
var quickInsertOptions = [{
|
|
57
|
+
id: 'infopanel',
|
|
58
|
+
title: formatMessage(_messages.blockTypeMessages.infoPanel),
|
|
59
|
+
keywords: ['panel'],
|
|
60
|
+
description: formatMessage(_messages.blockTypeMessages.infoPanelDescription),
|
|
61
|
+
priority: 800,
|
|
62
|
+
icon: function icon() {
|
|
63
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanel, null);
|
|
64
|
+
},
|
|
65
|
+
action: function action(insert, state) {
|
|
66
|
+
return createPanelAction({
|
|
67
|
+
state: state,
|
|
68
|
+
attributes: {
|
|
69
|
+
panelType: _adfSchema.PanelType.INFO
|
|
70
|
+
},
|
|
71
|
+
api: api
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
id: 'notepanel',
|
|
76
|
+
title: formatMessage(_messages.blockTypeMessages.notePanel),
|
|
77
|
+
description: formatMessage(_messages.blockTypeMessages.notePanelDescription),
|
|
78
|
+
priority: 1000,
|
|
79
|
+
icon: function icon() {
|
|
80
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelNote, null);
|
|
81
|
+
},
|
|
82
|
+
action: function action(insert, state) {
|
|
83
|
+
return createPanelAction({
|
|
84
|
+
state: state,
|
|
85
|
+
attributes: {
|
|
86
|
+
panelType: _adfSchema.PanelType.NOTE
|
|
87
|
+
},
|
|
88
|
+
api: api
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
id: 'successpanel',
|
|
93
|
+
title: formatMessage(_messages.blockTypeMessages.successPanel),
|
|
94
|
+
description: formatMessage(_messages.blockTypeMessages.successPanelDescription),
|
|
95
|
+
keywords: ['tip'],
|
|
96
|
+
priority: 1000,
|
|
97
|
+
icon: function icon() {
|
|
98
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelSuccess, null);
|
|
99
|
+
},
|
|
100
|
+
action: function action(insert, state) {
|
|
101
|
+
return createPanelAction({
|
|
102
|
+
state: state,
|
|
103
|
+
attributes: {
|
|
104
|
+
panelType: _adfSchema.PanelType.SUCCESS
|
|
105
|
+
},
|
|
106
|
+
api: api
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
id: 'warningpanel',
|
|
111
|
+
title: formatMessage(_messages.blockTypeMessages.warningPanel),
|
|
112
|
+
description: formatMessage(_messages.blockTypeMessages.warningPanelDescription),
|
|
113
|
+
priority: 1000,
|
|
114
|
+
icon: function icon() {
|
|
115
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelWarning, null);
|
|
116
|
+
},
|
|
117
|
+
action: function action(insert, state) {
|
|
118
|
+
return createPanelAction({
|
|
119
|
+
state: state,
|
|
120
|
+
attributes: {
|
|
121
|
+
panelType: _adfSchema.PanelType.WARNING
|
|
122
|
+
},
|
|
123
|
+
api: api
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
id: 'errorpanel',
|
|
128
|
+
title: formatMessage(_messages.blockTypeMessages.errorPanel),
|
|
129
|
+
description: formatMessage(_messages.blockTypeMessages.errorPanelDescription),
|
|
130
|
+
priority: 1000,
|
|
131
|
+
icon: function icon() {
|
|
132
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconPanelError, null);
|
|
133
|
+
},
|
|
134
|
+
action: function action(insert, state) {
|
|
135
|
+
return createPanelAction({
|
|
136
|
+
state: state,
|
|
137
|
+
attributes: {
|
|
138
|
+
panelType: _adfSchema.PanelType.ERROR
|
|
139
|
+
},
|
|
140
|
+
api: api
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}];
|
|
144
|
+
if (options.allowCustomPanel && options.allowCustomPanelEdit) {
|
|
145
|
+
quickInsertOptions.push({
|
|
146
|
+
id: 'custompanel',
|
|
147
|
+
title: formatMessage(_messages.blockTypeMessages.customPanel),
|
|
148
|
+
description: formatMessage(_messages.blockTypeMessages.customPanelDescription),
|
|
149
|
+
priority: 1000,
|
|
150
|
+
icon: function icon() {
|
|
151
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconCustomPanel, null);
|
|
152
|
+
},
|
|
153
|
+
action: function action(insert, state) {
|
|
154
|
+
return createPanelAction({
|
|
155
|
+
state: state,
|
|
156
|
+
attributes: {
|
|
157
|
+
panelType: _adfSchema.PanelType.CUSTOM,
|
|
158
|
+
panelIcon: ':rainbow:',
|
|
159
|
+
panelIconId: '1f308',
|
|
160
|
+
panelIconText: '🌈',
|
|
161
|
+
// TODO: https://product-fabric.atlassian.net/browse/DSP-7268
|
|
162
|
+
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
163
|
+
panelColor: _colors.T50
|
|
164
|
+
},
|
|
165
|
+
api: api
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return quickInsertOptions;
|
|
171
|
+
},
|
|
172
|
+
floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
|
|
173
|
+
return (0, _toolbar.getToolbarConfig)(state, intl, options, providerFactory, api);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Creates panel action and wrap selection transaction with analytics for the panel insertion.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* const tr = createPanelAction({
|
|
184
|
+
* state: editorState,
|
|
185
|
+
* attributes: { panelType: 'info' },
|
|
186
|
+
* });
|
|
187
|
+
* if (tr) {
|
|
188
|
+
* applyTransaction(tr);
|
|
189
|
+
* }
|
|
190
|
+
*/
|
|
191
|
+
function createPanelAction(_ref4) {
|
|
192
|
+
var state = _ref4.state,
|
|
193
|
+
attributes = _ref4.attributes,
|
|
194
|
+
api = _ref4.api;
|
|
195
|
+
var tr = (0, _utils.createWrapSelectionTransaction)({
|
|
196
|
+
state: state,
|
|
197
|
+
type: state.schema.nodes.panel,
|
|
198
|
+
nodeAttributes: attributes
|
|
199
|
+
});
|
|
200
|
+
if (tr) {
|
|
201
|
+
var _api$analytics2;
|
|
202
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
|
|
203
|
+
action: _analytics.ACTION.INSERTED,
|
|
204
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
205
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PANEL,
|
|
206
|
+
attributes: {
|
|
207
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT,
|
|
208
|
+
panelType: attributes.panelType
|
|
209
|
+
},
|
|
210
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
211
|
+
})(tr);
|
|
212
|
+
}
|
|
213
|
+
return tr;
|
|
214
|
+
}
|
|
215
|
+
var _default = exports.default = panelPlugin;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.keymapPlugin = keymapPlugin;
|
|
8
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
|
+
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
10
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
11
|
+
function findParentNode(selection, nodeType) {
|
|
12
|
+
var parentPosition = (0, _utils2.findParentNodeOfType)(nodeType)(selection);
|
|
13
|
+
if (parentPosition) {
|
|
14
|
+
return parentPosition.node;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function isInsideAnEmptyNode(selection, nodeType, schema) {
|
|
19
|
+
var parentNode = findParentNode(selection, nodeType);
|
|
20
|
+
return parentNode && (0, _utils.isEmptyNode)(schema)(parentNode);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Somewhat broken and subverted: https://product-fabric.atlassian.net/browse/ED-6504
|
|
24
|
+
function keymapPlugin() {
|
|
25
|
+
var deleteCurrentItem = function deleteCurrentItem($from, tr) {
|
|
26
|
+
return tr.delete($from.before($from.depth) - 1, $from.end($from.depth) + 1);
|
|
27
|
+
};
|
|
28
|
+
var keymaps = {
|
|
29
|
+
Backspace: function Backspace(state, dispatch) {
|
|
30
|
+
var _nodeBeforePanel$type;
|
|
31
|
+
var selection = state.selection,
|
|
32
|
+
nodes = state.schema.nodes,
|
|
33
|
+
tr = state.tr;
|
|
34
|
+
var panel = nodes.panel,
|
|
35
|
+
blockquote = nodes.blockquote;
|
|
36
|
+
var $from = selection.$from,
|
|
37
|
+
$to = selection.$to;
|
|
38
|
+
// Don't do anything if selection is a range
|
|
39
|
+
if ($from.pos !== $to.pos) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// If not at the start of a panel, no joining will happen so allow default behaviour (backspacing characters etc..)
|
|
44
|
+
if ($from.parentOffset !== 0) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
var $previousPos = tr.doc.resolve(Math.max(0, $from.before($from.depth) - 1));
|
|
48
|
+
var previousNodeType = $previousPos.pos > 0 && $previousPos.parent && $previousPos.parent.type;
|
|
49
|
+
var parentNodeType = $from.parent.type;
|
|
50
|
+
var isPreviousNodeAPanel = previousNodeType === panel;
|
|
51
|
+
var isParentNodeAPanel = parentNodeType === panel;
|
|
52
|
+
var nodeBeforePanel = $previousPos === null || $previousPos === void 0 ? void 0 : $previousPos.nodeBefore;
|
|
53
|
+
|
|
54
|
+
// Stops merging panels when deleting empty paragraph in between
|
|
55
|
+
// Stops merging blockquotes with panels when deleting from start of blockquote
|
|
56
|
+
|
|
57
|
+
if (isPreviousNodeAPanel && !isParentNodeAPanel || isInsideAnEmptyNode(selection, panel, state.schema) || (0, _utils2.hasParentNodeOfType)(blockquote)(selection) ||
|
|
58
|
+
// Lift line of panel content up and out of the panel, when backspacing
|
|
59
|
+
// at the start of a panel, if the node before the panel is an 'isolating' node
|
|
60
|
+
// (for e.g. a table, or an expand), otherwise the default prosemirror backspace
|
|
61
|
+
// behaviour will fallback to 'select node backward' logic because the node
|
|
62
|
+
// before is an isolating node.
|
|
63
|
+
nodeBeforePanel !== null && nodeBeforePanel !== void 0 && (_nodeBeforePanel$type = nodeBeforePanel.type) !== null && _nodeBeforePanel$type !== void 0 && (_nodeBeforePanel$type = _nodeBeforePanel$type.spec) !== null && _nodeBeforePanel$type !== void 0 && _nodeBeforePanel$type.isolating && (0, _utils2.hasParentNodeOfType)(panel)(selection)) {
|
|
64
|
+
var content = $from.node($from.depth).content;
|
|
65
|
+
var insertPos = $previousPos.pos;
|
|
66
|
+
deleteCurrentItem($from, tr).insert(insertPos, content);
|
|
67
|
+
if (dispatch) {
|
|
68
|
+
dispatch((0, _utils2.setTextSelection)(insertPos)(tr).scrollIntoView());
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
var nodeType = $from.node().type;
|
|
73
|
+
if (nodeType !== panel) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return (0, _keymap.keymap)(keymaps);
|
|
80
|
+
}
|
|
81
|
+
var _default = exports.default = keymapPlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createPlugin = void 0;
|
|
7
|
+
var _panel = require("@atlaskit/editor-common/panel");
|
|
8
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
10
|
+
var _panel2 = require("../nodeviews/panel");
|
|
11
|
+
var _types = require("../types");
|
|
12
|
+
var createPlugin = exports.createPlugin = function createPlugin(dispatch, providerFactory, pluginOptions) {
|
|
13
|
+
var _pluginOptions$useLon = pluginOptions.useLongPressSelection,
|
|
14
|
+
useLongPressSelection = _pluginOptions$useLon === void 0 ? false : _pluginOptions$useLon;
|
|
15
|
+
return new _safePlugin.SafePlugin({
|
|
16
|
+
key: _types.pluginKey,
|
|
17
|
+
props: {
|
|
18
|
+
nodeViews: {
|
|
19
|
+
panel: (0, _panel2.getPanelNodeView)(pluginOptions, providerFactory)
|
|
20
|
+
},
|
|
21
|
+
handleClickOn: (0, _selection.createSelectionClickHandler)(['panel'], function (target) {
|
|
22
|
+
return !!target.closest(".".concat(_panel.PanelSharedCssClassName.prefix));
|
|
23
|
+
}, {
|
|
24
|
+
useLongPressSelection: useLongPressSelection
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
};
|