@void/react 0.7.5 → 0.7.7

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.
@@ -15,7 +15,7 @@ type CommonProps = {
15
15
  replace?: boolean;
16
16
  reloadDocument?: boolean;
17
17
  viewTransition?: boolean;
18
- prefetch?: boolean | PrefetchStrategy | Array<PrefetchStrategy>;
18
+ prefetch?: boolean | PrefetchStrategy | ReadonlyArray<PrefetchStrategy>;
19
19
  cacheFor?: number | string | [string, string];
20
20
  onNavigate?: (event: {
21
21
  preventDefault(): void;
@@ -68,8 +68,8 @@ declare function useForm<U extends ActionUrl & string>(url: U, defaults: Resolve
68
68
  put(formData: FormData): void;
69
69
  patch(formData: FormData): void;
70
70
  delete(formData: FormData): void;
71
- reset(...fields: Array<keyof ResolveActionBody<U> & string>): void;
72
- clearErrors(...fields: Array<keyof ResolveActionBody<U> & string>): void;
71
+ reset(...fields: ReadonlyArray<keyof ResolveActionBody<U> & string>): void;
72
+ clearErrors(...fields: ReadonlyArray<keyof ResolveActionBody<U> & string>): void;
73
73
  clearError(): void;
74
74
  };
75
75
  //#endregion
@@ -77,7 +77,7 @@ declare function useForm<U extends ActionUrl & string>(url: U, defaults: Resolve
77
77
  declare function useNavigation(): NavigationState;
78
78
  //#endregion
79
79
  //#region src/runtime/use-island-form.d.ts
80
- interface IslandFormReturn<T extends Record<string, unknown>> {
80
+ type IslandFormReturn<T extends Record<string, unknown>> = Readonly<{
81
81
  data: T;
82
82
  setData: <K extends keyof T & string>(field: K, value: T[K]) => void;
83
83
  errors: Record<string, string>;
@@ -86,14 +86,14 @@ interface IslandFormReturn<T extends Record<string, unknown>> {
86
86
  hasChanges: boolean;
87
87
  wasSuccessful: boolean;
88
88
  recentlySuccessful: boolean;
89
- reset: (...fields: Array<keyof T & string>) => void;
90
- clearErrors: (...fields: Array<string>) => void;
89
+ reset: (...fields: ReadonlyArray<keyof T & string>) => void;
90
+ clearErrors: (...fields: ReadonlyArray<string>) => void;
91
91
  clearError: () => void;
92
92
  post: (url: string) => Promise<void>;
93
93
  put: (url: string) => Promise<void>;
94
94
  patch: (url: string) => Promise<void>;
95
95
  delete: (url: string) => Promise<void>;
96
- }
96
+ }>;
97
97
  /**
98
98
  * Form hook for island pages. Uses fetch + page reload instead of the
99
99
  * Void Router (which is not available in island mode).
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as ParamsContext, c as action, d as useNavigation, f as useForm, g as Link, h as useRouter, i as NavigationContext, l as setActionRouter, m as useParams, n as InferProps, o as RouterContext, p as useShared, r as ErrorsContext, s as SharedContext, t as Deferred, u as useIslandForm } from "./index-75EO-lLe.mjs";
1
+ import { a as ParamsContext, c as action, d as useNavigation, f as useForm, g as Link, h as useRouter, i as NavigationContext, l as setActionRouter, m as useParams, n as InferProps, o as RouterContext, p as useShared, r as ErrorsContext, s as SharedContext, t as Deferred, u as useIslandForm } from "./index-CykTJ4Xm.mjs";
2
2
  export { Deferred, ErrorsContext, InferProps, Link, NavigationContext, ParamsContext, RouterContext, SharedContext, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  import { a as SharedContext, i as RouterContext, n as NavigationContext, r as ParamsContext, t as ErrorsContext } from "./context-CBGCQE3p.mjs";
2
- import { a as useParams, i as useShared, n as useNavigation, o as useRouter, r as useForm, s as Link, t as useIslandForm } from "./runtime-BpEAl7K2.mjs";
2
+ import { a as useParams, i as useShared, n as useNavigation, o as useRouter, r as useForm, s as Link, t as useIslandForm } from "./runtime-C0j3tKTP.mjs";
3
3
  import { n as setActionRouter, t as action } from "./action-BFWtavbf.mjs";
4
4
  export { ErrorsContext, Link, NavigationContext, ParamsContext, RouterContext, SharedContext, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
package/dist/plugin.d.mts CHANGED
@@ -2,15 +2,15 @@ import react from "@vitejs/plugin-react";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/plugin.d.ts
5
- interface PrefetchConfig {
5
+ type PrefetchConfig = {
6
6
  hoverDelay?: number;
7
7
  cacheFor?: number | string | [string, string];
8
- }
9
- interface VoidReactOptions {
8
+ };
9
+ type VoidReactOptions = Readonly<{
10
10
  react?: Parameters<typeof react>[0];
11
11
  viewTransitions?: boolean;
12
12
  prefetch?: PrefetchConfig;
13
- }
14
- declare function voidReact(options?: VoidReactOptions): Array<Plugin>;
13
+ }>;
14
+ declare function voidReact(options?: VoidReactOptions): ReadonlyArray<Plugin>;
15
15
  //#endregion
16
16
  export { VoidReactOptions, voidReact };
package/dist/plugin.mjs CHANGED
@@ -2,7 +2,7 @@ import react from "@vitejs/plugin-react";
2
2
  import { existsSync, readFileSync, readdirSync } from "node:fs";
3
3
  import { normalizePath } from "vite";
4
4
  import { generateComponentManifest, resolveEffectiveLayoutChain, resolveStaticPageDataBuildOptions, scanPages } from "void/pages";
5
- import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, configureIslandCssServer, extractCssImports, fileHasCssImports, needsIslandClientBundle, rebuildIslandCssMap, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
5
+ import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, extractCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
6
6
  //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
7
7
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
8
8
  function normalizeWindowsPath(input = "") {
@@ -148,13 +148,7 @@ function islandsPlugin(pagesDir) {
148
148
  const islandManifest = /* @__PURE__ */ new Map();
149
149
  const islandCssFiles = /* @__PURE__ */ new Set();
150
150
  let viteRoot = "";
151
- const islandCssMap = /* @__PURE__ */ new Map();
152
151
  let resolvedConfig = null;
153
- /** Rebuild islandCssMap from current file contents (re-runs fileHasCssImports). */
154
- function rebuildCssMapLocal() {
155
- if (!pageScan) return;
156
- rebuildIslandCssMap(pageScan, pagesDir, islandCssMap, fileHasCssImports);
157
- }
158
152
  function computePagesNeedingClientJSLocal() {
159
153
  if (!pageScan) return /* @__PURE__ */ new Set();
160
154
  return computePagesNeedingClientJS(pageScan, pagesDir, resolvedConfig);
@@ -167,10 +161,8 @@ function islandsPlugin(pagesDir) {
167
161
  isDev = config.command === "serve";
168
162
  },
169
163
  configureServer(server) {
170
- configureIslandCssServer(server, islandCssFiles, viteRoot, rebuildCssMapLocal);
171
164
  watchPagesForRescan(server, pagesDir, root, (scan) => {
172
165
  pageScan = scan;
173
- rebuildCssMapLocal();
174
166
  });
175
167
  },
176
168
  async buildStart() {
@@ -178,17 +170,17 @@ function islandsPlugin(pagesDir) {
178
170
  pageScan = await scanPages(root);
179
171
  const importAttrRe = /import\s+\w+\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*\}/g;
180
172
  const filesToScan = [
181
- ...pageScan.pages.map((p) => ({
182
- filePath: p.componentPath,
183
- island: p.island
173
+ ...pageScan.pages.map((page) => ({
174
+ filePath: page.componentPath,
175
+ island: page.island
184
176
  })),
185
- ...pageScan.layouts.map((l) => ({
186
- filePath: l.filePath,
187
- island: l.island
177
+ ...pageScan.layouts.map((layout) => ({
178
+ filePath: layout.filePath,
179
+ island: layout.island
188
180
  })),
189
- ...pageScan.namedLayouts.map((nl) => ({
190
- filePath: nl.filePath,
191
- island: nl.island
181
+ ...pageScan.namedLayouts.map((namedLayout) => ({
182
+ filePath: namedLayout.filePath,
183
+ island: namedLayout.island
192
184
  }))
193
185
  ];
194
186
  for (const entry of filesToScan) {
@@ -197,10 +189,10 @@ function islandsPlugin(pagesDir) {
197
189
  const code = readFileSync(filePath, "utf-8");
198
190
  const importerDir = dirname(filePath);
199
191
  importAttrRe.lastIndex = 0;
200
- let m;
201
- while ((m = importAttrRe.exec(code)) !== null) {
202
- const spec = m[1].slice(1, -1);
203
- const strategy = m[2].slice(1, -1);
192
+ let importMatch;
193
+ while ((importMatch = importAttrRe.exec(code)) !== null) {
194
+ const spec = importMatch[1].slice(1, -1);
195
+ const strategy = importMatch[2].slice(1, -1);
204
196
  const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
205
197
  if (absPath) {
206
198
  const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "");
@@ -218,7 +210,6 @@ function islandsPlugin(pagesDir) {
218
210
  const layoutChain = resolveEffectiveLayoutChain(page, pageScan.layouts, pageScan.namedLayouts);
219
211
  for (const layout of layoutChain) islandCssFiles.add(normalizePath(resolve(pagesDir, layout.filePath)));
220
212
  }
221
- rebuildCssMapLocal();
222
213
  }
223
214
  },
224
215
  resolveId: {
@@ -240,10 +231,10 @@ function islandsPlugin(pagesDir) {
240
231
  handler(id) {
241
232
  if (id === "\0" + ISLANDS_RENDERER_ID) {
242
233
  if (!pageScan) return "export function renderIslandPage() { throw new Error('No pages found'); }";
243
- const mdPlugin = resolvedConfig?.plugins?.find((p) => p.name === "void-md");
234
+ const mdPlugin = resolvedConfig?.plugins?.find((plugin) => plugin.name === "void-md");
244
235
  const mdScriptIds = new Set(mdPlugin?.api?.getClientScripts?.()?.keys() ?? []);
245
236
  const needsJS = computePagesNeedingClientJSLocal();
246
- return generateIslandRenderer(pageScan, pagesDir, isDev, islandCssMap, viteRoot, mdScriptIds, needsJS);
237
+ return generateIslandRenderer(pageScan, pagesDir, isDev, mdScriptIds, needsJS);
247
238
  }
248
239
  if (id === "\0" + ISLANDS_CLIENT_ENTRY_ID) {
249
240
  if (!pageScan) return "";
@@ -304,7 +295,7 @@ function islandsPlugin(pagesDir) {
304
295
  }
305
296
  }];
306
297
  }
307
- function generateIslandRenderer(scan, pagesDir, isDev, islandCssMap, viteRoot, mdScriptIds, pagesNeedingClientJS) {
298
+ function generateIslandRenderer(scan, pagesDir, isDev, mdScriptIds, pagesNeedingClientJS) {
308
299
  const preambleScript = isDev ? `
309
300
  <script type="module">
310
301
  import RefreshRuntime from "/@react-refresh"
@@ -313,12 +304,6 @@ function generateIslandRenderer(scan, pagesDir, isDev, islandCssMap, viteRoot, m
313
304
  window.$RefreshSig$ = () => (type) => type
314
305
  window.__vite_plugin_react_preamble_installed__ = true
315
306
  <\/script>` : "";
316
- let cssMapCode = "";
317
- if (isDev && islandCssMap.size > 0) {
318
- const cssMapObj = {};
319
- for (const [compId, paths] of islandCssMap) cssMapObj[compId] = paths.map((p) => "/" + normalizePath(relative(viteRoot, p)) + ".css");
320
- cssMapCode = `const __cssPaths = ${JSON.stringify(cssMapObj)};`;
321
- }
322
307
  const mdScriptIdsCode = `const __mdClientScriptIds = new Set(${JSON.stringify([...mdScriptIds])});`;
323
308
  const needsJSCode = `const __pagesNeedingClientJS = new Set(${JSON.stringify([...pagesNeedingClientJS])});`;
324
309
  return `
@@ -328,7 +313,6 @@ import { SharedContext, ErrorsContext, ParamsContext } from "@void/react";
328
313
  import { renderHeadToString, renderHtmlAttrs, renderBodyAttrs } from "void/pages-head";
329
314
 
330
315
  ${generateComponentManifest(scan, pagesDir)}
331
- ${cssMapCode}
332
316
  ${mdScriptIdsCode}
333
317
  ${needsJSCode}
334
318
 
@@ -373,7 +357,7 @@ export async function renderIslandPage(pageObj, assetTags) {
373
357
 
374
358
  return \`<!doctype html>
375
359
  <html\${htmlAttrs}>
376
- <head>\${headHtml}\${typeof __cssPaths !== "undefined" ? (__cssPaths[pageObj.component] || []).map(url => '<link rel="stylesheet" href="' + url + '">').join("\\n") : ""}\${PREAMBLE_SCRIPT}\${assetTags.css}\${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.preloads : ""}</head>
360
+ <head>\${headHtml}\${PREAMBLE_SCRIPT}\${assetTags.css}\${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.preloads : ""}</head>
377
361
  <body\${bodyAttrs}>
378
362
  <div id="app"\${__mdScriptAttr}>\${html}</div>
379
363
  \${__pagesNeedingClientJS.has(pageObj.component) ? assetTags.body : ""}
@@ -1,2 +1,2 @@
1
- import { a as ParamsContext, c as action, d as useNavigation, f as useForm, g as Link, h as useRouter, i as NavigationContext, l as setActionRouter, m as useParams, n as InferProps, o as RouterContext, p as useShared, r as ErrorsContext, s as SharedContext, t as Deferred, u as useIslandForm } from "../index-75EO-lLe.mjs";
1
+ import { a as ParamsContext, c as action, d as useNavigation, f as useForm, g as Link, h as useRouter, i as NavigationContext, l as setActionRouter, m as useParams, n as InferProps, o as RouterContext, p as useShared, r as ErrorsContext, s as SharedContext, t as Deferred, u as useIslandForm } from "../index-CykTJ4Xm.mjs";
2
2
  export { Deferred, ErrorsContext, InferProps, Link, NavigationContext, ParamsContext, RouterContext, SharedContext, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
@@ -1,4 +1,4 @@
1
1
  import { a as SharedContext, i as RouterContext, n as NavigationContext, r as ParamsContext, t as ErrorsContext } from "../context-CBGCQE3p.mjs";
2
- import { a as useParams, i as useShared, n as useNavigation, o as useRouter, r as useForm, s as Link, t as useIslandForm } from "../runtime-BpEAl7K2.mjs";
2
+ import { a as useParams, i as useShared, n as useNavigation, o as useRouter, r as useForm, s as Link, t as useIslandForm } from "../runtime-C0j3tKTP.mjs";
3
3
  import { n as setActionRouter, t as action } from "../action-BFWtavbf.mjs";
4
4
  export { ErrorsContext, Link, NavigationContext, ParamsContext, RouterContext, SharedContext, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
@@ -6,7 +6,7 @@ import { CacheForResult } from "void/pages-prefetch";
6
6
  type ComponentModule = {
7
7
  default: ComponentType<any>;
8
8
  };
9
- interface ReactPagesConfig {
9
+ type ReactPagesConfig = Readonly<{
10
10
  components: Record<string, () => Promise<ComponentModule>>;
11
11
  layoutTree: Record<string, Array<string>>;
12
12
  routeMeta: Record<string, {
@@ -18,10 +18,10 @@ interface ReactPagesConfig {
18
18
  viewTransitions: boolean;
19
19
  prefetchHoverDelay: number;
20
20
  prefetchDefaultCacheFor: CacheForResult;
21
- }
22
- interface ReactPagesClient {
21
+ }>;
22
+ type ReactPagesClient = Readonly<{
23
23
  router: VoidRouter;
24
- }
24
+ }>;
25
25
  declare function startReactPages(config: ReactPagesConfig): Promise<ReactPagesClient>;
26
26
  //#endregion
27
27
  export { ReactPagesClient, ReactPagesConfig, startReactPages };
@@ -5,7 +5,7 @@ import { PageObject } from "void/pages-protocol";
5
5
  type ComponentModule = {
6
6
  default: ComponentType<any>;
7
7
  };
8
- interface ReactPagesServerConfig {
8
+ type ReactPagesServerConfig = Readonly<{
9
9
  pageObj: PageObject;
10
10
  assetTags: {
11
11
  css: string;
@@ -15,7 +15,7 @@ interface ReactPagesServerConfig {
15
15
  components: Record<string, () => Promise<ComponentModule>>;
16
16
  layoutTree: Record<string, Array<string>>;
17
17
  preambleScript?: string;
18
- }
18
+ }>;
19
19
  declare function renderReactPage({
20
20
  pageObj,
21
21
  assetTags,
@@ -425,7 +425,7 @@ function useIslandForm(defaults) {
425
425
  if (fields.length === 0) setErrors({});
426
426
  else setErrors((prev) => {
427
427
  const next = { ...prev };
428
- for (const f of fields) delete next[f];
428
+ for (const field of fields) delete next[field];
429
429
  return next;
430
430
  });
431
431
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/react",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voidzero-dev/void.git",
@@ -51,13 +51,13 @@
51
51
  "react-dom": "^19.2.6",
52
52
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
53
53
  "vite-plus": "^0.1.20",
54
- "void": "0.7.5"
54
+ "void": "0.7.7"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "react": "^19.0.0",
58
58
  "react-dom": "^19.0.0",
59
59
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
60
- "void": "0.7.5"
60
+ "void": "0.7.7"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "vp pack",