sanity-plugin-seofields 1.6.4 → 1.6.5

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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { getMetaTitleValidationMessages, getMetaDescriptionValidationMessages, getMetaImageValidation, getOgTitleValidation, getOgDescriptionValidation, getOgImageValidation, getOgImageUrlValidation, getTwitterTitleValidation, getTwitterDescriptionValidation, getTwitterImageValidation, getTwitterImageUrlValidation } from './chunk-25JLWVEU.js';
1
+ import { getMetaTitleValidationMessages, getMetaDescriptionValidationMessages, getMetaImageValidation, getOgTitleValidation, getOgDescriptionValidation, getOgImageValidation, getOgImageUrlValidation, getTwitterTitleValidation, getTwitterDescriptionValidation, getTwitterImageValidation, getTwitterImageUrlValidation } from './chunk-HDZZQCH7.js';
2
2
  import { __spreadValues, __spreadProps, __objRest } from './chunk-2NMEKWO5.js';
3
- import { lazy, createElement, Suspense, useMemo } from 'react';
4
- import { defineType, defineField, definePlugin, useFormValue } from 'sanity';
3
+ import { lazy, createElement, Suspense, useMemo, useState, useEffect } from 'react';
4
+ import { defineType, defineField, definePlugin, useFormValue, useClient } from 'sanity';
5
5
  import { Stack, Text } from '@sanity/ui';
6
6
  import { jsxs, jsx } from 'react/jsx-runtime';
7
7
 
@@ -56,13 +56,37 @@ var MetaImage = (props) => {
56
56
  };
57
57
  var MetaImage_default = MetaImage;
58
58
  var MetaTitle = (props) => {
59
- const { value, renderDefault, path } = props;
59
+ var _a, _b;
60
+ const { value, renderDefault, path, schemaType } = props;
61
+ const { options } = schemaType;
60
62
  const parent = useFormValue([path[0]]);
61
63
  const isParentseoField = parent && (parent == null ? void 0 : parent._type) === "seoFields";
62
64
  const keywords = useMemo(() => (parent == null ? void 0 : parent.keywords) || [], [parent == null ? void 0 : parent.keywords]);
65
+ const rootDoc = (_a = useFormValue([])) != null ? _a : {};
66
+ const client = useClient({ apiVersion: (_b = options == null ? void 0 : options.apiVersion) != null ? _b : "2024-01-01" });
67
+ const [groqTitleSuffix, setGroqTitleSuffix] = useState("");
68
+ const titleSuffixQuery = options == null ? void 0 : options.titleSuffixQuery;
69
+ const titleSuffixOption = options == null ? void 0 : options.titleSuffix;
70
+ useEffect(() => {
71
+ if (!titleSuffixQuery) return;
72
+ client.fetch(titleSuffixQuery).then((result) => {
73
+ setGroqTitleSuffix(result === null || result === void 0 ? "" : String(result));
74
+ }).catch(() => {
75
+ setGroqTitleSuffix("");
76
+ });
77
+ }, [titleSuffixQuery, client]);
78
+ const resolvedSuffix = useMemo(() => {
79
+ if (titleSuffixQuery) return groqTitleSuffix;
80
+ if (!titleSuffixOption) return "";
81
+ if (typeof titleSuffixOption === "function") {
82
+ return titleSuffixOption(rootDoc);
83
+ }
84
+ return titleSuffixOption;
85
+ }, [titleSuffixQuery, groqTitleSuffix, titleSuffixOption, rootDoc]);
86
+ const suffixLength = resolvedSuffix ? resolvedSuffix.length + 3 : 0;
63
87
  const feedbackItems = useMemo(
64
- () => getMetaTitleValidationMessages(value || "", keywords, isParentseoField),
65
- [value, keywords, isParentseoField]
88
+ () => getMetaTitleValidationMessages(value || "", keywords, isParentseoField, suffixLength),
89
+ [value, keywords, isParentseoField, suffixLength]
66
90
  );
67
91
  return /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
68
92
  renderDefault(props),
@@ -653,7 +677,7 @@ function twitter(config = {}) {
653
677
  }
654
678
 
655
679
  // src/schemas/index.ts
656
- var LazySeoPreview = lazy(() => import('./SeoPreview-XVAZYHCL.js'));
680
+ var LazySeoPreview = lazy(() => import('./SeoPreview-KEGGQSPJ.js'));
657
681
  var SeoPreviewWrapper = (props) => createElement(Suspense, { fallback: null }, createElement(LazySeoPreview, props));
658
682
  function buildFieldGroupMap(groups) {
659
683
  const map = /* @__PURE__ */ new Map();
@@ -732,6 +756,7 @@ function seoFieldsSchema(config = {}) {
732
756
  components: {
733
757
  input: MetaTitle_default
734
758
  },
759
+ options: __spreadValues(__spreadValues(__spreadValues({}, config.apiVersion ? { apiVersion: config.apiVersion } : {}), typeof config.seoPreview === "object" && config.seoPreview && config.seoPreview.titleSuffix ? { titleSuffix: config.seoPreview.titleSuffix } : {}), typeof config.seoPreview === "object" && config.seoPreview && config.seoPreview.titleSuffixQuery ? { titleSuffixQuery: config.seoPreview.titleSuffixQuery } : {}),
735
760
  hidden: getFieldHiddenFunction("title", config)
736
761
  })),
737
762
  fieldGroupMap