@sanity/presets 0.5.2 → 1.0.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.
- package/README.md +126 -36
- package/dist/index.js +410 -453
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -1,489 +1,446 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
1
|
import { uuid } from "@sanity/uuid";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
import { c } from "react/compiler-runtime";
|
|
4
4
|
import { useTelemetry } from "@sanity/telemetry/react";
|
|
5
|
-
import { useEffect } from "react";
|
|
6
5
|
import { defineEvent } from "@sanity/telemetry";
|
|
7
|
-
import {
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { ALL_FIELDS_GROUP, defineArrayMember, defineField, defineType } from "sanity";
|
|
8
8
|
import { getImageDimensions } from "@sanity/asset-utils";
|
|
9
9
|
const PresetsAdded = defineEvent({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
name: "Presets Added",
|
|
11
|
+
version: 1,
|
|
12
|
+
description: "Workspace using presets was accessed"
|
|
13
13
|
}), registries = /* @__PURE__ */ new Map();
|
|
14
14
|
function registerRegistry(id) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
registries.set(id, {
|
|
16
|
+
id,
|
|
17
|
+
presets: /* @__PURE__ */ new Set(),
|
|
18
|
+
logged: !1
|
|
19
|
+
});
|
|
20
20
|
}
|
|
21
21
|
function recordPresetUsage(registryId, identifier) {
|
|
22
|
-
|
|
22
|
+
registries.get(registryId)?.presets.add(identifier);
|
|
23
23
|
}
|
|
24
24
|
function collectPresetsRegistryTelemetry(registryId, telemetry) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
presetNames: [...record.presets]
|
|
28
|
-
}));
|
|
25
|
+
let record = registries.get(registryId);
|
|
26
|
+
!record || record.logged || (record.logged = !0, record.presets.size > 0 && telemetry.log(PresetsAdded, { presetNames: [...record.presets] }));
|
|
29
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* A transparent input component wrapper that triggers telemetry collection
|
|
30
|
+
* for the presets registry. Renders the user-provided input component if
|
|
31
|
+
* supplied, otherwise the default input component unchanged.
|
|
32
|
+
*
|
|
33
|
+
* Attached to every schema type produced by a define<Type> function via
|
|
34
|
+
* components.input. The first instance to render for a given registry id
|
|
35
|
+
* submits the PresetsAdded telemetry event; subsequent renders are no-ops.
|
|
36
|
+
*/
|
|
30
37
|
const PresetsTelemetryCollector = (t0) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} = t0, telemetry = useTelemetry();
|
|
36
|
-
let t1, t2;
|
|
37
|
-
return $[0] !== registryId || $[1] !== telemetry ? (t1 = () => {
|
|
38
|
-
collectPresetsRegistryTelemetry(registryId, telemetry);
|
|
39
|
-
}, t2 = [registryId, telemetry], $[0] = registryId, $[1] = telemetry, $[2] = t1, $[3] = t2) : (t1 = $[2], t2 = $[3]), useEffect(t1, t2), UserInput ? /* @__PURE__ */ jsx(UserInput, { ...props }) : props.renderDefault(props);
|
|
40
|
-
};
|
|
41
|
-
const ctaType = {
|
|
42
|
-
name: "cta",
|
|
43
|
-
identifier: "core.cta",
|
|
44
|
-
schemaType: (config, registry) => {
|
|
45
|
-
const {
|
|
46
|
-
fields,
|
|
47
|
-
...objectConfig
|
|
48
|
-
} = config;
|
|
49
|
-
return defineType({
|
|
50
|
-
...objectConfig,
|
|
51
|
-
type: "object",
|
|
52
|
-
fields: [registry.getPreset("link", {
|
|
53
|
-
name: "link",
|
|
54
|
-
title: "Link"
|
|
55
|
-
}), defineField({
|
|
56
|
-
name: "level",
|
|
57
|
-
title: "Level",
|
|
58
|
-
description: "The importance of the action relative to its siblings: level 1 being the primary action, 2 the secondary action, and so on.",
|
|
59
|
-
type: "number",
|
|
60
|
-
options: {
|
|
61
|
-
layout: "radio",
|
|
62
|
-
list: [1, 2, 3]
|
|
63
|
-
}
|
|
64
|
-
}), ...fields ?? []],
|
|
65
|
-
preview: {
|
|
66
|
-
select: {
|
|
67
|
-
linkType: "link.linkType",
|
|
68
|
-
url: "link.url",
|
|
69
|
-
referenceTitle: "link.reference.title",
|
|
70
|
-
referenceName: "link.reference.name"
|
|
71
|
-
},
|
|
72
|
-
prepare({
|
|
73
|
-
linkType: linkType2,
|
|
74
|
-
url,
|
|
75
|
-
referenceTitle,
|
|
76
|
-
referenceName
|
|
77
|
-
}) {
|
|
78
|
-
return {
|
|
79
|
-
title: linkType2 === "external" ? url || "No URL" : referenceTitle || referenceName || "No reference",
|
|
80
|
-
subtitle: "Button"
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}, imageType = {
|
|
87
|
-
name: "image",
|
|
88
|
-
identifier: "core.image",
|
|
89
|
-
schemaType: (config) => {
|
|
90
|
-
const {
|
|
91
|
-
altText = !0,
|
|
92
|
-
caption = !0,
|
|
93
|
-
hotspot = !0,
|
|
94
|
-
fields,
|
|
95
|
-
...imageConfig
|
|
96
|
-
} = config;
|
|
97
|
-
return defineType({
|
|
98
|
-
...imageConfig,
|
|
99
|
-
type: "image",
|
|
100
|
-
// hotspot is the curated default; callers override other image options (accept, sources, storeOriginalFilename) via the map.options hook
|
|
101
|
-
options: {
|
|
102
|
-
hotspot
|
|
103
|
-
},
|
|
104
|
-
fields: [...altText ? [defineField({
|
|
105
|
-
name: "altText",
|
|
106
|
-
title: "Alt text",
|
|
107
|
-
description: "Describes the image for screen readers and search engines. Important for accessibility.",
|
|
108
|
-
type: "string",
|
|
109
|
-
validation: (rule) => rule.warning("Alt text improves accessibility.")
|
|
110
|
-
})] : [], ...caption ? [defineField({
|
|
111
|
-
name: "caption",
|
|
112
|
-
title: "Caption",
|
|
113
|
-
type: "text"
|
|
114
|
-
})] : [], ...fields ?? []],
|
|
115
|
-
preview: {
|
|
116
|
-
select: {
|
|
117
|
-
title: altText ? "altText" : caption ? "caption" : "asset.originalFilename"
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
38
|
+
let $ = c(4), { registryId, userInput: UserInput, ...props } = t0, telemetry = useTelemetry(), t1, t2;
|
|
39
|
+
return $[0] !== registryId || $[1] !== telemetry ? (t1 = () => {
|
|
40
|
+
collectPresetsRegistryTelemetry(registryId, telemetry);
|
|
41
|
+
}, t2 = [registryId, telemetry], $[0] = registryId, $[1] = telemetry, $[2] = t1, $[3] = t2) : (t1 = $[2], t2 = $[3]), useEffect(t1, t2), UserInput ? /* @__PURE__ */ jsx(UserInput, { ...props }) : props.renderDefault(props);
|
|
122
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* A typed passthrough for defining a preset. Given a `PresetDefinition`, it
|
|
45
|
+
* returns the same value, narrowed to its concrete generic parameters so
|
|
46
|
+
* downstream code can infer the preset's config type from it.
|
|
47
|
+
*
|
|
48
|
+
* This is intentionally lightweight: it performs no work at call time. The
|
|
49
|
+
* registry is responsible for invoking `schemaType` when a preset is
|
|
50
|
+
* instantiated, and for applying `map` hooks to the produced schema type.
|
|
51
|
+
*/
|
|
52
|
+
function definePresetType(preset) {
|
|
53
|
+
return preset;
|
|
54
|
+
}
|
|
55
|
+
const ctaType = definePresetType({
|
|
56
|
+
name: "cta",
|
|
57
|
+
identifier: "core.cta",
|
|
58
|
+
schemaType: (config, registry) => {
|
|
59
|
+
let { fields, ...objectConfig } = config;
|
|
60
|
+
return defineType({
|
|
61
|
+
...objectConfig,
|
|
62
|
+
type: "object",
|
|
63
|
+
fields: [
|
|
64
|
+
registry.getPreset("link", {
|
|
65
|
+
name: "link",
|
|
66
|
+
title: "Link"
|
|
67
|
+
}),
|
|
68
|
+
defineField({
|
|
69
|
+
name: "level",
|
|
70
|
+
title: "Level",
|
|
71
|
+
description: "The importance of the action relative to its siblings: level 1 being the primary action, 2 the secondary action, and so on.",
|
|
72
|
+
type: "number",
|
|
73
|
+
options: {
|
|
74
|
+
layout: "radio",
|
|
75
|
+
list: [
|
|
76
|
+
1,
|
|
77
|
+
2,
|
|
78
|
+
3
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
}),
|
|
82
|
+
...fields ?? []
|
|
83
|
+
],
|
|
84
|
+
preview: {
|
|
85
|
+
select: {
|
|
86
|
+
linkType: "link.linkType",
|
|
87
|
+
url: "link.url",
|
|
88
|
+
referenceTitle: "link.reference.title",
|
|
89
|
+
referenceName: "link.reference.name"
|
|
90
|
+
},
|
|
91
|
+
prepare({ linkType, url, referenceTitle, referenceName }) {
|
|
92
|
+
return {
|
|
93
|
+
title: linkType === "external" ? url || "No URL" : referenceTitle || referenceName || "No reference",
|
|
94
|
+
subtitle: "Button"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}), imageType = definePresetType({
|
|
101
|
+
name: "image",
|
|
102
|
+
identifier: "core.image",
|
|
103
|
+
schemaType: (config) => {
|
|
104
|
+
let { altText = !0, caption = !0, hotspot = !0, fields, ...imageConfig } = config;
|
|
105
|
+
return defineType({
|
|
106
|
+
...imageConfig,
|
|
107
|
+
type: "image",
|
|
108
|
+
options: { hotspot },
|
|
109
|
+
fields: [
|
|
110
|
+
...altText ? [defineField({
|
|
111
|
+
name: "altText",
|
|
112
|
+
title: "Alt text",
|
|
113
|
+
description: "Describes the image for screen readers and search engines. Important for accessibility.",
|
|
114
|
+
type: "string",
|
|
115
|
+
validation: (rule) => rule.warning("Alt text improves accessibility.")
|
|
116
|
+
})] : [],
|
|
117
|
+
...caption ? [defineField({
|
|
118
|
+
name: "caption",
|
|
119
|
+
title: "Caption",
|
|
120
|
+
type: "text"
|
|
121
|
+
})] : [],
|
|
122
|
+
...fields ?? []
|
|
123
|
+
],
|
|
124
|
+
preview: { select: { title: altText ? "altText" : caption ? "caption" : "asset.originalFilename" } }
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
123
128
|
function normalizeToTargets(entries) {
|
|
124
|
-
|
|
125
|
-
type: entry
|
|
126
|
-
} : entry);
|
|
129
|
+
return entries.map((entry) => typeof entry == "string" ? { type: entry } : entry);
|
|
127
130
|
}
|
|
128
|
-
const linkType = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
};
|
|
131
|
+
const linkType = definePresetType({
|
|
132
|
+
name: "link",
|
|
133
|
+
identifier: "core.link",
|
|
134
|
+
schemaType: ({ to, fields, ...objectConfig }) => {
|
|
135
|
+
let referenceTargets = normalizeToTargets(to ?? []);
|
|
136
|
+
return defineType({
|
|
137
|
+
...objectConfig,
|
|
138
|
+
type: "object",
|
|
139
|
+
fields: [
|
|
140
|
+
defineField({
|
|
141
|
+
name: "linkType",
|
|
142
|
+
type: "string",
|
|
143
|
+
title: "Link Type",
|
|
144
|
+
description: "Internal links point to a page in this project. External links point to a full URL.",
|
|
145
|
+
initialValue: "internal",
|
|
146
|
+
options: {
|
|
147
|
+
layout: "radio",
|
|
148
|
+
list: [{
|
|
149
|
+
title: "Internal",
|
|
150
|
+
value: "internal"
|
|
151
|
+
}, {
|
|
152
|
+
title: "External",
|
|
153
|
+
value: "external"
|
|
154
|
+
}]
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
defineField({
|
|
158
|
+
name: "reference",
|
|
159
|
+
type: "reference",
|
|
160
|
+
title: "Internal Link",
|
|
161
|
+
to: referenceTargets,
|
|
162
|
+
hidden: ({ parent }) => parent?.linkType === "external"
|
|
163
|
+
}),
|
|
164
|
+
defineField({
|
|
165
|
+
name: "url",
|
|
166
|
+
type: "url",
|
|
167
|
+
title: "URL",
|
|
168
|
+
description: "Full URL including protocol, e.g. https://example.com. Supports http, https, mailto, and tel.",
|
|
169
|
+
hidden: ({ parent }) => parent?.linkType === "internal",
|
|
170
|
+
validation: (rule) => rule.uri({ scheme: [
|
|
171
|
+
"http",
|
|
172
|
+
"https",
|
|
173
|
+
"mailto",
|
|
174
|
+
"tel"
|
|
175
|
+
] })
|
|
176
|
+
}),
|
|
177
|
+
defineField({
|
|
178
|
+
name: "openInNewTab",
|
|
179
|
+
type: "boolean",
|
|
180
|
+
title: "Open in New Tab",
|
|
181
|
+
initialValue: !1,
|
|
182
|
+
hidden: ({ parent }) => parent?.linkType === "internal"
|
|
183
|
+
}),
|
|
184
|
+
...fields ?? []
|
|
185
|
+
],
|
|
186
|
+
preview: {
|
|
187
|
+
select: {
|
|
188
|
+
linkType: "linkType",
|
|
189
|
+
url: "url",
|
|
190
|
+
referenceTitle: "reference.title",
|
|
191
|
+
referenceName: "reference.name"
|
|
192
|
+
},
|
|
193
|
+
prepare({ linkType, url, referenceTitle, referenceName }) {
|
|
194
|
+
return {
|
|
195
|
+
title: linkType === "external" ? url || "No URL" : referenceTitle || referenceName || "No reference",
|
|
196
|
+
subtitle: linkType === "external" ? "External link" : "Internal link"
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
206
203
|
function wrapArrayAsPageBuilderBlock(arraySchema) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
204
|
+
let components = "components" in arraySchema ? arraySchema.components : void 0;
|
|
205
|
+
return defineArrayMember({
|
|
206
|
+
name: arraySchema.name,
|
|
207
|
+
title: arraySchema.title,
|
|
208
|
+
type: "object",
|
|
209
|
+
fields: [defineField({
|
|
210
|
+
name: "content",
|
|
211
|
+
type: "array",
|
|
212
|
+
of: arraySchema.of,
|
|
213
|
+
components
|
|
214
|
+
})]
|
|
215
|
+
});
|
|
219
216
|
}
|
|
220
217
|
function toPageBuilderArrayMember(block, lookupArrayPreset) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
return block.type === "array" ? wrapArrayAsPageBuilderBlock(block) : defineArrayMember(block);
|
|
218
|
+
if (typeof block == "string") {
|
|
219
|
+
let arrayPreset = lookupArrayPreset(block);
|
|
220
|
+
return arrayPreset ? wrapArrayAsPageBuilderBlock(arrayPreset) : defineArrayMember({ type: block });
|
|
221
|
+
}
|
|
222
|
+
return block.type === "array" ? wrapArrayAsPageBuilderBlock(block) : defineArrayMember(block);
|
|
228
223
|
}
|
|
229
224
|
function defineLazyContentField(blocks, lookupArrayPreset) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
225
|
+
let cached;
|
|
226
|
+
return defineField({
|
|
227
|
+
name: "content",
|
|
228
|
+
title: "Content",
|
|
229
|
+
description: "Page sections rendered in order. Add, remove, or reorder blocks to build the page.",
|
|
230
|
+
group: "main",
|
|
231
|
+
type: "array",
|
|
232
|
+
get of() {
|
|
233
|
+
return cached ??= blocks.map((block) => toPageBuilderArrayMember(block, lookupArrayPreset)), cached;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
241
236
|
}
|
|
242
|
-
function createPageType({
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
237
|
+
function createPageType({ lookupArrayPreset }) {
|
|
238
|
+
return definePresetType({
|
|
239
|
+
name: "page",
|
|
240
|
+
identifier: "core.page",
|
|
241
|
+
schemaType: (config, registry) => {
|
|
242
|
+
let { pageBuilderBlocks, groups, fields, ...documentConfig } = config;
|
|
243
|
+
return defineType({
|
|
244
|
+
...documentConfig,
|
|
245
|
+
type: "document",
|
|
246
|
+
groups: [
|
|
247
|
+
{
|
|
248
|
+
...ALL_FIELDS_GROUP,
|
|
249
|
+
hidden: !0
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "main",
|
|
253
|
+
title: "Main",
|
|
254
|
+
default: !0
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: "metadata",
|
|
258
|
+
title: "Metadata"
|
|
259
|
+
},
|
|
260
|
+
...groups ?? []
|
|
261
|
+
],
|
|
262
|
+
fields: [
|
|
263
|
+
defineField({
|
|
264
|
+
name: "name",
|
|
265
|
+
title: "Name",
|
|
266
|
+
description: "Used as the page title and as the source for the auto-generated slug.",
|
|
267
|
+
type: "string",
|
|
268
|
+
group: "main",
|
|
269
|
+
validation: (rule) => rule.required()
|
|
270
|
+
}),
|
|
271
|
+
defineField({
|
|
272
|
+
name: "slug",
|
|
273
|
+
title: "Slug",
|
|
274
|
+
type: "slug",
|
|
275
|
+
group: "main",
|
|
276
|
+
options: { source: "name" }
|
|
277
|
+
}),
|
|
278
|
+
defineLazyContentField(pageBuilderBlocks ?? [], lookupArrayPreset),
|
|
279
|
+
registry.getPreset("seo", {
|
|
280
|
+
name: "seo",
|
|
281
|
+
title: "SEO",
|
|
282
|
+
group: "metadata"
|
|
283
|
+
}),
|
|
284
|
+
...fields ?? []
|
|
285
|
+
]
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
});
|
|
292
289
|
}
|
|
290
|
+
createPageType({ lookupArrayPreset: () => void 0 });
|
|
293
291
|
function resolveObjects(objects) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
link,
|
|
311
|
-
image,
|
|
312
|
-
cta
|
|
313
|
-
};
|
|
292
|
+
if (objects === !1) return {
|
|
293
|
+
link: !1,
|
|
294
|
+
image: !1,
|
|
295
|
+
cta: !1
|
|
296
|
+
};
|
|
297
|
+
if (objects === !0 || objects === void 0) return {
|
|
298
|
+
link: !0,
|
|
299
|
+
image: !0,
|
|
300
|
+
cta: !0
|
|
301
|
+
};
|
|
302
|
+
let { link = !0, image = !0, cta = !0 } = objects;
|
|
303
|
+
return {
|
|
304
|
+
link,
|
|
305
|
+
image,
|
|
306
|
+
cta
|
|
307
|
+
};
|
|
314
308
|
}
|
|
315
|
-
const richTextType = {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
aspectRatio: 1.91 / 1
|
|
381
|
-
}]
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
validation: (Rule) => Rule.custom((value) => {
|
|
385
|
-
if (!value?.asset?._ref)
|
|
386
|
-
return !0;
|
|
387
|
-
const {
|
|
388
|
-
height,
|
|
389
|
-
width
|
|
390
|
-
} = getImageDimensions(value.asset?._ref);
|
|
391
|
-
return height !== 630 || width !== 1200 ? "Open Graph images are recommended to be exactly 1200x630 (1.91:1) for the best social sharing previews." : !0;
|
|
392
|
-
}).warning()
|
|
393
|
-
}), ...fields ?? []]
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
};
|
|
309
|
+
const richTextType = definePresetType({
|
|
310
|
+
name: "richText",
|
|
311
|
+
identifier: "core.richText",
|
|
312
|
+
schemaType: (config, registry) => {
|
|
313
|
+
let { objects, ...arrayConfig } = config, { link, image, cta } = resolveObjects(objects), linkAnnotation = link ? registry.getPreset("link", {
|
|
314
|
+
name: "link",
|
|
315
|
+
title: "Link"
|
|
316
|
+
}) : void 0, ctaInline = cta ? registry.getPreset("cta", {
|
|
317
|
+
name: "cta",
|
|
318
|
+
title: "CTA"
|
|
319
|
+
}) : void 0, imageMember = image ? registry.getPreset("image", {
|
|
320
|
+
name: "richTextImage",
|
|
321
|
+
title: "Image"
|
|
322
|
+
}) : void 0, blockMember = defineArrayMember({
|
|
323
|
+
type: "block",
|
|
324
|
+
marks: { annotations: linkAnnotation ? [linkAnnotation] : [] },
|
|
325
|
+
...ctaInline && { of: [ctaInline] }
|
|
326
|
+
});
|
|
327
|
+
return defineType({
|
|
328
|
+
...arrayConfig,
|
|
329
|
+
type: "array",
|
|
330
|
+
of: imageMember ? [blockMember, imageMember] : [blockMember]
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}), seoType = definePresetType({
|
|
334
|
+
name: "seo",
|
|
335
|
+
identifier: "core.seo",
|
|
336
|
+
schemaType: (config) => {
|
|
337
|
+
let { fields, ...objectConfig } = config;
|
|
338
|
+
return defineType({
|
|
339
|
+
...objectConfig,
|
|
340
|
+
type: "object",
|
|
341
|
+
fields: [
|
|
342
|
+
defineField({
|
|
343
|
+
name: "title",
|
|
344
|
+
title: "Title",
|
|
345
|
+
type: "string",
|
|
346
|
+
validation: (rule) => rule.max(70).info("Search engines may truncate this title.")
|
|
347
|
+
}),
|
|
348
|
+
defineField({
|
|
349
|
+
name: "description",
|
|
350
|
+
title: "Description",
|
|
351
|
+
type: "text",
|
|
352
|
+
validation: (rule) => rule.max(150).info("Search engines may truncate this description.")
|
|
353
|
+
}),
|
|
354
|
+
defineField({
|
|
355
|
+
name: "ogImage",
|
|
356
|
+
title: "Open Graph image",
|
|
357
|
+
type: "image",
|
|
358
|
+
description: "Landscape 1200x630 (1.91:1)",
|
|
359
|
+
options: { hotspot: { previews: [{
|
|
360
|
+
title: "Landscape (1.91:1)",
|
|
361
|
+
aspectRatio: 1.91 / 1
|
|
362
|
+
}] } },
|
|
363
|
+
validation: (Rule) => Rule.custom((value) => {
|
|
364
|
+
if (!value?.asset?._ref) return !0;
|
|
365
|
+
let { height, width } = getImageDimensions(value.asset?._ref);
|
|
366
|
+
return height !== 630 || width !== 1200 ? "Open Graph images are recommended to be exactly 1200x630 (1.91:1) for the best social sharing previews." : !0;
|
|
367
|
+
}).warning()
|
|
368
|
+
}),
|
|
369
|
+
...fields ?? []
|
|
370
|
+
]
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
});
|
|
397
374
|
function createPresetsRegistry(config = {}) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
375
|
+
let registryId = uuid();
|
|
376
|
+
registerRegistry(registryId);
|
|
377
|
+
let seed = {}, registeredSchemas = /* @__PURE__ */ new Map();
|
|
378
|
+
return [
|
|
379
|
+
linkType,
|
|
380
|
+
ctaType,
|
|
381
|
+
seoType,
|
|
382
|
+
imageType,
|
|
383
|
+
createPageType({ lookupArrayPreset: (name) => {
|
|
384
|
+
let registered = registeredSchemas.get(name);
|
|
385
|
+
return registered?.type === "array" ? registered : void 0;
|
|
386
|
+
} }),
|
|
387
|
+
richTextType
|
|
388
|
+
].reduce((registry, preset) => {
|
|
389
|
+
let key = getPresetKey(preset.name);
|
|
390
|
+
return registry[key] = createDefiner({
|
|
391
|
+
registryId,
|
|
392
|
+
preset,
|
|
393
|
+
config,
|
|
394
|
+
registry,
|
|
395
|
+
registeredSchemas
|
|
396
|
+
}), registry;
|
|
397
|
+
}, seed);
|
|
416
398
|
}
|
|
417
399
|
function getPresetKey(name) {
|
|
418
|
-
|
|
400
|
+
return `define${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
419
401
|
}
|
|
420
|
-
function createRegistryContext({
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
if (!definer)
|
|
427
|
-
throw new Error(`Cannot resolve preset "${name}". No such preset in this registry.`);
|
|
428
|
-
return definer(presetConfig);
|
|
429
|
-
}
|
|
430
|
-
};
|
|
402
|
+
function createRegistryContext({ registry }) {
|
|
403
|
+
return { getPreset: (name, presetConfig) => {
|
|
404
|
+
let definer = registry[getPresetKey(name)];
|
|
405
|
+
if (!definer) throw Error(`Cannot resolve preset "${name}". No such preset in this registry.`);
|
|
406
|
+
return definer(presetConfig);
|
|
407
|
+
} };
|
|
431
408
|
}
|
|
432
|
-
function createDefiner({
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
recordPresetUsage(registryId, preset.identifier ?? "unnamed");
|
|
444
|
-
const registryContext = createRegistryContext({
|
|
445
|
-
registry
|
|
446
|
-
}), registryDefaults = config[preset.name], mergedConfig = {
|
|
447
|
-
...typeof registryDefaults == "object" && registryDefaults !== null ? registryDefaults : {},
|
|
448
|
-
...userConfig
|
|
449
|
-
}, {
|
|
450
|
-
map,
|
|
451
|
-
...factoryConfig
|
|
452
|
-
} = mergedConfig, schemaType = preset.schemaType(
|
|
453
|
-
// oxlint-disable-next-line no-unsafe-type-assertion -- factoryConfig is the merged user config (minus `map`, with `name` injected); its shape matches the factory's expected parameter at runtime
|
|
454
|
-
factoryConfig,
|
|
455
|
-
registryContext
|
|
456
|
-
);
|
|
457
|
-
return registeredSchemas.set(name, schemaType), applyMapHooks(addTelemetryComponent(schemaType, registryId), map);
|
|
458
|
-
};
|
|
409
|
+
function createDefiner({ registryId, preset, config, registry, registeredSchemas }) {
|
|
410
|
+
return function(userConfig = {}) {
|
|
411
|
+
let name = userConfig.name;
|
|
412
|
+
if (typeof name != "string" || name.length === 0) throw Error(`${getPresetKey(preset.name)}: "name" is required. Pass {name: "yourTypeName"}.`);
|
|
413
|
+
recordPresetUsage(registryId, preset.identifier ?? "unnamed");
|
|
414
|
+
let registryContext = createRegistryContext({ registry }), registryDefaults = config[preset.name], { map, ...factoryConfig } = {
|
|
415
|
+
...typeof registryDefaults == "object" && registryDefaults ? registryDefaults : {},
|
|
416
|
+
...userConfig
|
|
417
|
+
}, schemaType = preset.schemaType(factoryConfig, registryContext);
|
|
418
|
+
return registeredSchemas.set(name, schemaType), applyMapHooks(addTelemetryComponent(schemaType, registryId), map);
|
|
419
|
+
};
|
|
459
420
|
}
|
|
460
421
|
function applyMapHooks(schemaType, map) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
return {
|
|
469
|
-
...schemaType,
|
|
470
|
-
...mappedSchemaType
|
|
471
|
-
};
|
|
422
|
+
if (!map || typeof map != "object") return schemaType;
|
|
423
|
+
let mappedSchemaType = {};
|
|
424
|
+
for (let [configName, configValue] of Object.entries(map)) typeof configValue == "function" && (mappedSchemaType[configName] = configValue(schemaType[configName]));
|
|
425
|
+
return {
|
|
426
|
+
...schemaType,
|
|
427
|
+
...mappedSchemaType
|
|
428
|
+
};
|
|
472
429
|
}
|
|
473
430
|
function addTelemetryComponent(schemaType, registryId) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
431
|
+
let existing = "components" in schemaType ? schemaType.components : void 0, existingInput = existing && "input" in existing && typeof existing.input == "function" ? existing.input : void 0;
|
|
432
|
+
return {
|
|
433
|
+
...schemaType,
|
|
434
|
+
components: {
|
|
435
|
+
...existing,
|
|
436
|
+
input: (props) => /* @__PURE__ */ jsx(PresetsTelemetryCollector, {
|
|
437
|
+
...props,
|
|
438
|
+
registryId,
|
|
439
|
+
userInput: existingInput
|
|
440
|
+
})
|
|
441
|
+
}
|
|
442
|
+
};
|
|
485
443
|
}
|
|
486
|
-
export {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
//# sourceMappingURL=index.js.map
|
|
444
|
+
export { createPresetsRegistry };
|
|
445
|
+
|
|
446
|
+
//# sourceMappingURL=index.js.map
|