@contentful/field-editor-shared
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -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 |
@@ -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
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
55253
17
513
6
+ Addedemotion@^10.0.17
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/runtime@7.26.0(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Added@contentful/forma-36-tokens@0.5.3(transitive)
+ Added@emotion/cache@10.0.29(transitive)
+ Added@emotion/hash@0.8.0(transitive)
+ Added@emotion/memoize@0.7.4(transitive)
+ Added@emotion/serialize@0.11.16(transitive)
+ Added@emotion/sheet@0.9.4(transitive)
+ Added@emotion/stylis@0.8.5(transitive)
+ Added@emotion/unitless@0.7.5(transitive)
+ Added@emotion/utils@0.11.3(transitive)
+ Added@emotion/weak-memoize@0.2.5(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@types/parse-json@4.0.2(transitive)
+ Addedbabel-plugin-emotion@10.2.2(transitive)
+ Addedbabel-plugin-macros@2.8.0(transitive)
+ Addedbabel-plugin-syntax-jsx@6.18.0(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedcosmiconfig@6.0.0(transitive)
+ Addedcreate-emotion@10.0.27(transitive)
+ Addedcsstype@2.6.21(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedemotion@10.0.27(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfind-root@1.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedimport-fresh@3.3.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedms@2.1.3(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@4.0.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedyaml@1.10.2(transitive)