@limetech/lime-elements 38.29.3 → 38.30.0

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 (38) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/index.cjs.js.map +1 -1
  3. package/dist/cjs/limel-form.cjs.entry.js +60 -27
  4. package/dist/cjs/limel-form.cjs.entry.js.map +1 -1
  5. package/dist/cjs/limel-table.cjs.entry.js +14 -6
  6. package/dist/cjs/limel-table.cjs.entry.js.map +1 -1
  7. package/dist/collection/components/form/form.js +1 -0
  8. package/dist/collection/components/form/form.js.map +1 -1
  9. package/dist/collection/components/form/form.types.js.map +1 -1
  10. package/dist/collection/components/form/templates/array-field-collapsible-item.js +11 -9
  11. package/dist/collection/components/form/templates/array-field-collapsible-item.js.map +1 -1
  12. package/dist/collection/components/form/templates/array-field-simple-item.js +36 -18
  13. package/dist/collection/components/form/templates/array-field-simple-item.js.map +1 -1
  14. package/dist/collection/components/form/templates/array-field.js +13 -0
  15. package/dist/collection/components/form/templates/array-field.js.map +1 -1
  16. package/dist/collection/components/table/table.js +15 -7
  17. package/dist/collection/components/table/table.js.map +1 -1
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/limel-form.entry.js +60 -27
  20. package/dist/esm/limel-form.entry.js.map +1 -1
  21. package/dist/esm/limel-table.entry.js +14 -6
  22. package/dist/esm/limel-table.entry.js.map +1 -1
  23. package/dist/lime-elements/index.esm.js.map +1 -1
  24. package/dist/lime-elements/lime-elements.esm.js +1 -1
  25. package/dist/lime-elements/{p-d24988e7.entry.js → p-beee38bc.entry.js} +5 -5
  26. package/dist/lime-elements/p-beee38bc.entry.js.map +1 -0
  27. package/dist/lime-elements/{p-c3394c18.entry.js → p-d1aa44e1.entry.js} +2 -2
  28. package/dist/lime-elements/p-d1aa44e1.entry.js.map +1 -0
  29. package/dist/types/components/form/form.d.ts +1 -0
  30. package/dist/types/components/form/form.types.d.ts +8 -0
  31. package/dist/types/components/form/templates/array-field-collapsible-item.d.ts +9 -1
  32. package/dist/types/components/form/templates/array-field-simple-item.d.ts +9 -5
  33. package/dist/types/components/form/templates/array-field.d.ts +1 -0
  34. package/dist/types/components/table/table.d.ts +3 -1
  35. package/dist/types/components.d.ts +6 -2
  36. package/package.json +1 -1
  37. package/dist/lime-elements/p-c3394c18.entry.js.map +0 -1
  38. package/dist/lime-elements/p-d24988e7.entry.js.map +0 -1
@@ -23,6 +23,7 @@ import { mapValues } from 'lodash-es';
23
23
  * @exampleComponent limel-example-form-span-fields
24
24
  * @exampleComponent limel-example-custom-error-message
25
25
  * @exampleComponent limel-example-server-errors
26
+ * @exampleComponent limel-example-form-array-item-controls
26
27
  * @exampleComponent limel-example-form-with-help
27
28
  * @exampleComponent limel-example-form-row-layout
28
29
  */
