@kong-ui-public/dashboard-renderer 8.3.0 → 8.3.2-pr.2722.b1aa23ae4.0

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 (74) hide show
  1. package/package.json +5 -5
  2. package/dist/GeoMapRenderer-BbPpTgP2.js +0 -74
  3. package/dist/dashboard-renderer.es.js +0 -16
  4. package/dist/dashboard-renderer.umd.js +0 -9
  5. package/dist/index-CTwvjVRa.js +0 -4559
  6. package/dist/style.css +0 -1
  7. package/dist/types/components/BarChartRenderer.vue.d.ts +0 -6
  8. package/dist/types/components/BarChartRenderer.vue.d.ts.map +0 -1
  9. package/dist/types/components/BaseAnalyticsChartRenderer.vue.d.ts +0 -20
  10. package/dist/types/components/BaseAnalyticsChartRenderer.vue.d.ts.map +0 -1
  11. package/dist/types/components/DashboardRenderer.vue.d.ts +0 -673
  12. package/dist/types/components/DashboardRenderer.vue.d.ts.map +0 -1
  13. package/dist/types/components/DashboardTile.vue.d.ts +0 -915
  14. package/dist/types/components/DashboardTile.vue.d.ts.map +0 -1
  15. package/dist/types/components/DashboardTilePreview.vue.d.ts +0 -18
  16. package/dist/types/components/DashboardTilePreview.vue.d.ts.map +0 -1
  17. package/dist/types/components/DonutChartRenderer.vue.d.ts +0 -6
  18. package/dist/types/components/DonutChartRenderer.vue.d.ts.map +0 -1
  19. package/dist/types/components/FallbackEntityLink.vue.d.ts +0 -8
  20. package/dist/types/components/FallbackEntityLink.vue.d.ts.map +0 -1
  21. package/dist/types/components/GeoMapRenderer.vue.d.ts +0 -11
  22. package/dist/types/components/GeoMapRenderer.vue.d.ts.map +0 -1
  23. package/dist/types/components/GoldenSignalsRenderer.vue.d.ts +0 -6
  24. package/dist/types/components/GoldenSignalsRenderer.vue.d.ts.map +0 -1
  25. package/dist/types/components/QueryDataProvider.vue.d.ts +0 -30
  26. package/dist/types/components/QueryDataProvider.vue.d.ts.map +0 -1
  27. package/dist/types/components/SimpleChartRenderer.vue.d.ts +0 -6
  28. package/dist/types/components/SimpleChartRenderer.vue.d.ts.map +0 -1
  29. package/dist/types/components/TimeseriesChartRenderer.vue.d.ts +0 -12
  30. package/dist/types/components/TimeseriesChartRenderer.vue.d.ts.map +0 -1
  31. package/dist/types/components/TopNTableRenderer.vue.d.ts +0 -6
  32. package/dist/types/components/TopNTableRenderer.vue.d.ts.map +0 -1
  33. package/dist/types/components/layout/DraggableGridLayout.vue.d.ts +0 -32
  34. package/dist/types/components/layout/DraggableGridLayout.vue.d.ts.map +0 -1
  35. package/dist/types/components/layout/GridLayout.vue.d.ts +0 -30
  36. package/dist/types/components/layout/GridLayout.vue.d.ts.map +0 -1
  37. package/dist/types/components/layout/grid-utils.d.ts +0 -3
  38. package/dist/types/components/layout/grid-utils.d.ts.map +0 -1
  39. package/dist/types/composables/index.d.ts +0 -15
  40. package/dist/types/composables/index.d.ts.map +0 -1
  41. package/dist/types/composables/useContextLinks.d.ts +0 -67
  42. package/dist/types/composables/useContextLinks.d.ts.map +0 -1
  43. package/dist/types/composables/useDashboardInternalContext.d.ts +0 -11
  44. package/dist/types/composables/useDashboardInternalContext.d.ts.map +0 -1
  45. package/dist/types/composables/useEvauluateFeatureFlag.d.ts +0 -4
  46. package/dist/types/composables/useEvauluateFeatureFlag.d.ts.map +0 -1
  47. package/dist/types/composables/useI18n.d.ts +0 -9
  48. package/dist/types/composables/useI18n.d.ts.map +0 -1
  49. package/dist/types/composables/useIssueQuery.d.ts +0 -6
  50. package/dist/types/composables/useIssueQuery.d.ts.map +0 -1
  51. package/dist/types/composables/useRequestQueue.d.ts +0 -3
  52. package/dist/types/composables/useRequestQueue.d.ts.map +0 -1
  53. package/dist/types/constants.d.ts +0 -16
  54. package/dist/types/constants.d.ts.map +0 -1
  55. package/dist/types/index.d.ts +0 -8
  56. package/dist/types/index.d.ts.map +0 -1
  57. package/dist/types/stores/tests/setupPiniaTestStore.d.ts +0 -13
  58. package/dist/types/stores/tests/setupPiniaTestStore.d.ts.map +0 -1
  59. package/dist/types/test-utils/dragutil.d.ts +0 -8
  60. package/dist/types/test-utils/dragutil.d.ts.map +0 -1
  61. package/dist/types/test-utils/index.d.ts +0 -2
  62. package/dist/types/test-utils/index.d.ts.map +0 -1
  63. package/dist/types/types/grid-layout-types.d.ts +0 -26
  64. package/dist/types/types/grid-layout-types.d.ts.map +0 -1
  65. package/dist/types/types/index.d.ts +0 -4
  66. package/dist/types/types/index.d.ts.map +0 -1
  67. package/dist/types/types/renderer-types.d.ts +0 -23
  68. package/dist/types/types/renderer-types.d.ts.map +0 -1
  69. package/dist/types/types/tile-events.d.ts +0 -10
  70. package/dist/types/types/tile-events.d.ts.map +0 -1
  71. package/dist/types/utils/configure-definition.d.ts +0 -10
  72. package/dist/types/utils/configure-definition.d.ts.map +0 -1
  73. package/dist/types/utils/index.d.ts +0 -2
  74. package/dist/types/utils/index.d.ts.map +0 -1
