@se-studio/core-ui 1.24.3 → 1.24.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @se-studio/core-ui
2
2
 
3
+ ## 1.24.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 2c479e7: Wrap HtmlComponent customJs in an IIFE so `hcRoot` is per-instance. Two HtmlComponents with scripts on the same page no longer throw `Identifier 'hcRoot' has already been declared`.
8
+
3
9
  ## 1.24.3
4
10
 
5
11
  ### Patch Changes
@@ -144,7 +144,7 @@ export function PageRenderer({ page }) {
144
144
 
145
145
  ### HtmlComponent entries
146
146
 
147
- Contentful **HTML component** entries (`type: 'HtmlComponent'`) render through `HtmlComponent` inside `CmsContent` and `CmsEmbeddedContent`. Optional config:
147
+ Contentful **HTML component** entries (`type: 'HtmlComponent'`) render through `HtmlComponent` inside `CmsContent` and `CmsEmbeddedContent`. `customJs` runs inside an IIFE with a per-instance `hcRoot` (safe to place more than one scripted HtmlComponent on a page). Optional config:
148
148
 
149
149
  - **`htmlComponentFullWidthClassName`** — Tailwind (or other) classes applied when the entry has `fullWidth: true`. If unset, a built-in viewport-breakout default is used; override per project to match your grid.
150
150
 
@@ -1 +1 @@
1
- {"version":3,"file":"HtmlComponent.d.ts","sourceRoot":"","sources":["../../src/components/HtmlComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAKrE,0FAA0F;AAC1F,eAAO,MAAM,sCAAsC,8DACU,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG,kBAAkB,GAAG;IACpD,mHAAmH;IACnH,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kFAAkF;IAClF,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,EAC5B,EAAE,EACF,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,0BAA0B,GAC3B,EAAE,kBAAkB,+BAiCpB"}
1
+ {"version":3,"file":"HtmlComponent.d.ts","sourceRoot":"","sources":["../../src/components/HtmlComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAMrE,0FAA0F;AAC1F,eAAO,MAAM,sCAAsC,8DACU,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG,kBAAkB,GAAG;IACpD,mHAAmH;IACnH,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kFAAkF;IAClF,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,EAC5B,EAAE,EACF,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,0BAA0B,GAC3B,EAAE,kBAAkB,+BA6BpB"}
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn } from '../utils/cn';
3
3
  import { scopeCss } from '../utils/scopeCss';
4
+ import { wrapHtmlComponentJs } from '../utils/wrapHtmlComponentJs';
4
5
  import { HtmlComponentScript } from './HtmlComponentScript';
5
6
  /** Default Tailwind breakout when `fullWidth` is true and no renderer override is set. */
6
7
  export const defaultHtmlComponentFullWidthClassName = 'relative left-1/2 w-screen max-w-[100vw] -translate-x-1/2';
@@ -17,11 +18,7 @@ export const defaultHtmlComponentFullWidthClassName = 'relative left-1/2 w-scree
17
18
  export function HtmlComponent({ id, rawHtml, customCss, customJs, fullWidth, scriptStrategy, loadScriptOnce, flowPositionIndex, fullWidthBreakoutClassName, }) {
18
19
  const scopedCss = customCss ? scopeCss(customCss, id) : undefined;
19
20
  const scriptId = loadScriptOnce ? `hc-${id}` : `hc-${id}-${flowPositionIndex}`;
20
- // Prepend a scoped root variable so authors can write `hcRoot.querySelector(...)` instead of
21
- // `document.querySelector('[data-hc-id]')` which would match the first component on the page.
22
- const scopedJs = customJs
23
- ? `const hcRoot = document.querySelector('[data-hc-id="${id}"]');\n${customJs}`
24
- : undefined;
21
+ const scopedJs = customJs ? wrapHtmlComponentJs(id, customJs) : undefined;
25
22
  let breakout;
26
23
  if (fullWidth) {
27
24
  if (fullWidthBreakoutClassName !== undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"HtmlComponent.js","sourceRoot":"","sources":["../../src/components/HtmlComponent.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,0FAA0F;AAC1F,MAAM,CAAC,MAAM,sCAAsC,GACjD,2DAA2D,CAAC;AAS9D;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,EAAE,EACF,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,EACT,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,0BAA0B,GACP;IACnB,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,MAAM,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,iBAAiB,EAAE,CAAC;IAC/E,6FAA6F;IAC7F,8FAA8F;IAC9F,MAAM,QAAQ,GAAG,QAAQ;QACvB,CAAC,CAAC,uDAAuD,EAAE,UAAU,QAAQ,EAAE;QAC/E,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,QAA4B,CAAC;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,IA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AAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,MAAM,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,iBAAiB,EAAE,CAAC;IAC/E,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1E,IAAI,QAA4B,CAAC;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,0BAA0B,KAAK,SAAS,EAAE,CAAC;YAC7C,MAAM,CAAC,GAAG,0BAA0B,CAAC,IAAI,EAAE,CAAC;YAC5C,QAAQ,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,0BAA0B,CAAC;QAC/D,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,sCAAsC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,CACL,6BAAiB,EAAE,uBAAqB,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,aACxF,SAAS,IAAI,0BAAQ,SAAS,GAAS,EAExC,cAAK,uBAAuB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAI,EACpD,QAAQ,IAAI,CACX,KAAC,mBAAmB,IAClB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,QAAQ,GAClB,CACH,IACG,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Wraps HtmlComponent `customJs` so `hcRoot` is function-scoped.
3
+ *
4
+ * `@se-studio/core-ui` prepends `const hcRoot = …` so authors can query this
5
+ * instance. Inline `next/script` payloads on one page share a JS realm, so a
6
+ * second top-level `const hcRoot` throws and the later script never runs.
7
+ * An IIFE keeps the documented `hcRoot` name without colliding.
8
+ */
9
+ export declare function wrapHtmlComponentJs(id: string, customJs: string): string;
10
+ //# sourceMappingURL=wrapHtmlComponentJs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapHtmlComponentJs.d.ts","sourceRoot":"","sources":["../../src/utils/wrapHtmlComponentJs.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Wraps HtmlComponent `customJs` so `hcRoot` is function-scoped.
3
+ *
4
+ * `@se-studio/core-ui` prepends `const hcRoot = …` so authors can query this
5
+ * instance. Inline `next/script` payloads on one page share a JS realm, so a
6
+ * second top-level `const hcRoot` throws and the later script never runs.
7
+ * An IIFE keeps the documented `hcRoot` name without colliding.
8
+ */
9
+ export function wrapHtmlComponentJs(id, customJs) {
10
+ return `(function () {\n const hcRoot = document.querySelector('[data-hc-id="' + ${JSON.stringify(id)} + '"]');\n${customJs}\n})();`;
11
+ }
12
+ //# sourceMappingURL=wrapHtmlComponentJs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapHtmlComponentJs.js","sourceRoot":"","sources":["../../src/utils/wrapHtmlComponentJs.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAU,EAAE,QAAgB;IAC9D,OAAO,6EAA6E,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,cAAc,QAAQ,SAAS,CAAC;AACxI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/core-ui",
3
- "version": "1.24.3",
3
+ "version": "1.24.4",
4
4
  "description": "Shared React UI component library with Tailwind CSS v4 for SE Studio applications",
5
5
  "repository": {
6
6
  "type": "git",