@se-studio/core-ui 1.24.2 → 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 +14 -0
- package/CMS_INFRASTRUCTURE.md +1 -1
- package/dist/components/HtmlComponent.d.ts.map +1 -1
- package/dist/components/HtmlComponent.js +2 -5
- package/dist/components/HtmlComponent.js.map +1 -1
- package/dist/utils/wrapHtmlComponentJs.d.ts +10 -0
- package/dist/utils/wrapHtmlComponentJs.d.ts.map +1 -0
- package/dist/utils/wrapHtmlComponentJs.js +12 -0
- package/dist/utils/wrapHtmlComponentJs.js.map +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
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
|
+
|
|
9
|
+
## 1.24.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [f6a7b89]
|
|
14
|
+
- @se-studio/core-data-types@1.12.0
|
|
15
|
+
- @se-studio/contentful-rest-api@1.24.0
|
|
16
|
+
|
|
3
17
|
## 1.24.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/CMS_INFRASTRUCTURE.md
CHANGED
|
@@ -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;
|
|
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
|
-
|
|
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,S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C5C,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
|
+
"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",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"mustache": "4.2.0",
|
|
85
85
|
"server-only": "0.0.1",
|
|
86
86
|
"tailwind-merge": "^3.6.0",
|
|
87
|
-
"@se-studio/contentful-rest-api": "1.
|
|
88
|
-
"@se-studio/core-data-types": "1.
|
|
87
|
+
"@se-studio/contentful-rest-api": "1.24.0",
|
|
88
|
+
"@se-studio/core-data-types": "1.12.0"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@biomejs/biome": "^2.5.5",
|