@threadlabs/looma 0.49.3 → 0.50.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.
@@ -1,4 +1,4 @@
1
- <template component="ui-cluster">
1
+ <template component="ui-cluster" module="./ui-cluster.js">
2
2
  <defs>
3
3
  <prop name="padding" type="keyword" values="none, s, m, l" default="none"
4
4
  >Optional internal space for an action group, using the shared spacing scale.</prop>
@@ -18,8 +18,19 @@
18
18
  >Whether items move onto a new row when they run out of space: wrap (the default) or nowrap, which keeps them on one row at their own sizes. Use nowrap for
19
19
  a small group that must read as one unit, such as a meter and its value in a table cell, so the cell grows to fit it; a whole row of actions should keep
20
20
  wrapping so it fits narrow screens.</prop>
21
+ <prop name="maxRows" type="integer" default="0"
22
+ >Maximum complete visible rows when wrapping. Zero leaves the group unbounded. Supply an overflow slot with a control that opens the complete collection;
23
+ extra direct items are hidden and leave keyboard navigation. The trailing slot stays visible and counts toward the row cap.</prop>
24
+ <state name="overflowCount" type="integer" value="0"></state>
25
+ <event name="overflow-change" type="object">
26
+ <prop name="count" required type="integer"></prop>
27
+ </event>
21
28
  </defs>
22
- <div><slot></slot></div>
29
+ <div>
30
+ <slot></slot>
31
+ <span class="overflow" $ref="overflow" from:hidden="$overflowCount = 0"><slot name="overflow"></slot></span>
32
+ <span class="trailing" $ref="trailing"><slot name="trailing"></slot></span>
33
+ </div>
23
34
  <style>
24
35
  :host {
25
36
  --_layout-gap: var(--ui-space-3);
@@ -32,6 +43,23 @@
32
43
  margin: 0 !important;
33
44
  }
34
45
 
46
+ .overflow,
47
+ .trailing {
48
+ display: flex !important;
49
+ align-items: center !important;
50
+ gap: inherit !important;
51
+ min-inline-size: 0;
52
+ max-inline-size: 100%;
53
+ }
54
+ :slotted([hidden]) {
55
+ display: none !important;
56
+ }
57
+
58
+ .overflow[hidden],
59
+ .trailing:empty {
60
+ display: none !important;
61
+ }
62
+
35
63
  :host([fixed]) {
36
64
  flex: none;
37
65
  }
@@ -0,0 +1,107 @@
1
+ /** Bound a wrapping group by complete rows while preserving its overflow action. */
2
+ export function connect(host) {
3
+ const element = host.element;
4
+ const view = element.ownerDocument.defaultView;
5
+ const overflow = host.refs.overflow;
6
+ const trailing = host.refs.trailing;
7
+ const collapsed = new Set();
8
+ const observed = new Set();
9
+ let limit = 0;
10
+ let frame = 0;
11
+ let count = 0;
12
+ let alive = true;
13
+
14
+ function report(next) {
15
+ overflow.hidden = next === 0;
16
+ host.state.overflowCount = next;
17
+ if (next !== count) host.dispatch('overflow-change', { count: next });
18
+ count = next;
19
+ }
20
+
21
+ function restore() {
22
+ for (const item of collapsed) item.removeAttribute('hidden');
23
+ collapsed.clear();
24
+ }
25
+
26
+ function rows(items) {
27
+ let total = 0;
28
+ let end = -Infinity;
29
+ for (const item of items) {
30
+ const box = item.getBoundingClientRect();
31
+ if (!box.width || !box.height) continue;
32
+ if (box.top >= end - 0.5) total++;
33
+ end = Math.max(end, box.bottom);
34
+ }
35
+ return total;
36
+ }
37
+
38
+ function measure() {
39
+ frame = 0;
40
+ if (!alive || !limit) return;
41
+ const active = element.ownerDocument.activeElement;
42
+ restore();
43
+ overflow.hidden = true;
44
+ const items = Array.from(element.children).filter(item => item !== overflow && item !== trailing && !item.hasAttribute('hidden'));
45
+ for (const item of observed) if (!items.includes(item)) { resize.unobserve(item); observed.delete(item); }
46
+ for (const item of items) if (!observed.has(item)) { resize.observe(item); observed.add(item); }
47
+ if (!element.clientWidth || !overflow.childElementCount || getComputedStyle(element).flexWrap === 'nowrap'
48
+ || rows([...items, trailing]) <= limit) { report(0); return; }
49
+
50
+ // Measure the real overflow/trailing controls in the final row, rather than clipping a partial item.
51
+ overflow.hidden = false;
52
+ const showPrefix = count => {
53
+ for (const [index, item] of items.entries()) {
54
+ item.toggleAttribute('hidden', index >= count);
55
+ if (index >= count) collapsed.add(item);
56
+ else collapsed.delete(item);
57
+ }
58
+ };
59
+ let visible = 0;
60
+ let upper = items.length;
61
+ while (visible < upper) {
62
+ const candidate = Math.ceil((visible + upper) / 2);
63
+ showPrefix(candidate);
64
+ if (rows([...items.slice(0, candidate), overflow, trailing]) <= limit) visible = candidate;
65
+ else upper = candidate - 1;
66
+ }
67
+ showPrefix(visible);
68
+ report(items.length - visible);
69
+ if (active && Array.from(collapsed).some(item => item.contains(active))) {
70
+ overflow.querySelector('button, a[href], input, [tabindex="0"]')?.focus({ preventScroll: true });
71
+ }
72
+ }
73
+
74
+ const schedule = () => {
75
+ if (alive && limit && !frame) frame = view.requestAnimationFrame(measure);
76
+ };
77
+ let resize;
78
+ let changes;
79
+ const stop = host.effect(() => {
80
+ const requested = Number(host.props.maxRows.value);
81
+ host.props.wrap.value;
82
+ limit = Number.isFinite(requested) ? Math.max(0, Math.floor(requested)) : 0;
83
+ resize?.disconnect();
84
+ observed.clear();
85
+ changes?.disconnect();
86
+ element.ownerDocument.fonts?.removeEventListener('loadingdone', schedule);
87
+ if (limit) {
88
+ resize ??= new view.ResizeObserver(schedule);
89
+ changes ??= new view.MutationObserver(schedule);
90
+ resize.observe(element);
91
+ resize.observe(overflow);
92
+ resize.observe(trailing);
93
+ changes.observe(element, { childList: true, subtree: true, characterData: true });
94
+ element.ownerDocument.fonts?.addEventListener('loadingdone', schedule);
95
+ schedule();
96
+ } else { restore(); report(0); }
97
+ });
98
+ return () => {
99
+ alive = false;
100
+ stop();
101
+ resize?.disconnect();
102
+ changes?.disconnect();
103
+ element.ownerDocument.fonts?.removeEventListener('loadingdone', schedule);
104
+ if (frame) view.cancelAnimationFrame(frame);
105
+ restore();
106
+ };
107
+ }
@@ -47,9 +47,11 @@
47
47
  >Lets the user choose several options. Each choice becomes a removable badge before the input, the list stays open between picks, and choosing a checked
