@shineuix/react 0.0.0-stage → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/dist/components/components.d.ts +845 -0
- package/dist/components/components.js +1637 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/runtime.d.ts +18 -0
- package/dist/runtime.js +77 -0
- package/package.json +59 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components/components.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components/components.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Vendored from @stencil/react-output-target 1.6.2, src/runtime/create-component.ts.
|
|
3
|
+
* The MIT License (MIT). Copyright (c) 2019-present Drifty Co.
|
|
4
|
+
* Changed here: the wrapper renders nothing on the server and during hydration (useClientRender).
|
|
5
|
+
*/
|
|
6
|
+
import type { EventName, Options } from '@lit/react';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
export type { EventName, Options } from '@lit/react';
|
|
9
|
+
type EventNames = Record<string, EventName | string>;
|
|
10
|
+
type StencilProps<I extends HTMLElement, E extends EventNames, C, R extends keyof C = never> = Omit<React.HTMLAttributes<I>, keyof E> & Partial<{
|
|
11
|
+
[K in keyof E]: E[K] extends EventName<infer T> ? (event: T) => void : (event: any) => void;
|
|
12
|
+
}> & Required<Pick<C, R>> & Partial<Omit<C, R>> & React.RefAttributes<I>;
|
|
13
|
+
export type StencilReactComponent<I extends HTMLElement, E extends EventNames = {}, C = Omit<I, keyof HTMLElement>, R extends keyof C = never> = React.FunctionComponent<StencilProps<I, E, C, R>>;
|
|
14
|
+
export declare const mergeClassNames: (currentClasses: Iterable<string>, newClassName: string | undefined, oldClassName: string | undefined) => string;
|
|
15
|
+
export declare const createComponent: <I extends HTMLElement, E extends EventNames = {}, C = Omit<I, keyof HTMLElement>, R extends keyof C = never>({ defineCustomElement, tagName, transformTag, ...options }: Options<I, E> & {
|
|
16
|
+
defineCustomElement: () => void;
|
|
17
|
+
transformTag?: (tagName: string) => string;
|
|
18
|
+
}) => StencilReactComponent<I, E, C, R>;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Vendored from @stencil/react-output-target 1.6.2, src/runtime/create-component.ts.
|
|
3
|
+
* The MIT License (MIT). Copyright (c) 2019-present Drifty Co.
|
|
4
|
+
* Changed here: the wrapper renders nothing on the server and during hydration (useClientRender).
|
|
5
|
+
*/
|
|
6
|
+
import { createComponent as createComponentWrapper } from '@lit/react';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
const splitClassName = (className) => className ? className.split(/\s+/).filter(Boolean) : [];
|
|
9
|
+
export const mergeClassNames = (currentClasses, newClassName, oldClassName) => {
|
|
10
|
+
const incoming = new Set(splitClassName(newClassName));
|
|
11
|
+
const previous = new Set(splitClassName(oldClassName));
|
|
12
|
+
const finalClassNames = [];
|
|
13
|
+
for (const className of currentClasses) {
|
|
14
|
+
if (incoming.has(className)) {
|
|
15
|
+
finalClassNames.push(className);
|
|
16
|
+
incoming.delete(className);
|
|
17
|
+
}
|
|
18
|
+
else if (!previous.has(className)) {
|
|
19
|
+
finalClassNames.push(className);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (const className of incoming) {
|
|
23
|
+
finalClassNames.push(className);
|
|
24
|
+
}
|
|
25
|
+
return finalClassNames.join(' ');
|
|
26
|
+
};
|
|
27
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
28
|
+
const subscribeNever = () => () => { };
|
|
29
|
+
/**
|
|
30
|
+
* False on the server and while the page hydrates, true in every other render.
|
|
31
|
+
*
|
|
32
|
+
* ShineUI's elements render into their own light DOM. In a server-rendered React app (Next.js,
|
|
33
|
+
* Remix) that collides with hydration: the element modules define the tags on import, the host
|
|
34
|
+
* tags the server sent upgrade and draw their inner markup, and React then finds children it did
|
|
35
|
+
* not render, reports a hydration mismatch (#418) and throws the server's markup away for the
|
|
36
|
+
* whole tree. So a wrapper renders nothing until this is true. useSyncExternalStore is React's
|
|
37
|
+
* own switch for it: the server snapshot is used on the server and during hydration, the client
|
|
38
|
+
* snapshot in every other render, so an app that only renders on the client sees the element in
|
|
39
|
+
* its first render.
|
|
40
|
+
*/
|
|
41
|
+
const useClientRender = () => React.useSyncExternalStore(subscribeNever, () => true, () => false);
|
|
42
|
+
export const createComponent = ({ defineCustomElement, tagName, transformTag, ...options }) => {
|
|
43
|
+
if (typeof defineCustomElement !== 'undefined') {
|
|
44
|
+
defineCustomElement();
|
|
45
|
+
}
|
|
46
|
+
const finalTagName = transformTag ? transformTag(tagName) : tagName;
|
|
47
|
+
const ReactComponent = createComponentWrapper({ ...options, tagName: finalTagName });
|
|
48
|
+
const WrappedComponent = React.forwardRef((props, ref) => {
|
|
49
|
+
const { className, class: classProp, ...restProps } = props;
|
|
50
|
+
const incomingClassName = className ?? classProp ?? '';
|
|
51
|
+
const client = useClientRender();
|
|
52
|
+
const elementRef = React.useRef(null);
|
|
53
|
+
const previousClassName = React.useRef('');
|
|
54
|
+
useIsomorphicLayoutEffect(() => {
|
|
55
|
+
const element = elementRef.current;
|
|
56
|
+
if (element === null || incomingClassName === previousClassName.current) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
element.className = mergeClassNames(Array.from(element.classList), incomingClassName, previousClassName.current);
|
|
60
|
+
previousClassName.current = incomingClassName;
|
|
61
|
+
});
|
|
62
|
+
const setRef = React.useCallback((node) => {
|
|
63
|
+
elementRef.current = node;
|
|
64
|
+
if (typeof ref === 'function') {
|
|
65
|
+
ref(node);
|
|
66
|
+
}
|
|
67
|
+
else if (ref !== null && ref !== undefined) {
|
|
68
|
+
ref.current = node;
|
|
69
|
+
}
|
|
70
|
+
}, [ref]);
|
|
71
|
+
if (!client)
|
|
72
|
+
return null;
|
|
73
|
+
return React.createElement(ReactComponent, { ...restProps, ref: setRef });
|
|
74
|
+
});
|
|
75
|
+
WrappedComponent.displayName = options.displayName ?? finalTagName;
|
|
76
|
+
return WrappedComponent;
|
|
77
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shineuix/react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React bindings for ShineUI web components.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"web-components",
|
|
9
|
+
"design-system",
|
|
10
|
+
"ui",
|
|
11
|
+
"components",
|
|
12
|
+
"shineui"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"module": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"dist/",
|
|
33
|
+
"!dist/components/components.server.*"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@lit/react": "^1.0.8",
|
|
37
|
+
"@shineuix/core": "1.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^18 || ^19",
|
|
41
|
+
"react-dom": "^18 || ^19"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@stencil/react-output-target": "^1.6.2",
|
|
45
|
+
"@types/react": "^19.1.0",
|
|
46
|
+
"@types/react-dom": "^19.1.0",
|
|
47
|
+
"react": "^19.1.0",
|
|
48
|
+
"react-dom": "^19.1.0",
|
|
49
|
+
"typescript": "~5.9.0"
|
|
50
|
+
},
|
|
51
|
+
"author": "ShineUI contributors",
|
|
52
|
+
"homepage": "https://shineui.dev",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"email": "info@shineui.dev"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc -p tsconfig.json && node scripts/vendor-runtime.mjs"
|
|
61
|
+
}
|
|
6
62
|
}
|