@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.
Files changed (117) hide show
  1. package/CHANGELOG.md +8 -16
  2. package/afm-cc/tsconfig.json +0 -12
  3. package/afm-dev-agents/tsconfig.json +0 -12
  4. package/afm-jira/tsconfig.json +0 -12
  5. package/afm-passionfruit/tsconfig.json +0 -12
  6. package/afm-post-office/tsconfig.json +0 -12
  7. package/afm-rovo-extension/tsconfig.json +0 -12
  8. package/afm-townsquare/tsconfig.json +0 -12
  9. package/dist/cjs/nodeviews/lazySyncedBlock.js +26 -0
  10. package/dist/cjs/nodeviews/syncedBlock.js +137 -0
  11. package/dist/cjs/pm-plugins/actions.js +25 -0
  12. package/dist/cjs/pm-plugins/main.js +10 -22
  13. package/dist/cjs/syncedBlockPlugin.js +35 -5
  14. package/dist/cjs/ui/floating-toolbar.js +11 -0
  15. package/dist/es2019/nodeviews/lazySyncedBlock.js +16 -0
  16. package/dist/es2019/nodeviews/syncedBlock.js +105 -0
  17. package/dist/es2019/pm-plugins/actions.js +19 -0
  18. package/dist/es2019/pm-plugins/main.js +10 -25
  19. package/dist/es2019/syncedBlockPlugin.js +38 -15
  20. package/dist/es2019/ui/floating-toolbar.js +3 -0
  21. package/dist/esm/nodeviews/lazySyncedBlock.js +15 -0
  22. package/dist/esm/nodeviews/syncedBlock.js +129 -0
  23. package/dist/esm/pm-plugins/actions.js +19 -0
  24. package/dist/esm/pm-plugins/main.js +10 -22
  25. package/dist/esm/syncedBlockPlugin.js +35 -5
  26. package/dist/esm/ui/floating-toolbar.js +5 -0
  27. package/dist/types/index.d.ts +1 -2
  28. package/dist/types/nodeviews/lazySyncedBlock.d.ts +3 -0
  29. package/dist/types/nodeviews/syncedBlock.d.ts +28 -0
  30. package/dist/types/pm-plugins/actions.d.ts +2 -0
  31. package/dist/types/pm-plugins/main.d.ts +3 -1
  32. package/dist/types/syncedBlockPluginType.d.ts +36 -1
  33. package/dist/types/ui/floating-toolbar.d.ts +2 -0
  34. package/dist/types-ts4.5/index.d.ts +1 -2
  35. package/dist/types-ts4.5/nodeviews/lazySyncedBlock.d.ts +3 -0
  36. package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +28 -0
  37. package/dist/types-ts4.5/pm-plugins/actions.d.ts +2 -0
  38. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -1
  39. package/dist/types-ts4.5/syncedBlockPluginType.d.ts +36 -1
  40. package/dist/types-ts4.5/ui/floating-toolbar.d.ts +2 -0
  41. package/package.json +5 -9
  42. package/SyncedBlock/package.json +0 -15
  43. package/dist/cjs/pm-plugins/SyncClient.js +0 -167
  44. package/dist/cjs/pm-plugins/utils.js +0 -19
  45. package/dist/cjs/types/index.js +0 -1
  46. package/dist/cjs/ui/extensions/synced-block/components/GlobalStyles.js +0 -25
  47. package/dist/cjs/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -25
  48. package/dist/cjs/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -25
  49. package/dist/cjs/ui/extensions/synced-block/constants.js +0 -32
  50. package/dist/cjs/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -11
  51. package/dist/cjs/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -29
  52. package/dist/cjs/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -121
  53. package/dist/cjs/ui/extensions/synced-block/index.js +0 -19
  54. package/dist/cjs/ui/extensions/synced-block/manifest.js +0 -281
  55. package/dist/cjs/ui/extensions/synced-block/utils/ari.js +0 -29
  56. package/dist/cjs/ui/extensions/synced-block/utils/content-property.js +0 -159
  57. package/dist/cjs/ui/extensions/synced-block/utils/synced-block.js +0 -65
  58. package/dist/es2019/pm-plugins/SyncClient.js +0 -102
  59. package/dist/es2019/pm-plugins/utils.js +0 -13
  60. package/dist/es2019/types/index.js +0 -0
  61. package/dist/es2019/ui/extensions/synced-block/components/GlobalStyles.js +0 -18
  62. package/dist/es2019/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -19
  63. package/dist/es2019/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -19
  64. package/dist/es2019/ui/extensions/synced-block/constants.js +0 -26
  65. package/dist/es2019/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -5
  66. package/dist/es2019/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -24
  67. package/dist/es2019/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -107
  68. package/dist/es2019/ui/extensions/synced-block/index.js +0 -5
  69. package/dist/es2019/ui/extensions/synced-block/manifest.js +0 -172
  70. package/dist/es2019/ui/extensions/synced-block/utils/ari.js +0 -19
  71. package/dist/es2019/ui/extensions/synced-block/utils/content-property.js +0 -108
  72. package/dist/es2019/ui/extensions/synced-block/utils/synced-block.js +0 -57
  73. package/dist/esm/pm-plugins/SyncClient.js +0 -160
  74. package/dist/esm/pm-plugins/utils.js +0 -13
  75. package/dist/esm/types/index.js +0 -0
  76. package/dist/esm/ui/extensions/synced-block/components/GlobalStyles.js +0 -18
  77. package/dist/esm/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -18
  78. package/dist/esm/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -18
  79. package/dist/esm/ui/extensions/synced-block/constants.js +0 -26
  80. package/dist/esm/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -5
  81. package/dist/esm/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -23
  82. package/dist/esm/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -114
  83. package/dist/esm/ui/extensions/synced-block/index.js +0 -5
  84. package/dist/esm/ui/extensions/synced-block/manifest.js +0 -274
  85. package/dist/esm/ui/extensions/synced-block/utils/ari.js +0 -23
  86. package/dist/esm/ui/extensions/synced-block/utils/content-property.js +0 -153
  87. package/dist/esm/ui/extensions/synced-block/utils/synced-block.js +0 -58
  88. package/dist/types/pm-plugins/SyncClient.d.ts +0 -14
  89. package/dist/types/pm-plugins/utils.d.ts +0 -5
  90. package/dist/types/types/index.d.ts +0 -3
  91. package/dist/types/ui/extensions/synced-block/components/GlobalStyles.d.ts +0 -6
  92. package/dist/types/ui/extensions/synced-block/components/SyncedBlockLiveView.d.ts +0 -7
  93. package/dist/types/ui/extensions/synced-block/components/SyncedBlockRenderer.d.ts +0 -7
  94. package/dist/types/ui/extensions/synced-block/constants.d.ts +0 -8
  95. package/dist/types/ui/extensions/synced-block/getSyncedBlockExtensionProvider.d.ts +0 -3
  96. package/dist/types/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.d.ts +0 -6
  97. package/dist/types/ui/extensions/synced-block/hooks/usePollContentProperty.d.ts +0 -7
  98. package/dist/types/ui/extensions/synced-block/index.d.ts +0 -2
  99. package/dist/types/ui/extensions/synced-block/manifest.d.ts +0 -3
  100. package/dist/types/ui/extensions/synced-block/utils/ari.d.ts +0 -4
  101. package/dist/types/ui/extensions/synced-block/utils/content-property.d.ts +0 -33
  102. package/dist/types/ui/extensions/synced-block/utils/synced-block.d.ts +0 -24
  103. package/dist/types-ts4.5/pm-plugins/SyncClient.d.ts +0 -14
  104. package/dist/types-ts4.5/pm-plugins/utils.d.ts +0 -5
  105. package/dist/types-ts4.5/types/index.d.ts +0 -3
  106. package/dist/types-ts4.5/ui/extensions/synced-block/components/GlobalStyles.d.ts +0 -6
  107. package/dist/types-ts4.5/ui/extensions/synced-block/components/SyncedBlockLiveView.d.ts +0 -7
  108. package/dist/types-ts4.5/ui/extensions/synced-block/components/SyncedBlockRenderer.d.ts +0 -7
  109. package/dist/types-ts4.5/ui/extensions/synced-block/constants.d.ts +0 -8
  110. package/dist/types-ts4.5/ui/extensions/synced-block/getSyncedBlockExtensionProvider.d.ts +0 -3
  111. package/dist/types-ts4.5/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.d.ts +0 -6
  112. package/dist/types-ts4.5/ui/extensions/synced-block/hooks/usePollContentProperty.d.ts +0 -7
  113. package/dist/types-ts4.5/ui/extensions/synced-block/index.d.ts +0 -2
  114. package/dist/types-ts4.5/ui/extensions/synced-block/manifest.d.ts +0 -3
  115. package/dist/types-ts4.5/ui/extensions/synced-block/utils/ari.d.ts +0 -4
  116. package/dist/types-ts4.5/ui/extensions/synced-block/utils/content-property.d.ts +0 -33
  117. package/dist/types-ts4.5/ui/extensions/synced-block/utils/synced-block.d.ts +0 -24
