@ktjs/shared 0.20.2 → 0.22.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.d.ts +80 -3
- package/dist/index.iife.js +19 -4
- package/dist/index.legacy.js +19 -4
- package/dist/index.mjs +18 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,79 @@ declare const $define: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor
|
|
|
20
20
|
declare const $entries: <T>(o: T) => Array<[keyof T, T[keyof T]]>;
|
|
21
21
|
declare const $isThenable: (o: any) => o is Promise<any>;
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* * Actually, these functions will be replaced as they are by @rollup/plugin-replace
|
|
25
|
+
* @see ./.scripts/replace.mjs
|
|
26
|
+
*/
|
|
23
27
|
declare const $throw: (message: string) => never;
|
|
28
|
+
declare const $warn: (message: string) => void;
|
|
29
|
+
|
|
30
|
+
type otherstring = string & {};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Normal HTML tags like `div`, `span`, `a`, etc.
|
|
34
|
+
*/
|
|
35
|
+
type HTMLTag = keyof HTMLElementTagNameMap;
|
|
36
|
+
type SVGTag = keyof SVGElementTagNameMap;
|
|
37
|
+
type MathMLTag = keyof MathMLElementTagNameMap;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the tags that makes HTMLElementTagNameMap[tag] = HTMLElement
|
|
41
|
+
*/
|
|
42
|
+
type NonSpecialTags = {
|
|
43
|
+
[K in keyof HTMLElementTagNameMap]: HTMLElement extends HTMLElementTagNameMap[K] ? K : never;
|
|
44
|
+
}[keyof HTMLElementTagNameMap];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This is tested on 15 browsers (most popular ones)
|
|
48
|
+
* - appending a text node to these tags takes no effect.
|
|
49
|
+
* - No effect means `innerText` does not include the text in the text node.
|
|
50
|
+
* @see {@link src/core/h/no-text-node.ts}
|
|
51
|
+
*/
|
|
52
|
+
type NoTextNodeTag =
|
|
53
|
+
| 'area'
|
|
54
|
+
| 'audio'
|
|
55
|
+
| 'base'
|
|
56
|
+
| 'basefont'
|
|
57
|
+
| 'br'
|
|
58
|
+
| 'canvas'
|
|
59
|
+
| 'datalist'
|
|
60
|
+
| 'details'
|
|
61
|
+
| 'dialog'
|
|
62
|
+
| 'frameset'
|
|
63
|
+
| 'head'
|
|
64
|
+
| 'iframe'
|
|
65
|
+
| 'img'
|
|
66
|
+
| 'input'
|
|
67
|
+
| 'link'
|
|
68
|
+
| 'meta'
|
|
69
|
+
| 'meter'
|
|
70
|
+
| 'noembed'
|
|
71
|
+
| 'noframes'
|
|
72
|
+
| 'noscript'
|
|
73
|
+
| 'optgroup'
|
|
74
|
+
| 'param'
|
|
75
|
+
| 'progress'
|
|
76
|
+
| 'rp'
|
|
77
|
+
| 'select'
|
|
78
|
+
| 'style'
|
|
79
|
+
| 'template'
|
|
80
|
+
| 'textarea'
|
|
81
|
+
| 'title'
|
|
82
|
+
| 'video'
|
|
83
|
+
| 'wbr'
|
|
84
|
+
| 'embed'
|
|
85
|
+
| 'frame'
|
|
86
|
+
| 'keygen'
|
|
87
|
+
| 'option';
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* These fields of HTMLElement can trigger `change`.
|
|
91
|
+
*/
|
|
92
|
+
type ChangeTriggerField = 'value' | 'checked' | 'selected' | 'valueAsDate' | 'valueAsNumber';
|
|
93
|
+
|
|
94
|
+
type InputElementTag = 'input' | 'select' | 'textarea';
|
|
24
95
|
|
|
25
|
-
declare const $replaceWith: (...nodes: (Node | string)[]) => void;
|
|
26
96
|
/**
|
|
27
97
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
28
98
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -35,6 +105,13 @@ declare const $buttonDisabledSetter: (v: any) => void;
|
|
|
35
105
|
declare const parseStyle: (style: string | Partial<CSSStyleDeclaration> | undefined) => string;
|
|
36
106
|
type ChangeHandler<T = string> = (value: T, ...args: any[]) => void;
|
|
37
107
|
declare const generateHandler: <T = string>(props: any, key: string) => ChangeHandler<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Used for `k-model`
|
|
110
|
+
*/
|
|
111
|
+
declare const applyModel: (element: HTMLElementTagNameMap[InputElementTag], valueRef: {
|
|
112
|
+
value: unknown;
|
|
113
|
+
addOnChange: (fn: (newValue: unknown) => void) => void;
|
|
114
|
+
}, propName: "value" | "checked", eventName: "change" | "input") => void;
|
|
38
115
|
|
|
39
116
|
/**
|
|
40
117
|
* Default empty function
|
|
@@ -64,5 +141,5 @@ declare const emplaceParams: (path: string, params: Record<string, string>) => s
|
|
|
64
141
|
*/
|
|
65
142
|
declare const extractParams: (pattern: string, path: string) => Record<string, string> | null;
|
|
66
143
|
|
|
67
|
-
export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isThenable, $keys, $
|
|
68
|
-
export type { ChangeHandler };
|
|
144
|
+
export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isThenable, $keys, $throw, $toString, $warn, applyModel, buildQuery, emplaceParams, extractParams, generateHandler, normalizePath, parseQuery, parseStyle };
|
|
145
|
+
export type { ChangeHandler, ChangeTriggerField, HTMLTag, InputElementTag, MathMLTag, NoTextNodeTag, NonSpecialTags, SVGTag, otherstring };
|
package/dist/index.iife.js
CHANGED
|
@@ -15,8 +15,15 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
15
15
|
const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
|
|
16
16
|
|
|
17
17
|
// Error handling utilities
|
|
18
|
+
/**
|
|
19
|
+
* * Actually, these functions will be replaced as they are by @rollup/plugin-replace
|
|
20
|
+
* @see ./.scripts/replace.mjs
|
|
21
|
+
*/
|
|
18
22
|
const $throw = (message) => {
|
|
19
|
-
throw new Error('
|
|
23
|
+
throw new Error('[kt.js error]' + message);
|
|
24
|
+
};
|
|
25
|
+
const $warn = (message) => {
|
|
26
|
+
console.warn('[kt.js warn] ' + message);
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
// String manipulation utilities
|
|
@@ -27,7 +34,6 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
27
34
|
|
|
28
35
|
// DOM manipulation utilities
|
|
29
36
|
// # dom natives
|
|
30
|
-
const $replaceWith = Element.prototype.replaceWith;
|
|
31
37
|
/**
|
|
32
38
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
33
39
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -90,6 +96,14 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
90
96
|
}
|
|
91
97
|
return $emptyFn;
|
|
92
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* Used for `k-model`
|
|
101
|
+
*/
|
|
102
|
+
const applyModel = (element, valueRef, propName, eventName) => {
|
|
103
|
+
element[propName] = valueRef.value; // initialize
|
|
104
|
+
valueRef.addOnChange((newValue) => (element[propName] = newValue));
|
|
105
|
+
element.addEventListener(eventName, () => (valueRef.value = element[propName]));
|
|
106
|
+
};
|
|
93
107
|
|
|
94
108
|
/**
|
|
95
109
|
* Normalize path by joining parts and ensuring leading slash
|
|
@@ -166,7 +180,7 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
166
180
|
|
|
167
181
|
// Shared utilities and cached native methods for kt.js framework
|
|
168
182
|
// Re-export all utilities
|
|
169
|
-
Object.defineProperty(window, '
|
|
183
|
+
Object.defineProperty(window, '__ktjs__', { value: '0.22.2' });
|
|
170
184
|
|
|
171
185
|
exports.$ArrayFrom = $ArrayFrom;
|
|
172
186
|
exports.$append = $append;
|
|
@@ -183,9 +197,10 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
183
197
|
exports.$isArray = $isArray;
|
|
184
198
|
exports.$isThenable = $isThenable;
|
|
185
199
|
exports.$keys = $keys;
|
|
186
|
-
exports.$replaceWith = $replaceWith;
|
|
187
200
|
exports.$throw = $throw;
|
|
188
201
|
exports.$toString = $toString;
|
|
202
|
+
exports.$warn = $warn;
|
|
203
|
+
exports.applyModel = applyModel;
|
|
189
204
|
exports.buildQuery = buildQuery;
|
|
190
205
|
exports.emplaceParams = emplaceParams;
|
|
191
206
|
exports.extractParams = extractParams;
|
package/dist/index.legacy.js
CHANGED
|
@@ -17,8 +17,15 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// Error handling utilities
|
|
20
|
+
/**
|
|
21
|
+
* * Actually, these functions will be replaced as they are by @rollup/plugin-replace
|
|
22
|
+
* @see ./.scripts/replace.mjs
|
|
23
|
+
*/
|
|
20
24
|
var $throw = function (message) {
|
|
21
|
-
throw new Error('
|
|
25
|
+
throw new Error('[kt.js error]' + message);
|
|
26
|
+
};
|
|
27
|
+
var $warn = function (message) {
|
|
28
|
+
console.warn('[kt.js warn] ' + message);
|
|
22
29
|
};
|
|
23
30
|
|
|
24
31
|
// String manipulation utilities
|
|
@@ -30,7 +37,6 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
30
37
|
// DOM manipulation utilities
|
|
31
38
|
var _a;
|
|
32
39
|
// # dom natives
|
|
33
|
-
var $replaceWith = Element.prototype.replaceWith;
|
|
34
40
|
/**
|
|
35
41
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
36
42
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -98,6 +104,14 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
98
104
|
}
|
|
99
105
|
return $emptyFn;
|
|
100
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Used for `k-model`
|
|
109
|
+
*/
|
|
110
|
+
var applyModel = function (element, valueRef, propName, eventName) {
|
|
111
|
+
element[propName] = valueRef.value; // initialize
|
|
112
|
+
valueRef.addOnChange(function (newValue) { return (element[propName] = newValue); });
|
|
113
|
+
element.addEventListener(eventName, function () { return (valueRef.value = element[propName]); });
|
|
114
|
+
};
|
|
101
115
|
|
|
102
116
|
/**
|
|
103
117
|
* Normalize path by joining parts and ensuring leading slash
|
|
@@ -179,7 +193,7 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
179
193
|
|
|
180
194
|
// Shared utilities and cached native methods for kt.js framework
|
|
181
195
|
// Re-export all utilities
|
|
182
|
-
Object.defineProperty(window, '
|
|
196
|
+
Object.defineProperty(window, '__ktjs__', { value: '0.22.2' });
|
|
183
197
|
|
|
184
198
|
exports.$ArrayFrom = $ArrayFrom;
|
|
185
199
|
exports.$append = $append;
|
|
@@ -196,9 +210,10 @@ var __ktjs_shared__ = (function (exports) {
|
|
|
196
210
|
exports.$isArray = $isArray;
|
|
197
211
|
exports.$isThenable = $isThenable;
|
|
198
212
|
exports.$keys = $keys;
|
|
199
|
-
exports.$replaceWith = $replaceWith;
|
|
200
213
|
exports.$throw = $throw;
|
|
201
214
|
exports.$toString = $toString;
|
|
215
|
+
exports.$warn = $warn;
|
|
216
|
+
exports.applyModel = applyModel;
|
|
202
217
|
exports.buildQuery = buildQuery;
|
|
203
218
|
exports.emplaceParams = emplaceParams;
|
|
204
219
|
exports.extractParams = extractParams;
|
package/dist/index.mjs
CHANGED
|
@@ -12,8 +12,15 @@ const $entries = Object.entries;
|
|
|
12
12
|
const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
|
|
13
13
|
|
|
14
14
|
// Error handling utilities
|
|
15
|
+
/**
|
|
16
|
+
* * Actually, these functions will be replaced as they are by @rollup/plugin-replace
|
|
17
|
+
* @see ./.scripts/replace.mjs
|
|
18
|
+
*/
|
|
15
19
|
const $throw = (message) => {
|
|
16
|
-
throw new Error('
|
|
20
|
+
throw new Error('[kt.js error]' + message);
|
|
21
|
+
};
|
|
22
|
+
const $warn = (message) => {
|
|
23
|
+
console.warn('[kt.js warn] ' + message);
|
|
17
24
|
};
|
|
18
25
|
|
|
19
26
|
// String manipulation utilities
|
|
@@ -24,7 +31,6 @@ const $emptyFn = (() => true);
|
|
|
24
31
|
|
|
25
32
|
// DOM manipulation utilities
|
|
26
33
|
// # dom natives
|
|
27
|
-
const $replaceWith = Element.prototype.replaceWith;
|
|
28
34
|
/**
|
|
29
35
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
30
36
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -87,6 +93,14 @@ const generateHandler = (props, key) => {
|
|
|
87
93
|
}
|
|
88
94
|
return $emptyFn;
|
|
89
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Used for `k-model`
|
|
98
|
+
*/
|
|
99
|
+
const applyModel = (element, valueRef, propName, eventName) => {
|
|
100
|
+
element[propName] = valueRef.value; // initialize
|
|
101
|
+
valueRef.addOnChange((newValue) => (element[propName] = newValue));
|
|
102
|
+
element.addEventListener(eventName, () => (valueRef.value = element[propName]));
|
|
103
|
+
};
|
|
90
104
|
|
|
91
105
|
/**
|
|
92
106
|
* Normalize path by joining parts and ensuring leading slash
|
|
@@ -163,6 +177,6 @@ const extractParams = (pattern, path) => {
|
|
|
163
177
|
|
|
164
178
|
// Shared utilities and cached native methods for kt.js framework
|
|
165
179
|
// Re-export all utilities
|
|
166
|
-
Object.defineProperty(window, '
|
|
180
|
+
Object.defineProperty(window, '__ktjs__', { value: '0.22.2' });
|
|
167
181
|
|
|
168
|
-
export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isThenable, $keys, $
|
|
182
|
+
export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isThenable, $keys, $throw, $toString, $warn, applyModel, buildQuery, emplaceParams, extractParams, generateHandler, normalizePath, parseQuery, parseStyle };
|