@madebywild/sanity-richtext-field 0.1.0 → 0.1.2
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 +26 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -16
- package/dist/index.d.ts +14 -14
- package/dist/index.js +26 -26
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
- package/src/index.tsx +2 -24
- package/src/input.tsx +8 -1
- package/src/parts/annotations/color.tsx +2 -2
- package/src/parts/annotations/link.tsx +1 -1
- package/src/parts/blocks/media-block.tsx +2 -2
- package/src/parts/index.tsx +3 -3
- package/src/parts/spans/icon.tsx +1 -1
- package/src/parts/spans/media.tsx +1 -1
- package/src/presets.tsx +19 -0
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), o = require("react"), icons = require("@sanity/icons"), sanityMediaField = require("@madebywild/sanity-media-field");
|
|
3
|
+
var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), o = require("react"), tsDeepmerge = require("ts-deepmerge"), icons = require("@sanity/icons"), sanityMediaField = require("@madebywild/sanity-media-field");
|
|
4
4
|
function _interopNamespaceCompat(e) {
|
|
5
5
|
if (e && typeof e == "object" && "default" in e) return e;
|
|
6
6
|
var n = /* @__PURE__ */ Object.create(null);
|
|
@@ -1173,7 +1173,7 @@ const ColorText = dt.span`
|
|
|
1173
1173
|
}
|
|
1174
1174
|
`, textColor = sanity.defineField({
|
|
1175
1175
|
type: "object",
|
|
1176
|
-
name: `${typeName}.
|
|
1176
|
+
name: `${typeName}.annotation.textColor`,
|
|
1177
1177
|
title: "Text Color",
|
|
1178
1178
|
icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F58B}" }),
|
|
1179
1179
|
fields: [sanity.defineField({ name: "color", type: "wild.color" })],
|
|
@@ -1191,7 +1191,7 @@ const ColorText = dt.span`
|
|
|
1191
1191
|
}
|
|
1192
1192
|
`, highlightColor = sanity.defineField({
|
|
1193
1193
|
type: "object",
|
|
1194
|
-
name: `${typeName}.
|
|
1194
|
+
name: `${typeName}.annotation.highlightColor`,
|
|
1195
1195
|
title: "Highlight Color",
|
|
1196
1196
|
icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u{1F58D}" }),
|
|
1197
1197
|
fields: [sanity.defineField({ name: "color", type: "wild.color" })],
|
|
@@ -1203,7 +1203,7 @@ const ColorText = dt.span`
|
|
|
1203
1203
|
}
|
|
1204
1204
|
}), link = sanity.defineField({
|
|
1205
1205
|
type: "wild.link",
|
|
1206
|
-
name: `${typeName}.
|
|
1206
|
+
name: `${typeName}.annotation.link`,
|
|
1207
1207
|
title: "Link",
|
|
1208
1208
|
icon: icons.LinkIcon,
|
|
1209
1209
|
options: {
|
|
@@ -1212,7 +1212,7 @@ const ColorText = dt.span`
|
|
|
1212
1212
|
collapsible: !1
|
|
1213
1213
|
}
|
|
1214
1214
|
}), annotations = [link, textColor, highlightColor], media$1 = sanity.defineArrayMember({
|
|
1215
|
-
name: `${typeName}.
|
|
1215
|
+
name: `${typeName}.block.media`,
|
|
1216
1216
|
type: "object",
|
|
1217
1217
|
title: "Media Block",
|
|
1218
1218
|
description: "Embed block video or image content.",
|
|
@@ -1241,7 +1241,7 @@ const ColorText = dt.span`
|
|
|
1241
1241
|
],
|
|
1242
1242
|
preview: {
|
|
1243
1243
|
select: {
|
|
1244
|
-
|
|
1244
|
+
kind: "appMedia.kind",
|
|
1245
1245
|
image: "appMedia.image",
|
|
1246
1246
|
playbackId: "appMedia.video.asset.playbackId",
|
|
1247
1247
|
thumbTime: "appMedia.video.asset.thumbTime"
|
|
@@ -1269,7 +1269,7 @@ const ColorText = dt.span`
|
|
|
1269
1269
|
title: "Number",
|
|
1270
1270
|
value: "number"
|
|
1271
1271
|
}, lists = [bullet, number], icon = sanity.defineArrayMember({
|
|
1272
|
-
name: `${typeName}.
|
|
1272
|
+
name: `${typeName}.span.icon`,
|
|
1273
1273
|
type: "object",
|
|
1274
1274
|
title: "Icon",
|
|
1275
1275
|
description: "Insert an icon.",
|
|
@@ -1291,7 +1291,7 @@ const ColorText = dt.span`
|
|
|
1291
1291
|
}
|
|
1292
1292
|
}
|
|
1293
1293
|
}), media = sanity.defineArrayMember({
|
|
1294
|
-
name: `${typeName}.
|
|
1294
|
+
name: `${typeName}.span.media`,
|
|
1295
1295
|
type: "object",
|
|
1296
1296
|
title: "Inline Media",
|
|
1297
1297
|
description: "Embed inline video or image content.",
|
|
@@ -1350,7 +1350,7 @@ const parts = {
|
|
|
1350
1350
|
spans: spans.filter(hasName),
|
|
1351
1351
|
styles: styles.filter(hasValue),
|
|
1352
1352
|
annotations: annotations.filter(hasName)
|
|
1353
|
-
}, List = makeRecord(parts.lists, "value", ""), Style = makeRecord(parts.styles, "value", ""), Decorator = makeRecord(parts.decorators, "value", ""), Span = makeRecord(parts.spans, "name", `${typeName}.
|
|
1353
|
+
}, List = makeRecord(parts.lists, "value", ""), Style = makeRecord(parts.styles, "value", ""), Decorator = makeRecord(parts.decorators, "value", ""), Span = makeRecord(parts.spans, "name", `${typeName}.span.`), Block = makeRecord(parts.blocks, "name", `${typeName}.block.`), Annotation = makeRecord(parts.annotations, "name", `${typeName}.annotation.`), Part = {
|
|
1354
1354
|
// Individual parts.
|
|
1355
1355
|
List,
|
|
1356
1356
|
Style,
|
|
@@ -1366,6 +1366,18 @@ const parts = {
|
|
|
1366
1366
|
Decorators: Object.values(Decorator),
|
|
1367
1367
|
Spans: Object.values(Span),
|
|
1368
1368
|
Blocks: Object.values(Block)
|
|
1369
|
+
}, presets = {
|
|
1370
|
+
basic: {
|
|
1371
|
+
size: "sm",
|
|
1372
|
+
initiallyActive: !0,
|
|
1373
|
+
whitelist: [Part.Decorator.em, Part.Decorator.strong, Part.Annotation.link]
|
|
1374
|
+
},
|
|
1375
|
+
full: {
|
|
1376
|
+
size: "lg",
|
|
1377
|
+
initiallyActive: !1,
|
|
1378
|
+
// Empty blacklist means "enable all".
|
|
1379
|
+
blacklist: []
|
|
1380
|
+
}
|
|
1369
1381
|
};
|
|
1370
1382
|
function handleListKind(entry, findNeedle) {
|
|
1371
1383
|
const filteredList = entry.type?.options?.list?.filter((s) => findNeedle(s.value));
|
|
@@ -1380,7 +1392,9 @@ const sizeToHeightMap = {
|
|
|
1380
1392
|
lg: "50vh"
|
|
1381
1393
|
};
|
|
1382
1394
|
function RichtextInput(props) {
|
|
1383
|
-
const
|
|
1395
|
+
const { preset, ...mainOptions } = props.schemaType.options ?? {}, presetOptions = preset ? presets[preset] : {}, options = tsDeepmerge.merge(mainOptions, presetOptions), initiallyActive = options?.initiallyActive ?? !1, height = options?.size ? sizeToHeightMap[options.size] : sizeToHeightMap.sm, whitelist = options?.whitelist, blacklist = options?.blacklist;
|
|
1396
|
+
whitelist && blacklist && console.warn("Wild Sanity Rich Text Field: Both whitelist and blacklist are set. Whitelist will take precedence.");
|
|
1397
|
+
const createFilteredParts = o__namespace.useCallback(
|
|
1384
1398
|
(parts2, findNeedle) => parts2.filter((b) => {
|
|
1385
1399
|
const needle = findNeedle(b);
|
|
1386
1400
|
return needle ? whitelist ? whitelist.includes(needle) : blacklist ? !blacklist.includes(needle) : !1 : !0;
|
|
@@ -1450,19 +1464,7 @@ function RichtextInput(props) {
|
|
|
1450
1464
|
}) })
|
|
1451
1465
|
] });
|
|
1452
1466
|
}
|
|
1453
|
-
const
|
|
1454
|
-
basic: {
|
|
1455
|
-
size: "sm",
|
|
1456
|
-
initiallyActive: !0,
|
|
1457
|
-
whitelist: [Part.Decorator.em, Part.Decorator.strong, Part.Annotation.link]
|
|
1458
|
-
},
|
|
1459
|
-
full: {
|
|
1460
|
-
size: "lg",
|
|
1461
|
-
initiallyActive: !1,
|
|
1462
|
-
// Empty blacklist means "enable all".
|
|
1463
|
-
blacklist: []
|
|
1464
|
-
}
|
|
1465
|
-
}, wildSanityRichtextFieldPlugin = sanity.definePlugin((config) => {
|
|
1467
|
+
const wildSanityRichtextFieldPlugin = sanity.definePlugin((config) => {
|
|
1466
1468
|
const userSpans = config?.spans ?? [], userLists = config?.lists ?? [], userBlocks = config?.blocks ?? [], userStyles = config?.styles ?? [], userDecorators = config?.decorators ?? [], userAnnotations = config?.annotations ?? [];
|
|
1467
1469
|
return {
|
|
1468
1470
|
name: "@madebywild/sanity-richtext-field",
|
|
@@ -1475,10 +1477,7 @@ const presets = {
|
|
|
1475
1477
|
description: "Rich text content with formatting options.",
|
|
1476
1478
|
icon: () => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "\u2328\uFE0F" }),
|
|
1477
1479
|
components: {
|
|
1478
|
-
input: (props) => {
|
|
1479
|
-
const options = props.schemaType.options, preset = options?.preset ? presets[options.preset] : void 0, nextProps = { ...props, schemaType: { ...props.schemaType, options: { ...preset, ...options } } };
|
|
1480
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RichtextInput, { ...nextProps });
|
|
1481
|
-
}
|
|
1480
|
+
input: (props) => /* @__PURE__ */ jsxRuntime.jsx(RichtextInput, { ...props })
|
|
1482
1481
|
},
|
|
1483
1482
|
of: [
|
|
1484
1483
|
...userBlocks,
|