@mixd-id/web-scaffold 0.2.250801014 → 0.2.260801002

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.
Files changed (113) hide show
  1. package/README.md +25 -1
  2. package/docs/components/AIDashboard.md +117 -32
  3. package/docs/components/Alert.md +3 -1
  4. package/docs/components/Card.md +5 -0
  5. package/docs/components/PivotList.md +207 -0
  6. package/docs/components/Textbox.md +20 -1
  7. package/docs/components/Tooltip.md +148 -0
  8. package/package.json +17 -61
  9. package/src/components/AIChat.vue +14 -5
  10. package/src/components/AIChatItem.vue +34 -3
  11. package/src/components/AIDashboard.vue +144 -98
  12. package/src/components/Alert.vue +58 -35
  13. package/src/components/Card.vue +55 -6
  14. package/src/components/Carousel.vue +1 -1
  15. package/src/{widgets → components}/CartSetting.vue +1 -0
  16. package/src/components/Chart.vue +2 -2
  17. package/src/components/Checkbox.vue +22 -24
  18. package/src/components/CodeEditor.vue +2 -0
  19. package/src/{widgets → components}/CollapsiblePanelSetting.vue +1 -0
  20. package/src/components/ColorPicker.vue +2 -2
  21. package/src/{widgets → components}/ComponentSetting2.vue +1 -1
  22. package/src/components/Confirm.vue +2 -0
  23. package/src/{widgets → components}/ContactForm.vue +1 -1
  24. package/src/components/CopyToClipboard.vue +0 -1
  25. package/src/components/Datepicker.vue +2 -0
  26. package/src/components/Datetimepicker.vue +1 -1
  27. package/src/components/Dropdown.vue +1 -1
  28. package/src/{widgets → components}/FeatureList.vue +1 -1
  29. package/src/components/Gmaps.vue +1 -1
  30. package/src/{widgets → components}/IconList.vue +1 -1
  31. package/src/components/Image.vue +1 -1
  32. package/src/components/ImagePreview.vue +32 -51
  33. package/src/components/List.vue +45 -8
  34. package/src/components/MarkdownEdit.vue +1 -1
  35. package/src/components/MarkdownPreview.vue +4 -1
  36. package/src/{widgets → components}/MenuItem1Setting.vue +1 -0
  37. package/src/components/Metric.vue +30 -7
  38. package/src/components/MultiDropdown.vue +3 -1
  39. package/src/{widgets → components}/MultiValueSetting.vue +2 -2
  40. package/src/{widgets → components}/MultiValueSetting2.vue +2 -2
  41. package/src/components/OTPField.vue +3 -1
  42. package/src/components/PivotList.vue +1239 -0
  43. package/src/{widgets → components}/PresetBar.vue +1 -1
  44. package/src/components/PresetSelectorFilterItem.vue +1 -1
  45. package/src/components/Radio.vue +1 -1
  46. package/src/{widgets → components}/Share.vue +1 -1
  47. package/src/components/SvgEditor.vue +1 -1
  48. package/src/components/Switch.vue +1 -1
  49. package/src/components/TextWithTag.vue +2 -2
  50. package/src/components/Textbox.vue +63 -5
  51. package/src/components/Toast.vue +2 -1
  52. package/src/components/Tooltip.vue +626 -0
  53. package/src/components/VirtualGrid.vue +2 -2
  54. package/src/components/VirtualTable.vue +4 -3
  55. package/src/{widgets → components}/WebDatasourceSelector.vue +2 -0
  56. package/src/{widgets → components}/WebLayoutSelector.vue +1 -1
  57. package/src/directives/tooltip.js +131 -0
  58. package/src/index.js +11 -235
  59. package/src/themes/default/index.js +16 -0
  60. package/src/utils/ai-dashboard.js +163 -38
  61. package/src/utils/helpers.mjs +52 -5
  62. package/src/utils/list.mjs +4 -1
  63. package/src/utils/pivot-formula.mjs +358 -0
  64. package/src/utils/pivot-list.mjs +557 -0
  65. package/src/utils/tooltip.mjs +243 -0
  66. package/src/utils/wss.js +26 -6
  67. package/src/utils/wss.mjs +29 -2
  68. /package/src/{widgets → components}/AhrefSetting.vue +0 -0
  69. /package/src/{widgets → components}/ArticleSetting.vue +0 -0
  70. /package/src/{widgets → components}/BackgroundColorSetting.vue +0 -0
  71. /package/src/{widgets → components}/BlockSetting.vue +0 -0
  72. /package/src/{widgets → components}/BorderColorSetting.vue +0 -0
  73. /package/src/{widgets → components}/ButtonSetting.vue +0 -0
  74. /package/src/{widgets → components}/CarouselSetting.vue +0 -0
  75. /package/src/{widgets → components}/ColumnSelector.vue +0 -0
  76. /package/src/{widgets → components}/ComponentSetting.vue +0 -0
  77. /package/src/{widgets → components}/ContactFormSetting.vue +0 -0
  78. /package/src/{widgets → components}/CountdownSetting.vue +0 -0
  79. /package/src/{widgets → components}/DataListSetting.vue +0 -0
  80. /package/src/{widgets → components}/EmbeddedVideo.vue +0 -0
  81. /package/src/{widgets → components}/EmbeddedVideoSetting.vue +0 -0
  82. /package/src/{widgets → components}/FAQ.vue +0 -0
  83. /package/src/{widgets → components}/FAQSetting.vue +0 -0
  84. /package/src/{widgets → components}/FeatureListSetting.vue +0 -0
  85. /package/src/{widgets → components}/FlexSetting.vue +0 -0
  86. /package/src/{widgets → components}/GridSetting.vue +0 -0
  87. /package/src/{widgets → components}/Header2.vue +0 -0
  88. /package/src/{widgets → components}/Header2Setting.vue +0 -0
  89. /package/src/{widgets → components}/IconListSetting.vue +0 -0
  90. /package/src/{widgets → components}/ImageSetting.vue +0 -0
  91. /package/src/{widgets → components}/LLMChat.vue +0 -0
  92. /package/src/{widgets → components}/LinkSetting.vue +0 -0
  93. /package/src/{widgets → components}/LinkSettingModal.vue +0 -0
  94. /package/src/{widgets → components}/ModalSetting.vue +0 -0
  95. /package/src/{widgets → components}/OGSettingModal.vue +0 -0
  96. /package/src/{widgets → components}/ParagraphSetting.vue +0 -0
  97. /package/src/{widgets → components}/PositionSetting.vue +0 -0
  98. /package/src/{widgets → components}/PresetBarPivot.vue +0 -0
  99. /package/src/{widgets → components}/PresetBarPivotColumnEdit.vue +0 -0
  100. /package/src/{widgets → components}/PresetBarPivotValueEdit.vue +0 -0
  101. /package/src/{widgets → components}/PresetSelector.vue +0 -0
  102. /package/src/{widgets → components}/Review.vue +0 -0
  103. /package/src/{widgets → components}/ReviewSetting.vue +0 -0
  104. /package/src/{widgets → components}/SearchModalSetting.vue +0 -0
  105. /package/src/{widgets → components}/ShareSetting.vue +0 -0
  106. /package/src/{widgets → components}/SvgSetting.vue +0 -0
  107. /package/src/{widgets → components}/TableSetting.vue +0 -0
  108. /package/src/{widgets → components}/TestimonialSetting.vue +0 -0
  109. /package/src/{widgets → components}/TextBlockSetting.vue +0 -0
  110. /package/src/{widgets → components}/ThumbnailSetting.vue +0 -0
  111. /package/src/{widgets → components}/WebComponentSelector.vue +0 -0
  112. /package/src/{widgets → components}/WebPageBuilder.vue +0 -0
  113. /package/src/{widgets → components}/YoutubeVideoSetting.vue +0 -0