@@ -1,4559 +0,0 @@
1
- var ci = Object.defineProperty;
2
- var _t = (a) => {
3
- throw TypeError(a);
4
- };
5
- var fi = (a, e, t) => e in a ? ci(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
6
- var bt = (a, e, t) => fi(a, typeof e != "symbol" ? e + "" : e, t), st = (a, e, t) => e.has(a) || _t("Cannot " + t);
7
- var v = (a, e, t) => (st(a, e, "read from private field"), t ? t.call(a) : e.get(a)), B = (a, e, t) => e.has(a) ? _t("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(a) : e.set(a, t), M = (a, e, t, i) => (st(a, e, "write to private field"), i ? i.call(a, t) : e.set(a, t), t), U = (a, e, t) => (st(a, e, "access private method"), t);
8
- var Te = (a, e, t, i) => ({
9
- set _(s) {
10
- M(a, e, s, t);
11
- },
12
- get _() {
13
- return v(a, e, i);
14
- }
15
- });
16
- import { ref as L, watchEffect as Ot, inject as ve, provide as gi, onMounted as Xe, computed as k, watch as Se, onUnmounted as Ze, getCurrentInstance as mi, defineComponent as V, resolveComponent as ge, createBlock as O, renderSlot as ze, createCommentVNode as K, unref as E, openBlock as x, createSlots as Je, withCtx as P, createElementVNode as se, toDisplayString as ae, normalizeStyle as nt, normalizeClass as De, createVNode as re, mergeProps as Ht, createTextVNode as ht, createElementBlock as G, normalizeProps as pi, guardReactiveProps as yi, defineAsyncComponent as It, mergeModels as Ge, useCssVars as ut, useModel as Mt, readonly as rt, toRef as Ne, nextTick as dt, resolveDynamicComponent as qt, toHandlers as vi, Fragment as Pt, renderList as $t, useTemplateRef as _i } from "vue";
17
- import { msToGranularity as ot, getFieldDataSources as Bt, stripUnknownFilters as bi, TimePeriods as wi, TIMEFRAME_LOOKUP as Ei, formatTime as wt, EXPORT_RECORD_LIMIT as xi } from "@kong-ui-public/analytics-utilities";
18
- import { handleQueryError as Ci, SimpleChart as Ri, AnalyticsChart as ki, TopNTable as Ti, CsvExportModal as Si } from "@kong-ui-public/analytics-chart";
19
- import zi from "swrv";
20
- import "axios";
21
- import { createI18n as Di, i18nTComponent as Ni } from "@kong-ui-public/i18n";
22
- import { useAnalyticsConfigStore as qe } from "@kong-ui-public/analytics-config-store";
23
- import { VisibilityOffIcon as Li, WarningOutlineIcon as Ai, WarningIcon as Oi, ProgressIcon as Hi, RefreshIcon as Ii, EditIcon as Mi, MoreIcon as qi } from "@kong/icons";
24
- import { MetricsProvider as Pi, MetricsConsumer as $i } from "@kong-ui-public/analytics-metric-provider";
25
- var Ft = /* @__PURE__ */ ((a) => (a.VALIDATING = "VALIDATING", a.VALIDATING_HAS_DATA = "VALIDATING_HAS_DATA", a.PENDING = "PENDING", a.SUCCESS = "SUCCESS", a.SUCCESS_HAS_DATA = "SUCCESS_HAS_DATA", a.ERROR = "ERROR", a.STALE_IF_ERROR = "STALE_IF_ERROR", a))(Ft || {});
26
- const Bi = (a) => {
27
- var e, t, i, s, r;
28
- return a ? !!// TODO: revisit: currently only the first check ever matters?
29
- ((e = Object.keys(a)) != null && e.length || (t = a.data) != null && t.length || (s = (i = a.data) == null ? void 0 : i.data) != null && s.length || !((r = a.data) != null && r.data) && typeof a.data == "object" && Object.keys(a == null ? void 0 : a.data).length) : !1;
30
- };
31
- function Fi(a = L({}), e, t, i = Bi) {
32
- const s = L(
33
- "PENDING"
34
- /* PENDING */
35
- );
36
- return Ot(() => {
37
- const r = i(a.value);
38
- if (a.value && r && t.value) {
39
- s.value = "VALIDATING_HAS_DATA";
40
- return;
41
- }
42
- if (a.value && t.value) {
43
- s.value = "VALIDATING";
44
- return;
45
- }
46
- if (a.value && e.value) {
47
- s.value = "STALE_IF_ERROR";
48
- return;
49
- }
50
- if (a.value === void 0 && !e.value) {
51
- s.value = "PENDING";
52
- return;
53
- }
54
- if (a.value && !e.value && r) {
55
- s.value = "SUCCESS_HAS_DATA";
56
- return;
57
- }
58
- if (a.value && !e.value) {
59
- s.value = "SUCCESS";
60
- return;
61
- }
62
- a.value === void 0 && e && (s.value = "ERROR");
63
- }), {
64
- state: s,
65
- swrvState: Ft
66
- };
67
- }
68
- const Ui = {
69
- noQueryBridge: "No query bridge provided. Unable to render dashboard.",
70
- trendRange: {
71
- "24h": "Last 24-hour summary",
72
- "7d": "Last 7-day summary",
73
- "30d": "Last 30-day summary"
74
- },
75
- edit: "Edit",
76
- duplicateTile: "Duplicate",
77
- exit_fullscreen: "Exit fullscreen",
78
- fullscreen: "Fullscreen",
79
- remove: "Remove",
80
- delete: "Delete"
81
- }, Gi = {
82
- defaultFilename: "Chart export",
83
- exportAsCsv: "Export as CSV"
84
- }, Wi = "Explore", Ki = "View requests", Qi = "This tile was configured with {savedGranularity} granularity, which is no longer available. It now shows {currentGranularity} data, the closest available granularity.", Vi = {
85
- daily: "1 day",
86
- fiveMinutely: "5 minutes",
87
- hourly: "1 hour",
88
- minutely: "1 minute",
89
- tenMinutely: "10 minutes",
90
- tenSecondly: "10 seconds",
91
- thirtyMinutely: "30 minutes",
92
- thirtySecondly: "30 seconds",
93
- twelveHourly: "12 hours",
94
- twoHourly: "2 hours",
95
- weekly: "1 week",
96
- unknown: "Unknown"
97
- }, Yi = {
98
- renderer: Ui,
99
- csvExport: Gi,
100
- jumpToExplore: Wi,
101
- jumpToRequests: Ki,
102
- query_aged_out_warning: Qi,
103
- granularities: Vi
104
- };
105
- function ji() {
106
- const a = Di("en-us", Yi);
107
- return {
108
- i18n: a,
109
- i18nT: Ni(a)
110
- // Translation component <i18n-t>
111
- };
112
- }
113
- const Pe = 170, ct = 6, ye = "analytics-query-provider", Et = "{entity-id}", Xi = "{cp-id}", Zi = "{timeframe}", Ji = 30 * 1e3, es = 3e5, ts = 36e5;
114
- function is() {
115
- const a = ve(ye);
116
- return {
117
- evaluateFeatureFlag: (t, i) => a ? a.evaluateFeatureFlagFn(t, i) : i
118
- };
119
- }
120
- function ss(a) {
121
- return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a;
122
- }
123
- var Ut = { exports: {} };
124
- (function(a) {
125
- var e = Object.prototype.hasOwnProperty, t = "~";
126
- function i() {
127
- }
128
- Object.create && (i.prototype = /* @__PURE__ */ Object.create(null), new i().__proto__ || (t = !1));
129
- function s(d, u, h) {
130
- this.fn = d, this.context = u, this.once = h || !1;
131
- }
132
- function r(d, u, h, l, f) {
133
- if (typeof h != "function")
134
- throw new TypeError("The listener must be a function");
135
- var g = new s(h, l || d, f), p = t ? t + u : u;
136
- return d._events[p] ? d._events[p].fn ? d._events[p] = [d._events[p], g] : d._events[p].push(g) : (d._events[p] = g, d._eventsCount++), d;
137
- }
138
- function o(d, u) {
139
- --d._eventsCount === 0 ? d._events = new i() : delete d._events[u];
140
- }
141
- function n() {
142
- this._events = new i(), this._eventsCount = 0;
143
- }
144
- n.prototype.eventNames = function() {
145
- var u = [], h, l;
146
- if (this._eventsCount === 0) return u;
147
- for (l in h = this._events)
148
- e.call(h, l) && u.push(t ? l.slice(1) : l);
149
- return Object.getOwnPropertySymbols ? u.concat(Object.getOwnPropertySymbols(h)) : u;
150
- }, n.prototype.listeners = function(u) {
151
- var h = t ? t + u : u, l = this._events[h];
152
- if (!l) return [];
153
- if (l.fn) return [l.fn];
154
- for (var f = 0, g = l.length, p = new Array(g); f < g; f++)
155
- p[f] = l[f].fn;
156
- return p;
157
- }, n.prototype.listenerCount = function(u) {
158
- var h = t ? t + u : u, l = this._events[h];
159
- return l ? l.fn ? 1 : l.length : 0;
160
- }, n.prototype.emit = function(u, h, l, f, g, p) {
161
- var y = t ? t + u : u;
162
- if (!this._events[y]) return !1;
163
- var m = this._events[y], C = arguments.length, A, D;
164
- if (m.fn) {
165
- switch (m.once && this.removeListener(u, m.fn, void 0, !0), C) {
166
- case 1:
167
- return m.fn.call(m.context), !0;
168
- case 2:
169
- return m.fn.call(m.context, h), !0;
170
- case 3:
171
- return m.fn.call(m.context, h, l), !0;
172
- case 4:
173
- return m.fn.call(m.context, h, l, f), !0;
174
- case 5:
175
- return m.fn.call(m.context, h, l, f, g), !0;
176
- case 6:
177
- return m.fn.call(m.context, h, l, f, g, p), !0;
178
- }
179
- for (D = 1, A = new Array(C - 1); D < C; D++)
180
- A[D - 1] = arguments[D];
181
- m.fn.apply(m.context, A);
182
- } else {
183
- var J = m.length, F;
184
- for (D = 0; D < J; D++)
185
- switch (m[D].once && this.removeListener(u, m[D].fn, void 0, !0), C) {
186
- case 1:
187
- m[D].fn.call(m[D].context);
188
- break;
189
- case 2:
190
- m[D].fn.call(m[D].context, h);
191
- break;
192
- case 3:
193
- m[D].fn.call(m[D].context, h, l);
194
- break;
195
- case 4:
196
- m[D].fn.call(m[D].context, h, l, f);
197
- break;
198
- default:
199
- if (!A) for (F = 1, A = new Array(C - 1); F < C; F++)
200
- A[F - 1] = arguments[F];
201
- m[D].fn.apply(m[D].context, A);
202
- }
203
- }
204
- return !0;
205
- }, n.prototype.on = function(u, h, l) {
206
- return r(this, u, h, l, !1);
207
- }, n.prototype.once = function(u, h, l) {
208
- return r(this, u, h, l, !0);
209
- }, n.prototype.removeListener = function(u, h, l, f) {
210
- var g = t ? t + u : u;
211
- if (!this._events[g]) return this;
212
- if (!h)
213
- return o(this, g), this;
214
- var p = this._events[g];
215
- if (p.fn)
216
- p.fn === h && (!f || p.once) && (!l || p.context === l) && o(this, g);
217
- else {
218
- for (var y = 0, m = [], C = p.length; y < C; y++)
219
- (p[y].fn !== h || f && !p[y].once || l && p[y].context !== l) && m.push(p[y]);
220
- m.length ? this._events[g] = m.length === 1 ? m[0] : m : o(this, g);
221
- }
222
- return this;
223
- }, n.prototype.removeAllListeners = function(u) {
224
- var h;
225
- return u ? (h = t ? t + u : u, this._events[h] && o(this, h)) : (this._events = new i(), this._eventsCount = 0), this;
226
- }, n.prototype.off = n.prototype.removeListener, n.prototype.addListener = n.prototype.on, n.prefixed = t, n.EventEmitter = n, a.exports = n;
227
- })(Ut);
228
- var rs = Ut.exports;
229
- const ns = /* @__PURE__ */ ss(rs);
230
- class Gt extends Error {
231
- constructor(e) {
232
- super(e), this.name = "TimeoutError";
233
- }
234
- }
235
- class os extends Error {
236
- constructor(e) {
237
- super(), this.name = "AbortError", this.message = e;
238
- }
239
- }
240
- const xt = (a) => globalThis.DOMException === void 0 ? new os(a) : new DOMException(a), Ct = (a) => {
241
- const e = a.reason === void 0 ? xt("This operation was aborted.") : a.reason;
242
- return e instanceof Error ? e : xt(e);
243
- };
244
- function as(a, e) {
245
- const {
246
- milliseconds: t,
247
- fallback: i,
248
- message: s,
249
- customTimers: r = { setTimeout, clearTimeout }
250
- } = e;
251
- let o, n;
252
- const u = new Promise((h, l) => {
253
- if (typeof t != "number" || Math.sign(t) !== 1)
254
- throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);
255
- if (e.signal) {
256
- const { signal: g } = e;
257
- g.aborted && l(Ct(g)), n = () => {
258
- l(Ct(g));
259
- }, g.addEventListener("abort", n, { once: !0 });
260
- }
261
- if (t === Number.POSITIVE_INFINITY) {
262
- a.then(h, l);
263
- return;
264
- }
265
- const f = new Gt();
266
- o = r.setTimeout.call(void 0, () => {
267
- if (i) {
268
- try {
269
- h(i());
270
- } catch (g) {
271
- l(g);
272
- }
273
- return;
274
- }
275
- typeof a.cancel == "function" && a.cancel(), s === !1 ? h() : s instanceof Error ? l(s) : (f.message = s ?? `Promise timed out after ${t} milliseconds`, l(f));
276
- }, t), (async () => {
277
- try {
278
- h(await a);
279
- } catch (g) {
280
- l(g);
281
- }
282
- })();
283
- }).finally(() => {
284
- u.clear(), n && e.signal && e.signal.removeEventListener("abort", n);
285
- });
286
- return u.clear = () => {
287
- r.clearTimeout.call(void 0, o), o = void 0;
288
- }, u;
289
- }
290
- function ls(a, e, t) {
291
- let i = 0, s = a.length;
292
- for (; s > 0; ) {
293
- const r = Math.trunc(s / 2);
294
- let o = i + r;
295
- t(a[o], e) <= 0 ? (i = ++o, s -= r + 1) : s = r;
296
- }
297
- return i;
298
- }
299
- var ee;
300
- class hs {
301
- constructor() {
302
- B(this, ee, []);
303
- }
304
- enqueue(e, t) {
305
- t = {
306
- priority: 0,
307
- ...t
308
- };
309
- const i = {
310
- priority: t.priority,
311
- id: t.id,
312
- run: e
313
- };
314
- if (this.size === 0 || v(this, ee)[this.size - 1].priority >= t.priority) {
315
- v(this, ee).push(i);
316
- return;
317
- }
318
- const s = ls(v(this, ee), i, (r, o) => o.priority - r.priority);
319
- v(this, ee).splice(s, 0, i);
320
- }
321
- setPriority(e, t) {
322
- const i = v(this, ee).findIndex((r) => r.id === e);
323
- if (i === -1)
324
- throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);
325
- const [s] = v(this, ee).splice(i, 1);
326
- this.enqueue(s.run, { priority: t, id: e });
327
- }
328
- dequeue() {
329
- const e = v(this, ee).shift();
330
- return e == null ? void 0 : e.run;
331
- }
332
- filter(e) {
333
- return v(this, ee).filter((t) => t.priority === e.priority).map((t) => t.run);
334
- }
335
- get size() {
336
- return v(this, ee).length;
337
- }
338
- }
339
- ee = new WeakMap();
340
- var be, we, pe, Oe, Ee, He, te, xe, Q, Ie, ie, Ce, fe, Me, je, z, Wt, Kt, Qt, Vt, Yt, Be, at, lt, Fe, jt, Ue;
341
- class us extends ns {
342
- // TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()`
343
- constructor(t) {
344
- var i, s;
345
- super();
346
- B(this, z);
347
- B(this, be);
348
- B(this, we);
349
- B(this, pe, 0);
350
- B(this, Oe);
351
- B(this, Ee);
352
- B(this, He, 0);
353
- B(this, te);
354
- B(this, xe);
355
- B(this, Q);
356
- B(this, Ie);
357
- B(this, ie, 0);
358
- // The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
359
- B(this, Ce);
360
- B(this, fe);
361
- B(this, Me);
362
- // Use to assign a unique identifier to a promise function, if not explicitly specified
363
- B(this, je, 1n);
364
- /**
365
- Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
366
-
367
- Applies to each future operation.
368
- */
369
- bt(this, "timeout");
370
- if (t = {
371
- carryoverConcurrencyCount: !1,
372
- intervalCap: Number.POSITIVE_INFINITY,
373
- interval: 0,
374
- concurrency: Number.POSITIVE_INFINITY,
375
- autoStart: !0,
376
- queueClass: hs,
377
- ...t
378
- }, !(typeof t.intervalCap == "number" && t.intervalCap >= 1))
379
- throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${((i = t.intervalCap) == null ? void 0 : i.toString()) ?? ""}\` (${typeof t.intervalCap})`);
380
- if (t.interval === void 0 || !(Number.isFinite(t.interval) && t.interval >= 0))
381
- throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${((s = t.interval) == null ? void 0 : s.toString()) ?? ""}\` (${typeof t.interval})`);
382
- M(this, be, t.carryoverConcurrencyCount), M(this, we, t.intervalCap === Number.POSITIVE_INFINITY || t.interval === 0), M(this, Oe, t.intervalCap), M(this, Ee, t.interval), M(this, Q, new t.queueClass()), M(this, Ie, t.queueClass), this.concurrency = t.concurrency, this.timeout = t.timeout, M(this, Me, t.throwOnTimeout === !0), M(this, fe, t.autoStart === !1);
383
- }
384
- get concurrency() {
385
- return v(this, Ce);
386
- }
387
- set concurrency(t) {
388
- if (!(typeof t == "number" && t >= 1))
389
- throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);
390
- M(this, Ce, t), U(this, z, Fe).call(this);
391
- }
392
- /**
393
- Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.
394
-
395
- For example, this can be used to prioritize a promise function to run earlier.
396
-
397
- ```js
398
- import PQueue from 'p-queue';
399
-
400
- const queue = new PQueue({concurrency: 1});
401
-
402
- queue.add(async () => '🦄', {priority: 1});
403
- queue.add(async () => '🦀', {priority: 0, id: '🦀'});
404
- queue.add(async () => '🦄', {priority: 1});
405
- queue.add(async () => '🦄', {priority: 1});
406
-
407
- queue.setPriority('🦀', 2);
408
- ```
409
-
410
- In this case, the promise function with `id: '🦀'` runs second.
411
-
412
- You can also deprioritize a promise function to delay its execution:
413
-
414
- ```js
415
- import PQueue from 'p-queue';
416
-
417
- const queue = new PQueue({concurrency: 1});
418
-
419
- queue.add(async () => '🦄', {priority: 1});
420
- queue.add(async () => '🦀', {priority: 1, id: '🦀'});
421
- queue.add(async () => '🦄');
422
- queue.add(async () => '🦄', {priority: 0});
423
-
424
- queue.setPriority('🦀', -1);
425
- ```
426
- Here, the promise function with `id: '🦀'` executes last.
427
- */
428
- setPriority(t, i) {
429
- v(this, Q).setPriority(t, i);
430
- }
431
- async add(t, i = {}) {
432
- return i.id ?? (i.id = (Te(this, je)._++).toString()), i = {
433
- timeout: this.timeout,
434
- throwOnTimeout: v(this, Me),
435
- ...i
436
- }, new Promise((s, r) => {
437
- v(this, Q).enqueue(async () => {
438
- var o;
439
- Te(this, ie)._++, Te(this, pe)._++;
440
- try {
441
- (o = i.signal) == null || o.throwIfAborted();
442
- let n = t({ signal: i.signal });
443
- i.timeout && (n = as(Promise.resolve(n), { milliseconds: i.timeout })), i.signal && (n = Promise.race([n, U(this, z, jt).call(this, i.signal)]));
444
- const d = await n;
445
- s(d), this.emit("completed", d);
446
- } catch (n) {
447
- if (n instanceof Gt && !i.throwOnTimeout) {
448
- s();
449
- return;
450
- }
451
- r(n), this.emit("error", n);
452
- } finally {
453
- U(this, z, Qt).call(this);
454
- }
455
- }, i), this.emit("add"), U(this, z, Be).call(this);
456
- });
457
- }
458
- async addAll(t, i) {
459
- return Promise.all(t.map(async (s) => this.add(s, i)));
460
- }
461
- /**
462
- Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
463
- */
464
- start() {
465
- return v(this, fe) ? (M(this, fe, !1), U(this, z, Fe).call(this), this) : this;
466
- }
467
- /**
468
- Put queue execution on hold.
469
- */
470
- pause() {
471
- M(this, fe, !0);
472
- }
473
- /**
474
- Clear the queue.
475
- */
476
- clear() {
477
- M(this, Q, new (v(this, Ie))());
478
- }
479
- /**
480
- Can be called multiple times. Useful if you for example add additional items at a later time.
481
-
482
- @returns A promise that settles when the queue becomes empty.
483
- */
484
- async onEmpty() {
485
- v(this, Q).size !== 0 && await U(this, z, Ue).call(this, "empty");
486
- }
487
- /**
488
- @returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
489
-
490
- If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
491
-
492
- Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation.
493
- */
494
- async onSizeLessThan(t) {
495
- v(this, Q).size < t || await U(this, z, Ue).call(this, "next", () => v(this, Q).size < t);
496
- }
497
- /**
498
- The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
499
-
500
- @returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
501
- */
502
- async onIdle() {
503
- v(this, ie) === 0 && v(this, Q).size === 0 || await U(this, z, Ue).call(this, "idle");
504
- }
505
- /**
506
- Size of the queue, the number of queued items waiting to run.
507
- */
508
- get size() {
509
- return v(this, Q).size;
510
- }
511
- /**
512
- Size of the queue, filtered by the given options.
513
-
514
- For example, this can be used to find the number of items remaining in the queue with a specific priority level.
515
- */
516
- sizeBy(t) {
517
- return v(this, Q).filter(t).length;
518
- }
519
- /**
520
- Number of running items (no longer in the queue).
521
- */
522
- get pending() {
523
- return v(this, ie);
524
- }
525
- /**
526
- Whether the queue is currently paused.
527
- */
528
- get isPaused() {
529
- return v(this, fe);
530
- }
531
- }
532
- be = new WeakMap(), we = new WeakMap(), pe = new WeakMap(), Oe = new WeakMap(), Ee = new WeakMap(), He = new WeakMap(), te = new WeakMap(), xe = new WeakMap(), Q = new WeakMap(), Ie = new WeakMap(), ie = new WeakMap(), Ce = new WeakMap(), fe = new WeakMap(), Me = new WeakMap(), je = new WeakMap(), z = new WeakSet(), Wt = function() {
533
- return v(this, we) || v(this, pe) < v(this, Oe);
534
- }, Kt = function() {
535
- return v(this, ie) < v(this, Ce);
536
- }, Qt = function() {
537
- Te(this, ie)._--, U(this, z, Be).call(this), this.emit("next");
538
- }, Vt = function() {
539
- U(this, z, lt).call(this), U(this, z, at).call(this), M(this, xe, void 0);
540
- }, Yt = function() {
541
- const t = Date.now();
542
- if (v(this, te) === void 0) {
543
- const i = v(this, He) - t;
544
- if (i < 0)
545
- M(this, pe, v(this, be) ? v(this, ie) : 0);
546
- else
547
- return v(this, xe) === void 0 && M(this, xe, setTimeout(() => {
548
- U(this, z, Vt).call(this);
549
- }, i)), !0;
550
- }
551
- return !1;
552
- }, Be = function() {
553
- if (v(this, Q).size === 0)
554
- return v(this, te) && clearInterval(v(this, te)), M(this, te, void 0), this.emit("empty"), v(this, ie) === 0 && this.emit("idle"), !1;
555
- if (!v(this, fe)) {
556
- const t = !v(this, z, Yt);
557
- if (v(this, z, Wt) && v(this, z, Kt)) {
558
- const i = v(this, Q).dequeue();
559
- return i ? (this.emit("active"), i(), t && U(this, z, at).call(this), !0) : !1;
560
- }
561
- }
562
- return !1;
563
- }, at = function() {
564
- v(this, we) || v(this, te) !== void 0 || (M(this, te, setInterval(() => {
565
- U(this, z, lt).call(this);
566
- }, v(this, Ee))), M(this, He, Date.now() + v(this, Ee)));
567
- }, lt = function() {
568
- v(this, pe) === 0 && v(this, ie) === 0 && v(this, te) && (clearInterval(v(this, te)), M(this, te, void 0)), M(this, pe, v(this, be) ? v(this, ie) : 0), U(this, z, Fe).call(this);
569
- }, /**
570
- Executes all queued functions until it reaches the limit.
571
- */
572
- Fe = function() {
573
- for (; U(this, z, Be).call(this); )
574
- ;
575
- }, jt = async function(t) {
576
- return new Promise((i, s) => {
577
- t.addEventListener("abort", () => {
578
- s(t.reason);
579
- }, { once: !0 });
580
- });
581
- }, Ue = async function(t, i) {
582
- return new Promise((s) => {
583
- const r = () => {
584
- i && !i() || (this.off(t, r), s());
585
- };
586
- this.on(t, r);
587
- });
588
- };
589
- const ds = () => {
590
- const a = qe(), e = ve(ye);
591
- if (!e)
592
- return;
593
- if (e.queryFnOverride) {
594
- console.warn("Detected incorrect use of useRequestQueue. This composable should not be used in nested components. Please discuss with team-data or report an issue if you feel you have a use case.");
595
- return;
596
- }
597
- const t = new us({
598
- carryoverConcurrencyCount: !0,
599
- concurrency: a.maxParallelRequests,
600
- interval: a.requestInterval,
601
- intervalCap: a.requestIntervalCap
602
- }), i = {
603
- ...e,
604
- queryFnOverride: !0,
605
- queryFn: (s, r) => t.add(() => e.queryFn(s, r), { throwOnTimeout: !0 })
606
- };
607
- gi(ye, i);
608
- };
609
- function cs({
610
- queryBridge: a,
611
- context: e,
612
- definition: t,
613
- chartData: i
614
- }) {
615
- const s = L(""), r = L(""), o = L(void 0), n = L(void 0), d = qe();
616
- Xe(async () => {
617
- var S, H;
618
- s.value = await ((S = a == null ? void 0 : a.exploreBaseUrl) == null ? void 0 : S.call(a)) ?? "", r.value = await ((H = a == null ? void 0 : a.requestsBaseUrl) == null ? void 0 : H.call(a)) ?? "";
619
- });
620
- const u = k(() => d.analytics && d.percentiles), h = k(() => !["golden_signals", "top_n", "gauge"].includes(t.value.chart.type)), l = k(() => r.value && t.value.query && t.value.query.datasource !== "llm_usage" && u.value), f = k(() => s.value && t.value.query && ["basic", "api_usage", "llm_usage", void 0].includes(t.value.query.datasource) && u.value), g = k(() => i.value ? ot(i.value.meta.granularity_ms) : void 0), p = k(() => {
621
- var Y;
622
- const S = [...e.value.filters, ...t.value.query.filters ?? []], H = ((Y = t.value.query) == null ? void 0 : Y.datasource) ?? "api_usage";
623
- return S.filter((de) => Bt(de.field).some((Re) => H === Re));
624
- }), y = k(() => {
625
- if (!f.value || !h.value)
626
- return "";
627
- const S = p.value, H = t.value.query.time_range || e.value.timeSpec, Y = J(H, S);
628
- return F(Y);
629
- }), m = k(() => {
630
- if (!l.value || !h.value)
631
- return "";
632
- const S = p.value, H = A(
633
- t.value.query.time_range || e.value.timeSpec,
634
- S
635
- );
636
- return C(H);
637
- }), C = (S) => l.value ? `${r.value}?q=${JSON.stringify(S)}` : "", A = (S, H) => {
638
- var Y, de;
639
- return {
640
- filter: H,
641
- timeframe: {
642
- timePeriodsKey: S.type === "relative" ? S.time_range : "custom",
643
- start: S.type === "absolute" ? (Y = i.value) == null ? void 0 : Y.meta.start_ms : void 0,
644
- end: S.type === "absolute" ? (de = i.value) == null ? void 0 : de.meta.end_ms : void 0
645
- }
646
- };
647
- }, D = (S, H) => ({
648
- filter: H,
649
- timeframe: {
650
- timePeriodsKey: S.type === "relative" ? S.time_range : "custom",
651
- start: S.type === "absolute" ? S.start : void 0,
652
- end: S.type === "absolute" ? S.end : void 0
653
- }
654
- }), J = (S, H) => {
655
- const Y = t.value.query.dimensions ?? [];
656
- return {
657
- filters: H,
658
- metrics: t.value.query.metrics ?? [],
659
- dimensions: Y,
660
- time_range: S,
661
- granularity: t.value.query.granularity || g.value
662
- };
663
- }, F = (S) => {
664
- if (!f.value)
665
- return "";
666
- const H = ["api_usage", "llm_usage"].includes(t.value.query.datasource) ? t.value.query.datasource : "api_usage";
667
- return `${s.value}?q=${JSON.stringify(S)}&d=${H}&c=${t.value.chart.type}`;
668
- };
669
- return Se([l, f], ([S, H]) => {
670
- S && (o.value = { href: "" }), H && (n.value = { href: "" });
671
- }), {
672
- exploreLinkKebabMenu: y,
673
- requestsLinkKebabMenu: m,
674
- canShowKebabMenu: h,
675
- canGenerateRequestsLink: l,
676
- canGenerateExploreLink: f,
677
- requestsLinkZoomActions: o,
678
- exploreLinkZoomActions: n,
679
- buildExploreQuery: J,
680
- buildRequestsQueryZoomActions: D,
681
- buildExploreLink: F,
682
- buildRequestLink: C
683
- };
684
- }
685
- const fs = (a, e, t) => {
686
- const i = [];
687
- return e && i.push(...e), i.push(...bi(a, t)), i;
688
- };
689
- function gs() {
690
- const a = ve(ye), e = new AbortController();
691
- return Ze(() => {
692
- e.abort();
693
- }), { issueQuery: async (i, s, r) => {
694
- if (!a)
695
- throw new Error("Query bridge is not defined");
696
- const {
697
- datasource: o,
698
- limit: n,
699
- ...d
700
- } = i, u = o || "basic", h = fs(u, i.filters, s.filters);
701
- let l = i.time_range;
702
- l ? l.tz || (l = {
703
- ...l,
704
- tz: s.tz
705
- }) : l = {
706
- ...s.timeSpec,
707
- tz: s.tz
708
- };
709
- const f = {
710
- datasource: u,
711
- query: {
712
- ...d,
713
- time_range: l,
714
- filters: h,
715
- limit: r ?? n
716
- }
717
- };
718
- return a.queryFn(f, e);
719
- } };
720
- }
721
- function ms({
722
- context: a,
723
- globalFilters: e = L([]),
724
- isFullscreen: t = L(!1)
725
- }) {
726
- const i = qe(), s = k(() => a.value.timeSpec ? a.value.timeSpec : {
727
- type: "relative",
728
- time_range: i.defaultQueryTimeForOrg
729
- });
730
- return {
731
- internalContext: k(() => {
732
- var l, f, g;
733
- let { tz: o, refreshInterval: n, editable: d } = a.value;
734
- const u = [...a.value.filters ?? [], ...e.value];
735
- if (o || (o = new Intl.DateTimeFormat().resolvedOptions().timeZone), n === void 0 && (n = Ji), t.value) {
736
- let p = !1;
737
- if (s.value.type === "relative")
738
- p = ["15m", "1h", "6h", "12h", "24h"].includes(s.value.time_range);
739
- else {
740
- const C = s.value.start.getTime(), A = s.value.end.getTime();
741
- p = Math.abs(A - C) <= 864e5;
742
- }
743
- const y = (/* @__PURE__ */ new Date()).getTime();
744
- s.value.type === "absolute" && s.value.end.getTime() < y || s.value.type === "relative" && ["previous_week", "previous_month"].includes(s.value.time_range) ? n = 0 : p ? n = es : n = ts;
745
- }
746
- d === void 0 && (d = !1);
747
- const h = !!((g = (f = (l = mi()) == null ? void 0 : l.vnode) == null ? void 0 : f.props) != null && g.onTileTimeRangeZoom);
748
- return {
749
- filters: u,
750
- tz: o,
751
- timeSpec: s.value,
752
- refreshInterval: n,
753
- editable: d,
754
- zoomable: h
755
- };
756
- })
757
- };
758
- }
759
- const me = {
760
- useContextLinks: cs,
761
- useDashboardInternalContext: ms,
762
- useEvaluateFeatureFlag: is,
763
- useI18n: ji,
764
- useIssueQuery: gs,
765
- useRequestQueue: ds
766
- }, ft = /* @__PURE__ */ V({
767
- __name: "QueryDataProvider",
768
- props: {
769
- context: {},
770
- limitOverride: {},
771
- query: {},
772
- queryReady: { type: Boolean },
773
- refreshCounter: {}
774
- },
775
- emits: ["chart-data", "queryComplete"],
776
- setup(a, { emit: e }) {
777
- const t = a, i = e, { issueQuery: s } = me.useIssueQuery(), r = ve(ye), o = () => t.queryReady && r ? JSON.stringify([t.query, t.context, t.refreshCounter]) : null, { data: n, error: d, isValidating: u } = zi(o, async () => {
778
- try {
779
- const y = await s(t.query, t.context, t.limitOverride);
780
- return f.value = null, y;
781
- } catch (y) {
782
- throw f.value = Ci(y), y;
783
- } finally {
784
- i("queryComplete");
785
- }
786
- }, {
787
- refreshInterval: t.context.refreshInterval,
788
- revalidateOnFocus: !1,
789
- shouldRetryOnError: !1
790
- }), { state: h, swrvState: l } = Fi(n, d, u), f = L(null), g = k(() => h.value === l.ERROR || !!f.value), p = k(() => !t.queryReady || h.value === l.PENDING);
791
- return Se([() => n.value, () => h.value], ([y, m]) => {
792
- y && (m === "SUCCESS_HAS_DATA" || m === "SUCCESS") && i("chart-data", y);
793
- }), (y, m) => {
794
- const C = ge("KSkeleton"), A = ge("KEmptyState");
795
- return p.value || !E(n) && !g.value ? (x(), O(C, {
796
- key: 0,
797
- class: "chart-skeleton",
798
- type: "table"
799
- })) : g.value && f.value ? (x(), O(A, {
800
- key: 1,
801
- "action-button-visible": !1,
802
- "data-testid": "chart-empty-state"
803
- }, Je({
804
- icon: P(() => [
805
- f.value.type === "forbidden" ? (x(), O(E(Li), { key: 0 })) : (x(), O(E(Ai), { key: 1 }))
806
- ]),
807
- title: P(() => [
808
- se("p", null, ae(f.value.message), 1)
809
- ]),
810
- _: 2
811
- }, [
812
- f.value.details ? {
813
- name: "default",
814
- fn: P(() => [
815
- se("p", null, ae(f.value.details), 1)
816
- ]),
817
- key: "0"
818
- } : void 0
819
- ]), 1024)) : E(n) ? ze(y.$slots, "default", {
820
- key: 2,
821
- data: E(n)
822
- }) : K("", !0);
823
- };
824
- }
825
- }), ps = /* @__PURE__ */ V({
826
- __name: "SimpleChartRenderer",
827
- props: {
828
- query: {},
829
- context: {},
830
- queryReady: { type: Boolean },
831
- chartOptions: {},
832
- height: {},
833
- refreshCounter: {},
834
- requestsLink: {},
835
- exploreLink: {}
836
- },
837
- setup(a) {
838
- const e = a, t = k(() => e.chartOptions.type === "single_value");
839
- return (i, s) => (x(), O(ft, {
840
- context: a.context,
841
- query: a.query,
842
- "query-ready": a.queryReady,
843
- "refresh-counter": a.refreshCounter
844
- }, {
845
- default: P(({ data: r }) => [
846
- se("div", {
847
- class: De(["analytics-chart", { "single-value": t.value }]),
848
- style: nt({ height: `${a.height}px` })
849
- }, [
850
- re(E(Ri), {
851
- "chart-data": r,
852
- "chart-options": a.chartOptions,
853
- "synthetics-data-key": t.value ? void 0 : a.chartOptions.synthetics_data_key
854
- }, null, 8, ["chart-data", "chart-options", "synthetics-data-key"])
855
- ], 6)
856
- ]),
857
- _: 1
858
- }, 8, ["context", "query", "query-ready", "refresh-counter"]));
859
- }
860
- }), _e = (a, e) => {
861
- const t = a.__vccOpts || a;
862
- for (const [i, s] of e)
863
- t[i] = s;
864
- return t;
865
- }, Rt = /* @__PURE__ */ _e(ps, [["__scopeId", "data-v-5304442e"]]), ys = { class: "analytics-chart" }, vs = /* @__PURE__ */ V({
866
- __name: "BaseAnalyticsChartRenderer",
867
- props: {
868
- query: {},
869
- context: {},
870
- queryReady: { type: Boolean },
871
- chartOptions: {},
872
- height: {},
873
- refreshCounter: {},
874
- requestsLink: {},
875
- exploreLink: {},
876
- extraProps: {}
877
- },
878
- emits: ["edit-tile", "chart-data", "zoom-time-range", "view-requests", "select-chart-range"],
879
- setup(a, { emit: e }) {
880
- const t = a, i = e, { i18n: s } = me.useI18n(), r = k(() => ({
881
- type: t.chartOptions.type,
882
- stacked: t.chartOptions.stacked ?? !1,
883
- chartDatasetColors: t.chartOptions.chart_dataset_colors,
884
- threshold: t.chartOptions.threshold,
885
- hideTruncationWarning: t.query.limit !== void 0 && t.query.limit > 0
886
- })), o = k(() => t.context.zoomable), n = () => {
887
- i("edit-tile");
888
- }, d = (u) => {
889
- i("chart-data", u);
890
- };
891
- return (u, h) => {
892
- const l = ge("KDropdownItem");
893
- return x(), O(ft, {
894
- context: a.context,
895
- query: a.query,
896
- "query-ready": a.queryReady,
897
- "refresh-counter": a.refreshCounter,
898
- onChartData: d
899
- }, {
900
- default: P(({ data: f }) => [
901
- se("div", ys, [
902
- re(E(ki), Ht({
903
- "chart-data": f,
904
- "chart-options": r.value,
905
- "explore-link": a.exploreLink,
906
- "legend-position": "bottom",
907
- "requests-link": a.requestsLink,
908
- "synthetics-data-key": a.chartOptions.synthetics_data_key,
909
- "timeseries-zoom": o.value,
910
- "tooltip-title": ""
911
- }, a.extraProps, {
912
- onSelectChartRange: h[0] || (h[0] = (g) => i("select-chart-range", g)),
913
- onZoomTimeRange: h[1] || (h[1] = (g) => i("zoom-time-range", g))
914
- }), Je({ _: 2 }, [
915
- a.context.editable ? {
916
- name: "menu-items",
917
- fn: P(() => [
918
- re(l, { onClick: n }, {
919
- default: P(() => [
920
- ht(ae(E(s).t("renderer.edit")), 1)
921
- ]),
922
- _: 1
923
- })
924
- ]),
925
- key: "0"
926
- } : void 0
927
- ]), 1040, ["chart-data", "chart-options", "explore-link", "requests-link", "synthetics-data-key", "timeseries-zoom"])
928
- ])
929
- ]),
930
- _: 1
931
- }, 8, ["context", "query", "query-ready", "refresh-counter"]);
932
- };
933
- }
934
- }), gt = /* @__PURE__ */ _e(vs, [["__scopeId", "data-v-52357845"]]), kt = /* @__PURE__ */ V({
935
- __name: "BarChartRenderer",
936
- props: {
937
- query: {},
938
- context: {},
939
- queryReady: { type: Boolean },
940
- chartOptions: {},
941
- height: {},
942
- refreshCounter: {},
943
- requestsLink: {},
944
- exploreLink: {}
945
- },
946
- setup(a) {
947
- return (e, t) => (x(), O(gt, {
948
- "chart-options": a.chartOptions,
949
- context: a.context,
950
- "extra-props": { showAnnotations: !1 },
951
- height: a.height,
952
- query: a.query,
953
- "query-ready": a.queryReady,
954
- "refresh-counter": a.refreshCounter
955
- }, null, 8, ["chart-options", "context", "height", "query", "query-ready", "refresh-counter"]));
956
- }
957
- }), Tt = /* @__PURE__ */ V({
958
- __name: "TimeseriesChartRenderer",
959
- props: {
960
- query: {},
961
- context: {},
962
- queryReady: { type: Boolean },
963
- chartOptions: {},
964
- height: {},
965
- refreshCounter: {},
966
- requestsLink: {},
967
- exploreLink: {}
968
- },
969
- emits: ["zoom-time-range", "select-chart-range"],
970
- setup(a, { emit: e }) {
971
- const t = e;
972
- return (i, s) => (x(), O(gt, {
973
- "chart-options": a.chartOptions,
974
- context: a.context,
975
- "explore-link": a.exploreLink,
976
- height: a.height,
977
- query: a.query,
978
- "query-ready": a.queryReady,
979
- "refresh-counter": a.refreshCounter,
980
- "requests-link": a.requestsLink,
981
- onSelectChartRange: s[0] || (s[0] = (r) => t("select-chart-range", r)),
982
- onZoomTimeRange: s[1] || (s[1] = (r) => t("zoom-time-range", r))
983
- }, null, 8, ["chart-options", "context", "explore-link", "height", "query", "query-ready", "refresh-counter", "requests-link"]));
984
- }
985
- }), _s = { class: "metric-card-tile-wrapper" }, bs = /* @__PURE__ */ V({
986
- __name: "GoldenSignalsRenderer",
987
- props: {
988
- query: {},
989
- context: {},
990
- queryReady: { type: Boolean },
991
- chartOptions: {},
992
- height: {},
993
- refreshCounter: {},
994
- requestsLink: {},
995
- exploreLink: {}
996
- },
997
- setup(a) {
998
- const e = a, t = k(() => {
999
- var s, r;
1000
- const i = (s = e.query) == null ? void 0 : s.datasource;
1001
- if (i && i !== "api_usage" && i !== "basic")
1002
- throw new Error(`Invalid datasource value: ${i}`);
1003
- return {
1004
- datasource: (r = e.query) == null ? void 0 : r.datasource,
1005
- overrideTimeRange: e.context.timeSpec,
1006
- tz: e.context.tz,
1007
- additionalFilter: e.context.filters,
1008
- // TODO: Decide how to handle metric card filters.
1009
- longCardTitles: e.chartOptions.long_card_titles,
1010
- percentileLatency: e.chartOptions.percentile_latency,
1011
- refreshInterval: e.context.refreshInterval,
1012
- queryReady: e.queryReady,
1013
- refreshCounter: e.refreshCounter
1014
- };
1015
- });
1016
- return (i, s) => (x(), G("div", _s, [
1017
- re(E(Pi), pi(yi(t.value)), {
1018
- default: P(() => [
1019
- re(E($i))
1020
- ]),
1021
- _: 1
1022
- }, 16)
1023
- ]));
1024
- }
1025
- }), ws = /* @__PURE__ */ _e(bs, [["__scopeId", "data-v-86bb2448"]]), Es = {
1026
- class: "fallback-entity-link",
1027
- "data-testid": "entity-link-parent"
1028
- }, St = /* @__PURE__ */ V({
1029
- __name: "FallbackEntityLink",
1030
- props: {
1031
- entityLinkData: {}
1032
- },
1033
- setup(a) {
1034
- return (e, t) => (x(), G("div", Es, ae(a.entityLinkData.label), 1));
1035
- }
1036
- }), xs = /* @__PURE__ */ V({
1037
- __name: "TopNTableRenderer",
1038
- props: {
1039
- query: {},
1040
- context: {},
1041
- queryReady: { type: Boolean },
1042
- chartOptions: {},
1043
- height: {},
1044
- refreshCounter: {},
1045
- requestsLink: {},
1046
- exploreLink: {}
1047
- },
1048
- setup(a) {
1049
- const e = a, t = ve(ye), i = It(async () => {
1050
- if (t != null && t.fetchComponent)
1051
- try {
1052
- return await t.fetchComponent("EntityLink");
1053
- } catch {
1054
- return St;
1055
- }
1056
- return St;
1057
- }), s = (r) => {
1058
- var o;
1059
- if ((o = e.chartOptions) != null && o.entity_link)
1060
- if (r.id.includes(":")) {
1061
- const [n, d] = r.id.split(":");
1062
- return e.chartOptions.entity_link.replace(Xi, n).replace(Et, d);
1063
- } else
1064
- return e.chartOptions.entity_link.replace(Et, r.id);
1065
- return "";
1066
- };
1067
- return (r, o) => (x(), O(ft, {
1068
- context: a.context,
1069
- query: a.query,
1070
- "query-ready": a.queryReady,
1071
- "refresh-counter": a.refreshCounter
1072
- }, {
1073
- default: P(({ data: n }) => [
1074
- re(E(Ti), {
1075
- data: n,
1076
- "synthetics-data-key": a.chartOptions.synthetics_data_key
1077
- }, Je({ _: 2 }, [
1078
- e.chartOptions.entity_link ? {
1079
- name: "name",
1080
- fn: P(({ record: d }) => [
1081
- re(E(i), {
1082
- "entity-link-data": {
1083
- id: d.id,
1084
- label: d.name,
1085
- deleted: d.deleted
1086
- },
1087
- "external-link": s(d)
1088
- }, null, 8, ["entity-link-data", "external-link"])
1089
- ]),
1090
- key: "0"
1091
- } : void 0
1092
- ]), 1032, ["data", "synthetics-data-key"])
1093
- ]),
1094
- _: 1
1095
- }, 8, ["context", "query", "query-ready", "refresh-counter"]));
1096
- }
1097
- }), zt = "#6c7489", Cs = "12px", Dt = "20px", Nt = "32px", Xt = "20px", Rs = /* @__PURE__ */ V({
1098
- __name: "DonutChartRenderer",
1099
- props: {
1100
- query: {},
1101
- context: {},
1102
- queryReady: { type: Boolean },
1103
- chartOptions: {},
1104
- height: {},
1105
- refreshCounter: {},
1106
- requestsLink: {},
1107
- exploreLink: {}
1108
- },
1109
- setup(a) {
1110
- return (e, t) => (x(), O(gt, {
1111
- "chart-options": a.chartOptions,
1112
- context: a.context,
1113
- height: a.height,
1114
- query: a.query,
1115
- "query-ready": a.queryReady,
1116
- "refresh-counter": a.refreshCounter
1117
- }, null, 8, ["chart-options", "context", "height", "query", "query-ready", "refresh-counter"]));
1118
- }
1119
- }), ks = ["data-testid"], Ts = {
1120
- key: 0,
1121
- class: "tile-header"
1122
- }, Ss = { class: "badge-container" }, zs = { class: "badge-text" }, Ds = { key: 0 }, Ns = ["data-testid"], Ls = ["data-testid"], As = { class: "delete-option" }, Os = ["data-testid"], Hs = ["data-testid"], Is = /* @__PURE__ */ V({
1123
- __name: "DashboardTile",
1124
- props: /* @__PURE__ */ Ge({
1125
- context: {},
1126
- definition: {},
1127
- height: { default: Pe },
1128
- isFullscreen: { type: Boolean },
1129
- hideActions: { type: Boolean, default: !1 },
1130
- queryReady: { type: Boolean },
1131
- showRefresh: { type: Boolean, default: !1 },
1132
- tileId: {}
1133
- }, {
1134
- refreshCounter: { default: 0 },
1135
- refreshCounterModifiers: {}
1136
- }),
1137
- emits: /* @__PURE__ */ Ge(["edit-tile", "duplicate-tile", "remove-tile", "tile-time-range-zoom", "tile-bounds-change"], ["update:refreshCounter"]),
1138
- setup(a, { emit: e }) {
1139
- ut((b) => ({
1140
- v47039fac: `${b.height}px`
1141
- }));
1142
- const t = parseInt(Xt, 10), i = a, s = Mt(a, "refreshCounter"), r = () => {
1143
- y.value = !0, s.value++;
1144
- }, o = e, n = It(() => import("./GeoMapRenderer-BbPpTgP2.js")), d = ve(ye), { i18n: u } = me.useI18n(), h = L(), l = L({ status: "loading" }), f = L(!1), g = L(), p = L(!1), y = L(!0), {
1145
- exploreLinkKebabMenu: m,
1146
- requestsLinkKebabMenu: C,
1147
- canShowKebabMenu: A,
1148
- canGenerateRequestsLink: D,
1149
- canGenerateExploreLink: J,
1150
- requestsLinkZoomActions: F,
1151
- exploreLinkZoomActions: S,
1152
- buildExploreQuery: H,
1153
- buildExploreLink: Y,
1154
- buildRequestLink: de,
1155
- buildRequestsQueryZoomActions: ne
1156
- } = me.useContextLinks({
1157
- queryBridge: d,
1158
- chartData: rt(h),
1159
- definition: rt(Ne(i, "definition")),
1160
- context: rt(Ne(i, "context"))
1161
- }), { issueQuery: Re } = me.useIssueQuery();
1162
- Se(() => i.definition, async (b, T) => {
1163
- await dt(), g.value && (p.value = g.value.scrollWidth > g.value.clientWidth);
1164
- try {
1165
- JSON.stringify(b == null ? void 0 : b.query) !== JSON.stringify(T == null ? void 0 : T.query) && (y.value = !0);
1166
- } catch {
1167
- }
1168
- }, { immediate: !0, deep: !0 });
1169
- const tt = k(() => u.t("csvExport.defaultFilename")), $e = k(() => A.value && !i.hideActions && (R.value || i.context.editable)), R = k(() => !!m.value || ("allow_csv_export" in i.definition.chart ? i.definition.chart.allow_csv_export : !0) || i.context.editable), I = {
1170
- timeseries_line: Tt,
1171
- timeseries_bar: Tt,
1172
- horizontal_bar: kt,
1173
- vertical_bar: kt,
1174
- gauge: Rt,
1175
- donut: Rs,
1176
- golden_signals: ws,
1177
- top_n: xs,
1178
- slottable: void 0,
1179
- single_value: Rt,
1180
- choropleth_map: n
1181
- }, $ = k(() => {
1182
- var b, T, N;
1183
- return {
1184
- ...(b = q.value) != null && b.rendererEvents.supportsRequests ? { "select-chart-range": di } : {},
1185
- ...(T = q.value) != null && T.rendererEvents.supportsZoom ? { "zoom-time-range": hi } : {},
1186
- ...(N = q.value) != null && N.rendererEvents.supportsBounds ? { "bounds-change": ui } : {}
1187
- };
1188
- }), q = k(() => {
1189
- var oe, ce;
1190
- const b = I[i.definition.chart.type], T = !!((oe = b == null ? void 0 : b.emits) != null && oe.includes("select-chart-range")), N = !!((ce = b == null ? void 0 : b.emits) != null && ce.includes("zoom-time-range")), X = i.definition.chart.type === "choropleth_map";
1191
- return b && {
1192
- component: b,
1193
- rendererProps: {
1194
- query: i.definition.query,
1195
- context: i.context,
1196
- queryReady: i.queryReady,
1197
- chartOptions: i.definition.chart,
1198
- height: i.height - t * 2,
1199
- refreshCounter: s.value,
1200
- requestsLink: F.value,
1201
- exploreLink: S.value
1202
- },
1203
- rendererEvents: {
1204
- supportsRequests: T,
1205
- supportsZoom: N,
1206
- supportsBounds: X
1207
- }
1208
- };
1209
- }), j = k(() => {
1210
- var T;
1211
- const b = (T = i.definition.query) == null ? void 0 : T.time_range;
1212
- if ((b == null ? void 0 : b.type) === "relative") {
1213
- const N = wi.get(Ei[b.time_range]);
1214
- return N ? N.display : (console.warn("Did not recognize the given relative time range:", b.time_range), b.time_range);
1215
- } else if ((b == null ? void 0 : b.type) === "absolute") {
1216
- const N = b.tz || "Etc/UTC";
1217
- return `${wt(b.start, { short: !0, tz: N })} - ${wt(b.end, { short: !0, tz: N })}`;
1218
- }
1219
- return null;
1220
- }), ke = k(() => {
1221
- if (i.definition.chart.type === "slottable")
1222
- return !1;
1223
- const b = !!i.definition.chart.chart_title, T = i.definition.chart.type === "golden_signals" && !!i.definition.chart.description, N = i.showRefresh, X = $e.value && R.value && !i.isFullscreen, oe = !!j.value;
1224
- return b || X || oe || T || N;
1225
- }), yt = k(() => h.value ? ot(h.value.meta.granularity_ms) : void 0), ei = k(() => ["timeseries_line", "timeseries_bar"].includes(i.definition.chart.type)), vt = k(() => {
1226
- var T, N;
1227
- if (!ei.value || !i.queryReady || y.value)
1228
- return !1;
1229
- const b = (N = (T = i.definition) == null ? void 0 : T.query) == null ? void 0 : N.granularity;
1230
- return !b || !yt.value ? !1 : b !== yt.value;
1231
- }), ti = k(() => {
1232
- var N, X, oe;
1233
- const b = ot(((N = h.value) == null ? void 0 : N.meta.granularity_ms) ?? 0) ?? "unknown", T = ((oe = (X = i.definition) == null ? void 0 : X.query) == null ? void 0 : oe.granularity) ?? "unknown";
1234
- return u.t("query_aged_out_warning", {
1235
- currentGranularity: u.t(`granularities.${b}`),
1236
- savedGranularity: u.t(`granularities.${T}`)
1237
- });
1238
- }), ii = k(() => {
1239
- var N, X;
1240
- const b = [...i.context.filters, ...i.definition.query.filters ?? []], T = ((X = (N = i.definition) == null ? void 0 : N.query) == null ? void 0 : X.datasource) ?? "api_usage";
1241
- return b.filter((oe) => Bt(oe.field).some((it) => T === it));
1242
- }), si = () => {
1243
- o("edit-tile", i.definition);
1244
- }, ri = () => {
1245
- o("duplicate-tile", i.definition);
1246
- }, ni = () => {
1247
- o("remove-tile", i.definition);
1248
- }, oi = (b) => {
1249
- h.value = b, y.value = !1;
1250
- }, ai = () => {
1251
- f.value = !1;
1252
- }, li = async () => {
1253
- var b;
1254
- if (f.value = !0, l.value = { status: "loading" }, ((b = d == null ? void 0 : d.staticConfig) == null ? void 0 : b.increaseCsvExportLimit) ?? !0)
1255
- Re(i.definition.query, i.context, xi).then((T) => {
1256
- l.value = { status: "success", chartData: T };
1257
- }).catch((T) => {
1258
- l.value = { status: "error", error: T };
1259
- });
1260
- else if (h.value)
1261
- l.value = { status: "success", chartData: h.value };
1262
- else {
1263
- const T = Se(h, (N) => {
1264
- N && (l.value = { status: "success", chartData: N }, T());
1265
- });
1266
- }
1267
- }, hi = (b) => {
1268
- const T = {
1269
- tileId: i.tileId.toString(),
1270
- timeRange: b
1271
- };
1272
- o("tile-time-range-zoom", T);
1273
- }, ui = (b) => {
1274
- const T = {
1275
- tileId: i.tileId.toString(),
1276
- bounds: b
1277
- };
1278
- o("tile-bounds-change", T);
1279
- }, di = (b) => {
1280
- const T = ii.value, N = ne(b, T), X = H(b, T);
1281
- F.value = D.value ? { href: de(N) } : void 0, S.value = J.value ? { href: Y(X) } : void 0;
1282
- };
1283
- return (b, T) => {
1284
- const N = ge("KTooltip"), X = ge("KBadge"), oe = ge("KButton"), ce = ge("KDropdownItem"), it = ge("KDropdown");
1285
- return x(), G("div", {
1286
- class: De(["tile-boundary", {
1287
- editable: a.context.editable,
1288
- headless: !ke.value
1289
- }]),
1290
- "data-testid": `tile-${a.tileId}`
1291
- }, [
1292
- ke.value && a.definition.chart.type !== "slottable" ? (x(), G("div", Ts, [
1293
- re(N, {
1294
- class: "title-tooltip",
1295
- disabled: !p.value,
1296
- "max-width": "500",
1297
- text: a.definition.chart.chart_title
1298
- }, {
1299
- default: P(() => [
1300
- se("div", {
1301
- ref_key: "titleRef",
1302
- ref: g,
1303
- class: "title"
1304
- }, ae(a.definition.chart.chart_title), 513)
1305
- ]),
1306
- _: 1
1307
- }, 8, ["disabled", "text"]),
1308
- se("div", Ss, [
1309
- j.value ? (x(), O(X, {
1310
- key: 0,
1311
- "data-testid": "time-range-badge",
1312
- tooltip: vt.value ? ti.value : void 0,
1313
- "tooltip-attributes": { maxWidth: "320px" }
1314
- }, Je({
1315
- default: P(() => [
1316
- se("span", zs, ae(j.value), 1)
1317
- ]),
1318
- _: 2
1319
- }, [
1320
- vt.value ? {
1321
- name: "icon",
1322
- fn: P(() => [
1323
- re(E(Oi), { size: E(Cs) }, null, 8, ["size"])
1324
- ]),
1325
- key: "0"
1326
- } : void 0
1327
- ]), 1032, ["tooltip"])) : K("", !0)
1328
- ]),
1329
- a.showRefresh ? (x(), G("div", Ds, [
1330
- re(oe, {
1331
- appearance: "secondary",
1332
- class: "refresh-button",
1333
- disabled: y.value,
1334
- icon: "",
1335
- size: "small",
1336
- onClick: r
1337
- }, {
1338
- default: P(() => [
1339
- y.value ? (x(), O(E(Hi), {
1340
- key: 0,
1341
- role: "button",
1342
- size: E(Nt),
1343
- tabindex: "0"
1344
- }, null, 8, ["size"])) : (x(), O(E(Ii), {
1345
- key: 1,
1346
- role: "button",
1347
- size: E(Nt),
1348
- tabindex: "0"
1349
- }, null, 8, ["size"]))
1350
- ]),
1351
- _: 1
1352
- }, 8, ["disabled"])
1353
- ])) : K("", !0),
1354
- $e.value ? (x(), G("div", {
1355
- key: 1,
1356
- class: "tile-actions",
1357
- "data-testid": `tile-actions-${a.tileId}`
1358
- }, [
1359
- E(A) && a.context.editable && !a.isFullscreen ? (x(), O(E(Mi), {
1360
- key: 0,
1361
- class: "edit-icon",
1362
- color: E(zt),
1363
- "data-testid": `edit-tile-${a.tileId}`,
1364
- size: E(Dt),
1365
- onClick: si
1366
- }, null, 8, ["color", "data-testid", "size"])) : K("", !0),
1367
- E(A) && R.value && !a.isFullscreen ? (x(), O(it, {
1368
- key: 1,
1369
- class: "dropdown",
1370
- "data-testid": `chart-action-menu-${a.tileId}`,
1371
- "kpop-attributes": { placement: "bottom-end" }
1372
- }, {
1373
- items: P(() => [
1374
- E(m) ? (x(), O(ce, {
1375
- key: 0,
1376
- "data-testid": `chart-jump-to-explore-${a.tileId}`,
1377
- item: { label: E(u).t("jumpToExplore"), to: E(m) }
1378
- }, null, 8, ["data-testid", "item"])) : K("", !0),
1379
- E(C) ? (x(), O(ce, {
1380
- key: 1,
1381
- "data-testid": `chart-jump-to-requests-${a.tileId}`,
1382
- item: { label: E(u).t("jumpToRequests"), to: E(C) }
1383
- }, null, 8, ["data-testid", "item"])) : K("", !0),
1384
- !("allow_csv_export" in a.definition.chart) || a.definition.chart.allow_csv_export ? (x(), O(ce, {
1385
- key: 2,
1386
- class: "chart-export-button",
1387
- "data-testid": `chart-csv-export-${a.tileId}`,
1388
- onClick: li
1389
- }, {
1390
- default: P(() => [
1391
- se("span", {
1392
- class: "chart-export-trigger",
1393
- "data-testid": `csv-export-button-${a.tileId}`
1394
- }, ae(E(u).t("csvExport.exportAsCsv")), 9, Ls)
1395
- ]),
1396
- _: 1
1397
- }, 8, ["data-testid"])) : K("", !0),
1398
- a.context.editable ? (x(), O(ce, {
1399
- key: 3,
1400
- "data-testid": `duplicate-tile-${a.tileId}`,
1401
- onClick: ri
1402
- }, {
1403
- default: P(() => [
1404
- ht(ae(E(u).t("renderer.duplicateTile")), 1)
1405
- ]),
1406
- _: 1
1407
- }, 8, ["data-testid"])) : K("", !0),
1408
- a.context.editable ? (x(), O(ce, {
1409
- key: 4,
1410
- "data-testid": `remove-tile-${a.tileId}`,
1411
- onClick: ni
1412
- }, {
1413
- default: P(() => [
1414
- se("span", As, ae(E(u).t("renderer.delete")), 1)
1415
- ]),
1416
- _: 1
1417
- }, 8, ["data-testid"])) : K("", !0)
1418
- ]),
1419
- default: P(() => [
1420
- re(E(qi), {
1421
- class: "kebab-action-menu",
1422
- color: E(zt),
1423
- "data-testid": `kebab-action-menu-${a.tileId}`,
1424
- size: E(Dt)
1425
- }, null, 8, ["color", "data-testid", "size"])
1426
- ]),
1427
- _: 1
1428
- }, 8, ["data-testid"])) : K("", !0)
1429
- ], 8, Ns)) : "description" in a.definition.chart ? (x(), G("div", {
1430
- key: 2,
1431
- class: "header-description",
1432
- "data-testid": `tile-description-${a.tileId}`
1433
- }, ae(a.definition.chart.description), 9, Os)) : K("", !0),
1434
- f.value ? (x(), O(E(Si), {
1435
- key: 3,
1436
- "data-testid": `csv-export-modal-${a.tileId}`,
1437
- "export-state": l.value,
1438
- filename: tt.value,
1439
- onCloseModal: ai
1440
- }, null, 8, ["data-testid", "export-state", "filename"])) : K("", !0)
1441
- ])) : K("", !0),
1442
- se("div", {
1443
- class: De(["tile-content", `type-${a.definition.chart.type}`]),
1444
- "data-testid": `tile-content-${a.tileId}`
1445
- }, [
1446
- q.value ? (x(), O(qt(q.value.component), Ht({ key: 0 }, q.value.rendererProps, vi($.value), { onChartData: oi }), null, 16)) : K("", !0)
1447
- ], 10, Hs)
1448
- ], 10, ks);
1449
- };
1450
- }
1451
- }), Zt = /* @__PURE__ */ _e(Is, [["__scopeId", "data-v-139d64e3"]]), Ms = (a, e) => {
1452
- let t = 0;
1453
- const i = /* @__PURE__ */ new Map();
1454
- e.forEach((r) => {
1455
- const o = r.layout.position.row, n = i.get(o), d = r.layout.size.rows === 1 && !!r.layout.size.fit_to_content;
1456
- t = Math.max(t, o + r.layout.size.rows), n === void 0 ? i.set(o, d) : i.set(o, n && d);
1457
- });
1458
- const s = [];
1459
- for (let r = 0; r < t; r++)
1460
- i.get(r) ? s.push("auto") : s.push(`${a}px`);
1461
- return s;
1462
- }, qs = /* @__PURE__ */ V({
1463
- __name: "GridLayout",
1464
- props: {
1465
- tileHeight: {
1466
- type: Number,
1467
- required: !1,
1468
- default: () => Pe
1469
- },
1470
- tiles: {
1471
- type: Array,
1472
- required: !0
1473
- }
1474
- },
1475
- setup(a) {
1476
- ut((n) => ({
1477
- v2a38e79e: E(ct),
1478
- v4cc71de6: r.value
1479
- }));
1480
- const e = a, t = L(null), i = L(0), s = new ResizeObserver((n) => {
1481
- window.requestAnimationFrame(() => {
1482
- !Array.isArray(n) || !n.length || (i.value = n[0].contentRect.width);
1483
- });
1484
- });
1485
- Xe(() => {
1486
- t.value && s.observe(t.value);
1487
- }), Ze(() => {
1488
- t.value && s.unobserve(t.value);
1489
- });
1490
- const r = k(() => Ms(e.tileHeight, e.tiles).join(" ")), o = k(() => e.tiles.map((n, d) => ({
1491
- key: `tile-${d}`,
1492
- tile: n,
1493
- style: {
1494
- "grid-column-start": n.layout.position.col + 1,
1495
- "grid-column-end": n.layout.position.col + 1 + n.layout.size.cols,
1496
- "grid-row-start": n.layout.position.row + 1,
1497
- "grid-row-end": n.layout.position.row + 1 + n.layout.size.rows
1498
- }
1499
- })));
1500
- return (n, d) => (x(), G("div", {
1501
- ref_key: "gridContainer",
1502
- ref: t,
1503
- class: "kong-ui-public-grid-layout"
1504
- }, [
1505
- (x(!0), G(Pt, null, $t(o.value, (u) => (x(), G("div", {
1506
- key: u.key,
1507
- class: De(["grid-cell", {
1508
- "empty-cell": !u.tile
1509
- }]),
1510
- style: nt(u.style)
1511
- }, [
1512
- ze(n.$slots, "tile", {
1513
- style: nt(u.style),
1514
- tile: u.tile
1515
- }, void 0, !0)
1516
- ], 6))), 128))
1517
- ], 512));
1518
- }
1519
- }), Ps = /* @__PURE__ */ _e(qs, [["__scopeId", "data-v-354b7177"]]);
1520
- function $s(a, e, t, i, s) {
1521
- const r = (...o) => (console.warn("gridstack.js: Function `" + t + "` is deprecated in " + s + " and has been replaced with `" + i + "`. It will be **removed** in a future release"), e.apply(a, o));
1522
- return r.prototype = e.prototype, r;
1523
- }
1524
- class c {
1525
- /** convert a potential selector into actual list of html elements. optional root which defaults to document (for shadow dom) */
1526
- static getElements(e, t = document) {
1527
- if (typeof e == "string") {
1528
- const i = "getElementById" in t ? t : void 0;
1529
- if (i && !isNaN(+e[0])) {
1530
- const r = i.getElementById(e);
1531
- return r ? [r] : [];
1532
- }
1533
- let s = t.querySelectorAll(e);
1534
- return !s.length && e[0] !== "." && e[0] !== "#" && (s = t.querySelectorAll("." + e), s.length || (s = t.querySelectorAll("#" + e))), Array.from(s);
1535
- }
1536
- return [e];
1537
- }
1538
- /** convert a potential selector into actual single element. optional root which defaults to document (for shadow dom) */
1539
- static getElement(e, t = document) {
1540
- if (typeof e == "string") {
1541
- const i = "getElementById" in t ? t : void 0;
1542
- if (!e.length)
1543
- return null;
1544
- if (i && e[0] === "#")
1545
- return i.getElementById(e.substring(1));
1546
- if (e[0] === "#" || e[0] === "." || e[0] === "[")
1547
- return t.querySelector(e);
1548
- if (i && !isNaN(+e[0]))
1549
- return i.getElementById(e);
1550
- let s = t.querySelector(e);
1551
- return i && !s && (s = i.getElementById(e)), s || (s = t.querySelector("." + e)), s;
1552
- }
1553
- return e;
1554
- }
1555
- /** true if widget (or grid) makes this item lazyLoad */
1556
- static lazyLoad(e) {
1557
- var t, i;
1558
- return e.lazyLoad || ((i = (t = e.grid) == null ? void 0 : t.opts) == null ? void 0 : i.lazyLoad) && e.lazyLoad !== !1;
1559
- }
1560
- /** create a div with the given classes */
1561
- static createDiv(e, t) {
1562
- const i = document.createElement("div");
1563
- return e.forEach((s) => {
1564
- s && i.classList.add(s);
1565
- }), t == null || t.appendChild(i), i;
1566
- }
1567
- /** true if we should resize to content. strict=true when only 'sizeToContent:true' and not a number which lets user adjust */
1568
- static shouldSizeToContent(e, t = !1) {
1569
- return (e == null ? void 0 : e.grid) && (t ? e.sizeToContent === !0 || e.grid.opts.sizeToContent === !0 && e.sizeToContent === void 0 : !!e.sizeToContent || e.grid.opts.sizeToContent && e.sizeToContent !== !1);
1570
- }
1571
- /** returns true if a and b overlap */
1572
- static isIntercepted(e, t) {
1573
- return !(e.y >= t.y + t.h || e.y + e.h <= t.y || e.x + e.w <= t.x || e.x >= t.x + t.w);
1574
- }
1575
- /** returns true if a and b touch edges or corners */
1576
- static isTouching(e, t) {
1577
- return c.isIntercepted(e, { x: t.x - 0.5, y: t.y - 0.5, w: t.w + 1, h: t.h + 1 });
1578
- }
1579
- /** returns the area a and b overlap */
1580
- static areaIntercept(e, t) {
1581
- const i = e.x > t.x ? e.x : t.x, s = e.x + e.w < t.x + t.w ? e.x + e.w : t.x + t.w;
1582
- if (s <= i)
1583
- return 0;
1584
- const r = e.y > t.y ? e.y : t.y, o = e.y + e.h < t.y + t.h ? e.y + e.h : t.y + t.h;
1585
- return o <= r ? 0 : (s - i) * (o - r);
1586
- }
1587
- /** returns the area */
1588
- static area(e) {
1589
- return e.w * e.h;
1590
- }
1591
- /**
1592
- * Sorts array of nodes
1593
- * @param nodes array to sort
1594
- * @param dir 1 for ascending, -1 for descending (optional)
1595
- **/
1596
- static sort(e, t = 1) {
1597
- return e.sort((s, r) => {
1598
- const o = t * ((s.y ?? 1e4) - (r.y ?? 1e4));
1599
- return o === 0 ? t * ((s.x ?? 1e4) - (r.x ?? 1e4)) : o;
1600
- });
1601
- }
1602
- /** find an item by id */
1603
- static find(e, t) {
1604
- return t ? e.find((i) => i.id === t) : void 0;
1605
- }
1606
- /**
1607
- * creates a style sheet with style id under given parent
1608
- * @param id will set the 'gs-style-id' attribute to that id
1609
- * @param parent to insert the stylesheet as first child,
1610
- * if none supplied it will be appended to the document head instead.
1611
- */
1612
- static createStylesheet(e, t, i) {
1613
- const s = document.createElement("style"), r = i == null ? void 0 : i.nonce;
1614
- return r && (s.nonce = r), s.setAttribute("type", "text/css"), s.setAttribute("gs-style-id", e), s.styleSheet ? s.styleSheet.cssText = "" : s.appendChild(document.createTextNode("")), t ? t.insertBefore(s, t.firstChild) : (t = document.getElementsByTagName("head")[0], t.appendChild(s)), s;
1615
- }
1616
- /** removed the given stylesheet id */
1617
- static removeStylesheet(e, t) {
1618
- const s = (t || document).querySelector("STYLE[gs-style-id=" + e + "]");
1619
- s && s.parentNode && s.remove();
1620
- }
1621
- /** inserts a CSS rule */
1622
- static addCSSRule(e, t, i) {
1623
- e.textContent += `${t} { ${i} } `;
1624
- }
1625
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1626
- static toBool(e) {
1627
- return typeof e == "boolean" ? e : typeof e == "string" ? (e = e.toLowerCase(), !(e === "" || e === "no" || e === "false" || e === "0")) : !!e;
1628
- }
1629
- static toNumber(e) {
1630
- return e === null || e.length === 0 ? void 0 : Number(e);
1631
- }
1632
- static parseHeight(e) {
1633
- let t, i = "px";
1634
- if (typeof e == "string")
1635
- if (e === "auto" || e === "")
1636
- t = 0;
1637
- else {
1638
- const s = e.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw|%|cm|mm)?$/);
1639
- if (!s)
1640
- throw new Error(`Invalid height val = ${e}`);
1641
- i = s[2] || "px", t = parseFloat(s[1]);
1642
- }
1643
- else
1644
- t = e;
1645
- return { h: t, unit: i };
1646
- }
1647
- /** copies unset fields in target to use the given default sources values */
1648
- // eslint-disable-next-line
1649
- static defaults(e, ...t) {
1650
- return t.forEach((i) => {
1651
- for (const s in i) {
1652
- if (!i.hasOwnProperty(s))
1653
- return;
1654
- e[s] === null || e[s] === void 0 ? e[s] = i[s] : typeof i[s] == "object" && typeof e[s] == "object" && this.defaults(e[s], i[s]);
1655
- }
1656
- }), e;
1657
- }
1658
- /** given 2 objects return true if they have the same values. Checks for Object {} having same fields and values (just 1 level down) */
1659
- static same(e, t) {
1660
- if (typeof e != "object")
1661
- return e == t;
1662
- if (typeof e != typeof t || Object.keys(e).length !== Object.keys(t).length)
1663
- return !1;
1664
- for (const i in e)
1665
- if (e[i] !== t[i])
1666
- return !1;
1667
- return !0;
1668
- }
1669
- /** copies over b size & position (GridStackPosition), and optionally min/max as well */
1670
- static copyPos(e, t, i = !1) {
1671
- return t.x !== void 0 && (e.x = t.x), t.y !== void 0 && (e.y = t.y), t.w !== void 0 && (e.w = t.w), t.h !== void 0 && (e.h = t.h), i && (t.minW && (e.minW = t.minW), t.minH && (e.minH = t.minH), t.maxW && (e.maxW = t.maxW), t.maxH && (e.maxH = t.maxH)), e;
1672
- }
1673
- /** true if a and b has same size & position */
1674
- static samePos(e, t) {
1675
- return e && t && e.x === t.x && e.y === t.y && (e.w || 1) === (t.w || 1) && (e.h || 1) === (t.h || 1);
1676
- }
1677
- /** given a node, makes sure it's min/max are valid */
1678
- static sanitizeMinMax(e) {
1679
- e.minW || delete e.minW, e.minH || delete e.minH, e.maxW || delete e.maxW, e.maxH || delete e.maxH;
1680
- }
1681
- /** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */
1682
- static removeInternalAndSame(e, t) {
1683
- if (!(typeof e != "object" || typeof t != "object"))
1684
- for (let i in e) {
1685
- const s = e[i], r = t[i];
1686
- i[0] === "_" || s === r ? delete e[i] : s && typeof s == "object" && r !== void 0 && (c.removeInternalAndSame(s, r), Object.keys(s).length || delete e[i]);
1687
- }
1688
- }
1689
- /** removes internal fields '_' and default values for saving */
1690
- static removeInternalForSave(e, t = !0) {
1691
- for (let i in e)
1692
- (i[0] === "_" || e[i] === null || e[i] === void 0) && delete e[i];
1693
- delete e.grid, t && delete e.el, e.autoPosition || delete e.autoPosition, e.noResize || delete e.noResize, e.noMove || delete e.noMove, e.locked || delete e.locked, (e.w === 1 || e.w === e.minW) && delete e.w, (e.h === 1 || e.h === e.minH) && delete e.h;
1694
- }
1695
- /** return the closest parent (or itself) matching the given class */
1696
- // static closestUpByClass(el: HTMLElement, name: string): HTMLElement {
1697
- // while (el) {
1698
- // if (el.classList.contains(name)) return el;
1699
- // el = el.parentElement
1700
- // }
1701
- // return null;
1702
- // }
1703
- /** delay calling the given function for given delay, preventing new calls from happening while waiting */
1704
- static throttle(e, t) {
1705
- let i = !1;
1706
- return (...s) => {
1707
- i || (i = !0, setTimeout(() => {
1708
- e(...s), i = !1;
1709
- }, t));
1710
- };
1711
- }
1712
- static removePositioningStyles(e) {
1713
- const t = e.style;
1714
- t.position && t.removeProperty("position"), t.left && t.removeProperty("left"), t.top && t.removeProperty("top"), t.width && t.removeProperty("width"), t.height && t.removeProperty("height");
1715
- }
1716
- /** @internal returns the passed element if scrollable, else the closest parent that will, up to the entire document scrolling element */
1717
- static getScrollElement(e) {
1718
- if (!e)
1719
- return document.scrollingElement || document.documentElement;
1720
- const t = getComputedStyle(e);
1721
- return /(auto|scroll)/.test(t.overflow + t.overflowY) ? e : this.getScrollElement(e.parentElement);
1722
- }
1723
- /** @internal */
1724
- static updateScrollPosition(e, t, i) {
1725
- const s = e.getBoundingClientRect(), r = window.innerHeight || document.documentElement.clientHeight;
1726
- if (s.top < 0 || s.bottom > r) {
1727
- const o = s.bottom - r, n = s.top, d = this.getScrollElement(e);
1728
- if (d !== null) {
1729
- const u = d.scrollTop;
1730
- s.top < 0 && i < 0 ? e.offsetHeight > r ? d.scrollTop += i : d.scrollTop += Math.abs(n) > Math.abs(i) ? i : n : i > 0 && (e.offsetHeight > r ? d.scrollTop += i : d.scrollTop += o > i ? i : o), t.top += d.scrollTop - u;
1731
- }
1732
- }
1733
- }
1734
- /**
1735
- * @internal Function used to scroll the page.
1736
- *
1737
- * @param event `MouseEvent` that triggers the resize
1738
- * @param el `HTMLElement` that's being resized
1739
- * @param distance Distance from the V edges to start scrolling
1740
- */
1741
- static updateScrollResize(e, t, i) {
1742
- const s = this.getScrollElement(t), r = s.clientHeight, o = s === this.getScrollElement() ? 0 : s.getBoundingClientRect().top, n = e.clientY - o, d = n < i, u = n > r - i;
1743
- d ? s.scrollBy({ behavior: "smooth", top: n - i }) : u && s.scrollBy({ behavior: "smooth", top: i - (r - n) });
1744
- }
1745
- /** single level clone, returning a new object with same top fields. This will share sub objects and arrays */
1746
- static clone(e) {
1747
- return e == null || typeof e != "object" ? e : e instanceof Array ? [...e] : { ...e };
1748
- }
1749
- /**
1750
- * Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY.
1751
- * Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
1752
- */
1753
- static cloneDeep(e) {
1754
- const t = ["parentGrid", "el", "grid", "subGrid", "engine"], i = c.clone(e);
1755
- for (const s in i)
1756
- i.hasOwnProperty(s) && typeof i[s] == "object" && s.substring(0, 2) !== "__" && !t.find((r) => r === s) && (i[s] = c.cloneDeep(e[s]));
1757
- return i;
1758
- }
1759
- /** deep clone the given HTML node, removing teh unique id field */
1760
- static cloneNode(e) {
1761
- const t = e.cloneNode(!0);
1762
- return t.removeAttribute("id"), t;
1763
- }
1764
- static appendTo(e, t) {
1765
- let i;
1766
- typeof t == "string" ? i = c.getElement(t) : i = t, i && i.appendChild(e);
1767
- }
1768
- // public static setPositionRelative(el: HTMLElement): void {
1769
- // if (!(/^(?:r|a|f)/).test(getComputedStyle(el).position)) {
1770
- // el.style.position = "relative";
1771
- // }
1772
- // }
1773
- static addElStyles(e, t) {
1774
- if (t instanceof Object)
1775
- for (const i in t)
1776
- t.hasOwnProperty(i) && (Array.isArray(t[i]) ? t[i].forEach((s) => {
1777
- e.style[i] = s;
1778
- }) : e.style[i] = t[i]);
1779
- }
1780
- static initEvent(e, t) {
1781
- const i = { type: t.type }, s = {
1782
- button: 0,
1783
- which: 0,
1784
- buttons: 1,
1785
- bubbles: !0,
1786
- cancelable: !0,
1787
- target: t.target ? t.target : e.target
1788
- };
1789
- return ["altKey", "ctrlKey", "metaKey", "shiftKey"].forEach((r) => i[r] = e[r]), ["pageX", "pageY", "clientX", "clientY", "screenX", "screenY"].forEach((r) => i[r] = e[r]), { ...i, ...s };
1790
- }
1791
- /** copies the MouseEvent (or convert Touch) properties and sends it as another event to the given target */
1792
- static simulateMouseEvent(e, t, i) {
1793
- const s = e, r = new MouseEvent(t, {
1794
- bubbles: !0,
1795
- composed: !0,
1796
- cancelable: !0,
1797
- view: window,
1798
- detail: 1,
1799
- screenX: e.screenX,
1800
- screenY: e.screenY,
1801
- clientX: e.clientX,
1802
- clientY: e.clientY,
1803
- ctrlKey: s.ctrlKey ?? !1,
1804
- altKey: s.altKey ?? !1,
1805
- shiftKey: s.shiftKey ?? !1,
1806
- metaKey: s.metaKey ?? !1,
1807
- button: 0,
1808
- relatedTarget: e.target
1809
- });
1810
- (i || e.target).dispatchEvent(r);
1811
- }
1812
- /**
1813
- * defines an element that is used to get the offset and scale from grid transforms
1814
- * returns the scale and offsets from said element
1815
- */
1816
- static getValuesFromTransformedElement(e) {
1817
- const t = document.createElement("div");
1818
- c.addElStyles(t, {
1819
- opacity: "0",
1820
- position: "fixed",
1821
- top: "0px",
1822
- left: "0px",
1823
- width: "1px",
1824
- height: "1px",
1825
- zIndex: "-999999"
1826
- }), e.appendChild(t);
1827
- const i = t.getBoundingClientRect();
1828
- return e.removeChild(t), t.remove(), {
1829
- xScale: 1 / i.width,
1830
- yScale: 1 / i.height,
1831
- xOffset: i.left,
1832
- yOffset: i.top
1833
- };
1834
- }
1835
- /** swap the given object 2 field values */
1836
- static swap(e, t, i) {
1837
- if (!e)
1838
- return;
1839
- const s = e[t];
1840
- e[t] = e[i], e[i] = s;
1841
- }
1842
- /** returns true if event is inside the given element rectangle */
1843
- // Note: Safari Mac has null event.relatedTarget which causes #1684 so check if DragEvent is inside the coordinates instead
1844
- // this.el.contains(event.relatedTarget as HTMLElement)
1845
- // public static inside(e: MouseEvent, el: HTMLElement): boolean {
1846
- // // srcElement, toElement, target: all set to placeholder when leaving simple grid, so we can't use that (Chrome)
1847
- // const target: HTMLElement = e.relatedTarget || (e as any).fromElement;
1848
- // if (!target) {
1849
- // const { bottom, left, right, top } = el.getBoundingClientRect();
1850
- // return (e.x < right && e.x > left && e.y < bottom && e.y > top);
1851
- // }
1852
- // return el.contains(target);
1853
- // }
1854
- /** true if the item can be rotated (checking for prop, not space available) */
1855
- static canBeRotated(e) {
1856
- var t;
1857
- return !(!e || e.w === e.h || e.locked || e.noResize || (t = e.grid) != null && t.opts.disableResize || e.minW && e.minW === e.maxW || e.minH && e.minH === e.maxH);
1858
- }
1859
- }
1860
- class he {
1861
- constructor(e = {}) {
1862
- this.addedNodes = [], this.removedNodes = [], this.defaultColumn = 12, this.column = e.column || this.defaultColumn, this.column > this.defaultColumn && (this.defaultColumn = this.column), this.maxRow = e.maxRow, this._float = e.float, this.nodes = e.nodes || [], this.onChange = e.onChange;
1863
- }
1864
- batchUpdate(e = !0, t = !0) {
1865
- return !!this.batchMode === e ? this : (this.batchMode = e, e ? (this._prevFloat = this._float, this._float = !0, this.cleanNodes(), this.saveInitial()) : (this._float = this._prevFloat, delete this._prevFloat, t && this._packNodes(), this._notify()), this);
1866
- }
1867
- // use entire row for hitting area (will use bottom reverse sorted first) if we not actively moving DOWN and didn't already skip
1868
- _useEntireRowArea(e, t) {
1869
- return (!this.float || this.batchMode && !this._prevFloat) && !this._hasLocked && (!e._moving || e._skipDown || t.y <= e.y);
1870
- }
1871
- /** @internal fix collision on given 'node', going to given new location 'nn', with optional 'collide' node already found.
1872
- * return true if we moved. */
1873
- _fixCollisions(e, t = e, i, s = {}) {
1874
- if (this.sortNodes(-1), i = i || this.collide(e, t), !i)
1875
- return !1;
1876
- if (e._moving && !s.nested && !this.float && this.swap(e, i))
1877
- return !0;
1878
- let r = t;
1879
- !this._loading && this._useEntireRowArea(e, t) && (r = { x: 0, w: this.column, y: t.y, h: t.h }, i = this.collide(e, r, s.skip));
1880
- let o = !1;
1881
- const n = { nested: !0, pack: !1 };
1882
- let d = 0;
1883
- for (; i = i || this.collide(e, r, s.skip); ) {
1884
- if (d++ > this.nodes.length * 2)
1885
- throw new Error("Infinite collide check");
1886
- let u;
1887
- if (i.locked || this._loading || e._moving && !e._skipDown && t.y > e.y && !this.float && // can take space we had, or before where we're going
1888
- (!this.collide(i, { ...i, y: e.y }, e) || !this.collide(i, { ...i, y: t.y - i.h }, e))) {
1889
- e._skipDown = e._skipDown || t.y > e.y;
1890
- const h = { ...t, y: i.y + i.h, ...n };
1891
- u = this._loading && c.samePos(e, h) ? !0 : this.moveNode(e, h), (i.locked || this._loading) && u ? c.copyPos(t, e) : !i.locked && u && s.pack && (this._packNodes(), t.y = i.y + i.h, c.copyPos(e, t)), o = o || u;
1892
- } else
1893
- u = this.moveNode(i, { ...i, y: t.y + t.h, skip: e, ...n });
1894
- if (!u)
1895
- return o;
1896
- i = void 0;
1897
- }
1898
- return o;
1899
- }
1900
- /** return the nodes that intercept the given node. Optionally a different area can be used, as well as a second node to skip */
1901
- collide(e, t = e, i) {
1902
- const s = e._id, r = i == null ? void 0 : i._id;
1903
- return this.nodes.find((o) => o._id !== s && o._id !== r && c.isIntercepted(o, t));
1904
- }
1905
- collideAll(e, t = e, i) {
1906
- const s = e._id, r = i == null ? void 0 : i._id;
1907
- return this.nodes.filter((o) => o._id !== s && o._id !== r && c.isIntercepted(o, t));
1908
- }
1909
- /** does a pixel coverage collision based on where we started, returning the node that has the most coverage that is >50% mid line */
1910
- directionCollideCoverage(e, t, i) {
1911
- if (!t.rect || !e._rect)
1912
- return;
1913
- const s = e._rect, r = { ...t.rect };
1914
- r.y > s.y ? (r.h += r.y - s.y, r.y = s.y) : r.h += s.y - r.y, r.x > s.x ? (r.w += r.x - s.x, r.x = s.x) : r.w += s.x - r.x;
1915
- let o, n = 0.5;
1916
- for (let d of i) {
1917
- if (d.locked || !d._rect)
1918
- break;
1919
- const u = d._rect;
1920
- let h = Number.MAX_VALUE, l = Number.MAX_VALUE;
1921
- s.y < u.y ? h = (r.y + r.h - u.y) / u.h : s.y + s.h > u.y + u.h && (h = (u.y + u.h - r.y) / u.h), s.x < u.x ? l = (r.x + r.w - u.x) / u.w : s.x + s.w > u.x + u.w && (l = (u.x + u.w - r.x) / u.w);
1922
- const f = Math.min(l, h);
1923
- f > n && (n = f, o = d);
1924
- }
1925
- return t.collide = o, o;
1926
- }
1927
- /** does a pixel coverage returning the node that has the most coverage by area */
1928
- /*
1929
- protected collideCoverage(r: GridStackPosition, collides: GridStackNode[]): {collide: GridStackNode, over: number} {
1930
- const collide: GridStackNode;
1931
- const overMax = 0;
1932
- collides.forEach(n => {
1933
- if (n.locked || !n._rect) return;
1934
- const over = Utils.areaIntercept(r, n._rect);
1935
- if (over > overMax) {
1936
- overMax = over;
1937
- collide = n;
1938
- }
1939
- });
1940
- return {collide, over: overMax};
1941
- }
1942
- */
1943
- /** called to cache the nodes pixel rectangles used for collision detection during drag */
1944
- cacheRects(e, t, i, s, r, o) {
1945
- return this.nodes.forEach((n) => n._rect = {
1946
- y: n.y * t + i,
1947
- x: n.x * e + o,
1948
- w: n.w * e - o - s,
1949
- h: n.h * t - i - r
1950
- }), this;
1951
- }
1952
- /** called to possibly swap between 2 nodes (same size or column, not locked, touching), returning true if successful */
1953
- swap(e, t) {
1954
- if (!t || t.locked || !e || e.locked)
1955
- return !1;
1956
- function i() {
1957
- const r = t.x, o = t.y;
1958
- return t.x = e.x, t.y = e.y, e.h != t.h ? (e.x = r, e.y = t.y + t.h) : e.w != t.w ? (e.x = t.x + t.w, e.y = o) : (e.x = r, e.y = o), e._dirty = t._dirty = !0, !0;
1959
- }
1960
- let s;
1961
- if (e.w === t.w && e.h === t.h && (e.x === t.x || e.y === t.y) && (s = c.isTouching(e, t)))
1962
- return i();
1963
- if (s !== !1) {
1964
- if (e.w === t.w && e.x === t.x && (s || (s = c.isTouching(e, t)))) {
1965
- if (t.y < e.y) {
1966
- const r = e;
1967
- e = t, t = r;
1968
- }
1969
- return i();
1970
- }
1971
- if (s !== !1) {
1972
- if (e.h === t.h && e.y === t.y && (s || (s = c.isTouching(e, t)))) {
1973
- if (t.x < e.x) {
1974
- const r = e;
1975
- e = t, t = r;
1976
- }
1977
- return i();
1978
- }
1979
- return !1;
1980
- }
1981
- }
1982
- }
1983
- isAreaEmpty(e, t, i, s) {
1984
- const r = { x: e || 0, y: t || 0, w: i || 1, h: s || 1 };
1985
- return !this.collide(r);
1986
- }
1987
- /** re-layout grid items to reclaim any empty space - optionally keeping the sort order exactly the same ('list' mode) vs truly finding an empty spaces */
1988
- compact(e = "compact", t = !0) {
1989
- if (this.nodes.length === 0)
1990
- return this;
1991
- t && this.sortNodes();
1992
- const i = this.batchMode;
1993
- i || this.batchUpdate();
1994
- const s = this._inColumnResize;
1995
- s || (this._inColumnResize = !0);
1996
- const r = this.nodes;
1997
- return this.nodes = [], r.forEach((o, n, d) => {
1998
- let u;
1999
- o.locked || (o.autoPosition = !0, e === "list" && n && (u = d[n - 1])), this.addNode(o, !1, u);
2000
- }), s || delete this._inColumnResize, i || this.batchUpdate(!1), this;
2001
- }
2002
- /** enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html) */
2003
- set float(e) {
2004
- this._float !== e && (this._float = e || !1, e || this._packNodes()._notify());
2005
- }
2006
- /** float getter method */
2007
- get float() {
2008
- return this._float || !1;
2009
- }
2010
- /** sort the nodes array from first to last, or reverse. Called during collision/placement to force an order */
2011
- sortNodes(e = 1) {
2012
- return this.nodes = c.sort(this.nodes, e), this;
2013
- }
2014
- /** @internal called to top gravity pack the items back OR revert back to original Y positions when floating */
2015
- _packNodes() {
2016
- return this.batchMode ? this : (this.sortNodes(), this.float ? this.nodes.forEach((e) => {
2017
- if (e._updating || e._orig === void 0 || e.y === e._orig.y)
2018
- return;
2019
- let t = e.y;
2020
- for (; t > e._orig.y; )
2021
- --t, this.collide(e, { x: e.x, y: t, w: e.w, h: e.h }) || (e._dirty = !0, e.y = t);
2022
- }) : this.nodes.forEach((e, t) => {
2023
- if (!e.locked)
2024
- for (; e.y > 0; ) {
2025
- const i = t === 0 ? 0 : e.y - 1;
2026
- if (!(t === 0 || !this.collide(e, { x: e.x, y: i, w: e.w, h: e.h })))
2027
- break;
2028
- e._dirty = e.y !== i, e.y = i;
2029
- }
2030
- }), this);
2031
- }
2032
- /**
2033
- * given a random node, makes sure it's coordinates/values are valid in the current grid
2034
- * @param node to adjust
2035
- * @param resizing if out of bound, resize down or move into the grid to fit ?
2036
- */
2037
- prepareNode(e, t) {
2038
- e._id = e._id ?? he._idSeq++;
2039
- const i = e.id;
2040
- if (i) {
2041
- let r = 1;
2042
- for (; this.nodes.find((o) => o.id === e.id && o !== e); )
2043
- e.id = i + "_" + r++;
2044
- }
2045
- (e.x === void 0 || e.y === void 0 || e.x === null || e.y === null) && (e.autoPosition = !0);
2046
- const s = { x: 0, y: 0, w: 1, h: 1 };
2047
- return c.defaults(e, s), e.autoPosition || delete e.autoPosition, e.noResize || delete e.noResize, e.noMove || delete e.noMove, c.sanitizeMinMax(e), typeof e.x == "string" && (e.x = Number(e.x)), typeof e.y == "string" && (e.y = Number(e.y)), typeof e.w == "string" && (e.w = Number(e.w)), typeof e.h == "string" && (e.h = Number(e.h)), isNaN(e.x) && (e.x = s.x, e.autoPosition = !0), isNaN(e.y) && (e.y = s.y, e.autoPosition = !0), isNaN(e.w) && (e.w = s.w), isNaN(e.h) && (e.h = s.h), this.nodeBoundFix(e, t), e;
2048
- }
2049
- /** part2 of preparing a node to fit inside our grid - checks for x,y,w from grid dimensions */
2050
- nodeBoundFix(e, t) {
2051
- const i = e._orig || c.copyPos({}, e);
2052
- if (e.maxW && (e.w = Math.min(e.w || 1, e.maxW)), e.maxH && (e.h = Math.min(e.h || 1, e.maxH)), e.minW && (e.w = Math.max(e.w || 1, e.minW)), e.minH && (e.h = Math.max(e.h || 1, e.minH)), (e.x || 0) + (e.w || 1) > this.column && this.column < this.defaultColumn && !this._inColumnResize && !this.skipCacheUpdate && e._id && this.findCacheLayout(e, this.defaultColumn) === -1) {
2053
- const r = { ...e };
2054
- r.autoPosition || r.x === void 0 ? (delete r.x, delete r.y) : r.x = Math.min(this.defaultColumn - 1, r.x), r.w = Math.min(this.defaultColumn, r.w || 1), this.cacheOneLayout(r, this.defaultColumn);
2055
- }
2056
- return e.w > this.column ? e.w = this.column : e.w < 1 && (e.w = 1), this.maxRow && e.h > this.maxRow ? e.h = this.maxRow : e.h < 1 && (e.h = 1), e.x < 0 && (e.x = 0), e.y < 0 && (e.y = 0), e.x + e.w > this.column && (t ? e.w = this.column - e.x : e.x = this.column - e.w), this.maxRow && e.y + e.h > this.maxRow && (t ? e.h = this.maxRow - e.y : e.y = this.maxRow - e.h), c.samePos(e, i) || (e._dirty = !0), this;
2057
- }
2058
- /** returns a list of modified nodes from their original values */
2059
- getDirtyNodes(e) {
2060
- return e ? this.nodes.filter((t) => t._dirty && !c.samePos(t, t._orig)) : this.nodes.filter((t) => t._dirty);
2061
- }
2062
- /** @internal call this to call onChange callback with dirty nodes so DOM can be updated */
2063
- _notify(e) {
2064
- if (this.batchMode || !this.onChange)
2065
- return this;
2066
- const t = (e || []).concat(this.getDirtyNodes());
2067
- return this.onChange(t), this;
2068
- }
2069
- /** @internal remove dirty and last tried info */
2070
- cleanNodes() {
2071
- return this.batchMode ? this : (this.nodes.forEach((e) => {
2072
- delete e._dirty, delete e._lastTried;
2073
- }), this);
2074
- }
2075
- /** @internal called to save initial position/size to track real dirty state.
2076
- * Note: should be called right after we call change event (so next API is can detect changes)
2077
- * as well as right before we start move/resize/enter (so we can restore items to prev values) */
2078
- saveInitial() {
2079
- return this.nodes.forEach((e) => {
2080
- e._orig = c.copyPos({}, e), delete e._dirty;
2081
- }), this._hasLocked = this.nodes.some((e) => e.locked), this;
2082
- }
2083
- /** @internal restore all the nodes back to initial values (called when we leave) */
2084
- restoreInitial() {
2085
- return this.nodes.forEach((e) => {
2086
- !e._orig || c.samePos(e, e._orig) || (c.copyPos(e, e._orig), e._dirty = !0);
2087
- }), this._notify(), this;
2088
- }
2089
- /** find the first available empty spot for the given node width/height, updating the x,y attributes. return true if found.
2090
- * optionally you can pass your own existing node list and column count, otherwise defaults to that engine data.
2091
- * Optionally pass a widget to start search AFTER, meaning the order will remain the same but possibly have empty slots we skipped
2092
- */
2093
- findEmptyPosition(e, t = this.nodes, i = this.column, s) {
2094
- const r = s ? s.y * i + (s.x + s.w) : 0;
2095
- let o = !1;
2096
- for (let n = r; !o; ++n) {
2097
- const d = n % i, u = Math.floor(n / i);
2098
- if (d + e.w > i)
2099
- continue;
2100
- const h = { x: d, y: u, w: e.w, h: e.h };
2101
- t.find((l) => c.isIntercepted(h, l)) || ((e.x !== d || e.y !== u) && (e._dirty = !0), e.x = d, e.y = u, delete e.autoPosition, o = !0);
2102
- }
2103
- return o;
2104
- }
2105
- /** call to add the given node to our list, fixing collision and re-packing */
2106
- addNode(e, t = !1, i) {
2107
- const s = this.nodes.find((o) => o._id === e._id);
2108
- if (s)
2109
- return s;
2110
- this._inColumnResize ? this.nodeBoundFix(e) : this.prepareNode(e), delete e._temporaryRemoved, delete e._removeDOM;
2111
- let r;
2112
- return e.autoPosition && this.findEmptyPosition(e, this.nodes, this.column, i) && (delete e.autoPosition, r = !0), this.nodes.push(e), t && this.addedNodes.push(e), r || this._fixCollisions(e), this.batchMode || this._packNodes()._notify(), e;
2113
- }
2114
- removeNode(e, t = !0, i = !1) {
2115
- return this.nodes.find((s) => s._id === e._id) ? (i && this.removedNodes.push(e), t && (e._removeDOM = !0), this.nodes = this.nodes.filter((s) => s._id !== e._id), e._isAboutToRemove || this._packNodes(), this._notify([e]), this) : this;
2116
- }
2117
- removeAll(e = !0, t = !0) {
2118
- if (delete this._layouts, !this.nodes.length)
2119
- return this;
2120
- e && this.nodes.forEach((s) => s._removeDOM = !0);
2121
- const i = this.nodes;
2122
- return this.removedNodes = t ? i : [], this.nodes = [], this._notify(i);
2123
- }
2124
- /** checks if item can be moved (layout constrain) vs moveNode(), returning true if was able to move.
2125
- * In more complicated cases (maxRow) it will attempt at moving the item and fixing
2126
- * others in a clone first, then apply those changes if still within specs. */
2127
- moveNodeCheck(e, t) {
2128
- if (!this.changedPosConstrain(e, t))
2129
- return !1;
2130
- if (t.pack = !0, !this.maxRow)
2131
- return this.moveNode(e, t);
2132
- let i;
2133
- const s = new he({
2134
- column: this.column,
2135
- float: this.float,
2136
- nodes: this.nodes.map((o) => o._id === e._id ? (i = { ...o }, i) : { ...o })
2137
- });
2138
- if (!i)
2139
- return !1;
2140
- const r = s.moveNode(i, t) && s.getRow() <= Math.max(this.getRow(), this.maxRow);
2141
- if (!r && !t.resizing && t.collide) {
2142
- const o = t.collide.el.gridstackNode;
2143
- if (this.swap(e, o))
2144
- return this._notify(), !0;
2145
- }
2146
- return r ? (s.nodes.filter((o) => o._dirty).forEach((o) => {
2147
- const n = this.nodes.find((d) => d._id === o._id);
2148
- n && (c.copyPos(n, o), n._dirty = !0);
2149
- }), this._notify(), !0) : !1;
2150
- }
2151
- /** return true if can fit in grid height constrain only (always true if no maxRow) */
2152
- willItFit(e) {
2153
- if (delete e._willFitPos, !this.maxRow)
2154
- return !0;
2155
- const t = new he({
2156
- column: this.column,
2157
- float: this.float,
2158
- nodes: this.nodes.map((s) => ({ ...s }))
2159
- }), i = { ...e };
2160
- return this.cleanupNode(i), delete i.el, delete i._id, delete i.content, delete i.grid, t.addNode(i), t.getRow() <= this.maxRow ? (e._willFitPos = c.copyPos({}, i), !0) : !1;
2161
- }
2162
- /** true if x,y or w,h are different after clamping to min/max */
2163
- changedPosConstrain(e, t) {
2164
- return t.w = t.w || e.w, t.h = t.h || e.h, e.x !== t.x || e.y !== t.y ? !0 : (e.maxW && (t.w = Math.min(t.w, e.maxW)), e.maxH && (t.h = Math.min(t.h, e.maxH)), e.minW && (t.w = Math.max(t.w, e.minW)), e.minH && (t.h = Math.max(t.h, e.minH)), e.w !== t.w || e.h !== t.h);
2165
- }
2166
- /** return true if the passed in node was actually moved (checks for no-op and locked) */
2167
- moveNode(e, t) {
2168
- var u, h;
2169
- if (!e || /*node.locked ||*/
2170
- !t)
2171
- return !1;
2172
- let i;
2173
- t.pack === void 0 && !this.batchMode && (i = t.pack = !0), typeof t.x != "number" && (t.x = e.x), typeof t.y != "number" && (t.y = e.y), typeof t.w != "number" && (t.w = e.w), typeof t.h != "number" && (t.h = e.h);
2174
- const s = e.w !== t.w || e.h !== t.h, r = c.copyPos({}, e, !0);
2175
- if (c.copyPos(r, t), this.nodeBoundFix(r, s), c.copyPos(t, r), !t.forceCollide && c.samePos(e, t))
2176
- return !1;
2177
- const o = c.copyPos({}, e), n = this.collideAll(e, r, t.skip);
2178
- let d = !0;
2179
- if (n.length) {
2180
- const l = e._moving && !t.nested;
2181
- let f = l ? this.directionCollideCoverage(e, t, n) : n[0];
2182
- if (l && f && ((h = (u = e.grid) == null ? void 0 : u.opts) != null && h.subGridDynamic) && !e.grid._isTemp) {
2183
- const g = c.areaIntercept(t.rect, f._rect), p = c.area(t.rect), y = c.area(f._rect);
2184
- g / (p < y ? p : y) > 0.8 && (f.grid.makeSubGrid(f.el, void 0, e), f = void 0);
2185
- }
2186
- f ? d = !this._fixCollisions(e, r, f, t) : (d = !1, i && delete t.pack);
2187
- }
2188
- return d && !c.samePos(e, r) && (e._dirty = !0, c.copyPos(e, r)), t.pack && this._packNodes()._notify(), !c.samePos(e, o);
2189
- }
2190
- getRow() {
2191
- return this.nodes.reduce((e, t) => Math.max(e, t.y + t.h), 0);
2192
- }
2193
- beginUpdate(e) {
2194
- return e._updating || (e._updating = !0, delete e._skipDown, this.batchMode || this.saveInitial()), this;
2195
- }
2196
- endUpdate() {
2197
- const e = this.nodes.find((t) => t._updating);
2198
- return e && (delete e._updating, delete e._skipDown), this;
2199
- }
2200
- /** saves a copy of the largest column layout (eg 12 even when rendering oneColumnMode) so we don't loose orig layout,
2201
- * returning a list of widgets for serialization */
2202
- save(e = !0, t) {
2203
- var o;
2204
- const i = (o = this._layouts) == null ? void 0 : o.length, s = i && this.column !== i - 1 ? this._layouts[i - 1] : null, r = [];
2205
- return this.sortNodes(), this.nodes.forEach((n) => {
2206
- const d = s == null ? void 0 : s.find((h) => h._id === n._id), u = { ...n, ...d || {} };
2207
- c.removeInternalForSave(u, !e), t && t(n, u), r.push(u);
2208
- }), r;
2209
- }
2210
- /** @internal called whenever a node is added or moved - updates the cached layouts */
2211
- layoutsNodesChange(e) {
2212
- return !this._layouts || this._inColumnResize ? this : (this._layouts.forEach((t, i) => {
2213
- if (!t || i === this.column)
2214
- return this;
2215
- if (i < this.column)
2216
- this._layouts[i] = void 0;
2217
- else {
2218
- const s = i / this.column;
2219
- e.forEach((r) => {
2220
- if (!r._orig)
2221
- return;
2222
- const o = t.find((n) => n._id === r._id);
2223
- o && (o.y >= 0 && r.y !== r._orig.y && (o.y += r.y - r._orig.y), r.x !== r._orig.x && (o.x = Math.round(r.x * s)), r.w !== r._orig.w && (o.w = Math.round(r.w * s)));
2224
- });
2225
- }
2226
- }), this);
2227
- }
2228
- /**
2229
- * @internal Called to scale the widget width & position up/down based on the column change.
2230
- * Note we store previous layouts (especially original ones) to make it possible to go
2231
- * from say 12 -> 1 -> 12 and get back to where we were.
2232
- *
2233
- * @param prevColumn previous number of columns
2234
- * @param column new column number
2235
- * @param layout specify the type of re-layout that will happen (position, size, etc...).
2236
- * Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column
2237
- */
2238
- columnChanged(e, t, i = "moveScale") {
2239
- var n;
2240
- if (!this.nodes.length || !t || e === t)
2241
- return this;
2242
- const s = i === "compact" || i === "list";
2243
- s && this.sortNodes(1), t < e && this.cacheLayout(this.nodes, e), this.batchUpdate();
2244
- let r = [], o = s ? this.nodes : c.sort(this.nodes, -1);
2245
- if (t > e && this._layouts) {
2246
- const d = this._layouts[t] || [], u = this._layouts.length - 1;
2247
- !d.length && e !== u && ((n = this._layouts[u]) != null && n.length) && (e = u, this._layouts[u].forEach((h) => {
2248
- const l = o.find((f) => f._id === h._id);
2249
- l && (!s && !h.autoPosition && (l.x = h.x ?? l.x, l.y = h.y ?? l.y), l.w = h.w ?? l.w, (h.x == null || h.y === void 0) && (l.autoPosition = !0));
2250
- })), d.forEach((h) => {
2251
- const l = o.findIndex((f) => f._id === h._id);
2252
- if (l !== -1) {
2253
- const f = o[l];
2254
- if (s) {
2255
- f.w = h.w;
2256
- return;
2257
- }
2258
- (h.autoPosition || isNaN(h.x) || isNaN(h.y)) && this.findEmptyPosition(h, r), h.autoPosition || (f.x = h.x ?? f.x, f.y = h.y ?? f.y, f.w = h.w ?? f.w, r.push(f)), o.splice(l, 1);
2259
- }
2260
- });
2261
- }
2262
- if (s)
2263
- this.compact(i, !1);
2264
- else {
2265
- if (o.length)
2266
- if (typeof i == "function")
2267
- i(t, e, r, o);
2268
- else {
2269
- const d = s || i === "none" ? 1 : t / e, u = i === "move" || i === "moveScale", h = i === "scale" || i === "moveScale";
2270
- o.forEach((l) => {
2271
- l.x = t === 1 ? 0 : u ? Math.round(l.x * d) : Math.min(l.x, t - 1), l.w = t === 1 || e === 1 ? 1 : h ? Math.round(l.w * d) || 1 : Math.min(l.w, t), r.push(l);
2272
- }), o = [];
2273
- }
2274
- r = c.sort(r, -1), this._inColumnResize = !0, this.nodes = [], r.forEach((d) => {
2275
- this.addNode(d, !1), delete d._orig;
2276
- });
2277
- }
2278
- return this.nodes.forEach((d) => delete d._orig), this.batchUpdate(!1, !s), delete this._inColumnResize, this;
2279
- }
2280
- /**
2281
- * call to cache the given layout internally to the given location so we can restore back when column changes size
2282
- * @param nodes list of nodes
2283
- * @param column corresponding column index to save it under
2284
- * @param clear if true, will force other caches to be removed (default false)
2285
- */
2286
- cacheLayout(e, t, i = !1) {
2287
- const s = [];
2288
- return e.forEach((r, o) => {
2289
- if (r._id === void 0) {
2290
- const n = r.id ? this.nodes.find((d) => d.id === r.id) : void 0;
2291
- r._id = (n == null ? void 0 : n._id) ?? he._idSeq++;
2292
- }
2293
- s[o] = { x: r.x, y: r.y, w: r.w, _id: r._id };
2294
- }), this._layouts = i ? [] : this._layouts || [], this._layouts[t] = s, this;
2295
- }
2296
- /**
2297
- * call to cache the given node layout internally to the given location so we can restore back when column changes size
2298
- * @param node single node to cache
2299
- * @param column corresponding column index to save it under
2300
- */
2301
- cacheOneLayout(e, t) {
2302
- e._id = e._id ?? he._idSeq++;
2303
- const i = { x: e.x, y: e.y, w: e.w, _id: e._id };
2304
- (e.autoPosition || e.x === void 0) && (delete i.x, delete i.y, e.autoPosition && (i.autoPosition = !0)), this._layouts = this._layouts || [], this._layouts[t] = this._layouts[t] || [];
2305
- const s = this.findCacheLayout(e, t);
2306
- return s === -1 ? this._layouts[t].push(i) : this._layouts[t][s] = i, this;
2307
- }
2308
- findCacheLayout(e, t) {
2309
- var i, s;
2310
- return ((s = (i = this._layouts) == null ? void 0 : i[t]) == null ? void 0 : s.findIndex((r) => r._id === e._id)) ?? -1;
2311
- }
2312
- removeNodeFromLayoutCache(e) {
2313
- if (this._layouts)
2314
- for (let t = 0; t < this._layouts.length; t++) {
2315
- const i = this.findCacheLayout(e, t);
2316
- i !== -1 && this._layouts[t].splice(i, 1);
2317
- }
2318
- }
2319
- /** called to remove all internal values but the _id */
2320
- cleanupNode(e) {
2321
- for (const t in e)
2322
- t[0] === "_" && t !== "_id" && delete e[t];
2323
- return this;
2324
- }
2325
- }
2326
- he._idSeq = 0;
2327
- const Z = {
2328
- alwaysShowResizeHandle: "mobile",
2329
- animate: !0,
2330
- auto: !0,
2331
- cellHeight: "auto",
2332
- cellHeightThrottle: 100,
2333
- cellHeightUnit: "px",
2334
- column: 12,
2335
- draggable: { handle: ".grid-stack-item-content", appendTo: "body", scroll: !0 },
2336
- handle: ".grid-stack-item-content",
2337
- itemClass: "grid-stack-item",
2338
- margin: 10,
2339
- marginUnit: "px",
2340
- maxRow: 0,
2341
- minRow: 0,
2342
- placeholderClass: "grid-stack-placeholder",
2343
- placeholderText: "",
2344
- removableOptions: { accept: "grid-stack-item", decline: "grid-stack-non-removable" },
2345
- resizable: { handles: "se" },
2346
- rtl: "auto"
2347
- // **** same as not being set ****
2348
- // disableDrag: false,
2349
- // disableResize: false,
2350
- // float: false,
2351
- // handleClass: null,
2352
- // removable: false,
2353
- // staticGrid: false,
2354
- // styleInHead: false,
2355
- //removable
2356
- };
2357
- class w {
2358
- }
2359
- const le = typeof window < "u" && typeof document < "u" && ("ontouchstart" in document || "ontouchstart" in window || window.DocumentTouch && document instanceof window.DocumentTouch || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
2360
- class ue {
2361
- }
2362
- function We(a, e) {
2363
- a.touches.length > 1 || (a.cancelable && a.preventDefault(), c.simulateMouseEvent(a.changedTouches[0], e));
2364
- }
2365
- function Jt(a, e) {
2366
- a.cancelable && a.preventDefault(), c.simulateMouseEvent(a, e);
2367
- }
2368
- function Ke(a) {
2369
- ue.touchHandled || (ue.touchHandled = !0, We(a, "mousedown"));
2370
- }
2371
- function Qe(a) {
2372
- ue.touchHandled && We(a, "mousemove");
2373
- }
2374
- function Ve(a) {
2375
- if (!ue.touchHandled)
2376
- return;
2377
- ue.pointerLeaveTimeout && (window.clearTimeout(ue.pointerLeaveTimeout), delete ue.pointerLeaveTimeout);
2378
- const e = !!w.dragElement;
2379
- We(a, "mouseup"), e || We(a, "click"), ue.touchHandled = !1;
2380
- }
2381
- function Ye(a) {
2382
- a.pointerType !== "mouse" && a.target.releasePointerCapture(a.pointerId);
2383
- }
2384
- function Lt(a) {
2385
- w.dragElement && a.pointerType !== "mouse" && Jt(a, "mouseenter");
2386
- }
2387
- function At(a) {
2388
- w.dragElement && a.pointerType !== "mouse" && (ue.pointerLeaveTimeout = window.setTimeout(() => {
2389
- delete ue.pointerLeaveTimeout, Jt(a, "mouseleave");
2390
- }, 10));
2391
- }
2392
- class et {
2393
- constructor(e, t, i) {
2394
- this.host = e, this.dir = t, this.option = i, this.moving = !1, this._mouseDown = this._mouseDown.bind(this), this._mouseMove = this._mouseMove.bind(this), this._mouseUp = this._mouseUp.bind(this), this._keyEvent = this._keyEvent.bind(this), this._init();
2395
- }
2396
- /** @internal */
2397
- _init() {
2398
- const e = this.el = document.createElement("div");
2399
- return e.classList.add("ui-resizable-handle"), e.classList.add(`${et.prefix}${this.dir}`), e.style.zIndex = "100", e.style.userSelect = "none", this.host.appendChild(this.el), this.el.addEventListener("mousedown", this._mouseDown), le && (this.el.addEventListener("touchstart", Ke), this.el.addEventListener("pointerdown", Ye)), this;
2400
- }
2401
- /** call this when resize handle needs to be removed and cleaned up */
2402
- destroy() {
2403
- return this.moving && this._mouseUp(this.mouseDownEvent), this.el.removeEventListener("mousedown", this._mouseDown), le && (this.el.removeEventListener("touchstart", Ke), this.el.removeEventListener("pointerdown", Ye)), this.host.removeChild(this.el), delete this.el, delete this.host, this;
2404
- }
2405
- /** @internal called on mouse down on us: capture move on the entire document (mouse might not stay on us) until we release the mouse */
2406
- _mouseDown(e) {
2407
- this.mouseDownEvent = e, document.addEventListener("mousemove", this._mouseMove, { capture: !0, passive: !0 }), document.addEventListener("mouseup", this._mouseUp, !0), le && (this.el.addEventListener("touchmove", Qe), this.el.addEventListener("touchend", Ve)), e.stopPropagation(), e.preventDefault();
2408
- }
2409
- /** @internal */
2410
- _mouseMove(e) {
2411
- const t = this.mouseDownEvent;
2412
- this.moving ? this._triggerEvent("move", e) : Math.abs(e.x - t.x) + Math.abs(e.y - t.y) > 2 && (this.moving = !0, this._triggerEvent("start", this.mouseDownEvent), this._triggerEvent("move", e), document.addEventListener("keydown", this._keyEvent)), e.stopPropagation();
2413
- }
2414
- /** @internal */
2415
- _mouseUp(e) {
2416
- this.moving && (this._triggerEvent("stop", e), document.removeEventListener("keydown", this._keyEvent)), document.removeEventListener("mousemove", this._mouseMove, !0), document.removeEventListener("mouseup", this._mouseUp, !0), le && (this.el.removeEventListener("touchmove", Qe), this.el.removeEventListener("touchend", Ve)), delete this.moving, delete this.mouseDownEvent, e.stopPropagation(), e.preventDefault();
2417
- }
2418
- /** @internal call when keys are being pressed - use Esc to cancel */
2419
- _keyEvent(e) {
2420
- var t, i;
2421
- e.key === "Escape" && ((i = (t = this.host.gridstackNode) == null ? void 0 : t.grid) == null || i.engine.restoreInitial(), this._mouseUp(this.mouseDownEvent));
2422
- }
2423
- /** @internal */
2424
- _triggerEvent(e, t) {
2425
- return this.option[e] && this.option[e](t), this;
2426
- }
2427
- }
2428
- et.prefix = "ui-resizable-";
2429
- class mt {
2430
- constructor() {
2431
- this._eventRegister = {};
2432
- }
2433
- /** returns the enable state, but you have to call enable()/disable() to change (as other things need to happen) */
2434
- get disabled() {
2435
- return this._disabled;
2436
- }
2437
- on(e, t) {
2438
- this._eventRegister[e] = t;
2439
- }
2440
- off(e) {
2441
- delete this._eventRegister[e];
2442
- }
2443
- enable() {
2444
- this._disabled = !1;
2445
- }
2446
- disable() {
2447
- this._disabled = !0;
2448
- }
2449
- destroy() {
2450
- delete this._eventRegister;
2451
- }
2452
- triggerEvent(e, t) {
2453
- if (!this.disabled && this._eventRegister && this._eventRegister[e])
2454
- return this._eventRegister[e](t);
2455
- }
2456
- }
2457
- class Le extends mt {
2458
- // have to be public else complains for HTMLElementExtendOpt ?
2459
- constructor(e, t = {}) {
2460
- super(), this.el = e, this.option = t, this.rectScale = { x: 1, y: 1 }, this._ui = () => {
2461
- const s = this.el.parentElement.getBoundingClientRect(), r = {
2462
- width: this.originalRect.width,
2463
- height: this.originalRect.height + this.scrolled,
2464
- left: this.originalRect.left,
2465
- top: this.originalRect.top - this.scrolled
2466
- }, o = this.temporalRect || r;
2467
- return {
2468
- position: {
2469
- left: (o.left - s.left) * this.rectScale.x,
2470
- top: (o.top - s.top) * this.rectScale.y
2471
- },
2472
- size: {
2473
- width: o.width * this.rectScale.x,
2474
- height: o.height * this.rectScale.y
2475
- }
2476
- /* Gridstack ONLY needs position set above... keep around in case.
2477
- element: [this.el], // The object representing the element to be resized
2478
- helper: [], // TODO: not support yet - The object representing the helper that's being resized
2479
- originalElement: [this.el],// we don't wrap here, so simplify as this.el //The object representing the original element before it is wrapped
2480
- originalPosition: { // The position represented as { left, top } before the resizable is resized
2481
- left: this.originalRect.left - containmentRect.left,
2482
- top: this.originalRect.top - containmentRect.top
2483
- },
2484
- originalSize: { // The size represented as { width, height } before the resizable is resized
2485
- width: this.originalRect.width,
2486
- height: this.originalRect.height
2487
- }
2488
- */
2489
- };
2490
- }, this._mouseOver = this._mouseOver.bind(this), this._mouseOut = this._mouseOut.bind(this), this.enable(), this._setupAutoHide(this.option.autoHide), this._setupHandlers();
2491
- }
2492
- on(e, t) {
2493
- super.on(e, t);
2494
- }
2495
- off(e) {
2496
- super.off(e);
2497
- }
2498
- enable() {
2499
- super.enable(), this.el.classList.remove("ui-resizable-disabled"), this._setupAutoHide(this.option.autoHide);
2500
- }
2501
- disable() {
2502
- super.disable(), this.el.classList.add("ui-resizable-disabled"), this._setupAutoHide(!1);
2503
- }
2504
- destroy() {
2505
- this._removeHandlers(), this._setupAutoHide(!1), delete this.el, super.destroy();
2506
- }
2507
- updateOption(e) {
2508
- const t = e.handles && e.handles !== this.option.handles, i = e.autoHide && e.autoHide !== this.option.autoHide;
2509
- return Object.keys(e).forEach((s) => this.option[s] = e[s]), t && (this._removeHandlers(), this._setupHandlers()), i && this._setupAutoHide(this.option.autoHide), this;
2510
- }
2511
- /** @internal turns auto hide on/off */
2512
- _setupAutoHide(e) {
2513
- return e ? (this.el.classList.add("ui-resizable-autohide"), this.el.addEventListener("mouseover", this._mouseOver), this.el.addEventListener("mouseout", this._mouseOut)) : (this.el.classList.remove("ui-resizable-autohide"), this.el.removeEventListener("mouseover", this._mouseOver), this.el.removeEventListener("mouseout", this._mouseOut), w.overResizeElement === this && delete w.overResizeElement), this;
2514
- }
2515
- /** @internal */
2516
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2517
- _mouseOver(e) {
2518
- w.overResizeElement || w.dragElement || (w.overResizeElement = this, this.el.classList.remove("ui-resizable-autohide"));
2519
- }
2520
- /** @internal */
2521
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2522
- _mouseOut(e) {
2523
- w.overResizeElement === this && (delete w.overResizeElement, this.el.classList.add("ui-resizable-autohide"));
2524
- }
2525
- /** @internal */
2526
- _setupHandlers() {
2527
- return this.handlers = this.option.handles.split(",").map((e) => e.trim()).map((e) => new et(this.el, e, {
2528
- start: (t) => {
2529
- this._resizeStart(t);
2530
- },
2531
- stop: (t) => {
2532
- this._resizeStop(t);
2533
- },
2534
- move: (t) => {
2535
- this._resizing(t, e);
2536
- }
2537
- })), this;
2538
- }
2539
- /** @internal */
2540
- _resizeStart(e) {
2541
- this.sizeToContent = c.shouldSizeToContent(this.el.gridstackNode, !0), this.originalRect = this.el.getBoundingClientRect(), this.scrollEl = c.getScrollElement(this.el), this.scrollY = this.scrollEl.scrollTop, this.scrolled = 0, this.startEvent = e, this._setupHelper(), this._applyChange();
2542
- const t = c.initEvent(e, { type: "resizestart", target: this.el });
2543
- return this.option.start && this.option.start(t, this._ui()), this.el.classList.add("ui-resizable-resizing"), this.triggerEvent("resizestart", t), this;
2544
- }
2545
- /** @internal */
2546
- _resizing(e, t) {
2547
- this.scrolled = this.scrollEl.scrollTop - this.scrollY, this.temporalRect = this._getChange(e, t), this._applyChange();
2548
- const i = c.initEvent(e, { type: "resize", target: this.el });
2549
- return this.option.resize && this.option.resize(i, this._ui()), this.triggerEvent("resize", i), this;
2550
- }
2551
- /** @internal */
2552
- _resizeStop(e) {
2553
- const t = c.initEvent(e, { type: "resizestop", target: this.el });
2554
- return this.option.stop && this.option.stop(t), this.el.classList.remove("ui-resizable-resizing"), this.triggerEvent("resizestop", t), this._cleanHelper(), delete this.startEvent, delete this.originalRect, delete this.temporalRect, delete this.scrollY, delete this.scrolled, this;
2555
- }
2556
- /** @internal */
2557
- _setupHelper() {
2558
- this.elOriginStyleVal = Le._originStyleProp.map((i) => this.el.style[i]), this.parentOriginStylePosition = this.el.parentElement.style.position;
2559
- const e = this.el.parentElement, t = c.getValuesFromTransformedElement(e);
2560
- return this.rectScale = {
2561
- x: t.xScale,
2562
- y: t.yScale
2563
- }, getComputedStyle(this.el.parentElement).position.match(/static/) && (this.el.parentElement.style.position = "relative"), this.el.style.position = "absolute", this.el.style.opacity = "0.8", this;
2564
- }
2565
- /** @internal */
2566
- _cleanHelper() {
2567
- return Le._originStyleProp.forEach((e, t) => {
2568
- this.el.style[e] = this.elOriginStyleVal[t] || null;
2569
- }), this.el.parentElement.style.position = this.parentOriginStylePosition || null, this;
2570
- }
2571
- /** @internal */
2572
- _getChange(e, t) {
2573
- const i = this.startEvent, s = {
2574
- width: this.originalRect.width,
2575
- height: this.originalRect.height + this.scrolled,
2576
- left: this.originalRect.left,
2577
- top: this.originalRect.top - this.scrolled
2578
- }, r = e.clientX - i.clientX, o = this.sizeToContent ? 0 : e.clientY - i.clientY;
2579
- let n, d;
2580
- t.indexOf("e") > -1 ? s.width += r : t.indexOf("w") > -1 && (s.width -= r, s.left += r, n = !0), t.indexOf("s") > -1 ? s.height += o : t.indexOf("n") > -1 && (s.height -= o, s.top += o, d = !0);
2581
- const u = this._constrainSize(s.width, s.height, n, d);
2582
- return Math.round(s.width) !== Math.round(u.width) && (t.indexOf("w") > -1 && (s.left += s.width - u.width), s.width = u.width), Math.round(s.height) !== Math.round(u.height) && (t.indexOf("n") > -1 && (s.top += s.height - u.height), s.height = u.height), s;
2583
- }
2584
- /** @internal constrain the size to the set min/max values */
2585
- _constrainSize(e, t, i, s) {
2586
- const r = this.option, o = (i ? r.maxWidthMoveLeft : r.maxWidth) || Number.MAX_SAFE_INTEGER, n = r.minWidth / this.rectScale.x || e, d = (s ? r.maxHeightMoveUp : r.maxHeight) || Number.MAX_SAFE_INTEGER, u = r.minHeight / this.rectScale.y || t, h = Math.min(o, Math.max(n, e)), l = Math.min(d, Math.max(u, t));
2587
- return { width: h, height: l };
2588
- }
2589
- /** @internal */
2590
- _applyChange() {
2591
- let e = { left: 0, top: 0, width: 0, height: 0 };
2592
- if (this.el.style.position === "absolute") {
2593
- const t = this.el.parentElement, { left: i, top: s } = t.getBoundingClientRect();
2594
- e = { left: i, top: s, width: 0, height: 0 };
2595
- }
2596
- return this.temporalRect ? (Object.keys(this.temporalRect).forEach((t) => {
2597
- const i = this.temporalRect[t], s = t === "width" || t === "left" ? this.rectScale.x : t === "height" || t === "top" ? this.rectScale.y : 1;
2598
- this.el.style[t] = (i - e[t]) * s + "px";
2599
- }), this) : this;
2600
- }
2601
- /** @internal */
2602
- _removeHandlers() {
2603
- return this.handlers.forEach((e) => e.destroy()), delete this.handlers, this;
2604
- }
2605
- }
2606
- Le._originStyleProp = ["width", "height", "position", "left", "top", "opacity", "zIndex"];
2607
- const Bs = 'input,textarea,button,select,option,[contenteditable="true"],.ui-resizable-handle';
2608
- class Ae extends mt {
2609
- constructor(e, t = {}) {
2610
- var r;
2611
- super(), this.el = e, this.option = t, this.dragTransform = {
2612
- xScale: 1,
2613
- yScale: 1,
2614
- xOffset: 0,
2615
- yOffset: 0
2616
- };
2617
- const i = (r = t == null ? void 0 : t.handle) == null ? void 0 : r.substring(1), s = e.gridstackNode;
2618
- this.dragEls = !i || e.classList.contains(i) ? [e] : s != null && s.subGrid ? [e.querySelector(t.handle) || e] : Array.from(e.querySelectorAll(t.handle)), this.dragEls.length === 0 && (this.dragEls = [e]), this._mouseDown = this._mouseDown.bind(this), this._mouseMove = this._mouseMove.bind(this), this._mouseUp = this._mouseUp.bind(this), this._keyEvent = this._keyEvent.bind(this), this.enable();
2619
- }
2620
- on(e, t) {
2621
- super.on(e, t);
2622
- }
2623
- off(e) {
2624
- super.off(e);
2625
- }
2626
- enable() {
2627
- this.disabled !== !1 && (super.enable(), this.dragEls.forEach((e) => {
2628
- e.addEventListener("mousedown", this._mouseDown), le && (e.addEventListener("touchstart", Ke), e.addEventListener("pointerdown", Ye));
2629
- }), this.el.classList.remove("ui-draggable-disabled"));
2630
- }
2631
- disable(e = !1) {
2632
- this.disabled !== !0 && (super.disable(), this.dragEls.forEach((t) => {
2633
- t.removeEventListener("mousedown", this._mouseDown), le && (t.removeEventListener("touchstart", Ke), t.removeEventListener("pointerdown", Ye));
2634
- }), e || this.el.classList.add("ui-draggable-disabled"));
2635
- }
2636
- destroy() {
2637
- this.dragTimeout && window.clearTimeout(this.dragTimeout), delete this.dragTimeout, this.mouseDownEvent && this._mouseUp(this.mouseDownEvent), this.disable(!0), delete this.el, delete this.helper, delete this.option, super.destroy();
2638
- }
2639
- updateOption(e) {
2640
- return Object.keys(e).forEach((t) => this.option[t] = e[t]), this;
2641
- }
2642
- /** @internal call when mouse goes down before a dragstart happens */
2643
- _mouseDown(e) {
2644
- if (!w.mouseHandled)
2645
- return e.button !== 0 || !this.dragEls.find((t) => t === e.target) && e.target.closest(Bs) || this.option.cancel && e.target.closest(this.option.cancel) || (this.mouseDownEvent = e, delete this.dragging, delete w.dragElement, delete w.dropElement, document.addEventListener("mousemove", this._mouseMove, { capture: !0, passive: !0 }), document.addEventListener("mouseup", this._mouseUp, !0), le && (e.currentTarget.addEventListener("touchmove", Qe), e.currentTarget.addEventListener("touchend", Ve)), e.preventDefault(), document.activeElement && document.activeElement.blur(), w.mouseHandled = !0), !0;
2646
- }
2647
- /** @internal method to call actual drag event */
2648
- _callDrag(e) {
2649
- if (!this.dragging)
2650
- return;
2651
- const t = c.initEvent(e, { target: this.el, type: "drag" });
2652
- this.option.drag && this.option.drag(t, this.ui()), this.triggerEvent("drag", t);
2653
- }
2654
- /** @internal called when the main page (after successful mousedown) receives a move event to drag the item around the screen */
2655
- _mouseMove(e) {
2656
- var i;
2657
- const t = this.mouseDownEvent;
2658
- if (this.lastDrag = e, this.dragging)
2659
- if (this._dragFollow(e), w.pauseDrag) {
2660
- const s = Number.isInteger(w.pauseDrag) ? w.pauseDrag : 100;
2661
- this.dragTimeout && window.clearTimeout(this.dragTimeout), this.dragTimeout = window.setTimeout(() => this._callDrag(e), s);
2662
- } else
2663
- this._callDrag(e);
2664
- else if (Math.abs(e.x - t.x) + Math.abs(e.y - t.y) > 3) {
2665
- this.dragging = !0, w.dragElement = this;
2666
- const s = (i = this.el.gridstackNode) == null ? void 0 : i.grid;
2667
- s ? w.dropElement = s.el.ddElement.ddDroppable : delete w.dropElement, this.helper = this._createHelper(), this._setupHelperContainmentStyle(), this.dragTransform = c.getValuesFromTransformedElement(this.helperContainment), this.dragOffset = this._getDragOffset(e, this.el, this.helperContainment), this._setupHelperStyle(e);
2668
- const r = c.initEvent(e, { target: this.el, type: "dragstart" });
2669
- this.option.start && this.option.start(r, this.ui()), this.triggerEvent("dragstart", r), document.addEventListener("keydown", this._keyEvent);
2670
- }
2671
- return !0;
2672
- }
2673
- /** @internal call when the mouse gets released to drop the item at current location */
2674
- _mouseUp(e) {
2675
- var t, i;
2676
- if (document.removeEventListener("mousemove", this._mouseMove, !0), document.removeEventListener("mouseup", this._mouseUp, !0), le && e.currentTarget && (e.currentTarget.removeEventListener("touchmove", Qe, !0), e.currentTarget.removeEventListener("touchend", Ve, !0)), this.dragging) {
2677
- delete this.dragging, (t = this.el.gridstackNode) == null || delete t._origRotate, document.removeEventListener("keydown", this._keyEvent), ((i = w.dropElement) == null ? void 0 : i.el) === this.el.parentElement && delete w.dropElement, this.helperContainment.style.position = this.parentOriginStylePosition || null, this.helper !== this.el && this.helper.remove(), this._removeHelperStyle();
2678
- const s = c.initEvent(e, { target: this.el, type: "dragstop" });
2679
- this.option.stop && this.option.stop(s), this.triggerEvent("dragstop", s), w.dropElement && w.dropElement.drop(e);
2680
- }
2681
- delete this.helper, delete this.mouseDownEvent, delete w.dragElement, delete w.dropElement, delete w.mouseHandled, e.preventDefault();
2682
- }
2683
- /** @internal call when keys are being pressed - use Esc to cancel, R to rotate */
2684
- _keyEvent(e) {
2685
- var s, r;
2686
- const t = this.el.gridstackNode, i = (t == null ? void 0 : t.grid) || ((r = (s = w.dropElement) == null ? void 0 : s.el) == null ? void 0 : r.gridstack);
2687
- if (e.key === "Escape")
2688
- t && t._origRotate && (t._orig = t._origRotate, delete t._origRotate), i == null || i.cancelDrag(), this._mouseUp(this.mouseDownEvent);
2689
- else if (t && i && (e.key === "r" || e.key === "R")) {
2690
- if (!c.canBeRotated(t))
2691
- return;
2692
- t._origRotate = t._origRotate || { ...t._orig }, delete t._moving, i.setAnimation(!1).rotate(t.el, { top: -this.dragOffset.offsetTop, left: -this.dragOffset.offsetLeft }).setAnimation(), t._moving = !0, this.dragOffset = this._getDragOffset(this.lastDrag, t.el, this.helperContainment), this.helper.style.width = this.dragOffset.width + "px", this.helper.style.height = this.dragOffset.height + "px", c.swap(t._orig, "w", "h"), delete t._rect, this._mouseMove(this.lastDrag);
2693
- }
2694
- }
2695
- /** @internal create a clone copy (or user defined method) of the original drag item if set */
2696
- _createHelper() {
2697
- let e = this.el;
2698
- return typeof this.option.helper == "function" ? e = this.option.helper(this.el) : this.option.helper === "clone" && (e = c.cloneNode(this.el)), e.parentElement || c.appendTo(e, this.option.appendTo === "parent" ? this.el.parentElement : this.option.appendTo), this.dragElementOriginStyle = Ae.originStyleProp.map((t) => this.el.style[t]), e;
2699
- }
2700
- /** @internal set the fix position of the dragged item */
2701
- _setupHelperStyle(e) {
2702
- this.helper.classList.add("ui-draggable-dragging");
2703
- const t = this.helper.style;
2704
- return t.pointerEvents = "none", t.width = this.dragOffset.width + "px", t.height = this.dragOffset.height + "px", t.willChange = "left, top", t.position = "fixed", this._dragFollow(e), t.transition = "none", setTimeout(() => {
2705
- this.helper && (t.transition = null);
2706
- }, 0), this;
2707
- }
2708
- /** @internal restore back the original style before dragging */
2709
- _removeHelperStyle() {
2710
- var t;
2711
- this.helper.classList.remove("ui-draggable-dragging");
2712
- const e = (t = this.helper) == null ? void 0 : t.gridstackNode;
2713
- if (!(e != null && e._isAboutToRemove) && this.dragElementOriginStyle) {
2714
- const i = this.helper, s = this.dragElementOriginStyle.transition || null;
2715
- i.style.transition = this.dragElementOriginStyle.transition = "none", Ae.originStyleProp.forEach((r) => i.style[r] = this.dragElementOriginStyle[r] || null), setTimeout(() => i.style.transition = s, 50);
2716
- }
2717
- return delete this.dragElementOriginStyle, this;
2718
- }
2719
- /** @internal updates the top/left position to follow the mouse */
2720
- _dragFollow(e) {
2721
- const t = { left: 0, top: 0 }, i = this.helper.style, s = this.dragOffset;
2722
- i.left = (e.clientX + s.offsetLeft - t.left) * this.dragTransform.xScale + "px", i.top = (e.clientY + s.offsetTop - t.top) * this.dragTransform.yScale + "px";
2723
- }
2724
- /** @internal */
2725
- _setupHelperContainmentStyle() {
2726
- return this.helperContainment = this.helper.parentElement, this.helper.style.position !== "fixed" && (this.parentOriginStylePosition = this.helperContainment.style.position, getComputedStyle(this.helperContainment).position.match(/static/) && (this.helperContainment.style.position = "relative")), this;
2727
- }
2728
- /** @internal */
2729
- _getDragOffset(e, t, i) {
2730
- let s = 0, r = 0;
2731
- i && (s = this.dragTransform.xOffset, r = this.dragTransform.yOffset);
2732
- const o = t.getBoundingClientRect();
2733
- return {
2734
- left: o.left,
2735
- top: o.top,
2736
- offsetLeft: -e.clientX + o.left - s,
2737
- offsetTop: -e.clientY + o.top - r,
2738
- width: o.width * this.dragTransform.xScale,
2739
- height: o.height * this.dragTransform.yScale
2740
- };
2741
- }
2742
- /** @internal TODO: set to public as called by DDDroppable! */
2743
- ui() {
2744
- const t = this.el.parentElement.getBoundingClientRect(), i = this.helper.getBoundingClientRect();
2745
- return {
2746
- position: {
2747
- top: (i.top - t.top) * this.dragTransform.yScale,
2748
- left: (i.left - t.left) * this.dragTransform.xScale
2749
- }
2750
- /* not used by GridStack for now...
2751
- helper: [this.helper], //The object arr representing the helper that's being dragged.
2752
- offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.
2753
- */
2754
- };
2755
- }
2756
- }
2757
- Ae.originStyleProp = ["width", "height", "transform", "transform-origin", "transition", "pointerEvents", "position", "left", "top", "minWidth", "willChange"];
2758
- class Fs extends mt {
2759
- constructor(e, t = {}) {
2760
- super(), this.el = e, this.option = t, this._mouseEnter = this._mouseEnter.bind(this), this._mouseLeave = this._mouseLeave.bind(this), this.enable(), this._setupAccept();
2761
- }
2762
- on(e, t) {
2763
- super.on(e, t);
2764
- }
2765
- off(e) {
2766
- super.off(e);
2767
- }
2768
- enable() {
2769
- this.disabled !== !1 && (super.enable(), this.el.classList.add("ui-droppable"), this.el.classList.remove("ui-droppable-disabled"), this.el.addEventListener("mouseenter", this._mouseEnter), this.el.addEventListener("mouseleave", this._mouseLeave), le && (this.el.addEventListener("pointerenter", Lt), this.el.addEventListener("pointerleave", At)));
2770
- }
2771
- disable(e = !1) {
2772
- this.disabled !== !0 && (super.disable(), this.el.classList.remove("ui-droppable"), e || this.el.classList.add("ui-droppable-disabled"), this.el.removeEventListener("mouseenter", this._mouseEnter), this.el.removeEventListener("mouseleave", this._mouseLeave), le && (this.el.removeEventListener("pointerenter", Lt), this.el.removeEventListener("pointerleave", At)));
2773
- }
2774
- destroy() {
2775
- this.disable(!0), this.el.classList.remove("ui-droppable"), this.el.classList.remove("ui-droppable-disabled"), super.destroy();
2776
- }
2777
- updateOption(e) {
2778
- return Object.keys(e).forEach((t) => this.option[t] = e[t]), this._setupAccept(), this;
2779
- }
2780
- /** @internal called when the cursor enters our area - prepare for a possible drop and track leaving */
2781
- _mouseEnter(e) {
2782
- if (!w.dragElement || !this._canDrop(w.dragElement.el))
2783
- return;
2784
- e.preventDefault(), e.stopPropagation(), w.dropElement && w.dropElement !== this && w.dropElement._mouseLeave(e, !0), w.dropElement = this;
2785
- const t = c.initEvent(e, { target: this.el, type: "dropover" });
2786
- this.option.over && this.option.over(t, this._ui(w.dragElement)), this.triggerEvent("dropover", t), this.el.classList.add("ui-droppable-over");
2787
- }
2788
- /** @internal called when the item is leaving our area, stop tracking if we had moving item */
2789
- _mouseLeave(e, t = !1) {
2790
- var s;
2791
- if (!w.dragElement || w.dropElement !== this)
2792
- return;
2793
- e.preventDefault(), e.stopPropagation();
2794
- const i = c.initEvent(e, { target: this.el, type: "dropout" });
2795
- if (this.option.out && this.option.out(i, this._ui(w.dragElement)), this.triggerEvent("dropout", i), w.dropElement === this && (delete w.dropElement, !t)) {
2796
- let r, o = this.el.parentElement;
2797
- for (; !r && o; )
2798
- r = (s = o.ddElement) == null ? void 0 : s.ddDroppable, o = o.parentElement;
2799
- r && r._mouseEnter(e);
2800
- }
2801
- }
2802
- /** item is being dropped on us - called by the drag mouseup handler - this calls the client drop event */
2803
- drop(e) {
2804
- e.preventDefault();
2805
- const t = c.initEvent(e, { target: this.el, type: "drop" });
2806
- this.option.drop && this.option.drop(t, this._ui(w.dragElement)), this.triggerEvent("drop", t);
2807
- }
2808
- /** @internal true if element matches the string/method accept option */
2809
- _canDrop(e) {
2810
- return e && (!this.accept || this.accept(e));
2811
- }
2812
- /** @internal */
2813
- _setupAccept() {
2814
- return this.option.accept ? (typeof this.option.accept == "string" ? this.accept = (e) => e.classList.contains(this.option.accept) || e.matches(this.option.accept) : this.accept = this.option.accept, this) : this;
2815
- }
2816
- /** @internal */
2817
- _ui(e) {
2818
- return {
2819
- draggable: e.el,
2820
- ...e.ui()
2821
- };
2822
- }
2823
- }
2824
- class pt {
2825
- static init(e) {
2826
- return e.ddElement || (e.ddElement = new pt(e)), e.ddElement;
2827
- }
2828
- constructor(e) {
2829
- this.el = e;
2830
- }
2831
- on(e, t) {
2832
- return this.ddDraggable && ["drag", "dragstart", "dragstop"].indexOf(e) > -1 ? this.ddDraggable.on(e, t) : this.ddDroppable && ["drop", "dropover", "dropout"].indexOf(e) > -1 ? this.ddDroppable.on(e, t) : this.ddResizable && ["resizestart", "resize", "resizestop"].indexOf(e) > -1 && this.ddResizable.on(e, t), this;
2833
- }
2834
- off(e) {
2835
- return this.ddDraggable && ["drag", "dragstart", "dragstop"].indexOf(e) > -1 ? this.ddDraggable.off(e) : this.ddDroppable && ["drop", "dropover", "dropout"].indexOf(e) > -1 ? this.ddDroppable.off(e) : this.ddResizable && ["resizestart", "resize", "resizestop"].indexOf(e) > -1 && this.ddResizable.off(e), this;
2836
- }
2837
- setupDraggable(e) {
2838
- return this.ddDraggable ? this.ddDraggable.updateOption(e) : this.ddDraggable = new Ae(this.el, e), this;
2839
- }
2840
- cleanDraggable() {
2841
- return this.ddDraggable && (this.ddDraggable.destroy(), delete this.ddDraggable), this;
2842
- }
2843
- setupResizable(e) {
2844
- return this.ddResizable ? this.ddResizable.updateOption(e) : this.ddResizable = new Le(this.el, e), this;
2845
- }
2846
- cleanResizable() {
2847
- return this.ddResizable && (this.ddResizable.destroy(), delete this.ddResizable), this;
2848
- }
2849
- setupDroppable(e) {
2850
- return this.ddDroppable ? this.ddDroppable.updateOption(e) : this.ddDroppable = new Fs(this.el, e), this;
2851
- }
2852
- cleanDroppable() {
2853
- return this.ddDroppable && (this.ddDroppable.destroy(), delete this.ddDroppable), this;
2854
- }
2855
- }
2856
- class Us {
2857
- resizable(e, t, i, s) {
2858
- return this._getDDElements(e, t).forEach((r) => {
2859
- if (t === "disable" || t === "enable")
2860
- r.ddResizable && r.ddResizable[t]();
2861
- else if (t === "destroy")
2862
- r.ddResizable && r.cleanResizable();
2863
- else if (t === "option")
2864
- r.setupResizable({ [i]: s });
2865
- else {
2866
- const n = r.el.gridstackNode.grid;
2867
- let d = r.el.getAttribute("gs-resize-handles") || n.opts.resizable.handles || "e,s,se";
2868
- d === "all" && (d = "n,e,s,w,se,sw,ne,nw");
2869
- const u = !n.opts.alwaysShowResizeHandle;
2870
- r.setupResizable({
2871
- ...n.opts.resizable,
2872
- handles: d,
2873
- autoHide: u,
2874
- start: t.start,
2875
- stop: t.stop,
2876
- resize: t.resize
2877
- });
2878
- }
2879
- }), this;
2880
- }
2881
- draggable(e, t, i, s) {
2882
- return this._getDDElements(e, t).forEach((r) => {
2883
- if (t === "disable" || t === "enable")
2884
- r.ddDraggable && r.ddDraggable[t]();
2885
- else if (t === "destroy")
2886
- r.ddDraggable && r.cleanDraggable();
2887
- else if (t === "option")
2888
- r.setupDraggable({ [i]: s });
2889
- else {
2890
- const o = r.el.gridstackNode.grid;
2891
- r.setupDraggable({
2892
- ...o.opts.draggable,
2893
- // containment: (grid.parentGridNode && grid.opts.dragOut === false) ? grid.el.parentElement : (grid.opts.draggable.containment || null),
2894
- start: t.start,
2895
- stop: t.stop,
2896
- drag: t.drag
2897
- });
2898
- }
2899
- }), this;
2900
- }
2901
- dragIn(e, t) {
2902
- return this._getDDElements(e).forEach((i) => i.setupDraggable(t)), this;
2903
- }
2904
- droppable(e, t, i, s) {
2905
- return typeof t.accept == "function" && !t._accept && (t._accept = t.accept, t.accept = (r) => t._accept(r)), this._getDDElements(e, t).forEach((r) => {
2906
- t === "disable" || t === "enable" ? r.ddDroppable && r.ddDroppable[t]() : t === "destroy" ? r.ddDroppable && r.cleanDroppable() : t === "option" ? r.setupDroppable({ [i]: s }) : r.setupDroppable(t);
2907
- }), this;
2908
- }
2909
- /** true if element is droppable */
2910
- isDroppable(e) {
2911
- var t;
2912
- return !!((t = e == null ? void 0 : e.ddElement) != null && t.ddDroppable && !e.ddElement.ddDroppable.disabled);
2913
- }
2914
- /** true if element is draggable */
2915
- isDraggable(e) {
2916
- var t;
2917
- return !!((t = e == null ? void 0 : e.ddElement) != null && t.ddDraggable && !e.ddElement.ddDraggable.disabled);
2918
- }
2919
- /** true if element is draggable */
2920
- isResizable(e) {
2921
- var t;
2922
- return !!((t = e == null ? void 0 : e.ddElement) != null && t.ddResizable && !e.ddElement.ddResizable.disabled);
2923
- }
2924
- on(e, t, i) {
2925
- return this._getDDElements(e).forEach((s) => s.on(t, (r) => {
2926
- i(r, w.dragElement ? w.dragElement.el : r.target, w.dragElement ? w.dragElement.helper : null);
2927
- })), this;
2928
- }
2929
- off(e, t) {
2930
- return this._getDDElements(e).forEach((i) => i.off(t)), this;
2931
- }
2932
- /** @internal returns a list of DD elements, creating them on the fly by default unless option is to destroy or disable */
2933
- _getDDElements(e, t) {
2934
- const i = e.gridstack || t !== "destroy" && t !== "disable", s = c.getElements(e);
2935
- return s.length ? s.map((o) => o.ddElement || (i ? pt.init(o) : null)).filter((o) => o) : [];
2936
- }
2937
- }
2938
- /*!
2939
- * GridStack 11.5.1
2940
- * https://gridstackjs.com/
2941
- *
2942
- * Copyright (c) 2021-2024 Alain Dumesny
2943
- * see root license https://github.com/gridstack/gridstack.js/tree/master/LICENSE
2944
- */
2945
- const W = new Us();
2946
- class _ {
2947
- /**
2948
- * initializing the HTML element, or selector string, into a grid will return the grid. Calling it again will
2949
- * simply return the existing instance (ignore any passed options). There is also an initAll() version that support
2950
- * multiple grids initialization at once. Or you can use addGrid() to create the entire grid from JSON.
2951
- * @param options grid options (optional)
2952
- * @param elOrString element or CSS selector (first one used) to convert to a grid (default to '.grid-stack' class selector)
2953
- *
2954
- * @example
2955
- * const grid = GridStack.init();
2956
- *
2957
- * Note: the HTMLElement (of type GridHTMLElement) will store a `gridstack: GridStack` value that can be retrieve later
2958
- * const grid = document.querySelector('.grid-stack').gridstack;
2959
- */
2960
- static init(e = {}, t = ".grid-stack") {
2961
- if (typeof document > "u")
2962
- return null;
2963
- const i = _.getGridElement(t);
2964
- return i ? (i.gridstack || (i.gridstack = new _(i, c.cloneDeep(e))), i.gridstack) : (console.error(typeof t == "string" ? 'GridStack.initAll() no grid was found with selector "' + t + `" - element missing or wrong selector ?
2965
- Note: ".grid-stack" is required for proper CSS styling and drag/drop, and is the default selector.` : "GridStack.init() no grid element was passed."), null);
2966
- }
2967
- /**
2968
- * Will initialize a list of elements (given a selector) and return an array of grids.
2969
- * @param options grid options (optional)
2970
- * @param selector elements selector to convert to grids (default to '.grid-stack' class selector)
2971
- *
2972
- * @example
2973
- * const grids = GridStack.initAll();
2974
- * grids.forEach(...)
2975
- */
2976
- static initAll(e = {}, t = ".grid-stack") {
2977
- const i = [];
2978
- return typeof document > "u" || (_.getGridElements(t).forEach((s) => {
2979
- s.gridstack || (s.gridstack = new _(s, c.cloneDeep(e))), i.push(s.gridstack);
2980
- }), i.length === 0 && console.error('GridStack.initAll() no grid was found with selector "' + t + `" - element missing or wrong selector ?
2981
- Note: ".grid-stack" is required for proper CSS styling and drag/drop, and is the default selector.`)), i;
2982
- }
2983
- /**
2984
- * call to create a grid with the given options, including loading any children from JSON structure. This will call GridStack.init(), then
2985
- * grid.load() on any passed children (recursively). Great alternative to calling init() if you want entire grid to come from
2986
- * JSON serialized data, including options.
2987
- * @param parent HTML element parent to the grid
2988
- * @param opt grids options used to initialize the grid, and list of children
2989
- */
2990
- static addGrid(e, t = {}) {
2991
- if (!e)
2992
- return null;
2993
- let i = e;
2994
- if (i.gridstack) {
2995
- const o = i.gridstack;
2996
- return t && (o.opts = { ...o.opts, ...t }), t.children !== void 0 && o.load(t.children), o;
2997
- }
2998
- return (!e.classList.contains("grid-stack") || _.addRemoveCB) && (_.addRemoveCB ? i = _.addRemoveCB(e, t, !0, !0) : i = c.createDiv(["grid-stack", t.class], e)), _.init(t, i);
2999
- }
3000
- /** call this method to register your engine instead of the default one.
3001
- * See instead `GridStackOptions.engineClass` if you only need to
3002
- * replace just one instance.
3003
- */
3004
- static registerEngine(e) {
3005
- _.engineClass = e;
3006
- }
3007
- /** @internal create placeholder DIV as needed */
3008
- get placeholder() {
3009
- if (!this._placeholder) {
3010
- this._placeholder = c.createDiv([this.opts.placeholderClass, Z.itemClass, this.opts.itemClass]);
3011
- const e = c.createDiv(["placeholder-content"], this._placeholder);
3012
- this.opts.placeholderText && (e.textContent = this.opts.placeholderText);
3013
- }
3014
- return this._placeholder;
3015
- }
3016
- /**
3017
- * Construct a grid item from the given element and options
3018
- * @param el the HTML element tied to this grid after it's been initialized
3019
- * @param opts grid options - public for classes to access, but use methods to modify!
3020
- */
3021
- constructor(e, t = {}) {
3022
- var l, f, g;
3023
- this.el = e, this.opts = t, this.animationDelay = 310, this._gsEventHandler = {}, this._extraDragRow = 0, this.dragTransform = { xScale: 1, yScale: 1, xOffset: 0, yOffset: 0 }, e.gridstack = this, this.opts = t = t || {}, e.classList.contains("grid-stack") || this.el.classList.add("grid-stack"), t.row && (t.minRow = t.maxRow = t.row, delete t.row);
3024
- const i = c.toNumber(e.getAttribute("gs-row"));
3025
- t.column === "auto" && delete t.column, t.alwaysShowResizeHandle !== void 0 && (t._alwaysShowResizeHandle = t.alwaysShowResizeHandle);
3026
- let s = (l = t.columnOpts) == null ? void 0 : l.breakpoints;
3027
- const r = t;
3028
- if (r.oneColumnModeDomSort && (delete r.oneColumnModeDomSort, console.log("warning: Gridstack oneColumnModeDomSort no longer supported. Use GridStackOptions.columnOpts instead.")), r.oneColumnSize || r.disableOneColumnMode === !1) {
3029
- const p = r.oneColumnSize || 768;
3030
- delete r.oneColumnSize, delete r.disableOneColumnMode, t.columnOpts = t.columnOpts || {}, s = t.columnOpts.breakpoints = t.columnOpts.breakpoints || [];
3031
- let y = s.find((m) => m.c === 1);
3032
- y ? y.w = p : (y = { c: 1, w: p }, s.push(y, { c: 12, w: p + 1 }));
3033
- }
3034
- const o = t.columnOpts;
3035
- o && (!o.columnWidth && !((f = o.breakpoints) != null && f.length) ? (delete t.columnOpts, s = void 0) : o.columnMax = o.columnMax || 12), (s == null ? void 0 : s.length) > 1 && s.sort((p, y) => (y.w || 0) - (p.w || 0));
3036
- const n = {
3037
- ...c.cloneDeep(Z),
3038
- column: c.toNumber(e.getAttribute("gs-column")) || Z.column,
3039
- minRow: i || c.toNumber(e.getAttribute("gs-min-row")) || Z.minRow,
3040
- maxRow: i || c.toNumber(e.getAttribute("gs-max-row")) || Z.maxRow,
3041
- staticGrid: c.toBool(e.getAttribute("gs-static")) || Z.staticGrid,
3042
- sizeToContent: c.toBool(e.getAttribute("gs-size-to-content")) || void 0,
3043
- draggable: {
3044
- handle: (t.handleClass ? "." + t.handleClass : t.handle ? t.handle : "") || Z.draggable.handle
3045
- },
3046
- removableOptions: {
3047
- accept: t.itemClass || Z.removableOptions.accept,
3048
- decline: Z.removableOptions.decline
3049
- }
3050
- };
3051
- e.getAttribute("gs-animate") && (n.animate = c.toBool(e.getAttribute("gs-animate"))), t = c.defaults(t, n), this._initMargin(), this.checkDynamicColumn(), this.el.classList.add("gs-" + t.column), t.rtl === "auto" && (t.rtl = e.style.direction === "rtl"), t.rtl && this.el.classList.add("grid-stack-rtl");
3052
- const d = this.el.closest("." + Z.itemClass), u = d == null ? void 0 : d.gridstackNode;
3053
- u && (u.subGrid = this, this.parentGridNode = u, this.el.classList.add("grid-stack-nested"), u.el.classList.add("grid-stack-sub-grid")), this._isAutoCellHeight = t.cellHeight === "auto", this._isAutoCellHeight || t.cellHeight === "initial" ? this.cellHeight(void 0, !1) : (typeof t.cellHeight == "number" && t.cellHeightUnit && t.cellHeightUnit !== Z.cellHeightUnit && (t.cellHeight = t.cellHeight + t.cellHeightUnit, delete t.cellHeightUnit), this.cellHeight(t.cellHeight, !1)), t.alwaysShowResizeHandle === "mobile" && (t.alwaysShowResizeHandle = le), this._styleSheetClass = "gs-id-" + he._idSeq++, this.el.classList.add(this._styleSheetClass), this._setStaticClass();
3054
- const h = t.engineClass || _.engineClass || he;
3055
- if (this.engine = new h({
3056
- column: this.getColumn(),
3057
- float: t.float,
3058
- maxRow: t.maxRow,
3059
- onChange: (p) => {
3060
- let y = 0;
3061
- this.engine.nodes.forEach((m) => {
3062
- y = Math.max(y, m.y + m.h);
3063
- }), p.forEach((m) => {
3064
- const C = m.el;
3065
- C && (m._removeDOM ? (C && C.remove(), delete m._removeDOM) : this._writePosAttr(C, m));
3066
- }), this._updateStyles(!1, y);
3067
- }
3068
- }), this._updateStyles(!1, 0), t.auto && (this.batchUpdate(), this.engine._loading = !0, this.getGridItems().forEach((p) => this._prepareElement(p)), delete this.engine._loading, this.batchUpdate(!1)), t.children) {
3069
- const p = t.children;
3070
- delete t.children, p.length && this.load(p);
3071
- }
3072
- this.setAnimation(), t.subGridDynamic && !w.pauseDrag && (w.pauseDrag = !0), ((g = t.draggable) == null ? void 0 : g.pause) !== void 0 && (w.pauseDrag = t.draggable.pause), this._setupRemoveDrop(), this._setupAcceptWidget(), this._updateResizeEvent();
3073
- }
3074
- /**
3075
- * add a new widget and returns it.
3076
- *
3077
- * Widget will be always placed even if result height is more than actual grid height.
3078
- * You need to use `willItFit()` before calling addWidget for additional check.
3079
- * See also `makeWidget(el)` for DOM element.
3080
- *
3081
- * @example
3082
- * const grid = GridStack.init();
3083
- * grid.addWidget({w: 3, content: 'hello'});
3084
- *
3085
- * @param w GridStackWidget definition. used MakeWidget(el) if you have dom element instead.
3086
- */
3087
- addWidget(e) {
3088
- if (typeof e == "string") {
3089
- console.error("V11: GridStack.addWidget() does not support string anymore. see #2736");
3090
- return;
3091
- }
3092
- if (e.ELEMENT_NODE)
3093
- return console.error("V11: GridStack.addWidget() does not support HTMLElement anymore. use makeWidget()"), this.makeWidget(e);
3094
- let t, i = e;
3095
- if (i.grid = this, i != null && i.el ? t = i.el : _.addRemoveCB ? t = _.addRemoveCB(this.el, e, !0, !1) : t = this.createWidgetDivs(i), !t)
3096
- return;
3097
- if (i = t.gridstackNode, i && t.parentElement === this.el && this.engine.nodes.find((r) => r._id === i._id))
3098
- return t;
3099
- const s = this._readAttr(t);
3100
- return c.defaults(e, s), this.engine.prepareNode(e), this.el.appendChild(t), this.makeWidget(t, e), t;
3101
- }
3102
- /** create the default grid item divs, and content (possibly lazy loaded) by using GridStack.renderCB() */
3103
- createWidgetDivs(e) {
3104
- const t = c.createDiv(["grid-stack-item", this.opts.itemClass]), i = c.createDiv(["grid-stack-item-content"], t);
3105
- return c.lazyLoad(e) ? e.visibleObservable || (e.visibleObservable = new IntersectionObserver(([s]) => {
3106
- var r, o;
3107
- s.isIntersecting && ((r = e.visibleObservable) == null || r.disconnect(), delete e.visibleObservable, _.renderCB(i, e), (o = e.grid) == null || o.prepareDragDrop(e.el));
3108
- }), window.setTimeout(() => {
3109
- var s;
3110
- return (s = e.visibleObservable) == null ? void 0 : s.observe(t);
3111
- })) : _.renderCB(i, e), t;
3112
- }
3113
- /**
3114
- * Convert an existing gridItem element into a sub-grid with the given (optional) options, else inherit them
3115
- * from the parent's subGrid options.
3116
- * @param el gridItem element to convert
3117
- * @param ops (optional) sub-grid options, else default to node, then parent settings, else defaults
3118
- * @param nodeToAdd (optional) node to add to the newly created sub grid (used when dragging over existing regular item)
3119
- * @param saveContent if true (default) the html inside .grid-stack-content will be saved to child widget
3120
- * @returns newly created grid
3121
- */
3122
- makeSubGrid(e, t, i, s = !0) {
3123
- var g, p, y;
3124
- let r = e.gridstackNode;
3125
- if (r || (r = this.makeWidget(e).gridstackNode), (g = r.subGrid) != null && g.el)
3126
- return r.subGrid;
3127
- let o, n = this;
3128
- for (; n && !o; )
3129
- o = (p = n.opts) == null ? void 0 : p.subGridOpts, n = (y = n.parentGridNode) == null ? void 0 : y.grid;
3130
- t = c.cloneDeep({
3131
- // by default sub-grid inherit from us | parent, other than id, children, etc...
3132
- ...this.opts,
3133
- id: void 0,
3134
- children: void 0,
3135
- column: "auto",
3136
- columnOpts: void 0,
3137
- layout: "list",
3138
- subGridOpts: void 0,
3139
- ...o || {},
3140
- ...t || r.subGridOpts || {}
3141
- }), r.subGridOpts = t;
3142
- let d;
3143
- t.column === "auto" && (d = !0, t.column = Math.max(r.w || 1, (i == null ? void 0 : i.w) || 1), delete t.columnOpts);
3144
- let u = r.el.querySelector(".grid-stack-item-content"), h, l;
3145
- if (s && (this._removeDD(r.el), l = { ...r, x: 0, y: 0 }, c.removeInternalForSave(l), delete l.subGridOpts, r.content && (l.content = r.content, delete r.content), _.addRemoveCB ? h = _.addRemoveCB(this.el, l, !0, !1) : (h = c.createDiv(["grid-stack-item"]), h.appendChild(u), u = c.createDiv(["grid-stack-item-content"], r.el)), this.prepareDragDrop(r.el)), i) {
3146
- const m = d ? t.column : r.w, C = r.h + i.h, A = r.el.style;
3147
- A.transition = "none", this.update(r.el, { w: m, h: C }), setTimeout(() => A.transition = null);
3148
- }
3149
- const f = r.subGrid = _.addGrid(u, t);
3150
- return i != null && i._moving && (f._isTemp = !0), d && (f._autoColumn = !0), s && f.makeWidget(h, l), i && (i._moving ? window.setTimeout(() => c.simulateMouseEvent(i._event, "mouseenter", f.el), 0) : f.makeWidget(r.el, r)), this.resizeToContentCheck(!1, r), f;
3151
- }
3152
- /**
3153
- * called when an item was converted into a nested grid to accommodate a dragged over item, but then item leaves - return back
3154
- * to the original grid-item. Also called to remove empty sub-grids when last item is dragged out (since re-creating is simple)
3155
- */
3156
- removeAsSubGrid(e) {
3157
- var i;
3158
- const t = (i = this.parentGridNode) == null ? void 0 : i.grid;
3159
- t && (t.batchUpdate(), t.removeWidget(this.parentGridNode.el, !0, !0), this.engine.nodes.forEach((s) => {
3160
- s.x += this.parentGridNode.x, s.y += this.parentGridNode.y, t.makeWidget(s.el, s);
3161
- }), t.batchUpdate(!1), this.parentGridNode && delete this.parentGridNode.subGrid, delete this.parentGridNode, e && window.setTimeout(() => c.simulateMouseEvent(e._event, "mouseenter", t.el), 0));
3162
- }
3163
- /**
3164
- * saves the current layout returning a list of widgets for serialization which might include any nested grids.
3165
- * @param saveContent if true (default) the latest html inside .grid-stack-content will be saved to GridStackWidget.content field, else it will
3166
- * be removed.
3167
- * @param saveGridOpt if true (default false), save the grid options itself, so you can call the new GridStack.addGrid()
3168
- * to recreate everything from scratch. GridStackOptions.children would then contain the widget list instead.
3169
- * @param saveCB callback for each node -> widget, so application can insert additional data to be saved into the widget data structure.
3170
- * @returns list of widgets or full grid option, including .children list of widgets
3171
- */
3172
- save(e = !0, t = !1, i = _.saveCB) {
3173
- const s = this.engine.save(e, i);
3174
- if (s.forEach((r) => {
3175
- var o;
3176
- if (e && r.el && !r.subGrid && !i) {
3177
- const n = r.el.querySelector(".grid-stack-item-content");
3178
- r.content = n == null ? void 0 : n.innerHTML, r.content || delete r.content;
3179
- } else if (!e && !i && delete r.content, (o = r.subGrid) != null && o.el) {
3180
- const n = r.subGrid.save(e, t, i);
3181
- r.subGridOpts = t ? n : { children: n }, delete r.subGrid;
3182
- }
3183
- delete r.el;
3184
- }), t) {
3185
- const r = c.cloneDeep(this.opts);
3186
- r.marginBottom === r.marginTop && r.marginRight === r.marginLeft && r.marginTop === r.marginRight && (r.margin = r.marginTop, delete r.marginTop, delete r.marginRight, delete r.marginBottom, delete r.marginLeft), r.rtl === (this.el.style.direction === "rtl") && (r.rtl = "auto"), this._isAutoCellHeight && (r.cellHeight = "auto"), this._autoColumn && (r.column = "auto");
3187
- const o = r._alwaysShowResizeHandle;
3188
- return delete r._alwaysShowResizeHandle, o !== void 0 ? r.alwaysShowResizeHandle = o : delete r.alwaysShowResizeHandle, c.removeInternalAndSame(r, Z), r.children = s, r;
3189
- }
3190
- return s;
3191
- }
3192
- /**
3193
- * load the widgets from a list. This will call update() on each (matching by id) or add/remove widgets that are not there.
3194
- *
3195
- * @param items list of widgets definition to update/create
3196
- * @param addRemove boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving
3197
- * the user control of insertion.
3198
- *
3199
- * @example
3200
- * see http://gridstackjs.com/demo/serialization.html
3201
- */
3202
- load(e, t = _.addRemoveCB || !0) {
3203
- var u;
3204
- e = c.cloneDeep(e);
3205
- const i = this.getColumn();
3206
- e.forEach((h) => {
3207
- h.w = h.w || 1, h.h = h.h || 1;
3208
- }), e = c.sort(e), this.engine.skipCacheUpdate = this._ignoreLayoutsNodeChange = !0;
3209
- let s = 0;
3210
- e.forEach((h) => {
3211
- s = Math.max(s, (h.x || 0) + h.w);
3212
- }), s > this.engine.defaultColumn && (this.engine.defaultColumn = s), s > i && this.engine.cacheLayout(e, s, !0);
3213
- const r = _.addRemoveCB;
3214
- typeof t == "function" && (_.addRemoveCB = t);
3215
- const o = [];
3216
- this.batchUpdate();
3217
- const n = !this.engine.nodes.length;
3218
- n && this.setAnimation(!1), !n && t && [...this.engine.nodes].forEach((l) => {
3219
- if (!l.id)
3220
- return;
3221
- c.find(e, l.id) || (_.addRemoveCB && _.addRemoveCB(this.el, l, !1, !1), o.push(l), this.removeWidget(l.el, !0, !1));
3222
- }), this.engine._loading = !0;
3223
- const d = [];
3224
- return this.engine.nodes = this.engine.nodes.filter((h) => c.find(e, h.id) ? (d.push(h), !1) : !0), e.forEach((h) => {
3225
- var f;
3226
- const l = c.find(d, h.id);
3227
- if (l) {
3228
- if (c.shouldSizeToContent(l) && (h.h = l.h), this.engine.nodeBoundFix(h), (h.autoPosition || h.x === void 0 || h.y === void 0) && (h.w = h.w || l.w, h.h = h.h || l.h, this.engine.findEmptyPosition(h)), this.engine.nodes.push(l), c.samePos(l, h) && this.engine.nodes.length > 1 && (this.moveNode(l, { ...h, forceCollide: !0 }), c.copyPos(h, l)), this.update(l.el, h), (f = h.subGridOpts) != null && f.children) {
3229
- const g = l.el.querySelector(".grid-stack");
3230
- g && g.gridstack && g.gridstack.load(h.subGridOpts.children);
3231
- }
3232
- } else t && this.addWidget(h);
3233
- }), delete this.engine._loading, this.engine.removedNodes = o, this.batchUpdate(!1), delete this._ignoreLayoutsNodeChange, delete this.engine.skipCacheUpdate, r ? _.addRemoveCB = r : delete _.addRemoveCB, n && ((u = this.opts) != null && u.animate) && this.setAnimation(this.opts.animate, !0), this;
3234
- }
3235
- /**
3236
- * use before calling a bunch of `addWidget()` to prevent un-necessary relayouts in between (more efficient)
3237
- * and get a single event callback. You will see no changes until `batchUpdate(false)` is called.
3238
- */
3239
- batchUpdate(e = !0) {
3240
- return this.engine.batchUpdate(e), e || (this._updateContainerHeight(), this._triggerRemoveEvent(), this._triggerAddEvent(), this._triggerChangeEvent()), this;
3241
- }
3242
- /**
3243
- * Gets current cell height.
3244
- */
3245
- getCellHeight(e = !1) {
3246
- if (this.opts.cellHeight && this.opts.cellHeight !== "auto" && (!e || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === "px"))
3247
- return this.opts.cellHeight;
3248
- if (this.opts.cellHeightUnit === "rem")
3249
- return this.opts.cellHeight * parseFloat(getComputedStyle(document.documentElement).fontSize);
3250
- if (this.opts.cellHeightUnit === "em")
3251
- return this.opts.cellHeight * parseFloat(getComputedStyle(this.el).fontSize);
3252
- if (this.opts.cellHeightUnit === "cm")
3253
- return this.opts.cellHeight * (96 / 2.54);
3254
- if (this.opts.cellHeightUnit === "mm")
3255
- return this.opts.cellHeight * (96 / 2.54) / 10;
3256
- const t = this.el.querySelector("." + this.opts.itemClass);
3257
- if (t) {
3258
- const s = c.toNumber(t.getAttribute("gs-h")) || 1;
3259
- return Math.round(t.offsetHeight / s);
3260
- }
3261
- const i = parseInt(this.el.getAttribute("gs-current-row"));
3262
- return i ? Math.round(this.el.getBoundingClientRect().height / i) : this.opts.cellHeight;
3263
- }
3264
- /**
3265
- * Update current cell height - see `GridStackOptions.cellHeight` for format.
3266
- * This method rebuilds an internal CSS style sheet.
3267
- * Note: You can expect performance issues if call this method too often.
3268
- *
3269
- * @param val the cell height. If not passed (undefined), cells content will be made square (match width minus margin),
3270
- * if pass 0 the CSS will be generated by the application instead.
3271
- * @param update (Optional) if false, styles will not be updated
3272
- *
3273
- * @example
3274
- * grid.cellHeight(100); // same as 100px
3275
- * grid.cellHeight('70px');
3276
- * grid.cellHeight(grid.cellWidth() * 1.2);
3277
- */
3278
- cellHeight(e, t = !0) {
3279
- if (t && e !== void 0 && this._isAutoCellHeight !== (e === "auto") && (this._isAutoCellHeight = e === "auto", this._updateResizeEvent()), (e === "initial" || e === "auto") && (e = void 0), e === void 0) {
3280
- const s = -this.opts.marginRight - this.opts.marginLeft + this.opts.marginTop + this.opts.marginBottom;
3281
- e = this.cellWidth() + s;
3282
- }
3283
- const i = c.parseHeight(e);
3284
- return this.opts.cellHeightUnit === i.unit && this.opts.cellHeight === i.h ? this : (this.opts.cellHeightUnit = i.unit, this.opts.cellHeight = i.h, this.resizeToContentCheck(), t && this._updateStyles(!0), this);
3285
- }
3286
- /** Gets current cell width. */
3287
- cellWidth() {
3288
- return this._widthOrContainer() / this.getColumn();
3289
- }
3290
- /** return our expected width (or parent) , and optionally of window for dynamic column check */
3291
- _widthOrContainer(e = !1) {
3292
- var t;
3293
- return e && ((t = this.opts.columnOpts) != null && t.breakpointForWindow) ? window.innerWidth : this.el.clientWidth || this.el.parentElement.clientWidth || window.innerWidth;
3294
- }
3295
- /** checks for dynamic column count for our current size, returning true if changed */
3296
- checkDynamicColumn() {
3297
- var r, o;
3298
- const e = this.opts.columnOpts;
3299
- if (!e || !e.columnWidth && !((r = e.breakpoints) != null && r.length))
3300
- return !1;
3301
- const t = this.getColumn();
3302
- let i = t;
3303
- const s = this._widthOrContainer(!0);
3304
- if (e.columnWidth)
3305
- i = Math.min(Math.round(s / e.columnWidth) || 1, e.columnMax);
3306
- else {
3307
- i = e.columnMax;
3308
- let n = 0;
3309
- for (; n < e.breakpoints.length && s <= e.breakpoints[n].w; )
3310
- i = e.breakpoints[n++].c || t;
3311
- }
3312
- if (i !== t) {
3313
- const n = (o = e.breakpoints) == null ? void 0 : o.find((d) => d.c === i);
3314
- return this.column(i, (n == null ? void 0 : n.layout) || e.layout), !0;
3315
- }
3316
- return !1;
3317
- }
3318
- /**
3319
- * re-layout grid items to reclaim any empty space. Options are:
3320
- * 'list' keep the widget left->right order the same, even if that means leaving an empty slot if things don't fit
3321
- * 'compact' might re-order items to fill any empty space
3322
- *
3323
- * doSort - 'false' to let you do your own sorting ahead in case you need to control a different order. (default to sort)
3324
- */
3325
- compact(e = "compact", t = !0) {
3326
- return this.engine.compact(e, t), this._triggerChangeEvent(), this;
3327
- }
3328
- /**
3329
- * set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
3330
- * as well as cache the original layout so you can revert back to previous positions without loss.
3331
- * Requires `gridstack-extra.css` or `gridstack-extra.min.css` for [2-11],
3332
- * else you will need to generate correct CSS (see https://github.com/gridstack/gridstack.js#change-grid-columns)
3333
- * @param column - Integer > 0 (default 12).
3334
- * @param layout specify the type of re-layout that will happen (position, size, etc...).
3335
- * Note: items will never be outside of the current column boundaries. default ('moveScale'). Ignored for 1 column
3336
- */
3337
- column(e, t = "moveScale") {
3338
- if (!e || e < 1 || this.opts.column === e)
3339
- return this;
3340
- const i = this.getColumn();
3341
- return this.opts.column = e, this.engine ? (this.engine.column = e, this.el.classList.remove("gs-" + i), this.el.classList.add("gs-" + e), this.engine.columnChanged(i, e, t), this._isAutoCellHeight && this.cellHeight(), this.resizeToContentCheck(!0), this._ignoreLayoutsNodeChange = !0, this._triggerChangeEvent(), delete this._ignoreLayoutsNodeChange, this) : this;
3342
- }
3343
- /**
3344
- * get the number of columns in the grid (default 12)
3345
- */
3346
- getColumn() {
3347
- return this.opts.column;
3348
- }
3349
- /** returns an array of grid HTML elements (no placeholder) - used to iterate through our children in DOM order */
3350
- getGridItems() {
3351
- return Array.from(this.el.children).filter((e) => e.matches("." + this.opts.itemClass) && !e.matches("." + this.opts.placeholderClass));
3352
- }
3353
- /** true if changeCB should be ignored due to column change, sizeToContent, loading, etc... which caller can ignore for dirty flag case */
3354
- isIgnoreChangeCB() {
3355
- return this._ignoreLayoutsNodeChange;
3356
- }
3357
- /**
3358
- * Destroys a grid instance. DO NOT CALL any methods or access any vars after this as it will free up members.
3359
- * @param removeDOM if `false` grid and items HTML elements will not be removed from the DOM (Optional. Default `true`).
3360
- */
3361
- destroy(e = !0) {
3362
- var t, i;
3363
- if (this.el)
3364
- return this.offAll(), this._updateResizeEvent(!0), this.setStatic(!0, !1), this.setAnimation(!1), e ? this.el.parentNode.removeChild(this.el) : (this.removeAll(e), this.el.classList.remove(this._styleSheetClass), this.el.removeAttribute("gs-current-row")), this._removeStylesheet(), (t = this.parentGridNode) == null || delete t.subGrid, delete this.parentGridNode, delete this.opts, (i = this._placeholder) == null || delete i.gridstackNode, delete this._placeholder, delete this.engine, delete this.el.gridstack, delete this.el, this;
3365
- }
3366
- /**
3367
- * enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
3368
- */
3369
- float(e) {
3370
- return this.opts.float !== e && (this.opts.float = this.engine.float = e, this._triggerChangeEvent()), this;
3371
- }
3372
- /**
3373
- * get the current float mode
3374
- */
3375
- getFloat() {
3376
- return this.engine.float;
3377
- }
3378
- /**
3379
- * Get the position of the cell under a pixel on screen.
3380
- * @param position the position of the pixel to resolve in
3381
- * absolute coordinates, as an object with top and left properties
3382
- * @param useDocRelative if true, value will be based on document position vs parent position (Optional. Default false).
3383
- * Useful when grid is within `position: relative` element
3384
- *
3385
- * Returns an object with properties `x` and `y` i.e. the column and row in the grid.
3386
- */
3387
- getCellFromPixel(e, t = !1) {
3388
- const i = this.el.getBoundingClientRect();
3389
- let s;
3390
- t ? s = { top: i.top + document.documentElement.scrollTop, left: i.left } : s = { top: this.el.offsetTop, left: this.el.offsetLeft };
3391
- const r = e.left - s.left, o = e.top - s.top, n = i.width / this.getColumn(), d = i.height / parseInt(this.el.getAttribute("gs-current-row"));
3392
- return { x: Math.floor(r / n), y: Math.floor(o / d) };
3393
- }
3394
- /** returns the current number of rows, which will be at least `minRow` if set */
3395
- getRow() {
3396
- return Math.max(this.engine.getRow(), this.opts.minRow);
3397
- }
3398
- /**
3399
- * Checks if specified area is empty.
3400
- * @param x the position x.
3401
- * @param y the position y.
3402
- * @param w the width of to check
3403
- * @param h the height of to check
3404
- */
3405
- isAreaEmpty(e, t, i, s) {
3406
- return this.engine.isAreaEmpty(e, t, i, s);
3407
- }
3408
- /**
3409
- * If you add elements to your grid by hand (or have some framework creating DOM), you have to tell gridstack afterwards to make them widgets.
3410
- * If you want gridstack to add the elements for you, use `addWidget()` instead.
3411
- * Makes the given element a widget and returns it.
3412
- * @param els widget or single selector to convert.
3413
- * @param options widget definition to use instead of reading attributes or using default sizing values
3414
- *
3415
- * @example
3416
- * const grid = GridStack.init();
3417
- * grid.el.innerHtml = '<div id="1" gs-w="3"></div><div id="2"></div>';
3418
- * grid.makeWidget('1');
3419
- * grid.makeWidget('2', {w:2, content: 'hello'});
3420
- */
3421
- makeWidget(e, t) {
3422
- const i = _.getElement(e);
3423
- if (!i)
3424
- return;
3425
- i.parentElement || this.el.appendChild(i), this._prepareElement(i, !0, t);
3426
- const s = i.gridstackNode;
3427
- this._updateContainerHeight(), s.subGridOpts && this.makeSubGrid(i, s.subGridOpts, void 0, !1);
3428
- let r;
3429
- return this.opts.column === 1 && !this._ignoreLayoutsNodeChange && (r = this._ignoreLayoutsNodeChange = !0), this._triggerAddEvent(), this._triggerChangeEvent(), r && delete this._ignoreLayoutsNodeChange, i;
3430
- }
3431
- on(e, t) {
3432
- return e.indexOf(" ") !== -1 ? (e.split(" ").forEach((s) => this.on(s, t)), this) : (e === "change" || e === "added" || e === "removed" || e === "enable" || e === "disable" ? (e === "enable" || e === "disable" ? this._gsEventHandler[e] = (s) => t(s) : this._gsEventHandler[e] = (s) => {
3433
- s.detail && t(s, s.detail);
3434
- }, this.el.addEventListener(e, this._gsEventHandler[e])) : e === "drag" || e === "dragstart" || e === "dragstop" || e === "resizestart" || e === "resize" || e === "resizestop" || e === "dropped" || e === "resizecontent" ? this._gsEventHandler[e] = t : console.error("GridStack.on(" + e + ") event not supported"), this);
3435
- }
3436
- /**
3437
- * unsubscribe from the 'on' event GridStackEvent
3438
- * @param name of the event (see possible values) or list of names space separated
3439
- */
3440
- off(e) {
3441
- return e.indexOf(" ") !== -1 ? (e.split(" ").forEach((i) => this.off(i)), this) : ((e === "change" || e === "added" || e === "removed" || e === "enable" || e === "disable") && this._gsEventHandler[e] && this.el.removeEventListener(e, this._gsEventHandler[e]), delete this._gsEventHandler[e], this);
3442
- }
3443
- /** remove all event handlers */
3444
- offAll() {
3445
- return Object.keys(this._gsEventHandler).forEach((e) => this.off(e)), this;
3446
- }
3447
- /**
3448
- * Removes widget from the grid.
3449
- * @param el widget or selector to modify
3450
- * @param removeDOM if `false` DOM element won't be removed from the tree (Default? true).
3451
- * @param triggerEvent if `false` (quiet mode) element will not be added to removed list and no 'removed' callbacks will be called (Default? true).
3452
- */
3453
- removeWidget(e, t = !0, i = !0) {
3454
- return e ? (_.getElements(e).forEach((s) => {
3455
- if (s.parentElement && s.parentElement !== this.el)
3456
- return;
3457
- let r = s.gridstackNode;
3458
- r || (r = this.engine.nodes.find((o) => s === o.el)), r && (t && _.addRemoveCB && _.addRemoveCB(this.el, r, !1, !1), delete s.gridstackNode, this._removeDD(s), this.engine.removeNode(r, t, i), t && s.parentElement && s.remove());
3459
- }), i && (this._triggerRemoveEvent(), this._triggerChangeEvent()), this) : (console.error("Error: GridStack.removeWidget(undefined) called"), this);
3460
- }
3461
- /**
3462
- * Removes all widgets from the grid.
3463
- * @param removeDOM if `false` DOM elements won't be removed from the tree (Default? `true`).
3464
- * @param triggerEvent if `false` (quiet mode) element will not be added to removed list and no 'removed' callbacks will be called (Default? true).
3465
- */
3466
- removeAll(e = !0, t = !0) {
3467
- return this.engine.nodes.forEach((i) => {
3468
- e && _.addRemoveCB && _.addRemoveCB(this.el, i, !1, !1), delete i.el.gridstackNode, this.opts.staticGrid || this._removeDD(i.el);
3469
- }), this.engine.removeAll(e, t), t && this._triggerRemoveEvent(), this;
3470
- }
3471
- /**
3472
- * Toggle the grid animation state. Toggles the `grid-stack-animate` class.
3473
- * @param doAnimate if true the grid will animate.
3474
- * @param delay if true setting will be set on next event loop.
3475
- */
3476
- setAnimation(e = this.opts.animate, t) {
3477
- return t ? setTimeout(() => {
3478
- this.opts && this.setAnimation(e);
3479
- }) : e ? this.el.classList.add("grid-stack-animate") : this.el.classList.remove("grid-stack-animate"), this;
3480
- }
3481
- /** @internal */
3482
- hasAnimationCSS() {
3483
- return this.el.classList.contains("grid-stack-animate");
3484
- }
3485
- /**
3486
- * Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
3487
- * Also toggle the grid-stack-static class.
3488
- * @param val if true the grid become static.
3489
- * @param updateClass true (default) if css class gets updated
3490
- * @param recurse true (default) if sub-grids also get updated
3491
- */
3492
- setStatic(e, t = !0, i = !0) {
3493
- return !!this.opts.staticGrid === e ? this : (e ? this.opts.staticGrid = !0 : delete this.opts.staticGrid, this._setupRemoveDrop(), this._setupAcceptWidget(), this.engine.nodes.forEach((s) => {
3494
- this.prepareDragDrop(s.el), s.subGrid && i && s.subGrid.setStatic(e, t, i);
3495
- }), t && this._setStaticClass(), this);
3496
- }
3497
- /**
3498
- * Updates the passed in options on the grid (similar to update(widget) for for the grid options).
3499
- * @param options PARTIAL grid options to update - only items specified will be updated.
3500
- * NOTE: not all options updating are currently supported (lot of code, unlikely to change)
3501
- */
3502
- updateOptions(e) {
3503
- var i;
3504
- const t = this.opts;
3505
- return e.acceptWidgets !== void 0 && this._setupAcceptWidget(), e.animate !== void 0 && this.setAnimation(), e.cellHeight && (this.cellHeight(e.cellHeight, !0), delete e.cellHeight), e.class && e.class !== t.class && (t.class && this.el.classList.remove(t.class), this.el.classList.add(e.class)), typeof e.column == "number" && !e.columnOpts && (this.column(e.column), delete e.column), e.margin !== void 0 && this.margin(e.margin), e.staticGrid !== void 0 && this.setStatic(e.staticGrid), e.disableDrag !== void 0 && !e.staticGrid && this.enableMove(!e.disableDrag), e.disableResize !== void 0 && !e.staticGrid && this.enableResize(!e.disableResize), e.float !== void 0 && this.float(e.float), e.row !== void 0 && (t.minRow = t.maxRow = e.row), (i = e.children) != null && i.length && (this.load(e.children), delete e.children), this.opts = { ...this.opts, ...e }, this;
3506
- }
3507
- /**
3508
- * Updates widget position/size and other info. Note: if you need to call this on all nodes, use load() instead which will update what changed.
3509
- * @param els widget or selector of objects to modify (note: setting the same x,y for multiple items will be indeterministic and likely unwanted)
3510
- * @param opt new widget options (x,y,w,h, etc..). Only those set will be updated.
3511
- */
3512
- update(e, t) {
3513
- return _.getElements(e).forEach((i) => {
3514
- var h;
3515
- const s = i == null ? void 0 : i.gridstackNode;
3516
- if (!s)
3517
- return;
3518
- const r = { ...c.copyPos({}, s), ...c.cloneDeep(t) };
3519
- this.engine.nodeBoundFix(r), delete r.autoPosition;
3520
- const o = ["x", "y", "w", "h"];
3521
- let n;
3522
- if (o.some((l) => r[l] !== void 0 && r[l] !== s[l]) && (n = {}, o.forEach((l) => {
3523
- n[l] = r[l] !== void 0 ? r[l] : s[l], delete r[l];
3524
- })), !n && (r.minW || r.minH || r.maxW || r.maxH) && (n = {}), r.content !== void 0) {
3525
- const l = i.querySelector(".grid-stack-item-content");
3526
- l && l.textContent !== r.content && (s.content = r.content, _.renderCB(l, r), (h = s.subGrid) != null && h.el && (l.appendChild(s.subGrid.el), s.subGrid.opts.styleInHead || s.subGrid._updateStyles(!0))), delete r.content;
3527
- }
3528
- let d = !1, u = !1;
3529
- for (const l in r)
3530
- l[0] !== "_" && s[l] !== r[l] && (s[l] = r[l], d = !0, u = u || !this.opts.staticGrid && (l === "noResize" || l === "noMove" || l === "locked"));
3531
- if (c.sanitizeMinMax(s), n) {
3532
- const l = n.w !== void 0 && n.w !== s.w;
3533
- this.moveNode(s, n), l && s.subGrid ? s.subGrid.onResize(this.hasAnimationCSS() ? s.w : void 0) : this.resizeToContentCheck(l, s), delete s._orig;
3534
- }
3535
- (n || d) && this._writeAttr(i, s), u && this.prepareDragDrop(s.el);
3536
- }), this;
3537
- }
3538
- moveNode(e, t) {
3539
- const i = e._updating;
3540
- i || this.engine.cleanNodes().beginUpdate(e), this.engine.moveNode(e, t), this._updateContainerHeight(), i || (this._triggerChangeEvent(), this.engine.endUpdate());
3541
- }
3542
- /**
3543
- * Updates widget height to match the content height to avoid v-scrollbar or dead space.
3544
- * Note: this assumes only 1 child under resizeToContentParent='.grid-stack-item-content' (sized to gridItem minus padding) that is at the entire content size wanted.
3545
- * @param el grid item element
3546
- * @param useNodeH set to true if GridStackNode.h should be used instead of actual container height when we don't need to wait for animation to finish to get actual DOM heights
3547
- */
3548
- resizeToContent(e) {
3549
- var f, g;
3550
- if (!e || (e.classList.remove("size-to-content-max"), !e.clientHeight))
3551
- return;
3552
- const t = e.gridstackNode;
3553
- if (!t)
3554
- return;
3555
- const i = t.grid;
3556
- if (!i || e.parentElement !== i.el)
3557
- return;
3558
- const s = i.getCellHeight(!0);
3559
- if (!s)
3560
- return;
3561
- let r = t.h ? t.h * s : e.clientHeight, o;
3562
- if (t.resizeToContentParent && (o = e.querySelector(t.resizeToContentParent)), o || (o = e.querySelector(_.resizeToContentParent)), !o)
3563
- return;
3564
- const n = e.clientHeight - o.clientHeight, d = t.h ? t.h * s - n : o.clientHeight;
3565
- let u;
3566
- if (t.subGrid) {
3567
- u = t.subGrid.getRow() * t.subGrid.getCellHeight(!0);
3568
- const p = t.subGrid.el.getBoundingClientRect(), y = t.subGrid.el.parentElement.getBoundingClientRect();
3569
- u += p.top - y.top;
3570
- } else {
3571
- if ((g = (f = t.subGridOpts) == null ? void 0 : f.children) != null && g.length)
3572
- return;
3573
- {
3574
- const p = o.firstElementChild;
3575
- if (!p) {
3576
- console.error(`Error: GridStack.resizeToContent() widget id:${t.id} '${_.resizeToContentParent}'.firstElementChild is null, make sure to have a div like container. Skipping sizing.`);
3577
- return;
3578
- }
3579
- u = p.getBoundingClientRect().height || d;
3580
- }
3581
- }
3582
- if (d === u)
3583
- return;
3584
- r += u - d;
3585
- let h = Math.ceil(r / s);
3586
- const l = Number.isInteger(t.sizeToContent) ? t.sizeToContent : 0;
3587
- l && h > l && (h = l, e.classList.add("size-to-content-max")), t.minH && h < t.minH ? h = t.minH : t.maxH && h > t.maxH && (h = t.maxH), h !== t.h && (i._ignoreLayoutsNodeChange = !0, i.moveNode(t, { h }), delete i._ignoreLayoutsNodeChange);
3588
- }
3589
- /** call the user resize (so they can do extra work) else our build in version */
3590
- resizeToContentCBCheck(e) {
3591
- _.resizeToContentCB ? _.resizeToContentCB(e) : this.resizeToContent(e);
3592
- }
3593
- /** rotate (by swapping w & h) the passed in node - called when user press 'r' during dragging
3594
- * @param els widget or selector of objects to modify
3595
- * @param relative optional pixel coord relative to upper/left corner to rotate around (will keep that cell under cursor)
3596
- */
3597
- rotate(e, t) {
3598
- return _.getElements(e).forEach((i) => {
3599
- const s = i.gridstackNode;
3600
- if (!c.canBeRotated(s))
3601
- return;
3602
- const r = { w: s.h, h: s.w, minH: s.minW, minW: s.minH, maxH: s.maxW, maxW: s.maxH };
3603
- if (t) {
3604
- const n = t.left > 0 ? Math.floor(t.left / this.cellWidth()) : 0, d = t.top > 0 ? Math.floor(t.top / this.opts.cellHeight) : 0;
3605
- r.x = s.x + n - (s.h - (d + 1)), r.y = s.y + d - n;
3606
- }
3607
- Object.keys(r).forEach((n) => {
3608
- r[n] === void 0 && delete r[n];
3609
- });
3610
- const o = s._orig;
3611
- this.update(i, r), s._orig = o;
3612
- }), this;
3613
- }
3614
- /**
3615
- * Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options (CSS string format of 1,2,4 values or single number).
3616
- * @param value margin value
3617
- */
3618
- margin(e) {
3619
- if (!(typeof e == "string" && e.split(" ").length > 1)) {
3620
- const i = c.parseHeight(e);
3621
- if (this.opts.marginUnit === i.unit && this.opts.margin === i.h)
3622
- return;
3623
- }
3624
- return this.opts.margin = e, this.opts.marginTop = this.opts.marginBottom = this.opts.marginLeft = this.opts.marginRight = void 0, this._initMargin(), this._updateStyles(!0), this;
3625
- }
3626
- /** returns current margin number value (undefined if 4 sides don't match) */
3627
- getMargin() {
3628
- return this.opts.margin;
3629
- }
3630
- /**
3631
- * Returns true if the height of the grid will be less than the vertical
3632
- * constraint. Always returns true if grid doesn't have height constraint.
3633
- * @param node contains x,y,w,h,auto-position options
3634
- *
3635
- * @example
3636
- * if (grid.willItFit(newWidget)) {
3637
- * grid.addWidget(newWidget);
3638
- * } else {
3639
- * alert('Not enough free space to place the widget');
3640
- * }
3641
- */
3642
- willItFit(e) {
3643
- if (arguments.length > 1) {
3644
- console.warn("gridstack.ts: `willItFit(x,y,w,h,autoPosition)` is deprecated. Use `willItFit({x, y,...})`. It will be removed soon");
3645
- const t = arguments;
3646
- let i = 0, s = { x: t[i++], y: t[i++], w: t[i++], h: t[i++], autoPosition: t[i++] };
3647
- return this.willItFit(s);
3648
- }
3649
- return this.engine.willItFit(e);
3650
- }
3651
- /** @internal */
3652
- _triggerChangeEvent() {
3653
- if (this.engine.batchMode)
3654
- return this;
3655
- const e = this.engine.getDirtyNodes(!0);
3656
- return e && e.length && (this._ignoreLayoutsNodeChange || this.engine.layoutsNodesChange(e), this._triggerEvent("change", e)), this.engine.saveInitial(), this;
3657
- }
3658
- /** @internal */
3659
- _triggerAddEvent() {
3660
- var e;
3661
- if (this.engine.batchMode)
3662
- return this;
3663
- if ((e = this.engine.addedNodes) != null && e.length) {
3664
- this._ignoreLayoutsNodeChange || this.engine.layoutsNodesChange(this.engine.addedNodes), this.engine.addedNodes.forEach((i) => {
3665
- delete i._dirty;
3666
- });
3667
- const t = [...this.engine.addedNodes];
3668
- this.engine.addedNodes = [], this._triggerEvent("added", t);
3669
- }
3670
- return this;
3671
- }
3672
- /** @internal */
3673
- _triggerRemoveEvent() {
3674
- var e;
3675
- if (this.engine.batchMode)
3676
- return this;
3677
- if ((e = this.engine.removedNodes) != null && e.length) {
3678
- const t = [...this.engine.removedNodes];
3679
- this.engine.removedNodes = [], this._triggerEvent("removed", t);
3680
- }
3681
- return this;
3682
- }
3683
- /** @internal */
3684
- _triggerEvent(e, t) {
3685
- const i = t ? new CustomEvent(e, { bubbles: !1, detail: t }) : new Event(e);
3686
- return this.el.dispatchEvent(i), this;
3687
- }
3688
- /** @internal called to delete the current dynamic style sheet used for our layout */
3689
- _removeStylesheet() {
3690
- if (this._styles) {
3691
- const e = this.opts.styleInHead ? void 0 : this.el.parentNode;
3692
- c.removeStylesheet(this._styleSheetClass, e), delete this._styles;
3693
- }
3694
- return this;
3695
- }
3696
- /** @internal updated/create the CSS styles for row based layout and initial margin setting */
3697
- _updateStyles(e = !1, t) {
3698
- if (e && this._removeStylesheet(), t === void 0 && (t = this.getRow()), this._updateContainerHeight(), this.opts.cellHeight === 0)
3699
- return this;
3700
- const i = this.opts.cellHeight, s = this.opts.cellHeightUnit, r = `.${this._styleSheetClass} > .${this.opts.itemClass}`;
3701
- if (!this._styles) {
3702
- const o = this.opts.styleInHead ? void 0 : this.el.parentNode;
3703
- if (this._styles = c.createStylesheet(this._styleSheetClass, o, {
3704
- nonce: this.opts.nonce
3705
- }), !this._styles)
3706
- return this;
3707
- this._styles._max = 0, c.addCSSRule(this._styles, r, `height: ${i}${s}`);
3708
- const n = this.opts.marginTop + this.opts.marginUnit, d = this.opts.marginBottom + this.opts.marginUnit, u = this.opts.marginRight + this.opts.marginUnit, h = this.opts.marginLeft + this.opts.marginUnit, l = `${r} > .grid-stack-item-content`, f = `.${this._styleSheetClass} > .grid-stack-placeholder > .placeholder-content`;
3709
- c.addCSSRule(this._styles, l, `top: ${n}; right: ${u}; bottom: ${d}; left: ${h};`), c.addCSSRule(this._styles, f, `top: ${n}; right: ${u}; bottom: ${d}; left: ${h};`), c.addCSSRule(this._styles, `${r} > .ui-resizable-n`, `top: ${n};`), c.addCSSRule(this._styles, `${r} > .ui-resizable-s`, `bottom: ${d}`), c.addCSSRule(this._styles, `${r} > .ui-resizable-ne`, `right: ${u}; top: ${n}`), c.addCSSRule(this._styles, `${r} > .ui-resizable-e`, `right: ${u}`), c.addCSSRule(this._styles, `${r} > .ui-resizable-se`, `right: ${u}; bottom: ${d}`), c.addCSSRule(this._styles, `${r} > .ui-resizable-nw`, `left: ${h}; top: ${n}`), c.addCSSRule(this._styles, `${r} > .ui-resizable-w`, `left: ${h}`), c.addCSSRule(this._styles, `${r} > .ui-resizable-sw`, `left: ${h}; bottom: ${d}`);
3710
- }
3711
- if (t = t || this._styles._max, t > this._styles._max) {
3712
- const o = (n) => i * n + s;
3713
- for (let n = this._styles._max + 1; n <= t; n++)
3714
- c.addCSSRule(this._styles, `${r}[gs-y="${n}"]`, `top: ${o(n)}`), c.addCSSRule(this._styles, `${r}[gs-h="${n + 1}"]`, `height: ${o(n + 1)}`);
3715
- this._styles._max = t;
3716
- }
3717
- return this;
3718
- }
3719
- /** @internal */
3720
- _updateContainerHeight() {
3721
- if (!this.engine || this.engine.batchMode)
3722
- return this;
3723
- const e = this.parentGridNode;
3724
- let t = this.getRow() + this._extraDragRow;
3725
- const i = this.opts.cellHeight, s = this.opts.cellHeightUnit;
3726
- if (!i)
3727
- return this;
3728
- if (!e) {
3729
- const r = c.parseHeight(getComputedStyle(this.el).minHeight);
3730
- if (r.h > 0 && r.unit === s) {
3731
- const o = Math.floor(r.h / i);
3732
- t < o && (t = o);
3733
- }
3734
- }
3735
- return this.el.setAttribute("gs-current-row", String(t)), this.el.style.removeProperty("min-height"), this.el.style.removeProperty("height"), t && (this.el.style[e ? "minHeight" : "height"] = t * i + s), e && !e.grid.engine.batchMode && c.shouldSizeToContent(e) && e.grid.resizeToContentCBCheck(e.el), this;
3736
- }
3737
- /** @internal */
3738
- _prepareElement(e, t = !1, i) {
3739
- i = i || this._readAttr(e), e.gridstackNode = i, i.el = e, i.grid = this, i = this.engine.addNode(i, t), this._writeAttr(e, i), e.classList.add(Z.itemClass, this.opts.itemClass);
3740
- const s = c.shouldSizeToContent(i);
3741
- return s ? e.classList.add("size-to-content") : e.classList.remove("size-to-content"), s && this.resizeToContentCheck(!1, i), c.lazyLoad(i) || this.prepareDragDrop(i.el), this;
3742
- }
3743
- /** @internal call to write position x,y,w,h attributes back to element */
3744
- _writePosAttr(e, t) {
3745
- return t.x !== void 0 && t.x !== null && e.setAttribute("gs-x", String(t.x)), t.y !== void 0 && t.y !== null && e.setAttribute("gs-y", String(t.y)), t.w > 1 ? e.setAttribute("gs-w", String(t.w)) : e.removeAttribute("gs-w"), t.h > 1 ? e.setAttribute("gs-h", String(t.h)) : e.removeAttribute("gs-h"), this;
3746
- }
3747
- /** @internal call to write any default attributes back to element */
3748
- _writeAttr(e, t) {
3749
- if (!t)
3750
- return this;
3751
- this._writePosAttr(e, t);
3752
- const i = {
3753
- // autoPosition: 'gs-auto-position', // no need to write out as already in node and doesn't affect CSS
3754
- noResize: "gs-no-resize",
3755
- noMove: "gs-no-move",
3756
- locked: "gs-locked",
3757
- id: "gs-id",
3758
- sizeToContent: "gs-size-to-content"
3759
- };
3760
- for (const s in i)
3761
- t[s] ? e.setAttribute(i[s], String(t[s])) : e.removeAttribute(i[s]);
3762
- return this;
3763
- }
3764
- /** @internal call to read any default attributes from element */
3765
- _readAttr(e, t = !0) {
3766
- const i = {};
3767
- i.x = c.toNumber(e.getAttribute("gs-x")), i.y = c.toNumber(e.getAttribute("gs-y")), i.w = c.toNumber(e.getAttribute("gs-w")), i.h = c.toNumber(e.getAttribute("gs-h")), i.autoPosition = c.toBool(e.getAttribute("gs-auto-position")), i.noResize = c.toBool(e.getAttribute("gs-no-resize")), i.noMove = c.toBool(e.getAttribute("gs-no-move")), i.locked = c.toBool(e.getAttribute("gs-locked"));
3768
- const s = e.getAttribute("gs-size-to-content");
3769
- s && (s === "true" || s === "false" ? i.sizeToContent = c.toBool(s) : i.sizeToContent = parseInt(s, 10)), i.id = e.getAttribute("gs-id"), i.maxW = c.toNumber(e.getAttribute("gs-max-w")), i.minW = c.toNumber(e.getAttribute("gs-min-w")), i.maxH = c.toNumber(e.getAttribute("gs-max-h")), i.minH = c.toNumber(e.getAttribute("gs-min-h")), t && (i.w === 1 && e.removeAttribute("gs-w"), i.h === 1 && e.removeAttribute("gs-h"), i.maxW && e.removeAttribute("gs-max-w"), i.minW && e.removeAttribute("gs-min-w"), i.maxH && e.removeAttribute("gs-max-h"), i.minH && e.removeAttribute("gs-min-h"));
3770
- for (const r in i) {
3771
- if (!i.hasOwnProperty(r))
3772
- return;
3773
- !i[r] && i[r] !== 0 && r !== "gs-size-to-content" && delete i[r];
3774
- }
3775
- return i;
3776
- }
3777
- /** @internal */
3778
- _setStaticClass() {
3779
- const e = ["grid-stack-static"];
3780
- return this.opts.staticGrid ? (this.el.classList.add(...e), this.el.setAttribute("gs-static", "true")) : (this.el.classList.remove(...e), this.el.removeAttribute("gs-static")), this;
3781
- }
3782
- /**
3783
- * called when we are being resized - check if the one Column Mode needs to be turned on/off
3784
- * and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square)
3785
- * or `sizeToContent` gridItem options.
3786
- */
3787
- onResize(e = ((t) => (t = this.el) == null ? void 0 : t.clientWidth)()) {
3788
- if (!e || this.prevWidth === e)
3789
- return;
3790
- this.prevWidth = e, this.batchUpdate();
3791
- let i = !1;
3792
- return this._autoColumn && this.parentGridNode ? this.opts.column !== this.parentGridNode.w && (this.column(this.parentGridNode.w, this.opts.layout || "list"), i = !0) : i = this.checkDynamicColumn(), this._isAutoCellHeight && this.cellHeight(), this.engine.nodes.forEach((s) => {
3793
- s.subGrid && s.subGrid.onResize();
3794
- }), this._skipInitialResize || this.resizeToContentCheck(i), delete this._skipInitialResize, this.batchUpdate(!1), this;
3795
- }
3796
- /** resizes content for given node (or all) if shouldSizeToContent() is true */
3797
- resizeToContentCheck(e = !1, t = void 0) {
3798
- if (this.engine) {
3799
- if (e && this.hasAnimationCSS())
3800
- return setTimeout(() => this.resizeToContentCheck(!1, t), this.animationDelay);
3801
- if (t)
3802
- c.shouldSizeToContent(t) && this.resizeToContentCBCheck(t.el);
3803
- else if (this.engine.nodes.some((i) => c.shouldSizeToContent(i))) {
3804
- const i = [...this.engine.nodes];
3805
- this.batchUpdate(), i.forEach((s) => {
3806
- c.shouldSizeToContent(s) && this.resizeToContentCBCheck(s.el);
3807
- }), this.batchUpdate(!1);
3808
- }
3809
- this._gsEventHandler.resizecontent && this._gsEventHandler.resizecontent(null, t ? [t] : this.engine.nodes);
3810
- }
3811
- }
3812
- /** add or remove the grid element size event handler */
3813
- _updateResizeEvent(e = !1) {
3814
- const t = !this.parentGridNode && (this._isAutoCellHeight || this.opts.sizeToContent || this.opts.columnOpts || this.engine.nodes.find((i) => i.sizeToContent));
3815
- return !e && t && !this.resizeObserver ? (this._sizeThrottle = c.throttle(() => this.onResize(), this.opts.cellHeightThrottle), this.resizeObserver = new ResizeObserver(() => this._sizeThrottle()), this.resizeObserver.observe(this.el), this._skipInitialResize = !0) : (e || !t) && this.resizeObserver && (this.resizeObserver.disconnect(), delete this.resizeObserver, delete this._sizeThrottle), this;
3816
- }
3817
- /** @internal convert a potential selector into actual element */
3818
- static getElement(e = ".grid-stack-item") {
3819
- return c.getElement(e);
3820
- }
3821
- /** @internal */
3822
- static getElements(e = ".grid-stack-item") {
3823
- return c.getElements(e);
3824
- }
3825
- /** @internal */
3826
- static getGridElement(e) {
3827
- return _.getElement(e);
3828
- }
3829
- /** @internal */
3830
- static getGridElements(e) {
3831
- return c.getElements(e);
3832
- }
3833
- /** @internal initialize margin top/bottom/left/right and units */
3834
- _initMargin() {
3835
- let e, t = 0, i = [];
3836
- return typeof this.opts.margin == "string" && (i = this.opts.margin.split(" ")), i.length === 2 ? (this.opts.marginTop = this.opts.marginBottom = i[0], this.opts.marginLeft = this.opts.marginRight = i[1]) : i.length === 4 ? (this.opts.marginTop = i[0], this.opts.marginRight = i[1], this.opts.marginBottom = i[2], this.opts.marginLeft = i[3]) : (e = c.parseHeight(this.opts.margin), this.opts.marginUnit = e.unit, t = this.opts.margin = e.h), this.opts.marginTop === void 0 ? this.opts.marginTop = t : (e = c.parseHeight(this.opts.marginTop), this.opts.marginTop = e.h, delete this.opts.margin), this.opts.marginBottom === void 0 ? this.opts.marginBottom = t : (e = c.parseHeight(this.opts.marginBottom), this.opts.marginBottom = e.h, delete this.opts.margin), this.opts.marginRight === void 0 ? this.opts.marginRight = t : (e = c.parseHeight(this.opts.marginRight), this.opts.marginRight = e.h, delete this.opts.margin), this.opts.marginLeft === void 0 ? this.opts.marginLeft = t : (e = c.parseHeight(this.opts.marginLeft), this.opts.marginLeft = e.h, delete this.opts.margin), this.opts.marginUnit = e.unit, this.opts.marginTop === this.opts.marginBottom && this.opts.marginLeft === this.opts.marginRight && this.opts.marginTop === this.opts.marginRight && (this.opts.margin = this.opts.marginTop), this;
3837
- }
3838
- /* ===========================================================================================
3839
- * drag&drop methods that used to be stubbed out and implemented in dd-gridstack.ts
3840
- * but caused loading issues in prod - see https://github.com/gridstack/gridstack.js/issues/2039
3841
- * ===========================================================================================
3842
- */
3843
- /** get the global (but static to this code) DD implementation */
3844
- static getDD() {
3845
- return W;
3846
- }
3847
- /**
3848
- * call to setup dragging in from the outside (say toolbar), by specifying the class selection and options.
3849
- * Called during GridStack.init() as options, but can also be called directly (last param are used) in case the toolbar
3850
- * is dynamically create and needs to be set later.
3851
- * @param dragIn string selector (ex: '.sidebar-item') or list of dom elements
3852
- * @param dragInOptions options - see DDDragOpt. (default: {handle: '.grid-stack-item-content', appendTo: 'body'}
3853
- * @param widgets GridStackWidget def to assign to each element which defines what to create on drop
3854
- * @param root optional root which defaults to document (for shadow dom pass the parent HTMLDocument)
3855
- */
3856
- static setupDragIn(e, t, i, s = document) {
3857
- (t == null ? void 0 : t.pause) !== void 0 && (w.pauseDrag = t.pause), t = { appendTo: "body", helper: "clone", ...t || {} }, (typeof e == "string" ? c.getElements(e, s) : e).forEach((o, n) => {
3858
- W.isDraggable(o) || W.dragIn(o, t), i != null && i[n] && (o.gridstackNode = i[n]);
3859
- });
3860
- }
3861
- /**
3862
- * Enables/Disables dragging by the user of specific grid element. If you want all items, and have it affect future items, use enableMove() instead. No-op for static grids.
3863
- * IF you are looking to prevent an item from moving (due to being pushed around by another during collision) use locked property instead.
3864
- * @param els widget or selector to modify.
3865
- * @param val if true widget will be draggable, assuming the parent grid isn't noMove or static.
3866
- */
3867
- movable(e, t) {
3868
- return this.opts.staticGrid ? this : (_.getElements(e).forEach((i) => {
3869
- const s = i.gridstackNode;
3870
- s && (t ? delete s.noMove : s.noMove = !0, this.prepareDragDrop(s.el));
3871
- }), this);
3872
- }
3873
- /**
3874
- * Enables/Disables user resizing of specific grid element. If you want all items, and have it affect future items, use enableResize() instead. No-op for static grids.
3875
- * @param els widget or selector to modify
3876
- * @param val if true widget will be resizable, assuming the parent grid isn't noResize or static.
3877
- */
3878
- resizable(e, t) {
3879
- return this.opts.staticGrid ? this : (_.getElements(e).forEach((i) => {
3880
- const s = i.gridstackNode;
3881
- s && (t ? delete s.noResize : s.noResize = !0, this.prepareDragDrop(s.el));
3882
- }), this);
3883
- }
3884
- /**
3885
- * Temporarily disables widgets moving/resizing.
3886
- * If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
3887
- * Note: no-op for static grid
3888
- * This is a shortcut for:
3889
- * @example
3890
- * grid.enableMove(false);
3891
- * grid.enableResize(false);
3892
- * @param recurse true (default) if sub-grids also get updated
3893
- */
3894
- disable(e = !0) {
3895
- if (!this.opts.staticGrid)
3896
- return this.enableMove(!1, e), this.enableResize(!1, e), this._triggerEvent("disable"), this;
3897
- }
3898
- /**
3899
- * Re-enables widgets moving/resizing - see disable().
3900
- * Note: no-op for static grid.
3901
- * This is a shortcut for:
3902
- * @example
3903
- * grid.enableMove(true);
3904
- * grid.enableResize(true);
3905
- * @param recurse true (default) if sub-grids also get updated
3906
- */
3907
- enable(e = !0) {
3908
- if (!this.opts.staticGrid)
3909
- return this.enableMove(!0, e), this.enableResize(!0, e), this._triggerEvent("enable"), this;
3910
- }
3911
- /**
3912
- * Enables/disables widget moving. No-op for static grids, and locally defined items still overrule
3913
- * @param recurse true (default) if sub-grids also get updated
3914
- */
3915
- enableMove(e, t = !0) {
3916
- return this.opts.staticGrid ? this : (e ? delete this.opts.disableDrag : this.opts.disableDrag = !0, this.engine.nodes.forEach((i) => {
3917
- this.prepareDragDrop(i.el), i.subGrid && t && i.subGrid.enableMove(e, t);
3918
- }), this);
3919
- }
3920
- /**
3921
- * Enables/disables widget resizing. No-op for static grids.
3922
- * @param recurse true (default) if sub-grids also get updated
3923
- */
3924
- enableResize(e, t = !0) {
3925
- return this.opts.staticGrid ? this : (e ? delete this.opts.disableResize : this.opts.disableResize = !0, this.engine.nodes.forEach((i) => {
3926
- this.prepareDragDrop(i.el), i.subGrid && t && i.subGrid.enableResize(e, t);
3927
- }), this);
3928
- }
3929
- /** @internal call when drag (and drop) needs to be cancelled (Esc key) */
3930
- cancelDrag() {
3931
- var t;
3932
- const e = (t = this._placeholder) == null ? void 0 : t.gridstackNode;
3933
- e && (e._isExternal ? (e._isAboutToRemove = !0, this.engine.removeNode(e)) : e._isAboutToRemove && _._itemRemoving(e.el, !1), this.engine.restoreInitial());
3934
- }
3935
- /** @internal removes any drag&drop present (called during destroy) */
3936
- _removeDD(e) {
3937
- return W.draggable(e, "destroy").resizable(e, "destroy"), e.gridstackNode && delete e.gridstackNode._initDD, delete e.ddElement, this;
3938
- }
3939
- /** @internal called to add drag over to support widgets being added externally */
3940
- _setupAcceptWidget() {
3941
- if (this.opts.staticGrid || !this.opts.acceptWidgets && !this.opts.removable)
3942
- return W.droppable(this.el, "destroy"), this;
3943
- let e, t;
3944
- const i = (s, r, o) => {
3945
- var f;
3946
- o = o || r;
3947
- const n = o.gridstackNode;
3948
- if (!n)
3949
- return;
3950
- if (!((f = n.grid) != null && f.el)) {
3951
- o.style.transform = `scale(${1 / this.dragTransform.xScale},${1 / this.dragTransform.yScale})`;
3952
- const g = o.getBoundingClientRect();
3953
- o.style.left = g.x + (this.dragTransform.xScale - 1) * (s.clientX - g.x) / this.dragTransform.xScale + "px", o.style.top = g.y + (this.dragTransform.yScale - 1) * (s.clientY - g.y) / this.dragTransform.yScale + "px", o.style.transformOrigin = "0px 0px";
3954
- }
3955
- let { top: d, left: u } = o.getBoundingClientRect();
3956
- const h = this.el.getBoundingClientRect();
3957
- u -= h.left, d -= h.top;
3958
- const l = {
3959
- position: {
3960
- top: d * this.dragTransform.xScale,
3961
- left: u * this.dragTransform.yScale
3962
- }
3963
- };
3964
- if (n._temporaryRemoved) {
3965
- if (n.x = Math.max(0, Math.round(u / t)), n.y = Math.max(0, Math.round(d / e)), delete n.autoPosition, this.engine.nodeBoundFix(n), !this.engine.willItFit(n)) {
3966
- if (n.autoPosition = !0, !this.engine.willItFit(n)) {
3967
- W.off(r, "drag");
3968
- return;
3969
- }
3970
- n._willFitPos && (c.copyPos(n, n._willFitPos), delete n._willFitPos);
3971
- }
3972
- this._onStartMoving(o, s, l, n, t, e);
3973
- } else
3974
- this._dragOrResize(o, s, l, n, t, e);
3975
- };
3976
- return W.droppable(this.el, {
3977
- accept: (s) => {
3978
- const r = s.gridstackNode || this._readAttr(s, !1);
3979
- if ((r == null ? void 0 : r.grid) === this)
3980
- return !0;
3981
- if (!this.opts.acceptWidgets)
3982
- return !1;
3983
- let o = !0;
3984
- if (typeof this.opts.acceptWidgets == "function")
3985
- o = this.opts.acceptWidgets(s);
3986
- else {
3987
- const n = this.opts.acceptWidgets === !0 ? ".grid-stack-item" : this.opts.acceptWidgets;
3988
- o = s.matches(n);
3989
- }
3990
- if (o && r && this.opts.maxRow) {
3991
- const n = { w: r.w, h: r.h, minW: r.minW, minH: r.minH };
3992
- o = this.engine.willItFit(n);
3993
- }
3994
- return o;
3995
- }
3996
- }).on(this.el, "dropover", (s, r, o) => {
3997
- let n = (o == null ? void 0 : o.gridstackNode) || r.gridstackNode;
3998
- if ((n == null ? void 0 : n.grid) === this && !n._temporaryRemoved)
3999
- return !1;
4000
- if (n != null && n._sidebarOrig && (n.w = n._sidebarOrig.w, n.h = n._sidebarOrig.h), n != null && n.grid && n.grid !== this && !n._temporaryRemoved && n.grid._leave(r, o), o = o || r, t = this.cellWidth(), e = this.getCellHeight(!0), !n) {
4001
- const h = o.getAttribute("data-gs-widget") || o.getAttribute("gridstacknode");
4002
- if (h) {
4003
- try {
4004
- n = JSON.parse(h);
4005
- } catch {
4006
- console.error("Gridstack dropover: Bad JSON format: ", h);
4007
- }
4008
- o.removeAttribute("data-gs-widget"), o.removeAttribute("gridstacknode");
4009
- }
4010
- n || (n = this._readAttr(o)), n._sidebarOrig = { w: n.w, h: n.h };
4011
- }
4012
- n.grid || (n.el || (n = { ...n }), n._isExternal = !0, o.gridstackNode = n);
4013
- const d = n.w || Math.round(o.offsetWidth / t) || 1, u = n.h || Math.round(o.offsetHeight / e) || 1;
4014
- return n.grid && n.grid !== this ? (r._gridstackNodeOrig || (r._gridstackNodeOrig = n), r.gridstackNode = n = { ...n, w: d, h: u, grid: this }, delete n.x, delete n.y, this.engine.cleanupNode(n).nodeBoundFix(n), n._initDD = n._isExternal = // DOM needs to be re-parented on a drop
4015
- n._temporaryRemoved = !0) : (n.w = d, n.h = u, n._temporaryRemoved = !0), _._itemRemoving(n.el, !1), W.on(r, "drag", i), i(s, r, o), !1;
4016
- }).on(this.el, "dropout", (s, r, o) => {
4017
- const n = (o == null ? void 0 : o.gridstackNode) || r.gridstackNode;
4018
- return n && (!n.grid || n.grid === this) && (this._leave(r, o), this._isTemp && this.removeAsSubGrid(n)), !1;
4019
- }).on(this.el, "drop", (s, r, o) => {
4020
- var g, p, y;
4021
- const n = (o == null ? void 0 : o.gridstackNode) || r.gridstackNode;
4022
- if ((n == null ? void 0 : n.grid) === this && !n._isExternal)
4023
- return !1;
4024
- const d = !!this.placeholder.parentElement, u = r !== o;
4025
- this.placeholder.remove(), delete this.placeholder.gridstackNode;
4026
- const h = d && this.opts.animate;
4027
- h && this.setAnimation(!1);
4028
- const l = r._gridstackNodeOrig;
4029
- if (delete r._gridstackNodeOrig, d && (l != null && l.grid) && l.grid !== this) {
4030
- const m = l.grid;
4031
- m.engine.removeNodeFromLayoutCache(l), m.engine.removedNodes.push(l), m._triggerRemoveEvent()._triggerChangeEvent(), m.parentGridNode && !m.engine.nodes.length && m.opts.subGridDynamic && m.removeAsSubGrid();
4032
- }
4033
- if (!n || (d && (this.engine.cleanupNode(n), n.grid = this), (g = n.grid) == null || delete g._isTemp, W.off(r, "drag"), o !== r ? (o.remove(), r = o) : r.remove(), this._removeDD(r), !d))
4034
- return !1;
4035
- const f = (y = (p = n.subGrid) == null ? void 0 : p.el) == null ? void 0 : y.gridstack;
4036
- return c.copyPos(n, this._readAttr(this.placeholder)), c.removePositioningStyles(r), u && (n.content || n.subGridOpts || _.addRemoveCB) ? (delete n.el, r = this.addWidget(n)) : (this._prepareElement(r, !0, n), this.el.appendChild(r), this.resizeToContentCheck(!1, n), f && (f.parentGridNode = n, f.opts.styleInHead || f._updateStyles(!0)), this._updateContainerHeight()), this.engine.addedNodes.push(n), this._triggerAddEvent(), this._triggerChangeEvent(), this.engine.endUpdate(), this._gsEventHandler.dropped && this._gsEventHandler.dropped({ ...s, type: "dropped" }, l && l.grid ? l : void 0, n), h && this.setAnimation(this.opts.animate, !0), !1;
4037
- }), this;
4038
- }
4039
- /** @internal mark item for removal */
4040
- static _itemRemoving(e, t) {
4041
- if (!e)
4042
- return;
4043
- const i = e ? e.gridstackNode : void 0;
4044
- !(i != null && i.grid) || e.classList.contains(i.grid.opts.removableOptions.decline) || (t ? i._isAboutToRemove = !0 : delete i._isAboutToRemove, t ? e.classList.add("grid-stack-item-removing") : e.classList.remove("grid-stack-item-removing"));
4045
- }
4046
- /** @internal called to setup a trash drop zone if the user specifies it */
4047
- _setupRemoveDrop() {
4048
- if (typeof this.opts.removable != "string")
4049
- return this;
4050
- const e = document.querySelector(this.opts.removable);
4051
- return e ? (!this.opts.staticGrid && !W.isDroppable(e) && W.droppable(e, this.opts.removableOptions).on(e, "dropover", (t, i) => _._itemRemoving(i, !0)).on(e, "dropout", (t, i) => _._itemRemoving(i, !1)), this) : this;
4052
- }
4053
- /**
4054
- * prepares the element for drag&drop - this is normally called by makeWidget() unless are are delay loading
4055
- * @param el GridItemHTMLElement of the widget
4056
- * @param [force=false]
4057
- * */
4058
- prepareDragDrop(e, t = !1) {
4059
- const i = e == null ? void 0 : e.gridstackNode;
4060
- if (!i)
4061
- return;
4062
- const s = i.noMove || this.opts.disableDrag, r = i.noResize || this.opts.disableResize, o = this.opts.staticGrid || s && r;
4063
- if ((t || o) && (i._initDD && (this._removeDD(e), delete i._initDD), o && e.classList.add("ui-draggable-disabled", "ui-resizable-disabled"), !t))
4064
- return this;
4065
- if (!i._initDD) {
4066
- let n, d;
4067
- const u = (f, g) => {
4068
- this._gsEventHandler[f.type] && this._gsEventHandler[f.type](f, f.target), n = this.cellWidth(), d = this.getCellHeight(!0), this._onStartMoving(e, f, g, i, n, d);
4069
- }, h = (f, g) => {
4070
- this._dragOrResize(e, f, g, i, n, d);
4071
- }, l = (f) => {
4072
- this.placeholder.remove(), delete this.placeholder.gridstackNode, delete i._moving, delete i._event, delete i._lastTried;
4073
- const g = i.w !== i._orig.w, p = f.target;
4074
- if (!(!p.gridstackNode || p.gridstackNode.grid !== this)) {
4075
- if (i.el = p, i._isAboutToRemove) {
4076
- const y = e.gridstackNode.grid;
4077
- y._gsEventHandler[f.type] && y._gsEventHandler[f.type](f, p), y.engine.nodes.push(i), y.removeWidget(e, !0, !0);
4078
- } else
4079
- c.removePositioningStyles(p), i._temporaryRemoved ? (c.copyPos(i, i._orig), this._writePosAttr(p, i), this.engine.addNode(i)) : this._writePosAttr(p, i), this._gsEventHandler[f.type] && this._gsEventHandler[f.type](f, p);
4080
- this._extraDragRow = 0, this._updateContainerHeight(), this._triggerChangeEvent(), this.engine.endUpdate(), f.type === "resizestop" && (Number.isInteger(i.sizeToContent) && (i.sizeToContent = i.h), this.resizeToContentCheck(g, i));
4081
- }
4082
- };
4083
- W.draggable(e, {
4084
- start: u,
4085
- stop: l,
4086
- drag: h
4087
- }).resizable(e, {
4088
- start: u,
4089
- stop: l,
4090
- resize: h
4091
- }), i._initDD = !0;
4092
- }
4093
- return W.draggable(e, s ? "disable" : "enable").resizable(e, r ? "disable" : "enable"), this;
4094
- }
4095
- /** @internal handles actual drag/resize start */
4096
- _onStartMoving(e, t, i, s, r, o) {
4097
- var n;
4098
- if (this.engine.cleanNodes().beginUpdate(s), this._writePosAttr(this.placeholder, s), this.el.appendChild(this.placeholder), this.placeholder.gridstackNode = s, (n = s.grid) != null && n.el)
4099
- this.dragTransform = c.getValuesFromTransformedElement(e);
4100
- else if (this.placeholder && this.placeholder.closest(".grid-stack")) {
4101
- const d = this.placeholder.closest(".grid-stack");
4102
- this.dragTransform = c.getValuesFromTransformedElement(d);
4103
- } else
4104
- this.dragTransform = {
4105
- xScale: 1,
4106
- xOffset: 0,
4107
- yScale: 1,
4108
- yOffset: 0
4109
- };
4110
- if (s.el = this.placeholder, s._lastUiPosition = i.position, s._prevYPix = i.position.top, s._moving = t.type === "dragstart", delete s._lastTried, t.type === "dropover" && s._temporaryRemoved && (this.engine.addNode(s), s._moving = !0), this.engine.cacheRects(r, o, this.opts.marginTop, this.opts.marginRight, this.opts.marginBottom, this.opts.marginLeft), t.type === "resizestart") {
4111
- const d = this.getColumn() - s.x, u = (this.opts.maxRow || Number.MAX_SAFE_INTEGER) - s.y;
4112
- W.resizable(e, "option", "minWidth", r * Math.min(s.minW || 1, d)).resizable(e, "option", "minHeight", o * Math.min(s.minH || 1, u)).resizable(e, "option", "maxWidth", r * Math.min(s.maxW || Number.MAX_SAFE_INTEGER, d)).resizable(e, "option", "maxWidthMoveLeft", r * Math.min(s.maxW || Number.MAX_SAFE_INTEGER, s.x + s.w)).resizable(e, "option", "maxHeight", o * Math.min(s.maxH || Number.MAX_SAFE_INTEGER, u)).resizable(e, "option", "maxHeightMoveUp", o * Math.min(s.maxH || Number.MAX_SAFE_INTEGER, s.y + s.h));
4113
- }
4114
- }
4115
- /** @internal handles actual drag/resize */
4116
- _dragOrResize(e, t, i, s, r, o) {
4117
- const n = { ...s._orig };
4118
- let d, u = this.opts.marginLeft, h = this.opts.marginRight, l = this.opts.marginTop, f = this.opts.marginBottom;
4119
- const g = Math.round(o * 0.1), p = Math.round(r * 0.1);
4120
- if (u = Math.min(u, p), h = Math.min(h, p), l = Math.min(l, g), f = Math.min(f, g), t.type === "drag") {
4121
- if (s._temporaryRemoved)
4122
- return;
4123
- const m = i.position.top - s._prevYPix;
4124
- s._prevYPix = i.position.top, this.opts.draggable.scroll !== !1 && c.updateScrollPosition(e, i.position, m);
4125
- const C = i.position.left + (i.position.left > s._lastUiPosition.left ? -h : u), A = i.position.top + (i.position.top > s._lastUiPosition.top ? -f : l);
4126
- n.x = Math.round(C / r), n.y = Math.round(A / o);
4127
- const D = this._extraDragRow;
4128
- if (this.engine.collide(s, n)) {
4129
- const J = this.getRow();
4130
- let F = Math.max(0, n.y + s.h - J);
4131
- this.opts.maxRow && J + F > this.opts.maxRow && (F = Math.max(0, this.opts.maxRow - J)), this._extraDragRow = F;
4132
- } else
4133
- this._extraDragRow = 0;
4134
- if (this._extraDragRow !== D && this._updateContainerHeight(), s.x === n.x && s.y === n.y)
4135
- return;
4136
- } else if (t.type === "resize") {
4137
- if (n.x < 0 || (c.updateScrollResize(t, e, o), n.w = Math.round((i.size.width - u) / r), n.h = Math.round((i.size.height - l) / o), s.w === n.w && s.h === n.h) || s._lastTried && s._lastTried.w === n.w && s._lastTried.h === n.h)
4138
- return;
4139
- const m = i.position.left + u, C = i.position.top + l;
4140
- n.x = Math.round(m / r), n.y = Math.round(C / o), d = !0;
4141
- }
4142
- s._event = t, s._lastTried = n;
4143
- const y = {
4144
- x: i.position.left + u,
4145
- y: i.position.top + l,
4146
- w: (i.size ? i.size.width : s.w * r) - u - h,
4147
- h: (i.size ? i.size.height : s.h * o) - l - f
4148
- };
4149
- if (this.engine.moveNodeCheck(s, { ...n, cellWidth: r, cellHeight: o, rect: y, resizing: d })) {
4150
- s._lastUiPosition = i.position, this.engine.cacheRects(r, o, l, h, f, u), delete s._skipDown, d && s.subGrid && s.subGrid.onResize(), this._extraDragRow = 0, this._updateContainerHeight();
4151
- const m = t.target;
4152
- s._sidebarOrig || this._writePosAttr(m, s), this._gsEventHandler[t.type] && this._gsEventHandler[t.type](t, m);
4153
- }
4154
- }
4155
- /** @internal called when item leaving our area by either cursor dropout event
4156
- * or shape is outside our boundaries. remove it from us, and mark temporary if this was
4157
- * our item to start with else restore prev node values from prev grid it came from.
4158
- */
4159
- _leave(e, t) {
4160
- t = t || e;
4161
- const i = t.gridstackNode;
4162
- if (!i || (t.style.transform = t.style.transformOrigin = null, W.off(e, "drag"), i._temporaryRemoved))
4163
- return;
4164
- i._temporaryRemoved = !0, this.engine.removeNode(i), i.el = i._isExternal && t ? t : e;
4165
- const s = i._sidebarOrig;
4166
- i._isExternal && this.engine.cleanupNode(i), i._sidebarOrig = s, this.opts.removable === !0 && _._itemRemoving(e, !0), e._gridstackNodeOrig ? (e.gridstackNode = e._gridstackNodeOrig, delete e._gridstackNodeOrig) : i._isExternal && this.engine.restoreInitial();
4167
- }
4168
- // legacy method removed
4169
- commit() {
4170
- return $s(this, this.batchUpdate(!1), "commit", "batchUpdate", "5.2"), this;
4171
- }
4172
- }
4173
- _.renderCB = (a, e) => {
4174
- a && (e != null && e.content) && (a.textContent = e.content);
4175
- };
4176
- _.resizeToContentParent = ".grid-stack-item-content";
4177
- _.Utils = c;
4178
- _.Engine = he;
4179
- _.GDRev = "11.5.1";
4180
- const Gs = ["data-id", "data-testid", "gs-h", "gs-w", "gs-x", "gs-y"], Ws = { class: "grid-stack-item-content" }, Ks = /* @__PURE__ */ V({
4181
- __name: "DraggableGridLayout",
4182
- props: {
4183
- tiles: {},
4184
- tileHeight: { default: Pe }
4185
- },
4186
- emits: ["update-tiles"],
4187
- setup(a, { expose: e, emit: t }) {
4188
- const i = a, s = t, r = L(null), o = L(new Map(i.tiles.map((g) => [`${g.id}`, g])));
4189
- let n = null;
4190
- const d = (g) => `[data-id="${g}"]`, u = (g) => g.map((p) => {
4191
- var m;
4192
- const y = o.value.get(`${(m = p.el) == null ? void 0 : m.getAttribute("data-id")}`);
4193
- if (y)
4194
- return {
4195
- ...y,
4196
- layout: {
4197
- position: { col: Number(p.x), row: Number(p.y) },
4198
- size: { cols: Number(p.w), rows: Number(p.h) }
4199
- }
4200
- };
4201
- }).filter((p) => p !== void 0), h = (g, p) => {
4202
- n && (u(p).forEach((m) => {
4203
- o.value.set(`${m.id}`, m);
4204
- }), s("update-tiles", Array.from(o.value.values())));
4205
- }, l = (g, p) => {
4206
- p.forEach((y) => {
4207
- var m;
4208
- o.value.delete(`${(m = y.el) == null ? void 0 : m.getAttribute("data-id")}`);
4209
- }), s("update-tiles", Array.from(o.value.values()));
4210
- };
4211
- Xe(() => {
4212
- r.value && (n = _.init({
4213
- margin: 10,
4214
- column: ct,
4215
- cellHeight: i.tileHeight,
4216
- resizable: { handles: "se, sw" },
4217
- handle: ".tile-header"
4218
- }, r.value), n.on("change", h), n.on("added", h), n.on("removed", l));
4219
- }), Ze(() => {
4220
- n && n.destroy(!1);
4221
- });
4222
- const f = (g) => {
4223
- if (n && r.value) {
4224
- const p = r.value.querySelector(d(g));
4225
- p && n.removeWidget(p);
4226
- }
4227
- };
4228
- return Se(() => i.tiles.length, async (g, p) => {
4229
- if (g > p && n) {
4230
- const y = i.tiles.slice(p);
4231
- for (const m of y)
4232
- o.value.set(`${m.id}`, m), await dt(), n.makeWidget(d(m.id), {
4233
- autoPosition: !0,
4234
- w: m.layout.size.cols,
4235
- h: m.layout.size.rows
4236
- });
4237
- }
4238
- }), Ot(() => {
4239
- i.tiles.forEach((g) => {
4240
- o.value.set(`${g.id}`, g);
4241
- });
4242
- }), e({ removeWidget: f }), (g, p) => (x(), G("div", {
4243
- ref_key: "gridContainer",
4244
- ref: r,
4245
- class: "grid-stack"
4246
- }, [
4247
- (x(!0), G(Pt, null, $t(i.tiles, (y) => (x(), G("div", {
4248
- key: y.id,
4249
- class: "grid-stack-item",
4250
- "data-id": `${y.id}`,
4251
- "data-testid": `grid-stack-item-${y.id}`,
4252
- "gs-h": y.layout.size.rows,
4253
- "gs-lazy-load": !0,
4254
- "gs-w": y.layout.size.cols,
4255
- "gs-x": y.layout.position.col,
4256
- "gs-y": y.layout.position.row
4257
- }, [
4258
- se("div", Ws, [
4259
- ze(g.$slots, "tile", { tile: y }, void 0, !0)
4260
- ])
4261
- ], 8, Gs))), 128))
4262
- ], 512));
4263
- }
4264
- }), Qs = /* @__PURE__ */ _e(Ks, [["__scopeId", "data-v-a68d6821"]]), Vs = {
4265
- key: 0,
4266
- class: "fullscreen-header"
4267
- }, Ys = {
4268
- key: 0,
4269
- class: "tile-container slottable-tile"
4270
- }, js = /* @__PURE__ */ V({
4271
- __name: "DashboardRenderer",
4272
- props: /* @__PURE__ */ Ge({
4273
- context: {}
4274
- }, {
4275
- modelValue: { required: !0 },
4276
- modelModifiers: {}
4277
- }),
4278
- emits: /* @__PURE__ */ Ge(["edit-tile", "tile-time-range-zoom"], ["update:modelValue"]),
4279
- setup(a, { expose: e, emit: t }) {
4280
- ut((R) => ({
4281
- v019a5586: l.value
4282
- }));
4283
- const i = a, s = t, r = Mt(a, "modelValue"), { i18n: o } = me.useI18n(), n = L(0), d = L(null), u = L(), h = L(), l = L("scale(1)"), f = ve(ye);
4284
- f || (console.warn("Analytics dashboards require a query bridge supplied via provide / inject."), console.warn("Please ensure your application has a query bridge provided under the key 'analytics-query-provider', as described in"), console.warn("https://github.com/Kong/public-ui-components/blob/main/packages/analytics/dashboard-renderer/README.md#requirements")), me.useRequestQueue();
4285
- const g = qe(), p = k(() => i.context.timeSpec ? i.context.timeSpec : {
4286
- type: "relative",
4287
- time_range: g.defaultQueryTimeForOrg
4288
- }), y = k(() => !!i.context.timeSpec || !g.loading), m = (R, I) => {
4289
- const $ = R.layout.position.row - I.layout.position.row;
4290
- return $ !== 0 ? $ : R.layout.position.col - I.layout.position.col;
4291
- }, C = k(() => r.value.tiles.map((R) => {
4292
- var $;
4293
- let I = R.definition;
4294
- if ("description" in I.chart) {
4295
- const q = ($ = I.chart.description) == null ? void 0 : $.replace(Zi, () => {
4296
- const ke = `renderer.trendRange.${p.value.type === "absolute" ? "custom" : p.value.time_range}`;
4297
- return o.te(ke) ? o.t(ke) : "";
4298
- });
4299
- I = {
4300
- ...I,
4301
- chart: {
4302
- ...I.chart,
4303
- description: q
4304
- }
4305
- };
4306
- }
4307
- return i.context.editable && !R.id && console.warn(
4308
- "No id provided for tile. One will be generated automatically,",
4309
- "however tracking changes to this tile may not work as expected.",
4310
- R
4311
- ), {
4312
- layout: R.layout,
4313
- meta: I,
4314
- type: R.type,
4315
- // Add a unique key to each tile internally.
4316
- id: R.id ?? crypto.randomUUID()
4317
- };
4318
- })), A = (R) => {
4319
- s("edit-tile", R);
4320
- }, D = (R) => R.type === "slottable", J = (R) => {
4321
- const I = D(R.meta.chart) ? { ...R.meta.chart } : {
4322
- ...R.meta.chart,
4323
- chart_title: R.meta.chart.chart_title ? `Copy of ${R.meta.chart.chart_title}` : ""
4324
- }, $ = {
4325
- id: crypto.randomUUID(),
4326
- type: "chart",
4327
- definition: {
4328
- ...R.meta,
4329
- chart: I
4330
- },
4331
- layout: {
4332
- position: {
4333
- col: 0,
4334
- row: 0
4335
- },
4336
- size: R.layout.size
4337
- }
4338
- };
4339
- r.value.tiles.push($);
4340
- }, F = (R) => {
4341
- d.value && d.value.removeWidget(R.id);
4342
- }, S = () => {
4343
- n.value++;
4344
- }, H = (R) => {
4345
- const I = R.map(($) => ({
4346
- id: $.id,
4347
- type: $.type,
4348
- layout: $.layout,
4349
- definition: $.meta
4350
- }));
4351
- r.value.tiles = I.sort(m);
4352
- }, Y = async () => {
4353
- if (l.value = "scale(1)", await dt(), h.value) {
4354
- const { availWidth: R, availHeight: I } = window.screen, { width: $, height: q } = h.value.getBoundingClientRect(), j = Math.min(I / q, R / $);
4355
- l.value = `scale(${j})`;
4356
- }
4357
- }, de = () => {
4358
- u.value && (document.fullscreenElement ? document.exitFullscreen() : u.value.requestFullscreen());
4359
- }, ne = L(!1), Re = () => {
4360
- ne.value = document.fullscreenElement !== null, ne.value && Y();
4361
- }, tt = k(() => r.value.preset_filters ?? []), { internalContext: $e } = me.useDashboardInternalContext({
4362
- globalFilters: tt,
4363
- context: Ne(i, "context"),
4364
- isFullscreen: ne
4365
- });
4366
- return e({
4367
- refresh: S,
4368
- toggleFullscreen: de
4369
- }), (R, I) => {
4370
- const $ = ge("KAlert");
4371
- return x(), G("div", {
4372
- ref_key: "dashboardContainer",
4373
- ref: u,
4374
- class: De(["kong-ui-public-dashboard-renderer", { "is-fullscreen": ne.value }]),
4375
- onFullscreenchange: Re
4376
- }, [
4377
- se("div", {
4378
- ref_key: "layoutContainer",
4379
- ref: h,
4380
- class: "layout"
4381
- }, [
4382
- E(f) && ne.value ? (x(), G("div", Vs, [
4383
- ze(R.$slots, "fullscreenHeader", {}, void 0, !0)
4384
- ])) : K("", !0),
4385
- E(f) ? (x(), O(qt(a.context.editable && !ne.value ? Qs : Ps), {
4386
- key: 2,
4387
- ref_key: "gridLayoutRef",
4388
- ref: d,
4389
- "tile-height": r.value.tile_height,
4390
- tiles: C.value,
4391
- onUpdateTiles: H
4392
- }, {
4393
- tile: P(({ tile: q }) => [
4394
- q.meta.chart.type === "slottable" ? (x(), G("div", Ys, [
4395
- ze(R.$slots, q.meta.chart.id, {}, void 0, !0)
4396
- ])) : (x(), O(Zt, {
4397
- key: ne.value ? `${q.id}-tile` : `${q.id}-tile-fullscreen`,
4398
- "refresh-counter": n.value,
4399
- "onUpdate:refreshCounter": I[0] || (I[0] = (j) => n.value = j),
4400
- class: "tile-container",
4401
- context: E($e),
4402
- definition: q.meta,
4403
- height: q.layout.size.rows * (r.value.tile_height || E(Pe)) + parseInt(E(Xt), 10),
4404
- "is-fullscreen": ne.value,
4405
- "query-ready": y.value,
4406
- "tile-id": q.id,
4407
- onDuplicateTile: (j) => J(q),
4408
- onEditTile: (j) => A(q),
4409
- onRemoveTile: (j) => F(q),
4410
- onTileTimeRangeZoom: I[1] || (I[1] = (j) => s("tile-time-range-zoom", j))
4411
- }, null, 8, ["refresh-counter", "context", "definition", "height", "is-fullscreen", "query-ready", "tile-id", "onDuplicateTile", "onEditTile", "onRemoveTile"]))
4412
- ]),
4413
- _: 3
4414
- }, 40, ["tile-height", "tiles"])) : (x(), O($, {
4415
- key: 1,
4416
- appearance: "danger"
4417
- }, {
4418
- default: P(() => [
4419
- ht(ae(E(o).t("renderer.noQueryBridge")), 1)
4420
- ]),
4421
- _: 1
4422
- }))
4423
- ], 512)
4424
- ], 34);
4425
- };
4426
- }
4427
- }), ur = /* @__PURE__ */ _e(js, [["__scopeId", "data-v-1fc40e84"]]), dr = /* @__PURE__ */ V({
4428
- __name: "DashboardTilePreview",
4429
- props: {
4430
- context: {},
4431
- definition: {},
4432
- globalFilters: { default: () => [] }
4433
- },
4434
- emits: ["tile-time-range-zoom", "tile-bounds-change"],
4435
- setup(a, { expose: e, emit: t }) {
4436
- const i = _i("root"), s = crypto.randomUUID(), r = t, o = (y) => {
4437
- r("tile-time-range-zoom", y);
4438
- }, n = (y) => {
4439
- r("tile-bounds-change", y);
4440
- }, { internalContext: d } = me.useDashboardInternalContext({
4441
- globalFilters: Ne(() => a.globalFilters),
4442
- context: Ne(() => a.context)
4443
- }), u = qe(), h = k(() => !!a.context.timeSpec || !u.loading), l = L(Pe);
4444
- let f;
4445
- Xe(() => {
4446
- var m;
4447
- const y = (m = i.value) == null ? void 0 : m.parentElement;
4448
- y && (l.value = y.getBoundingClientRect().height, f = new ResizeObserver(([C]) => {
4449
- const { height: A } = C.contentRect;
4450
- l.value = A;
4451
- }), f.observe(y));
4452
- }), Ze(() => f == null ? void 0 : f.disconnect());
4453
- const g = L(0);
4454
- return e({
4455
- refresh: () => {
4456
- g.value++;
4457
- }
4458
- }), (y, m) => (x(), G("div", {
4459
- ref_key: "root",
4460
- ref: i,
4461
- "data-testid": "dashboard-tile-preview-root"
4462
- }, [
4463
- re(Zt, {
4464
- "refresh-counter": g.value,
4465
- "onUpdate:refreshCounter": m[0] || (m[0] = (C) => g.value = C),
4466
- context: {
4467
- ...E(d),
4468
- editable: !1
4469
- },
4470
- definition: a.definition,
4471
- height: l.value,
4472
- "hide-actions": "",
4473
- "query-ready": h.value,
4474
- "show-refresh": "",
4475
- "tile-id": E(s),
4476
- onTileBoundsChange: n,
4477
- onTileTimeRangeZoom: o
4478
- }, null, 8, ["refresh-counter", "context", "definition", "height", "query-ready", "tile-id"])
4479
- ], 512));
4480
- }
4481
- }), Xs = (a) => {
4482
- var t;
4483
- const e = (t = a.definition) == null ? void 0 : t.query;
4484
- if (!e)
4485
- return a;
4486
- if (e.datasource === "api_usage") {
4487
- console.warn("[@kong-ui-public/dashboard-renderer] A tile was filtered out for the Basic Tier", a);
4488
- return;
4489
- }
4490
- return a;
4491
- }, Zs = (a) => {
4492
- var i;
4493
- const e = (i = a.definition) == null ? void 0 : i.query;
4494
- if (!e)
4495
- return a;
4496
- const t = {
4497
- ...e,
4498
- datasource: e.datasource === "basic" ? "api_usage" : e.datasource
4499
- };
4500
- return {
4501
- ...a,
4502
- definition: {
4503
- ...a.definition,
4504
- query: t
4505
- }
4506
- };
4507
- }, Js = (a) => {
4508
- var r, o, n, d, u;
4509
- if (!a.length)
4510
- return [];
4511
- let e = 0, t = 0, i = 0;
4512
- const s = [];
4513
- for (const h of a) {
4514
- const l = ((o = (r = h.layout) == null ? void 0 : r.size) == null ? void 0 : o.cols) ?? 1, f = ((d = (n = h.layout) == null ? void 0 : n.size) == null ? void 0 : d.rows) ?? 1;
4515
- t + l > ct && (e += i, t = 0, i = 0);
4516
- const g = {
4517
- ...h,
4518
- layout: {
4519
- ...h.layout,
4520
- position: {
4521
- ...((u = h.layout) == null ? void 0 : u.position) ?? {},
4522
- col: t,
4523
- row: e
4524
- }
4525
- }
4526
- };
4527
- s.push(g), t += l, i = Math.max(i, f);
4528
- }
4529
- return s;
4530
- }, cr = (a, e) => {
4531
- if (e) {
4532
- const s = a.tiles.map(Zs);
4533
- return {
4534
- ...a,
4535
- tiles: s
4536
- };
4537
- }
4538
- const t = a.tiles.map(Xs).filter((s) => s !== void 0), i = Js(t);
4539
- return {
4540
- ...a,
4541
- tiles: i
4542
- };
4543
- };
4544
- export {
4545
- Xi as C,
4546
- ur as D,
4547
- Et as E,
4548
- es as F,
4549
- Ps as G,
4550
- ye as I,
4551
- Zi as T,
4552
- ft as _,
4553
- dr as a,
4554
- Pe as b,
4555
- ct as c,
4556
- Ji as d,
4557
- ts as e,
4558
- cr as f
4559
- };