@logimaxx/kgrid 0.5.2 → 0.5.4

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.
@@ -307,50 +307,53 @@
307
307
  return merged;
308
308
  };
309
309
 
310
- CT.applyLayoutToDom = function ($table, columns, options) {
311
- if (!$table || !$table.length) {
310
+ CT.applyLayoutToRow = function ($row, columns) {
311
+ if (!$row || !$row.length) {
312
312
  return;
313
313
  }
314
- const order = CT.chooserColumns(columns).map(function (col) {
314
+ const chooser = CT.chooserColumns(columns);
315
+ const order = chooser.map(function (col) {
315
316
  return col.name;
316
317
  });
317
318
  const hidden = {};
318
- CT.chooserColumns(columns).forEach(function (col) {
319
+ chooser.forEach(function (col) {
319
320
  if (col.userHidden) {
320
321
  hidden[col.name] = true;
321
322
  }
322
323
  });
324
+ const $action = $row.children(".kgrid-row-actions");
325
+ const byName = {};
326
+ $row.children("[data-name]").each(function () {
327
+ byName[this.getAttribute("data-name")] = this;
328
+ });
329
+ order.forEach(function (name) {
330
+ const el = byName[name];
331
+ if (!el) {
332
+ return;
333
+ }
334
+ if ($action.length) {
335
+ $(el).insertBefore($action);
336
+ } else {
337
+ $row.append(el);
338
+ }
339
+ el.classList.toggle("kgrid-user-hidden", !!hidden[name]);
340
+ });
341
+ };
342
+
343
+ CT.applyLayoutToDom = function ($table, columns, options) {
344
+ if (!$table || !$table.length) {
345
+ return;
346
+ }
323
347
  const $rows = $table.find(
324
348
  ".thead-labels tr, .thead-filters tr, .before-main-tbody tr, .main-tbody tr, .after-main-tbody tr"
325
349
  );
326
350
  $rows.each(function () {
327
- const $row = $(this);
328
- const $action = $row.children(".kgrid-row-actions");
329
- const byName = {};
330
- $row.children("[data-name]").each(function () {
331
- byName[this.getAttribute("data-name")] = this;
332
- });
333
- order.forEach(function (name) {
334
- const el = byName[name];
335
- if (!el) {
336
- return;
337
- }
338
- if ($action.length) {
339
- $(el).insertBefore($action);
340
- } else {
341
- $row.append(el);
342
- }
343
- el.classList.toggle("kgrid-user-hidden", !!hidden[name]);
344
- });
351
+ CT.applyLayoutToRow($(this), columns);
345
352
  });
353
+ const visible = CT.layoutVisibleColumns(columns);
346
354
  const hasActions = $table.find(".kgrid-row-actions").length > 0;
347
- CT.syncActionColumnColgroup(
348
- $table,
349
- order.length,
350
- hasActions,
351
- options,
352
- CT.chooserColumns(columns)
353
- );
355
+ CT.syncActionColumnColgroup($table, visible.length, hasActions, options, visible);
356
+ CT.syncSpanningCells($table, CT.participatingColumnCount(columns, hasActions));
354
357
  };
355
358
 
356
359
  CT.refreshCollectionTemplate = function (api, options) {
@@ -213,39 +213,70 @@
213
213
  return (2.5 * n + 0.75).toFixed(2) + "rem";
214
214
  };
215
215
 
216
- CT.getBootstrapDropdown = function () {
217
- const bs =
218
- (typeof bootstrap !== "undefined" && bootstrap) ||
219
- (typeof window !== "undefined" && window.bootstrap) ||
220
- null;
221
- return bs && bs.Dropdown ? bs.Dropdown : null;
216
+ CT.closeRowActionDropdowns = function ($exceptMenu) {
217
+ $(".kgrid-row-actions-menu").each(function () {
218
+ const $wrap = $(this);
219
+ const $menu = $wrap.children(".dropdown-menu");
220
+ if ($exceptMenu && $menu[0] === $exceptMenu[0]) {
221
+ return;
222
+ }
223
+ $menu.removeClass("show").css({ top: "", left: "", right: "", position: "" });
224
+ $wrap.children(".kgrid-actions-dropdown-toggle").attr("aria-expanded", "false").removeClass("show");
225
+ });
222
226
  };
223
227
 
224
228
  /**
225
- * Init Bootstrap dropdowns with fixed Popper strategy (avoids table clipping / click-through).
226
- * Do not use data-bs-popper-config — Bootstrap may treat the attribute as a raw string.
229
+ * Wire row-action kebab menus. Uses a small jQuery toggle (not Bootstrap Dropdown)
230
+ * so we do not depend on data-api / popperConfig quirks; menu is position:fixed while open.
227
231
  * @param {JQuery} $root
228
232
  */
229
233
  CT.mountRowActionDropdowns = function ($root) {
230
234
  if (!$root || !$root.length) {
231
235
  return;
232
236
  }
233
- const Dropdown = CT.getBootstrapDropdown();
234
- if (!Dropdown) {
235
- return;
237
+ if (!CT._rowActionsDropdownDocBound) {
238
+ CT._rowActionsDropdownDocBound = true;
239
+ $(document)
240
+ .on("click.kgridRowActions", function () {
241
+ CT.closeRowActionDropdowns();
242
+ })
243
+ .on("keydown.kgridRowActions", function (e) {
244
+ if (e.key === "Escape") {
245
+ CT.closeRowActionDropdowns();
246
+ }
247
+ });
236
248
  }
237
249
  $root.find(".kgrid-row-actions-menu > .kgrid-actions-dropdown-toggle").each(function () {
238
- const el = this;
239
- const prev = Dropdown.getInstance(el);
240
- if (prev) {
241
- prev.dispose();
242
- }
243
- new Dropdown(el, {
244
- popperConfig: function (defaultConfig) {
245
- const next = defaultConfig && typeof defaultConfig === "object" ? { ...defaultConfig } : {};
246
- next.strategy = "fixed";
247
- return next;
248
- },
250
+ const toggle = this;
251
+ const $toggle = $(toggle);
252
+ const $wrap = $toggle.parent(".kgrid-row-actions-menu");
253
+ const $menu = $wrap.children(".dropdown-menu");
254
+ $toggle.off("click.kgridRowActions").on("click.kgridRowActions", function (event) {
255
+ event.preventDefault();
256
+ event.stopPropagation();
257
+ const willOpen = !$menu.hasClass("show");
258
+ CT.closeRowActionDropdowns();
259
+ if (!willOpen) {
260
+ return;
261
+ }
262
+ const rect = toggle.getBoundingClientRect();
263
+ $menu.addClass("show").css({
264
+ position: "fixed",
265
+ top: Math.round(rect.bottom + 2) + "px",
266
+ left: "auto",
267
+ right: Math.round(window.innerWidth - rect.right) + "px",
268
+ zIndex: 1055,
269
+ });
270
+ $toggle.addClass("show").attr("aria-expanded", "true");
271
+ });
272
+ $menu.off("click.kgridRowActions").on("click.kgridRowActions", function (event) {
273
+ event.stopPropagation();
274
+ });
275
+ $menu.find(".dropdown-item").off("click.kgridRowActionsClose").on("click.kgridRowActionsClose", function () {
276
+ // Close after the action click handlers (same tick is fine).
277
+ setTimeout(function () {
278
+ CT.closeRowActionDropdowns();
279
+ }, 0);
249
280
  });
250
281
  });
251
282
  };
@@ -369,8 +400,9 @@
369
400
  }
370
401
  });
371
402
  } else {
403
+ // span (not div): stay on one horizontal line with sibling actions
372
404
  idleItems.forEach(function (item) {
373
- const $grp = $("<div>")
405
+ const $grp = $("<span>")
374
406
  .addClass(item.groupClass || "btn-group kgrid-custom-action-grp")
375
407
  .appendTo($buttonColumn);
376
408
  if (item.when === "always") {
@@ -382,7 +414,7 @@
382
414
 
383
415
  const editingAll = ra.editingItems.concat(editingExtras);
384
416
  if (editingAll.length) {
385
- const $grp = $("<div>").addClass("btn-group edit-item-grp").appendTo($buttonColumn);
417
+ const $grp = $("<span>").addClass("btn-group edit-item-grp").appendTo($buttonColumn);
386
418
  editingAll.forEach(function (item) {
387
419
  appendButton($grp, item, dataRowFormId);
388
420
  });