@firetail/finchly-ux 0.0.0-stage → 0.1.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/README.md +267 -2
- package/dist/components/action-button.d.ts +12 -0
- package/dist/components/action-button.js +34 -0
- package/dist/components/action-button.js.map +1 -0
- package/dist/components/app-shell.d.ts +18 -0
- package/dist/components/app-shell.js +56 -0
- package/dist/components/app-shell.js.map +1 -0
- package/dist/components/ask.d.ts +37 -0
- package/dist/components/ask.js +73 -0
- package/dist/components/ask.js.map +1 -0
- package/dist/components/bar.d.ts +11 -0
- package/dist/components/bar.js +187 -0
- package/dist/components/bar.js.map +1 -0
- package/dist/components/choosing.d.ts +18 -0
- package/dist/components/choosing.js +68 -0
- package/dist/components/choosing.js.map +1 -0
- package/dist/components/column-chart.d.ts +50 -0
- package/dist/components/column-chart.js +181 -0
- package/dist/components/column-chart.js.map +1 -0
- package/dist/components/composing.d.ts +40 -0
- package/dist/components/composing.js +101 -0
- package/dist/components/composing.js.map +1 -0
- package/dist/components/conversation.d.ts +50 -0
- package/dist/components/conversation.js +116 -0
- package/dist/components/conversation.js.map +1 -0
- package/dist/components/data-table.d.ts +43 -0
- package/dist/components/data-table.js +212 -0
- package/dist/components/data-table.js.map +1 -0
- package/dist/components/fields.d.ts +61 -0
- package/dist/components/fields.js +144 -0
- package/dist/components/fields.js.map +1 -0
- package/dist/components/file-button.d.ts +16 -0
- package/dist/components/file-button.js +39 -0
- package/dist/components/file-button.js.map +1 -0
- package/dist/components/form-dialog.d.ts +51 -0
- package/dist/components/form-dialog.js +113 -0
- package/dist/components/form-dialog.js.map +1 -0
- package/dist/components/link-button.d.ts +5 -0
- package/dist/components/link-button.js +24 -0
- package/dist/components/link-button.js.map +1 -0
- package/dist/components/link-tabs.d.ts +13 -0
- package/dist/components/link-tabs.js +26 -0
- package/dist/components/link-tabs.js.map +1 -0
- package/dist/components/markdown.d.ts +13 -0
- package/dist/components/markdown.js +132 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/page.d.ts +18 -0
- package/dist/components/page.js +45 -0
- package/dist/components/page.js.map +1 -0
- package/dist/components/palette.d.ts +16 -0
- package/dist/components/palette.js +27 -0
- package/dist/components/palette.js.map +1 -0
- package/dist/components/panel.d.ts +12 -0
- package/dist/components/panel.js +30 -0
- package/dist/components/panel.js.map +1 -0
- package/dist/components/pick-tile.d.ts +21 -0
- package/dist/components/pick-tile.js +40 -0
- package/dist/components/pick-tile.js.map +1 -0
- package/dist/components/provider-mark.d.ts +33 -0
- package/dist/components/provider-mark.js +58 -0
- package/dist/components/provider-mark.js.map +1 -0
- package/dist/components/provider.d.ts +17 -0
- package/dist/components/provider.js +39 -0
- package/dist/components/provider.js.map +1 -0
- package/dist/components/rows.d.ts +48 -0
- package/dist/components/rows.js +112 -0
- package/dist/components/rows.js.map +1 -0
- package/dist/components/side-nav.d.ts +23 -0
- package/dist/components/side-nav.js +41 -0
- package/dist/components/side-nav.js.map +1 -0
- package/dist/components/states.d.ts +19 -0
- package/dist/components/states.js +45 -0
- package/dist/components/states.js.map +1 -0
- package/dist/components/suggest-field.d.ts +19 -0
- package/dist/components/suggest-field.js +124 -0
- package/dist/components/suggest-field.js.map +1 -0
- package/dist/components/tag.d.ts +27 -0
- package/dist/components/tag.js +38 -0
- package/dist/components/tag.js.map +1 -0
- package/dist/components/text.d.ts +41 -0
- package/dist/components/text.js +97 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/tile.d.ts +30 -0
- package/dist/components/tile.js +68 -0
- package/dist/components/tile.js.map +1 -0
- package/dist/components/toast.d.ts +10 -0
- package/dist/components/toast.js +38 -0
- package/dist/components/toast.js.map +1 -0
- package/dist/components/ui/alert-dialog.d.ts +18 -0
- package/dist/components/ui/alert.d.ts +10 -0
- package/dist/components/ui/badge.d.ts +7 -0
- package/dist/components/ui/button.d.ts +8 -0
- package/dist/components/ui/button.js +45 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/card.d.ts +11 -0
- package/dist/components/ui/card.js +57 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +3 -0
- package/dist/components/ui/checkbox.js +20 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/collapsible.d.ts +5 -0
- package/dist/components/ui/collapsible.js +24 -0
- package/dist/components/ui/collapsible.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/dialog.js +92 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +29 -0
- package/dist/components/ui/dropdown-menu.js +65 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/empty.d.ts +11 -0
- package/dist/components/ui/field.d.ts +24 -0
- package/dist/components/ui/field.js +89 -0
- package/dist/components/ui/field.js.map +1 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.js +16 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/label.d.ts +3 -0
- package/dist/components/ui/label.js +14 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/native-select.d.ts +8 -0
- package/dist/components/ui/native-select.js +39 -0
- package/dist/components/ui/native-select.js.map +1 -0
- package/dist/components/ui/radio-group.d.ts +5 -0
- package/dist/components/ui/radio-group.js +27 -0
- package/dist/components/ui/radio-group.js.map +1 -0
- package/dist/components/ui/separator.d.ts +3 -0
- package/dist/components/ui/separator.js +15 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/skeleton.d.ts +2 -0
- package/dist/components/ui/skeleton.js +13 -0
- package/dist/components/ui/skeleton.js.map +1 -0
- package/dist/components/ui/spinner.d.ts +2 -0
- package/dist/components/ui/spinner.js +16 -0
- package/dist/components/ui/spinner.js.map +1 -0
- package/dist/components/ui/table.d.ts +10 -0
- package/dist/components/ui/table.js +53 -0
- package/dist/components/ui/table.js.map +1 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/components/ui/textarea.js +14 -0
- package/dist/components/ui/textarea.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +6 -0
- package/dist/components/ui/tooltip.js +41 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/icons.d.ts +1 -0
- package/dist/icons.js +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +56 -0
- package/dist/lib/api.d.ts +49 -0
- package/dist/lib/api.js +80 -0
- package/dist/lib/api.js.map +1 -0
- package/dist/lib/chart.d.ts +35 -0
- package/dist/lib/chart.js +86 -0
- package/dist/lib/chart.js.map +1 -0
- package/dist/lib/cn.d.ts +3 -0
- package/dist/lib/cn.js +10 -0
- package/dist/lib/cn.js.map +1 -0
- package/dist/lib/events.d.ts +34 -0
- package/dist/lib/events.js +72 -0
- package/dist/lib/events.js.map +1 -0
- package/dist/lib/format.d.ts +16 -0
- package/dist/lib/format.js +71 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/hash.d.ts +2 -0
- package/dist/lib/hash.js +13 -0
- package/dist/lib/hash.js.map +1 -0
- package/dist/lib/launcher.d.ts +54 -0
- package/dist/lib/launcher.js +46 -0
- package/dist/lib/launcher.js.map +1 -0
- package/dist/lib/markdown-inline.d.ts +18 -0
- package/dist/lib/markdown-inline.js +155 -0
- package/dist/lib/markdown-inline.js.map +1 -0
- package/dist/lib/markdown.d.ts +40 -0
- package/dist/lib/markdown.js +198 -0
- package/dist/lib/markdown.js.map +1 -0
- package/dist/lib/marks.d.ts +17 -0
- package/dist/lib/marks.js +56 -0
- package/dist/lib/marks.js.map +1 -0
- package/dist/lib/over.d.ts +26 -0
- package/dist/lib/over.js +38 -0
- package/dist/lib/over.js.map +1 -0
- package/dist/lib/route.d.ts +15 -0
- package/dist/lib/route.js +29 -0
- package/dist/lib/route.js.map +1 -0
- package/dist/lib/table.d.ts +43 -0
- package/dist/lib/table.js +86 -0
- package/dist/lib/table.js.map +1 -0
- package/dist/lib/theme.d.ts +12 -0
- package/dist/lib/theme.js +42 -0
- package/dist/lib/theme.js.map +1 -0
- package/eslint/index.d.ts +8 -0
- package/eslint/index.js +135 -0
- package/eslint/page-imports.js +46 -0
- package/package.json +91 -4
- package/styles/styles.css +221 -0
- package/styles/tokens.css +99 -0
- package/tsconfig.app.json +21 -0
- package/vite/index.d.ts +16 -0
- package/vite/index.js +84 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marks.js","names":[],"sources":["../../src/lib/marks.ts"],"sourcesContent":["// The marks of the platforms things are connected to. Nothing here knows\n// of a page.\n\n/**\n * Which mark stands for what: a kind of connection of the platform's\n * (spec/connectors.md), a provider of the toolbox's tools, or an MCP\n * server the platform knows of, by its id. The marks are kept by the\n * platform's connections, at notification-service/static/logos/<mark>.svg,\n * each in its own colour. One that is not here is shown by its initials.\n *\n * This is where a mark is added. A test (test/marks.test.ts) holds it to\n * what there is to connect: every provider of the toolbox's tools, every\n * server the platform knows of and every kind of connection has a mark,\n * or is named there as having none.\n */\nexport const MARKS: Readonly<Record<string, string>> = Object.freeze({\n github: \"github\",\n gitlab: \"gitlab\",\n git: \"git\",\n hubspot: \"hubspot\",\n \"hubspot-crm\": \"hubspot-crm\",\n anthropic: \"anthropic\",\n openai: \"openai\",\n atlassian: \"atlassian\",\n \"atlassian-mcp\": \"atlassian\",\n \"google-workspace\": \"google-workspace\",\n tailscale: \"tailscale\",\n auth0: \"auth0\",\n airtable: \"airtable\",\n slack: \"slack\",\n \"slack-mcp\": \"slack\",\n msteams: \"msteams\",\n azure: \"azure\",\n cloudflare: \"cloudflare\",\n \"cloudflare-docs\": \"cloudflare\",\n aws: \"aws\",\n \"aws-sts\": \"aws\",\n \"aws-agentcore\": \"aws\",\n \"aws-knowledge\": \"aws\",\n \"aws-bedrock\": \"aws\",\n \"azure-ai-foundry\": \"azure\",\n \"brave-search\": \"brave\",\n tavily: \"tavily\",\n apollo: \"apollo\",\n \"apollo-mcp\": \"apollo\",\n});\n\n/** Where the mark for something is kept, or null where there is none. */\nexport function markOf(id: string | null | undefined): string | null {\n return typeof id === \"string\" && Object.hasOwn(MARKS, id) ? `/notification-service/static/logos/${MARKS[id]}.svg` : null;\n}\n\n/** The letters that stand for something that has no mark: its words' first letters, three at most, or the first two of one word. */\nexport function markLetters(name: string | null | undefined): string {\n const words = String(name ?? \"\")\n .replace(/[^A-Za-z0-9 ]/g, \" \")\n .trim()\n .split(/\\s+/)\n .filter(Boolean);\n return (words.length > 1 ? words.slice(0, 3).map((word) => word.charAt(0)).join(\"\") : (words[0] ?? \"?\").slice(0, 2)).toUpperCase();\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,IAAa,QAA0C,OAAO,OAAO;CACnE,QAAQ;CACR,QAAQ;CACR,KAAK;CACL,SAAS;CACT,eAAe;CACf,WAAW;CACX,QAAQ;CACR,WAAW;CACX,iBAAiB;CACjB,oBAAoB;CACpB,WAAW;CACX,OAAO;CACP,UAAU;CACV,OAAO;CACP,aAAa;CACb,SAAS;CACT,OAAO;CACP,YAAY;CACZ,mBAAmB;CACnB,KAAK;CACL,WAAW;CACX,iBAAiB;CACjB,iBAAiB;CACjB,eAAe;CACf,oBAAoB;CACpB,gBAAgB;CAChB,QAAQ;CACR,QAAQ;CACR,cAAc;AAChB,CAAC;;AAGD,SAAgB,OAAO,IAA8C;CACnE,OAAO,OAAO,OAAO,YAAY,OAAO,OAAO,OAAO,EAAE,IAAI,sCAAsC,MAAM,IAAI,QAAQ;AACtH;;AAGA,SAAgB,YAAY,MAAyC;CACnE,MAAM,QAAQ,OAAO,QAAQ,EAAE,CAAC,CAC7B,QAAQ,kBAAkB,GAAG,CAAC,CAC9B,KAAK,CAAC,CACN,MAAM,KAAK,CAAC,CACZ,OAAO,OAAO;CACjB,QAAQ,MAAM,SAAS,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,MAAM,MAAM,IAAA,CAAK,MAAM,GAAG,CAAC,EAAA,CAAG,YAAY;AACnI"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** What a window is opened through, and placed by. Given in a test. */
|
|
2
|
+
export interface Opener {
|
|
3
|
+
open: (url?: string, target?: string, features?: string) => Window | null;
|
|
4
|
+
screen: {
|
|
5
|
+
availWidth: number;
|
|
6
|
+
availHeight: number;
|
|
7
|
+
};
|
|
8
|
+
screenX: number;
|
|
9
|
+
screenY: number;
|
|
10
|
+
outerWidth: number;
|
|
11
|
+
outerHeight: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Open a page of this platform in a window over the one the person is
|
|
15
|
+
* on. They stay where they are, and the window is closed from here once
|
|
16
|
+
* what it was opened for is done (`closeOver`). It cannot reach back: it
|
|
17
|
+
* is given no way to this page, whatever it goes on to, such as a
|
|
18
|
+
* provider's page to sign in at. Where a browser opens no window, it is
|
|
19
|
+
* opened in another tab.
|
|
20
|
+
*
|
|
21
|
+
* @param url a path on this platform
|
|
22
|
+
* @returns the window, to close afterwards. Null where it was opened in a tab
|
|
23
|
+
*/
|
|
24
|
+
export declare function openOver(url: string, world?: Opener): Window | null;
|
|
25
|
+
/** Close a window that was opened over the page. Nothing where there is none, or it is closed already. */
|
|
26
|
+
export declare function closeOver(over: Window | null | undefined): void;
|
package/dist/lib/over.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/lib/over.ts
|
|
2
|
+
/**
|
|
3
|
+
* Open a page of this platform in a window over the one the person is
|
|
4
|
+
* on. They stay where they are, and the window is closed from here once
|
|
5
|
+
* what it was opened for is done (`closeOver`). It cannot reach back: it
|
|
6
|
+
* is given no way to this page, whatever it goes on to, such as a
|
|
7
|
+
* provider's page to sign in at. Where a browser opens no window, it is
|
|
8
|
+
* opened in another tab.
|
|
9
|
+
*
|
|
10
|
+
* @param url a path on this platform
|
|
11
|
+
* @returns the window, to close afterwards. Null where it was opened in a tab
|
|
12
|
+
*/
|
|
13
|
+
function openOver(url, world = window) {
|
|
14
|
+
const width = Math.min(560, world.screen.availWidth);
|
|
15
|
+
const height = Math.min(760, world.screen.availHeight);
|
|
16
|
+
const left = Math.max(0, Math.round(world.screenX + (world.outerWidth - width) / 2));
|
|
17
|
+
const top = Math.max(0, Math.round(world.screenY + (world.outerHeight - height) / 2));
|
|
18
|
+
const over = world.open("", "finchly-over", `popup=yes,width=${width},height=${height},left=${left},top=${top}`);
|
|
19
|
+
if (!over) {
|
|
20
|
+
world.open(url, "_blank", "noopener");
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
over.opener = null;
|
|
25
|
+
} catch {}
|
|
26
|
+
over.location.replace(url);
|
|
27
|
+
over.focus();
|
|
28
|
+
return over;
|
|
29
|
+
}
|
|
30
|
+
/** Close a window that was opened over the page. Nothing where there is none, or it is closed already. */
|
|
31
|
+
function closeOver(over) {
|
|
32
|
+
try {
|
|
33
|
+
over?.close();
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
export { closeOver, openOver };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=over.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"over.js","names":[],"sources":["../../src/lib/over.ts"],"sourcesContent":["// A page of this platform opened in a window over the one a person is\n// on: where something is connected, or switched on, without their\n// leaving what they were doing.\n\n/** What a window is opened through, and placed by. Given in a test. */\nexport interface Opener {\n open: (url?: string, target?: string, features?: string) => Window | null;\n screen: { availWidth: number; availHeight: number };\n screenX: number;\n screenY: number;\n outerWidth: number;\n outerHeight: number;\n}\n\n/**\n * Open a page of this platform in a window over the one the person is\n * on. They stay where they are, and the window is closed from here once\n * what it was opened for is done (`closeOver`). It cannot reach back: it\n * is given no way to this page, whatever it goes on to, such as a\n * provider's page to sign in at. Where a browser opens no window, it is\n * opened in another tab.\n *\n * @param url a path on this platform\n * @returns the window, to close afterwards. Null where it was opened in a tab\n */\nexport function openOver(url: string, world: Opener = window): Window | null {\n const width = Math.min(560, world.screen.availWidth);\n const height = Math.min(760, world.screen.availHeight);\n const left = Math.max(0, Math.round(world.screenX + (world.outerWidth - width) / 2));\n const top = Math.max(0, Math.round(world.screenY + (world.outerHeight - height) / 2));\n // Named, so that the page it opens knows it was opened over another, and says that it closes by itself.\n const over = world.open(\"\", \"finchly-over\", `popup=yes,width=${width},height=${height},left=${left},top=${top}`);\n if (!over) {\n world.open(url, \"_blank\", \"noopener\");\n return null;\n }\n try {\n over.opener = null;\n } catch {\n // One left open from before, now at a provider's own page: it was given no way back when it was opened.\n }\n over.location.replace(url);\n over.focus();\n return over;\n}\n\n/** Close a window that was opened over the page. Nothing where there is none, or it is closed already. */\nexport function closeOver(over: Window | null | undefined): void {\n try {\n over?.close();\n } catch {\n // Closed already.\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,SAAgB,SAAS,KAAa,QAAgB,QAAuB;CAC3E,MAAM,QAAQ,KAAK,IAAI,KAAK,MAAM,OAAO,UAAU;CACnD,MAAM,SAAS,KAAK,IAAI,KAAK,MAAM,OAAO,WAAW;CACrD,MAAM,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,WAAW,MAAM,aAAa,SAAS,CAAC,CAAC;CACnF,MAAM,MAAM,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,WAAW,MAAM,cAAc,UAAU,CAAC,CAAC;CAEpF,MAAM,OAAO,MAAM,KAAK,IAAI,gBAAgB,mBAAmB,MAAM,UAAU,OAAO,QAAQ,KAAK,OAAO,KAAK;CAC/G,IAAI,CAAC,MAAM;EACT,MAAM,KAAK,KAAK,UAAU,UAAU;EACpC,OAAO;CACT;CACA,IAAI;EACF,KAAK,SAAS;CAChB,QAAQ,CAER;CACA,KAAK,SAAS,QAAQ,GAAG;CACzB,KAAK,MAAM;CACX,OAAO;AACT;;AAGA,SAAgB,UAAU,MAAuC;CAC/D,IAAI;EACF,MAAM,MAAM;CACd,QAAQ,CAER;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** What an address names: a section, and a thing within it where it names one. */
|
|
2
|
+
export interface Route {
|
|
3
|
+
section: string;
|
|
4
|
+
id: string | null;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* What an address names after its `#`. Nothing named is the section `""`.
|
|
8
|
+
* What follows the section is one thing, whatever slashes its own name
|
|
9
|
+
* has. An escape that cannot be read names nothing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function routeOf(hash: string): Route;
|
|
12
|
+
/** The address of a section, or of a thing within it. */
|
|
13
|
+
export declare function addressOf(section: string, id?: string | null): string;
|
|
14
|
+
/** What the page's address names, kept up with as it changes. */
|
|
15
|
+
export declare function useRoute(): Route;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useHash } from "./hash.js";
|
|
2
|
+
// src/lib/route.ts
|
|
3
|
+
/**
|
|
4
|
+
* What an address names after its `#`. Nothing named is the section `""`.
|
|
5
|
+
* What follows the section is one thing, whatever slashes its own name
|
|
6
|
+
* has. An escape that cannot be read names nothing.
|
|
7
|
+
*/
|
|
8
|
+
function routeOf(hash) {
|
|
9
|
+
const [, section = "", ...rest] = hash.slice(hash.indexOf("#") + 1).split("/");
|
|
10
|
+
let id = null;
|
|
11
|
+
try {
|
|
12
|
+
id = rest.length > 0 && rest[0] !== "" ? decodeURIComponent(rest.join("/")) : null;
|
|
13
|
+
} catch {}
|
|
14
|
+
return {
|
|
15
|
+
section,
|
|
16
|
+
id
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** The address of a section, or of a thing within it. */
|
|
20
|
+
function addressOf(section, id) {
|
|
21
|
+
return id === void 0 || id === null ? `#/${section}` : `#/${section}/${encodeURIComponent(id)}`;
|
|
22
|
+
}
|
|
23
|
+
/** What the page's address names, kept up with as it changes. */
|
|
24
|
+
function useRoute() {
|
|
25
|
+
return routeOf(useHash());
|
|
26
|
+
}
|
|
27
|
+
export { addressOf, routeOf, useRoute };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","names":[],"sources":["../../src/lib/route.ts"],"sourcesContent":["// A page with sections, each with an address of its own: `#/users` is\n// the section `users`, and `#/users/abc` the thing `abc` within it. So\n// that a section and a thing in it can be linked to, and the browser's\n// own way back works.\n\nimport { useHash } from \"./hash\";\n\n/** What an address names: a section, and a thing within it where it names one. */\nexport interface Route {\n section: string;\n id: string | null;\n}\n\n/**\n * What an address names after its `#`. Nothing named is the section `\"\"`.\n * What follows the section is one thing, whatever slashes its own name\n * has. An escape that cannot be read names nothing.\n */\nexport function routeOf(hash: string): Route {\n const [, section = \"\", ...rest] = hash.slice(hash.indexOf(\"#\") + 1).split(\"/\");\n let id: string | null = null;\n try {\n id = rest.length > 0 && rest[0] !== \"\" ? decodeURIComponent(rest.join(\"/\")) : null;\n } catch {\n // A malformed escape names nothing.\n }\n return { section, id };\n}\n\n/** The address of a section, or of a thing within it. */\nexport function addressOf(section: string, id?: string | null): string {\n return id === undefined || id === null ? `#/${section}` : `#/${section}/${encodeURIComponent(id)}`;\n}\n\n/** What the page's address names, kept up with as it changes. */\nexport function useRoute(): Route {\n return routeOf(useHash());\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,QAAQ,MAAqB;CAC3C,MAAM,GAAG,UAAU,IAAI,GAAG,QAAQ,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG;CAC7E,IAAI,KAAoB;CACxB,IAAI;EACF,KAAK,KAAK,SAAS,KAAK,KAAK,OAAO,KAAK,mBAAmB,KAAK,KAAK,GAAG,CAAC,IAAI;CAChF,QAAQ,CAER;CACA,OAAO;EAAE;EAAS;CAAG;AACvB;;AAGA,SAAgB,UAAU,SAAiB,IAA4B;CACrE,OAAO,OAAO,KAAA,KAAa,OAAO,OAAO,KAAK,YAAY,KAAK,QAAQ,GAAG,mBAAmB,EAAE;AACjG;;AAGA,SAAgB,WAAkB;CAChC,OAAO,QAAQ,QAAQ,CAAC;AAC1B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Fewer rows than this are read at a glance: there is nothing to search or narrow. */
|
|
2
|
+
export declare const FEW = 8;
|
|
3
|
+
/** A column with more values than this is searched, not chosen from. */
|
|
4
|
+
export declare const CHOICES = 12;
|
|
5
|
+
/** What a column needs to say of a row, to be sorted, searched and chosen by. */
|
|
6
|
+
export interface Says<Row> {
|
|
7
|
+
header: string;
|
|
8
|
+
cell: (row: Row) => unknown;
|
|
9
|
+
align?: "start" | "end";
|
|
10
|
+
text?: (row: Row) => string | number | null | undefined;
|
|
11
|
+
time?: (row: Row) => string | null | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** How a table is narrowed and ordered: what the person has typed and chosen. */
|
|
14
|
+
export interface Narrowing {
|
|
15
|
+
search: string;
|
|
16
|
+
/** What a column must say, by the column's place. */
|
|
17
|
+
chosen: Record<number, string>;
|
|
18
|
+
/** Calendar dates, as a date field gives them (`2026-11-19`). Both are included. */
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
/** The place of the column to sort by, or -1 for the order the rows came in. */
|
|
22
|
+
sort: number;
|
|
23
|
+
descending: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare const AS_LISTED: Narrowing;
|
|
26
|
+
/** What a column says of a row, in words. Where the column does not say, what its cell shows, if that is text or a number. */
|
|
27
|
+
export declare function saidOf<Row>(column: Says<Row>, row: Row): string;
|
|
28
|
+
/** When a column's time is, as a number to compare. A day with no time is the start of that day here. */
|
|
29
|
+
export declare function timeOf<Row>(column: Says<Row>, row: Row): number | null;
|
|
30
|
+
/**
|
|
31
|
+
* The values a column can be narrowed to, or null where a choice would
|
|
32
|
+
* not narrow anything: a column that says one of a few things, more than
|
|
33
|
+
* once. Not a column of things to do, of numbers, or of times.
|
|
34
|
+
*/
|
|
35
|
+
export declare function choicesOf<Row>(column: Says<Row>, rows: Row[]): string[] | null;
|
|
36
|
+
/**
|
|
37
|
+
* The rows that are shown, in the order they are shown in: those that
|
|
38
|
+
* say what was searched for in any column, say what was chosen in each
|
|
39
|
+
* column narrowed, and are within the dates, by the first column that
|
|
40
|
+
* says a time. Sorted by the column asked for, and as they came where
|
|
41
|
+
* none is.
|
|
42
|
+
*/
|
|
43
|
+
export declare function narrowed<Row>(columns: Array<Says<Row>>, rows: Row[], how: Narrowing): Row[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var AS_LISTED = {
|
|
2
|
+
search: "",
|
|
3
|
+
chosen: {},
|
|
4
|
+
from: "",
|
|
5
|
+
to: "",
|
|
6
|
+
sort: -1,
|
|
7
|
+
descending: false
|
|
8
|
+
};
|
|
9
|
+
/** What a column says of a row, in words. Where the column does not say, what its cell shows, if that is text or a number. */
|
|
10
|
+
function saidOf(column, row) {
|
|
11
|
+
const said = column.text ? column.text(row) : column.cell(row);
|
|
12
|
+
return typeof said === "string" || typeof said === "number" ? String(said) : "";
|
|
13
|
+
}
|
|
14
|
+
/** When a column's time is, as a number to compare. A day with no time is the start of that day here. */
|
|
15
|
+
function timeOf(column, row) {
|
|
16
|
+
const said = column.time?.(row);
|
|
17
|
+
if (!said) return null;
|
|
18
|
+
const at = new Date(/^\d{4}-\d{2}-\d{2}$/.test(said) ? `${said}T00:00:00` : said).getTime();
|
|
19
|
+
return Number.isNaN(at) ? null : at;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The values a column can be narrowed to, or null where a choice would
|
|
23
|
+
* not narrow anything: a column that says one of a few things, more than
|
|
24
|
+
* once. Not a column of things to do, of numbers, or of times.
|
|
25
|
+
*/
|
|
26
|
+
function choicesOf(column, rows) {
|
|
27
|
+
if (column.header === "" || column.align === "end" || column.time) return null;
|
|
28
|
+
if (rows.some((row) => typeof (column.text ? column.text(row) : column.cell(row)) === "number")) return null;
|
|
29
|
+
const values = [...new Set(rows.map((row) => saidOf(column, row)))].filter((value) => value !== "").sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
|
|
30
|
+
return values.length < 2 || values.length > 12 || values.length >= rows.length ? null : values;
|
|
31
|
+
}
|
|
32
|
+
/** What a column is sorted by: its time, a number where it says one, else its words. */
|
|
33
|
+
function sortValue(column, row) {
|
|
34
|
+
if (column.time) return timeOf(column, row) ?? Number.NEGATIVE_INFINITY;
|
|
35
|
+
const said = column.text ? column.text(row) : column.cell(row);
|
|
36
|
+
if (typeof said === "number") return said;
|
|
37
|
+
const text = saidOf(column, row);
|
|
38
|
+
if (column.align === "end") {
|
|
39
|
+
const number = Number(text.replace(/[^\d.+-]/g, ""));
|
|
40
|
+
if (text !== "" && Number.isFinite(number)) return number;
|
|
41
|
+
}
|
|
42
|
+
return text;
|
|
43
|
+
}
|
|
44
|
+
/** The start of a calendar day here, and of the day after it. */
|
|
45
|
+
var dayStart = (date) => (/* @__PURE__ */ new Date(`${date}T00:00:00`)).getTime();
|
|
46
|
+
function dayEnd(date) {
|
|
47
|
+
const next = /* @__PURE__ */ new Date(`${date}T00:00:00`);
|
|
48
|
+
next.setDate(next.getDate() + 1);
|
|
49
|
+
return next.getTime();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The rows that are shown, in the order they are shown in: those that
|
|
53
|
+
* say what was searched for in any column, say what was chosen in each
|
|
54
|
+
* column narrowed, and are within the dates, by the first column that
|
|
55
|
+
* says a time. Sorted by the column asked for, and as they came where
|
|
56
|
+
* none is.
|
|
57
|
+
*/
|
|
58
|
+
function narrowed(columns, rows, how) {
|
|
59
|
+
const sought = how.search.trim().toLowerCase();
|
|
60
|
+
const dated = columns.find((column) => column.time);
|
|
61
|
+
const after = how.from ? dayStart(how.from) : null;
|
|
62
|
+
const before = how.to ? dayEnd(how.to) : null;
|
|
63
|
+
const shown = rows.filter((row) => {
|
|
64
|
+
if (sought !== "" && !columns.some((column) => saidOf(column, row).toLowerCase().includes(sought))) return false;
|
|
65
|
+
for (const [place, value] of Object.entries(how.chosen)) {
|
|
66
|
+
const column = columns[Number(place)];
|
|
67
|
+
if (value !== "" && column && saidOf(column, row) !== value) return false;
|
|
68
|
+
}
|
|
69
|
+
if (dated && (after !== null || before !== null)) {
|
|
70
|
+
const at = timeOf(dated, row);
|
|
71
|
+
if (at === null || after !== null && at < after || before !== null && at >= before) return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
const by = columns[how.sort];
|
|
76
|
+
if (!by) return shown;
|
|
77
|
+
const direction = how.descending ? -1 : 1;
|
|
78
|
+
return [...shown].sort((a, b) => {
|
|
79
|
+
const x = sortValue(by, a);
|
|
80
|
+
const y = sortValue(by, b);
|
|
81
|
+
return direction * (typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), void 0, { numeric: true }));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export { AS_LISTED, choicesOf, narrowed, saidOf, timeOf };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","names":[],"sources":["../../src/lib/table.ts"],"sourcesContent":["// What a table works out without a page: what each column says of a row,\n// which rows are shown once it is searched and narrowed, and in what\n// order. Kept apart from the component so that it is tested by itself.\n\n/** Fewer rows than this are read at a glance: there is nothing to search or narrow. */\nexport const FEW = 8;\n/** A column with more values than this is searched, not chosen from. */\nexport const CHOICES = 12;\n\n/** What a column needs to say of a row, to be sorted, searched and chosen by. */\nexport interface Says<Row> {\n header: string;\n cell: (row: Row) => unknown;\n align?: \"start\" | \"end\";\n text?: (row: Row) => string | number | null | undefined;\n time?: (row: Row) => string | null | undefined;\n}\n\n/** How a table is narrowed and ordered: what the person has typed and chosen. */\nexport interface Narrowing {\n search: string;\n /** What a column must say, by the column's place. */\n chosen: Record<number, string>;\n /** Calendar dates, as a date field gives them (`2026-11-19`). Both are included. */\n from: string;\n to: string;\n /** The place of the column to sort by, or -1 for the order the rows came in. */\n sort: number;\n descending: boolean;\n}\n\nexport const AS_LISTED: Narrowing = { search: \"\", chosen: {}, from: \"\", to: \"\", sort: -1, descending: false };\n\n/** What a column says of a row, in words. Where the column does not say, what its cell shows, if that is text or a number. */\nexport function saidOf<Row>(column: Says<Row>, row: Row): string {\n const said = column.text ? column.text(row) : column.cell(row);\n return typeof said === \"string\" || typeof said === \"number\" ? String(said) : \"\";\n}\n\n/** When a column's time is, as a number to compare. A day with no time is the start of that day here. */\nexport function timeOf<Row>(column: Says<Row>, row: Row): number | null {\n const said = column.time?.(row);\n if (!said) return null;\n const at = new Date(/^\\d{4}-\\d{2}-\\d{2}$/.test(said) ? `${said}T00:00:00` : said).getTime();\n return Number.isNaN(at) ? null : at;\n}\n\n/**\n * The values a column can be narrowed to, or null where a choice would\n * not narrow anything: a column that says one of a few things, more than\n * once. Not a column of things to do, of numbers, or of times.\n */\nexport function choicesOf<Row>(column: Says<Row>, rows: Row[]): string[] | null {\n if (column.header === \"\" || column.align === \"end\" || column.time) return null;\n // A column that says a number is one of numbers, whichever side it is set to: a bar with its figure, for one.\n if (rows.some((row) => typeof (column.text ? column.text(row) : column.cell(row)) === \"number\")) return null;\n const values = [...new Set(rows.map((row) => saidOf(column, row)))].filter((value) => value !== \"\").sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));\n return values.length < 2 || values.length > CHOICES || values.length >= rows.length ? null : values;\n}\n\n/** What a column is sorted by: its time, a number where it says one, else its words. */\nfunction sortValue<Row>(column: Says<Row>, row: Row): string | number {\n // What has no time, in a column of times, is before all that have one: \"never\" is first, and last from the latest.\n if (column.time) return timeOf(column, row) ?? Number.NEGATIVE_INFINITY;\n const said = column.text ? column.text(row) : column.cell(row);\n if (typeof said === \"number\") return said;\n const text = saidOf(column, row);\n if (column.align === \"end\") {\n // A column of numbers, said with their units: \"1,204 calls\" is 1204.\n const number = Number(text.replace(/[^\\d.+-]/g, \"\"));\n if (text !== \"\" && Number.isFinite(number)) return number;\n }\n return text;\n}\n\n/** The start of a calendar day here, and of the day after it. */\nconst dayStart = (date: string): number => new Date(`${date}T00:00:00`).getTime();\nfunction dayEnd(date: string): number {\n const next = new Date(`${date}T00:00:00`);\n next.setDate(next.getDate() + 1);\n return next.getTime();\n}\n\n/**\n * The rows that are shown, in the order they are shown in: those that\n * say what was searched for in any column, say what was chosen in each\n * column narrowed, and are within the dates, by the first column that\n * says a time. Sorted by the column asked for, and as they came where\n * none is.\n */\nexport function narrowed<Row>(columns: Array<Says<Row>>, rows: Row[], how: Narrowing): Row[] {\n const sought = how.search.trim().toLowerCase();\n const dated = columns.find((column) => column.time);\n const after = how.from ? dayStart(how.from) : null;\n const before = how.to ? dayEnd(how.to) : null;\n const shown = rows.filter((row) => {\n if (sought !== \"\" && !columns.some((column) => saidOf(column, row).toLowerCase().includes(sought))) return false;\n for (const [place, value] of Object.entries(how.chosen)) {\n const column = columns[Number(place)];\n if (value !== \"\" && column && saidOf(column, row) !== value) return false;\n }\n if (dated && (after !== null || before !== null)) {\n const at = timeOf(dated, row);\n if (at === null || (after !== null && at < after) || (before !== null && at >= before)) return false;\n }\n return true;\n });\n const by = columns[how.sort];\n if (!by) return shown;\n const direction = how.descending ? -1 : 1;\n return [...shown].sort((a, b) => {\n const x = sortValue(by, a);\n const y = sortValue(by, b);\n return direction * (typeof x === \"number\" && typeof y === \"number\" ? x - y : String(x).localeCompare(String(y), undefined, { numeric: true }));\n });\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Scheme = "light" | "dark";
|
|
2
|
+
/**
|
|
3
|
+
* What the page is drawn in now. Where the person has not chosen, that is
|
|
4
|
+
* their tenant's own beginning, or their system's: the stylesheets say
|
|
5
|
+
* which, and the page is asked.
|
|
6
|
+
*/
|
|
7
|
+
export declare function currentScheme(): Scheme;
|
|
8
|
+
/** The scheme the page is in, and the way to change to the other. */
|
|
9
|
+
export declare function useScheme(): {
|
|
10
|
+
scheme: Scheme;
|
|
11
|
+
toggle: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
// src/lib/theme.ts
|
|
3
|
+
var KEY = "finchly-theme";
|
|
4
|
+
/** The theme the person chose here before, if they did. */
|
|
5
|
+
function chosen() {
|
|
6
|
+
try {
|
|
7
|
+
const value = localStorage.getItem(KEY);
|
|
8
|
+
return value === "light" || value === "dark" ? value : null;
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* What the page is drawn in now. Where the person has not chosen, that is
|
|
15
|
+
* their tenant's own beginning, or their system's: the stylesheets say
|
|
16
|
+
* which, and the page is asked.
|
|
17
|
+
*/
|
|
18
|
+
function currentScheme() {
|
|
19
|
+
const said = chosen();
|
|
20
|
+
if (said) return said;
|
|
21
|
+
const drawn = getComputedStyle(document.documentElement).colorScheme;
|
|
22
|
+
if (drawn === "dark" || drawn === "light") return drawn;
|
|
23
|
+
return matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
24
|
+
}
|
|
25
|
+
/** The scheme the page is in, and the way to change to the other. */
|
|
26
|
+
function useScheme() {
|
|
27
|
+
const [scheme, setScheme] = useState(currentScheme);
|
|
28
|
+
return {
|
|
29
|
+
scheme,
|
|
30
|
+
toggle: useCallback(() => {
|
|
31
|
+
const next = currentScheme() === "dark" ? "light" : "dark";
|
|
32
|
+
document.documentElement.dataset.theme = next;
|
|
33
|
+
try {
|
|
34
|
+
localStorage.setItem(KEY, next);
|
|
35
|
+
} catch {}
|
|
36
|
+
setScheme(next);
|
|
37
|
+
}, [])
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export { currentScheme, useScheme };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","names":[],"sources":["../../src/lib/theme.ts"],"sourcesContent":["// Light and dark. A person's choice is kept in their browser, and is the\n// same choice the gateway's own pages go by, under the same name.\n\nimport { useCallback, useState } from \"react\";\n\nconst KEY = \"finchly-theme\";\nexport type Scheme = \"light\" | \"dark\";\n\n/** The theme the person chose here before, if they did. */\nfunction chosen(): Scheme | null {\n try {\n const value = localStorage.getItem(KEY);\n return value === \"light\" || value === \"dark\" ? value : null;\n } catch {\n return null;\n }\n}\n\n/**\n * What the page is drawn in now. Where the person has not chosen, that is\n * their tenant's own beginning, or their system's: the stylesheets say\n * which, and the page is asked.\n */\nexport function currentScheme(): Scheme {\n const said = chosen();\n if (said) return said;\n const drawn = getComputedStyle(document.documentElement).colorScheme;\n if (drawn === \"dark\" || drawn === \"light\") return drawn;\n return matchMedia(\"(prefers-color-scheme: dark)\").matches ? \"dark\" : \"light\";\n}\n\n/** The scheme the page is in, and the way to change to the other. */\nexport function useScheme(): { scheme: Scheme; toggle: () => void } {\n const [scheme, setScheme] = useState<Scheme>(currentScheme);\n const toggle = useCallback(() => {\n const next: Scheme = currentScheme() === \"dark\" ? \"light\" : \"dark\";\n document.documentElement.dataset.theme = next;\n try {\n localStorage.setItem(KEY, next);\n } catch {\n // Kept for this page only.\n }\n setScheme(next);\n }, []);\n return { scheme, toggle };\n}\n"],"mappings":";;AAKA,IAAM,MAAM;;AAIZ,SAAS,SAAwB;CAC/B,IAAI;EACF,MAAM,QAAQ,aAAa,QAAQ,GAAG;EACtC,OAAO,UAAU,WAAW,UAAU,SAAS,QAAQ;CACzD,QAAQ;EACN,OAAO;CACT;AACF;;;;;;AAOA,SAAgB,gBAAwB;CACtC,MAAM,OAAO,OAAO;CACpB,IAAI,MAAM,OAAO;CACjB,MAAM,QAAQ,iBAAiB,SAAS,eAAe,CAAC,CAAC;CACzD,IAAI,UAAU,UAAU,UAAU,SAAS,OAAO;CAClD,OAAO,WAAW,8BAA8B,CAAC,CAAC,UAAU,SAAS;AACvE;;AAGA,SAAgB,YAAoD;CAClE,MAAM,CAAC,QAAQ,aAAa,SAAiB,aAAa;CAW1D,OAAO;EAAE;EAAQ,QAVF,kBAAkB;GAC/B,MAAM,OAAe,cAAc,MAAM,SAAS,UAAU;GAC5D,SAAS,gBAAgB,QAAQ,QAAQ;GACzC,IAAI;IACF,aAAa,QAAQ,KAAK,IAAI;GAChC,QAAQ,CAER;GACA,UAAU,IAAI;EAChB,GAAG,CAAC,CACa;CAAO;AAC1B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Linter } from "eslint";
|
|
2
|
+
|
|
3
|
+
/** No file of a page is longer than this. */
|
|
4
|
+
export const MAX_LINES: number;
|
|
5
|
+
/** The checks for an app's page. `files` are `src/**/*.{ts,tsx}` unless said. */
|
|
6
|
+
export function app(options?: { files?: string[] }): Linter.Config[];
|
|
7
|
+
/** The checks for finchly-ux itself. */
|
|
8
|
+
export function library(options?: { files?: string[] }): Linter.Config[];
|
package/eslint/index.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// The checks every page built on finchly-ux passes. They are what keeps
|
|
2
|
+
// pages written by many hands, at many times, the same: a rule here is
|
|
3
|
+
// one nobody has to remember.
|
|
4
|
+
//
|
|
5
|
+
// import { app } from "@firetail/finchly-ux/eslint";
|
|
6
|
+
// export default app();
|
|
7
|
+
//
|
|
8
|
+
// Two sets: `app` for a page's own code, and `library` for finchly-ux
|
|
9
|
+
// itself, which is where the things an app may not do are done once.
|
|
10
|
+
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import tailwind from "eslint-plugin-better-tailwindcss";
|
|
14
|
+
import reactHooks from "eslint-plugin-react-hooks";
|
|
15
|
+
import tseslint from "typescript-eslint";
|
|
16
|
+
import { pageImports } from "./page-imports.js";
|
|
17
|
+
|
|
18
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
/** The one stylesheet: what a class may be is read from it. */
|
|
20
|
+
const STYLES = join(HERE, "../styles/styles.css");
|
|
21
|
+
|
|
22
|
+
/** No file of a page is longer than this. A longer one is doing more than one thing: divide it. */
|
|
23
|
+
export const MAX_LINES = 300;
|
|
24
|
+
|
|
25
|
+
const NO_DARK = { pattern: "^(.*:)?dark:.*$", message: "A page is dark where its tokens are. Use a token (bg-card, text-muted-foreground), or for-light / for-dark for what must differ." };
|
|
26
|
+
const NO_ARBITRARY = { pattern: "^.*\\[.*\\].*$", message: "No value of your own in a class: use the scale and the tokens. If something cannot be said with them, it belongs in finchly-ux." };
|
|
27
|
+
|
|
28
|
+
/** What both sets share: TypeScript, React's rules for hooks, and classes that exist. */
|
|
29
|
+
function shared(files) {
|
|
30
|
+
return [
|
|
31
|
+
...tseslint.configs.recommended.map((config) => ({ ...config, files })),
|
|
32
|
+
{
|
|
33
|
+
files,
|
|
34
|
+
plugins: { "react-hooks": reactHooks, "better-tailwindcss": tailwind },
|
|
35
|
+
settings: { "better-tailwindcss": { entryPoint: STYLES } },
|
|
36
|
+
rules: {
|
|
37
|
+
...reactHooks.configs.flat.recommended.rules,
|
|
38
|
+
// A class that is not Tailwind's, with the platform's tokens, is a mistake: it does nothing.
|
|
39
|
+
"better-tailwindcss/no-unknown-classes": ["error", { ignore: ["^base-ui-disable-scrollbar$"] }],
|
|
40
|
+
"better-tailwindcss/no-conflicting-classes": "error",
|
|
41
|
+
"better-tailwindcss/no-duplicate-classes": "error",
|
|
42
|
+
"max-lines": ["error", { max: MAX_LINES, skipBlankLines: true, skipComments: true }],
|
|
43
|
+
"@typescript-eslint/consistent-type-imports": ["error", { fixStyle: "inline-type-imports" }],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The checks for finchly-ux itself.
|
|
51
|
+
*
|
|
52
|
+
* @param {{ files?: string[] }} [options]
|
|
53
|
+
*/
|
|
54
|
+
export function library({ files = ["src/**/*.{ts,tsx}"] } = {}) {
|
|
55
|
+
return [
|
|
56
|
+
...shared(files),
|
|
57
|
+
{
|
|
58
|
+
files,
|
|
59
|
+
rules: {
|
|
60
|
+
"better-tailwindcss/no-restricted-classes": ["error", { restrict: [NO_DARK] }],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
// shadcn's own, brought in by `npm run add`: kept as they came, so that one can be brought in again.
|
|
65
|
+
files: files.map((pattern) => pattern.replace("src/", "src/components/ui/")),
|
|
66
|
+
rules: { "max-lines": "off", "@typescript-eslint/consistent-type-imports": "off" },
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** What an app's page may not write itself, and what it uses in its place. */
|
|
72
|
+
const ELEMENTS = {
|
|
73
|
+
button: "Button, or LinkButton for a link",
|
|
74
|
+
input: "TextField, or Input and Checkbox",
|
|
75
|
+
select: "SelectField, or NativeSelect",
|
|
76
|
+
textarea: "Textarea",
|
|
77
|
+
table: "DataTable, or Table",
|
|
78
|
+
dialog: "FormDialog or ConfirmDialog",
|
|
79
|
+
label: "TextField and SelectField label themselves; otherwise Label",
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** What an app's page may not import, and where it finds the thing instead. */
|
|
83
|
+
const IMPORTS = {
|
|
84
|
+
paths: [
|
|
85
|
+
{ name: "lucide-react", message: "Icons are imported from @firetail/finchly-ux/icons." },
|
|
86
|
+
{ name: "@tanstack/react-query", message: "useQuery and useMutation are imported from @firetail/finchly-ux: two copies on a page do not see each other." },
|
|
87
|
+
...["clsx", "tailwind-merge", "class-variance-authority"].map((name) => ({ name, message: "Use cn from @firetail/finchly-ux. A component with variants of its own belongs in finchly-ux." })),
|
|
88
|
+
],
|
|
89
|
+
patterns: [
|
|
90
|
+
{ group: ["@firetail/finchly-ux/*", "!@firetail/finchly-ux/icons", "!@firetail/finchly-ux/styles.css"], message: "Import from @firetail/finchly-ux itself. What it does not export is not for a page to use." },
|
|
91
|
+
{ group: ["@base-ui/*", "@radix-ui/*", "radix-ui"], message: "A page is built from finchly-ux. If it lacks a component, add it there (in the finchly-ux repository: npm run add)." },
|
|
92
|
+
{ group: ["*.css", "!@firetail/finchly-ux/styles.css"], message: "A page has no stylesheet of its own. Use finchly-ux's components and Tailwind's classes." },
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
/** A model knows nothing of a page. A type may still be imported: it is gone once the page is built. */
|
|
96
|
+
const MODEL_IMPORTS = {
|
|
97
|
+
paths: IMPORTS.paths,
|
|
98
|
+
patterns: [...IMPORTS.patterns, { group: ["react", "react-dom", "react-dom/*", "@firetail/finchly-ux", "@firetail/finchly-ux/*"], allowTypeImports: true, message: "A model knows nothing of a page: no React, and nothing from finchly-ux." }],
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The checks for an app's page.
|
|
103
|
+
*
|
|
104
|
+
* @param {{ files?: string[] }} [options]
|
|
105
|
+
*/
|
|
106
|
+
export function app({ files = ["src/**/*.{ts,tsx}"] } = {}) {
|
|
107
|
+
return [
|
|
108
|
+
...shared(files),
|
|
109
|
+
{
|
|
110
|
+
files,
|
|
111
|
+
plugins: { finchly: { rules: { "page-imports": pageImports } } },
|
|
112
|
+
rules: {
|
|
113
|
+
"finchly/page-imports": "error",
|
|
114
|
+
"better-tailwindcss/no-restricted-classes": ["error", { restrict: [NO_DARK, NO_ARBITRARY] }],
|
|
115
|
+
"no-restricted-imports": ["error", IMPORTS],
|
|
116
|
+
"no-restricted-globals": ["error", { name: "fetch", message: "Ask through a client made with createApi(), so that a refusal and a session that has ended are handled as on every page." }],
|
|
117
|
+
"no-restricted-syntax": [
|
|
118
|
+
"error",
|
|
119
|
+
...Object.entries(ELEMENTS).map(([element, instead]) => ({ selector: `JSXOpeningElement[name.name='${element}']`, message: `No <${element}> of a page's own. Use ${instead}, from @firetail/finchly-ux.` })),
|
|
120
|
+
{ selector: "JSXAttribute[name.name='style']", message: "No style of a page's own: the platform's pages take none. Use Tailwind's classes." },
|
|
121
|
+
{ selector: "JSXAttribute[name.name='dangerouslySetInnerHTML']", message: "Nothing a page shows is read as HTML." },
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
// What can be worked out without a page is kept apart from it, and tested without one.
|
|
127
|
+
files: files.flatMap((pattern) => [pattern.replace(/\*\*\/\*\.\{ts,tsx\}$/, "**/model.ts"), pattern.replace(/\*\*\/\*\.\{ts,tsx\}$/, "**/*.model.ts")]),
|
|
128
|
+
rules: {
|
|
129
|
+
"no-restricted-imports": "off",
|
|
130
|
+
"@typescript-eslint/no-restricted-imports": ["error", MODEL_IMPORTS],
|
|
131
|
+
"no-restricted-globals": ["error", "document", "window", "fetch", "localStorage"],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
const publicUI = new Set(["@firetail/finchly-ux", "@firetail/finchly-ux/icons", "@firetail/finchly-ux/styles.css"]);
|
|
5
|
+
const projects = new Map();
|
|
6
|
+
|
|
7
|
+
function projectFor(filename) {
|
|
8
|
+
const config = ts.findConfigFile(dirname(filename), ts.sys.fileExists);
|
|
9
|
+
if (!config) return null;
|
|
10
|
+
if (!projects.has(config)) {
|
|
11
|
+
const root = dirname(config);
|
|
12
|
+
const { config: json } = ts.readConfigFile(config, ts.sys.readFile);
|
|
13
|
+
const { options } = ts.parseJsonConfigFileContent(json, ts.sys, root);
|
|
14
|
+
projects.set(config, { root, options, cache: ts.createModuleResolutionCache(root, (path) => path, options) });
|
|
15
|
+
}
|
|
16
|
+
return projects.get(config);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** TypeScript's resolved target catches aliases and npm workspace symlinks as well as relative imports. */
|
|
20
|
+
export const pageImports = {
|
|
21
|
+
meta: { type: "problem", schema: [], messages: { boundary: "Import from this page's src, its declared shared modules, or a public package entry. Other workspaces' source is private." } },
|
|
22
|
+
create(context) {
|
|
23
|
+
const filename = context.physicalFilename;
|
|
24
|
+
const project = projectFor(filename);
|
|
25
|
+
if (!project) return {};
|
|
26
|
+
const src = resolve(project.root, "src");
|
|
27
|
+
const shared = new Set((context.settings["finchly/sharedModules"] ?? []).map((file) => resolve(project.root, file)));
|
|
28
|
+
function check(source) {
|
|
29
|
+
const name = source?.value;
|
|
30
|
+
if (typeof name !== "string" || publicUI.has(name)) return;
|
|
31
|
+
const local = name.startsWith(".") || isAbsolute(name);
|
|
32
|
+
const found = ts.resolveModuleName(name, filename, project.options, ts.sys, project.cache).resolvedModule;
|
|
33
|
+
const target = found ? ts.sys.realpath(found.resolvedFileName) : local ? resolve(dirname(filename), name) : null;
|
|
34
|
+
if (!target || shared.has(target)) return;
|
|
35
|
+
if (!local && target.split(sep).includes("node_modules")) return;
|
|
36
|
+
const path = relative(src, target);
|
|
37
|
+
if (path === ".." || path.startsWith(".." + sep) || isAbsolute(path)) context.report({ node: source, messageId: "boundary" });
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
ImportDeclaration: (node) => check(node.source),
|
|
41
|
+
ExportNamedDeclaration: (node) => check(node.source),
|
|
42
|
+
ExportAllDeclaration: (node) => check(node.source),
|
|
43
|
+
ImportExpression: (node) => check(node.source),
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,93 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firetail/finchly-ux",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "finchly-ux: the components every page of the Finchly platform and of its apps is built from, and the toolchain that builds and checks them",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/FireTail-io/finchly-ux.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"*.css"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./icons": {
|
|
25
|
+
"types": "./dist/icons.d.ts",
|
|
26
|
+
"default": "./dist/icons.js"
|
|
27
|
+
},
|
|
28
|
+
"./styles.css": "./styles/styles.css",
|
|
29
|
+
"./vite": {
|
|
30
|
+
"types": "./vite/index.d.ts",
|
|
31
|
+
"default": "./vite/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./eslint": {
|
|
34
|
+
"types": "./eslint/index.d.ts",
|
|
35
|
+
"default": "./eslint/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./tsconfig.app.json": "./tsconfig.app.json"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"styles",
|
|
42
|
+
"vite",
|
|
43
|
+
"eslint",
|
|
44
|
+
"tsconfig.app.json",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
49
|
+
"build": "npm run clean && vite build -c build.config.ts && tsc -p tsconfig.build.json",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
52
|
+
"lint": "eslint",
|
|
53
|
+
"check": "npm run lint && npm run typecheck && npm run build && npm test",
|
|
54
|
+
"add": "node scripts/add-component.mjs",
|
|
55
|
+
"prepublishOnly": "npm run check"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"eslint": "^10.15.0",
|
|
59
|
+
"react": "^19.0.0",
|
|
60
|
+
"react-dom": "^19.0.0",
|
|
61
|
+
"typescript": "~5.9.3",
|
|
62
|
+
"vite": "^8.3.8"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@base-ui/react": "^1.9.0",
|
|
66
|
+
"@tailwindcss/vite": "^4.3.5",
|
|
67
|
+
"@tanstack/react-query": "^5.108.0",
|
|
68
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
69
|
+
"class-variance-authority": "^0.7.1",
|
|
70
|
+
"clsx": "^2.1.1",
|
|
71
|
+
"eslint-plugin-better-tailwindcss": "^4.11.0",
|
|
72
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
73
|
+
"lucide-react": "^1.76.0",
|
|
74
|
+
"tailwind-merge": "^3.7.0",
|
|
75
|
+
"tailwindcss": "^4.3.5",
|
|
76
|
+
"tw-animate-css": "^1.4.0",
|
|
77
|
+
"typescript-eslint": "^8.73.0"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@testing-library/dom": "^10.4.0",
|
|
81
|
+
"@testing-library/react": "^16.3.3",
|
|
82
|
+
"@types/node": "^22.0.0",
|
|
83
|
+
"@types/react": "^19.3.0",
|
|
84
|
+
"@types/react-dom": "^19.3.0",
|
|
85
|
+
"eslint": "^10.15.0",
|
|
86
|
+
"jsdom": "^31.0.1",
|
|
87
|
+
"react": "^19.3.1",
|
|
88
|
+
"react-dom": "^19.3.1",
|
|
89
|
+
"typescript": "~5.9.3",
|
|
90
|
+
"vite": "^8.3.8",
|
|
91
|
+
"vitest": "^5.1.1"
|
|
92
|
+
}
|
|
93
|
+
}
|