{"version":3,"file":"slug_controller-hQ1NWUcG.js","sources":["../../../app/javascript/controllers/admin/slug_controller.js"],"sourcesContent":["import { Controller } from '@hotwired/stimulus'\n\nexport default class extends Controller {\n static targets = ['field', 'source']\n\n connect() {\n console.log('Slug controller connected')\n // Initial generation if title has content and slug is empty\n if (this.sourceTarget.value && this.fieldTarget.value.trim() === '') {\n this.generateSlug()\n }\n }\n\n generateSlug() {\n // Get the complete value from the source target\n const title = this.sourceTarget.value\n console.log(`Raw title value: ${title}`)\n\n // Always update the slug field with the parameterized title\n const slug = this.parameterize(title)\n this.fieldTarget.value = slug\n console.log(`Generated slug: ${slug} from title: ${title}`)\n }\n\n parameterize(string) {\n if (!string || string.length === 0) {\n return ''\n }\n\n return string\n .toString()\n .normalize('NFD') // normalize diacritics\n .replace(/[\\u0300-\\u036f]/g, '') // remove diacritics\n .toLowerCase()\n .trim()\n .replace(/\\s+/g, '-') // replace spaces with -\n .replace(/[^\\w\\-]+/g, '') // remove all non-word chars\n .replace(/\\-\\-+/g, '-') // replace multiple - with single -\n }\n}\n"],"names":["slug_controller","Controller","title","slug","string","__publicField"],"mappings":"4MAEe,MAAKA,UAASC,CAAW,CAGtC,SAAU,CACR,QAAQ,IAAI,2BAA2B,EAEnC,KAAK,aAAa,OAAS,KAAK,YAAY,MAAM,KAAM,IAAK,IAC/D,KAAK,aAAY,CAEvB,CAEE,cAAe,CAEb,MAAMC,EAAQ,KAAK,aAAa,MAChC,QAAQ,IAAI,oBAAoBA,CAAK,EAAE,EAGvC,MAAMC,EAAO,KAAK,aAAaD,CAAK,EACpC,KAAK,YAAY,MAAQC,EACzB,QAAQ,IAAI,mBAAmBA,CAAI,gBAAgBD,CAAK,EAAE,CAC9D,CAEE,aAAaE,EAAQ,CACnB,MAAI,CAACA,GAAUA,EAAO,SAAW,EACxB,GAGFA,EACJ,SAAQ,EACR,UAAU,KAAK,EACf,QAAQ,mBAAoB,EAAE,EAC9B,YAAW,EACX,KAAI,EACJ,QAAQ,OAAQ,GAAG,EACnB,QAAQ,YAAa,EAAE,EACvB,QAAQ,SAAU,GAAG,CAC5B,CACA,CApCEC,EADkBL,EACX,UAAU,CAAC,QAAS,QAAQ"}