@lazlon-platform/html-editor 0.1.0 → 0.2.1

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.
Files changed (42) hide show
  1. package/package.json +14 -11
  2. package/.claude/settings.local.json +0 -9
  3. package/.github/workflows/ci.yml +0 -34
  4. package/demo/App.tsx +0 -62
  5. package/demo/EditorView/PageView/NodeContent.tsx +0 -35
  6. package/demo/EditorView/PageView/SnapLines.tsx +0 -28
  7. package/demo/EditorView/PageView/index.tsx +0 -45
  8. package/demo/EditorView/SelectionFrame/Corner.tsx +0 -24
  9. package/demo/EditorView/SelectionFrame/Edge.tsx +0 -21
  10. package/demo/EditorView/SelectionFrame/index.tsx +0 -27
  11. package/demo/EditorView/SelectionOverlay/ActionHud.tsx +0 -32
  12. package/demo/EditorView/SelectionOverlay/Rotation.tsx +0 -39
  13. package/demo/EditorView/SelectionOverlay/Toolbar.tsx +0 -128
  14. package/demo/EditorView/SelectionOverlay/index.tsx +0 -21
  15. package/demo/EditorView/Toolbar/index.tsx +0 -68
  16. package/demo/EditorView/index.tsx +0 -47
  17. package/demo/Navbar/index.tsx +0 -33
  18. package/demo/Sidebar/index.tsx +0 -71
  19. package/demo/hotkeys.ts +0 -93
  20. package/demo/main.tsx +0 -10
  21. package/demo/style.css +0 -1
  22. package/eslint.config.js +0 -43
  23. package/index.html +0 -14
  24. package/tests/createTestEditor.ts +0 -19
  25. package/tests/hooks/actions.test.tsx +0 -736
  26. package/tests/hooks/batch.test.tsx +0 -332
  27. package/tests/hooks/editor.test.tsx +0 -56
  28. package/tests/hooks/page.test.tsx +0 -135
  29. package/tests/hooks/pointer/pointer.test.tsx +0 -244
  30. package/tests/hooks/textMarks.test.tsx +0 -624
  31. package/tests/model/editor.test.ts +0 -384
  32. package/tests/model/history.test.ts +0 -293
  33. package/tests/model/node/group.test.ts +0 -294
  34. package/tests/model/node/image.test.ts +0 -150
  35. package/tests/model/node/polygon.test.ts +0 -408
  36. package/tests/model/node/text.test.ts +0 -158
  37. package/tests/model/node.test.ts +0 -276
  38. package/tests/model/page.test.ts +0 -150
  39. package/tests/setup.ts +0 -7
  40. package/tsconfig.json +0 -28
  41. package/vite.config.ts +0 -9
  42. package/vitest.config.ts +0 -13