@@ -1 +1 @@
1
- {"version":3,"file":"form.js","sourceRoot":"","sources":["../../../src/components/form/form.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,CAAC,EACD,IAAI,EACJ,KAAK,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAQ,MAAM,kBAAkB,CAAC;AACpD,OAAO,cAA4B,MAAM,YAAY,CAAC;AACtD,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAO9D,OAAO,EACH,kBAAkB,EAClB,aAAa,EACb,mBAAmB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D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AAE;MACjC,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,KAAe,EAAE,EAAE;QAC1D,OAAO,gBAAgB,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,CAAC;MACxD,CAAC,CAAC,CAAC;MAEH,uCACO,aAAa,KAChB,OAAO,EAAE,gBAAgB,CAAC,OAAO,IACnC;IACN,CAAC,CAAC,CAAC;EACX,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n h,\n Prop,\n Watch,\n} from '@stencil/core';\nimport React from 'react';\nimport { createRoot, Root } from 'react-dom/client';\nimport JSONSchemaForm, { AjvError } from '@rjsf/core';\nimport retargetEvents from 'react-shadow-dom-retarget-events';\nimport {\n FormError,\n FormSchema,\n ValidationError,\n ValidationStatus,\n} from './form.types';\nimport {\n ArrayFieldTemplate,\n FieldTemplate,\n ObjectFieldTemplate,\n} from './templates';\nimport { SchemaField as CustomSchemaField } from './fields/schema-field';\nimport { ArrayField as CustomArrayField } from './fields/array-field';\nimport { ObjectField as CustomObjectField } from './fields/object-field';\nimport { widgets } from './widgets';\nimport { createRandomString } from '../../util/random-string';\nimport Ajv, { RequiredParams } from 'ajv';\nimport { isInteger } from './validators';\nimport { mapValues } from 'lodash-es';\n\n/**\n * @exampleComponent limel-example-form\n * @exampleComponent limel-example-nested-form\n * @exampleComponent limel-example-list-form\n * @exampleComponent limel-example-dynamic-form\n * @exampleComponent limel-example-custom-component-form\n * @exampleComponent limel-example-props-factory-form\n * @exampleComponent limel-example-form-layout\n * @exampleComponent limel-example-form-span-fields\n * @exampleComponent limel-example-custom-error-message\n * @exampleComponent limel-example-server-errors\n * @exampleComponent limel-example-form-with-help\n * @exampleComponent limel-example-form-row-layout\n */\n@Component({\n tag: 'limel-form',\n shadow: true,\n styleUrl: 'form.scss',\n})\nexport class Form {\n /**\n * The schema used to render the form\n */\n @Prop()\n public schema: FormSchema = {};\n\n /**\n * Value of the form\n */\n @Prop()\n public value: object;\n\n /**\n * Set to `true` to disable the whole form.\n */\n @Prop()\n public disabled = false;\n\n /**\n * Factory for creating properties for custom form components\n *\n * When using custom components in the form some properties might have to be\n * set dynamically. If this factory is set, it will be called with the\n * current schema for the field for each custom component in the form. The\n * factory must return an object where each key is the name of the property\n * that should be set, along with its value.\n */\n @Prop()\n public propsFactory?: (schema: FormSchema) => Record<string, any>;\n\n /**\n * Custom function to customize the default error messages\n */\n @Prop()\n public transformErrors?: (errors: FormError[]) => FormError[];\n\n /**\n * Extra errors to display in the form. Typical use case is asynchronous\n * errors generated server side.\n */\n @Prop()\n public errors: ValidationError;\n\n /**\n * Emitted when a change is made within the form\n */\n @Event()\n public change: EventEmitter<object>;\n\n /**\n * Emitted when the validity of the form changes, or when\n * a change is made to an invalid form\n */\n @Event()\n public validate: EventEmitter<ValidationStatus>;\n\n @Element()\n private host: HTMLLimelFormElement;\n\n private isValid = true;\n private modifiedSchema: FormSchema;\n private validator: Ajv.ValidateFunction;\n private root: Root;\n\n public constructor() {\n this.handleChange = this.handleChange.bind(this);\n this.getCustomErrorMessages = this.getCustomErrorMessages.bind(this);\n }\n\n public connectedCallback() {\n this.initialize();\n }\n\n public componentWillLoad() {\n this.setSchemaId();\n this.createValidator();\n }\n\n public componentDidLoad() {\n this.initialize();\n }\n\n private initialize() {\n if (!this.host.shadowRoot.querySelector('.root')) {\n return;\n }\n\n this.reactRender();\n retargetEvents(this.host.shadowRoot);\n this.validateForm(this.value);\n }\n\n public componentDidUpdate() {\n this.reactRender();\n this.validateForm(this.value);\n }\n\n public disconnectedCallback() {\n if (this.root) {\n this.root.unmount();\n this.root = undefined;\n }\n }\n\n public render() {\n return <div class=\"root\" />;\n }\n\n private reactRender() {\n if (!this.root) {\n const rootElement = this.host.shadowRoot.querySelector('.root');\n this.root = createRoot(rootElement);\n }\n\n this.root.render(\n React.createElement(\n JSONSchemaForm,\n {\n schema: this.modifiedSchema,\n formData: this.value,\n onChange: this.handleChange,\n widgets: widgets,\n liveValidate: true,\n showErrorList: false,\n extraErrors: this.getExtraErrors(this.errors),\n FieldTemplate: FieldTemplate,\n ArrayFieldTemplate: ArrayFieldTemplate as any,\n ObjectFieldTemplate: ObjectFieldTemplate,\n disabled: this.disabled,\n transformErrors: this.getCustomErrorMessages,\n formContext: {\n schema: this.modifiedSchema,\n rootValue: this.value,\n propsFactory: this.propsFactory,\n },\n fields: {\n SchemaField: CustomSchemaField as any,\n ArrayField: CustomArrayField as any,\n ObjectField: CustomObjectField as any,\n },\n },\n []\n )\n );\n }\n\n private handleChange(event: any) {\n this.change.emit(event.formData);\n }\n\n private validateForm(value: object) {\n const isValid = this.validator(value) === true;\n const errors: FormError[] = this.getValidationErrors();\n const status: ValidationStatus = {\n valid: isValid,\n errors: errors,\n };\n\n if (this.isValid !== status.valid || !status.valid) {\n this.validate.emit(status);\n }\n\n this.isValid = status.valid;\n }\n\n @Watch('schema')\n public setSchema() {\n this.setSchemaId();\n this.createValidator();\n }\n\n private setSchemaId() {\n // Due to a bug in react-jsonschema-form, validation will stop working if the schema is updated.\n // A workaround at the moment is to always give it a unique ID\n // https://github.com/rjsf-team/react-jsonschema-form/issues/1563\n const id = `${this.schema.$id}-${createRandomString()}`;\n this.modifiedSchema = {\n ...this.schema,\n id: id,\n $id: id,\n };\n }\n\n private createValidator() {\n const validator = new Ajv({\n unknownFormats: 'ignore',\n allErrors: true,\n multipleOfPrecision: 2,\n }).addFormat('integer', isInteger);\n this.validator = validator.compile(this.schema);\n }\n\n private getValidationErrors(): FormError[] {\n const errors = this.validator.errors || [];\n\n return errors.map((error: Ajv.ErrorObject): FormError => {\n let property = error.dataPath;\n if (error.keyword === 'required') {\n property = (error.params as RequiredParams).missingProperty;\n }\n\n return {\n name: error.keyword,\n property: property,\n message: error.message,\n schemaPath: error.schemaPath,\n };\n });\n }\n\n private getExtraErrors(errors: ValidationError): ExtraError | undefined {\n if (!errors) {\n return;\n }\n\n return mapValues(errors, (error) => {\n if (Array.isArray(error)) {\n return { __errors: error };\n }\n\n return this.getExtraErrors(error);\n });\n }\n\n private getCustomErrorMessages(originalErrors: AjvError[]): AjvError[] {\n if (!this.transformErrors) {\n return originalErrors;\n }\n\n const errors: FormError[] = originalErrors.map((error: AjvError) => {\n return {\n name: error.name,\n params: error.params,\n property: error.property,\n message: error.message,\n // For some reason 'schemaPath' is missing from the AjvError type definition:\n // https://github.com/rjsf-team/react-jsonschema-form/issues/2140\n\n schemaPath: error['schemaPath'],\n };\n });\n\n // Use `.call({}, …)` here to bind `this` to an empty object to prevent\n // the consumer submitted `transformErrors` from getting access to our\n // component's internals. /Ads\n return this.transformErrors\n .call({}, errors)\n .map((transformedError: FormError) => {\n const originalError = originalErrors.find((error: AjvError) => {\n return transformedError.property === error.property;\n });\n\n return {\n ...originalError,\n message: transformedError.message,\n };\n });\n }\n}\n\ninterface ExtraError {\n [key: string]:\n | ExtraError\n | {\n __errors: string[];\n };\n}\n"]}
1
+ {"version":3,"file":"form.js","sourceRoot":"","sources":["../../../src/components/form/form.tsx"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,CAAC,EACD,IAAI,EACJ,KAAK,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAQ,MAAM,kBAAkB,CAAC;AACpD,OAAO,cAA4B,MAAM,YAAY,CAAC;AACtD,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAO9D,OAAO,EACH,kBAAkB,EAClB,aAAa,EACb,mBAAmB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,uB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QAC7E,iEAAiE;QAEjE,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC;OAClC,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,uEAAuE;IACvE,sEAAsE;IACtE,8BAA8B;IAC9B,OAAO,IAAI,CAAC,eAAe;OACtB,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC;OAChB,GAAG,CAAC,CAAC,gBAA2B,EAAE,EAAE;MACjC,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,KAAe,EAAE,EAAE;QAC1D,OAAO,gBAAgB,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,CAAC;MACxD,CAAC,CAAC,CAAC;MAEH,uCACO,aAAa,KAChB,OAAO,EAAE,gBAAgB,CAAC,OAAO,IACnC;IACN,CAAC,CAAC,CAAC;EACX,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import {\n Component,\n Element,\n Event,\n EventEmitter,\n h,\n Prop,\n Watch,\n} from '@stencil/core';\nimport React from 'react';\nimport { createRoot, Root } from 'react-dom/client';\nimport JSONSchemaForm, { AjvError } from '@rjsf/core';\nimport retargetEvents from 'react-shadow-dom-retarget-events';\nimport {\n FormError,\n FormSchema,\n ValidationError,\n ValidationStatus,\n} from './form.types';\nimport {\n ArrayFieldTemplate,\n FieldTemplate,\n ObjectFieldTemplate,\n} from './templates';\nimport { SchemaField as CustomSchemaField } from './fields/schema-field';\nimport { ArrayField as CustomArrayField } from './fields/array-field';\nimport { ObjectField as CustomObjectField } from './fields/object-field';\nimport { widgets } from './widgets';\nimport { createRandomString } from '../../util/random-string';\nimport Ajv, { RequiredParams } from 'ajv';\nimport { isInteger } from './validators';\nimport { mapValues } from 'lodash-es';\n\n/**\n * @exampleComponent limel-example-form\n * @exampleComponent limel-example-nested-form\n * @exampleComponent limel-example-list-form\n * @exampleComponent limel-example-dynamic-form\n * @exampleComponent limel-example-custom-component-form\n * @exampleComponent limel-example-props-factory-form\n * @exampleComponent limel-example-form-layout\n * @exampleComponent limel-example-form-span-fields\n * @exampleComponent limel-example-custom-error-message\n * @exampleComponent limel-example-server-errors\n * @exampleComponent limel-example-form-array-item-controls\n * @exampleComponent limel-example-form-with-help\n * @exampleComponent limel-example-form-row-layout\n */\n@Component({\n tag: 'limel-form',\n shadow: true,\n styleUrl: 'form.scss',\n})\nexport class Form {\n /**\n * The schema used to render the form\n */\n @Prop()\n public schema: FormSchema = {};\n\n /**\n * Value of the form\n */\n @Prop()\n public value: object;\n\n /**\n * Set to `true` to disable the whole form.\n */\n @Prop()\n public disabled = false;\n\n /**\n * Factory for creating properties for custom form components\n *\n * When using custom components in the form some properties might have to be\n * set dynamically. If this factory is set, it will be called with the\n * current schema for the field for each custom component in the form. The\n * factory must return an object where each key is the name of the property\n * that should be set, along with its value.\n */\n @Prop()\n public propsFactory?: (schema: FormSchema) => Record<string, any>;\n\n /**\n * Custom function to customize the default error messages\n */\n @Prop()\n public transformErrors?: (errors: FormError[]) => FormError[];\n\n /**\n * Extra errors to display in the form. Typical use case is asynchronous\n * errors generated server side.\n */\n @Prop()\n public errors: ValidationError;\n\n /**\n * Emitted when a change is made within the form\n */\n @Event()\n public change: EventEmitter<object>;\n\n /**\n * Emitted when the validity of the form changes, or when\n * a change is made to an invalid form\n */\n @Event()\n public validate: EventEmitter<ValidationStatus>;\n\n @Element()\n private host: HTMLLimelFormElement;\n\n private isValid = true;\n private modifiedSchema: FormSchema;\n private validator: Ajv.ValidateFunction;\n private root: Root;\n\n public constructor() {\n this.handleChange = this.handleChange.bind(this);\n this.getCustomErrorMessages = this.getCustomErrorMessages.bind(this);\n }\n\n public connectedCallback() {\n this.initialize();\n }\n\n public componentWillLoad() {\n this.setSchemaId();\n this.createValidator();\n }\n\n public componentDidLoad() {\n this.initialize();\n }\n\n private initialize() {\n if (!this.host.shadowRoot.querySelector('.root')) {\n return;\n }\n\n this.reactRender();\n retargetEvents(this.host.shadowRoot);\n this.validateForm(this.value);\n }\n\n public componentDidUpdate() {\n this.reactRender();\n this.validateForm(this.value);\n }\n\n public disconnectedCallback() {\n if (this.root) {\n this.root.unmount();\n this.root = undefined;\n }\n }\n\n public render() {\n return <div class=\"root\" />;\n }\n\n private reactRender() {\n if (!this.root) {\n const rootElement = this.host.shadowRoot.querySelector('.root');\n this.root = createRoot(rootElement);\n }\n\n this.root.render(\n React.createElement(\n JSONSchemaForm,\n {\n schema: this.modifiedSchema,\n formData: this.value,\n onChange: this.handleChange,\n widgets: widgets,\n liveValidate: true,\n showErrorList: false,\n extraErrors: this.getExtraErrors(this.errors),\n FieldTemplate: FieldTemplate,\n ArrayFieldTemplate: ArrayFieldTemplate as any,\n ObjectFieldTemplate: ObjectFieldTemplate,\n disabled: this.disabled,\n transformErrors: this.getCustomErrorMessages,\n formContext: {\n schema: this.modifiedSchema,\n rootValue: this.value,\n propsFactory: this.propsFactory,\n },\n fields: {\n SchemaField: CustomSchemaField as any,\n ArrayField: CustomArrayField as any,\n ObjectField: CustomObjectField as any,\n },\n },\n []\n )\n );\n }\n\n private handleChange(event: any) {\n this.change.emit(event.formData);\n }\n\n private validateForm(value: object) {\n const isValid = this.validator(value) === true;\n const errors: FormError[] = this.getValidationErrors();\n const status: ValidationStatus = {\n valid: isValid,\n errors: errors,\n };\n\n if (this.isValid !== status.valid || !status.valid) {\n this.validate.emit(status);\n }\n\n this.isValid = status.valid;\n }\n\n @Watch('schema')\n public setSchema() {\n this.setSchemaId();\n this.createValidator();\n }\n\n private setSchemaId() {\n // Due to a bug in react-jsonschema-form, validation will stop working if the schema is updated.\n // A workaround at the moment is to always give it a unique ID\n // https://github.com/rjsf-team/react-jsonschema-form/issues/1563\n const id = `${this.schema.$id}-${createRandomString()}`;\n this.modifiedSchema = {\n ...this.schema,\n id: id,\n $id: id,\n };\n }\n\n private createValidator() {\n const validator = new Ajv({\n unknownFormats: 'ignore',\n allErrors: true,\n multipleOfPrecision: 2,\n }).addFormat('integer', isInteger);\n this.validator = validator.compile(this.schema);\n }\n\n private getValidationErrors(): FormError[] {\n const errors = this.validator.errors || [];\n\n return errors.map((error: Ajv.ErrorObject): FormError => {\n let property = error.dataPath;\n if (error.keyword === 'required') {\n property = (error.params as RequiredParams).missingProperty;\n }\n\n return {\n name: error.keyword,\n property: property,\n message: error.message,\n schemaPath: error.schemaPath,\n };\n });\n }\n\n private getExtraErrors(errors: ValidationError): ExtraError | undefined {\n if (!errors) {\n return;\n }\n\n return mapValues(errors, (error) => {\n if (Array.isArray(error)) {\n return { __errors: error };\n }\n\n return this.getExtraErrors(error);\n });\n }\n\n private getCustomErrorMessages(originalErrors: AjvError[]): AjvError[] {\n if (!this.transformErrors) {\n return originalErrors;\n }\n\n const errors: FormError[] = originalErrors.map((error: AjvError) => {\n return {\n name: error.name,\n params: error.params,\n property: error.property,\n message: error.message,\n // For some reason 'schemaPath' is missing from the AjvError type definition:\n // https://github.com/rjsf-team/react-jsonschema-form/issues/2140\n\n schemaPath: error['schemaPath'],\n };\n });\n\n // Use `.call({}, …)` here to bind `this` to an empty object to prevent\n // the consumer submitted `transformErrors` from getting access to our\n // component's internals. /Ads\n return this.transformErrors\n .call({}, errors)\n .map((transformedError: FormError) => {\n const originalError = originalErrors.find((error: AjvError) => {\n return transformedError.property === error.property;\n });\n\n return {\n ...originalError,\n message: transformedError.message,\n };\n });\n }\n}\n\ninterface ExtraError {\n [key: string]:\n | ExtraError\n | {\n __errors: string[];\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"form.types.js","sourceRoot":"","sources":["../../../src/components/form/form.types.ts"],"names":[],"mappings":"AA6SA;;;GAGG;AACH,MAAM,CAAN,IAAY,cAmBX;AAnBD,WAAY,cAAc;EACtB;;KAEG;EACH,qCAAmB,CAAA;EAEnB;;KAEG;EACH,+BAAa,CAAA;EAEb;;;;;;KAMG;EACH,6BAAW,CAAA;AACf,CAAC,EAnBW,cAAc,KAAd,cAAc,QAmBzB","sourcesContent":["import { JSONSchema7 } from 'json-schema';\nimport { Help } from '../help/help.types';\nimport { EventEmitter } from '@stencil/core';\n\n/**\n * EventEmitter from `@stencil/core`.\n *\n * @public\n */\nexport { EventEmitter } from '@stencil/core';\n\ndeclare module 'json-schema' {\n interface JSONSchema7 {\n /**\n * Unique identifier for the schema\n * @internal\n */\n id?: string;\n\n /**\n * Lime elements specific options that can be specified in a schema\n */\n lime?: Omit<LimeSchemaOptions, 'layout'> & {\n layout?: Partial<LimeLayoutOptions>;\n };\n }\n}\n\n/**\n * @public\n */\nexport interface ValidationStatus {\n /**\n * True if the form is valid, false otherwise\n *\n * If the form is invalid, any errors can be found on the `errors` property\n */\n valid: boolean;\n\n /**\n * List of validation errors\n */\n errors?: FormError[];\n}\n\n/**\n * @public\n */\nexport interface FormError {\n /**\n * Name of the error\n */\n name: string;\n\n /**\n * Params of the error\n */\n params?: unknown;\n\n /**\n * Name of the invalid property\n */\n property: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath: string;\n\n /**\n * String describing the error\n */\n message: string;\n}\n\n/**\n * @public\n */\nexport type ValidationError = {\n /**\n * Name of the field the error belongs to\n */\n [key: string]: string[] | ValidationError;\n};\n\n/**\n * @public\n */\nexport interface FormComponent<T = any> {\n /**\n * The value of the current property\n */\n value: T;\n\n /**\n * Whether or not the current property is required\n */\n required?: boolean;\n\n /**\n * Whether or not the current property is readonly\n */\n readonly?: boolean;\n\n /**\n * Whether or not the current property is disabled\n */\n disabled?: boolean;\n\n /**\n * The label of the current property\n */\n label?: string;\n\n /**\n * The helper text for the current property\n */\n helperText?: string;\n\n /**\n * Additional contextual information about the form\n */\n formInfo?: FormInfo;\n\n /**\n * The event to emit when the value of the current property has changed\n */\n change: EventEmitter<T>;\n}\n\n/**\n * @public\n */\nexport interface FormInfo {\n /**\n * The schema of the current property\n */\n schema?: FormSchema;\n\n /**\n * The schema of the whole form\n */\n rootSchema?: FormSchema;\n\n /**\n * A tree of errors for this property and its children\n */\n errorSchema?: object;\n\n /**\n * The value of the whole form\n */\n rootValue?: any;\n\n /**\n * The name of the current property\n */\n name?: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath?: string[];\n}\n\n/**\n * Lime elements specific options that can be specified under the `lime` key in\n * a schema, e.g.\n *\n * ```ts\n * const schema = {\n * type: 'object',\n * lime: {\n * collapsible: true,\n * },\n * };\n * ```\n *\n * @public\n */\nexport interface LimeSchemaOptions {\n /**\n * When specified on an object it will render all sub components inside a\n * collapsible section\n */\n collapsible?: boolean;\n\n /**\n * When `collapsible` is `true`, set this to `false` to make the\n * collapsible section load in the open state.\n * Defaults to `true`.\n */\n collapsed?: boolean;\n\n /**\n * Will render the field using the specified component. The component\n * should implement the `FormComponent` interface\n */\n component?: FormComponentOptions;\n\n /**\n * When specified on an object it will render the sub components with the\n * specified layout\n */\n layout?: LimeLayoutOptions;\n\n /**\n * Mark the field as disabled\n */\n disabled?: boolean;\n\n /**\n * Hide the field from the UI while preserving its value in the form data.\n */\n hidden?: boolean;\n\n help?: string | Partial<Help>;\n}\n\n/**\n * Options for a layout to be used in a form\n * @public\n */\nexport type LimeLayoutOptions = GridLayoutOptions & RowLayoutOptions;\n\n/**\n * Options for a component to be rendered inside a form\n *\n * @public\n */\nexport interface FormComponentOptions {\n /**\n * Name of the component\n */\n name?: string;\n\n /**\n * Extra properties to give the component in addition to the properties\n * specified on the `FormComponent` interface\n */\n props?: Record<string, any>;\n}\n\n/**\n * @public\n */\nexport interface FormLayoutOptions<\n T extends FormLayoutType | `${FormLayoutType}` = FormLayoutType.Default,\n> {\n /**\n * The type of layout to use\n */\n type: T;\n}\n\n/**\n * Layout options for a grid layout\n * @public\n */\nexport interface GridLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of columns in the form\n */\n\n colSpan?: 1 | 2 | 3 | 4 | 5 | 'all';\n\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of rows in the form\n */\n rowSpan?: number;\n\n /**\n * Number of columns to use in the layout\n */\n\n columns?: 1 | 2 | 3 | 4 | 5;\n\n /**\n * Attempts to fill in holes earlier in the grid, if smaller items come up\n * later. This may cause items to appear out-of-order, when doing so would\n * fill holes left by larger items. Defaults to `true`.\n */\n dense?: boolean;\n}\n\n/**\n * Layout options for a row layout\n * @public\n */\nexport interface RowLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a field, the chosen icon will be displayed\n * on the left side of the row, beside the title.\n */\n icon?: string;\n}\n\n/**\n * Represents the layout types for a form.\n * @public\n */\nexport enum FormLayoutType {\n /**\n * The default layout\n */\n Default = 'default',\n\n /**\n * Render the form fields using a responsive grid layout\n */\n Grid = 'grid',\n\n /**\n * Render the form fields in full-width rows.\n * Each row can have a leading `icon`, and a field.\n * `title` and `description` provided by the schema will be placed\n * on the row itself, and not on the field.\n * This layout is good for creating UIs for user settings pages.\n */\n Row = 'row',\n}\n\n/**\n * Represents the JSON schema with Lime specific options\n * @public\n */\nexport interface FormSchema<T extends Record<string, any> = any>\n extends JSONSchema7 {\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.1\n */\n items?: FormSchemaArrayItem<T> | Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.2\n */\n additionalItems?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be a valid JSON Schema.\n *\n * An array instance is valid against \"contains\" if at least one of its\n * elements is valid against the given schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.6\n */\n contains?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be an array. Elements of this array,\n * if any, MUST be strings, and MUST be unique.\n *\n * An object instance is valid against this keyword if every item in the\n * array is the name of a property in the instance.\n *\n * Omitting this keyword has the same behavior as an empty array.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.3\n */\n required?: Array<ReplaceObjectType<T, Extract<keyof T, string>, string>>;\n\n /**\n * The value of \"properties\" MUST be an object. Each value of this\n * object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation succeeds if, for each name that appears in both the\n * instance and as a name within this keyword's value, the child\n * instance for that name successfully validates against the\n * corresponding schema.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.4\n */\n properties?: ReplaceObjectType<\n T,\n FormSubKeySchema<T>,\n Record<string, FormSchema>\n >;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against all schemas defined by this keyword's\n * value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.1\n */\n allOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against at least one schema defined by this\n * keyword's value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.2\n */\n anyOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against exactly one schema defined by this\n * keyword's value.\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.3\n */\n oneOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"patternProperties\" MUST be an object. Each property\n * name of this object SHOULD be a valid regular expression, according\n * to the ECMA 262 regular expression dialect. Each property value of\n * this object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself. Validation\n * of the primitive instance type against this keyword always succeeds.\n *\n * Validation succeeds if, for each instance name that matches any\n * regular expressions that appear as a property name in this keyword's\n * value, the child instance for that name successfully validates\n * against each schema that corresponds to a matching regular\n * expression.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.5\n */\n patternProperties?: Record<string, FormSchema>;\n\n /**\n * The value of \"additionalProperties\" MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation with \"additionalProperties\" applies only to the child\n * values of instance names that do not match any names in \"properties\",\n * and do not match any regular expression in \"patternProperties\".\n *\n * For all such properties, validation succeeds if the child instance\n * validates against the \"additionalProperties\" schema.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.6\n */\n additionalProperties?: FormSchema | boolean;\n\n /**\n * This keyword specifies rules that are evaluated if the instance is an\n * object and contains a certain property.\n *\n * This keyword's value MUST be an object. Each property specifies a\n * dependency. Each dependency value MUST be an array or a valid JSON\n * Schema.\n *\n * If the dependency value is a subschema, and the dependency key is a\n * property in the instance, the entire instance must validate against\n * the dependency value.\n *\n * If the dependency value is an array, each element in the array, if\n * any, MUST be a string, and MUST be unique. If the dependency key is\n * a property in the instance, each of the items in the dependency value\n * must be a property that exists in the instance.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.7\n */\n dependencies?: Record<string, FormSchema | string[]>;\n\n /**\n * The value of \"propertyNames\" MUST be a valid JSON Schema.\n *\n * If the instance is an object, this keyword validates if every\n * property name in the instance validates against the provided schema.\n * Note the property name that the schema is testing will always be a\n * string.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.8\n */\n propertyNames?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.1\n */\n if?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.2\n */\n then?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * When \"if\" is present, and the instance fails to validate against its\n * subschema, then valiation succeeds against this keyword if the\n * instance successfully validates against this keyword's subschema.\n *\n * This keyword has no effect when \"if\" is absent, or when the instance\n * successfully validates against its subschema. Implementations MUST\n * NOT evaluate the instance against this keyword, for either validation\n * or annotation collection purposes, in such cases.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.3\n */\n else?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * An instance is valid against this keyword if it fails to validate\n * successfully against the schema defined by this keyword.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.4\n */\n not?: FormSchema;\n\n /**\n * The \"$defs\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n $defs?: Record<string, FormSchema>;\n\n /**\n * The \"definitions\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n definitions?: Record<string, FormSchema>;\n}\n\n/**\n * Utility type for replacing object types with a specified type\n * @public\n */\nexport type ReplaceObjectType<T, AllowedType, ElseType> = T extends any[]\n ? ElseType\n : T extends Record<string, any>\n ? AllowedType\n : ElseType;\n\n/**\n * Utility type for supporting nested sub items in arrays\n * @public\n */\nexport type FormSchemaArrayItem<T> = T extends any[]\n ? FormSchema<T[Extract<keyof T, number>]>\n : FormSchema;\n\n/**\n * Utility type for recursive properties in a schema\n * @public\n */\nexport type FormSubKeySchema<TObj> = Partial<{\n [Key in Extract<keyof TObj, any>]: FormSchema<TObj[Key]>;\n}>;\n"]}
1
+ {"version":3,"file":"form.types.js","sourceRoot":"","sources":["../../../src/components/form/form.types.ts"],"names":[],"mappings":"AAuTA;;;GAGG;AACH,MAAM,CAAN,IAAY,cAmBX;AAnBD,WAAY,cAAc;EACtB;;KAEG;EACH,qCAAmB,CAAA;EAEnB;;KAEG;EACH,+BAAa,CAAA;EAEb;;;;;;KAMG;EACH,6BAAW,CAAA;AACf,CAAC,EAnBW,cAAc,KAAd,cAAc,QAmBzB","sourcesContent":["import { JSONSchema7 } from 'json-schema';\nimport { Help } from '../help/help.types';\nimport { EventEmitter } from '@stencil/core';\n\n/**\n * EventEmitter from `@stencil/core`.\n *\n * @public\n */\nexport { EventEmitter } from '@stencil/core';\n\ndeclare module 'json-schema' {\n interface JSONSchema7 {\n /**\n * Unique identifier for the schema\n * @internal\n */\n id?: string;\n\n /**\n * Lime elements specific options that can be specified in a schema\n */\n lime?: Omit<LimeSchemaOptions, 'layout'> & {\n layout?: Partial<LimeLayoutOptions>;\n };\n }\n}\n\n/**\n * @public\n */\nexport interface ValidationStatus {\n /**\n * True if the form is valid, false otherwise\n *\n * If the form is invalid, any errors can be found on the `errors` property\n */\n valid: boolean;\n\n /**\n * List of validation errors\n */\n errors?: FormError[];\n}\n\n/**\n * @public\n */\nexport interface FormError {\n /**\n * Name of the error\n */\n name: string;\n\n /**\n * Params of the error\n */\n params?: unknown;\n\n /**\n * Name of the invalid property\n */\n property: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath: string;\n\n /**\n * String describing the error\n */\n message: string;\n}\n\n/**\n * @public\n */\nexport type ValidationError = {\n /**\n * Name of the field the error belongs to\n */\n [key: string]: string[] | ValidationError;\n};\n\n/**\n * @public\n */\nexport interface FormComponent<T = any> {\n /**\n * The value of the current property\n */\n value: T;\n\n /**\n * Whether or not the current property is required\n */\n required?: boolean;\n\n /**\n * Whether or not the current property is readonly\n */\n readonly?: boolean;\n\n /**\n * Whether or not the current property is disabled\n */\n disabled?: boolean;\n\n /**\n * The label of the current property\n */\n label?: string;\n\n /**\n * The helper text for the current property\n */\n helperText?: string;\n\n /**\n * Additional contextual information about the form\n */\n formInfo?: FormInfo;\n\n /**\n * The event to emit when the value of the current property has changed\n */\n change: EventEmitter<T>;\n}\n\n/**\n * @public\n */\nexport interface FormInfo {\n /**\n * The schema of the current property\n */\n schema?: FormSchema;\n\n /**\n * The schema of the whole form\n */\n rootSchema?: FormSchema;\n\n /**\n * A tree of errors for this property and its children\n */\n errorSchema?: object;\n\n /**\n * The value of the whole form\n */\n rootValue?: any;\n\n /**\n * The name of the current property\n */\n name?: string;\n\n /**\n * Path to the property within the schema\n */\n schemaPath?: string[];\n}\n\n/**\n * Lime elements specific options that can be specified under the `lime` key in\n * a schema, e.g.\n *\n * ```ts\n * const schema = {\n * type: 'object',\n * lime: {\n * collapsible: true,\n * },\n * };\n * ```\n *\n * @public\n */\nexport interface LimeSchemaOptions {\n /**\n * When specified on an object it will render all sub components inside a\n * collapsible section\n */\n collapsible?: boolean;\n\n /**\n * When `collapsible` is `true`, set this to `false` to make the\n * collapsible section load in the open state.\n * Defaults to `true`.\n */\n collapsed?: boolean;\n\n /**\n * Will render the field using the specified component. The component\n * should implement the `FormComponent` interface\n */\n component?: FormComponentOptions;\n\n /**\n * When specified on an object it will render the sub components with the\n * specified layout\n */\n layout?: LimeLayoutOptions;\n\n /**\n * Mark the field as disabled\n */\n disabled?: boolean;\n\n /**\n * Hide the field from the UI while preserving its value in the form data.\n */\n hidden?: boolean;\n\n help?: string | Partial<Help>;\n\n /**\n * Controls whether items in an array can be reordered by the end user.\n */\n allowItemReorder?: boolean;\n\n /**\n * Controls whether items in an array can be removed by the end user.\n */\n allowItemRemoval?: boolean;\n}\n\n/**\n * Options for a layout to be used in a form\n * @public\n */\nexport type LimeLayoutOptions = GridLayoutOptions & RowLayoutOptions;\n\n/**\n * Options for a component to be rendered inside a form\n *\n * @public\n */\nexport interface FormComponentOptions {\n /**\n * Name of the component\n */\n name?: string;\n\n /**\n * Extra properties to give the component in addition to the properties\n * specified on the `FormComponent` interface\n */\n props?: Record<string, any>;\n}\n\n/**\n * @public\n */\nexport interface FormLayoutOptions<\n T extends FormLayoutType | `${FormLayoutType}` = FormLayoutType.Default,\n> {\n /**\n * The type of layout to use\n */\n type: T;\n}\n\n/**\n * Layout options for a grid layout\n * @public\n */\nexport interface GridLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of columns in the form\n */\n\n colSpan?: 1 | 2 | 3 | 4 | 5 | 'all';\n\n /**\n * When specified on a component within the grid, the component will take\n * up the the specified number of rows in the form\n */\n rowSpan?: number;\n\n /**\n * Number of columns to use in the layout\n */\n\n columns?: 1 | 2 | 3 | 4 | 5;\n\n /**\n * Attempts to fill in holes earlier in the grid, if smaller items come up\n * later. This may cause items to appear out-of-order, when doing so would\n * fill holes left by larger items. Defaults to `true`.\n */\n dense?: boolean;\n}\n\n/**\n * Layout options for a row layout\n * @public\n */\nexport interface RowLayoutOptions\n extends FormLayoutOptions<FormLayoutType | `${FormLayoutType}`> {\n /**\n * When specified on a field, the chosen icon will be displayed\n * on the left side of the row, beside the title.\n */\n icon?: string;\n}\n\n/**\n * Represents the layout types for a form.\n * @public\n */\nexport enum FormLayoutType {\n /**\n * The default layout\n */\n Default = 'default',\n\n /**\n * Render the form fields using a responsive grid layout\n */\n Grid = 'grid',\n\n /**\n * Render the form fields in full-width rows.\n * Each row can have a leading `icon`, and a field.\n * `title` and `description` provided by the schema will be placed\n * on the row itself, and not on the field.\n * This layout is good for creating UIs for user settings pages.\n */\n Row = 'row',\n}\n\n/**\n * Represents the JSON schema with Lime specific options\n * @public\n */\nexport interface FormSchema<T extends Record<string, any> = any>\n extends JSONSchema7 {\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.1\n */\n items?: FormSchemaArrayItem<T> | Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"items\" MUST be either a valid JSON Schema or an array\n * of valid JSON Schemas.\n *\n * This keyword determines how child instances validate for arrays, and\n * does not directly validate the immediate instance itself.\n *\n * If \"items\" is a schema, validation succeeds if all elements in the\n * array successfully validate against that schema.\n *\n * If \"items\" is an array of schemas, validation succeeds if each\n * element of the instance validates against the schema at the same\n * position, if any.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.2\n */\n additionalItems?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be a valid JSON Schema.\n *\n * An array instance is valid against \"contains\" if at least one of its\n * elements is valid against the given schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.6\n */\n contains?: FormSchemaArrayItem<T>;\n\n /**\n * The value of this keyword MUST be an array. Elements of this array,\n * if any, MUST be strings, and MUST be unique.\n *\n * An object instance is valid against this keyword if every item in the\n * array is the name of a property in the instance.\n *\n * Omitting this keyword has the same behavior as an empty array.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.3\n */\n required?: Array<ReplaceObjectType<T, Extract<keyof T, string>, string>>;\n\n /**\n * The value of \"properties\" MUST be an object. Each value of this\n * object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation succeeds if, for each name that appears in both the\n * instance and as a name within this keyword's value, the child\n * instance for that name successfully validates against the\n * corresponding schema.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.4\n */\n properties?: ReplaceObjectType<\n T,\n FormSubKeySchema<T>,\n Record<string, FormSchema>\n >;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against all schemas defined by this keyword's\n * value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.1\n */\n allOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against at least one schema defined by this\n * keyword's value.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.2\n */\n anyOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * This keyword's value MUST be a non-empty array. Each item of the\n * array MUST be a valid JSON Schema.\n *\n * An instance validates successfully against this keyword if it\n * validates successfully against exactly one schema defined by this\n * keyword's value.\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.3\n */\n oneOf?: Array<FormSchemaArrayItem<T>>;\n\n /**\n * The value of \"patternProperties\" MUST be an object. Each property\n * name of this object SHOULD be a valid regular expression, according\n * to the ECMA 262 regular expression dialect. Each property value of\n * this object MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself. Validation\n * of the primitive instance type against this keyword always succeeds.\n *\n * Validation succeeds if, for each instance name that matches any\n * regular expressions that appear as a property name in this keyword's\n * value, the child instance for that name successfully validates\n * against each schema that corresponds to a matching regular\n * expression.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.5\n */\n patternProperties?: Record<string, FormSchema>;\n\n /**\n * The value of \"additionalProperties\" MUST be a valid JSON Schema.\n *\n * This keyword determines how child instances validate for objects, and\n * does not directly validate the immediate instance itself.\n *\n * Validation with \"additionalProperties\" applies only to the child\n * values of instance names that do not match any names in \"properties\",\n * and do not match any regular expression in \"patternProperties\".\n *\n * For all such properties, validation succeeds if the child instance\n * validates against the \"additionalProperties\" schema.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.6\n */\n additionalProperties?: FormSchema | boolean;\n\n /**\n * This keyword specifies rules that are evaluated if the instance is an\n * object and contains a certain property.\n *\n * This keyword's value MUST be an object. Each property specifies a\n * dependency. Each dependency value MUST be an array or a valid JSON\n * Schema.\n *\n * If the dependency value is a subschema, and the dependency key is a\n * property in the instance, the entire instance must validate against\n * the dependency value.\n *\n * If the dependency value is an array, each element in the array, if\n * any, MUST be a string, and MUST be unique. If the dependency key is\n * a property in the instance, each of the items in the dependency value\n * must be a property that exists in the instance.\n *\n * Omitting this keyword has the same behavior as an empty object.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.7\n */\n dependencies?: Record<string, FormSchema | string[]>;\n\n /**\n * The value of \"propertyNames\" MUST be a valid JSON Schema.\n *\n * If the instance is an object, this keyword validates if every\n * property name in the instance validates against the provided schema.\n * Note the property name that the schema is testing will always be a\n * string.\n *\n * Omitting this keyword has the same behavior as an empty schema.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.5.8\n */\n propertyNames?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.1\n */\n if?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * This validation outcome of this keyword's subschema has no direct\n * effect on the overall validation result. Rather, it controls which\n * of the \"then\" or \"else\" keywords are evaluated.\n *\n * Instances that successfully validate against this keyword's subschema\n * MUST also be valid against the subschema value of the \"then\" keyword,\n * if present.\n *\n * Instances that fail to validate against this keyword's subschema MUST\n * also be valid against the subschema value of the \"else\" keyword, if\n * present.\n *\n * If annotations (Section 3.3) are being collected, they are collected\n * from this keyword's subschema in the usual way, including when the\n * keyword is present without either \"then\" or \"else\".\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.2\n */\n then?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * When \"if\" is present, and the instance fails to validate against its\n * subschema, then valiation succeeds against this keyword if the\n * instance successfully validates against this keyword's subschema.\n *\n * This keyword has no effect when \"if\" is absent, or when the instance\n * successfully validates against its subschema. Implementations MUST\n * NOT evaluate the instance against this keyword, for either validation\n * or annotation collection purposes, in such cases.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.6.3\n */\n else?: FormSchema;\n\n /**\n * This keyword's value MUST be a valid JSON Schema.\n *\n * An instance is valid against this keyword if it fails to validate\n * successfully against the schema defined by this keyword.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.7.4\n */\n not?: FormSchema;\n\n /**\n * The \"$defs\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n $defs?: Record<string, FormSchema>;\n\n /**\n * The \"definitions\" keywords provides a standardized location for\n * schema authors to inline re-usable JSON Schemas into a more general\n * schema. The keyword does not directly affect the validation result.\n *\n * This keyword's value MUST be an object. Each member value of this\n * object MUST be a valid JSON Schema.\n *\n * As an example, here is a schema describing an array of positive\n * integers, where the positive integer constraint is a subschema in\n * \"definitions\":\n * ```\n * {\n * \"type\": \"array\",\n * \"items\": { \"$ref\": \"#/definitions/positiveInteger\" },\n * \"definitions\": {\n * \"positiveInteger\": {\n * \"type\": \"integer\",\n * \"exclusiveMinimum\": 0\n * }\n * }\n * }\n * ```\n *\n * $defs is the newer keyword introduced in the JSON Schema Draft 2019-09, while definitions is from the older drafts.\n *\n * The main difference is that definitions is no longer an official keyword in the latest JSON Schema specification (Draft 2019-09 and later),\n * but it is still widely supported for backward compatibility.\n *\n * @see https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9\n */\n definitions?: Record<string, FormSchema>;\n}\n\n/**\n * Utility type for replacing object types with a specified type\n * @public\n */\nexport type ReplaceObjectType<T, AllowedType, ElseType> = T extends any[]\n ? ElseType\n : T extends Record<string, any>\n ? AllowedType\n : ElseType;\n\n/**\n * Utility type for supporting nested sub items in arrays\n * @public\n */\nexport type FormSchemaArrayItem<T> = T extends any[]\n ? FormSchema<T[Extract<keyof T, number>]>\n : FormSchema;\n\n/**\n * Utility type for recursive properties in a schema\n * @public\n */\nexport type FormSubKeySchema<TObj> = Partial<{\n [Key in Extract<keyof TObj, any>]: FormSchema<TObj[Key]>;\n}>;\n"]}
@@ -49,27 +49,29 @@ export class CollapsibleItemTemplate extends React.Component {
49
49
  }, children);
