@salesforce/metadata-core-sdk 1.5.0 → 1.6.0

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.
Files changed (58) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +26 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/sdk/contracts/core/IMetadataParser.d.ts +22 -0
  6. package/dist/sdk/contracts/core/IMetadataParser.d.ts.map +1 -1
  7. package/dist/sdk/contracts/types/SelectableNode.d.ts +62 -0
  8. package/dist/sdk/contracts/types/SelectableNode.d.ts.map +1 -0
  9. package/dist/sdk/contracts/types/SelectableNode.js +8 -0
  10. package/dist/sdk/contracts/types/SelectableNode.js.map +1 -0
  11. package/dist/sdk/contracts/types/index.d.ts +1 -0
  12. package/dist/sdk/contracts/types/index.d.ts.map +1 -1
  13. package/dist/sdk/contracts/types/index.js +1 -0
  14. package/dist/sdk/contracts/types/index.js.map +1 -1
  15. package/dist/sdk/hooks/vibe-edit/index.d.ts +39 -0
  16. package/dist/sdk/hooks/vibe-edit/index.d.ts.map +1 -0
  17. package/dist/sdk/hooks/vibe-edit/index.js +42 -0
  18. package/dist/sdk/hooks/vibe-edit/index.js.map +1 -0
  19. package/dist/sdk/hooks/vibe-edit/selection/selectionGeometry.d.ts +56 -0
  20. package/dist/sdk/hooks/vibe-edit/selection/selectionGeometry.d.ts.map +1 -0
  21. package/dist/sdk/hooks/vibe-edit/selection/selectionGeometry.js +138 -0
  22. package/dist/sdk/hooks/vibe-edit/selection/selectionGeometry.js.map +1 -0
  23. package/dist/sdk/hooks/vibe-edit/selection/selectionGraph.d.ts +66 -0
  24. package/dist/sdk/hooks/vibe-edit/selection/selectionGraph.d.ts.map +1 -0
  25. package/dist/sdk/hooks/vibe-edit/selection/selectionGraph.js +73 -0
  26. package/dist/sdk/hooks/vibe-edit/selection/selectionGraph.js.map +1 -0
  27. package/dist/sdk/hooks/vibe-edit/selection/selectionGraphEngine.d.ts +64 -0
  28. package/dist/sdk/hooks/vibe-edit/selection/selectionGraphEngine.d.ts.map +1 -0
  29. package/dist/sdk/hooks/vibe-edit/selection/selectionGraphEngine.js +161 -0
  30. package/dist/sdk/hooks/vibe-edit/selection/selectionGraphEngine.js.map +1 -0
  31. package/dist/sdk/hooks/vibe-edit/selection/types.d.ts +47 -0
  32. package/dist/sdk/hooks/vibe-edit/selection/types.d.ts.map +1 -0
  33. package/dist/sdk/hooks/vibe-edit/selection/types.js +40 -0
  34. package/dist/sdk/hooks/vibe-edit/selection/types.js.map +1 -0
  35. package/dist/sdk/hooks/vibe-edit/selection/useMarqueeSelection.d.ts +30 -0
  36. package/dist/sdk/hooks/vibe-edit/selection/useMarqueeSelection.d.ts.map +1 -0
  37. package/dist/sdk/hooks/vibe-edit/selection/useMarqueeSelection.js +50 -0
  38. package/dist/sdk/hooks/vibe-edit/selection/useMarqueeSelection.js.map +1 -0
  39. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.css +26 -0
  40. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.d.ts +84 -0
  41. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.d.ts.map +1 -0
  42. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.js +256 -0
  43. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.js.map +1 -0
  44. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.css +207 -0
  45. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.d.ts +43 -0
  46. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.d.ts.map +1 -0
  47. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.js +80 -0
  48. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.js.map +1 -0
  49. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.css +79 -0
  50. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.d.ts +116 -0
  51. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.d.ts.map +1 -0
  52. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.js +264 -0
  53. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.js.map +1 -0
  54. package/dist/sdk/webviewMessageTypes.d.ts +77 -0
  55. package/dist/sdk/webviewMessageTypes.d.ts.map +1 -1
  56. package/dist/sdk/webviewMessageTypes.js +7 -4
  57. package/dist/sdk/webviewMessageTypes.js.map +1 -1
  58. package/package.json +11 -3
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Copyright (c) 2025, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+
8
+ /* Select-mode toggle button shipped by useVibeEdit(). Per the design spec this
9
+ is a NEUTRAL rounded-rectangle button in the resting state (not a blue pill):
10
+ the blue is reserved for the ACTIVE (selecting) state, giving a clear
11
+ neutral→blue on/off signal. */
12
+ .mv-vibe-edit-toggle {
13
+ display: inline-flex;
14
+ align-items: center;
15
+ gap: var(--mv-spacing-xs);
16
+ padding: var(--mv-spacing-xs) var(--mv-spacing-md);
17
+ font-size: var(--mv-font-size-xs);
18
+ font-weight: var(--mv-font-weight-medium);
19
+ /* Resting = neutral secondary button: dark text, gray border, subtle surface
20
+ fill. Rounded rectangle (radius-md), NOT a full pill. */
21
+ color: var(--mv-text-primary);
22
+ background: var(--mv-bg-surface);
23
+ border: 1px solid var(--mv-border-default);
24
+ border-radius: var(--mv-radius-md);
25
+ cursor: pointer;
26
+ transition: all var(--mv-transition-fast);
27
+ }
28
+
29
+ .mv-vibe-edit-toggle:hover {
30
+ background: var(--mv-bg-surface-hover);
31
+ border-color: var(--mv-border-hover, var(--mv-border-default));
32
+ }
33
+
34
+ /* Active (selecting) state: blue OUTLINE — blue text + border over a light
35
+ fill (not a solid blue fill), matching the design's active variant. */
36
+ .mv-vibe-edit-toggle--active {
37
+ color: var(--mv-interactive-primary);
38
+ background: var(--mv-interactive-primary-subtle, color-mix(in srgb, var(--mv-interactive-primary) 10%, transparent));
39
+ border-color: var(--mv-interactive-primary);
40
+ }
41
+
42
+ /* Hover + selection outline reflected by useVibeEdit onto the matching
43
+ [data-mv-id] element. The literals MUST mirror HOVER_ATTR / SELECTED_ATTR in
44
+ selection/types.ts. outline (not border) avoids layout shift.
45
+
46
+ Hover and selected are DELIBERATELY distinct (design spec):
47
+ - hover / bulk-preview → prominent DASHED 2px line (what WILL be selected)
48
+ - selected → bold SOLID 2px line + light-blue fill (committed)
49
+ The earlier 1px lines read as "almost invisible" over the busy canvas, and
50
+ the dotted bulk-preview was too faint to see mid-drag; both are now 2px and
51
+ the committed selection gets a translucent blue fill so it reads clearly
52
+ (matching the desired Image #4 selection style).
53
+
54
+ outline-offset is NEGATIVE so the line is drawn just INSIDE the element edge.
55
+ A positive offset draws the outline OUTSIDE the box, where an ancestor with
56
+ overflow:hidden (e.g. a React Flow node card / scroll container) clips its
57
+ left & right sides — the "selection box cut off on the sides" rendering bug.
58
+ Insetting the line by 2px keeps it fully within the clipping rect. */
59
+ [data-mv-hover] {
60
+ outline: 2px dashed var(--mv-interactive-primary);
61
+ outline-offset: -2px;
62
+ border-radius: var(--mv-radius-sm);
63
+ /* Faint tint so the bulk-selection preview is visible mid-drag, not just an
64
+ outline that gets lost against node chrome. */
65
+ background-color: color-mix(in srgb, var(--mv-interactive-primary) 8%, transparent);
66
+ }
67
+
68
+ /* Selected wins over hover on an element that is both: this rule follows the
69
+ hover rule, so at equal specificity the solid outline takes precedence. */
70
+ [data-mv-selected] {
71
+ outline: 2px solid var(--mv-interactive-primary);
72
+ outline-offset: -2px;
73
+ border-radius: var(--mv-radius-sm);
74
+ /* Bold blue border + light-blue fill — the prominent committed-selection look
75
+ from the design (Image #4). color-mix keeps it theme-driven off the single
76
+ interactive-primary token, so it tracks light/dark automatically. */
77
+ background-color: color-mix(in srgb, var(--mv-interactive-primary) 16%, transparent);
78
+ box-shadow: 0 0 0 1px color-mix(in srgb, var(--mv-interactive-primary) 40%, transparent);
79
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ /**
8
+ * useVibeEdit — the drop-in vibe-edit hook (plugin-side, core-sdk).
9
+ *
10
+ * SelectionGraph (C1 + C4) — the single, final selection path. The plugin's
11
+ * parser emits a normalized `SelectableNode[]` (via IMetadataParser.getSelectableNodes),
12
+ * and each node is rendered with `data-mv-id={node.id}`. Given those nodes the
13
+ * hook does EVERYTHING generically:
14
+ *
15
+ * - stamps the hit-test contract (data-mv-selectable / -type) onto the tagged
16
+ * elements, kept live across re-renders via a MutationObserver, and
17
+ * - builds SpatialContext by a pure `Map.get(id)` over the nodes — no
18
+ * per-plugin buildContext, no descriptors, no shape traversal.
19
+ *
20
+ * The plugin's only residue is the parser's one-time node projection plus the
21
+ * `data-mv-id` render — there is no plugin-side selection logic.
22
+ *
23
+ * The hook internally owns: the useMarqueeSelection state machine, the
24
+ * MarqueeSelection overlay (active when select-mode is on), the VibeEditPanel,
25
+ * a select-mode toggle button, chip generation from the current selection, and
26
+ * the handoff — building the EditRequest and calling
27
+ * sendToHost({ type: SUBMIT_EDIT, payload }).
28
+ *
29
+ * Because plugins render their own React DOM inside an iframe the framework
30
+ * cannot reach, a plugin-side hook is the only architecturally valid home for
31
+ * this logic (ARCHITECTURE.md §3).
32
+ */
33
+ import React from 'react';
34
+ import type { SelectableNode } from '../selection/selectionGraph.js';
35
+ import { type VibeEditChip } from './VibeEditPanel.js';
36
+ import type { SpatialContext } from '../../../webviewMessageTypes.js';
37
+ import './useVibeEdit.css';
38
+ /** Optional ergonomics for the hook's built-in UI pieces. */
39
+ export interface UseVibeEditOptions {
40
+ /** Placeholder for the VibeEditPanel prompt textarea. */
41
+ placeholder?: string;
42
+ /** Label shown on the toggle when select-mode is OFF. Default: 'Select'. */
43
+ selectLabel?: string;
44
+ /** Label shown on the toggle when select-mode is ON. Default: 'Selecting'. */
45
+ selectingLabel?: string;
46
+ /**
47
+ * Builds a chip for a selected element. Defaults to label = apiName, title =
48
+ * `${elementType}: ${apiName}`, variant = 'primary' for `field` elements.
49
+ */
50
+ chipFor?: (ctx: SpatialContext) => VibeEditChip;
51
+ /**
52
+ * Called when the user double-clicks a selectable element while in select-mode.
53
+ * Lets the plugin drill into a nested view (e.g. open a subagent's detail) WITHOUT
54
+ * leaving select-mode. Receives the node id (data-mv-id) of the activated element.
55
+ */
56
+ onActivate?: (nodeId: string) => void;
57
+ }
58
+ export interface UseVibeEditResult {
59
+ /** Select-mode toggle button — mount in the toolbar. */
60
+ toggleButton: React.ReactNode;
61
+ /** Marquee overlay — mount over the (positioned) canvas. */
62
+ overlay: React.ReactNode;
63
+ /** The prompt / chip / submit panel — mount once near the canvas. */
64
+ panel: React.ReactNode;
65
+ /** Whether select-mode is currently active. */
66
+ selectMode: boolean;
67
+ /** True if a given type::id is currently selected. */
68
+ isSelected: (type: string, id: string) => boolean;
69
+ /**
70
+ * Imperatively toggle a node's membership in the current selection by its
71
+ * `type` + `id` (the same `data-mv-type` / `data-mv-id` the node renders).
72
+ *
73
+ * The marquee overlay only covers the positioned canvas, so selectable
74
+ * elements rendered OUTSIDE it (e.g. the flow inspector sidebar's
75
+ * detail rows, a sibling flex column) can never be reached by a click/drag
76
+ * hit-test. Those elements are still tagged (the engine's tagger scans the
77
+ * whole document) and still get the `[data-mv-selected]` CSS, but they need
78
+ * this explicit write path to actually join the one unified selection set —
79
+ * so a single SUBMIT_EDIT carries canvas + sidebar picks together. A no-op
80
+ * when select-mode is off.
81
+ */
82
+ toggle: (type: string, id: string) => void;
83
+ }
84
+ /**
85
+ * Vibe-edit availability predicate — the feature-gate contract.
86
+ *
87
+ * The host (VS Code engine / framework web path) forwards `SelectableNode[]`
88
+ * ONLY when vibe-edit is wired end-to-end AND enabled: it withholds them when
89
+ * the feature is gated off (e.g. App Studio's SPA drops `selectableNodes` when
90
+ * the `vibeEdit` gate is closed). So the presence of nodes IS the on-signal and
91
+ * their absence is graceful degradation — no separate flag rides the wire.
92
+ *
93
+ * Pure so it can be unit-tested in core-sdk's node-env jest project (no DOM /
94
+ * testing-library); the hook branches on it to render no selection UI when off.
95
+ */
96
+ export declare function isVibeEditAvailable(nodes: SelectableNode[]): boolean;
97
+ /**
98
+ * The vibe-edit hook. Mount the three returned nodes (toggleButton, overlay,
99
+ * panel) and render `data-mv-id={node.id}` on each selectable element; pass the
100
+ * same `nodes` the parser emitted.
101
+ */
102
+ export declare function useVibeEdit(args: {
103
+ /** The normalized node list emitted by the plugin's parser (SelectionGraph). */
104
+ nodes: SelectableNode[];
105
+ /**
106
+ * File-level name of the current metadata file (from the plugin data
107
+ * context's `fileName`). Stamped onto every SpatialContext as the fallback so
108
+ * the always-available `fileName` contract holds even for nodes that carry no
109
+ * per-node `filePath` (e.g. flexipage region/component nodes). Optional; when
110
+ * omitted, only nodes with their own `filePath` surface a fileName.
111
+ */
112
+ fileName?: string;
113
+ /** Optional UI ergonomics. */
114
+ options?: UseVibeEditOptions;
115
+ }): UseVibeEditResult;
116
+ //# sourceMappingURL=useVibeEdit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVibeEdit.d.ts","sourceRoot":"","sources":["../../../../../src/sdk/hooks/vibe-edit/ui/useVibeEdit.tsx"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAA4D,MAAM,OAAO,CAAC;AAIjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKrE,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGtE,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACn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esforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ /**
8
+ * useVibeEdit — the drop-in vibe-edit hook (plugin-side, core-sdk).
9
+ *
10
+ * SelectionGraph (C1 + C4) — the single, final selection path. The plugin's
11
+ * parser emits a normalized `SelectableNode[]` (via IMetadataParser.getSelectableNodes),
12
+ * and each node is rendered with `data-mv-id={node.id}`. Given those nodes the
13
+ * hook does EVERYTHING generically:
14
+ *
15
+ * - stamps the hit-test contract (data-mv-selectable / -type) onto the tagged
16
+ * elements, kept live across re-renders via a MutationObserver, and
17
+ * - builds SpatialContext by a pure `Map.get(id)` over the nodes — no
18
+ * per-plugin buildContext, no descriptors, no shape traversal.
19
+ *
20
+ * The plugin's only residue is the parser's one-time node projection plus the
21
+ * `data-mv-id` render — there is no plugin-side selection logic.
22
+ *
23
+ * The hook internally owns: the useMarqueeSelection state machine, the
24
+ * MarqueeSelection overlay (active when select-mode is on), the VibeEditPanel,
25
+ * a select-mode toggle button, chip generation from the current selection, and
26
+ * the handoff — building the EditRequest and calling
27
+ * sendToHost({ type: SUBMIT_EDIT, payload }).
28
+ *
29
+ * Because plugins render their own React DOM inside an iframe the framework
30
+ * cannot reach, a plugin-side hook is the only architecturally valid home for
31
+ * this logic (ARCHITECTURE.md §3).
32
+ */
33
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
34
+ import { MarqueeSelection } from './MarqueeSelection.js';
35
+ import { useMarqueeSelection } from '../selection/useMarqueeSelection.js';
36
+ import { TYPE_ATTR, SELECTED_ATTR, HOVER_ATTR } from '../selection/types.js';
37
+ import { tagSelectionGraphLive, buildContextsFromNodes, } from '../selection/selectionGraphEngine.js';
38
+ import { VibeEditPanel } from './VibeEditPanel.js';
39
+ import { sendToHost } from '../../../utils/HostCommunicationUtils.js';
40
+ import { WebviewMessageType } from '../../../webviewMessageTypes.js';
41
+ import './useVibeEdit.css';
42
+ /**
43
+ * Vibe-edit availability predicate — the feature-gate contract.
44
+ *
45
+ * The host (VS Code engine / framework web path) forwards `SelectableNode[]`
46
+ * ONLY when vibe-edit is wired end-to-end AND enabled: it withholds them when
47
+ * the feature is gated off (e.g. App Studio's SPA drops `selectableNodes` when
48
+ * the `vibeEdit` gate is closed). So the presence of nodes IS the on-signal and
49
+ * their absence is graceful degradation — no separate flag rides the wire.
50
+ *
51
+ * Pure so it can be unit-tested in core-sdk's node-env jest project (no DOM /
52
+ * testing-library); the hook branches on it to render no selection UI when off.
53
+ */
54
+ export function isVibeEditAvailable(nodes) {
55
+ return nodes.length > 0;
56
+ }
57
+ /** Default chip projection from a SpatialContext. */
58
+ function defaultChipFor(ctx) {
59
+ return {
60
+ label: ctx.apiName,
61
+ title: `${ctx.elementType}: ${ctx.apiName}`,
62
+ variant: ctx.elementType === 'field' ? 'primary' : 'default',
63
+ };
64
+ }
65
+ /**
66
+ * Toggle glyph: a pointer/cursor arrow sitting inside a dashed marquee box —
67
+ * "select (drag a box) to edit". Matches the design's Select-to-Edit icon
68
+ * (cursor + marquee), replacing the earlier dashed-box-with-checkmark.
69
+ */
70
+ function ToggleIcon() {
71
+ return (React.createElement("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true" },
72
+ React.createElement("rect", { x: "1.5", y: "1.5", width: "9", height: "9", stroke: "currentColor", strokeWidth: "1.25", strokeDasharray: "2 1.75" }),
73
+ React.createElement("path", { d: "M7 7l7 2.6-2.9 0.9-0.9 2.9L7 7z", fill: "currentColor", stroke: "currentColor", strokeWidth: "0.5", strokeLinejoin: "round" })));
74
+ }
75
+ /**
76
+ * The vibe-edit hook. Mount the three returned nodes (toggleButton, overlay,
77
+ * panel) and render `data-mv-id={node.id}` on each selectable element; pass the
78
+ * same `nodes` the parser emitted.
79
+ */
80
+ export function useVibeEdit(args) {
81
+ const { nodes, fileName, options } = args;
82
+ const placeholder = options?.placeholder;
83
+ const selectLabel = options?.selectLabel ?? 'Select';
84
+ const selectingLabel = options?.selectingLabel ?? 'Selecting';
85
+ const chipFor = options?.chipFor ?? defaultChipFor;
86
+ const onActivate = options?.onActivate;
87
+ const [selectMode, setSelectMode] = useState(false);
88
+ const [hovered, setHovered] = useState(null);
89
+ // Elements the in-progress marquee currently covers (bulk-selection preview).
90
+ // Keyed by `type::id`; reflected onto the DOM as the dotted hover mark so the
91
+ // user sees what WILL be selected while still dragging. Empty when not dragging.
92
+ const [previewed, setPreviewed] = useState([]);
93
+ const marquee = useMarqueeSelection();
94
+ // The plugin rendered data-mv-id={node.id}; the engine stamps the hit-test
95
+ // contract (data-mv-selectable / -type) onto those elements and keeps it live
96
+ // across re-renders via a MutationObserver (childList + subtree only).
97
+ const graphTagRef = useRef(new Map());
98
+ useEffect(() => {
99
+ if (!selectMode) {
100
+ return;
101
+ }
102
+ return tagSelectionGraphLive(nodes, graphTagRef.current);
103
+ }, [selectMode, nodes]);
104
+ // Reflect the current selection onto the DOM as `data-mv-selected` so the
105
+ // plugin's CSS can render a visible selected state (issue: selection was
106
+ // invisible, so click-to-deselect had no feedback). Keyed off the selection
107
+ // map + selectMode; when select-mode turns off, all marks are removed. Uses
108
+ // data-mv-id to find the elements — the same ids the marquee selection holds.
109
+ useEffect(() => {
110
+ if (typeof document === 'undefined') {
111
+ return undefined;
112
+ }
113
+ const marked = [];
114
+ if (selectMode) {
115
+ // Iterate the tagged-element map the engine already maintains
116
+ // (id -> element, kept live by the MutationObserver) rather than
117
+ // re-scanning the whole document on every selection change — this effect
118
+ // fires per pointer event during a drag, so a full querySelectorAll here
119
+ // is O(DOM) per mousemove.
120
+ for (const [id, el] of graphTagRef.current) {
121
+ const type = el.getAttribute(TYPE_ATTR) ?? '';
122
+ // Selection is keyed by `type::id`; an element only counts as selected
123
+ // when both match (guards against id collisions across node types).
124
+ if (id && marquee.isSelected(type, id)) {
125
+ el.setAttribute(SELECTED_ATTR, '');
126
+ marked.push(el);
127
+ }
128
+ }
129
+ }
130
+ return () => {
131
+ for (const el of marked) {
132
+ el.removeAttribute(SELECTED_ATTR);
133
+ }
134
+ };
135
+ }, [selectMode, marquee.selected, nodes]);
136
+ // Reflect the hover affordance onto the DOM as `data-mv-hover` (the dotted
137
+ // outline) so the plugin's CSS renders it. Marks the union of:
138
+ // - the single element under the pointer (`hovered`), and
139
+ // - every element the in-progress marquee covers (`previewed`) — the
140
+ // bulk-selection preview, so the user sees what WILL be selected mid-drag.
141
+ // Keyed by `type::id`; all marks cleared when the set changes, hover leaves,
142
+ // or select-mode turns off. (Single hover and drag preview are mutually
143
+ // exclusive in practice — hover is suppressed during a drag — but marking the
144
+ // union keeps this one effect the sole owner of the hover attribute.)
145
+ useEffect(() => {
146
+ if (typeof document === 'undefined' || !selectMode) {
147
+ return undefined;
148
+ }
149
+ const wanted = new Set();
150
+ if (hovered) {
151
+ wanted.add(`${hovered.type}::${hovered.id}`);
152
+ }
153
+ for (const p of previewed) {
154
+ wanted.add(`${p.type}::${p.id}`);
155
+ }
156
+ if (wanted.size === 0) {
157
+ return undefined;
158
+ }
159
+ // Same optimization as the selection effect: walk the engine's tagged map
160
+ // (id -> element) instead of re-querying the document. This effect fires on
161
+ // every hover/preview change — i.e. per mousemove during a marquee drag.
162
+ const marked = [];
163
+ for (const [id, el] of graphTagRef.current) {
164
+ const type = el.getAttribute(TYPE_ATTR) ?? '';
165
+ if (id && wanted.has(`${type}::${id}`)) {
166
+ el.setAttribute(HOVER_ATTR, '');
167
+ marked.push(el);
168
+ }
169
+ }
170
+ return () => {
171
+ for (const el of marked) {
172
+ el.removeAttribute(HOVER_ATTR);
173
+ }
174
+ };
175
+ }, [selectMode, hovered, previewed, nodes]);
176
+ // Map the raw selection → SpatialContext[] once by a pure Map.get(id) over the
177
+ // nodes; both chips and the handoff derive from it so they never drift.
178
+ const contexts = useMemo(() => buildContextsFromNodes(marquee.items, nodes, fileName), [nodes, marquee.items, fileName]);
179
+ const chips = useMemo(() => contexts.map(chipFor), [contexts, chipFor]);
180
+ const handleSubmit = useCallback((prompt) => {
181
+ const request = {
182
+ prompt: prompt.trim(),
183
+ attachments: contexts,
184
+ };
185
+ const sent = sendToHost({
186
+ type: WebviewMessageType.SUBMIT_EDIT,
187
+ payload: request,
188
+ });
189
+ // Reset locally as soon as the request is handed off — the user gets
190
+ // immediate feedback (overlay + panel disappear, selection cleared) rather
191
+ // than waiting on the host's async edit to complete. Only reset on a
192
+ // successful send so a failed handoff leaves the selection intact to retry.
193
+ if (sent) {
194
+ marquee.clear();
195
+ setSelectMode(false);
196
+ }
197
+ return sent;
198
+ }, [contexts, marquee]);
199
+ // Explicit, gesture-free deselect: remove one selected element by its chip
200
+ // index. chips/contexts are derived from marquee.items in order, so the chip
201
+ // index maps directly to marquee.items[index]. toggle() removes it (it's
202
+ // already selected). This is the reliable deselect path — canvas click-timing
203
+ // competes with double-click-to-drill-in, so the chip ✕ is authoritative.
204
+ const handleRemove = useCallback((index) => {
205
+ const item = marquee.items[index];
206
+ if (item) {
207
+ marquee.toggle(item);
208
+ }
209
+ }, [marquee]);
210
+ // Imperative select/deselect for selectable elements that live OUTSIDE the
211
+ // marquee overlay's reach (e.g. the flow inspector sidebar's detail rows).
212
+ // Routes through the same `marquee.toggle` the overlay's click gesture uses,
213
+ // so canvas and off-canvas picks share one selection set and one handoff.
214
+ // Gated on select-mode so a stray sidebar click while NOT selecting can't
215
+ // silently build a hidden selection.
216
+ const toggle = useCallback((type, id) => {
217
+ if (!selectMode) {
218
+ return;
219
+ }
220
+ marquee.toggle({ type, id });
221
+ }, [selectMode, marquee]);
222
+ const handleToggleSelectMode = useCallback(() => {
223
+ setSelectMode((prev) => {
224
+ const next = !prev;
225
+ // Leaving select-mode clears the selection (matches prior plugin behavior)
226
+ // and drops any lingering hover / marquee preview so no outline persists.
227
+ if (!next) {
228
+ marquee.clear();
229
+ setHovered(null);
230
+ setPreviewed([]);
231
+ }
232
+ return next;
233
+ });
234
+ }, [marquee]);
235
+ // Graceful degradation: when the host forwarded no selectable nodes, vibe-edit
236
+ // is gated off (or unsupported) for this host/file — render NOTHING (no toggle,
237
+ // overlay, or panel) so the visualization is a plain diagram. Placed after all
238
+ // hook calls above to keep hook order stable across renders (rules of hooks);
239
+ // only the returned UI is withheld.
240
+ if (!isVibeEditAvailable(nodes)) {
241
+ return {
242
+ toggleButton: null,
243
+ overlay: null,
244
+ panel: null,
245
+ selectMode: false,
246
+ isSelected: () => false,
247
+ toggle: () => { },
248
+ };
249
+ }
250
+ const toggleButton = (React.createElement("button", { className: `mv-vibe-edit-toggle ${selectMode ? 'mv-vibe-edit-toggle--active' : ''}`, onClick: handleToggleSelectMode, "aria-label": "Select components to edit with AI", title: "Select components to edit with AI", type: "button" },
251
+ React.createElement(ToggleIcon, null),
252
+ React.createElement("span", null, selectMode ? selectingLabel : selectLabel)));
253
+ const overlay = (React.createElement(MarqueeSelection, { active: selectMode, selected: marquee.selected, onReplace: marquee.replace, onAdd: marquee.add, onToggle: marquee.toggle, onClear: marquee.clear, onActivate: onActivate ? (item) => onActivate(item.id) : undefined, onHover: setHovered, onMarqueePreview: setPreviewed }));
254
+ const panel = (React.createElement(VibeEditPanel, { chips: chips, onSubmit: handleSubmit, onClear: marquee.clear, onRemove: handleRemove, placeholder: placeholder }));
255
+ return {
256
+ toggleButton,
257
+ overlay,
258
+ panel,
259
+ selectMode,
260
+ isSelected: marquee.isSelected,
261
+ toggle,
262
+ };
263
+ }
264
+ //# sourceMappingURL=useVibeEdit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVibeEdit.js","sourceRoot":"","sources":["../../../../../src/sdk/hooks/vibe-edit/ui/useVibeEdit.tsx"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,gBAA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G;QACd,kCAAO,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,WAAW,CAAQ,CACjD,CACV,CAAC;IAEF,MAAM,OAAO,GAAG,CACd,oBAAC,gBAAgB,IACf,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAC1B,SAAS,EAAE,OAAO,CAAC,OAAO,EAC1B,KAAK,EAAE,OAAO,CAAC,GAAG,EAClB,QAAQ,EAAE,OAAO,CAAC,MAAM,EACxB,OAAO,EAAE,OAAO,CAAC,KAAK,EACtB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,EAClE,OAAO,EAAE,UAAU,EACnB,gBAAgB,EAAE,YAAY,GAC9B,CACH,CAAC;IAEF,MAAM,KAAK,GAAG,CACZ,oBAAC,aAAa,IACZ,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,OAAO,CAAC,KAAK,EACtB,QAAQ,EAAE,YAAY,EACtB,WAAW,EAAE,WAAW,GACxB,CACH,CAAC;IAEF,OAAO;QACL,YAAY;QACZ,OAAO;QACP,KAAK;QACL,UAAU;QACV,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -8,6 +8,7 @@
8
8
  * Message types for webview <-> extension host communication.
