@ktjs/mui 0.20.2 → 0.23.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.
- package/dist/index.css +1 -1
- package/dist/index.d.ts +626 -679
- package/dist/index.iife.css +1 -1
- package/dist/index.iife.js +831 -615
- package/dist/index.mjs +830 -616
- package/package.json +3 -3
package/dist/index.iife.js
CHANGED
|
@@ -1,17 +1,81 @@
|
|
|
1
1
|
var __ktjs_mui__ = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
// Shared constants
|
|
5
|
+
// Empty for now - can be extended with framework-wide constants
|
|
6
|
+
/**
|
|
7
|
+
* Mark the attribute as SVG to handle special cases during rendering.
|
|
8
|
+
*/
|
|
9
|
+
const $defines = Object.defineProperties;
|
|
10
|
+
const $entries = Object.entries;
|
|
11
|
+
const $random$2 = Math.random;
|
|
12
|
+
const { get: $buttonDisabledGetter$2, set: $buttonDisabledSetter$2 } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
|
|
13
|
+
const parseStyle = (style) => {
|
|
14
|
+
if (!style) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
if (typeof style === 'string') {
|
|
18
|
+
return style;
|
|
19
|
+
}
|
|
20
|
+
if (style && typeof style === 'object') {
|
|
21
|
+
if (style.isKT) {
|
|
22
|
+
return parseStyle(style.value);
|
|
23
|
+
}
|
|
24
|
+
return $entries(style)
|
|
25
|
+
.map((entry) => {
|
|
26
|
+
const cssKey = entry[0].replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
27
|
+
return `${cssKey}:${entry[1]}`;
|
|
28
|
+
})
|
|
29
|
+
.join(';');
|
|
30
|
+
}
|
|
31
|
+
return '';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// String manipulation utilities
|
|
35
|
+
/**
|
|
36
|
+
* Default empty function
|
|
37
|
+
*/
|
|
38
|
+
const $emptyFn = (() => true);
|
|
39
|
+
|
|
40
|
+
if (typeof Symbol === 'undefined') {
|
|
41
|
+
window.Symbol = function Symbol(description) {
|
|
42
|
+
return `@@SYMBOL_${description || ''}_${$random$2().toString(36).slice(2)}`;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Shared utilities and cached native methods for kt.js framework
|
|
47
|
+
Object.defineProperty(window, '__ktjs__', { value: '0.23.4' });
|
|
48
|
+
|
|
49
|
+
// Shared constants
|
|
50
|
+
// Empty for now - can be extended with framework-wide constants
|
|
51
|
+
/**
|
|
52
|
+
* Mark the attribute as SVG to handle special cases during rendering.
|
|
53
|
+
*/
|
|
54
|
+
const SVG_ATTR_FLAG = '__kt_svg__';
|
|
55
|
+
/**
|
|
56
|
+
* Mark the attribute as MathML to handle special cases during rendering.
|
|
57
|
+
*/
|
|
58
|
+
const MATHML_ATTR_FLAG = '__kt_mathml__';
|
|
59
|
+
|
|
4
60
|
// Cached native methods for performance optimization
|
|
5
61
|
const $isArray = Array.isArray;
|
|
6
|
-
const $
|
|
7
|
-
|
|
8
|
-
// Error handling utilities
|
|
9
|
-
const $throw = (message) => {
|
|
10
|
-
throw new Error('@ktjs/shared: ' + message);
|
|
11
|
-
};
|
|
62
|
+
const $random$1 = Math.random;
|
|
63
|
+
const $isThenable = (o) => typeof o?.then === 'function';
|
|
12
64
|
|
|
13
65
|
// DOM manipulation utilities
|
|
14
66
|
// # dom natives
|
|
67
|
+
const $isNode$1 = (x) => x?.nodeType > 0;
|
|
68
|
+
/**
|
|
69
|
+
* Safe replace `oldNode` With `newNode`
|
|
70
|
+
*/
|
|
71
|
+
const $replaceNode$1 = (oldNode, newNode) => {
|
|
72
|
+
if ($isNode$1(oldNode) && $isNode$1(newNode)) {
|
|
73
|
+
if (newNode.contains(oldNode)) {
|
|
74
|
+
newNode.remove();
|
|
75
|
+
}
|
|
76
|
+
oldNode.replaceWith(newNode);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
15
79
|
/**
|
|
16
80
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
17
81
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -47,11 +111,28 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
47
111
|
$appendChild.call(this, fragment);
|
|
48
112
|
}
|
|
49
113
|
};
|
|
50
|
-
const { get: $buttonDisabledGetter$
|
|
114
|
+
const { get: $buttonDisabledGetter$1, set: $buttonDisabledSetter$1 } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
|
|
115
|
+
/**
|
|
116
|
+
* Used for `k-model`
|
|
117
|
+
*/
|
|
118
|
+
const applyModel = (element, valueRef, propName, eventName) => {
|
|
119
|
+
element[propName] = valueRef.value; // initialize
|
|
120
|
+
valueRef.addOnChange((newValue) => (element[propName] = newValue));
|
|
121
|
+
element.addEventListener(eventName, () => (valueRef.value = element[propName]));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (typeof Symbol === 'undefined') {
|
|
125
|
+
window.Symbol = function Symbol(description) {
|
|
126
|
+
return `@@SYMBOL_${description || ''}_${$random$1().toString(36).slice(2)}`;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
51
129
|
|
|
52
130
|
// Shared utilities and cached native methods for kt.js framework
|
|
53
|
-
|
|
54
|
-
|
|
131
|
+
Object.defineProperty(window, '__ktjs__', { value: '0.23.4' });
|
|
132
|
+
|
|
133
|
+
const isKT$1 = (obj) => obj?.isKT;
|
|
134
|
+
const isRef = (obj) => obj?.ktType === 1 /* KTReactiveType.REF */;
|
|
135
|
+
const isComputed = (obj) => obj?.ktType === 2 /* KTReactiveType.COMPUTED */;
|
|
55
136
|
|
|
56
137
|
const booleanHandler = (element, key, value) => {
|
|
57
138
|
if (key in element) {
|
|
@@ -95,10 +176,25 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
95
176
|
};
|
|
96
177
|
|
|
97
178
|
const defaultHandler = (element, key, value) => element.setAttribute(key, value);
|
|
179
|
+
const setElementStyle = (element, style) => {
|
|
180
|
+
if (typeof style === 'string') {
|
|
181
|
+
element.style.cssText = style;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
for (const key in style) {
|
|
185
|
+
element.style[key] = style[key];
|
|
186
|
+
}
|
|
187
|
+
};
|
|
98
188
|
function attrIsObject(element, attr) {
|
|
99
189
|
const classValue = attr.class || attr.className;
|
|
100
190
|
if (classValue !== undefined) {
|
|
101
|
-
|
|
191
|
+
if (isKT$1(classValue)) {
|
|
192
|
+
element.setAttribute('class', classValue.value);
|
|
193
|
+
classValue.addOnChange((v) => element.setAttribute('class', v));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
element.setAttribute('class', classValue);
|
|
197
|
+
}
|
|
102
198
|
}
|
|
103
199
|
const style = attr.style;
|
|
104
200
|
if (style) {
|
|
@@ -106,18 +202,34 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
106
202
|
element.setAttribute('style', style);
|
|
107
203
|
}
|
|
108
204
|
else if (typeof style === 'object') {
|
|
109
|
-
|
|
110
|
-
element
|
|
205
|
+
if (isKT$1(style)) {
|
|
206
|
+
setElementStyle(element, style.value);
|
|
207
|
+
style.addOnChange((v) => setElementStyle(element, v));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
setElementStyle(element, style);
|
|
111
211
|
}
|
|
112
212
|
}
|
|
113
213
|
}
|
|
214
|
+
if ('k-html' in attr) {
|
|
215
|
+
const html = attr['k-html'];
|
|
216
|
+
if (isKT$1(html)) {
|
|
217
|
+
element.innerHTML = html.value;
|
|
218
|
+
html.addOnChange((v) => (element.innerHTML = v));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
element.innerHTML = html;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
114
224
|
for (const key in attr) {
|
|
115
|
-
if (key === '
|
|
225
|
+
if (key === 'k-if' ||
|
|
226
|
+
key === 'k-model' ||
|
|
227
|
+
key === 'ref' ||
|
|
228
|
+
key === 'class' ||
|
|
116
229
|
key === 'className' ||
|
|
117
230
|
key === 'style' ||
|
|
118
231
|
key === 'children' ||
|
|
119
|
-
key === 'k-
|
|
120
|
-
key === 'ref') {
|
|
232
|
+
key === 'k-html') {
|
|
121
233
|
continue;
|
|
122
234
|
}
|
|
123
235
|
const o = attr[key];
|
|
@@ -127,7 +239,14 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
127
239
|
}
|
|
128
240
|
// normal attributes
|
|
129
241
|
else {
|
|
130
|
-
|
|
242
|
+
const handler = handlers[key] || defaultHandler;
|
|
243
|
+
if (isKT$1(o)) {
|
|
244
|
+
handler(element, key, o.value);
|
|
245
|
+
o.addOnChange((v) => handler(element, key, v));
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
handler(element, key, o);
|
|
249
|
+
}
|
|
131
250
|
}
|
|
132
251
|
}
|
|
133
252
|
}
|
|
@@ -139,17 +258,28 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
139
258
|
attrIsObject(element, attr);
|
|
140
259
|
}
|
|
141
260
|
else {
|
|
142
|
-
throw new Error('kt.js
|
|
261
|
+
throw new Error('[kt.js error] attr must be an object.');
|
|
143
262
|
}
|
|
144
263
|
}
|
|
145
264
|
|
|
265
|
+
const assureNode = (o) => ($isNode$1(o) ? o : document.createTextNode(o));
|
|
146
266
|
function apdSingle(element, c) {
|
|
147
267
|
// & JSX should ignore false, undefined, and null
|
|
148
268
|
if (c === false || c === undefined || c === null) {
|
|
149
269
|
return;
|
|
150
270
|
}
|
|
151
|
-
if (
|
|
152
|
-
|
|
271
|
+
if (isKT$1(c)) {
|
|
272
|
+
let node = assureNode(c.value);
|
|
273
|
+
$append.call(element, node);
|
|
274
|
+
c.addOnChange((newValue, oldValue) => {
|
|
275
|
+
if ($isNode$1(newValue) && $isNode$1(oldValue)) {
|
|
276
|
+
// & this case is handled automically in `class KTRef`
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const oldNode = node;
|
|
280
|
+
node = assureNode(newValue);
|
|
281
|
+
oldNode.replaceWith(node);
|
|
282
|
+
});
|
|
153
283
|
}
|
|
154
284
|
else {
|
|
155
285
|
$append.call(element, c);
|
|
@@ -194,14 +324,34 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
194
324
|
}
|
|
195
325
|
}
|
|
196
326
|
|
|
197
|
-
|
|
327
|
+
function applyKModel(element, valueRef) {
|
|
328
|
+
if (!isKT$1(valueRef)) {
|
|
329
|
+
console.warn('[kt.js warn]','k-model value must be a KTRef.');
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (element instanceof HTMLInputElement) {
|
|
333
|
+
if (element.type === 'radio' || element.type === 'checkbox') {
|
|
334
|
+
applyModel(element, valueRef, 'checked', 'change');
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
applyModel(element, valueRef, 'value', 'input');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else if (element instanceof HTMLSelectElement) {
|
|
341
|
+
applyModel(element, valueRef, 'value', 'change');
|
|
342
|
+
}
|
|
343
|
+
else if (element instanceof HTMLTextAreaElement) {
|
|
344
|
+
applyModel(element, valueRef, 'value', 'input');
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
console.warn('[kt.js warn]','not supported element for k-model:');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
198
351
|
const htmlCreator = (tag) => document.createElement(tag);
|
|
199
352
|
const svgCreator = (tag) => document.createElementNS('http://www.w3.org/2000/svg', tag);
|
|
200
353
|
const mathMLCreator = (tag) => document.createElementNS('http://www.w3.org/1998/Math/MathML', tag);
|
|
201
354
|
let creator = htmlCreator;
|
|
202
|
-
// # consts
|
|
203
|
-
const SVG_ATTR_FLAG = '__kt_svg__';
|
|
204
|
-
const MATHML_ATTR_FLAG = '__kt_mathml__';
|
|
205
355
|
/**
|
|
206
356
|
* Create an enhanced HTMLElement.
|
|
207
357
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -212,7 +362,7 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
212
362
|
* ## About
|
|
213
363
|
* @package @ktjs/core
|
|
214
364
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
215
|
-
* @version 0.
|
|
365
|
+
* @version 0.26.9 (Last Update: 2026.02.09 00:03:34.324)
|
|
216
366
|
* @license MIT
|
|
217
367
|
* @link https://github.com/baendlorel/kt.js
|
|
218
368
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -221,7 +371,7 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
221
371
|
*/
|
|
222
372
|
const h = (tag, attr, content) => {
|
|
223
373
|
if (typeof tag !== 'string') {
|
|
224
|
-
|
|
374
|
+
throw new Error('[kt.js error] tagName must be a string.');
|
|
225
375
|
}
|
|
226
376
|
if (attr) {
|
|
227
377
|
if (SVG_ATTR_FLAG in attr) {
|
|
@@ -241,39 +391,57 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
241
391
|
// * Handle content
|
|
242
392
|
applyAttr(element, attr);
|
|
243
393
|
applyContent(element, content);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// }
|
|
248
|
-
// if (tag === 'math') {
|
|
249
|
-
// tempWrapper.innerHTML = element.outerHTML;
|
|
250
|
-
// return tempWrapper.firstChild as HTML<T>;
|
|
251
|
-
// }
|
|
394
|
+
if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {
|
|
395
|
+
applyKModel(element, attr['k-model']);
|
|
396
|
+
}
|
|
252
397
|
return element;
|
|
253
398
|
};
|
|
254
399
|
|
|
255
400
|
const dummyRef = { value: null };
|
|
401
|
+
const create = (tag, props) => {
|
|
402
|
+
if (typeof tag === 'function') {
|
|
403
|
+
return tag(props);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
return h(tag, props, props.children);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
const placeholder = () => document.createComment('k-if');
|
|
256
410
|
/**
|
|
257
411
|
* @param tag html tag or function component
|
|
258
412
|
* @param props properties/attributes
|
|
259
413
|
*/
|
|
260
414
|
function jsx(tag, props) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if ('k-if' in props && !props['k-if']) {
|
|
264
|
-
// & make comment placeholder in case that ref might be redrawn later
|
|
265
|
-
el = document.createComment('k-if');
|
|
266
|
-
ref.value = el;
|
|
267
|
-
return el;
|
|
268
|
-
}
|
|
269
|
-
// Handle function components
|
|
270
|
-
if (typeof tag === 'function') {
|
|
271
|
-
el = tag(props);
|
|
415
|
+
if (isComputed(props.ref)) {
|
|
416
|
+
throw new Error('[kt.js error] Cannot assign a computed value to an element.');
|
|
272
417
|
}
|
|
273
|
-
|
|
274
|
-
|
|
418
|
+
const maybeDummyRef = isRef(props.ref) ? props.ref : dummyRef;
|
|
419
|
+
let el;
|
|
420
|
+
if ('k-if' in props) {
|
|
421
|
+
const kif = props['k-if'];
|
|
422
|
+
let condition = kif; // assume boolean by default
|
|
423
|
+
// Handle reactive k-if
|
|
424
|
+
if (isKT$1(kif)) {
|
|
425
|
+
kif.addOnChange((newValue, oldValue) => {
|
|
426
|
+
if (newValue === oldValue) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const oldEl = el;
|
|
430
|
+
el = newValue ? create(tag, props) : placeholder();
|
|
431
|
+
$replaceNode$1(oldEl, el);
|
|
432
|
+
maybeDummyRef.value = el;
|
|
433
|
+
});
|
|
434
|
+
condition = kif.value;
|
|
435
|
+
}
|
|
436
|
+
if (!condition) {
|
|
437
|
+
// & make comment placeholder in case that ref might be redrawn later
|
|
438
|
+
el = placeholder();
|
|
439
|
+
maybeDummyRef.value = el;
|
|
440
|
+
return el;
|
|
441
|
+
}
|
|
275
442
|
}
|
|
276
|
-
|
|
443
|
+
el = create(tag, props);
|
|
444
|
+
maybeDummyRef.value = el;
|
|
277
445
|
return el;
|
|
278
446
|
}
|
|
279
447
|
/**
|
|
@@ -282,48 +450,8 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
282
450
|
*/
|
|
283
451
|
const jsxs = jsx;
|
|
284
452
|
|
|
285
|
-
// Cached native methods for performance optimization
|
|
286
|
-
const $defines = Object.defineProperties;
|
|
287
|
-
|
|
288
|
-
// String manipulation utilities
|
|
289
|
-
/**
|
|
290
|
-
* Default empty function
|
|
291
|
-
*/
|
|
292
|
-
const $emptyFn = (() => true);
|
|
293
|
-
const { get: $buttonDisabledGetter$1, set: $buttonDisabledSetter$1 } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
|
|
294
|
-
// # DOM utilities
|
|
295
|
-
const parseStyle = (style) => {
|
|
296
|
-
if (typeof style === 'string') {
|
|
297
|
-
return style;
|
|
298
|
-
}
|
|
299
|
-
if (style && typeof style === 'object') {
|
|
300
|
-
return Object.entries(style)
|
|
301
|
-
.map(([key, value]) => {
|
|
302
|
-
// Convert camelCase to kebab-case
|
|
303
|
-
const cssKey = key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
304
|
-
return `${cssKey}: ${value}`;
|
|
305
|
-
})
|
|
306
|
-
.join('; ');
|
|
307
|
-
}
|
|
308
|
-
return '';
|
|
309
|
-
};
|
|
310
|
-
const generateHandler = (props, key) => {
|
|
311
|
-
const handler = props[key];
|
|
312
|
-
if (typeof handler === 'function') {
|
|
313
|
-
return handler;
|
|
314
|
-
}
|
|
315
|
-
else if (handler && typeof handler === 'object' && handler.isKT) {
|
|
316
|
-
return (value) => (handler.value = value);
|
|
317
|
-
}
|
|
318
|
-
return $emptyFn;
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
// Shared utilities and cached native methods for kt.js framework
|
|
322
|
-
// Re-export all utilities
|
|
323
|
-
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.0' });
|
|
324
|
-
|
|
325
453
|
function Alert(props) {
|
|
326
|
-
const { children, severity = 'info', variant = 'standard', icon, '
|
|
454
|
+
const { children, severity = 'info', variant = 'standard', icon, 'on:close': onClose } = props;
|
|
327
455
|
const classes = `mui-alert mui-alert-${severity} mui-alert-${variant} ${props.class ? props.class : ''}`;
|
|
328
456
|
// Icon SVG paths for different severities
|
|
329
457
|
const getIcon = () => {
|
|
@@ -352,201 +480,409 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
352
480
|
return alert;
|
|
353
481
|
}
|
|
354
482
|
|
|
483
|
+
// Shared constants
|
|
484
|
+
// Empty for now - can be extended with framework-wide constants
|
|
355
485
|
/**
|
|
356
|
-
*
|
|
486
|
+
* Mark the attribute as SVG to handle special cases during rendering.
|
|
357
487
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const classes = [
|
|
361
|
-
'mui-button',
|
|
362
|
-
`mui-button-${variant}`,
|
|
363
|
-
`mui-button-${variant}-${color}`,
|
|
364
|
-
`mui-button-size-${size}`,
|
|
365
|
-
fullWidth ? 'mui-button-fullwidth' : '',
|
|
366
|
-
iconOnly ? 'mui-button-icon-only' : '',
|
|
367
|
-
disabled ? 'mui-button-disabled' : '',
|
|
368
|
-
props.class ? props.class : '',
|
|
369
|
-
].join(' ');
|
|
370
|
-
const rippleContainer = jsx("span", { class: "mui-button-ripple" });
|
|
371
|
-
const handleClick = (e) => {
|
|
372
|
-
if (disabled) {
|
|
373
|
-
e.preventDefault();
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
// Create ripple effect
|
|
377
|
-
const button = e.currentTarget;
|
|
378
|
-
if (rippleContainer) {
|
|
379
|
-
const rect = button.getBoundingClientRect();
|
|
380
|
-
const size = Math.max(rect.width, rect.height);
|
|
381
|
-
const x = e.clientX - rect.left - size / 2;
|
|
382
|
-
const y = e.clientY - rect.top - size / 2;
|
|
383
|
-
const ripple = document.createElement('span');
|
|
384
|
-
ripple.style.width = ripple.style.height = `${size}px`;
|
|
385
|
-
ripple.style.left = `${x}px`;
|
|
386
|
-
ripple.style.top = `${y}px`;
|
|
387
|
-
ripple.classList.add('mui-button-ripple-effect');
|
|
388
|
-
rippleContainer.appendChild(ripple);
|
|
389
|
-
// Remove ripple after animation
|
|
390
|
-
setTimeout(() => ripple.remove(), 600);
|
|
391
|
-
}
|
|
392
|
-
onClick(e);
|
|
393
|
-
};
|
|
394
|
-
const container = (jsxs("button", { class: classes, style: parseStyle(props.style), type: type, disabled: disabled, "on:click": handleClick, children: [startIcon && jsx("span", { class: "mui-button-start-icon", children: startIcon }), jsx("span", { class: "mui-button-label", children: children }), endIcon && jsx("span", { class: "mui-button-end-icon", children: endIcon }), rippleContainer] }));
|
|
395
|
-
$defines(container, {
|
|
396
|
-
disabled: {
|
|
397
|
-
get: $buttonDisabledGetter$1,
|
|
398
|
-
set: function (value) {
|
|
399
|
-
$buttonDisabledSetter$1.call(this, value);
|
|
400
|
-
this.classList.toggle('mui-button-disabled', value);
|
|
401
|
-
},
|
|
402
|
-
},
|
|
403
|
-
});
|
|
404
|
-
return container;
|
|
405
|
-
}
|
|
488
|
+
const $is = Object.is;
|
|
489
|
+
const $random = Math.random;
|
|
406
490
|
|
|
491
|
+
// DOM manipulation utilities
|
|
492
|
+
// # dom natives
|
|
493
|
+
const $isNode = (x) => x?.nodeType > 0;
|
|
407
494
|
/**
|
|
408
|
-
*
|
|
495
|
+
* Safe replace `oldNode` With `newNode`
|
|
409
496
|
*/
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
checkedIcon.style.display = 'none';
|
|
415
|
-
indeterminateIcon.style.display = '';
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
uncheckedIcon.style.display = checked ? 'none' : '';
|
|
419
|
-
checkedIcon.style.display = checked ? '' : 'none';
|
|
420
|
-
indeterminateIcon.style.display = 'none';
|
|
497
|
+
const $replaceNode = (oldNode, newNode) => {
|
|
498
|
+
if ($isNode(oldNode) && $isNode(newNode)) {
|
|
499
|
+
if (newNode.contains(oldNode)) {
|
|
500
|
+
newNode.remove();
|
|
421
501
|
}
|
|
502
|
+
oldNode.replaceWith(newNode);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
|
|
506
|
+
|
|
507
|
+
if (typeof Symbol === 'undefined') {
|
|
508
|
+
window.Symbol = function Symbol(description) {
|
|
509
|
+
return `@@SYMBOL_${description || ''}_${$random().toString(36).slice(2)}`;
|
|
422
510
|
};
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Shared utilities and cached native methods for kt.js framework
|
|
514
|
+
Object.defineProperty(window, '__ktjs__', { value: '0.23.4' });
|
|
515
|
+
|
|
516
|
+
const isKT = (obj) => obj?.isKT;
|
|
517
|
+
|
|
518
|
+
class KTRef {
|
|
519
|
+
/**
|
|
520
|
+
* Indicates that this is a KTRef instance
|
|
521
|
+
*/
|
|
522
|
+
isKT = true;
|
|
523
|
+
ktType = 1 /* KTReactiveType.REF */;
|
|
524
|
+
/**
|
|
525
|
+
* @internal
|
|
526
|
+
*/
|
|
527
|
+
_value;
|
|
528
|
+
/**
|
|
529
|
+
* @internal
|
|
530
|
+
*/
|
|
531
|
+
_onChanges;
|
|
532
|
+
constructor(_value, _onChanges) {
|
|
533
|
+
this._value = _value;
|
|
534
|
+
this._onChanges = _onChanges;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
538
|
+
*/
|
|
539
|
+
get value() {
|
|
540
|
+
return this._value;
|
|
541
|
+
}
|
|
542
|
+
set value(newValue) {
|
|
543
|
+
if ($is(newValue, this._value)) {
|
|
426
544
|
return;
|
|
427
545
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
toggleIcon(checked, indeterminate);
|
|
455
|
-
},
|
|
456
|
-
},
|
|
457
|
-
value: {
|
|
458
|
-
get() {
|
|
459
|
-
return value;
|
|
460
|
-
},
|
|
461
|
-
set(newValue) {
|
|
462
|
-
value = newValue;
|
|
463
|
-
inputEl.value = value;
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
disabled: {
|
|
467
|
-
get() {
|
|
468
|
-
return disabled;
|
|
469
|
-
},
|
|
470
|
-
set(newDisabled) {
|
|
471
|
-
disabled = Boolean(newDisabled);
|
|
472
|
-
inputEl.disabled = disabled;
|
|
473
|
-
container.classList.toggle('mui-checkbox-disabled', disabled);
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
});
|
|
477
|
-
return container;
|
|
546
|
+
const oldValue = this._value;
|
|
547
|
+
$replaceNode(oldValue, newValue);
|
|
548
|
+
this._value = newValue;
|
|
549
|
+
for (let i = 0; i < this._onChanges.length; i++) {
|
|
550
|
+
this._onChanges[i](newValue, oldValue);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Register a callback when the value changes
|
|
555
|
+
* @param callback (newValue, oldValue) => xxx
|
|
556
|
+
*/
|
|
557
|
+
addOnChange(callback) {
|
|
558
|
+
if (typeof callback !== 'function') {
|
|
559
|
+
throw new Error('[kt.js error] KTRef.addOnChange: callback must be a function');
|
|
560
|
+
}
|
|
561
|
+
this._onChanges.push(callback);
|
|
562
|
+
}
|
|
563
|
+
removeOnChange(callback) {
|
|
564
|
+
for (let i = this._onChanges.length - 1; i >= 0; i--) {
|
|
565
|
+
if (this._onChanges[i] === callback) {
|
|
566
|
+
this._onChanges.splice(i, 1);
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
478
572
|
}
|
|
479
573
|
/**
|
|
480
|
-
*
|
|
574
|
+
* Reference to the created HTML element.
|
|
575
|
+
* - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
|
|
576
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
577
|
+
* - if the value is already a `KTRef`, it will be returned **directly**.
|
|
578
|
+
* @param value mostly an HTMLElement
|
|
481
579
|
*/
|
|
482
|
-
function
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
580
|
+
function ref(value, onChange) {
|
|
581
|
+
return new KTRef(value, onChange ? [onChange] : []);
|
|
582
|
+
}
|
|
583
|
+
function deref(value) {
|
|
584
|
+
return isKT(value) ? value.value : value;
|
|
585
|
+
}
|
|
586
|
+
// # asserts
|
|
587
|
+
/**
|
|
588
|
+
* Assert k-model to be a ref object
|
|
589
|
+
*/
|
|
590
|
+
const $modelOrRef = (props, defaultValue) => {
|
|
591
|
+
// & props is an object. Won't use it in any other place
|
|
592
|
+
if ('k-model' in props) {
|
|
593
|
+
const kmodel = props['k-model'];
|
|
594
|
+
if (!kmodel?.isKT) {
|
|
595
|
+
throw new Error(`[kt.js error] k-model data must be a KTRef object, please use 'ref(...)' to wrap it.`);
|
|
492
596
|
}
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
597
|
+
return kmodel;
|
|
598
|
+
}
|
|
599
|
+
return ref(defaultValue);
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
class KTComputed {
|
|
603
|
+
/**
|
|
604
|
+
* Indicates that this is a KTRef instance
|
|
605
|
+
*/
|
|
606
|
+
isKT = true;
|
|
607
|
+
ktType = 2 /* KTReactiveType.COMPUTED */;
|
|
608
|
+
/**
|
|
609
|
+
* @internal
|
|
610
|
+
*/
|
|
611
|
+
_calculator;
|
|
612
|
+
/**
|
|
613
|
+
* @internal
|
|
614
|
+
*/
|
|
615
|
+
_value;
|
|
616
|
+
/**
|
|
617
|
+
* @internal
|
|
618
|
+
*/
|
|
619
|
+
_onChanges = [];
|
|
620
|
+
/**
|
|
621
|
+
* @internal
|
|
622
|
+
*/
|
|
623
|
+
_subscribe(reactives) {
|
|
624
|
+
for (let i = 0; i < reactives.length; i++) {
|
|
625
|
+
const reactive = reactives[i];
|
|
626
|
+
reactive.addOnChange(() => {
|
|
627
|
+
const oldValue = this._value;
|
|
628
|
+
this._value = this._calculator();
|
|
629
|
+
if (oldValue === this._value) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
$replaceNode(oldValue, this._value);
|
|
633
|
+
for (let i = 0; i < this._onChanges.length; i++) {
|
|
634
|
+
this._onChanges[i](this._value, oldValue);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
constructor(_calculator, reactives) {
|
|
640
|
+
this._calculator = _calculator;
|
|
641
|
+
this._value = _calculator();
|
|
642
|
+
this._subscribe(reactives);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
646
|
+
*/
|
|
647
|
+
get value() {
|
|
648
|
+
return this._value;
|
|
649
|
+
}
|
|
650
|
+
set value(_newValue) {
|
|
651
|
+
throw new Error('[kt.js error] KTComputed: cannot set value of a computed value');
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Register a callback when the value changes
|
|
655
|
+
* @param callback (newValue, oldValue) => xxx
|
|
656
|
+
*/
|
|
657
|
+
addOnChange(callback) {
|
|
658
|
+
if (typeof callback !== 'function') {
|
|
659
|
+
throw new Error('[kt.js error] KTRef.addOnChange: callback must be a function');
|
|
660
|
+
}
|
|
661
|
+
this._onChanges.push(callback);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Unregister a callback
|
|
665
|
+
* @param callback (newValue, oldValue) => xxx
|
|
666
|
+
*/
|
|
667
|
+
removeOnChange(callback) {
|
|
668
|
+
for (let i = this._onChanges.length - 1; i >= 0; i--) {
|
|
669
|
+
if (this._onChanges[i] === callback) {
|
|
670
|
+
this._onChanges.splice(i, 1);
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Create a reactive computed value
|
|
679
|
+
* @param computeFn
|
|
680
|
+
* @param reactives refs and computeds that this computed depends on
|
|
681
|
+
*/
|
|
682
|
+
function computed(computeFn, reactives) {
|
|
683
|
+
if (reactives.some((v) => !isKT(v))) {
|
|
684
|
+
throw new Error('[kt.js error] computed: all reactives must be KTRef or KTComputed instances');
|
|
685
|
+
}
|
|
686
|
+
return new KTComputed(computeFn, reactives);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
const toReactive = (value, onChange) => {
|
|
690
|
+
if (isKT(value)) {
|
|
691
|
+
if (onChange) {
|
|
692
|
+
value.addOnChange(onChange);
|
|
693
|
+
}
|
|
694
|
+
return value;
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
return ref(value, onChange);
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
const registerPrefixedEventsForButton = (element, props) => {
|
|
702
|
+
for (const key in props) {
|
|
703
|
+
if (key.startsWith('on:') && key !== 'on:click' && key !== 'on:dblclick') {
|
|
704
|
+
element.addEventListener(key.slice(3), props[key]);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Button component - mimics MUI Button appearance and behavior
|
|
711
|
+
*/
|
|
712
|
+
function Button(props) {
|
|
713
|
+
let { children, variant = 'text', color = 'primary', size = 'medium', disabled = false, fullWidth = false, iconOnly = false, startIcon, endIcon, type = 'button', 'on:click': onClick = $emptyFn, // & must be bound because of the ripple effect
|
|
714
|
+
} = props;
|
|
715
|
+
const updateClass = () => {
|
|
716
|
+
container.className = [
|
|
717
|
+
'mui-button',
|
|
718
|
+
`mui-button-${variant}`,
|
|
719
|
+
`mui-button-${variant}-${color}`,
|
|
720
|
+
`mui-button-size-${size}`,
|
|
721
|
+
fullWidth ? 'mui-button-fullwidth' : '',
|
|
722
|
+
iconOnly ? 'mui-button-icon-only' : '',
|
|
723
|
+
disabledRef.value ? 'mui-button-disabled' : '',
|
|
724
|
+
props.class ? props.class : '',
|
|
725
|
+
].join(' ');
|
|
726
|
+
};
|
|
727
|
+
const disabledRef = toReactive(disabled, (v) => {
|
|
728
|
+
container.disabled = v;
|
|
729
|
+
updateClass();
|
|
730
|
+
});
|
|
731
|
+
const rippleContainer = jsx("span", { class: "mui-button-ripple" });
|
|
732
|
+
const createRippleEffect = (mouseX, mouseY) => {
|
|
733
|
+
const rect = container.getBoundingClientRect();
|
|
734
|
+
const size = Math.max(rect.width, rect.height);
|
|
735
|
+
const x = mouseX - rect.left - size / 2;
|
|
736
|
+
const y = mouseY - rect.top - size / 2;
|
|
737
|
+
const ripple = (jsx("span", { class: "mui-button-ripple-effect", style: `width:${size}px; height:${size}px; left:${x}px; top:${y}px;` }));
|
|
738
|
+
rippleContainer.appendChild(ripple);
|
|
739
|
+
setTimeout(() => ripple.remove(), 600); // Remove ripple after animation
|
|
740
|
+
};
|
|
741
|
+
const handleClick = (e) => {
|
|
742
|
+
if (disabledRef.value) {
|
|
743
|
+
e.preventDefault();
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
createRippleEffect(e.clientX, e.clientY);
|
|
747
|
+
onClick(e);
|
|
748
|
+
};
|
|
749
|
+
const container = (jsxs("button", { style: parseStyle(props.style), type: type, disabled: disabledRef.value, "on:click": handleClick, children: [jsx("span", { "k-if": startIcon, class: "mui-button-start-icon", children: startIcon }), jsx("span", { class: "mui-button-label", children: children }), jsx("span", { "k-if": endIcon, class: "mui-button-end-icon", children: endIcon }), rippleContainer] }));
|
|
750
|
+
const onDblclick = props['on:dblclick'];
|
|
751
|
+
if (onDblclick) {
|
|
752
|
+
container.addEventListener('dblclick', (e) => {
|
|
753
|
+
if (disabledRef.value) {
|
|
754
|
+
e.preventDefault();
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
createRippleEffect(e.clientX, e.clientY);
|
|
758
|
+
onDblclick(e);
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
registerPrefixedEventsForButton(container, props);
|
|
762
|
+
// # initialize
|
|
763
|
+
updateClass();
|
|
764
|
+
return container;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
const $ArrayPushUnique = (arr, item) => {
|
|
768
|
+
if (!arr.includes(item)) {
|
|
769
|
+
arr.push(item);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
const $ArrayDelete = (arr, item) => {
|
|
773
|
+
const index = arr.indexOf(item);
|
|
774
|
+
if (index > -1) {
|
|
775
|
+
arr.splice(index, 1);
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
const createUncheckedIcon = () => (jsx("span", { class: "mui-checkbox-icon-unchecked", children: jsx("svg", { viewBox: "0 0 24 24", children: jsx("path", { d: "M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z" }) }) }));
|
|
780
|
+
const createCheckedIcon = () => (jsx("span", { class: "mui-checkbox-icon-checked", children: jsx("svg", { viewBox: "0 0 24 24", children: jsx("path", { d: "M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" }) }) }));
|
|
781
|
+
const createIndeterminateIcon = () => (jsx("span", { class: "mui-checkbox-icon-indeterminate", children: jsx("svg", { viewBox: "0 0 24 24", children: jsx("path", { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-2 10H7v-2h10v2z" }) }) }));
|
|
782
|
+
/**
|
|
783
|
+
* Checkbox component - mimics MUI Checkbox appearance and behavior
|
|
784
|
+
*/
|
|
785
|
+
function Checkbox(props) {
|
|
786
|
+
const toggleIcon = (checked, indeterminate) => {
|
|
787
|
+
if (indeterminate) {
|
|
788
|
+
uncheckedIcon.style.display = 'none';
|
|
789
|
+
checkedIcon.style.display = 'none';
|
|
790
|
+
indeterminateIcon.style.display = '';
|
|
504
791
|
}
|
|
505
792
|
else {
|
|
506
|
-
|
|
793
|
+
uncheckedIcon.style.display = checked ? 'none' : '';
|
|
794
|
+
checkedIcon.style.display = checked ? '' : 'none';
|
|
795
|
+
indeterminateIcon.style.display = 'none';
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
// Handle change
|
|
799
|
+
const handleChange = () => {
|
|
800
|
+
if (disabledRef.value) {
|
|
801
|
+
return;
|
|
507
802
|
}
|
|
508
|
-
|
|
803
|
+
modelRef.value = inputEl.checked;
|
|
804
|
+
interminateRef.value = false;
|
|
805
|
+
toggleIcon(modelRef.value, interminateRef.value);
|
|
806
|
+
onChange(modelRef.value, valueRef.value);
|
|
807
|
+
};
|
|
808
|
+
const onChange = props['on:change'] ?? $emptyFn;
|
|
809
|
+
const labelRef = toReactive(props.label ?? '');
|
|
810
|
+
const valueRef = toReactive(props.value ?? '');
|
|
811
|
+
const interminateRef = toReactive(props.indeterminate ?? false);
|
|
812
|
+
const colorRef = toReactive(props.color ?? 'primary');
|
|
813
|
+
const sizeRef = toReactive(props.size ?? 'medium');
|
|
814
|
+
const disabledRef = toReactive(props.disabled ?? false, (v) => {
|
|
815
|
+
inputEl.disabled = v;
|
|
816
|
+
container.classList.toggle('mui-checkbox-disabled', v);
|
|
509
817
|
});
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return Array.from(selectedValues);
|
|
515
|
-
},
|
|
516
|
-
set(newValues) {
|
|
517
|
-
selectedValues = new Set(newValues);
|
|
518
|
-
for (let i = 0; i < checkboxes.length; i++) {
|
|
519
|
-
const checkbox = checkboxes[i];
|
|
520
|
-
checkbox.checked = selectedValues.has(checkbox.value);
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
},
|
|
524
|
-
disabled: {
|
|
525
|
-
get() {
|
|
526
|
-
return checkboxes.map((cb) => cb.disabled);
|
|
527
|
-
},
|
|
528
|
-
set(newDisabled) {
|
|
529
|
-
for (let i = 0; i < checkboxes.length; i++) {
|
|
530
|
-
const checkbox = checkboxes[i];
|
|
531
|
-
checkbox.disabled = Boolean(newDisabled);
|
|
532
|
-
}
|
|
533
|
-
},
|
|
534
|
-
},
|
|
535
|
-
disableAll: {
|
|
536
|
-
value: () => {
|
|
537
|
-
for (let i = 0; i < checkboxes.length; i++) {
|
|
538
|
-
checkboxes[i].disabled = true;
|
|
539
|
-
}
|
|
540
|
-
},
|
|
541
|
-
},
|
|
542
|
-
enableAll: {
|
|
543
|
-
value: () => {
|
|
544
|
-
for (let i = 0; i < checkboxes.length; i++) {
|
|
545
|
-
checkboxes[i].disabled = false;
|
|
546
|
-
}
|
|
547
|
-
},
|
|
548
|
-
},
|
|
818
|
+
const modelRef = $modelOrRef(props, props.checked ?? false);
|
|
819
|
+
modelRef.addOnChange((newValue) => {
|
|
820
|
+
inputEl.checked = newValue;
|
|
821
|
+
toggleIcon(newValue, interminateRef.value);
|
|
549
822
|
});
|
|
823
|
+
const inputEl = (jsx("input", { type: "checkbox", class: "mui-checkbox-input", checked: modelRef.value, value: valueRef, disabled: disabledRef, "on:change": handleChange }));
|
|
824
|
+
const uncheckedIcon = createUncheckedIcon();
|
|
825
|
+
const checkedIcon = createCheckedIcon();
|
|
826
|
+
const indeterminateIcon = createIndeterminateIcon();
|
|
827
|
+
// Initialize icon state
|
|
828
|
+
toggleIcon(modelRef.value, interminateRef.value);
|
|
829
|
+
const classRef = computed(() => {
|
|
830
|
+
return `mui-checkbox-wrapper mui-checkbox-size-${sizeRef.value} ${disabledRef.value ? 'mui-checkbox-disabled' : ''} mui-checkbox-color-${colorRef.value}`;
|
|
831
|
+
}, [colorRef, disabledRef, sizeRef]);
|
|
832
|
+
const container = (jsxs("label", { class: classRef, children: [inputEl, jsxs("span", { class: "mui-checkbox-icon", children: [uncheckedIcon, checkedIcon, indeterminateIcon] }), jsx("span", { "k-if": labelRef, class: "mui-checkbox-label", children: labelRef })] }));
|
|
833
|
+
return container;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* CheckboxGroup component - groups multiple checkboxes together
|
|
837
|
+
*/
|
|
838
|
+
function CheckboxGroup(props) {
|
|
839
|
+
let { row = false, 'on:change': onChange = $emptyFn } = props;
|
|
840
|
+
const changeHandler = (checked, checkboxValue) => {
|
|
841
|
+
if (checked) {
|
|
842
|
+
$ArrayPushUnique(modelRef.value, checkboxValue);
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
$ArrayDelete(modelRef.value, checkboxValue);
|
|
846
|
+
}
|
|
847
|
+
onChange(modelRef.value);
|
|
848
|
+
};
|
|
849
|
+
const rowRef = toReactive(props.row ?? true);
|
|
850
|
+
const sizeRef = toReactive(props.size ?? 'medium');
|
|
851
|
+
const modelRef = $modelOrRef(props, props.value ?? []);
|
|
852
|
+
modelRef.addOnChange((newValues) => {
|
|
853
|
+
for (let i = 0; i < checkboxes.value.length; i++) {
|
|
854
|
+
const c = checkboxes.value[i];
|
|
855
|
+
c.checked = newValues.includes(c.value);
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
const customClassRef = toReactive(props.class ?? '');
|
|
859
|
+
const classRef = computed(() => {
|
|
860
|
+
return `mui-checkbox-group ${rowRef.value ? 'mui-checkbox-group-row' : ''} ${customClassRef.value}`;
|
|
861
|
+
}, [rowRef, customClassRef]);
|
|
862
|
+
const styleRef = toReactive(parseStyle(props.style ?? ''));
|
|
863
|
+
const optionsRef = toReactive(props.options);
|
|
864
|
+
const checkboxes = computed(() => {
|
|
865
|
+
return optionsRef.value.map((o) => {
|
|
866
|
+
o.size = sizeRef.value;
|
|
867
|
+
o.checked = modelRef.value.includes(o.value);
|
|
868
|
+
const originalChange = o['on:change'];
|
|
869
|
+
if (originalChange) {
|
|
870
|
+
if (typeof originalChange !== 'function') {
|
|
871
|
+
throw new Error('[kt.js error] CheckboxGroup: handler must be a function');
|
|
872
|
+
}
|
|
873
|
+
o['on:change'] = (checked, value) => {
|
|
874
|
+
originalChange(checked, value);
|
|
875
|
+
changeHandler(checked, value);
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
else {
|
|
879
|
+
o['on:change'] = changeHandler;
|
|
880
|
+
}
|
|
881
|
+
return Checkbox(o);
|
|
882
|
+
});
|
|
883
|
+
}, [optionsRef, sizeRef]);
|
|
884
|
+
console.log('checkboxes', checkboxes.value);
|
|
885
|
+
const container = (jsx("div", { class: classRef, style: styleRef, role: "group", children: checkboxes }));
|
|
550
886
|
return container;
|
|
551
887
|
}
|
|
552
888
|
|
|
@@ -555,11 +891,30 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
555
891
|
* Only handles open/close state, title and content are passed as props
|
|
556
892
|
*/
|
|
557
893
|
function Dialog(props) {
|
|
558
|
-
let {
|
|
894
|
+
let { 'on:close': onClose = $emptyFn, children, actions } = props;
|
|
895
|
+
const titleRef = toReactive(props.title ?? '');
|
|
896
|
+
const openRef = toReactive(props.open ?? false, (isOpen) => {
|
|
897
|
+
if (isOpen) {
|
|
898
|
+
// Opening: set display first, then add class with double RAF for animation
|
|
899
|
+
container.style.display = 'flex';
|
|
900
|
+
setTimeout(() => container.classList.add('kt-dialog-backdrop-open'), 50);
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
container.classList.remove('kt-dialog-backdrop-open');
|
|
904
|
+
setTimeout(() => {
|
|
905
|
+
if (!openRef.value) {
|
|
906
|
+
container.style.display = 'none';
|
|
907
|
+
}
|
|
908
|
+
}, 225);
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
const sizeRef = toReactive(props.size ?? 'sm');
|
|
912
|
+
const fullWidthRef = toReactive(props.fullWidth ?? false);
|
|
913
|
+
const classNameRef = computed(() => `kt-dialog-paper ${sizeRef.value ? `kt-dialog-maxWidth-${sizeRef.value}` : ''} ${fullWidthRef.value ? 'kt-dialog-fullWidth' : ''}`, [sizeRef, fullWidthRef]);
|
|
559
914
|
// Handle ESC key - store handler for cleanup
|
|
560
915
|
const keyDownHandler = (e) => {
|
|
561
916
|
if (e.key === 'Escape') {
|
|
562
|
-
|
|
917
|
+
openRef.value = false;
|
|
563
918
|
onClose();
|
|
564
919
|
}
|
|
565
920
|
};
|
|
@@ -569,7 +924,7 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
569
924
|
}
|
|
570
925
|
};
|
|
571
926
|
// Backdrop element
|
|
572
|
-
const container = (jsx("div", { class: `kt-dialog-backdrop ${
|
|
927
|
+
const container = (jsx("div", { class: `kt-dialog-backdrop ${openRef.value ? 'kt-dialog-backdrop-open' : ''}`, style: { display: openRef.value ? 'flex' : 'none' }, "on:click": handleBackdropClick, children: jsxs("div", { class: classNameRef, "on:click": (e) => e.stopPropagation(), children: [jsx("div", { "k-if": titleRef, class: "kt-dialog-title", children: jsx("h2", { children: titleRef }) }), jsx("div", { "k-if": children, class: "kt-dialog-content", children: children }), jsx("div", { "k-if": actions, class: "kt-dialog-actions", children: actions })] }) }));
|
|
573
928
|
document.addEventListener('keydown', keyDownHandler);
|
|
574
929
|
// Store cleanup function
|
|
575
930
|
const originalRemove = container.remove;
|
|
@@ -579,30 +934,6 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
579
934
|
}
|
|
580
935
|
return originalRemove.call(container);
|
|
581
936
|
};
|
|
582
|
-
$defines(container, {
|
|
583
|
-
open: {
|
|
584
|
-
get: () => open,
|
|
585
|
-
set: (isOpen) => {
|
|
586
|
-
if (isOpen === open) {
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
open = isOpen;
|
|
590
|
-
if (isOpen) {
|
|
591
|
-
// Opening: set display first, then add class with double RAF for animation
|
|
592
|
-
container.style.display = 'flex';
|
|
593
|
-
setTimeout(() => container.classList.add('kt-dialog-backdrop-open'), 50);
|
|
594
|
-
}
|
|
595
|
-
else {
|
|
596
|
-
container.classList.remove('kt-dialog-backdrop-open');
|
|
597
|
-
setTimeout(() => {
|
|
598
|
-
if (!open) {
|
|
599
|
-
container.style.display = 'none';
|
|
600
|
-
}
|
|
601
|
-
}, 225);
|
|
602
|
-
}
|
|
603
|
-
},
|
|
604
|
-
},
|
|
605
|
-
});
|
|
606
937
|
return container;
|
|
607
938
|
}
|
|
608
939
|
|
|
@@ -630,192 +961,68 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
630
961
|
return element;
|
|
631
962
|
}
|
|
632
963
|
|
|
633
|
-
// Cached native methods for performance optimization
|
|
634
|
-
const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
|
|
635
|
-
|
|
636
|
-
// Shared utilities and cached native methods for kt.js framework
|
|
637
|
-
// Re-export all utilities
|
|
638
|
-
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.0' });
|
|
639
|
-
|
|
640
|
-
document.createElement('div');
|
|
641
|
-
|
|
642
|
-
class KTRef {
|
|
643
|
-
/**
|
|
644
|
-
* Indicates that this is a KTRef instance
|
|
645
|
-
*/
|
|
646
|
-
isKT = true;
|
|
647
|
-
/**
|
|
648
|
-
* @internal
|
|
649
|
-
*/
|
|
650
|
-
_value;
|
|
651
|
-
/**
|
|
652
|
-
* @internal
|
|
653
|
-
*/
|
|
654
|
-
_onChanges;
|
|
655
|
-
constructor(_value, _onChanges) {
|
|
656
|
-
this._value = _value;
|
|
657
|
-
this._onChanges = _onChanges;
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
661
|
-
*/
|
|
662
|
-
get value() {
|
|
663
|
-
return this._value;
|
|
664
|
-
}
|
|
665
|
-
set value(newValue) {
|
|
666
|
-
if (newValue === this._value) {
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
// replace the old node with the new one in the DOM if both are nodes
|
|
670
|
-
if (this._value instanceof Node && newValue instanceof Node) {
|
|
671
|
-
if (newValue.contains(this._value)) {
|
|
672
|
-
this._value.remove();
|
|
673
|
-
}
|
|
674
|
-
this._value.replaceWith(newValue);
|
|
675
|
-
}
|
|
676
|
-
const oldValue = this._value;
|
|
677
|
-
this._value = newValue;
|
|
678
|
-
for (let i = 0; i < this._onChanges.length; i++) {
|
|
679
|
-
this._onChanges[i](newValue, oldValue);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
addOnChange(callback) {
|
|
683
|
-
this._onChanges.push(callback);
|
|
684
|
-
}
|
|
685
|
-
removeOnChange(callback) {
|
|
686
|
-
for (let i = this._onChanges.length - 1; i >= 0; i--) {
|
|
687
|
-
if (this._onChanges[i] === callback) {
|
|
688
|
-
this._onChanges.splice(i, 1);
|
|
689
|
-
return true;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
return false;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Reference to the created HTML element.
|
|
697
|
-
* - can alse be used to store normal values, but it is not reactive.
|
|
698
|
-
* @param value mostly an HTMLElement
|
|
699
|
-
*/
|
|
700
|
-
function ref(value, onChange) {
|
|
701
|
-
return new KTRef(value, []);
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* A helper to create redrawable elements
|
|
705
|
-
* ```tsx
|
|
706
|
-
* export function MyComponent() {
|
|
707
|
-
* let aa = 10;
|
|
708
|
-
* // ...
|
|
709
|
-
* // aa might be changed
|
|
710
|
-
* return createRedrawable(() => <div>{aa}</div>);
|
|
711
|
-
* }
|
|
712
|
-
* ```
|
|
713
|
-
* Then the returned element has a `redraw` method to redraw itself with new values.
|
|
714
|
-
* @param creator a simple creator function that returns an element
|
|
715
|
-
* @returns created element's ref
|
|
716
|
-
*/
|
|
717
|
-
function createRedrawable(creator) {
|
|
718
|
-
const elRef = ref();
|
|
719
|
-
const redraw = () => {
|
|
720
|
-
elRef.value = creator(); // ref setter automatically calls replaceWith
|
|
721
|
-
elRef.redraw = redraw;
|
|
722
|
-
return elRef.value;
|
|
723
|
-
};
|
|
724
|
-
redraw();
|
|
725
|
-
return elRef;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* LinearProgress component - mimics MUI LinearProgress appearance and behavior
|
|
730
|
-
*/
|
|
731
964
|
function LinearProgress(props) {
|
|
732
|
-
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
]
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
const container = (jsx("div", { class:
|
|
744
|
-
$defines(container, {
|
|
745
|
-
progress: {
|
|
746
|
-
get() {
|
|
747
|
-
return progressValue;
|
|
748
|
-
},
|
|
749
|
-
set(newValue) {
|
|
750
|
-
progressValue = Math.min(Math.max(newValue, 0), 100);
|
|
751
|
-
if (variant === 'determinate') {
|
|
752
|
-
barRef.value.style.width = `${progressValue}%`;
|
|
753
|
-
}
|
|
754
|
-
},
|
|
755
|
-
},
|
|
756
|
-
});
|
|
965
|
+
const valueRef = ref(props.progress ?? 0);
|
|
966
|
+
const customClassRef = toReactive(props.class ?? '');
|
|
967
|
+
const colorRef = toReactive(props.color ?? 'primary');
|
|
968
|
+
const variantRef = toReactive(props.variant ?? 'indeterminate');
|
|
969
|
+
const classRef = computed(() => {
|
|
970
|
+
return `mui-linear-progress mui-linear-progress-${variantRef.value} mui-linear-progress-${colorRef.value} ${customClassRef.value}`;
|
|
971
|
+
}, [customClassRef, colorRef, variantRef]);
|
|
972
|
+
const styleRef = toReactive(props.style ?? '');
|
|
973
|
+
const barLengthRef = computed(() => {
|
|
974
|
+
return variantRef.value === 'determinate' ? `width: ${valueRef.value}%` : '';
|
|
975
|
+
}, [variantRef, valueRef]);
|
|
976
|
+
const container = (jsx("div", { class: classRef, style: styleRef, role: "progressbar", "aria-valuenow": valueRef, children: jsx("div", { class: "mui-linear-progress-bar", style: barLengthRef }) }));
|
|
757
977
|
return container;
|
|
758
978
|
}
|
|
759
979
|
|
|
760
|
-
/**
|
|
761
|
-
* TextField component - mimics MUI TextField appearance and behavior
|
|
762
|
-
*/
|
|
763
980
|
function TextField(props) {
|
|
764
|
-
|
|
765
|
-
const onInput =
|
|
766
|
-
const onInputTrim =
|
|
767
|
-
const onChange =
|
|
768
|
-
const onChangeTrim =
|
|
769
|
-
const onBlur =
|
|
770
|
-
const onFocus =
|
|
771
|
-
const
|
|
772
|
-
|
|
773
|
-
'mui-textfield-root',
|
|
774
|
-
`mui-textfield-size-${size}`,
|
|
775
|
-
isFocused ? 'mui-textfield-focused' : '',
|
|
776
|
-
error ? 'mui-textfield-error' : '',
|
|
777
|
-
disabled ? 'mui-textfield-disabled' : '',
|
|
778
|
-
fullWidth ? 'mui-textfield-fullwidth' : '',
|
|
779
|
-
label && inputEl.value ? 'mui-textfield-has-value' : '',
|
|
780
|
-
label ? '' : 'mui-textfield-no-label',
|
|
781
|
-
].join(' ');
|
|
782
|
-
};
|
|
981
|
+
// # events
|
|
982
|
+
const onInput = props['on:input'] ?? $emptyFn;
|
|
983
|
+
const onInputTrim = props['on-trim:input'] ?? $emptyFn;
|
|
984
|
+
const onChange = props['on:change'] ?? $emptyFn;
|
|
985
|
+
const onChangeTrim = props['on-trim:change'] ?? $emptyFn;
|
|
986
|
+
const onBlur = props['on:blur'] ?? $emptyFn;
|
|
987
|
+
const onFocus = props['on:focus'] ?? $emptyFn;
|
|
988
|
+
const isFocusedRef = ref(false);
|
|
989
|
+
// # methods
|
|
783
990
|
const handleInput = () => {
|
|
784
|
-
|
|
785
|
-
if (type === 'number') {
|
|
991
|
+
if (inputType === 'number') {
|
|
786
992
|
const v = Number(inputEl.value);
|
|
993
|
+
modelRef.value = v;
|
|
787
994
|
onInput(v);
|
|
788
995
|
onInputTrim(v);
|
|
789
996
|
}
|
|
790
997
|
else {
|
|
998
|
+
modelRef.value = inputEl.value;
|
|
791
999
|
onInput(inputEl.value);
|
|
792
1000
|
onInputTrim(inputEl.value.trim());
|
|
793
1001
|
}
|
|
794
1002
|
};
|
|
795
1003
|
const handleChange = () => {
|
|
796
|
-
|
|
797
|
-
if (type === 'number') {
|
|
1004
|
+
if (inputType === 'number') {
|
|
798
1005
|
const v = Number(inputEl.value);
|
|
1006
|
+
modelRef.value = v;
|
|
799
1007
|
onChange(v);
|
|
800
1008
|
onChangeTrim(v);
|
|
801
1009
|
}
|
|
802
1010
|
else {
|
|
1011
|
+
modelRef.value = inputEl.value;
|
|
803
1012
|
onChange(inputEl.value);
|
|
804
1013
|
onChangeTrim(inputEl.value.trim());
|
|
805
1014
|
}
|
|
806
1015
|
};
|
|
807
1016
|
const handleFocus = () => {
|
|
808
|
-
isFocused = true;
|
|
809
|
-
updateContainerClass();
|
|
1017
|
+
isFocused.value = true;
|
|
810
1018
|
onFocus(inputEl.value);
|
|
811
1019
|
};
|
|
812
1020
|
const handleBlur = () => {
|
|
813
|
-
isFocused = false;
|
|
814
|
-
updateContainerClass();
|
|
1021
|
+
isFocused.value = false;
|
|
815
1022
|
onBlur(inputEl.value);
|
|
816
1023
|
};
|
|
817
1024
|
const handleWrapperMouseDown = (e) => {
|
|
818
|
-
if (
|
|
1025
|
+
if (disabledRef.value) {
|
|
819
1026
|
return;
|
|
820
1027
|
}
|
|
821
1028
|
const target = e.target;
|
|
@@ -824,92 +1031,55 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
824
1031
|
}
|
|
825
1032
|
setTimeout(() => inputEl.focus(), 0);
|
|
826
1033
|
};
|
|
827
|
-
const getPlaceholder = () => (
|
|
828
|
-
|
|
1034
|
+
const getPlaceholder = () => (labelRef.value && !isFocused && !modelRef.value ? '' : placeholderRef.value);
|
|
1035
|
+
// # non-refs
|
|
1036
|
+
const inputType = deref(props.type ?? 'text');
|
|
1037
|
+
const multiline = props.multiline;
|
|
1038
|
+
// # refs
|
|
1039
|
+
// Create refs for all reactive properties
|
|
1040
|
+
const labelRef = toReactive(props.label ?? '');
|
|
1041
|
+
const placeholderRef = toReactive(props.placeholder ?? '', () => (inputEl.placeholder = getPlaceholder()));
|
|
1042
|
+
const disabledRef = toReactive(props.disabled ?? false);
|
|
1043
|
+
const readOnlyRef = toReactive(props.readOnly ?? false);
|
|
1044
|
+
const requiredRef = toReactive(props.required ?? false);
|
|
1045
|
+
const errorRef = toReactive(props.error ?? false);
|
|
1046
|
+
const helperTextRef = toReactive(props.helperText ?? '');
|
|
1047
|
+
const fullWidthRef = toReactive(props.fullWidth ?? false);
|
|
1048
|
+
const rowsRef = toReactive(props.rows ?? 3);
|
|
1049
|
+
const sizeRef = toReactive(props.size ?? 'medium');
|
|
1050
|
+
// k-model takes precedence over value prop for two-way binding
|
|
1051
|
+
const modelRef = $modelOrRef(props, props.value ?? '');
|
|
1052
|
+
// Add change listeners for reactive properties
|
|
1053
|
+
// `k-if` changing triggers redrawing, no need to do this again
|
|
1054
|
+
// // labelRef.addOnChange(() => {
|
|
1055
|
+
// // wrapperRef.redraw();
|
|
1056
|
+
// // updateContainerClass();
|
|
1057
|
+
// // });
|
|
1058
|
+
const isFocused = ref(false);
|
|
829
1059
|
const inputEl = multiline
|
|
830
|
-
? (jsx("textarea", { class: "mui-textfield-input", placeholder: getPlaceholder(), value: value, disabled:
|
|
831
|
-
: (jsx("input", { type:
|
|
832
|
-
|
|
833
|
-
const
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
wrapperRef.redraw(); // label takes too much and should be redrawn
|
|
854
|
-
updateContainerClass();
|
|
855
|
-
},
|
|
856
|
-
},
|
|
857
|
-
placeholder: {
|
|
858
|
-
get() {
|
|
859
|
-
return placeholder;
|
|
860
|
-
},
|
|
861
|
-
set(newPlaceholder) {
|
|
862
|
-
placeholder = newPlaceholder;
|
|
863
|
-
inputEl.placeholder = getPlaceholder();
|
|
864
|
-
},
|
|
865
|
-
},
|
|
866
|
-
type: {
|
|
867
|
-
get() {
|
|
868
|
-
return type;
|
|
869
|
-
},
|
|
870
|
-
set(newType) {
|
|
871
|
-
type = newType || 'text';
|
|
872
|
-
inputEl.type = type;
|
|
873
|
-
},
|
|
874
|
-
},
|
|
875
|
-
disabled: {
|
|
876
|
-
get() {
|
|
877
|
-
return disabled;
|
|
878
|
-
},
|
|
879
|
-
set(val) {
|
|
880
|
-
disabled = !!val;
|
|
881
|
-
inputEl.disabled = disabled;
|
|
882
|
-
container.classList.toggle('mui-textfield-disabled', disabled);
|
|
883
|
-
},
|
|
884
|
-
},
|
|
885
|
-
readonly: {
|
|
886
|
-
get() {
|
|
887
|
-
return readonly;
|
|
888
|
-
},
|
|
889
|
-
set(val) {
|
|
890
|
-
readonly = Boolean(val);
|
|
891
|
-
inputEl.readOnly = readonly;
|
|
892
|
-
},
|
|
893
|
-
},
|
|
894
|
-
error: {
|
|
895
|
-
get() {
|
|
896
|
-
return error;
|
|
897
|
-
},
|
|
898
|
-
set(val) {
|
|
899
|
-
error = Boolean(val);
|
|
900
|
-
container.classList.toggle('mui-textfield-error', error);
|
|
901
|
-
},
|
|
902
|
-
},
|
|
903
|
-
helperText: {
|
|
904
|
-
get() {
|
|
905
|
-
return helperText;
|
|
906
|
-
},
|
|
907
|
-
set(text) {
|
|
908
|
-
helperTextEl.textContent = text;
|
|
909
|
-
helperTextEl.style.display = text ? 'block' : 'none';
|
|
910
|
-
},
|
|
911
|
-
},
|
|
912
|
-
});
|
|
1060
|
+
? (jsx("textarea", { class: "mui-textfield-input", placeholder: getPlaceholder(), value: modelRef.value, disabled: disabledRef, readOnly: readOnlyRef, required: requiredRef, rows: rowsRef, "on:input": handleInput, "on:change": handleChange, "on:focus": handleFocus, "on:blur": handleBlur }))
|
|
1061
|
+
: (jsx("input", { type: inputType, class: "mui-textfield-input", placeholder: getPlaceholder(), value: modelRef.value, disabled: disabledRef, readOnly: readOnlyRef, required: requiredRef, "on:input": handleInput, "on:change": handleChange, "on:focus": handleFocus, "on:blur": handleBlur }));
|
|
1062
|
+
modelRef.addOnChange((newValue) => (inputEl.value = newValue));
|
|
1063
|
+
const styleRef = toReactive(parseStyle(props.style ?? ''));
|
|
1064
|
+
const customClassRef = toReactive(props.class ?? '');
|
|
1065
|
+
const classRef = computed(() => {
|
|
1066
|
+
const className = [
|
|
1067
|
+
'mui-textfield-root',
|
|
1068
|
+
`mui-textfield-size-${sizeRef.value}`,
|
|
1069
|
+
isFocusedRef.value ? 'mui-textfield-focused' : '',
|
|
1070
|
+
errorRef.value ? 'mui-textfield-error' : '',
|
|
1071
|
+
disabledRef.value ? 'mui-textfield-disabled' : '',
|
|
1072
|
+
fullWidthRef.value ? 'mui-textfield-fullwidth' : '',
|
|
1073
|
+
labelRef.value && inputEl.value ? 'mui-textfield-has-value' : '',
|
|
1074
|
+
labelRef.value ? '' : 'mui-textfield-no-label',
|
|
1075
|
+
customClassRef.value ? customClassRef.value : '',
|
|
1076
|
+
].join(' ');
|
|
1077
|
+
return className;
|
|
1078
|
+
}, [sizeRef, errorRef, disabledRef, fullWidthRef, labelRef, isFocusedRef, customClassRef]);
|
|
1079
|
+
// if (multiline) {
|
|
1080
|
+
// rowsRef.addOnChange((newRows) => ((inputEl as HTMLTextAreaElement).rows = newRows));
|
|
1081
|
+
// }
|
|
1082
|
+
const container = (jsxs("div", { class: classRef, style: styleRef, children: [jsxs("div", { class: "mui-textfield-wrapper", "on:mousedown": handleWrapperMouseDown, children: [jsxs("label", { class: "mui-textfield-label", children: [labelRef, jsx("span", { "k-if": requiredRef, class: "mui-textfield-required", children: "*" })] }), jsx("div", { class: "mui-textfield-input-wrapper", children: inputEl }), jsx("fieldset", { class: "mui-textfield-fieldset", children: jsx("legend", { class: "mui-textfield-legend", children: jsxs("span", { children: [labelRef, jsx("span", { "k-if": requiredRef, children: "*" })] }) }) })] }), jsx("p", { class: "mui-textfield-helper-text", children: helperTextRef })] }));
|
|
913
1083
|
return container;
|
|
914
1084
|
}
|
|
915
1085
|
|
|
@@ -917,7 +1087,7 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
917
1087
|
* Radio component - mimics MUI Radio appearance and behavior
|
|
918
1088
|
*/
|
|
919
1089
|
function Radio(props) {
|
|
920
|
-
const onChange =
|
|
1090
|
+
const onChange = props['on:change'] ?? $emptyFn;
|
|
921
1091
|
const toggleIcon = (checked) => {
|
|
922
1092
|
uncheckedIcon.style.display = checked ? 'none' : '';
|
|
923
1093
|
checkedIcon.style.display = checked ? '' : 'none';
|
|
@@ -932,7 +1102,9 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
932
1102
|
onChange(checked, value);
|
|
933
1103
|
};
|
|
934
1104
|
let { checked = false, value = '', label: text = '', size = 'small', disabled = false, color = 'primary' } = props;
|
|
935
|
-
const
|
|
1105
|
+
const valueRef = toReactive(props.value ?? '');
|
|
1106
|
+
const disabledRef = toReactive(props.disabled ?? false);
|
|
1107
|
+
const input = (jsx("input", { type: "radio", class: "mui-radio-input", checked: checked, value: valueRef, disabled: disabledRef, "on:change": handleChange }));
|
|
936
1108
|
const uncheckedIcon = (jsx("span", { class: "mui-radio-icon-unchecked", children: jsx("svg", { viewBox: "0 0 24 24", children: jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" }) }) }));
|
|
937
1109
|
const checkedIcon = (jsx("span", { class: "mui-radio-icon-checked", children: jsx("svg", { viewBox: "0 0 24 24", children: jsx("path", { d: "M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" }) }) }));
|
|
938
1110
|
// initialize icon state
|
|
@@ -962,7 +1134,7 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
962
1134
|
*/
|
|
963
1135
|
function RadioGroup(props) {
|
|
964
1136
|
let { value = '', size = 'small', row = false } = props;
|
|
965
|
-
const onChange =
|
|
1137
|
+
const onChange = props['on:change'] ?? $emptyFn;
|
|
966
1138
|
const changeHandler = (checked, value) => {
|
|
967
1139
|
if (checked) {
|
|
968
1140
|
onChange(value);
|
|
@@ -972,15 +1144,15 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
972
1144
|
const radios = props.options.map((o) => {
|
|
973
1145
|
o.size = size;
|
|
974
1146
|
o.checked = value === o.value;
|
|
975
|
-
const originalChange = o['
|
|
1147
|
+
const originalChange = o['on:change'];
|
|
976
1148
|
if (originalChange) {
|
|
977
|
-
o['
|
|
1149
|
+
o['on:change'] = (checked, newValue) => {
|
|
978
1150
|
originalChange(checked, newValue);
|
|
979
1151
|
changeHandler(checked, newValue);
|
|
980
1152
|
};
|
|
981
1153
|
}
|
|
982
1154
|
else {
|
|
983
|
-
o['
|
|
1155
|
+
o['on:change'] = changeHandler;
|
|
984
1156
|
}
|
|
985
1157
|
return Radio(o);
|
|
986
1158
|
});
|
|
@@ -1003,22 +1175,10 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
1003
1175
|
* Select component - mimics MUI Select appearance and behavior
|
|
1004
1176
|
*/
|
|
1005
1177
|
function Select(props) {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
const selectRef = ref();
|
|
1011
|
-
const selectLabelRef = ref();
|
|
1012
|
-
// Toggle dropdown
|
|
1013
|
-
const toggleMenu = () => {
|
|
1014
|
-
if (disabled) {
|
|
1015
|
-
return;
|
|
1016
|
-
}
|
|
1017
|
-
isOpen = !isOpen;
|
|
1018
|
-
updateMenu();
|
|
1019
|
-
};
|
|
1020
|
-
// Update menu visibility
|
|
1021
|
-
const updateMenu = () => {
|
|
1178
|
+
const onChange = props['on:change'] ?? $emptyFn;
|
|
1179
|
+
// # refs
|
|
1180
|
+
const isFocusedRef = ref(false);
|
|
1181
|
+
const open = ref(false, (isOpen) => {
|
|
1022
1182
|
if (isOpen) {
|
|
1023
1183
|
menu.value.style.display = 'block';
|
|
1024
1184
|
void menu.value.offsetHeight; // & Trigger reflow to enable animation
|
|
@@ -1032,85 +1192,139 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
1032
1192
|
}, 200);
|
|
1033
1193
|
}
|
|
1034
1194
|
menu.value.classList.toggle('mui-select-menu-open', isOpen);
|
|
1035
|
-
|
|
1195
|
+
container.classList.toggle('mui-select-open', isOpen);
|
|
1196
|
+
});
|
|
1197
|
+
// # ref props
|
|
1198
|
+
const placeholderRef = toReactive(props.placeholder ?? '');
|
|
1199
|
+
const labelRef = toReactive(props.label ?? '');
|
|
1200
|
+
const optionsRef = toReactive(props.options, (newOptions) => {
|
|
1201
|
+
if (!newOptions.find((o) => o.value === modelRef.value)) {
|
|
1202
|
+
onChange((modelRef.value = ''));
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
const disabledRef = toReactive(props.disabled ?? false, (v) => container.classList.toggle('mui-select-disabled', v));
|
|
1206
|
+
const modelRef = $modelOrRef(props, props.value ?? '');
|
|
1207
|
+
const styleRef = toReactive(parseStyle(props.style ?? ''));
|
|
1208
|
+
const classRef = toReactive(props.class ?? '');
|
|
1209
|
+
const sizeRef = toReactive(props.size ?? 'medium');
|
|
1210
|
+
const fullwidthRef = toReactive(props.fullWidth ?? false);
|
|
1211
|
+
const className = computed(() => {
|
|
1212
|
+
return `mui-select-wrapper mui-select-size-${sizeRef.value} ${fullwidthRef.value ? 'mui-select-fullWidth' : ''} ${classRef.value} ${disabledRef.value ? 'mui-select-disabled' : ''}`;
|
|
1213
|
+
}, [sizeRef, fullwidthRef, classRef, disabledRef]);
|
|
1214
|
+
const label = computed(() => {
|
|
1215
|
+
if (labelRef.value) {
|
|
1216
|
+
return (jsx("label", { class: `mui-select-label ${modelRef.value || isFocusedRef.value || placeholderRef.value ? 'focused' : ''}`, children: labelRef }));
|
|
1217
|
+
}
|
|
1218
|
+
return '';
|
|
1219
|
+
}, [labelRef, modelRef, isFocusedRef, placeholderRef]);
|
|
1220
|
+
// Toggle dropdown
|
|
1221
|
+
const toggleMenu = () => {
|
|
1222
|
+
if (!disabledRef.value) {
|
|
1223
|
+
open.value = !open.value;
|
|
1224
|
+
}
|
|
1036
1225
|
};
|
|
1037
1226
|
// Handle option click
|
|
1038
|
-
const handleOptionClick = (
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
onChange(
|
|
1042
|
-
|
|
1043
|
-
updateLabelState();
|
|
1044
|
-
valueDisplay.redraw();
|
|
1045
|
-
setTimeout(() => menu.redraw(), 200);
|
|
1227
|
+
const handleOptionClick = (e) => {
|
|
1228
|
+
const newValue = e.currentTarget.dataset.value;
|
|
1229
|
+
modelRef.value = newValue;
|
|
1230
|
+
onChange(newValue);
|
|
1231
|
+
open.value = false;
|
|
1046
1232
|
};
|
|
1047
1233
|
// Close menu when clicking outside
|
|
1048
1234
|
const handleClickOutside = (e) => {
|
|
1049
|
-
if (!
|
|
1050
|
-
|
|
1051
|
-
updateMenu();
|
|
1235
|
+
if (!container.contains(e.target)) {
|
|
1236
|
+
open.value = false;
|
|
1052
1237
|
}
|
|
1053
1238
|
};
|
|
1054
1239
|
// Handle focus
|
|
1055
|
-
const handleFocus = () =>
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
selectLabelRef.value.classList?.toggle('focused', isFocused || !!value);
|
|
1066
|
-
};
|
|
1067
|
-
const valueDisplay = createRedrawable(() => {
|
|
1068
|
-
const o = options.find((opt) => opt.value === value);
|
|
1069
|
-
let inner;
|
|
1070
|
-
if (o === undefined) {
|
|
1071
|
-
inner = jsx("span", { class: "mui-select-placeholder", children: placeholder || '\u00a0' });
|
|
1072
|
-
}
|
|
1073
|
-
else {
|
|
1074
|
-
inner = o.label;
|
|
1075
|
-
}
|
|
1076
|
-
return jsx("div", { class: "mui-select-display", children: inner });
|
|
1077
|
-
});
|
|
1078
|
-
const menu = createRedrawable(() => {
|
|
1079
|
-
return (jsx("div", { class: "mui-select-menu", style: "display: none;", children: options.map((option) => (jsx("div", { class: `mui-select-option ${option.value === value ? 'selected' : ''}`, "on:click": () => handleOptionClick(option.value), children: option.label }))) }));
|
|
1080
|
-
});
|
|
1240
|
+
const handleFocus = () => (isFocusedRef.value = true);
|
|
1241
|
+
const handleBlur = () => (isFocusedRef.value = false);
|
|
1242
|
+
const defaultEmpty = jsx("span", { class: "mui-select-placeholder", children: placeholderRef.value || '\u00a0' });
|
|
1243
|
+
const displayedValue = computed(() => {
|
|
1244
|
+
const o = optionsRef.value.find((item) => item.value === modelRef.value);
|
|
1245
|
+
return jsx("div", { class: "mui-select-display", children: o?.label ?? defaultEmpty });
|
|
1246
|
+
}, [modelRef]);
|
|
1247
|
+
const menu = computed(() => {
|
|
1248
|
+
return (jsxs("div", { class: "mui-select-menu", style: "display: none;", children: [optionsRef.value.map((o) => (jsx("div", { class: `mui-select-option ${o.value === modelRef.value ? 'selected' : ''}`, "data-value": o.value, "on:click": handleOptionClick, children: o.label }))), ' '] }));
|
|
1249
|
+
}, [optionsRef, modelRef]);
|
|
1081
1250
|
// Create container
|
|
1082
|
-
const container = (jsxs("div", {
|
|
1083
|
-
$defines(container, {
|
|
1084
|
-
value: {
|
|
1085
|
-
get: () => value,
|
|
1086
|
-
set: (newValue) => {
|
|
1087
|
-
value = newValue;
|
|
1088
|
-
updateLabelState();
|
|
1089
|
-
valueDisplay.redraw();
|
|
1090
|
-
menu.redraw();
|
|
1091
|
-
},
|
|
1092
|
-
},
|
|
1093
|
-
disabled: {
|
|
1094
|
-
get: () => disabled,
|
|
1095
|
-
set: (newDisabled) => {
|
|
1096
|
-
disabled = newDisabled;
|
|
1097
|
-
if (disabled) {
|
|
1098
|
-
isOpen = false;
|
|
1099
|
-
updateMenu();
|
|
1100
|
-
}
|
|
1101
|
-
container.classList.toggle('mui-select-disabled', disabled);
|
|
1102
|
-
},
|
|
1103
|
-
},
|
|
1104
|
-
});
|
|
1251
|
+
const container = (jsxs("div", { class: className, style: styleRef, children: [label, jsxs("div", { class: "mui-select-control mui-select-outlined", "on:click": toggleMenu, "on:focus": handleFocus, "on:blur": handleBlur, tabIndex: disabledRef.value ? -1 : 0, children: [displayedValue, jsx("input", { type: "hidden", value: modelRef }), jsx("fieldset", { class: "mui-select-fieldset", children: jsx("legend", { class: "mui-select-legend", children: jsx("span", { children: labelRef }) }) }), jsx("svg", { class: "mui-select-icon", focusable: "false", "aria-hidden": "true", viewBox: "0 0 24 24", width: "24", height: "24", children: jsx("path", { d: "M7 10l5 5 5-5Z", fill: "currentColor" }) })] }), menu] }));
|
|
1105
1252
|
// Add global click listener
|
|
1106
1253
|
setTimeout(() => {
|
|
1107
1254
|
document.removeEventListener('click', handleClickOutside);
|
|
1108
1255
|
document.addEventListener('click', handleClickOutside);
|
|
1109
|
-
updateLabelState();
|
|
1110
1256
|
}, 0);
|
|
1111
1257
|
return container;
|
|
1112
1258
|
}
|
|
1113
1259
|
|
|
1260
|
+
/**
|
|
1261
|
+
* Card component - mimics MUI Card appearance and behavior
|
|
1262
|
+
*/
|
|
1263
|
+
function Card(props) {
|
|
1264
|
+
// # ref props
|
|
1265
|
+
const variantRef = toReactive(props.variant ?? 'elevation');
|
|
1266
|
+
const elevationRef = toReactive(props.elevation ?? 1);
|
|
1267
|
+
const squareRef = toReactive(props.square ?? false);
|
|
1268
|
+
const raisedRef = toReactive(props.raised ?? false);
|
|
1269
|
+
const styleRef = toReactive(parseStyle(props.style ?? ''));
|
|
1270
|
+
const classRef = toReactive(props.class ?? '');
|
|
1271
|
+
const className = computed(() => {
|
|
1272
|
+
const base = 'mui-card';
|
|
1273
|
+
const variantClass = `mui-card-${variantRef.value}`;
|
|
1274
|
+
const elevationClass = variantRef.value === 'elevation' ? `mui-card-elevation-${Math.min(24, Math.max(0, elevationRef.value))}` : '';
|
|
1275
|
+
const squareClass = squareRef.value ? 'mui-card-square' : '';
|
|
1276
|
+
const raisedClass = raisedRef.value ? 'mui-card-raised' : '';
|
|
1277
|
+
return `${base} ${variantClass} ${elevationClass} ${squareClass} ${raisedClass} ${classRef.value}`.trim().replace(/\s+/g, ' ');
|
|
1278
|
+
}, [variantRef, elevationRef, squareRef, raisedRef, classRef]);
|
|
1279
|
+
// Handle click
|
|
1280
|
+
const handleClick = props['on:click'] ?? (() => { });
|
|
1281
|
+
const container = (jsx("div", { class: className, style: styleRef, "on:click": handleClick, children: props.children }));
|
|
1282
|
+
return container;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* Switch component - mimics MUI Switch appearance and behavior
|
|
1287
|
+
*/
|
|
1288
|
+
function Switch(props) {
|
|
1289
|
+
const onChange = props['on:change'] ?? $emptyFn;
|
|
1290
|
+
// # ref props
|
|
1291
|
+
const labelRef = toReactive(props.label ?? '');
|
|
1292
|
+
const valueRef = toReactive(props.value ?? '');
|
|
1293
|
+
const colorRef = toReactive(props.color ?? 'primary');
|
|
1294
|
+
const sizeRef = toReactive(props.size ?? 'medium');
|
|
1295
|
+
const disabledRef = toReactive(props.disabled ?? false, (v) => {
|
|
1296
|
+
inputEl.disabled = v;
|
|
1297
|
+
container.classList.toggle('mui-switch-disabled', v);
|
|
1298
|
+
});
|
|
1299
|
+
const modelRef = $modelOrRef(props, props.checked ?? false);
|
|
1300
|
+
modelRef.addOnChange((newValue) => {
|
|
1301
|
+
inputEl.checked = newValue;
|
|
1302
|
+
track.classList.toggle('mui-switch-track-checked', newValue);
|
|
1303
|
+
thumb.classList.toggle('mui-switch-thumb-checked', newValue);
|
|
1304
|
+
});
|
|
1305
|
+
const styleRef = toReactive(parseStyle(props.style ?? ''));
|
|
1306
|
+
const classRef = toReactive(props.class ?? '');
|
|
1307
|
+
const className = computed(() => {
|
|
1308
|
+
return `mui-switch-wrapper mui-switch-size-${sizeRef.value} ${disabledRef.value ? 'mui-switch-disabled' : ''} mui-switch-color-${colorRef.value} ${classRef.value}`;
|
|
1309
|
+
}, [colorRef, disabledRef, sizeRef, classRef]);
|
|
1310
|
+
// Handle change
|
|
1311
|
+
const handleChange = () => {
|
|
1312
|
+
if (disabledRef.value) {
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
modelRef.value = inputEl.checked;
|
|
1316
|
+
onChange(modelRef.value, valueRef.value);
|
|
1317
|
+
};
|
|
1318
|
+
const inputEl = (jsx("input", { type: "checkbox", class: "mui-switch-input", checked: modelRef.value, value: valueRef, disabled: disabledRef, "on:change": handleChange }));
|
|
1319
|
+
const track = jsx("span", { class: "mui-switch-track" });
|
|
1320
|
+
const thumb = jsx("span", { class: "mui-switch-thumb" });
|
|
1321
|
+
const container = (jsxs("label", { class: className, style: styleRef, children: [inputEl, jsxs("span", { class: "mui-switch-base", children: [track, thumb] }), jsx("span", { "k-if": labelRef, class: "mui-switch-label", children: labelRef })] }));
|
|
1322
|
+
// Initialize state
|
|
1323
|
+
track.classList.toggle('mui-switch-track-checked', modelRef.value);
|
|
1324
|
+
thumb.classList.toggle('mui-switch-thumb-checked', modelRef.value);
|
|
1325
|
+
return container;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1114
1328
|
function DownloadIcon(props) {
|
|
1115
1329
|
return (jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", width: "1em", height: "1em", ...props, children: jsx("path", { d: "M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" }) }));
|
|
1116
1330
|
}
|
|
@@ -1201,6 +1415,7 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
1201
1415
|
|
|
1202
1416
|
exports.Alert = Alert;
|
|
1203
1417
|
exports.Button = Button;
|
|
1418
|
+
exports.Card = Card;
|
|
1204
1419
|
exports.Checkbox = Checkbox;
|
|
1205
1420
|
exports.CheckboxGroup = CheckboxGroup;
|
|
1206
1421
|
exports.ColorLensIcon = ColorLensIcon;
|
|
@@ -1228,6 +1443,7 @@ var __ktjs_mui__ = (function (exports) {
|
|
|
1228
1443
|
exports.SettingsIcon = SettingsIcon;
|
|
1229
1444
|
exports.StopIcon = StopIcon;
|
|
1230
1445
|
exports.SubtitlesIcon = SubtitlesIcon;
|
|
1446
|
+
exports.Switch = Switch;
|
|
1231
1447
|
exports.TextField = TextField;
|
|
1232
1448
|
exports.UploadFileIcon = UploadFileIcon;
|
|
1233
1449
|
exports.VideoFileIcon = VideoFileIcon;
|