Explorar o código

update 选中文字

liwei hai 1 ano
pai
achega
21c3fcc2b8

+ 32 - 6
src/modules/editor/components/CompUI/basicUI/Text/component.tsx

@@ -7,10 +7,11 @@ import { FontColor, FontFamily, FontSize } from "@ckeditor/ckeditor5-font";
 import { Link } from "@ckeditor/ckeditor5-link";
 import { Paragraph } from "@ckeditor/ckeditor5-paragraph";
 import { css } from "@linaria/core";
-import { defineComponent, onUnmounted, watch, watchEffect } from "vue";
-import { string } from "vue-types";
+import { defineComponent, onUnmounted, watch, watchEffect , ref} from "vue";
+import { string} from "vue-types";
 import { useCompData } from ".";
 import { View } from "../View";
+import { nextTick } from "process";
 
 export const Component = defineComponent({
   props: {
@@ -18,7 +19,13 @@ export const Component = defineComponent({
   },
   setup(props) {
     const comp = useCompData(props.compId);
-    const { store, actions } = useEditor();
+    const { store, actions , helper, controls} = useEditor();
+
+    const fontSizeOptions=[];
+    const list = [12, 14, 16, 18, 20, 24, 28, 32, 38, 42, 46, 52, 60]
+    for (const s of list) {
+      fontSizeOptions.push({title: s+"", model: s + "px"})
+    }
     const config = {
       language: "zh-cn",
       plugins: [
@@ -33,7 +40,8 @@ export const Component = defineComponent({
         Alignment,
       ],
       fontSize: {
-        options: [12, 14, 16, 18, 20, 24, 28, 32, 38, 42, 46, 52, 60],
+        options: fontSizeOptions,
+        supportAllValues:true,
       },
       toolbar: {
         items: [
@@ -94,7 +102,18 @@ export const Component = defineComponent({
         document.removeEventListener("mousedown", blur, { capture: true });
       };
     }
+    const inputRef = ref<any>();
+    if (store.isEditMode) {
+      actions.on("textFocus", (compId, focus:boolean)=>{
+        if (compId != props.compId) return;
 
+        if (focus) {
+          editorInstance.focus();
+          return;
+        } 
+      })  
+    }
+    
     return () => (
       <View
         class={[textStyle, store.currCompId === props.compId && "drag-disable"]}
@@ -102,13 +121,19 @@ export const Component = defineComponent({
       >
         <ckeditor
           class={textStyle}
+          ref={inputRef}
           editor={InlineEditor}
           onFocus={() => {
+            console.log("on  onn focus !!!")
             store.setTextEditingState(true);
           }}
           onInput={(value: any) => {
             if (editorInstance && comp.value !== value) {
-              actions.updateCompData(comp, "value", value);
+              // actions.updateCompData(comp, "value", value);
+              nextTick(()=>{
+                actions.updateCompDatas(comp, ["value", "layout.size.1"], [value, helper.pxToDesignSize(inputRef.value?.$el.clientHeight)])
+                controls.selectCtrl.upgateGizmoStyle();
+              })
             }
           }}
           onReady={(editor: InlineEditor) => {
@@ -126,7 +151,8 @@ export const Component = defineComponent({
 });
 
 const textStyle = css`
-  font-size: 12px;
+  font-size: 0.24rem;
+  width: 100%;
   color: #666;
   p {
     margin: 0;

+ 1 - 1
src/modules/editor/components/CompUI/basicUI/Text/index.ts

@@ -9,7 +9,7 @@ export const options = {
 };
 
 export const { createComp, useCompData } = createCompHooks({
-  value: "<p>请输入内容</p>",
+  value: `<p><span style="font-size:0.36rem;">请输入内容</span></p>`,
   layout: {
     size: [750, 60]
   }

+ 58 - 77
src/modules/editor/components/CompUI/basicUI/Transfer/select.tsx

@@ -1,4 +1,4 @@
-import { IconRotate } from "@/assets/icons";
+import { IconRotate , IconMove} from "@/assets/icons";
 import { CompToolbars } from "@/modules/editor/objects/Toolbars";
 import { css } from "@linaria/core";
 import { defineComponent, onMounted, onUnmounted, ref, nextTick } from "vue";
@@ -12,46 +12,8 @@ export const SelectTransfer = defineComponent({
     const { selectCtrl } = controls;
     const { transferStyle } = selectCtrl;
 
-    const selectRectRef = ref();
-    const rotateRef = ref();
-    const rotateRef2 = ref();
-    const rotateRef3 = ref();
-    const scaleBottomrightRef = ref();
-    const scaleBottomLeftRef = ref();
-    const scaleTopLeftRef = ref();
-    const scaleTopRightRef = ref();
-    const scaleRightRef = ref();
-    const scaleLeftRef = ref();
-
-    const scaleTopRef = ref();
-    const scaleBottomRef = ref();
-    const toolbarRef = ref();
-
-    onMounted(() => {
-      nextTick(() => {
-        selectRectRef.value.editable = "move";
-        rotateRef.value.editable = "rotate";
-        rotateRef2.value.editable = "rotate";
-        rotateRef3.value.editable = "rotate";
-        scaleBottomrightRef.value.editable = "scaleBottomright";
-
-        scaleBottomLeftRef.value.editable = "scaleBottomleft";
-        scaleTopLeftRef.value.editable = "scaleTopleft";
-        scaleTopRightRef.value.editable = "scaleTopright";
-        toolbarRef.value.editable = "toolbar"
-      });
-    });
 
     return () => {
-      if (selectCtrl.transferStyle.showOrthScale) {
-        nextTick(() => {
-          scaleRightRef.value.editable = "scaleright";
-          scaleLeftRef.value.editable = "scaleleft";
-          scaleTopRef.value.editable = "scaletop";
-          scaleBottomRef.value.editable = "scalebottom";
-        });
-      }
-
       let toolbarOpts = CompToolbars.default;
       let comp: any = null;
       if (selectCtrl.selected.length == 1) {
@@ -60,7 +22,8 @@ export const SelectTransfer = defineComponent({
         toolbarOpts = CompToolbars[comp.compKey] || toolbarOpts;
       }
       const w = selectCtrl.objContainer?.getBound();
-      
+      const isTextEdit = selectCtrl.selected.length == 1 && selectCtrl.selected[0].comp.compKey == "Text";
+
       return (
         <div
           class={[
@@ -72,7 +35,7 @@ export const SelectTransfer = defineComponent({
           }}
         >
           <div
-            ref={toolbarRef}
+            id= "toolbar"
             class={toolbarStyle}
             style={{
               top: w?.y + "px",
@@ -93,7 +56,7 @@ export const SelectTransfer = defineComponent({
 
           <div
             class={["absolute", selctRectStyle]}
-            ref={selectRectRef}
+            id="movecenter"
             style={{
               width: transferStyle.width + "px",
               height: transferStyle.height + "px",
@@ -105,63 +68,81 @@ export const SelectTransfer = defineComponent({
                 <div class={borderContentStyle} style={{width: transferStyle.relWidth + "px", height: transferStyle.relHeight + "px"}}></div>
             </div>
             <>
-              <div
-                class={[resizeStyle, scaleBottomRightStyle]}
-                style={{ transform: transferStyle.matrixInvert }}
-                ref={scaleBottomrightRef}
-              />
-              <div
-                class={[resizeStyle, scaleBottomLeftStyle]}
-                style={{ transform: transferStyle.matrixInvert }}
-                ref={scaleBottomLeftRef}
-              />
-              <div
-                class={[resizeStyle, scaleTopLeftStyle]}
-                style={{ transform: transferStyle.matrixInvert }}
-                ref={scaleTopLeftRef}
-              />
+              
+              {
+                !isTextEdit &&  <div
+                  class={[resizeStyle, scaleBottomRightStyle]}
+                  style={{ transform: transferStyle.matrixInvert }}
+                  id="scaleBottomright"
+                />
+              }
+
+                {
+                  !isTextEdit &&   <div
+                    class={[resizeStyle, scaleBottomLeftStyle]}
+                    style={{ transform: transferStyle.matrixInvert }}
+                    id="scaleBottomleft"
+                  />
+                }
+
+              {
+                  !isTextEdit &&<div
+                  class={[resizeStyle, scaleTopLeftStyle]}
+                  style={{ transform: transferStyle.matrixInvert }}
+                  id="scaleTopleft"
+                />
+              }
+              {
+                  !isTextEdit && <div
+                  class={[resizeStyle, scaleTopRightStyle]}
+                  style={{ transform: transferStyle.matrixInvert }}
+                  id="scaleTopright"
+                />
+              }
 
-              <div
-                class={[resizeStyle, scaleTopRightStyle]}
-                style={{ transform: transferStyle.matrixInvert }}
-                ref={scaleTopRightRef}
-              />
+              <div class={transformBtnsStyle} style={{ transform: transferStyle.matrixInvert }}>
+
+                <div
+                    class={transBtnStyle}
+                    id="moveicon"
+                  >
+                    <IconMove />
+                </div>
 
-              <div class={transformBtnsStyle} ref={rotateRef3} style={{ transform: transferStyle.matrixInvert }}>
                 <div
                   class={transBtnStyle}
-                  ref={rotateRef}
+                  id = "rotate"
                 >
-                  <IconRotate ref={rotateRef2} />
+                  <IconRotate  />
                 </div>
               </div>
 
-              {transferStyle.showOrthScale && (
+              {transferStyle.showOrthScale && !isTextEdit && (
                 <div
                   class={[resizeHeightBtnCls, scaleTopCls]}
                   style={{ transform: transferStyle.matrixInvert }}
-                  ref={scaleTopRef}
+                  id="scaletop"
                 />
               )}
-              {transferStyle.showOrthScale && (
+              {transferStyle.showOrthScale && !isTextEdit && (
                 <div
                   class={[resizeHeightBtnCls, scaleBottomCls]}
                   style={{ transform: transferStyle.matrixInvert }}
-                  ref={scaleBottomRef}
+                  id="scalebottom"
                 />
               )}
-              {transferStyle.showOrthScale && (
+              {transferStyle.showOrthScale &&  (
                 <div
                   class={[resizeWidthBtnCls, scaleRightCls]}
                   style={{ transform: transferStyle.matrixInvert }}
-                  ref={scaleRightRef}
+                  id="scaleright"
                 />
               )}
               {transferStyle.showOrthScale && (
                 <div
                   class={[resizeWidthBtnCls, scaleLeftCls]}
                   style={{ transform: transferStyle.matrixInvert }}
-                  ref={scaleLeftRef}
+                  id="scaleleft"
                 />
               )}
             </>
@@ -241,7 +222,7 @@ const transformBtnsStyle = css`
   @apply space-x-10px whitespace-nowrap;
   position: absolute;
   bottom: 0px;
-  left:calc(50% - 18px);
+  left:calc(50% - 32px);
   font-size: 16px;
   z-index: 999;
   pointer-events: auto;
@@ -250,13 +231,13 @@ const transformBtnsStyle = css`
 
 const transBtnStyle = css`
   display: inline-block;
-  width: 36px;
-  height: 36px;
+  width: 28px;
+  height: 28px;
   border-radius: 50%;
   background-color: #fff;
   text-align: center;
-  line-height: 36px;
-  font-size: 20px;
+  line-height: 28px;
+  font-size: 16px;
   color: #333;
   position: relative;
   top: 50px;

+ 6 - 6
src/modules/editor/components/CompUI/basicUI/View.tsx

@@ -35,12 +35,12 @@ export const View = defineComponent({
             store.currStreamCardId == props.compId && CurrCompStyle,
           ]}
           style={helper.createStyle(comp.layout)}
-          onClick={(e) => {
-            e.stopPropagation();
-            if (store.isEditMode) {
-              actions.pickComp(props.compId);
-            }
-          }}
+          // onClick={(e) => {
+          //   e.stopPropagation();
+          //   if (store.isEditMode) {
+          //     actions.pickComp(props.compId);
+          //   }
+          // }}
           onDblclick={() => emit("dblclick")}
         >
           <div

+ 2 - 0
src/modules/editor/components/CompUI/basicUI/hooks.ts

@@ -19,6 +19,8 @@ export function useCompRef(compId: string) {
           configurable: true,
         },
       });
+      compRef.value.compId= compId;
+      compRef.value.compKey= comp.compKey;
     }
   });
   return compRef;

+ 90 - 32
src/modules/editor/controllers/SelectCtrl/index.ts

@@ -7,6 +7,7 @@ import Event from "./event";
 import { Matrix } from "./matrix";
 import { Project, VectorLenth } from "./objects/mathUtils";
 import { Point } from "./objects/point";
+import { indexOf } from "lodash";
 
 /**
  *  页面画布空间进行选择
@@ -31,6 +32,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
   transferStyle = reactive({
     baseCardTop: "0px",
     showGizmo: false,
+    editingText: false,
     width: 0,
     height: 0,
     relWidth: 0,
@@ -116,9 +118,17 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
     }
   }
 
+  _downClickedCompId = "";
   onDocMouseDown(e: MouseEvent) {
     this._mouseDownTimestamp = Date.now();
 
+    const compKey = this.getDivFlag(e.target as any, "compKey");
+    console.log("compKey === >", compKey);
+    if (compKey == "Text" && !this.transferStyle.editingText) {
+       e.preventDefault();
+       e.stopPropagation();
+    }
+
     if (!this.pageEl || !this.selCanvas) return;
     if (this.store.textEditingState) return;
 
@@ -147,10 +157,10 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
     this._downClientX = e.clientX;
     this._downClientY = e.clientY;
 
-    // console.log(cardX, selX, cardY, sely);
+    this._downClickedCompId = this.compClickTest2(e);
 
     this._downed = true;
-    this._mouseDownFlag = this.getDivFlag(e.target as any);
+    this._mouseDownFlag = this.getDivTransformFlag(e.target as any);
     if (!this._mouseDownFlag) {
       //选框点击判断
       let isClickSelRect = false;
@@ -164,19 +174,9 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
           this._state = MODE_MOVING;
         }
       }
-      if (!isClickSelRect) {
-        //判断是否有点击到card stream
-        const comps = this.compClickTest(e);
-        console.log("comps=>", comps);
-        if (comps.length < 1) {
-          const test = this.streamCardClickTest(e);
-          if (test) {
-            const childs = this.compMap[test.id].children.default || [];
-            if (childs.length < 1) {
-              return;
-            }
-          }
-
+      if (!isClickSelRect) { //点击在选框之外
+        
+        if (!this._downClickedCompId) {//没有点击到组件
           const view = this.viewport?.getBoundingClientRect() as any;
           const isOut =
             e.clientX < view.left ||
@@ -187,7 +187,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
             this._state = MODE_SEL_RECT;
           }
         }
-        //else {
+        //else {//点击到选框之外的组件, 把时间放到mouseup 时相应.
         //   this._state = MODE_MOVING;
         //   const obj = this.compMap[comps[0].id];
         //   this.selecteObjs([new CompObject(obj)]);
@@ -195,7 +195,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
       }
     } else if (this._mouseDownFlag == "rotate") {
       this._state = MODE_ROTATE;
-    } else if (this._mouseDownFlag == "move") {
+    } else if (this._mouseDownFlag.indexOf("move") > -1) {
       this._state = MODE_MOVING;
     } else if (this._mouseDownFlag.indexOf("scale") > -1) {
       this._state = MODE_SCALE;
@@ -203,20 +203,33 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
 
     this._movePreClientX = this._downClientX;
     this._movePreClientY = this._downClientY;
+    this._initMovePos.x = -1;
+    this._initMovePos.y = -1;
 
-    if (this._state == MODE_MOVING) {
-      const obj = this.objContainer as ObjsContainer;
-      this._initMovePos = { x: obj.parent.x, y: obj.parent.y };
-    }
   }
-  _initMovePos = { x: 0, y: 0 };
+  _initMovePos = { x: -1, y: -1 };
+
+  getDivFlag(div: HTMLElement, flag="editable") {
+    let c: any = div;
+    if (!c) return ""
+    let i = 0;
+    do {
+      if (c[flag]) return c[flag];
+      c = c.parentElement;
+      i += 1;
+      if (i > 16) {
+        return ""
+      }
+    } while (c);
+    return "";
+  }
 
-  getDivFlag(div: HTMLElement) {
+  getDivId(div: HTMLElement) {
     let c: any = div;
     if (!c) return;
     let i = 0;
     do {
-      if (c.editable) return c.editable;
+      if (c.id) return c.id;
       c = c.parentElement;
       i += 1;
       if (i > 5) {
@@ -224,6 +237,20 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
       }
     } while (c);
   }
+  
+  getDivTransformFlag(div: HTMLElement) {
+     const id = this.getDivId(div);
+     if (!id) return "";
+     if ( id.indexOf("rotate")>-1 || id.indexOf("move") > -1 || id.indexOf("scale") > -1 || id.indexOf("toolbar") > -1) return id;
+     return "";
+  }
+
+  compClickTest2(e: MouseEvent) {
+    const compId = this.getDivFlag(e.target as any, "compId");
+    console.log("down click=>", compId);
+
+    return compId;
+  }
 
   compClickTest(e: MouseEvent) {
     const cards = this.store.streamCardIds;
@@ -300,6 +327,10 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
   movingMousemove(e: MouseEvent) {
     const objContainer = this.objContainer as ObjsContainer;
 
+    if (this._initMovePos.x == -1 && this._initMovePos.y == -1) {
+        const obj = this.objContainer as ObjsContainer;
+        this._initMovePos = { x: obj.parent.x, y: obj.parent.y };
+    }
     objContainer.setPivot(0);
     objContainer.translate(
       e.clientX - this._movePreClientX,
@@ -346,6 +377,13 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
   }
 
   onDocMouseUp(e: MouseEvent) {
+    let isClick = false;
+    let offsetT = Date.now() - this._mouseDownTimestamp;
+    const dx = Math.abs(e.clientX - this._downClientX);
+    const dy = Math.abs(e.clientY - this._downClientY);
+    if (dx < 2 && dy < 2 && offsetT < 200) {
+      isClick = true;
+    }
     document.removeEventListener("mousemove", this.onDocMouseMove, {
       capture: true,
     });
@@ -354,23 +392,33 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
       return;
     }
 
-    let isClick = false;
-    let offsetT = Date.now() - this._mouseDownTimestamp;
-    const dx = Math.abs(e.clientX - this._downClientX);
-    const dy = Math.abs(e.clientY - this._downClientY);
-    if (dx < 2 && dy < 2 && !this.store.textEditingState && offsetT < 200) {
-      isClick = true;
+    if (isClick) {
+      this.actions.pickComp(this._downClickedCompId);
     }
+
     if (isClick) {
       this._state = MODE_NONE;
       const comps = this.compClickTest(e);
       if (comps.length < 1) {
         setTimeout(() => {
+            this.transferStyle.editingText = false;
             this.actions.selectObjs([]) //清空选择
         }, 0);
+      } else {
+        const compKey = this.getDivFlag(e.target as any, "compKey");
+        console.log("up compKey === >", compKey);
+        if (compKey == "Text" ) { //点击鼠标上来后 focus文本选中
+             const compId = this.getDivFlag(e.target as any, "compId");
+             if ( this.selected.length ==  1 && this.selected[0].comp.id == compId ) {
+
+                //取消当前选择
+                this.selecteObjs([])
+                this.actions.textFocus(compId);
+                this.transferStyle.editingText = true;
+                
+             }
+        }
       }
-    } else {
-      e.stopPropagation();
     }
 
     if (this._state == MODE_SEL_RECT && !isClick) {
@@ -415,6 +463,16 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
     const initX = this._initMovePos.x,
       initY = this._initMovePos.y;
 
+      this._initMovePos.x = -1;
+      this._initMovePos.y = -1;
+
+      if (this.store.selected.length == 1 && this.store.currComp.compKey == "Text") {
+          this.actions.textFocus(this.store.currCompId, false)
+      }
+
+      if (initX == -1 && initY == -1) return;
+
+
       obj.setPivot(0);
 
     history.record({

+ 1 - 1
src/modules/editor/controllers/SelectCtrl/objects/displayObject.ts

@@ -8,7 +8,7 @@ export class DisplayObject {
 
   tempDisplayObjectParent?:DisplayObject;
 
-  transform = new Transform();
+transform = new Transform();
 
   visible = true;
 

+ 7 - 5
src/modules/editor/module/actions/edit.ts

@@ -9,6 +9,9 @@ import { ICompKeys, Layout } from "../../typings";
 export const editActions = EditorModule.action({
 
   pickComp(compId: string) {
+    if (compId == "") {//空的时候,就选择根页面
+      compId = "root";
+    }
     const selectCardChild = (id:string)=>{
       const paths = this.helper.getCompTrees(id)
         const cardChilds = paths[2];
@@ -19,11 +22,7 @@ export const editActions = EditorModule.action({
         }
     }
     if (this.store.currCompId == compId) {
-      // if (this.controls.selectCtrl.selected.length < 1 ) {
-      //   selectCardChild(compId);
-      // }else {
-      //     this.controls.selectCtrl.upgateGizmoStyle();
-      //   }
+      //this.controls.selectCtrl.upgateGizmoStyle();
       return;
     }
 
@@ -106,6 +105,9 @@ export const editActions = EditorModule.action({
    async selectObjs(ids: string[]) {
      this.store.selected = ids;
      this.store.selectId = ids.length > 1 ? (Date.now() + "") : ""
+     if (ids.length < 1) {
+      this.actions.pickComp("root");
+     }
    },
 
   // 添加组件到画布

+ 16 - 0
src/modules/editor/module/actions/editWithManualHistory.ts

@@ -22,7 +22,23 @@ export const manualActions = EditorModule.action({
     historyCtrl.historyActionDoing = false;
   },
 
+  updateCompDatas(comp: DesignComp, paths: string[], values: any[]) {
+    const { historyCtrl } = this.controls;
+    historyCtrl.historyActionDoing = true;
+    historyCtrl.historyCombine = true;
+    let n = paths.length;
+    while(n--) {
+      set(comp, paths[n], values[n]);
+    }
+    // call action method
+    historyCtrl.historyCombine = false;
+    historyCtrl.historyActionDoing = false;
+  },
+
   submitUpdate() {
     this.controls.historyCtrl.history.submit();
   },
+  textFocus(compId:string, focus=true) {
+    console.log("text focus", compId,  focus);
+  },
 });

+ 1 - 1
src/modules/resource/components/PromotionItem.tsx

@@ -17,7 +17,7 @@ export default defineComponent({
 
     const goEdit = () => {
       if (location.host == "www.infish.cn") {
-        const url = `${location.origin}/projects/queenshow/editor.html#/?id=${props.record._id}`;
+        const url = `${location.origin}/projects/queenshowv1/editor.html#/?id=${props.record._id}`;
         location.href = url;
         return;
       }