|
@@ -1,19 +1,20 @@
|
|
import {
|
|
import {
|
|
|
|
+ IconStrikethrough,
|
|
|
|
+ IconTextBold,
|
|
IconTextCenter,
|
|
IconTextCenter,
|
|
|
|
+ IconTextItalic,
|
|
IconTextJustify,
|
|
IconTextJustify,
|
|
IconTextLeft,
|
|
IconTextLeft,
|
|
IconTextLetterSpacing,
|
|
IconTextLetterSpacing,
|
|
IconTextLineHeight,
|
|
IconTextLineHeight,
|
|
IconTextRight,
|
|
IconTextRight,
|
|
IconTextSize,
|
|
IconTextSize,
|
|
- IconStrikethrough,
|
|
|
|
- IconTextBold,
|
|
|
|
- IconTextItalic,
|
|
|
|
IconTextUnderline,
|
|
IconTextUnderline,
|
|
} from "@/assets/icons";
|
|
} from "@/assets/icons";
|
|
import { css } from "@linaria/core";
|
|
import { css } from "@linaria/core";
|
|
-import { Button, Input, InputNumber, Tooltip } from "ant-design-vue";
|
|
|
|
|
|
+import { Button, InputNumber, Tooltip } from "ant-design-vue";
|
|
|
|
|
|
|
|
+import { useEditor } from "@/modules/editor";
|
|
import Select from "@queenjs-modules/queditor/components/FormUI/Items/Select";
|
|
import Select from "@queenjs-modules/queditor/components/FormUI/Items/Select";
|
|
import "@simonwep/pickr/dist/themes/nano.min.css";
|
|
import "@simonwep/pickr/dist/themes/nano.min.css";
|
|
import _ from "lodash";
|
|
import _ from "lodash";
|
|
@@ -24,10 +25,10 @@ import {
|
|
onUnmounted,
|
|
onUnmounted,
|
|
reactive,
|
|
reactive,
|
|
ref,
|
|
ref,
|
|
|
|
+ toRaw,
|
|
watch,
|
|
watch,
|
|
} from "vue";
|
|
} from "vue";
|
|
import { any, bool, func, number, object, string } from "vue-types";
|
|
import { any, bool, func, number, object, string } from "vue-types";
|
|
-import { useEditor } from "@/modules/editor";
|
|
|
|
interface ColumnItem {
|
|
interface ColumnItem {
|
|
label?: string;
|
|
label?: string;
|
|
component?: ((...args: any[]) => any) | Record<string, any>;
|
|
component?: ((...args: any[]) => any) | Record<string, any>;
|
|
@@ -36,104 +37,7 @@ interface ColumnItem {
|
|
itemProps?: { [name: string]: any };
|
|
itemProps?: { [name: string]: any };
|
|
changeExtra?: (data: any) => any;
|
|
changeExtra?: (data: any) => any;
|
|
}
|
|
}
|
|
-// export const TextColor = defineComponent({
|
|
|
|
-// props: {
|
|
|
|
-// value: string().def("#666666"),
|
|
|
|
-// },
|
|
|
|
-// emits: ["change"],
|
|
|
|
-// setup(props, { emit }) {
|
|
|
|
-// let picker: any = null;
|
|
|
|
|
|
|
|
-// let emitFlagRef = ref(true);
|
|
|
|
-// const color = HSLToHex(props.value);
|
|
|
|
-// function HSLToHex(hslStr: string): string {
|
|
|
|
-// const isHsl = hslStr.indexOf("hsl");
|
|
|
|
-// if (isHsl == -1) {
|
|
|
|
-// return hslStr;
|
|
|
|
-// }
|
|
|
|
-// const reg = /(?<=hsl\()(\W|\w)*(?=\))/g;
|
|
|
|
-// let hsl: any = hslStr.match(reg);
|
|
|
|
-// if (!hsl) {
|
|
|
|
-// return hslStr;
|
|
|
|
-// }
|
|
|
|
-// hsl = hsl[0];
|
|
|
|
-// hsl = hsl.split(",");
|
|
|
|
-// const [h, s, l] = hsl;
|
|
|
|
-
|
|
|
|
-// const hDecimal = parseInt(l) / 100;
|
|
|
|
-// const a = (parseInt(s) * Math.min(hDecimal, 1 - hDecimal)) / 100;
|
|
|
|
-// const f = (n: number) => {
|
|
|
|
-// const k = (n + parseInt(h) / 30) % 12;
|
|
|
|
-// const color = hDecimal - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
|
|
-
|
|
|
|
-// return Math.round(255 * color)
|
|
|
|
-// .toString(16)
|
|
|
|
-// .padStart(2, "0");
|
|
|
|
-// };
|
|
|
|
-// return `#${f(0)}${f(8)}${f(4)}`;
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// function initPicker() {
|
|
|
|
-// picker = Pickr.create({
|
|
|
|
-// el: ".color_picker",
|
|
|
|
-// theme: "nano",
|
|
|
|
-// default: color,
|
|
|
|
-// i18n: {
|
|
|
|
-// "btn:save": "确定",
|
|
|
|
-// },
|
|
|
|
-// components: {
|
|
|
|
-// preview: true,
|
|
|
|
-// opacity: false,
|
|
|
|
-// hue: true,
|
|
|
|
-// interaction: {
|
|
|
|
-// hex: false,
|
|
|
|
-// hsla: false,
|
|
|
|
-// rgba: false,
|
|
|
|
-// input: true,
|
|
|
|
-// save: true,
|
|
|
|
-// },
|
|
|
|
-// },
|
|
|
|
-// });
|
|
|
|
-// // picker.on("change", (color: any) => {
|
|
|
|
-// // const hexa = color.toHEXA().toString();
|
|
|
|
-// // console.log("setChange", hexa);
|
|
|
|
-// // });
|
|
|
|
-// picker.on("save", (color: any) => {
|
|
|
|
-// picker.hide();
|
|
|
|
-// const hexa = color.toHEXA().toString();
|
|
|
|
-// emit("change", hexa);
|
|
|
|
-// });
|
|
|
|
-// }
|
|
|
|
-// watch(
|
|
|
|
-// () => props.value,
|
|
|
|
-// () => {
|
|
|
|
-// const color = HSLToHex(props.value);
|
|
|
|
-// const res = picker.setColor(color);
|
|
|
|
-// console.log("picker change", color, res);
|
|
|
|
-// }
|
|
|
|
-// );
|
|
|
|
-// onMounted(() => {
|
|
|
|
-// initPicker();
|
|
|
|
-// });
|
|
|
|
-// onUnmounted(() => {
|
|
|
|
-// if (picker) {
|
|
|
|
-// picker.destroyAndRemove();
|
|
|
|
-// picker = null;
|
|
|
|
-// }
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-// return () => (
|
|
|
|
-// <div
|
|
|
|
-// class={ColorPicker}
|
|
|
|
-// onClick={() => {
|
|
|
|
-// picker?.show();
|
|
|
|
-// }}
|
|
|
|
-// >
|
|
|
|
-// <div class={"color_picker"} id="color_picker"></div>
|
|
|
|
-// </div>
|
|
|
|
-// );
|
|
|
|
-// },
|
|
|
|
-// });
|
|
|
|
export const TextColor = defineComponent({
|
|
export const TextColor = defineComponent({
|
|
props: {
|
|
props: {
|
|
value: string().def("#666666"),
|
|
value: string().def("#666666"),
|
|
@@ -227,12 +131,14 @@ export const AlignComp = defineComponent({
|
|
});
|
|
});
|
|
export const LetterSpacingComp = defineComponent({
|
|
export const LetterSpacingComp = defineComponent({
|
|
props: {
|
|
props: {
|
|
- value: string().def("0"),
|
|
|
|
|
|
+ value: any<string | number>().def(0),
|
|
},
|
|
},
|
|
emits: ["change"],
|
|
emits: ["change"],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
return () => {
|
|
return () => {
|
|
- const value = parseFloat(props.value) || 0;
|
|
|
|
|
|
+ const value =
|
|
|
|
+ typeof props.value === "string" ? parseInt(props.value) : props.value;
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<InputNumber
|
|
<InputNumber
|
|
prefix={<IconTextLetterSpacing class="text-22px mr-6px" />}
|
|
prefix={<IconTextLetterSpacing class="text-22px mr-6px" />}
|
|
@@ -243,10 +149,10 @@ export const LetterSpacingComp = defineComponent({
|
|
value={value}
|
|
value={value}
|
|
onChange={(value: any) => {
|
|
onChange={(value: any) => {
|
|
if (!value) {
|
|
if (!value) {
|
|
- emit("change", "0em");
|
|
|
|
|
|
+ emit("change", "0px");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- emit("change", value / 100 + "em");
|
|
|
|
|
|
+ emit("change", value + "px");
|
|
}}
|
|
}}
|
|
/>
|
|
/>
|
|
);
|
|
);
|
|
@@ -256,11 +162,13 @@ export const LetterSpacingComp = defineComponent({
|
|
|
|
|
|
export const LineHeightComp = defineComponent({
|
|
export const LineHeightComp = defineComponent({
|
|
props: {
|
|
props: {
|
|
- value: number().def(1.5),
|
|
|
|
|
|
+ value: any<string | number>().def(1.5),
|
|
},
|
|
},
|
|
emits: ["change"],
|
|
emits: ["change"],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
return () => {
|
|
return () => {
|
|
|
|
+ const value =
|
|
|
|
+ typeof props.value === "string" ? parseFloat(props.value) : props.value;
|
|
return (
|
|
return (
|
|
<InputNumber
|
|
<InputNumber
|
|
prefix={<IconTextLineHeight class="text-22px mr-6px" />}
|
|
prefix={<IconTextLineHeight class="text-22px mr-6px" />}
|
|
@@ -268,7 +176,7 @@ export const LineHeightComp = defineComponent({
|
|
min={0.5}
|
|
min={0.5}
|
|
max={3}
|
|
max={3}
|
|
step={0.5}
|
|
step={0.5}
|
|
- value={props.value || 1.5}
|
|
|
|
|
|
+ value={value || 1.5}
|
|
onChange={(value: any) => {
|
|
onChange={(value: any) => {
|
|
if (!value) {
|
|
if (!value) {
|
|
emit("change", 1.5);
|
|
emit("change", 1.5);
|
|
@@ -282,9 +190,6 @@ export const LineHeightComp = defineComponent({
|
|
},
|
|
},
|
|
});
|
|
});
|
|
export const FontStyleWapper = defineComponent({
|
|
export const FontStyleWapper = defineComponent({
|
|
- props: {
|
|
|
|
- editor: any(),
|
|
|
|
- },
|
|
|
|
emits: ["change"],
|
|
emits: ["change"],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
const fontStyleColumns = [
|
|
const fontStyleColumns = [
|
|
@@ -322,11 +227,10 @@ export const FontStyleWapper = defineComponent({
|
|
column={{
|
|
column={{
|
|
label: e.label,
|
|
label: e.label,
|
|
dataIndex: e.dataIndex,
|
|
dataIndex: e.dataIndex,
|
|
- component: (props) => (
|
|
|
|
- <FontStyleComp icon={e.icon} {...props} />
|
|
|
|
- ),
|
|
|
|
|
|
+ component: (props) => {
|
|
|
|
+ return <FontStyleComp icon={e.icon} {...props} />;
|
|
|
|
+ },
|
|
}}
|
|
}}
|
|
- editor={props.editor}
|
|
|
|
onChange={changeVal}
|
|
onChange={changeVal}
|
|
/>
|
|
/>
|
|
);
|
|
);
|
|
@@ -342,17 +246,15 @@ export const FontStyleComp = defineComponent({
|
|
},
|
|
},
|
|
emits: ["change"],
|
|
emits: ["change"],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
- const triggerStyle = () => {
|
|
|
|
- emit("change", !props.value);
|
|
|
|
- };
|
|
|
|
return () => {
|
|
return () => {
|
|
- console.log(props.value);
|
|
|
|
return (
|
|
return (
|
|
<Button
|
|
<Button
|
|
type="text"
|
|
type="text"
|
|
class={props.value ? currStyle : null}
|
|
class={props.value ? currStyle : null}
|
|
icon={props.icon}
|
|
icon={props.icon}
|
|
- onClick={triggerStyle}
|
|
|
|
|
|
+ onClick={() => {
|
|
|
|
+ emit("change", !props.value);
|
|
|
|
+ }}
|
|
></Button>
|
|
></Button>
|
|
);
|
|
);
|
|
};
|
|
};
|
|
@@ -387,7 +289,7 @@ export const FontFamily = defineComponent({
|
|
});
|
|
});
|
|
export const FontSize = defineComponent({
|
|
export const FontSize = defineComponent({
|
|
props: {
|
|
props: {
|
|
- value: string().def("12px"),
|
|
|
|
|
|
+ value: any().def("12px"),
|
|
},
|
|
},
|
|
emits: ["change"],
|
|
emits: ["change"],
|
|
setup(props, { emit }) {
|
|
setup(props, { emit }) {
|
|
@@ -435,29 +337,41 @@ export const TextToolItem = defineComponent({
|
|
props: {
|
|
props: {
|
|
column: object<ColumnItem>(),
|
|
column: object<ColumnItem>(),
|
|
index: number(),
|
|
index: number(),
|
|
- editor: any(),
|
|
|
|
onChange: func(),
|
|
onChange: func(),
|
|
},
|
|
},
|
|
setup(props) {
|
|
setup(props) {
|
|
const state = reactive({
|
|
const state = reactive({
|
|
value: undefined,
|
|
value: undefined,
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ const { controls } = useEditor();
|
|
|
|
+ let editor: any = null;
|
|
|
|
+ watch(
|
|
|
|
+ () => controls.textEditorCtrl.state.currEditor,
|
|
|
|
+ () => {
|
|
|
|
+ editor = toRaw(controls.textEditorCtrl.state.currEditor);
|
|
|
|
+ initCommands();
|
|
|
|
+ }
|
|
|
|
+ );
|
|
function handleValueChange() {
|
|
function handleValueChange() {
|
|
- const { column, editor } = props;
|
|
|
|
- const command = editor ? editor.commands.get(column?.dataIndex) : "";
|
|
|
|
|
|
+ const { column } = props;
|
|
|
|
+ if (!editor) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const command = editor.commands.get(column?.dataIndex);
|
|
if (command) {
|
|
if (command) {
|
|
- console.log("change==>", column?.dataIndex, state.value);
|
|
|
|
state.value = command.value;
|
|
state.value = command.value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const initCommands = () => {
|
|
const initCommands = () => {
|
|
- const { column, editor } = props;
|
|
|
|
- const { controls } = useEditor();
|
|
|
|
- const command = editor ? editor.commands.get(column?.dataIndex) : "";
|
|
|
|
- console.log(column?.dataIndex, controls.textEditor);
|
|
|
|
|
|
+ const { column } = props;
|
|
|
|
+ if (!editor) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const command = editor.commands.get(column?.dataIndex);
|
|
if (command) {
|
|
if (command) {
|
|
|
|
+ console.log("init", column?.dataIndex, command.value);
|
|
state.value = command.value;
|
|
state.value = command.value;
|
|
-
|
|
|
|
command.on("change:value", handleValueChange);
|
|
command.on("change:value", handleValueChange);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
@@ -465,8 +379,11 @@ export const TextToolItem = defineComponent({
|
|
initCommands();
|
|
initCommands();
|
|
});
|
|
});
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
- const { column, editor } = props;
|
|
|
|
- const command = editor ? editor.commands.get(column?.dataIndex) : "";
|
|
|
|
|
|
+ const { column } = props;
|
|
|
|
+ if (!editor) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const command = editor.commands.get(column?.dataIndex);
|
|
if (command) {
|
|
if (command) {
|
|
command.off("change:value", handleValueChange);
|
|
command.off("change:value", handleValueChange);
|
|
}
|
|
}
|