@atlaskit/editor-plugin-synced-block 2.1.0 → 2.2.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 +19 -0
- package/afm-cc/tsconfig.json +9 -0
- package/afm-dev-agents/tsconfig.json +9 -0
- package/afm-jira/tsconfig.json +9 -0
- package/afm-passionfruit/tsconfig.json +9 -0
- package/afm-post-office/tsconfig.json +9 -0
- package/afm-rovo-extension/tsconfig.json +9 -0
- package/afm-townsquare/tsconfig.json +9 -0
- package/dist/cjs/nodeviews/syncedBlock.js +118 -75
- package/dist/cjs/pm-plugins/actions.js +23 -9
- package/dist/cjs/pm-plugins/main.js +34 -8
- package/dist/cjs/pm-plugins/utils/track-sync-blocks.js +54 -0
- package/dist/cjs/pm-plugins/utils/utils.js +11 -0
- package/dist/cjs/syncedBlockPlugin.js +12 -3
- package/dist/cjs/ui/ContentComponent.js +55 -0
- package/dist/cjs/ui/SyncBlockEditorWrapper.js +38 -0
- package/dist/cjs/ui/SyncBlockRendererWrapper.js +26 -0
- package/dist/cjs/ui/floating-toolbar.js +58 -3
- package/dist/es2019/nodeviews/syncedBlock.js +103 -67
- package/dist/es2019/pm-plugins/actions.js +23 -8
- package/dist/es2019/pm-plugins/main.js +35 -8
- package/dist/es2019/pm-plugins/utils/track-sync-blocks.js +50 -0
- package/dist/es2019/pm-plugins/utils/utils.js +7 -0
- package/dist/es2019/syncedBlockPlugin.js +10 -3
- package/dist/es2019/ui/ContentComponent.js +41 -0
- package/dist/es2019/ui/SyncBlockEditorWrapper.js +28 -0
- package/dist/es2019/ui/SyncBlockRendererWrapper.js +20 -0
- package/dist/es2019/ui/floating-toolbar.js +56 -2
- package/dist/esm/nodeviews/syncedBlock.js +116 -72
- package/dist/esm/pm-plugins/actions.js +21 -8
- package/dist/esm/pm-plugins/main.js +34 -8
- package/dist/esm/pm-plugins/utils/track-sync-blocks.js +48 -0
- package/dist/esm/pm-plugins/utils/utils.js +5 -0
- package/dist/esm/syncedBlockPlugin.js +12 -3
- package/dist/esm/ui/ContentComponent.js +46 -0
- package/dist/esm/ui/SyncBlockEditorWrapper.js +31 -0
- package/dist/esm/ui/SyncBlockRendererWrapper.js +19 -0
- package/dist/esm/ui/floating-toolbar.js +57 -3
- package/dist/types/nodeviews/syncedBlock.d.ts +29 -15
- package/dist/types/pm-plugins/actions.d.ts +3 -1
- package/dist/types/pm-plugins/main.d.ts +3 -3
- package/dist/types/pm-plugins/utils/track-sync-blocks.d.ts +7 -0
- package/dist/types/pm-plugins/utils/utils.d.ts +3 -0
- package/dist/types/syncedBlockPluginType.d.ts +8 -2
- package/dist/types/ui/ContentComponent.d.ts +5 -0
- package/dist/types/ui/SyncBlockEditorWrapper.d.ts +16 -0
- package/dist/types/ui/SyncBlockRendererWrapper.d.ts +9 -0
- package/dist/types/ui/floating-toolbar.d.ts +6 -2
- package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +29 -15
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +3 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -3
- package/dist/types-ts4.5/pm-plugins/utils/track-sync-blocks.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/utils/utils.d.ts +3 -0
- package/dist/types-ts4.5/syncedBlockPluginType.d.ts +10 -2
- package/dist/types-ts4.5/ui/ContentComponent.d.ts +5 -0
- package/dist/types-ts4.5/ui/SyncBlockEditorWrapper.d.ts +16 -0
- package/dist/types-ts4.5/ui/SyncBlockRendererWrapper.d.ts +9 -0
- package/dist/types-ts4.5/ui/floating-toolbar.d.ts +6 -2
- package/package.json +8 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export const SyncBlockEditorWrapperDataId = 'sync-block-plugin-editor-wrapper';
|
|
3
|
+
const SyncBlockEditorWrapperComponent = ({
|
|
4
|
+
defaultDocument,
|
|
5
|
+
getSyncedBlockEditor,
|
|
6
|
+
popupsBoundariesElement,
|
|
7
|
+
popupsMountPoint,
|
|
8
|
+
setInnerEditorView,
|
|
9
|
+
handleContentChanges
|
|
10
|
+
}) => {
|
|
11
|
+
return (
|
|
12
|
+
/*#__PURE__*/
|
|
13
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop, @atlaskit/design-system/ensure-design-token-usage
|
|
14
|
+
React.createElement("div", {
|
|
15
|
+
"data-testid": SyncBlockEditorWrapperDataId,
|
|
16
|
+
style: {
|
|
17
|
+
border: 'purple solid 1px'
|
|
18
|
+
}
|
|
19
|
+
}, getSyncedBlockEditor({
|
|
20
|
+
popupsBoundariesElement,
|
|
21
|
+
defaultDocument,
|
|
22
|
+
popupsMountPoint,
|
|
23
|
+
onChange: value => handleContentChanges(value.state.doc),
|
|
24
|
+
onEditorReady: value => setInnerEditorView(value.editorView)
|
|
25
|
+
}))
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
export const SyncBlockEditorWrapper = /*#__PURE__*/React.memo(SyncBlockEditorWrapperComponent);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
const SyncBlockRendererWrapperDataId = 'sync-block-plugin-renderer-wrapper';
|
|
3
|
+
const SyncBlockRendererWrapperComponent = ({
|
|
4
|
+
getSyncedBlockRenderer,
|
|
5
|
+
docNode
|
|
6
|
+
}) => {
|
|
7
|
+
return (
|
|
8
|
+
/*#__PURE__*/
|
|
9
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop, @atlaskit/design-system/ensure-design-token-usage
|
|
10
|
+
React.createElement("div", {
|
|
11
|
+
"data-testid": SyncBlockRendererWrapperDataId,
|
|
12
|
+
style: {
|
|
13
|
+
border: 'blue solid 1px'
|
|
14
|
+
}
|
|
15
|
+
}, getSyncedBlockRenderer({
|
|
16
|
+
docNode
|
|
17
|
+
}))
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
export const SyncBlockRendererWrapper = /*#__PURE__*/React.memo(SyncBlockRendererWrapperComponent);
|
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
import CopyIcon from '@atlaskit/icon/core/copy';
|
|
3
|
+
import LinkExternalIcon from '@atlaskit/icon/core/link-external';
|
|
4
|
+
import { copySyncedBlockReferenceToClipboard } from '../pm-plugins/actions';
|
|
5
|
+
import { findSyncBlock } from '../pm-plugins/utils/utils';
|
|
6
|
+
export const getToolbarConfig = (state, _intl, _options = {}, _providerFactory) => {
|
|
7
|
+
const syncBlockObject = findSyncBlock(state);
|
|
8
|
+
if (!syncBlockObject) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const nodeType = state.schema.nodes.syncBlock;
|
|
12
|
+
const items = [];
|
|
13
|
+
const copyButton = {
|
|
14
|
+
id: 'editor.syncedBlock.copy',
|
|
15
|
+
type: 'button',
|
|
16
|
+
appearance: 'subtle',
|
|
17
|
+
icon: CopyIcon,
|
|
18
|
+
title: 'Copy',
|
|
19
|
+
showTitle: true,
|
|
20
|
+
tooltipContent: 'Copy reference to clipboard',
|
|
21
|
+
onClick: copySyncedBlockReferenceToClipboard
|
|
22
|
+
};
|
|
23
|
+
items.push(copyButton);
|
|
24
|
+
if (syncBlockObject.node.attrs.resourceId !== syncBlockObject.node.attrs.localId) {
|
|
25
|
+
const editSourceButton = {
|
|
26
|
+
id: 'editor.syncedBlock.editSource',
|
|
27
|
+
type: 'button',
|
|
28
|
+
appearance: 'subtle',
|
|
29
|
+
icon: LinkExternalIcon,
|
|
30
|
+
title: 'Edit source',
|
|
31
|
+
showTitle: true,
|
|
32
|
+
tooltipContent: 'Navigate to source page of the sync block',
|
|
33
|
+
disabled: true,
|
|
34
|
+
onClick: (_state, _dispatch, view) => {
|
|
35
|
+
if (!view) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// to be implemented in a follow up PR
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
items.push(editSourceButton);
|
|
43
|
+
}
|
|
44
|
+
const getDomRef = editorView => {
|
|
45
|
+
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
46
|
+
const element = findDomRefAtPos(syncBlockObject.pos, domAtPos);
|
|
47
|
+
return element;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
title: 'Synced Block floating controls',
|
|
51
|
+
getDomRef,
|
|
52
|
+
nodeType,
|
|
53
|
+
items,
|
|
54
|
+
scrollable: true,
|
|
55
|
+
groupLabel: 'Synced blocks'
|
|
56
|
+
};
|
|
3
57
|
};
|
|
@@ -4,97 +4,108 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstruct
|
|
|
4
4
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
5
|
import _get from "@babel/runtime/helpers/get";
|
|
6
6
|
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
8
7
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
9
8
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
10
9
|
function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
11
|
-
|
|
12
|
-
import React, { useMemo, useRef, useState } from 'react';
|
|
10
|
+
import React from 'react';
|
|
13
11
|
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
14
|
-
|
|
12
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
13
|
+
import { SyncBlockEditorWrapper, SyncBlockEditorWrapperDataId } from '../ui/SyncBlockEditorWrapper';
|
|
14
|
+
import { SyncBlockRendererWrapper } from '../ui/SyncBlockRendererWrapper';
|
|
15
|
+
var defaultSyncBlockEditorDocument = {
|
|
15
16
|
version: 1,
|
|
16
17
|
type: 'doc',
|
|
17
18
|
content: [{
|
|
18
19
|
type: 'paragraph',
|
|
19
20
|
content: [{
|
|
20
21
|
type: 'text',
|
|
21
|
-
text: 'This is a
|
|
22
|
+
text: 'This is a source sync block. Edit me to update the content.'
|
|
22
23
|
}]
|
|
23
24
|
}]
|
|
24
25
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
setRendererDocument = _useState2[1];
|
|
36
|
-
var onChange = function onChange(editorView, _meta) {
|
|
37
|
-
var content = editorView.state.doc.toJSON().content;
|
|
38
|
-
var rendererDocument = {
|
|
39
|
-
version: 1,
|
|
40
|
-
type: 'doc',
|
|
41
|
-
content: content
|
|
42
|
-
};
|
|
43
|
-
setRendererDocument(rendererDocument);
|
|
44
|
-
};
|
|
45
|
-
var onEditorReady = function onEditorReady(_ref2) {
|
|
46
|
-
var editorView = _ref2.editorView;
|
|
47
|
-
innerEditorView.current = editorView || null;
|
|
48
|
-
};
|
|
49
|
-
var boundariesElement = useMemo(function () {
|
|
50
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
51
|
-
return dom.closest('.fabric-editor-popup-scroll-parent');
|
|
52
|
-
}, [dom]);
|
|
53
|
-
if (!boundariesElement || !(boundariesElement instanceof HTMLElement)) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
if (!(config !== null && config !== void 0 && config.getSyncedBlockEditor) || !(config !== null && config !== void 0 && config.getSyncedBlockRenderer)) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
60
|
-
"data-testid": SyncBlockEditorWrapperDataId
|
|
61
|
-
}, config.getSyncedBlockEditor({
|
|
62
|
-
boundariesElement: boundariesElement,
|
|
63
|
-
defaultDocument: defaultSyncBlockDocument,
|
|
64
|
-
mountPoint: dom,
|
|
65
|
-
onChange: onChange,
|
|
66
|
-
onEditorReady: onEditorReady
|
|
67
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
68
|
-
style: {
|
|
69
|
-
width: '100%',
|
|
70
|
-
height: '1px',
|
|
71
|
-
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
72
|
-
backgroundColor: 'purple'
|
|
73
|
-
}
|
|
74
|
-
}), config.getSyncedBlockRenderer({
|
|
75
|
-
docNode: rendererDocument
|
|
76
|
-
}));
|
|
26
|
+
var defaultSyncBlockRendererDocument = {
|
|
27
|
+
version: 1,
|
|
28
|
+
type: 'doc',
|
|
29
|
+
content: [{
|
|
30
|
+
type: 'paragraph',
|
|
31
|
+
content: [{
|
|
32
|
+
type: 'text',
|
|
33
|
+
text: 'This is a reference sync block. Stay tuned for updates...'
|
|
34
|
+
}]
|
|
35
|
+
}]
|
|
77
36
|
};
|
|
78
37
|
var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
79
|
-
function SyncBlock() {
|
|
38
|
+
function SyncBlock(props) {
|
|
39
|
+
var _this;
|
|
80
40
|
_classCallCheck(this, SyncBlock);
|
|
81
|
-
|
|
41
|
+
_this = _callSuper(this, SyncBlock, [props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props]);
|
|
42
|
+
var _props$node$attrs = props.node.attrs,
|
|
43
|
+
resourceId = _props$node$attrs.resourceId,
|
|
44
|
+
localId = _props$node$attrs.localId;
|
|
45
|
+
// Temporary solution to identify the source
|
|
46
|
+
_this.isSource = resourceId === localId;
|
|
47
|
+
_this.options = props.options;
|
|
48
|
+
return _this;
|
|
82
49
|
}
|
|
83
50
|
_inherits(SyncBlock, _ReactNodeView);
|
|
84
51
|
return _createClass(SyncBlock, [{
|
|
85
52
|
key: "createDomRef",
|
|
86
53
|
value: function createDomRef() {
|
|
87
54
|
var domRef = document.createElement('div');
|
|
88
|
-
domRef.setAttribute('style', 'border: purple solid 1px;');
|
|
89
55
|
return domRef;
|
|
90
56
|
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "handleContentChanges",
|
|
59
|
+
value: function handleContentChanges(_updatedDoc) {
|
|
60
|
+
// write data
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "setInnerEditorView",
|
|
64
|
+
value: function setInnerEditorView(_editorView) {
|
|
65
|
+
// set inner editor view
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "renderEditor",
|
|
69
|
+
value: function renderEditor() {
|
|
70
|
+
var _this$options, _this$options2;
|
|
71
|
+
var popupsBoundariesElement = this.dom.closest('.fabric-editor-popup-scroll-parent');
|
|
72
|
+
if (!(popupsBoundariesElement instanceof HTMLElement)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.getSyncedBlockEditor)) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return /*#__PURE__*/React.createElement(SyncBlockEditorWrapper, {
|
|
79
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
80
|
+
popupsMountPoint: this.dom,
|
|
81
|
+
defaultDocument: defaultSyncBlockEditorDocument,
|
|
82
|
+
handleContentChanges: this.handleContentChanges,
|
|
83
|
+
setInnerEditorView: this.setInnerEditorView,
|
|
84
|
+
getSyncedBlockEditor: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.getSyncedBlockEditor
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "renderRenderer",
|
|
89
|
+
value: function renderRenderer() {
|
|
90
|
+
var _this$options3, _this$options4;
|
|
91
|
+
if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.getSyncedBlockRenderer)) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// get document node from data provider
|
|
96
|
+
var docNode = defaultSyncBlockRendererDocument;
|
|
97
|
+
return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
|
|
98
|
+
docNode: docNode,
|
|
99
|
+
getSyncedBlockRenderer: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.getSyncedBlockRenderer
|
|
100
|
+
});
|
|
101
|
+
}
|
|
91
102
|
}, {
|
|
92
103
|
key: "render",
|
|
93
104
|
value: function render() {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
105
|
+
if (this.isSource) {
|
|
106
|
+
return this.renderEditor();
|
|
107
|
+
}
|
|
108
|
+
return this.renderRenderer();
|
|
98
109
|
}
|
|
99
110
|
}, {
|
|
100
111
|
key: "stopEvent",
|
|
@@ -104,7 +115,17 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
104
115
|
if (!target) {
|
|
105
116
|
return false;
|
|
106
117
|
}
|
|
107
|
-
|
|
118
|
+
var isInNestedEditor = ((_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, "[data-testid=\"".concat(SyncBlockEditorWrapperDataId, "\"]"))) != null;
|
|
119
|
+
if (isInNestedEditor) {
|
|
120
|
+
this.selectNode();
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "selectNode",
|
|
127
|
+
value: function selectNode() {
|
|
128
|
+
this.selectSyncBlockNode(undefined);
|
|
108
129
|
}
|
|
109
130
|
}, {
|
|
110
131
|
key: "destroy",
|
|
@@ -113,17 +134,40 @@ var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
113
134
|
(_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
|
|
114
135
|
_superPropGet(SyncBlock, "destroy", this, 3)([]);
|
|
115
136
|
}
|
|
137
|
+
}, {
|
|
138
|
+
key: "selectSyncBlockNode",
|
|
139
|
+
value: function selectSyncBlockNode(relativeSelectionPos) {
|
|
140
|
+
var _this$reactComponentP;
|
|
141
|
+
var getPos = typeof this.getPos === 'function' ? this.getPos() : 0;
|
|
142
|
+
var selectionAPI = (_this$reactComponentP = this.reactComponentProps.api) === null || _this$reactComponentP === void 0 || (_this$reactComponentP = _this$reactComponentP.selection) === null || _this$reactComponentP === void 0 ? void 0 : _this$reactComponentP.actions;
|
|
143
|
+
if (!selectionAPI) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
var tr = selectionAPI.selectNearNode({
|
|
147
|
+
selectionRelativeToNode: relativeSelectionPos,
|
|
148
|
+
selection: NodeSelection.create(this.view.state.doc, getPos !== null && getPos !== void 0 ? getPos : 0)
|
|
149
|
+
})(this.view.state);
|
|
150
|
+
if (tr) {
|
|
151
|
+
this.view.dispatch(tr);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
116
154
|
}]);
|
|
117
155
|
}(ReactNodeView);
|
|
118
|
-
export var syncBlockNodeView = function syncBlockNodeView(
|
|
119
|
-
var
|
|
120
|
-
pmPluginFactoryParams =
|
|
156
|
+
export var syncBlockNodeView = function syncBlockNodeView(_ref) {
|
|
157
|
+
var options = _ref.options,
|
|
158
|
+
pmPluginFactoryParams = _ref.pmPluginFactoryParams,
|
|
159
|
+
api = _ref.api;
|
|
121
160
|
return function (node, view, getPos) {
|
|
122
161
|
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
123
162
|
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
163
|
+
return new SyncBlock({
|
|
164
|
+
api: api,
|
|
165
|
+
options: options,
|
|
166
|
+
node: node,
|
|
167
|
+
view: view,
|
|
168
|
+
getPos: getPos,
|
|
169
|
+
portalProviderAPI: portalProviderAPI,
|
|
170
|
+
eventDispatcher: eventDispatcher
|
|
171
|
+
}).init();
|
|
128
172
|
};
|
|
129
173
|
};
|
|
@@ -1,19 +1,32 @@
|
|
|
1
|
+
import uuid from 'uuid';
|
|
2
|
+
import { toDOM, copyDomNode } from '@atlaskit/editor-common/copy-button';
|
|
3
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
1
4
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
-
var getRandomId = function getRandomId() {
|
|
3
|
-
if (!globalThis.crypto || typeof globalThis.crypto.randomUUID !== 'function') {
|
|
4
|
-
return new Date().toISOString();
|
|
5
|
-
}
|
|
6
|
-
return globalThis.crypto.randomUUID();
|
|
7
|
-
};
|
|
8
5
|
export var createSyncedBlock = function createSyncedBlock(state) {
|
|
6
|
+
var id = uuid();
|
|
9
7
|
var tr = state.tr;
|
|
10
8
|
// const { breakout } = state.schema.marks;
|
|
11
9
|
var node = state.schema.nodes.syncBlock.createChecked({
|
|
12
|
-
resourceId:
|
|
13
|
-
localId:
|
|
10
|
+
resourceId: id,
|
|
11
|
+
localId: id
|
|
14
12
|
}, null
|
|
15
13
|
// [breakout.create({ mode: 'wide' })],
|
|
16
14
|
);
|
|
17
15
|
safeInsert(node)(tr);
|
|
18
16
|
return tr;
|
|
17
|
+
};
|
|
18
|
+
export var copySyncedBlockReferenceToClipboard = function copySyncedBlockReferenceToClipboard(state, _dispatch, _view) {
|
|
19
|
+
var schema = state.schema,
|
|
20
|
+
selection = state.selection;
|
|
21
|
+
if (selection instanceof NodeSelection) {
|
|
22
|
+
var nodeType = selection.node.type;
|
|
23
|
+
var domNode = toDOM(selection.node, schema);
|
|
24
|
+
// clear local-id
|
|
25
|
+
if (domNode instanceof HTMLElement) {
|
|
26
|
+
domNode.setAttribute('data-local-id', '');
|
|
27
|
+
}
|
|
28
|
+
copyDomNode(domNode, nodeType, selection);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
19
32
|
};
|
|
@@ -1,32 +1,58 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
|
|
4
|
+
import { trackSyncBlocks } from './utils/track-sync-blocks';
|
|
4
5
|
export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
5
6
|
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
7
8
|
|
|
8
|
-
export var createPlugin = function createPlugin(
|
|
9
|
+
export var createPlugin = function createPlugin(options, pmPluginFactoryParams, syncBlockStore, api) {
|
|
9
10
|
return new SafePlugin({
|
|
10
11
|
key: syncedBlockPluginKey,
|
|
11
12
|
state: {
|
|
12
13
|
init: function init() {
|
|
13
14
|
return {};
|
|
14
15
|
},
|
|
15
|
-
apply: function apply(
|
|
16
|
-
var meta = tr.getMeta(syncedBlockPluginKey);
|
|
17
|
-
if (meta) {
|
|
18
|
-
return meta;
|
|
19
|
-
}
|
|
16
|
+
apply: function apply(_tr, currentPluginState) {
|
|
20
17
|
return currentPluginState;
|
|
21
18
|
}
|
|
22
19
|
},
|
|
23
20
|
props: {
|
|
24
21
|
nodeViews: {
|
|
25
22
|
syncBlock: lazySyncBlockView({
|
|
26
|
-
|
|
27
|
-
pmPluginFactoryParams: pmPluginFactoryParams
|
|
23
|
+
options: options,
|
|
24
|
+
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
25
|
+
api: api
|
|
28
26
|
})
|
|
29
27
|
}
|
|
28
|
+
},
|
|
29
|
+
view: function view(editorView) {
|
|
30
|
+
syncBlockStore.setEditorView(editorView);
|
|
31
|
+
return {
|
|
32
|
+
destroy: function destroy() {
|
|
33
|
+
syncBlockStore.setEditorView(undefined);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
filterTransaction: function filterTransaction(tr, state) {
|
|
38
|
+
// Ignore transactions that don't change the document
|
|
39
|
+
// or are from remote (collab) or already confirmed sync block deletion
|
|
40
|
+
// We only care about local changes that change the document
|
|
41
|
+
// and are not yet confirmed for sync block deletion
|
|
42
|
+
if (!tr.docChanged || !(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.requireConfirmationBeforeDelete()) || Boolean(tr.getMeta('isRemote')) || Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'))) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
var _trackSyncBlocks = trackSyncBlocks(syncBlockStore, tr, state),
|
|
46
|
+
removed = _trackSyncBlocks.removed;
|
|
47
|
+
if (removed.length > 0) {
|
|
48
|
+
// If there are source sync blocks being removed, and we need to confirm with user before deleting,
|
|
49
|
+
// we block the transaction here, and wait for user confirmation to proceed with deletion.
|
|
50
|
+
// See editor-common/src/sync-block/sync-block-store-manager.ts for how we handle user confirmation and
|
|
51
|
+
// proceed with deletion.
|
|
52
|
+
syncBlockStore.deleteSyncBlocksWithConfirmation(tr, removed);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
30
56
|
}
|
|
31
57
|
});
|
|
32
58
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
2
|
+
export var trackSyncBlocks = function trackSyncBlocks(storeManager, tr, state) {
|
|
3
|
+
var sourceSyncBlockRemoved = {};
|
|
4
|
+
var sourceSyncBlockAdded = {};
|
|
5
|
+
tr.steps.map(function (step) {
|
|
6
|
+
if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
|
|
7
|
+
var from = step.from,
|
|
8
|
+
to = step.to;
|
|
9
|
+
// replaced a range, check for deleted syncBlock
|
|
10
|
+
if (from !== to) {
|
|
11
|
+
state.doc.nodesBetween(step.from, step.to, function (node) {
|
|
12
|
+
if (storeManager.isSourceBlock(node)) {
|
|
13
|
+
if (sourceSyncBlockAdded[node.attrs.localId]) {
|
|
14
|
+
// If a source block added and then removed in the same transaction,
|
|
15
|
+
// we treat it as no-op.
|
|
16
|
+
delete sourceSyncBlockAdded[node.attrs.localId];
|
|
17
|
+
} else {
|
|
18
|
+
sourceSyncBlockRemoved[node.attrs.localId] = node.attrs;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// we don't need to go deeper
|
|
22
|
+
return false;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// replaced content, check for inserted syncBlock
|
|
27
|
+
if (step.slice.content.size > 0) {
|
|
28
|
+
step.slice.content.nodesBetween(0, step.slice.content.size, function (node) {
|
|
29
|
+
if (storeManager.isSourceBlock(node)) {
|
|
30
|
+
if (sourceSyncBlockRemoved[node.attrs.localId]) {
|
|
31
|
+
// If a source block is removed and added back in the same transaction,
|
|
32
|
+
// we treat it as no-op.
|
|
33
|
+
delete sourceSyncBlockRemoved[node.attrs.localId];
|
|
34
|
+
} else {
|
|
35
|
+
sourceSyncBlockAdded[node.attrs.localId] = node.attrs;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// we don't need to go deeper
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
removed: Object.values(sourceSyncBlockRemoved),
|
|
46
|
+
added: Object.values(sourceSyncBlockAdded)
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
export var findSyncBlock = function findSyncBlock(state, selection) {
|
|
3
|
+
var syncBlock = state.schema.nodes.syncBlock;
|
|
4
|
+
return findSelectedNodeOfType(syncBlock)(selection || state.selection) || findParentNodeOfType(syncBlock)(selection || state.selection);
|
|
5
|
+
};
|
|
@@ -4,9 +4,11 @@ import { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
|
|
|
4
4
|
import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
|
|
5
5
|
import { createSyncedBlock } from './pm-plugins/actions';
|
|
6
6
|
import { createPlugin } from './pm-plugins/main';
|
|
7
|
+
import { ContentComponent } from './ui/ContentComponent';
|
|
7
8
|
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
8
9
|
export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
9
|
-
var config = _ref.config
|
|
10
|
+
var config = _ref.config,
|
|
11
|
+
api = _ref.api;
|
|
10
12
|
var syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
|
|
11
13
|
return {
|
|
12
14
|
name: 'syncedBlock',
|
|
@@ -20,7 +22,7 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
|
20
22
|
return [{
|
|
21
23
|
name: 'syncedBlockPlugin',
|
|
22
24
|
plugin: function plugin(params) {
|
|
23
|
-
return createPlugin(config, params, syncBlockStore);
|
|
25
|
+
return createPlugin(config, params, syncBlockStore, api);
|
|
24
26
|
}
|
|
25
27
|
}];
|
|
26
28
|
},
|
|
@@ -43,7 +45,14 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
|
43
45
|
}
|
|
44
46
|
}];
|
|
45
47
|
},
|
|
46
|
-
floatingToolbar:
|
|
48
|
+
floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
|
|
49
|
+
return getToolbarConfig(state, intl, config, providerFactory);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
contentComponent: function contentComponent() {
|
|
53
|
+
return /*#__PURE__*/React.createElement(ContentComponent, {
|
|
54
|
+
syncBlockStoreManager: syncBlockStore
|
|
55
|
+
});
|
|
47
56
|
}
|
|
48
57
|
};
|
|
49
58
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import Button from '@atlaskit/button/new';
|
|
4
|
+
import ModalDialog, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
|
|
5
|
+
export var ContentComponent = function ContentComponent(_ref) {
|
|
6
|
+
var syncBlockStoreManager = _ref.syncBlockStoreManager;
|
|
7
|
+
var _useState = useState(false),
|
|
8
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
9
|
+
isOpen = _useState2[0],
|
|
10
|
+
setIsOpen = _useState2[1];
|
|
11
|
+
var resolverRef = React.useRef(undefined);
|
|
12
|
+
var handleClose = useCallback(function (confirm) {
|
|
13
|
+
return function () {
|
|
14
|
+
if (resolverRef.current) {
|
|
15
|
+
resolverRef.current(confirm);
|
|
16
|
+
resolverRef.current = undefined;
|
|
17
|
+
}
|
|
18
|
+
setIsOpen(false);
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
var confirmationCallback = useCallback(function () {
|
|
22
|
+
setIsOpen(true);
|
|
23
|
+
var confirmedPromise = new Promise(function (resolve) {
|
|
24
|
+
resolverRef.current = resolve;
|
|
25
|
+
});
|
|
26
|
+
return confirmedPromise;
|
|
27
|
+
}, []);
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
var unregister = syncBlockStoreManager.registerConfirmationCallback(confirmationCallback);
|
|
30
|
+
return function () {
|
|
31
|
+
unregister();
|
|
32
|
+
};
|
|
33
|
+
}, [syncBlockStoreManager, confirmationCallback]);
|
|
34
|
+
return /*#__PURE__*/React.createElement(ModalTransition, null, isOpen && /*#__PURE__*/React.createElement(ModalDialog, {
|
|
35
|
+
onClose: handleClose(false)
|
|
36
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, {
|
|
37
|
+
hasCloseButton: true
|
|
38
|
+
}, /*#__PURE__*/React.createElement(ModalTitle, null, "Confirmation")), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement("div", null, "Are you sure you want to delete this synced block?")), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
39
|
+
appearance: "subtle",
|
|
40
|
+
onClick: handleClose(false)
|
|
41
|
+
}, "Cancel"), /*#__PURE__*/React.createElement(Button, {
|
|
42
|
+
appearance: "danger",
|
|
43
|
+
onClick: handleClose(true),
|
|
44
|
+
autoFocus: true
|
|
45
|
+
}, "Delete"))));
|
|
46
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export var SyncBlockEditorWrapperDataId = 'sync-block-plugin-editor-wrapper';
|
|
3
|
+
var SyncBlockEditorWrapperComponent = function SyncBlockEditorWrapperComponent(_ref) {
|
|
4
|
+
var defaultDocument = _ref.defaultDocument,
|
|
5
|
+
getSyncedBlockEditor = _ref.getSyncedBlockEditor,
|
|
6
|
+
popupsBoundariesElement = _ref.popupsBoundariesElement,
|
|
7
|
+
popupsMountPoint = _ref.popupsMountPoint,
|
|
8
|
+
setInnerEditorView = _ref.setInnerEditorView,
|
|
9
|
+
handleContentChanges = _ref.handleContentChanges;
|
|
10
|
+
return (
|
|
11
|
+
/*#__PURE__*/
|
|
12
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop, @atlaskit/design-system/ensure-design-token-usage
|
|
13
|
+
React.createElement("div", {
|
|
14
|
+
"data-testid": SyncBlockEditorWrapperDataId,
|
|
15
|
+
style: {
|
|
16
|
+
border: 'purple solid 1px'
|
|
17
|
+
}
|
|
18
|
+
}, getSyncedBlockEditor({
|
|
19
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
20
|
+
defaultDocument: defaultDocument,
|
|
21
|
+
popupsMountPoint: popupsMountPoint,
|
|
22
|
+
onChange: function onChange(value) {
|
|
23
|
+
return handleContentChanges(value.state.doc);
|
|
24
|
+
},
|
|
25
|
+
onEditorReady: function onEditorReady(value) {
|
|
26
|
+
return setInnerEditorView(value.editorView);
|
|
27
|
+
}
|
|
28
|
+
}))
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
export var SyncBlockEditorWrapper = /*#__PURE__*/React.memo(SyncBlockEditorWrapperComponent);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
var SyncBlockRendererWrapperDataId = 'sync-block-plugin-renderer-wrapper';
|
|
3
|
+
var SyncBlockRendererWrapperComponent = function SyncBlockRendererWrapperComponent(_ref) {
|
|
4
|
+
var getSyncedBlockRenderer = _ref.getSyncedBlockRenderer,
|
|
5
|
+
docNode = _ref.docNode;
|
|
6
|
+
return (
|
|
7
|
+
/*#__PURE__*/
|
|
8
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop, @atlaskit/design-system/ensure-design-token-usage
|
|
9
|
+
React.createElement("div", {
|
|
10
|
+
"data-testid": SyncBlockRendererWrapperDataId,
|
|
11
|
+
style: {
|
|
12
|
+
border: 'blue solid 1px'
|
|
13
|
+
}
|
|
14
|
+
}, getSyncedBlockRenderer({
|
|
15
|
+
docNode: docNode
|
|
16
|
+
}))
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
export var SyncBlockRendererWrapper = /*#__PURE__*/React.memo(SyncBlockRendererWrapperComponent);
|