@ilokesto/utilinent 1.0.14 → 1.1.1
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/README.md +10 -1
- package/dist/components/For/index.d.ts +2 -0
- package/dist/components/For/index.js +12 -0
- package/dist/components/For/types.d.ts +13 -0
- package/dist/components/For/types.js +2 -0
- package/dist/components/Mount/index.d.ts +2 -0
- package/dist/components/Mount/index.js +68 -0
- package/dist/components/Mount/types.d.ts +13 -0
- package/dist/components/{Observer.d.ts → Observer/index.d.ts} +1 -1
- package/dist/components/{Observer.js → Observer/index.js} +2 -2
- package/dist/components/Observer/types.d.ts +8 -0
- package/dist/components/OptionalWrapper/index.d.ts +2 -0
- package/dist/components/{OptionalWrapper.js → OptionalWrapper/index.js} +1 -1
- package/dist/components/OptionalWrapper/types.d.ts +6 -0
- package/dist/components/Repeat/index.d.ts +2 -0
- package/dist/components/Repeat/index.js +14 -0
- package/dist/components/Repeat/types.d.ts +13 -0
- package/dist/components/Repeat/types.js +1 -0
- package/dist/components/Show/index.d.ts +2 -0
- package/dist/components/Show/index.js +16 -0
- package/dist/components/Show/types.d.ts +18 -0
- package/dist/components/Show/types.js +1 -0
- package/dist/components/{Slacker.d.ts → Slacker/index.d.ts} +1 -1
- package/dist/components/{Slacker.js → Slacker/index.js} +1 -1
- package/dist/components/Slacker/types.d.ts +16 -0
- package/dist/components/Slacker/types.js +1 -0
- package/dist/components/{Slot.d.ts → Slot/Slot.d.ts} +0 -3
- package/dist/components/Slot/Slot.js +37 -0
- package/dist/components/Slot/Slottable.d.ts +4 -0
- package/dist/components/Slot/Slottable.js +8 -0
- package/dist/components/Slot/composeRefs.d.ts +2 -0
- package/dist/components/Slot/composeRefs.js +12 -0
- package/dist/components/Slot/index.d.ts +2 -0
- package/dist/components/Slot/index.js +2 -0
- package/dist/components/Slot/mergeProps.d.ts +2 -0
- package/dist/components/Slot/mergeProps.js +23 -0
- package/dist/components/Slot/types.d.ts +1 -0
- package/dist/components/Slot/types.js +1 -0
- package/dist/components/Switch/Match.d.ts +3 -0
- package/dist/components/Switch/Match.js +11 -0
- package/dist/components/Switch/Switch.d.ts +2 -0
- package/dist/components/Switch/Switch.js +24 -0
- package/dist/components/Switch/flattenChildren.d.ts +1 -0
- package/dist/components/Switch/flattenChildren.js +7 -0
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.js +2 -0
- package/dist/components/Switch/types.d.ts +16 -0
- package/dist/components/Switch/types.js +1 -0
- package/dist/constants/htmlTags.d.ts +88 -2
- package/dist/constants/htmlTags.js +87 -3
- package/dist/core/PluginManager.d.ts +7 -7
- package/dist/core/PluginManager.js +20 -13
- package/dist/core/createProxy.d.ts +2 -0
- package/dist/core/createProxy.js +30 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +8 -1
- package/dist/types/RegistryCategory.d.ts +1 -0
- package/dist/types/RegistryCategory.js +1 -0
- package/dist/types/index.d.ts +4 -51
- package/dist/types/index.js +4 -1
- package/dist/types/register.d.ts +4 -12
- package/dist/types/tagHelper.d.ts +20 -0
- package/dist/types/tagHelper.js +1 -0
- package/dist/types/utils.d.ts +14 -0
- package/dist/types/utils.js +1 -0
- package/dist/utils/resolveWhen.d.ts +1 -0
- package/dist/utils/resolveWhen.js +1 -0
- package/package.json +1 -5
- package/dist/components/For.d.ts +0 -2
- package/dist/components/For.js +0 -48
- package/dist/components/OptionalWrapper.d.ts +0 -2
- package/dist/components/Repeat.d.ts +0 -2
- package/dist/components/Repeat.js +0 -52
- package/dist/components/Show.d.ts +0 -2
- package/dist/components/Show.js +0 -55
- package/dist/components/Slot.js +0 -75
- package/dist/experimental/Mount.d.ts +0 -2
- package/dist/experimental/Mount.js +0 -8
- package/dist/experimental/Switch.d.ts +0 -8
- package/dist/experimental/Switch.js +0 -21
- package/dist/experimental.d.ts +0 -2
- package/dist/experimental.js +0 -2
- package/dist/types/for.d.ts +0 -25
- package/dist/types/repeat.d.ts +0 -24
- package/dist/types/show.d.ts +0 -31
- /package/dist/{types/for.js → components/Mount/types.js} +0 -0
- /package/dist/{types/repeat.js → components/Observer/types.js} +0 -0
- /package/dist/{types/show.js → components/OptionalWrapper/types.js} +0 -0
package/dist/components/Slot.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Children, cloneElement, forwardRef, isValidElement } from 'react';
|
|
3
|
-
function mergeProps(slotProps, childProps) {
|
|
4
|
-
const merged = { ...childProps };
|
|
5
|
-
for (const propName in slotProps) {
|
|
6
|
-
const slotProp = slotProps[propName];
|
|
7
|
-
const childProp = merged[propName];
|
|
8
|
-
if (/^on[A-Z]/.test(propName) && typeof slotProp === 'function' && typeof childProp === 'function') {
|
|
9
|
-
merged[propName] = (...args) => {
|
|
10
|
-
childProp(...args);
|
|
11
|
-
slotProp(...args);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
else if (propName === 'style' && typeof slotProp === 'object' && typeof childProp === 'object') {
|
|
15
|
-
merged[propName] = { ...childProp, ...slotProp };
|
|
16
|
-
}
|
|
17
|
-
else if (propName === 'className' && typeof slotProp === 'string' && typeof childProp === 'string') {
|
|
18
|
-
merged[propName] = [childProp, slotProp].filter(Boolean).join(' ');
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
merged[propName] = slotProp;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return merged;
|
|
25
|
-
}
|
|
26
|
-
function composeRefs(...refs) {
|
|
27
|
-
return (node) => {
|
|
28
|
-
for (const ref of refs) {
|
|
29
|
-
if (typeof ref === 'function') {
|
|
30
|
-
ref(node);
|
|
31
|
-
}
|
|
32
|
-
else if (ref != null) {
|
|
33
|
-
ref.current = node;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export const Slot = forwardRef((props, ref) => {
|
|
39
|
-
const { children, ...slotProps } = props;
|
|
40
|
-
const childrenArray = Children.toArray(children);
|
|
41
|
-
const slottable = childrenArray.find(isSlottable);
|
|
42
|
-
if (slottable) {
|
|
43
|
-
// Slottable의 children을 가져와서 병합
|
|
44
|
-
const slottableChild = slottable.props.children;
|
|
45
|
-
if (!isValidElement(slottableChild)) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const newElement = cloneElement(slottableChild, {
|
|
49
|
-
...mergeProps(slotProps, slottableChild.props),
|
|
50
|
-
ref: ref ? composeRefs(ref, slottableChild.ref) : slottableChild.ref,
|
|
51
|
-
key: slottable.key
|
|
52
|
-
});
|
|
53
|
-
const newChildren = childrenArray.map((child) => {
|
|
54
|
-
if (child === slottable) {
|
|
55
|
-
return newElement;
|
|
56
|
-
}
|
|
57
|
-
return child;
|
|
58
|
-
});
|
|
59
|
-
return _jsx(_Fragment, { children: newChildren });
|
|
60
|
-
}
|
|
61
|
-
const [child] = childrenArray;
|
|
62
|
-
if (!isValidElement(child)) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
return cloneElement(child, {
|
|
66
|
-
...mergeProps(slotProps, child.props),
|
|
67
|
-
ref: ref ? composeRefs(ref, child.ref) : child.ref
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
function isSlottable(child) {
|
|
71
|
-
return isValidElement(child) && child.type === Slottable;
|
|
72
|
-
}
|
|
73
|
-
export const Slottable = ({ children }) => {
|
|
74
|
-
return _jsx(_Fragment, { children: children });
|
|
75
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
export function Mount({ children, fallback = null }) {
|
|
3
|
-
const [resolvedChildren, setResolvedChildren] = useState(fallback);
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
(async () => setResolvedChildren(typeof children === "function" ? await children() : children))();
|
|
6
|
-
}, [children]);
|
|
7
|
-
return resolvedChildren;
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ExtractByKeyValue, ExtractValues, LiteralKeys, SwitchProps } from "../types";
|
|
2
|
-
export declare function createSwitcher<T, K extends LiteralKeys<T>>(data: T): {
|
|
3
|
-
Switch: ({ children, when, fallback }: SwitchProps<T, K>) => string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null;
|
|
4
|
-
Match: <V extends ExtractValues<T, K>>({ children }: {
|
|
5
|
-
case: V;
|
|
6
|
-
children: (props: ExtractByKeyValue<T, K, V>) => React.ReactNode;
|
|
7
|
-
}) => import("react").ReactNode;
|
|
8
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function createSwitcher(data) {
|
|
2
|
-
function Switch({ children, when, fallback = null }) {
|
|
3
|
-
children.reduce((acc, { type, props }) => {
|
|
4
|
-
if (type !== Match)
|
|
5
|
-
throw new Error("Match 컴포넌트만 사용할 수 있습니다.");
|
|
6
|
-
if (props.case) {
|
|
7
|
-
if (acc.includes(props.case))
|
|
8
|
-
throw new Error(`Duplicate Match key: ${props.case}`);
|
|
9
|
-
else
|
|
10
|
-
acc.push(props.case);
|
|
11
|
-
}
|
|
12
|
-
return acc;
|
|
13
|
-
}, []);
|
|
14
|
-
return children.find(({ props }) => props.case === data[when]) ?? fallback;
|
|
15
|
-
}
|
|
16
|
-
function Match({ children }) {
|
|
17
|
-
return children(data);
|
|
18
|
-
}
|
|
19
|
-
;
|
|
20
|
-
return { Switch, Match };
|
|
21
|
-
}
|
package/dist/experimental.d.ts
DELETED
package/dist/experimental.js
DELETED
package/dist/types/for.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Fallback } from ".";
|
|
2
|
-
import { HtmlTag } from "../constants/htmlTags";
|
|
3
|
-
import { UtilinentRegisterBase, UtilinentRegisterFor } from "./register";
|
|
4
|
-
export interface ForProps<T extends Array<unknown>> extends Fallback {
|
|
5
|
-
each: T | null | undefined;
|
|
6
|
-
children: (item: T[number], index: number) => React.ReactNode;
|
|
7
|
-
before?: React.ReactNode;
|
|
8
|
-
after?: React.ReactNode;
|
|
9
|
-
}
|
|
10
|
-
type ForTagHelper<K extends HtmlTag> = {
|
|
11
|
-
<const T extends Array<unknown>>(props: ForProps<T> & Omit<React.ComponentPropsWithRef<K>, 'children'>): React.ReactNode;
|
|
12
|
-
};
|
|
13
|
-
type ForRegisterHelper<C> = C extends React.ComponentType<infer P> ? {
|
|
14
|
-
<const T extends Array<unknown>>(props: Omit<P, "children"> & ForProps<T>): React.ReactNode;
|
|
15
|
-
} : C;
|
|
16
|
-
export type ForType = {
|
|
17
|
-
<const T extends Array<unknown>>(props: ForProps<T>): React.ReactNode;
|
|
18
|
-
} & {
|
|
19
|
-
[K in HtmlTag]: ForTagHelper<K>;
|
|
20
|
-
} & {
|
|
21
|
-
[K in keyof UtilinentRegisterFor]: ForRegisterHelper<UtilinentRegisterFor[K]>;
|
|
22
|
-
} & {
|
|
23
|
-
[K in keyof UtilinentRegisterBase]: ForRegisterHelper<UtilinentRegisterBase[K]>;
|
|
24
|
-
};
|
|
25
|
-
export {};
|
package/dist/types/repeat.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ComponentPropsWithRef } from "react";
|
|
2
|
-
import { Fallback } from ".";
|
|
3
|
-
import { HtmlTag } from "../constants/htmlTags";
|
|
4
|
-
import { UtilinentRegisterBase, UtilinentRegisterRepeat } from "./register";
|
|
5
|
-
export interface RepeatProps extends Fallback {
|
|
6
|
-
times: number;
|
|
7
|
-
children: (index: number) => React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
type RepeatTagHelper<K extends HtmlTag> = {
|
|
10
|
-
(props: RepeatProps & Omit<ComponentPropsWithRef<K>, "children">): React.ReactNode;
|
|
11
|
-
};
|
|
12
|
-
type RepeatRegisterHelper<C> = C extends React.ComponentType<infer P> ? {
|
|
13
|
-
(props: Omit<P, "children"> & RepeatProps): React.ReactNode;
|
|
14
|
-
} : C;
|
|
15
|
-
export type RepeatType = {
|
|
16
|
-
(props: RepeatProps): React.ReactNode;
|
|
17
|
-
} & {
|
|
18
|
-
[K in HtmlTag]: RepeatTagHelper<K>;
|
|
19
|
-
} & {
|
|
20
|
-
[K in keyof UtilinentRegisterRepeat]: RepeatRegisterHelper<UtilinentRegisterRepeat[K]>;
|
|
21
|
-
} & {
|
|
22
|
-
[K in keyof UtilinentRegisterBase]: RepeatRegisterHelper<UtilinentRegisterBase[K]>;
|
|
23
|
-
};
|
|
24
|
-
export {};
|
package/dist/types/show.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ComponentPropsWithRef } from "react";
|
|
2
|
-
import { HtmlTag } from "../constants/htmlTags";
|
|
3
|
-
import { Fallback, NonNullableElements } from "./";
|
|
4
|
-
import { UtilinentRegisterBase, UtilinentRegisterShow } from "./register";
|
|
5
|
-
export interface ShowPropsArray<T extends unknown[]> extends Fallback {
|
|
6
|
-
when: T;
|
|
7
|
-
children: React.ReactNode | ((item: NonNullableElements<T>) => React.ReactNode);
|
|
8
|
-
}
|
|
9
|
-
export interface ShowProps<T = unknown> extends Fallback {
|
|
10
|
-
when: T;
|
|
11
|
-
children: React.ReactNode | ((item: NonNullable<T>) => React.ReactNode);
|
|
12
|
-
}
|
|
13
|
-
type ShowTagHelper<K extends HtmlTag> = {
|
|
14
|
-
<const T extends unknown[]>(props: Omit<ComponentPropsWithRef<K>, "children"> & ShowPropsArray<T>): React.ReactNode;
|
|
15
|
-
<const T extends unknown>(props: Omit<ComponentPropsWithRef<K>, "children"> & ShowProps<T>): React.ReactNode;
|
|
16
|
-
};
|
|
17
|
-
type ShowRegisterHelper<C> = C extends React.ComponentType<infer P> ? {
|
|
18
|
-
<const T extends unknown[]>(props: Omit<P, "children"> & ShowPropsArray<T>): React.ReactNode;
|
|
19
|
-
<const T extends unknown>(props: Omit<P, "children"> & ShowProps<T>): React.ReactNode;
|
|
20
|
-
} : C;
|
|
21
|
-
export type ShowType = {
|
|
22
|
-
<const T extends unknown[]>(props: ShowPropsArray<T>): React.ReactNode;
|
|
23
|
-
<const T extends unknown>(props: ShowProps<T>): React.ReactNode;
|
|
24
|
-
} & {
|
|
25
|
-
[K in HtmlTag]: ShowTagHelper<K>;
|
|
26
|
-
} & {
|
|
27
|
-
[K in keyof UtilinentRegisterShow]: ShowRegisterHelper<UtilinentRegisterShow[K]>;
|
|
28
|
-
} & {
|
|
29
|
-
[K in keyof UtilinentRegisterBase]: ShowRegisterHelper<UtilinentRegisterBase[K]>;
|
|
30
|
-
};
|
|
31
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|