sanity-plugin-seofields 1.2.5 → 1.2.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.
Files changed (50) hide show
  1. package/README.md +465 -0
  2. package/dist/index.cjs +2604 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +422 -0
  5. package/dist/index.d.ts +339 -492
  6. package/dist/index.js +1284 -2013
  7. package/dist/index.js.map +1 -1
  8. package/dist/next.cjs +182 -0
  9. package/dist/next.cjs.map +1 -0
  10. package/dist/next.d.cts +241 -0
  11. package/dist/next.d.ts +202 -295
  12. package/dist/next.js +110 -70
  13. package/dist/next.js.map +1 -1
  14. package/dist/types-B91ena4g.d.cts +89 -0
  15. package/dist/types-B91ena4g.d.ts +89 -0
  16. package/package.json +46 -20
  17. package/dist/index.d.mts +0 -575
  18. package/dist/index.mjs +0 -3292
  19. package/dist/index.mjs.map +0 -1
  20. package/dist/next.d.mts +0 -334
  21. package/dist/next.mjs +0 -102
  22. package/dist/next.mjs.map +0 -1
  23. package/sanity.json +0 -8
  24. package/src/components/SeoHealthDashboard.tsx +0 -1568
  25. package/src/components/SeoHealthPane.tsx +0 -81
  26. package/src/components/SeoHealthTool.tsx +0 -11
  27. package/src/components/SeoPreview.tsx +0 -178
  28. package/src/components/meta/MetaDescription.tsx +0 -39
  29. package/src/components/meta/MetaTitle.tsx +0 -44
  30. package/src/components/openGraph/OgDescription.tsx +0 -46
  31. package/src/components/openGraph/OgTitle.tsx +0 -45
  32. package/src/components/twitter/twitterDescription.tsx +0 -45
  33. package/src/components/twitter/twitterTitle.tsx +0 -45
  34. package/src/helpers/SeoMetaTags.tsx +0 -154
  35. package/src/helpers/seoMeta.ts +0 -283
  36. package/src/index.ts +0 -26
  37. package/src/next.ts +0 -12
  38. package/src/plugin.ts +0 -344
  39. package/src/schemas/index.ts +0 -121
  40. package/src/schemas/types/index.ts +0 -20
  41. package/src/schemas/types/metaAttribute/index.ts +0 -60
  42. package/src/schemas/types/metaTag/index.ts +0 -17
  43. package/src/schemas/types/openGraph/index.ts +0 -114
  44. package/src/schemas/types/robots/index.ts +0 -26
  45. package/src/schemas/types/twitter/index.ts +0 -108
  46. package/src/types.ts +0 -108
  47. package/src/utils/fieldsUtils.ts +0 -160
  48. package/src/utils/seoUtils.ts +0 -423
  49. package/src/utils/utils.ts +0 -9
  50. package/v2-incompatible.js +0 -11
