1 | interface KnockoutSubscribableFunctions<T> {
|
2 | |
3 |
|
4 |
|
5 |
|
6 |
|
7 | notifySubscribers(eventValue?: T, event?: "change"): void;
|
8 | |
9 |
|
10 |
|
11 |
|
12 |
|
13 | notifySubscribers<U>(eventValue: U, event: string): void;
|
14 | }
|
15 |
|
16 | interface KnockoutComputedFunctions<T> {
|
17 | }
|
18 |
|
19 | interface KnockoutObservableFunctions<T> {
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | equalityComparer(a: T, b: T): boolean;
|
27 | }
|
28 |
|
29 |
|
30 | interface KnockoutReadonlyObservableArrayFunctions<T> {
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 | indexOf(searchElement: T, fromIndex?: number): number;
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 | slice(start: number, end?: number): T[];
|
43 | }
|
44 |
|
45 | interface KnockoutObservableArrayFunctions<T> extends KnockoutReadonlyObservableArrayFunctions<T> {
|
46 | |
47 |
|
48 |
|
49 |
|
50 | splice(start: number): T[];
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | splice(start: number, deleteCount: number, ...items: T[]): T[];
|
58 | |
59 |
|
60 |
|
61 | pop(): T;
|
62 | |
63 |
|
64 |
|
65 |
|
66 | push(...items: T[]): void;
|
67 | |
68 |
|
69 |
|
70 | shift(): T;
|
71 | |
72 |
|
73 |
|
74 |
|
75 | unshift(...items: T[]): number;
|
76 | |
77 |
|
78 |
|
79 | reverse(): KnockoutObservableArray<T>;
|
80 | |
81 |
|
82 |
|
83 | sort(): KnockoutObservableArray<T>;
|
84 | |
85 |
|
86 |
|
87 |
|
88 | sort(compareFunction: (left: T, right: T) => number): KnockoutObservableArray<T>;
|
89 |
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 | replace(oldItem: T, newItem: T): void;
|
97 | |
98 |
|
99 |
|
100 |
|
101 | remove(item: T): T[];
|
102 | |
103 |
|
104 |
|
105 |
|
106 | remove(removeFunction: (item: T) => boolean): T[];
|
107 | |
108 |
|
109 |
|
110 |
|
111 | removeAll(items: T[]): T[];
|
112 | |
113 |
|
114 |
|
115 | removeAll(): T[];
|
116 |
|
117 |
|
118 | |
119 |
|
120 |
|
121 |
|
122 | destroy(item: T): void;
|
123 | |
124 |
|
125 |
|
126 |
|
127 | destroy(destroyFunction: (item: T) => boolean): void;
|
128 | |
129 |
|
130 |
|
131 |
|
132 | destroyAll(items: T[]): void;
|
133 | |
134 |
|
135 |
|
136 | destroyAll(): void;
|
137 | }
|
138 |
|
139 | interface KnockoutSubscribableStatic {
|
140 | fn: KnockoutSubscribableFunctions<any>;
|
141 |
|
142 | new<T>(): KnockoutSubscribable<T>;
|
143 | }
|
144 |
|
145 | interface KnockoutSubscription {
|
146 | |
147 |
|
148 |
|
149 | dispose(): void;
|
150 | }
|
151 |
|
152 | interface KnockoutSubscribable<T> extends KnockoutSubscribableFunctions<T> {
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | subscribe(callback: (newValue: T) => void, target?: any, event?: "change"): KnockoutSubscription;
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 | subscribe(callback: (newValue: T) => void, target: any, event: "beforeChange"): KnockoutSubscription;
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | subscribe<U>(callback: (eventValue: U) => void, target: any, event: string): KnockoutSubscription;
|
174 | /**
|
175 | * Customizes observables basic functionality.
|
176 | * @param requestedExtenders Name of the extender feature and its value, e.g. { notify: 'always' }, { rateLimit: 50 }
|
177 | */
|
178 | extend(requestedExtenders: { [key: string]: any }): KnockoutSubscribable<T>;
|
179 | /**
|
180 | * Gets total number of subscribers.
|
181 | */
|
182 | getSubscriptionsCount(): number;
|
183 | /**
|
184 | * Gets number of subscribers of a particular event.
|
185 | * @param event Event name.
|
186 | */
|
187 | getSubscriptionsCount(event: string): number;
|
188 | }
|
189 |
|
190 | interface KnockoutComputedStatic {
|
191 | fn: KnockoutComputedFunctions<any>;
|
192 |
|
193 | /**
|
194 | * Creates computed observable.
|
195 | */
|
196 | <T>(): KnockoutComputed<T>;
|
197 | /**
|
198 | * Creates computed observable.
|
199 | * @param evaluatorFunction Function that computes the observable value.
|
200 | * @param context Defines the value of 'this' when evaluating the computed observable.
|
201 | * @param options An object with further properties for the computed observable.
|
202 | */
|
203 | <T>(evaluatorFunction: () => T, context?: any, options?: KnockoutComputedOptions<T>): KnockoutComputed<T>;
|
204 | /**
|
205 | * Creates computed observable.
|
206 | * @param options An object that defines the computed observable options and behavior.
|
207 | * @param context Defines the value of 'this' when evaluating the computed observable.
|
208 | */
|
209 | <T>(options: KnockoutComputedDefine<T>, context?: any): KnockoutComputed<T>;
|
210 | }
|
211 |
|
212 | interface KnockoutReadonlyComputed<T> extends KnockoutReadonlyObservable<T> {
|
213 | /**
|
214 | * Returns whether the computed observable may be updated in the future. A computed observable is inactive if it has no dependencies.
|
215 | */
|
216 | isActive(): boolean;
|
217 | /**
|
218 | * Returns the current number of dependencies of the computed observable.
|
219 | */
|
220 | getDependenciesCount(): number;
|
221 | }
|
222 |
|
223 | interface KnockoutComputed<T> extends KnockoutReadonlyComputed<T>, KnockoutObservable<T>, KnockoutComputedFunctions<T> {
|
224 | fn: KnockoutComputedFunctions<any>;
|
225 |
|
226 | /**
|
227 | * Manually disposes the computed observable, clearing all subscriptions to dependencies.
|
228 | * This function is useful if you want to stop a computed observable from being updated or want to clean up memory for a
|
229 | * computed observable that has dependencies on observables that won’t be cleaned.
|
230 | */
|
231 | dispose(): void;
|
232 | /**
|
233 | * Customizes observables basic functionality.
|
234 | * @param requestedExtenders Name of the extender feature and it's value, e.g. { notify: 'always' }, { rateLimit: 50 }
|
235 | */
|
236 | extend(requestedExtenders: { [key: string]: any }): KnockoutComputed<T>;
|
237 | }
|
238 |
|
239 | interface KnockoutObservableArrayStatic {
|
240 | fn: KnockoutObservableArrayFunctions<any>;
|
241 |
|
242 | <T>(value?: T[] | null): KnockoutObservableArray<T>;
|
243 | }
|
244 |
|
245 | /**
|
246 | * While all observable arrays are writable at runtime, this type is analogous to the native ReadonlyArray type:
|
247 | * casting an observable array to this type expresses the intention that it shouldn't be mutated.
|
248 | */
|
249 | interface KnockoutReadonlyObservableArray<T>
|
250 | extends KnockoutReadonlyObservable<readonly T[]>, KnockoutReadonlyObservableArrayFunctions<T>
|
251 | {
|
252 | // NOTE: Keep in sync with KnockoutObservableArray<T>, see note on KnockoutObservableArray<T>
|
253 | subscribe(
|
254 | callback: (newValue: Array<KnockoutArrayChange<T>>) => void,
|
255 | target: any,
|
256 | event: "arrayChange",
|
257 | ): KnockoutSubscription;
|
258 | subscribe(callback: (newValue: T[]) => void, target: any, event: "beforeChange"): KnockoutSubscription;
|
259 | subscribe(callback: (newValue: T[]) => void, target?: any, event?: "change"): KnockoutSubscription;
|
260 | subscribe<U>(callback: (newValue: U) => void, target: any, event: string): KnockoutSubscription;
|
261 | }
|
262 |
|
263 | /*
|
264 | NOTE: In theory this should extend both KnockoutObservable<T[]> and KnockoutReadonlyObservableArray<T>,
|
265 | but can't since they both provide conflicting typings of .subscribe.
|
266 | So it extends KnockoutObservable<T[]> and duplicates the subscribe definitions, which should be kept in sync
|
267 | */
|
268 | interface KnockoutObservableArray<T> extends KnockoutObservable<T[]>, KnockoutObservableArrayFunctions<T> {
|
269 | subscribe(
|
270 | callback: (newValue: Array<KnockoutArrayChange<T>>) => void,
|
271 | target: any,
|
272 | event: "arrayChange",
|
273 | ): KnockoutSubscription;
|
274 | subscribe(callback: (newValue: T[]) => void, target: any, event: "beforeChange"): KnockoutSubscription;
|
275 | subscribe(callback: (newValue: T[]) => void, target?: any, event?: "change"): KnockoutSubscription;
|
276 | subscribe<U>(callback: (newValue: U) => void, target: any, event: string): KnockoutSubscription;
|
277 |
|
278 | extend(requestedExtenders: { [key: string]: any }): KnockoutObservableArray<T>;
|
279 | }
|
280 |
|
281 | interface KnockoutObservableStatic {
|
282 | fn: KnockoutObservableFunctions<any>;
|
283 |
|
284 | <T>(value: T): KnockoutObservable<T>;
|
285 | <T>(value: any): KnockoutObservable<T>;
|
286 | <T = any>(value: null): KnockoutObservable<T | null>;
|
287 | <T = any>(): KnockoutObservable<T | undefined>;
|
288 | }
|
289 |
|
290 | /**
|
291 | * While all observable are writable at runtime, this type is analogous to the native ReadonlyArray type:
|
292 | * casting an observable to this type expresses the intention that this observable shouldn't be mutated.
|
293 | */
|
294 | interface KnockoutReadonlyObservable<T> extends KnockoutSubscribable<T>, KnockoutObservableFunctions<T> {
|
295 | (): T;
|
296 |
|
297 | /**
|
298 | * Returns the current value of the computed observable without creating a dependency.
|
299 | */
|
300 | peek(): T;
|
301 | valueHasMutated?: { (): void } | undefined;
|
302 | valueWillMutate?: { (): void } | undefined;
|
303 | }
|
304 |
|
305 | interface KnockoutObservable<T> extends KnockoutReadonlyObservable<T> {
|
306 | (value: T): void;
|
307 |
|
308 | // Since .extend does arbitrary thing to an observable, it's not safe to do on a readonly observable
|
309 | /**
|
310 | * Customizes observables basic functionality.
|
311 | * @param requestedExtenders Name of the extender feature and it's value, e.g. { notify: 'always' }, { rateLimit: 50 }
|
312 | */
|
313 | extend(requestedExtenders: { [key: string]: any }): KnockoutObservable<T>;
|
314 | }
|
315 |
|
316 | interface KnockoutComputedOptions<T> {
|
317 | /**
|
318 | * Makes the computed observable writable. This is a function that receives values that other code is trying to write to your computed observable.
|
319 | * It’s up to you to supply custom logic to handle the incoming values, typically by writing the values to some underlying observable(s).
|
320 | * @param value Value being written to the computer observable.
|
321 | */
|
322 | write?(value: T): void;
|
323 | /**
|
324 | * Disposal of the computed observable will be triggered when the specified DOM node is removed by KO.
|
325 | * This feature is used to dispose computed observables used in bindings when nodes are removed by the template and control-flow bindings.
|
326 | */
|
327 | disposeWhenNodeIsRemoved?: Node | undefined;
|
328 | /**
|
329 | * This function is executed before each re-evaluation to determine if the computed observable should be disposed.
|
330 | * A true-ish result will trigger disposal of the computed observable.
|
331 | */
|
332 | disposeWhen?(): boolean;
|
333 | /**
|
334 | * Defines the value of 'this' whenever KO invokes your 'read' or 'write' callbacks.
|
335 | */
|
336 | owner?: any;
|
337 | /**
|
338 | * If true, then the value of the computed observable will not be evaluated until something actually attempts to access its value or manually subscribes to it.
|
339 | * By default, a computed observable has its value determined immediately during creation.
|
340 | */
|
341 | deferEvaluation?: boolean | undefined;
|
342 | /**
|
343 | * If true, the computed observable will be set up as a purecomputed observable. This option is an alternative to the ko.pureComputed constructor.
|
344 | */
|
345 | pure?: boolean | undefined;
|
346 | }
|
347 |
|
348 | interface KnockoutComputedDefine<T> extends KnockoutComputedOptions<T> {
|
349 | /**
|
350 | * A function that is used to evaluate the computed observable’s current value.
|
351 | */
|
352 | read(): T;
|
353 | }
|
354 |
|
355 | interface KnockoutBindingContext {
|
356 | $parent: any;
|
357 | $parents: any[];
|
358 | $root: any;
|
359 | $data: any;
|
360 | $rawData: any | KnockoutObservable<any>;
|
361 | $index?: KnockoutObservable<number> | undefined;
|
362 | $parentContext?: KnockoutBindingContext | undefined;
|
363 | $component: any;
|
364 | $componentTemplateNodes: Node[];
|
365 |
|
366 | /**
|
367 | * Clones the current Binding Context, adding extra properties to it.
|
368 | * @param properties object with properties to be added in the binding context.
|
369 | */
|
370 | extend(properties: { [key: string]: any } | (() => { [key: string]: any })): KnockoutBindingContext;
|
371 | /**
|
372 | * This returns a new binding context whose viewmodel is the first parameter and whose $parentContext is the current bindingContext.
|
373 | * @param dataItemOrAccessor The binding context of the children.
|
374 | * @param dataItemAlias An alias for the data item in descendant contexts.
|
375 | * @param extendCallback Function to be called.
|
376 | * @param options Further options.
|
377 | */
|
378 | createChildContext(
|
379 | dataItemOrAccessor: any,
|
380 | dataItemAlias?: string,
|
381 | extendCallback?: Function,
|
382 | options?: { "exportDependencies": boolean },
|
383 | ): any;
|
384 | }
|
385 |
|
386 | interface KnockoutAllBindingsAccessor {
|
387 | (): any;
|
388 | get(name: string): any;
|
389 | has(name: string): boolean;
|
390 | }
|
391 |
|
392 | interface KnockoutBindingHandler<E extends Node = any, V = any, VM = any> {
|
393 | after?: string[] | undefined;
|
394 | init?:
|
395 | | ((
|
396 | element: E,
|
397 | valueAccessor: () => V,
|
398 | allBindingsAccessor: KnockoutAllBindingsAccessor,
|
399 | viewModel: VM,
|
400 | bindingContext: KnockoutBindingContext,
|
401 |
|
402 | ) => void | { controlsDescendantBindings: boolean })
|
403 | | undefined;
|
404 | update?:
|
405 | | ((
|
406 | element: E,
|
407 | valueAccessor: () => V,
|
408 | allBindingsAccessor: KnockoutAllBindingsAccessor,
|
409 | viewModel: VM,
|
410 | bindingContext: KnockoutBindingContext,
|
411 | ) => void)
|
412 | | undefined;
|
413 | options?: any;
|
414 | preprocess?:
|
415 | | ((value: string, name: string, addBindingCallback?: (name: string, value: string) => void) => string)
|
416 | | undefined;
|
417 | [s: string]: any;
|
418 | }
|
419 |
|
420 | interface KnockoutBindingHandlers {
|
421 | [bindingHandler: string]: KnockoutBindingHandler;
|
422 |
|
423 | // Controlling text and appearance
|
424 | visible: KnockoutBindingHandler;
|
425 | text: KnockoutBindingHandler;
|
426 | html: KnockoutBindingHandler;
|
427 | css: KnockoutBindingHandler;
|
428 | style: KnockoutBindingHandler;
|
429 | attr: KnockoutBindingHandler;
|
430 |
|
431 | // Control Flow
|
432 | foreach: KnockoutBindingHandler;
|
433 | if: KnockoutBindingHandler;
|
434 | ifnot: KnockoutBindingHandler;
|
435 | with: KnockoutBindingHandler;
|
436 |
|
437 | // Working with form fields
|
438 | click: KnockoutBindingHandler;
|
439 | event: KnockoutBindingHandler;
|
440 | submit: KnockoutBindingHandler;
|
441 | enable: KnockoutBindingHandler;
|
442 | disable: KnockoutBindingHandler;
|
443 | value: KnockoutBindingHandler;
|
444 | textInput: KnockoutBindingHandler;
|
445 | hasfocus: KnockoutBindingHandler;
|
446 | checked: KnockoutBindingHandler;
|
447 | options: KnockoutBindingHandler;
|
448 | selectedOptions: KnockoutBindingHandler;
|
449 | uniqueName: KnockoutBindingHandler;
|
450 |
|
451 | // Rendering templates
|
452 | template: KnockoutBindingHandler;
|
453 |
|
454 | // Components (new for v3.2)
|
455 | component: KnockoutBindingHandler;
|
456 | }
|
457 |
|
458 | interface KnockoutMemoization {
|
459 | memoize(callback: Function): string;
|
460 | unmemoize(memoId: string, callbackParams: any[]): boolean;
|
461 | unmemoizeDomNodeAndDescendants(domNode: any, extraCallbackParamsArray: any[]): boolean;
|
462 | parseMemoText(memoText: string): string;
|
463 | }
|
464 |
|
465 | interface KnockoutVirtualElement {}
|
466 |
|
467 | interface KnockoutVirtualElements {
|
468 | allowedBindings: { [bindingName: string]: boolean };
|
469 | emptyNode(node: KnockoutVirtualElement): void;
|
470 | firstChild(node: KnockoutVirtualElement): KnockoutVirtualElement;
|
471 | insertAfter(container: KnockoutVirtualElement, nodeToInsert: Node, insertAfter: Node): void;
|
472 | nextSibling(node: KnockoutVirtualElement): Node;
|
473 | prepend(node: KnockoutVirtualElement, toInsert: Node): void;
|
474 | setDomNodeChildren(node: KnockoutVirtualElement, newChildren: { length: number; [index: number]: Node }): void;
|
475 | childNodes(node: KnockoutVirtualElement): Node[];
|
476 | }
|
477 |
|
478 | interface KnockoutExtenders {
|
479 | throttle(target: any, timeout: number): KnockoutComputed<any>;
|
480 | notify(target: any, notifyWhen: string): any;
|
481 |
|
482 | rateLimit(target: any, timeout: number): any;
|
483 | rateLimit(target: any, options: { timeout: number; method?: string | undefined }): any;
|
484 |
|
485 | trackArrayChanges(target: any): any;
|
486 | }
|
487 |
|
488 | //
|
489 | // NOTE TO MAINTAINERS AND CONTRIBUTORS : pay attention to only include symbols that are
|
490 | // publicly exported in the minified version of ko, without that you can give the false
|
491 | // impression that some functions will be available in production builds.
|
492 | //
|
493 | interface KnockoutUtils {
|
494 | //////////////////////////////////
|
495 | // utils.domData.js
|
496 | //////////////////////////////////
|
497 |
|
498 | domData: {
|
499 | get(node: Node, key: string): any;
|
500 |
|
501 | set(node: Node, key: string, value: any): void;
|
502 |
|
503 | getAll(node: Node, createIfNotFound: boolean): any;
|
504 |
|
505 | clear(node: Node): boolean;
|
506 | };
|
507 |
|
508 | //////////////////////////////////
|
509 | // utils.domNodeDisposal.js
|
510 | //////////////////////////////////
|
511 |
|
512 | domNodeDisposal: {
|
513 | addDisposeCallback(node: Node, callback: Function): void;
|
514 |
|
515 | removeDisposeCallback(node: Node, callback: Function): void;
|
516 |
|
517 | cleanNode(node: Node): Node;
|
518 |
|
519 | removeNode(node: Node): void;
|
520 | };
|
521 |
|
522 | addOrRemoveItem<T>(array: T[] | KnockoutObservable<T>, value: T, included: T): void;
|
523 |
|
524 | arrayFilter<T>(array: T[], predicate: (item: T) => boolean): T[];
|
525 |
|
526 | arrayFirst<T>(array: T[], predicate: (item: T) => boolean, predicateOwner?: any): T;
|
527 |
|
528 | arrayForEach<T>(array: T[], action: (item: T, index: number) => void): void;
|
529 |
|
530 | arrayGetDistinctValues<T>(array: T[]): T[];
|
531 |
|
532 | arrayIndexOf<T>(array: T[], item: T): number;
|
533 |
|
534 | arrayMap<T, U>(array: T[], mapping: (item: T) => U): U[];
|
535 |
|
536 | arrayPushAll<T>(array: T[] | KnockoutObservableArray<T>, valuesToPush: T[]): T[];
|
537 |
|
538 | arrayRemoveItem(array: any[], itemToRemove: any): void;
|
539 |
|
540 | compareArrays<T>(a: T[], b: T[]): Array<KnockoutArrayChange<T>>;
|
541 |
|
542 | extend(target: Object, source: Object): Object;
|
543 |
|
544 | fieldsIncludedWithJsonPost: any[];
|
545 |
|
546 | getFormFields(form: any, fieldName: string): any[];
|
547 |
|
548 | objectForEach(obj: any, action: (key: any, value: any) => void): void;
|
549 |
|
550 | parseHtmlFragment(html: string): any[];
|
551 |
|
552 | parseJson(jsonString: string): any;
|
553 |
|
554 | postJson(urlOrForm: any, data: any, options: any): void;
|
555 |
|
556 | peekObservable<T>(value: KnockoutObservable<T> | T): T;
|
557 |
|
558 | range(min: any, max: any): any;
|
559 |
|
560 | registerEventHandler(element: any, eventType: any, handler: Function): void;
|
561 |
|
562 | setHtml(node: Element, html: () => string): void;
|
563 |
|
564 | setHtml(node: Element, html: string): void;
|
565 |
|
566 | setTextContent(element: any, textContent: string | KnockoutObservable<string>): void;
|
567 |
|
568 | stringifyJson(data: any, replacer?: Function, space?: string): string;
|
569 |
|
570 | toggleDomNodeCssClass(node: any, className: string, shouldHaveClass: boolean): void;
|
571 |
|
572 | triggerEvent(element: any, eventType: any): void;
|
573 |
|
574 | unwrapObservable<T>(value: KnockoutObservable<T> | T): T;
|
575 | unwrapObservable<T>(value: KnockoutObservableArray<T> | T[]): T[];
|
576 |
|
577 | // NOT PART OF THE MINIFIED API SURFACE (ONLY IN knockout-{version}.debug.js) https://github.com/SteveSanderson/knockout/issues/670
|
578 | // forceRefresh(node: any): void;
|
579 | // ieVersion: number;
|
580 | // isIe6: boolean;
|
581 | // isIe7: boolean;
|
582 | // jQueryHtmlParse(html: string): any[];
|
583 | // makeArray(arrayLikeObject: any): any[];
|
584 | // moveCleanedNodesToContainerElement(nodes: any[]): HTMLElement;
|
585 | // replaceDomNodes(nodeToReplaceOrNodeArray: any, newNodesArray: any[]): void;
|
586 | // setDomNodeChildren(domNode: any, childNodes: any[]): void;
|
587 | // setElementName(element: any, name: string): void;
|
588 | // setOptionNodeSelectionState(optionNode: any, isSelected: boolean): void;
|
589 | // simpleHtmlParse(html: string): any[];
|
590 | // stringStartsWith(str: string, startsWith: string): boolean;
|
591 | // stringTokenize(str: string, delimiter: string): string[];
|
592 | // stringTrim(str: string): string;
|
593 | // tagNameLower(element: any): string;
|
594 | }
|
595 |
|
596 | interface KnockoutArrayChange<T> {
|
597 | status: "added" | "deleted" | "retained";
|
598 | value: T;
|
599 | index: number;
|
600 | moved?: number | undefined;
|
601 | }
|
602 |
|
603 | //////////////////////////////////
|
604 | // templateSources.js
|
605 | //////////////////////////////////
|
606 |
|
607 | interface KnockoutTemplateSourcesDomElement {
|
608 | text(): any;
|
609 | text(value: any): void;
|
610 |
|
611 | data(key: string): any;
|
612 | data(key: string, value: any): any;
|
613 | }
|
614 |
|
615 | interface KnockoutTemplateAnonymous extends KnockoutTemplateSourcesDomElement {
|
616 | nodes(): any;
|
617 | nodes(value: any): void;
|
618 | }
|
619 |
|
620 | interface KnockoutTemplateSources {
|
621 | domElement: {
|
622 | prototype: KnockoutTemplateSourcesDomElement;
|
623 | new(element: Element): KnockoutTemplateSourcesDomElement;
|
624 | };
|
625 |
|
626 | anonymousTemplate: {
|
627 | prototype: KnockoutTemplateAnonymous;
|
628 | new(element: Element): KnockoutTemplateAnonymous;
|
629 | };
|
630 | }
|
631 |
|
632 | //////////////////////////////////
|
633 | // nativeTemplateEngine.js
|
634 | //////////////////////////////////
|
635 |
|
636 | interface KnockoutNativeTemplateEngine extends KnockoutTemplateEngine {
|
637 | renderTemplateSource(templateSource: Object, bindingContext?: KnockoutBindingContext, options?: Object): any[];
|
638 | }
|
639 |
|
640 | //////////////////////////////////
|
641 | // templateEngine.js
|
642 | //////////////////////////////////
|
643 |
|
644 | interface KnockoutTemplateEngine {
|
645 | createJavaScriptEvaluatorBlock(script: string): string;
|
646 |
|
647 | makeTemplateSource(template: any, templateDocument?: Document): any;
|
648 |
|
649 | renderTemplate(
|
650 | template: any,
|
651 | bindingContext: KnockoutBindingContext,
|
652 | options: Object,
|
653 | templateDocument: Document,
|
654 | ): any;
|
655 |
|
656 | isTemplateRewritten(template: any, templateDocument: Document): boolean;
|
657 |
|
658 | rewriteTemplate(template: any, rewriterCallback: Function, templateDocument: Document): void;
|
659 | }
|
660 |
|
661 | //////////////////////////////////
|
662 | // tasks.js
|
663 | //////////////////////////////////
|
664 |
|
665 | interface KnockoutTasks {
|
666 | scheduler: (callback: Function) => any;
|
667 | schedule(task: Function): number;
|
668 | cancel(handle: number): void;
|
669 | runEarly(): void;
|
670 | }
|
671 |
|
672 |
|
673 | interface KnockoutStatic {
|
674 | utils: KnockoutUtils;
|
675 | memoization: KnockoutMemoization;
|
676 |
|
677 | bindingHandlers: KnockoutBindingHandlers;
|
678 | getBindingHandler(handler: string): KnockoutBindingHandler;
|
679 |
|
680 | virtualElements: KnockoutVirtualElements;
|
681 | extenders: KnockoutExtenders;
|
682 |
|
683 | applyBindings(viewModelOrBindingContext?: any, rootNode?: any): void;
|
684 | applyBindingsToDescendants(viewModelOrBindingContext: any, rootNode: any): void;
|
685 | applyBindingAccessorsToNode(
|
686 | node: Node,
|
687 | bindings: (bindingContext: KnockoutBindingContext, node: Node) => {},
|
688 | bindingContext: KnockoutBindingContext,
|
689 | ): void;
|
690 | applyBindingAccessorsToNode(node: Node, bindings: {}, bindingContext: KnockoutBindingContext): void;
|
691 | applyBindingAccessorsToNode(
|
692 | node: Node,
|
693 | bindings: (bindingContext: KnockoutBindingContext, node: Node) => {},
|
694 | viewModel: any,
|
695 | ): void;
|
696 | applyBindingAccessorsToNode(node: Node, bindings: {}, viewModel: any): void;
|
697 | applyBindingsToNode(node: Node, bindings: any, viewModelOrBindingContext?: any): any;
|
698 |
|
699 | subscribable: KnockoutSubscribableStatic;
|
700 | observable: KnockoutObservableStatic;
|
701 |
|
702 | computed: KnockoutComputedStatic;
|
703 | |
704 |
|
705 |
|
706 |
|
707 |
|
708 | pureComputed<T>(evaluatorFunction: () => T, context?: any): KnockoutComputed<T>;
|
709 | /**
|
710 | * Creates a pure computed observable.
|
711 | * @param options An object that defines the computed observable options and behavior.
|
712 | * @param context Defines the value of 'this' when evaluating the computed observable.
|
713 | */
|
714 | pureComputed<T>(options: KnockoutComputedDefine<T>, context?: any): KnockoutComputed<T>;
|
715 |
|
716 | observableArray: KnockoutObservableArrayStatic;
|
717 |
|
718 | /**
|
719 | * Evaluates if instance is a KnockoutSubscribable.
|
720 | * @param instance Instance to be evaluated.
|
721 | */
|
722 | isSubscribable(instance: any): instance is KnockoutSubscribable<any>;
|
723 | /**
|
724 | * Clones object substituting each observable for it's underlying value. Uses browser JSON.stringify internally to stringify the result.
|
725 | * @param viewModel Object with observables to be converted.
|
726 | * @param replacer A Function or array of names that alters the behavior of the stringification process.
|
727 | * @param space Used to insert white space into the output JSON string for readability purposes.
|
728 | */
|
729 | toJSON(viewModel: any, replacer?: Function | [string | number], space?: string | number): string;
|
730 | /**
|
731 | * Clones object substituting for each observable the current value of that observable.
|
732 | * @param viewModel Object with observables to be converted.
|
733 | */
|
734 | toJS(viewModel: any): any;
|
735 | /**
|
736 | * Determine if argument is an observable. Returns true for observables, observable arrays, and all computed observables.
|
737 | * @param instance Object to be checked.
|
738 | */
|
739 | isObservable(instance: any): instance is KnockoutObservable<any>;
|
740 | /**
|
741 | * Determine if argument is an observable. Returns true for observables, observable arrays, and all computed observables.
|
742 | * @param instance Object to be checked.
|
743 | */
|
744 | isObservable<T>(instance: KnockoutObservable<T> | T): instance is KnockoutObservable<T>;
|
745 | /**
|
746 | * Determine if argument is a writable observable. Returns true for observables, observable arrays, and writable computed observables.
|
747 | * @param instance Object to be checked.
|
748 | */
|
749 | isWriteableObservable(instance: any): instance is KnockoutObservable<any>;
|
750 | /**
|
751 | * Determine if argument is a writable observable. Returns true for observables, observable arrays, and writable computed observables.
|
752 | * @param instance Object to be checked.
|
753 | */
|
754 | isWriteableObservable<T>(instance: KnockoutObservable<T> | T): instance is KnockoutObservable<T>;
|
755 | /**
|
756 | * Determine if argument is a computed observable.
|
757 | * @param instance Object to be checked.
|
758 | */
|
759 | isComputed(instance: any): instance is KnockoutComputed<any>;
|
760 | /**
|
761 | * Determine if argument is a computed observable.
|
762 | * @param instance Object to be checked.
|
763 | */
|
764 | isComputed<T>(instance: KnockoutObservable<T> | T): instance is KnockoutComputed<T>;
|
765 |
|
766 | /**
|
767 | * Returns the data that was available for binding against the element.
|
768 | * @param node Html node that contains the binding context.
|
769 | */
|
770 | dataFor(node: Node): any;
|
771 | /**
|
772 | * Returns the entire binding context that was available to the DOM element.
|
773 | * @param node Html node that contains the binding context.
|
774 | */
|
775 | contextFor(node: Node): any;
|
776 | /**
|
777 | * Removes a node from the DOM.
|
778 | * @param node Node to be removed.
|
779 | */
|
780 | removeNode(node: Node): void;
|
781 | /**
|
782 | * Used internally by Knockout to clean up data/computeds that it created related to the element. It does not remove any event handlers added by bindings.
|
783 | * @param node Node to be cleaned.
|
784 | */
|
785 | cleanNode(node: Node): Node;
|
786 | renderTemplate(template: Function, viewModel: any, options?: any, target?: any, renderMode?: any): any;
|
787 | renderTemplate(template: string, viewModel: any, options?: any, target?: any, renderMode?: any): any;
|
788 | /**
|
789 | * Returns the underlying value of the Knockout Observable or in case of plain js object, return the object. Use this to easily accept both observable and plain values.
|
790 | * @param instance observable to be unwraped if it's an Observable.
|
791 | */
|
792 | unwrap<T>(instance: KnockoutObservable<T> | T): T;
|
793 | /**
|
794 | * Gets the array inside the KnockoutObservableArray.
|
795 | * @param instance observable to be unwraped.
|
796 | */
|
797 | unwrap<T>(instance: KnockoutObservableArray<T> | T[]): T[];
|
798 |
|
799 | /**
|
800 | * Get information about the current computed property during the execution of a computed observable’s evaluator function.
|
801 | */
|
802 | computedContext: KnockoutComputedContext;
|
803 |
|
804 | //////////////////////////////////
|
805 | // templateSources.js
|
806 | //////////////////////////////////
|
807 |
|
808 | templateSources: KnockoutTemplateSources;
|
809 |
|
810 | //////////////////////////////////
|
811 | // templateEngine.js
|
812 | //////////////////////////////////
|
813 |
|
814 | templateEngine: {
|
815 | prototype: KnockoutTemplateEngine;
|
816 |
|
817 | new(): KnockoutTemplateEngine;
|
818 | };
|
819 |
|
820 | //////////////////////////////////
|
821 | // templateRewriting.js
|
822 | //////////////////////////////////
|
823 |
|
824 | templateRewriting: {
|
825 | ensureTemplateIsRewritten(
|
826 | template: Node,
|
827 | templateEngine: KnockoutTemplateEngine,
|
828 | templateDocument: Document,
|
829 | ): any;
|
830 | ensureTemplateIsRewritten(
|
831 | template: string,
|
832 | templateEngine: KnockoutTemplateEngine,
|
833 | templateDocument: Document,
|
834 | ): any;
|
835 |
|
836 | memoizeBindingAttributeSyntax(htmlString: string, templateEngine: KnockoutTemplateEngine): any;
|
837 |
|
838 | applyMemoizedBindingsToNextSibling(bindings: any, nodeName: string): string;
|
839 | };
|
840 |
|
841 | //////////////////////////////////
|
842 | // nativeTemplateEngine.js
|
843 | //////////////////////////////////
|
844 |
|
845 | nativeTemplateEngine: {
|
846 | prototype: KnockoutNativeTemplateEngine;
|
847 |
|
848 | new(): KnockoutNativeTemplateEngine;
|
849 |
|
850 | instance: KnockoutNativeTemplateEngine;
|
851 | };
|
852 |
|
853 | //////////////////////////////////
|
854 | // jqueryTmplTemplateEngine.js
|
855 | //////////////////////////////////
|
856 |
|
857 | jqueryTmplTemplateEngine: {
|
858 | prototype: KnockoutTemplateEngine;
|
859 |
|
860 | renderTemplateSource(templateSource: Object, bindingContext: KnockoutBindingContext, options: Object): Node[];
|
861 |
|
862 | createJavaScriptEvaluatorBlock(script: string): string;
|
863 |
|
864 | addTemplate(templateName: string, templateMarkup: string): void;
|
865 | };
|
866 |
|
867 | //////////////////////////////////
|
868 | // templating.js
|
869 | //////////////////////////////////
|
870 |
|
871 | setTemplateEngine(templateEngine: KnockoutNativeTemplateEngine | undefined): void;
|
872 |
|
873 | renderTemplate(
|
874 | template: Function,
|
875 | dataOrBindingContext: KnockoutBindingContext,
|
876 | options: Object,
|
877 | targetNodeOrNodeArray: Node,
|
878 | renderMode: string,
|
879 | ): any;
|
880 | renderTemplate(
|
881 | template: any,
|
882 | dataOrBindingContext: KnockoutBindingContext,
|
883 | options: Object,
|
884 | targetNodeOrNodeArray: Node,
|
885 | renderMode: string,
|
886 | ): any;
|
887 | renderTemplate(
|
888 | template: Function,
|
889 | dataOrBindingContext: any,
|
890 | options: Object,
|
891 | targetNodeOrNodeArray: Node,
|
892 | renderMode: string,
|
893 | ): any;
|
894 | renderTemplate(
|
895 | template: any,
|
896 | dataOrBindingContext: any,
|
897 | options: Object,
|
898 | targetNodeOrNodeArray: Node,
|
899 | renderMode: string,
|
900 | ): any;
|
901 | renderTemplate(
|
902 | template: Function,
|
903 | dataOrBindingContext: KnockoutBindingContext,
|
904 | options: Object,
|
905 | targetNodeOrNodeArray: Node[],
|
906 | renderMode: string,
|
907 | ): any;
|
908 | renderTemplate(
|
909 | template: any,
|
910 | dataOrBindingContext: KnockoutBindingContext,
|
911 | options: Object,
|
912 | targetNodeOrNodeArray: Node[],
|
913 | renderMode: string,
|
914 | ): any;
|
915 | renderTemplate(
|
916 | template: Function,
|
917 | dataOrBindingContext: any,
|
918 | options: Object,
|
919 | targetNodeOrNodeArray: Node[],
|
920 | renderMode: string,
|
921 | ): any;
|
922 | renderTemplate(
|
923 | template: any,
|
924 | dataOrBindingContext: any,
|
925 | options: Object,
|
926 | targetNodeOrNodeArray: Node[],
|
927 | renderMode: string,
|
928 | ): any;
|
929 |
|
930 | renderTemplateForEach(
|
931 | template: Function,
|
932 | arrayOrObservableArray: any[],
|
933 | options: Object,
|
934 | targetNode: Node,
|
935 | parentBindingContext: KnockoutBindingContext,
|
936 | ): any;
|
937 | renderTemplateForEach(
|
938 | template: any,
|
939 | arrayOrObservableArray: any[],
|
940 | options: Object,
|
941 | targetNode: Node,
|
942 | parentBindingContext: KnockoutBindingContext,
|
943 | ): any;
|
944 | renderTemplateForEach(
|
945 | template: Function,
|
946 | arrayOrObservableArray: KnockoutObservable<any>,
|
947 | options: Object,
|
948 | targetNode: Node,
|
949 | parentBindingContext: KnockoutBindingContext,
|
950 | ): any;
|
951 | renderTemplateForEach(
|
952 | template: any,
|
953 | arrayOrObservableArray: KnockoutObservable<any>,
|
954 | options: Object,
|
955 | targetNode: Node,
|
956 | parentBindingContext: KnockoutBindingContext,
|
957 | ): any;
|
958 |
|
959 | /**
|
960 | * Executes a callback function inside a computed observable, without creating a dependecy between it and the observables inside the function.
|
961 | * @param callback Function to be called.
|
962 | * @param callbackTarget Defines the value of 'this' in the callback function.
|
963 | * @param callbackArgs Arguments for the callback Function.
|
964 | */
|
965 | ignoreDependencies<T>(callback: () => T, callbackTarget?: any, callbackArgs?: any): T;
|
966 |
|
967 | expressionRewriting: {
|
968 | bindingRewriteValidators: any[];
|
969 | twoWayBindings: any;
|
970 | parseObjectLiteral: (objectLiteralString: string) => any[];
|
971 |
|
972 | |
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 | writeValueToProperty: (
|
988 | property: KnockoutObservable<any> | any,
|
989 | allBindings: KnockoutAllBindingsAccessor,
|
990 | key: string,
|
991 | value: any,
|
992 | checkIfDifferent?: boolean,
|
993 | ) => void;
|
994 | };
|
995 |
|
996 |
|
997 |
|
998 | bindingProvider: {
|
999 | instance: KnockoutBindingProvider;
|
1000 | new(): KnockoutBindingProvider;
|
1001 | };
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 | selectExtensions: {
|
1008 | readValue(element: HTMLElement): any;
|
1009 |
|
1010 | writeValue(element: HTMLElement, value: any, allowUnset?: boolean): void;
|
1011 | };
|
1012 |
|
1013 | components: KnockoutComponents;
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 | options: {
|
1020 | deferUpdates: boolean;
|
1021 |
|
1022 | useOnlyNativeEvents: boolean;
|
1023 | };
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 | tasks: KnockoutTasks;
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 | onError?: ((error: Error) => void) | undefined;
|
1036 | }
|
1037 |
|
1038 | interface KnockoutBindingProvider {
|
1039 | nodeHasBindings(node: Node): boolean;
|
1040 | getBindings(node: Node, bindingContext: KnockoutBindingContext): {};
|
1041 | getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string };
|
1042 | }
|
1043 |
|
1044 | interface KnockoutComputedContext {
|
1045 | /**
|
1046 | * Returns the number of dependencies of the computed observable detected so far during the current evaluation.
|
1047 | */
|
1048 | getDependenciesCount(): number;
|
1049 | /**
|
1050 | * A function that returns true if called during the first ever evaluation of the current computed observable, or false otherwise.
|
1051 | * For pure computed observables, isInitial() is always undefined.
|
1052 | */
|
1053 | isInitial: () => boolean;
|
1054 | isSleeping: boolean;
|
1055 | }
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 | declare namespace KnockoutComponentTypes {
|
1062 | type ViewModel = ViewModelFunction | ViewModelSharedInstance | ViewModelFactoryFunction | AMDModule;
|
1063 |
|
1064 | interface Config<T> {
|
1065 | viewModel?: T | undefined;
|
1066 | template: string | Node[] | DocumentFragment | TemplateElement | AMDModule;
|
1067 | synchronous?: boolean | undefined;
|
1068 | }
|
1069 |
|
1070 | interface ComponentConfig<T = ViewModel> {
|
1071 | viewModel?: T | undefined;
|
1072 | template: any;
|
1073 | createViewModel?: any;
|
1074 | }
|
1075 |
|
1076 | interface EmptyConfig {
|
1077 | }
|
1078 |
|
1079 |
|
1080 | interface AMDModule {
|
1081 | require: string;
|
1082 | }
|
1083 |
|
1084 |
|
1085 | interface ViewModelFunction {
|
1086 | (params?: any): any;
|
1087 | }
|
1088 |
|
1089 | interface ViewModelSharedInstance {
|
1090 | instance: any;
|
1091 | }
|
1092 |
|
1093 | interface ViewModelFactoryFunction {
|
1094 | createViewModel: (params: any, componentInfo: ComponentInfo) => any;
|
1095 | }
|
1096 |
|
1097 | interface ComponentInfo {
|
1098 | element: Node;
|
1099 | templateNodes: Node[];
|
1100 | }
|
1101 |
|
1102 | interface TemplateElement {
|
1103 | element: string | Node;
|
1104 | }
|
1105 |
|
1106 | interface Loader {
|
1107 | |
1108 |
|
1109 |
|
1110 |
|
1111 | getConfig?(componentName: string, callback: (result: ComponentConfig | null) => void): void;
|
1112 | /**
|
1113 | * Define this if: you want to take control over how component configurations are interpreted, e.g., if you do not want to use the standard 'viewModel/template' pair format.
|
1114 | * @see {@link https://knockoutjs.com/documentation/component-loaders.html}
|
1115 | */
|
1116 | loadComponent?(
|
1117 | componentName: string,
|
1118 | config: ComponentConfig,
|
1119 | callback: (result: Definition | null) => void,
|
1120 | ): void;
|
1121 | /**
|
1122 | * Define this if: you want to use custom logic to supply DOM nodes for a given template configuration (e.g., using an ajax request to fetch a template by URL).
|
1123 | * @see {@link https://knockoutjs.com/documentation/component-loaders.html}
|
1124 | */
|
1125 | loadTemplate?(componentName: string, templateConfig: any, callback: (result: Node[] | null) => void): void;
|
1126 | /**
|
1127 | * Define this if: you want to use custom logic to supply a viewmodel factory for a given viewmodel configuration (e.g., integrating with a third-party module loader or dependency injection system).
|
1128 | * @see {@link https://knockoutjs.com/documentation/component-loaders.html}
|
1129 | */
|
1130 | loadViewModel?(componentName: string, viewModelConfig: any, callback: (result: any) => void): void;
|
1131 | suppressLoaderExceptions?: boolean | undefined;
|
1132 | }
|
1133 |
|
1134 | interface Definition {
|
1135 | template: Node[];
|
1136 | createViewModel?(params: any, options: { element: Node }): any;
|
1137 | }
|
1138 | }
|
1139 |
|
1140 | interface KnockoutComponents {
|
1141 | /**
|
1142 | * Registers a component, in the default component loader, to be used by name in the component binding.
|
1143 | * @param componentName Component name. Will be used for your custom HTML tag name.
|
1144 | * @param config Component configuration.
|
1145 | */
|
1146 | register<T = KnockoutComponentTypes.ViewModel>(
|
1147 | componentName: string,
|
1148 | config: KnockoutComponentTypes.Config<T> | KnockoutComponentTypes.EmptyConfig,
|
1149 | ): void;
|
1150 | /**
|
1151 | * Determine if a component with the specified name is already registered in the default component loader.
|
1152 | * @param componentName Component name.
|
1153 | */
|
1154 | isRegistered(componentName: string): boolean;
|
1155 | /**
|
1156 | * Removes the named component from the default component loader registry. Or if no such component was registered, does nothing.
|
1157 | * @param componentName Component name.
|
1158 | */
|
1159 | unregister(componentName: string): void;
|
1160 | /**
|
1161 | * Searchs each registered component loader by component name, and returns the viewmodel/template declaration via callback parameter.
|
1162 | * @param componentName Component name.
|
1163 | * @param callback Function to be called with the viewmodel/template declaration parameter.
|
1164 | */
|
1165 | get(componentName: string, callback: (definition: KnockoutComponentTypes.Definition) => void): void;
|
1166 | /**
|
1167 | * Clears the cache knockout creates to speed up component loading, for a given component.
|
1168 | * @param componentName Component name.
|
1169 | */
|
1170 | clearCachedDefinition(componentName: string): void;
|
1171 | defaultLoader: KnockoutComponentTypes.Loader;
|
1172 | loaders: KnockoutComponentTypes.Loader[];
|
1173 | /**
|
1174 | * Returns the registered component name for a HTML element. Can be overwriten to to control dynamically which HTML element map to which component name.
|
1175 | * @param node html element that corresponds to a custom component.
|
1176 | */
|
1177 | getComponentNameForNode(node: Node): string;
|
1178 | }
|
1179 |
|
1180 | declare var ko: KnockoutStatic;
|
1181 |
|
1182 | declare module "knockout" {
|
1183 | export = ko;
|
1184 | }
|
1185 |
|
\ | No newline at end of file |