@madebywild/sanity-richtext-field 1.0.0 → 2.0.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/dist/parts.d.cts CHANGED
@@ -1,96 +1,115 @@
1
- import * as sanity76 from "sanity";
2
- import * as react25 from "react";
1
+ import * as sanity77 from "sanity";
2
+ import * as react22 from "react";
3
+ type ColorAnnotationOptions = {
4
+ renderValue?: (value: string | undefined) => string | undefined;
5
+ };
3
6
  /** @public */
4
- declare function createAnnotations(): readonly [{
7
+ declare function createAnnotations(options?: {
8
+ textColor?: ColorAnnotationOptions;
9
+ highlightColor?: ColorAnnotationOptions;
10
+ }): readonly [{
5
11
  type: "wild.link";
6
12
  name: "wild.richtext.annotation.link";
7
- } & sanity76.TypeAliasDefinition<"wild.link", "string" | "number" | "boolean" | "object" | "wild.richtext" | "wild.quote" | "wild.media" | "array" | "block" | "date" | "datetime" | "document" | "file" | "geopoint" | "image" | "reference" | "crossDatasetReference" | "globalDocumentReference" | "slug" | "text" | "url" | "email" | undefined> & {
8
- preview?: sanity76.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
9
- } & sanity76.FieldDefinitionBase & sanity76.WidenValidation & sanity76.WidenInitialValue, {
13
+ } & sanity77.TypeAliasDefinition<"wild.link", "string" | "number" | "boolean" | "object" | "wild.richtext" | "wild.media" | "wild.quote" | "array" | "block" | "date" | "datetime" | "document" | "file" | "geopoint" | "image" | "reference" | "crossDatasetReference" | "globalDocumentReference" | "slug" | "text" | "url" | "email" | undefined> & {
14
+ preview?: sanity77.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
15
+ } & sanity77.FieldDefinitionBase & sanity77.WidenValidation & sanity77.WidenInitialValue, {
10
16
  type: "object";
11
17
  name: "wild.richtext.annotation.textColor";
12
- } & Omit<sanity76.ObjectDefinition, "preview"> & {
13
- preview?: sanity76.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
14
- } & sanity76.FieldDefinitionBase & sanity76.WidenValidation & sanity76.WidenInitialValue, {
18
+ } & Omit<sanity77.ObjectDefinition, "preview"> & {
19
+ preview?: sanity77.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
20
+ } & sanity77.FieldDefinitionBase & sanity77.WidenValidation & sanity77.WidenInitialValue, {
15
21
  type: "object";
16
22
  name: "wild.richtext.annotation.highlightColor";
17
- } & Omit<sanity76.ObjectDefinition, "preview"> & {
18
- preview?: sanity76.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
19
- } & sanity76.FieldDefinitionBase & sanity76.WidenValidation & sanity76.WidenInitialValue];
23
+ } & Omit<sanity77.ObjectDefinition, "preview"> & {
24
+ preview?: sanity77.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
25
+ } & sanity77.FieldDefinitionBase & sanity77.WidenValidation & sanity77.WidenInitialValue];
20
26
  /** @public */
21
27
  declare function createDecorators(): readonly [{
22
28
  readonly title: "Strong";
23
29
  readonly value: "wild.richtext.decorator.strong";
24
- readonly icon: react25.ForwardRefExoticComponent<Omit<react25.SVGProps<SVGSVGElement>, "ref"> & react25.RefAttributes<SVGSVGElement>>;
30
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
25
31
  readonly component: ({
26
32
  children
27
- }: BlockDecoratorProps) => react25.JSX.Element;
33
+ }: BlockDecoratorProps) => react22.JSX.Element;
28
34
  }, {
29
35
  readonly title: "Emphasis";
30
36
  readonly value: "wild.richtext.decorator.em";
31
- readonly icon: react25.ForwardRefExoticComponent<Omit<react25.SVGProps<SVGSVGElement>, "ref"> & react25.RefAttributes<SVGSVGElement>>;
37
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
32
38
  readonly component: ({
33
39
  children
34
- }: BlockDecoratorProps) => react25.JSX.Element;
40
+ }: BlockDecoratorProps) => react22.JSX.Element;
35
41
  }, {
36
42
  readonly title: "Code";
37
43
  readonly value: "wild.richtext.decorator.code";
38
- readonly icon: react25.ForwardRefExoticComponent<Omit<react25.SVGProps<SVGSVGElement>, "ref"> & react25.RefAttributes<SVGSVGElement>>;
44
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
39
45
  readonly component: ({
40
46
  children
41
- }: BlockDecoratorProps) => react25.JSX.Element;
47
+ }: BlockDecoratorProps) => react22.JSX.Element;
42
48
  }, {
43
49
  readonly title: "Sup";
44
50
  readonly value: "wild.richtext.decorator.sup";
45
- readonly icon: () => react25.JSX.Element;
51
+ readonly icon: () => react22.JSX.Element;
46
52
  readonly component: ({
47
53
  children
48
- }: BlockDecoratorProps) => react25.JSX.Element;
54
+ }: BlockDecoratorProps) => react22.JSX.Element;
49
55
  }];
50
56
  /** @public */
51
57
  declare function createLists(): readonly [{
52
58
  readonly title: "Bullet";
53
59
  readonly value: "wild.richtext.list.bullet";
54
- readonly icon: react25.ForwardRefExoticComponent<Omit<react25.SVGProps<SVGSVGElement>, "ref"> & react25.RefAttributes<SVGSVGElement>>;
60
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
55
61
  }, {
56
62
  readonly title: "Number";
57
63
  readonly value: "wild.richtext.list.number";
58
- readonly icon: react25.ForwardRefExoticComponent<Omit<react25.SVGProps<SVGSVGElement>, "ref"> & react25.RefAttributes<SVGSVGElement>>;
64
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
59
65
  }];
66
+ type IconSpanOptions = {
67
+ renderValuePreview?: (value?: string) => react22.ReactNode;
68
+ };
69
+ declare function createIconSpan(options?: IconSpanOptions): {
70
+ type: "object";
71
+ name?: "wild.richtext.span.icon" | undefined;
72
+ } & Omit<sanity77.ArrayOfEntry<sanity77.ObjectDefinition>, "preview"> & {
73
+ preview?: sanity77.PreviewConfig<{
74
+ icon: string;
75
+ }, Record<"icon", any>> | undefined;
76
+ } & sanity77.WidenValidation & sanity77.WidenInitialValue;
60
77
  /** @public */
