juxscript 1.0.132 → 1.1.2

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 (133) hide show
  1. package/README.md +1 -32
  2. package/bin/cli.js +4 -2
  3. package/index.d.ts +200 -0
  4. package/index.js +96 -22
  5. package/juxconfig.example.js +58 -63
  6. package/lib/components/alert.ts +200 -0
  7. package/lib/components/app.ts +247 -0
  8. package/lib/components/badge.ts +101 -0
  9. package/lib/components/base/BaseComponent.ts +421 -0
  10. package/lib/components/base/FormInput.ts +227 -0
  11. package/lib/components/button.ts +178 -0
  12. package/lib/components/card.ts +173 -0
  13. package/lib/components/chart.ts +231 -0
  14. package/lib/components/checkbox.ts +242 -0
  15. package/lib/components/code.ts +123 -0
  16. package/lib/components/container.ts +140 -0
  17. package/lib/components/data.ts +135 -0
  18. package/lib/components/datepicker.ts +234 -0
  19. package/lib/components/dialog.ts +172 -0
  20. package/lib/components/divider.ts +100 -0
  21. package/lib/components/dropdown.ts +186 -0
  22. package/lib/components/element.ts +267 -0
  23. package/lib/components/fileupload.ts +309 -0
  24. package/lib/components/grid.ts +291 -0
  25. package/lib/components/guard.ts +92 -0
  26. package/lib/components/heading.ts +96 -0
  27. package/lib/components/helpers.ts +41 -0
  28. package/lib/components/hero.ts +224 -0
  29. package/lib/components/icon.ts +178 -0
  30. package/lib/components/icons.ts +464 -0
  31. package/lib/components/include.ts +410 -0
  32. package/lib/components/input.ts +457 -0
  33. package/lib/components/list.ts +419 -0
  34. package/lib/components/loading.ts +100 -0
  35. package/lib/components/menu.ts +275 -0
  36. package/lib/components/modal.ts +284 -0
  37. package/lib/components/nav.ts +257 -0
  38. package/lib/components/paragraph.ts +97 -0
  39. package/lib/components/progress.ts +159 -0
  40. package/lib/components/radio.ts +278 -0
  41. package/lib/components/req.ts +303 -0
  42. package/lib/components/script.ts +41 -0
  43. package/lib/components/select.ts +252 -0
  44. package/lib/components/sidebar.ts +275 -0
  45. package/lib/components/style.ts +41 -0
  46. package/lib/components/switch.ts +246 -0
  47. package/lib/components/table.ts +1249 -0
  48. package/lib/components/tabs.ts +250 -0
  49. package/lib/components/theme-toggle.ts +293 -0
  50. package/lib/components/tooltip.ts +144 -0
  51. package/lib/components/view.ts +190 -0
  52. package/lib/components/write.ts +272 -0
  53. package/lib/globals.d.ts +19 -5
  54. package/lib/layouts/default.css +260 -0
  55. package/lib/layouts/figma.css +334 -0
  56. package/lib/reactivity/state.ts +78 -0
  57. package/lib/utils/{fetch.js → fetch.ts} +206 -81
  58. package/machinery/ast.js +347 -0
  59. package/machinery/build.js +466 -0
  60. package/machinery/compiler3.js +6 -66
  61. package/machinery/config.js +6 -93
  62. package/machinery/doc-generator.js +136 -0
  63. package/machinery/imports.js +155 -0
  64. package/machinery/server.js +166 -0
  65. package/machinery/ts-shim.js +46 -0
  66. package/machinery/watcher.js +162 -50
  67. package/package.json +9 -30
  68. package/create/index.jux +0 -77
  69. package/create/layout.jux +0 -18
  70. package/create/style.css +0 -57
  71. package/create/themes/assets/jux.svg +0 -34
  72. package/create/themes/base.css +0 -197
  73. package/create/themes/base2.css +0 -54
  74. package/create/themes/layouts/base.jux +0 -16
  75. package/create/themes/layouts/base_marketing.jux +0 -0
  76. package/create/themes/layouts/base_saas.jux +0 -0
  77. package/lib/componentsv2/base/BaseEngine.d.ts +0 -112
  78. package/lib/componentsv2/base/BaseEngine.js +0 -279
  79. package/lib/componentsv2/base/BaseSkin.d.ts +0 -74
  80. package/lib/componentsv2/base/BaseSkin.js +0 -130
  81. package/lib/componentsv2/base/Neighborhood.d.ts +0 -22
  82. package/lib/componentsv2/base/Neighborhood.js +0 -56
  83. package/lib/componentsv2/base/OptionsContract.d.ts +0 -20
  84. package/lib/componentsv2/base/OptionsContract.js +0 -107
  85. package/lib/componentsv2/base/State.d.ts +0 -18
  86. package/lib/componentsv2/base/State.js +0 -68
  87. package/lib/componentsv2/element/Element.d.ts +0 -30
  88. package/lib/componentsv2/element/Element.js +0 -50
  89. package/lib/componentsv2/element/ElementEngine.d.ts +0 -59
  90. package/lib/componentsv2/element/ElementEngine.js +0 -118
  91. package/lib/componentsv2/element/ElementSkin.d.ts +0 -10
  92. package/lib/componentsv2/element/ElementSkin.js +0 -56
  93. package/lib/componentsv2/element/structure.css +0 -261
  94. package/lib/componentsv2/grid/Grid.d.ts +0 -13
  95. package/lib/componentsv2/grid/Grid.js +0 -27
  96. package/lib/componentsv2/grid/GridEngine.d.ts +0 -77
  97. package/lib/componentsv2/grid/GridEngine.js +0 -153
  98. package/lib/componentsv2/grid/GridSkin.d.ts +0 -11
  99. package/lib/componentsv2/grid/GridSkin.js +0 -84
  100. package/lib/componentsv2/grid/structure.css +0 -27
  101. package/lib/componentsv2/input/Input.d.ts +0 -6
  102. package/lib/componentsv2/input/Input.js +0 -21
  103. package/lib/componentsv2/input/InputEngine.d.ts +0 -70
  104. package/lib/componentsv2/input/InputEngine.js +0 -143
  105. package/lib/componentsv2/input/InputSkin.d.ts +0 -11
  106. package/lib/componentsv2/input/InputSkin.js +0 -89
  107. package/lib/componentsv2/input/structure.css +0 -47
  108. package/lib/componentsv2/list/List.d.ts +0 -49
  109. package/lib/componentsv2/list/List.js +0 -105
  110. package/lib/componentsv2/list/ListEngine.d.ts +0 -121
  111. package/lib/componentsv2/list/ListEngine.js +0 -322
  112. package/lib/componentsv2/list/ListSkin.d.ts +0 -20
  113. package/lib/componentsv2/list/ListSkin.js +0 -345
  114. package/lib/componentsv2/list/structure.css +0 -359
  115. package/lib/componentsv2/plugins/ClientSQLitePlugin.d.ts +0 -21
  116. package/lib/componentsv2/plugins/ClientSQLitePlugin.js +0 -130
  117. package/lib/componentsv2/plugins/IndexedDBPlugin.d.ts +0 -18
  118. package/lib/componentsv2/plugins/IndexedDBPlugin.js +0 -75
  119. package/lib/componentsv2/plugins/LocalStoragePlugin.d.ts +0 -20
  120. package/lib/componentsv2/plugins/LocalStoragePlugin.js +0 -65
  121. package/lib/componentsv2/plugins/ServerSQLitePlugin.d.ts +0 -25
  122. package/lib/componentsv2/plugins/ServerSQLitePlugin.js +0 -70
  123. package/lib/componentsv2/stubs/ComponentComposition.ts.stub +0 -32
  124. package/lib/componentsv2/stubs/ComponentEngine.ts.stub +0 -36
  125. package/lib/componentsv2/stubs/ComponentSkin.ts.stub +0 -35
  126. package/lib/componentsv2/stubs/ComponentStructure.css.d.ts.stub +0 -2
  127. package/lib/componentsv2/stubs/ComponentStructure.css.stub +0 -13
  128. package/lib/utils/fetch.d.ts +0 -176
  129. package/machinery/serve.js +0 -255
  130. package/types/css.d.ts +0 -10
  131. /package/{create/themes/layouts/base_blog.jux → machinery/bundleAssets.js} +0 -0
  132. /package/{create/themes/layouts/base_docs.jux → machinery/bundleJux.js} +0 -0
  133. /package/{create/themes/layouts/base_login.jux → machinery/bundleVendors.js} +0 -0
