diff --git a/CHANGELOG.md b/CHANGELOG.md index 469e09a..0f187da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ + +## 0.11.4 + +修复参考线bug + +优化拖拽算法 + + ## 0.11.3 增加旋转回正功能。 diff --git a/packages/dooringx-dumi-doc/docs/ChangeLog/index.en.md b/packages/dooringx-dumi-doc/docs/ChangeLog/index.en.md index 4a8f772..7b6cf64 100644 --- a/packages/dooringx-dumi-doc/docs/ChangeLog/index.en.md +++ b/packages/dooringx-dumi-doc/docs/ChangeLog/index.en.md @@ -5,6 +5,9 @@ nav: title: change log order: 6 --- +## 0.11.4 +Fix guide line bug +Optimized drag and drop algorithm ## 0.11.3 Add rotation return function. Optimize mouse style. diff --git a/packages/dooringx-dumi-doc/docs/ChangeLog/index.md b/packages/dooringx-dumi-doc/docs/ChangeLog/index.md index 0e105d8..0607981 100644 --- a/packages/dooringx-dumi-doc/docs/ChangeLog/index.md +++ b/packages/dooringx-dumi-doc/docs/ChangeLog/index.md @@ -5,6 +5,14 @@ nav: title: 变更日志 order: 6 --- + +## 0.11.4 + +修复参考线bug + +优化拖拽算法 + + ## 0.11.3 增加旋转回正功能。 diff --git a/packages/dooringx-lib/package.json b/packages/dooringx-lib/package.json index aab9ade..5cc6486 100644 --- a/packages/dooringx-lib/package.json +++ b/packages/dooringx-lib/package.json @@ -1,5 +1,5 @@ { - "version": "0.11.3", + "version": "0.11.4", "license": "MIT", "main": "dist/index.js", "module": "dist/dooringx-lib.esm.js", diff --git a/packages/dooringx-lib/src/core/markline/calcRender.ts b/packages/dooringx-lib/src/core/markline/calcRender.ts index a8b9cd1..51f1582 100644 --- a/packages/dooringx-lib/src/core/markline/calcRender.ts +++ b/packages/dooringx-lib/src/core/markline/calcRender.ts @@ -6,7 +6,7 @@ * @FilePath: \dooringx\packages\dooringx-lib\src\core\markline\calcRender.ts */ import { innerDragState } from '../innerDrag/state'; -import { newMarklineDisplay } from './normalMode'; +import { marklineDisplay, newMarklineDisplay } from './normalMode'; import { marklineConfig } from './marklineConfig'; import UserConfig from '../../config'; import { angleToRadian, binarySearchRemain, getContainer } from '../utils'; @@ -125,6 +125,13 @@ export function marklineCalRender(config: UserConfig, iframe: boolean): LinesTyp return a.right - b.right; }); } + // 划线的元素不应该冲突 + // 当横向或者纵向已经吸附过,则后续不进行吸附,差值为0则划线。 + // 未吸附过时的第一次划线会带吸附,后续按上述走 + const dirty = { + dirtyX: false, + dirtyY: false, + }; const indexLeft = binarySearchRemain( realStyle.left, marklineState.sortLeft, @@ -132,7 +139,77 @@ export function marklineCalRender(config: UserConfig, iframe: boolean): LinesTyp marklineConfig.indent ); if (indexLeft) { - newMarklineDisplay(realStyle, indexLeft, lines, focus); + marklineDisplay(realStyle, indexLeft[0], lines, focus, indexLeft[1], dirty, 'left'); + } + + const indexLeftRight = binarySearchRemain( + realStyle.left, + marklineState.sortRight, + 'right', + marklineConfig.indent + ); + if (indexLeftRight) { + marklineDisplay( + realStyle, + indexLeftRight[0], + lines, + focus, + indexLeftRight[1], + dirty, + 'l-r' + ); + } + const indexRightLeft = binarySearchRemain( + realStyle.right, + marklineState.sortLeft, + 'left', + marklineConfig.indent + ); + if (indexRightLeft) { + marklineDisplay( + realStyle, + indexRightLeft[0], + lines, + focus, + indexRightLeft[1], + dirty, + 'r-l' + ); + } + + const indexTopBottom = binarySearchRemain( + realStyle.top, + marklineState.sortBottom, + 'bottom', + marklineConfig.indent + ); + if (indexTopBottom) { + marklineDisplay( + realStyle, + indexTopBottom[0], + lines, + focus, + indexTopBottom[1], + dirty, + 't-b' + ); + } + const indexBottomTop = binarySearchRemain( + realStyle.bottom, + marklineState.sortTop, + 'top', + marklineConfig.indent + ); + if (indexBottomTop) { + marklineDisplay( + realStyle, + indexBottomTop[0], + lines, + focus, + indexBottomTop[1], + dirty, + 'b-t' + ); } const indexTop = binarySearchRemain( realStyle.top, @@ -141,7 +218,7 @@ export function marklineCalRender(config: UserConfig, iframe: boolean): LinesTyp marklineConfig.indent ); if (indexTop) { - newMarklineDisplay(realStyle, indexTop, lines, focus); + marklineDisplay(realStyle, indexTop[0], lines, focus, indexTop[1], dirty, 'top'); } const indexRight = binarySearchRemain( realStyle.right, @@ -150,7 +227,7 @@ export function marklineCalRender(config: UserConfig, iframe: boolean): LinesTyp marklineConfig.indent ); if (indexRight) { - newMarklineDisplay(realStyle, indexRight, lines, focus); + marklineDisplay(realStyle, indexRight[0], lines, focus, indexRight[1], dirty, 'right'); } const indexBottom = binarySearchRemain( realStyle.bottom, @@ -159,7 +236,7 @@ export function marklineCalRender(config: UserConfig, iframe: boolean): LinesTyp marklineConfig.indent ); if (indexBottom) { - newMarklineDisplay(realStyle, indexBottom, lines, focus); + marklineDisplay(realStyle, indexBottom[0], lines, focus, indexBottom[1], dirty, 'bottom'); } } else { for (let i = 0; i < len; i++) { diff --git a/packages/dooringx-lib/src/core/markline/normalMode.ts b/packages/dooringx-lib/src/core/markline/normalMode.ts index f6f5324..f406751 100644 --- a/packages/dooringx-lib/src/core/markline/normalMode.ts +++ b/packages/dooringx-lib/src/core/markline/normalMode.ts @@ -11,6 +11,134 @@ export interface RealStyle { bottom: number; } +/** + * + * + * @export 吸附间距之前已经算出,该函数直接做处理 + * @param {RealStyle} focusStyle + * @param {RealStyle} unFocusStyle + * @param {LinesTypes} lines + * @param {IBlockType} focus + * @param {number} diff 绝对值 + * @param {('left' | 'top' | 'bottom' | 'right' | 't-b' | 'b-t' | 'l-r' | 'r-l')} direction + */ +export function marklineDisplay( + focusStyle: RealStyle, + unFocusStyle: RealStyle, + lines: LinesTypes, + focus: IBlockType, + diff: number, + dirty: { dirtyX: boolean; dirtyY: boolean }, + direction: 'left' | 'top' | 'bottom' | 'right' | 't-b' | 'b-t' | 'l-r' | 'r-l' +) { + const { top, height, left, width } = focusStyle; + let { dirtyX, dirtyY } = dirty; + const { top: t, height: h, left: l, width: w } = unFocusStyle; + let diffY = 0; + let diffX = 0; + switch (direction) { + case 'left': + if (dirtyY) { + if (diff === 0) { + lines.y.push(l); + } + } else { + lines.y.push(l); + diffX = l - left; + dirtyY = true; + } + break; + case 'right': + if (dirtyY) { + if (diff === 0) { + lines.y.push(l + w); + } + } else { + lines.y.push(l + w); + diffX = l + w - left - width; + dirtyY = true; + } + break; + case 'l-r': + if (dirtyY) { + if (diff === 0) { + lines.y.push(l + w); + } + } else { + lines.y.push(l + w); + diffX = l + w - left; + dirtyY = true; + } + break; + case 'r-l': + if (dirtyY) { + if (diff === 0) { + lines.y.push(l); + } + } else { + lines.y.push(l); + diffX = l - (left + width); + dirtyY = true; + } + break; + case 'top': + if (dirtyX) { + if (diff === 0) { + lines.x.push(t); + } + } else { + lines.x.push(t); + diffY = t - top; + dirtyX = true; + } + break; + case 'bottom': + if (dirtyX) { + if (diff === 0) { + lines.x.push(t + h); + } + } else { + lines.x.push(t + h); + diffY = (t + h - top - height) / 2; + dirtyX = true; + } + break; + case 't-b': + if (dirtyX) { + if (diff === 0) { + lines.x.push(t + h); + } + } else { + lines.x.push(t + h); + diffY = (t + h - top) / 2; + dirtyX = true; + } + break; + case 'b-t': + if (dirtyX) { + if (diff === 0) { + lines.x.push(t); + } + } else { + lines.x.push(t); + diffY = t - (top + height); + dirtyX = true; + } + break; + } + focus.top = Math.round(focus.top + diffY); + focus.left = Math.round(focus.left + diffX); +} + +/** + * + * 第一次运算时需要 + * @export + * @param {RealStyle} focusStyle + * @param {RealStyle} unFocusStyle + * @param {LinesTypes} lines + * @param {IBlockType} focus + */ export function newMarklineDisplay( focusStyle: RealStyle, unFocusStyle: RealStyle, @@ -116,6 +244,10 @@ export function newMarklineDisplay( focus.left = Math.round(focus.left + diffX); } +/** + * + * @deprecated + */ export function switchMarklineDisplay( l: number, t: number, @@ -303,6 +435,9 @@ export function switchMarklineDisplay( } } +/** + * @todo 暂时无效 + */ export function switchMarklineResizeDisplay( l: number, t: number, diff --git a/packages/dooringx-lib/src/core/utils/index.ts b/packages/dooringx-lib/src/core/utils/index.ts index 4ea8734..7cf6932 100644 --- a/packages/dooringx-lib/src/core/utils/index.ts +++ b/packages/dooringx-lib/src/core/utils/index.ts @@ -316,14 +316,14 @@ export function binarySearchRemain>( arr: Array, attribute: keyof T, indent: number -) { +): null | [T, number] { let start = 0; let end = arr.length - 1; while (start <= end) { - var mid = parseInt(start + (end - start) / 2 + ''); + let mid = parseInt(start + (end - start) / 2 + ''); if (target === arr[mid][attribute] || Math.abs(target - arr[mid][attribute]) < indent) { - return arr[mid]; + return [arr[mid], Math.abs(target - arr[mid][attribute])]; } else if (target > arr[mid][attribute]) { start = mid + 1; } else { diff --git a/packages/dooringx-plugin-template/package.json b/packages/dooringx-plugin-template/package.json index 28d69b9..2d00b8f 100644 --- a/packages/dooringx-plugin-template/package.json +++ b/packages/dooringx-plugin-template/package.json @@ -1,6 +1,6 @@ { "name": "dooringx-plugin-template", - "version": "0.11.3", + "version": "0.11.4", "description": "> TODO: description", "author": "yehuozhili <673632758@qq.com>", "homepage": "https://github.com/H5-Dooring/dooringx#readme", diff --git a/packages/dooringx-plugin-template/template/template.json b/packages/dooringx-plugin-template/template/template.json index f504de4..28ad377 100644 --- a/packages/dooringx-plugin-template/template/template.json +++ b/packages/dooringx-plugin-template/template/template.json @@ -40,7 +40,7 @@ "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@svgr/rollup": "^5.5.0", - "dooringx-lib": "^0.11.3", + "dooringx-lib": "^0.11.4", "postcss": "^8.3.6", "rollup-plugin-peer-deps-external": "^2.2.4", "rollup-plugin-postcss": "^4.0.1",