@atlaskit/editor-synced-block-provider 2.6.0 → 2.7.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/hooks/useFetchSyncBlockData.js +2 -2
  3. package/dist/cjs/index.js +9 -4
  4. package/dist/cjs/providers/confluence/confluenceContentAPI.js +86 -73
  5. package/dist/cjs/providers/syncBlockProvider.js +60 -36
  6. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +4 -4
  7. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +78 -17
  8. package/dist/cjs/store-manager/syncBlockStoreManager.js +41 -8
  9. package/dist/cjs/utils/errorHandling.js +13 -0
  10. package/dist/cjs/utils/utils.js +32 -1
  11. package/dist/es2019/hooks/useFetchSyncBlockData.js +1 -1
  12. package/dist/es2019/index.js +2 -3
  13. package/dist/es2019/providers/confluence/confluenceContentAPI.js +62 -40
  14. package/dist/es2019/providers/syncBlockProvider.js +15 -9
  15. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +1 -1
  16. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +64 -12
  17. package/dist/es2019/store-manager/syncBlockStoreManager.js +31 -8
  18. package/dist/es2019/utils/errorHandling.js +7 -0
  19. package/dist/es2019/utils/utils.js +31 -0
  20. package/dist/esm/hooks/useFetchSyncBlockData.js +1 -1
  21. package/dist/esm/index.js +2 -3
  22. package/dist/esm/providers/confluence/confluenceContentAPI.js +79 -66
  23. package/dist/esm/providers/syncBlockProvider.js +60 -36
  24. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +1 -1
  25. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +79 -18
  26. package/dist/esm/store-manager/syncBlockStoreManager.js +41 -8
  27. package/dist/esm/utils/errorHandling.js +7 -0
  28. package/dist/esm/utils/utils.js +31 -0
  29. package/dist/types/index.d.ts +1 -2
  30. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -2
  31. package/dist/types/providers/syncBlockProvider.d.ts +4 -3
  32. package/dist/types/providers/types.d.ts +6 -2
  33. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
  34. package/dist/types/store-manager/syncBlockStoreManager.d.ts +20 -3
  35. package/dist/types/utils/errorHandling.d.ts +1 -0
  36. package/dist/types/utils/utils.d.ts +6 -1
  37. package/dist/types-ts4.5/index.d.ts +1 -2
  38. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -2
  39. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +4 -3
  40. package/dist/types-ts4.5/providers/types.d.ts +6 -2
  41. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
  42. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +20 -3
  43. package/dist/types-ts4.5/utils/errorHandling.d.ts +1 -0
  44. package/dist/types-ts4.5/utils/utils.d.ts +6 -1
  45. package/package.json +2 -2
  46. package/dist/cjs/utils/createSyncBlock.js +0 -15
  47. package/dist/es2019/utils/createSyncBlock.js +0 -9
  48. package/dist/esm/utils/createSyncBlock.js +0 -9
  49. package/dist/types/utils/createSyncBlock.d.ts +0 -2
  50. package/dist/types-ts4.5/utils/createSyncBlock.d.ts +0 -2
@@ -1,6 +1,6 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import { createSyncBlockNode } from '../utils/createSyncBlock';
3
+ import { convertPMNodeToSyncBlockNode } from '../utils/utils';
4
4
  import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
5
5
  import { SourceSyncBlockStoreManager } from './sourceSyncBlockStoreManager';
6
6
 