@@ -0,0 +1,246 @@
1
+ import { FormInput, FormInputState } from './base/FormInput.js';
2
+
3
+ // Event definitions
4
+ const TRIGGER_EVENTS = [] as const;
5
+ const CALLBACK_EVENTS = ['change'] as const;
6
+
7
+ export interface SwitchOptions {
8
+ checked?: boolean;
9
+ label?: string;
10
+ required?: boolean;
11
+ disabled?: boolean;
12
+ name?: string;
13
+ value?: string;
14
+ style?: string;
15
+ class?: string;
16
+ onValidate?: (checked: boolean) => boolean | string;
17
+ }
18
+
19
+ interface SwitchState extends FormInputState {
20
+ checked: boolean;
21
+ value: string;
22
+ }
23
+
24
+ export class Switch extends FormInput<SwitchState> {
25
+ constructor(id: string, options: SwitchOptions = {}) {
26
+ super(id, {
27
+ checked: options.checked ?? false,
28
+ value: options.value ?? 'on',
29
+ label: options.label ?? '',
30
+ required: options.required ?? false,
31
+ disabled: options.disabled ?? false,
32
+ name: options.name ?? id,
33
+ style: options.style ?? '',
34
+ class: options.class ?? '',
35
+ errorMessage: undefined
36
+ });
37
+
38
+ if (options.onValidate) {
39
+ this._onValidate = options.onValidate;
40
+ }
41
+ }
42
+
43
+ protected getTriggerEvents(): readonly string[] {
44
+ return TRIGGER_EVENTS;
45
+ }
46
+
47
+ protected getCallbackEvents(): readonly string[] {
48
+ return CALLBACK_EVENTS;
49
+ }
50
+
51
+ /* ═════════════════════════════════════════════════════════════════
52
+ * FLUENT API
53
+ * ═════════════════════════════════════════════════════════════════ */
54
+
55
+ // ✅ Inherited from FormInput/BaseComponent:
56
+ // - label(), required(), name(), onValidate()
57
+ // - validate(), isValid()
58
+ // - style(), class()
59
+ // - bind(), sync(), renderTo()
60
+ // - disabled(), enable(), disable()
61
+
62
+ checked(value: boolean): this {
63
+ return this.setValue(value);
64
+ }
65
+
66
+ value(value: string): this {
67
+ this.state.value = value;
68
+ return this;
69
+ }
70
+
71
+ toggle(): this {
72
+ return this.setValue(!this.state.checked);
73
+ }
74
+
75
+ /* ═════════════════════════════════════════════════════════════════
76
+ * FORM INPUT IMPLEMENTATION
77
+ * ═════════════════════════════════════════════════════════════════ */
78
+
79
+ getValue(): boolean {
80
+ return this.state.checked;
81
+ }
82
+
83
+ setValue(value: boolean): this {
84
+ this.state.checked = value;
85
+ if (this._inputElement) {
86
+ (this._inputElement as HTMLInputElement).checked = value;
87
+ }
88
+ return this;
89
+ }
90
+
91
+ protected _validateValue(checked: boolean): boolean | string {
92
+ const { required } = this.state;
93
+
94
+ if (required && !checked) {
95
+ return 'This field must be enabled';
96
+ }
97
+
98
+ if (this._onValidate) {
99
+ const result = this._onValidate(checked);
100
+ if (result !== true) {
101
+ return result || 'Invalid value';
102
+ }
103
+ }
104
+
105
+ return true;
106
+ }
107
+
108
+ protected _buildInputElement(): HTMLElement {
109
+ const { checked, value, required, disabled, name } = this.state;
110
+
111
+ const input = document.createElement('input');
112
+ input.type = 'checkbox';
113
+ input.className = 'jux-switch-input';
114
+ input.id = `${this._id}-input`;
115
+ input.name = name;
116
+ input.value = value;
117
+ input.checked = checked;
118
+ input.required = required;
119
+ input.disabled = disabled;
120
+
121
+ return input;
122
+ }
123
+
124
+ /* ═════════════════════════════════════════════════════════════════
125
+ * RENDER
126
+ * ═════════════════════════════════════════════════════════════════ */
127
+
128
+ render(targetId?: string): this {
129
+ const container = this._setupContainer(targetId);
130
+
131
+ const { style, class: className } = this.state;
132
+
133
+ // Build wrapper
134
+ const wrapper = document.createElement('div');
135
+ wrapper.className = 'jux-switch';
136
+ wrapper.id = this._id;
137
+ if (className) wrapper.className += ` ${className}`;
138
+ if (style) wrapper.setAttribute('style', style);
139
+
140
+ // Switch container
141
+ const switchContainer = document.createElement('label');
142
+ switchContainer.className = 'jux-switch-container';
143
+ switchContainer.htmlFor = `${this._id}-input`;
144
+
145
+ // Input element
146
+ const inputEl = this._buildInputElement() as HTMLInputElement;
147
+ this._inputElement = inputEl;
148
+ switchContainer.appendChild(inputEl);
149
+
150
+ // Toggle slider
151
+ const slider = document.createElement('span');
152
+ slider.className = 'jux-switch-slider';
153
+ switchContainer.appendChild(slider);
154
+
155
+ // Label text
156
+ if (this.state.label) {
157
+ const labelText = document.createElement('span');
158
+ labelText.className = 'jux-switch-label-text';
159
+ labelText.textContent = this.state.label;
160
+ if (this.state.required) {
161
+ const requiredSpan = document.createElement('span');
162
+ requiredSpan.className = 'jux-input-required';
163
+ requiredSpan.textContent = ' *';
164
+ labelText.appendChild(requiredSpan);
165
+ }
166
+ switchContainer.appendChild(labelText);
167
+ }
168
+
169
+ wrapper.appendChild(switchContainer);
170
+
171
+ // Error element
172
+ wrapper.appendChild(this._renderError());
173
+
174
+ // Wire events
175
+ this._wireStandardEvents(wrapper);
176
+
177
+ // Wire switch-specific sync (maps 'checked' to 'value' property for consistency)
178
+ const valueSync = this._syncBindings.find(b => b.property === 'value' || b.property === 'checked');
179
+
180
+ if (valueSync) {
181
+ const { stateObj, toState, toComponent } = valueSync;
182
+
183
+ const transformToState = toState || ((v: boolean) => v);
184
+ const transformToComponent = toComponent || ((v: any) => Boolean(v));
185
+
186
+ let isUpdating = false;
187
+
188
+ // State → Component
189
+ stateObj.subscribe((val: any) => {
190
+ if (isUpdating) return;
191
+ const transformed = transformToComponent(val);
192
+ this.setValue(transformed);
193
+ });
194
+
195
+ // Component → State
196
+ inputEl.addEventListener('change', () => {
197
+ if (isUpdating) return;
198
+ isUpdating = true;
199
+
200
+ const checked = inputEl.checked;
201
+ this.state.checked = checked;
202
+ this._clearError();
203
+
204
+ const transformed = transformToState(checked);
205
+ stateObj.set(transformed);
206
+
207
+ // 🎯 Fire the change callback event
208
+ this._triggerCallback('change', checked);
209
+
210
+ setTimeout(() => { isUpdating = false; }, 0);
211
+ });
212
+ } else {
213
+ // Default behavior without sync
214
+ inputEl.addEventListener('change', () => {
215
+ this.state.checked = inputEl.checked;
216
+ this._clearError();
217
+
218
+ // 🎯 Fire the change callback event
219
+ this._triggerCallback('change', inputEl.checked);
220
+ });
221
+ }
222
+
223
+ // Always add blur validation
224
+ inputEl.addEventListener('blur', () => {
225
+ this.validate();
226
+ });
227
+
228
+ // Sync label changes
229
+ const labelSync = this._syncBindings.find(b => b.property === 'label');
230
+ if (labelSync) {
231
+ const transform = labelSync.toComponent || ((v: any) => String(v));
232
+ labelSync.stateObj.subscribe((val: any) => {
233
+ this.label(transform(val));
234
+ });
235
+ }
236
+
237
+ container.appendChild(wrapper);
238
+
239
+ return this;
240
+ }
241
+ }
242
+
243
+ export function switchComponent(id: string, options: SwitchOptions = {}): Switch {
244
+ return new Switch(id, options);
245
+ }
246
+