@threadlabs/looma 0.49.4 → 0.50.1

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/docs/catalog.json CHANGED
@@ -498,7 +498,7 @@
498
498
  ],
499
499
  "schemaVersion": 1,
500
500
  "package": "@threadlabs/looma",
501
- "version": "0.49.4",
501
+ "version": "0.50.1",
502
502
  "groups": [
503
503
  {
504
504
  "id": "layout",
@@ -4980,7 +4980,7 @@
4980
4980
  "tag": "ui-cluster",
4981
4981
  "package": "@threadlabs/looma",
4982
4982
  "root": "div",
4983
- "description": "Cluster layout primitive for row-style content with wrapping support. Set `wrap=\"nowrap\"` to keep a small group, such as a meter and its value, on one row.",
4983
+ "description": "Cluster layout primitive for row-style content with wrapping support. Set `wrap=\"nowrap\"` to keep a small group, such as a meter and its value, on one row. Set `maxRows` with an `overflow` slot to show complete rows and reveal the remaining items through your action. The optional `trailing` slot stays visible within the row limit. The `overflow-change` event reports the hidden count. Omit maxRows for ordinary unbounded wrapping.",
4984
4984
  "designTokens": {
4985
4985
  "sources": [
4986
4986
  "packages/looma/src/components/ui-cluster/ui-cluster.html"
@@ -5077,6 +5077,17 @@
5077
5077
  "between"
5078
5078
  ]
5079
5079
  },
5080
+ {
5081
+ "name": "max-rows",
5082
+ "property": "maxRows",
5083
+ "description": "Maximum complete visible rows when wrapping. Zero leaves the group unbounded. Supply an overflow slot with a control that opens the complete collection; extra direct items are hidden and leave keyboard navigation. The trailing slot stays visible and counts toward the row cap.",
5084
+ "type": "integer",
5085
+ "valueType": {
5086
+ "kind": "terminal",
5087
+ "name": "integer"
5088
+ },
5089
+ "default": 0
5090
+ },
5080
5091
  {
5081
5092
  "name": "padding",
5082
5093
  "property": "padding",
@@ -5169,6 +5180,12 @@
5169
5180
  "between"
5170
5181
  ]
5171
5182
  },
5183
+ {
5184
+ "name": "maxRows",
5185
+ "description": "Maximum complete visible rows when wrapping. Zero leaves the group unbounded. Supply an overflow slot with a control that opens the complete collection; extra direct items are hidden and leave keyboard navigation. The trailing slot stays visible and counts toward the row cap.",
5186
+ "type": "number",
5187
+ "default": 0
5188
+ },
5172
5189
  {
5173
5190
  "name": "padding",
5174
5191
  "description": "Optional internal space for an action group, using the shared spacing scale.",
@@ -5204,11 +5221,33 @@
5204
5221
  ]
5205
5222
  }
5206
5223
  ],
5207
- "events": [],
5224
+ "events": [
5225
+ {
5226
+ "name": "overflow-change",
5227
+ "detailType": "{ readonly count: number }",
5228
+ "detailSchema": "object",
5229
+ "fields": [
5230
+ {
5231
+ "path": "count",
5232
+ "type": "integer",
5233
+ "required": true
5234
+ }
5235
+ ],
5236
+ "detailDocs": "Emitted with the declared detail payload."
5237
+ }
5238
+ ],
5208
5239
  "slots": [
5209
5240
  {
5210
5241
  "name": "default",
5211
5242
  "description": "Default child content."
5243
+ },
5244
+ {
5245
+ "name": "overflow",
5246
+ "description": "Named content for the overflow region."
5247
+ },
5248
+ {
5249
+ "name": "trailing",
5250
+ "description": "Named content for the trailing region."
5212
5251
  }
5213
5252
  ],
5214
5253
  "group": "layout",
@@ -5272,6 +5311,16 @@
5272
5311
  "bindings": "",
5273
5312
  "frameworks": {}
5274
5313
  },
