Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentful/field-editor-shared

Package Overview
Dependencies
Maintainers
62
Versions
88
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.3.1 to 0.4.0

dist/CharCounter.d.ts

94

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

@@ -9,2 +9,5 @@ 'use strict';

var forma36ReactComponents = require('@contentful/forma-36-react-components');
var tokens = _interopDefault(require('@contentful/forma-36-tokens'));
var emotion = require('emotion');
var isNumber = _interopDefault(require('lodash/isNumber'));

@@ -148,4 +151,95 @@ function _extends() {

var styles = {
invalid:
/*#__PURE__*/
emotion.css({
color: tokens.colorRedBase
})
};
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");
}
}
/* eslint-disable @typescript-eslint/no-explicit-any */
function fromFieldValidations(validations, fieldType) {
if (validations === void 0) {
validations = [];
}
var sizeValidation = validations.find(function (v) {
return 'size' in v;
});
var size = sizeValidation && sizeValidation.size || {};
var min = size.min;
var max = size.max;
if (isNumber(min) && isNumber(max)) {
return {
type: 'min-max',
min: min,
max: max
};
} else if (isNumber(min)) {
return {
type: 'min',
min: min
};
} else if (isNumber(max)) {
return {
type: 'max',
max: max
};
} else {
return {
type: 'max',
max: fieldType === 'Symbol' ? 256 : 50000
};
}
}
function makeChecker(constraint) {
return function checkConstraint(length) {
if (constraint.type === 'max') {
return length <= constraint.max;
} else if (constraint.type === 'min') {
return length >= constraint.min;
} else {
return length >= constraint.min && length <= constraint.max;
}
};
}
var constraints = ({
fromFieldValidations: fromFieldValidations,
makeChecker: makeChecker
});
exports.CharCounter = CharCounter;
exports.CharValidation = CharValidation;
exports.ConstraintsUtils = constraints;
exports.FieldConnector = FieldConnector;
exports.PredefinedValuesError = PredefinedValuesError;
//# sourceMappingURL=field-editor-shared.cjs.development.js.map

2

dist/field-editor-shared.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("react")),r=e(require("lodash/throttle")),n=e(require("lodash/isEqual")),s=require("@contentful/forma-36-react-components");function i(){return(i=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 u=function(e){var t,n;function s(t){var n;(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.setState({lastSetValue:void 0},(function(){n.props.field.removeValue()})):n.setState({lastSetValue:e},(function(){n.props.field.setValue(e)}))}),n.props.throttle,{leading:0===n.props.throttle});var s=t.field.getValue();return n.state={externalReset:0,value:s,lastSetValue:s,disabled:t.isInitiallyDisabled,errors:[]},n}n=e,(t=s).prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n;var u=s.prototype;return u.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,externalReset:n?r.externalReset:r.externalReset+1}}))}))},u.componentWillUnmount=function(){"function"==typeof this.unsubscribeErrors&&this.unsubscribeErrors(),"function"==typeof this.unsubscribeDisabled&&this.unsubscribeDisabled(),"function"==typeof this.unsubscribeValue&&this.unsubscribeValue()},u.render=function(){return this.props.children(i({},this.state,{setValue:this.setValue}))},s}(t.Component);u.defaultProps={children:function(){return null},isEmptyValue:function(e){return null===e||""===e},isEqualValues:function(e,t){return n(e,t)},throttle:300},exports.FieldConnector=u,exports.PredefinedValuesError=function(){return t.createElement(s.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.")};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("react")),n=e(require("lodash/throttle")),r=e(require("lodash/isEqual")),a=require("@contentful/forma-36-react-components"),i=e(require("@contentful/forma-36-tokens")),s=require("emotion"),u=e(require("lodash/isNumber"));function o(){return(o=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 l=function(e){var t,r;function a(t){var r;(r=e.call(this,t)||this).unsubscribeErrors=null,r.unsubscribeDisabled=null,r.unsubscribeValue=null,r.setValue=n((function(e){r.props.isEmptyValue(void 0===e?null:e)?r.setState({lastSetValue:void 0},(function(){r.props.field.removeValue()})):r.setState({lastSetValue:e},(function(){r.props.field.setValue(e)}))}),r.props.throttle,{leading:0===r.props.throttle});var a=t.field.getValue();return r.state={externalReset:0,value:a,lastSetValue:a,disabled:t.isInitiallyDisabled,errors:[]},r}r=e,(t=a).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r;var i=a.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(n){var r=e.props.isEqualValues(t,n.lastSetValue);return{value:t,lastSetValue:t,externalReset:r?n.externalReset:n.externalReset+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(o({},this.state,{setValue:this.setValue}))},a}(t.Component);l.defaultProps={children:function(){return null},isEmptyValue:function(e){return null===e||""===e},isEqualValues:function(e,t){return r(e,t)},throttle:300};var c=s.css({color:i.colorRedBase}),p={fromFieldValidations:function(e,t){void 0===e&&(e=[]);var n=e.find((function(e){return"size"in e})),r=n&&n.size||{},a=r.min,i=r.max;return u(a)&&u(i)?{type:"min-max",min:a,max:i}:u(a)?{type:"min",min:a}: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 n,r=0;e.value&&(r=e.value.length);var a=0===r||e.checkConstraint(r);return t.createElement("span",{"data-status-code":a?null:"invalid-size",className:s.cx((n={},n[c]=!a,n))},r," characters")},exports.CharValidation=function(e){var n=e.constraints;return"max"===n.type?t.createElement("span",null,"Maximum ",n.max," characters"):"min"===n.type?t.createElement("span",null,"Requires at least ",n.min," characters"):t.createElement("span",null,"Requires between ",n.min," and ",n.max," characters")},exports.ConstraintsUtils=p,exports.FieldConnector=l,exports.PredefinedValuesError=function(){return t.createElement(a.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.")};
//# sourceMappingURL=field-editor-shared.cjs.production.min.js.map

