@atlaskit/editor-plugin-decorations 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/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +7 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin.js +36 -0
- package/dist/cjs/pm-plugin.js +125 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin.js +22 -0
- package/dist/es2019/pm-plugin.js +114 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.js +26 -0
- package/dist/esm/pm-plugin.js +114 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugin.d.ts +9 -0
- package/dist/types/pm-plugin.d.ts +19 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/plugin.d.ts +9 -0
- package/dist/types-ts4.5/pm-plugin.d.ts +19 -0
- package/package.json +81 -0
- package/report.api.md +68 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-decorations
|
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,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "decorationsPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _plugin.decorationsPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _plugin = require("./plugin");
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.decorationsPlugin = void 0;
|
|
8
|
+
var _pmPlugin = _interopRequireWildcard(require("./pm-plugin"));
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
|
+
var decorationsPlugin = function decorationsPlugin() {
|
|
12
|
+
return {
|
|
13
|
+
name: 'decorations',
|
|
14
|
+
pmPlugins: function pmPlugins() {
|
|
15
|
+
return [{
|
|
16
|
+
name: 'decorationPlugin',
|
|
17
|
+
plugin: function plugin() {
|
|
18
|
+
return (0, _pmPlugin.default)();
|
|
19
|
+
}
|
|
20
|
+
}];
|
|
21
|
+
},
|
|
22
|
+
actions: {
|
|
23
|
+
hoverDecoration: _pmPlugin.hoverDecoration,
|
|
24
|
+
removeDecoration: _pmPlugin.removeDecoration
|
|
25
|
+
},
|
|
26
|
+
getSharedState: function getSharedState(editorState) {
|
|
27
|
+
if (!editorState) {
|
|
28
|
+
return {
|
|
29
|
+
decoration: undefined
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return _pmPlugin.decorationStateKey.getState(editorState);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.decorationsPlugin = decorationsPlugin;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeDecoration = exports.hoverDecoration = exports.default = exports.decorationStateKey = exports.ACTIONS = void 0;
|
|
7
|
+
var _prosemirrorState = require("prosemirror-state");
|
|
8
|
+
var _prosemirrorUtils = require("prosemirror-utils");
|
|
9
|
+
var _prosemirrorView = require("prosemirror-view");
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
+
var decorationStateKey = new _prosemirrorState.PluginKey('decorationPlugin');
|
|
12
|
+
exports.decorationStateKey = decorationStateKey;
|
|
13
|
+
var ACTIONS = /*#__PURE__*/function (ACTIONS) {
|
|
14
|
+
ACTIONS[ACTIONS["DECORATION_ADD"] = 0] = "DECORATION_ADD";
|
|
15
|
+
ACTIONS[ACTIONS["DECORATION_REMOVE"] = 1] = "DECORATION_REMOVE";
|
|
16
|
+
return ACTIONS;
|
|
17
|
+
}({});
|
|
18
|
+
exports.ACTIONS = ACTIONS;
|
|
19
|
+
var removeDecoration = function removeDecoration(state, dispatch) {
|
|
20
|
+
var tr = state.tr;
|
|
21
|
+
if (dispatch) {
|
|
22
|
+
dispatch(tr.setMeta(decorationStateKey, {
|
|
23
|
+
action: ACTIONS.DECORATION_REMOVE
|
|
24
|
+
}));
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
exports.removeDecoration = removeDecoration;
|
|
30
|
+
var hoverDecoration = function hoverDecoration(nodeType, add) {
|
|
31
|
+
var className = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'danger';
|
|
32
|
+
return function (state, dispatch) {
|
|
33
|
+
var from;
|
|
34
|
+
var parentNode;
|
|
35
|
+
if (state.selection instanceof _prosemirrorState.NodeSelection) {
|
|
36
|
+
var selectedNode = state.selection.node;
|
|
37
|
+
var nodeTypes = Array.isArray(nodeType) ? nodeType : [nodeType];
|
|
38
|
+
var isNodeTypeMatching = nodeTypes.indexOf(selectedNode.type) > -1;
|
|
39
|
+
// This adds danger styling if the selected node is the one that requires
|
|
40
|
+
// the decoration to be added, e.g. if a layout is selected and the user
|
|
41
|
+
// hovers over the layout's delete button.
|
|
42
|
+
if (isNodeTypeMatching) {
|
|
43
|
+
from = state.selection.from;
|
|
44
|
+
parentNode = selectedNode;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// This adds danger styling if the selection is not a node selection, OR if
|
|
49
|
+
// the selected node is a child of the one that requires the decoration to
|
|
50
|
+
// be added, e.g. if a decision item is selected inside a layout and the
|
|
51
|
+
// user hovers over the layout's delete button.
|
|
52
|
+
var foundParentNode = (0, _prosemirrorUtils.findParentNodeOfType)(nodeType)(state.selection);
|
|
53
|
+
if (from === undefined && foundParentNode) {
|
|
54
|
+
from = foundParentNode.pos;
|
|
55
|
+
parentNode = foundParentNode.node;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Note: can't use !from as from could be 0, which is falsy but valid
|
|
59
|
+
if (from === undefined || parentNode === undefined) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (dispatch) {
|
|
63
|
+
dispatch(state.tr.setMeta(decorationStateKey, {
|
|
64
|
+
action: add ? ACTIONS.DECORATION_ADD : ACTIONS.DECORATION_REMOVE,
|
|
65
|
+
data: _prosemirrorView.Decoration.node(from, from + parentNode.nodeSize, {
|
|
66
|
+
class: className
|
|
67
|
+
}, {
|
|
68
|
+
key: 'decorationNode'
|
|
69
|
+
})
|
|
70
|
+
}).setMeta('addToHistory', false));
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exports.hoverDecoration = hoverDecoration;
|
|
76
|
+
var _default = function _default() {
|
|
77
|
+
return new _safePlugin.SafePlugin({
|
|
78
|
+
key: decorationStateKey,
|
|
79
|
+
state: {
|
|
80
|
+
init: function init() {
|
|
81
|
+
return {
|
|
82
|
+
decoration: undefined
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
apply: function apply(tr, pluginState) {
|
|
86
|
+
if (pluginState.decoration) {
|
|
87
|
+
var mapResult = tr.mapping.mapResult(pluginState.decoration.from);
|
|
88
|
+
if (mapResult.deleted) {
|
|
89
|
+
pluginState = {
|
|
90
|
+
decoration: undefined
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var meta = tr.getMeta(decorationStateKey);
|
|
95
|
+
if (!meta) {
|
|
96
|
+
return pluginState;
|
|
97
|
+
}
|
|
98
|
+
switch (meta.action) {
|
|
99
|
+
case ACTIONS.DECORATION_ADD:
|
|
100
|
+
return {
|
|
101
|
+
decoration: meta.data
|
|
102
|
+
};
|
|
103
|
+
case ACTIONS.DECORATION_REMOVE:
|
|
104
|
+
return {
|
|
105
|
+
decoration: undefined
|
|
106
|
+
};
|
|
107
|
+
default:
|
|
108
|
+
return pluginState;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
props: {
|
|
113
|
+
decorations: function decorations(state) {
|
|
114
|
+
var doc = state.doc;
|
|
115
|
+
var _ref = decorationStateKey.getState(state),
|
|
116
|
+
decoration = _ref.decoration;
|
|
117
|
+
if (decoration) {
|
|
118
|
+
return _prosemirrorView.DecorationSet.create(doc, [decoration]);
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { decorationsPlugin } from './plugin';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import decorationPlugin, { decorationStateKey, hoverDecoration, removeDecoration } from './pm-plugin';
|
|
2
|
+
export const decorationsPlugin = () => ({
|
|
3
|
+
name: 'decorations',
|
|
4
|
+
pmPlugins() {
|
|
5
|
+
return [{
|
|
6
|
+
name: 'decorationPlugin',
|
|
7
|
+
plugin: () => decorationPlugin()
|
|
8
|
+
}];
|
|
9
|
+
},
|
|
10
|
+
actions: {
|
|
11
|
+
hoverDecoration,
|
|
12
|
+
removeDecoration
|
|
13
|
+
},
|
|
14
|
+
getSharedState(editorState) {
|
|
15
|
+
if (!editorState) {
|
|
16
|
+
return {
|
|
17
|
+
decoration: undefined
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return decorationStateKey.getState(editorState);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { NodeSelection, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { findParentNodeOfType } from 'prosemirror-utils';
|
|
3
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
+
export const decorationStateKey = new PluginKey('decorationPlugin');
|
|
6
|
+
export let ACTIONS = /*#__PURE__*/function (ACTIONS) {
|
|
7
|
+
ACTIONS[ACTIONS["DECORATION_ADD"] = 0] = "DECORATION_ADD";
|
|
8
|
+
ACTIONS[ACTIONS["DECORATION_REMOVE"] = 1] = "DECORATION_REMOVE";
|
|
9
|
+
return ACTIONS;
|
|
10
|
+
}({});
|
|
11
|
+
export const removeDecoration = (state, dispatch) => {
|
|
12
|
+
const {
|
|
13
|
+
tr
|
|
14
|
+
} = state;
|
|
15
|
+
if (dispatch) {
|
|
16
|
+
dispatch(tr.setMeta(decorationStateKey, {
|
|
17
|
+
action: ACTIONS.DECORATION_REMOVE
|
|
18
|
+
}));
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
export const hoverDecoration = (nodeType, add, className = 'danger') => (state, dispatch) => {
|
|
24
|
+
let from;
|
|
25
|
+
let parentNode;
|
|
26
|
+
if (state.selection instanceof NodeSelection) {
|
|
27
|
+
const selectedNode = state.selection.node;
|
|
28
|
+
const nodeTypes = Array.isArray(nodeType) ? nodeType : [nodeType];
|
|
29
|
+
const isNodeTypeMatching = nodeTypes.indexOf(selectedNode.type) > -1;
|
|
30
|
+
// This adds danger styling if the selected node is the one that requires
|
|
31
|
+
// the decoration to be added, e.g. if a layout is selected and the user
|
|
32
|
+
// hovers over the layout's delete button.
|
|
33
|
+
if (isNodeTypeMatching) {
|
|
34
|
+
from = state.selection.from;
|
|
35
|
+
parentNode = selectedNode;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// This adds danger styling if the selection is not a node selection, OR if
|
|
40
|
+
// the selected node is a child of the one that requires the decoration to
|
|
41
|
+
// be added, e.g. if a decision item is selected inside a layout and the
|
|
42
|
+
// user hovers over the layout's delete button.
|
|
43
|
+
const foundParentNode = findParentNodeOfType(nodeType)(state.selection);
|
|
44
|
+
if (from === undefined && foundParentNode) {
|
|
45
|
+
from = foundParentNode.pos;
|
|
46
|
+
parentNode = foundParentNode.node;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Note: can't use !from as from could be 0, which is falsy but valid
|
|
50
|
+
if (from === undefined || parentNode === undefined) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (dispatch) {
|
|
54
|
+
dispatch(state.tr.setMeta(decorationStateKey, {
|
|
55
|
+
action: add ? ACTIONS.DECORATION_ADD : ACTIONS.DECORATION_REMOVE,
|
|
56
|
+
data: Decoration.node(from, from + parentNode.nodeSize, {
|
|
57
|
+
class: className
|
|
58
|
+
}, {
|
|
59
|
+
key: 'decorationNode'
|
|
60
|
+
})
|
|
61
|
+
}).setMeta('addToHistory', false));
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
export default (() => {
|
|
66
|
+
return new SafePlugin({
|
|
67
|
+
key: decorationStateKey,
|
|
68
|
+
state: {
|
|
69
|
+
init: () => ({
|
|
70
|
+
decoration: undefined
|
|
71
|
+
}),
|
|
72
|
+
apply(tr, pluginState) {
|
|
73
|
+
if (pluginState.decoration) {
|
|
74
|
+
const mapResult = tr.mapping.mapResult(pluginState.decoration.from);
|
|
75
|
+
if (mapResult.deleted) {
|
|
76
|
+
pluginState = {
|
|
77
|
+
decoration: undefined
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const meta = tr.getMeta(decorationStateKey);
|
|
82
|
+
if (!meta) {
|
|
83
|
+
return pluginState;
|
|
84
|
+
}
|
|
85
|
+
switch (meta.action) {
|
|
86
|
+
case ACTIONS.DECORATION_ADD:
|
|
87
|
+
return {
|
|
88
|
+
decoration: meta.data
|
|
89
|
+
};
|
|
90
|
+
case ACTIONS.DECORATION_REMOVE:
|
|
91
|
+
return {
|
|
92
|
+
decoration: undefined
|
|
93
|
+
};
|
|
94
|
+
default:
|
|
95
|
+
return pluginState;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
props: {
|
|
100
|
+
decorations(state) {
|
|
101
|
+
const {
|
|
102
|
+
doc
|
|
103
|
+
} = state;
|
|
104
|
+
const {
|
|
105
|
+
decoration
|
|
106
|
+
} = decorationStateKey.getState(state);
|
|
107
|
+
if (decoration) {
|
|
108
|
+
return DecorationSet.create(doc, [decoration]);
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { decorationsPlugin } from './plugin';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import decorationPlugin, { decorationStateKey, hoverDecoration, removeDecoration } from './pm-plugin';
|
|
2
|
+
export var decorationsPlugin = function decorationsPlugin() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'decorations',
|
|
5
|
+
pmPlugins: function pmPlugins() {
|
|
6
|
+
return [{
|
|
7
|
+
name: 'decorationPlugin',
|
|
8
|
+
plugin: function plugin() {
|
|
9
|
+
return decorationPlugin();
|
|
10
|
+
}
|
|
11
|
+
}];
|
|
12
|
+
},
|
|
13
|
+
actions: {
|
|
14
|
+
hoverDecoration: hoverDecoration,
|
|
15
|
+
removeDecoration: removeDecoration
|
|
16
|
+
},
|
|
17
|
+
getSharedState: function getSharedState(editorState) {
|
|
18
|
+
if (!editorState) {
|
|
19
|
+
return {
|
|
20
|
+
decoration: undefined
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return decorationStateKey.getState(editorState);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { NodeSelection, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { findParentNodeOfType } from 'prosemirror-utils';
|
|
3
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
+
export var decorationStateKey = new PluginKey('decorationPlugin');
|
|
6
|
+
export var ACTIONS = /*#__PURE__*/function (ACTIONS) {
|
|
7
|
+
ACTIONS[ACTIONS["DECORATION_ADD"] = 0] = "DECORATION_ADD";
|
|
8
|
+
ACTIONS[ACTIONS["DECORATION_REMOVE"] = 1] = "DECORATION_REMOVE";
|
|
9
|
+
return ACTIONS;
|
|
10
|
+
}({});
|
|
11
|
+
export var removeDecoration = function removeDecoration(state, dispatch) {
|
|
12
|
+
var tr = state.tr;
|
|
13
|
+
if (dispatch) {
|
|
14
|
+
dispatch(tr.setMeta(decorationStateKey, {
|
|
15
|
+
action: ACTIONS.DECORATION_REMOVE
|
|
16
|
+
}));
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
export var hoverDecoration = function hoverDecoration(nodeType, add) {
|
|
22
|
+
var className = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'danger';
|
|
23
|
+
return function (state, dispatch) {
|
|
24
|
+
var from;
|
|
25
|
+
var parentNode;
|
|
26
|
+
if (state.selection instanceof NodeSelection) {
|
|
27
|
+
var selectedNode = state.selection.node;
|
|
28
|
+
var nodeTypes = Array.isArray(nodeType) ? nodeType : [nodeType];
|
|
29
|
+
var isNodeTypeMatching = nodeTypes.indexOf(selectedNode.type) > -1;
|
|
30
|
+
// This adds danger styling if the selected node is the one that requires
|
|
31
|
+
// the decoration to be added, e.g. if a layout is selected and the user
|
|
32
|
+
// hovers over the layout's delete button.
|
|
33
|
+
if (isNodeTypeMatching) {
|
|
34
|
+
from = state.selection.from;
|
|
35
|
+
parentNode = selectedNode;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// This adds danger styling if the selection is not a node selection, OR if
|
|
40
|
+
// the selected node is a child of the one that requires the decoration to
|
|
41
|
+
// be added, e.g. if a decision item is selected inside a layout and the
|
|
42
|
+
// user hovers over the layout's delete button.
|
|
43
|
+
var foundParentNode = findParentNodeOfType(nodeType)(state.selection);
|
|
44
|
+
if (from === undefined && foundParentNode) {
|
|
45
|
+
from = foundParentNode.pos;
|
|
46
|
+
parentNode = foundParentNode.node;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Note: can't use !from as from could be 0, which is falsy but valid
|
|
50
|
+
if (from === undefined || parentNode === undefined) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (dispatch) {
|
|
54
|
+
dispatch(state.tr.setMeta(decorationStateKey, {
|
|
55
|
+
action: add ? ACTIONS.DECORATION_ADD : ACTIONS.DECORATION_REMOVE,
|
|
56
|
+
data: Decoration.node(from, from + parentNode.nodeSize, {
|
|
57
|
+
class: className
|
|
58
|
+
}, {
|
|
59
|
+
key: 'decorationNode'
|
|
60
|
+
})
|
|
61
|
+
}).setMeta('addToHistory', false));
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export default (function () {
|
|
67
|
+
return new SafePlugin({
|
|
68
|
+
key: decorationStateKey,
|
|
69
|
+
state: {
|
|
70
|
+
init: function init() {
|
|
71
|
+
return {
|
|
72
|
+
decoration: undefined
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
apply: function apply(tr, pluginState) {
|
|
76
|
+
if (pluginState.decoration) {
|
|
77
|
+
var mapResult = tr.mapping.mapResult(pluginState.decoration.from);
|
|
78
|
+
if (mapResult.deleted) {
|
|
79
|
+
pluginState = {
|
|
80
|
+
decoration: undefined
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var meta = tr.getMeta(decorationStateKey);
|
|
85
|
+
if (!meta) {
|
|
86
|
+
return pluginState;
|
|
87
|
+
}
|
|
88
|
+
switch (meta.action) {
|
|
89
|
+
case ACTIONS.DECORATION_ADD:
|
|
90
|
+
return {
|
|
91
|
+
decoration: meta.data
|
|
92
|
+
};
|
|
93
|
+
case ACTIONS.DECORATION_REMOVE:
|
|
94
|
+
return {
|
|
95
|
+
decoration: undefined
|
|
96
|
+
};
|
|
97
|
+
default:
|
|
98
|
+
return pluginState;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
props: {
|
|
103
|
+
decorations: function decorations(state) {
|
|
104
|
+
var doc = state.doc;
|
|
105
|
+
var _ref = decorationStateKey.getState(state),
|
|
106
|
+
decoration = _ref.decoration;
|
|
107
|
+
if (decoration) {
|
|
108
|
+
return DecorationSet.create(doc, [decoration]);
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { DecorationState, HoverDecorationHandler, removeDecoration } from './pm-plugin';
|
|
3
|
+
export declare const decorationsPlugin: NextEditorPlugin<'decorations', {
|
|
4
|
+
sharedState: DecorationState;
|
|
5
|
+
actions: {
|
|
6
|
+
hoverDecoration: HoverDecorationHandler;
|
|
7
|
+
removeDecoration: typeof removeDecoration;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NodeType } from 'prosemirror-model';
|
|
2
|
+
import { PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { Decoration } from 'prosemirror-view';
|
|
4
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
6
|
+
export declare const decorationStateKey: PluginKey<any, any>;
|
|
7
|
+
export declare enum ACTIONS {
|
|
8
|
+
DECORATION_ADD = 0,
|
|
9
|
+
DECORATION_REMOVE = 1
|
|
10
|
+
}
|
|
11
|
+
export declare const removeDecoration: Command;
|
|
12
|
+
export declare const hoverDecoration: (nodeType: NodeType | Array<NodeType>, add: boolean, className?: string) => Command;
|
|
13
|
+
export type DecorationState = {
|
|
14
|
+
decoration?: Decoration;
|
|
15
|
+
};
|
|
16
|
+
type HoverDecorationHandler = typeof hoverDecoration;
|
|
17
|
+
export type { HoverDecorationHandler };
|
|
18
|
+
declare const _default: () => SafePlugin<DecorationState, any>;
|
|
19
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { DecorationState, HoverDecorationHandler, removeDecoration } from './pm-plugin';
|
|
3
|
+
export declare const decorationsPlugin: NextEditorPlugin<'decorations', {
|
|
4
|
+
sharedState: DecorationState;
|
|
5
|
+
actions: {
|
|
6
|
+
hoverDecoration: HoverDecorationHandler;
|
|
7
|
+
removeDecoration: typeof removeDecoration;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NodeType } from 'prosemirror-model';
|
|
2
|
+
import { PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { Decoration } from 'prosemirror-view';
|
|
4
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
6
|
+
export declare const decorationStateKey: PluginKey<any, any>;
|
|
7
|
+
export declare enum ACTIONS {
|
|
8
|
+
DECORATION_ADD = 0,
|
|
9
|
+
DECORATION_REMOVE = 1
|
|
10
|
+
}
|
|
11
|
+
export declare const removeDecoration: Command;
|
|
12
|
+
export declare const hoverDecoration: (nodeType: NodeType | Array<NodeType>, add: boolean, className?: string) => Command;
|
|
13
|
+
export type DecorationState = {
|
|
14
|
+
decoration?: Decoration;
|
|
15
|
+
};
|
|
16
|
+
type HoverDecorationHandler = typeof hoverDecoration;
|
|
17
|
+
export type { HoverDecorationHandler };
|
|
18
|
+
declare const _default: () => SafePlugin<DecorationState, any>;
|
|
19
|
+
export default _default;
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-decorations",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Decorations 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",
|
|
12
|
+
"releaseModel": "scheduled"
|
|
13
|
+
},
|
|
14
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend",
|
|
15
|
+
"main": "dist/cjs/index.js",
|
|
16
|
+
"module": "dist/esm/index.js",
|
|
17
|
+
"module:es2019": "dist/es2019/index.js",
|
|
18
|
+
"types": "dist/types/index.d.ts",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"atlaskit:src": "src/index.ts",
|
|
21
|
+
"af:exports": {
|
|
22
|
+
".": "./src/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@atlaskit/editor-common": "^74.3.0",
|
|
26
|
+
"@babel/runtime": "^7.0.0",
|
|
27
|
+
"prosemirror-model": "1.16.0",
|
|
28
|
+
"prosemirror-state": "1.3.4",
|
|
29
|
+
"prosemirror-utils": "^1.0.0-0",
|
|
30
|
+
"prosemirror-view": "1.23.7"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^16.8.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@atlaskit/docs": "*",
|
|
37
|
+
"@atlaskit/editor-core": "^185.0.0",
|
|
38
|
+
"@atlaskit/editor-test-helpers": "^18.2.0",
|
|
39
|
+
"@atlaskit/ssr": "*",
|
|
40
|
+
"@atlaskit/visual-regression": "*",
|
|
41
|
+
"@atlaskit/webdriver-runner": "*",
|
|
42
|
+
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
43
|
+
"@testing-library/react": "^12.1.5",
|
|
44
|
+
"react-dom": "^16.8.0",
|
|
45
|
+
"typescript": "~4.9.5",
|
|
46
|
+
"wait-for-expect": "^1.2.0"
|
|
47
|
+
},
|
|
48
|
+
"techstack": {
|
|
49
|
+
"@atlassian/frontend": {
|
|
50
|
+
"import-structure": [
|
|
51
|
+
"atlassian-conventions"
|
|
52
|
+
],
|
|
53
|
+
"circular-dependencies": [
|
|
54
|
+
"file-and-folder-level"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"@repo/internal": {
|
|
58
|
+
"dom-events": "use-bind-event-listener",
|
|
59
|
+
"analytics": [
|
|
60
|
+
"analytics-next"
|
|
61
|
+
],
|
|
62
|
+
"design-tokens": [
|
|
63
|
+
"color"
|
|
64
|
+
],
|
|
65
|
+
"theming": [
|
|
66
|
+
"react-context"
|
|
67
|
+
],
|
|
68
|
+
"ui-components": [
|
|
69
|
+
"lite-mode"
|
|
70
|
+
],
|
|
71
|
+
"deprecation": [
|
|
72
|
+
"no-deprecated-imports"
|
|
73
|
+
],
|
|
74
|
+
"styling": [
|
|
75
|
+
"static",
|
|
76
|
+
"emotion"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
|
|
81
|
+
}
|
package/report.api.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!-- API Report Version: 2.3 -->
|
|
2
|
+
|
|
3
|
+
## API Report File for "@atlaskit/editor-plugin-decorations"
|
|
4
|
+
|
|
5
|
+
> Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
|
|
6
|
+
> [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
|
|
7
|
+
|
|
8
|
+
### Table of contents
|
|
9
|
+
|
|
10
|
+
- [Main Entry Types](#main-entry-types)
|
|
11
|
+
- [Peer Dependencies](#peer-dependencies)
|
|
12
|
+
|
|
13
|
+
### Main Entry Types
|
|
14
|
+
|
|
15
|
+
<!--SECTION START: Main Entry Types-->
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
19
|
+
import { Decoration } from 'prosemirror-view';
|
|
20
|
+
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
21
|
+
import { NodeType } from 'prosemirror-model';
|
|
22
|
+
|
|
23
|
+
// @public (undocumented)
|
|
24
|
+
export const decorationsPlugin: NextEditorPlugin<
|
|
25
|
+
'decorations',
|
|
26
|
+
{
|
|
27
|
+
sharedState: DecorationState;
|
|
28
|
+
actions: {
|
|
29
|
+
hoverDecoration: HoverDecorationHandler;
|
|
30
|
+
removeDecoration: typeof removeDecoration;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
// @public (undocumented)
|
|
36
|
+
export type DecorationState = {
|
|
37
|
+
decoration?: Decoration;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// @public (undocumented)
|
|
41
|
+
const hoverDecoration: (
|
|
42
|
+
nodeType: Array<NodeType> | NodeType,
|
|
43
|
+
add: boolean,
|
|
44
|
+
className?: string,
|
|
45
|
+
) => Command;
|
|
46
|
+
|
|
47
|
+
// @public (undocumented)
|
|
48
|
+
export type HoverDecorationHandler = typeof hoverDecoration;
|
|
49
|
+
|
|
50
|
+
// @public (undocumented)
|
|
51
|
+
const removeDecoration: Command;
|
|
52
|
+
|
|
53
|
+
// (No @packageDocumentation comment for this package)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
<!--SECTION END: Main Entry Types-->
|
|
57
|
+
|
|
58
|
+
### Peer Dependencies
|
|
59
|
+
|
|
60
|
+
<!--SECTION START: Peer Dependencies-->
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"react": "^16.8.0"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
<!--SECTION END: Peer Dependencies-->
|