61
- declare function createSpans(): readonly [{
78
+ declare function createSpans(options?: {
79
+ icon?: IconSpanOptions;
80
+ }): readonly [{
62
81
  type: "object";
63
82
  name?: "wild.richtext.span.icon" | undefined;
64
- } & Omit<sanity76.ArrayOfEntry<sanity76.ObjectDefinition>, "preview"> & {
65
- preview?: sanity76.PreviewConfig<{
83
+ } & Omit<sanity77.ArrayOfEntry<sanity77.ObjectDefinition>, "preview"> & {
84
+ preview?: sanity77.PreviewConfig<{
66
85
  icon: string;
67
86
  }, Record<"icon", any>> | undefined;
68
- } & sanity76.WidenValidation & sanity76.WidenInitialValue, {
87
+ } & sanity77.WidenValidation & sanity77.WidenInitialValue, {
69
88
  type: "object";
70
89
  name?: "wild.richtext.span.media" | undefined;
71
- } & Omit<sanity76.ArrayOfEntry<sanity76.ObjectDefinition>, "preview"> & {
72
- preview?: sanity76.PreviewConfig<{
90
+ } & Omit<sanity77.ArrayOfEntry<sanity77.ObjectDefinition>, "preview"> & {
91
+ preview?: sanity77.PreviewConfig<{
73
92
  kind: string;
74
93
  }, Record<"kind", any>> | undefined;
75
- } & sanity76.WidenValidation & sanity76.WidenInitialValue];
94
+ } & sanity77.WidenValidation & sanity77.WidenInitialValue];
76
95
  /** @public */
77
96
  declare function createStyles(): readonly [{
78
97
  readonly title: "Heading 2";
79
98
  readonly value: "wild.richtext.style.h2";
80
99
  readonly component: ({
81
100
  children
82
- }: BlockStyleProps) => react25.JSX.Element;
101
+ }: BlockStyleProps) => react22.JSX.Element;
83
102
  }, {
84
103
  readonly title: "Heading 3";
85
104
  readonly value: "wild.richtext.style.h3";
86
105
  readonly component: ({
87
106
  children
88
- }: BlockStyleProps) => react25.JSX.Element;
107
+ }: BlockStyleProps) => react22.JSX.Element;
89
108
  }, {
90
109
  readonly title: "Heading 4";
91
110
  readonly value: "wild.richtext.style.h4";
92
111
  readonly component: ({
93
112
  children
94
- }: BlockStyleProps) => react25.JSX.Element;
113
+ }: BlockStyleProps) => react22.JSX.Element;
95
114
  }];
96
- export { createAnnotations, createDecorators, createLists, createSpans, createStyles };
115
+ export { createAnnotations, createDecorators, createIconSpan, createLists, createSpans, createStyles };
package/dist/parts.d.ts CHANGED
@@ -1,96 +1,115 @@
1
- import * as sanity62 from "sanity";
2
- import * as react31 from "react";
1
+ import * as sanity81 from "sanity";
2
+ import * as react22 from "react";
3
+ type ColorAnnotationOptions = {
4
+ renderValue?: (value: string | undefined) => string | undefined;
5
+ };
3
6
  /** @public */
4
- declare function createAnnotations(): readonly [{
7
+ declare function createAnnotations(options?: {
8
+ textColor?: ColorAnnotationOptions;
9
+ highlightColor?: ColorAnnotationOptions;
10
+ }): readonly [{
5
11
  type: "wild.link";
6
12
  name: "wild.richtext.annotation.link";
7
- } & sanity62.TypeAliasDefinition<"wild.link", "string" | "number" | "boolean" | "object" | "wild.richtext" | "wild.media" | "wild.quote" | "array" | "block" | "date" | "datetime" | "document" | "file" | "geopoint" | "image" | "reference" | "crossDatasetReference" | "globalDocumentReference" | "slug" | "text" | "url" | "email" | undefined> & {
8
- preview?: sanity62.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
9
- } & sanity62.FieldDefinitionBase & sanity62.WidenValidation & sanity62.WidenInitialValue, {
13
+ } & sanity81.TypeAliasDefinition<"wild.link", "string" | "number" | "boolean" | "object" | "wild.richtext" | "wild.media" | "wild.quote" | "array" | "block" | "date" | "datetime" | "document" | "file" | "geopoint" | "image" | "reference" | "crossDatasetReference" | "globalDocumentReference" | "slug" | "text" | "url" | "email" | undefined> & {
14
+ preview?: sanity81.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
15
+ } & sanity81.FieldDefinitionBase & sanity81.WidenValidation & sanity81.WidenInitialValue, {
10
16
  type: "object";
11
17
  name: "wild.richtext.annotation.textColor";
12
- } & Omit<sanity62.ObjectDefinition, "preview"> & {
13
- preview?: sanity62.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
14
- } & sanity62.FieldDefinitionBase & sanity62.WidenValidation & sanity62.WidenInitialValue, {
18
+ } & Omit<sanity81.ObjectDefinition, "preview"> & {
19
+ preview?: sanity81.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
20
+ } & sanity81.FieldDefinitionBase & sanity81.WidenValidation & sanity81.WidenInitialValue, {
15
21
  type: "object";
16
22
  name: "wild.richtext.annotation.highlightColor";
17
- } & Omit<sanity62.ObjectDefinition, "preview"> & {
18
- preview?: sanity62.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
19
- } & sanity62.FieldDefinitionBase & sanity62.WidenValidation & sanity62.WidenInitialValue];
23
+ } & Omit<sanity81.ObjectDefinition, "preview"> & {
24
+ preview?: sanity81.PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
25
+ } & sanity81.FieldDefinitionBase & sanity81.WidenValidation & sanity81.WidenInitialValue];
20
26
  /** @public */
