create-ncblock 0.0.34 → 0.0.35
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/package.json
CHANGED
|
@@ -15,8 +15,9 @@ That writes `custom_blocks.json`, `.notion/target.json`, and PATCHes any blocks
|
|
|
15
15
|
## Talking to the host
|
|
16
16
|
|
|
17
17
|
- Always use the React hooks from `ncblock/react`. Never call `window.parent.postMessage` directly — the SDK owns the protocol.
|
|
18
|
-
- Render app code inside `<NotionCustomBlock>` so the handshake completes before hooks run.
|
|
19
|
-
|
|
18
|
+
- Render app code inside `<NotionCustomBlock>` so the handshake completes before hooks like `useTheme` or `useBlockId` run.
|
|
19
|
+
|
|
20
|
+
`<NotionCustomBlock>` runs `useCustomBlockAutoResize` for you by default — no extra wiring needed. Pass `autoResize={false}` for full-bleed views. Read `node_modules/ncblock/README.md` and the `.d.ts` files for current APIs and signatures.
|
|
20
21
|
|
|
21
22
|
## Sizing
|
|
22
23
|
|
|
@@ -49,7 +50,7 @@ Two options:
|
|
|
49
50
|
|
|
50
51
|
- `node_modules/ncblock/README.md` — landing page with a TOC into the per-category docs below.
|
|
51
52
|
- `node_modules/ncblock/docs/lifecycle.md` — `<NotionCustomBlock>`, init, sizing, auto-resize.
|
|
52
|
-
- `node_modules/ncblock/docs/
|
|
53
|
+
- `node_modules/ncblock/docs/block-location.md` — `useBlockId`, `useParent`, `usePage`, `useTheme`.
|
|
53
54
|
- `node_modules/ncblock/docs/data-sources.md` — `useDataSource`, row/property/date types, worked example.
|
|
54
55
|
- `node_modules/ncblock/docs/pages.md` — `pages.create / get / update / delete`.
|
|
55
56
|
- `node_modules/ncblock/docs/users.md` — `users.list / get`, `NotionUser`.
|
package/sdk-version.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.0.
|
|
1
|
+
{"version":"0.0.33"}
|
|
@@ -28,9 +28,6 @@ Vite bundles `src/index.tsx` into `dist/`. When embedded in Notion, the SDK hook
|
|
|
28
28
|
|
|
29
29
|
The debug template includes a message log that intercepts and displays all incoming and outgoing `postMessage` events, making it useful for understanding the Notion host communication protocol.
|
|
30
30
|
|
|
31
|
-
### SDK
|
|
31
|
+
### SDK docs
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
- **`useTheme()`** -- returns the host's current theme (`"light"` or `"dark"`)
|
|
35
|
-
- **`useManifest()`** -- returns the declared manifest (data-source keys + property declarations)
|
|
36
|
-
- **`useDataSource(key)`** -- returns `{ items, collectionSchema, propertySchemasById, propertySchemasByKey, isLoading, hasMore, fetchMore, error }`. Each `item` has `{ id, propertiesById, propertiesByKey }`. The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) appear in `propertiesById` / `propertySchemasById`, never in the `*ByKey` views.
|
|
33
|
+
This project uses the public `ncblock` React hooks and data source APIs. After installing dependencies, see `node_modules/ncblock/README.md` for the current API reference and links to the per-category docs.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type NotionBlockId,
|
|
2
3
|
type NotionCreatePagePosition,
|
|
3
|
-
type NotionCustomBlockContext,
|
|
4
4
|
type NotionDataSourceId,
|
|
5
5
|
type NotionPage,
|
|
6
6
|
type NotionPageId,
|
|
@@ -8,9 +8,11 @@ import {
|
|
|
8
8
|
} from "ncblock"
|
|
9
9
|
import {
|
|
10
10
|
NotionCustomBlock,
|
|
11
|
+
useBlockId,
|
|
11
12
|
useCurrentUser,
|
|
12
|
-
useCustomBlockContext,
|
|
13
13
|
useManifest,
|
|
14
|
+
usePage,
|
|
15
|
+
useParent,
|
|
14
16
|
useTheme,
|
|
15
17
|
} from "ncblock/react"
|
|
16
18
|
import React, {
|
|
@@ -55,7 +57,9 @@ const metaTextClass =
|
|
|
55
57
|
const HOST_NO_READY_ERROR_DELAY_SECONDS = 5
|
|
56
58
|
|
|
57
59
|
function App() {
|
|
58
|
-
const
|
|
60
|
+
const blockId = useBlockId()
|
|
61
|
+
const parent = useParent()
|
|
62
|
+
const page = usePage()
|
|
59
63
|
const currentUser = useCurrentUser()
|
|
60
64
|
const hostThemeValue = useTheme()
|
|
61
65
|
const manifest = useManifest()
|
|
@@ -84,11 +88,11 @@ function App() {
|
|
|
84
88
|
"--status-color": status.color,
|
|
85
89
|
} as React.CSSProperties
|
|
86
90
|
|
|
87
|
-
const
|
|
91
|
+
const blockLocationValue = {
|
|
88
92
|
theme: hostThemeValue,
|
|
89
|
-
|
|
90
|
-
parent
|
|
91
|
-
page
|
|
93
|
+
blockId,
|
|
94
|
+
parent,
|
|
95
|
+
page,
|
|
92
96
|
currentUser,
|
|
93
97
|
manifest,
|
|
94
98
|
}
|
|
@@ -158,32 +162,36 @@ function App() {
|
|
|
158
162
|
</div>
|
|
159
163
|
</CollapsibleCard>
|
|
160
164
|
|
|
161
|
-
{/*
|
|
165
|
+
{/* Init state */}
|
|
162
166
|
<CollapsibleCard
|
|
163
167
|
label="Init payload"
|
|
164
168
|
headerExtra={
|
|
165
169
|
<span className={metaTextClass}>
|
|
166
|
-
{Object.keys(
|
|
170
|
+
{Object.keys(blockLocationValue).length} keys
|
|
167
171
|
</span>
|
|
168
172
|
}
|
|
169
173
|
headerActions={
|
|
170
174
|
<IconButton
|
|
171
|
-
label="Copy
|
|
172
|
-
onClick={() => copy(serializeForCopy(
|
|
175
|
+
label="Copy init JSON"
|
|
176
|
+
onClick={() => copy(serializeForCopy(blockLocationValue))}
|
|
173
177
|
>
|
|
174
178
|
<CopyIcon />
|
|
175
179
|
</IconButton>
|
|
176
180
|
}
|
|
177
181
|
>
|
|
178
182
|
<JsonPanel
|
|
179
|
-
value={
|
|
183
|
+
value={blockLocationValue}
|
|
180
184
|
onCopy={copy}
|
|
181
185
|
defaultExpandedDepth={2}
|
|
182
186
|
/>
|
|
183
187
|
</CollapsibleCard>
|
|
184
188
|
|
|
185
189
|
{/* Create page */}
|
|
186
|
-
<CreatePageCard
|
|
190
|
+
<CreatePageCard
|
|
191
|
+
blockId={blockId}
|
|
192
|
+
currentPage={page}
|
|
193
|
+
dataSourceKeys={dataSourceKeys}
|
|
194
|
+
/>
|
|
187
195
|
|
|
188
196
|
{/* Send message */}
|
|
189
197
|
<SendMessageCard onSend={send} />
|
|
@@ -1655,7 +1663,8 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
|
1655
1663
|
}
|
|
1656
1664
|
|
|
1657
1665
|
type CreatePageCardProps = {
|
|
1658
|
-
|
|
1666
|
+
blockId: NotionBlockId | undefined
|
|
1667
|
+
currentPage: { id: NotionPageId } | undefined
|
|
1659
1668
|
dataSourceKeys: string[]
|
|
1660
1669
|
}
|
|
1661
1670
|
|
|
@@ -1666,7 +1675,7 @@ type CreatePagePreset = {
|
|
|
1666
1675
|
}
|
|
1667
1676
|
|
|
1668
1677
|
function presetPositions(
|
|
1669
|
-
customBlockId:
|
|
1678
|
+
customBlockId: NotionBlockId | undefined,
|
|
1670
1679
|
): CreatePagePreset[] {
|
|
1671
1680
|
const presets: CreatePagePreset[] = [
|
|
1672
1681
|
{
|
|
@@ -1775,7 +1784,7 @@ function pageIconFromInput(raw: string): NotionPage["icon"] | undefined {
|
|
|
1775
1784
|
/**
|
|
1776
1785
|
* Buttons that exercise `sdk.pages.create` at each of the supported positions. Every preset creates
|
|
1777
1786
|
* a page whose `parent.page_id` is the nearest page ancestor. `position` demonstrates append,
|
|
1778
|
-
* prepend, and inserting directly above or below the custom block via `
|
|
1787
|
+
* prepend, and inserting directly above or below the custom block via `useBlockId()`.
|
|
1779
1788
|
*
|
|
1780
1789
|
* Two extra affordances exercise the data-source-backed parents:
|
|
1781
1790
|
* - A free-form input accepts a data source ID and uses `parent: { type: "data_source_id", ... }`
|
|
@@ -1784,34 +1793,38 @@ function pageIconFromInput(raw: string): NotionPage["icon"] | undefined {
|
|
|
1784
1793
|
* SDK resolve the key to the configured data source ID locally before sending the request to the
|
|
1785
1794
|
* Notion host.
|
|
1786
1795
|
*/
|
|
1787
|
-
function CreatePageCard({
|
|
1796
|
+
function CreatePageCard({
|
|
1797
|
+
blockId,
|
|
1798
|
+
currentPage,
|
|
1799
|
+
dataSourceKeys,
|
|
1800
|
+
}: CreatePageCardProps) {
|
|
1788
1801
|
const [status, setStatus] = useState<string | null>(null)
|
|
1789
1802
|
const [busy, setBusy] = useState(false)
|
|
1790
1803
|
const [dataSourceId, setDataSourceId] = useState("")
|
|
1791
1804
|
const [pageId, setPageId] = useState("")
|
|
1792
1805
|
const [trackedPages, setTrackedPages] = useState<TrackedPage[]>([])
|
|
1793
|
-
const presets = presetPositions(
|
|
1794
|
-
const disabled =
|
|
1806
|
+
const presets = presetPositions(blockId)
|
|
1807
|
+
const disabled = currentPage === undefined || busy
|
|
1795
1808
|
const trimmedDataSourceId = dataSourceId.trim()
|
|
1796
1809
|
const dataSourceDisabled = disabled || trimmedDataSourceId === ""
|
|
1797
1810
|
const trimmedPageId = pageId.trim()
|
|
1798
1811
|
const fetchDisabled = busy || trimmedPageId === ""
|
|
1799
1812
|
|
|
1800
1813
|
useEffect(() => {
|
|
1801
|
-
if (
|
|
1802
|
-
setPageId(
|
|
1814
|
+
if (currentPage !== undefined && pageId === "") {
|
|
1815
|
+
setPageId(currentPage.id)
|
|
1803
1816
|
}
|
|
1804
|
-
}, [
|
|
1817
|
+
}, [currentPage, pageId])
|
|
1805
1818
|
|
|
1806
1819
|
const handleCreate = async (preset: CreatePagePreset) => {
|
|
1807
|
-
if (
|
|
1820
|
+
if (currentPage === undefined || busy) {
|
|
1808
1821
|
return
|
|
1809
1822
|
}
|
|
1810
1823
|
setBusy(true)
|
|
1811
1824
|
setStatus(`Creating (${preset.label})\u2026`)
|
|
1812
1825
|
const title = `New page (${preset.label.toLowerCase()}) ${new Date().toLocaleTimeString()}`
|
|
1813
1826
|
const result = await pages.create({
|
|
1814
|
-
parent: { type: "page_id", page_id:
|
|
1827
|
+
parent: { type: "page_id", page_id: currentPage.id },
|
|
1815
1828
|
properties: {
|
|
1816
1829
|
title: {
|
|
1817
1830
|
id: "title",
|
|
@@ -1831,7 +1844,7 @@ function CreatePageCard({ context, dataSourceKeys }: CreatePageCardProps) {
|
|
|
1831
1844
|
}
|
|
1832
1845
|
|
|
1833
1846
|
const handleCreateInDataSource = async () => {
|
|
1834
|
-
if (
|
|
1847
|
+
if (currentPage === undefined || busy || trimmedDataSourceId === "") {
|
|
1835
1848
|
return
|
|
1836
1849
|
}
|
|
1837
1850
|
setBusy(true)
|
|
@@ -1860,7 +1873,7 @@ function CreatePageCard({ context, dataSourceKeys }: CreatePageCardProps) {
|
|
|
1860
1873
|
}
|
|
1861
1874
|
|
|
1862
1875
|
const handleCreateForKey = async (key: string) => {
|
|
1863
|
-
if (
|
|
1876
|
+
if (disabled) {
|
|
1864
1877
|
return
|
|
1865
1878
|
}
|
|
1866
1879
|
setBusy(true)
|
|
@@ -2047,7 +2060,7 @@ function CreatePageCard({ context, dataSourceKeys }: CreatePageCardProps) {
|
|
|
2047
2060
|
type="text"
|
|
2048
2061
|
value={pageId}
|
|
2049
2062
|
onChange={event => setPageId(event.target.value)}
|
|
2050
|
-
placeholder={
|
|
2063
|
+
placeholder={currentPage?.id ?? "page_id"}
|
|
2051
2064
|
spellCheck={false}
|
|
2052
2065
|
className="min-w-0 flex-1 rounded-md border border-(--border) bg-(--app-bg) px-2 py-1 font-mono text-[11px] outline-none transition-colors focus:border-(--foreground)"
|
|
2053
2066
|
/>
|
|
@@ -47,9 +47,6 @@ Example row shape:
|
|
|
47
47
|
|
|
48
48
|
If the mapped collection is missing any of those fields, the template shows a setup hint and falls back to built-in sample data so you can still preview the chart locally.
|
|
49
49
|
|
|
50
|
-
## SDK
|
|
50
|
+
## SDK docs
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
- **`useTheme()`** -- returns the host's current theme (`"light"` or `"dark"`)
|
|
54
|
-
- **`useManifest()`** -- returns the declared manifest (data-source keys + property declarations)
|
|
55
|
-
- **`useDataSource(key)`** -- returns `{ items, collectionSchema, propertySchemasById, propertySchemasByKey, isLoading, hasMore, fetchMore, error }`. Each `item` has `{ id, propertiesById, propertiesByKey }`. The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) appear in `propertiesById` / `propertySchemasById`, never in the `*ByKey` views.
|
|
52
|
+
This project uses the public `ncblock` React hooks and data source APIs. After installing dependencies, see `node_modules/ncblock/README.md` for the current API reference and links to the per-category docs.
|
|
@@ -35,9 +35,6 @@ string arrays, and relations. It also includes search, column visibility
|
|
|
35
35
|
controls, density switching, and relation pills that render `-> title` when a
|
|
36
36
|
related page is loaded or `-> uuid` when it is not.
|
|
37
37
|
|
|
38
|
-
## SDK
|
|
38
|
+
## SDK docs
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
- **`useTheme()`** -- returns the host's current theme (`"light"` or `"dark"`)
|
|
42
|
-
- **`useManifest()`** -- returns the declared manifest (data-source keys + property declarations)
|
|
43
|
-
- **`useDataSource(key)`** -- returns `{ items, collectionSchema, propertySchemasById, propertySchemasByKey, isLoading, hasMore, fetchMore, error }`. Each `item` has `{ id, propertiesById, propertiesByKey }`. The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) appear in `propertiesById` / `propertySchemasById`, never in the `*ByKey` views.
|
|
40
|
+
This project uses the public `ncblock` React hooks and data source APIs. After installing dependencies, see `node_modules/ncblock/README.md` for the current API reference and links to the per-category docs.
|