@atlaskit/editor-core 189.3.38 → 189.4.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 +10 -0
- package/dist/cjs/plugins/extension/commands.js +9 -2
- package/dist/cjs/plugins/extension/index.js +15 -1
- package/dist/cjs/plugins/extension/pm-plugins/main.js +2 -1
- package/dist/cjs/plugins/extension/toolbar.js +1 -1
- package/dist/cjs/plugins/extension/ui/Extension/Extension/index.js +1 -8
- package/dist/cjs/plugins/extension/ui/Extension/ExtensionComponent.js +29 -10
- package/dist/cjs/plugins/extension/ui/Extension/ExtensionNodeWrapper.js +7 -0
- package/dist/cjs/plugins/extension/ui/Extension/MultiBodiedExtension/index.js +154 -0
- package/dist/cjs/plugins/extension/utils.js +6 -4
- package/dist/cjs/ui/ContentStyles/extension.js +2 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/plugins/extension/commands.js +10 -3
- package/dist/es2019/plugins/extension/index.js +16 -2
- package/dist/es2019/plugins/extension/pm-plugins/main.js +2 -1
- package/dist/es2019/plugins/extension/toolbar.js +1 -1
- package/dist/es2019/plugins/extension/ui/Extension/Extension/index.js +1 -8
- package/dist/es2019/plugins/extension/ui/Extension/ExtensionComponent.js +29 -10
- package/dist/es2019/plugins/extension/ui/Extension/ExtensionNodeWrapper.js +7 -0
- package/dist/es2019/plugins/extension/ui/Extension/MultiBodiedExtension/index.js +159 -0
- package/dist/es2019/plugins/extension/utils.js +6 -4
- package/dist/es2019/ui/ContentStyles/extension.js +6 -0
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/plugins/extension/commands.js +9 -2
- package/dist/esm/plugins/extension/index.js +16 -2
- package/dist/esm/plugins/extension/pm-plugins/main.js +2 -1
- package/dist/esm/plugins/extension/toolbar.js +1 -1
- package/dist/esm/plugins/extension/ui/Extension/Extension/index.js +1 -8
- package/dist/esm/plugins/extension/ui/Extension/ExtensionComponent.js +29 -10
- package/dist/esm/plugins/extension/ui/Extension/ExtensionNodeWrapper.js +7 -0
- package/dist/esm/plugins/extension/ui/Extension/MultiBodiedExtension/index.js +146 -0
- package/dist/esm/plugins/extension/utils.js +6 -4
- package/dist/esm/ui/ContentStyles/extension.js +2 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/plugins/extension/commands.d.ts +2 -0
- package/dist/types/plugins/extension/ui/Extension/ExtensionComponent.d.ts +1 -0
- package/dist/types/plugins/extension/ui/Extension/ExtensionNodeWrapper.d.ts +7 -0
- package/dist/types/plugins/extension/ui/Extension/MultiBodiedExtension/index.d.ts +16 -0
- package/dist/types-ts4.5/plugins/extension/commands.d.ts +2 -0
- package/dist/types-ts4.5/plugins/extension/ui/Extension/ExtensionComponent.d.ts +1 -0
- package/dist/types-ts4.5/plugins/extension/ui/Extension/ExtensionNodeWrapper.d.ts +7 -0
- package/dist/types-ts4.5/plugins/extension/ui/Extension/MultiBodiedExtension/index.d.ts +16 -0
- package/package.json +6 -6
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
|
|
3
|
+
import { jsx, css } from '@emotion/react';
|
|
4
|
+
import { N30 } from '@atlaskit/theme/colors';
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
const useMultiBodiedExtensionActions = ({
|
|
7
|
+
updateActiveChild,
|
|
8
|
+
editorView,
|
|
9
|
+
getPos,
|
|
10
|
+
node
|
|
11
|
+
}) => {
|
|
12
|
+
const actions = React.useMemo(() => {
|
|
13
|
+
return {
|
|
14
|
+
changeActive(index) {
|
|
15
|
+
return updateActiveChild(index);
|
|
16
|
+
},
|
|
17
|
+
addChild() {
|
|
18
|
+
const {
|
|
19
|
+
state,
|
|
20
|
+
dispatch
|
|
21
|
+
} = editorView;
|
|
22
|
+
if (node.content.childCount >= node.attrs.maxFrames) {
|
|
23
|
+
// TODO: add proper log on this
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const p = state.schema.nodes.paragraph.createAndFill({});
|
|
27
|
+
if (!p) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const frame = state.schema.nodes.extensionFrame.createAndFill({}, [p]);
|
|
31
|
+
const pos = getPos();
|
|
32
|
+
if (typeof pos !== 'number' || !frame) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const insertAt = Math.min((pos || 1) + node.content.size, state.doc.content.size);
|
|
36
|
+
dispatch(state.tr.insert(insertAt, frame));
|
|
37
|
+
return true;
|
|
38
|
+
},
|
|
39
|
+
getChildrenCount() {
|
|
40
|
+
return node.content.childCount;
|
|
41
|
+
},
|
|
42
|
+
removeChild(index) {
|
|
43
|
+
const pos = getPos();
|
|
44
|
+
// TODO: Add child index validation here, don't trust this data
|
|
45
|
+
if (typeof pos !== 'number' || typeof index !== 'number') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const {
|
|
49
|
+
state,
|
|
50
|
+
dispatch
|
|
51
|
+
} = editorView;
|
|
52
|
+
if (node.content.childCount === 1) {
|
|
53
|
+
const tr = state.tr;
|
|
54
|
+
tr.deleteRange(pos, pos + node.content.size);
|
|
55
|
+
dispatch(tr);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const $pos = state.doc.resolve(pos);
|
|
59
|
+
const $startNodePos = state.doc.resolve($pos.start($pos.depth + 1));
|
|
60
|
+
const startFramePosition = $startNodePos.posAtIndex(index);
|
|
61
|
+
const maybeFrameNode = state.doc.nodeAt(startFramePosition);
|
|
62
|
+
if (!maybeFrameNode) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const endFramePosition = maybeFrameNode.content.size + startFramePosition;
|
|
66
|
+
const tr = state.tr;
|
|
67
|
+
tr.deleteRange(startFramePosition, endFramePosition);
|
|
68
|
+
dispatch(tr);
|
|
69
|
+
return true;
|
|
70
|
+
},
|
|
71
|
+
updateParameters(parameters) {
|
|
72
|
+
const {
|
|
73
|
+
state,
|
|
74
|
+
dispatch
|
|
75
|
+
} = editorView;
|
|
76
|
+
const pos = getPos();
|
|
77
|
+
if (typeof pos !== 'number') {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const tr = state.tr.setNodeMarkup(pos, undefined, {
|
|
81
|
+
...node.attrs,
|
|
82
|
+
parameters
|
|
83
|
+
});
|
|
84
|
+
dispatch(tr);
|
|
85
|
+
return true;
|
|
86
|
+
},
|
|
87
|
+
getChildren() {
|
|
88
|
+
var _state$doc$nodeAt;
|
|
89
|
+
const {
|
|
90
|
+
state
|
|
91
|
+
} = editorView;
|
|
92
|
+
const pos = getPos();
|
|
93
|
+
if (typeof pos !== 'number') {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
const children = (_state$doc$nodeAt = state.doc.nodeAt(pos)) === null || _state$doc$nodeAt === void 0 ? void 0 : _state$doc$nodeAt.content;
|
|
97
|
+
return children ? children.toJSON() : [];
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, [node, editorView, getPos, updateActiveChild]);
|
|
101
|
+
return actions;
|
|
102
|
+
};
|
|
103
|
+
const MultiBodiedExtension = ({
|
|
104
|
+
node,
|
|
105
|
+
handleContentDOMRef,
|
|
106
|
+
getPos,
|
|
107
|
+
tryExtensionHandler,
|
|
108
|
+
editorView
|
|
109
|
+
}) => {
|
|
110
|
+
const [activeChildIndex, setActiveChildIndex] = useState(0);
|
|
111
|
+
// Adding to avoid aliasing `this` for the callbacks
|
|
112
|
+
const updateActiveChild = React.useCallback(index => {
|
|
113
|
+
if (typeof index !== 'number') {
|
|
114
|
+
// TODO: Make sure we log this somewhere if this happens
|
|
115
|
+
setActiveChildIndex(0);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
setActiveChildIndex(index);
|
|
119
|
+
return true;
|
|
120
|
+
}, [setActiveChildIndex]);
|
|
121
|
+
const actions = useMultiBodiedExtensionActions({
|
|
122
|
+
updateActiveChild,
|
|
123
|
+
editorView,
|
|
124
|
+
getPos,
|
|
125
|
+
node
|
|
126
|
+
});
|
|
127
|
+
const extensionHandlerResult = React.useMemo(() => {
|
|
128
|
+
return tryExtensionHandler(actions);
|
|
129
|
+
}, [tryExtensionHandler, actions]);
|
|
130
|
+
const articleRef = React.useCallback(node => {
|
|
131
|
+
return handleContentDOMRef(node);
|
|
132
|
+
}, [handleContentDOMRef]);
|
|
133
|
+
const containerCss = css`
|
|
134
|
+
border: 1px solid ${`var(--ds-border, ${N30})`};
|
|
135
|
+
padding: ${"var(--ds-space-050, 4px)"};
|
|
136
|
+
.multiBodiedExtension-content-dom-wrapper > [data-extension-frame='true'] {
|
|
137
|
+
display: none;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.multiBodiedExtension-content-dom-wrapper
|
|
141
|
+
> [data-extension-frame='true']:nth-of-type(${activeChildIndex + 1}) {
|
|
142
|
+
display: block;
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
145
|
+
return jsx("section", {
|
|
146
|
+
className: "multiBodiedExtension--container",
|
|
147
|
+
css: containerCss,
|
|
148
|
+
"data-testid": "multiBodiedExtension--container",
|
|
149
|
+
"data-active-child-index": activeChildIndex
|
|
150
|
+
}, jsx("nav", {
|
|
151
|
+
className: "multiBodiedExtension-navigation",
|
|
152
|
+
"data-testid": "multiBodiedExtension-navigation"
|
|
153
|
+
}, extensionHandlerResult), jsx("article", {
|
|
154
|
+
className: "multiBodiedExtension--frames",
|
|
155
|
+
"data-testid": "multiBodiedExtension--frames",
|
|
156
|
+
ref: articleRef
|
|
157
|
+
}));
|
|
158
|
+
};
|
|
159
|
+
export default MultiBodiedExtension;
|
|
@@ -4,9 +4,10 @@ export const getSelectedExtension = (state, searchParent = false) => {
|
|
|
4
4
|
const {
|
|
5
5
|
inlineExtension,
|
|
6
6
|
extension,
|
|
7
|
-
bodiedExtension
|
|
7
|
+
bodiedExtension,
|
|
8
|
+
multiBodiedExtension
|
|
8
9
|
} = state.schema.nodes;
|
|
9
|
-
const nodeTypes = [extension, bodiedExtension, inlineExtension];
|
|
10
|
+
const nodeTypes = [extension, bodiedExtension, inlineExtension, multiBodiedExtension];
|
|
10
11
|
return findSelectedNodeOfType(nodeTypes)(state.selection) || searchParent && findParentNodeOfType(nodeTypes)(state.selection) || undefined;
|
|
11
12
|
};
|
|
12
13
|
export const findExtensionWithLocalId = (state, localId) => {
|
|
@@ -20,9 +21,10 @@ export const findExtensionWithLocalId = (state, localId) => {
|
|
|
20
21
|
const {
|
|
21
22
|
inlineExtension,
|
|
22
23
|
extension,
|
|
23
|
-
bodiedExtension
|
|
24
|
+
bodiedExtension,
|
|
25
|
+
multiBodiedExtension
|
|
24
26
|
} = state.schema.nodes;
|
|
25
|
-
const nodeTypes = [extension, bodiedExtension, inlineExtension];
|
|
27
|
+
const nodeTypes = [extension, bodiedExtension, inlineExtension, multiBodiedExtension];
|
|
26
28
|
let matched;
|
|
27
29
|
state.doc.descendants((node, pos) => {
|
|
28
30
|
if (nodeTypes.includes(node.type) && node.attrs.localId === localId) {
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { css } from '@emotion/react';
|
|
2
2
|
import { blockNodesVerticalMargin, akEditorSelectedBorderSize, akEditorDeleteBorder, akEditorDeleteBackground, SelectionStyle, getSelectionStyles, akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
|
|
3
|
+
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
3
4
|
export const extensionStyles = css`
|
|
5
|
+
.multiBodiedExtensionView-content-wrap.${akEditorSelectedNodeClassName}:not(.danger) {
|
|
6
|
+
${getSelectionStyles([SelectionStyle.BoxShadow, SelectionStyle.Blanket])}
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
.extensionView-content-wrap,
|
|
10
|
+
.multiBodiedExtensionView-content-wrap,
|
|
5
11
|
.bodiedExtensionView-content-wrap {
|
|
6
12
|
margin: ${blockNodesVerticalMargin} 0;
|
|
7
13
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = "@atlaskit/editor-core";
|
|
2
|
-
export const version = "189.
|
|
2
|
+
export const version = "189.4.0";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
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
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import { removeSelectedNode, removeParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
+
import { removeSelectedNode, removeParentNodeOfType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
5
|
import { createCommand } from './plugin-factory';
|
|
6
6
|
import { getSelectedExtension } from './utils';
|
|
7
7
|
import { removeConnectedNodes } from '@atlaskit/editor-common/utils';
|
|
@@ -72,7 +72,7 @@ export var removeExtension = function removeExtension() {
|
|
|
72
72
|
if (getSelectedExtension(state)) {
|
|
73
73
|
return removeSelectedNode(tr);
|
|
74
74
|
} else {
|
|
75
|
-
return
|
|
75
|
+
return checkAndRemoveExtensionNode(state, tr);
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
};
|
|
@@ -85,4 +85,11 @@ export var removeDescendantNodes = function removeDescendantNodes(sourceNode) {
|
|
|
85
85
|
}, function (tr, state) {
|
|
86
86
|
return sourceNode ? removeConnectedNodes(state, sourceNode) : tr;
|
|
87
87
|
});
|
|
88
|
+
};
|
|
89
|
+
export var checkAndRemoveExtensionNode = function checkAndRemoveExtensionNode(state, tr) {
|
|
90
|
+
var nodeType = state.schema.nodes.bodiedExtension;
|
|
91
|
+
if (findParentNodeOfType(state.schema.nodes.multiBodiedExtension)(state.selection)) {
|
|
92
|
+
nodeType = state.schema.nodes.multiBodiedExtension;
|
|
93
|
+
}
|
|
94
|
+
return removeParentNodeOfType(nodeType)(tr);
|
|
88
95
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extension, bodiedExtension, inlineExtension } from '@atlaskit/adf-schema';
|
|
1
|
+
import { extension, bodiedExtension, inlineExtension, multiBodiedExtension, extensionFrame } from '@atlaskit/adf-schema';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import { createPlugin } from './pm-plugins/main';
|
|
4
4
|
import { createPlugin as createMacroPlugin } from './pm-plugins/macro';
|
|
@@ -9,6 +9,7 @@ import { getToolbarConfig } from './toolbar';
|
|
|
9
9
|
import { getContextPanel } from './context-panel';
|
|
10
10
|
import { createExtensionAPI } from './extension-api';
|
|
11
11
|
import { createEditSelectedExtensionAction } from './actions';
|
|
12
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
12
13
|
var extensionPlugin = function extensionPlugin(_ref) {
|
|
13
14
|
var _api$featureFlags, _api$analytics2, _api$analytics3, _api$contextPanel3, _api$analytics4, _api$contextPanel4;
|
|
14
15
|
var _ref$config = _ref.config,
|
|
@@ -23,7 +24,7 @@ var extensionPlugin = function extensionPlugin(_ref) {
|
|
|
23
24
|
return {
|
|
24
25
|
name: 'extension',
|
|
25
26
|
nodes: function nodes() {
|
|
26
|
-
|
|
27
|
+
var extensionNodes = [{
|
|
27
28
|
name: 'extension',
|
|
28
29
|
node: extension
|
|
29
30
|
}, {
|
|
@@ -33,6 +34,19 @@ var extensionPlugin = function extensionPlugin(_ref) {
|
|
|
33
34
|
name: 'inlineExtension',
|
|
34
35
|
node: inlineExtension
|
|
35
36
|
}];
|
|
37
|
+
|
|
38
|
+
// Revert to returning all nodes without local variable, once FF is removed
|
|
39
|
+
if (getBooleanFF('platform.editor.multi-bodied-extension_0rygg')) {
|
|
40
|
+
extensionNodes.push({
|
|
41
|
+
name: 'extensionFrame',
|
|
42
|
+
node: extensionFrame
|
|
43
|
+
});
|
|
44
|
+
extensionNodes.push({
|
|
45
|
+
name: 'multiBodiedExtension',
|
|
46
|
+
node: multiBodiedExtension
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return extensionNodes;
|
|
36
50
|
},
|
|
37
51
|
pmPlugins: function pmPlugins() {
|
|
38
52
|
return [{
|
|
@@ -284,7 +284,8 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
|
|
|
284
284
|
// WARNING: referentiality-plugin also creates these nodeviews
|
|
285
285
|
bodiedExtension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi),
|
|
286
286
|
// WARNING: referentiality-plugin also creates these nodeviews
|
|
287
|
-
inlineExtension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi)
|
|
287
|
+
inlineExtension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi),
|
|
288
|
+
multiBodiedExtension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi)
|
|
288
289
|
},
|
|
289
290
|
handleClickOn: createSelectionClickHandler(['extension', 'bodiedExtension'], function (target) {
|
|
290
291
|
return !target.closest('.extension-content');
|
|
@@ -121,7 +121,7 @@ export var getToolbarConfig = function getToolbarConfig(_ref) {
|
|
|
121
121
|
var formatMessage = intl.formatMessage;
|
|
122
122
|
var extensionState = getPluginState(state);
|
|
123
123
|
if (extensionState && !extensionState.showContextPanel && extensionState.element) {
|
|
124
|
-
var nodeType = [state.schema.nodes.extension, state.schema.nodes.inlineExtension, state.schema.nodes.bodiedExtension];
|
|
124
|
+
var nodeType = [state.schema.nodes.extension, state.schema.nodes.inlineExtension, state.schema.nodes.bodiedExtension, state.schema.nodes.multiBodiedExtension];
|
|
125
125
|
var editButtonArray = editButton(formatMessage, extensionState, applyChangeToContextPanel, editorAnalyticsAPI);
|
|
126
126
|
var breakoutButtonArray = breakoutOptions(state, formatMessage, extensionState, breakoutEnabled);
|
|
127
127
|
var extensionObj = getSelectedExtension(state, true);
|
|
@@ -15,7 +15,6 @@ import { overlay } from '../styles';
|
|
|
15
15
|
import ExtensionLozenge from '../Lozenge';
|
|
16
16
|
import classnames from 'classnames';
|
|
17
17
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
18
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
19
18
|
function ExtensionWithPluginState(props) {
|
|
20
19
|
var node = props.node,
|
|
21
20
|
handleContentDOMRef = props.handleContentDOMRef,
|
|
@@ -28,13 +27,7 @@ function ExtensionWithPluginState(props) {
|
|
|
28
27
|
shadowClassNames = props.shadowClassNames,
|
|
29
28
|
hideFrame = props.hideFrame,
|
|
30
29
|
editorAppearance = props.editorAppearance;
|
|
31
|
-
var
|
|
32
|
-
if (getBooleanFF('platform.editor.multi-bodied-extension_0rygg')) {
|
|
33
|
-
isMultiBodiedExtension = true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//TODO: clean-up after removing multi-bodied-extension FF
|
|
37
|
-
var hasBody = node.type.name === 'bodiedExtension' || isMultiBodiedExtension && node.type.name === 'multiBodiedExtension';
|
|
30
|
+
var hasBody = ['bodiedExtension', 'multiBodiedExtension'].includes(node.type.name);
|
|
38
31
|
var isMobile = editorAppearance === 'mobile';
|
|
39
32
|
var hasChildren = !!children;
|
|
40
33
|
var removeBorder = hideFrame && !isMobile && !hasBody || false;
|
|
@@ -16,6 +16,7 @@ import { getNodeRenderer, getExtensionModuleNodePrivateProps } from '@atlaskit/e
|
|
|
16
16
|
import { getExtensionRenderer } from '@atlaskit/editor-common/utils';
|
|
17
17
|
import Extension from './Extension';
|
|
18
18
|
import InlineExtension from './InlineExtension';
|
|
19
|
+
import MultiBodiedExtension from './MultiBodiedExtension';
|
|
19
20
|
var ExtensionComponent = /*#__PURE__*/function (_Component) {
|
|
20
21
|
_inherits(ExtensionComponent, _Component);
|
|
21
22
|
var _super = _createSuper(ExtensionComponent);
|
|
@@ -87,7 +88,7 @@ var ExtensionComponent = /*#__PURE__*/function (_Component) {
|
|
|
87
88
|
}
|
|
88
89
|
}, _callee, null, [[4, 11]]);
|
|
89
90
|
})));
|
|
90
|
-
_defineProperty(_assertThisInitialized(_this), "handleExtension", function (pmNode) {
|
|
91
|
+
_defineProperty(_assertThisInitialized(_this), "handleExtension", function (pmNode, actions) {
|
|
91
92
|
var _pmNode$marks;
|
|
92
93
|
var _this$props = _this.props,
|
|
93
94
|
extensionHandlers = _this$props.extensionHandlers,
|
|
@@ -116,16 +117,24 @@ var ExtensionComponent = /*#__PURE__*/function (_Component) {
|
|
|
116
117
|
var result;
|
|
117
118
|
if (extensionHandlers && extensionHandlers[extensionType]) {
|
|
118
119
|
var render = getExtensionRenderer(extensionHandlers[extensionType]);
|
|
119
|
-
result = render(node, editorView.state.doc);
|
|
120
|
+
result = render(node, editorView.state.doc, actions);
|
|
120
121
|
}
|
|
121
122
|
if (!result) {
|
|
122
123
|
var extensionHandlerFromProvider = _this.state.extensionProvider && _this.getNodeRenderer(_this.state.extensionProvider, extensionType, extensionKey);
|
|
123
124
|
if (extensionHandlerFromProvider) {
|
|
124
125
|
var NodeRenderer = extensionHandlerFromProvider;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
if (node.type === 'multiBodiedExtension') {
|
|
127
|
+
return /*#__PURE__*/React.createElement(NodeRenderer, {
|
|
128
|
+
node: node,
|
|
129
|
+
references: _this.props.references,
|
|
130
|
+
actions: actions
|
|
131
|
+
});
|
|
132
|
+
} else {
|
|
133
|
+
return /*#__PURE__*/React.createElement(NodeRenderer, {
|
|
134
|
+
node: node,
|
|
135
|
+
references: _this.props.references
|
|
136
|
+
});
|
|
137
|
+
}
|
|
129
138
|
}
|
|
130
139
|
}
|
|
131
140
|
return result;
|
|
@@ -173,8 +182,18 @@ var ExtensionComponent = /*#__PURE__*/function (_Component) {
|
|
|
173
182
|
editorView = _this$props2.editorView,
|
|
174
183
|
references = _this$props2.references,
|
|
175
184
|
editorAppearance = _this$props2.editorAppearance,
|
|
176
|
-
pluginInjectionApi = _this$props2.pluginInjectionApi
|
|
177
|
-
|
|
185
|
+
pluginInjectionApi = _this$props2.pluginInjectionApi,
|
|
186
|
+
getPos = _this$props2.getPos;
|
|
187
|
+
if (node.type.name === 'multiBodiedExtension') {
|
|
188
|
+
return /*#__PURE__*/React.createElement(MultiBodiedExtension, {
|
|
189
|
+
node: node,
|
|
190
|
+
editorView: editorView,
|
|
191
|
+
getPos: getPos,
|
|
192
|
+
handleContentDOMRef: handleContentDOMRef,
|
|
193
|
+
tryExtensionHandler: this.tryExtensionHandler.bind(this)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
var extensionHandlerResult = this.tryExtensionHandler(undefined);
|
|
178
197
|
switch (node.type.name) {
|
|
179
198
|
case 'extension':
|
|
180
199
|
case 'bodiedExtension':
|
|
@@ -199,10 +218,10 @@ var ExtensionComponent = /*#__PURE__*/function (_Component) {
|
|
|
199
218
|
}
|
|
200
219
|
}, {
|
|
201
220
|
key: "tryExtensionHandler",
|
|
202
|
-
value: function tryExtensionHandler() {
|
|
221
|
+
value: function tryExtensionHandler(actions) {
|
|
203
222
|
var node = this.props.node;
|
|
204
223
|
try {
|
|
205
|
-
var extensionContent = this.handleExtension(node);
|
|
224
|
+
var extensionContent = this.handleExtension(node, actions);
|
|
206
225
|
if (extensionContent && /*#__PURE__*/React.isValidElement(extensionContent)) {
|
|
207
226
|
return extensionContent;
|
|
208
227
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/utils';
|
|
3
|
+
/**
|
|
4
|
+
* If inlineExtension, add zero width space to the end of the nodes and wrap with span;
|
|
5
|
+
* else wrap with a div (for multi bodied extensions)
|
|
6
|
+
*
|
|
7
|
+
* @param param0
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
3
10
|
var ExtensionNodeWrapper = function ExtensionNodeWrapper(_ref) {
|
|
4
11
|
var children = _ref.children,
|
|
5
12
|
nodeType = _ref.nodeType;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
var _templateObject;
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
/** @jsx jsx */
|
|
8
|
+
|
|
9
|
+
import { jsx, css } from '@emotion/react';
|
|
10
|
+
import { N30 } from '@atlaskit/theme/colors';
|
|
11
|
+
import React, { useState } from 'react';
|
|
12
|
+
var useMultiBodiedExtensionActions = function useMultiBodiedExtensionActions(_ref) {
|
|
13
|
+
var updateActiveChild = _ref.updateActiveChild,
|
|
14
|
+
editorView = _ref.editorView,
|
|
15
|
+
getPos = _ref.getPos,
|
|
16
|
+
node = _ref.node;
|
|
17
|
+
var actions = React.useMemo(function () {
|
|
18
|
+
return {
|
|
19
|
+
changeActive: function changeActive(index) {
|
|
20
|
+
return updateActiveChild(index);
|
|
21
|
+
},
|
|
22
|
+
addChild: function addChild() {
|
|
23
|
+
var state = editorView.state,
|
|
24
|
+
dispatch = editorView.dispatch;
|
|
25
|
+
if (node.content.childCount >= node.attrs.maxFrames) {
|
|
26
|
+
// TODO: add proper log on this
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var p = state.schema.nodes.paragraph.createAndFill({});
|
|
30
|
+
if (!p) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
var frame = state.schema.nodes.extensionFrame.createAndFill({}, [p]);
|
|
34
|
+
var pos = getPos();
|
|
35
|
+
if (typeof pos !== 'number' || !frame) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
var insertAt = Math.min((pos || 1) + node.content.size, state.doc.content.size);
|
|
39
|
+
dispatch(state.tr.insert(insertAt, frame));
|
|
40
|
+
return true;
|
|
41
|
+
},
|
|
42
|
+
getChildrenCount: function getChildrenCount() {
|
|
43
|
+
return node.content.childCount;
|
|
44
|
+
},
|
|
45
|
+
removeChild: function removeChild(index) {
|
|
46
|
+
var pos = getPos();
|
|
47
|
+
// TODO: Add child index validation here, don't trust this data
|
|
48
|
+
if (typeof pos !== 'number' || typeof index !== 'number') {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
var state = editorView.state,
|
|
52
|
+
dispatch = editorView.dispatch;
|
|
53
|
+
if (node.content.childCount === 1) {
|
|
54
|
+
var _tr = state.tr;
|
|
55
|
+
_tr.deleteRange(pos, pos + node.content.size);
|
|
56
|
+
dispatch(_tr);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
var $pos = state.doc.resolve(pos);
|
|
60
|
+
var $startNodePos = state.doc.resolve($pos.start($pos.depth + 1));
|
|
61
|
+
var startFramePosition = $startNodePos.posAtIndex(index);
|
|
62
|
+
var maybeFrameNode = state.doc.nodeAt(startFramePosition);
|
|
63
|
+
if (!maybeFrameNode) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
var endFramePosition = maybeFrameNode.content.size + startFramePosition;
|
|
67
|
+
var tr = state.tr;
|
|
68
|
+
tr.deleteRange(startFramePosition, endFramePosition);
|
|
69
|
+
dispatch(tr);
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
updateParameters: function updateParameters(parameters) {
|
|
73
|
+
var state = editorView.state,
|
|
74
|
+
dispatch = editorView.dispatch;
|
|
75
|
+
var pos = getPos();
|
|
76
|
+
if (typeof pos !== 'number') {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
var tr = state.tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
80
|
+
parameters: parameters
|
|
81
|
+
}));
|
|
82
|
+
dispatch(tr);
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
getChildren: function getChildren() {
|
|
86
|
+
var _state$doc$nodeAt;
|
|
87
|
+
var state = editorView.state;
|
|
88
|
+
var pos = getPos();
|
|
89
|
+
if (typeof pos !== 'number') {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
var children = (_state$doc$nodeAt = state.doc.nodeAt(pos)) === null || _state$doc$nodeAt === void 0 ? void 0 : _state$doc$nodeAt.content;
|
|
93
|
+
return children ? children.toJSON() : [];
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, [node, editorView, getPos, updateActiveChild]);
|
|
97
|
+
return actions;
|
|
98
|
+
};
|
|
99
|
+
var MultiBodiedExtension = function MultiBodiedExtension(_ref2) {
|
|
100
|
+
var node = _ref2.node,
|
|
101
|
+
handleContentDOMRef = _ref2.handleContentDOMRef,
|
|
102
|
+
getPos = _ref2.getPos,
|
|
103
|
+
tryExtensionHandler = _ref2.tryExtensionHandler,
|
|
104
|
+
editorView = _ref2.editorView;
|
|
105
|
+
var _useState = useState(0),
|
|
106
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
107
|
+
activeChildIndex = _useState2[0],
|
|
108
|
+
setActiveChildIndex = _useState2[1];
|
|
109
|
+
// Adding to avoid aliasing `this` for the callbacks
|
|
110
|
+
var updateActiveChild = React.useCallback(function (index) {
|
|
111
|
+
if (typeof index !== 'number') {
|
|
112
|
+
// TODO: Make sure we log this somewhere if this happens
|
|
113
|
+
setActiveChildIndex(0);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
setActiveChildIndex(index);
|
|
117
|
+
return true;
|
|
118
|
+
}, [setActiveChildIndex]);
|
|
119
|
+
var actions = useMultiBodiedExtensionActions({
|
|
120
|
+
updateActiveChild: updateActiveChild,
|
|
121
|
+
editorView: editorView,
|
|
122
|
+
getPos: getPos,
|
|
123
|
+
node: node
|
|
124
|
+
});
|
|
125
|
+
var extensionHandlerResult = React.useMemo(function () {
|
|
126
|
+
return tryExtensionHandler(actions);
|
|
127
|
+
}, [tryExtensionHandler, actions]);
|
|
128
|
+
var articleRef = React.useCallback(function (node) {
|
|
129
|
+
return handleContentDOMRef(node);
|
|
130
|
+
}, [handleContentDOMRef]);
|
|
131
|
+
var containerCss = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n border: 1px solid ", ";\n padding: ", ";\n .multiBodiedExtension-content-dom-wrapper > [data-extension-frame='true'] {\n display: none;\n }\n\n .multiBodiedExtension-content-dom-wrapper\n > [data-extension-frame='true']:nth-of-type(", ") {\n display: block;\n }\n "])), "var(--ds-border, ".concat(N30, ")"), "var(--ds-space-050, 4px)", activeChildIndex + 1);
|
|
132
|
+
return jsx("section", {
|
|
133
|
+
className: "multiBodiedExtension--container",
|
|
134
|
+
css: containerCss,
|
|
135
|
+
"data-testid": "multiBodiedExtension--container",
|
|
136
|
+
"data-active-child-index": activeChildIndex
|
|
137
|
+
}, jsx("nav", {
|
|
138
|
+
className: "multiBodiedExtension-navigation",
|
|
139
|
+
"data-testid": "multiBodiedExtension-navigation"
|
|
140
|
+
}, extensionHandlerResult), jsx("article", {
|
|
141
|
+
className: "multiBodiedExtension--frames",
|
|
142
|
+
"data-testid": "multiBodiedExtension--frames",
|
|
143
|
+
ref: articleRef
|
|
144
|
+
}));
|
|
145
|
+
};
|
|
146
|
+
export default MultiBodiedExtension;
|
|
@@ -5,8 +5,9 @@ export var getSelectedExtension = function getSelectedExtension(state) {
|
|
|
5
5
|
var _state$schema$nodes = state.schema.nodes,
|
|
6
6
|
inlineExtension = _state$schema$nodes.inlineExtension,
|
|
7
7
|
extension = _state$schema$nodes.extension,
|
|
8
|
-
bodiedExtension = _state$schema$nodes.bodiedExtension
|
|
9
|
-
|
|
8
|
+
bodiedExtension = _state$schema$nodes.bodiedExtension,
|
|
9
|
+
multiBodiedExtension = _state$schema$nodes.multiBodiedExtension;
|
|
10
|
+
var nodeTypes = [extension, bodiedExtension, inlineExtension, multiBodiedExtension];
|
|
10
11
|
return findSelectedNodeOfType(nodeTypes)(state.selection) || searchParent && findParentNodeOfType(nodeTypes)(state.selection) || undefined;
|
|
11
12
|
};
|
|
12
13
|
export var findExtensionWithLocalId = function findExtensionWithLocalId(state, localId) {
|
|
@@ -20,8 +21,9 @@ export var findExtensionWithLocalId = function findExtensionWithLocalId(state, l
|
|
|
20
21
|
var _state$schema$nodes2 = state.schema.nodes,
|
|
21
22
|
inlineExtension = _state$schema$nodes2.inlineExtension,
|
|
22
23
|
extension = _state$schema$nodes2.extension,
|
|
23
|
-
bodiedExtension = _state$schema$nodes2.bodiedExtension
|
|
24
|
-
|
|
24
|
+
bodiedExtension = _state$schema$nodes2.bodiedExtension,
|
|
25
|
+
multiBodiedExtension = _state$schema$nodes2.multiBodiedExtension;
|
|
26
|
+
var nodeTypes = [extension, bodiedExtension, inlineExtension, multiBodiedExtension];
|
|
25
27
|
var matched;
|
|
26
28
|
state.doc.descendants(function (node, pos) {
|
|
27
29
|
if (nodeTypes.includes(node.type) && node.attrs.localId === localId) {
|
|
@@ -2,4 +2,5 @@ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral
|
|
|
2
2
|
var _templateObject;
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
4
|
import { blockNodesVerticalMargin, akEditorSelectedBorderSize, akEditorDeleteBorder, akEditorDeleteBackground, SelectionStyle, getSelectionStyles, akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
|
|
5
|
-
|
|
5
|
+
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
6
|
+
export var extensionStyles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .multiBodiedExtensionView-content-wrap.", ":not(.danger) {\n ", "\n }\n\n .extensionView-content-wrap,\n .multiBodiedExtensionView-content-wrap,\n .bodiedExtensionView-content-wrap {\n margin: ", " 0;\n\n &:first-of-type {\n margin-top: 0;\n }\n\n &:last-of-type {\n margin-bottom: 0;\n }\n\n &:not(.danger).", " {\n & > span > .extension-container {\n ", "\n }\n }\n\n &.danger > span > .extension-container {\n box-shadow: 0 0 0 ", "px\n ", ";\n background-color: ", ";\n }\n\n &.inline {\n word-wrap: break-all;\n }\n }\n\n .extensionView-content-wrap .extension-container {\n overflow: hidden;\n }\n\n .bodiedExtensionView-content-wrap\n .extensionView-content-wrap\n .extension-container {\n width: 100%;\n max-width: 100%; // ensure width can't go over 100%;\n }\n\n [data-mark-type='fragment'] {\n & > .extensionView-content-wrap,\n & > .bodiedExtensionView-content-wrap {\n margin: ", " 0;\n }\n\n & > [data-mark-type='dataConsumer'] {\n & > .extensionView-content-wrap,\n & > .bodiedExtensionView-content-wrap {\n margin: ", " 0;\n }\n }\n\n &:first-child {\n & > .extensionView-content-wrap,\n & > .bodiedExtensionView-content-wrap {\n margin-top: 0;\n }\n\n & > [data-mark-type='dataConsumer'] {\n & > .extensionView-content-wrap,\n & > .bodiedExtensionView-content-wrap {\n margin-top: 0;\n }\n }\n }\n\n &:nth-last-of-type(-n + 2):not(:first-of-type) {\n & > .extensionView-content-wrap,\n & > .bodiedExtensionView-content-wrap {\n margin-bottom: 0;\n }\n\n & > [data-mark-type='dataConsumer'] {\n & > .extensionView-content-wrap,\n & > .bodiedExtensionView-content-wrap {\n margin-bottom: 0;\n }\n }\n }\n }\n"])), akEditorSelectedNodeClassName, getSelectionStyles([SelectionStyle.BoxShadow, SelectionStyle.Blanket]), blockNodesVerticalMargin, akEditorSelectedNodeClassName, getSelectionStyles([SelectionStyle.BoxShadow]), akEditorSelectedBorderSize, "var(--ds-border-danger, ".concat(akEditorDeleteBorder, ")"), "var(--ds-background-danger, ".concat(akEditorDeleteBackground, ")"), blockNodesVerticalMargin, blockNodesVerticalMargin);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export var name = "@atlaskit/editor-core";
|
|
2
|
-
export var version = "189.
|
|
2
|
+
export var version = "189.4.0";
|
|
@@ -3,6 +3,7 @@ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { ExtensionState } from './types';
|
|
4
4
|
import type { Parameters, TransformBefore, TransformAfter } from '@atlaskit/editor-common/src/extensions';
|
|
5
5
|
import type { ApplyChangeHandler } from '@atlaskit/editor-plugin-context-panel';
|
|
6
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
7
|
export declare function updateState(state: Partial<ExtensionState>): import("@atlaskit/editor-common/types").Command;
|
|
7
8
|
export declare function setEditingContextToContextPanel<T extends Parameters = Parameters>(processParametersBefore: TransformBefore<T>, processParametersAfter: TransformAfter<T>, applyChangeToContextPanel: ApplyChangeHandler | undefined): import("@atlaskit/editor-common/types").Command;
|
|
8
9
|
export declare const clearEditingContext: (applyChangeToContextPanel: ApplyChangeHandler | undefined) => import("@atlaskit/editor-common/types").Command;
|
|
@@ -10,3 +11,4 @@ export declare const forceAutoSave: (applyChangeToContextPanel: ApplyChangeHandl
|
|
|
10
11
|
export declare const updateExtensionLayout: (layout: ExtensionLayout) => import("@atlaskit/editor-common/types").Command;
|
|
11
12
|
export declare const removeExtension: () => import("@atlaskit/editor-common/types").Command;
|
|
12
13
|
export declare const removeDescendantNodes: (sourceNode?: PMNode) => import("@atlaskit/editor-common/types").Command;
|
|
14
|
+
export declare const checkAndRemoveExtensionNode: (state: EditorState, tr: Transaction) => Transaction;
|
|
@@ -3,5 +3,12 @@ type Props = {
|
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
nodeType: string;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* If inlineExtension, add zero width space to the end of the nodes and wrap with span;
|
|
8
|
+
* else wrap with a div (for multi bodied extensions)
|
|
9
|
+
*
|
|
10
|
+
* @param param0
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
6
13
|
declare const ExtensionNodeWrapper: ({ children, nodeType }: Props) => JSX.Element;
|
|
7
14
|
export default ExtensionNodeWrapper;
|