@notionhq/custom-blocks 0.1.18 → 0.1.19

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,gBAAgB,EAEhB,MAAM,4DAA4D,CAAA;AAWnE,OAAO,EAEN,KAAK,WAAW,EAEhB,MAAM,mDAAmD,CAAA;AAc1D,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,8BAA8B,EAC9B,gCAAgC,EAChC,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,aAAa,CAAA;AAKpB,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAG3D;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,IAAI,EAAE,OAAO,CAAA;CACb,CAAA;AAED,qBAAa,aAAa;IACzB,OAAO,CAAC,SAAS,CAIhB;IACD,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,mBAAmB,CAAwB;IACnD,OAAO,CAAC,aAAa,CAAI;IACzB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAEjC;IACD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAE9B;IACD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAE9B;IACD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAEhC;IACD,OAAO,CAAC,QAAQ,CAAC,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e,CAAC;IAa7D,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2C3D;;;;OAIG;IACH,oBAAoB,CAAC,IAAI,EAAE;QAC1B,UAAU,EAAE,gBAAgB,CAAA;QAC5B,MAAM,EAAE,YAAY,CAAA;QACpB,cAAc,EAAE,8BAA8B,CAAA;KAC9C,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAuB7C;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAkE/B"}
1
+ {"version":3,"file":"SandboxBridge.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/SandboxBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EAEhB,MAAM,4DAA4D,CAAA;AAWnE,OAAO,EAEN,KAAK,WAAW,EAEhB,MAAM,mDAAmD,CAAA;AAe1D,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,8BAA8B,EAC9B,gCAAgC,EAChC,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,aAAa,CAAA;AASpB,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAG3D;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,IAAI,EAAE,OAAO,CAAA;CACb,CAAA;AAED,qBAAa,aAAa;IACzB,OAAO,CAAC,SAAS,CAIhB;IACD,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,mBAAmB,CAAwB;IACnD,OAAO,CAAC,aAAa,CAAI;IACzB,OAAO,CAAC,Q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D,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAYrD,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAYrD,SAAS,CAAC,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,eAAe,CAAC;IAa7D,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2C3D;;;;OAIG;IACH,oBAAoB,CAAC,IAAI,EAAE;QAC1B,UAAU,EAAE,gBAAgB,CAAA;QAC5B,MAAM,EAAE,YAAY,CAAA;QACpB,cAAc,EAAE,8BAA8B,CAAA;KAC9C,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAuB7C;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAkE/B"}
@@ -6,6 +6,7 @@ import { CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION } from "../protocol/protocolVersio
6
6
  import * as v from "valibot";
7
7
  import { unreachable } from "../utils.js";
8
8
  import { CUSTOM_BLOCKS_SDK_VERSION } from "../version.js";
9
+ import { NOTION_DARK_BACKGROUND_BASE, NOTION_LIGHT_BACKGROUND_BASE, } from "./appearance.js";
9
10
  import { resolveDataSources } from "./dataSources/resolve.js";
10
11
  import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js";
11
12
  import { createEmptyDataSourceQueryState, } from "./hostState.js";
@@ -104,6 +105,10 @@ export class SandboxBridge {
104
105
  ...hostState,
105
106
  theme: message.theme,
106
107
  };
108
+ syncDocumentAppearance({
109
+ theme: message.theme,
110
+ contrastMode: hostState.contrastMode,
111
+ });
107
112
  this.notify();
108
113
  return;
109
114
  }
@@ -112,6 +117,10 @@ export class SandboxBridge {
112
117
  ...hostState,
113
118
  contrastMode: message.contrastMode,
114
119
  };
120
+ syncDocumentAppearance({
121
+ theme: hostState.theme,
122
+ contrastMode: message.contrastMode,
123
+ });
115
124
  this.notify();
116
125
  return;
117
126
  }
@@ -410,6 +419,10 @@ export class SandboxBridge {
410
419
  dataSources,
411
420
  dataSourceState: {},
412
421
  };
422
+ syncDocumentAppearance({
423
+ theme: message.theme,
424
+ contrastMode: message.contrastMode,
425
+ });
413
426
  this.notify();
