em-kit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Embeddable.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,129 @@
1
- # Temporary Holding Version
1
+ # EmKit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Finished React chart, KPI and table components by [Embeddable](https://embeddable.com), for teams that already have a data layer. MIT licensed. Docs: [emkit.embeddable.com](https://emkit.embeddable.com).
4
+
5
+ EmKit is Embeddable’s chart components as a standalone React library: you bring the data. Inside Embeddable the same components are called Remarkable Pro. [Embeddable](https://embeddable.com) adds the data layer, multi-tenant security and self-serve dashboards for your customers.
6
+
7
+ Code samples import from `em-kit`; the package is not published yet. This repository is the standalone build of the Remarkable Pro components: no Embeddable runtime, builder metadata, or data loading.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ npm run sync # fetch and regenerate src/generated from remarkable-pro origin/main, then the exports and props reference
13
+ npm run exports # regenerate src/components.generated.ts from the component manifest
14
+ npm run types:check # drift alarm: fails if upstream starts using an Embeddable API the shim lacks
15
+ npm run test # smoke tests: every exported component × every data state × en/de
16
+ npm run check # all three
17
+ npm run dev # docs site on http://localhost:5310
18
+ ```
19
+
20
+ ## Build the site
21
+
22
+ ```bash
23
+ npm run site:build # dist-site/: Vite build, then every page prerendered to HTML
24
+ npm run site:check # the same, then asserts every page (one h1, title, canonical, Markdown link, install command)
25
+ npm run site:preview # serves dist-site/ on http://localhost:5311 (404.html with a 404 status for unknown paths)
26
+ ```
27
+
28
+ Each page in `sitePages()` is written to `dist-site/<path>/index.html` with its content and head tags, next to its `.md` twin, `llms.txt`, `llms-full.txt`, `sitemap.xml` and `robots.txt`. Old URLs get a small redirect page, and `_redirects` (Netlify and Cloudflare Pages format) lists them. Absolute URLs use `BRAND.url`; set `SITE_URL=http://localhost:5311` to override.
29
+
30
+ The host must serve `dist-site/404.html` with a 404 status for unknown paths (Netlify and Cloudflare Pages do this on their own). Playgrounds (`/docs/components/<slug>/playground[/<preset>]`) are rendered in the browser, so also serve `404.html` for them (`_redirects` rewrites them to it with a 200), and the page script then draws the playground. The pages load with `createRoot`, which replaces the prerendered HTML; `hydrateRoot` reports text mismatches (React error 418) on every page today.
31
+
32
+ ## Docs site (`site/`)
33
+
34
+ A landing page, the docs (shadcn-style: sidebar, page, "On this page", ⌘K search), the chart gallery with a playground per chart, and the examples. Path-routed (`site/router.ts`), so every page has a real URL: `/`, `/docs/<guide>`, `/docs/components`, `/docs/components/<id>`, `/charts`, `/charts/<id>[/<preset>]` (playground), `/examples`, `/examples/ai-chat`. Old `#/…` links and aliases rewrite to their canonical path on load. The host must serve `index.html` for unknown paths (Vite does in dev).
35
+
36
+ Docs pages are data, not JSX, so one source renders the page, its "On this page" list, "Copy Markdown" and the search index (and later `llms.txt`):
37
+
38
+ | Path | What |
39
+ |---|---|
40
+ | `site/docs/guides.ts` | Every guide page as blocks (headings, Markdown prose, code, live demos), including "Why EmKit" and its comparison with a raw chart library. |
41
+ | `site/docs/components.ts` | Per component, derived from the registry and generated props: its examples (presets, an "Other" bucket where supported, loading/empty/error), what it does for you, and its Markdown. |
42
+ | `site/docs/nav.ts` | The sidebar and the ⌘K search index. |
43
+ | `site/pages/DocPage.tsx`, `ComponentDocPage.tsx`, `ComponentsIndex.tsx` | The guide, component and components-index pages. |
44
+
45
+ | Path | What |
46
+ |---|---|
47
+ | `site/config.ts` | Brand and package name. Rename here. |
48
+ | `site/catalog/registry.tsx` | One entry per chart: the props it takes and which toggles it exposes. The live preview and the Code tab are both generated from `props(ctx)`, so they can't drift apart. |
49
+ | `site/catalog/build.ts` | Turns an entry and the current settings into render props and a copy-pasteable snippet. |
50
+ | `site/catalog/datasets.ts` | Three seeded sample datasets (SaaS, web, retail), re-aggregated per granularity like a real query. |
51
+ | `site/catalog/themes.ts` | Theme presets (Default, Ocean, Forest, Midnight) and languages. |
52
+ | `site/generated/props.ts` | Every public component's props, extracted from the types by `scripts/props.mjs` (runs with `npm run sync`). Chart pages turn it into live controls: scalar props get inputs that update the preview and the generated code together, data-bound props and handlers show as chips. `site/catalog/propNotes.ts` holds the hand-written one-liner per prop name, shown on hover. |
53
+ | `site/pages/` | Landing, Gallery, ChartPage (the playground: preview, code, data, props and event log), the docs pages above, Examples (one tab per complete app). |
54
+ | `site/components/HeroShowcase.tsx` | The landing page's one visual: the same components on a live dashboard and in an AI chat, fed by one `useLiveSeries` stream. A nested `ChartsProvider` scopes a single-hue colour ramp to both, so a value is the same colour on either surface. |
55
+ | `site/components/DemoDashboard.tsx` | The dashboard example: five components cross-filtered by one donut click, with a granularity switcher and a controlled table. `site/pages/Examples.tsx` shows the standalone version of this source; keep the two in step. |
56
+ | `site/components/ChatDemo.tsx`, `SpecPlayground.tsx` | The AI chat example: the mock chat (click → intent → next chart) and the paste-a-spec playground. |
57
+ | `site/catalog/aiSnippets.ts` | The single source for every AI code sample on the site. |
58
+ | `site/catalog/benefits.ts` | The full benefit list on the landing page (ten groups, the last full-width for AI chat). Each point says what the library does, not what you still supply, and no point repeats another anywhere on the page. Counts (design tokens, AI chart kinds) are computed from the code. |
59
+
60
+ Theme, language and dataset are site-wide settings, persisted in `localStorage`. Adding a chart means adding a registry entry.
61
+
62
+ `REMARKABLE_PRO_REF=<ref>` syncs from another ref (default `origin/main`, fetched first; `SYNC_NO_FETCH=1` skips the fetch). Uncommitted upstream work is never synced.
63
+
64
+ ### Adding a new Remarkable component
65
+
66
+ `scripts/components.manifest.mjs` lists every component remarkable-pro publishes (every directory with a `*.emb.ts` file) as `exported`, `wrapped` or `skipped` with a reason. When upstream adds one, `npm run sync` fails and prints the manifest line to add. Then:
67
+
68
+ 1. Add the line, with the standalone name (upstream name minus `Pro`).
69
+ 2. `npm run sync`. The export lands in `src/components.generated.ts`.
70
+ 3. Add a gallery entry in `site/catalog/registry.tsx` (and a title in `site/catalog/translations.ts`). `tests/manifest.test.tsx` fails until the component is exported and has a gallery entry, and the gallery entry puts it in the smoke suite.
71
+
72
+ CI: `.github/workflows/ci.yml` checks types, tests and generated exports on every push. `.github/workflows/sync-upstream.yml` runs the sync every Monday and opens a PR listing the upstream commits it brings in, or fails with the sync's reason.
73
+
74
+ ## How it's built
75
+
76
+ | Path | Owner | What |
77
+ |---|---|---|
78
+ | `src/generated/` | `scripts/sync.mjs` | remarkable-pro `src/` minus the Embeddable layer. **Never edit by hand**; fix upstream and resync. |
79
+ | `@embeddable.com/remarkable-ui` | npm | The UI primitives, used as published. `src/generated` imports them as upstream does; a change to them is a pull request on remarkable-ui, not a rewrite here. |
80
+ | `src/runtime/core.ts` | hand-written | Replaces `@embeddable.com/core`: data types (structurally identical), type guards, no-op `defineType`/`defineOption`. |
81
+ | `src/runtime/react.ts` | hand-written | Replaces `@embeddable.com/react`: theme context + `useTheme`. |
82
+ | `src/ChartsProvider.tsx` | hand-written | Merges theme overrides onto the default theme, injects CSS variables and fonts (what Embeddable's lifecycle hook does). |
83
+ | `src/TableScrollable.tsx` | hand-written | Wraps the generated scrollable table: a `resetKey` prop replaces the Embeddable `dataset` prop as the "query changed, reset paging" signal, and a `heightMode` prop replaces Embeddable's dashboard layout (`'auto'` grows the card to fit every row). |
84
+ | `src/data.ts` | hand-written | `dimension()`, `measure()`, `results()` helpers for building props. |
85
+ | `src/spec.ts` | hand-written | `ChartSpec`: the JSON-serializable chart spec an LLM tool call returns (23 chart kinds, including the KPI-tab and comparison lines and the labelled donut). |
86
+ | `src/ChartFromSpec.tsx` | hand-written | Renders a `ChartSpec` with the real components: normalizes dates/keys/types, falls back to a table or the error card, `chrome: card\|plain\|bare`, emits `ChartIntent`s on clicks, streams via `loading` + growing rows. |
87
+ | `src/intents.ts` | hand-written | `ChartIntent` + `intentToPrompt()`: chart clicks as one-line follow-up prompts. |
88
+ | `src/ai/` | hand-written + generated | `renderChartTool` / `renderChartToolOpenAI` tool definitions, `chartGuidance` prompt snippet, and the JSON Schemas (`spec.schema.generated.ts`, regenerated by `scripts/props.mjs`). Shown live on the docs site at `#/ai`. |
89
+ | `src/build/` | hand-written | `em-kit/build`: the toolkit for custom charts (theme and i18n, `getThemeFormatter`, `useFillGaps`, colours and tokens, `ChartCard`, the Chart.js primitives and the Pro data/option builders), under the upstream names. Curated: nothing is re-exported wholesale. Worked example live on the docs site at `#/docs` → "Build your own chart". |
90
+ | `src/fieldInputs.ts`, `src/fieldInputs.generated.*` | hand-written + generated | `FieldInputs`: every per-field option a chart reads from a field's `inputs`, extracted from remarkable-pro's chart definitions by `scripts/extract-field-inputs.mjs` during sync. |
91
+ | `scripts/components.manifest.mjs` | hand-written | Every upstream component and its fate: exported (under which name), wrapped, or skipped (and why). |
92
+ | `src/components.generated.ts`, `src/componentDefaults.generated.ts` | `scripts/exports.mjs` | One export per manifest component under its standalone name, with its Embeddable builder defaults applied (see below): the upstream `Pro` suffix is dropped (`BarChartDefaultPro` → `BarChart`, `KpiChartNumberPro` → `KpiNumber`, …). |
93
+ | `src/index.ts` | hand-written | Public API (v1: charts, KPIs, tables): the generated component exports plus providers, helpers, wrappers and the AI spec. |
94
+
95
+ The sync drops `*.emb.ts`, `definition.ts`, `*.loadData.utils.ts`, builder input constants, preview mocks, `src/editors`, filter builders, dimension/measure pickers, and tests. `*.type.emb.ts` files are kept and renamed `*.type.ts`, because chart code imports their option constants. Declared content rewrites fail the sync when they stop matching upstream. Currently: the colour-cache `sessionStorage` key `embeddable` → `emkit`; two upstream bug fixes awaiting an upstream release (scatter labels forced on in remarkable-pro, the KPI number's font size in remarkable-ui). After a sync, no `@embeddable.com` import may remain anywhere, in either tree.
96
+
97
+ **Builder defaults.** Embeddable's builder fills every input an author leaves unset with the default declared in the component's `definition.ts`, so upstream components can rely on it (the export menu, for one, only appears when `menuOptions` is passed). The sync records those defaults (`src/builderDefaults.generated.json`), `scripts/exports.mjs` keeps the ones that are props and type-checks them (`src/componentDefaults.generated.ts`), and every exported component applies them through `src/withDefaults.tsx`. A prop passed as `undefined` gets the default too. Charts therefore look as they do in Embeddable out of the box: value labels on for bars, lines, pies and scatter, export menu with CSV, XLSX, PNG and Maximize.
98
+
99
+ ## Data contract
100
+
101
+ - `results`: `{ isLoading, data?: Row[], error?, total? }`, the rows from your own query.
102
+ - `dimension`/`measure`: `name` is the row key. `type` is a native type (`string | number | time | boolean`); numbers are only formatted when `type` is `number`.
103
+ - Display options go on `inputs`, e.g. `prefix`, `suffix`, `decimalPlaces`, `displayName`, `displayNullAs`.
104
+ - Time values are ISO strings without a zone: `YYYY-MM-DDTHH:mm:ss.sss`. A time dimension's value goes under its `name`. Only a time `groupBy` on a stacked or grouped bar chart, or a scatter or bubble chart's point or group field, is read from `name.granularity` (Cube returns both).
105
+ - Tables are controlled: pass `state`/`setState` from `useState`, then slice and sort your data from `state.page`, `state.pageSize`, `state.sort`.
106
+ - `TableScrollable` (default `heightMode: 'fixed'`) accumulates pages as the user scrolls: serve pages of `TABLE_SCROLLABLE_SIZE` rows (fewer means no more data), and change `resetKey` whenever the query behind the rows changes so it resets to the first page. With `heightMode: 'auto'` the card grows to fit: pass every row at once (up to your own cap) with `results.total`, and the table says when rows were left out.
107
+
108
+ ## Licence
109
+
110
+ MIT, like the upstream remarkable-pro and remarkable-ui repositories it is built from (`LICENSE`, copyright Embeddable.com).
111
+
112
+ ## Todo
113
+
114
+ - [ ] **Publish as EmKit, last.** Name decided 2026-11-17: **EmKit**, npm package `em-kit` (free on npm that day), docs at **emkit.embeddable.com**. Build everything first; packaging and publishing come at the end.
115
+ - [ ] **Localise percentages everywhere** (low impact, later). Six places format percentages by hand (`toFixed` + `%`), so German shows `12.5%` instead of `12,5 %`: remarkable-ui `KpiChartChange.tsx` (PR [remarkable-ui#445](https://github.com/embeddable-hq/remarkable-ui/pull/445) adds `percentageFormatter`), `PivotTable.utils.ts`, `funnel.utils.ts`; remarkable-pro `charts.utils.ts` (pie/donut labels as %), `LineChartComparisonWithKpiTabsPro.utils.tsx`, `FunnelChartPro.utils.ts`. Fix: one `themeFormatter.percent(value, decimals)` in remarkable-pro (Intl, theme locale), used directly in the three Pro spots and passed as `percentageFormatter` to the three ui ones. ~half a day.
116
+
117
+ ## Open findings
118
+
119
+ Resolved: the `embeddable` sessionStorage key (rewritten to `emkit` at sync), the `__embeddableVariableMeta` payload field (dead code, removed with `Value`), the `TableScrollable` dataset prop (wrapped with `resetKey`), the `Pro` suffix (dropped from the public API), missing tests (smoke suite in `tests/`), and the gallery gap (every exported component now has a gallery entry).
120
+
121
+ 1. No library build or publish step yet (tsup/Vite library mode + CSS modules + SVG assets).
122
+ 2. CSS tokens are page-global. `theme.styles` goes on `:root`, so nested providers can't use different styles. JS theme settings (`theme.charts` options, colour maps, i18n) do scope correctly to a nested provider, which is how the hero dashboard gets its own palette. This is by design upstream; use one set of CSS tokens per page.
123
+ 3. Percentages aren't localised. The KPI change shows `+7.4%` in German, which should be `+7,4%`.
124
+ 4. `hideMenu` hides the whole card header, title included, not just the menu. By design upstream; `ChartFromSpec`'s `chrome="plain"` keeps the title and drops only the menu.
125
+ 5. The granularity picker needs `inputs.showGranularityDropdown: true` on the time dimension, an Embeddable builder input that isn't obvious from the props.
126
+ 6. UI language (`theme.i18n.language`) and number/date locale (`theme.formatter.locale`) are set separately. That's flexible, but the provider should probably offer a single `locale` shortcut.
127
+ 7. `TableScrollable` shows the first page twice in dev under React StrictMode: the append effect in the generated component (`src/generated/.../TableScrollable/index.tsx`, the `[rows]` effect) re-runs on StrictMode's double mount after `firstLoadPending` has already flipped, so the mount page is appended again. Production builds are unaffected. Fix upstream (guard with a last-processed-rows ref) and resync.
128
+ 8. `src/i18n/fr.ts` (French) is hand-written in this repo, not synced. Keep its keys in step with the upstream `en`/`de` bundles, or better, contribute it upstream.
129
+ 9. Y-axis labels clip their first character when a locale widens numbers (French `$7 000` shows as `7 000`).