diff --git a/components/baseEditor.vue b/components/baseEditor.vue index f8dcbae..c86a695 100644 --- a/components/baseEditor.vue +++ b/components/baseEditor.vue @@ -19,6 +19,12 @@ (); + let w; + onMounted(() => { + w = window; + }); const dc = defaultChapter; // data: FormStory; - const data = defineModel("data", { + const sdata = defineModel("data", { required: true, }); let drag = false; @@ -54,114 +58,121 @@ const { values, setFieldValue, handleSubmit } = useForm({ keepValuesOnUnmount: true, validationSchema: storySchema, - initialValues: data.value, + initialValues: sdata.value, }); + // const { push, remove, move, fields } = useFieldArray("chapters"); const subCb = handleSubmit(onSubmit); + + const pushHOF = (push) => (e) => { + if (!Array.isArray(values.chapters)) { + // noinspection TypeScriptValidateTypes + setFieldValue("chapters", []); + } + const chaps = [...toRaw(values.chapters)]; + let lastIndex = chaps.length - 1; + if (lastIndex < 0) lastIndex = 0; + let lastChapter = chaps[lastIndex]; + // log.debug('chaptrs->', chaps); + // log.debug('lastIndex->', lastIndex, lastChapter); + let newChapter = Object.assign({}, defaultChapter, { + summary: lastChapter?.summary || "", + index: (lastChapter?.index || 0) + 1, + bands: lastChapter?.bands || [], + characters: lastChapter?.characters || [], + relationships: lastChapter?.relationships || [], + uuidKey: v4(), + genre: lastChapter?.genre || [], + }); + // console.debug("nc->", newChapter); + // console.debug("pushi -> ", push); + push(newChapter); + sdata.value.chapters.push(newChapter); + };