21
27
  declare function createDecorators(): readonly [{
22
28
  readonly title: "Strong";
23
29
  readonly value: "wild.richtext.decorator.strong";
24
- readonly icon: react31.ForwardRefExoticComponent<Omit<react31.SVGProps<SVGSVGElement>, "ref"> & react31.RefAttributes<SVGSVGElement>>;
30
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
25
31
  readonly component: ({
26
32
  children
27
- }: BlockDecoratorProps) => react31.JSX.Element;
33
+ }: BlockDecoratorProps) => react22.JSX.Element;
28
34
  }, {
29
35
  readonly title: "Emphasis";
30
36
  readonly value: "wild.richtext.decorator.em";
31
- readonly icon: react31.ForwardRefExoticComponent<Omit<react31.SVGProps<SVGSVGElement>, "ref"> & react31.RefAttributes<SVGSVGElement>>;
37
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
32
38
  readonly component: ({
33
39
  children
34
- }: BlockDecoratorProps) => react31.JSX.Element;
40
+ }: BlockDecoratorProps) => react22.JSX.Element;
35
41
  }, {
36
42
  readonly title: "Code";
37
43
  readonly value: "wild.richtext.decorator.code";
38
- readonly icon: react31.ForwardRefExoticComponent<Omit<react31.SVGProps<SVGSVGElement>, "ref"> & react31.RefAttributes<SVGSVGElement>>;
44
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
39
45
  readonly component: ({
40
46
  children
41
- }: BlockDecoratorProps) => react31.JSX.Element;
47
+ }: BlockDecoratorProps) => react22.JSX.Element;
42
48
  }, {
43
49
  readonly title: "Sup";
44
50
  readonly value: "wild.richtext.decorator.sup";
45
- readonly icon: () => react31.JSX.Element;
51
+ readonly icon: () => react22.JSX.Element;
46
52
  readonly component: ({
47
53
  children
48
- }: BlockDecoratorProps) => react31.JSX.Element;
54
+ }: BlockDecoratorProps) => react22.JSX.Element;
49
55
  }];
50
56
  /** @public */
51
57
  declare function createLists(): readonly [{
52
58
  readonly title: "Bullet";
53
59
  readonly value: "wild.richtext.list.bullet";
54
- readonly icon: react31.ForwardRefExoticComponent<Omit<react31.SVGProps<SVGSVGElement>, "ref"> & react31.RefAttributes<SVGSVGElement>>;
60
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
55
61
  }, {
56
62
  readonly title: "Number";
57
63
  readonly value: "wild.richtext.list.number";
58
- readonly icon: react31.ForwardRefExoticComponent<Omit<react31.SVGProps<SVGSVGElement>, "ref"> & react31.RefAttributes<SVGSVGElement>>;
64
+ readonly icon: react22.ForwardRefExoticComponent<Omit<react22.SVGProps<SVGSVGElement>, "ref"> & react22.RefAttributes<SVGSVGElement>>;
59
65
  }];
66
+ type IconSpanOptions = {
67
+ renderValuePreview?: (value?: string) => react22.ReactNode;
68
+ };
69
+ declare function createIconSpan(options?: IconSpanOptions): {
70
+ type: "object";
71
+ name?: "wild.richtext.span.icon" | undefined;
72
+ } & Omit<sanity81.ArrayOfEntry<sanity81.ObjectDefinition>, "preview"> & {
73
+ preview?: sanity81.PreviewConfig<{
74
+ icon: string;
75
+ }, Record<"icon", any>> | undefined;
76
+ } & sanity81.WidenValidation & sanity81.WidenInitialValue;
60
77
  /** @public */
61
- declare function createSpans(): readonly [{
78
+ declare function createSpans(options?: {
79
+ icon?: IconSpanOptions;
80
+ }): readonly [{
62
81
  type: "object";
63
82
  name?: "wild.richtext.span.icon" | undefined;
64
- } & Omit<sanity62.ArrayOfEntry<sanity62.ObjectDefinition>, "preview"> & {
65
- preview?: sanity62.PreviewConfig<{
83
+ } & Omit<sanity81.ArrayOfEntry<sanity81.ObjectDefinition>, "preview"> & {
84
+ preview?: sanity81.PreviewConfig<{
66
85
  icon: string;
67
86
  }, Record<"icon", any>> | undefined;
68
- } & sanity62.WidenValidation & sanity62.WidenInitialValue, {
87
+ } & sanity81.WidenValidation & sanity81.WidenInitialValue, {
69
88
  type: "object";
70
89
  name?: "wild.richtext.span.media" | undefined;
71
- } & Omit<sanity62.ArrayOfEntry<sanity62.ObjectDefinition>, "preview"> & {
72
- preview?: sanity62.PreviewConfig<{
90
+ } & Omit<sanity81.ArrayOfEntry<sanity81.ObjectDefinition>, "preview"> & {
91
+ preview?: sanity81.PreviewConfig<{
73
92
  kind: string;
74
93
  }, Record<"kind", any>> | undefined;
75
- } & sanity62.WidenValidation & sanity62.WidenInitialValue];
94
+ } & sanity81.WidenValidation & sanity81.WidenInitialValue];
76
95
  /** @public */
77
96
  declare function createStyles(): readonly [{
78
97
  readonly title: "Heading 2";
79
98
  readonly value: "wild.richtext.style.h2";
80
99
  readonly component: ({
81
100
  children
82
- }: BlockStyleProps) => react31.JSX.Element;
101
+ }: BlockStyleProps) => react22.JSX.Element;
83
102
  }, {
84
103
  readonly title: "Heading 3";
85
104
  readonly value: "wild.richtext.style.h3";
86
105
  readonly component: ({
87
106
  children
88
- }: BlockStyleProps) => react31.JSX.Element;
107
+ }: BlockStyleProps) => react22.JSX.Element;
89
108
  }, {
90
109
  readonly title: "Heading 4";
91
110
  readonly value: "wild.richtext.style.h4";
92
111
  readonly component: ({
93
112
  children
94
- }: BlockStyleProps) => react31.JSX.Element;
113
+ }: BlockStyleProps) => react22.JSX.Element;
95
114
  }];
