Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,784 changes: 1,605 additions & 2,179 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
"@types/jquery": "^4.0.0",
"@types/mocha": "^10.0.10",
"chai": "^4.5.0",
"electron": "^33.2.1",
"esbuild": "^0.27.0",
"eslint": "^10.0.3",
"esbuild": "^0.28.0",
"eslint": "^10.2.0",
"fs-extra": "^11.3.2",
"globals": "^17.4.0",
"jquery": "^4.0.0",
"karma": "^6.4.4",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.1",
"karma-electron-launcher": "^0.3.0",
"karma-esbuild": "^2.3.0",
"karma-firefox-launcher": "^2.1.2",
"karma-jasmine": "^0.1.6",
Expand All @@ -41,10 +39,10 @@
"lerna": "^9.0.3",
"mocha": "^11.0.1",
"nyc": "^18.0.0",
"prettier": "^3.7.4",
"prettier": "^3.8.1",
"sinon": "^19.0.2",
"typescript": "^5.9.3",
"typescript-eslint": "^8.56.1"
"typescript": "^6.0.2",
"typescript-eslint": "^8.58.0"
},
"workspaces": [
"packages/*",
Expand Down
12 changes: 5 additions & 7 deletions packages/bind/spec/bindingHandlerBehaviors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { VirtualProvider } from '@tko/provider.virtual'

import { DataBindProvider } from '@tko/provider.databind'

import { applyBindings, BindingHandler, contextFor } from '../dist'
import { applyBindings, BindingHandler, contextFor } from '../src'

import { bindings as coreBindings } from '@tko/binding.core'
import { bindings as templateBindings } from '@tko/binding.template'
Expand Down Expand Up @@ -48,10 +48,9 @@ describe('BindingHandler behaviors', function () {
v: Observable
x: Observable
y: Observable
computed

constructor(...args) {
super(...args)
constructor(params) {
super(params)
const v = (this.v = koObservable(0))
instance = this
this.x = this.computed(() => {
Expand Down Expand Up @@ -93,9 +92,8 @@ describe('BindingHandler behaviors', function () {
let obs = koObservable(),
handlerInstance
bindingHandlers.fnHandler = class extends BindingHandler {
subscribe
constructor(...args) {
super(...args)
constructor(params) {
super(params)
handlerInstance = this
this.subscribe(obs, this.cb)
}
Expand Down
6 changes: 5 additions & 1 deletion packages/bind/src/BindingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export class BindingHandler<T = any> extends LifeCycle {
provider.bindingHandlers.set(name, this) //todo dangerous javascript: this in static function = this is calling object
}

static registerBindingHandler(handler: BindingHandler, name: string, provider = options.bindingProviderInstance) {
static registerBindingHandler(
handler: typeof BindingHandler,
name: string,
provider = options.bindingProviderInstance
) {
provider.bindingHandlers.set(name, handler)
}
}
Expand Down
18 changes: 11 additions & 7 deletions packages/binding.core/src/textInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ class TextInput extends BindingHandler {
return 'textinput'
}

override $element: HTMLInputElement
get $inputElement(): HTMLInputElement {
return this.$element as HTMLInputElement
}

previousElementValue: any
elementValueBeforeEvent?: ReturnType<typeof setTimeout>
timeoutHandle?: ReturnType<typeof setTimeout>

constructor(...args: [any]) {
super(...args)
this.previousElementValue = this.$element.value

this.previousElementValue = this.$inputElement.value

if (options.debug && (this.constructor as any)._forceUpdateOn) {
// Provide a way for tests to specify exactly which events are bound
Expand Down Expand Up @@ -58,7 +62,7 @@ class TextInput extends BindingHandler {
}

updateModel(event) {
const element = this.$element
const element = this.$inputElement
clearTimeout(this.timeoutHandle)
this.elementValueBeforeEvent = this.timeoutHandle = undefined
const elementValue = element.value
Expand All @@ -73,7 +77,7 @@ class TextInput extends BindingHandler {
}

deferUpdateModel(event: any) {
const element = this.$element
const element = this.$inputElement
if (!this.timeoutHandle) {
// The elementValueBeforeEvent variable is set *only* during the brief gap between an
// event firing and the updateModel function running. This allows us to ignore model
Expand All @@ -92,12 +96,12 @@ class TextInput extends BindingHandler {
}
if (this.elementValueBeforeEvent !== undefined && modelValue === this.elementValueBeforeEvent) {
setTimeout(this.updateView.bind(this), 4)
} else if (this.$element.value !== modelValue) {
} else if (this.$inputElement.value !== modelValue) {
// Update the element only if the element and model are different. On some browsers, updating the value
// will move the cursor to the end of the input, which would be bad while the user is typing.
this.previousElementValue = modelValue // Make sure we ignore events (propertychange) that result from updating the value
this.$element.value = modelValue
this.previousElementValue = this.$element.value // In case the browser changes the value (see #2281)
this.$inputElement.value = modelValue
this.previousElementValue = this.$inputElement.value // In case the browser changes the value (see #2281)
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions packages/binding.core/src/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class value extends BindingHandler {
return ['options', 'foreach', 'template']
}

override $element: HTMLInputElement
elementValueBeforeEvent: any
propertyChangeFired: any
propertyChangedFired: boolean
Expand All @@ -36,7 +35,7 @@ export class value extends BindingHandler {

arrayForEach(this.eventsToCatch, eventName => this.registerEvent(eventName))

if (this.isInput && this.$element.type === 'file') {
if (this.isInput(this.$element) && this.$element.type === 'file') {
this.updateFromModel = this.updateFromModelForFile
} else {
this.updateFromModel = this.updateFromModelForValue
Expand All @@ -52,20 +51,20 @@ export class value extends BindingHandler {
return [...new Set(['change', ...requestedEventsArray])]
}

get isInput() {
isInput(element: HTMLElement): element is HTMLInputElement {
return tagNameLower(this.$element) === 'input'
}

get isCheckboxOrRadio() {
const e = this.$element
return this.isInput && (e.type == 'checkbox' || e.type == 'radio')
return this.isInput(e) && (e.type == 'checkbox' || e.type == 'radio')
}

// Workaround for https://github.com/SteveSanderson/knockout/issues/122
// IE doesn't fire "change" events on textboxes if the user selects a value from its autocomplete list
get ieAutoCompleteHackNeeded() {
return (
this.isInput
this.isInput(this.$element)
&& this.$element.type == 'text'
&& this.$element.autocomplete != 'off'
&& (!this.$element.form || this.$element.form.autocomplete != 'off')
Expand Down Expand Up @@ -105,7 +104,7 @@ export class value extends BindingHandler {
// For file input elements, can only write the empty string
const newValue = unwrap(this.value)
if (newValue === null || newValue === undefined || newValue === '') {
this.$element.value = ''
;(this.$element as HTMLInputElement).value = ''
} else {
dependencyDetection.ignore(this.valueUpdateHandler, this) // reset the model to match the element
}
Expand Down
1 change: 0 additions & 1 deletion packages/binding.foreach/src/foreach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export class ForEachBinding extends AsyncBindingHandler {
// computed
// {data: array, name: string, as: string}
afterAdd
override allBindings: AllBindings
static animateFrame
as
beforeRemove
Expand Down
3 changes: 2 additions & 1 deletion packages/lifecycle/src/LifeCycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { addDisposeCallback, createSymbolOrString } from '@tko/utils'

import { computed } from '@tko/computed'
import { Observable } from '@tko/observable'

const SUBSCRIPTIONS = createSymbolOrString('LifeCycle Subscriptions List')
const ANCHOR_NODE = createSymbolOrString('LifeCycle Anchor Node')
Expand All @@ -24,7 +25,7 @@ export default class LifeCycle {
}
}

subscribe(observable, action, subscriptionType) {
subscribe(observable: Observable, action: any, subscriptionType?: string) {
if (typeof action === 'string') {
action = this[action]
}
Expand Down
21 changes: 10 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
"compileOnSave": false,
"compilerOptions": {
"declaration": true,
"downlevelIteration": true,
"target": "ES6",
"module": "ES2015",
"moduleResolution": "node",
"ignoreDeprecations": "6.0",
"target": "es2022",
"module": "es2022",
"moduleResolution": "node10", //Deprecated in ts7.0
"allowJs": false,
"importHelpers": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"baseUrl": ".",
"noEmit": true,
/*Disable some typing feature from ts*/
"noImplicitAny": false,
Expand All @@ -23,18 +22,18 @@
"strictBindCallApply": true,
"strictFunctionTypes": true,
"skipLibCheck": true,

"lib": ["es2022", "dom"],
"paths": {
"@tko/utils/helpers/jasmine-13-helper": [
"packages/utils/helpers/jasmine-13-helper.ts"
"./packages/utils/helpers/jasmine-13-helper.ts"
],
"@tko/binding.template/helpers/dummyTemplateEngine": [
"packages/binding.template/helpers/dummyTemplateEngine.ts"
"./packages/binding.template/helpers/dummyTemplateEngine.ts"
],
"*": [
"*",
"packages/*",
"builds/*"
"./*",
"./packages/*",
"./builds/*"
]
}
},
Expand Down
Loading