48
48
  option removes it. items-change then reports the whole list of items, and selected-values-change the list of their values; use selectedValues or items,
49
49
  not value, in this mode.</prop>
50
- <prop name="maxRows" type="integer" default="1"
51
- >Visible rows of selected items and typing space in multiple mode. More than one lets the field grow and wrap before extra rows scroll vertically inside it.
52
- One or less keeps the single horizontally scrolling row; single-selection fields are unchanged.</prop>
50
+ <prop name="grow" type="boolean" default="false"
51
+ >Let a multiple-selection field wrap and grow with its selected items and typing space. Without grow it stays one horizontally scrolling row.</prop>
52
+ <prop name="maxRows" type="integer"
53
+ >Optional maximum visible rows when grow is enabled. Extra selections scroll vertically inside the field. Omit it for unbounded growth; single-selection
54
+ fields are unchanged.</prop>
53
55
  <prop name="tokenSeparators" type="list(string)"
54
56
  >Keys that commit the typed text in multiple mode, as KeyboardEvent key values such as "," or ";". The text is added as the option whose label matches it,
55
57
  ignoring case, or with allowCreate is reported as create-item; otherwise it stays in the input.</prop>
@@ -430,7 +432,7 @@
430
432
  *</template></label>
431
433
  <div class="control">
432
434
  <div class="field" $ref="field">
433
- <div class="entry" class:multiline="$multiple and $maxRows > 1" style:--_max-rows="$maxRows">
435
+ <div class="entry" class:multiline="$multiple and $grow" style:--_max-rows="$maxRows">
434
436
  <span class="start"><slot name="start"></slot></span>
435
437
  <template $if="$multiple">
436
438
  <button
@@ -899,7 +901,7 @@
899
901
  --_entry-row: max(1.5rem, var(--_item-row));
900
902
  flex-wrap: wrap !important;
901
903
  align-content: flex-start !important;
902
- max-block-size: calc(var(--_max-rows) * var(--_entry-row) + (var(--_max-rows) - 1) * var(--ui-space-1));
904
+ max-block-size: calc(max(1, var(--_max-rows)) * var(--_entry-row) + (max(1, var(--_max-rows)) - 1) * var(--ui-space-1));
903
905
  overflow-x: hidden;
904
906
  overflow-y: auto;
905
907
  }
@@ -497,7 +497,7 @@ export function connect(host) {
497
497
  void validateCurrent();
498
498
  };
499
499
  const onFocusin = (event) => {
500
- if (host.props.multiple.value && host.props.maxRows.value > 1 && field.contains(event.target)) {
500
+ if (host.props.multiple.value && host.props.grow.value && field.contains(event.target)) {
501
501
  revealActiveItem(field, () => document.activeElement);
502
502
  }
503
503
  if (event.target === input && host.props.openOnFocus.value && !host.state.expanded && !suppressFocusOpening) openFromField();
@@ -588,7 +588,7 @@ export function connect(host) {
588
588
  if (host.props.query.value !== lastQuery) { lastQuery = host.props.query.value; syncQuery(); }
589
589
  if (host.props.disabled.value || host.props.readonly.value) close();
590
590
  updateView();
591
- if (host.props.multiple.value && host.props.maxRows.value > 1
591
+ if (host.props.multiple.value && host.props.grow.value
592
592
  && document.activeElement && field.contains(document.activeElement)) revealActiveItem(field, () => document.activeElement);
593
593
  });
594
594
 
@@ -96,6 +96,10 @@
96
96
  color: inherit;
97
97
  text-decoration: none;
98
98
  }
99
+ .brand > :slotted(a) > img, .brand > :slotted(img) {
100
+ max-inline-size: 100%;
101
+ object-fit: contain;
102
+ }
99
103
  .navigation {
100
104
  display: flex !important;
101
105
  flex-wrap: wrap !important;