@reforma/site 0.0.4 → 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.
@@ -11,10 +11,13 @@ type TrackOptions = {
11
11
  };
12
12
  /**
13
13
  * Start first-party pageview collection for a published Reforma site.
14
- * Reads `NEXT_PUBLIC_REFORMA_ANALYTICS*` env baked on publish. Safe to call
15
- * multiple times — only the first call installs history hooks.
14
+ * Reads the project site config. Only the first call installs history hooks.
16
15
  */
17
- export declare function initAnalytics(options?: AnalyticsOptions): void;
16
+ export declare function initAnalytics(config: {
17
+ analyticsEnabled: boolean;
18
+ analyticsWriteKey: string;
19
+ analyticsEndpoint: string;
20
+ }, options?: AnalyticsOptions): void;
18
21
  /**
19
22
  * Send a named event. `pageview` is traffic (deduped by path); any other name
20
23
  * is a custom event / goal conversion. Optional `props` are string key/values.
@@ -1 +1 @@
1
- {"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACpB,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AASF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,gBAAqB,GAAG,IAAI,CAqClE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CA6DpE"}
1
+ {"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACpB,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AASF;;;GAGG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE;IAAE,gBAAgB,EAAE,OAAO,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,EAC3F,OAAO,GAAE,gBAAqB,GAC/B,IAAI,CAqCN;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CA6DpE"}
package/dist/analytics.js CHANGED
@@ -6,10 +6,9 @@ let lastPath = '';
6
6
  let unhook = null;
7
7
  /**
8
8
  * Start first-party pageview collection for a published Reforma site.
9
- * Reads `NEXT_PUBLIC_REFORMA_ANALYTICS*` env baked on publish. Safe to call
10
- * multiple times — only the first call installs history hooks.
9
+ * Reads the project site config. Only the first call installs history hooks.
11
10
  */
