@weasel-js/editing 1.19.1 → 2.0.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.
Files changed (363) hide show
  1. package/README.md +23 -11
  2. package/dist/actionGroups.js +27 -0
  3. package/dist/actionGroups.js.map +1 -0
  4. package/dist/actions/align/action.js +12 -9
  5. package/dist/actions/align/action.js.map +1 -1
  6. package/dist/actions/align/align.js +5 -4
  7. package/dist/actions/align/align.js.map +1 -1
  8. package/dist/actions/clipboard/action.js +10 -7
  9. package/dist/actions/clipboard/action.js.map +1 -1
  10. package/dist/actions/clone/action.js +217 -0
  11. package/dist/actions/clone/action.js.map +1 -0
  12. package/dist/actions/clone/behaviors.js +65 -0
  13. package/dist/actions/clone/behaviors.js.map +1 -0
  14. package/dist/actions/delete/delete.js +123 -0
  15. package/dist/actions/delete/delete.js.map +1 -0
  16. package/dist/actions/derivedBox.js +16 -0
  17. package/dist/actions/derivedBox.js.map +1 -0
  18. package/dist/actions/distribute/action.js +6 -3
  19. package/dist/actions/distribute/action.js.map +1 -1
  20. package/dist/actions/distribute/distribute.js +3 -2
  21. package/dist/actions/distribute/distribute.js.map +1 -1
  22. package/dist/actions/distribute/plan.js.map +1 -1
  23. package/dist/actions/edit/createPaintAction.js +42 -13
  24. package/dist/actions/edit/createPaintAction.js.map +1 -1
  25. package/dist/actions/edit/{escape.js → deselect.js} +8 -8
  26. package/dist/actions/edit/deselect.js.map +1 -0
  27. package/dist/actions/edit/duplicate.js +9 -7
  28. package/dist/actions/edit/duplicate.js.map +1 -1
  29. package/dist/actions/edit/group.js +24 -20
  30. package/dist/actions/edit/group.js.map +1 -1
  31. package/dist/actions/edit/ingest.js +4 -2
  32. package/dist/actions/edit/ingest.js.map +1 -1
  33. package/dist/actions/edit/nudge.js +14 -10
  34. package/dist/actions/edit/nudge.js.map +1 -1
  35. package/dist/actions/edit/selectAll.js +1 -1
  36. package/dist/actions/edit/setFill.js +1 -1
  37. package/dist/actions/edit/setFill.js.map +1 -1
  38. package/dist/actions/edit/setFillOpacity.js +5 -5
  39. package/dist/actions/edit/setFillOpacity.js.map +1 -1
  40. package/dist/actions/edit/setStroke.js +1 -1
  41. package/dist/actions/edit/setStroke.js.map +1 -1
  42. package/dist/actions/edit/setStrokeOpacity.js +6 -6
  43. package/dist/actions/edit/setStrokeOpacity.js.map +1 -1
  44. package/dist/actions/edit/setStrokeWidth.js +13 -8
  45. package/dist/actions/edit/setStrokeWidth.js.map +1 -1
  46. package/dist/actions/edit/setVertexColor.js +13 -6
  47. package/dist/actions/edit/setVertexColor.js.map +1 -1
  48. package/dist/actions/flip/action.js +19 -14
  49. package/dist/actions/flip/action.js.map +1 -1
  50. package/dist/actions/flip/helpers.js.map +1 -1
  51. package/dist/actions/group/enterGroup.js +81 -0
  52. package/dist/actions/group/enterGroup.js.map +1 -0
  53. package/dist/actions/insert/action.js +152 -0
  54. package/dist/actions/insert/action.js.map +1 -0
  55. package/dist/actions/insert/commit.js +52 -0
  56. package/dist/actions/insert/commit.js.map +1 -0
  57. package/dist/actions/insert/extras.js +88 -0
  58. package/dist/actions/insert/extras.js.map +1 -0
  59. package/dist/actions/insert/frame.js +96 -0
  60. package/dist/actions/insert/frame.js.map +1 -0
  61. package/dist/actions/insert/geometry.js +35 -0
  62. package/dist/actions/insert/geometry.js.map +1 -0
  63. package/dist/actions/insert/lands.js +41 -0
  64. package/dist/actions/insert/lands.js.map +1 -0
  65. package/dist/actions/insert/params.js +42 -0
  66. package/dist/actions/insert/params.js.map +1 -0
  67. package/dist/actions/insert/placeAction.js +137 -0
  68. package/dist/actions/insert/placeAction.js.map +1 -0
  69. package/dist/actions/insert/repositionAction.js +47 -0
  70. package/dist/actions/insert/repositionAction.js.map +1 -0
  71. package/dist/actions/insert/rotateAction.js +34 -0
  72. package/dist/actions/insert/rotateAction.js.map +1 -0
  73. package/dist/actions/insert/session.js +99 -0
  74. package/dist/actions/insert/session.js.map +1 -0
  75. package/dist/actions/insert/shape.js +117 -0
  76. package/dist/actions/insert/shape.js.map +1 -0
  77. package/dist/actions/insert/style.js +23 -0
  78. package/dist/actions/insert/style.js.map +1 -0
  79. package/dist/actions/lassoSelect/action.js +201 -0
  80. package/dist/actions/lassoSelect/action.js.map +1 -0
  81. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js +61 -0
  82. package/dist/actions/lassoSelect/behaviors/selectFromLasso.js.map +1 -0
  83. package/dist/actions/lockedWrites.js +20 -0
  84. package/dist/actions/lockedWrites.js.map +1 -0
  85. package/dist/actions/move/action.js +138 -0
  86. package/dist/actions/move/action.js.map +1 -0
  87. package/dist/actions/move/behaviors/clampMove.js +42 -0
  88. package/dist/actions/move/behaviors/clampMove.js.map +1 -0
  89. package/dist/actions/move/behaviors/layoutDrop.js +84 -0
  90. package/dist/actions/move/behaviors/layoutDrop.js.map +1 -0
  91. package/dist/actions/move/behaviors/pageDrop.js +30 -0
  92. package/dist/actions/move/behaviors/pageDrop.js.map +1 -0
  93. package/dist/actions/move/behaviors/reparentOnDrop.js +44 -0
  94. package/dist/actions/move/behaviors/reparentOnDrop.js.map +1 -0
  95. package/dist/actions/move/behaviors/snapBackOrDelete.js +52 -0
  96. package/dist/actions/move/behaviors/snapBackOrDelete.js.map +1 -0
  97. package/dist/actions/move/behaviors/snapToContainer.js +214 -0
  98. package/dist/actions/move/behaviors/snapToContainer.js.map +1 -0
  99. package/dist/actions/move/behaviors/swapOnDrop.js +180 -0
  100. package/dist/actions/move/behaviors/swapOnDrop.js.map +1 -0
  101. package/dist/actions/move/capture.js +116 -0
  102. package/dist/actions/move/capture.js.map +1 -0
  103. package/dist/actions/move/commit/index.js +47 -0
  104. package/dist/actions/move/commit/index.js.map +1 -0
  105. package/dist/actions/move/commit/layoutDrop.js +68 -0
  106. package/dist/actions/move/commit/layoutDrop.js.map +1 -0
  107. package/dist/actions/move/commit/layoutRelease.js +146 -0
  108. package/dist/actions/move/commit/layoutRelease.js.map +1 -0
  109. package/dist/actions/move/commit/pageDrop.js +162 -0
  110. package/dist/actions/move/commit/pageDrop.js.map +1 -0
  111. package/dist/actions/move/commit/rebase.js +24 -0
  112. package/dist/actions/move/commit/rebase.js.map +1 -0
  113. package/dist/actions/move/commit/reparent.js +157 -0
  114. package/dist/actions/move/commit/reparent.js.map +1 -0
  115. package/dist/actions/move/delta.js +127 -0
  116. package/dist/actions/move/delta.js.map +1 -0
  117. package/dist/actions/move/dragSnap.js +55 -0
  118. package/dist/actions/move/dragSnap.js.map +1 -0
  119. package/dist/actions/move/frame.js +67 -0
  120. package/dist/actions/move/frame.js.map +1 -0
  121. package/dist/actions/move/gestureAdapter.js +36 -0
  122. package/dist/actions/move/gestureAdapter.js.map +1 -0
  123. package/dist/actions/move/landedDescendants.js +50 -0
  124. package/dist/actions/move/landedDescendants.js.map +1 -0
  125. package/dist/actions/move/layout/container.js +119 -0
  126. package/dist/actions/move/layout/container.js.map +1 -0
  127. package/dist/actions/move/layout/dragged.js +75 -0
  128. package/dist/actions/move/layout/dragged.js.map +1 -0
  129. package/dist/actions/move/layout/dropPass.js +205 -0
  130. package/dist/actions/move/layout/dropPass.js.map +1 -0
  131. package/dist/actions/move/layout/exits.js +62 -0
  132. package/dist/actions/move/layout/exits.js.map +1 -0
  133. package/dist/actions/move/layout/glide.js +70 -0
  134. package/dist/actions/move/layout/glide.js.map +1 -0
  135. package/dist/actions/move/layout/view.js +60 -0
  136. package/dist/actions/move/layout/view.js.map +1 -0
  137. package/dist/actions/move/refusal.js +49 -0
  138. package/dist/actions/move/refusal.js.map +1 -0
  139. package/dist/actions/move/session.js +105 -0
  140. package/dist/actions/move/session.js.map +1 -0
  141. package/dist/actions/move/sessionOf.js +27 -0
  142. package/dist/actions/move/sessionOf.js.map +1 -0
  143. package/dist/actions/move/translate.js +49 -0
  144. package/dist/actions/move/translate.js.map +1 -0
  145. package/dist/actions/pathfinder/action.js +8 -6
  146. package/dist/actions/pathfinder/action.js.map +1 -1
  147. package/dist/actions/pathfinder/booleanGroupAction.js +16 -10
  148. package/dist/actions/pathfinder/booleanGroupAction.js.map +1 -1
  149. package/dist/actions/pathfinder/keymap.js +2 -2
  150. package/dist/actions/pathfinder/keymap.js.map +1 -1
  151. package/dist/actions/reorder/reorder.js +13 -11
  152. package/dist/actions/reorder/reorder.js.map +1 -1
  153. package/dist/actions/resize/action.js +105 -0
  154. package/dist/actions/resize/action.js.map +1 -0
  155. package/dist/actions/resize/aspect.js +42 -0
  156. package/dist/actions/resize/aspect.js.map +1 -0
  157. package/dist/actions/resize/behaviors/clampMinSize.js +100 -0
  158. package/dist/actions/resize/behaviors/clampMinSize.js.map +1 -0
  159. package/dist/actions/resize/boxFrame.js +19 -0
  160. package/dist/actions/resize/boxFrame.js.map +1 -0
  161. package/dist/actions/resize/capture.js +121 -0
  162. package/dist/actions/resize/capture.js.map +1 -0
  163. package/dist/actions/resize/commit.js +104 -0
  164. package/dist/actions/resize/commit.js.map +1 -0
  165. package/dist/actions/resize/frame.js +171 -0
  166. package/dist/actions/resize/frame.js.map +1 -0
  167. package/dist/actions/resize/held.js +44 -0
  168. package/dist/actions/resize/held.js.map +1 -0
  169. package/dist/actions/resize/minimum.js +34 -0
  170. package/dist/actions/resize/minimum.js.map +1 -0
  171. package/dist/actions/resize/replay.js +58 -0
  172. package/dist/actions/resize/replay.js.map +1 -0
  173. package/dist/actions/resize/ruleBounds.js +11 -0
  174. package/dist/actions/resize/ruleBounds.js.map +1 -0
  175. package/dist/actions/resize/session.js +118 -0
  176. package/dist/actions/resize/session.js.map +1 -0
  177. package/dist/actions/rotate/action.js +99 -0
  178. package/dist/actions/rotate/action.js.map +1 -0
  179. package/dist/actions/rotate/commit.js +48 -0
  180. package/dist/actions/rotate/commit.js.map +1 -0
  181. package/dist/actions/rotate/frame.js +96 -0
  182. package/dist/actions/rotate/frame.js.map +1 -0
  183. package/dist/actions/rotate/replay.js +25 -0
  184. package/dist/actions/rotate/replay.js.map +1 -0
  185. package/dist/actions/rotate/session.js +135 -0
  186. package/dist/actions/rotate/session.js.map +1 -0
  187. package/dist/actions/select/areaSelect.js +83 -0
  188. package/dist/actions/select/areaSelect.js.map +1 -0
  189. package/dist/actions/select/clearSelection.js +33 -0
  190. package/dist/actions/select/clearSelection.js.map +1 -0
  191. package/dist/actions/swap/action.js +63 -0
  192. package/dist/actions/swap/action.js.map +1 -0
  193. package/dist/actions/swap/swapOps.js +160 -0
  194. package/dist/actions/swap/swapOps.js.map +1 -0
  195. package/dist/actions/transformAgain/action.js +16 -14
  196. package/dist/actions/transformAgain/action.js.map +1 -1
  197. package/dist/actions/transformAgain/transformSelection.js +19 -5
  198. package/dist/actions/transformAgain/transformSelection.js.map +1 -1
  199. package/dist/booleans/booleans.js +130 -0
  200. package/dist/booleans/booleans.js.map +1 -0
  201. package/dist/booleans/commit.js +45 -0
  202. package/dist/booleans/commit.js.map +1 -0
  203. package/dist/booleans/custom.js +48 -0
  204. package/dist/booleans/custom.js.map +1 -0
  205. package/dist/booleans/operands.js +50 -0
  206. package/dist/booleans/operands.js.map +1 -0
  207. package/dist/booleans/pieces.js +43 -0
  208. package/dist/booleans/pieces.js.map +1 -0
  209. package/dist/booleans/placement.js +37 -0
  210. package/dist/booleans/placement.js.map +1 -0
  211. package/dist/booleans/useBooleans.js +34 -0
  212. package/dist/booleans/useBooleans.js.map +1 -0
  213. package/dist/booleans/useBooleansAdapter.js +11 -0
  214. package/dist/booleans/useBooleansAdapter.js.map +1 -0
  215. package/dist/chrome/affordances/cornerResize.js +123 -0
  216. package/dist/chrome/affordances/cornerResize.js.map +1 -0
  217. package/dist/chrome/affordances/rotateCursor.js +17 -0
  218. package/dist/chrome/affordances/rotateCursor.js.map +1 -0
  219. package/dist/chrome/affordances/rotationHandle.js +117 -0
  220. package/dist/chrome/affordances/rotationHandle.js.map +1 -0
  221. package/dist/chrome/handleCommands.js +110 -0
  222. package/dist/chrome/handleCommands.js.map +1 -0
  223. package/dist/chrome/overlay.js +271 -0
  224. package/dist/chrome/overlay.js.map +1 -0
  225. package/dist/chrome/rotationBadge.js +132 -0
  226. package/dist/chrome/rotationBadge.js.map +1 -0
  227. package/dist/chrome/rotationHandleGeometry.js +49 -0
  228. package/dist/chrome/rotationHandleGeometry.js.map +1 -0
  229. package/dist/chrome/selectionChrome.js +25 -0
  230. package/dist/chrome/selectionChrome.js.map +1 -0
  231. package/dist/chrome/selectionPose.js +112 -0
  232. package/dist/chrome/selectionPose.js.map +1 -0
  233. package/dist/chrome/shapeOutline.js +137 -0
  234. package/dist/chrome/shapeOutline.js.map +1 -0
  235. package/dist/clipboard/clipboardOps.js +48 -0
  236. package/dist/clipboard/clipboardOps.js.map +1 -0
  237. package/dist/clipboard/materializePaste.js +34 -0
  238. package/dist/clipboard/materializePaste.js.map +1 -0
  239. package/dist/clipboard/osClipboard.js +67 -0
  240. package/dist/clipboard/osClipboard.js.map +1 -0
  241. package/dist/clipboard/useClipboard.js +64 -0
  242. package/dist/clipboard/useClipboard.js.map +1 -0
  243. package/dist/clipboard/wireFormat.js +108 -0
  244. package/dist/clipboard/wireFormat.js.map +1 -0
  245. package/dist/deps/areaSelect.js +42 -0
  246. package/dist/deps/areaSelect.js.map +1 -0
  247. package/dist/deps/booleans.js +99 -0
  248. package/dist/deps/booleans.js.map +1 -0
  249. package/dist/deps/insert.js +260 -0
  250. package/dist/deps/insert.js.map +1 -0
  251. package/dist/deps/lassoSelect.js +37 -0
  252. package/dist/deps/lassoSelect.js.map +1 -0
  253. package/dist/deps/presetDeps.js +40 -0
  254. package/dist/deps/presetDeps.js.map +1 -0
  255. package/dist/deps/resizePolicy.js +41 -0
  256. package/dist/deps/resizePolicy.js.map +1 -0
  257. package/dist/engine-BV9RDHOL.d.ts +339 -0
  258. package/dist/engine.d.ts +6 -0
  259. package/dist/engine.js +10 -0
  260. package/dist/engineStandardActions.js +16 -7
  261. package/dist/engineStandardActions.js.map +1 -1
  262. package/dist/groups.d.ts +27 -0
  263. package/dist/groups.js +4 -0
  264. package/dist/icons.gen.js +8 -0
  265. package/dist/icons.gen.js.map +1 -0
  266. package/dist/icons.table.d.ts +6 -0
  267. package/dist/icons.table.js +8 -0
  268. package/dist/icons.table.js.map +1 -0
  269. package/dist/icons.table.json +156 -0
  270. package/dist/icons2.table.js +163 -0
  271. package/dist/icons2.table.js.map +1 -0
  272. package/dist/index.d.ts +1293 -105
  273. package/dist/index.js +61 -12
  274. package/dist/ingest/ghost.js +58 -0
  275. package/dist/ingest/ghost.js.map +1 -0
  276. package/dist/ingest/imageHandler.js +80 -0
  277. package/dist/ingest/imageHandler.js.map +1 -0
  278. package/dist/ingest/kitHandlers.js +15 -0
  279. package/dist/ingest/kitHandlers.js.map +1 -0
  280. package/dist/ingest/svgHandler.js +97 -0
  281. package/dist/ingest/svgHandler.js.map +1 -0
  282. package/dist/ingest/weaselJsonHandler.js +68 -0
  283. package/dist/ingest/weaselJsonHandler.js.map +1 -0
  284. package/dist/namedPresets.js +23 -11
  285. package/dist/namedPresets.js.map +1 -1
  286. package/dist/presets/arrange.js +21 -7
  287. package/dist/presets/arrange.js.map +1 -1
  288. package/dist/presets/booleans.js +13 -0
  289. package/dist/presets/booleans.js.map +1 -0
  290. package/dist/presets/composites.js +8 -5
  291. package/dist/presets/composites.js.map +1 -1
  292. package/dist/presets/edit.js +25 -13
  293. package/dist/presets/edit.js.map +1 -1
  294. package/dist/presets/ingest.js +7 -3
  295. package/dist/presets/ingest.js.map +1 -1
  296. package/dist/presets/insert.js +28 -0
  297. package/dist/presets/insert.js.map +1 -0
  298. package/dist/presets/pathfinder.js +5 -2
  299. package/dist/presets/pathfinder.js.map +1 -1
  300. package/dist/presets/select.js +16 -3
  301. package/dist/presets/select.js.map +1 -1
  302. package/dist/presets/selection.js +13 -0
  303. package/dist/presets/selection.js.map +1 -0
  304. package/dist/presets/selectionChrome.js +15 -0
  305. package/dist/presets/selectionChrome.js.map +1 -0
  306. package/dist/presets/tools.js +78 -9
  307. package/dist/presets/tools.js.map +1 -1
  308. package/dist/presets/transform.js +20 -7
  309. package/dist/presets/transform.js.map +1 -1
  310. package/dist/presets.d.ts +104 -0
  311. package/dist/presets.js +15 -0
  312. package/dist/selection/useSelection.js +127 -0
  313. package/dist/selection/useSelection.js.map +1 -0
  314. package/dist/test-seams.d.ts +50 -0
  315. package/dist/test-seams.js +4 -0
  316. package/dist/tools/ellipse/useEllipseTool.js +72 -0
  317. package/dist/tools/ellipse/useEllipseTool.js.map +1 -0
  318. package/dist/tools/eyedropper/useEyedropperTool.js +100 -0
  319. package/dist/tools/eyedropper/useEyedropperTool.js.map +1 -0
  320. package/dist/tools/image/useImageTool.js +57 -0
  321. package/dist/tools/image/useImageTool.js.map +1 -0
  322. package/dist/tools/lasso/useLassoTool.js +96 -0
  323. package/dist/tools/lasso/useLassoTool.js.map +1 -0
  324. package/dist/tools/line/useLineTool.js +67 -0
  325. package/dist/tools/line/useLineTool.js.map +1 -0
  326. package/dist/tools/polygon/usePolygonTool.js +149 -0
  327. package/dist/tools/polygon/usePolygonTool.js.map +1 -0
  328. package/dist/tools/rect/useRectTool.js +74 -0
  329. package/dist/tools/rect/useRectTool.js.map +1 -0
  330. package/dist/tools/select/adapterPointQuery.js +56 -0
  331. package/dist/tools/select/adapterPointQuery.js.map +1 -0
  332. package/dist/tools/select/collapseDeferred.js +35 -0
  333. package/dist/tools/select/collapseDeferred.js.map +1 -0
  334. package/dist/tools/select/extendPressLocked.js +17 -0
  335. package/dist/tools/select/extendPressLocked.js.map +1 -0
  336. package/dist/tools/select/groupEntry.js +73 -0
  337. package/dist/tools/select/groupEntry.js.map +1 -0
  338. package/dist/tools/select/pressDecision.js +39 -0
  339. package/dist/tools/select/pressDecision.js.map +1 -0
  340. package/dist/tools/select/selectDeep.js +39 -0
  341. package/dist/tools/select/selectDeep.js.map +1 -0
  342. package/dist/tools/select/selectPick.js +60 -0
  343. package/dist/tools/select/selectPick.js.map +1 -0
  344. package/dist/tools/select/selectionContributions.js +191 -0
  345. package/dist/tools/select/selectionContributions.js.map +1 -0
  346. package/dist/tools/select/usePickerSelectTool.js +145 -0
  347. package/dist/tools/select/usePickerSelectTool.js.map +1 -0
  348. package/dist/tools/select/useSelectTool.js +54 -0
  349. package/dist/tools/select/useSelectTool.js.map +1 -0
  350. package/dist/tools/shared/countOption.js +24 -0
  351. package/dist/tools/shared/countOption.js.map +1 -0
  352. package/dist/tools/shared/insertToolOptions.js +8 -0
  353. package/dist/tools/shared/insertToolOptions.js.map +1 -0
  354. package/dist/tools/shared/pointerFollower.js +23 -0
  355. package/dist/tools/shared/pointerFollower.js.map +1 -0
  356. package/dist/tools/shared/styleOptions.js +76 -0
  357. package/dist/tools/shared/styleOptions.js.map +1 -0
  358. package/dist/tools/star/useStarTool.js +149 -0
  359. package/dist/tools/star/useStarTool.js.map +1 -0
  360. package/dist/tools/toolSets.js +26 -0
  361. package/dist/tools/toolSets.js.map +1 -0
  362. package/package.json +39 -11
  363. package/dist/actions/edit/escape.js.map +0 -1
