sanity 5.31.0-next.36 → 5.31.0-next.46
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/lib/_chunks-es/version.js +2 -2
- package/lib/index.js +117 -40
- package/lib/index.js.map +1 -1
- package/package.json +13 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version = "5.31.0-next.
|
|
1
|
+
var version = "5.31.0-next.46+b830a72a55";
|
|
2
2
|
let buildVersion;
|
|
3
3
|
try {
|
|
4
4
|
buildVersion = process.env.PKG_BUILD_VERSION;
|
|
@@ -7,7 +7,7 @@ try {
|
|
|
7
7
|
try {
|
|
8
8
|
buildVersion = buildVersion || // This is replaced by `@sanity/pkg-utils` at build time
|
|
9
9
|
// and must always be references by its full static name, e.g. no optional chaining, no `if (process && process.env)` etc.
|
|
10
|
-
"5.31.0-next.
|
|
10
|
+
"5.31.0-next.46+b830a72a55";
|
|
11
11
|
} catch {
|
|
12
12
|
}
|
|
13
13
|
const SANITY_VERSION = buildVersion || `${version}-dev`;
|
package/lib/index.js
CHANGED
|
@@ -19100,7 +19100,7 @@ const CACHE$1 = /* @__PURE__ */ new WeakMap(), PREVIEW_FIELD_WEIGHT_MAP$1 = {
|
|
|
19100
19100
|
title: 10,
|
|
19101
19101
|
subtitle: 5,
|
|
19102
19102
|
description: 1.5
|
|
19103
|
-
}, BASE_WEIGHTS$1 = {
|
|
19103
|
+
}, DEFAULT_PREVIEW_SELECT_WEIGHT = 5, BASE_WEIGHTS$1 = {
|
|
19104
19104
|
_id: {
|
|
19105
19105
|
weight: 1,
|
|
19106
19106
|
type: "string"
|
|
@@ -19164,7 +19164,47 @@ function getLeafWeights$1(schemaType, maxDepth, getWeight) {
|
|
|
19164
19164
|
const getUserSetWeight$1 = (schemaType) => {
|
|
19165
19165
|
const searchOptions = getTypeChain$1(schemaType).map((type) => type.options).find(isSearchConfiguration$1);
|
|
19166
19166
|
return typeof searchOptions?.search?.weight == "number" ? searchOptions.search.weight : null;
|
|
19167
|
-
}, getHiddenWeight$1 = (schemaType) => getTypeChain$1(schemaType).some((type) => type.hidden) ? 0 : null, getDefaultWeights$1 = (schemaType) => typeof (getUserSetWeight$1(schemaType) ?? getHiddenWeight$1(schemaType)) == "number" ? null : 1
|
|
19167
|
+
}, getHiddenWeight$1 = (schemaType) => getTypeChain$1(schemaType).some((type) => type.hidden) ? 0 : null, getDefaultWeights$1 = (schemaType) => typeof (getUserSetWeight$1(schemaType) ?? getHiddenWeight$1(schemaType)) == "number" ? null : 1;
|
|
19168
|
+
function findFieldType(type, fieldName) {
|
|
19169
|
+
for (const chainType of getTypeChain$1(type))
|
|
19170
|
+
if (chainType.jsonType === "object" && chainType.fields?.length) {
|
|
19171
|
+
const field = chainType.fields.find(({
|
|
19172
|
+
name
|
|
19173
|
+
}) => name === fieldName);
|
|
19174
|
+
if (field) return field.type;
|
|
19175
|
+
}
|
|
19176
|
+
}
|
|
19177
|
+
function resolveLeafType(type, segments, depth, maxDepth) {
|
|
19178
|
+
if (!type || depth > maxDepth) return null;
|
|
19179
|
+
if (segments.length === 0)
|
|
19180
|
+
return isPtField$1(type) ? "pt" : isSlugField$1(type) ? "slug" : isStringField$1(type) ? "string" : null;
|
|
19181
|
+
const [head, ...rest] = segments, fieldType = findFieldType(type, head);
|
|
19182
|
+
if (!fieldType) return null;
|
|
19183
|
+
if (isReferenceSchemaType(fieldType) && "to" in fieldType) {
|
|
19184
|
+
for (const target of fieldType.to) {
|
|
19185
|
+
const leaf = resolveLeafType(target, rest, depth + 1, maxDepth);
|
|
19186
|
+
if (leaf) return leaf;
|
|
19187
|
+
}
|
|
19188
|
+
return null;
|
|
19189
|
+
}
|
|
19190
|
+
return resolveLeafType(fieldType, rest, depth + 1, maxDepth);
|
|
19191
|
+
}
|
|
19192
|
+
function getPreviewSelectionPathWeights(schemaType, maxDepth, selectionKeysBySelectionPath, existingPaths) {
|
|
19193
|
+
const weights = {};
|
|
19194
|
+
for (const [path, previewKey] of Object.entries(selectionKeysBySelectionPath)) {
|
|
19195
|
+
if (existingPaths.has(path) || path.includes("[]")) continue;
|
|
19196
|
+
const leaf = resolveLeafType(schemaType, path.split("."), 0, maxDepth);
|
|
19197
|
+
if (!leaf) continue;
|
|
19198
|
+
const resolvedPath = leaf === "slug" && !path.endsWith(".current") ? `${path}.current` : path;
|
|
19199
|
+
weights[resolvedPath] = {
|
|
19200
|
+
path: resolvedPath,
|
|
19201
|
+
weight: PREVIEW_FIELD_WEIGHT_MAP$1[previewKey] ?? DEFAULT_PREVIEW_SELECT_WEIGHT,
|
|
19202
|
+
type: leaf === "pt" ? "pt" : "string"
|
|
19203
|
+
};
|
|
19204
|
+
}
|
|
19205
|
+
return weights;
|
|
19206
|
+
}
|
|
19207
|
+
const getPreviewWeights$1 = (schemaType, maxDepth, isCrossDataset) => {
|
|
19168
19208
|
const select2 = schemaType?.preview?.select;
|
|
19169
19209
|
if (!select2) return null;
|
|
19170
19210
|
const selectionKeysBySelectionPath = Object.fromEntries(Object.entries(select2).map(([selectionKey, selectionPath]) => [
|
|
@@ -19186,14 +19226,20 @@ const getUserSetWeight$1 = (schemaType) => {
|
|
|
19186
19226
|
type,
|
|
19187
19227
|
weight: PREVIEW_FIELD_WEIGHT_MAP$1[selectionKeysBySelectionPath[path]]
|
|
19188
19228
|
}]));
|
|
19189
|
-
|
|
19190
|
-
path,
|
|
19191
|
-
|
|
19192
|
-
|
|
19193
|
-
|
|
19229
|
+
if (isCrossDataset)
|
|
19230
|
+
return Object.fromEntries(Object.entries(selectionKeysBySelectionPath).map(([path, previewFieldName]) => [path, {
|
|
19231
|
+
path,
|
|
19232
|
+
type: "string",
|
|
19233
|
+
weight: PREVIEW_FIELD_WEIGHT_MAP$1[previewFieldName]
|
|
19234
|
+
}]));
|
|
19235
|
+
const previewSelectionPathWeights = isSchemaType$2(schemaType) ? getPreviewSelectionPathWeights(schemaType, maxDepth, selectionKeysBySelectionPath, new Set(Object.keys(defaultWeights))) : {}, previewWeightsFromLeafTraversal = getLeafWeights$1(schemaType, maxDepth, (type, path) => {
|
|
19194
19236
|
const nested = nestedWeightsBySelectionPath[getFullyQualifiedPath$1(type, path)];
|
|
19195
19237
|
return nested ? nested.weight : null;
|
|
19196
19238
|
});
|
|
19239
|
+
return {
|
|
19240
|
+
...previewSelectionPathWeights,
|
|
19241
|
+
...previewWeightsFromLeafTraversal
|
|
19242
|
+
};
|
|
19197
19243
|
};
|
|
19198
19244
|
function deriveSearchWeightsFromType({
|
|
19199
19245
|
schemaType,
|
|
@@ -19310,14 +19356,20 @@ const getUserSetWeight = (schemaType) => {
|
|
|
19310
19356
|
type,
|
|
19311
19357
|
weight: PREVIEW_FIELD_WEIGHT_MAP[selectionKeysBySelectionPath[path]] ?? 0
|
|
19312
19358
|
}]));
|
|
19313
|
-
|
|
19314
|
-
path,
|
|
19315
|
-
|
|
19316
|
-
|
|
19317
|
-
|
|
19359
|
+
if (isCrossDataset)
|
|
19360
|
+
return Object.fromEntries(Object.entries(selectionKeysBySelectionPath).map(([path, previewFieldName]) => [path, {
|
|
19361
|
+
path,
|
|
19362
|
+
type: "string",
|
|
19363
|
+
weight: PREVIEW_FIELD_WEIGHT_MAP[previewFieldName] ?? 0
|
|
19364
|
+
}]));
|
|
19365
|
+
const previewSelectionPathWeights = isSchemaType$1(schemaType) ? getPreviewSelectionPathWeights(schemaType, maxDepth, selectionKeysBySelectionPath, new Set(Object.keys(defaultWeights))) : {}, previewWeightsFromLeafTraversal = getLeafWeights(schemaType, maxDepth, (type, path) => {
|
|
19318
19366
|
const nested = nestedWeightsBySelectionPath[getFullyQualifiedPath(type, path)];
|
|
19319
19367
|
return nested ? nested.weight : null;
|
|
19320
19368
|
});
|
|
19369
|
+
return {
|
|
19370
|
+
...previewSelectionPathWeights,
|
|
19371
|
+
...previewWeightsFromLeafTraversal
|
|
19372
|
+
};
|
|
19321
19373
|
};
|
|
19322
19374
|
function deriveSearchWeightsFromType2024({
|
|
19323
19375
|
schemaType,
|
|
@@ -19407,24 +19459,33 @@ function createSearchQuery$1(searchTerms, searchParams, {
|
|
|
19407
19459
|
comments: comments2,
|
|
19408
19460
|
filter: filter2
|
|
19409
19461
|
} = {}) {
|
|
19410
|
-
const flattenedSpecs = searchTerms.types.map((schemaType) =>
|
|
19462
|
+
const flattenedSpecs = searchTerms.types.map((schemaType) => ({
|
|
19411
19463
|
schemaType,
|
|
19412
|
-
|
|
19413
|
-
|
|
19414
|
-
|
|
19415
|
-
|
|
19416
|
-
|
|
19464
|
+
searchSpec: deriveSearchWeightsFromType2024({
|
|
19465
|
+
schemaType,
|
|
19466
|
+
maxDepth: maxDepth || DEFAULT_MAX_FIELD_DEPTH,
|
|
19467
|
+
isCrossDataset,
|
|
19468
|
+
processPaths: (paths) => paths.filter(({
|
|
19469
|
+
weight
|
|
19470
|
+
}) => weight !== 1)
|
|
19471
|
+
})
|
|
19417
19472
|
})).filter(({
|
|
19418
|
-
|
|
19419
|
-
}) => paths.length !== 0).flatMap(({
|
|
19420
|
-
|
|
19421
|
-
|
|
19422
|
-
}) => paths.map((path) => ({
|
|
19473
|
+
searchSpec
|
|
19474
|
+
}) => searchSpec.paths.length !== 0).flatMap(({
|
|
19475
|
+
schemaType,
|
|
19476
|
+
searchSpec
|
|
19477
|
+
}) => searchSpec.paths.map((path) => ({
|
|
19423
19478
|
...path,
|
|
19424
|
-
typeName
|
|
19425
|
-
|
|
19426
|
-
|
|
19427
|
-
|
|
19479
|
+
typeName: searchSpec.typeName,
|
|
19480
|
+
schemaType
|
|
19481
|
+
}))), groupedSpecs = groupBy(flattenedSpecs, (entry) => [entry.path, entry.weight].join(":")), baseMatch = "([@, _id] match text::query($__query) || references($__rawQuery))", score = Object.entries(groupedSpecs).flatMap(([, entries]) => {
|
|
19482
|
+
if (entries.some(({
|
|
19483
|
+
weight
|
|
19484
|
+
}) => weight === 0))
|
|
19485
|
+
return [];
|
|
19486
|
+
const path = entries[0].path.includes("[]") ? entries[0].path : compileFieldPath(entries[0].schemaType, entries[0].path);
|
|
19487
|
+
return `boost(_type in ${JSON.stringify(entries.map((entry) => entry.typeName))} && ${path} match text::query($__query), ${entries[0].weight})`;
|
|
19488
|
+
}).concat(baseMatch), inputSortOrder = sort ?? [{
|
|
19428
19489
|
field: "_score",
|
|
19429
19490
|
direction: "desc"
|
|
19430
19491
|
}], isScored = inputSortOrder.some(({
|
|
@@ -19590,10 +19651,13 @@ function stripWrappingQuotes(str) {
|
|
|
19590
19651
|
}
|
|
19591
19652
|
const FINDABILITY_MVI = 4, DEFAULT_LIMIT = 1e3, combinePaths = flow([flatten$1, union, compact]), pathWithMapper = ({
|
|
19592
19653
|
mapWith,
|
|
19593
|
-
path
|
|
19594
|
-
}) =>
|
|
19654
|
+
path: rawPath
|
|
19655
|
+
}, schemaType) => {
|
|
19656
|
+
const path = !schemaType || rawPath.includes("[]") ? rawPath : compileFieldPath(schemaType, rawPath);
|
|
19657
|
+
return mapWith ? `${mapWith}(${path})` : path;
|
|
19658
|
+
};
|
|
19595
19659
|
function createConstraints(terms, specs) {
|
|
19596
|
-
const combinedSearchPaths = combinePaths(specs.map((configForType) => (configForType.paths || []).map((opt) => pathWithMapper(opt))));
|
|
19660
|
+
const combinedSearchPaths = combinePaths(specs.map((configForType) => (configForType.searchSpec.paths || []).map((opt) => pathWithMapper(opt, configForType.schemaType))));
|
|
19597
19661
|
return terms.map((_term, i) => combinedSearchPaths.map((joinedPath) => `${joinedPath} match $t${i}`)).filter((constraint) => constraint.length > 0).map((constraint) => `(${constraint.join(" || ")})`);
|
|
19598
19662
|
}
|
|
19599
19663
|
const SPECIAL_CHARS = /([^!@#$%^&*(),\\/?";:{}|[\]+<>\s-])+/g, STRIP_EDGE_CHARS = /(^[.]+)|([.]+$)/;
|
|
@@ -19615,17 +19679,23 @@ function createSearchQuery(searchTerms, searchOpts = {}) {
|
|
|
19615
19679
|
sort,
|
|
19616
19680
|
limit: limit2,
|
|
19617
19681
|
comments: comments2
|
|
19618
|
-
} = searchOpts, specs = searchTerms.types.map((schemaType) =>
|
|
19682
|
+
} = searchOpts, specs = searchTerms.types.map((schemaType) => ({
|
|
19619
19683
|
schemaType,
|
|
19620
|
-
|
|
19621
|
-
|
|
19684
|
+
searchSpec: deriveSearchWeightsFromType({
|
|
19685
|
+
schemaType,
|
|
19686
|
+
maxDepth: maxDepth || DEFAULT_MAX_FIELD_DEPTH,
|
|
19687
|
+
isCrossDataset
|
|
19688
|
+
})
|
|
19622
19689
|
})).filter(({
|
|
19623
|
-
|
|
19624
|
-
}) => paths.length), terms = extractTermsFromQuery(searchTerms.query), filters = ["_type in $__types", ...createConstraints(terms, specs), filter2 ? `(${filter2})` : "", searchTerms.filter ? `(${searchTerms.filter})` : ""].filter(Boolean), selections = searchOpts.skipSortByScore ? [] : specs.map((
|
|
19625
|
-
|
|
19690
|
+
searchSpec
|
|
19691
|
+
}) => searchSpec.paths.length !== 0), terms = extractTermsFromQuery(searchTerms.query), filters = ["_type in $__types", ...createConstraints(terms, specs), filter2 ? `(${filter2})` : "", searchTerms.filter ? `(${searchTerms.filter})` : ""].filter(Boolean), selections = searchOpts.skipSortByScore ? [] : specs.map(({
|
|
19692
|
+
searchSpec,
|
|
19693
|
+
schemaType
|
|
19694
|
+
}) => {
|
|
19695
|
+
const constraint = `_type == "${searchSpec.typeName}" => `;
|
|
19626
19696
|
if (searchOpts.skipSortByScore)
|
|
19627
19697
|
return;
|
|
19628
|
-
const selection2 = `{ ${
|
|
19698
|
+
const selection2 = `{ ${searchSpec.paths.map((cfg, i) => `"w${i}": ${pathWithMapper(cfg, schemaType)}`)} }`;
|
|
19629
19699
|
return `${constraint}${selection2}`;
|
|
19630
19700
|
}), inputSortOrder = sort || [{
|
|
19631
19701
|
field: "_id",
|
|
@@ -19641,7 +19711,9 @@ function createSearchQuery(searchTerms, searchOpts = {}) {
|
|
|
19641
19711
|
${query}` : query,
|
|
19642
19712
|
params: {
|
|
19643
19713
|
...toGroqParams(terms),
|
|
19644
|
-
__types: specs.map((
|
|
19714
|
+
__types: specs.map(({
|
|
19715
|
+
searchSpec
|
|
19716
|
+
}) => searchSpec.typeName),
|
|
19645
19717
|
__limit: limit2 ?? DEFAULT_LIMIT,
|
|
19646
19718
|
...params
|
|
19647
19719
|
},
|
|
@@ -19649,7 +19721,9 @@ ${query}` : query,
|
|
|
19649
19721
|
tag,
|
|
19650
19722
|
perspective
|
|
19651
19723
|
},
|
|
19652
|
-
searchSpec: specs
|
|
19724
|
+
searchSpec: specs.map(({
|
|
19725
|
+
searchSpec
|
|
19726
|
+
}) => searchSpec),
|
|
19653
19727
|
terms
|
|
19654
19728
|
};
|
|
19655
19729
|
}
|
|
@@ -27095,8 +27169,11 @@ const DragHandleButton = /* @__PURE__ */ styled(Button).withConfig({
|
|
|
27095
27169
|
$grid,
|
|
27096
27170
|
disabled
|
|
27097
27171
|
} = props2;
|
|
27098
|
-
return disabled ? css
|
|
27172
|
+
return disabled ? css`
|
|
27173
|
+
touch-action: auto;
|
|
27174
|
+
` : css`
|
|
27099
27175
|
cursor: ${$grid ? "move" : "ns-resize"};
|
|
27176
|
+
touch-action: none;
|
|
27100
27177
|
`;
|
|
27101
27178
|
}), DragHandle = function(props2) {
|
|
27102
27179
|
const $ = c(20), id2 = useContext(SortableItemIdContext);
|