@schemasentry/react 0.8.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Schema Sentry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @schemasentry/react
2
+
3
+ React components for Schema Sentry. Works with Next.js Pages Router and other React frameworks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @schemasentry/react @schemasentry/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Next.js Pages Router
14
+
15
+ In your `_document.js`:
16
+
17
+ ```jsx
18
+ import { Html, Head, Main, NextScripts, Script } from "next/document";
19
+ import { Schema } from "@schemasentry/react";
20
+ import { Organization, WebSite } from "@schemasentry/core";
21
+
22
+ export default function Document() {
23
+ return (
24
+ <Html lang="en">
25
+ <Head />
26
+ <body>
27
+ {/* Global schema on every page */}
28
+ <Schema
29
+ data={[
30
+ Organization({ name: "My Company", url: "https://example.com" }),
31
+ WebSite({ name: "My Site", url: "https://example.com" })
32
+ ]}
33
+ />
34
+ <Main />
35
+ <NextScripts />
36
+ </body>
37
+ </Html>
38
+ );
39
+ }
40
+ ```
41
+
42
+ In a specific page (e.g., `pages/about.js`):
43
+
44
+ ```jsx
45
+ import { Schema } from "@schemasentry/react";
46
+ import { Organization, FAQPage } from "@schemasentry/core";
47
+
48
+ export default function AboutPage() {
49
+ return (
50
+ <div>
51
+ <h1>About Us</h1>
52
+ <Schema
53
+ data={FAQPage({
54
+ questions: [
55
+ { question: "What is your return policy?", answer: "30 days" },
56
+ { question: "Do you ship internationally?", answer: "Yes, worldwide" }
57
+ ]
58
+ })}
59
+ />
60
+ </div>
61
+ );
62
+ }
63
+ ```
64
+
65
+ ### Other React Frameworks
66
+
67
+ Works with any React framework that supports SSR:
68
+
69
+ ```jsx
70
+ import { Schema } from "@schemasentry/react";
71
+ import { Article } from "@schemasentry/core";
72
+
73
+ function ArticlePage({ title, content }) {
74
+ return (
75
+ <article>
76
+ <Schema
77
+ data={Article({
78
+ headline: title,
79
+ author: { name: "John Doe" },
80
+ datePublished: "2024-01-15",
81
+ url: "https://example.com/article"
82
+ })}
83
+ />
84
+ <h1>{title}</h1>
85
+ <p>{content}</p>
86
+ </article>
87
+ );
88
+ }
89
+ ```
90
+
91
+ ## API
92
+
93
+ ### `<Schema />`
94
+
95
+ Renders a `<script type="application/ld+json">` tag with the schema data.
96
+
97
+ ```tsx
98
+ import { Schema } from "@schemasentry/react";
99
+ import { Product } from "@schemasentry/core";
100
+
101
+ <Schema
102
+ data={Product({
103
+ name: "Widget",
104
+ description: "A great widget",
105
+ url: "https://example.com/widget"
106
+ })}
107
+ id="product-schema" // optional: adds id attribute
108
+ nonce="abc123" // optional: for CSP nonce
109
+ />
110
+ ```
111
+
112
+ ## TypeScript
113
+
114
+ Full TypeScript support out of the box. All schema builders from `@schemasentry/core` are re-exported.
@@ -0,0 +1,13 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { SchemaNode } from '@schemasentry/core';
3
+ export * from '@schemasentry/core';
4
+ export { stableStringify } from '@schemasentry/core';
5
+
6
+ type SchemaProps = {
7
+ data: SchemaNode | SchemaNode[];
8
+ id?: string;
9
+ nonce?: string;
10
+ };
11
+ declare const Schema: ({ data, id, nonce }: SchemaProps) => react_jsx_runtime.JSX.Element;
12
+
13
+ export { Schema, type SchemaProps };
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ // src/index.tsx
2
+ import { stableStringify } from "@schemasentry/core";
3
+ import { stableStringify as stableStringify2 } from "@schemasentry/core";
4
+ export * from "@schemasentry/core";
5
+ import { jsx } from "react/jsx-runtime";
6
+ var Schema = ({ data, id, nonce }) => {
7
+ const blocks = Array.isArray(data) ? data : [data];
8
+ const payload = blocks.length === 1 ? blocks[0] : blocks;
9
+ const json = stableStringify(payload);
10
+ return /* @__PURE__ */ jsx(
11
+ "script",
12
+ {
13
+ id,
14
+ nonce,
15
+ type: "application/ld+json",
16
+ dangerouslySetInnerHTML: { __html: json }
17
+ }
18
+ );
19
+ };
20
+ export {
21
+ Schema,
22
+ stableStringify2 as stableStringify
23
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@schemasentry/react",
3
+ "version": "0.8.0",
4
+ "description": "React components for Schema Sentry - works with Next.js Pages Router and other React frameworks.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/arindamdawn/schema-sentry.git",
16
+ "directory": "packages/react"
17
+ },
18
+ "homepage": "https://github.com/arindamdawn/schema-sentry#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/arindamdawn/schema-sentry/issues"
21
+ },
22
+ "keywords": [
23
+ "schema",
24
+ "json-ld",
25
+ "structured-data",
26
+ "seo",
27
+ "react",
28
+ "nextjs"
29
+ ],
30
+ "peerDependencies": {
31
+ "react": ">=18"
32
+ },
33
+ "dependencies": {
34
+ "@schemasentry/core": "0.8.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup src/index.tsx --format esm --dts --clean --tsconfig tsconfig.build.json"
41
+ }
42
+ }