12
- export function initAnalytics(options = {}) {
11
+ export function initAnalytics(config, options = {}) {
13
12
  if (typeof window === 'undefined') {
14
13
  return;
15
14
  }
@@ -23,9 +22,9 @@ export function initAnalytics(options = {}) {
23
22
  return;
24
23
  }
25
24
  started = true;
26
- enabled = process.env.NEXT_PUBLIC_REFORMA_ANALYTICS === '1';
27
- writeKey = process.env.NEXT_PUBLIC_REFORMA_ANALYTICS_KEY?.trim() ?? '';
28
- endpoint = process.env.NEXT_PUBLIC_REFORMA_ANALYTICS_ENDPOINT?.trim() ?? '';
25
+ enabled = config.analyticsEnabled;
26
+ writeKey = config.analyticsWriteKey.trim();
27
+ endpoint = config.analyticsEndpoint.trim();
29
28
  if (!enabled || !writeKey || !endpoint) {
30
29
  enabled = false;
31
30
  return;
@@ -0,0 +1,11 @@
1
+ /** Detail of the `reforma:fix-error` window event the editor bridge forwards to a new chat. */
2
+ export type FixErrorDetail = {
3
+ message: string;
4
+ digest: string | null;
5
+ stack: string | null;
6
+ };
7
+ /** Fallback for `error.tsx` and `global-error.tsx`. Details and Fix with AI show in development only. */
8
+ export declare function ErrorState({ error }: {
9
+ error: unknown;
10
+ }): import("react").JSX.Element;
11
+ //# sourceMappingURL=error-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-state.d.ts","sourceRoot":"","sources":["../src/error-state.tsx"],"names":[],"mappings":"AAIA,+FAA+F;AAC/F,MAAM,MAAM,cAAc,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AA+CF,yGAAyG;AACzG,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,+BAmCvD"}
@@ -0,0 +1,64 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useSyncExternalStore } from 'react';
4
+ const button = {
5
+ height: '32px',
6
+ padding: '0 12px',
7
+ fontSize: '14px',
8
+ fontWeight: 500,
9
+ borderRadius: '6px',
10
+ cursor: 'pointer',
11
+ };
12
+ const styles = {
13
+ main: {
14
+ fontFamily: 'system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
15
+ minHeight: '100vh',
16
+ display: 'flex',
17
+ alignItems: 'center',
18
+ justifyContent: 'center',
19
+ padding: '64px 24px',
20
+ boxSizing: 'border-box',
21
+ },
22
+ card: { width: '100%', maxWidth: '448px' },
23
+ title: { fontSize: '24px', fontWeight: 500, lineHeight: '32px', margin: '0 0 12px' },
24
+ message: { fontSize: '14px', lineHeight: '21px', margin: '0 0 20px', opacity: 0.7 },
25
+ details: {
26
+ fontFamily: 'ui-monospace, Menlo, monospace',
27
+ fontSize: '12px',
28
+ whiteSpace: 'pre-wrap',
29
+ overflowX: 'auto',
30
+ margin: '0 0 20px',
31
+ padding: '12px',
32
+ borderRadius: '8px',
33
+ background: 'color-mix(in srgb, currentColor 6%, transparent)',
34
+ },
35
+ buttons: { display: 'flex', gap: '8px' },
36
+ button: { ...button, color: 'Canvas', background: 'CanvasText', border: 'none' },
37
+ secondary: {
38
+ ...button,
39
+ color: 'inherit',
40
+ background: 'transparent',
41
+ border: '1px solid color-mix(in srgb, currentColor 20%, transparent)',
42
+ },
43
+ digest: { fontFamily: 'ui-monospace, Menlo, monospace', fontSize: '12px', margin: '20px 0 0', opacity: 0.6 },
44
+ };
45
+ const subscribe = () => () => { };
46
+ /** Fallback for `error.tsx` and `global-error.tsx`. Details and Fix with AI show in development only. */
47
+ export function ErrorState({ error }) {
48
+ const isDev = process.env.NODE_ENV === 'development';
49
+ // Server snapshot is false, so hydration matches and the button appears right after.
50
+ const isEmbedded = useSyncExternalStore(subscribe, () => window !== window.parent, () => false);
51
+ const digest = error instanceof Error && 'digest' in error ? String(error.digest) : null;
52
+ const message = error instanceof Error ? error.message : String(error);
53
+ const fixWithAi = () => {
54
+ const detail = {
55
+ message,
56
+ digest,
57
+ stack: error instanceof Error ? error.stack ?? null : null,
58
+ };
59
+ window.dispatchEvent(new CustomEvent('reforma:fix-error', { detail }));
60
+ };
61
+ return (_jsx("main", { style: styles.main, children: _jsxs("div", { style: styles.card, children: [_jsx("h1", { style: styles.title, children: "Something went wrong" }), _jsx("p", { style: styles.message, children: "This page didn't load." }), isDev && message ? _jsx("pre", { style: styles.details, children: message }) : null, _jsxs("div", { style: styles.buttons, children: [_jsx("button", { type: "button", style: styles.button, onClick: () => window.location.reload(), children: "Reload" }), isDev && isEmbedded
62
+ ? _jsx("button", { type: "button", style: styles.secondary, onClick: fixWithAi, children: "Fix with AI" })
63
+ : null] }), digest ? _jsxs("p", { style: styles.digest, children: ["Error ID: ", digest] }) : null] }) }));
64
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { initAnalytics, track } from './analytics.js';
2
+ export { ErrorState } from './error-state.js';
2
3
  export { projectMetadata, projectRobots } from './metadata.js';
3
4
  export { SiteRoot, useMode } from './root.js';
5
+ export type { FixErrorDetail } from './error-state.js';
4
6
  export type { Appearance, ModeAppearances, ModeDocument, SystemModes } from './root.js';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { initAnalytics, track } from './analytics.js';
2
+ export { ErrorState } from './error-state.js';
2
3
  export { projectMetadata, projectRobots } from './metadata.js';
3
4
  export { SiteRoot, useMode } from './root.js';
@@ -1,6 +1,9 @@
1
- export declare function projectMetadata(fallback: {
1
+ export declare function projectMetadata(defaults: {
2
2
  title: string;
3
3
  description: string;
4
+ }, config: {
5
+ faviconUrl: string;
6
+ indexingEnabled: boolean;
4
7
  }): {
5
8
  title: {
6
9
  template: string;
@@ -18,7 +21,9 @@ export declare function projectMetadata(fallback: {
18
21
  follow: boolean;
19
22
  };
20
23
  };
21
- export declare function projectRobots(): {
24
+ export declare function projectRobots(config: {
25
+ indexingEnabled: boolean;
26
+ }): {
22
27
  rules: {
23
28
  userAgent: string;
24
29
  disallow: string;
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE;;QAMpE,QAAQ;QACR,OAAO;;;;QAIP,IAAI;;;;;;;;;EAQf;AAED,wBAAgB,aAAa;IAIrB,KAAK;;;;;;;EAKZ"}
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAC3B,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAChD,MAAM,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE;;QAOhD,QAAQ;QACR,OAAO;;;;QAIP,IAAI;;;;;;;;;EAQf;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,eAAe,EAAE,OAAO,CAAA;CAAE;IAI1D,KAAK;;;;;;;EAKZ"}
package/dist/metadata.js CHANGED
@@ -1,12 +1,12 @@
1
- export function projectMetadata(fallback) {
2
- const faviconUrl = process.env.REFORMA_FAVICON_URL || '/favicon.svg';
3
- const indexingOn = process.env.REFORMA_INDEXING !== '0';
1
+ export function projectMetadata(defaults, config) {
2
+ const faviconUrl = config.faviconUrl || '/favicon.svg';
3
+ const indexingOn = config.indexingEnabled;
4
4
  return {
5
5
  title: {
6
6
  template: '%s',
7
- default: process.env.REFORMA_DEFAULT_TITLE || fallback.title,
7
+ default: defaults.title,
8
8
  },
9
- description: process.env.REFORMA_DEFAULT_DESCRIPTION || fallback.description,
9
+ description: defaults.description,
10
10
  icons: {
11
11
  icon: faviconUrl.endsWith('.svg')
12
12
  ? { url: faviconUrl, type: 'image/svg+xml' }
@@ -17,8 +17,8 @@ export function projectMetadata(fallback) {
17
17
  : { index: false, follow: false },
18
18
  };
19
19
  }
20
- export function projectRobots() {
21
- const blocked = process.env.REFORMA_INDEXING === '0';
20
+ export function projectRobots(config) {
21
+ const blocked = !config.indexingEnabled;
22
22
  return {
23
23
  rules: {
24
24
  userAgent: '*',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reforma/site",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Visitor runtime for a Reforma site: mode, publish metadata, and the PostCSS url guard.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -44,17 +44,5 @@
44
44
  "peerDependencies": {
45
45
  "react": "^19.2.8",
46
46
  "react-dom": "^19.2.8"
47
- },
48
- "devDependencies": {
49
- "@reforma/config-typescript": "workspace:*",
50
- "@reforma/eslint-config": "workspace:*",
51
- "@types/node": "^24",
52
- "@types/react": "^19",
53
- "@types/react-dom": "^19",
54
- "happy-dom": "20.10.6",
55
- "react": "^19.2.8",
56
- "react-dom": "^19.2.8",
57
- "typescript": "^7",
58
- "vitest": "^5.0.1"
59
47
  }
60
48
  }