@scania/tegel-react 1.49.2-modal-warn-fix-beta.0 → 1.50.0-dev-test-beta.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.
|
@@ -82,7 +82,7 @@ import { TdsTextarea as TdsTextareaElement, defineCustomElement as defineTdsText
|
|
|
82
82
|
import { TdsToast as TdsToastElement, defineCustomElement as defineTdsToast } from "@scania/tegel/dist/components/tds-toast.js";
|
|
83
83
|
import { TdsToggle as TdsToggleElement, defineCustomElement as defineTdsToggle } from "@scania/tegel/dist/components/tds-toggle.js";
|
|
84
84
|
import { TdsTooltip as TdsTooltipElement, defineCustomElement as defineTdsTooltip } from "@scania/tegel/dist/components/tds-tooltip.js";
|
|
85
|
-
import { createComponent } from '
|
|
85
|
+
import { createComponent } from '../../runtime';
|
|
86
86
|
import React from 'react';
|
|
87
87
|
export const TdsAccordion = /*@__PURE__*/ createComponent({
|
|
88
88
|
tagName: 'tds-accordion',
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom runtime wrapper for @stencil/react-output-target.
|
|
3
|
+
*
|
|
4
|
+
* In JSDOM (vitest / jest), Stencil's lazy-loaded property-to-attribute
|
|
5
|
+
* reflection never fires, so props set as JS properties via @lit/react's
|
|
6
|
+
* createComponent are invisible to getAttribute(). This wrapper detects
|
|
7
|
+
* JSDOM and adds a useLayoutEffect that explicitly syncs primitive props
|
|
8
|
+
* to DOM attributes. In real browsers, the original component is returned
|
|
9
|
+
* unchanged — zero runtime cost.
|
|
10
|
+
*/
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
import { createComponent as litCreateComponent } from '@lit/react';
|
|
23
|
+
import React from 'react';
|
|
24
|
+
// ---------- JSDOM detection ----------
|
|
25
|
+
const isJsdom = typeof navigator !== 'undefined' && /jsdom/i.test(navigator.userAgent);
|
|
26
|
+
// ---------- Attribute helpers ----------
|
|
27
|
+
const reservedProps = new Set(['children', 'localName', 'ref', 'style', 'className']);
|
|
28
|
+
function camelToDash(str) {
|
|
29
|
+
return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
30
|
+
}
|
|
31
|
+
function syncAttribute(node, name, value) {
|
|
32
|
+
const attrName = camelToDash(name);
|
|
33
|
+
if (typeof value === 'string') {
|
|
34
|
+
node.setAttribute(attrName, value);
|
|
35
|
+
}
|
|
36
|
+
else if (typeof value === 'number') {
|
|
37
|
+
node.setAttribute(attrName, String(value));
|
|
38
|
+
}
|
|
39
|
+
else if (typeof value === 'boolean') {
|
|
40
|
+
if (value) {
|
|
41
|
+
node.setAttribute(attrName, '');
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
node.removeAttribute(attrName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (value === undefined || value === null) {
|
|
48
|
+
node.removeAttribute(attrName);
|
|
49
|
+
}
|
|
50
|
+
// Objects, arrays, functions — not serializable, skip.
|
|
51
|
+
}
|
|
52
|
+
export const createComponent = (_a) => {
|
|
53
|
+
var _b;
|
|
54
|
+
var { defineCustomElement, tagName, transformTag } = _a, rest = __rest(_a, ["defineCustomElement", "tagName", "transformTag"]);
|
|
55
|
+
if (defineCustomElement !== undefined) {
|
|
56
|
+
defineCustomElement();
|
|
57
|
+
}
|
|
58
|
+
const resolvedTagName = transformTag ? transformTag(tagName) : tagName;
|
|
59
|
+
const OriginalComponent = litCreateComponent(Object.assign(Object.assign({}, rest), { tagName: resolvedTagName }));
|
|
60
|
+
// In real browsers Stencil's proxy handles reflection — return as-is.
|
|
61
|
+
if (!isJsdom) {
|
|
62
|
+
return OriginalComponent;
|
|
63
|
+
}
|
|
64
|
+
// --- JSDOM wrapper ---
|
|
65
|
+
const { elementClass, events } = rest;
|
|
66
|
+
const eventKeys = new Set(Object.keys(events !== null && events !== void 0 ? events : {}));
|
|
67
|
+
const WrappedComponent = React.forwardRef((props, ref) => {
|
|
68
|
+
const innerRef = React.useRef(null);
|
|
69
|
+
// Sync primitive props as DOM attributes after every render.
|
|
70
|
+
React.useLayoutEffect(() => {
|
|
71
|
+
const el = innerRef.current;
|
|
72
|
+
if (!el)
|
|
73
|
+
return;
|
|
74
|
+
for (const [key, value] of Object.entries(props)) {
|
|
75
|
+
if (reservedProps.has(key))
|
|
76
|
+
continue;
|
|
77
|
+
if (eventKeys.has(key))
|
|
78
|
+
continue;
|
|
79
|
+
if (typeof value === 'function')
|
|
80
|
+
continue;
|
|
81
|
+
// Only sync props that belong to the custom element, not generic
|
|
82
|
+
// HTML attributes (which React already handles).
|
|
83
|
+
if (key in elementClass.prototype && !(key in HTMLElement.prototype)) {
|
|
84
|
+
syncAttribute(el, key, value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const mergedRef = React.useCallback((node) => {
|
|
89
|
+
innerRef.current = node;
|
|
90
|
+
if (typeof ref === 'function') {
|
|
91
|
+
ref(node);
|
|
92
|
+
}
|
|
93
|
+
else if (ref) {
|
|
94
|
+
ref.current = node;
|
|
95
|
+
}
|
|
96
|
+
}, [ref]);
|
|
97
|
+
return React.createElement(OriginalComponent, Object.assign(Object.assign({}, props), { ref: mergedRef }));
|
|
98
|
+
});
|
|
99
|
+
WrappedComponent.displayName = (_b = OriginalComponent.displayName) !== null && _b !== void 0 ? _b : elementClass.name;
|
|
100
|
+
return WrappedComponent;
|
|
101
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom runtime wrapper for @stencil/react-output-target.
|
|
3
|
+
*
|
|
4
|
+
* In JSDOM (vitest / jest), Stencil's lazy-loaded property-to-attribute
|
|
5
|
+
* reflection never fires, so props set as JS properties via @lit/react's
|
|
6
|
+
* createComponent are invisible to getAttribute(). This wrapper detects
|
|
7
|
+
* JSDOM and adds a useLayoutEffect that explicitly syncs primitive props
|
|
8
|
+
* to DOM attributes. In real browsers, the original component is returned
|
|
9
|
+
* unchanged — zero runtime cost.
|
|
10
|
+
*/
|
|
11
|
+
import type { Options, EventName } from '@lit/react';
|
|
12
|
+
export type { EventName } from '@lit/react';
|
|
13
|
+
export type { StencilReactComponent } from '@stencil/react-output-target/runtime';
|
|
14
|
+
type EventNames = Record<string, EventName | string>;
|
|
15
|
+
export declare const createComponent: <I extends HTMLElement, E extends EventNames = {}>({ defineCustomElement, tagName, transformTag, ...rest }: Options<I, E> & {
|
|
16
|
+
defineCustomElement?: () => void;
|
|
17
|
+
transformTag?: (tag: string) => string;
|
|
18
|
+
}) => any;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scania/tegel-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.50.0-dev-test-beta.0",
|
|
4
4
|
"description": "React wrappers for Tegel package",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "node ./__tests__/react-library.test.js",
|
|
10
|
-
"build": "npm run tsc",
|
|
10
|
+
"build": "node scripts/patch-imports.mjs && npm run tsc",
|
|
11
11
|
"tsc": "tsc -p . --outDir ./dist"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/scania-digital-design-system/tegel#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@scania/tegel": "1.
|
|
30
|
+
"@scania/tegel": "1.50.0-dev-test-beta.0",
|
|
31
31
|
"@stencil/react-output-target": "1.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|