@contentstack/studio-client 3.2.0 → 4.1.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 (97) hide show
  1. package/dist/breakpoints/BreakpointManager.js +7 -5
  2. package/dist/breakpoints/BreakpointManager.js.map +1 -1
  3. package/dist/breakpoints/breakpoint.js +3 -2
  4. package/dist/breakpoints/breakpoint.js.map +1 -1
  5. package/dist/canvas/canvas.utils.js +64 -9
  6. package/dist/canvas/canvas.utils.js.map +1 -1
  7. package/dist/composable-studio/build-scoped-data.js +12 -35
  8. package/dist/composable-studio/build-scoped-data.js.map +1 -1
  9. package/dist/composable-studio/sdk.js +1064 -430
  10. package/dist/composable-studio/sdk.js.map +1 -1
  11. package/dist/composable-studio/studio-intelligence.manager.js +5 -2
  12. package/dist/composable-studio/studio-intelligence.manager.js.map +1 -1
  13. package/dist/composable-studio/weak-maps.js +3 -1
  14. package/dist/composable-studio/weak-maps.js.map +1 -1
  15. package/dist/config/config.schema.js +45 -8
  16. package/dist/config/config.schema.js.map +1 -1
  17. package/dist/config/default-config.js +10 -3
  18. package/dist/config/default-config.js.map +1 -1
  19. package/dist/config/process-user-config.js +37 -1
  20. package/dist/config/process-user-config.js.map +1 -1
  21. package/dist/config/stack-sdk-wrapper.js +36 -1
  22. package/dist/config/stack-sdk-wrapper.js.map +1 -1
  23. package/dist/context-menu/context-menu.js +5 -2
  24. package/dist/context-menu/context-menu.js.map +1 -1
  25. package/dist/design/handle-active-style-change.js +3 -2
  26. package/dist/design/handle-active-style-change.js.map +1 -1
  27. package/dist/dnd/dnd-event.js +2 -1
  28. package/dist/dnd/dnd-event.js.map +1 -1
  29. package/dist/dnd/dnd-manager.js +31 -1
  30. package/dist/dnd/dnd-manager.js.map +1 -1
  31. package/dist/editor.d.ts +258 -0
  32. package/dist/editor.js +11 -0
  33. package/dist/editor.js.map +1 -0
  34. package/dist/get-active-node-screenshot/get-node-screenshot-event.js +2 -1
  35. package/dist/get-active-node-screenshot/get-node-screenshot-event.js.map +1 -1
  36. package/dist/hidden-element-notification/hidden-element-notification-event.js +2 -1
  37. package/dist/hidden-element-notification/hidden-element-notification-event.js.map +1 -1
  38. package/dist/highlight-node/highlight-node-manager.js +225 -15
  39. package/dist/highlight-node/highlight-node-manager.js.map +1 -1
  40. package/dist/highlight-node/highlight-node.js +52 -10
  41. package/dist/highlight-node/highlight-node.js.map +1 -1
  42. package/dist/highlight-spacing/highlight-spacing-events.js +2 -1
  43. package/dist/highlight-spacing/highlight-spacing-events.js.map +1 -1
  44. package/dist/index.d.ts +1024 -436
  45. package/dist/index.js +13 -14
  46. package/dist/index.js.map +1 -1
  47. package/dist/url-change/url-change.js +4 -3
  48. package/dist/url-change/url-change.js.map +1 -1
  49. package/dist/url-metadata/build-template-query.js +14 -3
  50. package/dist/url-metadata/build-template-query.js.map +1 -1
  51. package/dist/utils/canvas.js +2 -1
  52. package/dist/utils/canvas.js.map +1 -1
  53. package/dist/utils/check-bindings.js +233 -0
  54. package/dist/utils/check-bindings.js.map +1 -0
  55. package/dist/utils/classify-response-error.js +288 -0
  56. package/dist/utils/classify-response-error.js.map +1 -0
  57. package/dist/utils/composable-studio-error.js +36 -20
  58. package/dist/utils/composable-studio-error.js.map +1 -1
  59. package/dist/utils/composition-not-found.js +52 -0
  60. package/dist/utils/composition-not-found.js.map +1 -0
  61. package/dist/utils/constants.js +25 -2
  62. package/dist/utils/constants.js.map +1 -1
  63. package/dist/utils/degraded-finding.js +166 -0
  64. package/dist/utils/degraded-finding.js.map +1 -0
  65. package/dist/utils/editor-mode.js +1 -1
  66. package/dist/utils/http-error.constants.js +12 -46
  67. package/dist/utils/http-error.constants.js.map +1 -1
  68. package/dist/utils/include-path-rules.js +40 -1
  69. package/dist/utils/include-path-rules.js.map +1 -1
  70. package/dist/utils/is-composition-being-edited.js +1 -1
  71. package/dist/utils/is-inside-iframe.js +1 -1
  72. package/dist/utils/is-inside-visual-builder-frame.js +1 -1
  73. package/dist/utils/parse-ui.js +60 -0
  74. package/dist/utils/parse-ui.js.map +1 -0
  75. package/dist/utils/query-param.js +1 -1
  76. package/dist/utils/query-param.js.map +1 -1
  77. package/dist/utils/reference-stub.js +75 -0
  78. package/dist/utils/reference-stub.js.map +1 -0
  79. package/dist/utils/reference_fetcher.js +44 -3
  80. package/dist/utils/reference_fetcher.js.map +1 -1
  81. package/dist/utils/require-stack.js +141 -0
  82. package/dist/utils/require-stack.js.map +1 -0
  83. package/dist/utils/served-by.js +33 -0
  84. package/dist/utils/served-by.js.map +1 -0
  85. package/dist/utils/studio-error-codes.js +253 -0
  86. package/dist/utils/studio-error-codes.js.map +1 -0
  87. package/dist/utils/studio-error.js +122 -0
  88. package/dist/utils/studio-error.js.map +1 -0
  89. package/dist/utils/studio-messaging.js +25 -0
  90. package/dist/utils/studio-messaging.js.map +1 -0
  91. package/dist/visual-builder/composition-save-event.js +2 -1
  92. package/dist/visual-builder/composition-save-event.js.map +1 -1
  93. package/package.json +19 -6
  94. package/dist/utils/error-messages.default.js +0 -141
  95. package/dist/utils/error-messages.default.js.map +0 -1
  96. package/dist/utils/error-messages.js +0 -47
  97. package/dist/utils/error-messages.js.map +0 -1