@@ -1,281 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getSyncedBlockManifest = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
- var _react = _interopRequireDefault(require("react"));
12
- var _clipboard = require("@atlaskit/editor-common/clipboard");
13
- var _model = require("@atlaskit/editor-prosemirror/model");
14
- var _smartLink = _interopRequireDefault(require("@atlaskit/icon/core/smart-link"));
15
- var _SyncedBlockLiveView = _interopRequireDefault(require("./components/SyncedBlockLiveView"));
16
- var _constants = require("./constants");
17
- var _ari = require("./utils/ari");
18
- var _contentProperty = require("./utils/content-property");
19
- var _syncedBlock = require("./utils/synced-block");
20
- var getRandomId = function getRandomId() {
21
- if (!globalThis.crypto || typeof globalThis.crypto.randomUUID !== 'function') {
22
- return new Date().toISOString();
23
- }
24
- return globalThis.crypto.randomUUID();
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
- };
49
-
50
- // Remaining tasks
51
- // - Better location for content sync implementation – currently done in SyncedBlockSource renderer which won't work in editor
52
- // - Could implement an editor plugin to do this, if there's no native way to do it with extensions
53
- // - Implement separate content property for storage of the metadata of a synced block, separate from the content
54
- // - Update polling to use the metadata content property, then if metadata updated, fetch the content property
55
- // - Investigate re-rendering of SyncedBlockReference in editor on every document change (is this just atlaskit behavior?)
56
- // - On copy of the synced block, transform into a reference
57
- // - Move implementation into Confluence and test in branch environment
58
- // - Dealing with orphaned synced block content properties data
59
- // - Getting current page id in editor context and the cloud id
60
- // - Explore hiding the frame for the extension in the editor, currently using `__hideFrame: true` and commented code to enable
61
- var getSyncedBlockManifest = exports.getSyncedBlockManifest = function getSyncedBlockManifest(schema) {
62
- return {
63
- title: 'Synced Block',
64
- type: _syncedBlock.SYNCED_BLOCK_EXTENSION_TYPE,
65
- key: _syncedBlock.SYNCED_BLOCK_EXTENSION_KEY,
66
- description: 'Synced block spike',
67
- icons: {
68
- // Ignored via go/ees005
69
- // eslint-disable-next-line require-await
70
- '48': function () {
71
- var _2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
72
- return _regenerator.default.wrap(function _callee$(_context) {
73
- while (1) switch (_context.prev = _context.next) {
74
- case 0:
75
- return _context.abrupt("return", function () {
76
- return /*#__PURE__*/_react.default.createElement(_smartLink.default, {
77
- label: "Synced Block",
78
- size: "medium"
79
- });
80
- });
81
- case 1:
82
- case "end":
83
- return _context.stop();
84
- }
85
- }, _callee);
86
- }));
87
- function _() {
88
- return _2.apply(this, arguments);
89
- }
90
- return _;
91
- }()
92
- },
93
- modules: {
94
- quickInsert: [{
95
- key: 'quick-insert-synced-block-source',
96
- action: function () {
97
- var _action = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_api) {
98
- var contentPropertyKey, content, value, contentProperty, attributes;
99
- return _regenerator.default.wrap(function _callee2$(_context2) {
100
- while (1) switch (_context2.prev = _context2.next) {
101
- case 0:
102
- contentPropertyKey = "synced-block-" + getRandomId();
103
- content = (0, _syncedBlock.getDefaultSyncedBlockContent)();
104
- value = (0, _syncedBlock.stringifySyncedBlockContentPropertyValue)({
105
- adf: content
106
- });
107
- _context2.next = 5;
108
- return (0, _contentProperty.createContentProperty)({
109
- pageId: (0, _constants.getPageId)(),
110
- key: contentPropertyKey,
111
- value: value
112
- });
113
- case 5:
114
- contentProperty = _context2.sent;
115
- attributes = {
116
- extensionType: _syncedBlock.SYNCED_BLOCK_EXTENSION_TYPE,
117
- extensionKey: _syncedBlock.SYNCED_BLOCK_SOURCE_KEY,
118
- parameters: {
119
- sourceDocumentAri: (0, _ari.getConfluencePageAri)((0, _constants.getPageId)()),
120
- contentAri: (0, _ari.getContentPropertyAri)(contentProperty.id),
121
- contentPropertyKey: contentPropertyKey
122
- },
123
- localId: 'testId'
124
- };
125
- content.attrs = attributes;
126
- return _context2.abrupt("return", content);
127
- case 9:
128
- case "end":
129
- return _context2.stop();
130
- }
131
- }, _callee2);
132
- }));
133
- function action(_x) {
134
- return _action.apply(this, arguments);
135
- }
136
- return action;
137
- }()
138
- }],
139
- nodes: (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _syncedBlock.SYNCED_BLOCK_SOURCE_NODE, {
140
- type: 'bodiedExtension',
141
- // Ignored via go/ees005
142
- // eslint-disable-next-line require-await
143
- render: function () {
144
- var _render = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
145
- return _regenerator.default.wrap(function _callee3$(_context3) {
146
- while (1) switch (_context3.prev = _context3.next) {
147
- case 0:
148
- return _context3.abrupt("return", function (props) {
149
- if (!(0, _syncedBlock.isSyncedBlockAttributes)(props.node)) {
150
- return null;
151
- }
152
- var _props$node$parameter = props.node.parameters,
153
- sourceDocumentAri = _props$node$parameter.sourceDocumentAri,
154
- contentAri = _props$node$parameter.contentAri;
155
- return /*#__PURE__*/_react.default.createElement(_SyncedBlockLiveView.default, {
156
- sourceDocumentAri: sourceDocumentAri,
157
- contentAri: contentAri
158
- });
159
- });
160
- case 1:
161
- case "end":
162
- return _context3.stop();
163
- }
164
- }, _callee3);
165
- }));
166
- function render() {
167
- return _render.apply(this, arguments);
168
- }
169
- return render;
170
- }(),
171
- // @ts-expect-error
172
- __hideFrame: true
173
- }), _syncedBlock.SYNCED_BLOCK_REFERENCE_NODE, {
174
- type: 'extension',
175
- // Ignored via go/ees005
176
- // eslint-disable-next-line require-await
177
- render: function () {
178
- var _render2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
179
- return _regenerator.default.wrap(function _callee4$(_context4) {
180
- while (1) switch (_context4.prev = _context4.next) {
181
- case 0:
182
- return _context4.abrupt("return", function (props) {
183
- if (!(0, _syncedBlock.isSyncedBlockAttributes)(props.node)) {
184
- return null;
185
- }
186
- var _props$node$parameter2 = props.node.parameters,
187
- sourceDocumentAri = _props$node$parameter2.sourceDocumentAri,
188
- contentAri = _props$node$parameter2.contentAri;
189
- return /*#__PURE__*/_react.default.createElement(_SyncedBlockLiveView.default, {
190
- sourceDocumentAri: sourceDocumentAri,
191
- contentAri: contentAri
192
- });
193
- });
194
- case 1:
195
- case "end":
196
- return _context4.stop();
197
- }
198
- }, _callee4);
199
- }));
200
- function render() {
201
- return _render2.apply(this, arguments);
202
- }
203
- return render;
204
- }(),
205
- // @ts-expect-error
206
- __hideFrame: true
207
- }),
208
- contextualToolbars: [{
209
- context: {
210
- type: 'extension',
211
- nodeType: 'bodiedExtension',
212
- extensionType: _syncedBlock.SYNCED_BLOCK_EXTENSION_TYPE,
213
- extensionKey: _syncedBlock.SYNCED_BLOCK_SOURCE_KEY
214
- },
215
- toolbarItems: [{
216
- key: 'toolbar-item-key',
217
- label: 'Referenece',
218
- display: 'icon',
219
- tooltip: 'Copy reference to clipboard',
220
- // Ignored via go/ees005
221
- // eslint-disable-next-line require-await
222
- icon: function () {
223
- var _icon = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
224
- return _regenerator.default.wrap(function _callee5$(_context5) {
225
- while (1) switch (_context5.prev = _context5.next) {
226
- case 0:
227
- return _context5.abrupt("return", function () {
228
- return /*#__PURE__*/_react.default.createElement(_smartLink.default, {
229
- label: "Synced Block",
230
- size: "medium"
231
- });
232
- });
233
- case 1:
234
- case "end":
235
- return _context5.stop();
236
- }
237
- }, _callee5);
238
- }));
239
- function icon() {
240
- return _icon.apply(this, arguments);
241
- }
242
- return icon;
243
- }(),
244
- // Ignored via go/ees005
245
- // eslint-disable-next-line require-await
246
- action: function () {
247
- var _action2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(contextNode) {
248
- var _contextNode$attrs, _contextNode$attrs2;
249
- return _regenerator.default.wrap(function _callee6$(_context6) {
250
- while (1) switch (_context6.prev = _context6.next) {
251
- case 0:
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) {}
266
- case 1:
267
- case "end":
268
- return _context6.stop();
269
- }
270
- }, _callee6);
271
- }));
272
- function action(_x2) {
273
- return _action2.apply(this, arguments);
274
- }
275
- return action;
276
- }()
277
- }]
278
- }]
279
- }
280
- };
281
- };
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getPageIdFromAri = exports.getContentPropertyIdFromAri = exports.getContentPropertyAri = exports.getConfluencePageAri = void 0;
7
- var _constants = require("../constants");
8
- var getConfluencePageAri = exports.getConfluencePageAri = function getConfluencePageAri(pageId) {
9
- return "ari:cloud:confluence:".concat((0, _constants.getCloudId)(), ":page/").concat(pageId);
10
- };
11
- var getPageIdFromAri = exports.getPageIdFromAri = function getPageIdFromAri(ari) {
12
- // eslint-disable-next-line require-unicode-regexp
13
- var match = ari.match(/ari:cloud:confluence:[^:]+:page\/(\d+)/);
14
- if (match) {
15
- return match[1];
16
- }
17
- throw new Error("Invalid page ARI: ".concat(ari));
18
- };
19
- var getContentPropertyAri = exports.getContentPropertyAri = function getContentPropertyAri(contentPropertyId) {
20
- return "ari:cloud:confluence:".concat((0, _constants.getCloudId)(), ":content/").concat(contentPropertyId);
21
- };
22
- var getContentPropertyIdFromAri = exports.getContentPropertyIdFromAri = function getContentPropertyIdFromAri(ari) {
23
- // eslint-disable-next-line require-unicode-regexp
24
- var match = ari.match(/ari:cloud:confluence:[^:]+:content\/([^/]+)/);
25
- if (match) {
26
- return match[1];
27
- }
28
- throw new Error("Invalid content property ARI: ".concat(ari));
29
- };
@@ -1,159 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.updateContentProperty = exports.getContentProperty = exports.createContentProperty = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _constants = require("../constants");
11
- var _ari = require("./ari");
12
- // Uncomment for proxy in Atlaskit, which will route to hello.atlassian.net
13
- // const BASE_URL = 'https://localhost:9876';
14
- var BASE_URL = "/gateway/api/ex/confluence/".concat((0, _constants.getCloudId)());
15
- var API_BASE_URL = "".concat(BASE_URL, "/wiki/api/v2");
16
- var COMMON_HEADERS = {
17
- 'Content-Type': 'application/json',
18
- Accept: 'application/json'
19
- };
20
- var getContentPropertiesUrl = function getContentPropertiesUrl(_ref) {
21
- var pageId = _ref.pageId,
22
- contentPropertyId = _ref.contentPropertyId;
23
- var url = "".concat(API_BASE_URL, "/pages/").concat(pageId, "/properties");
24
- if (contentPropertyId) {
25
- return "".concat(url, "/").concat(contentPropertyId);
26
- }
27
- return url;
28
- };
29
- var getGraphQLPropertiesUrl = function getGraphQLPropertiesUrl() {
30
- return "/cgraphql/api/graphql";
31
- };
32
- var createContentProperty = exports.createContentProperty = /*#__PURE__*/function () {
33
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref2) {
34
- var pageId, key, value, url, body, response, contentProperty;
35
- return _regenerator.default.wrap(function _callee$(_context) {
36
- while (1) switch (_context.prev = _context.next) {
37
- case 0:
38
- pageId = _ref2.pageId, key = _ref2.key, value = _ref2.value;
39
- url = getContentPropertiesUrl({
40
- pageId: pageId
41
- });
42
- body = JSON.stringify({
43
- key: key,
44
- value: value
45
- });
46
- _context.next = 5;
47
- return fetch(url, {
48
- method: 'POST',
49
- headers: COMMON_HEADERS,
50
- body: body
51
- });
52
- case 5:
53
- response = _context.sent;
54
- if (response.ok) {
55
- _context.next = 8;
56
- break;
57
- }
58
- throw new Error("Failed to create content property: ".concat(response.statusText));
59
- case 8:
60
- _context.next = 10;
61
- return response.json();
62
- case 10:
63
- contentProperty = _context.sent;
64
- return _context.abrupt("return", contentProperty);
65
- case 12:
66
- case "end":
67
- return _context.stop();
68
- }
69
- }, _callee);
70
- }));
71
- return function createContentProperty(_x) {
72
- return _ref3.apply(this, arguments);
73
- };
74
- }();
75
- var getContentProperty = exports.getContentProperty = /*#__PURE__*/function () {
76
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref4) {
77
- var pageId, contentPropertyId, signal, url, response, contentProperty;
78
- return _regenerator.default.wrap(function _callee2$(_context2) {
79
- while (1) switch (_context2.prev = _context2.next) {
80
- case 0:
81
- pageId = _ref4.pageId, contentPropertyId = _ref4.contentPropertyId, signal = _ref4.signal;
82
- url = getContentPropertiesUrl({
83
- pageId: pageId,
84
- contentPropertyId: contentPropertyId
85
- });
86
- _context2.next = 4;
87
- return fetch(url, {
88
- method: 'GET',
89
- headers: COMMON_HEADERS,
90
- signal: signal
91
- });
92
- case 4:
93
- response = _context2.sent;
94
- if (response.ok) {
95
- _context2.next = 7;
96
- break;
97
- }
98
- throw new Error("Failed to get content property: ".concat(response.statusText));
99
- case 7:
100
- _context2.next = 9;
101
- return response.json();
102
- case 9:
103
- contentProperty = _context2.sent;
104
- return _context2.abrupt("return", contentProperty);
105
- case 11:
106
- case "end":
107
- return _context2.stop();
108
- }
109
- }, _callee2);
110
- }));
111
- return function getContentProperty(_x2) {
112
- return _ref5.apply(this, arguments);
113
- };
114
- }();
115
- var getQuery = function getQuery(documentARI, key, value) {
116
- return "mutation {\n\t confluence {\n\t updateValuePageProperty(input: {\n\t pageId: \"".concat(documentARI, "\",\n\t key: \"").concat(key, "\",\n\t value: \"").concat(value, "\",\n\t useSameVersion: true\n\t }) {\n\t pageProperty {\n\t key,\n\t value\n\t }\n\t }\n\t }\n\t}");
117
- };
118
- var updateContentProperty = exports.updateContentProperty = /*#__PURE__*/function () {
119
- var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(_ref6) {
120
- var pageId, key, value, url, documentARI, query, bodyData, response, contentProperty;
121
- return _regenerator.default.wrap(function _callee3$(_context3) {
122
- while (1) switch (_context3.prev = _context3.next) {
123
- case 0:
124
- pageId = _ref6.pageId, key = _ref6.key, value = _ref6.value;
125
- url = getGraphQLPropertiesUrl();
126
- documentARI = (0, _ari.getConfluencePageAri)(pageId); // eslint-disable-next-line require-unicode-regexp
127
- query = getQuery(documentARI, key, value.replace(/"/g, '\\"'));
128
- bodyData = {
129
- query: query
130
- };
131
- _context3.next = 7;
132
- return fetch(url, {
133
- method: 'POST',
134
- headers: COMMON_HEADERS,
135
- body: JSON.stringify(bodyData)
136
- });
137
- case 7:
138
- response = _context3.sent;
139
- if (response.ok) {
140
- _context3.next = 10;
141
- break;
142
- }
143
- throw new Error("Failed to update content property: ".concat(response.statusText));
144
- case 10:
145
- _context3.next = 12;
146
- return response.json();
147
- case 12:
148
- contentProperty = _context3.sent;
149
- return _context3.abrupt("return", contentProperty);
150
- case 14:
151
- case "end":
152
- return _context3.stop();
153
- }
154
- }, _callee3);
155
- }));
156
- return function updateContentProperty(_x3) {
157
- return _ref7.apply(this, arguments);
158
- };
159
- }();
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.stringifySyncedBlockContentPropertyValue = exports.parseSyncedBlockContentPropertyValue = exports.isSyncedBlockAttributes = exports.getDefaultSyncedBlockContent = exports.SYNCED_BLOCK_SOURCE_NODE = exports.SYNCED_BLOCK_SOURCE_KEY = exports.SYNCED_BLOCK_REFERENCE_NODE = exports.SYNCED_BLOCK_REFERENCE_KEY = exports.SYNCED_BLOCK_EXTENSION_TYPE = exports.SYNCED_BLOCK_EXTENSION_KEY = void 0;
8
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
- var SYNCED_BLOCK_EXTENSION_TYPE = exports.SYNCED_BLOCK_EXTENSION_TYPE = 'com.atlassian.platform.extensions';
10
- var SYNCED_BLOCK_EXTENSION_KEY = exports.SYNCED_BLOCK_EXTENSION_KEY = 'synced-block';
11
- var SYNCED_BLOCK_SOURCE_NODE = exports.SYNCED_BLOCK_SOURCE_NODE = 'source';
12
- var SYNCED_BLOCK_SOURCE_KEY = exports.SYNCED_BLOCK_SOURCE_KEY = "".concat(SYNCED_BLOCK_EXTENSION_KEY, ":").concat(SYNCED_BLOCK_SOURCE_NODE);
13
- var SYNCED_BLOCK_REFERENCE_NODE = exports.SYNCED_BLOCK_REFERENCE_NODE = 'reference';
14
- var SYNCED_BLOCK_REFERENCE_KEY = exports.SYNCED_BLOCK_REFERENCE_KEY = "".concat(SYNCED_BLOCK_EXTENSION_KEY, ":").concat(SYNCED_BLOCK_REFERENCE_NODE);
15
- var isSyncedBlockAttributes = exports.isSyncedBlockAttributes = function isSyncedBlockAttributes(attributes) {
16
- return !!attributes && (0, _typeof2.default)(attributes) === 'object' && 'extensionKey' in attributes && (attributes.extensionKey === SYNCED_BLOCK_SOURCE_KEY || attributes.extensionKey === SYNCED_BLOCK_REFERENCE_KEY);
17
- };
18
- var getDefaultSyncedBlockContent = exports.getDefaultSyncedBlockContent = function getDefaultSyncedBlockContent() {
19
- var attributes = {
20
- extensionType: SYNCED_BLOCK_EXTENSION_TYPE,
21
- extensionKey: SYNCED_BLOCK_SOURCE_KEY,
22
- parameters: {
23
- sourceDocumentAri: '',
24
- contentAri: '',
25
- contentPropertyKey: ''
26
- },
27
- localId: ''
28
- };
29
- return {
30
- type: 'bodiedExtension',
31
- attrs: attributes,
32
- content: [{
33
- type: 'paragraph',
34
- content: [{
35
- type: 'text',
36
- text: 'This is a synced block. Please edit the source document to update the content.'
37
- }]
38
- }]
39
- };
40
- };
41
- var parseSyncedBlockContentPropertyValue = exports.parseSyncedBlockContentPropertyValue = function parseSyncedBlockContentPropertyValue(value) {
42
- try {
43
- if (typeof value === 'string') {
44
- return JSON.parse(value);
45
- }
46
- return value;
47
- } catch (error) {
48
- // eslint-disable-next-line no-console
49
- console.error('Failed to parse synced block content:', error);
50
- return {
51
- adf: getDefaultSyncedBlockContent()
52
- };
53
- }
54
- };
55
- var stringifySyncedBlockContentPropertyValue = exports.stringifySyncedBlockContentPropertyValue = function stringifySyncedBlockContentPropertyValue(value) {
56
- try {
57
- return JSON.stringify(value);
58
- } catch (error) {
59
- // eslint-disable-next-line no-console
60
- console.error('Failed to serialize synced block content:', error);
61
- return JSON.stringify({
62
- adf: getDefaultSyncedBlockContent()
63
- });
64
- }
65
- };
@@ -1,102 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { JSONTransformer } from '@atlaskit/editor-json-transformer';
3
- import { getContentPropertyIdFromAri, getPageIdFromAri } from '../ui/extensions/synced-block/utils/ari';
4
- import { getContentProperty, updateContentProperty } from '../ui/extensions/synced-block/utils/content-property';
5
- import { parseSyncedBlockContentPropertyValue, stringifySyncedBlockContentPropertyValue } from '../ui/extensions/synced-block/utils/synced-block';
6
- const transformer = new JSONTransformer();
7
- const toJSON = node => transformer.encodeNode(node);
8
- const getCacheKey = ({
9
- sourceDocumentAri,
10
- contentAri,
11
- contentPropertyKey
12
- }) => `${sourceDocumentAri}-${contentAri}-${contentPropertyKey}`;
13
- export class SyncClient {
14
- constructor() {
15
- _defineProperty(this, "requestMap", new Map());
16
- this.requestMap = new Map();
17
- }
18
- getRequestState(key) {
19
- return this.requestMap.get(key);
20
- }
21
- setRequestState(key, state) {
22
- this.requestMap.set(key, state);
23
- }
24
- async sendRequest({
25
- sourceDocumentAri,
26
- contentAri,
27
- contentPropertyKey,
28
- value
29
- }) {
30
- const pageId = getPageIdFromAri(sourceDocumentAri);
31
- const contentPropertyId = getContentPropertyIdFromAri(contentAri);
32
- try {
33
- const contentProperty = await getContentProperty({
34
- pageId,
35
- contentPropertyId
36
- });
37
- const updatedValue = stringifySyncedBlockContentPropertyValue({
38
- ...parseSyncedBlockContentPropertyValue(contentProperty.value),
39
- ...JSON.parse(value)
40
- });
41
- await updateContentProperty({
42
- pageId,
43
- key: contentPropertyKey,
44
- value: updatedValue,
45
- signal: undefined
46
- });
47
- } catch (error) {
48
- // eslint-disable-next-line no-console
49
- console.error('Failed to update content property:', error);
50
- }
51
- }
52
- syncContent({
53
- sourceDocumentAri,
54
- contentAri,
55
- contentPropertyKey,
56
- node
57
- }) {
58
- const nodeAdf = toJSON(node);
59
- const key = getCacheKey({
60
- sourceDocumentAri,
61
- contentAri,
62
- contentPropertyKey
63
- });
64
- const value = stringifySyncedBlockContentPropertyValue({
65
- adf: nodeAdf
66
- });
67
- const requestState = this.getRequestState(key) || {
68
- timeout: null,
69
- pendingValue: null,
70
- isSending: false
71
- };
72
- requestState.pendingValue = value;
73
- if (requestState.isSending) {
74
- return;
75
- }
76
- if (requestState.timeout) {
77
- clearTimeout(requestState.timeout);
78
- }
79
- const send = async () => {
80
- if (requestState.isSending) {
81
- return;
82
- }
83
- requestState.isSending = true;
84
- try {
85
- await this.sendRequest({
86
- sourceDocumentAri,
87
- contentAri,
88
- contentPropertyKey,
89
- value: requestState.pendingValue || ''
90
- });
91
- requestState.pendingValue = null;
92
- } catch (error) {
93
- // eslint-disable-next-line no-console
94
- console.error('Failed to send synced block content:', error);
95
- } finally {
96
- requestState.isSending = false;
97
- }
98
- };
99
- requestState.timeout = setTimeout(send, 1000);
100
- this.setRequestState(key, requestState);
101
- }
102
- }
@@ -1,13 +0,0 @@
1
- import { isSyncedBlockAttributes } from '../ui/extensions/synced-block/utils/synced-block';
2
- export const findSyncedBlockParent = $pos => {
3
- for (let i = 0; i <= $pos.depth; i++) {
4
- const node = $pos.node(i);
5
- if (isSyncedBlockAttributes(node.attrs)) {
6
- return {
7
- node,
8
- attributes: node.attrs
9
- };
10
- }
11
- }
12
- return;
13
- };
File without changes
@@ -1,18 +0,0 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
5
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @atlaskit/ui-styling-standard/no-global-styles
6
- import { css, Global, jsx } from '@emotion/react';
7
- const extensionStyles = css({
8
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
9
- '[extensionkey="synced-block:reference"] .ak-renderer-wrapper > div:last-of-type': {
10
- padding: "var(--ds-space-250, 20px)",
11
- paddingRight: "var(--ds-space-250, 20px)"
12
- }
13
- });
14
- export const GlobalStylesWrapper = () => {
15
- return jsx(Global, {
16
- styles: [extensionStyles]
17
- });
18
- };