@threadlabs/looma 0.50.0 → 0.50.2
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 +4 -4
- package/docs/framework-examples.mjs +34 -20
- package/package.json +1 -1
package/docs/catalog.json
CHANGED
|
@@ -498,7 +498,7 @@
|
|
|
498
498
|
],
|
|
499
499
|
"schemaVersion": 1,
|
|
500
500
|
"package": "@threadlabs/looma",
|
|
501
|
-
"version": "0.50.
|
|
501
|
+
"version": "0.50.2",
|
|
502
502
|
"groups": [
|
|
503
503
|
{
|
|
504
504
|
"id": "layout",
|
|
@@ -3588,7 +3588,7 @@
|
|
|
3588
3588
|
"frameworks": {
|
|
3589
3589
|
"html-next": {
|
|
3590
3590
|
"language": "html",
|
|
3591
|
-
"code": "<script
|
|
3591
|
+
"code": "<script\n type=\"module\"\n>\n import \"@threadlabs/looma\";\n import { componentRegistry } from \"@nextwebwg/html-next/runtime\";\n\n const button = document.querySelector(\"#docs-save-changes\");\n button.addEventListener(\"click\", async () => {\n componentRegistry.update(button, { loading: true });\n try {\n await new Promise((resolve) => setTimeout(resolve, 1500));\n } finally {\n componentRegistry.update(button, { loading: false });\n }\n });\n</script>\n\n<ui-button\n id=\"docs-save-changes\"\n variant=\"solid\"\n>Save changes</ui-button>\n"
|
|
3592
3592
|
},
|
|
3593
3593
|
"vue": {
|
|
3594
3594
|
"language": "vue",
|
|
@@ -4919,7 +4919,7 @@
|
|
|
4919
4919
|
"frameworks": {
|
|
4920
4920
|
"html-next": {
|
|
4921
4921
|
"language": "html",
|
|
4922
|
-
"code": "<script
|
|
4922
|
+
"code": "<script\n type=\"module\"\n>\n import \"@threadlabs/looma\";\n import { componentRegistry } from \"@nextwebwg/html-next/runtime\";\n\n const all = document.querySelector(\"#docs-checkbox-all\");\n const items = [...document.querySelectorAll(\".docs-checkbox-item\")];\n const isChecked = (item) => item.querySelector('input[type=\"checkbox\"]').checked;\n\n all.addEventListener(\"change\", (event) => {\n if (typeof event.detail?.checked !== \"boolean\") return;\n for (const item of items) componentRegistry.update(item, { checked: event.detail.checked });\n componentRegistry.update(all, { indeterminate: false });\n });\n\n for (const item of items) item.addEventListener(\"change\", (event) => {\n if (typeof event.detail?.checked !== \"boolean\") return;\n const count = items.filter(isChecked).length;\n componentRegistry.update(all, { checked: count === items.length, indeterminate: count > 0 && count < items.length });\n });\n</script>\n\n<ui-stack\n gap=\"s\"\n>\n <ui-checkbox\n id=\"docs-checkbox-all\"\n indeterminate\n >Select all</ui-checkbox>\n <ui-stack\n gap=\"xs\"\n style=\"padding-inline-start: 1.5rem\"\n >\n <ui-checkbox\n class=\"docs-checkbox-item\"\n checked\n >Design</ui-checkbox>\n <ui-checkbox\n class=\"docs-checkbox-item\"\n >Build</ui-checkbox>\n <ui-checkbox\n class=\"docs-checkbox-item\"\n >Review</ui-checkbox>\n </ui-stack>\n</ui-stack>\n"
|
|
4923
4923
|
}
|
|
4924
4924
|
},
|
|
4925
4925
|
"behavior": "@threadlabs/looma/docs/examples/ui-checkbox/examples/02-checked-indeterminate-and-disabled.behavior.js"
|
|
@@ -19822,7 +19822,7 @@
|
|
|
19822
19822
|
"frameworks": {
|
|
19823
19823
|
"html-next": {
|
|
19824
19824
|
"language": "html",
|
|
19825
|
-
"code": "<script
|
|
19825
|
+
"code": "<script\n type=\"module\"\n>\n import \"@threadlabs/looma\";\n\n const input = document.querySelector(\"#docs-search-input\");\n const status = document.querySelector(\"#docs-search-status\");\n const empty = document.querySelector(\"#docs-search-empty\");\n const results = [\n document.querySelector(\"#docs-result-design-tokens\"),\n document.querySelector(\"#docs-result-token-overrides\"),\n document.querySelector(\"#docs-result-button-variants\")\n ];\n\n function updateResults() {\n const query = input.value.trim().toLowerCase();\n let visible = 0;\n for (const result of results) {\n result.hidden = !result.textContent.toLowerCase().includes(query);\n if (!result.hidden) visible += 1;\n }\n status.textContent = visible + \" result\" + (visible === 1 ? \"\" : \"s\");\n empty.hidden = visible !== 0;\n }\n\n input.addEventListener(\"input\", updateResults);\n</script>\n\n<ui-search-shell\n id=\"docs-search-shell\"\n open\n dismissible\n label=\"Search documentation\"\n>\n <ui-input\n id=\"docs-search-input\"\n slot=\"search\"\n type=\"search\"\n aria-label=\"Search documentation\"\n placeholder=\"Search documentation\"\n ></ui-input>\n <div\n id=\"docs-search-status\"\n slot=\"status\"\n aria-live=\"polite\"\n >3 results</div>\n <div\n id=\"docs-search-results\"\n slot=\"body\"\n >\n <ui-search-result-row\n id=\"docs-result-design-tokens\"\n >\n <strong\n slot=\"title\"\n >Design tokens</strong>\n <span\n slot=\"excerpt\"\n >Color, type, spacing, and motion.</span>\n </ui-search-result-row>\n <ui-search-result-row\n id=\"docs-result-token-overrides\"\n >\n <strong\n slot=\"title\"\n >Token overrides</strong>\n <span\n slot=\"excerpt\"\n >Customize shared and component tokens.</span>\n </ui-search-result-row>\n <ui-search-result-row\n id=\"docs-result-button-variants\"\n >\n <strong\n slot=\"title\"\n >Button variants</strong>\n <span\n slot=\"excerpt\"\n >Choose solid, outline, ghost, or danger.</span>\n </ui-search-result-row>\n <p\n id=\"docs-search-empty\"\n hidden\n >No matching documentation.</p>\n </div>\n <form\n slot=\"footer\"\n method=\"dialog\"\n >\n <ui-button\n type=\"submit\"\n size=\"sm\"\n >Close</ui-button>\n </form>\n</ui-search-shell>\n"
|
|
19826
19826
|
},
|
|
19827
19827
|
"vue": {
|
|
19828
19828
|
"language": "vue",
|
|
@@ -3,6 +3,7 @@ import { camel, componentName, exampleInvocations, nativeBooleans } from './exam
|
|
|
3
3
|
const escapeHtml = value => String(value).replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
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,26 @@ 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
|
-
//
|
|
17
|
+
// Derive block layout from the tree. Mixed text and inline adjacency stay together.
|
|
17
18
|
function layout(nodes, owner) {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const structural = nodes.some(node => node.kind === 'slot' || node.kind === 'element' && (node.component || !inlineElements.has(node.tag)));
|
|
20
|
+
const labels = nodes.filter(node => node.kind === 'text' && !formattingSpace(node));
|
|
21
|
+
const namedSlot = node => node.kind === 'element' && node.attributes.some(attribute => attribute.name === 'slot' && attribute.value);
|
|
22
|
+
const slottedLabel = owner?.tag.includes('-') && labels.length === 1 && !labels[0].preserve
|
|
23
|
+
&& nodes.some(namedSlot) && nodes.every(node => node.kind !== 'element' || namedSlot(node));
|
|
24
|
+
const multiline = slottedLabel || structural
|
|
21
25
|
&& !nodes.some(node => node.kind === 'text' && !formattingSpace(node));
|
|
22
|
-
return { multiline, nodes
|
|
26
|
+
if (!multiline) return { multiline, nodes };
|
|
27
|
+
const displayed = nodes.filter(node => !formattingSpace(node)).map(node => {
|
|
28
|
+
if (!slottedLabel || node.kind !== 'text') return node;
|
|
29
|
+
return { ...node, value: node.value.replace(/^[\t\n\r\f ]+|[\t\n\r\f ]+$/g, '') };
|
|
30
|
+
});
|
|
31
|
+
return { multiline, nodes: displayed };
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
function text(node, target) {
|
|
26
35
|
const value = textValue(node);
|
|
36
|
+
if (target === 'html-next') return escapeHtml(value);
|
|
27
37
|
if (target === 'react') {
|
|
28
38
|
if (node.preserve || /[\n\r\t]/.test(node.value)) {
|
|
29
39
|
return `{${JSON.stringify(value)}}`;
|
|
@@ -37,6 +47,7 @@ function text(node, target) {
|
|
|
37
47
|
function attribute(value, target, component) {
|
|
38
48
|
let name = value.property;
|
|
39
49
|
let data = value.value;
|
|
50
|
+
if (target === 'html-next') return data === true || data === '' ? name : `${name}="${escapeHtml(data)}"`;
|
|
40
51
|
if (target === 'react') {
|
|
41
52
|
name = reactAttributes[name] ?? name;
|
|
42
53
|
if (name === 'style') {
|
|
@@ -95,7 +106,11 @@ function printer(model, target) {
|
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
function reactValue(nodes, depth) {
|
|
98
|
-
const
|
|
109
|
+
const content = [...nodes];
|
|
110
|
+
const boundaryIndentation = node => formattingSpace(node) && /[\n\r]/.test(node.value);
|
|
111
|
+
while (boundaryIndentation(content[0])) content.shift();
|
|
112
|
+
while (boundaryIndentation(content.at(-1))) content.pop();
|
|
113
|
+
const arranged = layout(content);
|
|
99
114
|
if (!arranged.nodes.length) return 'null';
|
|
100
115
|
if (arranged.nodes.length === 1) {
|
|
101
116
|
const node = arranged.nodes[0];
|
|
@@ -104,8 +119,8 @@ function printer(model, target) {
|
|
|
104
119
|
return render(node, depth);
|
|
105
120
|
}
|
|
106
121
|
return arranged.multiline
|
|
107
|
-
? `<>\n${sequence(
|
|
108
|
-
: `<>${sequence(
|
|
122
|
+
? `<>\n${sequence(content, depth + 1)}\n${indent(depth)}</>`
|
|
123
|
+
: `<>${sequence(content, depth)}</>`;
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
function render(node, depth) {
|
|
@@ -121,14 +136,14 @@ function printer(model, target) {
|
|
|
121
136
|
if (node.slots.length && target === 'react') {
|
|
122
137
|
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
138
|
}
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const start = wrapped ? `<${node.tag}\n${attrs.map(value => indent(depth + 1) + value).join('\n')}\n${indent(depth)}` : opening;
|
|
139
|
+
const wrapped = attrs.length > 0;
|
|
140
|
+
const start = wrapped ? `<${node.tag}\n${attrs.map(value => indent(depth + 1) + value).join('\n')}\n${indent(depth)}` : `<${node.tag}`;
|
|
127
141
|
const children = target === 'vue' ? node.children : node.children.filter(child => child.kind !== 'slot');
|
|
128
|
-
const
|
|
142
|
+
const owner = target === 'html-next' ? node : undefined;
|
|
143
|
+
const arranged = layout(children, owner);
|
|
129
144
|
if (!arranged.nodes.length && (node.component || target === 'react')) return `${start}${wrapped ? '' : ' '}/>`;
|
|
130
145
|
if (voidElements.has(node.tag)) return `${start}>`;
|
|
131
|
-
const content = sequence(children, depth + 1, false,
|
|
146
|
+
const content = sequence(children, depth + 1, false, owner);
|
|
132
147
|
return arranged.multiline
|
|
133
148
|
? `${start}>\n${content}\n${indent(depth)}</${node.tag}>`
|
|
134
149
|
: `${start}>${content}</${node.tag}>`;
|
|
@@ -136,8 +151,8 @@ function printer(model, target) {
|
|
|
136
151
|
|
|
137
152
|
function body(depth) {
|
|
138
153
|
const arranged = layout(model.nodes);
|
|
139
|
-
if (target
|
|
140
|
-
return
|
|
154
|
+
if (target === 'react') return reactValue(model.nodes, depth);
|
|
155
|
+
return (arranged.multiline ? '' : indent(depth)) + sequence(model.nodes, depth);
|
|
141
156
|
}
|
|
142
157
|
|
|
143
158
|
return {
|
|
@@ -155,15 +170,14 @@ export function frameworkExamples(example, components) {
|
|
|
155
170
|
const line = `import { ${names.join(', ')} } from ${JSON.stringify(owner)};`;
|
|
156
171
|
return line.length <= 100 ? line : `import {\n${names.map(name => ` ${name},`).join('\n')}\n} from ${JSON.stringify(owner)};`;
|
|
157
172
|
}).join('\n');
|
|
158
|
-
const links = model.components.map(component => `<link
|
|
159
|
-
const
|
|
173
|
+
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');
|
|
174
|
+
const html = printer(exampleInvocations(example.markup, []), 'html-next').body(0);
|
|
175
|
+
const codes = { 'html-next': { language: 'html', code: [links, html].filter(Boolean).join('\n\n') } };
|
|
160
176
|
for (const target of ['vue', 'react', 'svelte']) {
|
|
161
177
|
const output = printer(model, target);
|
|
162
178
|
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
179
|
codes[target] = target === 'react'
|
|
166
|
-
? { language: 'tsx', code: `${imports ? imports + '\n\n' : ''}export default function Example() {\n ${
|
|
180
|
+
? { language: 'tsx', code: `${imports ? imports + '\n\n' : ''}export default function Example() {\n return ${output.body(1)};\n}` }
|
|
167
181
|
: { language: target, code: script + (target === 'vue' ? `<template>\n${output.body(1)}\n</template>` : [output.snippets(), output.body(0)].filter(Boolean).join('\n\n')) };
|
|
168
182
|
}
|
|
169
183
|
return { ...codes, ...example.frameworks };
|