create-ncblock 0.0.32 → 0.0.34

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.32",
3
+ "version": "0.0.34",
4
4
  "description": "Create a Notion custom view block project.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,7 +14,7 @@ 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.
17
+ - Always use the React hooks from `ncblock/react`. Never call `window.parent.postMessage` directly — the SDK owns the protocol.
18
18
  - Render app code inside `<NotionCustomBlock>` so the handshake completes before hooks run.
19
19
  - `<NotionCustomBlock>` runs `useCustomBlockAutoResize` for you by default — no extra wiring needed. Pass `autoResize={false}` for full-bleed views.
20
20
 
@@ -190,6 +190,27 @@ function copyDirectoryContents(
190
190
  }
191
191
  }
192
192
 
193
+ function applyTemplateReplacements(
194
+ contents: string,
195
+ replacements: Record<string, string>,
196
+ ): string {
197
+ let replaced = contents
198
+ for (const [placeholder, value] of Object.entries(replacements)) {
199
+ replaced = replaced.replaceAll(placeholder, value)
200
+ }
201
+ return replaced
202
+ }
203
+
204
+ function writeRenderedFile(args: {
205
+ sourcePath: string
206
+ targetPath: string
207
+ replacements: Record<string, string>
208
+ }) {
209
+ const { sourcePath, targetPath, replacements } = args
210
+ const contents = readFileSync(sourcePath, "utf-8")
211
+ writeFileSync(targetPath, applyTemplateReplacements(contents, replacements))
212
+ }
213
+
193
214
  export function scaffoldTemplate({
194
215
  root,
195
216
  templateDir,
@@ -198,6 +219,12 @@ export function scaffoldTemplate({
198
219
  overwrite = false,
199
220
  sdkDep,
200
221
  }: ScaffoldTemplateOptions) {
222
+ const replacements = { "{{name}}": name }
223
+ const appEntrySource = resolve(templateDir, "src/index.tsx")
224
+ const appEntryTarget = resolve(dest, "src/index.tsx")
225
+ const shouldRenderAppEntry =
226
+ existsSync(appEntrySource) && (overwrite || !existsSync(appEntryTarget))
227
+
201
228
  copyDirectoryContents(templateDir, dest, {
202
229
  overwrite,
203
230
  // README.md and package.json are rendered below with the app name and
@@ -209,6 +236,14 @@ export function scaffoldTemplate({
209
236
  ]),
210
237
  })
211
238
 
239
+ if (shouldRenderAppEntry) {
240
+ writeRenderedFile({
241
+ sourcePath: appEntrySource,
242
+ targetPath: appEntryTarget,
243
+ replacements,
244
+ })
245
+ }
246
+
212
247
  // Scaffolded projects are standalone, not workspace members. If the user
213
248
  // scaffolds inside an existing pnpm workspace (e.g. this repo), pnpm walks
214
249
  // up, finds the workspace root, and the install ends up partial. A local
@@ -221,15 +256,21 @@ export function scaffoldTemplate({
221
256
 
222
257
  const readmeTarget = resolve(dest, "README.md")
223
258
  if (overwrite || !existsSync(readmeTarget)) {
224
- const readme = readFileSync(resolve(templateDir, "README.md"), "utf-8")
225
- writeFileSync(readmeTarget, readme.replace(/\{\{name\}\}/g, name))
259
+ writeRenderedFile({
260
+ sourcePath: resolve(templateDir, "README.md"),
261
+ targetPath: readmeTarget,
262
+ replacements,
263
+ })
226
264
  }
227
265
 
228
266
  const agentsTarget = resolve(dest, "AGENTS.md")
229
267
  if (overwrite || !existsSync(agentsTarget)) {
230
268
  const agentsSource = resolve(root, "scripts/scaffold-assets/AGENTS.md")
231
- const agents = readFileSync(agentsSource, "utf-8")
232
- writeFileSync(agentsTarget, agents.replace(/\{\{name\}\}/g, name))
269
+ writeRenderedFile({
270
+ sourcePath: agentsSource,
271
+ targetPath: agentsTarget,
272
+ replacements,
273
+ })
233
274
  }
234
275
 
235
276
  const pkgPath = resolve(dest, "package.json")
package/sdk-version.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.0.30"}
1
+ {"version":"0.0.32"}
@@ -1,16 +1,18 @@
1
1
  import {
2
2
  type NotionCreatePagePosition,
3
- NotionCustomBlock,
4
3
  type NotionCustomBlockContext,
5
4
  type NotionDataSourceId,
6
5
  type NotionPage,
7
6
  type NotionPageId,
8
7
  pages,
8
+ } from "ncblock"
9
+ import {
10
+ NotionCustomBlock,
9
11
  useCurrentUser,
10
12
  useCustomBlockContext,
11
13
  useManifest,
12
14
  useTheme,
13
- } from "ncblock"
15
+ } from "ncblock/react"
14
16
  import React, {
15
17
  Component,
16
18
  useCallback,
@@ -0,0 +1,33 @@
1
+ :root {
2
+ color-scheme: light dark;
3
+ --background: #ffffff;
4
+ --foreground: #1f1f1f;
5
+ --muted: #5f5e5b;
6
+ --border: #e6e6e6;
7
+ }
8
+
9
+ @media (prefers-color-scheme: dark) {
10
+ :root {
11
+ --background: #191919;
12
+ --foreground: #f1f1ef;
13
+ --muted: #b7b6b2;
14
+ --border: #3f3f3c;
15
+ }
16
+ }
17
+
18
+ body {
19
+ background: var(--background);
20
+ }
21
+
22
+ main {
23
+ box-sizing: border-box;
24
+ padding: 8px 24px;
25
+ border: 1px solid var(--border);
26
+ border-radius: 12px;
27
+ color: var(--foreground);
28
+ background: var(--background);
29
+ }
30
+
31
+ p {
32
+ color: var(--muted);
33
+ }
@@ -1,8 +1,16 @@
1
- import { NotionCustomBlock } from "ncblock"
1
+ import { NotionCustomBlock } from "ncblock/react"
2
2
  import ReactDOM from "react-dom/client"
3
+ import "./index.css"
3
4
 
4
5
  function App() {
5
- return <h1>Edit me in index.tsx</h1>
6
+ return (
7
+ <main>
8
+ <h3>{"{{name}}"}</h3>
9
+ <p>
10
+ Edit <code>src/index.tsx</code> and then deploy using <code>ntn</code>
11
+ </p>
12
+ </main>
13
+ )
6
14
  }
7
15
 
8
16
  ReactDOM.createRoot(document.getElementById("root")!).render(
@@ -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
 
@@ -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