@ktjs/core 0.18.1 → 0.18.3

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.d.ts CHANGED
@@ -21,7 +21,7 @@ interface KTRef<T> {
21
21
  * - can alse be used to store normal values, but it is not reactive.
22
22
  * @param value mostly an HTMLElement
23
23
  */
24
- declare function ref<T = HTMLElement>(value?: T): KTRef<T>;
24
+ declare function ref<T = HTMLElement>(value?: T, onChange?: ChangeHandler<T>): KTRef<T>;
25
25
 
26
26
  type Redraw = (props?: KTAttribute, ...args: any[]) => KTHTMLElement;
27
27
  type KTHTMLElement<El extends HTMLElement = HTMLElement, R extends Function = Redraw> = El & {
@@ -178,7 +178,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
178
178
  * ## About
179
179
  * @package @ktjs/core
180
180
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
181
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
181
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
182
182
  * @license MIT
183
183
  * @link https://github.com/baendlorel/kt.js
184
184
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -197,7 +197,7 @@ declare function jsx(tag: JSXTag, props?: KTAttribute): KTHTMLElement;
197
197
  * Fragment support - returns an array of children
198
198
  * Note: kt.js doesn't have a real Fragment concept,
199
199
  */
200
- declare function Fragment(props: {
200
+ declare function Fragment(_props: {
201
201
  children?: KTRawContent;
202
202
  }): HTMLElement;
203
203
  /**
@@ -215,7 +215,7 @@ var __ktjs_core__ = (function (exports) {
215
215
  * ## About
216
216
  * @package @ktjs/core
217
217
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
218
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
218
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
219
219
  * @license MIT
220
220
  * @link https://github.com/baendlorel/kt.js
221
221
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -243,9 +243,9 @@ var __ktjs_core__ = (function (exports) {
243
243
  * - can alse be used to store normal values, but it is not reactive.
244
244
  * @param value mostly an HTMLElement
245
245
  */
246
- function ref(value) {
246
+ function ref(value, onChange) {
247
247
  let _value = value;
248
- let _onChanges = [];
248
+ let _onChanges = onChange ? [onChange] : [];
249
249
  return {
250
250
  isKT: true,
251
251
  get value() {
@@ -291,9 +291,10 @@ var __ktjs_core__ = (function (exports) {
291
291
  let el;
292
292
  const redraw = (newProps) => {
293
293
  props = newProps ? { ...props, ...newProps } : props;
294
- const old = el;
295
294
  el = jsx(tag, props);
296
- old.replaceWith(el);
295
+ if (ref !== dummyRef) {
296
+ ref.value = el; // ref setter automatically replaces old element in DOM
297
+ }
297
298
  return el;
298
299
  };
299
300
  if ('k-if' in props && !props['k-if']) {
@@ -317,7 +318,7 @@ var __ktjs_core__ = (function (exports) {
317
318
  * Fragment support - returns an array of children
318
319
  * Note: kt.js doesn't have a real Fragment concept,
319
320
  */
320
- function Fragment(props) {
321
+ function Fragment(_props) {
321
322
  throw new Error("kt.js doesn't have a Fragment concept");
322
323
  // const { children } = props ?? {};
323
324
  // if (!children) {
@@ -397,9 +398,7 @@ var __ktjs_core__ = (function (exports) {
397
398
  const elRef = ref();
398
399
  elRef.value = creator();
399
400
  const redraw = () => {
400
- const old = elRef.value;
401
- elRef.value = creator();
402
- old.replaceWith(elRef.value);
401
+ elRef.value = creator(); // ref setter automatically calls replaceWith
403
402
  elRef.value.redraw = redraw;
404
403
  return elRef.value;
405
404
  };
@@ -240,7 +240,7 @@ var __ktjs_core__ = (function (exports) {
240
240
  * ## About
241
241
  * @package @ktjs/core
242
242
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
243
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
243
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
244
244
  * @license MIT
245
245
  * @link https://github.com/baendlorel/kt.js
246
246
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -301,9 +301,9 @@ var __ktjs_core__ = (function (exports) {
301
301
  * - can alse be used to store normal values, but it is not reactive.
302
302
  * @param value mostly an HTMLElement
303
303
  */
304
- function ref(value) {
304
+ function ref(value, onChange) {
305
305
  var _value = value;
306
- var _onChanges = [];
306
+ var _onChanges = onChange ? [onChange] : [];
307
307
  return {
308
308
  isKT: true,
309
309
  get value() {
@@ -351,9 +351,10 @@ var __ktjs_core__ = (function (exports) {
351
351
  var el;
352
352
  var redraw = function (newProps) {
353
353
  props = newProps ? __assign(__assign({}, props), newProps) : props;
354
- var old = el;
355
354
  el = jsx(tag, props);
356
- old.replaceWith(el);
355
+ if (ref !== dummyRef) {
356
+ ref.value = el; // ref setter automatically replaces old element in DOM
357
+ }
357
358
  return el;
358
359
  };
359
360
  if ('k-if' in props && !props['k-if']) {
@@ -377,7 +378,7 @@ var __ktjs_core__ = (function (exports) {
377
378
  * Fragment support - returns an array of children
378
379
  * Note: kt.js doesn't have a real Fragment concept,
379
380
  */
380
- function Fragment(props) {
381
+ function Fragment(_props) {
381
382
  throw new Error("kt.js doesn't have a Fragment concept");
382
383
  // const { children } = props ?? {};
383
384
  // if (!children) {
@@ -461,9 +462,7 @@ var __ktjs_core__ = (function (exports) {
461
462
  var elRef = ref();
462
463
  elRef.value = creator();
463
464
  var redraw = function () {
464
- var old = elRef.value;
465
- elRef.value = creator();
466
- old.replaceWith(elRef.value);
465
+ elRef.value = creator(); // ref setter automatically calls replaceWith
467
466
  elRef.value.redraw = redraw;
468
467
  return elRef.value;
469
468
  };
package/dist/index.mjs CHANGED
@@ -212,7 +212,7 @@ const svgTempWrapper = document.createElement('div');
212
212
  * ## About
213
213
  * @package @ktjs/core
214
214
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
215
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
215
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
216
216
  * @license MIT
217
217
  * @link https://github.com/baendlorel/kt.js
218
218
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -240,9 +240,9 @@ const h = (tag, attr, content) => {
240
240
  * - can alse be used to store normal values, but it is not reactive.
241
241
  * @param value mostly an HTMLElement
242
242
  */
243
- function ref(value) {
243
+ function ref(value, onChange) {
244
244
  let _value = value;
245
- let _onChanges = [];
245
+ let _onChanges = onChange ? [onChange] : [];
246
246
  return {
247
247
  isKT: true,
248
248
  get value() {
@@ -288,9 +288,10 @@ function jsx(tag, props = {}) {
288
288
  let el;
289
289
  const redraw = (newProps) => {
290
290
  props = newProps ? { ...props, ...newProps } : props;
291
- const old = el;
292
291
  el = jsx(tag, props);
293
- old.replaceWith(el);
292
+ if (ref !== dummyRef) {
293
+ ref.value = el; // ref setter automatically replaces old element in DOM
294
+ }
294
295
  return el;
295
296
  };
296
297
  if ('k-if' in props && !props['k-if']) {
@@ -314,7 +315,7 @@ function jsx(tag, props = {}) {
314
315
  * Fragment support - returns an array of children
315
316
  * Note: kt.js doesn't have a real Fragment concept,
316
317
  */
317
- function Fragment(props) {
318
+ function Fragment(_props) {
318
319
  throw new Error("kt.js doesn't have a Fragment concept");
319
320
  // const { children } = props ?? {};
320
321
  // if (!children) {
@@ -394,9 +395,7 @@ function createRedrawable(creator) {
394
395
  const elRef = ref();
395
396
  elRef.value = creator();
396
397
  const redraw = () => {
397
- const old = elRef.value;
398
- elRef.value = creator();
399
- old.replaceWith(elRef.value);
398
+ elRef.value = creator(); // ref setter automatically calls replaceWith
400
399
  elRef.value.redraw = redraw;
401
400
  return elRef.value;
402
401
  };
@@ -21,7 +21,7 @@ interface KTRef<T> {
21
21
  * - can alse be used to store normal values, but it is not reactive.
22
22
  * @param value mostly an HTMLElement
23
23
  */
24
- declare function ref<T = HTMLElement>(value?: T): KTRef<T>;
24
+ declare function ref<T = HTMLElement>(value?: T, onChange?: ChangeHandler<T>): KTRef<T>;
25
25
 
26
26
  type Redraw = (props?: KTAttribute, ...args: any[]) => KTHTMLElement;
27
27
  type KTHTMLElement<El extends HTMLElement = HTMLElement, R extends Function = Redraw> = El & {
@@ -164,7 +164,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
164
164
  * ## About
165
165
  * @package @ktjs/core
166
166
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
167
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
167
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
168
168
  * @license MIT
169
169
  * @link https://github.com/baendlorel/kt.js
170
170
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -183,7 +183,7 @@ declare function jsx(tag: JSXTag, props?: KTAttribute): KTHTMLElement;
183
183
  * Fragment support - returns an array of children
184
184
  * Note: kt.js doesn't have a real Fragment concept,
185
185
  */
186
- declare function Fragment(props: {
186
+ declare function Fragment(_props: {
187
187
  children?: KTRawContent;
188
188
  }): HTMLElement;
189
189
  /**
@@ -212,7 +212,7 @@ const svgTempWrapper = document.createElement('div');
212
212
  * ## About
213
213
  * @package @ktjs/core
214
214
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
215
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
215
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
216
216
  * @license MIT
217
217
  * @link https://github.com/baendlorel/kt.js
218
218
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -240,9 +240,9 @@ const h = (tag, attr, content) => {
240
240
  * - can alse be used to store normal values, but it is not reactive.
241
241
  * @param value mostly an HTMLElement
242
242
  */
243
- function ref(value) {
243
+ function ref(value, onChange) {
244
244
  let _value = value;
245
- let _onChanges = [];
245
+ let _onChanges = onChange ? [onChange] : [];
246
246
  return {
247
247
  isKT: true,
248
248
  get value() {
@@ -288,9 +288,10 @@ function jsx(tag, props = {}) {
288
288
  let el;
289
289
  const redraw = (newProps) => {
290
290
  props = newProps ? { ...props, ...newProps } : props;
291
- const old = el;
292
291
  el = jsx(tag, props);
293
- old.replaceWith(el);
292
+ if (ref !== dummyRef) {
293
+ ref.value = el; // ref setter automatically replaces old element in DOM
294
+ }
294
295
  return el;
295
296
  };
296
297
  if ('k-if' in props && !props['k-if']) {
@@ -314,7 +315,7 @@ function jsx(tag, props = {}) {
314
315
  * Fragment support - returns an array of children
315
316
  * Note: kt.js doesn't have a real Fragment concept,
316
317
  */
317
- function Fragment(props) {
318
+ function Fragment(_props) {
318
319
  throw new Error("kt.js doesn't have a Fragment concept");
319
320
  // const { children } = props ?? {};
320
321
  // if (!children) {
@@ -394,9 +395,7 @@ function createRedrawable(creator) {
394
395
  const elRef = ref();
395
396
  elRef.value = creator();
396
397
  const redraw = () => {
397
- const old = elRef.value;
398
- elRef.value = creator();
399
- old.replaceWith(elRef.value);
398
+ elRef.value = creator(); // ref setter automatically calls replaceWith
400
399
  elRef.value.redraw = redraw;
401
400
  return elRef.value;
402
401
  };
@@ -158,7 +158,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
158
158
  * ## About
159
159
  * @package @ktjs/core
160
160
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
161
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
161
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
162
162
  * @license MIT
163
163
  * @link https://github.com/baendlorel/kt.js
164
164
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -177,7 +177,7 @@ declare function jsx(tag: JSXTag, props?: KTAttribute): KTHTMLElement;
177
177
  * Fragment support - returns an array of children
178
178
  * Note: kt.js doesn't have a real Fragment concept,
179
179
  */
180
- declare function Fragment(props: {
180
+ declare function Fragment(_props: {
181
181
  children?: KTRawContent;
182
182
  }): HTMLElement;
183
183
  /**
@@ -212,7 +212,7 @@ const svgTempWrapper = document.createElement('div');
212
212
  * ## About
213
213
  * @package @ktjs/core
214
214
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
215
- * @version 0.18.1 (Last Update: 2026.01.30 21:24:36.481)
215
+ * @version 0.18.3 (Last Update: 2026.01.30 23:10:27.447)
216
216
  * @license MIT
217
217
  * @link https://github.com/baendlorel/kt.js
218
218
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -240,7 +240,7 @@ const h = (tag, attr, content) => {
240
240
  * - can alse be used to store normal values, but it is not reactive.
241
241
  * @param value mostly an HTMLElement
242
242
  */
243
- function ref(value) {
243
+ function ref(value, onChange) {
244
244
  let _value = value;
245
245
  let _onChanges = [];
246
246
  return {
@@ -288,9 +288,10 @@ function jsx(tag, props = {}) {
288
288
  let el;
289
289
  const redraw = (newProps) => {
290
290
  props = newProps ? { ...props, ...newProps } : props;
291
- const old = el;
292
291
  el = jsx(tag, props);
293
- old.replaceWith(el);
292
+ if (ref !== dummyRef) {
293
+ ref.value = el; // ref setter automatically replaces old element in DOM
294
+ }
294
295
  return el;
295
296
  };
296
297
  if ('k-if' in props && !props['k-if']) {
@@ -314,7 +315,7 @@ function jsx(tag, props = {}) {
314
315
  * Fragment support - returns an array of children
315
316
  * Note: kt.js doesn't have a real Fragment concept,
316
317
  */
317
- function Fragment(props) {
318
+ function Fragment(_props) {
318
319
  throw new Error("kt.js doesn't have a Fragment concept");
319
320
  // const { children } = props ?? {};
320
321
  // if (!children) {
@@ -394,9 +395,7 @@ function createRedrawable(creator) {
394
395
  const elRef = ref();
395
396
  elRef.value = creator();
396
397
  const redraw = () => {
397
- const old = elRef.value;
398
- elRef.value = creator();
399
- old.replaceWith(elRef.value);
398
+ elRef.value = creator(); // ref setter automatically calls replaceWith
400
399
  elRef.value.redraw = redraw;
401
400
  return elRef.value;
402
401
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.18.1",
3
+ "version": "0.18.3",
4
4
  "description": "Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",