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