frontile 0.18.0 → 0.18.2

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 (155) hide show
  1. package/declarations/-private/get-config.d.ts.map +1 -1
  2. package/declarations/-private/timer.d.ts +3 -3
  3. package/declarations/-private/timer.d.ts.map +1 -1
  4. package/declarations/components/buttons/chip.d.ts +1 -1
  5. package/declarations/components/buttons/chip.d.ts.map +1 -1
  6. package/declarations/components/buttons/close-button.d.ts +2 -2
  7. package/declarations/components/buttons/close-button.d.ts.map +1 -1
  8. package/declarations/components/collections/listbox/item.d.ts +2 -2
  9. package/declarations/components/collections/listbox/item.d.ts.map +1 -1
  10. package/declarations/components/collections/simple-table/column.d.ts +6 -0
  11. package/declarations/components/collections/simple-table/column.d.ts.map +1 -1
  12. package/declarations/components/collections/simple-table/footer.d.ts +2 -1
  13. package/declarations/components/collections/simple-table/footer.d.ts.map +1 -1
  14. package/declarations/components/collections/simple-table/header.d.ts +2 -1
  15. package/declarations/components/collections/simple-table/header.d.ts.map +1 -1
  16. package/declarations/components/collections/simple-table/index.d.ts +1 -1
  17. package/declarations/components/collections/simple-table/index.d.ts.map +1 -1
  18. package/declarations/components/collections/table/checkbox.d.ts +1 -1
  19. package/declarations/components/collections/table/checkbox.d.ts.map +1 -1
  20. package/declarations/components/collections/table/column-visibility.d.ts +2 -2
  21. package/declarations/components/collections/table/column-visibility.d.ts.map +1 -1
  22. package/declarations/components/collections/table/table.d.ts +9 -7
  23. package/declarations/components/collections/table/table.d.ts.map +1 -1
  24. package/declarations/components/forms/autocomplete.d.ts +12 -12
  25. package/declarations/components/forms/checkbox.d.ts +2 -2
  26. package/declarations/components/forms/checkbox.d.ts.map +1 -1
  27. package/declarations/components/forms/date-input/clipboard.d.ts +34 -0
  28. package/declarations/components/forms/date-input/clipboard.d.ts.map +1 -0
  29. package/declarations/components/forms/date-input/date-input.d.ts +93 -0
  30. package/declarations/components/forms/date-input/date-input.d.ts.map +1 -0
  31. package/declarations/components/forms/date-input/segment-group.d.ts +132 -0
  32. package/declarations/components/forms/date-input/segment-group.d.ts.map +1 -0
  33. package/declarations/components/forms/date-input/segments.d.ts +163 -0
  34. package/declarations/components/forms/date-input/segments.d.ts.map +1 -0
  35. package/declarations/components/forms/date-input/types.d.ts +175 -0
  36. package/declarations/components/forms/date-input/types.d.ts.map +1 -0
  37. package/declarations/components/forms/date-input.d.ts +6 -0
  38. package/declarations/components/forms/date-input.d.ts.map +1 -0
  39. package/declarations/components/forms/date-picker/date-picker.d.ts +263 -15
  40. package/declarations/components/forms/date-picker/date-picker.d.ts.map +1 -1
  41. package/declarations/components/forms/date-picker/end-content.d.ts +33 -3
  42. package/declarations/components/forms/date-picker/end-content.d.ts.map +1 -1
  43. package/declarations/components/forms/date-picker/types.d.ts +45 -2
  44. package/declarations/components/forms/date-picker/types.d.ts.map +1 -1
  45. package/declarations/components/forms/date-picker/value.d.ts +21 -5
  46. package/declarations/components/forms/date-picker/value.d.ts.map +1 -1
  47. package/declarations/components/forms/field.d.ts +7 -5
  48. package/declarations/components/forms/field.d.ts.map +1 -1
  49. package/declarations/components/forms/form.d.ts +5 -5
  50. package/declarations/components/forms/form.d.ts.map +1 -1
  51. package/declarations/components/forms/index.d.ts +1 -0
  52. package/declarations/components/forms/index.d.ts.map +1 -1
  53. package/declarations/components/forms/input-otp.d.ts +5 -5
  54. package/declarations/components/forms/input-otp.d.ts.map +1 -1
  55. package/declarations/components/forms/input.d.ts +15 -15
  56. package/declarations/components/forms/input.d.ts.map +1 -1
  57. package/declarations/components/forms/native-select.d.ts +10 -10
  58. package/declarations/components/forms/native-select.d.ts.map +1 -1
  59. package/declarations/components/forms/radio.d.ts +2 -2
  60. package/declarations/components/forms/radio.d.ts.map +1 -1
  61. package/declarations/components/forms/select/select.d.ts +16 -16
  62. package/declarations/components/forms/textarea.d.ts +10 -10
  63. package/declarations/components/forms/textarea.d.ts.map +1 -1
  64. package/declarations/components/navigation/pagination/pagination.d.ts +32 -1
  65. package/declarations/components/navigation/pagination/pagination.d.ts.map +1 -1
  66. package/declarations/components/overlays/overlay.d.ts +4 -4
  67. package/declarations/components/overlays/overlay.d.ts.map +1 -1
  68. package/declarations/components/utilities/avatar.d.ts +35 -2
  69. package/declarations/components/utilities/avatar.d.ts.map +1 -1
  70. package/declarations/components/utilities/collapsible.d.ts +16 -0
  71. package/declarations/components/utilities/collapsible.d.ts.map +1 -1
  72. package/declarations/test-support.d.ts +30 -0
  73. package/declarations/test-support.d.ts.map +1 -1
  74. package/declarations/utils/forms-utils-index.d.ts +1 -1
  75. package/declarations/utils/forms-utils-index.d.ts.map +1 -1
  76. package/declarations/utils/nested-data.d.ts +17 -0
  77. package/declarations/utils/nested-data.d.ts.map +1 -1
  78. package/dist/components/buttons/chip.js.map +1 -1
  79. package/dist/components/buttons/close-button.js +5 -12
  80. package/dist/components/buttons/close-button.js.map +1 -1
  81. package/dist/components/collections/listbox/item.js +4 -11
  82. package/dist/components/collections/listbox/item.js.map +1 -1
  83. package/dist/components/collections/simple-table/column.js +2 -2
  84. package/dist/components/collections/simple-table/column.js.map +1 -1
  85. package/dist/components/collections/simple-table/footer.js +1 -1
  86. package/dist/components/collections/simple-table/footer.js.map +1 -1
  87. package/dist/components/collections/simple-table/header.js +1 -1
  88. package/dist/components/collections/simple-table/header.js.map +1 -1
  89. package/dist/components/collections/simple-table/index.js +1 -1
  90. package/dist/components/collections/simple-table/index.js.map +1 -1
  91. package/dist/components/collections/table/checkbox.js +2 -7
  92. package/dist/components/collections/table/checkbox.js.map +1 -1
  93. package/dist/components/collections/table/column-visibility.js +2 -7
  94. package/dist/components/collections/table/column-visibility.js.map +1 -1
  95. package/dist/components/forms/checkbox.js +4 -12
  96. package/dist/components/forms/checkbox.js.map +1 -1
  97. package/dist/components/forms/date-input/clipboard.js +231 -0
  98. package/dist/components/forms/date-input/clipboard.js.map +1 -0
  99. package/dist/components/forms/date-input/date-input.js +204 -0
  100. package/dist/components/forms/date-input/date-input.js.map +1 -0
  101. package/dist/components/forms/date-input/segment-group.js +292 -0
  102. package/dist/components/forms/date-input/segment-group.js.map +1 -0
  103. package/dist/components/forms/date-input/segments.js +562 -0
  104. package/dist/components/forms/date-input/segments.js.map +1 -0
  105. package/dist/components/forms/date-input/types.js +2 -0
  106. package/dist/components/forms/date-input/types.js.map +1 -0
  107. package/dist/components/forms/date-input.js +4 -0
  108. package/dist/components/forms/date-input.js.map +1 -0
  109. package/dist/components/forms/date-picker/date-picker.js +361 -20
  110. package/dist/components/forms/date-picker/date-picker.js.map +1 -1
  111. package/dist/components/forms/date-picker/end-content.js +17 -4
  112. package/dist/components/forms/date-picker/end-content.js.map +1 -1
  113. package/dist/components/forms/date-picker/value.js +44 -6
  114. package/dist/components/forms/date-picker/value.js.map +1 -1
  115. package/dist/components/forms/field.js +12 -20
  116. package/dist/components/forms/field.js.map +1 -1
  117. package/dist/components/forms/form.js +11 -27
  118. package/dist/components/forms/form.js.map +1 -1
  119. package/dist/components/forms/index.js +5 -2
  120. package/dist/components/forms/index.js.map +1 -1
  121. package/dist/components/forms/input-otp.js +10 -26
  122. package/dist/components/forms/input-otp.js.map +1 -1
  123. package/dist/components/forms/input.js +9 -22
  124. package/dist/components/forms/input.js.map +1 -1
  125. package/dist/components/forms/native-select.js +5 -12
  126. package/dist/components/forms/native-select.js.map +1 -1
  127. package/dist/components/forms/radio.js +4 -12
  128. package/dist/components/forms/radio.js.map +1 -1
  129. package/dist/components/forms/textarea.js +6 -17
  130. package/dist/components/forms/textarea.js.map +1 -1
  131. package/dist/components/navigation/pagination/pagination.js +18 -2
  132. package/dist/components/navigation/pagination/pagination.js.map +1 -1
  133. package/dist/components/notifications/index.js +1 -1
  134. package/dist/components/overlays/overlay.js +8 -21
  135. package/dist/components/overlays/overlay.js.map +1 -1
  136. package/dist/components/utilities/avatar.js +26 -5
  137. package/dist/components/utilities/avatar.js.map +1 -1
  138. package/dist/components/utilities/collapsible.js +47 -3
  139. package/dist/components/utilities/collapsible.js.map +1 -1
  140. package/dist/forms.js +5 -2
  141. package/dist/forms.js.map +1 -1
  142. package/dist/index.js +6 -3
  143. package/dist/index.js.map +1 -1
  144. package/dist/{manager-jDaRVZ5o.js → manager-Dge4r8Vn.js} +9 -19
  145. package/dist/manager-Dge4r8Vn.js.map +1 -0
  146. package/dist/notifications.js +1 -1
  147. package/dist/services/notifications.js +1 -1
  148. package/dist/test-support.js +903 -389
  149. package/dist/test-support.js.map +1 -1
  150. package/dist/utils/forms-utils-index.js +1 -1
  151. package/dist/utils/forms-utils-index.js.map +1 -1
  152. package/dist/utils/nested-data.js +28 -1
  153. package/dist/utils/nested-data.js.map +1 -1
  154. package/package.json +10 -10
  155. package/dist/manager-jDaRVZ5o.js.map +0 -1
@@ -1,6 +1,5 @@
1
1
  import Component from '@glimmer/component';
2
2
  import { tracked } from '@glimmer/tracking';
3
- import { action } from '@ember/object';
4
3
  import { hash } from '@ember/helper';
5
4
  import { on } from '@ember/modifier';
6
5
  import { ref } from '../../utils/ref.js';
@@ -10,7 +9,7 @@ import { flattenData, deepEqual, unflattenData } from '../../utils/nested-data.j
10
9
  import { Field } from './field.js';
11
10
  import { precompileTemplate } from '@ember/template-compilation';
12
11
  import { setComponentTemplate } from '@ember/component';
13
- import { d as decorateFieldV2, i as initializeDeferredDecorator, a as decorateMethodV2 } from '../../runtime--fcdnjmJ-BOdRhmsS.js';
12
+ import { d as decorateFieldV2, i as initializeDeferredDecorator } from '../../runtime--fcdnjmJ-BOdRhmsS.js';
14
13
 
15
14
  /**
16
15
  * A form component that handles form submissions and input changes.
@@ -146,7 +145,7 @@ class Form extends Component {
146
145
  * @param name - The name of the field to validate.
147
146
  * @returns A promise that resolves to errors for the field, if any.
148
147
  */
149
- async validateField(data, name) {
148
+ validateField = async (data, name) => {
150
149
  if (!this.args.schema && !this.args.validate) {
151
150
  return;
152
151
  }
@@ -170,7 +169,7 @@ class Form extends Component {
170
169
  } = this.errors;
171
170
  this.errors = rest;
172
171
  }
173
- }
172
+ };
174
173
  /**
175
174
  * Computes which fields have changed from their initial values.
176
175
  * Uses deep comparison for consistency across flat and nested structures.
@@ -179,9 +178,6 @@ class Form extends Component {
179
178
  * @param data - The current form data.
180
179
  * @returns A set of field names that have changed.
181
180
  */