50
50
  }
51
51
  setActions(element) {
52
- const { item, index } = this.props;
53
- const actions = [
54
- {
52
+ const { item, index, allowItemRemoval, allowItemReorder } = this.props;
53
+ const actions = [];
54
+ if (allowItemReorder) {
55
+ actions.push({
55
56
  id: 'down',
56
57
  icon: 'down_arrow',
57
58
  disabled: !item.hasMoveDown,
58
59
  run: item.onReorderClick(index, index + 1),
59
- },
60
- {
60
+ }, {
61
61
  id: 'up',
62
62
  icon: 'up_arrow',
63
63
  disabled: !item.hasMoveUp,
64
64
  run: item.onReorderClick(index, index - 1),
65
- },
66
- {
65
+ });
66
+ }
67
+ if (allowItemRemoval) {
68
+ actions.push({
67
69
  id: 'remove',
68
70
  icon: 'trash',
69
71
  disabled: !item.hasRemove,
70
72
  run: item.onDropIndexClick(index),
71
- },
72
- ];
73
+ });
74
+ }
73
75
  element.actions = actions;
74
76
  }
75
77
  handleAction(event) {
@@ -1 +1 @@
1
- {"version":3,"file":"array-field-collapsible-item.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field-collapsible-item.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8BpC,MAAM,OAAO,uBAAwB,SAAQ,KAAK,CAAC,SAAS;EAKxD,YAAmB,KAA2B;IAC1C,KAAK,CAAC,KAAK,CAAC,CAAC;IADE,UAAK,GAAL,KAAK,CAAsB;IAJ9C,UAAK,GAAG;MACJ,MAAM,EAAE,KAAK;KAChB,CAAC;IAoFM,eAAU,GAAG,GAAG,EAAE;MACtB,IAAI,CAAC,QAAQ,CAAC;QACV,MAAM,EAAE,IAAI;OACf,CAAC,CAAC;IACP,CAAC,CAAC;IApFE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE/C,IAAI,CAAC,KAAK,GAAG;MACT,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC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IAC1D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IACnC,MAAM,OAAO,GAA6B;MACtC;QACI,EAAE,EAAE,MAAM;QACV,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,CAAC,IAAI,CAAC,WAAW;QAC3B,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC;OAC7C;MACD;QACI,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS;QACzB,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC;OAC7C;MACD;QACI,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS;QACzB,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;OACpC;KACJ,CAAC;IAEF,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;EAC9B,CAAC;EAEO,YAAY,CAAC,KAAqC;IACtD,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;EAC5B,CAAC;EAQO,WAAW,CAAC,IAAI;IACpB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;MAC1B,OAAO,KAAK,CAAC;KAChB;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;MACf,OAAO,IAAI,CAAC;KACf;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;EACvD,CAAC;CACJ","sourcesContent":["import { Action } from '../../collapsible-section/action';\nimport React from 'react';\nimport { findTitle } from './common';\nimport { ArrayFieldItem, Runnable } from './types';\nimport { isEmpty } from 'lodash-es';\nimport { JSONSchema7 } from 'json-schema';\n\ninterface CollapsibleItemProps {\n /**\n * Data from reach-jsonschema-form\n */\n item: ArrayFieldItem;\n\n /**\n * The index of the field in the array\n */\n index: number;\n\n /**\n * The value of the field\n */\n data: any;\n\n /**\n * Schema for the field\n */\n schema: JSONSchema7;\n\n /**\n * Schema for the entire form\n */\n formSchema: JSONSchema7;\n}\n\nexport class CollapsibleItemTemplate extends React.Component {\n state = {\n isOpen: false,\n };\n\n constructor(public props: CollapsibleItemProps) {\n super(props);\n this.handleAction = this.handleAction.bind(this);\n this.isDeepEmpty = this.isDeepEmpty.bind(this);\n\n this.state = {\n isOpen: this.isDeepEmpty(props.data),\n };\n }\n\n private section: HTMLLimelCollapsibleSectionElement;\n\n public componentDidMount() {\n const section = this.section;\n section.addEventListener('action', this.handleAction);\n section.addEventListener('open', this.handleOpen);\n\n this.setActions(section);\n }\n\n public componentDidUpdate() {\n this.setActions(this.section);\n }\n\n public componentWillUnmount() {\n const section = this.section;\n section.removeEventListener('action', this.handleAction);\n section.removeEventListener('open', this.handleOpen);\n }\n\n public render() {\n const { data, schema, formSchema } = this.props;\n let children: any;\n if (this.state.isOpen) {\n children = this.props.item.children;\n }\n\n return React.createElement(\n 'limel-collapsible-section',\n {\n header: findTitle(data, schema, formSchema) || 'New item',\n class: 'limel-form-array-item--object',\n ref: (section: HTMLLimelCollapsibleSectionElement) => {\n this.section = section;\n },\n 'is-open': this.state.isOpen,\n },\n children\n );\n }\n\n private setActions(element: HTMLLimelCollapsibleSectionElement) {\n const { item, index } = this.props;\n const actions: Array<Action & Runnable> = [\n {\n id: 'down',\n icon: 'down_arrow',\n disabled: !item.hasMoveDown,\n run: item.onReorderClick(index, index + 1),\n },\n {\n id: 'up',\n icon: 'up_arrow',\n disabled: !item.hasMoveUp,\n run: item.onReorderClick(index, index - 1),\n },\n {\n id: 'remove',\n icon: 'trash',\n disabled: !item.hasRemove,\n run: item.onDropIndexClick(index),\n },\n ];\n\n element.actions = actions;\n }\n\n private handleAction(event: CustomEvent<Action & Runnable>) {\n event.stopPropagation();\n event.detail.run(event);\n }\n\n private handleOpen = () => {\n this.setState({\n isOpen: true,\n });\n };\n\n private isDeepEmpty(data) {\n if (typeof data !== 'object') {\n return false;\n }\n\n if (isEmpty(data)) {\n return true;\n }\n\n return Object.values(data).every(this.isDeepEmpty);\n }\n}\n"]}
1
+ {"version":3,"file":"array-field-collapsible-item.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field-collapsible-item.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwCpC,MAAM,OAAO,uBAAwB,SAAQ,KAAK,CAAC,SAA+B;EAK9E,YAAmB,KAA2B;IAC1C,KAAK,CAAC,KAAK,CAAC,CAAC;IADE,UAAK,GAAL,KAAK,CAAsB;IAJ9C,UAAK,GAAG;MACJ,MAAM,EAAE,KAAK;KAChB,CAAC;IA2FM,eAAU,GAAG,GAAG,EAAE;MACtB,IAAI,CAAC,QAAQ,CAAC;QACV,MAAM,EAAE,IAAI;OACf,CAAC,CAAC;IACP,CAAC,CAAC;IA3FE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE/C,IAAI,CAAC,KAAK,GAAG;MACT,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC;KACvC,CAAC;EACN,CAAC;EAIM,iBAAiB;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC7B,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACtD,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,IA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,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,CAAC,IAAI,CAAC,WAAW;QAC3B,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC;OAC7C,EACD;QACI,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS;QACzB,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC;OAC7C,CACJ,CAAC;KACL;IAED,IAAI,gBAAgB,EAAE;MAClB,OAAO,CAAC,IAAI,CAAC;QACT,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS;QACzB,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;OACpC,CAAC,CAAC;KACN;IAED,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;EAC9B,CAAC;EAEO,YAAY,CAAC,KAAqC;IACtD,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;EAC5B,CAAC;EAQO,WAAW,CAAC,IAAI;IACpB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;MAC1B,OAAO,KAAK,CAAC;KAChB;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;MACf,OAAO,IAAI,CAAC;KACf;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;EACvD,CAAC;CACJ","sourcesContent":["import { Action } from '../../collapsible-section/action';\nimport React from 'react';\nimport { findTitle } from './common';\nimport { ArrayFieldItem, Runnable } from './types';\nimport { isEmpty } from 'lodash-es';\nimport { JSONSchema7 } from 'json-schema';\n\ninterface CollapsibleItemProps {\n /**\n * Data from reach-jsonschema-form\n */\n item: ArrayFieldItem;\n\n /**\n * The index of the field in the array\n */\n index: number;\n\n /**\n * The value of the field\n */\n data: any;\n\n /**\n * Schema for the field\n */\n schema: JSONSchema7;\n\n /**\n * Schema for the entire form\n */\n formSchema: JSONSchema7;\n\n /**\n * Control whether items can be removed.\n */\n allowItemRemoval: boolean;\n\n /**\n * Control whether items can be reordered.\n */\n allowItemReorder: boolean;\n}\n\nexport class CollapsibleItemTemplate extends React.Component<CollapsibleItemProps> {\n state = {\n isOpen: false,\n };\n\n constructor(public props: CollapsibleItemProps) {\n super(props);\n this.handleAction = this.handleAction.bind(this);\n this.isDeepEmpty = this.isDeepEmpty.bind(this);\n\n this.state = {\n isOpen: this.isDeepEmpty(props.data),\n };\n }\n\n private section: HTMLLimelCollapsibleSectionElement;\n\n public componentDidMount() {\n const section = this.section;\n section.addEventListener('action', this.handleAction);\n section.addEventListener('open', this.handleOpen);\n\n this.setActions(section);\n }\n\n public componentDidUpdate() {\n this.setActions(this.section);\n }\n\n public componentWillUnmount() {\n const section = this.section;\n section.removeEventListener('action', this.handleAction);\n section.removeEventListener('open', this.handleOpen);\n }\n\n public render() {\n const { data, schema, formSchema } = this.props;\n let children: any;\n if (this.state.isOpen) {\n children = this.props.item.children;\n }\n\n return React.createElement(\n 'limel-collapsible-section',\n {\n header: findTitle(data, schema, formSchema) || 'New item',\n class: 'limel-form-array-item--object',\n ref: (section: HTMLLimelCollapsibleSectionElement) => {\n this.section = section;\n },\n 'is-open': this.state.isOpen,\n },\n children\n );\n }\n\n private setActions(element: HTMLLimelCollapsibleSectionElement) {\n const { item, index, allowItemRemoval, allowItemReorder } = this.props;\n const actions: Array<Action & Runnable> = [];\n\n if (allowItemReorder) {\n actions.push(\n {\n id: 'down',\n icon: 'down_arrow',\n disabled: !item.hasMoveDown,\n run: item.onReorderClick(index, index + 1),\n },\n {\n id: 'up',\n icon: 'up_arrow',\n disabled: !item.hasMoveUp,\n run: item.onReorderClick(index, index - 1),\n }\n );\n }\n\n if (allowItemRemoval) {\n actions.push({\n id: 'remove',\n icon: 'trash',\n disabled: !item.hasRemove,\n run: item.onDropIndexClick(index),\n });\n }\n\n element.actions = actions;\n }\n\n private handleAction(event: CustomEvent<Action & Runnable>) {\n event.stopPropagation();\n event.detail.run(event);\n }\n\n private handleOpen = () => {\n this.setState({\n isOpen: true,\n });\n };\n\n private isDeepEmpty(data) {\n if (typeof data !== 'object') {\n return false;\n }\n\n if (isEmpty(data)) {\n return true;\n }\n\n return Object.values(data).every(this.isDeepEmpty);\n }\n}\n"]}
@@ -16,30 +16,52 @@ export class SimpleItemTemplate extends React.Component {
16
16
  const { item, index } = this.props;
17
17
  item.onReorderClick(index, index + 1)(event);
18
18
  };
19
- }
20
- componentDidMount() {
21
- this.removeButton.addEventListener('click', this.handleRemove);
22
- this.moveUpButton.addEventListener('click', this.handleMoveUp);
23
- this.moveDownButton.addEventListener('click', this.handleMoveDown);
19
+ this.setRemoveButton = (button) => {
20
+ if (this.removeButton) {
21
+ this.removeButton.removeEventListener('click', this.handleRemove);
22
+ }
23
+ this.removeButton = button || undefined;
24
+ if (this.removeButton) {
25
+ this.removeButton.addEventListener('click', this.handleRemove);
26
+ }
27
+ };
28
+ this.setMoveUpButton = (button) => {
29
+ if (this.moveUpButton) {
30
+ this.moveUpButton.removeEventListener('click', this.handleMoveUp);
31
+ }
32
+ this.moveUpButton = button || undefined;
33
+ if (this.moveUpButton) {
34
+ this.moveUpButton.addEventListener('click', this.handleMoveUp);
35
+ }
36
+ };
37
+ this.setMoveDownButton = (button) => {
38
+ if (this.moveDownButton) {
39
+ this.moveDownButton.removeEventListener('click', this.handleMoveDown);
40
+ }
41
+ this.moveDownButton = button || undefined;
42
+ if (this.moveDownButton) {
43
+ this.moveDownButton.addEventListener('click', this.handleMoveDown);
44
+ }
45
+ };
24
46
  }
