boottent-design 0.1.13 → 0.1.14

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 (32) hide show
  1. package/dist/boottent-design.hooks.cjs.js +1 -1
  2. package/dist/boottent-design.hooks.es.js +1 -1
  3. package/dist/boottent-design.main.cjs.js +1 -1
  4. package/dist/boottent-design.main.es.js +5 -5
  5. package/dist/boottent-design.provider.cjs.js +1 -1
  6. package/dist/boottent-design.provider.es.js +1 -1
  7. package/dist/boottent-design.ui.cjs.js +1 -1
  8. package/dist/boottent-design.ui.es.js +2 -2
  9. package/dist/boottent-design.utils.cjs.js +1 -1
  10. package/dist/boottent-design.utils.es.js +1 -1
  11. package/dist/{index-eA7KeYI8.js → index-BKXoRMW5.js} +1 -1
  12. package/dist/{index-C9dzv_CG.cjs → index-yzR38MB_.cjs} +1 -1
  13. package/dist/portal-manager-9WO01tNb.cjs +1 -0
  14. package/dist/portal-manager-nNJ4SIa2.js +95 -0
  15. package/dist/portal-provider-BCk-4D3n.js +110 -0
  16. package/dist/portal-provider-BXqsWpse.cjs +1 -0
  17. package/dist/{tooltip-Beq86Qug.js → tooltip-CHFJbt8g.js} +179 -180
  18. package/dist/{tooltip-DWrSWVcc.cjs → tooltip-CO-z-DrW.cjs} +1 -1
  19. package/dist/types/hooks.d.ts +14 -13
  20. package/dist/types/main.d.ts +31 -16
  21. package/dist/types/types.d.ts +25 -11
  22. package/dist/types/ui.d.ts +7 -7
  23. package/dist/types/utils.d.ts +24 -14
  24. package/dist/use-portal-B-W1cxuO.js +32 -0
  25. package/dist/use-portal-D6lcMQX5.cjs +1 -0
  26. package/package.json +1 -1
  27. package/dist/portal-manager-6YGufJVr.cjs +0 -1
  28. package/dist/portal-manager-CttMAZAu.js +0 -73
  29. package/dist/portal-provider-Bwzhqa3P.js +0 -106
  30. package/dist/portal-provider-DXVWgfhq.cjs +0 -1
  31. package/dist/use-portal-Ck3GPJQN.cjs +0 -1
  32. package/dist/use-portal-TiMPd_EZ.js +0 -17
@@ -1,5 +1,6 @@
1
1
  import { ClassProp } from 'class-variance-authority/types';
2
2
  import { ClassValue } from 'clsx';
3
+ import { default as default_2 } from 'react';
3
4
  import * as React_2 from 'react';
4
5
  import * as ToastPrimitives from '@radix-ui/react-toast';
5
6
  import { VariantProps } from 'class-variance-authority';
