universal-modal-monorepo 1.0.0

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 (106) hide show
  1. package/AUTHORS +5 -0
  2. package/CHANGELOG.md +10 -0
  3. package/LICENSE +21 -0
  4. package/NOTICE +6 -0
  5. package/README.md +239 -0
  6. package/SECURITY.md +21 -0
  7. package/docs/ACCESSIBILITY.md +43 -0
  8. package/docs/API.md +56 -0
  9. package/docs/THEMING.md +65 -0
  10. package/examples/angular/app.component.html +137 -0
  11. package/examples/angular/app.component.ts +53 -0
  12. package/examples/angular/index.html +99 -0
  13. package/examples/angular/main.js +121 -0
  14. package/examples/angular/styles.css +25 -0
  15. package/examples/index.html +53 -0
  16. package/examples/react/App.tsx +242 -0
  17. package/examples/react/index.html +26 -0
  18. package/examples/react/main.js +144 -0
  19. package/examples/react/styles.css +1 -0
  20. package/examples/shared/gallery.css +177 -0
  21. package/examples/vanilla/index.html +89 -0
  22. package/examples/vanilla/main.js +174 -0
  23. package/examples/vanilla/styles.css +1 -0
  24. package/examples/vue/App.vue +190 -0
  25. package/examples/vue/index.html +23 -0
  26. package/examples/vue/main.js +174 -0
  27. package/examples/vue/styles.css +1 -0
  28. package/examples/web-component/index.html +190 -0
  29. package/examples/web-component/main.js +58 -0
  30. package/examples/web-component/styles.css +11 -0
  31. package/package.json +36 -0
  32. package/packages/universal-modal/AUTHORS +5 -0
  33. package/packages/universal-modal/CHANGELOG.md +10 -0
  34. package/packages/universal-modal/LICENSE +21 -0
  35. package/packages/universal-modal/NOTICE +6 -0
  36. package/packages/universal-modal/README.md +29 -0
  37. package/packages/universal-modal/package.json +83 -0
  38. package/packages/universal-modal/scripts/copy-styles.mjs +11 -0
  39. package/packages/universal-modal/src/core/constants.ts +50 -0
  40. package/packages/universal-modal/src/core/event-emitter.ts +46 -0
  41. package/packages/universal-modal/src/core/focus-trap.ts +101 -0
  42. package/packages/universal-modal/src/core/index.ts +39 -0
  43. package/packages/universal-modal/src/core/modal-engine.ts +410 -0
  44. package/packages/universal-modal/src/core/modal-stack.ts +68 -0
  45. package/packages/universal-modal/src/core/scroll-lock.ts +78 -0
  46. package/packages/universal-modal/src/core/theme.ts +50 -0
  47. package/packages/universal-modal/src/core/types.ts +196 -0
  48. package/packages/universal-modal/src/core/utils.ts +114 -0
  49. package/packages/universal-modal/src/dom/index.ts +1 -0
  50. package/packages/universal-modal/src/dom/modal-renderer.ts +191 -0
  51. package/packages/universal-modal/src/index.ts +2 -0
  52. package/packages/universal-modal/src/styles/modal.css +368 -0
  53. package/packages/universal-modal/tsconfig.json +24 -0
  54. package/packages/universal-modal/tsup.config.ts +12 -0
  55. package/packages/universal-modal-angular/AUTHORS +5 -0
  56. package/packages/universal-modal-angular/CHANGELOG.md +9 -0
  57. package/packages/universal-modal-angular/LICENSE +21 -0
  58. package/packages/universal-modal-angular/NOTICE +6 -0
  59. package/packages/universal-modal-angular/README.md +12 -0
  60. package/packages/universal-modal-angular/package.json +85 -0
  61. package/packages/universal-modal-angular/src/index.ts +10 -0
  62. package/packages/universal-modal-angular/src/universal-modal.component.ts +275 -0
  63. package/packages/universal-modal-angular/tsconfig.json +20 -0
  64. package/packages/universal-modal-angular/tsup.config.ts +10 -0
  65. package/packages/universal-modal-react/AUTHORS +5 -0
  66. package/packages/universal-modal-react/CHANGELOG.md +9 -0
  67. package/packages/universal-modal-react/LICENSE +21 -0
  68. package/packages/universal-modal-react/NOTICE +6 -0
  69. package/packages/universal-modal-react/README.md +12 -0
  70. package/packages/universal-modal-react/package.json +87 -0
  71. package/packages/universal-modal-react/src/UniversalModal.tsx +340 -0
  72. package/packages/universal-modal-react/src/index.ts +10 -0
  73. package/packages/universal-modal-react/tsconfig.json +19 -0
  74. package/packages/universal-modal-react/tsup.config.ts +13 -0
  75. package/packages/universal-modal-vanilla/AUTHORS +5 -0
  76. package/packages/universal-modal-vanilla/CHANGELOG.md +9 -0
  77. package/packages/universal-modal-vanilla/LICENSE +21 -0
  78. package/packages/universal-modal-vanilla/NOTICE +6 -0
  79. package/packages/universal-modal-vanilla/README.md +12 -0
  80. package/packages/universal-modal-vanilla/package.json +79 -0
  81. package/packages/universal-modal-vanilla/src/create-modal.ts +125 -0
  82. package/packages/universal-modal-vanilla/src/index.ts +14 -0
  83. package/packages/universal-modal-vanilla/tsconfig.json +18 -0
  84. package/packages/universal-modal-vanilla/tsup.config.ts +10 -0
  85. package/packages/universal-modal-vue/AUTHORS +5 -0
  86. package/packages/universal-modal-vue/CHANGELOG.md +9 -0
  87. package/packages/universal-modal-vue/LICENSE +21 -0
  88. package/packages/universal-modal-vue/NOTICE +6 -0
  89. package/packages/universal-modal-vue/README.md +12 -0
  90. package/packages/universal-modal-vue/package.json +83 -0
  91. package/packages/universal-modal-vue/src/UniversalModal.ts +342 -0
  92. package/packages/universal-modal-vue/src/index.ts +10 -0
  93. package/packages/universal-modal-vue/tsconfig.json +18 -0
  94. package/packages/universal-modal-vue/tsup.config.ts +10 -0
  95. package/packages/universal-modal-web-component/AUTHORS +5 -0
  96. package/packages/universal-modal-web-component/CHANGELOG.md +9 -0
  97. package/packages/universal-modal-web-component/LICENSE +21 -0
  98. package/packages/universal-modal-web-component/NOTICE +6 -0
  99. package/packages/universal-modal-web-component/README.md +12 -0
  100. package/packages/universal-modal-web-component/package.json +83 -0
  101. package/packages/universal-modal-web-component/src/index.ts +11 -0
  102. package/packages/universal-modal-web-component/src/universal-modal-element.ts +424 -0
  103. package/packages/universal-modal-web-component/tsconfig.json +18 -0
  104. package/packages/universal-modal-web-component/tsup.config.ts +10 -0
  105. package/scripts/copy-styles.mjs +11 -0
  106. package/scripts/serve-examples.mjs +48 -0
