@ilokesto/utilinent 1.0.7 → 1.0.9
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/dist/components/Show/index.d.ts +5 -0
- package/dist/components/Show/index.js +5 -0
- package/dist/components/Show/processShowable.d.ts +6 -1
- package/dist/components/Show/processShowable.js +26 -6
- package/dist/components/Show/renderShowContent.d.ts +4 -0
- package/dist/components/Show/renderShowContent.js +6 -2
- package/dist/constants/htmlTags.d.ts +7 -1
- package/dist/constants/htmlTags.js +7 -1
- package/package.json +1 -1
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { ShowType } from "../../types/show";
|
|
2
|
+
/**
|
|
3
|
+
* Showable 컴포넌트는 실제로는 렌더링되지 않고,
|
|
4
|
+
* Show 컴포넌트가 이를 찾아서 when 값을 전달하고 조건부 렌더링 처리
|
|
5
|
+
* Forrable과 동일한 패턴
|
|
6
|
+
*/
|
|
2
7
|
export declare const Showable: ({ children, fallback }: {
|
|
3
8
|
children: React.ReactNode | ((value: any) => React.ReactNode);
|
|
4
9
|
fallback?: React.ReactNode;
|
|
@@ -2,6 +2,11 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createElement, forwardRef } from "react";
|
|
3
3
|
import { htmlTags } from "../../constants/htmlTags";
|
|
4
4
|
import { renderShowContent } from "./renderShowContent";
|
|
5
|
+
/**
|
|
6
|
+
* Showable 컴포넌트는 실제로는 렌더링되지 않고,
|
|
7
|
+
* Show 컴포넌트가 이를 찾아서 when 값을 전달하고 조건부 렌더링 처리
|
|
8
|
+
* Forrable과 동일한 패턴
|
|
9
|
+
*/
|
|
5
10
|
export const Showable = ({ children, fallback = null }) => {
|
|
6
11
|
return _jsx(_Fragment, { children: children });
|
|
7
12
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Showable 패턴을 처리하는 공통 함수
|
|
3
|
+
*
|
|
4
|
+
* Forrable과 동일한 패턴:
|
|
5
|
+
* - Showable을 찾아서 when 값을 기반으로 조건부 렌더링
|
|
6
|
+
* - 다른 children은 그대로 유지
|
|
7
|
+
* - Showable 위치에 렌더링 결과 삽입
|
|
3
8
|
*/
|
|
4
|
-
export declare function processShowable(children: React.ReactNode, when: any, fallback: React.ReactNode):
|
|
9
|
+
export declare function processShowable(children: React.ReactNode, when: any, fallback: React.ReactNode): import("react").ReactNode;
|
|
@@ -8,17 +8,37 @@ function isShowable(child) {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Showable 패턴을 처리하는 공통 함수
|
|
11
|
+
*
|
|
12
|
+
* Forrable과 동일한 패턴:
|
|
13
|
+
* - Showable을 찾아서 when 값을 기반으로 조건부 렌더링
|
|
14
|
+
* - 다른 children은 그대로 유지
|
|
15
|
+
* - Showable 위치에 렌더링 결과 삽입
|
|
11
16
|
*/
|
|
12
17
|
export function processShowable(children, when, fallback) {
|
|
13
18
|
const childrenArray = Children.toArray(children);
|
|
19
|
+
const showable = childrenArray.find(isShowable);
|
|
14
20
|
const shouldRender = Array.isArray(when) ? when.every(Boolean) : !!when;
|
|
21
|
+
// Showable이 없으면 children 그대로 반환 (일반 children들)
|
|
22
|
+
if (!showable) {
|
|
23
|
+
return children;
|
|
24
|
+
}
|
|
25
|
+
// Showable을 찾아서 조건부 렌더링 처리
|
|
26
|
+
const showableChildren = showable.props.children;
|
|
27
|
+
const showableFallback = showable.props.fallback ?? fallback;
|
|
28
|
+
// when 조건에 따라 Showable의 content 결정
|
|
29
|
+
let showableContent;
|
|
30
|
+
if (typeof showableChildren === "function") {
|
|
31
|
+
// 함수인 경우: when 값을 전달하고 조건부 렌더링
|
|
32
|
+
showableContent = shouldRender ? showableChildren(when) : showableFallback;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// ReactNode인 경우: 조건부 렌더링
|
|
36
|
+
showableContent = shouldRender ? showableChildren : showableFallback;
|
|
37
|
+
}
|
|
38
|
+
// children 배열에서 Showable만 교체
|
|
15
39
|
return childrenArray.map((child) => {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
const showableFallback = child.props.fallback ?? fallback;
|
|
19
|
-
if (typeof showableChildren === "function") {
|
|
20
|
-
return shouldRender ? showableChildren(when) : showableFallback;
|
|
21
|
-
}
|
|
40
|
+
if (child === showable) {
|
|
41
|
+
return showableContent;
|
|
22
42
|
}
|
|
23
43
|
return child;
|
|
24
44
|
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* children 렌더링을 처리하는 공통 함수
|
|
3
|
+
*
|
|
4
|
+
* 두 가지 사용 패턴:
|
|
5
|
+
* 1. 함수 children: Show 자체가 조건부 렌더링 (<Show when={x}>{(val) => ...}</Show>)
|
|
6
|
+
* 2. ReactNode children: Show는 항상 렌더링, Showable만 조건부 (<Show.div when={x}><Showable>...</Showable></Show.div>)
|
|
3
7
|
*/
|
|
4
8
|
export declare function renderShowContent(when: any, children: React.ReactNode | ((value: any) => React.ReactNode), fallback: React.ReactNode): React.ReactNode;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { processShowable } from "./processShowable";
|
|
2
2
|
/**
|
|
3
3
|
* children 렌더링을 처리하는 공통 함수
|
|
4
|
+
*
|
|
5
|
+
* 두 가지 사용 패턴:
|
|
6
|
+
* 1. 함수 children: Show 자체가 조건부 렌더링 (<Show when={x}>{(val) => ...}</Show>)
|
|
7
|
+
* 2. ReactNode children: Show는 항상 렌더링, Showable만 조건부 (<Show.div when={x}><Showable>...</Showable></Show.div>)
|
|
4
8
|
*/
|
|
5
9
|
export function renderShowContent(when, children, fallback) {
|
|
6
|
-
// children이 함수인 경우 (기존 방식)
|
|
10
|
+
// children이 함수인 경우 (기존 방식 - Show 자체가 조건부 렌더링)
|
|
7
11
|
if (typeof children === "function") {
|
|
8
12
|
const shouldRender = Array.isArray(when) ? when.every(Boolean) : !!when;
|
|
9
13
|
return shouldRender ? children(when) : fallback;
|
|
10
14
|
}
|
|
11
|
-
// children이 ReactNode인 경우 (Showable 패턴)
|
|
15
|
+
// children이 ReactNode인 경우 (Showable 패턴 - Show는 항상 렌더링, Showable만 조건부)
|
|
12
16
|
return processShowable(children, when, fallback);
|
|
13
17
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 지원되는 HTML 태그 목록
|
|
3
3
|
* const assertion을 사용하여 타입 레벨에서도 활용 가능
|
|
4
|
+
*
|
|
5
|
+
* 제외된 태그:
|
|
6
|
+
* - data: 일반적인 prop 이름과 충돌
|
|
7
|
+
* - map: Array.prototype.map, Map 객체와 충돌
|
|
8
|
+
* - var: JavaScript 예약어 (속성으로는 사용 가능하나 혼동 방지)
|
|
9
|
+
* - s: 너무 짧고 흔한 변수명
|
|
4
10
|
*/
|
|
5
|
-
export declare const htmlTags: readonly ["a", "abbr", "address", "article", "aside", "b", "bdi", "bdo", "blockquote", "button", "canvas", "cite", "code", "
|
|
11
|
+
export declare const htmlTags: readonly ["a", "abbr", "address", "article", "aside", "b", "bdi", "bdo", "blockquote", "button", "canvas", "cite", "code", "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", "mark", "menu", "meter", "nav", "ol", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "samp", "section", "select", "small", "span", "strong", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "tr", "u", "ul", "video"];
|
|
6
12
|
/**
|
|
7
13
|
* HTML 태그 이름의 유니온 타입
|
|
8
14
|
*/
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 지원되는 HTML 태그 목록
|
|
3
3
|
* const assertion을 사용하여 타입 레벨에서도 활용 가능
|
|
4
|
+
*
|
|
5
|
+
* 제외된 태그:
|
|
6
|
+
* - data: 일반적인 prop 이름과 충돌
|
|
7
|
+
* - map: Array.prototype.map, Map 객체와 충돌
|
|
8
|
+
* - var: JavaScript 예약어 (속성으로는 사용 가능하나 혼동 방지)
|
|
9
|
+
* - s: 너무 짧고 흔한 변수명
|
|
4
10
|
*/
|
|
5
11
|
export const htmlTags = [
|
|
6
|
-
"a", "abbr", "address", "article", "aside", "b", "bdi", "bdo", "blockquote", "button", "canvas", "cite", "code", "
|
|
12
|
+
"a", "abbr", "address", "article", "aside", "b", "bdi", "bdo", "blockquote", "button", "canvas", "cite", "code", "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", "mark", "menu", "meter", "nav", "ol", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "samp", "section", "select", "small", "span", "strong", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "tr", "u", "ul", "video"
|
|
7
13
|
];
|