@ilokesto/utilinent 1.1.0 → 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.
Files changed (83) hide show
  1. package/README.md +10 -1
  2. package/dist/components/For/index.d.ts +2 -0
  3. package/dist/components/{For.js → For/index.js} +2 -2
  4. package/dist/components/For/types.d.ts +13 -0
  5. package/dist/components/For/types.js +2 -0
  6. package/dist/components/Mount/index.d.ts +2 -0
  7. package/dist/components/{Mount.js → Mount/index.js} +3 -5
  8. package/dist/components/Mount/types.d.ts +13 -0
  9. package/dist/components/{Observer.d.ts → Observer/index.d.ts} +1 -1
  10. package/dist/components/{Observer.js → Observer/index.js} +2 -2
  11. package/dist/components/Observer/types.d.ts +8 -0
  12. package/dist/components/{OptionalWrapper.d.ts → OptionalWrapper/index.d.ts} +1 -1
  13. package/dist/components/{OptionalWrapper.js → OptionalWrapper/index.js} +1 -1
  14. package/dist/components/OptionalWrapper/types.d.ts +6 -0
  15. package/dist/components/Repeat/index.d.ts +2 -0
  16. package/dist/components/{Repeat.js → Repeat/index.js} +3 -5
  17. package/dist/components/Repeat/types.d.ts +13 -0
  18. package/dist/components/Show/index.d.ts +2 -0
  19. package/dist/components/{Show.js → Show/index.js} +4 -6
  20. package/dist/components/Show/types.d.ts +18 -0
  21. package/dist/components/{Slacker.d.ts → Slacker/index.d.ts} +1 -1
  22. package/dist/components/{Slacker.js → Slacker/index.js} +1 -1
  23. package/dist/components/Slacker/types.d.ts +16 -0
  24. package/dist/components/{Slot.d.ts → Slot/Slot.d.ts} +0 -3
  25. package/dist/components/Slot/Slot.js +37 -0
  26. package/dist/components/Slot/Slottable.d.ts +4 -0
  27. package/dist/components/Slot/Slottable.js +8 -0
  28. package/dist/components/Slot/composeRefs.d.ts +2 -0
  29. package/dist/components/Slot/composeRefs.js +12 -0
  30. package/dist/components/Slot/index.d.ts +2 -0
  31. package/dist/components/Slot/index.js +2 -0
  32. package/dist/components/Slot/mergeProps.d.ts +2 -0
  33. package/dist/components/Slot/mergeProps.js +23 -0
  34. package/dist/components/Slot/types.d.ts +1 -0
  35. package/dist/components/Slot/types.js +1 -0
  36. package/dist/components/Switch/Match.d.ts +3 -0
  37. package/dist/components/Switch/Match.js +11 -0
  38. package/dist/components/Switch/Switch.d.ts +2 -0
  39. package/dist/components/Switch/Switch.js +24 -0
  40. package/dist/components/Switch/flattenChildren.d.ts +1 -0
  41. package/dist/components/Switch/flattenChildren.js +7 -0
  42. package/dist/components/Switch/index.d.ts +2 -0
  43. package/dist/components/Switch/index.js +2 -0
  44. package/dist/components/Switch/types.d.ts +16 -0
  45. package/dist/components/Switch/types.js +1 -0
  46. package/dist/constants/htmlTags.d.ts +88 -2
  47. package/dist/constants/htmlTags.js +87 -3
  48. package/dist/core/PluginManager.d.ts +7 -8
  49. package/dist/core/PluginManager.js +20 -15
  50. package/dist/core/createProxy.d.ts +2 -0
  51. package/dist/core/{createTagProxy.js → createProxy.js} +2 -2
  52. package/dist/index.d.ts +5 -3
  53. package/dist/index.js +7 -2
  54. package/dist/types/RegistryCategory.d.ts +1 -0
  55. package/dist/types/RegistryCategory.js +1 -0
  56. package/dist/types/index.d.ts +4 -47
  57. package/dist/types/index.js +4 -1
  58. package/dist/types/register.d.ts +4 -18
  59. package/dist/types/tagHelper.d.ts +20 -0
  60. package/dist/types/tagHelper.js +1 -0
  61. package/dist/types/utils.d.ts +14 -0
  62. package/dist/types/utils.js +1 -0
  63. package/package.json +1 -1
  64. package/dist/components/For.d.ts +0 -2
  65. package/dist/components/Mount.d.ts +0 -2
  66. package/dist/components/Repeat.d.ts +0 -2
  67. package/dist/components/Show.d.ts +0 -2
  68. package/dist/components/Slot.js +0 -75
  69. package/dist/components/Switch.d.ts +0 -4
  70. package/dist/components/Switch.js +0 -39
  71. package/dist/core/createTagProxy.d.ts +0 -3
  72. package/dist/core/tagProxyTypes.d.ts +0 -1
  73. package/dist/types/for.d.ts +0 -23
  74. package/dist/types/mount.d.ts +0 -20
  75. package/dist/types/repeat.d.ts +0 -24
  76. package/dist/types/show.d.ts +0 -31
  77. package/dist/types/switch.d.ts +0 -27
  78. /package/dist/{core/tagProxyTypes.js → components/Mount/types.js} +0 -0
  79. /package/dist/{types/for.js → components/Observer/types.js} +0 -0
  80. /package/dist/{types/mount.js → components/OptionalWrapper/types.js} +0 -0
  81. /package/dist/{types/repeat.js → components/Repeat/types.js} +0 -0
  82. /package/dist/{types/show.js → components/Show/types.js} +0 -0
  83. /package/dist/{types/switch.js → components/Slacker/types.js} +0 -0
