juxscript 1.1.2 → 1.1.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.
- package/machinery/build3.js +7 -91
- package/machinery/compiler3.js +3 -209
- package/machinery/config.js +93 -6
- package/machinery/serve.js +255 -0
- package/machinery/watcher.js +49 -161
- package/package.json +19 -5
- package/lib/components/alert.ts +0 -200
- package/lib/components/app.ts +0 -247
- package/lib/components/badge.ts +0 -101
- package/lib/components/base/BaseComponent.ts +0 -421
- package/lib/components/base/FormInput.ts +0 -227
- package/lib/components/button.ts +0 -178
- package/lib/components/card.ts +0 -173
- package/lib/components/chart.ts +0 -231
- package/lib/components/checkbox.ts +0 -242
- package/lib/components/code.ts +0 -123
- package/lib/components/container.ts +0 -140
- package/lib/components/data.ts +0 -135
- package/lib/components/datepicker.ts +0 -234
- package/lib/components/dialog.ts +0 -172
- package/lib/components/divider.ts +0 -100
- package/lib/components/dropdown.ts +0 -186
- package/lib/components/element.ts +0 -267
- package/lib/components/fileupload.ts +0 -309
- package/lib/components/grid.ts +0 -291
- package/lib/components/guard.ts +0 -92
- package/lib/components/heading.ts +0 -96
- package/lib/components/helpers.ts +0 -41
- package/lib/components/hero.ts +0 -224
- package/lib/components/icon.ts +0 -178
- package/lib/components/icons.ts +0 -464
- package/lib/components/include.ts +0 -410
- package/lib/components/input.ts +0 -457
- package/lib/components/list.ts +0 -419
- package/lib/components/loading.ts +0 -100
- package/lib/components/menu.ts +0 -275
- package/lib/components/modal.ts +0 -284
- package/lib/components/nav.ts +0 -257
- package/lib/components/paragraph.ts +0 -97
- package/lib/components/progress.ts +0 -159
- package/lib/components/radio.ts +0 -278
- package/lib/components/req.ts +0 -303
- package/lib/components/script.ts +0 -41
- package/lib/components/select.ts +0 -252
- package/lib/components/sidebar.ts +0 -275
- package/lib/components/style.ts +0 -41
- package/lib/components/switch.ts +0 -246
- package/lib/components/table.ts +0 -1249
- package/lib/components/tabs.ts +0 -250
- package/lib/components/theme-toggle.ts +0 -293
- package/lib/components/tooltip.ts +0 -144
- package/lib/components/view.ts +0 -190
- package/lib/components/write.ts +0 -272
- package/lib/layouts/default.css +0 -260
- package/lib/layouts/figma.css +0 -334
- package/lib/reactivity/state.ts +0 -78
- package/lib/utils/fetch.ts +0 -553
- package/machinery/ast.js +0 -347
- package/machinery/build.js +0 -466
- package/machinery/bundleAssets.js +0 -0
- package/machinery/bundleJux.js +0 -0
- package/machinery/bundleVendors.js +0 -0
- package/machinery/doc-generator.js +0 -136
- package/machinery/imports.js +0 -155
- package/machinery/server.js +0 -166
- package/machinery/ts-shim.js +0 -46
- package/machinery/validators/file-validator.js +0 -123
package/lib/components/radio.ts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
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 RadioOption {
|
|
8
|
-
label: string;
|
|
9
|
-
value: string;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface RadioOptions {
|
|
14
|
-
options?: RadioOption[];
|
|
15
|
-
value?: string;
|
|
16
|
-
label?: string;
|
|
17
|
-
required?: boolean;
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
name?: string;
|
|
20
|
-
orientation?: 'vertical' | 'horizontal'; // ✅ Add orientation
|
|
21
|
-
style?: string;
|
|
22
|
-
class?: string;
|
|
23
|
-
onValidate?: (value: string) => boolean | string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface RadioState extends FormInputState {
|
|
27
|
-
options: RadioOption[];
|
|
28
|
-
value: string;
|
|
29
|
-
orientation: 'vertical' | 'horizontal'; // ✅ Add to state
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class Radio extends FormInput<RadioState> {
|
|
33
|
-
private _radioInputs: HTMLInputElement[] = [];
|
|
34
|
-
|
|
35
|
-
constructor(id: string, options: RadioOptions = {}) {
|
|
36
|
-
super(id, {
|
|
37
|
-
options: options.options ?? [],
|
|
38
|
-
value: options.value ?? '',
|
|
39
|
-
label: options.label ?? '',
|
|
40
|
-
required: options.required ?? false,
|
|
41
|
-
disabled: options.disabled ?? false,
|
|
42
|
-
name: options.name ?? id,
|
|
43
|
-
orientation: options.orientation ?? 'vertical', // ✅ Default to vertical
|
|
44
|
-
style: options.style ?? '',
|
|
45
|
-
class: options.class ?? '',
|
|
46
|
-
errorMessage: undefined
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (options.onValidate) {
|
|
50
|
-
this._onValidate = options.onValidate;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected getTriggerEvents(): readonly string[] {
|
|
55
|
-
return TRIGGER_EVENTS;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
protected getCallbackEvents(): readonly string[] {
|
|
59
|
-
return CALLBACK_EVENTS;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
63
|
-
* FLUENT API
|
|
64
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
65
|
-
|
|
66
|
-
// ✅ Inherited from FormInput/BaseComponent:
|
|
67
|
-
// - label(), required(), name(), onValidate()
|
|
68
|
-
// - validate(), isValid()
|
|
69
|
-
// - style(), class()
|
|
70
|
-
// - bind(), sync(), renderTo()
|
|
71
|
-
// - disabled(), enable(), disable()
|
|
72
|
-
|
|
73
|
-
options(value: RadioOption[]): this {
|
|
74
|
-
this.state.options = value;
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
value(value: string): this {
|
|
79
|
-
return this.setValue(value);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
addOption(option: RadioOption): this {
|
|
83
|
-
this.state.options = [...this.state.options, option];
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
orientation(value: 'vertical' | 'horizontal'): this {
|
|
88
|
-
this.state.orientation = value;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
93
|
-
* FORM INPUT IMPLEMENTATION
|
|
94
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
95
|
-
|
|
96
|
-
getValue(): string {
|
|
97
|
-
return this.state.value;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setValue(value: string): this {
|
|
101
|
-
this.state.value = value;
|
|
102
|
-
|
|
103
|
-
// Update all radio inputs
|
|
104
|
-
this._radioInputs.forEach(input => {
|
|
105
|
-
input.checked = input.value === value;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
return this;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
protected _validateValue(value: string): boolean | string {
|
|
112
|
-
const { required, options } = this.state;
|
|
113
|
-
|
|
114
|
-
if (required && !value) {
|
|
115
|
-
return 'Please select an option';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Validate that value is one of the options
|
|
119
|
-
if (value && !options.some(opt => opt.value === value)) {
|
|
120
|
-
return 'Invalid option selected';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (this._onValidate) {
|
|
124
|
-
const result = this._onValidate(value);
|
|
125
|
-
if (result !== true) {
|
|
126
|
-
return result || 'Invalid value';
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
protected _buildInputElement(): HTMLElement {
|
|
134
|
-
// Radio uses a container, not a single input
|
|
135
|
-
const container = document.createElement('div');
|
|
136
|
-
container.className = 'jux-radio-options';
|
|
137
|
-
return container;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
141
|
-
* RENDER
|
|
142
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
143
|
-
|
|
144
|
-
render(targetId?: string): this {
|
|
145
|
-
const container = this._setupContainer(targetId);
|
|
146
|
-
|
|
147
|
-
const { options, value, name, disabled, orientation, style, class: className } = this.state; // ✅ Destructure orientation
|
|
148
|
-
|
|
149
|
-
// Build wrapper
|
|
150
|
-
const wrapper = document.createElement('div');
|
|
151
|
-
wrapper.className = 'jux-radio';
|
|
152
|
-
wrapper.id = this._id;
|
|
153
|
-
if (className) wrapper.className += ` ${className}`;
|
|
154
|
-
if (style) wrapper.setAttribute('style', style);
|
|
155
|
-
|
|
156
|
-
// Label
|
|
157
|
-
if (this.state.label) {
|
|
158
|
-
wrapper.appendChild(this._renderLabel());
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Radio options container
|
|
162
|
-
const optionsContainer = document.createElement('div');
|
|
163
|
-
optionsContainer.className = `jux-radio-options jux-radio-${orientation}`; // ✅ Add orientation class
|
|
164
|
-
this._inputElement = optionsContainer;
|
|
165
|
-
|
|
166
|
-
this._radioInputs = [];
|
|
167
|
-
|
|
168
|
-
options.forEach((option, index) => {
|
|
169
|
-
const radioWrapper = document.createElement('label');
|
|
170
|
-
radioWrapper.className = 'jux-radio-option';
|
|
171
|
-
|
|
172
|
-
const input = document.createElement('input');
|
|
173
|
-
input.type = 'radio';
|
|
174
|
-
input.className = 'jux-radio-input';
|
|
175
|
-
input.id = `${this._id}-option-${index}`;
|
|
176
|
-
input.name = name;
|
|
177
|
-
input.value = option.value;
|
|
178
|
-
input.checked = option.value === value;
|
|
179
|
-
input.disabled = disabled || option.disabled || false;
|
|
180
|
-
|
|
181
|
-
this._radioInputs.push(input);
|
|
182
|
-
|
|
183
|
-
const radioMark = document.createElement('span');
|
|
184
|
-
radioMark.className = 'jux-radio-mark';
|
|
185
|
-
|
|
186
|
-
const labelText = document.createElement('span');
|
|
187
|
-
labelText.className = 'jux-radio-label-text';
|
|
188
|
-
labelText.textContent = option.label;
|
|
189
|
-
|
|
190
|
-
radioWrapper.appendChild(input);
|
|
191
|
-
radioWrapper.appendChild(radioMark);
|
|
192
|
-
radioWrapper.appendChild(labelText);
|
|
193
|
-
|
|
194
|
-
optionsContainer.appendChild(radioWrapper);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
wrapper.appendChild(optionsContainer);
|
|
198
|
-
|
|
199
|
-
// Error element
|
|
200
|
-
wrapper.appendChild(this._renderError());
|
|
201
|
-
|
|
202
|
-
// Wire events
|
|
203
|
-
this._wireStandardEvents(wrapper);
|
|
204
|
-
|
|
205
|
-
// Wire radio-specific sync
|
|
206
|
-
const valueSync = this._syncBindings.find(b => b.property === 'value');
|
|
207
|
-
|
|
208
|
-
if (valueSync) {
|
|
209
|
-
const { stateObj, toState, toComponent } = valueSync;
|
|
210
|
-
|
|
211
|
-
const transformToState = toState || ((v: string) => v);
|
|
212
|
-
const transformToComponent = toComponent || ((v: any) => String(v));
|
|
213
|
-
|
|
214
|
-
let isUpdating = false;
|
|
215
|
-
|
|
216
|
-
// State → Component
|
|
217
|
-
stateObj.subscribe((val: any) => {
|
|
218
|
-
if (isUpdating) return;
|
|
219
|
-
const transformed = transformToComponent(val);
|
|
220
|
-
this.setValue(transformed);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// Component → State
|
|
224
|
-
this._radioInputs.forEach(input => {
|
|
225
|
-
input.addEventListener('change', () => {
|
|
226
|
-
if (isUpdating) return;
|
|
227
|
-
isUpdating = true;
|
|
228
|
-
|
|
229
|
-
const selectedValue = input.value;
|
|
230
|
-
this.state.value = selectedValue;
|
|
231
|
-
this._clearError();
|
|
232
|
-
|
|
233
|
-
const transformed = transformToState(selectedValue);
|
|
234
|
-
stateObj.set(transformed);
|
|
235
|
-
|
|
236
|
-
// 🎯 Fire the change callback event
|
|
237
|
-
this._triggerCallback('change', selectedValue);
|
|
238
|
-
|
|
239
|
-
setTimeout(() => { isUpdating = false; }, 0);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
} else {
|
|
243
|
-
// Default behavior without sync
|
|
244
|
-
this._radioInputs.forEach(input => {
|
|
245
|
-
input.addEventListener('change', () => {
|
|
246
|
-
this.state.value = input.value;
|
|
247
|
-
this._clearError();
|
|
248
|
-
|
|
249
|
-
// 🎯 Fire the change callback event
|
|
250
|
-
this._triggerCallback('change', input.value);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Always add blur validation
|
|
256
|
-
this._radioInputs.forEach(input => {
|
|
257
|
-
input.addEventListener('blur', () => {
|
|
258
|
-
this.validate();
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// Sync label changes
|
|
263
|
-
const labelSync = this._syncBindings.find(b => b.property === 'label');
|
|
264
|
-
if (labelSync) {
|
|
265
|
-
const transform = labelSync.toComponent || ((v: any) => String(v));
|
|
266
|
-
labelSync.stateObj.subscribe((val: any) => {
|
|
267
|
-
this.label(transform(val));
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
container.appendChild(wrapper);
|
|
272
|
-
return this;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export function radio(id: string, options: RadioOptions = {}): Radio {
|
|
277
|
-
return new Radio(id, options);
|
|
278
|
-
}
|
package/lib/components/req.ts
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request information and utilities
|
|
3
|
-
* Provides access to URL, query params, path, referrer, etc.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface RequestInfo {
|
|
7
|
-
url: string;
|
|
8
|
-
path: string;
|
|
9
|
-
query: Record<string, string>;
|
|
10
|
-
params: Record<string, string>;
|
|
11
|
-
hash: string;
|
|
12
|
-
referrer: string;
|
|
13
|
-
method: string;
|
|
14
|
-
headers: Record<string, string>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class Req {
|
|
18
|
-
private static _instance: Req | null = null;
|
|
19
|
-
private _info: RequestInfo;
|
|
20
|
-
|
|
21
|
-
private constructor() {
|
|
22
|
-
this._info = this._parseRequest();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Singleton instance
|
|
27
|
-
*/
|
|
28
|
-
static get instance(): Req {
|
|
29
|
-
if (!Req._instance) {
|
|
30
|
-
Req._instance = new Req();
|
|
31
|
-
}
|
|
32
|
-
return Req._instance;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Parse current request information
|
|
37
|
-
*/
|
|
38
|
-
private _parseRequest(): RequestInfo {
|
|
39
|
-
const url = new URL(window.location.href);
|
|
40
|
-
|
|
41
|
-
// Parse query string
|
|
42
|
-
const query: Record<string, string> = {};
|
|
43
|
-
url.searchParams.forEach((value, key) => {
|
|
44
|
-
query[key] = value;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// Parse path segments as params (basic routing)
|
|
48
|
-
const pathSegments = url.pathname.split('/').filter(s => s);
|
|
49
|
-
const params: Record<string, string> = {};
|
|
50
|
-
pathSegments.forEach((segment, index) => {
|
|
51
|
-
params[`${index}`] = segment;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
url: url.href,
|
|
56
|
-
path: url.pathname,
|
|
57
|
-
query,
|
|
58
|
-
params,
|
|
59
|
-
hash: url.hash.slice(1), // Remove leading #
|
|
60
|
-
referrer: document.referrer,
|
|
61
|
-
method: 'GET', // Browser requests are always GET initially
|
|
62
|
-
headers: {
|
|
63
|
-
'user-agent': navigator.userAgent,
|
|
64
|
-
'accept-language': navigator.language
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get full URL
|
|
71
|
-
*/
|
|
72
|
-
get url(): string {
|
|
73
|
-
return this._info.url;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get current path (e.g., "/examples/sample/dashboards")
|
|
78
|
-
*/
|
|
79
|
-
get path(): string {
|
|
80
|
-
// Always get fresh path from current URL
|
|
81
|
-
return window.location.pathname;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get query string parameters
|
|
86
|
-
*/
|
|
87
|
-
get query(): Record<string, string> {
|
|
88
|
-
return { ...this._info.query };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get path parameters
|
|
93
|
-
*/
|
|
94
|
-
get params(): Record<string, string> {
|
|
95
|
-
return { ...this._info.params };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Get URL hash (without #)
|
|
100
|
-
*/
|
|
101
|
-
get hash(): string {
|
|
102
|
-
return this._info.hash;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get referrer URL
|
|
107
|
-
*/
|
|
108
|
-
get referrer(): string {
|
|
109
|
-
return this._info.referrer;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Get request method (always GET for browser)
|
|
114
|
-
*/
|
|
115
|
-
get method(): string {
|
|
116
|
-
return this._info.method;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Get request headers
|
|
121
|
-
*/
|
|
122
|
-
get headers(): Record<string, string> {
|
|
123
|
-
return { ...this._info.headers };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Check if current path matches a pattern
|
|
128
|
-
* @param pattern - Path pattern (supports wildcards)
|
|
129
|
-
*
|
|
130
|
-
* Examples:
|
|
131
|
-
* req.matches('/examples/sample/*')
|
|
132
|
-
* req.matches('/examples/sample/dashboards')
|
|
133
|
-
* req.matches('/examples/*\/dashboards')
|
|
134
|
-
*/
|
|
135
|
-
matches(pattern: string): boolean {
|
|
136
|
-
const regexPattern = pattern
|
|
137
|
-
.replace(/\*/g, '.*')
|
|
138
|
-
.replace(/\//g, '\\/');
|
|
139
|
-
const regex = new RegExp(`^${regexPattern}$`);
|
|
140
|
-
return regex.test(this.path);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Check if current path starts with prefix
|
|
145
|
-
*/
|
|
146
|
-
startsWith(prefix: string): boolean {
|
|
147
|
-
return this.path.startsWith(prefix);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Check if current path ends with suffix
|
|
152
|
-
*/
|
|
153
|
-
endsWith(suffix: string): boolean {
|
|
154
|
-
return this.path.endsWith(suffix);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Get query parameter value
|
|
159
|
-
*/
|
|
160
|
-
getQuery(key: string, defaultValue?: string): string | undefined {
|
|
161
|
-
return this.query[key] ?? defaultValue;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Get path parameter value
|
|
166
|
-
*/
|
|
167
|
-
getParam(key: string, defaultValue?: string): string | undefined {
|
|
168
|
-
return this.params[key] ?? defaultValue;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Check if query parameter exists
|
|
173
|
-
*/
|
|
174
|
-
hasQuery(key: string): boolean {
|
|
175
|
-
return key in this.query;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Get all query parameters as URLSearchParams
|
|
180
|
-
*/
|
|
181
|
-
getSearchParams(): URLSearchParams {
|
|
182
|
-
return new URLSearchParams(this.query);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Refresh request info (call after navigation)
|
|
187
|
-
*/
|
|
188
|
-
refresh(): void {
|
|
189
|
-
this._info = this._parseRequest();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Set active state on nav items based on current path
|
|
194
|
-
* @param items - Nav items to update
|
|
195
|
-
* @returns Updated nav items with active state set
|
|
196
|
-
*/
|
|
197
|
-
setActiveNavItems(items: Array<{ href: string; active?: boolean }>): Array<{ href: string; active: boolean }> {
|
|
198
|
-
return items.map(item => ({
|
|
199
|
-
...item,
|
|
200
|
-
active: this.isActiveNavItem(item.href)
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Check if a nav item should be active based on current path
|
|
206
|
-
* @param href - The nav item's href
|
|
207
|
-
*/
|
|
208
|
-
isActiveNavItem(href: string): boolean {
|
|
209
|
-
// Exact match
|
|
210
|
-
if (href === this.path) {
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Starts with match (for parent routes)
|
|
215
|
-
// Must be followed by a path separator or end of string
|
|
216
|
-
// e.g., "/examples/sample" matches "/examples/sample/dashboards"
|
|
217
|
-
// but "/examples/sam" does NOT match "/examples/sample/dashboards"
|
|
218
|
-
if (href !== '/' && (this.path === href || this.path.startsWith(href + '/'))) {
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Get breadcrumbs from current path
|
|
227
|
-
* @returns Array of breadcrumb objects with label and href
|
|
228
|
-
*/
|
|
229
|
-
getBreadcrumbs(): Array<{ label: string; href: string }> {
|
|
230
|
-
const segments = this.path.split('/').filter(s => s);
|
|
231
|
-
const breadcrumbs: Array<{ label: string; href: string }> = [
|
|
232
|
-
{ label: 'Home', href: '/' }
|
|
233
|
-
];
|
|
234
|
-
|
|
235
|
-
let currentPath = '';
|
|
236
|
-
segments.forEach(segment => {
|
|
237
|
-
currentPath += `/${segment}`;
|
|
238
|
-
breadcrumbs.push({
|
|
239
|
-
label: this._formatBreadcrumbLabel(segment),
|
|
240
|
-
href: currentPath
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
return breadcrumbs;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Format segment into readable breadcrumb label
|
|
249
|
-
*/
|
|
250
|
-
private _formatBreadcrumbLabel(segment: string): string {
|
|
251
|
-
return segment
|
|
252
|
-
.split('-')
|
|
253
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
254
|
-
.join(' ');
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Check if this is the home/root path
|
|
259
|
-
*/
|
|
260
|
-
get isHome(): boolean {
|
|
261
|
-
return this.path === '/' || this.path === '';
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Get current domain
|
|
266
|
-
*/
|
|
267
|
-
get domain(): string {
|
|
268
|
-
return window.location.hostname;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Get current port
|
|
273
|
-
*/
|
|
274
|
-
get port(): string {
|
|
275
|
-
return window.location.port;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Get current protocol
|
|
280
|
-
*/
|
|
281
|
-
get protocol(): string {
|
|
282
|
-
return window.location.protocol.replace(':', '');
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Check if HTTPS
|
|
287
|
-
*/
|
|
288
|
-
get isSecure(): boolean {
|
|
289
|
-
return this.protocol === 'https';
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Global request instance
|
|
295
|
-
*/
|
|
296
|
-
export const req = Req.instance;
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Factory function (returns singleton)
|
|
300
|
-
*/
|
|
301
|
-
export function request(): Req {
|
|
302
|
-
return Req.instance;
|
|
303
|
-
}
|
package/lib/components/script.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Script - Inject inline JavaScript into the document
|
|
3
|
-
* For external scripts, use Import component instead
|
|
4
|
-
* Auto-renders when created or modified
|
|
5
|
-
*/
|
|
6
|
-
export class Script {
|
|
7
|
-
private _id: string;
|
|
8
|
-
private code: string;
|
|
9
|
-
|
|
10
|
-
constructor(code: string, id?: string) {
|
|
11
|
-
// ID only for deduplication, auto-generate if not provided
|
|
12
|
-
this._id = id || `jux-script-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
13
|
-
this.code = code;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
render(): this {
|
|
17
|
-
// Check if script with this ID already exists
|
|
18
|
-
if (document.getElementById(this._id)) {
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const script = document.createElement('script');
|
|
23
|
-
script.id = this._id;
|
|
24
|
-
script.textContent = this.code;
|
|
25
|
-
document.head.appendChild(script);
|
|
26
|
-
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
remove(): void {
|
|
31
|
-
const existing = document.getElementById(this._id);
|
|
32
|
-
if (existing) {
|
|
33
|
-
existing.remove();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ✅ ID is optional
|
|
39
|
-
export function script(code: string, id?: string): Script {
|
|
40
|
-
return new Script(code, id);
|
|
41
|
-
}
|