@ktjs/shared 0.22.4 → 0.22.6

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
@@ -107,7 +107,11 @@ type ChangeTriggerField = 'value' | 'checked' | 'selected' | 'valueAsDate' | 'va
107
107
 
108
108
  type InputElementTag = 'input' | 'select' | 'textarea';
109
109
 
110
- declare const $isNode: (x: any) => boolean;
110
+ declare const $isNode: (x: any) => x is ChildNode;
111
+ /**
112
+ * Safe replace `oldNode` With `newNode`
113
+ */
114
+ declare const $replaceNode: (oldNode: unknown, newNode: unknown) => void;
111
115
  /**
112
116
  * & Remove `bind` because it is shockingly slower than wrapper
113
117
  * & `window.document` is safe because it is not configurable and its setter is undefined
@@ -156,5 +160,5 @@ declare const emplaceParams: (path: string, params: Record<string, string>) => s
156
160
  */
157
161
  declare const extractParams: (pattern: string, path: string) => Record<string, string> | null;
158
162
 
159
- export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isNode, $isThenable, $keys, $random, $throw, $toString, $warn, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, applyModel, buildQuery, emplaceParams, extractParams, generateHandler, normalizePath, parseQuery, parseStyle };
163
+ export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isNode, $isThenable, $keys, $random, $replaceNode, $throw, $toString, $warn, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, applyModel, buildQuery, emplaceParams, extractParams, generateHandler, normalizePath, parseQuery, parseStyle };
160
164
  export type { ChangeHandler, ChangeTriggerField, HTMLTag, InputElementTag, MathMLTag, NoTextNodeTag, NonSpecialTags, SVGTag, otherstring };