@@ -8,6 +8,14 @@ const md5 = require('md5')
8
8
  // config.presets[] — saved dashboards, ordered by seq
9
9
  // config.presets[].params — { structure: node[], messages: [] }
10
10
  //
11
+ // Mix it into a socket controller (see `mixin` at the bottom); every method
12
+ // below is then reachable as a socket path, kebab-cased:
13
+ //
14
+ // <controller>.load <controller>.load-dashboard
15
+ // <controller>.save <controller>.load-datasource
16
+ // <controller>.save-preset <controller>.analyze-node
17
+ // <controller>.remove-preset <controller>.ai-chat
18
+ //
11
19
  // Expects the host controller to have:
12
20
  // this.Models → { UserConfig, UserPreset }
13
21
  // this.Sequelize → Sequelize (for Op)
@@ -17,7 +25,16 @@ const md5 = require('md5')
17
25
  // this.datasources → { [name]: SequelizeModel } — models a node's
18
26
  // `query.datasource` can reference (e.g. { inbox, message })
19
27
  // this.model → fallback model when a node has no `query.datasource`
20
- // this.conn → the Sequelize connection (fn, col)
28
+ // this.conn → the Sequelize connection (fn, col, literal)
29
+ // optionally:
30
+ // this.datasourceList → the catalogue load-datasource answers with; without
31
+ // it the models in `this.datasources` are described
32
+ //
33
+ // The node `query` it executes is the one documented in
34
+ // `server/docs/dashboard.md` and worked through in `server/docs/dashboard.json`:
35
+ // metric → { datasource, aggregation, field, filters }
36
+ // chart → { datasource, aggregation, field, groupBy, dateModifier, limit, filters }
37
+ // table → { datasource, columns, order, page, pageSize, filters }
21
38
 