@@ -36,7 +37,7 @@ declare interface AlertPortalOptions {
36
37
  declare interface AlertProps {
37
38
  id?: string;
38
39
  title?: string;
39
- description: string | React.ReactNode;
40
+ description: string | default_2.ReactNode;
40
41
  confirmText?: string;
41
42
  onConfirm?: () => void;
42
43
  size?: "sm" | "md" | "lg" | "fit";
@@ -54,7 +55,7 @@ declare interface DialogPortalOptions {
54
55
  declare interface DialogProps {
55
56
  id?: string;
56
57
  title: string;
57
- content: string | React.ReactNode;
58
+ content: string | default_2.ReactNode;
58
59
  onConfirm?: () => void;
59
60
  onCancel?: () => void;
60
61
  onClose?: () => void;
@@ -70,15 +71,15 @@ declare interface ModalPortalOptions {
70
71
 
71
72
  declare interface ModalProps {
72
73
  id?: string;
73
- title: string;
74
- description?: string | React.ReactNode;
75
- subDescription?: string | React.ReactNode;
74
+ title?: string;
75
+ description: string | default_2.ReactNode;
76
+ subDescription?: string | default_2.ReactNode;
76
77
  size?: "sm" | "md" | "lg" | "fit";
77
78
  confirmText?: string;
78
79
  onConfirm?: () => void;
79
80
  cancelText?: string;
80
- onClose: () => void;
81
- contents?: React.ReactNode;
81
+ onClose?: () => void;
82
+ contents?: default_2.ReactNode;
82
83
  className?: string;
83
84
  }
84
85
 
@@ -90,19 +91,28 @@ declare class PortalManager {
90
91
  private processQueue;
91
92
  private isPortalOpen;
92
93
  subscribe(listener: Listener): () => void;
93
- showPortal(type: PortalType, props: any): string | null;
94
+ showPortal<T extends PortalType>(type: T, props: PortalTypeMap[T] & {
95
+ id?: string;
96
+ }): string | null;
94
97
  setPortalOpen(id: string, isOpen: boolean): void;
95
- getIsPortalOpen(id: string): boolean | undefined;
98
+ getIsPortalOpen(id: string): boolean;
96
99
  getOpenPortals(): string[];
97
100
  private generateId;
98
101
  }
99
102
 
100
103
  export declare const portalManager: PortalManager;
101
104
 
102
- export declare type PortalOptions = ModalPortalOptions | ToastPortalOptions | AlertPortalOptions | DialogPortalOptions;
105
+ declare type PortalOptions = ModalPortalOptions | ToastPortalOptions | AlertPortalOptions | DialogPortalOptions;
103
106
 
104
107
  export declare type PortalType = "modal" | "toast" | "alert" | "dialog";
105
108
 
109
+ declare interface PortalTypeMap {
110
+ modal: ModalProps;
111
+ toast: ToasterProps;
112
+ alert: AlertProps;
113
+ dialog: DialogProps;
114
+ }
115
+
106
116
  export declare const reducer: (state: State, action: Action) => State;
107
117
 
108
118
  declare interface State {
@@ -130,10 +140,10 @@ export declare function toaster(): {
130
140
 
131
141
  declare type ToasterProps = ToastProps & ToastViewportProps & {
132
142
  id?: string;
133
- title?: React.ReactNode;
134
- description?: React.ReactNode;
143
+ title?: default_2.ReactNode;
144
+ description?: default_2.ReactNode;
135
145
  action?: () => void;
136
- actionText?: string | React.ReactNode;
146
+ actionText?: string | default_2.ReactNode;
137
147
  closeButton?: boolean;
138
148
  onClose?: () => void;
139
149
  };
@@ -141,7 +151,7 @@ declare type ToasterProps = ToastProps & ToastViewportProps & {
141
151
  declare interface ToastPortalOptions {
142
152
  id: string;
143
153
  type: "toast";
144
- props: ToastProps;
154
+ props: ToasterProps;
145
155
  }
146
156
 
147
157
  declare type ToastPositionsType = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
@@ -0,0 +1,32 @@
1
+ import { p as o } from "./portal-manager-nNJ4SIa2.js";
2
+ import { useState as c, useEffect as u } from "react";
3
+ const b = () => {
4
+ const [l, r] = c([]);
5
+ return u(() => {
6
+ const t = (n, a) => {
7
+ r(a ? (s) => s.includes(n.id) ? s : [...s, n.id] : (s) => s.filter((i) => i !== n.id));
8
+ }, e = o.subscribe(t);
9
+ return r(o.getOpenPortals()), () => {
10
+ e();
11
+ };
12
+ }, []), { modal: (t) => {
13
+ const { onClose: e = () => {
14
+ } } = t;
15
+ return o.showPortal("modal", { ...t, onClose: e });
16
+ }, toast: (t) => {
17
+ let e;
18
+ return typeof t == "string" ? e = { description: t } : e = t, o.showPortal("toast", e);
19
+ }, alert: (t) => {
20
+ let e;
21
+ return typeof t == "string" ? e = { description: t, onClose: () => {
22
+ } } : e = { ...t, onClose: t.onClose || (() => {
23
+ }) }, o.showPortal("alert", e);
24
+ }, dialog: (t) => {
25
+ const { onClose: e = () => {
26
+ } } = t;
27
+ return o.showPortal("dialog", { ...t, onClose: e });
28
+ }, getIsOpen: (t) => o.getIsPortalOpen(t), openPortals: l };
29
+ };
30
+ export {
31
+ b as u
32
+ };
@@ -0,0 +1 @@
1
+ "use strict";const r=require("./portal-manager-9WO01tNb.cjs"),s=require("react"),u=()=>{const[l,a]=s.useState([]);return s.useEffect(()=>{const t=(n,i)=>{a(i?o=>o.includes(n.id)?o:[...o,n.id]:o=>o.filter(c=>c!==n.id))},e=r.portalManager.subscribe(t);return a(r.portalManager.getOpenPortals()),()=>{e()}},[]),{modal:t=>{const{onClose:e=()=>{}}=t;return r.portalManager.showPortal("modal",{...t,onClose:e})},toast:t=>{let e;return typeof t=="string"?e={description:t}:e=t,r.portalManager.showPortal("toast",e)},alert:t=>{let e;return typeof t=="string"?e={description:t,onClose:()=>{}}:e={...t,onClose:t.onClose||(()=>{})},r.portalManager.showPortal("alert",e)},dialog:t=>{const{onClose:e=()=>{}}=t;return r.portalManager.showPortal("dialog",{...t,onClose:e})},getIsOpen:t=>r.portalManager.getIsPortalOpen(t),openPortals:l}};exports.usePortal=u;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "boottent-design",
3
3
  "private": false,
4
- "version": "0.1.13",
4
+ "version": "0.1.14",
5
5
  "description": "부트텐트 디자인시스템 라이브러리",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1 +0,0 @@
1
- "use strict";var o=Object.defineProperty;var l=(i,s,e)=>s in i?o(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var a=(i,s,e)=>l(i,typeof s!="symbol"?s+"":s,e);class h{constructor(){a(this,"listeners",[]);a(this,"portals",new Map);a(this,"queue",[]);a(this,"isProcessing",!1)}processQueue(){if(this.isProcessing||this.queue.length===0)return;this.isProcessing=!0;const s=this.queue.shift();s&&s(),this.isProcessing=!1,this.processQueue()}isPortalOpen(s){var e;return this.portals.has(s)&&((e=this.portals.get(s))==null?void 0:e.isOpen)}subscribe(s){return this.listeners.push(s),()=>{this.listeners=this.listeners.filter(e=>e!==s)}}showPortal(s,e){const t=e.id||this.generateId(s);if(this.isPortalOpen(t))return console.warn(`Portal with id "${t}" is already open.`),t;let r=null;switch(s){case"modal":r={id:t,type:s,props:e};break;case"toast":r={id:t,type:s,props:e};break;case"alert":r={id:t,type:s,props:e};break;case"dialog":r={id:t,type:s,props:e};break}return r&&(this.portals.set(t,{isOpen:!0,options:r}),this.queue.push(()=>{this.listeners.forEach(n=>n(r,!0))}),this.processQueue()),t}setPortalOpen(s,e){if(this.portals.has(s)){const t=this.portals.get(s);t.isOpen=e,this.portals.set(s,{...t}),this.queue.push(()=>{this.listeners.forEach(r=>r(t.options,e))}),this.processQueue()}}getIsPortalOpen(s){var e;return(e=this.portals.get(s))==null?void 0:e.isOpen}getOpenPortals(){return Array.from(this.portals.entries()).filter(([s,e])=>e.isOpen).map(([s,e])=>s)}generateId(s){return`${s}_${Date.now()}`}}const u=new h;exports.portalManager=u;
@@ -1,73 +0,0 @@
1
- var o = Object.defineProperty;
2
- var l = (i, s, e) => s in i ? o(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
3
- var a = (i, s, e) => l(i, typeof s != "symbol" ? s + "" : s, e);
4
- class h {
5
- constructor() {
6
- a(this, "listeners", []);
7
- a(this, "portals", /* @__PURE__ */ new Map());
8
- a(this, "queue", []);
9
- a(this, "isProcessing", !1);
10
- }
11
- processQueue() {
12
- if (this.isProcessing || this.queue.length === 0) return;
13
- this.isProcessing = !0;
14
- const s = this.queue.shift();
15
- s && s(), this.isProcessing = !1, this.processQueue();
16
- }
17
- isPortalOpen(s) {
18
- var e;
19
- return this.portals.has(s) && ((e = this.portals.get(s)) == null ? void 0 : e.isOpen);
20
- }
21
- subscribe(s) {
22
- return this.listeners.push(s), () => {
23
- this.listeners = this.listeners.filter((e) => e !== s);
24
- };
25
- }
26
- showPortal(s, e) {
27
- const t = e.id || this.generateId(s);
28
- if (this.isPortalOpen(t))
29
- return console.warn(`Portal with id "${t}" is already open.`), t;
30
- let r = null;
31
- switch (s) {
32
- case "modal":
33
- r = { id: t, type: s, props: e };
34
- break;
35
- case "toast":
36
- r = { id: t, type: s, props: e };
37
- break;
38
- case "alert":
39
- r = { id: t, type: s, props: e };
40
- break;
41
- case "dialog":
42
- r = { id: t, type: s, props: e };
43
- break;
44
- }
45
- return r && (this.portals.set(t, { isOpen: !0, options: r }), this.queue.push(() => {
46
- this.listeners.forEach((n) => n(r, !0));
47
- }), this.processQueue()), t;
48
- }
49
- setPortalOpen(s, e) {
50
- if (this.portals.has(s)) {
51
- const t = this.portals.get(s);
52
- t.isOpen = e, this.portals.set(s, { ...t }), this.queue.push(() => {
53
- this.listeners.forEach(
54
- (r) => r(t.options, e)
55
- );
56
- }), this.processQueue();
57
- }
58
- }
59
- getIsPortalOpen(s) {
60
- var e;
61
- return (e = this.portals.get(s)) == null ? void 0 : e.isOpen;
62
- }
63
- getOpenPortals() {
64
- return Array.from(this.portals.entries()).filter(([s, e]) => e.isOpen).map(([s, e]) => s);
65
- }
66
- generateId(s) {
67
- return `${s}_${Date.now()}`;
68
- }
69
- }
70
- const c = new h();
71
- export {
72
- c as p
73
- };
@@ -1,106 +0,0 @@
1
- import { jsxs as l, jsx as a } from "react/jsx-runtime";
2
- import { P as f, T as m, D as p, f as C, M as P } from "./tooltip-Beq86Qug.js";
3
- import { useState as h, useEffect as c } from "react";
4
- import { p as u } from "./portal-manager-CttMAZAu.js";
5
- import { toast as T } from "./boottent-design.utils.es.js";
6
- const j = () => {
7
- const [t, d] = h([]);
8
- c(() => {
9
- const s = u.subscribe(
10
- (e, o) => {
11
- d((i) => {
12
- if (o) {
13
- if (!i.find((r) => r.id === e.id))
14
- return [...i, { ...e, isOpen: o }];
15
- } else
16
- return i.map(
17
- (r) => r.id === e.id ? { ...r, isOpen: o } : r
18
- );
19
- return i;
20
- });
21
- }
22
- );
23
- return () => {
24
- s();
25
- };
26
- }, []);
27
- const n = (s) => {
28
- u.setPortalOpen(s, !1);
29
- };
30
- return c(() => {
31
- t.forEach((s) => {
32
- if (!s.isOpen) {
33
- const e = setTimeout(() => {
34
- d((o) => o.filter((i) => i.id !== s.id));
35
- }, 300);
36
- return () => clearTimeout(e);
37
- }
38
- });
39
- }, [t]), c(() => {
40
- const s = (e) => {
41
- const o = e.props;
42
- T({
43
- title: o.title,
44
- description: o.description,
45
- action: o.action,
46
- closeButton: o.closeButton,
47
- variant: o.variant,
48
- position: o.position,
49
- size: o.size,
50
- className: o.className
51
- }), n(e.id);
52
- };
53
- t.forEach((e) => {
54
- e.type === "toast" && e.isOpen && s(e);
55
- });
56
- }, [t, n]), /* @__PURE__ */ l(f, { children: [
57
- /* @__PURE__ */ a(m, {}),
58
- t.map((s) => {
59
- var e;
60
- if (!s.isOpen) return null;
61
- switch (s.type) {
62
- case "modal":
63
- return /* @__PURE__ */ a(
64
- P,
65
- {
66
- ...s.props,
67
- onClose: () => {
68
- s.props.onClose && s.props.onClose(), n(s.id);
69
- },
70
- description: (e = s.props.description) == null ? void 0 : e.toString()
71
- },
72
- s.id
73
- );
74
- case "alert":
75
- return /* @__PURE__ */ a(
76
- C,
77
- {
78
- ...s.props,
79
- onClose: () => {
80
- s.props.onClose && s.props.onClose(), n(s.id);
81
- }
82
- },
83
- s.id
84
- );
85
- case "dialog":
86
- return /* @__PURE__ */ a(
87
- p,
88
- {
89
- ...s.props,
90
- onClose: () => {
91
- s.props.onClose && s.props.onClose(), n(s.id);
92
- }
93
- },
94
- s.id
95
- );
96
- case "toast":
97
- return null;
98
- default:
99
- return null;
100
- }
101
- })
102
- ] });
103
- };
104
- export {
105
- j as P
106
- };
@@ -1 +0,0 @@
1
- "use strict";const c=require("react/jsx-runtime"),u=require("./tooltip-DWrSWVcc.cjs"),a=require("react"),l=require("./portal-manager-6YGufJVr.cjs"),f=require("./boottent-design.utils.cjs.js"),p=()=>{const[o,d]=a.useState([]);a.useEffect(()=>{const e=l.portalManager.subscribe((s,t)=>{d(i=>{if(t){if(!i.find(r=>r.id===s.id))return[...i,{...s,isOpen:t}]}else return i.map(r=>r.id===s.id?{...r,isOpen:t}:r);return i})});return()=>{e()}},[]);const n=e=>{l.portalManager.setPortalOpen(e,!1)};return a.useEffect(()=>{o.forEach(e=>{if(!e.isOpen){const s=setTimeout(()=>{d(t=>t.filter(i=>i.id!==e.id))},300);return()=>clearTimeout(s)}})},[o]),a.useEffect(()=>{const e=s=>{const t=s.props;f.toast({title:t.title,description:t.description,action:t.action,closeButton:t.closeButton,variant:t.variant,position:t.position,size:t.size,className:t.className}),n(s.id)};o.forEach(s=>{s.type==="toast"&&s.isOpen&&e(s)})},[o,n]),c.jsxs(u.PortalContainer,{children:[c.jsx(u.Toaster,{}),o.map(e=>{var s;if(!e.isOpen)return null;switch(e.type){case"modal":return c.jsx(u.Modal,{...e.props,onClose:()=>{e.props.onClose&&e.props.onClose(),n(e.id)},description:(s=e.props.description)==null?void 0:s.toString()},e.id);case"alert":return c.jsx(u.Alert,{...e.props,onClose:()=>{e.props.onClose&&e.props.onClose(),n(e.id)}},e.id);case"dialog":return c.jsx(u.Dialog,{...e.props,onClose:()=>{e.props.onClose&&e.props.onClose(),n(e.id)}},e.id);case"toast":return null;default:return null}})]})};exports.PortalProvider=p;
@@ -1 +0,0 @@
1
- "use strict";const r=require("./portal-manager-6YGufJVr.cjs"),s=require("react"),g=()=>{const[n,a]=s.useState([]);return s.useEffect(()=>{a(r.portalManager.getOpenPortals());const t=(o,u)=>{a(u?e=>[...e,o.id]:e=>e.filter(c=>c!==o.id))},l=r.portalManager.subscribe(t);return()=>{l()}},[]),{modal:t=>r.portalManager.showPortal("modal",t),toast:t=>r.portalManager.showPortal("toast",t),alert:t=>r.portalManager.showPortal("alert",t),dialog:t=>r.portalManager.showPortal("dialog",t),getIsOpen:t=>r.portalManager.getIsPortalOpen(t),openPortals:n}};exports.usePortal=g;
@@ -1,17 +0,0 @@
1
- import { p as r } from "./portal-manager-CttMAZAu.js";
2
- import { useState as c, useEffect as i } from "react";
3
- const b = () => {
4
- const [a, o] = c([]);
5
- return i(() => {
6
- o(r.getOpenPortals());
7
- const t = (s, l) => {
8
- o(l ? (e) => [...e, s.id] : (e) => e.filter((u) => u !== s.id));
9
- }, n = r.subscribe(t);
10
- return () => {
11
- n();
12
- };
13
- }, []), { modal: (t) => r.showPortal("modal", t), toast: (t) => r.showPortal("toast", t), alert: (t) => r.showPortal("alert", t), dialog: (t) => r.showPortal("dialog", t), getIsOpen: (t) => r.getIsPortalOpen(t), openPortals: a };
14
- };
15
- export {
16
- b as u
17
- };