@castlabs/ui 7.23.0 → 7.23.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.
@@ -17,9 +17,9 @@ declare module '@castlabs/ui/dist/castlabs-ui.module.js' {
17
17
 
18
18
  export function clFormReset (id: string, fields?: any[]): void
19
19
  export function clFormFieldReset (ref: any, oldValue: any): void
20
- export function clFormIsValid (id: string): boolean
21
- export function clFormIsValidAsync (id: string): Promise<boolean>
22
- export function clFormFieldFocusFirstInvalid (id: string): void
20
+ export function clFormIsValid (id: string, moreSelectors?: string[], triggerSelectors?: string[]): boolean
21
+ export function clFormIsValidAsync (id: string, moreSelectors?: string[], triggerSelectors?: string[]): Promise<boolean>
22
+ export function clFormFieldFocusFirstInvalid (id: string, moreSelectors?: string[]): void
23
23
  export function clFormAutofocus (id: string): void
24
24
 
25
25
  export function clFormatFilesize (bytes: number): string
@@ -1,4 +1,4 @@
1
- /* @castlabs/ui v7.23.0 */
1
+ /* @castlabs/ui v7.23.1 */
2
2
 
3
3
  /*!
4
4
  * Bootstrap v5.3.8 (https://getbootstrap.com/)
@@ -256,7 +256,7 @@ function clTableSetResizeListeners (resizer, auto = false) {
256
256
  document.addEventListener('mousemove', mousemove)
257
257
  document.addEventListener('mouseup', mouseup)
258
258
  if (auto) {
259
- document.addEventListener('click', mouseclick)
259
+ resizer.addEventListener('click', mouseclick)
260
260
  }
261
261
  }
262
262
 
@@ -308,9 +308,10 @@ const mouseup = mouseup => {
308
308
 
309
309
  const mouseclick = click => {
310
310
  if (click.detail === 2) {
311
+ const table = click.target?.closest('table')
312
+ if (!table) return
311
313
  click.preventDefault()
312
314
 
313
- const table = click.target?.closest('table')
314
315
  const id = table?.id ?? 'unknown'
315
316
  const th = click.target?.closest('th')
316
317
  const colIndex = Array.from(th.parentElement.children).indexOf(th)
@@ -1164,9 +1165,11 @@ export function clFormFieldReset (ref, oldValue) {
1164
1165
  * Will autofocus the first wrong input (if any).
1165
1166
  *
1166
1167
  * @param {string} id ID of form.
1168
+ * @param {string[]} moreSelectors Optional additional classes that mark invalid fields.
1169
+ * @param {string[]} moreTriggers Optional additional classes mark elements that should be focused & blurred to trigger validation.
1167
1170
  * @return {boolean} True if form is OK.
1168
1171
  */
1169
- export function clFormIsValid (id) {
1172
+ export function clFormIsValid (id, moreSelectors = [], moreTriggers = []) {
1170
1173
  const form = document.querySelector(`#${id}`)
1171
1174
  if (!form) {
1172
1175
  // not a form at all
@@ -1177,16 +1180,18 @@ export function clFormIsValid (id) {
1177
1180
  // force trigger validation
1178
1181
  // as some inputs like the ace editor do custom validation based on events,
1179
1182
  // we fire various event/element/class combinations to make sure custom handlers run.
1180
- document.querySelectorAll(`#${id} input, #${id} .form-control`).forEach(input => {
1181
- input.focus()
1182
- input.blur()
1183
- })
1183
+ document
1184
+ .querySelectorAll(clSubselectorQuery(`#${id}`, ['input', '.form-control', ...moreTriggers]))
1185
+ .forEach(input => {
1186
+ input.focus()
1187
+ input.blur()
1188
+ })
1184
1189
 
1185
1190
  if (
1186
1191
  form.checkValidity() === false ||
1187
- document.querySelector(`#${id} :invalid, #${id} .invalid`)
1192
+ document.querySelector(clSubselectorQuery(`#${id}`, [':invalid', '.invalid', ...moreSelectors]))
1188
1193
  ) {
1189
- clFormFieldFocusFirstInvalid(id)
1194
+ clFormFieldFocusFirstInvalid(id, moreSelectors)
1190
1195
  return false
1191
1196
  }
1192
1197
 
@@ -1199,9 +1204,11 @@ export function clFormIsValid (id) {
1199
1204
  * Useful for complicated inputs like ACE editor.
1200
1205
  *
1201
1206
  * @param {string} id ID of form.
1207
+ * @param {string[]} moreSelectors Optional additional classes that mark invalid fields.
1208
+ * @param {string[]} moreTriggers Optional additional classes mark elements that should be focused & blurred to trigger validation.
1202
1209
  * @return {boolean} Promise of true if form is OK.
1203
1210
  */
1204
- export async function clFormIsValidAsync (id) {
1211
+ export async function clFormIsValidAsync (id, moreSelectors = [], moreTriggers = []) {
1205
1212
  const form = document.getElementById(id)
1206
1213
  if (!form) {
1207
1214
  // not a form at all
@@ -1212,10 +1219,12 @@ export async function clFormIsValidAsync (id) {
1212
1219
  // force trigger validation
1213
1220
  // as some inputs like the ace editor do custom validation based on events,
1214
1221
  // we fire various event/element/class combinations to make sure custom handlers run.
1215
- document.querySelectorAll(`#${id} input, #${id} .form-control`).forEach(input => {
1216
- input.focus()
1217
- input.blur()
1218
- })
1222
+ document
1223
+ .querySelectorAll(clSubselectorQuery(`#${id}`, ['input', '.form-control', ...moreTriggers]))
1224
+ .forEach(input => {
1225
+ input.focus()
1226
+ input.blur()
1227
+ })
1219
1228
  document.querySelectorAll(`#${id} .ace_editor`).forEach(input => {
1220
1229
  input.click()
1221
1230
  })
@@ -1225,9 +1234,11 @@ export async function clFormIsValidAsync (id) {
1225
1234
  setTimeout(() => {
1226
1235
  if (
1227
1236
  form.checkValidity() === false ||
1228
- document.querySelector(`#${id} :invalid, #${id} .invalid`)
1237
+ document.querySelector(
1238
+ clSubselectorQuery(`#${id}`, [':invalid', '.invalid', ...moreSelectors])
1239
+ )
1229
1240
  ) {
1230
- clFormFieldFocusFirstInvalid(id)
1241
+ clFormFieldFocusFirstInvalid(id, moreSelectors)
1231
1242
  resolve(false)
1232
1243
  return
1233
1244
  }
@@ -1252,12 +1263,23 @@ export function clFormAutofocus (formId) {
1252
1263
  * Set the focus in the first invalid field of the given form (if any).
1253
1264
  *
1254
1265
  * @param {string} formId HTML ID of form.
1266
+ * @param {string[]} moreSelectors Optional additional classes that mark invalid fields.
1255
1267
  */
1256
- export function clFormFieldFocusFirstInvalid (formId) {
1257
- const invalid = document.querySelector(`#${formId} :invalid, #${formId} .invalid`)
1268
+ export function clFormFieldFocusFirstInvalid (formId, moreSelectors = []) {
1269
+ const invalid = document.querySelector(
1270
+ clSubselectorQuery(`#${formId}`, [':invalid', '.invalid', ...moreSelectors])
1271
+ )
1258
1272
  invalid?.focus()
1259
1273
  }
1260
1274
 
1275
+ export function clSubselectorQuery (main, subselectors) {
1276
+ const selectors = []
1277
+ for (const subselector of subselectors) {
1278
+ selectors.push(`${main} ${subselector}`)
1279
+ }
1280
+ return selectors.join(', ')
1281
+ }
1282
+
1261
1283
  // -----------------------------------------------------------------------------
1262
1284
  // --- formatters --------------------------------------------------------------
1263
1285
  // -----------------------------------------------------------------------------