@contentstack/live-preview-utils 3.2.5 → 3.3.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 (141) hide show
  1. package/dist/legacy/light-sdk.cjs +1 -1
  2. package/dist/legacy/light-sdk.js +1 -1
  3. package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.cjs +1 -1
  4. package/dist/legacy/livePreview/eventManager/postMessageEvent.hooks.js +1 -1
  5. package/dist/legacy/preview/contentstack-live-preview-HOC.cjs +1 -1
  6. package/dist/legacy/preview/contentstack-live-preview-HOC.js +1 -1
  7. package/dist/legacy/visualBuilder/components/Tooltip.cjs +167 -0
  8. package/dist/legacy/visualBuilder/components/Tooltip.cjs.map +1 -0
  9. package/dist/legacy/visualBuilder/components/Tooltip.d.cts +26 -0
  10. package/dist/legacy/visualBuilder/components/Tooltip.d.ts +26 -0
  11. package/dist/legacy/visualBuilder/components/Tooltip.js +140 -0
  12. package/dist/legacy/visualBuilder/components/Tooltip.js.map +1 -0
  13. package/dist/legacy/visualBuilder/components/fieldLabelWrapper.cjs +115 -15
  14. package/dist/legacy/visualBuilder/components/fieldLabelWrapper.cjs.map +1 -1
  15. package/dist/legacy/visualBuilder/components/fieldLabelWrapper.js +117 -17
  16. package/dist/legacy/visualBuilder/components/fieldLabelWrapper.js.map +1 -1
  17. package/dist/legacy/visualBuilder/components/icons/index.cjs +44 -0
  18. package/dist/legacy/visualBuilder/components/icons/index.cjs.map +1 -1
  19. package/dist/legacy/visualBuilder/components/icons/index.d.cts +3 -1
  20. package/dist/legacy/visualBuilder/components/icons/index.d.ts +3 -1
  21. package/dist/legacy/visualBuilder/components/icons/index.js +32 -0
  22. package/dist/legacy/visualBuilder/components/icons/index.js.map +1 -1
  23. package/dist/legacy/visualBuilder/generators/generateOverlay.cjs +1 -0
  24. package/dist/legacy/visualBuilder/generators/generateOverlay.cjs.map +1 -1
  25. package/dist/legacy/visualBuilder/generators/generateOverlay.js +1 -0
  26. package/dist/legacy/visualBuilder/generators/generateOverlay.js.map +1 -1
  27. package/dist/legacy/visualBuilder/generators/generateToolbar.cjs +43 -10
  28. package/dist/legacy/visualBuilder/generators/generateToolbar.cjs.map +1 -1
  29. package/dist/legacy/visualBuilder/generators/generateToolbar.d.cts +11 -4
  30. package/dist/legacy/visualBuilder/generators/generateToolbar.d.ts +11 -4
  31. package/dist/legacy/visualBuilder/generators/generateToolbar.js +41 -9
  32. package/dist/legacy/visualBuilder/generators/generateToolbar.js.map +1 -1
  33. package/dist/legacy/visualBuilder/index.cjs +6 -2
  34. package/dist/legacy/visualBuilder/index.cjs.map +1 -1
  35. package/dist/legacy/visualBuilder/index.d.cts +2 -0
  36. package/dist/legacy/visualBuilder/index.d.ts +2 -0
  37. package/dist/legacy/visualBuilder/index.js +6 -2
  38. package/dist/legacy/visualBuilder/index.js.map +1 -1
  39. package/dist/legacy/visualBuilder/listeners/index.cjs +3 -1
  40. package/dist/legacy/visualBuilder/listeners/index.cjs.map +1 -1
  41. package/dist/legacy/visualBuilder/listeners/index.js +3 -1
  42. package/dist/legacy/visualBuilder/listeners/index.js.map +1 -1
  43. package/dist/legacy/visualBuilder/listeners/mouseClick.cjs +7 -3
  44. package/dist/legacy/visualBuilder/listeners/mouseClick.cjs.map +1 -1
  45. package/dist/legacy/visualBuilder/listeners/mouseClick.d.cts +4 -1
  46. package/dist/legacy/visualBuilder/listeners/mouseClick.d.ts +4 -1
  47. package/dist/legacy/visualBuilder/listeners/mouseClick.js +5 -2
  48. package/dist/legacy/visualBuilder/listeners/mouseClick.js.map +1 -1
  49. package/dist/legacy/visualBuilder/listeners/mouseHover.cjs +183 -133
  50. package/dist/legacy/visualBuilder/listeners/mouseHover.cjs.map +1 -1
  51. package/dist/legacy/visualBuilder/listeners/mouseHover.d.cts +5 -3
  52. package/dist/legacy/visualBuilder/listeners/mouseHover.d.ts +5 -3
  53. package/dist/legacy/visualBuilder/listeners/mouseHover.js +182 -133
  54. package/dist/legacy/visualBuilder/listeners/mouseHover.js.map +1 -1
  55. package/dist/legacy/visualBuilder/utils/handleIndividualFields.cjs +2 -23
  56. package/dist/legacy/visualBuilder/utils/handleIndividualFields.cjs.map +1 -1
  57. package/dist/legacy/visualBuilder/utils/handleIndividualFields.js +2 -13
  58. package/dist/legacy/visualBuilder/utils/handleIndividualFields.js.map +1 -1
  59. package/dist/legacy/visualBuilder/utils/types/postMessage.types.cjs +2 -0
  60. package/dist/legacy/visualBuilder/utils/types/postMessage.types.cjs.map +1 -1
  61. package/dist/legacy/visualBuilder/utils/types/postMessage.types.d.cts +2 -0
  62. package/dist/legacy/visualBuilder/utils/types/postMessage.types.d.ts +2 -0
  63. package/dist/legacy/visualBuilder/utils/types/postMessage.types.js +2 -0
  64. package/dist/legacy/visualBuilder/utils/types/postMessage.types.js.map +1 -1
  65. package/dist/legacy/visualBuilder/visualBuilder.style.cjs +66 -1
  66. package/dist/legacy/visualBuilder/visualBuilder.style.cjs.map +1 -1
  67. package/dist/legacy/visualBuilder/visualBuilder.style.d.cts +7 -0
  68. package/dist/legacy/visualBuilder/visualBuilder.style.d.ts +7 -0
  69. package/dist/legacy/visualBuilder/visualBuilder.style.js +66 -1
  70. package/dist/legacy/visualBuilder/visualBuilder.style.js.map +1 -1
  71. package/dist/modern/light-sdk.cjs +1 -1
  72. package/dist/modern/light-sdk.js +1 -1
  73. package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.cjs +1 -1
  74. package/dist/modern/livePreview/eventManager/postMessageEvent.hooks.js +1 -1
  75. package/dist/modern/preview/contentstack-live-preview-HOC.cjs +1 -1
  76. package/dist/modern/preview/contentstack-live-preview-HOC.js +1 -1
  77. package/dist/modern/visualBuilder/components/Tooltip.cjs +167 -0
  78. package/dist/modern/visualBuilder/components/Tooltip.cjs.map +1 -0
  79. package/dist/modern/visualBuilder/components/Tooltip.d.cts +26 -0
  80. package/dist/modern/visualBuilder/components/Tooltip.d.ts +26 -0
  81. package/dist/modern/visualBuilder/components/Tooltip.js +140 -0
  82. package/dist/modern/visualBuilder/components/Tooltip.js.map +1 -0
  83. package/dist/modern/visualBuilder/components/fieldLabelWrapper.cjs +113 -15
  84. package/dist/modern/visualBuilder/components/fieldLabelWrapper.cjs.map +1 -1
  85. package/dist/modern/visualBuilder/components/fieldLabelWrapper.js +115 -17
  86. package/dist/modern/visualBuilder/components/fieldLabelWrapper.js.map +1 -1
  87. package/dist/modern/visualBuilder/components/icons/index.cjs +44 -0
  88. package/dist/modern/visualBuilder/components/icons/index.cjs.map +1 -1
  89. package/dist/modern/visualBuilder/components/icons/index.d.cts +3 -1
  90. package/dist/modern/visualBuilder/components/icons/index.d.ts +3 -1
  91. package/dist/modern/visualBuilder/components/icons/index.js +32 -0
  92. package/dist/modern/visualBuilder/components/icons/index.js.map +1 -1
  93. package/dist/modern/visualBuilder/generators/generateOverlay.cjs +1 -0
  94. package/dist/modern/visualBuilder/generators/generateOverlay.cjs.map +1 -1
  95. package/dist/modern/visualBuilder/generators/generateOverlay.js +1 -0
  96. package/dist/modern/visualBuilder/generators/generateOverlay.js.map +1 -1
  97. package/dist/modern/visualBuilder/generators/generateToolbar.cjs +42 -10
  98. package/dist/modern/visualBuilder/generators/generateToolbar.cjs.map +1 -1
  99. package/dist/modern/visualBuilder/generators/generateToolbar.d.cts +11 -4
  100. package/dist/modern/visualBuilder/generators/generateToolbar.d.ts +11 -4
  101. package/dist/modern/visualBuilder/generators/generateToolbar.js +40 -9
  102. package/dist/modern/visualBuilder/generators/generateToolbar.js.map +1 -1
  103. package/dist/modern/visualBuilder/index.cjs +6 -2
  104. package/dist/modern/visualBuilder/index.cjs.map +1 -1
  105. package/dist/modern/visualBuilder/index.d.cts +2 -0
  106. package/dist/modern/visualBuilder/index.d.ts +2 -0
  107. package/dist/modern/visualBuilder/index.js +6 -2
  108. package/dist/modern/visualBuilder/index.js.map +1 -1
  109. package/dist/modern/visualBuilder/listeners/index.cjs +3 -1
  110. package/dist/modern/visualBuilder/listeners/index.cjs.map +1 -1
  111. package/dist/modern/visualBuilder/listeners/index.js +3 -1
  112. package/dist/modern/visualBuilder/listeners/index.js.map +1 -1
  113. package/dist/modern/visualBuilder/listeners/mouseClick.cjs +7 -3
  114. package/dist/modern/visualBuilder/listeners/mouseClick.cjs.map +1 -1
  115. package/dist/modern/visualBuilder/listeners/mouseClick.d.cts +4 -1
  116. package/dist/modern/visualBuilder/listeners/mouseClick.d.ts +4 -1
  117. package/dist/modern/visualBuilder/listeners/mouseClick.js +5 -2
  118. package/dist/modern/visualBuilder/listeners/mouseClick.js.map +1 -1
  119. package/dist/modern/visualBuilder/listeners/mouseHover.cjs +183 -133
  120. package/dist/modern/visualBuilder/listeners/mouseHover.cjs.map +1 -1
  121. package/dist/modern/visualBuilder/listeners/mouseHover.d.cts +5 -3
  122. package/dist/modern/visualBuilder/listeners/mouseHover.d.ts +5 -3
  123. package/dist/modern/visualBuilder/listeners/mouseHover.js +182 -133
  124. package/dist/modern/visualBuilder/listeners/mouseHover.js.map +1 -1
  125. package/dist/modern/visualBuilder/utils/handleIndividualFields.cjs +2 -22
  126. package/dist/modern/visualBuilder/utils/handleIndividualFields.cjs.map +1 -1
  127. package/dist/modern/visualBuilder/utils/handleIndividualFields.js +2 -12
  128. package/dist/modern/visualBuilder/utils/handleIndividualFields.js.map +1 -1
  129. package/dist/modern/visualBuilder/utils/types/postMessage.types.cjs +2 -0
  130. package/dist/modern/visualBuilder/utils/types/postMessage.types.cjs.map +1 -1
  131. package/dist/modern/visualBuilder/utils/types/postMessage.types.d.cts +2 -0
  132. package/dist/modern/visualBuilder/utils/types/postMessage.types.d.ts +2 -0
  133. package/dist/modern/visualBuilder/utils/types/postMessage.types.js +2 -0
  134. package/dist/modern/visualBuilder/utils/types/postMessage.types.js.map +1 -1
  135. package/dist/modern/visualBuilder/visualBuilder.style.cjs +66 -1
  136. package/dist/modern/visualBuilder/visualBuilder.style.cjs.map +1 -1
  137. package/dist/modern/visualBuilder/visualBuilder.style.d.cts +7 -0
  138. package/dist/modern/visualBuilder/visualBuilder.style.d.ts +7 -0
  139. package/dist/modern/visualBuilder/visualBuilder.style.js +66 -1
  140. package/dist/modern/visualBuilder/visualBuilder.style.js.map +1 -1
  141. package/package.json +2 -1
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/visualBuilder/components/Tooltip.tsx
31
+ var Tooltip_exports = {};
32
+ __export(Tooltip_exports, {
33
+ ToolbarTooltip: () => ToolbarTooltip,
34
+ default: () => Tooltip_default
35
+ });
36
+ module.exports = __toCommonJS(Tooltip_exports);
37
+ var import_preact = require("preact");
38
+ var import_hooks = require("preact/hooks");
39
+ var import_dom = require("@floating-ui/dom");
40
+ var import_visualBuilder = require("../visualBuilder.style.cjs");
41
+ var import_classnames = __toESM(require("classnames"), 1);
42
+ var import_icons = require("./icons/index.cjs");
43
+ var import_generateCustomCursor = require("../generators/generateCustomCursor.cjs");
44
+ var import_jsx_runtime = require("preact/jsx-runtime");
45
+ var Tooltip = ({ children, content, placement = "top-start" }) => {
46
+ const [isVisible, setIsVisible] = (0, import_hooks.useState)(false);
47
+ const triggerRef = (0, import_hooks.useRef)(null);
48
+ const tooltipRef = (0, import_hooks.useRef)(null);
49
+ const arrowRef = (0, import_hooks.useRef)(null);
50
+ const showTooltip = () => setIsVisible(true);
51
+ const hideTooltip = () => setIsVisible(false);
52
+ (0, import_hooks.useEffect)(() => {
53
+ if (!isVisible || !triggerRef.current || !tooltipRef.current) {
54
+ return;
55
+ }
56
+ const trigger = triggerRef.current;
57
+ const tooltip = tooltipRef.current;
58
+ (0, import_dom.computePosition)(trigger, tooltip, {
59
+ placement,
60
+ // Middleware runs in order to modify the position
61
+ middleware: [
62
+ (0, import_dom.offset)(8),
63
+ // Add 8px of space between the trigger and tooltip
64
+ (0, import_dom.flip)(),
65
+ // Flip to the opposite side if it overflows
66
+ (0, import_dom.shift)({ padding: 5 }),
67
+ // Shift to keep it in view
68
+ ...arrowRef.current ? [(0, import_dom.arrow)({ element: arrowRef.current })] : []
69
+ // Handle arrow positioning
70
+ ]
71
+ }).then(({ x, y, placement: placement2, middlewareData }) => {
72
+ Object.assign(tooltip.style, {
73
+ left: `${x}px`,
74
+ top: `${y}px`
75
+ });
76
+ if (middlewareData.arrow && arrowRef.current) {
77
+ const { x: arrowX, y: arrowY } = middlewareData.arrow;
78
+ const side = placement2.split("-")[0];
79
+ const staticSide = {
80
+ top: "bottom",
81
+ right: "left",
82
+ bottom: "top",
83
+ left: "right"
84
+ }[side];
85
+ const arrowElement = arrowRef.current;
86
+ Object.assign(arrowElement.style, {
87
+ left: "",
88
+ top: "",
89
+ right: "",
90
+ bottom: ""
91
+ });
92
+ if (placement2.includes("-start") || placement2.includes("-end")) {
93
+ const tooltipRect = tooltip.getBoundingClientRect();
94
+ if (side === "top" || side === "bottom") {
95
+ arrowElement.style.left = `${14}px`;
96
+ if (arrowY != null) {
97
+ arrowElement.style.top = `${arrowY}px`;
98
+ }
99
+ } else {
100
+ arrowElement.style.top = `${tooltipRect.height / 2 - 4}px`;
101
+ if (arrowX != null) {
102
+ arrowElement.style.left = `${arrowX}px`;
103
+ }
104
+ }
105
+ } else {
106
+ if (arrowX != null) {
107
+ arrowElement.style.left = `${arrowX}px`;
108
+ }
109
+ if (arrowY != null) {
110
+ arrowElement.style.top = `${arrowY}px`;
111
+ }
112
+ }
113
+ arrowElement.style[staticSide] = "-4px";
114
+ }
115
+ });
116
+ }, [isVisible, placement, content]);
117
+ const triggerWithListeners = (0, import_preact.cloneElement)(children, {
118
+ ref: triggerRef,
119
+ onMouseEnter: showTooltip,
120
+ onMouseLeave: hideTooltip,
121
+ onFocus: showTooltip,
122
+ onBlur: hideTooltip,
123
+ "aria-describedby": "lightweight-tooltip"
124
+ // for accessibility
125
+ });
126
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
127
+ triggerWithListeners,
128
+ isVisible && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
129
+ "div",
130
+ {
131
+ ref: tooltipRef,
132
+ role: "tooltip",
133
+ id: "lightweight-tooltip",
134
+ className: (0, import_classnames.default)("tooltip-container", (0, import_visualBuilder.visualBuilderStyles)()["tooltip-container"]),
135
+ children: [
136
+ content,
137
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: arrowRef, className: (0, import_classnames.default)("tooltip-arrow", (0, import_visualBuilder.visualBuilderStyles)()["tooltip-arrow"]) })
138
+ ]
139
+ }
140
+ )
141
+ ] });
142
+ };
143
+ function ToolbarTooltipContent({ contentTypeName, referenceFieldName }) {
144
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_classnames.default)("toolbar-tooltip-content", (0, import_visualBuilder.visualBuilderStyles)()["toolbar-tooltip-content"]), children: [
145
+ contentTypeName && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_classnames.default)("toolbar-tooltip-content-item", (0, import_visualBuilder.visualBuilderStyles)()["toolbar-tooltip-content-item"]), children: [
146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ContentTypeIcon, {}),
147
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: contentTypeName })
148
+ ] }),
149
+ referenceFieldName && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_classnames.default)("toolbar-tooltip-content-item", (0, import_visualBuilder.visualBuilderStyles)()["toolbar-tooltip-content-item"]), children: [
150
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { dangerouslySetInnerHTML: { __html: import_generateCustomCursor.FieldTypeIconsMap.reference }, className: (0, import_classnames.default)("visual-builder__field-icon", (0, import_visualBuilder.visualBuilderStyles)()["visual-builder__field-icon"]) }),
151
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: referenceFieldName })
152
+ ] })
153
+ ] });
154
+ }
155
+ function ToolbarTooltip({ children, data, disabled = false }) {
156
+ if (disabled) {
157
+ return children;
158
+ }
159
+ const { contentTypeName, referenceFieldName } = data;
160
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tooltip, { content: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolbarTooltipContent, { contentTypeName, referenceFieldName }), children });
161
+ }
162
+ var Tooltip_default = Tooltip;
163
+ // Annotate the CommonJS export names for ESM import in node:
164
+ 0 && (module.exports = {
165
+ ToolbarTooltip
166
+ });
167
+ //# sourceMappingURL=Tooltip.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/visualBuilder/components/Tooltip.tsx"],"sourcesContent":["import { h, cloneElement } from 'preact';\nimport { useState, useEffect, useRef } from 'preact/hooks';\nimport {\n computePosition,\n flip,\n shift,\n offset,\n arrow\n} from '@floating-ui/dom';\nimport { visualBuilderStyles } from '../visualBuilder.style';\nimport classNames from 'classnames';\nimport { ContentTypeIcon } from './icons';\nimport { FieldTypeIconsMap } from '../generators/generateCustomCursor';\ninterface TooltipProps {\n children: JSX.Element;\n content: JSX.Element;\n placement?: 'top-start' | 'bottom-start' | 'left-start' | 'right-start';\n}\n\n/**\n * A lightweight, reusable tooltip component for Preact powered by Floating UI.\n *\n * @param {object} props - The component props.\n * @param {preact.ComponentChildren} props.children - The single child element that triggers the tooltip.\n * @param {string | preact.VNode} props.content - The content to display inside the tooltip.\n * @param {'top'|'bottom'|'left'|'right'} [props.placement='top'] - The desired placement of the tooltip.\n */\nconst Tooltip = ({ children, content, placement = 'top-start' }: TooltipProps) => {\n const [isVisible, setIsVisible] = useState(false);\n // Create refs for the trigger and the floating tooltip elements\n const triggerRef = useRef(null);\n const tooltipRef = useRef(null);\n const arrowRef = useRef(null);\n\n const showTooltip = () => setIsVisible(true);\n const hideTooltip = () => setIsVisible(false);\n\n // This effect calculates the tooltip's position whenever it becomes visible\n // or if its content or placement changes.\n useEffect(() => {\n if (!isVisible || !triggerRef.current || !tooltipRef.current) {\n return;\n }\n\n const trigger = triggerRef.current as HTMLElement;\n const tooltip = tooltipRef.current as HTMLElement;\n\n computePosition(trigger, tooltip, {\n placement,\n // Middleware runs in order to modify the position\n middleware: [\n offset(8), // Add 8px of space between the trigger and tooltip\n flip(), // Flip to the opposite side if it overflows\n shift({ padding: 5 }), // Shift to keep it in view\n ...(arrowRef.current ? [arrow({ element: arrowRef.current as HTMLElement })] : []), // Handle arrow positioning\n ],\n }).then(({ x, y, placement, middlewareData }) => {\n // Apply the calculated coordinates to the tooltip element\n Object.assign(tooltip.style, {\n left: `${x}px`,\n top: `${y}px`,\n });\n\n // Position the arrow element\n if (middlewareData.arrow && arrowRef.current) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n const side = placement.split('-')[0];\n const staticSide = {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right',\n }[side] as string;\n\n const arrowElement = arrowRef.current as HTMLElement;\n \n // Reset all positioning properties\n Object.assign(arrowElement.style, {\n left: '',\n top: '',\n right: '',\n bottom: '',\n });\n\n // For placements like top-start, bottom-start, etc., we want the arrow \n // to be centered on the tooltip rather than pointing at the trigger center\n if (placement.includes('-start') || placement.includes('-end')) {\n const tooltipRect = tooltip.getBoundingClientRect();\n \n if (side === 'top' || side === 'bottom') {\n // For top/bottom placements, center the arrow horizontally\n arrowElement.style.left = `${14}px`; // 4px = half arrow width\n if (arrowY != null) {\n arrowElement.style.top = `${arrowY}px`;\n }\n } else {\n // For left/right placements, center the arrow vertically\n arrowElement.style.top = `${tooltipRect.height / 2 - 4}px`; // 4px = half arrow height\n if (arrowX != null) {\n arrowElement.style.left = `${arrowX}px`;\n }\n }\n } else {\n // For regular placements (top, bottom, left, right), use floating-ui's positioning\n if (arrowX != null) {\n arrowElement.style.left = `${arrowX}px`;\n }\n if (arrowY != null) {\n arrowElement.style.top = `${arrowY}px`;\n }\n }\n\n // Position arrow to overlap the tooltip's border\n (arrowElement.style as any)[staticSide] = '-4px';\n }\n });\n\n }, [isVisible, placement, content]);\n\n // We need to clone the child element to attach our ref and event listeners.\n // This ensures we don't wrap the child in an extra <div>.\n const triggerWithListeners = cloneElement(children, {\n ref: triggerRef,\n onMouseEnter: showTooltip,\n onMouseLeave: hideTooltip,\n onFocus: showTooltip,\n onBlur: hideTooltip,\n 'aria-describedby': 'lightweight-tooltip' // for accessibility\n });\n\n return (\n <>\n {triggerWithListeners}\n {isVisible && (\n <div\n ref={tooltipRef}\n role=\"tooltip\"\n id=\"lightweight-tooltip\"\n className={classNames(\"tooltip-container\", visualBuilderStyles()[\"tooltip-container\"])}\n >\n {content}\n <div ref={arrowRef} className={classNames(\"tooltip-arrow\", visualBuilderStyles()[\"tooltip-arrow\"])}></div>\n </div>\n )}\n </>\n );\n};\n\nfunction ToolbarTooltipContent({contentTypeName, referenceFieldName}: {contentTypeName: string, referenceFieldName: string}) {\n return (\n <div className={classNames(\"toolbar-tooltip-content\", visualBuilderStyles()[\"toolbar-tooltip-content\"])}>\n {\n contentTypeName && (\n <div className={classNames(\"toolbar-tooltip-content-item\", visualBuilderStyles()[\"toolbar-tooltip-content-item\"])}>\n <ContentTypeIcon />\n <p>{contentTypeName}</p>\n </div>\n )\n }\n {\n referenceFieldName && (\n <div className={classNames(\"toolbar-tooltip-content-item\", visualBuilderStyles()[\"toolbar-tooltip-content-item\"])}>\n <div dangerouslySetInnerHTML={{__html: FieldTypeIconsMap.reference}} className={classNames(\"visual-builder__field-icon\", visualBuilderStyles()[\"visual-builder__field-icon\"])}/>\n <p>{referenceFieldName}</p>\n </div>\n )\n }\n </div>\n )\n}\n\nexport function ToolbarTooltip({children, data, disabled = false}: {children: JSX.Element, data: {contentTypeName: string, referenceFieldName: string}, disabled?: boolean}) {\n if (disabled) {\n return children;\n }\n const { contentTypeName, referenceFieldName } = data;\n return (\n <Tooltip content={<ToolbarTooltipContent contentTypeName={contentTypeName} referenceFieldName={referenceFieldName} />}>\n {children}\n </Tooltip>\n )\n}\n\nexport default Tooltip;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgC;AAChC,mBAA4C;AAC5C,iBAMO;AACP,2BAAoC;AACpC,wBAAuB;AACvB,mBAAgC;AAChC,kCAAkC;AAuH1B;AAxGR,IAAM,UAAU,CAAC,EAAE,UAAU,SAAS,YAAY,YAAY,MAAoB;AAC9E,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAEhD,QAAM,iBAAa,qBAAO,IAAI;AAC9B,QAAM,iBAAa,qBAAO,IAAI;AAC9B,QAAM,eAAW,qBAAO,IAAI;AAE5B,QAAM,cAAc,MAAM,aAAa,IAAI;AAC3C,QAAM,cAAc,MAAM,aAAa,KAAK;AAI5C,8BAAU,MAAM;AACZ,QAAI,C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ACtB;AAAA,IAIF,sBACE,6CAAC,SAAI,eAAW,kBAAAA,SAAW,oCAAgC,0CAAoB,EAAE,8BAA8B,CAAC,GAC9G;AAAA,kDAAC,SAAI,yBAAyB,EAAC,QAAQ,8CAAkB,UAAS,GAAG,eAAW,kBAAAA,SAAW,kCAA8B,0CAAoB,EAAE,4BAA4B,CAAC,GAAE;AAAA,MAC9K,4CAAC,OAAG,8BAAmB;AAAA,OACzB;AAAA,KAGN;AAEJ;AAEO,SAAS,eAAe,EAAC,UAAU,MAAM,WAAW,MAAK,GAA6G;AAC3K,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AACA,QAAM,EAAE,iBAAiB,mBAAmB,IAAI;AAChD,SACE,4CAAC,WAAQ,SAAS,4CAAC,yBAAsB,iBAAkC,oBAAwC,GAChH,UACH;AAEJ;AAEA,IAAO,kBAAQ;","names":["placement","classNames"]}
@@ -0,0 +1,26 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface TooltipProps {
4
+ children: JSX.Element;
5
+ content: JSX.Element;
6
+ placement?: 'top-start' | 'bottom-start' | 'left-start' | 'right-start';
7
+ }
8
+ /**
9
+ * A lightweight, reusable tooltip component for Preact powered by Floating UI.
10
+ *
11
+ * @param {object} props - The component props.
12
+ * @param {preact.ComponentChildren} props.children - The single child element that triggers the tooltip.
13
+ * @param {string | preact.VNode} props.content - The content to display inside the tooltip.
14
+ * @param {'top'|'bottom'|'left'|'right'} [props.placement='top'] - The desired placement of the tooltip.
15
+ */
16
+ declare const Tooltip: ({ children, content, placement }: TooltipProps) => react_jsx_runtime.JSX.Element;
17
+ declare function ToolbarTooltip({ children, data, disabled }: {
18
+ children: JSX.Element;
19
+ data: {
20
+ contentTypeName: string;
21
+ referenceFieldName: string;
22
+ };
23
+ disabled?: boolean;
24
+ }): JSX.Element;
25
+
26
+ export { ToolbarTooltip, Tooltip as default };
@@ -0,0 +1,26 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface TooltipProps {
4
+ children: JSX.Element;
5
+ content: JSX.Element;
6
+ placement?: 'top-start' | 'bottom-start' | 'left-start' | 'right-start';
7
+ }
8
+ /**
9
+ * A lightweight, reusable tooltip component for Preact powered by Floating UI.
10
+ *
11
+ * @param {object} props - The component props.
12
+ * @param {preact.ComponentChildren} props.children - The single child element that triggers the tooltip.
13
+ * @param {string | preact.VNode} props.content - The content to display inside the tooltip.
14
+ * @param {'top'|'bottom'|'left'|'right'} [props.placement='top'] - The desired placement of the tooltip.
15
+ */
16
+ declare const Tooltip: ({ children, content, placement }: TooltipProps) => react_jsx_runtime.JSX.Element;
17
+ declare function ToolbarTooltip({ children, data, disabled }: {
18
+ children: JSX.Element;
19
+ data: {
20
+ contentTypeName: string;
21
+ referenceFieldName: string;
22
+ };
23
+ disabled?: boolean;
24
+ }): JSX.Element;
25
+
26
+ export { ToolbarTooltip, Tooltip as default };
@@ -0,0 +1,140 @@
1
+ import "../../chunk-5WRI5ZAA.js";
2
+
3
+ // src/visualBuilder/components/Tooltip.tsx
4
+ import { cloneElement } from "preact";
5
+ import { useState, useEffect, useRef } from "preact/hooks";
6
+ import {
7
+ computePosition,
8
+ flip,
9
+ shift,
10
+ offset,
11
+ arrow
12
+ } from "@floating-ui/dom";
13
+ import { visualBuilderStyles } from "../visualBuilder.style.js";
14
+ import classNames from "classnames";
15
+ import { ContentTypeIcon } from "./icons/index.js";
16
+ import { FieldTypeIconsMap } from "../generators/generateCustomCursor.js";
17
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
18
+ var Tooltip = ({ children, content, placement = "top-start" }) => {
19
+ const [isVisible, setIsVisible] = useState(false);
20
+ const triggerRef = useRef(null);
21
+ const tooltipRef = useRef(null);
22
+ const arrowRef = useRef(null);
23
+ const showTooltip = () => setIsVisible(true);
24
+ const hideTooltip = () => setIsVisible(false);
25
+ useEffect(() => {
26
+ if (!isVisible || !triggerRef.current || !tooltipRef.current) {
27
+ return;
28
+ }
29
+ const trigger = triggerRef.current;
30
+ const tooltip = tooltipRef.current;
31
+ computePosition(trigger, tooltip, {
32
+ placement,
33
+ // Middleware runs in order to modify the position
34
+ middleware: [
35
+ offset(8),
36
+ // Add 8px of space between the trigger and tooltip
37
+ flip(),
38
+ // Flip to the opposite side if it overflows
39
+ shift({ padding: 5 }),
40
+ // Shift to keep it in view
41
+ ...arrowRef.current ? [arrow({ element: arrowRef.current })] : []
42
+ // Handle arrow positioning
43
+ ]
44
+ }).then(({ x, y, placement: placement2, middlewareData }) => {
45
+ Object.assign(tooltip.style, {
46
+ left: `${x}px`,
47
+ top: `${y}px`
48
+ });
49
+ if (middlewareData.arrow && arrowRef.current) {
50
+ const { x: arrowX, y: arrowY } = middlewareData.arrow;
51
+ const side = placement2.split("-")[0];
52
+ const staticSide = {
53
+ top: "bottom",
54
+ right: "left",
55
+ bottom: "top",
56
+ left: "right"
57
+ }[side];
58
+ const arrowElement = arrowRef.current;
59
+ Object.assign(arrowElement.style, {
60
+ left: "",
61
+ top: "",
62
+ right: "",
63
+ bottom: ""
64
+ });
65
+ if (placement2.includes("-start") || placement2.includes("-end")) {
66
+ const tooltipRect = tooltip.getBoundingClientRect();
67
+ if (side === "top" || side === "bottom") {
68
+ arrowElement.style.left = `${14}px`;
69
+ if (arrowY != null) {
70
+ arrowElement.style.top = `${arrowY}px`;
71
+ }
72
+ } else {
73
+ arrowElement.style.top = `${tooltipRect.height / 2 - 4}px`;
74
+ if (arrowX != null) {
75
+ arrowElement.style.left = `${arrowX}px`;
76
+ }
77
+ }
78
+ } else {
79
+ if (arrowX != null) {
80
+ arrowElement.style.left = `${arrowX}px`;
81
+ }
82
+ if (arrowY != null) {
83
+ arrowElement.style.top = `${arrowY}px`;
84
+ }
85
+ }
86
+ arrowElement.style[staticSide] = "-4px";
87
+ }
88
+ });
89
+ }, [isVisible, placement, content]);
90
+ const triggerWithListeners = cloneElement(children, {
91
+ ref: triggerRef,
92
+ onMouseEnter: showTooltip,
93
+ onMouseLeave: hideTooltip,
94
+ onFocus: showTooltip,
95
+ onBlur: hideTooltip,
96
+ "aria-describedby": "lightweight-tooltip"
97
+ // for accessibility
98
+ });
99
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
100
+ triggerWithListeners,
101
+ isVisible && /* @__PURE__ */ jsxs(
102
+ "div",
103
+ {
104
+ ref: tooltipRef,
105
+ role: "tooltip",
106
+ id: "lightweight-tooltip",
107
+ className: classNames("tooltip-container", visualBuilderStyles()["tooltip-container"]),
108
+ children: [
109
+ content,
110
+ /* @__PURE__ */ jsx("div", { ref: arrowRef, className: classNames("tooltip-arrow", visualBuilderStyles()["tooltip-arrow"]) })
111
+ ]
112
+ }
113
+ )
114
+ ] });
115
+ };
116
+ function ToolbarTooltipContent({ contentTypeName, referenceFieldName }) {
117
+ return /* @__PURE__ */ jsxs("div", { className: classNames("toolbar-tooltip-content", visualBuilderStyles()["toolbar-tooltip-content"]), children: [
118
+ contentTypeName && /* @__PURE__ */ jsxs("div", { className: classNames("toolbar-tooltip-content-item", visualBuilderStyles()["toolbar-tooltip-content-item"]), children: [
119
+ /* @__PURE__ */ jsx(ContentTypeIcon, {}),
120
+ /* @__PURE__ */ jsx("p", { children: contentTypeName })
121
+ ] }),
122
+ referenceFieldName && /* @__PURE__ */ jsxs("div", { className: classNames("toolbar-tooltip-content-item", visualBuilderStyles()["toolbar-tooltip-content-item"]), children: [
123
+ /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: FieldTypeIconsMap.reference }, className: classNames("visual-builder__field-icon", visualBuilderStyles()["visual-builder__field-icon"]) }),
124
+ /* @__PURE__ */ jsx("p", { children: referenceFieldName })
125
+ ] })
126
+ ] });
127
+ }
128
+ function ToolbarTooltip({ children, data, disabled = false }) {
129
+ if (disabled) {
130
+ return children;
131
+ }
132
+ const { contentTypeName, referenceFieldName } = data;
133
+ return /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ToolbarTooltipContent, { contentTypeName, referenceFieldName }), children });
134
+ }
135
+ var Tooltip_default = Tooltip;
136
+ export {
137
+ ToolbarTooltip,
138
+ Tooltip_default as default
139
+ };
140
+ //# sourceMappingURL=Tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/visualBuilder/components/Tooltip.tsx"],"sourcesContent":["import { h, cloneElement } from 'preact';\nimport { useState, useEffect, useRef } from 'preact/hooks';\nimport {\n computePosition,\n flip,\n shift,\n offset,\n arrow\n} from '@floating-ui/dom';\nimport { visualBuilderStyles } from '../visualBuilder.style';\nimport classNames from 'classnames';\nimport { ContentTypeIcon } from './icons';\nimport { FieldTypeIconsMap } from '../generators/generateCustomCursor';\ninterface TooltipProps {\n children: JSX.Element;\n content: JSX.Element;\n placement?: 'top-start' | 'bottom-start' | 'left-start' | 'right-start';\n}\n\n/**\n * A lightweight, reusable tooltip component for Preact powered by Floating UI.\n *\n * @param {object} props - The component props.\n * @param {preact.ComponentChildren} props.children - The single child element that triggers the tooltip.\n * @param {string | preact.VNode} props.content - The content to display inside the tooltip.\n * @param {'top'|'bottom'|'left'|'right'} [props.placement='top'] - The desired placement of the tooltip.\n */\nconst Tooltip = ({ children, content, placement = 'top-start' }: TooltipProps) => {\n const [isVisible, setIsVisible] = useState(false);\n // Create refs for the trigger and the floating tooltip elements\n const triggerRef = useRef(null);\n const tooltipRef = useRef(null);\n const arrowRef = useRef(null);\n\n const showTooltip = () => setIsVisible(true);\n const hideTooltip = () => setIsVisible(false);\n\n // This effect calculates the tooltip's position whenever it becomes visible\n // or if its content or placement changes.\n useEffect(() => {\n if (!isVisible || !triggerRef.current || !tooltipRef.current) {\n return;\n }\n\n const trigger = triggerRef.current as HTMLElement;\n const tooltip = tooltipRef.current as HTMLElement;\n\n computePosition(trigger, tooltip, {\n placement,\n // Middleware runs in order to modify the position\n middleware: [\n offset(8), // Add 8px of space between the trigger and tooltip\n flip(), // Flip to the opposite side if it overflows\n shift({ padding: 5 }), // Shift to keep it in view\n ...(arrowRef.current ? [arrow({ element: arrowRef.current as HTMLElement })] : []), // Handle arrow positioning\n ],\n }).then(({ x, y, placement, middlewareData }) => {\n // Apply the calculated coordinates to the tooltip element\n Object.assign(tooltip.style, {\n left: `${x}px`,\n top: `${y}px`,\n });\n\n // Position the arrow element\n if (middlewareData.arrow && arrowRef.current) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n const side = placement.split('-')[0];\n const staticSide = {\n top: 'bottom',\n right: 'left',\n bottom: 'top',\n left: 'right',\n }[side] as string;\n\n const arrowElement = arrowRef.current as HTMLElement;\n \n // Reset all positioning properties\n Object.assign(arrowElement.style, {\n left: '',\n top: '',\n right: '',\n bottom: '',\n });\n\n // For placements like top-start, bottom-start, etc., we want the arrow \n // to be centered on the tooltip rather than pointing at the trigger center\n if (placement.includes('-start') || placement.includes('-end')) {\n const tooltipRect = tooltip.getBoundingClientRect();\n \n if (side === 'top' || side === 'bottom') {\n // For top/bottom placements, center the arrow horizontally\n arrowElement.style.left = `${14}px`; // 4px = half arrow width\n if (arrowY != null) {\n arrowElement.style.top = `${arrowY}px`;\n }\n } else {\n // For left/right placements, center the arrow vertically\n arrowElement.style.top = `${tooltipRect.height / 2 - 4}px`; // 4px = half arrow height\n if (arrowX != null) {\n arrowElement.style.left = `${arrowX}px`;\n }\n }\n } else {\n // For regular placements (top, bottom, left, right), use floating-ui's positioning\n if (arrowX != null) {\n arrowElement.style.left = `${arrowX}px`;\n }\n if (arrowY != null) {\n arrowElement.style.top = `${arrowY}px`;\n }\n }\n\n // Position arrow to overlap the tooltip's border\n (arrowElement.style as any)[staticSide] = '-4px';\n }\n });\n\n }, [isVisible, placement, content]);\n\n // We need to clone the child element to attach our ref and event listeners.\n // This ensures we don't wrap the child in an extra <div>.\n const triggerWithListeners = cloneElement(children, {\n ref: triggerRef,\n onMouseEnter: showTooltip,\n onMouseLeave: hideTooltip,\n onFocus: showTooltip,\n onBlur: hideTooltip,\n 'aria-describedby': 'lightweight-tooltip' // for accessibility\n });\n\n return (\n <>\n {triggerWithListeners}\n {isVisible && (\n <div\n ref={tooltipRef}\n role=\"tooltip\"\n id=\"lightweight-tooltip\"\n className={classNames(\"tooltip-container\", visualBuilderStyles()[\"tooltip-container\"])}\n >\n {content}\n <div ref={arrowRef} className={classNames(\"tooltip-arrow\", visualBuilderStyles()[\"tooltip-arrow\"])}></div>\n </div>\n )}\n </>\n );\n};\n\nfunction ToolbarTooltipContent({contentTypeName, referenceFieldName}: {contentTypeName: string, referenceFieldName: string}) {\n return (\n <div className={classNames(\"toolbar-tooltip-content\", visualBuilderStyles()[\"toolbar-tooltip-content\"])}>\n {\n contentTypeName && (\n <div className={classNames(\"toolbar-tooltip-content-item\", visualBuilderStyles()[\"toolbar-tooltip-content-item\"])}>\n <ContentTypeIcon />\n <p>{contentTypeName}</p>\n </div>\n )\n }\n {\n referenceFieldName && (\n <div className={classNames(\"toolbar-tooltip-content-item\", visualBuilderStyles()[\"toolbar-tooltip-content-item\"])}>\n <div dangerouslySetInnerHTML={{__html: FieldTypeIconsMap.reference}} className={classNames(\"visual-builder__field-icon\", visualBuilderStyles()[\"visual-builder__field-icon\"])}/>\n <p>{referenceFieldName}</p>\n </div>\n )\n }\n </div>\n )\n}\n\nexport function ToolbarTooltip({children, data, disabled = false}: {children: JSX.Element, data: {contentTypeName: string, referenceFieldName: string}, disabled?: boolean}) {\n if (disabled) {\n return children;\n }\n const { contentTypeName, referenceFieldName } = data;\n return (\n <Tooltip content={<ToolbarTooltipContent contentTypeName={contentTypeName} referenceFieldName={referenceFieldName} />}>\n {children}\n </Tooltip>\n )\n}\n\nexport default Tooltip;"],"mappings":";;;AAAA,SAAY,oBAAoB;AAChC,SAAS,UAAU,WAAW,cAAc;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC,OAAO,gBAAgB;AACvB,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAuH1B,mBAUY,KAPJ,YAHR;AAxGR,IAAM,U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sB,EAAC,iBAAiB,mBAAkB,GAA0D;AAC3H,SACE,qBAAC,SAAI,WAAW,WAAW,2BAA2B,oBAAoB,EAAE,yBAAyB,CAAC,GAElG;AAAA,uBACE,qBAAC,SAAI,WAAW,WAAW,gCAAgC,oBAAoB,EAAE,8BAA8B,CAAC,GAC9G;AAAA,0BAAC,mBAAgB;AAAA,MACjB,oBAAC,OAAG,2BAAgB;AAAA,OACtB;AAAA,IAIF,sBACE,qBAAC,SAAI,WAAW,WAAW,gCAAgC,oBAAoB,EAAE,8BAA8B,CAAC,GAC9G;AAAA,0BAAC,SAAI,yBAAyB,EAAC,QAAQ,kBAAkB,UAAS,GAAG,WAAW,WAAW,8BAA8B,oBAAoB,EAAE,4BAA4B,CAAC,GAAE;AAAA,MAC9K,oBAAC,OAAG,8BAAmB;AAAA,OACzB;AAAA,KAGN;AAEJ;AAEO,SAAS,eAAe,EAAC,UAAU,MAAM,WAAW,MAAK,GAA6G;AAC3K,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AACA,QAAM,EAAE,iBAAiB,mBAAmB,IAAI;AAChD,SACE,oBAAC,WAAQ,SAAS,oBAAC,yBAAsB,iBAAkC,oBAAwC,GAChH,UACH;AAEJ;AAEA,IAAO,kBAAQ;","names":["placement"]}
@@ -48,24 +48,50 @@ var import_CslpError = require("./CslpError.cjs");
48
48
  var import_errorHandling = require("../utils/errorHandling.cjs");
