@agent-native/core 0.131.4 → 0.131.6
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/corpus/README.md +3 -3
- package/corpus/core/CHANGELOG.md +69 -0
- package/corpus/core/docs/content/agent-native-toolkit.mdx +13 -6
- package/corpus/core/docs/content/cloneable-saas.mdx +5 -5
- package/corpus/core/docs/content/creating-templates.mdx +9 -0
- package/corpus/core/docs/content/deployment.mdx +14 -10
- package/corpus/core/docs/content/docs-components.mdx +491 -0
- package/corpus/core/docs/content/doctor.mdx +8 -1
- package/corpus/core/docs/content/drop-in-agent.mdx +1 -1
- package/corpus/core/docs/content/extensions.mdx +18 -18
- package/corpus/core/docs/content/faq.mdx +4 -4
- package/corpus/core/docs/content/key-concepts.mdx +30 -21
- package/corpus/core/docs/content/template-brain-developers.mdx +4 -1
- package/corpus/core/docs/content/template-mail-developers.mdx +4 -1
- package/corpus/core/docs/content/what-is-agent-native.mdx +6 -6
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/a2a/client.ts +449 -66
- package/corpus/core/src/a2a/correlation.ts +31 -0
- package/corpus/core/src/a2a/types.ts +4 -0
- package/corpus/core/src/action.ts +3 -0
- package/corpus/core/src/agent/engine/registry.ts +45 -5
- package/corpus/core/src/agent/production-agent.ts +151 -18
- package/corpus/core/src/agent/run-loop-with-resume.ts +190 -3
- package/corpus/core/src/agent/run-manager.ts +117 -41
- package/corpus/core/src/agent/thread-debug-history.ts +86 -0
- package/corpus/core/src/agent/types.ts +3 -1
- package/corpus/core/src/cli/create.ts +11 -1
- package/corpus/core/src/cli/templates-meta.ts +2 -2
- package/corpus/core/src/client/agent-chat-adapter.ts +91 -13
- package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +11 -9
- package/corpus/core/src/client/sse-event-processor.ts +17 -3
- package/corpus/core/src/db/client.ts +57 -17
- package/corpus/core/src/integrations/adapters/slack.ts +8 -3
- package/corpus/core/src/localization/default-messages.ts +44 -0
- package/corpus/core/src/observability/traces.ts +78 -5
- package/corpus/core/src/scripts/call-agent.ts +290 -9
- package/corpus/core/src/scripts/describe-workspace-apps.ts +2 -2
- package/corpus/core/src/secrets/crypto.ts +126 -34
- package/corpus/core/src/secrets/storage.ts +61 -25
- package/corpus/core/src/server/agent-capabilities.ts +1 -1
- package/corpus/core/src/server/agent-chat/action-filters-a2a.ts +111 -7
- package/corpus/core/src/server/agent-chat/context-tools.ts +2 -0
- package/corpus/core/src/server/agent-chat/plugin-options.ts +34 -1
- package/corpus/core/src/server/agent-chat/prompt-resources.ts +1 -1
- package/corpus/core/src/server/agent-chat-plugin.ts +91 -59
- package/corpus/core/src/templates/default/.agents/skills/secrets/SKILL.md +14 -7
- package/corpus/core/src/templates/headless/.agents/skills/secrets/SKILL.md +14 -7
- package/corpus/core/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +18 -7
- package/corpus/core/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +15 -14
- package/corpus/core/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +14 -7
- package/corpus/core/src/vite/client.ts +1 -0
- package/corpus/templates/analytics/.agents/skills/dashboard-ops/SKILL.md +5 -4
- package/corpus/templates/analytics/.agents/skills/gong/SKILL.md +6 -4
- package/corpus/templates/analytics/AGENTS.md +6 -4
- package/corpus/templates/analytics/actions/query-agent-native-analytics.ts +4 -3
- package/corpus/templates/analytics/changelog/2026-07-30-scheduled-dashboard-emails-complete-every-panel-without-pool.md +6 -0
- package/corpus/templates/analytics/scripts/emit-netlify-dashboard-report-cron.ts +28 -1
- package/corpus/templates/analytics/server/jobs/dashboard-report.ts +18 -11
- package/corpus/templates/analytics/server/lib/analytics-connector-catalog.ts +4 -4
- package/corpus/templates/analytics/server/lib/canonical-first-party-dashboard-repair.ts +9 -5
- package/corpus/templates/analytics/server/lib/dashboard-panel-query.ts +6 -2
- package/corpus/templates/analytics/server/lib/dashboard-panel-source-resolver.ts +11 -4
- package/corpus/templates/analytics/server/lib/dashboard-report-render.ts +49 -31
- package/corpus/templates/analytics/server/lib/first-party-analytics.ts +16 -8
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +9 -3
- package/corpus/templates/analytics/server/lib/production-serverless-runtime.ts +11 -0
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +3 -2
- package/corpus/templates/analytics/server/plugins/analytics-alert-jobs.ts +2 -1
- package/corpus/templates/analytics/server/plugins/dashboard-report-jobs.ts +2 -1
- package/corpus/templates/analytics/server/plugins/uptime-monitor-jobs.ts +1 -12
- package/corpus/templates/brain/.agents/skills/brain/RUNBOOK.md +54 -6
- package/corpus/templates/brain/.agents/skills/brain/SKILL.md +20 -9
- package/corpus/templates/brain/.agents/skills/ingestion-and-connectors/SKILL.md +33 -1
- package/corpus/templates/brain/AGENTS.md +3 -1
- package/corpus/templates/brain/README.md +4 -1
- package/corpus/templates/brain/actions/_schemas.ts +30 -8
- package/corpus/templates/brain/actions/ask-brain.ts +124 -14
- package/corpus/templates/brain/actions/create-source.ts +18 -2
- package/corpus/templates/brain/actions/enqueue-captures-distillation.ts +8 -123
- package/corpus/templates/brain/actions/enqueue-distillation.ts +6 -127
- package/corpus/templates/brain/actions/import-capture.ts +17 -5
- package/corpus/templates/brain/actions/import-transcript.ts +17 -5
- package/corpus/templates/brain/actions/update-source.ts +25 -5
- package/corpus/templates/brain/app/components/layout/Sidebar.tsx +1 -1
- package/corpus/templates/brain/changelog/2026-07-30-blessed-resources-can-feed-cited-company-answers.md +6 -0
- package/corpus/templates/brain/changelog/2026-07-30-the-left-sidebar-no-longer-shows-a-blank-organization-placeh.md +6 -0
- package/corpus/templates/brain/server/lib/brain.ts +49 -19
- package/corpus/templates/brain/server/lib/distillation-queue.ts +147 -0
- package/corpus/templates/brain/server/lib/source-policy.ts +264 -0
- package/corpus/templates/brain/server/plugins/agent-chat.ts +3 -2
- package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +116 -19
- package/corpus/templates/clips/app/components/meetings/google-oauth-identity-notice.tsx +51 -0
- package/corpus/templates/clips/app/i18n/en-US.ts +4 -0
- package/corpus/templates/clips/app/routes/_app.meetings._index.tsx +3 -1
- package/corpus/templates/clips/changelog/2026-07-30-google-calendar-warning.md +6 -0
- package/corpus/templates/content/.agents/skills/content-product-development/SKILL.md +47 -0
- package/corpus/templates/content/app/components/editor/VisualEditor.tsx +72 -8
- package/corpus/templates/content/changelog/2026-07-30-the-slash-command-hint-now-stays-on-only-the-active-empty-li.md +6 -0
- package/corpus/templates/design/.generated/bridge/editor-chrome.generated.ts +506 -11
- package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +148 -17
- package/corpus/templates/design/app/components/design/canvas-interactions/design-canvas-interactions.ts +357 -0
- package/corpus/templates/design/app/components/design/inspector/ScrubInput.tsx +7 -466
- package/corpus/templates/design/app/components/design/inspector/scrub-input-utils.ts +15 -311
- package/corpus/templates/design/app/components/visual-editor/CanvasCommentPins.tsx +19 -997
- package/corpus/templates/design/app/components/visual-editor/DrawOverlay.tsx +8 -1216
- package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +31 -38
- package/corpus/templates/design/package.json +0 -1
- package/corpus/templates/dispatch/AGENTS.md +8 -0
- package/corpus/templates/dispatch/DEVELOPING.md +29 -0
- package/corpus/templates/dispatch/actions/view-screen.ts +34 -2
- package/corpus/templates/dispatch/app/i18n-data.ts +457 -0
- package/corpus/templates/dispatch/changelog/2026-07-30-delegated-dispatch-work-continues-reliably-in-the-background.md +6 -0
- package/corpus/templates/dispatch/changelog/2026-07-30-find-failed-runs-across-apps.md +6 -0
- package/corpus/templates/dispatch/netlify.toml +3 -0
- package/corpus/templates/slides/.agents/skills/analytics-data-for-decks/SKILL.md +8 -12
- package/corpus/templates/slides/AGENTS.md +4 -4
- package/corpus/templates/slides/actions/duplicate-deck.ts +19 -4
- package/corpus/templates/slides/app/components/deck/DeckCard.tsx +2 -10
- package/corpus/templates/slides/app/components/deck/MermaidRenderer.tsx +12 -1
- package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +30 -13
- package/corpus/templates/slides/app/components/editor/DeckEditorSkeleton.tsx +35 -0
- package/corpus/templates/slides/app/components/editor/EditorSidebar.tsx +63 -56
- package/corpus/templates/slides/app/components/editor/EditorToolbar.tsx +21 -76
- package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +1110 -292
- package/corpus/templates/slides/app/components/editor/SlideOverflowWarning.tsx +53 -0
- package/corpus/templates/slides/app/components/editor/SlideStyleInspector.tsx +235 -18
- package/corpus/templates/slides/app/components/editor/SpeakerNotesPanel.tsx +4 -1
- package/corpus/templates/slides/app/components/editor/canvas-interactions/index.ts +11 -0
- package/corpus/templates/slides/app/components/editor/canvas-interactions/slides-canvas-adapter.ts +129 -0
- package/corpus/templates/slides/app/components/editor/selection-overlay-measurement.ts +70 -0
- package/corpus/templates/slides/app/components/editor/slide-object-interactions.ts +519 -65
- package/corpus/templates/slides/app/components/visual-editor/CanvasCommentPins.tsx +36 -426
- package/corpus/templates/slides/app/components/visual-editor/DrawOverlay.tsx +19 -458
- package/corpus/templates/slides/app/context/DeckContext.tsx +179 -72
- package/corpus/templates/slides/app/global.css +105 -0
- package/corpus/templates/slides/app/i18n/en-US.ts +8 -0
- package/corpus/templates/slides/app/lib/deck-editor-loading.ts +26 -0
- package/corpus/templates/slides/app/lib/mermaid-blocks.ts +27 -0
- package/corpus/templates/slides/app/pages/DeckEditor.tsx +71 -38
- package/corpus/templates/slides/app/pages/Index.tsx +98 -41
- package/corpus/templates/slides/changelog/2026-07-30-deck-loading-no-longer-flashes-an-unavailable-message.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-30-duplicating-a-deck-from-the-deck-list-now-opens-the-copy-imm.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-30-layout-overflow-warning-is-readable-and-dismissible.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-30-shared-canvas-annotations.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-30-slide-objects-can-be-moved-as-a-group-copied-and-pasted-with.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-30-slide-text-editing-and-object-controls-now-match-google-slides.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-30-style-panel-now-scrolls-with-speaker-notes-open-shows-the-sl.md +6 -0
- package/corpus/templates/slides/changelog/2026-07-30-top-toolbar-controls-now-use-consistent-sizing-with-undo-and.md +6 -0
- package/corpus/templates/slides/netlify.toml +3 -1
- package/corpus/templates/slides/package.json +0 -1
- package/corpus/templates/slides/server/lib/chat-attachments.ts +18 -0
- package/corpus/templates/slides/server/plugins/agent-chat.ts +5 -0
- package/corpus/templates/slides/vite.config.ts +0 -1
- package/corpus/toolkit/CHANGELOG.md +13 -0
- package/corpus/toolkit/README.md +19 -0
- package/corpus/toolkit/agent-native.eject.json +38 -0
- package/corpus/toolkit/package.json +29 -1
- package/corpus/toolkit/src/canvas-annotations/CanvasCommentPins.tsx +861 -0
- package/corpus/toolkit/src/canvas-annotations/DrawOverlay.tsx +1233 -0
- package/corpus/toolkit/src/canvas-annotations/index.ts +15 -0
- package/corpus/toolkit/src/canvas-annotations/types.ts +14 -0
- package/corpus/toolkit/src/canvas-interactions/canvas-interactions.ts +933 -0
- package/corpus/toolkit/src/canvas-interactions/index.ts +67 -0
- package/corpus/toolkit/src/design-tweaks/scrub-input-utils.ts +311 -0
- package/corpus/toolkit/src/design-tweaks/scrub-input.tsx +491 -0
- package/corpus/toolkit/src/design-tweaks/visual-style-controls.tsx +26 -171
- package/corpus/toolkit/src/index.ts +1 -0
- package/dist/a2a/client.d.ts +23 -0
- package/dist/a2a/client.d.ts.map +1 -1
- package/dist/a2a/client.js +309 -44
- package/dist/a2a/client.js.map +1 -1
- package/dist/a2a/correlation.d.ts +1 -0
- package/dist/a2a/correlation.d.ts.map +1 -1
- package/dist/a2a/correlation.js +27 -0
- package/dist/a2a/correlation.js.map +1 -1
- package/dist/a2a/types.d.ts +4 -0
- package/dist/a2a/types.d.ts.map +1 -1
- package/dist/a2a/types.js.map +1 -1
- package/dist/action.d.ts +3 -0
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js.map +1 -1
- package/dist/agent/engine/registry.d.ts.map +1 -1
- package/dist/agent/engine/registry.js +34 -7
- package/dist/agent/engine/registry.js.map +1 -1
- package/dist/agent/production-agent.d.ts +40 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +113 -15
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-loop-with-resume.d.ts +21 -0
- package/dist/agent/run-loop-with-resume.d.ts.map +1 -1
- package/dist/agent/run-loop-with-resume.js +163 -4
- package/dist/agent/run-loop-with-resume.js.map +1 -1
- package/dist/agent/run-manager.d.ts +16 -9
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +93 -42
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/thread-debug-history.d.ts +10 -0
- package/dist/agent/thread-debug-history.d.ts.map +1 -0
- package/dist/agent/thread-debug-history.js +68 -0
- package/dist/agent/thread-debug-history.js.map +1 -0
- package/dist/agent/types.d.ts +3 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/create.js +6 -1
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/templates-meta.js +2 -2
- package/dist/cli/templates-meta.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +76 -13
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
- package/dist/client/resources/McpIntegrationDialog.js +1 -1
- package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +12 -3
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +48 -17
- package/dist/db/client.js.map +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/integrations/adapters/slack.js +7 -3
- package/dist/integrations/adapters/slack.js.map +1 -1
- package/dist/localization/default-messages.d.ts +43 -0
- package/dist/localization/default-messages.d.ts.map +1 -1
- package/dist/localization/default-messages.js +43 -0
- package/dist/localization/default-messages.js.map +1 -1
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/traces.d.ts +3 -1
- package/dist/observability/traces.d.ts.map +1 -1
- package/dist/observability/traces.js +73 -4
- package/dist/observability/traces.js.map +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +12 -12
- package/dist/provider-api/actions/provider-api.d.ts +13 -13
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/scripts/call-agent.d.ts.map +1 -1
- package/dist/scripts/call-agent.js +233 -10
- package/dist/scripts/call-agent.js.map +1 -1
- package/dist/scripts/describe-workspace-apps.js +2 -2
- package/dist/scripts/describe-workspace-apps.js.map +1 -1
- package/dist/secrets/crypto.d.ts +31 -21
- package/dist/secrets/crypto.d.ts.map +1 -1
- package/dist/secrets/crypto.js +108 -33
- package/dist/secrets/crypto.js.map +1 -1
- package/dist/secrets/storage.d.ts +3 -5
- package/dist/secrets/storage.d.ts.map +1 -1
- package/dist/secrets/storage.js +40 -25
- package/dist/secrets/storage.js.map +1 -1
- package/dist/server/agent-capabilities.js +1 -1
- package/dist/server/agent-capabilities.js.map +1 -1
- package/dist/server/agent-chat/action-filters-a2a.d.ts +17 -3
- package/dist/server/agent-chat/action-filters-a2a.d.ts.map +1 -1
- package/dist/server/agent-chat/action-filters-a2a.js +92 -3
- package/dist/server/agent-chat/action-filters-a2a.js.map +1 -1
- package/dist/server/agent-chat/context-tools.d.ts.map +1 -1
- package/dist/server/agent-chat/context-tools.js +2 -0
- package/dist/server/agent-chat/context-tools.js.map +1 -1
- package/dist/server/agent-chat/plugin-options.d.ts +23 -0
- package/dist/server/agent-chat/plugin-options.d.ts.map +1 -1
- package/dist/server/agent-chat/plugin-options.js +4 -1
- package/dist/server/agent-chat/plugin-options.js.map +1 -1
- package/dist/server/agent-chat/prompt-resources.js +1 -1
- package/dist/server/agent-chat/prompt-resources.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts +2 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +79 -56
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/templates/default/.agents/skills/secrets/SKILL.md +14 -7
- package/dist/templates/headless/.agents/skills/secrets/SKILL.md +14 -7
- package/dist/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +18 -7
- package/dist/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +15 -14
- package/dist/templates/workspace-core/.agents/skills/secrets/SKILL.md +14 -7
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +1 -0
- package/dist/vite/client.js.map +1 -1
- package/docs/content/agent-native-toolkit.mdx +13 -6
- package/docs/content/cloneable-saas.mdx +5 -5
- package/docs/content/creating-templates.mdx +9 -0
- package/docs/content/deployment.mdx +14 -10
- package/docs/content/docs-components.mdx +491 -0
- package/docs/content/doctor.mdx +8 -1
- package/docs/content/drop-in-agent.mdx +1 -1
- package/docs/content/extensions.mdx +18 -18
- package/docs/content/faq.mdx +4 -4
- package/docs/content/key-concepts.mdx +30 -21
- package/docs/content/template-brain-developers.mdx +4 -1
- package/docs/content/template-mail-developers.mdx +4 -1
- package/docs/content/what-is-agent-native.mdx +6 -6
- package/package.json +2 -2
- package/src/a2a/client.ts +449 -66
- package/src/a2a/correlation.ts +31 -0
- package/src/a2a/types.ts +4 -0
- package/src/action.ts +3 -0
- package/src/agent/engine/registry.ts +45 -5
- package/src/agent/production-agent.ts +151 -18
- package/src/agent/run-loop-with-resume.ts +190 -3
- package/src/agent/run-manager.ts +117 -41
- package/src/agent/thread-debug-history.ts +86 -0
- package/src/agent/types.ts +3 -1
- package/src/cli/create.ts +11 -1
- package/src/cli/templates-meta.ts +2 -2
- package/src/client/agent-chat-adapter.ts +91 -13
- package/src/client/resources/McpIntegrationDialog.tsx +11 -9
- package/src/client/sse-event-processor.ts +17 -3
- package/src/db/client.ts +57 -17
- package/src/integrations/adapters/slack.ts +8 -3
- package/src/localization/default-messages.ts +44 -0
- package/src/observability/traces.ts +78 -5
- package/src/scripts/call-agent.ts +290 -9
- package/src/scripts/describe-workspace-apps.ts +2 -2
- package/src/secrets/crypto.ts +126 -34
- package/src/secrets/storage.ts +61 -25
- package/src/server/agent-capabilities.ts +1 -1
- package/src/server/agent-chat/action-filters-a2a.ts +111 -7
- package/src/server/agent-chat/context-tools.ts +2 -0
- package/src/server/agent-chat/plugin-options.ts +34 -1
- package/src/server/agent-chat/prompt-resources.ts +1 -1
- package/src/server/agent-chat-plugin.ts +91 -59
- package/src/templates/default/.agents/skills/secrets/SKILL.md +14 -7
- package/src/templates/headless/.agents/skills/secrets/SKILL.md +14 -7
- package/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +18 -7
- package/src/templates/workspace-core/.agents/skills/composable-mini-apps/SKILL.md +15 -14
- package/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +14 -7
- package/src/vite/client.ts +1 -0
|
@@ -0,0 +1,861 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IconBolt,
|
|
3
|
+
IconLoader2,
|
|
4
|
+
IconMessage,
|
|
5
|
+
IconMessageCheck,
|
|
6
|
+
IconSend,
|
|
7
|
+
IconX,
|
|
8
|
+
} from "@tabler/icons-react";
|
|
9
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
10
|
+
import { toast } from "sonner";
|
|
11
|
+
|
|
12
|
+
import { Button } from "../ui/button.js";
|
|
13
|
+
import { Textarea } from "../ui/textarea.js";
|
|
14
|
+
import {
|
|
15
|
+
Tooltip,
|
|
16
|
+
TooltipContent,
|
|
17
|
+
TooltipProvider,
|
|
18
|
+
TooltipTrigger,
|
|
19
|
+
} from "../ui/tooltip.js";
|
|
20
|
+
import { cn } from "../utils.js";
|
|
21
|
+
import type {
|
|
22
|
+
CanvasAnnotationTranslate,
|
|
23
|
+
SendCanvasAnnotation,
|
|
24
|
+
} from "./types.js";
|
|
25
|
+
|
|
26
|
+
export interface CanvasPin {
|
|
27
|
+
id: string;
|
|
28
|
+
/** Position as a percentage of the canvas (so it survives resize/zoom) */
|
|
29
|
+
xPct: number;
|
|
30
|
+
yPct: number;
|
|
31
|
+
/** Optional CSS selector of the element under the click, for context */
|
|
32
|
+
targetSelector?: string;
|
|
33
|
+
/** Best-effort stable canvas/code-layer id when the clicked layer exposes one. */
|
|
34
|
+
targetAnchorId?: string;
|
|
35
|
+
/** Optional snippet of text content the user clicked near */
|
|
36
|
+
targetText?: string;
|
|
37
|
+
/** Pending comment text the user is composing */
|
|
38
|
+
draft?: string;
|
|
39
|
+
/** Held locally until the user batch-applies queued comments. */
|
|
40
|
+
queued?: boolean;
|
|
41
|
+
/** Submitted state — the marker stays visible as confirmation. */
|
|
42
|
+
submitted?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface CanvasCommentPinsProps {
|
|
46
|
+
translate: CanvasAnnotationTranslate;
|
|
47
|
+
sendToAgent: SendCanvasAnnotation;
|
|
48
|
+
onSendError?: () => void;
|
|
49
|
+
allowQueue?: boolean;
|
|
50
|
+
showAnchorDetails?: boolean;
|
|
51
|
+
showSubmitShortcut?: boolean;
|
|
52
|
+
/** Whether the pin tool is active. When true, clicks drop pins. */
|
|
53
|
+
active: boolean;
|
|
54
|
+
/** In queue mode, pin Send adds to the shared annotation batch. */
|
|
55
|
+
submitMode?: "direct" | "queue";
|
|
56
|
+
/** Disable / exit the pin mode (called on Escape, after submit, etc.) */
|
|
57
|
+
onClose: () => void;
|
|
58
|
+
/** Mirrors local pins to a parent that can submit them with other annotations. */
|
|
59
|
+
onPinsChange?: (pins: CanvasPin[]) => void;
|
|
60
|
+
/** Increment to mark queued pins as submitted by a parent action. */
|
|
61
|
+
submitQueuedSignal?: number;
|
|
62
|
+
/** Keep the click plane below a sibling draw toolbar in combined annotate mode. */
|
|
63
|
+
clickPlaneUnderToolbar?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Selector for the canvas surface (e.g. `.slide-content`). Pins are anchored
|
|
66
|
+
* to this element's bounding rect; clicks outside are ignored.
|
|
67
|
+
*/
|
|
68
|
+
canvasSelector: string;
|
|
69
|
+
/** Stable identifier for the current view (slide id / design id) — used in
|
|
70
|
+
* the agent prompt and as a pin namespace key. */
|
|
71
|
+
contextId: string;
|
|
72
|
+
/** Human-readable label for the context (slide title, slide index, design
|
|
73
|
+
* title) used in the agent prompt. */
|
|
74
|
+
contextLabel?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function escapeAttributeValue(value: string): string {
|
|
78
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function escapeCssIdentifier(value: string): string {
|
|
82
|
+
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
83
|
+
return CSS.escape(value);
|
|
84
|
+
}
|
|
85
|
+
return value.replace(/[^a-zA-Z0-9_-]/g, "\\$&");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Best-effort check for whether a pin's captured anchor element still exists
|
|
90
|
+
* on the canvas. Only meaningful for parent-DOM canvases with a captured
|
|
91
|
+
* `targetSelector` — iframe canvases never capture one (see `dropPinAt`), so
|
|
92
|
+
* this naturally no-ops there rather than mislabeling every iframe pin as
|
|
93
|
+
* stale. Recomputed on each render (already triggered by scroll/resize/pins
|
|
94
|
+
* changes); this deliberately avoids adding a dedicated poll so idle canvas
|
|
95
|
+
* perf is unaffected.
|
|
96
|
+
*/
|
|
97
|
+
function pinAnchorStillPresent(canvas: HTMLElement, pin: CanvasPin): boolean {
|
|
98
|
+
if (!pin.targetSelector) return true;
|
|
99
|
+
try {
|
|
100
|
+
return canvas.querySelector(pin.targetSelector) !== null;
|
|
101
|
+
} catch {
|
|
102
|
+
// A selector that no longer parses shouldn't be reported as "stale" —
|
|
103
|
+
// that's a different failure mode than "the element was removed".
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getTargetAnchor(target?: HTMLElement | null): {
|
|
109
|
+
targetSelector?: string;
|
|
110
|
+
targetAnchorId?: string;
|
|
111
|
+
} {
|
|
112
|
+
const anchor = target?.closest(
|
|
113
|
+
"[data-agent-native-node-id], [data-builder-id], [data-loc], [id]",
|
|
114
|
+
);
|
|
115
|
+
if (!(anchor instanceof HTMLElement)) return {};
|
|
116
|
+
|
|
117
|
+
for (const attribute of [
|
|
118
|
+
"data-agent-native-node-id",
|
|
119
|
+
"data-builder-id",
|
|
120
|
+
"data-loc",
|
|
121
|
+
]) {
|
|
122
|
+
const value = anchor.getAttribute(attribute);
|
|
123
|
+
if (value) {
|
|
124
|
+
return {
|
|
125
|
+
targetSelector: `[${attribute}="${escapeAttributeValue(value)}"]`,
|
|
126
|
+
targetAnchorId: value,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (anchor.id) {
|
|
132
|
+
return {
|
|
133
|
+
targetSelector: `#${escapeCssIdentifier(anchor.id)}`,
|
|
134
|
+
targetAnchorId: anchor.id,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getTargetBehindClickPlane(
|
|
142
|
+
clickPlane: HTMLElement,
|
|
143
|
+
canvas: HTMLElement,
|
|
144
|
+
clientX: number,
|
|
145
|
+
clientY: number,
|
|
146
|
+
): HTMLElement | null {
|
|
147
|
+
const pointerEvents = clickPlane.style.pointerEvents;
|
|
148
|
+
clickPlane.style.pointerEvents = "none";
|
|
149
|
+
try {
|
|
150
|
+
const targets = document.elementsFromPoint
|
|
151
|
+
? document.elementsFromPoint(clientX, clientY)
|
|
152
|
+
: [document.elementFromPoint(clientX, clientY)];
|
|
153
|
+
for (const target of targets) {
|
|
154
|
+
if (!(target instanceof HTMLElement) || !canvas.contains(target)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
return target instanceof HTMLIFrameElement ? null : target;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
} finally {
|
|
161
|
+
clickPlane.style.pointerEvents = pointerEvents;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Purely visual "same spot" check used to spread overlapping markers apart on
|
|
167
|
+
* screen. This also considers submitted pins so a new pin dropped on top of an
|
|
168
|
+
* earlier confirmation marker doesn't render fully hidden underneath it.
|
|
169
|
+
*/
|
|
170
|
+
function pinsAtSameSpot(pin: CanvasPin, other: CanvasPin): boolean {
|
|
171
|
+
if (pin.id === other.id) return false;
|
|
172
|
+
const xDelta = Math.abs(pin.xPct - other.xPct);
|
|
173
|
+
const yDelta = Math.abs(pin.yPct - other.yPct);
|
|
174
|
+
return xDelta <= 3 && yDelta <= 3;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Deterministic pixel nudge for a pin whose marker would otherwise render
|
|
179
|
+
* stacked exactly on top of an earlier pin at (approximately) the same
|
|
180
|
+
* canvas position. Pins are placed in a small golden-angle spiral around
|
|
181
|
+
* their true position so every marker in a cluster stays visible and
|
|
182
|
+
* individually clickable; the stored `xPct`/`yPct` (and the position sent to
|
|
183
|
+
* the agent) are unaffected.
|
|
184
|
+
*/
|
|
185
|
+
function pinClusterOffset(
|
|
186
|
+
pin: CanvasPin,
|
|
187
|
+
indexInPins: number,
|
|
188
|
+
pins: CanvasPin[],
|
|
189
|
+
): { dx: number; dy: number } {
|
|
190
|
+
let clusterIndex = 0;
|
|
191
|
+
for (let i = 0; i < indexInPins; i++) {
|
|
192
|
+
if (pinsAtSameSpot(pin, pins[i]!)) clusterIndex += 1;
|
|
193
|
+
}
|
|
194
|
+
if (clusterIndex === 0) return { dx: 0, dy: 0 };
|
|
195
|
+
const angle = clusterIndex * 2.4; // golden angle (radians) for even spread
|
|
196
|
+
const radius = 9 + clusterIndex * 5;
|
|
197
|
+
return {
|
|
198
|
+
dx: Math.round(Math.cos(angle) * radius),
|
|
199
|
+
dy: Math.round(Math.sin(angle) * radius),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Click-to-comment pins anchored to the canvas.
|
|
205
|
+
*
|
|
206
|
+
* Mirrors claude.ai/design's "inline comments" feature — the most-praised
|
|
207
|
+
* interaction pattern of that tool. A user clicks anywhere on the canvas to
|
|
208
|
+
* drop a pin, types a one-line instruction, and the pin's position + nearby
|
|
209
|
+
* element selector + instruction is sent to the agent. Submitted pins stay on
|
|
210
|
+
* the canvas as local confirmation; the agent's reply lands in the chat
|
|
211
|
+
* sidebar where it can make targeted edits.
|
|
212
|
+
*
|
|
213
|
+
* Why pins (vs text-anchored comments):
|
|
214
|
+
* The existing slide_comments table anchors comments to text selections via
|
|
215
|
+
* TipTap. That's good for prose review — but Rochkind also wants to point
|
|
216
|
+
* to images, charts, and whitespace. Pins handle those cases without
|
|
217
|
+
* requiring a text selection.
|
|
218
|
+
*/
|
|
219
|
+
export function CanvasCommentPins({
|
|
220
|
+
translate,
|
|
221
|
+
sendToAgent,
|
|
222
|
+
onSendError,
|
|
223
|
+
allowQueue = true,
|
|
224
|
+
showAnchorDetails = true,
|
|
225
|
+
showSubmitShortcut = true,
|
|
226
|
+
active,
|
|
227
|
+
submitMode = "direct",
|
|
228
|
+
onClose,
|
|
229
|
+
onPinsChange,
|
|
230
|
+
submitQueuedSignal,
|
|
231
|
+
clickPlaneUnderToolbar = false,
|
|
232
|
+
canvasSelector,
|
|
233
|
+
contextId,
|
|
234
|
+
contextLabel,
|
|
235
|
+
}: CanvasCommentPinsProps) {
|
|
236
|
+
const t = translate;
|
|
237
|
+
const [pins, setPins] = useState<CanvasPin[]>([]);
|
|
238
|
+
// Mirrors `pins` so the context-change reset effect below can inspect what
|
|
239
|
+
// was on the canvas the instant `contextId` changes, without re-running on
|
|
240
|
+
// every pin edit (it should only fire once, on the context switch itself).
|
|
241
|
+
const pinsRef = useRef<CanvasPin[]>(pins);
|
|
242
|
+
pinsRef.current = pins;
|
|
243
|
+
const [activePinId, setActivePinId] = useState<string | null>(null);
|
|
244
|
+
const [sending, setSending] = useState(false);
|
|
245
|
+
const containerRef = useRef<HTMLElement | null>(null);
|
|
246
|
+
const lastSubmitQueuedSignalRef = useRef(submitQueuedSignal);
|
|
247
|
+
const [canvasEl, setCanvasEl] = useState<HTMLElement | null>(null);
|
|
248
|
+
// Dummy tick forces a re-render (and a fresh getBoundingClientRect()) whenever
|
|
249
|
+
// the canvas scrolls or resizes, keeping pin overlays in sync.
|
|
250
|
+
const [, setLayoutTick] = useState(0);
|
|
251
|
+
|
|
252
|
+
// Reset pins when the context (slide) changes — they're scoped to one view.
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
// Queued-but-unsent comment drafts don't survive a context switch (pins
|
|
255
|
+
// are intentionally scoped to one view). Losing them is unavoidable here
|
|
256
|
+
// since we don't control cross-view navigation, but it must never be
|
|
257
|
+
// silent — warn instead of quietly wiping the user's typed drafts.
|
|
258
|
+
const discardedDraftCount = pinsRef.current.filter(
|
|
259
|
+
(pin) => pin.queued && !pin.submitted && (pin.draft || "").trim(),
|
|
260
|
+
).length;
|
|
261
|
+
if (discardedDraftCount > 0) {
|
|
262
|
+
toast(
|
|
263
|
+
t("visualEditor.queuedCommentsDiscarded", {
|
|
264
|
+
count: discardedDraftCount,
|
|
265
|
+
}),
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
setPins([]);
|
|
269
|
+
setActivePinId(null);
|
|
270
|
+
setCanvasEl(null);
|
|
271
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only fire on an
|
|
272
|
+
// actual context (slide/design) switch, not on every pins/t change.
|
|
273
|
+
}, [contextId]);
|
|
274
|
+
|
|
275
|
+
// Find the canvas container the pins overlay
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
if (!active) return;
|
|
278
|
+
const findCanvas = () => {
|
|
279
|
+
const el = document.querySelector(canvasSelector) as HTMLElement | null;
|
|
280
|
+
if (el) {
|
|
281
|
+
containerRef.current = el;
|
|
282
|
+
setCanvasEl(el);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
findCanvas();
|
|
286
|
+
const t = setTimeout(findCanvas, 50);
|
|
287
|
+
return () => clearTimeout(t);
|
|
288
|
+
}, [active, canvasSelector, contextId]);
|
|
289
|
+
|
|
290
|
+
// Re-render when the canvas element moves in the viewport (scroll or resize),
|
|
291
|
+
// so getBoundingClientRect() returns fresh coordinates for pin overlays.
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
const canvas = containerRef.current ?? canvasEl;
|
|
294
|
+
if (!canvas) return;
|
|
295
|
+
|
|
296
|
+
const bump = () => setLayoutTick((t) => t + 1);
|
|
297
|
+
|
|
298
|
+
// ResizeObserver fires when the canvas element's own size changes.
|
|
299
|
+
const ro = new ResizeObserver(bump);
|
|
300
|
+
ro.observe(canvas);
|
|
301
|
+
|
|
302
|
+
// Scroll listeners on every scrollable ancestor and the window cover both
|
|
303
|
+
// page-level scrolling and container-level panning. Walk the ancestor
|
|
304
|
+
// chain with getComputedStyle instead of a class-name heuristic so
|
|
305
|
+
// inline-styled, nested, and multiple scroll containers are all covered.
|
|
306
|
+
const isScrollable = (value: string) =>
|
|
307
|
+
value === "auto" || value === "scroll" || value === "overlay";
|
|
308
|
+
const scrollTargets: Array<HTMLElement | Window> = [];
|
|
309
|
+
for (let el: HTMLElement | null = canvas; el; el = el.parentElement) {
|
|
310
|
+
const style = getComputedStyle(el);
|
|
311
|
+
if (
|
|
312
|
+
isScrollable(style.overflow) ||
|
|
313
|
+
isScrollable(style.overflowX) ||
|
|
314
|
+
isScrollable(style.overflowY)
|
|
315
|
+
) {
|
|
316
|
+
scrollTargets.push(el);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
scrollTargets.push(window);
|
|
320
|
+
for (const target of scrollTargets) {
|
|
321
|
+
target.addEventListener("scroll", bump, { passive: true });
|
|
322
|
+
}
|
|
323
|
+
window.addEventListener("resize", bump, { passive: true });
|
|
324
|
+
|
|
325
|
+
return () => {
|
|
326
|
+
ro.disconnect();
|
|
327
|
+
for (const target of scrollTargets) {
|
|
328
|
+
target.removeEventListener("scroll", bump);
|
|
329
|
+
}
|
|
330
|
+
window.removeEventListener("resize", bump);
|
|
331
|
+
};
|
|
332
|
+
}, [canvasEl]);
|
|
333
|
+
|
|
334
|
+
const dropPinAt = useCallback(
|
|
335
|
+
(clientX: number, clientY: number, target?: HTMLElement | null) => {
|
|
336
|
+
const canvas = containerRef.current;
|
|
337
|
+
if (!canvas) return;
|
|
338
|
+
|
|
339
|
+
const rect = canvas.getBoundingClientRect();
|
|
340
|
+
const xPct = ((clientX - rect.left) / rect.width) * 100;
|
|
341
|
+
const yPct = ((clientY - rect.top) / rect.height) * 100;
|
|
342
|
+
if (xPct < 0 || xPct > 100 || yPct < 0 || yPct > 100) return; // i18n-ignore geometry bounds check, not UI copy
|
|
343
|
+
|
|
344
|
+
// Build a best-effort selector for parent-DOM canvases. For iframe
|
|
345
|
+
// canvases the transparent overlay captures the click, so target details
|
|
346
|
+
// are intentionally omitted but the precise position is preserved.
|
|
347
|
+
const { targetSelector, targetAnchorId } = getTargetAnchor(target);
|
|
348
|
+
const targetText = target?.textContent?.trim().slice(0, 80) || undefined;
|
|
349
|
+
|
|
350
|
+
const newPin: CanvasPin = {
|
|
351
|
+
id: crypto.randomUUID(),
|
|
352
|
+
xPct,
|
|
353
|
+
yPct,
|
|
354
|
+
targetSelector,
|
|
355
|
+
targetAnchorId,
|
|
356
|
+
targetText,
|
|
357
|
+
draft: "",
|
|
358
|
+
};
|
|
359
|
+
setPins((prev) => [...prev, newPin]);
|
|
360
|
+
setActivePinId(newPin.id);
|
|
361
|
+
},
|
|
362
|
+
[],
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
// Click handler — drops a pin where the user clicks a non-iframe canvas.
|
|
366
|
+
// Iframe canvases cannot bubble clicks to the parent, so the rendered
|
|
367
|
+
// transparent overlay below handles those reliably.
|
|
368
|
+
useEffect(() => {
|
|
369
|
+
if (!active) return;
|
|
370
|
+
const onClick = (e: MouseEvent) => {
|
|
371
|
+
const canvas = containerRef.current;
|
|
372
|
+
if (!canvas) return;
|
|
373
|
+
const target = e.target as HTMLElement;
|
|
374
|
+
|
|
375
|
+
// Ignore clicks on UI chrome (the pin popovers themselves)
|
|
376
|
+
if (target.closest("[data-pin-popover]")) return;
|
|
377
|
+
if (target.closest("[data-pin-click-overlay]")) return;
|
|
378
|
+
if (!canvas.contains(target)) return;
|
|
379
|
+
dropPinAt(e.clientX, e.clientY, target);
|
|
380
|
+
e.stopPropagation();
|
|
381
|
+
e.preventDefault();
|
|
382
|
+
};
|
|
383
|
+
window.addEventListener("click", onClick, { capture: true });
|
|
384
|
+
return () =>
|
|
385
|
+
window.removeEventListener("click", onClick, { capture: true });
|
|
386
|
+
}, [active, dropPinAt]);
|
|
387
|
+
|
|
388
|
+
// Escape closes pin mode
|
|
389
|
+
useEffect(() => {
|
|
390
|
+
if (!active) return;
|
|
391
|
+
const onKey = (e: KeyboardEvent) => {
|
|
392
|
+
if (e.key === "Escape") {
|
|
393
|
+
onClose();
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
window.addEventListener("keydown", onKey);
|
|
397
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
398
|
+
}, [active, onClose]);
|
|
399
|
+
|
|
400
|
+
const updatePin = (id: string, updates: Partial<CanvasPin>) => {
|
|
401
|
+
setPins((prev) =>
|
|
402
|
+
prev.map((p) => (p.id === id ? { ...p, ...updates } : p)),
|
|
403
|
+
);
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const removePin = (id: string) => {
|
|
407
|
+
setPins((prev) => prev.filter((p) => p.id !== id));
|
|
408
|
+
if (activePinId === id) setActivePinId(null);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const queuedPins = useMemo(
|
|
412
|
+
() =>
|
|
413
|
+
pins.filter(
|
|
414
|
+
(pin) => pin.queued && !pin.submitted && (pin.draft || "").trim(),
|
|
415
|
+
),
|
|
416
|
+
[pins],
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
useEffect(() => {
|
|
420
|
+
onPinsChange?.(pins);
|
|
421
|
+
}, [onPinsChange, pins]);
|
|
422
|
+
|
|
423
|
+
useEffect(() => {
|
|
424
|
+
if (
|
|
425
|
+
submitQueuedSignal === undefined ||
|
|
426
|
+
submitQueuedSignal === lastSubmitQueuedSignalRef.current
|
|
427
|
+
) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
lastSubmitQueuedSignalRef.current = submitQueuedSignal;
|
|
431
|
+
if (queuedPins.length === 0) return;
|
|
432
|
+
const submittedIds = new Set(queuedPins.map((pin) => pin.id));
|
|
433
|
+
setPins((prev) =>
|
|
434
|
+
prev.map((pin) =>
|
|
435
|
+
submittedIds.has(pin.id)
|
|
436
|
+
? { ...pin, queued: false, submitted: true }
|
|
437
|
+
: pin,
|
|
438
|
+
),
|
|
439
|
+
);
|
|
440
|
+
setActivePinId(null);
|
|
441
|
+
}, [queuedPins, submitQueuedSignal]);
|
|
442
|
+
|
|
443
|
+
const submittedCount = pins.filter((pin) => pin.submitted).length;
|
|
444
|
+
|
|
445
|
+
const buildPinLines = (pin: CanvasPin, index?: number) => {
|
|
446
|
+
const lines = [
|
|
447
|
+
index === undefined
|
|
448
|
+
? `[Comment pin on ${contextLabel || contextId}]`
|
|
449
|
+
: `[${index + 1}] Comment pin on ${contextLabel || contextId}`,
|
|
450
|
+
`Position: ${pin.xPct.toFixed(1)}% from left, ${pin.yPct.toFixed(1)}% from top`,
|
|
451
|
+
];
|
|
452
|
+
if (pin.targetAnchorId) lines.push(`Anchor id: ${pin.targetAnchorId}`);
|
|
453
|
+
if (pin.targetSelector) lines.push(`Element: ${pin.targetSelector}`);
|
|
454
|
+
if (pin.targetText) lines.push(`Nearby text: "${pin.targetText}"`);
|
|
455
|
+
lines.push("");
|
|
456
|
+
lines.push((pin.draft || "").trim());
|
|
457
|
+
return lines;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const sendPinsToAgent = async (
|
|
461
|
+
targetPins: CanvasPin[],
|
|
462
|
+
batch = false,
|
|
463
|
+
): Promise<boolean> => {
|
|
464
|
+
const message = batch
|
|
465
|
+
? [
|
|
466
|
+
`[Comment batch on ${contextLabel || contextId}]`,
|
|
467
|
+
`Annotations: ${targetPins.length}`,
|
|
468
|
+
"",
|
|
469
|
+
...targetPins.flatMap((pin, index) => [
|
|
470
|
+
...buildPinLines(pin, index),
|
|
471
|
+
"",
|
|
472
|
+
]),
|
|
473
|
+
].join("\n")
|
|
474
|
+
: buildPinLines(targetPins[0]!).join("\n");
|
|
475
|
+
|
|
476
|
+
try {
|
|
477
|
+
return await sendToAgent({
|
|
478
|
+
message,
|
|
479
|
+
submit: true,
|
|
480
|
+
openSidebar: true,
|
|
481
|
+
});
|
|
482
|
+
} catch (err) {
|
|
483
|
+
console.error("[CanvasCommentPins] failed to send to agent:", err);
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const queuePin = (pin: CanvasPin) => {
|
|
489
|
+
const text = (pin.draft || "").trim();
|
|
490
|
+
if (!text) {
|
|
491
|
+
removePin(pin.id);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
updatePin(pin.id, { draft: text, queued: true });
|
|
495
|
+
setActivePinId(null);
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
const submitPin = async (pin: CanvasPin) => {
|
|
499
|
+
const text = (pin.draft || "").trim();
|
|
500
|
+
if (!text) {
|
|
501
|
+
removePin(pin.id);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (submitMode === "queue") {
|
|
505
|
+
queuePin(pin);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const nextPin = { ...pin, draft: text };
|
|
509
|
+
setSending(true);
|
|
510
|
+
const delivered = await sendPinsToAgent([nextPin]);
|
|
511
|
+
setSending(false);
|
|
512
|
+
if (delivered) {
|
|
513
|
+
updatePin(pin.id, { draft: text, queued: false, submitted: true });
|
|
514
|
+
setActivePinId(null);
|
|
515
|
+
} else {
|
|
516
|
+
onSendError?.();
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
const submitQueuedPins = async () => {
|
|
521
|
+
if (queuedPins.length === 0) return;
|
|
522
|
+
if (submitMode === "queue") return;
|
|
523
|
+
setSending(true);
|
|
524
|
+
const delivered = await sendPinsToAgent(queuedPins, true);
|
|
525
|
+
setSending(false);
|
|
526
|
+
if (!delivered) {
|
|
527
|
+
onSendError?.();
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const submittedIds = new Set(queuedPins.map((pin) => pin.id));
|
|
531
|
+
setPins((prev) =>
|
|
532
|
+
prev.map((pin) =>
|
|
533
|
+
submittedIds.has(pin.id)
|
|
534
|
+
? { ...pin, queued: false, submitted: true }
|
|
535
|
+
: pin,
|
|
536
|
+
),
|
|
537
|
+
);
|
|
538
|
+
setActivePinId(null);
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
// Refs for drag-detection on the click overlay (Bug 3 fix).
|
|
542
|
+
// A pin is only dropped on a completed click, not on any drag gesture.
|
|
543
|
+
const overlayDownPos = useRef<{ x: number; y: number } | null>(null);
|
|
544
|
+
const overlayDidDrag = useRef(false);
|
|
545
|
+
|
|
546
|
+
if (!active && pins.length === 0) return null;
|
|
547
|
+
|
|
548
|
+
// Render pins as portaled overlays positioned on top of the canvas
|
|
549
|
+
const canvas = containerRef.current ?? canvasEl;
|
|
550
|
+
if (!canvas) return null;
|
|
551
|
+
const rect = canvas.getBoundingClientRect();
|
|
552
|
+
// Clamp summaryLeft so the w-64 (256px) panel, which is shifted left by
|
|
553
|
+
// -translate-x-full, never overflows the left viewport edge.
|
|
554
|
+
// 264 = 256 (panel width) + 8 (minimum margin from the viewport left edge).
|
|
555
|
+
const summaryLeft = Math.max(
|
|
556
|
+
264,
|
|
557
|
+
Math.min(rect.right - 8, window.innerWidth - 8),
|
|
558
|
+
);
|
|
559
|
+
const summaryTop = Math.max(rect.top + 8, 72);
|
|
560
|
+
|
|
561
|
+
return (
|
|
562
|
+
<TooltipProvider>
|
|
563
|
+
{/* Parent-side click plane. This is what makes iframe canvases commentable:
|
|
564
|
+
clicks inside an iframe never bubble to the parent document. */}
|
|
565
|
+
{active && (
|
|
566
|
+
<div
|
|
567
|
+
data-pin-click-overlay
|
|
568
|
+
className={cn(
|
|
569
|
+
"fixed cursor-crosshair",
|
|
570
|
+
clickPlaneUnderToolbar ? "z-[20]" : "z-[54]",
|
|
571
|
+
)}
|
|
572
|
+
style={{
|
|
573
|
+
left: rect.left,
|
|
574
|
+
top: rect.top,
|
|
575
|
+
width: rect.width,
|
|
576
|
+
height: rect.height,
|
|
577
|
+
}}
|
|
578
|
+
onPointerDown={(e) => {
|
|
579
|
+
overlayDownPos.current = { x: e.clientX, y: e.clientY };
|
|
580
|
+
overlayDidDrag.current = false;
|
|
581
|
+
e.stopPropagation();
|
|
582
|
+
}}
|
|
583
|
+
onPointerMove={(e) => {
|
|
584
|
+
if (overlayDownPos.current) {
|
|
585
|
+
const dx = e.clientX - overlayDownPos.current.x;
|
|
586
|
+
const dy = e.clientY - overlayDownPos.current.y;
|
|
587
|
+
if (dx * dx + dy * dy > 16) overlayDidDrag.current = true;
|
|
588
|
+
}
|
|
589
|
+
}}
|
|
590
|
+
onClick={(e) => {
|
|
591
|
+
e.preventDefault();
|
|
592
|
+
e.stopPropagation();
|
|
593
|
+
if (!overlayDidDrag.current) {
|
|
594
|
+
dropPinAt(
|
|
595
|
+
e.clientX,
|
|
596
|
+
e.clientY,
|
|
597
|
+
getTargetBehindClickPlane(
|
|
598
|
+
e.currentTarget,
|
|
599
|
+
canvas,
|
|
600
|
+
e.clientX,
|
|
601
|
+
e.clientY,
|
|
602
|
+
),
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
overlayDownPos.current = null;
|
|
606
|
+
overlayDidDrag.current = false;
|
|
607
|
+
}}
|
|
608
|
+
/>
|
|
609
|
+
)}
|
|
610
|
+
|
|
611
|
+
{/* Cursor hint banner — only when pin mode is active */}
|
|
612
|
+
{active && (
|
|
613
|
+
<div
|
|
614
|
+
data-pin-mode-banner
|
|
615
|
+
className="fixed top-16 left-1/2 -translate-x-1/2 z-50 flex items-center gap-2 rounded-full border border-border bg-popover px-3 py-1.5 shadow-lg pointer-events-none"
|
|
616
|
+
>
|
|
617
|
+
<IconMessage className="w-3.5 h-3.5 text-[#609FF8]" />
|
|
618
|
+
<span className="!text-[11px] text-foreground">
|
|
619
|
+
{t("visualEditor.clickToDropCommentPin")}
|
|
620
|
+
</span>
|
|
621
|
+
<span className="text-[10px] text-muted-foreground ml-1">
|
|
622
|
+
{t("visualEditor.escToExit")}
|
|
623
|
+
</span>
|
|
624
|
+
</div>
|
|
625
|
+
)}
|
|
626
|
+
|
|
627
|
+
{/* Compact queue/result summary for local annotation batching. */}
|
|
628
|
+
{allowQueue && pins.length > 0 && (
|
|
629
|
+
<div
|
|
630
|
+
data-pin-popover
|
|
631
|
+
className="fixed z-[56] w-64 -translate-x-full rounded-lg border border-border bg-popover p-3 shadow-xl"
|
|
632
|
+
style={{ left: summaryLeft, top: summaryTop }}
|
|
633
|
+
>
|
|
634
|
+
<div className="mb-2 flex items-center justify-between gap-2">
|
|
635
|
+
<div className="min-w-0">
|
|
636
|
+
<p className="truncate text-xs font-semibold text-foreground">
|
|
637
|
+
{t("visualEditor.annotationQueue")}
|
|
638
|
+
</p>
|
|
639
|
+
<p className="text-[10px] text-muted-foreground">
|
|
640
|
+
{t("visualEditor.annotationQueueCounts", {
|
|
641
|
+
queued: queuedPins.length,
|
|
642
|
+
sent: submittedCount,
|
|
643
|
+
})}
|
|
644
|
+
</p>
|
|
645
|
+
</div>
|
|
646
|
+
{submitMode === "direct" ? (
|
|
647
|
+
<Button
|
|
648
|
+
size="sm"
|
|
649
|
+
className="h-7 gap-1 px-2 text-[10px]"
|
|
650
|
+
onClick={submitQueuedPins}
|
|
651
|
+
disabled={queuedPins.length === 0 || sending}
|
|
652
|
+
>
|
|
653
|
+
{sending ? (
|
|
654
|
+
<IconLoader2 className="size-3 animate-spin" />
|
|
655
|
+
) : (
|
|
656
|
+
<IconBolt className="size-3" />
|
|
657
|
+
)}
|
|
658
|
+
{t("visualEditor.batchApply")}
|
|
659
|
+
</Button>
|
|
660
|
+
) : (
|
|
661
|
+
<span className="rounded-md bg-muted px-2 py-1 text-[10px] font-medium text-muted-foreground">
|
|
662
|
+
{t("visualEditor.queued")}
|
|
663
|
+
</span>
|
|
664
|
+
)}
|
|
665
|
+
</div>
|
|
666
|
+
</div>
|
|
667
|
+
)}
|
|
668
|
+
|
|
669
|
+
{/* Pin overlays */}
|
|
670
|
+
{pins.map((pin, pinIndex) => {
|
|
671
|
+
const { dx, dy } = pinClusterOffset(pin, pinIndex, pins);
|
|
672
|
+
const left = rect.left + (pin.xPct / 100) * rect.width + dx;
|
|
673
|
+
const top = rect.top + (pin.yPct / 100) * rect.height + dy;
|
|
674
|
+
const isActive = activePinId === pin.id;
|
|
675
|
+
const PinIcon = pin.submitted ? IconMessageCheck : IconMessage;
|
|
676
|
+
// Not submitted yet + claims a specific anchor that's no longer on
|
|
677
|
+
// the canvas (e.g. the element was deleted or the design was edited
|
|
678
|
+
// elsewhere) — flag it instead of silently pretending the position
|
|
679
|
+
// is still meaningful.
|
|
680
|
+
const isStaleAnchor =
|
|
681
|
+
!pin.submitted && !pinAnchorStillPresent(canvas, pin);
|
|
682
|
+
return (
|
|
683
|
+
<div
|
|
684
|
+
key={pin.id}
|
|
685
|
+
data-pin-popover
|
|
686
|
+
data-pin-id={pin.id}
|
|
687
|
+
className="fixed z-[55]"
|
|
688
|
+
style={{ left, top }}
|
|
689
|
+
>
|
|
690
|
+
{/* Pin marker. The tooltip is suppressed while the composer is
|
|
691
|
+
* open: the textarea already shows the same draft text, and a
|
|
692
|
+
* shadcn TooltipContent (z-[250], no `pointer-events: none`) was
|
|
693
|
+
* intercepting Send-button clicks for pins near the top of the
|
|
694
|
+
* canvas where Radix auto-flips the tooltip below the trigger
|
|
695
|
+
* and onto the composer. */}
|
|
696
|
+
<Tooltip open={isActive ? false : undefined}>
|
|
697
|
+
<TooltipTrigger asChild>
|
|
698
|
+
<button
|
|
699
|
+
onClick={() => {
|
|
700
|
+
if (!pin.submitted) setActivePinId(pin.id);
|
|
701
|
+
}}
|
|
702
|
+
className={cn(
|
|
703
|
+
"absolute -mt-1 flex size-7 -translate-x-1/2 -translate-y-full cursor-pointer items-center justify-center rounded-full rounded-bl-none shadow-lg ring-2 transition-transform hover:scale-110",
|
|
704
|
+
pin.submitted
|
|
705
|
+
? "bg-emerald-500 text-white ring-emerald-200"
|
|
706
|
+
: "bg-[#609FF8] text-white ring-blue-200",
|
|
707
|
+
pin.submitted && "opacity-95",
|
|
708
|
+
isStaleAnchor &&
|
|
709
|
+
"outline outline-2 outline-dashed outline-offset-2 outline-muted-foreground/70",
|
|
710
|
+
)}
|
|
711
|
+
>
|
|
712
|
+
<PinIcon className="size-3.5" />
|
|
713
|
+
</button>
|
|
714
|
+
</TooltipTrigger>
|
|
715
|
+
<TooltipContent className="pointer-events-none">
|
|
716
|
+
{isStaleAnchor
|
|
717
|
+
? t("visualEditor.staleAnchorDetail")
|
|
718
|
+
: pin.queued
|
|
719
|
+
? t("visualEditor.queued")
|
|
720
|
+
: pin.draft ||
|
|
721
|
+
(pin.submitted
|
|
722
|
+
? t("visualEditor.commentSent")
|
|
723
|
+
: t("visualEditor.comment"))}
|
|
724
|
+
</TooltipContent>
|
|
725
|
+
</Tooltip>
|
|
726
|
+
|
|
727
|
+
{/* Inline composer. z-[260] keeps it above the shadcn floating-UI
|
|
728
|
+
* tier (z-[250] — Tooltip, Popover, Dialog overlay, etc.) so a
|
|
729
|
+
* stray tooltip that pops over the pin can't swallow Send clicks.
|
|
730
|
+
* Composer is flipped horizontally and/or vertically when the pin
|
|
731
|
+
* is near a viewport edge so it stays fully on-screen. */}
|
|
732
|
+
{isActive &&
|
|
733
|
+
!pin.submitted &&
|
|
734
|
+
(() => {
|
|
735
|
+
const composerW = 288; // w-72
|
|
736
|
+
const composerH = 220; // estimated height
|
|
737
|
+
const flipX = left + 12 + composerW > window.innerWidth;
|
|
738
|
+
const flipY = top + 4 + composerH > window.innerHeight;
|
|
739
|
+
return (
|
|
740
|
+
<div
|
|
741
|
+
data-pin-popover
|
|
742
|
+
className="absolute z-[260] w-72 rounded-lg border border-border bg-popover shadow-xl p-2"
|
|
743
|
+
style={{
|
|
744
|
+
...(flipX
|
|
745
|
+
? { right: "calc(100% + 4px)", left: "auto" }
|
|
746
|
+
: { left: "0.75rem" }),
|
|
747
|
+
...(flipY
|
|
748
|
+
? { bottom: "calc(100% + 4px)", top: "auto" }
|
|
749
|
+
: { top: "0.25rem" }),
|
|
750
|
+
}}
|
|
751
|
+
>
|
|
752
|
+
<p className="mb-2 text-xs font-semibold text-foreground">
|
|
753
|
+
{t("visualEditor.editDesign")}
|
|
754
|
+
</p>
|
|
755
|
+
<Textarea
|
|
756
|
+
autoFocus
|
|
757
|
+
value={pin.draft || ""}
|
|
758
|
+
onChange={(e) =>
|
|
759
|
+
updatePin(pin.id, {
|
|
760
|
+
draft: e.target.value,
|
|
761
|
+
queued: false,
|
|
762
|
+
})
|
|
763
|
+
}
|
|
764
|
+
onKeyDown={(e) => {
|
|
765
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
|
766
|
+
e.preventDefault();
|
|
767
|
+
submitPin(pin);
|
|
768
|
+
}
|
|
769
|
+
if (e.key === "Escape") {
|
|
770
|
+
// Stop propagation so the window Escape listener (which
|
|
771
|
+
// calls onClose) does not also fire. Collapse the composer
|
|
772
|
+
// back to the pin dot while preserving the draft text —
|
|
773
|
+
// the pin and any typed draft survive. A second Escape
|
|
774
|
+
// with no composer open exits pin mode, matching Figma.
|
|
775
|
+
e.stopPropagation();
|
|
776
|
+
e.preventDefault();
|
|
777
|
+
setActivePinId(null);
|
|
778
|
+
}
|
|
779
|
+
}}
|
|
780
|
+
placeholder={t("visualEditor.tellAgentWhatToChange")}
|
|
781
|
+
className="resize-none text-xs min-h-[60px]"
|
|
782
|
+
/>
|
|
783
|
+
{showAnchorDetails && pin.targetAnchorId && (
|
|
784
|
+
<div
|
|
785
|
+
className={cn(
|
|
786
|
+
"mt-1 truncate rounded-md px-2 py-1 text-[10px]",
|
|
787
|
+
isStaleAnchor
|
|
788
|
+
? "bg-destructive/10 text-destructive"
|
|
789
|
+
: "bg-muted/45 text-muted-foreground",
|
|
790
|
+
)}
|
|
791
|
+
>
|
|
792
|
+
{isStaleAnchor
|
|
793
|
+
? t("visualEditor.staleAnchorDetail")
|
|
794
|
+
: t("visualEditor.anchorLabel", {
|
|
795
|
+
id: pin.targetAnchorId,
|
|
796
|
+
})}
|
|
797
|
+
</div>
|
|
798
|
+
)}
|
|
799
|
+
{showAnchorDetails && pin.targetText && (
|
|
800
|
+
<div className="text-[10px] text-muted-foreground mt-1 italic line-clamp-1">
|
|
801
|
+
{t("visualEditor.nearText", { text: pin.targetText })}
|
|
802
|
+
</div>
|
|
803
|
+
)}
|
|
804
|
+
<div className="flex items-center justify-between mt-2">
|
|
805
|
+
{showSubmitShortcut ? (
|
|
806
|
+
<span className="text-[10px] text-muted-foreground">
|
|
807
|
+
{t("visualEditor.submitShortcut", {
|
|
808
|
+
mod: /Mac|iPhone|iPad/.test(navigator.userAgent)
|
|
809
|
+
? "⌘"
|
|
810
|
+
: "Ctrl",
|
|
811
|
+
})}
|
|
812
|
+
</span>
|
|
813
|
+
) : (
|
|
814
|
+
<span />
|
|
815
|
+
)}
|
|
816
|
+
<div className="flex gap-1">
|
|
817
|
+
<Button
|
|
818
|
+
size="sm"
|
|
819
|
+
variant="ghost"
|
|
820
|
+
className="h-6 px-2 text-[10px] cursor-pointer"
|
|
821
|
+
onClick={() => removePin(pin.id)}
|
|
822
|
+
>
|
|
823
|
+
<IconX className="w-3 h-3" />
|
|
824
|
+
</Button>
|
|
825
|
+
{allowQueue ? (
|
|
826
|
+
<Button
|
|
827
|
+
size="sm"
|
|
828
|
+
variant="outline"
|
|
829
|
+
className="h-6 gap-1 px-2 text-[10px] cursor-pointer"
|
|
830
|
+
onClick={() => queuePin(pin)}
|
|
831
|
+
disabled={!(pin.draft || "").trim()}
|
|
832
|
+
>
|
|
833
|
+
{t("visualEditor.queue")}
|
|
834
|
+
</Button>
|
|
835
|
+
) : null}
|
|
836
|
+
{submitMode === "direct" && (
|
|
837
|
+
<Button
|
|
838
|
+
size="sm"
|
|
839
|
+
className="h-6 gap-1 px-2 text-[10px] cursor-pointer"
|
|
840
|
+
onClick={() => submitPin(pin)}
|
|
841
|
+
disabled={!(pin.draft || "").trim() || sending}
|
|
842
|
+
>
|
|
843
|
+
{sending ? (
|
|
844
|
+
<IconLoader2 className="size-3 animate-spin" />
|
|
845
|
+
) : (
|
|
846
|
+
<IconSend className="size-3" />
|
|
847
|
+
)}
|
|
848
|
+
{t("visualEditor.send")}
|
|
849
|
+
</Button>
|
|
850
|
+
)}
|
|
851
|
+
</div>
|
|
852
|
+
</div>
|
|
853
|
+
</div>
|
|
854
|
+
);
|
|
855
|
+
})()}
|
|
856
|
+
</div>
|
|
857
|
+
);
|
|
858
|
+
})}
|
|
859
|
+
</TooltipProvider>
|
|
860
|
+
);
|
|
861
|
+
}
|