25
47
  componentWillUnmount() {
26
- this.removeButton.removeEventListener('click', this.handleRemove);
27
- this.moveUpButton.removeEventListener('click', this.handleMoveUp);
28
- this.moveDownButton.removeEventListener('click', this.handleMoveDown);
48
+ this.setRemoveButton(undefined);
49
+ this.setMoveUpButton(undefined);
50
+ this.setMoveDownButton(undefined);
29
51
  }
30
52
  render() {
31
53
  const { item } = this.props;
32
54
  return React.createElement('div', {
33
55
  className: 'limel-form-array-item--simple',
34
- }, this.props.item.children, this.renderRemoveButton(item), this.renderMoveUpButton(item), this.renderMoveDownButton(item));
56
+ }, this.props.item.children, this.props.allowItemReorder
57
+ ? this.renderMoveDownButton(item)
58
+ : null, this.props.allowItemReorder ? this.renderMoveUpButton(item) : null, this.props.allowItemRemoval ? this.renderRemoveButton(item) : null);
35
59
  }
36
60
  renderRemoveButton(item) {
37
61
  const props = {
38
62
  icon: 'trash',
39
63
  disabled: !item.hasRemove,
40
- ref: (button) => {
41
- this.removeButton = button;
42
- },
64
+ ref: this.setRemoveButton,
43
65
  };
44
66
  return React.createElement(LIMEL_ICON_BUTTON, props);
45
67
  }
