@xleddyl/443-components-vue 0.16.29 → 0.16.31

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/README.md CHANGED
@@ -881,7 +881,7 @@ Accessibility related props and defaults:
881
881
  - `DataGrid` `showEdges` and `showJump` reach the footer pager (first and last page buttons, page number input). `loading` also keeps the pager from resetting the page while a server total is unknown.
882
882
  - `DataGrid` registers the AG Grid cell editors (text, large text, number, date, checkbox, select, custom and undo/redo) when `editable` is set or when a column or `gridOptions.defaultColDef` has `editable` at mount. `registerGridEditorModules()` from `/grid` does it by hand, before the first grid mounts, for columns that become editable later.
883
883
  - `ImageCell` takes `fit` (`'cover'` default, or `'contain'` for logos) and `size` (any CSS length, default `1.75rem`) in `cellRendererParams`. `EmptyCell` (the hidden "Empty" dash) is exported from `/grid` for custom renderers.
884
- - `BadgeCell` takes `variant` (`BadgeVariant`, `'soft' | 'solid' | 'outline'`) in `cellRendererParams`: set, the cell renders a `KBadge` with that variant and the resolved tone (`size`, `BadgeSize`, default `'sm'`); unset keeps the compact grid pill. `badgeClass` (`string | ((value, data) => string | undefined)`) adds host classes to the badge, to set the per instance badge tokens (`--k-badge-background`, `--k-badge-color`, `--k-badge-border-color`, which the grid pill also reads) for values outside `Tone`. `BadgeCellParams<T>` types the row of `data`. When the value is an array, the cell renders one badge per item (each item resolves its own `tones`, `labels` and `badgeClass`), on one line clipped to the cell, with the full list in the `title` attribute. `max` (a number) shows the first items and a `+N` badge for the rest (announced as "N more", `grid.moreValues`); `wrap: true` lets the badges wrap onto more lines (pair it with `autoHeight` on the column). Give an array column a `valueFormatter` (`(params) => params.value.join(', ')`): AG Grid infers an object type for arrays and uses the formatter for export, copy and the quick filter. Single values render as before.
884
+ - `BadgeCell` takes `variant` (`BadgeVariant`, `'soft' | 'solid' | 'outline'`) in `cellRendererParams`: set, the cell renders a `KBadge` with that variant and the resolved tone (`size`, `BadgeSize`, default `'sm'`); unset keeps the compact grid pill. `badgeClass` (`string | ((value, data) => string | undefined)`) adds host classes to the badge, to set the per instance badge tokens (`--k-badge-background`, `--k-badge-color`, `--k-badge-border-color`, which the grid pill also reads) for values outside `Tone`. `BadgeCellParams<T>` types the row of `data`. When the value is an array, the cell renders one badge per item (each item resolves its own `tones`, `labels` and `badgeClass`), on one line, with the full list in the `title` attribute. The cell shows only the badges that fit its width and a `+N` badge for the rest, and measures again when the column is resized. `max` (a number) also limits the badges to the first items, with a `+N` badge for the rest (announced as "N more", `grid.moreValues`); `wrap: true` lets the badges wrap onto more lines (pair it with `autoHeight` on the column). Give an array column a `valueFormatter` (`(params) => params.value.join(', ')`): AG Grid infers an object type for arrays and uses the formatter for export, copy and the quick filter. Single values render as before.
885
885
  - `DataGrid` `spreadsheet` turns on Excel like editing on AG Grid Community (no Enterprise modules): it registers the editor modules and the AG Grid `ScrollApiModule` (`registerGridSpreadsheetModules()` from `/grid` does it by hand) and leaves the normal grid unchanged when it is off. Set `rowIdKey` or `getRowId`: changes, dirty cells and undo refer to row ids, never to indexes.
886
886
  - Selection: click selects a cell; drag, Shift+click and Shift+arrows extend a rectangular range (Shift+Cmd/Ctrl+arrow to the edge); Cmd/Ctrl+A selects every cell. The range follows the displayed row order (after sort, filter and quick search) and the displayed column order; the row selection checkbox column is not part of it. Escape collapses the range to the active cell.
