@moriajs/ui 0.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.
@@ -0,0 +1,4 @@
1
+
2
+ > @moriajs/ui@0.1.1 build C:\Codes\node\2026\github\moriajs\packages\ui
3
+ > tsc
4
+
@@ -0,0 +1,7 @@
1
+
2
+ > @moriajs/ui@0.0.1 typecheck C:\Codes\node\2026\github\moriajs\packages\ui
3
+ > tsc --noEmit
4
+
5
+ src/index.ts(44,13): error TS2304: Cannot find name 'setTimeout'.
6
+ src/index.ts(153,30): error TS2304: Cannot find name 'Event'.
7
+  ELIFECYCLE  Command failed with exit code 2.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Guntur D
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,76 @@
1
+ /**
2
+ * @moriajs/ui
3
+ *
4
+ * UI component library for Mithril.js.
5
+ * Includes toaster notifications, modals, and layout primitives.
6
+ * CSS-framework agnostic — ships its own minimal styles.
7
+ */
8
+ import m from 'mithril';
9
+ export type ToastType = 'success' | 'error' | 'warning' | 'info';
10
+ export interface Toast {
11
+ id: string;
12
+ message: string;
13
+ type: ToastType;
14
+ duration?: number;
15
+ }
16
+ /**
17
+ * Show a toast notification.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { toast } from '@moriajs/ui';
22
+ *
23
+ * toast.success('Saved successfully!');
24
+ * toast.error('Something went wrong');
25
+ * toast.info('New update available');
26
+ * ```
27
+ */
28
+ export declare const toast: {
29
+ show(message: string, type?: ToastType, duration?: number): string;
30
+ success(message: string, duration?: number): string;
31
+ error(message: string, duration?: number): string;
32
+ warning(message: string, duration?: number): string;
33
+ info(message: string, duration?: number): string;
34
+ dismiss(id: string): void;
35
+ clear(): void;
36
+ };
37
+ /**
38
+ * Toaster container component.
39
+ * Mount once in your app layout.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { Toaster } from '@moriajs/ui';
44
+ * m(Toaster); // Place in your root layout
45
+ * ```
46
+ */
47
+ export declare const Toaster: m.Component;
48
+ export interface ModalAttrs {
49
+ /** Whether the modal is visible */
50
+ isOpen: boolean;
51
+ /** Callback when modal is closed */
52
+ onClose: () => void;
53
+ /** Modal title */
54
+ title?: string;
55
+ }
56
+ /**
57
+ * Modal dialog component.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import { Modal } from '@moriajs/ui';
62
+ *
63
+ * let showModal = false;
64
+ *
65
+ * m(Modal, {
66
+ * isOpen: showModal,
67
+ * onClose: () => { showModal = false; },
68
+ * title: 'Confirm Action',
69
+ * }, [
70
+ * m('p', 'Are you sure?'),
71
+ * m('button', { onclick: () => { showModal = false; } }, 'Yes'),
72
+ * ]);
73
+ * ```
74
+ */
75
+ export declare const Modal: m.Component<ModalAttrs>;
76
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,CAAC,MAAM,SAAS,CAAC;AAIxB,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAEjE,MAAM,WAAW,KAAK;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK;kBACA,MAAM,SAAQ,SAAS;qBAiBpB,MAAM,aAAa,MAAM;mBAG3B,MAAM,aAAa,MAAM;qBAGvB,MAAM,aAAa,MAAM;kBAG5B,MAAM,aAAa,MAAM;gBAG3B,MAAM;;CAWrB,CAAC;AASF;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,SAqCvB,CAAC;AAIF,MAAM,WAAW,UAAU;IACvB,mCAAmC;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,oCAAoC;IACpC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,kBAAkB;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,CAgEzC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,176 @@
1
+ /**
2
+ * @moriajs/ui
3
+ *
4
+ * UI component library for Mithril.js.
5
+ * Includes toaster notifications, modals, and layout primitives.
6
+ * CSS-framework agnostic — ships its own minimal styles.
7
+ */
8
+ import m from 'mithril';
9
+ /** Internal toast state */
10
+ const toasts = [];
11
+ /**
12
+ * Show a toast notification.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { toast } from '@moriajs/ui';
17
+ *
18
+ * toast.success('Saved successfully!');
19
+ * toast.error('Something went wrong');
20
+ * toast.info('New update available');
21
+ * ```
22
+ */
23
+ export const toast = {
24
+ show(message, type = 'info', duration = 3000) {
25
+ const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2)}`;
26
+ toasts.push({ id, message, type, duration });
27
+ m.redraw();
28
+ if (duration > 0) {
29
+ setTimeout(() => {
30
+ const index = toasts.findIndex((t) => t.id === id);
31
+ if (index !== -1) {
32
+ toasts.splice(index, 1);
33
+ m.redraw();
34
+ }
35
+ }, duration);
36
+ }
37
+ return id;
38
+ },
39
+ success(message, duration) {
40
+ return this.show(message, 'success', duration);
41
+ },
42
+ error(message, duration) {
43
+ return this.show(message, 'error', duration);
44
+ },
45
+ warning(message, duration) {
46
+ return this.show(message, 'warning', duration);
47
+ },
48
+ info(message, duration) {
49
+ return this.show(message, 'info', duration);
50
+ },
51
+ dismiss(id) {
52
+ const index = toasts.findIndex((t) => t.id === id);
53
+ if (index !== -1) {
54
+ toasts.splice(index, 1);
55
+ m.redraw();
56
+ }
57
+ },
58
+ clear() {
59
+ toasts.length = 0;
60
+ m.redraw();
61
+ },
62
+ };
63
+ const TOAST_COLORS = {
64
+ success: '#16a34a',
65
+ error: '#dc2626',
66
+ warning: '#d97706',
67
+ info: '#2563eb',
68
+ };
69
+ /**
70
+ * Toaster container component.
71
+ * Mount once in your app layout.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { Toaster } from '@moriajs/ui';
76
+ * m(Toaster); // Place in your root layout
77
+ * ```
78
+ */
79
+ export const Toaster = {
80
+ view() {
81
+ return m('.moria-toaster', {
82
+ style: {
83
+ position: 'fixed',
84
+ top: '1rem',
85
+ right: '1rem',
86
+ zIndex: '9999',
87
+ display: 'flex',
88
+ flexDirection: 'column',
89
+ gap: '0.5rem',
90
+ },
91
+ }, toasts.map((t) => m('.moria-toast', {
92
+ key: t.id,
93
+ 'data-type': t.type,
94
+ style: {
95
+ padding: '0.75rem 1rem',
96
+ borderRadius: '0.5rem',
97
+ color: '#fff',
98
+ fontSize: '0.875rem',
99
+ minWidth: '250px',
100
+ cursor: 'pointer',
101
+ background: TOAST_COLORS[t.type],
102
+ },
103
+ onclick: () => toast.dismiss(t.id),
104
+ }, t.message)));
105
+ },
106
+ };
107
+ /**
108
+ * Modal dialog component.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import { Modal } from '@moriajs/ui';
113
+ *
114
+ * let showModal = false;
115
+ *
116
+ * m(Modal, {
117
+ * isOpen: showModal,
118
+ * onClose: () => { showModal = false; },
119
+ * title: 'Confirm Action',
120
+ * }, [
121
+ * m('p', 'Are you sure?'),
122
+ * m('button', { onclick: () => { showModal = false; } }, 'Yes'),
123
+ * ]);
124
+ * ```
125
+ */
126
+ export const Modal = {
127
+ view(vnode) {
128
+ if (!vnode.attrs.isOpen)
129
+ return m('div', { style: { display: 'none' } });
130
+ return m('.moria-modal-overlay', {
131
+ style: {
132
+ position: 'fixed',
133
+ inset: '0',
134
+ background: 'rgba(0,0,0,0.5)',
135
+ display: 'flex',
136
+ alignItems: 'center',
137
+ justifyContent: 'center',
138
+ zIndex: '9998',
139
+ },
140
+ onclick: (e) => {
141
+ if (e.target === e.currentTarget)
142
+ vnode.attrs.onClose();
143
+ },
144
+ }, m('.moria-modal', {
145
+ style: {
146
+ background: '#fff',
147
+ borderRadius: '0.75rem',
148
+ padding: '1.5rem',
149
+ minWidth: '400px',
150
+ maxWidth: '90vw',
151
+ maxHeight: '90vh',
152
+ overflowY: 'auto',
153
+ boxShadow: '0 25px 50px -12px rgba(0,0,0,0.25)',
154
+ },
155
+ }, [
156
+ vnode.attrs.title
157
+ ? m('.moria-modal-header', {
158
+ style: {
159
+ display: 'flex',
160
+ justifyContent: 'space-between',
161
+ alignItems: 'center',
162
+ marginBottom: '1rem',
163
+ },
164
+ }, [
165
+ m('h2', { style: { margin: '0', fontSize: '1.25rem', fontWeight: '600' } }, vnode.attrs.title),
166
+ m('button', {
167
+ style: { background: 'none', border: 'none', fontSize: '1.5rem', cursor: 'pointer', color: '#6b7280' },
168
+ onclick: vnode.attrs.onClose,
169
+ }, '×'),
170
+ ])
171
+ : m('span'),
172
+ m('.moria-modal-body', vnode.children),
173
+ ]));
174
+ },
175
+ };
176
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,CAAC,MAAM,SAAS,CAAC;AAaxB,2BAA2B;AAC3B,MAAM,MAAM,GAAY,EAAE,CAAC;AAE3B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACjB,IAAI,CAAC,OAAe,EAAE,OAAkB,MAAM,EAAE,QAAQ,GAAG,IAAI;QAC3D,MAAM,EAAE,GAAG,SAAS,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC,MAAM,EAAE,CAAC;QAEX,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YACf,UAAU,CAAC,GAAG,EAAE;gBACZ,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACnD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;oBACf,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;oBACxB,CAAC,CAAC,MAAM,EAAE,CAAC;gBACf,CAAC;YACL,CAAC,EAAE,QAAQ,CAAC,CAAC;QACjB,CAAC;QAED,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,CAAC,OAAe,EAAE,QAAiB;QACtC,OA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aJS UI — Toaster, modals, and component primitives for Mithril.js",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^5.7.0",
16
+ "rimraf": "^6.0.0",
17
+ "@types/mithril": "^2.2.0"
18
+ },
19
+ "peerDependencies": {
20
+ "mithril": "^2.2.0"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Guntur-D <guntur.d.npm@gmail.com>",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/guntur-d/moriajs.git",
27
+ "directory": "packages/ui"
28
+ },
29
+ "homepage": "https://github.com/guntur-d/moriajs/tree/main/packages/ui#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/guntur-d/moriajs/issues"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "dev": "tsc --watch",
39
+ "typecheck": "tsc --noEmit",
40
+ "clean": "rimraf dist .turbo"
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,230 @@
1
+ /**
2
+ * @moriajs/ui
3
+ *
4
+ * UI component library for Mithril.js.
5
+ * Includes toaster notifications, modals, and layout primitives.
6
+ * CSS-framework agnostic — ships its own minimal styles.
7
+ */
8
+
9
+ import m from 'mithril';
10
+
11
+ // ─── Toaster ────────────────────────────────────────
12
+
13
+ export type ToastType = 'success' | 'error' | 'warning' | 'info';
14
+
15
+ export interface Toast {
16
+ id: string;
17
+ message: string;
18
+ type: ToastType;
19
+ duration?: number;
20
+ }
21
+
22
+ /** Internal toast state */
23
+ const toasts: Toast[] = [];
24
+
25
+ /**
26
+ * Show a toast notification.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { toast } from '@moriajs/ui';
31
+ *
32
+ * toast.success('Saved successfully!');
33
+ * toast.error('Something went wrong');
34
+ * toast.info('New update available');
35
+ * ```
36
+ */
37
+ export const toast = {
38
+ show(message: string, type: ToastType = 'info', duration = 3000) {
39
+ const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2)}`;
40
+ toasts.push({ id, message, type, duration });
41
+ m.redraw();
42
+
43
+ if (duration > 0) {
44
+ setTimeout(() => {
45
+ const index = toasts.findIndex((t) => t.id === id);
46
+ if (index !== -1) {
47
+ toasts.splice(index, 1);
48
+ m.redraw();
49
+ }
50
+ }, duration);
51
+ }
52
+
53
+ return id;
54
+ },
55
+ success(message: string, duration?: number) {
56
+ return this.show(message, 'success', duration);
57
+ },
58
+ error(message: string, duration?: number) {
59
+ return this.show(message, 'error', duration);
60
+ },
61
+ warning(message: string, duration?: number) {
62
+ return this.show(message, 'warning', duration);
63
+ },
64
+ info(message: string, duration?: number) {
65
+ return this.show(message, 'info', duration);
66
+ },
67
+ dismiss(id: string) {
68
+ const index = toasts.findIndex((t) => t.id === id);
69
+ if (index !== -1) {
70
+ toasts.splice(index, 1);
71
+ m.redraw();
72
+ }
73
+ },
74
+ clear() {
75
+ toasts.length = 0;
76
+ m.redraw();
77
+ },
78
+ };
79
+
80
+ const TOAST_COLORS: Record<ToastType, string> = {
81
+ success: '#16a34a',
82
+ error: '#dc2626',
83
+ warning: '#d97706',
84
+ info: '#2563eb',
85
+ };
86
+
87
+ /**
88
+ * Toaster container component.
89
+ * Mount once in your app layout.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { Toaster } from '@moriajs/ui';
94
+ * m(Toaster); // Place in your root layout
95
+ * ```
96
+ */
97
+ export const Toaster: m.Component = {
98
+ view() {
99
+ return m(
100
+ '.moria-toaster',
101
+ {
102
+ style: {
103
+ position: 'fixed',
104
+ top: '1rem',
105
+ right: '1rem',
106
+ zIndex: '9999',
107
+ display: 'flex',
108
+ flexDirection: 'column',
109
+ gap: '0.5rem',
110
+ },
111
+ },
112
+ toasts.map((t) =>
113
+ m(
114
+ '.moria-toast',
115
+ {
116
+ key: t.id,
117
+ 'data-type': t.type,
118
+ style: {
119
+ padding: '0.75rem 1rem',
120
+ borderRadius: '0.5rem',
121
+ color: '#fff',
122
+ fontSize: '0.875rem',
123
+ minWidth: '250px',
124
+ cursor: 'pointer',
125
+ background: TOAST_COLORS[t.type],
126
+ },
127
+ onclick: () => toast.dismiss(t.id),
128
+ },
129
+ t.message
130
+ )
131
+ )
132
+ );
133
+ },
134
+ };
135
+
136
+ // ─── Modal ──────────────────────────────────────────
137
+
138
+ export interface ModalAttrs {
139
+ /** Whether the modal is visible */
140
+ isOpen: boolean;
141
+ /** Callback when modal is closed */
142
+ onClose: () => void;
143
+ /** Modal title */
144
+ title?: string;
145
+ }
146
+
147
+ /**
148
+ * Modal dialog component.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * import { Modal } from '@moriajs/ui';
153
+ *
154
+ * let showModal = false;
155
+ *
156
+ * m(Modal, {
157
+ * isOpen: showModal,
158
+ * onClose: () => { showModal = false; },
159
+ * title: 'Confirm Action',
160
+ * }, [
161
+ * m('p', 'Are you sure?'),
162
+ * m('button', { onclick: () => { showModal = false; } }, 'Yes'),
163
+ * ]);
164
+ * ```
165
+ */
166
+ export const Modal: m.Component<ModalAttrs> = {
167
+ view(vnode) {
168
+ if (!vnode.attrs.isOpen) return m('div', { style: { display: 'none' } });
169
+
170
+ return m(
171
+ '.moria-modal-overlay',
172
+ {
173
+ style: {
174
+ position: 'fixed',
175
+ inset: '0',
176
+ background: 'rgba(0,0,0,0.5)',
177
+ display: 'flex',
178
+ alignItems: 'center',
179
+ justifyContent: 'center',
180
+ zIndex: '9998',
181
+ },
182
+ onclick: (e: MouseEvent) => {
183
+ if (e.target === e.currentTarget) vnode.attrs.onClose();
184
+ },
185
+ },
186
+ m(
187
+ '.moria-modal',
188
+ {
189
+ style: {
190
+ background: '#fff',
191
+ borderRadius: '0.75rem',
192
+ padding: '1.5rem',
193
+ minWidth: '400px',
194
+ maxWidth: '90vw',
195
+ maxHeight: '90vh',
196
+ overflowY: 'auto',
197
+ boxShadow: '0 25px 50px -12px rgba(0,0,0,0.25)',
198
+ },
199
+ },
200
+ [
201
+ vnode.attrs.title
202
+ ? m(
203
+ '.moria-modal-header',
204
+ {
205
+ style: {
206
+ display: 'flex',
207
+ justifyContent: 'space-between',
208
+ alignItems: 'center',
209
+ marginBottom: '1rem',
210
+ },
211
+ },
212
+ [
213
+ m('h2', { style: { margin: '0', fontSize: '1.25rem', fontWeight: '600' } }, vnode.attrs.title),
214
+ m(
215
+ 'button',
216
+ {
217
+ style: { background: 'none', border: 'none', fontSize: '1.5rem', cursor: 'pointer', color: '#6b7280' },
218
+ onclick: vnode.attrs.onClose,
219
+ },
220
+ '×'
221
+ ),
222
+ ]
223
+ )
224
+ : m('span'),
225
+ m('.moria-modal-body', vnode.children as m.Children),
226
+ ]
227
+ )
228
+ );
229
+ },
230
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src",
6
+ "lib": [
7
+ "ES2022",
8
+ "DOM"
9
+ ],
10
+ "jsx": "react",
11
+ "jsxFactory": "m"
12
+ },
13
+ "include": [
14
+ "src"
15
+ ]
16
+ }