@@ -1,33 +0,0 @@
1
- import { useAddNodeAction, useEditor } from "@lazlon/html-editor/hooks"
2
- import { PolygonNode } from "@lazlon/html-editor/model"
3
- import { useStore } from "react-bolt"
4
-
5
- function randomHexColor(): string {
6
- const value = Math.floor(Math.random() * 0xffffff)
7
- return `#${value.toString(16).padStart(6, "0")}`
8
- }
9
-
10
- export default function Navbar() {
11
- const { history } = useEditor()
12
- const canUndo = useStore(history, "undoHistory").length
13
- const canRedo = useStore(history, "redoHistory").length
14
- const addNode = useAddNodeAction()
15
-
16
- return (
17
- <nav className="bg-white flex shadow-xl justify-between px-2">
18
- <span className="text-3xl font-medium p-1">Brand</span>
19
-
20
- <div className="flex gap-2 my-auto">
21
- <button onClick={() => addNode(PolygonNode, { background: randomHexColor() })}>
22
- add
23
- </button>
24
- <button disabled={!canRedo} onClick={history.redo}>
25
- redo
26
- </button>
27
- <button disabled={!canUndo} onClick={history.undo}>
28
- undo
29
- </button>
30
- </div>
31
- </nav>
32
- )
33
- }
@@ -1,71 +0,0 @@
1
- import {
2
- useEditor,
3
- useNodeFieldBatch,
4
- useVisualPositionBatch,
5
- } from "@lazlon/html-editor/hooks"
6
- import { PolygonNode } from "@lazlon/html-editor/model"
7
- import { ColorField, Input, Label, NumberField } from "react-aria-components"
8
- import { useStore } from "react-bolt"
9
-
10
- export default function SideBar() {
11
- const editor = useEditor()
12
- const selection = useStore(editor, "selection").values().toArray()
13
-
14
- const width = useNodeFieldBatch(selection, "width", NaN)
15
- const height = useNodeFieldBatch(selection, "height", NaN)
16
- const { x, y } = useVisualPositionBatch(selection)
17
- const rotation = useNodeFieldBatch(selection, "rotation", NaN)
18
-
19
- const polygons = selection.filter((node) => node instanceof PolygonNode)
20
- const color = useNodeFieldBatch(polygons, "background", "#000000")
21
- const roundness = useNodeFieldBatch(polygons, "roundness", NaN)
22
- const sides = useNodeFieldBatch(polygons, "sides", NaN)
23
-
24
- return (
25
- <div className="bg-white flex flex-col w-58 shadow-lg p-2 gap-8 h-full">
26
- {selection.length > 0 && (
27
- <fieldset className="grid grid-cols-2 gap-4">
28
- <NumberField value={x.value} onChange={x.onChangeEnd}>
29
- <Label>X Position</Label>
30
- <Input className="w-full" />
31
- </NumberField>
32
- <NumberField value={y.value} onChange={y.onChangeEnd}>
33
- <Label>Y Position</Label>
34
- <Input className="w-full" />
35
- </NumberField>
36
- <NumberField value={width.value} onChange={width.onChangeEnd}>
37
- <Label>Width</Label>
38
- <Input className="w-full" />
39
- </NumberField>
40
- <NumberField value={height.value} onChange={height.onChangeEnd}>
41
- <Label>Height</Label>
42
- <Input className="w-full" />
43
- </NumberField>
44
- <NumberField value={rotation.value} onChange={rotation.onChangeEnd}>
45
- <Label>Rotation</Label>
46
- <Input className="w-full" />
47
- </NumberField>
48
- </fieldset>
49
- )}
50
- {polygons.length > 0 && (
51
- <fieldset className="grid grid-cols-2 gap-4">
52
- <ColorField
53
- value={color.value}
54
- onChange={(c) => color.onChangeEnd(c!.toString("hex"))}
55
- >
56
- <Label>Color</Label>
57
- <Input className="w-full" />
58
- </ColorField>
59
- <NumberField value={roundness.value} onChange={roundness.onChangeEnd}>
60
- <Label>Roundness</Label>
61
- <Input className="w-full" />
62
- </NumberField>
63
- <NumberField value={sides.value} onChange={sides.onChangeEnd} minValue={3}>
64
- <Label>Sides</Label>
65
- <Input className="w-full" />
66
- </NumberField>
67
- </fieldset>
68
- )}
69
- </div>
70
- )
71
- }
package/demo/hotkeys.ts DELETED
@@ -1,93 +0,0 @@
1
- import {
2
- useAddNodeAction,
3
- useDuplicateAction,
4
- useEditor,
5
- useGroupAction,
6
- useMoveAction,
7
- useTrashAction,
8
- } from "@lazlon/html-editor/hooks"
9
- import { GroupNode, PolygonNode, TextNode, type Node } from "@lazlon/html-editor/model"
10
- import { useEffect } from "react"
11
- import { useHotkeys } from "react-hotkeys-hook"
12
-
13
- let pasteCount = 0
14
- let clipboard = new Set<Node>()
15
-
16
- export default function Hotkeys(): React.ReactNode {
17
- const editor = useEditor()
18
- const duplicate = useDuplicateAction()
19
- const trash = useTrashAction()
20
- const { group, ungroup } = useGroupAction()
21
- const addNode = useAddNodeAction()
22
- const move = useMoveAction()
23
-
24
- useEffect(() => {
25
- const stage = editor.ref
26
-
27
- function onWheel(e: WheelEvent) {
28
- if (!e.ctrlKey) return
29
- e.preventDefault()
30
-
31
- const sign = Math.sign(e.deltaY)
32
-
33
- // zoom in, cap at 500%
34
- if (sign < 0 && editor.zoom < 5) {
35
- editor.zoom += 0.05
36
- }
37
-
38
- // zoom out, cap at 5%
39
- if (sign > 0 && editor.zoom > 0.05) {
40
- editor.zoom -= 0.05
41
- }
42
- }
43
-
44
- if (stage) {
45
- stage.addEventListener("wheel", onWheel, { passive: false })
46
- return () => void stage.removeEventListener("wheel", onWheel)
47
- }
48
- })
49
-
50
- useHotkeys("mod+c", () => {
51
- pasteCount = 0
52
- clipboard = new Set(editor.selection)
53
- })
54
-
55
- useHotkeys("mod+v", () => {
56
- duplicate({ nodes: clipboard, offset: ++pasteCount * 10 })
57
- })
58
-
59
- useHotkeys("backspace", trash)
60
- useHotkeys("delete", trash)
61
- useHotkeys("mod+d", () => duplicate())
62
-
63
- useHotkeys("mod+z", () => editor.history.undo())
64
- useHotkeys("mod+y", () => editor.history.redo())
65
-
66
- useHotkeys("mod+g", group)
67
- useHotkeys("mod+shift+g", () => {
68
- const [group, ...rest] = editor.selection
69
- if (group && group instanceof GroupNode && rest.length === 0) {
70
- ungroup(group)
71
- }
72
- })
73
-
74
- useHotkeys("shift+r", () => addNode(PolygonNode, { sides: 4 }))
75
- // useHotkeys("shift+l", () => addNode(LineNode))
76
- useHotkeys("shift+t", () => addNode(TextNode))
77
- // useHotkeys("shift+o", () => addNode(OvalNode))
78
-
79
- useHotkeys("escape", () => {
80
- editor.selection = new Set()
81
- })
82
-
83
- useHotkeys("up", () => move({ y: -1 }))
84
- useHotkeys("down", () => move({ y: 1 }))
85
- useHotkeys("left", () => move({ x: -1 }))
86
- useHotkeys("right", () => move({ x: 1 }))
87
- useHotkeys("shift+up", () => move({ y: -10 }))
88
- useHotkeys("shift+down", () => move({ y: 10 }))
89
- useHotkeys("shift+left", () => move({ x: -10 }))
90
- useHotkeys("shift+right", () => move({ x: 10 }))
91
-
92
- return null
93
- }
package/demo/main.tsx DELETED
@@ -1,10 +0,0 @@
1
- import { StrictMode } from "react"
2
- import { createRoot } from "react-dom/client"
3
- import App from "./App"
4
- import "./style.css"
5
-
6
- createRoot(document.body).render(
7
- <StrictMode>
8
- <App />
9
- </StrictMode>,
10
- )
package/demo/style.css DELETED
@@ -1 +0,0 @@
1
- @import "tailwindcss";
package/eslint.config.js DELETED
@@ -1,43 +0,0 @@
1
- // @ts-check
2
-
3
- import js from "@eslint/js"
4
- import globals from "globals"
5
- import reactHooks from "eslint-plugin-react-hooks"
6
- import reactRefresh from "eslint-plugin-react-refresh"
7
- import tseslint from "typescript-eslint"
8
- import { defineConfig, globalIgnores } from "eslint/config"
9
-
10
- export default defineConfig([
11
- globalIgnores(["dist"]),
12
- {
13
- files: ["**/*.{ts,tsx}"],
14
- extends: [
15
- js.configs.recommended,
16
- tseslint.configs.recommended,
17
- reactHooks.configs.flat.recommended,
18
- reactRefresh.configs.vite,
19
- ],
20
- languageOptions: {
21
- ecmaVersion: 2020,
22
- globals: globals.browser,
23
- },
24
- rules: {
25
- // react-bolt uses accessors for state updates
26
- "react-hooks/immutability": ["off"],
27
-
28
- // Allow unused variables with underscore
29
- "@typescript-eslint/no-unused-vars": [
30
- "error",
31
- {
32
- args: "all",
33
- argsIgnorePattern: "^_",
34
- caughtErrors: "all",
35
- caughtErrorsIgnorePattern: "^_",
36
- destructuredArrayIgnorePattern: "^_",
37
- varsIgnorePattern: "^_",
38
- ignoreRestSiblings: true,
39
- },
40
- ],
41
- },
42
- },
43
- ])
package/index.html DELETED
@@ -1,14 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>html-editor</title>
8
- </head>
9
-
10
- <body class="h-screen">
11
- <script type="module" src="/demo/main.tsx"></script>
12
- </body>
13
-
14
- </html>
@@ -1,19 +0,0 @@
1
- import { Editor, type NodeConstructor } from "@lazlon/html-editor/model"
2
- import { TextNode } from "../lib/model/node/text"
3
- import { ImageNode } from "../lib/model/node/image"
4
- import { PolygonNode } from "../lib/model/node/shape/polygon"
5
- import { GroupNode } from "../lib/model/node/group"
6
-
7
- export function createTestEditor(options?: {
8
- schema?: NodeConstructor[]
9
- maxHistory?: number
10
- }) {
11
- return new Editor({
12
- schema: options?.schema ?? [TextNode, ImageNode, PolygonNode, GroupNode],
13
- options: {
14
- loadFonts: async () => [],
15
- maxHistory: options?.maxHistory ?? 100,
16
- snapThreshold: 8,
17
- },
18
- })
19
- }