juxscript 1.0.2 → 1.0.4

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 (71) hide show
  1. package/README.md +37 -92
  2. package/bin/cli.js +57 -56
  3. package/lib/components/alert.ts +240 -0
  4. package/lib/components/app.ts +216 -82
  5. package/lib/components/badge.ts +164 -0
  6. package/lib/components/button.ts +188 -53
  7. package/lib/components/card.ts +75 -61
  8. package/lib/components/chart.ts +17 -15
  9. package/lib/components/checkbox.ts +228 -0
  10. package/lib/components/code.ts +66 -152
  11. package/lib/components/container.ts +104 -208
  12. package/lib/components/data.ts +1 -3
  13. package/lib/components/datepicker.ts +226 -0
  14. package/lib/components/dialog.ts +258 -0
  15. package/lib/components/docs-data.json +1697 -388
  16. package/lib/components/dropdown.ts +244 -0
  17. package/lib/components/element.ts +271 -0
  18. package/lib/components/fileupload.ts +319 -0
  19. package/lib/components/footer.ts +37 -18
  20. package/lib/components/header.ts +53 -33
  21. package/lib/components/heading.ts +119 -0
  22. package/lib/components/helpers.ts +34 -0
  23. package/lib/components/hero.ts +57 -31
  24. package/lib/components/include.ts +292 -0
  25. package/lib/components/input.ts +166 -78
  26. package/lib/components/layout.ts +144 -18
  27. package/lib/components/list.ts +83 -74
  28. package/lib/components/loading.ts +263 -0
  29. package/lib/components/main.ts +43 -17
  30. package/lib/components/menu.ts +108 -24
  31. package/lib/components/modal.ts +50 -21
  32. package/lib/components/nav.ts +60 -18
  33. package/lib/components/paragraph.ts +111 -0
  34. package/lib/components/progress.ts +276 -0
  35. package/lib/components/radio.ts +236 -0
  36. package/lib/components/req.ts +300 -0
  37. package/lib/components/script.ts +33 -74
  38. package/lib/components/select.ts +247 -0
  39. package/lib/components/sidebar.ts +86 -36
  40. package/lib/components/style.ts +47 -70
  41. package/lib/components/switch.ts +261 -0
  42. package/lib/components/table.ts +47 -24
  43. package/lib/components/tabs.ts +105 -63
  44. package/lib/components/theme-toggle.ts +361 -0
  45. package/lib/components/token-calculator.ts +380 -0
  46. package/lib/components/tooltip.ts +244 -0
  47. package/lib/components/view.ts +36 -20
  48. package/lib/components/write.ts +284 -0
  49. package/lib/globals.d.ts +21 -0
  50. package/lib/jux.ts +172 -68
  51. package/lib/presets/notion.css +521 -0
  52. package/lib/presets/notion.jux +27 -0
  53. package/lib/reactivity/state.ts +364 -0
  54. package/machinery/compiler.js +126 -38
  55. package/machinery/generators/html.js +2 -3
  56. package/machinery/server.js +2 -2
  57. package/package.json +29 -3
  58. package/lib/components/import.ts +0 -430
  59. package/lib/components/node.ts +0 -200
  60. package/lib/components/reactivity.js +0 -104
  61. package/lib/components/theme.ts +0 -97
  62. package/lib/layouts/notion.css +0 -258
  63. package/lib/styles/base-theme.css +0 -186
  64. package/lib/styles/dark-theme.css +0 -144
  65. package/lib/styles/light-theme.css +0 -144
  66. package/lib/styles/tokens/dark.css +0 -86
  67. package/lib/styles/tokens/light.css +0 -86
  68. package/lib/templates/index.juxt +0 -33
  69. package/lib/themes/dark.css +0 -86
  70. package/lib/themes/light.css +0 -86
  71. /package/lib/{styles → presets}/global.css +0 -0
