@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
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
export const htmlTags =
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export const htmlTags = {
|
|
2
|
+
a: "a",
|
|
3
|
+
abbr: "abbr",
|
|
4
|
+
address: "address",
|
|
5
|
+
article: "article",
|
|
6
|
+
aside: "aside",
|
|
7
|
+
b: "b",
|
|
8
|
+
bdi: "bdi",
|
|
9
|
+
bdo: "bdo",
|
|
10
|
+
blockquote: "blockquote",
|
|
11
|
+
button: "button",
|
|
12
|
+
canvas: "canvas",
|
|
13
|
+
cite: "cite",
|
|
14
|
+
code: "code",
|
|
15
|
+
data: "data",
|
|
16
|
+
datalist: "datalist",
|
|
17
|
+
dd: "dd",
|
|
18
|
+
del: "del",
|
|
19
|
+
details: "details",
|
|
20
|
+
dfn: "dfn",
|
|
21
|
+
dialog: "dialog",
|
|
22
|
+
div: "div",
|
|
23
|
+
dl: "dl",
|
|
24
|
+
dt: "dt",
|
|
25
|
+
em: "em",
|
|
26
|
+
fieldset: "fieldset",
|
|
27
|
+
figcaption: "figcaption",
|
|
28
|
+
figure: "figure",
|
|
29
|
+
footer: "footer",
|
|
30
|
+
form: "form",
|
|
31
|
+
h1: "h1",
|
|
32
|
+
h2: "h2",
|
|
33
|
+
h3: "h3",
|
|
34
|
+
h4: "h4",
|
|
35
|
+
h5: "h5",
|
|
36
|
+
h6: "h6",
|
|
37
|
+
header: "header",
|
|
38
|
+
hr: "hr",
|
|
39
|
+
i: "i",
|
|
40
|
+
img: "img",
|
|
41
|
+
input: "input",
|
|
42
|
+
ins: "ins",
|
|
43
|
+
kbd: "kbd",
|
|
44
|
+
label: "label",
|
|
45
|
+
legend: "legend",
|
|
46
|
+
li: "li",
|
|
47
|
+
main: "main",
|
|
48
|
+
map: "map",
|
|
49
|
+
mark: "mark",
|
|
50
|
+
menu: "menu",
|
|
51
|
+
meter: "meter",
|
|
52
|
+
nav: "nav",
|
|
53
|
+
ol: "ol",
|
|
54
|
+
option: "option",
|
|
55
|
+
output: "output",
|
|
56
|
+
p: "p",
|
|
57
|
+
picture: "picture",
|
|
58
|
+
pre: "pre",
|
|
59
|
+
progress: "progress",
|
|
60
|
+
q: "q",
|
|
61
|
+
rp: "rp",
|
|
62
|
+
rt: "rt",
|
|
63
|
+
ruby: "ruby",
|
|
64
|
+
s: "s",
|
|
65
|
+
samp: "samp",
|
|
66
|
+
section: "section",
|
|
67
|
+
select: "select",
|
|
68
|
+
small: "small",
|
|
69
|
+
span: "span",
|
|
70
|
+
strong: "strong",
|
|
71
|
+
sub: "sub",
|
|
72
|
+
summary: "summary",
|
|
73
|
+
sup: "sup",
|
|
74
|
+
table: "table",
|
|
75
|
+
tbody: "tbody",
|
|
76
|
+
td: "td",
|
|
77
|
+
textarea: "textarea",
|
|
78
|
+
tfoot: "tfoot",
|
|
79
|
+
th: "th",
|
|
80
|
+
thead: "thead",
|
|
81
|
+
time: "time",
|
|
82
|
+
tr: "tr",
|
|
83
|
+
u: "u",
|
|
84
|
+
ul: "ul",
|
|
85
|
+
var: "var",
|
|
86
|
+
video: "video"
|
|
87
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import type { RegistryCategory } from "../types";
|
|
1
2
|
/**
|
|
2
3
|
* 플러그인 등록을 위한 타입
|
|
3
4
|
* Register 인터페이스의 각 카테고리에 대해 부분적으로 등록 가능
|
|
4
5
|
*/
|
|
5
|
-
type PluginRegistration =
|
|
6
|
-
[K in "show" | "for" | "repeat" | "base"]?: Record<string, any>;
|
|
7
|
-
};
|
|
6
|
+
type PluginRegistration = Partial<Record<RegistryCategory, Record<string, any>>>;
|
|
8
7
|
/**
|
|
9
8
|
* 플러그인 컴포넌트를 등록하고 관리하는 싱글턴 클래스
|
|
10
9
|
*
|
|
@@ -41,6 +40,7 @@ export declare class PluginManager {
|
|
|
41
40
|
private static instance;
|
|
42
41
|
private plugins;
|
|
43
42
|
private constructor();
|
|
43
|
+
private getCategory;
|
|
44
44
|
/**
|
|
45
45
|
* PluginManager 인스턴스를 가져옵니다
|
|
46
46
|
*/
|
|
@@ -71,18 +71,18 @@ export declare class PluginManager {
|
|
|
71
71
|
/**
|
|
72
72
|
* 등록된 플러그인 컴포넌트를 가져옵니다 (내부용)
|
|
73
73
|
*/
|
|
74
|
-
static get<K extends
|
|
74
|
+
static get<K extends RegistryCategory>(category: K, name: string): any;
|
|
75
75
|
/**
|
|
76
76
|
* 특정 카테고리의 모든 플러그인을 가져옵니다 (내부용)
|
|
77
77
|
*/
|
|
78
|
-
static getAll<K extends
|
|
78
|
+
static getAll<K extends RegistryCategory>(category: K): Map<string, any>;
|
|
79
79
|
/**
|
|
80
80
|
* 플러그인이 등록되어 있는지 확인합니다
|
|
81
81
|
*/
|
|
82
|
-
static has<K extends
|
|
82
|
+
static has<K extends RegistryCategory>(category: K, name: string): boolean;
|
|
83
83
|
/**
|
|
84
84
|
* 플러그인을 제거합니다
|
|
85
85
|
*/
|
|
86
|
-
static unregister<K extends
|
|
86
|
+
static unregister<K extends RegistryCategory>(category: K, name: string): boolean;
|
|
87
87
|
}
|
|
88
88
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const DEFAULT_CATEGORIES = ["show", "for", "repeat", "mount", "switch", "base"];
|
|
1
2
|
/**
|
|
2
3
|
* 플러그인 컴포넌트를 등록하고 관리하는 싱글턴 클래스
|
|
3
4
|
*
|
|
@@ -32,14 +33,21 @@
|
|
|
32
33
|
*/
|
|
33
34
|
export class PluginManager {
|
|
34
35
|
static instance;
|
|
35
|
-
plugins =
|
|
36
|
-
show: new Map(),
|
|
37
|
-
for: new Map(),
|
|
38
|
-
repeat: new Map(),
|
|
39
|
-
base: new Map(),
|
|
40
|
-
};
|
|
36
|
+
plugins = new Map();
|
|
41
37
|
constructor() {
|
|
42
38
|
// 싱글턴 패턴: private constructor
|
|
39
|
+
DEFAULT_CATEGORIES.forEach((category) => {
|
|
40
|
+
this.plugins.set(category, new Map());
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getCategory(category) {
|
|
44
|
+
const existing = this.plugins.get(category);
|
|
45
|
+
if (existing) {
|
|
46
|
+
return existing;
|
|
47
|
+
}
|
|
48
|
+
const created = new Map();
|
|
49
|
+
this.plugins.set(category, created);
|
|
50
|
+
return created;
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
45
53
|
* PluginManager 인스턴스를 가져옵니다
|
|
@@ -70,8 +78,7 @@ export class PluginManager {
|
|
|
70
78
|
*/
|
|
71
79
|
static register(plugins) {
|
|
72
80
|
const instance = PluginManager.getInstance();
|
|
73
|
-
Object.
|
|
74
|
-
const components = plugins[category];
|
|
81
|
+
Object.entries(plugins).forEach(([category, components]) => {
|
|
75
82
|
if (components) {
|
|
76
83
|
Object.entries(components).forEach(([name, component]) => {
|
|
77
84
|
instance.registerOne(category, name, component);
|
|
@@ -83,34 +90,34 @@ export class PluginManager {
|
|
|
83
90
|
* 단일 플러그인 컴포넌트를 등록합니다 (내부용)
|
|
84
91
|
*/
|
|
85
92
|
registerOne(category, name, component) {
|
|
86
|
-
this.
|
|
93
|
+
this.getCategory(category).set(name, component);
|
|
87
94
|
}
|
|
88
95
|
/**
|
|
89
96
|
* 등록된 플러그인 컴포넌트를 가져옵니다 (내부용)
|
|
90
97
|
*/
|
|
91
98
|
static get(category, name) {
|
|
92
99
|
const instance = PluginManager.getInstance();
|
|
93
|
-
return instance.plugins
|
|
100
|
+
return instance.plugins.get(category)?.get(name);
|
|
94
101
|
}
|
|
95
102
|
/**
|
|
96
103
|
* 특정 카테고리의 모든 플러그인을 가져옵니다 (내부용)
|
|
97
104
|
*/
|
|
98
105
|
static getAll(category) {
|
|
99
106
|
const instance = PluginManager.getInstance();
|
|
100
|
-
return instance.
|
|
107
|
+
return instance.getCategory(category);
|
|
101
108
|
}
|
|
102
109
|
/**
|
|
103
110
|
* 플러그인이 등록되어 있는지 확인합니다
|
|
104
111
|
*/
|
|
105
112
|
static has(category, name) {
|
|
106
113
|
const instance = PluginManager.getInstance();
|
|
107
|
-
return instance.plugins
|
|
114
|
+
return instance.plugins.get(category)?.has(name) ?? false;
|
|
108
115
|
}
|
|
109
116
|
/**
|
|
110
117
|
* 플러그인을 제거합니다
|
|
111
118
|
*/
|
|
112
119
|
static unregister(category, name) {
|
|
113
120
|
const instance = PluginManager.getInstance();
|
|
114
|
-
return instance.plugins
|
|
121
|
+
return instance.plugins.get(category)?.delete(name) ?? false;
|
|
115
122
|
}
|
|
116
123
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { htmlTags } from "../constants/htmlTags";
|
|
2
|
+
import { PluginManager } from "./PluginManager";
|
|
3
|
+
export function createProxy(base, renderForTag, category) {
|
|
4
|
+
const tagEntries = Object.keys(htmlTags).reduce((acc, tag) => {
|
|
5
|
+
acc[tag] = renderForTag(tag);
|
|
6
|
+
return acc;
|
|
7
|
+
}, {});
|
|
8
|
+
const target = Object.assign(base, tagEntries);
|
|
9
|
+
return new Proxy(target, {
|
|
10
|
+
get(currentTarget, prop) {
|
|
11
|
+
if (prop in currentTarget) {
|
|
12
|
+
return currentTarget[prop];
|
|
13
|
+
}
|
|
14
|
+
const propName = String(prop);
|
|
15
|
+
if (PluginManager.has(category, propName)) {
|
|
16
|
+
const component = PluginManager.get(category, propName);
|
|
17
|
+
const specialized = renderForTag(component);
|
|
18
|
+
currentTarget[prop] = specialized;
|
|
19
|
+
return specialized;
|
|
20
|
+
}
|
|
21
|
+
if (PluginManager.has("base", propName)) {
|
|
22
|
+
const component = PluginManager.get("base", propName);
|
|
23
|
+
const specialized = renderForTag(component);
|
|
24
|
+
currentTarget[prop] = specialized;
|
|
25
|
+
return specialized;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export * from './components/For';
|
|
2
|
+
export * from './components/Mount';
|
|
2
3
|
export * from './components/Observer';
|
|
3
4
|
export * from './components/OptionalWrapper';
|
|
4
5
|
export * from './components/Repeat';
|
|
5
6
|
export * from './components/Show';
|
|
6
7
|
export * from './components/Slacker';
|
|
7
|
-
export * from './components/Slot';
|
|
8
|
+
export * from './components/Slot/Slot';
|
|
9
|
+
export * from './components/Switch/Switch';
|
|
8
10
|
export * from './hooks/useIntersectionObserver';
|
|
9
11
|
export { PluginManager } from './core/PluginManager';
|
|
10
|
-
export { UtilinentRegister } from './types
|
|
12
|
+
export { UtilinentRegister } from './types';
|
|
13
|
+
export { createProxy } from './core/createProxy';
|
|
14
|
+
export { BaseTypeHelperFn, ProxyType } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
// export components
|
|
1
2
|
export * from './components/For';
|
|
3
|
+
export * from './components/Mount';
|
|
2
4
|
export * from './components/Observer';
|
|
3
5
|
export * from './components/OptionalWrapper';
|
|
4
6
|
export * from './components/Repeat';
|
|
5
7
|
export * from './components/Show';
|
|
6
8
|
export * from './components/Slacker';
|
|
7
|
-
export * from './components/Slot';
|
|
9
|
+
export * from './components/Slot/Slot';
|
|
10
|
+
export * from './components/Switch/Switch';
|
|
11
|
+
// export hooks
|
|
8
12
|
export * from './hooks/useIntersectionObserver';
|
|
13
|
+
// export Register and PluginManager
|
|
9
14
|
export { PluginManager } from './core/PluginManager';
|
|
15
|
+
// export createProxy
|
|
16
|
+
export { createProxy } from './core/createProxy';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RegistryCategory = "show" | "for" | "repeat" | "mount" | "switch" | "base" | (string & {});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,51 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export type NonNullableElements<T extends readonly any[]> = {
|
|
7
|
-
-readonly [P in keyof T]: NonNullable<T[P]>;
|
|
8
|
-
};
|
|
9
|
-
export interface OptionalWrapperProps {
|
|
10
|
-
when: boolean;
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
wrapper: (children: React.ReactNode) => React.ReactNode;
|
|
13
|
-
fallback?: (children: React.ReactNode) => React.ReactNode;
|
|
14
|
-
}
|
|
15
|
-
export interface ObserverProps extends Fallback {
|
|
16
|
-
children?: React.ReactNode | ((isIntersecting: boolean) => React.ReactNode);
|
|
17
|
-
threshold?: number | number[];
|
|
18
|
-
rootMargin?: string;
|
|
19
|
-
triggerOnce?: boolean;
|
|
20
|
-
onIntersect?: (isIntersecting: boolean, entry: IntersectionObserverEntry) => void;
|
|
21
|
-
}
|
|
22
|
-
export interface SwitchProps<T, K extends LiteralKeys<T>> extends Fallback {
|
|
23
|
-
children: Array<ReactElement>;
|
|
24
|
-
when: K;
|
|
25
|
-
}
|
|
26
|
-
export interface MountProps extends Fallback {
|
|
27
|
-
children: React.ReactNode | (() => React.ReactNode | Promise<React.ReactNode>);
|
|
28
|
-
}
|
|
29
|
-
export type ExtractValues<T, K extends keyof T> = T extends any ? T[K] : never;
|
|
30
|
-
type IsUnion<T, U = T> = T extends any ? [U] extends [T] ? false : true : false;
|
|
31
|
-
export type ExtractByKeyValue<T, K extends keyof T, V> = T extends any ? IsUnion<T> extends true ? T[K] extends V ? T : never : V extends T[K] ? T : never : never;
|
|
32
|
-
export type GetLiteralKeys<T> = {
|
|
33
|
-
[K in keyof T]: T[K] extends string ? string extends T[K] ? never : K : T[K] extends number ? number extends T[K] ? never : K : T[K] extends boolean ? boolean extends T[K] ? never : K : T[K] extends bigint ? bigint extends T[K] ? never : K : T[K] extends symbol ? symbol extends T[K] ? never : K : never;
|
|
34
|
-
}[keyof T];
|
|
35
|
-
export type LiteralKeys<T> = [GetLiteralKeys<T>] extends [never] ? keyof T : GetLiteralKeys<T>;
|
|
36
|
-
export type SlackerFallbackProps = {
|
|
37
|
-
isLoading: boolean;
|
|
38
|
-
error: Error | null;
|
|
39
|
-
retry: () => void;
|
|
40
|
-
};
|
|
41
|
-
export type SlackerProps<T = any> = {
|
|
42
|
-
children: (loaded: T) => React.ReactNode;
|
|
43
|
-
errorFallback?: React.ReactNode | ((props: SlackerFallbackProps) => React.ReactNode);
|
|
44
|
-
loadingFallback?: React.ReactNode;
|
|
45
|
-
threshold?: number | number[];
|
|
46
|
-
rootMargin?: string;
|
|
47
|
-
loader: () => Promise<T> | T;
|
|
48
|
-
onError?: (error: Error) => void;
|
|
49
|
-
maxRetries?: number;
|
|
50
|
-
retryDelay?: number;
|
|
51
|
-
};
|
|
1
|
+
export * from "./register";
|
|
2
|
+
export * from "./RegistryCategory";
|
|
3
|
+
export * from "./tagHelper";
|
|
4
|
+
export * from "./utils";
|
package/dist/types/index.js
CHANGED
package/dist/types/register.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
+
import { RegistryCategory } from "./RegistryCategory";
|
|
1
2
|
export interface UtilinentRegister {
|
|
2
3
|
}
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
} ?
|
|
6
|
-
export type UtilinentRegisterBase = UtilinentRegister extends {
|
|
7
|
-
base: infer Base;
|
|
8
|
-
} ? Base : never;
|
|
9
|
-
export type UtilinentRegisterFor = UtilinentRegister extends {
|
|
10
|
-
for: infer For;
|
|
11
|
-
} ? For : never;
|
|
12
|
-
export type UtilinentRegisterRepeat = UtilinentRegister extends {
|
|
13
|
-
repeat: infer Repeat;
|
|
14
|
-
} ? Repeat : never;
|
|
4
|
+
export type RegisterProps<T extends RegistryCategory> = UtilinentRegister extends {
|
|
5
|
+
[X in T]: infer Props;
|
|
6
|
+
} ? Props : never;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HtmlTag } from "../constants/htmlTags";
|
|
2
|
+
import { RegisterProps } from "./register";
|
|
3
|
+
import { RegistryCategory } from "./RegistryCategory";
|
|
4
|
+
export interface BaseTypeHelperFn {
|
|
5
|
+
props: unknown;
|
|
6
|
+
type: unknown;
|
|
7
|
+
}
|
|
8
|
+
type Apply<F extends BaseTypeHelperFn, Props> = (F & {
|
|
9
|
+
props: Props;
|
|
10
|
+
})["type"];
|
|
11
|
+
type MaybeOmitChildren<Props, OmitChildren extends boolean> = OmitChildren extends true ? Omit<Props, "children"> : Props;
|
|
12
|
+
export type TagHelper<K, F extends BaseTypeHelperFn, OmitChildren extends boolean = true> = K extends keyof HtmlTag ? Apply<F, MaybeOmitChildren<React.ComponentPropsWithRef<K>, OmitChildren>> : K extends React.ComponentType<infer P> ? Apply<F, MaybeOmitChildren<P, OmitChildren>> : K;
|
|
13
|
+
export type ProxyType<F extends BaseTypeHelperFn, RegisterKey extends RegistryCategory, OmitChildren extends boolean = true> = Apply<F, object> & {
|
|
14
|
+
[K in keyof HtmlTag]: TagHelper<K, F, OmitChildren>;
|
|
15
|
+
} & {
|
|
16
|
+
[K in keyof RegisterProps<RegisterKey>]: TagHelper<RegisterProps<RegisterKey>[K], F, OmitChildren>;
|
|
17
|
+
} & {
|
|
18
|
+
[K in keyof RegisterProps<"base">]: TagHelper<RegisterProps<"base">[K], F, OmitChildren>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { UtilinentRegister } from "./register";
|
|
2
|
+
export interface Fallback {
|
|
3
|
+
fallback?: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export type NonNullableElements<T extends readonly any[]> = {
|
|
6
|
+
-readonly [P in keyof T]: NonNullable<T[P]>;
|
|
7
|
+
};
|
|
8
|
+
export type ExtractValues<T, K extends keyof T> = T extends any ? T[K] : never;
|
|
9
|
+
type IsUnion<T, U = T> = T extends any ? [U] extends [T] ? false : true : false;
|
|
10
|
+
export type ExtractByKeyValue<T, K extends keyof T, V> = T extends any ? IsUnion<T> extends true ? T[K] extends V ? T : never : V extends T[K] ? T : never : never;
|
|
11
|
+
export type GetLiteralKeys<T> = {
|
|
12
|
+
[K in keyof T]: T[K] extends string ? string extends T[K] ? never : K : T[K] extends number ? number extends T[K] ? never : K : T[K] extends boolean ? boolean extends T[K] ? never : K : T[K] extends bigint ? bigint extends T[K] ? never : K : T[K] extends symbol ? symbol extends T[K] ? never : K : never;
|
|
13
|
+
}[keyof T];
|
|
14
|
+
export type LiteralKeys<T> = [GetLiteralKeys<T>] extends [never] ? keyof T : GetLiteralKeys<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveWhen: (value: unknown) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const resolveWhen = (value) => Array.isArray(value) ? value.every(Boolean) : !!value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ilokesto/utilinent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ilokesto/utilinent.git"
|
|
@@ -13,10 +13,6 @@
|
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./dist/index.js",
|
|
15
15
|
"types": "./dist/index.d.ts"
|
|
16
|
-
},
|
|
17
|
-
"./experimental": {
|
|
18
|
-
"import": "./dist/experimental.js",
|
|
19
|
-
"types": "./dist/experimental.d.ts"
|
|
20
16
|
}
|
|
21
17
|
},
|
|
22
18
|
"files": [
|
package/dist/components/For.d.ts
DELETED
package/dist/components/For.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createElement, forwardRef } from "react";
|
|
3
|
-
import { htmlTags } from "../constants/htmlTags";
|
|
4
|
-
import { PluginManager } from "../core/PluginManager";
|
|
5
|
-
function BaseFor({ each, children, fallback = null, before, after, }) {
|
|
6
|
-
const content = each && each.length > 0 ? each.map(children) : fallback;
|
|
7
|
-
return (_jsxs(_Fragment, { children: [before, content, after] }));
|
|
8
|
-
}
|
|
9
|
-
const renderForTag = (tag) =>
|
|
10
|
-
// forward ref so consumers can attach a ref to the underlying DOM element
|
|
11
|
-
forwardRef(({ each, children, fallback = null, before, after, ...props }, ref) => {
|
|
12
|
-
const content = each && each.length > 0 ? each.map(children) : fallback;
|
|
13
|
-
return createElement(tag, { ...props, ref }, before, content, after);
|
|
14
|
-
});
|
|
15
|
-
// HTML 태그들을 등록
|
|
16
|
-
const tagEntries = htmlTags.reduce((acc, tag) => {
|
|
17
|
-
acc[tag] = renderForTag(tag);
|
|
18
|
-
return acc;
|
|
19
|
-
}, {});
|
|
20
|
-
// Proxy를 사용하여 동적으로 플러그인 조회
|
|
21
|
-
export const For = new Proxy(Object.assign(BaseFor, tagEntries), {
|
|
22
|
-
get(target, prop) {
|
|
23
|
-
// 기존 속성이 있으면 반환
|
|
24
|
-
if (prop in target) {
|
|
25
|
-
return target[prop];
|
|
26
|
-
}
|
|
27
|
-
// 플러그인에서 동적으로 조회
|
|
28
|
-
const propName = String(prop);
|
|
29
|
-
// 'for' 카테고리에서 먼저 찾기
|
|
30
|
-
if (PluginManager.has('for', propName)) {
|
|
31
|
-
const component = PluginManager.get('for', propName);
|
|
32
|
-
const specialized = renderForTag(component);
|
|
33
|
-
// 캐싱하여 다음 조회 시 동일한 참조 반환
|
|
34
|
-
target[prop] = specialized;
|
|
35
|
-
return specialized;
|
|
36
|
-
}
|
|
37
|
-
// 'base' 카테고리에서 찾기
|
|
38
|
-
if (PluginManager.has('base', propName)) {
|
|
39
|
-
const component = PluginManager.get('base', propName);
|
|
40
|
-
const specialized = renderForTag(component);
|
|
41
|
-
// 캐싱하여 다음 조회 시 동일한 참조 반환
|
|
42
|
-
target[prop] = specialized;
|
|
43
|
-
return specialized;
|
|
44
|
-
}
|
|
45
|
-
// 찾지 못하면 undefined 반환
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createElement, forwardRef } from "react";
|
|
3
|
-
import { htmlTags } from "../constants/htmlTags";
|
|
4
|
-
import { PluginManager } from "../core/PluginManager";
|
|
5
|
-
import { For } from "./For";
|
|
6
|
-
function BaseRepeat({ times, children, fallback = null }) {
|
|
7
|
-
if (!times || times <= 0 || !Number.isInteger(times)) {
|
|
8
|
-
return fallback ?? null;
|
|
9
|
-
}
|
|
10
|
-
return _jsx(For, { each: Array.from({ length: times }, (_, i) => i), children: children });
|
|
11
|
-
}
|
|
12
|
-
const renderForTag = (tag) =>
|
|
13
|
-
// forward ref so consumers can attach a ref to the underlying DOM element
|
|
14
|
-
forwardRef(({ times, children, fallback = null, ...props }, ref) => {
|
|
15
|
-
const content = times && times > 0 && Number.isInteger(times)
|
|
16
|
-
? Array.from({ length: times }, (_, i) => children(i))
|
|
17
|
-
: fallback ?? null;
|
|
18
|
-
return createElement(tag, { ...props, ref }, content);
|
|
19
|
-
});
|
|
20
|
-
// HTML 태그들을 등록
|
|
21
|
-
const tagEntries = htmlTags.reduce((acc, tag) => {
|
|
22
|
-
acc[tag] = renderForTag(tag);
|
|
23
|
-
return acc;
|
|
24
|
-
}, {});
|
|
25
|
-
export const Repeat = new Proxy(Object.assign(BaseRepeat, tagEntries), {
|
|
26
|
-
get(target, prop) {
|
|
27
|
-
// 기존 속성이 있으면 반환
|
|
28
|
-
if (prop in target) {
|
|
29
|
-
return target[prop];
|
|
30
|
-
}
|
|
31
|
-
// 플러그인에서 동적으로 조회
|
|
32
|
-
const propName = String(prop);
|
|
33
|
-
// 'repeat' 카테고리에서 먼저 찾기
|
|
34
|
-
if (PluginManager.has('repeat', propName)) {
|
|
35
|
-
const component = PluginManager.get('repeat', propName);
|
|
36
|
-
const specialized = renderForTag(component);
|
|
37
|
-
// 캐싱하여 다음 조회 시 동일한 참조 반환
|
|
38
|
-
target[prop] = specialized;
|
|
39
|
-
return specialized;
|
|
40
|
-
}
|
|
41
|
-
// 'base' 카테고리에서 찾기
|
|
42
|
-
if (PluginManager.has('base', propName)) {
|
|
43
|
-
const component = PluginManager.get('base', propName);
|
|
44
|
-
const specialized = renderForTag(component);
|
|
45
|
-
// 캐싱하여 다음 조회 시 동일한 참조 반환
|
|
46
|
-
target[prop] = specialized;
|
|
47
|
-
return specialized;
|
|
48
|
-
}
|
|
49
|
-
// 찾지 못하면 undefined 반환
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
});
|
package/dist/components/Show.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createElement, forwardRef } from "react";
|
|
2
|
-
import { htmlTags } from "../constants/htmlTags";
|
|
3
|
-
import { PluginManager } from "../core/PluginManager";
|
|
4
|
-
const BaseShow = ({ when, children, fallback = null }) => {
|
|
5
|
-
const shouldRender = Array.isArray(when) ? when.every(Boolean) : !!when;
|
|
6
|
-
return shouldRender
|
|
7
|
-
? typeof children === "function"
|
|
8
|
-
? children(when)
|
|
9
|
-
: children
|
|
10
|
-
: fallback;
|
|
11
|
-
};
|
|
12
|
-
const renderForTag = (tag) =>
|
|
13
|
-
// forward ref so consumers like Observer can pass a ref to the real DOM element
|
|
14
|
-
forwardRef(function Render({ when, children, fallback = null, ...props }, ref) {
|
|
15
|
-
const shouldRender = Array.isArray(when) ? when.every(Boolean) : !!when;
|
|
16
|
-
const content = shouldRender
|
|
17
|
-
? typeof children === "function"
|
|
18
|
-
? children(when)
|
|
19
|
-
: children
|
|
20
|
-
: fallback;
|
|
21
|
-
return createElement(tag, { ...props, ref }, content);
|
|
22
|
-
});
|
|
23
|
-
// HTML 태그들을 등록
|
|
24
|
-
const tagEntries = htmlTags.reduce((acc, tag) => {
|
|
25
|
-
acc[tag] = renderForTag(tag);
|
|
26
|
-
return acc;
|
|
27
|
-
}, {});
|
|
28
|
-
export const Show = new Proxy(Object.assign(BaseShow, tagEntries), {
|
|
29
|
-
get(target, prop) {
|
|
30
|
-
// 기존 속성이 있으면 반환
|
|
31
|
-
if (prop in target) {
|
|
32
|
-
return target[prop];
|
|
33
|
-
}
|
|
34
|
-
// 플러그인에서 동적으로 조회
|
|
35
|
-
const propName = String(prop);
|
|
36
|
-
// 'show' 카테고리에서 먼저 찾기
|
|
37
|
-
if (PluginManager.has('show', propName)) {
|
|
38
|
-
const component = PluginManager.get('show', propName);
|
|
39
|
-
const specialized = renderForTag(component);
|
|
40
|
-
// 캐싱하여 다음 조회 시 동일한 참조 반환
|
|
41
|
-
target[prop] = specialized;
|
|
42
|
-
return specialized;
|
|
43
|
-
}
|
|
44
|
-
// 'base' 카테고리에서 찾기
|
|
45
|
-
if (PluginManager.has('base', propName)) {
|
|
46
|
-
const component = PluginManager.get('base', propName);
|
|
47
|
-
const specialized = renderForTag(component);
|
|
48
|
-
// 캐싱하여 다음 조회 시 동일한 참조 반환
|
|
49
|
-
target[prop] = specialized;
|
|
50
|
-
return specialized;
|
|
51
|
-
}
|
|
52
|
-
// 찾지 못하면 undefined 반환
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
});
|