22
39
  const AIDashboardMixin = {
23
40
 
@@ -141,9 +158,16 @@ const AIDashboardMixin = {
141
158
 
142
159
  const hydrate = async (node) => {
143
160
  const copy = { ...node }
144
- if (copy.query) {
145
- const data = await this.analyzeNode({ node: copy })
146
- if (data) copy.data = { ...copy.data, ...data }
161
+ // an empty query computes nothing — unless the host set a fallback model
162
+ if (copy.query?.datasource || (copy.query && this.model)) {
163
+ try {
164
+ const data = await this.analyzeNode({ node: copy })
165
+ if (data) copy.data = { ...copy.data, ...data, error: null }
166
+ } catch (e) {
167
+ // one broken widget must not blank the whole dashboard — the client
168
+ // renders `data.error` in place of the widget body
169
+ copy.data = { ...copy.data, error: e.message }
170
+ }
147
171
  }
148
172
  if (Array.isArray(copy.items) && copy.items.length) {
149
173
  copy.items = await Promise.all(copy.items.map(hydrate))
@@ -168,6 +192,80 @@ const AIDashboardMixin = {
168
192
  return model
169
193
  },
170
194
 
195
+ // ── Data sources: `<controller>.load-datasource` ────────────────────────────
196
+ // What the query builder and the Data tab list. A host controller can define
197
+ // `datasourceList` (the hand-written catalogue, the shape docs/dashboard.json
198
+ // carries) — otherwise the models in `this.datasources` are described here.
199
+
200
+ async loadDatasource() {
201
+ return { datasources: this.datasourceList ?? this.describeDatasources() }
202
+ },
203
+
204
+ describeDatasources() {
205
+ const typeOf = (attr) => {
206
+ const key = `${attr?.type?.key ?? ''}`.toUpperCase()
207
+ if ([ 'DATE', 'DATEONLY', 'TIME' ].includes(key)) return 'date'
208
+ if ([ 'INTEGER', 'BIGINT', 'TINYINT', 'SMALLINT', 'MEDIUMINT',
209
+ 'FLOAT', 'DOUBLE', 'DECIMAL', 'REAL' ].includes(key)) return 'number'
210
+ return 'string'
211
+ }
212
+ const titleize = (key) => key.replace(/([A-Z])/g, ' $1').replace(/^./, c => c.toUpperCase()).trim()
213
+
214
+ return Object.entries(this.datasources ?? {}).map(([ key, model ]) => ({
215
+ key,
216
+ label: titleize(model.options?.name?.plural ?? key),
217
+ aggregations: [ 'count', 'sum', 'avg', 'min', 'max' ],
218
+ fields: Object.entries(this.attributesOf(model)).map(([ field, attr ]) => ({
219
+ key: field,
220
+ label: titleize(field),
221
+ type: typeOf(attr),
222
+ })),
223
+ }))
224
+ },
225
+
226
+ /** The model's attribute map, across Sequelize versions. */
227
+ attributesOf(model) {
228
+ return (typeof model.getAttributes === 'function' ? model.getAttributes() : model.rawAttributes) ?? {}
229
+ },
230
+
231
+ // Every field name in a query reaches raw SQL through fn/col/literal, so it is
232
+ // checked against the model before use.
233
+ safeField(model, field, role = 'field') {
234
+ if (!field || !(field in this.attributesOf(model))) {
235
+ throw new Error(`AIDashboard: unknown ${role} "${field ?? ''}" on ${model.name}`)
236
+ }
237
+ return field
238
+ },
239
+
240
+ // ── Filters → Sequelize `where` ─────────────────────────────────────────────
241
+ // A filter row is { field, op, value }; op ∈ = != > >= < <= contains in.
242
+ // Rows with no field or no value are dropped, `in` is comma-split.
243
+
244
+ filtersToWhere(model, filters) {
245
+ const { Op } = this.Sequelize
246
+ const ops = {
247
+ '=': Op.eq, '!=': Op.ne, '>': Op.gt, '>=': Op.gte, '<': Op.lt, '<=': Op.lte,
248
+ }
249
+ const where = {}
250
+
251
+ for (const filter of filters ?? []) {
252
+ if (!filter?.field || filter.value === '' || filter.value == null) continue
253
+ const field = this.safeField(model, filter.field, 'filter field')
254
+ if (filter.op === 'contains') where[field] = { [Op.like]: `%${filter.value}%` }
255
+ else if (filter.op === 'in') where[field] = { [Op.in]: `${filter.value}`.split(',').map(v => v.trim()).filter(Boolean) }
256
+ else if (ops[filter.op]) where[field] = { [ops[filter.op]]: filter.value }
257
+ }
258
+ return where
259
+ },
260
+
261
+ // A node query's `where`: its literal `where` plus its `filters` rows. Named
262
+ // apart from a host controller's own `buildWhere` — mixin() never replaces a
263
+ // method the class already defines, so a clashing name would silently be
264
+ // called with the wrong arguments.
265
+ whereFor(model, query) {
266
+ return { ...(query?.where ?? {}), ...this.filtersToWhere(model, query?.filters) }
267
+ },
268
+
171
269
  // ── Ask AI: `<controller>.ai-chat` ──────────────────────────────────────────
172
270
  // Overridable hook — the default is offline and only describes what it would
173
271
  // do. A real controller overrides this (via mixin overrides) with an LLM call
@@ -187,7 +285,9 @@ const AIDashboardMixin = {
187
285
  // AIDashboard component renders:
188
286
  // metric → { value }
189
287
  // chart → { series: [{ label, value }] }
190
- // table → { columns, rows }
288
+ // table → { columns, rows, hasNext }
289
+ // Each query's `filters` are folded into its `where` by the analyzers, so a
290
+ // host controller does not need to override this.
191
291
 
192
292
  async analyzeNode({ node } = {}) {
193
293
  switch (node?.type) {
@@ -198,78 +298,99 @@ const AIDashboardMixin = {
198
298
  }
199
299
  },
200
300
 
201
- // node.query = { datasource, aggregation: 'count'|'sum'|'avg'|'min'|'max', field, where }
301
+ // node.query = { datasource, aggregation, field, where, filters }
202
302
 
203
303
  async analyzeMetricNode(node) {
204
304
  const { fn, col } = this.conn
205
- const { datasource, aggregation = 'count', field, where = {} } = node.query ?? {}
305
+ const { datasource, aggregation = 'count', field } = node.query ?? {}
206
306
  const model = this.modelFor(datasource)
307
+ const where = this.whereFor(model, node.query)
308
+
309
+ if (aggregation === 'count') return { value: await model.count({ where }) }
310
+
311
+ const column = this.safeField(model, field, 'aggregation field')
207
312
 
208
313
  switch (aggregation) {
209
- case 'count':
210
- return { value: await model.count({ where }) }
211
314
  case 'sum':
212
- return { value: await model.sum(field, { where }) ?? 0 }
315
+ return { value: await model.sum(column, { where }) ?? 0 }
213
316
  case 'avg': {
214
- const [row] = await model.findAll({
215
- attributes: [[ fn('AVG', col(field)), 'result' ]],
317
+ const [ row ] = await model.findAll({
318
+ attributes: [[ fn('AVG', col(column)), 'result' ]],
216
319
  where,
217
320
  raw: true,
218
321
  })
219
322
  return { value: parseFloat(row?.result ?? 0) }
220
323
  }
221
324
  case 'min':
222
- return { value: await model.min(field, { where }) ?? 0 }
325
+ return { value: await model.min(column, { where }) ?? 0 }
223
326
  case 'max':
224
- return { value: await model.max(field, { where }) ?? 0 }
327
+ return { value: await model.max(column, { where }) ?? 0 }
225
328
  default:
226
- return { value: 0 }
329
+ throw new Error(`AIDashboard: unknown aggregation "${aggregation}"`)
227
330
  }
228
331
  },
229
332
 
230
- // node.query = { datasource, groupBy, dateModifier: 'day'|'week'|'month'|'year', where, limit }
333
+ // node.query = { datasource, aggregation, field, groupBy, dateModifier, where, filters, limit }
334
+ //
335
+ // The bucket expression comes from `dateModifier`, the bar height from
336
+ // `aggregation`/`field` (count of rows when unset). Date buckets are ordered
337
+ // chronologically; plain category groupings are ordered by value, so `limit`
338
+ // reads as "top N".
231
339
 
232
340
  async analyzeChartNode(node) {
233
341
  const { fn, col, literal } = this.conn
234
- const { datasource, groupBy, dateModifier = '', where = {}, limit } = node.query ?? {}
342
+ const { datasource, aggregation = 'count', field, groupBy, dateModifier = '', limit } = node.query ?? {}
235
343
  const model = this.modelFor(datasource)
236
344
  if (!groupBy) return { series: [] }
237
345
 
238
- const xExprMap = {
239
- day: () => fn('DATE', col(groupBy)),
240
- week: () => fn('DATE_FORMAT', col(groupBy), '%Y-%u'),
241
- month: () => fn('DATE_FORMAT', col(groupBy), '%Y-%m'),
242
- year: () => fn('YEAR', col(groupBy)),
346
+ const where = this.whereFor(model, node.query)
347
+ const group = this.safeField(model, groupBy, 'groupBy field')
348
+
349
+ const bucketMap = {
350
+ day: () => fn('DATE', col(group)),
351
+ week: () => fn('DATE_FORMAT', col(group), '%Y-%u'),
352
+ month: () => fn('DATE_FORMAT', col(group), '%Y-%m'),
353
+ year: () => fn('YEAR', col(group)),
243
354
  }
244
- const hasMod = Boolean(dateModifier && xExprMap[dateModifier])
245
- const xExpr = hasMod ? xExprMap[dateModifier]() : col(groupBy)
246
- const xAlias = hasMod ? 'x_grp' : groupBy
355
+ const bucketed = Boolean(dateModifier && bucketMap[dateModifier])
356
+ const xExpr = bucketed ? bucketMap[dateModifier]() : col(group)
357
+ const xAlias = bucketed ? 'x_grp' : group
358
+
359
+ const yExpr = aggregation === 'count'
360
+ ? fn('COUNT', col('*'))
361
+ : fn(aggregation.toUpperCase(), col(this.safeField(model, field, 'aggregation field')))
247
362
 
248
363
  const rows = await model.findAll({
249
- attributes: [ hasMod ? [xExpr, xAlias] : groupBy, [ fn('COUNT', col('*')), 'count' ] ],
364
+ attributes: [ bucketed ? [ xExpr, xAlias ] : group, [ yExpr, 'y_val' ] ],
250
365
  where,
251
366
  group: [ xExpr ],
252
- order: [[ literal(xAlias), 'ASC' ]],
367
+ order: [[ literal(bucketed ? xAlias : 'y_val'), bucketed ? 'ASC' : 'DESC' ]],
253
368
  limit,
254
369
  raw: true,
255
370
  })
256
371
 
257
372
  return {
258
- series: rows.map(r => ({ label: `${r[xAlias]}`, value: parseInt(r.count) })),
373
+ series: rows.map(r => ({ label: `${r[xAlias]}`, value: parseFloat(r.y_val) || 0 })),
259
374
  }
260
375
  },
261
376
 
262
- // node.query = { datasource, columns: [{ key, label }], where, order, page, pageSize }
377
+ // node.query = { datasource, columns: [{ key, label }], where, filters, order, page, pageSize }
263
378
 
264
379
  async analyzeTableNode(node) {
265
- const { datasource, columns = [], where = {}, order, page = 0, pageSize = 20 } = node.query ?? {}
380
+ const { datasource, columns = [], order, page = 0, pageSize = 20 } = node.query ?? {}
266
381
  const model = this.modelFor(datasource)
267
- const attributes = columns.length > 0 ? columns.map(c => c.key ?? c) : undefined
382
+ const where = this.whereFor(model, node.query)
383
+
384
+ const cols = columns.map(c => (typeof c === 'string' ? { key: c, label: c } : { ...c, key: c.key ?? c.label, label: c.label ?? c.key }))
385
+ cols.forEach(c => this.safeField(model, c.key, 'column'))
268
386
 
269
387
  const rows = await model.findAll({
270
- attributes,
388
+ attributes: cols.length > 0 ? cols.map(c => c.key) : undefined,
271
389
  where,
272
- order,
390
+ order: (order ?? []).map(([ field, dir ]) => [
391
+ this.safeField(model, field, 'order field'),
392
+ `${dir}`.toUpperCase() === 'ASC' ? 'ASC' : 'DESC',
393
+ ]),
273
394
  limit: pageSize + 1,
274
395
  offset: page * pageSize,
275
396
  raw: true,
@@ -277,7 +398,7 @@ const AIDashboardMixin = {
277
398
  const hasNext = rows.length > pageSize
278
399
 
279
400
  return {
280
- columns,
401
+ columns: cols,
281
402
  rows: hasNext ? rows.slice(0, pageSize) : rows,
282
403
  hasNext,
283
404
  }
@@ -293,21 +414,25 @@ const AIDashboardMixin = {
293
414
  * @param {Object} [overrides] - Methods to assign on top of AIDashboardMixin.
294
415
  *
295
416
  * @example
296
- * import { AIDashboardMixin, mixin } from "@mixd-id/web-scaffold/ai-dashboard"
417
+ * import { mixin } from "@mixd-id/web-scaffold/ai-dashboard"
297
418
  *
298
- * class DashboardController extends Controller {
419
+ * class AiDashboardController extends Controller {
299
420
  * get Models() { return Models }
300
421
  * get Sequelize() { return Sequelize }
301
422
  * get conn() { return conn }
302
- * get configKey() { return 'dashboard' }
423
+ * get configKey() { return 'ai-dashboard' }
303
424
  * get datasources() { return { inbox: Models.Inbox, message: Models.Message } }
425
+ * get datasourceList() { return DATASOURCES }
304
426
  * }
305
427
  *
306
- * mixin(DashboardController, {
428
+ * mixin(AiDashboardController, {
307
429
  * async aiChat({ messages, structure }) {
308
430
  * // call an LLM, return { reply, structure?, nodes? }
309
431
  * }
310
432
  * })
433
+ *
434
+ * // src/controllers/sockets/index.js
435
+ * routes['ai-dashboard'] = AiDashboard
311
436
  */
312
437
  function mixin(ControllerClass, overrides = {}) {
313
438
  for (const [key, fn] of Object.entries(AIDashboardMixin)) {
@@ -382,17 +382,63 @@ const round = (num, precision = 0) => {
382
382
  return Math.round(n) / p
383
383
  }
384
384
 
385
+ const pendingIdleInvocations = new Set()
386
+
387
+ const flushIdleInvocations = () => {
388
+ for(const invocation of Array.from(pendingIdleInvocations))
389
+ invocation.flush()
390
+ }
391
+
392
+ let idleFlushListening = false
393
+
394
+ const listenForIdleFlush = () => {
395
+
396
+ if(idleFlushListening || typeof window === 'undefined')
397
+ return
398
+
399
+ idleFlushListening = true
400
+
401
+ window.addEventListener('pagehide', flushIdleInvocations)
402
+ window.addEventListener('beforeunload', flushIdleInvocations)
403
+ document.addEventListener('visibilitychange', () => {
404
+ if(document.visibilityState === 'hidden')
405
+ flushIdleInvocations()
406
+ })
407
+ }
408
+
385
409
  const invokeAfterIdle = (callback, opt) => {
386
410
 
387
411
  let timeoutId
388
- const { delay = 500 } = opt ?? {}
412
+ let pending
413
+ const { delay = 500, flushOnExit = true } = opt ?? {}
414
+
415
+ const invoke = function(){
416
+ window.clearTimeout(timeoutId)
417
+ pending = { context: this, args: arguments }
418
+ if(flushOnExit){
419
+ pendingIdleInvocations.add(invoke)
420
+ listenForIdleFlush()
421
+ }
422
+ timeoutId = window.setTimeout(invoke.flush, delay)
423
+ }
389
424
 
390
- return function(){
425
+ invoke.flush = () => {
426
+ if(!pending)
427
+ return
391
428
  window.clearTimeout(timeoutId)
392
- timeoutId = window.setTimeout(() => {
393
- callback.apply(this, arguments)
394
- }, delay)
429
+ const { context, args } = pending
430
+ pending = null
431
+ pendingIdleInvocations.delete(invoke)
432
+ callback.apply(context, args)
395
433
  }
434
+
435
+ invoke.cancel = () => {
436
+ window.clearTimeout(timeoutId)
437
+ pending = null
438
+ pendingIdleInvocations.delete(invoke)
439
+ }
440
+
441
+ return invoke
396
442
  }
397
443
 
398
444
  const queueForLater = (params) => {
@@ -641,6 +687,7 @@ export {
641
687
  applyDatasourceReplacer,
642
688
  strVars,
643
689
  invokeAfterIdle,
690
+ flushIdleInvocations,
644
691
  queueForLater,
645
692
  queueForLaterWithKey,
646
693
  transactionWithRetry,
@@ -1560,5 +1560,8 @@ export {
1560
1560
  filtersToSequelizeInclude,
1561
1561
  getColumnTypeFromModelAttribute,
1562
1562
 
1563
- presetToSequelizeList
1563
+ presetToSequelizeList,
1564
+
1565
+ PIVOT_DATE_BUCKETS,
1566
+ sqlString
1564
1567
  }