@arkstack/view 0.15.4 → 0.16.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/dist/index.d.ts CHANGED
@@ -257,9 +257,23 @@ interface ViteTagOptions {
257
257
  */
258
258
  declare const viteTags: (entries: string | string[], options?: ViteTagOptions) => string;
259
259
  /**
260
- * Register the `@vite(...)` tag (and its backing global) on a view factory so
261
- * templates can emit Vite asset tags: `@vite('resources/js/app.ts')` or
262
- * `@vite(['resources/css/app.css', 'resources/js/app.ts'])`.
260
+ * Resolve the React Refresh preamble for `@vitejs/plugin-react`.
261
+ *
262
+ * When Vite serves the HTML itself it injects this preamble automatically; here
263
+ * the page is rendered by Edge and the dev tags are emitted manually, so the
264
+ * preamble must be added by hand — otherwise React throws "can't detect
265
+ * preamble". It must precede the `@vite(...)` tags. Emits nothing in production.
266
+ *
267
+ * @param options
268
+ * @returns
269
+ */
270
+ declare const viteReactRefresh: (options?: ViteTagOptions) => string;
271
+ /**
272
+ * Register the `@vite(...)` and `@viteReactRefresh` tags (and their backing
273
+ * globals) on a view factory so templates can emit Vite asset tags:
274
+ * `@vite('resources/js/app.ts')` or `@vite(['resources/css/app.css',
275
+ * 'resources/js/app.ts'])`, and the React Refresh preamble via
276
+ * `@viteReactRefresh` (placed before `@vite`).
263
277
  *
264
278
  * @param factory
265
279
  */
@@ -272,4 +286,4 @@ declare const runWithViewData: <T>(data: ViewData, callback: () => T | Promise<T
272
286
  declare const clearViewData: () => void;
273
287
  declare const collectViewData: (context: Record<string, any>) => ViewData;
274
288
  //#endregion
275
- export { type ComposerRunner, Edge, type SyncComposerRunner, View, type ViewComposer, type ViewComposerClass, type ViewComposerHandler, type ViewComposerName, type ViewComposerObject, type ViewData, ViewErrorBag, type ViewErrorRecord, type ViewErrorValue, ViewFactory, type ViewFactoryOptions, ViewInstance, type ViewName, type ViteTagOptions, clearRouterViewPlugin, clearViewData, collectViewData, edge, enterViewData, getViewData, normalizeViewErrors, parsePackageViewName, registerViteTag, resolvePackageViewsPath, runWithViewData, view, viteTags };
289
+ export { type ComposerRunner, Edge, type SyncComposerRunner, View, type ViewComposer, type ViewComposerClass, type ViewComposerHandler, type ViewComposerName, type ViewComposerObject, type ViewData, ViewErrorBag, type ViewErrorRecord, type ViewErrorValue, ViewFactory, type ViewFactoryOptions, ViewInstance, type ViewName, type ViteTagOptions, clearRouterViewPlugin, clearViewData, collectViewData, edge, enterViewData, getViewData, normalizeViewErrors, parsePackageViewName, registerViteTag, resolvePackageViewsPath, runWithViewData, view, viteReactRefresh, viteTags };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { a as viteTags, c as enterViewData, d as ViewInstance, f as parsePackageViewName, g as normalizeViewErrors, h as ViewErrorBag, i as registerViteTag, l as getViewData, m as view, n as View, o as clearViewData, p as resolvePackageViewsPath, r as ViewFactory, s as collectViewData, t as clearRouterViewPlugin, u as runWithViewData } from "./plugins-DWO_aTcP.js";
1
+ import { _ as normalizeViewErrors, a as viteReactRefresh, c as collectViewData, d as runWithViewData, f as ViewInstance, g as ViewErrorBag, h as view, i as registerViteTag, l as enterViewData, m as resolvePackageViewsPath, n as View, o as viteTags, p as parsePackageViewName, r as ViewFactory, s as clearViewData, t as clearRouterViewPlugin, u as getViewData } from "./plugins-DCq-Gl05.js";
2
2
  import edge, { Edge } from "edge.js";
3
- export { Edge, View, ViewErrorBag, ViewFactory, ViewInstance, clearRouterViewPlugin, clearViewData, collectViewData, edge, enterViewData, getViewData, normalizeViewErrors, parsePackageViewName, registerViteTag, resolvePackageViewsPath, runWithViewData, view, viteTags };
3
+ export { Edge, View, ViewErrorBag, ViewFactory, ViewInstance, clearRouterViewPlugin, clearViewData, collectViewData, edge, enterViewData, getViewData, normalizeViewErrors, parsePackageViewName, registerViteTag, resolvePackageViewsPath, runWithViewData, view, viteReactRefresh, viteTags };
@@ -351,19 +351,49 @@ const viteTags = (entries, options = {}) => {
351
351
  return productionTags(list, options.manifest ?? join(Arkstack.rootDir(), "public", "build", ".vite", "manifest.json"), options.buildDir ?? "/build/");
352
352
  };
353
353
  /**
354
- * Register the `@vite(...)` tag (and its backing global) on a view factory so
355
- * templates can emit Vite asset tags: `@vite('resources/js/app.ts')` or
356
- * `@vite(['resources/css/app.css', 'resources/js/app.ts'])`.
357
- *
358
- * @param factory
354
+ * Resolve the React Refresh preamble for `@vitejs/plugin-react`.
355
+ *
356
+ * When Vite serves the HTML itself it injects this preamble automatically; here
357
+ * the page is rendered by Edge and the dev tags are emitted manually, so the
358
+ * preamble must be added by hand — otherwise React throws "can't detect
359
+ * preamble". It must precede the `@vite(...)` tags. Emits nothing in production.
360
+ *
361
+ * @param options
362
+ * @returns
363
+ */
364
+ const viteReactRefresh = (options = {}) => {
365
+ if (!(options.hot ?? nodeEnv() !== "prod")) return "";
366
+ return [
367
+ "<script type=\"module\">",
368
+ `import RefreshRuntime from '${trimTrailingSlash(options.devUrl ?? env("VITE_DEV_URL", "http://localhost:5173"))}/@react-refresh'`,
369
+ "RefreshRuntime.injectIntoGlobalHook(window)",
370
+ "window.$RefreshReg$ = () => {}",
371
+ "window.$RefreshSig$ = () => (type) => type",
372
+ "window.__vite_plugin_react_preamble_installed__ = true",
373
+ "<\/script>"
374
+ ].join("\n");
375
+ };
376
+ /**
377
+ * Register the `@vite(...)` and `@viteReactRefresh` tags (and their backing
378
+ * globals) on a view factory so templates can emit Vite asset tags:
379
+ * `@vite('resources/js/app.ts')` or `@vite(['resources/css/app.css',
380
+ * 'resources/js/app.ts'])`, and the React Refresh preamble via
381
+ * `@viteReactRefresh` (placed before `@vite`).
382
+ *
383
+ * @param factory
359
384
  */
360
385
  const registerViteTag = (factory) => {
361
386
  factory.edge.global("__arkViteTags", (entries, options) => viteTags(entries, options));
387
+ factory.edge.global("__arkViteReactRefresh", (options) => viteReactRefresh(options));
362
388
  factory.tag("vite", false, true, (parser, buffer, token) => {
363
389
  const expression = `__arkViteTags(${token.properties.jsArg})`;
364
390
  const ast = parser.utils.transformAst(parser.utils.generateAST(expression, token.loc, token.filename), token.filename, parser);
365
391
  buffer.outputExpression(parser.utils.stringify(ast), token.filename, token.loc.start.line, false);
366
392
  });
393
+ factory.tag("viteReactRefresh", false, false, (parser, buffer, token) => {
394
+ const ast = parser.utils.transformAst(parser.utils.generateAST("__arkViteReactRefresh()", token.loc, token.filename), token.filename, parser);
395
+ buffer.outputExpression(parser.utils.stringify(ast), token.filename, token.loc.start.line, false);
396
+ });
367
397
  };
368
398
  //#endregion
369
399
  //#region src/ViewFactory.ts
@@ -588,4 +618,4 @@ const clearRouterViewPlugin = definePlugin({
588
618
  }
589
619
  });
590
620
  //#endregion
591
- export { viteTags as a, enterViewData as c, ViewInstance as d, parsePackageViewName as f, normalizeViewErrors as g, ViewErrorBag as h, registerViteTag as i, getViewData as l, view as m, View as n, clearViewData as o, resolvePackageViewsPath as p, ViewFactory as r, collectViewData as s, clearRouterViewPlugin as t, runWithViewData as u };
621
+ export { normalizeViewErrors as _, viteReactRefresh as a, collectViewData as c, runWithViewData as d, ViewInstance as f, ViewErrorBag as g, view as h, registerViteTag as i, enterViewData as l, resolvePackageViewsPath as m, View as n, viteTags as o, parsePackageViewName as p, ViewFactory as r, clearViewData as s, clearRouterViewPlugin as t, getViewData as u };
package/dist/setup.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as clearRouterViewPlugin } from "./plugins-DWO_aTcP.js";
1
+ import { t as clearRouterViewPlugin } from "./plugins-DCq-Gl05.js";
2
2
  import { CoreRouter } from "clear-router/core";
3
3
  //#region src/setup.ts
4
4
  CoreRouter.use(clearRouterViewPlugin);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/view",
3
- "version": "0.15.4",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "description": "View module for Arkstack, providing template rendering and view integration utilities.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/views",
@@ -33,13 +33,13 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "edge.js": "^6.5.0",
36
- "@arkstack/contract": "^0.15.4"
36
+ "@arkstack/contract": "^0.16.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@h3ravel/musket": "^2.2.1",
40
40
  "clear-router": "^2.9.0",
41
- "@arkstack/common": "^0.15.4",
42
- "@arkstack/foundry": "^0.15.4"
41
+ "@arkstack/common": "^0.16.0",
42
+ "@arkstack/foundry": "^0.16.0"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@h3ravel/musket": {