terrier-engine 4.33.0 → 4.34.1
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/data-dive/plots/dive-plot-traces.ts +1 -1
- package/package.json +1 -1
- package/terrier/forms.ts +91 -102
|
@@ -59,7 +59,7 @@ class TraceStyleFields extends TerrierFormFields<TraceStyle> {
|
|
|
59
59
|
.label("Color")
|
|
60
60
|
.textInput({placeholder: 'Color'})
|
|
61
61
|
|
|
62
|
-
this.
|
|
62
|
+
this.compoundField(container, 'strokeWidth')
|
|
63
63
|
.label("Width")
|
|
64
64
|
.numberInput({placeholder: 'Width'})
|
|
65
65
|
|
package/package.json
CHANGED
package/terrier/forms.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {FieldConstructor, FormFields, FormPartData, InputType, KeyOfType, SelectOptions} from "tuff-core/forms"
|
|
2
2
|
import {DbErrors} from "./db-client"
|
|
3
3
|
import {PartTag} from "tuff-core/parts"
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DefaultTagAttrs,
|
|
6
|
+
DivTag,
|
|
7
|
+
InputTag,
|
|
8
|
+
InputTagAttrs,
|
|
9
|
+
SelectTag,
|
|
10
|
+
SelectTagAttrs,
|
|
11
|
+
TextAreaTag,
|
|
12
|
+
TextAreaTagAttrs
|
|
13
|
+
} from "tuff-core/html"
|
|
5
14
|
import TerrierPart from "./parts/terrier-part"
|
|
6
15
|
import GlypPicker from "./parts/glyp-picker"
|
|
7
16
|
import Glyps from "./glyps"
|
|
@@ -90,33 +99,27 @@ export class TerrierFormFields<T extends FormPartData> extends FormFields<T> {
|
|
|
90
99
|
})
|
|
91
100
|
}
|
|
92
101
|
|
|
93
|
-
protected
|
|
94
|
-
new(name: string): Field<any, Element>
|
|
95
|
-
}, attrs?: InputTagAttrs): InputTag {
|
|
102
|
+
protected addErrorClass(name: string, attrs: DefaultTagAttrs) {
|
|
96
103
|
if (this.errors && this.errors[name]) {
|
|
97
104
|
attrs ||= {}
|
|
98
105
|
attrs.classes ||= []
|
|
99
106
|
attrs.classes.push('error')
|
|
100
107
|
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
input<Key extends KeyOfType<T,any> & string>(parent: PartTag, type: InputType, name: Key, serializerType: FieldConstructor<any, Element>, attrs: InputTagAttrs={}): InputTag {
|
|
111
|
+
this.addErrorClass(name, attrs)
|
|
101
112
|
return super.input(parent, type, name, serializerType, attrs);
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
select<Key extends
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
attrs.classes ||= []
|
|
108
|
-
attrs.classes.push('error')
|
|
109
|
-
}
|
|
110
|
-
return super.select(parent, name, options, attrs);
|
|
115
|
+
select<Key extends keyof T & string, TSerializer extends FieldConstructor<T[Key], HTMLSelectElement>>(parent: PartTag, name: Key, options?: SelectOptions, attrs: SelectTagAttrs = {}, serializerType?: TSerializer): SelectTag {
|
|
116
|
+
this.addErrorClass(name, attrs)
|
|
117
|
+
return super.select(parent, name, options, attrs, serializerType);
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
textArea<Key extends
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
attrs.classes ||= []
|
|
117
|
-
attrs.classes.push('error')
|
|
118
|
-
}
|
|
119
|
-
return super.textArea(parent, name, attrs);
|
|
120
|
+
textArea<Key extends keyof T & string, TSerializer extends FieldConstructor<T[Key], HTMLTextAreaElement>>(parent: PartTag, name: Key, attrs: TextAreaTagAttrs = {}, serializerType?: TSerializer): TextAreaTag {
|
|
121
|
+
this.addErrorClass(name, attrs)
|
|
122
|
+
return super.textArea(parent, name, attrs, serializerType);
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
/**
|
|
@@ -146,22 +149,14 @@ export class TerrierFormFields<T extends FormPartData> extends FormFields<T> {
|
|
|
146
149
|
}).emitClick(this.pickGlypKey, {key})
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
compoundField<Key extends
|
|
150
|
-
return new
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
numericCompoundField<Key extends KeyOfType<T, number> & string>(parent: PartTag, key: Key, ...classes: string[]): NumericCompoundFieldBuilder<T, Key> {
|
|
154
|
-
return new NumericCompoundFieldBuilder(this, parent, key, (this.part as TerrierPart<any>).theme, ...classes)
|
|
152
|
+
compoundField<Key extends keyof T & string>(parent: PartTag, key: Key, ...classes: string[]): CompoundFieldBuilder<T, Key> {
|
|
153
|
+
return new CompoundFieldBuilder(this, parent, key, (this.part as TerrierPart<any>).theme, ...classes)
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
fileCompoundField<Key extends KeyOfType<T, File> & string>(parent: PartTag, key: Key, ...classes: string[]): FileCompoundFieldBuilder<T, Key> {
|
|
158
157
|
return new FileCompoundFieldBuilder(this, parent, key, (this.part as TerrierPart<any>).theme, ...classes)
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
booleanCompoundField<Key extends KeyOfType<T, boolean> & string>(parent: PartTag, key: Key, ...classes: string[]): BooleanCompoundFieldBuilder<T, Key> {
|
|
162
|
-
return new BooleanCompoundFieldBuilder(this, parent, key, (this.part as TerrierPart<any>).theme, ...classes)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
160
|
/**
|
|
166
161
|
* Makes a label with a radio and title span inside of it.
|
|
167
162
|
* @param parent
|
|
@@ -170,7 +165,7 @@ export class TerrierFormFields<T extends FormPartData> extends FormFields<T> {
|
|
|
170
165
|
* @param title the title to put in the label span
|
|
171
166
|
* @param attrs attributes for the radio input
|
|
172
167
|
*/
|
|
173
|
-
radioLabel<Key extends KeyOfType<T, string> & string>(parent: PartTag, name: Key, value:
|
|
168
|
+
radioLabel<Key extends KeyOfType<T, string> & string>(parent: PartTag, name: Key, value: T[Key], title?: string, attrs: InputTagAttrs = {}) {
|
|
174
169
|
return parent.label('.body-size', label => {
|
|
175
170
|
this.radio(label, name, value, attrs)
|
|
176
171
|
label.span().text(title || value)
|
|
@@ -179,7 +174,7 @@ export class TerrierFormFields<T extends FormPartData> extends FormFields<T> {
|
|
|
179
174
|
|
|
180
175
|
}
|
|
181
176
|
|
|
182
|
-
|
|
177
|
+
class CompoundFieldBuilder<T extends Record<string, unknown>, K extends keyof T & string> {
|
|
183
178
|
|
|
184
179
|
field!: DivTag
|
|
185
180
|
|
|
@@ -194,119 +189,120 @@ abstract class CompoundFieldBuilder<T extends Record<string, unknown>, K extends
|
|
|
194
189
|
}
|
|
195
190
|
}
|
|
196
191
|
|
|
197
|
-
|
|
198
|
-
this.
|
|
192
|
+
hiddenInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
193
|
+
this.formFields.hiddenInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
199
194
|
return this
|
|
200
195
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this.field.label({ text, htmlFor: `${this.formFields.part.id}-${this.key}`, classes })
|
|
196
|
+
textInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
197
|
+
this.formFields.textInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
204
198
|
return this
|
|
205
199
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this.field.dataAttr('tooltip', text)
|
|
200
|
+
numberInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
201
|
+
this.formFields.numberInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
209
202
|
return this
|
|
210
203
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
Hints.renderHint(this.theme, this.field, hint, options)
|
|
204
|
+
emailInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
205
|
+
this.formFields.emailInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
214
206
|
return this
|
|
215
207
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.theme.renderIcon(this.field, icon, color)
|
|
208
|
+
phoneInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
209
|
+
this.formFields.phoneInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
219
210
|
return this
|
|
220
211
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.field.css(styles)
|
|
212
|
+
passwordInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
213
|
+
this.formFields.passwordInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
224
214
|
return this
|
|
225
215
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
action.classes ||= []
|
|
229
|
-
action.classes.push(color)
|
|
230
|
-
this.theme.renderActions(this.field, action, {iconColor: color})
|
|
216
|
+
searchInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
217
|
+
this.formFields.searchInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
231
218
|
return this
|
|
232
219
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
this.field.class(...s)
|
|
220
|
+
urlInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
221
|
+
this.formFields.urlInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
236
222
|
return this
|
|
237
223
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
class StringCompoundFieldBuilder<T extends Record<string, unknown>, K extends KeyOfType<T, string> & string> extends CompoundFieldBuilder<T, K> {
|
|
241
|
-
hiddenInput(attrs?: InputTagAttrs): this {
|
|
242
|
-
this.formFields.hiddenInput(this.field, this.key, attrs ?? {})
|
|
224
|
+
textArea(attrs?: TextAreaTagAttrs, serializerType?: FieldConstructor<T[K], HTMLTextAreaElement>): this {
|
|
225
|
+
this.formFields.textArea(this.field, this.key, attrs ?? {}, serializerType)
|
|
243
226
|
return this
|
|
244
227
|
}
|
|
245
|
-
|
|
246
|
-
this.formFields.
|
|
228
|
+
dateInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
229
|
+
this.formFields.dateInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
247
230
|
return this
|
|
248
231
|
}
|
|
249
|
-
|
|
250
|
-
this.formFields.
|
|
232
|
+
timeInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
233
|
+
this.formFields.timeInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
251
234
|
return this
|
|
252
235
|
}
|
|
253
|
-
|
|
254
|
-
this.formFields.
|
|
236
|
+
dateTimeInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
237
|
+
this.formFields.dateTimeInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
255
238
|
return this
|
|
256
239
|
}
|
|
257
|
-
|
|
258
|
-
this.formFields.
|
|
240
|
+
monthInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
241
|
+
this.formFields.monthInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
259
242
|
return this
|
|
260
243
|
}
|
|
261
|
-
|
|
262
|
-
this.formFields.
|
|
244
|
+
weekInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
245
|
+
this.formFields.weekInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
263
246
|
return this
|
|
264
247
|
}
|
|
265
|
-
|
|
266
|
-
this.formFields.
|
|
248
|
+
radio(value: T[K], attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
249
|
+
this.formFields.radio(this.field, this.key, value, attrs ?? {}, serializerType)
|
|
267
250
|
return this
|
|
268
251
|
}
|
|
269
|
-
|
|
270
|
-
this.formFields.
|
|
252
|
+
checkbox(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
253
|
+
this.formFields.checkbox(this.field, this.key, attrs ?? {}, serializerType)
|
|
271
254
|
return this
|
|
272
255
|
}
|
|
273
|
-
|
|
274
|
-
this.formFields.
|
|
256
|
+
select(selectOptions?: SelectOptions, attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLSelectElement>): this {
|
|
257
|
+
this.formFields.select(this.field, this.key, selectOptions, attrs ?? {}, serializerType)
|
|
275
258
|
return this
|
|
276
259
|
}
|
|
277
|
-
|
|
278
|
-
this.formFields.
|
|
260
|
+
colorInput(attrs?: InputTagAttrs, serializerType?: FieldConstructor<T[K], HTMLInputElement>): this {
|
|
261
|
+
this.formFields.colorInput(this.field, this.key, attrs ?? {}, serializerType)
|
|
279
262
|
return this
|
|
280
263
|
}
|
|
281
|
-
|
|
282
|
-
|
|
264
|
+
|
|
265
|
+
readonly(text?: string): this {
|
|
266
|
+
this.field.div('.readonly-field', {text: text ?? Objects.safeToString(this.formFields.data[this.key]) })
|
|
283
267
|
return this
|
|
284
268
|
}
|
|
285
|
-
|
|
286
|
-
|
|
269
|
+
|
|
270
|
+
label(text: string, ...classes: string[]): this {
|
|
271
|
+
this.field.label({ text, htmlFor: `${this.formFields.part.id}-${this.key}`, classes })
|
|
287
272
|
return this
|
|
288
273
|
}
|
|
289
|
-
|
|
290
|
-
|
|
274
|
+
|
|
275
|
+
tooltip(text: string): this {
|
|
276
|
+
this.field.dataAttr('tooltip', text)
|
|
291
277
|
return this
|
|
292
278
|
}
|
|
293
|
-
|
|
294
|
-
|
|
279
|
+
|
|
280
|
+
hint(hint: Hint, options?: HintRenderOptions): this {
|
|
281
|
+
Hints.renderHint(this.theme, this.field, hint, options)
|
|
295
282
|
return this
|
|
296
283
|
}
|
|
297
|
-
|
|
298
|
-
|
|
284
|
+
|
|
285
|
+
icon(icon: IconName, color: ColorName | null = 'secondary'): this {
|
|
286
|
+
this.field.label('.icon-only', label => {
|
|
287
|
+
this.theme.renderIcon(label, icon, color)
|
|
288
|
+
})
|
|
299
289
|
return this
|
|
300
290
|
}
|
|
301
|
-
|
|
302
|
-
|
|
291
|
+
|
|
292
|
+
css(styles: InlineStyle): this {
|
|
293
|
+
this.field.css(styles)
|
|
303
294
|
return this
|
|
304
295
|
}
|
|
305
|
-
}
|
|
306
296
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
297
|
+
action(action: Action, color: ColorName = 'link'): this {
|
|
298
|
+
action.classes ||= []
|
|
299
|
+
action.classes.push(color)
|
|
300
|
+
this.theme.renderActions(this.field, action, {iconColor: color})
|
|
301
|
+
return this
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
class(...s: string[]): this {
|
|
305
|
+
this.field.class(...s)
|
|
310
306
|
return this
|
|
311
307
|
}
|
|
312
308
|
}
|
|
@@ -318,13 +314,6 @@ class FileCompoundFieldBuilder<T extends Record<string, unknown>, K extends KeyO
|
|
|
318
314
|
}
|
|
319
315
|
}
|
|
320
316
|
|
|
321
|
-
class BooleanCompoundFieldBuilder<T extends Record<string, unknown>, K extends KeyOfType<T, boolean> & string> extends CompoundFieldBuilder<T, K> {
|
|
322
|
-
|
|
323
|
-
checkbox(attrs?: InputTagAttrs): this {
|
|
324
|
-
this.formFields.checkbox(this.field, this.key, attrs ?? {})
|
|
325
|
-
return this
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
317
|
|
|
329
318
|
|
|
330
319
|
|