182
- static {
183
- decorateMethodV2(this.prototype, "validateField", [action]);
184
- }
185
181
  computeDirtyFields(data) {
186
182
  const dirty = new Set();
187
183
  if (!this.initialDataSnapshot) {
@@ -228,7 +224,7 @@ class Form extends Component {
228
224
  * Calls the `onChange` callback with the current form data if provided.
229
225
  * Automatically unflattens dotted field names to nested structure.
230
226
  */
231
- handleInput(event) {
227
+ handleInput = event => {
232
228
  const form = event.currentTarget;
233
229
  if (form instanceof HTMLFormElement) {
234
230
  let data = dataFrom(event);
@@ -237,17 +233,14 @@ class Form extends Component {
237
233
  this.uncontrolledData = data;
238
234
  this.args.onChange?.(resultData, event);
239
235
  }
240
- }
236
+ };
241
237
  /**
242
238
  * Handles the `submit` event on the form element.
243
239
  * Prevents the default form submission and calls the `onSubmit` callback
244
240
  * with the current form data. Manages the `isLoading` state during the
245
241
  * submission process. Automatically unflattens dotted field names to nested structure.
246
242
  */
247
- static {
248
- decorateMethodV2(this.prototype, "handleInput", [action]);
249
- }
250
- async handleSubmit(event) {
243
+ handleSubmit = async event => {
251
244
  event.preventDefault();
252
245
  const form = event.currentTarget;
253
246
  if (form instanceof HTMLFormElement) {
@@ -272,17 +265,14 @@ class Form extends Component {
272
265
  this.isLoading = false;
273
266
  }
274
267
  }
275
- }
268
+ };
276
269
  /**
277
270
  * Handles the `reset` event on the form element.
278
271
  * Clears validation errors and dirty tracking.
279
272
  * Restores the form data to its initial state.
280
273
  * Calls `onChange` if the form is controlled to let parent update state.
281
274
  */
282
- static {
283
- decorateMethodV2(this.prototype, "handleSubmit", [action]);
284
- }
285
- handleReset(event) {
275
+ handleReset = event => {
286
276
  this.errors = {};
287
277
  this.dirty = new Set();
288
278
  if (this.initialDataSnapshot) {
@@ -296,21 +286,15 @@ class Form extends Component {
296
286
  } else {
297
287
  this.uncontrolledData = undefined;
298
288
  }
299
- }
289
+ };
300
290
  /**
301
291
  * Resets the form to its initial state.
302
292
  * This method calls the native form reset() to clear all form controls,
303
293
  * triggering a `reset` event that is handled in `handleReset`.
304
294
  */
305
- static {
306
- decorateMethodV2(this.prototype, "handleReset", [action]);
307
- }
308
- reset() {
295
+ reset = () => {
309
296
  this.element?.current?.reset();
310
- }
311
- static {
312
- decorateMethodV2(this.prototype, "reset", [action]);
313
- }
297
+ };
314
298
  static {
315
299
  setComponentTemplate(precompileTemplate("{{!-- @glint-nocheck component generics (field) trigger: type instantiation is excessively deep and possibly infinite --}}\n<form {{this.element.setup}} {{on \"input\" this.handleInput}} {{on \"submit\" this.handleSubmit}} {{on \"reset\" this.handleReset}} ...attributes>\n {{yield (hash data=this.currentData isLoading=this.isLoading isValid=this.isValid isInvalid=this.isInvalid errors=this.errors dirty=this.dirty reset=this.reset Field=(component Field errors=this.errors formData=this.currentData disabled=@disabled validateOn=this.fieldValidateOn validateField=this.validateField)) to=\"default\"}}\n</form>", {
316
300
  strictMode: true,
@@ -1 +1 @@
1
- {"version":3,"file":"form.js","sources":["../../../src/components/forms/form.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { hash } from '@ember/helper';\nimport { on } from '@ember/modifier';\nimport { ref } from '../../utils/ref';\nimport { dataFrom } from 'form-data-utils';\nimport {\n StandardValidator,\n issuePathToFieldName\n} from '../../utils/standard-validator';\nimport { flattenData, unflattenData, deepEqual } from '../../utils/nested-data';\nimport { Field } from './field';\n\nimport type { WithBoundArgs } from '@glint/template';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Issues, CustomValidatorFn } from '../../utils/standard-validator';\nimport type Owner from '@ember/owner';\n\n/** The form data as key/value pairs. */\ntype FormDataCompiled = ReturnType<typeof dataFrom>;\n/** The validation errors for the form, keyed by field name. */\ntype FormErrors = Record<string, string | string[] | undefined>;\n\n/**\n * The data passed to `onChange` and `onSubmit` callbacks, which is similar\n * to `FormContext` but also includes the form data.\n */\ntype FormResultData<T = FormDataCompiled> = {\n /** The form data as key/value pairs. */\n data: T;\n /** Whether the form is valid (i.e. has no validation errors). */\n isValid: boolean;\n /** Whether the form is invalid (i.e. has validation errors). */\n isInvalid: boolean;\n /** The current form validation errors. */\n errors: FormErrors;\n /**\n * The set of fields that have changed from their initial values.\n * For flat data structures: contains top-level keys (e.g., \"firstName\", \"email\")\n * For nested data structures: contains dotted paths (e.g., \"user.name.first\", \"profile.email\")\n */\n dirty: Set<string>;\n};\n\n/**\n * The context yielded to the default block of the `Form` component.\n */\ninterface FormContext<T = FormDataCompiled> {\n /** The form data as key/value pairs. */\n data?: T;\n /** Whether the form is currently submitting. */\n isLoading: boolean;\n /** Whether the form is valid (i.e. has no validation errors). */\n isValid: boolean;\n /** Whether the form is invalid (i.e. has validation errors). */\n isInvalid: boolean;\n /** The current form validation errors. */\n errors: FormErrors;\n /**\n * The set of fields that have changed from their initial values.\n * For flat data structures: contains top-level keys (e.g., \"firstName\", \"email\")\n * For nested data structures: contains dotted paths (e.g., \"user.name.first\", \"profile.email\")\n */\n dirty: Set<string>;\n /**\n * Resets the form to its initial state.\n * Clears all form fields, validation errors, and dirty tracking.\n */\n reset: () => void;\n /** The `Field` component, with args bound. */\n Field: WithBoundArgs<\n typeof Field,\n 'errors' | 'formData' | 'disabled' | 'validateOn' | 'validateField'\n >;\n}\n\ninterface FormSignature<T = FormDataCompiled> {\n Element: HTMLFormElement;\n Args: {\n /**\n * The standard schema to validate form data against.\n */\n schema?: StandardSchemaV1<T>;\n /**\n * Optional custom validation function. A custom validator should return\n * an array of Standard Schema issues, or `undefined` if there are none.\n * This function may be async or sync.\n */\n validate?: CustomValidatorFn<T>;\n /**\n * When to run validation.\n */\n validateOn?: ('change' | 'input' | 'blur' | 'submit')[];\n /**\n * The initial form data as key/value pairs.\n * This is primarily useful for setting default values in the form.\n * This object receives changes as the user interacts with the form.\n */\n data?: T;\n /**\n * Whether the entire form and all its fields should be disabled. This only\n * applies when using the yielded `Field` component.\n */\n disabled?: boolean;\n /**\n * Optional callback invoked on input changes within the form.\n * @param result - The current form result data.\n * @param event - The input event that triggered the change.\n * @returns A promise or void.\n */\n onChange?: (\n result: FormResultData<T>,\n event: Event\n ) => Promise<void> | void;\n /**\n * Callback invoked on form submission. If `onSubmit` returns a promise,\n * the form will be marked as `isLoading` until the promise resolves.\n * @param result - The current form result data.\n * @param event - The submit event that triggered the submission.\n * @returns A promise or void.\n */\n onSubmit: (\n result: FormResultData<T>,\n event: SubmitEvent\n ) => Promise<void> | void;\n /**\n * Optional callback invoked when validation errors occur on form submission.\n * @param errors - The validation errors found.\n * @param data - The form data that was validated.\n * @param event - The submit event that triggered the validation.\n * @returns A promise or void.\n */\n onError?: (\n errors: FormErrors,\n data: T,\n event: SubmitEvent\n ) => Promise<void> | void;\n };\n Blocks: {\n default: [FormContext<T>];\n };\n}\n\n/**\n * A form component that handles form submissions and input changes.\n *\n * @example\n * ```hbs\n * <Form\n * @data={{this.formData}}\n * @schema={{this.schema}}\n * @validate={{this.customValidator}}\n * @onSubmit={{this.onSubmit}}\n * @onChange={{this.onChange}}\n * as |form|\n * >\n * <form.Field name=\"firstName\" as |field|>\n * <field.Input />\n * </form.Field>\n * <form.Field name=\"lastName\" as |field|>\n * <field.Input />\n * </form.Field>\n * <Button type=\"submit\" @isLoading={{form.isLoading}}>\n * Submit\n * <:loading>Submitting...</:loading>\n * </Button>\n * </Form>\n * ```\n */\nclass Form<T = FormDataCompiled> extends Component<FormSignature<T>> {\n /** Whether the form is currently submitting. */\n @tracked isLoading = false;\n\n /** The current form validation errors. */\n @tracked errors: FormErrors = {};\n\n /** The current uncontrolled form data. */\n @tracked uncontrolledData?: T;\n\n /**\n * Flattened snapshot of initial data for dirty field comparison.\n * Stored in flattened form regardless of whether source data is nested or flat.\n */\n @tracked initialDataSnapshot?: Record<string, unknown>;\n\n /**\n * The set of fields that have changed from their initial values.\n * For flat data structures: contains top-level keys (e.g., \"firstName\", \"email\")\n * For nested data structures: contains dotted paths (e.g., \"user.name.first\", \"profile.email\")\n */\n @tracked dirty: Set<string> = new Set();\n\n /** Reference to the form element. */\n element = ref<HTMLFormElement>();\n\n /**\n * Creates a new instance of the Form component.\n * Initializes internal state based on provided args.\n * @param owner - The owner of the component.\n * @param args - The arguments passed to the component.\n */\n constructor(owner: Owner, args: FormSignature<T>['Args']) {\n super(owner, args);\n if (args.data) {\n this.initialDataSnapshot = flattenData(\n args.data as Record<string, unknown>\n );\n\n this.uncontrolledData = { ...args.data };\n }\n }\n\n /** Whether the form is valid (i.e. has no validation errors). */\n get isValid() {\n return Object.keys(this.errors).length === 0;\n }\n\n /** Whether the form is invalid (i.e. has validation errors). */\n get isInvalid() {\n return !this.isValid;\n }\n\n /** Whether the form is controlled (`onChange` is provided). */\n get isControlled(): boolean {\n return !!this.args.onChange;\n }\n\n /** The events on which validation should run. */\n get validateOn(): ('change' | 'input' | 'blur' | 'submit')[] {\n return this.args.validateOn ?? ['change', 'blur', 'submit'];\n }\n\n /** The events on which field-level validation should run. */\n get fieldValidateOn(): ('change' | 'input' | 'blur')[] {\n return this.validateOn.filter((e) => e !== 'submit');\n }\n\n /** The current form data, from args if controlled, or internal state if uncontrolled. */\n get currentData(): T | undefined {\n if (this.isControlled) {\n return this.args.data;\n }\n return this.uncontrolledData;\n }\n\n /**\n * Validates data against the provided schema using StandardValidator.\n * Updates the `errors` property with any validation errors found.\n *\n * @param data - The form data to validate.\n * @returns A promise that resolves to the validation errors, if any.\n */\n async validate(data: T): Promise<FormErrors | undefined> {\n const errors = await StandardValidator.validateAll(\n data,\n this.args.schema,\n this.args.validate\n );\n if (errors) {\n const formErrors = validatorToFormErrors(errors);\n this.errors = formErrors;\n return formErrors;\n }\n this.errors = {};\n }\n\n /**\n * Validates a single field against the provided schema using\n * StandardValidator. Updates the `errors` property with any validation\n * errors found for the field. If the field had previous errors but\n * is now valid, those errors are cleared.\n *\n * @param data - The form data to validate against.\n * @param name - The name of the field to validate.\n * @returns A promise that resolves to errors for the field, if any.\n */\n @action\n async validateField(data: T, name: string): Promise<FormErrors | undefined> {\n if (!this.args.schema && !this.args.validate) {\n return;\n }\n const errors = await StandardValidator.validateFieldAll(\n data,\n name,\n this.args.schema,\n this.args.validate\n );\n if (errors) {\n const formErrors = validatorToFormErrors(errors);\n if (formErrors[name]) {\n this.errors = { ...this.errors, [name]: formErrors[name] };\n }\n return { [name]: formErrors[name] };\n }\n if (this.errors[name]) {\n const { [name]: _, ...rest } = this.errors;\n this.errors = rest;\n }\n }\n\n /**\n * Computes which fields have changed from their initial values.\n * Uses deep comparison for consistency across flat and nested structures.\n * This is a pure function with no side effects.\n *\n * @param data - The current form data.\n * @returns A set of field names that have changed.\n */\n computeDirtyFields(data: T): Set<string> {\n const dirty = new Set<string>();\n\n if (!this.initialDataSnapshot) {\n return dirty;\n }\n\n const currentFlat = flattenData(data as Record<string, unknown>);\n\n for (const key in currentFlat) {\n if (!deepEqual(currentFlat[key], this.initialDataSnapshot[key])) {\n dirty.add(key);\n }\n }\n\n for (const key in this.initialDataSnapshot) {\n if (\n !(key in currentFlat) &&\n this.initialDataSnapshot[key] !== undefined\n ) {\n dirty.add(key);\n }\n }\n\n return dirty;\n }\n\n /**\n * Builds the form result data object to pass to callbacks.\n * Also updates the dirty state as a side effect.\n *\n * @param data - The current form data.\n * @returns The form result data object.\n */\n buildFormResultData(data: T): FormResultData<T> {\n const { isValid, isInvalid, errors } = this;\n const dirty = this.computeDirtyFields(data);\n this.dirty = dirty;\n return {\n data,\n isValid,\n isInvalid,\n errors,\n dirty\n };\n }\n\n /**\n * Handles the `input` event on the form element.\n * Calls the `onChange` callback with the current form data if provided.\n * Automatically unflattens dotted field names to nested structure.\n */\n @action\n handleInput(event: Event) {\n const form = event.currentTarget;\n if (form instanceof HTMLFormElement) {\n let data = dataFrom(event) as T;\n data = unflattenData(data as Record<string, unknown>) as T;\n\n const resultData = this.buildFormResultData(data);\n this.uncontrolledData = data;\n this.args.onChange?.(resultData, event);\n }\n }\n\n /**\n * Handles the `submit` event on the form element.\n * Prevents the default form submission and calls the `onSubmit` callback\n * with the current form data. Manages the `isLoading` state during the\n * submission process. Automatically unflattens dotted field names to nested structure.\n */\n @action\n async handleSubmit(event: SubmitEvent) {\n event.preventDefault();\n const form = event.currentTarget;\n if (form instanceof HTMLFormElement) {\n this.isLoading = true;\n let data = dataFrom(event) as T;\n data = unflattenData(data as Record<string, unknown>) as T;\n\n let errors: FormErrors | undefined;\n if (this.validateOn.includes('submit')) {\n errors = await this.validate(data);\n }\n\n const resultData = this.buildFormResultData(data);\n this.uncontrolledData = data;\n try {\n if (errors && this.args.onError) {\n await this.args.onError(errors, data, event);\n } else if (!errors && this.args.onSubmit) {\n await this.args.onSubmit(resultData, event);\n this.initialDataSnapshot = flattenData(\n data as Record<string, unknown>\n );\n this.dirty = new Set();\n }\n } finally {\n this.isLoading = false;\n }\n }\n }\n\n /**\n * Handles the `reset` event on the form element.\n * Clears validation errors and dirty tracking.\n * Restores the form data to its initial state.\n * Calls `onChange` if the form is controlled to let parent update state.\n */\n @action\n handleReset(event: Event) {\n this.errors = {};\n this.dirty = new Set();\n\n if (this.initialDataSnapshot) {\n const restoredData = unflattenData(this.initialDataSnapshot) as T;\n\n if (this.isControlled && this.args.onChange) {\n const resultData = this.buildFormResultData(restoredData);\n\n this.args.onChange(resultData, event);\n } else {\n this.uncontrolledData = restoredData;\n }\n } else {\n this.uncontrolledData = undefined;\n }\n }\n\n /**\n * Resets the form to its initial state.\n * This method calls the native form reset() to clear all form controls,\n * triggering a `reset` event that is handled in `handleReset`.\n */\n @action\n reset() {\n this.element?.current?.reset();\n }\n\n <template>\n {{! @glint-nocheck component generics (field) trigger: type instantiation is excessively deep and possibly infinite }}\n <form\n {{this.element.setup}}\n {{on \"input\" this.handleInput}}\n {{on \"submit\" this.handleSubmit}}\n {{on \"reset\" this.handleReset}}\n ...attributes\n >\n {{yield\n (hash\n data=this.currentData\n isLoading=this.isLoading\n isValid=this.isValid\n isInvalid=this.isInvalid\n errors=this.errors\n dirty=this.dirty\n reset=this.reset\n Field=(component\n Field\n errors=this.errors\n formData=this.currentData\n disabled=@disabled\n validateOn=this.fieldValidateOn\n validateField=this.validateField\n )\n )\n to=\"default\"\n }}\n </form>\n </template>\n}\n\n/**\n * Converts validation type `Issues` from StandardValidator into a format\n * suitable for the form component, type `FormErrors`.\n *\n * For example, an issue with path `['email']` will be converted\n * to a form error for the field `email`, `{\"email\": \"error message\" }`.\n * Numeric path segments are kept, so an issue with path\n * `['items', 0, 'name']` becomes `{\"items.0.name\": \"error message\"}`.\n *\n * @param errors - The validation issues to convert.\n * @returns A mapping of field names to their validation error messages.\n */\nfunction validatorToFormErrors(errors: Issues): FormErrors {\n const formErrors: FormErrors = {};\n\n for (const issue of errors) {\n if (!issue.path || issue.path.length === 0) continue;\n\n // `issuePathToFieldName` is shared with\n // `StandardValidator.filterFieldIssues`, so the keys written here are\n // by construction the dotted names field lookup resolves against.\n const fieldName = issuePathToFieldName(issue);\n const message = issue.message;\n\n const existing = formErrors[fieldName];\n if (existing === undefined) {\n formErrors[fieldName] = message;\n } else if (Array.isArray(existing)) {\n existing.push(message);\n } else {\n formErrors[fieldName] = [existing, message];\n }\n }\n\n return formErrors;\n}\n\nexport {\n Form,\n type FormContext,\n type FormSignature,\n type FormDataCompiled,\n type FormResultData,\n type FormErrors\n};\nexport default Form;\n"],"names":["Form","Component","g","prototype","tracked","i","Set","element","ref","constructor","owner","args","data","initialDataSnapshot","flattenData","uncontrolledData","isValid","Object","keys","errors","length","isInvalid","isControlled","onChange","validateOn","fieldValidateOn","filter","e","currentData","validate","StandardValidator","validateAll","schema","formErrors","validatorToFormErrors","validateField","name","validateFieldAll","_","rest","n","action","computeDirtyFields","dirty","currentFlat","key","deepEqual","add","undefined","buildFormResultData","handleInput","event","form","currentTarget","HTMLFormElement","dataFrom","unflattenData","resultData","handleSubmit","preventDefault","isLoading","includes","onError","onSubmit","handleReset","restoredData","reset","current","setComponentTemplate","precompileTemplate","strictMode","scope","on","hash","Field","issue","path","fieldName","issuePathToFieldName","message","existing","Array","isArray","push"],"mappings":";;;;;;;;;;;;;;AAgJA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBC;AACD,MAAMA,IAAA,SAAmCC,UAAwB;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CAE9DC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAoB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,UAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAA,MAAA;AADrB;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAICC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA6B,EAAC;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,OAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAA,MAAA;AAD/B;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,kBAAA,EAAA,CAICC,OAAA,CAAA,CAAA;AAAA;EAAA,iBAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,kBAAA,CAAA,EAAA,MAAA;AADD;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,qBAAA,EAAA,CAOCC,OAAA,CAAA,CAAA;AAAA;EAAA,oBAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,qBAAA,CAAA,EAAA,MAAA;AAJD;;;AAGC;AAHD,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,OAAA,EAAA,CAWCC,OAAA,CAAA,EAAA,YAAA;MAAA,OAA6B,IAAIE,GAAA,EAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,MAAA,IA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AAU,CAAC4C,UAAU,GAAG,CAACG,QAAA,EAAUD,OAAA,CAAQ;AAC7C,IAAA;AACF,EAAA;AAEA,EAAA,OAAO9C,UAAA;AACT;;"}
1
+ {"version":3,"file":"form.js","sources":["../../../src/components/forms/form.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { hash } from '@ember/helper';\nimport { on } from '@ember/modifier';\nimport { ref } from '../../utils/ref';\nimport { dataFrom } from 'form-data-utils';\nimport {\n StandardValidator,\n issuePathToFieldName\n} from '../../utils/standard-validator';\nimport { flattenData, unflattenData, deepEqual } from '../../utils/nested-data';\nimport { Field } from './field';\n\nimport type { WithBoundArgs } from '@glint/template';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Issues, CustomValidatorFn } from '../../utils/standard-validator';\nimport type Owner from '@ember/owner';\n\n/** The form data as key/value pairs. */\ntype FormDataCompiled = ReturnType<typeof dataFrom>;\n/** The validation errors for the form, keyed by field name. */\ntype FormErrors = Record<string, string | string[] | undefined>;\n\n/**\n * The data passed to `onChange` and `onSubmit` callbacks, which is similar\n * to `FormContext` but also includes the form data.\n */\ntype FormResultData<T = FormDataCompiled> = {\n /** The form data as key/value pairs. */\n data: T;\n /** Whether the form is valid (i.e. has no validation errors). */\n isValid: boolean;\n /** Whether the form is invalid (i.e. has validation errors). */\n isInvalid: boolean;\n /** The current form validation errors. */\n errors: FormErrors;\n /**\n * The set of fields that have changed from their initial values.\n * For flat data structures: contains top-level keys (e.g., \"firstName\", \"email\")\n * For nested data structures: contains dotted paths (e.g., \"user.name.first\", \"profile.email\")\n */\n dirty: Set<string>;\n};\n\n/**\n * The context yielded to the default block of the `Form` component.\n */\ninterface FormContext<T = FormDataCompiled> {\n /** The form data as key/value pairs. */\n data?: T;\n /** Whether the form is currently submitting. */\n isLoading: boolean;\n /** Whether the form is valid (i.e. has no validation errors). */\n isValid: boolean;\n /** Whether the form is invalid (i.e. has validation errors). */\n isInvalid: boolean;\n /** The current form validation errors. */\n errors: FormErrors;\n /**\n * The set of fields that have changed from their initial values.\n * For flat data structures: contains top-level keys (e.g., \"firstName\", \"email\")\n * For nested data structures: contains dotted paths (e.g., \"user.name.first\", \"profile.email\")\n */\n dirty: Set<string>;\n /**\n * Resets the form to its initial state.\n * Clears all form fields, validation errors, and dirty tracking.\n */\n reset: () => void;\n /** The `Field` component, with args bound. */\n Field: WithBoundArgs<\n typeof Field,\n 'errors' | 'formData' | 'disabled' | 'validateOn' | 'validateField'\n >;\n}\n\ninterface FormSignature<T = FormDataCompiled> {\n Element: HTMLFormElement;\n Args: {\n /**\n * The standard schema to validate form data against.\n */\n schema?: StandardSchemaV1<T>;\n /**\n * Optional custom validation function. A custom validator should return\n * an array of Standard Schema issues, or `undefined` if there are none.\n * This function may be async or sync.\n */\n validate?: CustomValidatorFn<T>;\n /**\n * When to run validation.\n */\n validateOn?: ('change' | 'input' | 'blur' | 'submit')[];\n /**\n * The initial form data as key/value pairs.\n * This is primarily useful for setting default values in the form.\n * This object receives changes as the user interacts with the form.\n */\n data?: T;\n /**\n * Whether the entire form and all its fields should be disabled. This only\n * applies when using the yielded `Field` component.\n */\n disabled?: boolean;\n /**\n * Optional callback invoked on input changes within the form.\n * @param result - The current form result data.\n * @param event - The input event that triggered the change.\n * @returns A promise or void.\n */\n onChange?: (\n result: FormResultData<T>,\n event: Event\n ) => Promise<void> | void;\n /**\n * Callback invoked on form submission. If `onSubmit` returns a promise,\n * the form will be marked as `isLoading` until the promise resolves.\n * @param result - The current form result data.\n * @param event - The submit event that triggered the submission.\n * @returns A promise or void.\n */\n onSubmit: (\n result: FormResultData<T>,\n event: SubmitEvent\n ) => Promise<void> | void;\n /**\n * Optional callback invoked when validation errors occur on form submission.\n * @param errors - The validation errors found.\n * @param data - The form data that was validated.\n * @param event - The submit event that triggered the validation.\n * @returns A promise or void.\n */\n onError?: (\n errors: FormErrors,\n data: T,\n event: SubmitEvent\n ) => Promise<void> | void;\n };\n Blocks: {\n default: [FormContext<T>];\n };\n}\n\n/**\n * A form component that handles form submissions and input changes.\n *\n * @example\n * ```hbs\n * <Form\n * @data={{this.formData}}\n * @schema={{this.schema}}\n * @validate={{this.customValidator}}\n * @onSubmit={{this.onSubmit}}\n * @onChange={{this.onChange}}\n * as |form|\n * >\n * <form.Field name=\"firstName\" as |field|>\n * <field.Input />\n * </form.Field>\n * <form.Field name=\"lastName\" as |field|>\n * <field.Input />\n * </form.Field>\n * <Button type=\"submit\" @isLoading={{form.isLoading}}>\n * Submit\n * <:loading>Submitting...</:loading>\n * </Button>\n * </Form>\n * ```\n */\nclass Form<T = FormDataCompiled> extends Component<FormSignature<T>> {\n /** Whether the form is currently submitting. */\n @tracked isLoading = false;\n\n /** The current form validation errors. */\n @tracked errors: FormErrors = {};\n\n /** The current uncontrolled form data. */\n @tracked uncontrolledData?: T;\n\n /**\n * Flattened snapshot of initial data for dirty field comparison.\n * Stored in flattened form regardless of whether source data is nested or flat.\n */\n @tracked initialDataSnapshot?: Record<string, unknown>;\n\n /**\n * The set of fields that have changed from their initial values.\n * For flat data structures: contains top-level keys (e.g., \"firstName\", \"email\")\n * For nested data structures: contains dotted paths (e.g., \"user.name.first\", \"profile.email\")\n */\n @tracked dirty: Set<string> = new Set();\n\n /** Reference to the form element. */\n element = ref<HTMLFormElement>();\n\n /**\n * Creates a new instance of the Form component.\n * Initializes internal state based on provided args.\n * @param owner - The owner of the component.\n * @param args - The arguments passed to the component.\n */\n constructor(owner: Owner, args: FormSignature<T>['Args']) {\n super(owner, args);\n if (args.data) {\n this.initialDataSnapshot = flattenData(\n args.data as Record<string, unknown>\n );\n\n this.uncontrolledData = { ...args.data };\n }\n }\n\n /** Whether the form is valid (i.e. has no validation errors). */\n get isValid() {\n return Object.keys(this.errors).length === 0;\n }\n\n /** Whether the form is invalid (i.e. has validation errors). */\n get isInvalid() {\n return !this.isValid;\n }\n\n /** Whether the form is controlled (`onChange` is provided). */\n get isControlled(): boolean {\n return !!this.args.onChange;\n }\n\n /** The events on which validation should run. */\n get validateOn(): ('change' | 'input' | 'blur' | 'submit')[] {\n return this.args.validateOn ?? ['change', 'blur', 'submit'];\n }\n\n /** The events on which field-level validation should run. */\n get fieldValidateOn(): ('change' | 'input' | 'blur')[] {\n return this.validateOn.filter((e) => e !== 'submit');\n }\n\n /** The current form data, from args if controlled, or internal state if uncontrolled. */\n get currentData(): T | undefined {\n if (this.isControlled) {\n return this.args.data;\n }\n return this.uncontrolledData;\n }\n\n /**\n * Validates data against the provided schema using StandardValidator.\n * Updates the `errors` property with any validation errors found.\n *\n * @param data - The form data to validate.\n * @returns A promise that resolves to the validation errors, if any.\n */\n async validate(data: T): Promise<FormErrors | undefined> {\n const errors = await StandardValidator.validateAll(\n data,\n this.args.schema,\n this.args.validate\n );\n if (errors) {\n const formErrors = validatorToFormErrors(errors);\n this.errors = formErrors;\n return formErrors;\n }\n this.errors = {};\n }\n\n /**\n * Validates a single field against the provided schema using\n * StandardValidator. Updates the `errors` property with any validation\n * errors found for the field. If the field had previous errors but\n * is now valid, those errors are cleared.\n *\n * @param data - The form data to validate against.\n * @param name - The name of the field to validate.\n * @returns A promise that resolves to errors for the field, if any.\n */\n validateField = async (\n data: T,\n name: string\n ): Promise<FormErrors | undefined> => {\n if (!this.args.schema && !this.args.validate) {\n return;\n }\n const errors = await StandardValidator.validateFieldAll(\n data,\n name,\n this.args.schema,\n this.args.validate\n );\n if (errors) {\n const formErrors = validatorToFormErrors(errors);\n if (formErrors[name]) {\n this.errors = { ...this.errors, [name]: formErrors[name] };\n }\n return { [name]: formErrors[name] };\n }\n if (this.errors[name]) {\n const { [name]: _, ...rest } = this.errors;\n this.errors = rest;\n }\n };\n\n /**\n * Computes which fields have changed from their initial values.\n * Uses deep comparison for consistency across flat and nested structures.\n * This is a pure function with no side effects.\n *\n * @param data - The current form data.\n * @returns A set of field names that have changed.\n */\n computeDirtyFields(data: T): Set<string> {\n const dirty = new Set<string>();\n\n if (!this.initialDataSnapshot) {\n return dirty;\n }\n\n const currentFlat = flattenData(data as Record<string, unknown>);\n\n for (const key in currentFlat) {\n if (!deepEqual(currentFlat[key], this.initialDataSnapshot[key])) {\n dirty.add(key);\n }\n }\n\n for (const key in this.initialDataSnapshot) {\n if (\n !(key in currentFlat) &&\n this.initialDataSnapshot[key] !== undefined\n ) {\n dirty.add(key);\n }\n }\n\n return dirty;\n }\n\n /**\n * Builds the form result data object to pass to callbacks.\n * Also updates the dirty state as a side effect.\n *\n * @param data - The current form data.\n * @returns The form result data object.\n */\n buildFormResultData(data: T): FormResultData<T> {\n const { isValid, isInvalid, errors } = this;\n const dirty = this.computeDirtyFields(data);\n this.dirty = dirty;\n return {\n data,\n isValid,\n isInvalid,\n errors,\n dirty\n };\n }\n\n /**\n * Handles the `input` event on the form element.\n * Calls the `onChange` callback with the current form data if provided.\n * Automatically unflattens dotted field names to nested structure.\n */\n handleInput = (event: Event) => {\n const form = event.currentTarget;\n if (form instanceof HTMLFormElement) {\n let data = dataFrom(event) as T;\n data = unflattenData(data as Record<string, unknown>) as T;\n\n const resultData = this.buildFormResultData(data);\n this.uncontrolledData = data;\n this.args.onChange?.(resultData, event);\n }\n };\n\n /**\n * Handles the `submit` event on the form element.\n * Prevents the default form submission and calls the `onSubmit` callback\n * with the current form data. Manages the `isLoading` state during the\n * submission process. Automatically unflattens dotted field names to nested structure.\n */\n handleSubmit = async (event: SubmitEvent) => {\n event.preventDefault();\n const form = event.currentTarget;\n if (form instanceof HTMLFormElement) {\n this.isLoading = true;\n let data = dataFrom(event) as T;\n data = unflattenData(data as Record<string, unknown>) as T;\n\n let errors: FormErrors | undefined;\n if (this.validateOn.includes('submit')) {\n errors = await this.validate(data);\n }\n\n const resultData = this.buildFormResultData(data);\n this.uncontrolledData = data;\n try {\n if (errors && this.args.onError) {\n await this.args.onError(errors, data, event);\n } else if (!errors && this.args.onSubmit) {\n await this.args.onSubmit(resultData, event);\n this.initialDataSnapshot = flattenData(\n data as Record<string, unknown>\n );\n this.dirty = new Set();\n }\n } finally {\n this.isLoading = false;\n }\n }\n };\n\n /**\n * Handles the `reset` event on the form element.\n * Clears validation errors and dirty tracking.\n * Restores the form data to its initial state.\n * Calls `onChange` if the form is controlled to let parent update state.\n */\n handleReset = (event: Event) => {\n this.errors = {};\n this.dirty = new Set();\n\n if (this.initialDataSnapshot) {\n const restoredData = unflattenData(this.initialDataSnapshot) as T;\n\n if (this.isControlled && this.args.onChange) {\n const resultData = this.buildFormResultData(restoredData);\n\n this.args.onChange(resultData, event);\n } else {\n this.uncontrolledData = restoredData;\n }\n } else {\n this.uncontrolledData = undefined;\n }\n };\n\n /**\n * Resets the form to its initial state.\n * This method calls the native form reset() to clear all form controls,\n * triggering a `reset` event that is handled in `handleReset`.\n */\n reset = () => {\n this.element?.current?.reset();\n };\n\n <template>\n {{! @glint-nocheck component generics (field) trigger: type instantiation is excessively deep and possibly infinite }}\n <form\n {{this.element.setup}}\n {{on \"input\" this.handleInput}}\n {{on \"submit\" this.handleSubmit}}\n {{on \"reset\" this.handleReset}}\n ...attributes\n >\n {{yield\n (hash\n data=this.currentData\n isLoading=this.isLoading\n isValid=this.isValid\n isInvalid=this.isInvalid\n errors=this.errors\n dirty=this.dirty\n reset=this.reset\n Field=(component\n Field\n errors=this.errors\n formData=this.currentData\n disabled=@disabled\n validateOn=this.fieldValidateOn\n validateField=this.validateField\n )\n )\n to=\"default\"\n }}\n </form>\n </template>\n}\n\n/**\n * Converts validation type `Issues` from StandardValidator into a format\n * suitable for the form component, type `FormErrors`.\n *\n * For example, an issue with path `['email']` will be converted\n * to a form error for the field `email`, `{\"email\": \"error message\" }`.\n * Numeric path segments are kept, so an issue with path\n * `['items', 0, 'name']` becomes `{\"items.0.name\": \"error message\"}`.\n *\n * @param errors - The validation issues to convert.\n * @returns A mapping of field names to their validation error messages.\n */\nfunction validatorToFormErrors(errors: Issues): FormErrors {\n const formErrors: FormErrors = {};\n\n for (const issue of errors) {\n if (!issue.path || issue.path.length === 0) continue;\n\n // `issuePathToFieldName` is shared with\n // `StandardValidator.filterFieldIssues`, so the keys written here are\n // by construction the dotted names field lookup resolves against.\n const fieldName = issuePathToFieldName(issue);\n const message = issue.message;\n\n const existing = formErrors[fieldName];\n if (existing === undefined) {\n formErrors[fieldName] = message;\n } else if (Array.isArray(existing)) {\n existing.push(message);\n } else {\n formErrors[fieldName] = [existing, message];\n }\n }\n\n return formErrors;\n}\n\nexport {\n Form,\n type FormContext,\n type FormSignature,\n type FormDataCompiled,\n type FormResultData,\n type FormErrors\n};\nexport default Form;\n"],"names":["Form","Component","g","prototype","tracked","i","Set","element","ref","constructor","owner","args","data","initialDataSnapshot","flattenData","uncontrolledData","isValid","Object","keys","errors","length","isInvalid","isControlled","onChange","validateOn","fieldValidateOn","filter","e","currentData","validate","StandardValidator","validateAll","schema","formErrors","validatorToFormErrors","validateField","name","validateFieldAll","_","rest","computeDirtyFields","dirty","currentFlat","key","deepEqual","add","undefined","buildFormResultData","handleInput","event","form","currentTarget","HTMLFormElement","dataFrom","unflattenData","resultData","handleSubmit","preventDefault","isLoading","includes","onError","onSubmit","handleReset","restoredData","reset","current","setComponentTemplate","precompileTemplate","strictMode","scope","on","hash","Field","issue","path","fieldName","issuePathToFieldName","message","existing","Array","isArray","push"],"mappings":";;;;;;;;;;;;;AA+IA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBC;AACD,MAAMA,IAAA,SAAmCC,UAAwB;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CAE9DC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAoB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;EAAA,UAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAA,MAAA;AADrB;AAAA,EAAA;IAAAH,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAICC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA6B,EAAC;AAAA,IAAA,CAAA,CA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,MAAAA,QAAA,CAASG,IAAI,CAACJ,OAAA,CAAA;AAChB,IAAA,CAAA,MAAO;MACL5C,UAAU,CAAC0C,UAAU,GAAG,CAACG,QAAA,EAAUD,OAAA,CAAQ;AAC7C,IAAA;AACF,EAAA;AAEA,EAAA,OAAO5C,UAAA;AACT;;"}
@@ -16,7 +16,10 @@ export { RadioGroup } from './radio-group.js';
16
16
  export { FormControl } from './form-control.js';
17
17
  export { Switch } from './switch.js';
18
18
  export { DatePicker } from './date-picker/date-picker.js';
19
- export { formatValue, isEmptyValue, parseDate, parseRange, toWire } from './date-picker/value.js';
19
+ export { DEFAULT_TIME_FORMAT, formatValue, isEmptyValue, parseDate, parseRange, toWire, withTimeOf } from './date-picker/value.js';
20
+ export { BOUNDS, DEFAULT_FORMAT, applyDigit, applyLetter, buildParts, carryOver, clearSegment, commitSegment, daysInMonth, deleteDigit, displaySegment, emptySegment, findSegment, fromDate, hasDateChanged, hasTextualMonth, hourOfDay, hourOnCycle, isSegment, resolveSegmentFormat, resolveTwoDigitYear, step, timeOf, toDate, toNumericFormat, withTime, withValue } from './date-input/segments.js';
21
+ export { formatForClipboard, parsePasted, splitRange } from './date-input/clipboard.js';
22
+ export { DateInput } from './date-input/date-input.js';
20
23
  export { StandardValidator } from '../../utils/standard-validator.js';
21
- export { deepEqual, flattenData, hasNestedData, unflattenData } from '../../utils/nested-data.js';
24
+ export { deepEqual, flattenData, getPath, hasNestedData, unflattenData } from '../../utils/nested-data.js';
22
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,5 @@
1
1
  import Component from '@glimmer/component';
2
2
  import { tracked, cached } from '@glimmer/tracking';
3
- import { action } from '@ember/object';
4
3
  import { on } from '@ember/modifier';
5
4
  import { warn } from '@ember/debug';
6
5
  import { next } from '@ember/runloop';
@@ -285,25 +284,19 @@ class InputOtp extends Component {
285
284
  this.args.onComplete?.(next);
286
285
  }
287
286
  }
288
- handleOnInput(event) {
287
+ handleOnInput = event => {
289
288
  this.syncValue(event, 'input');
290
- }
291
- static {
292
- decorateMethodV2(this.prototype, "handleOnInput", [action]);
293
- }
294
- handleOnChange(event) {
289
+ };
290
+ handleOnChange = event => {
295
291
  this.syncValue(event, 'change');
296
- }
292
+ };
297
293
  /**
298
294
  * Maps the input's text caret onto discrete cells. A collapsed caret sits
299
295
  * between characters and so belongs to no cell; widening it to a
300
296
  * one-character range makes exactly one cell active and makes typing
301
297
  * overwrite rather than insert.
302
298
  */
303
- static {
304
- decorateMethodV2(this.prototype, "handleOnChange", [action]);
305
- }
306
- onSelectionChange() {
299
+ onSelectionChange = () => {
307
300
  const input = this.inputRef.current;
308
301
  if (!input || document.activeElement !== input) {
309
302
  return;
@@ -364,11 +357,8 @@ class InputOtp extends Component {
364
357
  this.selectionEnd = input.selectionEnd;
365
358
  }
366
359
  this.prevSelection = [input.selectionStart, input.selectionEnd];
367
- }
368
- static {
369
- decorateMethodV2(this.prototype, "onSelectionChange", [action]);
370
- }
371
- handleFocus() {
360
+ };
361
+ handleFocus = () => {
372
362
  this.isFocused = true;
373
363
  const input = this.inputRef.current;
374
364
  if (!input) {
@@ -378,20 +368,14 @@ class InputOtp extends Component {
378
368
  const start = Math.min(input.value.length, this.length - 1);
379
369
  input.setSelectionRange(start, input.value.length);
380
370
  this.onSelectionChange();
381
- }
382
- static {
383
- decorateMethodV2(this.prototype, "handleFocus", [action]);
384
- }
385
- handleOnBlur() {
371
+ };
372
+ handleOnBlur = () => {
386
373
  this.isFocused = false;
387
374
  this.selectionStart = null;
388
375
  this.selectionEnd = null;
389
376
  this.prevSelection = [null, null];
390
377
  this.args.onBlur?.();
391
- }
392
- static {
393
- decorateMethodV2(this.prototype, "handleOnBlur", [action]);
394
- }
378
+ };
395
379
  static {
396
380
  setComponentTemplate(precompileTemplate("<FormControl @size={{@size}} @label={{@label}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} data-component=\"input-otp\" data-part=\"base\" as |c|>\n {{!-- Chrome's translate feature rewrites the cell text nodes, wrapping\n them in <font> elements that Glimmer then tries to update. --}}\n <div class={{this.classes.container class=@classes.container}} data-part=\"container\" translate=\"no\">\n {{#each this.cellGroups key=\"@index\" as |group groupIndex|}}\n {{#if groupIndex}}\n <div class={{this.classes.separator class=@classes.separator}} data-part=\"separator\" aria-hidden=\"true\">{{this.separator}}</div>\n {{/if}}\n <div class={{this.classes.group class=@classes.group}} data-part=\"group\">\n {{#each group key=\"index\" as |cell|}}\n <div class={{this.classes.cell class=@classes.cell isActive=cell.isActive isInvalid=c.isInvalid isDisabled=@isDisabled}} data-part=\"cell\" data-active={{if cell.isActive \"true\"}} aria-hidden=\"true\">\n <span class={{this.classes.cellChar class=@classes.cellChar}} data-part=\"cell-char\">\n {{cell.displayChar}}\n </span>\n {{#if cell.hasFakeCaret}}\n {{!-- Never the only focus affordance -- under\n prefers-reduced-motion it stops blinking and reads as a\n static bar, so the active cell also rings. --}}\n <span class={{this.classes.caret class=@classes.caret}} data-part=\"caret\"></span>\n {{/if}}\n </div>\n {{/each}}\n </div>\n {{/each}}\n\n {{!-- False positive in no-unsupported-role-attributes\n (ember-template-lint 7.9.3). Its getImplicitRole helper matches an\n aria-query key on the type attribute alone and ignores that key's\n other constraints, so a plain text input resolves to the\n list-bearing combobox entry instead of textbox. This input has no\n list attribute, so textbox is its real implicit role, and textbox\n does support aria-placeholder. The rule is disabled for this\n element only, so its autofixer cannot silently delete\n aria-placeholder when someone runs pnpm lint:hbs --fix. See the\n @placeholder test in input-otp-test.gts. --}}\n {{!-- template-lint-disable no-unsupported-role-attributes --}}\n <input {{this.inputRef.setup}} {{this.syncFromValueArg @value}} {{on \"input\" this.handleOnInput}} {{on \"change\" this.handleOnChange}} {{on \"focus\" this.handleFocus}} {{on \"blur\" this.handleOnBlur}} id={{c.id}} name={{@name}} type=\"text\" maxlength={{this.length}} disabled={{@isDisabled}} class={{this.classes.input class=@classes.input}} data-part=\"input\" aria-invalid={{if c.isInvalid \"true\"}} aria-describedby={{c.describedBy @description c.isInvalid}} aria-placeholder={{@placeholder}} autocomplete=\"one-time-code\" inputmode={{this.inputMode}} pattern={{this.pattern.source}} autocapitalize={{this.autoCapitalize}} autocorrect=\"off\" spellcheck=\"false\" ...attributes />\n {{!-- template-lint-enable no-unsupported-role-attributes --}}\n </div>\n</FormControl>", {
397
381
  strictMode: true,
@@ -1 +1 @@
1
- {"version":3,"file":"input-otp.js","sources":["../../../src/components/forms/input-otp.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { cached, tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { on } from '@ember/modifier';\nimport { warn } from '@ember/debug';\nimport { next } from '@ember/runloop';\nimport { modifier } from 'ember-modifier';\nimport {\n useStyles,\n type InputOtpSlots,\n type InputOtpVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport { ref } from '../../utils/ref';\n\n/**\n * These must match PARTIAL values. A pattern anchored to the full length --\n * `/^\\d{6}$/` -- rejects the very first keystroke and makes the field\n * impossible to type into.\n */\nconst OTP_PATTERNS = {\n digits: /^\\d+$/,\n letters: /^[a-zA-Z]+$/,\n alphanumeric: /^[a-zA-Z0-9]+$/\n} as const;\n\ntype AllowedChars = keyof typeof OTP_PATTERNS;\n\n/**\n * The on-screen keyboard and autocapitalisation each character set implies.\n *\n * `tel` is deliberately not offered: its keypad carries `*`, `#` and pause\n * characters that every one of our patterns rejects.\n */\nconst OTP_INPUT_HINTS = {\n digits: { inputMode: 'numeric', autoCapitalize: 'off' },\n letters: { inputMode: 'text', autoCapitalize: 'characters' },\n alphanumeric: { inputMode: 'text', autoCapitalize: 'characters' }\n} as const satisfies Record<\n AllowedChars,\n { inputMode: 'numeric' | 'text'; autoCapitalize: 'off' | 'characters' }\n>;\n\ninterface Cell {\n index: number;\n /** What the cell actually draws: the character, a mask, or a placeholder. */\n displayChar: string | null;\n isActive: boolean;\n hasFakeCaret: boolean;\n}\n\ninterface Args extends FormControlSharedArgs {\n /**\n * How many characters the code has. Also the input's `maxlength`.\n *\n * @defaultValue 6\n */\n length?: number;\n\n /**\n * The name attribute of the underlying input, used when the code is\n * submitted as part of a form.\n */\n name?: string;\n\n /**\n * Which characters the code may contain. Also decides the on-screen keyboard\n * (`inputmode`) and autocapitalisation.\n *\n * @defaultValue 'digits'\n */\n allowedChars?: AllowedChars;\n\n /**\n * A custom character rule, overriding `allowedChars`. It is tested against\n * every intermediate value, so it must accept partial input: `/^\\d+$/`, not\n * `/^\\d{6}$/`.\n */\n pattern?: RegExp;\n\n /**\n * The size of the cells and the label.\n *\n * @defaultValue 'md'\n */\n size?: InputOtpVariants['size'];\n\n /**\n * Class names for each slot of the component, merged with the theme's.\n */\n classes?: SlotsToClasses<InputOtpSlots>;\n\n /**\n * The value of the input. Pair with `onInput` or `onChange` to control the\n * input; leave it unset to let the component track its own value.\n */\n value?: string;\n\n /**\n * Callback when oninput is triggered.\n */\n onInput?: (value: string, event?: Event) => void;\n\n /**\n * Callback when onchange is triggered.\n */\n onChange?: (value: string, event?: Event) => void;\n\n /**\n * Callback when onblur is triggered.\n */\n onBlur?: () => void;\n\n /**\n * Called when the code becomes complete. Fires on the transition from a\n * shorter value to exactly `length` characters, so re-rendering an already\n * full value does not fire it again.\n */\n onComplete?: (value: string) => void;\n\n /**\n * Splits the cells into visual groups, e.g. `[3, 3]` for a six-digit code.\n * Omit it for a single group. Entries that do not sum to `length` warn in\n * development; the groups then run out of cells or take a final group of the\n * remainder, so exactly `length` cells render either way.\n */\n groups?: number[];\n\n /**\n * The character shown between groups. Rendered `aria-hidden`, because the\n * value itself contains no separator.\n *\n * @defaultValue '–'\n */\n separator?: string;\n\n /**\n * Renders a bullet in place of each entered character. The real input's text\n * is already transparent, so this is purely what the cells draw -- the input\n * stays `type=\"text\"`, which `type=\"password\"` would break for autofill.\n *\n * @defaultValue false\n */\n isMasked?: boolean;\n\n /**\n * Characters shown in empty cells before anything is entered. Also exposed as\n * `aria-placeholder`.\n */\n placeholder?: string;\n}\n\ninterface InputOtpSignature {\n Args: Args;\n Element: HTMLInputElement;\n}\n\n/**\n * Ownership model, stated once.\n *\n * The `<input>` element is the source of truth for what the user typed -- the\n * browser guarantees that -- so a parent-owned `@value` is *written down into*\n * it (by `syncFromValueArg` and `reconcileWithParent`) rather than bound over\n * it with `value={{...}}`.\n *\n * That binding is what broke typing inside a `<Form>`. `elementValue` is\n * dirtied mid-dispatch and the template reads it (through `cellGroups`), so\n * Glimmer revalidates in a microtask that runs *between* event listeners --\n * rewriting the `value` attribute from a still-stale `@value` before the\n * `input` event had finished bubbling to the `<form>`, wiping the keystroke and\n * handing `<Form>` an empty value to store.\n *\n * The one invariant that keeps the mirror honest: every code path that writes\n * `element.value` goes through `writeValue`, which re-derives the selection\n * mirror straight afterwards.\n */\nclass InputOtp extends Component<InputOtpSignature> {\n /** What the element holds, and what the cells draw. */\n @tracked elementValue: string = this.args.value || '';\n\n @tracked isFocused = false;\n @tracked selectionStart: number | null = null;\n @tracked selectionEnd: number | null = null;\n\n /**\n * The previous selection. The selection API cannot tell us which side of a\n * character boundary the user meant, so direction is inferred by comparing\n * against where the caret was a moment ago.\n */\n prevSelection: [number | null, number | null] = [null, null];\n\n /**\n * `selectionchange` only fires on `document`, and capture phase keeps us\n * ahead of anything else listening.\n */\n inputRef = ref<HTMLInputElement>((element) => {\n if (element) {\n document.addEventListener('selectionchange', this.onSelectionChange, {\n capture: true\n });\n } else {\n document.removeEventListener('selectionchange', this.onSelectionChange, {\n capture: true\n });\n }\n });\n\n get length(): number {\n return this.args.length ?? 6;\n }\n\n get allowedChars(): AllowedChars {\n return this.args.allowedChars ?? 'digits';\n }\n\n get pattern(): RegExp {\n return this.args.pattern ?? OTP_PATTERNS[this.allowedChars];\n }\n\n get inputMode(): 'numeric' | 'text' {\n return OTP_INPUT_HINTS[this.allowedChars].inputMode;\n }\n\n get autoCapitalize(): 'off' | 'characters' {\n return OTP_INPUT_HINTS[this.allowedChars].autoCapitalize;\n }\n\n /**\n * The only way the element's value is ever written. Keeping the element, the\n * mirror of its value and the mirror of its selection in step here is what\n * lets every reader downstream just read them.\n */\n writeValue(element: HTMLInputElement, value: string): void {\n // Assigning to `value` resets the selection even when the string is\n // unchanged, so a redundant write is not merely wasteful.\n if (element.value !== value) {\n element.value = value;\n }\n\n // Deliberately unguarded: `syncFromValueArg` reaches here from inside a\n // modifier, and reading `elementValue` there would consume it into the same\n // computation that then writes it -- which Glimmer rejects outright.\n this.elementValue = value;\n\n // No browser fires `selectionchange` for a programmatic write (nor for a\n // deletion or a cut), so the mirror is re-derived by hand. It is a no-op\n // while the input is not focused, which is exactly right.\n this.onSelectionChange();\n }\n\n /**\n * Writes a parent-owned value down into the element. A modifier re-runs only\n * when its tracked arguments actually change, so a `@value` that is merely\n * lagging behind what the user typed never re-runs this and never clobbers a\n * keystroke.\n */\n syncFromValueArg = modifier(\n (element: HTMLInputElement, [value]: [string | undefined]) => {\n if (typeof value === 'string' && value !== element.value) {\n this.writeValue(element, value);\n }\n }\n );\n\n /**\n * Gives a controlled parent the last word on an edit -- but only once the\n * `input` (or `change`) event has finished travelling.\n *\n * A parent that has been told the new value and still holds a different one\n * has *rejected* it, and controlled semantics say its value wins. A parent\n * that has not caught up yet has not rejected anything, and the two are\n * indistinguishable from `@value` at the moment we notify: `<Form>` updates\n * its data from a handler on the `<form>` element, which runs after ours.\n * Waiting for the dispatch to finish is what separates them.\n */\n reconcileWithParent(element: HTMLInputElement, emitted: string): void {\n next(this, () => {\n if (this.isDestroying || this.isDestroyed) {\n return;\n }\n\n const { value } = this.args;\n\n // Anything typed since this was scheduled wins: it is a later edit, with\n // a reconciliation of its own already on its way.\n if (\n typeof value !== 'string' ||\n value === emitted ||\n element.value !== emitted\n ) {\n return;\n }\n\n this.writeValue(element, value);\n });\n }\n\n /** The selection mirror, kept in step by `writeValue`. */\n get mirroredSelection(): [number | null, number | null] {\n return [this.selectionStart, this.selectionEnd];\n }\n\n get separator(): string {\n return this.args.separator ?? '–';\n }\n\n /**\n * Cell counts per group. A mismatched `@groups` warns in development and\n * still renders `length` cells, so development and production behave the\n * same way.\n */\n get groupSizes(): number[] {\n const { groups } = this.args;\n\n if (!groups || groups.length === 0) {\n return [this.length];\n }\n\n const total = groups.reduce((sum, size) => sum + size, 0);\n\n if (total !== this.length) {\n warn(\n `<InputOtp>: @groups must sum to @length (${this.length}), got ${total}. ` +\n `Rendering ${this.length} cells and adjusting the groups to fit.`,\n false,\n { id: 'frontile.input-otp.groups-mismatch' }\n );\n }\n\n return groups;\n }\n\n get cellGroups(): Cell[][] {\n const value = this.elementValue;\n const cells: Cell[] = [];\n\n const [start, end] = this.mirroredSelection;\n\n for (let index = 0; index < this.length; index++) {\n const char = value[index] ?? null;\n // The placeholder is an all-or-nothing preview: it survives only while\n // nothing at all has been entered.\n const placeholderChar =\n value.length === 0 ? (this.args.placeholder?.[index] ?? null) : null;\n\n let displayChar: string | null = placeholderChar;\n if (char !== null) {\n displayChar = this.args.isMasked ? '•' : char;\n }\n\n // A range selection lights up every cell it covers -- that is correct,\n // not a bug.\n const isActive =\n this.isFocused &&\n start !== null &&\n end !== null &&\n ((start === end && index === start) || (index >= start && index < end));\n\n cells.push({\n index,\n displayChar,\n isActive,\n hasFakeCaret: isActive && char === null\n });\n }\n\n // `slice` clamps on its own, so a `@groups` that overshoots simply runs out\n // of cells; anything left over becomes a final group. Either way exactly\n // `length` cells render.\n const groups: Cell[][] = [];\n let offset = 0;\n\n for (const size of this.groupSizes) {\n if (offset >= cells.length) {\n break;\n }\n if (size <= 0) {\n continue;\n }\n groups.push(cells.slice(offset, offset + size));\n offset += size;\n }\n\n if (offset < cells.length) {\n groups.push(cells.slice(offset));\n }\n\n return groups;\n }\n\n @cached\n get classes() {\n const { inputOtp } = useStyles();\n return inputOtp({ size: this.args.size });\n }\n\n /**\n * Both `input` and `change` funnel through here so the element, our mirror of\n * it, and the parent never disagree about the value.\n */\n syncValue(event: Event, notify: 'input' | 'change'): void {\n const element = event.target as HTMLInputElement;\n const next = element.value.slice(0, this.length);\n\n // The value as it stood before this edit, read before anything is mutated.\n const previous = this.elementValue;\n\n // All-or-nothing: a value that fails the rule is dropped whole rather than\n // filtered, so a pasted \"123-456\" never silently becomes \"123456\".\n if (next.length > 0 && !this.pattern.test(next)) {\n this.writeValue(element, previous);\n return;\n }\n\n this.writeValue(element, next);\n\n // Only a parent that was actually told gets a say in the reconciliation --\n // an `@onChange`-only parent is not credited with knowing about an `input`\n // it never heard.\n const notifyParent =\n notify === 'input' ? this.args.onInput : this.args.onChange;\n\n if (notifyParent) {\n notifyParent(next, event);\n this.reconcileWithParent(element, next);\n }\n\n if (\n next !== previous &&\n previous.length < this.length &&\n next.length === this.length\n ) {\n this.args.onComplete?.(next);\n }\n }\n\n @action handleOnInput(event: Event): void {\n this.syncValue(event, 'input');\n }\n\n @action handleOnChange(event: Event): void {\n this.syncValue(event, 'change');\n }\n\n /**\n * Maps the input's text caret onto discrete cells. A collapsed caret sits\n * between characters and so belongs to no cell; widening it to a\n * one-character range makes exactly one cell active and makes typing\n * overwrite rather than insert.\n */\n @action onSelectionChange(): void {\n const input = this.inputRef.current;\n if (!input || document.activeElement !== input) {\n return;\n }\n\n const value = input.value;\n const maxLength = this.length;\n const caretStart = input.selectionStart;\n const caretEnd = input.selectionEnd;\n\n if (caretStart === null || caretEnd === null) {\n return;\n }\n\n let start = -1;\n let end = -1;\n let direction: 'forward' | 'backward' | 'none' =\n input.selectionDirection ?? 'none';\n\n const isSingleCaret = caretStart === caretEnd;\n // Appending to a not-yet-full code: leave the caret collapsed, or the next\n // keystroke would replace the character before it instead of adding one.\n const isInsertMode =\n caretStart === value.length && value.length < maxLength;\n\n if (isSingleCaret && !isInsertMode) {\n const caret = caretStart;\n\n if (caret === 0) {\n start = 0;\n end = 1;\n direction = 'forward';\n } else if (caret === maxLength) {\n start = caret - 1;\n end = caret;\n direction = 'backward';\n } else if (maxLength > 1 && value.length > 1) {\n let offset = 0;\n const [prevStart, prevEnd] = this.prevSelection;\n\n if (prevStart !== null && prevEnd !== null) {\n direction = caret < prevEnd ? 'backward' : 'forward';\n const wasInserting = prevStart === prevEnd && prevStart < maxLength;\n // Without this, ArrowLeft appears to skip a cell -- except when\n // leaving append mode, where the shift would overshoot.\n if (direction === 'backward' && !wasInserting) {\n offset = -1;\n }\n }\n\n start = offset + caret;\n end = offset + caret + 1;\n }\n }\n\n if (start !== -1 && end !== -1 && start !== end) {\n input.setSelectionRange(start, end, direction);\n }\n\n // `selectionchange` fires several times per keystroke; writing an identical\n // value would still dirty the tag and rebuild every cell. The comparison\n // goes through the untracked `prevSelection`, which holds exactly what was\n // last mirrored -- reading the tracked fields here would consume them into\n // the modifier computation that `writeValue` calls this from.\n const [lastStart, lastEnd] = this.prevSelection;\n\n if (lastStart !== input.selectionStart) {\n this.selectionStart = input.selectionStart;\n }\n\n if (lastEnd !== input.selectionEnd) {\n this.selectionEnd = input.selectionEnd;\n }\n\n this.prevSelection = [input.selectionStart, input.selectionEnd];\n }\n\n @action handleFocus(): void {\n this.isFocused = true;\n\n const input = this.inputRef.current;\n if (!input) {\n return;\n }\n\n // Park on the last cell rather than past the end of a full code.\n const start = Math.min(input.value.length, this.length - 1);\n input.setSelectionRange(start, input.value.length);\n this.onSelectionChange();\n }\n\n @action handleOnBlur(): void {\n this.isFocused = false;\n this.selectionStart = null;\n this.selectionEnd = null;\n this.prevSelection = [null, null];\n this.args.onBlur?.();\n }\n\n <template>\n <FormControl\n @size={{@size}}\n @label={{@label}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n @class={{this.classes.base class=@classes.base}}\n data-component=\"input-otp\"\n data-part=\"base\"\n as |c|\n >\n {{! Chrome's translate feature rewrites the cell text nodes, wrapping\n them in <font> elements that Glimmer then tries to update. }}\n <div\n class={{this.classes.container class=@classes.container}}\n data-part=\"container\"\n translate=\"no\"\n >\n {{#each this.cellGroups key=\"@index\" as |group groupIndex|}}\n {{#if groupIndex}}\n <div\n class={{this.classes.separator class=@classes.separator}}\n data-part=\"separator\"\n aria-hidden=\"true\"\n >{{this.separator}}</div>\n {{/if}}\n <div\n class={{this.classes.group class=@classes.group}}\n data-part=\"group\"\n >\n {{#each group key=\"index\" as |cell|}}\n <div\n class={{this.classes.cell\n class=@classes.cell\n isActive=cell.isActive\n isInvalid=c.isInvalid\n isDisabled=@isDisabled\n }}\n data-part=\"cell\"\n data-active={{if cell.isActive \"true\"}}\n aria-hidden=\"true\"\n >\n <span\n class={{this.classes.cellChar class=@classes.cellChar}}\n data-part=\"cell-char\"\n >\n {{cell.displayChar}}\n </span>\n {{#if cell.hasFakeCaret}}\n {{! Never the only focus affordance -- under\n prefers-reduced-motion it stops blinking and reads as a\n static bar, so the active cell also rings. }}\n <span\n class={{this.classes.caret class=@classes.caret}}\n data-part=\"caret\"\n ></span>\n {{/if}}\n </div>\n {{/each}}\n </div>\n {{/each}}\n\n {{! False positive in no-unsupported-role-attributes\n (ember-template-lint 7.9.3). Its getImplicitRole helper matches an\n aria-query key on the type attribute alone and ignores that key's\n other constraints, so a plain text input resolves to the\n list-bearing combobox entry instead of textbox. This input has no\n list attribute, so textbox is its real implicit role, and textbox\n does support aria-placeholder. The rule is disabled for this\n element only, so its autofixer cannot silently delete\n aria-placeholder when someone runs pnpm lint:hbs --fix. See the\n @placeholder test in input-otp-test.gts. }}\n {{! template-lint-disable no-unsupported-role-attributes }}\n <input\n {{this.inputRef.setup}}\n {{this.syncFromValueArg @value}}\n {{on \"input\" this.handleOnInput}}\n {{on \"change\" this.handleOnChange}}\n {{on \"focus\" this.handleFocus}}\n {{on \"blur\" this.handleOnBlur}}\n id={{c.id}}\n name={{@name}}\n type=\"text\"\n maxlength={{this.length}}\n disabled={{@isDisabled}}\n class={{this.classes.input class=@classes.input}}\n data-part=\"input\"\n aria-invalid={{if c.isInvalid \"true\"}}\n aria-describedby={{c.describedBy @description c.isInvalid}}\n aria-placeholder={{@placeholder}}\n autocomplete=\"one-time-code\"\n inputmode={{this.inputMode}}\n pattern={{this.pattern.source}}\n autocapitalize={{this.autoCapitalize}}\n autocorrect=\"off\"\n spellcheck=\"false\"\n ...attributes\n />\n {{! template-lint-enable no-unsupported-role-attributes }}\n </div>\n </FormControl>\n </template>\n}\n\nexport { InputOtp, type InputOtpSignature };\nexport default InputOtp;\n"],"names":["OTP_PATTERNS","digits","letters","alphanumeric","OTP_INPUT_HINTS","inputMode","autoCapitalize","InputOtp","Component","g","prototype","tracked","args","value","i","prevSelection","inputRef","ref","element","document","addEventListener","onSelectionChange","capture","removeEventListener","length","allowedChars","pattern","writeValue","elementValue","syncFromValueArg","modifier","reconcileWithParent","emitted","next","isDestroying","isDestroyed","mirroredSelection","selectionStart","selectionEnd","separator","groupSizes","groups","total","reduce","sum","size","warn","id","cellGroups","cells","start","end","index","char","placeholderChar","placeholder","displayChar","isMasked","isActive","isFocused","push","hasFakeCaret","offset","slice","classes","inputOtp","useStyles","n","cached","syncValue","event","notify","target","previous","test","notifyParent","onInput","onChange","onComplete","handleOnInput","action","handleOnChange","input","current","activeElement","maxLength","caretStart","caretEnd","direction","selectionDirection","isSingleCaret","isInsertMode","caret","prevStart","prevEnd","wasInserting","setSelectionRange","lastStart","lastEnd","handleFocus","Math","min","handleOnBlur","onBlur","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","on"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAMA,YAAA,GAAe;AACnBC,EAAAA,MAAA,EAAQ,OAAA;AACRC,EAAAA,OAAA,EAAS,aAAA;AACTC,EAAAA,YAAA,EAAc;AAChB,CAAA;AAIA;;;;;AAKC;AACD,MAAMC,eAAA,GAAkB;AACtBH,EAAAA,MA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C,gBAAA,CAAA,IAAA,CAAAzD,SAAA,EAAA,cAAA,EAAA,CANCsE,MAAA,CAAA,CAAA;AAAA;AAQD,EAAA;IAAAwB,oBAAA,CAAAC,kBAAA,CAAA,6qGAAA,EAuGA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
1
+ {"version":3,"file":"input-otp.js","sources":["../../../src/components/forms/input-otp.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { cached, tracked } from '@glimmer/tracking';\nimport { on } from '@ember/modifier';\nimport { warn } from '@ember/debug';\nimport { next } from '@ember/runloop';\nimport { modifier } from 'ember-modifier';\nimport {\n useStyles,\n type InputOtpSlots,\n type InputOtpVariants,\n type SlotsToClasses\n} from '@frontile/theme';\nimport { FormControl, type FormControlSharedArgs } from './form-control';\nimport { ref } from '../../utils/ref';\n\n/**\n * These must match PARTIAL values. A pattern anchored to the full length --\n * `/^\\d{6}$/` -- rejects the very first keystroke and makes the field\n * impossible to type into.\n */\nconst OTP_PATTERNS = {\n digits: /^\\d+$/,\n letters: /^[a-zA-Z]+$/,\n alphanumeric: /^[a-zA-Z0-9]+$/\n} as const;\n\ntype AllowedChars = keyof typeof OTP_PATTERNS;\n\n/**\n * The on-screen keyboard and autocapitalisation each character set implies.\n *\n * `tel` is deliberately not offered: its keypad carries `*`, `#` and pause\n * characters that every one of our patterns rejects.\n */\nconst OTP_INPUT_HINTS = {\n digits: { inputMode: 'numeric', autoCapitalize: 'off' },\n letters: { inputMode: 'text', autoCapitalize: 'characters' },\n alphanumeric: { inputMode: 'text', autoCapitalize: 'characters' }\n} as const satisfies Record<\n AllowedChars,\n { inputMode: 'numeric' | 'text'; autoCapitalize: 'off' | 'characters' }\n>;\n\ninterface Cell {\n index: number;\n /** What the cell actually draws: the character, a mask, or a placeholder. */\n displayChar: string | null;\n isActive: boolean;\n hasFakeCaret: boolean;\n}\n\ninterface Args extends FormControlSharedArgs {\n /**\n * How many characters the code has. Also the input's `maxlength`.\n *\n * @defaultValue 6\n */\n length?: number;\n\n /**\n * The name attribute of the underlying input, used when the code is\n * submitted as part of a form.\n */\n name?: string;\n\n /**\n * Which characters the code may contain. Also decides the on-screen keyboard\n * (`inputmode`) and autocapitalisation.\n *\n * @defaultValue 'digits'\n */\n allowedChars?: AllowedChars;\n\n /**\n * A custom character rule, overriding `allowedChars`. It is tested against\n * every intermediate value, so it must accept partial input: `/^\\d+$/`, not\n * `/^\\d{6}$/`.\n */\n pattern?: RegExp;\n\n /**\n * The size of the cells and the label.\n *\n * @defaultValue 'md'\n */\n size?: InputOtpVariants['size'];\n\n /**\n * Class names for each slot of the component, merged with the theme's.\n */\n classes?: SlotsToClasses<InputOtpSlots>;\n\n /**\n * The value of the input. Pair with `onInput` or `onChange` to control the\n * input; leave it unset to let the component track its own value.\n */\n value?: string;\n\n /**\n * Callback when oninput is triggered.\n */\n onInput?: (value: string, event?: Event) => void;\n\n /**\n * Callback when onchange is triggered.\n */\n onChange?: (value: string, event?: Event) => void;\n\n /**\n * Callback when onblur is triggered.\n */\n onBlur?: () => void;\n\n /**\n * Called when the code becomes complete. Fires on the transition from a\n * shorter value to exactly `length` characters, so re-rendering an already\n * full value does not fire it again.\n */\n onComplete?: (value: string) => void;\n\n /**\n * Splits the cells into visual groups, e.g. `[3, 3]` for a six-digit code.\n * Omit it for a single group. Entries that do not sum to `length` warn in\n * development; the groups then run out of cells or take a final group of the\n * remainder, so exactly `length` cells render either way.\n */\n groups?: number[];\n\n /**\n * The character shown between groups. Rendered `aria-hidden`, because the\n * value itself contains no separator.\n *\n * @defaultValue '–'\n */\n separator?: string;\n\n /**\n * Renders a bullet in place of each entered character. The real input's text\n * is already transparent, so this is purely what the cells draw -- the input\n * stays `type=\"text\"`, which `type=\"password\"` would break for autofill.\n *\n * @defaultValue false\n */\n isMasked?: boolean;\n\n /**\n * Characters shown in empty cells before anything is entered. Also exposed as\n * `aria-placeholder`.\n */\n placeholder?: string;\n}\n\ninterface InputOtpSignature {\n Args: Args;\n Element: HTMLInputElement;\n}\n\n/**\n * Ownership model, stated once.\n *\n * The `<input>` element is the source of truth for what the user typed -- the\n * browser guarantees that -- so a parent-owned `@value` is *written down into*\n * it (by `syncFromValueArg` and `reconcileWithParent`) rather than bound over\n * it with `value={{...}}`.\n *\n * That binding is what broke typing inside a `<Form>`. `elementValue` is\n * dirtied mid-dispatch and the template reads it (through `cellGroups`), so\n * Glimmer revalidates in a microtask that runs *between* event listeners --\n * rewriting the `value` attribute from a still-stale `@value` before the\n * `input` event had finished bubbling to the `<form>`, wiping the keystroke and\n * handing `<Form>` an empty value to store.\n *\n * The one invariant that keeps the mirror honest: every code path that writes\n * `element.value` goes through `writeValue`, which re-derives the selection\n * mirror straight afterwards.\n */\nclass InputOtp extends Component<InputOtpSignature> {\n /** What the element holds, and what the cells draw. */\n @tracked elementValue: string = this.args.value || '';\n\n @tracked isFocused = false;\n @tracked selectionStart: number | null = null;\n @tracked selectionEnd: number | null = null;\n\n /**\n * The previous selection. The selection API cannot tell us which side of a\n * character boundary the user meant, so direction is inferred by comparing\n * against where the caret was a moment ago.\n */\n prevSelection: [number | null, number | null] = [null, null];\n\n /**\n * `selectionchange` only fires on `document`, and capture phase keeps us\n * ahead of anything else listening.\n */\n inputRef = ref<HTMLInputElement>((element) => {\n if (element) {\n document.addEventListener('selectionchange', this.onSelectionChange, {\n capture: true\n });\n } else {\n document.removeEventListener('selectionchange', this.onSelectionChange, {\n capture: true\n });\n }\n });\n\n get length(): number {\n return this.args.length ?? 6;\n }\n\n get allowedChars(): AllowedChars {\n return this.args.allowedChars ?? 'digits';\n }\n\n get pattern(): RegExp {\n return this.args.pattern ?? OTP_PATTERNS[this.allowedChars];\n }\n\n get inputMode(): 'numeric' | 'text' {\n return OTP_INPUT_HINTS[this.allowedChars].inputMode;\n }\n\n get autoCapitalize(): 'off' | 'characters' {\n return OTP_INPUT_HINTS[this.allowedChars].autoCapitalize;\n }\n\n /**\n * The only way the element's value is ever written. Keeping the element, the\n * mirror of its value and the mirror of its selection in step here is what\n * lets every reader downstream just read them.\n */\n writeValue(element: HTMLInputElement, value: string): void {\n // Assigning to `value` resets the selection even when the string is\n // unchanged, so a redundant write is not merely wasteful.\n if (element.value !== value) {\n element.value = value;\n }\n\n // Deliberately unguarded: `syncFromValueArg` reaches here from inside a\n // modifier, and reading `elementValue` there would consume it into the same\n // computation that then writes it -- which Glimmer rejects outright.\n this.elementValue = value;\n\n // No browser fires `selectionchange` for a programmatic write (nor for a\n // deletion or a cut), so the mirror is re-derived by hand. It is a no-op\n // while the input is not focused, which is exactly right.\n this.onSelectionChange();\n }\n\n /**\n * Writes a parent-owned value down into the element. A modifier re-runs only\n * when its tracked arguments actually change, so a `@value` that is merely\n * lagging behind what the user typed never re-runs this and never clobbers a\n * keystroke.\n */\n syncFromValueArg = modifier(\n (element: HTMLInputElement, [value]: [string | undefined]) => {\n if (typeof value === 'string' && value !== element.value) {\n this.writeValue(element, value);\n }\n }\n );\n\n /**\n * Gives a controlled parent the last word on an edit -- but only once the\n * `input` (or `change`) event has finished travelling.\n *\n * A parent that has been told the new value and still holds a different one\n * has *rejected* it, and controlled semantics say its value wins. A parent\n * that has not caught up yet has not rejected anything, and the two are\n * indistinguishable from `@value` at the moment we notify: `<Form>` updates\n * its data from a handler on the `<form>` element, which runs after ours.\n * Waiting for the dispatch to finish is what separates them.\n */\n reconcileWithParent(element: HTMLInputElement, emitted: string): void {\n next(this, () => {\n if (this.isDestroying || this.isDestroyed) {\n return;\n }\n\n const { value } = this.args;\n\n // Anything typed since this was scheduled wins: it is a later edit, with\n // a reconciliation of its own already on its way.\n if (\n typeof value !== 'string' ||\n value === emitted ||\n element.value !== emitted\n ) {\n return;\n }\n\n this.writeValue(element, value);\n });\n }\n\n /** The selection mirror, kept in step by `writeValue`. */\n get mirroredSelection(): [number | null, number | null] {\n return [this.selectionStart, this.selectionEnd];\n }\n\n get separator(): string {\n return this.args.separator ?? '–';\n }\n\n /**\n * Cell counts per group. A mismatched `@groups` warns in development and\n * still renders `length` cells, so development and production behave the\n * same way.\n */\n get groupSizes(): number[] {\n const { groups } = this.args;\n\n if (!groups || groups.length === 0) {\n return [this.length];\n }\n\n const total = groups.reduce((sum, size) => sum + size, 0);\n\n if (total !== this.length) {\n warn(\n `<InputOtp>: @groups must sum to @length (${this.length}), got ${total}. ` +\n `Rendering ${this.length} cells and adjusting the groups to fit.`,\n false,\n { id: 'frontile.input-otp.groups-mismatch' }\n );\n }\n\n return groups;\n }\n\n get cellGroups(): Cell[][] {\n const value = this.elementValue;\n const cells: Cell[] = [];\n\n const [start, end] = this.mirroredSelection;\n\n for (let index = 0; index < this.length; index++) {\n const char = value[index] ?? null;\n // The placeholder is an all-or-nothing preview: it survives only while\n // nothing at all has been entered.\n const placeholderChar =\n value.length === 0 ? (this.args.placeholder?.[index] ?? null) : null;\n\n let displayChar: string | null = placeholderChar;\n if (char !== null) {\n displayChar = this.args.isMasked ? '•' : char;\n }\n\n // A range selection lights up every cell it covers -- that is correct,\n // not a bug.\n const isActive =\n this.isFocused &&\n start !== null &&\n end !== null &&\n ((start === end && index === start) || (index >= start && index < end));\n\n cells.push({\n index,\n displayChar,\n isActive,\n hasFakeCaret: isActive && char === null\n });\n }\n\n // `slice` clamps on its own, so a `@groups` that overshoots simply runs out\n // of cells; anything left over becomes a final group. Either way exactly\n // `length` cells render.\n const groups: Cell[][] = [];\n let offset = 0;\n\n for (const size of this.groupSizes) {\n if (offset >= cells.length) {\n break;\n }\n if (size <= 0) {\n continue;\n }\n groups.push(cells.slice(offset, offset + size));\n offset += size;\n }\n\n if (offset < cells.length) {\n groups.push(cells.slice(offset));\n }\n\n return groups;\n }\n\n @cached\n get classes() {\n const { inputOtp } = useStyles();\n return inputOtp({ size: this.args.size });\n }\n\n /**\n * Both `input` and `change` funnel through here so the element, our mirror of\n * it, and the parent never disagree about the value.\n */\n syncValue(event: Event, notify: 'input' | 'change'): void {\n const element = event.target as HTMLInputElement;\n const next = element.value.slice(0, this.length);\n\n // The value as it stood before this edit, read before anything is mutated.\n const previous = this.elementValue;\n\n // All-or-nothing: a value that fails the rule is dropped whole rather than\n // filtered, so a pasted \"123-456\" never silently becomes \"123456\".\n if (next.length > 0 && !this.pattern.test(next)) {\n this.writeValue(element, previous);\n return;\n }\n\n this.writeValue(element, next);\n\n // Only a parent that was actually told gets a say in the reconciliation --\n // an `@onChange`-only parent is not credited with knowing about an `input`\n // it never heard.\n const notifyParent =\n notify === 'input' ? this.args.onInput : this.args.onChange;\n\n if (notifyParent) {\n notifyParent(next, event);\n this.reconcileWithParent(element, next);\n }\n\n if (\n next !== previous &&\n previous.length < this.length &&\n next.length === this.length\n ) {\n this.args.onComplete?.(next);\n }\n }\n\n handleOnInput = (event: Event): void => {\n this.syncValue(event, 'input');\n };\n\n handleOnChange = (event: Event): void => {\n this.syncValue(event, 'change');\n };\n\n /**\n * Maps the input's text caret onto discrete cells. A collapsed caret sits\n * between characters and so belongs to no cell; widening it to a\n * one-character range makes exactly one cell active and makes typing\n * overwrite rather than insert.\n */\n onSelectionChange = (): void => {\n const input = this.inputRef.current;\n if (!input || document.activeElement !== input) {\n return;\n }\n\n const value = input.value;\n const maxLength = this.length;\n const caretStart = input.selectionStart;\n const caretEnd = input.selectionEnd;\n\n if (caretStart === null || caretEnd === null) {\n return;\n }\n\n let start = -1;\n let end = -1;\n let direction: 'forward' | 'backward' | 'none' =\n input.selectionDirection ?? 'none';\n\n const isSingleCaret = caretStart === caretEnd;\n // Appending to a not-yet-full code: leave the caret collapsed, or the next\n // keystroke would replace the character before it instead of adding one.\n const isInsertMode =\n caretStart === value.length && value.length < maxLength;\n\n if (isSingleCaret && !isInsertMode) {\n const caret = caretStart;\n\n if (caret === 0) {\n start = 0;\n end = 1;\n direction = 'forward';\n } else if (caret === maxLength) {\n start = caret - 1;\n end = caret;\n direction = 'backward';\n } else if (maxLength > 1 && value.length > 1) {\n let offset = 0;\n const [prevStart, prevEnd] = this.prevSelection;\n\n if (prevStart !== null && prevEnd !== null) {\n direction = caret < prevEnd ? 'backward' : 'forward';\n const wasInserting = prevStart === prevEnd && prevStart < maxLength;\n // Without this, ArrowLeft appears to skip a cell -- except when\n // leaving append mode, where the shift would overshoot.\n if (direction === 'backward' && !wasInserting) {\n offset = -1;\n }\n }\n\n start = offset + caret;\n end = offset + caret + 1;\n }\n }\n\n if (start !== -1 && end !== -1 && start !== end) {\n input.setSelectionRange(start, end, direction);\n }\n\n // `selectionchange` fires several times per keystroke; writing an identical\n // value would still dirty the tag and rebuild every cell. The comparison\n // goes through the untracked `prevSelection`, which holds exactly what was\n // last mirrored -- reading the tracked fields here would consume them into\n // the modifier computation that `writeValue` calls this from.\n const [lastStart, lastEnd] = this.prevSelection;\n\n if (lastStart !== input.selectionStart) {\n this.selectionStart = input.selectionStart;\n }\n\n if (lastEnd !== input.selectionEnd) {\n this.selectionEnd = input.selectionEnd;\n }\n\n this.prevSelection = [input.selectionStart, input.selectionEnd];\n };\n\n handleFocus = (): void => {\n this.isFocused = true;\n\n const input = this.inputRef.current;\n if (!input) {\n return;\n }\n\n // Park on the last cell rather than past the end of a full code.\n const start = Math.min(input.value.length, this.length - 1);\n input.setSelectionRange(start, input.value.length);\n this.onSelectionChange();\n };\n\n handleOnBlur = (): void => {\n this.isFocused = false;\n this.selectionStart = null;\n this.selectionEnd = null;\n this.prevSelection = [null, null];\n this.args.onBlur?.();\n };\n\n <template>\n <FormControl\n @size={{@size}}\n @label={{@label}}\n @isRequired={{@isRequired}}\n @description={{@description}}\n @errors={{@errors}}\n @isInvalid={{@isInvalid}}\n @class={{this.classes.base class=@classes.base}}\n data-component=\"input-otp\"\n data-part=\"base\"\n as |c|\n >\n {{! Chrome's translate feature rewrites the cell text nodes, wrapping\n them in <font> elements that Glimmer then tries to update. }}\n <div\n class={{this.classes.container class=@classes.container}}\n data-part=\"container\"\n translate=\"no\"\n >\n {{#each this.cellGroups key=\"@index\" as |group groupIndex|}}\n {{#if groupIndex}}\n <div\n class={{this.classes.separator class=@classes.separator}}\n data-part=\"separator\"\n aria-hidden=\"true\"\n >{{this.separator}}</div>\n {{/if}}\n <div\n class={{this.classes.group class=@classes.group}}\n data-part=\"group\"\n >\n {{#each group key=\"index\" as |cell|}}\n <div\n class={{this.classes.cell\n class=@classes.cell\n isActive=cell.isActive\n isInvalid=c.isInvalid\n isDisabled=@isDisabled\n }}\n data-part=\"cell\"\n data-active={{if cell.isActive \"true\"}}\n aria-hidden=\"true\"\n >\n <span\n class={{this.classes.cellChar class=@classes.cellChar}}\n data-part=\"cell-char\"\n >\n {{cell.displayChar}}\n </span>\n {{#if cell.hasFakeCaret}}\n {{! Never the only focus affordance -- under\n prefers-reduced-motion it stops blinking and reads as a\n static bar, so the active cell also rings. }}\n <span\n class={{this.classes.caret class=@classes.caret}}\n data-part=\"caret\"\n ></span>\n {{/if}}\n </div>\n {{/each}}\n </div>\n {{/each}}\n\n {{! False positive in no-unsupported-role-attributes\n (ember-template-lint 7.9.3). Its getImplicitRole helper matches an\n aria-query key on the type attribute alone and ignores that key's\n other constraints, so a plain text input resolves to the\n list-bearing combobox entry instead of textbox. This input has no\n list attribute, so textbox is its real implicit role, and textbox\n does support aria-placeholder. The rule is disabled for this\n element only, so its autofixer cannot silently delete\n aria-placeholder when someone runs pnpm lint:hbs --fix. See the\n @placeholder test in input-otp-test.gts. }}\n {{! template-lint-disable no-unsupported-role-attributes }}\n <input\n {{this.inputRef.setup}}\n {{this.syncFromValueArg @value}}\n {{on \"input\" this.handleOnInput}}\n {{on \"change\" this.handleOnChange}}\n {{on \"focus\" this.handleFocus}}\n {{on \"blur\" this.handleOnBlur}}\n id={{c.id}}\n name={{@name}}\n type=\"text\"\n maxlength={{this.length}}\n disabled={{@isDisabled}}\n class={{this.classes.input class=@classes.input}}\n data-part=\"input\"\n aria-invalid={{if c.isInvalid \"true\"}}\n aria-describedby={{c.describedBy @description c.isInvalid}}\n aria-placeholder={{@placeholder}}\n autocomplete=\"one-time-code\"\n inputmode={{this.inputMode}}\n pattern={{this.pattern.source}}\n autocapitalize={{this.autoCapitalize}}\n autocorrect=\"off\"\n spellcheck=\"false\"\n ...attributes\n />\n {{! template-lint-enable no-unsupported-role-attributes }}\n </div>\n </FormControl>\n </template>\n}\n\nexport { InputOtp, type InputOtpSignature };\nexport default InputOtp;\n"],"names":["OTP_PATTERNS","digits","letters","alphanumeric","OTP_INPUT_HINTS","inputMode","autoCapitalize","InputOtp","Component","g","prototype","tracked","args","value","i","prevSelection","inputRef","ref","element","document","addEventListener","onSelectionChange","capture","removeEventListener","length","allowedChars","pattern","writeValue","elementValue","syncFromValueArg","modifier","reconcileWithParent","emitted","next","isDestroying","isDestroyed","mirroredSelection","selectionStart","selectionEnd","separator","groupSizes","groups","total","reduce","sum","size","warn","id","cellGroups","cells","start","end","index","char","placeholderChar","placeholder","displayChar","isMasked","isActive","isFocused","push","hasFakeCaret","offset","slice","classes","inputOtp","useStyles","n","cached","syncValue","event","notify","target","previous","test","notifyParent","onInput","onChange","onComplete","handleOnInput","handleOnChange","input","current","activeElement","maxLength","caretStart","caretEnd","direction","selectionDirection","isSingleCaret","isInsertMode","caret","prevStart","prevEnd","wasInserting","setSelectionRange","lastStart","lastEnd","handleFocus","Math","min","handleOnBlur","onBlur","setComponentTemplate","precompileTemplate","strictMode","scope","FormControl","on"],"mappings":";;;;;;;;;;;;;AAoBA,MAAMA,YAAA,GAAe;AACnBC,EAAAA,MAAA,EAAQ,OAAA;AACRC,EAAAA,OAAA,EAAS,aAAA;AACTC,EAAAA,YAAA,EAAc;AAChB,CAAA;AAIA;;;;;AAKC;AACD,MAAMC,eAAA,GAAkB;AACtBH,EAAAA,MAAA,EAAQ;AAAEI,IAAAA,SAAA,EAAW,SAAA;AAAWC,IAAAA,cAAA,EAAgB;GAAM;AACtDJ,EAAAA,OAAA,EAAS;AAAEG,IAAAA,SAAA,EAAW,MAAA;AAAQC,IAAAA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AAI,CAACjE,QAAQ,CAACkE,OAAO;IACnC,IAAI,CAACD,KAAA,EAAO;AACV,MAAA;AACF,IAAA;AAEA;AACA,IAAA,MAAM/B,KAAA,GAAQiD,IAAA,CAAKC,GAAG,CAACnB,KAAA,CAAMpE,KAAK,CAACW,MAAM,EAAE,IAAI,CAACA,MAAM,GAAG,CAAA,CAAA;IACzDyD,KAAA,CAAMc,iBAAiB,CAAC7C,KAAA,EAAO+B,KAAA,CAAMpE,KAAK,CAACW,MAAM,CAAA;IACjD,IAAI,CAACH,iBAAiB,EAAA;EACxB,CAAA;EAEAgF,YAAA,GAAeA,MAAQ;IACrB,IAAI,CAAC1C,SAAS,GAAG,KAAA;IACjB,IAAI,CAACtB,cAAc,GAAG,IAAA;IACtB,IAAI,CAACC,YAAY,GAAG,IAAA;AACpB,IAAA,IAAI,CAACvB,aAAa,GAAG,CAAC,IAAA,EAAM,IAAA,CAAK;AACjC,IAAA,IAAI,CAACH,IAAI,CAAC0F,MAAM,IAAA;EAClB,CAAA;AAEA,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,6qGAAA,EAuGA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,WAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
@@ -1,6 +1,5 @@
1
1
  import Component from '@glimmer/component';
2
2
  import { tracked } from '@glimmer/tracking';
3
- import { action } from '@ember/object';
4
3
  import { on } from '@ember/modifier';
5
4
  import { useStyles } from '@frontile/theme';
6
5
  import { FormControl } from './form-control.js';
@@ -9,7 +8,7 @@ import { ref } from '../../utils/ref.js';
9
8
  import { CloseButton } from '../buttons/close-button.js';
10
9
  import { precompileTemplate } from '@ember/template-compilation';
11
10
  import { setComponentTemplate } from '@ember/component';
12
- import { d as decorateFieldV2, i as initializeDeferredDecorator, a as decorateMethodV2 } from '../../runtime--fcdnjmJ-BOdRhmsS.js';
11
+ import { d as decorateFieldV2, i as initializeDeferredDecorator } from '../../runtime--fcdnjmJ-BOdRhmsS.js';
13
12
 
14
13
  function or(arg1, arg2) {
15
14
  return !!(arg1 || arg2);
@@ -56,7 +55,7 @@ class Input extends Component {
56
55
  }
57
56
  return 'text';
58
57
  }
59
- handleOnInput(event) {
58
+ handleOnInput = event => {
60
59
  const value = event.target.value;
61
60
  this.elementValue = value;
62
61
  if (this.isControlled) {
@@ -64,11 +63,8 @@ class Input extends Component {
64
63
  } else {
65
64
  this.uncontrolledValue = value;
66
65
  }
67
- }
68
- static {
69
- decorateMethodV2(this.prototype, "handleOnInput", [action]);
70
- }
71
- handleOnChange(event) {
66
+ };
67
+ handleOnChange = event => {
72
68
  const value = event.target.value;
73
69
  this.elementValue = value;
74
70
  if (this.isControlled) {
@@ -76,17 +72,11 @@ class Input extends Component {
76
72
  } else {
77
73
  this.uncontrolledValue = value;
78
74
  }
79
- }
80
- static {
81
- decorateMethodV2(this.prototype, "handleOnChange", [action]);
82
- }
83
- handleOnBlur() {
75
+ };
76
+ handleOnBlur = () => {
84
77
  this.args.onBlur?.();
85
- }
86
- static {
87
- decorateMethodV2(this.prototype, "handleOnBlur", [action]);
88
- }
89
- clearValue() {
78
+ };
79
+ clearValue = () => {
90
80
  // Clear the element first: a parent that owns the value may derive it from
91
81
  // the DOM (as `<Form>` does via FormData), in which case notifying it
92
82
  // before the element is empty would just hand back the stale value.
@@ -102,10 +92,7 @@ class Input extends Component {
102
92
  }
103
93
  this.inputRef.current?.focus();
104
94
  triggerFormInputEvent(this.inputRef.current);
105
- }
106
- static {
107
- decorateMethodV2(this.prototype, "clearValue", [action]);
108
- }
95
+ };
109
96
  get isClearable() {
110
97
  if (this.args.isClearable === true && this.currentValue !== '' && typeof this.currentValue !== 'undefined') {
111
98
  return true;