96
- export { createAnnotations, createDecorators, createLists, createSpans, createStyles };
115
+ export { createAnnotations, createDecorators, createIconSpan, createLists, createSpans, createStyles };
package/dist/parts.js CHANGED
@@ -9,48 +9,61 @@ const ColorText = styled.span`
9
9
  background-color: inherit;
10
10
  border-bottom: unset;
11
11
  color: ${({
12
- color = "inherit"
13
- }) => color};
12
+ $color = "inherit"
13
+ }) => $color};
14
14
  }
15
- `, textColor = defineField({
16
- type: "object",
17
- name: `${typeName}.annotation.textColor`,
18
- title: "Text Color",
19
- icon: ColorWheelIcon,
20
- fields: [defineField({
21
- name: "color",
22
- type: "wild.color"
23
- })],
24
- components: {
25
- annotation: (props) => {
26
- const color = props.value?.color?.value;
27
- return /* @__PURE__ */ jsx(ColorText, { color, children: props.renderDefault(props) });
15
+ `;
16
+ function defaultResolveColor(value) {
17
+ return value;
18
+ }
19
+ function createTextColorAnnotation(options) {
20
+ const renderValue = options?.renderValue ?? defaultResolveColor;
21
+ return defineField({
22
+ type: "object",
23
+ name: `${typeName}.annotation.textColor`,
24
+ title: "Text Color",
25
+ icon: ColorWheelIcon,
26
+ fields: [defineField({
27
+ name: "color",
28
+ type: "wild.color"
29
+ })],
30
+ components: {
31
+ annotation: (props) => {
32
+ const value = renderValue(props.value?.color);
33
+ return /* @__PURE__ */ jsx(ColorText, { $color: value, children: props.renderDefault(props) });
34
+ }
28
35
  }
29
- }
30
- }), ColorBg = styled.span`
36
+ });
37
+ }
38
+ const ColorBg = styled.span`
31
39
  & > span {
32
40
  background-color: ${({
33
- color = "inherit"
34
- }) => color};
41
+ $color = "inherit"
42
+ }) => $color};
35
43
  border-bottom: unset;
36
44
  color: inherit;
37
45
  }
38
- `, highlightColor = defineField({
39
- type: "object",
40
- name: `${typeName}.annotation.highlightColor`,
41
- title: "Highlight Color",
42
- icon: HighlightIcon,
43
- fields: [defineField({
44
- name: "color",
45
- type: "wild.color"
46
- })],
47
- components: {
48
- annotation: (props) => {
49
- const color = props.value?.color?.value;
50
- return /* @__PURE__ */ jsx(ColorBg, { color, children: props.renderDefault(props) });
46
+ `;
47
+ function createHighlightColorAnnotation(options) {
48
+ const renderValue = options?.renderValue ?? defaultResolveColor;
49
+ return defineField({
50
+ type: "object",
51
+ name: `${typeName}.annotation.highlightColor`,
52
+ title: "Highlight Color",
53
+ icon: HighlightIcon,
54
+ fields: [defineField({
55
+ name: "color",
56
+ type: "wild.color"
57
+ })],
58
+ components: {
59
+ annotation: (props) => {
60
+ const value = renderValue(props.value?.color);
61
+ return /* @__PURE__ */ jsx(ColorBg, { $color: value, children: props.renderDefault(props) });
62
+ }
51
63
  }
52
- }
53
- }), link = defineField({
64
+ });
65
+ }
66
+ const link = defineField({
54
67
  type: "wild.link",
55
68
  name: `${typeName}.annotation.link`,
56
69
  title: "Link",
@@ -60,8 +73,8 @@ const ColorText = styled.span`
60
73
  collapsible: !1
61
74
  }
62
75
  });
63
- function createAnnotations() {
64
- return [link, textColor, highlightColor];
76
+ function createAnnotations(options) {
77
+ return [link, createTextColorAnnotation(options?.textColor), createHighlightColorAnnotation(options?.highlightColor)];
65
78
  }
66
79
  const strong = {
67
80
  title: "Strong",
@@ -109,34 +122,41 @@ const bullet = {
109
122
  function createLists() {
110
123
  return [bullet, number];
111
124
  }
112
- const icon = defineArrayMember({
113
- name: `${typeName}.span.icon`,
114
- type: "object",
115
- title: "Icon",
116
- description: "Insert an icon.",
117
- icon: () => /* @__PURE__ */ jsx(Fragment, { children: "\u{1F9FF}" }),
118
- fields: [defineField({
119
- name: "icon",
120
- type: "wild.icon"
121
- })],
122
- components: {
123
- // This is the inline-preview in the PortableText editor.
124
- // It gets its props from the prepare function below.
125
- preview: (props) => React.isValidElement(props.media) ? props.media : props.fallbackTitle
126
- },
127
- preview: {
128
- select: {
129
- icon: "icon"
125
+ function defaultRenderIconPreview(value) {
126
+ return React.isValidElement(value) ? value : /* @__PURE__ */ jsx("span", { role: "img", className: "inline-block size-[1em] shrink-0 text-current", title: typeof value == "string" ? value : "Icon", children: "\u{1F9FF}" });
127
+ }
128
+ function createIconSpan(options) {
129
+ const renderValuePreview = options?.renderValuePreview;
130
+ return defineArrayMember({
131
+ name: `${typeName}.span.icon`,
132
+ type: "object",
133
+ title: "Icon",
134
+ description: "Insert an icon.",
135
+ icon: () => /* @__PURE__ */ jsx(Fragment, { children: "\u{1F9FF}" }),
136
+ fields: [defineField({
137
+ name: "icon",
138
+ type: "wild.icon"
139
+ })],
140
+ components: {
141
+ // This is the inline-preview in the PortableText editor.
142
+ // It gets its props from the prepare function below.
143
+ preview: (props) => React.isValidElement(props.media) ? props.media : props.fallbackTitle
130
144
  },
131
- prepare({
132
- icon: icon2
133
- }) {
134
- return {
135
- media: /* @__PURE__ */ jsx("span", { role: "img", className: "inline-block size-[1em] shrink-0 text-current", title: icon2 ?? "Icon", children: "\u{1F9FF}" })
136
- };
145
+ preview: {
146
+ select: {
147
+ icon: "icon"
148
+ },
149
+ prepare({
150
+ icon
151
+ }) {
152
+ return {
153
+ media: renderValuePreview?.(icon) ?? defaultRenderIconPreview(icon)
154
+ };
155
+ }
137
156
  }
138
- }
139
- }), media = defineArrayMember({
157
+ });
158
+ }
159
+ const media = defineArrayMember({
140
160
  name: `${typeName}.span.media`,
141
161
  type: "object",
142
162
  title: "Inline Media",
@@ -163,8 +183,8 @@ const icon = defineArrayMember({
163
183
  }
164
184
  }
165
185
  });
166
- function createSpans() {
167
- return [icon, media];
186
+ function createSpans(options) {
187
+ return [createIconSpan(options?.icon), media];
168
188
  }
169
189
  const h2 = {
170
190
  title: "Heading 2",
@@ -203,6 +223,7 @@ function createStyles() {
203
223
  export {
204
224
  createAnnotations,
205
225
  createDecorators,
226
+ createIconSpan,
206
227
  createLists,
207
228
  createSpans,
208
229
  createStyles
package/dist/parts.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"parts.js","sources":["../src/parts/annotations/color.tsx","../src/parts/annotations/link.tsx","../src/parts/annotations/index.tsx","../src/parts/decorators/index.tsx","../src/parts/lists/index.tsx","../src/parts/spans/icon.tsx","../src/parts/spans/media.tsx","../src/parts/spans/index.tsx","../src/parts/styles/index.tsx"],"sourcesContent":["import { ColorWheelIcon, HighlightIcon } from \"@sanity/icons\";\nimport { defineField } from \"sanity\";\nimport { styled } from \"styled-components\";\nimport { typeName } from \"../../types\";\n\nconst ColorText = styled.span<{ color?: string }>`\n & > span {\n background-color: inherit;\n border-bottom: unset;\n color: ${({ color = \"inherit\" }) => color};\n }\n`;\n\nexport const textColor = defineField({\n type: \"object\",\n name: `${typeName}.annotation.textColor`,\n title: \"Text Color\",\n icon: ColorWheelIcon,\n fields: [defineField({ name: \"color\", type: \"wild.color\" })],\n components: {\n annotation: (props) => {\n // @ts-expect-error: Sanity types are not aware of the color field structure.\n const color = props.value?.color?.value as string;\n return <ColorText color={color}>{props.renderDefault(props)}</ColorText>;\n },\n },\n});\n\nconst ColorBg = styled.span<{ color?: string }>`\n & > span {\n background-color: ${({ color = \"inherit\" }) => color};\n border-bottom: unset;\n color: inherit;\n }\n`;\n\nexport const highlightColor = defineField({\n type: \"object\",\n name: `${typeName}.annotation.highlightColor`,\n title: \"Highlight Color\",\n icon: HighlightIcon,\n fields: [defineField({ name: \"color\", type: \"wild.color\" })],\n components: {\n annotation: (props) => {\n // @ts-expect-error: Sanity types are not aware of the color field structure.\n const color = props.value?.color?.value as string;\n return <ColorBg color={color}>{props.renderDefault(props)}</ColorBg>;\n },\n },\n});\n","import { LinkIcon } from \"@sanity/icons\";\nimport { defineField } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nexport const link = defineField({\n type: \"wild.link\",\n name: `${typeName}.annotation.link`,\n title: \"Link\",\n icon: LinkIcon,\n options: {\n collapsed: false,\n collapsible: false,\n },\n});\n","import { highlightColor, textColor } from \"./color\";\nimport { link } from \"./link\";\n\n/** @public */\nfunction createAnnotations() {\n return [link, textColor, highlightColor] as const;\n}\n\nexport { createAnnotations };\n","import { BoldIcon, CodeIcon, ItalicIcon } from \"@sanity/icons\";\nimport type { BlockDecoratorDefinition } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nconst strong = {\n title: \"Strong\",\n value: `${typeName}.decorator.strong`,\n icon: BoldIcon,\n component: ({ children }) => <strong>{children}</strong>,\n} as const satisfies BlockDecoratorDefinition;\n\nconst em = {\n title: \"Emphasis\",\n value: `${typeName}.decorator.em`,\n icon: ItalicIcon,\n component: ({ children }) => <em>{children}</em>,\n} as const satisfies BlockDecoratorDefinition;\n\nconst code = {\n title: \"Code\",\n value: `${typeName}.decorator.code`,\n icon: CodeIcon,\n component: ({ children }) => <code>{children}</code>,\n} as const satisfies BlockDecoratorDefinition;\n\nconst sup = {\n title: \"Sup\",\n value: `${typeName}.decorator.sup`,\n icon: () => <sup>[1]</sup>,\n component: ({ children }) => <sup style={{ verticalAlign: \"super\" }}>{children}</sup>,\n} as const satisfies BlockDecoratorDefinition;\n\n/** @public */\nfunction createDecorators() {\n return [strong, em, code, sup] as const;\n}\n\nexport { createDecorators };\n","import { OlistIcon, UlistIcon } from \"@sanity/icons\";\nimport type { BlockListDefinition } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nconst bullet = {\n title: \"Bullet\",\n value: `${typeName}.list.bullet`,\n icon: UlistIcon,\n} as const satisfies BlockListDefinition;\n\nconst number = {\n title: \"Number\",\n value: `${typeName}.list.number`,\n icon: OlistIcon,\n} as const satisfies BlockListDefinition;\n\n/** @public */\nfunction createLists() {\n return [bullet, number] as const;\n}\n\nexport { createLists };\n","import * as React from \"react\";\nimport { defineArrayMember, defineField } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nexport const icon = defineArrayMember({\n name: `${typeName}.span.icon`,\n type: \"object\",\n title: \"Icon\",\n description: \"Insert an icon.\",\n icon: () => <>🧿</>,\n fields: [defineField({ name: \"icon\", type: \"wild.icon\" })],\n components: {\n // This is the inline-preview in the PortableText editor.\n // It gets its props from the prepare function below.\n preview: (props) => {\n return React.isValidElement(props.media) ? props.media : props.fallbackTitle;\n },\n },\n preview: {\n select: {\n icon: \"icon\",\n },\n prepare({ icon }) {\n return {\n media: (\n <span role=\"img\" className=\"inline-block size-[1em] shrink-0 text-current\" title={icon ?? \"Icon\"}>\n 🧿\n </span>\n ),\n };\n },\n },\n});\n","import { defineArrayMember, defineField } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nexport const media = defineArrayMember({\n name: `${typeName}.span.media`,\n type: \"object\",\n title: \"Inline Media\",\n description: \"Embed inline video or image content.\",\n icon: () => <>🫧</>,\n fields: [\n defineField({\n name: \"media\",\n type: \"wild.media\",\n options: {\n inline: true,\n },\n }),\n ],\n components: {\n // This is the inline-preview in the PortableText editor.\n preview: (props) => {\n const icons = {\n video: <>🎥</>,\n image: <>🖼️</>,\n motion: <>🌀</>,\n };\n\n // @ts-expect-error: It gets its props from the prepare function below.\n return icons[props.kind as keyof typeof icons] || <>🖼️</>;\n },\n },\n preview: {\n select: {\n kind: \"media.kind\",\n },\n },\n});\n","import { icon } from \"./icon\";\nimport { media } from \"./media\";\n\n/** @public */\nfunction createSpans() {\n return [icon, media] as const;\n}\n\nexport { createSpans };\n","import type { BlockStyleDefinition } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nconst h2 = {\n title: \"Heading 2\",\n value: `${typeName}.style.h2`,\n component: ({ children }) => (\n <h2\n style={{\n fontSize: \"2.0625rem\",\n fontWeight: \"700\",\n lineHeight: \"calc(41 / 33)\",\n }}\n >\n {children}\n </h2>\n ),\n} as const satisfies BlockStyleDefinition;\n\nconst h3 = {\n title: \"Heading 3\",\n value: `${typeName}.style.h3`,\n component: ({ children }) => (\n <h3\n style={{\n fontSize: \"1.6875rem\",\n fontWeight: \"700\",\n lineHeight: \"calc(35 / 27)\",\n }}\n >\n {children}\n </h3>\n ),\n} as const satisfies BlockStyleDefinition;\n\nconst h4 = {\n title: \"Heading 4\",\n value: `${typeName}.style.h4`,\n component: ({ children }) => (\n <h4\n style={{\n fontSize: \"1.3125rem\",\n fontWeight: \"700\",\n lineHeight: \"calc(29 / 21)\",\n }}\n >\n {children}\n </h4>\n ),\n} as const satisfies BlockStyleDefinition;\n\n/** @public */\nfunction createStyles() {\n return [h2, h3, h4] as const;\n}\n\nexport { createStyles };\n"],"names":["ColorText","styled","span","color","textColor","defineField","type","name","typeName","title","icon","ColorWheelIcon","fields","components","annotation","props","value","renderDefault","ColorBg","highlightColor","HighlightIcon","link","LinkIcon","options","collapsed","collapsible","createAnnotations","strong","BoldIcon","component","children","em","ItalicIcon","code","CodeIcon","sup","verticalAlign","createDecorators","bullet","UlistIcon","number","OlistIcon","createLists","defineArrayMember","description","preview","React","isValidElement","media","fallbackTitle","select","prepare","inline","video","image","motion","kind","createSpans","h2","fontSize","fontWeight","lineHeight","h3","h4","createStyles"],"mappings":";;;;;;AAKA,MAAMA,YAAYC,OAAOC;AAAAA;AAAAA;AAAAA;AAAAA,aAIZ,CAAC;AAAA,EAAEC,QAAQ;AAAU,MAAMA,KAAK;AAAA;AAAA,GAIhCC,YAAYC,YAAY;AAAA,EACnCC,MAAM;AAAA,EACNC,MAAM,GAAGC,QAAQ;AAAA,EACjBC,OAAO;AAAA,EACPC,MAAMC;AAAAA,EACNC,QAAQ,CAACP,YAAY;AAAA,IAAEE,MAAM;AAAA,IAASD,MAAM;AAAA,EAAA,CAAc,CAAC;AAAA,EAC3DO,YAAY;AAAA,IACVC,YAAaC,CAAAA,UAAU;AAErB,YAAMZ,QAAQY,MAAMC,OAAOb,OAAOa;AAClC,iCAAQ,WAAA,EAAU,OAAeD,UAAAA,MAAME,cAAcF,KAAK,GAAE;AAAA,IAC9D;AAAA,EAAA;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A,EACPO,OAAO,GAAGR,QAAQ;AAAA,EAClBqB,WAAWA,CAAC;AAAA,IAAEC;AAAAA,EAAAA,MACZ,oBAAC,MAAA,EACC,OAAO;AAAA,IACL6B,UAAU;AAAA,IACVC,YAAY;AAAA,IACZC,YAAY;AAAA,EAAA,GAGb/B,SAAAA,CACH;AAEJ,GAEMiC,KAAK;AAAA,EACTtD,OAAO;AAAA,EACPO,OAAO,GAAGR,QAAQ;AAAA,EAClBqB,WAAWA,CAAC;AAAA,IAAEC;AAAAA,EAAAA,MACZ,oBAAC,MAAA,EACC,OAAO;AAAA,IACL6B,UAAU;AAAA,IACVC,YAAY;AAAA,IACZC,YAAY;AAAA,EAAA,GAGb/B,SAAAA,CACH;AAEJ;AAGA,SAASkC,eAAe;AACtB,SAAO,CAACN,IAAII,IAAIC,EAAE;AACpB;"}
1
+ {"version":3,"file":"parts.js","sources":["../src/parts/annotations/color.tsx","../src/parts/annotations/link.tsx","../src/parts/annotations/index.tsx","../src/parts/decorators/index.tsx","../src/parts/lists/index.tsx","../src/parts/spans/icon.tsx","../src/parts/spans/media.tsx","../src/parts/spans/index.tsx","../src/parts/styles/index.tsx"],"sourcesContent":["import { ColorWheelIcon, HighlightIcon } from \"@sanity/icons\";\nimport { defineField } from \"sanity\";\nimport { styled } from \"styled-components\";\nimport { typeName } from \"../../types\";\n\ntype ColorAnnotationOptions = {\n renderValue?: (value: string | undefined) => string | undefined;\n};\n\nconst ColorText = styled.span<{ $color?: string }>`\n & > span {\n background-color: inherit;\n border-bottom: unset;\n color: ${({ $color = \"inherit\" }) => $color};\n }\n`;\n\nfunction defaultResolveColor(value: string | undefined) {\n return value;\n}\n\nfunction createTextColorAnnotation(options?: ColorAnnotationOptions) {\n const renderValue = options?.renderValue ?? defaultResolveColor;\n\n return defineField({\n type: \"object\",\n name: `${typeName}.annotation.textColor`,\n title: \"Text Color\",\n icon: ColorWheelIcon,\n fields: [defineField({ name: \"color\", type: \"wild.color\" })],\n components: {\n annotation: (props) => {\n const value = renderValue(props.value?.color);\n return <ColorText $color={value}>{props.renderDefault(props)}</ColorText>;\n },\n },\n });\n}\n\nconst ColorBg = styled.span<{ $color?: string }>`\n & > span {\n background-color: ${({ $color = \"inherit\" }) => $color};\n border-bottom: unset;\n color: inherit;\n }\n`;\n\nfunction createHighlightColorAnnotation(options?: ColorAnnotationOptions) {\n const renderValue = options?.renderValue ?? defaultResolveColor;\n\n return defineField({\n type: \"object\",\n name: `${typeName}.annotation.highlightColor`,\n title: \"Highlight Color\",\n icon: HighlightIcon,\n fields: [defineField({ name: \"color\", type: \"wild.color\" })],\n components: {\n annotation: (props) => {\n const value = renderValue(props.value?.color);\n return <ColorBg $color={value}>{props.renderDefault(props)}</ColorBg>;\n },\n },\n });\n}\n\nexport { createTextColorAnnotation, createHighlightColorAnnotation, type ColorAnnotationOptions };\n","import { LinkIcon } from \"@sanity/icons\";\nimport { defineField } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nexport const link = defineField({\n type: \"wild.link\",\n name: `${typeName}.annotation.link`,\n title: \"Link\",\n icon: LinkIcon,\n options: {\n collapsed: false,\n collapsible: false,\n },\n});\n","import { type ColorAnnotationOptions, createHighlightColorAnnotation, createTextColorAnnotation } from \"./color\";\nimport { link } from \"./link\";\n\n/** @public */\nfunction createAnnotations(options?: { textColor?: ColorAnnotationOptions; highlightColor?: ColorAnnotationOptions }) {\n return [link, createTextColorAnnotation(options?.textColor), createHighlightColorAnnotation(options?.highlightColor)] as const;\n}\n\nexport { createAnnotations };\n","import { BoldIcon, CodeIcon, ItalicIcon } from \"@sanity/icons\";\nimport type { BlockDecoratorDefinition } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nconst strong = {\n title: \"Strong\",\n value: `${typeName}.decorator.strong`,\n icon: BoldIcon,\n component: ({ children }) => <strong>{children}</strong>,\n} as const satisfies BlockDecoratorDefinition;\n\nconst em = {\n title: \"Emphasis\",\n value: `${typeName}.decorator.em`,\n icon: ItalicIcon,\n component: ({ children }) => <em>{children}</em>,\n} as const satisfies BlockDecoratorDefinition;\n\nconst code = {\n title: \"Code\",\n value: `${typeName}.decorator.code`,\n icon: CodeIcon,\n component: ({ children }) => <code>{children}</code>,\n} as const satisfies BlockDecoratorDefinition;\n\nconst sup = {\n title: \"Sup\",\n value: `${typeName}.decorator.sup`,\n icon: () => <sup>[1]</sup>,\n component: ({ children }) => <sup style={{ verticalAlign: \"super\" }}>{children}</sup>,\n} as const satisfies BlockDecoratorDefinition;\n\n/** @public */\nfunction createDecorators() {\n return [strong, em, code, sup] as const;\n}\n\nexport { createDecorators };\n","import { OlistIcon, UlistIcon } from \"@sanity/icons\";\nimport type { BlockListDefinition } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nconst bullet = {\n title: \"Bullet\",\n value: `${typeName}.list.bullet`,\n icon: UlistIcon,\n} as const satisfies BlockListDefinition;\n\nconst number = {\n title: \"Number\",\n value: `${typeName}.list.number`,\n icon: OlistIcon,\n} as const satisfies BlockListDefinition;\n\n/** @public */\nfunction createLists() {\n return [bullet, number] as const;\n}\n\nexport { createLists };\n","import * as React from \"react\";\nimport { defineArrayMember, defineField } from \"sanity\";\nimport { typeName } from \"../../types\";\n\ntype IconSpanOptions = {\n renderValuePreview?: (value?: string) => React.ReactNode;\n};\n\nfunction defaultRenderIconPreview(value?: React.ReactNode) {\n if (React.isValidElement(value)) return value;\n return (\n <span role=\"img\" className=\"inline-block size-[1em] shrink-0 text-current\" title={typeof value === \"string\" ? value : \"Icon\"}>\n 🧿\n </span>\n );\n}\n\nfunction createIconSpan(options?: IconSpanOptions) {\n const renderValuePreview = options?.renderValuePreview;\n\n return defineArrayMember({\n name: `${typeName}.span.icon`,\n type: \"object\",\n title: \"Icon\",\n description: \"Insert an icon.\",\n icon: () => <>🧿</>,\n fields: [defineField({ name: \"icon\", type: \"wild.icon\" })],\n components: {\n // This is the inline-preview in the PortableText editor.\n // It gets its props from the prepare function below.\n preview: (props) => {\n return React.isValidElement(props.media) ? props.media : props.fallbackTitle;\n },\n },\n preview: {\n select: {\n icon: \"icon\",\n },\n prepare({ icon }) {\n return {\n media: renderValuePreview?.(icon) ?? defaultRenderIconPreview(icon),\n };\n },\n },\n });\n}\n\nexport { createIconSpan, type IconSpanOptions };\n","import { defineArrayMember, defineField } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nexport const media = defineArrayMember({\n name: `${typeName}.span.media`,\n type: \"object\",\n title: \"Inline Media\",\n description: \"Embed inline video or image content.\",\n icon: () => <>🫧</>,\n fields: [\n defineField({\n name: \"media\",\n type: \"wild.media\",\n options: {\n inline: true,\n },\n }),\n ],\n components: {\n // This is the inline-preview in the PortableText editor.\n preview: (props) => {\n const icons = {\n video: <>🎥</>,\n image: <>🖼️</>,\n motion: <>🌀</>,\n };\n\n // @ts-expect-error: It gets its props from the prepare function below.\n return icons[props.kind as keyof typeof icons] || <>🖼️</>;\n },\n },\n preview: {\n select: {\n kind: \"media.kind\",\n },\n },\n});\n","import { createIconSpan, type IconSpanOptions } from \"./icon\";\nimport { media } from \"./media\";\n\n/** @public */\nfunction createSpans(options?: { icon?: IconSpanOptions }) {\n return [createIconSpan(options?.icon), media] as const;\n}\n\nexport { createSpans };\n","import type { BlockStyleDefinition } from \"sanity\";\nimport { typeName } from \"../../types\";\n\nconst h2 = {\n title: \"Heading 2\",\n value: `${typeName}.style.h2`,\n component: ({ children }) => (\n <h2\n style={{\n fontSize: \"2.0625rem\",\n fontWeight: \"700\",\n lineHeight: \"calc(41 / 33)\",\n }}\n >\n {children}\n </h2>\n ),\n} as const satisfies BlockStyleDefinition;\n\nconst h3 = {\n title: \"Heading 3\",\n value: `${typeName}.style.h3`,\n component: ({ children }) => (\n <h3\n style={{\n fontSize: \"1.6875rem\",\n fontWeight: \"700\",\n lineHeight: \"calc(35 / 27)\",\n }}\n >\n {children}\n </h3>\n ),\n} as const satisfies BlockStyleDefinition;\n\nconst h4 = {\n title: \"Heading 4\",\n value: `${typeName}.style.h4`,\n component: ({ children }) => (\n <h4\n style={{\n fontSize: \"1.3125rem\",\n fontWeight: \"700\",\n lineHeight: \"calc(29 / 21)\",\n }}\n >\n {children}\n </h4>\n ),\n} as const satisfies BlockStyleDefinition;\n\n/** @public */\nfunction createStyles() {\n return [h2, h3, h4] as const;\n}\n\nexport { createStyles };\n"],"names":["ColorText","styled","span","$color","defaultResolveColor","value","createTextColorAnnotation","options","renderValue","defineField","type","name","typeName","title","icon","ColorWheelIcon","fields","components","annotation","props","color","renderDefault","ColorBg","createHighlightColorAnnotation","HighlightIcon","link","LinkIcon","collapsed","collapsible","createAnnotations","textColor","highlightColor","strong","BoldIcon","component","children","em","ItalicIcon","code","CodeIcon","sup","verticalAlign","createDecorators","bullet","UlistIcon","number","OlistIcon","createLists","defaultRenderIconPreview","React","isValidElement","createIconSpan","renderValuePreview","defineArrayMember","description","preview","media","fallbackTitle","select","prepare","inline","video","image","motion","kind","createSpans","h2","fontSize","fontWeight","lineHeight","h3","h4","createStyles"],"mappings":";;;;;;AASA,MAAMA,YAAYC,OAAOC;AAAAA;AAAAA;AAAAA;AAAAA,aAIZ,CAAC;AAAA,EAAEC,SAAS;AAAU,MAAMA,MAAM;AAAA;AAAA;AAI/C,SAASC,oBAAoBC,OAA2B;AACtD,SAAOA;AACT;AAEA,SAASC,0BAA0BC,SAAkC;AACnE,QAAMC,cAAcD,SAASC,eAAeJ;AAE5C,SAAOK,YAAY;AAAA,IACjBC,MAAM;AAAA,IACNC,MAAM,GAAGC,QAAQ;AAAA,IACjBC,OAAO;AAAA,IACPC,MAAMC;AAAAA,IACNC,QAAQ,CAACP,YAAY;AAAA,MAAEE,MAAM;AAAA,MAASD,MAAM;AAAA,IAAA,CAAc,CAAC;AAAA,IAC3DO,YAAY;AAAA,MACVC,YAAaC,CAAAA,UAAU;AACrB,cAAMd,QAAQG,YAAYW,MAAMd,OAAOe,KAAK;AAC5C,mCAAQ,WAAA,EAAU,QAAQf,OAAQc,UAAAA,MAAME,cAAcF,KAAK,GAAE;AAAA,MAC/D;AAAA,I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A,EACR;AAEJ,CAAC;AChCD,SAASC,YAAY1D,SAAsC;AACzD,SAAO,CAAC4C,eAAe5C,SAASO,IAAI,GAAG0C,KAAK;AAC9C;ACHA,MAAMU,KAAK;AAAA,EACTrD,OAAO;AAAA,EACPR,OAAO,GAAGO,QAAQ;AAAA,EAClBsB,WAAWA,CAAC;AAAA,IAAEC;AAAAA,EAAAA,MACZ,oBAAC,MAAA,EACC,OAAO;AAAA,IACLgC,UAAU;AAAA,IACVC,YAAY;AAAA,IACZC,YAAY;AAAA,EAAA,GAGblC,SAAAA,CACH;AAEJ,GAEMmC,KAAK;AAAA,EACTzD,OAAO;AAAA,EACPR,OAAO,GAAGO,QAAQ;AAAA,EAClBsB,WAAWA,CAAC;AAAA,IAAEC;AAAAA,EAAAA,MACZ,oBAAC,MAAA,EACC,OAAO;AAAA,IACLgC,UAAU;AAAA,IACVC,YAAY;AAAA,IACZC,YAAY;AAAA,EAAA,GAGblC,SAAAA,CACH;AAEJ,GAEMoC,KAAK;AAAA,EACT1D,OAAO;AAAA,EACPR,OAAO,GAAGO,QAAQ;AAAA,EAClBsB,WAAWA,CAAC;AAAA,IAAEC;AAAAA,EAAAA,MACZ,oBAAC,MAAA,EACC,OAAO;AAAA,IACLgC,UAAU;AAAA,IACVC,YAAY;AAAA,IACZC,YAAY;AAAA,EAAA,GAGblC,SAAAA,CACH;AAEJ;AAGA,SAASqC,eAAe;AACtB,SAAO,CAACN,IAAII,IAAIC,EAAE;AACpB;"}
package/dist/utils.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import * as sanity62 from "sanity";
1
+ import * as sanity92 from "sanity";
2
2
  import { ObjectDefinition } from "sanity";
3
3
  /**
4
4
  * Creates a schema definition for a new richtext block.
@@ -7,11 +7,11 @@ import { ObjectDefinition } from "sanity";
7
7
  declare function createBlock(block: ObjectDefinition): {
8
8
  type: "object";
9
9
  name?: string | undefined;
10
- } & Omit<sanity62.ArrayOfEntry<ObjectDefinition>, "preview"> & {
11
- preview?: sanity62.PreviewConfig<{
10
+ } & Omit<sanity92.ArrayOfEntry<ObjectDefinition>, "preview"> & {
11
+ preview?: sanity92.PreviewConfig<{
12
12
  [x: string]: string;
13
13
  }, Record<string, string>> | undefined;
14
- } & sanity62.WidenValidation & sanity62.WidenInitialValue;
14
+ } & sanity92.WidenValidation & sanity92.WidenInitialValue;
15
15
  /**
16
16
  * Reshapes the list kind of an array field.
17
17
  */
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as sanity87 from "sanity";
1
+ import * as sanity77 from "sanity";
2
2
  import { ObjectDefinition } from "sanity";
3
3
  /**
4
4
  * Creates a schema definition for a new richtext block.
@@ -7,11 +7,11 @@ import { ObjectDefinition } from "sanity";
7
7
  declare function createBlock(block: ObjectDefinition): {
8
8
  type: "object";
9
9
  name?: string | undefined;
10
- } & Omit<sanity87.ArrayOfEntry<ObjectDefinition>, "preview"> & {
11
- preview?: sanity87.PreviewConfig<{
10
+ } & Omit<sanity77.ArrayOfEntry<ObjectDefinition>, "preview"> & {
11
+ preview?: sanity77.PreviewConfig<{
12
12
  [x: string]: string;
13
13
  }, Record<string, string>> | undefined;
14
- } & sanity87.WidenValidation & sanity87.WidenInitialValue;
14
+ } & sanity77.WidenValidation & sanity77.WidenInitialValue;
15
15
  /**
16
16
  * Reshapes the list kind of an array field.
17
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madebywild/sanity-richtext-field",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "UNLICENSED",
@@ -53,7 +53,7 @@
53
53
  "dependencies": {
54
54
  "ts-deepmerge": "^7.0.3",
55
55
  "@madebywild/sanity-media-field": "1.0.0",
56
- "@madebywild/sanity-quote-field": "1.0.0",
56
+ "@madebywild/sanity-quote-field": "1.0.2",
57
57
  "@madebywild/sanity-utils": "1.0.0"
58
58
  },
59
59
  "peerDependencies": {