@@ -0,0 +1,422 @@
1
+ import * as sanity from 'sanity';
2
+ import { SchemaTypeDefinition } from 'sanity';
3
+ import { D as DocumentWithSeoHealth } from './types-B91ena4g.cjs';
4
+ export { S as SeoHealthMetrics, a as SeoHealthStatus } from './types-B91ena4g.cjs';
5
+ import React from 'react';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
+ import { StructureBuilder, ComponentBuilder } from 'sanity/structure';
8
+
9
+ interface SeoFieldConfig {
10
+ title?: string;
11
+ description?: string;
12
+ }
13
+ type SeoFieldKeys = 'title' | 'description' | 'canonicalUrl' | 'metaImage' | 'keywords' | 'metaAttributes' | 'robots';
14
+ type openGraphFieldKeys = 'openGraphUrl' | 'openGraphTitle' | 'openGraphDescription' | 'openGraphSiteName' | 'openGraphType' | 'openGraphImageType' | 'openGraphImage' | 'openGraphImageUrl';
15
+ type twitterFieldKeys = 'twitterCard' | 'twitterSite' | 'twitterCreator' | 'twitterTitle' | 'twitterDescription' | 'twitterImageType' | 'twitterImage' | 'twitterImageUrl';
16
+ type AllFieldKeys = SeoFieldKeys | openGraphFieldKeys | twitterFieldKeys;
17
+ type ValidHiddenFieldKeys = Exclude<AllFieldKeys, 'openGraphImageUrl' | 'twitterImageUrl' | 'openGraphImageType' | 'twitterImageType'>;
18
+ interface FieldVisibilityConfig {
19
+ hiddenFields?: ValidHiddenFieldKeys[];
20
+ }
21
+ interface SeoFieldsPluginConfig {
22
+ /**
23
+ * Enable or configure the SEO preview feature.
24
+ * If set to `true`, the SEO preview will be enabled with default settings.
25
+ * If set to an object, you can provide a custom prefix function to modify the URL prefix in the preview.
26
+ * The prefix function receives the current document as an argument and should return a string.
27
+ * Example:
28
+ * ```
29
+ * seoPreview: {
30
+ * prefix: (doc) => `/${doc.slug?.current || 'untitled'}`
31
+ * }
32
+ * ```
33
+ */
34
+ seoPreview?: boolean | {
35
+ prefix?: (doc: {
36
+ _type?: string;
37
+ } & Record<string, unknown>) => string;
38
+ };
39
+ /**
40
+ * A mapping of field keys to their configuration settings.
41
+ * This allows customization of field titles and descriptions.
42
+ * For example, to change the title of the 'title' field:
43
+ */
44
+ fieldOverrides?: Partial<Record<AllFieldKeys, SeoFieldConfig>>;
45
+ /**
46
+ * A mapping of document types to field visibility configurations.
47
+ * This allows you to specify which fields should be hidden for specific document types.
48
+ */
49
+ fieldVisibility?: Record<string, FieldVisibilityConfig>;
50
+ /**
51
+ * A list of fields that should be hidden by default in all document types.
52
+ * This can be overridden by specific document type settings in `fieldVisibility`.
53
+ */
54
+ defaultHiddenFields?: ValidHiddenFieldKeys[];
55
+ /**
56
+ * The base URL of your website, used for generating full URLs in the SEO preview.
57
+ * Defaults to 'https://www.example.com' if not provided.
58
+ */
59
+ baseUrl?: string;
60
+ /**
61
+ * Enable or configure the SEO Health Dashboard tool.
62
+ * If set to `true`, the dashboard is enabled with all defaults.
63
+ * If set to an object, you can customise the tool and dashboard settings.
64
+ * Defaults to `true`.
65
+ * Example:
66
+ * ```
67
+ * healthDashboard: {
68
+ * toolTitle: 'SEO Overview', // Studio nav tab label
69
+ * content: {
70
+ * icon: '🔍', // Emoji icon shown before the page heading
71
+ * title: 'My SEO Dashboard',// Page heading inside the tool (no emoji)
72
+ * description: 'Track SEO across all documents', // Subtitle under the heading
73
+ * },
74
+ * display: {
75
+ * typeColumn: false, // Hide the document type column (default: true)
76
+ * documentId: false, // Hide the document ID under titles (default: true)
77
+ * },
78
+ * query: {
79
+ * // Option 1 – filter by specific document types
80
+ * types: ['post', 'page'],
81
+ * // Option 2 – provide a full custom GROQ query (takes precedence over `types`)
82
+ * // Must return documents with at least: _id, _type, title, seo, _updatedAt
83
+ * groq: `*[seo != null && defined(slug.current)]{ _id, _type, title, slug, seo, _updatedAt }`,
84
+ * },
85
+ * }
86
+ * ```
87
+ */
88
+ healthDashboard?: boolean | {
89
+ tool?: {
90
+ title?: string;
91
+ name?: string;
92
+ };
93
+ toolTitle?: string;
94
+ content?: {
95
+ icon?: string;
96
+ title?: string;
97
+ description?: string;
98
+ /** Text shown while the license key is being verified. Defaults to "Verifying license…" */
99
+ loadingLicense?: string;
100
+ /** Text shown while documents are being fetched. Defaults to "Loading documents…" */
101
+ loadingDocuments?: string;
102
+ /** Text shown when the query returns zero results. Defaults to "No documents found" */
103
+ noDocuments?: string;
104
+ };
105
+ display?: {
106
+ typeColumn?: boolean;
107
+ documentId?: boolean;
108
+ };
109
+ query?: {
110
+ /**
111
+ * Limit the dashboard to specific document types.
112
+ * Example: `['post', 'page']`
113
+ */
114
+ types?: string[];
115
+ /**
116
+ * When using `types`, also require the `seo` field to be non-null.
117
+ * Set to `false` to include documents of those types even if `seo` is missing.
118
+ * Defaults to `true`.
119
+ */
120
+ requireSeo?: boolean;
121
+ /**
122
+ * Provide a fully custom GROQ query. Takes precedence over `types`.
123
+ * The query must return documents with at least: _id, _type, title, seo, _updatedAt
124
+ */
125
+ groq?: string;
126
+ };
127
+ /**
128
+ * The Sanity API version to use for the client (e.g. '2023-01-01').
129
+ * Defaults to '2023-01-01'.
130
+ */
131
+ apiVersion?: string;
132
+ /**
133
+ * License key for the SEO Health Dashboard pro feature.
134
+ * Obtain a license at https://sanity-plugin-seofields.thehardik.in
135
+ */
136
+ licenseKey?: string;
137
+ /**
138
+ * Map raw `_type` values to human-readable display labels.
139
+ * Used in both the Type column and the Type filter dropdown.
140
+ * Any type without an entry falls back to the raw `_type` string.
141
+ *
142
+ * @example
143
+ * typeLabels: { productDrug: 'Products', singleCondition: 'Condition' }
144
+ */
145
+ typeLabels?: Record<string, string>;
146
+ /**
147
+ * Controls how the document type is rendered in the Type column.
148
+ * - `'badge'` (default) — coloured pill
149
+ * - `'text'` — plain text, useful for dense layouts
150
+ */
151
+ typeColumnMode?: 'badge' | 'text';
152
+ /**
153
+ * The document field to use as the display title in the dashboard.
154
+ *
155
+ * - `string` — use this field for every document type (e.g. `'name'`)
156
+ * - `Record<string, string>` — per-type mapping; unmapped types fall back to `title`
157
+ *
158
+ * @example
159
+ * titleField: 'name'
160
+ *
161
+ * @example
162
+ * titleField: { post: 'title', product: 'name', category: 'label' }
163
+ */
164
+ titleField?: string | Record<string, string>;
165
+ /**
166
+ * Callback function to render a custom badge next to the document title.
167
+ * Receives the full document and should return badge data or undefined.
168
+ *
169
+ * @example
170
+ * docBadge: (doc) => {
171
+ * if (doc.services === 'NHS')
172
+ * return { label: 'NHS', bgColor: '#e0f2fe', textColor: '#0369a1' }
173
+ * if (doc.services === 'Private')
174
+ * return { label: 'Private', bgColor: '#fef3c7', textColor: '#92400e' }
175
+ * }
176
+ */
177
+ docBadge?: (doc: DocumentWithSeoHealth & Record<string, unknown>) => {
178
+ label: string;
179
+ bgColor?: string;
180
+ textColor?: string;
181
+ fontSize?: string;
182
+ } | undefined;
183
+ /**
184
+ * The `name` of the Sanity structure tool that contains the monitored documents.
185
+ * Required when you have multiple structure tools and the documents live in a
186
+ * non-default one. Clicking a title will navigate to
187
+ * `/{basePath}/{structureTool}/intent/edit/…` directly.
188
+ *
189
+ * @example
190
+ * structureTool: 'common'
191
+ */
192
+ structureTool?: string;
193
+ /**
194
+ * Enable preview/demo mode to show dummy data.
195
+ * Useful for testing, documentation, or showcasing the dashboard.
196
+ * When enabled, displays realistic sample documents with various SEO scores.
197
+ * Defaults to `false`.
198
+ *
199
+ * @example
200
+ * previewMode: true
201
+ */
202
+ previewMode?: boolean;
203
+ };
204
+ }
205
+ declare const seofields: sanity.Plugin<void | SeoFieldsPluginConfig>;
206
+
207
+ declare function seoFieldsSchema(config?: SeoFieldsPluginConfig): SchemaTypeDefinition;
208
+
209
+ declare function types(config?: SeoFieldsPluginConfig): SchemaTypeDefinition[];
210
+
211
+ declare const _default$2: {
212
+ type: "object";
213
+ name: "metaAttribute";
214
+ } & Omit<sanity.ObjectDefinition, "preview"> & {
215
+ preview?: sanity.PreviewConfig<{
216
+ attributeName: string;
217
+ attributeValueString: string;
218
+ attributeValueImage: string;
219
+ }, Record<"attributeName" | "attributeValueString" | "attributeValueImage", any>> | undefined;
220
+ };
221
+
222
+ declare const _default$1: {
223
+ type: "object";
224
+ name: "metaTag";
225
+ } & Omit<sanity.ObjectDefinition, "preview"> & {
226
+ preview?: sanity.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
227
+ };
228
+
229
+ declare function openGraph(config?: SeoFieldsPluginConfig): SchemaTypeDefinition;
230
+
231
+ declare const _default: {
232
+ type: "object";
233
+ name: "robots";
234
+ } & Omit<sanity.ObjectDefinition, "preview"> & {
235
+ preview?: sanity.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
236
+ };
237
+
238
+ declare function twitter(config?: SeoFieldsPluginConfig): SchemaTypeDefinition;
239
+
240
+ interface SeoHealthDashboardProps {
241
+ icon?: string;
242
+ title?: string;
243
+ description?: string;
244
+ showTypeColumn?: boolean;
245
+ showDocumentId?: boolean;
246
+ /**
247
+ * Limit the dashboard to specific document type names.
248
+ * If both queryTypes and customQuery are provided, customQuery takes precedence.
249
+ */
250
+ queryTypes?: string[];
251
+ /**
252
+ * When using `queryTypes`, also filter by `seo != null`.
253
+ * Set to `false` to include documents of those types even without an seo field.
254
+ * Defaults to `true`.
255
+ */
256
+ queryRequireSeo?: boolean;
257
+ /**
258
+ * A fully custom GROQ query used to fetch documents.
259
+ * Must return objects with at least: _id, _type, title, seo, _updatedAt
260
+ * Takes precedence over queryTypes.
261
+ */
262
+ customQuery?: string;
263
+ /**
264
+ * The Sanity API version to use for the client (e.g. '2023-01-01').
265
+ * Defaults to '2023-01-01'.
266
+ */
267
+ apiVersion?: string;
268
+ /**
269
+ * License key for the SEO Health Dashboard.
270
+ * Obtain a key at https://sanity-plugin-seofields.thehardik.in
271
+ */
272
+ licenseKey?: string;
273
+ /**
274
+ * Map raw `_type` values to human-readable display labels used in the
275
+ * Type column and the Type filter dropdown.
276
+ * Any type without an entry falls back to the raw `_type` string.
277
+ *
278
+ * @example
279
+ * typeLabels={{ productDrug: 'Products', singleCondition: 'Condition' }}
280
+ */
281
+ typeLabels?: Record<string, string>;
282
+ /**
283
+ * Controls how the type is rendered in the Type column.
284
+ * - `'badge'` (default) — coloured pill, consistent with score badges
285
+ * - `'text'` — plain text, useful for dense layouts
286
+ */
287
+ typeColumnMode?: 'badge' | 'text';
288
+ /**
289
+ * The document field to use as the display title.
290
+ *
291
+ * - `string` — use this field for every document type (e.g. `'name'`)
292
+ * - `Record<string, string>` — per-type mapping; unmapped types fall back to `title`
293
+ *
294
+ * @example
295
+ * // Same field for all types
296
+ * titleField: 'name'
297
+ *
298
+ * @example
299
+ * // Different field per type
300
+ * titleField: { post: 'title', product: 'name', category: 'label' }
301
+ */
302
+ titleField?: string | Record<string, string>;
303
+ /**
304
+ * Callback function to render a custom badge next to the document title.
305
+ * Receives the full document and should return badge data or undefined.
306
+ *
307
+ * @example
308
+ * docBadge: (doc) => {
309
+ * if (doc.services === 'NHS')
310
+ * return { label: 'NHS', bgColor: '#e0f2fe', textColor: '#0369a1' }
311
+ * if (doc.services === 'Private')
312
+ * return { label: 'Private', bgColor: '#fef3c7', textColor: '#92400e' }
313
+ * }
314
+ */
315
+ docBadge?: (doc: DocumentWithSeoHealth & Record<string, unknown>) => {
316
+ label: string;
317
+ bgColor?: string;
318
+ textColor?: string;
319
+ fontSize?: string;
320
+ } | undefined;
321
+ /**
322
+ * Custom text shown while the license key is being verified.
323
+ * Defaults to `"Verifying license…"`.
324
+ */
325
+ loadingLicense?: React.ReactNode;
326
+ /**
327
+ * Custom text shown while documents are being fetched.
328
+ * Defaults to `"Loading documents…"`.
329
+ */
330
+ loadingDocuments?: React.ReactNode;
331
+ /**
332
+ * Custom text shown when the query returns zero results.
333
+ * Defaults to `"No documents found"`.
334
+ */
335
+ noDocuments?: React.ReactNode;
336
+ /**
337
+ * Enable preview/demo mode to show dummy data.
338
+ * Useful for testing, documentation, or showcasing the dashboard.
339
+ * When enabled, displays realistic sample documents with various SEO scores.
340
+ * Defaults to `false`.
341
+ */
342
+ previewMode?: boolean;
343
+ /**
344
+ * When `true`, clicking a document title opens the document editor as a split
345
+ * pane to the right, keeping the SEO Health pane visible on the left.
346
+ * This uses Sanity's pane router and requires the component to be rendered
347
+ * inside a desk-structure pane context (i.e. via `createSeoHealthPane`).
348
+ *
349
+ * When `false` (default), clicking navigates to the document via the standard
350
+ * intent-link system (full navigation).
351
+ *
352
+ * This is set to `true` automatically by `createSeoHealthPane`.
353
+ */
354
+ openInPane?: boolean;
355
+ /**
356
+ * The `name` of the Sanity structure tool that contains the monitored documents.
357
+ * When provided, clicking a document title navigates directly to that tool's
358
+ * intent URL (`/{basePath}/{structureTool}/intent/edit/id=…;type=…/`) instead of
359
+ * using the generic intent resolver, which always picks the first registered tool.
360
+ *
361
+ * Required when you have multiple structure tools and the documents live in a
362
+ * non-default one (e.g. `name: 'common'`).
363
+ *
364
+ * @example
365
+ * structureTool: 'common'
366
+ */
367
+ structureTool?: string;
368
+ }
369
+ declare const SeoHealthDashboard: React.FC<SeoHealthDashboardProps>;
370
+
371
+ /**
372
+ * Sanity Tool component for the SEO Health Dashboard
373
+ * This component wraps the SeoHealthDashboard for use as a custom tool in Sanity Studio
374
+ */
375
+ declare const SeoHealthTool: (props: SeoHealthDashboardProps) => react_jsx_runtime.JSX.Element;
376
+
377
+ /**
378
+ * Options accepted by `createSeoHealthPane`.
379
+ * All props from `SeoHealthDashboardProps` are supported.
380
+ *
381
+ * `licenseKey` is **required** — the dashboard will not render without it.
382
+ */
383
+ interface SeoHealthPaneOptions extends Omit<SeoHealthDashboardProps, 'customQuery'> {
384
+ /** Required license key (format: `SEOF-XXXX-XXXX-XXXX`). */
385
+ licenseKey: string;
386
+ /**
387
+ * A fully custom GROQ query used to fetch documents for the dashboard.
388
+ * The query must return documents with at least: `_id`, `_type`, `title`, `seo`, `_updatedAt`.
389
+ *
390
+ * Takes precedence over `queryTypes` when both are provided.
391
+ *
392
+ * @example
393
+ * query: `*[_type in ["post","page"] && defined(seo)]{ _id, _type, title, slug, seo, _updatedAt }`
394
+ */
395
+ query?: string;
396
+ }
397
+ /**
398
+ * Creates a desk-structure pane for the SEO Health Dashboard.
399
+ *
400
+ * Returns a **`ComponentBuilder`** with a built-in `.child()` resolver so that
401
+ * clicking any document row opens the document editor as a split pane to the right.
402
+ *
403
+ * Use it **directly** as the `.child()` value — do **not** wrap it in `S.component()`.
404
+ *
405
+ * ```ts
406
+ * // sanity.config.ts
407
+ * structure: (S) =>
408
+ * S.list().items([
409
+ * S.listItem()
410
+ * .title('SEO Health')
411
+ * .child(
412
+ * createSeoHealthPane(S, {
413
+ * licenseKey: 'SEOF-XXXX-XXXX-XXXX',
414
+ * query: `*[_type == "post" && defined(seo)]{ _id, _type, title, slug, seo, _updatedAt }`,
415
+ * })
416
+ * ),
417
+ * ])
418
+ * ```
419
+ */
420
+ declare function createSeoHealthPane(optionsOrS: StructureBuilder, optionsWhenS: SeoHealthPaneOptions): ComponentBuilder;
421
+
422
+ export { type AllFieldKeys, DocumentWithSeoHealth, type FieldVisibilityConfig, type SeoFieldConfig, type SeoFieldKeys, type SeoFieldsPluginConfig, SeoHealthDashboard, type SeoHealthPaneOptions, SeoHealthTool, type ValidHiddenFieldKeys, types as allSchemas, createSeoHealthPane, seofields as default, _default$2 as metaAttributeSchema, _default$1 as metaTagSchema, type openGraphFieldKeys, openGraph as openGraphSchema, _default as robotsSchema, seoFieldsSchema, type twitterFieldKeys, twitter as twitterSchema };