@atlaskit/editor-plugin-synced-block 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -16
- package/afm-cc/tsconfig.json +0 -12
- package/afm-dev-agents/tsconfig.json +0 -12
- package/afm-jira/tsconfig.json +0 -12
- package/afm-passionfruit/tsconfig.json +0 -12
- package/afm-post-office/tsconfig.json +0 -12
- package/afm-rovo-extension/tsconfig.json +0 -12
- package/afm-townsquare/tsconfig.json +0 -12
- package/dist/cjs/nodeviews/lazySyncedBlock.js +26 -0
- package/dist/cjs/nodeviews/syncedBlock.js +137 -0
- package/dist/cjs/pm-plugins/actions.js +25 -0
- package/dist/cjs/pm-plugins/main.js +10 -22
- package/dist/cjs/syncedBlockPlugin.js +35 -5
- package/dist/cjs/ui/floating-toolbar.js +11 -0
- package/dist/es2019/nodeviews/lazySyncedBlock.js +16 -0
- package/dist/es2019/nodeviews/syncedBlock.js +105 -0
- package/dist/es2019/pm-plugins/actions.js +19 -0
- package/dist/es2019/pm-plugins/main.js +10 -25
- package/dist/es2019/syncedBlockPlugin.js +38 -15
- package/dist/es2019/ui/floating-toolbar.js +3 -0
- package/dist/esm/nodeviews/lazySyncedBlock.js +15 -0
- package/dist/esm/nodeviews/syncedBlock.js +129 -0
- package/dist/esm/pm-plugins/actions.js +19 -0
- package/dist/esm/pm-plugins/main.js +10 -22
- package/dist/esm/syncedBlockPlugin.js +35 -5
- package/dist/esm/ui/floating-toolbar.js +5 -0
- package/dist/types/index.d.ts +1 -2
- package/dist/types/nodeviews/lazySyncedBlock.d.ts +3 -0
- package/dist/types/nodeviews/syncedBlock.d.ts +28 -0
- package/dist/types/pm-plugins/actions.d.ts +2 -0
- package/dist/types/pm-plugins/main.d.ts +3 -1
- package/dist/types/syncedBlockPluginType.d.ts +36 -1
- package/dist/types/ui/floating-toolbar.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +1 -2
- package/dist/types-ts4.5/nodeviews/lazySyncedBlock.d.ts +3 -0
- package/dist/types-ts4.5/nodeviews/syncedBlock.d.ts +28 -0
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -1
- package/dist/types-ts4.5/syncedBlockPluginType.d.ts +36 -1
- package/dist/types-ts4.5/ui/floating-toolbar.d.ts +2 -0
- package/package.json +5 -9
- package/SyncedBlock/package.json +0 -15
- package/dist/cjs/pm-plugins/SyncClient.js +0 -167
- package/dist/cjs/pm-plugins/utils.js +0 -19
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/ui/extensions/synced-block/components/GlobalStyles.js +0 -25
- package/dist/cjs/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -25
- package/dist/cjs/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -25
- package/dist/cjs/ui/extensions/synced-block/constants.js +0 -32
- package/dist/cjs/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -11
- package/dist/cjs/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -29
- package/dist/cjs/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -121
- package/dist/cjs/ui/extensions/synced-block/index.js +0 -19
- package/dist/cjs/ui/extensions/synced-block/manifest.js +0 -281
- package/dist/cjs/ui/extensions/synced-block/utils/ari.js +0 -29
- package/dist/cjs/ui/extensions/synced-block/utils/content-property.js +0 -159
- package/dist/cjs/ui/extensions/synced-block/utils/synced-block.js +0 -65
- package/dist/es2019/pm-plugins/SyncClient.js +0 -102
- package/dist/es2019/pm-plugins/utils.js +0 -13
- package/dist/es2019/types/index.js +0 -0
- package/dist/es2019/ui/extensions/synced-block/components/GlobalStyles.js +0 -18
- package/dist/es2019/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -19
- package/dist/es2019/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -19
- package/dist/es2019/ui/extensions/synced-block/constants.js +0 -26
- package/dist/es2019/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -5
- package/dist/es2019/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -24
- package/dist/es2019/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -107
- package/dist/es2019/ui/extensions/synced-block/index.js +0 -5
- package/dist/es2019/ui/extensions/synced-block/manifest.js +0 -172
- package/dist/es2019/ui/extensions/synced-block/utils/ari.js +0 -19
- package/dist/es2019/ui/extensions/synced-block/utils/content-property.js +0 -108
- package/dist/es2019/ui/extensions/synced-block/utils/synced-block.js +0 -57
- package/dist/esm/pm-plugins/SyncClient.js +0 -160
- package/dist/esm/pm-plugins/utils.js +0 -13
- package/dist/esm/types/index.js +0 -0
- package/dist/esm/ui/extensions/synced-block/components/GlobalStyles.js +0 -18
- package/dist/esm/ui/extensions/synced-block/components/SyncedBlockLiveView.js +0 -18
- package/dist/esm/ui/extensions/synced-block/components/SyncedBlockRenderer.js +0 -18
- package/dist/esm/ui/extensions/synced-block/constants.js +0 -26
- package/dist/esm/ui/extensions/synced-block/getSyncedBlockExtensionProvider.js +0 -5
- package/dist/esm/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.js +0 -23
- package/dist/esm/ui/extensions/synced-block/hooks/usePollContentProperty.js +0 -114
- package/dist/esm/ui/extensions/synced-block/index.js +0 -5
- package/dist/esm/ui/extensions/synced-block/manifest.js +0 -274
- package/dist/esm/ui/extensions/synced-block/utils/ari.js +0 -23
- package/dist/esm/ui/extensions/synced-block/utils/content-property.js +0 -153
- package/dist/esm/ui/extensions/synced-block/utils/synced-block.js +0 -58
- package/dist/types/pm-plugins/SyncClient.d.ts +0 -14
- package/dist/types/pm-plugins/utils.d.ts +0 -5
- package/dist/types/types/index.d.ts +0 -3
- package/dist/types/ui/extensions/synced-block/components/GlobalStyles.d.ts +0 -6
- package/dist/types/ui/extensions/synced-block/components/SyncedBlockLiveView.d.ts +0 -7
- package/dist/types/ui/extensions/synced-block/components/SyncedBlockRenderer.d.ts +0 -7
- package/dist/types/ui/extensions/synced-block/constants.d.ts +0 -8
- package/dist/types/ui/extensions/synced-block/getSyncedBlockExtensionProvider.d.ts +0 -3
- package/dist/types/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.d.ts +0 -6
- package/dist/types/ui/extensions/synced-block/hooks/usePollContentProperty.d.ts +0 -7
- package/dist/types/ui/extensions/synced-block/index.d.ts +0 -2
- package/dist/types/ui/extensions/synced-block/manifest.d.ts +0 -3
- package/dist/types/ui/extensions/synced-block/utils/ari.d.ts +0 -4
- package/dist/types/ui/extensions/synced-block/utils/content-property.d.ts +0 -33
- package/dist/types/ui/extensions/synced-block/utils/synced-block.d.ts +0 -24
- package/dist/types-ts4.5/pm-plugins/SyncClient.d.ts +0 -14
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +0 -5
- package/dist/types-ts4.5/types/index.d.ts +0 -3
- package/dist/types-ts4.5/ui/extensions/synced-block/components/GlobalStyles.d.ts +0 -6
- package/dist/types-ts4.5/ui/extensions/synced-block/components/SyncedBlockLiveView.d.ts +0 -7
- package/dist/types-ts4.5/ui/extensions/synced-block/components/SyncedBlockRenderer.d.ts +0 -7
- package/dist/types-ts4.5/ui/extensions/synced-block/constants.d.ts +0 -8
- package/dist/types-ts4.5/ui/extensions/synced-block/getSyncedBlockExtensionProvider.d.ts +0 -3
- package/dist/types-ts4.5/ui/extensions/synced-block/hooks/useLiveSyncedBlockContent.d.ts +0 -6
- package/dist/types-ts4.5/ui/extensions/synced-block/hooks/usePollContentProperty.d.ts +0 -7
- package/dist/types-ts4.5/ui/extensions/synced-block/index.d.ts +0 -2
- package/dist/types-ts4.5/ui/extensions/synced-block/manifest.d.ts +0 -3
- package/dist/types-ts4.5/ui/extensions/synced-block/utils/ari.d.ts +0 -4
- package/dist/types-ts4.5/ui/extensions/synced-block/utils/content-property.d.ts +0 -33
- package/dist/types-ts4.5/ui/extensions/synced-block/utils/synced-block.d.ts +0 -24
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
-
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
9
|
-
import { getContentPropertyIdFromAri, getPageIdFromAri } from '../ui/extensions/synced-block/utils/ari';
|
|
10
|
-
import { getContentProperty, updateContentProperty } from '../ui/extensions/synced-block/utils/content-property';
|
|
11
|
-
import { parseSyncedBlockContentPropertyValue, stringifySyncedBlockContentPropertyValue } from '../ui/extensions/synced-block/utils/synced-block';
|
|
12
|
-
var transformer = new JSONTransformer();
|
|
13
|
-
var toJSON = function toJSON(node) {
|
|
14
|
-
return transformer.encodeNode(node);
|
|
15
|
-
};
|
|
16
|
-
var getCacheKey = function getCacheKey(_ref) {
|
|
17
|
-
var sourceDocumentAri = _ref.sourceDocumentAri,
|
|
18
|
-
contentAri = _ref.contentAri,
|
|
19
|
-
contentPropertyKey = _ref.contentPropertyKey;
|
|
20
|
-
return "".concat(sourceDocumentAri, "-").concat(contentAri, "-").concat(contentPropertyKey);
|
|
21
|
-
};
|
|
22
|
-
export var SyncClient = /*#__PURE__*/function () {
|
|
23
|
-
function SyncClient() {
|
|
24
|
-
_classCallCheck(this, SyncClient);
|
|
25
|
-
_defineProperty(this, "requestMap", new Map());
|
|
26
|
-
this.requestMap = new Map();
|
|
27
|
-
}
|
|
28
|
-
return _createClass(SyncClient, [{
|
|
29
|
-
key: "getRequestState",
|
|
30
|
-
value: function getRequestState(key) {
|
|
31
|
-
return this.requestMap.get(key);
|
|
32
|
-
}
|
|
33
|
-
}, {
|
|
34
|
-
key: "setRequestState",
|
|
35
|
-
value: function setRequestState(key, state) {
|
|
36
|
-
this.requestMap.set(key, state);
|
|
37
|
-
}
|
|
38
|
-
}, {
|
|
39
|
-
key: "sendRequest",
|
|
40
|
-
value: function () {
|
|
41
|
-
var _sendRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
|
|
42
|
-
var sourceDocumentAri, contentAri, contentPropertyKey, value, pageId, contentPropertyId, contentProperty, updatedValue;
|
|
43
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
44
|
-
while (1) switch (_context.prev = _context.next) {
|
|
45
|
-
case 0:
|
|
46
|
-
sourceDocumentAri = _ref2.sourceDocumentAri, contentAri = _ref2.contentAri, contentPropertyKey = _ref2.contentPropertyKey, value = _ref2.value;
|
|
47
|
-
pageId = getPageIdFromAri(sourceDocumentAri);
|
|
48
|
-
contentPropertyId = getContentPropertyIdFromAri(contentAri);
|
|
49
|
-
_context.prev = 3;
|
|
50
|
-
_context.next = 6;
|
|
51
|
-
return getContentProperty({
|
|
52
|
-
pageId: pageId,
|
|
53
|
-
contentPropertyId: contentPropertyId
|
|
54
|
-
});
|
|
55
|
-
case 6:
|
|
56
|
-
contentProperty = _context.sent;
|
|
57
|
-
updatedValue = stringifySyncedBlockContentPropertyValue(_objectSpread(_objectSpread({}, parseSyncedBlockContentPropertyValue(contentProperty.value)), JSON.parse(value)));
|
|
58
|
-
_context.next = 10;
|
|
59
|
-
return updateContentProperty({
|
|
60
|
-
pageId: pageId,
|
|
61
|
-
key: contentPropertyKey,
|
|
62
|
-
value: updatedValue,
|
|
63
|
-
signal: undefined
|
|
64
|
-
});
|
|
65
|
-
case 10:
|
|
66
|
-
_context.next = 15;
|
|
67
|
-
break;
|
|
68
|
-
case 12:
|
|
69
|
-
_context.prev = 12;
|
|
70
|
-
_context.t0 = _context["catch"](3);
|
|
71
|
-
// eslint-disable-next-line no-console
|
|
72
|
-
console.error('Failed to update content property:', _context.t0);
|
|
73
|
-
case 15:
|
|
74
|
-
case "end":
|
|
75
|
-
return _context.stop();
|
|
76
|
-
}
|
|
77
|
-
}, _callee, null, [[3, 12]]);
|
|
78
|
-
}));
|
|
79
|
-
function sendRequest(_x) {
|
|
80
|
-
return _sendRequest.apply(this, arguments);
|
|
81
|
-
}
|
|
82
|
-
return sendRequest;
|
|
83
|
-
}()
|
|
84
|
-
}, {
|
|
85
|
-
key: "syncContent",
|
|
86
|
-
value: function syncContent(_ref3) {
|
|
87
|
-
var _this = this;
|
|
88
|
-
var sourceDocumentAri = _ref3.sourceDocumentAri,
|
|
89
|
-
contentAri = _ref3.contentAri,
|
|
90
|
-
contentPropertyKey = _ref3.contentPropertyKey,
|
|
91
|
-
node = _ref3.node;
|
|
92
|
-
var nodeAdf = toJSON(node);
|
|
93
|
-
var key = getCacheKey({
|
|
94
|
-
sourceDocumentAri: sourceDocumentAri,
|
|
95
|
-
contentAri: contentAri,
|
|
96
|
-
contentPropertyKey: contentPropertyKey
|
|
97
|
-
});
|
|
98
|
-
var value = stringifySyncedBlockContentPropertyValue({
|
|
99
|
-
adf: nodeAdf
|
|
100
|
-
});
|
|
101
|
-
var requestState = this.getRequestState(key) || {
|
|
102
|
-
timeout: null,
|
|
103
|
-
pendingValue: null,
|
|
104
|
-
isSending: false
|
|
105
|
-
};
|
|
106
|
-
requestState.pendingValue = value;
|
|
107
|
-
if (requestState.isSending) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (requestState.timeout) {
|
|
111
|
-
clearTimeout(requestState.timeout);
|
|
112
|
-
}
|
|
113
|
-
var send = /*#__PURE__*/function () {
|
|
114
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
115
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
116
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
117
|
-
case 0:
|
|
118
|
-
if (!requestState.isSending) {
|
|
119
|
-
_context2.next = 2;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
return _context2.abrupt("return");
|
|
123
|
-
case 2:
|
|
124
|
-
requestState.isSending = true;
|
|
125
|
-
_context2.prev = 3;
|
|
126
|
-
_context2.next = 6;
|
|
127
|
-
return _this.sendRequest({
|
|
128
|
-
sourceDocumentAri: sourceDocumentAri,
|
|
129
|
-
contentAri: contentAri,
|
|
130
|
-
contentPropertyKey: contentPropertyKey,
|
|
131
|
-
value: requestState.pendingValue || ''
|
|
132
|
-
});
|
|
133
|
-
case 6:
|
|
134
|
-
requestState.pendingValue = null;
|
|
135
|
-
_context2.next = 12;
|
|
136
|
-
break;
|
|
137
|
-
case 9:
|
|
138
|
-
_context2.prev = 9;
|
|
139
|
-
_context2.t0 = _context2["catch"](3);
|
|
140
|
-
// eslint-disable-next-line no-console
|
|
141
|
-
console.error('Failed to send synced block content:', _context2.t0);
|
|
142
|
-
case 12:
|
|
143
|
-
_context2.prev = 12;
|
|
144
|
-
requestState.isSending = false;
|
|
145
|
-
return _context2.finish(12);
|
|
146
|
-
case 15:
|
|
147
|
-
case "end":
|
|
148
|
-
return _context2.stop();
|
|
149
|
-
}
|
|
150
|
-
}, _callee2, null, [[3, 9, 12, 15]]);
|
|
151
|
-
}));
|
|
152
|
-
return function send() {
|
|
153
|
-
return _ref4.apply(this, arguments);
|
|
154
|
-
};
|
|
155
|
-
}();
|
|
156
|
-
requestState.timeout = setTimeout(send, 1000);
|
|
157
|
-
this.setRequestState(key, requestState);
|
|
158
|
-
}
|
|
159
|
-
}]);
|
|
160
|
-
}();
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { isSyncedBlockAttributes } from '../ui/extensions/synced-block/utils/synced-block';
|
|
2
|
-
export var findSyncedBlockParent = function findSyncedBlockParent($pos) {
|
|
3
|
-
for (var i = 0; i <= $pos.depth; i++) {
|
|
4
|
-
var node = $pos.node(i);
|
|
5
|
-
if (isSyncedBlockAttributes(node.attrs)) {
|
|
6
|
-
return {
|
|
7
|
-
node: node,
|
|
8
|
-
attributes: node.attrs
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return;
|
|
13
|
-
};
|
package/dist/esm/types/index.js
DELETED
|
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
|
-
var 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 var GlobalStylesWrapper = function GlobalStylesWrapper() {
|
|
15
|
-
return jsx(Global, {
|
|
16
|
-
styles: [extensionStyles]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useLiveSyncedBlockContent } from '../hooks/useLiveSyncedBlockContent';
|
|
3
|
-
import SyncedBlockRenderer from './SyncedBlockRenderer';
|
|
4
|
-
var SyncedBlockLiveView = function SyncedBlockLiveView(_ref) {
|
|
5
|
-
var sourceDocumentAri = _ref.sourceDocumentAri,
|
|
6
|
-
contentAri = _ref.contentAri;
|
|
7
|
-
var syncedBlockContent = useLiveSyncedBlockContent({
|
|
8
|
-
sourceDocumentAri: sourceDocumentAri,
|
|
9
|
-
contentAri: contentAri
|
|
10
|
-
});
|
|
11
|
-
if (!syncedBlockContent) {
|
|
12
|
-
return /*#__PURE__*/React.createElement("div", null, "Loading...");
|
|
13
|
-
}
|
|
14
|
-
return /*#__PURE__*/React.createElement(SyncedBlockRenderer, {
|
|
15
|
-
syncedBlockContent: syncedBlockContent
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
export default SyncedBlockLiveView;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ReactRenderer } from '@atlaskit/renderer';
|
|
3
|
-
import { RendererActionsContext } from '@atlaskit/renderer/actions';
|
|
4
|
-
var SyncedBlockRenderer = function SyncedBlockRenderer(_ref) {
|
|
5
|
-
var syncedBlockContent = _ref.syncedBlockContent;
|
|
6
|
-
return /*#__PURE__*/React.createElement(RendererActionsContext, null, /*#__PURE__*/React.createElement(ReactRenderer, {
|
|
7
|
-
adfStage: "stage0"
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
,
|
|
10
|
-
document: {
|
|
11
|
-
type: 'doc',
|
|
12
|
-
version: 1,
|
|
13
|
-
content: syncedBlockContent.adf.content
|
|
14
|
-
},
|
|
15
|
-
appearance: "full-page"
|
|
16
|
-
}));
|
|
17
|
-
};
|
|
18
|
-
export default SyncedBlockRenderer;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// hello.atlassian.net cloud id
|
|
2
|
-
var HELLO_CLOUD_ID = 'a436116f-02ce-4520-8fbb-7301462a1674';
|
|
3
|
-
|
|
4
|
-
// spike page https://hello.atlassian.net/wiki/spaces/~7120208ef57ce4d614485e876489301a16b906/pages/5626233808
|
|
5
|
-
var TEST_PAGE_ID = '5626233808';
|
|
6
|
-
export var getPageId = function getPageId() {
|
|
7
|
-
var _window$location$href, _window$location$href2, _window$location$path;
|
|
8
|
-
return (
|
|
9
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
10
|
-
((_window$location$href = window.location.href.match(/pageId=(\d+)/)) === null || _window$location$href === void 0 ? void 0 : _window$location$href[1]) || ( // eslint-disable-next-line require-unicode-regexp
|
|
11
|
-
(_window$location$href2 = window.location.href.match(/pages\/edit-v2\/(\d+)/)) === null || _window$location$href2 === void 0 ? void 0 : _window$location$href2[1]) || ( // eslint-disable-next-line require-unicode-regexp
|
|
12
|
-
(_window$location$path = window.location.pathname.match(/pages\/(\d+)/)) === null || _window$location$path === void 0 ? void 0 : _window$location$path[1]) ||
|
|
13
|
-
// view page or live doc
|
|
14
|
-
TEST_PAGE_ID
|
|
15
|
-
);
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* This by no means is a stable way to get the cloud id, but it works for now.
|
|
19
|
-
* We should switch passing the cloud id from Confluence to a Editor plugin,
|
|
20
|
-
* for instance the user preferences plugin would have a seperate place for user and cloud info
|
|
21
|
-
* @returns the cloud id from the initial state
|
|
22
|
-
*/
|
|
23
|
-
export var getCloudId = function getCloudId() {
|
|
24
|
-
var _INITIAL_STATE__;
|
|
25
|
-
return ((_INITIAL_STATE__ = window.__INITIAL_STATE__) === null || _INITIAL_STATE__ === void 0 || (_INITIAL_STATE__ = _INITIAL_STATE__.meta) === null || _INITIAL_STATE__ === void 0 ? void 0 : _INITIAL_STATE__['cloud-id']) || HELLO_CLOUD_ID;
|
|
26
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DefaultExtensionProvider } from '@atlaskit/editor-common/extensions';
|
|
2
|
-
import { getSyncedBlockManifest } from './manifest';
|
|
3
|
-
export var getSyncedBlockExtensionProvider = function getSyncedBlockExtensionProvider(schema) {
|
|
4
|
-
return new DefaultExtensionProvider([getSyncedBlockManifest(schema)]);
|
|
5
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { usePollContentProperty } from '../hooks/usePollContentProperty';
|
|
3
|
-
import { parseSyncedBlockContentPropertyValue } from '../utils/synced-block';
|
|
4
|
-
export var useLiveSyncedBlockContent = function useLiveSyncedBlockContent(_ref) {
|
|
5
|
-
var sourceDocumentAri = _ref.sourceDocumentAri,
|
|
6
|
-
contentAri = _ref.contentAri;
|
|
7
|
-
var contentProperty = usePollContentProperty({
|
|
8
|
-
sourceDocumentAri: sourceDocumentAri,
|
|
9
|
-
contentAri: contentAri
|
|
10
|
-
});
|
|
11
|
-
return useMemo(function () {
|
|
12
|
-
if (!contentProperty) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
return parseSyncedBlockContentPropertyValue(contentProperty.value);
|
|
17
|
-
} catch (error) {
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.error('Failed to extract synced block content:', error);
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}, [contentProperty]);
|
|
23
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { getContentPropertyIdFromAri, getPageIdFromAri } from '../utils/ari';
|
|
4
|
-
import { getContentProperty } from '../utils/content-property';
|
|
5
|
-
var POLLING_INTERVAL = 1000;
|
|
6
|
-
var cache = new Map();
|
|
7
|
-
var inFlightRequests = new Map();
|
|
8
|
-
var subscribers = new Map();
|
|
9
|
-
var pollingTimeouts = new Map();
|
|
10
|
-
var lastRequestTimes = new Map();
|
|
11
|
-
var getRequestKey = function getRequestKey(pageId, contentPropertyId) {
|
|
12
|
-
return "".concat(pageId, ":").concat(contentPropertyId);
|
|
13
|
-
};
|
|
14
|
-
var fetchContentPropertyWithDedup = function fetchContentPropertyWithDedup(pageId, contentPropertyId) {
|
|
15
|
-
var requestKey = getRequestKey(pageId, contentPropertyId);
|
|
16
|
-
lastRequestTimes.set(requestKey, Date.now());
|
|
17
|
-
var inFlightRequest = inFlightRequests.get(requestKey);
|
|
18
|
-
if (inFlightRequest) {
|
|
19
|
-
return inFlightRequest;
|
|
20
|
-
}
|
|
21
|
-
var requestPromise = getContentProperty({
|
|
22
|
-
pageId: pageId,
|
|
23
|
-
contentPropertyId: contentPropertyId
|
|
24
|
-
}).then(function (result) {
|
|
25
|
-
cache.set(requestKey, result);
|
|
26
|
-
var subscribersForKey = subscribers.get(requestKey);
|
|
27
|
-
if (subscribersForKey) {
|
|
28
|
-
subscribersForKey.forEach(function (callback) {
|
|
29
|
-
return callback(result);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
inFlightRequests.delete(requestKey);
|
|
33
|
-
if (subscribersForKey && subscribersForKey.size > 0) {
|
|
34
|
-
scheduleNextPoll(pageId, contentPropertyId);
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
}).catch(function (error) {
|
|
38
|
-
inFlightRequests.delete(requestKey);
|
|
39
|
-
var subscribersForKey = subscribers.get(requestKey);
|
|
40
|
-
if (subscribersForKey && subscribersForKey.size > 0) {
|
|
41
|
-
scheduleNextPoll(pageId, contentPropertyId);
|
|
42
|
-
}
|
|
43
|
-
throw error;
|
|
44
|
-
});
|
|
45
|
-
inFlightRequests.set(requestKey, requestPromise);
|
|
46
|
-
return requestPromise;
|
|
47
|
-
};
|
|
48
|
-
var scheduleNextPoll = function scheduleNextPoll(pageId, contentPropertyId) {
|
|
49
|
-
var requestKey = getRequestKey(pageId, contentPropertyId);
|
|
50
|
-
var existingTimeout = pollingTimeouts.get(requestKey);
|
|
51
|
-
if (existingTimeout) {
|
|
52
|
-
clearTimeout(existingTimeout);
|
|
53
|
-
}
|
|
54
|
-
var lastRequestTime = lastRequestTimes.get(requestKey) || 0;
|
|
55
|
-
var timeElapsed = Date.now() - lastRequestTime;
|
|
56
|
-
var delay = Math.max(100, POLLING_INTERVAL - timeElapsed);
|
|
57
|
-
var timeout = setTimeout(function () {
|
|
58
|
-
var subscribersForKey = subscribers.get(requestKey);
|
|
59
|
-
if (subscribersForKey && subscribersForKey.size > 0) {
|
|
60
|
-
fetchContentPropertyWithDedup(pageId, contentPropertyId).catch(function (error) {
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console.error('Failed to fetch content property:', error);
|
|
63
|
-
});
|
|
64
|
-
} else {
|
|
65
|
-
pollingTimeouts.delete(requestKey);
|
|
66
|
-
}
|
|
67
|
-
}, delay);
|
|
68
|
-
pollingTimeouts.set(requestKey, timeout);
|
|
69
|
-
};
|
|
70
|
-
export var usePollContentProperty = function usePollContentProperty(_ref) {
|
|
71
|
-
var sourceDocumentAri = _ref.sourceDocumentAri,
|
|
72
|
-
contentAri = _ref.contentAri;
|
|
73
|
-
var _useState = useState(),
|
|
74
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
75
|
-
contentProperty = _useState2[0],
|
|
76
|
-
setContentProperty = _useState2[1];
|
|
77
|
-
var initializedRef = useRef(false);
|
|
78
|
-
useEffect(function () {
|
|
79
|
-
var pageId = getPageIdFromAri(sourceDocumentAri);
|
|
80
|
-
var contentPropertyId = getContentPropertyIdFromAri(contentAri);
|
|
81
|
-
var requestKey = getRequestKey(pageId, contentPropertyId);
|
|
82
|
-
var subscribersForKey = subscribers.get(requestKey) || new Set();
|
|
83
|
-
if (!subscribers.has(requestKey)) {
|
|
84
|
-
subscribers.set(requestKey, subscribersForKey);
|
|
85
|
-
}
|
|
86
|
-
subscribersForKey.add(setContentProperty);
|
|
87
|
-
var cachedValue = cache.get(requestKey);
|
|
88
|
-
if (cachedValue) {
|
|
89
|
-
setContentProperty(cachedValue);
|
|
90
|
-
}
|
|
91
|
-
if (subscribersForKey.size === 1 || !initializedRef.current) {
|
|
92
|
-
initializedRef.current = true;
|
|
93
|
-
fetchContentPropertyWithDedup(pageId, contentPropertyId).catch(function (error) {
|
|
94
|
-
// eslint-disable-next-line no-console
|
|
95
|
-
console.error('Failed to fetch content property:', error);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return function () {
|
|
99
|
-
subscribersForKey.delete(setContentProperty);
|
|
100
|
-
if (subscribersForKey.size === 0) {
|
|
101
|
-
subscribers.delete(requestKey);
|
|
102
|
-
var existingTimeout = pollingTimeouts.get(requestKey);
|
|
103
|
-
if (existingTimeout) {
|
|
104
|
-
clearTimeout(existingTimeout);
|
|
105
|
-
pollingTimeouts.delete(requestKey);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}, [sourceDocumentAri, contentAri]);
|
|
110
|
-
var pageId = getPageIdFromAri(sourceDocumentAri);
|
|
111
|
-
var contentPropertyId = getContentPropertyIdFromAri(contentAri);
|
|
112
|
-
var requestKey = getRequestKey(pageId, contentPropertyId);
|
|
113
|
-
return contentProperty || cache.get(requestKey);
|
|
114
|
-
};
|