@@ -0,0 +1,73 @@
1
+ import { createEnterGroupAction, createLeaveGroupAction } from "../../actions/group/enterGroup.js";
2
+ import { isBodyOffChrome, isEmptyOffChrome } from "./selectionContributions.js";
3
+ import { BETWEEN_GESTURES } from "@weasel-js/routing";
4
+ import { useMemo } from "react";
5
+ import { useLatest } from "@weasel-js/react";
6
+ import { ANY_MODS } from "@weasel-js/gestures";
7
+
8
+ // src/tools/select/groupEntry.ts
9
+ /** Id of the entry {@link createGroupEntryContribution} builds. */
10
+ var GROUP_ENTRY_ID = "group.entry";
11
+ /**
12
+ * `group.enter` and `group.leave`, bound under any tool that leaves the gesture unclaimed. A
13
+ * double-click on a body enters the group a press there would select, and declines where that is
14
+ * no group, so text and path editing keep their double-click. Escape leaves one level, carrying
15
+ * the phase `escape` does and declining with nothing entered, which leaves Escape to `escape`.
16
+ * Leaving on a press is the select tool's ({@link GROUP_LEAVE_PRESS_BINDING}): under a drawing
17
+ * tool a press outside the group draws into it.
18
+ */
19
+ function createGroupEntryContribution(opts) {
20
+ return {
21
+ id: GROUP_ENTRY_ID,
22
+ eligibility: { always: true },
23
+ actions: [createEnterGroupAction(opts), createLeaveGroupAction(opts)],
24
+ bindings: [{
25
+ spec: {
26
+ kind: "doubleClick",
27
+ target: { kindOf: isBodyOffChrome },
28
+ phase: BETWEEN_GESTURES
29
+ },
30
+ actionId: "group.enter",
31
+ opts: { id: "group.enter" }
32
+ }, {
33
+ spec: {
34
+ kind: "key",
35
+ key: "Escape",
36
+ phase: BETWEEN_GESTURES
37
+ },
38
+ actionId: "group.leave",
39
+ opts: {
40
+ id: "group.leave.key",
41
+ yields: true
42
+ }
43
+ }]
44
+ };
45
+ }
46
+ /** {@link createGroupEntryContribution} for the life of a canvas, reading its pickers live. */
47
+ function useGroupEntryContribution(opts) {
48
+ const live = useLatest(opts);
49
+ return useMemo(() => createGroupEntryContribution({
50
+ pickHit: (world, viewId) => viewId == null ? live.current.pickHit(world) : live.current.pickHit(world, viewId),
51
+ tree: {
52
+ getParent: (id) => live.current.tree.getParent(id),
53
+ getNode: (id) => live.current.tree.getNode(id)
54
+ },
55
+ boxOf: (id) => live.current.boxOf(id)
56
+ }), [live]);
57
+ }
58
+ /**
59
+ * A press outside the entered group's box leaves it, whatever modifiers are held. Nodes outside
60
+ * the group take no hits, so every such press lands on empty canvas.
61
+ */
62
+ var GROUP_LEAVE_PRESS_BINDING = {
63
+ spec: {
64
+ kind: "pointerDown",
65
+ target: { kindOf: isEmptyOffChrome },
66
+ mods: ANY_MODS
67
+ },
68
+ actionId: "group.leave",
69
+ opts: { id: "group.leave.press" }
70
+ };
71
+
72
+ export { GROUP_ENTRY_ID, GROUP_LEAVE_PRESS_BINDING, createGroupEntryContribution, useGroupEntryContribution };
73
+ //# sourceMappingURL=groupEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupEntry.js","names":[],"sources":["../../../src/tools/select/groupEntry.ts"],"sourcesContent":["import { ANY_MODS } from '@weasel-js/gestures';\nimport { useMemo } from 'react';\nimport { useLatest } from '@weasel-js/react';\nimport {\n createEnterGroupAction, createLeaveGroupAction, type EnterGroupOptions, type LeaveGroupOptions,\n} from '../../actions/group/enterGroup';\nimport type { Contribution } from '@weasel-js/core';\nimport { isBodyOffChrome, isEmptyOffChrome } from './selectionContributions';\nimport { BETWEEN_GESTURES } from '@weasel-js/routing';\nimport type {} from '@weasel-js/core';\n\n/** Id of the entry {@link createGroupEntryContribution} builds. */\nexport const GROUP_ENTRY_ID = 'group.entry';\n\n/**\n * `group.enter` and `group.leave`, bound under any tool that leaves the gesture unclaimed. A\n * double-click on a body enters the group a press there would select, and declines where that is\n * no group, so text and path editing keep their double-click. Escape leaves one level, carrying\n * the phase `escape` does and declining with nothing entered, which leaves Escape to `escape`.\n * Leaving on a press is the select tool's ({@link GROUP_LEAVE_PRESS_BINDING}): under a drawing\n * tool a press outside the group draws into it.\n */\nexport function createGroupEntryContribution(opts: EnterGroupOptions & LeaveGroupOptions): Contribution {\n return {\n id: GROUP_ENTRY_ID,\n eligibility: { always: true },\n actions: [createEnterGroupAction(opts), createLeaveGroupAction(opts)],\n bindings: [\n {\n spec: { kind: 'doubleClick', target: { kindOf: isBodyOffChrome }, phase: BETWEEN_GESTURES },\n actionId: 'group.enter',\n opts: { id: 'group.enter' },\n },\n {\n spec: { kind: 'key', key: 'Escape', phase: BETWEEN_GESTURES },\n actionId: 'group.leave',\n opts: { id: 'group.leave.key', yields: true },\n },\n ],\n };\n}\n\n/** {@link createGroupEntryContribution} for the life of a canvas, reading its pickers live. */\nexport function useGroupEntryContribution(opts: EnterGroupOptions & LeaveGroupOptions): Contribution {\n const live = useLatest(opts);\n return useMemo(() => createGroupEntryContribution({\n pickHit: (world, viewId) => (viewId == null ? live.current.pickHit(world) : live.current.pickHit(world, viewId)),\n tree: {\n getParent: (id) => live.current.tree.getParent(id),\n getNode: (id) => live.current.tree.getNode(id),\n },\n boxOf: (id) => live.current.boxOf(id),\n }), [live]);\n}\n\n/**\n * A press outside the entered group's box leaves it, whatever modifiers are held. Nodes outside\n * the group take no hits, so every such press lands on empty canvas.\n */\nexport const GROUP_LEAVE_PRESS_BINDING = {\n spec: { kind: 'pointerDown' as const, target: { kindOf: isEmptyOffChrome }, mods: ANY_MODS },\n actionId: 'group.leave',\n opts: { id: 'group.leave.press' },\n};\n"],"mappings":";;;;;;;;;AAYA,IAAa,iBAAiB;;;;;;;;;AAU9B,SAAgB,6BAA6B,MAA2D;CACtG,OAAO;EACL,IAAI;EACJ,aAAa,EAAE,QAAQ,KAAK;EAC5B,SAAS,CAAC,uBAAuB,IAAI,GAAG,uBAAuB,IAAI,CAAC;EACpE,UAAU,CACR;GACE,MAAM;IAAE,MAAM;IAAe,QAAQ,EAAE,QAAQ,gBAAgB;IAAG,OAAO;GAAiB;GAC1F,UAAU;GACV,MAAM,EAAE,IAAI,cAAc;EAC5B,GACA;GACE,MAAM;IAAE,MAAM;IAAO,KAAK;IAAU,OAAO;GAAiB;GAC5D,UAAU;GACV,MAAM;IAAE,IAAI;IAAmB,QAAQ;GAAK;EAC9C,CACF;CACF;AACF;;AAGA,SAAgB,0BAA0B,MAA2D;CACnG,MAAM,OAAO,UAAU,IAAI;CAC3B,OAAO,cAAc,6BAA6B;EAChD,UAAU,OAAO,WAAY,UAAU,OAAO,KAAK,QAAQ,QAAQ,KAAK,IAAI,KAAK,QAAQ,QAAQ,OAAO,MAAM;EAC9G,MAAM;GACJ,YAAY,OAAO,KAAK,QAAQ,KAAK,UAAU,EAAE;GACjD,UAAU,OAAO,KAAK,QAAQ,KAAK,QAAQ,EAAE;EAC/C;EACA,QAAQ,OAAO,KAAK,QAAQ,MAAM,EAAE;CACtC,CAAC,GAAG,CAAC,IAAI,CAAC;AACZ;;;;;AAMA,IAAa,4BAA4B;CACvC,MAAM;EAAE,MAAM;EAAwB,QAAQ,EAAE,QAAQ,iBAAiB;EAAG,MAAM;CAAS;CAC3F,UAAU;CACV,MAAM,EAAE,IAAI,oBAAoB;AAClC"}
@@ -0,0 +1,39 @@
1
+ import { isEnvelope } from "@weasel-js/core";
2
+ import { holderOf } from "@weasel-js/select";
3
+
4
+ // src/tools/select/pressDecision.ts
5
+ /**
6
+ * Decide a press on `top`; `extend` is whether the selection reads its
7
+ * modifiers as a toggle or a range (`SelectionApi.intentOf`), and `locked`
8
+ * whether the press must not change it (`extendPressLocked`).
9
+ *
10
+ * Pressing a member of a multi-selection, or a node inside a selected group,
11
+ * leaves the selection alone: the press may be the start of a drag of the
12
+ * set, or of the group. A group here is a container whose pose derives from
13
+ * its children; one with its own pose is a place its members sit, and a press
14
+ * picks the member out of it.
15
+ *
16
+ * A locked press neither applies nor defers: the release would otherwise
17
+ * make the change the lock holds back.
18
+ */
19
+ function pressDecision(top, sel, extend, locked, tree) {
20
+ const inMultiSelection = sel.includes(top) && sel.length > 1;
21
+ const defer = !extend && (inMultiSelection || insideSelectedGroup(top, sel, tree));
22
+ if (locked) return {
23
+ applyNow: false,
24
+ deferred: null
25
+ };
26
+ return {
27
+ applyNow: !defer,
28
+ deferred: defer ? top : null
29
+ };
30
+ }
31
+ function insideSelectedGroup(top, sel, tree) {
32
+ if (sel.includes(top)) return false;
33
+ const ancestor = holderOf(new Set(sel), top, (id) => tree.getParent(id));
34
+ const node = ancestor === null ? void 0 : tree.getNode(ancestor);
35
+ return node !== void 0 && isEnvelope(node);
36
+ }
37
+
38
+ export { pressDecision };
39
+ //# sourceMappingURL=pressDecision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pressDecision.js","names":[],"sources":["../../../src/tools/select/pressDecision.ts"],"sourcesContent":["import { isEnvelope } from '@weasel-js/core';\nimport { holderOf } from '@weasel-js/select';\n\n/** The tree a press reads: who a node's parent is, and the node itself. */\nexport interface PressTree {\n getParent(id: string): string | null;\n getNode(id: string): unknown;\n}\n\n/** What a press on `top` does to the selection. */\nexport interface PressDecision {\n /** Apply the click to the selection on the press. */\n applyNow: boolean;\n /** The id the click is held back for until release, so the press can drag\n * what is already selected instead; `null` when nothing is held back. */\n deferred: string | null;\n}\n\n/**\n * Decide a press on `top`; `extend` is whether the selection reads its\n * modifiers as a toggle or a range (`SelectionApi.intentOf`), and `locked`\n * whether the press must not change it (`extendPressLocked`).\n *\n * Pressing a member of a multi-selection, or a node inside a selected group,\n * leaves the selection alone: the press may be the start of a drag of the\n * set, or of the group. A group here is a container whose pose derives from\n * its children; one with its own pose is a place its members sit, and a press\n * picks the member out of it.\n *\n * A locked press neither applies nor defers: the release would otherwise\n * make the change the lock holds back.\n */\nexport function pressDecision(\n top: string,\n sel: readonly string[],\n extend: boolean,\n locked: boolean,\n tree: PressTree,\n): PressDecision {\n const inMultiSelection = sel.includes(top) && sel.length > 1;\n const defer = !extend && (inMultiSelection || insideSelectedGroup(top, sel, tree));\n // A locked press changes nothing on the press, and nothing on release either.\n if (locked) return { applyNow: false, deferred: null };\n return { applyNow: !defer, deferred: defer ? top : null };\n}\n\nfunction insideSelectedGroup(top: string, sel: readonly string[], tree: PressTree): boolean {\n if (sel.includes(top)) return false;\n const ancestor = holderOf(new Set(sel), top, (id) => tree.getParent(id));\n const node = ancestor === null ? undefined : tree.getNode(ancestor) as { dependsOn?: unknown; derivePose?: unknown } | undefined;\n return node !== undefined && isEnvelope(node);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgCA,SAAgB,cACd,KACA,KACA,QACA,QACA,MACe;CACf,MAAM,mBAAmB,IAAI,SAAS,GAAG,KAAK,IAAI,SAAS;CAC3D,MAAM,QAAQ,CAAC,WAAW,oBAAoB,oBAAoB,KAAK,KAAK,IAAI;CAEhF,IAAI,QAAQ,OAAO;EAAE,UAAU;EAAO,UAAU;CAAK;CACrD,OAAO;EAAE,UAAU,CAAC;EAAO,UAAU,QAAQ,MAAM;CAAK;AAC1D;AAEA,SAAS,oBAAoB,KAAa,KAAwB,MAA0B;CAC1F,IAAI,IAAI,SAAS,GAAG,GAAG,OAAO;CAC9B,MAAM,WAAW,SAAS,IAAI,IAAI,GAAG,GAAG,MAAM,OAAO,KAAK,UAAU,EAAE,CAAC;CACvE,MAAM,OAAO,aAAa,OAAO,SAAY,KAAK,QAAQ,QAAQ;CAClE,OAAO,SAAS,UAAa,WAAW,IAAI;AAC9C"}
@@ -0,0 +1,39 @@
1
+ import { extendPressLocked } from "./extendPressLocked.js";
2
+ import { defineAction } from "@weasel-js/routing";
3
+
4
+ // src/tools/select/selectDeep.ts
5
+ /**
6
+ * `select.deep` — selects the node under the point itself, not the outermost
7
+ * group above it; with Shift it applies the click the way the selection's keys read Shift, a range
8
+ * covering what `rangeAt` gives. Bound to Cmd+Alt-press by `useSelectTool`, ahead of `select.pick`.
9
+ */
10
+ function createSelectDeepAction(opts) {
11
+ return defineAction({
12
+ id: "select.deep",
13
+ label: "Select — pick past groups",
14
+ eligible: { capability: "creates-selection" },
15
+ requires: ["selection"],
16
+ invoker: {
17
+ timing: "immediate",
18
+ run: (deps, p) => {
19
+ const selection = deps.selection;
20
+ if (!selection || !p?.world) return;
21
+ const mods = {
22
+ ctrl: false,
23
+ meta: false,
24
+ shift: p.mods?.shift === true
25
+ };
26
+ const hit = opts.pickHit(p.world, false, selection.get(), p.viewId);
27
+ opts.settled();
28
+ const intent = selection.intentOf(mods);
29
+ if (hit === null || extendPressLocked(intent, mods.shift, opts.extendLocked)) return;
30
+ const between = intent === "range" ? opts.rangeAt?.(hit) : void 0;
31
+ if (between) selection.applyClick(hit, mods, between);
32
+ else selection.applyClick(hit, mods);
33
+ }
34
+ }
35
+ });
36
+ }
37
+
38
+ export { createSelectDeepAction };
39
+ //# sourceMappingURL=selectDeep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectDeep.js","names":[],"sources":["../../../src/tools/select/selectDeep.ts"],"sourcesContent":["import { defineAction, type Action, type WorldPoint } from '@weasel-js/routing';\nimport type { NodeId } from '@weasel-js/core';\nimport { extendPressLocked } from './extendPressLocked';\nimport type {} from '@weasel-js/core';\n\nexport interface SelectDeepOptions {\n /** The node under the point, past every group. Locked nodes are the\n * picker's to skip, as they are for `select.pick`. */\n pickHit: (world: WorldPoint, alt: boolean, selection: readonly string[], viewId?: string | null) => string | null;\n /** True when an extend press must leave the selection alone. */\n extendLocked: () => boolean;\n /** Called once the press is handled, so a deferral left by an earlier press cannot fire on release. */\n settled: () => void;\n /** What a range to `hit` covers, or undefined to walk the selection's own order. */\n rangeAt?: (hit: string) => ((from: NodeId, to: NodeId) => readonly NodeId[]) | undefined;\n}\n\n/**\n * `select.deep` — selects the node under the point itself, not the outermost\n * group above it; with Shift it applies the click the way the selection's keys read Shift, a range\n * covering what `rangeAt` gives. Bound to Cmd+Alt-press by `useSelectTool`, ahead of `select.pick`.\n */\nexport function createSelectDeepAction(opts: SelectDeepOptions): Action {\n return defineAction({\n id: 'select.deep',\n label: 'Select — pick past groups',\n eligible: { capability: 'creates-selection' },\n requires: ['selection'],\n invoker: {\n timing: 'immediate',\n run: (deps, p) => {\n const selection = deps.selection;\n if (!selection || !p?.world) return;\n // The deep chord is Mod+Alt, so only Shift is left to say how the click applies.\n const mods = { ctrl: false, meta: false, shift: p.mods?.shift === true };\n const hit = opts.pickHit(p.world, false, selection.get(), p.viewId);\n opts.settled();\n const intent = selection.intentOf(mods);\n if (hit === null || extendPressLocked(intent, mods.shift, opts.extendLocked)) return;\n const between = intent === 'range' ? opts.rangeAt?.(hit) : undefined;\n if (between) selection.applyClick(hit as NodeId, mods, between);\n else selection.applyClick(hit as NodeId, mods);\n },\n },\n });\n}\n"],"mappings":";;;;;;;;;AAsBA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,aAAa;EAClB,IAAI;EACJ,OAAO;EACP,UAAU,EAAE,YAAY,oBAAoB;EAC5C,UAAU,CAAC,WAAW;EACtB,SAAS;GACP,QAAQ;GACR,MAAM,MAAM,MAAM;IAChB,MAAM,YAAY,KAAK;IACvB,IAAI,CAAC,aAAa,CAAC,GAAG,OAAO;IAE7B,MAAM,OAAO;KAAE,MAAM;KAAO,MAAM;KAAO,OAAO,EAAE,MAAM,UAAU;IAAK;IACvE,MAAM,MAAM,KAAK,QAAQ,EAAE,OAAO,OAAO,UAAU,IAAI,GAAG,EAAE,MAAM;IAClE,KAAK,QAAQ;IACb,MAAM,SAAS,UAAU,SAAS,IAAI;IACtC,IAAI,QAAQ,QAAQ,kBAAkB,QAAQ,KAAK,OAAO,KAAK,YAAY,GAAG;IAC9E,MAAM,UAAU,WAAW,UAAU,KAAK,UAAU,GAAG,IAAI;IAC3D,IAAI,SAAS,UAAU,WAAW,KAAe,MAAM,OAAO;SACzD,UAAU,WAAW,KAAe,IAAI;GAC/C;EACF;CACF,CAAC;AACH"}
@@ -0,0 +1,60 @@
1
+ import { extendPressLocked, extendsSelection } from "./extendPressLocked.js";
2
+ import { pressDecision } from "./pressDecision.js";
3
+ import { defineAction } from "@weasel-js/routing";
4
+ import { pressTarget } from "@weasel-js/core/engine";
5
+
6
+ // src/tools/select/selectPick.ts
7
+ /**
8
+ * `select.pick` — classifies the press and updates the node selection.
9
+ *
10
+ * Bound to `pointerDown` rather than `click` on purpose: pressing an
11
+ * unselected node must highlight it while the button is still down, and any
12
+ * drag that follows has to start from the updated selection (both
13
+ * `moveAction` and `cloneAction` read `selection.get()` in their `start`).
14
+ */
15
+ function createSelectPickAction(opts) {
16
+ return defineAction({
17
+ id: "select.pick",
18
+ label: "Select — pick under pointer",
19
+ eligible: { capability: "creates-selection" },
20
+ requires: ["selection", "enteredGroup"],
21
+ invoker: {
22
+ timing: "immediate",
23
+ run: (deps, p) => {
24
+ const selection = deps.selection;
25
+ if (!selection || !p?.world) return;
26
+ const mods = p.mods ?? {
27
+ alt: false,
28
+ ctrl: false,
29
+ meta: false,
30
+ shift: false
31
+ };
32
+ const sel = selection.get();
33
+ const hit = opts.pickHit(p.world, mods.alt, sel, p.viewId);
34
+ if (hit === null) {
35
+ opts.pressed(null);
36
+ return;
37
+ }
38
+ const entered = deps.enteredGroup?.get() ?? null;
39
+ const tree = opts.tree();
40
+ const top = pressTarget(tree, hit, entered);
41
+ const intent = selection.intentOf(mods);
42
+ const locked = extendPressLocked(intent, mods.shift === true, opts.extendLocked);
43
+ const press = pressDecision(top, sel, extendsSelection(intent), locked, tree);
44
+ if (press.applyNow) applyClickIn(selection, top, mods, intent === "range" ? opts.rangeIn(entered) : void 0);
45
+ opts.pressed(press.deferred === null ? null : {
46
+ id: press.deferred,
47
+ mods
48
+ });
49
+ }
50
+ }
51
+ });
52
+ }
53
+ /** `selection.applyClick`, handing it `between` only when there is one. */
54
+ function applyClickIn(selection, id, mods, between) {
55
+ if (between) selection.applyClick(id, mods, between);
56
+ else selection.applyClick(id, mods);
57
+ }
58
+
59
+ export { applyClickIn, createSelectPickAction };
60
+ //# sourceMappingURL=selectPick.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectPick.js","names":[],"sources":["../../../src/tools/select/selectPick.ts"],"sourcesContent":["import { defineAction, type Action, type SelectionApi, type WorldPoint } from '@weasel-js/routing';\nimport type { SelectModifiers } from '@weasel-js/select';\nimport type { NodeId } from '@weasel-js/core';\nimport { extendPressLocked, extendsSelection } from './extendPressLocked';\nimport { pressTarget, type PressTargetTree } from '@weasel-js/core/engine';\nimport { pressDecision, type PressTree } from './pressDecision';\nimport type { DeferredClick } from './collapseDeferred';\nimport type {} from '@weasel-js/core';\n\ntype Between = (from: NodeId, to: NodeId) => readonly NodeId[];\n\nexport interface SelectPickOptions {\n /** The node under the point, before any group above it is considered. */\n pickHit: (world: WorldPoint, alt: boolean, selection: readonly string[], viewId?: string | null) => string | null;\n /** True when an extend press must leave the selection alone. */\n extendLocked: () => boolean;\n /** The tree the press reads. */\n tree: () => PressTree & PressTargetTree;\n /** What a range covers for a press inside `level`, or undefined to walk the selection's order. */\n rangeIn: (level: string | null) => Between | undefined;\n /** Told the click the press held back, with the modifiers it was classified with, or null. */\n pressed: (deferred: DeferredClick | null) => void;\n}\n\n/**\n * `select.pick` — classifies the press and updates the node selection.\n *\n * Bound to `pointerDown` rather than `click` on purpose: pressing an\n * unselected node must highlight it while the button is still down, and any\n * drag that follows has to start from the updated selection (both\n * `moveAction` and `cloneAction` read `selection.get()` in their `start`).\n */\nexport function createSelectPickAction(opts: SelectPickOptions): Action {\n return defineAction({\n id: 'select.pick',\n label: 'Select — pick under pointer',\n eligible: { capability: 'creates-selection' },\n requires: ['selection', 'enteredGroup'],\n invoker: {\n timing: 'immediate',\n run: (deps, p) => {\n const selection = deps.selection;\n if (!selection || !p?.world) return;\n const mods = p.mods ?? { alt: false, ctrl: false, meta: false, shift: false };\n const sel = selection.get();\n const hit = opts.pickHit(p.world, mods.alt, sel, p.viewId);\n if (hit === null) {\n opts.pressed(null);\n return;\n }\n const entered = deps.enteredGroup?.get() ?? null;\n const tree = opts.tree();\n const top = pressTarget(tree, hit, entered);\n\n // `extendClickLocked` is an option rather than `Action.enabled` because it reads the press's\n // modifiers, and `enabled` is evaluated without them.\n const intent = selection.intentOf(mods);\n const locked = extendPressLocked(intent, mods.shift === true, opts.extendLocked);\n const press = pressDecision(top, sel, extendsSelection(intent), locked, tree);\n if (press.applyNow) applyClickIn(selection, top as NodeId, mods, intent === 'range' ? opts.rangeIn(entered) : undefined);\n opts.pressed(press.deferred === null ? null : { id: press.deferred, mods });\n },\n },\n });\n}\n\n/** `selection.applyClick`, handing it `between` only when there is one. */\nexport function applyClickIn(selection: SelectionApi, id: NodeId, mods: SelectModifiers, between: Between | undefined): void {\n if (between) selection.applyClick(id, mods, between);\n else selection.applyClick(id, mods);\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,aAAa;EAClB,IAAI;EACJ,OAAO;EACP,UAAU,EAAE,YAAY,oBAAoB;EAC5C,UAAU,CAAC,aAAa,cAAc;EACtC,SAAS;GACP,QAAQ;GACR,MAAM,MAAM,MAAM;IAChB,MAAM,YAAY,KAAK;IACvB,IAAI,CAAC,aAAa,CAAC,GAAG,OAAO;IAC7B,MAAM,OAAO,EAAE,QAAQ;KAAE,KAAK;KAAO,MAAM;KAAO,MAAM;KAAO,OAAO;IAAM;IAC5E,MAAM,MAAM,UAAU,IAAI;IAC1B,MAAM,MAAM,KAAK,QAAQ,EAAE,OAAO,KAAK,KAAK,KAAK,EAAE,MAAM;IACzD,IAAI,QAAQ,MAAM;KAChB,KAAK,QAAQ,IAAI;KACjB;IACF;IACA,MAAM,UAAU,KAAK,cAAc,IAAI,KAAK;IAC5C,MAAM,OAAO,KAAK,KAAK;IACvB,MAAM,MAAM,YAAY,MAAM,KAAK,OAAO;IAI1C,MAAM,SAAS,UAAU,SAAS,IAAI;IACtC,MAAM,SAAS,kBAAkB,QAAQ,KAAK,UAAU,MAAM,KAAK,YAAY;IAC/E,MAAM,QAAQ,cAAc,KAAK,KAAK,iBAAiB,MAAM,GAAG,QAAQ,IAAI;IAC5E,IAAI,MAAM,UAAU,aAAa,WAAW,KAAe,MAAM,WAAW,UAAU,KAAK,QAAQ,OAAO,IAAI,MAAS;IACvH,KAAK,QAAQ,MAAM,aAAa,OAAO,OAAO;KAAE,IAAI,MAAM;KAAU;IAAK,CAAC;GAC5E;EACF;CACF,CAAC;AACH;;AAGA,SAAgB,aAAa,WAAyB,IAAY,MAAuB,SAAoC;CAC3H,IAAI,SAAS,UAAU,WAAW,IAAI,MAAM,OAAO;MAC9C,UAAU,WAAW,IAAI,IAAI;AACpC"}
@@ -0,0 +1,191 @@
1
+ import { runLifecycleParams } from "@weasel-js/core";
2
+ import { isPathEditPart, isResizeHandle, isRotateHandle } from "@weasel-js/routing";
3
+ import { SNAP_ROLE_MODS } from "@weasel-js/core/engine";
4
+ import { hitPredicate } from "@weasel-js/gestures";
5
+
6
+ // src/tools/select/selectionContributions.ts
7
+ /** Id of the entry {@link createSelectionMoveContribution} builds. */
8
+ var SELECTION_MOVE_ID = "selection.move";
9
+ /** Id of the entry {@link createSelectionTransformContribution} builds. */
10
+ var SELECTION_TRANSFORM_ID = "selection.transform";
11
+ /** Id of the entry {@link createSelectionResizeContribution} builds. */
12
+ var SELECTION_RESIZE_ID = "selection.resize";
13
+ /** Id of the entry {@link createSelectionRotateContribution} builds. */
14
+ var SELECTION_ROTATE_ID = "selection.rotate";
15
+ /** Drag a body to move the selection; Alt-drag to clone it. */
16
+ function selectionMoveBindings(options = {}) {
17
+ const moveOpts = (() => {
18
+ const move = options.move ?? {};
19
+ const params = runLifecycleParams(move);
20
+ if (options.reparentOnDrop && options.reparentOnDrop !== "off") params.reparentOnDrop = options.reparentOnDrop;
21
+ if (move.expandIds) params.expandIds = move.expandIds;
22
+ return {
23
+ ...Object.keys(params).length > 0 ? { params } : {},
24
+ ...move.dragThresholdPx !== void 0 ? { dragThresholdPx: move.dragThresholdPx } : {},
25
+ ...move.behaviors?.length ? { behaviors: move.behaviors } : {}
26
+ };
27
+ })();
28
+ const cloneBehaviors = (options.move?.behaviors ?? []).flatMap((b) => b.clone ? [b.clone] : []);
29
+ const cloneOpts = (id) => ({
30
+ id,
31
+ ...options.move?.dragThresholdPx !== void 0 ? { dragThresholdPx: options.move.dragThresholdPx } : {},
32
+ ...cloneBehaviors.length ? { behaviors: cloneBehaviors } : {}
33
+ });
34
+ return [
35
+ {
36
+ spec: {
37
+ kind: "drag",
38
+ target: "selected-body",
39
+ mods: {
40
+ ...SNAP_ROLE_MODS,
41
+ alt: true
42
+ }
43
+ },
44
+ actionId: "clone",
45
+ opts: cloneOpts("selection.move.clone")
46
+ },
47
+ {
48
+ spec: {
49
+ kind: "drag",
50
+ target: "unselected-body",
51
+ mods: {
52
+ ...SNAP_ROLE_MODS,
53
+ alt: true
54
+ }
55
+ },
56
+ actionId: "clone",
57
+ opts: cloneOpts("selection.move.cloneUnselected")
58
+ },
59
+ {
60
+ spec: {
61
+ kind: "drag",
62
+ target: { kindOf: hitPredicate((afford, body) => body === "selected-body" && !isPathEditPart(afford)) },
63
+ mods: SNAP_ROLE_MODS
64
+ },
65
+ actionId: "move",
66
+ opts: {
67
+ ...moveOpts,
68
+ id: "selection.move.body"
69
+ }
70
+ },
71
+ {
72
+ spec: {
73
+ kind: "drag",
74
+ target: "unselected-body",
75
+ mods: SNAP_ROLE_MODS
76
+ },
77
+ actionId: "move",
78
+ opts: {
79
+ ...moveOpts,
80
+ id: "selection.move.unselectedBody"
81
+ }
82
+ }
83
+ ];
84
+ }
85
+ /** Drag a resize handle to resize the selection. Options come through the
86
+ * `resizePolicy` dep (`useResizePolicyDepSource`). */
87
+ function selectionResizeBindings() {
88
+ return [{
89
+ spec: {
90
+ kind: "drag",
91
+ target: { kindOf: isResizeHandle },
92
+ mods: SNAP_ROLE_MODS
93
+ },
94
+ actionId: "resize",
95
+ opts: { id: "selection.resize.handle" }
96
+ }];
97
+ }
98
+ /** Drag the rotation handle to rotate the selection. */
99
+ function selectionRotateBindings(options = {}) {
100
+ const rotate = options.rotate ?? {};
101
+ const params = runLifecycleParams({
102
+ ...rotate,
103
+ label: rotate.rotateLabel
104
+ });
105
+ if (rotate.pivot) params.pivot = rotate.pivot;
106
+ const opts = {
107
+ id: "selection.rotate.handle",
108
+ ...Object.keys(params).length > 0 ? { params } : {},
109
+ ...rotate.behaviors?.length ? { behaviors: rotate.behaviors } : {}
110
+ };
111
+ return [{
112
+ spec: {
113
+ kind: "drag",
114
+ target: { kindOf: isRotateHandle },
115
+ mods: SNAP_ROLE_MODS
116
+ },
117
+ actionId: "rotate",
118
+ opts
119
+ }];
120
+ }
121
+ /** Drag a resize handle to resize the selection, the rotation handle to rotate it. */
122
+ function selectionTransformBindings(options = {}) {
123
+ return [...selectionResizeBindings(), ...selectionRotateBindings(options)];
124
+ }
125
+ /** An always-live entry carrying {@link selectionMoveBindings}. Add it to a
126
+ * canvas's ambient list; `<SceneCanvas features={[presets.move]}>` does. */
127
+ function createSelectionMoveContribution(options = {}) {
128
+ return {
129
+ id: SELECTION_MOVE_ID,
130
+ eligibility: { always: true },
131
+ bindings: selectionMoveBindings(options)
132
+ };
133
+ }
134
+ /** An always-live entry carrying {@link selectionTransformBindings}: resize
135
+ * and rotate in one entry, what `<SceneCanvas features={[presets.transform]}>`
136
+ * turns on. */
137
+ function createSelectionTransformContribution(options = {}) {
138
+ return {
139
+ id: SELECTION_TRANSFORM_ID,
140
+ eligibility: { always: true },
141
+ bindings: selectionTransformBindings(options)
142
+ };
143
+ }
144
+ /** An always-live entry carrying {@link selectionResizeBindings}. Add it to a
145
+ * canvas's ambient list; `<SceneCanvas features={[presets.resize]}>` does. */
146
+ function createSelectionResizeContribution() {
147
+ return {
148
+ id: SELECTION_RESIZE_ID,
149
+ eligibility: { always: true },
150
+ bindings: selectionResizeBindings()
151
+ };
152
+ }
153
+ /** An always-live entry carrying {@link selectionRotateBindings}. Add it to a
154
+ * canvas's ambient list; `<SceneCanvas features={[presets.rotate]}>` does. */
155
+ function createSelectionRotateContribution(options = {}) {
156
+ return {
157
+ id: SELECTION_ROTATE_ID,
158
+ eligibility: { always: true },
159
+ bindings: selectionRotateBindings(options)
160
+ };
161
+ }
162
+ /** Id of the entry {@link createAreaSelectContribution} builds. */
163
+ var AREA_SELECT_ID = "selection.areaSelect";
164
+ /** A press on empty canvas: no hit, and not on chrome over it — the rotation
165
+ * handle and the outer half of a resize handle sit off the body. */
166
+ var isEmptyOffChrome = hitPredicate((hit, body) => hit == null && body === "empty");
167
+ /** A press on a node, off chrome. With no `classifyTarget` wired there is no
168
+ * body class to read, and every press off chrome passes. */
169
+ var isBodyOffChrome = hitPredicate((hit, body) => hit == null && body !== "empty");
170
+ /** An always-live entry that marquee-selects on a drag across empty canvas,
171
+ * under any tool that does not claim the drag itself. No preset installs it:
172
+ * the select tool already marquees, and a canvas that wants it under every
173
+ * tool adds this to its ambient list. */
174
+ function createAreaSelectContribution() {
175
+ return {
176
+ id: AREA_SELECT_ID,
177
+ eligibility: { always: true },
178
+ bindings: [{
179
+ spec: {
180
+ kind: "drag",
181
+ target: { kindOf: isEmptyOffChrome },
182
+ mods: { shift: "optional" }
183
+ },
184
+ actionId: "areaSelect",
185
+ opts: { id: "selection.areaSelect.drag" }
186
+ }]
187
+ };
188
+ }
189
+
190
+ export { AREA_SELECT_ID, SELECTION_MOVE_ID, SELECTION_RESIZE_ID, SELECTION_ROTATE_ID, SELECTION_TRANSFORM_ID, createAreaSelectContribution, createSelectionMoveContribution, createSelectionResizeContribution, createSelectionRotateContribution, createSelectionTransformContribution, isBodyOffChrome, isEmptyOffChrome, selectionMoveBindings, selectionResizeBindings, selectionRotateBindings, selectionTransformBindings };
191
+ //# sourceMappingURL=selectionContributions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectionContributions.js","names":[],"sources":["../../../src/tools/select/selectionContributions.ts"],"sourcesContent":["/**\n * The ambient bindings that act on the selection: moving it, cloning it, and\n * resizing or rotating it from its handles. They belong to the selection, not\n * to the select tool, so they run under any tool that does not claim the\n * gesture itself. `<SceneCanvas features>` installs them as the `move`,\n * `resize` and `rotate` presets.\n */\nimport type { BindingOptions, GestureBinding } from '@weasel-js/routing';\nimport type { MoveParams, RotateParams, Contribution, MoveOptions, RotateOptions } from '@weasel-js/core';\nimport { isResizeHandle, isRotateHandle, isPathEditPart } from '@weasel-js/routing';\nimport { hitPredicate } from '@weasel-js/gestures';\nimport { SNAP_ROLE_MODS } from '@weasel-js/core/engine';\nimport { runLifecycleParams } from '@weasel-js/core';\n\n/** Options for {@link createSelectionMoveContribution}. */\nexport interface SelectionMoveOptions<TPose = unknown> {\n /** Move-action options: `behaviors` become the move bindings'\n * `opts.behaviors`, everything else their `opts.params`. */\n move?: MoveOptions<TPose>;\n /** Reparent-on-drop behavior for drag-to-move. `'off'` (default) keeps\n * translate-only commits. `'top'` lands the moved nodes at the top of the\n * container under the drop point; `'above'` lands them immediately above the\n * hit sibling. Requires the `nodeAtPoint` dep (`<SceneCanvas>` sources it). */\n reparentOnDrop?: 'off' | 'top' | 'above';\n}\n\n/** Id of the entry {@link createSelectionMoveContribution} builds. */\nexport const SELECTION_MOVE_ID = 'selection.move';\n/** Id of the entry {@link createSelectionTransformContribution} builds. */\nexport const SELECTION_TRANSFORM_ID = 'selection.transform';\n/** Id of the entry {@link createSelectionResizeContribution} builds. */\nexport const SELECTION_RESIZE_ID = 'selection.resize';\n/** Id of the entry {@link createSelectionRotateContribution} builds. */\nexport const SELECTION_ROTATE_ID = 'selection.rotate';\n\n/** Drag a body to move the selection; Alt-drag to clone it. */\nexport function selectionMoveBindings<TPose>(\n options: SelectionMoveOptions<TPose> = {},\n): GestureBinding[] {\n // Shared move-binding opts (params + behaviors). Applied to\n // both the selected-body and unselected-body move bindings so a\n // first-touch drag and a re-drag commit identically.\n const moveOpts: BindingOptions<MoveParams> = (() => {\n const move = options.move ?? {};\n const params: MoveParams = runLifecycleParams(move);\n if (options.reparentOnDrop && options.reparentOnDrop !== 'off') params.reparentOnDrop = options.reparentOnDrop;\n if (move.expandIds) params.expandIds = move.expandIds;\n return {\n ...(Object.keys(params).length > 0 ? { params } : {}),\n ...(move.dragThresholdPx !== undefined ? { dragThresholdPx: move.dragThresholdPx } : {}),\n ...(move.behaviors?.length ? { behaviors: move.behaviors as BindingOptions['behaviors'] } : {}),\n };\n })();\n const cloneBehaviors = (options.move?.behaviors ?? []).flatMap((b) => (b.clone ? [b.clone] : []));\n // The threshold is the press's, not the move's: an Alt-press on the same\n // body waits as far as a plain one before it drops a copy.\n const cloneOpts = (id: string): Omit<BindingOptions, 'params'> => ({\n id,\n ...(options.move?.dragThresholdPx !== undefined ? { dragThresholdPx: options.move.dragThresholdPx } : {}),\n ...(cloneBehaviors.length ? { behaviors: cloneBehaviors as BindingOptions['behaviors'] } : {}),\n });\n\n return [\n // Alt-drag on a body → clone.\n // Listed BEFORE bare move so the strict-modifier dispatcher\n // picks this when Alt is held; bare move matches no-mod drags.\n // Both selected and unselected bodies are valid clone targets — the\n // select tool's pointerDown classifier calls `selection.applyClick(top, mods)`\n // on an unselected hit before the drag fires, so cloneAction's\n // `start` sees the hit node in `selection.get()` either way.\n { spec: { kind: 'drag' as const, target: 'selected-body' as const, mods: { ...SNAP_ROLE_MODS, alt: true } }, actionId: 'clone', opts: cloneOpts('selection.move.clone') },\n { spec: { kind: 'drag' as const, target: 'unselected-body' as const, mods: { ...SNAP_ROLE_MODS, alt: true } }, actionId: 'clone', opts: cloneOpts('selection.move.cloneUnselected') },\n {\n // Body-drag → move, BUT defer when the pointerdown hit a path\n // anchor, control, or segment affordance. Those lie on the curve so\n // the body classifier still reports 'selected-body'; without this\n // opt-out, move's binding beats editAnchors's on every anchor drag.\n //\n // `isPathEditPart` covers exactly what `editAnchorsAction`,\n // `bendSegmentAction`, and `poiseHandlesAction` match on. That is load-bearing: they must agree\n // on what counts as an anchor or segment hit or move steals the\n // drag — which is exactly the bug this opt-out exists to prevent.\n spec: {\n kind: 'drag' as const,\n target: {\n kindOf: hitPredicate((afford, body) =>\n body === 'selected-body' && !isPathEditPart(afford)),\n },\n mods: SNAP_ROLE_MODS,\n },\n actionId: 'move',\n opts: { ...moveOpts, id: 'selection.move.body' },\n },\n // Body-drag on a NOT-yet-selected node → also move. The select tool's\n // pointerDown classifier selects the hit node before the drag fires (same\n // contract clone relies on), so by the time moveAction.start() runs the\n // node is in `selection.get()`. Without this binding an unselected-body\n // drag falls through to whatever ambient drag binding comes next — once\n // the `rotate` catch-all, which made the first drag rotate and later ones\n // move. Unselected nodes never carry anchor affordances (those gate on\n // selection), so the plain string-form target is sufficient here.\n {\n spec: { kind: 'drag' as const, target: 'unselected-body' as const, mods: SNAP_ROLE_MODS },\n actionId: 'move',\n opts: { ...moveOpts, id: 'selection.move.unselectedBody' },\n },\n ];\n}\n\n/** Options for {@link createSelectionRotateContribution}. */\nexport interface SelectionRotateOptions<TPose = unknown> {\n /** Rotate-action options: `behaviors` become the rotate binding's\n * `opts.behaviors`, everything else its `opts.params`. */\n rotate?: RotateOptions<TPose>;\n}\n\n/** Options for {@link createSelectionTransformContribution}. Resize takes its\n * options through the `resizePolicy` dep (`useResizePolicyDepSource`), not here. */\nexport type SelectionTransformOptions<TPose = unknown> = SelectionRotateOptions<TPose>;\n\n/** Drag a resize handle to resize the selection. Options come through the\n * `resizePolicy` dep (`useResizePolicyDepSource`). */\nexport function selectionResizeBindings(): GestureBinding[] {\n return [{ spec: { kind: 'drag' as const, target: { kindOf: isResizeHandle }, mods: SNAP_ROLE_MODS }, actionId: 'resize', opts: { id: 'selection.resize.handle' } }];\n}\n\n/** Drag the rotation handle to rotate the selection. */\nexport function selectionRotateBindings<TPose>(\n options: SelectionRotateOptions<TPose> = {},\n): GestureBinding[] {\n const rotate = options.rotate ?? {};\n const params: RotateParams = runLifecycleParams({ ...rotate, label: rotate.rotateLabel });\n if (rotate.pivot) params.pivot = rotate.pivot;\n const opts: BindingOptions<RotateParams> = {\n id: 'selection.rotate.handle',\n ...(Object.keys(params).length > 0 ? { params } : {}),\n ...(rotate.behaviors?.length ? { behaviors: rotate.behaviors as BindingOptions['behaviors'] } : {}),\n };\n return [{\n spec: { kind: 'drag' as const, target: { kindOf: isRotateHandle }, mods: SNAP_ROLE_MODS },\n actionId: 'rotate',\n opts,\n }];\n}\n\n/** Drag a resize handle to resize the selection, the rotation handle to rotate it. */\nexport function selectionTransformBindings<TPose>(\n options: SelectionTransformOptions<TPose> = {},\n): GestureBinding[] {\n return [...selectionResizeBindings(), ...selectionRotateBindings(options)];\n}\n\n/** An always-live entry carrying {@link selectionMoveBindings}. Add it to a\n * canvas's ambient list; `<SceneCanvas features={[presets.move]}>` does. */\nexport function createSelectionMoveContribution<TPose>(\n options: SelectionMoveOptions<TPose> = {},\n): Contribution {\n return {\n id: SELECTION_MOVE_ID,\n eligibility: { always: true },\n bindings: selectionMoveBindings(options),\n };\n}\n\n/** An always-live entry carrying {@link selectionTransformBindings}: resize\n * and rotate in one entry, what `<SceneCanvas features={[presets.transform]}>`\n * turns on. */\nexport function createSelectionTransformContribution<TPose>(\n options: SelectionTransformOptions<TPose> = {},\n): Contribution {\n return {\n id: SELECTION_TRANSFORM_ID,\n eligibility: { always: true },\n bindings: selectionTransformBindings(options),\n };\n}\n\n/** An always-live entry carrying {@link selectionResizeBindings}. Add it to a\n * canvas's ambient list; `<SceneCanvas features={[presets.resize]}>` does. */\nexport function createSelectionResizeContribution(): Contribution {\n return {\n id: SELECTION_RESIZE_ID,\n eligibility: { always: true },\n bindings: selectionResizeBindings(),\n };\n}\n\n/** An always-live entry carrying {@link selectionRotateBindings}. Add it to a\n * canvas's ambient list; `<SceneCanvas features={[presets.rotate]}>` does. */\nexport function createSelectionRotateContribution<TPose>(\n options: SelectionRotateOptions<TPose> = {},\n): Contribution {\n return {\n id: SELECTION_ROTATE_ID,\n eligibility: { always: true },\n bindings: selectionRotateBindings(options),\n };\n}\n\n/** Id of the entry {@link createAreaSelectContribution} builds. */\nexport const AREA_SELECT_ID = 'selection.areaSelect';\n\n/** A press on empty canvas: no hit, and not on chrome over it — the rotation\n * handle and the outer half of a resize handle sit off the body. */\nexport const isEmptyOffChrome = hitPredicate((hit, body) => hit == null && body === 'empty');\n\n/** A press on a node, off chrome. With no `classifyTarget` wired there is no\n * body class to read, and every press off chrome passes. */\nexport const isBodyOffChrome = hitPredicate((hit, body) => hit == null && body !== 'empty');\n\n/** An always-live entry that marquee-selects on a drag across empty canvas,\n * under any tool that does not claim the drag itself. No preset installs it:\n * the select tool already marquees, and a canvas that wants it under every\n * tool adds this to its ambient list. */\nexport function createAreaSelectContribution(): Contribution {\n return {\n id: AREA_SELECT_ID,\n eligibility: { always: true },\n bindings: [{\n spec: { kind: 'drag', target: { kindOf: isEmptyOffChrome }, mods: { shift: 'optional' } },\n actionId: 'areaSelect',\n opts: { id: 'selection.areaSelect.drag' },\n }],\n };\n}\n"],"mappings":";;;;;;;AA2BA,IAAa,oBAAoB;;AAEjC,IAAa,yBAAyB;;AAEtC,IAAa,sBAAsB;;AAEnC,IAAa,sBAAsB;;AAGnC,SAAgB,sBACd,UAAuC,CAAC,GACtB;CAIlB,MAAM,kBAA8C;EAClD,MAAM,OAAO,QAAQ,QAAQ,CAAC;EAC9B,MAAM,SAAqB,mBAAmB,IAAI;EAClD,IAAI,QAAQ,kBAAkB,QAAQ,mBAAmB,OAAO,OAAO,iBAAiB,QAAQ;EAChG,IAAI,KAAK,WAAW,OAAO,YAAY,KAAK;EAC5C,OAAO;GACL,GAAI,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;GACnD,GAAI,KAAK,oBAAoB,SAAY,EAAE,iBAAiB,KAAK,gBAAgB,IAAI,CAAC;GACtF,GAAI,KAAK,WAAW,SAAS,EAAE,WAAW,KAAK,UAAyC,IAAI,CAAC;EAC/F;CACF,EAAA,CAAG;CACH,MAAM,kBAAkB,QAAQ,MAAM,aAAa,CAAC,EAAA,CAAG,SAAS,MAAO,EAAE,QAAQ,CAAC,EAAE,KAAK,IAAI,CAAC,CAAE;CAGhG,MAAM,aAAa,QAAgD;EACjE;EACA,GAAI,QAAQ,MAAM,oBAAoB,SAAY,EAAE,iBAAiB,QAAQ,KAAK,gBAAgB,IAAI,CAAC;EACvG,GAAI,eAAe,SAAS,EAAE,WAAW,eAA8C,IAAI,CAAC;CAC9F;CAEA,OAAO;EAQL;GAAE,MAAM;IAAE,MAAM;IAAiB,QAAQ;IAA0B,MAAM;KAAE,GAAG;KAAgB,KAAK;IAAK;GAAE;GAAG,UAAU;GAAS,MAAM,UAAU,sBAAsB;EAAE;EACxK;GAAE,MAAM;IAAE,MAAM;IAAiB,QAAQ;IAA4B,MAAM;KAAE,GAAG;KAAgB,KAAK;IAAK;GAAE;GAAG,UAAU;GAAS,MAAM,UAAU,gCAAgC;EAAE;EACpL;GAUE,MAAM;IACJ,MAAM;IACN,QAAQ,EACN,QAAQ,cAAc,QAAQ,SAC5B,SAAS,mBAAmB,CAAC,eAAe,MAAM,CAAC,EACvD;IACA,MAAM;GACR;GACA,UAAU;GACV,MAAM;IAAE,GAAG;IAAU,IAAI;GAAsB;EACjD;EASA;GACE,MAAM;IAAE,MAAM;IAAiB,QAAQ;IAA4B,MAAM;GAAe;GACxF,UAAU;GACV,MAAM;IAAE,GAAG;IAAU,IAAI;GAAgC;EAC3D;CACF;AACF;;;AAeA,SAAgB,0BAA4C;CAC1D,OAAO,CAAC;EAAE,MAAM;GAAE,MAAM;GAAiB,QAAQ,EAAE,QAAQ,eAAe;GAAG,MAAM;EAAe;EAAG,UAAU;EAAU,MAAM,EAAE,IAAI,0BAA0B;CAAE,CAAC;AACpK;;AAGA,SAAgB,wBACd,UAAyC,CAAC,GACxB;CAClB,MAAM,SAAS,QAAQ,UAAU,CAAC;CAClC,MAAM,SAAuB,mBAAmB;EAAE,GAAG;EAAQ,OAAO,OAAO;CAAY,CAAC;CACxF,IAAI,OAAO,OAAO,OAAO,QAAQ,OAAO;CACxC,MAAM,OAAqC;EACzC,IAAI;EACJ,GAAI,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,IAAI,CAAC;EACnD,GAAI,OAAO,WAAW,SAAS,EAAE,WAAW,OAAO,UAAyC,IAAI,CAAC;CACnG;CACA,OAAO,CAAC;EACN,MAAM;GAAE,MAAM;GAAiB,QAAQ,EAAE,QAAQ,eAAe;GAAG,MAAM;EAAe;EACxF,UAAU;EACV;CACF,CAAC;AACH;;AAGA,SAAgB,2BACd,UAA4C,CAAC,GAC3B;CAClB,OAAO,CAAC,GAAG,wBAAwB,GAAG,GAAG,wBAAwB,OAAO,CAAC;AAC3E;;;AAIA,SAAgB,gCACd,UAAuC,CAAC,GAC1B;CACd,OAAO;EACL,IAAI;EACJ,aAAa,EAAE,QAAQ,KAAK;EAC5B,UAAU,sBAAsB,OAAO;CACzC;AACF;;;;AAKA,SAAgB,qCACd,UAA4C,CAAC,GAC/B;CACd,OAAO;EACL,IAAI;EACJ,aAAa,EAAE,QAAQ,KAAK;EAC5B,UAAU,2BAA2B,OAAO;CAC9C;AACF;;;AAIA,SAAgB,oCAAkD;CAChE,OAAO;EACL,IAAI;EACJ,aAAa,EAAE,QAAQ,KAAK;EAC5B,UAAU,wBAAwB;CACpC;AACF;;;AAIA,SAAgB,kCACd,UAAyC,CAAC,GAC5B;CACd,OAAO;EACL,IAAI;EACJ,aAAa,EAAE,QAAQ,KAAK;EAC5B,UAAU,wBAAwB,OAAO;CAC3C;AACF;;AAGA,IAAa,iBAAiB;;;AAI9B,IAAa,mBAAmB,cAAc,KAAK,SAAS,OAAO,QAAQ,SAAS,OAAO;;;AAI3F,IAAa,kBAAkB,cAAc,KAAK,SAAS,OAAO,QAAQ,SAAS,OAAO;;;;;AAM1F,SAAgB,+BAA6C;CAC3D,OAAO;EACL,IAAI;EACJ,aAAa,EAAE,QAAQ,KAAK;EAC5B,UAAU,CAAC;GACT,MAAM;IAAE,MAAM;IAAQ,QAAQ,EAAE,QAAQ,iBAAiB;IAAG,MAAM,EAAE,OAAO,WAAW;GAAE;GACxF,UAAU;GACV,MAAM,EAAE,IAAI,4BAA4B;EAC1C,CAAC;CACH;AACF"}
@@ -0,0 +1,145 @@
1
+ import { createSelectPickAction } from "./selectPick.js";
2
+ import { createCollapseDeferredAction } from "./collapseDeferred.js";
3
+ import { GROUP_LEAVE_PRESS_BINDING } from "./groupEntry.js";
4
+ import { createSelectDeepAction } from "./selectDeep.js";
5
+ import { isBodyOffChrome, isEmptyOffChrome } from "./selectionContributions.js";
6
+ import { defineTool, rangeAmong, topmostOf } from "@weasel-js/core";
7
+ import { useMemo } from "react";
8
+ import { useLatest } from "@weasel-js/react";
9
+ import { ANY_MODS } from "@weasel-js/gestures";
10
+
11
+ // src/tools/select/usePickerSelectTool.ts
12
+ /** The routed view as a trailing argument, or none: a pick no view was routed for is asked as before. */
13
+ function routed(viewId) {
14
+ return viewId === void 0 ? [] : [viewId];
15
+ }
16
+ var SELECT_TOOL_BINDINGS = [
17
+ {
18
+ spec: {
19
+ kind: "pointerDown",
20
+ target: { kindOf: isBodyOffChrome },
21
+ mods: {
22
+ mod: true,
23
+ alt: true,
24
+ shift: "optional"
25
+ }
26
+ },
27
+ actionId: "select.deep",
28
+ opts: { id: "select.deep" }
29
+ },
30
+ {
31
+ spec: {
32
+ kind: "pointerDown",
33
+ target: { kindOf: isBodyOffChrome },
34
+ mods: ANY_MODS
35
+ },
36
+ actionId: "select.pick",
37
+ opts: { id: "select.pick" }
38
+ },
39
+ {
40
+ spec: {
41
+ kind: "click",
42
+ target: { kindOf: isBodyOffChrome },
43
+ mods: ANY_MODS
44
+ },
45
+ actionId: "select.collapseDeferred",
46
+ opts: { id: "select.collapseDeferred" }
47
+ },
48
+ GROUP_LEAVE_PRESS_BINDING,
49
+ {
50
+ spec: {
51
+ kind: "drag",
52
+ target: { kindOf: isEmptyOffChrome },
53
+ mods: { shift: "optional" }
54
+ },
55
+ actionId: "areaSelect",
56
+ opts: { id: "select.marquee" }
57
+ },
58
+ {
59
+ spec: {
60
+ kind: "click",
61
+ target: { kindOf: isEmptyOffChrome },
62
+ mods: {}
63
+ },
64
+ actionId: "clearSelection",
65
+ opts: { id: "select.clearOnClick" }
66
+ }
67
+ ];
68
+ /** The select tool over a picker the host supplies (`pickEvery`), with no
69
+ * 2D default: what a host that is not a 2D canvas builds on. `useSelectTool`
70
+ * is this with the kit's adapter walk as the default picker.
71
+ *
72
+ * Active-slot Tool:
73
+ * - `select.pick` classifies the press (pointerDown) — it runs the tool's own
74
+ * pickBest/pickEvery so click semantics (selection replace, extend,
75
+ * deferred collapse) live in one place.
76
+ * - an empty drag marquees (`areaSelect`) and a click on empty clears the
77
+ * selection (`clearSelection`); the marquee renders via the dispatcher
78
+ * overlay layer, driven by areaSelectAction's `overlay()`.
79
+ * - moving and transforming the selection are not the tool's: they are the
80
+ * ambient bindings in `selectionContributions.ts`.
81
+ */
82
+ function createPickerSelectTool(adapter, options) {
83
+ const pressRef = { current: { deferred: null } };
84
+ const pickHit = (world, alt, sel, viewId) => {
85
+ const opts = options();
86
+ if (opts.pickBest) return opts.pickBest(world, alt, sel, ...routed(viewId));
87
+ const ids = opts.pickEvery(world, ...routed(viewId));
88
+ if (ids.length === 0) return null;
89
+ return topmostOf(ids, adapter()) ?? ids[0];
90
+ };
91
+ const extendLocked = () => options().extendClickLocked?.() === true;
92
+ const settled = () => {
93
+ pressRef.current = { deferred: null };
94
+ };
95
+ const rangeIn = (level) => {
96
+ const between = options().between;
97
+ if (!between) return void 0;
98
+ return rangeAmong(between, adapter(), level);
99
+ };
100
+ const deepAction = createSelectDeepAction({
101
+ pickHit,
102
+ extendLocked,
103
+ settled,
104
+ rangeAt: (hit) => rangeIn(adapter().getParent(hit))
105
+ });
106
+ const pickAction = createSelectPickAction({
107
+ pickHit,
108
+ extendLocked,
109
+ rangeIn,
110
+ tree: () => adapter(),
111
+ pressed: (deferred) => {
112
+ pressRef.current = { deferred };
113
+ }
114
+ });
115
+ const collapseDeferredAction = createCollapseDeferredAction(pressRef);
116
+ return {
117
+ ...defineTool({
118
+ id: "select",
119
+ keybinding: { key: "V" },
120
+ capabilities: ["creates-selection"],
121
+ hookName: "useSelectTool",
122
+ cursor: "default",
123
+ presentation: {
124
+ label: "Select",
125
+ icon: /* @icon */ "editing:select",
126
+ group: "select"
127
+ },
128
+ actions: [
129
+ pickAction,
130
+ deepAction,
131
+ collapseDeferredAction
132
+ ]
133
+ }),
134
+ bindings: SELECT_TOOL_BINDINGS
135
+ };
136
+ }
137
+ /** {@link createPickerSelectTool} for the life of the calling component, reading `adapter` and `options` live. */
138
+ function usePickerSelectTool(adapter, options) {
139
+ const liveAdapter = useLatest(adapter);
140
+ const liveOptions = useLatest(options);
141
+ return useMemo(() => createPickerSelectTool(() => liveAdapter.current, () => liveOptions.current), [liveAdapter, liveOptions]);
142
+ }
143
+
144
+ export { createPickerSelectTool, usePickerSelectTool };
145
+ //# sourceMappingURL=usePickerSelectTool.js.map