@notionhq/custom-blocks 0.3.2 → 0.3.4
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/LICENSE +21 -0
- package/README.md +13 -19
- package/dist/bridge/SandboxBridge.d.ts +0 -2
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +16 -39
- package/dist/bridge/SandboxInitialization.d.ts +1 -3
- package/dist/bridge/SandboxInitialization.d.ts.map +1 -1
- package/dist/bridge/SandboxInitialization.js +13 -15
- package/dist/bridge/appearance.d.ts +2 -10
- package/dist/bridge/appearance.d.ts.map +1 -1
- package/dist/bridge/appearance.js +2 -10
- package/dist/bridge/dataSources/query.d.ts +1 -2
- package/dist/bridge/dataSources/query.d.ts.map +1 -1
- package/dist/bridge/dataSources/query.js +15 -398
- package/dist/bridge/dataSources/queryFilter.d.ts +10 -0
- package/dist/bridge/dataSources/queryFilter.d.ts.map +1 -0
- package/dist/bridge/dataSources/queryFilter.js +123 -0
- package/dist/bridge/dataSources/resolveProperty.d.ts +1 -20
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolveProperty.js +37 -32
- package/dist/bridge/dataSources/resolvePropertyAddress.d.ts +10 -0
- package/dist/bridge/dataSources/resolvePropertyAddress.d.ts.map +1 -0
- package/dist/bridge/dataSources/resolvePropertyAddress.js +55 -0
- package/dist/bridge/dataSources/resolveSorts.d.ts +10 -0
- package/dist/bridge/dataSources/resolveSorts.d.ts.map +1 -0
- package/dist/bridge/dataSources/resolveSorts.js +80 -0
- package/dist/bridge/hostState.d.ts +3 -7
- package/dist/bridge/hostState.d.ts.map +1 -1
- package/dist/bridge/hostState.js +0 -24
- package/dist/bridge/page.d.ts +9 -3
- package/dist/bridge/page.d.ts.map +1 -1
- package/dist/bridge/page.js +19 -2
- package/dist/bridge/readLocalManifest.d.ts +23 -0
- package/dist/bridge/readLocalManifest.d.ts.map +1 -0
- package/dist/bridge/readLocalManifest.js +46 -0
- package/dist/bridge/sandboxClient.d.ts +0 -2
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +50 -24
- package/dist/protocol/dataSources/dataSourcePage.d.ts +3 -4
- package/dist/protocol/dataSources/dataSourcePage.js +2 -3
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/isLocalBlockServerUrl.d.ts +2 -0
- package/dist/protocol/isLocalBlockServerUrl.js +9 -0
- package/dist/protocol/messages/connect.d.ts +2 -2
- package/dist/protocol/messages/connect.js +2 -2
- package/dist/protocol/messages/createPage.d.ts +1 -1
- package/dist/protocol/messages/createPage.js +1 -1
- package/dist/protocol/messages/createPageResult.d.ts +3 -3
- package/dist/protocol/messages/createPageResult.js +4 -4
- package/dist/protocol/messages/getPage.d.ts +2 -2
- package/dist/protocol/messages/getPage.js +4 -4
- package/dist/protocol/messages/hostToSandbox.d.ts +3 -3
- package/dist/protocol/messages/hostToSandbox.js +10 -10
- package/dist/protocol/messages/init.d.ts +1 -1
- package/dist/protocol/messages/queryDataSource.d.ts +24 -0
- package/dist/protocol/messages/queryDataSource.js +2 -0
- package/dist/protocol/messages/queryDataSourceResult.d.ts +3 -3
- package/dist/protocol/messages/queryDataSourceResult.js +5 -5
- package/dist/protocol/messages/sandboxToHost.d.ts +8 -0
- package/dist/protocol/messages/updatePageResult.d.ts +3 -3
- package/dist/protocol/messages/updatePageResult.js +4 -4
- package/dist/protocol/pages/page.d.ts +4 -4
- package/dist/protocol/pages/page.js +2 -2
- package/dist/protocol/parent.d.ts +1 -1
- package/dist/protocol/protocolVersion.d.ts +3 -2
- package/dist/protocol/protocolVersion.js +4 -2
- package/dist/react/useDataSource.d.ts +2 -2
- package/dist/react/useDataSource.js +2 -2
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +6 -4
- package/docs/bridge-interceptors.md +4 -0
- package/docs/build-tools.md +58 -0
- package/docs/data-sources.md +24 -18
- package/docs/deployment.md +23 -36
- package/docs/errors.md +75 -52
- package/docs/lifecycle.md +10 -3
- package/docs/pages.md +84 -76
- package/docs/users.md +4 -4
- package/package.json +4 -19
- package/src/bridge/SandboxBridge.ts +18 -48
- package/src/bridge/SandboxInitialization.ts +14 -20
- package/src/bridge/appearance.ts +2 -10
- package/src/bridge/dataSources/query.ts +17 -530
- package/src/bridge/dataSources/queryFilter.ts +181 -0
- package/src/bridge/dataSources/resolveProperty.ts +48 -39
- package/src/bridge/dataSources/resolvePropertyAddress.ts +62 -0
- package/src/bridge/dataSources/resolveSorts.ts +107 -0
- package/src/bridge/hostState.ts +3 -43
- package/src/bridge/page.ts +28 -4
- package/src/bridge/readLocalManifest.ts +60 -0
- package/src/bridge/sandboxClient.ts +63 -38
- package/src/react/useDataSource.ts +2 -2
- package/src/types.ts +5 -5
- package/dist/bridge/loadManifest.d.ts +0 -21
- package/dist/bridge/loadManifest.d.ts.map +0 -1
- package/dist/bridge/loadManifest.js +0 -85
- package/src/bridge/loadManifest.ts +0 -114
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Notion Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -6,24 +6,18 @@ Custom blocks let you build custom UI inside Notion that uses workspace data. Th
|
|
|
6
6
|
to read and update data the viewer can access. It includes framework-neutral TypeScript APIs and
|
|
7
7
|
React hooks.
|
|
8
8
|
|
|
9
|
-
## Bundle tooling
|
|
10
|
-
|
|
11
|
-
Node build tools can import `build` and `upload` from `@notionhq/custom-blocks/bundle`. See
|
|
12
|
-
[deployment tooling](./docs/deployment.md#apps-sdk-integration).
|
|
13
|
-
|
|
14
9
|
## Install
|
|
15
10
|
|
|
16
11
|
Create a worker project with `ntn workers new --template custom`. Use the dependencies and
|
|
17
12
|
entrypoint that the Notion CLI generates.
|
|
18
13
|
|
|
19
14
|
React is optional. Blocks that import `@notionhq/custom-blocks/react` need `react` and `react-dom`.
|
|
20
|
-
This repository's fixtures use the workspace SDK.
|
|
21
15
|
|
|
22
|
-
For local preview, run `ntn workers customblocks dev` from the worker project.
|
|
23
|
-
|
|
16
|
+
For local preview, run `ntn workers customblocks dev` from the worker project. Open the shell URL
|
|
17
|
+
printed by the command. Install
|
|
24
18
|
[`@notionhq/custom-blocks-dev-shell`](https://www.npmjs.com/package/@notionhq/custom-blocks-dev-shell)
|
|
25
19
|
as a devDependency to pin the shell and get its reference docs in `node_modules`. See
|
|
26
|
-
[`docs/deployment.md`](
|
|
20
|
+
[`docs/deployment.md`](docs/deployment.md) for local serving details.
|
|
27
21
|
|
|
28
22
|
## Quick start
|
|
29
23
|
|
|
@@ -107,31 +101,31 @@ wrap the portal content in another `<NotionTokenScope>`.
|
|
|
107
101
|
|
|
108
102
|
Outside React, use `customBlock.getTheme()` and `customBlock.getContrastMode()` to read the current
|
|
109
103
|
appearance, or `customBlock.subscribeToTheme()` and `customBlock.subscribeToContrastMode()` to
|
|
110
|
-
follow changes. See [Block location and appearance](
|
|
104
|
+
follow changes. See [Block location and appearance](docs/block-location.md) for details.
|
|
111
105
|
|
|
112
106
|
## Reference
|
|
113
107
|
|
|
114
108
|
Each page covers one API category. Import framework-neutral APIs from `@notionhq/custom-blocks`.
|
|
115
109
|
Import React hooks and components from `@notionhq/custom-blocks/react`.
|
|
116
110
|
|
|
117
|
-
- [`docs/lifecycle.md`](
|
|
111
|
+
- [`docs/lifecycle.md`](docs/lifecycle.md) — `<NotionCustomBlock>`, `useCustomBlockInit`,
|
|
118
112
|
`initCustomBlock`, `NotInIframeError`. The handshake, the React wrapper, sizing.
|
|
119
|
-
- [`docs/block-location.md`](
|
|
113
|
+
- [`docs/block-location.md`](docs/block-location.md) — `useBlockId`, `useParent`, `usePage`,
|
|
120
114
|
`useTheme`, `useContrastMode`, `NotionTokenScope`, and `NotionTokenScopeProps`. Where the block
|
|
121
115
|
sits and how to read the host's appearance.
|
|
122
|
-
- [`docs/data-sources.md`](
|
|
116
|
+
- [`docs/data-sources.md`](docs/data-sources.md) — `dataSources.query / getPage / create`,
|
|
123
117
|
`customBlock.subscribeToDataSource`, `useDataSource`, `useManifest`, `customBlock.getManifest`,
|
|
124
118
|
the row, property, and date-value types, plus a worked example.
|
|
125
|
-
- [`docs/pages.md`](
|
|
119
|
+
- [`docs/pages.md`](docs/pages.md) — `pages.create / get / open` and page instance mutations,
|
|
126
120
|
parent variants (including the recommended `data_source_key`), property input shapes.
|
|
127
|
-
- [`docs/links.md`](
|
|
121
|
+
- [`docs/links.md`](docs/links.md) — `links.open`, URL validation, host-owned confirmation, and
|
|
128
122
|
external-navigation errors.
|
|
129
|
-
- [`docs/users.md`](
|
|
130
|
-
- [`docs/errors.md`](
|
|
123
|
+
- [`docs/users.md`](docs/users.md) — `users.list / get`, the `NotionUser` shape, paging.
|
|
124
|
+
- [`docs/errors.md`](docs/errors.md) — request results, error format, error codes, retries, and
|
|
131
125
|
initialization failures.
|
|
132
|
-
- [`docs/bridge-interceptors.md`](
|
|
126
|
+
- [`docs/bridge-interceptors.md`](docs/bridge-interceptors.md) — `registerMessageInterceptor` and
|
|
133
127
|
`MessageInterceptor` for controlled bridge responses.
|
|
134
|
-
- [`docs/deployment.md`](
|
|
128
|
+
- [`docs/deployment.md`](docs/deployment.md) — worker-backed deploys, localhost self-hosted
|
|
135
129
|
fallback, where the manifest comes from.
|
|
136
130
|
|
|
137
131
|
## Limitations
|
|
@@ -5,7 +5,6 @@ import type { BridgeMessagePayload } from "../protocol/messages/messagePayload.j
|
|
|
5
5
|
import type { UpdatePageResultMessage } from "../protocol/messages/updatePageResult.js";
|
|
6
6
|
import type { CreatePageArgs, CreatePageResult, DataSourceQueryOptions, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionPage, NotionUserId, OpenExternalUrlResult, OpenPageOptions, OpenPageResult, PageUpdatePayload } from "../types.js";
|
|
7
7
|
import { type CustomBlockHostState } from "./hostState.js";
|
|
8
|
-
import type { ManifestLoadResult } from "./loadManifest.js";
|
|
9
8
|
import type { MessageInterceptor } from "./messageInterceptor.js";
|
|
10
9
|
/**
|
|
11
10
|
* A single entry in the bridge message log. Kept intentionally plain so the log is copy-pasteable
|
|
@@ -57,7 +56,6 @@ export declare class SandboxBridge {
|
|
|
57
56
|
getMessageLog(): readonly MessageLogEntry[];
|
|
58
57
|
subscribeToMessageLog(listener: () => void): () => boolean;
|
|
59
58
|
registerMessageInterceptor(interceptor: MessageInterceptor): () => void;
|
|
60
|
-
sendConnect(manifestResult: ManifestLoadResult): void;
|
|
61
59
|
private postToHost;
|
|
62
60
|
private sendToHost;
|
|
63
61
|
private notify;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EAEhB,MAAM,4DAA4D,CAAA;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAiB3E,OAAO,EACN,KAAK,WAAW,EAEhB,MAAM,mDAAmD,CAAA;AAI1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AASvG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAG5G,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,iBAAiB,EAEjB,MAAM,aAAa,CAAA;AASpB,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EAEhB,MAAM,4DAA4D,CAAA;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAiB3E,OAAO,EACN,KAAK,WAAW,EAEhB,MAAM,mDAAmD,CAAA;AAI1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AASvG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+DAA+D,CAAA;AAG5G,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,UAAU,EACV,YAAY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,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAA;QAC5C,IAAI,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAA;QAChC,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAClC,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;QAC9C,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;KACxC,GAAG,OAAO,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,CAAC,CAiEzD;IAED;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CA2D/B"}
|
|
@@ -10,7 +10,7 @@ import { resolveDataSources } from "./dataSources/resolve.js";
|
|
|
10
10
|
import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js";
|
|
11
11
|
import { createEmptyDataSourceQueryState, } from "./hostState.js";
|
|
12
12
|
import { notifyListener } from "./notifyListener.js";
|
|
13
|
-
import {
|
|
13
|
+
import { makeUpdatePageByKey, toNotionPageFromBridgePage } from "./page.js";
|
|
14
14
|
import { PendingRequests } from "./pendingRequests.js";
|
|
15
15
|
import { SandboxInitialization } from "./SandboxInitialization.js";
|
|
16
16
|
export class SandboxBridge {
|
|
@@ -94,9 +94,6 @@ export class SandboxBridge {
|
|
|
94
94
|
this.messageInterceptors.add(interceptor);
|
|
95
95
|
return () => this.messageInterceptors.delete(interceptor);
|
|
96
96
|
}
|
|
97
|
-
sendConnect(manifestResult) {
|
|
98
|
-
this.initialization.sendConnect(manifestResult);
|
|
99
|
-
}
|
|
100
97
|
postToHost(message) {
|
|
101
98
|
this.initialization.post(message);
|
|
102
99
|
}
|
|
@@ -570,7 +567,6 @@ export class SandboxBridge {
|
|
|
570
567
|
const resolvedProperties = resolvePropertyWriteMapForDataSource({
|
|
571
568
|
dataSource: propertyDataSource,
|
|
572
569
|
properties: args.properties,
|
|
573
|
-
operationName: "createPage",
|
|
574
570
|
});
|
|
575
571
|
if (resolvedProperties.status === "error") {
|
|
576
572
|
resolve(resolvedProperties);
|
|
@@ -589,13 +585,16 @@ export class SandboxBridge {
|
|
|
589
585
|
Object.assign(page, result.page);
|
|
590
586
|
return { status: "success", page };
|
|
591
587
|
};
|
|
592
|
-
const page =
|
|
593
|
-
|
|
588
|
+
const page = toNotionPageFromBridgePage({
|
|
589
|
+
bridgePage: result.page,
|
|
594
590
|
dataSourceKey,
|
|
595
591
|
getPropertyById: propertyId => this.getPropertyById({ page, propertyId }),
|
|
596
592
|
getPropertyByKey: propertyKey => this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
597
593
|
updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
598
|
-
updateByKey:
|
|
594
|
+
updateByKey: makeUpdatePageByKey({
|
|
595
|
+
dataSource,
|
|
596
|
+
update: payload => update({ ...payload, pageId: page.id, dataSource }),
|
|
597
|
+
}),
|
|
599
598
|
});
|
|
600
599
|
resolve({ status: "success", page });
|
|
601
600
|
});
|
|
@@ -629,13 +628,16 @@ export class SandboxBridge {
|
|
|
629
628
|
Object.assign(page, result.page);
|
|
630
629
|
return { status: "success", page };
|
|
631
630
|
};
|
|
632
|
-
const page =
|
|
633
|
-
|
|
631
|
+
const page = toNotionPageFromBridgePage({
|
|
632
|
+
bridgePage: result.page,
|
|
634
633
|
dataSourceKey,
|
|
635
634
|
getPropertyById: propertyId => this.getPropertyById({ page, propertyId }),
|
|
636
635
|
getPropertyByKey: propertyKey => this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
637
636
|
updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
638
|
-
updateByKey:
|
|
637
|
+
updateByKey: makeUpdatePageByKey({
|
|
638
|
+
dataSource,
|
|
639
|
+
update: payload => update({ ...payload, pageId: page.id, dataSource }),
|
|
640
|
+
}),
|
|
639
641
|
});
|
|
640
642
|
resolve({ status: "success", page });
|
|
641
643
|
});
|
|
@@ -719,30 +721,9 @@ export class SandboxBridge {
|
|
|
719
721
|
const operation = async () => {
|
|
720
722
|
const { dataSource } = args;
|
|
721
723
|
const dataSourceId = dataSource?.collectionPointer?.id;
|
|
722
|
-
const propertyIdsByKey = dataSource?.propertyIdsByKey ?? {};
|
|
723
|
-
if (dataSource !== undefined) {
|
|
724
|
-
for (const propertyKey of Object.keys(args.properties ?? {})) {
|
|
725
|
-
const propertyId = Object.hasOwn(propertyIdsByKey, propertyKey)
|
|
726
|
-
? propertyIdsByKey[propertyKey]
|
|
727
|
-
: undefined;
|
|
728
|
-
if (propertyId &&
|
|
729
|
-
dataSource?.collectionSchema?.propertiesById[propertyId]) {
|
|
730
|
-
continue;
|
|
731
|
-
}
|
|
732
|
-
return {
|
|
733
|
-
status: "error",
|
|
734
|
-
error: {
|
|
735
|
-
code: "unmapped_property",
|
|
736
|
-
message: `Cannot resolve property key "${propertyKey}" on this page.`,
|
|
737
|
-
isRetryable: false,
|
|
738
|
-
},
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
724
|
const resolved = resolvePropertyWriteMapForDataSource({
|
|
743
725
|
dataSource,
|
|
744
|
-
properties: args.properties
|
|
745
|
-
operationName: "page.update",
|
|
726
|
+
properties: args.properties === undefined ? {} : args.properties,
|
|
746
727
|
});
|
|
747
728
|
if (resolved.status === "error") {
|
|
748
729
|
return resolved;
|
|
@@ -802,12 +783,8 @@ export class SandboxBridge {
|
|
|
802
783
|
switch (parent.type) {
|
|
803
784
|
case "page_id":
|
|
804
785
|
return { status: "ok", parent, dataSource: undefined };
|
|
805
|
-
case "data_source_id":
|
|
806
|
-
|
|
807
|
-
? this.hostState.dataSources.find(entry => entry.collectionPointer?.id === parent.data_source_id)
|
|
808
|
-
: undefined;
|
|
809
|
-
return { status: "ok", parent, dataSource };
|
|
810
|
-
}
|
|
786
|
+
case "data_source_id":
|
|
787
|
+
return { status: "ok", parent, dataSource: undefined };
|
|
811
788
|
case "data_source_key": {
|
|
812
789
|
if (this.hostState.status !== "initialized") {
|
|
813
790
|
return {
|
|
@@ -3,7 +3,6 @@ import type { CustomBlockInitResultErrorInfo } from "../protocol/messages/initRe
|
|
|
3
3
|
import type { SandboxToHostMessage } from "../protocol/messages/sandboxToHost.js";
|
|
4
4
|
import { type CustomBlockInitPayload } from "../initTypes.js";
|
|
5
5
|
import type { CustomBlockHostState } from "./hostState.js";
|
|
6
|
-
import { type ManifestLoadResult } from "./loadManifest.js";
|
|
7
6
|
/** Bridge callbacks used by the initialization controller. */
|
|
8
7
|
export type InitializationOptions = {
|
|
9
8
|
/** Starts listening for host messages on the first call to initialize, before connect is sent. */
|
|
@@ -36,8 +35,7 @@ export declare class SandboxInitialization {
|
|
|
36
35
|
constructor(options: InitializationOptions);
|
|
37
36
|
initialize(): Promise<CustomBlockInitPayload>;
|
|
38
37
|
private run;
|
|
39
|
-
private
|
|
40
|
-
sendConnect(result: ManifestLoadResult): void;
|
|
38
|
+
private sendConnect;
|
|
41
39
|
handleInit(message: InitMessage): void;
|
|
42
40
|
handleInvalidInit(id: string | undefined, error: CustomBlockInitResultErrorInfo): boolean;
|
|
43
41
|
post(message: SandboxToHostMessage): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SandboxInitialization.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxInitialization.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,WAAW,EAChB,MAAM,mDAAmD,CAAA;AAC1D,OAAO,KAAK,EACX,8BAA8B,EAE9B,MAAM,yDAAyD,CAAA;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4DAA4D,CAAA;AAEtG,OAAO,EAAE,KAAK,sBAAsB,EAAoB,MAAM,iBAAiB,CAAA;AAE/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"SandboxInitialization.d.ts","sourceRoot":"","sources":["../../src/bridge/SandboxInitialization.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,WAAW,EAChB,MAAM,mDAAmD,C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AAE,EAAE,MAAM,GAAG,SAAS,EACtB,KAAK,EAAE,8BAA8B,GACnC,OAAO,CAMT;IAED,IAAI,CAAC,OAAO,EAAE,oBAAoB,QASjC;IAED,QAAQ,SAkBP;IAED,UAAU,SAIT;IAED,OAAO,SAWN;IAED,OAAO,CAAC,IAAI;IAcZ,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,oBAAoB;CAW5B"}
|
|
@@ -2,7 +2,7 @@ import { CustomBlockInitializationError, } from "../protocol/messages/init.js";
|
|
|
2
2
|
import { LATEST_BRIDGE_PROTOCOL_VERSION } from "../protocol/protocolVersion.js";
|
|
3
3
|
import { NotInIframeError } from "../initTypes.js";
|
|
4
4
|
import { CUSTOM_BLOCKS_SDK_VERSION } from "../version.js";
|
|
5
|
-
import {
|
|
5
|
+
import { readLocalManifest } from "./readLocalManifest.js";
|
|
6
6
|
const INITIALIZATION_ID = "custom-block-initialization-1";
|
|
7
7
|
/** Owns one document's startup, acknowledgement, and messages queued during rendering. */
|
|
8
8
|
export class SandboxInitialization {
|
|
@@ -32,10 +32,11 @@ export class SandboxInitialization {
|
|
|
32
32
|
}
|
|
33
33
|
async run() {
|
|
34
34
|
try {
|
|
35
|
-
if (typeof window
|
|
35
|
+
if (typeof window === "undefined" || window.parent === window) {
|
|
36
36
|
throw new NotInIframeError();
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
this.sendConnect();
|
|
39
|
+
await this.initialized;
|
|
39
40
|
const state = this.options.getState();
|
|
40
41
|
if (state.status !== "initialized") {
|
|
41
42
|
throw new CustomBlockInitializationError({
|
|
@@ -65,20 +66,15 @@ export class SandboxInitialization {
|
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
-
const manifest = await attemptToLoadSelfHostedManifest();
|
|
70
|
-
if (this.phase !== "disposed") {
|
|
71
|
-
this.sendConnect(manifest);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
sendConnect(result) {
|
|
75
|
-
if (typeof window === "undefined") {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
69
|
+
sendConnect() {
|
|
78
70
|
if (this.phase !== "idle" && this.phase !== "preview") {
|
|
79
71
|
console.warn("[custom-blocks-sdk] ignoring duplicate connect message");
|
|
80
72
|
return;
|
|
81
73
|
}
|
|
74
|
+
const result = readLocalManifest({
|
|
75
|
+
document: window.document,
|
|
76
|
+
url: new URL(window.location.href),
|
|
77
|
+
});
|
|
82
78
|
this.phase = "waiting";
|
|
83
79
|
const identity = {
|
|
84
80
|
type: "connect",
|
|
@@ -86,12 +82,14 @@ export class SandboxInitialization {
|
|
|
86
82
|
bridgeProtocolVersion: LATEST_BRIDGE_PROTOCOL_VERSION,
|
|
87
83
|
sdkVersion: CUSTOM_BLOCKS_SDK_VERSION,
|
|
88
84
|
};
|
|
89
|
-
const message = result.
|
|
85
|
+
const message = result.status === "error"
|
|
90
86
|
? { ...identity, status: "error", error: result.error }
|
|
91
87
|
: {
|
|
92
88
|
...identity,
|
|
93
89
|
status: "success",
|
|
94
|
-
...(result.manifest !==
|
|
90
|
+
...(result.manifest !== undefined
|
|
91
|
+
? { manifest: result.manifest }
|
|
92
|
+
: {}),
|
|
95
93
|
};
|
|
96
94
|
this.options.post(message);
|
|
97
95
|
}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Background
|
|
3
|
-
*
|
|
4
|
-
* The light value matches NDS's semantic `--bg-base` token in light mode
|
|
5
|
-
* (`--gray-0`, white). The dark value is the existing SDK fallback canvas
|
|
6
|
-
* color; it is not an exact current generated NDS value. Current NDS maps
|
|
7
|
-
* dark `--bg-base` to `--gray-145` (approximately `#1b1b1b`), while the
|
|
8
|
-
* legacy notion-next gray surface is `rgba(32, 32, 32, 1)`.
|
|
9
|
-
*
|
|
10
|
-
* Keep the resolved values here because the document must be styled before the block's NDS
|
|
11
|
-
* stylesheet and token scope are guaranteed to be available.
|
|
2
|
+
* Background colors applied before the block's NDS stylesheet and token scope
|
|
3
|
+
* are available, preventing an initial theme flash.
|
|
12
4
|
*/
|
|
13
5
|
export declare const NOTION_DARK_BACKGROUND_BASE = "#191918";
|
|
14
6
|
export declare const NOTION_LIGHT_BACKGROUND_BASE = "#ffffff";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appearance.d.ts","sourceRoot":"","sources":["../../src/bridge/appearance.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"appearance.d.ts","sourceRoot":"","sources":["../../src/bridge/appearance.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,2BAA2B,YAAY,CAAA;AACpD,eAAO,MAAM,4BAA4B,YAAY,CAAA"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Background
|
|
3
|
-
*
|
|
4
|
-
* The light value matches NDS's semantic `--bg-base` token in light mode
|
|
5
|
-
* (`--gray-0`, white). The dark value is the existing SDK fallback canvas
|
|
6
|
-
* color; it is not an exact current generated NDS value. Current NDS maps
|
|
7
|
-
* dark `--bg-base` to `--gray-145` (approximately `#1b1b1b`), while the
|
|
8
|
-
* legacy notion-next gray surface is `rgba(32, 32, 32, 1)`.
|
|
9
|
-
*
|
|
10
|
-
* Keep the resolved values here because the document must be styled before the block's NDS
|
|
11
|
-
* stylesheet and token scope are guaranteed to be available.
|
|
2
|
+
* Background colors applied before the block's NDS stylesheet and token scope
|
|
3
|
+
* are available, preventing an initial theme flash.
|
|
12
4
|
*/
|
|
13
5
|
export const NOTION_DARK_BACKGROUND_BASE = "#191918";
|
|
14
6
|
export const NOTION_LIGHT_BACKGROUND_BASE = "#ffffff";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NotionDataSource } from "../../protocol/dataSources/dataSource.js";
|
|
2
2
|
import type { NotionDataSourceId } from "../../protocol/ids.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ResolvedCustomBlockDataSourceFilter, ResolvedCustomBlockDataSourceSort } from "../../protocol/messages/queryDataSource.js";
|
|
4
4
|
import type { CustomBlockQueryDataSourceErrorInfo } from "../../protocol/messages/queryDataSourceResult.js";
|
|
5
5
|
import type { UseDataSourceOptions } from "../../types.js";
|
|
6
6
|
export type ResolvedDataSourceQuery = {
|
|
@@ -22,7 +22,6 @@ export declare function resolveDataSourceQuery(args: {
|
|
|
22
22
|
dataSources: NotionDataSource[];
|
|
23
23
|
key: string;
|
|
24
24
|
options?: unknown;
|
|
25
|
-
warn?: (message: string) => void;
|
|
26
25
|
}): ResolveDataSourceQueryResult;
|
|
27
26
|
export declare function getDataSourceQueryOptionsIdentity(options: UseDataSourceOptions | undefined): string;
|
|
28
27
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,KAAK,EACX,mCAAmC,EACnC,iCAAiC,EACjC,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAM1D,MAAM,MAAM,uBAAuB,GAAG;IACrC,YAAY,EAAE,kBAAkB,CAAA;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,mCAAmC,CAAA;IAC5C,KAAK,CAAC,EAAE,iCAAiC,EAAE,CAAA;IAC3C,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,4BAA4B,GACrC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,mCAAmC,CAAA;CAAE,GAC/D;IACA,MAAM,EAAE,IAAI,CAAA;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,KAAK,EAAE,uBAAuB,CAAA;CAC7B,CAAA;AAQJ,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC5C,WAAW,EAAE,gBAAgB,EAAE,CAAA;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB,GAAG,4BAA4B,CAuF/B;AA4ED,wBAAgB,iCAAiC,CAChD,OAAO,EAAE,oBAAoB,GAAG,SAAS,GACvC,MAAM,CAMR"}
|