@atlaskit/editor-synced-block-provider 0.1.2 → 0.2.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 +14 -0
- package/dist/cjs/common/schema.js +18 -0
- package/dist/cjs/common/syncBlockProvider.js +1 -1
- package/dist/cjs/common/syncBlockStoreManager.js +25 -3
- package/dist/cjs/index.js +8 -7
- package/dist/cjs/utils/utils.js +2 -15
- package/dist/es2019/common/schema.js +13 -0
- package/dist/es2019/common/syncBlockProvider.js +2 -2
- package/dist/es2019/common/syncBlockStoreManager.js +24 -3
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/utils/utils.js +1 -13
- package/dist/esm/common/schema.js +13 -0
- package/dist/esm/common/syncBlockProvider.js +2 -2
- package/dist/esm/common/syncBlockStoreManager.js +26 -3
- package/dist/esm/index.js +2 -1
- package/dist/esm/utils/utils.js +1 -13
- package/dist/types/common/schema.d.ts +6 -0
- package/dist/types/common/syncBlockStoreManager.d.ts +3 -8
- package/dist/types/common/types.d.ts +6 -4
- package/dist/types/index.d.ts +2 -1
- package/dist/types/utils/utils.d.ts +2 -3
- package/dist/types-ts4.5/common/schema.d.ts +6 -0
- package/dist/types-ts4.5/common/syncBlockStoreManager.d.ts +3 -8
- package/dist/types-ts4.5/common/types.d.ts +6 -4
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/utils/utils.d.ts +2 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`6fabf6d555515`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6fabf6d555515) -
|
|
8
|
+
EDITOR-1566 add renderer sync-block node support
|
|
9
|
+
|
|
10
|
+
## 0.1.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`dd19fd49edc58`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/dd19fd49edc58) -
|
|
15
|
+
Added sync block quick insert
|
|
16
|
+
|
|
3
17
|
## 0.1.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultSyncBlockSchema = void 0;
|
|
7
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
8
|
+
/**
|
|
9
|
+
* We currently do not need any of the new features, like nested tables
|
|
10
|
+
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
var getDefaultSyncBlockSchema = exports.getDefaultSyncBlockSchema = function getDefaultSyncBlockSchema() {
|
|
14
|
+
return (0, _adfSchema.createSchema)({
|
|
15
|
+
nodes: ['doc', 'paragraph', 'text', 'bulletList', 'orderedList', 'listItem', 'heading', 'blockquote', 'codeBlock', 'panel', 'rule', 'expand', 'nestedExpand', 'table', 'tableCell', 'tableHeader', 'tableRow', 'date', 'status', 'layoutSection', 'layoutColumn', 'unsupportedBlock', 'unsupportedInline'],
|
|
16
|
+
marks: ['link', 'em', 'strong', 'strike', 'subsup', 'underline', 'code', 'textColor', 'backgroundColor', 'alignment', 'indentation', 'border', 'unsupportedMark', 'unsupportedNodeAttribute', 'typeAheadQuery']
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -73,7 +73,7 @@ var useFetchDocNode = exports.useFetchDocNode = function useFetchDocNode(editorV
|
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
var interval = window.setInterval(function () {
|
|
76
|
-
var nodes = [(0, _utils.
|
|
76
|
+
var nodes = [(0, _utils.convertSyncBlockPMNodeToSyncBlockData)(node, false)];
|
|
77
77
|
provider === null || provider === void 0 || provider.fetchNodesData(nodes).then(function (data) {
|
|
78
78
|
var _data$;
|
|
79
79
|
if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
|
|
@@ -9,6 +9,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
12
13
|
// Do this typedef to make it clear that
|
|
13
14
|
// this is a local identifier for a resource for local use
|
|
14
15
|
// A store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
|
|
@@ -17,10 +18,9 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
17
18
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
18
19
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
19
20
|
var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
20
|
-
function SyncBlockStoreManager(
|
|
21
|
+
function SyncBlockStoreManager(_dataProvider) {
|
|
21
22
|
(0, _classCallCheck2.default)(this, SyncBlockStoreManager);
|
|
22
23
|
this.syncBlocks = new Map();
|
|
23
|
-
this.dataProvider = dataProvider;
|
|
24
24
|
}
|
|
25
25
|
return (0, _createClass2.default)(SyncBlockStoreManager, [{
|
|
26
26
|
key: "setEditorView",
|
|
@@ -31,7 +31,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
31
31
|
key: "isSourceBlock",
|
|
32
32
|
value: function isSourceBlock(node) {
|
|
33
33
|
var _this$syncBlocks$get;
|
|
34
|
-
if (
|
|
34
|
+
if (node.type.name !== 'syncBlock') {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
37
|
var _node$attrs = node.attrs,
|
|
@@ -53,6 +53,28 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
|
|
|
53
53
|
value: function requireConfirmationBeforeDelete() {
|
|
54
54
|
return !!this.confirmationCallback;
|
|
55
55
|
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "createSyncBlockNode",
|
|
58
|
+
value: function createSyncBlockNode() {
|
|
59
|
+
// TODO: EDITOR-1644 - properly implement creation of the synced block
|
|
60
|
+
// below is a temporary implementation for the creation of the synced block
|
|
61
|
+
// the resource id needs to have pageId and content property key in it
|
|
62
|
+
|
|
63
|
+
var blockInstanceId = (0, _uuid.default)();
|
|
64
|
+
var localId = (0, _uuid.default)();
|
|
65
|
+
var syncBlockNode = {
|
|
66
|
+
attrs: {
|
|
67
|
+
resourceId: "ari:cloud:confluence:fake_cloud_id:page/fake_page_id/".concat(blockInstanceId),
|
|
68
|
+
localId: localId
|
|
69
|
+
},
|
|
70
|
+
type: 'syncBlock'
|
|
71
|
+
};
|
|
72
|
+
this.syncBlocks.set(syncBlockNode.attrs.resourceId, {
|
|
73
|
+
resourceId: syncBlockNode.attrs.resourceId,
|
|
74
|
+
sourceLocalId: syncBlockNode.attrs.localId
|
|
75
|
+
});
|
|
76
|
+
return syncBlockNode;
|
|
77
|
+
}
|
|
56
78
|
}, {
|
|
57
79
|
key: "deleteSyncBlocksWithConfirmation",
|
|
58
80
|
value: function () {
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,22 +15,22 @@ Object.defineProperty(exports, "SyncedBlockProvider", {
|
|
|
15
15
|
return _syncBlockProvider.SyncBlockProvider;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "convertSyncBlockPMNodeToSyncBlockData", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function get() {
|
|
21
|
-
return _utils.
|
|
21
|
+
return _utils.convertSyncBlockPMNodeToSyncBlockData;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "generateSyncBlockSourceUrl", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function get() {
|
|
27
|
-
return _utils.
|
|
27
|
+
return _utils.generateSyncBlockSourceUrl;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "getDefaultSyncBlockSchema", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function get() {
|
|
33
|
-
return
|
|
33
|
+
return _schema.getDefaultSyncBlockSchema;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "inMemoryFetchProvider", {
|
|
@@ -54,4 +54,5 @@ Object.defineProperty(exports, "useFetchDocNode", {
|
|
|
54
54
|
var _syncBlockProvider = require("./common/syncBlockProvider");
|
|
55
55
|
var _syncBlockStoreManager = require("./common/syncBlockStoreManager");
|
|
56
56
|
var _inMemory = require("./providers/inMemory");
|
|
57
|
-
var _utils = require("./utils/utils");
|
|
57
|
+
var _utils = require("./utils/utils");
|
|
58
|
+
var _schema = require("./common/schema");
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -1,13 +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
|
-
exports.generateSyncBlockSourceUrl = exports.
|
|
8
|
-
var _uuid = _interopRequireDefault(require("uuid"));
|
|
6
|
+
exports.generateSyncBlockSourceUrl = exports.convertSyncBlockPMNodeToSyncBlockData = void 0;
|
|
9
7
|
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
|
|
10
|
-
var
|
|
8
|
+
var convertSyncBlockPMNodeToSyncBlockData = exports.convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
11
9
|
var includeContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
12
10
|
var transformer = new _editorJsonTransformer.JSONTransformer();
|
|
13
11
|
var toJSON = function toJSON(node) {
|
|
@@ -22,17 +20,6 @@ var createSyncBlockNode = exports.createSyncBlockNode = function createSyncBlock
|
|
|
22
20
|
content: includeContent ? node.content.content.map(toJSON) : undefined
|
|
23
21
|
};
|
|
24
22
|
};
|
|
25
|
-
var createSyncBlockPMNode = exports.createSyncBlockPMNode = function createSyncBlockPMNode(nodeType) {
|
|
26
|
-
// TODO: EDITOR-1644 - properly implement creation of the synced block
|
|
27
|
-
// below is a temporary implementation for the creation of the synced block
|
|
28
|
-
// the resource id needs to have pageId and content property key in it
|
|
29
|
-
var id = (0, _uuid.default)();
|
|
30
|
-
var node = nodeType.createChecked({
|
|
31
|
-
resourceId: id,
|
|
32
|
-
localId: id
|
|
33
|
-
}, null);
|
|
34
|
-
return node;
|
|
35
|
-
};
|
|
36
23
|
var generateSyncBlockSourceUrl = exports.generateSyncBlockSourceUrl = function generateSyncBlockSourceUrl(node) {
|
|
37
24
|
var _node$attrs = node.attrs,
|
|
38
25
|
localId = _node$attrs.localId,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createSchema } from '@atlaskit/adf-schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* We currently do not need any of the new features, like nested tables
|
|
5
|
+
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const getDefaultSyncBlockSchema = () => {
|
|
9
|
+
return createSchema({
|
|
10
|
+
nodes: ['doc', 'paragraph', 'text', 'bulletList', 'orderedList', 'listItem', 'heading', 'blockquote', 'codeBlock', 'panel', 'rule', 'expand', 'nestedExpand', 'table', 'tableCell', 'tableHeader', 'tableRow', 'date', 'status', 'layoutSection', 'layoutColumn', 'unsupportedBlock', 'unsupportedInline'],
|
|
11
|
+
marks: ['link', 'em', 'strong', 'strike', 'subsup', 'underline', 'code', 'textColor', 'backgroundColor', 'alignment', 'indentation', 'border', 'unsupportedMark', 'unsupportedNodeAttribute', 'typeAheadQuery']
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
4
4
|
import { SyncBlockDataProvider } from './types';
|
|
5
5
|
export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
6
6
|
constructor(fetchProvider, writeProvider, sourceId) {
|
|
@@ -44,7 +44,7 @@ export const useFetchDocNode = (editorView, node, defaultDocNode, provider) => {
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const interval = window.setInterval(() => {
|
|
47
|
-
const nodes = [
|
|
47
|
+
const nodes = [convertSyncBlockPMNodeToSyncBlockData(node, false)];
|
|
48
48
|
provider === null || provider === void 0 ? void 0 : provider.fetchNodesData(nodes).then(data => {
|
|
49
49
|
var _data$;
|
|
50
50
|
if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import uuid from 'uuid';
|
|
2
|
+
|
|
1
3
|
// Do this typedef to make it clear that
|
|
2
4
|
// this is a local identifier for a resource for local use
|
|
3
5
|
|
|
@@ -7,16 +9,15 @@
|
|
|
7
9
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
8
10
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
9
11
|
export class SyncBlockStoreManager {
|
|
10
|
-
constructor(
|
|
12
|
+
constructor(_dataProvider) {
|
|
11
13
|
this.syncBlocks = new Map();
|
|
12
|
-
this.dataProvider = dataProvider;
|
|
13
14
|
}
|
|
14
15
|
setEditorView(editorView) {
|
|
15
16
|
this.editorView = editorView;
|
|
16
17
|
}
|
|
17
18
|
isSourceBlock(node) {
|
|
18
19
|
var _this$syncBlocks$get;
|
|
19
|
-
if (
|
|
20
|
+
if (node.type.name !== 'syncBlock') {
|
|
20
21
|
return false;
|
|
21
22
|
}
|
|
22
23
|
const {
|
|
@@ -34,6 +35,26 @@ export class SyncBlockStoreManager {
|
|
|
34
35
|
requireConfirmationBeforeDelete() {
|
|
35
36
|
return !!this.confirmationCallback;
|
|
36
37
|
}
|
|
38
|
+
createSyncBlockNode() {
|
|
39
|
+
// TODO: EDITOR-1644 - properly implement creation of the synced block
|
|
40
|
+
// below is a temporary implementation for the creation of the synced block
|
|
41
|
+
// the resource id needs to have pageId and content property key in it
|
|
42
|
+
|
|
43
|
+
const blockInstanceId = uuid();
|
|
44
|
+
const localId = uuid();
|
|
45
|
+
const syncBlockNode = {
|
|
46
|
+
attrs: {
|
|
47
|
+
resourceId: `ari:cloud:confluence:fake_cloud_id:page/fake_page_id/${blockInstanceId}`,
|
|
48
|
+
localId
|
|
49
|
+
},
|
|
50
|
+
type: 'syncBlock'
|
|
51
|
+
};
|
|
52
|
+
this.syncBlocks.set(syncBlockNode.attrs.resourceId, {
|
|
53
|
+
resourceId: syncBlockNode.attrs.resourceId,
|
|
54
|
+
sourceLocalId: syncBlockNode.attrs.localId
|
|
55
|
+
});
|
|
56
|
+
return syncBlockNode;
|
|
57
|
+
}
|
|
37
58
|
async deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
|
|
38
59
|
if (this.confirmationCallback) {
|
|
39
60
|
const confirmed = await this.confirmationCallback();
|
package/dist/es2019/index.js
CHANGED
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode } from './common/syncBlockProvider';
|
|
4
4
|
export { SyncBlockStoreManager } from './common/syncBlockStoreManager';
|
|
5
5
|
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
6
|
-
export {
|
|
6
|
+
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
7
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import uuid from 'uuid';
|
|
2
1
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
3
|
-
export const
|
|
2
|
+
export const convertSyncBlockPMNodeToSyncBlockData = (node, includeContent = false) => {
|
|
4
3
|
const transformer = new JSONTransformer();
|
|
5
4
|
const toJSON = node => transformer.encodeNode(node);
|
|
6
5
|
return {
|
|
@@ -12,17 +11,6 @@ export const createSyncBlockNode = (node, includeContent = false) => {
|
|
|
12
11
|
content: includeContent ? node.content.content.map(toJSON) : undefined
|
|
13
12
|
};
|
|
14
13
|
};
|
|
15
|
-
export const createSyncBlockPMNode = nodeType => {
|
|
16
|
-
// TODO: EDITOR-1644 - properly implement creation of the synced block
|
|
17
|
-
// below is a temporary implementation for the creation of the synced block
|
|
18
|
-
// the resource id needs to have pageId and content property key in it
|
|
19
|
-
const id = uuid();
|
|
20
|
-
const node = nodeType.createChecked({
|
|
21
|
-
resourceId: id,
|
|
22
|
-
localId: id
|
|
23
|
-
}, null);
|
|
24
|
-
return node;
|
|
25
|
-
};
|
|
26
14
|
export const generateSyncBlockSourceUrl = node => {
|
|
27
15
|
const {
|
|
28
16
|
localId,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createSchema } from '@atlaskit/adf-schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* We currently do not need any of the new features, like nested tables
|
|
5
|
+
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export var getDefaultSyncBlockSchema = function getDefaultSyncBlockSchema() {
|
|
9
|
+
return createSchema({
|
|
10
|
+
nodes: ['doc', 'paragraph', 'text', 'bulletList', 'orderedList', 'listItem', 'heading', 'blockquote', 'codeBlock', 'panel', 'rule', 'expand', 'nestedExpand', 'table', 'tableCell', 'tableHeader', 'tableRow', 'date', 'status', 'layoutSection', 'layoutColumn', 'unsupportedBlock', 'unsupportedInline'],
|
|
11
|
+
marks: ['link', 'em', 'strong', 'strike', 'subsup', 'underline', 'code', 'textColor', 'backgroundColor', 'alignment', 'indentation', 'border', 'unsupportedMark', 'unsupportedNodeAttribute', 'typeAheadQuery']
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -10,7 +10,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
10
10
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
11
11
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
12
12
|
import { useEffect, useState } from 'react';
|
|
13
|
-
import {
|
|
13
|
+
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
14
14
|
import { SyncBlockDataProvider } from './types';
|
|
15
15
|
export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
|
|
16
16
|
function SyncBlockProvider(fetchProvider, writeProvider, sourceId) {
|
|
@@ -66,7 +66,7 @@ export var useFetchDocNode = function useFetchDocNode(editorView, node, defaultD
|
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
var interval = window.setInterval(function () {
|
|
69
|
-
var nodes = [
|
|
69
|
+
var nodes = [convertSyncBlockPMNodeToSyncBlockData(node, false)];
|
|
70
70
|
provider === null || provider === void 0 || provider.fetchNodesData(nodes).then(function (data) {
|
|
71
71
|
var _data$;
|
|
72
72
|
if (data && (_data$ = data[0]) !== null && _data$ !== void 0 && _data$.content) {
|
|
@@ -2,6 +2,8 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
import uuid from 'uuid';
|
|
6
|
+
|
|
5
7
|
// Do this typedef to make it clear that
|
|
6
8
|
// this is a local identifier for a resource for local use
|
|
7
9
|
|
|
@@ -11,10 +13,9 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
11
13
|
// Handles caching, debouncing updates, and publish/subscribe for local changes.
|
|
12
14
|
// Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
|
|
13
15
|
export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
14
|
-
function SyncBlockStoreManager(
|
|
16
|
+
function SyncBlockStoreManager(_dataProvider) {
|
|
15
17
|
_classCallCheck(this, SyncBlockStoreManager);
|
|
16
18
|
this.syncBlocks = new Map();
|
|
17
|
-
this.dataProvider = dataProvider;
|
|
18
19
|
}
|
|
19
20
|
return _createClass(SyncBlockStoreManager, [{
|
|
20
21
|
key: "setEditorView",
|
|
@@ -25,7 +26,7 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
25
26
|
key: "isSourceBlock",
|
|
26
27
|
value: function isSourceBlock(node) {
|
|
27
28
|
var _this$syncBlocks$get;
|
|
28
|
-
if (
|
|
29
|
+
if (node.type.name !== 'syncBlock') {
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
32
|
var _node$attrs = node.attrs,
|
|
@@ -47,6 +48,28 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
47
48
|
value: function requireConfirmationBeforeDelete() {
|
|
48
49
|
return !!this.confirmationCallback;
|
|
49
50
|
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "createSyncBlockNode",
|
|
53
|
+
value: function createSyncBlockNode() {
|
|
54
|
+
// TODO: EDITOR-1644 - properly implement creation of the synced block
|
|
55
|
+
// below is a temporary implementation for the creation of the synced block
|
|
56
|
+
// the resource id needs to have pageId and content property key in it
|
|
57
|
+
|
|
58
|
+
var blockInstanceId = uuid();
|
|
59
|
+
var localId = uuid();
|
|
60
|
+
var syncBlockNode = {
|
|
61
|
+
attrs: {
|
|
62
|
+
resourceId: "ari:cloud:confluence:fake_cloud_id:page/fake_page_id/".concat(blockInstanceId),
|
|
63
|
+
localId: localId
|
|
64
|
+
},
|
|
65
|
+
type: 'syncBlock'
|
|
66
|
+
};
|
|
67
|
+
this.syncBlocks.set(syncBlockNode.attrs.resourceId, {
|
|
68
|
+
resourceId: syncBlockNode.attrs.resourceId,
|
|
69
|
+
sourceLocalId: syncBlockNode.attrs.localId
|
|
70
|
+
});
|
|
71
|
+
return syncBlockNode;
|
|
72
|
+
}
|
|
50
73
|
}, {
|
|
51
74
|
key: "deleteSyncBlocksWithConfirmation",
|
|
52
75
|
value: function () {
|
package/dist/esm/index.js
CHANGED
|
@@ -3,4 +3,5 @@
|
|
|
3
3
|
export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode } from './common/syncBlockProvider';
|
|
4
4
|
export { SyncBlockStoreManager } from './common/syncBlockStoreManager';
|
|
5
5
|
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
6
|
-
export {
|
|
6
|
+
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
7
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import uuid from 'uuid';
|
|
2
1
|
import { JSONTransformer } from '@atlaskit/editor-json-transformer';
|
|
3
|
-
export var
|
|
2
|
+
export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNodeToSyncBlockData(node) {
|
|
4
3
|
var includeContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
5
4
|
var transformer = new JSONTransformer();
|
|
6
5
|
var toJSON = function toJSON(node) {
|
|
@@ -15,17 +14,6 @@ export var createSyncBlockNode = function createSyncBlockNode(node) {
|
|
|
15
14
|
content: includeContent ? node.content.content.map(toJSON) : undefined
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
|
-
export var createSyncBlockPMNode = function createSyncBlockPMNode(nodeType) {
|
|
19
|
-
// TODO: EDITOR-1644 - properly implement creation of the synced block
|
|
20
|
-
// below is a temporary implementation for the creation of the synced block
|
|
21
|
-
// the resource id needs to have pageId and content property key in it
|
|
22
|
-
var id = uuid();
|
|
23
|
-
var node = nodeType.createChecked({
|
|
24
|
-
resourceId: id,
|
|
25
|
-
localId: id
|
|
26
|
-
}, null);
|
|
27
|
-
return node;
|
|
28
|
-
};
|
|
29
17
|
export var generateSyncBlockSourceUrl = function generateSyncBlockSourceUrl(node) {
|
|
30
18
|
var _node$attrs = node.attrs,
|
|
31
19
|
localId = _node$attrs.localId,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We currently do not need any of the new features, like nested tables
|
|
3
|
+
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"doc" | "paragraph" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "panel" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "status" | "layoutSection" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
|
|
@@ -2,8 +2,7 @@ import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import type { SyncBlockDataProvider } from './types';
|
|
6
|
-
type ResourceId = string;
|
|
5
|
+
import type { SyncBlockAttrs, SyncBlockDataProvider, SyncBlockNode } from './types';
|
|
7
6
|
export interface SyncBlock {
|
|
8
7
|
/**
|
|
9
8
|
* The local content of the block,
|
|
@@ -13,21 +12,17 @@ export interface SyncBlock {
|
|
|
13
12
|
resourceId: string;
|
|
14
13
|
sourceLocalId: string;
|
|
15
14
|
}
|
|
16
|
-
type SyncBlockAttrs = {
|
|
17
|
-
localId: string;
|
|
18
|
-
resourceId: ResourceId;
|
|
19
|
-
};
|
|
20
15
|
type ConfirmationCallback = () => Promise<boolean>;
|
|
21
16
|
export declare class SyncBlockStoreManager {
|
|
22
17
|
private syncBlocks;
|
|
23
|
-
private dataProvider?;
|
|
24
18
|
private confirmationCallback?;
|
|
25
19
|
private editorView?;
|
|
26
|
-
constructor(
|
|
20
|
+
constructor(_dataProvider?: SyncBlockDataProvider);
|
|
27
21
|
setEditorView(editorView: EditorView | undefined): void;
|
|
28
22
|
isSourceBlock(node: PMNode): boolean;
|
|
29
23
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
30
24
|
requireConfirmationBeforeDelete(): boolean;
|
|
25
|
+
createSyncBlockNode(): SyncBlockNode;
|
|
31
26
|
deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
|
|
32
27
|
}
|
|
33
28
|
export {};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
3
3
|
import { NodeDataProvider } from '@atlaskit/node-data-provider';
|
|
4
|
+
export type SyncBlockAttrs = {
|
|
5
|
+
localId: string;
|
|
6
|
+
resourceId: string;
|
|
7
|
+
};
|
|
4
8
|
export type SyncBlockNode = {
|
|
5
|
-
attrs:
|
|
6
|
-
localId: string;
|
|
7
|
-
resourceId: string;
|
|
8
|
-
};
|
|
9
|
+
attrs: SyncBlockAttrs;
|
|
9
10
|
content?: Array<JSONNode>;
|
|
10
11
|
type: 'syncBlock';
|
|
11
12
|
};
|
|
12
13
|
export type SyncBlockData = {
|
|
13
14
|
content: ADFEntity | undefined;
|
|
15
|
+
resourceId?: string;
|
|
14
16
|
};
|
|
15
17
|
export interface ADFFetchProvider {
|
|
16
18
|
fetchData: (resourceId: string) => Promise<SyncBlockData>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, } from './co
|
|
|
2
2
|
export { SyncBlockStoreManager } from './common/syncBlockStoreManager';
|
|
3
3
|
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, } from './common/types';
|
|
4
4
|
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
5
|
-
export {
|
|
5
|
+
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
6
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Node as PMNode
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { SyncBlockNode } from '../common/types';
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const createSyncBlockPMNode: (nodeType: NodeType) => PMNode;
|
|
3
|
+
export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode, includeContent?: boolean) => SyncBlockNode;
|
|
5
4
|
export declare const generateSyncBlockSourceUrl: (node: PMNode) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We currently do not need any of the new features, like nested tables
|
|
3
|
+
* Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"doc" | "paragraph" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "panel" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "status" | "layoutSection" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
|
|
@@ -2,8 +2,7 @@ import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import type { SyncBlockDataProvider } from './types';
|
|
6
|
-
type ResourceId = string;
|
|
5
|
+
import type { SyncBlockAttrs, SyncBlockDataProvider, SyncBlockNode } from './types';
|
|
7
6
|
export interface SyncBlock {
|
|
8
7
|
/**
|
|
9
8
|
* The local content of the block,
|
|
@@ -13,21 +12,17 @@ export interface SyncBlock {
|
|
|
13
12
|
resourceId: string;
|
|
14
13
|
sourceLocalId: string;
|
|
15
14
|
}
|
|
16
|
-
type SyncBlockAttrs = {
|
|
17
|
-
localId: string;
|
|
18
|
-
resourceId: ResourceId;
|
|
19
|
-
};
|
|
20
15
|
type ConfirmationCallback = () => Promise<boolean>;
|
|
21
16
|
export declare class SyncBlockStoreManager {
|
|
22
17
|
private syncBlocks;
|
|
23
|
-
private dataProvider?;
|
|
24
18
|
private confirmationCallback?;
|
|
25
19
|
private editorView?;
|
|
26
|
-
constructor(
|
|
20
|
+
constructor(_dataProvider?: SyncBlockDataProvider);
|
|
27
21
|
setEditorView(editorView: EditorView | undefined): void;
|
|
28
22
|
isSourceBlock(node: PMNode): boolean;
|
|
29
23
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
30
24
|
requireConfirmationBeforeDelete(): boolean;
|
|
25
|
+
createSyncBlockNode(): SyncBlockNode;
|
|
31
26
|
deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
|
|
32
27
|
}
|
|
33
28
|
export {};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
2
|
import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
|
|
3
3
|
import { NodeDataProvider } from '@atlaskit/node-data-provider';
|
|
4
|
+
export type SyncBlockAttrs = {
|
|
5
|
+
localId: string;
|
|
6
|
+
resourceId: string;
|
|
7
|
+
};
|
|
4
8
|
export type SyncBlockNode = {
|
|
5
|
-
attrs:
|
|
6
|
-
localId: string;
|
|
7
|
-
resourceId: string;
|
|
8
|
-
};
|
|
9
|
+
attrs: SyncBlockAttrs;
|
|
9
10
|
content?: Array<JSONNode>;
|
|
10
11
|
type: 'syncBlock';
|
|
11
12
|
};
|
|
12
13
|
export type SyncBlockData = {
|
|
13
14
|
content: ADFEntity | undefined;
|
|
15
|
+
resourceId?: string;
|
|
14
16
|
};
|
|
15
17
|
export interface ADFFetchProvider {
|
|
16
18
|
fetchData: (resourceId: string) => Promise<SyncBlockData>;
|
|
@@ -2,4 +2,5 @@ export { SyncBlockProvider as SyncedBlockProvider, useFetchDocNode, } from './co
|
|
|
2
2
|
export { SyncBlockStoreManager } from './common/syncBlockStoreManager';
|
|
3
3
|
export type { SyncBlockDataProvider, ADFFetchProvider, ADFWriteProvider, SyncBlockData, SyncBlockNode, } from './common/types';
|
|
4
4
|
export { inMemoryFetchProvider, inMemoryWriteProvider } from './providers/inMemory';
|
|
5
|
-
export {
|
|
5
|
+
export { convertSyncBlockPMNodeToSyncBlockData, generateSyncBlockSourceUrl } from './utils/utils';
|
|
6
|
+
export { getDefaultSyncBlockSchema } from './common/schema';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Node as PMNode
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { SyncBlockNode } from '../common/types';
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const createSyncBlockPMNode: (nodeType: NodeType) => PMNode;
|
|
3
|
+
export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode, includeContent?: boolean) => SyncBlockNode;
|
|
5
4
|
export declare const generateSyncBlockSourceUrl: (node: PMNode) => string;
|
package/package.json
CHANGED