terrier-engine 4.10.0 → 4.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/terrier/list-viewer.ts +44 -53
package/package.json
CHANGED
package/terrier/list-viewer.ts
CHANGED
|
@@ -2,10 +2,10 @@ import TerrierPart from "./parts/terrier-part"
|
|
|
2
2
|
import {Part, PartConstructor, PartTag, StatelessPart} from "tuff-core/parts"
|
|
3
3
|
import Messages from "tuff-core/messages"
|
|
4
4
|
import {Logger} from "tuff-core/logging"
|
|
5
|
-
import {
|
|
6
|
-
import {PageBreakpoints} from "./parts/page-part";
|
|
5
|
+
import {PageBreakpoints} from "./parts/page-part"
|
|
7
6
|
|
|
8
7
|
const log = new Logger('List Viewer')
|
|
8
|
+
Logger.level = 'debug'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Optional values to return from rendering a list item that control
|
|
@@ -45,13 +45,11 @@ class ListItemPart<T extends ListItem> extends Part<T> {
|
|
|
45
45
|
}).id(`item-${this.state.id}`)
|
|
46
46
|
|
|
47
47
|
// render the details if this is the current item and it's supposed to be rendered inline
|
|
48
|
-
if (isCurrent && this.viewer.
|
|
48
|
+
if (isCurrent && this.viewer.layout == 'inline') {
|
|
49
|
+
log.debug(`ListItemPart: rendering inline item details`)
|
|
49
50
|
if (this.viewer.currentDetailsPart) {
|
|
50
51
|
parent.part(this.viewer.currentDetailsPart)
|
|
51
52
|
}
|
|
52
|
-
else if (this.viewer.currentDetailsDiv) {
|
|
53
|
-
parent.div().append(this.viewer.currentDetailsDiv)
|
|
54
|
-
}
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
|
|
@@ -80,12 +78,6 @@ export class ListViewerDetailsContext<T extends ListItem> {
|
|
|
80
78
|
*/
|
|
81
79
|
itemPart?: ListItemPart<T>
|
|
82
80
|
|
|
83
|
-
/**
|
|
84
|
-
* The tag rendered by `renderDirect()` to represent the details until
|
|
85
|
-
* the details part renders (if that happens at all).
|
|
86
|
-
*/
|
|
87
|
-
directDiv?: DivTag
|
|
88
|
-
|
|
89
81
|
constructor(readonly viewer: ListViewerPart<T>, readonly item: T) {
|
|
90
82
|
}
|
|
91
83
|
|
|
@@ -95,18 +87,12 @@ export class ListViewerDetailsContext<T extends ListItem> {
|
|
|
95
87
|
* @param state
|
|
96
88
|
*/
|
|
97
89
|
makePart<PartType extends Part<StateType>, StateType>(partType: PartConstructor<PartType, StateType>, state: StateType) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
* @param fn the render function for the content
|
|
105
|
-
*/
|
|
106
|
-
renderDirect(fn: (parent: DivTag) => any) {
|
|
107
|
-
this.directDiv = new DivTag("div")
|
|
108
|
-
fn(this.directDiv)
|
|
109
|
-
return this.directDiv
|
|
90
|
+
if (this.viewer.layout == 'side') {
|
|
91
|
+
this.part = this.viewer.sideContainerPart.makePart(partType, state)
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.part = this.viewer.currentItemPart?.makePart(partType, state)
|
|
95
|
+
}
|
|
110
96
|
}
|
|
111
97
|
|
|
112
98
|
/**
|
|
@@ -140,12 +126,12 @@ class SideContainerPart extends Part<{viewer: ListViewerPart<any>}> {
|
|
|
140
126
|
}
|
|
141
127
|
|
|
142
128
|
render(parent: PartTag) {
|
|
143
|
-
if (this.viewer.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
129
|
+
if (this.viewer.currentDetailsPart) {
|
|
130
|
+
log.debug(`[SideContainerPart] Rendering details part`, this.viewer.currentDetailsPart)
|
|
131
|
+
parent.part(this.viewer.currentDetailsPart)
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
log.debug(`[SideContainerPart] No details part to render`)
|
|
149
135
|
}
|
|
150
136
|
}
|
|
151
137
|
|
|
@@ -161,14 +147,14 @@ export abstract class ListViewerPart<T extends ListItem> extends TerrierPart<any
|
|
|
161
147
|
sideContainerPart!: SideContainerPart
|
|
162
148
|
|
|
163
149
|
detailsContext?: ListViewerDetailsContext<T>
|
|
164
|
-
|
|
150
|
+
layout: 'inline' | 'side' = 'side'
|
|
165
151
|
|
|
166
152
|
get currentDetailsPart(): StatelessPart | undefined {
|
|
167
153
|
return this.detailsContext?.part
|
|
168
154
|
}
|
|
169
155
|
|
|
170
|
-
get
|
|
171
|
-
return this.detailsContext?.
|
|
156
|
+
get currentItemPart(): StatelessPart | undefined {
|
|
157
|
+
return this.detailsContext?.itemPart
|
|
172
158
|
}
|
|
173
159
|
|
|
174
160
|
items: T[] = []
|
|
@@ -184,13 +170,12 @@ export abstract class ListViewerPart<T extends ListItem> extends TerrierPart<any
|
|
|
184
170
|
async init() {
|
|
185
171
|
await super.init()
|
|
186
172
|
|
|
187
|
-
this.computeDetailsLocation()
|
|
188
173
|
this.sideContainerPart = this.makePart(SideContainerPart, {viewer: this})
|
|
189
174
|
|
|
190
175
|
await this.reload()
|
|
191
176
|
|
|
192
177
|
this.onClick(this.itemClickedKey, m => {
|
|
193
|
-
log.
|
|
178
|
+
log.debug(`Clicked on list item ${m.data.id}`, m)
|
|
194
179
|
this.showDetails(m.data.id)
|
|
195
180
|
})
|
|
196
181
|
}
|
|
@@ -212,9 +197,22 @@ export abstract class ListViewerPart<T extends ListItem> extends TerrierPart<any
|
|
|
212
197
|
this.getCollectionParts('items').forEach(itemPart => {
|
|
213
198
|
// HACK
|
|
214
199
|
(itemPart as ListItemPart<T>).viewer = this
|
|
215
|
-
log.
|
|
200
|
+
// log.debug(`Adding item part ${itemPart.state.id}`, itemPart)
|
|
216
201
|
this.itemPartMap[itemPart.state.id] = (itemPart as ListItemPart<T>)
|
|
217
202
|
})
|
|
203
|
+
this.relayout()
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Determine whether the details should be shown inline with the list or
|
|
208
|
+
* off to the side, based on screen size.
|
|
209
|
+
*/
|
|
210
|
+
relayout() {
|
|
211
|
+
if (window.innerWidth > PageBreakpoints.phone) {
|
|
212
|
+
this.layout = 'side'
|
|
213
|
+
} else {
|
|
214
|
+
this.layout = 'inline'
|
|
215
|
+
}
|
|
218
216
|
this.dirty()
|
|
219
217
|
}
|
|
220
218
|
|
|
@@ -226,10 +224,14 @@ export abstract class ListViewerPart<T extends ListItem> extends TerrierPart<any
|
|
|
226
224
|
}
|
|
227
225
|
|
|
228
226
|
render(parent: PartTag): any {
|
|
227
|
+
log.debug(`Rendering the viewer`)
|
|
229
228
|
parent.div('.tt-list-viewer-list', list => {
|
|
230
229
|
this.renderCollection(list, 'items')
|
|
231
230
|
})
|
|
232
|
-
|
|
231
|
+
if (this.layout == 'side') {
|
|
232
|
+
log.debug(`Rendering sideContainerPart inside the viewer`)
|
|
233
|
+
parent.part(this.sideContainerPart)
|
|
234
|
+
}
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
/**
|
|
@@ -248,19 +250,6 @@ export abstract class ListViewerPart<T extends ListItem> extends TerrierPart<any
|
|
|
248
250
|
|
|
249
251
|
// Details
|
|
250
252
|
|
|
251
|
-
/**
|
|
252
|
-
* Determine whether the details should be shown inline with the list or
|
|
253
|
-
* off to the side, based on screen size.
|
|
254
|
-
*/
|
|
255
|
-
computeDetailsLocation() {
|
|
256
|
-
if (window.innerWidth > PageBreakpoints.phone) {
|
|
257
|
-
this.detailsLocation = 'side'
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
this.detailsLocation = 'inline'
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
253
|
/**
|
|
265
254
|
* Show the details view for the item with the given id
|
|
266
255
|
* @param id
|
|
@@ -270,14 +259,16 @@ export abstract class ListViewerPart<T extends ListItem> extends TerrierPart<any
|
|
|
270
259
|
|
|
271
260
|
const itemPart = this.itemPartMap[id]
|
|
272
261
|
if (!itemPart) {
|
|
273
|
-
log.
|
|
262
|
+
log.debug(`${Object.keys(this.itemPartMap).length} item parts: `, this.itemPartMap)
|
|
274
263
|
throw `No item part ${id}`
|
|
275
264
|
}
|
|
276
265
|
|
|
277
266
|
this.detailsContext = new ListViewerDetailsContext(this, itemPart.state)
|
|
278
|
-
this.renderDetails(this.detailsContext)
|
|
279
|
-
this.sideContainerPart.dirty()
|
|
280
267
|
this.detailsContext.itemPart = itemPart
|
|
268
|
+
this.renderDetails(this.detailsContext)
|
|
269
|
+
if (this.layout == 'side') {
|
|
270
|
+
this.sideContainerPart.dirty()
|
|
271
|
+
}
|
|
281
272
|
itemPart.dirty()
|
|
282
273
|
|
|
283
274
|
// let the world know
|