create-ncblock 0.0.33 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ncblock",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "Create a Notion custom view block project.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,9 +14,10 @@ That writes `custom_blocks.json`, `.notion/target.json`, and PATCHes any blocks
14
14
 
15
15
  ## Talking to the host
16
16
 
17
- - Always use the React hooks from `ncblock`. 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
- - `<NotionCustomBlock>` runs `useCustomBlockAutoResize` for you by default — no extra wiring needed. Pass `autoResize={false}` for full-bleed views.
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 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/context.md` — `useCustomBlockContext`, `useTheme`.
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.31"}
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 hooks
31
+ ### SDK docs
32
32
 
33
- - **`useCustomBlockContext()`** -- returns `{ customBlockId, parent, page }` describing the block's location in the document tree
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,16 +1,20 @@
1
1
  import {
2
+ type NotionBlockId,
2
3
  type NotionCreatePagePosition,
3
- NotionCustomBlock,
4
- type NotionCustomBlockContext,
5
4
  type NotionDataSourceId,
6
5
  type NotionPage,
7
6
  type NotionPageId,
8
7
  pages,
8
+ } from "ncblock"
9
+ import {
10
+ NotionCustomBlock,
11
+ useBlockId,
9
12
  useCurrentUser,
10
- useCustomBlockContext,
11
13
  useManifest,
14
+ usePage,
15
+ useParent,
12
16
  useTheme,
13
- } from "ncblock"
17
+ } from "ncblock/react"
14
18
  import React, {
15
19
  Component,
16
20
  useCallback,
@@ -53,7 +57,9 @@ const metaTextClass =
53
57
  const HOST_NO_READY_ERROR_DELAY_SECONDS = 5
54
58
 
55
59
  function App() {
56
- const ctx = useCustomBlockContext()
60
+ const blockId = useBlockId()
61
+ const parent = useParent()
62
+ const page = usePage()
57
63
  const currentUser = useCurrentUser()
58
64
  const hostThemeValue = useTheme()
59
65
  const manifest = useManifest()
@@ -82,11 +88,11 @@ function App() {
82
88
  "--status-color": status.color,
83
89
  } as React.CSSProperties
84
90
 
85
- const contextValue = {
91
+ const blockLocationValue = {
86
92
  theme: hostThemeValue,
87
- customBlockId: ctx?.customBlockId,
88
- parent: ctx?.parent,
89
- page: ctx?.page,
93
+ blockId,
94
+ parent,
95
+ page,
90
96
  currentUser,
91
97
  manifest,
92
98
  }
@@ -156,32 +162,36 @@ function App() {
156
162
  </div>
157
163
  </CollapsibleCard>
158
164
 
159
- {/* Context state */}
165
+ {/* Init state */}
160
166
  <CollapsibleCard
161
167
  label="Init payload"
162
168
  headerExtra={
163
169
  <span className={metaTextClass}>
164
- {Object.keys(contextValue).length} keys
170
+ {Object.keys(blockLocationValue).length} keys
165
171
  </span>
166
172
  }
167
173
  headerActions={
168
174
  <IconButton
169
- label="Copy context JSON"
170
- onClick={() => copy(serializeForCopy(contextValue))}
175
+ label="Copy init JSON"
176
+ onClick={() => copy(serializeForCopy(blockLocationValue))}
171
177
  >
172
178
  <CopyIcon />
173
179
  </IconButton>
174
180
  }
175
181
  >
176
182
  <JsonPanel
177
- value={contextValue}
183
+ value={blockLocationValue}
178
184
  onCopy={copy}
179
185
  defaultExpandedDepth={2}
180
186
  />
181
187
  </CollapsibleCard>
182
188
 
183
189
  {/* Create page */}
184
- <CreatePageCard context={ctx} dataSourceKeys={dataSourceKeys} />
190
+ <CreatePageCard
191
+ blockId={blockId}
192
+ currentPage={page}
193
+ dataSourceKeys={dataSourceKeys}
194
+ />
185
195
 
186
196
  {/* Send message */}
187
197
  <SendMessageCard onSend={send} />
@@ -1653,7 +1663,8 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
1653
1663
  }
1654
1664
 
1655
1665
  type CreatePageCardProps = {
1656
- context: NotionCustomBlockContext | undefined
1666
+ blockId: NotionBlockId | undefined
1667
+ currentPage: { id: NotionPageId } | undefined
1657
1668
  dataSourceKeys: string[]
1658
1669
  }
1659
1670
 
@@ -1664,7 +1675,7 @@ type CreatePagePreset = {
1664
1675
  }
1665
1676
 
1666
1677
  function presetPositions(
1667
- customBlockId: string | undefined,
1678
+ customBlockId: NotionBlockId | undefined,
1668
1679
  ): CreatePagePreset[] {
1669
1680
  const presets: CreatePagePreset[] = [
1670
1681
  {
@@ -1773,7 +1784,7 @@ function pageIconFromInput(raw: string): NotionPage["icon"] | undefined {
1773
1784
  /**
1774
1785
  * Buttons that exercise `sdk.pages.create` at each of the supported positions. Every preset creates
1775
1786
  * a page whose `parent.page_id` is the nearest page ancestor. `position` demonstrates append,
1776
- * prepend, and inserting directly above or below the custom block via `context.customBlockId`.
1787
+ * prepend, and inserting directly above or below the custom block via `useBlockId()`.
1777
1788
  *
1778
1789
  * Two extra affordances exercise the data-source-backed parents:
1779
1790
  * - A free-form input accepts a data source ID and uses `parent: { type: "data_source_id", ... }`
@@ -1782,34 +1793,38 @@ function pageIconFromInput(raw: string): NotionPage["icon"] | undefined {
1782
1793
  * SDK resolve the key to the configured data source ID locally before sending the request to the
1783
1794
  * Notion host.
1784
1795
  */
1785
- function CreatePageCard({ context, dataSourceKeys }: CreatePageCardProps) {
1796
+ function CreatePageCard({
1797
+ blockId,
1798
+ currentPage,
1799
+ dataSourceKeys,
1800
+ }: CreatePageCardProps) {
1786
1801
  const [status, setStatus] = useState<string | null>(null)
1787
1802
  const [busy, setBusy] = useState(false)
1788
1803
  const [dataSourceId, setDataSourceId] = useState("")
1789
1804
  const [pageId, setPageId] = useState("")
1790
1805
  const [trackedPages, setTrackedPages] = useState<TrackedPage[]>([])
1791
- const presets = presetPositions(context?.customBlockId)
1792
- const disabled = context === undefined || busy
1806
+ const presets = presetPositions(blockId)
1807
+ const disabled = currentPage === undefined || busy
1793
1808
  const trimmedDataSourceId = dataSourceId.trim()
1794
1809
  const dataSourceDisabled = disabled || trimmedDataSourceId === ""
1795
1810
  const trimmedPageId = pageId.trim()
1796
1811
  const fetchDisabled = busy || trimmedPageId === ""
1797
1812
 
1798
1813
  useEffect(() => {
1799
- if (context?.page.id && pageId === "") {
1800
- setPageId(context.page.id)
1814
+ if (currentPage !== undefined && pageId === "") {
1815
+ setPageId(currentPage.id)
1801
1816
  }
1802
- }, [context?.page.id, pageId])
1817
+ }, [currentPage, pageId])
1803
1818
 
1804
1819
  const handleCreate = async (preset: CreatePagePreset) => {
1805
- if (context === undefined || busy) {
1820
+ if (currentPage === undefined || busy) {
1806
1821
  return
1807
1822
  }
1808
1823
  setBusy(true)
1809
1824
  setStatus(`Creating (${preset.label})\u2026`)
1810
1825
  const title = `New page (${preset.label.toLowerCase()}) ${new Date().toLocaleTimeString()}`
1811
1826
  const result = await pages.create({
1812
- parent: { type: "page_id", page_id: context.page.id },
1827
+ parent: { type: "page_id", page_id: currentPage.id },
1813
1828
  properties: {
1814
1829
  title: {
1815
1830
  id: "title",
@@ -1829,7 +1844,7 @@ function CreatePageCard({ context, dataSourceKeys }: CreatePageCardProps) {
1829
1844
  }
1830
1845
 
1831
1846
  const handleCreateInDataSource = async () => {
1832
- if (context === undefined || busy || trimmedDataSourceId === "") {
1847
+ if (currentPage === undefined || busy || trimmedDataSourceId === "") {
1833
1848
  return
1834
1849
  }
1835
1850
  setBusy(true)
@@ -1858,7 +1873,7 @@ function CreatePageCard({ context, dataSourceKeys }: CreatePageCardProps) {
1858
1873
  }
1859
1874
 
1860
1875
  const handleCreateForKey = async (key: string) => {
1861
- if (context === undefined || busy) {
1876
+ if (disabled) {
1862
1877
  return
1863
1878
  }
1864
1879
  setBusy(true)
@@ -2045,7 +2060,7 @@ function CreatePageCard({ context, dataSourceKeys }: CreatePageCardProps) {
2045
2060
  type="text"
2046
2061
  value={pageId}
2047
2062
  onChange={event => setPageId(event.target.value)}
2048
- placeholder={context?.page.id ?? "page_id"}
2063
+ placeholder={currentPage?.id ?? "page_id"}
2049
2064
  spellCheck={false}
2050
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)"
2051
2066
  />
@@ -1,4 +1,4 @@
1
- import { NotionCustomBlock } from "ncblock"
1
+ import { NotionCustomBlock } from "ncblock/react"
2
2
  import ReactDOM from "react-dom/client"
3
3
  import "./index.css"
4
4
 
@@ -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 hooks
50
+ ## SDK docs
51
51
 
52
- - **`useCustomBlockContext()`** -- returns `{ customBlockId, parent, page }` describing the block's location in the document tree
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.
@@ -1,11 +1,10 @@
1
+ import type { NotionDataSourcePage, NotionPageId } from "ncblock"
1
2
  import {
2
3
  NotionCustomBlock,
3
- type NotionDataSourcePage,
4
- type NotionPageId,
5
4
  useDataSource,
6
5
  useManifest,
7
6
  useTheme,
8
- } from "ncblock"
7
+ } from "ncblock/react"
9
8
  import React from "react"
10
9
  import ReactDOM from "react-dom/client"
11
10
 
@@ -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 hooks
38
+ ## SDK docs
39
39
 
40
- - **`useCustomBlockContext()`** -- returns `{ customBlockId, parent, page }` describing the block's location in the document tree
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.
@@ -7,15 +7,17 @@ import {
7
7
  useReactTable,
8
8
  } from "@tanstack/react-table"
9
9
  import {
10
- NotionCustomBlock,
11
10
  type NotionPagePropertyInputMap,
12
11
  type NotionPagePropertyInputValue,
13
12
  type NotionPropertySchema,
14
13
  pages,
14
+ } from "ncblock"
15
+ import {
16
+ NotionCustomBlock,
15
17
  useDataSource,
16
18
  useManifest,
17
19
  useTheme,
18
- } from "ncblock"
20
+ } from "ncblock/react"
19
21
  import React from "react"
20
22
  import ReactDOM from "react-dom/client"
21
23