@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.
package/AGENTS.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  **Proprietary (Logimaxx System SRL, Sergiu Voicu).** Maintainer: sergiu@logimaxx.ro — https://logimaxx.ro. Do not suggest open-sourcing, public npm publish, or MIT licensing unless explicitly requested. Branding: [NOTICE.md](NOTICE.md).
4
4
 
5
+ **Consumers (MaxxOps, etc.):** never vendor a local tarball or `file:` path for `@logimaxx/kgrid`. Publish to npm, then bump the app to that version. Local `file:../kgrid` is for throwaway experiments only — not commits or Coolify deploys.
6
+
5
7
  When changing this repository or integrating **@logimaxx/kgrid** in another app, read:
6
8
 
7
9
  **[docs/ai-guide.md](docs/ai-guide.md)** — integration checklist, config shape, DOM/CSS contract, pitfalls.
package/README.md CHANGED
@@ -106,7 +106,7 @@ const grid = await KGrid.init(document.getElementById("table-host"), {
106
106
  | `KGrid.init(host, opts)` | Empty host or existing `<table>`; returns grid API |
107
107
  | `KGrid.TABLE_SHELL_TEMPLATE` | Default table HTML (editable) |
108
108
  | `KGrid.hasActionColumn(opts)` | Whether a trailing row-actions column is rendered |
109
- | `opts.rowActions` | `{ display, items }` for delete/clone/custom; save/cancel from `features.update` |
109
+ | `opts.rowActions` | `{ display, items }` for delete/clone/custom; kebab menus are KGrid-toggled (`position:fixed`), not Bootstrap Dropdown |
110
110
  | `KGrid.registerFieldType(name, plugin)` | Custom filter/insert/update widgets |
111
111
  | `grid.setInteraction('view' \| 'edit')` | View or edit; menu actions can stay visible in view |
112
112
  | `grid.getLayout()` / `setLayout()` / `resetLayout()` | Column order and user-hidden columns |
package/dist/kgrid.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-09-16T18:50:49.507Z */
1
+ /*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-09-30T07:34:42.692Z */
2
2
 
3
3
  /* --- configure.js --- */
4
4
  /**
@@ -425,12 +425,61 @@
425
425
  return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
426
426
  };
427
427
 
428
+ /** CSS width for a visible column from `attrs.width` (px if numeric). */
429
+ CT.columnWidthCss = function (col) {
430
+ if (!col || !col.attrs) {
431
+ return null;
432
+ }
433
+ const w = col.attrs.width;
434
+ if (w == null || w === "") {
435
+ return null;
436
+ }
437
+ if (typeof w === "number" || /^\d+(\.\d+)?$/.test(String(w))) {
438
+ return String(w) + "px";
439
+ }
440
+ return String(w);
441
+ };
442
+
443
+ /** Copy `col.attrs` onto a cell, except layout `width` (that belongs on `<col>`). */
444
+ CT.applyColumnDomAttrs = function ($el, col) {
445
+ const attrs = col && col.attrs && typeof col.attrs === "object" ? col.attrs : null;
446
+ if (!attrs) {
447
+ return $el;
448
+ }
449
+ Object.keys(attrs).forEach(function (attr) {
450
+ if (attr === "width") {
451
+ return;
452
+ }
453
+ $el.attr(attr, attrs[attr]);
454
+ });
455
+ return $el;
456
+ };
457
+
458
+ /**
459
+ * Columns that occupy a table-layout slot (named, not schema-hidden, not user-hidden).
460
+ * `display:none` cells do not participate, so colgroup must list only these.
461
+ */
462
+ CT.layoutVisibleColumns = function (columns) {
463
+ return (columns || []).filter(function (col) {
464
+ return col && col.name && !col.hidden && !col.userHidden;
465
+ });
466
+ };
467
+
468
+ /** Header/body/footer participating column count (visible data + optional actions). */
469
+ CT.participatingColumnCount = function (columns, hasActions) {
470
+ return CT.layoutVisibleColumns(columns).length + (hasActions ? 1 : 0);
471
+ };
472
+
428
473
  /**
429
- * Sync <colgroup> so row-actions width can collapse in view (table-layout: fixed).
474
+ * Sync <colgroup> for `table-layout: fixed`.
475
+ * One `<col>` per participating data column, then optional row-actions.
476
+ * Never emit a col for user-hidden fields: `display:none` cells skip a slot,
477
+ * so a leftover col (even width 0) remaps every following cell onto the wrong width.
430
478
  * @param {JQuery} $table
431
- * @param {number} dataColumnCount visible data columns (no row-actions)
479
+ * @param {number} dataColumnCount participating data columns (no row-actions)
432
480
  * @param {boolean} hasActions
433
481
  * @param {Object} [options] table options (for action column width)
482
+ * @param {Array} [layoutColumns] column objects in display order; userHidden entries are skipped
434
483
  */
435
484
  CT.syncActionColumnColgroup = function ($table, dataColumnCount, hasActions, options, layoutColumns) {
436
485
  let $colgroup = $table.children("colgroup.kgrid-colgroup");
@@ -439,20 +488,27 @@
439
488
  }
440
489
  $colgroup.empty();
441
490
  const named = Array.isArray(layoutColumns) ? layoutColumns : null;
491
+ let emitted = 0;
442
492
  if (named && named.length) {
443
493
  named.forEach(function (col) {
494
+ if (col && col.userHidden) {
495
+ return;
496
+ }
444
497
  const $col = $("<col>");
445
498
  if (col && col.name) {
446
499
  $col.attr("data-name", col.name);
447
500
  }
448
- if (col && col.userHidden) {
449
- $col.addClass("kgrid-user-hidden");
501
+ const cssW = CT.columnWidthCss(col);
502
+ if (cssW) {
503
+ $col.css("width", cssW);
450
504
  }
451
505
  $colgroup.append($col);
506
+ emitted += 1;
452
507
  });
453
508
  } else {
454
509
  for (let i = 0; i < dataColumnCount; i++) {
455
510
  $colgroup.append($("<col>"));
511
+ emitted += 1;
456
512
  }
457
513
  }
458
514
  if (hasActions) {
@@ -462,6 +518,14 @@
462
518
  .css("width", CT.actionColumnWidth(options))
463
519
  );
464
520
  }
521
+ return emitted;
522
+ };
523
+
524
+ CT.syncSpanningCells = function ($table, span) {
525
+ if (!$table || !$table.length || !span) {
526
+ return;
527
+ }
528
+ $table.find(".paging-footer td, .no-data-tbody td").attr("colspan", span);
465
529
  };
466
530
 
467
531
  /**
@@ -741,39 +805,70 @@
741
805
  return (2.5 * n + 0.75).toFixed(2) + "rem";
742
806
  };
743
807
 
744
- CT.getBootstrapDropdown = function () {
745
- const bs =
746
- (typeof bootstrap !== "undefined" && bootstrap) ||
747
- (typeof window !== "undefined" && window.bootstrap) ||
748
- null;
749
- return bs && bs.Dropdown ? bs.Dropdown : null;
808
+ CT.closeRowActionDropdowns = function ($exceptMenu) {
809
+ $(".kgrid-row-actions-menu").each(function () {
810
+ const $wrap = $(this);
811
+ const $menu = $wrap.children(".dropdown-menu");
812
+ if ($exceptMenu && $menu[0] === $exceptMenu[0]) {
813
+ return;
814
+ }
815
+ $menu.removeClass("show").css({ top: "", left: "", right: "", position: "" });
816
+ $wrap.children(".kgrid-actions-dropdown-toggle").attr("aria-expanded", "false").removeClass("show");
817
+ });
750
818
  };
751
819
 
752
820
  /**
753
- * Init Bootstrap dropdowns with fixed Popper strategy (avoids table clipping / click-through).
754
- * Do not use data-bs-popper-config — Bootstrap may treat the attribute as a raw string.
821
+ * Wire row-action kebab menus. Uses a small jQuery toggle (not Bootstrap Dropdown)
822
+ * so we do not depend on data-api / popperConfig quirks; menu is position:fixed while open.
755
823
  * @param {JQuery} $root
756
824
  */
757
825
  CT.mountRowActionDropdowns = function ($root) {
758
826
  if (!$root || !$root.length) {
759
827
  return;
760
828
  }
761
- const Dropdown = CT.getBootstrapDropdown();
762
- if (!Dropdown) {
763
- return;
829
+ if (!CT._rowActionsDropdownDocBound) {
830
+ CT._rowActionsDropdownDocBound = true;
831
+ $(document)
832
+ .on("click.kgridRowActions", function () {
833
+ CT.closeRowActionDropdowns();
834
+ })
835
+ .on("keydown.kgridRowActions", function (e) {
836
+ if (e.key === "Escape") {
837
+ CT.closeRowActionDropdowns();
838
+ }
839
+ });
764
840
  }
765
841
  $root.find(".kgrid-row-actions-menu > .kgrid-actions-dropdown-toggle").each(function () {
766
- const el = this;
767
- const prev = Dropdown.getInstance(el);
768
- if (prev) {
769
- prev.dispose();
770
- }
771
- new Dropdown(el, {
772
- popperConfig: function (defaultConfig) {
773
- const next = defaultConfig && typeof defaultConfig === "object" ? { ...defaultConfig } : {};
774
- next.strategy = "fixed";
775
- return next;
776
- },
842
+ const toggle = this;
843
+ const $toggle = $(toggle);
844
+ const $wrap = $toggle.parent(".kgrid-row-actions-menu");
845
+ const $menu = $wrap.children(".dropdown-menu");
846
+ $toggle.off("click.kgridRowActions").on("click.kgridRowActions", function (event) {
847
+ event.preventDefault();
848
+ event.stopPropagation();
849
+ const willOpen = !$menu.hasClass("show");
850
+ CT.closeRowActionDropdowns();
851
+ if (!willOpen) {
852
+ return;
853
+ }
854
+ const rect = toggle.getBoundingClientRect();
855
+ $menu.addClass("show").css({
856
+ position: "fixed",
857
+ top: Math.round(rect.bottom + 2) + "px",
858
+ left: "auto",
859
+ right: Math.round(window.innerWidth - rect.right) + "px",
860
+ zIndex: 1055,
861
+ });
862
+ $toggle.addClass("show").attr("aria-expanded", "true");
863
+ });
864
+ $menu.off("click.kgridRowActions").on("click.kgridRowActions", function (event) {
865
+ event.stopPropagation();
866
+ });
867
+ $menu.find(".dropdown-item").off("click.kgridRowActionsClose").on("click.kgridRowActionsClose", function () {
868
+ // Close after the action click handlers (same tick is fine).
869
+ setTimeout(function () {
870
+ CT.closeRowActionDropdowns();
871
+ }, 0);
777
872
  });
778
873
  });
779
874
  };
@@ -897,8 +992,9 @@
897
992
  }
898
993
  });
899
994
  } else {
995
+ // span (not div): stay on one horizontal line with sibling actions
900
996
  idleItems.forEach(function (item) {
901
- const $grp = $("<div>")
997
+ const $grp = $("<span>")
902
998
  .addClass(item.groupClass || "btn-group kgrid-custom-action-grp")
903
999
  .appendTo($buttonColumn);
904
1000
  if (item.when === "always") {
@@ -910,7 +1006,7 @@
910
1006
 
911
1007
  const editingAll = ra.editingItems.concat(editingExtras);
912
1008
  if (editingAll.length) {
913
- const $grp = $("<div>").addClass("btn-group edit-item-grp").appendTo($buttonColumn);
1009
+ const $grp = $("<span>").addClass("btn-group edit-item-grp").appendTo($buttonColumn);
914
1010
  editingAll.forEach(function (item) {
915
1011
  appendButton($grp, item, dataRowFormId);
916
1012
  });
@@ -1692,9 +1788,7 @@
1692
1788
  }
1693
1789
 
1694
1790
  let cell = labelTemplate.clone(true);
1695
- if (col.attrs && typeof col.attrs === "object") {
1696
- Object.keys(col.attrs).forEach((attr) => cell.attr(attr, col.attrs[attr]));
1697
- }
1791
+ CT.applyColumnDomAttrs(cell, col);
1698
1792
  CT.applyColumnCellMeta(cell, col);
1699
1793
 
1700
1794
  if (!col.features?.sort) {
@@ -2195,8 +2289,7 @@
2195
2289
  const $cell = $("<td>").attr("data-label", col.label);
2196
2290
  CT.applyColumnCellMeta($cell, col);
2197
2291
 
2198
- const attrs = (c.attrs && typeof c.attrs==="object") ? c.attrs : {};
2199
- Object.keys(attrs).forEach(attr => $cell.attr(attr, attrs[attr]));
2292
+ CT.applyColumnDomAttrs($cell, c);
2200
2293
 
2201
2294
  let cellContent = $("<div>").addClass("cell-content");
2202
2295
  cellContent.html(c.display.template ?? `{{${c.name}}}`);
@@ -2580,6 +2673,9 @@
2580
2673
  */
2581
2674
  CT.setupEvents = function (item, table, options, colMap) {
2582
2675
  const view = item.views[0];
2676
+ if (view && view.el && typeof CT.applyLayoutToRow === "function") {
2677
+ CT.applyLayoutToRow(view.el, options.columns);
2678
+ }
2583
2679
 
2584
2680
  options.columns.forEach(col=>{
2585
2681
  col.display.events.forEach(event=>{
@@ -3032,50 +3128,53 @@
3032
3128
  return merged;
3033
3129
  };
3034
3130
 
3035
- CT.applyLayoutToDom = function ($table, columns, options) {
3036
- if (!$table || !$table.length) {
3131
+ CT.applyLayoutToRow = function ($row, columns) {
3132
+ if (!$row || !$row.length) {
3037
3133
  return;
3038
3134
  }
3039
- const order = CT.chooserColumns(columns).map(function (col) {
3135
+ const chooser = CT.chooserColumns(columns);
3136
+ const order = chooser.map(function (col) {
3040
3137
  return col.name;
3041
3138
  });
3042
3139
  const hidden = {};
3043
- CT.chooserColumns(columns).forEach(function (col) {
3140
+ chooser.forEach(function (col) {
3044
3141
  if (col.userHidden) {
3045
3142
  hidden[col.name] = true;
3046
3143
  }
3047
3144
  });
3145
+ const $action = $row.children(".kgrid-row-actions");
3146
+ const byName = {};
3147
+ $row.children("[data-name]").each(function () {
3148
+ byName[this.getAttribute("data-name")] = this;
3149
+ });
3150
+ order.forEach(function (name) {
3151
+ const el = byName[name];
3152
+ if (!el) {
3153
+ return;
3154
+ }
3155
+ if ($action.length) {
3156
+ $(el).insertBefore($action);
3157
+ } else {
3158
+ $row.append(el);
3159
+ }
3160
+ el.classList.toggle("kgrid-user-hidden", !!hidden[name]);
3161
+ });
3162
+ };
3163
+
3164
+ CT.applyLayoutToDom = function ($table, columns, options) {
3165
+ if (!$table || !$table.length) {
3166
+ return;
3167
+ }
3048
3168
  const $rows = $table.find(
3049
3169
  ".thead-labels tr, .thead-filters tr, .before-main-tbody tr, .main-tbody tr, .after-main-tbody tr"
3050
3170
  );
3051
3171
  $rows.each(function () {
3052
- const $row = $(this);
3053
- const $action = $row.children(".kgrid-row-actions");
3054
- const byName = {};
3055
- $row.children("[data-name]").each(function () {
3056
- byName[this.getAttribute("data-name")] = this;
3057
- });
3058
- order.forEach(function (name) {
3059
- const el = byName[name];
3060
- if (!el) {
3061
- return;
3062
- }
3063
- if ($action.length) {
3064
- $(el).insertBefore($action);
3065
- } else {
3066
- $row.append(el);
3067
- }
3068
- el.classList.toggle("kgrid-user-hidden", !!hidden[name]);
3069
- });
3172
+ CT.applyLayoutToRow($(this), columns);
3070
3173
  });
3174
+ const visible = CT.layoutVisibleColumns(columns);
3071
3175
  const hasActions = $table.find(".kgrid-row-actions").length > 0;
3072
- CT.syncActionColumnColgroup(
3073
- $table,
3074
- order.length,
3075
- hasActions,
3076
- options,
3077
- CT.chooserColumns(columns)
3078
- );
3176
+ CT.syncActionColumnColgroup($table, visible.length, hasActions, options, visible);
3177
+ CT.syncSpanningCells($table, CT.participatingColumnCount(columns, hasActions));
3079
3178
  };
3080
3179
 
3081
3180
  CT.refreshCollectionTemplate = function (api, options) {
@@ -3458,14 +3557,14 @@
3458
3557
  const labelsRow = CT.setupLabelsHeader(table.find(".thead-labels"), options);
3459
3558
 
3460
3559
  const hasActionColumn = CT.hasActionColumn(options);
3461
- const visibleColumnsCount = labelsRow.find("th").length;
3462
- const dataColumnCount = visibleColumnsCount - (hasActionColumn ? 1 : 0);
3560
+ const layoutCols = CT.layoutVisibleColumns(options.columns);
3561
+ const visibleColumnsCount = CT.participatingColumnCount(options.columns, hasActionColumn);
3463
3562
  CT.syncActionColumnColgroup(
3464
3563
  table,
3465
- dataColumnCount,
3564
+ layoutCols.length,
3466
3565
  hasActionColumn,
3467
3566
  options,
3468
- CT.chooserColumns(options.columns)
3567
+ layoutCols
3469
3568
  );
3470
3569
 
3471
3570
  const filterForm = options.filterForm ?? CT.setupFilterHeader(table, options);