@@ -47,9 +69,7 @@ export class SimpleItemTemplate extends React.Component {
47
69
  const props = {
48
70
  icon: 'up_arrow',
49
71
  disabled: !item.hasMoveUp,
50
- ref: (button) => {
51
- this.moveUpButton = button;
52
- },
72
+ ref: this.setMoveUpButton,
53
73
  };
54
74
  return React.createElement(LIMEL_ICON_BUTTON, props);
55
75
  }
@@ -57,9 +77,7 @@ export class SimpleItemTemplate extends React.Component {
57
77
  const props = {
58
78
  icon: 'down_arrow',
59
79
  disabled: !item.hasMoveDown,
60
- ref: (button) => {
61
- this.moveDownButton = button;
62
- },
80
+ ref: this.setMoveDownButton,
63
81
  };
64
82
  return React.createElement(LIMEL_ICON_BUTTON, props);
65
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"array-field-simple-item.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field-simple-item.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAE9C,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAA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CAAC,MAA8B,EAAE,EAAE;QACpC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;MACjC,CAAC;KACJ,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;EACzD,CAAC;CAgBJ","sourcesContent":["import React from 'react';\nimport { ArrayFieldItem } from './types';\n\ninterface SimpleItemProps {\n item: ArrayFieldItem;\n index: number;\n}\n\nconst LIMEL_ICON_BUTTON = 'limel-icon-button';\n\nexport class SimpleItemTemplate extends React.Component {\n constructor(public props: SimpleItemProps) {\n super(props);\n }\n\n private removeButton: HTMLLimelButtonElement;\n private moveUpButton: HTMLLimelButtonElement;\n private moveDownButton: HTMLLimelButtonElement;\n\n public componentDidMount() {\n this.removeButton.addEventListener('click', this.handleRemove);\n this.moveUpButton.addEventListener('click', this.handleMoveUp);\n this.moveDownButton.addEventListener('click', this.handleMoveDown);\n }\n\n public componentWillUnmount() {\n this.removeButton.removeEventListener('click', this.handleRemove);\n this.moveUpButton.removeEventListener('click', this.handleMoveUp);\n this.moveDownButton.removeEventListener('click', this.handleMoveDown);\n }\n\n public render() {\n const { item } = this.props;\n\n return React.createElement(\n 'div',\n {\n className: 'limel-form-array-item--simple',\n },\n this.props.item.children,\n this.renderRemoveButton(item),\n this.renderMoveUpButton(item),\n this.renderMoveDownButton(item)\n );\n }\n\n private renderRemoveButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'trash',\n disabled: !item.hasRemove,\n ref: (button: HTMLLimelButtonElement) => {\n this.removeButton = button;\n },\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private renderMoveUpButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'up_arrow',\n disabled: !item.hasMoveUp,\n ref: (button: HTMLLimelButtonElement) => {\n this.moveUpButton = button;\n },\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private renderMoveDownButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'down_arrow',\n disabled: !item.hasMoveDown,\n ref: (button: HTMLLimelButtonElement) => {\n this.moveDownButton = button;\n },\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private handleRemove = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onDropIndexClick(index)(event);\n };\n\n private handleMoveUp = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onReorderClick(index, index - 1)(event);\n };\n\n private handleMoveDown = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onReorderClick(index, index + 1)(event);\n };\n}\n"]}
1
+ {"version":3,"file":"array-field-simple-item.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field-simple-item.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAE9C,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,SAA0B;EACpE,YAAmB,KAAsB;IACrC,KAAK,CAAC,KAAK,CAAC,CAAC;IADE,UAAK,GAAL,KAAK,CAAiB;IA6DjC,iBAAY,GAAG,CAAC,KAAmB,EAAQ,EAAE;MACjD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;MACnC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC;IAEM,iBAAY,GAAG,CAAC,KAAmB,EAAQ,EAAE;MACjD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;MACnC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC,CAAC;IAEM,mBAAc,GAAG,CAAC,KAAmB,EAAQ,EAAE;MACnD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;MACnC,IAAI,CAAC,cAAc,CAAC,K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BAAoB,CAAC,IAAoB;IAC7C,MAAM,KAAK,GAAQ;MACf,IAAI,EAAE,YAAY;MAClB,QAAQ,EAAE,CAAC,IAAI,CAAC,WAAW;MAC3B,GAAG,EAAE,IAAI,CAAC,iBAAiB;KAC9B,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;EACzD,CAAC;CAuDJ","sourcesContent":["import React from 'react';\nimport { ArrayFieldItem } from './types';\n\ninterface SimpleItemProps {\n item: ArrayFieldItem;\n index: number;\n allowItemRemoval: boolean;\n allowItemReorder: boolean;\n}\n\nconst LIMEL_ICON_BUTTON = 'limel-icon-button';\n\nexport class SimpleItemTemplate extends React.Component<SimpleItemProps> {\n constructor(public props: SimpleItemProps) {\n super(props);\n }\n\n private removeButton?: HTMLLimelButtonElement;\n private moveUpButton?: HTMLLimelButtonElement;\n private moveDownButton?: HTMLLimelButtonElement;\n\n public componentWillUnmount() {\n this.setRemoveButton(undefined);\n this.setMoveUpButton(undefined);\n this.setMoveDownButton(undefined);\n }\n\n public render() {\n const { item } = this.props;\n\n return React.createElement(\n 'div',\n {\n className: 'limel-form-array-item--simple',\n },\n this.props.item.children,\n this.props.allowItemReorder\n ? this.renderMoveDownButton(item)\n : null,\n this.props.allowItemReorder ? this.renderMoveUpButton(item) : null,\n this.props.allowItemRemoval ? this.renderRemoveButton(item) : null\n );\n }\n\n private renderRemoveButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'trash',\n disabled: !item.hasRemove,\n ref: this.setRemoveButton,\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private renderMoveUpButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'up_arrow',\n disabled: !item.hasMoveUp,\n ref: this.setMoveUpButton,\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private renderMoveDownButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'down_arrow',\n disabled: !item.hasMoveDown,\n ref: this.setMoveDownButton,\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private handleRemove = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onDropIndexClick(index)(event);\n };\n\n private handleMoveUp = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onReorderClick(index, index - 1)(event);\n };\n\n private handleMoveDown = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onReorderClick(index, index + 1)(event);\n };\n\n private setRemoveButton = (button?: HTMLLimelButtonElement | null) => {\n if (this.removeButton) {\n this.removeButton.removeEventListener('click', this.handleRemove);\n }\n\n this.removeButton = button || undefined;\n\n if (this.removeButton) {\n this.removeButton.addEventListener('click', this.handleRemove);\n }\n };\n\n private setMoveUpButton = (button?: HTMLLimelButtonElement | null) => {\n if (this.moveUpButton) {\n this.moveUpButton.removeEventListener('click', this.handleMoveUp);\n }\n\n this.moveUpButton = button || undefined;\n\n if (this.moveUpButton) {\n this.moveUpButton.addEventListener('click', this.handleMoveUp);\n }\n };\n\n private setMoveDownButton = (button?: HTMLLimelButtonElement | null) => {\n if (this.moveDownButton) {\n this.moveDownButton.removeEventListener(\n 'click',\n this.handleMoveDown\n );\n }\n\n this.moveDownButton = button || undefined;\n\n if (this.moveDownButton) {\n this.moveDownButton.addEventListener('click', this.handleMoveDown);\n }\n };\n}\n"]}
@@ -26,6 +26,7 @@ export class ArrayFieldTemplate extends React.Component {
26
26
  }
