Skip to content

Commit ca3dc62

Browse files
authored
Merge pull request #508 from contentstack/feat/VB-442-variant-on-hover
[Feat/VB-442] Indicator for variant fields
2 parents b365b99 + f294971 commit ca3dc62

File tree

12 files changed

+267
-26
lines changed

12 files changed

+267
-26
lines changed

CHANGELOG.md

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,108 @@
11
# Changelog
22

3+
## [v4.0.2](https://github.com/contentstack/live-preview-sdk/compare/v4.0.1...v4.0.2)
4+
5+
> 16 September 2025
6+
7+
### New Features
8+
9+
- feat(VE-7062-dev): disable editing based on workflow stage rules (Faraaz Biyabani - [#489](https://github.com/contentstack/live-preview-sdk/pull/489))
10+
11+
### Fixes
12+
13+
- fix: remove integrity attribute from script tag and update copyright year in `main.mustache` (Hitesh Shetty - [#499](https://github.com/contentstack/live-preview-sdk/pull/499))
14+
- fix: multiple reloads in timeline (Mridul Sharma - [#479](https://github.com/contentstack/live-preview-sdk/pull/479))
15+
- fix: removed edit icon when the click is on the container (Sahil Chalke - [#478](https://github.com/contentstack/live-preview-sdk/pull/478))
16+
- Fix: Issue with hover toolbar click-ability (Ayush Dubey - [#467](https://github.com/contentstack/live-preview-sdk/pull/467))
17+
- fix: modified the way we were handling fieldlocation data fetch (Sahil Chalke - [#462](https://github.com/contentstack/live-preview-sdk/pull/462))
18+
- Fix: HoverToolbar to not render when focussed (Ayush Dubey - [#461](https://github.com/contentstack/live-preview-sdk/pull/461))
19+
20+
### General Changes
21+
22+
- Develop v4 (Kirtesh Suthar - [#506](https://github.com/contentstack/live-preview-sdk/pull/506))
23+
- 18th sept 2025 release (Kirtesh Suthar - [#505](https://github.com/contentstack/live-preview-sdk/pull/505))
24+
- Live preview new tab ssr issue (Mridul Sharma - [#502](https://github.com/contentstack/live-preview-sdk/pull/502))
25+
- VB-248 fixed the cursor moving to the start with a explicitly adding pseudo element on second time a field is visited (Sahil Chalke - [#497](https://github.com/contentstack/live-preview-sdk/pull/497))
26+
- VE-6918 : warning message improved (Aditya Pachauri - [#475](https://github.com/contentstack/live-preview-sdk/pull/475))
27+
- HoverToolbar: Requested Changes (Ayush Dubey - [#464](https://github.com/contentstack/live-preview-sdk/pull/464))
28+
- Ve 5474 field modifier support for canvas in visual builder (Sahil Chalke - [#460](https://github.com/contentstack/live-preview-sdk/pull/460))
29+
- [Feature] HoverToolbar (Ayush Dubey - [#455](https://github.com/contentstack/live-preview-sdk/pull/455))
30+
- Disable scroll when field modifer is active (Sahil Chalke - [#458](https://github.com/contentstack/live-preview-sdk/pull/458))
31+
- [HoverToolbar]: Handling postMessage for ReferenceParentMap and rendering changes (Ayush Dubey - [#453](https://github.com/contentstack/live-preview-sdk/pull/453))
32+
- [Feat: HoverToolbar] Component and rendering logic changes (Ayush Dubey - [#450](https://github.com/contentstack/live-preview-sdk/pull/450))
33+
- Field modifiers in canvas (Sairaj - [#449](https://github.com/contentstack/live-preview-sdk/pull/449))
34+
35+
### New Features
36+
37+
- feat: hovertoolbar component and rendering (csAyushDubey - [000168e](https://github.com/contentstack/live-preview-sdk/commit/000168ed0a2757d48912e96917950b4915cce8ab))
38+
- feat: fieldLabelWrapper changes (csAyushDubey - [42c1576](https://github.com/contentstack/live-preview-sdk/commit/42c15760efe4faf271e78911be5db8f76be8c700))
39+
40+
### Fixes
41+
42+
- fix: tests (csAyushDubey - [71f24d8](https://github.com/contentstack/live-preview-sdk/commit/71f24d82b67ad1682dd9240fddc84adbede15211))
43+
- fix: fixed the required changes (SahilCs15 - [435a028](https://github.com/contentstack/live-preview-sdk/commit/435a02894c456c015107a10ee0367f8f5a348ecf))
44+
- fix: resolved the issues (SahilCs15 - [a0ff5b0](https://github.com/contentstack/live-preview-sdk/commit/a0ff5b0d32c8b62f86e81bd5130f6cce04aa914f))
45+
- fix: undo unneccsary changes (SahilCs15 - [bf2cc68](https://github.com/contentstack/live-preview-sdk/commit/bf2cc68b83f3bb4889c3ecc497b6e77d785ee001))
46+
- fix: new tab ssr params issue fix (Mridul Sharma - [b78db51](https://github.com/contentstack/live-preview-sdk/commit/b78db513ce62e657c7ca9b4c343b6742a47e293e))
47+
- fix: missed rendering case (csAyushDubey - [8478bbc](https://github.com/contentstack/live-preview-sdk/commit/8478bbc2b1216d78fbbb1a831ee47dbb62e1f413))
48+
- fix: removed not requied changes (SahilCs15 - [37dccb8](https://github.com/contentstack/live-preview-sdk/commit/37dccb8265ce92ac6f63832220828ac7ec41428b))
49+
- fix: disable scroll when field modifer is active (SahilCs15 - [1cae0c3](https://github.com/contentstack/live-preview-sdk/commit/1cae0c38962d8b4cef541931125d5e4c2d987fa5))
50+
- fix: no hovertoolbar when focussed (csAyushDubey - [a80d08d](https://github.com/contentstack/live-preview-sdk/commit/a80d08d26de47e9eb357b0fc2da5888f3f72ddb4))
51+
- fix: remove integrity attribute from script tag and update copyright year in main.mustache (hiteshshetty-dev - [51fec5b](https://github.com/contentstack/live-preview-sdk/commit/51fec5bbe8ad125552f404bf4844a94aa58960e2))
52+
- fix: changed order in tooltip and customcursor hiding (csAyushDubey - [cc71759](https://github.com/contentstack/live-preview-sdk/commit/cc71759fe7479f46d4cdc6dc76e433cd67b1336a))
53+
- fix: addresed the requested cahnges (SahilCs15 - [12be298](https://github.com/contentstack/live-preview-sdk/commit/12be2984477ce3dfd249a81de33f1777c6cf59eb))
54+
- fix:removed uncessary changes (SahilCs15 - [14ba432](https://github.com/contentstack/live-preview-sdk/commit/14ba43239ccc486767ea282729bb3ec7f6f824f0))
55+
- fix: field parent clickability (csAyushDubey - [ac4fdb3](https://github.com/contentstack/live-preview-sdk/commit/ac4fdb383bc2c27c8e157446e663cbdbcf0879bd))
56+
- fix: fixed conficts (SahilCs15 - [c8e3a35](https://github.com/contentstack/live-preview-sdk/commit/c8e3a350cdc1f59a3422b05265d9d9ade5e5ac79))
57+
- fix: tooltip arrow change (csAyushDubey - [bab4171](https://github.com/contentstack/live-preview-sdk/commit/bab41716a7dfbe4bcb3b74f310cb314c2faa16b4))
58+
59+
### Chores And Housekeeping
60+
61+
- chore: rendered the fieldmodifier apps added an event listner to send the selected app (SahilCs15 - [26a70f4](https://github.com/contentstack/live-preview-sdk/commit/26a70f48ac9e62af5b7f9d69bc10eefa0f103255))
62+
- chore: added test cases for the field location data (SahilCs15 - [c394b1f](https://github.com/contentstack/live-preview-sdk/commit/c394b1f74fca020f9cc9eef3a8ca24cc51882507))
63+
- chore: fieldlocation fetch completed (SahilCs15 - [2c4e0ee](https://github.com/contentstack/live-preview-sdk/commit/2c4e0ee8896cf71c22edbadcaa750d75f4642de3))
64+
- chore: added test cases for testing the pseudo element (SahilCs15 - [41de9c3](https://github.com/contentstack/live-preview-sdk/commit/41de9c3fc50f33dd83d53767d216c4dfd0c43e88))
65+
- chore(VE-6918/error-text): unit test file added (Aditya Pachauri - [7ecfb19](https://github.com/contentstack/live-preview-sdk/commit/7ecfb19309e55bba554ad71cf8b66bd95c575a1e))
66+
- chore(VE-6918/error-text): warning message improved (Aditya Pachauri - [6b83664](https://github.com/contentstack/live-preview-sdk/commit/6b83664d5393bd5ebaf0c57667c0086f328d50d2))
67+
- chore: remove ssri and @types/ssri from installed packages (hiteshshetty-dev - [2305f45](https://github.com/contentstack/live-preview-sdk/commit/2305f45ffb102555d1a56145b0e715c2cda72ba9))
68+
- chore: cleanup commit (csAyushDubey - [51204af](https://github.com/contentstack/live-preview-sdk/commit/51204af486426ade2095bdc84b8cf46c375ebb2c))
69+
- chore: increased test timeout for CI (csAyushDubey - [8830f3c](https://github.com/contentstack/live-preview-sdk/commit/8830f3c3fa5bec5253b3b57f85e866d331089198))
70+
- chore: increased timeout further (csAyushDubey - [da638dd](https://github.com/contentstack/live-preview-sdk/commit/da638dd326270a094cc456289b6c533bca1f43ba))
71+
- chore(VE-6918/error-text): component name changed to title case (Aditya Pachauri - [ec3ccab](https://github.com/contentstack/live-preview-sdk/commit/ec3ccab4ef0d8d456d650f4dd6896d119bb9c32b))
72+
- chore: removed unused console log (Mridul Sharma - [e65d15c](https://github.com/contentstack/live-preview-sdk/commit/e65d15c51445e58b46e8d37a2a375fe2cf2f739a))
73+
- chore: added test cases and updated .talismanrc (SahilCs15 - [07ffb6e](https://github.com/contentstack/live-preview-sdk/commit/07ffb6ea358ff1232c958b7e2cd05b25b46f430f))
74+
- chore: talismanrc update (csAyushDubey - [d9a0d09](https://github.com/contentstack/live-preview-sdk/commit/d9a0d09bd157ffcf8675c05efc5afd6add854c56))
75+
- chore: added retry to vitest (csAyushDubey - [abfd640](https://github.com/contentstack/live-preview-sdk/commit/abfd64004407350d1e65af16fcf11f564edcfa52))
76+
- chore: incresed hook timeout for CI (csAyushDubey - [eb2d72f](https://github.com/contentstack/live-preview-sdk/commit/eb2d72f7665f65ef9c46b4d3a6f36c1bd045cef9))
77+
78+
### Changes to Test Assests
79+
80+
- test: fieldlabelwrapper (csAyushDubey - [bc21aae](https://github.com/contentstack/live-preview-sdk/commit/bc21aae35120e03d9b555676974442b955c046cd))
81+
- test: updated new tab test for ssr reload (Mridul Sharma - [f3c6abc](https://github.com/contentstack/live-preview-sdk/commit/f3c6abcffa822e224f6bd6a95bb6d7f99e12e3e0))
82+
83+
### General Changes
84+
85+
- redner the app on dom (SahilCs15 - [88a81a4](https://github.com/contentstack/live-preview-sdk/commit/88a81a4d82cb02b1e54977aa5d9fa684a6a773a2))
86+
- Delete secrets-scan.yml (Aravind Kumar - [52f91a4](https://github.com/contentstack/live-preview-sdk/commit/52f91a4c851d9b0e618ce0bb8c96863fba85065c))
87+
- Updated codeowners (Aravind Kumar - [1b89e20](https://github.com/contentstack/live-preview-sdk/commit/1b89e20fab643f51abe0b5edd4dec357622fce92))
88+
389
## [v4.0.1](https://github.com/contentstack/live-preview-sdk/compare/v4.0.0...v4.0.1)
490

5-
> 22 August 2025
91+
> 25 August 2025
92+
93+
### General Changes
94+
95+
- V4.0.1 (Zuhair Ahmed - [#496](https://github.com/contentstack/live-preview-sdk/pull/496))
696

797
### Fixes
898

999
- fix(preview): add util function to allow operations in preview share (Zuhair Ahmed - [fb70cdf](https://github.com/contentstack/live-preview-sdk/commit/fb70cdf8f238a0f54bbf85cacd84a09688d54b9e))
10100

101+
### Chores And Housekeeping
102+
103+
- chore(talisman): update .talismanrc (Zuhair Ahmed - [e044f1b](https://github.com/contentstack/live-preview-sdk/commit/e044f1b304c2de666471f47d4a5a3235945b6f6c))
104+
- chore(readme): update readme (Zuhair Ahmed - [2e6d835](https://github.com/contentstack/live-preview-sdk/commit/2e6d835b4d99ca628835e00a6cb1ff1a2197c039))
105+
11106
## [v4.0.0](https://github.com/contentstack/live-preview-sdk/compare/v3.4.0...v4.0.0)
12107

13108
> 22 August 2025
@@ -520,9 +615,11 @@
520615
### General Changes
521616

522617
- sync main for upcoming release (Hitesh Shetty - [#338](https://github.com/contentstack/live-preview-sdk/pull/338))
618+
- 3.1.0 (Kirtesh Suthar - [#323](https://github.com/contentstack/live-preview-sdk/pull/323))
523619

524620
### Fixes
525621

622+
- fix: live preview doc (Kirtesh Suthar - [f81fdf5](https://github.com/contentstack/live-preview-sdk/commit/f81fdf55fd2ab2ce4cac3bf974b0a31566c24001))
526623
- fix: live preview doc (Kirtesh Suthar - [8fcdcc5](https://github.com/contentstack/live-preview-sdk/commit/8fcdcc5127ea722bd9c01f74b1168d9f579e5f30))
527624

528625
### Chores And Housekeeping
@@ -544,7 +641,7 @@
544641

545642
## [v3.1.0](https://github.com/contentstack/live-preview-sdk/compare/v3.0.2...v3.1.0)
546643

547-
> 16 January 2025
644+
> 10 January 2025
548645
549646
### New Features
550647

@@ -561,7 +658,6 @@
561658

562659
### General Changes
563660

564-
- 3.1.0 (Kirtesh Suthar - [#323](https://github.com/contentstack/live-preview-sdk/pull/323))
565661
- Feat/auto changelog (Kirtesh Suthar - [#321](https://github.com/contentstack/live-preview-sdk/pull/321))
566662

567663
### New Features
@@ -572,7 +668,6 @@
572668
### Fixes
573669

574670
- fix: issue with variant revert dropdown in canvas and show variant icon for multiple fields (Srinadh Reddy - [8718c48](https://github.com/contentstack/live-preview-sdk/commit/8718c4832f30606437da1fd18513006f21e0fd34))
575-
- fix: live preview doc (Kirtesh Suthar - [f81fdf5](https://github.com/contentstack/live-preview-sdk/commit/f81fdf55fd2ab2ce4cac3bf974b0a31566c24001))
576671

577672
### Chores And Housekeeping
578673

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Alternatively, if you want to include the package directly in your website HTML
1616

1717
```html
1818
<script type='module' crossorigin="anonymous">
19-
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@4.0.1';
19+
import ContentstackLivePreview from 'https://esm.sh/@contentstack/live-preview-utils@4.0.2';
2020
2121
ContentstackLivePreview.init({
2222
stackDetails: {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/live-preview-utils",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"description": "Contentstack provides the Live Preview SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane.",
55
"type": "module",
66
"types": "dist/legacy/index.d.ts",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "preact/compat";
2+
import { VariantIcon } from "./icons/variant";
3+
import { visualBuilderStyles } from "../visualBuilder.style";
4+
5+
export function VariantIndicator(): JSX.Element {
6+
return (
7+
<div className={visualBuilderStyles()["visual-builder__variant-indicator"]}>
8+
<VariantIcon size="18px" />
9+
</div>
10+
);
11+
12+
}

src/visualBuilder/components/__test__/fieldLabelWrapper.test.tsx

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ vi.mock("../generators/generateCustomCursor", () => ({
118118
}));
119119

120120
vi.mock("../visualBuilder.style", () => ({
121-
visualBuilderStyles: vi.fn().mockReturnValue({}),
121+
visualBuilderStyles: vi.fn().mockReturnValue({
122+
"visual-builder__focused-toolbar--variant": "visual-builder__focused-toolbar--variant"
123+
}),
124+
}));
125+
126+
vi.mock("../VariantIndicator", () => ({
127+
VariantIndicator: () => <div data-testid="variant-indicator">Variant</div>
122128
}));
123129

124130
vi.mock("../../utils/errorHandling", () => ({
@@ -387,4 +393,78 @@ describe("FieldLabelWrapperComponent", () => {
387393
const contentTypeIcon = container.querySelector(".visual-builder__content-type-icon");
388394
expect(contentTypeIcon).not.toBeInTheDocument();
389395
});
396+
397+
test("renders VariantIndicator when field has variant", async () => {
398+
const variantFieldMetadata = {
399+
...mockFieldMetadata,
400+
variant: "variant-uid-123"
401+
};
402+
403+
const { findByTestId } = await asyncRender(
404+
<FieldLabelWrapperComponent
405+
fieldMetadata={variantFieldMetadata}
406+
eventDetails={mockEventDetails}
407+
parentPaths={[]}
408+
getParentEditableElement={mockGetParentEditable}
409+
/>
410+
);
411+
412+
const variantIndicator = await findByTestId("variant-indicator");
413+
expect(variantIndicator).toBeInTheDocument();
414+
});
415+
416+
test("does not render VariantIndicator when field has no variant", async () => {
417+
const { container } = await asyncRender(
418+
<FieldLabelWrapperComponent
419+
fieldMetadata={mockFieldMetadata}
420+
eventDetails={mockEventDetails}
421+
parentPaths={[]}
422+
getParentEditableElement={mockGetParentEditable}
423+
/>
424+
);
425+
426+
await waitFor(() => {
427+
const variantIndicator = container.querySelector("[data-testid='variant-indicator']");
428+
expect(variantIndicator).not.toBeInTheDocument();
429+
});
430+
});
431+
432+
test("applies variant CSS classes when field has variant", async () => {
433+
const variantFieldMetadata = {
434+
...mockFieldMetadata,
435+
variant: "variant-uid-123"
436+
};
437+
438+
const { findByTestId } = await asyncRender(
439+
<FieldLabelWrapperComponent
440+
fieldMetadata={variantFieldMetadata}
441+
eventDetails={mockEventDetails}
442+
parentPaths={[]}
443+
getParentEditableElement={mockGetParentEditable}
444+
/>
445+
);
446+
447+
const fieldLabelWrapper = await findByTestId("visual-builder__focused-toolbar__field-label-wrapper");
448+
449+
await waitFor(() => {
450+
expect(fieldLabelWrapper).toHaveClass("visual-builder__focused-toolbar--variant");
451+
});
452+
});
453+
454+
test("does not apply variant CSS classes when field has no variant", async () => {
455+
const { findByTestId } = await asyncRender(
456+
<FieldLabelWrapperComponent
457+
fieldMetadata={mockFieldMetadata}
458+
eventDetails={mockEventDetails}
459+
parentPaths={[]}
460+
getParentEditableElement={mockGetParentEditable}
461+
/>
462+
);
463+
464+
const fieldLabelWrapper = await findByTestId("visual-builder__focused-toolbar__field-label-wrapper");
465+
466+
await waitFor(() => {
467+
expect(fieldLabelWrapper).not.toHaveClass("visual-builder__focused-toolbar--variant");
468+
});
469+
});
390470
});

src/visualBuilder/components/fieldLabelWrapper.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { VisualBuilderPostMessageEvents } from "../utils/types/postMessage.types
1717
import { ContentTypeIcon } from "./icons";
1818
import { ToolbarTooltip } from "./Tooltip";
1919
import { fetchEntryPermissionsAndStageDetails } from "../utils/fetchEntryPermissionsAndStageDetails";
20+
import { VariantIndicator } from "./VariantIndicator";
2021

2122
interface ReferenceParentMap {
2223
[entryUid: string]: {
@@ -246,6 +247,7 @@ function FieldLabelWrapperComponent(
246247
]
247248
)}
248249
>
250+
{currentField.isVariant ? <VariantIndicator /> : null}
249251
<ToolbarTooltip data={{contentTypeName: currentField.parentContentTypeName, referenceFieldName: currentField.referenceFieldName}} disabled={!currentField.isReference || isDropdownOpen}>
250252
<div
251253
className={classNames(
@@ -266,6 +268,15 @@ function FieldLabelWrapperComponent(
266268
"field-label-dropdown-open": isDropdownOpen,
267269
[visualBuilderStyles()["field-label-dropdown-open"]]:
268270
isDropdownOpen,
271+
},
272+
{
273+
"visual-builder__focused-toolbar--variant":
274+
currentField.isVariant,
275+
},
276+
{
277+
[visualBuilderStyles()[
278+
"visual-builder__focused-toolbar--variant"
279+
]]: currentField.isVariant,
269280
}
270281
)}
271282
onClick={() => setIsDropdownOpen((prev) => !prev)}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import React from "preact/compat";
22

3-
export function VariantIcon(): JSX.Element {
4-
return (
3+
export function VariantIcon(props: {
4+
size?: string;
5+
}): JSX.Element {
6+
return (
57
<svg
68
width="12"
79
height="12"
810
viewBox="0 0 12 12"
911
fill="none"
1012
xmlns="http://www.w3.org/2000/svg"
13+
style={{
14+
width: props.size,
15+
height: props.size,
16+
}}
1117
>
1218
<path
1319
fill-rule="evenodd"
1420
clip-rule="evenodd"
1521
d="M4.41131 0.157165C4.34585 0.0589769 4.23565 0 4.11765 0C3.99964 0 3.88944 0.0589769 3.82398 0.157165L0.0592764 5.80422C-0.0197588 5.92278 -0.0197588 6.07722 0.0592764 6.19578L3.82398 11.8428C3.88944 11.941 3.99964 12 4.11765 12C4.23565 12 4.34585 11.941 4.41131 11.8428L6 9.4598L7.58869 11.8428C7.65415 11.941 7.76435 12 7.88235 12C8.00036 12 8.11056 11.941 8.17602 11.8428L11.9407 6.19578C12.0198 6.07722 12.0198 5.92278 11.9407 5.80422L8.17602 0.157165C8.11056 0.0589769 8.00036 0 7.88235 0C7.76435 0 7.65415 0.0589769 7.58869 0.157165L6 2.5402L4.41131 0.157165ZM5.57582 3.17647L4.11765 0.989215L0.777124 6L4.11765 11.0108L5.57582 8.82353L3.82398 6.19578C3.74495 6.07722 3.74495 5.92278 3.82398 5.80422L5.57582 3.17647ZM6 8.18726L4.54183 6L6 3.81274L7.45817 6L6 8.18726ZM6.42418 8.82353L8.17602 6.19578C8.25505 6.07722 8.25505 5.92278 8.17602 5.80422L6.42418 3.17647L7.88235 0.989215L11.2229 6L7.88235 11.0108L6.42418 8.82353Z"
1622
fill="currentColor"
1723
/>
18-
</svg>
24+
</svg>
1925
);
2026
}

0 commit comments

Comments
 (0)