@tko/binding.core 4.0.0-alpha9.0 → 4.0.0-beta1.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/attr.js +36 -0
- package/dist/attr.js.map +7 -0
- package/dist/checked.js +94 -0
- package/dist/checked.js.map +7 -0
- package/dist/click.js +5 -0
- package/dist/click.js.map +7 -0
- package/dist/css.js +28 -0
- package/dist/css.js.map +7 -0
- package/dist/descendantsComplete.js +14 -0
- package/dist/descendantsComplete.js.map +7 -0
- package/dist/enableDisable.js +21 -0
- package/dist/enableDisable.js.map +7 -0
- package/dist/event.js +75 -0
- package/dist/event.js.map +7 -0
- package/dist/hasfocus.js +48 -0
- package/dist/hasfocus.js.map +7 -0
- package/dist/html.js +15 -0
- package/dist/html.js.map +7 -0
- package/dist/index.cjs +3956 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +50 -0
- package/dist/index.mjs.map +7 -0
- package/dist/let.js +12 -0
- package/dist/let.js.map +7 -0
- package/dist/options.js +130 -0
- package/dist/options.js.map +7 -0
- package/dist/selectedOptions.js +41 -0
- package/dist/selectedOptions.js.map +7 -0
- package/dist/style.js +30 -0
- package/dist/style.js.map +7 -0
- package/dist/submit.js +26 -0
- package/dist/submit.js.map +7 -0
- package/dist/test-helper.js +14 -0
- package/dist/test-helper.js.map +7 -0
- package/dist/text.js +13 -0
- package/dist/text.js.map +7 -0
- package/dist/textInput.js +151 -0
- package/dist/textInput.js.map +7 -0
- package/dist/uniqueName.js +13 -0
- package/dist/uniqueName.js.map +7 -0
- package/dist/using.js +12 -0
- package/dist/using.js.map +7 -0
- package/dist/value.js +103 -0
- package/dist/value.js.map +7 -0
- package/dist/visible.js +20 -0
- package/dist/visible.js.map +7 -0
- package/package.json +18 -28
- package/dist/binding.core.es6.js +0 -1044
- package/dist/binding.core.es6.js.map +0 -1
- package/dist/binding.core.js +0 -1146
- package/dist/binding.core.js.map +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/textInput.ts"],
|
|
4
|
+
"sourcesContent": ["\nimport {\n domData, registerEventHandler, ieVersion, safeSetTimeout, options,\n arrayForEach, tagNameLower\n} from '@tko/utils'\n\nimport {\n unwrap\n} from '@tko/observable'\n\nimport {\n computed\n} from '@tko/computed'\n\nimport {\n BindingHandler\n} from '@tko/bind'\n\nvar parseVersion, operaVersion, safariVersion, firefoxVersion\n\n\n/**\n * TextInput binding handler for modern browsers (legacy below).\n * @extends BindingHandler\n */\nclass TextInput extends BindingHandler {\n get aliases () { return 'textinput' }\n\n constructor (...args) {\n super(...args)\n this.previousElementValue = this.$element.value\n\n if (options.debug && this.constructor._forceUpdateOn) {\n // Provide a way for tests to specify exactly which events are bound\n arrayForEach(this.constructor._forceUpdateOn, (eventName) => {\n if (eventName.slice(0, 5) === 'after') {\n this.addEventListener(eventName.slice(5), 'deferUpdateModel')\n } else {\n this.addEventListener(eventName, 'updateModel')\n }\n })\n }\n\n for (const eventName of this.eventsIndicatingSyncValueChange()) {\n this.addEventListener(eventName, 'updateModel')\n }\n for (const eventName of this.eventsIndicatingDeferValueChange()) {\n this.addEventListener(eventName, 'deferUpdateModel')\n }\n this.computed('updateView')\n }\n\n eventsIndicatingSyncValueChange () {\n // input: Default, modern handler\n // change: Catch programmatic updates of the value that fire this event.\n // blur: To deal with browsers that don't notify any kind of event for some changes (IE, Safari, etc.)\n return ['input', 'change', 'blur']\n }\n\n eventsIndicatingDeferValueChange () {\n return []\n }\n\n updateModel (event) {\n const element = this.$element\n clearTimeout(this.timeoutHandle)\n this.elementValueBeforeEvent = this.timeoutHandle = undefined\n const elementValue = element.value\n if (this.previousElementValue !== elementValue) {\n // Provide a way for tests to know exactly which event was processed\n if (options.debug && event) {\n element._ko_textInputProcessedEvent = event.type\n }\n this.previousElementValue = elementValue\n this.value = elementValue\n }\n }\n\n deferUpdateModel (event) {\n const element = this.$element\n if (!this.timeoutHandle) {\n // The elementValueBeforeEvent variable is set *only* during the brief gap between an\n // event firing and the updateModel function running. This allows us to ignore model\n // updates that are from the previous state of the element, usually due to techniques\n // such as rateLimit. Such updates, if not ignored, can cause keystrokes to be lost.\n this.elementValueBeforeEvent = element.value\n const handler = options.debug ? this.updateModel.bind(this, { type: event.type }) : this.updateModel\n this.timeoutHandle = safeSetTimeout(handler, 4)\n }\n }\n\n updateView () {\n let modelValue = unwrap(this.value)\n if (modelValue === null || modelValue === undefined) {\n modelValue = ''\n }\n if (this.elementValueBeforeEvent !== undefined\n && modelValue === this.elementValueBeforeEvent) {\n setTimeout(this.updateView.bind(this), 4)\n } else if (this.$element.value !== modelValue) {\n // Update the element only if the element and model are different. On some browsers, updating the value\n // will move the cursor to the end of the input, which would be bad while the user is typing.\n this.previousElementValue = modelValue // Make sure we ignore events (propertychange) that result from updating the value\n this.$element.value = modelValue\n this.previousElementValue = this.$element.value // In case the browser changes the value (see #2281)\n }\n }\n}\n\n/**\n * Legacy Input Classes, below\n */\nclass TextInputIE extends TextInput {\n constructor (...args) {\n super(...args)\n\n if (ieVersion < 11) {\n // Internet Explorer <= 8 doesn't support the 'input' event, but does include 'propertychange' that fires whenever\n // any property of an element changes. Unlike 'input', it also fires if a property is changed from JavaScript code,\n // but that's an acceptable compromise for this binding. IE 9 and 10 support 'input', but since they don't always\n // fire it when using autocomplete, we'll use 'propertychange' for them also.\n this.addEventListener('propertychange', event =>\n event.propertyName === 'value' && this.updateModel(event)\n )\n }\n\n if (ieVersion >= 8 && ieVersion < 10) {\n this.watchForSelectionChangeEvent()\n this.addEventListener('dragend', 'deferUpdateModel')\n }\n }\n\n eventsIndicatingSyncValueChange () {\n // keypress: All versions (including 11) of Internet Explorer have a bug that they don't generate an input or propertychange event when ESC is pressed\n return [...super.eventsIndicatingValueChange(), 'keypress']\n }\n\n // IE 8 and 9 have bugs that prevent the normal events from firing when the value changes.\n // But it does fire the 'selectionchange' event on many of those, presumably because the\n // cursor is moving and that counts as the selection changing. The 'selectionchange' event is\n // fired at the document level only and doesn't directly indicate which element changed. We\n // set up just one event handler for the document and use 'activeElement' to determine which\n // element was changed.\n selectionChangeHandler (event) {\n const target = this.activeElement\n const handler = target && domData.get(target, selectionChangeHandlerName)\n if (handler) { handler(event) }\n }\n\n watchForSelectionChangeEvent (element, ieUpdateModel) {\n const ownerDoc = element.ownerDocument;\n if (!domData.get(ownerDoc, selectionChangeRegisteredName)) {\n domData.set(ownerDoc, selectionChangeRegisteredName, true)\n registerEventHandler(ownerDoc, 'selectionchange', this.selectionChangeHandler.bind(ownerDoc))\n }\n domData.set(element, selectionChangeHandlerName, handler)\n }\n}\n\n\n// IE 8 and 9 have bugs that prevent the normal events from firing when the value changes.\n// But it does fire the 'selectionchange' event on many of those, presumably because the\n// cursor is moving and that counts as the selection changing. The 'selectionchange' event is\n// fired at the document level only and doesn't directly indicate which element changed. We\n// set up just one event handler for the document and use 'activeElement' to determine which\n// element was changed.\nclass TextInputIE9 extends TextInputIE {\n updateModel (...args) {\n // IE9 will mess up the DOM if you handle events synchronously which results in DOM changes (such as other bindings);\n // so we'll make sure all updates are asynchronous\n this.deferUpdateModel(...args)\n }\n}\n\n\nclass TextInputIE8 extends TextInputIE {\n eventsIndicatingValueChange () {\n // IE 8 has a bug where it fails to fire 'propertychange' on the first update following a value change from\n // JavaScript code. It also doesn't fire if you clear the entire value. To fix this, we bind to the following\n // events too.\n // keypress: All versions (including 11) of Internet Explorer have a bug that they don't generate an input or propertychange event when ESC is pressed\n // keyup: A single keystoke\n // keydown: First character when a key is held down\n return [...super.eventsIndicatingValueChange(), 'keyup', 'keydown']\n }\n}\n\n\n// Safari <5 doesn't fire the 'input' event for <textarea> elements (it does fire 'textInput'\n// but only when typing). So we'll just catch as much as we can with keydown, cut, and paste.\nclass TextInputLegacySafari extends TextInput {\n eventsIndicatingDeferValueChange () {\n return ['keydown', 'paste', 'cut']\n }\n}\n\n\nclass TextInputLegacyOpera extends TextInput {\n eventsIndicatingDeferValueChange () {\n // Opera 10 doesn't always fire the 'input' event for cut, paste, undo & drop operations.\n // We can try to catch some of those using 'keydown'.\n return ['keydown']\n }\n}\n\n\nclass TextInputLegacyFirefox extends TextInput {\n eventsIndicatingValueChange () {\n return [\n ...super.eventsIndicatingSyncValueChange(),\n // Firefox <= 3.6 doesn't fire the 'input' event when text is filled in through autocomplete\n 'DOMAutoComplete',\n // Firefox <=3.5 doesn't fire the 'input' event when text is dropped into the input.\n 'dragdrop', // < 3.5\n 'drop' // 3.5\n ]\n }\n}\n\n\nconst w = options.global // window / global\nif (w.navigator) {\n const parseVersion = (matches) => matches && parseFloat(matches[1])\n const userAgent = w.navigator.userAgent\n const isChrome = userAgent.match(/Chrome\\/([^ ]+)/)\n // Detect various browser versions because some old versions don't fully support the 'input' event\n operaVersion = w.opera && w.opera.version && parseInt(w.opera.version())\n safariVersion = parseVersion(userAgent.match(/Version\\/([^ ]+) Safari/))\n firefoxVersion = parseVersion(userAgent.match(/Firefox\\/([^ ]*)/))\n}\n\n\nexport const textInput =\n ieVersion === 8 ? TextInputIE8\n : ieVersion === 9 ? TextInputIE9\n : ieVersion ? TextInputIE\n : safariVersion && safariVersion < 5 ? TextInputLegacySafari\n : operaVersion < 11 ? TextInputLegacyOpera\n : firefoxVersion && firefoxVersion < 4 ? TextInputLegacyFirefox\n : TextInput\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAQA;AAAA;AAAA;AAIA,IAAI,cAAc,cAAc,eAAe;AAO/C,MAAM,kBAAkB,eAAe;AAAA,MACjC,UAAW;AAAE,WAAO;AAAA,EAAY;AAAA,EAEpC,eAAgB,MAAM;AACpB,UAAM,GAAG,IAAI;AACb,SAAK,uBAAuB,KAAK,SAAS;AAE1C,QAAI,QAAQ,SAAS,KAAK,YAAY,gBAAgB;AAEpD,mBAAa,KAAK,YAAY,gBA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B;AAO7B,WAAO,CAAC,GAAG,MAAM,4BAA4B,GAAG,SAAS,SAAS;AAAA,EACpE;AACF;AAKA,MAAM,8BAA8B,UAAU;AAAA,EAC5C,mCAAoC;AAClC,WAAO,CAAC,WAAW,SAAS,KAAK;AAAA,EACnC;AACF;AAGA,MAAM,6BAA6B,UAAU;AAAA,EAC3C,mCAAoC;AAGlC,WAAO,CAAC,SAAS;AAAA,EACnB;AACF;AAGA,MAAM,+BAA+B,UAAU;AAAA,EAC7C,8BAA+B;AAC7B,WAAO;AAAA,MACL,GAAG,MAAM,gCAAgC;AAAA,MAEzC;AAAA,MAEA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAGA,MAAM,IAAI,QAAQ;AAClB,IAAI,EAAE,WAAW;AACf,QAAM,gBAAe,CAAC,YAAY,WAAW,WAAW,QAAQ,EAAE;AAClE,QAAM,YAAY,EAAE,UAAU;AAC9B,QAAM,WAAW,UAAU,MAAM,iBAAiB;AAElD,iBAAe,EAAE,SAAS,EAAE,MAAM,WAAW,SAAS,EAAE,MAAM,QAAQ,CAAC;AACvE,kBAAgB,cAAa,UAAU,MAAM,yBAAyB,CAAC;AACvE,mBAAiB,cAAa,UAAU,MAAM,kBAAkB,CAAC;AACnE;AAGO,aAAM,YACX,cAAc,IAAI,eAChB,cAAc,IAAI,eAClB,YAAY,cACZ,iBAAiB,gBAAgB,IAAI,wBACrC,eAAe,KAAK,uBACpB,kBAAkB,iBAAiB,IAAI,yBACvC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @tko/binding.core 🥊 4.0.0-beta1.0 ESM
|
|
2
|
+
import {
|
|
3
|
+
setElementName
|
|
4
|
+
} from "@tko/utils";
|
|
5
|
+
export var uniqueName = {
|
|
6
|
+
init: function(element, valueAccessor) {
|
|
7
|
+
if (valueAccessor()) {
|
|
8
|
+
var name = "ko_unique_" + ++uniqueName.currentIndex;
|
|
9
|
+
setElementName(element, name);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
currentIndex: 0
|
|
13
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/uniqueName.ts"],
|
|
4
|
+
"sourcesContent": ["\nimport {\n setElementName\n} from '@tko/utils'\n\nexport var uniqueName = {\n init: function (element, valueAccessor) {\n if (valueAccessor()) {\n var name = 'ko_unique_' + (++uniqueName.currentIndex)\n setElementName(element, name)\n }\n },\n currentIndex: 0\n}\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA;AAAA;AAIO,WAAI,aAAa;AAAA,EACtB,MAAM,SAAU,SAAS,eAAe;AACtC,QAAI,cAAc,GAAG;AACnB,UAAI,OAAO,eAAgB,EAAE,WAAW;AACxC,qBAAe,SAAS,IAAI;AAAA,IAC9B;AAAA,EACF;AAAA,EACA,cAAc;AAChB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/using.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @tko/binding.core 🥊 4.0.0-beta1.0 ESM
|
|
2
|
+
import {
|
|
3
|
+
applyBindingsToDescendants
|
|
4
|
+
} from "@tko/bind";
|
|
5
|
+
export var using = {
|
|
6
|
+
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
|
|
7
|
+
var innerContext = bindingContext.createChildContext(valueAccessor);
|
|
8
|
+
applyBindingsToDescendants(innerContext, element);
|
|
9
|
+
return { controlsDescendantBindings: true };
|
|
10
|
+
},
|
|
11
|
+
allowVirtualElements: true
|
|
12
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/using.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n applyBindingsToDescendants\n} from '@tko/bind'\n\nexport var using = {\n init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {\n var innerContext = bindingContext.createChildContext(valueAccessor)\n applyBindingsToDescendants(innerContext, element)\n return { controlsDescendantBindings: true }\n },\n allowVirtualElements: true\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA;AAAA;AAIO,WAAI,QAAQ;AAAA,EACjB,MAAM,SAAU,SAAS,eAAe,aAAa,WAAW,gBAAgB;AAC9E,QAAI,eAAe,eAAe,mBAAmB,aAAa;AAClE,+BAA2B,cAAc,OAAO;AAChD,WAAO,EAAE,4BAA4B,KAAK;AAAA,EAC5C;AAAA,EACA,sBAAsB;AACxB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/value.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// @tko/binding.core 🥊 4.0.0-beta1.0 ESM
|
|
2
|
+
import {
|
|
3
|
+
ieVersion,
|
|
4
|
+
stringStartsWith,
|
|
5
|
+
safeSetTimeout,
|
|
6
|
+
tagNameLower,
|
|
7
|
+
arrayForEach,
|
|
8
|
+
selectExtensions
|
|
9
|
+
} from "@tko/utils";
|
|
10
|
+
import {
|
|
11
|
+
unwrap,
|
|
12
|
+
dependencyDetection
|
|
13
|
+
} from "@tko/observable";
|
|
14
|
+
import {
|
|
15
|
+
applyBindingAccessorsToNode,
|
|
16
|
+
BindingHandler
|
|
17
|
+
} from "@tko/bind";
|
|
18
|
+
export class value extends BindingHandler {
|
|
19
|
+
static get after() {
|
|
20
|
+
return ["options", "foreach", "template"];
|
|
21
|
+
}
|
|
22
|
+
constructor(...args) {
|
|
23
|
+
super(...args);
|
|
24
|
+
if (this.isCheckboxOrRadio) {
|
|
25
|
+
applyBindingAccessorsToNode(this.$element, { checkedValue: this.valueAccessor });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.propertyChangedFired = false;
|
|
29
|
+
this.elementValueBeforeEvent = null;
|
|
30
|
+
if (this.ieAutoCompleteHackNeeded) {
|
|
31
|
+
this.addEventListener("propertyChange", () => this.propertyChangedFired = true);
|
|
32
|
+
this.addEventListener("focus", () => this.propertyChangedFired = false);
|
|
33
|
+
this.addEventListener("blur", () => this.propertyChangeFired && this.valueUpdateHandler());
|
|
34
|
+
}
|
|
35
|
+
arrayForEach(this.eventsToCatch, (eventName) => this.registerEvent(eventName));
|
|
36
|
+
if (this.isInput && this.$element.type === "file") {
|
|
37
|
+
this.updateFromModel = this.updateFromModelForFile;
|
|
38
|
+
} else {
|
|
39
|
+
this.updateFromModel = this.updateFromModelForValue;
|
|
40
|
+
}
|
|
41
|
+
this.computed("updateFromModel");
|
|
42
|
+
}
|
|
43
|
+
get eventsToCatch() {
|
|
44
|
+
const requestedEventsToCatch = this.allBindings.get("valueUpdate");
|
|
45
|
+
const requestedEventsArray = typeof requestedEventsToCatch === "string" ? [requestedEventsToCatch] : requestedEventsToCatch || [];
|
|
46
|
+
return [.../* @__PURE__ */ new Set(["change", ...requestedEventsArray])];
|
|
47
|
+
}
|
|
48
|
+
get isInput() {
|
|
49
|
+
return tagNameLower(this.$element) === "input";
|
|
50
|
+
}
|
|
51
|
+
get isCheckboxOrRadio() {
|
|
52
|
+
const e = this.$element;
|
|
53
|
+
return this.isInput && (e.type == "checkbox" || e.type == "radio");
|
|
54
|
+
}
|
|
55
|
+
get ieAutoCompleteHackNeeded() {
|
|
56
|
+
return ieVersion && isInputElement && this.$element.type == "text" && this.$element.autocomplete != "off" && (!this.$element.form || this.$element.form.autocomplete != "off");
|
|
57
|
+
}
|
|
58
|
+
valueUpdateHandler() {
|
|
59
|
+
this.elementValueBeforeEvent = null;
|
|
60
|
+
this.propertyChangedFired = false;
|
|
61
|
+
this.value = selectExtensions.readValue(this.$element);
|
|
62
|
+
}
|
|
63
|
+
registerEvent(eventName) {
|
|
64
|
+
var handler = this.valueUpdateHandler.bind(this);
|
|
65
|
+
if (stringStartsWith(eventName, "after")) {
|
|
66
|
+
handler = () => {
|
|
67
|
+
this.elementValueBeforeEvent = selectExtensions.readValue(this.$element);
|
|
68
|
+
safeSetTimeout(this.valueUpdateHandler.bind(this), 0);
|
|
69
|
+
};
|
|
70
|
+
eventName = eventName.substring(5);
|
|
71
|
+
}
|
|
72
|
+
this.addEventListener(eventName, handler);
|
|
73
|
+
}
|
|
74
|
+
updateFromModelForFile() {
|
|
75
|
+
var newValue = unwrap(this.value);
|
|
76
|
+
if (newValue === null || newValue === void 0 || newValue === "") {
|
|
77
|
+
this.$element.value = "";
|
|
78
|
+
} else {
|
|
79
|
+
dependencyDetection.ignore(this.valueUpdateHandler, this);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
updateFromModelForValue() {
|
|
83
|
+
const element = this.$element;
|
|
84
|
+
var newValue = unwrap(this.value);
|
|
85
|
+
var elementValue = selectExtensions.readValue(element);
|
|
86
|
+
if (this.elementValueBeforeEvent !== null && newValue === this.elementValueBeforeEvent) {
|
|
87
|
+
safeSetTimeout(this.updateFromModel.bind(this), 0);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (newValue === elementValue && elementValue !== void 0) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (tagNameLower(element) === "select") {
|
|
94
|
+
const allowUnset = this.allBindings.get("valueAllowUnset");
|
|
95
|
+
selectExtensions.writeValue(element, newValue, allowUnset);
|
|
96
|
+
if (!allowUnset && newValue !== selectExtensions.readValue(element)) {
|
|
97
|
+
dependencyDetection.ignore(this.valueUpdateHandler, this);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
selectExtensions.writeValue(element, newValue);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/value.ts"],
|
|
4
|
+
"sourcesContent": ["\nimport {\n ieVersion, stringStartsWith, safeSetTimeout, tagNameLower, arrayForEach,\n selectExtensions\n} from '@tko/utils'\n\nimport {\n unwrap, dependencyDetection\n} from '@tko/observable'\n\nimport {\n applyBindingAccessorsToNode, BindingHandler\n} from '@tko/bind'\n\nexport class value extends BindingHandler {\n static get after () { return ['options', 'foreach', 'template'] }\n\n constructor (...args) {\n super(...args)\n\n // If the value binding is placed on a radio/checkbox, then just pass through to checkedValue and quit\n if (this.isCheckboxOrRadio) {\n applyBindingAccessorsToNode(this.$element,\n { checkedValue: this.valueAccessor })\n return\n }\n\n this.propertyChangedFired = false\n this.elementValueBeforeEvent = null\n\n if (this.ieAutoCompleteHackNeeded) {\n this.addEventListener('propertyChange', () => this.propertyChangedFired = true)\n this.addEventListener('focus', () => this.propertyChangedFired = false)\n this.addEventListener('blur', () => this.propertyChangeFired &&\n this.valueUpdateHandler())\n }\n\n arrayForEach(this.eventsToCatch, eventName => this.registerEvent(eventName))\n\n if (this.isInput && this.$element.type === 'file') {\n this.updateFromModel = this.updateFromModelForFile\n } else {\n this.updateFromModel = this.updateFromModelForValue\n }\n\n this.computed('updateFromModel')\n }\n\n get eventsToCatch () {\n const requestedEventsToCatch = this.allBindings.get('valueUpdate')\n const requestedEventsArray = typeof requestedEventsToCatch === 'string' ?\n [requestedEventsToCatch] : requestedEventsToCatch || []\n return [...new Set(['change', ...requestedEventsArray])]\n }\n\n get isInput () {\n return tagNameLower(this.$element) === 'input'\n }\n\n get isCheckboxOrRadio () {\n const e = this.$element\n return this.isInput && (e.type == 'checkbox' || e.type == 'radio')\n }\n\n // Workaround for https://github.com/SteveSanderson/knockout/issues/122\n // IE doesn't fire \"change\" events on textboxes if the user selects a value from its autocomplete list\n get ieAutoCompleteHackNeeded () {\n return ieVersion && isInputElement &&\n this.$element.type == 'text' && this.$element.autocomplete != 'off' &&\n (!this.$element.form || this.$element.form.autocomplete != 'off')\n }\n\n valueUpdateHandler () {\n this.elementValueBeforeEvent = null\n this.propertyChangedFired = false\n this.value = selectExtensions.readValue(this.$element)\n }\n\n registerEvent (eventName) {\n // The syntax \"after<eventname>\" means \"run the handler asynchronously after the event\"\n // This is useful, for example, to catch \"keydown\" events after the browser has updated the control\n // (otherwise, selectExtensions.readValue(this) will receive the control's value *before* the key event)\n var handler = this.valueUpdateHandler.bind(this)\n if (stringStartsWith(eventName, 'after')) {\n handler = () => {\n // The elementValueBeforeEvent variable is non-null *only* during the brief gap between\n // a keyX event firing and the valueUpdateHandler running, which is scheduled to happen\n // at the earliest asynchronous opportunity. We store this temporary information so that\n // if, between keyX and valueUpdateHandler, the underlying model value changes separately,\n // we can overwrite that model value change with the value the user just typed. Otherwise,\n // techniques like rateLimit can trigger model changes at critical moments that will\n // override the user's inputs, causing keystrokes to be lost.\n this.elementValueBeforeEvent = selectExtensions.readValue(this.$element)\n safeSetTimeout(this.valueUpdateHandler.bind(this), 0)\n }\n eventName = eventName.substring(5 /* 'after'.length */)\n }\n this.addEventListener(eventName, handler)\n }\n\n updateFromModelForFile () {\n // For file input elements, can only write the empty string\n var newValue = unwrap(this.value)\n if (newValue === null || newValue === undefined || newValue === '') {\n this.$element.value = ''\n } else {\n dependencyDetection.ignore(this.valueUpdateHandler, this) // reset the model to match the element\n }\n }\n\n updateFromModelForValue () {\n const element = this.$element\n var newValue = unwrap(this.value)\n var elementValue = selectExtensions.readValue(element)\n\n if (this.elementValueBeforeEvent !== null && newValue === this.elementValueBeforeEvent) {\n safeSetTimeout(this.updateFromModel.bind(this), 0)\n return\n }\n\n if (newValue === elementValue && elementValue !== undefined) { return }\n\n if (tagNameLower(element) === 'select') {\n const allowUnset = this.allBindings.get('valueAllowUnset')\n selectExtensions.writeValue(element, newValue, allowUnset)\n\n if (!allowUnset && newValue !== selectExtensions.readValue(element)) {\n // If you try to set a model value that can't be represented in an already-populated dropdown, reject that change,\n // because you're not allowed to have a model value that disagrees with a visible UI selection.\n dependencyDetection.ignore(this.valueUpdateHandler, this)\n }\n } else {\n selectExtensions.writeValue(element, newValue)\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAIA;AAAA;AAAA;AAAA;AAIO,aAAM,cAAc,eAAe;AAAA,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A,MAC1D;AAAA,IACF,OAAO;AACL,uBAAiB,WAAW,SAAS,QAAQ;AAAA,IAC/C;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/visible.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @tko/binding.core 🥊 4.0.0-beta1.0 ESM
|
|
2
|
+
import {
|
|
3
|
+
unwrap
|
|
4
|
+
} from "@tko/observable";
|
|
5
|
+
export var visible = {
|
|
6
|
+
update: function(element, valueAccessor) {
|
|
7
|
+
var value = unwrap(valueAccessor());
|
|
8
|
+
var isCurrentlyVisible = !(element.style.display === "none");
|
|
9
|
+
if (value && !isCurrentlyVisible) {
|
|
10
|
+
element.style.display = "";
|
|
11
|
+
} else if (!value && isCurrentlyVisible) {
|
|
12
|
+
element.style.display = "none";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export var hidden = {
|
|
17
|
+
update: function(element, valueAccessor) {
|
|
18
|
+
visible.update.call(this, element, () => !unwrap(valueAccessor()));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/visible.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n unwrap\n} from '@tko/observable'\n\nexport var visible = {\n update: function (element, valueAccessor) {\n var value = unwrap(valueAccessor())\n var isCurrentlyVisible = !(element.style.display === 'none')\n if (value && !isCurrentlyVisible) {\n element.style.display = ''\n } else if (!value && isCurrentlyVisible) {\n element.style.display = 'none'\n }\n }\n}\n\nexport var hidden = {\n update: function (element, valueAccessor) {\n visible.update.call(this, element, () => !unwrap(valueAccessor()))\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA;AAAA;AAIO,WAAI,UAAU;AAAA,EACnB,QAAQ,SAAU,SAAS,eAAe;AACxC,QAAI,QAAQ,OAAO,cAAc,CAAC;AAClC,QAAI,qBAAqB,CAAE,SAAQ,MAAM,YAAY;AACrD,QAAI,SAAS,CAAC,oBAAoB;AAChC,cAAQ,MAAM,UAAU;AAAA,IAC1B,WAAW,CAAC,SAAS,oBAAoB;AACvC,cAAQ,MAAM,UAAU;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,WAAI,SAAS;AAAA,EAClB,QAAQ,SAAU,SAAS,eAAe;AACxC,YAAQ,OAAO,KAAK,MAAM,SAAS,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAAA,EACnE;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "4.0.0-beta1.0",
|
|
2
3
|
"name": "@tko/binding.core",
|
|
3
|
-
"version": "4.0.0-alpha9.0",
|
|
4
4
|
"description": "TKO Core bindings",
|
|
5
5
|
"module": "dist/binding.core.js",
|
|
6
6
|
"files": [
|
|
@@ -9,53 +9,43 @@
|
|
|
9
9
|
],
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/knockout/tko.
|
|
12
|
+
"url": "git+https://github.com/knockout/tko.git"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"knockout",
|
|
16
16
|
"tko",
|
|
17
17
|
"ko"
|
|
18
18
|
],
|
|
19
|
-
"author": "Knockout",
|
|
19
|
+
"author": "The Knockout Team",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/knockout/tko
|
|
22
|
+
"url": "https://github.com/knockout/tko/issues"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://tko.io",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tko/bind": "^4.0.0-
|
|
27
|
-
"@tko/computed": "^4.0.0-
|
|
28
|
-
"@tko/observable": "^4.0.0-
|
|
29
|
-
"@tko/utils": "^4.0.0-
|
|
30
|
-
"tslib": "^
|
|
26
|
+
"@tko/bind": "^4.0.0-beta1.0",
|
|
27
|
+
"@tko/computed": "^4.0.0-beta1.0",
|
|
28
|
+
"@tko/observable": "^4.0.0-beta1.0",
|
|
29
|
+
"@tko/utils": "^4.0.0-beta1.0",
|
|
30
|
+
"tslib": "^2.2.0"
|
|
31
31
|
},
|
|
32
32
|
"karma": {
|
|
33
33
|
"frameworks": [
|
|
34
34
|
"jasmine"
|
|
35
35
|
]
|
|
36
36
|
},
|
|
37
|
-
"__about__shared.package.json": "These properties are copied into all packages/*/package.json. Run `yarn repackage`",
|
|
38
|
-
"standard": {
|
|
39
|
-
"env": [
|
|
40
|
-
"browser",
|
|
41
|
-
"jasmine",
|
|
42
|
-
"mocha"
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"test": "npx karma start ../../karma.conf.js --once",
|
|
47
|
-
"build": "npx rollup -c ../../rollup.config.js",
|
|
48
|
-
"watch": "npx karma start ../../karma.conf.js",
|
|
49
|
-
"prepare": "npx rollup -c ../../rollup.config.js"
|
|
50
|
-
},
|
|
51
|
-
"publishConfig": {
|
|
52
|
-
"access": "public"
|
|
53
|
-
},
|
|
54
37
|
"licenses": [
|
|
55
38
|
{
|
|
56
39
|
"type": "MIT",
|
|
57
|
-
"url": "
|
|
40
|
+
"url": "https://opensource.org/licenses/MIT"
|
|
58
41
|
}
|
|
59
42
|
],
|
|
60
|
-
"
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"require": "./dist/index.cjs",
|
|
46
|
+
"import": "./dist/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./helpers/*": "./helpers/*"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "99114c4deded3fc5dbddd5c7c9c63c845a18263b"
|
|
61
51
|
}
|