import { Controller } from '@hotwired/stimulus'; export default class extends Controller { static targets = ['collection']; static values = { prototype: String }; declare readonly collectionTarget: HTMLElement; declare readonly prototypeValue: string; index = 0; _dragging: Element | null = null; _form: HTMLFormElement | null = null; _submitHandler: (() => void) | null = null; connect(): void { this.index = this.collectionTarget.children.length; this._syncOrdering(); if (this.index === 0) { this.addItem(); } // `submit` fires on the ancestor