@@ -28,7 +28,7 @@ var __ktjs_shared__ = (function (exports) {
28
28
  const $define = Object.defineProperty;
29
29
  const $entries = Object.entries;
30
30
  const $random = Math.random;
31
- const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
31
+ const $isThenable = (o) => typeof o?.then === 'function';
32
32
 
33
33
  // Error handling utilities
34
34
  /**
@@ -51,6 +51,17 @@ var __ktjs_shared__ = (function (exports) {
51
51
  // DOM manipulation utilities
52
52
  // # dom natives
53
53
  const $isNode = (x) => x?.nodeType > 0;
54
+ /**
55
+ * Safe replace `oldNode` With `newNode`
56
+ */
57
+ const $replaceNode = (oldNode, newNode) => {
58
+ if ($isNode(oldNode) && $isNode(newNode)) {
59
+ if (newNode.contains(oldNode)) {
60
+ newNode.remove();
61
+ }
62
+ oldNode.replaceWith(newNode);
63
+ }
64
+ };
54
65
  /**
55
66
  * & Remove `bind` because it is shockingly slower than wrapper
56
67
  * & `window.document` is safe because it is not configurable and its setter is undefined
@@ -202,7 +213,7 @@ var __ktjs_shared__ = (function (exports) {
202
213
  }
203
214
 
204
215
  // Shared utilities and cached native methods for kt.js framework
205
- Object.defineProperty(window, '__ktjs__', { value: '0.22.4' });
216
+ Object.defineProperty(window, '__ktjs__', { value: '0.22.6' });
206
217
 
207
218
  exports.$ArrayFrom = $ArrayFrom;
208
219
  exports.$append = $append;
@@ -221,6 +232,7 @@ var __ktjs_shared__ = (function (exports) {
221
232
  exports.$isThenable = $isThenable;
222
233
  exports.$keys = $keys;
223
234
  exports.$random = $random;
235
+ exports.$replaceNode = $replaceNode;
224
236
  exports.$throw = $throw;
225
237
  exports.$toString = $toString;
226
238
  exports.$warn = $warn;
@@ -28,9 +28,7 @@ var __ktjs_shared__ = (function (exports) {
28
28
  var $define = Object.defineProperty;
29
29
  var $entries = Object.entries;
30
30
  var $random = Math.random;
31
- var $isThenable = function (o) {
32
- return typeof o === 'object' && o !== null && typeof o.then === 'function';
33
- };
31
+ var $isThenable = function (o) { return typeof (o === null || o === void 0 ? void 0 : o.then) === 'function'; };
34
32
 
35
33
  // Error handling utilities
36
34
  /**
@@ -54,6 +52,17 @@ var __ktjs_shared__ = (function (exports) {
54
52
  var _a;
55
53
  // # dom natives
56
54
  var $isNode = function (x) { return (x === null || x === void 0 ? void 0 : x.nodeType) > 0; };
55
+ /**
56
+ * Safe replace `oldNode` With `newNode`
57
+ */
58
+ var $replaceNode = function (oldNode, newNode) {
59
+ if ($isNode(oldNode) && $isNode(newNode)) {
60
+ if (newNode.contains(oldNode)) {
61
+ newNode.remove();
62
+ }
63
+ oldNode.replaceWith(newNode);
64
+ }
65
+ };
57
66
  /**
58
67
  * & Remove `bind` because it is shockingly slower than wrapper
59
68
  * & `window.document` is safe because it is not configurable and its setter is undefined
@@ -215,7 +224,7 @@ var __ktjs_shared__ = (function (exports) {
215
224
  }
216
225
 
217
226
  // Shared utilities and cached native methods for kt.js framework
218
- Object.defineProperty(window, '__ktjs__', { value: '0.22.4' });
227
+ Object.defineProperty(window, '__ktjs__', { value: '0.22.6' });
219
228
 
220
229
  exports.$ArrayFrom = $ArrayFrom;
221
230
  exports.$append = $append;
@@ -234,6 +243,7 @@ var __ktjs_shared__ = (function (exports) {
234
243
  exports.$isThenable = $isThenable;
235
244
  exports.$keys = $keys;
236
245
  exports.$random = $random;
246
+ exports.$replaceNode = $replaceNode;
237
247
  exports.$throw = $throw;
238
248
  exports.$toString = $toString;
239
249
  exports.$warn = $warn;
package/dist/index.mjs CHANGED
@@ -25,7 +25,7 @@ const $defines = Object.defineProperties;
25
25
  const $define = Object.defineProperty;
26
26
  const $entries = Object.entries;
27
27
  const $random = Math.random;
28
- const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
28
+ const $isThenable = (o) => typeof o?.then === 'function';
29
29
 
30
30
  // Error handling utilities
31
31
  /**
@@ -48,6 +48,17 @@ const $emptyFn = (() => true);
48
48
  // DOM manipulation utilities
49
49
  // # dom natives
50
50
  const $isNode = (x) => x?.nodeType > 0;
51
+ /**
52
+ * Safe replace `oldNode` With `newNode`
53
+ */
54
+ const $replaceNode = (oldNode, newNode) => {
55
+ if ($isNode(oldNode) && $isNode(newNode)) {
56
+ if (newNode.contains(oldNode)) {
57
+ newNode.remove();
58
+ }
59
+ oldNode.replaceWith(newNode);
60
+ }
61
+ };
51
62
  /**
52
63
  * & Remove `bind` because it is shockingly slower than wrapper
53
64
  * & `window.document` is safe because it is not configurable and its setter is undefined
@@ -199,6 +210,6 @@ if (typeof Symbol === 'undefined') {
199
210
  }
200
211
 
201
212
  // Shared utilities and cached native methods for kt.js framework
202
- Object.defineProperty(window, '__ktjs__', { value: '0.22.4' });
213
+ Object.defineProperty(window, '__ktjs__', { value: '0.22.6' });
203
214
 
204
- export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isNode, $isThenable, $keys, $random, $throw, $toString, $warn, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, applyModel, buildQuery, emplaceParams, extractParams, generateHandler, normalizePath, parseQuery, parseStyle };
215
+ export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isNode, $isThenable, $keys, $random, $replaceNode, $throw, $toString, $warn, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, applyModel, buildQuery, emplaceParams, extractParams, generateHandler, normalizePath, parseQuery, parseStyle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/shared",
3
- "version": "0.22.4",
3
+ "version": "0.22.6",
4
4
  "description": "Shared utilities and cached native methods for kt.js framework",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",