@limetech/lime-elements 37.61.3 → 37.61.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/limel-form.cjs.entry.js +6 -0
  3. package/dist/cjs/limel-form.cjs.entry.js.map +1 -1
  4. package/dist/cjs/limel-markdown.cjs.entry.js +1 -1
  5. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +1 -1
  6. package/dist/cjs/{markdown-parser-23fa389f.js → markdown-parser-c4a1ec47.js} +6 -2
  7. package/dist/cjs/markdown-parser-c4a1ec47.js.map +1 -0
  8. package/dist/collection/components/form/adapters/widget-adapter.js +3 -0
  9. package/dist/collection/components/form/adapters/widget-adapter.js.map +1 -1
  10. package/dist/collection/components/form/fields/schema-field.js +3 -0
  11. package/dist/collection/components/form/fields/schema-field.js.map +1 -1
  12. package/dist/esm/limel-form.entry.js +6 -0
  13. package/dist/esm/limel-form.entry.js.map +1 -1
  14. package/dist/esm/limel-markdown.entry.js +1 -1
  15. package/dist/esm/limel-prosemirror-adapter.entry.js +1 -1
  16. package/dist/esm/{markdown-parser-4a4cd2c9.js → markdown-parser-108384e8.js} +6 -2
  17. package/dist/esm/markdown-parser-108384e8.js.map +1 -0
  18. package/dist/lime-elements/lime-elements.esm.js +1 -1
  19. package/dist/lime-elements/{p-31ebf375.js → p-a7fca1dd.js} +2 -2
  20. package/dist/lime-elements/p-a7fca1dd.js.map +1 -0
  21. package/dist/lime-elements/{p-66bea69a.entry.js → p-c864b34b.entry.js} +2 -2
  22. package/dist/lime-elements/{p-66bea69a.entry.js.map → p-c864b34b.entry.js.map} +1 -1
  23. package/dist/lime-elements/{p-cd04c508.entry.js → p-df684b38.entry.js} +2 -2
  24. package/dist/lime-elements/{p-75cfe1e5.entry.js → p-ee74cfff.entry.js} +2 -2
  25. package/package.json +3 -3
  26. package/dist/cjs/markdown-parser-23fa389f.js.map +0 -1
  27. package/dist/esm/markdown-parser-4a4cd2c9.js.map +0 -1
  28. package/dist/lime-elements/p-31ebf375.js.map +0 -1
  29. /package/dist/lime-elements/{p-cd04c508.entry.js.map → p-df684b38.entry.js.map} +0 -0
  30. /package/dist/lime-elements/{p-75cfe1e5.entry.js.map → p-ee74cfff.entry.js.map} +0 -0
