{"version":3,"file":"AutosizeTextarea-sn0UZwFe.js","sources":["../../../app/javascript/src/components/InputValidation.vue","../../../app/javascript/src/components/Containers/WithId.vue","../../../app/javascript/src/components/Containers/DivWithId.vue","../../../app/javascript/src/modules/LiteCMS/Common/AutosizeTextarea.vue"],"sourcesContent":["<template>\n  <div v-if=\"showError\"\n       class=\"message\"\n       :style=\"style\"\n  >{{ message }}</div>\n</template>\n\n<script setup>\nimport { computed, onBeforeUnmount, nextTick, onMounted } from \"vue\";\nimport { watchImmediate } from \"@vueuse/core\";\nimport { randomKey } from \"@/utils/stringUtils.js\";\nimport { toggleValue } from \"@/utils/arrayUtils.ts\";\n\nconst props = defineProps({\n  id: String, // target single # element\n  target: String, // any css selector\n  checker: Function, // validate function\n  top: {\n    type: String,\n    default: '6px'\n  },\n  message: {\n    type: String,\n    default: 'This cannot be empty'\n  },\n  inline: {\n    type: Boolean,\n    default: false\n  },\n  basic: {\n    type: Boolean,\n    default: false,\n  },\n  errors: Object, // { [key: string]: boolean | null }\n  validating: String, // full / basic / null\n  invalidClass: String\n});\nconst showError = computed(() => {\n  const validating = props.validating === 'full' || (props.validating === 'basic' && props.basic);\n  return validating && !props.checker()\n});\nconst style = computed(() => ({\n  display: props.inline ? 'inline' : 'block',\n  marginTop: props.top,\n}));\nconst selector = computed(() => {\n  if (props.id) return `#${props.id}`;\n  if (props.target) return props.target;\n  return null;\n});\nconst key = randomKey();\n\nwatchImmediate(() => [props.validating, props.checker()], () => onErrorStateChanged(showError.value));\n\nonMounted(() => {\n  props.errors[key] = showError.value;\n});\n\nonBeforeUnmount(() => {\n  delete (props.errors[key]);\n  toggleTargetElementErrorClass(false);\n});\n\nfunction onErrorStateChanged(hasError) {\n  props.errors[key] = hasError;\n  toggleTargetElementErrorClass(hasError);\n}\n\nfunction toggleTargetElementErrorClass(isInvalid) {\n  nextTick(() => {\n    if (!selector.value) return;\n    const elements = [...document.querySelectorAll(selector.value)];\n    elements.forEach(el => {\n      let errorList = JSON.parse(el.dataset.errors || '[]');\n      errorList = toggleValue(errorList, key, isInvalid);\n      el.dataset.errors = JSON.stringify(errorList);\n      el.classList.toggle(props.invalidClass, errorList.length > 0);\n    });\n  });\n}\n</script>\n\n<style lang=\"scss\" scoped>\n.message {\n  color: $brand-secondary;\n}\n</style>","<template>\n  <slot :id=\"uniqueId\"></slot>\n</template>\n\n<script setup>\nimport { ref } from 'vue';\nimport { uniqId } from \"@/utils/stringUtils.js\";\n\nconst uniqueId = ref(uniqId());\n</script>","<template>\n  <div>\n    <slot :id=\"id\" :id1=\"id1\" :id2=\"id2\" />\n  </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue';\nimport { uniqId } from \"@/utils/stringUtils.js\";\n\nconst id = ref(uniqId());\nconst id1 = ref(uniqId());\nconst id2 = ref(uniqId());\n</script>","<template>\n  <textarea\n    ref=\"textarea\"\n    :rows=\"rows\"\n    v-bind=\"$attrs\"\n    v-model=\"input\"\n    :maxlength=\"max\"\n  />\n</template>\n\n<script setup>\nimport { useTextareaAutosize } from \"@vueuse/core\";\nimport { nextTick, watch } from \"vue\";\n\nconst props = defineProps({\n  rows: { type: [String, Number], default: 1 },\n  prefix: { type: String, default: '' },\n  max: { type: Number, default: Infinity },\n});\nconst model = defineModel();\nconst { textarea, input } = useTextareaAutosize({ input: model, styleProp: 'minHeight' });\n\nwatch(input, async (newVal, oldVal) => {\n  await nextTick();\n  oldVal ??= '';\n  newVal ??= '';\n  if (props.prefix && !oldVal.startsWith(props.prefix)) {\n    oldVal = props.prefix + oldVal;\n  }\n  if (props.prefix && !newVal.startsWith(props.prefix)) {\n    input.value = oldVal;\n  }\n}, { immediate: true })\n</script>\n\n<style lang=\"scss\" scoped>\ntextarea {\n  resize: none;\n  -ms-overflow-style: none;\n  scrollbar-width: none;\n}\n\ntextarea::-webkit-scrollbar {\n  display: none;\n}\n</style>"],"names":["props","__props","showError","computed","style","selector","key","randomKey","watchImmediate","onErrorStateChanged","onMounted","onBeforeUnmount","toggleTargetElementErrorClass","hasError","isInvalid","nextTick","el","errorList","toggleValue","uniqueId","ref","uniqId","id","id1","id2","model","_useModel","textarea","input","useTextareaAutosize","watch","newVal","oldVal"],"mappings":"yyDAaA,MAAMA,EAAQC,EAwBRC,EAAYC,EAAS,KACNH,EAAM,aAAe,QAAWA,EAAM,aAAe,SAAWA,EAAM,QACpE,CAACA,EAAM,QAAO,CACpC,EACKI,EAAQD,EAAS,KAAO,CAC5B,QAASH,EAAM,OAAS,SAAW,QACnC,UAAWA,EAAM,GACnB,EAAE,EACIK,EAAWF,EAAS,IACpBH,EAAM,GAAW,IAAIA,EAAM,EAAE,GAC7BA,EAAM,OAAeA,EAAM,OACxB,IACR,EACKM,EAAMC,EAAW,EAEvBC,EAAe,IAAM,CAACR,EAAM,WAAYA,EAAM,SAAS,EAAG,IAAMS,EAAoBP,EAAU,KAAK,CAAC,EAEpGQ,EAAU,IAAM,CACdV,EAAM,OAAOM,CAAG,EAAIJ,EAAU,KAChC,CAAC,EAEDS,EAAgB,IAAM,CACpB,OAAQX,EAAM,OAAOM,CAAG,EACxBM,EAA8B,EAAK,CACrC,CAAC,EAED,SAASH,EAAoBI,EAAU,CACrCb,EAAM,OAAOM,CAAG,EAAIO,EACpBD,EAA8BC,CAAQ,CACxC,CAEA,SAASD,EAA8BE,EAAW,CAChDC,EAAS,IAAM,CACb,GAAI,CAACV,EAAS,MAAO,OACJ,CAAC,GAAG,SAAS,iBAAiBA,EAAS,KAAK,CAAC,EACrD,QAAQW,GAAM,CACrB,IAAIC,EAAY,KAAK,MAAMD,EAAG,QAAQ,QAAU,IAAI,EACpDC,EAAYC,EAAYD,EAAWX,EAAKQ,CAAS,EACjDE,EAAG,QAAQ,OAAS,KAAK,UAAUC,CAAS,EAC5CD,EAAG,UAAU,OAAOhB,EAAM,aAAciB,EAAU,OAAS,CAAC,CAClE,CAAK,CACL,CAAG,CACH,+KCvEA,MAAME,EAAWC,EAAIC,GAAQ,oFCE7B,MAAMC,EAAKF,EAAIC,GAAQ,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