@contentstack/studio-react-editor 1.7.0 → 1.9.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 (62) hide show
  1. package/dist/components/AddIcon.js +18 -0
  2. package/dist/components/AddIcon.js.map +1 -0
  3. package/dist/components/BuildingIllustration.js +1 -1
  4. package/dist/components/BuildingIllustration.js.map +1 -1
  5. package/dist/components/EditableRenderer.js +10 -22
  6. package/dist/components/EditableRenderer.js.map +1 -1
  7. package/dist/components/Element.js +81 -38
  8. package/dist/components/Element.js.map +1 -1
  9. package/dist/components/PreviewRenderer.js +0 -19
  10. package/dist/components/PreviewRenderer.js.map +1 -1
  11. package/dist/components/Slot.js +5 -4
  12. package/dist/components/Slot.js.map +1 -1
  13. package/dist/components/WelcomeState.js +44 -27
  14. package/dist/components/WelcomeState.js.map +1 -1
  15. package/dist/components/elements/ConditionBlock.js +9 -35
  16. package/dist/components/elements/ConditionBlock.js.map +1 -1
  17. package/dist/components/elements/Repeater.js +1 -15
  18. package/dist/components/elements/Repeater.js.map +1 -1
  19. package/dist/components/elements/SectionSlot.js +68 -5
  20. package/dist/components/elements/SectionSlot.js.map +1 -1
  21. package/dist/components/styles.js +133 -8
  22. package/dist/components/styles.js.map +1 -1
  23. package/dist/contexts/providers/selected-node.provider.js +7 -1
  24. package/dist/contexts/providers/selected-node.provider.js.map +1 -1
  25. package/dist/hooks/use-active-node-path.hook.js +0 -19
  26. package/dist/hooks/use-active-node-path.hook.js.map +1 -1
  27. package/dist/hooks/use-condition-block-context.js +0 -20
  28. package/dist/hooks/use-condition-block-context.js.map +1 -1
  29. package/dist/hooks/use-design-preview.hook.js +0 -20
  30. package/dist/hooks/use-design-preview.hook.js.map +1 -1
  31. package/dist/hooks/use-preview-mode.hook.js +0 -20
  32. package/dist/hooks/use-preview-mode.hook.js.map +1 -1
  33. package/dist/hooks/use-register-section.hook.js +0 -1
  34. package/dist/hooks/use-register-section.hook.js.map +1 -1
  35. package/dist/hooks/use-renderer.hook.js +0 -20
  36. package/dist/hooks/use-renderer.hook.js.map +1 -1
  37. package/dist/hooks/use-repeater.hook.js +0 -20
  38. package/dist/hooks/use-repeater.hook.js.map +1 -1
  39. package/dist/hooks/use-should-show-design.hook.js +1 -20
  40. package/dist/hooks/use-should-show-design.hook.js.map +1 -1
  41. package/dist/hooks/use-slot-copy-color.hook.js +54 -0
  42. package/dist/hooks/use-slot-copy-color.hook.js.map +1 -0
  43. package/dist/hooks/use-spec-data-listener.hook.js +168 -24
  44. package/dist/hooks/use-spec-data-listener.hook.js.map +1 -1
  45. package/dist/utils/backdrop-watcher.util.js +79 -0
  46. package/dist/utils/backdrop-watcher.util.js.map +1 -0
  47. package/dist/utils/copy-color.util.js +300 -0
  48. package/dist/utils/copy-color.util.js.map +1 -0
  49. package/dist/utils/renderer.util.js +92 -1
  50. package/dist/utils/renderer.util.js.map +1 -1
  51. package/package.json +12 -14
  52. package/LICENSE +0 -21
  53. package/dist/components/elements/Symbol.js +0 -65
  54. package/dist/components/elements/Symbol.js.map +0 -1
  55. package/dist/contexts/providers/symbol-ui.provider.js +0 -88
  56. package/dist/contexts/providers/symbol-ui.provider.js.map +0 -1
  57. package/dist/hooks/use-register-symbol.hook.js +0 -54
  58. package/dist/hooks/use-register-symbol.hook.js.map +0 -1
  59. package/dist/hooks/use-symbol-events.hook.js +0 -45
  60. package/dist/hooks/use-symbol-events.hook.js.map +0 -1
  61. package/dist/hooks/use-symbol-ui-listener.hook.js +0 -17
  62. package/dist/hooks/use-symbol-ui-listener.hook.js.map +0 -1
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Colour for Studio chrome that renders inside the customer's page.
3
+ *
4
+ * The chrome has no surface of its own, so its colour cannot be fixed: the page
5
+ * behind it may be anything. It resolves the page colour and picks one of two
6
+ * modes — light mode for a light page, dark mode for a dark one. Each mode is a
7
+ * set of Venus tokens, so the chrome looks like a Studio component rather than
8
+ * something tinted to match the page.
9
+ *
10
+ * Two modes and nothing in between is deliberate. An earlier version tinted the
11
+ * ink towards the page's own hue family, which cost contrast — a tint always
12
+ * sits inside the extreme it is derived from — and stopped looking like Venus.
13
+ *
14
+ * Where even the right mode cannot carry the text — a mid-tone page, far from
15
+ * both ends of the lightness range, where no ink reaches the readable bar — the
16
+ * chrome takes that mode's surface instead. That is the only case a surface
17
+ * appears.
18
+ */
19
+ /**
20
+ * The Venus tokens each mode is built from:
21
+ * `--color-font-black` / `--color-font-white` for primary ink,
22
+ * `--color-font-text-secondary-text-tarmac-grey-n-700` /
23
+ * `--color-bg-colors-milkybar-white-n-5` for secondary,
24
+ * `--color-bg-colors-pure-white` / `--color-brand-black-base` for the surface,
25
+ * `--color-bg-colors-dolphin-grey-n-200` for the light surface's edge, and
26
+ * `--color-bg-colors-tulip-purple-p-5` for the emphasised surface in light mode.
27
+ * Dark mode has no Venus counterpart for that last one — Venus is a light-mode
28
+ * system — so it is brand purple at 25% over the dark surface, the strength at
29
+ * which the tint reads against a plain card without competing with the copy.
30
+ */
31
+ const STUDIO_CHROME_MODES = {
32
+ light: {
33
+ ink: "#222222",
34
+ secondary: "#475161",
35
+ surface: "#ffffff",
36
+ surfaceEdge: "#dde3ee",
37
+ emphasisSurface: "#f9f8ff",
38
+ },
39
+ dark: {
40
+ ink: "#ffffff",
41
+ secondary: "#f7f9fc",
42
+ surface: "#222222",
43
+ surfaceEdge: "rgba(255, 255, 255, 0.2)",
44
+ emphasisSurface: "#353153",
45
+ },
46
+ };
47
+ /** APCA minimum for a column of body text. Lc 90 is the preferred level. */
48
+ const LC_BODY_TEXT = 75;
49
+ /** APCA minimum for shorter content text that is not body copy — a label. */
50
+ const LC_CONTENT_TEXT = 60;
51
+ /**
52
+ * Page luminance either side of which the mode flips. Sits at the crossover
53
+ * where dark and light ink reach equal contrast against the page.
54
+ */
55
+ const PAGE_TONE_CROSSOVER = 0.18;
56
+ const HEX_PATTERN = /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i;
57
+ /**
58
+ * Matches the `rgb()` / `rgba()` serialisations `getComputedStyle` returns for
59
+ * `background-color`. Anything else (a modern `oklch()` / `color()` form, say)
60
+ * fails to parse and is treated as unresolvable, which drops the caller onto
61
+ * the treatment that needs no measurement rather than onto a guess.
62
+ */
63
+ const RGB_PATTERN = /^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:\s*[,/]\s*([\d.]+)(%?))?\s*\)$/i;
64
+ /** Parses `#rrggbb` into channels. Returns null for any other form. */
65
+ function hexToRgb(hex) {
66
+ const match = HEX_PATTERN.exec(hex.trim());
67
+ if (!match)
68
+ return null;
69
+ return {
70
+ r: parseInt(match[1], 16),
71
+ g: parseInt(match[2], 16),
72
+ b: parseInt(match[3], 16),
73
+ };
74
+ }
75
+ const TRANSPARENT = { rgb: { r: 0, g: 0, b: 0 }, alpha: 0 };
76
+ /**
77
+ * Normalises any colour the browser accepts by painting one pixel of it and
78
+ * reading the pixel back.
79
+ *
80
+ * `getComputedStyle` returns the modern colour syntaxes verbatim rather than
81
+ * resolving them to `rgb()` — `oklch()`, `oklab()`, `lab()`, `lch()` and
82
+ * `color()` all come back as written, and `color-mix()` computes to `oklab()`.
83
+ * Tailwind v4's default palette is oklch, so without this a large share of
84
+ * customer pages cannot be measured at all. The older trick of round-tripping
85
+ * through `ctx.fillStyle` no longer normalises anything; only the pixel does.
86
+ */
87
+ function paintedColor(value) {
88
+ if (typeof document === "undefined")
89
+ return null;
90
+ try {
91
+ const canvas = document.createElement("canvas");
92
+ const context = canvas.getContext?.("2d", {
93
+ willReadFrequently: true,
94
+ });
95
+ if (!context)
96
+ return null;
97
+ // Assigning an unparseable value to fillStyle is a silent no-op: it keeps
98
+ // whatever was there. Without this check an unreadable colour would come
99
+ // back as the previous fill — opaque black — which is a confident wrong
100
+ // answer where the honest one is "unknown". Probe with two different
101
+ // sentinels so a value that genuinely IS the sentinel is not mistaken for
102
+ // a rejection.
103
+ context.fillStyle = "#000000";
104
+ context.fillStyle = value;
105
+ const acceptedAsBlack = context.fillStyle !== "#000000";
106
+ context.fillStyle = "#ffffff";
107
+ context.fillStyle = value;
108
+ if (!acceptedAsBlack && context.fillStyle === "#ffffff")
109
+ return null;
110
+ context.clearRect(0, 0, 1, 1);
111
+ context.fillRect(0, 0, 1, 1);
112
+ const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data;
113
+ return { rgb: { r, g, b }, alpha: a / 255 };
114
+ }
115
+ catch {
116
+ // Canvas can be unavailable or refuse readback (privacy settings). Not
117
+ // knowing is a supported answer; guessing is not.
118
+ return null;
119
+ }
120
+ }
121
+ /**
122
+ * Parses a computed colour value into channels plus alpha.
123
+ *
124
+ * @returns null when the value cannot be read at all, which drops the caller
125
+ * onto a treatment that needs no measurement rather than onto a guess.
126
+ */
127
+ function parseCssColor(value) {
128
+ const trimmed = value.trim();
129
+ // An empty computed value means nothing is painted here, which is
130
+ // transparent — distinct from a value we could not read.
131
+ if (trimmed === "" || trimmed === "transparent")
132
+ return TRANSPARENT;
133
+ const match = RGB_PATTERN.exec(trimmed);
134
+ if (!match)
135
+ return paintedColor(trimmed);
136
+ const rawAlpha = match[4] === undefined ? 1 : Number(match[4]);
137
+ const alpha = match[5] === "%" ? rawAlpha / 100 : rawAlpha;
138
+ return {
139
+ rgb: { r: Number(match[1]), g: Number(match[2]), b: Number(match[3]) },
140
+ alpha: Number.isFinite(alpha) ? Math.min(Math.max(alpha, 0), 1) : 1,
141
+ };
142
+ }
143
+ /** WCAG relative luminance, 0 (black) to 1 (white). */
144
+ function relativeLuminance({ r, g, b }) {
145
+ const channel = (raw) => {
146
+ const srgb = raw / 255;
147
+ return srgb <= 0.04045
148
+ ? srgb / 12.92
149
+ : Math.pow((srgb + 0.055) / 1.055, 2.4);
150
+ };
151
+ return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
152
+ }
153
+ /* ---------------------------------------------------------------------------
154
+ * Perceptual contrast (APCA).
155
+ *
156
+ * WCAG 2's ratio is only perceptually accurate near the middle of the lightness
157
+ * range, which is exactly where this chrome keeps landing — a page that passes
158
+ * AA at 4.5:1 can still read as washed out. APCA holds across the range and
159
+ * scores body copy on its own scale, so it is what we design to; WCAG AA stays
160
+ * the compliance floor. Constants are SA98G, verbatim from the reference
161
+ * implementation (Myndex/apca-w3).
162
+ * ------------------------------------------------------------------------- */
163
+ const SA98G = {
164
+ mainTRC: 2.4,
165
+ sRco: 0.2126729,
166
+ sGco: 0.7151522,
167
+ sBco: 0.072175,
168
+ normBG: 0.56,
169
+ normTXT: 0.57,
170
+ revTXT: 0.62,
171
+ revBG: 0.65,
172
+ blkThrs: 0.022,
173
+ blkClmp: 1.414,
174
+ scaleBoW: 1.14,
175
+ scaleWoB: 1.14,
176
+ loBoWoffset: 0.027,
177
+ loWoBoffset: 0.027,
178
+ deltaYmin: 0.0005,
179
+ loClip: 0.1,
180
+ };
181
+ function screenLuminance({ r, g, b }) {
182
+ const channel = (raw) => Math.pow(raw / 255, SA98G.mainTRC);
183
+ return (SA98G.sRco * channel(r) + SA98G.sGco * channel(g) + SA98G.sBco * channel(b));
184
+ }
185
+ /**
186
+ * APCA lightness contrast (Lc) between text and its background, 0-106.
187
+ *
188
+ * Unlike a WCAG ratio this is polarity-aware: light text on dark needs more
189
+ * separation than dark text on light for the same perceived contrast.
190
+ */
191
+ function apcaContrast(text, background) {
192
+ const softClamp = (y) => y > SA98G.blkThrs ? y : y + Math.pow(SA98G.blkThrs - y, SA98G.blkClmp);
193
+ const textY = softClamp(screenLuminance(text));
194
+ const backgroundY = softClamp(screenLuminance(background));
195
+ if (Math.abs(backgroundY - textY) < SA98G.deltaYmin)
196
+ return 0;
197
+ let sapc;
198
+ let output;
199
+ if (backgroundY > textY) {
200
+ sapc =
201
+ (Math.pow(backgroundY, SA98G.normBG) - Math.pow(textY, SA98G.normTXT)) *
202
+ SA98G.scaleBoW;
203
+ output = sapc < SA98G.loClip ? 0 : sapc - SA98G.loBoWoffset;
204
+ }
205
+ else {
206
+ sapc =
207
+ (Math.pow(backgroundY, SA98G.revBG) - Math.pow(textY, SA98G.revTXT)) *
208
+ SA98G.scaleWoB;
209
+ output = sapc > -0.1 ? 0 : sapc + SA98G.loWoBoffset;
210
+ }
211
+ return Math.abs(output * 100);
212
+ }
213
+ /** Composites a translucent colour over an opaque one. */
214
+ function compositeOver(top, alpha, bottom) {
215
+ return {
216
+ r: top.r * alpha + bottom.r * (1 - alpha),
217
+ g: top.g * alpha + bottom.g * (1 - alpha),
218
+ b: top.b * alpha + bottom.b * (1 - alpha),
219
+ };
220
+ }
221
+ /**
222
+ * The colour a page shows where nothing paints a background: the viewport
223
+ * canvas is white in every browser unless the document sets otherwise.
224
+ */
225
+ const CANVAS_DEFAULT = { r: 255, g: 255, b: 255 };
226
+ /**
227
+ * Resolves the opaque page colour behind `element` by walking its ancestors and
228
+ * compositing their background colours until they add up to full opacity.
229
+ *
230
+ * @returns null when the answer cannot be known from computed styles — any
231
+ * ancestor painting a `background-image` (a gradient, photo or sprite) while
232
+ * the stack is still translucent, or a background colour in a form we cannot
233
+ * parse. Callers should fall back to a treatment that needs no measurement.
234
+ */
235
+ function resolveBackdropColor(element) {
236
+ if (typeof window === "undefined")
237
+ return null;
238
+ const layers = [];
239
+ let current = element;
240
+ let coverage = 0;
241
+ while (current && coverage < 1) {
242
+ const computed = window.getComputedStyle(current);
243
+ // A background-image paints above that element's background-colour, so
244
+ // whatever is underneath stops being knowable from computed styles.
245
+ if (computed.backgroundImage && computed.backgroundImage !== "none") {
246
+ return null;
247
+ }
248
+ const parsed = parseCssColor(computed.backgroundColor);
249
+ if (!parsed)
250
+ return null;
251
+ if (parsed.alpha > 0) {
252
+ layers.push(parsed);
253
+ coverage += parsed.alpha * (1 - coverage);
254
+ }
255
+ current = current.parentElement;
256
+ }
257
+ // Fold from the bottom layer up: the last one collected is the outermost.
258
+ let result = CANVAS_DEFAULT;
259
+ for (let index = layers.length - 1; index >= 0; index -= 1) {
260
+ result = compositeOver(layers[index].rgb, layers[index].alpha, result);
261
+ }
262
+ return result;
263
+ }
264
+ /** Which mode reads against a page: dark ink on a light page, and the reverse. */
265
+ function pickChromeMode(backdrop) {
266
+ return relativeLuminance(backdrop) >= PAGE_TONE_CROSSOVER ? "light" : "dark";
267
+ }
268
+ /**
269
+ * Whether a one-line label on this page needs a stroke around its glyphs.
270
+ *
271
+ * A card can take a surface where the ink runs out; a bare label sitting
272
+ * directly on the customer's page cannot, and on the mid-tone band the ink
273
+ * alone does not reach even the label bar. A stroke in the opposite mode's ink
274
+ * gives each glyph its own local polarity without painting a fill behind it,
275
+ * which is the treatment a filled chip was rejected for.
276
+ */
277
+ function needsStroke(mode, backdrop) {
278
+ const ink = hexToRgb(STUDIO_CHROME_MODES[mode].ink);
279
+ if (!ink)
280
+ return false;
281
+ return apcaContrast(ink, backdrop) < LC_CONTENT_TEXT;
282
+ }
283
+ /**
284
+ * Whether chrome on this page needs its mode's surface behind it.
285
+ *
286
+ * True only where the mode's own secondary ink cannot reach the body-text bar
287
+ * on the page itself. That is the mid-tone band: a mid grey sits far from both
288
+ * ends of the lightness range, so neither dark nor light ink separates from it
289
+ * enough to read. Everywhere else the chrome stays surfaceless, directly on the
290
+ * page.
291
+ */
292
+ function needsSurface(mode, backdrop) {
293
+ const secondary = hexToRgb(STUDIO_CHROME_MODES[mode].secondary);
294
+ if (!secondary)
295
+ return false;
296
+ return apcaContrast(secondary, backdrop) < LC_BODY_TEXT;
297
+ }
298
+
299
+ export { LC_BODY_TEXT, LC_CONTENT_TEXT, STUDIO_CHROME_MODES, apcaContrast, hexToRgb, needsStroke, needsSurface, parseCssColor, pickChromeMode, relativeLuminance, resolveBackdropColor };
300
+ //# sourceMappingURL=copy-color.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-color.util.js","sources":["../../src/utils/copy-color.util.ts"],"sourcesContent":["/**\n * Colour for Studio chrome that renders inside the customer's page.\n *\n * The chrome has no surface of its own, so its colour cannot be fixed: the page\n * behind it may be anything. It resolves the page colour and picks one of two\n * modes — light mode for a light page, dark mode for a dark one. Each mode is a\n * set of Venus tokens, so the chrome looks like a Studio component rather than\n * something tinted to match the page.\n *\n * Two modes and nothing in between is deliberate. An earlier version tinted the\n * ink towards the page's own hue family, which cost contrast — a tint always\n * sits inside the extreme it is derived from — and stopped looking like Venus.\n *\n * Where even the right mode cannot carry the text — a mid-tone page, far from\n * both ends of the lightness range, where no ink reaches the readable bar — the\n * chrome takes that mode's surface instead. That is the only case a surface\n * appears.\n */\n\n/** An opaque colour in sRGB, channels 0-255. */\nexport interface Rgb {\n r: number;\n g: number;\n b: number;\n}\n\n/** Light mode for a light page, dark mode for a dark one. */\nexport type StudioChromeMode = \"light\" | \"dark\";\n\n/**\n * The Venus tokens each mode is built from:\n * `--color-font-black` / `--color-font-white` for primary ink,\n * `--color-font-text-secondary-text-tarmac-grey-n-700` /\n * `--color-bg-colors-milkybar-white-n-5` for secondary,\n * `--color-bg-colors-pure-white` / `--color-brand-black-base` for the surface,\n * `--color-bg-colors-dolphin-grey-n-200` for the light surface's edge, and\n * `--color-bg-colors-tulip-purple-p-5` for the emphasised surface in light mode.\n * Dark mode has no Venus counterpart for that last one — Venus is a light-mode\n * system — so it is brand purple at 25% over the dark surface, the strength at\n * which the tint reads against a plain card without competing with the copy.\n */\nexport const STUDIO_CHROME_MODES = {\n light: {\n ink: \"#222222\",\n secondary: \"#475161\",\n surface: \"#ffffff\",\n surfaceEdge: \"#dde3ee\",\n emphasisSurface: \"#f9f8ff\",\n },\n dark: {\n ink: \"#ffffff\",\n secondary: \"#f7f9fc\",\n surface: \"#222222\",\n surfaceEdge: \"rgba(255, 255, 255, 0.2)\",\n emphasisSurface: \"#353153\",\n },\n} as const;\n\n/** WCAG AA for normal-size text — the compliance floor. */\nexport const AA_CONTRAST = 4.5;\n\n/** APCA minimum for a column of body text. Lc 90 is the preferred level. */\nexport const LC_BODY_TEXT = 75;\n\n/** APCA minimum for shorter content text that is not body copy — a label. */\nexport const LC_CONTENT_TEXT = 60;\n\n/**\n * Page luminance either side of which the mode flips. Sits at the crossover\n * where dark and light ink reach equal contrast against the page.\n */\nconst PAGE_TONE_CROSSOVER = 0.18;\n\nconst HEX_PATTERN = /^#([\\da-f]{2})([\\da-f]{2})([\\da-f]{2})$/i;\n\n/**\n * Matches the `rgb()` / `rgba()` serialisations `getComputedStyle` returns for\n * `background-color`. Anything else (a modern `oklch()` / `color()` form, say)\n * fails to parse and is treated as unresolvable, which drops the caller onto\n * the treatment that needs no measurement rather than onto a guess.\n */\nconst RGB_PATTERN =\n /^rgba?\\(\\s*([\\d.]+)[,\\s]+([\\d.]+)[,\\s]+([\\d.]+)(?:\\s*[,/]\\s*([\\d.]+)(%?))?\\s*\\)$/i;\n\n/** Parses `#rrggbb` into channels. Returns null for any other form. */\nexport function hexToRgb(hex: string): Rgb | null {\n const match = HEX_PATTERN.exec(hex.trim());\n if (!match) return null;\n return {\n r: parseInt(match[1], 16),\n g: parseInt(match[2], 16),\n b: parseInt(match[3], 16),\n };\n}\n\nconst TRANSPARENT = { rgb: { r: 0, g: 0, b: 0 }, alpha: 0 };\n\n/**\n * Normalises any colour the browser accepts by painting one pixel of it and\n * reading the pixel back.\n *\n * `getComputedStyle` returns the modern colour syntaxes verbatim rather than\n * resolving them to `rgb()` — `oklch()`, `oklab()`, `lab()`, `lch()` and\n * `color()` all come back as written, and `color-mix()` computes to `oklab()`.\n * Tailwind v4's default palette is oklch, so without this a large share of\n * customer pages cannot be measured at all. The older trick of round-tripping\n * through `ctx.fillStyle` no longer normalises anything; only the pixel does.\n */\nfunction paintedColor(value: string): { rgb: Rgb; alpha: number } | null {\n if (typeof document === \"undefined\") return null;\n try {\n const canvas = document.createElement(\"canvas\");\n const context = (canvas as HTMLCanvasElement).getContext?.(\"2d\", {\n willReadFrequently: true,\n });\n if (!context) return null;\n\n // Assigning an unparseable value to fillStyle is a silent no-op: it keeps\n // whatever was there. Without this check an unreadable colour would come\n // back as the previous fill — opaque black — which is a confident wrong\n // answer where the honest one is \"unknown\". Probe with two different\n // sentinels so a value that genuinely IS the sentinel is not mistaken for\n // a rejection.\n context.fillStyle = \"#000000\";\n context.fillStyle = value;\n const acceptedAsBlack = context.fillStyle !== \"#000000\";\n context.fillStyle = \"#ffffff\";\n context.fillStyle = value;\n if (!acceptedAsBlack && context.fillStyle === \"#ffffff\") return null;\n\n context.clearRect(0, 0, 1, 1);\n context.fillRect(0, 0, 1, 1);\n const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data;\n return { rgb: { r, g, b }, alpha: a / 255 };\n } catch {\n // Canvas can be unavailable or refuse readback (privacy settings). Not\n // knowing is a supported answer; guessing is not.\n return null;\n }\n}\n\n/**\n * Parses a computed colour value into channels plus alpha.\n *\n * @returns null when the value cannot be read at all, which drops the caller\n * onto a treatment that needs no measurement rather than onto a guess.\n */\nexport function parseCssColor(\n value: string,\n): { rgb: Rgb; alpha: number } | null {\n const trimmed = value.trim();\n // An empty computed value means nothing is painted here, which is\n // transparent — distinct from a value we could not read.\n if (trimmed === \"\" || trimmed === \"transparent\") return TRANSPARENT;\n\n const match = RGB_PATTERN.exec(trimmed);\n if (!match) return paintedColor(trimmed);\n\n const rawAlpha = match[4] === undefined ? 1 : Number(match[4]);\n const alpha = match[5] === \"%\" ? rawAlpha / 100 : rawAlpha;\n return {\n rgb: { r: Number(match[1]), g: Number(match[2]), b: Number(match[3]) },\n alpha: Number.isFinite(alpha) ? Math.min(Math.max(alpha, 0), 1) : 1,\n };\n}\n\n/** WCAG relative luminance, 0 (black) to 1 (white). */\nexport function relativeLuminance({ r, g, b }: Rgb): number {\n const channel = (raw: number): number => {\n const srgb = raw / 255;\n return srgb <= 0.04045\n ? srgb / 12.92\n : Math.pow((srgb + 0.055) / 1.055, 2.4);\n };\n return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);\n}\n\n/** WCAG contrast ratio between two opaque colours, 1 to 21. */\nexport function contrastRatio(a: Rgb, b: Rgb): number {\n const luminanceA = relativeLuminance(a);\n const luminanceB = relativeLuminance(b);\n const lighter = Math.max(luminanceA, luminanceB);\n const darker = Math.min(luminanceA, luminanceB);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\n/* ---------------------------------------------------------------------------\n * Perceptual contrast (APCA).\n *\n * WCAG 2's ratio is only perceptually accurate near the middle of the lightness\n * range, which is exactly where this chrome keeps landing — a page that passes\n * AA at 4.5:1 can still read as washed out. APCA holds across the range and\n * scores body copy on its own scale, so it is what we design to; WCAG AA stays\n * the compliance floor. Constants are SA98G, verbatim from the reference\n * implementation (Myndex/apca-w3).\n * ------------------------------------------------------------------------- */\n\nconst SA98G = {\n mainTRC: 2.4,\n sRco: 0.2126729,\n sGco: 0.7151522,\n sBco: 0.072175,\n normBG: 0.56,\n normTXT: 0.57,\n revTXT: 0.62,\n revBG: 0.65,\n blkThrs: 0.022,\n blkClmp: 1.414,\n scaleBoW: 1.14,\n scaleWoB: 1.14,\n loBoWoffset: 0.027,\n loWoBoffset: 0.027,\n deltaYmin: 0.0005,\n loClip: 0.1,\n};\n\nfunction screenLuminance({ r, g, b }: Rgb): number {\n const channel = (raw: number): number => Math.pow(raw / 255, SA98G.mainTRC);\n return (\n SA98G.sRco * channel(r) + SA98G.sGco * channel(g) + SA98G.sBco * channel(b)\n );\n}\n\n/**\n * APCA lightness contrast (Lc) between text and its background, 0-106.\n *\n * Unlike a WCAG ratio this is polarity-aware: light text on dark needs more\n * separation than dark text on light for the same perceived contrast.\n */\nexport function apcaContrast(text: Rgb, background: Rgb): number {\n const softClamp = (y: number): number =>\n y > SA98G.blkThrs ? y : y + Math.pow(SA98G.blkThrs - y, SA98G.blkClmp);\n const textY = softClamp(screenLuminance(text));\n const backgroundY = softClamp(screenLuminance(background));\n if (Math.abs(backgroundY - textY) < SA98G.deltaYmin) return 0;\n\n let sapc: number;\n let output: number;\n if (backgroundY > textY) {\n sapc =\n (Math.pow(backgroundY, SA98G.normBG) - Math.pow(textY, SA98G.normTXT)) *\n SA98G.scaleBoW;\n output = sapc < SA98G.loClip ? 0 : sapc - SA98G.loBoWoffset;\n } else {\n sapc =\n (Math.pow(backgroundY, SA98G.revBG) - Math.pow(textY, SA98G.revTXT)) *\n SA98G.scaleWoB;\n output = sapc > -SA98G.loClip ? 0 : sapc + SA98G.loWoBoffset;\n }\n return Math.abs(output * 100);\n}\n\n/** Composites a translucent colour over an opaque one. */\nfunction compositeOver(top: Rgb, alpha: number, bottom: Rgb): Rgb {\n return {\n r: top.r * alpha + bottom.r * (1 - alpha),\n g: top.g * alpha + bottom.g * (1 - alpha),\n b: top.b * alpha + bottom.b * (1 - alpha),\n };\n}\n\n/**\n * The colour a page shows where nothing paints a background: the viewport\n * canvas is white in every browser unless the document sets otherwise.\n */\nconst CANVAS_DEFAULT: Rgb = { r: 255, g: 255, b: 255 };\n\n/**\n * Resolves the opaque page colour behind `element` by walking its ancestors and\n * compositing their background colours until they add up to full opacity.\n *\n * @returns null when the answer cannot be known from computed styles — any\n * ancestor painting a `background-image` (a gradient, photo or sprite) while\n * the stack is still translucent, or a background colour in a form we cannot\n * parse. Callers should fall back to a treatment that needs no measurement.\n */\nexport function resolveBackdropColor(element: Element): Rgb | null {\n if (typeof window === \"undefined\") return null;\n\n const layers: Array<{ rgb: Rgb; alpha: number }> = [];\n let current: Element | null = element;\n let coverage = 0;\n\n while (current && coverage < 1) {\n const computed = window.getComputedStyle(current);\n\n // A background-image paints above that element's background-colour, so\n // whatever is underneath stops being knowable from computed styles.\n if (computed.backgroundImage && computed.backgroundImage !== \"none\") {\n return null;\n }\n\n const parsed = parseCssColor(computed.backgroundColor);\n if (!parsed) return null;\n\n if (parsed.alpha > 0) {\n layers.push(parsed);\n coverage += parsed.alpha * (1 - coverage);\n }\n current = current.parentElement;\n }\n\n // Fold from the bottom layer up: the last one collected is the outermost.\n let result = CANVAS_DEFAULT;\n for (let index = layers.length - 1; index >= 0; index -= 1) {\n result = compositeOver(layers[index].rgb, layers[index].alpha, result);\n }\n return result;\n}\n\n/** Which mode reads against a page: dark ink on a light page, and the reverse. */\nexport function pickChromeMode(backdrop: Rgb): StudioChromeMode {\n return relativeLuminance(backdrop) >= PAGE_TONE_CROSSOVER ? \"light\" : \"dark\";\n}\n\n/**\n * Whether a one-line label on this page needs a stroke around its glyphs.\n *\n * A card can take a surface where the ink runs out; a bare label sitting\n * directly on the customer's page cannot, and on the mid-tone band the ink\n * alone does not reach even the label bar. A stroke in the opposite mode's ink\n * gives each glyph its own local polarity without painting a fill behind it,\n * which is the treatment a filled chip was rejected for.\n */\nexport function needsStroke(mode: StudioChromeMode, backdrop: Rgb): boolean {\n const ink = hexToRgb(STUDIO_CHROME_MODES[mode].ink);\n if (!ink) return false;\n return apcaContrast(ink, backdrop) < LC_CONTENT_TEXT;\n}\n\n/**\n * Whether chrome on this page needs its mode's surface behind it.\n *\n * True only where the mode's own secondary ink cannot reach the body-text bar\n * on the page itself. That is the mid-tone band: a mid grey sits far from both\n * ends of the lightness range, so neither dark nor light ink separates from it\n * enough to read. Everywhere else the chrome stays surfaceless, directly on the\n * page.\n */\nexport function needsSurface(mode: StudioChromeMode, backdrop: Rgb): boolean {\n const secondary = hexToRgb(STUDIO_CHROME_MODES[mode].secondary);\n if (!secondary) return false;\n return apcaContrast(secondary, backdrop) < LC_BODY_TEXT;\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;AAiBG;AAYH;;;;;;;;;;;AAWG;AACI,MAAM,mBAAmB,GAAG;AACjC,IAAA,KAAK,EAAE;AACL,QAAA,GAAG,EAAE,SAAS;AACd,QAAA,SAAS,EAAE,SAAS;AACpB,QAAA,OAAO,EAAE,SAAS;AAClB,QAAA,WAAW,EAAE,SAAS;AACtB,QAAA,eAAe,EAAE,SAAS;AAC3B,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,SAAS;AACd,QAAA,SAAS,EAAE,SAAS;AACpB,QAAA,OAAO,EAAE,SAAS;AAClB,QAAA,WAAW,EAAE,0BAA0B;AACvC,QAAA,eAAe,EAAE,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,mBAAmB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;AACnD,IAAA,IAAI,CAAC,GAAG;AAAE,QAAA,OAAO,KAAK;IACtB,OAAO,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,eAAe;AACtD;AAEA;;;;;;;;AAQG;AACG,SAAU,YAAY,CAAC,IAAsB,EAAE,QAAa,EAAA;IAChE,MAAM,SAAS,GAAG,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC;AAC/D,IAAA,IAAI,CAAC,SAAS;AAAE,QAAA,OAAO,KAAK;IAC5B,OAAO,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,YAAY;AACzD;;;;"}
@@ -1,3 +1,7 @@
1
+ import { NODE_TO_PARENT } from '@contentstack/studio-client';
2
+ import { getConditionHint, getBindingFieldPath, uidToDisplayName } from '@contentstack/studio-internal';
3
+ import { INTERNAL_COMPONENTS_NAMES } from '@contentstack/studio-registry';
4
+
1
5
  const shouldRenderSlot = (componentRegistry, parent, nodes, isCompositionBeingEdited) => {
2
6
  if (!isCompositionBeingEdited)
3
7
  return false;
@@ -7,6 +11,93 @@ const shouldRenderSlot = (componentRegistry, parent, nodes, isCompositionBeingEd
7
11
  const isEmpty = nodes.length === 0;
8
12
  return isEmpty;
9
13
  };
14
+ /**
15
+ * The condition block whose contents the slot owned by `parent` stands in for —
16
+ * its **drop well** — or `undefined` when this slot is not a well.
17
+ *
18
+ * A condition block is `display: contents`, so it has no drop area of its own.
19
+ * The well is therefore the block's own slot while the block is empty, and the
20
+ * slot of the single container placed inside it once one has been (typically the
21
+ * Box auto-inserted for modular-block / reference repeaters). Those two are
22
+ * mutually exclusive in time: the moment the Box exists, the block's own slot is
23
+ * filled and stops rendering a placeholder.
24
+ *
25
+ * The lookup goes UP, not down — nothing is threaded from the block to the
26
+ * container. `NODE_TO_PARENT` is populated tree-wide by `refreshNodeWeakMaps`
27
+ * after every spec apply, so it is reliable at slot-render time.
28
+ *
29
+ * The rule is positional, not provenance-based: a Box the author dropped in
30
+ * themselves is treated exactly like the auto-inserted one, because its
31
+ * provenance is invisible to the author and should not change what the slot
32
+ * says. Depth stops at one hop — a well is a single slot, so a placeholder
33
+ * nested deeper is not standing in for the block's contents.
34
+ */
35
+ const getConditionWellBlock = (parent) => {
36
+ if (parent.type === INTERNAL_COMPONENTS_NAMES.CONDITION_BLOCK)
37
+ return parent;
38
+ const grandParent = NODE_TO_PARENT.get(parent);
39
+ if (grandParent?.type !== INTERNAL_COMPONENTS_NAMES.CONDITION_BLOCK)
40
+ return undefined;
41
+ // The block must hold exactly this one node. With two empty containers there
42
+ // is no single well, and printing the hint on both would be noise.
43
+ const blockChildren = Object.values(grandParent.slots || {}).flat();
44
+ if (blockChildren.length !== 1 || blockChildren[0] !== parent)
45
+ return undefined;
46
+ // And that node must itself be empty — once real content lands anywhere under
47
+ // the block, no slot beneath it is standing in for the block's contents.
48
+ if (Object.values(parent.slots || {}).flat().length > 0)
49
+ return undefined;
50
+ return grandParent;
51
+ };
52
+ /**
53
+ * Placeholder text for an empty slot, or `undefined` for the plain "Drop Here".
54
+ *
55
+ * Repeater and condition hints are mutually exclusive by construction — a node
56
+ * cannot be both — so they share the single `hint` channel and need no
57
+ * precedence rule between them.
58
+ */
59
+ const getSlotHint = (parent) => {
60
+ if (parent.type === INTERNAL_COMPONENTS_NAMES.REPEATER &&
61
+ parent.metadata?.repeaterBindingFieldType) {
62
+ return "It is recommended to drop a condition block inside the repeater to handle Modular Blocks & References.";
63
+ }
64
+ const block = getConditionWellBlock(parent);
65
+ if (!block)
66
+ return undefined;
67
+ // An `unsupported` hint means a condition IS set but cannot be described.
68
+ // "Drop Here" on its own is already a complete, correct message, so the well
69
+ // says nothing extra rather than guessing.
70
+ //
71
+ // `conditionDisplay` carries the display names resolved when the condition was
72
+ // authored. The helper falls back to the stored uids when it is absent, which
73
+ // is the permanent case for conditions written by the CLI or the API.
74
+ const hint = getConditionHint(block.metadata?.condition, block.metadata?.conditionDisplay, {
75
+ subject: getRepeaterFieldName(NODE_TO_PARENT.get(block)),
76
+ });
77
+ return hint?.kind === "info" ? `${hint.prefix} ${hint.value}` : undefined;
78
+ };
79
+ /**
80
+ * The field a Repeater iterates, as a display name — `hero_sections` → "Hero
81
+ * Sections".
82
+ *
83
+ * Recovers the subject of a condition whose own binding has collapsed into its
84
+ * value: a repeater-scoped condition's `path` is rewritten to the branch, but the
85
+ * Repeater it sits in still names the field. Used only as a fallback, so a name
86
+ * stamped at author time always wins.
87
+ *
88
+ * De-uid-ified deliberately, unlike a subject read from the condition's own
89
+ * binding. This is the same string the Repeater's own hint renders one row up in
90
+ * Layers ("Iterates Hero Sections"), so showing it raw here would make the two
91
+ * disagree about the same field.
92
+ */
93
+ const getRepeaterFieldName = (node) => {
94
+ if (node?.type !== INTERNAL_COMPONENTS_NAMES.REPEATER)
95
+ return undefined;
96
+ const binding = node.props?.items?.binding;
97
+ const path = getBindingFieldPath(binding);
98
+ const field = path?.split(".").pop();
99
+ return field ? uidToDisplayName(field) : undefined;
100
+ };
10
101
 
11
- export { shouldRenderSlot };
102
+ export { getConditionWellBlock, getSlotHint, shouldRenderSlot };
12
103
  //# sourceMappingURL=renderer.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.util.js","sources":["../../src/utils/renderer.util.ts"],"sourcesContent":["import type { Node } from \"@contentstack/studio-internal\";\nimport { ComponentRegistry } from \"@contentstack/studio-registry\";\nimport { ReactNode } from \"react\";\n\nexport const shouldRenderSlot = (\n componentRegistry: ComponentRegistry<(props?: any) => ReactNode>,\n parent: Node,\n nodes: Node[],\n isCompositionBeingEdited: boolean,\n) => {\n if (!isCompositionBeingEdited) return false;\n if (!componentRegistry?.hasComponent(parent)) {\n return false;\n }\n const isEmpty = nodes.length === 0;\n\n return isEmpty;\n};\n"],"names":[],"mappings":"AAIO,MAAM,gBAAgB,GAAG,CAC9B,iBAAgE,EAChE,MAAY,EACZ,KAAa,EACb,wBAAiC,KAC/B;AACF,IAAA,IAAI,CAAC,wBAAwB;AAAE,QAAA,OAAO,KAAK;IAC3C,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE;AAC5C,QAAA,OAAO,KAAK;IACd;AACA,IAAA,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC;AAElC,IAAA,OAAO,OAAO;AAChB;;;;"}
1
+ {"version":3,"file":"renderer.util.js","sources":["../../src/utils/renderer.util.ts"],"sourcesContent":["import { NODE_TO_PARENT } from \"@contentstack/studio-client\";\nimport type {\n Condition,\n ConditionDisplay,\n Node,\n} from \"@contentstack/studio-internal\";\nimport {\n getBindingFieldPath,\n getConditionHint,\n uidToDisplayName,\n} from \"@contentstack/studio-internal\";\nimport {\n ComponentRegistry,\n INTERNAL_COMPONENTS_NAMES,\n} from \"@contentstack/studio-registry\";\nimport { ReactNode } from \"react\";\n\nexport const shouldRenderSlot = (\n componentRegistry: ComponentRegistry<(props?: any) => ReactNode>,\n parent: Node,\n nodes: Node[],\n isCompositionBeingEdited: boolean,\n) => {\n if (!isCompositionBeingEdited) return false;\n if (!componentRegistry?.hasComponent(parent)) {\n return false;\n }\n const isEmpty = nodes.length === 0;\n\n return isEmpty;\n};\n\n/**\n * The condition block whose contents the slot owned by `parent` stands in for —\n * its **drop well** — or `undefined` when this slot is not a well.\n *\n * A condition block is `display: contents`, so it has no drop area of its own.\n * The well is therefore the block's own slot while the block is empty, and the\n * slot of the single container placed inside it once one has been (typically the\n * Box auto-inserted for modular-block / reference repeaters). Those two are\n * mutually exclusive in time: the moment the Box exists, the block's own slot is\n * filled and stops rendering a placeholder.\n *\n * The lookup goes UP, not down — nothing is threaded from the block to the\n * container. `NODE_TO_PARENT` is populated tree-wide by `refreshNodeWeakMaps`\n * after every spec apply, so it is reliable at slot-render time.\n *\n * The rule is positional, not provenance-based: a Box the author dropped in\n * themselves is treated exactly like the auto-inserted one, because its\n * provenance is invisible to the author and should not change what the slot\n * says. Depth stops at one hop — a well is a single slot, so a placeholder\n * nested deeper is not standing in for the block's contents.\n */\nexport const getConditionWellBlock = (parent: Node): Node | undefined => {\n if (parent.type === INTERNAL_COMPONENTS_NAMES.CONDITION_BLOCK) return parent;\n\n const grandParent = NODE_TO_PARENT.get(parent) as Node | undefined;\n if (grandParent?.type !== INTERNAL_COMPONENTS_NAMES.CONDITION_BLOCK)\n return undefined;\n\n // The block must hold exactly this one node. With two empty containers there\n // is no single well, and printing the hint on both would be noise.\n const blockChildren = Object.values(grandParent.slots || {}).flat();\n if (blockChildren.length !== 1 || blockChildren[0] !== parent)\n return undefined;\n\n // And that node must itself be empty — once real content lands anywhere under\n // the block, no slot beneath it is standing in for the block's contents.\n if (Object.values(parent.slots || {}).flat().length > 0) return undefined;\n\n return grandParent;\n};\n\n/**\n * Placeholder text for an empty slot, or `undefined` for the plain \"Drop Here\".\n *\n * Repeater and condition hints are mutually exclusive by construction — a node\n * cannot be both — so they share the single `hint` channel and need no\n * precedence rule between them.\n */\nexport const getSlotHint = (parent: Node): string | undefined => {\n if (\n parent.type === INTERNAL_COMPONENTS_NAMES.REPEATER &&\n parent.metadata?.repeaterBindingFieldType\n ) {\n return \"It is recommended to drop a condition block inside the repeater to handle Modular Blocks & References.\";\n }\n\n const block = getConditionWellBlock(parent);\n if (!block) return undefined;\n\n // An `unsupported` hint means a condition IS set but cannot be described.\n // \"Drop Here\" on its own is already a complete, correct message, so the well\n // says nothing extra rather than guessing.\n //\n // `conditionDisplay` carries the display names resolved when the condition was\n // authored. The helper falls back to the stored uids when it is absent, which\n // is the permanent case for conditions written by the CLI or the API.\n const hint = getConditionHint(\n block.metadata?.condition as Condition | undefined,\n block.metadata?.conditionDisplay as ConditionDisplay | undefined,\n {\n subject: getRepeaterFieldName(\n NODE_TO_PARENT.get(block) as Node | undefined,\n ),\n },\n );\n return hint?.kind === \"info\" ? `${hint.prefix} ${hint.value}` : undefined;\n};\n\n/**\n * The field a Repeater iterates, as a display name — `hero_sections` → \"Hero\n * Sections\".\n *\n * Recovers the subject of a condition whose own binding has collapsed into its\n * value: a repeater-scoped condition's `path` is rewritten to the branch, but the\n * Repeater it sits in still names the field. Used only as a fallback, so a name\n * stamped at author time always wins.\n *\n * De-uid-ified deliberately, unlike a subject read from the condition's own\n * binding. This is the same string the Repeater's own hint renders one row up in\n * Layers (\"Iterates Hero Sections\"), so showing it raw here would make the two\n * disagree about the same field.\n */\nconst getRepeaterFieldName = (node?: Node): string | undefined => {\n if (node?.type !== INTERNAL_COMPONENTS_NAMES.REPEATER) return undefined;\n const binding = (node.props?.items as { binding?: any } | undefined)?.binding;\n const path = getBindingFieldPath(binding);\n const field = path?.split(\".\").pop();\n return field ? uidToDisplayName(field) : undefined;\n};\n"],"names":[],"mappings":";;;;AAiBO,MAAM,gBAAgB,GAAG,CAC9B,iBAAgE,EAChE,MAAY,EACZ,KAAa,EACb,wBAAiC,KAC/B;AACF,IAAA,IAAI,CAAC,wBAAwB;AAAE,QAAA,OAAO,KAAK;IAC3C,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE;AAC5C,QAAA,OAAO,KAAK;IACd;AACA,IAAA,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC;AAElC,IAAA,OAAO,OAAO;AAChB;AAEA;;;;;;;;;;;;;;;;;;;;AAoBG;AACI,MAAM,qBAAqB,GAAG,CAAC,MAAY,KAAsB;AACtE,IAAA,IAAI,MAAM,CAAC,IAAI,KAAK,yBAAyB,CAAC,eAAe;AAAE,QAAA,OAAO,MAAM;IAE5E,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAqB;AAClE,IAAA,IAAI,WAAW,EAAE,IAAI,KAAK,yBAAyB,CAAC,eAAe;AACjE,QAAA,OAAO,SAAS;;;AAIlB,IAAA,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;IACnE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B,CAAC,OAAO,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE;AACpC,IAAA,OAAO,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,SAAS;AACpD,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/studio-react-editor",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Contains all logic of editing for react based environment",
5
5
  "author": "RavenColEvol <ravilamkoti@gmail.com>",
6
6
  "homepage": "https://github.com/contentstack/composable-studio-sdk#readme",
@@ -14,10 +14,9 @@
14
14
  ],
15
15
  "exports": {
16
16
  ".": {
17
- "import": {
18
- "types": "./dist/index.d.ts",
19
- "default": "./dist/index.js"
20
- }
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "default": "./dist/index.js"
21
20
  }
22
21
  },
23
22
  "repository": {
@@ -39,7 +38,7 @@
39
38
  "react-dom": "^18.0.0 || ^19.0.0"
40
39
  },
41
40
  "devDependencies": {
42
- "@contentstack/common-config": "^1.2.2",
41
+ "@contentstack/common-config": "^1.2.4",
43
42
  "@rollup/plugin-commonjs": "^28.0.6",
44
43
  "@rollup/plugin-node-resolve": "^16.0.1",
45
44
  "@rollup/plugin-terser": "^1.0.0",
@@ -59,17 +58,16 @@
59
58
  "typescript": "^5.2.2"
60
59
  },
61
60
  "dependencies": {
62
- "@contentstack/studio-client": "^3.0.0",
63
- "@contentstack/studio-core": "^1.4.0",
64
- "@contentstack/studio-internal": "^1.5.0",
65
- "@contentstack/studio-messenger": "^3.0.0",
66
- "@contentstack/studio-react-components": "^1.9.0",
67
- "@contentstack/studio-registry": "^1.8.0",
61
+ "@contentstack/studio-client": "^3.2.0",
62
+ "@contentstack/studio-core": "^1.4.2",
63
+ "@contentstack/studio-internal": "^1.7.0",
64
+ "@contentstack/studio-messenger": "^3.1.1",
65
+ "@contentstack/studio-react-components": "^1.10.1",
66
+ "@contentstack/studio-registry": "^1.10.0",
68
67
  "classnames": "^2.5.1",
69
68
  "goober": "^2.1.16",
70
69
  "immer": "^10.1.1",
71
70
  "lodash-es": "^4.18.1",
72
71
  "react-error-boundary": "^6.0.0"
73
- },
74
- "gitHead": "0a4e62965622cd47c743978ebdcda4f74515fc6e"
72
+ }
75
73
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Contentstack
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,65 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { DataCtxProvider } from '@contentstack/studio-react-components/contexts';
3
- import { useData } from '@contentstack/studio-react-components/hooks';
4
- import { DATA_SOURCES } from '@contentstack/studio-registry';
5
- import { useMemo } from 'react';
6
- import '@contentstack/studio-client';
7
- import '../../hooks/use-edit-context-listener.hook.js';
8
- import '@contentstack/studio-messenger';
9
- import '@contentstack/studio-internal';
10
- import '@contentstack/studio-core';
11
- import '@contentstack/studio-react-components/basic-components';
12
- import 'goober';
13
- import { PreviewRenderer } from '../PreviewRenderer.js';
14
- import '../../contexts/providers/section-mode.provider.js';
15
- import '../../contexts/providers/renderer.provider.js';
16
- import '../../contexts/providers/edit-context.provider.js';
17
- import '../../contexts/providers/active-node.provider.js';
18
- import 'immer';
19
- import '../../contexts/providers/use-design-preview.provider.js';
20
- import '../../contexts/providers/use-repeater.provider.js';
21
- import '../../contexts/providers/use-condition-block.provider.js';
22
- import '../../contexts/providers/preview-mode.provider.js';
23
- import { useSymbolUIListener } from '../../hooks/use-symbol-ui-listener.hook.js';
24
-
25
- function EditSymbolRenderer({ ui, studioAttributes, }) {
26
- return (jsx("div", { ...studioAttributes, style: { display: "contents" }, children: ui }));
27
- }
28
- function ViewOnlySymbolRenderer({ symbolUID, spec, studioAttributes, }) {
29
- const activeSpec = useSymbolUIListener(spec, symbolUID);
30
- const data = useData();
31
- // This was required as two nested symbols were added because of this this component itself was rendered for type symbol and again it was rendering it for same json
32
- const activeSpecWithoutSymbolWrapper = useMemo(() => {
33
- const ui = activeSpec.ui;
34
- const uiWithFragment = {
35
- ...ui,
36
- type: "fragment",
37
- slots: ui.slots,
38
- };
39
- return {
40
- ...activeSpec,
41
- data,
42
- ui: uiWithFragment,
43
- };
44
- }, [activeSpec, data]);
45
- return (jsx("div", { ...studioAttributes, style: { display: "contents" }, children: jsx(PreviewRenderer, { spec: activeSpecWithoutSymbolWrapper }) }));
46
- }
47
- function WithSymbolPropsData(props) {
48
- const data = useData();
49
- // Can't memoize it because data doesn't change when symbol changes
50
- const dataWithSymbol = {
51
- ...data,
52
- [DATA_SOURCES.SYMBOL_PROPS]: {
53
- ...(data[DATA_SOURCES.SYMBOL_PROPS] || {}),
54
- ...(props.symbol_props || {}),
55
- },
56
- };
57
- return (jsx(DataCtxProvider, { value: dataWithSymbol, children: props.children }));
58
- }
59
- function Symbol(props) {
60
- const isEditing = props.symbol_internal_props?.isEditing;
61
- return (jsx(WithSymbolPropsData, { ...props, children: !isEditing ? (jsx(ViewOnlySymbolRenderer, { ...props })) : (jsx(EditSymbolRenderer, { ...props })) }));
62
- }
63
-
64
- export { EditSymbolRenderer, Symbol, ViewOnlySymbolRenderer };
65
- //# sourceMappingURL=Symbol.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Symbol.js","sources":["../../../src/components/elements/Symbol.tsx"],"sourcesContent":["/**\n * Symbol component will be used to render when a symbol is in edit mode.\n * @param props:\n * @returns\n */\n\nimport { StudioSpec } from \"@contentstack/studio-client\";\nimport { DataCtxProvider } from \"@contentstack/studio-react-components/contexts\";\nimport { useData } from \"@contentstack/studio-react-components/hooks\";\nimport { DATA_SOURCES } from \"@contentstack/studio-registry\";\nimport { useMemo } from \"react\";\nimport { useSymbolUIListener } from \"../../hooks\";\nimport { PreviewRenderer } from \"../PreviewRenderer\";\n\n/*\n * SymbolEditRenderer is used by the renderer when symbol is in edit mode\n */\ninterface EditSymbolRendererProps {\n ui: React.ReactElement;\n [key: string]: any;\n}\n\nexport function EditSymbolRenderer({\n ui,\n studioAttributes,\n}: EditSymbolRendererProps) {\n return (\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n {ui}\n </div>\n );\n}\n\n/*\n * SymbolRenderer is used by the renderer when symbol is in view mode\n */\ninterface ViewOnlySymbolRendererProps {\n ui: null;\n spec: Omit<StudioSpec, \"compositionEntry\">;\n symbolUID: string;\n studioAttributes: Record<string, any>;\n [key: string]: any;\n}\n\nexport function ViewOnlySymbolRenderer({\n symbolUID,\n spec,\n studioAttributes,\n}: ViewOnlySymbolRendererProps) {\n const activeSpec = useSymbolUIListener(spec, symbolUID);\n const data = useData();\n // This was required as two nested symbols were added because of this this component itself was rendered for type symbol and again it was rendering it for same json\n const activeSpecWithoutSymbolWrapper = useMemo(() => {\n const ui = activeSpec.ui;\n const uiWithFragment = {\n ...ui,\n type: \"fragment\",\n slots: ui.slots,\n };\n return {\n ...activeSpec,\n data,\n ui: uiWithFragment,\n };\n }, [activeSpec, data]);\n return (\n <div {...studioAttributes} style={{ display: \"contents\" }}>\n <PreviewRenderer spec={activeSpecWithoutSymbolWrapper} />\n </div>\n );\n}\n\ntype SymbolProps = ViewOnlySymbolRendererProps | EditSymbolRendererProps;\n\nfunction WithSymbolPropsData(props: SymbolProps) {\n const data = useData();\n // Can't memoize it because data doesn't change when symbol changes\n const dataWithSymbol = {\n ...data,\n [DATA_SOURCES.SYMBOL_PROPS]: {\n ...(data[DATA_SOURCES.SYMBOL_PROPS] || {}),\n ...(props.symbol_props || {}),\n },\n };\n return (\n <DataCtxProvider value={dataWithSymbol}>{props.children}</DataCtxProvider>\n );\n}\nexport function Symbol(props: SymbolProps) {\n const isEditing = props.symbol_internal_props?.isEditing;\n return (\n <WithSymbolPropsData {...props}>\n {!isEditing ? (\n <ViewOnlySymbolRenderer {...(props as ViewOnlySymbolRendererProps)} />\n ) : (\n <EditSymbolRenderer {...(props as EditSymbolRendererProps)} />\n )}\n </WithSymbolPropsData>\n );\n}\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;SAsBgB,kBAAkB,CAAC,EACjC,EAAE,EACF,gBAAgB,GACQ,EAAA;AACxB,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,gBAAgB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAA,QAAA,EACtD,EAAE,EAAA,CACC;AAEV;AAaM,SAAU,sBAAsB,CAAC,EACrC,SAAS,EACT,IAAI,EACJ,gBAAgB,GACY,EAAA;IAC5B,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,EAAE,SAAS,CAAC;AACvD,IAAA,MAAM,IAAI,GAAG,OAAO,EAAE;;AAEtB,IAAA,MAAM,8BAA8B,GAAG,OAAO,CAAC,MAAK;AAClD,QAAA,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE;AACxB,QAAA,MAAM,cAAc,GAAG;AACrB,YAAA,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