@madebywild/sanity-richtext-field 0.0.2 → 0.0.4

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.cjs CHANGED
@@ -1,9 +1,297 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- require("react/jsx-runtime");
4
- require("sanity");
5
- var index = require("./_chunks-cjs/index.cjs");
6
- exports.typeNameBasic = index.typeNameBasic;
7
- exports.typeNameExtended = index.typeNameExtended;
8
- exports.wildSanityRichtextFieldPlugin = index.wildSanityRichtextFieldPlugin;
3
+ var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), sanityMediaField = require("@madebywild/sanity-media-field"), React = require("react"), styled = require("styled-components");
4
+ function _interopDefaultCompat(e) {
5
+ return e && typeof e == "object" && "default" in e ? e : { default: e };
6
+ }
7
+ function _interopNamespaceCompat(e) {
8
+ if (e && typeof e == "object" && "default" in e) return e;
9
+ var n = /* @__PURE__ */ Object.create(null);
10
+ return e && Object.keys(e).forEach(function(k) {
11
+ if (k !== "default") {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: !0,
15
+ get: function() {
16
+ return e[k];
17
+ }
18
+ });
19
+ }
20
+ }), n.default = e, Object.freeze(n);
21
+ }
22
+ var React__namespace = /* @__PURE__ */ _interopNamespaceCompat(React), styled__default = /* @__PURE__ */ _interopDefaultCompat(styled);
23
+ const mediaBlock = sanity.defineArrayMember({
24
+ name: "wild.richtext.blocks.mediaBlock",
25
+ type: "object",
26
+ title: "Media Block",
27
+ description: "Embed block video or image content.",
28
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F5BC}\uFE0F" }),
29
+ fields: [
30
+ sanity.defineField({
31
+ title: "Wrap",
32
+ name: "wrapping",
33
+ type: "wild.wrapping"
34
+ }),
35
+ sanity.defineField({
36
+ name: "appMedia",
37
+ type: "wild.media",
38
+ options: {
39
+ withCustomRatio: !0,
40
+ withCustomOptions: !0
41
+ }
42
+ }),
43
+ sanity.defineField({
44
+ name: "caption",
45
+ type: "text",
46
+ rows: 2,
47
+ description: "Add a caption for the media."
48
+ })
49
+ ],
50
+ preview: {
51
+ select: {
52
+ type: "appMedia.type",
53
+ image: "appMedia.image",
54
+ playbackId: "appMedia.video.asset.playbackId",
55
+ thumbTime: "appMedia.video.asset.thumbTime"
56
+ },
57
+ prepare: (props) => sanityMediaField.buildMediaPreview(props)
58
+ }
59
+ }), blocks = [
60
+ mediaBlock
61
+ // Add block
62
+ ], LinkIcon = /* @__PURE__ */ React.forwardRef(function(props, ref) {
63
+ return /* @__PURE__ */ jsxRuntime.jsx(
64
+ "svg",
65
+ {
66
+ "data-sanity-icon": "link",
67
+ width: "1em",
68
+ height: "1em",
69
+ viewBox: "0 0 25 25",
70
+ fill: "none",
71
+ xmlns: "http://www.w3.org/2000/svg",
72
+ ...props,
73
+ ref,
74
+ children: /* @__PURE__ */ jsxRuntime.jsx(
75
+ "path",
76
+ {
77
+ d: "M11 12.5L12.5 14C13.281 14.781 14.719 14.781 15.5 14L18.5 11C19.281 10.219 19.281 8.78105 18.5 8L18 7.5C17.2189 6.71895 15.781 6.71895 15 7.5L13 9.5M12 15.5L10 17.5C9.21895 18.281 7.78105 18.281 7 17.5L6.5 17C5.71895 16.219 5.71896 14.781 6.5 14L9.50001 11C10.2811 10.219 11.719 10.2189 12.5 11L14 12.5",
78
+ stroke: "currentColor",
79
+ strokeWidth: 1.2,
80
+ strokeLinejoin: "round"
81
+ }
82
+ )
83
+ }
84
+ );
85
+ }), linkField = sanity.defineField({
86
+ type: "wild.link",
87
+ name: "linkField",
88
+ title: "Link",
89
+ icon: LinkIcon,
90
+ options: {
91
+ noCustomText: !0,
92
+ collapsed: !1,
93
+ collapsible: !1
94
+ }
95
+ }), ColorText = styled__default.default.span`
96
+ & > span {
97
+ background-color: inherit;
98
+ border-bottom: unset;
99
+ color: ${({ color = "inherit" }) => color};
100
+ }
101
+ `, textColorField = sanity.defineField({
102
+ type: "object",
103
+ name: "textColorField",
104
+ title: "Text Color",
105
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F58B}" }),
106
+ fields: [sanity.defineField({ name: "color", type: "wild.color" })],
107
+ components: {
108
+ annotation: (props) => {
109
+ const color = props.value?.color;
110
+ return /* @__PURE__ */ jsxRuntime.jsx(ColorText, { color, children: props.renderDefault(props) });
111
+ }
112
+ }
113
+ }), ColorBg = styled__default.default.span`
114
+ & > span {
115
+ background-color: ${({ color = "inherit" }) => color};
116
+ border-bottom: unset;
117
+ color: inherit;
118
+ }
119
+ `, highlightColorField = sanity.defineField({
120
+ type: "object",
121
+ name: "highlightColorField",
122
+ title: "Highlight Color",
123
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F58D}" }),
124
+ fields: [sanity.defineField({ name: "color", type: "wild.color" })],
125
+ components: {
126
+ annotation: (props) => {
127
+ const color = props.value?.color;
128
+ return /* @__PURE__ */ jsxRuntime.jsx(ColorBg, { color, children: props.renderDefault(props) });
129
+ }
130
+ }
131
+ }), appIconField = sanity.defineArrayMember({
132
+ name: "appIconField",
133
+ type: "object",
134
+ title: "Icon",
135
+ description: "Insert an icon.",
136
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F9FF}" }),
137
+ fields: [sanity.defineField({ name: "icon", type: "wild.icon" })],
138
+ components: {
139
+ // This is the inline-preview in the PortableText editor.
140
+ // It gets its props from the prepare function below.
141
+ preview: (props) => React__namespace.isValidElement(props.media) ? props.media : props.fallbackTitle
142
+ },
143
+ preview: {
144
+ select: {
145
+ icon: "icon"
146
+ },
147
+ prepare({ icon }) {
148
+ return {
149
+ media: /* @__PURE__ */ jsxRuntime.jsx("span", { role: "img", className: "inline-block size-[1em] shrink-0 text-current", title: icon ?? "Icon", children: "\u{1F9FF}" })
150
+ };
151
+ }
152
+ }
153
+ }), inlineMediaField = sanity.defineArrayMember({
154
+ name: "inlineMediaField",
155
+ type: "object",
156
+ title: "Inline Media",
157
+ description: "Embed inline video or image content.",
158
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1FAE7}" }),
159
+ fields: [
160
+ sanity.defineField({
161
+ name: "media",
162
+ type: "wild.media"
163
+ })
164
+ ],
165
+ components: {
166
+ // This is the inline-preview in the PortableText editor.
167
+ preview: (props) => ({
168
+ video: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F3A5}" }),
169
+ image: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F5BC}\uFE0F" }),
170
+ lottie: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F300}" }),
171
+ rive: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F36D}" })
172
+ })[props.type] || /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F5BC}\uFE0F" })
173
+ },
174
+ preview: {
175
+ select: {
176
+ type: "media.type"
177
+ }
178
+ }
179
+ }), typeNameBasic = "wild.richtext.basic", typeNameExtended = "wild.richtext.extended";
180
+ function StudioLayout(props) {
181
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
182
+ /* @__PURE__ */ jsxRuntime.jsx(
183
+ "style",
184
+ {
185
+ dangerouslySetInnerHTML: {
186
+ __html: `
187
+ fieldset [data-testid="pt-editor"][data-fullscreen="false"] {
188
+ height: var(--pt-editor-height, initial);
189
+ }
190
+ `
191
+ }
192
+ }
193
+ ),
194
+ props.renderDefault(props)
195
+ ] });
196
+ }
197
+ const wildSanityRichtextFieldPlugin = sanity.definePlugin((config) => {
198
+ const userBlocks = config?.blocks ?? [], userSpans = config?.spans ?? [], userDecorators = config?.decorators ?? [], userAnnotations = config?.annotations ?? [], userLists = config?.lists ?? [], userStyles = config?.styles ?? [];
199
+ return {
200
+ name: "@madebywild/sanity-richtext-field",
201
+ studio: {
202
+ components: {
203
+ layout: StudioLayout
204
+ }
205
+ },
206
+ schema: {
207
+ types: [
208
+ sanity.defineType({
209
+ name: typeNameBasic,
210
+ type: "array",
211
+ title: "Rich Text",
212
+ description: "Rich text content with formatting options.",
213
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u2328\uFE0F" }),
214
+ components: {
215
+ // biome-ignore lint/suspicious/noExplicitAny: Sanity doesn't provide these types.
216
+ field: (props) => (
217
+ // The CSS variable is used the set the min-height of the Portable Text editor.
218
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { "--pt-editor-height": "10rem" }, children: props.renderDefault({ ...props, initialActive: !0 }) })
219
+ )
220
+ },
221
+ of: [
222
+ sanity.defineArrayMember({
223
+ type: "block",
224
+ options: {
225
+ spellCheck: !1,
226
+ unstable_whitespaceOnPasteMode: "normalize"
227
+ },
228
+ of: [appIconField, inlineMediaField],
229
+ styles: [],
230
+ lists: [],
231
+ marks: {
232
+ annotations: [linkField],
233
+ decorators: [
234
+ { title: "Strong", value: "strong" },
235
+ { title: "Emphasis", value: "em" }
236
+ ]
237
+ }
238
+ })
239
+ ]
240
+ }),
241
+ sanity.defineType({
242
+ name: typeNameExtended,
243
+ type: "array",
244
+ title: "Rich Text",
245
+ description: "Rich text content with formatting options.",
246
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u2328\uFE0F" }),
247
+ components: {
248
+ // biome-ignore lint/suspicious/noExplicitAny: Sanity doesn't provide these types.
249
+ field: (props) => (
250
+ // The CSS variable is used the set the min-height of the Portable Text editor.
251
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { "--pt-editor-height": "50vh" }, children: props.renderDefault({ ...props, initialActive: !0 }) })
252
+ )
253
+ },
254
+ of: [
255
+ ...userBlocks,
256
+ ...blocks,
257
+ sanity.defineArrayMember({
258
+ type: "block",
259
+ options: {
260
+ spellCheck: config?.spellCheck ?? !0,
261
+ unstable_whitespaceOnPasteMode: "normalize"
262
+ },
263
+ of: [...userSpans, appIconField, inlineMediaField],
264
+ styles: [
265
+ ...userStyles,
266
+ { title: "Normal", value: "normal" },
267
+ { title: "Heading 2", value: "h2" },
268
+ { title: "Heading 3", value: "h3" },
269
+ { title: "Heading 4", value: "h4" }
270
+ ],
271
+ lists: [...userLists, { title: "Bullet", value: "bullet" }, { title: "Number", value: "number" }],
272
+ marks: {
273
+ annotations: [...userAnnotations, linkField, textColorField, highlightColorField],
274
+ decorators: [
275
+ ...userDecorators,
276
+ { title: "Strong", value: "strong" },
277
+ { title: "Emphasis", value: "em" },
278
+ { title: "Code", value: "code" },
279
+ {
280
+ title: "Sup",
281
+ value: "sup",
282
+ icon: () => /* @__PURE__ */ jsxRuntime.jsx("sup", { children: "[1]" }),
283
+ component: (props) => /* @__PURE__ */ jsxRuntime.jsx("sup", { style: { verticalAlign: "super" }, children: props.children })
284
+ }
285
+ ]
286
+ }
287
+ })
288
+ ]
289
+ })
290
+ ]
291
+ }
292
+ };
293
+ });
294
+ exports.typeNameBasic = typeNameBasic;
295
+ exports.typeNameExtended = typeNameExtended;
296
+ exports.wildSanityRichtextFieldPlugin = wildSanityRichtextFieldPlugin;
9
297
  //# sourceMappingURL=index.cjs.map