49
49
  var import_postMessage = require("../utils/types/postMessage.types.cjs");
50
50
  var import_getEntryPermissionsCached = require("../utils/getEntryPermissionsCached.cjs");
51
+ var import_icons2 = require("./icons/index.cjs");
52
+ var import_Tooltip = require("./Tooltip.cjs");
51
53
  var import_jsx_runtime = require("preact/jsx-runtime");
52
54
  async function getFieldDisplayNames(fieldMetadata) {
53
55
  const result = await import_visualBuilderPostMessage.default?.send(import_postMessage.VisualBuilderPostMessageEvents.GET_FIELD_DISPLAY_NAMES, fieldMetadata);
54
56
  return result;
55
57
  }
58
+ async function getContentTypeName(contentTypeUid) {
59
+ try {
60
+ const result = await import_visualBuilderPostMessage.default?.send(import_postMessage.VisualBuilderPostMessageEvents.GET_CONTENT_TYPE_NAME, {
61
+ content_type_uid: contentTypeUid
62
+ });
63
+ return result?.contentTypeName;
64
+ } catch (e) {
65
+ console.warn("[getFieldLabelWrapper] Error getting content type name", e);
66
+ return "";
67
+ }
68
+ }
69
+ async function getReferenceParentMap() {
70
+ try {
71
+ const result = await import_visualBuilderPostMessage.default?.send(import_postMessage.VisualBuilderPostMessageEvents.REFERENCE_MAP, {}) ?? {};
72
+ return result;
73
+ } catch (e) {
74
+ console.warn("[getFieldLabelWrapper] Error getting reference parent map", e);
75
+ return {};
76
+ }
77
+ }
56
78
  function FieldLabelWrapperComponent(props) {
57
79
  const { eventDetails } = props;
58
80
  const [currentField, setCurrentField] = (0, import_compat.useState)({
59
81
  text: "",
82
+ contentTypeName: "",
60
83
  icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CaretIcon, {}),
61
84
  prefixIcon: null,
62
85
  disabled: false,
63
- isVariant: false
86
+ isVariant: false,
87
+ isReference: false,
88
+ referenceFieldName: "",
89
+ parentContentTypeName: ""
64
90
  });