414
427
  if (postResult) {
415
428
  const result = {
@@ -699,6 +712,27 @@ export class SandboxBridge {
699
712
  }
700
713
  }
701
714
  SandboxBridge.MAX_LOG_ENTRIES = 100;
715
+ /**
716
+ * Makes the document canvas match the host appearance before acknowledging init.
717
+ *
718
+ * The host reveals the iframe as soon as it receives `initResult.success`. Applying these
719
+ * attributes synchronously prevents the browser's default white canvas from flashing while React
720
+ * mounts a token scope.
721
+ */
722
+ function syncDocumentAppearance(args) {
723
+ if (typeof document === "undefined") {
724
+ return;
725
+ }
726
+ const { theme, contrastMode } = args;
727
+ const root = document.documentElement;
728
+ root.dataset.displayMode = theme;
729
+ root.dataset.contrastMode = contrastMode;
730
+ root.style.colorScheme = theme;
731
+ root.style.backgroundColor =
732
+ theme === "dark"
733
+ ? NOTION_DARK_BACKGROUND_BASE
734
+ : NOTION_LIGHT_BACKGROUND_BASE;
735
+ }
702
736
  /**
703
737
  * `postMessage` cloning creates new objects even for bindings that did not change.
704
738
  * Preserve their resolved object identity so React effects only run for changed bindings.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Background color values used before the NDS token scope mounts.
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.
12
+ */
13
+ export declare const NOTION_DARK_BACKGROUND_BASE = "#191918";
14
+ export declare const NOTION_LIGHT_BACKGROUND_BASE = "#ffffff";
15
+ //# sourceMappingURL=appearance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appearance.d.ts","sourceRoot":"","sources":["../../../../home/runner/work/custom-blocks/custom-blocks/sdk/src/bridge/appearance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,YAAY,CAAA;AACpD,eAAO,MAAM,4BAA4B,YAAY,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Background color values used before the NDS token scope mounts.
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.
12
+ */
13
+ export const NOTION_DARK_BACKGROUND_BASE = "#191918";
14
+ export const NOTION_LIGHT_BACKGROUND_BASE = "#ffffff";
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@
4
4
  *
5
5
  * WARNING: Generated during SDK publish. Do not edit in the published package.
6
6
  */
7
- export const CUSTOM_BLOCKS_SDK_VERSION = "0.1.18"
7
+ export const CUSTOM_BLOCKS_SDK_VERSION = "0.1.19"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,3 +1,4 @@
1
+ import type { NotionContrastMode } from "@notionhq/custom-blocks-protocol/contrast.js"
1
2
  import { DEFAULT_CONTRAST_MODE } from "@notionhq/custom-blocks-protocol/contrast.js"
2
3
  import type {
3
4
  NotionDataSource,
@@ -29,6 +30,7 @@ import type { CustomBlockQueryDataSourceErrorInfo } from "@notionhq/custom-block
29
30
  import type { ResizeMessage } from "@notionhq/custom-blocks-protocol/messages/resize.js"
30
31
  import type { UpdatePageMessage } from "@notionhq/custom-blocks-protocol/messages/updatePage.js"
31
32
  import { CUSTOM_BLOCK_BRIDGE_PROTOCOL_VERSION } from "@notionhq/custom-blocks-protocol/protocolVersion.js"
33
+ import type { NotionTheme } from "@notionhq/custom-blocks-protocol/theme.js"
32
34
  import type { NotionUser } from "@notionhq/custom-blocks-protocol/users/user.js"
33
35
  import * as v from "valibot"
34
36
  import type {
@@ -48,6 +50,10 @@ import type {
48
50
  } from "../types.js"
49
51
  import { unreachable } from "../utils.js"
50
52
  import { CUSTOM_BLOCKS_SDK_VERSION } from "../version.js"
53
+ import {
54
+ NOTION_DARK_BACKGROUND_BASE,
55
+ NOTION_LIGHT_BACKGROUND_BASE,
56
+ } from "./appearance.js"
51
57
  import { resolveDataSources } from "./dataSources/resolve.js"
52
58
  import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js"
53
59
  import {
@@ -291,6 +297,10 @@ export class SandboxBridge {
291
297
  ...hostState,
292
298
  theme: message.theme,
293
299
  }
300
+ syncDocumentAppearance({
301
+ theme: message.theme,
302
+ contrastMode: hostState.contrastMode,
303
+ })
294
304
  this.notify()
295
305
  return
296
306
  }
@@ -300,6 +310,10 @@ export class SandboxBridge {
300
310
  ...hostState,
301
311
  contrastMode: message.contrastMode,
302
312
  }
313
+ syncDocumentAppearance({
314
+ theme: hostState.theme,
315
+ contrastMode: message.contrastMode,
316
+ })
303
317
  this.notify()
304
318
  return
305
319
  }
@@ -550,6 +564,10 @@ export class SandboxBridge {
550
564
  dataSources,
551
565
  dataSourceState: {},
552
566
  }
567
+ syncDocumentAppearance({
568
+ theme: message.theme,
569
+ contrastMode: message.contrastMode,
570
+ })
553
571
  this.notify()
554
572
  if (postResult) {
555
573
  const result: InitResultMessage = {
@@ -885,6 +903,31 @@ export class SandboxBridge {
885
903
  }
886
904
  }
887
905
 
906
+ /**
907
+ * Makes the document canvas match the host appearance before acknowledging init.
908
+ *
909
+ * The host reveals the iframe as soon as it receives `initResult.success`. Applying these
910
+ * attributes synchronously prevents the browser's default white canvas from flashing while React
911
+ * mounts a token scope.
912
+ */
913
+ function syncDocumentAppearance(args: {
914
+ theme: NotionTheme
915
+ contrastMode: NotionContrastMode
916
+ }): void {
917
+ if (typeof document === "undefined") {
918
+ return
919
+ }
920
+ const { theme, contrastMode } = args
921
+ const root = document.documentElement
922
+ root.dataset.displayMode = theme
923
+ root.dataset.contrastMode = contrastMode
924
+ root.style.colorScheme = theme
925
+ root.style.backgroundColor =
926
+ theme === "dark"
927
+ ? NOTION_DARK_BACKGROUND_BASE
928
+ : NOTION_LIGHT_BACKGROUND_BASE
929
+ }
930
+
888
931
  /**
889
932
  * `postMessage` cloning creates new objects even for bindings that did not change.
890
933
  * Preserve their resolved object identity so React effects only run for changed bindings.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Background color values used before the NDS token scope mounts.
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.
12
+ */
13
+ export const NOTION_DARK_BACKGROUND_BASE = "#191918"
14
+ export const NOTION_LIGHT_BACKGROUND_BASE = "#ffffff"