@ktjs/core 0.29.8 → 0.29.9
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 +428 -10
- package/dist/jsx-runtime.d.ts +245 -0
- package/dist/jsx-runtime.mjs +1 -0
- package/package.json +7 -7
- package/dist/h/attr-helpers.d.ts +0 -6
- package/dist/h/attr.d.ts +0 -2
- package/dist/h/content.d.ts +0 -2
- package/dist/h/index.d.ts +0 -12
- package/dist/h/model.d.ts +0 -3
- package/dist/jsx/async.d.ts +0 -13
- package/dist/jsx/common.d.ts +0 -4
- package/dist/jsx/for.d.ts +0 -14
- package/dist/jsx/fragment.d.ts +0 -35
- package/dist/jsx/if.d.ts +0 -10
- package/dist/jsx/index.d.ts +0 -2
- package/dist/jsx/index.mjs +0 -1
- package/dist/jsx/jsx-runtime.d.ts +0 -43
- package/dist/jsx/jsx-runtime.mjs +0 -2
- package/dist/reactive/computed.d.ts +0 -63
- package/dist/reactive/core.d.ts +0 -9
- package/dist/reactive/effect.d.ts +0 -15
- package/dist/reactive/index.d.ts +0 -10
- package/dist/reactive/ref.d.ts +0 -89
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,428 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { HTMLTag } from '@ktjs/shared';
|
|
2
|
+
import { InputElementTag } from '@ktjs/shared';
|
|
3
|
+
import { JSXTag } from '@ktjs/shared';
|
|
4
|
+
import { MathMLTag } from '@ktjs/shared';
|
|
5
|
+
import { otherstring } from '@ktjs/shared';
|
|
6
|
+
import { SVGTag } from '@ktjs/shared';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Whether `props.ref` is a `KTRef` only needs to be checked in the initial render
|
|
10
|
+
*/
|
|
11
|
+
export declare const $initRef: <T extends Node>(props: {
|
|
12
|
+
ref?: KTRef<T>;
|
|
13
|
+
}, node: T) => RefSetter<T>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Assert k-model to be a ref object
|
|
17
|
+
*/
|
|
18
|
+
export declare const $modelOrRef: <T = any>(props: any, defaultValue?: T) => KTRef<T>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a reactive computed value
|
|
22
|
+
* @param computeFn
|
|
23
|
+
* @param reactives refs and computeds that this computed depends on
|
|
24
|
+
*/
|
|
25
|
+
export declare function computed<T = JSX.Element>(computeFn: () => T, reactives: Array<KTReactive<any>>): KTComputed<T>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A helper to create redrawable elements
|
|
29
|
+
* ```tsx
|
|
30
|
+
* export function MyComponent() {
|
|
31
|
+
* let aa = 10;
|
|
32
|
+
* // ...
|
|
33
|
+
* // aa might be changed
|
|
34
|
+
* return createRedrawable(() => <div>{aa}</div>);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
* Then the returned element has a `redraw` method to redraw itself with new values.
|
|
38
|
+
* @param creator a simple creator function that returns an element
|
|
39
|
+
* @returns created element's ref
|
|
40
|
+
*/
|
|
41
|
+
export declare function createRedrawable<T>(creator: () => T): KTRef<T> & {
|
|
42
|
+
redraw: () => T;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Extracts the value from a KTReactive, or returns the value directly if it's not reactive.
|
|
47
|
+
*/
|
|
48
|
+
export declare function dereactive<T = JSX.Element>(value: T | KTReactive<T>): T;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Register a reactive effect with options.
|
|
52
|
+
* @param effectFn The effect function to run when dependencies change
|
|
53
|
+
* @param reactives The reactive dependencies
|
|
54
|
+
* @param options Effect options: lazy, onCleanup, debugName
|
|
55
|
+
* @returns stop function to remove all listeners
|
|
56
|
+
*/
|
|
57
|
+
export declare function effect(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>): () => void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Event handler type for DOM events
|
|
61
|
+
*/
|
|
62
|
+
export declare type EventHandler<T extends Event = Event> = (this: HTMLElement, ev: T) => any;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Extract component props type (excluding ref and children)
|
|
66
|
+
*/
|
|
67
|
+
declare type ExtractComponentProps<T> = T extends (props: infer P) => any ? Omit<P, 'ref' | 'children'> : {};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Fragment support - returns an array of children
|
|
71
|
+
* Enhanced Fragment component that manages arrays of elements
|
|
72
|
+
*/
|
|
73
|
+
export declare function Fragment(props: {
|
|
74
|
+
children?: KTRawContent;
|
|
75
|
+
}): JSX.Element;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create an enhanced HTMLElement.
|
|
79
|
+
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
80
|
+
* @param tag tag of an `HTMLElement`
|
|
81
|
+
* @param attr attribute object or className
|
|
82
|
+
* @param content a string or an array of HTMLEnhancedElement as child nodes
|
|
83
|
+
*
|
|
84
|
+
* __PKG_INFO__
|
|
85
|
+
*/
|
|
86
|
+
declare const h: <T extends HTMLTag | SVGTag | MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>;
|
|
87
|
+
export { h as createElement }
|
|
88
|
+
export { h }
|
|
89
|
+
|
|
90
|
+
declare type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
|
|
91
|
+
? SVGElementTagNameMap[T]
|
|
92
|
+
: T extends HTMLTag
|
|
93
|
+
? HTMLElementTagNameMap[T]
|
|
94
|
+
: T extends MathMLTag
|
|
95
|
+
? MathMLElementTagNameMap[T]
|
|
96
|
+
: HTMLElement;
|
|
97
|
+
|
|
98
|
+
export { HTMLTag }
|
|
99
|
+
|
|
100
|
+
export { InputElementTag }
|
|
101
|
+
|
|
102
|
+
export declare const isComputed: <T = any>(obj: any) => obj is KTComputed<T>;
|
|
103
|
+
|
|
104
|
+
export declare const isKT: <T = any>(obj: any) => obj is KTReactive<T>;
|
|
105
|
+
|
|
106
|
+
export declare const isRef: <T = any>(obj: any) => obj is KTRef<T>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param tag html tag or function component
|
|
110
|
+
* @param props properties/attributes
|
|
111
|
+
*/
|
|
112
|
+
export declare function jsx(tag: JSXTag, props: KTAttribute): JSX.Element;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* JSX Development runtime - same as jsx but with additional dev checks
|
|
116
|
+
*/
|
|
117
|
+
export declare const jsxDEV: typeof jsx;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* JSX runtime for React 17+ automatic runtime
|
|
121
|
+
* This is called when using jsx: "react-jsx" or "react-jsxdev"
|
|
122
|
+
*/
|
|
123
|
+
export declare const jsxs: typeof jsx;
|
|
124
|
+
|
|
125
|
+
export declare function KTAsync<T extends KTComponent>(props: {
|
|
126
|
+
ref?: KTRef<JSX.Element>;
|
|
127
|
+
skeleton?: JSX.Element;
|
|
128
|
+
component: T;
|
|
129
|
+
children?: KTRawContent;
|
|
130
|
+
} & ExtractComponentProps<T>): JSX.Element;
|
|
131
|
+
|
|
132
|
+
export declare type KTAttribute = KTBaseAttribute & KTPrefixedEventAttribute;
|
|
133
|
+
|
|
134
|
+
declare type KTAvailableContent = SingleContent | KTAvailableContent[];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Used to create enhanced HTML elements
|
|
138
|
+
*/
|
|
139
|
+
declare interface KTBaseAttribute {
|
|
140
|
+
[k: string]: any;
|
|
141
|
+
|
|
142
|
+
// # kt-specific attributes
|
|
143
|
+
ref?: KTRef<JSX.Element>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* If a `KTRef` is bound, it will be reactive; otherwise, it will be static.
|
|
147
|
+
*/
|
|
148
|
+
'k-if'?: any;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Register two-way data binding between an input element and a KTRef.
|
|
152
|
+
* - Default to regist `input` event and `value` property(`checked` for checkboxes and radios).
|
|
153
|
+
*/
|
|
154
|
+
'k-model'?: KTRef<any>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Directly apply html string to `innerHTML`.
|
|
158
|
+
* - Would be reactive if `KTRef` instance is provided
|
|
159
|
+
*/
|
|
160
|
+
'k-html'?: any;
|
|
161
|
+
|
|
162
|
+
// # normal HTML attributes
|
|
163
|
+
id?: string;
|
|
164
|
+
class?: string;
|
|
165
|
+
className?: string;
|
|
166
|
+
style?: string | Partial<CSSStyleDeclaration>;
|
|
167
|
+
|
|
168
|
+
type?:
|
|
169
|
+
| 'text'
|
|
170
|
+
| 'password'
|
|
171
|
+
| 'email'
|
|
172
|
+
| 'number'
|
|
173
|
+
| 'tel'
|
|
174
|
+
| 'url'
|
|
175
|
+
| 'search'
|
|
176
|
+
| 'date'
|
|
177
|
+
| 'datetime-local'
|
|
178
|
+
| 'time'
|
|
179
|
+
| 'month'
|
|
180
|
+
| 'week'
|
|
181
|
+
| 'color'
|
|
182
|
+
| 'range'
|
|
183
|
+
| 'file'
|
|
184
|
+
| 'checkbox'
|
|
185
|
+
| 'radio'
|
|
186
|
+
| 'hidden'
|
|
187
|
+
| 'submit'
|
|
188
|
+
| 'reset'
|
|
189
|
+
| 'button'
|
|
190
|
+
| 'image'
|
|
191
|
+
| otherstring;
|
|
192
|
+
for?: string;
|
|
193
|
+
|
|
194
|
+
name?: string;
|
|
195
|
+
title?: string;
|
|
196
|
+
placeholder?: string;
|
|
197
|
+
contenteditable?: boolean;
|
|
198
|
+
value?: any;
|
|
199
|
+
valueAsDate?: Date;
|
|
200
|
+
valueAsNumber?: number;
|
|
201
|
+
label?: string;
|
|
202
|
+
disabled?: boolean;
|
|
203
|
+
|
|
204
|
+
min?: string | number;
|
|
205
|
+
max?: string | number;
|
|
206
|
+
step?: string | number;
|
|
207
|
+
|
|
208
|
+
selected?: boolean;
|
|
209
|
+
checked?: boolean;
|
|
210
|
+
|
|
211
|
+
action?: string;
|
|
212
|
+
method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
declare type KTComponent = (
|
|
216
|
+
props: {
|
|
217
|
+
ref?: KTRef<JSX.Element>;
|
|
218
|
+
children?: KTRawContent;
|
|
219
|
+
} & KTAttribute &
|
|
220
|
+
any,
|
|
221
|
+
) => JSX.Element | Promise<JSX.Element> | any;
|
|
222
|
+
|
|
223
|
+
export declare class KTComputed<T> implements KTReactive<T> {
|
|
224
|
+
/**
|
|
225
|
+
* Indicates that this is a KTRef instance
|
|
226
|
+
*/
|
|
227
|
+
isKT: true;
|
|
228
|
+
ktType: KTReactiveType;
|
|
229
|
+
/* Excluded from this release type: _calculator */
|
|
230
|
+
/* Excluded from this release type: _value */
|
|
231
|
+
/* Excluded from this release type: _onChanges */
|
|
232
|
+
/* Excluded from this release type: _emit */
|
|
233
|
+
/* Excluded from this release type: _recalculate */
|
|
234
|
+
/* Excluded from this release type: _subscribe */
|
|
235
|
+
constructor(_calculator: () => T, reactives: Array<KTReactive<unknown>>);
|
|
236
|
+
/**
|
|
237
|
+
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
238
|
+
*/
|
|
239
|
+
get value(): T;
|
|
240
|
+
set value(_newValue: T);
|
|
241
|
+
/**
|
|
242
|
+
* Force listeners to run once with the latest computed result.
|
|
243
|
+
*/
|
|
244
|
+
notify(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Computed values are derived from dependencies and should not be mutated manually.
|
|
247
|
+
*/
|
|
248
|
+
mutate<R = void>(): R;
|
|
249
|
+
/**
|
|
250
|
+
* Register a callback when the value changes
|
|
251
|
+
* @param callback (newValue, oldValue) => xxx
|
|
252
|
+
*/
|
|
253
|
+
addOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
254
|
+
/**
|
|
255
|
+
* Unregister a callback
|
|
256
|
+
* @param callback (newValue, oldValue) => xxx
|
|
257
|
+
*/
|
|
258
|
+
removeOnChange(callback: ReactiveChangeHandler<T>): boolean;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
declare interface KTEffectOptions {
|
|
262
|
+
lazy: boolean;
|
|
263
|
+
onCleanup: () => void;
|
|
264
|
+
debugName: string;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* KTFor - List rendering component with key-based optimization
|
|
269
|
+
* Returns a Comment anchor node with rendered elements in __kt_for_list__
|
|
270
|
+
*/
|
|
271
|
+
export declare function KTFor<T>(props: KTForProps<T>): KTForElement;
|
|
272
|
+
|
|
273
|
+
export declare type KTForElement = JSX.Element;
|
|
274
|
+
|
|
275
|
+
export declare interface KTForProps<T> {
|
|
276
|
+
ref?: KTRef<KTForElement>;
|
|
277
|
+
list: T[] | KTReactive<T[]>;
|
|
278
|
+
key?: (item: T, index: number, array: T[]) => any;
|
|
279
|
+
map: (item: T, index: number, array: T[]) => HTMLElement;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export declare type KTPrefixedEventAttribute = {
|
|
283
|
+
[EventName in keyof HTMLElementEventMap as `on:${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export declare type KTRawAttr = KTAttribute | null | undefined | '' | false;
|
|
287
|
+
|
|
288
|
+
export declare type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
|
|
289
|
+
|
|
290
|
+
export declare type KTRawContents = KTAvailableContent;
|
|
291
|
+
|
|
292
|
+
export declare type KTReactify<T> = T extends boolean ? KTReactive<boolean> : T extends any ? KTReactive<T> : never;
|
|
293
|
+
|
|
294
|
+
export declare type KTReactifyObject<T extends object> = {
|
|
295
|
+
[K in keyof T]: KTReactify<T[K]>;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export declare type KTReactifyProps<T extends object> = {
|
|
299
|
+
[K in keyof T]: KTReactify<Exclude<T[K], undefined>> | T[K];
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export declare class KTReactive<T> {
|
|
303
|
+
/**
|
|
304
|
+
* Indicates that this is a KTRef instance
|
|
305
|
+
*/
|
|
306
|
+
isKT: boolean;
|
|
307
|
+
|
|
308
|
+
ktType: KTReactiveType;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
312
|
+
*/
|
|
313
|
+
get value();
|
|
314
|
+
set value(newValue: T);
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Force all listeners to run even when reference identity has not changed.
|
|
318
|
+
* Useful for in-place array/object mutations.
|
|
319
|
+
*/
|
|
320
|
+
notify(): void;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Mutate current value in-place and notify listeners once.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* const items = ref<number[]>([1, 2]);
|
|
327
|
+
* items.mutate((list) => list.push(3));
|
|
328
|
+
*/
|
|
329
|
+
mutate<R = void>(mutator: (currentValue: T) => R): R;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Register a callback when the value changes
|
|
333
|
+
* - Value setter will check `Object.is(newValue, oldValue)`.
|
|
334
|
+
* @param callback (newValue, oldValue) => xxx
|
|
335
|
+
*/
|
|
336
|
+
addOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
337
|
+
removeOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export declare const enum KTReactiveType {
|
|
341
|
+
REF = 1,
|
|
342
|
+
COMPUTED = 2
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export declare class KTRef<T> implements KTReactive<T> {
|
|
346
|
+
/**
|
|
347
|
+
* Indicates that this is a KTRef instance
|
|
348
|
+
*/
|
|
349
|
+
isKT: true;
|
|
350
|
+
ktType: KTReactiveType;
|
|
351
|
+
/* Excluded from this release type: _value */
|
|
352
|
+
/* Excluded from this release type: _onChanges */
|
|
353
|
+
/* Excluded from this release type: _emit */
|
|
354
|
+
constructor(_value: T, _onChanges: Array<ReactiveChangeHandler<T>>);
|
|
355
|
+
/**
|
|
356
|
+
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
357
|
+
*/
|
|
358
|
+
get value(): T;
|
|
359
|
+
set value(newValue: T);
|
|
360
|
+
/**
|
|
361
|
+
* Force all listeners to run even when reference identity has not changed.
|
|
362
|
+
* Useful for in-place array/object mutations.
|
|
363
|
+
*/
|
|
364
|
+
notify(): void;
|
|
365
|
+
/**
|
|
366
|
+
* Mutate current value in-place and notify listeners once.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* const items = ref<number[]>([1, 2]);
|
|
370
|
+
* items.mutate((list) => list.push(3));
|
|
371
|
+
*/
|
|
372
|
+
mutate<R = void>(mutator: (currentValue: T) => R): R;
|
|
373
|
+
/**
|
|
374
|
+
* Register a callback when the value changes
|
|
375
|
+
* @param callback (newValue, oldValue) => xxx
|
|
376
|
+
*/
|
|
377
|
+
addOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
378
|
+
removeOnChange(callback: ReactiveChangeHandler<T>): boolean;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export declare type KTSurfaceRef<T extends object> = {
|
|
382
|
+
[K in keyof T]: KTRef<T[K]>;
|
|
383
|
+
} & {
|
|
384
|
+
/**
|
|
385
|
+
* Get the dereferenced object like the original one
|
|
386
|
+
*/
|
|
387
|
+
kcollect: () => T;
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
export { MathMLTag }
|
|
391
|
+
|
|
392
|
+
export declare type ReactiveChangeHandler<T> = (newValue: T, oldValue: T) => void;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Reference to the created HTML element.
|
|
396
|
+
* - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
|
|
397
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
398
|
+
* - if the value is already a `KTRef`, it will be returned **directly**.
|
|
399
|
+
* @param value mostly an HTMLElement
|
|
400
|
+
*/
|
|
401
|
+
export declare function ref<T = JSX.Element>(value?: T, onChange?: ReactiveChangeHandler<T>): KTRef<T>;
|
|
402
|
+
|
|
403
|
+
declare type RefSetter<T> = (props: {
|
|
404
|
+
ref?: KTRef<T>;
|
|
405
|
+
}, node: T) => void;
|
|
406
|
+
|
|
407
|
+
declare type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Make all first-level properties of the object a `KTRef`.
|
|
411
|
+
* - `obj.a.b` is not reactive
|
|
412
|
+
*/
|
|
413
|
+
export declare const surfaceRef: <T extends object>(obj: T) => KTSurfaceRef<T>;
|
|
414
|
+
|
|
415
|
+
export { SVGTag }
|
|
416
|
+
|
|
417
|
+
export declare const toReactive: <T>(value: T | KTReactive<T>, onChange?: ReactiveChangeHandler<T>) => KTReactive<T>;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Convert a value to `KTRef`.
|
|
421
|
+
* - Returns the original value if it is already a `KTRef`.
|
|
422
|
+
* - Throws error if the value is a `KTComputed`.
|
|
423
|
+
* - Otherwise wraps the value with `ref()`.
|
|
424
|
+
* @param o value to convert
|
|
425
|
+
*/
|
|
426
|
+
export declare const toRef: <T = any>(o: any) => KTRef<T>;
|
|
427
|
+
|
|
428
|
+
export { }
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { HTMLTag } from '@ktjs/shared';
|
|
2
|
+
import { JSXTag } from '@ktjs/shared';
|
|
3
|
+
import { MathMLTag } from '@ktjs/shared';
|
|
4
|
+
import { otherstring } from '@ktjs/shared';
|
|
5
|
+
import { SVGTag } from '@ktjs/shared';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A helper to create redrawable elements
|
|
9
|
+
* ```tsx
|
|
10
|
+
* export function MyComponent() {
|
|
11
|
+
* let aa = 10;
|
|
12
|
+
* // ...
|
|
13
|
+
* // aa might be changed
|
|
14
|
+
* return createRedrawable(() => <div>{aa}</div>);
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
* Then the returned element has a `redraw` method to redraw itself with new values.
|
|
18
|
+
* @param creator a simple creator function that returns an element
|
|
19
|
+
* @returns created element's ref
|
|
20
|
+
*/
|
|
21
|
+
export declare function createRedrawable<T>(creator: () => T): KTRef<T> & {
|
|
22
|
+
redraw: () => T;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Fragment support - returns an array of children
|
|
27
|
+
* Enhanced Fragment component that manages arrays of elements
|
|
28
|
+
*/
|
|
29
|
+
export declare function Fragment(props: {
|
|
30
|
+
children?: KTRawContent;
|
|
31
|
+
}): JSX.Element;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create an enhanced HTMLElement.
|
|
35
|
+
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
36
|
+
* @param tag tag of an `HTMLElement`
|
|
37
|
+
* @param attr attribute object or className
|
|
38
|
+
* @param content a string or an array of HTMLEnhancedElement as child nodes
|
|
39
|
+
*
|
|
40
|
+
* __PKG_INFO__
|
|
41
|
+
*/
|
|
42
|
+
declare const h: <T extends HTMLTag | SVGTag | MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>;
|
|
43
|
+
export { h as createElement }
|
|
44
|
+
export { h }
|
|
45
|
+
|
|
46
|
+
declare type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
|
|
47
|
+
? SVGElementTagNameMap[T]
|
|
48
|
+
: T extends HTMLTag
|
|
49
|
+
? HTMLElementTagNameMap[T]
|
|
50
|
+
: T extends MathMLTag
|
|
51
|
+
? MathMLElementTagNameMap[T]
|
|
52
|
+
: HTMLElement;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param tag html tag or function component
|
|
56
|
+
* @param props properties/attributes
|
|
57
|
+
*/
|
|
58
|
+
export declare function jsx(tag: JSXTag, props: KTAttribute): JSX.Element;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* JSX Development runtime - same as jsx but with additional dev checks
|
|
62
|
+
*/
|
|
63
|
+
export declare const jsxDEV: typeof jsx;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* JSX runtime for React 17+ automatic runtime
|
|
67
|
+
* This is called when using jsx: "react-jsx" or "react-jsxdev"
|
|
68
|
+
*/
|
|
69
|
+
export declare const jsxs: typeof jsx;
|
|
70
|
+
|
|
71
|
+
declare type KTAttribute = KTBaseAttribute & KTPrefixedEventAttribute;
|
|
72
|
+
|
|
73
|
+
declare type KTAvailableContent = SingleContent | KTAvailableContent[];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Used to create enhanced HTML elements
|
|
77
|
+
*/
|
|
78
|
+
declare interface KTBaseAttribute {
|
|
79
|
+
[k: string]: any;
|
|
80
|
+
|
|
81
|
+
// # kt-specific attributes
|
|
82
|
+
ref?: KTRef<JSX.Element>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* If a `KTRef` is bound, it will be reactive; otherwise, it will be static.
|
|
86
|
+
*/
|
|
87
|
+
'k-if'?: any;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Register two-way data binding between an input element and a KTRef.
|
|
91
|
+
* - Default to regist `input` event and `value` property(`checked` for checkboxes and radios).
|
|
92
|
+
*/
|
|
93
|
+
'k-model'?: KTRef<any>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Directly apply html string to `innerHTML`.
|
|
97
|
+
* - Would be reactive if `KTRef` instance is provided
|
|
98
|
+
*/
|
|
99
|
+
'k-html'?: any;
|
|
100
|
+
|
|
101
|
+
// # normal HTML attributes
|
|
102
|
+
id?: string;
|
|
103
|
+
class?: string;
|
|
104
|
+
className?: string;
|
|
105
|
+
style?: string | Partial<CSSStyleDeclaration>;
|
|
106
|
+
|
|
107
|
+
type?:
|
|
108
|
+
| 'text'
|
|
109
|
+
| 'password'
|
|
110
|
+
| 'email'
|
|
111
|
+
| 'number'
|
|
112
|
+
| 'tel'
|
|
113
|
+
| 'url'
|
|
114
|
+
| 'search'
|
|
115
|
+
| 'date'
|
|
116
|
+
| 'datetime-local'
|
|
117
|
+
| 'time'
|
|
118
|
+
| 'month'
|
|
119
|
+
| 'week'
|
|
120
|
+
| 'color'
|
|
121
|
+
| 'range'
|
|
122
|
+
| 'file'
|
|
123
|
+
| 'checkbox'
|
|
124
|
+
| 'radio'
|
|
125
|
+
| 'hidden'
|
|
126
|
+
| 'submit'
|
|
127
|
+
| 'reset'
|
|
128
|
+
| 'button'
|
|
129
|
+
| 'image'
|
|
130
|
+
| otherstring;
|
|
131
|
+
for?: string;
|
|
132
|
+
|
|
133
|
+
name?: string;
|
|
134
|
+
title?: string;
|
|
135
|
+
placeholder?: string;
|
|
136
|
+
contenteditable?: boolean;
|
|
137
|
+
value?: any;
|
|
138
|
+
valueAsDate?: Date;
|
|
139
|
+
valueAsNumber?: number;
|
|
140
|
+
label?: string;
|
|
141
|
+
disabled?: boolean;
|
|
142
|
+
|
|
143
|
+
min?: string | number;
|
|
144
|
+
max?: string | number;
|
|
145
|
+
step?: string | number;
|
|
146
|
+
|
|
147
|
+
selected?: boolean;
|
|
148
|
+
checked?: boolean;
|
|
149
|
+
|
|
150
|
+
action?: string;
|
|
151
|
+
method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare type KTPrefixedEventAttribute = {
|
|
155
|
+
[EventName in keyof HTMLElementEventMap as `on:${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
declare type KTRawAttr = KTAttribute | null | undefined | '' | false;
|
|
159
|
+
|
|
160
|
+
declare type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
|
|
161
|
+
|
|
162
|
+
declare class KTReactive<T> {
|
|
163
|
+
/**
|
|
164
|
+
* Indicates that this is a KTRef instance
|
|
165
|
+
*/
|
|
166
|
+
isKT: boolean;
|
|
167
|
+
|
|
168
|
+
ktType: KTReactiveType;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
172
|
+
*/
|
|
173
|
+
get value();
|
|
174
|
+
set value(newValue: T);
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Force all listeners to run even when reference identity has not changed.
|
|
178
|
+
* Useful for in-place array/object mutations.
|
|
179
|
+
*/
|
|
180
|
+
notify(): void;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Mutate current value in-place and notify listeners once.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* const items = ref<number[]>([1, 2]);
|
|
187
|
+
* items.mutate((list) => list.push(3));
|
|
188
|
+
*/
|
|
189
|
+
mutate<R = void>(mutator: (currentValue: T) => R): R;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Register a callback when the value changes
|
|
193
|
+
* - Value setter will check `Object.is(newValue, oldValue)`.
|
|
194
|
+
* @param callback (newValue, oldValue) => xxx
|
|
195
|
+
*/
|
|
196
|
+
addOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
197
|
+
removeOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare const enum KTReactiveType {
|
|
201
|
+
REF = 1,
|
|
202
|
+
COMPUTED = 2
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
declare class KTRef<T> implements KTReactive<T> {
|
|
206
|
+
/**
|
|
207
|
+
* Indicates that this is a KTRef instance
|
|
208
|
+
*/
|
|
209
|
+
isKT: true;
|
|
210
|
+
ktType: KTReactiveType;
|
|
211
|
+
/* Excluded from this release type: _value */
|
|
212
|
+
/* Excluded from this release type: _onChanges */
|
|
213
|
+
/* Excluded from this release type: _emit */
|
|
214
|
+
constructor(_value: T, _onChanges: Array<ReactiveChangeHandler<T>>);
|
|
215
|
+
/**
|
|
216
|
+
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
217
|
+
*/
|
|
218
|
+
get value(): T;
|
|
219
|
+
set value(newValue: T);
|
|
220
|
+
/**
|
|
221
|
+
* Force all listeners to run even when reference identity has not changed.
|
|
222
|
+
* Useful for in-place array/object mutations.
|
|
223
|
+
*/
|
|
224
|
+
notify(): void;
|
|
225
|
+
/**
|
|
226
|
+
* Mutate current value in-place and notify listeners once.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* const items = ref<number[]>([1, 2]);
|
|
230
|
+
* items.mutate((list) => list.push(3));
|
|
231
|
+
*/
|
|
232
|
+
mutate<R = void>(mutator: (currentValue: T) => R): R;
|
|
233
|
+
/**
|
|
234
|
+
* Register a callback when the value changes
|
|
235
|
+
* @param callback (newValue, oldValue) => xxx
|
|
236
|
+
*/
|
|
237
|
+
addOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
238
|
+
removeOnChange(callback: ReactiveChangeHandler<T>): boolean;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare type ReactiveChangeHandler<T> = (newValue: T, oldValue: T) => void;
|
|
242
|
+
|
|
243
|
+
declare type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
|
|
244
|
+
|
|
245
|
+
export { }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { F as Fragment, h as createElement, c as createRedrawable, h, j as jsx, a as jsxDEV, b as jsxs } from './jsx-runtime-DGJHUQEM.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ktjs/core",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.9",
|
|
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",
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"default": "./dist/index.mjs"
|
|
13
13
|
},
|
|
14
14
|
"./jsx": {
|
|
15
|
-
"types": "./dist/
|
|
16
|
-
"import": "./dist/
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.mjs"
|
|
17
17
|
},
|
|
18
18
|
"./jsx-runtime": {
|
|
19
|
-
"types": "./dist/jsx
|
|
20
|
-
"import": "./dist/jsx
|
|
19
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
20
|
+
"import": "./dist/jsx-runtime.mjs"
|
|
21
21
|
},
|
|
22
22
|
"./jsx-dev-runtime": {
|
|
23
|
-
"types": "./dist/jsx
|
|
24
|
-
"import": "./dist/jsx
|
|
23
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
24
|
+
"import": "./dist/jsx-runtime.mjs"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
package/dist/h/attr-helpers.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const handlers: Record<string, (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => void>;
|
|
2
|
-
type InputElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
3
|
-
type StringEventHandler = (element: InputElement, handler: (value: string) => void) => void;
|
|
4
|
-
type NumberEventHandler = (element: InputElement, handler: (value: number) => void) => void;
|
|
5
|
-
export declare const ktEventHandlers: Record<string, StringEventHandler | NumberEventHandler>;
|
|
6
|
-
export {};
|
package/dist/h/attr.d.ts
DELETED
package/dist/h/content.d.ts
DELETED
package/dist/h/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { HTMLTag, MathMLTag, SVGTag } from '@ktjs/shared';
|
|
2
|
-
import { KTRawAttr, KTRawContent, HTML } from '../types/h.js';
|
|
3
|
-
/**
|
|
4
|
-
* Create an enhanced HTMLElement.
|
|
5
|
-
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
6
|
-
* @param tag tag of an `HTMLElement`
|
|
7
|
-
* @param attr attribute object or className
|
|
8
|
-
* @param content a string or an array of HTMLEnhancedElement as child nodes
|
|
9
|
-
*
|
|
10
|
-
* __PKG_INFO__
|
|
11
|
-
*/
|
|
12
|
-
export declare const h: <T extends HTMLTag | SVGTag | MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>;
|
package/dist/h/model.d.ts
DELETED
package/dist/jsx/async.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { KTComponent, KTRawContent } from '../types/h.js';
|
|
2
|
-
import { KTRef } from '../reactive/ref.js';
|
|
3
|
-
/**
|
|
4
|
-
* Extract component props type (excluding ref and children)
|
|
5
|
-
*/
|
|
6
|
-
type ExtractComponentProps<T> = T extends (props: infer P) => any ? Omit<P, 'ref' | 'children'> : {};
|
|
7
|
-
export declare function KTAsync<T extends KTComponent>(props: {
|
|
8
|
-
ref?: KTRef<JSX.Element>;
|
|
9
|
-
skeleton?: JSX.Element;
|
|
10
|
-
component: T;
|
|
11
|
-
children?: KTRawContent;
|
|
12
|
-
} & ExtractComponentProps<T>): JSX.Element;
|
|
13
|
-
export {};
|
package/dist/jsx/common.d.ts
DELETED
package/dist/jsx/for.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { KTRef } from '../reactive/ref.js';
|
|
2
|
-
import { KTReactive } from '../types/reactive.js';
|
|
3
|
-
export type KTForElement = JSX.Element;
|
|
4
|
-
export interface KTForProps<T> {
|
|
5
|
-
ref?: KTRef<KTForElement>;
|
|
6
|
-
list: T[] | KTReactive<T[]>;
|
|
7
|
-
key?: (item: T, index: number, array: T[]) => any;
|
|
8
|
-
map: (item: T, index: number, array: T[]) => HTMLElement;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* KTFor - List rendering component with key-based optimization
|
|
12
|
-
* Returns a Comment anchor node with rendered elements in __kt_for_list__
|
|
13
|
-
*/
|
|
14
|
-
export declare function KTFor<T>(props: KTForProps<T>): KTForElement;
|
package/dist/jsx/fragment.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { KTRef } from '../reactive/ref.js';
|
|
2
|
-
import { KTReactive } from '../types/reactive.js';
|
|
3
|
-
import { KTRawContent } from '../types/h.js';
|
|
4
|
-
export interface FragmentProps<T extends HTMLElement = HTMLElement> {
|
|
5
|
-
/** Array of child elements, supports reactive arrays */
|
|
6
|
-
children: T[] | KTReactive<T[]>;
|
|
7
|
-
/** element key function for optimization (future enhancement) */
|
|
8
|
-
key?: (element: T, index: number, array: T[]) => any;
|
|
9
|
-
/** ref to get the anchor node */
|
|
10
|
-
ref?: KTRef<JSX.Element>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Fragment - Container component for managing arrays of child elements
|
|
14
|
-
*
|
|
15
|
-
* Features:
|
|
16
|
-
* 1. Returns a comment anchor node, child elements are inserted after the anchor
|
|
17
|
-
* 2. Supports reactive arrays, automatically updates DOM when array changes
|
|
18
|
-
* 3. Basic version uses simple replacement algorithm (remove all old elements, insert all new elements)
|
|
19
|
-
* 4. Future enhancement: key-based optimization
|
|
20
|
-
*
|
|
21
|
-
* Usage example:
|
|
22
|
-
* ```tsx
|
|
23
|
-
* const children = ref([<div>A</div>, <div>B</div>]);
|
|
24
|
-
* const fragment = <Fragment children={children} />;
|
|
25
|
-
* document.body.appendChild(fragment);
|
|
26
|
-
*
|
|
27
|
-
* // Automatic update
|
|
28
|
-
* children.value = [<div>C</div>, <div>D</div>];
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare function Fragment<T extends HTMLElement = HTMLElement>(props: FragmentProps<T>): JSX.Element;
|
|
32
|
-
/**
|
|
33
|
-
* Convert KTRawContent to HTMLElement array
|
|
34
|
-
*/
|
|
35
|
-
export declare function convertChildrenToElements(children: KTRawContent): HTMLElement[];
|
package/dist/jsx/if.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { JSXTag } from '@ktjs/shared';
|
|
2
|
-
import { KTAttribute } from '../types/h.js';
|
|
3
|
-
import { KElseElement, KIfElement } from '../types/directives.js';
|
|
4
|
-
export declare function kif(tag: JSXTag, props: KTAttribute): KIfElement;
|
|
5
|
-
export declare function kelse(tag: JSXTag, props: KTAttribute): KElseElement;
|
|
6
|
-
/**
|
|
7
|
-
* Deal with `k-if` and `k-else`, checking syntax and applying listeners
|
|
8
|
-
* @param el parent element
|
|
9
|
-
*/
|
|
10
|
-
export declare function kifelseApply(el: HTMLElement): void;
|
package/dist/jsx/index.d.ts
DELETED
package/dist/jsx/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { F as Fragment, h as createElement, c as createRedrawable, j as jsx, a as jsxDEV, b as jsxs } from '../jsx-runtime-DGJHUQEM.js';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { JSXTag } from '@ktjs/shared';
|
|
2
|
-
import { KTAttribute, KTRawContent } from '../types/h.js';
|
|
3
|
-
import { h } from '../h/index.js';
|
|
4
|
-
import { KTRef } from '../reactive/index.js';
|
|
5
|
-
/**
|
|
6
|
-
* @param tag html tag or function component
|
|
7
|
-
* @param props properties/attributes
|
|
8
|
-
*/
|
|
9
|
-
export declare function jsx(tag: JSXTag, props: KTAttribute): JSX.Element;
|
|
10
|
-
/**
|
|
11
|
-
* Fragment support - returns an array of children
|
|
12
|
-
* Enhanced Fragment component that manages arrays of elements
|
|
13
|
-
*/
|
|
14
|
-
export declare function Fragment(props: {
|
|
15
|
-
children?: KTRawContent;
|
|
16
|
-
}): JSX.Element;
|
|
17
|
-
/**
|
|
18
|
-
* JSX Development runtime - same as jsx but with additional dev checks
|
|
19
|
-
*/
|
|
20
|
-
export declare const jsxDEV: typeof jsx;
|
|
21
|
-
/**
|
|
22
|
-
* JSX runtime for React 17+ automatic runtime
|
|
23
|
-
* This is called when using jsx: "react-jsx" or "react-jsxdev"
|
|
24
|
-
*/
|
|
25
|
-
export declare const jsxs: typeof jsx;
|
|
26
|
-
export { h, h as createElement };
|
|
27
|
-
/**
|
|
28
|
-
* A helper to create redrawable elements
|
|
29
|
-
* ```tsx
|
|
30
|
-
* export function MyComponent() {
|
|
31
|
-
* let aa = 10;
|
|
32
|
-
* // ...
|
|
33
|
-
* // aa might be changed
|
|
34
|
-
* return createRedrawable(() => <div>{aa}</div>);
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
* Then the returned element has a `redraw` method to redraw itself with new values.
|
|
38
|
-
* @param creator a simple creator function that returns an element
|
|
39
|
-
* @returns created element's ref
|
|
40
|
-
*/
|
|
41
|
-
export declare function createRedrawable<T>(creator: () => T): KTRef<T> & {
|
|
42
|
-
redraw: () => T;
|
|
43
|
-
};
|
package/dist/jsx/jsx-runtime.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { KTReactive, ReactiveChangeHandler } from '../types/reactive.js';
|
|
2
|
-
import { KTReactiveType } from './core.js';
|
|
3
|
-
export declare class KTComputed<T> implements KTReactive<T> {
|
|
4
|
-
/**
|
|
5
|
-
* Indicates that this is a KTRef instance
|
|
6
|
-
*/
|
|
7
|
-
isKT: true;
|
|
8
|
-
ktType: KTReactiveType;
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
private _calculator;
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
private _value;
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
private _onChanges;
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
private _emit;
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
private _recalculate;
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
private _subscribe;
|
|
33
|
-
constructor(_calculator: () => T, reactives: Array<KTReactive<unknown>>);
|
|
34
|
-
/**
|
|
35
|
-
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
36
|
-
*/
|
|
37
|
-
get value(): T;
|
|
38
|
-
set value(_newValue: T);
|
|
39
|
-
/**
|
|
40
|
-
* Force listeners to run once with the latest computed result.
|
|
41
|
-
*/
|
|
42
|
-
notify(): void;
|
|
43
|
-
/**
|
|
44
|
-
* Computed values are derived from dependencies and should not be mutated manually.
|
|
45
|
-
*/
|
|
46
|
-
mutate<R = void>(): R;
|
|
47
|
-
/**
|
|
48
|
-
* Register a callback when the value changes
|
|
49
|
-
* @param callback (newValue, oldValue) => xxx
|
|
50
|
-
*/
|
|
51
|
-
addOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
52
|
-
/**
|
|
53
|
-
* Unregister a callback
|
|
54
|
-
* @param callback (newValue, oldValue) => xxx
|
|
55
|
-
*/
|
|
56
|
-
removeOnChange(callback: ReactiveChangeHandler<T>): boolean;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Create a reactive computed value
|
|
60
|
-
* @param computeFn
|
|
61
|
-
* @param reactives refs and computeds that this computed depends on
|
|
62
|
-
*/
|
|
63
|
-
export declare function computed<T = JSX.Element>(computeFn: () => T, reactives: Array<KTReactive<any>>): KTComputed<T>;
|
package/dist/reactive/core.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { KTReactive } from '../types/reactive.js';
|
|
2
|
-
import { KTComputed, KTRef } from './index.js';
|
|
3
|
-
export declare const enum KTReactiveType {
|
|
4
|
-
REF = 1,
|
|
5
|
-
COMPUTED = 2
|
|
6
|
-
}
|
|
7
|
-
export declare const isKT: <T = any>(obj: any) => obj is KTReactive<T>;
|
|
8
|
-
export declare const isRef: <T = any>(obj: any) => obj is KTRef<T>;
|
|
9
|
-
export declare const isComputed: <T = any>(obj: any) => obj is KTComputed<T>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { KTReactive } from '../types/reactive.js';
|
|
2
|
-
interface KTEffectOptions {
|
|
3
|
-
lazy: boolean;
|
|
4
|
-
onCleanup: () => void;
|
|
5
|
-
debugName: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Register a reactive effect with options.
|
|
9
|
-
* @param effectFn The effect function to run when dependencies change
|
|
10
|
-
* @param reactives The reactive dependencies
|
|
11
|
-
* @param options Effect options: lazy, onCleanup, debugName
|
|
12
|
-
* @returns stop function to remove all listeners
|
|
13
|
-
*/
|
|
14
|
-
export declare function effect(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>): () => void;
|
|
15
|
-
export {};
|
package/dist/reactive/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { KTReactive, ReactiveChangeHandler } from '../types/reactive.js';
|
|
2
|
-
export declare const toReactive: <T>(value: T | KTReactive<T>, onChange?: ReactiveChangeHandler<T>) => KTReactive<T>;
|
|
3
|
-
/**
|
|
4
|
-
* Extracts the value from a KTReactive, or returns the value directly if it's not reactive.
|
|
5
|
-
*/
|
|
6
|
-
export declare function dereactive<T = JSX.Element>(value: T | KTReactive<T>): T;
|
|
7
|
-
export * from './core.js';
|
|
8
|
-
export * from './ref.js';
|
|
9
|
-
export * from './computed.js';
|
|
10
|
-
export * from './effect.js';
|
package/dist/reactive/ref.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { KTReactive, ReactiveChangeHandler } from '../types/reactive.js';
|
|
2
|
-
import { KTReactiveType } from './core.js';
|
|
3
|
-
export declare class KTRef<T> implements KTReactive<T> {
|
|
4
|
-
/**
|
|
5
|
-
* Indicates that this is a KTRef instance
|
|
6
|
-
*/
|
|
7
|
-
isKT: true;
|
|
8
|
-
ktType: KTReactiveType;
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
private _value;
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
private _onChanges;
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
private _emit;
|
|
21
|
-
constructor(_value: T, _onChanges: Array<ReactiveChangeHandler<T>>);
|
|
22
|
-
/**
|
|
23
|
-
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
24
|
-
*/
|
|
25
|
-
get value(): T;
|
|
26
|
-
set value(newValue: T);
|
|
27
|
-
/**
|
|
28
|
-
* Force all listeners to run even when reference identity has not changed.
|
|
29
|
-
* Useful for in-place array/object mutations.
|
|
30
|
-
*/
|
|
31
|
-
notify(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Mutate current value in-place and notify listeners once.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* const items = ref<number[]>([1, 2]);
|
|
37
|
-
* items.mutate((list) => list.push(3));
|
|
38
|
-
*/
|
|
39
|
-
mutate<R = void>(mutator: (currentValue: T) => R): R;
|
|
40
|
-
/**
|
|
41
|
-
* Register a callback when the value changes
|
|
42
|
-
* @param callback (newValue, oldValue) => xxx
|
|
43
|
-
*/
|
|
44
|
-
addOnChange(callback: ReactiveChangeHandler<T>): void;
|
|
45
|
-
removeOnChange(callback: ReactiveChangeHandler<T>): boolean;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Reference to the created HTML element.
|
|
49
|
-
* - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
|
|
50
|
-
* - can alse be used to store normal values, but it is not reactive.
|
|
51
|
-
* - if the value is already a `KTRef`, it will be returned **directly**.
|
|
52
|
-
* @param value mostly an HTMLElement
|
|
53
|
-
*/
|
|
54
|
-
export declare function ref<T = JSX.Element>(value?: T, onChange?: ReactiveChangeHandler<T>): KTRef<T>;
|
|
55
|
-
/**
|
|
56
|
-
* Convert a value to `KTRef`.
|
|
57
|
-
* - Returns the original value if it is already a `KTRef`.
|
|
58
|
-
* - Throws error if the value is a `KTComputed`.
|
|
59
|
-
* - Otherwise wraps the value with `ref()`.
|
|
60
|
-
* @param o value to convert
|
|
61
|
-
*/
|
|
62
|
-
export declare const toRef: <T = any>(o: any) => KTRef<T>;
|
|
63
|
-
export type KTSurfaceRef<T extends object> = {
|
|
64
|
-
[K in keyof T]: KTRef<T[K]>;
|
|
65
|
-
} & {
|
|
66
|
-
/**
|
|
67
|
-
* Get the dereferenced object like the original one
|
|
68
|
-
*/
|
|
69
|
-
kcollect: () => T;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Make all first-level properties of the object a `KTRef`.
|
|
73
|
-
* - `obj.a.b` is not reactive
|
|
74
|
-
*/
|
|
75
|
-
export declare const surfaceRef: <T extends object>(obj: T) => KTSurfaceRef<T>;
|
|
76
|
-
/**
|
|
77
|
-
* Assert k-model to be a ref object
|
|
78
|
-
*/
|
|
79
|
-
export declare const $modelOrRef: <T = any>(props: any, defaultValue?: T) => KTRef<T>;
|
|
80
|
-
type RefSetter<T> = (props: {
|
|
81
|
-
ref?: KTRef<T>;
|
|
82
|
-
}, node: T) => void;
|
|
83
|
-
/**
|
|
84
|
-
* Whether `props.ref` is a `KTRef` only needs to be checked in the initial render
|
|
85
|
-
*/
|
|
86
|
-
export declare const $initRef: <T extends Node>(props: {
|
|
87
|
-
ref?: KTRef<T>;
|
|
88
|
-
}, node: T) => RefSetter<T>;
|
|
89
|
-
export {};
|