@@ -1,3 +1,87 @@
1
- export const htmlTags = [
2
- "a", "abbr", "address", "article", "aside", "b", "bdi", "bdo", "blockquote", "button", "canvas", "cite", "code", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hr", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "menu", "meter", "nav", "ol", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "section", "select", "small", "span", "strong", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "tr", "u", "ul", "var", "video"
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,11 +1,9 @@
1
- import type { TagProxyCategory } from "./tagProxyTypes";
1
+ import type { RegistryCategory } from "../types";
2
2
  /**
3
3
  * 플러그인 등록을 위한 타입
4
4
  * Register 인터페이스의 각 카테고리에 대해 부분적으로 등록 가능
5
5
  */
6
- type PluginRegistration = {
7
- [K in TagProxyCategory]?: Record<string, any>;
8
- };
6
+ type PluginRegistration = Partial<Record<RegistryCategory, Record<string, any>>>;
9
7
  /**
10
8
  * 플러그인 컴포넌트를 등록하고 관리하는 싱글턴 클래스
11
9
  *
@@ -42,6 +40,7 @@ export declare class PluginManager {
42
40
  private static instance;
43
41
  private plugins;
44
42
  private constructor();
43
+ private getCategory;
45
44
  /**
46
45
  * PluginManager 인스턴스를 가져옵니다
47
46
  */
@@ -72,18 +71,18 @@ export declare class PluginManager {
72
71
  /**
73
72
  * 등록된 플러그인 컴포넌트를 가져옵니다 (내부용)
74
73
  */
75
- static get<K extends TagProxyCategory>(category: K, name: string): any;
74
+ static get<K extends RegistryCategory>(category: K, name: string): any;
76
75
  /**
77
76
  * 특정 카테고리의 모든 플러그인을 가져옵니다 (내부용)
78
77
  */
79
- static getAll<K extends TagProxyCategory>(category: K): Map<string, any>;
78
+ static getAll<K extends RegistryCategory>(category: K): Map<string, any>;
80
79
  /**
81
80
  * 플러그인이 등록되어 있는지 확인합니다
82
81
  */
83
- static has<K extends TagProxyCategory>(category: K, name: string): boolean;
82
+ static has<K extends RegistryCategory>(category: K, name: string): boolean;
84
83
  /**
85
84
  * 플러그인을 제거합니다
86
85
  */
87
- static unregister<K extends TagProxyCategory>(category: K, name: string): boolean;
86
+ static unregister<K extends RegistryCategory>(category: K, name: string): boolean;
88
87
  }
89
88
  export {};
@@ -1,3 +1,4 @@
1
+ const DEFAULT_CATEGORIES = ["show", "for", "repeat", "mount", "switch", "base"];
1
2
  /**
2
3
  * 플러그인 컴포넌트를 등록하고 관리하는 싱글턴 클래스
3
4
  *
@@ -32,16 +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
- mount: new Map(),
40
- switch: new Map(),
41
- base: new Map(),
42
- };
36
+ plugins = new Map();
43
37
  constructor() {
44
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;
45
51
  }
46
52
  /**
47
53
  * PluginManager 인스턴스를 가져옵니다
@@ -72,8 +78,7 @@ export class PluginManager {
72
78
  */
73
79
  static register(plugins) {
74
80
  const instance = PluginManager.getInstance();
75
- Object.keys(plugins).forEach((category) => {
76
- const components = plugins[category];
81
+ Object.entries(plugins).forEach(([category, components]) => {
77
82
  if (components) {
78
83
  Object.entries(components).forEach(([name, component]) => {
79
84
  instance.registerOne(category, name, component);
@@ -85,34 +90,34 @@ export class PluginManager {
85
90
  * 단일 플러그인 컴포넌트를 등록합니다 (내부용)
86
91
  */
87
92
  registerOne(category, name, component) {
88
- this.plugins[category].set(name, component);
93
+ this.getCategory(category).set(name, component);
89
94
  }
90
95
  /**
91
96
  * 등록된 플러그인 컴포넌트를 가져옵니다 (내부용)
92
97
  */
93
98
  static get(category, name) {
94
99
  const instance = PluginManager.getInstance();
95
- return instance.plugins[category].get(name);
100
+ return instance.plugins.get(category)?.get(name);
96
101
  }
97
102
  /**
98
103
  * 특정 카테고리의 모든 플러그인을 가져옵니다 (내부용)
99
104
  */
100
105
  static getAll(category) {
101
106
  const instance = PluginManager.getInstance();
102
- return instance.plugins[category];
107
+ return instance.getCategory(category);
103
108
  }
104
109
  /**
105
110
  * 플러그인이 등록되어 있는지 확인합니다
106
111
  */
107
112
  static has(category, name) {
108
113
  const instance = PluginManager.getInstance();
109
- return instance.plugins[category].has(name);
114
+ return instance.plugins.get(category)?.has(name) ?? false;
110
115
  }
111
116
  /**
112
117
  * 플러그인을 제거합니다
113
118
  */
114
119
  static unregister(category, name) {
115
120
  const instance = PluginManager.getInstance();
116
- return instance.plugins[category].delete(name);
121
+ return instance.plugins.get(category)?.delete(name) ?? false;
117
122
  }
118
123
  }
@@ -0,0 +1,2 @@
1
+ import type { RegistryCategory } from "../types";
2
+ export declare function createProxy<TProxy extends object, TBase extends object = TProxy>(base: TBase, renderForTag: (tag: any) => React.ForwardRefExoticComponent<any>, category: RegistryCategory): TProxy;
@@ -1,7 +1,7 @@
1
1
  import { htmlTags } from "../constants/htmlTags";
2
2
  import { PluginManager } from "./PluginManager";
3
- export function createTagProxy(base, renderForTag, category) {
4
- const tagEntries = htmlTags.reduce((acc, tag) => {
3
+ export function createProxy(base, renderForTag, category) {
4
+ const tagEntries = Object.keys(htmlTags).reduce((acc, tag) => {
5
5
  acc[tag] = renderForTag(tag);
6
6
  return acc;
7
7
  }, {});
package/dist/index.d.ts CHANGED
@@ -4,9 +4,11 @@ export * from './components/Observer';
4
4
  export * from './components/OptionalWrapper';
5
5
  export * from './components/Repeat';
6
6
  export * from './components/Show';
7
- export * from './components/Switch';
8
7
  export * from './components/Slacker';
9
- export * from './components/Slot';
8
+ export * from './components/Slot/Slot';
9
+ export * from './components/Switch/Switch';
10
10
  export * from './hooks/useIntersectionObserver';
11
11
  export { PluginManager } from './core/PluginManager';
12
- export { UtilinentRegister } from './types/register';
12
+ export { UtilinentRegister } from './types';
13
+ export { createProxy } from './core/createProxy';
14
+ export { BaseTypeHelperFn, ProxyType } from './types';
package/dist/index.js CHANGED
@@ -1,11 +1,16 @@
1
+ // export components
1
2
  export * from './components/For';
2
3
  export * from './components/Mount';
3
4
  export * from './components/Observer';
4
5
  export * from './components/OptionalWrapper';
5
6
  export * from './components/Repeat';
6
7
  export * from './components/Show';
7
- export * from './components/Switch';
8
8
  export * from './components/Slacker';
9
- export * from './components/Slot';
9
+ export * from './components/Slot/Slot';
10
+ export * from './components/Switch/Switch';
11
+ // export hooks
10
12
  export * from './hooks/useIntersectionObserver';
13
+ // export Register and PluginManager
11
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 {};
@@ -1,47 +1,4 @@
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 interface OptionalWrapperProps<T = unknown> {
9
- when: T;
10
- children: React.ReactNode;
11
- wrapper: (children: React.ReactNode) => React.ReactNode;
12
- fallback?: (children: React.ReactNode) => React.ReactNode;
13
- }
14
- export interface ObserverProps extends Fallback {
15
- children?: React.ReactNode | ((isIntersecting: boolean) => React.ReactNode);
16
- threshold?: number | number[];
17
- rootMargin?: string;
18
- triggerOnce?: boolean;
19
- onIntersect?: (isIntersecting: boolean, entry: IntersectionObserverEntry) => void;
20
- }
21
- export interface MountProps extends Fallback {
22
- children: React.ReactNode | (() => React.ReactNode | Promise<React.ReactNode>);
23
- onError?: (error: unknown) => void;
24
- }
25
- export type ExtractValues<T, K extends keyof T> = T extends any ? T[K] : never;
26
- type IsUnion<T, U = T> = T extends any ? [U] extends [T] ? false : true : false;
27
- 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;
28
- export type GetLiteralKeys<T> = {
29
- [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;
30
- }[keyof T];
31
- export type LiteralKeys<T> = [GetLiteralKeys<T>] extends [never] ? keyof T : GetLiteralKeys<T>;
32
- export type SlackerFallbackProps = {
33
- isLoading: boolean;
34
- error: Error | null;
35
- retry: () => void;
36
- };
37
- export type SlackerProps<T = any> = {
38
- children: (loaded: T) => React.ReactNode;
39
- errorFallback?: React.ReactNode | ((props: SlackerFallbackProps) => React.ReactNode);
40
- loadingFallback?: React.ReactNode;
41
- threshold?: number | number[];
42
- rootMargin?: string;
43
- loader: () => Promise<T> | T;
44
- onError?: (error: Error) => void;
45
- maxRetries?: number;
46
- retryDelay?: number;
47
- };
1
+ export * from "./register";
2
+ export * from "./RegistryCategory";
3
+ export * from "./tagHelper";
4
+ export * from "./utils";
@@ -1 +1,4 @@
1
- export {};
1
+ export * from "./register";
2
+ export * from "./RegistryCategory";
3
+ export * from "./tagHelper";
4
+ export * from "./utils";
@@ -1,20 +1,6 @@
1
+ import { RegistryCategory } from "./RegistryCategory";
1
2
  export interface UtilinentRegister {
2
3
  }
3
- export type UtilinentRegisterShow = UtilinentRegister extends {
4
- show: infer Show;
5
- } ? Show : never;
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;
15
- export type UtilinentRegisterMount = UtilinentRegister extends {
16
- mount: infer Mount;
17
- } ? Mount : never;
18
- export type UtilinentRegisterSwitch = UtilinentRegister extends {
19
- switch: infer Switch;
20
- } ? Switch : 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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ilokesto/utilinent",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ilokesto/utilinent.git"
@@ -1,2 +0,0 @@
1
- import type { ForType } from "../types/for";
2
- export declare const For: ForType;
@@ -1,2 +0,0 @@
1
- import type { MountType } from "../types/mount";
2
- export declare const Mount: MountType;
@@ -1,2 +0,0 @@
1
- import type { RepeatType } from "../types/repeat";
2
- export declare const Repeat: RepeatType;
@@ -1,2 +0,0 @@
1
- import type { ShowType } from "../types/show";
2
- export declare const Show: ShowType;
@@ -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,4 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { MatchProps, SwitchType } from "../types/switch";
3
- export declare const Switch: SwitchType;
4
- export declare function Match<T>({ when, children }: MatchProps<T>): ReactNode;
@@ -1,39 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Children, Fragment, createElement, forwardRef, isValidElement, } from "react";
3
- import { createTagProxy } from "../core/createTagProxy";
4
- import { resolveWhen } from "../utils/resolveWhen";
5
- const flattenChildren = (nodes) => Children.toArray(nodes).flatMap((child) => {
6
- if (isValidElement(child) && child.type === Fragment) {
7
- return flattenChildren(child.props.children);
8
- }
9
- return [child];
10
- });
11
- const isMatchElement = (child) => isValidElement(child) && child.type === Match;
12
- function BaseSwitch({ children, fallback = null }) {
13
- const childArray = flattenChildren(children);
14
- for (const child of childArray) {
15
- if (!isMatchElement(child)) {
16
- continue;
17
- }
18
- const { when } = child.props;
19
- if (!resolveWhen(when)) {
20
- continue;
21
- }
22
- return child;
23
- }
24
- return fallback;
25
- }
26
- const renderForTag = (tag) =>
27
- // forward ref so consumers can attach a ref to the underlying DOM element
28
- forwardRef(function Render({ children, fallback = null, ...props }, ref) {
29
- return createElement(tag, { ...props, ref }, _jsx(BaseSwitch, { fallback: fallback, children: children }));
30
- });
31
- export const Switch = createTagProxy(BaseSwitch, renderForTag, "switch");
32
- export function Match({ when, children }) {
33
- if (!resolveWhen(when)) {
34
- return null;
35
- }
36
- return typeof children === "function"
37
- ? children(when)
38
- : children;
39
- }
@@ -1,3 +0,0 @@
1
- import type { TagProxyCategory } from "./tagProxyTypes";
2
- export type { TagProxyCategory } from "./tagProxyTypes";
3
- export declare function createTagProxy<TProxy extends object, TBase extends object = TProxy>(base: TBase, renderForTag: (tag: any) => any, category: TagProxyCategory): TProxy;
@@ -1 +0,0 @@
1
- export type TagProxyCategory = "show" | "for" | "repeat" | "mount" | "switch" | "base";
@@ -1,23 +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
- }
8
- type ForTagHelper<K extends HtmlTag> = {
9
- <const T extends Array<unknown>>(props: ForProps<T> & Omit<React.ComponentPropsWithRef<K>, 'children'>): React.ReactNode;
10
- };
11
- type ForRegisterHelper<C> = C extends React.ComponentType<infer P> ? {
12
- <const T extends Array<unknown>>(props: Omit<P, "children"> & ForProps<T>): React.ReactNode;
13
- } : C;
14
- export type ForType = {
15
- <const T extends Array<unknown>>(props: ForProps<T>): React.ReactNode;
16
- } & {
17
- [K in HtmlTag]: ForTagHelper<K>;
18
- } & {
19
- [K in keyof UtilinentRegisterFor]: ForRegisterHelper<UtilinentRegisterFor[K]>;
20
- } & {
21
- [K in keyof UtilinentRegisterBase]: ForRegisterHelper<UtilinentRegisterBase[K]>;
22
- };
23
- export {};
@@ -1,20 +0,0 @@
1
- import { ComponentPropsWithRef } from "react";
2
- import { HtmlTag } from "../constants/htmlTags";
3
- import { MountProps } from ".";
4
- import { UtilinentRegisterBase, UtilinentRegisterMount } from "./register";
5
- type MountTagHelper<K extends HtmlTag> = {
6
- (props: MountProps & Omit<ComponentPropsWithRef<K>, "children">): React.ReactNode;
7
- };
8
- type MountRegisterHelper<C> = C extends React.ComponentType<infer P> ? {
9
- (props: Omit<P, "children"> & MountProps): React.ReactNode;
10
- } : C;
11
- export type MountType = {
12
- (props: MountProps): React.ReactNode;
13
- } & {
14
- [K in HtmlTag]: MountTagHelper<K>;
15
- } & {
16
- [K in keyof UtilinentRegisterMount]: MountRegisterHelper<UtilinentRegisterMount[K]>;
17
- } & {
18
- [K in keyof UtilinentRegisterBase]: MountRegisterHelper<UtilinentRegisterBase[K]>;
19
- };
20
- export {};
@@ -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 {};