@foundrykit/seo-plugin 0.0.0-stage → 0.3.1

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 (71) hide show
  1. package/README.md +270 -2
  2. package/dist/components/JsonLdEditor.d.ts +2 -0
  3. package/dist/components/JsonLdEditor.js +1184 -0
  4. package/dist/components/JsonLdEditor.js.map +1 -0
  5. package/dist/components/JsonLdTemplateRowLabel.d.ts +2 -0
  6. package/dist/components/JsonLdTemplateRowLabel.js +12 -0
  7. package/dist/components/JsonLdTemplateRowLabel.js.map +1 -0
  8. package/dist/components/MetaDescriptionComponent.d.ts +8 -0
  9. package/dist/components/MetaDescriptionComponent.js +101 -0
  10. package/dist/components/MetaDescriptionComponent.js.map +1 -0
  11. package/dist/components/MetaTitleComponent.d.ts +9 -0
  12. package/dist/components/MetaTitleComponent.js +193 -0
  13. package/dist/components/MetaTitleComponent.js.map +1 -0
  14. package/dist/components/OverviewComponent.d.ts +8 -0
  15. package/dist/components/OverviewComponent.js +64 -0
  16. package/dist/components/OverviewComponent.js.map +1 -0
  17. package/dist/components/PreviewComponent.d.ts +8 -0
  18. package/dist/components/PreviewComponent.js +51 -0
  19. package/dist/components/PreviewComponent.js.map +1 -0
  20. package/dist/exports/client.d.ts +6 -0
  21. package/dist/exports/client.js +8 -0
  22. package/dist/exports/client.js.map +1 -0
  23. package/dist/exports/next.d.ts +2 -0
  24. package/dist/exports/next.js +3 -0
  25. package/dist/exports/next.js.map +1 -0
  26. package/dist/exports/rsc.d.ts +1 -0
  27. package/dist/exports/rsc.js +5 -0
  28. package/dist/exports/rsc.js.map +1 -0
  29. package/dist/fields.d.ts +67 -0
  30. package/dist/fields.js +220 -0
  31. package/dist/fields.js.map +1 -0
  32. package/dist/global.d.ts +6 -0
  33. package/dist/global.js +93 -0
  34. package/dist/global.js.map +1 -0
  35. package/dist/helpers.d.ts +44 -0
  36. package/dist/helpers.js +23 -0
  37. package/dist/helpers.js.map +1 -0
  38. package/dist/helpers.test.d.ts +1 -0
  39. package/dist/helpers.test.js +234 -0
  40. package/dist/helpers.test.js.map +1 -0
  41. package/dist/hooks/autoAlternates.d.ts +18 -0
  42. package/dist/hooks/autoAlternates.js +63 -0
  43. package/dist/hooks/autoAlternates.js.map +1 -0
  44. package/dist/hooks/autoAlternates.test.d.ts +1 -0
  45. package/dist/hooks/autoAlternates.test.js +225 -0
  46. package/dist/hooks/autoAlternates.test.js.map +1 -0
  47. package/dist/hooks/generateMeta.d.ts +17 -0
  48. package/dist/hooks/generateMeta.js +58 -0
  49. package/dist/hooks/generateMeta.js.map +1 -0
  50. package/dist/hooks/generateMeta.test.d.ts +1 -0
  51. package/dist/hooks/generateMeta.test.js +132 -0
  52. package/dist/hooks/generateMeta.test.js.map +1 -0
  53. package/dist/hooks/ogImageGenerator.d.ts +19 -0
  54. package/dist/hooks/ogImageGenerator.js +96 -0
  55. package/dist/hooks/ogImageGenerator.js.map +1 -0
  56. package/dist/index.d.ts +87 -0
  57. package/dist/index.js +269 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/jsonld.d.ts +83 -0
  60. package/dist/jsonld.js +179 -0
  61. package/dist/jsonld.js.map +1 -0
  62. package/dist/jsonld.test.d.ts +1 -0
  63. package/dist/jsonld.test.js +214 -0
  64. package/dist/jsonld.test.js.map +1 -0
  65. package/dist/metadata.d.ts +53 -0
  66. package/dist/metadata.js +114 -0
  67. package/dist/metadata.js.map +1 -0
  68. package/dist/metadata.test.d.ts +1 -0
  69. package/dist/metadata.test.js +286 -0
  70. package/dist/metadata.test.js.map +1 -0
  71. package/package.json +99 -3
