@notionhq/custom-blocks 0.1.43 → 0.1.45
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/README.md +2 -2
- package/dist/bridge/SandboxBridge.d.ts +9 -2
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +24 -9
- package/dist/bridge/dataSources/subscribe.d.ts +3 -0
- package/dist/bridge/dataSources/subscribe.d.ts.map +1 -0
- package/dist/bridge/dataSources/subscribe.js +63 -0
- package/dist/bridge/notifyListener.d.ts +3 -0
- package/dist/bridge/notifyListener.d.ts.map +1 -0
- package/dist/bridge/notifyListener.js +16 -0
- package/dist/bridge/primedResponses.d.ts +8 -0
- package/dist/bridge/primedResponses.d.ts.map +1 -0
- package/dist/bridge/primedResponses.js +5 -0
- package/dist/bridge/sandboxClient.d.ts +3 -3
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +3 -3
- package/dist/customBlock.d.ts +6 -0
- package/dist/customBlock.d.ts.map +1 -1
- package/dist/customBlock.js +6 -0
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/messages/sandboxToHost.d.ts +3 -0
- package/dist/protocol/messages/sandboxToHost.js +2 -0
- package/dist/protocol/messages/unsubscribeDataSourceQuery.d.ts +10 -0
- package/dist/protocol/messages/unsubscribeDataSourceQuery.js +9 -0
- package/dist/react/useDataSource.d.ts.map +1 -1
- package/dist/react/useDataSource.js +26 -29
- package/dist/testing.d.ts +0 -5
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -5
- package/dist/types.d.ts +15 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/data-sources.md +212 -72
- package/docs/lifecycle.md +1 -11
- package/docs/pages.md +0 -2
- package/docs/users.md +0 -1
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +42 -14
- package/src/bridge/dataSources/subscribe.ts +97 -0
- package/src/bridge/notifyListener.ts +14 -0
- package/src/bridge/primedResponses.ts +11 -0
- package/src/bridge/sandboxClient.ts +7 -8
- package/src/customBlock.ts +7 -0
- package/src/react/useDataSource.ts +32 -39
- package/src/testing.ts +1 -8
- package/src/types.ts +18 -15
package/README.md
CHANGED
|
@@ -124,9 +124,9 @@ Each page covers one API category. Import framework-neutral APIs from
|
|
|
124
124
|
`@notionhq/custom-blocks`. Import React hooks and components from
|
|
125
125
|
`@notionhq/custom-blocks/react`.
|
|
126
126
|
|
|
127
|
-
- [`docs/lifecycle.md`](./docs/lifecycle.md) — `<NotionCustomBlock>`, `useCustomBlockInit`, `initCustomBlock`, `NotInIframeError
|
|
127
|
+
- [`docs/lifecycle.md`](./docs/lifecycle.md) — `<NotionCustomBlock>`, `useCustomBlockInit`, `initCustomBlock`, `NotInIframeError`. The handshake, the React wrapper, sizing.
|
|
128
128
|
- [`docs/block-location.md`](./docs/block-location.md) — `useBlockId`, `useParent`, `usePage`, `useTheme`, `useContrastMode`, `NotionTokenScope`, and `NotionTokenScopeProps`. Where the block sits and how to read the host's appearance.
|
|
129
|
-
- [`docs/data-sources.md`](./docs/data-sources.md) — `useDataSource`, `useManifest`, `customBlock.getManifest`, the row, property, and date-value types, plus a worked example.
|
|
129
|
+
- [`docs/data-sources.md`](./docs/data-sources.md) — `customBlock.subscribeToDataSource`, `useDataSource`, `useManifest`, `customBlock.getManifest`, the row, property, and date-value types, plus a worked example.
|
|
130
130
|
- [`docs/pages.md`](./docs/pages.md) — `pages.create / get / update / archive / unarchive`, parent variants (including the recommended `data_source_key`), property input shapes.
|
|
131
131
|
- [`docs/users.md`](./docs/users.md) — `users.list / get`, the `NotionUser` shape, paging.
|
|
132
132
|
- [`docs/errors.md`](./docs/errors.md) — request results, error format, error codes, retries, and initialization failures.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NotionDataSource } from "../protocol/dataSources/dataSource.js";
|
|
2
2
|
import type { NotionPageId } from "../protocol/ids.js";
|
|
3
3
|
import { type InitMessage } from "../protocol/messages/init.js";
|
|
4
|
-
import type { CreatePageArgs, CreatePageResult, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionDataSourcePageUpdateArgs, NotionUserId, UpdatePageArgs, UpdatePageResult
|
|
4
|
+
import type { CreatePageArgs, CreatePageResult, DataSourceQueryOptions, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionDataSourcePageUpdateArgs, NotionUserId, UpdatePageArgs, UpdatePageResult } from "../types.js";
|
|
5
5
|
import { type CustomBlockHostState } from "./hostState.js";
|
|
6
6
|
import type { ManifestLoadResult } from "./loadManifest.js";
|
|
7
7
|
/**
|
|
@@ -13,6 +13,13 @@ export type MessageLogEntry = {
|
|
|
13
13
|
direction: "sent" | "received";
|
|
14
14
|
data: unknown;
|
|
15
15
|
};
|
|
16
|
+
export type QueryDataSourceArgs = {
|
|
17
|
+
subscriptionId: string;
|
|
18
|
+
key: string;
|
|
19
|
+
options?: DataSourceQueryOptions;
|
|
20
|
+
/** Send the query even if an identical query is already loading. */
|
|
21
|
+
forceRequery?: boolean;
|
|
22
|
+
};
|
|
16
23
|
export declare class SandboxBridge {
|
|
17
24
|
private hostState;
|
|
18
25
|
private listeners;
|
|
@@ -67,7 +74,7 @@ export declare class SandboxBridge {
|
|
|
67
74
|
*/
|
|
68
75
|
private scheduleInitResult;
|
|
69
76
|
createDataSourceSubscriptionId(): string;
|
|
70
|
-
queryDataSource(subscriptionId
|
|
77
|
+
queryDataSource({ subscriptionId, key, options, forceRequery, }: QueryDataSourceArgs): void;
|
|
71
78
|
private setDataSourceQueryError;
|
|
72
79
|
releaseDataSourceSubscription(subscriptionId: string): void;
|
|
73
80
|
postResize(height: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EA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cAAc;IA2RtB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,iBAG7B;IAED,YAAY,IAAI,oBAAoB,CAEnC;IAED;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,WAAW,QAGhC;IAED,sBAAsB,SAiBrB;IAED,OAAO,CAAC,mBAAmB;IAmB3B,OAAO,CAAC,SAAS;IAkEjB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAyB1B,8BAA8B,IAAI,MAAM,CAEvC;IAED,eAAe,CAAC,EACf,cAAc,EACd,GAAG,EACH,OAAY,EACZ,YAAoB,GACpB,EAAE,mBAAmB,QA6ErB;IAED,OAAO,CAAC,uBAAuB;IAwB/B,6BAA6B,CAAC,cAAc,EAAE,MAAM,QAkBnD;IAED,UAAU,CAAC,MAAM,EAAE,MAAM,QAWxB;IAED,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA4B1D;IAED,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAUpD;IAED,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAUpD;IAED,SAAS,CAAC,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAW5D;IAED,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA2C1D;IAED;;;;OAIG;IACH,oBAAoB,CAAC,IAAI,EAAE;QAC1B,UAAU,EAAE,gBAAgB,CAAA;QAC5B,MAAM,EAAE,YAAY,CAAA;QACpB,cAAc,EAAE,8BAA8B,CAAA;KAC9C,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqB5B;IAED;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAkE/B"}
|
|
@@ -4,7 +4,6 @@ import { hostToSandboxMessageSchema, } from "../protocol/messages/hostToSandbox.
|
|
|
4
4
|
import { CustomBlockInitializationError, initMessageSchema, } from "../protocol/messages/init.js";
|
|
5
5
|
import { CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION } from "../protocol/protocolVersion.js";
|
|
6
6
|
import * as v from "valibot";
|
|
7
|
-
import { globalPrimedResponsesCache } from "../testing.js";
|
|
8
7
|
import { unreachable } from "../utils.js";
|
|
9
8
|
import { CUSTOM_BLOCKS_SDK_VERSION } from "../version.js";
|
|
10
9
|
import { NOTION_DARK_BACKGROUND_BASE, NOTION_LIGHT_BACKGROUND_BASE, } from "./appearance.js";
|
|
@@ -12,7 +11,9 @@ import { resolveDataSourceQuery } from "./dataSources/query.js";
|
|
|
12
11
|
import { resolveDataSources } from "./dataSources/resolve.js";
|
|
13
12
|
import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js";
|
|
14
13
|
import { createEmptyDataSourceQueryState, } from "./hostState.js";
|
|
14
|
+
import { notifyListener } from "./notifyListener.js";
|
|
15
15
|
import { PendingRequests } from "./pendingRequests.js";
|
|
16
|
+
import { globalPrimedResponsesCache } from "./primedResponses.js";
|
|
16
17
|
const RESPONSE_TYPE_BY_REQUEST = new Map([
|
|
17
18
|
["getPage", "getPageResult"],
|
|
18
19
|
["createPage", "createPageResult"],
|
|
@@ -181,7 +182,7 @@ export class SandboxBridge {
|
|
|
181
182
|
}
|
|
182
183
|
notify = () => {
|
|
183
184
|
for (const listener of this.listeners) {
|
|
184
|
-
listener
|
|
185
|
+
notifyListener(listener);
|
|
185
186
|
}
|
|
186
187
|
};
|
|
187
188
|
handleMessage = (event) => {
|
|
@@ -312,13 +313,21 @@ export class SandboxBridge {
|
|
|
312
313
|
nextBindings,
|
|
313
314
|
});
|
|
314
315
|
this.latestDataSourceBindings = nextBindings;
|
|
315
|
-
//
|
|
316
|
-
const
|
|
316
|
+
// Preserve rows only while the key still refers to the same backing data source.
|
|
317
|
+
const previousSourcesByKey = new Map(hostState.dataSources.map(source => [source.key, source]));
|
|
318
|
+
const nextSourcesByKey = new Map(dataSources.map(source => [source.key, source]));
|
|
317
319
|
const prunedState = {};
|
|
318
320
|
for (const [subscriptionId, state] of Object.entries(hostState.dataSourceState)) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
+
const nextSource = nextSourcesByKey.get(state.dataSourceKey);
|
|
322
|
+
if (nextSource === undefined) {
|
|
323
|
+
continue;
|
|
321
324
|
}
|
|
325
|
+
const previousSource = previousSourcesByKey.get(state.dataSourceKey);
|
|
326
|
+
prunedState[subscriptionId] =
|
|
327
|
+
previousSource?.collectionPointer?.id ===
|
|
328
|
+
nextSource.collectionPointer?.id
|
|
329
|
+
? state
|
|
330
|
+
: createEmptyDataSourceQueryState(state.dataSourceKey);
|
|
322
331
|
}
|
|
323
332
|
this.hostState = {
|
|
324
333
|
...hostState,
|
|
@@ -552,7 +561,7 @@ export class SandboxBridge {
|
|
|
552
561
|
createDataSourceSubscriptionId() {
|
|
553
562
|
return `data-source:${globalThis.crypto.randomUUID()}`;
|
|
554
563
|
}
|
|
555
|
-
queryDataSource(subscriptionId, key, options = {}) {
|
|
564
|
+
queryDataSource({ subscriptionId, key, options = {}, forceRequery = false, }) {
|
|
556
565
|
if (this.hostState.status !== "initialized") {
|
|
557
566
|
return;
|
|
558
567
|
}
|
|
@@ -591,7 +600,8 @@ export class SandboxBridge {
|
|
|
591
600
|
return;
|
|
592
601
|
}
|
|
593
602
|
const query = resolvedQuery.query;
|
|
594
|
-
if (
|
|
603
|
+
if (!forceRequery &&
|
|
604
|
+
currentState.isLoading &&
|
|
595
605
|
currentState.latestQueryIdentity === query.identity) {
|
|
596
606
|
return;
|
|
597
607
|
}
|
|
@@ -609,7 +619,6 @@ export class SandboxBridge {
|
|
|
609
619
|
},
|
|
610
620
|
},
|
|
611
621
|
};
|
|
612
|
-
this.notify();
|
|
613
622
|
const outbound = {
|
|
614
623
|
type: "queryDataSource",
|
|
615
624
|
subscriptionId,
|
|
@@ -619,6 +628,7 @@ export class SandboxBridge {
|
|
|
619
628
|
...(query.sorts !== undefined ? { sorts: query.sorts } : {}),
|
|
620
629
|
};
|
|
621
630
|
this.postToHost(outbound);
|
|
631
|
+
this.notify();
|
|
622
632
|
}
|
|
623
633
|
setDataSourceQueryError(subscriptionId, currentState, error) {
|
|
624
634
|
if (this.hostState.status !== "initialized") {
|
|
@@ -649,6 +659,11 @@ export class SandboxBridge {
|
|
|
649
659
|
...this.hostState,
|
|
650
660
|
dataSourceState,
|
|
651
661
|
};
|
|
662
|
+
const outbound = {
|
|
663
|
+
type: "unsubscribeDataSourceQuery",
|
|
664
|
+
subscriptionId,
|
|
665
|
+
};
|
|
666
|
+
this.postToHost(outbound);
|
|
652
667
|
}
|
|
653
668
|
postResize(height) {
|
|
654
669
|
if (typeof window === "undefined") {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAQ/D,wBAAgB,qBAAqB,CAAC,EACrC,GAAG,EACH,UAAU,EACV,OAAO,EAAE,eAAoB,GAC7B,EAAE,yBAAyB,GAAG,MAAM,IAAI,CAoFxC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { notifyListener } from "../notifyListener.js";
|
|
2
|
+
import { customBlockDataSources, customBlockHost } from "../sandboxClient.js";
|
|
3
|
+
export function subscribeToDataSource({ key, onSnapshot, options: providedOptions = {}, }) {
|
|
4
|
+
const options = structuredClone(providedOptions);
|
|
5
|
+
const subscriptionId = customBlockDataSources.createSubscriptionId();
|
|
6
|
+
let active = true;
|
|
7
|
+
let lastSnapshotInputs;
|
|
8
|
+
let lastMatchingSignature;
|
|
9
|
+
const deliverSnapshotIfChanged = (hostState, dataSource, queryState) => {
|
|
10
|
+
if (lastSnapshotInputs !== undefined &&
|
|
11
|
+
lastSnapshotInputs.status === hostState.status &&
|
|
12
|
+
lastSnapshotInputs.dataSource === dataSource &&
|
|
13
|
+
lastSnapshotInputs.queryState === queryState) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const snapshot = customBlockDataSources.getView(hostState, key, subscriptionId);
|
|
17
|
+
// Record inputs before calling consumer code, which can trigger another notification.
|
|
18
|
+
lastSnapshotInputs = { status: hostState.status, dataSource, queryState };
|
|
19
|
+
notifyListener(() => onSnapshot(snapshot));
|
|
20
|
+
};
|
|
21
|
+
const handleHostChange = () => {
|
|
22
|
+
if (!active) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const hostState = customBlockHost.getState();
|
|
26
|
+
if (hostState.status !== "initialized") {
|
|
27
|
+
deliverSnapshotIfChanged(hostState, undefined, undefined);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const dataSource = hostState.dataSources.find(source => source.key === key);
|
|
31
|
+
const signature = dataSource === undefined ? null : JSON.stringify(dataSource);
|
|
32
|
+
if (signature !== lastMatchingSignature) {
|
|
33
|
+
const forceRequery = lastMatchingSignature !== undefined;
|
|
34
|
+
lastMatchingSignature = signature;
|
|
35
|
+
// Querying updates SDK state and calls this listener again.
|
|
36
|
+
customBlockDataSources.query({
|
|
37
|
+
subscriptionId,
|
|
38
|
+
key,
|
|
39
|
+
options,
|
|
40
|
+
forceRequery,
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
deliverSnapshotIfChanged(hostState, dataSource, hostState.dataSourceState[subscriptionId]);
|
|
45
|
+
};
|
|
46
|
+
const unsubscribeHost = customBlockHost.subscribe(handleHostChange);
|
|
47
|
+
try {
|
|
48
|
+
handleHostChange();
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
unsubscribeHost();
|
|
52
|
+
customBlockDataSources.release(subscriptionId);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
if (!active) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
active = false;
|
|
60
|
+
unsubscribeHost();
|
|
61
|
+
customBlockDataSources.release(subscriptionId);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifyListener.d.ts","sourceRoot":"","sources":["../../src/bridge/notifyListener.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAYzD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Report consumer errors without interrupting bridge operations or other listeners. */
|
|
2
|
+
export function notifyListener(listener) {
|
|
3
|
+
try {
|
|
4
|
+
listener();
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
if (typeof globalThis.reportError === "function") {
|
|
8
|
+
globalThis.reportError(error);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
throw error;
|
|
13
|
+
}, 0);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BridgeMessagePayload } from "../protocol/index.js";
|
|
2
|
+
import type { PrimeableHostToSandboxMessage } from "../protocol/messages/hostToSandbox.js";
|
|
3
|
+
/**
|
|
4
|
+
* Shared across sandbox bridge instances. Each result type holds one response;
|
|
5
|
+
* consuming it removes it, and priming it again replaces the previous response.
|
|
6
|
+
*/
|
|
7
|
+
export declare const globalPrimedResponsesCache: Map<"createPageResult" | "getPageResult" | "getUserResult" | "listUsersResult" | "queryDataSourceResult" | "updatePageResult", BridgeMessagePayload<PrimeableHostToSandboxMessage>>;
|
|
8
|
+
//# sourceMappingURL=primedResponses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primedResponses.d.ts","sourceRoot":"","sources":["../../src/bridge/primedResponses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAC5E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAA;AAE/G;;;GAGG;AACH,eAAO,MAAM,0BAA0B,qLAGpC,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { NotionPageId } from "../protocol/ids.js";
|
|
2
2
|
import type { InitMessage } from "../protocol/messages/init.js";
|
|
3
|
-
import type { CreatePageArgs, CreatePageResult, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionUserId, UpdatePageArgs, UpdatePageResult
|
|
3
|
+
import type { CreatePageArgs, CreatePageResult, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionUserId, UpdatePageArgs, UpdatePageResult } from "../types.js";
|
|
4
4
|
import { type CustomBlockHostState, type DataSourceQueryView } from "./hostState.js";
|
|
5
5
|
import type { ManifestLoadResult } from "./loadManifest.js";
|
|
6
|
-
import { type MessageLogEntry } from "./SandboxBridge.js";
|
|
6
|
+
import { type MessageLogEntry, type QueryDataSourceArgs } from "./SandboxBridge.js";
|
|
7
7
|
export declare const customBlockHost: {
|
|
8
8
|
start: () => void;
|
|
9
9
|
sendConnect: (manifestResult: ManifestLoadResult) => void;
|
|
@@ -20,7 +20,7 @@ export declare const customBlockHost: {
|
|
|
20
20
|
};
|
|
21
21
|
export declare const customBlockDataSources: {
|
|
22
22
|
createSubscriptionId: () => string;
|
|
23
|
-
query: (
|
|
23
|
+
query: (args: QueryDataSourceArgs) => void;
|
|
24
24
|
release: (subscriptionId: string) => void;
|
|
25
25
|
getView: (hostState: CustomBlockHostState, key: string, subscriptionId: string) => DataSourceQueryView;
|
|
26
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAA;AACp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GhC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;IACH,MAAM,UAAU,cAAc,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAI1D;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;IAInD;;OAEG;IACH,MAAM,UAAU,cAAc,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAI1D;;OAEG;IACH,OAAO,WAAW,YAAY,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAI1D;;OAEG;IACH,SAAS,WAAW,YAAY,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAI5D;;;OAGG;IACH,MAAM,WAAW,YAAY,KAAG,OAAO,CAAC,gBAAgB,CAAC;CASzD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;IACH,IAAI,WAAW,aAAa,KAAG,OAAO,CAAC,eAAe,CAAC;IAIvD;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;CAGnD,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getDataSourceQueryView as getDataSourceQueryViewWithBridge, } from "./hostState.js";
|
|
2
|
-
import { SandboxBridge } from "./SandboxBridge.js";
|
|
2
|
+
import { SandboxBridge, } from "./SandboxBridge.js";
|
|
3
3
|
let bridge;
|
|
4
4
|
let didWarnAboutPagesDelete = false;
|
|
5
5
|
function getBridge() {
|
|
@@ -42,8 +42,8 @@ export const customBlockDataSources = {
|
|
|
42
42
|
createSubscriptionId: () => {
|
|
43
43
|
return getBridge().createDataSourceSubscriptionId();
|
|
44
44
|
},
|
|
45
|
-
query: (
|
|
46
|
-
getBridge().queryDataSource(
|
|
45
|
+
query: (args) => {
|
|
46
|
+
getBridge().queryDataSource(args);
|
|
47
47
|
},
|
|
48
48
|
release: (subscriptionId) => {
|
|
49
49
|
getBridge().releaseDataSourceSubscription(subscriptionId);
|
package/dist/customBlock.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { NotionParent } from "./protocol/parent.js";
|
|
|
7
7
|
import type { NotionTheme } from "./protocol/theme.js";
|
|
8
8
|
import type { NotionUser } from "./protocol/users/user.js";
|
|
9
9
|
import { autoResize } from "./autoResize.js";
|
|
10
|
+
import { subscribeToDataSource } from "./bridge/dataSources/subscribe.js";
|
|
10
11
|
export type CustomBlockState = {
|
|
11
12
|
status: "uninitialized";
|
|
12
13
|
theme: NotionTheme;
|
|
@@ -36,5 +37,10 @@ export declare const customBlock: {
|
|
|
36
37
|
getPage(): CustomBlockPage;
|
|
37
38
|
getManifest(): CustomBlockManifest;
|
|
38
39
|
autoResize: typeof autoResize;
|
|
40
|
+
/**
|
|
41
|
+
* Registers a listener that receives the current query snapshot and later updates.
|
|
42
|
+
* Returns a function that removes this listener. Other listeners remain subscribed.
|
|
43
|
+
*/
|
|
44
|
+
subscribeToDataSource: typeof subscribeToDataSource;
|
|
39
45
|
};
|
|
40
46
|
//# sourceMappingURL=customBlock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customBlock.d.ts","sourceRoot":"","sources":["../src/customBlock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,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AAe;mBAIX,mBAAmB;;IAMlC;;;OAGG;;CAEH,CAAA"}
|
package/dist/customBlock.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { autoResize } from "./autoResize.js";
|
|
2
|
+
import { subscribeToDataSource } from "./bridge/dataSources/subscribe.js";
|
|
2
3
|
import { customBlockHost } from "./bridge/sandboxClient.js";
|
|
3
4
|
/**
|
|
4
5
|
* Framework-neutral runtime state APIs for a custom block. Call `initCustomBlock`
|
|
@@ -33,6 +34,11 @@ export const customBlock = {
|
|
|
33
34
|
return getInitializedHostState("getManifest").manifest;
|
|
34
35
|
},
|
|
35
36
|
autoResize,
|
|
37
|
+
/**
|
|
38
|
+
* Registers a listener that receives the current query snapshot and later updates.
|
|
39
|
+
* Returns a function that removes this listener. Other listeners remain subscribed.
|
|
40
|
+
*/
|
|
41
|
+
subscribeToDataSource,
|
|
36
42
|
};
|
|
37
43
|
let lastHostState;
|
|
38
44
|
let lastPublicState;
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from "./messages/queryDataSourceResult.js";
|
|
|
39
39
|
export * from "./messages/resize.js";
|
|
40
40
|
export * from "./messages/sandboxToHost.js";
|
|
41
41
|
export * from "./messages/themeChanged.js";
|
|
42
|
+
export * from "./messages/unsubscribeDataSourceQuery.js";
|
|
42
43
|
export * from "./messages/updatePage.js";
|
|
43
44
|
export * from "./messages/updatePageResult.js";
|
|
44
45
|
export * from "./pages/page.js";
|
package/dist/protocol/index.js
CHANGED
|
@@ -39,6 +39,7 @@ export * from "./messages/queryDataSourceResult.js";
|
|
|
39
39
|
export * from "./messages/resize.js";
|
|
40
40
|
export * from "./messages/sandboxToHost.js";
|
|
41
41
|
export * from "./messages/themeChanged.js";
|
|
42
|
+
export * from "./messages/unsubscribeDataSourceQuery.js";
|
|
42
43
|
export * from "./messages/updatePage.js";
|
|
43
44
|
export * from "./messages/updatePageResult.js";
|
|
44
45
|
export * from "./pages/page.js";
|
|
@@ -411,6 +411,9 @@ export declare const sandboxToHostMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
411
411
|
readonly propertyId: v.StringSchema<undefined>;
|
|
412
412
|
readonly direction: v.PicklistSchema<["ascending", "descending"], undefined>;
|
|
413
413
|
}, undefined>, undefined>, undefined>;
|
|
414
|
+
}, undefined>, v.ObjectSchema<{
|
|
415
|
+
readonly type: v.LiteralSchema<"unsubscribeDataSourceQuery", undefined>;
|
|
416
|
+
readonly subscriptionId: v.StringSchema<undefined>;
|
|
414
417
|
}, undefined>, v.ObjectSchema<{
|
|
415
418
|
readonly type: v.LiteralSchema<"createPage", undefined>;
|
|
416
419
|
readonly requestId: v.StringSchema<undefined>;
|
|
@@ -8,6 +8,7 @@ import { invalidHostMessageSchema } from "./invalidHostMessage.js";
|
|
|
8
8
|
import { listUsersMessageSchema } from "./listUsers.js";
|
|
9
9
|
import { queryDataSourceMessageSchema } from "./queryDataSource.js";
|
|
10
10
|
import { resizeMessageSchema } from "./resize.js";
|
|
11
|
+
import { unsubscribeDataSourceQueryMessageSchema } from "./unsubscribeDataSourceQuery.js";
|
|
11
12
|
import { updatePageMessageSchema } from "./updatePage.js";
|
|
12
13
|
/**
|
|
13
14
|
* Discriminated union of every message the sandbox is allowed to send the host. Useful for hosts
|
|
@@ -17,6 +18,7 @@ export const sandboxToHostMessageSchema = v.variant("type", [
|
|
|
17
18
|
connectMessageSchema,
|
|
18
19
|
initResultMessageSchema,
|
|
19
20
|
queryDataSourceMessageSchema,
|
|
21
|
+
unsubscribeDataSourceQueryMessageSchema,
|
|
20
22
|
createPageMessageSchema,
|
|
21
23
|
getPageMessageSchema,
|
|
22
24
|
getUserMessageSchema,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Tells the host to stop an active data source query subscription.
|
|
4
|
+
*/
|
|
5
|
+
export declare const unsubscribeDataSourceQueryMessageSchema: v.ObjectSchema<{
|
|
6
|
+
readonly type: v.LiteralSchema<"unsubscribeDataSourceQuery", undefined>;
|
|
7
|
+
/** The subscription to remove from the host. */
|
|
8
|
+
readonly subscriptionId: v.StringSchema<undefined>;
|
|
9
|
+
}, undefined>;
|
|
10
|
+
export type UnsubscribeDataSourceQueryMessage = v.InferOutput<typeof unsubscribeDataSourceQueryMessageSchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Tells the host to stop an active data source query subscription.
|
|
4
|
+
*/
|
|
5
|
+
export const unsubscribeDataSourceQueryMessageSchema = v.object({
|
|
6
|
+
type: v.literal("unsubscribeDataSourceQuery"),
|
|
7
|
+
/** The subscription to remove from the host. */
|
|
8
|
+
subscriptionId: v.string(),
|
|
9
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataSource.d.ts","sourceRoot":"","sources":["../../src/react/useDataSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"useDataSource.d.ts","sourceRoot":"","sources":["../../src/react/useDataSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAiB5E;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,oBAAoB,GAC5B,mBAAmB,CAqBrB"}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { getDataSourceQueryOptionsIdentity } from "../bridge/dataSources/query.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { customBlock } from "../customBlock.js";
|
|
4
|
+
const EMPTY_DATA_SOURCE_RESULT = {
|
|
5
|
+
items: [],
|
|
6
|
+
propertySchemasById: {},
|
|
7
|
+
propertyIdsByKey: {},
|
|
8
|
+
propertySchemasByKey: {},
|
|
9
|
+
isLoading: false,
|
|
10
|
+
hasMore: false,
|
|
11
|
+
};
|
|
5
12
|
/**
|
|
6
13
|
* Reads from the data source mapped to the given semantic `key`.
|
|
7
14
|
*
|
|
@@ -13,34 +20,24 @@ import { useCustomBlockHost } from "./useHostState.js";
|
|
|
13
20
|
* const { items, isLoading, hasMore, error } = useDataSource("default", { limit: 25 })
|
|
14
21
|
*/
|
|
15
22
|
export function useDataSource(key, options) {
|
|
16
|
-
const host = useCustomBlockHost();
|
|
17
|
-
const [subscriptionId] = useState(() => customBlockDataSources.createSubscriptionId());
|
|
18
23
|
const optionsIdentity = getDataSourceQueryOptionsIdentity(options);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const [state, setState] = useState(() => ({
|
|
25
|
+
key,
|
|
26
|
+
optionsIdentity,
|
|
27
|
+
snapshot: EMPTY_DATA_SOURCE_RESULT,
|
|
28
|
+
}));
|
|
23
29
|
// biome-ignore lint/correctness/useExhaustiveDependencies(options): Compare options by value through optionsIdentity. Object identity alone must not trigger queries.
|
|
24
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies(optionsIdentity): Changes to the serialized options must trigger a query even though the callback reads options.
|
|
25
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies(matchingDataSource): Requery when the matching data source changes, even when the key and options are unchanged.
|
|
26
30
|
useEffect(() => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}, [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
propertySchemasById: view.propertySchemasById,
|
|
40
|
-
propertyIdsByKey: view.propertyIdsByKey,
|
|
41
|
-
propertySchemasByKey: view.propertySchemasByKey,
|
|
42
|
-
isLoading: view.isLoading,
|
|
43
|
-
hasMore: view.hasMore,
|
|
44
|
-
error: view.error,
|
|
45
|
-
};
|
|
31
|
+
return customBlock.subscribeToDataSource({
|
|
32
|
+
key,
|
|
33
|
+
onSnapshot: snapshot => {
|
|
34
|
+
setState({ key, optionsIdentity, snapshot });
|
|
35
|
+
},
|
|
36
|
+
options,
|
|
37
|
+
});
|
|
38
|
+
}, [key, optionsIdentity]);
|
|
39
|
+
if (state.key !== key || state.optionsIdentity !== optionsIdentity) {
|
|
40
|
+
return EMPTY_DATA_SOURCE_RESULT;
|
|
41
|
+
}
|
|
42
|
+
return state.snapshot;
|
|
46
43
|
}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { BridgeMessagePayload } from "./protocol/index.js";
|
|
2
2
|
import type { PrimeableHostToSandboxMessage } from "./protocol/messages/hostToSandbox.js";
|
|
3
|
-
/**
|
|
4
|
-
* Shared across sandbox bridge instances. Each result type holds one response;
|
|
5
|
-
* consuming it removes it, and priming it again replaces the previous response.
|
|
6
|
-
*/
|
|
7
|
-
export declare const globalPrimedResponsesCache: Map<"createPageResult" | "getPageResult" | "getUserResult" | "listUsersResult" | "queryDataSourceResult" | "updatePageResult", BridgeMessagePayload<PrimeableHostToSandboxMessage>>;
|
|
8
3
|
/**
|
|
9
4
|
* Injects a one-use response for SDK tests and verification fixtures. The next
|
|
10
5
|
* matching request receives it locally without reaching the host; later requests
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAC5E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAA;
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAC5E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAA;AAI/G;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,6BAA6B,EAAE,EAC1E,YAAY,EACZ,QAAQ,GACR,EAAE;IACF,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;IACvB,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;CACjC,QAEA"}
|
package/dist/testing.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Shared across sandbox bridge instances. Each result type holds one response;
|
|
3
|
-
* consuming it removes it, and priming it again replaces the previous response.
|
|
4
|
-
*/
|
|
5
|
-
export const globalPrimedResponsesCache = new Map();
|
|
1
|
+
import { globalPrimedResponsesCache } from "./bridge/primedResponses.js";
|
|
6
2
|
/**
|
|
7
3
|
* Injects a one-use response for SDK tests and verification fixtures. The next
|
|
8
4
|
* matching request receives it locally without reaching the host; later requests
|
package/dist/types.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type NotionPagePropertyInputMap = {
|
|
|
31
31
|
[propertyIdOrKey: string]: NotionPagePropertyInputValue;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* Consumer-facing page shape returned from
|
|
34
|
+
* Consumer-facing page shape returned from a data source snapshot. Derived from the bridge payload
|
|
35
35
|
* plus the data source's `propertyIdsByKey`.
|
|
36
36
|
*/
|
|
37
37
|
export type NotionDataSourcePage = {
|
|
@@ -129,14 +129,14 @@ export type NotionDataSourceFilter = NotionDataSourcePropertyFilter | {
|
|
|
129
129
|
and: NotionDataSourcePropertyFilter[];
|
|
130
130
|
};
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
132
|
+
* Latest live snapshot of a data source query.
|
|
133
133
|
*
|
|
134
134
|
* - `items` — the rows the host has returned so far. Empty until the first response arrives.
|
|
135
135
|
* - `isLoading` — `true` while a query is in flight.
|
|
136
|
-
* - `hasMore` — `true` if the host indicated more rows are available beyond the
|
|
136
|
+
* - `hasMore` — `true` if the host indicated more rows are available beyond the requested prefix.
|
|
137
137
|
* - `error` — structured error information if the most recent query failed.
|
|
138
138
|
*/
|
|
139
|
-
export type
|
|
139
|
+
export type DataSourceSnapshot = {
|
|
140
140
|
items: NotionDataSourcePage[];
|
|
141
141
|
/**
|
|
142
142
|
* Collection/data source schema for the bound Notion data source, including raw property
|
|
@@ -169,21 +169,21 @@ export type UseDataSourceResult = {
|
|
|
169
169
|
hasMore: boolean;
|
|
170
170
|
error?: CustomBlockQueryDataSourceErrorInfo;
|
|
171
171
|
};
|
|
172
|
-
export type
|
|
173
|
-
/**
|
|
174
|
-
* Maximum number of rows to request from the host. Defaults to 20.
|
|
175
|
-
*/
|
|
172
|
+
export type DataSourceQueryOptions = {
|
|
173
|
+
/** Maximum number of rows to request from the host. Defaults to 20. */
|
|
176
174
|
limit?: number;
|
|
177
|
-
/**
|
|
178
|
-
* Optional property filter. The SDK resolves semantic property keys before
|
|
179
|
-
* it sends the query to the host.
|
|
180
|
-
*/
|
|
175
|
+
/** Optional property filter. The SDK resolves semantic keys before it sends the query. */
|
|
181
176
|
filter?: NotionDataSourceFilter;
|
|
182
|
-
/**
|
|
183
|
-
* Optional property sorts. The host applies them in array order.
|
|
184
|
-
*/
|
|
177
|
+
/** Optional property sorts. The host applies them in array order. */
|
|
185
178
|
sorts?: NotionDataSourceSort[];
|
|
186
179
|
};
|
|
180
|
+
export type SubscribeToDataSourceArgs = {
|
|
181
|
+
key: string;
|
|
182
|
+
onSnapshot: (snapshot: DataSourceSnapshot) => void;
|
|
183
|
+
options?: DataSourceQueryOptions;
|
|
184
|
+
};
|
|
185
|
+
export type UseDataSourceResult = DataSourceSnapshot;
|
|
186
|
+
export type UseDataSourceOptions = DataSourceQueryOptions;
|
|
187
187
|
/**
|
|
188
188
|
* Parent reference accepted by `sdk.pages.create`. Mirrors Notion's public `POST /v1/pages`
|
|
189
189
|
* parent shape; see https://developers.notion.com/reference/data-source.
|