65
91
  const [displayNames, setDisplayNames] = (0, import_compat.useState)(
66
92
  {}
67
93
  );
68
- const [displayNamesLoading, setDisplayNamesLoading] = (0, import_compat.useState)(true);
94
+ const [dataLoading, setDataLoading] = (0, import_compat.useState)(true);
69
95
  const [error, setError] = (0, import_compat.useState)(false);
70
96
  const [isDropdownOpen, setIsDropdownOpen] = (0, import_compat.useState)(false);
71
97
  function calculateTopOffset(index) {
@@ -75,7 +101,7 @@ function FieldLabelWrapperComponent(props) {
75
101
  }
76
102
  (0, import_compat.useEffect)(() => {
77
103
  const fetchData = async () => {
78
- setDisplayNamesLoading(true);
104
+ setDataLoading(true);
79
105
  const allPaths = (0, import_lodash_es.uniqBy)(
80
106
  [
81
107
  props.fieldMetadata,
@@ -85,13 +111,37 @@ function FieldLabelWrapperComponent(props) {
85
111
  ],
86
112
  "cslpValue"
87
113
  );
88
- const displayNames2 = await getFieldDisplayNames(allPaths);
89
- const fieldSchema = await import_fieldSchemaMap.FieldSchemaMap.getFieldSchema(
90
- props.fieldMetadata.content_type_uid,
91
- props.fieldMetadata.fieldPath
92
- );
114
+ const [displayNames2, fieldSchema, contentTypeName, referenceParentMap] = await Promise.all([
115
+ getFieldDisplayNames(allPaths),
116
+ import_fieldSchemaMap.FieldSchemaMap.getFieldSchema(
117
+ props.fieldMetadata.content_type_uid,
118
+ props.fieldMetadata.fieldPath
119
+ ),
120
+ getContentTypeName(
121
+ props.fieldMetadata.content_type_uid
122
+ ),
123
+ getReferenceParentMap()
124
+ ]);
125
+ const entryUid = props.fieldMetadata.entry_uid;
126
+ const referenceData = referenceParentMap[entryUid];
127
+ const isReference = !!referenceData;
128
+ let referenceFieldName = referenceData ? referenceData[0].referenceFieldName : "";
129
+ let parentContentTypeName = referenceData ? referenceData[0].contentTypeTitle : "";
130
+ if (isReference) {
131
+ const domAncestor = eventDetails.editableElement.closest(`[data-cslp]:not([data-cslp^="${props.fieldMetadata.content_type_uid}"])`);
132
+ if (domAncestor) {
133
+ const domAncestorCslp = domAncestor.getAttribute("data-cslp");
134
+ const domAncestorDetails = (0, import_cslp.extractDetailsFromCslp)(domAncestorCslp);
135
+ const domAncestorContentTypeUid = domAncestorDetails.content_type_uid;
136
+ const domAncestorContentParent = referenceData?.find((data) => data.contentTypeUid === domAncestorContentTypeUid);
137
+ if (domAncestorContentParent) {
138
+ referenceFieldName = domAncestorContentParent.referenceFieldName;
139
+ parentContentTypeName = domAncestorContentParent.contentTypeTitle;
140
+ }
141
+ }
142
+ }
93
143
  if ((0, import_errorHandling.hasPostMessageError)(displayNames2) || !fieldSchema) {
94
- setDisplayNamesLoading(false);
144
+ setDataLoading(false);
95
145
  setError(true);
96
146
  return;
97
147
  }
@@ -110,6 +160,7 @@ function FieldLabelWrapperComponent(props) {
110
160
  const isVariant = props.fieldMetadata.variant ? true : false;
111
161
  setCurrentField({
112
162
  text: currentFieldDisplayName,
163
+ contentTypeName: contentTypeName ?? "",
113
164
  icon: fieldDisabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
114
165
  "div",
115
166
  {
@@ -120,18 +171,25 @@ function FieldLabelWrapperComponent(props) {
120
171
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.InfoIcon, {})
121
172
  }
122
173
  ) : hasParentPaths ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CaretIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {}),
174
+ isReference,
123
175
  prefixIcon: (0, import_generateCustomCursor.getFieldIcon)(fieldSchema),
124
176
  disabled: fieldDisabled,
177
+ referenceFieldName,
178
+ parentContentTypeName,
125
179
  isVariant
126
180
  });
127
181
  if (displayNames2) {
128
182
  setDisplayNames(displayNames2);
129
183
  }
130
184
  if (Object.keys(displayNames2 || {})?.length === allPaths.length) {
131
- setDisplayNamesLoading(false);
185
+ setDataLoading(false);
132
186
  }
133
187
  };
134
- fetchData();
188
+ try {
189
+ fetchData();
190
+ } catch (e) {
191
+ console.warn("[getFieldLabelWrapper] Error fetching field label data", e);
192
+ }
135
193
  }, [props]);
136
194
  const onParentPathClick = (cslp) => {
137
195
  const parentElement = props.getParentEditableElement(cslp);
@@ -142,7 +200,7 @@ function FieldLabelWrapperComponent(props) {
142
200
  function getCurrentFieldIcon() {
143
201
  if (error) {
144
202
  return null;
145
- } else if (displayNamesLoading) {
203
+ } else if (dataLoading) {
146
204
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loading.LoadingIcon, {});
147
205
  } else {
148
206
  return currentField.icon;
@@ -155,7 +213,7 @@ function FieldLabelWrapperComponent(props) {
155
213
  "visual-builder__focused-toolbar__field-label-container",
156
214
  (0, import_visualBuilder.visualBuilderStyles)()["visual-builder__focused-toolbar__field-label-container"]
157
215
  ),
158
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
216
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Tooltip.ToolbarTooltip, { data: { contentTypeName: currentField.parentContentTypeName, referenceFieldName: currentField.referenceFieldName }, disabled: !currentField.isReference || isDropdownOpen, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
159
217
  "div",
160
218
  {
161
219
  className: (0, import_classnames.default)(
@@ -174,6 +232,7 @@ function FieldLabelWrapperComponent(props) {
174
232
  ),
175
233
  onClick: () => setIsDropdownOpen((prev) => !prev),
176
234
  "data-testid": "visual-builder__focused-toolbar__field-label-wrapper",
235
+ "data-hovered-cslp": props.fieldMetadata.cslpValue,
177
236
  children: [
178
237
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
179
238
  "button",
@@ -186,8 +245,47 @@ function FieldLabelWrapperComponent(props) {
186
245
  (0, import_visualBuilder.visualBuilderStyles)()["visual-builder__button-loader"],
187
246
  error && (0, import_visualBuilder.visualBuilderStyles)()["visual-builder__button-error"]
188
247
  ),
189
- disabled: displayNamesLoading,
248
+ disabled: dataLoading,
190
249
  children: [
250
+ currentField.isReference && !dataLoading && !error ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
251
+ "div",
252
+ {
253
+ className: (0, import_classnames.default)(
254
+ "visual-builder__reference-icon-container",
255
+ (0, import_visualBuilder.visualBuilderStyles)()["visual-builder__reference-icon-container"]
256
+ ),
257
+ children: [
258
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
259
+ "div",
260
+ {
261
+ className: (0, import_classnames.default)(
262
+ "visual-builder__field-icon",
263
+ (0, import_visualBuilder.visualBuilderStyles)()["visual-builder__field-icon"]
264
+ ),
265
+ dangerouslySetInnerHTML: {
266
+ __html: import_generateCustomCursor.FieldTypeIconsMap.reference
267
+ },
268
+ "data-testid": "visual-builder__field-icon-caret"
269
+ }
270
+ ),
271
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CaretRightIcon, {})
272
+ ]
273
+ }
274
+ ) : null,
275
+ currentField.contentTypeName && !dataLoading && !error ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
276
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons2.ContentTypeIcon, {}),
277
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
278
+ "div",
279
+ {
280
+ className: (0, import_classnames.default)(
281
+ "visual-builder__focused-toolbar__text",
282
+ (0, import_visualBuilder.visualBuilderStyles)()["visual-builder__focused-toolbar__text"]
283
+ ),
284
+ "data-testid": "visual-builder__focused-toolbar__ct-name",
285
+ children: currentField.contentTypeName + " : "
286
+ }
287
+ )
288
+ ] }) : null,
191
289
  currentField.prefixIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
192
290
  "div",
193
291
  {
@@ -236,7 +334,7 @@ function FieldLabelWrapperComponent(props) {
236
334
  ))
237
335
  ]
238
336
  }
239
- )
337
+ ) })
240
338
  }
241
339
  );
242
340
  }