@notionhq/custom-blocks 0.3.3 → 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 +11 -11
- package/dist/bridge/SandboxBridge.d.ts +0 -2
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +5 -8
- 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/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 +3 -3
- package/dist/bridge/page.d.ts.map +1 -1
- package/dist/bridge/page.js +2 -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 -27
- 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 +2 -2
- package/dist/protocol/protocolVersion.js +2 -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 +5 -2
- package/docs/data-sources.md +21 -17
- package/docs/deployment.md +16 -11
- package/docs/errors.md +11 -1
- package/docs/lifecycle.md +10 -3
- package/docs/pages.md +7 -3
- package/docs/users.md +4 -4
- package/package.json +3 -2
- package/src/bridge/SandboxBridge.ts +5 -10
- 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/resolvePropertyAddress.ts +62 -0
- package/src/bridge/dataSources/resolveSorts.ts +107 -0
- package/src/bridge/hostState.ts +3 -43
- package/src/bridge/page.ts +4 -4
- package/src/bridge/readLocalManifest.ts +60 -0
- package/src/bridge/sandboxClient.ts +63 -41
- 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/docs/data-sources.md
CHANGED
|
@@ -10,8 +10,8 @@ Each snapshot contains `items`, `propertyIdsByKey`, `isLoading`, and `hasMore`.
|
|
|
10
10
|
replaces the previous rows in the snapshot. Subscriptions remain independent, even when they query
|
|
11
11
|
the same data source.
|
|
12
12
|
|
|
13
|
-
Queries default to 20 rows
|
|
14
|
-
pagination, filter, and sort restrictions.
|
|
13
|
+
Queries default to 20 rows. The host enforces the maximum row limit. See
|
|
14
|
+
[Known limitations](#known-limitations) for pagination, filter, and sort restrictions.
|
|
15
15
|
|
|
16
16
|
## Bind a data source
|
|
17
17
|
|
|
@@ -161,9 +161,10 @@ time** column. Use the column's bound key or actual property ID.
|
|
|
161
161
|
|
|
162
162
|
### Row limits
|
|
163
163
|
|
|
164
|
-
`limit` defaults to 20 and must be a positive integer. The SDK
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
`limit` defaults to 20 and must be a positive safe integer. The SDK forwards the requested limit
|
|
165
|
+
without capping it. The Notion host currently supports up to 1,000 rows and rejects larger requests
|
|
166
|
+
with an error that states the maximum. Each query reads from the start of the matching rows. A
|
|
167
|
+
larger limit replaces the previous snapshot with a larger result.
|
|
167
168
|
|
|
168
169
|
`hasMore` indicates that more matching rows exist beyond the result. It does not provide a cursor or
|
|
169
170
|
guarantee that increasing the limit can retrieve every row.
|
|
@@ -242,7 +243,7 @@ the filter type, not the column.
|
|
|
242
243
|
| `multi_select` | `contains`, `contains_all`, `does_not_contain`, `is_empty`, `is_not_empty` |
|
|
243
244
|
| `date` | `equals`, `before`, `after`, `on_or_before`, `on_or_after`, relative ranges, `is_empty`, `is_not_empty` |
|
|
244
245
|
| `people` | `contains`, `does_not_contain`, `is_empty`, `is_not_empty` |
|
|
245
|
-
| `relation` | `contains`, `does_not_contain`
|
|
246
|
+
| `relation` | `contains`, `does_not_contain`, `is_empty`, `is_not_empty` |
|
|
246
247
|
| `created_by` | `contains`, `does_not_contain`, `is_empty`, `is_not_empty` |
|
|
247
248
|
|
|
248
249
|
- Select, multi-select, and status filters accept one option name or an array of option names.
|
|
@@ -257,9 +258,9 @@ the filter type, not the column.
|
|
|
257
258
|
- Creator filters accept one explicit human user reference. Groups, bots, and organization bots are
|
|
258
259
|
not supported as filter references. `does_not_contain` also matches rows with non-human or missing
|
|
259
260
|
creators. Empty checks test whether creator metadata is missing.
|
|
260
|
-
- Relation filters accept one page ID in dashed or undashed UUID format.
|
|
261
|
-
- Relation `does_not_contain`
|
|
262
|
-
unsupported.
|
|
261
|
+
- Relation membership filters accept one page ID in dashed or undashed UUID format.
|
|
262
|
+
- Relation `does_not_contain` returns rows that do not reference the specified page. Rows with no
|
|
263
|
+
related pages also match. Multiple targets are unsupported.
|
|
263
264
|
|
|
264
265
|
```ts
|
|
265
266
|
filter: {
|
|
@@ -427,7 +428,7 @@ function customBlock.getManifest(): CustomBlockManifest;
|
|
|
427
428
|
|
|
428
429
|
Framework-neutral getter for the same manifest returned by `useManifest()`.
|
|
429
430
|
`customBlock.subscribeToManifest(callback)` follows the
|
|
430
|
-
[context subscription contract](
|
|
431
|
+
[context subscription contract](block-location.md#reading-values-and-following-changes). The
|
|
431
432
|
manifest stays fixed for the lifetime of the running block, so each subscription delivers it once.
|
|
432
433
|
You can register before initialization without an error.
|
|
433
434
|
|
|
@@ -475,10 +476,10 @@ export function ScoreList() {
|
|
|
475
476
|
)
|
|
476
477
|
})}
|
|
477
478
|
</ul>
|
|
478
|
-
{hasMore && limit <
|
|
479
|
+
{hasMore && limit < 1000 ? (
|
|
479
480
|
<button
|
|
480
481
|
type="button"
|
|
481
|
-
onClick={() => setLimit(Math.min(limit + 20,
|
|
482
|
+
onClick={() => setLimit(Math.min(limit + 20, 1000))}
|
|
482
483
|
disabled={isLoading}
|
|
483
484
|
>
|
|
484
485
|
{isLoading ? "Loading…" : "Load more"}
|
|
@@ -491,9 +492,12 @@ export function ScoreList() {
|
|
|
491
492
|
|
|
492
493
|
## Known limitations
|
|
493
494
|
|
|
494
|
-
- **Row limits and pagination:**
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
- **Row limits and pagination:** Hosts enforce their own limits. The Notion app supports up to 32
|
|
496
|
+
active subscriptions per custom block, each with up to 1,000 rows. Requests that exceed either
|
|
497
|
+
limit return an error. Queries have no cursor or offset. Increasing `limit` replaces the snapshot
|
|
498
|
+
with a larger result from the start of the matching rows. If `hasMore` is true, increase `limit`
|
|
499
|
+
up to 1,000 or use filters to query smaller subsets. Unsubscribe from queries you no longer need
|
|
500
|
+
to free subscription slots.
|
|
497
501
|
- **Filter and sort rules:** Use one property condition or one `and` group with up to 25 conditions.
|
|
498
502
|
Nested groups and `or` are unsupported. You can sort by up to 10 unique properties. Empty values
|
|
499
503
|
sort last in both directions. See the table below for property support and [Filters](#filters) for
|
|
@@ -536,7 +540,7 @@ refer to the core values inside each property object. For example, “Number”
|
|
|
536
540
|
| `people` | 🟢 User or group references | 🟢 Supported | 🟢 Supported | 🟢 Native name ordering |
|
|
537
541
|
| `files` | 🟡 External files only | 🟡 File URLs only | 🔴 Unavailable | 🔴 Unavailable |
|
|
538
542
|
| `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
539
|
-
| `relation` | 🟢 Page reference array | 🟡 Replaces value. Rejects `has_more: true`. | 🟢 Supported | 🔴 Unavailable
|
|
543
|
+
| `relation` | 🟢 Page reference array | 🟡 Replaces value. Rejects `has_more: true`. | 🟢 Supported | 🔴 Unavailable |
|
|
540
544
|
| `place` | 🟢 Place object | 🟢 Supported | 🔴 Unavailable | 🔴 Unavailable |
|
|
541
545
|
| `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
542
546
|
| `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable for numeric targets or numeric aggregations. ⚫ Notion cannot sort other rollups. |
|
|
@@ -605,7 +609,7 @@ Other write restrictions:
|
|
|
605
609
|
- **Relations:** Supply the complete replacement list of related pages. The host rejects
|
|
606
610
|
`has_more: true`, which indicates an incomplete list.
|
|
607
611
|
|
|
608
|
-
See [Pages property support](
|
|
612
|
+
See [Pages property support](pages.md#property-support) for the page-property read shapes.
|
|
609
613
|
|
|
610
614
|
## Types
|
|
611
615
|
|
package/docs/deployment.md
CHANGED
|
@@ -11,25 +11,30 @@ manifest's single source of truth:
|
|
|
11
11
|
|
|
12
12
|
- **Deployed** — deploying persists the manifest on the block's definition record in Notion. The
|
|
13
13
|
host reads it from there and sends it to the SDK during initialization.
|
|
14
|
-
- **Local development** —
|
|
15
|
-
|
|
14
|
+
- **Local development** — dev tooling extracts the same worker declaration and injects it into the
|
|
15
|
+
block HTML as a JSON script with ID `notion-custom-block-manifest` and type `application/json`.
|
|
16
|
+
The SDK reads the manifest from this metadata and sends it in `connect`.
|
|
16
17
|
|
|
17
18
|
Notion reconciles custom block definitions by their Worker capability keys during deployment.
|
|
18
19
|
|
|
20
|
+
## Browser and server dependencies
|
|
21
|
+
|
|
22
|
+
Put packages used only by the custom block frontend, such as React and the custom blocks SDK, in
|
|
23
|
+
`devDependencies` in the Worker's root `package.json`. The frontend build includes their code in the
|
|
24
|
+
browser assets, so their package files do not need to ship with the Worker.
|
|
25
|
+
|
|
26
|
+
Keep packages that the Worker's server code imports in `dependencies`.
|
|
27
|
+
|
|
19
28
|
## Local development
|
|
20
29
|
|
|
21
30
|
Run `ntn workers customblocks dev` from your worker project. The dev shell builds the worker and
|
|
22
31
|
reads its custom block declarations. It serves the shell and blocks on one port, with a separate
|
|
23
32
|
localhost subdomain for each block. Open the shell URL printed by the command. The default port is
|
|
24
|
-
`9873`; the launcher selects another port when needed.
|
|
25
|
-
|
|
26
|
-
The dev shell supplies the worker's manifest to the host. When Notion previews a local block
|
|
27
|
-
directly, its host fetches `/manifest` from the block server. In both cases, the host sends the
|
|
28
|
-
manifest to the SDK during initialization.
|
|
33
|
+
`9873`; the launcher selects another port when needed. Vite provides source transforms and hot
|
|
34
|
+
reload.
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
manifest; blocks do not need to fetch or send one themselves.
|
|
36
|
+
Worker declarations are read when the dev shell starts. Restart it after changing a declaration to
|
|
37
|
+
regenerate the injected metadata, then reload the block. Block source files hot reload.
|
|
33
38
|
|
|
34
39
|
## Types
|
|
35
40
|
|
|
@@ -38,4 +43,4 @@ manifest; blocks do not need to fetch or send one themselves.
|
|
|
38
43
|
- `ManifestProperty` — a single property declaration inside a `ManifestDataSource`.
|
|
39
44
|
- `ManifestIcon` — the icon variant accepted on a `ManifestDataSource`.
|
|
40
45
|
|
|
41
|
-
For the Node.js build and upload API, see the [build-tool reference](
|
|
46
|
+
For the Node.js build and upload API, see the [build-tool reference](build-tools.md).
|
package/docs/errors.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Error handling
|
|
2
2
|
|
|
3
|
+
SDK operations report failures through result objects, initialization failures, or subscription
|
|
4
|
+
state. This reference describes each error surface, the error payload, and known codes so your block
|
|
5
|
+
can display failures and decide when to retry.
|
|
6
|
+
|
|
3
7
|
Pages, Users, navigation, and asynchronous Data sources methods return a result with a `status`
|
|
4
8
|
field. Success returns `{ status: "success", ... }` with the requested data. Failure returns
|
|
5
9
|
`{ status: "error", error }`. Initialization rejects on failure. Hooks and subscriptions report
|
|
@@ -58,6 +62,12 @@ The SDK validates all properties before sending an update. These local errors ha
|
|
|
58
62
|
|
|
59
63
|
## Data source errors
|
|
60
64
|
|
|
65
|
+
- `data_source_access_failed`: A page create or update operation cannot use its data source because
|
|
66
|
+
the data source is unavailable, lacks workspace information, or does not allow the operation.
|
|
67
|
+
|
|
68
|
+
- `data_source_query_invalid_limit`: The row limit is not a positive safe integer or exceeds the
|
|
69
|
+
host maximum. The error message states the maximum when the host rejects an oversized request.
|
|
70
|
+
|
|
61
71
|
- `data_source_schema_unavailable`: A query uses filters or sorts, but the host did not provide the
|
|
62
72
|
database schema. Both the SDK and the generic host use this code. Queries without filters or sorts
|
|
63
73
|
can run without a schema.
|
|
@@ -95,7 +105,7 @@ The error code identifies which side failed:
|
|
|
95
105
|
- `initial_state_timeout`: The host could not prepare the initial state before its timeout.
|
|
96
106
|
- `no_init_result`: The host did not receive a valid `initResult` before its timeout.
|
|
97
107
|
|
|
98
|
-
See [Lifecycle and initialization](
|
|
108
|
+
See [Lifecycle and initialization](lifecycle.md) for initialization-specific error codes.
|
|
99
109
|
|
|
100
110
|
## Handling errors
|
|
101
111
|
|
package/docs/lifecycle.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Lifecycle
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A custom block needs context from its host before it can render content that uses Notion data. This
|
|
4
|
+
guide covers initialization, loading and error states, and iframe sizing for React and
|
|
5
|
+
framework-neutral blocks. The SDK and host initialize the block through a three-message
|
|
6
|
+
`postMessage` handshake.
|
|
4
7
|
|
|
5
8
|
This handshake can be completed with one of these APIs:
|
|
6
9
|
|
|
@@ -133,9 +136,13 @@ The `CustomBlockInitializationErrorCode` tells you where initialization failed:
|
|
|
133
136
|
- The SDK could not apply the host's state.
|
|
134
137
|
- The SDK failed before the handshake completed, such as `not_in_iframe`.
|
|
135
138
|
|
|
139
|
+
`manifest_unavailable` means the sandbox omitted its declaration or the host reported an unavailable
|
|
140
|
+
manifest. `manifest_invalid` reports a manifest validation failure. Hosts can also return errors
|
|
141
|
+
from their definition-loading code; the shared host forwards those errors unchanged.
|
|
142
|
+
|
|
136
143
|
All code types are open string unions, so keep a default branch. Use `isRetryable` to decide whether
|
|
137
144
|
offering a retry makes sense, and treat `message` as display text rather than a stable identifier.
|
|
138
|
-
See [Error handling](
|
|
145
|
+
See [Error handling](errors.md) for the shared error contract.
|
|
139
146
|
|
|
140
147
|
### `customBlock`
|
|
141
148
|
|
|
@@ -196,7 +203,7 @@ function ThemeLabel() {
|
|
|
196
203
|
}
|
|
197
204
|
```
|
|
198
205
|
|
|
199
|
-
See [Block location and appearance](
|
|
206
|
+
See [Block location and appearance](block-location.md#reading-values-and-following-changes) for
|
|
200
207
|
the available getters, subscriptions, and React hooks.
|
|
201
208
|
|
|
202
209
|
### `NotInIframeError`
|
package/docs/pages.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Pages
|
|
2
2
|
|
|
3
|
+
The `pages` API reads, creates, updates, and opens Notion pages from a custom block. This guide
|
|
4
|
+
covers page results, property access, mutations, and navigation. Data source operations return the
|
|
5
|
+
same page objects, so these property methods also apply to query rows.
|
|
6
|
+
|
|
3
7
|
`pages.get` and `pages.create` return `{ status: "success", page }` or `{ status: "error", error }`.
|
|
4
8
|
Both the Pages and Data sources namespaces return the same `NotionPage` type, with methods to read
|
|
5
9
|
and update properties.
|
|
@@ -14,7 +18,7 @@ if (result.status === "success") {
|
|
|
14
18
|
}
|
|
15
19
|
```
|
|
16
20
|
|
|
17
|
-
`
|
|
21
|
+
`BridgePage` contains the serializable page fields. `NotionPage` adds methods, which are not
|
|
18
22
|
serialized. Reads use loaded values. Writes send bridge messages to Notion.
|
|
19
23
|
|
|
20
24
|
## Page fields
|
|
@@ -100,7 +104,7 @@ do not require data source context.
|
|
|
100
104
|
|
|
101
105
|
The SDK validates all properties before sending an update. Invalid values, mismatched IDs, duplicate
|
|
102
106
|
targets, and unresolved keys return local errors. An update must include at least one property or
|
|
103
|
-
metadata change. See [Local page update errors](
|
|
107
|
+
metadata change. See [Local page update errors](errors.md#local-page-update-errors).
|
|
104
108
|
|
|
105
109
|
Icons use `NotionPageIcon` and covers use `NotionPageCover`. Supported values include emoji,
|
|
106
110
|
external URLs, and existing hosted file URLs. File upload references are unsupported.
|
|
@@ -180,7 +184,7 @@ matching property in its schema.
|
|
|
180
184
|
stored text as a string. Formulas and rollups are not evaluated. Missing values return `""`.
|
|
181
185
|
|
|
182
186
|
For query properties, filters, and sorts, see
|
|
183
|
-
[Data source property support](
|
|
187
|
+
[Data source property support](data-sources.md#property-support).
|
|
184
188
|
|
|
185
189
|
## Opening pages
|
|
186
190
|
|
package/docs/users.md
CHANGED
|
@@ -7,7 +7,7 @@ import { customBlock, initCustomBlock, users, type NotionUserId } from "@notionh
|
|
|
7
7
|
import { useCurrentUser } from "@notionhq/custom-blocks/react"
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
`users.get()` and `users.list()` follow the SDK's [error-handling contract](
|
|
10
|
+
`users.get()` and `users.list()` follow the SDK's [error-handling contract](errors.md). Check
|
|
11
11
|
`result.status` before reading `result.user` or `result.list`.
|
|
12
12
|
|
|
13
13
|
## Reading the current user
|
|
@@ -16,7 +16,7 @@ import { useCurrentUser } from "@notionhq/custom-blocks/react"
|
|
|
16
16
|
read the user from the block’s state without a separate request.
|
|
17
17
|
|
|
18
18
|
Wait for `initCustomBlock()` to resolve before calling the getter or mounting components that use
|
|
19
|
-
the hook. See [initialization](
|
|
19
|
+
the hook. See [initialization](lifecycle.md).
|
|
20
20
|
|
|
21
21
|
### TypeScript API
|
|
22
22
|
|
|
@@ -36,7 +36,7 @@ const unsubscribe = customBlock.subscribeToCurrentUser(nextUser => {
|
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Call `unsubscribe()` when you no longer need updates. The callback receives the initial profile and
|
|
39
|
-
later changes. See [context subscriptions](
|
|
39
|
+
later changes. See [context subscriptions](block-location.md#reading-values-and-following-changes)
|
|
40
40
|
for initialization and equality rules.
|
|
41
41
|
|
|
42
42
|
### React hook
|
|
@@ -154,7 +154,7 @@ A user returned by `users.list()` does not necessarily have access to the curren
|
|
|
154
154
|
source. Do not use this list to check page or data source permissions.
|
|
155
155
|
|
|
156
156
|
If a request returns `status: "error"`, handle the error before reading `result.user` or
|
|
157
|
-
`result.list`. See [error handling](
|
|
157
|
+
`result.list`. See [error handling](errors.md).
|
|
158
158
|
|
|
159
159
|
## Types
|
|
160
160
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/custom-blocks",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"src",
|
|
32
32
|
"bin",
|
|
33
33
|
"docs",
|
|
34
|
-
"dist"
|
|
34
|
+
"dist",
|
|
35
|
+
"LICENSE"
|
|
35
36
|
],
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"react": "^19.2.8"
|
|
@@ -69,10 +69,9 @@ import {
|
|
|
69
69
|
createEmptyDataSourceQueryState,
|
|
70
70
|
type DataSourceQueryState,
|
|
71
71
|
} from "./hostState.js"
|
|
72
|
-
import type { ManifestLoadResult } from "./loadManifest.js"
|
|
73
72
|
import type { MessageInterceptor } from "./messageInterceptor.js"
|
|
74
73
|
import { notifyListener } from "./notifyListener.js"
|
|
75
|
-
import { makeUpdatePageByKey,
|
|
74
|
+
import { makeUpdatePageByKey, toNotionPageFromBridgePage } from "./page.js"
|
|
76
75
|
import { PendingRequests } from "./pendingRequests.js"
|
|
77
76
|
import { SandboxInitialization } from "./SandboxInitialization.js"
|
|
78
77
|
|
|
@@ -196,10 +195,6 @@ export class SandboxBridge {
|
|
|
196
195
|
return () => this.messageInterceptors.delete(interceptor)
|
|
197
196
|
}
|
|
198
197
|
|
|
199
|
-
sendConnect(manifestResult: ManifestLoadResult) {
|
|
200
|
-
this.initialization.sendConnect(manifestResult)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
198
|
private postToHost(message: SandboxToHostMessage) {
|
|
204
199
|
this.initialization.post(message)
|
|
205
200
|
}
|
|
@@ -803,8 +798,8 @@ export class SandboxBridge {
|
|
|
803
798
|
Object.assign(page, result.page)
|
|
804
799
|
return { status: "success", page }
|
|
805
800
|
}
|
|
806
|
-
const page: NotionPage =
|
|
807
|
-
|
|
801
|
+
const page: NotionPage = toNotionPageFromBridgePage({
|
|
802
|
+
bridgePage: result.page,
|
|
808
803
|
dataSourceKey,
|
|
809
804
|
getPropertyById: propertyId =>
|
|
810
805
|
this.getPropertyById({ page, propertyId }),
|
|
@@ -856,8 +851,8 @@ export class SandboxBridge {
|
|
|
856
851
|
Object.assign(page, result.page)
|
|
857
852
|
return { status: "success", page }
|
|
858
853
|
}
|
|
859
|
-
const page: NotionPage =
|
|
860
|
-
|
|
854
|
+
const page: NotionPage = toNotionPageFromBridgePage({
|
|
855
|
+
bridgePage: result.page,
|
|
861
856
|
dataSourceKey,
|
|
862
857
|
getPropertyById: propertyId =>
|
|
863
858
|
this.getPropertyById({ page, propertyId }),
|
|
@@ -12,16 +12,13 @@ import { LATEST_BRIDGE_PROTOCOL_VERSION } from "@notionhq/custom-blocks-protocol
|
|
|
12
12
|
import { type CustomBlockInitPayload, NotInIframeError } from "../initTypes.js"
|
|
13
13
|
import { CUSTOM_BLOCKS_SDK_VERSION } from "../version.js"
|
|
14
14
|
import type { CustomBlockHostState } from "./hostState.js"
|
|
15
|
-
import {
|
|
16
|
-
attemptToLoadSelfHostedManifest,
|
|
17
|
-
type ManifestLoadResult,
|
|
18
|
-
} from "./loadManifest.js"
|
|
15
|
+
import { readLocalManifest } from "./readLocalManifest.js"
|
|
19
16
|
|
|
20
17
|
const INITIALIZATION_ID = "custom-block-initialization-1"
|
|
21
18
|
|
|
22
19
|
/** Tracks the startup handshake and when outbound messages can be sent. */
|
|
23
20
|
type SandboxInitializationPhase =
|
|
24
|
-
/** No connect message has been sent.
|
|
21
|
+
/** No connect message has been sent. */
|
|
25
22
|
| "idle"
|
|
26
23
|
/** Standalone preview state is available without a host handshake. */
|
|
27
24
|
| "preview"
|
|
@@ -86,10 +83,11 @@ export class SandboxInitialization {
|
|
|
86
83
|
|
|
87
84
|
private async run(): Promise<CustomBlockInitPayload> {
|
|
88
85
|
try {
|
|
89
|
-
if (typeof window
|
|
86
|
+
if (typeof window === "undefined" || window.parent === window) {
|
|
90
87
|
throw new NotInIframeError()
|
|
91
88
|
}
|
|
92
|
-
|
|
89
|
+
this.sendConnect()
|
|
90
|
+
await this.initialized
|
|
93
91
|
const state = this.options.getState()
|
|
94
92
|
if (state.status !== "initialized") {
|
|
95
93
|
throw new CustomBlockInitializationError({
|
|
@@ -119,21 +117,15 @@ export class SandboxInitialization {
|
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
119
|
|
|
122
|
-
private
|
|
123
|
-
const manifest = await attemptToLoadSelfHostedManifest()
|
|
124
|
-
if (this.phase !== "disposed") {
|
|
125
|
-
this.sendConnect(manifest)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
sendConnect(result: ManifestLoadResult) {
|
|
130
|
-
if (typeof window === "undefined") {
|
|
131
|
-
return
|
|
132
|
-
}
|
|
120
|
+
private sendConnect() {
|
|
133
121
|
if (this.phase !== "idle" && this.phase !== "preview") {
|
|
134
122
|
console.warn("[custom-blocks-sdk] ignoring duplicate connect message")
|
|
135
123
|
return
|
|
136
124
|
}
|
|
125
|
+
const result = readLocalManifest({
|
|
126
|
+
document: window.document,
|
|
127
|
+
url: new URL(window.location.href),
|
|
128
|
+
})
|
|
137
129
|
this.phase = "waiting"
|
|
138
130
|
const identity = {
|
|
139
131
|
type: "connect" as const,
|
|
@@ -142,12 +134,14 @@ export class SandboxInitialization {
|
|
|
142
134
|
sdkVersion: CUSTOM_BLOCKS_SDK_VERSION,
|
|
143
135
|
}
|
|
144
136
|
const message: ConnectMessage =
|
|
145
|
-
result.
|
|
137
|
+
result.status === "error"
|
|
146
138
|
? { ...identity, status: "error", error: result.error }
|
|
147
139
|
: {
|
|
148
140
|
...identity,
|
|
149
141
|
status: "success",
|
|
150
|
-
...(result.manifest !==
|
|
142
|
+
...(result.manifest !== undefined
|
|
143
|
+
? { manifest: result.manifest }
|
|
144
|
+
: {}),
|
|
151
145
|
}
|
|
152
146
|
this.options.post(message)
|
|
153
147
|
}
|
package/src/bridge/appearance.ts
CHANGED
|
@@ -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"
|