@@ -0,0 +1,340 @@
1
+ import {
2
+ useEffect,
3
+ useId,
4
+ useRef,
5
+ useState,
6
+ type CSSProperties,
7
+ type ReactNode,
8
+ } from 'react';
9
+ import { createPortal } from 'react-dom';
10
+ import {
11
+ CSS_CLASSES,
12
+ ModalEngine,
13
+ type CloseReason,
14
+ type ModalOptions,
15
+ type ModalPlacement,
16
+ type ModalRole,
17
+ type ModalSize,
18
+ type ModalTheme,
19
+ } from '@poluru-labs/universal-modal';
20
+
21
+ export interface UniversalModalProps {
22
+ open: boolean;
23
+ onOpenChange?: (open: boolean) => void;
24
+ size?: ModalSize;
25
+ placement?: ModalPlacement;
26
+ title?: string;
27
+ description?: string;
28
+ persistent?: boolean;
29
+ closeOnEsc?: boolean;
30
+ closeOnBackdrop?: boolean;
31
+ showCloseIcon?: boolean;
32
+ role?: ModalRole;
33
+ confirmText?: string;
34
+ cancelText?: string;
35
+ hideActions?: boolean;
36
+ loading?: boolean;
37
+ zIndexBase?: number;
38
+ className?: string;
39
+ style?: CSSProperties;
40
+ theme?: ModalTheme;
41
+ ariaLabel?: string;
42
+ ariaLabelledBy?: string;
43
+ ariaDescribedBy?: string;
44
+ children?: ReactNode;
45
+ header?: ReactNode;
46
+ footer?: ReactNode;
47
+ onConfirm?: () => void | Promise<void>;
48
+ onCancel?: () => void | Promise<void>;
49
+ beforeOpen?: ModalOptions['beforeOpen'];
50
+ afterOpen?: ModalOptions['afterOpen'];
51
+ beforeClose?: ModalOptions['beforeClose'];
52
+ afterClose?: ModalOptions['afterClose'];
53
+ }
54
+
55
+ export function UniversalModal({
56
+ open,
57
+ onOpenChange,
58
+ size = 'md',
59
+ placement = 'center',
60
+ title,
61
+ description,
62
+ persistent = false,
63
+ closeOnEsc = true,
64
+ closeOnBackdrop = true,
65
+ showCloseIcon = true,
66
+ role = 'dialog',
67
+ confirmText = 'Confirm',
68
+ cancelText = 'Cancel',
69
+ hideActions = false,
70
+ loading: loadingProp,
71
+ zIndexBase,
72
+ className,
73
+ style,
74
+ theme,
75
+ ariaLabel,
76
+ ariaLabelledBy,
77
+ ariaDescribedBy,
78
+ children,
79
+ header,
80
+ footer,
81
+ onConfirm,
82
+ onCancel,
83
+ beforeOpen,
84
+ afterOpen,
85
+ beforeClose,
86
+ afterClose,
87
+ }: UniversalModalProps) {
88
+ const reactId = useId();
89
+ const id = `um-${reactId.replace(/:/g, '')}`;
90
+ const titleId = `${id}-title`;
91
+ const descId = `${id}-description`;
92
+
93
+ const rootRef = useRef<HTMLDivElement>(null);
94
+ const backdropRef = useRef<HTMLDivElement>(null);
95
+ const dialogRef = useRef<HTMLDivElement>(null);
96
+ const panelRef = useRef<HTMLDivElement>(null);
97
+ const closeRef = useRef<HTMLButtonElement>(null);
98
+ const confirmRef = useRef<HTMLButtonElement>(null);
99
+ const cancelRef = useRef<HTMLButtonElement>(null);
100
+
101
+ const engineRef = useRef<ModalEngine | null>(null);
102
+ const onOpenChangeRef = useRef(onOpenChange);
103
+ onOpenChangeRef.current = onOpenChange;
104
+ const [mounted, setMounted] = useState(false);
105
+ const [visible, setVisible] = useState(open);
106
+ const [loading, setLoading] = useState(Boolean(loadingProp));
107
+
108
+ useEffect(() => {
109
+ setMounted(true);
110
+ }, []);
111
+
112
+ useEffect(() => {
113
+ if (loadingProp !== undefined) {
114
+ setLoading(loadingProp);
115
+ engineRef.current?.setLoading(loadingProp);
116
+ }
117
+ }, [loadingProp]);
118
+
119
+ useEffect(() => {
120
+ if (!mounted || !rootRef.current || !backdropRef.current || !dialogRef.current || !panelRef.current) {
121
+ return;
122
+ }
123
+
124
+ const engine = new ModalEngine({
125
+ id,
126
+ size,
127
+ placement,
128
+ title,
129
+ description,
130
+ persistent,
131
+ closeOnEsc,
132
+ closeOnBackdrop,
133
+ showCloseIcon,
134
+ role,
135
+ confirmText,
136
+ cancelText,
137
+ hideActions,
138
+ zIndexBase,
139
+ className,
140
+ theme,
141
+ ariaLabel,
142
+ ariaLabelledBy: ariaLabelledBy ?? (title ? titleId : undefined),
143
+ ariaDescribedBy: ariaDescribedBy ?? (description ? descId : undefined),
144
+ beforeOpen,
145
+ afterOpen,
146
+ beforeClose,
147
+ afterClose,
148
+ onConfirm,
149
+ onCancel,
150
+ manageDom: true,
151
+ });
152
+
153
+ engine.attach({
154
+ root: rootRef.current,
155
+ backdrop: backdropRef.current,
156
+ dialog: dialogRef.current,
157
+ panel: panelRef.current,
158
+ closeButton: closeRef.current,
159
+ confirmButton: confirmRef.current,
160
+ cancelButton: cancelRef.current,
161
+ });
162
+
163
+ const unsubs = [
164
+ engine.on('openChange', (isOpen) => {
165
+ setVisible(isOpen);
166
+ onOpenChangeRef.current?.(isOpen);
167
+ }),
168
+ engine.on('loadingChange', setLoading),
169
+ engine.on('afterClose', () => setVisible(false)),
170
+ ];
171
+
172
+ engineRef.current = engine;
173
+
174
+ return () => {
175
+ for (const off of unsubs) off();
176
+ engine.destroy();
177
+ engineRef.current = null;
178
+ };
179
+ // Engine is created once per mount; options synced below.
180
+ // eslint-disable-next-line react-hooks/exhaustive-deps
181
+ }, [mounted, id]);
182
+
183
+ useEffect(() => {
184
+ engineRef.current?.updateOptions({
185
+ size,
186
+ placement,
187
+ title,
188
+ description,
189
+ persistent,
190
+ closeOnEsc,
191
+ closeOnBackdrop,
192
+ showCloseIcon,
193
+ role,
194
+ confirmText,
195
+ cancelText,
196
+ hideActions,
197
+ zIndexBase,
198
+ className,
199
+ theme,
200
+ ariaLabel,
201
+ ariaLabelledBy: ariaLabelledBy ?? (title ? titleId : undefined),
202
+ ariaDescribedBy: ariaDescribedBy ?? (description ? descId : undefined),
203
+ beforeOpen,
204
+ afterOpen,
205
+ beforeClose,
206
+ afterClose,
207
+ onConfirm,
208
+ onCancel,
209
+ });
210
+ }, [
211
+ size,
212
+ placement,
213
+ title,
214
+ description,
215
+ persistent,
216
+ closeOnEsc,
217
+ closeOnBackdrop,
218
+ showCloseIcon,
219
+ role,
220
+ confirmText,
221
+ cancelText,
222
+ hideActions,
223
+ zIndexBase,
224
+ className,
225
+ theme,
226
+ ariaLabel,
227
+ ariaLabelledBy,
228
+ ariaDescribedBy,
229
+ beforeOpen,
230
+ afterOpen,
231
+ beforeClose,
232
+ afterClose,
233
+ onConfirm,
234
+ onCancel,
235
+ titleId,
236
+ descId,
237
+ ]);
238
+
239
+ useEffect(() => {
240
+ const engine = engineRef.current;
241
+ if (!engine) return;
242
+ if (open && !engine.isOpen) void engine.open();
243
+ if (!open && engine.isOpen) void engine.close('programmatic');
244
+ }, [open]);
245
+
246
+ if (!mounted || typeof document === 'undefined') return null;
247
+
248
+ const rootClass = [
249
+ CSS_CLASSES.root,
250
+ visible || open ? CSS_CLASSES.open : '',
251
+ loading ? CSS_CLASSES.loading : '',
252
+ className ?? '',
253
+ ]
254
+ .filter(Boolean)
255
+ .join(' ');
256
+
257
+ return createPortal(
258
+ <div
259
+ ref={rootRef}
260
+ className={rootClass}
261
+ style={style}
262
+ hidden={!visible && !open}
263
+ aria-hidden={!(visible || open)}
264
+ >
265
+ <div ref={backdropRef} className={CSS_CLASSES.backdrop} data-um-backdrop="" />
266
+ <div ref={dialogRef} className={CSS_CLASSES.dialog}>
267
+ <div ref={panelRef} className={CSS_CLASSES.panel} data-size={size} data-placement={placement}>
268
+ {showCloseIcon ? (
269
+ <button
270
+ ref={closeRef}
271
+ type="button"
272
+ className={CSS_CLASSES.close}
273
+ aria-label="Close dialog"
274
+ >
275
+ <svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false">
276
+ <path
277
+ d="M6.4 6.4l11.2 11.2M17.6 6.4L6.4 17.6"
278
+ stroke="currentColor"
279
+ strokeWidth="2"
280
+ strokeLinecap="round"
281
+ />
282
+ </svg>
283
+ </button>
284
+ ) : null}
285
+
286
+ {(header || title || description) && (
287
+ <div className={CSS_CLASSES.header}>
288
+ {header ?? (
289
+ <>
290
+ {title ? (
291
+ <h2 id={titleId} className={CSS_CLASSES.title}>
292
+ {title}
293
+ </h2>
294
+ ) : null}
295
+ {description ? (
296
+ <p id={descId} className={CSS_CLASSES.description}>
297
+ {description}
298
+ </p>
299
+ ) : null}
300
+ </>
301
+ )}
302
+ </div>
303
+ )}
304
+
305
+ <div className={CSS_CLASSES.body}>{children}</div>
306
+
307
+ {(footer || !hideActions) && (
308
+ <div className={CSS_CLASSES.footer}>
309
+ {footer ?? (
310
+ <div className={CSS_CLASSES.actions}>
311
+ <button
312
+ ref={cancelRef}
313
+ type="button"
314
+ className={CSS_CLASSES.cancel}
315
+ disabled={loading}
316
+ >
317
+ {cancelText}
318
+ </button>
319
+ <button
320
+ ref={confirmRef}
321
+ type="button"
322
+ className={CSS_CLASSES.confirm}
323
+ disabled={loading}
324
+ aria-busy={loading}
325
+ >
326
+ {confirmText}
327
+ <span className={CSS_CLASSES.spinner} aria-hidden="true" />
328
+ </button>
329
+ </div>
330
+ )}
331
+ </div>
332
+ )}
333
+ </div>
334
+ </div>
335
+ </div>,
336
+ document.body,
337
+ );
338
+ }
339
+
340
+ export type { CloseReason, ModalPlacement, ModalRole, ModalSize };
@@ -0,0 +1,10 @@
1
+ export { UniversalModal, type UniversalModalProps } from './UniversalModal';
2
+ export type {
3
+ CloseReason,
4
+ ModalOptions,
5
+ ModalPlacement,
6
+ ModalRole,
7
+ ModalSize,
8
+ ModalState,
9
+ ModalTheme,
10
+ } from '@poluru-labs/universal-modal';
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "jsx": "react-jsx",
8
+ "strict": true,
9
+ "skipLibCheck": true,
10
+ "noUnusedLocals": true,
11
+ "noUnusedParameters": true,
12
+ "esModuleInterop": true,
13
+ "isolatedModules": true,
14
+ "rootDir": "src",
15
+ "outDir": "dist"
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: { index: 'src/index.ts' },
5
+ format: ['esm', 'cjs'],
6
+ dts: true,
7
+ sourcemap: true,
8
+ clean: true,
9
+ external: ['react', 'react-dom', 'react/jsx-runtime', '@poluru-labs/universal-modal'],
10
+ esbuildOptions(options) {
11
+ options.jsx = 'automatic';
12
+ },
13
+ });
@@ -0,0 +1,5 @@
1
+ # Authors
2
+
3
+ Subrahmanyam Poluru <mail.polurus@gmail.com>
4
+ https://polurus.com
5
+ https://www.linkedin.com/in/polurus/
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 — 2026-08-01
4
+
5
+ ### Added
6
+ - Initial public release
7
+ - Depends on `@poluru-labs/universal-modal@1.0.0`
8
+ - MIT licensed (see LICENSE)
9
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Subrahmanyam Poluru
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ @poluru-labs/universal-modal
2
+ Copyright (c) 2026 Subrahmanyam Poluru
3
+
4
+ This product is developed and maintained by .
5
+ Homepage: https://polurus.com
6
+ Contact: mail.polurus@gmail.com
@@ -0,0 +1,12 @@
1
+ # @poluru-labs/universal-modal-vanilla
2
+
3
+ ```bash
4
+ npm install @poluru-labs/universal-modal-vanilla
5
+ ```
6
+
7
+ ```ts
8
+ import { createModal } from '@poluru-labs/universal-modal-vanilla';
9
+ import '@poluru-labs/universal-modal/styles.css';
10
+ ```
11
+
12
+ Author: Subrahmanyam Poluru · mail.polurus@gmail.com
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@poluru-labs/universal-modal-vanilla",
3
+ "version": "1.0.0",
4
+ "description": "Vanilla JS/TS adapter for @poluru-labs/universal-modal",
5
+ "author": {
6
+ "name": "Subrahmanyam Poluru",
7
+ "email": "mail.polurus@gmail.com",
8
+ "url": "https://polurus.com"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "Subrahmanyam Poluru",
13
+ "email": "mail.polurus@gmail.com",
14
+ "url": "https://www.linkedin.com/in/polurus/"
15
+ }
16
+ ],
17
+ "license": "MIT",
18
+ "homepage": "https://github.com/poluru-labs/universal-modal#readme",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/poluru-labs/universal-modal.git",
22
+ "directory": "packages/universal-modal-vanilla"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/poluru-labs/universal-modal/issues",
26
+ "email": "mail.polurus@gmail.com"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org/"
31
+ },
32
+ "keywords": [
33
+ "modal",
34
+ "dialog",
35
+ "vanilla-js",
36
+ "typescript",
37
+ "poluru-labs"
38
+ ],
39
+ "type": "module",
40
+ "main": "./dist/index.cjs",
41
+ "module": "./dist/index.js",
42
+ "types": "./dist/index.d.ts",
43
+ "exports": {
44
+ ".": {
45
+ "types": "./dist/index.d.ts",
46
+ "import": "./dist/index.js",
47
+ "require": "./dist/index.cjs"
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "LICENSE",
54
+ "AUTHORS",
55
+ "NOTICE",
56
+ "README.md",
57
+ "CHANGELOG.md"
58
+ ],
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "typecheck": "tsc --noEmit",
62
+ "clean": "rm -rf dist *.tgz",
63
+ "prepublishOnly": "npm run clean && npm run typecheck && npm run build"
64
+ },
65
+ "dependencies": {
66
+ "@poluru-labs/universal-modal": "1.0.0"
67
+ },
68
+ "devDependencies": {
69
+ "tsup": "^8.3.5",
70
+ "typescript": "^5.7.2"
71
+ },
72
+ "engines": {
73
+ "node": ">=18"
74
+ },
75
+ "funding": {
76
+ "type": "individual",
77
+ "url": "https://polurus.com"
78
+ }
79
+ }
@@ -0,0 +1,125 @@
1
+ import {
2
+ ModalEngine,
3
+ ModalRenderer,
4
+ type CloseReason,
5
+ type ModalEngineConfig,
6
+ type ModalEventMap,
7
+ type ModalOptions,
8
+ type ModalState,
9
+ type ResolvedModalOptions,
10
+ } from '@poluru-labs/universal-modal';
11
+
12
+ export interface CreateModalOptions extends ModalEngineConfig {
13
+ /** Auto-mount into container (default: true). */
14
+ autoMount?: boolean;
15
+ }
16
+
17
+ export interface VanillaModal {
18
+ readonly id: string;
19
+ readonly el: HTMLElement;
20
+ readonly isOpen: boolean;
21
+ readonly isLoading: boolean;
22
+ getState: () => ModalState;
23
+ getOptions: () => Readonly<ResolvedModalOptions>;
24
+ updateOptions: (partial: Partial<ModalOptions>) => void;
25
+ setContent: (options: Partial<ModalOptions>) => void;
26
+ open: () => Promise<boolean>;
27
+ close: (reason?: CloseReason) => Promise<boolean>;
28
+ confirm: () => Promise<void>;
29
+ cancel: () => Promise<void>;
30
+ setLoading: (loading: boolean) => void;
31
+ on: <K extends keyof ModalEventMap>(
32
+ event: K,
33
+ listener: (payload: ModalEventMap[K]) => void,
34
+ ) => () => void;
35
+ off: <K extends keyof ModalEventMap>(
36
+ event: K,
37
+ listener: (payload: ModalEventMap[K]) => void,
38
+ ) => void;
39
+ destroy: () => void;
40
+ }
41
+
42
+ /**
43
+ * Vanilla JS / TypeScript factory.
44
+ */
45
+ export function createModal(options: CreateModalOptions = {}): VanillaModal {
46
+ const { autoMount = true, ...engineOptions } = options;
47
+ const engine = new ModalEngine(engineOptions);
48
+ const renderer = new ModalRenderer(engine);
49
+
50
+ if (autoMount) {
51
+ renderer.mount();
52
+ }
53
+
54
+ return {
55
+ get id() {
56
+ return engine.id;
57
+ },
58
+ get el() {
59
+ return renderer.elements.root;
60
+ },
61
+ get isOpen() {
62
+ return engine.isOpen;
63
+ },
64
+ get isLoading() {
65
+ return engine.isLoading;
66
+ },
67
+ getState: () => engine.getState(),
68
+ getOptions: () => engine.getOptions(),
69
+ updateOptions: (partial) => {
70
+ renderer.syncContent(partial);
71
+ },
72
+ setContent: (partial) => {
73
+ renderer.syncContent(partial);
74
+ },
75
+ open: () => engine.open(),
76
+ close: (reason) => engine.close(reason),
77
+ confirm: () => engine.confirm(),
78
+ cancel: () => engine.cancel(),
79
+ setLoading: (loading) => engine.setLoading(loading),
80
+ on: (event, listener) => engine.on(event, listener),
81
+ off: (event, listener) => engine.off(event, listener),
82
+ destroy: () => {
83
+ renderer.destroy();
84
+ engine.destroy();
85
+ },
86
+ };
87
+ }
88
+
89
+ /** Imperative helper: open a one-shot confirmation dialog. */
90
+ export function confirmModal(
91
+ options: CreateModalOptions & { message?: string },
92
+ ): Promise<boolean> {
93
+ const { message, body, afterClose, onConfirm, onCancel, ...rest } = options;
94
+
95
+ return new Promise((resolve) => {
96
+ let settled = false;
97
+ const settle = (value: boolean) => {
98
+ if (settled) return;
99
+ settled = true;
100
+ resolve(value);
101
+ };
102
+
103
+ const modal = createModal({
104
+ role: 'alertdialog',
105
+ hideActions: false,
106
+ ...rest,
107
+ body: body ?? (message ? `<p>${message}</p>` : undefined),
108
+ onConfirm: async () => {
109
+ await onConfirm?.();
110
+ settle(true);
111
+ },
112
+ onCancel: async () => {
113
+ await onCancel?.();
114
+ settle(false);
115
+ },
116
+ afterClose: (reason: CloseReason) => {
117
+ afterClose?.(reason);
118
+ if (reason !== 'confirm') settle(false);
119
+ queueMicrotask(() => modal.destroy());
120
+ },
121
+ });
122
+
123
+ void modal.open();
124
+ });
125
+ }
@@ -0,0 +1,14 @@
1
+ export {
2
+ confirmModal,
3
+ createModal,
4
+ type CreateModalOptions,
5
+ type VanillaModal,
6
+ } from './create-modal';
7
+ export type {
8
+ CloseReason,
9
+ ModalOptions,
10
+ ModalPlacement,
11
+ ModalRole,
12
+ ModalSize,
13
+ ModalState,
14
+ } from '@poluru-labs/universal-modal';
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "noUnusedLocals": true,
10
+ "noUnusedParameters": true,
11
+ "esModuleInterop": true,
12
+ "isolatedModules": true,
13
+ "rootDir": "src",
14
+ "outDir": "dist"
15
+ },
16
+ "include": ["src/**/*"],
17
+ "exclude": ["node_modules", "dist"]
18
+ }
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: { index: 'src/index.ts' },
5
+ format: ['esm', 'cjs'],
6
+ dts: true,
7
+ sourcemap: true,
8
+ clean: true,
9
+ external: ['@poluru-labs/universal-modal'],
10
+ });