@contentful/field-editor-shared
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -6,2 +6,8 @@ # Change Log | ||
## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@1.1.4...@contentful/field-editor-shared@1.1.5) (2023-02-07) | ||
### Bug Fixes | ||
- improve types ([#1338](https://github.com/contentful/field-editors/issues/1338)) ([3197fa9](https://github.com/contentful/field-editors/commit/3197fa9e806f32c90cda454681cb48b604072529)) | ||
## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@1.1.3...@contentful/field-editor-shared@1.1.4) (2022-12-08) | ||
@@ -8,0 +14,0 @@ |
@@ -1115,2 +1115,4 @@ 'use strict'; | ||
function getAssetTitle(_ref2) { | ||
var _asset$fields; | ||
var asset = _ref2.asset, | ||
@@ -1121,3 +1123,7 @@ localeCode = _ref2.localeCode, | ||
var title = getFieldValue({ | ||
entity: asset, | ||
entity: { | ||
fields: { | ||
title: (_asset$fields = asset.fields) == null ? void 0 : _asset$fields.title | ||
} | ||
}, | ||
fieldId: 'title', | ||
@@ -1124,0 +1130,0 @@ localeCode: localeCode, |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),r=e(require("lodash/isEqual")),n=e(require("lodash/throttle")),o=require("@contentful/f36-note"),i=e(require("@contentful/f36-tokens")),a=require("emotion"),u=e(require("lodash/isNumber")),l=e(require("react-dom")),c=require("@contentful/f36-components"),s=e(require("lodash/get")),f=e(require("lodash/isObject")),d=e(require("lodash/isString"));function p(e,t,r,n,o,i,a){try{var u=e[i](a),l=u.value}catch(e){return void r(e)}u.done?t(l):Promise.resolve(l).then(n,o)}function h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){p(i,n,o,a,u,"next",e)}function u(e){p(i,n,o,a,u,"throw",e)}a(void 0)}))}}function v(){return(v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function y(e,t){return(y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function m(e,t){return e(t={exports:{}},t.exports),t.exports}var g=m((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),i=new C(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=x(a,r);if(u){if(u===s)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var l=c(e,t,r);if("normal"===l.type){if(n=r.done?"completed":"suspendedYield",l.arg===s)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(n="completed",r.method="throw",r.arg=l.arg)}}}(e,r,i),o}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var s={};function f(){}function d(){}function p(){}var h={};u(h,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(L([])));y&&y!==t&&r.call(y,o)&&(h=y);var m=p.prototype=f.prototype=Object.create(h);function g(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var l=c(e[o],e,i);if("throw"!==l.type){var s=l.arg,f=s.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,u)}),(function(e){n("throw",e,a,u)})):t.resolve(f).then((function(e){s.value=e,a(s)}),(function(e){return n("throw",e,a,u)}))}u(l.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=c(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,s;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function C(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function L(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return d.prototype=p,u(m,"constructor",p),u(p,"constructor",d),d.displayName=u(p,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,u(e,a,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},g(b.prototype),u(b.prototype,i,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new b(l(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},g(m),u(m,a,"Generator"),u(m,o,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=L,C.prototype={constructor:C,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),l=r.call(i,"finallyLoc");if(u&&l){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),E(r),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:L(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})),b=function(e){var t,r;function o(t){var r;(r=e.call(this,t)||this).unsubscribeErrors=null,r.unsubscribeDisabled=null,r.unsubscribeValue=null,r.setValue=function(){var e=h(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.props.isEmptyValue(null!=t?t:null)?r.setState({value:void 0}):r.setState({value:t}),e.next=3,r.triggerSetValueCallbacks(t);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),r.triggerSetValueCallbacks=n((function(e){return new Promise((function(t,n){r.props.isEmptyValue(null!=e?e:null)?r.props.field.removeValue().then(t).catch(n):r.props.field.setValue(e).then(t).catch(n)}))}),r.props.throttle,{leading:0===r.props.throttle});var o=t.field.getValue();return r.state={isLocalValueChange:!1,externalReset:0,value:o,lastRemoteValue:o,disabled:t.isInitiallyDisabled,errors:[]},r}r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,y(t,r);var i=o.prototype;return i.componentDidMount=function(){var e=this,t=this.props.field;this.unsubscribeErrors=t.onSchemaErrorsChanged((function(t){e.setState({errors:t||[]})})),this.unsubscribeDisabled=t.onIsDisabledChanged((function(t){e.setState({disabled:t})})),this.unsubscribeValue=t.onValueChanged((function(t){e.setState((function(r){var n=e.props.isEqualValues(t,r.value);return{value:t,lastRemoteValue:n?r.lastRemoteValue:t,isLocalValueChange:n,externalReset:r.externalReset+(n?0:1)}}))}))},i.componentWillUnmount=function(){"function"==typeof this.unsubscribeErrors&&this.unsubscribeErrors(),"function"==typeof this.unsubscribeDisabled&&this.unsubscribeDisabled(),"function"==typeof this.unsubscribeValue&&this.unsubscribeValue()},i.render=function(){return this.props.children(v({},this.state,{setValue:this.setValue}))},o}(t.Component);b.defaultProps={children:function(){return null},isEmptyValue:function(e){return null===e||""===e},isEqualValues:function(e,t){return r(e,t)},throttle:300};var x=a.css({color:i.red600});function w(e){var t=null,r=function(){return null===t&&((t=document.createElement("div")).setAttribute("id","field-editor-modal-root"),document.body.appendChild(t)),t};return new Promise((function(t){var n={onClose:function(){o(n=v({},n,{isShown:!1})),t.apply(void 0,arguments),r().remove()},isShown:!0};function o(t){l.render(e({onClose:t.onClose,isShown:t.isShown}),r())}o(n)}))}function E(e,r){var n=Date.now(),o=u(e.width)?e.width+"px":e.width;return w((function(i){var a=i.onClose,u=function(){return a()};return t.createElement(c.Modal,{key:n,shouldCloseOnOverlayClick:e.shouldCloseOnOverlayClick||!1,shouldCloseOnEscapePress:e.shouldCloseOnEscapePress||!1,allowHeightOverflow:e.allowHeightOverflow||!1,position:e.position||"center",isShown:i.isShown,onClose:u,size:o||"700px"},(function(){return t.createElement(t.Fragment,null,e.title&&t.createElement(c.ModalHeader,{testId:"dialog-title",title:e.title,onClose:u}),t.createElement("div",{style:{minHeight:e.minHeight||"auto"}},t.createElement(r,{onClose:a})))}))}))}var C={__proto__:null,open:w,openDialog:E,default:{openDialog:E}};function L(e,t){if(!d(e))return t;if(e){var r=e.trim();return 0===r.length?t:r}return t}function O(e){var t=e.localeCode,r=e.defaultLocaleCode,n=s(e.entity,["fields",e.fieldId]);if(f(n)){var o=Object.keys(n)[0];return n[t]||n[r]||n[o]}}var _=function(e){return"Link"===e.type&&"Asset"===e.linkType};function V(e){return e.field.id===e.contentType.displayField}function S(e){var t=e.field,r=e.contentType;return function(e){return["Symbol","Text"].includes(e.type)}(t)&&!V({field:t,contentType:r})&&!function(e){return/\bslug\b/.test(e.name)}(t)}var j={__proto__:null,getFieldValue:O,getAssetTitle:function(e){var t=e.defaultTitle;return L(O({entity:e.asset,fieldId:"title",localeCode:e.localeCode,defaultLocaleCode:e.defaultLocaleCode}),t)},isAssetField:_,isDisplayField:V,isDescriptionField:S,getEntityDescription:function(e){var t=e.entity,r=e.contentType,n=e.localeCode,o=e.defaultLocaleCode;if(!r)return"";var i=r.fields.find((function(e){return S({field:e,contentType:r})}));return i&&O({entity:t,fieldId:i.id,localeCode:n,defaultLocaleCode:o})||""},getEntryTitle:function(e){var t,r=e.entry,n=e.contentType,o=e.localeCode,i=e.defaultLocaleCode,a=e.defaultTitle;if(!n)return a;var u=n.displayField;if(!u)return a;var l=n.fields.find((function(e){return e.id===u}));return l?(l.localized?(t=O({entity:r,fieldId:u,localeCode:o,defaultLocaleCode:i}))||(t=O({entity:r,fieldId:l.id,localeCode:o,defaultLocaleCode:i})):(t=O({entity:r,fieldId:u,defaultLocaleCode:i,localeCode:""}))||(t=O({entity:r,fieldId:l.id,defaultLocaleCode:i,localeCode:""})),L(t,a)):a},getEntryStatus:function(e){if(!e||"Entry"!==e.type&&"Asset"!==e.type)throw new TypeError("Invalid entity metadata object");return e.deletedVersion?"deleted":e.archivedVersion?"archived":e.publishedVersion?e.version>e.publishedVersion+1?"changed":"published":"draft"},getEntryImage:function(){var e=h(g.mark((function e(t,r){var n,o,i,a,u,l,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.entry,i=t.localeCode,o=t.contentType){e.next=3;break}return e.abrupt("return",null);case 3:if(a=o.fields.find(_)){e.next=6;break}return e.abrupt("return",null);case 6:if(u=s(n.fields,[a.id,i,"sys","id"])){e.next=9;break}return e.abrupt("return",null);case 9:return e.prev=9,e.next=12,r(u);case 12:return l=s(e.sent,["fields","file",i]),c=Boolean(s(l,["details","image"],!1)),e.abrupt("return",c?l:null);case 18:return e.prev=18,e.t0=e.catch(9),e.abrupt("return",null);case 21:case"end":return e.stop()}}),e,null,[[9,18]])})));return function(t,r){return e.apply(this,arguments)}}()},k={__proto__:null,fromFieldValidations:function(e,t){void 0===e&&(e=[]);var r=e.find((function(e){return"size"in e})),n=r&&r.size||{},o=n.min,i=n.max;return u(o)&&u(i)?{type:"min-max",min:o,max:i}:u(o)?{type:"min",min:o}:u(i)?{type:"max",max:i}:{type:"max",max:"Symbol"===t?256:5e4}},makeChecker:function(e){return function(t){return"max"===e.type?t<=e.max:"min"===e.type?t>=e.min:t>=e.min&&t<=e.max}}};exports.CharCounter=function(e){var r,n=0;e.value&&(n=e.value.length);var o=0===n||e.checkConstraint(n);return t.createElement("span",{"data-status-code":o?null:"invalid-size",className:a.cx((r={},r[x]=!o,r))},n," characters")},exports.CharValidation=function(e){var r=e.constraints;return"max"===r.type?t.createElement("span",null,"Maximum ",r.max," characters"):"min"===r.type?t.createElement("span",null,"Requires at least ",r.min," characters"):t.createElement("span",null,"Requires between ",r.min," and ",r.max," characters")},exports.ConstraintsUtils=k,exports.FieldConnector=b,exports.ModalDialogLauncher=C,exports.PredefinedValuesError=function(){return t.createElement(o.Note,{variant:"warning",testId:"predefined-values-warning"},"The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.")},exports.entityHelpers=j,exports.isValidImage=function(e){return["image/bmp","image/x-windows-bmp","image/gif","image/webp","image/jpg","image/jpeg","image/pjpeg","image/x-jps","image/png","image/svg+xml"].includes(e.contentType)},exports.shortenStorageUnit=function(e,t){if(e<=0)return"0 B";var r=["PB","TB","GB","MB","KB","B"],n=function e(t,n){return t<.99&&!function(e){return r.indexOf(e)===r.length-1}(n)?e(1e3*t,function(e){return r[r.indexOf(e)+1]}(n)):t>=1e3&&!function(e){return 0===r.indexOf(e)}(n)?e(t/1e3,function(e){return r[r.indexOf(e)-1]}(n)):{number:t,unit:n}}(e,t),o=n.unit;return function(e,t){return e.toFixed(2).replace(/\.(0)*$|0*$/,"")}(n.number)+" "+o},exports.toLocaleString=function(e){return e.toLocaleString("en-US")}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),r=e(require("lodash/isEqual")),n=e(require("lodash/throttle")),o=require("@contentful/f36-note"),i=e(require("@contentful/f36-tokens")),a=require("emotion"),u=e(require("lodash/isNumber")),l=e(require("react-dom")),c=require("@contentful/f36-components"),s=e(require("lodash/get")),f=e(require("lodash/isObject")),d=e(require("lodash/isString"));function p(e,t,r,n,o,i,a){try{var u=e[i](a),l=u.value}catch(e){return void r(e)}u.done?t(l):Promise.resolve(l).then(n,o)}function h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){p(i,n,o,a,u,"next",e)}function u(e){p(i,n,o,a,u,"throw",e)}a(void 0)}))}}function v(){return(v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function y(e,t){return(y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function m(e,t){return e(t={exports:{}},t.exports),t.exports}var g=m((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),i=new C(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=x(a,r);if(u){if(u===s)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var l=c(e,t,r);if("normal"===l.type){if(n=r.done?"completed":"suspendedYield",l.arg===s)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(n="completed",r.method="throw",r.arg=l.arg)}}}(e,r,i),o}function c(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var s={};function f(){}function d(){}function p(){}var h={};u(h,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(L([])));y&&y!==t&&r.call(y,o)&&(h=y);var m=p.prototype=f.prototype=Object.create(h);function g(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var l=c(e[o],e,i);if("throw"!==l.type){var s=l.arg,f=s.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,u)}),(function(e){n("throw",e,a,u)})):t.resolve(f).then((function(e){s.value=e,a(s)}),(function(e){return n("throw",e,a,u)}))}u(l.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=c(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,s;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function C(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function L(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return d.prototype=p,u(m,"constructor",p),u(p,"constructor",d),d.displayName=u(p,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,u(e,a,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},g(b.prototype),u(b.prototype,i,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new b(l(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},g(m),u(m,a,"Generator"),u(m,o,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=L,C.prototype={constructor:C,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),l=r.call(i,"finallyLoc");if(u&&l){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,s):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),E(r),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:L(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),s}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})),b=function(e){var t,r;function o(t){var r;(r=e.call(this,t)||this).unsubscribeErrors=null,r.unsubscribeDisabled=null,r.unsubscribeValue=null,r.setValue=function(){var e=h(g.mark((function e(t){return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.props.isEmptyValue(null!=t?t:null)?r.setState({value:void 0}):r.setState({value:t}),e.next=3,r.triggerSetValueCallbacks(t);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),r.triggerSetValueCallbacks=n((function(e){return new Promise((function(t,n){r.props.isEmptyValue(null!=e?e:null)?r.props.field.removeValue().then(t).catch(n):r.props.field.setValue(e).then(t).catch(n)}))}),r.props.throttle,{leading:0===r.props.throttle});var o=t.field.getValue();return r.state={isLocalValueChange:!1,externalReset:0,value:o,lastRemoteValue:o,disabled:t.isInitiallyDisabled,errors:[]},r}r=e,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,y(t,r);var i=o.prototype;return i.componentDidMount=function(){var e=this,t=this.props.field;this.unsubscribeErrors=t.onSchemaErrorsChanged((function(t){e.setState({errors:t||[]})})),this.unsubscribeDisabled=t.onIsDisabledChanged((function(t){e.setState({disabled:t})})),this.unsubscribeValue=t.onValueChanged((function(t){e.setState((function(r){var n=e.props.isEqualValues(t,r.value);return{value:t,lastRemoteValue:n?r.lastRemoteValue:t,isLocalValueChange:n,externalReset:r.externalReset+(n?0:1)}}))}))},i.componentWillUnmount=function(){"function"==typeof this.unsubscribeErrors&&this.unsubscribeErrors(),"function"==typeof this.unsubscribeDisabled&&this.unsubscribeDisabled(),"function"==typeof this.unsubscribeValue&&this.unsubscribeValue()},i.render=function(){return this.props.children(v({},this.state,{setValue:this.setValue}))},o}(t.Component);b.defaultProps={children:function(){return null},isEmptyValue:function(e){return null===e||""===e},isEqualValues:function(e,t){return r(e,t)},throttle:300};var x=a.css({color:i.red600});function w(e){var t=null,r=function(){return null===t&&((t=document.createElement("div")).setAttribute("id","field-editor-modal-root"),document.body.appendChild(t)),t};return new Promise((function(t){var n={onClose:function(){o(n=v({},n,{isShown:!1})),t.apply(void 0,arguments),r().remove()},isShown:!0};function o(t){l.render(e({onClose:t.onClose,isShown:t.isShown}),r())}o(n)}))}function E(e,r){var n=Date.now(),o=u(e.width)?e.width+"px":e.width;return w((function(i){var a=i.onClose,u=function(){return a()};return t.createElement(c.Modal,{key:n,shouldCloseOnOverlayClick:e.shouldCloseOnOverlayClick||!1,shouldCloseOnEscapePress:e.shouldCloseOnEscapePress||!1,allowHeightOverflow:e.allowHeightOverflow||!1,position:e.position||"center",isShown:i.isShown,onClose:u,size:o||"700px"},(function(){return t.createElement(t.Fragment,null,e.title&&t.createElement(c.ModalHeader,{testId:"dialog-title",title:e.title,onClose:u}),t.createElement("div",{style:{minHeight:e.minHeight||"auto"}},t.createElement(r,{onClose:a})))}))}))}var C={__proto__:null,open:w,openDialog:E,default:{openDialog:E}};function L(e,t){if(!d(e))return t;if(e){var r=e.trim();return 0===r.length?t:r}return t}function O(e){var t=e.localeCode,r=e.defaultLocaleCode,n=s(e.entity,["fields",e.fieldId]);if(f(n)){var o=Object.keys(n)[0];return n[t]||n[r]||n[o]}}var _=function(e){return"Link"===e.type&&"Asset"===e.linkType};function V(e){return e.field.id===e.contentType.displayField}function S(e){var t=e.field,r=e.contentType;return function(e){return["Symbol","Text"].includes(e.type)}(t)&&!V({field:t,contentType:r})&&!function(e){return/\bslug\b/.test(e.name)}(t)}var j={__proto__:null,getFieldValue:O,getAssetTitle:function(e){var t,r=e.defaultTitle;return L(O({entity:{fields:{title:null==(t=e.asset.fields)?void 0:t.title}},fieldId:"title",localeCode:e.localeCode,defaultLocaleCode:e.defaultLocaleCode}),r)},isAssetField:_,isDisplayField:V,isDescriptionField:S,getEntityDescription:function(e){var t=e.entity,r=e.contentType,n=e.localeCode,o=e.defaultLocaleCode;if(!r)return"";var i=r.fields.find((function(e){return S({field:e,contentType:r})}));return i&&O({entity:t,fieldId:i.id,localeCode:n,defaultLocaleCode:o})||""},getEntryTitle:function(e){var t,r=e.entry,n=e.contentType,o=e.localeCode,i=e.defaultLocaleCode,a=e.defaultTitle;if(!n)return a;var u=n.displayField;if(!u)return a;var l=n.fields.find((function(e){return e.id===u}));return l?(l.localized?(t=O({entity:r,fieldId:u,localeCode:o,defaultLocaleCode:i}))||(t=O({entity:r,fieldId:l.id,localeCode:o,defaultLocaleCode:i})):(t=O({entity:r,fieldId:u,defaultLocaleCode:i,localeCode:""}))||(t=O({entity:r,fieldId:l.id,defaultLocaleCode:i,localeCode:""})),L(t,a)):a},getEntryStatus:function(e){if(!e||"Entry"!==e.type&&"Asset"!==e.type)throw new TypeError("Invalid entity metadata object");return e.deletedVersion?"deleted":e.archivedVersion?"archived":e.publishedVersion?e.version>e.publishedVersion+1?"changed":"published":"draft"},getEntryImage:function(){var e=h(g.mark((function e(t,r){var n,o,i,a,u,l,c;return g.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.entry,i=t.localeCode,o=t.contentType){e.next=3;break}return e.abrupt("return",null);case 3:if(a=o.fields.find(_)){e.next=6;break}return e.abrupt("return",null);case 6:if(u=s(n.fields,[a.id,i,"sys","id"])){e.next=9;break}return e.abrupt("return",null);case 9:return e.prev=9,e.next=12,r(u);case 12:return l=s(e.sent,["fields","file",i]),c=Boolean(s(l,["details","image"],!1)),e.abrupt("return",c?l:null);case 18:return e.prev=18,e.t0=e.catch(9),e.abrupt("return",null);case 21:case"end":return e.stop()}}),e,null,[[9,18]])})));return function(t,r){return e.apply(this,arguments)}}()},k={__proto__:null,fromFieldValidations:function(e,t){void 0===e&&(e=[]);var r=e.find((function(e){return"size"in e})),n=r&&r.size||{},o=n.min,i=n.max;return u(o)&&u(i)?{type:"min-max",min:o,max:i}:u(o)?{type:"min",min:o}:u(i)?{type:"max",max:i}:{type:"max",max:"Symbol"===t?256:5e4}},makeChecker:function(e){return function(t){return"max"===e.type?t<=e.max:"min"===e.type?t>=e.min:t>=e.min&&t<=e.max}}};exports.CharCounter=function(e){var r,n=0;e.value&&(n=e.value.length);var o=0===n||e.checkConstraint(n);return t.createElement("span",{"data-status-code":o?null:"invalid-size",className:a.cx((r={},r[x]=!o,r))},n," characters")},exports.CharValidation=function(e){var r=e.constraints;return"max"===r.type?t.createElement("span",null,"Maximum ",r.max," characters"):"min"===r.type?t.createElement("span",null,"Requires at least ",r.min," characters"):t.createElement("span",null,"Requires between ",r.min," and ",r.max," characters")},exports.ConstraintsUtils=k,exports.FieldConnector=b,exports.ModalDialogLauncher=C,exports.PredefinedValuesError=function(){return t.createElement(o.Note,{variant:"warning",testId:"predefined-values-warning"},"The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.")},exports.entityHelpers=j,exports.isValidImage=function(e){return["image/bmp","image/x-windows-bmp","image/gif","image/webp","image/jpg","image/jpeg","image/pjpeg","image/x-jps","image/png","image/svg+xml"].includes(e.contentType)},exports.shortenStorageUnit=function(e,t){if(e<=0)return"0 B";var r=["PB","TB","GB","MB","KB","B"],n=function e(t,n){return t<.99&&!function(e){return r.indexOf(e)===r.length-1}(n)?e(1e3*t,function(e){return r[r.indexOf(e)+1]}(n)):t>=1e3&&!function(e){return 0===r.indexOf(e)}(n)?e(t/1e3,function(e){return r[r.indexOf(e)-1]}(n)):{number:t,unit:n}}(e,t),o=n.unit;return function(e,t){return e.toFixed(2).replace(/\.(0)*$|0*$/,"")}(n.number)+" "+o},exports.toLocaleString=function(e){return e.toLocaleString("en-US")}; | ||
//# sourceMappingURL=field-editor-shared.cjs.production.min.js.map |
@@ -1109,2 +1109,4 @@ import React from 'react'; | ||
function getAssetTitle(_ref2) { | ||
var _asset$fields; | ||
var asset = _ref2.asset, | ||
@@ -1115,3 +1117,7 @@ localeCode = _ref2.localeCode, | ||
var title = getFieldValue({ | ||
entity: asset, | ||
entity: { | ||
fields: { | ||
title: (_asset$fields = asset.fields) == null ? void 0 : _asset$fields.title | ||
} | ||
}, | ||
fieldId: 'title', | ||
@@ -1118,0 +1124,0 @@ localeCode: localeCode, |
@@ -1,2 +0,2 @@ | ||
import { File, ContentType, Entry, ContentTypeField } from '../typesEntity'; | ||
import { Asset, ContentType, ContentTypeField, Entry, File } from '../typesEntity'; | ||
export declare function getFieldValue({ | ||
@@ -19,3 +19,3 @@ /** | ||
export declare function getAssetTitle({ asset, localeCode, defaultLocaleCode, defaultTitle, }: { | ||
asset: Entry; | ||
asset: Asset; | ||
localeCode: string; | ||
@@ -22,0 +22,0 @@ defaultLocaleCode: string; |
{ | ||
"name": "@contentful/field-editor-shared", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"main": "dist/index.js", | ||
@@ -42,3 +42,3 @@ "module": "dist/field-editor-shared.esm.js", | ||
}, | ||
"gitHead": "6a478978e6c65ff918a34b07b78652ab8d1e1e55" | ||
"gitHead": "2b9eb3ff5cb1852338ac62d3257471106390a8f7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
352020
2804