@atlaskit/editor-plugin-synced-block 1.0.0 → 2.0.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 +8 -16
- package/afm-cc/tsconfig.json +0 -12
- package/afm-dev-agents/tsconfig.json +0 -12
- package/afm-jira/tsconfig.json +0 -12
- package/afm-passionfruit/tsconfig.json +0 -12
- package/afm-post-office/tsconfig.json +0 -12
- package/afm-rovo-extension/tsconfig.json +0 -12
- package/afm-townsquare/tsconfig.json +0 -12
- package/dist/cjs/nodeviews/lazySyncedBlock.js +26 -0
- package/dist/cjs/nodeviews/syncedBlock.js +137 -0
- package/dist/cjs/pm-plugins/actions.js +25 -0
- package/dist/cjs/pm-plugins/main.js +10 -22
- package/dist/cjs/syncedBlockPlugin.js +35 -5
- package/dist/cjs/ui/floating-toolbar.js +11 -0
- package/dist/es2019/nodeviews/lazySyncedBlock.js +16 -0
- package/dist/es2019/nodeviews/syncedBlock.js +105 -0
- package/dist/es2019/pm-plugins/actions.js +19 -0
- package/dist/es2019/pm-plugins/main.js +10 -25
- package/dist/es2019/syncedBlockPlugin.js +38 -15
- package/dist/es2019/ui/floating-toolbar.js +3 -0
- package/dist/esm/nodeviews/lazySyncedBlock.js +15 -0
- package/dist/esm/nodeviews/syncedBlock.js +129 -0
- package/dist/esm/pm-plugins/actions.js +19 -0
- package/dist/esm/pm-plugins/main.js +10 -22
- package/dist/esm/syncedBlockPlugin.js +35 -5
- package/dist/esm/ui/floating-toolbar.js +5 -0
- package/dist/types/index.d.ts +1 -2
- package/dist/types/nodeviews/lazySyncedBlock.d.ts +3 -0
- package/dist/types/nodeviews/syncedBlock.d.ts +28 -0
- package/dist/types/pm-plugins/actions.d.ts +2 -0
- package/dist/types/pm-plugins/main.d.ts +3 -1
- package/dist/types/syncedBlockPluginType.d.ts +36 -1
- package/dist/types/ui/floating-toolbar.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +1 -2
- package/dist/types-ts4.5/nodeviews/lazySyncedBlock.d.ts +3 -0
- package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +28 -0
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -1
- package/dist/types-ts4.5/syncedBlockPluginType.d.ts +36 -1
- package/dist/types-ts4.5/ui/floating-toolbar.d.ts +2 -0
- package/package.json +5 -9
- package/SyncedBlock/package.json +0 -15
- package/dist/cjs/pm-plugins/SyncClient.js +0 -167
- package/dist/cjs/pm-plugins/utils.js +0 -19
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/ui/extensions/synced-block/components/GlobalStyles.js +0 -25
- package/dist/cjs/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -25
- package/dist/cjs/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -25
- package/dist/cjs/ui/extensions/synced-block/constants.js +0 -32
- package/dist/cjs/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -11
- package/dist/cjs/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -29
- package/dist/cjs/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -121
- package/dist/cjs/ui/extensions/synced-block/index.js +0 -19
- package/dist/cjs/ui/extensions/synced-block/manifest.js +0 -281
- package/dist/cjs/ui/extensions/synced-block/utils/ari.js +0 -29
- package/dist/cjs/ui/extensions/synced-block/utils/content-property.js +0 -159
- package/dist/cjs/ui/extensions/synced-block/utils/synced-block.js +0 -65
- package/dist/es2019/pm-plugins/SyncClient.js +0 -102
- package/dist/es2019/pm-plugins/utils.js +0 -13
- package/dist/es2019/types/index.js +0 -0
- package/dist/es2019/ui/extensions/synced-block/components/GlobalStyles.js +0 -18
- package/dist/es2019/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -19
- package/dist/es2019/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -19
- package/dist/es2019/ui/extensions/synced-block/constants.js +0 -26
- package/dist/es2019/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -5
- package/dist/es2019/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -24
- package/dist/es2019/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -107
- package/dist/es2019/ui/extensions/synced-block/index.js +0 -5
- package/dist/es2019/ui/extensions/synced-block/manifest.js +0 -172
- package/dist/es2019/ui/extensions/synced-block/utils/ari.js +0 -19
- package/dist/es2019/ui/extensions/synced-block/utils/content-property.js +0 -108
- package/dist/es2019/ui/extensions/synced-block/utils/synced-block.js +0 -57
- package/dist/esm/pm-plugins/SyncClient.js +0 -160
- package/dist/esm/pm-plugins/utils.js +0 -13
- package/dist/esm/types/index.js +0 -0
- package/dist/esm/ui/extensions/synced-block/components/GlobalStyles.js +0 -18
- package/dist/esm/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -18
- package/dist/esm/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -18
- package/dist/esm/ui/extensions/synced-block/constants.js +0 -26
- package/dist/esm/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -5
- package/dist/esm/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -23
- package/dist/esm/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -114
- package/dist/esm/ui/extensions/synced-block/index.js +0 -5
- package/dist/esm/ui/extensions/synced-block/manifest.js +0 -274
- package/dist/esm/ui/extensions/synced-block/utils/ari.js +0 -23
- package/dist/esm/ui/extensions/synced-block/utils/content-property.js +0 -153
- package/dist/esm/ui/extensions/synced-block/utils/synced-block.js +0 -58
- package/dist/types/pm-plugins/SyncClient.d.ts +0 -14
- package/dist/types/pm-plugins/utils.d.ts +0 -5
- package/dist/types/types/index.d.ts +0 -3
- package/dist/types/ui/extensions/synced-block/components/GlobalStyles.d.ts +0 -6
- package/dist/types/ui/extensions/synced-block/components/SyncedBlockLiveView.d.ts +0 -7
- package/dist/types/ui/extensions/synced-block/components/SyncedBlockRenderer.d.ts +0 -7
- package/dist/types/ui/extensions/synced-block/constants.d.ts +0 -8
- package/dist/types/ui/extensions/synced-block/getSyncedBlockExtensionProvider.d.ts +0 -3
- package/dist/types/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.d.ts +0 -6
- package/dist/types/ui/extensions/synced-block/hooks/usePollContentProperty.d.ts +0 -7
- package/dist/types/ui/extensions/synced-block/index.d.ts +0 -2
- package/dist/types/ui/extensions/synced-block/manifest.d.ts +0 -3
- package/dist/types/ui/extensions/synced-block/utils/ari.d.ts +0 -4
- package/dist/types/ui/extensions/synced-block/utils/content-property.d.ts +0 -33
- package/dist/types/ui/extensions/synced-block/utils/synced-block.d.ts +0 -24
- package/dist/types-ts4.5/pm-plugins/SyncClient.d.ts +0 -14
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +0 -5
- package/dist/types-ts4.5/types/index.d.ts +0 -3
- package/dist/types-ts4.5/ui/extensions/synced-block/components/GlobalStyles.d.ts +0 -6
- package/dist/types-ts4.5/ui/extensions/synced-block/components/SyncedBlockLiveView.d.ts +0 -7
- package/dist/types-ts4.5/ui/extensions/synced-block/components/SyncedBlockRenderer.d.ts +0 -7
- package/dist/types-ts4.5/ui/extensions/synced-block/constants.d.ts +0 -8
- package/dist/types-ts4.5/ui/extensions/synced-block/getSyncedBlockExtensionProvider.d.ts +0 -3
- package/dist/types-ts4.5/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.d.ts +0 -6
- package/dist/types-ts4.5/ui/extensions/synced-block/hooks/usePollContentProperty.d.ts +0 -7
- package/dist/types-ts4.5/ui/extensions/synced-block/index.d.ts +0 -2
- package/dist/types-ts4.5/ui/extensions/synced-block/manifest.d.ts +0 -3
- package/dist/types-ts4.5/ui/extensions/synced-block/utils/ari.d.ts +0 -4
- package/dist/types-ts4.5/ui/extensions/synced-block/utils/content-property.d.ts +0 -33
- package/dist/types-ts4.5/ui/extensions/synced-block/utils/synced-block.d.ts +0 -24
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import {
|
|
4
|
-
import { findSyncedBlockParent } from './utils';
|
|
3
|
+
import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
|
|
5
4
|
export const syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
6
5
|
|
|
7
6
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
8
7
|
|
|
9
|
-
export const createPlugin = () => {
|
|
10
|
-
const syncClient = new SyncClient();
|
|
8
|
+
export const createPlugin = (config, pmPluginFactoryParams) => {
|
|
11
9
|
return new SafePlugin({
|
|
12
10
|
key: syncedBlockPluginKey,
|
|
13
11
|
state: {
|
|
@@ -15,33 +13,20 @@ export const createPlugin = () => {
|
|
|
15
13
|
return {};
|
|
16
14
|
},
|
|
17
15
|
apply: (tr, currentPluginState) => {
|
|
18
|
-
if (tr.docChanged) {
|
|
19
|
-
const $pos = tr.selection.$from;
|
|
20
|
-
const syncedBlockParent = findSyncedBlockParent($pos);
|
|
21
|
-
if (syncedBlockParent) {
|
|
22
|
-
const {
|
|
23
|
-
node,
|
|
24
|
-
attributes
|
|
25
|
-
} = syncedBlockParent;
|
|
26
|
-
const {
|
|
27
|
-
sourceDocumentAri,
|
|
28
|
-
contentAri,
|
|
29
|
-
contentPropertyKey
|
|
30
|
-
} = attributes.parameters;
|
|
31
|
-
syncClient.syncContent({
|
|
32
|
-
sourceDocumentAri,
|
|
33
|
-
contentAri,
|
|
34
|
-
contentPropertyKey,
|
|
35
|
-
node
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
16
|
const meta = tr.getMeta(syncedBlockPluginKey);
|
|
40
17
|
if (meta) {
|
|
41
18
|
return meta;
|
|
42
19
|
}
|
|
43
20
|
return currentPluginState;
|
|
44
21
|
}
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
nodeViews: {
|
|
25
|
+
syncBlock: lazySyncBlockView({
|
|
26
|
+
config,
|
|
27
|
+
pmPluginFactoryParams
|
|
28
|
+
})
|
|
29
|
+
}
|
|
45
30
|
}
|
|
46
31
|
});
|
|
47
32
|
};
|
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { syncBlock } from '@atlaskit/adf-schema';
|
|
3
|
+
import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
|
|
4
|
+
import { createSyncedBlock } from './pm-plugins/actions';
|
|
2
5
|
import { createPlugin } from './pm-plugins/main';
|
|
3
|
-
import {
|
|
4
|
-
export const syncedBlockPlugin = (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
7
|
+
export const syncedBlockPlugin = ({
|
|
8
|
+
config
|
|
9
|
+
}) => ({
|
|
10
|
+
name: 'syncedBlock',
|
|
11
|
+
nodes() {
|
|
12
|
+
return [{
|
|
13
|
+
name: 'syncBlock',
|
|
14
|
+
node: syncBlock
|
|
15
|
+
}];
|
|
16
|
+
},
|
|
17
|
+
pmPlugins() {
|
|
18
|
+
return [{
|
|
19
|
+
name: 'syncedBlockPlugin',
|
|
20
|
+
plugin: params => createPlugin(config, params)
|
|
21
|
+
}];
|
|
22
|
+
},
|
|
23
|
+
pluginsOptions: {
|
|
24
|
+
quickInsert: () => [{
|
|
25
|
+
id: 'syncBlock',
|
|
26
|
+
title: 'Synced Block',
|
|
27
|
+
description: 'Create a synced block',
|
|
28
|
+
priority: 800,
|
|
29
|
+
keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block'],
|
|
30
|
+
keyshortcut: '',
|
|
31
|
+
icon: () => /*#__PURE__*/React.createElement(SmartLinkIcon, {
|
|
32
|
+
label: "Synced Block"
|
|
33
|
+
}),
|
|
34
|
+
action: (_insert, state) => {
|
|
35
|
+
return createSyncedBlock(state);
|
|
36
|
+
}
|
|
37
|
+
}],
|
|
38
|
+
floatingToolbar: getToolbarConfig()
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
|
|
2
|
+
export var lazySyncBlockView = function lazySyncBlockView(props) {
|
|
3
|
+
return withLazyLoading({
|
|
4
|
+
nodeName: 'syncBlock',
|
|
5
|
+
getNodeViewOptions: function getNodeViewOptions() {},
|
|
6
|
+
loader: function loader() {
|
|
7
|
+
var result = import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-synced-block-nodeview" */
|
|
8
|
+
'./syncedBlock').then(function (_ref) {
|
|
9
|
+
var syncBlockNodeView = _ref.syncBlockNodeView;
|
|
10
|
+
return syncBlockNodeView(props);
|
|
11
|
+
});
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _get from "@babel/runtime/helpers/get";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
8
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
9
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
10
|
+
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
|
+
/* eslint-disable @atlaskit/ui-styling-standard/enforce-style-prop */
|
|
12
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
13
|
+
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
14
|
+
export var defaultSyncBlockDocument = {
|
|
15
|
+
version: 1,
|
|
16
|
+
type: 'doc',
|
|
17
|
+
content: [{
|
|
18
|
+
type: 'paragraph',
|
|
19
|
+
content: [{
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: 'This is a synced block. Edit the source to update the content.'
|
|
22
|
+
}]
|
|
23
|
+
}]
|
|
24
|
+
};
|
|
25
|
+
var SyncBlockEditorWrapperDataId = 'sync-block-plugin-editor-wrapper';
|
|
26
|
+
export var SyncBlockPluginComponent = function SyncBlockPluginComponent(_ref) {
|
|
27
|
+
var config = _ref.config,
|
|
28
|
+
dom = _ref.dom;
|
|
29
|
+
var innerEditorView = useRef(null);
|
|
30
|
+
|
|
31
|
+
/* Tmp solution to demonstrate the synced block renderer */
|
|
32
|
+
var _useState = useState(defaultSyncBlockDocument),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
rendererDocument = _useState2[0],
|
|
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
|
+
}));
|
|
77
|
+
};
|
|
78
|
+
var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
79
|
+
function SyncBlock() {
|
|
80
|
+
_classCallCheck(this, SyncBlock);
|
|
81
|
+
return _callSuper(this, SyncBlock, arguments);
|
|
82
|
+
}
|
|
83
|
+
_inherits(SyncBlock, _ReactNodeView);
|
|
84
|
+
return _createClass(SyncBlock, [{
|
|
85
|
+
key: "createDomRef",
|
|
86
|
+
value: function createDomRef() {
|
|
87
|
+
var domRef = document.createElement('div');
|
|
88
|
+
domRef.setAttribute('style', 'border: purple solid 1px;');
|
|
89
|
+
return domRef;
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
key: "render",
|
|
93
|
+
value: function render() {
|
|
94
|
+
return /*#__PURE__*/React.createElement(SyncBlockPluginComponent, {
|
|
95
|
+
config: this.reactComponentProps.config,
|
|
96
|
+
dom: this.dom
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "stopEvent",
|
|
101
|
+
value: function stopEvent(event) {
|
|
102
|
+
var _target$closest;
|
|
103
|
+
var target = event.target;
|
|
104
|
+
if (!target) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return ((_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, "[data-testid=\"".concat(SyncBlockEditorWrapperDataId, "\"]"))) != null;
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "destroy",
|
|
111
|
+
value: function destroy() {
|
|
112
|
+
var _this$unsubscribe;
|
|
113
|
+
(_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
|
|
114
|
+
_superPropGet(SyncBlock, "destroy", this, 3)([]);
|
|
115
|
+
}
|
|
116
|
+
}]);
|
|
117
|
+
}(ReactNodeView);
|
|
118
|
+
export var syncBlockNodeView = function syncBlockNodeView(_ref3) {
|
|
119
|
+
var config = _ref3.config,
|
|
120
|
+
pmPluginFactoryParams = _ref3.pmPluginFactoryParams;
|
|
121
|
+
return function (node, view, getPos) {
|
|
122
|
+
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
123
|
+
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
124
|
+
var reactComponentProps = {
|
|
125
|
+
config: config
|
|
126
|
+
};
|
|
127
|
+
return new SyncBlock(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
|
|
128
|
+
};
|
|
129
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
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
|
+
export var createSyncedBlock = function createSyncedBlock(state) {
|
|
9
|
+
var tr = state.tr;
|
|
10
|
+
// const { breakout } = state.schema.marks;
|
|
11
|
+
var node = state.schema.nodes.syncBlock.createChecked({
|
|
12
|
+
resourceId: getRandomId(),
|
|
13
|
+
localId: getRandomId()
|
|
14
|
+
}, null
|
|
15
|
+
// [breakout.create({ mode: 'wide' })],
|
|
16
|
+
);
|
|
17
|
+
safeInsert(node)(tr);
|
|
18
|
+
return tr;
|
|
19
|
+
};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import {
|
|
4
|
-
import { findSyncedBlockParent } from './utils';
|
|
3
|
+
import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
|
|
5
4
|
export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
6
5
|
|
|
7
6
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
8
7
|
|
|
9
|
-
export var createPlugin = function createPlugin() {
|
|
10
|
-
var syncClient = new SyncClient();
|
|
8
|
+
export var createPlugin = function createPlugin(config, pmPluginFactoryParams) {
|
|
11
9
|
return new SafePlugin({
|
|
12
10
|
key: syncedBlockPluginKey,
|
|
13
11
|
state: {
|
|
@@ -15,30 +13,20 @@ export var createPlugin = function createPlugin() {
|
|
|
15
13
|
return {};
|
|
16
14
|
},
|
|
17
15
|
apply: function apply(tr, currentPluginState) {
|
|
18
|
-
if (tr.docChanged) {
|
|
19
|
-
var $pos = tr.selection.$from;
|
|
20
|
-
var syncedBlockParent = findSyncedBlockParent($pos);
|
|
21
|
-
if (syncedBlockParent) {
|
|
22
|
-
var node = syncedBlockParent.node,
|
|
23
|
-
attributes = syncedBlockParent.attributes;
|
|
24
|
-
var _attributes$parameter = attributes.parameters,
|
|
25
|
-
sourceDocumentAri = _attributes$parameter.sourceDocumentAri,
|
|
26
|
-
contentAri = _attributes$parameter.contentAri,
|
|
27
|
-
contentPropertyKey = _attributes$parameter.contentPropertyKey;
|
|
28
|
-
syncClient.syncContent({
|
|
29
|
-
sourceDocumentAri: sourceDocumentAri,
|
|
30
|
-
contentAri: contentAri,
|
|
31
|
-
contentPropertyKey: contentPropertyKey,
|
|
32
|
-
node: node
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
16
|
var meta = tr.getMeta(syncedBlockPluginKey);
|
|
37
17
|
if (meta) {
|
|
38
18
|
return meta;
|
|
39
19
|
}
|
|
40
20
|
return currentPluginState;
|
|
41
21
|
}
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
nodeViews: {
|
|
25
|
+
syncBlock: lazySyncBlockView({
|
|
26
|
+
config: config,
|
|
27
|
+
pmPluginFactoryParams: pmPluginFactoryParams
|
|
28
|
+
})
|
|
29
|
+
}
|
|
42
30
|
}
|
|
43
31
|
});
|
|
44
32
|
};
|
|
@@ -1,17 +1,47 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { syncBlock } from '@atlaskit/adf-schema';
|
|
3
|
+
import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
|
|
4
|
+
import { createSyncedBlock } from './pm-plugins/actions';
|
|
2
5
|
import { createPlugin } from './pm-plugins/main';
|
|
3
|
-
import {
|
|
4
|
-
export var syncedBlockPlugin = function syncedBlockPlugin() {
|
|
6
|
+
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
7
|
+
export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
8
|
+
var config = _ref.config;
|
|
5
9
|
return {
|
|
6
10
|
name: 'syncedBlock',
|
|
11
|
+
nodes: function nodes() {
|
|
12
|
+
return [{
|
|
13
|
+
name: 'syncBlock',
|
|
14
|
+
node: syncBlock
|
|
15
|
+
}];
|
|
16
|
+
},
|
|
7
17
|
pmPlugins: function pmPlugins() {
|
|
8
18
|
return [{
|
|
9
19
|
name: 'syncedBlockPlugin',
|
|
10
|
-
plugin:
|
|
20
|
+
plugin: function plugin(params) {
|
|
21
|
+
return createPlugin(config, params);
|
|
22
|
+
}
|
|
11
23
|
}];
|
|
12
24
|
},
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
pluginsOptions: {
|
|
26
|
+
quickInsert: function quickInsert() {
|
|
27
|
+
return [{
|
|
28
|
+
id: 'syncBlock',
|
|
29
|
+
title: 'Synced Block',
|
|
30
|
+
description: 'Create a synced block',
|
|
31
|
+
priority: 800,
|
|
32
|
+
keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block'],
|
|
33
|
+
keyshortcut: '',
|
|
34
|
+
icon: function icon() {
|
|
35
|
+
return /*#__PURE__*/React.createElement(SmartLinkIcon, {
|
|
36
|
+
label: "Synced Block"
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
action: function action(_insert, state) {
|
|
40
|
+
return createSyncedBlock(state);
|
|
41
|
+
}
|
|
42
|
+
}];
|
|
43
|
+
},
|
|
44
|
+
floatingToolbar: getToolbarConfig()
|
|
15
45
|
}
|
|
16
46
|
};
|
|
17
47
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export { syncedBlockPlugin } from './syncedBlockPlugin';
|
|
2
|
-
export type { SyncedBlockPlugin } from './syncedBlockPluginType';
|
|
3
|
-
export type { SyncedBlockPluginOptions } from './types';
|
|
2
|
+
export type { SyncedBlockPlugin, SyncedBlockPluginOptions, SyncedBlockEditorProps, SyncedBlockRendererProps, } from './syncedBlockPluginType';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
3
|
+
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
4
|
+
import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
8
|
+
export type SyncBlockNodeViewProps = {
|
|
9
|
+
config: SyncedBlockPluginOptions | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare const defaultSyncBlockDocument: DocNode;
|
|
12
|
+
export declare const SyncBlockPluginComponent: ({ config, dom, }: {
|
|
13
|
+
config: SyncedBlockPluginOptions | undefined;
|
|
14
|
+
dom: HTMLElement;
|
|
15
|
+
}) => React.JSX.Element | null;
|
|
16
|
+
declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> {
|
|
17
|
+
unsubscribe: (() => void) | undefined;
|
|
18
|
+
createDomRef(): HTMLElement;
|
|
19
|
+
render(): React.JSX.Element;
|
|
20
|
+
stopEvent(event: Event): boolean;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
23
|
+
export interface SyncBlockNodeViewProperties {
|
|
24
|
+
config: SyncedBlockPluginOptions | undefined;
|
|
25
|
+
pmPluginFactoryParams: PMPluginFactoryParams;
|
|
26
|
+
}
|
|
27
|
+
export declare const syncBlockNodeView: ({ config, pmPluginFactoryParams }: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => SyncBlock;
|
|
28
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
2
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
3
5
|
export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
4
6
|
type SyncedBlockPluginState = {};
|
|
5
|
-
export declare const createPlugin: () => SafePlugin<SyncedBlockPluginState>;
|
|
7
|
+
export declare const createPlugin: (config: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams) => SafePlugin<SyncedBlockPluginState>;
|
|
6
8
|
export {};
|
|
@@ -1,2 +1,37 @@
|
|
|
1
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
1
3
|
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
|
|
4
|
+
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
5
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
6
|
+
export type SyncedBlockEditorProps = {
|
|
7
|
+
boundariesElement: HTMLElement;
|
|
8
|
+
defaultDocument: JSONDocNode;
|
|
9
|
+
mountPoint: HTMLElement;
|
|
10
|
+
onChange: (editorView: EditorView, meta: {
|
|
11
|
+
/**
|
|
12
|
+
* Indicates whether or not the change may be unnecessary to listen to (dirty
|
|
13
|
+
* changes can generally be ignored).
|
|
14
|
+
*
|
|
15
|
+
* This might be changes to media attributes for example when it gets updated
|
|
16
|
+
* due to initial setup.
|
|
17
|
+
*
|
|
18
|
+
* We still fire these events however to avoid a breaking change.
|
|
19
|
+
*/
|
|
20
|
+
isDirtyChange: boolean;
|
|
21
|
+
source: 'local' | 'remote';
|
|
22
|
+
}) => void;
|
|
23
|
+
onEditorReady: ({ editorView, eventDispatcher, }: {
|
|
24
|
+
editorView: EditorView;
|
|
25
|
+
eventDispatcher: EventDispatcher;
|
|
26
|
+
}) => void;
|
|
27
|
+
};
|
|
28
|
+
export type SyncedBlockRendererProps = {
|
|
29
|
+
docNode: DocNode;
|
|
30
|
+
};
|
|
31
|
+
export type SyncedBlockPluginOptions = {
|
|
32
|
+
getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
|
|
33
|
+
getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
34
|
+
};
|
|
35
|
+
export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
36
|
+
pluginConfiguration: SyncedBlockPluginOptions | undefined;
|
|
37
|
+
}>;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export { syncedBlockPlugin } from './syncedBlockPlugin';
|
|
2
|
-
export type { SyncedBlockPlugin } from './syncedBlockPluginType';
|
|
3
|
-
export type { SyncedBlockPluginOptions } from './types';
|
|
2
|
+
export type { SyncedBlockPlugin, SyncedBlockPluginOptions, SyncedBlockEditorProps, SyncedBlockRendererProps, } from './syncedBlockPluginType';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
3
|
+
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
4
|
+
import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
7
|
+
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
8
|
+
export type SyncBlockNodeViewProps = {
|
|
9
|
+
config: SyncedBlockPluginOptions | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare const defaultSyncBlockDocument: DocNode;
|
|
12
|
+
export declare const SyncBlockPluginComponent: ({ config, dom, }: {
|
|
13
|
+
config: SyncedBlockPluginOptions | undefined;
|
|
14
|
+
dom: HTMLElement;
|
|
15
|
+
}) => React.JSX.Element | null;
|
|
16
|
+
declare class SyncBlock extends ReactNodeView<SyncBlockNodeViewProps> {
|
|
17
|
+
unsubscribe: (() => void) | undefined;
|
|
18
|
+
createDomRef(): HTMLElement;
|
|
19
|
+
render(): React.JSX.Element;
|
|
20
|
+
stopEvent(event: Event): boolean;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
23
|
+
export interface SyncBlockNodeViewProperties {
|
|
24
|
+
config: SyncedBlockPluginOptions | undefined;
|
|
25
|
+
pmPluginFactoryParams: PMPluginFactoryParams;
|
|
26
|
+
}
|
|
27
|
+
export declare const syncBlockNodeView: ({ config, pmPluginFactoryParams }: SyncBlockNodeViewProperties) => (node: PMNode, view: EditorView, getPos: () => number | undefined) => SyncBlock;
|
|
28
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
2
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
3
5
|
export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
4
6
|
type SyncedBlockPluginState = {};
|
|
5
|
-
export declare const createPlugin: () => SafePlugin<SyncedBlockPluginState>;
|
|
7
|
+
export declare const createPlugin: (config: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams) => SafePlugin<SyncedBlockPluginState>;
|
|
6
8
|
export {};
|
|
@@ -1,2 +1,37 @@
|
|
|
1
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
1
3
|
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
|
|
4
|
+
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
5
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
6
|
+
export type SyncedBlockEditorProps = {
|
|
7
|
+
boundariesElement: HTMLElement;
|
|
8
|
+
defaultDocument: JSONDocNode;
|
|
9
|
+
mountPoint: HTMLElement;
|
|
10
|
+
onChange: (editorView: EditorView, meta: {
|
|
11
|
+
/**
|
|
12
|
+
* Indicates whether or not the change may be unnecessary to listen to (dirty
|
|
13
|
+
* changes can generally be ignored).
|
|
14
|
+
*
|
|
15
|
+
* This might be changes to media attributes for example when it gets updated
|
|
16
|
+
* due to initial setup.
|
|
17
|
+
*
|
|
18
|
+
* We still fire these events however to avoid a breaking change.
|
|
19
|
+
*/
|
|
20
|
+
isDirtyChange: boolean;
|
|
21
|
+
source: 'local' | 'remote';
|
|
22
|
+
}) => void;
|
|
23
|
+
onEditorReady: ({ editorView, eventDispatcher, }: {
|
|
24
|
+
editorView: EditorView;
|
|
25
|
+
eventDispatcher: EventDispatcher;
|
|
26
|
+
}) => void;
|
|
27
|
+
};
|
|
28
|
+
export type SyncedBlockRendererProps = {
|
|
29
|
+
docNode: DocNode;
|
|
30
|
+
};
|
|
31
|
+
export type SyncedBlockPluginOptions = {
|
|
32
|
+
getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
|
|
33
|
+
getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
34
|
+
};
|
|
35
|
+
export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
36
|
+
pluginConfiguration: SyncedBlockPluginOptions | undefined;
|
|
37
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-synced-block",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "SyncedBlock plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,18 +28,14 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"atlaskit:src": "src/index.ts",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/adf-schema": "^
|
|
32
|
-
"@atlaskit/adf-utils": "^19.21.0",
|
|
33
|
-
"@atlaskit/editor-json-transformer": "^8.27.0",
|
|
31
|
+
"@atlaskit/adf-schema": "^51.1.2",
|
|
34
32
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
35
|
-
"@atlaskit/icon": "
|
|
36
|
-
"@atlaskit/renderer": "^121.0.0",
|
|
37
|
-
"@atlaskit/tokens": "^6.1.0",
|
|
33
|
+
"@atlaskit/icon": "28.2.0",
|
|
38
34
|
"@babel/runtime": "^7.0.0",
|
|
39
|
-
"
|
|
35
|
+
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
40
36
|
},
|
|
41
37
|
"peerDependencies": {
|
|
42
|
-
"@atlaskit/editor-common": "^
|
|
38
|
+
"@atlaskit/editor-common": "^109.7.0",
|
|
43
39
|
"react": "^18.2.0"
|
|
44
40
|
},
|
|
45
41
|
"devDependencies": {
|
package/SyncedBlock/package.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@atlaskit/editor-plugin-synced-block/SyncedBlock",
|
|
3
|
-
"main": "../dist/cjs/ui/extensions/synced-block/index.js",
|
|
4
|
-
"module": "../dist/esm/ui/extensions/synced-block/index.js",
|
|
5
|
-
"module:es2019": "../dist/es2019/ui/extensions/synced-block/index.js",
|
|
6
|
-
"sideEffects": false,
|
|
7
|
-
"types": "../dist/types/ui/extensions/synced-block/index.d.ts",
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.9": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../dist/types-ts4.5/ui/extensions/synced-block/index.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|