27
27
  renderItem(item, index) {
28
28
  const { schema, formData, formContext } = this.props;
29
+ const controls = this.getItemControls();
29
30
  if (isObjectType(schema.items)) {
30
31
  return React.createElement(CollapsibleItemTemplate, {
31
32
  key: item.key,
@@ -34,14 +35,26 @@ export class ArrayFieldTemplate extends React.Component {
34
35
  schema: schema,
35
36
  formSchema: formContext.schema,
36
37
  index: index,
38
+ allowItemRemoval: controls.allowItemRemoval,
39
+ allowItemReorder: controls.allowItemReorder,
37
40
  });
38
41
  }
39
42
  return React.createElement(SimpleItemTemplate, {
40
43
  key: item.key,
41
44
  item: item,
42
45
  index: index,
46
+ allowItemRemoval: controls.allowItemRemoval,
47
+ allowItemReorder: controls.allowItemReorder,
43
48
  });
44
49
  }
50
+ getItemControls() {
51
+ var _a;
52
+ const limeOptions = ((_a = this.props.schema) === null || _a === void 0 ? void 0 : _a.lime) || {};
53
+ return {
54
+ allowItemRemoval: limeOptions.allowItemRemoval !== false,
55
+ allowItemReorder: limeOptions.allowItemReorder !== false,
56
+ };
57
+ }
45
58
  handleAddClick(event) {
46
59
  event.stopPropagation();
47
60
  this.props.onAddClick(event);
@@ -1 +1 @@
1
- {"version":3,"file":"array-field.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI1D,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,SAAS;EACnD,YAAmB,KAA8B;IAC7C,KAAK,CAAC,KAAK,CAAC,CAAC;IADE,UAAK,GAAL,KAAK,CAAyB;IAE7C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;EACzD,CAAC;EAEM,MAAM;IACT,OAAO,KAAK,CAAC,aAAa,CACtB,KAAK,EACL,EAAE,EACF,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAC7B,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,EAChD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EACrC,IAAI,CAAC,eAAe,EAAE,CACzB,CAAC;EACN,CAAC;EAEO,eAAe;IACnB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;MACpB,OAAO;KACV;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,cAAc,EAAE;MACvC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK;MAChC,OAAO,EAAE,IAAI,CAAC,cAAc;MAC5B,IAAI,EAAE,WAAW;MACjB,KAAK,EAAE,gBAAgB;KAC1B,CAAC,CAAC;EACP,CAAC;EAEO,UAAU,CAAC,IAAoB,EAAE,KAAa;IAClD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAErD,IAAI,YAAY,CAAC,MAAM,CAAC,KAAmB,CAAC,EAAE;MAC1C,OAAO,KAAK,CAAC,aAAa,CAAC,uBAAuB,EAAE;QAChD,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC;QACrB,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,WAAW,CAAC,MAAM;QAC9B,KAAK,EAAE,KAAK;OACf,CAAC,CAAC;KACN;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,kBAAkB,EAAE;MAC3C,GAAG,EAAE,IAAI,CAAC,GAAG;MACb,IAAI,EAAE,IAAI;MACV,KAAK,EAAE,KAAK;KACf,CAAC,CAAC;EACP,CAAC;EAEO,cAAc,CAAC,KAAiB;IACpC,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;EACjC,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { isObjectType } from '../schema';\nimport { CollapsibleItemTemplate } from './array-field-collapsible-item';\nimport { SimpleItemTemplate } from './array-field-simple-item';\nimport { renderDescription, renderTitle } from './common';\nimport { ArrayFieldItem, ArrayFieldTemplateProps } from './types';\nimport { FormSchema } from '../form.types';\n\nexport class ArrayFieldTemplate extends React.Component {\n constructor(public props: ArrayFieldTemplateProps) {\n super(props);\n this.renderItem = this.renderItem.bind(this);\n this.handleAddClick = this.handleAddClick.bind(this);\n }\n\n public render() {\n return React.createElement(\n 'div',\n {},\n renderTitle(this.props.title),\n renderDescription(this.props.schema.description),\n this.props.items.map(this.renderItem),\n this.renderAddButton()\n );\n }\n\n private renderAddButton() {\n if (!this.props.canAdd) {\n return;\n }\n\n return React.createElement('limel-button', {\n label: this.props.title || 'Add',\n onClick: this.handleAddClick,\n icon: 'plus_math',\n class: 'button-add-new',\n });\n }\n\n private renderItem(item: ArrayFieldItem, index: number) {\n const { schema, formData, formContext } = this.props;\n\n if (isObjectType(schema.items as FormSchema)) {\n return React.createElement(CollapsibleItemTemplate, {\n key: item.key,\n item: item,\n data: formData[index],\n schema: schema,\n formSchema: formContext.schema,\n index: index,\n });\n }\n\n return React.createElement(SimpleItemTemplate, {\n key: item.key,\n item: item,\n index: index,\n });\n }\n\n private handleAddClick(event: MouseEvent) {\n event.stopPropagation();\n this.props.onAddClick(event);\n }\n}\n"]}
1
+ {"version":3,"file":"array-field.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAS1D,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,SAAS;EACnD,YAAmB,KAA8B;IAC7C,KAAK,CAAC,KAAK,CAAC,CAAC;I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AM,EAAE,MAAM;QACd,UAAU,EAAE,WAAW,CAAC,MAAM;QAC9B,KAAK,EAAE,KAAK;QACZ,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;QAC3C,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;OAC9C,CAAC,CAAC;KACN;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,kBAAkB,EAAE;MAC3C,GAAG,EAAE,IAAI,CAAC,GAAG;MACb,IAAI,EAAE,IAAI;MACV,KAAK,EAAE,KAAK;MACZ,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;MAC3C,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;KAC9C,CAAC,CAAC;EACP,CAAC;EAEO,eAAe;;IACnB,MAAM,WAAW,GAAG,CAAA,MAAA,IAAI,CAAC,KAAK,CAAC,MAAM,0CAAE,IAAI,KAAI,EAAE,CAAC;IAElD,OAAO;MACH,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,KAAK,KAAK;MACxD,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,KAAK,KAAK;KAC3D,CAAC;EACN,CAAC;EAEO,cAAc,CAAC,KAAiB;IACpC,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;EACjC,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { isObjectType } from '../schema';\nimport { CollapsibleItemTemplate } from './array-field-collapsible-item';\nimport { SimpleItemTemplate } from './array-field-simple-item';\nimport { renderDescription, renderTitle } from './common';\nimport { ArrayFieldItem, ArrayFieldTemplateProps } from './types';\nimport { FormSchema } from '../form.types';\n\ninterface ArrayItemControls {\n allowItemRemoval: boolean;\n allowItemReorder: boolean;\n}\n\nexport class ArrayFieldTemplate extends React.Component {\n constructor(public props: ArrayFieldTemplateProps) {\n super(props);\n this.renderItem = this.renderItem.bind(this);\n this.handleAddClick = this.handleAddClick.bind(this);\n }\n\n public render() {\n return React.createElement(\n 'div',\n {},\n renderTitle(this.props.title),\n renderDescription(this.props.schema.description),\n this.props.items.map(this.renderItem),\n this.renderAddButton()\n );\n }\n\n private renderAddButton() {\n if (!this.props.canAdd) {\n return;\n }\n\n return React.createElement('limel-button', {\n label: this.props.title || 'Add',\n onClick: this.handleAddClick,\n icon: 'plus_math',\n class: 'button-add-new',\n });\n }\n\n private renderItem(item: ArrayFieldItem, index: number) {\n const { schema, formData, formContext } = this.props;\n const controls = this.getItemControls();\n\n if (isObjectType(schema.items as FormSchema)) {\n return React.createElement(CollapsibleItemTemplate, {\n key: item.key,\n item: item,\n data: formData[index],\n schema: schema,\n formSchema: formContext.schema,\n index: index,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: controls.allowItemReorder,\n });\n }\n\n return React.createElement(SimpleItemTemplate, {\n key: item.key,\n item: item,\n index: index,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: controls.allowItemReorder,\n });\n }\n\n private getItemControls(): ArrayItemControls {\n const limeOptions = this.props.schema?.lime || {};\n\n return {\n allowItemRemoval: limeOptions.allowItemRemoval !== false,\n allowItemReorder: limeOptions.allowItemReorder !== false,\n };\n }\n\n private handleAddClick(event: MouseEvent) {\n event.stopPropagation();\n this.props.onAddClick(event);\n }\n}\n"]}
@@ -135,7 +135,10 @@ export class Table {
135
135
  this.formatRows();
136
136
  }