9
9
  * Single source of truth: used by plugin iframes (postMessage), ErrorBuilder, and extension host (message handler).
10
10
  */
11
+ import type { SelectableNode } from './contracts/types/SelectableNode.js';
11
12
  export declare const WebviewMessageType: {
12
13
  /** Plugin reports an error to the extension (payload: PluginError) */
13
14
  readonly PLUGIN_ERROR: "PLUGIN_ERROR";
@@ -23,6 +24,13 @@ export declare const WebviewMessageType: {
23
24
  readonly PLUGIN_DATA_RESPONSE: "PLUGIN_DATA_RESPONSE";
24
25
  /** Host pushes updated plugin data to plugin (payload: PluginDataResponse) */
25
26
  readonly PLUGIN_DATA_UPDATE: "PLUGIN_DATA_UPDATE";
27
+ /**
28
+ * Plugin asks the host to apply a natural-language edit, plus the spatial
29
+ * context of the user's current selection, via the IDE's coding agent
30
+ * (payload: EditRequest). The host owns delivery to whatever agent the
31
+ * platform embeds.
32
+ */
33
+ readonly SUBMIT_EDIT: "SUBMIT_EDIT";
26
34
  };
27
35
  export type WebviewMessageTypeValue = (typeof WebviewMessageType)[keyof typeof WebviewMessageType];
28
36
  /**
@@ -43,6 +51,75 @@ export interface PluginDataResponse<T = unknown> {
43
51
  };
44
52
  /** Unique file ID for tracking file changes */
45
53
  fileId: string;
54
+ /**
55
+ * SelectionGraph (C1): the flat, normalized selectable nodes for this file,
56
+ * emitted by the parser's optional `getSelectableNodes()`. Optional — absent
57
+ * for plugins that don't opt into the SelectionGraph path. Uses the canonical
58
+ * `SelectableNode` (now in `contracts/types/`, the lowest SDK layer) so this
59
+ * message contract can't drift from the parser's return type. The old inline
60
+ * structural duplicate existed only to avoid a hooks-layer import, which the
61
+ * contracts-layer home removes.
62
+ */
63
+ selectableNodes?: SelectableNode[];
64
+ }
65
+ /**
66
+ * Spatial / semantic context for a single selected visualization element.
67
+ *
68
+ * This is the "what and where" the coding agent needs to locate the element
69
+ * in the underlying metadata. The POC populates semantic identity only
70
+ * (`elementType`, `apiName`, `parent`, `attributes`, `fileName`); the agent
71
+ * finds the element by name in the metadata. `sourceLocation` is intentionally
72
+ * optional so parsers can later emit precise line/xpath ranges without a
73
+ * contract change.
74
+ *
75
+ * Note: `filePath` is optional because not all host environments (e.g., web-based
76
+ * IDEs like CodysStudio) may have access to file system paths. `fileName` should
77
+ * always be available as it comes from the plugin data context.
78
+ */
79
+ export interface SpatialContext {
80
+ /** Kind of element, e.g. 'object' | 'field' | 'region'. Plugin-defined. */
81
+ elementType: string;
82
+ /** API name / stable identifier of the element (e.g. 'Account', 'Industry__c'). */
83
+ apiName: string;
84
+ /** API name of the containing element, if any (e.g. the parent object of a field). */
85
+ parent?: string;
86
+ /** Salient attributes worth surfacing to the agent (type, label, etc.). */
87
+ attributes?: Record<string, unknown>;
88
+ /** Name of the metadata file this element lives in (e.g., 'Account.object-meta.xml'). Always available. */
89
+ fileName?: string;
90
+ /** Optional full path of the metadata file (may not be available in all host environments). */
91
+ filePath?: string;
92
+ /** Optional precise source location. Not populated by the POC. */
93
+ sourceLocation?: {
94
+ lineStart: number;
95
+ lineEnd: number;
96
+ xpath?: string;
97
+ };
98
+ }
99
+ /**
100
+ * Payload for SUBMIT_EDIT: the user's instruction plus one SpatialContext per
101
+ * selected element. The host assembles this into an agent prompt.
102
+ */
103
+ export interface EditRequest {
104
+ /** The user's natural-language instruction. */
105
+ prompt: string;
106
+ /** Spatial context for each selected element (one entry per element). */
107
+ attachments: SpatialContext[];
108
+ }
109
+ /**
110
+ * Result of a host's attempt to deliver an EditRequest to the embedded agent.
111
+ *
112
+ * `channel` records which delivery mechanism actually fired (see the fallback
113
+ * chain in the design doc): the Agentforce Vibes inject command, the standard
114
+ * chat command, or the universal clipboard floor.
115
+ */
116
+ export interface EditHandoffResult {
117
+ /** Whether the request was delivered to (or staged for) the agent. */
118
+ delivered: boolean;
119
+ /** Which delivery channel was used. */
120
+ channel: 'vibes.inject' | 'chat.open' | 'clipboard' | 'none';
121
+ /** Optional human-readable detail (e.g. why a channel was skipped). */
122
+ detail?: string;
46
123
  }
