update 0.12.4

This commit is contained in:
hufeixiong
2022-02-15 18:02:32 +08:00
parent 012b578519
commit 958ddd3a09
12 changed files with 89 additions and 33 deletions

View File

@@ -1,3 +1,9 @@
## 0.12.4
添加生命周期。
修改timeline颜色及样式优化选中状态。
## 0.12.3 ## 0.12.3
修复双击定位问题 修复双击定位问题

View File

@@ -5,6 +5,9 @@ nav:
title: change log title: change log
order: 6 order: 6
--- ---
## 0.12.4
Add a lifecycle.
Modify the timeline color and style to optimize the selected state.
## 0.12.3 ## 0.12.3
Fix double click positioning problem Fix double click positioning problem
## 0.12.2 ## 0.12.2

View File

@@ -5,6 +5,12 @@ nav:
title: 变更日志 title: 变更日志
order: 6 order: 6
--- ---
## 0.12.4
添加生命周期。
修改timeline颜色及样式优化选中状态。
## 0.12.3 ## 0.12.3
修复双击定位问题 修复双击定位问题

View File

@@ -1,5 +1,5 @@
{ {
"version": "0.12.3", "version": "0.12.4",
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/dooringx-lib.esm.js", "module": "dist/dooringx-lib.esm.js",

View File

@@ -4,7 +4,7 @@ import { innerContainerDrag } from '../core/innerDrag';
import { NormalMarkLineRender } from '../core/markline'; import { NormalMarkLineRender } from '../core/markline';
import { IStoreData } from '../core/store/storetype'; import { IStoreData } from '../core/store/storetype';
import { wrapperMoveState } from './wrapperMove/event'; import { wrapperMoveState } from './wrapperMove/event';
import { CSSProperties, PropsWithChildren, useMemo, useState } from 'react'; import { CSSProperties, PropsWithChildren, useEffect, useMemo, useState } from 'react';
import Blocks from './blocks'; import Blocks from './blocks';
import { containerResizer } from '../core/resizeHandler/containerResizer'; import { containerResizer } from '../core/resizeHandler/containerResizer';
import React from 'react'; import React from 'react';
@@ -42,6 +42,19 @@ function Container(props: PropsWithChildren<ContainerProps>) {
forceUpdate((p) => p + 1); forceUpdate((p) => p + 1);
}; };
useEffect(() => {
if (props.context === 'preview') {
props.config.onMounted();
props.config.onMountedFn.forEach((v) => v());
}
return () => {
if (props.context === 'preview') {
props.config.destroyed();
props.config.destroyedFn.forEach((v) => v());
}
};
}, [props.config, props.context]);
return ( return (
<> <>
{props.context === 'edit' && ( {props.context === 'edit' && (

View File

@@ -49,6 +49,8 @@ function Preview(props: PreviewProps): ReactElement {
useEffect(() => { useEffect(() => {
const finalFn = () => { const finalFn = () => {
props.config.created();
props.config.createdFn.forEach((v) => v());
setTimeout(() => { setTimeout(() => {
// 链接数据 // 链接数据
props.config props.config
@@ -67,6 +69,8 @@ function Preview(props: PreviewProps): ReactElement {
if (props.completeFn) { if (props.completeFn) {
props.completeFn(); props.completeFn();
} }
props.config.beforeOnMounted();
props.config.beforeOnMountedFn.forEach((v) => v());
if (props.loadingState === undefined) { if (props.loadingState === undefined) {
setLoading(false); setLoading(false);
} }

View File

@@ -27,6 +27,7 @@ import {
TimeLineItemMouseOver, TimeLineItemMouseOver,
interval, interval,
iter, iter,
resetCurrentMoveItemId,
} from './timelineItem'; } from './timelineItem';
import { specialCoList } from '../../core/utils/special'; import { specialCoList } from '../../core/utils/special';
import { replaceLocale } from '../../locale'; import { replaceLocale } from '../../locale';
@@ -454,6 +455,12 @@ export function TimeLine(props: TimeLineProps) {
flexDirection: 'column', flexDirection: 'column',
...props.style, ...props.style,
}} }}
onMouseDown={(e) => {
const dom = e.target as HTMLDivElement;
if (!(dom.className && dom.className.indexOf('yh-timeline-item-mainblock') > -1)) {
resetCurrentMoveItemId();
}
}}
> >
<> <>
<div <div

View File

@@ -7,6 +7,7 @@
*/ */
import React, { CSSProperties } from 'react'; import React, { CSSProperties } from 'react';
import { AnimateItem } from '../../core/store/storetype'; import { AnimateItem } from '../../core/store/storetype';
import { randomColor } from '../../core/utils';
export const iter = 500; export const iter = 500;
export const itemHeight = 25; export const itemHeight = 25;
@@ -20,19 +21,6 @@ const times = interval + 1;
export interface TimeLineItemProps { export interface TimeLineItemProps {
animate: AnimateItem[]; animate: AnimateItem[];
} }
const bgColor = [
'#4af',
'rgb(93, 128, 158)',
'rgb(158, 130, 93)',
'rgb(219, 72, 34)',
'rgb(255, 68, 168)',
'#4af',
'rgb(93, 128, 158)',
'rgb(158, 130, 93)',
'rgb(219, 72, 34)',
'rgb(255, 68, 168)',
];
interface MoveStateTypes { interface MoveStateTypes {
startX: number; startX: number;
isMove: boolean; isMove: boolean;
@@ -47,6 +35,7 @@ const moveState: MoveStateTypes = {
interface resizeStateTypes extends MoveStateTypes { interface resizeStateTypes extends MoveStateTypes {
left: boolean; left: boolean;
} }
let currentMoveItemId = '';
const resizeState: resizeStateTypes = { const resizeState: resizeStateTypes = {
startX: 0, startX: 0,
@@ -118,6 +107,9 @@ export const TimeLineItemMouseOver = function () {
resizeState.startX = 0; resizeState.startX = 0;
resizeState.uid = ''; resizeState.uid = '';
}; };
export const resetCurrentMoveItemId = () => {
currentMoveItemId = '';
};
const commonCss: CSSProperties = { const commonCss: CSSProperties = {
transform: `rotate(45deg)`, transform: `rotate(45deg)`,
@@ -129,6 +121,8 @@ const commonCss: CSSProperties = {
cursor: 'e-resize', cursor: 'e-resize',
}; };
const bgColorCache: Record<string, string> = {};
export function TimeLineItem(props: TimeLineItemProps) { export function TimeLineItem(props: TimeLineItemProps) {
return ( return (
<> <>
@@ -137,7 +131,10 @@ export function TimeLineItem(props: TimeLineItemProps) {
const repeat = const repeat =
v.animationIterationCount === 'infinite' ? iter : parseInt(v.animationIterationCount); v.animationIterationCount === 'infinite' ? iter : parseInt(v.animationIterationCount);
const width = v.animationDuration * times * repeat; const width = v.animationDuration * times * repeat;
const index = v.uid.charCodeAt(0) % 10;
if (!bgColorCache[v.uid]) {
bgColorCache[v.uid] = randomColor();
}
return ( return (
<div <div
key={v.uid} key={v.uid}
@@ -145,18 +142,24 @@ export function TimeLineItem(props: TimeLineItemProps) {
moveState.startX = e.clientX; moveState.startX = e.clientX;
moveState.uid = v.uid; moveState.uid = v.uid;
moveState.isMove = true; moveState.isMove = true;
currentMoveItemId = v.uid;
}} }}
className="yh-timeline-item-mainblock"
style={{ style={{
position: 'absolute', position: 'absolute',
top: diff / 2, top: diff / 2,
left: left, left: left,
width: width, width: width,
height: itemHeight - diff, height: itemHeight - diff,
background: bgColor[index], background: bgColorCache[v.uid],
zIndex: 1, zIndex: 1,
cursor: 'move', cursor: 'move',
borderRadius: '4px',
opacity: v.uid === currentMoveItemId ? 1 : 0.7,
}} }}
> >
{v.uid === currentMoveItemId && (
<>
<div <div
className="yh-timeline-item-left" className="yh-timeline-item-left"
style={{ ...commonCss, left: -square }} style={{ ...commonCss, left: -square }}
@@ -171,6 +174,8 @@ export function TimeLineItem(props: TimeLineItemProps) {
resizeMouseDown(e, v, false); resizeMouseDown(e, v, false);
}} }}
></div> ></div>
</>
)}
</div> </div>
); );
})} })}

View File

@@ -364,6 +364,14 @@ export class UserConfig {
current: 0, current: 0,
isRefresh: true, isRefresh: true,
}; };
public createdFn: Function[] = [];
public created: Function = () => {};
public beforeOnMountedFn: Function[] = [];
public beforeOnMounted: Function = () => {};
public onMountedFn: Function[] = [];
public onMounted: Function = () => {};
public destroyedFn: Function[] = [];
public destroyed: Function = () => {};
public blockForceUpdate: Array<Function> = []; public blockForceUpdate: Array<Function> = [];
public waitAnimate = false; public waitAnimate = false;
public wrapperMoveState = wrapperMoveState; public wrapperMoveState = wrapperMoveState;

View File

@@ -17,6 +17,10 @@ export function swap(indexa: number, indexb: number, arr: Array<any>) {
return arr; return arr;
} }
export function randomColor() {
return '#' + ('00000' + ((Math.random() * 0x1000000) << 0).toString(16)).slice(-6);
}
// 将rgba字符串对象转化为rgba对象 // 将rgba字符串对象转化为rgba对象
export function rgba2Obj(rgba = '') { export function rgba2Obj(rgba = '') {
let reg = /rgba\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?\)/g; let reg = /rgba\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?\)/g;

View File

@@ -1,6 +1,6 @@
{ {
"name": "dooringx-plugin-template", "name": "dooringx-plugin-template",
"version": "0.12.3", "version": "0.12.4",
"description": "> TODO: description", "description": "> TODO: description",
"author": "yehuozhili <673632758@qq.com>", "author": "yehuozhili <673632758@qq.com>",
"homepage": "https://github.com/H5-Dooring/dooringx#readme", "homepage": "https://github.com/H5-Dooring/dooringx#readme",

View File

@@ -40,7 +40,7 @@
"@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-url": "^6.1.0", "@rollup/plugin-url": "^6.1.0",
"@svgr/rollup": "^5.5.0", "@svgr/rollup": "^5.5.0",
"dooringx-lib": "^0.12.3", "dooringx-lib": "^0.12.4",
"postcss": "^8.3.6", "postcss": "^8.3.6",
"rollup-plugin-peer-deps-external": "^2.2.4", "rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.1", "rollup-plugin-postcss": "^4.0.1",