887
887
  - Keyboard: arrows and Tab move the active cell, Enter, F2 or typing start the AG Grid editor, Escape cancels it. While an editor (or any input) has focus no shortcut fires.
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <span
3
3
  v-if="isList && entries.length"
4
+ ref="root"
4
5
  class="k-data-grid-badges"
5
6
  :class="{ 'is-wrap': params.wrap }"
6
7
  :title="fullText"
@@ -58,7 +59,8 @@
58
59
  </template>
59
60
 
60
61
  <script setup>
61
- import { computed } from "vue";
62
+ import { computed, nextTick, ref, watch } from "vue";
63
+ import { useResizeObserver } from "../../internal/core/resize";
62
64
  import Badge from "../../components/data/Badge.vue";
63
65
  import { paletteClass } from "../../components/core/palette";
64
66
  import { formatLocaleMessage } from "../../locale";
@@ -105,8 +107,55 @@ const limit = computed(() => {
105
107
  const max = props.params.max;
106
108
  return max === void 0 || max < 1 ? entries.value.length : Math.floor(max);
107
109
  });
108
- const shown = computed(() => entries.value.slice(0, limit.value));
110
+ const root = ref(null);
111
+ const available = ref(Number.POSITIVE_INFINITY);
112
+ const widths = ref(null);
113
+ const moreWidth = ref(0);
114
+ const fitted = computed(() => {
115
+ const measured = widths.value;
116
+ if (props.params.wrap || !measured) return limit.value;
117
+ const gap = 4;
118
+ const total = entries.value.length;
119
+ let used = 0;
120
+ for (let index = 0; index < limit.value; index += 1) {
121
+ const next = used + (index ? gap : 0) + (measured[index] ?? 0);
122
+ const reserve = index + 1 < total ? gap + moreWidth.value : 0;
123
+ if (next + reserve > available.value) return Math.max(index, 1);
124
+ used = next;
125
+ }
126
+ return limit.value;
127
+ });
128
+ const shown = computed(() => entries.value.slice(0, fitted.value));
109
129
  const hiddenCount = computed(() => entries.value.length - shown.value.length);
130
+ function badgeElements() {
131
+ return Array.from(root.value?.children ?? []).filter(
132
+ (element) => element instanceof HTMLElement && !element.classList.contains("k-data-grid-badge-more") && !element.classList.contains("k-visually-hidden")
133
+ );
134
+ }
135
+ function measure() {
136
+ if (!root.value) return;
137
+ available.value = root.value.clientWidth;
138
+ const more = root.value.querySelector(".k-data-grid-badge-more");
139
+ if (more) moreWidth.value = more.offsetWidth;
140
+ }
141
+ async function measureBadges() {
142
+ widths.value = null;
143
+ await nextTick();
144
+ if (!root.value) return;
145
+ widths.value = badgeElements().map((element) => element.offsetWidth);
146
+ moreWidth.value ||= 32;
147
+ measure();
148
+ await nextTick();
149
+ measure();
150
+ }
151
+ watch(
152
+ () => entries.value.map((entry) => entry.key + entry.text).join("|"),
153
+ () => {
154
+ if (!props.params.wrap) measureBadges();
155
+ },
156
+ { immediate: true }
157
+ );
158
+ useResizeObserver(() => [root.value], measure);
110
159
  const fullText = computed(() => entries.value.map((entry) => entry.text).join(", "));
111
160
  const moreText = computed(
112
161
  () => formatLocaleMessage(
@@ -204,6 +204,7 @@
204
204
  flex-wrap: nowrap;
205
205
  align-items: center;
206
206
  gap: 0.25rem;
207
+ width: 100%;
207
208
  min-width: 0;
208
209
  max-width: 100%;
209
210
  overflow: hidden;
@@ -91,6 +91,7 @@ export function useModalDialog(options) {
91
91
  if (returnTarget?.isConnected) returnTarget.focus({ preventScroll: true });
92
92
  });
93
93
  function onCancel(event) {
94
+ if (event.target !== event.currentTarget) return;
94
95
  event.preventDefault();
95
96
  if (options.dismissible()) requestClose("escape");
96
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/443-components-vue",
3
- "version": "0.16.29",
3
+ "version": "0.16.31",
4
4
  "description": "Compact, scoped dashboard components for Vue and Nuxt",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",