@ktjs/core 0.20.3 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -453
- package/dist/index.d.ts +33 -4
- package/dist/index.iife.js +68 -25
- package/dist/index.legacy.js +68 -26
- package/dist/index.mjs +67 -26
- package/dist/jsx/index.d.ts +33 -3
- package/dist/jsx/index.mjs +67 -26
- package/dist/jsx/jsx-runtime.d.ts +16 -2
- package/dist/jsx/jsx-runtime.mjs +41 -25
- package/package.json +2 -2
package/dist/index.legacy.js
CHANGED
|
@@ -3,6 +3,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
3
3
|
|
|
4
4
|
// Cached native methods for performance optimization
|
|
5
5
|
const $isArray = Array.isArray;
|
|
6
|
+
const $entries = Object.entries;
|
|
6
7
|
const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
|
|
7
8
|
|
|
8
9
|
// Error handling utilities
|
|
@@ -12,6 +13,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
12
13
|
|
|
13
14
|
// DOM manipulation utilities
|
|
14
15
|
// # dom natives
|
|
16
|
+
const $replaceWith = Element.prototype.replaceWith;
|
|
15
17
|
/**
|
|
16
18
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
17
19
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -51,7 +53,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
51
53
|
|
|
52
54
|
// Shared utilities and cached native methods for kt.js framework
|
|
53
55
|
// Re-export all utilities
|
|
54
|
-
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.
|
|
56
|
+
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.2' });
|
|
55
57
|
|
|
56
58
|
var booleanHandler = function (element, key, value) {
|
|
57
59
|
if (key in element) {
|
|
@@ -199,7 +201,6 @@ var __ktjs_core__ = (function (exports) {
|
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
203
|
|
|
202
|
-
document.createElement('div');
|
|
203
204
|
var htmlCreator = function (tag) { return document.createElement(tag); };
|
|
204
205
|
var svgCreator = function (tag) { return document.createElementNS('http://www.w3.org/2000/svg', tag); };
|
|
205
206
|
var mathMLCreator = function (tag) { return document.createElementNS('http://www.w3.org/1998/Math/MathML', tag); };
|
|
@@ -217,7 +218,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
217
218
|
* ## About
|
|
218
219
|
* @package @ktjs/core
|
|
219
220
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
220
|
-
* @version 0.
|
|
221
|
+
* @version 0.21.1 (Last Update: 2026.02.02 09:20:07.959)
|
|
221
222
|
* @license MIT
|
|
222
223
|
* @link https://github.com/baendlorel/kt.js
|
|
223
224
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -246,14 +247,6 @@ var __ktjs_core__ = (function (exports) {
|
|
|
246
247
|
// * Handle content
|
|
247
248
|
applyAttr(element, attr);
|
|
248
249
|
applyContent(element, content);
|
|
249
|
-
// if (tag === 'svg') {
|
|
250
|
-
// tempWrapper.innerHTML = element.outerHTML;
|
|
251
|
-
// return tempWrapper.firstChild as HTML<T>;
|
|
252
|
-
// }
|
|
253
|
-
// if (tag === 'math') {
|
|
254
|
-
// tempWrapper.innerHTML = element.outerHTML;
|
|
255
|
-
// return tempWrapper.firstChild as HTML<T>;
|
|
256
|
-
// }
|
|
257
250
|
return element;
|
|
258
251
|
};
|
|
259
252
|
|
|
@@ -307,38 +300,85 @@ var __ktjs_core__ = (function (exports) {
|
|
|
307
300
|
};
|
|
308
301
|
return KTRef;
|
|
309
302
|
}());
|
|
303
|
+
var isKTRef = function (obj) {
|
|
304
|
+
return typeof obj === 'object' && obj !== null && obj.isKT === true;
|
|
305
|
+
};
|
|
310
306
|
/**
|
|
311
307
|
* Reference to the created HTML element.
|
|
308
|
+
* - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
|
|
312
309
|
* - can alse be used to store normal values, but it is not reactive.
|
|
313
310
|
* @param value mostly an HTMLElement
|
|
314
311
|
*/
|
|
315
312
|
function ref(value, onChange) {
|
|
316
313
|
return new KTRef(value, onChange ? [onChange] : []);
|
|
317
314
|
}
|
|
315
|
+
function kcollect() {
|
|
316
|
+
var newObj = {};
|
|
317
|
+
var entries = $entries(this);
|
|
318
|
+
for (var i = 0; i < entries.length; i++) {
|
|
319
|
+
var key = entries[i][0];
|
|
320
|
+
if (key === 'kcollect') {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
newObj[key] = entries[i][1].value;
|
|
324
|
+
}
|
|
325
|
+
return newObj;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Make all first-level properties of the object a `KTRef`.
|
|
329
|
+
* - `obj.a.b` is not reactive
|
|
330
|
+
*/
|
|
331
|
+
var surfaceRef = function (obj) {
|
|
332
|
+
var entries = $entries(obj);
|
|
333
|
+
var newObj = { kcollect: kcollect };
|
|
334
|
+
for (var i = 0; i < entries.length; i++) {
|
|
335
|
+
newObj[entries[i][0]] = ref(entries[i][1]);
|
|
336
|
+
}
|
|
337
|
+
return newObj;
|
|
338
|
+
};
|
|
318
339
|
|
|
319
340
|
var dummyRef = { value: null };
|
|
341
|
+
var create = function (tag, props) {
|
|
342
|
+
if (typeof tag === 'function') {
|
|
343
|
+
return tag(props);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
return h(tag, props, props.children);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
var placeholder = function () { return document.createComment('k-if'); };
|
|
320
350
|
/**
|
|
321
351
|
* @param tag html tag or function component
|
|
322
352
|
* @param props properties/attributes
|
|
323
353
|
*/
|
|
324
354
|
function jsx(tag, props) {
|
|
325
|
-
var
|
|
326
|
-
var ref = ((_a = props.ref) === null || _a === void 0 ? void 0 : _a.isKT) ? props.ref : dummyRef;
|
|
355
|
+
var maybeDummyRef = isKTRef(props.ref) ? props.ref : dummyRef;
|
|
327
356
|
var el;
|
|
328
|
-
if ('k-if' in props
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
357
|
+
if ('k-if' in props) {
|
|
358
|
+
var kif = props['k-if'];
|
|
359
|
+
var condition = kif; // assume boolean by default
|
|
360
|
+
// Handle reactive k-if
|
|
361
|
+
if (isKTRef(kif)) {
|
|
362
|
+
kif.addOnChange(function (newValue, oldValue) {
|
|
363
|
+
if (newValue === oldValue) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
var oldEl = el;
|
|
367
|
+
el = newValue ? create(tag, props) : placeholder();
|
|
368
|
+
$replaceWith.call(oldEl, el);
|
|
369
|
+
maybeDummyRef.value = el;
|
|
370
|
+
});
|
|
371
|
+
condition = kif.value;
|
|
372
|
+
}
|
|
373
|
+
if (!condition) {
|
|
374
|
+
// & make comment placeholder in case that ref might be redrawn later
|
|
375
|
+
el = placeholder();
|
|
376
|
+
maybeDummyRef.value = el;
|
|
377
|
+
return el;
|
|
378
|
+
}
|
|
340
379
|
}
|
|
341
|
-
|
|
380
|
+
el = create(tag, props);
|
|
381
|
+
maybeDummyRef.value = el;
|
|
342
382
|
return el;
|
|
343
383
|
}
|
|
344
384
|
/**
|
|
@@ -644,10 +684,12 @@ var __ktjs_core__ = (function (exports) {
|
|
|
644
684
|
exports.createElement = h;
|
|
645
685
|
exports.createRedrawable = createRedrawable;
|
|
646
686
|
exports.h = h;
|
|
687
|
+
exports.isKTRef = isKTRef;
|
|
647
688
|
exports.jsx = jsx;
|
|
648
689
|
exports.jsxDEV = jsxDEV;
|
|
649
690
|
exports.jsxs = jsxs;
|
|
650
691
|
exports.ref = ref;
|
|
692
|
+
exports.surfaceRef = surfaceRef;
|
|
651
693
|
|
|
652
694
|
return exports;
|
|
653
695
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Cached native methods for performance optimization
|
|
2
2
|
const $isArray = Array.isArray;
|
|
3
|
+
const $entries = Object.entries;
|
|
3
4
|
const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
|
|
4
5
|
|
|
5
6
|
// Error handling utilities
|
|
@@ -9,6 +10,7 @@ const $throw = (message) => {
|
|
|
9
10
|
|
|
10
11
|
// DOM manipulation utilities
|
|
11
12
|
// # dom natives
|
|
13
|
+
const $replaceWith = Element.prototype.replaceWith;
|
|
12
14
|
/**
|
|
13
15
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
14
16
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -48,7 +50,7 @@ const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwn
|
|
|
48
50
|
|
|
49
51
|
// Shared utilities and cached native methods for kt.js framework
|
|
50
52
|
// Re-export all utilities
|
|
51
|
-
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.
|
|
53
|
+
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.2' });
|
|
52
54
|
|
|
53
55
|
const booleanHandler = (element, key, value) => {
|
|
54
56
|
if (key in element) {
|
|
@@ -191,7 +193,6 @@ function applyContent(element, content) {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
document.createElement('div');
|
|
195
196
|
const htmlCreator = (tag) => document.createElement(tag);
|
|
196
197
|
const svgCreator = (tag) => document.createElementNS('http://www.w3.org/2000/svg', tag);
|
|
197
198
|
const mathMLCreator = (tag) => document.createElementNS('http://www.w3.org/1998/Math/MathML', tag);
|
|
@@ -209,7 +210,7 @@ const MATHML_ATTR_FLAG = '__kt_mathml__';
|
|
|
209
210
|
* ## About
|
|
210
211
|
* @package @ktjs/core
|
|
211
212
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
212
|
-
* @version 0.
|
|
213
|
+
* @version 0.21.1 (Last Update: 2026.02.02 09:20:07.959)
|
|
213
214
|
* @license MIT
|
|
214
215
|
* @link https://github.com/baendlorel/kt.js
|
|
215
216
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -238,14 +239,6 @@ const h = (tag, attr, content) => {
|
|
|
238
239
|
// * Handle content
|
|
239
240
|
applyAttr(element, attr);
|
|
240
241
|
applyContent(element, content);
|
|
241
|
-
// if (tag === 'svg') {
|
|
242
|
-
// tempWrapper.innerHTML = element.outerHTML;
|
|
243
|
-
// return tempWrapper.firstChild as HTML<T>;
|
|
244
|
-
// }
|
|
245
|
-
// if (tag === 'math') {
|
|
246
|
-
// tempWrapper.innerHTML = element.outerHTML;
|
|
247
|
-
// return tempWrapper.firstChild as HTML<T>;
|
|
248
|
-
// }
|
|
249
242
|
return element;
|
|
250
243
|
};
|
|
251
244
|
|
|
@@ -302,37 +295,85 @@ class KTRef {
|
|
|
302
295
|
return false;
|
|
303
296
|
}
|
|
304
297
|
}
|
|
298
|
+
const isKTRef = (obj) => {
|
|
299
|
+
return typeof obj === 'object' && obj !== null && obj.isKT === true;
|
|
300
|
+
};
|
|
305
301
|
/**
|
|
306
302
|
* Reference to the created HTML element.
|
|
303
|
+
* - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
|
|
307
304
|
* - can alse be used to store normal values, but it is not reactive.
|
|
308
305
|
* @param value mostly an HTMLElement
|
|
309
306
|
*/
|
|
310
307
|
function ref(value, onChange) {
|
|
311
308
|
return new KTRef(value, onChange ? [onChange] : []);
|
|
312
309
|
}
|
|
310
|
+
function kcollect() {
|
|
311
|
+
const newObj = {};
|
|
312
|
+
const entries = $entries(this);
|
|
313
|
+
for (let i = 0; i < entries.length; i++) {
|
|
314
|
+
const key = entries[i][0];
|
|
315
|
+
if (key === 'kcollect') {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
newObj[key] = entries[i][1].value;
|
|
319
|
+
}
|
|
320
|
+
return newObj;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Make all first-level properties of the object a `KTRef`.
|
|
324
|
+
* - `obj.a.b` is not reactive
|
|
325
|
+
*/
|
|
326
|
+
const surfaceRef = (obj) => {
|
|
327
|
+
const entries = $entries(obj);
|
|
328
|
+
const newObj = { kcollect };
|
|
329
|
+
for (let i = 0; i < entries.length; i++) {
|
|
330
|
+
newObj[entries[i][0]] = ref(entries[i][1]);
|
|
331
|
+
}
|
|
332
|
+
return newObj;
|
|
333
|
+
};
|
|
313
334
|
|
|
314
335
|
const dummyRef = { value: null };
|
|
336
|
+
const create = (tag, props) => {
|
|
337
|
+
if (typeof tag === 'function') {
|
|
338
|
+
return tag(props);
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
return h(tag, props, props.children);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const placeholder = () => document.createComment('k-if');
|
|
315
345
|
/**
|
|
316
346
|
* @param tag html tag or function component
|
|
317
347
|
* @param props properties/attributes
|
|
318
348
|
*/
|
|
319
349
|
function jsx(tag, props) {
|
|
320
|
-
const
|
|
350
|
+
const maybeDummyRef = isKTRef(props.ref) ? props.ref : dummyRef;
|
|
321
351
|
let el;
|
|
322
|
-
if ('k-if' in props
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
352
|
+
if ('k-if' in props) {
|
|
353
|
+
const kif = props['k-if'];
|
|
354
|
+
let condition = kif; // assume boolean by default
|
|
355
|
+
// Handle reactive k-if
|
|
356
|
+
if (isKTRef(kif)) {
|
|
357
|
+
kif.addOnChange((newValue, oldValue) => {
|
|
358
|
+
if (newValue === oldValue) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const oldEl = el;
|
|
362
|
+
el = newValue ? create(tag, props) : placeholder();
|
|
363
|
+
$replaceWith.call(oldEl, el);
|
|
364
|
+
maybeDummyRef.value = el;
|
|
365
|
+
});
|
|
366
|
+
condition = kif.value;
|
|
367
|
+
}
|
|
368
|
+
if (!condition) {
|
|
369
|
+
// & make comment placeholder in case that ref might be redrawn later
|
|
370
|
+
el = placeholder();
|
|
371
|
+
maybeDummyRef.value = el;
|
|
372
|
+
return el;
|
|
373
|
+
}
|
|
334
374
|
}
|
|
335
|
-
|
|
375
|
+
el = create(tag, props);
|
|
376
|
+
maybeDummyRef.value = el;
|
|
336
377
|
return el;
|
|
337
378
|
}
|
|
338
379
|
/**
|
|
@@ -624,4 +665,4 @@ function getSequence(arr) {
|
|
|
624
665
|
return result;
|
|
625
666
|
}
|
|
626
667
|
|
|
627
|
-
export { Fragment, KTAsync, KTFor, KTRef, h as createElement, createRedrawable, h, jsx, jsxDEV, jsxs, ref };
|
|
668
|
+
export { Fragment, KTAsync, KTFor, KTRef, h as createElement, createRedrawable, h, isKTRef, jsx, jsxDEV, jsxs, ref, surfaceRef };
|
package/dist/jsx/index.d.ts
CHANGED
|
@@ -22,12 +22,35 @@ declare class KTRef<T> {
|
|
|
22
22
|
addOnChange(callback: RefChangeHandler<T>): void;
|
|
23
23
|
removeOnChange(callback: RefChangeHandler<T>): boolean;
|
|
24
24
|
}
|
|
25
|
+
declare const isKTRef: <T = any>(obj: any) => obj is KTRef<T>;
|
|
25
26
|
/**
|
|
26
27
|
* Reference to the created HTML element.
|
|
28
|
+
* - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
|
|
27
29
|
* - can alse be used to store normal values, but it is not reactive.
|
|
28
30
|
* @param value mostly an HTMLElement
|
|
29
31
|
*/
|
|
30
32
|
declare function ref<T = JSX.Element>(value?: T, onChange?: RefChangeHandler<T>): KTRef<T>;
|
|
33
|
+
type KTSurfaceRef<T extends Object> = {
|
|
34
|
+
[K in keyof T]: KTRef<T[K]>;
|
|
35
|
+
} & {
|
|
36
|
+
/**
|
|
37
|
+
* Get the dereferenced object like the original one
|
|
38
|
+
*/
|
|
39
|
+
kcollect: () => T;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Make all first-level properties of the object a `KTRef`.
|
|
43
|
+
* - `obj.a.b` is not reactive
|
|
44
|
+
*/
|
|
45
|
+
declare const surfaceRef: <T extends Object>(obj: T) => KTSurfaceRef<T>;
|
|
46
|
+
|
|
47
|
+
type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
|
|
48
|
+
? SVGElementTagNameMap[T]
|
|
49
|
+
: T extends HTMLTag
|
|
50
|
+
? HTMLElementTagNameMap[T]
|
|
51
|
+
: T extends MathMLTag
|
|
52
|
+
? MathMLElementTagNameMap[T]
|
|
53
|
+
: HTMLElement;
|
|
31
54
|
|
|
32
55
|
type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
|
|
33
56
|
type KTAvailableContent = SingleContent | KTAvailableContent[];
|
|
@@ -42,7 +65,14 @@ interface KTBaseAttribute {
|
|
|
42
65
|
|
|
43
66
|
// # kt-specific attributes
|
|
44
67
|
ref?: KTRef<JSX.Element>;
|
|
68
|
+
|
|
69
|
+
// todo 是否要让k-if是KTRef的时候具备响应能力?
|
|
70
|
+
/**
|
|
71
|
+
* If a `KTRef` is bound, it will be reactive; otherwise, it will be static.
|
|
72
|
+
*/
|
|
45
73
|
'k-if'?: any;
|
|
74
|
+
// todo k-model如何指定value还是checked还是别的什么?
|
|
75
|
+
'k-model'?: KTRef<any>;
|
|
46
76
|
|
|
47
77
|
// # normal HTML attributes
|
|
48
78
|
id?: string;
|
|
@@ -103,7 +133,6 @@ type KTPrefixedEventHandlers = {
|
|
|
103
133
|
|
|
104
134
|
type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
|
|
105
135
|
|
|
106
|
-
type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag ? SVGElementTagNameMap[T] : T extends HTMLTag ? HTMLElementTagNameMap[T] : T extends MathMLTag ? MathMLElementTagNameMap[T] : HTMLElement;
|
|
107
136
|
/**
|
|
108
137
|
* Create an enhanced HTMLElement.
|
|
109
138
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -114,7 +143,7 @@ type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SV
|
|
|
114
143
|
* ## About
|
|
115
144
|
* @package @ktjs/core
|
|
116
145
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
117
|
-
* @version 0.
|
|
146
|
+
* @version 0.21.1 (Last Update: 2026.02.02 09:20:07.959)
|
|
118
147
|
* @license MIT
|
|
119
148
|
* @link https://github.com/baendlorel/kt.js
|
|
120
149
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -1393,4 +1422,5 @@ declare global {
|
|
|
1393
1422
|
}
|
|
1394
1423
|
}
|
|
1395
1424
|
|
|
1396
|
-
export { Fragment, KTRef, h as createElement, createRedrawable, jsx, jsxDEV, jsxs, ref };
|
|
1425
|
+
export { Fragment, KTRef, h as createElement, createRedrawable, isKTRef, jsx, jsxDEV, jsxs, ref, surfaceRef };
|
|
1426
|
+
export type { KTSurfaceRef };
|
package/dist/jsx/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Cached native methods for performance optimization
|
|
2
2
|
const $isArray = Array.isArray;
|
|
3
|
+
const $entries = Object.entries;
|
|
3
4
|
const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
|
|
4
5
|
|
|
5
6
|
// Error handling utilities
|
|
@@ -9,6 +10,7 @@ const $throw = (message) => {
|
|
|
9
10
|
|
|
10
11
|
// DOM manipulation utilities
|
|
11
12
|
// # dom natives
|
|
13
|
+
const $replaceWith = Element.prototype.replaceWith;
|
|
12
14
|
/**
|
|
13
15
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
14
16
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -48,7 +50,7 @@ const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwn
|
|
|
48
50
|
|
|
49
51
|
// Shared utilities and cached native methods for kt.js framework
|
|
50
52
|
// Re-export all utilities
|
|
51
|
-
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.
|
|
53
|
+
Object.defineProperty(window, '@ktjs/shared', { value: '0.20.2' });
|
|
52
54
|
|
|
53
55
|
const booleanHandler = (element, key, value) => {
|
|
54
56
|
if (key in element) {
|
|
@@ -191,7 +193,6 @@ function applyContent(element, content) {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
document.createElement('div');
|
|
195
196
|
const htmlCreator = (tag) => document.createElement(tag);
|
|
196
197
|
const svgCreator = (tag) => document.createElementNS('http://www.w3.org/2000/svg', tag);
|
|
197
198
|
const mathMLCreator = (tag) => document.createElementNS('http://www.w3.org/1998/Math/MathML', tag);
|
|
@@ -209,7 +210,7 @@ const MATHML_ATTR_FLAG = '__kt_mathml__';
|
|
|
209
210
|
* ## About
|
|
210
211
|
* @package @ktjs/core
|
|
211
212
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
212
|
-
* @version 0.
|
|
213
|
+
* @version 0.21.1 (Last Update: 2026.02.02 09:20:07.959)
|
|
213
214
|
* @license MIT
|
|
214
215
|
* @link https://github.com/baendlorel/kt.js
|
|
215
216
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -238,14 +239,6 @@ const h = (tag, attr, content) => {
|
|
|
238
239
|
// * Handle content
|
|
239
240
|
applyAttr(element, attr);
|
|
240
241
|
applyContent(element, content);
|
|
241
|
-
// if (tag === 'svg') {
|
|
242
|
-
// tempWrapper.innerHTML = element.outerHTML;
|
|
243
|
-
// return tempWrapper.firstChild as HTML<T>;
|
|
244
|
-
// }
|
|
245
|
-
// if (tag === 'math') {
|
|
246
|
-
// tempWrapper.innerHTML = element.outerHTML;
|
|
247
|
-
// return tempWrapper.firstChild as HTML<T>;
|
|
248
|
-
// }
|
|
249
242
|
return element;
|
|
250
243
|
};
|
|
251
244
|
|
|
@@ -302,37 +295,85 @@ class KTRef {
|
|
|
302
295
|
return false;
|
|
303
296
|
}
|
|
304
297
|
}
|
|
298
|
+
const isKTRef = (obj) => {
|
|
299
|
+
return typeof obj === 'object' && obj !== null && obj.isKT === true;
|
|
300
|
+
};
|
|
305
301
|
/**
|
|
306
302
|
* Reference to the created HTML element.
|
|
303
|
+
* - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
|
|
307
304
|
* - can alse be used to store normal values, but it is not reactive.
|
|
308
305
|
* @param value mostly an HTMLElement
|
|
309
306
|
*/
|
|
310
307
|
function ref(value, onChange) {
|
|
311
308
|
return new KTRef(value, onChange ? [onChange] : []);
|
|
312
309
|
}
|
|
310
|
+
function kcollect() {
|
|
311
|
+
const newObj = {};
|
|
312
|
+
const entries = $entries(this);
|
|
313
|
+
for (let i = 0; i < entries.length; i++) {
|
|
314
|
+
const key = entries[i][0];
|
|
315
|
+
if (key === 'kcollect') {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
newObj[key] = entries[i][1].value;
|
|
319
|
+
}
|
|
320
|
+
return newObj;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Make all first-level properties of the object a `KTRef`.
|
|
324
|
+
* - `obj.a.b` is not reactive
|
|
325
|
+
*/
|
|
326
|
+
const surfaceRef = (obj) => {
|
|
327
|
+
const entries = $entries(obj);
|
|
328
|
+
const newObj = { kcollect };
|
|
329
|
+
for (let i = 0; i < entries.length; i++) {
|
|
330
|
+
newObj[entries[i][0]] = ref(entries[i][1]);
|
|
331
|
+
}
|
|
332
|
+
return newObj;
|
|
333
|
+
};
|
|
313
334
|
|
|
314
335
|
const dummyRef = { value: null };
|
|
336
|
+
const create = (tag, props) => {
|
|
337
|
+
if (typeof tag === 'function') {
|
|
338
|
+
return tag(props);
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
return h(tag, props, props.children);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const placeholder = () => document.createComment('k-if');
|
|
315
345
|
/**
|
|
316
346
|
* @param tag html tag or function component
|
|
317
347
|
* @param props properties/attributes
|
|
318
348
|
*/
|
|
319
349
|
function jsx(tag, props) {
|
|
320
|
-
const
|
|
350
|
+
const maybeDummyRef = isKTRef(props.ref) ? props.ref : dummyRef;
|
|
321
351
|
let el;
|
|
322
|
-
if ('k-if' in props
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
352
|
+
if ('k-if' in props) {
|
|
353
|
+
const kif = props['k-if'];
|
|
354
|
+
let condition = kif; // assume boolean by default
|
|
355
|
+
// Handle reactive k-if
|
|
356
|
+
if (isKTRef(kif)) {
|
|
357
|
+
kif.addOnChange((newValue, oldValue) => {
|
|
358
|
+
if (newValue === oldValue) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const oldEl = el;
|
|
362
|
+
el = newValue ? create(tag, props) : placeholder();
|
|
363
|
+
$replaceWith.call(oldEl, el);
|
|
364
|
+
maybeDummyRef.value = el;
|
|
365
|
+
});
|
|
366
|
+
condition = kif.value;
|
|
367
|
+
}
|
|
368
|
+
if (!condition) {
|
|
369
|
+
// & make comment placeholder in case that ref might be redrawn later
|
|
370
|
+
el = placeholder();
|
|
371
|
+
maybeDummyRef.value = el;
|
|
372
|
+
return el;
|
|
373
|
+
}
|
|
334
374
|
}
|
|
335
|
-
|
|
375
|
+
el = create(tag, props);
|
|
376
|
+
maybeDummyRef.value = el;
|
|
336
377
|
return el;
|
|
337
378
|
}
|
|
338
379
|
/**
|
|
@@ -400,4 +441,4 @@ function createRedrawable(creator) {
|
|
|
400
441
|
return elRef;
|
|
401
442
|
}
|
|
402
443
|
|
|
403
|
-
export { Fragment, KTRef, h as createElement, createRedrawable, jsx, jsxDEV, jsxs, ref };
|
|
444
|
+
export { Fragment, KTRef, h as createElement, createRedrawable, isKTRef, jsx, jsxDEV, jsxs, ref, surfaceRef };
|
|
@@ -23,6 +23,14 @@ declare class KTRef<T> {
|
|
|
23
23
|
removeOnChange(callback: RefChangeHandler<T>): boolean;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
|
|
27
|
+
? SVGElementTagNameMap[T]
|
|
28
|
+
: T extends HTMLTag
|
|
29
|
+
? HTMLElementTagNameMap[T]
|
|
30
|
+
: T extends MathMLTag
|
|
31
|
+
? MathMLElementTagNameMap[T]
|
|
32
|
+
: HTMLElement;
|
|
33
|
+
|
|
26
34
|
type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
|
|
27
35
|
type KTAvailableContent = SingleContent | KTAvailableContent[];
|
|
28
36
|
type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
|
|
@@ -36,7 +44,14 @@ interface KTBaseAttribute {
|
|
|
36
44
|
|
|
37
45
|
// # kt-specific attributes
|
|
38
46
|
ref?: KTRef<JSX.Element>;
|
|
47
|
+
|
|
48
|
+
// todo 是否要让k-if是KTRef的时候具备响应能力?
|
|
49
|
+
/**
|
|
50
|
+
* If a `KTRef` is bound, it will be reactive; otherwise, it will be static.
|
|
51
|
+
*/
|
|
39
52
|
'k-if'?: any;
|
|
53
|
+
// todo k-model如何指定value还是checked还是别的什么?
|
|
54
|
+
'k-model'?: KTRef<any>;
|
|
40
55
|
|
|
41
56
|
// # normal HTML attributes
|
|
42
57
|
id?: string;
|
|
@@ -97,7 +112,6 @@ type KTPrefixedEventHandlers = {
|
|
|
97
112
|
|
|
98
113
|
type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
|
|
99
114
|
|
|
100
|
-
type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag ? SVGElementTagNameMap[T] : T extends HTMLTag ? HTMLElementTagNameMap[T] : T extends MathMLTag ? MathMLElementTagNameMap[T] : HTMLElement;
|
|
101
115
|
/**
|
|
102
116
|
* Create an enhanced HTMLElement.
|
|
103
117
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -108,7 +122,7 @@ type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SV
|
|
|
108
122
|
* ## About
|
|
109
123
|
* @package @ktjs/core
|
|
110
124
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
111
|
-
* @version 0.
|
|
125
|
+
* @version 0.21.1 (Last Update: 2026.02.02 09:20:07.959)
|
|
112
126
|
* @license MIT
|
|
113
127
|
* @link https://github.com/baendlorel/kt.js
|
|
114
128
|
* @link https://baendlorel.github.io/ Welcome to my site!
|