@atlaskit/editor-plugin-synced-block 2.0.1 → 2.1.1
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 +3 -0
- package/afm-dev-agents/tsconfig.json +3 -0
- package/afm-jira/tsconfig.json +3 -0
- package/afm-passionfruit/tsconfig.json +3 -0
- package/afm-post-office/tsconfig.json +3 -0
- package/afm-rovo-extension/tsconfig.json +3 -0
- package/afm-townsquare/tsconfig.json +3 -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 +4 -3
- package/dist/cjs/pm-plugins/utils/utils.js +11 -0
- package/dist/cjs/syncedBlockPlugin.js +8 -3
- 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 +4 -3
- package/dist/es2019/pm-plugins/utils/utils.js +7 -0
- package/dist/es2019/syncedBlockPlugin.js +38 -33
- 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 +4 -3
- package/dist/esm/pm-plugins/utils/utils.js +5 -0
- package/dist/esm/syncedBlockPlugin.js +8 -3
- 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 +4 -3
- package/dist/types/pm-plugins/utils/utils.d.ts +3 -0
- package/dist/types/syncedBlockPluginType.d.ts +6 -2
- 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 +4 -3
- package/dist/types-ts4.5/pm-plugins/utils/utils.d.ts +3 -0
- package/dist/types-ts4.5/syncedBlockPluginType.d.ts +8 -2
- 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 +6 -4
|
@@ -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
|
};
|
|
@@ -5,7 +5,7 @@ export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
|
5
5
|
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
7
7
|
|
|
8
|
-
export var createPlugin = function createPlugin(
|
|
8
|
+
export var createPlugin = function createPlugin(options, pmPluginFactoryParams, _syncBlockStore, api) {
|
|
9
9
|
return new SafePlugin({
|
|
10
10
|
key: syncedBlockPluginKey,
|
|
11
11
|
state: {
|
|
@@ -23,8 +23,9 @@ export var createPlugin = function createPlugin(config, pmPluginFactoryParams) {
|
|
|
23
23
|
props: {
|
|
24
24
|
nodeViews: {
|
|
25
25
|
syncBlock: lazySyncBlockView({
|
|
26
|
-
|
|
27
|
-
pmPluginFactoryParams: pmPluginFactoryParams
|
|
26
|
+
options: options,
|
|
27
|
+
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
28
|
+
api: api
|
|
28
29
|
})
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -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
|
+
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { syncBlock } from '@atlaskit/adf-schema';
|
|
3
|
+
import { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
|
|
3
4
|
import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
|
|
4
5
|
import { createSyncedBlock } from './pm-plugins/actions';
|
|
5
6
|
import { createPlugin } from './pm-plugins/main';
|
|
6
7
|
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
7
8
|
export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
8
|
-
var config = _ref.config
|
|
9
|
+
var config = _ref.config,
|
|
10
|
+
api = _ref.api;
|
|
11
|
+
var syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
|
|
9
12
|
return {
|
|
10
13
|
name: 'syncedBlock',
|
|
11
14
|
nodes: function nodes() {
|
|
@@ -18,7 +21,7 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
|
18
21
|
return [{
|
|
19
22
|
name: 'syncedBlockPlugin',
|
|
20
23
|
plugin: function plugin(params) {
|
|
21
|
-
return createPlugin(config, params);
|
|
24
|
+
return createPlugin(config, params, syncBlockStore, api);
|
|
22
25
|
}
|
|
23
26
|
}];
|
|
24
27
|
},
|
|
@@ -41,7 +44,9 @@ export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
|
41
44
|
}
|
|
42
45
|
}];
|
|
43
46
|
},
|
|
44
|
-
floatingToolbar:
|
|
47
|
+
floatingToolbar: function floatingToolbar(state, intl, providerFactory) {
|
|
48
|
+
return getToolbarConfig(state, intl, config, providerFactory);
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
51
|
};
|
|
47
52
|
};
|
|
@@ -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);
|
|
@@ -1,5 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 var getToolbarConfig = function getToolbarConfig(state, _intl) {
|
|
7
|
+
var _options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
8
|
+
var _providerFactory = arguments.length > 3 ? arguments[3] : undefined;
|
|
9
|
+
var syncBlockObject = findSyncBlock(state);
|
|
10
|
+
if (!syncBlockObject) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
var nodeType = state.schema.nodes.syncBlock;
|
|
14
|
+
var items = [];
|
|
15
|
+
var copyButton = {
|
|
16
|
+
id: 'editor.syncedBlock.copy',
|
|
17
|
+
type: 'button',
|
|
18
|
+
appearance: 'subtle',
|
|
19
|
+
icon: CopyIcon,
|
|
20
|
+
title: 'Copy',
|
|
21
|
+
showTitle: true,
|
|
22
|
+
tooltipContent: 'Copy reference to clipboard',
|
|
23
|
+
onClick: copySyncedBlockReferenceToClipboard
|
|
24
|
+
};
|
|
25
|
+
items.push(copyButton);
|
|
26
|
+
if (syncBlockObject.node.attrs.resourceId !== syncBlockObject.node.attrs.localId) {
|
|
27
|
+
var editSourceButton = {
|
|
28
|
+
id: 'editor.syncedBlock.editSource',
|
|
29
|
+
type: 'button',
|
|
30
|
+
appearance: 'subtle',
|
|
31
|
+
icon: LinkExternalIcon,
|
|
32
|
+
title: 'Edit source',
|
|
33
|
+
showTitle: true,
|
|
34
|
+
tooltipContent: 'Navigate to source page of the sync block',
|
|
35
|
+
disabled: true,
|
|
36
|
+
onClick: function onClick(_state, _dispatch, view) {
|
|
37
|
+
if (!view) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// to be implemented in a follow up PR
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
items.push(editSourceButton);
|
|
45
|
+
}
|
|
46
|
+
var getDomRef = function getDomRef(editorView) {
|
|
47
|
+
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
48
|
+
var element = findDomRefAtPos(syncBlockObject.pos, domAtPos);
|
|
49
|
+
return element;
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
title: 'Synced Block floating controls',
|
|
53
|
+
getDomRef: getDomRef,
|
|
54
|
+
nodeType: nodeType,
|
|
55
|
+
items: items,
|
|
56
|
+
scrollable: true,
|
|
57
|
+
groupLabel: 'Synced blocks'
|
|
4
58
|
};
|
|
5
59
|
};
|
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
|
+
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal';
|
|
4
|
+
import ReactNodeView, { type getPosHandler } from '@atlaskit/editor-common/react-node-view';
|
|
5
|
+
import type { ReactComponentProps } from '@atlaskit/editor-common/react-node-view';
|
|
6
|
+
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
5
7
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
6
8
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
-
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
10
|
+
export interface SyncBlockNodeViewProps extends ReactComponentProps {
|
|
11
|
+
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
12
|
+
eventDispatcher: EventDispatcher;
|
|
13
|
+
getPos: getPosHandler;
|
|
14
|
+
isNodeNested?: boolean;
|
|
15
|
+
node: PMNode;
|
|
16
|
+
options: SyncedBlockPluginOptions | undefined;
|
|
17
|
+
portalProviderAPI: PortalProviderAPI;
|
|
18
|
+
view: EditorView;
|
|
19
|
+
}
|
|
16
20
|
declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> {
|
|
21
|
+
private isSource;
|
|
22
|
+
private options;
|
|
23
|
+
constructor(props: SyncBlockNodeViewProps);
|
|
17
24
|
unsubscribe: (() => void) | undefined;
|
|
18
25
|
createDomRef(): HTMLElement;
|
|
19
|
-
|
|
26
|
+
private handleContentChanges;
|
|
27
|
+
private setInnerEditorView;
|
|
28
|
+
private renderEditor;
|
|
29
|
+
private renderRenderer;
|
|
30
|
+
render(): React.JSX.Element | null;
|
|
20
31
|
stopEvent(event: Event): boolean;
|
|
32
|
+
selectNode(): void;
|
|
21
33
|
destroy(): void;
|
|
34
|
+
private selectSyncBlockNode;
|
|
22
35
|
}
|
|
23
36
|
export interface SyncBlockNodeViewProperties {
|
|
24
|
-
|
|
37
|
+
api?: ExtractInjectionAPI<SyncedBlockPlugin>;
|
|
38
|
+
options: SyncedBlockPluginOptions | undefined;
|
|
25
39
|
pmPluginFactoryParams: PMPluginFactoryParams;
|
|
26
40
|
}
|
|
27
|
-
export declare const syncBlockNodeView: ({
|
|
41
|
+
export declare const syncBlockNodeView: ({ options, pmPluginFactoryParams, api }: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => SyncBlock;
|
|
28
42
|
export {};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type EditorState, type Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
3
|
export declare const createSyncedBlock: (state: EditorState) => Transaction;
|
|
4
|
+
export declare const copySyncedBlockReferenceToClipboard: Command;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
|
|
3
|
+
import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
3
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
5
|
+
import type { SyncedBlockPlugin, SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
5
6
|
export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
6
7
|
type SyncedBlockPluginState = {};
|
|
7
|
-
export declare const createPlugin: (
|
|
8
|
+
export declare const createPlugin: (options: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, _syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => SafePlugin<SyncedBlockPluginState>;
|
|
8
9
|
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
export declare const findSyncBlock: (state: EditorState, selection?: Selection | null) => ReturnType<ReturnType<typeof findSelectedNodeOfType>> | ReturnType<ReturnType<typeof findParentNodeOfType>>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
|
+
import type { SyncBlockDataProvider } from '@atlaskit/editor-common/sync-block';
|
|
3
4
|
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
4
5
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
6
|
+
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
5
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
6
8
|
export type SyncedBlockEditorProps = {
|
|
7
|
-
boundariesElement: HTMLElement;
|
|
8
9
|
defaultDocument: JSONDocNode;
|
|
9
|
-
mountPoint: HTMLElement;
|
|
10
10
|
onChange: (editorView: EditorView, meta: {
|
|
11
11
|
/**
|
|
12
12
|
* Indicates whether or not the change may be unnecessary to listen to (dirty
|
|
@@ -24,14 +24,18 @@ export type SyncedBlockEditorProps = {
|
|
|
24
24
|
editorView: EditorView;
|
|
25
25
|
eventDispatcher: EventDispatcher;
|
|
26
26
|
}) => void;
|
|
27
|
+
popupsBoundariesElement: HTMLElement;
|
|
28
|
+
popupsMountPoint: HTMLElement;
|
|
27
29
|
};
|
|
28
30
|
export type SyncedBlockRendererProps = {
|
|
29
31
|
docNode: DocNode;
|
|
30
32
|
};
|
|
31
33
|
export type SyncedBlockPluginOptions = {
|
|
34
|
+
dataProvider?: SyncBlockDataProvider;
|
|
32
35
|
getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
|
|
33
36
|
getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
34
37
|
};
|
|
35
38
|
export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
39
|
+
dependencies: [SelectionPlugin];
|
|
36
40
|
pluginConfiguration: SyncedBlockPluginOptions | undefined;
|
|
37
41
|
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
3
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import type { SyncedBlockEditorProps } from '../syncedBlockPluginType';
|
|
6
|
+
type Props = {
|
|
7
|
+
defaultDocument: JSONDocNode;
|
|
8
|
+
getSyncedBlockEditor: (props: SyncedBlockEditorProps) => React.JSX.Element;
|
|
9
|
+
handleContentChanges: (updatedDoc: PMNode) => void;
|
|
10
|
+
popupsBoundariesElement: HTMLElement;
|
|
11
|
+
popupsMountPoint: HTMLElement;
|
|
12
|
+
setInnerEditorView: (editorView: EditorView) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const SyncBlockEditorWrapperDataId = "sync-block-plugin-editor-wrapper";
|
|
15
|
+
export declare const SyncBlockEditorWrapper: React.MemoExoticComponent<({ defaultDocument, getSyncedBlockEditor, popupsBoundariesElement, popupsMountPoint, setInnerEditorView, handleContentChanges, }: Props) => React.JSX.Element>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
3
|
+
import type { SyncedBlockRendererProps } from '../syncedBlockPluginType';
|
|
4
|
+
type Props = {
|
|
5
|
+
docNode: DocNode;
|
|
6
|
+
getSyncedBlockRenderer: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
7
|
+
};
|
|
8
|
+
export declare const SyncBlockRendererWrapper: React.MemoExoticComponent<({ getSyncedBlockRenderer, docNode }: Props) => React.JSX.Element>;
|
|
9
|
+
export {};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { IntlShape } from 'react-intl-next';
|
|
2
|
+
import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
|
|
3
|
+
import type { FloatingToolbarConfig } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/dist/types/state';
|
|
5
|
+
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
6
|
+
export declare const getToolbarConfig: (state: EditorState, _intl: IntlShape, _options: SyncedBlockPluginOptions | undefined, _providerFactory: ProviderFactory) => FloatingToolbarConfig | undefined;
|