@notionhq/custom-blocks 0.3.4 → 0.3.5
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 +2 -0
- package/dist/bridge/SandboxBridge.d.ts +28 -507
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +89 -686
- package/dist/bridge/getBridge.d.ts +3 -0
- package/dist/bridge/getBridge.d.ts.map +1 -0
- package/dist/bridge/getBridge.js +8 -0
- package/dist/bridge/{SandboxInitialization.d.ts → initialization/SandboxInitialization.d.ts} +5 -6
- package/dist/bridge/initialization/SandboxInitialization.d.ts.map +1 -0
- package/dist/bridge/{SandboxInitialization.js → initialization/SandboxInitialization.js} +6 -12
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js +2 -2
- package/dist/context/applyContextMessage.d.ts +6 -0
- package/dist/context/applyContextMessage.d.ts.map +1 -0
- package/dist/context/applyContextMessage.js +35 -0
- package/dist/{bridge/appearance.d.ts → context/backgroundColors.d.ts} +1 -1
- package/dist/context/backgroundColors.d.ts.map +1 -0
- package/dist/context/getBlockId.d.ts +7 -0
- package/dist/context/getBlockId.d.ts.map +1 -0
- package/dist/context/getBlockId.js +8 -0
- package/dist/context/getContrastMode.d.ts +7 -0
- package/dist/context/getContrastMode.d.ts.map +1 -0
- package/dist/context/getContrastMode.js +8 -0
- package/dist/context/getInitializedHostState.d.ts +3 -0
- package/dist/context/getInitializedHostState.d.ts.map +1 -0
- package/dist/context/getInitializedHostState.js +8 -0
- package/dist/context/getPage.d.ts +7 -0
- package/dist/context/getPage.d.ts.map +1 -0
- package/dist/context/getPage.js +8 -0
- package/dist/context/getParent.d.ts +7 -0
- package/dist/context/getParent.d.ts.map +1 -0
- package/dist/context/getParent.js +8 -0
- package/dist/context/getTheme.d.ts +7 -0
- package/dist/context/getTheme.d.ts.map +1 -0
- package/dist/context/getTheme.js +8 -0
- package/dist/context/hostState.d.ts +15 -0
- package/dist/context/hostState.d.ts.map +1 -0
- package/dist/context/index.d.ts +42 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +41 -0
- package/dist/context/react/useBlockId.d.ts +11 -0
- package/dist/context/react/useBlockId.d.ts.map +1 -0
- package/dist/context/react/useBlockId.js +14 -0
- package/dist/context/react/useContrastMode.d.ts +11 -0
- package/dist/context/react/useContrastMode.d.ts.map +1 -0
- package/dist/context/react/useContrastMode.js +14 -0
- package/dist/context/react/usePage.d.ts +12 -0
- package/dist/context/react/usePage.d.ts.map +1 -0
- package/dist/context/react/usePage.js +15 -0
- package/dist/context/react/useParent.d.ts +12 -0
- package/dist/context/react/useParent.d.ts.map +1 -0
- package/dist/context/react/useParent.js +15 -0
- package/dist/context/react/useTheme.d.ts +11 -0
- package/dist/context/react/useTheme.d.ts.map +1 -0
- package/dist/context/react/useTheme.js +14 -0
- package/dist/context/subscribeToBlockId.d.ts +8 -0
- package/dist/context/subscribeToBlockId.d.ts.map +1 -0
- package/dist/context/subscribeToBlockId.js +8 -0
- package/dist/context/subscribeToContext.d.ts +12 -0
- package/dist/context/subscribeToContext.d.ts.map +1 -0
- package/dist/context/subscribeToContext.js +35 -0
- package/dist/context/subscribeToContrastMode.d.ts +8 -0
- package/dist/context/subscribeToContrastMode.d.ts.map +1 -0
- package/dist/context/subscribeToContrastMode.js +8 -0
- package/dist/context/subscribeToPage.d.ts +8 -0
- package/dist/context/subscribeToPage.d.ts.map +1 -0
- package/dist/context/subscribeToPage.js +8 -0
- package/dist/context/subscribeToParent.d.ts +8 -0
- package/dist/context/subscribeToParent.d.ts.map +1 -0
- package/dist/context/subscribeToParent.js +8 -0
- package/dist/context/subscribeToTheme.d.ts +8 -0
- package/dist/context/subscribeToTheme.d.ts.map +1 -0
- package/dist/context/subscribeToTheme.js +8 -0
- package/dist/context/syncDocumentAppearance.d.ts +14 -0
- package/dist/context/syncDocumentAppearance.d.ts.map +1 -0
- package/dist/context/syncDocumentAppearance.js +22 -0
- package/dist/dataSources/bridge/applyDataSourceBindings.d.ts +4 -0
- package/dist/dataSources/bridge/applyDataSourceBindings.d.ts.map +1 -0
- package/dist/dataSources/bridge/applyDataSourceBindings.js +17 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts +17 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -0
- package/dist/{bridge/dataSources/query.js → dataSources/bridge/resolveDataSourceQuery.js} +13 -17
- package/dist/dataSources/bridge/resolveDataSources.d.ts +15 -0
- package/dist/dataSources/bridge/resolveDataSources.d.ts.map +1 -0
- package/dist/{bridge/dataSources/resolve.js → dataSources/bridge/resolveDataSources.js} +10 -11
- package/dist/{bridge/dataSources → dataSources/bridge}/resolveSorts.d.ts +3 -3
- package/dist/dataSources/bridge/resolveSorts.d.ts.map +1 -0
- package/dist/{bridge/dataSources → dataSources/bridge}/resolveSorts.js +3 -3
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts +16 -0
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts.map +1 -0
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.js +19 -0
- package/dist/dataSources/createDataSourcePage.d.ts +4 -0
- package/dist/dataSources/createDataSourcePage.d.ts.map +1 -0
- package/dist/dataSources/createDataSourcePage.js +40 -0
- package/dist/dataSources/dataSourceInaccessibleError.d.ts +4 -0
- package/dist/dataSources/dataSourceInaccessibleError.d.ts.map +1 -0
- package/dist/dataSources/dataSourceInaccessibleError.js +9 -0
- package/dist/{bridge/dataSources/queryFilter.d.ts → dataSources/filters/resolveFilter.d.ts} +4 -4
- package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -0
- package/dist/{bridge/dataSources/queryFilter.js → dataSources/filters/resolveFilter.js} +8 -4
- package/dist/dataSources/filters/types.d.ts +66 -0
- package/dist/dataSources/filters/types.d.ts.map +1 -0
- package/dist/dataSources/getDataSourcePage.d.ts +4 -0
- package/dist/dataSources/getDataSourcePage.d.ts.map +1 -0
- package/dist/dataSources/getDataSourcePage.js +18 -0
- package/dist/dataSources/index.d.ts +9 -0
- package/dist/dataSources/index.d.ts.map +1 -0
- package/dist/dataSources/index.js +8 -0
- package/dist/{bridge/dataSources → dataSources/properties}/resolvePropertyAddress.d.ts +1 -1
- package/dist/dataSources/properties/resolvePropertyAddress.d.ts.map +1 -0
- package/dist/{bridge/dataSources/resolveProperty.d.ts → dataSources/properties/resolvePropertyWriteMapForDataSource.d.ts} +4 -4
- package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.d.ts.map +1 -0
- package/dist/{bridge/dataSources/resolveProperty.js → dataSources/properties/resolvePropertyWriteMapForDataSource.js} +2 -2
- package/dist/dataSources/queryDataSource.d.ts +3 -0
- package/dist/dataSources/queryDataSource.d.ts.map +1 -0
- package/dist/dataSources/queryDataSource.js +56 -0
- package/dist/dataSources/react/useDataSource.d.ts.map +1 -0
- package/dist/{react → dataSources/react}/useDataSource.js +2 -2
- package/dist/dataSources/resolvePageDataSource.d.ts +16 -0
- package/dist/dataSources/resolvePageDataSource.d.ts.map +1 -0
- package/dist/dataSources/resolvePageDataSource.js +43 -0
- package/dist/{bridge/dataSources/subscribe.d.ts → dataSources/subscribeToDataSource.d.ts} +3 -3
- package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -0
- package/dist/dataSources/subscribeToDataSource.js +109 -0
- package/dist/dataSources/types.d.ts +47 -0
- package/dist/dataSources/types.d.ts.map +1 -0
- package/dist/dataSources/types.js +1 -0
- package/dist/index.d.ts +38 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/initialization/NotInIframeError.d.ts +12 -0
- package/dist/initialization/NotInIframeError.d.ts.map +1 -0
- package/dist/{initTypes.js → initialization/NotInIframeError.js} +3 -3
- package/dist/initialization/getInitBindingError.d.ts +5 -0
- package/dist/initialization/getInitBindingError.d.ts.map +1 -0
- package/dist/initialization/getInitBindingError.js +26 -0
- package/dist/{init.d.ts → initialization/initCustomBlock.d.ts} +2 -3
- package/dist/initialization/initCustomBlock.d.ts.map +1 -0
- package/dist/{init.js → initialization/initCustomBlock.js} +2 -3
- package/dist/{react → initialization/react}/useCustomBlockInit.d.ts +2 -2
- package/dist/initialization/react/useCustomBlockInit.d.ts.map +1 -0
- package/dist/{react → initialization/react}/useCustomBlockInit.js +1 -1
- package/dist/initialization/resolveInitialState.d.ts +13 -0
- package/dist/initialization/resolveInitialState.d.ts.map +1 -0
- package/dist/initialization/resolveInitialState.js +28 -0
- package/dist/initialization/types.d.ts +20 -0
- package/dist/initialization/types.d.ts.map +1 -0
- package/dist/initialization/types.js +1 -0
- package/dist/layout/autoResize.d.ts.map +1 -0
- package/dist/{autoResize.js → layout/autoResize.js} +2 -2
- package/dist/layout/getInitialContentHeight.d.ts +2 -0
- package/dist/layout/getInitialContentHeight.d.ts.map +1 -0
- package/dist/layout/getInitialContentHeight.js +10 -0
- package/dist/layout/postResize.d.ts +2 -0
- package/dist/layout/postResize.d.ts.map +1 -0
- package/dist/layout/postResize.js +12 -0
- package/dist/manifest/getManifest.d.ts +7 -0
- package/dist/manifest/getManifest.d.ts.map +1 -0
- package/dist/manifest/getManifest.js +8 -0
- package/dist/manifest/react/useManifest.d.ts +15 -0
- package/dist/manifest/react/useManifest.d.ts.map +1 -0
- package/dist/manifest/react/useManifest.js +18 -0
- package/dist/{bridge → manifest}/readLocalManifest.d.ts +3 -3
- package/dist/manifest/readLocalManifest.d.ts.map +1 -0
- package/dist/{bridge → manifest}/readLocalManifest.js +2 -2
- package/dist/manifest/subscribeToManifest.d.ts +8 -0
- package/dist/manifest/subscribeToManifest.d.ts.map +1 -0
- package/dist/manifest/subscribeToManifest.js +8 -0
- package/dist/manifest/types.d.ts +6 -0
- package/dist/manifest/types.d.ts.map +1 -0
- package/dist/manifest/types.js +1 -0
- package/dist/navigation/index.d.ts +5 -0
- package/dist/navigation/index.d.ts.map +1 -0
- package/dist/navigation/index.js +4 -0
- package/dist/navigation/openExternalUrl.d.ts +4 -0
- package/dist/navigation/openExternalUrl.d.ts.map +1 -0
- package/dist/navigation/openExternalUrl.js +5 -0
- package/dist/navigation/types.d.ts +4 -0
- package/dist/navigation/types.d.ts.map +1 -0
- package/dist/navigation/types.js +1 -0
- package/dist/pages/bridge/buildCreatePageRequest.d.ts +16 -0
- package/dist/pages/bridge/buildCreatePageRequest.d.ts.map +1 -0
- package/dist/pages/bridge/buildCreatePageRequest.js +38 -0
- package/dist/pages/bridge/getPageForDataSource.d.ts +9 -0
- package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -0
- package/dist/pages/bridge/getPageForDataSource.js +13 -0
- package/dist/pages/bridge/makeUpdatePageByKey.d.ts +8 -0
- package/dist/pages/bridge/makeUpdatePageByKey.d.ts.map +1 -0
- package/dist/{bridge/page.js → pages/bridge/makeUpdatePageByKey.js} +0 -12
- package/dist/pages/bridge/resolveCreatePageDestination.d.ts +24 -0
- package/dist/pages/bridge/resolveCreatePageDestination.d.ts.map +1 -0
- package/dist/pages/bridge/resolveCreatePageDestination.js +45 -0
- package/dist/pages/bridge/sendCreatePageRequest.d.ts +11 -0
- package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -0
- package/dist/pages/bridge/sendCreatePageRequest.js +12 -0
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +77 -0
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -0
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +25 -0
- package/dist/pages/bridge/toNotionPageFromBridgePage.d.ts +11 -0
- package/dist/pages/bridge/toNotionPageFromBridgePage.d.ts.map +1 -0
- package/dist/pages/bridge/toNotionPageFromBridgePage.js +12 -0
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts +4 -0
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -0
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +92 -0
- package/dist/pages/bridge/updateNotionPageFromBridgePage.d.ts +4 -0
- package/dist/pages/bridge/updateNotionPageFromBridgePage.d.ts.map +1 -0
- package/dist/pages/bridge/updateNotionPageFromBridgePage.js +4 -0
- package/dist/pages/bridge/updatePage.d.ts +12 -0
- package/dist/pages/bridge/updatePage.d.ts.map +1 -0
- package/dist/pages/bridge/updatePage.js +60 -0
- package/dist/pages/createPage.d.ts +3 -0
- package/dist/pages/createPage.d.ts.map +1 -0
- package/dist/pages/createPage.js +27 -0
- package/dist/pages/getPage.d.ts +7 -0
- package/dist/pages/getPage.d.ts.map +1 -0
- package/dist/pages/getPage.js +11 -0
- package/dist/pages/index.d.ts +9 -0
- package/dist/pages/index.d.ts.map +1 -0
- package/dist/pages/index.js +8 -0
- package/dist/pages/makeNotionPage.d.ts +11 -0
- package/dist/pages/makeNotionPage.d.ts.map +1 -0
- package/dist/pages/makeNotionPage.js +34 -0
- package/dist/pages/openPage.d.ts +7 -0
- package/dist/pages/openPage.d.ts.map +1 -0
- package/dist/pages/openPage.js +7 -0
- package/dist/pages/parent.d.ts +7 -0
- package/dist/pages/parent.d.ts.map +1 -0
- package/dist/pages/parent.js +1 -0
- package/dist/pages/properties/getPropertyById.d.ts +6 -0
- package/dist/pages/properties/getPropertyById.d.ts.map +1 -0
- package/dist/pages/properties/getPropertyById.js +3 -0
- package/dist/pages/properties/getPropertyByKey.d.ts +9 -0
- package/dist/pages/properties/getPropertyByKey.d.ts.map +1 -0
- package/dist/pages/properties/getPropertyByKey.js +16 -0
- package/dist/pages/types.d.ts +208 -0
- package/dist/pages/types.d.ts.map +1 -0
- package/dist/pages/types.js +1 -0
- package/dist/protocol/{messages/updatePage.d.ts → compatibility/protocol3To5/bridgePage.d.ts} +32 -22
- package/dist/protocol/compatibility/protocol3To5/bridgePage.js +21 -0
- package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourcePage.js +1 -1
- package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourceValue.js +2 -2
- package/dist/protocol/context/containingPage.d.ts +31 -0
- package/dist/protocol/context/containingPage.js +18 -0
- package/dist/protocol/{messages → context/messages}/pageChanged.js +1 -1
- package/dist/protocol/{parent.d.ts → context/parent.d.ts} +10 -0
- package/dist/protocol/context/parent.js +31 -0
- package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +164 -0
- package/dist/protocol/dataSources/bridgeDataSourceBinding.js +25 -0
- package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +148 -0
- package/dist/protocol/dataSources/bridgeDataSourceBindings.js +3 -0
- package/dist/protocol/dataSources/collectionPointer.d.ts +7 -0
- package/dist/protocol/dataSources/collectionPointer.js +7 -0
- package/dist/protocol/dataSources/collectionSchema.d.ts +144 -0
- package/dist/protocol/dataSources/collectionSchema.js +12 -0
- package/dist/protocol/dataSources/errors.d.ts +2 -2
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.d.ts +505 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.js +8 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.d.ts +253 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.js +69 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceSort.d.ts +11 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceSort.js +8 -0
- package/dist/protocol/dataSources/filters/checkboxFilterOperator.d.ts +7 -0
- package/dist/protocol/dataSources/filters/checkboxFilterOperator.js +5 -0
- package/dist/protocol/dataSources/filters/containsFilterOperator.d.ts +13 -0
- package/dist/protocol/dataSources/filters/containsFilterOperator.js +9 -0
- package/dist/protocol/dataSources/filters/createdByFilterOperator.d.ts +17 -0
- package/dist/protocol/dataSources/filters/createdByFilterOperator.js +11 -0
- package/dist/protocol/dataSources/filters/dateFilterOperator.d.ts +47 -0
- package/dist/protocol/dataSources/filters/dateFilterOperator.js +73 -0
- package/dist/protocol/dataSources/filters/emptyOperator.d.ts +6 -0
- package/dist/protocol/dataSources/filters/emptyOperator.js +5 -0
- package/dist/protocol/dataSources/filters/numberFilterOperator.d.ts +19 -0
- package/dist/protocol/dataSources/filters/numberFilterOperator.js +11 -0
- package/dist/protocol/dataSources/filters/optionFilterOperator.d.ts +11 -0
- package/dist/protocol/dataSources/filters/optionFilterOperator.js +8 -0
- package/dist/protocol/dataSources/filters/peopleFilterOperator.d.ts +23 -0
- package/dist/protocol/dataSources/filters/peopleFilterOperator.js +11 -0
- package/dist/protocol/dataSources/filters/relationFilterOperator.d.ts +11 -0
- package/dist/protocol/dataSources/filters/relationFilterOperator.js +12 -0
- package/dist/protocol/dataSources/filters/statusFilterOperator.d.ts +15 -0
- package/dist/protocol/dataSources/filters/statusFilterOperator.js +7 -0
- package/dist/protocol/dataSources/filters/statusGroupFilterOperator.d.ts +9 -0
- package/dist/protocol/dataSources/filters/statusGroupFilterOperator.js +18 -0
- package/dist/protocol/dataSources/filters/stringOrStringArray.d.ts +2 -0
- package/dist/protocol/dataSources/filters/stringOrStringArray.js +5 -0
- package/dist/protocol/dataSources/filters/textFilterOperator.d.ts +19 -0
- package/dist/protocol/dataSources/filters/textFilterOperator.js +11 -0
- package/dist/protocol/dataSources/makeBridgeDataSourceBinding.d.ts +6 -0
- package/dist/protocol/dataSources/makeBridgeDataSourceBinding.js +6 -0
- package/dist/protocol/{messages → dataSources/messages}/dataSourcesChanged.d.ts +1 -0
- package/dist/protocol/{messages → dataSources/messages}/dataSourcesChanged.js +2 -2
- package/dist/protocol/{messages/queryDataSourceResult.d.ts → dataSources/messages/queryDataSource.d.ts} +525 -2
- package/dist/protocol/{messages/queryDataSourceResult.js → dataSources/messages/queryDataSource.js} +22 -2
- package/dist/protocol/dataSources/notionDataSource.d.ts +309 -0
- package/dist/protocol/dataSources/notionDataSource.js +38 -0
- package/dist/protocol/dataSources/resolveDataSourceBinding.d.ts +32 -0
- package/dist/protocol/dataSources/resolveDataSourceBinding.js +33 -0
- package/dist/protocol/{messages → handshake}/connect.d.ts +4 -0
- package/dist/protocol/{messages → handshake}/connect.js +2 -2
- package/dist/protocol/{messages → handshake}/init.d.ts +6 -1
- package/dist/protocol/{messages → handshake}/init.js +10 -10
- package/dist/protocol/{messages → handshake}/initResult.d.ts +1 -1
- package/dist/protocol/{messages → handshake}/isInitHandshakeMessage.d.ts +2 -2
- package/dist/protocol/index.d.ts +150 -54
- package/dist/protocol/index.js +73 -54
- package/dist/protocol/manifest/capabilities.d.ts +37 -0
- package/dist/protocol/manifest/capabilities.js +13 -0
- package/dist/protocol/{manifest.d.ts → manifest/manifest.d.ts} +12 -2
- package/dist/protocol/{manifest.js → manifest/manifest.js} +8 -1
- package/dist/protocol/messages/hostToSandbox.d.ts +12 -0
- package/dist/protocol/messages/hostToSandbox.js +15 -15
- package/dist/protocol/messages/messagePayload.d.ts +1 -1
- package/dist/protocol/messages/sandboxToHost.d.ts +232 -8
- package/dist/protocol/messages/sandboxToHost.js +12 -12
- package/dist/protocol/{messages → navigation}/openExternalUrl.d.ts +1 -1
- package/dist/protocol/{messages/createPage.d.ts → pages/bridgePage.d.ts} +67 -65
- package/dist/protocol/pages/bridgePage.js +25 -0
- package/dist/protocol/pages/makeBridgePage.d.ts +4 -0
- package/dist/protocol/pages/makeBridgePage.js +12 -0
- package/dist/protocol/{messages/createPageResult.d.ts → pages/messages/createPage.d.ts} +500 -2
- package/dist/protocol/pages/messages/createPage.js +104 -0
- package/dist/protocol/{messages → pages/messages}/getPage.d.ts +2 -2
- package/dist/protocol/{messages → pages/messages}/getPage.js +4 -3
- package/dist/protocol/{messages → pages/messages}/openPage.d.ts +2 -2
- package/dist/protocol/{messages → pages/messages}/openPage.js +1 -1
- package/dist/protocol/{messages/updatePageResult.d.ts → pages/messages/updatePage.d.ts} +272 -2
- package/dist/protocol/{messages/updatePageResult.js → pages/messages/updatePage.js} +26 -2
- package/dist/protocol/pages/pageAppearance.d.ts +62 -0
- package/dist/protocol/pages/pageAppearance.js +34 -0
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +433 -0
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.js +4 -0
- package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +217 -0
- package/dist/protocol/pages/properties/bridgePagePropertyValue.js +144 -0
- package/dist/protocol/pages/properties/dateInput.d.ts +45 -0
- package/dist/protocol/pages/properties/dateInput.js +23 -0
- package/dist/protocol/pages/properties/fileInput.d.ts +16 -0
- package/dist/protocol/pages/properties/fileInput.js +16 -0
- package/dist/protocol/pages/properties/metadataActor.d.ts +6 -0
- package/dist/protocol/pages/properties/metadataActor.js +7 -0
- package/dist/protocol/pages/properties/placeInput.d.ts +10 -0
- package/dist/protocol/pages/properties/placeInput.js +10 -0
- package/dist/protocol/pages/properties/relationInput.d.ts +5 -0
- package/dist/protocol/pages/properties/relationInput.js +2 -0
- package/dist/protocol/pages/properties/richText.d.ts +3 -0
- package/dist/protocol/pages/properties/richText.js +2 -0
- package/dist/protocol/pages/properties/selectOption.d.ts +13 -0
- package/dist/protocol/pages/properties/selectOption.js +16 -0
- package/dist/protocol/pages/properties/userInput.d.ts +10 -0
- package/dist/protocol/pages/properties/userInput.js +13 -0
- package/dist/protocol/users/bridgeUser.d.ts +12 -0
- package/dist/protocol/users/bridgeUser.js +12 -0
- package/dist/protocol/users/{user.d.ts → bridgeUserList.d.ts} +2 -15
- package/dist/protocol/users/bridgeUserList.js +10 -0
- package/dist/protocol/users/makeBridgeUser.d.ts +4 -0
- package/dist/protocol/users/makeBridgeUser.js +11 -0
- package/dist/protocol/{messages → users/messages}/currentUserChanged.js +2 -2
- package/dist/protocol/{messages → users/messages}/getUser.d.ts +2 -2
- package/dist/protocol/{messages → users/messages}/getUser.js +3 -2
- package/dist/protocol/{messages → users/messages}/listUsers.d.ts +2 -2
- package/dist/protocol/{messages → users/messages}/listUsers.js +2 -2
- package/dist/protocol/users/userId.d.ts +3 -0
- package/dist/protocol/users/userId.js +2 -0
- package/dist/protocol/{errors.d.ts → utils/errors.d.ts} +6 -0
- package/dist/protocol/utils/errors.js +11 -0
- package/dist/protocol/utils/nullableStringSchema.d.ts +2 -0
- package/dist/protocol/utils/nullableStringSchema.js +2 -0
- package/dist/react/DebugMessageLog.d.ts.map +1 -1
- package/dist/react/DebugMessageLog.js +3 -2
- package/dist/react/InitializationErrorDetails.d.ts +7 -0
- package/dist/react/InitializationErrorDetails.d.ts.map +1 -0
- package/dist/react/InitializationErrorDetails.js +9 -0
- package/{src/react/NotionCustomBlock.css → dist/react/InitializationErrorScreen.css} +0 -20
- package/dist/react/MissingHostCommand.d.ts +2 -0
- package/dist/react/MissingHostCommand.d.ts.map +1 -0
- package/dist/react/MissingHostCommand.js +20 -0
- package/dist/react/MissingHostScreen.css +85 -0
- package/dist/react/MissingHostScreen.d.ts +7 -0
- package/dist/react/MissingHostScreen.d.ts.map +1 -0
- package/dist/react/MissingHostScreen.js +7 -0
- package/dist/react/NotionCustomBlock.d.ts +2 -2
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.js +14 -35
- package/dist/react/NotionTokenScope.d.ts.map +1 -1
- package/dist/react/NotionTokenScope.js +2 -1
- package/dist/react/index.d.ts +14 -5
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +11 -5
- package/dist/users/bridge/toNotionUserFromBridgeUser.d.ts +4 -0
- package/dist/users/bridge/toNotionUserFromBridgeUser.d.ts.map +1 -0
- package/dist/users/bridge/toNotionUserFromBridgeUser.js +10 -0
- package/dist/users/getCurrentUser.d.ts +7 -0
- package/dist/users/getCurrentUser.d.ts.map +1 -0
- package/dist/users/getCurrentUser.js +8 -0
- package/dist/users/getUser.d.ts +7 -0
- package/dist/users/getUser.d.ts.map +1 -0
- package/dist/users/getUser.js +11 -0
- package/dist/users/index.d.ts +7 -0
- package/dist/users/index.d.ts.map +1 -0
- package/dist/users/index.js +6 -0
- package/dist/users/listUsers.d.ts +6 -0
- package/dist/users/listUsers.d.ts.map +1 -0
- package/dist/users/listUsers.js +19 -0
- package/dist/users/react/useCurrentUser.d.ts +12 -0
- package/dist/users/react/useCurrentUser.d.ts.map +1 -0
- package/dist/users/react/useCurrentUser.js +15 -0
- package/dist/users/subscribeToCurrentUser.d.ts +8 -0
- package/dist/users/subscribeToCurrentUser.d.ts.map +1 -0
- package/dist/users/subscribeToCurrentUser.js +8 -0
- package/dist/users/types.d.ts +41 -0
- package/dist/users/types.d.ts.map +1 -0
- package/dist/users/types.js +1 -0
- package/dist/utils/notifyListener.d.ts.map +1 -0
- package/dist/utils/typeUtils.d.ts.map +1 -0
- package/dist/utils/typeUtils.js +1 -0
- package/dist/{utils.d.ts → utils/unreachable.d.ts} +1 -1
- package/dist/utils/unreachable.d.ts.map +1 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/{version.js → utils/version.js} +1 -1
- package/docs/block-location.md +3 -2
- package/docs/capabilities.md +111 -0
- package/docs/data-sources.md +6 -2
- package/docs/deployment.md +2 -1
- package/docs/errors.md +9 -0
- package/docs/lifecycle.md +6 -6
- package/docs/pages.md +0 -3
- package/docs/users.md +3 -0
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +159 -899
- package/src/bridge/getBridge.ts +10 -0
- package/src/bridge/{SandboxInitialization.ts → initialization/SandboxInitialization.ts} +11 -21
- package/src/bridge.ts +2 -2
- package/src/context/applyContextMessage.ts +55 -0
- package/src/context/getBlockId.ts +10 -0
- package/src/context/getContrastMode.ts +10 -0
- package/src/context/getInitializedHostState.ts +14 -0
- package/src/context/getPage.ts +10 -0
- package/src/context/getParent.ts +10 -0
- package/src/context/getTheme.ts +10 -0
- package/src/context/hostState.ts +17 -0
- package/src/context/index.ts +42 -0
- package/src/context/react/useBlockId.ts +16 -0
- package/src/context/react/useContrastMode.ts +16 -0
- package/src/context/react/usePage.ts +17 -0
- package/src/context/react/useParent.ts +17 -0
- package/src/context/react/useTheme.ts +16 -0
- package/src/context/subscribeToBlockId.ts +13 -0
- package/src/context/subscribeToContext.ts +42 -0
- package/src/context/subscribeToContrastMode.ts +13 -0
- package/src/context/subscribeToPage.ts +13 -0
- package/src/context/subscribeToParent.ts +13 -0
- package/src/context/subscribeToTheme.ts +13 -0
- package/src/context/syncDocumentAppearance.ts +31 -0
- package/src/dataSources/bridge/applyDataSourceBindings.ts +25 -0
- package/src/{bridge/dataSources/query.ts → dataSources/bridge/resolveDataSourceQuery.ts} +26 -41
- package/src/dataSources/bridge/resolveDataSources.ts +44 -0
- package/src/{bridge/dataSources → dataSources/bridge}/resolveSorts.ts +8 -10
- package/src/dataSources/bridge/reuseDataSourcesForUnchangedBindings.ts +32 -0
- package/src/dataSources/createDataSourcePage.ts +46 -0
- package/src/dataSources/dataSourceInaccessibleError.ts +13 -0
- package/src/{bridge/dataSources/queryFilter.ts → dataSources/filters/resolveFilter.ts} +14 -16
- package/src/dataSources/filters/types.ts +77 -0
- package/src/dataSources/getDataSourcePage.ts +24 -0
- package/src/dataSources/index.ts +9 -0
- package/src/{bridge/dataSources → dataSources/properties}/resolvePropertyAddress.ts +1 -1
- package/src/{bridge/dataSources/resolveProperty.ts → dataSources/properties/resolvePropertyWriteMapForDataSource.ts} +5 -5
- package/src/dataSources/queryDataSource.ts +62 -0
- package/src/{react → dataSources/react}/useDataSource.ts +2 -2
- package/src/dataSources/resolvePageDataSource.ts +57 -0
- package/src/dataSources/subscribeToDataSource.ts +143 -0
- package/src/dataSources/types.ts +53 -0
- package/src/index.ts +70 -68
- package/src/initialization/NotInIframeError.ts +23 -0
- package/src/initialization/getInitBindingError.ts +39 -0
- package/src/initialization/initCustomBlock.ts +10 -0
- package/src/{react → initialization/react}/useCustomBlockInit.ts +3 -2
- package/src/initialization/resolveInitialState.ts +37 -0
- package/src/initialization/types.ts +20 -0
- package/src/{autoResize.ts → layout/autoResize.ts} +2 -2
- package/src/layout/getInitialContentHeight.ts +10 -0
- package/src/layout/postResize.ts +15 -0
- package/src/manifest/getManifest.ts +10 -0
- package/src/manifest/react/useManifest.ts +20 -0
- package/src/{bridge → manifest}/readLocalManifest.ts +5 -7
- package/src/manifest/subscribeToManifest.ts +13 -0
- package/src/manifest/types.ts +7 -0
- package/src/navigation/index.ts +5 -0
- package/src/navigation/openExternalUrl.ts +9 -0
- package/src/navigation/types.ts +10 -0
- package/src/pages/bridge/buildCreatePageRequest.ts +49 -0
- package/src/pages/bridge/getPageForDataSource.ts +25 -0
- package/src/pages/bridge/makeUpdatePageByKey.ts +25 -0
- package/src/pages/bridge/resolveCreatePageDestination.ts +75 -0
- package/src/pages/bridge/sendCreatePageRequest.ts +22 -0
- package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +28 -0
- package/src/pages/bridge/toNotionPageFromBridgePage.ts +22 -0
- package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +97 -0
- package/src/pages/bridge/updateNotionPageFromBridgePage.ts +10 -0
- package/src/pages/bridge/updatePage.ts +90 -0
- package/src/pages/createPage.ts +31 -0
- package/src/pages/getPage.ts +14 -0
- package/src/pages/index.ts +9 -0
- package/src/pages/makeNotionPage.ts +55 -0
- package/src/pages/openPage.ts +13 -0
- package/src/pages/parent.ts +14 -0
- package/src/pages/properties/getPropertyById.ts +12 -0
- package/src/pages/properties/getPropertyByKey.ts +30 -0
- package/src/pages/types.ts +189 -0
- package/src/react/DebugMessageLog.tsx +6 -2
- package/src/react/InitializationErrorDetails.tsx +30 -0
- package/{dist/react/NotionCustomBlock.css → src/react/InitializationErrorScreen.css} +0 -20
- package/src/react/MissingHostCommand.tsx +49 -0
- package/src/react/MissingHostScreen.css +85 -0
- package/src/react/MissingHostScreen.tsx +34 -0
- package/src/react/NotionCustomBlock.tsx +17 -55
- package/src/react/NotionTokenScope.tsx +2 -1
- package/src/react/index.ts +14 -22
- package/src/users/bridge/toNotionUserFromBridgeUser.ts +13 -0
- package/src/users/getCurrentUser.ts +10 -0
- package/src/users/getUser.ts +14 -0
- package/src/users/index.ts +7 -0
- package/src/users/listUsers.ts +23 -0
- package/src/users/react/useCurrentUser.ts +17 -0
- package/src/users/subscribeToCurrentUser.ts +13 -0
- package/src/users/types.ts +36 -0
- package/dist/autoResize.d.ts.map +0 -1
- package/dist/bridge/SandboxInitialization.d.ts.map +0 -1
- package/dist/bridge/appearance.d.ts.map +0 -1
- package/dist/bridge/dataSources/query.d.ts +0 -27
- package/dist/bridge/dataSources/query.d.ts.map +0 -1
- package/dist/bridge/dataSources/queryFilter.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolve.d.ts +0 -14
- package/dist/bridge/dataSources/resolve.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolvePropertyAddress.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolveSorts.d.ts.map +0 -1
- package/dist/bridge/dataSources/subscribe.d.ts.map +0 -1
- package/dist/bridge/dataSources/subscribe.js +0 -76
- package/dist/bridge/hostState.d.ts +0 -42
- package/dist/bridge/hostState.d.ts.map +0 -1
- package/dist/bridge/hostState.js +0 -8
- package/dist/bridge/notifyListener.d.ts.map +0 -1
- package/dist/bridge/page.d.ts +0 -18
- package/dist/bridge/page.d.ts.map +0 -1
- package/dist/bridge/readLocalManifest.d.ts.map +0 -1
- package/dist/bridge/sandboxClient.d.ts +0 -66
- package/dist/bridge/sandboxClient.d.ts.map +0 -1
- package/dist/bridge/sandboxClient.js +0 -158
- package/dist/customBlock.d.ts +0 -97
- package/dist/customBlock.d.ts.map +0 -1
- package/dist/customBlock.js +0 -157
- package/dist/dataSources.d.ts +0 -8
- package/dist/dataSources.d.ts.map +0 -1
- package/dist/dataSources.js +0 -105
- package/dist/init.d.ts.map +0 -1
- package/dist/initTypes.d.ts +0 -31
- package/dist/initTypes.d.ts.map +0 -1
- package/dist/protocol/dataSources/dataSource.d.ts +0 -786
- package/dist/protocol/dataSources/dataSource.js +0 -66
- package/dist/protocol/errors.js +0 -6
- package/dist/protocol/messages/createPage.js +0 -51
- package/dist/protocol/messages/createPageResult.js +0 -43
- package/dist/protocol/messages/queryDataSource.d.ts +0 -1470
- package/dist/protocol/messages/queryDataSource.js +0 -254
- package/dist/protocol/messages/updatePage.js +0 -23
- package/dist/protocol/pages/page.d.ts +0 -1422
- package/dist/protocol/pages/page.js +0 -318
- package/dist/protocol/parent.js +0 -13
- package/dist/protocol/users/user.js +0 -20
- package/dist/react/standalonePreview.d.ts +0 -2
- package/dist/react/standalonePreview.d.ts.map +0 -1
- package/dist/react/standalonePreview.js +0 -36
- package/dist/react/useCustomBlockInit.d.ts.map +0 -1
- package/dist/react/useDataSource.d.ts.map +0 -1
- package/dist/react/useHostState.d.ts +0 -2
- package/dist/react/useHostState.d.ts.map +0 -1
- package/dist/react/useHostState.js +0 -5
- package/dist/react/useRuntimeState.d.ts +0 -78
- package/dist/react/useRuntimeState.d.ts.map +0 -1
- package/dist/react/useRuntimeState.js +0 -86
- package/dist/typeUtils.d.ts.map +0 -1
- package/dist/types.d.ts +0 -204
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/src/bridge/dataSources/resolve.ts +0 -50
- package/src/bridge/dataSources/subscribe.ts +0 -124
- package/src/bridge/hostState.ts +0 -59
- package/src/bridge/page.ts +0 -47
- package/src/bridge/sandboxClient.ts +0 -225
- package/src/customBlock.ts +0 -193
- package/src/dataSources.ts +0 -136
- package/src/init.ts +0 -15
- package/src/initTypes.ts +0 -43
- package/src/react/standalonePreview.ts +0 -41
- package/src/react/useHostState.ts +0 -9
- package/src/react/useRuntimeState.ts +0 -118
- package/src/types.ts +0 -284
- /package/dist/{bridge/appearance.js → context/backgroundColors.js} +0 -0
- /package/dist/{typeUtils.js → context/hostState.js} +0 -0
- /package/dist/{types.js → dataSources/filters/types.js} +0 -0
- /package/dist/{bridge/dataSources → dataSources/properties}/resolvePropertyAddress.js +0 -0
- /package/dist/{react → dataSources/react}/useDataSource.d.ts +0 -0
- /package/dist/{autoResize.d.ts → layout/autoResize.d.ts} +0 -0
- /package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourcePage.d.ts +0 -0
- /package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourceValue.d.ts +0 -0
- /package/dist/protocol/{contrast.d.ts → context/contrast.d.ts} +0 -0
- /package/dist/protocol/{contrast.js → context/contrast.js} +0 -0
- /package/dist/protocol/{messages → context/messages}/contrastModeChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/contrastModeChanged.js +0 -0
- /package/dist/protocol/{messages → context/messages}/pageChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/parentChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/parentChanged.js +0 -0
- /package/dist/protocol/{messages → context/messages}/resize.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/resize.js +0 -0
- /package/dist/protocol/{messages → context/messages}/themeChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/themeChanged.js +0 -0
- /package/dist/protocol/{theme.d.ts → context/theme.d.ts} +0 -0
- /package/dist/protocol/{theme.js → context/theme.js} +0 -0
- /package/dist/protocol/{messages → dataSources/messages}/unsubscribeDataSourceQuery.d.ts +0 -0
- /package/dist/protocol/{messages → dataSources/messages}/unsubscribeDataSourceQuery.js +0 -0
- /package/dist/protocol/dataSources/{dateValue.d.ts → properties/dateValue.d.ts} +0 -0
- /package/dist/protocol/dataSources/{dateValue.js → properties/dateValue.js} +0 -0
- /package/dist/protocol/dataSources/{propertySchema.d.ts → properties/propertySchema.d.ts} +0 -0
- /package/dist/protocol/dataSources/{propertySchema.js → properties/propertySchema.js} +0 -0
- /package/dist/protocol/{messages → handshake}/initResult.js +0 -0
- /package/dist/protocol/{messages → handshake}/isInitHandshakeMessage.js +0 -0
- /package/dist/protocol/{messages → navigation}/openExternalUrl.js +0 -0
- /package/dist/protocol/{messages → users/messages}/currentUserChanged.d.ts +0 -0
- /package/dist/protocol/{ids.d.ts → utils/ids.d.ts} +0 -0
- /package/dist/protocol/{ids.js → utils/ids.js} +0 -0
- /package/dist/protocol/{isLocalBlockServerUrl.d.ts → utils/isLocalBlockServerUrl.d.ts} +0 -0
- /package/dist/protocol/{isLocalBlockServerUrl.js → utils/isLocalBlockServerUrl.js} +0 -0
- /package/dist/protocol/{protocolVersion.d.ts → utils/protocolVersion.d.ts} +0 -0
- /package/dist/protocol/{protocolVersion.js → utils/protocolVersion.js} +0 -0
- /package/dist/protocol/{dataSources → utils}/recordPointer.d.ts +0 -0
- /package/dist/protocol/{dataSources → utils}/recordPointer.js +0 -0
- /package/dist/{bridge → utils}/notifyListener.d.ts +0 -0
- /package/dist/{bridge → utils}/notifyListener.js +0 -0
- /package/dist/{typeUtils.d.ts → utils/typeUtils.d.ts} +0 -0
- /package/dist/{utils.js → utils/unreachable.js} +0 -0
- /package/dist/{version.d.ts → utils/version.d.ts} +0 -0
- /package/src/{bridge/appearance.ts → context/backgroundColors.ts} +0 -0
- /package/src/{bridge → utils}/notifyListener.ts +0 -0
- /package/src/{typeUtils.ts → utils/typeUtils.ts} +0 -0
- /package/src/{utils.ts → utils/unreachable.ts} +0 -0
- /package/src/{version.ts → utils/version.ts} +0 -0
|
@@ -1,105 +1,76 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { DEFAULT_CONTRAST_MODE } from "@notionhq/custom-blocks-protocol/context/contrast.js"
|
|
2
|
+
import type { BridgeDataSourceBindings } from "@notionhq/custom-blocks-protocol/dataSources/bridgeDataSourceBindings.js"
|
|
3
|
+
import type { QueryDataSourceResultMessage } from "@notionhq/custom-blocks-protocol/dataSources/messages/queryDataSource.js"
|
|
4
|
+
import type { InitMessage } from "@notionhq/custom-blocks-protocol/handshake/init.js"
|
|
5
|
+
import type { CustomBlockInitResultErrorInfo } from "@notionhq/custom-blocks-protocol/handshake/initResult.js"
|
|
6
|
+
import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
|
|
7
|
+
import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
|
|
8
|
+
import type { InvalidHostMessage } from "@notionhq/custom-blocks-protocol/messages/invalidHostMessage.js"
|
|
9
|
+
import type { BridgeMessagePayload } from "@notionhq/custom-blocks-protocol/messages/messagePayload.js"
|
|
10
|
+
import type { SandboxToHostMessage } from "@notionhq/custom-blocks-protocol/messages/sandboxToHost.js"
|
|
3
11
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@notionhq/custom-blocks-protocol/
|
|
7
|
-
import type { NotionPageId } from "@notionhq/custom-blocks-protocol/ids.js"
|
|
8
|
-
import type { CustomBlockManifest } from "@notionhq/custom-blocks-protocol/manifest.js"
|
|
12
|
+
OpenExternalUrlMessage,
|
|
13
|
+
OpenExternalUrlResultMessage,
|
|
14
|
+
} from "@notionhq/custom-blocks-protocol/navigation/openExternalUrl.js"
|
|
9
15
|
import type {
|
|
10
16
|
CreatePageMessage,
|
|
11
|
-
CreatePageMessageParent,
|
|
12
|
-
} from "@notionhq/custom-blocks-protocol/messages/createPage.js"
|
|
13
|
-
import type {
|
|
14
17
|
CreatePageResultMessage,
|
|
15
|
-
|
|
16
|
-
} from "@notionhq/custom-blocks-protocol/messages/createPageResult.js"
|
|
18
|
+
} from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
|
|
17
19
|
import type {
|
|
18
20
|
GetPageMessage,
|
|
19
21
|
GetPageResultMessage,
|
|
20
|
-
} from "@notionhq/custom-blocks-protocol/messages/getPage.js"
|
|
21
|
-
import type { GetUserMessage } from "@notionhq/custom-blocks-protocol/messages/getUser.js"
|
|
22
|
-
import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
|
|
23
|
-
import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
|
|
24
|
-
import {
|
|
25
|
-
type InitMessage,
|
|
26
|
-
initMessageSchema,
|
|
27
|
-
} from "@notionhq/custom-blocks-protocol/messages/init.js"
|
|
28
|
-
import type { CustomBlockInitResultErrorInfo } from "@notionhq/custom-blocks-protocol/messages/initResult.js"
|
|
29
|
-
import type { InvalidHostMessage } from "@notionhq/custom-blocks-protocol/messages/invalidHostMessage.js"
|
|
30
|
-
import type { ListUsersMessage } from "@notionhq/custom-blocks-protocol/messages/listUsers.js"
|
|
31
|
-
import type { BridgeMessagePayload } from "@notionhq/custom-blocks-protocol/messages/messagePayload.js"
|
|
32
|
-
import type { OpenExternalUrlMessage } from "@notionhq/custom-blocks-protocol/messages/openExternalUrl.js"
|
|
33
|
-
import type { OpenPageMessage } from "@notionhq/custom-blocks-protocol/messages/openPage.js"
|
|
34
|
-
import type { QueryDataSourceMessage } from "@notionhq/custom-blocks-protocol/messages/queryDataSource.js"
|
|
35
|
-
import type { CustomBlockQueryDataSourceErrorInfo } from "@notionhq/custom-blocks-protocol/messages/queryDataSourceResult.js"
|
|
36
|
-
import type { ResizeMessage } from "@notionhq/custom-blocks-protocol/messages/resize.js"
|
|
37
|
-
import type { SandboxToHostMessage } from "@notionhq/custom-blocks-protocol/messages/sandboxToHost.js"
|
|
38
|
-
import type { UnsubscribeDataSourceQueryMessage } from "@notionhq/custom-blocks-protocol/messages/unsubscribeDataSourceQuery.js"
|
|
39
|
-
import type { UpdatePageMessage } from "@notionhq/custom-blocks-protocol/messages/updatePage.js"
|
|
40
|
-
import type { UpdatePageResultMessage } from "@notionhq/custom-blocks-protocol/messages/updatePageResult.js"
|
|
41
|
-
import type { NotionTheme } from "@notionhq/custom-blocks-protocol/theme.js"
|
|
42
|
-
import * as v from "valibot"
|
|
22
|
+
} from "@notionhq/custom-blocks-protocol/pages/messages/getPage.js"
|
|
43
23
|
import type {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} from "
|
|
59
|
-
import
|
|
60
|
-
import {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
} from "
|
|
64
|
-
import {
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
67
|
-
import {
|
|
68
|
-
|
|
69
|
-
createEmptyDataSourceQueryState,
|
|
70
|
-
type DataSourceQueryState,
|
|
71
|
-
} from "./hostState.js"
|
|
24
|
+
OpenPageMessage,
|
|
25
|
+
OpenPageResultMessage,
|
|
26
|
+
} from "@notionhq/custom-blocks-protocol/pages/messages/openPage.js"
|
|
27
|
+
import type {
|
|
28
|
+
UpdatePageMessage,
|
|
29
|
+
UpdatePageResultMessage,
|
|
30
|
+
} from "@notionhq/custom-blocks-protocol/pages/messages/updatePage.js"
|
|
31
|
+
import type {
|
|
32
|
+
GetUserMessage,
|
|
33
|
+
GetUserResultMessage,
|
|
34
|
+
} from "@notionhq/custom-blocks-protocol/users/messages/getUser.js"
|
|
35
|
+
import type {
|
|
36
|
+
ListUsersMessage,
|
|
37
|
+
ListUsersResultMessage,
|
|
38
|
+
} from "@notionhq/custom-blocks-protocol/users/messages/listUsers.js"
|
|
39
|
+
import * as v from "valibot"
|
|
40
|
+
import { applyContextMessage } from "../context/applyContextMessage.js"
|
|
41
|
+
import type { CustomBlockHostState } from "../context/hostState.js"
|
|
42
|
+
import { syncDocumentAppearance } from "../context/syncDocumentAppearance.js"
|
|
43
|
+
import { applyDataSourceBindings } from "../dataSources/bridge/applyDataSourceBindings.js"
|
|
44
|
+
import { resolveInitialState } from "../initialization/resolveInitialState.js"
|
|
45
|
+
import { getInitialContentHeight } from "../layout/getInitialContentHeight.js"
|
|
46
|
+
import { notifyListener } from "../utils/notifyListener.js"
|
|
47
|
+
import { unreachable } from "../utils/unreachable.js"
|
|
48
|
+
import { SandboxInitialization } from "./initialization/SandboxInitialization.js"
|
|
72
49
|
import type { MessageInterceptor } from "./messageInterceptor.js"
|
|
73
|
-
import { notifyListener } from "./notifyListener.js"
|
|
74
|
-
import { makeUpdatePageByKey, toNotionPageFromBridgePage } from "./page.js"
|
|
75
50
|
import { PendingRequests } from "./pendingRequests.js"
|
|
76
|
-
import { SandboxInitialization } from "./SandboxInitialization.js"
|
|
77
51
|
|
|
78
52
|
/**
|
|
79
53
|
* A single entry in the bridge message log. Kept intentionally plain so the log is copy-pasteable
|
|
80
54
|
* to a local coding agent without needing extra context.
|
|
81
55
|
*/
|
|
82
|
-
|
|
56
|
+
type MessageLogEntry = {
|
|
83
57
|
timestamp: string
|
|
84
58
|
direction: "sent" | "received"
|
|
85
59
|
data: unknown
|
|
86
60
|
}
|
|
87
61
|
|
|
88
|
-
export type QueryDataSourceArgs = {
|
|
89
|
-
subscriptionId: string
|
|
90
|
-
key: string
|
|
91
|
-
options?: DataSourceQueryOptions
|
|
92
|
-
/** Send the query even if an identical query is already loading. */
|
|
93
|
-
forceRequery?: boolean
|
|
94
|
-
}
|
|
95
62
|
export class SandboxBridge {
|
|
96
63
|
private hostState: CustomBlockHostState = {
|
|
97
64
|
status: "uninitialized",
|
|
98
65
|
theme: "light",
|
|
99
66
|
contrastMode: DEFAULT_CONTRAST_MODE,
|
|
100
67
|
}
|
|
101
|
-
|
|
68
|
+
|
|
102
69
|
private listeners = new Set<() => void>()
|
|
70
|
+
private dataSourceQueryListeners = new Map<
|
|
71
|
+
string,
|
|
72
|
+
(message: QueryDataSourceResultMessage) => void
|
|
73
|
+
>()
|
|
103
74
|
private messageInterceptors = new Set<MessageInterceptor>()
|
|
104
75
|
private messageLog: MessageLogEntry[] = []
|
|
105
76
|
private messageLogListeners = new Set<() => void>()
|
|
@@ -109,28 +80,28 @@ export class SandboxBridge {
|
|
|
109
80
|
private readonly pendingGetPage = new PendingRequests<
|
|
110
81
|
BridgeMessagePayload<GetPageResultMessage>
|
|
111
82
|
>("custom-block-get-page")
|
|
112
|
-
private readonly pendingGetUser = new PendingRequests<
|
|
113
|
-
|
|
114
|
-
)
|
|
115
|
-
private readonly pendingListUsers = new PendingRequests<
|
|
116
|
-
|
|
117
|
-
)
|
|
118
|
-
private readonly pendingOpenPage = new PendingRequests<
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
private readonly pendingOpenExternalUrl =
|
|
122
|
-
|
|
83
|
+
private readonly pendingGetUser = new PendingRequests<
|
|
84
|
+
BridgeMessagePayload<GetUserResultMessage>
|
|
85
|
+
>("custom-block-get-user")
|
|
86
|
+
private readonly pendingListUsers = new PendingRequests<
|
|
87
|
+
BridgeMessagePayload<ListUsersResultMessage>
|
|
88
|
+
>("custom-block-list-users")
|
|
89
|
+
private readonly pendingOpenPage = new PendingRequests<
|
|
90
|
+
BridgeMessagePayload<OpenPageResultMessage>
|
|
91
|
+
>("custom-block-open-page")
|
|
92
|
+
private readonly pendingOpenExternalUrl = new PendingRequests<
|
|
93
|
+
BridgeMessagePayload<OpenExternalUrlResultMessage>
|
|
94
|
+
>("custom-block-open-url")
|
|
123
95
|
private readonly pendingUpdatePage = new PendingRequests<
|
|
124
96
|
BridgeMessagePayload<UpdatePageResultMessage>
|
|
125
97
|
>("custom-block-update-page")
|
|
126
|
-
private latestDataSourceBindings:
|
|
127
|
-
private isMockState = false
|
|
98
|
+
private latestDataSourceBindings: BridgeDataSourceBindings = {}
|
|
128
99
|
private isListening = false
|
|
129
100
|
private isDisposed = false
|
|
130
101
|
private readonly initialization = new SandboxInitialization({
|
|
131
102
|
start: () => this.startListening(),
|
|
132
103
|
post: message => this.sendToHost(message),
|
|
133
|
-
apply: message => this.applyInit(message
|
|
104
|
+
apply: message => this.applyInit(message),
|
|
134
105
|
getState: () => this.hostState,
|
|
135
106
|
getInitialHeight: getInitialContentHeight,
|
|
136
107
|
})
|
|
@@ -154,6 +125,7 @@ export class SandboxBridge {
|
|
|
154
125
|
this.isListening = false
|
|
155
126
|
}
|
|
156
127
|
this.listeners.clear()
|
|
128
|
+
this.dataSourceQueryListeners.clear()
|
|
157
129
|
this.messageLogListeners.clear()
|
|
158
130
|
}
|
|
159
131
|
|
|
@@ -181,11 +153,11 @@ export class SandboxBridge {
|
|
|
181
153
|
}
|
|
182
154
|
}
|
|
183
155
|
|
|
184
|
-
getMessageLog(): readonly MessageLogEntry[] {
|
|
156
|
+
getMessageLog = (): readonly MessageLogEntry[] => {
|
|
185
157
|
return this.messageLog
|
|
186
158
|
}
|
|
187
159
|
|
|
188
|
-
subscribeToMessageLog(listener: () => void) {
|
|
160
|
+
subscribeToMessageLog = (listener: () => void) => {
|
|
189
161
|
this.messageLogListeners.add(listener)
|
|
190
162
|
return () => this.messageLogListeners.delete(listener)
|
|
191
163
|
}
|
|
@@ -195,7 +167,7 @@ export class SandboxBridge {
|
|
|
195
167
|
return () => this.messageInterceptors.delete(interceptor)
|
|
196
168
|
}
|
|
197
169
|
|
|
198
|
-
|
|
170
|
+
postToHost(message: SandboxToHostMessage) {
|
|
199
171
|
this.initialization.post(message)
|
|
200
172
|
}
|
|
201
173
|
|
|
@@ -211,12 +183,6 @@ export class SandboxBridge {
|
|
|
211
183
|
window.parent.postMessage(message, "*")
|
|
212
184
|
}
|
|
213
185
|
|
|
214
|
-
private notify = () => {
|
|
215
|
-
for (const listener of this.listeners) {
|
|
216
|
-
notifyListener(listener)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
186
|
private handleMessage = (event: MessageEvent) => {
|
|
221
187
|
if (event.source !== window.parent) {
|
|
222
188
|
return
|
|
@@ -293,110 +259,28 @@ export class SandboxBridge {
|
|
|
293
259
|
}
|
|
294
260
|
|
|
295
261
|
switch (message.type) {
|
|
296
|
-
case "themeChanged":
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
theme: message.theme,
|
|
303
|
-
contrastMode: hostState.contrastMode,
|
|
304
|
-
})
|
|
305
|
-
this.notify()
|
|
262
|
+
case "themeChanged":
|
|
263
|
+
case "contrastModeChanged":
|
|
264
|
+
case "parentChanged":
|
|
265
|
+
case "pageChanged":
|
|
266
|
+
case "currentUserChanged":
|
|
267
|
+
this.commitHostState(applyContextMessage(hostState, message))
|
|
306
268
|
return
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
case "contrastModeChanged": {
|
|
310
|
-
this.hostState = {
|
|
311
|
-
...hostState,
|
|
312
|
-
contrastMode: message.contrastMode,
|
|
313
|
-
}
|
|
314
|
-
syncDocumentAppearance({
|
|
315
|
-
theme: hostState.theme,
|
|
316
|
-
contrastMode: message.contrastMode,
|
|
317
|
-
})
|
|
318
|
-
this.notify()
|
|
319
|
-
return
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
case "parentChanged": {
|
|
323
|
-
this.hostState = {
|
|
324
|
-
...hostState,
|
|
325
|
-
parent: message.parent,
|
|
326
|
-
}
|
|
327
|
-
this.notify()
|
|
328
|
-
return
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
case "pageChanged": {
|
|
332
|
-
this.hostState = {
|
|
333
|
-
...hostState,
|
|
334
|
-
page: message.page,
|
|
335
|
-
}
|
|
336
|
-
this.notify()
|
|
337
|
-
return
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
case "currentUserChanged": {
|
|
341
|
-
this.hostState = {
|
|
342
|
-
...hostState,
|
|
343
|
-
currentUser: message.currentUser,
|
|
344
|
-
}
|
|
345
|
-
this.notify()
|
|
346
|
-
return
|
|
347
|
-
}
|
|
348
269
|
|
|
349
270
|
case "dataSourcesChanged": {
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
nextDataSources: this.isMockState
|
|
355
|
-
? resolveMockDataSources(nextBindings)
|
|
356
|
-
: resolveDataSources({
|
|
357
|
-
manifest: hostState.manifest,
|
|
358
|
-
dataSourceBindings: nextBindings,
|
|
359
|
-
}),
|
|
360
|
-
nextBindings,
|
|
361
|
-
})
|
|
362
|
-
this.latestDataSourceBindings = nextBindings
|
|
363
|
-
// Preserve rows only while the key still refers to the same backing data source.
|
|
364
|
-
const previousSourcesByKey = new Map(
|
|
365
|
-
hostState.dataSources.map(source => [source.key, source]),
|
|
366
|
-
)
|
|
367
|
-
const nextSourcesByKey = new Map(
|
|
368
|
-
dataSources.map(source => [source.key, source]),
|
|
271
|
+
const nextState = applyDataSourceBindings(
|
|
272
|
+
hostState,
|
|
273
|
+
message.dataSources.bindings,
|
|
274
|
+
this.latestDataSourceBindings,
|
|
369
275
|
)
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
hostState.dataSourceState,
|
|
373
|
-
)) {
|
|
374
|
-
const nextSource = nextSourcesByKey.get(state.dataSourceKey)
|
|
375
|
-
if (nextSource === undefined) {
|
|
376
|
-
continue
|
|
377
|
-
}
|
|
378
|
-
const previousSource = previousSourcesByKey.get(state.dataSourceKey)
|
|
379
|
-
prunedState[subscriptionId] =
|
|
380
|
-
previousSource?.collectionPointer?.id ===
|
|
381
|
-
nextSource.collectionPointer?.id
|
|
382
|
-
? state
|
|
383
|
-
: createEmptyDataSourceQueryState(state.dataSourceKey)
|
|
384
|
-
}
|
|
385
|
-
this.hostState = {
|
|
386
|
-
...hostState,
|
|
387
|
-
dataSources,
|
|
388
|
-
dataSourceState: prunedState,
|
|
389
|
-
}
|
|
390
|
-
this.notify()
|
|
276
|
+
this.latestDataSourceBindings = message.dataSources.bindings
|
|
277
|
+
this.commitHostState(nextState)
|
|
391
278
|
return
|
|
392
279
|
}
|
|
393
280
|
|
|
394
281
|
case "createPageResult": {
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
? { status: "success", page: message.page }
|
|
398
|
-
: { status: "error", error: message.error }
|
|
399
|
-
if (!this.pendingCreatePage.resolve(message.requestId, result)) {
|
|
282
|
+
const { type: _, requestId, ...result } = message
|
|
283
|
+
if (!this.pendingCreatePage.resolve(requestId, result)) {
|
|
400
284
|
console.warn(
|
|
401
285
|
`[custom-blocks-sdk] createPageResult for unknown requestId ${message.requestId}`,
|
|
402
286
|
)
|
|
@@ -405,11 +289,8 @@ export class SandboxBridge {
|
|
|
405
289
|
}
|
|
406
290
|
|
|
407
291
|
case "getPageResult": {
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
? { status: "success", page: message.page }
|
|
411
|
-
: { status: "error", error: message.error }
|
|
412
|
-
if (!this.pendingGetPage.resolve(message.requestId, result)) {
|
|
292
|
+
const { type: _, requestId, ...result } = message
|
|
293
|
+
if (!this.pendingGetPage.resolve(requestId, result)) {
|
|
413
294
|
console.warn(
|
|
414
295
|
`[custom-blocks-sdk] getPageResult for unknown requestId ${message.requestId}`,
|
|
415
296
|
)
|
|
@@ -418,11 +299,8 @@ export class SandboxBridge {
|
|
|
418
299
|
}
|
|
419
300
|
|
|
420
301
|
case "getUserResult": {
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
? { status: "success", user: message.user }
|
|
424
|
-
: { status: "error", error: message.error }
|
|
425
|
-
if (!this.pendingGetUser.resolve(message.requestId, result)) {
|
|
302
|
+
const { type: _, requestId, ...result } = message
|
|
303
|
+
if (!this.pendingGetUser.resolve(requestId, result)) {
|
|
426
304
|
console.warn(
|
|
427
305
|
`[custom-blocks-sdk] getUserResult for unknown requestId ${message.requestId}`,
|
|
428
306
|
)
|
|
@@ -431,11 +309,8 @@ export class SandboxBridge {
|
|
|
431
309
|
}
|
|
432
310
|
|
|
433
311
|
case "listUsersResult": {
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
? { status: "success", list: message.list }
|
|
437
|
-
: { status: "error", error: message.error }
|
|
438
|
-
if (!this.pendingListUsers.resolve(message.requestId, result)) {
|
|
312
|
+
const { type: _, requestId, ...result } = message
|
|
313
|
+
if (!this.pendingListUsers.resolve(requestId, result)) {
|
|
439
314
|
console.warn(
|
|
440
315
|
`[custom-blocks-sdk] listUsersResult for unknown requestId ${message.requestId}`,
|
|
441
316
|
)
|
|
@@ -444,11 +319,8 @@ export class SandboxBridge {
|
|
|
444
319
|
}
|
|
445
320
|
|
|
446
321
|
case "openPageResult": {
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
? { status: "success", pageId: message.pageId }
|
|
450
|
-
: { status: "error", error: message.error }
|
|
451
|
-
if (!this.pendingOpenPage.resolve(message.requestId, result)) {
|
|
322
|
+
const { type: _, requestId, ...result } = message
|
|
323
|
+
if (!this.pendingOpenPage.resolve(requestId, result)) {
|
|
452
324
|
console.warn(
|
|
453
325
|
`[custom-blocks-sdk] openPageResult for unknown requestId ${message.requestId}`,
|
|
454
326
|
)
|
|
@@ -457,11 +329,8 @@ export class SandboxBridge {
|
|
|
457
329
|
}
|
|
458
330
|
|
|
459
331
|
case "openExternalUrlResult": {
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
? { status: "success" }
|
|
463
|
-
: { status: "error", error: message.error }
|
|
464
|
-
if (!this.pendingOpenExternalUrl.resolve(message.requestId, result)) {
|
|
332
|
+
const { type: _, requestId, ...result } = message
|
|
333
|
+
if (!this.pendingOpenExternalUrl.resolve(requestId, result)) {
|
|
465
334
|
console.warn(
|
|
466
335
|
`[custom-blocks-sdk] openExternalUrlResult for unknown requestId ${message.requestId}`,
|
|
467
336
|
)
|
|
@@ -470,11 +339,8 @@ export class SandboxBridge {
|
|
|
470
339
|
}
|
|
471
340
|
|
|
472
341
|
case "updatePageResult": {
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
? { status: "success", page: message.page }
|
|
476
|
-
: { status: "error", error: message.error }
|
|
477
|
-
if (!this.pendingUpdatePage.resolve(message.requestId, result)) {
|
|
342
|
+
const { type: _, requestId, ...result } = message
|
|
343
|
+
if (!this.pendingUpdatePage.resolve(requestId, result)) {
|
|
478
344
|
console.warn(
|
|
479
345
|
`[custom-blocks-sdk] updatePageResult for unknown requestId ${message.requestId}`,
|
|
480
346
|
)
|
|
@@ -483,39 +349,12 @@ export class SandboxBridge {
|
|
|
483
349
|
}
|
|
484
350
|
|
|
485
351
|
case "queryDataSourceResult": {
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
const queryResult =
|
|
492
|
-
message.status === "error"
|
|
493
|
-
? {
|
|
494
|
-
items: [],
|
|
495
|
-
hasMore: false,
|
|
496
|
-
error: message.error,
|
|
497
|
-
}
|
|
498
|
-
: {
|
|
499
|
-
items,
|
|
500
|
-
hasMore: message.hasMore,
|
|
501
|
-
error: undefined,
|
|
502
|
-
}
|
|
503
|
-
this.hostState = {
|
|
504
|
-
...hostState,
|
|
505
|
-
dataSourceState: {
|
|
506
|
-
...hostState.dataSourceState,
|
|
507
|
-
[message.subscriptionId]: {
|
|
508
|
-
dataSourceKey: currentState.dataSourceKey,
|
|
509
|
-
items: queryResult.items,
|
|
510
|
-
isLoading: false,
|
|
511
|
-
hasMore: queryResult.hasMore,
|
|
512
|
-
error: queryResult.error,
|
|
513
|
-
latestLimit: currentState.latestLimit,
|
|
514
|
-
latestQueryIdentity: currentState.latestQueryIdentity,
|
|
515
|
-
},
|
|
516
|
-
},
|
|
352
|
+
const listener = this.dataSourceQueryListeners.get(
|
|
353
|
+
message.subscriptionId,
|
|
354
|
+
)
|
|
355
|
+
if (listener !== undefined) {
|
|
356
|
+
notifyListener(() => listener(message))
|
|
517
357
|
}
|
|
518
|
-
this.notify()
|
|
519
358
|
return
|
|
520
359
|
}
|
|
521
360
|
|
|
@@ -525,27 +364,37 @@ export class SandboxBridge {
|
|
|
525
364
|
}
|
|
526
365
|
}
|
|
527
366
|
|
|
528
|
-
subscribe(listener: () => void) {
|
|
367
|
+
subscribe = (listener: () => void) => {
|
|
529
368
|
this.listeners.add(listener)
|
|
530
369
|
return () => this.listeners.delete(listener)
|
|
531
370
|
}
|
|
532
371
|
|
|
533
|
-
getHostState(): CustomBlockHostState {
|
|
372
|
+
getHostState = (): CustomBlockHostState => {
|
|
534
373
|
return this.hostState
|
|
535
374
|
}
|
|
536
375
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
376
|
+
private commitHostState(state: CustomBlockHostState): void {
|
|
377
|
+
const previous = this.hostState
|
|
378
|
+
this.hostState = state
|
|
379
|
+
if (
|
|
380
|
+
previous.status !== state.status ||
|
|
381
|
+
previous.theme !== state.theme ||
|
|
382
|
+
previous.contrastMode !== state.contrastMode
|
|
383
|
+
) {
|
|
384
|
+
syncDocumentAppearance(state)
|
|
385
|
+
}
|
|
386
|
+
for (const listener of this.listeners) {
|
|
387
|
+
notifyListener(listener)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
subscribeToDataSourceQueryResults(
|
|
392
|
+
subscriptionId: string,
|
|
393
|
+
listener: (message: QueryDataSourceResultMessage) => void,
|
|
394
|
+
): () => void {
|
|
395
|
+
this.dataSourceQueryListeners.set(subscriptionId, listener)
|
|
396
|
+
return () => {
|
|
397
|
+
this.dataSourceQueryListeners.delete(subscriptionId)
|
|
549
398
|
}
|
|
550
399
|
}
|
|
551
400
|
|
|
@@ -555,622 +404,78 @@ export class SandboxBridge {
|
|
|
555
404
|
|
|
556
405
|
private applyInit(
|
|
557
406
|
message: Extract<InitMessage, { status: "success" }>,
|
|
558
|
-
postResult: boolean,
|
|
559
407
|
): CustomBlockInitResultErrorInfo | undefined {
|
|
560
|
-
if (postResult) {
|
|
561
|
-
this.isMockState = false
|
|
562
|
-
}
|
|
563
|
-
const { blockId, parent, page } = message
|
|
564
|
-
|
|
565
408
|
this.latestDataSourceBindings = message.dataSources.bindings
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
dataSourceBindings: this.latestDataSourceBindings,
|
|
570
|
-
})
|
|
571
|
-
: resolveMockDataSources(this.latestDataSourceBindings)
|
|
572
|
-
const bindingError = getInitBindingError(message.manifest, dataSources)
|
|
573
|
-
if (postResult && bindingError !== undefined) {
|
|
574
|
-
return bindingError
|
|
575
|
-
}
|
|
576
|
-
this.hostState = {
|
|
577
|
-
status: "initialized",
|
|
578
|
-
theme: message.theme,
|
|
579
|
-
contrastMode: message.contrastMode,
|
|
580
|
-
blockId,
|
|
581
|
-
parent,
|
|
582
|
-
page,
|
|
583
|
-
currentUser: message.currentUser,
|
|
584
|
-
manifest: message.manifest,
|
|
585
|
-
dataSources,
|
|
586
|
-
dataSourceState: {},
|
|
409
|
+
const result = resolveInitialState(message)
|
|
410
|
+
if (result.status === "error") {
|
|
411
|
+
return result.error
|
|
587
412
|
}
|
|
588
|
-
|
|
589
|
-
theme: message.theme,
|
|
590
|
-
contrastMode: message.contrastMode,
|
|
591
|
-
})
|
|
592
|
-
this.notify()
|
|
413
|
+
this.commitHostState(result.state)
|
|
593
414
|
return undefined
|
|
594
415
|
}
|
|
595
416
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
queryDataSource({
|
|
601
|
-
subscriptionId,
|
|
602
|
-
key,
|
|
603
|
-
options = {},
|
|
604
|
-
forceRequery = false,
|
|
605
|
-
}: QueryDataSourceArgs) {
|
|
606
|
-
if (this.hostState.status !== "initialized") {
|
|
607
|
-
return
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
const dataSource = this.hostState.dataSources.find(
|
|
611
|
-
entry => entry.key === key,
|
|
612
|
-
)
|
|
613
|
-
const subscriptionState = this.hostState.dataSourceState[subscriptionId]
|
|
614
|
-
const currentState =
|
|
615
|
-
subscriptionState?.dataSourceKey === key
|
|
616
|
-
? subscriptionState
|
|
617
|
-
: createEmptyDataSourceQueryState(key)
|
|
618
|
-
if (dataSource === undefined) {
|
|
619
|
-
this.setDataSourceQueryError({
|
|
620
|
-
subscriptionId,
|
|
621
|
-
currentState,
|
|
622
|
-
error: {
|
|
623
|
-
code: "unknown_data_source_key",
|
|
624
|
-
message: `Unknown data source key "${key}". Known keys: [${this.hostState.dataSources.map(entry => entry.key).join(", ")}].`,
|
|
625
|
-
isRetryable: false,
|
|
626
|
-
},
|
|
627
|
-
})
|
|
628
|
-
return
|
|
629
|
-
}
|
|
630
|
-
if (dataSource.collectionPointer === undefined) {
|
|
631
|
-
this.setDataSourceQueryError({
|
|
632
|
-
subscriptionId,
|
|
633
|
-
currentState,
|
|
634
|
-
error: {
|
|
635
|
-
code: "unmapped_data_source",
|
|
636
|
-
message: `Data source "${key}" has not been mapped to a database yet.`,
|
|
637
|
-
isRetryable: false,
|
|
638
|
-
},
|
|
639
|
-
})
|
|
640
|
-
return
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
const resolvedQuery = resolveDataSourceQuery({
|
|
644
|
-
dataSources: this.hostState.dataSources,
|
|
645
|
-
key,
|
|
646
|
-
options,
|
|
647
|
-
})
|
|
648
|
-
if (resolvedQuery.status === "error") {
|
|
649
|
-
this.setDataSourceQueryError({
|
|
650
|
-
subscriptionId,
|
|
651
|
-
currentState,
|
|
652
|
-
error: resolvedQuery.error,
|
|
653
|
-
})
|
|
654
|
-
return
|
|
655
|
-
}
|
|
656
|
-
const query = resolvedQuery.query
|
|
657
|
-
|
|
658
|
-
if (
|
|
659
|
-
!forceRequery &&
|
|
660
|
-
currentState.isLoading &&
|
|
661
|
-
currentState.latestQueryIdentity === query.identity
|
|
662
|
-
) {
|
|
663
|
-
return
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
this.hostState = {
|
|
667
|
-
...this.hostState,
|
|
668
|
-
dataSourceState: {
|
|
669
|
-
...this.hostState.dataSourceState,
|
|
670
|
-
[subscriptionId]: {
|
|
671
|
-
...currentState,
|
|
672
|
-
dataSourceKey: key,
|
|
673
|
-
isLoading: true,
|
|
674
|
-
error: undefined,
|
|
675
|
-
latestLimit: query.limit,
|
|
676
|
-
latestQueryIdentity: query.identity,
|
|
677
|
-
},
|
|
678
|
-
},
|
|
679
|
-
}
|
|
680
|
-
const outbound: QueryDataSourceMessage = {
|
|
681
|
-
type: "queryDataSource",
|
|
682
|
-
subscriptionId,
|
|
683
|
-
dataSourceId: query.dataSourceId,
|
|
684
|
-
limit: query.limit,
|
|
685
|
-
...(query.filter !== undefined ? { filter: query.filter } : {}),
|
|
686
|
-
...(query.sorts !== undefined ? { sorts: query.sorts } : {}),
|
|
687
|
-
}
|
|
688
|
-
this.postToHost(outbound)
|
|
689
|
-
this.notify()
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
private setDataSourceQueryError({
|
|
693
|
-
subscriptionId,
|
|
694
|
-
currentState,
|
|
695
|
-
error,
|
|
696
|
-
}: {
|
|
697
|
-
subscriptionId: string
|
|
698
|
-
currentState: DataSourceQueryState
|
|
699
|
-
error: CustomBlockQueryDataSourceErrorInfo
|
|
700
|
-
}) {
|
|
701
|
-
if (this.hostState.status !== "initialized") {
|
|
702
|
-
return
|
|
703
|
-
}
|
|
704
|
-
this.hostState = {
|
|
705
|
-
...this.hostState,
|
|
706
|
-
dataSourceState: {
|
|
707
|
-
...this.hostState.dataSourceState,
|
|
708
|
-
[subscriptionId]: {
|
|
709
|
-
...currentState,
|
|
710
|
-
isLoading: false,
|
|
711
|
-
error,
|
|
712
|
-
latestLimit: undefined,
|
|
713
|
-
latestQueryIdentity: undefined,
|
|
714
|
-
},
|
|
715
|
-
},
|
|
716
|
-
}
|
|
717
|
-
this.notify()
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
releaseDataSourceSubscription(subscriptionId: string) {
|
|
721
|
-
if (
|
|
722
|
-
this.hostState.status !== "initialized" ||
|
|
723
|
-
this.hostState.dataSourceState[subscriptionId] === undefined
|
|
724
|
-
) {
|
|
725
|
-
return
|
|
726
|
-
}
|
|
727
|
-
const { [subscriptionId]: _, ...dataSourceState } =
|
|
728
|
-
this.hostState.dataSourceState
|
|
729
|
-
this.hostState = {
|
|
730
|
-
...this.hostState,
|
|
731
|
-
dataSourceState,
|
|
732
|
-
}
|
|
733
|
-
const outbound: UnsubscribeDataSourceQueryMessage = {
|
|
734
|
-
type: "unsubscribeDataSourceQuery",
|
|
735
|
-
subscriptionId,
|
|
736
|
-
}
|
|
737
|
-
this.postToHost(outbound)
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
postResize(height: number) {
|
|
741
|
-
if (typeof window === "undefined") {
|
|
742
|
-
return
|
|
743
|
-
}
|
|
744
|
-
const safeHeight =
|
|
745
|
-
Number.isFinite(height) && height >= 0 ? Math.ceil(height) : 0
|
|
746
|
-
const outbound: ResizeMessage = {
|
|
747
|
-
type: "resize",
|
|
748
|
-
height: safeHeight,
|
|
749
|
-
}
|
|
750
|
-
this.postToHost(outbound)
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
createPage(args: {
|
|
754
|
-
parent: CreatePageArgs["parent"]
|
|
755
|
-
properties: CreatePageArgs["properties"]
|
|
756
|
-
position?: CreatePageArgs["position"]
|
|
757
|
-
dataSource: NotionDataSource | undefined
|
|
758
|
-
}): Promise<CreatePageResult> {
|
|
759
|
-
const { dataSource } = args
|
|
760
|
-
const dataSourceKey = dataSource?.key
|
|
417
|
+
requestCreatePage(
|
|
418
|
+
args: BridgeMessagePayload<CreatePageMessage>,
|
|
419
|
+
): Promise<BridgeMessagePayload<CreatePageResultMessage>> {
|
|
761
420
|
return new Promise(resolve => {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
if (dataSource?.collectionPointer) {
|
|
765
|
-
parent = {
|
|
766
|
-
type: "data_source_id",
|
|
767
|
-
data_source_id: dataSource.collectionPointer.id,
|
|
768
|
-
}
|
|
769
|
-
} else {
|
|
770
|
-
const resolvedParent = this.resolveCreatePageParent(args.parent)
|
|
771
|
-
if (resolvedParent.status === "error") {
|
|
772
|
-
resolve(resolvedParent)
|
|
773
|
-
return
|
|
774
|
-
}
|
|
775
|
-
parent = resolvedParent.parent
|
|
776
|
-
propertyDataSource = resolvedParent.dataSource
|
|
777
|
-
}
|
|
778
|
-
const resolvedProperties = resolvePropertyWriteMapForDataSource({
|
|
779
|
-
dataSource: propertyDataSource,
|
|
780
|
-
properties: args.properties,
|
|
781
|
-
})
|
|
782
|
-
if (resolvedProperties.status === "error") {
|
|
783
|
-
resolve(resolvedProperties)
|
|
784
|
-
return
|
|
785
|
-
}
|
|
786
|
-
const requestId = this.pendingCreatePage.allocate(result => {
|
|
787
|
-
if (result.status === "error") {
|
|
788
|
-
resolve(result)
|
|
789
|
-
return
|
|
790
|
-
}
|
|
791
|
-
const update = async (
|
|
792
|
-
args: Parameters<SandboxBridge["updatePage"]>[0],
|
|
793
|
-
): Promise<UpdatePageResult> => {
|
|
794
|
-
const result = await this.updatePage(args)
|
|
795
|
-
if (result.status === "error") {
|
|
796
|
-
return result
|
|
797
|
-
}
|
|
798
|
-
Object.assign(page, result.page)
|
|
799
|
-
return { status: "success", page }
|
|
800
|
-
}
|
|
801
|
-
const page: NotionPage = toNotionPageFromBridgePage({
|
|
802
|
-
bridgePage: result.page,
|
|
803
|
-
dataSourceKey,
|
|
804
|
-
getPropertyById: propertyId =>
|
|
805
|
-
this.getPropertyById({ page, propertyId }),
|
|
806
|
-
getPropertyByKey: propertyKey =>
|
|
807
|
-
this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
808
|
-
updateById: payload =>
|
|
809
|
-
update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
810
|
-
updateByKey: makeUpdatePageByKey({
|
|
811
|
-
dataSource,
|
|
812
|
-
update: payload =>
|
|
813
|
-
update({ ...payload, pageId: page.id, dataSource }),
|
|
814
|
-
}),
|
|
815
|
-
})
|
|
816
|
-
resolve({ status: "success", page })
|
|
817
|
-
})
|
|
818
|
-
const outbound: CreatePageMessage = {
|
|
819
|
-
type: "createPage",
|
|
820
|
-
requestId,
|
|
821
|
-
parent,
|
|
822
|
-
properties: resolvedProperties.properties,
|
|
823
|
-
}
|
|
824
|
-
if (args.position !== undefined) {
|
|
825
|
-
outbound.position = args.position
|
|
826
|
-
}
|
|
827
|
-
this.postToHost(outbound)
|
|
421
|
+
const requestId = this.pendingCreatePage.allocate(resolve)
|
|
422
|
+
this.postToHost({ type: "createPage", requestId, ...args })
|
|
828
423
|
})
|
|
829
424
|
}
|
|
830
425
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}): Promise<GetPageResult> {
|
|
835
|
-
const { pageId, dataSource } = args
|
|
836
|
-
const dataSourceId = dataSource?.collectionPointer?.id
|
|
837
|
-
const dataSourceKey = dataSource?.key
|
|
426
|
+
requestGetPage(
|
|
427
|
+
args: Omit<GetPageMessage, "type" | "requestId">,
|
|
428
|
+
): Promise<BridgeMessagePayload<GetPageResultMessage>> {
|
|
838
429
|
return new Promise(resolve => {
|
|
839
|
-
const requestId = this.pendingGetPage.allocate(
|
|
840
|
-
|
|
841
|
-
resolve(result)
|
|
842
|
-
return
|
|
843
|
-
}
|
|
844
|
-
const update = async (
|
|
845
|
-
args: Parameters<SandboxBridge["updatePage"]>[0],
|
|
846
|
-
): Promise<UpdatePageResult> => {
|
|
847
|
-
const result = await this.updatePage(args)
|
|
848
|
-
if (result.status === "error") {
|
|
849
|
-
return result
|
|
850
|
-
}
|
|
851
|
-
Object.assign(page, result.page)
|
|
852
|
-
return { status: "success", page }
|
|
853
|
-
}
|
|
854
|
-
const page: NotionPage = toNotionPageFromBridgePage({
|
|
855
|
-
bridgePage: result.page,
|
|
856
|
-
dataSourceKey,
|
|
857
|
-
getPropertyById: propertyId =>
|
|
858
|
-
this.getPropertyById({ page, propertyId }),
|
|
859
|
-
getPropertyByKey: propertyKey =>
|
|
860
|
-
this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
861
|
-
updateById: payload =>
|
|
862
|
-
update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
863
|
-
updateByKey: makeUpdatePageByKey({
|
|
864
|
-
dataSource,
|
|
865
|
-
update: payload =>
|
|
866
|
-
update({ ...payload, pageId: page.id, dataSource }),
|
|
867
|
-
}),
|
|
868
|
-
})
|
|
869
|
-
resolve({ status: "success", page })
|
|
870
|
-
})
|
|
871
|
-
const outbound: GetPageMessage = {
|
|
872
|
-
type: "getPage",
|
|
873
|
-
requestId,
|
|
874
|
-
dataSourceId,
|
|
875
|
-
pageId,
|
|
876
|
-
}
|
|
877
|
-
this.postToHost(outbound)
|
|
430
|
+
const requestId = this.pendingGetPage.allocate(resolve)
|
|
431
|
+
this.postToHost({ type: "getPage", requestId, ...args })
|
|
878
432
|
})
|
|
879
433
|
}
|
|
880
434
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
): Promise<OpenPageResult> {
|
|
435
|
+
requestUpdatePage(
|
|
436
|
+
args: Omit<UpdatePageMessage, "type" | "requestId">,
|
|
437
|
+
): Promise<BridgeMessagePayload<UpdatePageResultMessage>> {
|
|
885
438
|
return new Promise(resolve => {
|
|
886
|
-
const requestId = this.
|
|
887
|
-
|
|
888
|
-
type: "openPage",
|
|
889
|
-
requestId,
|
|
890
|
-
pageId,
|
|
891
|
-
mode: options.mode,
|
|
892
|
-
}
|
|
893
|
-
this.postToHost(outbound)
|
|
439
|
+
const requestId = this.pendingUpdatePage.allocate(resolve)
|
|
440
|
+
this.postToHost({ type: "updatePage", requestId, ...args })
|
|
894
441
|
})
|
|
895
442
|
}
|
|
896
443
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const outbound: OpenExternalUrlMessage = {
|
|
901
|
-
type: "openExternalUrl",
|
|
902
|
-
requestId,
|
|
903
|
-
url,
|
|
904
|
-
}
|
|
905
|
-
this.postToHost(outbound)
|
|
906
|
-
})
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
getUser(userId: NotionUserId): Promise<GetUserResult> {
|
|
444
|
+
requestGetUser(
|
|
445
|
+
args: Omit<GetUserMessage, "type" | "requestId">,
|
|
446
|
+
): Promise<BridgeMessagePayload<GetUserResultMessage>> {
|
|
910
447
|
return new Promise(resolve => {
|
|
911
448
|
const requestId = this.pendingGetUser.allocate(resolve)
|
|
912
|
-
|
|
913
|
-
type: "getUser",
|
|
914
|
-
requestId,
|
|
915
|
-
userId,
|
|
916
|
-
}
|
|
917
|
-
this.postToHost(outbound)
|
|
449
|
+
this.postToHost({ type: "getUser", requestId, ...args })
|
|
918
450
|
})
|
|
919
451
|
}
|
|
920
452
|
|
|
921
|
-
|
|
453
|
+
requestListUsers(
|
|
454
|
+
args: Omit<ListUsersMessage, "type" | "requestId">,
|
|
455
|
+
): Promise<BridgeMessagePayload<ListUsersResultMessage>> {
|
|
922
456
|
return new Promise(resolve => {
|
|
923
457
|
const requestId = this.pendingListUsers.allocate(resolve)
|
|
924
|
-
|
|
925
|
-
type: "listUsers",
|
|
926
|
-
requestId,
|
|
927
|
-
startCursor: args.startCursor,
|
|
928
|
-
pageSize: args.pageSize,
|
|
929
|
-
}
|
|
930
|
-
this.postToHost(outbound)
|
|
458
|
+
this.postToHost({ type: "listUsers", requestId, ...args })
|
|
931
459
|
})
|
|
932
460
|
}
|
|
933
461
|
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
getPropertyByKey(args: {
|
|
943
|
-
page: NotionPage
|
|
944
|
-
dataSource: NotionDataSource | undefined
|
|
945
|
-
propertyKey: string
|
|
946
|
-
}) {
|
|
947
|
-
const { page, dataSource, propertyKey } = args
|
|
948
|
-
const currentDataSource =
|
|
949
|
-
this.hostState.status === "initialized"
|
|
950
|
-
? this.hostState.dataSources.find(
|
|
951
|
-
source => source.key === dataSource?.key,
|
|
952
|
-
)
|
|
953
|
-
: undefined
|
|
954
|
-
// Keep the captured mapping valid only while its key remains bound to the original database.
|
|
955
|
-
if (
|
|
956
|
-
!dataSource?.collectionPointer ||
|
|
957
|
-
currentDataSource?.collectionPointer?.id !==
|
|
958
|
-
dataSource.collectionPointer.id
|
|
959
|
-
) {
|
|
960
|
-
return null
|
|
961
|
-
}
|
|
962
|
-
const propertyId = Object.hasOwn(dataSource.propertyIdsByKey, propertyKey)
|
|
963
|
-
? dataSource.propertyIdsByKey[propertyKey]
|
|
964
|
-
: undefined
|
|
965
|
-
return propertyId === undefined
|
|
966
|
-
? null
|
|
967
|
-
: this.getPropertyById({ page, propertyId })
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
updatePage(args: {
|
|
971
|
-
pageId: NotionPageId
|
|
972
|
-
properties?: PageUpdatePayload["properties"]
|
|
973
|
-
icon?: PageUpdatePayload["icon"]
|
|
974
|
-
cover?: PageUpdatePayload["cover"]
|
|
975
|
-
is_archived?: PageUpdatePayload["is_archived"]
|
|
976
|
-
dataSource: NotionDataSource | undefined
|
|
977
|
-
}): Promise<BridgeMessagePayload<UpdatePageResultMessage>> {
|
|
978
|
-
const operation = async (): Promise<
|
|
979
|
-
BridgeMessagePayload<UpdatePageResultMessage>
|
|
980
|
-
> => {
|
|
981
|
-
const { dataSource } = args
|
|
982
|
-
const dataSourceId = dataSource?.collectionPointer?.id
|
|
983
|
-
const resolved = resolvePropertyWriteMapForDataSource({
|
|
984
|
-
dataSource,
|
|
985
|
-
properties: args.properties === undefined ? {} : args.properties,
|
|
986
|
-
})
|
|
987
|
-
if (resolved.status === "error") {
|
|
988
|
-
return resolved
|
|
989
|
-
}
|
|
990
|
-
if (
|
|
991
|
-
Object.keys(args.properties ?? {}).length === 0 &&
|
|
992
|
-
args.icon === undefined &&
|
|
993
|
-
args.cover === undefined &&
|
|
994
|
-
args.is_archived === undefined
|
|
995
|
-
) {
|
|
996
|
-
return {
|
|
997
|
-
status: "error",
|
|
998
|
-
error: {
|
|
999
|
-
code: "invalid_page_update",
|
|
1000
|
-
message: "updatePage requires at least one property.",
|
|
1001
|
-
isRetryable: false,
|
|
1002
|
-
},
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
const outbound: Omit<UpdatePageMessage, "requestId"> = {
|
|
1006
|
-
type: "updatePage",
|
|
1007
|
-
dataSourceId,
|
|
1008
|
-
pageId: args.pageId,
|
|
1009
|
-
}
|
|
1010
|
-
if (args.properties !== undefined) {
|
|
1011
|
-
outbound.properties = resolved.properties
|
|
1012
|
-
}
|
|
1013
|
-
if (args.icon !== undefined) {
|
|
1014
|
-
outbound.icon = args.icon
|
|
1015
|
-
}
|
|
1016
|
-
if (args.cover !== undefined) {
|
|
1017
|
-
outbound.cover = args.cover
|
|
1018
|
-
}
|
|
1019
|
-
if (args.is_archived !== undefined) {
|
|
1020
|
-
outbound.archived = args.is_archived
|
|
1021
|
-
}
|
|
1022
|
-
return new Promise<BridgeMessagePayload<UpdatePageResultMessage>>(
|
|
1023
|
-
resolve => {
|
|
1024
|
-
const requestId = this.pendingUpdatePage.allocate(resolve)
|
|
1025
|
-
this.postToHost({ ...outbound, requestId })
|
|
1026
|
-
},
|
|
1027
|
-
)
|
|
1028
|
-
}
|
|
1029
|
-
const pending = this.pendingPageUpdates.get(args.pageId)
|
|
1030
|
-
const result = pending ? pending.then(operation) : operation()
|
|
1031
|
-
const finished = result.then(
|
|
1032
|
-
() => undefined,
|
|
1033
|
-
() => undefined,
|
|
1034
|
-
)
|
|
1035
|
-
this.pendingPageUpdates.set(args.pageId, finished)
|
|
1036
|
-
void finished.then(() => {
|
|
1037
|
-
if (this.pendingPageUpdates.get(args.pageId) === finished) {
|
|
1038
|
-
this.pendingPageUpdates.delete(args.pageId)
|
|
1039
|
-
}
|
|
462
|
+
requestOpenPage(
|
|
463
|
+
args: Omit<OpenPageMessage, "type" | "requestId">,
|
|
464
|
+
): Promise<BridgeMessagePayload<OpenPageResultMessage>> {
|
|
465
|
+
return new Promise(resolve => {
|
|
466
|
+
const requestId = this.pendingOpenPage.allocate(resolve)
|
|
467
|
+
this.postToHost({ type: "openPage", requestId, ...args })
|
|
1040
468
|
})
|
|
1041
|
-
return result
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
/**
|
|
1045
|
-
* Translates the public `CreatePageArgs["parent"]` into the bridge-native
|
|
1046
|
-
* `CreatePageMessageParent`. The `data_source_key` variant is resolved sandbox-side against the
|
|
1047
|
-
* data source mapping the host delivered in `init` / `dataSourcesChanged`.
|
|
1048
|
-
*/
|
|
1049
|
-
private resolveCreatePageParent(parent: CreatePageArgs["parent"]):
|
|
1050
|
-
| {
|
|
1051
|
-
status: "ok"
|
|
1052
|
-
parent: CreatePageMessageParent
|
|
1053
|
-
dataSource: NotionDataSource | undefined
|
|
1054
|
-
}
|
|
1055
|
-
| { status: "error"; error: CustomBlockCreatePageErrorInfo } {
|
|
1056
|
-
switch (parent.type) {
|
|
1057
|
-
case "page_id":
|
|
1058
|
-
return { status: "ok", parent, dataSource: undefined }
|
|
1059
|
-
case "data_source_id":
|
|
1060
|
-
return { status: "ok", parent, dataSource: undefined }
|
|
1061
|
-
case "data_source_key": {
|
|
1062
|
-
if (this.hostState.status !== "initialized") {
|
|
1063
|
-
return {
|
|
1064
|
-
status: "error",
|
|
1065
|
-
error: {
|
|
1066
|
-
code: "unknown_data_source_key",
|
|
1067
|
-
message: `Cannot resolve data source key "${parent.key}" before the host has initialized the SDK.`,
|
|
1068
|
-
isRetryable: false,
|
|
1069
|
-
},
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
const dataSource = this.hostState.dataSources.find(
|
|
1073
|
-
entry => entry.key === parent.key,
|
|
1074
|
-
)
|
|
1075
|
-
if (dataSource === undefined) {
|
|
1076
|
-
return {
|
|
1077
|
-
status: "error",
|
|
1078
|
-
error: {
|
|
1079
|
-
code: "unknown_data_source_key",
|
|
1080
|
-
message: `Unknown data source key "${parent.key}". Known keys: [${this.hostState.dataSources.map(entry => entry.key).join(", ")}].`,
|
|
1081
|
-
isRetryable: false,
|
|
1082
|
-
},
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
if (dataSource.collectionPointer === undefined) {
|
|
1086
|
-
return {
|
|
1087
|
-
status: "error",
|
|
1088
|
-
error: {
|
|
1089
|
-
code: "unmapped_data_source",
|
|
1090
|
-
message: `Data source "${parent.key}" has not been mapped to a database yet.`,
|
|
1091
|
-
isRetryable: false,
|
|
1092
|
-
},
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
return {
|
|
1096
|
-
status: "ok",
|
|
1097
|
-
parent: {
|
|
1098
|
-
type: "data_source_id",
|
|
1099
|
-
data_source_id: dataSource.collectionPointer.id,
|
|
1100
|
-
},
|
|
1101
|
-
dataSource,
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
default:
|
|
1105
|
-
unreachable(parent)
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
function getInitialContentHeight(): number {
|
|
1111
|
-
if (typeof document === "undefined") {
|
|
1112
|
-
return 0
|
|
1113
469
|
}
|
|
1114
|
-
const root = document.getElementById("root")
|
|
1115
|
-
if (root === null) {
|
|
1116
|
-
return 0
|
|
1117
|
-
}
|
|
1118
|
-
return Math.ceil(root.getBoundingClientRect().height)
|
|
1119
|
-
}
|
|
1120
470
|
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
function syncDocumentAppearance(args: {
|
|
1129
|
-
theme: NotionTheme
|
|
1130
|
-
contrastMode: NotionContrastMode
|
|
1131
|
-
}): void {
|
|
1132
|
-
if (typeof document === "undefined") {
|
|
1133
|
-
return
|
|
471
|
+
requestOpenExternalUrl(
|
|
472
|
+
args: Omit<OpenExternalUrlMessage, "type" | "requestId">,
|
|
473
|
+
): Promise<BridgeMessagePayload<OpenExternalUrlResultMessage>> {
|
|
474
|
+
return new Promise(resolve => {
|
|
475
|
+
const requestId = this.pendingOpenExternalUrl.allocate(resolve)
|
|
476
|
+
this.postToHost({ type: "openExternalUrl", requestId, ...args })
|
|
477
|
+
})
|
|
1134
478
|
}
|
|
1135
|
-
const { theme, contrastMode } = args
|
|
1136
|
-
const root = document.documentElement
|
|
1137
|
-
root.dataset.displayMode = theme
|
|
1138
|
-
root.dataset.contrastMode = contrastMode
|
|
1139
|
-
root.style.colorScheme = theme
|
|
1140
|
-
root.style.backgroundColor =
|
|
1141
|
-
theme === "dark"
|
|
1142
|
-
? NOTION_DARK_BACKGROUND_BASE
|
|
1143
|
-
: NOTION_LIGHT_BACKGROUND_BASE
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
/**
|
|
1147
|
-
* `postMessage` cloning creates new objects even for bindings that did not change. Preserve their
|
|
1148
|
-
* resolved object identity so React effects only run for changed bindings.
|
|
1149
|
-
*
|
|
1150
|
-
* This comparison runs when the host sends an update instead of on every component render. Bindings
|
|
1151
|
-
* are validated JSON-like bridge payloads, so serialization is sufficient here.
|
|
1152
|
-
*/
|
|
1153
|
-
function reuseDataSourcesForUnchangedBindings(args: {
|
|
1154
|
-
previousDataSources: NotionDataSource[]
|
|
1155
|
-
previousBindings: NotionDataSourceBindings
|
|
1156
|
-
nextDataSources: NotionDataSource[]
|
|
1157
|
-
nextBindings: NotionDataSourceBindings
|
|
1158
|
-
}): NotionDataSource[] {
|
|
1159
|
-
const previousDataSourcesByKey = new Map(
|
|
1160
|
-
args.previousDataSources.map(dataSource => [dataSource.key, dataSource]),
|
|
1161
|
-
)
|
|
1162
|
-
|
|
1163
|
-
return args.nextDataSources.map(dataSource => {
|
|
1164
|
-
const previousDataSource = previousDataSourcesByKey.get(dataSource.key)
|
|
1165
|
-
if (
|
|
1166
|
-
previousDataSource !== undefined &&
|
|
1167
|
-
JSON.stringify(args.previousBindings[dataSource.key]) ===
|
|
1168
|
-
JSON.stringify(args.nextBindings[dataSource.key])
|
|
1169
|
-
) {
|
|
1170
|
-
return previousDataSource
|
|
1171
|
-
}
|
|
1172
|
-
return dataSource
|
|
1173
|
-
})
|
|
1174
479
|
}
|
|
1175
480
|
|
|
1176
481
|
function invalidInitPayloadError(
|
|
@@ -1210,51 +515,6 @@ function redactExternalUrl(data: unknown): unknown {
|
|
|
1210
515
|
return data
|
|
1211
516
|
}
|
|
1212
517
|
|
|
1213
|
-
function getInitBindingError(
|
|
1214
|
-
manifest: CustomBlockManifest,
|
|
1215
|
-
dataSources: NotionDataSource[],
|
|
1216
|
-
): CustomBlockInitResultErrorInfo | undefined {
|
|
1217
|
-
for (const [dataSourceKey, manifestDataSource] of Object.entries(
|
|
1218
|
-
manifest.dataSources,
|
|
1219
|
-
)) {
|
|
1220
|
-
const dataSource = dataSources.find(entry => entry.key === dataSourceKey)
|
|
1221
|
-
if (
|
|
1222
|
-
dataSource?.collectionPointer === undefined ||
|
|
1223
|
-
dataSource.collectionSchema === undefined
|
|
1224
|
-
) {
|
|
1225
|
-
return {
|
|
1226
|
-
code: "invalid_init_bindings",
|
|
1227
|
-
message: `Host did not provide a complete binding for data source "${dataSourceKey}".`,
|
|
1228
|
-
isRetryable: false,
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
for (const propertyKey of Object.keys(
|
|
1232
|
-
manifestDataSource.properties ?? {},
|
|
1233
|
-
)) {
|
|
1234
|
-
if (dataSource.propertyIdsByKey[propertyKey] === undefined) {
|
|
1235
|
-
return {
|
|
1236
|
-
code: "invalid_init_bindings",
|
|
1237
|
-
message: `Host did not provide a valid binding for property "${dataSourceKey}.${propertyKey}".`,
|
|
1238
|
-
isRetryable: false,
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
return undefined
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
function resolveMockDataSources(
|
|
1247
|
-
bindings: NotionDataSourceBindings,
|
|
1248
|
-
): NotionDataSource[] {
|
|
1249
|
-
return Object.entries(bindings).map(([key, binding]) => ({
|
|
1250
|
-
key,
|
|
1251
|
-
collectionPointer: binding.collectionPointer,
|
|
1252
|
-
collectionSchema: binding.collectionSchema,
|
|
1253
|
-
propertyIdsByKey: { ...(binding.propertyIdsByKey ?? {}) },
|
|
1254
|
-
propertySchemasById: binding.collectionSchema?.propertiesById ?? {},
|
|
1255
|
-
}))
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
518
|
function formatInvalidHostReason(
|
|
1259
519
|
incomingType: string | undefined,
|
|
1260
520
|
issues: readonly v.BaseIssue<unknown>[],
|