@@ -5,2 +5,5 @@ import React from 'react';

import { Note } from '@contentful/forma-36-react-components';
import tokens from '@contentful/forma-36-tokens';
import { css, cx } from 'emotion';
import isNumber from 'lodash-es/isNumber';

@@ -144,3 +147,91 @@ function _extends() {

export { FieldConnector, PredefinedValuesError };
var styles = {
invalid:
/*#__PURE__*/
css({
color: tokens.colorRedBase
})
};
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");
}
}
/* eslint-disable @typescript-eslint/no-explicit-any */
function fromFieldValidations(validations, fieldType) {
if (validations === void 0) {
validations = [];
}
var sizeValidation = validations.find(function (v) {
return 'size' in v;
});
var size = sizeValidation && sizeValidation.size || {};
var min = size.min;
var max = size.max;
if (isNumber(min) && isNumber(max)) {
return {
type: 'min-max',
min: min,
max: max
};
} else if (isNumber(min)) {
return {
type: 'min',
min: min
};
} else if (isNumber(max)) {
return {
type: 'max',
max: max
};
} else {
return {
type: 'max',
max: fieldType === 'Symbol' ? 256 : 50000
};
}
}
function makeChecker(constraint) {
return function checkConstraint(length) {
if (constraint.type === 'max') {
return length <= constraint.max;
} else if (constraint.type === 'min') {
return length >= constraint.min;
} else {
return length >= constraint.min && length <= constraint.max;
}
};
}
var constraints = ({
fromFieldValidations: fromFieldValidations,
makeChecker: makeChecker
});
export { CharCounter, CharValidation, constraints as ConstraintsUtils, FieldConnector, PredefinedValuesError };
//# sourceMappingURL=field-editor-shared.esm.js.map
export { FieldAPI, ParametersAPI } from 'contentful-ui-extensions-sdk';
export { FieldConnector } from './FieldConnector';
export { PredefinedValuesError } from './PredefinedValuesError';
export { CharCounter } from './CharCounter';
export { CharValidation } from './CharValidation';
import * as ConstraintsUtils from './utils/constraints';
export { ConstraintsUtils };
{
"name": "@contentful/field-editor-shared",
"version": "0.3.1",
"version": "0.4.0",
"main": "dist/index.js",

@@ -22,3 +22,5 @@ "module": "dist/field-editor-shared.esm.js",

"dependencies": {
"contentful-ui-extensions-sdk": "^3.9.2",
"@contentful/forma-36-tokens": "^0.5.1",
"contentful-ui-extensions-sdk": "^3.10.4",
"emotion": "^10.0.17",
"lodash": "^4.17.15",

@@ -35,3 +37,3 @@ "lodash-es": "^4.17.15"

},
"gitHead": "70efc6c86f4d029f34e11d9b1edb08f3ef4d7dd0"
"gitHead": "f3001b6329054b1e33756f6c87a1ab96e552ac52"
}

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