@malloydata/malloyyo 0.2.55 → 0.2.57
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/dist/index.js +923 -380
- package/dist/shared/nav.ts +222 -30
- package/dist/templates/skills/malloyyo-datasets/SKILL.md +35 -0
- package/package.json +1 -1
package/dist/shared/nav.ts
CHANGED
|
@@ -8,6 +8,28 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Dependency-free so the Node dev server and the emitted static site share it.
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* What the switcher renders. A dashboard arrives with its SLUG already built —
|
|
13
|
+
* the address, from the one place that knows how addresses are made. This type
|
|
14
|
+
* is deliberately not the engine's `TreeDataset`: that one is the hosted menu's
|
|
15
|
+
* shape, which builds its own hrefs from dataset + name.
|
|
16
|
+
*/
|
|
17
|
+
export interface SwitcherDashboard {
|
|
18
|
+
/** How this dashboard is addressed on this host. */
|
|
19
|
+
slug: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SwitcherDataset {
|
|
24
|
+
dataset: string;
|
|
25
|
+
title?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
dashboards: SwitcherDashboard[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What `siblingList` needs of a dashboard: an address and something to call
|
|
31
|
+
it. The switcher has its own shape (`SwitcherDashboard`) because it is a
|
|
32
|
+
tree and this is a list. */
|
|
11
33
|
export interface NavDashboard {
|
|
12
34
|
name: string;
|
|
13
35
|
title?: string;
|
|
@@ -30,47 +52,59 @@ export const LOGO = `<svg viewBox="0 0 240 240" width="20" height="20" aria-hidd
|
|
|
30
52
|
page chrome, so it shouldn't invert with the color scheme. */
|
|
31
53
|
export const NAV_CSS = `
|
|
32
54
|
.dash-nav{display:flex;gap:4px;align-items:center;padding:8px 14px;background:#000;font:13px system-ui,-apple-system,sans-serif;flex-wrap:wrap}
|
|
33
|
-
/* The home icon
|
|
34
|
-
keeps its own square hit area. */
|
|
55
|
+
/* The home icon keeps its own square hit area. */
|
|
35
56
|
.dash-nav a.brand{display:inline-flex;align-items:center;justify-content:center;color:#9aa1ac;padding:5px;border-radius:6px;text-decoration:none}
|
|
36
57
|
.dash-nav a.brand:hover{background:#1f232a;color:#fff}
|
|
37
58
|
.dash-nav .brand svg{display:block}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
.dash-
|
|
59
|
+
/* The switcher: the same control the hosted app uses, in vanilla. A row of
|
|
60
|
+
pills stops working at about five dashboards — a repo with four datasets has
|
|
61
|
+
fifteen — so the list moves into a menu and the bar keeps one button. */
|
|
62
|
+
.dash-pick{position:relative;font:13px system-ui,-apple-system,sans-serif}
|
|
63
|
+
.dash-pick>button{display:flex;align-items:center;gap:6px;max-width:60vw;padding:4px 8px;border:0;border-radius:6px;
|
|
64
|
+
background:transparent;color:#c9ced6;font:inherit;cursor:pointer}
|
|
65
|
+
.dash-pick>button:hover{background:#1f232a;color:#fff}
|
|
66
|
+
.dash-pick .ds{font-weight:600;color:#fff}
|
|
67
|
+
.dash-pick .slash{color:#5b6270}
|
|
68
|
+
.dash-pick .lbl{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
69
|
+
.dash-pick .chev{flex:none;opacity:.6}
|
|
70
|
+
.dash-pick[data-open="1"] .panel{display:block}
|
|
71
|
+
.dash-pick .panel{display:none;position:absolute;left:0;top:100%;margin-top:4px;z-index:50;width:340px;max-width:92vw;
|
|
72
|
+
background:#fff;color:#111;border:1px solid #d7dbe0;border-radius:8px;box-shadow:0 10px 30px rgba(0,0,0,.25)}
|
|
73
|
+
.dash-pick .filter{padding:6px;border-bottom:1px solid #eceef1}
|
|
74
|
+
.dash-pick .filter input{width:100%;box-sizing:border-box;padding:5px 8px;border:0;border-radius:4px;background:#f3f4f6;
|
|
75
|
+
font:12px ui-monospace,SFMono-Regular,Menlo,monospace;color:#111}
|
|
76
|
+
.dash-pick .filter input:focus{outline:0}
|
|
77
|
+
.dash-pick .list{max-height:60vh;overflow-y:auto;padding:4px}
|
|
78
|
+
.dash-pick .branch{display:flex;align-items:center;gap:5px;width:100%;padding:4px 6px;border:0;border-radius:4px;
|
|
79
|
+
background:transparent;font:inherit;font-weight:600;color:#111;cursor:pointer;text-align:left}
|
|
80
|
+
.dash-pick .branch:hover{background:#f3f4f6}
|
|
81
|
+
.dash-pick .branch .tw{flex:none;transition:transform .12s}
|
|
82
|
+
.dash-pick .branch[aria-expanded="true"] .tw{transform:rotate(90deg)}
|
|
83
|
+
.dash-pick .leaf{display:block;padding:4px 8px;border-radius:4px;text-decoration:none;color:#374151;
|
|
84
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
85
|
+
.dash-pick .leaf:hover{background:#f3f4f6}
|
|
86
|
+
.dash-pick .leaf.on{background:#111;color:#fff}
|
|
87
|
+
.dash-pick .kids{display:none}
|
|
88
|
+
.dash-pick .kids.indent .leaf{margin-left:16px}
|
|
89
|
+
.dash-pick .grp[data-open="1"] .kids{display:block}
|
|
90
|
+
.dash-pick .empty{padding:6px 8px;color:#9aa1ac}
|
|
91
|
+
@media (prefers-color-scheme:dark){
|
|
92
|
+
.dash-pick .panel{background:#0b0d11;color:#e6e8eb;border-color:#262b33}
|
|
93
|
+
.dash-pick .filter{border-bottom-color:#1a1e25}
|
|
94
|
+
.dash-pick .filter input{background:#14181e;color:#e6e8eb}
|
|
95
|
+
.dash-pick .branch{color:#e6e8eb}
|
|
96
|
+
.dash-pick .branch:hover,.dash-pick .leaf:hover{background:#171b22}
|
|
97
|
+
.dash-pick .leaf{color:#c9ced6}
|
|
98
|
+
.dash-pick .leaf.on{background:#fff;color:#000}
|
|
99
|
+
}
|
|
42
100
|
`;
|
|
43
101
|
|
|
44
|
-
/** Render the bar. `href` maps a dashboard name to a link for THIS host — the
|
|
45
|
-
only thing that varies across dev / pages / vercel. The brand shows even for
|
|
46
|
-
a single dashboard; only the switcher links are conditional. */
|
|
47
|
-
export const MALLOYYO_REPO = "https://github.com/malloydata/malloyyo";
|
|
48
|
-
|
|
49
102
|
/** Home, back to the landing page. Attribution lives on that page rather than
|
|
50
103
|
in the bar — the bar should be navigation. */
|
|
51
104
|
const HOME_ICON = `<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" \
|
|
52
105
|
stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">\
|
|
53
106
|
<path d="M3 10.2 12 3.5l9 6.7"/><path d="M5.2 8.9V20h13.6V8.9"/><path d="M9.6 20v-6.2h4.8V20"/></svg>`;
|
|
54
107
|
|
|
55
|
-
export function navHtml(
|
|
56
|
-
active: string,
|
|
57
|
-
all: NavDashboard[],
|
|
58
|
-
href: (name: string) => string,
|
|
59
|
-
homeHref = "./",
|
|
60
|
-
): string {
|
|
61
|
-
const brand =
|
|
62
|
-
`<a class="brand" href="${esc(homeHref)}" title="Home" aria-label="Home">${HOME_ICON}</a>`;
|
|
63
|
-
if (all.length <= 1) return `<nav class="dash-nav">${brand}</nav>`;
|
|
64
|
-
const links = all
|
|
65
|
-
.map(
|
|
66
|
-
(x) =>
|
|
67
|
-
`<a href="${esc(href(x.name))}"${x.name === active ? ' class="on"' : ""}>` +
|
|
68
|
-
`${esc(x.title || x.name)}</a>`,
|
|
69
|
-
)
|
|
70
|
-
.join("");
|
|
71
|
-
return `<nav class="dash-nav">${brand}<span class="sep"></span>${links}</nav>`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
108
|
/** The sibling list a host injects as `window.__DASHBOARDS__`, in nav order and
|
|
75
109
|
excluding the current page.
|
|
76
110
|
*
|
|
@@ -92,3 +126,161 @@ export function siblingList<T extends NavDashboard & { description?: string }>(
|
|
|
92
126
|
href: href(d.name),
|
|
93
127
|
}));
|
|
94
128
|
}
|
|
129
|
+
|
|
130
|
+
// ── The dashboard switcher ──────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The same control the hosted app puts in its header (src/components/
|
|
134
|
+
* DashboardTree.tsx), in dependency-free HTML + a little script so the dev
|
|
135
|
+
* server and every static bundle can render it.
|
|
136
|
+
*
|
|
137
|
+
* A row of pills stops scaling at about five dashboards — a repo with four
|
|
138
|
+
* datasets has fifteen, wrapping onto three lines with two of them called
|
|
139
|
+
* "About". So: one button saying where you are, and a menu holding everything.
|
|
140
|
+
*
|
|
141
|
+
* The tree is INLINED rather than fetched. A bundle is a static site with no
|
|
142
|
+
* API to ask, and the dev server already knows the answer at render time.
|
|
143
|
+
*
|
|
144
|
+
* A single-dataset repo gets a flat list with no branches and no filter box —
|
|
145
|
+
* the same judgement the hosted one makes, for the same reason: one dataset is
|
|
146
|
+
* not a tree.
|
|
147
|
+
*/
|
|
148
|
+
export function switcherHtml(
|
|
149
|
+
activeSlug: string,
|
|
150
|
+
tree: SwitcherDataset[],
|
|
151
|
+
href: (slug: string) => string,
|
|
152
|
+
opts: { dataset?: string; label?: string } = {},
|
|
153
|
+
): string {
|
|
154
|
+
// `flat` decides LAYOUT ONLY — no branches, no filter box, for a repo with one
|
|
155
|
+
// dataset. It must never decide an address: slugs arrive already built, by the
|
|
156
|
+
// one place that knows the convention (repo.ts). Deriving them here from
|
|
157
|
+
// `tree.length` disagreed with that place for a repo holding exactly one
|
|
158
|
+
// dataset under `datasets/` — the shape every new repo starts in — and emitted
|
|
159
|
+
// links to pages that do not exist.
|
|
160
|
+
const flat = tree.length <= 1;
|
|
161
|
+
|
|
162
|
+
const groups = tree
|
|
163
|
+
.map((ds) => {
|
|
164
|
+
const open =
|
|
165
|
+
flat || ds.dashboards.some((d) => d.slug === activeSlug) ? ' data-open="1"' : "";
|
|
166
|
+
const leaves = ds.dashboards
|
|
167
|
+
.map((d) => {
|
|
168
|
+
const on = d.slug === activeSlug ? " on" : "";
|
|
169
|
+
return (
|
|
170
|
+
`<a class="leaf${on}" href="${esc(href(d.slug))}"` +
|
|
171
|
+
`${d.description ? ` title="${esc(d.description)}"` : ""}` +
|
|
172
|
+
` data-find="${esc(`${ds.dataset} ${ds.title ?? ""} ${d.slug} ${d.title}`.toLowerCase())}">` +
|
|
173
|
+
`${esc(d.title)}</a>`
|
|
174
|
+
);
|
|
175
|
+
})
|
|
176
|
+
.join("");
|
|
177
|
+
if (flat) return `<div class="grp" data-open="1"><div class="kids">${leaves}</div></div>`;
|
|
178
|
+
return (
|
|
179
|
+
`<div class="grp"${open} data-ds="${esc(`${ds.dataset} ${ds.title ?? ""}`.toLowerCase())}">` +
|
|
180
|
+
`<button class="branch" aria-expanded="${open ? "true" : "false"}">` +
|
|
181
|
+
`<svg class="tw" width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" ` +
|
|
182
|
+
`stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>` +
|
|
183
|
+
`<span title="${esc(ds.dataset)}">${esc(ds.title ?? ds.dataset)}</span></button>` +
|
|
184
|
+
`<div class="kids indent">${leaves}</div></div>`
|
|
185
|
+
);
|
|
186
|
+
})
|
|
187
|
+
.join("");
|
|
188
|
+
|
|
189
|
+
const filter = flat
|
|
190
|
+
? ""
|
|
191
|
+
: `<div class="filter"><input type="search" placeholder="filter…" aria-label="Filter dashboards"></div>`;
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
`<div class="dash-pick" data-open="0">` +
|
|
195
|
+
`<button type="button" aria-haspopup="menu" aria-expanded="false" title="All datasets and dashboards">` +
|
|
196
|
+
(opts.dataset ? `<span class="ds">${esc(opts.dataset)}</span><span class="slash">/</span>` : "") +
|
|
197
|
+
`<span class="lbl">${esc(opts.label ?? "dashboards")}</span>` +
|
|
198
|
+
`<svg class="chev" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" ` +
|
|
199
|
+
`stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>` +
|
|
200
|
+
`</button>` +
|
|
201
|
+
`<div class="panel" role="menu">${filter}<div class="list">${groups}` +
|
|
202
|
+
(flat ? "" : `<div class="empty" hidden>no match</div>`) +
|
|
203
|
+
`</div></div>` +
|
|
204
|
+
`</div>`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The switcher's behaviour: open/close, filter, expand. Inline it once per
|
|
209
|
+
page. Same rules as the hosted menu — Escape and a click outside close it,
|
|
210
|
+
a search opens everything that matched (hiding a match behind a closed
|
|
211
|
+
branch is the one thing a search must not do), and clearing the search puts
|
|
212
|
+
the branches back the way the page rendered them. That last part needs the
|
|
213
|
+
rendered state remembered: without it, closing the menu after a search left
|
|
214
|
+
the searched-for dataset expanded and the one you are standing in shut. */
|
|
215
|
+
export const SWITCHER_JS = `
|
|
216
|
+
(function(){
|
|
217
|
+
var p=document.querySelector('.dash-pick'); if(!p) return;
|
|
218
|
+
var btn=p.querySelector(':scope>button'), inp=p.querySelector('.filter input');
|
|
219
|
+
var grps=[].slice.call(p.querySelectorAll('.grp'));
|
|
220
|
+
var none=p.querySelector('.empty');
|
|
221
|
+
// How the page rendered: which branch holds the dashboard you are on. A
|
|
222
|
+
// cleared search restores this rather than whatever the search expanded.
|
|
223
|
+
var init=grps.map(function(g){return g.dataset.open==='1';});
|
|
224
|
+
function setOpen(g,on){
|
|
225
|
+
g.dataset.open=on?'1':'0';
|
|
226
|
+
var b=g.querySelector('.branch'); if(b) b.setAttribute('aria-expanded',on?'true':'false');
|
|
227
|
+
}
|
|
228
|
+
function openState(on){
|
|
229
|
+
p.dataset.open=on?'1':'0';
|
|
230
|
+
btn.setAttribute('aria-expanded',on?'true':'false');
|
|
231
|
+
if(!on&&inp){inp.value='';apply('');}
|
|
232
|
+
if(on&&inp){inp.focus();}
|
|
233
|
+
}
|
|
234
|
+
function apply(q){
|
|
235
|
+
q=q.trim().toLowerCase();
|
|
236
|
+
var hits=0;
|
|
237
|
+
grps.forEach(function(g,i){
|
|
238
|
+
var ds=g.dataset.ds||'', dsHit=!!q&&ds.indexOf(q)>=0;
|
|
239
|
+
var any=false;
|
|
240
|
+
[].slice.call(g.querySelectorAll('.leaf')).forEach(function(a){
|
|
241
|
+
var hit=!q||dsHit||(a.dataset.find||'').indexOf(q)>=0;
|
|
242
|
+
a.style.display=hit?'':'none'; if(hit){any=true;hits++;}
|
|
243
|
+
});
|
|
244
|
+
g.style.display=any?'':'none';
|
|
245
|
+
// While searching, everything that survived is open; with the box empty,
|
|
246
|
+
// back to how the page rendered.
|
|
247
|
+
setOpen(g,q?any:init[i]);
|
|
248
|
+
});
|
|
249
|
+
if(none) none.hidden=!q||hits>0;
|
|
250
|
+
}
|
|
251
|
+
btn.addEventListener('click',function(e){e.stopPropagation();openState(p.dataset.open!=='1');});
|
|
252
|
+
grps.forEach(function(g){
|
|
253
|
+
var b=g.querySelector('.branch'); if(!b) return;
|
|
254
|
+
b.addEventListener('click',function(e){
|
|
255
|
+
e.stopPropagation();
|
|
256
|
+
setOpen(g,g.dataset.open!=='1');
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
if(inp){inp.addEventListener('input',function(){apply(inp.value);});
|
|
260
|
+
inp.addEventListener('click',function(e){e.stopPropagation();});}
|
|
261
|
+
// Chrome inside the panel is not a dismissal — padding and the filter row's
|
|
262
|
+
// margin used to bubble to the document handler and close the menu.
|
|
263
|
+
var panel=p.querySelector('.panel');
|
|
264
|
+
if(panel) panel.addEventListener('click',function(e){e.stopPropagation();});
|
|
265
|
+
document.addEventListener('click',function(){ if(p.dataset.open==='1') openState(false); });
|
|
266
|
+
document.addEventListener('keydown',function(e){ if(e.key==='Escape') openState(false); });
|
|
267
|
+
})();
|
|
268
|
+
`;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The bar: brand, then the switcher. Both hosts render exactly this; the only
|
|
272
|
+
* thing that differs is the link shape, which is already a parameter.
|
|
273
|
+
*
|
|
274
|
+
* Replaces two copies that each rebuilt the bar by calling `navHtml` with an
|
|
275
|
+
* empty list and regex-stripping its wrapper tags back off.
|
|
276
|
+
*/
|
|
277
|
+
export function navWithSwitcher(
|
|
278
|
+
activeSlug: string,
|
|
279
|
+
tree: SwitcherDataset[],
|
|
280
|
+
href: (slug: string) => string,
|
|
281
|
+
opts: { dataset?: string; label?: string; homeHref?: string } = {},
|
|
282
|
+
): string {
|
|
283
|
+
const brand =
|
|
284
|
+
`<a class="brand" href="${esc(opts.homeHref ?? "./")}" title="Home" aria-label="Home">${HOME_ICON}</a>`;
|
|
285
|
+
return `<nav class="dash-nav">${brand}${switcherHtml(activeSlug, tree, href, opts)}</nav>`;
|
|
286
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: malloyyo-datasets
|
|
3
|
+
description: Add a dataset to a malloyyo model repo, or split one dataset into several. Use when someone asks to add a dataset to a repo, or to separate what a repo publishes into more than one dataset. A repo publishes one dataset per directory under datasets/, and publishes as a unit.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Datasets in a malloyyo repo
|
|
7
|
+
|
|
8
|
+
The procedure ships with the CLI, so it always matches the `malloyyo` you have
|
|
9
|
+
installed rather than whatever was current when this repo was scaffolded:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
mcp__malloyyo_author__yo_help("repo/datasets")
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Read that first. It covers the layout, adding a dataset, and splitting one
|
|
16
|
+
dataset into several.
|
|
17
|
+
|
|
18
|
+
Two things to get right before you touch files:
|
|
19
|
+
|
|
20
|
+
- **A dataset's name is its directory name**, slugified — `datasets/the-look/`
|
|
21
|
+
publishes `the_look`. That name is the identity: the URL, what a publish
|
|
22
|
+
matches on, and what a role is granted against.
|
|
23
|
+
- **Its title and description are separate**, and presentation only — at model
|
|
24
|
+
scope in its `index.malloy`:
|
|
25
|
+
|
|
26
|
+
##" What this dataset is.
|
|
27
|
+
## dataset { title="HubSpot CRM" }
|
|
28
|
+
|
|
29
|
+
`##"` is the MODEL's doc string; a single `#"` would attach to the next
|
|
30
|
+
declaration instead. Title derives from the name when absent.
|
|
31
|
+
- **`malloy-config.json` can be at the repo root** (shared by every dataset) or
|
|
32
|
+
**in a dataset** (its own, replacing the root's). Nearest one wins.
|
|
33
|
+
|
|
34
|
+
Check your work with `malloyyo lint`, which reads the repo exactly as the server
|
|
35
|
+
does — a clean lint means the server will accept it.
|