@lazlon-platform/html-editor 0.7.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/model/index.ts +8 -5
- package/lib/model/node/shapeNode/index.ts +2 -2
- package/lib/model/node/shapeNode/shape.ts +39 -42
- package/lib/ui/node/ShapeContent/ArrowContent.tsx +2 -2
- package/lib/ui/node/ShapeContent/PolygonContent.tsx +2 -2
- package/lib/ui/node/ShapeContent/RectangleContent.tsx +2 -5
- package/lib/ui/node/ShapeContent/StarContent.tsx +2 -2
- package/package.json +1 -1
package/lib/model/index.ts
CHANGED
|
@@ -7,13 +7,16 @@ export { GroupNode, type GroupNodeProps } from "./node/groupNode"
|
|
|
7
7
|
export { ImageNode, type ImageNodeProps } from "./node/imageNode"
|
|
8
8
|
export { LineNode, type LineNodeProps } from "./node/lineNode"
|
|
9
9
|
export {
|
|
10
|
-
ShapeNode,
|
|
11
|
-
type ShapeNodeProps,
|
|
12
|
-
newRectangleShape,
|
|
13
|
-
newPolygonShape,
|
|
14
|
-
newEllipseShape,
|
|
15
10
|
newArrowShape,
|
|
11
|
+
newEllipseShape,
|
|
12
|
+
newPolygonShape,
|
|
13
|
+
newRectangleShape,
|
|
16
14
|
newStarShape,
|
|
15
|
+
ShapeNode,
|
|
16
|
+
type ShapeEnum,
|
|
17
|
+
type ShapeNodeProps,
|
|
18
|
+
type Shape,
|
|
19
|
+
type Shapes,
|
|
17
20
|
} from "./node/shapeNode"
|
|
18
21
|
export { TextNode, type TextNodeProps } from "./node/textNode"
|
|
19
22
|
export { Page, type PageProps, type SerializedPage } from "./page"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { state } from "react-bolt"
|
|
2
2
|
import type { Page } from "../../page"
|
|
3
3
|
import { EditableNode, type EditableNodeProps } from "../editableNode"
|
|
4
|
-
import { newRectangleShape, type
|
|
4
|
+
import { newRectangleShape, type ShapeEnum } from "./shape"
|
|
5
5
|
|
|
6
6
|
export * from "./shape"
|
|
7
7
|
|
|
@@ -25,7 +25,7 @@ export class ShapeNode extends EditableNode {
|
|
|
25
25
|
@state accessor halign: "left" | "center" | "right" | "justify"
|
|
26
26
|
@state accessor valign: "top" | "center" | "bottom"
|
|
27
27
|
|
|
28
|
-
@state accessor shape:
|
|
28
|
+
@state accessor shape: ShapeEnum
|
|
29
29
|
|
|
30
30
|
constructor(
|
|
31
31
|
page: Page,
|
|
@@ -3,16 +3,45 @@
|
|
|
3
3
|
|
|
4
4
|
import { clamp } from "es-toolkit"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Register custom Shape types by augmentating this interface
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* declare module "@lazlon/html-editor/model" {
|
|
11
|
+
* interface Shapes {
|
|
12
|
+
* myCustomShape: {
|
|
13
|
+
* field: number
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface Shapes {
|
|
20
|
+
star: {
|
|
9
21
|
corners: number
|
|
10
22
|
roundness: number
|
|
11
23
|
depth: number
|
|
12
24
|
}
|
|
25
|
+
rectangle: {
|
|
26
|
+
cornerTopLeft: number
|
|
27
|
+
cornerTopRight: number
|
|
28
|
+
cornerBottomLeft: number
|
|
29
|
+
cornerBottomRight: number
|
|
30
|
+
}
|
|
31
|
+
polygon: {
|
|
32
|
+
roundness: number
|
|
33
|
+
sides: number
|
|
34
|
+
}
|
|
35
|
+
arrow: {
|
|
36
|
+
roundness: number
|
|
37
|
+
}
|
|
38
|
+
ellipse: { _?: never }
|
|
13
39
|
}
|
|
14
40
|
|
|
15
|
-
export
|
|
41
|
+
export type ShapeEnum = { [N in keyof Shapes]: Shape<N> }[keyof Shapes]
|
|
42
|
+
export type Shape<N extends keyof Shapes> = { name: N; props: Shapes[N] }
|
|
43
|
+
|
|
44
|
+
export function newStarShape(props?: Partial<Shapes["star"]>): Shape<"star"> {
|
|
16
45
|
return {
|
|
17
46
|
name: "star",
|
|
18
47
|
props: {
|
|
@@ -23,14 +52,7 @@ export function newStarShape(props?: Partial<StarShape["props"]>): StarShape {
|
|
|
23
52
|
}
|
|
24
53
|
}
|
|
25
54
|
|
|
26
|
-
export
|
|
27
|
-
name: "arrow"
|
|
28
|
-
props: {
|
|
29
|
-
roundness: number
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function newArrowShape(props?: Partial<ArrowShape["props"]>): ArrowShape {
|
|
55
|
+
export function newArrowShape(props?: Partial<Shapes["arrow"]>): Shape<"arrow"> {
|
|
34
56
|
return {
|
|
35
57
|
name: "arrow",
|
|
36
58
|
props: {
|
|
@@ -39,27 +61,14 @@ export function newArrowShape(props?: Partial<ArrowShape["props"]>): ArrowShape
|
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
|
|
42
|
-
export
|
|
43
|
-
name: "ellipse"
|
|
44
|
-
props: { _?: never }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function newEllipseShape(): EllipseShape {
|
|
64
|
+
export function newEllipseShape(props?: Partial<Shapes["ellipse"]>): Shape<"ellipse"> {
|
|
48
65
|
return {
|
|
49
66
|
name: "ellipse",
|
|
50
|
-
props: {},
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface PolygonShape {
|
|
55
|
-
name: "polygon"
|
|
56
|
-
props: {
|
|
57
|
-
roundness: number
|
|
58
|
-
sides: number
|
|
67
|
+
props: { ...props },
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
|
|
62
|
-
export function newPolygonShape(props?: Partial<
|
|
71
|
+
export function newPolygonShape(props?: Partial<Shapes["polygon"]>): Shape<"polygon"> {
|
|
63
72
|
return {
|
|
64
73
|
name: "polygon",
|
|
65
74
|
props: {
|
|
@@ -69,19 +78,9 @@ export function newPolygonShape(props?: Partial<PolygonShape["props"]>): Polygon
|
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
|
|
72
|
-
export interface RectangleShape {
|
|
73
|
-
name: "rectangle"
|
|
74
|
-
props: {
|
|
75
|
-
cornerTopLeft: number
|
|
76
|
-
cornerTopRight: number
|
|
77
|
-
cornerBottomLeft: number
|
|
78
|
-
cornerBottomRight: number
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
81
|
export function newRectangleShape(
|
|
83
|
-
props?: Partial<
|
|
84
|
-
):
|
|
82
|
+
props?: Partial<Shapes["rectangle"]>,
|
|
83
|
+
): Shape<"rectangle"> {
|
|
85
84
|
return {
|
|
86
85
|
name: "rectangle",
|
|
87
86
|
props: {
|
|
@@ -92,5 +91,3 @@ export function newRectangleShape(
|
|
|
92
91
|
},
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
|
-
|
|
96
|
-
export type Shape = RectangleShape | ArrowShape | PolygonShape | StarShape | EllipseShape
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useId } from "react"
|
|
2
2
|
import { useStore } from "react-bolt"
|
|
3
3
|
import { roundedPathData } from "../../../model/geometry/svg"
|
|
4
|
-
import type {
|
|
4
|
+
import type { ShapeNode, Shapes } from "../../../model/node/shapeNode"
|
|
5
5
|
|
|
6
6
|
function arrowPath(props: { height: number; width: number; roundness: number }) {
|
|
7
7
|
const { height, width, roundness } = props
|
|
@@ -21,7 +21,7 @@ function arrowPath(props: { height: number; width: number; roundness: number })
|
|
|
21
21
|
return roundedPathData(arrowPoints, roundness)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function ArrowContent(props: { node: ShapeNode; shape:
|
|
24
|
+
export function ArrowContent(props: { node: ShapeNode; shape: Shapes["arrow"] }) {
|
|
25
25
|
const maskId = useId()
|
|
26
26
|
const { node, shape } = props
|
|
27
27
|
|
|
@@ -2,7 +2,7 @@ import { useId } from "react"
|
|
|
2
2
|
import { useStore } from "react-bolt"
|
|
3
3
|
import type { Point } from "../../../model/geometry/math"
|
|
4
4
|
import { roundedPathData } from "../../../model/geometry/svg"
|
|
5
|
-
import type {
|
|
5
|
+
import type { ShapeNode, Shapes } from "../../../model/node/shapeNode"
|
|
6
6
|
|
|
7
7
|
function regularPolygonPoints(props: {
|
|
8
8
|
width: number
|
|
@@ -25,7 +25,7 @@ function regularPolygonPoints(props: {
|
|
|
25
25
|
})
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function PolygonContent(props: { node: ShapeNode; shape:
|
|
28
|
+
export function PolygonContent(props: { node: ShapeNode; shape: Shapes["polygon"] }) {
|
|
29
29
|
const maskId = useId()
|
|
30
30
|
const { node, shape } = props
|
|
31
31
|
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { useStore } from "react-bolt"
|
|
2
|
-
import type {
|
|
2
|
+
import type { ShapeNode, Shapes } from "../../../model/node/shapeNode"
|
|
3
3
|
|
|
4
|
-
export function RectangleShape(props: {
|
|
5
|
-
node: ShapeNode
|
|
6
|
-
shape: RectangleShape["props"]
|
|
7
|
-
}) {
|
|
4
|
+
export function RectangleShape(props: { node: ShapeNode; shape: Shapes["rectangle"] }) {
|
|
8
5
|
const { node, shape } = props
|
|
9
6
|
|
|
10
7
|
const [background, borderWidth, borderColor] = useStore(
|
|
@@ -2,7 +2,7 @@ import { useId } from "react"
|
|
|
2
2
|
import { useStore } from "react-bolt"
|
|
3
3
|
import type { Point } from "../../../model/geometry/math"
|
|
4
4
|
import { roundedPathData } from "../../../model/geometry/svg"
|
|
5
|
-
import type { ShapeNode,
|
|
5
|
+
import type { ShapeNode, Shapes } from "../../../model/node/shapeNode"
|
|
6
6
|
|
|
7
7
|
function starPoints(props: {
|
|
8
8
|
width: number
|
|
@@ -31,7 +31,7 @@ function starPoints(props: {
|
|
|
31
31
|
})
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function StarContent(props: { node: ShapeNode; shape:
|
|
34
|
+
export function StarContent(props: { node: ShapeNode; shape: Shapes["star"] }) {
|
|
35
35
|
const maskId = useId()
|
|
36
36
|
const { node, shape } = props
|
|
37
37
|
|