@notionhq/custom-blocks 0.1.42 → 0.1.44
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 +3 -3
- package/dist/bridge/SandboxBridge.d.ts +9 -2
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +31 -13
- 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/hostState.d.ts.map +1 -1
- package/dist/bridge/hostState.js +8 -5
- 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/sandboxClient.d.ts +13 -4
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +23 -5
- 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/types.d.ts +29 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/data-sources.md +213 -66
- package/docs/lifecycle.md +1 -11
- package/docs/pages.md +16 -8
- package/docs/users.md +0 -1
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +49 -19
- package/src/bridge/dataSources/subscribe.ts +97 -0
- package/src/bridge/hostState.ts +9 -6
- package/src/bridge/notifyListener.ts +14 -0
- package/src/bridge/sandboxClient.ts +31 -10
- package/src/customBlock.ts +7 -0
- package/src/react/useDataSource.ts +32 -39
- package/src/types.ts +37 -17
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 = {
|
|
@@ -60,11 +60,18 @@ export type NotionDataSourcePage = {
|
|
|
60
60
|
* keys to raw property IDs before sending the bridge message to the host.
|
|
61
61
|
*/
|
|
62
62
|
update: (args: NotionDataSourcePageUpdateArgs) => Promise<UpdatePageResult>;
|
|
63
|
+
/** Archives this page. Shorthand for update({ is_archived: true }). */
|
|
64
|
+
archive: () => Promise<UpdatePageResult>;
|
|
65
|
+
/** Unarchives this page. Shorthand for update({ is_archived: false }). */
|
|
66
|
+
unarchive: () => Promise<UpdatePageResult>;
|
|
63
67
|
};
|
|
64
68
|
export type NotionDataSourcePageUpdateArgs = {
|
|
65
69
|
properties?: NotionPagePropertyInputMap;
|
|
66
70
|
icon?: NotionPageIcon;
|
|
67
71
|
cover?: NotionPageCover;
|
|
72
|
+
/** Whether to archive this page. Takes precedence over archived. */
|
|
73
|
+
is_archived?: boolean;
|
|
74
|
+
/** @deprecated Use is_archived instead. */
|
|
68
75
|
archived?: boolean;
|
|
69
76
|
};
|
|
70
77
|
/**
|
|
@@ -122,14 +129,14 @@ export type NotionDataSourceFilter = NotionDataSourcePropertyFilter | {
|
|
|
122
129
|
and: NotionDataSourcePropertyFilter[];
|
|
123
130
|
};
|
|
124
131
|
/**
|
|
125
|
-
*
|
|
132
|
+
* Latest live snapshot of a data source query.
|
|
126
133
|
*
|
|
127
134
|
* - `items` — the rows the host has returned so far. Empty until the first response arrives.
|
|
128
135
|
* - `isLoading` — `true` while a query is in flight.
|
|
129
|
-
* - `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.
|
|
130
137
|
* - `error` — structured error information if the most recent query failed.
|
|
131
138
|
*/
|
|
132
|
-
export type
|
|
139
|
+
export type DataSourceSnapshot = {
|
|
133
140
|
items: NotionDataSourcePage[];
|
|
134
141
|
/**
|
|
135
142
|
* Collection/data source schema for the bound Notion data source, including raw property
|
|
@@ -162,21 +169,21 @@ export type UseDataSourceResult = {
|
|
|
162
169
|
hasMore: boolean;
|
|
163
170
|
error?: CustomBlockQueryDataSourceErrorInfo;
|
|
164
171
|
};
|
|
165
|
-
export type
|
|
166
|
-
/**
|
|
167
|
-
* Maximum number of rows to request from the host. Defaults to 20.
|
|
168
|
-
*/
|
|
172
|
+
export type DataSourceQueryOptions = {
|
|
173
|
+
/** Maximum number of rows to request from the host. Defaults to 20. */
|
|
169
174
|
limit?: number;
|
|
170
|
-
/**
|
|
171
|
-
* Optional property filter. The SDK resolves semantic property keys before
|
|
172
|
-
* it sends the query to the host.
|
|
173
|
-
*/
|
|
175
|
+
/** Optional property filter. The SDK resolves semantic keys before it sends the query. */
|
|
174
176
|
filter?: NotionDataSourceFilter;
|
|
175
|
-
/**
|
|
176
|
-
* Optional property sorts. The host applies them in array order.
|
|
177
|
-
*/
|
|
177
|
+
/** Optional property sorts. The host applies them in array order. */
|
|
178
178
|
sorts?: NotionDataSourceSort[];
|
|
179
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;
|
|
180
187
|
/**
|
|
181
188
|
* Parent reference accepted by `sdk.pages.create`. Mirrors Notion's public `POST /v1/pages`
|
|
182
189
|
* parent shape; see https://developers.notion.com/reference/data-source.
|
|
@@ -217,7 +224,12 @@ export type CreatePageInput = CreatePageArgs;
|
|
|
217
224
|
* The result of a `sdk.pages.create` API call.
|
|
218
225
|
*/
|
|
219
226
|
export type CreatePageResult = BridgeMessagePayload<CreatePageResultMessage, CustomBlockCreatePageErrorInfo>;
|
|
220
|
-
export type UpdatePageArgs = Omit<UpdatePageMessage, "type" | "requestId"
|
|
227
|
+
export type UpdatePageArgs = Omit<UpdatePageMessage, "type" | "requestId" | "archived"> & {
|
|
228
|
+
/** Whether to archive this page. Takes precedence over archived. */
|
|
229
|
+
is_archived?: boolean;
|
|
230
|
+
/** @deprecated Use is_archived instead. */
|
|
231
|
+
archived?: boolean;
|
|
232
|
+
};
|
|
221
233
|
/**
|
|
222
234
|
* @deprecated Use `UpdatePageArgs` instead.
|
|
223
235
|
*
|
|
@@ -229,7 +241,7 @@ export type UpdatePageInput = UpdatePageArgs;
|
|
|
229
241
|
*/
|
|
230
242
|
export type GetPageResult = BridgeMessagePayload<GetPageResultMessage, CustomBlockGetPageErrorInfo>;
|
|
231
243
|
/**
|
|
232
|
-
* Result of `sdk.pages.update`
|
|
244
|
+
* Result of `sdk.pages.update`, `sdk.pages.archive`, and `sdk.pages.unarchive`.
|
|
233
245
|
*/
|
|
234
246
|
export type UpdatePageResult = BridgeMessagePayload<UpdatePageResultMessage, CustomBlockUpdatePageErrorInfo>;
|
|
235
247
|
export type ListUsersArgs = Omit<ListUsersMessage, "type" | "requestId">;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAA;AACxG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iEAAiE,CAAA;AAC5G,OAAO,KAAK,EAAE,oBAAo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|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read the Notion rows your block needs with filters, sorts, and row limits. Your subscription keeps them current as the data changes.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use `customBlock.subscribeToDataSource(...)` with any TypeScript UI framework. For React, `useDataSource(key, options)` provides the latest snapshot and handles subscription cleanup.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Each snapshot contains rows, property schemas, loading and error state, and `hasMore`. Each query result replaces the previous rows in the snapshot. Subscriptions remain independent, even when they query the same data source.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Queries default to 20 rows and support up to 999. See [Known limitations](#known-limitations) for pagination, filter, and sort restrictions.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Bind a data source
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Declare the data your block needs under `dataSources` in `worker.customBlock(...)`. Give each declaration a key, such as `people`, and declare the properties your block uses.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
- `propertiesById[propertyId]` — keyed by the raw Notion property ID.
|
|
15
|
+
When someone adds the block to Notion, they bind each declaration to a data source and map its properties. Your code queries the declared key and the SDK resolves the binding. This lets the same block work with different data sources across workspaces.
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
Prefer `propertiesByKey` when reading declared properties. These keys stay the same across bindings. `propertiesById` exposes values keyed by the bound data source's raw property IDs.
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
Use `ManifestDataSource`, `ManifestProperty`, and `ManifestIcon` for declaration metadata. To list declared keys, use `useManifest()` in React or `customBlock.getManifest()` in TypeScript. These APIs are useful for a data source switcher.
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
## Subscribe to rows
|
|
22
|
+
|
|
23
|
+
### `customBlock.subscribeToDataSource(args)`
|
|
23
24
|
|
|
24
25
|
```ts
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
function customBlock.subscribeToDataSource(
|
|
27
|
+
args: SubscribeToDataSourceArgs,
|
|
28
|
+
): () => void;
|
|
29
|
+
|
|
30
|
+
type SubscribeToDataSourceArgs = {
|
|
31
|
+
key: string;
|
|
32
|
+
onSnapshot: (snapshot: DataSourceSnapshot) => void;
|
|
33
|
+
options?: DataSourceQueryOptions;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type DataSourceQueryOptions = {
|
|
37
|
+
limit?: number;
|
|
38
|
+
filter?: NotionDataSourceFilter;
|
|
39
|
+
sorts?: NotionDataSourceSort[];
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Each call registers the `onSnapshot` listener. When you unsubscribe that listener, other listeners remain subscribed. Queries start only after SDK initialization.
|
|
44
|
+
|
|
45
|
+
The listener receives the current snapshot immediately and receives later updates. Unrelated host changes do not trigger the listener. A new query result can trigger the listener even if its row values are unchanged. Each snapshot contains rows, schema, loading state, and row methods for updating, archiving, and unarchiving.
|
|
46
|
+
|
|
47
|
+
The SDK calls `onSnapshot` immediately with the current snapshot, before `subscribeToDataSource` returns.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { customBlock, initCustomBlock } from "@notionhq/custom-blocks";
|
|
51
|
+
|
|
52
|
+
await initCustomBlock();
|
|
53
|
+
|
|
54
|
+
const unsubscribe = customBlock.subscribeToDataSource({
|
|
55
|
+
key: "people",
|
|
56
|
+
onSnapshot: (snapshot) => render(snapshot),
|
|
57
|
+
options: {
|
|
58
|
+
limit: 50,
|
|
59
|
+
sorts: [{ key: "name", direction: "ascending" }],
|
|
28
60
|
},
|
|
29
|
-
icon: { type: "emoji", emoji: "✅" },
|
|
30
61
|
});
|
|
62
|
+
|
|
63
|
+
// When the renderer unmounts:
|
|
64
|
+
unsubscribe();
|
|
31
65
|
```
|
|
32
66
|
|
|
33
|
-
|
|
67
|
+
To change the query or request more rows, unsubscribe and create a new subscription with different options.
|
|
34
68
|
|
|
35
|
-
|
|
69
|
+
Both APIs accept the [query options](#query-options) below. The SDK copies options when you subscribe. Later changes to the supplied object do not affect the subscription. A change to the data source definition repeats the query with the current options.
|
|
36
70
|
|
|
37
|
-
|
|
71
|
+
`unsubscribe()` removes this SDK subscription and its listener, then sends `unsubscribeDataSourceQuery` to the host. The host stops future refreshes and ignores pending results for that subscription. Other subscriptions remain active. Repeated calls have no effect.
|
|
38
72
|
|
|
39
73
|
### `useDataSource(key, options?)`
|
|
40
74
|
|
|
@@ -60,80 +94,148 @@ type UseDataSourceResult = {
|
|
|
60
94
|
};
|
|
61
95
|
```
|
|
62
96
|
|
|
63
|
-
Reads the data source mapped to `key`.
|
|
97
|
+
Reads the data source mapped to `key`. To request more rows, store the limit in component state and pass it to `useDataSource` again.
|
|
98
|
+
|
|
99
|
+
`propertyIdsByKey` maps manifest property keys to raw Notion property IDs; unbound keys map to `undefined`. `propertySchemasByKey` exposes the corresponding schemas and is likewise `undefined` for declared-but-unbound slots.
|
|
100
|
+
|
|
101
|
+
`useDataSource` uses `customBlock.subscribeToDataSource` and returns its latest snapshot. A change to the key, limit, filter, or sorts replaces the subscription.
|
|
102
|
+
|
|
103
|
+
Each consumer has its own host subscription. On unmount, the SDK removes its local query state and sends an unsubscribe message. The host stops future refreshes and ignores pending results. Other consumers remain subscribed.
|
|
104
|
+
|
|
105
|
+
Query failures follow the SDK's [error-handling contract](./errors.md).
|
|
106
|
+
|
|
107
|
+
## Query options
|
|
108
|
+
|
|
109
|
+
Both subscription APIs accept `limit`, `filter`, and `sorts`.
|
|
110
|
+
|
|
111
|
+
### Row limits
|
|
112
|
+
|
|
113
|
+
`limit` defaults to 20 and must be a positive integer. The SDK caps values above 999. Each query reads from the start of the matching rows. A larger limit replaces the previous snapshot with a larger result.
|
|
114
|
+
|
|
115
|
+
`hasMore` indicates that more matching rows exist beyond the result. It does not provide a cursor or guarantee that increasing the limit can retrieve every row.
|
|
64
116
|
|
|
65
|
-
|
|
117
|
+
### Filters
|
|
118
|
+
|
|
119
|
+
Use `filter` to select matching rows. Filters do not support every property type yet. Check [Property support](#property-support) before choosing a property.
|
|
120
|
+
|
|
121
|
+
Use a single condition to match unfinished tasks:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
filter: {
|
|
125
|
+
key: "done",
|
|
126
|
+
checkbox: { equals: false },
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Use `and` to match unfinished tasks whose titles also contain "launch":
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
filter: {
|
|
134
|
+
and: [
|
|
135
|
+
{ key: "title", title: { contains: "launch" } },
|
|
136
|
+
{ key: "done", checkbox: { equals: false } },
|
|
137
|
+
],
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Here, `title` and `done` are declared property keys. Use `propertyId` instead of `key` when you have a raw property ID. The condition type, such as `checkbox`, must match the property's schema.
|
|
142
|
+
|
|
143
|
+
Pass a single condition directly, or combine up to 25 conditions with `and`. Nested groups and `or` are unsupported. An empty `and` group applies no conditions. Both APIs accept the same filter shape.
|
|
144
|
+
|
|
145
|
+
The SDK reports invalid keys, types, operators, and values through the snapshot's `error` field.
|
|
146
|
+
|
|
147
|
+
<details>
|
|
148
|
+
<summary>Filter operators and values</summary>
|
|
149
|
+
|
|
150
|
+
| Property types | Filter operators |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| `title`, `rich_text`, `url`, `email`, `phone_number` | `equals`, `does_not_equal`, `contains`, `does_not_contain`, `starts_with`, `ends_with`, `is_empty`, `is_not_empty` |
|
|
153
|
+
| `number` | `equals`, `does_not_equal`, `greater_than`, `less_than`, `greater_than_or_equal_to`, `less_than_or_equal_to`, `is_empty`, `is_not_empty` |
|
|
154
|
+
| `checkbox` | `equals`, `does_not_equal` |
|
|
155
|
+
| `select`, `status` | `equals`, `does_not_equal`, `is_empty`, `is_not_empty` |
|
|
156
|
+
| `multi_select` | `contains`, `contains_all`, `does_not_contain`, `is_empty`, `is_not_empty` |
|
|
157
|
+
| `date` | `equals`, `before`, `after`, `on_or_before`, `on_or_after`, `is_empty`, `is_not_empty` |
|
|
158
|
+
|
|
159
|
+
Select, multi-select, and status values can be one option name or an array of option names. For multi-select properties, `contains` matches any supplied option and `contains_all` requires every supplied option. Empty checks use `{ is_empty: true }` or `{ is_not_empty: true }`. Date comparisons accept ISO dates or ISO timestamps.
|
|
160
|
+
|
|
161
|
+
</details>
|
|
162
|
+
|
|
163
|
+
### Sorts
|
|
164
|
+
|
|
165
|
+
Use `sorts` to order matching rows. Sorts do not support every property type yet, including some types that support filters. Check [Property support](#property-support) before choosing a property.
|
|
166
|
+
|
|
167
|
+
This example sorts tasks by due date, with the earliest first. Tasks with the same due date use their creation time, newest first:
|
|
66
168
|
|
|
67
169
|
```tsx
|
|
68
170
|
const query = useDataSource("tasks", {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
sorts: [{ key: "due", direction: "ascending" }],
|
|
171
|
+
sorts: [
|
|
172
|
+
{ key: "due", direction: "ascending" },
|
|
173
|
+
{ propertyId: "created_time", direction: "descending" },
|
|
174
|
+
],
|
|
76
175
|
limit: 50,
|
|
77
176
|
});
|
|
78
177
|
```
|
|
79
178
|
|
|
80
|
-
|
|
179
|
+
Here, `due` is a declared date property key and `created_time` is a built-in property ID. Sorts apply in array order, with the first property taking priority. Empty values sort last in both directions.
|
|
81
180
|
|
|
82
|
-
|
|
83
|
-
- `number`: `equals`, `does_not_equal`, `greater_than`, `less_than`, `greater_than_or_equal_to`, `less_than_or_equal_to`, `is_empty`, and `is_not_empty`.
|
|
84
|
-
- `checkbox`: `equals` and `does_not_equal`.
|
|
85
|
-
- `select` and `status`: `equals`, `does_not_equal`, `is_empty`, and `is_not_empty`.
|
|
86
|
-
- `multi_select`: `contains`, `contains_all`, `does_not_contain`, `is_empty`, and `is_not_empty`.
|
|
87
|
-
- `date`: `equals`, `before`, `after`, `on_or_before`, `on_or_after`, `is_empty`, and `is_not_empty`.
|
|
181
|
+
You can sort by up to 10 unique properties. Both APIs accept the same sort shape, and you can combine `sorts` with `filter`.
|
|
88
182
|
|
|
89
|
-
|
|
183
|
+
## Pages within a data source
|
|
90
184
|
|
|
91
|
-
|
|
185
|
+
Each row returned by either API is a `NotionDataSourcePage` — `{ id, propertiesById, propertiesByKey, update, archive, unarchive }`. Read property values through either of the two views:
|
|
92
186
|
|
|
93
|
-
`
|
|
94
|
-
|
|
95
|
-
resolves semantic keys before it sends the bridge request. The host applies
|
|
96
|
-
sorts in array order. The first sort has the highest priority. The list can
|
|
97
|
-
contain up to ten unique properties. Empty values sort last in either
|
|
98
|
-
direction. Sorts currently support title, rich text, number, checkbox, URL,
|
|
99
|
-
email, phone number, date, created time, and last edited time properties.
|
|
100
|
-
Other property types are rejected until their sort values are supported.
|
|
187
|
+
- `propertiesByKey[key]` — keyed by the semantic property keys you declared in the manifest.
|
|
188
|
+
- `propertiesById[propertyId]` — keyed by the raw Notion property ID.
|
|
101
189
|
|
|
102
|
-
|
|
190
|
+
The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) are always present in `propertiesById` and `collectionSchema.propertiesById`. They have no semantic keys, so they do not appear in the `*ByKey` views.
|
|
103
191
|
|
|
104
|
-
|
|
192
|
+
### Updating a row
|
|
105
193
|
|
|
106
|
-
|
|
194
|
+
Each page carries its own `update` helper:
|
|
107
195
|
|
|
108
196
|
```ts
|
|
109
|
-
|
|
197
|
+
await row.update({
|
|
198
|
+
properties: {
|
|
199
|
+
score: { type: "number", number: 8 }, // semantic key
|
|
200
|
+
},
|
|
201
|
+
icon: { type: "emoji", emoji: "✅" },
|
|
202
|
+
});
|
|
110
203
|
```
|
|
111
204
|
|
|
112
|
-
|
|
205
|
+
Property values can be keyed by **either** semantic keys or raw IDs. The SDK resolves semantic keys to IDs before sending the request.
|
|
113
206
|
|
|
114
|
-
|
|
115
|
-
const query = useDataSource("tasks");
|
|
116
|
-
```
|
|
207
|
+
Use `row.update(...)` whenever you already have a row in hand. For pages you don't have a row for (e.g. you only have a `pageId`), drop down to the top-level [`pages` API](./pages.md) — it covers create / get / update / archive / unarchive and accepts raw property IDs only.
|
|
117
208
|
|
|
118
|
-
|
|
209
|
+
### Archiving and unarchiving a row
|
|
119
210
|
|
|
120
|
-
|
|
211
|
+
`row.archive()` is shorthand for calling `row.update({ is_archived: true })`.
|
|
212
|
+
`row.unarchive()` is shorthand for calling `row.update({ is_archived: false })`.
|
|
213
|
+
Both methods return an `UpdatePageResult`.
|
|
214
|
+
Use `row.update` to change archive status and other fields in one request.
|
|
121
215
|
|
|
122
|
-
|
|
216
|
+
## Read declarations
|
|
217
|
+
|
|
218
|
+
Use the manifest when your UI needs to discover which data sources and properties the block declares. For example, build a data source switcher from the declared keys or table headings from the declared property names.
|
|
219
|
+
|
|
220
|
+
Both APIs below return the declaration from `worker.customBlock(...)`, including its keys, names, descriptions, and property definitions. To query a selected data source, pass its key to either subscription API. Read resolved property IDs from the query snapshot's `propertyIdsByKey` map.
|
|
221
|
+
|
|
222
|
+
Both APIs return synchronously and throw if called before `initCustomBlock()` resolves.
|
|
223
|
+
|
|
224
|
+
### `useManifest()`
|
|
123
225
|
|
|
124
226
|
```ts
|
|
125
|
-
function
|
|
227
|
+
function useManifest(): CustomBlockManifest;
|
|
126
228
|
```
|
|
127
229
|
|
|
128
|
-
|
|
230
|
+
Returns the block manifest received from the host during initialization. The manifest contains declarations only. Resolved bindings and rows are available through query snapshots.
|
|
129
231
|
|
|
130
|
-
|
|
131
|
-
await initCustomBlock();
|
|
232
|
+
### `customBlock.getManifest()`
|
|
132
233
|
|
|
133
|
-
|
|
234
|
+
```ts
|
|
235
|
+
function customBlock.getManifest(): CustomBlockManifest;
|
|
134
236
|
```
|
|
135
237
|
|
|
136
|
-
|
|
238
|
+
Framework-neutral getter for the same manifest returned by `useManifest()`. The manifest is static for the lifetime of the sandbox, so there is nothing to subscribe to.
|
|
137
239
|
|
|
138
240
|
## Example: querying a data source
|
|
139
241
|
|
|
@@ -178,10 +280,10 @@ export function ScoreList() {
|
|
|
178
280
|
</li>
|
|
179
281
|
))}
|
|
180
282
|
</ul>
|
|
181
|
-
{hasMore ? (
|
|
283
|
+
{hasMore && limit < 999 ? (
|
|
182
284
|
<button
|
|
183
285
|
type="button"
|
|
184
|
-
onClick={() => setLimit(limit + 20)}
|
|
286
|
+
onClick={() => setLimit(Math.min(limit + 20, 999))}
|
|
185
287
|
disabled={isLoading}
|
|
186
288
|
>
|
|
187
289
|
{isLoading ? "Loading…" : "Load more"}
|
|
@@ -192,22 +294,67 @@ export function ScoreList() {
|
|
|
192
294
|
}
|
|
193
295
|
```
|
|
194
296
|
|
|
297
|
+
## Known limitations
|
|
298
|
+
|
|
299
|
+
- **Row limits and pagination:** `limit` defaults to 20 and is capped at 999. Queries have no cursor or offset. Increasing the limit repeats the query from the start and replaces the snapshot. `hasMore` can remain true at the cap, so use filters to narrow larger data sources.
|
|
300
|
+
- **Filter and sort rules:** Use one property condition or one `and` group with up to 25 conditions. Nested groups and `or` are unsupported. Sort by up to 10 unique properties. Empty values sort last in both directions. See the table below for property support and [Filters](#filters) for operators.
|
|
301
|
+
- **Changing a query:** TypeScript subscriptions copy their options when they start. To change them, unsubscribe and create a new subscription. React replaces the subscription when the key or options change. Previous rows are cleared while the new query loads.
|
|
302
|
+
- **Updates:** Callbacks receive complete snapshots, not individual row changes. A new result can trigger a callback even when its row values are unchanged.
|
|
303
|
+
|
|
304
|
+
### Property support
|
|
305
|
+
|
|
306
|
+
The table shows the values returned by the Notion host and whether each property type supports filtering and sorting. ✅ means supported. ❌ means unsupported. ⚠️ marks a text fallback that does not preserve the property's structured value. Missing values can be `undefined`.
|
|
307
|
+
|
|
308
|
+
| Property type | Query result | Filter | Sort |
|
|
309
|
+
| --- | --- | :---: | :---: |
|
|
310
|
+
| `title` | Plain text | ✅ | ✅ |
|
|
311
|
+
| `rich_text` | Plain text | ✅ | ✅ |
|
|
312
|
+
| `number` | Number | ✅ | ✅ |
|
|
313
|
+
| `checkbox` | Boolean | ✅ | ✅ |
|
|
314
|
+
| `url` | String | ✅ | ✅ |
|
|
315
|
+
| `email` | String | ✅ | ✅ |
|
|
316
|
+
| `phone_number` | String | ✅ | ✅ |
|
|
317
|
+
| `select` | Option name | ✅ | ❌ |
|
|
318
|
+
| `multi_select` | Array of option names | ✅ | ❌ |
|
|
319
|
+
| `status` | Option name | ✅ | ❌ |
|
|
320
|
+
| `date` | `NotionDateValue` | ✅ | ✅ |
|
|
321
|
+
| `people` | Array of record pointers | ❌ | ❌ |
|
|
322
|
+
| `files` | ⚠️ Text fallback | ❌ | ❌ |
|
|
323
|
+
| `unique_id` | ⚠️ Text fallback | ❌ | ❌ |
|
|
324
|
+
| `relation` | Array of record pointers | ❌ | ❌ |
|
|
325
|
+
| `place` | ⚠️ Text fallback | ❌ | ❌ |
|
|
326
|
+
| `formula` | ⚠️ Text fallback | ❌ | ❌ |
|
|
327
|
+
| `rollup` | ⚠️ Text fallback | ❌ | ❌ |
|
|
328
|
+
| `button` | ⚠️ Text fallback | ❌ | ❌ |
|
|
329
|
+
| `verification` | ⚠️ Text fallback | ❌ | ❌ |
|
|
330
|
+
| `last_visited_time` | ⚠️ Text fallback | ❌ | ❌ |
|
|
331
|
+
| `location` | ⚠️ Text fallback | ❌ | ❌ |
|
|
332
|
+
| `created_time` | `NotionDateTime` in UTC | ❌ | ✅ |
|
|
333
|
+
| `last_edited_time` | `NotionDateTime` in UTC | ❌ | ✅ |
|
|
334
|
+
| `created_by` | Array of record pointers | ❌ | ❌ |
|
|
335
|
+
| `last_edited_by` | Array of record pointers | ❌ | ❌ |
|
|
336
|
+
|
|
337
|
+
Text values omit formatting, mention tokens, and annotations. Record pointers contain a table name and a record ID.
|
|
338
|
+
|
|
339
|
+
Use `propertyId: "created_time"` or `propertyId: "last_edited_time"` to sort by these built-in timestamps.
|
|
340
|
+
|
|
195
341
|
## Types
|
|
196
342
|
|
|
197
343
|
### Rows & values
|
|
198
344
|
|
|
199
345
|
- `NotionDataSource` — a resolved data source: semantic key, optional `collectionSchema`, `propertyIdsByKey`, and `propertySchemasById`.
|
|
200
|
-
- `NotionDataSourcePage` — a single row exposed to app code: `{ id, propertiesById, propertiesByKey, update }`.
|
|
346
|
+
- `NotionDataSourcePage` — a single row exposed to app code: `{ id, propertiesById, propertiesByKey, update, archive, unarchive }`.
|
|
201
347
|
- `NotionDataSourceValue` — the value union for `propertiesById` and `propertiesByKey`.
|
|
202
348
|
- `NotionDataSourcePageUpdateArgs` / `UpdatePageResult` — arguments and result for the per-page `update` helper.
|
|
203
|
-
- `NotionDataSourcePageUpdateInput` — deprecated alias for `NotionDataSourcePageUpdateArgs`.
|
|
204
|
-
- `NotionDataSourcePageUpdateResult` — deprecated alias for `UpdatePageResult`.
|
|
205
349
|
- `UseDataSourceOptions` — options accepted by `useDataSource`: `limit?: number`, `filter?: NotionDataSourceFilter`, and `sorts?: NotionDataSourceSort[]`.
|
|
206
350
|
- `NotionDataSourceFilter` — one property condition or one shallow `and` group.
|
|
207
351
|
- `NotionDataSourcePropertyFilter` — one property address combined with a type-specific operator.
|
|
208
352
|
- `NotionDataSourcePropertyAddress` — either a semantic property `key` or a raw `propertyId`.
|
|
209
353
|
- `NotionDataSourceSort` — a property address with an `ascending` or `descending` direction.
|
|
210
354
|
- `NotionDataSourceTextFilterOperator`, `NotionDataSourceNumberFilterOperator`, `NotionDataSourceCheckboxFilterOperator`, `NotionDataSourceOptionFilterOperator`, `NotionDataSourceContainsFilterOperator`, and `NotionDataSourceDateFilterOperator` — the operators accepted for each property type.
|
|
355
|
+
- `DataSourceSnapshot` — current rows, schema, and status for one live data-source query.
|
|
356
|
+
- `DataSourceQueryOptions` — the row limit, filter, and sorts shared by both query APIs.
|
|
357
|
+
- `SubscribeToDataSourceArgs` — the key, `onSnapshot` listener, and optional query options for `customBlock.subscribeToDataSource`.
|
|
211
358
|
|
|
212
359
|
### Property schemas
|
|
213
360
|
|
package/docs/lifecycle.md
CHANGED
|
@@ -150,7 +150,7 @@ All code types are open string unions, so keep a default branch. Use `isRetryabl
|
|
|
150
150
|
|
|
151
151
|
Framework-neutral runtime APIs for renderers that do not use React hooks. `customBlock.getState()` returns a `CustomBlockState` snapshot that includes `theme` and `contrastMode` while hiding internal query cache details. All getters that read host state — `getTheme`, `getContrastMode`, `getBlockId`, `getParent`, `getPage`, `getCurrentUser`, and `getManifest` — throw until `initCustomBlock()` resolves. `getManifest()` then returns the authoritative manifest supplied by the host.
|
|
152
152
|
|
|
153
|
-
`customBlock` covers runtime state
|
|
153
|
+
`customBlock` covers runtime state, live data source snapshots, and sizing. Imperative APIs such as `pages.*` and `users.*` are also framework-neutral functions.
|
|
154
154
|
|
|
155
155
|
```ts
|
|
156
156
|
await initCustomBlock();
|
|
@@ -177,16 +177,6 @@ stopAutoResize();
|
|
|
177
177
|
|
|
178
178
|
Thrown when `initCustomBlock` is called in a top-level tab (no parent frame). It extends `CustomBlockInitializationError`, has `code: "not_in_iframe"` and `isRetryable: false`, and can be detected specifically with `instanceof NotInIframeError`. `<NotionCustomBlock>` catches it and falls back to a standalone preview with a warning banner.
|
|
179
179
|
|
|
180
|
-
### `useCustomBlockAutoResize({ enabled? })`
|
|
181
|
-
|
|
182
|
-
Deprecated. Blocks resize automatically. Use CSS `max-height` and `overflow` to set a shorter height.
|
|
183
|
-
|
|
184
|
-
```ts
|
|
185
|
-
function useCustomBlockAutoResize(args?: { enabled?: boolean }): void;
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
Deprecated React wrapper around `customBlock.autoResize({ target: document.getElementById("root") })`. It measures `#root`'s height and posts `resize` messages, deduping unchanged values. `<NotionCustomBlock>` runs this automatically.
|
|
189
|
-
|
|
190
180
|
## Debug console
|
|
191
181
|
|
|
192
182
|
Press `\` while focused in a custom block to toggle a debug overlay that replaces the block's children with a `<pre>` log of every `postMessage` sent and received over the bridge. Each line is formatted as:
|
package/docs/pages.md
CHANGED
|
@@ -97,7 +97,7 @@ Read `in_trash` on a page or data source row. It is `true` when the page or an a
|
|
|
97
97
|
|
|
98
98
|
## Updating pages
|
|
99
99
|
|
|
100
|
-
`pages.update` writes back to a page. The optional fields (`properties`, `icon`, `cover`, `
|
|
100
|
+
`pages.update` writes back to a page. The optional fields (`properties`, `icon`, `cover`, `is_archived`) are independent — supply only what you want to change:
|
|
101
101
|
|
|
102
102
|
```ts
|
|
103
103
|
const result = await pages.update({
|
|
@@ -115,17 +115,27 @@ const result = await pages.update({
|
|
|
115
115
|
|
|
116
116
|
The `properties` map (a `NotionPagePropertyWriteMap`) is keyed by **raw Notion property ID**, and each value must repeat that ID as its own `id` field — semantic data source keys aren't accepted here. To update a row by configured custom-block key without writing out the raw IDs, use the `update` helper on the row returned from `useDataSource` instead; the SDK handles the key → ID resolution for you.
|
|
117
117
|
|
|
118
|
-
If you call `pages.update` with no fields to change, it short-circuits and resolves with `{ status: "error", error: { code: "invalid_page_update", message: "updatePage requires at least one
|
|
118
|
+
If you call `pages.update` with no fields to change, it short-circuits and resolves with `{ status: "error", error: { code: "invalid_page_update", message: "updatePage requires at least one property.", isRetryable: false } }` — no request is sent.
|
|
119
119
|
|
|
120
|
-
##
|
|
120
|
+
## Archiving and unarchiving pages
|
|
121
121
|
|
|
122
|
-
`pages.
|
|
122
|
+
`pages.archive(pageId)` archives a page. `pages.unarchive(pageId)` removes its archive state.
|
|
123
123
|
|
|
124
124
|
```ts
|
|
125
|
-
await pages.
|
|
125
|
+
const result = await pages.archive(pageId);
|
|
126
|
+
if (result.status === "error") {
|
|
127
|
+
console.error(result.error.message);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const restored = await pages.unarchive(pageId);
|
|
131
|
+
if (restored.status === "error") {
|
|
132
|
+
console.error(restored.error.message);
|
|
133
|
+
}
|
|
126
134
|
```
|
|
127
135
|
|
|
128
|
-
|
|
136
|
+
`pages.archive` is shorthand for calling `pages.update` with `is_archived: true`.
|
|
137
|
+
`pages.unarchive` is shorthand for calling `pages.update` with `is_archived: false`.
|
|
138
|
+
Both methods return an `UpdatePageResult`.
|
|
129
139
|
|
|
130
140
|
## Icons, covers, and file uploads
|
|
131
141
|
|
|
@@ -151,7 +161,5 @@ Do **not** send `{ type: "file_upload", file_upload: { id } }`; the host will re
|
|
|
151
161
|
- `NotionPagePropertyWriteMap` — input map for `pages.update` (raw property IDs only).
|
|
152
162
|
- `NotionCreatePagePosition` — `start` / `end` / `before` / `after` insertion variants.
|
|
153
163
|
- `CreatePageArgs` / `CreatePageParent` / `CreatePageResult`.
|
|
154
|
-
- `CreatePageInput` — deprecated alias for `CreatePageArgs`.
|
|
155
164
|
- `GetPageResult`.
|
|
156
165
|
- `UpdatePageArgs` / `UpdatePageResult`.
|
|
157
|
-
- `UpdatePageInput` — deprecated alias for `UpdatePageArgs`.
|
package/docs/users.md
CHANGED
|
@@ -78,5 +78,4 @@ if (result.status === "success") {
|
|
|
78
78
|
- `useCurrentUser()` — hook that returns the viewer's `NotionUser`.
|
|
79
79
|
- `customBlock.getCurrentUser()` — framework-neutral getter for the viewer's `NotionUser`.
|
|
80
80
|
- `ListUsersArgs` / `ListUsersResult`.
|
|
81
|
-
- `ListUsersInput` — deprecated alias for `ListUsersArgs`.
|
|
82
81
|
- `GetUserResult`.
|