@nxgt/material 2.3.1 → 2.4.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.
Files changed (63) hide show
  1. package/README.md +19 -1
  2. package/dist/{_Uint8Array-BDK6FjpM.js → _Uint8Array-DEXn42kj.js} +1 -1
  3. package/dist/{blockDiagram-BEXU5L5S-C8q-lXgt.js → blockDiagram-BEXU5L5S-CD5PW_mQ.js} +2 -2
  4. package/dist/{chunk-3FUC2YCW-BGpNbruY.js → chunk-3FUC2YCW-CNBUvTSg.js} +2 -2
  5. package/dist/{chunk-7M6MHVWA-_-i4Sb1c.js → chunk-7M6MHVWA-DEh1Crrc.js} +1 -1
  6. package/dist/{chunk-GNY47TPC-BJperC1X.js → chunk-GNY47TPC-vOPvRE_8.js} +4 -4
  7. package/dist/{chunk-NETBCI7D-D0kbMnm0.js → chunk-NETBCI7D-CQV8lo68.js} +1 -1
  8. package/dist/{chunk-Z7XXMR3K-CJmPL4k9.js → chunk-Z7XXMR3K-DcqSgI9Q.js} +1 -1
  9. package/dist/{classDiagram-v2-NBCMYWYE-DRoCWiaP.js → classDiagram-v2-NBCMYWYE-tU42Be-2.js} +2 -2
  10. package/dist/{client-only.utils-qMX_CMiw.js → client-only.utils-DhcBUmau.js} +2 -2
  11. package/dist/{components-CRrswCsD.js → components-NLbPtyeB.js} +20564 -20586
  12. package/dist/components.js +5 -5
  13. package/dist/{dagre-6A5THRUB-B11jdkPL.js → dagre-6A5THRUB-CXwkkHFr.js} +8 -8
  14. package/dist/{diagram-22UHCM2B-CAVrn_uY.js → diagram-22UHCM2B-BswK7SlD.js} +2 -2
  15. package/dist/{diagram-3UASUU5V-uO9-gtWR.js → diagram-3UASUU5V-5p5ra9Yi.js} +1 -1
  16. package/dist/dnd.js +1 -1
  17. package/dist/{elk-276RUBZZ-BALenDhN.js → elk-276RUBZZ-CuGpDp18.js} +3 -3
  18. package/dist/{erDiagram-OPXOYQCR-FtFHGu-P.js → erDiagram-OPXOYQCR-vpNBbFgR.js} +2 -2
  19. package/dist/{field-blur-DkydMwaN.js → field-blur-EUOqpHbF.js} +1 -1
  20. package/dist/{flowDiagram-KWPJA3E3-DZwUgKQu.js → flowDiagram-KWPJA3E3-PC80XOp8.js} +3 -3
  21. package/dist/{ganttDiagram-FUAMR5RP-CmMpH0CG.js → ganttDiagram-FUAMR5RP-DC1sfzgs.js} +1 -1
  22. package/dist/{graphlib-DovxbouT.js → graphlib-DvOFXJbI.js} +5 -5
  23. package/dist/hooks.js +2 -2
  24. package/dist/{i18n-provider-BUQY82bS.js → i18n-provider-XTTU9ArK.js} +1 -1
  25. package/dist/i18n.js +6 -6
  26. package/dist/{isArrayLikeObject-D0u9Q9Yg.js → isArrayLikeObject-CCJDO2RL.js} +2 -2
  27. package/dist/{journeyDiagram-ZHPQQLJL-DVxTOFQu.js → journeyDiagram-ZHPQQLJL-C6djNSgq.js} +1 -1
  28. package/dist/lib/components/ui/media/file-list/index.d.ts +1 -1
  29. package/dist/lib/components/ui/media/upload/network-upload-field/network-upload-field.utils.d.ts +0 -1
  30. package/dist/lib/i18n/resources/fr/material.json.d.ts +1 -1
  31. package/dist/lib/next/index.d.ts +9 -0
  32. package/dist/lib/next/pdfkit-font-globs.d.ts +15 -0
  33. package/dist/lib/next/with-nxgt-print.d.ts +73 -0
  34. package/dist/{lib-B_cBmfz5.js → lib-DIj5dvbb.js} +3 -3
  35. package/dist/lib.js +2 -2
  36. package/dist/main.js +12 -12
  37. package/dist/map.js +2 -2
  38. package/dist/{merge-DQLOWMVN.js → merge-Dm-kHFxo.js} +3 -3
  39. package/dist/{mermaid.core-CQ6lUhgC.js → mermaid.core-CEDjsxgL.js} +21 -21
  40. package/dist/{mindmap-definition-NLK3R4M7-DyB5NgHM.js → mindmap-definition-NLK3R4M7-BYtcw4Io.js} +2 -2
  41. package/dist/next.js +35 -0
  42. package/dist/{pieDiagram-5QR66LMP-DCdDWF2H.js → pieDiagram-5QR66LMP-8ETWucra.js} +1 -1
  43. package/dist/print.js +2 -2
  44. package/dist/{quadrantDiagram-O4NWA36T-BMfcGUfy.js → quadrantDiagram-O4NWA36T-X05JG-jZ.js} +1 -1
  45. package/dist/{requirementDiagram-PLB6GJNP-Bg-uQlZj.js → requirementDiagram-PLB6GJNP-BwWSE7Fn.js} +2 -2
  46. package/dist/{sankeyDiagram-IPEJSGJF-E-o_7bq2.js → sankeyDiagram-IPEJSGJF-B6YxyZMn.js} +1 -1
  47. package/dist/{sortable-provider-NE74zkmo.js → sortable-provider-DuRzFvwe.js} +1 -1
  48. package/dist/{stateDiagram-v2-GCMORJYK-BDB4K1Fw.js → stateDiagram-v2-GCMORJYK-CAqcgA-x.js} +2 -2
  49. package/dist/{stored-language-BVYsloiW.js → stored-language-BP90Ydtg.js} +1 -1
  50. package/dist/{swimlanes-2SLR337P-C406S8ui.js → swimlanes-2SLR337P-DRQ2gho_.js} +3 -3
  51. package/dist/{swimlanesDiagram-TC7HE7FX-BstKZ--K.js → swimlanesDiagram-TC7HE7FX-DaXG362E.js} +3 -3
  52. package/dist/{timeline-definition-EJHVYXUP-BmhxT0qo.js → timeline-definition-EJHVYXUP-BtvpCePa.js} +1 -1
  53. package/dist/{translate-material-CRxs5aS3.js → translate-material-Ctzt0Y2N.js} +2 -2
  54. package/dist/{translator-BfyVF7Ej.js → translator-Cfug7hC5.js} +1 -1
  55. package/dist/{use-heading-spy-BiLosksJ.js → use-heading-spy-DtVo2HBk.js} +2 -2
  56. package/dist/{use-material-translation-D3HwtYDm.js → use-material-translation-CJswHOmK.js} +2 -2
  57. package/dist/{usecaseDiagram-POWQR4AR-cHGV1E_T.js → usecaseDiagram-POWQR4AR-DsYqBvQ-.js} +2 -2
  58. package/dist/{xychartDiagram-PMCCYNJV-ixeD_kO0.js → xychartDiagram-PMCCYNJV-CEf5bvG1.js} +1 -1
  59. package/docs/guides/printing.md +104 -0
  60. package/docs/roadmap.md +6 -0
  61. package/docs/troubleshooting.md +127 -0
  62. package/package.json +7 -2
  63. package/dist/lib/components/ui/media/file-list/format-file-size.d.ts +0 -1
