@puredesktop/puredesktop-ui-bridge 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +96 -0
- package/src/agents/runtime/agentLiveReducer.test.ts +72 -0
- package/src/agents/runtime/agentLiveReducer.ts +139 -0
- package/src/agents/runtime/agentRunEventTypes.ts +115 -0
- package/src/agents/runtime/contextWindowUsage.test.ts +38 -0
- package/src/agents/runtime/contextWindowUsage.ts +25 -0
- package/src/agents/runtime/index.ts +24 -0
- package/src/agents/runtime/mapAgentMessages.ts +54 -0
- package/src/agents/runtime/mapAgentSnapshot.ts +71 -0
- package/src/agents/runtime/mergeUsageTurn.ts +23 -0
- package/src/agents/runtime/pendingToolCalls.test.ts +85 -0
- package/src/agents/runtime/pendingToolCalls.ts +14 -0
- package/src/agents/runtime/toolRequiresApproval.ts +20 -0
- package/src/agents/runtime/unresolvedToolCalls.ts +42 -0
- package/src/bridge/agentModelTiers.ts +50 -0
- package/src/bridge/agentToolHandlers.ts +23 -0
- package/src/bridge/agentToolHelpers.test.ts +27 -0
- package/src/bridge/agentToolHelpers.ts +20 -0
- package/src/bridge/agentTypes.ts +294 -0
- package/src/bridge/agents.d.mts +113 -0
- package/src/bridge/agents.mjs +233 -0
- package/src/bridge/agents.ts +62 -0
- package/src/bridge/appSettings.d.mts +9 -0
- package/src/bridge/appSettings.mjs +18 -0
- package/src/bridge/appSettings.ts +4 -0
- package/src/bridge/applyThemeFromHost.d.mts +7 -0
- package/src/bridge/applyThemeFromHost.mjs +33 -0
- package/src/bridge/assets.d.mts +66 -0
- package/src/bridge/assets.mjs +121 -0
- package/src/bridge/catalog.d.mts +5 -0
- package/src/bridge/catalog.mjs +24 -0
- package/src/bridge/catalog.ts +1 -0
- package/src/bridge/client.d.mts +19 -0
- package/src/bridge/client.mjs +147 -0
- package/src/bridge/collectionAssetAdapter.ts +63 -0
- package/src/bridge/collectionAssets.d.mts +1 -0
- package/src/bridge/collectionAssets.mjs +2 -0
- package/src/bridge/collectionAssets.ts +1 -0
- package/src/bridge/collectionDocumentHtml.test.ts +71 -0
- package/src/bridge/collectionDocumentHtml.ts +118 -0
- package/src/bridge/collectionImagePaste.test.ts +32 -0
- package/src/bridge/collectionImagePaste.ts +130 -0
- package/src/bridge/context.mjs +12 -0
- package/src/bridge/credentials.mjs +22 -0
- package/src/bridge/dialog.d.mts +5 -0
- package/src/bridge/dialog.mjs +13 -0
- package/src/bridge/events.d.mts +14 -0
- package/src/bridge/events.mjs +12 -0
- package/src/bridge/filePreviewKind.test.ts +43 -0
- package/src/bridge/filePreviewKind.ts +76 -0
- package/src/bridge/fs.d.mts +41 -0
- package/src/bridge/fs.mjs +82 -0
- package/src/bridge/fs.test.ts +16 -0
- package/src/bridge/fs.ts +10 -0
- package/src/bridge/index.ts +12 -0
- package/src/bridge/inlinePreview.d.mts +35 -0
- package/src/bridge/inlinePreview.mjs +99 -0
- package/src/bridge/inlinePreview.test.ts +56 -0
- package/src/bridge/inlinePreview.ts +13 -0
- package/src/bridge/methods.d.mts +115 -0
- package/src/bridge/methods.mjs +132 -0
- package/src/bridge/os.d.mts +11 -0
- package/src/bridge/os.mjs +26 -0
- package/src/bridge/plugins.d.mts +9 -0
- package/src/bridge/plugins.mjs +31 -0
- package/src/bridge/plugins.ts +5 -0
- package/src/bridge/preferences.d.mts +7 -0
- package/src/bridge/preferences.mjs +17 -0
- package/src/bridge/preferences.ts +13 -0
- package/src/bridge/printDocument.test.ts +47 -0
- package/src/bridge/printDocument.ts +75 -0
- package/src/bridge/pureRender/adapters.test.ts +144 -0
- package/src/bridge/pureRender/adapters.ts +175 -0
- package/src/bridge/pureRender/assets.test.ts +44 -0
- package/src/bridge/pureRender/base.css +76 -0
- package/src/bridge/pureRender/compiler.test.ts +279 -0
- package/src/bridge/pureRender/compiler.ts +660 -0
- package/src/bridge/pureRender/document.test.ts +283 -0
- package/src/bridge/pureRender/document.ts +35 -0
- package/src/bridge/pureRender/extraction.test.ts +432 -0
- package/src/bridge/pureRender/extraction.ts +1023 -0
- package/src/bridge/pureRender/flow.css +3 -0
- package/src/bridge/pureRender/index.ts +66 -0
- package/src/bridge/pureRender/normalize.test.ts +442 -0
- package/src/bridge/pureRender/normalize.ts +682 -0
- package/src/bridge/pureRender/presets.ts +365 -0
- package/src/bridge/pureRender/profiles/book.css +19 -0
- package/src/bridge/pureRender/profiles/manuscript.css +11 -0
- package/src/bridge/pureRender/profiles/writer.css +10 -0
- package/src/bridge/pureRender/reset.css +5 -0
- package/src/bridge/pureRender/samples.ts +94 -0
- package/src/bridge/pureRender/styles.ts +164 -0
- package/src/bridge/pureRender/theme.test.ts +53 -0
- package/src/bridge/pureRender/theme.ts +258 -0
- package/src/bridge/pureRender/tokens/default.css +36 -0
- package/src/bridge/pureRender/tokens/default.json +32 -0
- package/src/bridge/pureRender/types.ts +264 -0
- package/src/bridge/pureRender/visualLayoutInspection.test.ts +57 -0
- package/src/bridge/pureRender/visualLayoutInspection.ts +161 -0
- package/src/bridge/react/useDebouncedEffect.ts +21 -0
- package/src/bridge/react/useIpc.tsx +75 -0
- package/src/bridge/react/usePlatformAgentRunLiveState.tsx +78 -0
- package/src/bridge/react/usePlatformAgentSessionDrive.tsx +729 -0
- package/src/bridge/react/usePlatformAgentSessions.tsx +60 -0
- package/src/bridge/react/usePlatformAgentTools.tsx +82 -0
- package/src/bridge/react/usePlatformAppManifest.tsx +32 -0
- package/src/bridge/react/usePlatformBridge.tsx +56 -0
- package/src/bridge/react/usePlatformDeepLink.tsx +57 -0
- package/src/bridge/react/usePlatformFileBinaryDataUrl.tsx +54 -0
- package/src/bridge/react/usePlatformFilePreview.tsx +92 -0
- package/src/bridge/react/usePlatformPreferences.tsx +77 -0
- package/src/bridge/react/usePlatformThemeDocumentAttrs.ts +35 -0
- package/src/bridge/react/usePlatformThemeFromBridge.tsx +16 -0
- package/src/bridge/react/usePlatformViewportResource.test.tsx +106 -0
- package/src/bridge/react/usePlatformViewportResource.tsx +72 -0
- package/src/bridge/react/useScheduledTask.tsx +59 -0
- package/src/bridge/render.d.mts +31 -0
- package/src/bridge/render.mjs +62 -0
- package/src/bridge/render.ts +8 -0
- package/src/bridge/screenAnnotation.test.ts +103 -0
- package/src/bridge/screenAnnotation.ts +269 -0
- package/src/bridge/theme.d.mts +3 -0
- package/src/bridge/theme.mjs +9 -0
- package/src/bridge/types.ts +439 -0
- package/src/bridge/watch.d.mts +9 -0
- package/src/bridge/watch.mjs +34 -0
- package/src/bridge/watch.ts +1 -0
- package/src/bridge/window.d.mts +44 -0
- package/src/bridge/window.mjs +33 -0
- package/src/chrome/index.ts +1 -0
- package/src/components/accessibility/AccessibilityReviewDialog.test.tsx +104 -0
- package/src/components/accessibility/AccessibilityReviewDialog.tsx +350 -0
- package/src/components/accessibility/accessibilityReview.test.ts +101 -0
- package/src/components/accessibility/accessibilityReview.ts +639 -0
- package/src/components/accessibility/index.ts +16 -0
- package/src/components/agent-feedback/ScreenAnnotationAgentDialog.tsx +509 -0
- package/src/components/agent-feedback/index.ts +5 -0
- package/src/components/agents/AgentComposer.tsx +34 -0
- package/src/components/agents/AgentContextUsageBar.tsx +127 -0
- package/src/components/agents/AgentDrawerPanel.tsx +82 -0
- package/src/components/agents/AgentMarkdown.tsx +12 -0
- package/src/components/agents/AgentMessageBubble.tsx +82 -0
- package/src/components/agents/AgentMessageList.tsx +47 -0
- package/src/components/agents/AgentModelMenu.tsx +55 -0
- package/src/components/agents/AgentThinkingBlock.tsx +66 -0
- package/src/components/agents/AgentToolApprovalActions.tsx +65 -0
- package/src/components/agents/AgentToolCallCard.tsx +26 -0
- package/src/components/agents/AgentToolPendingList.tsx +39 -0
- package/src/components/agents/AgentToolPendingReview.tsx +118 -0
- package/src/components/agents/agentPanelStyles.ts +79 -0
- package/src/components/agents/agentTypes.ts +96 -0
- package/src/components/agents/formatToolCallArguments.test.ts +16 -0
- package/src/components/agents/formatToolCallArguments.ts +9 -0
- package/src/components/agents/index.ts +40 -0
- package/src/components/assets/AssetLibraryDialog.tsx +5 -0
- package/src/components/assets/asset-library/AssetLibraryDialog.tsx +43 -0
- package/src/components/assets/asset-library/AssetLibraryWorkspace.tsx +54 -0
- package/src/components/assets/asset-library/detail/AssetLibraryDetailActions.tsx +68 -0
- package/src/components/assets/asset-library/detail/AssetLibraryDetailHeader.tsx +56 -0
- package/src/components/assets/asset-library/detail/AssetLibraryDetailPane.tsx +90 -0
- package/src/components/assets/asset-library/detail/AssetLibraryDetailPreview.tsx +67 -0
- package/src/components/assets/asset-library/detail/AssetLibraryInlinePreview.tsx +87 -0
- package/src/components/assets/asset-library/detail/AssetLibraryInlineSourceField.tsx +29 -0
- package/src/components/assets/asset-library/detail/AssetLibraryMetadataFields.tsx +34 -0
- package/src/components/assets/asset-library/detail/AssetLibraryUsagePanel.tsx +46 -0
- package/src/components/assets/asset-library/detail/AssetLibraryVersionsPanel.tsx +145 -0
- package/src/components/assets/asset-library/helpers/assetKind.ts +74 -0
- package/src/components/assets/asset-library/helpers.ts +41 -0
- package/src/components/assets/asset-library/hooks/useAssetDetailDraft.ts +81 -0
- package/src/components/assets/asset-library/hooks/useAssetLibraryDialog.ts +233 -0
- package/src/components/assets/asset-library/hooks/useAssetLibraryMutations.ts +266 -0
- package/src/components/assets/asset-library/hooks/useAssetLibrarySelectionSync.ts +24 -0
- package/src/components/assets/asset-library/hooks/useAssetLibraryVersions.ts +145 -0
- package/src/components/assets/asset-library/hooks/useInlineAssetPreview.ts +44 -0
- package/src/components/assets/asset-library/index.ts +19 -0
- package/src/components/assets/asset-library/layout/assetLibraryLayout.ts +201 -0
- package/src/components/assets/asset-library/shared/fieldStyles.ts +62 -0
- package/src/components/assets/asset-library/sidebar/AssetLibraryFilterPills.tsx +89 -0
- package/src/components/assets/asset-library/sidebar/AssetLibraryList.tsx +91 -0
- package/src/components/assets/asset-library/sidebar/AssetLibraryListRow.tsx +99 -0
- package/src/components/assets/asset-library/sidebar/AssetLibraryListStatus.tsx +24 -0
- package/src/components/assets/asset-library/sidebar/AssetLibrarySidebar.tsx +48 -0
- package/src/components/assets/asset-library/sidebar/AssetLibrarySidebarActions.tsx +38 -0
- package/src/components/assets/asset-library/sidebar/AssetLibrarySidebarToolbar.tsx +78 -0
- package/src/components/assets/asset-library/sidebar/AssetListThumbnail.tsx +86 -0
- package/src/components/assets/asset-library/types.ts +128 -0
- package/src/components/assets/asset-library/utils/assetLibraryUtils.ts +181 -0
- package/src/components/assets/asset-library/utils/pathBasename.ts +5 -0
- package/src/components/assets/asset-library/utils/sanitizeUploadFileName.ts +7 -0
- package/src/components/assets/asset-library/utils/uploadCollectionAsset.ts +52 -0
- package/src/components/chrome/OverlayActionCapsule.test.tsx +82 -0
- package/src/components/chrome/OverlayActionCapsule.tsx +90 -0
- package/src/components/chrome/PanelTabStrip.tsx +113 -0
- package/src/components/chrome/PlatformIcon.tsx +27 -0
- package/src/components/chrome/PureAppWordmark.tsx +89 -0
- package/src/components/chrome/ShellWindowControls.tsx +51 -0
- package/src/components/chrome/ThemeModeButton.tsx +16 -0
- package/src/components/chrome/Titlebar.tsx +79 -0
- package/src/components/chrome/WorkspaceTabStrip.tsx +300 -0
- package/src/components/chrome/index.ts +31 -0
- package/src/components/chrome/workspaceTabTypes.ts +29 -0
- package/src/components/common/buttons/Button.tsx +241 -0
- package/src/components/common/buttons/ChoiceChip.tsx +73 -0
- package/src/components/common/buttons/CleanButton.tsx +34 -0
- package/src/components/common/buttons/IconButton.tsx +89 -0
- package/src/components/common/buttons/QuietAction.tsx +29 -0
- package/src/components/common/buttons/SegmentedControl.tsx +67 -0
- package/src/components/common/buttons/TextActionButton.tsx +55 -0
- package/src/components/common/buttons/TextLink.tsx +38 -0
- package/src/components/common/canvas/CanvasElementFrame.test.tsx +79 -0
- package/src/components/common/canvas/CanvasElementFrame.tsx +182 -0
- package/src/components/common/canvas/canvasGeometry.test.ts +66 -0
- package/src/components/common/canvas/canvasGeometry.ts +133 -0
- package/src/components/common/canvas/index.ts +27 -0
- package/src/components/common/canvas/useCanvasDragResize.test.tsx +152 -0
- package/src/components/common/canvas/useCanvasDragResize.ts +161 -0
- package/src/components/common/chat/ChatAssistantMessage.tsx +81 -0
- package/src/components/common/chat/ChatBox.tsx +189 -0
- package/src/components/common/chat/ChatMarkdown.tsx +109 -0
- package/src/components/common/chat/ChatModelMenu.tsx +258 -0
- package/src/components/common/chat/ChatStatusRow.tsx +24 -0
- package/src/components/common/chat/ChatThinkingIndicator.tsx +54 -0
- package/src/components/common/chat/ChatThread.tsx +59 -0
- package/src/components/common/chat/ChatToolRow.tsx +141 -0
- package/src/components/common/chat/ChatUserBubble.tsx +45 -0
- package/src/components/common/chat/chatUtils.ts +7 -0
- package/src/components/common/chat/index.ts +24 -0
- package/src/components/common/connections/ConnectionSetup.tsx +529 -0
- package/src/components/common/connections/index.ts +26 -0
- package/src/components/common/containers/AppFrame.test.tsx +47 -0
- package/src/components/common/containers/AppFrame.tsx +65 -0
- package/src/components/common/containers/AppHeader.tsx +60 -0
- package/src/components/common/containers/AutoFillGrid.tsx +37 -0
- package/src/components/common/containers/Collapsible.tsx +43 -0
- package/src/components/common/containers/CollapsibleGrid.tsx +174 -0
- package/src/components/common/containers/MotionScope.tsx +32 -0
- package/src/components/common/containers/PageHeader.tsx +35 -0
- package/src/components/common/containers/PanelToolbarHeader.tsx +113 -0
- package/src/components/common/containers/QuietDisclosure.tsx +91 -0
- package/src/components/common/containers/QuietSurface.tsx +41 -0
- package/src/components/common/containers/ScrollPanel.tsx +33 -0
- package/src/components/common/containers/StatusBar.tsx +42 -0
- package/src/components/common/containers/SurfacePanel.tsx +66 -0
- package/src/components/common/containers/ToolbarStrip.tsx +80 -0
- package/src/components/common/containers/flex.ts +117 -0
- package/src/components/common/containers/useOpenTransition.ts +33 -0
- package/src/components/common/context/ContextSelector.tsx +269 -0
- package/src/components/common/context/index.ts +7 -0
- package/src/components/common/desk/ActionReader.tsx +270 -0
- package/src/components/common/desk/ActivityLedger.tsx +143 -0
- package/src/components/common/desk/CreationDesk.tsx +139 -0
- package/src/components/common/desk/DailyBrief.tsx +160 -0
- package/src/components/common/desk/DeskCard.tsx +157 -0
- package/src/components/common/desk/index.ts +30 -0
- package/src/components/common/dropdown/ContextMenu.tsx +87 -0
- package/src/components/common/dropdown/MenuButtonDropdown.tsx +121 -0
- package/src/components/common/dropdown/MenuDropdown.tsx +63 -0
- package/src/components/common/dropdown/MenuDropdownEntry.tsx +51 -0
- package/src/components/common/dropdown/MenuDropdownItem.tsx +82 -0
- package/src/components/common/dropdown/MenuDropdownSubmenu.tsx +145 -0
- package/src/components/common/dropdown/MenuPanel.tsx +69 -0
- package/src/components/common/dropdown/MenuPortal.tsx +162 -0
- package/src/components/common/dropdown/MenuPortalLayer.tsx +6 -0
- package/src/components/common/dropdown/SelectMenu.tsx +243 -0
- package/src/components/common/dropdown/SelectMenuControl.tsx +23 -0
- package/src/components/common/dropdown/SelectMenuOptions.tsx +38 -0
- package/src/components/common/dropdown/menuPortalConstants.ts +11 -0
- package/src/components/common/dropdown/menuTypes.ts +71 -0
- package/src/components/common/dropdown/menuViewportPosition.test.ts +139 -0
- package/src/components/common/dropdown/menuViewportPosition.ts +122 -0
- package/src/components/common/dropdown/selectMenuLayout.test.ts +42 -0
- package/src/components/common/dropdown/selectMenuLayout.ts +123 -0
- package/src/components/common/dropdown/useMenuAnchorPosition.ts +109 -0
- package/src/components/common/dropdown/useSelectMenuAnchor.ts +30 -0
- package/src/components/common/evidence/StructuredEvidenceView.test.tsx +77 -0
- package/src/components/common/evidence/StructuredEvidenceView.tsx +312 -0
- package/src/components/common/evidence/index.ts +13 -0
- package/src/components/common/feedback/Badge.tsx +33 -0
- package/src/components/common/feedback/CapabilityPills.tsx +36 -0
- package/src/components/common/feedback/EmptyState.tsx +132 -0
- package/src/components/common/feedback/InfoHint.tsx +67 -0
- package/src/components/common/feedback/InlineBanner.tsx +82 -0
- package/src/components/common/feedback/PlatformChip.tsx +104 -0
- package/src/components/common/feedback/QuietPill.tsx +75 -0
- package/src/components/common/feedback/WorkProgressPanel.tsx +156 -0
- package/src/components/common/feedback/index.ts +33 -0
- package/src/components/common/inputs/BareInput.tsx +31 -0
- package/src/components/common/inputs/BareTextarea.tsx +10 -0
- package/src/components/common/inputs/Checkbox.tsx +13 -0
- package/src/components/common/inputs/FieldControlShell.tsx +49 -0
- package/src/components/common/inputs/FormField.tsx +40 -0
- package/src/components/common/inputs/HybridSearchField.tsx +280 -0
- package/src/components/common/inputs/InlineComposer.tsx +197 -0
- package/src/components/common/inputs/PaletteCirclePicker.tsx +26 -0
- package/src/components/common/inputs/PaletteDropdown.tsx +413 -0
- package/src/components/common/inputs/Radio.tsx +19 -0
- package/src/components/common/inputs/SearchField.tsx +128 -0
- package/src/components/common/inputs/SelectField.tsx +169 -0
- package/src/components/common/inputs/SurfacePalettePicker.tsx +54 -0
- package/src/components/common/inputs/TextAreaField.tsx +22 -0
- package/src/components/common/inputs/TextField.tsx +51 -0
- package/src/components/common/inputs/ToggleSwitch.tsx +110 -0
- package/src/components/common/inputs/WorkspacePicker.tsx +349 -0
- package/src/components/common/inputs/fieldStyles.ts +137 -0
- package/src/components/common/layout/PanelGroup.tsx +479 -0
- package/src/components/common/layout/index.ts +31 -0
- package/src/components/common/layout/panelLayoutConstants.ts +7 -0
- package/src/components/common/layout/panelLayoutPersistence.ts +35 -0
- package/src/components/common/layout/panelLayoutState.test.ts +38 -0
- package/src/components/common/layout/panelLayoutState.ts +174 -0
- package/src/components/common/layout/panelLayoutTypes.ts +19 -0
- package/src/components/common/layout/tabs/Tabs.tsx +136 -0
- package/src/components/common/lists/listRowStyles.ts +32 -0
- package/src/components/common/lists/quiet-ledger/QuietActivityList.tsx +64 -0
- package/src/components/common/lists/quiet-ledger/QuietLedgerRow.tsx +119 -0
- package/src/components/common/lists/quiet-ledger/index.ts +9 -0
- package/src/components/common/lists/reorderable/DragHandle.tsx +65 -0
- package/src/components/common/lists/reorderable/ReorderableList.tsx +280 -0
- package/src/components/common/lists/reorderable/ReorderableListRow.tsx +102 -0
- package/src/components/common/lists/reorderable/ReorderableSections.tsx +344 -0
- package/src/components/common/lists/reorderable/ReorderableSectionsDemo.tsx +94 -0
- package/src/components/common/lists/reorderable/index.ts +15 -0
- package/src/components/common/lists/reorderable/reorderableUtils.test.ts +28 -0
- package/src/components/common/lists/reorderable/reorderableUtils.ts +23 -0
- package/src/components/common/lists/reorderable/types.ts +40 -0
- package/src/components/common/lists/reorderable/useReorderableDragState.ts +49 -0
- package/src/components/common/media/ImageReferencePicker.tsx +242 -0
- package/src/components/common/menubar/MenuBar.tsx +78 -0
- package/src/components/common/menubar/MenuBarTrigger.tsx +70 -0
- package/src/components/common/narrative/NarrativeMention.tsx +74 -0
- package/src/components/common/navigation/PathBreadcrumbs.tsx +78 -0
- package/src/components/common/navigation/UnderlineTabs.tsx +83 -0
- package/src/components/common/overlays/InstallAppPromptDialog.tsx +59 -0
- package/src/components/common/overlays/Modal.tsx +285 -0
- package/src/components/common/overlays/ModalChromeHeader.tsx +105 -0
- package/src/components/common/overlays/ObjectActionStrip.tsx +80 -0
- package/src/components/common/people/AutoUpdateReviewList.tsx +182 -0
- package/src/components/common/people/EntityList.tsx +122 -0
- package/src/components/common/people/EntityPortrait.tsx +64 -0
- package/src/components/common/people/LinkedDossierList.tsx +99 -0
- package/src/components/common/people/OpportunityList.tsx +94 -0
- package/src/components/common/people/PeopleSourceList.tsx +145 -0
- package/src/components/common/people/RelationshipDossier.tsx +168 -0
- package/src/components/common/people/RelationshipMap.tsx +362 -0
- package/src/components/common/people/index.ts +40 -0
- package/src/components/common/preview/FileAudioPreview.tsx +89 -0
- package/src/components/common/preview/FileImagePreview.tsx +88 -0
- package/src/components/common/preview/FilePdfPreview.tsx +87 -0
- package/src/components/common/preview/FileTextPreview.tsx +96 -0
- package/src/components/common/preview/FileVideoPreview.tsx +87 -0
- package/src/components/common/preview/PlatformFilePreview.tsx +166 -0
- package/src/components/common/preview/previewLayout.ts +27 -0
- package/src/components/common/render/Each.tsx +42 -0
- package/src/components/common/research/EvidenceDossier.tsx +894 -0
- package/src/components/common/research/index.ts +7 -0
- package/src/components/common/tiles/CatalogCard.tsx +116 -0
- package/src/components/common/tiles/Tile.tsx +45 -0
- package/src/components/common/tiles/TileGrid.tsx +13 -0
- package/src/components/common/typography/Heading.tsx +27 -0
- package/src/components/common/typography/Kicker.tsx +30 -0
- package/src/components/common/typography/Text.tsx +80 -0
- package/src/components/credentials/CredentialsPanel.tsx +169 -0
- package/src/components/credentials/credentialsTypes.ts +14 -0
- package/src/components/data/DataChart.tsx +913 -0
- package/src/components/data/dataTable.ts +99 -0
- package/src/components/editor/EditorCommentPromptDialog.tsx +124 -0
- package/src/components/editor/EditorLinkPromptDialog.tsx +65 -0
- package/src/components/print-design/PrintDesignPanel.test.tsx +1446 -0
- package/src/components/print-design/PrintDesignPanel.tsx +3043 -0
- package/src/components/print-design/index.ts +9 -0
- package/src/components/proofing/PagedProofDialog.tsx +453 -0
- package/src/components/proofing/index.ts +4 -0
- package/src/editor/DocumentEditor.tsx +28 -0
- package/src/editor/EditorViewModeToggle.tsx +35 -0
- package/src/editor/index.ts +97 -0
- package/src/editor/toolbarOverlays.ts +8 -0
- package/src/index.ts +209 -0
- package/src/theme/ThemeProvider.tsx +113 -0
- package/src/theme/appAccents.ts +87 -0
- package/src/theme/buildThemeBridgePayload.ts +23 -0
- package/src/theme/composePlatformTheme.test.ts +30 -0
- package/src/theme/composePlatformTheme.ts +23 -0
- package/src/theme/platformFont.d.mts +7 -0
- package/src/theme/platformFont.mjs +20 -0
- package/src/theme/platformFont.ts +6 -0
- package/src/theme/reportsShellChromeSelectors.ts +136 -0
- package/src/theme/styled.d.ts +5 -0
- package/src/theme/surfacePalettes.ts +178 -0
- package/src/theme/surfaceRoleSelectors.ts +113 -0
- package/src/theme/themeVars.ts +13 -0
- package/src/theme/themes/dark.ts +59 -0
- package/src/theme/themes/light.ts +60 -0
- package/src/theme/themes/palette.ts +44 -0
- package/src/theme/themes/shared.ts +68 -0
- package/src/theme/tokens.ts +114 -0
- package/src/theme/utils/GlobalStyles.ts +88 -0
- package/src/theme/utils/appFrameDocumentStyles.d.mts +5 -0
- package/src/theme/utils/appFrameDocumentStyles.mjs +89 -0
- package/src/theme/utils/appFrameDocumentStyles.ts +5 -0
- package/src/theme/utils/applyTheme.ts +50 -0
- package/src/theme/utils/cssVariables.ts +49 -0
- package/src/theme/utils/useInjectThemeIntoIframe.ts +40 -0
- package/src/utils/extensionIconMap.ts +123 -0
- package/src/utils/generalUtils.ts +157 -0
- package/src/writing/DraftAssistantDialog.tsx +279 -0
- package/src/writing/WritingStyleManager.tsx +416 -0
- package/src/writing/condenseWritingStyle.ts +103 -0
- package/src/writing/draftTextWithAgent.ts +134 -0
- package/src/writing/index.ts +39 -0
- package/src/writing/styleStore.ts +32 -0
- package/src/writing/writingStyle.test.ts +122 -0
- package/src/writing/writingStyle.ts +217 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PlatformAgentSessionRecord,
|
|
3
|
+
PlatformAgentSessionSummary,
|
|
4
|
+
PlatformCreateAgentSessionRequest,
|
|
5
|
+
PlatformListAgentSessionsRequest,
|
|
6
|
+
PlatformReadAgentSessionRequest,
|
|
7
|
+
PlatformUpdateAgentSessionRequest,
|
|
8
|
+
} from '../agentTypes.js'
|
|
9
|
+
import {
|
|
10
|
+
createAgentSession,
|
|
11
|
+
deleteAgentSession,
|
|
12
|
+
listAgentSessions,
|
|
13
|
+
readAgentSession,
|
|
14
|
+
updateAgentSession,
|
|
15
|
+
} from '../agents.mjs'
|
|
16
|
+
import { useIpc, type UseIpcOptions, type UseIpcResult } from './useIpc.js'
|
|
17
|
+
|
|
18
|
+
export function usePlatformAgentSessionList(
|
|
19
|
+
request: PlatformListAgentSessionsRequest,
|
|
20
|
+
options: UseIpcOptions = {},
|
|
21
|
+
): UseIpcResult<PlatformAgentSessionSummary[]> {
|
|
22
|
+
return useIpc(
|
|
23
|
+
() => listAgentSessions(request),
|
|
24
|
+
[request.scope, request.appSlug],
|
|
25
|
+
options,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function usePlatformAgentSession(
|
|
30
|
+
request: PlatformReadAgentSessionRequest | null,
|
|
31
|
+
options: UseIpcOptions = {},
|
|
32
|
+
): UseIpcResult<PlatformAgentSessionRecord | null> {
|
|
33
|
+
const enabled = Boolean(request) && (options.enabled ?? true)
|
|
34
|
+
return useIpc(
|
|
35
|
+
async () => {
|
|
36
|
+
if (!request) return null
|
|
37
|
+
return readAgentSession(request)
|
|
38
|
+
},
|
|
39
|
+
[request?.scope, request?.appSlug, request?.sessionId],
|
|
40
|
+
{ ...options, enabled },
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function createPlatformAgentSession(
|
|
45
|
+
request: PlatformCreateAgentSessionRequest,
|
|
46
|
+
): Promise<PlatformAgentSessionRecord> {
|
|
47
|
+
return createAgentSession(request)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function updatePlatformAgentSession(
|
|
51
|
+
request: PlatformUpdateAgentSessionRequest,
|
|
52
|
+
): Promise<PlatformAgentSessionRecord> {
|
|
53
|
+
return updateAgentSession(request)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function deletePlatformAgentSession(
|
|
57
|
+
request: PlatformReadAgentSessionRequest,
|
|
58
|
+
): Promise<void> {
|
|
59
|
+
return deleteAgentSession(request)
|
|
60
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { onAgentToolInvoke, registerAgentTools } from '../agents.mjs'
|
|
3
|
+
|
|
4
|
+
export interface AgentToolInvokeContext {
|
|
5
|
+
toolCallId: string
|
|
6
|
+
shortName: string
|
|
7
|
+
arguments: Record<string, unknown>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface AgentToolHandlerResult {
|
|
11
|
+
content: string
|
|
12
|
+
isError?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type AgentToolHandler = (
|
|
16
|
+
ctx: AgentToolInvokeContext,
|
|
17
|
+
) => Promise<AgentToolHandlerResult>
|
|
18
|
+
|
|
19
|
+
export interface UsePlatformAgentToolsOptions {
|
|
20
|
+
ready: boolean
|
|
21
|
+
tools: readonly string[]
|
|
22
|
+
handlers: Record<string, AgentToolHandler>
|
|
23
|
+
logLabel?: string
|
|
24
|
+
/** When set, instanceof checks map domain errors to message text. */
|
|
25
|
+
errorType?: new (message: string) => Error
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function usePlatformAgentTools({
|
|
29
|
+
ready,
|
|
30
|
+
tools,
|
|
31
|
+
handlers,
|
|
32
|
+
logLabel = 'app',
|
|
33
|
+
errorType,
|
|
34
|
+
}: UsePlatformAgentToolsOptions): void {
|
|
35
|
+
const handlersRef = useRef(handlers)
|
|
36
|
+
handlersRef.current = handlers
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!ready) return
|
|
40
|
+
|
|
41
|
+
void registerAgentTools({ tools: [...tools] }).catch(error => {
|
|
42
|
+
console.error(`[${logLabel}] agents.tools.register failed`, error)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return onAgentToolInvoke(async payload => {
|
|
46
|
+
try {
|
|
47
|
+
const handler = handlersRef.current[payload.shortName]
|
|
48
|
+
if (!handler) {
|
|
49
|
+
return {
|
|
50
|
+
toolCallId: payload.toolCallId,
|
|
51
|
+
content: `Unknown tool "${payload.shortName}"`,
|
|
52
|
+
isError: true,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const result = await handler({
|
|
57
|
+
toolCallId: payload.toolCallId,
|
|
58
|
+
shortName: payload.shortName,
|
|
59
|
+
arguments: payload.arguments,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
toolCallId: payload.toolCallId,
|
|
64
|
+
content: result.content,
|
|
65
|
+
isError: result.isError,
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const message =
|
|
69
|
+
errorType && error instanceof errorType
|
|
70
|
+
? error.message
|
|
71
|
+
: error instanceof Error
|
|
72
|
+
? error.message
|
|
73
|
+
: String(error)
|
|
74
|
+
return {
|
|
75
|
+
toolCallId: payload.toolCallId,
|
|
76
|
+
content: message,
|
|
77
|
+
isError: true,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}, [errorType, logLabel, ready, tools])
|
|
82
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { bridge } from '../client.mjs'
|
|
2
|
+
import { PLATFORM_BRIDGE_METHODS } from '../methods.mjs'
|
|
3
|
+
import type { PlatformAppManifest, PlatformShellManifest } from '../types.js'
|
|
4
|
+
import { useIpc } from './useIpc.js'
|
|
5
|
+
|
|
6
|
+
export interface UsePlatformAppManifestResult {
|
|
7
|
+
manifest: PlatformAppManifest | null
|
|
8
|
+
loading: boolean
|
|
9
|
+
error: Error | null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fetches the shell catalog manifest and returns the `PlatformAppManifest`
|
|
14
|
+
* for the current app (matched by `appSlug`).
|
|
15
|
+
*/
|
|
16
|
+
export function usePlatformAppManifest(
|
|
17
|
+
appSlug: string | null,
|
|
18
|
+
ready: boolean,
|
|
19
|
+
): UsePlatformAppManifestResult {
|
|
20
|
+
const { data, loading, error } = useIpc(
|
|
21
|
+
() =>
|
|
22
|
+
bridge.call<PlatformShellManifest>(
|
|
23
|
+
PLATFORM_BRIDGE_METHODS.CATALOG_MANIFEST,
|
|
24
|
+
),
|
|
25
|
+
[],
|
|
26
|
+
{ enabled: ready && appSlug !== null },
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const manifest = data?.apps.find(app => app.slug === appSlug) ?? null
|
|
30
|
+
|
|
31
|
+
return { manifest, loading, error }
|
|
32
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { bridge } from '../client.mjs'
|
|
3
|
+
import { PLATFORM_BRIDGE_METHODS } from '../methods.mjs'
|
|
4
|
+
import type { PlatformBridgeReadyMeta } from '../types.js'
|
|
5
|
+
|
|
6
|
+
export interface UsePlatformBridgeResult {
|
|
7
|
+
bridge: typeof bridge
|
|
8
|
+
meta: PlatformBridgeReadyMeta | null
|
|
9
|
+
error: Error | null
|
|
10
|
+
ready: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function usePlatformBridge(): UsePlatformBridgeResult {
|
|
14
|
+
const [meta, setMeta] = useState<PlatformBridgeReadyMeta | null>(null)
|
|
15
|
+
const [error, setError] = useState<Error | null>(null)
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let cancelled = false
|
|
19
|
+
bridge
|
|
20
|
+
.waitForReady()
|
|
21
|
+
.then(result => {
|
|
22
|
+
if (!cancelled) setMeta(result)
|
|
23
|
+
})
|
|
24
|
+
.catch((err: unknown) => {
|
|
25
|
+
if (!cancelled) {
|
|
26
|
+
setError(err instanceof Error ? err : new Error(String(err)))
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
return () => {
|
|
30
|
+
cancelled = true
|
|
31
|
+
}
|
|
32
|
+
}, [])
|
|
33
|
+
|
|
34
|
+
// Cmd/Ctrl-K belongs to the shell's universal jump palette, but key
|
|
35
|
+
// events land in whichever iframe has focus — forward them up.
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (window.parent === window) return undefined
|
|
38
|
+
const onKey = (event: KeyboardEvent): void => {
|
|
39
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k') {
|
|
40
|
+
event.preventDefault()
|
|
41
|
+
void bridge
|
|
42
|
+
.call(PLATFORM_BRIDGE_METHODS.WORKSPACE_OPEN_PALETTE, [])
|
|
43
|
+
.catch(() => undefined)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
window.addEventListener('keydown', onKey)
|
|
47
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
48
|
+
}, [])
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
bridge,
|
|
52
|
+
meta,
|
|
53
|
+
error,
|
|
54
|
+
ready: meta !== null,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { bridge } from '../client.mjs'
|
|
3
|
+
import { PLATFORM_BRIDGE_EVENTS } from '../events.mjs'
|
|
4
|
+
import { PLATFORM_BRIDGE_METHODS } from '../methods.mjs'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Consume deep links sent via `workspace.openApp({appSlug, resourceId})`.
|
|
8
|
+
* The shell delivers them as resource events with the pseudo-path
|
|
9
|
+
* `purescience://<appSlug>/<resourceId>`; this hook matches this app's
|
|
10
|
+
* slug and hands the resource id to the callback. Subscribe-on-mount so
|
|
11
|
+
* cold-launch deliveries are not missed.
|
|
12
|
+
*/
|
|
13
|
+
export function usePlatformDeepLink(
|
|
14
|
+
appSlug: string,
|
|
15
|
+
onOpen: (resourceId: string) => void,
|
|
16
|
+
): void {
|
|
17
|
+
const onOpenRef = useRef(onOpen)
|
|
18
|
+
onOpenRef.current = onOpen
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const prefix = `purescience://${appSlug}/`
|
|
22
|
+
const handlePath = (path: string): void => {
|
|
23
|
+
if (path.startsWith(prefix)) {
|
|
24
|
+
const resourceId = path.slice(prefix.length)
|
|
25
|
+
if (resourceId) onOpenRef.current(resourceId)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const unsubscribe = bridge.onEvent(
|
|
30
|
+
PLATFORM_BRIDGE_EVENTS.RESOURCE_OPEN,
|
|
31
|
+
payload => {
|
|
32
|
+
handlePath((payload as { path?: string } | null)?.path ?? '')
|
|
33
|
+
},
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
// Cold launches: the live event can be posted before this app
|
|
37
|
+
// subscribed, so the shell keeps the intent pending — collect it.
|
|
38
|
+
let cancelled = false
|
|
39
|
+
void bridge
|
|
40
|
+
.waitForReady()
|
|
41
|
+
.then(() =>
|
|
42
|
+
bridge.call<{ resource?: { path?: string } | null }>(
|
|
43
|
+
PLATFORM_BRIDGE_METHODS.CATALOG_CONSUME_PENDING_OPEN,
|
|
44
|
+
[],
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
.then(result => {
|
|
48
|
+
if (!cancelled) handlePath(result?.resource?.path ?? '')
|
|
49
|
+
})
|
|
50
|
+
.catch(() => undefined)
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
cancelled = true
|
|
54
|
+
unsubscribe()
|
|
55
|
+
}
|
|
56
|
+
}, [appSlug])
|
|
57
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { readPlatformFileBinaryDataUrl } from '../fs.mjs'
|
|
3
|
+
|
|
4
|
+
export interface UsePlatformFileBinaryDataUrlResult {
|
|
5
|
+
src: string | null
|
|
6
|
+
loading: boolean
|
|
7
|
+
error: string | null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** React binding for {@link readPlatformFileBinaryDataUrl}. */
|
|
11
|
+
export function usePlatformFileBinaryDataUrl(
|
|
12
|
+
path: string | null,
|
|
13
|
+
enabled: boolean,
|
|
14
|
+
maxBytes?: number,
|
|
15
|
+
): UsePlatformFileBinaryDataUrlResult {
|
|
16
|
+
const [src, setSrc] = useState<string | null>(null)
|
|
17
|
+
const [loading, setLoading] = useState(false)
|
|
18
|
+
const [error, setError] = useState<string | null>(null)
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!enabled || !path?.trim()) {
|
|
22
|
+
setSrc(null)
|
|
23
|
+
setLoading(false)
|
|
24
|
+
setError(null)
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let cancelled = false
|
|
29
|
+
setLoading(true)
|
|
30
|
+
setError(null)
|
|
31
|
+
setSrc(null)
|
|
32
|
+
|
|
33
|
+
void readPlatformFileBinaryDataUrl(path, maxBytes)
|
|
34
|
+
.then(dataUrl => {
|
|
35
|
+
if (cancelled) return
|
|
36
|
+
setSrc(dataUrl)
|
|
37
|
+
})
|
|
38
|
+
.catch(cause => {
|
|
39
|
+
if (cancelled) return
|
|
40
|
+
setError(
|
|
41
|
+
cause instanceof Error ? cause.message : 'Failed to load preview.',
|
|
42
|
+
)
|
|
43
|
+
})
|
|
44
|
+
.finally(() => {
|
|
45
|
+
if (!cancelled) setLoading(false)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
cancelled = true
|
|
50
|
+
}
|
|
51
|
+
}, [enabled, maxBytes, path])
|
|
52
|
+
|
|
53
|
+
return { src, loading, error }
|
|
54
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
PLATFORM_FILE_TEXT_PREVIEW_MAX_BYTES,
|
|
4
|
+
readPlatformFilePreview,
|
|
5
|
+
readPlatformFilePreviewUrl,
|
|
6
|
+
} from '../fs.mjs'
|
|
7
|
+
import type { PlatformFilePreviewEntry } from '../types.js'
|
|
8
|
+
import {
|
|
9
|
+
previewKindForEntry,
|
|
10
|
+
shouldFetchPreviewUrl,
|
|
11
|
+
shouldFetchTextPreview,
|
|
12
|
+
type FilePreviewKind,
|
|
13
|
+
} from '../filePreviewKind.js'
|
|
14
|
+
|
|
15
|
+
export interface UsePlatformFilePreviewResult {
|
|
16
|
+
previewKind: FilePreviewKind | null
|
|
17
|
+
textContent: string | null
|
|
18
|
+
textTruncated: boolean
|
|
19
|
+
mediaUrl: string | null
|
|
20
|
+
loading: boolean
|
|
21
|
+
error: string | null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Load inline file preview via shell bridge (text + streamed media URLs). */
|
|
25
|
+
export function usePlatformFilePreview(
|
|
26
|
+
entry: PlatformFilePreviewEntry | null,
|
|
27
|
+
): UsePlatformFilePreviewResult {
|
|
28
|
+
const [textContent, setTextContent] = useState<string | null>(null)
|
|
29
|
+
const [textTruncated, setTextTruncated] = useState(false)
|
|
30
|
+
const [mediaUrl, setMediaUrl] = useState<string | null>(null)
|
|
31
|
+
const [loading, setLoading] = useState(false)
|
|
32
|
+
const [error, setError] = useState<string | null>(null)
|
|
33
|
+
|
|
34
|
+
const previewKind = entry ? previewKindForEntry(entry) : null
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
let cancelled = false
|
|
38
|
+
|
|
39
|
+
setTextContent(null)
|
|
40
|
+
setTextTruncated(false)
|
|
41
|
+
setMediaUrl(null)
|
|
42
|
+
setError(null)
|
|
43
|
+
|
|
44
|
+
if (!entry || entry.isDirectory) return
|
|
45
|
+
|
|
46
|
+
const fetchText = shouldFetchTextPreview(entry)
|
|
47
|
+
const fetchMedia = shouldFetchPreviewUrl(entry)
|
|
48
|
+
if (!fetchText && !fetchMedia) return
|
|
49
|
+
|
|
50
|
+
setLoading(true)
|
|
51
|
+
|
|
52
|
+
void (async () => {
|
|
53
|
+
try {
|
|
54
|
+
if (fetchText) {
|
|
55
|
+
const result = await readPlatformFilePreview(
|
|
56
|
+
entry.path,
|
|
57
|
+
PLATFORM_FILE_TEXT_PREVIEW_MAX_BYTES,
|
|
58
|
+
)
|
|
59
|
+
if (cancelled) return
|
|
60
|
+
setTextContent(result.content)
|
|
61
|
+
setTextTruncated(result.truncated)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (fetchMedia) {
|
|
65
|
+
const result = await readPlatformFilePreviewUrl(entry.path)
|
|
66
|
+
if (cancelled) return
|
|
67
|
+
setMediaUrl(result.url)
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (cancelled) return
|
|
71
|
+
setTextContent(null)
|
|
72
|
+
setMediaUrl(null)
|
|
73
|
+
setError(err instanceof Error ? err.message : String(err))
|
|
74
|
+
} finally {
|
|
75
|
+
if (!cancelled) setLoading(false)
|
|
76
|
+
}
|
|
77
|
+
})()
|
|
78
|
+
|
|
79
|
+
return () => {
|
|
80
|
+
cancelled = true
|
|
81
|
+
}
|
|
82
|
+
}, [entry])
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
previewKind,
|
|
86
|
+
textContent,
|
|
87
|
+
textTruncated,
|
|
88
|
+
mediaUrl,
|
|
89
|
+
loading,
|
|
90
|
+
error,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
getPlatformPreferences,
|
|
4
|
+
patchPlatformPreferences,
|
|
5
|
+
} from '../preferences.mjs'
|
|
6
|
+
import type { PlatformShellPreferences } from '../types.js'
|
|
7
|
+
|
|
8
|
+
export interface UsePlatformPreferencesOptions {
|
|
9
|
+
/** Wait for bridge ready before loading (default true). */
|
|
10
|
+
enabled?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UsePlatformPreferencesResult {
|
|
14
|
+
prefs: PlatformShellPreferences | null
|
|
15
|
+
loading: boolean
|
|
16
|
+
error: Error | null
|
|
17
|
+
/** Merge a partial patch via shell `settings.prefs.set`. */
|
|
18
|
+
updatePrefs: (
|
|
19
|
+
patch: Partial<PlatformShellPreferences>,
|
|
20
|
+
) => Promise<PlatformShellPreferences>
|
|
21
|
+
reload: () => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Load and update shell preferences from a plugin iframe (`settings.prefs.*`).
|
|
26
|
+
* Host renderer should use shell IPC helpers instead of this hook.
|
|
27
|
+
*/
|
|
28
|
+
export function usePlatformPreferences(
|
|
29
|
+
options: UsePlatformPreferencesOptions = {},
|
|
30
|
+
): UsePlatformPreferencesResult {
|
|
31
|
+
const enabled = options.enabled ?? true
|
|
32
|
+
const [prefs, setPrefs] = useState<PlatformShellPreferences | null>(null)
|
|
33
|
+
const [loading, setLoading] = useState(false)
|
|
34
|
+
const [error, setError] = useState<Error | null>(null)
|
|
35
|
+
const [reloadToken, setReloadToken] = useState(0)
|
|
36
|
+
|
|
37
|
+
const reload = useCallback(() => {
|
|
38
|
+
setReloadToken(token => token + 1)
|
|
39
|
+
}, [])
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!enabled) return
|
|
43
|
+
|
|
44
|
+
let cancelled = false
|
|
45
|
+
setLoading(true)
|
|
46
|
+
setError(null)
|
|
47
|
+
|
|
48
|
+
void getPlatformPreferences()
|
|
49
|
+
.then(next => {
|
|
50
|
+
if (!cancelled) setPrefs(next)
|
|
51
|
+
})
|
|
52
|
+
.catch((err: unknown) => {
|
|
53
|
+
if (!cancelled) {
|
|
54
|
+
setPrefs(null)
|
|
55
|
+
setError(err instanceof Error ? err : new Error(String(err)))
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
.finally(() => {
|
|
59
|
+
if (!cancelled) setLoading(false)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return () => {
|
|
63
|
+
cancelled = true
|
|
64
|
+
}
|
|
65
|
+
}, [enabled, reloadToken])
|
|
66
|
+
|
|
67
|
+
const updatePrefs = useCallback(
|
|
68
|
+
async (patch: Partial<PlatformShellPreferences>) => {
|
|
69
|
+
const next = await patchPlatformPreferences(patch)
|
|
70
|
+
setPrefs(next)
|
|
71
|
+
return next
|
|
72
|
+
},
|
|
73
|
+
[],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
return { prefs, loading, error, updatePrefs, reload }
|
|
77
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { bridge } from '../client.mjs'
|
|
3
|
+
import { PLATFORM_BRIDGE_EVENTS } from '../events.mjs'
|
|
4
|
+
|
|
5
|
+
export interface PlatformThemeDocumentAttrs {
|
|
6
|
+
mode: string
|
|
7
|
+
surfacePalette: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function readThemeDocumentAttrs(): PlatformThemeDocumentAttrs {
|
|
11
|
+
const root = document.documentElement
|
|
12
|
+
return {
|
|
13
|
+
mode: root.dataset.platformTheme ?? '',
|
|
14
|
+
surfacePalette: root.dataset.platformSurfacePalette ?? '',
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Mirror shell-injected `data-platform-*` attrs for AppFrame styled selectors. */
|
|
19
|
+
export function usePlatformThemeDocumentAttrs(
|
|
20
|
+
enabled = true,
|
|
21
|
+
): PlatformThemeDocumentAttrs {
|
|
22
|
+
const [attrs, setAttrs] = useState<PlatformThemeDocumentAttrs>(() =>
|
|
23
|
+
enabled ? readThemeDocumentAttrs() : { mode: '', surfacePalette: '' },
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!enabled) return
|
|
28
|
+
setAttrs(readThemeDocumentAttrs())
|
|
29
|
+
return bridge.onEvent(PLATFORM_BRIDGE_EVENTS.THEME_CHANGED, () => {
|
|
30
|
+
setAttrs(readThemeDocumentAttrs())
|
|
31
|
+
})
|
|
32
|
+
}, [enabled])
|
|
33
|
+
|
|
34
|
+
return attrs
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
import { applyThemeFromHost } from '../applyThemeFromHost.mjs'
|
|
3
|
+
import { bridge } from '../client.mjs'
|
|
4
|
+
import { PLATFORM_BRIDGE_EVENTS } from '../events.mjs'
|
|
5
|
+
import type { PlatformThemeBridgePayload } from '../types.js'
|
|
6
|
+
|
|
7
|
+
/** Subscribe to shell theme updates in a plugin iframe (cross-origin safe). */
|
|
8
|
+
export function usePlatformThemeFromBridge(enabled = true): void {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!enabled) return
|
|
11
|
+
|
|
12
|
+
return bridge.onEvent(PLATFORM_BRIDGE_EVENTS.THEME_CHANGED, payload => {
|
|
13
|
+
applyThemeFromHost(payload as PlatformThemeBridgePayload)
|
|
14
|
+
})
|
|
15
|
+
}, [enabled])
|
|
16
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React, { act } from 'react'
|
|
2
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { bridge } from '../client.mjs'
|
|
5
|
+
import { PLATFORM_BRIDGE_METHODS } from '../methods.mjs'
|
|
6
|
+
import type { PlatformBridgeReadyMeta, ResourceOpenEvent } from '../types.js'
|
|
7
|
+
import { usePlatformViewportResource } from './usePlatformViewportResource.js'
|
|
8
|
+
|
|
9
|
+
const reactActGlobal = globalThis as typeof globalThis & {
|
|
10
|
+
IS_REACT_ACT_ENVIRONMENT?: boolean
|
|
11
|
+
}
|
|
12
|
+
reactActGlobal.IS_REACT_ACT_ENVIRONMENT = true
|
|
13
|
+
|
|
14
|
+
const originalCall = bridge.call
|
|
15
|
+
const originalOnEvent = bridge.onEvent
|
|
16
|
+
|
|
17
|
+
function renderProbe(
|
|
18
|
+
meta: PlatformBridgeReadyMeta,
|
|
19
|
+
onResource: (resource: ResourceOpenEvent | null) => void,
|
|
20
|
+
): Root {
|
|
21
|
+
const container = document.createElement('div')
|
|
22
|
+
document.body.appendChild(container)
|
|
23
|
+
const root = createRoot(container)
|
|
24
|
+
|
|
25
|
+
function Probe(): React.ReactElement {
|
|
26
|
+
const { resource } = usePlatformViewportResource(true, meta)
|
|
27
|
+
onResource(resource)
|
|
28
|
+
return <div />
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
act(() => {
|
|
32
|
+
root.render(<Probe />)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return root
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('usePlatformViewportResource', () => {
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
bridge.call = originalCall
|
|
41
|
+
bridge.onEvent = originalOnEvent
|
|
42
|
+
document.body.innerHTML = ''
|
|
43
|
+
vi.restoreAllMocks()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('uses the bridge-ready viewport resource', async () => {
|
|
47
|
+
bridge.call = vi.fn()
|
|
48
|
+
bridge.onEvent = vi.fn(() => () => undefined)
|
|
49
|
+
const resources: Array<ResourceOpenEvent | null> = []
|
|
50
|
+
const resource = {
|
|
51
|
+
path: '/tmp/example.slides',
|
|
52
|
+
name: 'Example',
|
|
53
|
+
kind: 'folder',
|
|
54
|
+
} satisfies ResourceOpenEvent
|
|
55
|
+
|
|
56
|
+
const root = renderProbe(
|
|
57
|
+
{
|
|
58
|
+
version: 1,
|
|
59
|
+
pluginId: 'pureslides2',
|
|
60
|
+
appSlug: 'slides2',
|
|
61
|
+
methods: [],
|
|
62
|
+
viewport: { tabId: 'tab-1', resource },
|
|
63
|
+
},
|
|
64
|
+
next => resources.push(next),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
await act(async () => undefined)
|
|
68
|
+
|
|
69
|
+
expect(resources.at(-1)).toEqual(resource)
|
|
70
|
+
expect(bridge.call).not.toHaveBeenCalled()
|
|
71
|
+
act(() => root.unmount())
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('consumes a per-tab pending open when ready metadata has no resource', async () => {
|
|
75
|
+
const resource = {
|
|
76
|
+
path: '/tmp/reopened.slides',
|
|
77
|
+
name: 'Reopened',
|
|
78
|
+
kind: 'folder',
|
|
79
|
+
sourceAppSlug: 'slides2',
|
|
80
|
+
} satisfies ResourceOpenEvent
|
|
81
|
+
bridge.call = vi.fn(async (method: string) => {
|
|
82
|
+
expect(method).toBe(PLATFORM_BRIDGE_METHODS.CATALOG_CONSUME_PENDING_OPEN)
|
|
83
|
+
return { resource }
|
|
84
|
+
}) as typeof bridge.call
|
|
85
|
+
bridge.onEvent = vi.fn(() => () => undefined)
|
|
86
|
+
const resources: Array<ResourceOpenEvent | null> = []
|
|
87
|
+
|
|
88
|
+
const root = renderProbe(
|
|
89
|
+
{
|
|
90
|
+
version: 1,
|
|
91
|
+
pluginId: 'pureslides2',
|
|
92
|
+
appSlug: 'slides2',
|
|
93
|
+
methods: [],
|
|
94
|
+
viewport: { tabId: 'tab-2', resource: null },
|
|
95
|
+
},
|
|
96
|
+
next => resources.push(next),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
await act(async () => {
|
|
100
|
+
await Promise.resolve()
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
expect(resources.at(-1)).toEqual(resource)
|
|
104
|
+
act(() => root.unmount())
|
|
105
|
+
})
|
|
106
|
+
})
|