@reforma/site 1.0.0 → 1.0.2

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.
@@ -12,6 +12,7 @@ type TrackOptions = {
12
12
  /**
13
13
  * Start first-party pageview collection for a published Reforma site.
14
14
  * Reads the project site config. Only the first call installs history hooks.
15
+ * In the Reforma editor's canvas it reports the address to the editor and counts nothing.
15
16
  */
16
17
  export declare function initAnalytics(config: {
17
18
  analyticsEnabled: boolean;
@@ -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;;;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"}
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;AAcF;;;;GAIG;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,CAoDN;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CA6DpE"}
package/dist/analytics.js CHANGED
@@ -1,3 +1,7 @@
1
+ /** The Reforma editor names its canvas iframe this; the site checks it because it cannot see the parent's origin. */
2
+ const EDITOR_FRAME_NAME = 'reforma-editor';
3
+ /** What the editor listens for to follow the site's address. */
4
+ const LOCATION_MESSAGE = 'reforma:location';
1
5
  let started = false;
2
6
  let enabled = false;
3
7
  let writeKey = '';
@@ -7,6 +11,7 @@ let unhook = null;
7
11
  /**
8
12
  * Start first-party pageview collection for a published Reforma site.
9
13
  * Reads the project site config. Only the first call installs history hooks.
14
+ * In the Reforma editor's canvas it reports the address to the editor and counts nothing.
10
15
  */
11
16
  export function initAnalytics(config, options = {}) {
12
17
  if (typeof window === 'undefined') {
@@ -22,6 +27,16 @@ export function initAnalytics(config, options = {}) {
22
27
  return;
23
28
  }
24
29
  started = true;
30
+ if (window.name === EDITOR_FRAME_NAME && window.parent !== window) {
31
+ enabled = false;
32
+ const report = () => {
33
+ // nosemgrep: javascript.browser.security.wildcard-postmessage-configuration.wildcard-postmessage-configuration -- only the page path, and the site cannot know the editor's origin
34
+ window.parent.postMessage({ type: LOCATION_MESSAGE, pathname: window.location.pathname }, '*');
35
+ };
36
+ report();
37
+ unhook = installHistoryHook(report);
38
+ return;
39
+ }
25
40
  enabled = config.analyticsEnabled;
26
41
  writeKey = config.analyticsWriteKey.trim();
27
42
  endpoint = config.analyticsEndpoint.trim();
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  export { initAnalytics, track } from './analytics.js';
2
2
  export { ErrorState } from './error-state.js';
3
3
  export { projectMetadata, projectRobots } from './metadata.js';
4
+ export { SiteRoot } from './root.js';
5
+ export { useTheme as useMode, useTheme } from 'next-themes';
4
6
  export type { FixErrorDetail } from './error-state.js';
7
+ export type { ModeDocument } from './root.js';
5
8
  //# 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,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,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,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5D,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export { initAnalytics, track } from './analytics.js';
2
2
  export { ErrorState } from './error-state.js';
3
3
  export { projectMetadata, projectRobots } from './metadata.js';
4
+ export { SiteRoot } from './root.js';
5
+ // `useMode` is the pre-1.0 name, kept for older starters' sonner.tsx.
6
+ export { useTheme as useMode, useTheme } from 'next-themes';
package/dist/root.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type ReactNode } from 'react';
2
+ /** The project's generated `.reforma/tokens/.generated/modes.json`. */
3
+ export type ModeDocument = {
4
+ default: string;
5
+ modifiers: {
6
+ name: string;
7
+ contexts: string[];
8
+ }[];
9
+ };
10
+ /** Mounts next-themes on `data-theme` with the token modes, which the generated token CSS selects. */
11
+ export declare function SiteRoot({ children, modes }: {
12
+ children: ReactNode;
13
+ modes: ModeDocument;
14
+ }): import("react").JSX.Element;
15
+ //# sourceMappingURL=root.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3D,uEAAuE;AACvE,MAAM,MAAM,YAAY,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;CACrD,CAAC;AAeF,sGAAsG;AACtG,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,+BAYzF"}
package/dist/root.js ADDED
@@ -0,0 +1,19 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { ThemeProvider, useTheme } from 'next-themes';
4
+ import { useEffect, useMemo } from 'react';
5
+ /** next-themes keeps a stored theme the tokens no longer have (renamed or deleted); fall back to the default mode. */
6
+ function DropRemovedTheme({ themes, defaultTheme }) {
7
+ const { theme, setTheme } = useTheme();
8
+ useEffect(() => {
9
+ if (theme && theme !== 'system' && !themes.includes(theme)) {
10
+ setTheme(defaultTheme);
11
+ }
12
+ }, [theme, setTheme, themes, defaultTheme]);
13
+ return null;
14
+ }
15
+ /** Mounts next-themes on `data-theme` with the token modes, which the generated token CSS selects. */
16
+ export function SiteRoot({ children, modes }) {
17
+ const themes = useMemo(() => modes.modifiers.find(modifier => modifier.name === 'mode')?.contexts ?? [], [modes]);
18
+ return (_jsxs(ThemeProvider, { attribute: "data-theme", themes: themes, defaultTheme: modes.default, disableTransitionOnChange: true, children: [_jsx(DropRemovedTheme, { themes: themes, defaultTheme: modes.default }), children] }));
19
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reforma/site",
3
- "version": "1.0.0",
4
- "description": "Visitor runtime for a Reforma site: publish metadata, analytics, and the PostCSS url guard.",
3
+ "version": "1.0.2",
4
+ "description": "Visitor runtime for a Reforma site: theme modes, publish metadata, analytics, and the PostCSS url guard.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
7
7
  "author": "Reforma, Inc. <dev@reforma.ai>",
@@ -41,6 +41,9 @@
41
41
  "lint": "eslint src",
42
42
  "lint:fix": "eslint src --fix"
43
43
  },
44
+ "dependencies": {
45
+ "next-themes": "^0.4.6"
46
+ },
44
47
  "peerDependencies": {
45
48
  "react": "^19.2.8",
46
49
  "react-dom": "^19.2.8"