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> extends KnockoutReadonlyObservable<ReadonlyArray<T>>, KnockoutReadonlyObservableArrayFunctions<T> {
|
250 | // NOTE: Keep in sync with KnockoutObservableArray<T>, see note on KnockoutObservableArray<T>
|
251 | subscribe(callback: (newValue: KnockoutArrayChange<T>[]) => void, target: any, event: "arrayChange"): KnockoutSubscription;
|
252 | subscribe(callback: (newValue: T[]) => void, target: any, event: "beforeChange"): KnockoutSubscription;
|
253 | subscribe(callback: (newValue: T[]) => void, target?: any, event?: "change"): KnockoutSubscription;
|
254 | subscribe<U>(callback: (newValue: U) => void, target: any, event: string): KnockoutSubscription;
|
255 | }
|
256 |
|
257 | /*
|
258 | NOTE: In theory this should extend both KnockoutObservable<T[]> and KnockoutReadonlyObservableArray<T>,
|
259 | but can't since they both provide conflicting typings of .subscribe.
|
260 | So it extends KnockoutObservable<T[]> and duplicates the subscribe definitions, which should be kept in sync
|
261 | */
|
262 | interface KnockoutObservableArray<T> extends KnockoutObservable<T[]>, KnockoutObservableArrayFunctions<T> {
|
263 | subscribe(callback: (newValue: KnockoutArrayChange<T>[]) => void, target: any, event: "arrayChange"): KnockoutSubscription;
|
264 | subscribe(callback: (newValue: T[]) => void, target: any, event: "beforeChange"): KnockoutSubscription;
|
265 | subscribe(callback: (newValue: T[]) => void, target?: any, event?: "change"): KnockoutSubscription;
|
266 | subscribe<U>(callback: (newValue: U) => void, target: any, event: string): KnockoutSubscription;
|
267 |
|
268 | extend(requestedExtenders: { [key: string]: any; }): KnockoutObservableArray<T>;
|
269 | }
|
270 |
|
271 | interface KnockoutObservableStatic {
|
272 | fn: KnockoutObservableFunctions<any>;
|
273 |
|
274 | <T>(value: T): KnockoutObservable<T>;
|
275 | <T = any>(value: null): KnockoutObservable<T | null>
|
276 | <T = any>(): KnockoutObservable<T | undefined>
|
277 | }
|
278 |
|
279 | /**
|
280 | * While all observable are writable at runtime, this type is analogous to the native ReadonlyArray type:
|
281 | * casting an observable to this type expresses the intention that this observable shouldn't be mutated.
|
282 | */
|
283 | interface KnockoutReadonlyObservable<T> extends KnockoutSubscribable<T>, KnockoutObservableFunctions<T> {
|
284 | (): T;
|
285 |
|
286 | /**
|
287 | * Returns the current value of the computed observable without creating a dependency.
|
288 | */
|
289 | peek(): T;
|
290 | valueHasMutated?: { (): void; };
|
291 | valueWillMutate?: { (): void; };
|
292 | }
|
293 |
|
294 | interface KnockoutObservable<T> extends KnockoutReadonlyObservable<T> {
|
295 | (value: T): void;
|
296 |
|
297 | // Since .extend does arbitrary thing to an observable, it's not safe to do on a readonly observable
|
298 | /**
|
299 | * Customizes observables basic functionality.
|
300 | * @param requestedExtenders Name of the extender feature and it's value, e.g. { notify: 'always' }, { rateLimit: 50 }
|
301 | */
|
302 | extend(requestedExtenders: { [key: string]: any; }): KnockoutObservable<T>;
|
303 | }
|
304 |
|
305 | interface KnockoutComputedOptions<T> {
|
306 | /**
|
307 | * Makes the computed observable writable. This is a function that receives values that other code is trying to write to your computed observable.
|
308 | * It’s up to you to supply custom logic to handle the incoming values, typically by writing the values to some underlying observable(s).
|
309 | * @param value Value being written to the computer observable.
|
310 | */
|
311 | write?(value: T): void;
|
312 | /**
|
313 | * Disposal of the computed observable will be triggered when the specified DOM node is removed by KO.
|
314 | * This feature is used to dispose computed observables used in bindings when nodes are removed by the template and control-flow bindings.
|
315 | */
|
316 | disposeWhenNodeIsRemoved?: Node;
|
317 | /**
|
318 | * This function is executed before each re-evaluation to determine if the computed observable should be disposed.
|
319 | * A true-ish result will trigger disposal of the computed observable.
|
320 | */
|
321 | disposeWhen?(): boolean;
|
322 | /**
|
323 | * Defines the value of 'this' whenever KO invokes your 'read' or 'write' callbacks.
|
324 | */
|
325 | owner?: any;
|
326 | /**
|
327 | * 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.
|
328 | * By default, a computed observable has its value determined immediately during creation.
|
329 | */
|
330 | deferEvaluation?: boolean;
|
331 | /**
|
332 | * If true, the computed observable will be set up as a purecomputed observable. This option is an alternative to the ko.pureComputed constructor.
|
333 | */
|
334 | pure?: boolean;
|
335 | }
|
336 |
|
337 | interface KnockoutComputedDefine<T> extends KnockoutComputedOptions<T> {
|
338 | /**
|
339 | * A function that is used to evaluate the computed observable’s current value.
|
340 | */
|
341 | read(): T;
|
342 | }
|
343 |
|
344 | interface KnockoutBindingContext {
|
345 | $parent: any;
|
346 | $parents: any[];
|
347 | $root: any;
|
348 | $data: any;
|
349 | $rawData: any | KnockoutObservable<any>;
|
350 | $index?: KnockoutObservable<number>;
|
351 | $parentContext?: KnockoutBindingContext;
|
352 | $component: any;
|
353 | $componentTemplateNodes: Node[];
|
354 |
|
355 | /**
|
356 | * Clones the current Binding Context, adding extra properties to it.
|
357 | * @param properties object with properties to be added in the binding context.
|
358 | */
|
359 | extend(properties: { [key: string]: any; } | (() => { [key: string]: any; })): KnockoutBindingContext;
|
360 | /**
|
361 | * This returns a new binding context whose viewmodel is the first parameter and whose $parentContext is the current bindingContext.
|
362 | * @param dataItemOrAccessor The binding context of the children.
|
363 | * @param dataItemAlias An alias for the data item in descendant contexts.
|
364 | * @param extendCallback Function to be called.
|
365 | * @param options Further options.
|
366 | */
|
367 | createChildContext(dataItemOrAccessor: any, dataItemAlias?: string, extendCallback?: Function, options?: { "exportDependencies": boolean }): any;
|
368 | }
|
369 |
|
370 | interface KnockoutAllBindingsAccessor {
|
371 | (): any;
|
372 | get(name: string): any;
|
373 | has(name: string): boolean;
|
374 | }
|
375 |
|
376 | interface KnockoutBindingHandler<E extends Node = any, V = any, VM = any> {
|
377 | after?: Array<string>;
|
378 | init?: (element: E, valueAccessor: () => V, allBindingsAccessor: KnockoutAllBindingsAccessor, viewModel: VM, bindingContext: KnockoutBindingContext) => void | { controlsDescendantBindings: boolean; };
|
379 | update?: (element: E, valueAccessor: () => V, allBindingsAccessor: KnockoutAllBindingsAccessor, viewModel: VM, bindingContext: KnockoutBindingContext) => void;
|
380 | options?: any;
|
381 | preprocess?: (value: string, name: string, addBindingCallback?: (name: string, value: string) => void) => string;
|
382 | [s: string]: any;
|
383 | }
|
384 |
|
385 | interface KnockoutBindingHandlers {
|
386 | [bindingHandler: string]: KnockoutBindingHandler;
|
387 |
|
388 |
|
389 | visible: KnockoutBindingHandler;
|
390 | text: KnockoutBindingHandler;
|
391 | html: KnockoutBindingHandler;
|
392 | css: KnockoutBindingHandler;
|
393 | style: KnockoutBindingHandler;
|
394 | attr: KnockoutBindingHandler;
|
395 |
|
396 |
|
397 | foreach: KnockoutBindingHandler;
|
398 | if: KnockoutBindingHandler;
|
399 | ifnot: KnockoutBindingHandler;
|
400 | with: KnockoutBindingHandler;
|
401 |
|
402 |
|
403 | click: KnockoutBindingHandler;
|
404 | event: KnockoutBindingHandler;
|
405 | submit: KnockoutBindingHandler;
|
406 | enable: KnockoutBindingHandler;
|
407 | disable: KnockoutBindingHandler;
|
408 | value: KnockoutBindingHandler;
|
409 | textInput: KnockoutBindingHandler;
|
410 | hasfocus: KnockoutBindingHandler;
|
411 | checked: KnockoutBindingHandler;
|
412 | options: KnockoutBindingHandler;
|
413 | selectedOptions: KnockoutBindingHandler;
|
414 | uniqueName: KnockoutBindingHandler;
|
415 |
|
416 |
|
417 | template: KnockoutBindingHandler;
|
418 |
|
419 |
|
420 | component: KnockoutBindingHandler;
|
421 | }
|
422 |
|
423 | interface KnockoutMemoization {
|
424 | memoize(callback: Function): string;
|
425 | unmemoize(memoId: string, callbackParams: any[]): boolean;
|
426 | unmemoizeDomNodeAndDescendants(domNode: any, extraCallbackParamsArray: any[]): boolean;
|
427 | parseMemoText(memoText: string): string;
|
428 | }
|
429 |
|
430 | interface KnockoutVirtualElement { }
|
431 |
|
432 | interface KnockoutVirtualElements {
|
433 | allowedBindings: { [bindingName: string]: boolean; };
|
434 | emptyNode(node: KnockoutVirtualElement): void;
|
435 | firstChild(node: KnockoutVirtualElement): KnockoutVirtualElement;
|
436 | insertAfter(container: KnockoutVirtualElement, nodeToInsert: Node, insertAfter: Node): void;
|
437 | nextSibling(node: KnockoutVirtualElement): Node;
|
438 | prepend(node: KnockoutVirtualElement, toInsert: Node): void;
|
439 | setDomNodeChildren(node: KnockoutVirtualElement, newChildren: { length: number;[index: number]: Node; }): void;
|
440 | childNodes(node: KnockoutVirtualElement): Node[];
|
441 | }
|
442 |
|
443 | interface KnockoutExtenders {
|
444 | throttle(target: any, timeout: number): KnockoutComputed<any>;
|
445 | notify(target: any, notifyWhen: string): any;
|
446 |
|
447 | rateLimit(target: any, timeout: number): any;
|
448 | rateLimit(target: any, options: { timeout: number; method?: string; }): any;
|
449 |
|
450 | trackArrayChanges(target: any): any;
|
451 | }
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 | interface KnockoutUtils {
|
459 |
|
460 |
|
461 |
|
462 |
|
463 | domData: {
|
464 | get(node: Node, key: string): any;
|
465 |
|
466 | set(node: Node, key: string, value: any): void;
|
467 |
|
468 | getAll(node: Node, createIfNotFound: boolean): any;
|
469 |
|
470 | clear(node: Node): boolean;
|
471 | };
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 | domNodeDisposal: {
|
478 | addDisposeCallback(node: Node, callback: Function): void;
|
479 |
|
480 | removeDisposeCallback(node: Node, callback: Function): void;
|
481 |
|
482 | cleanNode(node: Node): Node;
|
483 |
|
484 | removeNode(node: Node): void;
|
485 | };
|
486 |
|
487 | addOrRemoveItem<T>(array: T[] | KnockoutObservable<T>, value: T, included: T): void;
|
488 |
|
489 | arrayFilter<T>(array: T[], predicate: (item: T) => boolean): T[];
|
490 |
|
491 | arrayFirst<T>(array: T[], predicate: (item: T) => boolean, predicateOwner?: any): T;
|
492 |
|
493 | arrayForEach<T>(array: T[], action: (item: T, index: number) => void): void;
|
494 |
|
495 | arrayGetDistinctValues<T>(array: T[]): T[];
|
496 |
|
497 | arrayIndexOf<T>(array: T[], item: T): number;
|
498 |
|
499 | arrayMap<T, U>(array: T[], mapping: (item: T) => U): U[];
|
500 |
|
501 | arrayPushAll<T>(array: T[] | KnockoutObservableArray<T>, valuesToPush: T[]): T[];
|
502 |
|
503 | arrayRemoveItem(array: any[], itemToRemove: any): void;
|
504 |
|
505 | compareArrays<T>(a: T[], b: T[]): Array<KnockoutArrayChange<T>>;
|
506 |
|
507 | extend(target: Object, source: Object): Object;
|
508 |
|
509 | fieldsIncludedWithJsonPost: any[];
|
510 |
|
511 | getFormFields(form: any, fieldName: string): any[];
|
512 |
|
513 | objectForEach(obj: any, action: (key: any, value: any) => void): void;
|
514 |
|
515 | parseHtmlFragment(html: string): any[];
|
516 |
|
517 | parseJson(jsonString: string): any;
|
518 |
|
519 | postJson(urlOrForm: any, data: any, options: any): void;
|
520 |
|
521 | peekObservable<T>(value: KnockoutObservable<T> | T): T;
|
522 |
|
523 | range(min: any, max: any): any;
|
524 |
|
525 | registerEventHandler(element: any, eventType: any, handler: Function): void;
|
526 |
|
527 | setHtml(node: Element, html: () => string): void;
|
528 |
|
529 | setHtml(node: Element, html: string): void;
|
530 |
|
531 | setTextContent(element: any, textContent: string | KnockoutObservable<string>): void;
|
532 |
|
533 | stringifyJson(data: any, replacer?: Function, space?: string): string;
|
534 |
|
535 | toggleDomNodeCssClass(node: any, className: string, shouldHaveClass: boolean): void;
|
536 |
|
537 | triggerEvent(element: any, eventType: any): void;
|
538 |
|
539 | unwrapObservable<T>(value: KnockoutObservable<T> | T): T;
|
540 | unwrapObservable<T>(value: KnockoutObservableArray<T> | T[]): T[];
|
541 |
|
542 | // NOT PART OF THE MINIFIED API SURFACE (ONLY IN knockout-{version}.debug.js) https://github.com/SteveSanderson/knockout/issues/670
|
543 | // forceRefresh(node: any): void;
|
544 | // ieVersion: number;
|
545 | // isIe6: boolean;
|
546 | // isIe7: boolean;
|
547 | // jQueryHtmlParse(html: string): any[];
|
548 | // makeArray(arrayLikeObject: any): any[];
|
549 | // moveCleanedNodesToContainerElement(nodes: any[]): HTMLElement;
|
550 | // replaceDomNodes(nodeToReplaceOrNodeArray: any, newNodesArray: any[]): void;
|
551 | // setDomNodeChildren(domNode: any, childNodes: any[]): void;
|
552 | // setElementName(element: any, name: string): void;
|
553 | // setOptionNodeSelectionState(optionNode: any, isSelected: boolean): void;
|
554 | // simpleHtmlParse(html: string): any[];
|
555 | // stringStartsWith(str: string, startsWith: string): boolean;
|
556 | // stringTokenize(str: string, delimiter: string): string[];
|
557 | // stringTrim(str: string): string;
|
558 | // tagNameLower(element: any): string;
|
559 | }
|
560 |
|
561 | interface KnockoutArrayChange<T> {
|
562 | status: "added" | "deleted" | "retained";
|
563 | value: T;
|
564 | index: number;
|
565 | moved?: number;
|
566 | }
|
567 |
|
568 | //////////////////////////////////
|
569 | // templateSources.js
|
570 | //////////////////////////////////
|
571 |
|
572 | interface KnockoutTemplateSourcesDomElement {
|
573 | text(): any;
|
574 | text(value: any): void;
|
575 |
|
576 | data(key: string): any;
|
577 | data(key: string, value: any): any;
|
578 | }
|
579 |
|
580 | interface KnockoutTemplateAnonymous extends KnockoutTemplateSourcesDomElement {
|
581 | nodes(): any;
|
582 | nodes(value: any): void;
|
583 | }
|
584 |
|
585 | interface KnockoutTemplateSources {
|
586 |
|
587 | domElement: {
|
588 | prototype: KnockoutTemplateSourcesDomElement
|
589 | new(element: Element): KnockoutTemplateSourcesDomElement
|
590 | };
|
591 |
|
592 | anonymousTemplate: {
|
593 | prototype: KnockoutTemplateAnonymous;
|
594 | new(element: Element): KnockoutTemplateAnonymous;
|
595 | };
|
596 | }
|
597 |
|
598 | //////////////////////////////////
|
599 | // nativeTemplateEngine.js
|
600 | //////////////////////////////////
|
601 |
|
602 | interface KnockoutNativeTemplateEngine extends KnockoutTemplateEngine {
|
603 |
|
604 | renderTemplateSource(templateSource: Object, bindingContext?: KnockoutBindingContext, options?: Object): any[];
|
605 | }
|
606 |
|
607 | //////////////////////////////////
|
608 | // templateEngine.js
|
609 | //////////////////////////////////
|
610 |
|
611 | interface KnockoutTemplateEngine {
|
612 |
|
613 | createJavaScriptEvaluatorBlock(script: string): string;
|
614 |
|
615 | makeTemplateSource(template: any, templateDocument?: Document): any;
|
616 |
|
617 | renderTemplate(template: any, bindingContext: KnockoutBindingContext, options: Object, templateDocument: Document): any;
|
618 |
|
619 | isTemplateRewritten(template: any, templateDocument: Document): boolean;
|
620 |
|
621 | rewriteTemplate(template: any, rewriterCallback: Function, templateDocument: Document): void;
|
622 | }
|
623 |
|
624 | //////////////////////////////////
|
625 | // tasks.js
|
626 | //////////////////////////////////
|
627 |
|
628 | interface KnockoutTasks {
|
629 | scheduler: (callback: Function) => any;
|
630 | schedule(task: Function): number;
|
631 | cancel(handle: number): void;
|
632 | runEarly(): void;
|
633 | }
|
634 |
|
635 |
|
636 | interface KnockoutStatic {
|
637 | utils: KnockoutUtils;
|
638 | memoization: KnockoutMemoization;
|
639 |
|
640 | bindingHandlers: KnockoutBindingHandlers;
|
641 | getBindingHandler(handler: string): KnockoutBindingHandler;
|
642 |
|
643 | virtualElements: KnockoutVirtualElements;
|
644 | extenders: KnockoutExtenders;
|
645 |
|
646 | applyBindings(viewModelOrBindingContext?: any, rootNode?: any): void;
|
647 | applyBindingsToDescendants(viewModelOrBindingContext: any, rootNode: any): void;
|
648 | applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, bindingContext: KnockoutBindingContext): void;
|
649 | applyBindingAccessorsToNode(node: Node, bindings: {}, bindingContext: KnockoutBindingContext): void;
|
650 | applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, viewModel: any): void;
|
651 | applyBindingAccessorsToNode(node: Node, bindings: {}, viewModel: any): void;
|
652 | applyBindingsToNode(node: Node, bindings: any, viewModelOrBindingContext?: any): any;
|
653 |
|
654 | subscribable: KnockoutSubscribableStatic;
|
655 | observable: KnockoutObservableStatic;
|
656 |
|
657 | computed: KnockoutComputedStatic;
|
658 | |
659 |
|
660 |
|
661 |
|
662 |
|
663 | pureComputed<T>(evaluatorFunction: () => T, context?: any): KnockoutComputed<T>;
|
664 | /**
|
665 | * Creates a pure computed observable.
|
666 | * @param options An object that defines the computed observable options and behavior.
|
667 | * @param context Defines the value of 'this' when evaluating the computed observable.
|
668 | */
|
669 | pureComputed<T>(options: KnockoutComputedDefine<T>, context?: any): KnockoutComputed<T>;
|
670 |
|
671 | observableArray: KnockoutObservableArrayStatic;
|
672 |
|
673 | /**
|
674 | * Evaluates if instance is a KnockoutSubscribable.
|
675 | * @param instance Instance to be evaluated.
|
676 | */
|
677 | isSubscribable(instance: any): instance is KnockoutSubscribable<any>;
|
678 | /**
|
679 | * Clones object substituting each observable for it's underlying value. Uses browser JSON.stringify internally to stringify the result.
|
680 | * @param viewModel Object with observables to be converted.
|
681 | * @param replacer A Function or array of names that alters the behavior of the stringification process.
|
682 | * @param space Used to insert white space into the output JSON string for readability purposes.
|
683 | */
|
684 | toJSON(viewModel: any, replacer?: Function | [string | number], space?: string | number): string;
|
685 | /**
|
686 | * Clones object substituting for each observable the current value of that observable.
|
687 | * @param viewModel Object with observables to be converted.
|
688 | */
|
689 | toJS(viewModel: any): any;
|
690 | /**
|
691 | * Determine if argument is an observable. Returns true for observables, observable arrays, and all computed observables.
|
692 | * @param instance Object to be checked.
|
693 | */
|
694 | isObservable(instance: any): instance is KnockoutObservable<any>;
|
695 | /**
|
696 | * Determine if argument is an observable. Returns true for observables, observable arrays, and all computed observables.
|
697 | * @param instance Object to be checked.
|
698 | */
|
699 | isObservable<T>(instance: KnockoutObservable<T> | T): instance is KnockoutObservable<T>;
|
700 | /**
|
701 | * Determine if argument is a writable observable. Returns true for observables, observable arrays, and writable computed observables.
|
702 | * @param instance Object to be checked.
|
703 | */
|
704 | isWriteableObservable(instance: any): instance is KnockoutObservable<any>;
|
705 | /**
|
706 | * Determine if argument is a writable observable. Returns true for observables, observable arrays, and writable computed observables.
|
707 | * @param instance Object to be checked.
|
708 | */
|
709 | isWriteableObservable<T>(instance: KnockoutObservable<T> | T): instance is KnockoutObservable<T>;
|
710 | /**
|
711 | * Determine if argument is a computed observable.
|
712 | * @param instance Object to be checked.
|
713 | */
|
714 | isComputed(instance: any): instance is KnockoutComputed<any>;
|
715 | /**
|
716 | * Determine if argument is a computed observable.
|
717 | * @param instance Object to be checked.
|
718 | */
|
719 | isComputed<T>(instance: KnockoutObservable<T> | T): instance is KnockoutComputed<T>;
|
720 |
|
721 | /**
|
722 | * Returns the data that was available for binding against the element.
|
723 | * @param node Html node that contains the binding context.
|
724 | */
|
725 | dataFor(node: Node): any;
|
726 | /**
|
727 | * Returns the entire binding context that was available to the DOM element.
|
728 | * @param node Html node that contains the binding context.
|
729 | */
|
730 | contextFor(node: Node): any;
|
731 | /**
|
732 | * Removes a node from the DOM.
|
733 | * @param node Node to be removed.
|
734 | */
|
735 | removeNode(node: Node): void;
|
736 | /**
|
737 | * 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.
|
738 | * @param node Node to be cleaned.
|
739 | */
|
740 | cleanNode(node: Node): Node;
|
741 | renderTemplate(template: Function, viewModel: any, options?: any, target?: any, renderMode?: any): any;
|
742 | renderTemplate(template: string, viewModel: any, options?: any, target?: any, renderMode?: any): any;
|
743 | /**
|
744 | * 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.
|
745 | * @param instance observable to be unwraped if it's an Observable.
|
746 | */
|
747 | unwrap<T>(instance: KnockoutObservable<T> | T): T;
|
748 | /**
|
749 | * Gets the array inside the KnockoutObservableArray.
|
750 | * @param instance observable to be unwraped.
|
751 | */
|
752 | unwrap<T>(instance: KnockoutObservableArray<T> | T[]): T[];
|
753 |
|
754 | /**
|
755 | * Get information about the current computed property during the execution of a computed observable’s evaluator function.
|
756 | */
|
757 | computedContext: KnockoutComputedContext;
|
758 |
|
759 | //////////////////////////////////
|
760 | // templateSources.js
|
761 | //////////////////////////////////
|
762 |
|
763 | templateSources: KnockoutTemplateSources;
|
764 |
|
765 | //////////////////////////////////
|
766 | // templateEngine.js
|
767 | //////////////////////////////////
|
768 |
|
769 | templateEngine: {
|
770 |
|
771 | prototype: KnockoutTemplateEngine;
|
772 |
|
773 | new(): KnockoutTemplateEngine;
|
774 | };
|
775 |
|
776 | //////////////////////////////////
|
777 | // templateRewriting.js
|
778 | //////////////////////////////////
|
779 |
|
780 | templateRewriting: {
|
781 |
|
782 | ensureTemplateIsRewritten(template: Node, templateEngine: KnockoutTemplateEngine, templateDocument: Document): any;
|
783 | ensureTemplateIsRewritten(template: string, templateEngine: KnockoutTemplateEngine, templateDocument: Document): any;
|
784 |
|
785 | memoizeBindingAttributeSyntax(htmlString: string, templateEngine: KnockoutTemplateEngine): any;
|
786 |
|
787 | applyMemoizedBindingsToNextSibling(bindings: any, nodeName: string): string;
|
788 | };
|
789 |
|
790 | //////////////////////////////////
|
791 | // nativeTemplateEngine.js
|
792 | //////////////////////////////////
|
793 |
|
794 | nativeTemplateEngine: {
|
795 |
|
796 | prototype: KnockoutNativeTemplateEngine;
|
797 |
|
798 | new(): KnockoutNativeTemplateEngine;
|
799 |
|
800 | instance: KnockoutNativeTemplateEngine;
|
801 | };
|
802 |
|
803 | //////////////////////////////////
|
804 | // jqueryTmplTemplateEngine.js
|
805 | //////////////////////////////////
|
806 |
|
807 | jqueryTmplTemplateEngine: {
|
808 |
|
809 | prototype: KnockoutTemplateEngine;
|
810 |
|
811 | renderTemplateSource(templateSource: Object, bindingContext: KnockoutBindingContext, options: Object): Node[];
|
812 |
|
813 | createJavaScriptEvaluatorBlock(script: string): string;
|
814 |
|
815 | addTemplate(templateName: string, templateMarkup: string): void;
|
816 | };
|
817 |
|
818 | //////////////////////////////////
|
819 | // templating.js
|
820 | //////////////////////////////////
|
821 |
|
822 | setTemplateEngine(templateEngine: KnockoutNativeTemplateEngine | undefined): void;
|
823 |
|
824 | renderTemplate(template: Function, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
|
825 | renderTemplate(template: any, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
|
826 | renderTemplate(template: Function, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
|
827 | renderTemplate(template: any, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
|
828 | renderTemplate(template: Function, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
|
829 | renderTemplate(template: any, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
|
830 | renderTemplate(template: Function, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
|
831 | renderTemplate(template: any, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
|
832 |
|
833 | renderTemplateForEach(template: Function, arrayOrObservableArray: any[], options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
|
834 | renderTemplateForEach(template: any, arrayOrObservableArray: any[], options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
|
835 | renderTemplateForEach(template: Function, arrayOrObservableArray: KnockoutObservable<any>, options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
|
836 | renderTemplateForEach(template: any, arrayOrObservableArray: KnockoutObservable<any>, options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
|
837 |
|
838 | /**
|
839 | * Executes a callback function inside a computed observable, without creating a dependecy between it and the observables inside the function.
|
840 | * @param callback Function to be called.
|
841 | * @param callbackTarget Defines the value of 'this' in the callback function.
|
842 | * @param callbackArgs Arguments for the callback Function.
|
843 | */
|
844 | ignoreDependencies<T>(callback: () => T, callbackTarget?: any, callbackArgs?: any): T;
|
845 |
|
846 | expressionRewriting: {
|
847 | bindingRewriteValidators: any[];
|
848 | twoWayBindings: any;
|
849 | parseObjectLiteral: (objectLiteralString: string) => any[];
|
850 |
|
851 | |
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 | writeValueToProperty: (property: KnockoutObservable<any> | any, allBindings: KnockoutAllBindingsAccessor, key: string, value: any, checkIfDifferent?: boolean) => void;
|
867 | };
|
868 |
|
869 |
|
870 |
|
871 | bindingProvider: {
|
872 | instance: KnockoutBindingProvider;
|
873 | new(): KnockoutBindingProvider;
|
874 | }
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 | selectExtensions: {
|
881 |
|
882 | readValue(element: HTMLElement): any;
|
883 |
|
884 | writeValue(element: HTMLElement, value: any, allowUnset?: boolean): void;
|
885 | };
|
886 |
|
887 | components: KnockoutComponents;
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 | options: {
|
894 | deferUpdates: boolean,
|
895 |
|
896 | useOnlyNativeEvents: boolean
|
897 | };
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 | tasks: KnockoutTasks;
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 | onError?: (error: Error) => void;
|
910 | }
|
911 |
|
912 | interface KnockoutBindingProvider {
|
913 | nodeHasBindings(node: Node): boolean;
|
914 | getBindings(node: Node, bindingContext: KnockoutBindingContext): {};
|
915 | getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; };
|
916 | }
|
917 |
|
918 | interface KnockoutComputedContext {
|
919 | |
920 |
|
921 |
|
922 | getDependenciesCount(): number;
|
923 | |
924 |
|
925 |
|
926 |
|
927 | isInitial: () => boolean;
|
928 | isSleeping: boolean;
|
929 | }
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 | declare namespace KnockoutComponentTypes {
|
936 | type ViewModel = ViewModelFunction | ViewModelSharedInstance | ViewModelFactoryFunction | AMDModule;
|
937 |
|
938 | interface Config<T> {
|
939 | viewModel?: T;
|
940 | template: string | Node[] | DocumentFragment | TemplateElement | AMDModule;
|
941 | synchronous?: boolean;
|
942 | }
|
943 |
|
944 | interface ComponentConfig<T = ViewModel> {
|
945 | viewModel?: T;
|
946 | template: any;
|
947 | createViewModel?: any;
|
948 | }
|
949 |
|
950 | interface EmptyConfig {
|
951 | }
|
952 |
|
953 |
|
954 | interface AMDModule {
|
955 | require: string;
|
956 | }
|
957 |
|
958 |
|
959 | interface ViewModelFunction {
|
960 | (params?: any): any;
|
961 | }
|
962 |
|
963 | interface ViewModelSharedInstance {
|
964 | instance: any;
|
965 | }
|
966 |
|
967 | interface ViewModelFactoryFunction {
|
968 | createViewModel: (params: any, componentInfo: ComponentInfo) => any;
|
969 | }
|
970 |
|
971 | interface ComponentInfo {
|
972 | element: Node;
|
973 | templateNodes: Node[];
|
974 | }
|
975 |
|
976 | interface TemplateElement {
|
977 | element: string | Node;
|
978 | }
|
979 |
|
980 | interface Loader {
|
981 | |
982 |
|
983 |
|
984 |
|
985 | getConfig?(componentName: string, callback: (result: ComponentConfig | null) => void): void;
|
986 | /**
|
987 | * 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.
|
988 | * @see {@link https://knockoutjs.com/documentation/component-loaders.html}
|
989 | */
|
990 | loadComponent?(componentName: string, config: ComponentConfig, callback: (result: Definition | null) => void): void;
|
991 | /**
|
992 | * 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).
|
993 | * @see {@link https://knockoutjs.com/documentation/component-loaders.html}
|
994 | */
|
995 | loadTemplate?(componentName: string, templateConfig: any, callback: (result: Node[] | null) => void): void;
|
996 | /**
|
997 | * 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).
|
998 | * @see {@link https://knockoutjs.com/documentation/component-loaders.html}
|
999 | */
|
1000 | loadViewModel?(componentName: string, viewModelConfig: any, callback: (result: any) => void): void;
|
1001 | suppressLoaderExceptions?: boolean;
|
1002 | }
|
1003 |
|
1004 | interface Definition {
|
1005 | template: Node[];
|
1006 | createViewModel?(params: any, options: { element: Node; }): any;
|
1007 | }
|
1008 | }
|
1009 |
|
1010 | interface KnockoutComponents {
|
1011 |
|
1012 | /**
|
1013 | * Registers a component, in the default component loader, to be used by name in the component binding.
|
1014 | * @param componentName Component name. Will be used for your custom HTML tag name.
|
1015 | * @param config Component configuration.
|
1016 | */
|
1017 | register<T = KnockoutComponentTypes.ViewModel>(componentName: string, config: KnockoutComponentTypes.Config<T> | KnockoutComponentTypes.EmptyConfig): void;
|
1018 | /**
|
1019 | * Determine if a component with the specified name is already registered in the default component loader.
|
1020 | * @param componentName Component name.
|
1021 | */
|
1022 | isRegistered(componentName: string): boolean;
|
1023 | /**
|
1024 | * Removes the named component from the default component loader registry. Or if no such component was registered, does nothing.
|
1025 | * @param componentName Component name.
|
1026 | */
|
1027 | unregister(componentName: string): void;
|
1028 | /**
|
1029 | * Searchs each registered component loader by component name, and returns the viewmodel/template declaration via callback parameter.
|
1030 | * @param componentName Component name.
|
1031 | * @param callback Function to be called with the viewmodel/template declaration parameter.
|
1032 | */
|
1033 | get(componentName: string, callback: (definition: KnockoutComponentTypes.Definition) => void): void;
|
1034 | /**
|
1035 | * Clears the cache knockout creates to speed up component loading, for a given component.
|
1036 | * @param componentName Component name.
|
1037 | */
|
1038 | clearCachedDefinition(componentName: string): void
|
1039 | defaultLoader: KnockoutComponentTypes.Loader;
|
1040 | loaders: KnockoutComponentTypes.Loader[];
|
1041 | /**
|
1042 | * Returns the registered component name for a HTML element. Can be overwriten to to control dynamically which HTML element map to which component name.
|
1043 | * @param node html element that corresponds to a custom component.
|
1044 | */
|
1045 | getComponentNameForNode(node: Node): string;
|
1046 | }
|
1047 |
|
1048 | declare var ko: KnockoutStatic;
|
1049 |
|
1050 | declare module "knockout" {
|
1051 | export = ko;
|
1052 | }
|
1053 |
|
\ | No newline at end of file |