diff --git a/.changeset/config.json b/.changeset/config.json index fcfcf83e0..a1571f742 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -2,7 +2,7 @@ "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", "changelog": "@changesets/cli/changelog", "commit": false, - "fixed": [], + "fixed": [["@javaabu/onu", "@javaabu/onu-mcp"]], "linked": [], "access": "public", "baseBranch": "main", diff --git a/.changeset/drop-unused-peers.md b/.changeset/drop-unused-peers.md new file mode 100644 index 000000000..dd1573a71 --- /dev/null +++ b/.changeset/drop-unused-peers.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +Removed four optional peers nothing imports: `@tiptap/extension-link`, `@tiptap/extension-drag-handle-react`, `@tiptap/extension-code-block-lowlight` and `lowlight`. diff --git a/.changeset/peer-form-and-query.md b/.changeset/peer-form-and-query.md new file mode 100644 index 000000000..e44f976d4 --- /dev/null +++ b/.changeset/peer-form-and-query.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": minor +--- + +`react-hook-form` and `@tanstack/react-query` are now peer dependencies. `getOnuQueryClient` is gone: the fallback client belongs to each `OnuProvider`, and `invalidateApiOptions` takes the client first. diff --git a/.changeset/react-19-only.md b/.changeset/react-19-only.md new file mode 100644 index 000000000..26b0686b2 --- /dev/null +++ b/.changeset/react-19-only.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": minor +--- + +Onu now requires React 19; React 18 is no longer in the peer range. diff --git a/.changeset/remove-base-ui-combobox.md b/.changeset/remove-base-ui-combobox.md new file mode 100644 index 000000000..d3b40b2b4 --- /dev/null +++ b/.changeset/remove-base-ui-combobox.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": minor +--- + +Removed the unused `Combobox` primitive from `@javaabu/onu/primitives`, and with it the `@base-ui/react` dependency. diff --git a/.changeset/thaana-fonts-always.md b/.changeset/thaana-fonts-always.md new file mode 100644 index 000000000..134cc89d2 --- /dev/null +++ b/.changeset/thaana-fonts-always.md @@ -0,0 +1,5 @@ +--- +"@javaabu/onu": patch +--- + +Faruma and MV Faseyha now load from `tailwind.css` and `styles.css`, so Thaana text works without the optional font pack. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 202f2020e..5041de7ec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,6 +41,7 @@ jobs: exit 1 fi done + node scripts/sync-plugin-version.mjs --check - name: Check the npm token run: | if [ -z "$NPM_TOKEN" ]; then diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f6c04d146..605850660 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,10 +85,10 @@ Every change that affects a published package adds a changeset (`pnpm changeset` To release: -1. On `dev`, run `pnpm changeset version`. It bumps every package with pending changesets, writes their `CHANGELOG.md` and deletes the changesets. All packages share one version, so check that `packages/onu` and `packages/onu-mcp` match. +1. On `dev`, run `pnpm changeset version && node scripts/sync-plugin-version.mjs`. `@javaabu/onu` and `@javaabu/onu-mcp` are a fixed group in `.changeset/config.json`, so they always move to the same version; the script copies that version into `plugins/onu/.claude-plugin/plugin.json`, which changesets can't see. `changeset version` also writes their `CHANGELOG.md` and deletes the changesets. 2. Commit (`Release v0.1.0`) and merge `dev` into `main`. Wait for CI to pass on `main`. 3. Tag that commit on `main` and push the tag: `git tag v0.1.0 && git push origin v0.1.0`. -The **Release** workflow runs only for `v*` tags. It checks that the tagged commit is on `main` and that every package's version matches the tag, then builds and publishes to npm (versions already on npm are skipped). Tags with a pre-release suffix (`v1.0.0-beta.1`) publish under the `next` dist-tag. +The **Release** workflow runs only for `v*` tags. It checks that the tagged commit is on `main` and that every package's version and the plugin's match the tag, then builds and publishes to npm (versions already on npm are skipped). Tags with a pre-release suffix (`v1.0.0-beta.1`) publish under the `next` dist-tag. Publishing needs an `NPM_TOKEN` repository secret: an npm granular access token with read and write access to the `@javaabu` scope and "bypass 2FA" allowed, from an account that can publish to `@javaabu`. Write tokens expire after about 90 days. Provenance is signed only once the repository is public. After the first release, you can switch to npm trusted publishing (each package's settings on npmjs.com, pointing at `release.yml`) and remove the token. diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 5a2362888..098c3c852 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -9,7 +9,6 @@ Selection order: shadcn/ui component → reputable library (shadcn ecosystem fir | Package | Purpose | Licence | Notes | | -------------------------------------------------- | -------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------ | | `radix-ui` | Accessible primitives behind the shadcn components | MIT | shadcn default base | -| `@base-ui/react` | Combobox primitive (shadcn's combobox) | MIT | From the Radix / MUI team | | `class-variance-authority` | Variants (`buttonVariants`, …) | Apache-2.0 | Stable and feature-complete; last release 2024 (exception to the 12-month rule, used by shadcn) | | `clsx`, `tailwind-merge` | `cn()` class merging so consumer classes win | MIT | | | `tw-animate-css` | Enter/exit animations | MIT | shadcn default | @@ -19,25 +18,27 @@ Selection order: shadcn/ui component → reputable library (shadcn ecosystem fir | `vaul` | Drawer / bottom sheet | MIT | shadcn `drawer`. **Watch-list**: reduced maintenance (R4.3); kept behind Onu's API | | `input-otp` | OTP input | MIT | shadcn `input-otp` | | `react-day-picker`, `date-fns` | Calendar and date maths | MIT | shadcn `calendar`; Dhivehi locale maintained in Onu | -| `@internationalized/date` | Hijri (Umm al-Qura) calendar maths, date/time fields | Apache-2.0 | Adobe | -| `react-aria-components` | Tree, colour picker, date/time segment fields | Apache-2.0 | Adobe; fills Radix gaps (§4 step 3) | +| `@internationalized/date` | Hijri (Umm al-Qura) calendar maths, date/time segment fields | Apache-2.0 | Adobe | +| `react-aria-components` | Tree, colour picker | Apache-2.0 | Adobe; fills Radix gaps (§4 step 3) | | `embla-carousel-react` | Carousel | MIT | shadcn `carousel` | -| `react-hook-form` | Form state | MIT | | | `@tanstack/react-table`, `@tanstack/react-virtual` | Tables, data grid, virtualised lists | MIT | | -| `@tanstack/react-query` | API select caching and de-duplication | MIT | R16.5 | | `@dnd-kit/react`, `@dnd-kit/helpers` | Drag and drop (kanban, sortable lists, row reordering) with touch sensors | MIT | The maintained successor of `@dnd-kit/core` | | `@dnd-kit/dom` | dnd-kit's `Accessibility` plugin, configured with translated announcements | MIT | Already installed by `@dnd-kit/react`; imported directly so drag announcements follow the locale | | `react-phone-number-input` | Phone input (libphonenumber) | MIT | Default region MV | | `@sindresorhus/slugify` | Slug generator | MIT | | | `uqr` | QR code encoding for `QrCode` (media entry); Onu renders the SVG | MIT | unjs; zero-dep, typed. Picked over `qrcode` (Node deps), `qrcode-generator` (stale) | +## Peers (core) + +`react-hook-form` (form state, MIT) and `@tanstack/react-query` (API select caching and de-duplication, R16.5, MIT) are required peers, alongside `react` and `react-dom`. Onu reads their React context, so the app and Onu must resolve the same copy. They stay required because the core entry imports them statically. + ## Optional peers (entry points) | Entry | Packages | Licence | | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- | | `@javaabu/onu/charts` | `recharts` | MIT | | `@javaabu/onu/maps` | `@vis.gl/react-google-maps`, `terra-draw`, `terra-draw-google-maps-adapter`, `@googlemaps/markerclusterer`, `@deck.gl/core`, `@deck.gl/layers`, `@deck.gl/aggregation-layers`, `@deck.gl/google-maps`, `@turf/turf` | MIT / Apache-2.0 | -| `@javaabu/onu/editor` | `@tiptap/core`, `@tiptap/react`, `@tiptap/pm`, `@tiptap/starter-kit`, `@tiptap/static-renderer`, `@tiptap/suggestion` (slash menu), `@tiptap/extension-*` (MIT packages only), `lowlight`, `shiki` | MIT | +| `@javaabu/onu/editor` | `@tiptap/core`, `@tiptap/react`, `@tiptap/pm`, `@tiptap/starter-kit`, `@tiptap/static-renderer`, `@tiptap/suggestion` (slash menu), `@tiptap/extension-*` (MIT packages only), `shiki` | MIT | | `@javaabu/onu/calendar` | `@fullcalendar/core`, `@fullcalendar/react`, `@fullcalendar/daygrid`, `@fullcalendar/timegrid`, `@fullcalendar/list`, `@fullcalendar/interaction` (standard plugins only, v6) | MIT | | `@javaabu/onu/media` | `react-easy-crop`, `signature_pad`, `barcode-detector`, `yet-another-react-lightbox`, `media-chrome` | MIT | | `@javaabu/onu/export` | `write-excel-file` (Excel `.xlsx` only; CSV and PDF need nothing). Loaded with `import()` on the first Excel export. Chosen over the npm `xlsx` (SheetJS) package, whose npm release is outdated; supports right-to-left sheets and keeps Thaana text intact | MIT | diff --git a/README.md b/README.md index 10a9fbe8a..fae963795 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ See [`REQUIREMENTS.md`](REQUIREMENTS.md) for the full specification and [`docs/` ## Install ```bash -npm install @javaabu/onu -# optional font pack (Inter, JetBrains Mono, Noto Sans Thaana; Faruma and MV Faseyha are bundled) +npm install @javaabu/onu react-hook-form @tanstack/react-query +# optional font pack (Inter, JetBrains Mono, Noto Sans Thaana; Faruma and MV Faseyha come with tailwind.css and styles.css) npm install @fontsource-variable/inter @fontsource-variable/jetbrains-mono @fontsource-variable/noto-sans-thaana ``` diff --git a/REQUIREMENTS.md b/REQUIREMENTS.md index dee9bb8db..d8d75c590 100644 --- a/REQUIREMENTS.md +++ b/REQUIREMENTS.md @@ -86,7 +86,7 @@ This document captures the requirements, constraints and full build list for Onu - `@javaabu/onu/styles.css` — theme tokens + base styles - `@javaabu/onu/tailwind.css` — Tailwind `@theme` / `@source` entry for consumers - **R2.6** Heavy or licensed third-party dependencies (map SDKs, chart libs, editors, scanners, FontAwesome, fonts) are **optional peer dependencies**, required only when the matching subpath is imported. -- **R2.7** Peer dependencies: `react` and `react-dom` `^18.3 || ^19`, `tailwindcss` `^4`. +- **R2.7** Peer dependencies: `react` and `react-dom` `^19`, `tailwindcss` `^4`. - **R2.8** Ship TypeScript declarations; source written in TypeScript `strict` mode. No `any` in public APIs. - **R2.9** Every client component file carries a `"use client"` directive so it works in React Server Component environments (Next.js App Router). - **R2.10** Semantic versioning. Releases managed with [Changesets](https://github.com/changesets/changesets); `CHANGELOG.md` generated from them. @@ -181,7 +181,7 @@ A dependency must meet **all** of these criteria: - **Maintained**: a release or meaningful commit within the last 12 months, a responsive issue tracker, and not archived or deprecated. - **Reputable**: widely adopted, and backed by an organisation or established maintainers. - **Typed**: first-party TypeScript types. -- **Compatible**: React 18 and 19, SSR-safe, tree-shakable. +- **Compatible**: React 19, SSR-safe, tree-shakable. - **Accessible and RTL-capable**, or can be made so by wrapping. - **Reasonable bundle size** for what it provides. diff --git a/docs/choice-inputs/api-select.md b/docs/choice-inputs/api-select.md index 860304b4d..ce8f32e61 100644 --- a/docs/choice-inputs/api-select.md +++ b/docs/choice-inputs/api-select.md @@ -35,7 +35,7 @@ import { ApiSelect } from '@javaabu/onu'; - **Paging**: when the response says there is a next page (`meta.last_page`, `last_page`, `next_page_url`, `links.next`, `next_cursor`), the next page loads as the list scrolls to the end. - **Preloading**: options load when the list opens, or immediately with `preload`. - **States**: loading, empty ("No results for …"), and an error with a **Retry** button. All are announced in a polite live region. -- **Caching**: per endpoint + params + query, for `staleTime` (5 minutes). After creating a record elsewhere, call `invalidateApiOptions(url)` (or `queryClient.invalidateQueries({ queryKey: apiOptionsQueryKey(url) })` with your own client). Quick-create (`onCreate`) invalidates automatically. +- **Caching**: per endpoint + params + query, for `staleTime` (5 minutes). After creating a record elsewhere, call `invalidateApiOptions(client, url)` with the client from `useOnuQueryClient()` (or `queryClient.invalidateQueries({ queryKey: apiOptionsQueryKey(url) })` with your own). Quick-create (`onCreate`) invalidates automatically. - **No requests without a URL or fetcher** you supply; CSRF and auth headers are yours to add (`headers`, `credentials`). ## Props @@ -70,7 +70,7 @@ Values are strings (`id: 12` becomes `"12"`), so they round-trip through forms u ## Data layer -The helpers behind it are exported for Autocomplete and your own components: `fetchApiOptions`, `parseApiResponse`, `parseApiItem`, `mapApiItem`, `detectHasMore`, `buildUrl`, `requestJson`, `useOnuQueryClient`, `getOnuQueryClient`, `invalidateApiOptions`, `apiOptionsQueryKey`. +The helpers behind it are exported for Autocomplete and your own components: `fetchApiOptions`, `parseApiResponse`, `parseApiItem`, `mapApiItem`, `detectHasMore`, `buildUrl`, `requestJson`, `useOnuQueryClient`, `invalidateApiOptions`, `apiOptionsQueryKey`. ## Accessibility diff --git a/docs/guides/dhivehi-and-locales.md b/docs/guides/dhivehi-and-locales.md index b7f38287e..696e5743a 100644 --- a/docs/guides/dhivehi-and-locales.md +++ b/docs/guides/dhivehi-and-locales.md @@ -101,4 +101,4 @@ Charts have their own `useChartFormat` in `@javaabu/onu/charts`, with axis and p # Fonts -Dhivehi text uses Faruma, with MV Faseyha for headings and bold, both bundled with `fonts.css`. See [Fonts](./fonts). +Dhivehi text uses Faruma, with MV Faseyha for headings and bold, both loaded by `tailwind.css`. See [Fonts](./fonts). diff --git a/docs/guides/fonts.md b/docs/guides/fonts.md index d9b07b20e..0e7ee4bb1 100644 --- a/docs/guides/fonts.md +++ b/docs/guides/fonts.md @@ -29,13 +29,11 @@ All of these are self-hosted from npm, so no requests go to a font CDN. # Thaana fonts -Onu ships Faruma and MV Faseyha with `fonts.css`, as `woff2` files subset to Thaana and its punctuation (about 12 kB each). Their `unicode-range` means a browser only downloads them when a page shows Thaana text, and Latin text in a mixed sentence stays in Inter. +`tailwind.css` and `styles.css` load Faruma and MV Faseyha, so they work without `fonts.css` and its packages. They ship as `woff2` files subset to Thaana and its punctuation (about 12 kB each). Their `unicode-range` means a browser only downloads them when a page shows Thaana text, and Latin text in a mixed sentence stays in Inter. - **Faruma** is used for Dhivehi body text (`--onu-font-thaana`). - **MV Faseyha** is used for Dhivehi headings and ``/`` (`--onu-font-thaana-bold`). Both fonts have a single weight and Onu turns off faux bold for Dhivehi, so emphasis uses the second face instead. -- Characters neither font covers fall back to Noto Sans Thaana. - -If you don't import `fonts.css`, the same names still apply to copies installed on the device. +- Characters neither font covers fall back to Noto Sans Thaana when you import `fonts.css`. # Mixed Dhivehi and English diff --git a/docs/guides/inertia-and-nextjs.md b/docs/guides/inertia-and-nextjs.md index e587ff4a4..c92ec006b 100644 --- a/docs/guides/inertia-and-nextjs.md +++ b/docs/guides/inertia-and-nextjs.md @@ -3,7 +3,7 @@ title: Inertia & Next.js sidebar_position: 13 --- -Onu is plain React, so it works in Vite apps, Laravel + Inertia (React) and Next.js. +Onu is plain React (React 19), so it works in Vite apps, Laravel + Inertia (React) and Next.js. # Links diff --git a/docs/installation-and-setup.md b/docs/installation-and-setup.md index bf6c52a9a..7ab316eea 100644 --- a/docs/installation-and-setup.md +++ b/docs/installation-and-setup.md @@ -5,10 +5,10 @@ sidebar_position: 1.2 # Installation -First install the NPM package +Onu needs React 19. First install the NPM package ```bash -npm install @javaabu/onu --save +npm install @javaabu/onu react-hook-form @tanstack/react-query --save ``` # Styles @@ -25,7 +25,7 @@ npm install @fontsource-variable/inter @fontsource-variable/jetbrains-mono @font @import "@javaabu/onu/fonts.css"; /* optional: needs the font packages above */ ``` -Without the font pack, leave out the last line. Faruma and MV Faseyha (Thaana) are inside `@javaabu/onu`; see [Fonts](./guides/fonts). +Without the font pack, leave out the last line. `tailwind.css` already loads Faruma and MV Faseyha (Thaana); see [Fonts](./guides/fonts). `tailwind.css` adds Onu's design tokens, the dark mode variant, and tells Tailwind to scan Onu's components for classes. diff --git a/docs/requirements.md b/docs/requirements.md index 3c03366d3..6307e2c3a 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -5,8 +5,9 @@ sidebar_position: 1.1 This package requires: -- [React](https://react.dev) 18.3+ or 19 +- [React](https://react.dev) 19 - [Tailwind CSS](https://tailwindcss.com) 4 +- [React Hook Form](https://react-hook-form.com) 7 and [TanStack Query](https://tanstack.com/query) 5, which share React context with your app Onu supports every browser Tailwind CSS 4 supports: Chrome and Edge 111+, Safari 16.4+, Firefox 128+, and their mobile versions. diff --git a/packages/onu/README.md b/packages/onu/README.md index 908171131..d5a265037 100644 --- a/packages/onu/README.md +++ b/packages/onu/README.md @@ -16,8 +16,8 @@ Every component and the sample pages: [onu.on-forge.com](https://onu.on-forge.co ## Install ```bash -npm install @javaabu/onu -# optional font pack (Inter, JetBrains Mono, Noto Sans Thaana; Faruma and MV Faseyha are bundled) +npm install @javaabu/onu react-hook-form @tanstack/react-query +# optional font pack (Inter, JetBrains Mono, Noto Sans Thaana; Faruma and MV Faseyha come with tailwind.css and styles.css) npm install @fontsource-variable/inter @fontsource-variable/jetbrains-mono @fontsource-variable/noto-sans-thaana ``` diff --git a/packages/onu/package.json b/packages/onu/package.json index 64884fc44..abcbaf5bc 100644 --- a/packages/onu/package.json +++ b/packages/onu/package.json @@ -124,11 +124,9 @@ "@fullcalendar/timegrid": "^6.1.21", "@googlemaps/markerclusterer": "^2.6.2", "@iconify/react": "^6.0.2", + "@tanstack/react-query": "^5.104.1", "@tiptap/core": "^3.31.4", - "@tiptap/extension-code-block-lowlight": "^3.31.4", - "@tiptap/extension-drag-handle-react": "^3.31.4", "@tiptap/extension-image": "^3.31.4", - "@tiptap/extension-link": "^3.31.4", "@tiptap/extension-placeholder": "^3.31.4", "@tiptap/extension-table": "^3.31.4", "@tiptap/extension-text-align": "^3.31.4", @@ -140,11 +138,11 @@ "@turf/turf": "^7.4.0", "@vis.gl/react-google-maps": "^1.10.1", "barcode-detector": "^3.2.2", - "lowlight": "^3.3.0", "media-chrome": "^4.19.3", - "react": "^18.3.0 || ^19.0.0", - "react-dom": "^18.3.0 || ^19.0.0", + "react": "^19.0.0", + "react-dom": "^19.0.0", "react-easy-crop": "^6.2.4", + "react-hook-form": "^7.89.0", "recharts": "^3.10.1", "shiki": "^4.5.0", "signature_pad": "^5.1.4", @@ -180,14 +178,12 @@ "@iconify/react": "^6.0.2", "@size-limit/preset-small-lib": "^14.1.0", "@tailwindcss/vite": "^4.3.3", + "@tanstack/react-query": "^5.104.1", "@testing-library/jest-dom": "^7.0.1", "@testing-library/react": "^16.3.3", "@testing-library/user-event": "^14.6.7", "@tiptap/core": "^3.31.4", - "@tiptap/extension-code-block-lowlight": "^3.31.4", - "@tiptap/extension-drag-handle-react": "^3.31.4", "@tiptap/extension-image": "^3.31.4", - "@tiptap/extension-link": "^3.31.4", "@tiptap/extension-placeholder": "^3.31.4", "@tiptap/extension-table": "^3.31.4", "@tiptap/extension-text-align": "^3.31.4", @@ -207,13 +203,13 @@ "axe-core": "^4.14.0", "barcode-detector": "^3.2.2", "jsdom": "^30.1.2", - "lowlight": "^3.3.0", "media-chrome": "^4.19.3", "react": "^19.3.0", "react-dom": "^19.3.0", "react-easy-crop": "^6.2.4", + "react-hook-form": "^7.89.0", "recharts": "^3.10.1", - "shadcn": "^4.21.4", + "shadcn": "^4.23.0", "shiki": "^4.5.0", "signature_pad": "^5.1.4", "size-limit": "^14.1.0", @@ -228,13 +224,11 @@ "yet-another-react-lightbox": "^3.32.2" }, "dependencies": { - "@base-ui/react": "^1.8.0", "@dnd-kit/dom": "^0.5.0", "@dnd-kit/helpers": "^0.5.0", "@dnd-kit/react": "^0.5.0", "@internationalized/date": "^3.12.4", "@sindresorhus/slugify": "^3.0.1", - "@tanstack/react-query": "^5.104.1", "@tanstack/react-table": "^9.2.6", "@tanstack/react-virtual": "^3.14.13", "class-variance-authority": "^0.7.1", @@ -247,7 +241,6 @@ "radix-ui": "^1.7.0", "react-aria-components": "^1.21.1", "react-day-picker": "^10.0.2", - "react-hook-form": "^7.89.0", "react-phone-number-input": "^3.4.18", "sonner": "^2.0.8", "tailwind-merge": "^3.7.0", @@ -280,27 +273,15 @@ "@tiptap/extension-text-align": { "optional": true }, - "@tiptap/extension-link": { - "optional": true - }, "@tiptap/extension-image": { "optional": true }, "@tiptap/extension-table": { "optional": true }, - "@tiptap/extension-drag-handle-react": { - "optional": true - }, "@tiptap/core": { "optional": true }, - "@tiptap/extension-code-block-lowlight": { - "optional": true - }, - "lowlight": { - "optional": true - }, "shiki": { "optional": true }, @@ -451,7 +432,7 @@ "name": "primitives", "path": "dist/ui/index.js", "import": "*", - "limit": "165 kB" + "limit": "130 kB" }, { "name": "thaana", @@ -518,6 +499,7 @@ "path": [ "src/styles/styles.css", "src/styles/tokens.css", + "src/styles/fonts-thaana.css", "src/styles/theme.css" ], "rolldown": false, @@ -529,17 +511,24 @@ "src/styles/tailwind.css", "src/styles/shadcn.css", "src/styles/tokens.css", + "src/styles/fonts-thaana.css", "src/styles/theme.css", "src/styles/base.css" ], "rolldown": false, "limit": "8.5 kB" }, + { + "name": "fonts-thaana.css", + "path": "src/styles/fonts-thaana.css", + "rolldown": false, + "limit": "400 B" + }, { "name": "fonts.css", "path": "src/styles/fonts.css", "rolldown": false, - "limit": "600 B" + "limit": "400 B" }, { "name": "fonts-optional.css", diff --git a/packages/onu/src/components/choice/api-options.ts b/packages/onu/src/components/choice/api-options.ts index e7fe0bcfd..7225b9191 100644 --- a/packages/onu/src/components/choice/api-options.ts +++ b/packages/onu/src/components/choice/api-options.ts @@ -3,6 +3,7 @@ import * as React from "react" import { QueryClient, QueryClientContext } from "@tanstack/react-query" +import { useOnu } from "../../providers/onu-provider" import type { ChoiceOption } from "./options" /* @@ -245,27 +246,28 @@ export function apiOptionsQueryKey(url?: string) { return url ? (["onu-api-options", url] as const) : (["onu-api-options"] as const) } -let fallbackClient: QueryClient | undefined +function fallbackClient(store: { client?: QueryClient }) { + store.client ??= new QueryClient({ defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } } }) + return store.client +} /** - * Onu's own QueryClient, used when the app has no `QueryClientProvider`, so API - * selects work out of the box. Apps with a provider share their client instead. + * The app's QueryClient if there is a `QueryClientProvider`, else one owned by the + * nearest `OnuProvider` (or this component, without one), so API selects work out of + * the box and a server never shares a cache between requests. */ -export function getOnuQueryClient() { - fallbackClient ??= new QueryClient({ defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } } }) - return fallbackClient -} - -/** The app's QueryClient if there is a provider, else Onu's fallback client. */ export function useOnuQueryClient(explicit?: QueryClient) { const context = React.useContext(QueryClientContext) - return explicit ?? context ?? getOnuQueryClient() + const [own] = React.useState<{ client?: QueryClient }>({}) + const store = useOnu().queryClientStore ?? own + return explicit ?? context ?? fallbackClient(store) } /** * Clears cached API options (e.g. after creating a record elsewhere) so open - * selects refetch. Pass a URL to limit it to one endpoint. + * selects refetch. Pass a URL to limit it to one endpoint; `useOnuQueryClient()` + * returns the client `ApiSelect` uses. */ -export function invalidateApiOptions(url?: string, client: QueryClient = getOnuQueryClient()) { +export function invalidateApiOptions(client: QueryClient, url?: string) { return client.invalidateQueries({ queryKey: apiOptionsQueryKey(url) }) } diff --git a/packages/onu/src/components/choice/api-select.test.tsx b/packages/onu/src/components/choice/api-select.test.tsx index 2c41ac599..510ee50d6 100644 --- a/packages/onu/src/components/choice/api-select.test.tsx +++ b/packages/onu/src/components/choice/api-select.test.tsx @@ -9,8 +9,8 @@ import { FormField } from "../form/form-field" import { buildUrl, detectHasMore, - getOnuQueryClient, invalidateApiOptions, + useOnuQueryClient, parseApiItem, parseApiResponse, valueUrlFor, @@ -335,13 +335,34 @@ describe("ApiSelect", () => { expect(fetchMock).toHaveBeenCalledTimes(1) }) + it("gives each OnuProvider its own fallback client, and invalidates it", async () => { + const clients: QueryClient[] = [] + function Capture({ children }: { children?: React.ReactNode }) { + const client = useOnuQueryClient() + React.useEffect(() => void clients.push(client), [client]) + return children + } + renderWithOnu() + mockFetch(() => ({ data: islands })) + renderWithOnu( + + + , + ) + expect(clients).toHaveLength(2) + expect(clients[0]).not.toBe(clients[1]) + + await open() + expect(await screen.findByRole("option", { name: "Malé" })).toBeInTheDocument() + expect(clients[1]?.getQueryCache().getAll().length).toBeGreaterThan(0) + await invalidateApiOptions(clients[1]!, "/api/fallback-own") + }) + it("works without a QueryClientProvider (fallback client) and with one", async () => { mockFetch(() => ({ data: islands })) const { unmount } = renderWithOnu() await open() expect(await screen.findByRole("option", { name: "Malé" })).toBeInTheDocument() - expect(getOnuQueryClient().getQueryCache().getAll().length).toBeGreaterThan(0) - await invalidateApiOptions("/api/fallback") unmount() const appClient = newClient() diff --git a/packages/onu/src/providers/onu-provider.tsx b/packages/onu/src/providers/onu-provider.tsx index 4fec5580d..3dd521e56 100644 --- a/packages/onu/src/providers/onu-provider.tsx +++ b/packages/onu/src/providers/onu-provider.tsx @@ -1,5 +1,6 @@ "use client" +import type { QueryClient } from "@tanstack/react-query" import * as React from "react" import { Direction } from "radix-ui" @@ -34,6 +35,8 @@ export interface OnuContextValue { labelLayout: LabelLayout linkComponent: LinkComponent maps: MapsConfig + /** Holds this provider's fallback QueryClient, created on first use by `ApiSelect`. */ + queryClientStore?: { client?: QueryClient } } const fallbackContext: OnuContextValue = { @@ -146,6 +149,7 @@ export function OnuProvider({ [base, messages], ) const dir = dirProp ?? locale.dir + const [queryClientStore] = React.useState<{ client?: QueryClient }>({}) const value = React.useMemo( () => ({ @@ -156,8 +160,9 @@ export function OnuProvider({ labelLayout, linkComponent, maps: maps ?? {}, + queryClientStore, }), - [locale, dir, density, labelLayout, linkComponent, maps], + [locale, dir, density, labelLayout, linkComponent, maps, queryClientStore], ) React.useEffect(() => { diff --git a/packages/onu/src/styles/base.css b/packages/onu/src/styles/base.css index a4fb3e81f..29fcc661c 100644 --- a/packages/onu/src/styles/base.css +++ b/packages/onu/src/styles/base.css @@ -54,7 +54,6 @@ body { [data-slot="tabs-trigger"], [data-slot="input"], [data-slot="input-group"], - [data-slot="combobox-trigger"], [data-slot="pagination-link"], [data-slot="dropdown-menu-item"], [data-slot="command-item"], diff --git a/packages/onu/src/styles/fonts-thaana.css b/packages/onu/src/styles/fonts-thaana.css new file mode 100644 index 000000000..6db0a9990 --- /dev/null +++ b/packages/onu/src/styles/fonts-thaana.css @@ -0,0 +1,23 @@ +/* + * Thaana fonts (R7.3), bundled with Onu: Faruma for Dhivehi body text and + * MV Faseyha for Dhivehi headings and bold text (`--onu-font-thaana-bold`). + * Subset to Thaana and its punctuation; `unicode-range` keeps Latin text in + * Inter, and browsers only download a file when a page shows Thaana text. + */ +@font-face { + font-family: "Faruma"; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url("./fonts/faruma.woff2") format("woff2"); + unicode-range: U+0780-07BF, U+FDF2, U+060C, U+061B, U+061F, U+25CC; +} + +@font-face { + font-family: "MV Faseyha"; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url("./fonts/mv-faseyha.woff2") format("woff2"); + unicode-range: U+0780-07BF, U+FDF2, U+060C, U+061B, U+061F, U+25CC; +} diff --git a/packages/onu/src/styles/fonts.css b/packages/onu/src/styles/fonts.css index d242bc0c2..4d8f5096e 100644 --- a/packages/onu/src/styles/fonts.css +++ b/packages/onu/src/styles/fonts.css @@ -4,34 +4,12 @@ * * @import "@javaabu/onu/fonts.css"; * - * It loads Inter, JetBrains Mono and Noto Sans Thaana from npm, so install them first: + * It loads Inter, JetBrains Mono and Noto Sans Thaana from npm, so install them first + * (the bundled Thaana fonts come with `tailwind.css` and `styles.css` already): * npm install @fontsource-variable/inter @fontsource-variable/jetbrains-mono @fontsource-variable/noto-sans-thaana */ @import "@fontsource-variable/inter"; @import "@fontsource-variable/jetbrains-mono"; /* Fallback Thaana face for code points the bundled fonts don't cover (R7.3). */ @import "@fontsource-variable/noto-sans-thaana"; - -/* - * Thaana fonts (R7.3), bundled with Onu: Faruma for Dhivehi body text and - * MV Faseyha for Dhivehi headings and bold text (`--onu-font-thaana-bold`). - * Subset to Thaana and its punctuation; `unicode-range` keeps Latin text in - * Inter, and browsers only download a file when a page shows Thaana text. - */ -@font-face { - font-family: "Faruma"; - font-style: normal; - font-weight: 400; - font-display: swap; - src: url("./fonts/faruma.woff2") format("woff2"); - unicode-range: U+0780-07BF, U+FDF2, U+060C, U+061B, U+061F, U+25CC; -} - -@font-face { - font-family: "MV Faseyha"; - font-style: normal; - font-weight: 400; - font-display: swap; - src: url("./fonts/mv-faseyha.woff2") format("woff2"); - unicode-range: U+0780-07BF, U+FDF2, U+060C, U+061B, U+061F, U+25CC; -} +@import "./fonts-thaana.css"; diff --git a/packages/onu/src/styles/styles.css b/packages/onu/src/styles/styles.css index a60997777..4aa3ee852 100644 --- a/packages/onu/src/styles/styles.css +++ b/packages/onu/src/styles/styles.css @@ -3,4 +3,5 @@ * Tailwind projects should import `@javaabu/onu/tailwind.css` instead. */ @import "./tokens.css"; +@import "./fonts-thaana.css"; @import "./theme.css"; diff --git a/packages/onu/src/styles/tailwind.css b/packages/onu/src/styles/tailwind.css index e5c859c82..92054037d 100644 --- a/packages/onu/src/styles/tailwind.css +++ b/packages/onu/src/styles/tailwind.css @@ -7,6 +7,7 @@ @import "tw-animate-css"; @import "./shadcn.css"; @import "./tokens.css"; +@import "./fonts-thaana.css"; @import "./theme.css"; @import "./base.css" layer(base); diff --git a/packages/onu/src/ui/combobox.tsx b/packages/onu/src/ui/combobox.tsx deleted file mode 100644 index 2408b90a5..000000000 --- a/packages/onu/src/ui/combobox.tsx +++ /dev/null @@ -1,305 +0,0 @@ -"use client" - -// Vendored from shadcn/ui (radix base, nova style, RTL) by scripts/sync-shadcn.mjs. -// Onu changes are marked with "onu:" comments; keep them when re-syncing. -// onu: Ant popups: 8px corners (rounded-xl), a colorBorderSecondary hairline (ring-border) and the subtle popup shadow (shadow-popup). -// onu: Ant menu items: 32px tall, 12px padding, 4px corners (rounded-sm). - -import * as React from "react" -import { Combobox as ComboboxPrimitive } from "@base-ui/react" -import { cn } from "../lib/utils" - -import { Button } from "./button" -import { - InputGroup, - InputGroupAddon, - InputGroupButton, - InputGroupInput, -} from "./input-group" -// onu: fixed glyphs passed as Icon fallbacks, so primitives work without OnuProvider and the full icon map. -import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react" -import { Icon } from "../icons/icon" - -const Combobox = ComboboxPrimitive.Root - -function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) { - return -} - -function ComboboxTrigger({ - className, - children, - ...props -}: ComboboxPrimitive.Trigger.Props) { - return ( - - {children} - - - ) -} - -function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) { - return ( - } - className={cn(className)} - {...props} - > - - - ) -} - -function ComboboxInput({ - className, - children, - disabled = false, - showTrigger = true, - showClear = false, - ...props -}: ComboboxPrimitive.Input.Props & { - showTrigger?: boolean - showClear?: boolean -}) { - return ( - - } - {...props} - /> - - {showTrigger && ( - - - - )} - {showClear && } - - {children} - - ) -} - -function ComboboxContent({ - className, - side = "bottom", - sideOffset = 6, - align = "start", - alignOffset = 0, - anchor, - ...props -}: ComboboxPrimitive.Popup.Props & - Pick< - ComboboxPrimitive.Positioner.Props, - "side" | "align" | "sideOffset" | "alignOffset" | "anchor" - >) { - return ( - - - - - - ) -} - -function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) { - return ( - - ) -} - -function ComboboxItem({ - className, - children, - ...props -}: ComboboxPrimitive.Item.Props) { - return ( - - {children} - } - > - - - - ) -} - -function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) { - return ( - - ) -} - -function ComboboxLabel({ - className, - ...props -}: ComboboxPrimitive.GroupLabel.Props) { - return ( - - ) -} - -function ComboboxCollection({ ...props }: ComboboxPrimitive.Collection.Props) { - return ( - - ) -} - -function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) { - return ( -