@@ -0,0 +1,1184 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useConfig, useField } from '@payloadcms/ui';
4
+ import { useCallback, useEffect, useReducer, useRef, useState } from 'react';
5
+ // ---------------------------------------------------------------------------
6
+ // Helpers to build JSON-LD from form state
7
+ // ---------------------------------------------------------------------------
8
+ function buildJsonLd(state) {
9
+ if (state.schemaType === 'None') return null;
10
+ const base = {
11
+ '@context': 'https://schema.org',
12
+ '@type': state.schemaType
13
+ };
14
+ if (state.schemaType === 'WebPage') {
15
+ return {
16
+ ...base,
17
+ ...state.webName && {
18
+ name: state.webName
19
+ },
20
+ ...state.webUrl && {
21
+ url: state.webUrl
22
+ },
23
+ ...state.webDescription && {
24
+ description: state.webDescription
25
+ },
26
+ ...state.webImage && {
27
+ image: state.webImage
28
+ },
29
+ ...state.webDatePublished && {
30
+ datePublished: state.webDatePublished
31
+ },
32
+ ...state.webDateModified && {
33
+ dateModified: state.webDateModified
34
+ },
35
+ ...state.webBreadcrumb && {
36
+ breadcrumb: state.webBreadcrumb
37
+ }
38
+ };
39
+ }
40
+ if (state.schemaType === 'Article') {
41
+ return {
42
+ ...base,
43
+ ...state.articleHeadline && {
44
+ headline: state.articleHeadline
45
+ },
46
+ ...state.articleUrl && {
47
+ url: state.articleUrl
48
+ },
49
+ ...state.articleDescription && {
50
+ description: state.articleDescription
51
+ },
52
+ ...state.articleImage && {
53
+ image: state.articleImage
54
+ },
55
+ ...state.articleDatePublished && {
56
+ datePublished: state.articleDatePublished
57
+ },
58
+ ...state.articleDateModified && {
59
+ dateModified: state.articleDateModified
60
+ },
61
+ ...state.articleBody && {
62
+ articleBody: state.articleBody
63
+ },
64
+ ...state.articleAuthorName && {
65
+ author: {
66
+ '@type': 'Person',
67
+ name: state.articleAuthorName,
68
+ ...state.articleAuthorUrl && {
69
+ url: state.articleAuthorUrl
70
+ }
71
+ }
72
+ },
73
+ ...state.articlePublisherName && {
74
+ publisher: {
75
+ '@type': 'Organization',
76
+ name: state.articlePublisherName,
77
+ ...state.articlePublisherLogo && {
78
+ logo: {
79
+ '@type': 'ImageObject',
80
+ url: state.articlePublisherLogo
81
+ }
82
+ }
83
+ }
84
+ }
85
+ };
86
+ }
87
+ if (state.schemaType === 'Product') {
88
+ const hasOffer = state.productOffersPrice || state.productOffersCurrency || state.productOffersAvailability || state.productOffersUrl;
89
+ return {
90
+ ...base,
91
+ ...state.productName && {
92
+ name: state.productName
93
+ },
94
+ ...state.productUrl && {
95
+ url: state.productUrl
96
+ },
97
+ ...state.productDescription && {
98
+ description: state.productDescription
99
+ },
100
+ ...state.productImage && {
101
+ image: state.productImage
102
+ },
103
+ ...state.productSku && {
104
+ sku: state.productSku
105
+ },
106
+ ...state.productBrand && {
107
+ brand: {
108
+ '@type': 'Brand',
109
+ name: state.productBrand
110
+ }
111
+ },
112
+ ...hasOffer && {
113
+ offers: {
114
+ '@type': 'Offer',
115
+ ...state.productOffersPrice && {
116
+ price: state.productOffersPrice
117
+ },
118
+ ...state.productOffersCurrency && {
119
+ priceCurrency: state.productOffersCurrency
120
+ },
121
+ ...state.productOffersAvailability && {
122
+ availability: state.productOffersAvailability
123
+ },
124
+ ...state.productOffersUrl && {
125
+ url: state.productOffersUrl
126
+ }
127
+ }
128
+ }
129
+ };
130
+ }
131
+ if (state.schemaType === 'Organization') {
132
+ const sameAs = state.orgSameAs.split('\n').map((s)=>s.trim()).filter(Boolean);
133
+ return {
134
+ ...base,
135
+ ...state.orgName && {
136
+ name: state.orgName
137
+ },
138
+ ...state.orgUrl && {
139
+ url: state.orgUrl
140
+ },
141
+ ...state.orgDescription && {
142
+ description: state.orgDescription
143
+ },
144
+ ...state.orgEmail && {
145
+ email: state.orgEmail
146
+ },
147
+ ...state.orgTelephone && {
148
+ telephone: state.orgTelephone
149
+ },
150
+ ...state.orgLogo && {
151
+ logo: {
152
+ '@type': 'ImageObject',
153
+ url: state.orgLogo
154
+ }
155
+ },
156
+ ...sameAs.length > 0 && {
157
+ sameAs
158
+ }
159
+ };
160
+ }
161
+ if (state.schemaType === 'BreadcrumbList') {
162
+ const items = state.breadcrumbItems.filter((i)=>i.name && i.id);
163
+ return {
164
+ ...base,
165
+ itemListElement: items.map((item, index)=>({
166
+ '@type': 'ListItem',
167
+ item: item.id,
168
+ name: item.name,
169
+ position: index + 1
170
+ }))
171
+ };
172
+ }
173
+ return null;
174
+ }
175
+ // ---------------------------------------------------------------------------
176
+ // Parse existing JSON-LD value into form state
177
+ // ---------------------------------------------------------------------------
178
+ function parseJsonLd(value) {
179
+ const empty = {
180
+ schemaType: 'None',
181
+ articleAuthorName: '',
182
+ articleAuthorUrl: '',
183
+ articleBody: '',
184
+ articleDateModified: '',
185
+ articleDatePublished: '',
186
+ articleDescription: '',
187
+ articleHeadline: '',
188
+ articleImage: '',
189
+ articlePublisherLogo: '',
190
+ articlePublisherName: '',
191
+ articleUrl: '',
192
+ breadcrumbItems: [
193
+ {
194
+ id: '',
195
+ name: ''
196
+ }
197
+ ],
198
+ orgDescription: '',
199
+ orgEmail: '',
200
+ orgLogo: '',
201
+ orgName: '',
202
+ orgSameAs: '',
203
+ orgTelephone: '',
204
+ orgUrl: '',
205
+ productBrand: '',
206
+ productDescription: '',
207
+ productImage: '',
208
+ productName: '',
209
+ productOffersAvailability: '',
210
+ productOffersCurrency: '',
211
+ productOffersPrice: '',
212
+ productOffersUrl: '',
213
+ productSku: '',
214
+ productUrl: '',
215
+ webBreadcrumb: '',
216
+ webDateModified: '',
217
+ webDatePublished: '',
218
+ webDescription: '',
219
+ webImage: '',
220
+ webName: '',
221
+ webUrl: ''
222
+ };
223
+ if (!value || typeof value !== 'object') return empty;
224
+ const type = value['@type'];
225
+ if (!type) return empty;
226
+ if (type === 'WebPage') {
227
+ return {
228
+ ...empty,
229
+ schemaType: 'WebPage',
230
+ webBreadcrumb: value.breadcrumb ?? '',
231
+ webDateModified: value.dateModified ?? '',
232
+ webDatePublished: value.datePublished ?? '',
233
+ webDescription: value.description ?? '',
234
+ webImage: value.image ?? '',
235
+ webName: value.name ?? '',
236
+ webUrl: value.url ?? ''
237
+ };
238
+ }
239
+ if (type === 'Article') {
240
+ const author = value.author;
241
+ const publisher = value.publisher;
242
+ const logo = publisher?.logo;
243
+ return {
244
+ ...empty,
245
+ schemaType: 'Article',
246
+ articleAuthorName: author?.name ?? '',
247
+ articleAuthorUrl: author?.url ?? '',
248
+ articleBody: value.articleBody ?? '',
249
+ articleDateModified: value.dateModified ?? '',
250
+ articleDatePublished: value.datePublished ?? '',
251
+ articleDescription: value.description ?? '',
252
+ articleHeadline: value.headline ?? '',
253
+ articleImage: value.image ?? '',
254
+ articlePublisherLogo: logo?.url ?? '',
255
+ articlePublisherName: publisher?.name ?? '',
256
+ articleUrl: value.url ?? ''
257
+ };
258
+ }
259
+ if (type === 'Product') {
260
+ const brand = value.brand;
261
+ const offers = value.offers;
262
+ return {
263
+ ...empty,
264
+ schemaType: 'Product',
265
+ productBrand: brand?.name ?? '',
266
+ productDescription: value.description ?? '',
267
+ productImage: value.image ?? '',
268
+ productName: value.name ?? '',
269
+ productOffersAvailability: offers?.availability ?? '',
270
+ productOffersCurrency: offers?.priceCurrency ?? '',
271
+ productOffersPrice: offers?.price ?? '',
272
+ productOffersUrl: offers?.url ?? '',
273
+ productSku: value.sku ?? '',
274
+ productUrl: value.url ?? ''
275
+ };
276
+ }
277
+ if (type === 'Organization') {
278
+ const logo = value.logo;
279
+ const sameAs = value.sameAs;
280
+ return {
281
+ ...empty,
282
+ schemaType: 'Organization',
283
+ orgDescription: value.description ?? '',
284
+ orgEmail: value.email ?? '',
285
+ orgLogo: logo?.url ?? '',
286
+ orgName: value.name ?? '',
287
+ orgSameAs: sameAs?.join('\n') ?? '',
288
+ orgTelephone: value.telephone ?? '',
289
+ orgUrl: value.url ?? ''
290
+ };
291
+ }
292
+ if (type === 'BreadcrumbList') {
293
+ const items = value.itemListElement;
294
+ return {
295
+ ...empty,
296
+ schemaType: 'BreadcrumbList',
297
+ breadcrumbItems: items && items.length > 0 ? items.map((i)=>({
298
+ id: i.item ?? '',
299
+ name: i.name ?? ''
300
+ })) : [
301
+ {
302
+ id: '',
303
+ name: ''
304
+ }
305
+ ]
306
+ };
307
+ }
308
+ return empty;
309
+ }
310
+ // ---------------------------------------------------------------------------
311
+ // Reducer
312
+ // ---------------------------------------------------------------------------
313
+ function reducer(state, action) {
314
+ switch(action.type){
315
+ case 'SET_SCHEMA':
316
+ return {
317
+ ...state,
318
+ schemaType: action.value
319
+ };
320
+ case 'SET_FIELD':
321
+ return {
322
+ ...state,
323
+ [action.field]: action.value
324
+ };
325
+ case 'SET_BREADCRUMB':
326
+ {
327
+ const items = state.breadcrumbItems.map((item, i)=>i === action.index ? {
328
+ ...item,
329
+ [action.key]: action.value
330
+ } : item);
331
+ return {
332
+ ...state,
333
+ breadcrumbItems: items
334
+ };
335
+ }
336
+ case 'ADD_BREADCRUMB':
337
+ return {
338
+ ...state,
339
+ breadcrumbItems: [
340
+ ...state.breadcrumbItems,
341
+ {
342
+ id: '',
343
+ name: ''
344
+ }
345
+ ]
346
+ };
347
+ case 'REMOVE_BREADCRUMB':
348
+ return {
349
+ ...state,
350
+ breadcrumbItems: state.breadcrumbItems.length > 1 ? state.breadcrumbItems.filter((_, i)=>i !== action.index) : state.breadcrumbItems
351
+ };
352
+ case 'LOAD_TEMPLATE':
353
+ return parseJsonLd(action.value);
354
+ default:
355
+ return state;
356
+ }
357
+ }
358
+ // ---------------------------------------------------------------------------
359
+ // Shared input styles
360
+ // ---------------------------------------------------------------------------
361
+ const inputStyle = {
362
+ background: 'var(--theme-elevation-0)',
363
+ border: '1px solid var(--theme-elevation-150)',
364
+ borderRadius: 4,
365
+ color: 'var(--theme-text)',
366
+ fontFamily: 'inherit',
367
+ fontSize: 13,
368
+ padding: '6px 10px',
369
+ width: '100%'
370
+ };
371
+ const labelStyle = {
372
+ color: 'var(--theme-elevation-800)',
373
+ display: 'block',
374
+ fontSize: 12,
375
+ fontWeight: 600,
376
+ marginBottom: 4
377
+ };
378
+ const hintStyle = {
379
+ color: 'var(--theme-elevation-500)',
380
+ fontSize: 11,
381
+ marginTop: 2
382
+ };
383
+ const sectionStyle = {
384
+ borderTop: '1px solid var(--theme-elevation-100)',
385
+ marginTop: 16,
386
+ paddingTop: 16
387
+ };
388
+ const sectionLabelStyle = {
389
+ color: 'var(--theme-elevation-500)',
390
+ fontSize: 11,
391
+ fontWeight: 700,
392
+ letterSpacing: '0.06em',
393
+ marginBottom: 12,
394
+ textTransform: 'uppercase'
395
+ };
396
+ const gridStyle = {
397
+ display: 'grid',
398
+ gap: 12,
399
+ gridTemplateColumns: '1fr 1fr'
400
+ };
401
+ // ---------------------------------------------------------------------------
402
+ // Field helpers
403
+ // ---------------------------------------------------------------------------
404
+ function Field({ dispatch, field, hint, label, placeholder, state, textarea }) {
405
+ const value = state[field];
406
+ const handleChange = (e)=>dispatch({
407
+ field,
408
+ type: 'SET_FIELD',
409
+ value: e.target.value
410
+ });
411
+ return /*#__PURE__*/ _jsxs("div", {
412
+ children: [
413
+ /*#__PURE__*/ _jsx("label", {
414
+ style: labelStyle,
415
+ children: label
416
+ }),
417
+ textarea ? /*#__PURE__*/ _jsx("textarea", {
418
+ onChange: handleChange,
419
+ placeholder: placeholder,
420
+ rows: 3,
421
+ style: {
422
+ ...inputStyle,
423
+ resize: 'vertical'
424
+ },
425
+ value: value
426
+ }) : /*#__PURE__*/ _jsx("input", {
427
+ onChange: handleChange,
428
+ placeholder: placeholder,
429
+ style: inputStyle,
430
+ value: value
431
+ }),
432
+ hint && /*#__PURE__*/ _jsx("div", {
433
+ style: hintStyle,
434
+ children: hint
435
+ })
436
+ ]
437
+ });
438
+ }
439
+ // ---------------------------------------------------------------------------
440
+ // Schema-specific forms
441
+ // ---------------------------------------------------------------------------
442
+ function WebPageForm({ dispatch, state }) {
443
+ return /*#__PURE__*/ _jsxs("div", {
444
+ style: {
445
+ display: 'grid',
446
+ gap: 12
447
+ },
448
+ children: [
449
+ /*#__PURE__*/ _jsxs("div", {
450
+ style: gridStyle,
451
+ children: [
452
+ /*#__PURE__*/ _jsx(Field, {
453
+ dispatch: dispatch,
454
+ field: "webName",
455
+ label: "Page Name",
456
+ state: state
457
+ }),
458
+ /*#__PURE__*/ _jsx(Field, {
459
+ dispatch: dispatch,
460
+ field: "webUrl",
461
+ hint: "Full URL, e.g. https://example.com/page",
462
+ label: "Page URL",
463
+ state: state
464
+ })
465
+ ]
466
+ }),
467
+ /*#__PURE__*/ _jsx(Field, {
468
+ dispatch: dispatch,
469
+ field: "webDescription",
470
+ label: "Description",
471
+ state: state,
472
+ textarea: true
473
+ }),
474
+ /*#__PURE__*/ _jsxs("div", {
475
+ style: gridStyle,
476
+ children: [
477
+ /*#__PURE__*/ _jsx(Field, {
478
+ dispatch: dispatch,
479
+ field: "webImage",
480
+ hint: "Absolute URL of the featured image",
481
+ label: "Image URL",
482
+ state: state
483
+ }),
484
+ /*#__PURE__*/ _jsx(Field, {
485
+ dispatch: dispatch,
486
+ field: "webBreadcrumb",
487
+ label: "Breadcrumb",
488
+ state: state
489
+ })
490
+ ]
491
+ }),
492
+ /*#__PURE__*/ _jsxs("div", {
493
+ style: gridStyle,
494
+ children: [
495
+ /*#__PURE__*/ _jsx(Field, {
496
+ dispatch: dispatch,
497
+ field: "webDatePublished",
498
+ hint: "ISO 8601, e.g. 2024-01-15",
499
+ label: "Date Published",
500
+ placeholder: "2024-01-15",
501
+ state: state
502
+ }),
503
+ /*#__PURE__*/ _jsx(Field, {
504
+ dispatch: dispatch,
505
+ field: "webDateModified",
506
+ hint: "ISO 8601, e.g. 2024-06-01",
507
+ label: "Date Modified",
508
+ placeholder: "2024-06-01",
509
+ state: state
510
+ })
511
+ ]
512
+ })
513
+ ]
514
+ });
515
+ }
516
+ function ArticleForm({ dispatch, state }) {
517
+ return /*#__PURE__*/ _jsxs("div", {
518
+ style: {
519
+ display: 'grid',
520
+ gap: 12
521
+ },
522
+ children: [
523
+ /*#__PURE__*/ _jsx(Field, {
524
+ dispatch: dispatch,
525
+ field: "articleHeadline",
526
+ hint: "Max 110 characters recommended",
527
+ label: "Headline",
528
+ state: state
529
+ }),
530
+ /*#__PURE__*/ _jsxs("div", {
531
+ style: gridStyle,
532
+ children: [
533
+ /*#__PURE__*/ _jsx(Field, {
534
+ dispatch: dispatch,
535
+ field: "articleUrl",
536
+ label: "Article URL",
537
+ state: state
538
+ }),
539
+ /*#__PURE__*/ _jsx(Field, {
540
+ dispatch: dispatch,
541
+ field: "articleImage",
542
+ hint: "Absolute URL of the featured image",
543
+ label: "Image URL",
544
+ state: state
545
+ })
546
+ ]
547
+ }),
548
+ /*#__PURE__*/ _jsx(Field, {
549
+ dispatch: dispatch,
550
+ field: "articleDescription",
551
+ label: "Description",
552
+ state: state,
553
+ textarea: true
554
+ }),
555
+ /*#__PURE__*/ _jsxs("div", {
556
+ style: gridStyle,
557
+ children: [
558
+ /*#__PURE__*/ _jsx(Field, {
559
+ dispatch: dispatch,
560
+ field: "articleDatePublished",
561
+ hint: "ISO 8601, e.g. 2024-01-15",
562
+ label: "Date Published",
563
+ placeholder: "2024-01-15",
564
+ state: state
565
+ }),
566
+ /*#__PURE__*/ _jsx(Field, {
567
+ dispatch: dispatch,
568
+ field: "articleDateModified",
569
+ hint: "ISO 8601, e.g. 2024-06-01",
570
+ label: "Date Modified",
571
+ placeholder: "2024-06-01",
572
+ state: state
573
+ })
574
+ ]
575
+ }),
576
+ /*#__PURE__*/ _jsxs("div", {
577
+ style: sectionStyle,
578
+ children: [
579
+ /*#__PURE__*/ _jsx("div", {
580
+ style: sectionLabelStyle,
581
+ children: "Author"
582
+ }),
583
+ /*#__PURE__*/ _jsxs("div", {
584
+ style: gridStyle,
585
+ children: [
586
+ /*#__PURE__*/ _jsx(Field, {
587
+ dispatch: dispatch,
588
+ field: "articleAuthorName",
589
+ label: "Author Name",
590
+ state: state
591
+ }),
592
+ /*#__PURE__*/ _jsx(Field, {
593
+ dispatch: dispatch,
594
+ field: "articleAuthorUrl",
595
+ label: "Author URL",
596
+ state: state
597
+ })
598
+ ]
599
+ })
600
+ ]
601
+ }),
602
+ /*#__PURE__*/ _jsxs("div", {
603
+ style: sectionStyle,
604
+ children: [
605
+ /*#__PURE__*/ _jsx("div", {
606
+ style: sectionLabelStyle,
607
+ children: "Publisher"
608
+ }),
609
+ /*#__PURE__*/ _jsxs("div", {
610
+ style: gridStyle,
611
+ children: [
612
+ /*#__PURE__*/ _jsx(Field, {
613
+ dispatch: dispatch,
614
+ field: "articlePublisherName",
615
+ label: "Publisher Name",
616
+ state: state
617
+ }),
618
+ /*#__PURE__*/ _jsx(Field, {
619
+ dispatch: dispatch,
620
+ field: "articlePublisherLogo",
621
+ hint: "Absolute URL of the logo image",
622
+ label: "Publisher Logo URL",
623
+ state: state
624
+ })
625
+ ]
626
+ })
627
+ ]
628
+ })
629
+ ]
630
+ });
631
+ }
632
+ function ProductForm({ dispatch, state }) {
633
+ return /*#__PURE__*/ _jsxs("div", {
634
+ style: {
635
+ display: 'grid',
636
+ gap: 12
637
+ },
638
+ children: [
639
+ /*#__PURE__*/ _jsxs("div", {
640
+ style: gridStyle,
641
+ children: [
642
+ /*#__PURE__*/ _jsx(Field, {
643
+ dispatch: dispatch,
644
+ field: "productName",
645
+ label: "Product Name",
646
+ state: state
647
+ }),
648
+ /*#__PURE__*/ _jsx(Field, {
649
+ dispatch: dispatch,
650
+ field: "productBrand",
651
+ label: "Brand",
652
+ state: state
653
+ })
654
+ ]
655
+ }),
656
+ /*#__PURE__*/ _jsx(Field, {
657
+ dispatch: dispatch,
658
+ field: "productDescription",
659
+ label: "Description",
660
+ state: state,
661
+ textarea: true
662
+ }),
663
+ /*#__PURE__*/ _jsxs("div", {
664
+ style: gridStyle,
665
+ children: [
666
+ /*#__PURE__*/ _jsx(Field, {
667
+ dispatch: dispatch,
668
+ field: "productSku",
669
+ label: "SKU",
670
+ state: state
671
+ }),
672
+ /*#__PURE__*/ _jsx(Field, {
673
+ dispatch: dispatch,
674
+ field: "productUrl",
675
+ label: "Product URL",
676
+ state: state
677
+ })
678
+ ]
679
+ }),
680
+ /*#__PURE__*/ _jsx(Field, {
681
+ dispatch: dispatch,
682
+ field: "productImage",
683
+ hint: "Absolute URL of the product image",
684
+ label: "Image URL",
685
+ state: state
686
+ }),
687
+ /*#__PURE__*/ _jsxs("div", {
688
+ style: sectionStyle,
689
+ children: [
690
+ /*#__PURE__*/ _jsx("div", {
691
+ style: sectionLabelStyle,
692
+ children: "Offer"
693
+ }),
694
+ /*#__PURE__*/ _jsxs("div", {
695
+ style: gridStyle,
696
+ children: [
697
+ /*#__PURE__*/ _jsx(Field, {
698
+ dispatch: dispatch,
699
+ field: "productOffersPrice",
700
+ label: "Price",
701
+ placeholder: "29.99",
702
+ state: state
703
+ }),
704
+ /*#__PURE__*/ _jsx(Field, {
705
+ dispatch: dispatch,
706
+ field: "productOffersCurrency",
707
+ hint: "ISO 4217, e.g. USD, GBP, EUR",
708
+ label: "Currency",
709
+ placeholder: "USD",
710
+ state: state
711
+ })
712
+ ]
713
+ }),
714
+ /*#__PURE__*/ _jsxs("div", {
715
+ style: {
716
+ ...gridStyle,
717
+ marginTop: 12
718
+ },
719
+ children: [
720
+ /*#__PURE__*/ _jsx(Field, {
721
+ dispatch: dispatch,
722
+ field: "productOffersAvailability",
723
+ hint: "e.g. InStock, OutOfStock, PreOrder",
724
+ label: "Availability",
725
+ placeholder: "InStock",
726
+ state: state
727
+ }),
728
+ /*#__PURE__*/ _jsx(Field, {
729
+ dispatch: dispatch,
730
+ field: "productOffersUrl",
731
+ label: "Offer URL",
732
+ state: state
733
+ })
734
+ ]
735
+ })
736
+ ]
737
+ })
738
+ ]
739
+ });
740
+ }
741
+ function OrganizationForm({ dispatch, state }) {
742
+ return /*#__PURE__*/ _jsxs("div", {
743
+ style: {
744
+ display: 'grid',
745
+ gap: 12
746
+ },
747
+ children: [
748
+ /*#__PURE__*/ _jsxs("div", {
749
+ style: gridStyle,
750
+ children: [
751
+ /*#__PURE__*/ _jsx(Field, {
752
+ dispatch: dispatch,
753
+ field: "orgName",
754
+ label: "Organization Name",
755
+ state: state
756
+ }),
757
+ /*#__PURE__*/ _jsx(Field, {
758
+ dispatch: dispatch,
759
+ field: "orgUrl",
760
+ label: "Website URL",
761
+ state: state
762
+ })
763
+ ]
764
+ }),
765
+ /*#__PURE__*/ _jsx(Field, {
766
+ dispatch: dispatch,
767
+ field: "orgDescription",
768
+ label: "Description",
769
+ state: state,
770
+ textarea: true
771
+ }),
772
+ /*#__PURE__*/ _jsxs("div", {
773
+ style: gridStyle,
774
+ children: [
775
+ /*#__PURE__*/ _jsx(Field, {
776
+ dispatch: dispatch,
777
+ field: "orgEmail",
778
+ label: "Email",
779
+ state: state
780
+ }),
781
+ /*#__PURE__*/ _jsx(Field, {
782
+ dispatch: dispatch,
783
+ field: "orgTelephone",
784
+ label: "Telephone",
785
+ state: state
786
+ })
787
+ ]
788
+ }),
789
+ /*#__PURE__*/ _jsx(Field, {
790
+ dispatch: dispatch,
791
+ field: "orgLogo",
792
+ hint: "Absolute URL of the organization logo",
793
+ label: "Logo URL",
794
+ state: state
795
+ }),
796
+ /*#__PURE__*/ _jsx(Field, {
797
+ dispatch: dispatch,
798
+ field: "orgSameAs",
799
+ hint: "One URL per line — links to social profiles or other authoritative pages",
800
+ label: "Same As URLs",
801
+ state: state,
802
+ textarea: true
803
+ })
804
+ ]
805
+ });
806
+ }
807
+ function BreadcrumbForm({ dispatch, state }) {
808
+ return /*#__PURE__*/ _jsxs("div", {
809
+ children: [
810
+ state.breadcrumbItems.map((item, index)=>/*#__PURE__*/ _jsxs("div", {
811
+ style: {
812
+ alignItems: 'flex-end',
813
+ display: 'grid',
814
+ gap: 10,
815
+ gridTemplateColumns: '1fr 2fr auto',
816
+ marginBottom: 10
817
+ },
818
+ children: [
819
+ /*#__PURE__*/ _jsxs("div", {
820
+ children: [
821
+ /*#__PURE__*/ _jsx("label", {
822
+ style: labelStyle,
823
+ children: "Name"
824
+ }),
825
+ /*#__PURE__*/ _jsx("input", {
826
+ onChange: (e)=>dispatch({
827
+ index,
828
+ key: 'name',
829
+ type: 'SET_BREADCRUMB',
830
+ value: e.target.value
831
+ }),
832
+ placeholder: "Home",
833
+ style: inputStyle,
834
+ value: item.name
835
+ })
836
+ ]
837
+ }),
838
+ /*#__PURE__*/ _jsxs("div", {
839
+ children: [
840
+ /*#__PURE__*/ _jsx("label", {
841
+ style: labelStyle,
842
+ children: "URL"
843
+ }),
844
+ /*#__PURE__*/ _jsx("input", {
845
+ onChange: (e)=>dispatch({
846
+ index,
847
+ key: 'id',
848
+ type: 'SET_BREADCRUMB',
849
+ value: e.target.value
850
+ }),
851
+ placeholder: "https://example.com",
852
+ style: inputStyle,
853
+ value: item.id
854
+ })
855
+ ]
856
+ }),
857
+ /*#__PURE__*/ _jsx("button", {
858
+ disabled: state.breadcrumbItems.length <= 1,
859
+ onClick: ()=>dispatch({
860
+ index,
861
+ type: 'REMOVE_BREADCRUMB'
862
+ }),
863
+ style: {
864
+ background: 'none',
865
+ border: '1px solid var(--theme-elevation-150)',
866
+ borderRadius: 4,
867
+ color: state.breadcrumbItems.length <= 1 ? 'var(--theme-elevation-300)' : 'var(--theme-elevation-600)',
868
+ cursor: state.breadcrumbItems.length <= 1 ? 'default' : 'pointer',
869
+ fontSize: 13,
870
+ padding: '6px 10px'
871
+ },
872
+ title: "Remove",
873
+ type: "button",
874
+ children: "Remove"
875
+ })
876
+ ]
877
+ }, index)),
878
+ /*#__PURE__*/ _jsx("button", {
879
+ onClick: ()=>dispatch({
880
+ type: 'ADD_BREADCRUMB'
881
+ }),
882
+ style: {
883
+ background: 'none',
884
+ border: '1px solid var(--theme-elevation-200)',
885
+ borderRadius: 4,
886
+ color: 'var(--theme-elevation-700)',
887
+ cursor: 'pointer',
888
+ fontSize: 12,
889
+ marginTop: 4,
890
+ padding: '5px 12px'
891
+ },
892
+ type: "button",
893
+ children: "+ Add item"
894
+ })
895
+ ]
896
+ });
897
+ }
898
+ // ---------------------------------------------------------------------------
899
+ // Schema type picker
900
+ // ---------------------------------------------------------------------------
901
+ const SCHEMA_TYPES = [
902
+ {
903
+ description: 'No schema markup',
904
+ label: 'None',
905
+ value: 'None'
906
+ },
907
+ {
908
+ description: 'A generic web page',
909
+ label: 'Web Page',
910
+ value: 'WebPage'
911
+ },
912
+ {
913
+ description: 'A news or blog article',
914
+ label: 'Article',
915
+ value: 'Article'
916
+ },
917
+ {
918
+ description: 'A product listing',
919
+ label: 'Product',
920
+ value: 'Product'
921
+ },
922
+ {
923
+ description: 'A company or brand',
924
+ label: 'Organization',
925
+ value: 'Organization'
926
+ },
927
+ {
928
+ description: 'Navigational breadcrumbs',
929
+ label: 'Breadcrumb Trail',
930
+ value: 'BreadcrumbList'
931
+ }
932
+ ];
933
+ export const JsonLdEditorComponent = (props)=>{
934
+ const { path } = props;
935
+ const isTemplate = props.isTemplate ?? false;
936
+ const { setValue, value } = useField({
937
+ path
938
+ });
939
+ const { config } = useConfig();
940
+ const [state, dispatch] = useReducer(reducer, value, (v)=>parseJsonLd(v));
941
+ const [templates, setTemplates] = useState([]);
942
+ const [selectedTemplate, setSelectedTemplate] = useState('');
943
+ const didFetch = useRef(false);
944
+ // Fetch templates from global-seo once (only when not in template-editing mode)
945
+ useEffect(()=>{
946
+ if (isTemplate || didFetch.current) return;
947
+ didFetch.current = true;
948
+ const serverURL = config.serverURL ?? '';
949
+ fetch(`${serverURL}/api/globals/global-seo?depth=0`).then((r)=>r.ok ? r.json() : null).then((data)=>{
950
+ if (!data) return;
951
+ const entries = data.jsonLdTemplates;
952
+ if (Array.isArray(entries) && entries.length > 0) {
953
+ setTemplates(entries.filter((e)=>e.name && e.template));
954
+ }
955
+ }).catch(()=>{
956
+ // Global SEO not configured yet — silently ignore
957
+ });
958
+ }, [
959
+ isTemplate,
960
+ config.serverURL
961
+ ]);
962
+ // Sync state → field value whenever form state changes
963
+ useEffect(()=>{
964
+ const jsonLd = buildJsonLd(state);
965
+ setValue(jsonLd ?? {});
966
+ }, [
967
+ state
968
+ ]); // eslint-disable-line react-hooks/exhaustive-deps
969
+ const handleLoadTemplate = useCallback(()=>{
970
+ if (!selectedTemplate) return;
971
+ const entry = templates.find((t)=>t.name === selectedTemplate);
972
+ if (entry?.template) {
973
+ dispatch({
974
+ type: 'LOAD_TEMPLATE',
975
+ value: entry.template
976
+ });
977
+ setSelectedTemplate('');
978
+ }
979
+ }, [
980
+ selectedTemplate,
981
+ templates
982
+ ]);
983
+ const activeType = SCHEMA_TYPES.find((t)=>t.value === state.schemaType);
984
+ return /*#__PURE__*/ _jsxs("div", {
985
+ style: {
986
+ paddingTop: 16,
987
+ width: '100%'
988
+ },
989
+ children: [
990
+ /*#__PURE__*/ _jsxs("div", {
991
+ style: {
992
+ marginBottom: 16
993
+ },
994
+ children: [
995
+ !isTemplate && /*#__PURE__*/ _jsx("label", {
996
+ style: {
997
+ ...labelStyle,
998
+ fontSize: 13,
999
+ marginBottom: 8
1000
+ },
1001
+ children: "JSON-LD Structured Data"
1002
+ }),
1003
+ /*#__PURE__*/ _jsx("p", {
1004
+ style: {
1005
+ color: 'var(--theme-elevation-500)',
1006
+ fontSize: 12,
1007
+ margin: '0 0 12px'
1008
+ },
1009
+ children: isTemplate ? 'Define the schema markup for this template.' : 'Add schema markup to help search engines understand this page. Choose a type below, or load a saved template.'
1010
+ }),
1011
+ !isTemplate && templates.length > 0 && /*#__PURE__*/ _jsxs("div", {
1012
+ style: {
1013
+ alignItems: 'center',
1014
+ background: 'var(--theme-elevation-50, var(--theme-elevation-0))',
1015
+ border: '1px solid var(--theme-elevation-150)',
1016
+ borderRadius: 6,
1017
+ display: 'flex',
1018
+ gap: 8,
1019
+ marginBottom: 12,
1020
+ padding: '8px 10px'
1021
+ },
1022
+ children: [
1023
+ /*#__PURE__*/ _jsx("span", {
1024
+ style: {
1025
+ color: 'var(--theme-elevation-600)',
1026
+ fontSize: 12,
1027
+ whiteSpace: 'nowrap'
1028
+ },
1029
+ children: "Load template:"
1030
+ }),
1031
+ /*#__PURE__*/ _jsxs("select", {
1032
+ onChange: (e)=>setSelectedTemplate(e.target.value),
1033
+ style: {
1034
+ ...inputStyle,
1035
+ flex: 1,
1036
+ padding: '4px 8px'
1037
+ },
1038
+ value: selectedTemplate,
1039
+ children: [
1040
+ /*#__PURE__*/ _jsx("option", {
1041
+ value: "",
1042
+ children: "— choose a template —"
1043
+ }),
1044
+ templates.map((t)=>/*#__PURE__*/ _jsx("option", {
1045
+ value: t.name,
1046
+ children: t.name
1047
+ }, t.name))
1048
+ ]
1049
+ }),
1050
+ /*#__PURE__*/ _jsx("button", {
1051
+ disabled: !selectedTemplate,
1052
+ onClick: handleLoadTemplate,
1053
+ style: {
1054
+ background: selectedTemplate ? 'var(--theme-text)' : 'var(--theme-elevation-200)',
1055
+ border: 'none',
1056
+ borderRadius: 4,
1057
+ color: selectedTemplate ? 'var(--theme-bg)' : 'var(--theme-elevation-400)',
1058
+ cursor: selectedTemplate ? 'pointer' : 'default',
1059
+ fontFamily: 'inherit',
1060
+ fontSize: 12,
1061
+ padding: '5px 14px',
1062
+ whiteSpace: 'nowrap'
1063
+ },
1064
+ type: "button",
1065
+ children: "Apply"
1066
+ })
1067
+ ]
1068
+ }),
1069
+ /*#__PURE__*/ _jsx("div", {
1070
+ style: {
1071
+ display: 'grid',
1072
+ gap: 8,
1073
+ gridTemplateColumns: 'repeat(3, 1fr)'
1074
+ },
1075
+ children: SCHEMA_TYPES.map((t)=>{
1076
+ const isSelected = state.schemaType === t.value;
1077
+ return /*#__PURE__*/ _jsxs("button", {
1078
+ onClick: ()=>dispatch({
1079
+ type: 'SET_SCHEMA',
1080
+ value: t.value
1081
+ }),
1082
+ style: {
1083
+ background: isSelected ? 'var(--theme-success-500, #27ae60)' : 'var(--theme-elevation-0)',
1084
+ border: `1px solid ${isSelected ? 'var(--theme-success-500, #27ae60)' : 'var(--theme-elevation-200)'}`,
1085
+ borderRadius: 6,
1086
+ color: isSelected ? '#fff' : 'var(--theme-elevation-800)',
1087
+ cursor: 'pointer',
1088
+ fontFamily: 'inherit',
1089
+ fontSize: 12,
1090
+ padding: '8px 10px',
1091
+ textAlign: 'left',
1092
+ transition: 'all 0.1s ease'
1093
+ },
1094
+ type: "button",
1095
+ children: [
1096
+ /*#__PURE__*/ _jsx("div", {
1097
+ style: {
1098
+ fontWeight: 600
1099
+ },
1100
+ children: t.label
1101
+ }),
1102
+ /*#__PURE__*/ _jsx("div", {
1103
+ style: {
1104
+ color: isSelected ? 'rgba(255,255,255,0.8)' : 'var(--theme-elevation-500)',
1105
+ fontSize: 10,
1106
+ marginTop: 2
1107
+ },
1108
+ children: t.description
1109
+ })
1110
+ ]
1111
+ }, t.value);
1112
+ })
1113
+ })
1114
+ ]
1115
+ }),
1116
+ state.schemaType !== 'None' && /*#__PURE__*/ _jsxs("div", {
1117
+ style: {
1118
+ background: 'var(--theme-elevation-50, var(--theme-elevation-0))',
1119
+ border: '1px solid var(--theme-elevation-150)',
1120
+ borderRadius: 6,
1121
+ padding: 16
1122
+ },
1123
+ children: [
1124
+ /*#__PURE__*/ _jsxs("div", {
1125
+ style: {
1126
+ alignItems: 'center',
1127
+ display: 'flex',
1128
+ justifyContent: 'space-between',
1129
+ marginBottom: 16
1130
+ },
1131
+ children: [
1132
+ /*#__PURE__*/ _jsxs("span", {
1133
+ style: {
1134
+ fontSize: 13,
1135
+ fontWeight: 600
1136
+ },
1137
+ children: [
1138
+ activeType?.label,
1139
+ " Schema"
1140
+ ]
1141
+ }),
1142
+ /*#__PURE__*/ _jsxs("a", {
1143
+ href: `https://schema.org/${state.schemaType}`,
1144
+ rel: "noopener noreferrer",
1145
+ style: {
1146
+ color: 'var(--theme-elevation-500)',
1147
+ fontSize: 11
1148
+ },
1149
+ target: "_blank",
1150
+ children: [
1151
+ "schema.org/",
1152
+ state.schemaType,
1153
+ " ↗"
1154
+ ]
1155
+ })
1156
+ ]
1157
+ }),
1158
+ state.schemaType === 'WebPage' && /*#__PURE__*/ _jsx(WebPageForm, {
1159
+ dispatch: dispatch,
1160
+ state: state
1161
+ }),
1162
+ state.schemaType === 'Article' && /*#__PURE__*/ _jsx(ArticleForm, {
1163
+ dispatch: dispatch,
1164
+ state: state
1165
+ }),
1166
+ state.schemaType === 'Product' && /*#__PURE__*/ _jsx(ProductForm, {
1167
+ dispatch: dispatch,
1168
+ state: state
1169
+ }),
1170
+ state.schemaType === 'Organization' && /*#__PURE__*/ _jsx(OrganizationForm, {
1171
+ dispatch: dispatch,
1172
+ state: state
1173
+ }),
1174
+ state.schemaType === 'BreadcrumbList' && /*#__PURE__*/ _jsx(BreadcrumbForm, {
1175
+ dispatch: dispatch,
1176
+ state: state
1177
+ })
1178
+ ]
1179
+ })
1180
+ ]
1181
+ });
1182
+ };
1183
+
1184
+ //# sourceMappingURL=JsonLdEditor.js.map