@@ -0,0 +1,258 @@
1
+ import { getOrCreateContainer } from './helpers.js';
2
+
3
+ /**
4
+ * Dialog component options
5
+ */
6
+ export interface DialogOptions {
7
+ title?: string;
8
+ message?: string;
9
+ confirmText?: string;
10
+ cancelText?: string;
11
+ variant?: 'default' | 'danger' | 'warning';
12
+ onConfirm?: () => void;
13
+ onCancel?: () => void;
14
+ style?: string;
15
+ class?: string;
16
+ }
17
+
18
+ /**
19
+ * Dialog component state
20
+ */
21
+ type DialogState = {
22
+ title: string;
23
+ message: string;
24
+ confirmText: string;
25
+ cancelText: string;
26
+ variant: string;
27
+ style: string;
28
+ class: string;
29
+ isOpen: boolean;
30
+ };
31
+
32
+ /**
33
+ * Dialog component - Confirmation dialogs
34
+ *
35
+ * Usage:
36
+ * jux.dialog('confirm-delete', {
37
+ * title: 'Delete Item?',
38
+ * message: 'This action cannot be undone.',
39
+ * confirmText: 'Delete',
40
+ * cancelText: 'Cancel',
41
+ * variant: 'danger',
42
+ * onConfirm: () => console.log('Deleted'),
43
+ * onCancel: () => console.log('Cancelled')
44
+ * }).render();
45
+ *
46
+ * // Open/close programmatically
47
+ * const dialog = jux.dialog('my-dialog').render();
48
+ * dialog.open();
49
+ * dialog.close();
50
+ */
51
+ export class Dialog {
52
+ state: DialogState;
53
+ container: HTMLElement | null = null;
54
+ _id: string;
55
+ id: string;
56
+ private _onConfirm?: () => void;
57
+ private _onCancel?: () => void;
58
+
59
+ constructor(id: string, options: DialogOptions = {}) {
60
+ this._id = id;
61
+ this.id = id;
62
+ this._onConfirm = options.onConfirm;
63
+ this._onCancel = options.onCancel;
64
+
65
+ this.state = {
66
+ title: options.title ?? 'Confirm',
67
+ message: options.message ?? '',
68
+ confirmText: options.confirmText ?? 'Confirm',
69
+ cancelText: options.cancelText ?? 'Cancel',
70
+ variant: options.variant ?? 'default',
71
+ style: options.style ?? '',
72
+ class: options.class ?? '',
73
+ isOpen: false
74
+ };
75
+ }
76
+
77
+ /* -------------------------
78
+ * Fluent API
79
+ * ------------------------- */
80
+
81
+ title(value: string): this {
82
+ this.state.title = value;
83
+ return this;
84
+ }
85
+
86
+ message(value: string): this {
87
+ this.state.message = value;
88
+ return this;
89
+ }
90
+
91
+ confirmText(value: string): this {
92
+ this.state.confirmText = value;
93
+ return this;
94
+ }
95
+
96
+ cancelText(value: string): this {
97
+ this.state.cancelText = value;
98
+ return this;
99
+ }
100
+
101
+ variant(value: 'default' | 'danger' | 'warning'): this {
102
+ this.state.variant = value;
103
+ return this;
104
+ }
105
+
106
+ style(value: string): this {
107
+ this.state.style = value;
108
+ return this;
109
+ }
110
+
111
+ class(value: string): this {
112
+ this.state.class = value;
113
+ return this;
114
+ }
115
+
116
+ onConfirm(handler: () => void): this {
117
+ this._onConfirm = handler;
118
+ return this;
119
+ }
120
+
121
+ onCancel(handler: () => void): this {
122
+ this._onCancel = handler;
123
+ return this;
124
+ }
125
+
126
+ /* -------------------------
127
+ * Methods
128
+ * ------------------------- */
129
+
130
+ open(): void {
131
+ this.state.isOpen = true;
132
+ const element = document.getElementById(this._id);
133
+ if (element) {
134
+ element.style.display = 'flex';
135
+ setTimeout(() => element.classList.add('jux-dialog-open'), 10);
136
+ }
137
+ }
138
+
139
+ close(): void {
140
+ this.state.isOpen = false;
141
+ const element = document.getElementById(this._id);
142
+ if (element) {
143
+ element.classList.remove('jux-dialog-open');
144
+ setTimeout(() => element.style.display = 'none', 200);
145
+ }
146
+ }
147
+
148
+ /* -------------------------
149
+ * Render
150
+ * ------------------------- */
151
+
152
+ render(targetId?: string): this {
153
+ let container: HTMLElement;
154
+
155
+ if (targetId) {
156
+ const target = document.querySelector(targetId);
157
+ if (!target || !(target instanceof HTMLElement)) {
158
+ throw new Error(`Dialog: Target element "${targetId}" not found`);
159
+ }
160
+ container = target;
161
+ } else {
162
+ container = document.body;
163
+ }
164
+
165
+ this.container = container;
166
+ const { title, message, confirmText, cancelText, variant, style, class: className } = this.state;
167
+
168
+ // Overlay
169
+ const overlay = document.createElement('div');
170
+ overlay.className = 'jux-dialog';
171
+ overlay.id = this._id;
172
+ overlay.style.display = 'none';
173
+ overlay.setAttribute('role', 'dialog');
174
+ overlay.setAttribute('aria-modal', 'true');
175
+
176
+ if (className) {
177
+ overlay.className += ` ${className}`;
178
+ }
179
+
180
+ if (style) {
181
+ overlay.setAttribute('style', style);
182
+ }
183
+
184
+ // Click outside to close
185
+ overlay.addEventListener('click', (e) => {
186
+ if (e.target === overlay) {
187
+ this.close();
188
+ if (this._onCancel) {
189
+ this._onCancel();
190
+ }
191
+ }
192
+ });
193
+
194
+ // Dialog container
195
+ const dialogBox = document.createElement('div');
196
+ dialogBox.className = `jux-dialog-box jux-dialog-${variant}`;
197
+
198
+ // Header
199
+ const header = document.createElement('div');
200
+ header.className = 'jux-dialog-header';
201
+
202
+ const titleEl = document.createElement('h3');
203
+ titleEl.className = 'jux-dialog-title';
204
+ titleEl.textContent = title;
205
+ header.appendChild(titleEl);
206
+
207
+ // Body
208
+ const body = document.createElement('div');
209
+ body.className = 'jux-dialog-body';
210
+ body.textContent = message;
211
+
212
+ // Footer
213
+ const footer = document.createElement('div');
214
+ footer.className = 'jux-dialog-footer';
215
+
216
+ const cancelBtn = document.createElement('button');
217
+ cancelBtn.className = 'jux-dialog-button jux-dialog-button-cancel';
218
+ cancelBtn.textContent = cancelText;
219
+ cancelBtn.addEventListener('click', () => {
220
+ this.close();
221
+ if (this._onCancel) {
222
+ this._onCancel();
223
+ }
224
+ });
225
+
226
+ const confirmBtn = document.createElement('button');
227
+ confirmBtn.className = `jux-dialog-button jux-dialog-button-confirm jux-dialog-button-${variant}`;
228
+ confirmBtn.textContent = confirmText;
229
+ confirmBtn.addEventListener('click', () => {
230
+ this.close();
231
+ if (this._onConfirm) {
232
+ this._onConfirm();
233
+ }
234
+ });
235
+
236
+ footer.appendChild(cancelBtn);
237
+ footer.appendChild(confirmBtn);
238
+
239
+ dialogBox.appendChild(header);
240
+ dialogBox.appendChild(body);
241
+ dialogBox.appendChild(footer);
242
+ overlay.appendChild(dialogBox);
243
+ container.appendChild(overlay);
244
+
245
+ return this;
246
+ }
247
+
248
+ renderTo(juxComponent: any): this {
249
+ if (!juxComponent?._id) {
250
+ throw new Error('Dialog.renderTo: Invalid component');
251
+ }
252
+ return this.render(`#${juxComponent._id}`);
253
+ }
254
+ }
255
+
256
+ export function dialog(id: string, options: DialogOptions = {}): Dialog {
257
+ return new Dialog(id, options);
258
+ }