@mdesignable/core 1.0.0-beta.64

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 (389) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +1 -0
  3. package/dist/designable.core.umd.production.js +10 -0
  4. package/dist/designable.core.umd.production.min.js +23505 -0
  5. package/esm/drivers/DragDropDriver.d.ts +14 -0
  6. package/esm/drivers/DragDropDriver.js +157 -0
  7. package/esm/drivers/KeyboardDriver.d.ts +7 -0
  8. package/esm/drivers/KeyboardDriver.js +90 -0
  9. package/esm/drivers/MouseClickDriver.d.ts +8 -0
  10. package/esm/drivers/MouseClickDriver.js +95 -0
  11. package/esm/drivers/MouseMoveDriver.d.ts +8 -0
  12. package/esm/drivers/MouseMoveDriver.js +75 -0
  13. package/esm/drivers/ViewportResizeDriver.d.ts +10 -0
  14. package/esm/drivers/ViewportResizeDriver.js +95 -0
  15. package/esm/drivers/ViewportScrollDriver.d.ts +8 -0
  16. package/esm/drivers/ViewportScrollDriver.js +74 -0
  17. package/esm/drivers/index.d.ts +6 -0
  18. package/esm/drivers/index.js +6 -0
  19. package/esm/effects/index.d.ts +11 -0
  20. package/esm/effects/index.js +11 -0
  21. package/esm/effects/useAutoScrollEffect.d.ts +2 -0
  22. package/esm/effects/useAutoScrollEffect.js +65 -0
  23. package/esm/effects/useContentEditableEffect.d.ts +2 -0
  24. package/esm/effects/useContentEditableEffect.js +167 -0
  25. package/esm/effects/useCursorEffect.d.ts +2 -0
  26. package/esm/effects/useCursorEffect.js +55 -0
  27. package/esm/effects/useDragDropEffect.d.ts +2 -0
  28. package/esm/effects/useDragDropEffect.js +168 -0
  29. package/esm/effects/useFreeSelectionEffect.d.ts +2 -0
  30. package/esm/effects/useFreeSelectionEffect.js +59 -0
  31. package/esm/effects/useKeyboardEffect.d.ts +2 -0
  32. package/esm/effects/useKeyboardEffect.js +17 -0
  33. package/esm/effects/useResizeEffect.d.ts +2 -0
  34. package/esm/effects/useResizeEffect.js +80 -0
  35. package/esm/effects/useSelectionEffect.d.ts +2 -0
  36. package/esm/effects/useSelectionEffect.js +68 -0
  37. package/esm/effects/useTranslateEffect.d.ts +2 -0
  38. package/esm/effects/useTranslateEffect.js +58 -0
  39. package/esm/effects/useViewportEffect.d.ts +2 -0
  40. package/esm/effects/useViewportEffect.js +31 -0
  41. package/esm/effects/useWorkspaceEffect.d.ts +2 -0
  42. package/esm/effects/useWorkspaceEffect.js +29 -0
  43. package/esm/events/cursor/AbstractCursorEvent.d.ts +21 -0
  44. package/esm/events/cursor/AbstractCursorEvent.js +40 -0
  45. package/esm/events/cursor/DragMoveEvent.d.ts +5 -0
  46. package/esm/events/cursor/DragMoveEvent.js +51 -0
  47. package/esm/events/cursor/DragStartEvent.d.ts +5 -0
  48. package/esm/events/cursor/DragStartEvent.js +51 -0
  49. package/esm/events/cursor/DragStopEvent.d.ts +5 -0
  50. package/esm/events/cursor/DragStopEvent.js +51 -0
  51. package/esm/events/cursor/MouseClickEvent.d.ts +8 -0
  52. package/esm/events/cursor/MouseClickEvent.js +61 -0
  53. package/esm/events/cursor/MouseMoveEvent.d.ts +5 -0
  54. package/esm/events/cursor/MouseMoveEvent.js +51 -0
  55. package/esm/events/cursor/index.d.ts +5 -0
  56. package/esm/events/cursor/index.js +5 -0
  57. package/esm/events/history/AbstractHistoryEvent.d.ts +6 -0
  58. package/esm/events/history/AbstractHistoryEvent.js +7 -0
  59. package/esm/events/history/HistoryGotoEvent.d.ts +5 -0
  60. package/esm/events/history/HistoryGotoEvent.js +51 -0
  61. package/esm/events/history/HistoryPushEvent.d.ts +5 -0
  62. package/esm/events/history/HistoryPushEvent.js +51 -0
  63. package/esm/events/history/HistoryRedoEvent.d.ts +5 -0
  64. package/esm/events/history/HistoryRedoEvent.js +51 -0
  65. package/esm/events/history/HistoryUndoEvent.d.ts +5 -0
  66. package/esm/events/history/HistoryUndoEvent.js +51 -0
  67. package/esm/events/history/index.d.ts +4 -0
  68. package/esm/events/history/index.js +4 -0
  69. package/esm/events/index.d.ts +6 -0
  70. package/esm/events/index.js +6 -0
  71. package/esm/events/keyboard/AbstractKeyboardEvent.d.ts +15 -0
  72. package/esm/events/keyboard/AbstractKeyboardEvent.js +61 -0
  73. package/esm/events/keyboard/KeyDownEvent.d.ts +5 -0
  74. package/esm/events/keyboard/KeyDownEvent.js +51 -0
  75. package/esm/events/keyboard/KeyUpEvent.d.ts +5 -0
  76. package/esm/events/keyboard/KeyUpEvent.js +51 -0
  77. package/esm/events/keyboard/index.d.ts +2 -0
  78. package/esm/events/keyboard/index.js +2 -0
  79. package/esm/events/mutation/AbstractMutationNodeEvent.d.ts +13 -0
  80. package/esm/events/mutation/AbstractMutationNodeEvent.js +7 -0
  81. package/esm/events/mutation/AppendNodeEvent.d.ts +5 -0
  82. package/esm/events/mutation/AppendNodeEvent.js +51 -0
  83. package/esm/events/mutation/CloneNodeEvent.d.ts +5 -0
  84. package/esm/events/mutation/CloneNodeEvent.js +51 -0
  85. package/esm/events/mutation/DragNodeEvent.d.ts +5 -0
  86. package/esm/events/mutation/DragNodeEvent.js +51 -0
  87. package/esm/events/mutation/DropNodeEvent.d.ts +5 -0
  88. package/esm/events/mutation/DropNodeEvent.js +51 -0
  89. package/esm/events/mutation/FromNodeEvent.d.ts +13 -0
  90. package/esm/events/mutation/FromNodeEvent.js +8 -0
  91. package/esm/events/mutation/HoverNodeEvent.d.ts +5 -0
  92. package/esm/events/mutation/HoverNodeEvent.js +51 -0
  93. package/esm/events/mutation/InsertAfterEvent.d.ts +5 -0
  94. package/esm/events/mutation/InsertAfterEvent.js +51 -0
  95. package/esm/events/mutation/InsertBeforeEvent.d.ts +5 -0
  96. package/esm/events/mutation/InsertBeforeEvent.js +51 -0
  97. package/esm/events/mutation/InsertChildrenEvent.d.ts +5 -0
  98. package/esm/events/mutation/InsertChildrenEvent.js +51 -0
  99. package/esm/events/mutation/PrependNodeEvent.d.ts +5 -0
  100. package/esm/events/mutation/PrependNodeEvent.js +51 -0
  101. package/esm/events/mutation/RemoveNodeEvent.d.ts +5 -0
  102. package/esm/events/mutation/RemoveNodeEvent.js +51 -0
  103. package/esm/events/mutation/SelectNodeEvent.d.ts +5 -0
  104. package/esm/events/mutation/SelectNodeEvent.js +51 -0
  105. package/esm/events/mutation/UnSelectNodeEvent.d.ts +5 -0
  106. package/esm/events/mutation/UnSelectNodeEvent.js +51 -0
  107. package/esm/events/mutation/UpdateChildrenEvent.d.ts +5 -0
  108. package/esm/events/mutation/UpdateChildrenEvent.js +51 -0
  109. package/esm/events/mutation/UpdateNodePropsEvent.d.ts +5 -0
  110. package/esm/events/mutation/UpdateNodePropsEvent.js +51 -0
  111. package/esm/events/mutation/UserSelectNodeEvent.d.ts +5 -0
  112. package/esm/events/mutation/UserSelectNodeEvent.js +51 -0
  113. package/esm/events/mutation/WrapNodeEvent.d.ts +5 -0
  114. package/esm/events/mutation/WrapNodeEvent.js +51 -0
  115. package/esm/events/mutation/index.d.ts +16 -0
  116. package/esm/events/mutation/index.js +16 -0
  117. package/esm/events/viewport/AbstractViewportEvent.d.ts +16 -0
  118. package/esm/events/viewport/AbstractViewportEvent.js +17 -0
  119. package/esm/events/viewport/ViewportResizeEvent.d.ts +5 -0
  120. package/esm/events/viewport/ViewportResizeEvent.js +51 -0
  121. package/esm/events/viewport/ViewportScrollEvent.d.ts +5 -0
  122. package/esm/events/viewport/ViewportScrollEvent.js +51 -0
  123. package/esm/events/viewport/index.d.ts +2 -0
  124. package/esm/events/viewport/index.js +2 -0
  125. package/esm/events/workbench/AbstractWorkspaceEvent.d.ts +7 -0
  126. package/esm/events/workbench/AbstractWorkspaceEvent.js +7 -0
  127. package/esm/events/workbench/AddWorkspaceEvent.d.ts +5 -0
  128. package/esm/events/workbench/AddWorkspaceEvent.js +51 -0
  129. package/esm/events/workbench/RemoveWorkspaceEvent.d.ts +5 -0
  130. package/esm/events/workbench/RemoveWorkspaceEvent.js +51 -0
  131. package/esm/events/workbench/SwitchWorkspaceEvent.d.ts +5 -0
  132. package/esm/events/workbench/SwitchWorkspaceEvent.js +51 -0
  133. package/esm/events/workbench/index.d.ts +3 -0
  134. package/esm/events/workbench/index.js +3 -0
  135. package/esm/exports.d.ts +5 -0
  136. package/esm/exports.js +5 -0
  137. package/esm/externals.d.ts +12 -0
  138. package/esm/externals.js +113 -0
  139. package/esm/index.d.ts +1 -0
  140. package/esm/index.js +24 -0
  141. package/esm/internals.d.ts +3 -0
  142. package/esm/internals.js +34 -0
  143. package/esm/models/Cursor.d.ts +60 -0
  144. package/esm/models/Cursor.js +151 -0
  145. package/esm/models/Engine.d.ts +29 -0
  146. package/esm/models/Engine.js +112 -0
  147. package/esm/models/History.d.ts +34 -0
  148. package/esm/models/History.js +110 -0
  149. package/esm/models/Hover.d.ts +14 -0
  150. package/esm/models/Hover.js +38 -0
  151. package/esm/models/Keyboard.d.ts +29 -0
  152. package/esm/models/Keyboard.js +126 -0
  153. package/esm/models/MoveHelper.d.ts +66 -0
  154. package/esm/models/MoveHelper.js +363 -0
  155. package/esm/models/Operation.d.ts +29 -0
  156. package/esm/models/Operation.js +75 -0
  157. package/esm/models/Screen.d.ts +31 -0
  158. package/esm/models/Screen.js +73 -0
  159. package/esm/models/Selection.d.ts +29 -0
  160. package/esm/models/Selection.js +192 -0
  161. package/esm/models/Shortcut.d.ts +20 -0
  162. package/esm/models/Shortcut.js +69 -0
  163. package/esm/models/SnapLine.d.ts +27 -0
  164. package/esm/models/SnapLine.js +141 -0
  165. package/esm/models/SpaceBlock.d.ts +40 -0
  166. package/esm/models/SpaceBlock.js +171 -0
  167. package/esm/models/TransformHelper.d.ts +80 -0
  168. package/esm/models/TransformHelper.js +601 -0
  169. package/esm/models/TreeNode.d.ts +115 -0
  170. package/esm/models/TreeNode.js +932 -0
  171. package/esm/models/Viewport.d.ts +90 -0
  172. package/esm/models/Viewport.js +474 -0
  173. package/esm/models/Workbench.d.ts +23 -0
  174. package/esm/models/Workbench.js +98 -0
  175. package/esm/models/Workspace.d.ts +41 -0
  176. package/esm/models/Workspace.js +95 -0
  177. package/esm/models/index.d.ts +13 -0
  178. package/esm/models/index.js +13 -0
  179. package/esm/presets.d.ts +4 -0
  180. package/esm/presets.js +38 -0
  181. package/esm/registry.d.ts +16 -0
  182. package/esm/registry.js +123 -0
  183. package/esm/shortcuts/CursorSwitch.d.ts +2 -0
  184. package/esm/shortcuts/CursorSwitch.js +10 -0
  185. package/esm/shortcuts/MultiSelection.d.ts +5 -0
  186. package/esm/shortcuts/MultiSelection.js +27 -0
  187. package/esm/shortcuts/NodeMutation.d.ts +7 -0
  188. package/esm/shortcuts/NodeMutation.js +40 -0
  189. package/esm/shortcuts/QuickSelection.d.ts +3 -0
  190. package/esm/shortcuts/QuickSelection.js +85 -0
  191. package/esm/shortcuts/UndoRedo.d.ts +3 -0
  192. package/esm/shortcuts/UndoRedo.js +27 -0
  193. package/esm/shortcuts/index.d.ts +5 -0
  194. package/esm/shortcuts/index.js +5 -0
  195. package/esm/types.d.ts +131 -0
  196. package/esm/types.js +1 -0
  197. package/lib/drivers/DragDropDriver.d.ts +14 -0
  198. package/lib/drivers/DragDropDriver.js +160 -0
  199. package/lib/drivers/KeyboardDriver.d.ts +7 -0
  200. package/lib/drivers/KeyboardDriver.js +93 -0
  201. package/lib/drivers/MouseClickDriver.d.ts +8 -0
  202. package/lib/drivers/MouseClickDriver.js +98 -0
  203. package/lib/drivers/MouseMoveDriver.d.ts +8 -0
  204. package/lib/drivers/MouseMoveDriver.js +78 -0
  205. package/lib/drivers/ViewportResizeDriver.d.ts +10 -0
  206. package/lib/drivers/ViewportResizeDriver.js +98 -0
  207. package/lib/drivers/ViewportScrollDriver.d.ts +8 -0
  208. package/lib/drivers/ViewportScrollDriver.js +77 -0
  209. package/lib/drivers/index.d.ts +6 -0
  210. package/lib/drivers/index.js +22 -0
  211. package/lib/effects/index.d.ts +11 -0
  212. package/lib/effects/index.js +27 -0
  213. package/lib/effects/useAutoScrollEffect.d.ts +2 -0
  214. package/lib/effects/useAutoScrollEffect.js +69 -0
  215. package/lib/effects/useContentEditableEffect.d.ts +2 -0
  216. package/lib/effects/useContentEditableEffect.js +171 -0
  217. package/lib/effects/useCursorEffect.d.ts +2 -0
  218. package/lib/effects/useCursorEffect.js +59 -0
  219. package/lib/effects/useDragDropEffect.d.ts +2 -0
  220. package/lib/effects/useDragDropEffect.js +172 -0
  221. package/lib/effects/useFreeSelectionEffect.d.ts +2 -0
  222. package/lib/effects/useFreeSelectionEffect.js +63 -0
  223. package/lib/effects/useKeyboardEffect.d.ts +2 -0
  224. package/lib/effects/useKeyboardEffect.js +21 -0
  225. package/lib/effects/useResizeEffect.d.ts +2 -0
  226. package/lib/effects/useResizeEffect.js +84 -0
  227. package/lib/effects/useSelectionEffect.d.ts +2 -0
  228. package/lib/effects/useSelectionEffect.js +72 -0
  229. package/lib/effects/useTranslateEffect.d.ts +2 -0
  230. package/lib/effects/useTranslateEffect.js +62 -0
  231. package/lib/effects/useViewportEffect.d.ts +2 -0
  232. package/lib/effects/useViewportEffect.js +35 -0
  233. package/lib/effects/useWorkspaceEffect.d.ts +2 -0
  234. package/lib/effects/useWorkspaceEffect.js +33 -0
  235. package/lib/events/cursor/AbstractCursorEvent.d.ts +21 -0
  236. package/lib/events/cursor/AbstractCursorEvent.js +43 -0
  237. package/lib/events/cursor/DragMoveEvent.d.ts +5 -0
  238. package/lib/events/cursor/DragMoveEvent.js +54 -0
  239. package/lib/events/cursor/DragStartEvent.d.ts +5 -0
  240. package/lib/events/cursor/DragStartEvent.js +54 -0
  241. package/lib/events/cursor/DragStopEvent.d.ts +5 -0
  242. package/lib/events/cursor/DragStopEvent.js +54 -0
  243. package/lib/events/cursor/MouseClickEvent.d.ts +8 -0
  244. package/lib/events/cursor/MouseClickEvent.js +64 -0
  245. package/lib/events/cursor/MouseMoveEvent.d.ts +5 -0
  246. package/lib/events/cursor/MouseMoveEvent.js +54 -0
  247. package/lib/events/cursor/index.d.ts +5 -0
  248. package/lib/events/cursor/index.js +21 -0
  249. package/lib/events/history/AbstractHistoryEvent.d.ts +6 -0
  250. package/lib/events/history/AbstractHistoryEvent.js +10 -0
  251. package/lib/events/history/HistoryGotoEvent.d.ts +5 -0
  252. package/lib/events/history/HistoryGotoEvent.js +54 -0
  253. package/lib/events/history/HistoryPushEvent.d.ts +5 -0
  254. package/lib/events/history/HistoryPushEvent.js +54 -0
  255. package/lib/events/history/HistoryRedoEvent.d.ts +5 -0
  256. package/lib/events/history/HistoryRedoEvent.js +54 -0
  257. package/lib/events/history/HistoryUndoEvent.d.ts +5 -0
  258. package/lib/events/history/HistoryUndoEvent.js +54 -0
  259. package/lib/events/history/index.d.ts +4 -0
  260. package/lib/events/history/index.js +20 -0
  261. package/lib/events/index.d.ts +6 -0
  262. package/lib/events/index.js +22 -0
  263. package/lib/events/keyboard/AbstractKeyboardEvent.d.ts +15 -0
  264. package/lib/events/keyboard/AbstractKeyboardEvent.js +64 -0
  265. package/lib/events/keyboard/KeyDownEvent.d.ts +5 -0
  266. package/lib/events/keyboard/KeyDownEvent.js +54 -0
  267. package/lib/events/keyboard/KeyUpEvent.d.ts +5 -0
  268. package/lib/events/keyboard/KeyUpEvent.js +54 -0
  269. package/lib/events/keyboard/index.d.ts +2 -0
  270. package/lib/events/keyboard/index.js +18 -0
  271. package/lib/events/mutation/AbstractMutationNodeEvent.d.ts +13 -0
  272. package/lib/events/mutation/AbstractMutationNodeEvent.js +10 -0
  273. package/lib/events/mutation/AppendNodeEvent.d.ts +5 -0
  274. package/lib/events/mutation/AppendNodeEvent.js +54 -0
  275. package/lib/events/mutation/CloneNodeEvent.d.ts +5 -0
  276. package/lib/events/mutation/CloneNodeEvent.js +54 -0
  277. package/lib/events/mutation/DragNodeEvent.d.ts +5 -0
  278. package/lib/events/mutation/DragNodeEvent.js +54 -0
  279. package/lib/events/mutation/DropNodeEvent.d.ts +5 -0
  280. package/lib/events/mutation/DropNodeEvent.js +54 -0
  281. package/lib/events/mutation/FromNodeEvent.d.ts +13 -0
  282. package/lib/events/mutation/FromNodeEvent.js +11 -0
  283. package/lib/events/mutation/HoverNodeEvent.d.ts +5 -0
  284. package/lib/events/mutation/HoverNodeEvent.js +54 -0
  285. package/lib/events/mutation/InsertAfterEvent.d.ts +5 -0
  286. package/lib/events/mutation/InsertAfterEvent.js +54 -0
  287. package/lib/events/mutation/InsertBeforeEvent.d.ts +5 -0
  288. package/lib/events/mutation/InsertBeforeEvent.js +54 -0
  289. package/lib/events/mutation/InsertChildrenEvent.d.ts +5 -0
  290. package/lib/events/mutation/InsertChildrenEvent.js +54 -0
  291. package/lib/events/mutation/PrependNodeEvent.d.ts +5 -0
  292. package/lib/events/mutation/PrependNodeEvent.js +54 -0
  293. package/lib/events/mutation/RemoveNodeEvent.d.ts +5 -0
  294. package/lib/events/mutation/RemoveNodeEvent.js +54 -0
  295. package/lib/events/mutation/SelectNodeEvent.d.ts +5 -0
  296. package/lib/events/mutation/SelectNodeEvent.js +54 -0
  297. package/lib/events/mutation/UnSelectNodeEvent.d.ts +5 -0
  298. package/lib/events/mutation/UnSelectNodeEvent.js +54 -0
  299. package/lib/events/mutation/UpdateChildrenEvent.d.ts +5 -0
  300. package/lib/events/mutation/UpdateChildrenEvent.js +54 -0
  301. package/lib/events/mutation/UpdateNodePropsEvent.d.ts +5 -0
  302. package/lib/events/mutation/UpdateNodePropsEvent.js +54 -0
  303. package/lib/events/mutation/UserSelectNodeEvent.d.ts +5 -0
  304. package/lib/events/mutation/UserSelectNodeEvent.js +54 -0
  305. package/lib/events/mutation/WrapNodeEvent.d.ts +5 -0
  306. package/lib/events/mutation/WrapNodeEvent.js +54 -0
  307. package/lib/events/mutation/index.d.ts +16 -0
  308. package/lib/events/mutation/index.js +32 -0
  309. package/lib/events/viewport/AbstractViewportEvent.d.ts +16 -0
  310. package/lib/events/viewport/AbstractViewportEvent.js +20 -0
  311. package/lib/events/viewport/ViewportResizeEvent.d.ts +5 -0
  312. package/lib/events/viewport/ViewportResizeEvent.js +54 -0
  313. package/lib/events/viewport/ViewportScrollEvent.d.ts +5 -0
  314. package/lib/events/viewport/ViewportScrollEvent.js +54 -0
  315. package/lib/events/viewport/index.d.ts +2 -0
  316. package/lib/events/viewport/index.js +18 -0
  317. package/lib/events/workbench/AbstractWorkspaceEvent.d.ts +7 -0
  318. package/lib/events/workbench/AbstractWorkspaceEvent.js +10 -0
  319. package/lib/events/workbench/AddWorkspaceEvent.d.ts +5 -0
  320. package/lib/events/workbench/AddWorkspaceEvent.js +54 -0
  321. package/lib/events/workbench/RemoveWorkspaceEvent.d.ts +5 -0
  322. package/lib/events/workbench/RemoveWorkspaceEvent.js +54 -0
  323. package/lib/events/workbench/SwitchWorkspaceEvent.d.ts +5 -0
  324. package/lib/events/workbench/SwitchWorkspaceEvent.js +54 -0
  325. package/lib/events/workbench/index.d.ts +3 -0
  326. package/lib/events/workbench/index.js +19 -0
  327. package/lib/exports.d.ts +5 -0
  328. package/lib/exports.js +21 -0
  329. package/lib/externals.d.ts +12 -0
  330. package/lib/externals.js +126 -0
  331. package/lib/index.d.ts +1 -0
  332. package/lib/index.js +52 -0
  333. package/lib/internals.d.ts +3 -0
  334. package/lib/internals.js +40 -0
  335. package/lib/models/Cursor.d.ts +60 -0
  336. package/lib/models/Cursor.js +154 -0
  337. package/lib/models/Engine.d.ts +29 -0
  338. package/lib/models/Engine.js +115 -0
  339. package/lib/models/History.d.ts +34 -0
  340. package/lib/models/History.js +113 -0
  341. package/lib/models/Hover.d.ts +14 -0
  342. package/lib/models/Hover.js +41 -0
  343. package/lib/models/Keyboard.d.ts +29 -0
  344. package/lib/models/Keyboard.js +129 -0
  345. package/lib/models/MoveHelper.d.ts +66 -0
  346. package/lib/models/MoveHelper.js +366 -0
  347. package/lib/models/Operation.d.ts +29 -0
  348. package/lib/models/Operation.js +78 -0
  349. package/lib/models/Screen.d.ts +31 -0
  350. package/lib/models/Screen.js +76 -0
  351. package/lib/models/Selection.d.ts +29 -0
  352. package/lib/models/Selection.js +195 -0
  353. package/lib/models/Shortcut.d.ts +20 -0
  354. package/lib/models/Shortcut.js +72 -0
  355. package/lib/models/SnapLine.d.ts +27 -0
  356. package/lib/models/SnapLine.js +144 -0
  357. package/lib/models/SpaceBlock.d.ts +40 -0
  358. package/lib/models/SpaceBlock.js +174 -0
  359. package/lib/models/TransformHelper.d.ts +80 -0
  360. package/lib/models/TransformHelper.js +604 -0
  361. package/lib/models/TreeNode.d.ts +115 -0
  362. package/lib/models/TreeNode.js +935 -0
  363. package/lib/models/Viewport.d.ts +90 -0
  364. package/lib/models/Viewport.js +477 -0
  365. package/lib/models/Workbench.d.ts +23 -0
  366. package/lib/models/Workbench.js +101 -0
  367. package/lib/models/Workspace.d.ts +41 -0
  368. package/lib/models/Workspace.js +98 -0
  369. package/lib/models/index.d.ts +13 -0
  370. package/lib/models/index.js +29 -0
  371. package/lib/presets.d.ts +4 -0
  372. package/lib/presets.js +41 -0
  373. package/lib/registry.d.ts +16 -0
  374. package/lib/registry.js +126 -0
  375. package/lib/shortcuts/CursorSwitch.d.ts +2 -0
  376. package/lib/shortcuts/CursorSwitch.js +13 -0
  377. package/lib/shortcuts/MultiSelection.d.ts +5 -0
  378. package/lib/shortcuts/MultiSelection.js +30 -0
  379. package/lib/shortcuts/NodeMutation.d.ts +7 -0
  380. package/lib/shortcuts/NodeMutation.js +43 -0
  381. package/lib/shortcuts/QuickSelection.d.ts +3 -0
  382. package/lib/shortcuts/QuickSelection.js +88 -0
  383. package/lib/shortcuts/UndoRedo.d.ts +3 -0
  384. package/lib/shortcuts/UndoRedo.js +30 -0
  385. package/lib/shortcuts/index.d.ts +5 -0
  386. package/lib/shortcuts/index.js +21 -0
  387. package/lib/types.d.ts +131 -0
  388. package/lib/types.js +2 -0
  389. package/package.json +49 -0
