@contentful/field-editor-shared
Advanced tools
Comparing version 0.0.2-alpha.6 to 0.0.2-alpha.9
@@ -98,3 +98,3 @@ 'use strict'; | ||
_this.setValue = throttle(function (value) { | ||
if (value === null || value === undefined || value === '') { | ||
if (_this.props.isEmptyValue(value === undefined ? null : value)) { | ||
_this.props.field.removeValue(); | ||
@@ -104,3 +104,5 @@ } else { | ||
} | ||
}, _this.props.throttle); | ||
}, _this.props.throttle, { | ||
leading: _this.props.throttle === 0 | ||
}); | ||
_this.state = { | ||
@@ -163,2 +165,7 @@ value: props.field.getValue(), | ||
}, | ||
// eslint-disable-next-line | ||
isEmptyValue: function isEmptyValue(value) { | ||
// @ts-ignore | ||
return value === null || value === ''; | ||
}, | ||
throttle: 300 | ||
@@ -165,0 +172,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=e(require("mitt")),t=e(require("react")),r=e(require("lodash/throttle"));function o(e){return e}function u(){return(u=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}var i=function(e){var n,t;function o(n){var t;return(t=e.call(this,n)||this).unsubscribeErrors=null,t.unsubscribeDisabled=null,t.unsubscribeValue=null,t.setValue=r(function(e){null==e||""===e?t.props.field.removeValue():t.props.field.setValue(e)},t.props.throttle),t.state={value:n.field.getValue(),disabled:n.initialDisabled,errors:[]},t}t=e,(n=o).prototype=Object.create(t.prototype),n.prototype.constructor=n,n.__proto__=t;var i=o.prototype;return i.componentDidMount=function(){var e=this,n=this.props.field;this.unsubscribeErrors=n.onSchemaErrorsChanged(function(n){e.setState({errors:n||[]})}),this.unsubscribeDisabled=n.onIsDisabledChanged(function(n){e.setState({disabled:n})}),this.unsubscribeValue=n.onValueChanged(function(n){e.setState({value:n})})},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(u({},this.state,{setValue:this.setValue}))},o}(t.Component);i.defaultProps={children:function(){return null},throttle:300},exports.FieldConnector=i,exports.createFakeFieldAPI=function(e){void 0===e&&(e=o);var t=new n,r=void 0;return e({id:"fake-id",locale:"en-US",type:"",validations:[],required:!1,onValueChanged:function(e){return t.on("value_changed",e),function(){t.off("value_changed",e)}},onIsDisabledChanged:function(e){return t.on("disable_changed",e),function(){t.off("disable_changed",e)}},onSchemaErrorsChanged:function(e){return t.on("errors_changed",e),function(){t.off("errors_changed",e)}},getValue:function(){return r},setInvalid:function(){},setValue:function(e){return t.emit("value_changed",r=e),Promise.resolve()},removeValue:function(){return r="",t.emit("value_changed",""),Promise.resolve()}},t)}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("mitt")),n=e(require("react")),r=e(require("lodash/throttle"));function o(e){return e}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var i=function(e){var t,n;function o(t){var n;return(n=e.call(this,t)||this).unsubscribeErrors=null,n.unsubscribeDisabled=null,n.unsubscribeValue=null,n.setValue=r(function(e){n.props.isEmptyValue(void 0===e?null:e)?n.props.field.removeValue():n.props.field.setValue(e)},n.props.throttle,{leading:0===n.props.throttle}),n.state={value:t.field.getValue(),disabled:t.initialDisabled,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({value:t})})},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(u({},this.state,{setValue:this.setValue}))},o}(n.Component);i.defaultProps={children:function(){return null},isEmptyValue:function(e){return null===e||""===e},throttle:300},exports.FieldConnector=i,exports.createFakeFieldAPI=function(e){void 0===e&&(e=o);var n=new t,r=void 0;return e({id:"fake-id",locale:"en-US",type:"",validations:[],required:!1,onValueChanged:function(e){return n.on("value_changed",e),function(){n.off("value_changed",e)}},onIsDisabledChanged:function(e){return n.on("disable_changed",e),function(){n.off("disable_changed",e)}},onSchemaErrorsChanged:function(e){return n.on("errors_changed",e),function(){n.off("errors_changed",e)}},getValue:function(){return r},setInvalid:function(){},setValue:function(e){return n.emit("value_changed",r=e),Promise.resolve()},removeValue:function(){return r="",n.emit("value_changed",""),Promise.resolve()}},n)}; | ||
//# sourceMappingURL=field-editor-shared.cjs.production.min.js.map |
@@ -94,3 +94,3 @@ import mitt from 'mitt'; | ||
_this.setValue = throttle(function (value) { | ||
if (value === null || value === undefined || value === '') { | ||
if (_this.props.isEmptyValue(value === undefined ? null : value)) { | ||
_this.props.field.removeValue(); | ||
@@ -100,3 +100,5 @@ } else { | ||
} | ||
}, _this.props.throttle); | ||
}, _this.props.throttle, { | ||
leading: _this.props.throttle === 0 | ||
}); | ||
_this.state = { | ||
@@ -159,2 +161,7 @@ value: props.field.getValue(), | ||
}, | ||
// eslint-disable-next-line | ||
isEmptyValue: function isEmptyValue(value) { | ||
// @ts-ignore | ||
return value === null || value === ''; | ||
}, | ||
throttle: 300 | ||
@@ -161,0 +168,0 @@ }; |
/// <reference types="lodash" /> | ||
import React from 'react'; | ||
import { FieldAPI } from 'contentful-ui-extensions-sdk'; | ||
interface FieldConnectorState { | ||
value: any; | ||
declare type Nullable = null | undefined; | ||
interface FieldConnectorState<ValueType> { | ||
value: ValueType | Nullable; | ||
disabled: boolean; | ||
errors: string[]; | ||
} | ||
interface FieldConnectorProps { | ||
interface FieldConnectorProps<ValueType> { | ||
field: FieldAPI; | ||
initialDisabled: boolean; | ||
children: (state: FieldConnectorState & { | ||
setValue: (value: any) => void; | ||
children: (state: FieldConnectorState<ValueType> & { | ||
setValue: (value: ValueType | Nullable) => void; | ||
}) => React.ReactNode; | ||
isEmptyValue: (value: ValueType | null) => boolean; | ||
throttle: number; | ||
} | ||
export declare class FieldConnector extends React.Component<FieldConnectorProps, FieldConnectorState> { | ||
static defaultProps: Pick<FieldConnectorProps, 'children' | 'throttle'>; | ||
constructor(props: FieldConnectorProps); | ||
export declare class FieldConnector<ValueType> extends React.Component<FieldConnectorProps<ValueType>, FieldConnectorState<ValueType>> { | ||
static defaultProps: { | ||
children: () => null; | ||
isEmptyValue: (value: any) => boolean; | ||
throttle: number; | ||
}; | ||
constructor(props: FieldConnectorProps<ValueType>); | ||
unsubscribeErrors: Function | null; | ||
unsubscribeDisabled: Function | null; | ||
unsubscribeValue: Function | null; | ||
setValue: ((value: any) => void) & import("lodash").Cancelable; | ||
setValue: ((value: ValueType | null | undefined) => void) & import("lodash").Cancelable; | ||
componentDidMount(): void; | ||
@@ -25,0 +31,0 @@ componentWillUnmount(): void; |
{ | ||
"name": "@contentful/field-editor-shared", | ||
"version": "0.0.2-alpha.6+75baad8", | ||
"version": "0.0.2-alpha.9+fb58c97", | ||
"main": "dist/index.js", | ||
@@ -18,3 +18,3 @@ "module": "dist/field-editor-shared.esm.js", | ||
"dependencies": { | ||
"contentful-ui-extensions-sdk": "^3.9.1", | ||
"contentful-ui-extensions-sdk": "^3.9.2", | ||
"lodash": "^4.17.15", | ||
@@ -31,3 +31,3 @@ "lodash-es": "^4.17.15" | ||
}, | ||
"gitHead": "75baad86a405fe1a9cc565166bee73a0d27d82c9" | ||
"gitHead": "fb58c973ca96711db44f6d2b74e77c3fb48affd2" | ||
} |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
35905
359