@@ -29,6 +29,9 @@ export class LimeElementsWidgetAdapter extends React.Component {
29
29
  if (Array.isArray(value)) {
30
30
  return !!value.length;
31
31
  }
32
+ if (value instanceof Date) {
33
+ return true;
34
+ }
32
35
  if (typeof value === 'object') {
33
36
  return !!Object.entries(value).length;
34
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"widget-adapter.js","sourceRoot":"","sources":["../../../../src/components/form/adapters/widget-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAU3C;;;;;;;;;GASG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK,CAAC,SAAS;EAK1D,YAAmB,KAAyB;IACxC,KAAK,CAAC,KAAK,CAAC,CAAC;IADE,UAAK,GAAL,KAAK,CAAoB;IAJ5C,UAAK,GAAG;MACJ,QAAQ,EAAE,KAAK;KAClB,CAAC;IAKE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;EACjD,CAAC;EAEO,QAAQ;IACZ,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC9B,IAAI,CAAC,KAAK,EAAE;MACR,OAAO,KAAK,CAAC;KAChB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;MACtB,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;KACzB;I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AAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;IAExC,OAAO,CACH,WAAW,CAAC,QAAQ;OACpB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAA;OACjB,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,KAAK,0CAAE,QAAQ,CAAA,CACtC,CAAC;EACN,CAAC;EAEO,UAAU;IACd,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAE3C,OAAO,WAAW,CAAC,QAAQ,CAAC;EAChC,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { WidgetProps } from '../widgets/types';\nimport { LimeElementsAdapter } from './base-adapter';\nimport { capitalize } from 'lodash-es';\nimport { getHelpComponent } from '../help';\n\ninterface WidgetAdapterProps {\n name: string;\n value?: any;\n widgetProps: WidgetProps;\n extraProps?: any;\n events?: { [key: string]: (event: any) => void };\n}\n\n/**\n * A widget is a concept in react-jsonschema-form (rjsf).\n * It represents a HTML tag for the user to enter data, eg. input, select, etc.\n *\n * We use the widget adapter exclusively so we can use lime-elements instead of the\n * default input/select/checkbox/etc fields that rjsf provides.\n *\n * Please read the docs for more info.\n * Link: https://react-jsonschema-form.readthedocs.io/\n */\nexport class LimeElementsWidgetAdapter extends React.Component {\n state = {\n modified: false,\n };\n\n constructor(public props: WidgetAdapterProps) {\n super(props);\n\n this.handleBlur = this.handleBlur.bind(this);\n }\n\n private hasValue() {\n const value = this.getValue();\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value)) {\n return !!value.length;\n }\n\n if (typeof value === 'object') {\n return !!Object.entries(value).length;\n }\n\n return true;\n }\n\n private handleBlur() {\n this.setState({ modified: true });\n }\n\n private getLabel() {\n const { schema, label } = this.props.widgetProps;\n\n return label || schema.title;\n }\n\n private isInvalid() {\n const { modified } = this.state;\n const { rawErrors } = this.props.widgetProps;\n\n return (\n !!rawErrors && (modified || this.hasValue() || !this.isRequired())\n );\n }\n\n private isRequired() {\n const { required, schema } = this.props.widgetProps;\n\n return required || schema.minItems > 0;\n }\n\n private getHelperText() {\n const { rawErrors, schema } = this.props.widgetProps;\n\n if (!this.isInvalid()) {\n return schema.description;\n }\n\n if (rawErrors) {\n return capitalize(rawErrors[0]);\n }\n\n return schema.description;\n }\n\n private getValue() {\n const { value } = this.props;\n const { value: widgetValue } = this.props.widgetProps;\n\n // Use widgetValue unless its overriden in widget\n return value || widgetValue;\n }\n\n render() {\n const { name, events, extraProps } = this.props;\n const disabled = this.isDisabled();\n const value = this.getValue();\n const readonly = this.isReadOnly();\n\n const newEvents = {\n change: this.props.widgetProps.onChange,\n blur: this.handleBlur,\n ...events,\n };\n\n return React.createElement(\n React.Fragment,\n {},\n React.createElement(LimeElementsAdapter, {\n name: name,\n elementProps: {\n value: value,\n label: this.getLabel(),\n disabled: disabled,\n readonly: readonly,\n required: this.isRequired(),\n invalid: this.isInvalid(),\n 'helper-text': this.getHelperText(),\n ...extraProps,\n },\n events: newEvents,\n }),\n getHelpComponent(this.props.widgetProps.schema),\n );\n }\n\n private isDisabled() {\n const widgetProps = this.props.widgetProps;\n const options = widgetProps.schema.lime;\n\n return (\n widgetProps.disabled ||\n options?.disabled ||\n options?.component?.props?.disabled\n );\n }\n\n private isReadOnly() {\n const widgetProps = this.props.widgetProps;\n\n return widgetProps.readonly;\n }\n}\n"]}
1
+ {"version":3,"file":"widget-adapter.js","sourceRoot":"","sources":["../../../../src/components/form/adapters/widget-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAU3C;;;;;;;;;GASG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK,CAAC,SAAS;EAK1D,YAAmB,KAAyB;IACxC,KAA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AI,EAAE,IAAI;MACV,YAAY,kBACR,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,EACtB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,EAC3B,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,EACzB,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,IAChC,UAAU,CAChB;MACD,MAAM,EAAE,SAAS;KACpB,CAAC,EACF,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAClD,CAAC;EACN,CAAC;EAEO,UAAU;;IACd,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAC3C,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;IAExC,OAAO,CACH,WAAW,CAAC,QAAQ;OACpB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAA;OACjB,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,KAAK,0CAAE,QAAQ,CAAA,CACtC,CAAC;EACN,CAAC;EAEO,UAAU;IACd,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAE3C,OAAO,WAAW,CAAC,QAAQ,CAAC;EAChC,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { WidgetProps } from '../widgets/types';\nimport { LimeElementsAdapter } from './base-adapter';\nimport { capitalize } from 'lodash-es';\nimport { getHelpComponent } from '../help';\n\ninterface WidgetAdapterProps {\n name: string;\n value?: any;\n widgetProps: WidgetProps;\n extraProps?: any;\n events?: { [key: string]: (event: any) => void };\n}\n\n/**\n * A widget is a concept in react-jsonschema-form (rjsf).\n * It represents a HTML tag for the user to enter data, eg. input, select, etc.\n *\n * We use the widget adapter exclusively so we can use lime-elements instead of the\n * default input/select/checkbox/etc fields that rjsf provides.\n *\n * Please read the docs for more info.\n * Link: https://react-jsonschema-form.readthedocs.io/\n */\nexport class LimeElementsWidgetAdapter extends React.Component {\n state = {\n modified: false,\n };\n\n constructor(public props: WidgetAdapterProps) {\n super(props);\n\n this.handleBlur = this.handleBlur.bind(this);\n }\n\n private hasValue() {\n const value = this.getValue();\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value)) {\n return !!value.length;\n }\n\n if (value instanceof Date) {\n return true;\n }\n\n if (typeof value === 'object') {\n return !!Object.entries(value).length;\n }\n\n return true;\n }\n\n private handleBlur() {\n this.setState({ modified: true });\n }\n\n private getLabel() {\n const { schema, label } = this.props.widgetProps;\n\n return label || schema.title;\n }\n\n private isInvalid() {\n const { modified } = this.state;\n const { rawErrors } = this.props.widgetProps;\n\n return (\n !!rawErrors && (modified || this.hasValue() || !this.isRequired())\n );\n }\n\n private isRequired() {\n const { required, schema } = this.props.widgetProps;\n\n return required || schema.minItems > 0;\n }\n\n private getHelperText() {\n const { rawErrors, schema } = this.props.widgetProps;\n\n if (!this.isInvalid()) {\n return schema.description;\n }\n\n if (rawErrors) {\n return capitalize(rawErrors[0]);\n }\n\n return schema.description;\n }\n\n private getValue() {\n const { value } = this.props;\n const { value: widgetValue } = this.props.widgetProps;\n\n // Use widgetValue unless its overriden in widget\n return value || widgetValue;\n }\n\n render() {\n const { name, events, extraProps } = this.props;\n const disabled = this.isDisabled();\n const value = this.getValue();\n const readonly = this.isReadOnly();\n\n const newEvents = {\n change: this.props.widgetProps.onChange,\n blur: this.handleBlur,\n ...events,\n };\n\n return React.createElement(\n React.Fragment,\n {},\n React.createElement(LimeElementsAdapter, {\n name: name,\n elementProps: {\n value: value,\n label: this.getLabel(),\n disabled: disabled,\n readonly: readonly,\n required: this.isRequired(),\n invalid: this.isInvalid(),\n 'helper-text': this.getHelperText(),\n ...extraProps,\n },\n events: newEvents,\n }),\n getHelpComponent(this.props.widgetProps.schema),\n );\n }\n\n private isDisabled() {\n const widgetProps = this.props.widgetProps;\n const options = widgetProps.schema.lime;\n\n return (\n widgetProps.disabled ||\n options?.disabled ||\n options?.component?.props?.disabled\n );\n }\n\n private isReadOnly() {\n const widgetProps = this.props.widgetProps;\n\n return widgetProps.readonly;\n }\n}\n"]}
@@ -100,6 +100,9 @@ export class SchemaField extends React.Component {
100
100
  if (Array.isArray(value)) {
101
101
  return !!value.length;
102
102
  }
103
+ if (value instanceof Date) {
104
+ return true;
105
+ }
103
106
  if (typeof value === 'object') {
104
107
  return !isEmpty(value);
105
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema-field.js","sourceRoot":"","sources":["../../../../src/components/form/fields/schema-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,eAAe,MAAM,8CAA8C,CAAC;AAC3E,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAW,EAAE;EACvD,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAW,EAAE;;EAC3C,MAAM,IAAI,GAAG,MAAA,MAAA,MAAM,CAAC,IAAI,0CAAE,SAAS,0CAAE,IAAI,CAAC;EAC1C,IAAI,CAAC,IAAI,EAAE;IACP,OAAO,KAAK,CAAC;GACh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,aAAa,CAAC,mBAAmB,EAAE;MACvD,IAAI,EAAE,IAAI;MACV,YAAY,kCACL,yBAAyB,GACzB,IAAI,CAAC,yBAAyB,EAAE,CACtC;MACD,MAAM,EAAE;QACJ,MAAM,EAAE,IAAI,CAAC,2BAA2B;OAC3C;KACJ,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,aAAa,CACtB,aAAa,kCAEN,IAAI,CAAC,KAAK,KACb,UAAU,EAAE,+BAA+B,KAE/C,SAAS,EACT,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CACjC,CAAC;EACN,CAAC;EAED,MAAM;IACF,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;MACvC,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACjD;IAED,MAAM,UAAU,mCACT,IAAI,CAAC,KAAK,KACb,QAAQ,EAAE,IAAI,CAAC,YAAY,GAC9B,CAAC;IAEF,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE;MACrC,UAAU,CAAC,QAAQ,mBACf,WAAW,EAAE,UAAU,IACpB,UAAU,CAAC,QAAQ,CACzB,CAAC;KACL;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;EAC5D,CAAC;EAED;;;;;;;;;KASG;EACK,aAAa,CAAC,QAAgB;IAClC,IAAI,QAAQ,KAAK,SAAS,EAAE;MACxB,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EACpD,CAAC;CACJ","sourcesContent":["import { LimeElementsAdapter } from '../adapters';\nimport JSONSchemaField from '@rjsf/core/lib/components/fields/SchemaField';\nimport React from 'react';\nimport { FieldProps } from './types';\nimport { isEmpty, capitalize } from 'lodash-es';\nimport { resetDependentFields } from './field-helpers';\nimport { FieldTemplate } from '../templates';\nimport { getHelpComponent } from '../help';\nimport { FormSchema } from '../form.types';\nimport { TimePicker } from '../widgets/time-picker';\n\n/**\n * If given a value and schema, check if the value should be translated\n * from null to undefined to avoid issues with validation\n *\n * This function needs to be used for several reasons:\n * 1. CustomEvent does not allow `detail` to equal `undefined`, but we can call onChange with `undefined` in React\n * 2. `null` is treated as a valid value in a jsonschema and with marshmallow and it has its own type (null)\n * 3. Without changing `null` to `undefined` there would be no way to remove a field from\n * from the submitted form data once it had any data. (when POSTing, undefined is not posted since its not valid json)\n * 4. The only applies to custom web components since widgets handle transforming null/'' to undefined depending on the widget\n * and its purpose.\n *\n * Example:\n * If I have an object `{ name?: string, email?: string }` that I am using a custom web component for `name`,\n * then initially, the formData will be `{}` which is fine because neither name or email are required. Then if i input a\n * value for name the formData will be `{ name: 'some_value' }` which is also fine. But then if I want to remove name\n * from the form data I would delete all the text from the name input field. Web components would emit this empty value\n * as '' or null. If the web component tries to emit `undefined`, null would be emitted instead because CustomEvent has\n * a default `detail` value of null\n *\n * @param value - the value associated with the schema\n * @param schema - the schema for the value\n * @returns whether or not null should be changed to undefined\n */\nconst shouldChangeToUndefined = (value, schema): boolean => {\n return value === null && !schema.type.includes('null');\n};\n\nconst hasCustomComponent = (schema): boolean => {\n const name = schema.lime?.component?.name;\n if (!name) {\n return false;\n }\n\n try {\n verifyCustomComponentIsDefined(name);\n } catch {\n // eslint-disable-next-line no-console\n console.warn(`Custom component ${name} not defined`);\n\n return false;\n }\n\n return true;\n};\n\nconst verifyCustomComponentIsDefined = (elementName): void => {\n const supportsCustomElements = 'customElements' in window;\n\n if (!supportsCustomElements) {\n throw new Error(\n 'Custom form elements are not supported by this browser!',\n );\n }\n\n if (!customElements.get(elementName)) {\n throw new Error(`Custom form element '${elementName}' is not defined!`);\n }\n};\n\nconst getCustomComponent = (\n schema,\n): { name: string; props: { [key: string]: any } } => {\n const name = schema.lime?.component?.name;\n const props = schema.lime?.component?.props || {};\n\n return { name: name, props: props };\n};\n\n/**\n * Create properties from the factory that is set on `limel-form`\n *\n * @param formContext - the form context\n * @param schema - the schema for the current field\n * @returns the properties created by the factory\n */\nexport function getFactoryProps(\n formContext: any,\n schema: FormSchema,\n): Record<string, any> {\n const factory: (schema: FormSchema) => Record<string, any> =\n formContext.propsFactory;\n if (typeof factory !== 'function') {\n return {};\n }\n\n const props = factory(schema);\n if (!props) {\n return {};\n }\n\n return props;\n}\n\nexport class SchemaField extends React.Component<FieldProps> {\n state = {\n modified: false,\n };\n\n constructor(props) {\n super(props);\n this.handleChange = this.handleChange.bind(this);\n this.handleCustomComponentChange =\n this.handleCustomComponentChange.bind(this);\n }\n\n private hasValue() {\n const value = this.getValue();\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value)) {\n return !!value.length;\n }\n\n if (typeof value === 'object') {\n return !isEmpty(value);\n }\n\n return true;\n }\n\n private getLabel() {\n const { schema } = this.props;\n\n return schema.title;\n }\n\n private isInvalid() {\n const { modified } = this.state;\n const { errorSchema } = this.props;\n\n return (\n (modified || this.hasValue() || !this.isRequired()) &&\n !isEmpty(errorSchema)\n );\n }\n\n private isRequired() {\n const { required, schema } = this.props;\n\n return required || schema.minItems > 0;\n }\n\n private getHelperText() {\n const { errorSchema, schema } = this.props;\n\n if (!this.isInvalid()) {\n const helperText = schema.lime?.component?.props?.helperText;\n\n return helperText || schema.description;\n }\n\n if (!isEmpty(errorSchema) && '__errors' in errorSchema) {\n return capitalize(errorSchema.__errors[0]); // eslint-disable-line no-underscore-dangle\n }\n\n return schema.description;\n }\n\n private getValue() {\n const { formData } = this.props;\n\n return formData;\n }\n\n private handleCustomComponentChange(event) {\n const { schema } = this.props;\n event.stopPropagation();\n\n let value = event.detail;\n\n if (shouldChangeToUndefined(value, schema)) {\n value = undefined;\n }\n\n this.handleChange(value);\n }\n\n private handleChange(data) {\n const { formData, schema } = this.props;\n const { rootSchema } = this.props.registry;\n\n this.setState({ modified: true });\n\n const newData = resetDependentFields(\n formData,\n data,\n schema,\n rootSchema,\n );\n\n this.props.onChange(newData);\n }\n\n private buildCustomComponentProps() {\n const {\n disabled,\n readonly,\n name,\n registry,\n schema,\n errorSchema,\n idSchema,\n } = this.props;\n const factoryProps = getFactoryProps(registry.formContext, schema);\n\n return {\n ...factoryProps,\n value: this.getValue(),\n required: this.isRequired(),\n readonly: readonly || schema.readOnly,\n disabled: disabled,\n invalid: this.isInvalid(),\n label: this.getLabel(),\n helperText: this.getHelperText(),\n formInfo: {\n schema: schema,\n rootSchema: registry.formContext.schema,\n errorSchema: errorSchema,\n rootValue: registry.formContext.rootValue,\n name: name,\n schemaPath: this.getSchemaPath(idSchema?.$id),\n },\n };\n }\n\n private renderCustomComponent(props: FieldProps) {\n const { name, props: userDefinedComponentProps } = getCustomComponent(\n props.schema,\n );\n\n verifyCustomComponentIsDefined(name);\n\n const component = React.createElement(LimeElementsAdapter, {\n name: name,\n elementProps: {\n ...userDefinedComponentProps,\n ...this.buildCustomComponentProps(),\n },\n events: {\n change: this.handleCustomComponentChange,\n },\n });\n\n return React.createElement(\n FieldTemplate,\n {\n ...this.props,\n classNames: 'form-group field field-custom',\n },\n component,\n getHelpComponent(props.schema),\n );\n }\n\n render() {\n if (hasCustomComponent(this.props.schema)) {\n return this.renderCustomComponent(this.props);\n }\n\n const fieldProps = {\n ...this.props,\n onChange: this.handleChange,\n };\n\n if (this.props.schema.format === 'time') {\n fieldProps.uiSchema = {\n 'ui:widget': TimePicker,\n ...fieldProps.uiSchema,\n };\n }\n\n return React.createElement(JSONSchemaField, fieldProps);\n }\n\n /**\n * Gets the path to the current property within the schema\n *\n * @param schemaId - the id of the schema\n * @returns an array with the schema path for the current property\n * @example\n * const schemaId = 'root_sections_0_controls_0_name';\n * const schemaPath = getSchemaPath(schemaId);\n * // ➡ ['sections', '0', 'controls', '0', 'name']\n */\n private getSchemaPath(schemaId: string): string[] {\n if (schemaId === undefined) {\n return undefined;\n }\n\n return schemaId.replace('root_', '').split('_');\n }\n}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U,EAAE,+BAA+B,KAE/C,SAAS,EACT,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,CACjC,CAAC;EACN,CAAC;EAED,MAAM;IACF,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;MACvC,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACjD;IAED,MAAM,UAAU,mCACT,IAAI,CAAC,KAAK,KACb,QAAQ,EAAE,IAAI,CAAC,YAAY,GAC9B,CAAC;IAEF,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,EAAE;MACrC,UAAU,CAAC,QAAQ,mBACf,WAAW,EAAE,UAAU,IACpB,UAAU,CAAC,QAAQ,CACzB,CAAC;KACL;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;EAC5D,CAAC;EAED;;;;;;;;;KASG;EACK,aAAa,CAAC,QAAgB;IAClC,IAAI,QAAQ,KAAK,SAAS,EAAE;MACxB,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EACpD,CAAC;CACJ","sourcesContent":["import { LimeElementsAdapter } from '../adapters';\nimport JSONSchemaField from '@rjsf/core/lib/components/fields/SchemaField';\nimport React from 'react';\nimport { FieldProps } from './types';\nimport { isEmpty, capitalize } from 'lodash-es';\nimport { resetDependentFields } from './field-helpers';\nimport { FieldTemplate } from '../templates';\nimport { getHelpComponent } from '../help';\nimport { FormSchema } from '../form.types';\nimport { TimePicker } from '../widgets/time-picker';\n\n/**\n * If given a value and schema, check if the value should be translated\n * from null to undefined to avoid issues with validation\n *\n * This function needs to be used for several reasons:\n * 1. CustomEvent does not allow `detail` to equal `undefined`, but we can call onChange with `undefined` in React\n * 2. `null` is treated as a valid value in a jsonschema and with marshmallow and it has its own type (null)\n * 3. Without changing `null` to `undefined` there would be no way to remove a field from\n * from the submitted form data once it had any data. (when POSTing, undefined is not posted since its not valid json)\n * 4. The only applies to custom web components since widgets handle transforming null/'' to undefined depending on the widget\n * and its purpose.\n *\n * Example:\n * If I have an object `{ name?: string, email?: string }` that I am using a custom web component for `name`,\n * then initially, the formData will be `{}` which is fine because neither name or email are required. Then if i input a\n * value for name the formData will be `{ name: 'some_value' }` which is also fine. But then if I want to remove name\n * from the form data I would delete all the text from the name input field. Web components would emit this empty value\n * as '' or null. If the web component tries to emit `undefined`, null would be emitted instead because CustomEvent has\n * a default `detail` value of null\n *\n * @param value - the value associated with the schema\n * @param schema - the schema for the value\n * @returns whether or not null should be changed to undefined\n */\nconst shouldChangeToUndefined = (value, schema): boolean => {\n return value === null && !schema.type.includes('null');\n};\n\nconst hasCustomComponent = (schema): boolean => {\n const name = schema.lime?.component?.name;\n if (!name) {\n return false;\n }\n\n try {\n verifyCustomComponentIsDefined(name);\n } catch {\n // eslint-disable-next-line no-console\n console.warn(`Custom component ${name} not defined`);\n\n return false;\n }\n\n return true;\n};\n\nconst verifyCustomComponentIsDefined = (elementName): void => {\n const supportsCustomElements = 'customElements' in window;\n\n if (!supportsCustomElements) {\n throw new Error(\n 'Custom form elements are not supported by this browser!',\n );\n }\n\n if (!customElements.get(elementName)) {\n throw new Error(`Custom form element '${elementName}' is not defined!`);\n }\n};\n\nconst getCustomComponent = (\n schema,\n): { name: string; props: { [key: string]: any } } => {\n const name = schema.lime?.component?.name;\n const props = schema.lime?.component?.props || {};\n\n return { name: name, props: props };\n};\n\n/**\n * Create properties from the factory that is set on `limel-form`\n *\n * @param formContext - the form context\n * @param schema - the schema for the current field\n * @returns the properties created by the factory\n */\nexport function getFactoryProps(\n formContext: any,\n schema: FormSchema,\n): Record<string, any> {\n const factory: (schema: FormSchema) => Record<string, any> =\n formContext.propsFactory;\n if (typeof factory !== 'function') {\n return {};\n }\n\n const props = factory(schema);\n if (!props) {\n return {};\n }\n\n return props;\n}\n\nexport class SchemaField extends React.Component<FieldProps> {\n state = {\n modified: false,\n };\n\n constructor(props) {\n super(props);\n this.handleChange = this.handleChange.bind(this);\n this.handleCustomComponentChange =\n this.handleCustomComponentChange.bind(this);\n }\n\n private hasValue() {\n const value = this.getValue();\n if (!value) {\n return false;\n }\n\n if (Array.isArray(value)) {\n return !!value.length;\n }\n\n if (value instanceof Date) {\n return true;\n }\n\n if (typeof value === 'object') {\n return !isEmpty(value);\n }\n\n return true;\n }\n\n private getLabel() {\n const { schema } = this.props;\n\n return schema.title;\n }\n\n private isInvalid() {\n const { modified } = this.state;\n const { errorSchema } = this.props;\n\n return (\n (modified || this.hasValue() || !this.isRequired()) &&\n !isEmpty(errorSchema)\n );\n }\n\n private isRequired() {\n const { required, schema } = this.props;\n\n return required || schema.minItems > 0;\n }\n\n private getHelperText() {\n const { errorSchema, schema } = this.props;\n\n if (!this.isInvalid()) {\n const helperText = schema.lime?.component?.props?.helperText;\n\n return helperText || schema.description;\n }\n\n if (!isEmpty(errorSchema) && '__errors' in errorSchema) {\n return capitalize(errorSchema.__errors[0]); // eslint-disable-line no-underscore-dangle\n }\n\n return schema.description;\n }\n\n private getValue() {\n const { formData } = this.props;\n\n return formData;\n }\n\n private handleCustomComponentChange(event) {\n const { schema } = this.props;\n event.stopPropagation();\n\n let value = event.detail;\n\n if (shouldChangeToUndefined(value, schema)) {\n value = undefined;\n }\n\n this.handleChange(value);\n }\n\n private handleChange(data) {\n const { formData, schema } = this.props;\n const { rootSchema } = this.props.registry;\n\n this.setState({ modified: true });\n\n const newData = resetDependentFields(\n formData,\n data,\n schema,\n rootSchema,\n );\n\n this.props.onChange(newData);\n }\n\n private buildCustomComponentProps() {\n const {\n disabled,\n readonly,\n name,\n registry,\n schema,\n errorSchema,\n idSchema,\n } = this.props;\n const factoryProps = getFactoryProps(registry.formContext, schema);\n\n return {\n ...factoryProps,\n value: this.getValue(),\n required: this.isRequired(),\n readonly: readonly || schema.readOnly,\n disabled: disabled,\n invalid: this.isInvalid(),\n label: this.getLabel(),\n helperText: this.getHelperText(),\n formInfo: {\n schema: schema,\n rootSchema: registry.formContext.schema,\n errorSchema: errorSchema,\n rootValue: registry.formContext.rootValue,\n name: name,\n schemaPath: this.getSchemaPath(idSchema?.$id),\n },\n };\n }\n\n private renderCustomComponent(props: FieldProps) {\n const { name, props: userDefinedComponentProps } = getCustomComponent(\n props.schema,\n );\n\n verifyCustomComponentIsDefined(name);\n\n const component = React.createElement(LimeElementsAdapter, {\n name: name,\n elementProps: {\n ...userDefinedComponentProps,\n ...this.buildCustomComponentProps(),\n },\n events: {\n change: this.handleCustomComponentChange,\n },\n });\n\n return React.createElement(\n FieldTemplate,\n {\n ...this.props,\n classNames: 'form-group field field-custom',\n },\n component,\n getHelpComponent(props.schema),\n );\n }\n\n render() {\n if (hasCustomComponent(this.props.schema)) {\n return this.renderCustomComponent(this.props);\n }\n\n const fieldProps = {\n ...this.props,\n onChange: this.handleChange,\n };\n\n if (this.props.schema.format === 'time') {\n fieldProps.uiSchema = {\n 'ui:widget': TimePicker,\n ...fieldProps.uiSchema,\n };\n }\n\n return React.createElement(JSONSchemaField, fieldProps);\n }\n\n /**\n * Gets the path to the current property within the schema\n *\n * @param schemaId - the id of the schema\n * @returns an array with the schema path for the current property\n * @example\n * const schemaId = 'root_sections_0_controls_0_name';\n * const schemaPath = getSchemaPath(schemaId);\n * // ➡ ['sections', '0', 'controls', '0', 'name']\n */\n private getSchemaPath(schemaId: string): string[] {\n if (schemaId === undefined) {\n return undefined;\n }\n\n return schemaId.replace('root_', '').split('_');\n }\n}\n"]}
@@ -24344,6 +24344,9 @@ class LimeElementsWidgetAdapter extends react.Component {
24344
24344
  if (Array.isArray(value)) {
24345
24345
  return !!value.length;
24346
24346
  }
24347
+ if (value instanceof Date) {
24348
+ return true;
24349
+ }
24347
24350
  if (typeof value === 'object') {
24348
24351
  return !!Object.entries(value).length;
24349
24352
  }
@@ -29049,6 +29052,9 @@ class SchemaField extends react.Component {
29049
29052
  if (Array.isArray(value)) {
29050
29053
  return !!value.length;
29051
29054
  }
29055
+ if (value instanceof Date) {
29056
+ return true;
29057
+ }
29052
29058
  if (typeof value === 'object') {
29053
29059
  return !isEmpty$1(value);
29054
29060
  }