Socket
Socket
Sign inDemoInstall

@contentful/field-editor-shared

Package Overview
Dependencies
Maintainers
102
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/field-editor-shared - npm Package Compare versions

Comparing version 0.22.0 to 0.22.1

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [0.22.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.22.0...@contentful/field-editor-shared@0.22.1) (2021-08-19)
### Bug Fixes
* FieldConnector setValue race conditions ([#803](https://github.com/contentful/field-editors/issues/803)) ([15a5aa6](https://github.com/contentful/field-editors/commit/15a5aa68a6f3f6c7183444c8fd11de1e70208aa7))
# [0.22.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-shared@0.21.0...@contentful/field-editor-shared@0.22.0) (2021-07-23)

@@ -8,0 +19,0 @@

513

dist/field-editor-shared.cjs.development.js

@@ -8,4 +8,4 @@ 'use strict';

var React = _interopDefault(require('react'));
var isEqual = _interopDefault(require('lodash/isEqual'));
var throttle = _interopDefault(require('lodash/throttle'));
var isEqual = _interopDefault(require('lodash/isEqual'));
var forma36ReactComponents = require('@contentful/forma-36-react-components');

@@ -77,253 +77,15 @@ var tokens = _interopDefault(require('@contentful/forma-36-tokens'));

subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var FieldConnector = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(FieldConnector, _React$Component);
function FieldConnector(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.unsubscribeErrors = null;
_this.unsubscribeDisabled = null;
_this.unsubscribeValue = null;
_this.setValue = throttle(function (value) {
if (_this.props.isEmptyValue(value === undefined ? null : value)) {
return new Promise(function (resolve, reject) {
_this.setState({
lastSetValue: undefined
}, function () {
_this.props.field.removeValue().then(resolve)["catch"](reject);
});
});
} else {
return new Promise(function (resolve, reject) {
_this.setState({
lastSetValue: value
}, function () {
_this.props.field.setValue(value).then(resolve)["catch"](reject);
});
});
}
}, _this.props.throttle, {
leading: _this.props.throttle === 0
});
var initialValue = props.field.getValue();
_this.state = {
isLocalValueChange: false,
externalReset: 0,
value: initialValue,
lastSetValue: initialValue,
lastRemoteValue: initialValue,
disabled: props.isInitiallyDisabled,
errors: []
};
return _this;
}
var _proto = FieldConnector.prototype;
_proto.componentDidMount = function componentDidMount() {
var _this2 = this;
var field = this.props.field;
this.unsubscribeErrors = field.onSchemaErrorsChanged(function (errors) {
_this2.setState({
errors: errors || []
});
});
this.unsubscribeDisabled = field.onIsDisabledChanged(function (disabled) {
_this2.setState({
disabled: disabled
});
});
this.unsubscribeValue = field.onValueChanged(function (value) {
_this2.setState(function (currentState) {
var isLocalValueChange = _this2.props.isEqualValues(value, currentState.lastSetValue);
var lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
var externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
return {
value: value,
lastSetValue: value,
lastRemoteValue: lastRemoteValue,
isLocalValueChange: isLocalValueChange,
externalReset: externalReset
};
});
});
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (typeof this.unsubscribeErrors === 'function') {
this.unsubscribeErrors();
}
if (typeof this.unsubscribeDisabled === 'function') {
this.unsubscribeDisabled();
}
if (typeof this.unsubscribeValue === 'function') {
this.unsubscribeValue();
}
};
_proto.render = function render() {
var childProps = _extends({}, this.state); // `lastSetValue` can be either the `setValue()` value right after it got called
// or the current remote value. No use-case for passing this to child.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete childProps.lastSetValue;
return this.props.children(_extends({}, childProps, {
// @ts-expect-error
setValue: this.setValue
}));
};
return FieldConnector;
}(React.Component);
FieldConnector.defaultProps = {
children: function children() {
return null;
},
// eslint-disable-next-line
isEmptyValue: function isEmptyValue(value) {
return value === null || value === '';
},
// eslint-disable-next-line
isEqualValues: function isEqualValues(value1, value2) {
return isEqual(value1, value2);
},
throttle: 300
};
function PredefinedValuesError() {
return React.createElement(forma36ReactComponents.Note, {
noteType: "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.");
_setPrototypeOf(subClass, superClass);
}
var styles = {
invalid: /*#__PURE__*/emotion.css({
color: tokens.red600
})
};
function CharCounter(props) {
var _cx;
var count = 0;
if (props.value) {
count = props.value.length;
}
var valid = count === 0 || props.checkConstraint(count);
return React.createElement("span", {
"data-status-code": valid ? null : 'invalid-size',
className: emotion.cx((_cx = {}, _cx[styles.invalid] = !valid, _cx))
}, count, " characters");
}
function CharValidation(props) {
var constraints = props.constraints;
if (constraints.type === 'max') {
return React.createElement("span", null, "Maximum ", constraints.max, " characters");
} else if (constraints.type === 'min') {
return React.createElement("span", null, "Requires at least ", constraints.min, " characters");
} else {
return React.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
}
}
function open(componentRenderer) {
var rootDom = null;
var getRoot = function getRoot() {
if (rootDom === null) {
rootDom = document.createElement('div');
rootDom.setAttribute('id', 'field-editor-modal-root');
document.body.appendChild(rootDom);
}
return rootDom;
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return new Promise(function (resolve) {
var currentConfig = {
onClose: onClose,
isShown: true
};
function render(_ref) {
var onClose = _ref.onClose,
isShown = _ref.isShown;
ReactDOM.render(componentRenderer({
onClose: onClose,
isShown: isShown
}), getRoot());
}
function onClose() {
currentConfig = _extends({}, currentConfig, {
isShown: false
});
render(currentConfig);
resolve.apply(void 0, arguments);
getRoot().remove();
}
render(currentConfig);
});
return _setPrototypeOf(o, p);
}
function openDialog(options, Component) {
var key = Date.now();
var size = isNumber(options.width) ? options.width + "px" : options.width;
return open(function (_ref2) {
var isShown = _ref2.isShown,
onClose = _ref2.onClose;
var onCloseHandler = function onCloseHandler() {
return onClose();
};
return React.createElement(forma36ReactComponents.Modal, {
key: key,
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
allowHeightOverflow: options.allowHeightOverflow || false,
position: options.position || 'center',
isShown: isShown,
onClose: onCloseHandler,
size: size || '700px'
}, function () {
return React.createElement(React.Fragment, null, options.title && React.createElement(forma36ReactComponents.Modal.Header, {
testId: "dialog-title",
title: options.title,
onClose: onCloseHandler
}), React.createElement("div", {
style: {
minHeight: options.minHeight || 'auto'
}
}, React.createElement(Component, {
onClose: onClose
})));
});
});
}
var ModalDialogLauncher = {
openDialog: openDialog
};
var ModalDialogLauncher$1 = {
__proto__: null,
open: open,
openDialog: openDialog,
'default': ModalDialogLauncher
};
function createCommonjsModule(fn, module) {

@@ -1057,2 +819,263 @@ return module = { exports: {} }, fn(module, module.exports), module.exports;

var FieldConnector = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(FieldConnector, _React$Component);
function FieldConnector(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.unsubscribeErrors = null;
_this.unsubscribeDisabled = null;
_this.unsubscribeValue = null;
_this.setValue = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(value) {
return runtime_1.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (_this.props.isEmptyValue(value != null ? value : null)) {
_this.setState({
value: undefined
});
} else {
_this.setState({
value: value
});
}
_context.next = 3;
return _this.triggerSetValueCallbacks(value);
case 3:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
_this.triggerSetValueCallbacks = throttle(function (value) {
return new Promise(function (resolve, reject) {
if (_this.props.isEmptyValue(value != null ? value : null)) {
_this.props.field.removeValue().then(resolve)["catch"](reject);
} else {
_this.props.field.setValue(value).then(resolve)["catch"](reject);
}
});
}, _this.props.throttle, {
leading: _this.props.throttle === 0
});
var initialValue = props.field.getValue();
_this.state = {
isLocalValueChange: false,
externalReset: 0,
value: initialValue,
lastRemoteValue: initialValue,
disabled: props.isInitiallyDisabled,
errors: []
};
return _this;
}
var _proto = FieldConnector.prototype;
_proto.componentDidMount = function componentDidMount() {
var _this2 = this;
var field = this.props.field;
this.unsubscribeErrors = field.onSchemaErrorsChanged(function (errors) {
_this2.setState({
errors: errors || []
});
});
this.unsubscribeDisabled = field.onIsDisabledChanged(function (disabled) {
_this2.setState({
disabled: disabled
});
});
this.unsubscribeValue = field.onValueChanged(function (value) {
_this2.setState(function (currentState) {
var isLocalValueChange = _this2.props.isEqualValues(value, currentState.value);
var lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
var externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
return {
value: value,
lastRemoteValue: lastRemoteValue,
isLocalValueChange: isLocalValueChange,
externalReset: externalReset
};
});
});
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (typeof this.unsubscribeErrors === 'function') {
this.unsubscribeErrors();
}
if (typeof this.unsubscribeDisabled === 'function') {
this.unsubscribeDisabled();
}
if (typeof this.unsubscribeValue === 'function') {
this.unsubscribeValue();
}
};
_proto.render = function render() {
return this.props.children(_extends({}, this.state, {
setValue: this.setValue
}));
};
return FieldConnector;
}(React.Component);
FieldConnector.defaultProps = {
children: function children() {
return null;
},
// eslint-disable-next-line
isEmptyValue: function isEmptyValue(value) {
return value === null || value === '';
},
// eslint-disable-next-line
isEqualValues: function isEqualValues(value1, value2) {
return isEqual(value1, value2);
},
throttle: 300
};
function PredefinedValuesError() {
return React.createElement(forma36ReactComponents.Note, {
noteType: "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.");
}
var styles = {
invalid: /*#__PURE__*/emotion.css({
color: tokens.red600
})
};
function CharCounter(props) {
var _cx;
var count = 0;
if (props.value) {
count = props.value.length;
}
var valid = count === 0 || props.checkConstraint(count);
return React.createElement("span", {
"data-status-code": valid ? null : 'invalid-size',
className: emotion.cx((_cx = {}, _cx[styles.invalid] = !valid, _cx))
}, count, " characters");
}
function CharValidation(props) {
var constraints = props.constraints;
if (constraints.type === 'max') {
return React.createElement("span", null, "Maximum ", constraints.max, " characters");
} else if (constraints.type === 'min') {
return React.createElement("span", null, "Requires at least ", constraints.min, " characters");
} else {
return React.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
}
}
function open(componentRenderer) {
var rootDom = null;
var getRoot = function getRoot() {
if (rootDom === null) {
rootDom = document.createElement('div');
rootDom.setAttribute('id', 'field-editor-modal-root');
document.body.appendChild(rootDom);
}
return rootDom;
};
return new Promise(function (resolve) {
var currentConfig = {
onClose: onClose,
isShown: true
};
function render(_ref) {
var onClose = _ref.onClose,
isShown = _ref.isShown;
ReactDOM.render(componentRenderer({
onClose: onClose,
isShown: isShown
}), getRoot());
}
function onClose() {
currentConfig = _extends({}, currentConfig, {
isShown: false
});
render(currentConfig);
resolve.apply(void 0, arguments);
getRoot().remove();
}
render(currentConfig);
});
}
function openDialog(options, Component) {
var key = Date.now();
var size = isNumber(options.width) ? options.width + "px" : options.width;
return open(function (_ref2) {
var isShown = _ref2.isShown,
onClose = _ref2.onClose;
var onCloseHandler = function onCloseHandler() {
return onClose();
};
return React.createElement(forma36ReactComponents.Modal, {
key: key,
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
allowHeightOverflow: options.allowHeightOverflow || false,
position: options.position || 'center',
isShown: isShown,
onClose: onCloseHandler,
size: size || '700px'
}, function () {
return React.createElement(React.Fragment, null, options.title && React.createElement(forma36ReactComponents.Modal.Header, {
testId: "dialog-title",
title: options.title,
onClose: onCloseHandler
}), React.createElement("div", {
style: {
minHeight: options.minHeight || 'auto'
}
}, React.createElement(Component, {
onClose: onClose
})));
});
});
}
var ModalDialogLauncher = {
openDialog: openDialog
};
var ModalDialogLauncher$1 = {
__proto__: null,
open: open,
openDialog: openDialog,
'default': ModalDialogLauncher
};
function titleOrDefault(title, defaultTitle) {

@@ -1059,0 +1082,0 @@ if (!isString(title)) {

@@ -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/throttle")),n=e(require("lodash/isEqual")),o=require("@contentful/forma-36-react-components"),i=e(require("@contentful/forma-36-tokens")),a=require("emotion"),u=e(require("lodash/isNumber")),l=e(require("react-dom")),s=e(require("lodash/get")),c=e(require("lodash/isObject")),f=e(require("lodash/isString"));function d(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){d(i,n,o,a,u,"next",e)}function u(e){d(i,n,o,a,u,"throw",e)}a(void 0)}))}}function p(){return(p=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)}var v=function(e){var t,n;function o(t){var n;(n=e.call(this,t)||this).unsubscribeErrors=null,n.unsubscribeDisabled=null,n.unsubscribeValue=null,n.setValue=r((function(e){return n.props.isEmptyValue(void 0===e?null:e)?new Promise((function(e,t){n.setState({lastSetValue:void 0},(function(){n.props.field.removeValue().then(e).catch(t)}))})):new Promise((function(t,r){n.setState({lastSetValue:e},(function(){n.props.field.setValue(e).then(t).catch(r)}))}))}),n.props.throttle,{leading:0===n.props.throttle});var o=t.field.getValue();return n.state={isLocalValueChange:!1,externalReset:0,value:o,lastSetValue:o,lastRemoteValue:o,disabled:t.isInitiallyDisabled,errors:[]},n}n=e,(t=o).prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n;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.lastSetValue);return{value:t,lastSetValue: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(){var e=p({},this.state);return delete e.lastSetValue,this.props.children(p({},e,{setValue:this.setValue}))},o}(t.Component);v.defaultProps={children:function(){return null},isEmptyValue:function(e){return null===e||""===e},isEqualValues:function(e,t){return n(e,t)},throttle:300};var y=a.css({color:i.red600});function m(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=p({},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 g(e,r){var n=Date.now(),i=u(e.width)?e.width+"px":e.width;return m((function(a){var u=a.onClose,l=function(){return u()};return t.createElement(o.Modal,{key:n,shouldCloseOnOverlayClick:e.shouldCloseOnOverlayClick||!1,shouldCloseOnEscapePress:e.shouldCloseOnEscapePress||!1,allowHeightOverflow:e.allowHeightOverflow||!1,position:e.position||"center",isShown:a.isShown,onClose:l,size:i||"700px"},(function(){return t.createElement(t.Fragment,null,e.title&&t.createElement(o.Modal.Header,{testId:"dialog-title",title:e.title,onClose:l}),t.createElement("div",{style:{minHeight:e.minHeight||"auto"}},t.createElement(r,{onClose:u})))}))}))}var b={__proto__:null,open:m,openDialog:g,default:{openDialog:g}};function w(e,t){return e(t={exports:{}},t.exports),t.exports}var x=w((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=w(a,r);if(u){if(u===c)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=s(e,t,r);if("normal"===l.type){if(n=r.done?"completed":"suspendedYield",l.arg===c)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 s(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var c={};function f(){}function d(){}function h(){}var p={};p[o]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(L([])));y&&y!==t&&r.call(y,o)&&(p=y);var m=h.prototype=f.prototype=Object.create(p);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=s(e[o],e,i);if("throw"!==l.type){var c=l.arg,f=c.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){c.value=e,a(c)}),(function(e){return n("throw",e,a,u)}))}u(l.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function w(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,w(e,t),"throw"===t.method))return c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var n=s(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,c;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,c):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,c)}function x(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(x,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:V}}function V(){return{value:void 0,done:!0}}return d.prototype=m.constructor=h,h.constructor=d,d.displayName=u(h,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,h):(e.__proto__=h,u(e,a,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},g(b.prototype),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"),m[o]=function(){return this},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,c):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),c},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),c}},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),c}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}));function E(e,t){if(!f(e))return t;if(e){var r=e.trim();return 0===r.length?t:r}return t}function C(e){var t=e.localeCode,r=e.defaultLocaleCode,n=s(e.entity,["fields",e.fieldId]);if(c(n)){var o=Object.keys(n)[0];return n[t]||n[r]||n[o]}}var L={__proto__:null,getFieldValue:C,getAssetTitle:function(e){var t=e.defaultTitle;return E(C({entity:e.asset,fieldId:"title",localeCode:e.localeCode,defaultLocaleCode:e.defaultLocaleCode}),t)},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 function(e){return["Symbol","Text"].includes(e.type)}(e)&&!function(e){return e.id===r.displayField}(e)&&!function(e){return/\bslug\b/.test(e.name)}(e)}));return i&&C({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=C({entity:r,fieldId:u,localeCode:o,defaultLocaleCode:i}))||(t=C({entity:r,fieldId:l.id,localeCode:o,defaultLocaleCode:i})):(t=C({entity:r,fieldId:u,defaultLocaleCode:i,localeCode:""}))||(t=C({entity:r,fieldId:l.id,defaultLocaleCode:i,localeCode:""})),E(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(x.mark((function e(t,r){var n,o,i,a,u,l,c;return x.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((function(e){return"Link"===e.type&&"Asset"===e.linkType}))){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)}}()},V={__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[y]=!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=V,exports.FieldConnector=v,exports.ModalDialogLauncher=b,exports.PredefinedValuesError=function(){return t.createElement(o.Note,{noteType:"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=L;
"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/forma-36-react-components"),i=e(require("@contentful/forma-36-tokens")),a=require("emotion"),u=e(require("lodash/isNumber")),l=e(require("react-dom")),c=e(require("lodash/get")),s=e(require("lodash/isObject")),f=e(require("lodash/isString"));function d(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){d(i,n,o,a,u,"next",e)}function u(e){d(i,n,o,a,u,"throw",e)}a(void 0)}))}}function p(){return(p=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 v(e,t){return(v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function y(e,t){return e(t={exports:{}},t.exports),t.exports}var m=y((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=w(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 h(){}var p={};p[o]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(L([])));y&&y!==t&&r.call(y,o)&&(p=y);var m=h.prototype=f.prototype=Object.create(p);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 w(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,w(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 x(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(x,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:_}}function _(){return{value:void 0,done:!0}}return d.prototype=m.constructor=h,h.constructor=d,d.displayName=u(h,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,h):(e.__proto__=h,u(e,a,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},g(b.prototype),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"),m[o]=function(){return this},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){Function("r","regeneratorRuntime = r")(t)}})),g=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(m.mark((function e(t){return m.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,v(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(p({},this.state,{setValue:this.setValue}))},o}(t.Component);g.defaultProps={children:function(){return null},isEmptyValue:function(e){return null===e||""===e},isEqualValues:function(e,t){return r(e,t)},throttle:300};var b=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=p({},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 x(e,r){var n=Date.now(),i=u(e.width)?e.width+"px":e.width;return w((function(a){var u=a.onClose,l=function(){return u()};return t.createElement(o.Modal,{key:n,shouldCloseOnOverlayClick:e.shouldCloseOnOverlayClick||!1,shouldCloseOnEscapePress:e.shouldCloseOnEscapePress||!1,allowHeightOverflow:e.allowHeightOverflow||!1,position:e.position||"center",isShown:a.isShown,onClose:l,size:i||"700px"},(function(){return t.createElement(t.Fragment,null,e.title&&t.createElement(o.Modal.Header,{testId:"dialog-title",title:e.title,onClose:l}),t.createElement("div",{style:{minHeight:e.minHeight||"auto"}},t.createElement(r,{onClose:u})))}))}))}var E={__proto__:null,open:w,openDialog:x,default:{openDialog:x}};function C(e,t){if(!f(e))return t;if(e){var r=e.trim();return 0===r.length?t:r}return t}function L(e){var t=e.localeCode,r=e.defaultLocaleCode,n=c(e.entity,["fields",e.fieldId]);if(s(n)){var o=Object.keys(n)[0];return n[t]||n[r]||n[o]}}var _={__proto__:null,getFieldValue:L,getAssetTitle:function(e){var t=e.defaultTitle;return C(L({entity:e.asset,fieldId:"title",localeCode:e.localeCode,defaultLocaleCode:e.defaultLocaleCode}),t)},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 function(e){return["Symbol","Text"].includes(e.type)}(e)&&!function(e){return e.id===r.displayField}(e)&&!function(e){return/\bslug\b/.test(e.name)}(e)}));return i&&L({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=L({entity:r,fieldId:u,localeCode:o,defaultLocaleCode:i}))||(t=L({entity:r,fieldId:l.id,localeCode:o,defaultLocaleCode:i})):(t=L({entity:r,fieldId:u,defaultLocaleCode:i,localeCode:""}))||(t=L({entity:r,fieldId:l.id,defaultLocaleCode:i,localeCode:""})),C(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(m.mark((function e(t,r){var n,o,i,a,u,l,s;return m.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((function(e){return"Link"===e.type&&"Asset"===e.linkType}))){e.next=6;break}return e.abrupt("return",null);case 6:if(u=c(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=c(e.sent,["fields","file",i]),s=Boolean(c(l,["details","image"],!1)),e.abrupt("return",s?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)}}()},V={__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[b]=!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=V,exports.FieldConnector=g,exports.ModalDialogLauncher=E,exports.PredefinedValuesError=function(){return t.createElement(o.Note,{noteType:"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=_;
//# sourceMappingURL=field-editor-shared.cjs.production.min.js.map
import React from 'react';
import isEqual from 'lodash-es/isEqual';
import throttle from 'lodash-es/throttle';
import isEqual from 'lodash-es/isEqual';
import { Note, Modal } from '@contentful/forma-36-react-components';

@@ -70,253 +70,15 @@ import tokens from '@contentful/forma-36-tokens';

subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var FieldConnector = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(FieldConnector, _React$Component);
function FieldConnector(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.unsubscribeErrors = null;
_this.unsubscribeDisabled = null;
_this.unsubscribeValue = null;
_this.setValue = throttle(function (value) {
if (_this.props.isEmptyValue(value === undefined ? null : value)) {
return new Promise(function (resolve, reject) {
_this.setState({
lastSetValue: undefined
}, function () {
_this.props.field.removeValue().then(resolve)["catch"](reject);
});
});
} else {
return new Promise(function (resolve, reject) {
_this.setState({
lastSetValue: value
}, function () {
_this.props.field.setValue(value).then(resolve)["catch"](reject);
});
});
}
}, _this.props.throttle, {
leading: _this.props.throttle === 0
});
var initialValue = props.field.getValue();
_this.state = {
isLocalValueChange: false,
externalReset: 0,
value: initialValue,
lastSetValue: initialValue,
lastRemoteValue: initialValue,
disabled: props.isInitiallyDisabled,
errors: []
};
return _this;
}
var _proto = FieldConnector.prototype;
_proto.componentDidMount = function componentDidMount() {
var _this2 = this;
var field = this.props.field;
this.unsubscribeErrors = field.onSchemaErrorsChanged(function (errors) {
_this2.setState({
errors: errors || []
});
});
this.unsubscribeDisabled = field.onIsDisabledChanged(function (disabled) {
_this2.setState({
disabled: disabled
});
});
this.unsubscribeValue = field.onValueChanged(function (value) {
_this2.setState(function (currentState) {
var isLocalValueChange = _this2.props.isEqualValues(value, currentState.lastSetValue);
var lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
var externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
return {
value: value,
lastSetValue: value,
lastRemoteValue: lastRemoteValue,
isLocalValueChange: isLocalValueChange,
externalReset: externalReset
};
});
});
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (typeof this.unsubscribeErrors === 'function') {
this.unsubscribeErrors();
}
if (typeof this.unsubscribeDisabled === 'function') {
this.unsubscribeDisabled();
}
if (typeof this.unsubscribeValue === 'function') {
this.unsubscribeValue();
}
};
_proto.render = function render() {
var childProps = _extends({}, this.state); // `lastSetValue` can be either the `setValue()` value right after it got called
// or the current remote value. No use-case for passing this to child.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete childProps.lastSetValue;
return this.props.children(_extends({}, childProps, {
// @ts-expect-error
setValue: this.setValue
}));
};
return FieldConnector;
}(React.Component);
FieldConnector.defaultProps = {
children: function children() {
return null;
},
// eslint-disable-next-line
isEmptyValue: function isEmptyValue(value) {
return value === null || value === '';
},
// eslint-disable-next-line
isEqualValues: function isEqualValues(value1, value2) {
return isEqual(value1, value2);
},
throttle: 300
};
function PredefinedValuesError() {
return React.createElement(Note, {
noteType: "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.");
_setPrototypeOf(subClass, superClass);
}
var styles = {
invalid: /*#__PURE__*/css({
color: tokens.red600
})
};
function CharCounter(props) {
var _cx;
var count = 0;
if (props.value) {
count = props.value.length;
}
var valid = count === 0 || props.checkConstraint(count);
return React.createElement("span", {
"data-status-code": valid ? null : 'invalid-size',
className: cx((_cx = {}, _cx[styles.invalid] = !valid, _cx))
}, count, " characters");
}
function CharValidation(props) {
var constraints = props.constraints;
if (constraints.type === 'max') {
return React.createElement("span", null, "Maximum ", constraints.max, " characters");
} else if (constraints.type === 'min') {
return React.createElement("span", null, "Requires at least ", constraints.min, " characters");
} else {
return React.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
}
}
function open(componentRenderer) {
var rootDom = null;
var getRoot = function getRoot() {
if (rootDom === null) {
rootDom = document.createElement('div');
rootDom.setAttribute('id', 'field-editor-modal-root');
document.body.appendChild(rootDom);
}
return rootDom;
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return new Promise(function (resolve) {
var currentConfig = {
onClose: onClose,
isShown: true
};
function render(_ref) {
var onClose = _ref.onClose,
isShown = _ref.isShown;
ReactDOM.render(componentRenderer({
onClose: onClose,
isShown: isShown
}), getRoot());
}
function onClose() {
currentConfig = _extends({}, currentConfig, {
isShown: false
});
render(currentConfig);
resolve.apply(void 0, arguments);
getRoot().remove();
}
render(currentConfig);
});
return _setPrototypeOf(o, p);
}
function openDialog(options, Component) {
var key = Date.now();
var size = isNumber(options.width) ? options.width + "px" : options.width;
return open(function (_ref2) {
var isShown = _ref2.isShown,
onClose = _ref2.onClose;
var onCloseHandler = function onCloseHandler() {
return onClose();
};
return React.createElement(Modal, {
key: key,
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
allowHeightOverflow: options.allowHeightOverflow || false,
position: options.position || 'center',
isShown: isShown,
onClose: onCloseHandler,
size: size || '700px'
}, function () {
return React.createElement(React.Fragment, null, options.title && React.createElement(Modal.Header, {
testId: "dialog-title",
title: options.title,
onClose: onCloseHandler
}), React.createElement("div", {
style: {
minHeight: options.minHeight || 'auto'
}
}, React.createElement(Component, {
onClose: onClose
})));
});
});
}
var ModalDialogLauncher = {
openDialog: openDialog
};
var ModalDialogLauncher$1 = {
__proto__: null,
open: open,
openDialog: openDialog,
'default': ModalDialogLauncher
};
function createCommonjsModule(fn, module) {

@@ -1050,2 +812,263 @@ return module = { exports: {} }, fn(module, module.exports), module.exports;

var FieldConnector = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(FieldConnector, _React$Component);
function FieldConnector(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.unsubscribeErrors = null;
_this.unsubscribeDisabled = null;
_this.unsubscribeValue = null;
_this.setValue = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(value) {
return runtime_1.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (_this.props.isEmptyValue(value != null ? value : null)) {
_this.setState({
value: undefined
});
} else {
_this.setState({
value: value
});
}
_context.next = 3;
return _this.triggerSetValueCallbacks(value);
case 3:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
_this.triggerSetValueCallbacks = throttle(function (value) {
return new Promise(function (resolve, reject) {
if (_this.props.isEmptyValue(value != null ? value : null)) {
_this.props.field.removeValue().then(resolve)["catch"](reject);
} else {
_this.props.field.setValue(value).then(resolve)["catch"](reject);
}
});
}, _this.props.throttle, {
leading: _this.props.throttle === 0
});
var initialValue = props.field.getValue();
_this.state = {
isLocalValueChange: false,
externalReset: 0,
value: initialValue,
lastRemoteValue: initialValue,
disabled: props.isInitiallyDisabled,
errors: []
};
return _this;
}
var _proto = FieldConnector.prototype;
_proto.componentDidMount = function componentDidMount() {
var _this2 = this;
var field = this.props.field;
this.unsubscribeErrors = field.onSchemaErrorsChanged(function (errors) {
_this2.setState({
errors: errors || []
});
});
this.unsubscribeDisabled = field.onIsDisabledChanged(function (disabled) {
_this2.setState({
disabled: disabled
});
});
this.unsubscribeValue = field.onValueChanged(function (value) {
_this2.setState(function (currentState) {
var isLocalValueChange = _this2.props.isEqualValues(value, currentState.value);
var lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
var externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
return {
value: value,
lastRemoteValue: lastRemoteValue,
isLocalValueChange: isLocalValueChange,
externalReset: externalReset
};
});
});
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (typeof this.unsubscribeErrors === 'function') {
this.unsubscribeErrors();
}
if (typeof this.unsubscribeDisabled === 'function') {
this.unsubscribeDisabled();
}
if (typeof this.unsubscribeValue === 'function') {
this.unsubscribeValue();
}
};
_proto.render = function render() {
return this.props.children(_extends({}, this.state, {
setValue: this.setValue
}));
};
return FieldConnector;
}(React.Component);
FieldConnector.defaultProps = {
children: function children() {
return null;
},
// eslint-disable-next-line
isEmptyValue: function isEmptyValue(value) {
return value === null || value === '';
},
// eslint-disable-next-line
isEqualValues: function isEqualValues(value1, value2) {
return isEqual(value1, value2);
},
throttle: 300
};
function PredefinedValuesError() {
return React.createElement(Note, {
noteType: "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.");
}
var styles = {
invalid: /*#__PURE__*/css({
color: tokens.red600
})
};
function CharCounter(props) {
var _cx;
var count = 0;
if (props.value) {
count = props.value.length;
}
var valid = count === 0 || props.checkConstraint(count);
return React.createElement("span", {
"data-status-code": valid ? null : 'invalid-size',
className: cx((_cx = {}, _cx[styles.invalid] = !valid, _cx))
}, count, " characters");
}
function CharValidation(props) {
var constraints = props.constraints;
if (constraints.type === 'max') {
return React.createElement("span", null, "Maximum ", constraints.max, " characters");
} else if (constraints.type === 'min') {
return React.createElement("span", null, "Requires at least ", constraints.min, " characters");
} else {
return React.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
}
}
function open(componentRenderer) {
var rootDom = null;
var getRoot = function getRoot() {
if (rootDom === null) {
rootDom = document.createElement('div');
rootDom.setAttribute('id', 'field-editor-modal-root');
document.body.appendChild(rootDom);
}
return rootDom;
};
return new Promise(function (resolve) {
var currentConfig = {
onClose: onClose,
isShown: true
};
function render(_ref) {
var onClose = _ref.onClose,
isShown = _ref.isShown;
ReactDOM.render(componentRenderer({
onClose: onClose,
isShown: isShown
}), getRoot());
}
function onClose() {
currentConfig = _extends({}, currentConfig, {
isShown: false
});
render(currentConfig);
resolve.apply(void 0, arguments);
getRoot().remove();
}
render(currentConfig);
});
}
function openDialog(options, Component) {
var key = Date.now();
var size = isNumber(options.width) ? options.width + "px" : options.width;
return open(function (_ref2) {
var isShown = _ref2.isShown,
onClose = _ref2.onClose;
var onCloseHandler = function onCloseHandler() {
return onClose();
};
return React.createElement(Modal, {
key: key,
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
allowHeightOverflow: options.allowHeightOverflow || false,
position: options.position || 'center',
isShown: isShown,
onClose: onCloseHandler,
size: size || '700px'
}, function () {
return React.createElement(React.Fragment, null, options.title && React.createElement(Modal.Header, {
testId: "dialog-title",
title: options.title,
onClose: onCloseHandler
}), React.createElement("div", {
style: {
minHeight: options.minHeight || 'auto'
}
}, React.createElement(Component, {
onClose: onClose
})));
});
});
}
var ModalDialogLauncher = {
openDialog: openDialog
};
var ModalDialogLauncher$1 = {
__proto__: null,
open: open,
openDialog: openDialog,
'default': ModalDialogLauncher
};
function titleOrDefault(title, defaultTitle) {

@@ -1052,0 +1075,0 @@ if (!isString(title)) {

@@ -17,3 +17,2 @@ /// <reference types="lodash" />

externalReset: number;
lastSetValue: ValueType | Nullable;
lastRemoteValue: ValueType | Nullable;

@@ -43,3 +42,4 @@ value: ValueType | Nullable;

unsubscribeValue: Function | null;
setValue: import("lodash").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
setValue: (value: ValueType | Nullable) => Promise<void>;
triggerSetValueCallbacks: import("lodash").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
componentDidMount(): void;

@@ -46,0 +46,0 @@ componentWillUnmount(): void;

{
"name": "@contentful/field-editor-shared",
"version": "0.22.0",
"version": "0.22.1",
"main": "dist/index.js",

@@ -19,2 +19,4 @@ "module": "dist/field-editor-shared.esm.js",

"build": "tsdx build",
"test": "tsdx test --env=jsdom --watch",
"test:ci": "tsdx test --env=jsdom --ci",
"tsc": "tsc -p ./ --noEmit"

@@ -40,3 +42,3 @@ },

},
"gitHead": "35aa8358f3badc9a2ace48ceaff847800d6f766a"
"gitHead": "84d94f6280e00ddf7ce579f43e841e08c775db0f"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc