igniteui-webcomponents 7.1.2 → 7.2.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.
- package/CHANGELOG.md +51 -0
- package/components/banner/banner.d.ts +53 -17
- package/components/banner/banner.js +5 -0
- package/components/banner/banner.js.map +1 -1
- package/components/button/button-base.d.ts +80 -26
- package/components/button/button-base.js +64 -23
- package/components/button/button-base.js.map +1 -1
- package/components/button/button.d.ts +12 -3
- package/components/button/button.js +1 -1
- package/components/button/button.js.map +1 -1
- package/components/button/icon-button.d.ts +25 -9
- package/components/button/icon-button.js +2 -2
- package/components/button/icon-button.js.map +1 -1
- package/components/button-group/themes/shared/button/button.common.css.js +1 -1
- package/components/button-group/themes/shared/button/button.common.css.js.map +1 -1
- package/components/button-group/themes/shared/button/button.indigo.css.js +1 -1
- package/components/button-group/themes/shared/button/button.indigo.css.js.map +1 -1
- package/components/calendar/base.d.ts +5 -4
- package/components/calendar/base.js +3 -2
- package/components/calendar/base.js.map +1 -1
- package/components/calendar/calendar.js +17 -13
- package/components/calendar/calendar.js.map +1 -1
- package/components/calendar/days-view/days-view.d.ts +1 -0
- package/components/calendar/days-view/days-view.js +7 -4
- package/components/calendar/days-view/days-view.js.map +1 -1
- package/components/calendar/helpers.d.ts +1 -1
- package/components/calendar/helpers.js.map +1 -1
- package/components/chat/chat-message.js +8 -8
- package/components/chat/chat-message.js.map +1 -1
- package/components/chat/chat-state.d.ts +3 -1
- package/components/chat/chat-state.js +3 -2
- package/components/chat/chat-state.js.map +1 -1
- package/components/chat/chat.d.ts +5 -1
- package/components/chat/chat.js +14 -4
- package/components/chat/chat.js.map +1 -1
- package/components/checkbox/checkbox.js +1 -0
- package/components/checkbox/checkbox.js.map +1 -1
- package/components/checkbox/switch.js +1 -0
- package/components/checkbox/switch.js.map +1 -1
- package/components/combo/combo.d.ts +1 -0
- package/components/combo/combo.js +7 -0
- package/components/combo/combo.js.map +1 -1
- package/components/combo/controllers/navigation.js +3 -0
- package/components/combo/controllers/navigation.js.map +1 -1
- package/components/common/controllers/command.d.ts +62 -0
- package/components/common/controllers/command.js +25 -0
- package/components/common/controllers/command.js.map +1 -0
- package/components/common/controllers/id-resolver.d.ts +31 -0
- package/components/common/controllers/id-resolver.js +136 -0
- package/components/common/controllers/id-resolver.js.map +1 -0
- package/components/common/i18n/EN/calendar.resources.d.ts +16 -14
- package/components/common/i18n/EN/calendar.resources.js +1 -1
- package/components/common/i18n/EN/calendar.resources.js.map +1 -1
- package/components/common/i18n/EN/chat.resources.d.ts +10 -8
- package/components/common/i18n/EN/chat.resources.js.map +1 -1
- package/components/common/i18n/EN/date-picker.resources.d.ts +8 -0
- package/components/common/i18n/EN/date-picker.resources.js +8 -0
- package/components/common/i18n/EN/date-picker.resources.js.map +1 -0
- package/components/common/i18n/EN/date-range-picker.resources.d.ts +9 -7
- package/components/common/i18n/EN/date-range-picker.resources.js +1 -1
- package/components/common/i18n/EN/date-range-picker.resources.js.map +1 -1
- package/components/common/i18n/i18n-controller.d.ts +14 -11
- package/components/common/i18n/i18n-controller.js +33 -41
- package/components/common/i18n/i18n-controller.js.map +1 -1
- package/components/common/i18n/utils.d.ts +8 -2
- package/components/common/i18n/utils.js +52 -44
- package/components/common/i18n/utils.js.map +1 -1
- package/components/common/mixins/alert.d.ts +47 -9
- package/components/common/mixins/alert.js +55 -12
- package/components/common/mixins/alert.js.map +1 -1
- package/components/common/mixins/forms/associated.js +11 -0
- package/components/common/mixins/forms/associated.js.map +1 -1
- package/components/common/mixins/forms/form-transformers.d.ts +1 -1
- package/components/common/mixins/forms/form-transformers.js.map +1 -1
- package/components/common/mixins/forms/types.d.ts +5 -0
- package/components/common/mixins/forms/types.js.map +1 -1
- package/components/common/mixins/mask-behavior.d.ts +73 -0
- package/components/common/mixins/mask-behavior.js +159 -0
- package/components/common/mixins/mask-behavior.js.map +1 -0
- package/components/common/templates/input-shell.d.ts +24 -0
- package/components/common/templates/input-shell.js +43 -0
- package/components/common/templates/input-shell.js.map +1 -0
- package/components/common/templates/masked-input.d.ts +39 -0
- package/components/common/templates/masked-input.js +37 -0
- package/components/common/templates/masked-input.js.map +1 -0
- package/components/common/util.d.ts +11 -0
- package/components/common/util.js +20 -0
- package/components/common/util.js.map +1 -1
- package/components/date-picker/date-picker.d.ts +6 -4
- package/components/date-picker/date-picker.js +16 -5
- package/components/date-picker/date-picker.js.map +1 -1
- package/components/date-range-picker/date-range-input.d.ts +60 -0
- package/components/date-range-picker/date-range-input.js +251 -0
- package/components/date-range-picker/date-range-input.js.map +1 -0
- package/components/date-range-picker/date-range-mask-parser.d.ts +106 -0
- package/components/date-range-picker/date-range-mask-parser.js +121 -0
- package/components/date-range-picker/date-range-mask-parser.js.map +1 -0
- package/components/date-range-picker/date-range-picker.d.ts +17 -11
- package/components/date-range-picker/date-range-picker.js +89 -61
- package/components/date-range-picker/date-range-picker.js.map +1 -1
- package/components/date-range-picker/predefined-ranges-area.d.ts +4 -4
- package/components/date-range-picker/predefined-ranges-area.js +8 -4
- package/components/date-range-picker/predefined-ranges-area.js.map +1 -1
- package/components/date-range-picker/validators.d.ts +5 -19
- package/components/date-range-picker/validators.js +20 -16
- package/components/date-range-picker/validators.js.map +1 -1
- package/components/date-time-input/date-time-input.base.d.ts +155 -0
- package/components/date-time-input/date-time-input.base.js +275 -0
- package/components/date-time-input/date-time-input.base.js.map +1 -0
- package/components/date-time-input/date-time-input.d.ts +33 -122
- package/components/date-time-input/date-time-input.js +45 -258
- package/components/date-time-input/date-time-input.js.map +1 -1
- package/components/date-time-input/datetime-mask-parser.d.ts +11 -1
- package/components/date-time-input/datetime-mask-parser.js +5 -5
- package/components/date-time-input/datetime-mask-parser.js.map +1 -1
- package/components/dialog/dialog.d.ts +88 -31
- package/components/dialog/dialog.js +29 -31
- package/components/dialog/dialog.js.map +1 -1
- package/components/file-input/file-input.d.ts +1 -1
- package/components/input/input-base.d.ts +2 -10
- package/components/input/input-base.js +11 -57
- package/components/input/input-base.js.map +1 -1
- package/components/input/input.d.ts +1 -1
- package/components/input/input.js +1 -0
- package/components/input/input.js.map +1 -1
- package/components/input/themes/dark/input.shared.css.d.ts +1 -0
- package/components/input/themes/dark/input.shared.css.js +3 -0
- package/components/input/themes/dark/input.shared.css.js.map +1 -0
- package/components/input/themes/light/input.shared.css.js +1 -1
- package/components/input/themes/light/input.shared.css.js.map +1 -1
- package/components/input/themes/shared/input.common.css.js +1 -1
- package/components/input/themes/shared/input.common.css.js.map +1 -1
- package/components/input/themes/shared/input.material.css.js +1 -1
- package/components/input/themes/shared/input.material.css.js.map +1 -1
- package/components/input/themes/themes.js +4 -3
- package/components/input/themes/themes.js.map +1 -1
- package/components/mask-input/mask-input.d.ts +9 -4
- package/components/mask-input/mask-input.js +30 -36
- package/components/mask-input/mask-input.js.map +1 -1
- package/components/nav-drawer/nav-drawer.d.ts +93 -17
- package/components/nav-drawer/nav-drawer.js +148 -21
- package/components/nav-drawer/nav-drawer.js.map +1 -1
- package/components/nav-drawer/themes/container.base.css.js +1 -1
- package/components/nav-drawer/themes/container.base.css.js.map +1 -1
- package/components/nav-drawer/themes/shared/container/nav-drawer.common.css.js +1 -1
- package/components/nav-drawer/themes/shared/container/nav-drawer.common.css.js.map +1 -1
- package/components/nav-drawer/themes/shared/container/nav-drawer.fluent.css.js +1 -1
- package/components/nav-drawer/themes/shared/container/nav-drawer.fluent.css.js.map +1 -1
- package/components/nav-drawer/themes/shared/container/nav-drawer.indigo.css.js +1 -1
- package/components/nav-drawer/themes/shared/container/nav-drawer.indigo.css.js.map +1 -1
- package/components/radio/radio.js +1 -0
- package/components/radio/radio.js.map +1 -1
- package/components/snackbar/snackbar.d.ts +9 -5
- package/components/snackbar/snackbar.js +6 -8
- package/components/snackbar/snackbar.js.map +1 -1
- package/components/snackbar/themes/snackbar.base.css.js +1 -1
- package/components/snackbar/themes/snackbar.base.css.js.map +1 -1
- package/components/stepper/step.d.ts +1 -1
- package/components/stepper/step.js +4 -4
- package/components/stepper/step.js.map +1 -1
- package/components/stepper/stepper.js +5 -0
- package/components/stepper/stepper.js.map +1 -1
- package/components/stepper/themes/step/step.base.css.js +1 -1
- package/components/stepper/themes/step/step.base.css.js.map +1 -1
- package/components/stepper/themes/stepper/stepper.base.css.js +1 -1
- package/components/stepper/themes/stepper/stepper.base.css.js.map +1 -1
- package/components/toast/themes/toast.base.css.js +1 -1
- package/components/toast/themes/toast.base.css.js.map +1 -1
- package/components/toast/toast.d.ts +9 -2
- package/components/toast/toast.js +0 -2
- package/components/toast/toast.js.map +1 -1
- package/components/types.d.ts +4 -0
- package/components/types.js.map +1 -1
- package/custom-elements.json +34882 -28909
- package/igniteui-webcomponents.css-data.json +1 -1
- package/igniteui-webcomponents.html-data.json +1 -1
- package/index.d.ts +5 -2
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/skills/igniteui-wc-choose-components/SKILL.md +23 -6
- package/skills/igniteui-wc-choose-components/reference/mcp-setup.md +82 -0
- package/skills/igniteui-wc-generate-from-image-design/references/component-mapping.md +4 -2
- package/web-types.json +2 -2
- package/components/mask-input/mask-input-base.d.ts +0 -51
- package/components/mask-input/mask-input-base.js +0 -146
- package/components/mask-input/mask-input-base.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"associated.js","sourceRoot":"","sources":["../../../../../src/components/common/mixins/forms/associated.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAI3E,OAAO,EAKL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,aAAa,GAAG,YAAY,CAAC;AAEnC,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,KAAK;CAChB,CA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C;AACN,CAAC;AAKD,MAAM,UAAU,2BAA2B,CACzC,IAAO;IAEP,MAAM,6BAA8B,SAAQ,kBAAkB,CAAC,IAAI,CAAC;QAGlE,IAAW,cAAc,CAAC,KAAc;YACtC,IAAI,CAAC,UAAU,CAAC,YAAY,GAAG,KAAK,CAAC;YAErC,IAAI,IAAI,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;gBACxC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC;gBACnC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBACtB,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;QAED,IAAW,cAAc;YACvB,OAAO,IAAI,CAAC,UAAU,CAAC,YAAuB,CAAC;QACjD,CAAC;QAEe,wBAAwB,CACtC,IAAY,EACZ,IAAmB,EACnB,OAAsB;YAEtB,KAAK,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;KACF;IAxBC;QADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;uEAS9B;IAkBH,OAAO,6BACJ,CAAC;AACN,CAAC","sourcesContent":["import type { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { addInternalsController } from '../../controllers/internals.js';\nimport { addSafeEventListener, isFunction, isString } from '../../util.js';\nimport type { Validator } from '../../validators.js';\nimport type { Constructor } from '../constructor.js';\nimport type { FormValue } from './form-value.js';\nimport {\n type FormAssociatedCheckboxElementInterface,\n type FormAssociatedElementInterface,\n type FormRestoreMode,\n type FormValueType,\n InternalInvalidEvent,\n InternalResetEvent,\n} from './types.js';\n\nconst INVALID_STATE = 'ig-invalid';\n\nconst eventOptions = {\n bubbles: false,\n composed: false,\n};\n\nfunction emitFormInvalidEvent(host: LitElement): void {\n host.dispatchEvent(new CustomEvent(InternalInvalidEvent, eventOptions));\n}\n\nfunction emitFormResetEvent(host: LitElement): void {\n host.dispatchEvent(new CustomEvent(InternalResetEvent, eventOptions));\n}\n\nfunction BaseFormAssociated<T extends Constructor<LitElement>>(base: T) {\n class BaseFormAssociatedElement extends base {\n public static readonly formAssociated = true;\n\n //#region Internal state and properties\n\n private readonly __internals = addInternalsController(this);\n protected readonly _formValue!: FormValue<unknown>;\n\n private _isFormSubmit = false;\n private _isInternalValidation = false;\n private _touched = false;\n private _isExternalInvalid = false;\n\n private get _hasUserInteraction(): boolean {\n return this._touched || this._isFormSubmit;\n }\n\n private get _shouldApplyStyles(): boolean {\n if (this._isExternalInvalid) {\n return true;\n }\n\n return (\n this._invalid && this._hasUserInteraction && !this._isInternalValidation\n );\n }\n\n protected _disabled = false;\n protected _invalid = false;\n protected _pristine = true;\n\n protected get __validators(): Validator[] {\n return [];\n }\n\n //#endregion\n\n //#region Public properties and attributes\n\n /**\n * The name attribute of the control.\n * @attr\n */\n @property({ reflect: true })\n public name!: string;\n\n /**\n * The disabled state of the component.\n * @attr\n * @default false\n */\n @property({ type: Boolean, reflect: true })\n public set disabled(value: boolean) {\n this._disabled = value;\n this.toggleAttribute('disabled', Boolean(this._disabled));\n }\n\n public get disabled(): boolean {\n return this._disabled;\n }\n\n /**\n * Sets the control into invalid state (visual state only).\n * @attr\n * @default false\n */\n @property({ type: Boolean })\n public set invalid(value: boolean) {\n this._isExternalInvalid = value;\n this._setInvalidStyles();\n }\n\n public get invalid(): boolean {\n return this._isExternalInvalid || this._shouldApplyStyles;\n }\n\n /** Returns the HTMLFormElement associated with this element. */\n public get form(): HTMLFormElement | null {\n return this.__internals.form;\n }\n\n /**\n * Returns a ValidityState object which represents the different validity states\n * the element can be in, with respect to constraint validation.\n */\n public get validity(): ValidityState {\n return this.__internals.validity;\n }\n\n /** A string containing the validation message of this element. */\n public get validationMessage(): string {\n return this.__internals.validationMessage;\n }\n\n /**\n * A boolean value which returns true if the element is a submittable element\n * that is a candidate for constraint validation.\n */\n public get willValidate(): boolean {\n return this.__internals.willValidate;\n }\n //#endregion\n\n //#region Life-cycle hooks\n\n constructor(...args: any[]) {\n super(args);\n addSafeEventListener(this, 'invalid', this._handleInvalid);\n }\n\n /** @internal */\n public override connectedCallback(): void {\n super.connectedCallback();\n this._pristine = true;\n this._touched = false;\n this._validate();\n }\n\n //#endregion\n\n //#region Form value and validation states\n\n private async _handleInvalid(event: Event): Promise<void> {\n event.preventDefault();\n this._invalid = true;\n\n if (this._isInternalValidation) {\n this._isInternalValidation = false;\n } else {\n this._isFormSubmit = true;\n emitFormInvalidEvent(this);\n }\n\n this._setInvalidStyles();\n this.requestUpdate();\n\n if (this._isFormSubmit) {\n await this.updateComplete;\n this._isFormSubmit = false;\n }\n }\n\n private _setInvalidStyles(): void {\n this.__internals.setState(INVALID_STATE, this._shouldApplyStyles);\n }\n\n private __runValidators() {\n const validity: ValidityStateFlags = {};\n let message = '';\n let validationFailed = false;\n\n for (const validator of this.__validators) {\n const isValid = validator.isValid(this);\n\n validity[validator.key] = !isValid;\n\n if (!isValid) {\n validationFailed = true;\n message = isFunction(validator.message)\n ? validator.message(this)\n : validator.message;\n }\n }\n\n this._invalid = validationFailed;\n\n return { validity, message };\n }\n\n /**\n * Executes the component validators and updates the internal validity state.\n */\n protected _validate(userMessage?: string): void {\n let { validity, message } = this.__runValidators();\n const hasCustomError = this.validity.customError;\n\n // valueMissing has precedence over the other validators aside from customError\n if (validity.valueMissing) {\n validity = {\n valueMissing: true,\n customError: hasCustomError,\n };\n }\n\n if (hasCustomError && userMessage === undefined) {\n // Internal validation cycle after the user has called setCustomValidity()\n // with some message. Keep the customError flag and the passed in message.\n validity.customError = true;\n message = this.validationMessage;\n } else if (hasCustomError && userMessage === '') {\n // setCustomValidity with an empty message.\n validity.customError = false;\n } else if (userMessage && userMessage !== '') {\n // setCustomValidity with a message.\n validity.customError = true;\n message = userMessage;\n }\n\n this.__internals.setValidity(validity, message);\n this._isInternalValidation = true;\n this._invalid = !this.__internals.checkValidity();\n }\n\n protected _handleBlur(): void {\n this._setTouchedState();\n this._validate();\n }\n\n protected _setTouchedState(): void {\n if (!this._touched) {\n this._touched = true;\n }\n }\n\n protected _setDefaultValue(current: string | null): void {\n this._formValue.defaultValue = current;\n }\n\n protected _restoreDefaultValue(): void {\n const value = this._formValue.value;\n this._formValue.setValueAndFormState(this._formValue.defaultValue);\n this.requestUpdate('value', value);\n }\n\n protected _setFormValue(value: FormValueType, state?: FormValueType): void {\n this._pristine = false;\n this.__internals.setFormValue(value, state);\n this._validate();\n this._setInvalidStyles();\n }\n\n //#region Form associated callback hooks\n\n protected formAssociatedCallback(_form: HTMLFormElement): void {}\n\n protected formDisabledCallback(state: boolean): void {\n this._disabled = state;\n this.requestUpdate();\n }\n\n protected formResetCallback(): void {\n this._restoreDefaultValue();\n this._pristine = true;\n this._touched = false;\n this._invalid = false;\n this._setInvalidStyles();\n emitFormResetEvent(this);\n }\n\n /* c8 ignore next 4 */\n protected formStateRestoreCallback(\n _state: FormValueType,\n _mode: FormRestoreMode\n ): void {}\n\n //#endregion\n\n //#region Public API\n\n /** Checks for validity of the control and shows the browser message if it invalid. */\n public reportValidity(): boolean {\n const state = this.__internals.reportValidity();\n this._invalid = !state;\n return state;\n }\n\n /** Checks for validity of the control and emits the invalid event if it invalid. */\n public checkValidity(): boolean {\n this._isInternalValidation = true;\n const state = this.__internals.checkValidity();\n this._invalid = !state;\n return state;\n }\n\n /**\n * Sets a custom validation message for the control.\n * As long as `message` is not empty, the control is considered invalid.\n */\n public setCustomValidity(message: string): void {\n this._validate(message);\n this._isInternalValidation = message === '';\n this._setInvalidStyles();\n this.requestUpdate();\n }\n\n //#endregion\n }\n return BaseFormAssociatedElement as Constructor<BaseFormAssociatedElement> &\n T;\n}\n\n/**\n * Mixes the passed in class and turns it into a form associated custom element.\n */\nexport function FormAssociatedMixin<T extends Constructor<LitElement>>(\n base: T\n) {\n class FormAssociatedElement extends BaseFormAssociated(base) {\n /* blazorCSSuppress */\n @property({ attribute: false })\n public set defaultValue(value: unknown) {\n this._formValue.defaultValue = value;\n\n if (this._pristine && 'value' in this) {\n this.value = this.defaultValue;\n this._pristine = true;\n this._validate();\n }\n }\n\n public get defaultValue(): unknown {\n return this._formValue.defaultValue;\n }\n\n public override attributeChangedCallback(\n name: string,\n prev: string | null,\n current: string | null\n ): void {\n super.attributeChangedCallback(name, prev, current);\n if (name === 'value') {\n this._setDefaultValue(current);\n }\n }\n }\n\n return FormAssociatedElement as unknown as Constructor<FormAssociatedElementInterface> &\n T;\n}\n\n/**\n * Mixes the passed in class and turns it into a form associated custom element.\n */\nexport function FormAssociatedCheckboxMixin<T extends Constructor<LitElement>>(\n base: T\n) {\n class FormAssociatedCheckboxElement extends BaseFormAssociated(base) {\n /* blazorCSSuppress */\n @property({ attribute: false })\n public set defaultChecked(value: boolean) {\n this._formValue.defaultValue = value;\n\n if (this._pristine && 'checked' in this) {\n this.checked = this.defaultChecked;\n this._pristine = true;\n this._validate();\n }\n }\n\n public get defaultChecked(): boolean {\n return this._formValue.defaultValue as boolean;\n }\n\n public override attributeChangedCallback(\n name: string,\n prev: string | null,\n current: string | null\n ): void {\n super.attributeChangedCallback(name, prev, current);\n if (name === 'checked') {\n this._setDefaultValue(isString(current) ? 'true' : null);\n }\n }\n }\n\n return FormAssociatedCheckboxElement as unknown as Constructor<FormAssociatedCheckboxElementInterface> &\n T;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"associated.js","sourceRoot":"","sources":["../../../../../src/components/common/mixins/forms/associated.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,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,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;KACF;IAxBC;QADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;uEAS9B;IAkBH,OAAO,6BACJ,CAAC;AACN,CAAC","sourcesContent":["import type { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { addInternalsController } from '../../controllers/internals.js';\nimport { enterKey } from '../../controllers/key-bindings.js';\nimport { addSafeEventListener, isFunction, isString } from '../../util.js';\nimport type { Validator } from '../../validators.js';\nimport type { Constructor } from '../constructor.js';\nimport type { FormValue } from './form-value.js';\nimport {\n type FormAssociatedCheckboxElementInterface,\n type FormAssociatedElementInterface,\n type FormRestoreMode,\n type FormValueType,\n InternalInvalidEvent,\n InternalResetEvent,\n} from './types.js';\n\nconst INVALID_STATE = 'ig-invalid';\n\nconst eventOptions = {\n bubbles: false,\n composed: false,\n};\n\nfunction emitFormInvalidEvent(host: LitElement): void {\n host.dispatchEvent(new CustomEvent(InternalInvalidEvent, eventOptions));\n}\n\nfunction emitFormResetEvent(host: LitElement): void {\n host.dispatchEvent(new CustomEvent(InternalResetEvent, eventOptions));\n}\n\nfunction BaseFormAssociated<T extends Constructor<LitElement>>(base: T) {\n class BaseFormAssociatedElement extends base {\n public static readonly formAssociated = true;\n\n //#region Internal state and properties\n\n private readonly __internals = addInternalsController(this);\n protected readonly _formValue!: FormValue<unknown>;\n\n private _isFormSubmit = false;\n private _isInternalValidation = false;\n private _touched = false;\n private _isExternalInvalid = false;\n\n private get _hasUserInteraction(): boolean {\n return this._touched || this._isFormSubmit;\n }\n\n private get _shouldApplyStyles(): boolean {\n if (this._isExternalInvalid) {\n return true;\n }\n\n return (\n this._invalid && this._hasUserInteraction && !this._isInternalValidation\n );\n }\n\n protected _disabled = false;\n protected _invalid = false;\n protected _pristine = true;\n\n protected get __validators(): Validator[] {\n return [];\n }\n\n //#endregion\n\n //#region Public properties and attributes\n\n /**\n * The name attribute of the control.\n * @attr\n */\n @property({ reflect: true })\n public name!: string;\n\n /**\n * The disabled state of the component.\n * @attr\n * @default false\n */\n @property({ type: Boolean, reflect: true })\n public set disabled(value: boolean) {\n this._disabled = value;\n this.toggleAttribute('disabled', Boolean(this._disabled));\n }\n\n public get disabled(): boolean {\n return this._disabled;\n }\n\n /**\n * Sets the control into invalid state (visual state only).\n * @attr\n * @default false\n */\n @property({ type: Boolean })\n public set invalid(value: boolean) {\n this._isExternalInvalid = value;\n this._setInvalidStyles();\n }\n\n public get invalid(): boolean {\n return this._isExternalInvalid || this._shouldApplyStyles;\n }\n\n /** Returns the HTMLFormElement associated with this element. */\n public get form(): HTMLFormElement | null {\n return this.__internals.form;\n }\n\n /**\n * Returns a ValidityState object which represents the different validity states\n * the element can be in, with respect to constraint validation.\n */\n public get validity(): ValidityState {\n return this.__internals.validity;\n }\n\n /** A string containing the validation message of this element. */\n public get validationMessage(): string {\n return this.__internals.validationMessage;\n }\n\n /**\n * A boolean value which returns true if the element is a submittable element\n * that is a candidate for constraint validation.\n */\n public get willValidate(): boolean {\n return this.__internals.willValidate;\n }\n //#endregion\n\n //#region Life-cycle hooks\n\n constructor(...args: any[]) {\n super(args);\n addSafeEventListener(this, 'invalid', this._handleInvalid);\n }\n\n /** @internal */\n public override connectedCallback(): void {\n super.connectedCallback();\n this._pristine = true;\n this._touched = false;\n this._validate();\n }\n\n //#endregion\n\n //#region Enter key submission handling\n\n protected _handleEnterKeydown(event: KeyboardEvent): void {\n if (event.key !== enterKey) return;\n if (event.repeat) return;\n\n const canSubmit =\n this.form && (this.form.noValidate || this.checkValidity());\n\n if (canSubmit) {\n this.form?.requestSubmit();\n }\n }\n\n //#endregion\n\n //#region Form value and validation states\n\n private async _handleInvalid(event: Event): Promise<void> {\n event.preventDefault();\n this._invalid = true;\n\n if (this._isInternalValidation) {\n this._isInternalValidation = false;\n } else {\n this._isFormSubmit = true;\n emitFormInvalidEvent(this);\n }\n\n this._setInvalidStyles();\n this.requestUpdate();\n\n if (this._isFormSubmit) {\n await this.updateComplete;\n this._isFormSubmit = false;\n }\n }\n\n private _setInvalidStyles(): void {\n this.__internals.setState(INVALID_STATE, this._shouldApplyStyles);\n }\n\n private __runValidators() {\n const validity: ValidityStateFlags = {};\n let message = '';\n let validationFailed = false;\n\n for (const validator of this.__validators) {\n const isValid = validator.isValid(this);\n\n validity[validator.key] = !isValid;\n\n if (!isValid) {\n validationFailed = true;\n message = isFunction(validator.message)\n ? validator.message(this)\n : validator.message;\n }\n }\n\n this._invalid = validationFailed;\n\n return { validity, message };\n }\n\n /**\n * Executes the component validators and updates the internal validity state.\n */\n protected _validate(userMessage?: string): void {\n let { validity, message } = this.__runValidators();\n const hasCustomError = this.validity.customError;\n\n // valueMissing has precedence over the other validators aside from customError\n if (validity.valueMissing) {\n validity = {\n valueMissing: true,\n customError: hasCustomError,\n };\n }\n\n if (hasCustomError && userMessage === undefined) {\n // Internal validation cycle after the user has called setCustomValidity()\n // with some message. Keep the customError flag and the passed in message.\n validity.customError = true;\n message = this.validationMessage;\n } else if (hasCustomError && userMessage === '') {\n // setCustomValidity with an empty message.\n validity.customError = false;\n } else if (userMessage && userMessage !== '') {\n // setCustomValidity with a message.\n validity.customError = true;\n message = userMessage;\n }\n\n this.__internals.setValidity(validity, message);\n this._isInternalValidation = true;\n this._invalid = !this.__internals.checkValidity();\n }\n\n protected _handleBlur(): void {\n this._setTouchedState();\n this._validate();\n }\n\n protected _setTouchedState(): void {\n if (!this._touched) {\n this._touched = true;\n }\n }\n\n protected _setDefaultValue(current: string | null): void {\n this._formValue.defaultValue = current;\n }\n\n protected _restoreDefaultValue(): void {\n const value = this._formValue.value;\n this._formValue.setValueAndFormState(this._formValue.defaultValue);\n this.requestUpdate('value', value);\n }\n\n protected _setFormValue(value: FormValueType, state?: FormValueType): void {\n this._pristine = false;\n this.__internals.setFormValue(value, state);\n this._validate();\n this._setInvalidStyles();\n }\n\n //#region Form associated callback hooks\n\n protected formAssociatedCallback(_form: HTMLFormElement): void {}\n\n protected formDisabledCallback(state: boolean): void {\n this._disabled = state;\n this.requestUpdate();\n }\n\n protected formResetCallback(): void {\n this._restoreDefaultValue();\n this._pristine = true;\n this._touched = false;\n this._invalid = false;\n this._setInvalidStyles();\n emitFormResetEvent(this);\n }\n\n /* c8 ignore next 4 */\n protected formStateRestoreCallback(\n _state: FormValueType,\n _mode: FormRestoreMode\n ): void {}\n\n //#endregion\n\n //#region Public API\n\n /** Checks for validity of the control and shows the browser message if it invalid. */\n public reportValidity(): boolean {\n const state = this.__internals.reportValidity();\n this._invalid = !state;\n return state;\n }\n\n /** Checks for validity of the control and emits the invalid event if it invalid. */\n public checkValidity(): boolean {\n this._isInternalValidation = true;\n const state = this.__internals.checkValidity();\n this._invalid = !state;\n return state;\n }\n\n /**\n * Sets a custom validation message for the control.\n * As long as `message` is not empty, the control is considered invalid.\n */\n public setCustomValidity(message: string): void {\n this._validate(message);\n this._isInternalValidation = message === '';\n this._setInvalidStyles();\n this.requestUpdate();\n }\n\n //#endregion\n }\n return BaseFormAssociatedElement as Constructor<BaseFormAssociatedElement> &\n T;\n}\n\n/**\n * Mixes the passed in class and turns it into a form associated custom element.\n */\nexport function FormAssociatedMixin<T extends Constructor<LitElement>>(\n base: T\n) {\n class FormAssociatedElement extends BaseFormAssociated(base) {\n /* blazorCSSuppress */\n @property({ attribute: false })\n public set defaultValue(value: unknown) {\n this._formValue.defaultValue = value;\n\n if (this._pristine && 'value' in this) {\n this.value = this.defaultValue;\n this._pristine = true;\n this._validate();\n }\n }\n\n public get defaultValue(): unknown {\n return this._formValue.defaultValue;\n }\n\n public override attributeChangedCallback(\n name: string,\n prev: string | null,\n current: string | null\n ): void {\n super.attributeChangedCallback(name, prev, current);\n if (name === 'value') {\n this._setDefaultValue(current);\n }\n }\n }\n\n return FormAssociatedElement as unknown as Constructor<FormAssociatedElementInterface> &\n T;\n}\n\n/**\n * Mixes the passed in class and turns it into a form associated custom element.\n */\nexport function FormAssociatedCheckboxMixin<T extends Constructor<LitElement>>(\n base: T\n) {\n class FormAssociatedCheckboxElement extends BaseFormAssociated(base) {\n /* blazorCSSuppress */\n @property({ attribute: false })\n public set defaultChecked(value: boolean) {\n this._formValue.defaultValue = value;\n\n if (this._pristine && 'checked' in this) {\n this.checked = this.defaultChecked;\n this._pristine = true;\n this._validate();\n }\n }\n\n public get defaultChecked(): boolean {\n return this._formValue.defaultValue as boolean;\n }\n\n public override attributeChangedCallback(\n name: string,\n prev: string | null,\n current: string | null\n ): void {\n super.attributeChangedCallback(name, prev, current);\n if (name === 'checked') {\n this._setDefaultValue(isString(current) ? 'true' : null);\n }\n }\n }\n\n return FormAssociatedCheckboxElement as unknown as Constructor<FormAssociatedCheckboxElementInterface> &\n T;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DateRangeValue } from '../../../
|
|
1
|
+
import type { DateRangeValue } from '../../../types.js';
|
|
2
2
|
import type { FormValueType, IgcFormControl } from './types.js';
|
|
3
3
|
export type FormValueTransformers<T> = {
|
|
4
4
|
setValue: (value: T) => T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-transformers.js","sourceRoot":"","sources":["../../../../../src/components/common/mixins/forms/form-transformers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAmBzC,MAAM,CAAC,MAAM,4BAA4B,GAAkC;IACzE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;IAC1B,eAAe,EAA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AM,CAAC,GAAG,IAAI,CAAC,IAAI,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,GAAG,EAAE,CAAC;YACR,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,MAAM,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC;AAGF,MAAM,CAAC,MAAM,6BAA6B,GACxC;IACE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI;IAClC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;IAC1B,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI;IACzC,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;IACjC,YAAY,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC5B,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC;AAEJ,MAAM,CAAC,MAAM,2BAA2B,GAEpC;IACF,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,SAAS;IACvC,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,SAAS;CAC/C,CAAC","sourcesContent":["import {\n convertToDate,\n convertToDateRange,\n getDateFormValue,\n} from '../../../calendar/helpers.js';\nimport type { DateRangeValue } from '../../../
|
|
1
|
+
{"version":3,"file":"form-trans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,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC;AAEJ,MAAM,CAAC,MAAM,2BAA2B,GAEpC;IACF,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,SAAS;IACvC,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,SAAS;CAC/C,CAAC","sourcesContent":["import {\n convertToDate,\n convertToDateRange,\n getDateFormValue,\n} from '../../../calendar/helpers.js';\nimport type { DateRangeValue } from '../../../types.js';\nimport { asNumber } from '../../util.js';\nimport type { FormValueType, IgcFormControl } from './types.js';\n\nexport type FormValueTransformers<T> = {\n setValue: (value: T) => T;\n getValue: (value: T) => T;\n setDefaultValue: (value: T) => T;\n getDefaultValue: (value: T) => T;\n setFormValue: (value: T, host: IgcFormControl) => FormValueType;\n};\n\nexport type FormValueConfig<T> = {\n initialValue: T;\n initialDefaultValue?: T;\n transformers?: Partial<FormValueTransformers<T>>;\n};\n\n// Transformers\n\nexport const FormValueDefaultTransformers: FormValueTransformers<string> = {\n setValue: (value) => value || '',\n getValue: (value) => value,\n setDefaultValue: (value) => value || '',\n getDefaultValue: (value) => value,\n setFormValue: (value, _) => value || null,\n};\n\nexport const FormValueBooleanTransformers: Partial<\n FormValueTransformers<boolean>\n> = {\n setValue: Boolean,\n setDefaultValue: Boolean,\n setFormValue: (checked, host) =>\n checked && 'value' in host ? (host.value as string) || 'on' : null,\n};\n\nexport const FormValueNumberTransformers: Partial<\n FormValueTransformers<number>\n> = {\n setValue: asNumber,\n setDefaultValue: asNumber,\n setFormValue: (value) => value.toString(),\n};\n\nexport const FormValueDateTimeTransformers: Partial<\n FormValueTransformers<Date | null>\n> = {\n setValue: convertToDate,\n setDefaultValue: convertToDate,\n setFormValue: getDateFormValue,\n};\n\nexport const FormValueDateRangeTransformers: Partial<\n FormValueTransformers<DateRangeValue | null>\n> = {\n setValue: convertToDateRange,\n setDefaultValue: convertToDateRange,\n setFormValue: (value, host) => {\n if (!host.name) {\n return null;\n }\n const start = value?.start?.toISOString();\n const end = value?.end?.toISOString();\n\n const formData = new FormData();\n\n if (start) {\n formData.append(`${host.name}-start`, start);\n }\n if (end) {\n formData.append(`${host.name}-end`, end);\n }\n\n return formData;\n },\n};\n\n/* blazorSuppress */\nexport const FormValueFileListTransformers: FormValueTransformers<FileList | null> =\n {\n setValue: (value) => value || null,\n getValue: (value) => value,\n setDefaultValue: (value) => value || null,\n getDefaultValue: (value) => value,\n setFormValue: (files, host) => {\n if (!(host.name && files)) {\n return null;\n }\n\n const formData = new FormData();\n for (const file of files) {\n formData.append(host.name, file);\n }\n\n return formData;\n },\n };\n\nexport const FormValueSelectTransformers: Partial<\n FormValueTransformers<string | undefined>\n> = {\n setValue: (value) => value || undefined,\n setDefaultValue: (value) => value || undefined,\n};\n"]}
|
|
@@ -42,6 +42,11 @@ declare class BaseFormAssociatedElement {
|
|
|
42
42
|
* that is a candidate for constraint validation.
|
|
43
43
|
*/
|
|
44
44
|
get willValidate(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Default implementation for handling the `Enter` key press on the component.
|
|
47
|
+
* Checks if the component is inside a form and if so, submits it.
|
|
48
|
+
*/
|
|
49
|
+
protected _handleEnterKeydown(event: KeyboardEvent): void;
|
|
45
50
|
/**
|
|
46
51
|
* Sets the **touched** state of the component and invokes {@link BaseFormAssociatedElement._validate | `_validate()`} method.
|
|
47
52
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/common/mixins/forms/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/components/common/mixins/forms/types.ts"],"names":[],"mappings":"AAuLA,MAAM,CAAC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC","sourcesContent":["import type { LitElement } from 'lit';\nimport type { ElementInternalsController } from '../../controllers/internals.js';\nimport type { Validator } from '../../validators.js';\n\nexport type FormRestoreMode = 'autocomplete' | 'restore';\nexport type FormValueType = string | File | FormData | null;\nexport type IgcFormControl = LitElement &\n (FormAssociatedElementInterface | FormAssociatedCheckboxElementInterface);\n\ndeclare class BaseFormAssociatedElement {\n public static readonly formAssociated: boolean;\n\n //#region Properties\n\n private readonly __internals: ElementInternalsController;\n protected readonly _formValue: unknown;\n\n protected _pristine: boolean;\n protected _disabled: boolean;\n protected _invalid: boolean;\n\n protected get __validators(): Validator[];\n\n /**\n * The disabled state of the component.\n * @attr\n * @default false\n */\n public disabled: boolean;\n\n /**\n * Sets the control into invalid state (visual state only).\n * @attr\n * @default false\n */\n public invalid: boolean;\n\n /**\n * The name attribute of the control.\n * @attr\n */\n public name: string;\n\n /** Returns the HTMLFormElement associated with this element. */\n public get form(): HTMLFormElement | null;\n\n /**\n * Returns a ValidityState object which represents the different validity states\n * the element can be in, with respect to constraint validation.\n */\n public get validity(): ValidityState;\n\n /** A string containing the validation message of this element. */\n public get validationMessage(): string;\n\n /**\n * A boolean value which returns true if the element is a submittable element\n * that is a candidate for constraint validation.\n */\n public get willValidate(): boolean;\n\n //#endregion\n\n //#region Methods\n\n /**\n * Default implementation for handling the `Enter` key press on the component.\n * Checks if the component is inside a form and if so, submits it.\n */\n protected _handleEnterKeydown(event: KeyboardEvent): void;\n\n /**\n * Sets the **touched** state of the component and invokes {@link BaseFormAssociatedElement._validate | `_validate()`} method.\n *\n * As the naming of the method suggests, this should be invoked either on **blur** or **focusout**, depending\n * on the DOM structure and how focus state is managed by the component.\n */\n protected _handleBlur(): void;\n\n /**\n * Sets the **touched** state of the component and **DOES NOT** invoke {@link BaseFormAssociatedElement._validate | `_validate()`} method.\n *\n * This should be called whenever a user interaction triggers a response, usually an event, from the component in\n * regards to its value.\n */\n protected _setTouchedState(): void;\n\n /**\n * Sets the default value of the component.\n * Called in `attributeChangedCallback`(i.e. when the `value` attribute of the control is set).\n */\n protected _setDefaultValue(current: string | null): void;\n\n /**\n * Called when the associated parent form is reset.\n */\n protected _restoreDefaultValue(): void;\n\n /**\n * Executes the component validators and updates the internal validity state.\n */\n protected _validate(message?: string): void;\n\n /**\n * Sets the component's submission value and state.\n */\n protected _setFormValue(value: FormValueType, state?: FormValueType): void;\n\n /**\n * Called by the browser when it associates/disassociates the component with/from a given form element.\n * Receives the form element as a parameter.\n *\n * @remarks\n * This is not implemented currently.\n */\n protected formAssociatedCallback(form: HTMLFormElement): void;\n\n /**\n * Called whenever the component or a parent `fieldset` elements are disabled.\n * Receives the current disabled state.\n */\n protected formDisabledCallback(state: boolean): void;\n\n /**\n * Called when the form is reset.\n * Resets the component value/checked state to the default one, internal state and validation.\n *\n * @remarks\n * The default implementation calls {@link BaseFormAssociatedElement._restoreDefaultValue | `_restoreDefaultValue`}.\n * If additional customization is needed, it is better to override that method instead of this callback.\n */\n protected formResetCallback(): void;\n\n /**\n * Called when the browser attempts to automatically fill out the component.\n *\n * @remarks\n * This is not implemented currently.\n */\n protected formStateRestoreCallback(\n state: FormValueType,\n mode: FormRestoreMode\n ): void;\n\n /** Checks for validity of the control and emits the invalid event if it invalid. */\n public checkValidity(): boolean;\n\n /** Checks for validity of the control and shows the browser message if it invalid. */\n public reportValidity(): boolean;\n\n /**\n * Sets a custom validation message for the control.\n * As long as `message` is not empty, the control is considered invalid.\n */\n public setCustomValidity(message: string): void;\n\n //#endregion\n}\n\nexport declare class FormAssociatedElementInterface extends BaseFormAssociatedElement {\n /** The initial value of the component. */\n public set defaultValue(value: unknown);\n public get defaultValue(): unknown;\n}\n\nexport declare class FormAssociatedCheckboxElementInterface extends BaseFormAssociatedElement {\n /** The initial checked state of the component. */\n public set defaultChecked(value: boolean);\n public get defaultChecked(): boolean;\n}\n\nexport declare class FormRequiredInterface {\n protected _required: boolean;\n\n /**\n * When set, makes the component a required field for validation.\n * @attr\n * @default false\n */\n public set required(value: boolean);\n public get required(): boolean;\n}\n\nexport const InternalInvalidEvent = 'igc-form-internal-invalid';\nexport const InternalResetEvent = 'igc-form-internal-reset';\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { LitElement } from 'lit';
|
|
2
|
+
import type { MaskParser } from '../../mask-input/mask-parser.js';
|
|
3
|
+
import type { RangeTextSelectMode, SelectionRangeDirection } from '../../types.js';
|
|
4
|
+
import type { AbstractConstructor } from './constructor.js';
|
|
5
|
+
export type MaskSelection = {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Public + protected interface contributed by {@link MaskBehaviorMixin}.
|
|
11
|
+
* Declared as a `declare class` so consumers can see protected members through
|
|
12
|
+
* the cast return type (mirrors the pattern used by the form-associated mixins).
|
|
13
|
+
*/
|
|
14
|
+
export declare class MaskBehaviorElementInterface {
|
|
15
|
+
protected readonly _input?: HTMLInputElement;
|
|
16
|
+
protected readonly _parser: MaskParser;
|
|
17
|
+
/** Reflects the current parser state into the host's public value. */
|
|
18
|
+
protected _syncValueFromMask(): void;
|
|
19
|
+
/** Delegates Enter-key handling to the form-associated base. */
|
|
20
|
+
protected _handleEnterKeydown(event: KeyboardEvent): void;
|
|
21
|
+
protected _maskSelection: MaskSelection;
|
|
22
|
+
protected _compositionStart: number;
|
|
23
|
+
protected _focused: boolean;
|
|
24
|
+
protected _maskedValue: string;
|
|
25
|
+
protected get _inputSelection(): MaskSelection;
|
|
26
|
+
protected get _isEmptyMask(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Makes the control a readonly field.
|
|
29
|
+
* @attr readonly
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
readOnly: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The mask pattern of the component.
|
|
35
|
+
* @attr
|
|
36
|
+
*/
|
|
37
|
+
get mask(): string;
|
|
38
|
+
set mask(value: string);
|
|
39
|
+
/**
|
|
40
|
+
* The prompt symbol to use for unfilled parts of the mask pattern.
|
|
41
|
+
* @attr
|
|
42
|
+
* @default '_'
|
|
43
|
+
*/
|
|
44
|
+
get prompt(): string;
|
|
45
|
+
set prompt(value: string);
|
|
46
|
+
protected _handleInput(event: InputEvent): Promise<void>;
|
|
47
|
+
protected _updateInput(text: string, range: MaskSelection): Promise<void>;
|
|
48
|
+
protected _emitInputEvent(): void;
|
|
49
|
+
protected _setMaskSelection(event: Event): void;
|
|
50
|
+
protected _handleCompositionStart(): void;
|
|
51
|
+
protected _handleCompositionEnd(event: CompositionEvent): void;
|
|
52
|
+
protected _handleClick(): void;
|
|
53
|
+
/** Sets the text selection range of the control. */
|
|
54
|
+
setSelectionRange(start?: number, end?: number, direction?: SelectionRangeDirection): void;
|
|
55
|
+
/** Replaces the selected text in the control and re-applies the mask. */
|
|
56
|
+
setRangeText(replacement: string, start?: number, end?: number, selectMode?: RangeTextSelectMode): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Adds masked-input behavior (parser-driven editing, selection tracking,
|
|
60
|
+
* composition handling, range text replacement) to a LitElement-derived class.
|
|
61
|
+
*
|
|
62
|
+
* The host class is expected to provide:
|
|
63
|
+
* - `_input` – the native `<input>` element (typically via `@query('input')`).
|
|
64
|
+
* - `_parser` – a {@link MaskParser} (or subclass) instance.
|
|
65
|
+
* - `_setTouchedState` – from `FormAssociatedMixin`.
|
|
66
|
+
* - `emitEvent` – from `EventEmitterMixin`.
|
|
67
|
+
* - `select` – from the host base.
|
|
68
|
+
*
|
|
69
|
+
* The host class must implement `_syncValueFromMask` to bridge the masked
|
|
70
|
+
* text back into its public `value`. It is called by the default
|
|
71
|
+
* `_updateInput` implementation and by `setRangeText`.
|
|
72
|
+
*/
|
|
73
|
+
export declare function MaskBehaviorMixin<T extends AbstractConstructor<LitElement>>(superClass: T): AbstractConstructor<MaskBehaviorElementInterface> & T;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { property, state } from 'lit/decorators.js';
|
|
8
|
+
export function MaskBehaviorMixin(superClass) {
|
|
9
|
+
class MaskBehaviorElement extends superClass {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this._maskSelection = { start: 0, end: 0 };
|
|
13
|
+
this._compositionStart = 0;
|
|
14
|
+
this._focused = false;
|
|
15
|
+
this._maskedValue = '';
|
|
16
|
+
this.readOnly = false;
|
|
17
|
+
}
|
|
18
|
+
get _inputSelection() {
|
|
19
|
+
return {
|
|
20
|
+
start: this._input?.selectionStart || 0,
|
|
21
|
+
end: this._input?.selectionEnd || 0,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
get _isEmptyMask() {
|
|
25
|
+
return this._maskedValue === this._parser.emptyMask;
|
|
26
|
+
}
|
|
27
|
+
set mask(value) {
|
|
28
|
+
this._parser.mask = value;
|
|
29
|
+
}
|
|
30
|
+
get mask() {
|
|
31
|
+
return this._parser.mask;
|
|
32
|
+
}
|
|
33
|
+
set prompt(value) {
|
|
34
|
+
this._parser.prompt = value;
|
|
35
|
+
}
|
|
36
|
+
get prompt() {
|
|
37
|
+
return this._parser.prompt;
|
|
38
|
+
}
|
|
39
|
+
async _handleInput({ inputType, isComposing, }) {
|
|
40
|
+
const value = this._input?.value ?? '';
|
|
41
|
+
const { start, end } = this._maskSelection;
|
|
42
|
+
const deletePosition = this._parser.getNextNonLiteralPosition(end) + 1;
|
|
43
|
+
this._setTouchedState();
|
|
44
|
+
switch (inputType) {
|
|
45
|
+
case 'deleteContentForward':
|
|
46
|
+
this._updateInput('', { start, end: deletePosition });
|
|
47
|
+
await this.updateComplete;
|
|
48
|
+
return this._input?.setSelectionRange(deletePosition, deletePosition);
|
|
49
|
+
case 'deleteContentBackward':
|
|
50
|
+
if (isComposing)
|
|
51
|
+
return;
|
|
52
|
+
return this._updateInput('', {
|
|
53
|
+
start: this._parser.getPreviousNonLiteralPosition(this._inputSelection.start + 1),
|
|
54
|
+
end,
|
|
55
|
+
});
|
|
56
|
+
case 'deleteByCut':
|
|
57
|
+
return this._updateInput('', this._maskSelection);
|
|
58
|
+
case 'insertText':
|
|
59
|
+
return this._updateInput(value.substring(start, this._inputSelection.end), this._maskSelection);
|
|
60
|
+
case 'insertFromPaste':
|
|
61
|
+
return this._updateInput(value.substring(start, this._inputSelection.end), {
|
|
62
|
+
start,
|
|
63
|
+
end: this._inputSelection.start,
|
|
64
|
+
});
|
|
65
|
+
case 'insertFromDrop':
|
|
66
|
+
return this._updateInput(value.substring(this._inputSelection.start, this._inputSelection.end), { ...this._inputSelection });
|
|
67
|
+
case undefined:
|
|
68
|
+
case '':
|
|
69
|
+
return this._updateInput(this._parser.parse(value.substring(start, this._inputSelection.end)), {
|
|
70
|
+
start,
|
|
71
|
+
end: this._inputSelection.end,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async _updateInput(text, range) {
|
|
76
|
+
const { value, end } = this._parser.replace(this._maskedValue, text, range.start, range.end);
|
|
77
|
+
this._maskedValue = value;
|
|
78
|
+
this._syncValueFromMask();
|
|
79
|
+
this.requestUpdate();
|
|
80
|
+
if (range.start !== this._parser.mask.length) {
|
|
81
|
+
this._emitInputEvent();
|
|
82
|
+
}
|
|
83
|
+
await this.updateComplete;
|
|
84
|
+
this._input?.setSelectionRange(end, end);
|
|
85
|
+
}
|
|
86
|
+
_emitInputEvent() {
|
|
87
|
+
this._setTouchedState();
|
|
88
|
+
this.emitEvent('igcInput', { detail: this._maskedValue });
|
|
89
|
+
}
|
|
90
|
+
_setMaskSelection(event) {
|
|
91
|
+
this._maskSelection = this._inputSelection;
|
|
92
|
+
if (event instanceof KeyboardEvent) {
|
|
93
|
+
this._handleEnterKeydown(event);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
_handleCompositionStart() {
|
|
97
|
+
this._compositionStart = this._inputSelection.start;
|
|
98
|
+
}
|
|
99
|
+
_handleCompositionEnd({ data }) {
|
|
100
|
+
this._updateInput(data, {
|
|
101
|
+
start: this._compositionStart,
|
|
102
|
+
end: this._inputSelection.end,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
_handleClick() {
|
|
106
|
+
const { selectionStart: start, selectionEnd: end } = this._input ?? {
|
|
107
|
+
selectionStart: 0,
|
|
108
|
+
selectionEnd: 0,
|
|
109
|
+
};
|
|
110
|
+
if (start === end && start === this._maskedValue.length) {
|
|
111
|
+
this.select();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
setSelectionRange(start, end, direction = 'none') {
|
|
115
|
+
this._input?.setSelectionRange(start ?? null, end ?? null, direction);
|
|
116
|
+
this._maskSelection = { start: start ?? 0, end: end ?? 0 };
|
|
117
|
+
}
|
|
118
|
+
setRangeText(replacement, start, end, selectMode) {
|
|
119
|
+
const current = this._inputSelection;
|
|
120
|
+
const _start = start ?? current.start;
|
|
121
|
+
const _end = end ?? current.end;
|
|
122
|
+
const result = this._parser.replace(this._maskedValue || this._parser.emptyMask, replacement, _start, _end);
|
|
123
|
+
this._maskedValue = this._parser.apply(this._parser.parse(result.value));
|
|
124
|
+
this._syncValueFromMask();
|
|
125
|
+
this.updateComplete.then(() => {
|
|
126
|
+
switch (selectMode) {
|
|
127
|
+
case 'select':
|
|
128
|
+
this.setSelectionRange(_start, _end);
|
|
129
|
+
break;
|
|
130
|
+
case 'start':
|
|
131
|
+
this.setSelectionRange(_start, _start);
|
|
132
|
+
break;
|
|
133
|
+
case 'end':
|
|
134
|
+
this.setSelectionRange(_end, _end);
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
this.setSelectionRange(current.start, current.end);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
__decorate([
|
|
143
|
+
state()
|
|
144
|
+
], MaskBehaviorElement.prototype, "_focused", void 0);
|
|
145
|
+
__decorate([
|
|
146
|
+
state()
|
|
147
|
+
], MaskBehaviorElement.prototype, "_maskedValue", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
property({ type: Boolean, reflect: true })
|
|
150
|
+
], MaskBehaviorElement.prototype, "readOnly", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
property()
|
|
153
|
+
], MaskBehaviorElement.prototype, "mask", null);
|
|
154
|
+
__decorate([
|
|
155
|
+
property()
|
|
156
|
+
], MaskBehaviorElement.prototype, "prompt", null);
|
|
157
|
+
return MaskBehaviorElement;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=mask-behavior.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mask-behavior.js","sourceRoot":"","sources":["../../../../src/components/common/mixins/mask-behavior.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAqHpD,MAAM,UAAU,iBAAiB,CAC/B,UAAa;IAEb,MAAe,mBAAoB,SAAQ,UAAU;QAArD;;YAgBY,mBAAc,GAAkB,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;YACrD,sBAAiB,GAAG,CAAC,CAAC;YAGtB,aAAQ,GAAG,KAAK,CAAC;YAGjB,iBAAY,GAAG,EAAE,CAAC;YAyBrB,aAAQ,GAAG,KAAK,CAAC;QAgO1B,CAAC;QAvPC,IAAc,eAAe;YAC3B,OAAO;gBACL,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,cAAc,IAAI,CAAC;g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AQ;wBACX,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;wBACrC,MAAM;oBACR,KAAK,OAAO;wBACV,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;wBACvC,MAAM;oBACR,KAAK,KAAK;wBACR,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;wBACnC,MAAM;oBACR;wBACE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KAGF;IA5PW;QADT,KAAK,EAAE;yDACmB;IAGjB;QADT,KAAK,EAAE;6DACoB;IAyBrB;QADN,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yDACnB;IAQxB;QADC,QAAQ,EAAE;mDAGV;IAaD;QADC,QAAQ,EAAE;qDAGV;IAyMH,OAAO,mBACJ,CAAC;AACN,CAAC","sourcesContent":["import type { LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport type { MaskParser } from '../../mask-input/mask-parser.js';\nimport type {\n RangeTextSelectMode,\n SelectionRangeDirection,\n} from '../../types.js';\nimport type { AbstractConstructor } from './constructor.js';\n\nexport type MaskSelection = {\n start: number;\n end: number;\n};\n\n/**\n * Public + protected interface contributed by {@link MaskBehaviorMixin}.\n * Declared as a `declare class` so consumers can see protected members through\n * the cast return type (mirrors the pattern used by the form-associated mixins).\n */\nexport declare class MaskBehaviorElementInterface {\n //#region Required from host\n\n protected readonly _input?: HTMLInputElement;\n protected readonly _parser: MaskParser;\n\n /** Reflects the current parser state into the host's public value. */\n protected _syncValueFromMask(): void;\n\n /** Delegates Enter-key handling to the form-associated base. */\n protected _handleEnterKeydown(event: KeyboardEvent): void;\n\n //#endregion\n\n //#region Internal state\n\n protected _maskSelection: MaskSelection;\n protected _compositionStart: number;\n protected _focused: boolean;\n protected _maskedValue: string;\n\n protected get _inputSelection(): MaskSelection;\n protected get _isEmptyMask(): boolean;\n\n //#endregion\n\n //#region Public attributes and properties\n\n /**\n * Makes the control a readonly field.\n * @attr readonly\n * @default false\n */\n public readOnly: boolean;\n\n /**\n * The mask pattern of the component.\n * @attr\n */\n public get mask(): string;\n public set mask(value: string);\n\n /**\n * The prompt symbol to use for unfilled parts of the mask pattern.\n * @attr\n * @default '_'\n */\n public get prompt(): string;\n public set prompt(value: string);\n\n //#endregion\n\n //#region Event handlers\n\n protected _handleInput(event: InputEvent): Promise<void>;\n protected _updateInput(text: string, range: MaskSelection): Promise<void>;\n protected _emitInputEvent(): void;\n protected _setMaskSelection(event: Event): void;\n protected _handleCompositionStart(): void;\n protected _handleCompositionEnd(event: CompositionEvent): void;\n protected _handleClick(): void;\n\n //#endregion\n\n //#region Public methods\n\n /** Sets the text selection range of the control. */\n public setSelectionRange(\n start?: number,\n end?: number,\n direction?: SelectionRangeDirection\n ): void;\n\n /** Replaces the selected text in the control and re-applies the mask. */\n public setRangeText(\n replacement: string,\n start?: number,\n end?: number,\n selectMode?: RangeTextSelectMode\n ): void;\n\n //#endregion\n}\n\n/**\n * Adds masked-input behavior (parser-driven editing, selection tracking,\n * composition handling, range text replacement) to a LitElement-derived class.\n *\n * The host class is expected to provide:\n * - `_input` – the native `<input>` element (typically via `@query('input')`).\n * - `_parser` – a {@link MaskParser} (or subclass) instance.\n * - `_setTouchedState` – from `FormAssociatedMixin`.\n * - `emitEvent` – from `EventEmitterMixin`.\n * - `select` – from the host base.\n *\n * The host class must implement `_syncValueFromMask` to bridge the masked\n * text back into its public `value`. It is called by the default\n * `_updateInput` implementation and by `setRangeText`.\n */\nexport function MaskBehaviorMixin<T extends AbstractConstructor<LitElement>>(\n superClass: T\n): AbstractConstructor<MaskBehaviorElementInterface> & T {\n abstract class MaskBehaviorElement extends superClass {\n //#region Required from host\n\n protected abstract readonly _input?: HTMLInputElement;\n protected abstract readonly _parser: MaskParser;\n protected abstract _setTouchedState(): void;\n public abstract select(): void;\n public abstract emitEvent(name: string, init?: CustomEventInit): boolean;\n\n protected abstract _syncValueFromMask(): void;\n protected abstract _handleEnterKeydown(event: KeyboardEvent): void;\n\n //#endregion\n\n //#region Internal state\n\n protected _maskSelection: MaskSelection = { start: 0, end: 0 };\n protected _compositionStart = 0;\n\n @state()\n protected _focused = false;\n\n @state()\n protected _maskedValue = '';\n\n protected get _inputSelection(): MaskSelection {\n return {\n start: this._input?.selectionStart || 0,\n end: this._input?.selectionEnd || 0,\n };\n }\n\n /** Indicates whether the current mask value is empty. */\n protected get _isEmptyMask(): boolean {\n return this._maskedValue === this._parser.emptyMask;\n }\n\n //#endregion\n\n //#region Public attributes and properties\n\n /**\n * Makes the control a readonly field.\n *\n * @attr readonly\n * @default false\n */\n @property({ type: Boolean, reflect: true })\n public readOnly = false;\n\n /**\n * The mask pattern of the component.\n *\n * @attr\n */\n @property()\n public set mask(value: string) {\n this._parser.mask = value;\n }\n\n public get mask(): string {\n return this._parser.mask;\n }\n\n /**\n * The prompt symbol to use for unfilled parts of the mask pattern.\n *\n * @attr\n * @default '_'\n */\n @property()\n public set prompt(value: string) {\n this._parser.prompt = value;\n }\n\n public get prompt(): string {\n return this._parser.prompt;\n }\n\n //#endregion\n\n //#region Event handlers\n\n protected async _handleInput({\n inputType,\n isComposing,\n }: InputEvent): Promise<void> {\n const value = this._input?.value ?? '';\n const { start, end } = this._maskSelection;\n const deletePosition = this._parser.getNextNonLiteralPosition(end) + 1;\n this._setTouchedState();\n\n switch (inputType) {\n case 'deleteContentForward':\n this._updateInput('', { start, end: deletePosition });\n await this.updateComplete;\n return this._input?.setSelectionRange(deletePosition, deletePosition);\n\n case 'deleteContentBackward':\n if (isComposing) return;\n return this._updateInput('', {\n start: this._parser.getPreviousNonLiteralPosition(\n this._inputSelection.start + 1\n ),\n end,\n });\n\n case 'deleteByCut':\n return this._updateInput('', this._maskSelection);\n\n case 'insertText':\n return this._updateInput(\n value.substring(start, this._inputSelection.end),\n this._maskSelection\n );\n\n case 'insertFromPaste':\n return this._updateInput(\n value.substring(start, this._inputSelection.end),\n {\n start,\n end: this._inputSelection.start,\n }\n );\n\n case 'insertFromDrop':\n return this._updateInput(\n value.substring(\n this._inputSelection.start,\n this._inputSelection.end\n ),\n { ...this._inputSelection }\n );\n\n // Potential browser auto-fill behavior\n case undefined:\n case '':\n return this._updateInput(\n this._parser.parse(\n value.substring(start, this._inputSelection.end)\n ),\n {\n start,\n end: this._inputSelection.end,\n }\n );\n }\n }\n\n /**\n * Default mask-update routine. Re-applies the parser, syncs the leaf's\n * value via {@link MaskBehaviorElementInterface._syncValueFromMask} and\n * emits an input event when the edit is not at the trailing mask boundary.\n *\n * Leaves with bespoke commit semantics (e.g. `igc-mask-input`) override this.\n */\n protected async _updateInput(\n text: string,\n range: MaskSelection\n ): Promise<void> {\n const { value, end } = this._parser.replace(\n this._maskedValue,\n text,\n range.start,\n range.end\n );\n\n this._maskedValue = value;\n this._syncValueFromMask();\n this.requestUpdate();\n\n if (range.start !== this._parser.mask.length) {\n this._emitInputEvent();\n }\n\n await this.updateComplete;\n this._input?.setSelectionRange(end, end);\n }\n\n /**\n * Emits an `igcInput` event with the current masked value as detail.\n * Override to emit a different payload (e.g. the parsed value).\n */\n protected _emitInputEvent(): void {\n this._setTouchedState();\n this.emitEvent('igcInput', { detail: this._maskedValue });\n }\n\n protected _setMaskSelection(event: Event): void {\n this._maskSelection = this._inputSelection;\n if (event instanceof KeyboardEvent) {\n this._handleEnterKeydown(event);\n }\n }\n\n protected _handleCompositionStart(): void {\n this._compositionStart = this._inputSelection.start;\n }\n\n protected _handleCompositionEnd({ data }: CompositionEvent): void {\n this._updateInput(data, {\n start: this._compositionStart,\n end: this._inputSelection.end,\n });\n }\n\n protected _handleClick(): void {\n const { selectionStart: start, selectionEnd: end } = this._input ?? {\n selectionStart: 0,\n selectionEnd: 0,\n };\n\n // Clicking at the end of the input field will select the entire mask\n if (start === end && start === this._maskedValue.length) {\n this.select();\n }\n }\n\n //#endregion\n\n //#region Public methods\n\n /* blazorSuppress */\n /** Sets the text selection range of the control */\n public setSelectionRange(\n start?: number,\n end?: number,\n direction: SelectionRangeDirection = 'none'\n ): void {\n this._input?.setSelectionRange(start ?? null, end ?? null, direction);\n this._maskSelection = { start: start ?? 0, end: end ?? 0 };\n }\n\n /* blazorSuppress */\n /** Replaces the selected text in the control and re-applies the mask */\n public setRangeText(\n replacement: string,\n start?: number,\n end?: number,\n selectMode?: RangeTextSelectMode\n ): void {\n const current = this._inputSelection;\n const _start = start ?? current.start;\n const _end = end ?? current.end;\n\n const result = this._parser.replace(\n this._maskedValue || this._parser.emptyMask,\n replacement,\n _start,\n _end\n );\n this._maskedValue = this._parser.apply(this._parser.parse(result.value));\n this._syncValueFromMask();\n\n this.updateComplete.then(() => {\n switch (selectMode) {\n case 'select':\n this.setSelectionRange(_start, _end);\n break;\n case 'start':\n this.setSelectionRange(_start, _start);\n break;\n case 'end':\n this.setSelectionRange(_end, _end);\n break;\n default:\n this.setSelectionRange(current.start, current.end);\n }\n });\n }\n\n //#endregion\n }\n\n return MaskBehaviorElement as unknown as AbstractConstructor<MaskBehaviorElementInterface> &\n T;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { nothing, type TemplateResult } from 'lit';
|
|
2
|
+
import type { IgcFormControl } from '../mixins/forms/types.js';
|
|
3
|
+
/** Returns a unique id for native input elements rendered by input components. */
|
|
4
|
+
export declare function nextInputId(): string;
|
|
5
|
+
export interface InputShellOptions {
|
|
6
|
+
/** Active theme name. The `material` theme uses the notch layout. */
|
|
7
|
+
theme: string;
|
|
8
|
+
/** The label text. Empty string skips label rendering. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** The id of the input element used by the label `for` attribute. */
|
|
11
|
+
labelId: string;
|
|
12
|
+
/** Resolved part-name map for the container element. */
|
|
13
|
+
containerParts: Record<string, boolean>;
|
|
14
|
+
/** Renders the native `<input>` element. */
|
|
15
|
+
renderInput: () => TemplateResult;
|
|
16
|
+
/** Optional renderer for components that need extra parts inside the container (e.g. file-input). */
|
|
17
|
+
renderFileParts?: () => TemplateResult | typeof nothing;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders the shared input chrome (label, prefix, suffix, validator container)
|
|
21
|
+
* around a leaf-provided input template, switching layouts between the
|
|
22
|
+
* material notch and the standard flow.
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderInputShell(host: IgcFormControl, { containerParts, renderFileParts, renderInput, theme, label, labelId, }: InputShellOptions): TemplateResult;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { html, nothing } from 'lit';
|
|
2
|
+
import IgcValidationContainerComponent from '../../validation-container/validation-container.js';
|
|
3
|
+
import { partMap } from '../part-map.js';
|
|
4
|
+
let _nextInputId = 1;
|
|
5
|
+
export function nextInputId() {
|
|
6
|
+
return `input-${_nextInputId++}`;
|
|
7
|
+
}
|
|
8
|
+
function renderLabel(forId, label) {
|
|
9
|
+
return label
|
|
10
|
+
? html `<label part="label" for=${forId}>${label}</label>`
|
|
11
|
+
: nothing;
|
|
12
|
+
}
|
|
13
|
+
function renderPrefix() {
|
|
14
|
+
return html `<div part="prefix"><slot name="prefix"></slot></div>`;
|
|
15
|
+
}
|
|
16
|
+
function renderSuffix() {
|
|
17
|
+
return html `<div part="suffix"><slot name="suffix"></slot></div>`;
|
|
18
|
+
}
|
|
19
|
+
export function renderInputShell(host, { containerParts, renderFileParts, renderInput, theme, label, labelId, }) {
|
|
20
|
+
const validator = IgcValidationContainerComponent.create(host);
|
|
21
|
+
const input = renderInput.call(host);
|
|
22
|
+
const fileParts = renderFileParts?.call(host) ?? nothing;
|
|
23
|
+
if (theme === 'material') {
|
|
24
|
+
return html `
|
|
25
|
+
<div part=${partMap({ ...containerParts, labelled: !!label })}>
|
|
26
|
+
<div part="start">${renderPrefix()}</div>
|
|
27
|
+
${input}${fileParts}
|
|
28
|
+
<div part="notch">${renderLabel(labelId, label)}</div>
|
|
29
|
+
<div part="filler"></div>
|
|
30
|
+
<div part="end">${renderSuffix()}</div>
|
|
31
|
+
</div>
|
|
32
|
+
${validator}
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
return html `
|
|
36
|
+
${renderLabel(labelId, label)}
|
|
37
|
+
<div part=${partMap(containerParts)}>
|
|
38
|
+
${renderPrefix()}${fileParts}${input}${renderSuffix()}
|
|
39
|
+
</div>
|
|
40
|
+
${validator}
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=input-shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-shell.js","sourceRoot":"","sources":["../../../../src/components/common/templates/input-shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAuB,MAAM,KAAK,CAAC;AACzD,OAAO,+BAA+B,MAAM,oDAAoD,CAAC;AAEjG,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,IAAI,YAAY,GAAG,CAAC,CAAC;AAGrB,MAAM,UAAU,WAAW;IACzB,OAAO,SAAS,YAAY,EAAE,EAAE,CAAC;AACnC,CAAC;AAiBD,SAAS,WAAW,CAAC,KAAa,EAAE,KAAa;IAC/C,OAAO,KAAK;QACV,CAAC,CAAC,IAAI,CAAA,2BAA2B,KAAK,IAAI,KAAK,UAAU;QACzD,CAAC,CAAC,OAAO,CAAC;AACd,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,IAAI,CAAA,sDAAsD,CAAC;AACpE,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,IAAI,CAAA,sDAAsD,CAAC;AACpE,CAAC;AAOD,MAAM,UAAU,gBAAgB,CAC9B,IAAoB,EACpB,EACE,cAAc,EACd,eAAe,EACf,WAAW,EACX,KAAK,EACL,KAAK,EACL,OAAO,GACW;IAEpB,MAAM,SAAS,GAAG,+BAA+B,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC;IAEzD,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;QACzB,OAAO,IAAI,CAAA;kBACG,OAAO,CAAC,EAAE,GAAG,cAAc,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;4BACvC,YAAY,EAAE;UAChC,KAAK,GAAG,SAAS;4BACC,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC;;0BAE7B,YAAY,EAAE;;QAEhC,SAAS;KACZ,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAA;MACP,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC;gBACjB,OAAO,CAAC,cAAc,CAAC;QAC/B,YAAY,EAAE,GAAG,SAAS,GAAG,KAAK,GAAG,YAAY,EAAE;;MAErD,SAAS;GACZ,CAAC;AACJ,CAAC","sourcesContent":["import { html, nothing, type TemplateResult } from 'lit';\nimport IgcValidationContainerComponent from '../../validation-container/validation-container.js';\nimport type { IgcFormControl } from '../mixins/forms/types.js';\nimport { partMap } from '../part-map.js';\n\nlet _nextInputId = 1;\n\n/** Returns a unique id for native input elements rendered by input components. */\nexport function nextInputId(): string {\n return `input-${_nextInputId++}`;\n}\n\nexport interface InputShellOptions {\n /** Active theme name. The `material` theme uses the notch layout. */\n theme: string;\n /** The label text. Empty string skips label rendering. */\n label: string;\n /** The id of the input element used by the label `for` attribute. */\n labelId: string;\n /** Resolved part-name map for the container element. */\n containerParts: Record<string, boolean>;\n /** Renders the native `<input>` element. */\n renderInput: () => TemplateResult;\n /** Optional renderer for components that need extra parts inside the container (e.g. file-input). */\n renderFileParts?: () => TemplateResult | typeof nothing;\n}\n\nfunction renderLabel(forId: string, label: string) {\n return label\n ? html`<label part=\"label\" for=${forId}>${label}</label>`\n : nothing;\n}\n\nfunction renderPrefix() {\n return html`<div part=\"prefix\"><slot name=\"prefix\"></slot></div>`;\n}\n\nfunction renderSuffix() {\n return html`<div part=\"suffix\"><slot name=\"suffix\"></slot></div>`;\n}\n\n/**\n * Renders the shared input chrome (label, prefix, suffix, validator container)\n * around a leaf-provided input template, switching layouts between the\n * material notch and the standard flow.\n */\nexport function renderInputShell(\n host: IgcFormControl,\n {\n containerParts,\n renderFileParts,\n renderInput,\n theme,\n label,\n labelId,\n }: InputShellOptions\n): TemplateResult {\n const validator = IgcValidationContainerComponent.create(host);\n const input = renderInput.call(host);\n const fileParts = renderFileParts?.call(host) ?? nothing;\n\n if (theme === 'material') {\n return html`\n <div part=${partMap({ ...containerParts, labelled: !!label })}>\n <div part=\"start\">${renderPrefix()}</div>\n ${input}${fileParts}\n <div part=\"notch\">${renderLabel(labelId, label)}</div>\n <div part=\"filler\"></div>\n <div part=\"end\">${renderSuffix()}</div>\n </div>\n ${validator}\n `;\n }\n\n return html`\n ${renderLabel(labelId, label)}\n <div part=${partMap(containerParts)}>\n ${renderPrefix()}${fileParts}${input}${renderSuffix()}\n </div>\n ${validator}\n `;\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type TemplateResult } from 'lit';
|
|
2
|
+
export interface MaskedInputOptions {
|
|
3
|
+
/** Optional id for the native input element. */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** Resolved part-name map applied to the input. */
|
|
6
|
+
partNames: Record<string, boolean>;
|
|
7
|
+
/** The form-associated name attribute. */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Current value to render through `live()`. */
|
|
10
|
+
value: string;
|
|
11
|
+
/** Pre-resolved placeholder text. Caller decides empty-string semantics. */
|
|
12
|
+
placeholder: string;
|
|
13
|
+
readOnly: boolean;
|
|
14
|
+
disabled: boolean;
|
|
15
|
+
autofocus?: boolean;
|
|
16
|
+
inputMode?: string;
|
|
17
|
+
/** When provided, sets the `tabindex` attribute. */
|
|
18
|
+
tabindex?: number;
|
|
19
|
+
/** When provided, sets the `aria-describedby` attribute. */
|
|
20
|
+
ariaDescribedBy?: string;
|
|
21
|
+
onInput: (event: InputEvent) => void;
|
|
22
|
+
onFocus: (event: FocusEvent) => void;
|
|
23
|
+
onBlur: (event: FocusEvent) => void;
|
|
24
|
+
onClick: () => void;
|
|
25
|
+
/** Wired to `keydown`, `cut`, and `dragstart` to capture the current selection. */
|
|
26
|
+
onSetMaskSelection: (event: Event) => void;
|
|
27
|
+
onCompositionStart: () => void;
|
|
28
|
+
onCompositionEnd: (event: CompositionEvent) => void;
|
|
29
|
+
onChange?: () => void;
|
|
30
|
+
onWheel?: (event: WheelEvent) => void;
|
|
31
|
+
onDragEnter?: () => void;
|
|
32
|
+
onDragLeave?: () => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Renders the native `<input>` element shared by mask-driven components
|
|
36
|
+
* (`igc-mask-input`, `igc-date-time-input`, `igc-date-range-input`).
|
|
37
|
+
* Centralizes mask event wiring so leaves only describe their extras.
|
|
38
|
+
*/
|
|
39
|
+
export declare function renderMaskedNativeInput(opts: MaskedInputOptions): TemplateResult;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { live } from 'lit/directives/live.js';
|
|
4
|
+
import { partMap } from '../part-map.js';
|
|
5
|
+
import { bindIf } from '../util.js';
|
|
6
|
+
export function renderMaskedNativeInput(opts) {
|
|
7
|
+
return html `
|
|
8
|
+
<input
|
|
9
|
+
id=${ifDefined(opts.id)}
|
|
10
|
+
type="text"
|
|
11
|
+
part=${partMap(opts.partNames)}
|
|
12
|
+
name=${ifDefined(opts.name)}
|
|
13
|
+
.value=${live(opts.value)}
|
|
14
|
+
.placeholder=${opts.placeholder}
|
|
15
|
+
?readonly=${opts.readOnly}
|
|
16
|
+
?disabled=${opts.disabled}
|
|
17
|
+
?autofocus=${opts.autofocus}
|
|
18
|
+
inputmode=${ifDefined(opts.inputMode)}
|
|
19
|
+
tabindex=${bindIf(opts.tabindex !== undefined, opts.tabindex)}
|
|
20
|
+
aria-describedby=${bindIf(!!opts.ariaDescribedBy, opts.ariaDescribedBy)}
|
|
21
|
+
@input=${opts.onInput}
|
|
22
|
+
@focus=${opts.onFocus}
|
|
23
|
+
@blur=${opts.onBlur}
|
|
24
|
+
@click=${opts.onClick}
|
|
25
|
+
@keydown=${opts.onSetMaskSelection}
|
|
26
|
+
@cut=${opts.onSetMaskSelection}
|
|
27
|
+
@dragstart=${opts.onSetMaskSelection}
|
|
28
|
+
@compositionstart=${opts.onCompositionStart}
|
|
29
|
+
@compositionend=${opts.onCompositionEnd}
|
|
30
|
+
@change=${opts.onChange}
|
|
31
|
+
@wheel=${opts.onWheel}
|
|
32
|
+
@dragenter=${opts.onDragEnter}
|
|
33
|
+
@dragleave=${opts.onDragLeave}
|
|
34
|
+
/>
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=masked-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"masked-input.js","sourceRoot":"","sources":["../../../../src/components/common/templates/masked-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAuB,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA4CpC,MAAM,UAAU,uBAAuB,CACrC,IAAwB;IAExB,OAAO,IAAI,CAAA;;WAEF,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;;aAEhB,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;aACvB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;eAClB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;qBACV,IAAI,CAAC,WAAW;kBACnB,IAAI,CAAC,QAAQ;kBACb,IAAI,CAAC,QAAQ;mBACZ,IAAI,CAAC,SAAS;kBACf,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;iBAC1B,MAAM,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC;yBAC1C,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC;eAC9D,IAAI,CAAC,OAAO;eACZ,IAAI,CAAC,OAAO;cACb,IAAI,CAAC,MAAM;eACV,IAAI,CAAC,OAAO;iBACV,IAAI,CAAC,kBAAkB;aAC3B,IAAI,CAAC,kBAAkB;mBACjB,IAAI,CAAC,kBAAkB;0BAChB,IAAI,CAAC,kBAAkB;wBACzB,IAAI,CAAC,gBAAgB;gBAC7B,IAAI,CAAC,QAAQ;eACd,IAAI,CAAC,OAAO;mBACR,IAAI,CAAC,WAAW;mBAChB,IAAI,CAAC,WAAW;;GAEhC,CAAC;AACJ,CAAC","sourcesContent":["import { html, type TemplateResult } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { partMap } from '../part-map.js';\nimport { bindIf } from '../util.js';\n\nexport interface MaskedInputOptions {\n /** Optional id for the native input element. */\n id?: string;\n /** Resolved part-name map applied to the input. */\n partNames: Record<string, boolean>;\n /** The form-associated name attribute. */\n name?: string;\n /** Current value to render through `live()`. */\n value: string;\n /** Pre-resolved placeholder text. Caller decides empty-string semantics. */\n placeholder: string;\n readOnly: boolean;\n disabled: boolean;\n autofocus?: boolean;\n inputMode?: string;\n /** When provided, sets the `tabindex` attribute. */\n tabindex?: number;\n /** When provided, sets the `aria-describedby` attribute. */\n ariaDescribedBy?: string;\n\n // Required mask handlers\n onInput: (event: InputEvent) => void;\n onFocus: (event: FocusEvent) => void;\n onBlur: (event: FocusEvent) => void;\n onClick: () => void;\n /** Wired to `keydown`, `cut`, and `dragstart` to capture the current selection. */\n onSetMaskSelection: (event: Event) => void;\n onCompositionStart: () => void;\n onCompositionEnd: (event: CompositionEvent) => void;\n\n // Optional handlers\n onChange?: () => void;\n onWheel?: (event: WheelEvent) => void;\n onDragEnter?: () => void;\n onDragLeave?: () => void;\n}\n\n/**\n * Renders the native `<input>` element shared by mask-driven components\n * (`igc-mask-input`, `igc-date-time-input`, `igc-date-range-input`).\n * Centralizes mask event wiring so leaves only describe their extras.\n */\nexport function renderMaskedNativeInput(\n opts: MaskedInputOptions\n): TemplateResult {\n return html`\n <input\n id=${ifDefined(opts.id)}\n type=\"text\"\n part=${partMap(opts.partNames)}\n name=${ifDefined(opts.name)}\n .value=${live(opts.value)}\n .placeholder=${opts.placeholder}\n ?readonly=${opts.readOnly}\n ?disabled=${opts.disabled}\n ?autofocus=${opts.autofocus}\n inputmode=${ifDefined(opts.inputMode)}\n tabindex=${bindIf(opts.tabindex !== undefined, opts.tabindex)}\n aria-describedby=${bindIf(!!opts.ariaDescribedBy, opts.ariaDescribedBy)}\n @input=${opts.onInput}\n @focus=${opts.onFocus}\n @blur=${opts.onBlur}\n @click=${opts.onClick}\n @keydown=${opts.onSetMaskSelection}\n @cut=${opts.onSetMaskSelection}\n @dragstart=${opts.onSetMaskSelection}\n @compositionstart=${opts.onCompositionStart}\n @compositionend=${opts.onCompositionEnd}\n @change=${opts.onChange}\n @wheel=${opts.onWheel}\n @dragenter=${opts.onDragEnter}\n @dragleave=${opts.onDragLeave}\n />\n `;\n}\n"]}
|