diff --git a/src/create/createQuestion.tsx b/src/create/createQuestion.tsx index da04d985..cbbf80a5 100644 --- a/src/create/createQuestion.tsx +++ b/src/create/createQuestion.tsx @@ -12,7 +12,6 @@ import type {ElementsOfObject} from "./questionTypes" //Значения, собираемые для отправки на бэк interface Values { title: string; - type: string; children: string; description: string; } @@ -24,7 +23,8 @@ const types = [ {desc:"чекбокс", value:"checkbox"}, {desc:"файл", value:"file"}, {desc:"кнопка", value:"button"}, - {desc:"ничего", value:"none"} + {desc: "описание", value: "description"}, + {desc:"ничего", value:"none"}, ] export const TextField = (props: any) => { @@ -103,17 +103,34 @@ const getIndexById = (id:number, array:Array):number => { export default () => { - const [type, setType] = React.useState(4) const [stockroom, setStockroom] = React.useState>([]) const [focus, setFocus] = React.useState() //Хранит id объекта + // React.useEffect(() => { + // console.log(focus) + // if (focus !== undefined) { + // let elem = document.getElementById(focus + "") + // if (elem !== null) { + // console.log(elem) + // elem.focus() + // } + // } + // },[focus]) + //При пересоздании массива для изменения фокуса объекта отменяются фокусы у всех элементов массива - const typeHC = (value:number): void => { - setType(value) - setStockroom([]) - saveCondition("type", value) - saveCondition("stockroom", []) + //Изменение типа очищает все поля, кроме фокуса + const typeHC = (type:number): void => { + if (focus !== undefined) { + let index = getIndexById(focus, stockroom) + + let newArr = stockroom + newArr[index].type = type + newArr[index].color = "" + newArr[index].text = "" + setStockroom([...newArr]) + saveCondition("stockroom", newArr) + } } const changeFocus = (id: number): void => { //Не менять фокус если снова выбрано то же окно @@ -175,7 +192,16 @@ export default () => { //Говорим стейту с фокусом, что фокус изменился setFocus(newArr.length - 1) } else { //фокус есть - добавляем после объекта с фокусом + + + let index = getIndexById(focus, stockroom) + let current = stockroom[index] + //Объект в фокусе - контейнер. Новый объект создаётся с указанием, что контейнер - родитель + if (current.type === 7) { + obj.parent = current.id + } + newArr.splice(index + 1, 0, obj) //Говорим стейту с фокусом, что фокус изменился @@ -198,20 +224,20 @@ export default () => { saveCondition("stockroom", newArr) } } - + console.log("render") return( <> { - console.log(JSON.stringify(values)) + // console.log(JSON.stringify(values)) console.log(getCondition()) + console.log(focus) }} > {(props: FormikProps) => ( @@ -233,23 +259,22 @@ export default () => { { padding="10px" width="80%" ref={visual} - /> + tabIndex={0} + _focus={{ + border:"solid 1px red" + }} + > + + } ) diff --git a/src/create/lsBacking.tsx b/src/create/lsBacking.tsx index 316c2412..7cdce971 100644 --- a/src/create/lsBacking.tsx +++ b/src/create/lsBacking.tsx @@ -1,13 +1,3 @@ -export function saveCondition (key:string, value:any) { - let ls : any = window.localStorage.getItem("condition") - if (ls !== null) { - ls = JSON.parse(ls) - } else { - ls = {} - } - ls[key] = value - localStorage.setItem("condition", JSON.stringify(ls)) -} export function getCondition () { let ls : any = window.localStorage.getItem("condition") if (ls !== null) { @@ -15,4 +5,15 @@ export function getCondition () { } else { return null } +} +export function saveCondition (key:string, value:any) { + let ls : any = getCondition() + if (ls === null) { + ls = {} + } + ls[key] = value + localStorage.setItem("condition", JSON.stringify(ls)) +} +export function clearCondition (key:string, value:any) { + localStorage.setItem("condition", "{}") } \ No newline at end of file diff --git a/src/create/questionTypes.tsx b/src/create/questionTypes.tsx index 735c5ef8..ee065fc8 100644 --- a/src/create/questionTypes.tsx +++ b/src/create/questionTypes.tsx @@ -4,16 +4,18 @@ interface ElementsOfObject { id: number; isFocus: boolean; color?: string; + type: number + parent: undefined | number } interface QuestionProps { type: number; - stockroom: Array; + stockroom: Array | never[]; focus: number; - changeFocus: (id?: number) => void; - changeBgColor: (text?:string) => void; - changeText: (text?:string) => void; - createObject?: (obj?:ElementsOfObject) => void; - deleteObject: (id?:number) => void; - getIndexById: (id?:number, array?:ElementsOfObject) => number; + changeFocus: (id: number) => void; + changeBgColor: (text:string) => void; + changeText: (text:string) => void; + createObject?: (obj:ElementsOfObject) => void; + deleteObject: (id:number) => void; + getIndexById: (id:number, array?:ElementsOfObject) => number; } export type {ElementsOfObject, QuestionProps} \ No newline at end of file diff --git a/src/create/settings.tsx b/src/create/settings.tsx index 5fa42597..737a6573 100644 --- a/src/create/settings.tsx +++ b/src/create/settings.tsx @@ -1,14 +1,26 @@ import React from 'react'; -import {Box, Button, Checkbox, Container, Select} from "@chakra-ui/react"; -import Buttons from "./tools/buttons" +import {Box, Button, Checkbox, Container, Select, Textarea} from "@chakra-ui/react"; +import UserElements from "./userElements" +import SunEditor from "suneditor-react"; export default (props: any) => { + let current:any + if (props.focus !== undefined) { + if (props.stockroom !== undefined) { + const index = props.getIndexById(props.focus, props.stockroom) + + if (index !== undefined) { + current = props.stockroom[index] + } + } + } + return ( <> - { createObject={props.createObject} deleteObject={props.deleteObject} getIndexById={props.getIndexById} + current={current} /> + {current === undefined ? + null + : + current.type === 5 ? + { + let visual = document.getElementById(current.id) + if (visual !== null) { + visual.innerHTML = e + } + props.changeText(e) + }} + // imageUploadHandler={(e:any)=>console.log(e)} + // onImageUpload={(e:any)=>console.log(e)} + // showController={(e:any)=>console.log(e)} + // hideToolbar={false} + defaultValue={current.text} + setOptions={{ + buttonList: [ + [ + 'undo', 'redo', + 'font', 'fontSize', 'formatBlock', + 'paragraphStyle', 'blockquote', + 'bold', 'underline', 'italic', 'strike', 'subscript', 'superscript', + 'fontColor', 'hiliteColor', 'textStyle', + 'removeFormat', + 'outdent', 'indent', + 'align', 'horizontalRule', 'list', 'lineHeight', + 'table', 'link', 'image', 'video', + 'fullScreen', 'showBlocks', 'codeView', + 'preview', 'print', 'save', 'template', + ] + ] + }} + /> + : +