@@ -24,10 +24,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
24
24
  return _createClass(SyncBlockStoreManager, [{
25
25
  key: "fetchSyncBlocksData",
26
26
  value: function fetchSyncBlocksData(nodes) {
27
- var syncBlockNodes = nodes.filter(function (node) {
28
- return node.type.name === 'syncBlock' && node.attrs.resourceId && node.attrs.localId;
29
- }).map(function (node) {
30
- return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
27
+ var syncBlockNodes = nodes.map(function (node) {
28
+ return convertPMNodeToSyncBlockNode(node);
29
+ }).filter(function (node) {
30
+ return node !== undefined;
31
31
  }) || [];
32
32
  if (syncBlockNodes.length === 0) {
33
33
  return Promise.resolve([]);
@@ -99,11 +99,44 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
99
99
  // only applicable to source sync block, for now (will be refactored further)
100
100
  return this.sourceSyncBlockStoreManager.requireConfirmationBeforeDelete();
101
101
  }
102
+
103
+ /**
104
+ * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
105
+ */
106
+ }, {
107
+ key: "registerCreationCallback",
108
+ value: function registerCreationCallback(callback) {
109
+ this.sourceSyncBlockStoreManager.registerCreationCallback(callback);
110
+ }
111
+
112
+ /**
113
+ *
114
+ * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
115
+ */
116
+ }, {
117
+ key: "hasPendingCreation",
118
+ value: function hasPendingCreation() {
119
+ return this.sourceSyncBlockStoreManager.hasPendingCreation();
120
+ }
121
+
122
+ /**
123
+ * @returns attributes for a new bodiedSyncBlock node
124
+ */
125
+ }, {
126
+ key: "generateBodiedSyncBlockAttrs",
127
+ value: function generateBodiedSyncBlockAttrs() {
128
+ return this.sourceSyncBlockStoreManager.generateBodiedSyncBlockAttrs();
129
+ }
130
+
131
+ /**
132
+ * Save bodiedSyncBlock with empty content to backend
133
+ * @param attrs attributes Ids of the node
134
+ */
102
135
  }, {
103
- key: "createSyncBlockNode",
104
- value: function createSyncBlockNode() {
136
+ key: "createBodiedSyncBlockNode",
137
+ value: function createBodiedSyncBlockNode(attrs) {
105
138
  // only applicable to source sync block, for now (will be refactored further)
106
- return this.sourceSyncBlockStoreManager.createSyncBlockNode();
139
+ return this.sourceSyncBlockStoreManager.createBodiedSyncBlockNode(attrs);
107
140
  }
108
141
  }, {
109
142
  key: "subscribeToSyncBlockData",
@@ -0,0 +1,7 @@
1
+ export var stringifyError = function stringifyError(error) {
2
+ try {
3
+ return JSON.stringify(error);
4
+ } catch (_unused) {
5
+ return undefined;
6
+ }
7
+ };
@@ -7,4 +7,35 @@ export var convertSyncBlockPMNodeToSyncBlockData = function convertSyncBlockPMNo
7
7
  };
8
8
  export var isBlogPageType = function isBlogPageType(pageType) {
9
9
  return pageType === 'blogpost';
10
+ };
11
+ export var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
12
+ return {
13
+ type: 'syncBlock',
14
+ attrs: {
15
+ localId: localId,
16
+ resourceId: resourceId
17
+ }
18
+ };
19
+ };
20
+ export var createBodiedSyncBlockNode = function createBodiedSyncBlockNode(localId, resourceId) {
21
+ return {
22
+ type: 'bodiedSyncBlock',
23
+ attrs: {
24
+ localId: localId,
25
+ resourceId: resourceId
26
+ }
27
+ };
28
+ };
29
+ export var convertSyncBlockJSONNodeToSyncBlockNode = function convertSyncBlockJSONNodeToSyncBlockNode(node) {
30
+ if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
31
+ return undefined;
32
+ }
33
+ return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
34
+ };
35
+ export var convertPMNodeToSyncBlockNode = function convertPMNodeToSyncBlockNode(node) {
36
+ var _node$attrs, _node$attrs2;
37
+ if (node.type.name !== 'syncBlock' || !((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.localId) || !((_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.resourceId) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
38
+ return undefined;
39
+ }
40
+ return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
10
41
  };
@@ -11,6 +11,5 @@ export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlo
11
11
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
12
12
  export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
13
13
  export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
14
- export { createSyncBlockNode } from './utils/createSyncBlock';
14
+ export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, } from './utils/utils';
15
15
  export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
16
- export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
@@ -1,5 +1,5 @@
1
1
  import { type SyncBlockData } from '../../common/types';
2
- import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance } from '../types';
2
+ import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance, WriteSyncBlockResult } from '../types';
3
3
  /**
4
4
  * Configuration for Content API providers
5
5
  */
@@ -22,7 +22,7 @@ declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
22
22
  private config;
23
23
  constructor(config: ContentAPIConfig);
24
24
  private createNewContentProperty;
25
- writeData(data: SyncBlockData): Promise<string>;
25
+ writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
26
26
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
27
27
  }
28
28
  /**
@@ -1,6 +1,6 @@
1
1
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
2
2
  import { type SyncBlockData, type SyncBlockNode } from '../common/types';
3
- import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockSourceInfo } from '../providers/types';
3
+ import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockSourceInfo, type WriteSyncBlockResult } from '../providers/types';
4
4
  export declare class SyncBlockProvider extends SyncBlockDataProvider {
5
5
  name: string;
6
6
  private fetchProvider;
@@ -15,9 +15,10 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
15
15
  * @param nodes
16
16
  * @param data
17
17
  *
18
- * @returns the resource ids of the nodes that were written
18
+ * @returns Array of {resourceId?: string, error?: string}.
19
+ * resourceId: resource id of the node if write successfully , error: reason for when write failed
19
20
  */
20
- writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<string | undefined>>;
21
+ writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
21
22
  deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
22
23
  getSourceId(): string;
23
24
  retrieveSyncBlockSourceUrlAndTitle(node: SyncBlockNode): Promise<SyncBlockSourceInfo | undefined>;
@@ -19,15 +19,19 @@ export type SyncBlockSourceInfo = {
19
19
  title?: string;
20
20
  url?: string;
21
21
  };
22
+ export type WriteSyncBlockResult = {
23
+ error?: string;
24
+ resourceId?: string;
25
+ };
22
26
  export interface ADFFetchProvider {
23
27
  fetchData: (resourceId: ResourceId) => Promise<SyncBlockInstance>;
24
28
  }
25
29
  export interface ADFWriteProvider {
26
30
  deleteData: (resourceId: string) => Promise<DeleteSyncBlockResult>;
27
- writeData: (data: SyncBlockData) => Promise<string>;
31
+ writeData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
28
32
  }
29
33
  export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockInstance> {
30
- abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<ResourceId | undefined>>;
34
+ abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
31
35
  abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
32
36
  abstract getSourceId(): ResourceId;
33
37
  abstract retrieveSyncBlockSourceUrlAndTitle(node: SyncBlockNode): Promise<SyncBlockSourceInfo | undefined>;
@@ -1,15 +1,18 @@
1
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
1
+ import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import type { SyncBlockAttrs, SyncBlockNode } from '../common/types';
4
+ import type { ResourceId, SyncBlockAttrs } from '../common/types';
5
5
  import type { SyncBlockDataProvider } from '../providers/types';
6
6
  export type ConfirmationCallback = () => Promise<boolean>;
7
+ export type CreationCallback = () => void;
7
8
  export declare class SourceSyncBlockStoreManager {
8
9
  private dataProvider?;
9
10
  private editorView?;
10
11
  private syncBlockCache;
11
12
  private confirmationCallback?;
12
13
  private confirmationTransaction?;
14
+ private pendingResourceId?;
15
+ private creationCallback?;
13
16
  constructor(dataProvider?: SyncBlockDataProvider);
14
17
  /**
15
18
  * Add/update a sync block node to/from the local cache
@@ -23,9 +26,18 @@ export declare class SourceSyncBlockStoreManager {
23
26
  */
24
27
  flushBodiedSyncBlocks(): Promise<boolean>;
25
28
  setEditorView(editorView: EditorView | undefined): void;
29
+ registerPendingCreation(resourceId: ResourceId): void;
30
+ registerCreationCallback(callback: CreationCallback): void;
31
+ /**
32
+ * Fires callback to insert node (if creation is successful) and clears pending creation data
33
+ * @param success
34
+ */
35
+ commitPendingCreation(success: boolean): void;
36
+ hasPendingCreation(): boolean;
26
37
  registerConfirmationCallback(callback: ConfirmationCallback): () => void;
27
38
  requireConfirmationBeforeDelete(): boolean;
28
- createSyncBlockNode(): SyncBlockNode;
39
+ generateBodiedSyncBlockAttrs(): SyncBlockAttrs;
40
+ createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
29
41
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
30
42
  rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
31
43
  }
@@ -1,10 +1,10 @@
1
1
  import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
2
2
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import type { ResourceId, SyncBlockAttrs, SyncBlockNode } from '../common/types';
4
+ import type { ResourceId, SyncBlockAttrs } from '../common/types';
5
5
  import type { SubscriptionCallback, SyncBlockDataProvider, SyncBlockInstance, TitleSubscriptionCallback } from '../providers/types';
6
6
  import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
7
- import { type ConfirmationCallback } from './sourceSyncBlockStoreManager';
7
+ import { type ConfirmationCallback, type CreationCallback } from './sourceSyncBlockStoreManager';
8
8
  export declare class SyncBlockStoreManager {
9
9
  private referenceSyncBlockStoreManager;
10
10
  private sourceSyncBlockStoreManager;
@@ -37,7 +37,24 @@ export declare class SyncBlockStoreManager {
37
37
  isSourceBlock(node: PMNode): boolean;
38
38
  registerConfirmationCallback(callback: ConfirmationCallback): () => void;
39
39
  requireConfirmationBeforeDelete(): boolean;
40
- createSyncBlockNode(): SyncBlockNode;
40
+ /**
41
+ * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
42
+ */
43
+ registerCreationCallback(callback: CreationCallback): void;
44
+ /**
45
+ *
46
+ * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
47
+ */
48
+ hasPendingCreation(): boolean;
49
+ /**
50
+ * @returns attributes for a new bodiedSyncBlock node
51
+ */
52
+ generateBodiedSyncBlockAttrs(): SyncBlockAttrs;
53
+ /**
54
+ * Save bodiedSyncBlock with empty content to backend
55
+ * @param attrs attributes Ids of the node
56
+ */
57
+ createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
41
58
  subscribeToSyncBlockData(node: PMNode, callback: SubscriptionCallback): () => void;
42
59
  subscribeToSyncBlockSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
43
60
  refreshSubscriptions(): void;
@@ -0,0 +1 @@
1
+ export declare const stringifyError: (error: unknown) => string | undefined;
@@ -1,5 +1,10 @@
1
+ import type { JSONNode } from '@atlaskit/editor-json-transformer';
1
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import type { SyncBlockData } from '../common/types';
3
+ import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
3
4
  import type { PAGE_TYPE } from './ari';
4
5
  export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
5
6
  export declare const isBlogPageType: (pageType: PAGE_TYPE) => boolean;
7
+ export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
8
+ export declare const createBodiedSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
9
+ export declare const convertSyncBlockJSONNodeToSyncBlockNode: (node: JSONNode) => SyncBlockNode | undefined;
10
+ export declare const convertPMNodeToSyncBlockNode: (node: PMNode) => SyncBlockNode | undefined;
@@ -11,6 +11,5 @@ export type { ADFFetchProvider, ADFWriteProvider, SyncBlockDataProvider, SyncBlo
11
11
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
12
12
  export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
13
13
  export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
14
- export { createSyncBlockNode } from './utils/createSyncBlock';
14
+ export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, } from './utils/utils';
15
15
  export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
16
- export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
@@ -1,5 +1,5 @@
1
1
  import { type SyncBlockData } from '../../common/types';
2
- import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance } from '../types';
2
+ import type { ADFFetchProvider, ADFWriteProvider, DeleteSyncBlockResult, SyncBlockInstance, WriteSyncBlockResult } from '../types';
3
3
  /**
4
4
  * Configuration for Content API providers
5
5
  */
@@ -22,7 +22,7 @@ declare class ConfluenceADFWriteProvider implements ADFWriteProvider {
22
22
  private config;
23
23
  constructor(config: ContentAPIConfig);
24
24
  private createNewContentProperty;
25
- writeData(data: SyncBlockData): Promise<string>;
25
+ writeData(data: SyncBlockData): Promise<WriteSyncBlockResult>;
26
26
  deleteData(resourceId: string): Promise<DeleteSyncBlockResult>;
27
27
  }
28
28
  /**
@@ -1,6 +1,6 @@
1
1
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
2
2
  import { type SyncBlockData, type SyncBlockNode } from '../common/types';
3
- import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockSourceInfo } from '../providers/types';
3
+ import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type DeleteSyncBlockResult, type SyncBlockInstance, type SyncBlockSourceInfo, type WriteSyncBlockResult } from '../providers/types';
4
4
  export declare class SyncBlockProvider extends SyncBlockDataProvider {
5
5
  name: string;
6
6
  private fetchProvider;
@@ -15,9 +15,10 @@ export declare class SyncBlockProvider extends SyncBlockDataProvider {
15
15
  * @param nodes
16
16
  * @param data
17
17
  *
18
- * @returns the resource ids of the nodes that were written
18
+ * @returns Array of {resourceId?: string, error?: string}.
19
+ * resourceId: resource id of the node if write successfully , error: reason for when write failed
19
20
  */
20
- writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<string | undefined>>;
21
+ writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
21
22
  deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
22
23
  getSourceId(): string;
23
24
  retrieveSyncBlockSourceUrlAndTitle(node: SyncBlockNode): Promise<SyncBlockSourceInfo | undefined>;
@@ -19,15 +19,19 @@ export type SyncBlockSourceInfo = {
19
19
  title?: string;
20
20
  url?: string;
21
21
  };
22
+ export type WriteSyncBlockResult = {
23
+ error?: string;
24
+ resourceId?: string;
25
+ };
22
26
  export interface ADFFetchProvider {
23
27
  fetchData: (resourceId: ResourceId) => Promise<SyncBlockInstance>;
24
28
  }
25
29
  export interface ADFWriteProvider {
26
30
  deleteData: (resourceId: string) => Promise<DeleteSyncBlockResult>;
27
- writeData: (data: SyncBlockData) => Promise<string>;
31
+ writeData: (data: SyncBlockData) => Promise<WriteSyncBlockResult>;
28
32
  }
29
33
  export declare abstract class SyncBlockDataProvider extends NodeDataProvider<SyncBlockNode, SyncBlockInstance> {
30
- abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<ResourceId | undefined>>;
34
+ abstract writeNodesData(nodes: SyncBlockNode[], data: SyncBlockData[]): Promise<Array<WriteSyncBlockResult>>;
31
35
  abstract deleteNodesData(resourceIds: string[]): Promise<Array<DeleteSyncBlockResult>>;
32
36
  abstract getSourceId(): ResourceId;
33
37
  abstract retrieveSyncBlockSourceUrlAndTitle(node: SyncBlockNode): Promise<SyncBlockSourceInfo | undefined>;
@@ -1,15 +1,18 @@
1
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
1
+ import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import type { SyncBlockAttrs, SyncBlockNode } from '../common/types';
4
+ import type { ResourceId, SyncBlockAttrs } from '../common/types';
5
5
  import type { SyncBlockDataProvider } from '../providers/types';
6
6
  export type ConfirmationCallback = () => Promise<boolean>;
7
+ export type CreationCallback = () => void;
7
8
  export declare class SourceSyncBlockStoreManager {
8
9
  private dataProvider?;
9
10
  private editorView?;
10
11
  private syncBlockCache;
11
12
  private confirmationCallback?;
12
13
  private confirmationTransaction?;
14
+ private pendingResourceId?;
15
+ private creationCallback?;
13
16
  constructor(dataProvider?: SyncBlockDataProvider);
14
17
  /**
15
18
  * Add/update a sync block node to/from the local cache
@@ -23,9 +26,18 @@ export declare class SourceSyncBlockStoreManager {
23
26
  */
24
27
  flushBodiedSyncBlocks(): Promise<boolean>;
25
28
  setEditorView(editorView: EditorView | undefined): void;
29
+ registerPendingCreation(resourceId: ResourceId): void;
30
+ registerCreationCallback(callback: CreationCallback): void;
31
+ /**
32
+ * Fires callback to insert node (if creation is successful) and clears pending creation data
33
+ * @param success
34
+ */
35
+ commitPendingCreation(success: boolean): void;
36
+ hasPendingCreation(): boolean;
26
37
  registerConfirmationCallback(callback: ConfirmationCallback): () => void;
27
38
  requireConfirmationBeforeDelete(): boolean;
28
- createSyncBlockNode(): SyncBlockNode;
39
+ generateBodiedSyncBlockAttrs(): SyncBlockAttrs;
40
+ createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
29
41
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
30
42
  rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
31
43
  }
@@ -1,10 +1,10 @@
1
1
  import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
2
2
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import type { ResourceId, SyncBlockAttrs, SyncBlockNode } from '../common/types';
4
+ import type { ResourceId, SyncBlockAttrs } from '../common/types';
5
5
  import type { SubscriptionCallback, SyncBlockDataProvider, SyncBlockInstance, TitleSubscriptionCallback } from '../providers/types';
6
6
  import { ReferenceSyncBlockStoreManager } from './referenceSyncBlockStoreManager';
7
- import { type ConfirmationCallback } from './sourceSyncBlockStoreManager';
7
+ import { type ConfirmationCallback, type CreationCallback } from './sourceSyncBlockStoreManager';
8
8
  export declare class SyncBlockStoreManager {
9
9
  private referenceSyncBlockStoreManager;
10
10
  private sourceSyncBlockStoreManager;
@@ -37,7 +37,24 @@ export declare class SyncBlockStoreManager {
37
37
  isSourceBlock(node: PMNode): boolean;
38
38
  registerConfirmationCallback(callback: ConfirmationCallback): () => void;
39
39
  requireConfirmationBeforeDelete(): boolean;
40
- createSyncBlockNode(): SyncBlockNode;
40
+ /**
41
+ * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
42
+ */
43
+ registerCreationCallback(callback: CreationCallback): void;
44
+ /**
45
+ *
46
+ * @returns true if waiting for the result of saving new bodiedSyncBlock to backend
47
+ */
48
+ hasPendingCreation(): boolean;
49
+ /**
50
+ * @returns attributes for a new bodiedSyncBlock node
51
+ */
52
+ generateBodiedSyncBlockAttrs(): SyncBlockAttrs;
53
+ /**
54
+ * Save bodiedSyncBlock with empty content to backend
55
+ * @param attrs attributes Ids of the node
56
+ */
57
+ createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
41
58
  subscribeToSyncBlockData(node: PMNode, callback: SubscriptionCallback): () => void;
42
59
  subscribeToSyncBlockSourceTitle(node: PMNode, callback: TitleSubscriptionCallback): () => void;
43
60
  refreshSubscriptions(): void;
@@ -0,0 +1 @@
1
+ export declare const stringifyError: (error: unknown) => string | undefined;
@@ -1,5 +1,10 @@
1
+ import type { JSONNode } from '@atlaskit/editor-json-transformer';
1
2
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import type { SyncBlockData } from '../common/types';
3
+ import type { SyncBlockData, BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
3
4
  import type { PAGE_TYPE } from './ari';
4
5
  export declare const convertSyncBlockPMNodeToSyncBlockData: (node: PMNode) => SyncBlockData;
5
6
  export declare const isBlogPageType: (pageType: PAGE_TYPE) => boolean;
7
+ export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
8
+ export declare const createBodiedSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
9
+ export declare const convertSyncBlockJSONNodeToSyncBlockNode: (node: JSONNode) => SyncBlockNode | undefined;
10
+ export declare const convertPMNodeToSyncBlockNode: (node: PMNode) => SyncBlockNode | undefined;
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "@atlaskit/css": "^0.15.0",
30
30
  "@atlaskit/editor-json-transformer": "^8.31.0",
31
31
  "@atlaskit/editor-prosemirror": "7.0.0",
32
- "@atlaskit/node-data-provider": "^7.4.0",
32
+ "@atlaskit/node-data-provider": "^7.5.0",
33
33
  "@atlaskit/primitives": "^16.1.0",
34
34
  "@atlaskit/tokens": "^7.1.0",
35
35
  "@babel/runtime": "^7.0.0",
@@ -82,7 +82,7 @@
82
82
  }
83
83
  },
84
84
  "name": "@atlaskit/editor-synced-block-provider",
85
- "version": "2.6.0",
85
+ "version": "2.7.0",
86
86
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
87
87
  "author": "Atlassian Pty Ltd",
88
88
  "license": "Apache-2.0",
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createSyncBlockNode = void 0;
7
- var createSyncBlockNode = exports.createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
8
- return {
9
- type: 'syncBlock',
10
- attrs: {
11
- localId: localId,
12
- resourceId: resourceId
13
- }
14
- };
15
- };
@@ -1,9 +0,0 @@
1
- export const createSyncBlockNode = (localId, resourceId) => {
2
- return {
3
- type: 'syncBlock',
4
- attrs: {
5
- localId,
6
- resourceId
7
- }
8
- };
9
- };
@@ -1,9 +0,0 @@
1
- export var createSyncBlockNode = function createSyncBlockNode(localId, resourceId) {
2
- return {
3
- type: 'syncBlock',
4
- attrs: {
5
- localId: localId,
6
- resourceId: resourceId
7
- }
8
- };
9
- };
@@ -1,2 +0,0 @@
1
- import type { BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
2
- export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;
@@ -1,2 +0,0 @@
1
- import type { BlockInstanceId, ResourceId, SyncBlockNode } from '../common/types';
2
- export declare const createSyncBlockNode: (localId: BlockInstanceId, resourceId: ResourceId) => SyncBlockNode;