5314
+ {
5315
+ "id": "@threadlabs/looma/ui-cluster/06-bounded-rows",
5316
+ "name": "06-bounded-rows",
5317
+ "title": "Bounded rows with all items available",
5318
+ "description": "Reserve an overflow action and an always-visible trailing action within three rows. The popup contains the complete collection.",
5319
+ "markup": "<ui-container fill>\n <ui-stack>\n <ui-cluster max-rows=\"3\" gap=\"xs\">\n <ui-badge>Research and discovery</ui-badge>\n <ui-badge>Interface design</ui-badge>\n <ui-badge>Content strategy</ui-badge>\n <ui-badge>Accessibility review</ui-badge>\n <ui-badge>Implementation</ui-badge>\n <ui-badge>Testing and delivery</ui-badge>\n <ui-button slot=\"overflow\" id=\"bounded-all-items\" size=\"sm\" variant=\"ghost\">All items…</ui-button>\n <ui-button slot=\"trailing\" size=\"sm\" variant=\"ghost\">Add item</ui-button>\n </ui-cluster>\n <ui-popover for=\"bounded-all-items\" role=\"region\" aria-label=\"All items\">\n <ui-cluster gap=\"xs\">\n <ui-badge>Research and discovery</ui-badge>\n <ui-badge>Interface design</ui-badge>\n <ui-badge>Content strategy</ui-badge>\n <ui-badge>Accessibility review</ui-badge>\n <ui-badge>Implementation</ui-badge>\n <ui-badge>Testing and delivery</ui-badge>\n </ui-cluster>\n </ui-popover>\n </ui-stack>\n</ui-container>",
5320
+ "resizable": false,
5321
+ "bindings": "",
5322
+ "frameworks": {}
5323
+ },
5275
5324
  {
5276
5325
  "id": "@threadlabs/looma/ui-cluster/99-theme-sampler",
5277
5326
  "name": "99-theme-sampler",
@@ -6035,6 +6084,17 @@
6035
6084
  "none"
6036
6085
  ]
6037
6086
  },
6087
+ {
6088
+ "name": "grow",
6089
+ "property": "grow",
6090
+ "description": "Let a multiple-selection field wrap and grow with its selected items and typing space. Without grow it stays one horizontally scrolling row.",
6091
+ "type": "boolean",
6092
+ "valueType": {
6093
+ "kind": "terminal",
6094
+ "name": "boolean"
6095
+ },
6096
+ "default": false
6097
+ },
6038
6098
  {
6039
6099
  "name": "help",
6040
6100
  "property": "help",
@@ -6265,13 +6325,12 @@
6265
6325
  {
6266
6326
  "name": "max-rows",
6267
6327
  "property": "maxRows",
6268
- "description": "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. One or less keeps the single horizontally scrolling row; single-selection fields are unchanged.",
6328
+ "description": "Optional maximum visible rows when grow is enabled. Extra selections scroll vertically inside the field. Omit it for unbounded growth; single-selection fields are unchanged.",
6269
6329
  "type": "integer",
6270
6330
  "valueType": {
6271
6331
  "kind": "terminal",
6272
6332
  "name": "integer"
6273
- },
6274
- "default": 1
6333
+ }
6275
6334
  },
6276
6335
  {
6277
6336
  "name": "multiple",
@@ -6481,6 +6540,12 @@
6481
6540
  "none"
6482
6541
  ]
6483
6542
  },
6543
+ {
6544
+ "name": "grow",
6545
+ "description": "Let a multiple-selection field wrap and grow with its selected items and typing space. Without grow it stays one horizontally scrolling row.",
6546
+ "type": "boolean",
6547
+ "default": false
6548
+ },
6484
6549
  {
6485
6550
  "name": "help",
6486
6551
  "description": "Help text for the field. When set, a help button appears beside the field and opens a tooltip with this text; while it is open, the input is described by it.",
@@ -6582,9 +6647,8 @@
6582
6647
  },
6583
6648
  {
6584
6649
  "name": "maxRows",
6585
- "description": "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. One or less keeps the single horizontally scrolling row; single-selection fields are unchanged.",
6586
- "type": "number",
6587
- "default": 1
6650
+ "description": "Optional maximum visible rows when grow is enabled. Extra selections scroll vertically inside the field. Omit it for unbounded growth; single-selection fields are unchanged.",
6651
+ "type": "number"
6588
6652
  },
6589
6653
  {
6590
6654
  "name": "multiple",
@@ -7548,8 +7612,8 @@
7548
7612
  "id": "@threadlabs/looma/ui-combobox/08-multiple-rows",
7549
7613
  "name": "08-multiple-rows",
7550
7614
  "title": "Wrap selected items before scrolling",
7551
- "description": "maxRows lets a multiple field grow through three rows before additional selections scroll vertically inside the field. The input remains reachable by keyboard.",
7552
- "markup": "<ui-container fill>\n <ui-combobox label=\"Topics\" multiple max-rows=\"3\" disclosure placeholder=\"Add a topic…\">\n <option value=\"research\" selected>Research and discovery</option>\n <option value=\"design\" selected>Interface design</option>\n <option value=\"content\" selected>Content strategy</option>\n <option value=\"accessibility\" selected>Accessibility review</option>\n <option value=\"delivery\">Delivery</option>\n </ui-combobox>\n</ui-container>",
7615
+ "description": "grow with maxRows lets a multiple field grow through three rows before additional selections scroll vertically inside the field. The input remains reachable by keyboard.",
7616
+ "markup": "<ui-container fill>\n <ui-combobox label=\"Topics\" multiple grow max-rows=\"3\" disclosure placeholder=\"Add a topic…\">\n <option value=\"research\" selected>Research and discovery</option>\n <option value=\"design\" selected>Interface design</option>\n <option value=\"content\" selected>Content strategy</option>\n <option value=\"accessibility\" selected>Accessibility review</option>\n <option value=\"delivery\">Delivery</option>\n </ui-combobox>\n</ui-container>",
7553
7617
  "resizable": false,
7554
7618
  "bindings": "",
7555
7619
  "frameworks": {}
@@ -3,6 +3,7 @@ import { camel, componentName, exampleInvocations, nativeBooleans } from './exam
3
3
  const escapeHtml = value => String(value).replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;');
4
4
  const indent = depth => ' '.repeat(depth);
5
5
  const textValue = node => node.preserve ? node.value : node.value.replace(/[\t\n\r\f ]+/g, ' ');
6
+ const formattingSpace = node => node?.kind === 'text' && !node.preserve && /^[\t\n\r\f ]*$/.test(node.value);
6
7
  const key = value => /^[a-zA-Z_$][\w$]*$/.test(value) ? value : JSON.stringify(value);
7
8
  const kebab = value => value.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
8
9
  const voidElements = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
@@ -13,17 +14,17 @@ const reserved = new Set('await break case catch class const continue debugger d
13
14
 
14
15
  export const frameworkLabels = { 'html-next': 'HTML Next', vue: 'Vue', react: 'React', svelte: 'Svelte' };
15
16
 
16
- // Newline-only indentation can be rebuilt. Mixed text and explicit inline spaces stay together.
17
- function layout(nodes, owner) {
18
- const formattingSpace = node => node.kind === 'text' && !node.preserve && /^[\t\n\r\f ]*$/.test(node.value);
19
- const inline = !owner?.component && nodes.every(node => node.kind === 'text' || node.kind === 'element' && inlineElements.has(node.component?.root ?? node.tag));
20
- const multiline = !inline && nodes.some(node => formattingSpace(node) && node.value.includes('\n'))
17
+ // Derive block layout from the tree. Mixed text and inline adjacency stay together.
18
+ function layout(nodes) {
19
+ const structural = nodes.some(node => node.kind === 'slot' || node.kind === 'element' && (node.component || !inlineElements.has(node.tag)));
20
+ const multiline = structural
21
21
  && !nodes.some(node => node.kind === 'text' && !formattingSpace(node));
22
22
  return { multiline, nodes: multiline ? nodes.filter(node => !formattingSpace(node)) : nodes };
23
23
  }
24
24
 
25
25
  function text(node, target) {
26
26
  const value = textValue(node);
27
+ if (target === 'html-next') return escapeHtml(value);
27
28
  if (target === 'react') {
28
29
  if (node.preserve || /[\n\r\t]/.test(node.value)) {
29
30
  return `{${JSON.stringify(value)}}`;
@@ -37,6 +38,7 @@ function text(node, target) {
37
38
  function attribute(value, target, component) {
38
39
  let name = value.property;
39
40
  let data = value.value;
41
+ if (target === 'html-next') return data === true || data === '' ? name : `${name}="${escapeHtml(data)}"`;
40
42
  if (target === 'react') {
41
43
  name = reactAttributes[name] ?? name;
42
44
  if (name === 'style') {
@@ -88,14 +90,18 @@ function snippetBindings(model) {
88
90
  function printer(model, target) {
89
91
  const bindings = target === 'svelte' ? snippetBindings(model) : new Map();
90
92
 
91
- function sequence(nodes, depth, forceLines = false, owner) {
92
- const arranged = layout(nodes, owner);
93
+ function sequence(nodes, depth, forceLines = false) {
94
+ const arranged = layout(nodes);
93
95
  const content = arranged.nodes.map(node => (arranged.multiline ? indent(depth) : '') + render(node, depth)).join(arranged.multiline ? '\n' : '');
94
96
  return (forceLines && !arranged.multiline ? indent(depth) : '') + content;
95
97
  }
96
98
 
97
99
  function reactValue(nodes, depth) {
98
- const arranged = layout(nodes);
100
+ const content = [...nodes];
101
+ const boundaryIndentation = node => formattingSpace(node) && /[\n\r]/.test(node.value);
102
+ while (boundaryIndentation(content[0])) content.shift();
103
+ while (boundaryIndentation(content.at(-1))) content.pop();
104
+ const arranged = layout(content);
99
105
  if (!arranged.nodes.length) return 'null';
100
106
  if (arranged.nodes.length === 1) {
101
107
  const node = arranged.nodes[0];
@@ -104,8 +110,8 @@ function printer(model, target) {
104
110
  return render(node, depth);
105
111
  }
106
112
  return arranged.multiline
107
- ? `<>\n${sequence(nodes, depth + 1)}\n${indent(depth)}</>`
108
- : `<>${sequence(nodes, depth)}</>`;
113
+ ? `<>\n${sequence(content, depth + 1)}\n${indent(depth)}</>`
114
+ : `<>${sequence(content, depth)}</>`;
109
115
  }
110
116
 
111
117
  function render(node, depth) {
@@ -121,14 +127,13 @@ function printer(model, target) {
121
127
  if (node.slots.length && target === 'react') {
122
128
  attrs.push(`slots={{\n${node.slots.map(slot => `${indent(depth + 2)}${key(slot.name)}: ${reactValue(slot.children, depth + 2)},`).join('\n')}\n${indent(depth + 1)}}}`);
123
129
  }
124
- const opening = `<${node.tag}${attrs.length ? ' ' + attrs.join(' ') : ''}`;
125
- const wrapped = attrs.some(value => value.includes('\n')) || indent(depth).length + opening.length + 2 > 100;
126
- const start = wrapped ? `<${node.tag}\n${attrs.map(value => indent(depth + 1) + value).join('\n')}\n${indent(depth)}` : opening;
130
+ const wrapped = attrs.length > 0;
131
+ const start = wrapped ? `<${node.tag}\n${attrs.map(value => indent(depth + 1) + value).join('\n')}\n${indent(depth)}` : `<${node.tag}`;
127
132
  const children = target === 'vue' ? node.children : node.children.filter(child => child.kind !== 'slot');
128
- const arranged = layout(children, node);
133
+ const arranged = layout(children);
129
134
  if (!arranged.nodes.length && (node.component || target === 'react')) return `${start}${wrapped ? '' : ' '}/>`;
130
135
  if (voidElements.has(node.tag)) return `${start}>`;
131
- const content = sequence(children, depth + 1, false, node);
136
+ const content = sequence(children, depth + 1);
132
137
  return arranged.multiline
133
138
  ? `${start}>\n${content}\n${indent(depth)}</${node.tag}>`
134
139
  : `${start}>${content}</${node.tag}>`;
@@ -136,8 +141,8 @@ function printer(model, target) {
136
141
 
137
142
  function body(depth) {
138
143
  const arranged = layout(model.nodes);
139
- if (target !== 'react') return (arranged.multiline ? '' : indent(depth)) + sequence(model.nodes, depth);
140
- return reactValue(model.nodes, depth);
144
+ if (target === 'react') return reactValue(model.nodes, depth);
145
+ return (arranged.multiline ? '' : indent(depth)) + sequence(model.nodes, depth);
141
146
  }
142
147
 
143
148
  return {
@@ -155,15 +160,14 @@ export function frameworkExamples(example, components) {
155
160
  const line = `import { ${names.join(', ')} } from ${JSON.stringify(owner)};`;
156
161
  return line.length <= 100 ? line : `import {\n${names.map(name => ` ${name},`).join('\n')}\n} from ${JSON.stringify(owner)};`;
157
162
  }).join('\n');
158
- const links = model.components.map(component => `<link rel="component" href="${component.resource ?? `${component.package}/components/${component.tag}/${component.tag}.html`}">`).join('\n');
159
- const codes = { 'html-next': { language: 'html', code: `${links}\n\n${example.markup}` } };
163
+ const links = model.components.map(component => `<link\n rel="component"\n href="${escapeHtml(component.resource ?? `${component.package}/components/${component.tag}/${component.tag}.html`)}"\n>`).join('\n');
164
+ const html = printer(exampleInvocations(example.markup, []), 'html-next').body(0);
165
+ const codes = { 'html-next': { language: 'html', code: [links, html].filter(Boolean).join('\n\n') } };
160
166
  for (const target of ['vue', 'react', 'svelte']) {
161
167
  const output = printer(model, target);
162
168
  const script = imports ? `<script${target === 'vue' ? ' setup' : ''}>\n${imports.split('\n').map(line => ' ' + line).join('\n')}\n</script>\n\n` : '';
163
- const jsx = target === 'react' ? output.body(2) : '';
164
- const reactReturn = jsx.includes('\n') || jsx.length + 10 > 100 ? `return (\n ${jsx}\n );` : `return ${jsx};`;
165
169
  codes[target] = target === 'react'
166
- ? { language: 'tsx', code: `${imports ? imports + '\n\n' : ''}export default function Example() {\n ${reactReturn}\n}` }
170
+ ? { language: 'tsx', code: `${imports ? imports + '\n\n' : ''}export default function Example() {\n return ${output.body(1)};\n}` }
167
171
  : { language: target, code: script + (target === 'vue' ? `<template>\n${output.body(1)}\n</template>` : [output.snippets(), output.body(0)].filter(Boolean).join('\n\n')) };
168
172
  }
169
173
  return { ...codes, ...example.frameworks };
@@ -705,6 +705,20 @@
705
705
  margin: 0 !important;
706
706
  }
707
707
 
708
+ .overflow,
709
+ .trailing {
710
+ display: flex !important;
711
+ align-items: center !important;
712
+ gap: inherit !important;
713
+ min-inline-size: 0;
714
+ max-inline-size: 100%;
715
+ }
716
+
717
+ .overflow[hidden],
718
+ .trailing:empty {
719
+ display: none !important;
720
+ }
721
+
708
722
  :scope:where([data-component~="ui-cluster"])[data-ui-cluster-state~="fixed"] {
709
723
  flex: none;
710
724
  }
@@ -776,7 +790,11 @@
776
790
  }
777
791
  }
778
792
  @scope ([data-component~="ui-cluster"]) to ([data-component]) {
779
- /* A component that sets its display still honours the hidden attribute on its root. */
793
+ :where([data-slotted], [data-slotted] *):is([hidden]) {
794
+ display: none !important;
795
+ }
796
+
797
+ /* A component that sets its display still honours the hidden attribute on its root. */
780
798
  }
781
799
  /* Generated by HTML Next 1.0.0-alpha.76. Do not edit. */
782
800
  @supports (-moz-appearance: none) {