@atlaskit/editor-plugin-synced-block 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +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/lazySyncedBlock.js +26 -0
- package/dist/cjs/nodeviews/syncedBlock.js +127 -10
- package/dist/cjs/pm-plugins/actions.js +25 -0
- package/dist/cjs/pm-plugins/main.js +10 -1
- package/dist/cjs/syncedBlockPlugin.js +35 -7
- package/dist/cjs/ui/floating-toolbar.js +2 -30
- package/dist/es2019/nodeviews/lazySyncedBlock.js +16 -0
- package/dist/es2019/nodeviews/syncedBlock.js +102 -7
- package/dist/es2019/pm-plugins/actions.js +19 -0
- package/dist/es2019/pm-plugins/main.js +10 -1
- package/dist/es2019/syncedBlockPlugin.js +41 -17
- package/dist/es2019/ui/floating-toolbar.js +2 -30
- package/dist/esm/nodeviews/lazySyncedBlock.js +15 -0
- package/dist/esm/nodeviews/syncedBlock.js +125 -9
- package/dist/esm/pm-plugins/actions.js +19 -0
- package/dist/esm/pm-plugins/main.js +10 -1
- package/dist/esm/syncedBlockPlugin.js +34 -7
- package/dist/esm/ui/floating-toolbar.js +2 -29
- package/dist/types/index.d.ts +1 -1
- package/dist/types/nodeviews/lazySyncedBlock.d.ts +3 -0
- package/dist/types/nodeviews/syncedBlock.d.ts +24 -7
- package/dist/types/pm-plugins/actions.d.ts +2 -0
- package/dist/types/pm-plugins/main.d.ts +4 -1
- package/dist/types/syncedBlockPluginType.d.ts +38 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/lazySyncedBlock.d.ts +3 -0
- package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +24 -7
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +4 -1
- package/dist/types-ts4.5/syncedBlockPluginType.d.ts +38 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-synced-block
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`2ce1b7efe1d2e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2ce1b7efe1d2e) -
|
|
8
|
+
EDITOR-1640 Create Sync-Block data manager scaffolding
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 2.0.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [`1a1f634a70d97`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1a1f634a70d97) -
|
|
19
|
+
Added Sync Block Editor and Sync Block Renderer
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
|
|
3
22
|
## 2.0.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/afm-cc/tsconfig.json
CHANGED
package/afm-jira/tsconfig.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.lazySyncBlockView = void 0;
|
|
8
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
|
+
var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != (0, _typeof2.default)(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
11
|
+
var lazySyncBlockView = exports.lazySyncBlockView = function lazySyncBlockView(props) {
|
|
12
|
+
return (0, _lazyNodeView.withLazyLoading)({
|
|
13
|
+
nodeName: 'syncBlock',
|
|
14
|
+
getNodeViewOptions: function getNodeViewOptions() {},
|
|
15
|
+
loader: function loader() {
|
|
16
|
+
var result = Promise.resolve().then(function () {
|
|
17
|
+
return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-synced-block-nodeview" */
|
|
18
|
+
'./syncedBlock'));
|
|
19
|
+
}).then(function (_ref) {
|
|
20
|
+
var syncBlockNodeView = _ref.syncBlockNodeView;
|
|
21
|
+
return syncBlockNodeView(props);
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
@@ -1,20 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
|
-
exports.
|
|
8
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
+
exports.syncBlockNodeView = exports.defaultSyncBlockDocument = exports.SyncBlockPluginComponent = void 0;
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
12
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
16
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
17
|
+
var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
19
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
20
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
|
+
function _superPropGet(t, o, e, r) { var p = (0, _get2.default)((0, _getPrototypeOf2.default)(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; } /* eslint-disable @atlaskit/ui-styling-standard/enforce-style-prop */
|
|
22
|
+
var defaultSyncBlockDocument = exports.defaultSyncBlockDocument = {
|
|
23
|
+
version: 1,
|
|
24
|
+
type: 'doc',
|
|
25
|
+
content: [{
|
|
26
|
+
type: 'paragraph',
|
|
27
|
+
content: [{
|
|
28
|
+
type: 'text',
|
|
29
|
+
text: 'This is a synced block. Edit the source to update the content.'
|
|
30
|
+
}]
|
|
31
|
+
}]
|
|
32
|
+
};
|
|
33
|
+
var SyncBlockEditorWrapperDataId = 'sync-block-plugin-editor-wrapper';
|
|
34
|
+
var SyncBlockPluginComponent = exports.SyncBlockPluginComponent = function SyncBlockPluginComponent(_ref) {
|
|
35
|
+
var config = _ref.config,
|
|
36
|
+
dom = _ref.dom;
|
|
37
|
+
var innerEditorView = (0, _react.useRef)(null);
|
|
38
|
+
|
|
39
|
+
/* Tmp solution to demonstrate the synced block renderer */
|
|
40
|
+
var _useState = (0, _react.useState)(defaultSyncBlockDocument),
|
|
41
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
42
|
+
rendererDocument = _useState2[0],
|
|
43
|
+
setRendererDocument = _useState2[1];
|
|
44
|
+
var onChange = function onChange(editorView, _meta) {
|
|
45
|
+
var content = editorView.state.doc.toJSON().content;
|
|
46
|
+
var rendererDocument = {
|
|
47
|
+
version: 1,
|
|
48
|
+
type: 'doc',
|
|
49
|
+
content: content
|
|
50
|
+
};
|
|
51
|
+
setRendererDocument(rendererDocument);
|
|
52
|
+
};
|
|
53
|
+
var onEditorReady = function onEditorReady(_ref2) {
|
|
54
|
+
var editorView = _ref2.editorView;
|
|
55
|
+
innerEditorView.current = editorView || null;
|
|
56
|
+
};
|
|
57
|
+
var boundariesElement = (0, _react.useMemo)(function () {
|
|
58
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
59
|
+
return dom.closest('.fabric-editor-popup-scroll-parent');
|
|
60
|
+
}, [dom]);
|
|
61
|
+
if (!boundariesElement || !(boundariesElement instanceof HTMLElement)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (!(config !== null && config !== void 0 && config.getSyncedBlockEditor) || !(config !== null && config !== void 0 && config.getSyncedBlockRenderer)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
68
|
+
"data-testid": SyncBlockEditorWrapperDataId
|
|
69
|
+
}, config.getSyncedBlockEditor({
|
|
70
|
+
boundariesElement: boundariesElement,
|
|
71
|
+
defaultDocument: defaultSyncBlockDocument,
|
|
72
|
+
mountPoint: dom,
|
|
73
|
+
onChange: onChange,
|
|
74
|
+
onEditorReady: onEditorReady
|
|
75
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
76
|
+
style: {
|
|
77
|
+
width: '100%',
|
|
78
|
+
height: '1px',
|
|
79
|
+
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
80
|
+
backgroundColor: 'purple'
|
|
81
|
+
}
|
|
82
|
+
}), config.getSyncedBlockRenderer({
|
|
83
|
+
docNode: rendererDocument
|
|
84
|
+
}));
|
|
85
|
+
};
|
|
86
|
+
var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
|
|
87
|
+
function SyncBlock() {
|
|
88
|
+
(0, _classCallCheck2.default)(this, SyncBlock);
|
|
89
|
+
return _callSuper(this, SyncBlock, arguments);
|
|
90
|
+
}
|
|
91
|
+
(0, _inherits2.default)(SyncBlock, _ReactNodeView);
|
|
92
|
+
return (0, _createClass2.default)(SyncBlock, [{
|
|
93
|
+
key: "createDomRef",
|
|
94
|
+
value: function createDomRef() {
|
|
95
|
+
var domRef = document.createElement('div');
|
|
96
|
+
domRef.setAttribute('style', 'border: purple solid 1px;');
|
|
97
|
+
return domRef;
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "render",
|
|
101
|
+
value: function render() {
|
|
102
|
+
return /*#__PURE__*/_react.default.createElement(SyncBlockPluginComponent, {
|
|
103
|
+
config: this.reactComponentProps.config,
|
|
104
|
+
dom: this.dom
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "stopEvent",
|
|
109
|
+
value: function stopEvent(event) {
|
|
110
|
+
var _target$closest;
|
|
111
|
+
var target = event.target;
|
|
112
|
+
if (!target) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return ((_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, "[data-testid=\"".concat(SyncBlockEditorWrapperDataId, "\"]"))) != null;
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "destroy",
|
|
119
|
+
value: function destroy() {
|
|
120
|
+
var _this$unsubscribe;
|
|
121
|
+
(_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
|
|
122
|
+
_superPropGet(SyncBlock, "destroy", this, 3)([]);
|
|
123
|
+
}
|
|
124
|
+
}]);
|
|
125
|
+
}(_reactNodeView.default);
|
|
126
|
+
var syncBlockNodeView = exports.syncBlockNodeView = function syncBlockNodeView(_ref3) {
|
|
127
|
+
var config = _ref3.config,
|
|
128
|
+
pmPluginFactoryParams = _ref3.pmPluginFactoryParams;
|
|
17
129
|
return function (node, view, getPos) {
|
|
18
|
-
|
|
130
|
+
var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
|
|
131
|
+
eventDispatcher = pmPluginFactoryParams.eventDispatcher;
|
|
132
|
+
var reactComponentProps = {
|
|
133
|
+
config: config
|
|
134
|
+
};
|
|
135
|
+
return new SyncBlock(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
|
|
19
136
|
};
|
|
20
137
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSyncedBlock = void 0;
|
|
7
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
8
|
+
var getRandomId = function getRandomId() {
|
|
9
|
+
if (!globalThis.crypto || typeof globalThis.crypto.randomUUID !== 'function') {
|
|
10
|
+
return new Date().toISOString();
|
|
11
|
+
}
|
|
12
|
+
return globalThis.crypto.randomUUID();
|
|
13
|
+
};
|
|
14
|
+
var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(state) {
|
|
15
|
+
var tr = state.tr;
|
|
16
|
+
// const { breakout } = state.schema.marks;
|
|
17
|
+
var node = state.schema.nodes.syncBlock.createChecked({
|
|
18
|
+
resourceId: getRandomId(),
|
|
19
|
+
localId: getRandomId()
|
|
20
|
+
}, null
|
|
21
|
+
// [breakout.create({ mode: 'wide' })],
|
|
22
|
+
);
|
|
23
|
+
(0, _utils.safeInsert)(node)(tr);
|
|
24
|
+
return tr;
|
|
25
|
+
};
|
|
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.syncedBlockPluginKey = exports.createPlugin = void 0;
|
|
7
7
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
var _lazySyncedBlock = require("../nodeviews/lazySyncedBlock");
|
|
9
10
|
var syncedBlockPluginKey = exports.syncedBlockPluginKey = new _state.PluginKey('syncedBlockPlugin');
|
|
10
11
|
|
|
11
12
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
12
13
|
|
|
13
|
-
var createPlugin = exports.createPlugin = function createPlugin() {
|
|
14
|
+
var createPlugin = exports.createPlugin = function createPlugin(config, pmPluginFactoryParams, _syncBlockStore) {
|
|
14
15
|
return new _safePlugin.SafePlugin({
|
|
15
16
|
key: syncedBlockPluginKey,
|
|
16
17
|
state: {
|
|
@@ -24,6 +25,14 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
24
25
|
}
|
|
25
26
|
return currentPluginState;
|
|
26
27
|
}
|
|
28
|
+
},
|
|
29
|
+
props: {
|
|
30
|
+
nodeViews: {
|
|
31
|
+
syncBlock: (0, _lazySyncedBlock.lazySyncBlockView)({
|
|
32
|
+
config: config,
|
|
33
|
+
pmPluginFactoryParams: pmPluginFactoryParams
|
|
34
|
+
})
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
});
|
|
29
38
|
};
|
|
@@ -1,27 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.syncedBlockPlugin = void 0;
|
|
7
|
-
var
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
|
+
var _syncBlock = require("@atlaskit/editor-common/sync-block");
|
|
11
|
+
var _smartLink = _interopRequireDefault(require("@atlaskit/icon/core/smart-link"));
|
|
12
|
+
var _actions = require("./pm-plugins/actions");
|
|
8
13
|
var _main = require("./pm-plugins/main");
|
|
9
14
|
var _floatingToolbar = require("./ui/floating-toolbar");
|
|
10
|
-
var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin() {
|
|
15
|
+
var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
16
|
+
var config = _ref.config;
|
|
17
|
+
var syncBlockStore = new _syncBlock.SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
|
|
11
18
|
return {
|
|
12
19
|
name: 'syncedBlock',
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
nodes: function nodes() {
|
|
21
|
+
return [{
|
|
22
|
+
name: 'syncBlock',
|
|
23
|
+
node: _adfSchema.syncBlock
|
|
24
|
+
}];
|
|
17
25
|
},
|
|
18
26
|
pmPlugins: function pmPlugins() {
|
|
19
27
|
return [{
|
|
20
28
|
name: 'syncedBlockPlugin',
|
|
21
|
-
plugin:
|
|
29
|
+
plugin: function plugin(params) {
|
|
30
|
+
return (0, _main.createPlugin)(config, params, syncBlockStore);
|
|
31
|
+
}
|
|
22
32
|
}];
|
|
23
33
|
},
|
|
24
34
|
pluginsOptions: {
|
|
35
|
+
quickInsert: function quickInsert() {
|
|
36
|
+
return [{
|
|
37
|
+
id: 'syncBlock',
|
|
38
|
+
title: 'Synced Block',
|
|
39
|
+
description: 'Create a synced block',
|
|
40
|
+
priority: 800,
|
|
41
|
+
keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block'],
|
|
42
|
+
keyshortcut: '',
|
|
43
|
+
icon: function icon() {
|
|
44
|
+
return /*#__PURE__*/_react.default.createElement(_smartLink.default, {
|
|
45
|
+
label: "Synced Block"
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
action: function action(_insert, state) {
|
|
49
|
+
return (0, _actions.createSyncedBlock)(state);
|
|
50
|
+
}
|
|
51
|
+
}];
|
|
52
|
+
},
|
|
25
53
|
floatingToolbar: (0, _floatingToolbar.getToolbarConfig)()
|
|
26
54
|
}
|
|
27
55
|
};
|
|
@@ -1,39 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.getToolbarConfig = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
-
var basicButton = function basicButton(formatMessage) {
|
|
10
|
-
return [{
|
|
11
|
-
id: 'placeholder',
|
|
12
|
-
type: 'button',
|
|
13
|
-
onClick: function onClick() {
|
|
14
|
-
return true;
|
|
15
|
-
},
|
|
16
|
-
title: formatMessage({
|
|
17
|
-
id: 'placeholder',
|
|
18
|
-
defaultMessage: 'Message',
|
|
19
|
-
description: 'Placeholder description.'
|
|
20
|
-
})
|
|
21
|
-
}];
|
|
22
|
-
};
|
|
23
7
|
var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
|
|
24
|
-
return function (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// placeholder nodeType
|
|
28
|
-
var nodeType = [state.schema.nodes.paragraph];
|
|
29
|
-
var basicButtonArray = basicButton(formatMessage);
|
|
30
|
-
return {
|
|
31
|
-
title: 'Floating controls',
|
|
32
|
-
nodeType: nodeType,
|
|
33
|
-
items: [].concat((0, _toConsumableArray2.default)(basicButtonArray), [{
|
|
34
|
-
type: 'separator'
|
|
35
|
-
}]),
|
|
36
|
-
scrollable: true
|
|
37
|
-
};
|
|
8
|
+
return function (_state, _intl) {
|
|
9
|
+
return undefined;
|
|
38
10
|
};
|
|
39
11
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
|
|
2
|
+
export const lazySyncBlockView = props => {
|
|
3
|
+
return withLazyLoading({
|
|
4
|
+
nodeName: 'syncBlock',
|
|
5
|
+
getNodeViewOptions: () => {},
|
|
6
|
+
loader: () => {
|
|
7
|
+
const result = import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-synced-block-nodeview" */
|
|
8
|
+
'./syncedBlock').then(({
|
|
9
|
+
syncBlockNodeView
|
|
10
|
+
}) => {
|
|
11
|
+
return syncBlockNodeView(props);
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -1,10 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/* eslint-disable @atlaskit/ui-styling-standard/enforce-style-prop */
|
|
2
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
3
|
+
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
4
|
+
export const defaultSyncBlockDocument = {
|
|
5
|
+
version: 1,
|
|
6
|
+
type: 'doc',
|
|
7
|
+
content: [{
|
|
8
|
+
type: 'paragraph',
|
|
9
|
+
content: [{
|
|
10
|
+
type: 'text',
|
|
11
|
+
text: 'This is a synced block. Edit the source to update the content.'
|
|
12
|
+
}]
|
|
13
|
+
}]
|
|
14
|
+
};
|
|
15
|
+
const SyncBlockEditorWrapperDataId = 'sync-block-plugin-editor-wrapper';
|
|
16
|
+
export const SyncBlockPluginComponent = ({
|
|
17
|
+
config,
|
|
18
|
+
dom
|
|
19
|
+
}) => {
|
|
20
|
+
const innerEditorView = useRef(null);
|
|
21
|
+
|
|
22
|
+
/* Tmp solution to demonstrate the synced block renderer */
|
|
23
|
+
const [rendererDocument, setRendererDocument] = useState(defaultSyncBlockDocument);
|
|
24
|
+
const onChange = (editorView, _meta) => {
|
|
25
|
+
const content = editorView.state.doc.toJSON().content;
|
|
26
|
+
const rendererDocument = {
|
|
27
|
+
version: 1,
|
|
28
|
+
type: 'doc',
|
|
29
|
+
content
|
|
30
|
+
};
|
|
31
|
+
setRendererDocument(rendererDocument);
|
|
32
|
+
};
|
|
33
|
+
const onEditorReady = ({
|
|
34
|
+
editorView
|
|
35
|
+
}) => {
|
|
36
|
+
innerEditorView.current = editorView || null;
|
|
37
|
+
};
|
|
38
|
+
const boundariesElement = useMemo(() => {
|
|
39
|
+
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
40
|
+
return dom.closest('.fabric-editor-popup-scroll-parent');
|
|
41
|
+
}, [dom]);
|
|
42
|
+
if (!boundariesElement || !(boundariesElement instanceof HTMLElement)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (!(config !== null && config !== void 0 && config.getSyncedBlockEditor) || !(config !== null && config !== void 0 && config.getSyncedBlockRenderer)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
49
|
+
"data-testid": SyncBlockEditorWrapperDataId
|
|
50
|
+
}, config.getSyncedBlockEditor({
|
|
51
|
+
boundariesElement: boundariesElement,
|
|
52
|
+
defaultDocument: defaultSyncBlockDocument,
|
|
53
|
+
mountPoint: dom,
|
|
54
|
+
onChange: onChange,
|
|
55
|
+
onEditorReady: onEditorReady
|
|
56
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
57
|
+
style: {
|
|
58
|
+
width: '100%',
|
|
59
|
+
height: '1px',
|
|
60
|
+
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
61
|
+
backgroundColor: 'purple'
|
|
62
|
+
}
|
|
63
|
+
}), config.getSyncedBlockRenderer({
|
|
64
|
+
docNode: rendererDocument
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
class SyncBlock extends ReactNodeView {
|
|
68
|
+
createDomRef() {
|
|
69
|
+
const domRef = document.createElement('div');
|
|
70
|
+
domRef.setAttribute('style', 'border: purple solid 1px;');
|
|
71
|
+
return domRef;
|
|
72
|
+
}
|
|
73
|
+
render() {
|
|
74
|
+
return /*#__PURE__*/React.createElement(SyncBlockPluginComponent, {
|
|
75
|
+
config: this.reactComponentProps.config,
|
|
76
|
+
dom: this.dom
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
stopEvent(event) {
|
|
80
|
+
var _target$closest;
|
|
81
|
+
const target = event.target;
|
|
82
|
+
if (!target) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return ((_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : _target$closest.call(target, `[data-testid="${SyncBlockEditorWrapperDataId}"]`)) != null;
|
|
86
|
+
}
|
|
87
|
+
destroy() {
|
|
88
|
+
var _this$unsubscribe;
|
|
89
|
+
(_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
|
|
90
|
+
super.destroy();
|
|
6
91
|
}
|
|
7
92
|
}
|
|
8
|
-
export const
|
|
9
|
-
|
|
93
|
+
export const syncBlockNodeView = ({
|
|
94
|
+
config,
|
|
95
|
+
pmPluginFactoryParams
|
|
96
|
+
}) => (node, view, getPos) => {
|
|
97
|
+
const {
|
|
98
|
+
portalProviderAPI,
|
|
99
|
+
eventDispatcher
|
|
100
|
+
} = pmPluginFactoryParams;
|
|
101
|
+
const reactComponentProps = {
|
|
102
|
+
config
|
|
103
|
+
};
|
|
104
|
+
return new SyncBlock(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
|
|
10
105
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
const getRandomId = () => {
|
|
3
|
+
if (!globalThis.crypto || typeof globalThis.crypto.randomUUID !== 'function') {
|
|
4
|
+
return new Date().toISOString();
|
|
5
|
+
}
|
|
6
|
+
return globalThis.crypto.randomUUID();
|
|
7
|
+
};
|
|
8
|
+
export const createSyncedBlock = state => {
|
|
9
|
+
const tr = state.tr;
|
|
10
|
+
// const { breakout } = state.schema.marks;
|
|
11
|
+
const 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,10 +1,11 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
|
|
3
4
|
export const syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
4
5
|
|
|
5
6
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
6
7
|
|
|
7
|
-
export const createPlugin = () => {
|
|
8
|
+
export const createPlugin = (config, pmPluginFactoryParams, _syncBlockStore) => {
|
|
8
9
|
return new SafePlugin({
|
|
9
10
|
key: syncedBlockPluginKey,
|
|
10
11
|
state: {
|
|
@@ -18,6 +19,14 @@ export const createPlugin = () => {
|
|
|
18
19
|
}
|
|
19
20
|
return currentPluginState;
|
|
20
21
|
}
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
nodeViews: {
|
|
25
|
+
syncBlock: lazySyncBlockView({
|
|
26
|
+
config,
|
|
27
|
+
pmPluginFactoryParams
|
|
28
|
+
})
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
31
|
});
|
|
23
32
|
};
|
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { syncBlock } from '@atlaskit/adf-schema';
|
|
3
|
+
import { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
|
|
4
|
+
import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
|
|
5
|
+
import { createSyncedBlock } from './pm-plugins/actions';
|
|
2
6
|
import { createPlugin } from './pm-plugins/main';
|
|
3
7
|
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
4
|
-
export const syncedBlockPlugin = (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
export const syncedBlockPlugin = ({
|
|
9
|
+
config
|
|
10
|
+
}) => {
|
|
11
|
+
const syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
|
|
12
|
+
return {
|
|
13
|
+
name: 'syncedBlock',
|
|
14
|
+
nodes() {
|
|
15
|
+
return [{
|
|
16
|
+
name: 'syncBlock',
|
|
17
|
+
node: syncBlock
|
|
18
|
+
}];
|
|
19
|
+
},
|
|
20
|
+
pmPlugins() {
|
|
21
|
+
return [{
|
|
22
|
+
name: 'syncedBlockPlugin',
|
|
23
|
+
plugin: params => createPlugin(config, params, syncBlockStore)
|
|
24
|
+
}];
|
|
25
|
+
},
|
|
26
|
+
pluginsOptions: {
|
|
27
|
+
quickInsert: () => [{
|
|
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: () => /*#__PURE__*/React.createElement(SmartLinkIcon, {
|
|
35
|
+
label: "Synced Block"
|
|
36
|
+
}),
|
|
37
|
+
action: (_insert, state) => {
|
|
38
|
+
return createSyncedBlock(state);
|
|
39
|
+
}
|
|
40
|
+
}],
|
|
41
|
+
floatingToolbar: getToolbarConfig()
|
|
9
42
|
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return [{
|
|
13
|
-
name: 'syncedBlockPlugin',
|
|
14
|
-
plugin: createPlugin
|
|
15
|
-
}];
|
|
16
|
-
},
|
|
17
|
-
pluginsOptions: {
|
|
18
|
-
floatingToolbar: getToolbarConfig()
|
|
19
|
-
}
|
|
20
|
-
});
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
const
|
|
2
|
-
return
|
|
3
|
-
id: 'placeholder',
|
|
4
|
-
type: 'button',
|
|
5
|
-
onClick: () => {
|
|
6
|
-
return true;
|
|
7
|
-
},
|
|
8
|
-
title: formatMessage({
|
|
9
|
-
id: 'placeholder',
|
|
10
|
-
defaultMessage: 'Message',
|
|
11
|
-
description: 'Placeholder description.'
|
|
12
|
-
})
|
|
13
|
-
}];
|
|
14
|
-
};
|
|
15
|
-
export const getToolbarConfig = () => (state, intl) => {
|
|
16
|
-
const {
|
|
17
|
-
formatMessage
|
|
18
|
-
} = intl;
|
|
19
|
-
|
|
20
|
-
// placeholder nodeType
|
|
21
|
-
const nodeType = [state.schema.nodes.paragraph];
|
|
22
|
-
const basicButtonArray = basicButton(formatMessage);
|
|
23
|
-
return {
|
|
24
|
-
title: 'Floating controls',
|
|
25
|
-
nodeType,
|
|
26
|
-
items: [...basicButtonArray, {
|
|
27
|
-
type: 'separator'
|
|
28
|
-
}],
|
|
29
|
-
scrollable: true
|
|
30
|
-
};
|
|
1
|
+
export const getToolbarConfig = () => (_state, _intl) => {
|
|
2
|
+
return undefined;
|
|
31
3
|
};
|
|
@@ -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
|
+
};
|
|
@@ -1,13 +1,129 @@
|
|
|
1
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
10
121
|
return function (node, view, getPos) {
|
|
11
|
-
|
|
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();
|
|
12
128
|
};
|
|
13
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,10 +1,11 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { lazySyncBlockView } from '../nodeviews/lazySyncedBlock';
|
|
3
4
|
export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
4
5
|
|
|
5
6
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
6
7
|
|
|
7
|
-
export var createPlugin = function createPlugin() {
|
|
8
|
+
export var createPlugin = function createPlugin(config, pmPluginFactoryParams, _syncBlockStore) {
|
|
8
9
|
return new SafePlugin({
|
|
9
10
|
key: syncedBlockPluginKey,
|
|
10
11
|
state: {
|
|
@@ -18,6 +19,14 @@ export var createPlugin = function createPlugin() {
|
|
|
18
19
|
}
|
|
19
20
|
return currentPluginState;
|
|
20
21
|
}
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
nodeViews: {
|
|
25
|
+
syncBlock: lazySyncBlockView({
|
|
26
|
+
config: config,
|
|
27
|
+
pmPluginFactoryParams: pmPluginFactoryParams
|
|
28
|
+
})
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
31
|
});
|
|
23
32
|
};
|
|
@@ -1,21 +1,48 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { syncBlock } from '@atlaskit/adf-schema';
|
|
3
|
+
import { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
|
|
4
|
+
import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
|
|
5
|
+
import { createSyncedBlock } from './pm-plugins/actions';
|
|
2
6
|
import { createPlugin } from './pm-plugins/main';
|
|
3
7
|
import { getToolbarConfig } from './ui/floating-toolbar';
|
|
4
|
-
export var syncedBlockPlugin = function syncedBlockPlugin() {
|
|
8
|
+
export var syncedBlockPlugin = function syncedBlockPlugin(_ref) {
|
|
9
|
+
var config = _ref.config;
|
|
10
|
+
var syncBlockStore = new SyncBlockStoreManager(config === null || config === void 0 ? void 0 : config.dataProvider);
|
|
5
11
|
return {
|
|
6
12
|
name: 'syncedBlock',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
nodes: function nodes() {
|
|
14
|
+
return [{
|
|
15
|
+
name: 'syncBlock',
|
|
16
|
+
node: syncBlock
|
|
17
|
+
}];
|
|
11
18
|
},
|
|
12
19
|
pmPlugins: function pmPlugins() {
|
|
13
20
|
return [{
|
|
14
21
|
name: 'syncedBlockPlugin',
|
|
15
|
-
plugin:
|
|
22
|
+
plugin: function plugin(params) {
|
|
23
|
+
return createPlugin(config, params, syncBlockStore);
|
|
24
|
+
}
|
|
16
25
|
}];
|
|
17
26
|
},
|
|
18
27
|
pluginsOptions: {
|
|
28
|
+
quickInsert: function quickInsert() {
|
|
29
|
+
return [{
|
|
30
|
+
id: 'syncBlock',
|
|
31
|
+
title: 'Synced Block',
|
|
32
|
+
description: 'Create a synced block',
|
|
33
|
+
priority: 800,
|
|
34
|
+
keywords: ['synced', 'block', 'synced-block', 'sync', 'sync-block'],
|
|
35
|
+
keyshortcut: '',
|
|
36
|
+
icon: function icon() {
|
|
37
|
+
return /*#__PURE__*/React.createElement(SmartLinkIcon, {
|
|
38
|
+
label: "Synced Block"
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
action: function action(_insert, state) {
|
|
42
|
+
return createSyncedBlock(state);
|
|
43
|
+
}
|
|
44
|
+
}];
|
|
45
|
+
},
|
|
19
46
|
floatingToolbar: getToolbarConfig()
|
|
20
47
|
}
|
|
21
48
|
};
|
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
var basicButton = function basicButton(formatMessage) {
|
|
3
|
-
return [{
|
|
4
|
-
id: 'placeholder',
|
|
5
|
-
type: 'button',
|
|
6
|
-
onClick: function onClick() {
|
|
7
|
-
return true;
|
|
8
|
-
},
|
|
9
|
-
title: formatMessage({
|
|
10
|
-
id: 'placeholder',
|
|
11
|
-
defaultMessage: 'Message',
|
|
12
|
-
description: 'Placeholder description.'
|
|
13
|
-
})
|
|
14
|
-
}];
|
|
15
|
-
};
|
|
16
1
|
export var getToolbarConfig = function getToolbarConfig() {
|
|
17
|
-
return function (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// placeholder nodeType
|
|
21
|
-
var nodeType = [state.schema.nodes.paragraph];
|
|
22
|
-
var basicButtonArray = basicButton(formatMessage);
|
|
23
|
-
return {
|
|
24
|
-
title: 'Floating controls',
|
|
25
|
-
nodeType: nodeType,
|
|
26
|
-
items: [].concat(_toConsumableArray(basicButtonArray), [{
|
|
27
|
-
type: 'separator'
|
|
28
|
-
}]),
|
|
29
|
-
scrollable: true
|
|
30
|
-
};
|
|
2
|
+
return function (_state, _intl) {
|
|
3
|
+
return undefined;
|
|
31
4
|
};
|
|
32
5
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { syncedBlockPlugin } from './syncedBlockPlugin';
|
|
2
|
-
export type { SyncedBlockPlugin } from './syncedBlockPluginType';
|
|
2
|
+
export type { SyncedBlockPlugin, SyncedBlockPluginOptions, SyncedBlockEditorProps, SyncedBlockRendererProps, } from './syncedBlockPluginType';
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
-
import
|
|
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';
|
|
2
5
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
22
|
}
|
|
10
|
-
export
|
|
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;
|
|
11
28
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
|
|
3
|
+
import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
2
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
3
6
|
export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
4
7
|
type SyncedBlockPluginState = {};
|
|
5
|
-
export declare const createPlugin: () => SafePlugin<SyncedBlockPluginState>;
|
|
8
|
+
export declare const createPlugin: (config: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, _syncBlockStore: SyncBlockStoreManager) => SafePlugin<SyncedBlockPluginState>;
|
|
6
9
|
export {};
|
|
@@ -1,2 +1,39 @@
|
|
|
1
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
|
+
import type { SyncBlockDataProvider } from '@atlaskit/editor-common/sync-block';
|
|
1
4
|
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
|
|
5
|
+
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
7
|
+
export type SyncedBlockEditorProps = {
|
|
8
|
+
boundariesElement: HTMLElement;
|
|
9
|
+
defaultDocument: JSONDocNode;
|
|
10
|
+
mountPoint: HTMLElement;
|
|
11
|
+
onChange: (editorView: EditorView, meta: {
|
|
12
|
+
/**
|
|
13
|
+
* Indicates whether or not the change may be unnecessary to listen to (dirty
|
|
14
|
+
* changes can generally be ignored).
|
|
15
|
+
*
|
|
16
|
+
* This might be changes to media attributes for example when it gets updated
|
|
17
|
+
* due to initial setup.
|
|
18
|
+
*
|
|
19
|
+
* We still fire these events however to avoid a breaking change.
|
|
20
|
+
*/
|
|
21
|
+
isDirtyChange: boolean;
|
|
22
|
+
source: 'local' | 'remote';
|
|
23
|
+
}) => void;
|
|
24
|
+
onEditorReady: ({ editorView, eventDispatcher, }: {
|
|
25
|
+
editorView: EditorView;
|
|
26
|
+
eventDispatcher: EventDispatcher;
|
|
27
|
+
}) => void;
|
|
28
|
+
};
|
|
29
|
+
export type SyncedBlockRendererProps = {
|
|
30
|
+
docNode: DocNode;
|
|
31
|
+
};
|
|
32
|
+
export type SyncedBlockPluginOptions = {
|
|
33
|
+
dataProvider?: SyncBlockDataProvider;
|
|
34
|
+
getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
|
|
35
|
+
getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
36
|
+
};
|
|
37
|
+
export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
38
|
+
pluginConfiguration: SyncedBlockPluginOptions | undefined;
|
|
39
|
+
}>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { syncedBlockPlugin } from './syncedBlockPlugin';
|
|
2
|
-
export type { SyncedBlockPlugin } from './syncedBlockPluginType';
|
|
2
|
+
export type { SyncedBlockPlugin, SyncedBlockPluginOptions, SyncedBlockEditorProps, SyncedBlockRendererProps, } from './syncedBlockPluginType';
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
-
import
|
|
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';
|
|
2
5
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
22
|
}
|
|
10
|
-
export
|
|
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;
|
|
11
28
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import type { SyncBlockStoreManager } from '@atlaskit/editor-common/sync-block';
|
|
3
|
+
import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
|
|
2
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { SyncedBlockPluginOptions } from '../syncedBlockPluginType';
|
|
3
6
|
export declare const syncedBlockPluginKey: PluginKey<any>;
|
|
4
7
|
type SyncedBlockPluginState = {};
|
|
5
|
-
export declare const createPlugin: () => SafePlugin<SyncedBlockPluginState>;
|
|
8
|
+
export declare const createPlugin: (config: SyncedBlockPluginOptions | undefined, pmPluginFactoryParams: PMPluginFactoryParams, _syncBlockStore: SyncBlockStoreManager) => SafePlugin<SyncedBlockPluginState>;
|
|
6
9
|
export {};
|
|
@@ -1,2 +1,39 @@
|
|
|
1
|
+
import type { DocNode } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
|
+
import type { SyncBlockDataProvider } from '@atlaskit/editor-common/sync-block';
|
|
1
4
|
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
|
|
5
|
+
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
6
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
7
|
+
export type SyncedBlockEditorProps = {
|
|
8
|
+
boundariesElement: HTMLElement;
|
|
9
|
+
defaultDocument: JSONDocNode;
|
|
10
|
+
mountPoint: HTMLElement;
|
|
11
|
+
onChange: (editorView: EditorView, meta: {
|
|
12
|
+
/**
|
|
13
|
+
* Indicates whether or not the change may be unnecessary to listen to (dirty
|
|
14
|
+
* changes can generally be ignored).
|
|
15
|
+
*
|
|
16
|
+
* This might be changes to media attributes for example when it gets updated
|
|
17
|
+
* due to initial setup.
|
|
18
|
+
*
|
|
19
|
+
* We still fire these events however to avoid a breaking change.
|
|
20
|
+
*/
|
|
21
|
+
isDirtyChange: boolean;
|
|
22
|
+
source: 'local' | 'remote';
|
|
23
|
+
}) => void;
|
|
24
|
+
onEditorReady: ({ editorView, eventDispatcher, }: {
|
|
25
|
+
editorView: EditorView;
|
|
26
|
+
eventDispatcher: EventDispatcher;
|
|
27
|
+
}) => void;
|
|
28
|
+
};
|
|
29
|
+
export type SyncedBlockRendererProps = {
|
|
30
|
+
docNode: DocNode;
|
|
31
|
+
};
|
|
32
|
+
export type SyncedBlockPluginOptions = {
|
|
33
|
+
dataProvider?: SyncBlockDataProvider;
|
|
34
|
+
getSyncedBlockEditor?: (props: SyncedBlockEditorProps) => React.JSX.Element;
|
|
35
|
+
getSyncedBlockRenderer?: (props: SyncedBlockRendererProps) => React.JSX.Element;
|
|
36
|
+
};
|
|
37
|
+
export type SyncedBlockPlugin = NextEditorPlugin<'syncedBlock', {
|
|
38
|
+
pluginConfiguration: SyncedBlockPluginOptions | undefined;
|
|
39
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-synced-block",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "SyncedBlock plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"atlaskit:src": "src/index.ts",
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@atlaskit/adf-schema": "^51.1.2",
|
|
31
32
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
33
|
+
"@atlaskit/icon": "28.2.0",
|
|
32
34
|
"@babel/runtime": "^7.0.0",
|
|
33
35
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
34
36
|
},
|
|
35
37
|
"peerDependencies": {
|
|
36
|
-
"@atlaskit/editor-common": "^109.
|
|
38
|
+
"@atlaskit/editor-common": "^109.8.0",
|
|
37
39
|
"react": "^18.2.0"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|