@atlaskit/editor-plugin-synced-block 0.1.0 → 0.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-synced-block
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7ce112e18ca29`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7ce112e18ca29) -
8
+ [ux] Copy the sync block reference to clipboard
9
+ - Updated dependencies
10
+
3
11
  ## 0.1.0
4
12
 
5
13
  ### Minor Changes
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.dev-agents.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../dev-agents/tsDist/@atlaskit__editor-plugin-synced-block/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../adf-utils/afm-dev-agents/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-json-transformer/afm-dev-agents/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../../design-system/icon/afm-dev-agents/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../renderer/afm-dev-agents/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../../design-system/tokens/afm-dev-agents/tsconfig.json"
39
+ },
40
+ {
41
+ "path": "../../editor-common/afm-dev-agents/tsconfig.json"
42
+ }
43
+ ]
44
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.jira.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../tsDist/@atlaskit__editor-plugin-synced-block/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../adf-utils/afm-jira/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-json-transformer/afm-jira/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../../design-system/icon/afm-jira/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../renderer/afm-jira/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../../design-system/tokens/afm-jira/tsconfig.json"
39
+ },
40
+ {
41
+ "path": "../../editor-common/afm-jira/tsconfig.json"
42
+ }
43
+ ]
44
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.passionfruit.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../passionfruit/tsDist/@atlaskit__editor-plugin-synced-block/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../adf-utils/afm-passionfruit/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-json-transformer/afm-passionfruit/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../../design-system/icon/afm-passionfruit/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../renderer/afm-passionfruit/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../../design-system/tokens/afm-passionfruit/tsconfig.json"
39
+ },
40
+ {
41
+ "path": "../../editor-common/afm-passionfruit/tsconfig.json"
42
+ }
43
+ ]
44
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.post-office.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../post-office/tsDist/@atlaskit__editor-plugin-synced-block/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../adf-utils/afm-post-office/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-json-transformer/afm-post-office/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../../design-system/icon/afm-post-office/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../renderer/afm-post-office/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../../design-system/tokens/afm-post-office/tsconfig.json"
39
+ },
40
+ {
41
+ "path": "../../editor-common/afm-post-office/tsconfig.json"
42
+ }
43
+ ]
44
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.rovo-extension.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../rovo-extension/tsDist/@atlaskit__editor-plugin-synced-block/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../adf-utils/afm-rovo-extension/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-json-transformer/afm-rovo-extension/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../../design-system/icon/afm-rovo-extension/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../renderer/afm-rovo-extension/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../../design-system/tokens/afm-rovo-extension/tsconfig.json"
39
+ },
40
+ {
41
+ "path": "../../editor-common/afm-rovo-extension/tsconfig.json"
42
+ }
43
+ ]
44
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.townsquare.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../townsquare/tsDist/@atlaskit__editor-plugin-synced-block/app",
6
+ "rootDir": "../",
7
+ "composite": true
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../src/**/*.test.*",
16
+ "../src/**/test.*",
17
+ "../src/**/examples.*",
18
+ "../src/**/examples/*",
19
+ "../src/**/examples/**/*",
20
+ "../src/**/*.stories.*",
21
+ "../src/**/stories/*",
22
+ "../src/**/stories/**/*"
23
+ ],
24
+ "references": [
25
+ {
26
+ "path": "../../adf-utils/afm-townsquare/tsconfig.json"
27
+ },
28
+ {
29
+ "path": "../../editor-json-transformer/afm-townsquare/tsconfig.json"
30
+ },
31
+ {
32
+ "path": "../../../design-system/icon/afm-townsquare/tsconfig.json"
33
+ },
34
+ {
35
+ "path": "../../renderer/afm-townsquare/tsconfig.json"
36
+ },
37
+ {
38
+ "path": "../../../design-system/tokens/afm-townsquare/tsconfig.json"
39
+ },
40
+ {
41
+ "path": "../../editor-common/afm-townsquare/tsconfig.json"
42
+ }
43
+ ]
44
+ }
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getSyncedBlockExtensionProvider = void 0;
7
7
  var _extensions = require("@atlaskit/editor-common/extensions");
8
8
  var _manifest = require("./manifest");
9
- var getSyncedBlockExtensionProvider = exports.getSyncedBlockExtensionProvider = function getSyncedBlockExtensionProvider() {
10
- return new _extensions.DefaultExtensionProvider([(0, _manifest.getSyncedBlockManifest)()]);
9
+ var getSyncedBlockExtensionProvider = exports.getSyncedBlockExtensionProvider = function getSyncedBlockExtensionProvider(schema) {
10
+ return new _extensions.DefaultExtensionProvider([(0, _manifest.getSyncedBlockManifest)(schema)]);
11
11
  };
@@ -9,6 +9,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
11
  var _react = _interopRequireDefault(require("react"));
12
+ var _clipboard = require("@atlaskit/editor-common/clipboard");
13
+ var _model = require("@atlaskit/editor-prosemirror/model");
12
14
  var _smartLink = _interopRequireDefault(require("@atlaskit/icon/core/smart-link"));
13
15
  var _SyncedBlockLiveView = _interopRequireDefault(require("./components/SyncedBlockLiveView"));
14
16
  var _constants = require("./constants");
@@ -21,6 +23,29 @@ var getRandomId = function getRandomId() {
21
23
  }
22
24
  return globalThis.crypto.randomUUID();
23
25
  };
26
+ var copyToClipboard = function copyToClipboard(adf, schema) {
27
+ if (!schema) {
28
+ throw new Error('copyToClipboard(): Schema is required.');
29
+ }
30
+
31
+ // Validate the given ADF
32
+ var nodeType = schema.nodes[adf.type];
33
+ if (!nodeType) {
34
+ throw new Error("copyToClipboard(): Invalid ADF type '".concat(adf.type, "'."));
35
+ }
36
+ var fragment = _model.Fragment.fromJSON(schema, adf.content);
37
+ var marks = (adf.marks || []).map(function (markEntity) {
38
+ return _model.Mark.fromJSON(schema, markEntity);
39
+ });
40
+ var newNode = nodeType === null || nodeType === void 0 ? void 0 : nodeType.createChecked(adf.attrs, fragment, marks);
41
+ if (!newNode) {
42
+ throw new Error('copyToClipboard(): Could not create a node for given ADFEntity.');
43
+ }
44
+ var domNode = _model.DOMSerializer.fromSchema(schema).serializeNode(newNode);
45
+ var div = document.createElement('div');
46
+ div.appendChild(domNode);
47
+ (0, _clipboard.copyHTMLToClipboard)(div);
48
+ };
24
49
 
25
50
  // Remaining tasks
26
51
  // - Better location for content sync implementation – currently done in SyncedBlockSource renderer which won't work in editor
@@ -33,7 +58,7 @@ var getRandomId = function getRandomId() {
33
58
  // - Dealing with orphaned synced block content properties data
34
59
  // - Getting current page id in editor context and the cloud id
35
60
  // - Explore hiding the frame for the extension in the editor, currently using `__hideFrame: true` and commented code to enable
36
- var getSyncedBlockManifest = exports.getSyncedBlockManifest = function getSyncedBlockManifest() {
61
+ var getSyncedBlockManifest = exports.getSyncedBlockManifest = function getSyncedBlockManifest(schema) {
37
62
  return {
38
63
  title: 'Synced Block',
39
64
  type: _syncedBlock.SYNCED_BLOCK_EXTENSION_TYPE,
@@ -191,7 +216,7 @@ var getSyncedBlockManifest = exports.getSyncedBlockManifest = function getSynced
191
216
  key: 'toolbar-item-key',
192
217
  label: 'Referenece',
193
218
  display: 'icon',
194
- tooltip: 'Create reference',
219
+ tooltip: 'Copy reference to clipboard',
195
220
  // Ignored via go/ees005
196
221
  // eslint-disable-next-line require-await
197
222
  icon: function () {
@@ -219,30 +244,32 @@ var getSyncedBlockManifest = exports.getSyncedBlockManifest = function getSynced
219
244
  // Ignored via go/ees005
220
245
  // eslint-disable-next-line require-await
221
246
  action: function () {
222
- var _action2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(contextNode, api) {
223
- var _contextNode$attrs, _contextNode$attrs2, _contextNode$attrs3;
247
+ var _action2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(contextNode) {
248
+ var _contextNode$attrs, _contextNode$attrs2;
224
249
  return _regenerator.default.wrap(function _callee6$(_context6) {
225
250
  while (1) switch (_context6.prev = _context6.next) {
226
251
  case 0:
227
- api.doc.insertAfter((_contextNode$attrs = contextNode.attrs) === null || _contextNode$attrs === void 0 ? void 0 : _contextNode$attrs.localId, {
228
- type: 'extension',
229
- attrs: {
230
- extensionType: _syncedBlock.SYNCED_BLOCK_EXTENSION_TYPE,
231
- extensionKey: _syncedBlock.SYNCED_BLOCK_REFERENCE_KEY,
232
- parameters: {
233
- sourceDocumentAri: (_contextNode$attrs2 = contextNode.attrs) === null || _contextNode$attrs2 === void 0 || (_contextNode$attrs2 = _contextNode$attrs2.parameters) === null || _contextNode$attrs2 === void 0 ? void 0 : _contextNode$attrs2.sourceDocumentAri,
234
- contentAri: (_contextNode$attrs3 = contextNode.attrs) === null || _contextNode$attrs3 === void 0 || (_contextNode$attrs3 = _contextNode$attrs3.parameters) === null || _contextNode$attrs3 === void 0 ? void 0 : _contextNode$attrs3.contentAri
235
- },
236
- localId: 'testId'
237
- }
238
- });
252
+ try {
253
+ copyToClipboard({
254
+ type: 'extension',
255
+ attrs: {
256
+ extensionType: _syncedBlock.SYNCED_BLOCK_EXTENSION_TYPE,
257
+ extensionKey: _syncedBlock.SYNCED_BLOCK_REFERENCE_KEY,
258
+ parameters: {
259
+ sourceDocumentAri: (_contextNode$attrs = contextNode.attrs) === null || _contextNode$attrs === void 0 || (_contextNode$attrs = _contextNode$attrs.parameters) === null || _contextNode$attrs === void 0 ? void 0 : _contextNode$attrs.sourceDocumentAri,
260
+ contentAri: (_contextNode$attrs2 = contextNode.attrs) === null || _contextNode$attrs2 === void 0 || (_contextNode$attrs2 = _contextNode$attrs2.parameters) === null || _contextNode$attrs2 === void 0 ? void 0 : _contextNode$attrs2.contentAri
261
+ },
262
+ localId: 'testId'
263
+ }
264
+ }, schema);
265
+ } catch (e) {}
239
266
  case 1:
240
267
  case "end":
241
268
  return _context6.stop();
242
269
  }
243
270
  }, _callee6);
244
271
  }));
245
- function action(_x2, _x3) {
272
+ function action(_x2) {
246
273
  return _action2.apply(this, arguments);
247
274
  }
248
275
  return action;
@@ -1,5 +1,5 @@
1
1
  import { DefaultExtensionProvider } from '@atlaskit/editor-common/extensions';
2
2
  import { getSyncedBlockManifest } from './manifest';
3
- export const getSyncedBlockExtensionProvider = () => {
4
- return new DefaultExtensionProvider([getSyncedBlockManifest()]);
3
+ export const getSyncedBlockExtensionProvider = schema => {
4
+ return new DefaultExtensionProvider([getSyncedBlockManifest(schema)]);
5
5
  };
@@ -1,4 +1,6 @@
1
1
  import React from 'react';
2
+ import { copyHTMLToClipboard } from '@atlaskit/editor-common/clipboard';
3
+ import { DOMSerializer, Fragment, Mark } from '@atlaskit/editor-prosemirror/model';
2
4
  import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
3
5
  import SyncedBlockLiveView from './components/SyncedBlockLiveView';
4
6
  import { getPageId } from './constants';
@@ -11,6 +13,27 @@ const getRandomId = () => {
11
13
  }
12
14
  return globalThis.crypto.randomUUID();
13
15
  };
16
+ const copyToClipboard = (adf, schema) => {
17
+ if (!schema) {
18
+ throw new Error('copyToClipboard(): Schema is required.');
19
+ }
20
+
21
+ // Validate the given ADF
22
+ const nodeType = schema.nodes[adf.type];
23
+ if (!nodeType) {
24
+ throw new Error(`copyToClipboard(): Invalid ADF type '${adf.type}'.`);
25
+ }
26
+ const fragment = Fragment.fromJSON(schema, adf.content);
27
+ const marks = (adf.marks || []).map(markEntity => Mark.fromJSON(schema, markEntity));
28
+ const newNode = nodeType === null || nodeType === void 0 ? void 0 : nodeType.createChecked(adf.attrs, fragment, marks);
29
+ if (!newNode) {
30
+ throw new Error('copyToClipboard(): Could not create a node for given ADFEntity.');
31
+ }
32
+ const domNode = DOMSerializer.fromSchema(schema).serializeNode(newNode);
33
+ const div = document.createElement('div');
34
+ div.appendChild(domNode);
35
+ copyHTMLToClipboard(div);
36
+ };
14
37
 
15
38
  // Remaining tasks
16
39
  // - Better location for content sync implementation – currently done in SyncedBlockSource renderer which won't work in editor
@@ -23,7 +46,7 @@ const getRandomId = () => {
23
46
  // - Dealing with orphaned synced block content properties data
24
47
  // - Getting current page id in editor context and the cloud id
25
48
  // - Explore hiding the frame for the extension in the editor, currently using `__hideFrame: true` and commented code to enable
26
- export const getSyncedBlockManifest = () => ({
49
+ export const getSyncedBlockManifest = schema => ({
27
50
  title: 'Synced Block',
28
51
  type: SYNCED_BLOCK_EXTENSION_TYPE,
29
52
  key: SYNCED_BLOCK_EXTENSION_KEY,
@@ -117,7 +140,7 @@ export const getSyncedBlockManifest = () => ({
117
140
  key: 'toolbar-item-key',
118
141
  label: 'Referenece',
119
142
  display: 'icon',
120
- tooltip: 'Create reference',
143
+ tooltip: 'Copy reference to clipboard',
121
144
  // Ignored via go/ees005
122
145
  // eslint-disable-next-line require-await
123
146
  icon: async () => () => /*#__PURE__*/React.createElement(SmartLinkIcon, {
@@ -126,20 +149,22 @@ export const getSyncedBlockManifest = () => ({
126
149
  }),
127
150
  // Ignored via go/ees005
128
151
  // eslint-disable-next-line require-await
129
- action: async (contextNode, api) => {
130
- var _contextNode$attrs, _contextNode$attrs2, _contextNode$attrs2$p, _contextNode$attrs3, _contextNode$attrs3$p;
131
- api.doc.insertAfter((_contextNode$attrs = contextNode.attrs) === null || _contextNode$attrs === void 0 ? void 0 : _contextNode$attrs.localId, {
132
- type: 'extension',
133
- attrs: {
134
- extensionType: SYNCED_BLOCK_EXTENSION_TYPE,
135
- extensionKey: SYNCED_BLOCK_REFERENCE_KEY,
136
- parameters: {
137
- sourceDocumentAri: (_contextNode$attrs2 = contextNode.attrs) === null || _contextNode$attrs2 === void 0 ? void 0 : (_contextNode$attrs2$p = _contextNode$attrs2.parameters) === null || _contextNode$attrs2$p === void 0 ? void 0 : _contextNode$attrs2$p.sourceDocumentAri,
138
- contentAri: (_contextNode$attrs3 = contextNode.attrs) === null || _contextNode$attrs3 === void 0 ? void 0 : (_contextNode$attrs3$p = _contextNode$attrs3.parameters) === null || _contextNode$attrs3$p === void 0 ? void 0 : _contextNode$attrs3$p.contentAri
139
- },
140
- localId: 'testId'
141
- }
142
- });
152
+ action: async contextNode => {
153
+ try {
154
+ var _contextNode$attrs, _contextNode$attrs$pa, _contextNode$attrs2, _contextNode$attrs2$p;
155
+ copyToClipboard({
156
+ type: 'extension',
157
+ attrs: {
158
+ extensionType: SYNCED_BLOCK_EXTENSION_TYPE,
159
+ extensionKey: SYNCED_BLOCK_REFERENCE_KEY,
160
+ parameters: {
161
+ sourceDocumentAri: (_contextNode$attrs = contextNode.attrs) === null || _contextNode$attrs === void 0 ? void 0 : (_contextNode$attrs$pa = _contextNode$attrs.parameters) === null || _contextNode$attrs$pa === void 0 ? void 0 : _contextNode$attrs$pa.sourceDocumentAri,
162
+ contentAri: (_contextNode$attrs2 = contextNode.attrs) === null || _contextNode$attrs2 === void 0 ? void 0 : (_contextNode$attrs2$p = _contextNode$attrs2.parameters) === null || _contextNode$attrs2$p === void 0 ? void 0 : _contextNode$attrs2$p.contentAri
163
+ },
164
+ localId: 'testId'
165
+ }
166
+ }, schema);
167
+ } catch (e) {}
143
168
  }
144
169
  }]
145
170
  }]
@@ -1,5 +1,5 @@
1
1
  import { DefaultExtensionProvider } from '@atlaskit/editor-common/extensions';
2
2
  import { getSyncedBlockManifest } from './manifest';
3
- export var getSyncedBlockExtensionProvider = function getSyncedBlockExtensionProvider() {
4
- return new DefaultExtensionProvider([getSyncedBlockManifest()]);
3
+ export var getSyncedBlockExtensionProvider = function getSyncedBlockExtensionProvider(schema) {
4
+ return new DefaultExtensionProvider([getSyncedBlockManifest(schema)]);
5
5
  };
@@ -2,6 +2,8 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import React from 'react';
5
+ import { copyHTMLToClipboard } from '@atlaskit/editor-common/clipboard';
6
+ import { DOMSerializer, Fragment, Mark } from '@atlaskit/editor-prosemirror/model';
5
7
  import SmartLinkIcon from '@atlaskit/icon/core/smart-link';
6
8
  import SyncedBlockLiveView from './components/SyncedBlockLiveView';
7
9
  import { getPageId } from './constants';
@@ -14,6 +16,29 @@ var getRandomId = function getRandomId() {
14
16
  }
15
17
  return globalThis.crypto.randomUUID();
16
18
  };
19
+ var copyToClipboard = function copyToClipboard(adf, schema) {
20
+ if (!schema) {
21
+ throw new Error('copyToClipboard(): Schema is required.');
22
+ }
23
+
24
+ // Validate the given ADF
25
+ var nodeType = schema.nodes[adf.type];
26
+ if (!nodeType) {
27
+ throw new Error("copyToClipboard(): Invalid ADF type '".concat(adf.type, "'."));
28
+ }
29
+ var fragment = Fragment.fromJSON(schema, adf.content);
30
+ var marks = (adf.marks || []).map(function (markEntity) {
31
+ return Mark.fromJSON(schema, markEntity);
32
+ });
33
+ var newNode = nodeType === null || nodeType === void 0 ? void 0 : nodeType.createChecked(adf.attrs, fragment, marks);
34
+ if (!newNode) {
35
+ throw new Error('copyToClipboard(): Could not create a node for given ADFEntity.');
36
+ }
37
+ var domNode = DOMSerializer.fromSchema(schema).serializeNode(newNode);
38
+ var div = document.createElement('div');
39
+ div.appendChild(domNode);
40
+ copyHTMLToClipboard(div);
41
+ };
17
42
 
18
43
  // Remaining tasks
19
44
  // - Better location for content sync implementation – currently done in SyncedBlockSource renderer which won't work in editor
@@ -26,7 +51,7 @@ var getRandomId = function getRandomId() {
26
51
  // - Dealing with orphaned synced block content properties data
27
52
  // - Getting current page id in editor context and the cloud id
28
53
  // - Explore hiding the frame for the extension in the editor, currently using `__hideFrame: true` and commented code to enable
29
- export var getSyncedBlockManifest = function getSyncedBlockManifest() {
54
+ export var getSyncedBlockManifest = function getSyncedBlockManifest(schema) {
30
55
  return {
31
56
  title: 'Synced Block',
32
57
  type: SYNCED_BLOCK_EXTENSION_TYPE,
@@ -184,7 +209,7 @@ export var getSyncedBlockManifest = function getSyncedBlockManifest() {
184
209
  key: 'toolbar-item-key',
185
210
  label: 'Referenece',
186
211
  display: 'icon',
187
- tooltip: 'Create reference',
212
+ tooltip: 'Copy reference to clipboard',
188
213
  // Ignored via go/ees005
189
214
  // eslint-disable-next-line require-await
190
215
  icon: function () {
@@ -212,30 +237,32 @@ export var getSyncedBlockManifest = function getSyncedBlockManifest() {
212
237
  // Ignored via go/ees005
213
238
  // eslint-disable-next-line require-await
214
239
  action: function () {
215
- var _action2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(contextNode, api) {
216
- var _contextNode$attrs, _contextNode$attrs2, _contextNode$attrs3;
240
+ var _action2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(contextNode) {
241
+ var _contextNode$attrs, _contextNode$attrs2;
217
242
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
218
243
  while (1) switch (_context6.prev = _context6.next) {
219
244
  case 0:
220
- api.doc.insertAfter((_contextNode$attrs = contextNode.attrs) === null || _contextNode$attrs === void 0 ? void 0 : _contextNode$attrs.localId, {
221
- type: 'extension',
222
- attrs: {
223
- extensionType: SYNCED_BLOCK_EXTENSION_TYPE,
224
- extensionKey: SYNCED_BLOCK_REFERENCE_KEY,
225
- parameters: {
226
- sourceDocumentAri: (_contextNode$attrs2 = contextNode.attrs) === null || _contextNode$attrs2 === void 0 || (_contextNode$attrs2 = _contextNode$attrs2.parameters) === null || _contextNode$attrs2 === void 0 ? void 0 : _contextNode$attrs2.sourceDocumentAri,
227
- contentAri: (_contextNode$attrs3 = contextNode.attrs) === null || _contextNode$attrs3 === void 0 || (_contextNode$attrs3 = _contextNode$attrs3.parameters) === null || _contextNode$attrs3 === void 0 ? void 0 : _contextNode$attrs3.contentAri
228
- },
229
- localId: 'testId'
230
- }
231
- });
245
+ try {
246
+ copyToClipboard({
247
+ type: 'extension',
248
+ attrs: {
249
+ extensionType: SYNCED_BLOCK_EXTENSION_TYPE,
250
+ extensionKey: SYNCED_BLOCK_REFERENCE_KEY,
251
+ parameters: {
252
+ sourceDocumentAri: (_contextNode$attrs = contextNode.attrs) === null || _contextNode$attrs === void 0 || (_contextNode$attrs = _contextNode$attrs.parameters) === null || _contextNode$attrs === void 0 ? void 0 : _contextNode$attrs.sourceDocumentAri,
253
+ contentAri: (_contextNode$attrs2 = contextNode.attrs) === null || _contextNode$attrs2 === void 0 || (_contextNode$attrs2 = _contextNode$attrs2.parameters) === null || _contextNode$attrs2 === void 0 ? void 0 : _contextNode$attrs2.contentAri
254
+ },
255
+ localId: 'testId'
256
+ }
257
+ }, schema);
258
+ } catch (e) {}
232
259
  case 1:
233
260
  case "end":
234
261
  return _context6.stop();
235
262
  }
236
263
  }, _callee6);
237
264
  }));
238
- function action(_x2, _x3) {
265
+ function action(_x2) {
239
266
  return _action2.apply(this, arguments);
240
267
  }
241
268
  return action;
@@ -1,2 +1,3 @@
1
1
  import { DefaultExtensionProvider } from '@atlaskit/editor-common/extensions';
2
- export declare const getSyncedBlockExtensionProvider: () => DefaultExtensionProvider<import("@atlaskit/editor-common/extensions").Parameters>;
2
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
3
+ export declare const getSyncedBlockExtensionProvider: (schema?: Schema) => DefaultExtensionProvider<import("@atlaskit/editor-common/extensions").Parameters>;
@@ -1,2 +1,3 @@
1
1
  import type { ExtensionManifest } from '@atlaskit/editor-common/extensions';
2
- export declare const getSyncedBlockManifest: () => ExtensionManifest;
2
+ import { type Schema } from '@atlaskit/editor-prosemirror/model';
3
+ export declare const getSyncedBlockManifest: (schema?: Schema) => ExtensionManifest;
@@ -1,2 +1,3 @@
1
1
  import { DefaultExtensionProvider } from '@atlaskit/editor-common/extensions';
2
- export declare const getSyncedBlockExtensionProvider: () => DefaultExtensionProvider<import("@atlaskit/editor-common/extensions").Parameters>;
2
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
3
+ export declare const getSyncedBlockExtensionProvider: (schema?: Schema) => DefaultExtensionProvider<import("@atlaskit/editor-common/extensions").Parameters>;
@@ -1,2 +1,3 @@
1
1
  import type { ExtensionManifest } from '@atlaskit/editor-common/extensions';
2
- export declare const getSyncedBlockManifest: () => ExtensionManifest;
2
+ import { type Schema } from '@atlaskit/editor-prosemirror/model';
3
+ export declare const getSyncedBlockManifest: (schema?: Schema) => ExtensionManifest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  "@atlaskit/adf-utils": "^19.21.0",
37
37
  "@atlaskit/editor-json-transformer": "^8.27.0",
38
38
  "@atlaskit/editor-prosemirror": "7.0.0",
39
- "@atlaskit/icon": "^28.0.0",
39
+ "@atlaskit/icon": "^28.1.0",
40
40
  "@atlaskit/renderer": "^120.5.0",
41
41
  "@atlaskit/tokens": "^6.0.0",
42
42
  "@babel/runtime": "^7.0.0",