47
124
  /** Set of all valid message types for whitelist validation */
48
125
  export declare const VALID_MESSAGE_TYPES: Set<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"webviewMessageTypes.d.ts","sourceRoot":"","sources":["../../src/sdk/webviewMessageTypes.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;GAGG;AACH,eAAO,MAAM,kBAAkB;IAC7B,sEAAsE;;IAEtE,sCAAsC;;IAEtC,oCAAoC;;IAEpC,0BAA0B;;IAG1B,4CAA4C;;IAG5C,qEAAqE;;IAGrE,8EAA8E;;CAE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,10 +4,6 @@
4
4
  * Licensed under the BSD 3-Clause license.
5
5
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
6
  **/
7
- /**
8
- * Message types for webview <-> extension host communication.
9
- * Single source of truth: used by plugin iframes (postMessage), ErrorBuilder, and extension host (message handler).
10
- */
11
7
  export const WebviewMessageType = {
12
8
  /** Plugin reports an error to the extension (payload: PluginError) */
13
9
  PLUGIN_ERROR: 'PLUGIN_ERROR',
@@ -23,6 +19,13 @@ export const WebviewMessageType = {
23
19
  PLUGIN_DATA_RESPONSE: 'PLUGIN_DATA_RESPONSE',
24
20
  /** Host pushes updated plugin data to plugin (payload: PluginDataResponse) */
25
21
  PLUGIN_DATA_UPDATE: 'PLUGIN_DATA_UPDATE',
22
+ /**
23
+ * Plugin asks the host to apply a natural-language edit, plus the spatial
24
+ * context of the user's current selection, via the IDE's coding agent
25
+ * (payload: EditRequest). The host owns delivery to whatever agent the
26
+ * platform embeds.
27
+ */
28
+ SUBMIT_EDIT: 'SUBMIT_EDIT',
26
29
  };
27
30
  /** Set of all valid message types for whitelist validation */
28
31
  export const VALID_MESSAGE_TYPES = new Set(Object.values(WebviewMessageType));
@@ -1 +1 @@
1
- {"version":3,"file":"webviewMessageTypes.js","sourceRoot":"","sources":["../../src/sdk/webviewMessageTypes.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,sEAAsE;IACtE,YAAY,EAAE,cAAc;IAC5B,sCAAsC;IACtC,mBAAmB,EAAE,qBAAqB;IAC1C,oCAAoC;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,0BAA0B;IAC1B,aAAa,EAAE,cAAc;IAE7B,4CAA4C;IAC5C,mBAAmB,EAAE,qBAAqB;IAE1C,qEAAqE;IACrE,oBAAoB,EAAE,sBAAsB;IAE5C,8EAA8E;IAC9E,kBAAkB,EAAE,oBAAoB;CAChC,CAAC;AAwBX,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"webviewMessageTypes.js","sourceRoot":"","sources":["../../src/sdk/webviewMessageTypes.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAQJ,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,sEAAsE;IACtE,YAAY,EAAE,cAAc;IAC5B,sCAAsC;IACtC,mBAAmB,EAAE,qBAAqB;IAC1C,oCAAoC;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,0BAA0B;IAC1B,aAAa,EAAE,cAAc;IAE7B,4CAA4C;IAC5C,mBAAmB,EAAE,qBAAqB;IAE1C,qEAAqE;IACrE,oBAAoB,EAAE,sBAAsB;IAE5C,8EAA8E;IAC9E,kBAAkB,EAAE,oBAAoB;IAExC;;;;;OAKG;IACH,WAAW,EAAE,aAAa;CAClB,CAAC;AAgGX,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC"}