@@ -0,0 +1,258 @@
1
+ import { Path } from '@contentstack/studio-internal';
2
+ import { RevealResultPayload } from '@contentstack/studio-message-types/latest';
3
+ export { BaseHighlightEventPayload, ChangeActiveStyleGroupPayload, ComputedStyleSection, DraggerPosition, HighlightActiveNodeEventPayload, HighlightAncestorsEventPayload, HighlightFocusedNodeEventPayload, HighlightNodeEventPayload, HighlightSlotNodeEventPayload, HighlightStyleNodeEventPayload, HitboxDetails, MouseMoveEventPayload, MouseUpEventPayload, PermanentDropZoneDirection, PermanentDropZoneHitboxDetails, RequestHighlightNodeEventPayload, RevealMissKind, RevealNodePayload, RevealResultPayload, SetCursorTypeEventPayload, TARGET_NODE, UpdateStyleEventPayload, handleActiveNodePayload, handleActiveSlotNode, handleFocusedNodePayload } from '@contentstack/studio-message-types/latest';
4
+
5
+ declare const MAX_SCROLL_SPEED = 100;
6
+ declare const SCROLL_INTERVAL = 50;
7
+ declare const EDGE_PADDING = 50;
8
+ interface MousePosition {
9
+ clientX: number;
10
+ clientY: number;
11
+ }
12
+ declare class DNDManager {
13
+ started: boolean;
14
+ dragging: boolean;
15
+ scrollContainer: HTMLElement | null;
16
+ scrollInterval: ReturnType<typeof setInterval> | undefined;
17
+ startPosition: MousePosition | null;
18
+ hasMoved: boolean;
19
+ mouseDown: boolean;
20
+ private targetedPermanentDropZone;
21
+ constructor();
22
+ handleMouseDown(_e: MouseEvent): void;
23
+ handleMouseUp(_e: MouseEvent): void;
24
+ /** The mouse button is up, so whatever drag was running is over. */
25
+ private releaseDrag;
26
+ handleMouseLeave(e: MouseEvent): void;
27
+ start(e: MouseEvent): void;
28
+ startParent(): void;
29
+ end(): void;
30
+ mouseMove(e: MouseEvent): void;
31
+ /**
32
+ * Marks the permanent drop zone this drag targets. The zone highlights from
33
+ * the same decision that tells Studio where the drop goes.
34
+ */
35
+ private targetPermanentDropZone;
36
+ get isStarted(): boolean;
37
+ get isDragging(): boolean;
38
+ hasExceededTolerance(start: MousePosition, end: MousePosition): boolean;
39
+ }
40
+ declare const dndManager: DNDManager;
41
+
42
+ declare const dndEventListener: () => {
43
+ removeEventListeners: () => void;
44
+ };
45
+
46
+ declare const getScrollableParent: (el: HTMLElement) => HTMLElement;
47
+ declare const calculateDynamicSpeed: (distance: number, padding: number, maxSpeed: number) => number;
48
+
49
+ declare function handleOnScroll(): void;
50
+ declare function handleResize(): void;
51
+ declare const isModKey: (e: MouseEvent | KeyboardEvent) => boolean;
52
+ declare function addHighlightNodeEventListeners(): {
53
+ removeEventListeners: () => void;
54
+ } | undefined;
55
+
56
+ type OnStyleChangeCallback = (options: {
57
+ activeNodeUID: string;
58
+ element: HTMLElement;
59
+ componentClassName: string;
60
+ }) => void;
61
+ /** `revealNode`'s answer: the reply payload minus the uid the caller already knows. */
62
+ type RevealOutcome = Omit<RevealResultPayload, "requestedUid">;
63
+ /**
64
+ * The smallest rect covering every given rect. Missing rects, and empty ones
65
+ * (an element with `display: none` measures 0 × 0 at the viewport origin),
66
+ * are skipped so they can't stretch the union to the corner.
67
+ */
68
+ declare function unionRects(rects: (DOMRect | null | undefined)[]): DOMRect | null;
69
+ declare class HighlightNodeManager {
70
+ activeNodeUID: string | null;
71
+ focusedNodeUID: string | null;
72
+ activeNodePath: Path | null;
73
+ focusedNodePath: Path | null;
74
+ hoveredNodeUID: string | null;
75
+ /** The slot of the hovered node the pointer is on, if any (slot hover). */
76
+ hoveredSlotUID: string | null;
77
+ /**
78
+ * The element the slot hover came from (an empty slot's placeholder), so a
79
+ * slot inside a Repeater is measured where the pointer is, not at its first
80
+ * rendered copy. Null for a hover requested from a Layers slot row.
81
+ */
82
+ hoveredSlotElement: HTMLElement | null;
83
+ activeSlotUID: string | null;
84
+ styleGroup: string | null;
85
+ onStyleChangeCallbacks: Set<OnStyleChangeCallback>;
86
+ onActiveNodeChangeCallbacks: Set<(uid: string, path: Path) => void>;
87
+ visible: boolean;
88
+ constructor();
89
+ private setActiveNodeUID;
90
+ private setFocusedNodeUID;
91
+ setHoveredNode(uid: string): void;
92
+ setActiveSlotUID(uid: string | null): void;
93
+ resetActiveNode(): void;
94
+ resetFocusedNode(): void;
95
+ /**
96
+ * Subscribe to changes in the active node.
97
+ *
98
+ * @param callback - Function that will be called whenever the active node changes.
99
+ * The callback receives the UID of the newly active node as a parameter.
100
+ * @param options - Configuration options
101
+ * @param options.syncToExistingValue - When true, the callback will be immediately called
102
+ * with the current active node's UID. When false, the callback will only be called on future changes.
103
+ * Defaults to false.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * highlightNodeManager.onActiveNodeChange((uid) => {
108
+ * console.log('Active node changed to:', uid);
109
+ * }, { syncToExistingValue: true });
110
+ * ```
111
+ */
112
+ onActiveNodeChange(callback: (uid: string, path: Path) => void, options: {
113
+ syncToExistingValue: boolean;
114
+ }): void;
115
+ /**
116
+ * Unsubscribe from changes in the active node.
117
+ *
118
+ * @param callback - The callback function to unsubscribe.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * const onHighlight = (uid: string) => {
123
+ * console.log('Active node changed to:', uid);
124
+ * };
125
+ *
126
+ * highlightNodeManager.onActiveNodeChange(onHighlight);
127
+ * highlightNodeManager.unsubscribeFromActiveNodeChange(onHighlight);
128
+ * ```
129
+ */
130
+ unsubscribeFromActiveNodeChange(callback: (uid: string, path: Path) => void): void;
131
+ private notifyActiveNodeChange;
132
+ removeNodeHighligher(): void;
133
+ hideActiveNode(): void;
134
+ setStyleGroup: (styleGroup: string | null) => void;
135
+ subscribeToOnStyleChange: (callback: OnStyleChangeCallback) => void;
136
+ unsubscribeFromOnStyleChange: (callback: OnStyleChangeCallback) => void;
137
+ resetStyleGroup(): void;
138
+ setAndHighlightActiveNode(uid: string): void;
139
+ /**
140
+ * Scroll to the first node in `chain` that renders something measurable, and
141
+ * report what happened for the node that was actually asked for (`chain[0]`).
142
+ *
143
+ * Falling back to an ancestor is what makes a component with no box of its
144
+ * own reachable at all; the editor turns `miss` into the reason.
145
+ */
146
+ revealNode(chain: string[]): RevealOutcome;
147
+ /**
148
+ * Where a node is: the FIRST element it rendered that has a box.
149
+ *
150
+ * A node can reach the DOM many times — once per enclosing Repeater item,
151
+ * all copies under the same uid — and the copies that rendered nothing (a
152
+ * Condition Block whose condition is not met for that item) contribute no
153
+ * box. Reading only the first ELEMENT called the whole node absent whenever
154
+ * copy 0 was one of those; reading the first RENDERED one does not.
155
+ *
156
+ * First, and not the nearest to the viewport, because this single answer
157
+ * serves the outline as well as the scroll. If they disagreed the page would
158
+ * travel to a copy the outline is not drawn around, which is worse than the
159
+ * travel itself. Only one copy can be outlined, so only one can be revealed.
160
+ *
161
+ * The three outcomes are kept apart because the editor tells them apart: a
162
+ * node that rendered with no area is a styling result, one that rendered
163
+ * nothing at all is a different story, and conflating them would report
164
+ * `display: none` and "never rendered" as the same thing.
165
+ */
166
+ private locateNode;
167
+ /**
168
+ * The nearest element at or under `element` that the browser gave a box to.
169
+ *
170
+ * Returns `element` itself unless it is `display: contents`, in which case it
171
+ * has no box of its own and the search continues into what it rendered.
172
+ */
173
+ private firstBoxElement;
174
+ /**
175
+ * Whether the author can already see the whole node.
176
+ *
177
+ * A node taller than the viewport can never be "fully visible", so it is
178
+ * judged by its top edge instead — the top is what identifies a component,
179
+ * and scrolling a tall hero to chase its bottom edge is disorienting.
180
+ */
181
+ private isFullyVisible;
182
+ setAndHighlightFocusedNode(uid: string): void;
183
+ /**
184
+ * Hover the node `uid`, or one slot of it when `slotUid` is given. Moving
185
+ * from a container onto its own empty slot keeps the same node uid, so the
186
+ * slot is part of what counts as a change.
187
+ */
188
+ setAndHighlightHoveredNode(uid: string, slotUid?: string | null, slotElement?: HTMLElement | null): void;
189
+ setAndHighlightStyleNode(styleGroup: string, uid: string): {
190
+ styles: undefined;
191
+ } | {
192
+ styles: Partial<CSSStyleDeclaration>;
193
+ };
194
+ highlightActiveNode(): void;
195
+ highlightFocusedNode(): void;
196
+ highlightNodeOnHover(): void;
197
+ highlightStyleNode(): void;
198
+ sendStylesToClient(): {
199
+ styles: undefined;
200
+ } | {
201
+ styles: Partial<CSSStyleDeclaration>;
202
+ };
203
+ highlightSlotNode(): void;
204
+ private getStylesObject;
205
+ private getHighlightStyleNodePayload;
206
+ /**
207
+ * A slot's box. Only an empty slot renders an element of its own (its "Drop
208
+ * Here" placeholder, tagged with the slot uid). A filled slot renders its
209
+ * children bare, and a filled section slot renders a `display: contents`
210
+ * wrapper with no box — both are measured as the union of their children.
211
+ */
212
+ private getSlotRect;
213
+ /** The hovered slot's box: where the pointer is, else its first copy. */
214
+ private getHoveredSlotRect;
215
+ private measureSlotElement;
216
+ /**
217
+ * The rendered node whose `slots` holds `slotUid`. While a slot is selected
218
+ * Studio also selects its parent, so the active node is checked first and
219
+ * the page is scanned only when it isn't the owner.
220
+ */
221
+ private findSlotOwner;
222
+ getBoundingRectOfDisplayContents(element: HTMLElement): DOMRect | null;
223
+ /**
224
+ * The box to draw an outline around — the same copy `revealNode` scrolls to,
225
+ * resolved through the same lookup so the two can never point at different
226
+ * copies of one node.
227
+ */
228
+ private getNodeRect;
229
+ /**
230
+ * The box one element occupies. Repeater and Condition Block wrappers are
231
+ * `display: contents`, so they have no box of their own and are measured
232
+ * through what they rendered instead.
233
+ */
234
+ private measureElement;
235
+ private getNodePath;
236
+ getAncestorsElements(currEl: HTMLElement): HTMLElement[];
237
+ }
238
+ declare const highlightNodeManager: HighlightNodeManager;
239
+
240
+ declare function addHighlightSpacingEventListeners(): {
241
+ removeEventListeners: () => void;
242
+ } | undefined;
243
+
244
+ declare function openHiddenElementNotification(uid: string): void;
245
+ declare function closeHiddenElementNotification(uid: string): void;
246
+ declare function hiddenElementNotificationEventEmitter(): {
247
+ unregister: () => void;
248
+ } | undefined;
249
+
250
+ declare function getNodeScreenshotEvent(): {
251
+ unregister: () => void;
252
+ } | undefined;
253
+
254
+ declare const compositionSaveEventListener: () => {
255
+ unregister: () => void;
256
+ } | undefined;
257
+
258
+ export { EDGE_PADDING, MAX_SCROLL_SPEED, SCROLL_INTERVAL, addHighlightNodeEventListeners, addHighlightSpacingEventListeners, calculateDynamicSpeed, closeHiddenElementNotification, compositionSaveEventListener, dndEventListener, dndManager, getNodeScreenshotEvent, getScrollableParent, handleOnScroll, handleResize, hiddenElementNotificationEventEmitter, highlightNodeManager, isModKey, openHiddenElementNotification, unionRects };
package/dist/editor.js ADDED
@@ -0,0 +1,11 @@
1
+ export { EDGE_PADDING, MAX_SCROLL_SPEED, SCROLL_INTERVAL, dndManager } from './dnd/dnd-manager.js';
2
+ export { dndEventListener } from './dnd/dnd-event.js';
3
+ export { calculateDynamicSpeed, getScrollableParent } from './dnd/scroll-utils.js';
4
+ export { addHighlightNodeEventListeners, handleOnScroll, handleResize, isModKey } from './highlight-node/highlight-node.js';
5
+ export { highlightNodeManager, unionRects } from './highlight-node/highlight-node-manager.js';
6
+ export { TARGET_NODE } from '@contentstack/studio-message-types/latest';
7
+ export { addHighlightSpacingEventListeners } from './highlight-spacing/highlight-spacing-events.js';
8
+ export { closeHiddenElementNotification, hiddenElementNotificationEventEmitter, openHiddenElementNotification } from './hidden-element-notification/hidden-element-notification-event.js';
9
+ export { getNodeScreenshotEvent } from './get-active-node-screenshot/get-node-screenshot-event.js';
10
+ export { compositionSaveEventListener } from './visual-builder/composition-save-event.js';
11
+ //# sourceMappingURL=editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -1,4 +1,5 @@
1
- import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
1
+ import { POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
2
+ import { composableStudioEventManager } from '@contentstack/studio-messenger';
2
3
  import { getComposableElement, toggleNodeVisible } from '../canvas/canvas.utils.js';
3
4
 
4
5
  function getNodeScreenshotEvent() {
@@ -1 +1 @@
1
- {"version":3,"file":"get-node-screenshot-event.js","sources":["../../src/get-active-node-screenshot/get-node-screenshot-event.ts"],"sourcesContent":[null],"names":[],"mappings":";;;SAWgB,sBAAsB,GAAA;AACpC,IAAA,OAAO,4BAA4B,EAAE,EAAE,CAGrC,mBAAmB,CAAC,mBAAmB,EAAE,OAAO,KAAK,KAAI;AACzD,QAAA,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG;AAC9B,QAAA,MAAM,IAAI,GAAG,oBAAoB,CAAC,OAAO,CAAC;AAC1C,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;QAC7B,IAAI,CAAC,IAAI,EAAE;YACT,OAAO;AACL,gBAAA,UAAU,EAAE,EAAE;aACf;QACH;;;;;;;;;;QAUA,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,mBAAmB,CAAC;AACzD,QAAA,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAmB,EAA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A;AAClC,IAAA,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,aAAa;AAAE,QAAA,OAAO,KAAK;IACnD,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,sBAAsB,CAAC;AACpD,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,IAAI;AAC1B,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;AAC1D,IAAA,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AAC5D;;;;"}
@@ -1,4 +1,5 @@
1
- import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
1
+ import { POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
2
+ import { composableStudioEventManager } from '@contentstack/studio-messenger';
2
3
  import { COMPOSABLE_STUDIO_EMITTED_EVENTS } from '../emitted-events/events.constant.js';
3
4
  import { composableStudioEventEmitter } from '../emitted-events/event-emitter.js';
4
5
  import { isInsideIframe } from '../utils/is-inside-iframe.js';
@@ -1 +1 @@
1
- {"version":3,"file":"hidden-element-notification-event.js","sources":["../../src/hidden-element-notification/hidden-element-notification-event.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AASM,SAAU,6BAA6B,CAAC,GAAW,EAAA;;IAEvD,IAAI,CAAC,cAAc,EAAE;QAAE;AAEvB,IAAA,MAAM,OAAO,GAAuC;AAClD,QAAA,MAAM,EAAE,MAAM;QACd,GAAG;KACJ;IACD,4BAA4B,EAAE,IAAI,CAChC,mBAAmB,CAAC,6BAA6B,EACjD,OAAO,CACR;AACH;AAEM,SAAU,8BAA8B,CAAC,GAAW,EAAA;;IAExD,IAAI,CAAC,cAAc,EAAE;QAAE;AAEvB,IAAA,MAAM,OAAO,GAAuC;AAClD,QAAA,MAAM,EAAE,OAAO;QACf,GAAG;KACJ;IACD,4BAA4B,EAAE,IAAI,CAChC,mBAAmB,CAAC,6BAA6B,EACjD,OAAO,CACR;AACH;SAEgB,qCAAqC,GAAA;IACnD,OAAO,4BAA4B,EAAE,EAAE,CACrC,mBAAmB,CAAC,6BAA6B,EACjD,CAAC,KAAK,KAAI;QACR,4BAA4B,CAAC,IAAI,CAC/B,gCAAgC,CAAC,2BAA2B,EAC5D,KAAK,CAAC,IAAI,CACX;AACH,IAAA,CAAC,CACF;AACH;;;;"}
1
+ {"version":3,"file":"hidden-element-notification-event.js","sources":["../../src/hidden-element-notification/hidden-element-notification-event.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAOM,SAAU,6BAA6B,CAAC,GAAW,EAAA;;IAEvD,IAAI,CAAC,cAAc,EAAE;QAAE;AAEvB,IAAA,MAAM,OAAO,GAAuC;AAClD,QAAA,MAAM,EAAE,MAAM;QACd,GAAG;KACJ;IACD,4BAA4B,EAAE,IAAI,CAChC,mBAAmB,CAAC,6BAA6B,EACjD,OAAO,CACR;AACH;AAEM,SAAU,8BAA8B,CAAC,GAAW,EAAA;;IAExD,IAAI,CAAC,cAAc,EAAE;QAAE;AAEvB,IAAA,MAAM,OAAO,GAAuC;AAClD,QAAA,MAAM,EAAE,OAAO;QACf,GAAG;KACJ;IACD,4BAA4B,EAAE,IAAI,CAChC,mBAAmB,CAAC,6BAA6B,EACjD,OAAO,CACR;AACH;SAEgB,qCAAqC,GAAA;IACnD,OAAO,4BAA4B,EAAE,EAAE,CACrC,mBAAmB,CAAC,6BAA6B,EACjD,CAAC,KAAK,KAAI;QACR,4BAA4B,CAAC,IAAI,CAC/B,gCAAgC,CAAC,2BAA2B,EAC5D,KAAK,CAAC,IAAI,CACX;AACH,IAAA,CAAC,CACF;AACH;;;;"}
@@ -1,22 +1,52 @@
1
- import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
1
+ import { POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
2
+ import { composableStudioEventManager } from '@contentstack/studio-messenger';
2
3
  import { COMPOSABLE_DATA_ATTRIBUTES } from '../utils/constants.js';
3
- import { getComposableElement } from '../canvas/canvas.utils.js';
4
+ import { getComposableElements, getComposableElement } from '../canvas/canvas.utils.js';
4
5
  import { ELEMENT_TO_NODE } from '../composable-studio/weak-maps.js';
5
6
  import { createClassNameUid } from '../design/create-class-name-uid.js';
6
7
  import { findPath } from '../utils/editor-utils.js';
7
8
  import '@contentstack/studio-registry';
8
9
  import '../utils/editor-mode.js';
10
+ import '../utils/studio-error-codes.js';
11
+ import '../utils/composition-not-found.js';
9
12
  import '../utils/conditionBlock.js';
10
13
  import { serializeComputedStyles } from '../utils/canvas.js';
11
14
  import { dndEventManager } from '../shared/dnd-events.js';
12
15
  import { TARGET_NODE } from '@contentstack/studio-message-types/latest';
13
16
 
17
+ /**
18
+ * The smallest rect covering every given rect. Missing rects, and empty ones
19
+ * (an element with `display: none` measures 0 × 0 at the viewport origin),
20
+ * are skipped so they can't stretch the union to the corner.
21
+ */
22
+ function unionRects(rects) {
23
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
24
+ for (const rect of rects) {
25
+ if (!rect || (rect.width === 0 && rect.height === 0))
26
+ continue;
27
+ minX = Math.min(minX, rect.left);
28
+ minY = Math.min(minY, rect.top);
29
+ maxX = Math.max(maxX, rect.right);
30
+ maxY = Math.max(maxY, rect.bottom);
31
+ }
32
+ if (minX === Infinity)
33
+ return null;
34
+ return new DOMRect(minX, minY, maxX - minX, maxY - minY);
35
+ }
14
36
  class HighlightNodeManager {
15
37
  activeNodeUID = null;
16
38
  focusedNodeUID = null;
17
39
  activeNodePath = null;
18
40
  focusedNodePath = null;
19
41
  hoveredNodeUID = null;
42
+ /** The slot of the hovered node the pointer is on, if any (slot hover). */
43
+ hoveredSlotUID = null;
44
+ /**
45
+ * The element the slot hover came from (an empty slot's placeholder), so a
46
+ * slot inside a Repeater is measured where the pointer is, not at its first
47
+ * rendered copy. Null for a hover requested from a Layers slot row.
48
+ */
49
+ hoveredSlotElement = null;
20
50
  activeSlotUID = null;
21
51
  styleGroup = null;
22
52
  onStyleChangeCallbacks = new Set();
@@ -126,14 +156,119 @@ class HighlightNodeManager {
126
156
  this.notifyActiveNodeChange();
127
157
  }
128
158
  }
159
+ /**
160
+ * Scroll to the first node in `chain` that renders something measurable, and
161
+ * report what happened for the node that was actually asked for (`chain[0]`).
162
+ *
163
+ * Falling back to an ancestor is what makes a component with no box of its
164
+ * own reachable at all; the editor turns `miss` into the reason.
165
+ */
166
+ revealNode(chain) {
167
+ let miss = "no-element";
168
+ for (const uid of chain) {
169
+ const found = this.locateNode(uid);
170
+ if (found.kind !== "rendered") {
171
+ if (uid === chain[0] && found.kind === "zero-area")
172
+ miss = "zero-area";
173
+ continue;
174
+ }
175
+ if (!this.isFullyVisible(found.rect)) {
176
+ found.element.scrollIntoView({ behavior: "smooth", block: "nearest" });
177
+ }
178
+ return { revealedUid: uid, miss: uid === chain[0] ? null : miss };
179
+ }
180
+ return { revealedUid: null, miss };
181
+ }
182
+ /**
183
+ * Where a node is: the FIRST element it rendered that has a box.
184
+ *
185
+ * A node can reach the DOM many times — once per enclosing Repeater item,
186
+ * all copies under the same uid — and the copies that rendered nothing (a
187
+ * Condition Block whose condition is not met for that item) contribute no
188
+ * box. Reading only the first ELEMENT called the whole node absent whenever
189
+ * copy 0 was one of those; reading the first RENDERED one does not.
190
+ *
191
+ * First, and not the nearest to the viewport, because this single answer
192
+ * serves the outline as well as the scroll. If they disagreed the page would
193
+ * travel to a copy the outline is not drawn around, which is worse than the
194
+ * travel itself. Only one copy can be outlined, so only one can be revealed.
195
+ *
196
+ * The three outcomes are kept apart because the editor tells them apart: a
197
+ * node that rendered with no area is a styling result, one that rendered
198
+ * nothing at all is a different story, and conflating them would report
199
+ * `display: none` and "never rendered" as the same thing.
200
+ */
201
+ locateNode(nodeUid) {
202
+ let sawZeroArea = false;
203
+ for (const element of getComposableElements(nodeUid)) {
204
+ const rect = this.measureElement(element);
205
+ if (!rect)
206
+ continue;
207
+ // `display: none` yields a 0x0 rect at the origin, not null — scrolling
208
+ // to it would jump to the top of the page and outline nothing.
209
+ if (rect.width === 0 && rect.height === 0) {
210
+ sawZeroArea = true;
211
+ continue;
212
+ }
213
+ // The rect can come from the descendants, but the SCROLL cannot: calling
214
+ // `scrollIntoView` on a `display: contents` wrapper does nothing at all,
215
+ // because the browser has no box to bring into view. The reveal then
216
+ // reported success while the page never moved — which is what "clicking
217
+ // a Condition Block in Layers does nothing" turned out to be.
218
+ const scrollTarget = this.firstBoxElement(element);
219
+ if (!scrollTarget)
220
+ continue;
221
+ return { kind: "rendered", element: scrollTarget, rect };
222
+ }
223
+ return { kind: sawZeroArea ? "zero-area" : "absent" };
224
+ }
225
+ /**
226
+ * The nearest element at or under `element` that the browser gave a box to.
227
+ *
228
+ * Returns `element` itself unless it is `display: contents`, in which case it
229
+ * has no box of its own and the search continues into what it rendered.
230
+ */
231
+ firstBoxElement(element) {
232
+ if (window.getComputedStyle(element).display !== "contents")
233
+ return element;
234
+ for (const child of Array.from(element.children)) {
235
+ const candidate = this.firstBoxElement(child);
236
+ if (!candidate)
237
+ continue;
238
+ const rect = candidate.getBoundingClientRect();
239
+ if (rect.width !== 0 || rect.height !== 0)
240
+ return candidate;
241
+ }
242
+ return null;
243
+ }
244
+ /**
245
+ * Whether the author can already see the whole node.
246
+ *
247
+ * A node taller than the viewport can never be "fully visible", so it is
248
+ * judged by its top edge instead — the top is what identifies a component,
249
+ * and scrolling a tall hero to chase its bottom edge is disorienting.
250
+ */
251
+ isFullyVisible(rect) {
252
+ const viewport = window.innerHeight;
253
+ if (rect.height > viewport)
254
+ return rect.top <= 0 && rect.top + rect.height > 0;
255
+ return rect.top >= 0 && rect.top + rect.height <= viewport;
256
+ }
129
257
  setAndHighlightFocusedNode(uid) {
130
258
  this.setFocusedNodeUID(uid);
131
259
  this.highlightFocusedNode();
132
260
  }
133
- setAndHighlightHoveredNode(uid) {
134
- if (uid === this.hoveredNodeUID)
261
+ /**
262
+ * Hover the node `uid`, or one slot of it when `slotUid` is given. Moving
263
+ * from a container onto its own empty slot keeps the same node uid, so the
264
+ * slot is part of what counts as a change.
265
+ */
266
+ setAndHighlightHoveredNode(uid, slotUid = null, slotElement = null) {
267
+ if (uid === this.hoveredNodeUID && slotUid === this.hoveredSlotUID)
135
268
  return;
136
269
  this.setHoveredNode(uid);
270
+ this.hoveredSlotUID = slotUid;
271
+ this.hoveredSlotElement = slotUid ? slotElement : null;
137
272
  this.highlightNodeOnHover();
138
273
  }
139
274
  setAndHighlightStyleNode(styleGroup, uid) {
@@ -173,6 +308,9 @@ class HighlightNodeManager {
173
308
  const path = this.getNodePath(this.hoveredNodeUID);
174
309
  if (!nodeRect)
175
310
  return;
311
+ // A slot that can't be measured is reported as a plain node hover, so
312
+ // Studio outlines the node rather than nothing.
313
+ const slotRect = this.hoveredSlotUID ? this.getHoveredSlotRect() : null;
176
314
  // const ancestorsElements = this.getAncestorsElements(this.hoveredNode);
177
315
  const payload = {
178
316
  target: TARGET_NODE.HOVERED_NODE,
@@ -180,6 +318,9 @@ class HighlightNodeManager {
180
318
  hoveredNodeRect: nodeRect,
181
319
  hoveredNodeAncestorsRect: [],
182
320
  // hoveredNodeAncestorsRect: ancestorsElements.map((ancestor) => ancestor.getBoundingClientRect()),
321
+ ...(slotRect && this.hoveredSlotUID
322
+ ? { slotUid: this.hoveredSlotUID, hoveredSlotRect: slotRect }
323
+ : {}),
183
324
  };
184
325
  composableStudioEventManager?.send(POST_MESSAGE_EVENTS.HIGHLIGHT_NODE, payload);
185
326
  }
@@ -201,11 +342,11 @@ class HighlightNodeManager {
201
342
  highlightSlotNode() {
202
343
  if (!this.activeSlotUID)
203
344
  return;
204
- const slotNode = document.querySelector(`[${COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID}="${this.activeSlotUID}"]`);
205
- if (!slotNode)
345
+ const slotNodeRect = this.getSlotRect(this.activeSlotUID);
346
+ if (!slotNodeRect)
206
347
  return;
207
348
  const payload = {
208
- slotNodeRect: slotNode.getBoundingClientRect(),
349
+ slotNodeRect,
209
350
  slotUID: this.activeSlotUID,
210
351
  };
211
352
  composableStudioEventManager?.send(POST_MESSAGE_EVENTS.HIGHLIGHT_SLOT_NODE, payload);
@@ -249,6 +390,56 @@ class HighlightNodeManager {
249
390
  styles: stylesObject,
250
391
  };
251
392
  }
393
+ /**
394
+ * A slot's box. Only an empty slot renders an element of its own (its "Drop
395
+ * Here" placeholder, tagged with the slot uid). A filled slot renders its
396
+ * children bare, and a filled section slot renders a `display: contents`
397
+ * wrapper with no box — both are measured as the union of their children.
398
+ */
399
+ getSlotRect(slotUid) {
400
+ const slotElement = document.querySelector(`[${COMPOSABLE_DATA_ATTRIBUTES.SLOT_UID}="${slotUid}"]`);
401
+ if (slotElement)
402
+ return this.measureSlotElement(slotElement);
403
+ const owner = this.findSlotOwner(slotUid);
404
+ const children = owner?.slots?.[slotUid] ?? [];
405
+ return unionRects(children
406
+ // Hidden children are never rendered, so they have no box to add.
407
+ .filter((child) => child.metadata?.visible !== false)
408
+ .map((child) => this.getNodeRect(child.uid)));
409
+ }
410
+ /** The hovered slot's box: where the pointer is, else its first copy. */
411
+ getHoveredSlotRect() {
412
+ if (this.hoveredSlotElement?.isConnected) {
413
+ return this.measureSlotElement(this.hoveredSlotElement);
414
+ }
415
+ return this.hoveredSlotUID ? this.getSlotRect(this.hoveredSlotUID) : null;
416
+ }
417
+ measureSlotElement(element) {
418
+ return window.getComputedStyle(element).display === "contents"
419
+ ? this.getBoundingRectOfDisplayContents(element)
420
+ : element.getBoundingClientRect();
421
+ }
422
+ /**
423
+ * The rendered node whose `slots` holds `slotUid`. While a slot is selected
424
+ * Studio also selects its parent, so the active node is checked first and
425
+ * the page is scanned only when it isn't the owner.
426
+ */
427
+ findSlotOwner(slotUid) {
428
+ const ownsSlot = (node) => Boolean(node?.slots?.[slotUid]);
429
+ if (this.activeNodeUID) {
430
+ const element = getComposableElement(this.activeNodeUID);
431
+ const activeNode = element ? ELEMENT_TO_NODE.get(element) : undefined;
432
+ if (ownsSlot(activeNode))
433
+ return activeNode;
434
+ }
435
+ const elements = document.querySelectorAll(`[${COMPOSABLE_DATA_ATTRIBUTES.NODE}]`);
436
+ for (const element of Array.from(elements)) {
437
+ const node = ELEMENT_TO_NODE.get(element);
438
+ if (ownsSlot(node))
439
+ return node;
440
+ }
441
+ return null;
442
+ }
252
443
  // This returns the bounding rect of the elements with display: contents
253
444
  getBoundingRectOfDisplayContents(element) {
254
445
  const children = Array.from(element.children);
@@ -275,15 +466,34 @@ class HighlightNodeManager {
275
466
  return null;
276
467
  return new DOMRect(minX, minY, maxX - minX, maxY - minY);
277
468
  }
469
+ /**
470
+ * The box to draw an outline around — the same copy `revealNode` scrolls to,
471
+ * resolved through the same lookup so the two can never point at different
472
+ * copies of one node.
473
+ */
278
474
  getNodeRect(nodeUid) {
279
- const element = getComposableElement(nodeUid);
280
- if (!element)
281
- return null;
282
- const node = ELEMENT_TO_NODE.get(element);
283
- if (node?.type !== "repeater" && node?.type !== "condition-block") {
284
- return element.getBoundingClientRect();
475
+ const found = this.locateNode(nodeUid);
476
+ return found.kind === "rendered" ? found.rect : null;
477
+ }
478
+ /**
479
+ * The box one element occupies. Repeater and Condition Block wrappers are
480
+ * `display: contents`, so they have no box of their own and are measured
481
+ * through what they rendered instead.
482
+ */
483
+ measureElement(element) {
484
+ // A `display: contents` element has no box of its own — the browser reports
485
+ // 0x0 at the origin — so it is measured through what it rendered instead.
486
+ //
487
+ // The question asked is the computed style, not the node's type. Type came
488
+ // from a WeakMap keyed on the element, so a miss there fell through to
489
+ // `getBoundingClientRect()` and produced a 0x0 rect indistinguishable from
490
+ // `display: none` — a node that rendered perfectly, reported as rendering
491
+ // nothing. The style is the fact itself, and it covers every wrapper that
492
+ // is `display: contents`, not only Repeater and Condition Block.
493
+ if (window.getComputedStyle(element).display === "contents") {
494
+ return this.getBoundingRectOfDisplayContents(element);
285
495
  }
286
- return this.getBoundingRectOfDisplayContents(element);
496
+ return element.getBoundingClientRect();
287
497
  }
288
498
  getNodePath(nodeUid) {
289
499
  const element = getComposableElement(nodeUid);
@@ -307,5 +517,5 @@ class HighlightNodeManager {
307
517
  }
308
518
  const highlightNodeManager = /* #__PURE__ */ new HighlightNodeManager();
309
519
 
310
- export { highlightNodeManager };
520
+ export { highlightNodeManager, unionRects };
311
521
  //# sourceMappingURL=highlight-node-manager.js.map