@tko/utils 4.0.0-beta1.3 → 4.0.0
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/array.js +39 -35
- package/dist/array.js.map +2 -2
- package/dist/async.js +4 -3
- package/dist/async.js.map +2 -2
- package/dist/css.js +5 -4
- package/dist/css.js.map +2 -2
- package/dist/dom/data.js +36 -46
- package/dist/dom/data.js.map +2 -2
- package/dist/dom/disposal.js +23 -16
- package/dist/dom/disposal.js.map +2 -2
- package/dist/dom/event.js +39 -41
- package/dist/dom/event.js.map +2 -2
- package/dist/dom/fixes.js +5 -24
- package/dist/dom/fixes.js.map +2 -2
- package/dist/dom/html.js +46 -61
- package/dist/dom/html.js.map +2 -2
- package/dist/dom/info.js +10 -8
- package/dist/dom/info.js.map +2 -2
- package/dist/dom/manipulation.js +16 -24
- package/dist/dom/manipulation.js.map +2 -2
- package/dist/dom/selectExtensions.js +33 -23
- package/dist/dom/selectExtensions.js.map +2 -2
- package/dist/dom/virtualElements.js +40 -32
- package/dist/dom/virtualElements.js.map +3 -3
- package/dist/error.js +2 -1
- package/dist/error.js.map +2 -2
- package/dist/function.js +2 -1
- package/dist/function.js.map +2 -2
- package/dist/index.cjs +446 -449
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +2 -3
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +2 -2
- package/dist/memoization.js +18 -13
- package/dist/memoization.js.map +3 -3
- package/dist/object.js +10 -8
- package/dist/object.js.map +2 -2
- package/dist/options.js +97 -35
- package/dist/options.js.map +2 -2
- package/dist/string.js +3 -5
- package/dist/string.js.map +2 -2
- package/dist/symbol.js +3 -2
- package/dist/symbol.js.map +2 -2
- package/dist/tasks.js +10 -20
- package/dist/tasks.js.map +2 -2
- package/helpers/jasmine-13-helper.ts +198 -147
- package/package.json +2 -3
- package/LICENSE +0 -22
- package/dist/bind-shim.js +0 -18
- package/dist/bind-shim.js.map +0 -7
- package/dist/ie.js +0 -15
- package/dist/ie.js.map +0 -7
- package/dist/jquery.js +0 -6
- package/dist/jquery.js.map +0 -7
package/dist/dom/event.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
2
3
|
import { objectForEach } from "../object";
|
|
3
|
-
import { jQueryInstance } from "../jquery";
|
|
4
|
-
import { ieVersion } from "../ie";
|
|
5
4
|
import { catchFunctionErrors } from "../error";
|
|
6
5
|
import { tagNameLower } from "./info";
|
|
7
|
-
import { addDisposeCallback } from "./disposal";
|
|
8
6
|
import options from "../options";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
knownEvents[keyEventTypeName] = ["keyup", "keydown", "keypress"];
|
|
7
|
+
const knownEvents = {}, knownEventTypesByEventName = {};
|
|
8
|
+
knownEvents["UIEvents"] = ["keyup", "keydown", "keypress"];
|
|
12
9
|
knownEvents["MouseEvents"] = [
|
|
13
10
|
"click",
|
|
14
11
|
"dblclick",
|
|
@@ -22,65 +19,66 @@ knownEvents["MouseEvents"] = [
|
|
|
22
19
|
];
|
|
23
20
|
objectForEach(knownEvents, function(eventType, knownEventsForType) {
|
|
24
21
|
if (knownEventsForType.length) {
|
|
25
|
-
for (
|
|
22
|
+
for (let i = 0, j = knownEventsForType.length; i < j; i++) {
|
|
26
23
|
knownEventTypesByEventName[knownEventsForType[i]] = eventType;
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
27
|
function isClickOnCheckableElement(element, eventType) {
|
|
31
|
-
if (tagNameLower(element) !== "input" || !element.type)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return false;
|
|
35
|
-
var inputType = element.type;
|
|
28
|
+
if (tagNameLower(element) !== "input" || !element.type) return false;
|
|
29
|
+
if (eventType.toLowerCase() != "click") return false;
|
|
30
|
+
const inputType = element.type;
|
|
36
31
|
return inputType == "checkbox" || inputType == "radio";
|
|
37
32
|
}
|
|
38
|
-
var eventsThatMustBeRegisteredUsingAttachEvent = { "propertychange": true };
|
|
39
|
-
let jQueryEventAttachName;
|
|
40
33
|
export function registerEventHandler(element, eventType, handler, eventOptions = false) {
|
|
41
34
|
const wrappedHandler = catchFunctionErrors(handler);
|
|
42
|
-
const mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];
|
|
43
35
|
const mustUseNative = Boolean(eventOptions);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
jQueryInstance(element)[jQueryEventAttachName](eventType, wrappedHandler);
|
|
49
|
-
} else if (!mustUseAttachEvent && typeof element.addEventListener === "function") {
|
|
36
|
+
const jQuery = options.jQuery;
|
|
37
|
+
if (!options.useOnlyNativeEvents && !mustUseNative && jQuery) {
|
|
38
|
+
jQuery(element).on(eventType, wrappedHandler);
|
|
39
|
+
} else if (typeof element.addEventListener === "function") {
|
|
50
40
|
element.addEventListener(eventType, wrappedHandler, eventOptions);
|
|
51
|
-
} else if (typeof element.attachEvent !== "undefined") {
|
|
52
|
-
const attachEventHandler = function(event) {
|
|
53
|
-
wrappedHandler.call(element, event);
|
|
54
|
-
};
|
|
55
|
-
const attachEventName = "on" + eventType;
|
|
56
|
-
element.attachEvent(attachEventName, attachEventHandler);
|
|
57
|
-
addDisposeCallback(element, function() {
|
|
58
|
-
element.detachEvent(attachEventName, attachEventHandler);
|
|
59
|
-
});
|
|
60
41
|
} else {
|
|
61
|
-
throw new Error("Browser doesn't support addEventListener
|
|
42
|
+
throw new Error("Browser doesn't support addEventListener");
|
|
62
43
|
}
|
|
63
44
|
}
|
|
45
|
+
function hasClick(element) {
|
|
46
|
+
return typeof element.click === "function";
|
|
47
|
+
}
|
|
64
48
|
export function triggerEvent(element, eventType) {
|
|
65
49
|
if (!(element && element.nodeType)) {
|
|
66
50
|
throw new Error("element must be a DOM node when calling triggerEvent");
|
|
67
51
|
}
|
|
68
|
-
|
|
69
|
-
if (!options.useOnlyNativeEvents &&
|
|
70
|
-
|
|
52
|
+
const useClickWorkaround = isClickOnCheckableElement(element, eventType);
|
|
53
|
+
if (!options.useOnlyNativeEvents && options.jQuery && !useClickWorkaround) {
|
|
54
|
+
options.jQuery(element).trigger(eventType);
|
|
71
55
|
} else if (typeof document.createEvent === "function") {
|
|
72
56
|
if (typeof element.dispatchEvent === "function") {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
event.initEvent(
|
|
57
|
+
const eventCategory = knownEventTypesByEventName[eventType] || "HTMLEvents";
|
|
58
|
+
const event = document.createEvent(eventCategory);
|
|
59
|
+
event.initEvent(
|
|
60
|
+
eventType,
|
|
61
|
+
true,
|
|
62
|
+
true,
|
|
63
|
+
options.global,
|
|
64
|
+
0,
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
0,
|
|
68
|
+
0,
|
|
69
|
+
false,
|
|
70
|
+
false,
|
|
71
|
+
false,
|
|
72
|
+
false,
|
|
73
|
+
0,
|
|
74
|
+
element
|
|
75
|
+
);
|
|
76
76
|
element.dispatchEvent(event);
|
|
77
77
|
} else {
|
|
78
78
|
throw new Error("The supplied element doesn't support dispatchEvent");
|
|
79
79
|
}
|
|
80
|
-
} else if (useClickWorkaround && element
|
|
80
|
+
} else if (useClickWorkaround && hasClick(element)) {
|
|
81
81
|
element.click();
|
|
82
|
-
} else if (typeof element.fireEvent !== "undefined") {
|
|
83
|
-
element.fireEvent("on" + eventType);
|
|
84
82
|
} else {
|
|
85
83
|
throw new Error("Browser doesn't support triggering events");
|
|
86
84
|
}
|
package/dist/dom/event.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/event.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// DOM Events\n//\n\nimport { objectForEach } from '../object'\nimport {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// DOM Events\n//\n\nimport { objectForEach } from '../object'\nimport { catchFunctionErrors } from '../error'\nimport { tagNameLower } from './info'\n\nimport options from '../options'\n\n// Represent the known event types in a compact way, then at runtime transform it into a hash with event name as key (for fast lookup)\nconst knownEvents = {},\n knownEventTypesByEventName = {}\n\nknownEvents['UIEvents'] = ['keyup', 'keydown', 'keypress']\n\nknownEvents['MouseEvents'] = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseover',\n 'mouseout',\n 'mouseenter',\n 'mouseleave'\n]\n\nobjectForEach(knownEvents, function (eventType, knownEventsForType) {\n if (knownEventsForType.length) {\n for (let i = 0, j = knownEventsForType.length; i < j; i++) {\n knownEventTypesByEventName[knownEventsForType[i]] = eventType\n }\n }\n})\n\nfunction isClickOnCheckableElement(element: Element, eventType: string) {\n if (tagNameLower(element) !== 'input' || !(element as HTMLInputElement).type) return false\n if (eventType.toLowerCase() != 'click') return false\n const inputType = (element as HTMLInputElement).type\n return inputType == 'checkbox' || inputType == 'radio'\n}\n\nexport function registerEventHandler(\n element: Element,\n eventType: string,\n handler: EventListener,\n eventOptions = false\n): void {\n const wrappedHandler = catchFunctionErrors(handler)\n const mustUseNative = Boolean(eventOptions)\n const jQuery = options.jQuery\n\n if (!options.useOnlyNativeEvents && !mustUseNative && jQuery) {\n jQuery(element).on(eventType, wrappedHandler)\n } else if (typeof element.addEventListener === 'function') {\n element.addEventListener(eventType, wrappedHandler, eventOptions)\n } else {\n throw new Error(\"Browser doesn't support addEventListener\")\n }\n}\n\nfunction hasClick(element: Element): element is Element & { click(): void } {\n return typeof (element as any).click === 'function'\n}\n\nexport function triggerEvent(element: Element, eventType: string): void {\n if (!(element && element.nodeType)) {\n throw new Error('element must be a DOM node when calling triggerEvent')\n }\n\n // For click events on checkboxes and radio buttons, jQuery toggles the element checked state *after* the\n // event handler runs instead of *before*. (This was fixed in 1.9 for checkboxes but not for radio buttons.)\n const useClickWorkaround = isClickOnCheckableElement(element, eventType)\n\n if (!options.useOnlyNativeEvents && options.jQuery && !useClickWorkaround) {\n options.jQuery(element).trigger(eventType)\n } else if (typeof document.createEvent === 'function') {\n if (typeof element.dispatchEvent === 'function') {\n const eventCategory = knownEventTypesByEventName[eventType] || 'HTMLEvents'\n const event = document.createEvent(eventCategory)\n ;(event as any).initEvent(\n eventType,\n true,\n true,\n options.global,\n 0,\n 0,\n 0,\n 0,\n 0,\n false,\n false,\n false,\n false,\n 0,\n element\n )\n element.dispatchEvent(event)\n } else {\n throw new Error(\"The supplied element doesn't support dispatchEvent\")\n }\n } else if (useClickWorkaround && hasClick(element)) {\n element.click()\n } else {\n throw new Error(\"Browser doesn't support triggering events\")\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAIA,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAE7B,OAAO,aAAa;AAGpB,MAAM,cAAc,CAAC,GACnB,6BAA6B,CAAC;AAEhC,YAAY,UAAU,IAAI,CAAC,SAAS,WAAW,UAAU;AAEzD,YAAY,aAAa,IAAI;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,cAAc,aAAa,SAAU,WAAW,oBAAoB;AAClE,MAAI,mBAAmB,QAAQ;AAC7B,aAAS,IAAI,GAAG,IAAI,mBAAmB,QAAQ,IAAI,GAAG,KAAK;AACzD,iCAA2B,mBAAmB,CAAC,CAAC,IAAI;AAAA,IACtD;AAAA,EACF;AACF,CAAC;AAED,SAAS,0BAA0B,SAAkB,WAAmB;AACtE,MAAI,aAAa,OAAO,MAAM,WAAW,CAAE,QAA6B,KAAM,QAAO;AACrF,MAAI,UAAU,YAAY,KAAK,QAAS,QAAO;AAC/C,QAAM,YAAa,QAA6B;AAChD,SAAO,aAAa,cAAc,aAAa;AACjD;AAEO,gBAAS,qBACd,SACA,WACA,SACA,eAAe,OACT;AACN,QAAM,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;AAAA,EAC7D;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/dom/fixes.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
2
|
-
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
3
3
|
export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
|
|
4
4
|
if (continuousNodeArray.length) {
|
|
5
|
-
parentNode = parentNode.nodeType ===
|
|
5
|
+
parentNode = parentNode.nodeType === Node.COMMENT_NODE && parentNode.parentNode || parentNode;
|
|
6
6
|
while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) {
|
|
7
7
|
continuousNodeArray.splice(0, 1);
|
|
8
8
|
}
|
|
@@ -10,7 +10,7 @@ export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
|
|
|
10
10
|
continuousNodeArray.length--;
|
|
11
11
|
}
|
|
12
12
|
if (continuousNodeArray.length > 1) {
|
|
13
|
-
|
|
13
|
+
let current = continuousNodeArray[0], last = continuousNodeArray[continuousNodeArray.length - 1];
|
|
14
14
|
continuousNodeArray.length = 0;
|
|
15
15
|
while (current !== last) {
|
|
16
16
|
continuousNodeArray.push(current);
|
|
@@ -22,24 +22,5 @@ export function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {
|
|
|
22
22
|
return continuousNodeArray;
|
|
23
23
|
}
|
|
24
24
|
export function setOptionNodeSelectionState(optionNode, isSelected) {
|
|
25
|
-
|
|
26
|
-
optionNode.setAttribute("selected", isSelected);
|
|
27
|
-
} else {
|
|
28
|
-
optionNode.selected = isSelected;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export function forceRefresh(node) {
|
|
32
|
-
if (ieVersion >= 9) {
|
|
33
|
-
var elem = node.nodeType == 1 ? node : node.parentNode;
|
|
34
|
-
if (elem.style) {
|
|
35
|
-
elem.style.zoom = elem.style.zoom;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export function ensureSelectElementIsRenderedCorrectly(selectElement) {
|
|
40
|
-
if (ieVersion) {
|
|
41
|
-
var originalWidth = selectElement.style.width;
|
|
42
|
-
selectElement.style.width = 0;
|
|
43
|
-
selectElement.style.width = originalWidth;
|
|
44
|
-
}
|
|
25
|
+
optionNode.selected = isSelected;
|
|
45
26
|
}
|
package/dist/dom/fixes.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/fixes.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// DOM node manipulation\n//\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// DOM node manipulation\n//\n\nexport function fixUpContinuousNodeArray(continuousNodeArray, parentNode) {\n // Before acting on a set of nodes that were previously outputted by a template function, we have to reconcile\n // them against what is in the DOM right now. It may be that some of the nodes have already been removed, or that\n // new nodes might have been inserted in the middle, for example by a binding. Also, there may previously have been\n // leading comment nodes (created by rewritten string-based templates) that have since been removed during binding.\n // So, this function translates the old \"map\" output array into its best guess of the set of current DOM nodes.\n //\n // Rules:\n // [A] Any leading nodes that have been removed should be ignored\n // These most likely correspond to memoization nodes that were already removed during binding\n // See https://github.com/knockout/knockout/pull/440\n // [B] Any trailing nodes that have been remove should be ignored\n // This prevents the code here from adding unrelated nodes to the array while processing rule [C]\n // See https://github.com/knockout/knockout/pull/1903\n // [C] We want to output a continuous series of nodes. So, ignore any nodes that have already been removed,\n // and include any nodes that have been inserted among the previous collection\n\n if (continuousNodeArray.length) {\n // The parent node can be a virtual element; so get the real parent node\n parentNode = (parentNode.nodeType === Node.COMMENT_NODE && parentNode.parentNode) || parentNode\n\n // Rule [A]\n while (continuousNodeArray.length && continuousNodeArray[0].parentNode !== parentNode) {\n continuousNodeArray.splice(0, 1)\n }\n\n // Rule [B]\n while (\n continuousNodeArray.length > 1\n && continuousNodeArray[continuousNodeArray.length - 1].parentNode !== parentNode\n ) {\n continuousNodeArray.length--\n }\n\n // Rule [C]\n if (continuousNodeArray.length > 1) {\n let current = continuousNodeArray[0],\n last = continuousNodeArray[continuousNodeArray.length - 1]\n // Replace with the actual new continuous node set\n continuousNodeArray.length = 0\n while (current !== last) {\n continuousNodeArray.push(current)\n current = current.nextSibling\n }\n continuousNodeArray.push(last)\n }\n }\n return continuousNodeArray\n}\n\nexport function setOptionNodeSelectionState(optionNode, isSelected) {\n optionNode.selected = isSelected\n}\n"],
|
|
5
|
+
"mappings": ";;AAIO,gBAAS,yBAAyB,qBAAqB,YAAY;AAiBxE,MAAI,oBAAoB,QAAQ;AAE9B,iBAAc,WAAW,aAAa,KAAK,gBAAgB,WAAW,cAAe;AAGrF,WAAO,oBAAoB,UAAU,oBAAoB,CAAC,EAAE,eAAe,YAAY;AACrF,0BAAoB,OAAO,GAAG,CAAC;AAAA,IACjC;AAGA,WACE,oBAAoB,SAAS,KAC1B,oBAAoB,oBAAoB,SAAS,CAAC,EAAE,eAAe,YACtE;AACA,0BAAoB;AAAA,IACtB;AAGA,QAAI,oBAAoB,SAAS,GAAG;AAClC,UAAI,UAAU,oBAAoB,CAAC,GACjC,OAAO,oBAAoB,oBAAoB,SAAS,CAAC;AAE3D,0BAAoB,SAAS;AAC7B,aAAO,YAAY,MAAM;AACvB,4BAAoB,KAAK,OAAO;AAChC,kBAAU,QAAQ;AAAA,MACpB;AACA,0BAAoB,KAAK,IAAI;AAAA,IAC/B;AAAA,EACF;AACA,SAAO;AACT;AAEO,gBAAS,4BAA4B,YAAY,YAAY;AAClE,aAAW,WAAW;AACxB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/dom/html.js
CHANGED
|
@@ -1,73 +1,51 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
2
|
-
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
3
3
|
import { makeArray } from "../array";
|
|
4
4
|
import { emptyDomNode, moveCleanedNodesToContainerElement } from "./manipulation";
|
|
5
|
-
import { jQueryInstance } from "../jquery";
|
|
6
|
-
import { forceRefresh } from "./fixes";
|
|
7
5
|
import * as virtualElements from "./virtualElements";
|
|
8
6
|
import options from "../options";
|
|
9
|
-
|
|
10
|
-
"area": map,
|
|
11
|
-
"col": colgroup,
|
|
12
|
-
"colgroup": table,
|
|
13
|
-
"caption": table,
|
|
14
|
-
"legend": fieldset,
|
|
15
|
-
"thead": table,
|
|
16
|
-
"tbody": table,
|
|
17
|
-
"tfoot": table,
|
|
18
|
-
"tr": tbody,
|
|
19
|
-
"td": tr,
|
|
20
|
-
"th": tr,
|
|
21
|
-
"option": select,
|
|
22
|
-
"optgroup": select,
|
|
23
|
-
"param": object
|
|
24
|
-
}, supportsTemplateTag = options.document && "content" in options.document.createElement("template");
|
|
25
|
-
function getWrap(tags) {
|
|
26
|
-
const m = tags.match(/^(?:<!--.*?-->\s*?)*?<([a-z]+)[\s>]/);
|
|
27
|
-
return m && lookup[m[1]] || none;
|
|
28
|
-
}
|
|
7
|
+
const supportsTemplateTag = options.useTemplateTag && options.document && "content" in options.document.createElement("template");
|
|
29
8
|
function simpleHtmlParse(html, documentContext) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var tags = stringTrim(html).toLowerCase(), div = documentContext.createElement("div"), wrap = getWrap(tags), depth = wrap[0];
|
|
33
|
-
var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
|
|
34
|
-
if (typeof windowContext["innerShiv"] === "function") {
|
|
35
|
-
div.appendChild(windowContext["innerShiv"](markup));
|
|
36
|
-
} else {
|
|
37
|
-
div.innerHTML = markup;
|
|
38
|
-
}
|
|
39
|
-
while (depth--) {
|
|
40
|
-
div = div.lastChild;
|
|
9
|
+
if (!documentContext) {
|
|
10
|
+
documentContext = document;
|
|
41
11
|
}
|
|
42
|
-
|
|
12
|
+
const div = documentContext.createElement("div");
|
|
13
|
+
div.innerHTML = html;
|
|
14
|
+
return makeArray(div.childNodes);
|
|
43
15
|
}
|
|
44
16
|
function templateHtmlParse(html, documentContext) {
|
|
45
17
|
if (!documentContext) {
|
|
46
18
|
documentContext = document;
|
|
47
19
|
}
|
|
48
|
-
|
|
20
|
+
const template = documentContext.createElement("template");
|
|
49
21
|
template.innerHTML = html;
|
|
50
22
|
return makeArray(template.content.childNodes);
|
|
51
23
|
}
|
|
52
24
|
function jQueryHtmlParse(html, documentContext) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var elems = jQueryInstance.clean([html], documentContext);
|
|
57
|
-
if (elems && elems[0]) {
|
|
58
|
-
var elem = elems[0];
|
|
59
|
-
while (elem.parentNode && elem.parentNode.nodeType !== 11) {
|
|
60
|
-
elem = elem.parentNode;
|
|
61
|
-
}
|
|
62
|
-
if (elem.parentNode) {
|
|
63
|
-
elem.parentNode.removeChild(elem);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return elems;
|
|
25
|
+
const jQuery = options.jQuery;
|
|
26
|
+
if (jQuery) {
|
|
27
|
+
return jQuery.parseHTML(html, documentContext) || [];
|
|
67
28
|
}
|
|
29
|
+
return [];
|
|
68
30
|
}
|
|
69
31
|
export function parseHtmlFragment(html, documentContext) {
|
|
70
|
-
|
|
32
|
+
const saferHtml = validateHTMLInput(html);
|
|
33
|
+
if (supportsTemplateTag) return templateHtmlParse(saferHtml, documentContext);
|
|
34
|
+
if (options.jQuery) {
|
|
35
|
+
return jQueryHtmlParse(saferHtml, documentContext);
|
|
36
|
+
}
|
|
37
|
+
return simpleHtmlParse(saferHtml, documentContext);
|
|
38
|
+
}
|
|
39
|
+
const scriptTagPattern = /<script\b[^>]*>([\s\S]*?)<\/script[^>]*>/i;
|
|
40
|
+
function validateHTMLInput(html) {
|
|
41
|
+
if (!html) return "";
|
|
42
|
+
if (options.templateSizeLimit > 0 && html.length > options.templateSizeLimit) {
|
|
43
|
+
throw new Error("Template is too long. Please configure the 'templateSizeLimit'");
|
|
44
|
+
}
|
|
45
|
+
if (!options.allowScriptTagsInTemplates && scriptTagPattern.test(html)) {
|
|
46
|
+
throw new Error("Script-tag in template detected.");
|
|
47
|
+
}
|
|
48
|
+
return options.sanitizeHtmlTemplate(html);
|
|
71
49
|
}
|
|
72
50
|
export function parseHtmlForTemplateNodes(html, documentContext) {
|
|
73
51
|
const nodes = parseHtmlFragment(html, documentContext);
|
|
@@ -82,18 +60,25 @@ export function setHtml(node, html) {
|
|
|
82
60
|
if (typeof html !== "string") {
|
|
83
61
|
html = html.toString();
|
|
84
62
|
}
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
const jQuery = options.jQuery;
|
|
64
|
+
if (jQuery && !supportsTemplateTag) {
|
|
65
|
+
const saferHtml = validateHTMLInput(html);
|
|
66
|
+
jQuery(node).html(saferHtml);
|
|
87
67
|
} else {
|
|
88
|
-
|
|
89
|
-
if (node.
|
|
68
|
+
let parsedNodes;
|
|
69
|
+
if (node.ownerDocument) {
|
|
70
|
+
parsedNodes = parseHtmlFragment(html, node.ownerDocument);
|
|
71
|
+
} else {
|
|
72
|
+
parsedNodes = parseHtmlFragment(html);
|
|
73
|
+
}
|
|
74
|
+
if (node.nodeType === Node.COMMENT_NODE) {
|
|
90
75
|
if (html === null) {
|
|
91
76
|
virtualElements.emptyNode(node);
|
|
92
77
|
} else {
|
|
93
78
|
virtualElements.setDomNodeChildren(node, parsedNodes);
|
|
94
79
|
}
|
|
95
80
|
} else {
|
|
96
|
-
for (
|
|
81
|
+
for (let i = 0; i < parsedNodes.length; i++) {
|
|
97
82
|
node.appendChild(parsedNodes[i]);
|
|
98
83
|
}
|
|
99
84
|
}
|
|
@@ -101,15 +86,15 @@ export function setHtml(node, html) {
|
|
|
101
86
|
}
|
|
102
87
|
}
|
|
103
88
|
export function setTextContent(element, textContent) {
|
|
104
|
-
|
|
89
|
+
let value = typeof textContent === "function" ? textContent() : textContent;
|
|
105
90
|
if (value === null || value === void 0) {
|
|
106
91
|
value = "";
|
|
107
92
|
}
|
|
108
|
-
|
|
109
|
-
if (!innerTextNode || innerTextNode.nodeType
|
|
93
|
+
const innerTextNode = virtualElements.firstChild(element);
|
|
94
|
+
if (!innerTextNode || innerTextNode.nodeType !== Node.TEXT_NODE || virtualElements.nextSibling(innerTextNode)) {
|
|
110
95
|
virtualElements.setDomNodeChildren(element, [element.ownerDocument.createTextNode(value)]);
|
|
111
96
|
} else {
|
|
97
|
+
;
|
|
112
98
|
innerTextNode.data = value;
|
|
113
99
|
}
|
|
114
|
-
forceRefresh(element);
|
|
115
100
|
}
|
package/dist/dom/html.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/html.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// HTML-based manipulation\n//\nimport {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// HTML-based manipulation\n//\nimport { makeArray } from '../array'\nimport { emptyDomNode, moveCleanedNodesToContainerElement } from './manipulation'\nimport * as virtualElements from './virtualElements'\nimport options from '../options'\n\n// The canonical way to test that the HTML5 <template> tag is supported\nconst supportsTemplateTag =\n options.useTemplateTag && options.document && 'content' in options.document.createElement('template')\n\n/** @deprecated HTMLTemplateTag or the jquery-template-function as fallback are enough */\nfunction simpleHtmlParse(html: string, documentContext?: Document): Node[] {\n if (!documentContext) {\n documentContext = document\n }\n const div = documentContext.createElement('div')\n div.innerHTML = html\n return makeArray(div.childNodes)\n}\n\nfunction templateHtmlParse(html: string, documentContext?: Document): Node[] {\n if (!documentContext) {\n documentContext = document\n }\n const template = documentContext.createElement('template') as HTMLTemplateElement\n template.innerHTML = html\n return makeArray(template.content.childNodes)\n}\n\nfunction jQueryHtmlParse(html: string, documentContext?: Document): Node[] {\n const jQuery = options.jQuery\n\n // jQuery's \"parseHTML\" function was introduced in jQuery 1.8.0 and is a documented public API.\n if (jQuery) {\n return jQuery.parseHTML(html, documentContext) || [] // Ensure we always return an array and never null\n }\n\n return []\n}\n\n/**\n * parseHtmlFragment converts a string into an array of DOM Nodes.\n * If supported, it uses <template>-tag parsing, falling back on\n * jQuery parsing (if jQuery is present), and finally on a\n * straightforward parser.\n *\n * @param {string} html To be parsed.\n * @param {Document} documentContext That owns the executing code.\n * @return {[Node]} Parsed DOM Nodes\n */\nexport function parseHtmlFragment(html: string, documentContext?: Document): Node[] {\n const saferHtml = validateHTMLInput(html)\n\n // Prefer <template>-tag based HTML parsing.\n if (supportsTemplateTag) return templateHtmlParse(saferHtml, documentContext)\n\n //TODO: It is always true in modern browsers (higher IE11), so we can theoretically remove jQueryHtmlParse and simpleHtmlParse\n if (options.jQuery) {\n // Benefit from jQuery's on old browsers, where possible\n // NOTE: jQuery's HTML parsing fails on element names like tr-*.\n // See: https://github.com/jquery/jquery/pull/1988\n return jQueryHtmlParse(saferHtml, documentContext)\n }\n\n return simpleHtmlParse(saferHtml, documentContext)\n}\n\nconst scriptTagPattern = /<script\\b[^>]*>([\\s\\S]*?)<\\/script[^>]*>/i\nfunction validateHTMLInput(html: string): string {\n if (!html) return ''\n\n if (options.templateSizeLimit > 0 && html.length > options.templateSizeLimit) {\n throw new Error(\"Template is too long. Please configure the 'templateSizeLimit'\")\n }\n\n if (!options.allowScriptTagsInTemplates && scriptTagPattern.test(html)) {\n throw new Error('Script-tag in template detected.')\n }\n\n return options.sanitizeHtmlTemplate(html)\n}\n\nexport function parseHtmlForTemplateNodes(html, documentContext) {\n const nodes = parseHtmlFragment(html, documentContext)\n return (nodes.length && nodes[0].parentElement) || moveCleanedNodesToContainerElement(nodes)\n}\n\n/**\n * setHtml empties the node's contents, unwraps the HTML, and\n * sets the node's HTML using jQuery.html or parseHtmlFragment\n *\n * @param {DOMNode} node Node in which HTML needs to be set\n * @param {DOMNode} html HTML to be inserted in node\n * @returns undefined\n */\nexport function setHtml(node: Node, html: Function | string) {\n emptyDomNode(node)\n\n // There's few cases where we would want to display a stringified\n // function, so we unwrap it.\n if (typeof html === 'function') {\n html = html()\n }\n\n if (html !== null && html !== undefined) {\n if (typeof html !== 'string') {\n html = html.toString()\n }\n\n const jQuery = options.jQuery\n // If the browser supports <template> tags, prefer that, as\n // it obviates all the complex workarounds of jQuery.\n //\n // However, jQuery contains a lot of sophisticated code to parse arbitrary HTML fragments,\n // for example <tr> elements which are not normally allowed to exist on their own.\n // If you've referenced jQuery (and template tags are not supported) we'll use that rather than duplicating its code.\n if (jQuery && !supportsTemplateTag) {\n const saferHtml = validateHTMLInput(html)\n jQuery(node).html(saferHtml)\n } else {\n // ... otherwise, use KO's own parsing logic.\n let parsedNodes: Node[]\n if (node.ownerDocument) {\n parsedNodes = parseHtmlFragment(html, node.ownerDocument)\n } else {\n parsedNodes = parseHtmlFragment(html)\n }\n\n if (node.nodeType === Node.COMMENT_NODE) {\n if (html === null) {\n virtualElements.emptyNode(node)\n } else {\n virtualElements.setDomNodeChildren(node, parsedNodes)\n }\n } else {\n for (let i = 0; i < parsedNodes.length; i++) {\n node.appendChild(parsedNodes[i])\n }\n }\n }\n }\n}\n\n//TODO May be MaybeSubscribable<string> -> I actually don't want the dependency\ntype TextContent = string | null | undefined | Function\nexport function setTextContent(element: Node, textContent?: TextContent): void {\n let value = typeof textContent === 'function' ? (textContent as Function)() : textContent\n if (value === null || value === undefined) {\n value = ''\n }\n\n // We need there to be exactly one child: a text node.\n // If there are no children, more than one, or if it's not a text node,\n // we'll clear everything and create a single text node.\n const innerTextNode = virtualElements.firstChild(element)\n if (!innerTextNode || innerTextNode.nodeType !== Node.TEXT_NODE || virtualElements.nextSibling(innerTextNode)) {\n virtualElements.setDomNodeChildren(element, [element.ownerDocument!.createTextNode(value)])\n } else {\n ;(innerTextNode as Text).data = value\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAGA,SAAS,iBAAiB;AAC1B,SAAS,cAAc,0CAA0C;AACjE,YAAY,qBAAqB;AACjC,OAAO,aAAa;AAGpB,MAAM,sBACJ,QAAQ,kBAAkB,QAAQ,YAAY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AAO;AAAA,EAClC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/dom/info.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
2
3
|
import { arrayFirst } from "../array";
|
|
3
4
|
export function domNodeIsContainedBy(node, containedByNode) {
|
|
4
5
|
if (node === containedByNode) {
|
|
5
6
|
return true;
|
|
6
7
|
}
|
|
7
|
-
if (node.nodeType ===
|
|
8
|
+
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
8
9
|
return false;
|
|
9
10
|
}
|
|
10
11
|
if (containedByNode.contains) {
|
|
11
|
-
return containedByNode.contains(node.nodeType !==
|
|
12
|
+
return containedByNode.contains(node.nodeType !== Node.ELEMENT_NODE ? node.parentNode : node);
|
|
12
13
|
}
|
|
13
14
|
if (containedByNode.compareDocumentPosition) {
|
|
14
15
|
return (containedByNode.compareDocumentPosition(node) & 16) == 16;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
let parentNode = node;
|
|
18
|
+
while (parentNode && parentNode != containedByNode) {
|
|
19
|
+
parentNode = parentNode.parentNode;
|
|
18
20
|
}
|
|
19
|
-
return !!
|
|
21
|
+
return !!parentNode;
|
|
20
22
|
}
|
|
21
23
|
export function domNodeIsAttachedToDocument(node) {
|
|
22
24
|
return domNodeIsContainedBy(node, node.ownerDocument.documentElement);
|
|
@@ -31,13 +33,13 @@ export function isDomElement(obj) {
|
|
|
31
33
|
if (window.HTMLElement) {
|
|
32
34
|
return obj instanceof HTMLElement;
|
|
33
35
|
} else {
|
|
34
|
-
return obj && obj.tagName && obj.nodeType ===
|
|
36
|
+
return obj && obj.tagName && obj.nodeType === Node.ELEMENT_NODE;
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
export function isDocumentFragment(obj) {
|
|
38
40
|
if (window.DocumentFragment) {
|
|
39
41
|
return obj instanceof DocumentFragment;
|
|
40
42
|
} else {
|
|
41
|
-
return obj && obj.nodeType ===
|
|
43
|
+
return obj && obj.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
|
|
42
44
|
}
|
|
43
45
|
}
|
package/dist/dom/info.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/info.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Information about the DOM\n//\nimport { arrayFirst } from '../array'\n\nexport function domNodeIsContainedBy
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// Information about the DOM\n//\nimport { arrayFirst } from '../array'\n\nexport function domNodeIsContainedBy(node: Node, containedByNode: Node) {\n if (node === containedByNode) {\n return true\n }\n if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n return false\n } // Fixes issue #1162 - can't use node.contains for document fragments on IE8\n if (containedByNode.contains) {\n return containedByNode.contains(node.nodeType !== Node.ELEMENT_NODE ? node.parentNode : node)\n }\n if (containedByNode.compareDocumentPosition) {\n return (containedByNode.compareDocumentPosition(node) & 16) == 16\n }\n\n let parentNode: Node | null = node\n while (parentNode && parentNode != containedByNode) {\n parentNode = parentNode.parentNode\n }\n return !!parentNode\n}\n\nexport function domNodeIsAttachedToDocument(node) {\n return domNodeIsContainedBy(node, node.ownerDocument.documentElement)\n}\n\nexport function anyDomNodeIsAttachedToDocument(nodes) {\n return !!arrayFirst(nodes, domNodeIsAttachedToDocument)\n}\n\nexport function tagNameLower(element: Element) {\n // For HTML elements, tagName will always be upper case; for XHTML elements, it'll be lower case.\n // Possible future optimization: If we know it's an element from an XHTML document (not HTML),\n // we don't need to do the .toLowerCase() as it will always be lower case anyway.\n return element && element.tagName && element.tagName.toLowerCase()\n}\n\nexport function isDomElement(obj) {\n if (window.HTMLElement) {\n return obj instanceof HTMLElement\n } else {\n return obj && obj.tagName && obj.nodeType === Node.ELEMENT_NODE\n }\n}\n\nexport function isDocumentFragment(obj) {\n if (window.DocumentFragment) {\n return obj instanceof DocumentFragment\n } else {\n return obj && obj.nodeType === Node.DOCUMENT_FRAGMENT_NODE\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAGA,SAAS,kBAAkB;AAEpB,gBAAS,qBAAqB,MAAY,iBAAuB;AACtE,MAAI,SAAS,iBAAiB;AAC5B,WAAO;AAAA,EACT;AACA,MAAI,KAAK,aAAa,KAAK,wBAAwB;AACjD,WAAO;AAAA,EACT;AACA,MAAI,gBAAgB,UAAU;AAC5B,WAAO,gBAAgB,SAAS,KAAK,aAAa,KAAK,eAAe,KAAK,aAAa,IAAI;AAAA,EAC9F;AACA,MAAI,gBAAgB,yBAAyB;AAC3C,YAAQ,gBAAgB,wBAAwB,IAAI,IAAI,OAAO;AAAA,EACjE;AAEA,MAAI,aAA0B;AAC9B,SAAO,cAAc,cAAc,iBAAiB;AAClD,iBAAa,WAAW;AAAA,EAC1B;AACA,SAAO,CAAC,CAAC;AACX;AAEO,gBAAS,4BAA4B,MAAM;AAChD,SAAO,qBAAqB,MAAM,KAAK,cAAc,eAAe;AACtE;AAEO,gBAAS,+BAA+B,OAAO;AACpD,SAAO,CAAC,CAAC,WAAW,OAAO,2BAA2B;AACxD;AAEO,gBAAS,aAAa,SAAkB;AAI7C,SAAO,WAAW,QAAQ,WAAW,QAAQ,QAAQ,YAAY;AACnE;AAEO,gBAAS,aAAa,KAAK;AAChC,MAAI,OAAO,aAAa;AACtB,WAAO,eAAe;AAAA,EACxB,OAAO;AACL,WAAO,OAAO,IAAI,WAAW,IAAI,aAAa,KAAK;AAAA,EACrD;AACF;AAEO,gBAAS,mBAAmB,KAAK;AACtC,MAAI,OAAO,kBAAkB;AAC3B,WAAO,eAAe;AAAA,EACxB,OAAO;AACL,WAAO,OAAO,IAAI,aAAa,KAAK;AAAA,EACtC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/dom/manipulation.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
2
3
|
import { makeArray } from "../array";
|
|
3
|
-
import { ieVersion } from "../ie";
|
|
4
4
|
import { cleanNode, removeNode } from "./disposal";
|
|
5
5
|
export function moveCleanedNodesToContainerElement(nodes) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
for (
|
|
6
|
+
const nodesArray = makeArray(nodes);
|
|
7
|
+
const templateDocument = nodesArray[0] && nodesArray[0].ownerDocument || document;
|
|
8
|
+
const container = templateDocument.createElement("div");
|
|
9
|
+
for (let i = 0, j = nodesArray.length; i < j; i++) {
|
|
10
10
|
container.appendChild(cleanNode(nodesArray[i]));
|
|
11
11
|
}
|
|
12
12
|
return container;
|
|
13
13
|
}
|
|
14
14
|
export function cloneNodes(nodesArray, shouldCleanNodes) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const newNodesArray = new Array();
|
|
16
|
+
for (let i = 0; i < nodesArray.length; i++) {
|
|
17
|
+
const clonedNode = nodesArray[i].cloneNode(true);
|
|
17
18
|
newNodesArray.push(shouldCleanNodes ? cleanNode(clonedNode) : clonedNode);
|
|
18
19
|
}
|
|
19
20
|
return newNodesArray;
|
|
@@ -21,33 +22,24 @@ export function cloneNodes(nodesArray, shouldCleanNodes) {
|
|
|
21
22
|
export function setDomNodeChildren(domNode, childNodes) {
|
|
22
23
|
emptyDomNode(domNode);
|
|
23
24
|
if (childNodes) {
|
|
24
|
-
for (
|
|
25
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
25
26
|
domNode.appendChild(childNodes[i]);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
export function replaceDomNodes(nodeToReplaceOrNodeArray, newNodesArray) {
|
|
30
|
-
|
|
31
|
+
const nodesToReplaceArray = Array.isArray(nodeToReplaceOrNodeArray) ? nodeToReplaceOrNodeArray : [nodeToReplaceOrNodeArray];
|
|
31
32
|
if (nodesToReplaceArray.length > 0) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
for (
|
|
35
|
-
parent
|
|
33
|
+
const insertionPoint = nodesToReplaceArray[0];
|
|
34
|
+
const parent = insertionPoint.parentNode;
|
|
35
|
+
for (let i = 0; i < newNodesArray.length; i++) {
|
|
36
|
+
parent?.insertBefore(newNodesArray[i], insertionPoint);
|
|
36
37
|
}
|
|
37
|
-
for (i = 0
|
|
38
|
+
for (let i = 0; i < nodesToReplaceArray.length; i++) {
|
|
38
39
|
removeNode(nodesToReplaceArray[i]);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
export function setElementName(element, name) {
|
|
43
|
-
element.name = name;
|
|
44
|
-
if (ieVersion <= 7) {
|
|
45
|
-
try {
|
|
46
|
-
element.mergeAttributes(document.createElement("<input name='" + element.name + "'/>"), false);
|
|
47
|
-
} catch (e) {
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
43
|
export function emptyDomNode(domNode) {
|
|
52
44
|
while (domNode.firstChild) {
|
|
53
45
|
removeNode(domNode.firstChild);
|