@lazlon-platform/html-editor 0.8.0 → 0.9.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.
@@ -26,6 +26,50 @@ export function useNodeField<N extends Node, T>(
26
26
  })
27
27
  }
28
28
 
29
+ export function useNodeFieldBatchSetter<T, N extends Node>(
30
+ nodes: N[],
31
+ props: {
32
+ snapshot(node: N): Partial<N["props"]>
33
+ mutate(value: T, node: N): Partial<N["props"]>
34
+ },
35
+ ) {
36
+ const editor = useEditor()
37
+ const initial = useRef<Map<N, Partial<N["props"]>> | null>(null)
38
+
39
+ return {
40
+ onChange(value: T) {
41
+ if (!initial.current) {
42
+ initial.current = new Map(nodes.map((n) => [n, props.snapshot(n)]))
43
+ }
44
+
45
+ for (const node of nodes) {
46
+ if (!node.locked) {
47
+ Object.assign(node, props.mutate(value, node))
48
+ }
49
+ }
50
+ },
51
+ onChangeEnd(value: T) {
52
+ const init = initial.current || new Map(nodes.map((n) => [n, props.snapshot(n)]))
53
+
54
+ editor.pushHistory(
55
+ nodes
56
+ .filter((node) => !node.locked)
57
+ .map((node) => {
58
+ const prev = init.get(node)!
59
+ const next = props.mutate(value, node)
60
+ Object.assign(node, next)
61
+ return {
62
+ undo: ["set-node-props", [node.id, prev]],
63
+ redo: ["set-node-props", [node.id, next]],
64
+ }
65
+ }),
66
+ )
67
+
68
+ initial.current = null
69
+ },
70
+ }
71
+ }
72
+
29
73
  export interface NodeFieldBatch<N extends Node, T> {
30
74
  value: T
31
75
  onChange(set: T | ((node: N) => T)): void
@@ -10,15 +10,21 @@ export {
10
10
  useToggleLockAction,
11
11
  useTrashAction,
12
12
  } from "./actions"
13
- export { reduce, useBatchSet, useNodeField, useNodeFieldBatch } from "./batch"
13
+ export {
14
+ reduce,
15
+ useBatchSet,
16
+ useNodeField,
17
+ useNodeFieldBatch,
18
+ useNodeFieldBatchSetter,
19
+ } from "./batch"
14
20
  export { EditorContext, PageContext, useEditor, usePage } from "./editor"
21
+ export { useVisualPositionBatch } from "./node"
22
+ export { useEditPage } from "./page"
15
23
  export { useMoveable } from "./pointer/useMoveable"
16
24
  export { useMovePoint } from "./pointer/useMovePoint"
17
25
  export { usePointer } from "./pointer/usePointer"
18
26
  export { useResize } from "./pointer/useResize"
19
27
  export { useRotation } from "./pointer/useRotation"
20
- export { useSelectionFrame } from "./selectionFrame"
21
28
  export { useSelector } from "./pointer/useSelector"
29
+ export { useSelectionFrame } from "./selectionFrame"
22
30
  export { useTextMarks } from "./textMarks"
23
- export { useEditPage } from "./page"
24
- export { useVisualPositionBatch } from "./node"
@@ -76,8 +76,6 @@ export function useSelectionFrame<E extends HTMLElement>(props?: {
76
76
  const page = editor.selectionPage?.ref?.getBoundingClientRect()
77
77
  if (!frame || !stage || !page) return
78
78
 
79
- console.log(frame, stage, page)
80
-
81
79
  const tx = page.x - stage.x + x * zoom
82
80
  const ty = page.y - stage.y + y * zoom
83
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazlon-platform/html-editor",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib"