@sanity/schema
Advanced tools
Comparing version 0.109.0-alpha.4a764d83 to 0.109.0-next.03e4bf11
@@ -45,9 +45,9 @@ 'use strict'; | ||
function createPreviewGetter(typeDef, parsed) { | ||
function createPreviewGetter(objectTypeDef) { | ||
return function previewGetter() { | ||
(0, _deprecationUtils.warnIfPreviewOnOptions)(typeDef); | ||
(0, _deprecationUtils.warnIfPreviewHasFields)(typeDef); | ||
var preview = parsePreview(typeDef.preview || (typeDef.options || {}).preview); | ||
return preview || (0, _guessPreviewConfig2.default)(parsed.fields); | ||
(0, _deprecationUtils.warnIfPreviewOnOptions)(objectTypeDef); | ||
(0, _deprecationUtils.warnIfPreviewHasFields)(objectTypeDef); | ||
var preview = parsePreview(objectTypeDef.preview || (objectTypeDef.options || {}).preview); | ||
return preview || (0, _guessPreviewConfig2.default)(objectTypeDef); | ||
}; | ||
} |
@@ -17,2 +17,6 @@ 'use strict'; | ||
var _arrify = require('arrify'); | ||
var _arrify2 = _interopRequireDefault(_arrify); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -23,17 +27,23 @@ | ||
function isImageField(field) { | ||
return field.type.name === 'image'; | ||
function isImageField(fieldDef) { | ||
return fieldDef.type === 'image'; | ||
} | ||
function resolveImageAssetPath(fields) { | ||
var found = fields.find(function (field) { | ||
return isImageField(field); | ||
function isImageAssetField(fieldDef) { | ||
return fieldDef.type === 'reference' && (0, _arrify2.default)(fieldDef.to).some(function (memberTypeDef) { | ||
return memberTypeDef.type === 'imageAsset'; | ||
}); | ||
return found && found.name + '.url'; | ||
} | ||
function guessPreviewFields(fields) { | ||
function resolveImageAssetPath(fieldDefs) { | ||
var found = fieldDefs.find(function (field) { | ||
return isImageAssetField(field) || isImageField(field); | ||
}); | ||
return found && (isImageField(found) ? found.name + '.asset.url' : found.name + '.url'); | ||
} | ||
var stringFieldNames = fields.filter(function (field) { | ||
return field.type.name === 'string'; | ||
function guessPreviewFields(objectTypeDef) { | ||
var stringFieldNames = objectTypeDef.fields.filter(function (field) { | ||
return field.type === 'string'; | ||
}).map(function (field) { | ||
@@ -59,7 +69,7 @@ return field.name; | ||
var imageAssetPath = resolveImageAssetPath(fields); | ||
var imageAssetPath = resolveImageAssetPath(objectTypeDef.fields); | ||
if (!titleField && !imageAssetPath) { | ||
// last resort, pick all fields and concat them | ||
var fieldNames = fields.map(function (field) { | ||
var fieldNames = objectTypeDef.fields.map(function (field) { | ||
return field.name; | ||
@@ -66,0 +76,0 @@ }); |
@@ -75,3 +75,3 @@ 'use strict'; | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef, parsed)); | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef)); | ||
@@ -78,0 +78,0 @@ return subtype(parsed); |
@@ -60,3 +60,3 @@ 'use strict'; | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef, parsed)); | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef)); | ||
@@ -63,0 +63,0 @@ return subtype(parsed); |
@@ -16,6 +16,2 @@ 'use strict'; | ||
var _guessPreviewConfig = require('../preview/guessPreviewConfig'); | ||
var _guessPreviewConfig2 = _interopRequireDefault(_guessPreviewConfig); | ||
var _createPreviewGetter = require('../preview/createPreviewGetter'); | ||
@@ -71,3 +67,3 @@ | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef, parsed)); | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef)); | ||
@@ -74,0 +70,0 @@ return subtype(parsed); |
@@ -39,7 +39,2 @@ 'use strict'; | ||
var DEFAULT_OPTIONS = {}; | ||
var DEFAULT_PREVIEW = { | ||
select: { | ||
imageUrl: 'asset.url' | ||
} | ||
}; | ||
@@ -73,3 +68,3 @@ var ImageType = { | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(Object.assign({}, { preview: DEFAULT_PREVIEW }, subTypeDef), parsed)); | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(Object.assign({}, subTypeDef, { fields: fields }))); | ||
@@ -76,0 +71,0 @@ return subtype(parsed); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
type: 'reference', | ||
to: { type: 'imageAsset' } | ||
to: [{ type: 'imageAsset' }] | ||
}; | ||
@@ -12,0 +12,0 @@ |
@@ -72,3 +72,3 @@ 'use strict'; | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef, parsed)); | ||
(0, _utils.lazyGetter)(parsed, 'preview', (0, _createPreviewGetter2.default)(subTypeDef)); | ||
@@ -75,0 +75,0 @@ return subtype(parsed); |
{ | ||
"name": "@sanity/schema", | ||
"version": "0.109.0-alpha.4a764d83", | ||
"version": "0.109.0-next.03e4bf11", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
228746