/
array-selector.d.ts
200 lines (180 loc) · 6.12 KB
/
array-selector.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* lib/elements/array-selector.html
*/
/// <reference path="../../polymer-element.d.ts" />
/// <reference path="../utils/mixin.d.ts" />
/// <reference path="../utils/array-splice.d.ts" />
declare namespace Polymer {
/**
* Element mixin for recording dynamic associations between item paths in a
* master `items` array and a `selected` array such that path changes to the
* master array (at the host) element or elsewhere via data-binding) are
* correctly propagated to items in the selected array and vice-versa.
*
* The `items` property accepts an array of user data, and via the
* `select(item)` and `deselect(item)` API, updates the `selected` property
* which may be bound to other parts of the application, and any changes to
* sub-fields of `selected` item(s) will be kept in sync with items in the
* `items` array. When `multi` is false, `selected` is a property
* representing the last selected item. When `multi` is true, `selected`
* is an array of multiply selected items.
*/
function ArraySelectorMixin<T extends new (...args: any[]) => {}>(base: T): T & ArraySelectorMixinConstructor & Polymer.ElementMixinConstructor;
interface ArraySelectorMixinConstructor {
new(...args: any[]): ArraySelectorMixin;
}
interface ArraySelectorMixin {
/**
* An array containing items from which selection will be made.
*/
items: any[]|null|undefined;
/**
* When `true`, multiple items may be selected at once (in this case,
* `selected` is an array of currently selected items). When `false`,
* only one item may be selected at a time.
*/
multi: boolean|null|undefined;
/**
* When `multi` is true, this is an array that contains any selected.
* When `multi` is false, this is the currently selected item, or `null`
* if no item is selected.
*/
selected: object|object[]|null;
/**
* When `multi` is false, this is the currently selected item, or `null`
* if no item is selected.
*/
selectedItem: object|null;
/**
* When `true`, calling `select` on an item that is already selected
* will deselect the item.
*/
toggle: boolean|null|undefined;
/**
* Clears the selection state.
*/
clearSelection(): void;
/**
* Returns whether the item is currently selected.
*
* @param item Item from `items` array to test
* @returns Whether the item is selected
*/
isSelected(item: any): boolean;
/**
* Returns whether the item is currently selected.
*
* @param idx Index from `items` array to test
* @returns Whether the item is selected
*/
isIndexSelected(idx: number): boolean;
/**
* Deselects the given item if it is already selected.
*
* @param item Item from `items` array to deselect
*/
deselect(item: any): void;
/**
* Deselects the given index if it is already selected.
*
* @param idx Index from `items` array to deselect
*/
deselectIndex(idx: number): void;
/**
* Selects the given item. When `toggle` is true, this will automatically
* deselect the item if already selected.
*
* @param item Item from `items` array to select
*/
select(item: any): void;
/**
* Selects the given index. When `toggle` is true, this will automatically
* deselect the item if already selected.
*
* @param idx Index from `items` array to select
*/
selectIndex(idx: number): void;
}
/**
* Element implementing the `Polymer.ArraySelector` mixin, which records
* dynamic associations between item paths in a master `items` array and a
* `selected` array such that path changes to the master array (at the host)
* element or elsewhere via data-binding) are correctly propagated to items
* in the selected array and vice-versa.
*
* The `items` property accepts an array of user data, and via the
* `select(item)` and `deselect(item)` API, updates the `selected` property
* which may be bound to other parts of the application, and any changes to
* sub-fields of `selected` item(s) will be kept in sync with items in the
* `items` array. When `multi` is false, `selected` is a property
* representing the last selected item. When `multi` is true, `selected`
* is an array of multiply selected items.
*
* Example:
*
* ```html
* <dom-module id="employee-list">
*
* <template>
*
* <div> Employee list: </div>
* <dom-repeat id="employeeList" items="{{employees}}">
* <template>
* <div>First name: <span>{{item.first}}</span></div>
* <div>Last name: <span>{{item.last}}</span></div>
* <button on-click="toggleSelection">Select</button>
* </template>
* </dom-repeat>
*
* <array-selector id="selector" items="{{employees}}" selected="{{selected}}" multi toggle></array-selector>
*
* <div> Selected employees: </div>
* <dom-repeat items="{{selected}}">
* <template>
* <div>First name: <span>{{item.first}}</span></div>
* <div>Last name: <span>{{item.last}}</span></div>
* </template>
* </dom-repeat>
*
* </template>
*
* </dom-module>
* ```
*
* ```js
* class EmployeeList extends Polymer.Element {
* static get is() { return 'employee-list'; }
* static get properties() {
* return {
* employees: {
* value() {
* return [
* {first: 'Bob', last: 'Smith'},
* {first: 'Sally', last: 'Johnson'},
* ...
* ];
* }
* }
* };
* }
* toggleSelection(e) {
* let item = this.$.employeeList.itemForElement(e.target);
* this.$.selector.select(item);
* }
* }
* ```
*/
class ArraySelector extends
Polymer.ArraySelectorMixin(
Polymer.Element) {
}
}
interface HTMLElementTagNameMap {
"array-selector": Polymer.ArraySelector;
}