@@ -759,6 +759,12 @@ export async function GET(_request: Request, { params }: { params: Promise<{ id:
759
759
  }
760
760
  ```
761
761
 
762
+ A Next.js route handler also needs its `next.config.ts` wrapped in
763
+ `withNxgtPrint` from `@nxgt/material/next`, which adds
764
+ `serverExternalPackages: ['@nxgt/material']` and, for `output: 'standalone'`,
765
+ a trace of pdfkit's fonts: see
766
+ [Next.js](#nextjs-serverexternalpackages-and-output-standalone).
767
+
762
768
  ```tsx
763
769
  // Hono
764
770
  import { Hono } from 'hono';
@@ -1292,4 +1298,102 @@ Two changes look like fixes and are not:
1292
1298
  cannot resolve it from your app's directory:
1293
1299
  `Cannot find package 'pdfkit'`.
1294
1300
 
1301
+ ### Next.js: `serverExternalPackages` and `output: 'standalone'`
1302
+
1303
+ A route handler that imports `@nxgt/material/print` needs two keys of
1304
+ `next.config.ts`. `withNxgtPrint` from `@nxgt/material/next` (since 2.4.0)
1305
+ adds both:
1306
+
1307
+ ```ts
1308
+ // next.config.ts
1309
+ import { withNxgtPrint } from '@nxgt/material/next';
1310
+
1311
+ export default withNxgtPrint({
1312
+ output: 'standalone',
1313
+ // the rest of your config, as it was
1314
+ });
1315
+ ```
1316
+
1317
+ Checked with Next.js 16.3 against `.next/standalone/server.js` run alone,
1318
+ with both Turbopack and `next build --webpack`, under npm and pnpm.
1319
+
1320
+ - **`serverExternalPackages`** gets `'@nxgt/material'`. Route handlers are
1321
+ bundled with React's `react-server` build, which has no `createContext`,
1322
+ and `/print` calls it when it loads; external, the library and React load
1323
+ from `node_modules`. Without it, `next build` stops at `Collecting page
1324
+ data` with
1325
+ [`TypeError: (0 , t.createContext) is not a function`](../troubleshooting.md#typeerror-0--tcreatecontext-is-not-a-function-in-a-nextjs-route-handler).
1326
+ - **`outputFileTracingIncludes`** gets, for every route (`'/**'`), every
1327
+ `.cjs` file under pdfkit's `js/standard-fonts/`: pdfkit `require()`s its
1328
+ fonts at runtime, which the tracer does not follow. Without it, a webpack
1329
+ build passes and `next start` works, but the standalone server answers
1330
+ `500` on the PDF route with
1331
+ [`Cannot find module '…/node_modules/pdfkit/js/standard-fonts/Helvetica.cjs'`](../troubleshooting.md#cannot-find-module-node_modulespdfkitjsstandard-fontshelveticacjs).
1332
+ Turbopack's trace included the files; the glob is added anyway, whatever
1333
+ the `output` and the bundler, because it costs nothing.
1334
+
1335
+ What it does, precisely:
1336
+
1337
+ - **It merges, and never overwrites.** Your `serverExternalPackages` and
1338
+ `outputFileTracingIncludes` keep what they had, other routes' globs
1339
+ included; the two additions are deduplicated. Every other key passes
1340
+ through.
1341
+ - **pdfkit is found where your app installs it.** It resolves
1342
+ `@react-pdf/renderer` from the project directory, then the pdfkit it
1343
+ depends on and the one `@react-pdf/font` depends on, to their real
1344
+ directories, and writes each as a glob relative to the project directory:
1345
+ `./node_modules/pdfkit/js/standard-fonts/**/*.cjs` under npm (checked end
1346
+ to end), `./node_modules/.pnpm/pdfkit@<version>/node_modules/pdfkit/js/standard-fonts/**/*.cjs`
1347
+ under pnpm (checked end to end), `./node_modules/.bun/pdfkit@<version>/…`
1348
+ under Bun's isolated linker, `../../node_modules/…` in a monorepo that
1349
+ hoists it above the app.
1350
+ - **Without `@react-pdf/renderer`** (an optional peer), it adds no fonts and
1351
+ says nothing. Any other failure to resolve them prints one
1352
+ `[@nxgt/material/next]` warning; the config is still returned, and the
1353
+ manual globs below are the fallback.
1354
+ - **The project directory is `process.cwd()`**, which is right when
1355
+ `next build` runs in the project. For `next build <dir>` run from
1356
+ elsewhere, pass it: `withNxgtPrint(config, { dir: import.meta.dirname })`
1357
+ (checked with Next.js 16.3's `next.config.ts`; `__dirname` in a CommonJS
1358
+ `next.config.js`). A relative `dir` is taken from the working directory.
1359
+ - **The function form of `next.config` works too**:
1360
+ `withNxgtPrint((phase, { defaultConfig }) => ({ ... }))` returns a function
1361
+ Next.js calls as usual.
1362
+ - It runs in Node at config time, imports only `node:*` built-ins and
1363
+ `@nxgt/material-core/pdfkit-fonts` (already installed with the library),
1364
+ and needs no dependency on `next`: its parameter accepts any `NextConfig`, and it
1365
+ returns the type you passed in. Its keys are not checked against
1366
+ `NextConfig`, so a misspelt one passes: write
1367
+ `withNxgtPrint({ ... } satisfies NextConfig)` to have them checked. The
1368
+ types it is written with are exported too, should you wrap it:
1369
+ `WithNxgtPrintOptions` (`{ dir }`), `NextConfigLike`, `NextConfigFunction`
1370
+ and `WithPrint`.
1371
+ - The package is ESM. A CommonJS `next.config.js` `require()`s it, which
1372
+ needs Node 20.19+ or 22.12+; `next.config.ts` and `next.config.mjs` import
1373
+ it.
1374
+
1375
+ **By hand**, when you would rather not use the helper, the same config is:
1376
+
1377
+ ```ts
1378
+ // next.config.ts
1379
+ import type { NextConfig } from 'next';
1380
+
1381
+ export default {
1382
+ output: 'standalone',
1383
+ // Route handlers are bundled with React's react-server build, which has no
1384
+ // createContext: load the library from node_modules instead.
1385
+ serverExternalPackages: ['@nxgt/material'],
1386
+ // pdfkit require()s its fonts' .cjs files at runtime; the tracer copies
1387
+ // only the .mjs ones. Only needed with output: 'standalone'.
1388
+ outputFileTracingIncludes: {
1389
+ '/**': ['./node_modules/pdfkit/js/standard-fonts/**/*.cjs'],
1390
+ },
1391
+ } satisfies NextConfig;
1392
+ ```
1393
+
1394
+ Under pnpm the glob is
1395
+ `./node_modules/.pnpm/pdfkit@*/node_modules/pdfkit/js/standard-fonts/**/*.cjs`.
1396
+
1397
+ `pdfkitStandardFonts()` is a Vite plugin and does not apply to Next.js.
1398
+
1295
1399
  More on what a server bundle evaluates in [SSR](ssr.md).
package/docs/roadmap.md CHANGED
@@ -82,6 +82,12 @@ Nothing in progress right now; see Next.
82
82
 
83
83
  ## Shipped
84
84
 
85
+ - **PDFs from a Next.js route handler in one line of config** —
86
+ `withNxgtPrint(nextConfig)` from `@nxgt/material/next` adds what `/print`
87
+ needs to `next.config.ts` — the library in `serverExternalPackages`, and
88
+ pdfkit's fonts in the `output: 'standalone'` trace wherever your package manager
89
+ installed them — merged with your own config. 2.4.0.
90
+ ([printing](guides/printing.md#nextjs-serverexternalpackages-and-output-standalone))
85
91
  - **One copy of the framework-free code, shared with `@nxgt/material-vue`** —
86
92
  the PDF document model and renderer, the print formatters, the PDF file
87
93
  helpers, `PdfReader`'s page geometry, scroll spy and search, the
@@ -35,6 +35,9 @@ words in your error.
35
35
 
36
36
  - [`Cannot find module '#standard-fonts/Helvetica'`](#cannot-find-module-standard-fontshelvetica)
37
37
  - [`still references '#standard-fonts/' after the transform`](#still-references-standard-fonts-after-the-transform)
38
+ - [`TypeError: (0 , t.createContext) is not a function` in a Next.js route handler](#typeerror-0--tcreatecontext-is-not-a-function-in-a-nextjs-route-handler)
39
+ - [`Cannot find module '…/node_modules/pdfkit/js/standard-fonts/Helvetica.cjs'` (Next.js `output: 'standalone'`)](#cannot-find-module-node_modulespdfkitjsstandard-fontshelveticacjs)
40
+ - [`[@nxgt/material/next] could not resolve …`](#nxgtmaterialnext-could-not-resolve-)
38
41
  - [`Module '"@nxgt/material"' has no exported member 'PrintHeader'`](#module-nxgtmaterial-has-no-exported-member-printheader)
39
42
  - [`Module '"@nxgt/material"' has no exported member 'formatAmount'`](#module-nxgtmaterial-has-no-exported-member-formatamount)
40
43
  - [An amount in yen shows no decimals, or one in dinars shows three](#an-amount-in-yen-shows-no-decimals-or-one-in-dinars-shows-three)
@@ -530,6 +533,130 @@ last `pdfkit` that built, and please report it (see
530
533
  { "overrides": { "pdfkit": "<last version that built>" } }
531
534
  ```
532
535
 
536
+ ### `TypeError: (0 , t.createContext) is not a function` in a Next.js route handler
537
+
538
+ **When:** `next build`, at `Collecting page data`, for an App Router route
539
+ handler that imports `@nxgt/material/print`. The build stops with
540
+ `Failed to collect configuration for /invoices/[id]/pdf`; the letter before
541
+ `.createContext` depends on the build (`t` with Turbopack, `d` with webpack).
542
+ **Why:** Next.js bundles route handlers for React Server Components, with
543
+ the `react-server` build of React, which has no `createContext`.
544
+ `@nxgt/material/print` also holds `usePdfFile` and the print context, so it
545
+ calls `createContext` when the module loads. (`@react-pdf/renderer` is already
546
+ external by default in Next.js; the library that imports it is not.)
547
+ **Fix:** leave the library out of the server bundle, so Node loads it, and
548
+ React, from `node_modules`. `withNxgtPrint` (2.4.0+) does it, and also
549
+ traces pdfkit's fonts for `output: 'standalone'` (the next entry):
550
+
551
+ ```ts
552
+ // next.config.ts
553
+ import { withNxgtPrint } from '@nxgt/material/next';
554
+
555
+ export default withNxgtPrint({
556
+ // your config, as it was
557
+ });
558
+ ```
559
+
560
+ By hand, on an older version:
561
+
562
+ ```ts
563
+ // next.config.ts
564
+ export default {
565
+ serverExternalPackages: ['@nxgt/material'],
566
+ };
567
+ ```
568
+
569
+ With `output: 'standalone'`, add the font files of the next entry too.
570
+
571
+ ### `Cannot find module '…/node_modules/pdfkit/js/standard-fonts/Helvetica.cjs'`
572
+
573
+ **When:** a Next.js app built with `output: 'standalone'` renders a PDF, run
574
+ from `.next/standalone/server.js` alone (a container image, a copied
575
+ folder). `next build` passes, `next start` works, but the PDF route answers
576
+ `500` with an empty body and the server log shows this message, with
577
+ `code: 'MODULE_NOT_FOUND'`, as an `unhandledRejection`. Seen with
578
+ `next build --webpack` (Next.js 16); Turbopack's trace did include the
579
+ files in the same app.
580
+ **Why:** pdfkit loads its standard fonts at runtime with
581
+ `require('#standard-fonts/<name>')`, which its `package.json` `imports` maps
582
+ to `js/standard-fonts/<name>.cjs` for `require`. The output file tracer
583
+ (`@vercel/nft`) follows the `default` condition and copies the `.mjs` files
584
+ only, so the `.cjs` pdfkit asks for is not in `.next/standalone`.
585
+ **Fix:** add the `.cjs` fonts (and their `chunks/`) to the trace.
586
+ `withNxgtPrint` (2.4.0+) finds where pdfkit is installed (checked end to end
587
+ under npm and pnpm) and adds them, merged with your own
588
+ `outputFileTracingIncludes`:
589
+
590
+ ```ts
591
+ // next.config.ts
592
+ import { withNxgtPrint } from '@nxgt/material/next';
593
+
594
+ export default withNxgtPrint({ output: 'standalone' });
595
+ ```
596
+
597
+ If it cannot resolve a pdfkit it prints one `[@nxgt/material/next]` warning
598
+ (next entry) and adds only the fonts it did resolve. By hand, or on an older version:
599
+
600
+ ```ts
601
+ // next.config.ts
602
+ export default {
603
+ output: 'standalone',
604
+ serverExternalPackages: ['@nxgt/material'],
605
+ outputFileTracingIncludes: {
606
+ '/**': ['./node_modules/pdfkit/js/standard-fonts/**/*.cjs'],
607
+ },
608
+ };
609
+ ```
610
+
611
+ The key is a route glob: `'/**'` covers every route, `'/invoices/**'` only
612
+ the routes under `/invoices`. The path is from the project root to
613
+ where pdfkit is installed. With pnpm, pdfkit is not at the top of
614
+ `node_modules`; use its store directory (checked with pnpm 11, the same
615
+ `500` without it):
616
+
617
+ ```ts
618
+ outputFileTracingIncludes: {
619
+ '/**': ['./node_modules/.pnpm/pdfkit@*/node_modules/pdfkit/js/standard-fonts/**/*.cjs'],
620
+ },
621
+ ```
622
+
623
+ Check with `ls .next/standalone/node_modules/pdfkit/js/standard-fonts/*.cjs`
624
+ after the build (under pnpm,
625
+ `.next/standalone/node_modules/.pnpm/pdfkit@*/node_modules/pdfkit/js/standard-fonts/`).
626
+
627
+ ### `[@nxgt/material/next] could not resolve …`
628
+
629
+ **When:** `next build` or `next dev` prints, once,
630
+ `[@nxgt/material/next] could not resolve <what>: <error>. PDF routes may
631
+ answer 500 under output: 'standalone'; add pdfkit's
632
+ js/standard-fonts/**/*.cjs to outputFileTracingIncludes by hand.`
633
+ When several things failed, that one message lists them all, joined by
634
+ `; `, each error cut to its first line (for example `could not resolve
635
+ @react-pdf/font: …; could not resolve pdfkit's fonts for
636
+ @react-pdf/renderer: …`).
637
+ **Why:** `withNxgtPrint` found `@react-pdf/renderer` but could not follow it
638
+ to `@react-pdf/font` or to a pdfkit's `standard-fonts` (an unusual
639
+ installation, a patched or partial `node_modules`). It adds the fonts it did
640
+ resolve and returns your config; the build goes on. Without
641
+ `@react-pdf/renderer` installed it prints nothing: there is nothing to trace.
642
+ **Fix:** only `output: 'standalone'` needs the fonts. Add the missing ones by
643
+ hand, as in the previous entry, next to the helper:
644
+
645
+ ```ts
646
+ // next.config.ts
647
+ import { withNxgtPrint } from '@nxgt/material/next';
648
+
649
+ export default withNxgtPrint({
650
+ output: 'standalone',
651
+ outputFileTracingIncludes: {
652
+ '/**': ['./node_modules/pdfkit/js/standard-fonts/**/*.cjs'],
653
+ },
654
+ });
655
+ ```
656
+
657
+ If `next build` runs from another directory, pass `{ dir }` (see
658
+ [printing](guides/printing.md#nextjs-serverexternalpackages-and-output-standalone)).
659
+
533
660
  ### `Module '"@nxgt/material"' has no exported member 'PrintHeader'`
534
661
 
535
662
  **When:** type-checking (`TS2305`) or bundling (`"PrintHeader" is not exported
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxgt/material",
3
- "version": "2.3.1",
3
+ "version": "2.4.1",
4
4
  "license": "MIT",
5
5
  "bugs": {
6
6
  "email": "stevegires@gmail.com"
@@ -43,6 +43,11 @@
43
43
  "types": "./dist/lib/vite/index.d.ts",
44
44
  "require": "./dist/vite.js"
45
45
  },
46
+ "./next": {
47
+ "import": "./dist/next.js",
48
+ "types": "./dist/lib/next/index.d.ts",
49
+ "require": "./dist/next.js"
50
+ },
46
51
  "./hooks": {
47
52
  "import": "./dist/hooks.js",
48
53
  "types": "./dist/lib/hooks/index.d.ts",
@@ -108,7 +113,7 @@
108
113
  "docs:previews": "vitest run --project previews"
109
114
  },
110
115
  "dependencies": {
111
- "@nxgt/material-core": "^0.1.1",
116
+ "@nxgt/material-core": "^0.2.0",
112
117
  "@base-ui/react": "^1.6.0",
113
118
  "@dnd-kit/core": "^6.3.1",
114
119
  "@dnd-kit/sortable": "^10.0.0",
@@ -1 +0,0 @@
1
- export declare function formatFileSize(bytes: number): string;