|
@@ -7,8 +7,10 @@ import {
|
|
getRectSnapPoints,
|
|
getRectSnapPoints,
|
|
} from "../util.ts";
|
|
} from "../util.ts";
|
|
import { getMouseColors } from "@/utils/colors.ts";
|
|
import { getMouseColors } from "@/utils/colors.ts";
|
|
-import { InteractiveFix, InteractiveTo } from "../index.ts";
|
|
|
|
-import { Size } from "@/utils/math.ts";
|
|
|
|
|
|
+import { InteractiveFix, InteractiveTo, MatResponseProps } from "../index.ts";
|
|
|
|
+import { numEq, Size } from "@/utils/math.ts";
|
|
|
|
+import { copy } from "@/utils/shared.ts";
|
|
|
|
+import { MathUtils } from "three";
|
|
|
|
|
|
export { default as Component } from "./table.vue";
|
|
export { default as Component } from "./table.vue";
|
|
export { default as TempComponent } from "./temp-table.vue";
|
|
export { default as TempComponent } from "./temp-table.vue";
|
|
@@ -32,16 +34,18 @@ export const defaultCollData = {
|
|
|
|
|
|
export const addMode = "area";
|
|
export const addMode = "area";
|
|
|
|
|
|
-export type TableCollData = Partial<typeof defaultCollData> & Size & {
|
|
|
|
- content: string;
|
|
|
|
- padding: number
|
|
|
|
- readonly?: boolean
|
|
|
|
- notdel?: boolean
|
|
|
|
-};
|
|
|
|
|
|
+export type TableCollData = Partial<typeof defaultCollData> &
|
|
|
|
+ Size & {
|
|
|
|
+ content: string;
|
|
|
|
+ padding: number;
|
|
|
|
+ readonly?: boolean;
|
|
|
|
+ notdel?: boolean;
|
|
|
|
+ };
|
|
export type TableData = Partial<typeof defaultStyle> &
|
|
export type TableData = Partial<typeof defaultStyle> &
|
|
- BaseItem & Size & {
|
|
|
|
- notaddRow?: boolean
|
|
|
|
- notaddCol?: boolean
|
|
|
|
|
|
+ BaseItem &
|
|
|
|
+ Size & {
|
|
|
|
+ notaddRow?: boolean;
|
|
|
|
+ notaddCol?: boolean;
|
|
mat: number[];
|
|
mat: number[];
|
|
content: TableCollData[][];
|
|
content: TableCollData[][];
|
|
};
|
|
};
|
|
@@ -59,9 +63,10 @@ export const getMouseStyle = (data: TableData) => {
|
|
|
|
|
|
export const getSnapPoints = (data: TableData) => {
|
|
export const getSnapPoints = (data: TableData) => {
|
|
const tf = new Transform(data.mat);
|
|
const tf = new Transform(data.mat);
|
|
- const points = getRectSnapPoints(data.width, data.height, 0, 0)
|
|
|
|
- .map((v) => tf.point(v));
|
|
|
|
- return points
|
|
|
|
|
|
+ const points = getRectSnapPoints(data.width, data.height, 0, 0).map((v) =>
|
|
|
|
+ tf.point(v)
|
|
|
|
+ );
|
|
|
|
+ return points;
|
|
};
|
|
};
|
|
|
|
|
|
export const getSnapInfos = (data: TableData) => {
|
|
export const getSnapInfos = (data: TableData) => {
|
|
@@ -88,22 +93,22 @@ export const autoCollHeight = 50;
|
|
export const interactiveFixData: InteractiveFix<"table"> = ({
|
|
export const interactiveFixData: InteractiveFix<"table"> = ({
|
|
data,
|
|
data,
|
|
info,
|
|
info,
|
|
- notdraw
|
|
|
|
|
|
+ notdraw,
|
|
}) => {
|
|
}) => {
|
|
if (info.cur) {
|
|
if (info.cur) {
|
|
const area = info.cur!;
|
|
const area = info.cur!;
|
|
const origin = {
|
|
const origin = {
|
|
x: Math.min(area[0].x, area[1].x),
|
|
x: Math.min(area[0].x, area[1].x),
|
|
y: Math.min(area[0].y, area[1].y),
|
|
y: Math.min(area[0].y, area[1].y),
|
|
- }
|
|
|
|
- data.width = Math.abs(area[0].x - area[1].x)
|
|
|
|
- data.height = Math.abs(area[0].y - area[1].y)
|
|
|
|
-
|
|
|
|
|
|
+ };
|
|
|
|
+ data.width = Math.abs(area[0].x - area[1].x);
|
|
|
|
+ data.height = Math.abs(area[0].y - area[1].y);
|
|
|
|
+
|
|
if (!notdraw || !(data.content?.length && data.content[0].length)) {
|
|
if (!notdraw || !(data.content?.length && data.content[0].length)) {
|
|
const colNum = Math.floor(data.width / autoCollWidth) || 1;
|
|
const colNum = Math.floor(data.width / autoCollWidth) || 1;
|
|
const rawNum = Math.floor(data.height / autoCollHeight) || 1;
|
|
const rawNum = Math.floor(data.height / autoCollHeight) || 1;
|
|
const temp = data.content?.[0]?.[0] || {
|
|
const temp = data.content?.[0]?.[0] || {
|
|
- content: ""
|
|
|
|
|
|
+ content: "",
|
|
};
|
|
};
|
|
|
|
|
|
data.content = Array.from({ length: rawNum }, () =>
|
|
data.content = Array.from({ length: rawNum }, () =>
|
|
@@ -111,22 +116,88 @@ export const interactiveFixData: InteractiveFix<"table"> = ({
|
|
...temp,
|
|
...temp,
|
|
width: data.width / colNum,
|
|
width: data.width / colNum,
|
|
height: data.height / rawNum,
|
|
height: data.height / rawNum,
|
|
- padding: 8
|
|
|
|
|
|
+ padding: 8,
|
|
}))
|
|
}))
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
- const colHeight = data.height / data.content.length
|
|
|
|
- const colWidth = data.width / data.content[0].length
|
|
|
|
- data.content.forEach(row => {
|
|
|
|
- row.forEach(col => {
|
|
|
|
- col.width = colWidth
|
|
|
|
- col.height = colHeight
|
|
|
|
- col.padding = 8
|
|
|
|
- console.log(col.content)
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
|
|
+ const colHeight = data.height / data.content.length;
|
|
|
|
+ const colWidth = data.width / data.content[0].length;
|
|
|
|
+ data.content.forEach((row) => {
|
|
|
|
+ row.forEach((col) => {
|
|
|
|
+ col.width = colWidth;
|
|
|
|
+ col.height = colHeight;
|
|
|
|
+ col.padding = 8;
|
|
|
|
+ console.log(col.content);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
}
|
|
}
|
|
data.mat = new Transform().translate(origin.x, origin.y).m;
|
|
data.mat = new Transform().translate(origin.x, origin.y).m;
|
|
}
|
|
}
|
|
return data;
|
|
return data;
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+export const getColMinSize = (col: TableCollData) => {
|
|
|
|
+ const minw = (col.padding || 0) * 2 + (col.fontSize || 12) + 4;
|
|
|
|
+ const minh = (col.padding || 0) * 2 + (col.fontSize || 12) + 4;
|
|
|
|
+ return { w: minw, h: minh };
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const matResponse = (
|
|
|
|
+ { data, mat, operType, increment }: MatResponseProps<"table">,
|
|
|
|
+ initData?: TableData
|
|
|
|
+) => {
|
|
|
|
+ if (!initData) {
|
|
|
|
+ initData = copy(data);
|
|
|
|
+ }
|
|
|
|
+ if (increment) {
|
|
|
|
+ mat = mat.copy().multiply(new Transform(data.mat))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const dec = mat.decompose();
|
|
|
|
+ const oldData = copy(data);
|
|
|
|
+ data.height = dec.scaleY * initData.height;
|
|
|
|
+ data.width = dec.scaleX * initData.width;
|
|
|
|
+
|
|
|
|
+ let w = 0;
|
|
|
|
+ let h = 0;
|
|
|
|
+ data.content.forEach((row, rndx) => {
|
|
|
|
+ row.forEach((col, cndx) => {
|
|
|
|
+ const initCol = initData.content[rndx][cndx];
|
|
|
|
+ const minSize = getColMinSize(initCol);
|
|
|
|
+ col.width = Math.max(
|
|
|
|
+ minSize.w,
|
|
|
|
+ data.width * (initCol.width / initData.width)
|
|
|
|
+ );
|
|
|
|
+ col.height = Math.max(
|
|
|
|
+ minSize.h,
|
|
|
|
+ data.height * (initCol.height / initData.height)
|
|
|
|
+ );
|
|
|
|
+ if (rndx === 0) {
|
|
|
|
+ w += col.width;
|
|
|
|
+ }
|
|
|
|
+ if (cndx === 0) {
|
|
|
|
+ h += col.height;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ const eqW = numEq(w, data.width);
|
|
|
|
+ const eqH = numEq(h, data.height);
|
|
|
|
+
|
|
|
|
+ if (!eqW || !eqH) {
|
|
|
|
+ if (operType) {
|
|
|
|
+ Object.assign(data, oldData);
|
|
|
|
+ } else {
|
|
|
|
+ data.width = w;
|
|
|
|
+ data.height = h;
|
|
|
|
+ const initDec = new Transform(initData.mat).decompose();
|
|
|
|
+ data.mat = new Transform()
|
|
|
|
+ .translate(eqW ? dec.x : initDec.x, eqH ? dec.y : initDec.y)
|
|
|
|
+ .rotate(MathUtils.degToRad(dec.rotation)).m;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ data.mat = new Transform()
|
|
|
|
+ .translate(dec.x, dec.y)
|
|
|
|
+ .rotate(MathUtils.degToRad(dec.rotation)).m;
|
|
|
|
+ }
|
|
|
|
+ return data;
|
|
|
|
+};
|