137
137
  updateData(newData = [], oldData = []) {
138
- const shouldReplace = this.shouldReplaceData(newData, oldData);
138
+ const newIds = this.getRowIds(newData);
139
+ const oldIds = this.getRowIds(oldData);
140
+ const shouldReplace = this.shouldReplaceData(newIds, oldIds);
141
+ const hasRowUpdates = !areRowsEqual(newData, oldData);
139
142
  setTimeout(() => {
140
143
  if (!this.tabulator) {
141
144
  return;
@@ -146,6 +149,11 @@ export class Table {
146
149
  this.setSelection();
147
150
  return;
148
151
  }
152
+ if (hasRowUpdates) {
153
+ this.tabulator.updateData(newData);
154
+ this.setSelection();
155
+ return;
156
+ }
149
157
  this.tabulator.updateOrAddData(newData);
150
158
  });
151
159
  }
@@ -208,12 +216,12 @@ export class Table {
208
216
  }
209
217
  this.tabulator.setSort(newSorting);
210
218
  }
211
- shouldReplaceData(newData, oldData) {
212
- const newIds = newData.map((item) => { var _a; return (_a = item.id) !== null && _a !== void 0 ? _a : item; });
213
- const oldIds = oldData.map((item) => { var _a; return (_a = item.id) !== null && _a !== void 0 ? _a : item; });
219
+ shouldReplaceData(newIds, oldIds) {
214
220
  return (!this.areEqualIds(newIds, oldIds) ||
215
- !this.isSameOrder(newIds, oldIds) ||
216
- !areRowsEqual(newData, oldData));
221
+ !this.isSameOrder(newIds, oldIds));
222
+ }
223
+ getRowIds(data) {
224
+ return data.map((item) => { var _a; return (_a = item.id) !== null && _a !== void 0 ? _a : item; });
217
225
  }
218
226
  areEqualIds(newIds, oldIds) {
219
227
  const newIdSet = new Set(newIds);
@@ -548,7 +556,7 @@ export class Table {
548
556
  "optional": false,
549
557
  "docs": {
550
558
  "tags": [],
551
- "text": "Data to be displayed in the table"
559
+ "text": "Data to be displayed in the table. Provide a stable `id` on each row to keep\nscroll position, focus, and selections intact across updates."
552
560
  },
553
561
  "defaultValue": "[]"
554
562
  },