import {Controller} from '@hotwired/stimulus'; export default class extends Controller { static targets = ['collection']; static values = {prototype: String}; connect() { this.index = this.collectionTarget.children.length; this._syncOrdering(); if (this.index === 0) { this.addItem(); } // `submit` fires on the ancestor