@@ -0,0 +1,935 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.TreeNode = void 0;
29
+ var reactive_1 = require("@formily/reactive");
30
+ var shared_1 = require("@mdesignable/shared");
31
+ var events_1 = require("../events");
32
+ var registry_1 = require("../registry");
33
+ var internals_1 = require("../internals");
34
+ var TreeNodes = new Map();
35
+ var CommonDesignerPropsMap = new Map();
36
+ var removeNode = function (node) {
37
+ if (node.parent) {
38
+ node.parent.children = node.parent.children.filter(function (child) { return child !== node; });
39
+ }
40
+ };
41
+ var resetNodesParent = function (nodes, parent) {
42
+ var resetDepth = function (node) {
43
+ node.depth = node.parent ? node.parent.depth + 1 : 0;
44
+ node.children.forEach(resetDepth);
45
+ };
46
+ var shallowReset = function (node) {
47
+ node.parent = parent;
48
+ node.root = parent.root;
49
+ resetDepth(node);
50
+ };
51
+ var deepReset = function (node) {
52
+ shallowReset(node);
53
+ resetNodesParent(node.children, node);
54
+ };
55
+ return nodes.map(function (node) {
56
+ var _a;
57
+ if (node === parent)
58
+ return node;
59
+ if (!parent.isSourceNode) {
60
+ if (node.isSourceNode) {
61
+ node = node.clone(parent);
62
+ resetDepth(node);
63
+ }
64
+ else if (!node.isRoot && node.isInOperation) {
65
+ (_a = node.operation) === null || _a === void 0 ? void 0 : _a.selection.remove(node);
66
+ removeNode(node);
67
+ shallowReset(node);
68
+ }
69
+ else {
70
+ deepReset(node);
71
+ }
72
+ }
73
+ else {
74
+ deepReset(node);
75
+ }
76
+ if (!TreeNodes.has(node.id)) {
77
+ TreeNodes.set(node.id, node);
78
+ CommonDesignerPropsMap.set(node.componentName, node.designerProps);
79
+ }
80
+ return node;
81
+ });
82
+ };
83
+ var resetParent = function (node, parent) {
84
+ return resetNodesParent([node], parent)[0];
85
+ };
86
+ var resolveDesignerProps = function (node, props) {
87
+ if ((0, shared_1.isFn)(props))
88
+ return props(node);
89
+ return props;
90
+ };
91
+ var TreeNode = /** @class */ (function () {
92
+ function TreeNode(node, parent) {
93
+ this.depth = 0;
94
+ this.hidden = false;
95
+ this.componentName = 'NO_NAME_COMPONENT';
96
+ this.sourceName = '';
97
+ this.props = {};
98
+ this.children = [];
99
+ if (node instanceof TreeNode) {
100
+ return node;
101
+ }
102
+ this.id = node.id || (0, shared_1.uid)();
103
+ if (parent) {
104
+ this.parent = parent;
105
+ this.depth = parent.depth + 1;
106
+ this.root = parent.root;
107
+ TreeNodes.set(this.id, this);
108
+ }
109
+ else {
110
+ this.root = this;
111
+ this.rootOperation = node.operation;
112
+ this.isSelfSourceNode = node.isSourceNode || false;
113
+ TreeNodes.set(this.id, this);
114
+ }
115
+ if (node) {
116
+ this.from(node);
117
+ }
118
+ this.makeObservable();
119
+ }
120
+ TreeNode.prototype.makeObservable = function () {
121
+ (0, reactive_1.define)(this, {
122
+ componentName: reactive_1.observable.ref,
123
+ props: reactive_1.observable,
124
+ hidden: reactive_1.observable.ref,
125
+ children: reactive_1.observable.shallow,
126
+ designerProps: reactive_1.observable.computed,
127
+ designerLocales: reactive_1.observable.computed,
128
+ wrap: reactive_1.action,
129
+ prepend: reactive_1.action,
130
+ append: reactive_1.action,
131
+ insertAfter: reactive_1.action,
132
+ insertBefore: reactive_1.action,
133
+ remove: reactive_1.action,
134
+ setProps: reactive_1.action,
135
+ setChildren: reactive_1.action,
136
+ setComponentName: reactive_1.action,
137
+ });
138
+ };
139
+ Object.defineProperty(TreeNode.prototype, "designerProps", {
140
+ get: function () {
141
+ var _this = this;
142
+ var behaviors = registry_1.GlobalRegistry.getDesignerBehaviors(this);
143
+ var designerProps = behaviors.reduce(function (buf, pattern) {
144
+ if (!pattern.designerProps)
145
+ return buf;
146
+ Object.assign(buf, resolveDesignerProps(_this, pattern.designerProps));
147
+ return buf;
148
+ }, {});
149
+ return designerProps;
150
+ },
151
+ enumerable: false,
152
+ configurable: true
153
+ });
154
+ Object.defineProperty(TreeNode.prototype, "designerLocales", {
155
+ get: function () {
156
+ var behaviors = registry_1.GlobalRegistry.getDesignerBehaviors(this);
157
+ var designerLocales = behaviors.reduce(function (buf, pattern) {
158
+ if (!pattern.designerLocales)
159
+ return buf;
160
+ (0, internals_1.mergeLocales)(buf, pattern.designerLocales);
161
+ return buf;
162
+ }, {});
163
+ return designerLocales;
164
+ },
165
+ enumerable: false,
166
+ configurable: true
167
+ });
168
+ Object.defineProperty(TreeNode.prototype, "previous", {
169
+ get: function () {
170
+ if (this.parent === this || !this.parent)
171
+ return;
172
+ return this.parent.children[this.index - 1];
173
+ },
174
+ enumerable: false,
175
+ configurable: true
176
+ });
177
+ Object.defineProperty(TreeNode.prototype, "next", {
178
+ get: function () {
179
+ if (this.parent === this || !this.parent)
180
+ return;
181
+ return this.parent.children[this.index + 1];
182
+ },
183
+ enumerable: false,
184
+ configurable: true
185
+ });
186
+ Object.defineProperty(TreeNode.prototype, "siblings", {
187
+ get: function () {
188
+ var _this = this;
189
+ if (this.parent) {
190
+ return this.parent.children.filter(function (node) { return node !== _this; });
191
+ }
192
+ return [];
193
+ },
194
+ enumerable: false,
195
+ configurable: true
196
+ });
197
+ Object.defineProperty(TreeNode.prototype, "index", {
198
+ get: function () {
199
+ if (this.parent === this || !this.parent)
200
+ return 0;
201
+ return this.parent.children.indexOf(this);
202
+ },
203
+ enumerable: false,
204
+ configurable: true
205
+ });
206
+ Object.defineProperty(TreeNode.prototype, "descendants", {
207
+ get: function () {
208
+ return this.children.reduce(function (buf, node) {
209
+ return buf.concat(node).concat(node.descendants);
210
+ }, []);
211
+ },
212
+ enumerable: false,
213
+ configurable: true
214
+ });
215
+ Object.defineProperty(TreeNode.prototype, "isRoot", {
216
+ get: function () {
217
+ return this === this.root;
218
+ },
219
+ enumerable: false,
220
+ configurable: true
221
+ });
222
+ Object.defineProperty(TreeNode.prototype, "isInOperation", {
223
+ get: function () {
224
+ return !!this.operation;
225
+ },
226
+ enumerable: false,
227
+ configurable: true
228
+ });
229
+ Object.defineProperty(TreeNode.prototype, "lastChild", {
230
+ get: function () {
231
+ return this.children[this.children.length - 1];
232
+ },
233
+ enumerable: false,
234
+ configurable: true
235
+ });
236
+ Object.defineProperty(TreeNode.prototype, "firstChild", {
237
+ get: function () {
238
+ return this.children[0];
239
+ },
240
+ enumerable: false,
241
+ configurable: true
242
+ });
243
+ Object.defineProperty(TreeNode.prototype, "isSourceNode", {
244
+ get: function () {
245
+ return this.root.isSelfSourceNode;
246
+ },
247
+ enumerable: false,
248
+ configurable: true
249
+ });
250
+ Object.defineProperty(TreeNode.prototype, "operation", {
251
+ get: function () {
252
+ var _a;
253
+ return (_a = this.root) === null || _a === void 0 ? void 0 : _a.rootOperation;
254
+ },
255
+ enumerable: false,
256
+ configurable: true
257
+ });
258
+ Object.defineProperty(TreeNode.prototype, "viewport", {
259
+ get: function () {
260
+ var _a, _b;
261
+ return (_b = (_a = this.operation) === null || _a === void 0 ? void 0 : _a.workspace) === null || _b === void 0 ? void 0 : _b.viewport;
262
+ },
263
+ enumerable: false,
264
+ configurable: true
265
+ });
266
+ Object.defineProperty(TreeNode.prototype, "outline", {
267
+ get: function () {
268
+ var _a, _b;
269
+ return (_b = (_a = this.operation) === null || _a === void 0 ? void 0 : _a.workspace) === null || _b === void 0 ? void 0 : _b.outline;
270
+ },
271
+ enumerable: false,
272
+ configurable: true
273
+ });
274
+ Object.defineProperty(TreeNode.prototype, "moveLayout", {
275
+ get: function () {
276
+ var _a;
277
+ return (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.getValidNodeLayout(this);
278
+ },
279
+ enumerable: false,
280
+ configurable: true
281
+ });
282
+ TreeNode.prototype.getElement = function (area) {
283
+ var _a;
284
+ if (area === void 0) { area = 'viewport'; }
285
+ return (_a = this[area]) === null || _a === void 0 ? void 0 : _a.findElementById(this.id);
286
+ };
287
+ TreeNode.prototype.getValidElement = function (area) {
288
+ var _a;
289
+ if (area === void 0) { area = 'viewport'; }
290
+ return (_a = this[area]) === null || _a === void 0 ? void 0 : _a.getValidNodeElement(this);
291
+ };
292
+ TreeNode.prototype.getElementRect = function (area) {
293
+ var _a;
294
+ if (area === void 0) { area = 'viewport'; }
295
+ return (_a = this[area]) === null || _a === void 0 ? void 0 : _a.getElementRect(this.getElement(area));
296
+ };
297
+ TreeNode.prototype.getValidElementRect = function (area) {
298
+ var _a;
299
+ if (area === void 0) { area = 'viewport'; }
300
+ return (_a = this[area]) === null || _a === void 0 ? void 0 : _a.getValidNodeRect(this);
301
+ };
302
+ TreeNode.prototype.getElementOffsetRect = function (area) {
303
+ var _a;
304
+ if (area === void 0) { area = 'viewport'; }
305
+ return (_a = this[area]) === null || _a === void 0 ? void 0 : _a.getElementOffsetRect(this.getElement(area));
306
+ };
307
+ TreeNode.prototype.getValidElementOffsetRect = function (area) {
308
+ var _a;
309
+ if (area === void 0) { area = 'viewport'; }
310
+ return (_a = this[area]) === null || _a === void 0 ? void 0 : _a.getValidNodeOffsetRect(this);
311
+ };
312
+ TreeNode.prototype.getPrevious = function (step) {
313
+ if (step === void 0) { step = 1; }
314
+ return this.parent.children[this.index - step];
315
+ };
316
+ TreeNode.prototype.getAfter = function (step) {
317
+ if (step === void 0) { step = 1; }
318
+ return this.parent.children[this.index + step];
319
+ };
320
+ TreeNode.prototype.getSibling = function (index) {
321
+ if (index === void 0) { index = 0; }
322
+ return this.parent.children[index];
323
+ };
324
+ TreeNode.prototype.getParents = function (node) {
325
+ var _node = node || this;
326
+ return (_node === null || _node === void 0 ? void 0 : _node.parent)
327
+ ? [_node.parent].concat(this.getParents(_node.parent))
328
+ : [];
329
+ };
330
+ TreeNode.prototype.getParentByDepth = function (depth) {
331
+ if (depth === void 0) { depth = 0; }
332
+ var parent = this.parent;
333
+ if ((parent === null || parent === void 0 ? void 0 : parent.depth) === depth) {
334
+ return parent;
335
+ }
336
+ else {
337
+ return parent === null || parent === void 0 ? void 0 : parent.getParentByDepth(depth);
338
+ }
339
+ };
340
+ TreeNode.prototype.getMessage = function (token) {
341
+ return registry_1.GlobalRegistry.getDesignerMessage(token, this.designerLocales);
342
+ };
343
+ TreeNode.prototype.isMyAncestor = function (node) {
344
+ if (node === this || this.parent === node)
345
+ return false;
346
+ return node.contains(this);
347
+ };
348
+ TreeNode.prototype.isMyParent = function (node) {
349
+ return this.parent === node;
350
+ };
351
+ TreeNode.prototype.isMyParents = function (node) {
352
+ if (node === this)
353
+ return false;
354
+ return this.isMyParent(node) || this.isMyAncestor(node);
355
+ };
356
+ TreeNode.prototype.isMyChild = function (node) {
357
+ return node.isMyParent(this);
358
+ };
359
+ TreeNode.prototype.isMyChildren = function (node) {
360
+ return node.isMyParents(this);
361
+ };
362
+ TreeNode.prototype.takeSnapshot = function (type) {
363
+ var _a;
364
+ (_a = this.operation) === null || _a === void 0 ? void 0 : _a.snapshot(type);
365
+ };
366
+ TreeNode.prototype.triggerMutation = function (event, callback, defaults) {
367
+ if (this.operation) {
368
+ var result = this.operation.dispatch(event, callback) || defaults;
369
+ this.takeSnapshot(event === null || event === void 0 ? void 0 : event.type);
370
+ return result;
371
+ }
372
+ else if ((0, shared_1.isFn)(callback)) {
373
+ return callback();
374
+ }
375
+ };
376
+ TreeNode.prototype.find = function (finder) {
377
+ if (finder(this)) {
378
+ return this;
379
+ }
380
+ else {
381
+ var result_1 = undefined;
382
+ this.eachChildren(function (node) {
383
+ if (finder(node)) {
384
+ result_1 = node;
385
+ return false;
386
+ }
387
+ });
388
+ return result_1;
389
+ }
390
+ };
391
+ TreeNode.prototype.findAll = function (finder) {
392
+ var results = [];
393
+ if (finder(this)) {
394
+ results.push(this);
395
+ }
396
+ this.eachChildren(function (node) {
397
+ if (finder(node)) {
398
+ results.push(node);
399
+ }
400
+ });
401
+ return results;
402
+ };
403
+ TreeNode.prototype.distanceTo = function (node) {
404
+ if (this.root !== node.root) {
405
+ return Infinity;
406
+ }
407
+ if (this.parent !== node.parent) {
408
+ return Infinity;
409
+ }
410
+ return Math.abs(this.index - node.index);
411
+ };
412
+ TreeNode.prototype.crossSiblings = function (node) {
413
+ if (this.parent !== node.parent)
414
+ return [];
415
+ var minIndex = Math.min(this.index, node.index);
416
+ var maxIndex = Math.max(this.index, node.index);
417
+ var results = [];
418
+ for (var i = minIndex + 1; i < maxIndex; i++) {
419
+ results.push(this.parent.children[i]);
420
+ }
421
+ return results;
422
+ };
423
+ TreeNode.prototype.allowSibling = function (nodes) {
424
+ var _a, _b, _c;
425
+ if (((_b = (_a = this.designerProps) === null || _a === void 0 ? void 0 : _a.allowSiblings) === null || _b === void 0 ? void 0 : _b.call(_a, this, nodes)) === false)
426
+ return false;
427
+ return (_c = this.parent) === null || _c === void 0 ? void 0 : _c.allowAppend(nodes);
428
+ };
429
+ TreeNode.prototype.allowDrop = function (parent) {
430
+ if (!(0, shared_1.isFn)(this.designerProps.allowDrop))
431
+ return true;
432
+ return this.designerProps.allowDrop(parent);
433
+ };
434
+ TreeNode.prototype.allowAppend = function (nodes) {
435
+ var _this = this;
436
+ var _a, _b, _c;
437
+ if (!((_a = this.designerProps) === null || _a === void 0 ? void 0 : _a.droppable))
438
+ return false;
439
+ if (((_c = (_b = this.designerProps) === null || _b === void 0 ? void 0 : _b.allowAppend) === null || _c === void 0 ? void 0 : _c.call(_b, this, nodes)) === false)
440
+ return false;
441
+ if (nodes.some(function (node) { return !node.allowDrop(_this); }))
442
+ return false;
443
+ if (this.root === this)
444
+ return true;
445
+ return true;
446
+ };
447
+ TreeNode.prototype.allowClone = function () {
448
+ var _a;
449
+ if (this === this.root)
450
+ return false;
451
+ return (_a = this.designerProps.cloneable) !== null && _a !== void 0 ? _a : true;
452
+ };
453
+ TreeNode.prototype.allowDrag = function () {
454
+ var _a;
455
+ if (this === this.root && !this.isSourceNode)
456
+ return false;
457
+ return (_a = this.designerProps.draggable) !== null && _a !== void 0 ? _a : true;
458
+ };
459
+ TreeNode.prototype.allowResize = function () {
460
+ if (this === this.root && !this.isSourceNode)
461
+ return false;
462
+ var resizable = this.designerProps.resizable;
463
+ if (!resizable)
464
+ return false;
465
+ if (resizable.width && resizable.height)
466
+ return ['x', 'y'];
467
+ if (resizable.width)
468
+ return ['x'];
469
+ return ['y'];
470
+ };
471
+ TreeNode.prototype.allowRotate = function () { };
472
+ TreeNode.prototype.allowRound = function () { };
473
+ TreeNode.prototype.allowScale = function () { };
474
+ TreeNode.prototype.allowTranslate = function () {
475
+ if (this === this.root && !this.isSourceNode)
476
+ return false;
477
+ var translatable = this.designerProps.translatable;
478
+ if ((translatable === null || translatable === void 0 ? void 0 : translatable.x) && (translatable === null || translatable === void 0 ? void 0 : translatable.y))
479
+ return true;
480
+ return false;
481
+ };
482
+ TreeNode.prototype.allowDelete = function () {
483
+ var _a;
484
+ if (this === this.root)
485
+ return false;
486
+ return (_a = this.designerProps.deletable) !== null && _a !== void 0 ? _a : true;
487
+ };
488
+ TreeNode.prototype.findById = function (id) {
489
+ var _a;
490
+ if (!id)
491
+ return;
492
+ if (this.id === id)
493
+ return this;
494
+ if (((_a = this.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
495
+ return TreeNodes.get(id);
496
+ }
497
+ };
498
+ TreeNode.prototype.contains = function () {
499
+ var _this = this;
500
+ var nodes = [];
501
+ for (var _i = 0; _i < arguments.length; _i++) {
502
+ nodes[_i] = arguments[_i];
503
+ }
504
+ return nodes.every(function (node) {
505
+ if (node === _this ||
506
+ (node === null || node === void 0 ? void 0 : node.parent) === _this ||
507
+ (node === null || node === void 0 ? void 0 : node.getParentByDepth(_this.depth)) === _this) {
508
+ return true;
509
+ }
510
+ return false;
511
+ });
512
+ };
513
+ TreeNode.prototype.eachTree = function (callback) {
514
+ var _a;
515
+ if ((0, shared_1.isFn)(callback)) {
516
+ callback(this.root);
517
+ (_a = this.root) === null || _a === void 0 ? void 0 : _a.eachChildren(callback);
518
+ }
519
+ };
520
+ TreeNode.prototype.eachChildren = function (callback) {
521
+ if ((0, shared_1.isFn)(callback)) {
522
+ for (var i = 0; i < this.children.length; i++) {
523
+ var node = this.children[i];
524
+ if (callback(node) === false)
525
+ return;
526
+ node.eachChildren(callback);
527
+ }
528
+ }
529
+ };
530
+ TreeNode.prototype.resetNodesParent = function (nodes, parent) {
531
+ var _this = this;
532
+ return resetNodesParent(nodes.filter(function (node) { return node !== _this; }), parent);
533
+ };
534
+ TreeNode.prototype.setProps = function (props) {
535
+ var _this = this;
536
+ return this.triggerMutation(new events_1.UpdateNodePropsEvent({
537
+ target: this,
538
+ source: null,
539
+ }), function () {
540
+ Object.assign(_this.props, props);
541
+ });
542
+ };
543
+ TreeNode.prototype.setComponentName = function (componentName) {
544
+ this.componentName = componentName;
545
+ };
546
+ TreeNode.prototype.prepend = function () {
547
+ var _this = this;
548
+ var nodes = [];
549
+ for (var _i = 0; _i < arguments.length; _i++) {
550
+ nodes[_i] = arguments[_i];
551
+ }
552
+ if (nodes.some(function (node) { return node.contains(_this); }))
553
+ return [];
554
+ var originSourceParents = nodes.map(function (node) { return node.parent; });
555
+ var newNodes = this.resetNodesParent(nodes, this);
556
+ if (!newNodes.length)
557
+ return [];
558
+ return this.triggerMutation(new events_1.PrependNodeEvent({
559
+ originSourceParents: originSourceParents,
560
+ target: this,
561
+ source: newNodes,
562
+ }), function () {
563
+ _this.children = newNodes.concat(_this.children);
564
+ return newNodes;
565
+ }, []);
566
+ };
567
+ TreeNode.prototype.append = function () {
568
+ var _this = this;
569
+ var nodes = [];
570
+ for (var _i = 0; _i < arguments.length; _i++) {
571
+ nodes[_i] = arguments[_i];
572
+ }
573
+ if (nodes.some(function (node) { return node.contains(_this); }))
574
+ return [];
575
+ var originSourceParents = nodes.map(function (node) { return node.parent; });
576
+ var newNodes = this.resetNodesParent(nodes, this);
577
+ if (!newNodes.length)
578
+ return [];
579
+ return this.triggerMutation(new events_1.AppendNodeEvent({
580
+ originSourceParents: originSourceParents,
581
+ target: this,
582
+ source: newNodes,
583
+ }), function () {
584
+ _this.children = _this.children.concat(newNodes);
585
+ return newNodes;
586
+ }, []);
587
+ };
588
+ TreeNode.prototype.wrap = function (wrapper) {
589
+ var _this = this;
590
+ if (wrapper === this)
591
+ return;
592
+ var parent = this.parent;
593
+ return this.triggerMutation(new events_1.WrapNodeEvent({
594
+ target: this,
595
+ source: wrapper,
596
+ }), function () {
597
+ resetParent(_this, wrapper);
598
+ resetParent(wrapper, parent);
599
+ return wrapper;
600
+ });
601
+ };
602
+ TreeNode.prototype.insertAfter = function () {
603
+ var _this = this;
604
+ var _a;
605
+ var nodes = [];
606
+ for (var _i = 0; _i < arguments.length; _i++) {
607
+ nodes[_i] = arguments[_i];
608
+ }
609
+ var parent = this.parent;
610
+ if (nodes.some(function (node) { return node.contains(_this); }))
611
+ return [];
612
+ if ((_a = parent === null || parent === void 0 ? void 0 : parent.children) === null || _a === void 0 ? void 0 : _a.length) {
613
+ var originSourceParents = nodes.map(function (node) { return node.parent; });
614
+ var newNodes_1 = this.resetNodesParent(nodes, parent);
615
+ if (!newNodes_1.length)
616
+ return [];
617
+ return this.triggerMutation(new events_1.InsertAfterEvent({
618
+ originSourceParents: originSourceParents,
619
+ target: this,
620
+ source: newNodes_1,
621
+ }), function () {
622
+ parent.children = parent.children.reduce(function (buf, node) {
623
+ if (node === _this) {
624
+ return buf.concat([node]).concat(newNodes_1);
625
+ }
626
+ else {
627
+ return buf.concat([node]);
628
+ }
629
+ }, []);
630
+ return newNodes_1;
631
+ }, []);
632
+ }
633
+ return [];
634
+ };
635
+ TreeNode.prototype.insertBefore = function () {
636
+ var _this = this;
637
+ var _a;
638
+ var nodes = [];
639
+ for (var _i = 0; _i < arguments.length; _i++) {
640
+ nodes[_i] = arguments[_i];
641
+ }
642
+ var parent = this.parent;
643
+ if (nodes.some(function (node) { return node.contains(_this); }))
644
+ return [];
645
+ if ((_a = parent === null || parent === void 0 ? void 0 : parent.children) === null || _a === void 0 ? void 0 : _a.length) {
646
+ var originSourceParents = nodes.map(function (node) { return node.parent; });
647
+ var newNodes_2 = this.resetNodesParent(nodes, parent);
648
+ if (!newNodes_2.length)
649
+ return [];
650
+ return this.triggerMutation(new events_1.InsertBeforeEvent({
651
+ originSourceParents: originSourceParents,
652
+ target: this,
653
+ source: newNodes_2,
654
+ }), function () {
655
+ parent.children = parent.children.reduce(function (buf, node) {
656
+ if (node === _this) {
657
+ return buf.concat(newNodes_2).concat([node]);
658
+ }
659
+ else {
660
+ return buf.concat([node]);
661
+ }
662
+ }, []);
663
+ return newNodes_2;
664
+ }, []);
665
+ }
666
+ return [];
667
+ };
668
+ TreeNode.prototype.insertChildren = function (start) {
669
+ var _this = this;
670
+ var _a;
671
+ var nodes = [];
672
+ for (var _i = 1; _i < arguments.length; _i++) {
673
+ nodes[_i - 1] = arguments[_i];
674
+ }
675
+ if (nodes.some(function (node) { return node.contains(_this); }))
676
+ return [];
677
+ if ((_a = this.children) === null || _a === void 0 ? void 0 : _a.length) {
678
+ var originSourceParents = nodes.map(function (node) { return node.parent; });
679
+ var newNodes_3 = this.resetNodesParent(nodes, this);
680
+ if (!newNodes_3.length)
681
+ return [];
682
+ return this.triggerMutation(new events_1.InsertChildrenEvent({
683
+ originSourceParents: originSourceParents,
684
+ target: this,
685
+ source: newNodes_3,
686
+ }), function () {
687
+ _this.children = _this.children.reduce(function (buf, node, index) {
688
+ if (index === start) {
689
+ return buf.concat(newNodes_3).concat([node]);
690
+ }
691
+ return buf.concat([node]);
692
+ }, []);
693
+ return newNodes_3;
694
+ }, []);
695
+ }
696
+ return [];
697
+ };
698
+ TreeNode.prototype.setChildren = function () {
699
+ var _this = this;
700
+ var nodes = [];
701
+ for (var _i = 0; _i < arguments.length; _i++) {
702
+ nodes[_i] = arguments[_i];
703
+ }
704
+ var originSourceParents = nodes.map(function (node) { return node.parent; });
705
+ var newNodes = this.resetNodesParent(nodes, this);
706
+ return this.triggerMutation(new events_1.UpdateChildrenEvent({
707
+ originSourceParents: originSourceParents,
708
+ target: this,
709
+ source: newNodes,
710
+ }), function () {
711
+ _this.children = newNodes;
712
+ return newNodes;
713
+ }, []);
714
+ };
715
+ /**
716
+ * @deprecated
717
+ * please use `setChildren`
718
+ */
719
+ TreeNode.prototype.setNodeChildren = function () {
720
+ var nodes = [];
721
+ for (var _i = 0; _i < arguments.length; _i++) {
722
+ nodes[_i] = arguments[_i];
723
+ }
724
+ return this.setChildren.apply(this, __spreadArray([], __read(nodes), false));
725
+ };
726
+ TreeNode.prototype.remove = function () {
727
+ var _this = this;
728
+ return this.triggerMutation(new events_1.RemoveNodeEvent({
729
+ target: this,
730
+ source: null,
731
+ }), function () {
732
+ removeNode(_this);
733
+ TreeNodes.delete(_this.id);
734
+ });
735
+ };
736
+ TreeNode.prototype.clone = function (parent) {
737
+ var newNode = new TreeNode({
738
+ id: (0, shared_1.uid)(),
739
+ componentName: this.componentName,
740
+ sourceName: this.sourceName,
741
+ props: (0, reactive_1.toJS)(this.props),
742
+ children: [],
743
+ }, parent ? parent : this.parent);
744
+ newNode.children = resetNodesParent(this.children.map(function (child) {
745
+ return child.clone(newNode);
746
+ }), newNode);
747
+ return this.triggerMutation(new events_1.CloneNodeEvent({
748
+ target: this,
749
+ source: newNode,
750
+ }), function () { return newNode; });
751
+ };
752
+ TreeNode.prototype.from = function (node) {
753
+ var _this = this;
754
+ if (!node)
755
+ return;
756
+ return this.triggerMutation(new events_1.FromNodeEvent({
757
+ target: this,
758
+ source: node,
759
+ }), function () {
760
+ var _a, _b, _c;
761
+ if (node.id && node.id !== _this.id) {
762
+ TreeNodes.delete(_this.id);
763
+ TreeNodes.set(node.id, _this);
764
+ _this.id = node.id;
765
+ }
766
+ if (node.componentName) {
767
+ _this.componentName = node.componentName;
768
+ }
769
+ _this.props = (_a = node.props) !== null && _a !== void 0 ? _a : {};
770
+ if (node.hidden) {
771
+ _this.hidden = node.hidden;
772
+ }
773
+ if (node.children) {
774
+ _this.children =
775
+ ((_c = (_b = node.children) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.call(_b, function (node) {
776
+ return new TreeNode(node, _this);
777
+ })) || [];
778
+ }
779
+ });
780
+ };
781
+ TreeNode.prototype.serialize = function () {
782
+ return {
783
+ id: this.id,
784
+ componentName: this.componentName,
785
+ sourceName: this.sourceName,
786
+ props: (0, reactive_1.toJS)(this.props),
787
+ hidden: this.hidden,
788
+ children: this.children.map(function (treeNode) {
789
+ return treeNode.serialize();
790
+ }),
791
+ };
792
+ };
793
+ TreeNode.create = function (node, parent) {
794
+ return new TreeNode(node, parent);
795
+ };
796
+ TreeNode.findById = function (id) {
797
+ return TreeNodes.get(id);
798
+ };
799
+ TreeNode.remove = function (nodes) {
800
+ var _a, _b;
801
+ if (nodes === void 0) { nodes = []; }
802
+ for (var i = nodes.length - 1; i >= 0; i--) {
803
+ var node = nodes[i];
804
+ if (node.allowDelete()) {
805
+ var previous = node.previous;
806
+ var next = node.next;
807
+ node.remove();
808
+ (_a = node.operation) === null || _a === void 0 ? void 0 : _a.selection.select(previous ? previous : next ? next : node.parent);
809
+ (_b = node.operation) === null || _b === void 0 ? void 0 : _b.hover.clear();
810
+ }
811
+ }
812
+ };
813
+ TreeNode.sort = function (nodes) {
814
+ if (nodes === void 0) { nodes = []; }
815
+ return nodes.sort(function (before, after) {
816
+ if (before.depth !== after.depth)
817
+ return 0;
818
+ return before.index - after.index >= 0 ? 1 : -1;
819
+ });
820
+ };
821
+ TreeNode.clone = function (nodes) {
822
+ if (nodes === void 0) { nodes = []; }
823
+ var groups = {};
824
+ var lastGroupNode = {};
825
+ var filterNestedNode = TreeNode.sort(nodes).filter(function (node) {
826
+ return !nodes.some(function (parent) {
827
+ return node.isMyParents(parent);
828
+ });
829
+ });
830
+ (0, shared_1.each)(filterNestedNode, function (node) {
831
+ var _a, _b, _c, _d, _e, _f, _g;
832
+ if (node === node.root)
833
+ return;
834
+ if (!node.allowClone())
835
+ return;
836
+ if (!(node === null || node === void 0 ? void 0 : node.operation))
837
+ return;
838
+ groups[(_a = node === null || node === void 0 ? void 0 : node.parent) === null || _a === void 0 ? void 0 : _a.id] = groups[(_b = node === null || node === void 0 ? void 0 : node.parent) === null || _b === void 0 ? void 0 : _b.id] || [];
839
+ groups[(_c = node === null || node === void 0 ? void 0 : node.parent) === null || _c === void 0 ? void 0 : _c.id].push(node);
840
+ if (lastGroupNode[(_d = node === null || node === void 0 ? void 0 : node.parent) === null || _d === void 0 ? void 0 : _d.id]) {
841
+ if (node.index > lastGroupNode[(_e = node === null || node === void 0 ? void 0 : node.parent) === null || _e === void 0 ? void 0 : _e.id].index) {
842
+ lastGroupNode[(_f = node === null || node === void 0 ? void 0 : node.parent) === null || _f === void 0 ? void 0 : _f.id] = node;
843
+ }
844
+ }
845
+ else {
846
+ lastGroupNode[(_g = node === null || node === void 0 ? void 0 : node.parent) === null || _g === void 0 ? void 0 : _g.id] = node;
847
+ }
848
+ });
849
+ var parents = new Map();
850
+ (0, shared_1.each)(groups, function (nodes, parentId) {
851
+ var lastNode = lastGroupNode[parentId];
852
+ var insertPoint = lastNode;
853
+ (0, shared_1.each)(nodes, function (node) {
854
+ var _a, _b;
855
+ var cloned = node.clone();
856
+ if (!cloned)
857
+ return;
858
+ if (((_a = node.operation) === null || _a === void 0 ? void 0 : _a.selection.has(node)) &&
859
+ insertPoint.parent.allowAppend([cloned])) {
860
+ insertPoint.insertAfter(cloned);
861
+ insertPoint = insertPoint.next;
862
+ }
863
+ else if (node.operation.selection.length === 1) {
864
+ var targetNode = (_b = node.operation) === null || _b === void 0 ? void 0 : _b.tree.findById(node.operation.selection.first);
865
+ var cloneNodes = parents.get(targetNode);
866
+ if (!cloneNodes) {
867
+ cloneNodes = [];
868
+ parents.set(targetNode, cloneNodes);
869
+ }
870
+ if (targetNode && targetNode.allowAppend([cloned])) {
871
+ cloneNodes.push(cloned);
872
+ }
873
+ }
874
+ });
875
+ });
876
+ parents.forEach(function (nodes, target) {
877
+ if (!nodes.length)
878
+ return;
879
+ target.append.apply(target, __spreadArray([], __read(nodes), false));
880
+ });
881
+ };
882
+ TreeNode.filterResizable = function (nodes) {
883
+ if (nodes === void 0) { nodes = []; }
884
+ return nodes.filter(function (node) { return node.allowResize(); });
885
+ };
886
+ TreeNode.filterRotatable = function (nodes) {
887
+ if (nodes === void 0) { nodes = []; }
888
+ return nodes.filter(function (node) { return node.allowRotate(); });
889
+ };
890
+ TreeNode.filterScalable = function (nodes) {
891
+ if (nodes === void 0) { nodes = []; }
892
+ return nodes.filter(function (node) { return node.allowScale(); });
893
+ };
894
+ TreeNode.filterRoundable = function (nodes) {
895
+ if (nodes === void 0) { nodes = []; }
896
+ return nodes.filter(function (node) { return node.allowRound(); });
897
+ };
898
+ TreeNode.filterTranslatable = function (nodes) {
899
+ if (nodes === void 0) { nodes = []; }
900
+ return nodes.filter(function (node) { return node.allowTranslate(); });
901
+ };
902
+ TreeNode.filterDraggable = function (nodes) {
903
+ if (nodes === void 0) { nodes = []; }
904
+ return nodes.reduce(function (buf, node) {
905
+ var _a;
906
+ if (!node.allowDrag())
907
+ return buf;
908
+ if ((0, shared_1.isFn)((_a = node === null || node === void 0 ? void 0 : node.designerProps) === null || _a === void 0 ? void 0 : _a.getDragNodes)) {
909
+ var transformed = node.designerProps.getDragNodes(node);
910
+ return transformed ? buf.concat(transformed) : buf;
911
+ }
912
+ if (node.componentName === '$$ResourceNode$$')
913
+ return buf.concat(node.children);
914
+ return buf.concat([node]);
915
+ }, []);
916
+ };
917
+ TreeNode.filterDroppable = function (nodes, parent) {
918
+ if (nodes === void 0) { nodes = []; }
919
+ return nodes.reduce(function (buf, node) {
920
+ var _a;
921
+ if (!node.allowDrop(parent))
922
+ return buf;
923
+ if ((0, shared_1.isFn)((_a = node.designerProps) === null || _a === void 0 ? void 0 : _a.getDropNodes)) {
924
+ var cloned = node.isSourceNode ? node.clone(node.parent) : node;
925
+ var transformed = node.designerProps.getDropNodes(cloned, parent);
926
+ return transformed ? buf.concat(transformed) : buf;
927
+ }
928
+ if (node.componentName === '$$ResourceNode$$')
929
+ return buf.concat(node.children);
930
+ return buf.concat([node]);
931
+ }, []);
932
+ };
933
+ return TreeNode;
934
+ }());
935
+ exports.TreeNode = TreeNode;