@atlaskit/editor-synced-block-provider 2.2.3 → 2.3.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 (29) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -30
  3. package/dist/cjs/providers/syncBlockProvider.js +23 -4
  4. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +319 -63
  5. package/dist/cjs/store-manager/syncBlockStoreManager.js +27 -4
  6. package/dist/cjs/utils/mergeFetchSyncBlockDataResult.js +38 -0
  7. package/dist/es2019/hooks/useFetchSyncBlockData.js +6 -31
  8. package/dist/es2019/providers/syncBlockProvider.js +17 -3
  9. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +172 -44
  10. package/dist/es2019/store-manager/syncBlockStoreManager.js +21 -4
  11. package/dist/es2019/utils/mergeFetchSyncBlockDataResult.js +30 -0
  12. package/dist/esm/hooks/useFetchSyncBlockData.js +6 -31
  13. package/dist/esm/providers/syncBlockProvider.js +21 -2
  14. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +320 -64
  15. package/dist/esm/store-manager/syncBlockStoreManager.js +27 -4
  16. package/dist/esm/utils/mergeFetchSyncBlockDataResult.js +31 -0
  17. package/dist/types/common/schema.d.ts +1 -1
  18. package/dist/types/providers/syncBlockProvider.d.ts +1 -1
  19. package/dist/types/providers/types.d.ts +1 -0
  20. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +24 -8
  21. package/dist/types/store-manager/syncBlockStoreManager.d.ts +12 -4
  22. package/dist/types/utils/mergeFetchSyncBlockDataResult.d.ts +12 -0
  23. package/dist/types-ts4.5/common/schema.d.ts +1 -1
  24. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +1 -1
  25. package/dist/types-ts4.5/providers/types.d.ts +1 -0
  26. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +24 -8
  27. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +12 -4
  28. package/dist/types-ts4.5/utils/mergeFetchSyncBlockDataResult.d.ts +12 -0
  29. package/package.json +1 -1
@@ -0,0 +1,12 @@
1
+ import type { FetchSyncBlockDataResult } from '../providers/types';
2
+ /**
3
+ * Merges two FetchSyncBlockDataResult objects,
4
+ * currently it only preserves the sourceURL from the old result,
5
+ * but this can be extended in the future to preserve other fields and resolve conflicts as needed.
6
+ * e.g. compare timestamps or version numbers to determine which data is more recent.
7
+ *
8
+ * @param oldResult - The existing FetchSyncBlockDataResult object.
9
+ * @param newResult - The new FetchSyncBlockDataResult object to merge.
10
+ * @returns A merged FetchSyncBlockDataResult object.
11
+ */
12
+ export declare const resolveFetchSyncBlockDataResult: (oldResult: FetchSyncBlockDataResult, newResult: FetchSyncBlockDataResult) => FetchSyncBlockDataResult;
@@ -3,4 +3,4 @@
3
3
  * Otherwise we could import defaultSchemaConfig from '@atlaskit/adf-schema/schema-default';
4
4
  * @returns
5
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">;
6
+ export declare const getDefaultSyncBlockSchema: () => import("prosemirror-model").Schema<"status" | "doc" | "paragraph" | "text" | "bulletList" | "orderedList" | "listItem" | "heading" | "blockquote" | "codeBlock" | "panel" | "rule" | "expand" | "nestedExpand" | "table" | "tableCell" | "tableHeader" | "tableRow" | "date" | "layoutSection" | "layoutColumn" | "unsupportedBlock" | "unsupportedInline", "link" | "em" | "strong" | "strike" | "subsup" | "underline" | "code" | "textColor" | "backgroundColor" | "alignment" | "indentation" | "border" | "unsupportedMark" | "unsupportedNodeAttribute" | "typeAheadQuery">;
@@ -1,5 +1,5 @@
1
1
  import type { JSONNode } from '@atlaskit/editor-json-transformer/types';
2
- import type { SyncBlockData, SyncBlockNode } from '../common/types';
2
+ import { type SyncBlockData, type SyncBlockNode } from '../common/types';
3
3
  import { SyncBlockDataProvider, type ADFFetchProvider, type ADFWriteProvider, type FetchSyncBlockDataResult } from '../providers/types';
4
4
  export declare class SyncBlockProvider extends SyncBlockDataProvider {
5
5
  name: string;
@@ -16,3 +16,4 @@ export declare abstract class SyncBlockDataProvider extends NodeDataProvider<Syn
16
16
  abstract getSourceId(): ResourceId;
17
17
  abstract retrieveSyncBlockSourceUrl(node: SyncBlockNode): Promise<string | undefined>;
18
18
  }
19
+ export type SubscriptionCallback = (data: FetchSyncBlockDataResult) => void;
@@ -1,23 +1,39 @@
1
1
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import type { BlockInstanceId } from '../common/types';
3
- import type { FetchSyncBlockDataResult, SyncBlockDataProvider } from '../providers/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { ResourceId, SyncBlockNode } from '../common/types';
4
+ import type { FetchSyncBlockDataResult, SubscriptionCallback, SyncBlockDataProvider } from '../providers/types';
4
5
  export declare class ReferenceSyncBlockStoreManager {
5
6
  private dataProvider?;
6
7
  private syncBlockCache;
8
+ private subscriptions;
7
9
  private syncBlockURLRequests;
10
+ private editorView?;
11
+ private isInitialized;
12
+ private isRefreshingSubscriptions;
8
13
  constructor(dataProvider?: SyncBlockDataProvider);
14
+ init(editorView: EditorView): Promise<void>;
9
15
  /**
10
- *
11
- * @param localId - The local ID of the sync block to get the source URL for
12
- * @param resourceId - The resource ID of the sync block to get the source URL for
13
- * Fetches source URl for a sync block and updates sync block data with the source URL asynchronously.
16
+ * Refreshes the subscriptions for all sync blocks.
17
+ * @returns {Promise<void>}
14
18
  */
19
+ refreshSubscriptions(): Promise<void>;
15
20
  private fetchSyncBlockSourceURL;
21
+ /**
22
+ * Fetch sync block data for a given sync block node.
23
+ * @param syncBlockNode - The sync block node to fetch data for
24
+ * @returns The fetched sync block data result
25
+ */
16
26
  fetchSyncBlockData(syncBlockNode: PMNode): Promise<FetchSyncBlockDataResult>;
27
+ fetchSyncBlocksData(syncBlockNodes: SyncBlockNode[]): Promise<FetchSyncBlockDataResult[]>;
28
+ private updateCache;
29
+ private getFromCache;
30
+ private deleteFromCache;
31
+ subscribe(node: PMNode, callback: SubscriptionCallback): () => void;
17
32
  /**
18
33
  * Get the URL for a sync block.
19
- * @param localId - The local ID of the sync block to get the URL for
34
+ * @param resourceId - The resource ID of the sync block
20
35
  * @returns
21
36
  */
22
- getSyncBlockURL(localId: BlockInstanceId): string | undefined;
37
+ getSyncBlockURL(resourceId: ResourceId): string | undefined;
38
+ destroy(): void;
23
39
  }
@@ -1,13 +1,18 @@
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 { BlockInstanceId, SyncBlockAttrs, SyncBlockNode } from '../common/types';
5
- import type { FetchSyncBlockDataResult, SyncBlockDataProvider } from '../providers/types';
4
+ import type { ResourceId, SyncBlockAttrs, SyncBlockNode } from '../common/types';
5
+ import type { FetchSyncBlockDataResult, SubscriptionCallback, SyncBlockDataProvider } from '../providers/types';
6
6
  import { type ConfirmationCallback } from './sourceSyncBlockStoreManager';
7
7
  export declare class SyncBlockStoreManager {
8
8
  private referenceSyncBlockStoreManager;
9
9
  private sourceSyncBlockStoreManager;
10
10
  constructor(dataProvider?: SyncBlockDataProvider);
11
+ /**
12
+ * Fetch sync block data for a given sync block node.
13
+ * @param syncBlockNode - The sync block node to fetch data for
14
+ * @returns The fetched sync block data result
15
+ */
11
16
  fetchSyncBlockData(syncBlockNode: PMNode): Promise<FetchSyncBlockDataResult | undefined>;
12
17
  /**
13
18
  * Add/update a sync block node to/from the local cache
@@ -22,15 +27,18 @@ export declare class SyncBlockStoreManager {
22
27
  flushBodiedSyncBlocks(): Promise<boolean>;
23
28
  /**
24
29
  * Get the URL for a sync block.
25
- * @param localId - The local ID of the sync block to get the URL for
30
+ * @param resourceId - The resource ID of the sync block to get the URL for
26
31
  * @returns
27
32
  */
28
- getSyncBlockURL(localId: BlockInstanceId): string | undefined;
33
+ getSyncBlockURL(resourceId: ResourceId): string | undefined;
29
34
  setEditorView(editorView: EditorView | undefined): void;
30
35
  isSourceBlock(node: PMNode): boolean;
31
36
  registerConfirmationCallback(callback: ConfirmationCallback): () => void;
32
37
  requireConfirmationBeforeDelete(): boolean;
33
38
  createSyncBlockNode(): SyncBlockNode;
39
+ subscribeToSyncBlockData(node: PMNode, callback: SubscriptionCallback): () => void;
40
+ refreshSubscriptions(): void;
34
41
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
35
42
  rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
43
+ destroy(): void;
36
44
  }
@@ -0,0 +1,12 @@
1
+ import type { FetchSyncBlockDataResult } from '../providers/types';
2
+ /**
3
+ * Merges two FetchSyncBlockDataResult objects,
4
+ * currently it only preserves the sourceURL from the old result,
5
+ * but this can be extended in the future to preserve other fields and resolve conflicts as needed.
6
+ * e.g. compare timestamps or version numbers to determine which data is more recent.
7
+ *
8
+ * @param oldResult - The existing FetchSyncBlockDataResult object.
9
+ * @param newResult - The new FetchSyncBlockDataResult object to merge.
10
+ * @returns A merged FetchSyncBlockDataResult object.
11
+ */
12
+ export declare const resolveFetchSyncBlockDataResult: (oldResult: FetchSyncBlockDataResult, newResult: FetchSyncBlockDataResult) => FetchSyncBlockDataResult;
package/package.json CHANGED
@@ -82,7 +82,7 @@
82
82
  }
83
83
  },
84
84
  "name": "@atlaskit/editor-synced-block-provider",
85
- "version": "2.2.3",
85
+ "version": "2.3.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",