@pairdraw/vue 0.17.0 → 0.19.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/dist/canvas/CanvasRoot.vue.js +4 -1
  2. package/dist/canvas/CanvasRoot.vue.js.map +1 -1
  3. package/dist/canvas/drop/use.d.ts.map +1 -1
  4. package/dist/canvas/drop/use.js +5 -3
  5. package/dist/canvas/drop/use.js.map +1 -1
  6. package/dist/canvas/guides/input.js +2 -1
  7. package/dist/canvas/guides/input.js.map +1 -1
  8. package/dist/canvas/pen/input.js +20 -6
  9. package/dist/canvas/pen/input.js.map +1 -1
  10. package/dist/canvas/surface/gl-surface.js +82 -4
  11. package/dist/canvas/surface/gl-surface.js.map +1 -1
  12. package/dist/canvas/surface/kit-loader.js +22 -14
  13. package/dist/canvas/surface/kit-loader.js.map +1 -1
  14. package/dist/canvas/surface/lifecycle.js +41 -3
  15. package/dist/canvas/surface/lifecycle.js.map +1 -1
  16. package/dist/canvas/surface/resize-observer.js +11 -4
  17. package/dist/canvas/surface/resize-observer.js.map +1 -1
  18. package/dist/canvas/surface/types.d.ts +16 -0
  19. package/dist/canvas/surface/types.d.ts.map +1 -1
  20. package/dist/canvas/surface/use.d.ts +1 -0
  21. package/dist/canvas/surface/use.js +3 -1
  22. package/dist/canvas/surface/use.js.map +1 -1
  23. package/dist/canvas/text-edit/editing.js +11 -8
  24. package/dist/canvas/text-edit/editing.js.map +1 -1
  25. package/dist/canvas/text-edit/keyboard.js +12 -0
  26. package/dist/canvas/text-edit/keyboard.js.map +1 -1
  27. package/dist/canvas/useCanvasInput.d.ts +240 -0
  28. package/dist/controls/appearance/use.d.ts +1 -1
  29. package/dist/controls/layout/helpers.d.ts.map +1 -1
  30. package/dist/controls/layout/helpers.js +36 -7
  31. package/dist/controls/layout/helpers.js.map +1 -1
  32. package/dist/controls/layout/use.d.ts +1 -0
  33. package/dist/controls/layout/use.d.ts.map +1 -1
  34. package/dist/controls/layout/use.js +3 -0
  35. package/dist/controls/layout/use.js.map +1 -1
  36. package/dist/controls/node-preview/use.js +21 -1
  37. package/dist/controls/node-preview/use.js.map +1 -1
  38. package/dist/controls/position/use.d.ts +2 -1
  39. package/dist/controls/position/use.d.ts.map +1 -1
  40. package/dist/controls/position/use.js +13 -5
  41. package/dist/controls/position/use.js.map +1 -1
  42. package/dist/controls/property-list/use.d.ts.map +1 -1
  43. package/dist/controls/property-list/use.js +27 -5
  44. package/dist/controls/property-list/use.js.map +1 -1
  45. package/dist/controls/selection-layout/use.d.ts.map +1 -1
  46. package/dist/controls/selection-layout/use.js +3 -2
  47. package/dist/controls/selection-layout/use.js.map +1 -1
  48. package/dist/controls/slots/authoring.d.ts.map +1 -1
  49. package/dist/controls/slots/authoring.js +2 -1
  50. package/dist/controls/slots/authoring.js.map +1 -1
  51. package/dist/controls/typography/actions.js +18 -10
  52. package/dist/controls/typography/actions.js.map +1 -1
  53. package/dist/controls/typography/axes.d.ts.map +1 -1
  54. package/dist/controls/typography/axes.js +62 -19
  55. package/dist/controls/typography/axes.js.map +1 -1
  56. package/dist/editor/commands/registry.d.ts +1 -0
  57. package/dist/editor/commands/registry.d.ts.map +1 -1
  58. package/dist/editor/commands/registry.js +1 -0
  59. package/dist/editor/commands/registry.js.map +1 -1
  60. package/dist/editor/commands/selection.js +12 -3
  61. package/dist/editor/commands/selection.js.map +1 -1
  62. package/dist/editor/commands/types.d.ts +1 -1
  63. package/dist/editor/commands/types.d.ts.map +1 -1
  64. package/dist/editor/menu-model/canvas.js +5 -1
  65. package/dist/editor/menu-model/canvas.js.map +1 -1
  66. package/dist/editor/selection-capabilities/use.d.ts +1 -0
  67. package/dist/editor/selection-capabilities/use.js +4 -0
  68. package/dist/editor/selection-capabilities/use.js.map +1 -1
  69. package/dist/editor/selection-state/nodes.js +2 -2
  70. package/dist/editor/selection-state/nodes.js.map +1 -1
  71. package/dist/i18n/locale.d.ts.map +1 -1
  72. package/dist/i18n/locale.js +16 -6
  73. package/dist/i18n/locale.js.map +1 -1
  74. package/dist/i18n/locales/de/ai.json.js +9 -0
  75. package/dist/i18n/locales/de/automation.json.js +2 -0
  76. package/dist/i18n/locales/de/cloud/portal.json.js +1 -1
  77. package/dist/i18n/locales/de/commands.json.js +1 -0
  78. package/dist/i18n/locales/de/comments.json.js +1 -0
  79. package/dist/i18n/locales/de/diagnostics.json.js +1 -0
  80. package/dist/i18n/locales/de/editor.json.js +2 -2
  81. package/dist/i18n/locales/de/menu.json.js +1 -1
  82. package/dist/i18n/locales/de/variables/panel.json.js +2 -0
  83. package/dist/i18n/locales/es/ai.json.js +9 -0
  84. package/dist/i18n/locales/es/automation.json.js +2 -0
  85. package/dist/i18n/locales/es/cloud/portal.json.js +1 -1
  86. package/dist/i18n/locales/es/commands.json.js +1 -0
  87. package/dist/i18n/locales/es/comments.json.js +1 -0
  88. package/dist/i18n/locales/es/diagnostics.json.js +1 -0
  89. package/dist/i18n/locales/es/editor.json.js +2 -2
  90. package/dist/i18n/locales/es/menu.json.js +1 -1
  91. package/dist/i18n/locales/es/variables/panel.json.js +2 -0
  92. package/dist/i18n/locales/fr/ai.json.js +9 -0
  93. package/dist/i18n/locales/fr/automation.json.js +2 -0
  94. package/dist/i18n/locales/fr/cloud/portal.json.js +1 -1
  95. package/dist/i18n/locales/fr/commands.json.js +1 -0
  96. package/dist/i18n/locales/fr/comments.json.js +1 -0
  97. package/dist/i18n/locales/fr/diagnostics.json.js +1 -0
  98. package/dist/i18n/locales/fr/editor.json.js +2 -2
  99. package/dist/i18n/locales/fr/menu.json.js +1 -1
  100. package/dist/i18n/locales/fr/variables/panel.json.js +2 -0
  101. package/dist/i18n/locales/it/ai.json.js +9 -0
  102. package/dist/i18n/locales/it/automation.json.js +2 -0
  103. package/dist/i18n/locales/it/cloud/portal.json.js +1 -1
  104. package/dist/i18n/locales/it/commands.json.js +1 -0
  105. package/dist/i18n/locales/it/comments.json.js +1 -0
  106. package/dist/i18n/locales/it/diagnostics.json.js +1 -0
  107. package/dist/i18n/locales/it/editor.json.js +2 -2
  108. package/dist/i18n/locales/it/menu.json.js +1 -1
  109. package/dist/i18n/locales/it/variables/panel.json.js +2 -0
  110. package/dist/i18n/locales/ja/ai.json.js +9 -0
  111. package/dist/i18n/locales/ja/automation.json.js +2 -0
  112. package/dist/i18n/locales/ja/cloud/portal.json.js +1 -1
  113. package/dist/i18n/locales/ja/commands.json.js +1 -0
  114. package/dist/i18n/locales/ja/comments.json.js +1 -0
  115. package/dist/i18n/locales/ja/diagnostics.json.js +1 -0
  116. package/dist/i18n/locales/ja/editor.json.js +2 -2
  117. package/dist/i18n/locales/ja/menu.json.js +1 -1
  118. package/dist/i18n/locales/ja/variables/panel.json.js +2 -0
  119. package/dist/i18n/locales/pl/ai.json.js +9 -0
  120. package/dist/i18n/locales/pl/automation.json.js +2 -0
  121. package/dist/i18n/locales/pl/cloud/portal.json.js +1 -1
  122. package/dist/i18n/locales/pl/commands.json.js +1 -0
  123. package/dist/i18n/locales/pl/comments.json.js +1 -0
  124. package/dist/i18n/locales/pl/diagnostics.json.js +1 -0
  125. package/dist/i18n/locales/pl/editor.json.js +2 -2
  126. package/dist/i18n/locales/pl/menu.json.js +1 -1
  127. package/dist/i18n/locales/pl/variables/panel.json.js +2 -0
  128. package/dist/i18n/locales/ru/ai.json.js +9 -0
  129. package/dist/i18n/locales/ru/automation.json.js +2 -0
  130. package/dist/i18n/locales/ru/cloud/portal.json.js +1 -1
  131. package/dist/i18n/locales/ru/commands.json.js +1 -0
  132. package/dist/i18n/locales/ru/comments.json.js +1 -0
  133. package/dist/i18n/locales/ru/diagnostics.json.js +1 -0
  134. package/dist/i18n/locales/ru/editor.json.js +2 -2
  135. package/dist/i18n/locales/ru/menu.json.js +1 -1
  136. package/dist/i18n/locales/ru/variables/panel.json.js +2 -0
  137. package/dist/i18n/locales/zh-cn/ai.json.js +9 -0
  138. package/dist/i18n/locales/zh-cn/automation.json.js +2 -0
  139. package/dist/i18n/locales/zh-cn/cloud/portal.json.js +1 -1
  140. package/dist/i18n/locales/zh-cn/commands.json.js +1 -0
  141. package/dist/i18n/locales/zh-cn/comments.json.js +1 -0
  142. package/dist/i18n/locales/zh-cn/diagnostics.json.js +1 -0
  143. package/dist/i18n/locales/zh-cn/editor.json.js +2 -2
  144. package/dist/i18n/locales/zh-cn/menu.json.js +1 -1
  145. package/dist/i18n/locales/zh-cn/variables/panel.json.js +2 -0
  146. package/dist/i18n/messages/ai.d.ts +20 -0
  147. package/dist/i18n/messages/ai.d.ts.map +1 -1
  148. package/dist/i18n/messages/ai.js +10 -0
  149. package/dist/i18n/messages/ai.js.map +1 -1
  150. package/dist/i18n/messages/automation.d.ts +2 -0
  151. package/dist/i18n/messages/automation.d.ts.map +1 -1
  152. package/dist/i18n/messages/automation.js +2 -0
  153. package/dist/i18n/messages/automation.js.map +1 -1
  154. package/dist/i18n/messages/cloud/portal.d.ts +1 -1
  155. package/dist/i18n/messages/cloud/portal.js +1 -1
  156. package/dist/i18n/messages/cloud/portal.js.map +1 -1
  157. package/dist/i18n/messages/commands.d.ts +1 -0
  158. package/dist/i18n/messages/commands.d.ts.map +1 -1
  159. package/dist/i18n/messages/commands.js +1 -0
  160. package/dist/i18n/messages/commands.js.map +1 -1
  161. package/dist/i18n/messages/comments.d.ts +1 -0
  162. package/dist/i18n/messages/comments.d.ts.map +1 -1
  163. package/dist/i18n/messages/comments.js +1 -0
  164. package/dist/i18n/messages/comments.js.map +1 -1
  165. package/dist/i18n/messages/diagnostics.d.ts +1 -0
  166. package/dist/i18n/messages/diagnostics.d.ts.map +1 -1
  167. package/dist/i18n/messages/diagnostics.js +1 -0
  168. package/dist/i18n/messages/diagnostics.js.map +1 -1
  169. package/dist/i18n/messages/editor.d.ts +1 -1
  170. package/dist/i18n/messages/editor.js +1 -1
  171. package/dist/i18n/messages/editor.js.map +1 -1
  172. package/dist/i18n/messages/menu.d.ts +1 -1
  173. package/dist/i18n/messages/menu.js +1 -1
  174. package/dist/i18n/messages/menu.js.map +1 -1
  175. package/dist/i18n/messages/panels.d.ts +1 -1
  176. package/dist/i18n/messages/panels.js +1 -1
  177. package/dist/i18n/messages/panels.js.map +1 -1
  178. package/dist/i18n/messages/variables/panel.d.ts +2 -0
  179. package/dist/i18n/messages/variables/panel.d.ts.map +1 -1
  180. package/dist/i18n/messages/variables/panel.js +2 -0
  181. package/dist/i18n/messages/variables/panel.js.map +1 -1
  182. package/dist/i18n/messages.d.ts +30 -4
  183. package/dist/i18n/useI18n.d.ts +116 -14
  184. package/dist/i18n/useI18n.d.ts.map +1 -1
  185. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts +12 -2
  186. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.d.ts.map +1 -1
  187. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js +39 -10
  188. package/dist/primitives/ColorPicker/ColorPickerRoot.vue.js.map +1 -1
  189. package/dist/primitives/ColorPicker/gesture.d.ts +40 -0
  190. package/dist/primitives/ColorPicker/gesture.d.ts.map +1 -0
  191. package/dist/primitives/ColorPicker/gesture.js +120 -0
  192. package/dist/primitives/ColorPicker/gesture.js.map +1 -0
  193. package/dist/primitives/ColorPicker/index.d.ts +2 -1
  194. package/dist/primitives/ColorPicker/index.js +2 -1
  195. package/dist/primitives/Fill/FillSwatch.vue.d.ts.map +1 -1
  196. package/dist/primitives/Fill/FillSwatch.vue.js +6 -1
  197. package/dist/primitives/Fill/FillSwatch.vue.js.map +1 -1
  198. package/dist/primitives/Fill/types.d.ts +5 -0
  199. package/dist/primitives/Fill/types.d.ts.map +1 -1
  200. package/dist/primitives/Fill/useFill.d.ts.map +1 -1
  201. package/dist/primitives/Fill/useFill.js +15 -7
  202. package/dist/primitives/Fill/useFill.js.map +1 -1
  203. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts +1 -0
  204. package/dist/primitives/FontPicker/FontPickerRoot.vue.d.ts.map +1 -1
  205. package/dist/primitives/FontPicker/FontPickerRoot.vue.js +7 -2
  206. package/dist/primitives/FontPicker/FontPickerRoot.vue.js.map +1 -1
  207. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts +2 -0
  208. package/dist/primitives/LayerTree/LayerTreeRoot.vue.d.ts.map +1 -1
  209. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js +14 -3
  210. package/dist/primitives/LayerTree/LayerTreeRoot.vue.js.map +1 -1
  211. package/dist/primitives/LayerTree/model.js +1 -1
  212. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.d.ts.map +1 -1
  213. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js +1 -0
  214. package/dist/primitives/LayoutControls/LayoutControlsRoot.vue.js.map +1 -1
  215. package/dist/primitives/NumberField/NumberFieldRoot.vue.d.ts +2 -2
  216. package/dist/primitives/NumberField/NumberFieldRoot.vue.d.ts.map +1 -1
  217. package/dist/primitives/NumberField/NumberFieldRoot.vue.js +3 -2
  218. package/dist/primitives/NumberField/NumberFieldRoot.vue.js.map +1 -1
  219. package/dist/primitives/NumberField/types.d.ts +5 -0
  220. package/dist/primitives/NumberField/types.d.ts.map +1 -1
  221. package/dist/primitives/PageList/PageListRoot.vue.d.ts +3 -3
  222. package/dist/primitives/PageList/PageListRoot.vue.d.ts.map +1 -1
  223. package/dist/primitives/PageList/PageListRoot.vue.js +3 -2
  224. package/dist/primitives/PageList/PageListRoot.vue.js.map +1 -1
  225. package/dist/primitives/PageList/usePageList.d.ts +1 -1
  226. package/dist/primitives/PageList/usePageList.d.ts.map +1 -1
  227. package/dist/primitives/PositionControls/PositionControlsRoot.vue.d.ts +1 -0
  228. package/dist/primitives/PositionControls/PositionControlsRoot.vue.d.ts.map +1 -1
  229. package/dist/primitives/PositionControls/PositionControlsRoot.vue.js +11 -13
  230. package/dist/primitives/PositionControls/PositionControlsRoot.vue.js.map +1 -1
  231. package/dist/primitives/PropertyList/PropertyListRoot.vue.d.ts.map +1 -1
  232. package/dist/primitives/PropertyList/PropertyListRoot.vue.js +10 -1
  233. package/dist/primitives/PropertyList/PropertyListRoot.vue.js.map +1 -1
  234. package/dist/primitives/PropertyList/index.d.ts +2 -2
  235. package/dist/primitives/PropertyList/types.d.ts +14 -2
  236. package/dist/primitives/PropertyList/types.d.ts.map +1 -1
  237. package/dist/shared/input/drop-target.js +2 -1
  238. package/dist/shared/input/drop-target.js.map +1 -1
  239. package/dist/shared/input/duplicate-drag.js.map +1 -1
  240. package/dist/shared/input/move/drag.js +25 -4
  241. package/dist/shared/input/move/drag.js.map +1 -1
  242. package/dist/shared/input/resize/start.js +2 -1
  243. package/dist/shared/input/resize/start.js.map +1 -1
  244. package/dist/shared/input/select/move.js +8 -3
  245. package/dist/shared/input/select/move.js.map +1 -1
  246. package/dist/shared/input/select.js +22 -12
  247. package/dist/shared/input/select.js.map +1 -1
  248. package/dist/shared/input/types.d.ts +2 -0
  249. package/dist/shared/input/types.d.ts.map +1 -1
  250. package/dist/shared/input/types.js.map +1 -1
  251. package/dist/variables/use.d.ts.map +1 -1
  252. package/dist/variables/use.js +2 -1
  253. package/dist/variables/use.js.map +1 -1
  254. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/layout/use.ts"],"sourcesContent":["import {\n createGridTrackActions,\n createLayoutActions,\n createLayoutSelectionState,\n createPaddingActions,\n createTrackSizingOptions,\n trackLabel\n} from '#vue/controls/layout/helpers'\nimport { useEditor } from '#vue/editor/context'\nimport { useI18n } from '#vue/i18n'\n\n/**\n * Returns layout-related state and actions for the current selection.\n *\n * Use this composable to build auto-layout and grid panels that need sizing,\n * padding, alignment, and track editing behavior.\n */\nexport function useLayout() {\n const editor = useEditor()\n const { panels } = useI18n()\n\n const {\n node,\n layoutDirection,\n gapAuto,\n alignGrid,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable\n } = createLayoutSelectionState(editor, panels)\n\n const {\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding,\n cancelPaddingPreview\n } = createPaddingActions(editor, node)\n\n const layoutActions = createLayoutActions({ editor, node })\n\n const { updateGridTrack, addTrack, removeTrack } = createGridTrackActions(editor, node)\n\n return {\n editor,\n node,\n layoutDirection,\n gapAuto,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable,\n alignGrid,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n trackSizingOptions: createTrackSizingOptions(panels.value),\n cancelPreview: () => {\n cancelPaddingPreview()\n layoutActions.cancelPreview()\n },\n updateProp: layoutActions.updateProp,\n updateSizeLimit: layoutActions.updateSizeLimit,\n setSizeLimitToCurrent: layoutActions.setSizeLimitToCurrent,\n commitSizeLimit: layoutActions.commitSizeLimit,\n addSizeLimit: layoutActions.addSizeLimit,\n removeSizeLimit: layoutActions.removeSizeLimit,\n commitProp: layoutActions.commitProp,\n setAxisSizing: layoutActions.setAxisSizing,\n updateAxisSize: layoutActions.updateAxisSize,\n commitAxisSize: layoutActions.commitAxisSize,\n toggleAspectRatioLock: layoutActions.toggleAspectRatioLock,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n setAlignment: layoutActions.setAlignment,\n setGapAuto: layoutActions.setGapAuto,\n setLayoutDirection: layoutActions.setLayoutDirection,\n updateGridTrack,\n addTrack,\n removeTrack,\n trackLabel,\n toggleIndividualPadding\n }\n}\n"],"mappings":";;;;;;;;;;AAiBA,SAAgB,YAAY;CAC1B,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,WAAW,QAAQ;CAE3B,MAAM,EACJ,MACA,iBACA,SACA,WACA,gBACA,QACA,QACA,aACA,cACA,oBACA,qBACA,mBACA,wBACE,2BAA2B,QAAQ,MAAM;CAE7C,MAAM,EACJ,uBACA,mBACA,qBACA,sBACA,yBACA,oBACA,uBACA,yBACA,yBACE,qBAAqB,QAAQ,IAAI;CAErC,MAAM,gBAAgB,oBAAoB;EAAE;EAAQ;CAAK,CAAC;CAE1D,MAAM,EAAE,iBAAiB,UAAU,gBAAgB,uBAAuB,QAAQ,IAAI;CAEtF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,oBAAoB,yBAAyB,OAAO,KAAK;EACzD,qBAAqB;GACnB,qBAAqB;GACrB,cAAc,cAAc;EAC9B;EACA,YAAY,cAAc;EAC1B,iBAAiB,cAAc;EAC/B,uBAAuB,cAAc;EACrC,iBAAiB,cAAc;EAC/B,cAAc,cAAc;EAC5B,iBAAiB,cAAc;EAC/B,YAAY,cAAc;EAC1B,eAAe,cAAc;EAC7B,gBAAgB,cAAc;EAC9B,gBAAgB,cAAc;EAC9B,uBAAuB,cAAc;EACrC;EACA;EACA;EACA;EACA,cAAc,cAAc;EAC5B,YAAY,cAAc;EAC1B,oBAAoB,cAAc;EAClC;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\nimport {\n createGridTrackActions,\n createLayoutActions,\n createLayoutSelectionState,\n createPaddingActions,\n createTrackSizingOptions,\n trackLabel\n} from '#vue/controls/layout/helpers'\nimport { useEditor } from '#vue/editor/context'\nimport { useI18n } from '#vue/i18n'\n\n/**\n * Returns layout-related state and actions for the current selection.\n *\n * Use this composable to build auto-layout and grid panels that need sizing,\n * padding, alignment, and track editing behavior.\n */\nexport function useLayout() {\n const editor = useEditor()\n const { panels } = useI18n()\n\n const {\n node,\n layoutDirection,\n gapAuto,\n alignGrid,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable\n } = createLayoutSelectionState(editor, panels)\n\n const {\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n toggleIndividualPadding,\n cancelPaddingPreview\n } = createPaddingActions(editor, node)\n\n const layoutActions = createLayoutActions({ editor, node })\n\n const { updateGridTrack, addTrack, removeTrack } = createGridTrackActions(editor, node)\n\n /** Whether Figma lets the selected layer take a size of its own; see `takesOwnSize`. */\n const resizes = computed(() => (node.value ? takesOwnSize(editor.graph, node.value) : false))\n\n return {\n editor,\n node,\n resizes,\n layoutDirection,\n gapAuto,\n isInAutoLayout,\n isGrid,\n isFlex,\n widthSizing,\n heightSizing,\n widthSizingOptions,\n heightSizingOptions,\n aspectRatioLocked,\n aspectRatioLockable,\n alignGrid,\n showIndividualPadding,\n hasUniformPadding,\n hasSymmetricPadding,\n trackSizingOptions: createTrackSizingOptions(panels.value),\n cancelPreview: () => {\n cancelPaddingPreview()\n layoutActions.cancelPreview()\n },\n updateProp: layoutActions.updateProp,\n updateSizeLimit: layoutActions.updateSizeLimit,\n setSizeLimitToCurrent: layoutActions.setSizeLimitToCurrent,\n commitSizeLimit: layoutActions.commitSizeLimit,\n addSizeLimit: layoutActions.addSizeLimit,\n removeSizeLimit: layoutActions.removeSizeLimit,\n commitProp: layoutActions.commitProp,\n setAxisSizing: layoutActions.setAxisSizing,\n updateAxisSize: layoutActions.updateAxisSize,\n commitAxisSize: layoutActions.commitAxisSize,\n toggleAspectRatioLock: layoutActions.toggleAspectRatioLock,\n setHorizontalPadding,\n commitHorizontalPadding,\n setVerticalPadding,\n commitVerticalPadding,\n setAlignment: layoutActions.setAlignment,\n setGapAuto: layoutActions.setGapAuto,\n setLayoutDirection: layoutActions.setLayoutDirection,\n updateGridTrack,\n addTrack,\n removeTrack,\n trackLabel,\n toggleIndividualPadding\n }\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,SAAgB,YAAY;CAC1B,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,WAAW,QAAQ;CAE3B,MAAM,EACJ,MACA,iBACA,SACA,WACA,gBACA,QACA,QACA,aACA,cACA,oBACA,qBACA,mBACA,wBACE,2BAA2B,QAAQ,MAAM;CAE7C,MAAM,EACJ,uBACA,mBACA,qBACA,sBACA,yBACA,oBACA,uBACA,yBACA,yBACE,qBAAqB,QAAQ,IAAI;CAErC,MAAM,gBAAgB,oBAAoB;EAAE;EAAQ;CAAK,CAAC;CAE1D,MAAM,EAAE,iBAAiB,UAAU,gBAAgB,uBAAuB,QAAQ,IAAI;CAKtF,OAAO;EACL;EACA;EACA,SALc,eAAgB,KAAK,QAAQ,aAAa,OAAO,OAAO,KAAK,KAAK,IAAI,KAK9E;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,oBAAoB,yBAAyB,OAAO,KAAK;EACzD,qBAAqB;GACnB,qBAAqB;GACrB,cAAc,cAAc;EAC9B;EACA,YAAY,cAAc;EAC1B,iBAAiB,cAAc;EAC/B,uBAAuB,cAAc;EACrC,iBAAiB,cAAc;EAC/B,cAAc,cAAc;EAC5B,iBAAiB,cAAc;EAC/B,YAAY,cAAc;EAC1B,eAAe,cAAc;EAC7B,gBAAgB,cAAc;EAC9B,gBAAgB,cAAc;EAC9B,uBAAuB,cAAc;EACrC;EACA;EACA;EACA;EACA,cAAc,cAAc;EAC5B,YAAY,cAAc;EAC1B,oBAAoB,cAAc;EAClC;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -19,12 +19,30 @@ function useNodePreview(editor) {
19
19
  throw error;
20
20
  }
21
21
  }
22
+ /** Previews a change for each named node, such as the layers a resize places. */
23
+ function updateNodes(changes, label) {
24
+ if (!changes.size) return;
25
+ if (!preview) {
26
+ targets = [...changes.keys()];
27
+ preview = editor.beginNodePreview(label);
28
+ }
29
+ try {
30
+ for (const [id, patch] of changes) preview.update(id, patch);
31
+ } catch (error) {
32
+ cancel();
33
+ throw error;
34
+ }
35
+ }
22
36
  function takePreview() {
23
37
  const current = preview;
24
38
  preview = void 0;
25
39
  targets = [];
26
40
  return current;
27
41
  }
42
+ /** Whether a preview is running, so a caller can tell an edit's first preview from its later ones. */
43
+ function isActive() {
44
+ return preview !== void 0;
45
+ }
28
46
  function commit() {
29
47
  takePreview()?.commit();
30
48
  }
@@ -35,8 +53,10 @@ function useNodePreview(editor) {
35
53
  if (getCurrentInstance()) onDeactivated(cancel);
36
54
  return {
37
55
  update,
56
+ updateNodes,
38
57
  commit,
39
- cancel
58
+ cancel,
59
+ isActive
40
60
  };
41
61
  }
42
62
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/node-preview/use.ts"],"sourcesContent":["import { tryOnScopeDispose } from '@vueuse/core'\nimport { getCurrentInstance, onDeactivated } from 'vue'\n\nimport type { Editor, NodePreview } from '@pairdraw/core'\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\n/** Keeps an edit's original targets until its terminal event, even after selection changes. */\nexport function useNodePreview(editor: Editor) {\n let preview: NodePreview | undefined\n let targets: readonly string[] = []\n\n /** Previews `changes` on every target, or the changes a function gives for each one. */\n function update(\n ids: readonly string[],\n changes: Partial<SceneNode> | ((id: string) => Partial<SceneNode>),\n label: string\n ) {\n if (!preview) {\n if (!ids.length) return\n targets = [...ids]\n preview = editor.beginNodePreview(label)\n }\n try {\n for (const id of targets) {\n preview.update(id, typeof changes === 'function' ? changes(id) : changes)\n }\n } catch (error) {\n cancel()\n throw error\n }\n }\n\n function takePreview() {\n const current = preview\n preview = undefined\n targets = []\n return current\n }\n\n function commit() {\n takePreview()?.commit()\n }\n\n function cancel() {\n takePreview()?.cancel()\n }\n\n tryOnScopeDispose(cancel)\n if (getCurrentInstance()) onDeactivated(cancel)\n return { update, commit, cancel }\n}\n"],"mappings":";;;;AAOA,SAAgB,eAAe,QAAgB;CAC7C,IAAI;CACJ,IAAI,UAA6B,CAAC;;CAGlC,SAAS,OACP,KACA,SACA,OACA;EACA,IAAI,CAAC,SAAS;GACZ,IAAI,CAAC,IAAI,QAAQ;GACjB,UAAU,CAAC,GAAG,GAAG;GACjB,UAAU,OAAO,iBAAiB,KAAK;EACzC;EACA,IAAI;GACF,KAAK,MAAM,MAAM,SACf,QAAQ,OAAO,IAAI,OAAO,YAAY,aAAa,QAAQ,EAAE,IAAI,OAAO;EAE5E,SAAS,OAAO;GACd,OAAO;GACP,MAAM;EACR;CACF;CAEA,SAAS,cAAc;EACrB,MAAM,UAAU;EAChB,UAAU,KAAA;EACV,UAAU,CAAC;EACX,OAAO;CACT;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,kBAAkB,MAAM;CACxB,IAAI,mBAAmB,GAAG,cAAc,MAAM;CAC9C,OAAO;EAAE;EAAQ;EAAQ;CAAO;AAClC"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/node-preview/use.ts"],"sourcesContent":["import { tryOnScopeDispose } from '@vueuse/core'\nimport { getCurrentInstance, onDeactivated } from 'vue'\n\nimport type { Editor, NodePreview } from '@pairdraw/core'\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\n/** Keeps an edit's original targets until its terminal event, even after selection changes. */\nexport function useNodePreview(editor: Editor) {\n let preview: NodePreview | undefined\n let targets: readonly string[] = []\n\n /** Previews `changes` on every target, or the changes a function gives for each one. */\n function update(\n ids: readonly string[],\n changes: Partial<SceneNode> | ((id: string) => Partial<SceneNode>),\n label: string\n ) {\n if (!preview) {\n if (!ids.length) return\n targets = [...ids]\n preview = editor.beginNodePreview(label)\n }\n try {\n for (const id of targets) {\n preview.update(id, typeof changes === 'function' ? changes(id) : changes)\n }\n } catch (error) {\n cancel()\n throw error\n }\n }\n\n /** Previews a change for each named node, such as the layers a resize places. */\n function updateNodes(changes: ReadonlyMap<string, Partial<SceneNode>>, label: string) {\n if (!changes.size) return\n if (!preview) {\n targets = [...changes.keys()]\n preview = editor.beginNodePreview(label)\n }\n try {\n for (const [id, patch] of changes) preview.update(id, patch)\n } catch (error) {\n cancel()\n throw error\n }\n }\n\n function takePreview() {\n const current = preview\n preview = undefined\n targets = []\n return current\n }\n\n /** Whether a preview is running, so a caller can tell an edit's first preview from its later ones. */\n function isActive() {\n return preview !== undefined\n }\n\n function commit() {\n takePreview()?.commit()\n }\n\n function cancel() {\n takePreview()?.cancel()\n }\n\n tryOnScopeDispose(cancel)\n if (getCurrentInstance()) onDeactivated(cancel)\n return { update, updateNodes, commit, cancel, isActive }\n}\n"],"mappings":";;;;AAOA,SAAgB,eAAe,QAAgB;CAC7C,IAAI;CACJ,IAAI,UAA6B,CAAC;;CAGlC,SAAS,OACP,KACA,SACA,OACA;EACA,IAAI,CAAC,SAAS;GACZ,IAAI,CAAC,IAAI,QAAQ;GACjB,UAAU,CAAC,GAAG,GAAG;GACjB,UAAU,OAAO,iBAAiB,KAAK;EACzC;EACA,IAAI;GACF,KAAK,MAAM,MAAM,SACf,QAAQ,OAAO,IAAI,OAAO,YAAY,aAAa,QAAQ,EAAE,IAAI,OAAO;EAE5E,SAAS,OAAO;GACd,OAAO;GACP,MAAM;EACR;CACF;;CAGA,SAAS,YAAY,SAAkD,OAAe;EACpF,IAAI,CAAC,QAAQ,MAAM;EACnB,IAAI,CAAC,SAAS;GACZ,UAAU,CAAC,GAAG,QAAQ,KAAK,CAAC;GAC5B,UAAU,OAAO,iBAAiB,KAAK;EACzC;EACA,IAAI;GACF,KAAK,MAAM,CAAC,IAAI,UAAU,SAAS,QAAQ,OAAO,IAAI,KAAK;EAC7D,SAAS,OAAO;GACd,OAAO;GACP,MAAM;EACR;CACF;CAEA,SAAS,cAAc;EACrB,MAAM,UAAU;EAChB,UAAU,KAAA;EACV,UAAU,CAAC;EACX,OAAO;CACT;;CAGA,SAAS,WAAW;EAClB,OAAO,YAAY,KAAA;CACrB;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,SAAS,SAAS;EAChB,YAAY,CAAC,EAAE,OAAO;CACxB;CAEA,kBAAkB,MAAM;CACxB,IAAI,mBAAmB,GAAG,cAAc,MAAM;CAC9C,OAAO;EAAE;EAAQ;EAAa;EAAQ;EAAQ;CAAS;AACzD"}
@@ -14,7 +14,7 @@ declare function usePosition(): {
14
14
  active: import("vue").ComputedRef<boolean>;
15
15
  isMulti: import("vue").ComputedRef<boolean>;
16
16
  prop: <K extends keyof SceneNode>(key: K) => import("vue").ComputedRef<MixedValue<SceneNode[K]>>;
17
- panelProp: (key: "x" | "y" | "rotation") => import("vue").ComputedRef<MixedValue<number>>;
17
+ panelProp: (key: "x" | "y" | "rotation" | "width" | "height") => import("vue").ComputedRef<MixedValue<number>>;
18
18
  ids: import("vue").ComputedRef<string[]>;
19
19
  x: import("vue").ComputedRef<number>;
20
20
  y: import("vue").ComputedRef<number>;
@@ -22,6 +22,7 @@ declare function usePosition(): {
22
22
  height: import("vue").ComputedRef<number>;
23
23
  rotation: import("vue").ComputedRef<number>;
24
24
  rotates: import("vue").ComputedRef<boolean>;
25
+ resizes: import("vue").ComputedRef<boolean>;
25
26
  inAutoLayout: import("vue").ComputedRef<boolean>;
26
27
  ignoresAutoLayout: import("vue").ComputedRef<boolean>;
27
28
  toggleIgnoreAutoLayout: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/position/use.ts"],"mappings":";;;;;;;;;iBAqBgB;;;;;;;EAgBU,YAAA,8CAAsB,YAAA;;;;;;;;;;;EAuBrB,aAAA,KAAA,qBAAmB;EAYnB,aAAA,KAAA,qBAAmB,eAAe;EAIlC,aAAA,KAAA;EAwBJ,QAAA,iCAAyB;EAI1B,OAAA;EAIK,SAAA"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/position/use.ts"],"mappings":";;;;;;;;;iBAuBgB;;;;;;;;;;;;;;;;;;;EAmDW,aAAA,KAAA,qBAAmB;EAYnB,aAAA,KAAA,qBAAmB,eAAe;EAIlC,aAAA,KAAA;EAwBJ,QAAA,iCAAyB;EAI1B,OAAA;EAIK,SAAA"}
@@ -4,7 +4,8 @@ import { useNodeProps } from "../node-props/use.js";
4
4
  import { usePropScrub } from "../prop-scrub/use.js";
5
5
  import { computed } from "vue";
6
6
  import { layerRotates } from "@pairdraw/scene-graph/generated";
7
- import { panelPosition, panelPositionChange, panelRotation, panelRotationChange } from "@pairdraw/core/geometry";
7
+ import { takesOwnSize } from "@pairdraw/scene-graph/instances";
8
+ import { panelNumber, panelPosition, panelPositionChange, panelRotation, panelRotationChange } from "@pairdraw/core/geometry";
8
9
  //#region src/controls/position/use.ts
9
10
  /**
10
11
  * Returns position-related state and actions for the current selection.
@@ -18,9 +19,15 @@ function usePosition() {
18
19
  const ids = computed(() => nodes.value.map((n) => n.id));
19
20
  /** Whether the selection turns and flips; a sticky note or connector stays upright. */
20
21
  const rotates = computed(() => nodes.value.every(layerRotates));
22
+ /**
23
+ * Whether every selected layer takes a size of its own: a layer inside an instance shows its
24
+ * component's size, as in Figma, while an instance nested in another may be resized.
25
+ */
26
+ const resizes = computed(() => nodes.value.length > 0 && nodes.value.every((target) => takesOwnSize(editor.graph, target)));
21
27
  function shown(target, key) {
22
- if (key === "rotation") return Math.round(panelRotation(target, editor.graph));
23
- return Math.round(panelPosition(target, editor.graph)[key]);
28
+ if (key === "rotation") return panelNumber(panelRotation(target, editor.graph));
29
+ if (key === "x" || key === "y") return panelNumber(panelPosition(target, editor.graph)[key]);
30
+ return panelNumber(target[key]);
24
31
  }
25
32
  /** The shown value of every selected node, or MIXED when they differ. */
26
33
  function panelProp(key) {
@@ -33,8 +40,8 @@ function usePosition() {
33
40
  }
34
41
  const x = computed(() => node.value ? shown(node.value, "x") : 0);
35
42
  const y = computed(() => node.value ? shown(node.value, "y") : 0);
36
- const width = computed(() => node.value?.width ?? 0);
37
- const height = computed(() => node.value?.height ?? 0);
43
+ const width = computed(() => node.value ? shown(node.value, "width") : 0);
44
+ const height = computed(() => node.value ? shown(node.value, "height") : 0);
38
45
  const rotation = computed(() => node.value ? shown(node.value, "rotation") : 0);
39
46
  const { updateProp: _updateProp, updateEach, commitProp: _commitProp, cancelProp: _cancelProp } = usePropScrub(editor);
40
47
  function updateProp(key, value) {
@@ -83,6 +90,7 @@ function usePosition() {
83
90
  height,
84
91
  rotation,
85
92
  rotates,
93
+ resizes,
86
94
  inAutoLayout,
87
95
  ignoresAutoLayout,
88
96
  toggleIgnoreAutoLayout,
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/position/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport {\n panelPosition,\n panelPositionChange,\n panelRotation,\n panelRotationChange\n} from '@pairdraw/core/geometry'\nimport type { NumericNodeProperty, SceneNode } from '@pairdraw/scene-graph'\nimport { layerRotates } from '@pairdraw/scene-graph/generated'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { usePropScrub } from '#vue/controls/prop-scrub/use'\nimport { useEditor } from '#vue/editor/context'\n\n/**\n * Returns position-related state and actions for the current selection.\n *\n * This composable is designed for property panels that edit x/y, size,\n * rotation, alignment, flipping, and multi-node transforms.\n */\nexport function usePosition() {\n const editor = useEditor()\n\n const { nodes, node, active, isMulti, prop } = useNodeProps()\n const ids = computed(() => nodes.value.map((n) => n.id))\n /** Whether the selection turns and flips; a sticky note or connector stays upright. */\n const rotates = computed(() => nodes.value.every(layerRotates))\n\n // X, Y, and rotation read as Figma's panel shows them: the turned layer's box on the canvas and\n // its counterclockwise angle; see `panelPosition` and `panelRotation`.\n function shown(target: SceneNode, key: 'x' | 'y' | 'rotation'): number {\n if (key === 'rotation') return Math.round(panelRotation(target, editor.graph))\n return Math.round(panelPosition(target, editor.graph)[key])\n }\n\n /** The shown value of every selected node, or MIXED when they differ. */\n function panelProp(key: 'x' | 'y' | 'rotation') {\n return computed<MixedValue<number>>(() => {\n const values = nodes.value.map((target) => shown(target, key))\n if (values.length === 0) return 0\n const first = values[0]\n return values.every((value) => value === first) ? first : MIXED\n })\n }\n\n const x = computed(() => (node.value ? shown(node.value, 'x') : 0))\n const y = computed(() => (node.value ? shown(node.value, 'y') : 0))\n const width = computed(() => node.value?.width ?? 0)\n const height = computed(() => node.value?.height ?? 0)\n const rotation = computed(() => (node.value ? shown(node.value, 'rotation') : 0))\n\n const {\n updateProp: _updateProp,\n updateEach,\n commitProp: _commitProp,\n cancelProp: _cancelProp\n } = usePropScrub(editor)\n\n // Typed X, Y, and rotation become each node's own move or turn, as typing them in Figma does.\n function updateProp(key: NumericNodeProperty, value: number) {\n if (key === 'x' || key === 'y') {\n updateEach(nodes.value, key, (target) =>\n panelPositionChange(target, editor.graph, key, value)\n )\n } else if (key === 'rotation') {\n updateEach(nodes.value, key, (target) => panelRotationChange(target, editor.graph, value))\n } else {\n _updateProp(nodes.value, key, value)\n }\n }\n\n function commitProp(key: NumericNodeProperty, value: number, previous: number) {\n _commitProp(nodes.value, key, value, previous)\n }\n\n function cancelProp(key: NumericNodeProperty) {\n _cancelProp(nodes.value, key)\n }\n\n /** Whether every selected layer sits in an auto layout, where it can ignore that layout. */\n const inAutoLayout = computed(\n () =>\n nodes.value.length > 0 &&\n nodes.value.every((target) => {\n const parent = target.parentId ? editor.graph.getNode(target.parentId) : undefined\n return !!parent && parent.layoutMode !== 'NONE'\n })\n )\n /** On only when every selected layer ignores its auto layout. */\n const ignoresAutoLayout = computed(\n () =>\n inAutoLayout.value && nodes.value.every((target) => target.layoutPositioning === 'ABSOLUTE')\n )\n\n /** Figma's Ignore auto layout toggle: a mixed selection is taken out of its layouts. */\n function toggleIgnoreAutoLayout() {\n editor.setLayoutPositioning(ids.value, ignoresAutoLayout.value ? 'AUTO' : 'ABSOLUTE')\n }\n\n function align(axis: 'horizontal' | 'vertical', pos: 'min' | 'center' | 'max') {\n editor.alignNodes(ids.value, axis, pos)\n }\n\n function flip(axis: 'horizontal' | 'vertical') {\n editor.flipNodes(ids.value, axis)\n }\n\n function rotate(degrees: number) {\n editor.rotateNodes(ids.value, degrees)\n }\n\n return {\n editor,\n nodes,\n node,\n active,\n isMulti,\n prop,\n panelProp,\n ids,\n x,\n y,\n width,\n height,\n rotation,\n rotates,\n inAutoLayout,\n ignoresAutoLayout,\n toggleIgnoreAutoLayout,\n updateProp,\n commitProp,\n cancelProp,\n align,\n flip,\n rotate\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,SAAgB,cAAc;CAC5B,MAAM,SAAS,UAAU;CAEzB,MAAM,EAAE,OAAO,MAAM,QAAQ,SAAS,SAAS,aAAa;CAC5D,MAAM,MAAM,eAAe,MAAM,MAAM,KAAK,MAAM,EAAE,EAAE,CAAC;;CAEvD,MAAM,UAAU,eAAe,MAAM,MAAM,MAAM,YAAY,CAAC;CAI9D,SAAS,MAAM,QAAmB,KAAqC;EACrE,IAAI,QAAQ,YAAY,OAAO,KAAK,MAAM,cAAc,QAAQ,OAAO,KAAK,CAAC;EAC7E,OAAO,KAAK,MAAM,cAAc,QAAQ,OAAO,KAAK,CAAC,CAAC,IAAI;CAC5D;;CAGA,SAAS,UAAU,KAA6B;EAC9C,OAAO,eAAmC;GACxC,MAAM,SAAS,MAAM,MAAM,KAAK,WAAW,MAAM,QAAQ,GAAG,CAAC;GAC7D,IAAI,OAAO,WAAW,GAAG,OAAO;GAChC,MAAM,QAAQ,OAAO;GACrB,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK,IAAI,QAAQ;EAC5D,CAAC;CACH;CAEA,MAAM,IAAI,eAAgB,KAAK,QAAQ,MAAM,KAAK,OAAO,GAAG,IAAI,CAAE;CAClE,MAAM,IAAI,eAAgB,KAAK,QAAQ,MAAM,KAAK,OAAO,GAAG,IAAI,CAAE;CAClE,MAAM,QAAQ,eAAe,KAAK,OAAO,SAAS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AI,OAAO,OAAO;CACvC;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/position/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport {\n panelNumber,\n panelPosition,\n panelPositionChange,\n panelRotation,\n panelRotationChange\n} from '@pairdraw/core/geometry'\nimport type { NumericNodeProperty, SceneNode } from '@pairdraw/scene-graph'\nimport { layerRotates } from '@pairdraw/scene-graph/generated'\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { usePropScrub } from '#vue/controls/prop-scrub/use'\nimport { useEditor } from '#vue/editor/context'\n\n/**\n * Returns position-related state and actions for the current selection.\n *\n * This composable is designed for property panels that edit x/y, size,\n * rotation, alignment, flipping, and multi-node transforms.\n */\nexport function usePosition() {\n const editor = useEditor()\n\n const { nodes, node, active, isMulti, prop } = useNodeProps()\n const ids = computed(() => nodes.value.map((n) => n.id))\n /** Whether the selection turns and flips; a sticky note or connector stays upright. */\n const rotates = computed(() => nodes.value.every(layerRotates))\n /**\n * Whether every selected layer takes a size of its own: a layer inside an instance shows its\n * component's size, as in Figma, while an instance nested in another may be resized.\n */\n const resizes = computed(\n () =>\n nodes.value.length > 0 && nodes.value.every((target) => takesOwnSize(editor.graph, target))\n )\n\n type PanelProp = 'x' | 'y' | 'rotation' | 'width' | 'height'\n\n // X, Y, rotation, width and height read as Figma's panel shows them: two decimals, the turned\n // layer's box on the canvas and its counterclockwise angle; see `panelPosition` and\n // `panelRotation`.\n function shown(target: SceneNode, key: PanelProp): number {\n if (key === 'rotation') return panelNumber(panelRotation(target, editor.graph))\n if (key === 'x' || key === 'y') return panelNumber(panelPosition(target, editor.graph)[key])\n return panelNumber(target[key])\n }\n\n /** The shown value of every selected node, or MIXED when they differ. */\n function panelProp(key: PanelProp) {\n return computed<MixedValue<number>>(() => {\n const values = nodes.value.map((target) => shown(target, key))\n if (values.length === 0) return 0\n const first = values[0]\n return values.every((value) => value === first) ? first : MIXED\n })\n }\n\n const x = computed(() => (node.value ? shown(node.value, 'x') : 0))\n const y = computed(() => (node.value ? shown(node.value, 'y') : 0))\n const width = computed(() => (node.value ? shown(node.value, 'width') : 0))\n const height = computed(() => (node.value ? shown(node.value, 'height') : 0))\n const rotation = computed(() => (node.value ? shown(node.value, 'rotation') : 0))\n\n const {\n updateProp: _updateProp,\n updateEach,\n commitProp: _commitProp,\n cancelProp: _cancelProp\n } = usePropScrub(editor)\n\n // Typed X, Y, and rotation become each node's own move or turn, as typing them in Figma does.\n function updateProp(key: NumericNodeProperty, value: number) {\n if (key === 'x' || key === 'y') {\n updateEach(nodes.value, key, (target) =>\n panelPositionChange(target, editor.graph, key, value)\n )\n } else if (key === 'rotation') {\n updateEach(nodes.value, key, (target) => panelRotationChange(target, editor.graph, value))\n } else {\n _updateProp(nodes.value, key, value)\n }\n }\n\n function commitProp(key: NumericNodeProperty, value: number, previous: number) {\n _commitProp(nodes.value, key, value, previous)\n }\n\n function cancelProp(key: NumericNodeProperty) {\n _cancelProp(nodes.value, key)\n }\n\n /** Whether every selected layer sits in an auto layout, where it can ignore that layout. */\n const inAutoLayout = computed(\n () =>\n nodes.value.length > 0 &&\n nodes.value.every((target) => {\n const parent = target.parentId ? editor.graph.getNode(target.parentId) : undefined\n return !!parent && parent.layoutMode !== 'NONE'\n })\n )\n /** On only when every selected layer ignores its auto layout. */\n const ignoresAutoLayout = computed(\n () =>\n inAutoLayout.value && nodes.value.every((target) => target.layoutPositioning === 'ABSOLUTE')\n )\n\n /** Figma's Ignore auto layout toggle: a mixed selection is taken out of its layouts. */\n function toggleIgnoreAutoLayout() {\n editor.setLayoutPositioning(ids.value, ignoresAutoLayout.value ? 'AUTO' : 'ABSOLUTE')\n }\n\n function align(axis: 'horizontal' | 'vertical', pos: 'min' | 'center' | 'max') {\n editor.alignNodes(ids.value, axis, pos)\n }\n\n function flip(axis: 'horizontal' | 'vertical') {\n editor.flipNodes(ids.value, axis)\n }\n\n function rotate(degrees: number) {\n editor.rotateNodes(ids.value, degrees)\n }\n\n return {\n editor,\n nodes,\n node,\n active,\n isMulti,\n prop,\n panelProp,\n ids,\n x,\n y,\n width,\n height,\n rotation,\n rotates,\n resizes,\n inAutoLayout,\n ignoresAutoLayout,\n toggleIgnoreAutoLayout,\n updateProp,\n commitProp,\n cancelProp,\n align,\n flip,\n rotate\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,SAAgB,cAAc;CAC5B,MAAM,SAAS,UAAU;CAEzB,MAAM,EAAE,OAAO,MAAM,QAAQ,SAAS,SAAS,aAAa;CAC5D,MAAM,MAAM,eAAe,MAAM,MAAM,KAAK,MAAM,EAAE,EAAE,CAAC;;CAEvD,MAAM,UAAU,eAAe,MAAM,MAAM,MAAM,YAAY,CAAC;;;;;CAK9D,MAAM,UAAU,eAEZ,MAAM,MAAM,SAAS,KAAK,MAAM,MAAM,OAAO,WAAW,aAAa,OAAO,OAAO,MAAM,CAAC,CAC9F;CAOA,SAAS,MAAM,QAAmB,KAAwB;EACxD,IAAI,QAAQ,YAAY,OAAO,YAAY,cAAc,QAAQ,OAAO,KAAK,CAAC;EAC9E,IAAI,QAAQ,OAAO,QAAQ,KAAK,OAAO,YAAY,cAAc,QAAQ,OAAO,KAAK,CAAC,CAAC,IAAI;EAC3F,OAAO,YAAY,OAAO,IAAI;CAChC;;CAGA,SAAS,UAAU,KAAgB;EACjC,OAAO,eAAmC;GACxC,MAAM,SAAS,MAAM,MAAM,KAAK,WAAW,MAAM,QAAQ,GAAG,CAAC;GAC7D,IAAI,OAAO,WAAW,GAAG,OAAO;GAChC,MAAM,QAAQ,OAAO;GACrB,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK,IAAI,QAAQ;EAC5D,CAAC;CACH;CAEA,MA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I,OAAO,kBAAkB,QAAQ,SAAS,UAAU;CACtF;CAEA,SAAS,MAAM,MAAiC,KAA+B;EAC7E,OAAO,WAAW,IAAI,OAAO,MAAM,GAAG;CACxC;CAEA,SAAS,KAAK,MAAiC;EAC7C,OAAO,UAAU,IAAI,OAAO,IAAI;CAClC;CAEA,SAAS,OAAO,SAAiB;EAC/B,OAAO,YAAY,IAAI,OAAO,OAAO;CACvC;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/property-list/use.ts"],"mappings":";;;iBAwBgB,sBAAsB,UAAU,iBAAiB,SAAS"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/property-list/use.ts"],"mappings":";;;iBAyBgB,sBAAsB,UAAU,iBAAiB,SAAS"}
@@ -3,6 +3,7 @@ import { isNodeArrayMixed } from "../node-props/helpers.js";
3
3
  import { useNodeProps } from "../node-props/use.js";
4
4
  import { useUndoBatch } from "../undo-batch/use.js";
5
5
  import { computed } from "vue";
6
+ import { listBindingsAfterEdit } from "@pairdraw/scene-graph/variables";
6
7
  //#region src/controls/property-list/use.ts
7
8
  function moveItem(items, fromIndex, toIndex) {
8
9
  if (fromIndex === toIndex || fromIndex < 0 || fromIndex >= items.length) return items;
@@ -38,8 +39,19 @@ function useEditorPropertyList(propKey) {
38
39
  const own = node[propKey];
39
40
  return own.length === 0 && !isMixed.value ? items.value : own;
40
41
  }
41
- function updateArray(node, value, label) {
42
- editor.updateNodeWithUndo(node.id, { [propKey]: value }, label);
42
+ /**
43
+ * A text's fills colour every character, as a layer's own fills do in Figma. `sources` gives
44
+ * the position each item had, or null for a new one, when the edit adds, removes, or moves
45
+ * items, so their bindings follow them in the same undo step.
46
+ */
47
+ function updateArray(node, value, label, sources) {
48
+ const changes = { [propKey]: value };
49
+ if (sources) changes.boundVariables = listBindingsAfterEdit(node.boundVariables, propKey, sources);
50
+ editor.updateNodeWithUndo(node.id, editor.layerChanges(node.id, changes), label);
51
+ }
52
+ /** The positions of a list of `length` items, as `sources` for an edit that keeps them. */
53
+ function positions(length) {
54
+ return Array.from({ length }, (_, index) => index);
43
55
  }
44
56
  function add(item) {
45
57
  batch.flush();
@@ -48,7 +60,9 @@ function useEditorPropertyList(propKey) {
48
60
  const apply = () => {
49
61
  for (const node of nodes) {
50
62
  const nextItem = structuredClone(item);
51
- updateArray(node, isMulti.value ? [nextItem] : [...propArray(node), nextItem], label);
63
+ const replace = isMulti.value;
64
+ const current = propArray(node);
65
+ updateArray(node, replace ? [nextItem] : [...current, nextItem], label, replace ? [null] : [...positions(current.length), null]);
52
66
  }
53
67
  };
54
68
  if (nodes.length > 1) editor.undo.runBatch(label, apply);
@@ -59,7 +73,11 @@ function useEditorPropertyList(propKey) {
59
73
  const nodes = targetNodes();
60
74
  const label = `Remove ${propKey}`;
61
75
  const apply = () => {
62
- for (const node of nodes) updateArray(node, propArray(node).filter((_, itemIndex) => itemIndex !== index), label);
76
+ for (const node of nodes) {
77
+ const current = propArray(node);
78
+ const kept = positions(current.length).filter((itemIndex) => itemIndex !== index);
79
+ updateArray(node, kept.map((itemIndex) => current[itemIndex]), label, kept);
80
+ }
63
81
  };
64
82
  if (nodes.length > 1) editor.undo.runBatch(label, apply);
65
83
  else apply();
@@ -115,7 +133,11 @@ function useEditorPropertyList(propKey) {
115
133
  const nodes = targetNodes();
116
134
  if (nodes.length === 0 || fromIndex === toIndex) return;
117
135
  const apply = () => {
118
- for (const node of nodes) updateArray(node, moveItem(propArray(node), fromIndex, toIndex), `Reorder ${propKey}`);
136
+ for (const node of nodes) {
137
+ const current = propArray(node);
138
+ const order = moveItem(positions(current.length), fromIndex, toIndex);
139
+ updateArray(node, order.map((itemIndex) => current[itemIndex]), `Reorder ${propKey}`, order);
140
+ }
119
141
  };
120
142
  if (nodes.length > 1) editor.undo.runBatch(`Reorder ${propKey}`, apply);
121
143
  else apply();
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/property-list/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\nimport { isNodeArrayMixed } from '#vue/controls/node-props/helpers'\nimport { useNodeProps } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport type {\n PropertyListActions,\n PropertyListItemFor,\n PropertyListKey,\n PropertyListPatchFor\n} from '#vue/primitives/PropertyList/types.ts'\n\nfunction moveItem<T>(items: T[], fromIndex: number, toIndex: number): T[] {\n if (fromIndex === toIndex || fromIndex < 0 || fromIndex >= items.length) return items\n const next = [...items]\n const moved = next.splice(fromIndex, 1)[0]\n if (moved === undefined) return items\n next.splice(Math.max(0, Math.min(toIndex, next.length)), 0, moved)\n return next\n}\n\nexport function useEditorPropertyList<K extends PropertyListKey>(propKey: K) {\n const editor = useEditor()\n const { nodes: selectedNodes, activeNode } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n const selectedNodeIds = computed(() => selectedNodes.value.map((node) => node.id))\n const isMulti = computed(() => selectedNodes.value.length > 1)\n const active = computed(() => selectedNodes.value.length > 0)\n // Figma leaves layers without strokes out when it compares strokes, so a stroke on some of the\n // selection shows as theirs; fills and effects still differ when a layer has none.\n const shownNodes = computed(() => {\n if (propKey !== 'strokes') return selectedNodes.value\n const stroked = selectedNodes.value.filter((node) => node.strokes.length > 0)\n return stroked.length > 0 ? stroked : selectedNodes.value\n })\n const isMixed = computed(() => isNodeArrayMixed(shownNodes.value, propKey))\n const items = computed<PropertyListItemFor<K>[]>(() => {\n if (isMixed.value) return []\n const shown = shownNodes.value.at(0)\n return (shown?.[propKey] ?? []) as PropertyListItemFor<K>[]\n })\n\n function targetNodes(): SceneNode[] {\n if (isMulti.value) return selectedNodes.value\n return activeNode.value ? [activeNode.value] : []\n }\n\n /** A layer without strokes takes the shown ones when they are edited, as in Figma. */\n function propArray(node: SceneNode): PropertyListItemFor<K>[] {\n const own = node[propKey] as PropertyListItemFor<K>[]\n return own.length === 0 && !isMixed.value ? items.value : own\n }\n\n function updateArray(node: SceneNode, value: PropertyListItemFor<K>[], label: string) {\n editor.updateNodeWithUndo(node.id, { [propKey]: value }, label)\n }\n\n function add(item: PropertyListItemFor<K>) {\n batch.flush()\n const nodes = targetNodes()\n const label = isMulti.value ? `Set ${propKey}` : `Add ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n const nextItem = structuredClone(item)\n const next = isMulti.value ? [nextItem] : [...propArray(node), nextItem]\n updateArray(node, next, label)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function remove(index: number) {\n batch.flush()\n const nodes = targetNodes()\n const label = `Remove ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n updateArray(\n node,\n propArray(node).filter((_, itemIndex) => itemIndex !== index),\n label\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function update(index: number, item: PropertyListItemFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `update:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const next = [...propArray(node)]\n next[index] = structuredClone(item)\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function patch(index: number, changes: PropertyListPatchFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `patch:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const current = propArray(node)[index]\n if (!current) continue\n const next = [...propArray(node)]\n next[index] = { ...current, ...structuredClone(changes) }\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function toggleVisibility(index: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0) return\n const apply = () => {\n for (const node of nodes) {\n const liveNode = editor.getNode(node.id)\n if (!liveNode) continue\n const current = propArray(liveNode)[index]\n if (!current) continue\n const next = [...propArray(liveNode)]\n next[index] = { ...current, visible: !current.visible }\n updateArray(liveNode, next, `Toggle ${propKey} visibility`)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Toggle ${propKey} visibility`, apply)\n else apply()\n }\n\n function reorder(fromIndex: number, toIndex: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0 || fromIndex === toIndex) return\n const apply = () => {\n for (const node of nodes) {\n updateArray(node, moveItem(propArray(node), fromIndex, toIndex), `Reorder ${propKey}`)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Reorder ${propKey}`, apply)\n else apply()\n }\n\n const actions: PropertyListActions<K> = {\n add,\n remove,\n update,\n patch,\n toggleVisibility,\n reorder\n }\n\n return {\n items,\n isMixed,\n isMulti,\n active,\n activeNode,\n selectedNodeIds,\n flush: batch.flush,\n actions\n }\n}\n"],"mappings":";;;;;;AAeA,SAAS,SAAY,OAAY,WAAmB,SAAsB;CACxE,IAAI,cAAc,WAAW,YAAY,KAAK,aAAa,MAAM,QAAQ,OAAO;CAChF,MAAM,OAAO,CAAC,GAAG,KAAK;CACtB,MAAM,QAAQ,KAAK,OAAO,WAAW,CAAC,CAAC,CAAC;CACxC,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,CAAC,GAAG,GAAG,KAAK;CACjE,OAAO;AACT;AAEA,SAAgB,sBAAiD,SAAY;CAC3E,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,OAAO,eAAe,eAAe,aAAa;CAC1D,MAAM,QAAQ,aAAa,OAAO,MAAM,OAAO,oBAAoB;CACnE,MAAM,kBAAkB,eAAe,cAAc,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC;CACj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cAAc;GAClB,KAAK,MAAM,QAAQ,OAAO;IACxB,MAAM,WAAW,OAAO,QAAQ,KAAK,EAAE;IACvC,IAAI,CAAC,UAAU;IACf,MAAM,UAAU,UAAU,QAAQ,CAAC,CAAC;IACpC,IAAI,CAAC,SAAS;IACd,MAAM,OAAO,CAAC,GAAG,UAAU,QAAQ,CAAC;IACpC,KAAK,SAAS;KAAE,GAAG;KAAS,SAAS,CAAC,QAAQ;IAAQ;IACtD,YAAY,UAAU,MAAM,UAAU,QAAQ,YAAY;GAC5D;EACF;EACA,IAAI,MAAM,SAAS,GAAG,OAAO,KAAK,SAAS,UAAU,QAAQ,cAAc,KAAK;OAC3E,MAAM;CACb;CAEA,SAAS,QAAQ,WAAmB,SAAiB;EACnD,MAAM,MAAM;EACZ,MAAM,QAAQ,YAAY;EAC1B,IAAI,MAAM,WAAW,KAAK,cAAc,SAAS;EACjD,MAAM,cAAc;GAClB,KAAK,MAAM,QAAQ,OACjB,YAAY,MAAM,SAAS,UAAU,IAAI,GAAG,WAAW,OAAO,GAAG,WAAW,SAAS;EAEzF;EACA,IAAI,MAAM,SAAS,GAAG,OAAO,KAAK,SAAS,WAAW,WAAW,KAAK;OACjE,MAAM;CACb;CAEA,MAAM,UAAkC;EACtC;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,MAAM;EACb;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/property-list/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { listBindingsAfterEdit } from '@pairdraw/scene-graph/variables'\n\nimport { isNodeArrayMixed } from '#vue/controls/node-props/helpers'\nimport { useNodeProps } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport type {\n PropertyListActions,\n PropertyListItemFor,\n PropertyListKey,\n PropertyListPatchFor\n} from '#vue/primitives/PropertyList/types.ts'\n\nfunction moveItem<T>(items: readonly T[], fromIndex: number, toIndex: number): readonly T[] {\n if (fromIndex === toIndex || fromIndex < 0 || fromIndex >= items.length) return items\n const next = [...items]\n const moved = next.splice(fromIndex, 1)[0]\n if (moved === undefined) return items\n next.splice(Math.max(0, Math.min(toIndex, next.length)), 0, moved)\n return next\n}\n\nexport function useEditorPropertyList<K extends PropertyListKey>(propKey: K) {\n const editor = useEditor()\n const { nodes: selectedNodes, activeNode } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n const selectedNodeIds = computed(() => selectedNodes.value.map((node) => node.id))\n const isMulti = computed(() => selectedNodes.value.length > 1)\n const active = computed(() => selectedNodes.value.length > 0)\n // Figma leaves layers without strokes out when it compares strokes, so a stroke on some of the\n // selection shows as theirs; fills and effects still differ when a layer has none.\n const shownNodes = computed(() => {\n if (propKey !== 'strokes') return selectedNodes.value\n const stroked = selectedNodes.value.filter((node) => node.strokes.length > 0)\n return stroked.length > 0 ? stroked : selectedNodes.value\n })\n const isMixed = computed(() => isNodeArrayMixed(shownNodes.value, propKey))\n const items = computed<PropertyListItemFor<K>[]>(() => {\n if (isMixed.value) return []\n const shown = shownNodes.value.at(0)\n return (shown?.[propKey] ?? []) as PropertyListItemFor<K>[]\n })\n\n function targetNodes(): SceneNode[] {\n if (isMulti.value) return selectedNodes.value\n return activeNode.value ? [activeNode.value] : []\n }\n\n /** A layer without strokes takes the shown ones when they are edited, as in Figma. */\n function propArray(node: SceneNode): PropertyListItemFor<K>[] {\n const own = node[propKey] as PropertyListItemFor<K>[]\n return own.length === 0 && !isMixed.value ? items.value : own\n }\n\n /**\n * A text's fills colour every character, as a layer's own fills do in Figma. `sources` gives\n * the position each item had, or null for a new one, when the edit adds, removes, or moves\n * items, so their bindings follow them in the same undo step.\n */\n function updateArray(\n node: SceneNode,\n value: PropertyListItemFor<K>[],\n label: string,\n sources?: readonly (number | null)[]\n ) {\n const changes: Partial<SceneNode> = { [propKey]: value }\n if (sources) {\n changes.boundVariables = listBindingsAfterEdit(node.boundVariables, propKey, sources)\n }\n editor.updateNodeWithUndo(node.id, editor.layerChanges(node.id, changes), label)\n }\n\n /** The positions of a list of `length` items, as `sources` for an edit that keeps them. */\n function positions(length: number): number[] {\n return Array.from({ length }, (_, index) => index)\n }\n\n function add(item: PropertyListItemFor<K>) {\n batch.flush()\n const nodes = targetNodes()\n const label = isMulti.value ? `Set ${propKey}` : `Add ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n const nextItem = structuredClone(item)\n const replace = isMulti.value\n const current = propArray(node)\n updateArray(\n node,\n replace ? [nextItem] : [...current, nextItem],\n label,\n replace ? [null] : [...positions(current.length), null]\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function remove(index: number) {\n batch.flush()\n const nodes = targetNodes()\n const label = `Remove ${propKey}`\n const apply = () => {\n for (const node of nodes) {\n const current = propArray(node)\n const kept = positions(current.length).filter((itemIndex) => itemIndex !== index)\n updateArray(\n node,\n kept.map((itemIndex) => current[itemIndex]),\n label,\n kept\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(label, apply)\n else apply()\n }\n\n function update(index: number, item: PropertyListItemFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `update:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const next = [...propArray(node)]\n next[index] = structuredClone(item)\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function patch(index: number, changes: PropertyListPatchFor<K>) {\n const nodes = targetNodes()\n if (nodes.length === 0) return\n batch.ensure(\n `patch:${propKey}:${index}:${nodes.map((node) => node.id).join(',')}`,\n `Change ${propKey}`\n )\n for (const node of nodes) {\n const current = propArray(node)[index]\n if (!current) continue\n const next = [...propArray(node)]\n next[index] = { ...current, ...structuredClone(changes) }\n updateArray(node, next, `Change ${propKey}`)\n }\n }\n\n function toggleVisibility(index: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0) return\n const apply = () => {\n for (const node of nodes) {\n const liveNode = editor.getNode(node.id)\n if (!liveNode) continue\n const current = propArray(liveNode)[index]\n if (!current) continue\n const next = [...propArray(liveNode)]\n next[index] = { ...current, visible: !current.visible }\n updateArray(liveNode, next, `Toggle ${propKey} visibility`)\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Toggle ${propKey} visibility`, apply)\n else apply()\n }\n\n function reorder(fromIndex: number, toIndex: number) {\n batch.flush()\n const nodes = targetNodes()\n if (nodes.length === 0 || fromIndex === toIndex) return\n const apply = () => {\n for (const node of nodes) {\n const current = propArray(node)\n const order = moveItem(positions(current.length), fromIndex, toIndex)\n updateArray(\n node,\n order.map((itemIndex) => current[itemIndex]),\n `Reorder ${propKey}`,\n order\n )\n }\n }\n if (nodes.length > 1) editor.undo.runBatch(`Reorder ${propKey}`, apply)\n else apply()\n }\n\n const actions: PropertyListActions<K> = {\n add,\n remove,\n update,\n patch,\n toggleVisibility,\n reorder\n }\n\n return {\n items,\n isMixed,\n isMulti,\n active,\n activeNode,\n selectedNodeIds,\n flush: batch.flush,\n actions\n }\n}\n"],"mappings":";;;;;;;AAgBA,SAAS,SAAY,OAAqB,WAAmB,SAA+B;CAC1F,IAAI,cAAc,WAAW,YAAY,KAAK,aAAa,MAAM,QAAQ,OAAO;CAChF,MAAM,OAAO,CAAC,GAAG,KAAK;CACtB,MAAM,QAAQ,KAAK,OAAO,WAAW,CAAC,CAAC,CAAC;CACxC,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,KAAK,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,CAAC,GAAG,GAAG,KAAK;CACjE,OAAO;AACT;AAEA,SAAgB,sBAAiD,SAAY;CAC3E,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,OAAO,eAAe,eAAe,aAAa;CAC1D,MAAM,QAAQ,aAAa,OAA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,QAAQ,UAAU,GAC3C,WAAW,WACX,KACF;GACF;EACF;EACA,IAAI,MAAM,SAAS,GAAG,OAAO,KAAK,SAAS,WAAW,WAAW,KAAK;OACjE,MAAM;CACb;CAEA,MAAM,UAAkC;EACtC;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,MAAM;EACb;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/selection-layout/use.ts"],"mappings":";;;;cAUa,wBAAwB,YAAY;KAOrC;iBAQI,eAAe,MAAM,YAAY;;;;;;iBAiBjC;;;;;;;;;;;EA+BW,aAAA;;EAgBI,gBAAA,MAAA;EAOA,gBAAA,MAAA"}
1
+ {"version":3,"file":"use.d.ts","names":[],"sources":["../../../src/controls/selection-layout/use.ts"],"mappings":";;;;cAWa,wBAAwB,YAAY;KAOrC;iBAQI,eAAe,MAAM,YAAY;;;;;;iBAkBjC;;;;;;;;;;;EA+BW,aAAA;;EAgBI,gBAAA,MAAA;EAOA,gBAAA,MAAA"}
@@ -4,6 +4,7 @@ import { useNodeProps } from "../node-props/use.js";
4
4
  import { useSceneComputed } from "../../internal/scene-computed/use.js";
5
5
  import { useUndoBatch } from "../undo-batch/use.js";
6
6
  import { computed } from "vue";
7
+ import { panelNumber } from "@pairdraw/core/geometry";
7
8
  //#region src/controls/selection-layout/use.ts
8
9
  /** Layers that can hold an auto layout and clip their content. */
9
10
  const LAYOUT_CONTAINER_TYPES = /* @__PURE__ */ new Set([
@@ -19,7 +20,7 @@ const TEXT_AUTO_RESIZE = {
19
20
  };
20
21
  function textResizeMode(node) {
21
22
  if (node.textAutoResize === "WIDTH_AND_HEIGHT") return "AUTO_WIDTH";
22
- if (node.textAutoResize === "HEIGHT" || node.textAutoResize === "TRUNCATE") return "AUTO_HEIGHT";
23
+ if (node.textAutoResize === "HEIGHT") return "AUTO_HEIGHT";
23
24
  return "FIXED";
24
25
  }
25
26
  function shared(values) {
@@ -48,7 +49,7 @@ function useSelectionLayout() {
48
49
  const spacingAxis = computed(() => rowSpacing.value?.axis);
49
50
  /** The gap between neighbours, MIXED when they differ. */
50
51
  const spacing = computed(() => {
51
- return shared(rowSpacing.value?.gaps.map((gap) => Math.round(gap * 100) / 100) ?? []) ?? MIXED;
52
+ return shared(rowSpacing.value?.gaps.map(panelNumber) ?? []) ?? MIXED;
52
53
  });
53
54
  /** Spaces the row evenly from its first layer; a scrub is one undo step. */
54
55
  function setSpacing(gap) {
@@ -1 +1 @@
1
- {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/selection-layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport type { LayoutMode, NodeType, SceneNode } from '@pairdraw/scene-graph'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\n/** Layers that can hold an auto layout and clip their content. */\nexport const LAYOUT_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport type TextResizeMode = 'AUTO_WIDTH' | 'AUTO_HEIGHT' | 'FIXED'\n\nconst TEXT_AUTO_RESIZE: Record<TextResizeMode, SceneNode['textAutoResize']> = {\n AUTO_WIDTH: 'WIDTH_AND_HEIGHT',\n AUTO_HEIGHT: 'HEIGHT',\n FIXED: 'NONE'\n}\n\nexport function textResizeMode(node: SceneNode): TextResizeMode {\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') return 'AUTO_WIDTH'\n if (node.textAutoResize === 'HEIGHT' || node.textAutoResize === 'TRUNCATE') return 'AUTO_HEIGHT'\n return 'FIXED'\n}\n\nfunction shared<T>(values: readonly T[]): MixedValue<T> | undefined {\n if (values.length === 0) return undefined\n const [first] = values\n return values.every((value) => value === first) ? first : MIXED\n}\n\n/**\n * Layout of a multi-selection, as Figma's panel shows it: text resizing for its text layers,\n * flow when every layer can hold an auto layout, clip content for those that can clip, and the\n * spacing of a row or column. Each edit changes the layers it applies to in one undo step.\n */\nexport function useSelectionLayout() {\n const editor = useEditor()\n const { nodes } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n\n const texts = computed(() => nodes.value.filter((node) => node.type === 'TEXT'))\n const containers = computed(() =>\n nodes.value.filter((node) => LAYOUT_CONTAINER_TYPES.has(node.type))\n )\n const allContainers = computed(\n () => nodes.value.length > 0 && containers.value.length === nodes.value.length\n )\n\n /** Undefined when no text is selected. */\n const textResize = computed(() => shared(texts.value.map(textResizeMode)))\n /** Undefined unless every selected layer can hold an auto layout. */\n const layoutMode = computed(() =>\n allContainers.value ? shared(containers.value.map((node) => node.layoutMode)) : undefined\n )\n const rowSpacing = useSceneComputed(() =>\n editor.selectionSpacing(nodes.value.map((node) => node.id))\n )\n /** The axis of a row or column, or undefined when the layers are not one. */\n const spacingAxis = computed(() => rowSpacing.value?.axis)\n /** The gap between neighbours, MIXED when they differ. */\n const spacing = computed<MixedValue<number>>(() => {\n const gaps = rowSpacing.value?.gaps.map((gap) => Math.round(gap * 100) / 100) ?? []\n return shared(gaps) ?? MIXED\n })\n\n /** Spaces the row evenly from its first layer; a scrub is one undo step. */\n function setSpacing(gap: number) {\n batch.ensure('selection-spacing', 'Change spacing')\n editor.setSelectionSpacing(\n nodes.value.map((node) => node.id),\n gap\n )\n }\n\n /** Undefined when nothing selected can clip. */\n const clipsContent = computed(() => shared(containers.value.map((node) => node.clipsContent)))\n const autoLayouts = computed(() => containers.value.filter((node) => node.layoutMode !== 'NONE'))\n /** Undefined when nothing selected has an auto layout. */\n const strokesIncludedInLayout = computed(() =>\n shared(autoLayouts.value.map((node) => node.strokesIncludedInLayout))\n )\n\n function setTextResize(mode: TextResizeMode) {\n editor.undo.runBatch('Set text resizing', () => {\n for (const node of texts.value)\n editor.updateNodeWithUndo(node.id, { textAutoResize: TEXT_AUTO_RESIZE[mode] })\n })\n }\n\n function setLayoutMode(mode: LayoutMode) {\n editor.undo.runBatch('Set layout', () => {\n for (const node of containers.value) editor.setLayoutMode(node.id, mode)\n })\n }\n\n /** A mixed checkbox turns clipping on, as Figma's does. */\n function toggleClipsContent() {\n const clips = clipsContent.value !== true\n editor.undo.runBatch('Toggle clip content', () => {\n for (const node of containers.value)\n editor.updateNodeWithUndo(node.id, { clipsContent: clips })\n })\n }\n\n /** A mixed checkbox includes strokes, as a mixed clip content checkbox clips. */\n function toggleStrokesIncludedInLayout() {\n const included = strokesIncludedInLayout.value !== true\n editor.undo.runBatch('Toggle strokes in layout', () => {\n for (const node of autoLayouts.value)\n editor.updateNodeWithUndo(node.id, { strokesIncludedInLayout: included })\n })\n }\n\n return {\n editor,\n nodes,\n texts,\n containers,\n textResize,\n layoutMode,\n clipsContent,\n strokesIncludedInLayout,\n spacingAxis,\n spacing,\n setSpacing,\n flushSpacing: batch.flush,\n setTextResize,\n setLayoutMode,\n toggleClipsContent,\n toggleStrokesIncludedInLayout\n }\n}\n"],"mappings":";;;;;;;;AAUA,MAAa,yCAAgD,IAAI,IAAc;CAC7E;CACA;CACA;CACA;AACF,CAAC;AAID,MAAM,mBAAwE;CAC5E,YAAY;CACZ,aAAa;CACb,OAAO;AACT;AAEA,SAAgB,eAAe,MAAiC;CAC9D,IAAI,KAAK,mBAAmB,oBAAoB,OAAO;CACvD,IAAI,KAAK,mBAAmB,YAAY,KAAK,mBAAmB,YAAY,OAAO;CACnF,OAAO;AACT;AAEA,SAAS,OAAU,QAAiD;CAClE,IAAI,OAAO,WAAW,GAAG,OAAO,KAAA;CAChC,MAAM,CAAC,SAAS;CAChB,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK,IAAI,QAAQ;AAC5D;;;;;;AAOA,SAAgB,qBAAqB;CACnC,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,UAAU,aAAa;CAC/B,MAA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AK,IAAI,EAAE,gBAAgB,iBAAiB,MAAM,CAAC;EACjF,CAAC;CACH;CAEA,SAAS,cAAc,MAAkB;EACvC,OAAO,KAAK,SAAS,oBAAoB;GACvC,KAAK,MAAM,QAAQ,WAAW,OAAO,OAAO,cAAc,KAAK,IAAI,IAAI;EACzE,CAAC;CACH;;CAGA,SAAS,qBAAqB;EAC5B,MAAM,QAAQ,aAAa,UAAU;EACrC,OAAO,KAAK,SAAS,6BAA6B;GAChD,KAAK,MAAM,QAAQ,WAAW,OAC5B,OAAO,mBAAmB,KAAK,IAAI,EAAE,cAAc,MAAM,CAAC;EAC9D,CAAC;CACH;;CAGA,SAAS,gCAAgC;EACvC,MAAM,WAAW,wBAAwB,UAAU;EACnD,OAAO,KAAK,SAAS,kCAAkC;GACrD,KAAK,MAAM,QAAQ,YAAY,OAC7B,OAAO,mBAAmB,KAAK,IAAI,EAAE,yBAAyB,SAAS,CAAC;EAC5E,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc,MAAM;EACpB;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use.js","names":[],"sources":["../../../src/controls/selection-layout/use.ts"],"sourcesContent":["import { computed } from 'vue'\n\nimport { panelNumber } from '@pairdraw/core/geometry'\nimport type { LayoutMode, NodeType, SceneNode } from '@pairdraw/scene-graph'\n\nimport { MIXED, useNodeProps, type MixedValue } from '#vue/controls/node-props/use'\nimport { useUndoBatch } from '#vue/controls/undo-batch/use'\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\n/** Layers that can hold an auto layout and clip their content. */\nexport const LAYOUT_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport type TextResizeMode = 'AUTO_WIDTH' | 'AUTO_HEIGHT' | 'FIXED'\n\nconst TEXT_AUTO_RESIZE: Record<TextResizeMode, SceneNode['textAutoResize']> = {\n AUTO_WIDTH: 'WIDTH_AND_HEIGHT',\n AUTO_HEIGHT: 'HEIGHT',\n FIXED: 'NONE'\n}\n\nexport function textResizeMode(node: SceneNode): TextResizeMode {\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') return 'AUTO_WIDTH'\n // A truncating text keeps the size it has and ends its lines, so it is a fixed box here.\n if (node.textAutoResize === 'HEIGHT') return 'AUTO_HEIGHT'\n return 'FIXED'\n}\n\nfunction shared<T>(values: readonly T[]): MixedValue<T> | undefined {\n if (values.length === 0) return undefined\n const [first] = values\n return values.every((value) => value === first) ? first : MIXED\n}\n\n/**\n * Layout of a multi-selection, as Figma's panel shows it: text resizing for its text layers,\n * flow when every layer can hold an auto layout, clip content for those that can clip, and the\n * spacing of a row or column. Each edit changes the layers it applies to in one undo step.\n */\nexport function useSelectionLayout() {\n const editor = useEditor()\n const { nodes } = useNodeProps()\n const batch = useUndoBatch(editor.undo, editor.beginInteractiveEdit)\n\n const texts = computed(() => nodes.value.filter((node) => node.type === 'TEXT'))\n const containers = computed(() =>\n nodes.value.filter((node) => LAYOUT_CONTAINER_TYPES.has(node.type))\n )\n const allContainers = computed(\n () => nodes.value.length > 0 && containers.value.length === nodes.value.length\n )\n\n /** Undefined when no text is selected. */\n const textResize = computed(() => shared(texts.value.map(textResizeMode)))\n /** Undefined unless every selected layer can hold an auto layout. */\n const layoutMode = computed(() =>\n allContainers.value ? shared(containers.value.map((node) => node.layoutMode)) : undefined\n )\n const rowSpacing = useSceneComputed(() =>\n editor.selectionSpacing(nodes.value.map((node) => node.id))\n )\n /** The axis of a row or column, or undefined when the layers are not one. */\n const spacingAxis = computed(() => rowSpacing.value?.axis)\n /** The gap between neighbours, MIXED when they differ. */\n const spacing = computed<MixedValue<number>>(() => {\n const gaps = rowSpacing.value?.gaps.map(panelNumber) ?? []\n return shared(gaps) ?? MIXED\n })\n\n /** Spaces the row evenly from its first layer; a scrub is one undo step. */\n function setSpacing(gap: number) {\n batch.ensure('selection-spacing', 'Change spacing')\n editor.setSelectionSpacing(\n nodes.value.map((node) => node.id),\n gap\n )\n }\n\n /** Undefined when nothing selected can clip. */\n const clipsContent = computed(() => shared(containers.value.map((node) => node.clipsContent)))\n const autoLayouts = computed(() => containers.value.filter((node) => node.layoutMode !== 'NONE'))\n /** Undefined when nothing selected has an auto layout. */\n const strokesIncludedInLayout = computed(() =>\n shared(autoLayouts.value.map((node) => node.strokesIncludedInLayout))\n )\n\n function setTextResize(mode: TextResizeMode) {\n editor.undo.runBatch('Set text resizing', () => {\n for (const node of texts.value)\n editor.updateNodeWithUndo(node.id, { textAutoResize: TEXT_AUTO_RESIZE[mode] })\n })\n }\n\n function setLayoutMode(mode: LayoutMode) {\n editor.undo.runBatch('Set layout', () => {\n for (const node of containers.value) editor.setLayoutMode(node.id, mode)\n })\n }\n\n /** A mixed checkbox turns clipping on, as Figma's does. */\n function toggleClipsContent() {\n const clips = clipsContent.value !== true\n editor.undo.runBatch('Toggle clip content', () => {\n for (const node of containers.value)\n editor.updateNodeWithUndo(node.id, { clipsContent: clips })\n })\n }\n\n /** A mixed checkbox includes strokes, as a mixed clip content checkbox clips. */\n function toggleStrokesIncludedInLayout() {\n const included = strokesIncludedInLayout.value !== true\n editor.undo.runBatch('Toggle strokes in layout', () => {\n for (const node of autoLayouts.value)\n editor.updateNodeWithUndo(node.id, { strokesIncludedInLayout: included })\n })\n }\n\n return {\n editor,\n nodes,\n texts,\n containers,\n textResize,\n layoutMode,\n clipsContent,\n strokesIncludedInLayout,\n spacingAxis,\n spacing,\n setSpacing,\n flushSpacing: batch.flush,\n setTextResize,\n setLayoutMode,\n toggleClipsContent,\n toggleStrokesIncludedInLayout\n }\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,yCAAgD,IAAI,IAAc;CAC7E;CACA;CACA;CACA;AACF,CAAC;AAID,MAAM,mBAAwE;CAC5E,YAAY;CACZ,aAAa;CACb,OAAO;AACT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A,oBAAM;EACJ,WAAA,oBAAM;EACL,YAAA,oBAAM;IAAY;IAAsB;;EAEjC,mBAAA,oBAAM;EArBL,eAAA,oBAAM,qBAAqB;EAwBtC,SAAA"}
1
+ {"version":3,"file":"authoring.d.ts","names":[],"sources":["../../../src/controls/slots/authoring.ts"],"mappings":";;;UAeiB;EACf;EACA;EACA;EACA;EACA;EACA;;EAEA,WAAW;;;;;;iBAYG;;;mCAAA;EAiDe,UAAA,uBAAS;;EAsBf,SAAA,oBAAM;EACJ,WAAA,oBAAM;EACL,YAAA,oBAAM;IAAY;IAAsB;;EAEjC,mBAAA,oBAAM;EArBL,eAAA,oBAAM,qBAAqB;EAwBtC,SAAA"}
@@ -2,6 +2,7 @@ import { useEditor } from "../../editor/context/index.js";
2
2
  import { useSceneComputed } from "../../internal/scene-computed/use.js";
3
3
  import { slotInstanceOptions } from "./instance.js";
4
4
  import { canCreateSlot, slotOwner, slotPropertyId } from "@pairdraw/scene-graph/slots";
5
+ import { propertyOwner } from "@pairdraw/scene-graph/components";
5
6
  //#region src/controls/slots/authoring.ts
6
7
  /** The value a preferred-components list stores for a component: its key, else its id. */
7
8
  function preferredValue(component) {
@@ -18,7 +19,7 @@ function useSlotAuthoring() {
18
19
  if (nodes.length !== 1) return void 0;
19
20
  const [node] = nodes;
20
21
  if (node.type === "COMPONENT") return {
21
- owner: node,
22
+ owner: propertyOwner(editor.graph, node),
22
23
  frame: void 0,
23
24
  propertyId: void 0
24
25
  };
@@ -1 +1 @@
1
- {"version":3,"file":"authoring.js","names":[],"sources":["../../../src/controls/slots/authoring.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneNode } from '@pairdraw/scene-graph'\nimport {\n canCreateSlot,\n slotOwner,\n slotPropertyId,\n type SlotPropertyPatch\n} from '@pairdraw/scene-graph/slots'\n\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\nimport { slotInstanceOptions, type SlotInstanceOption } from './instance'\n\n/** A slot property as its main component defines it. */\nexport interface SlotDefinitionControl {\n id: string\n name: string\n description: string\n minChildren?: number\n maxChildren?: number\n preferredOnly: boolean\n /** Components the slot prefers, resolved from the definition's preferred values. */\n preferred: SlotInstanceOption[]\n}\n\n/** The value a preferred-components list stores for a component: its key, else its id. */\nfunction preferredValue(component: SceneNode): string {\n return component.componentKey ?? component.id\n}\n\n/**\n * Slot properties of the selected main component or slot frame, with the actions that\n * create, configure, and remove them.\n */\nexport function useSlotAuthoring() {\n const editor = useEditor()\n const target = useSceneComputed(() => {\n const nodes = editor.getSelectedNodes()\n if (nodes.length !== 1) return undefined\n const [node] = nodes\n if (node.type === 'COMPONENT') return { owner: node, frame: undefined, propertyId: undefined }\n const owner = slotOwner(editor.graph, node)\n if (!owner) return undefined\n const propertyId = slotPropertyId(node)\n if (!propertyId && !canCreateSlot(editor.graph, node)) return undefined\n return { owner, frame: node, propertyId }\n })\n const slots = useSceneComputed<SlotDefinitionControl[]>(() => {\n const current = target.value\n if (!current) return []\n return current.owner.componentPropertyDefinitions\n .filter((definition) => definition.type === 'SLOT')\n .filter((definition) => !current.frame || definition.id === current.propertyId)\n .map((definition) => {\n const values = new Set(definition.preferredValues)\n return {\n id: definition.id,\n name: definition.name,\n description: definition.description ?? '',\n minChildren: definition.slotSettings?.minChildren,\n maxChildren: definition.slotSettings?.maxChildren,\n preferredOnly: definition.slotSettings?.allowPreferredValuesOnly ?? false,\n preferred: slotInstanceOptions(editor.graph, definition).filter(\n (option) => option.preferred && values.size > 0\n )\n }\n })\n })\n /** Whether the selection is a frame that can become a slot. */\n const canCreate = useSceneComputed(() => !!target.value?.frame && !target.value.propertyId)\n const active = useSceneComputed(() => slots.value.length > 0 || canCreate.value)\n\n function update(propertyId: string, patch: SlotPropertyPatch) {\n const owner = target.value?.owner\n if (owner) editor.updateSlot(owner.id, propertyId, patch)\n }\n\n function definition(propertyId: string): ComponentPropertyDefinition | undefined {\n return target.value?.owner.componentPropertyDefinitions.find((item) => item.id === propertyId)\n }\n\n /** Components that can be marked preferred, the slot's current choices first. */\n function options(propertyId: string): SlotInstanceOption[] {\n const found = definition(propertyId)\n return found ? slotInstanceOptions(editor.graph, found) : []\n }\n\n function setPreferred(propertyId: string, componentId: string, preferred: boolean) {\n const found = definition(propertyId)\n const component = editor.graph.getNode(componentId)\n if (!found || !component) return\n const keys = new Set([component.id, component.componentKey, component.sourceLibraryKey])\n const rest = (found.preferredValues ?? []).filter((value) => !keys.has(value))\n update(propertyId, {\n preferredValues: preferred ? [...rest, preferredValue(component)] : rest\n })\n }\n\n return {\n active,\n canCreate,\n slots,\n options,\n create: () => editor.createSlot(),\n rename: (propertyId: string, name: string) => update(propertyId, { name }),\n describe: (propertyId: string, description: string) => update(propertyId, { description }),\n setLimits: (propertyId: string, limits: { minChildren?: number; maxChildren?: number }) =>\n update(propertyId, { slotSettings: limits }),\n setPreferredOnly: (propertyId: string, value: boolean) =>\n update(propertyId, { slotSettings: { allowPreferredValuesOnly: value } }),\n setPreferred,\n remove: (propertyId: string) => {\n const owner = target.value?.owner\n if (owner) editor.removeSlot(owner.id, propertyId)\n }\n }\n}\n"],"mappings":";;;;;;AA0BA,SAAS,eAAe,WAA8B;CACpD,OAAO,UAAU,gBAAgB,UAAU;AAC7C;;;;;AAMA,SAAgB,mBAAmB;CACjC,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,uBAAuB;EACpC,MAAM,QAAQ,OAAO,iBAAiB;EACtC,IAAI,MAAM,WAAW,GAAG,OAAO,KAAA;EAC/B,MAAM,CAAC,QAAQ;EACf,IAAI,KAAK,SAAS,aAAa,OAAO;GAAE,OAAO;GAAM,OAAO,KAAA;GAAW,YAAY,KAAA;EAAU;EAC7F,MAAM,QAAQ,UAAU,OAAO,OAAO,IAAI;EAC1C,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,MAAM,aAAa,eAAe,IAAI;EACtC,IAAI,CAAC,cAAc,CAAC,cAAc,OAAO,OAAO,IAAI,GAAG,OAAO,KAAA;EAC9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AI,CAAC,SAAS,CAAC,WAAW;EAC1B,MAAM,uBAAO,IAAI,IAAI;GAAC,UAAU;GAAI,UAAU;GAAc,UAAU;EAAgB,CAAC;EACvF,MAAM,QAAQ,MAAM,mBAAmB,CAAC,EAAA,CAAG,QAAQ,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC;EAC7E,OAAO,YAAY,EACjB,iBAAiB,YAAY,CAAC,GAAG,MAAM,eAAe,SAAS,CAAC,IAAI,KACtE,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA,cAAc,OAAO,WAAW;EAChC,SAAS,YAAoB,SAAiB,OAAO,YAAY,EAAE,KAAK,CAAC;EACzE,WAAW,YAAoB,gBAAwB,OAAO,YAAY,EAAE,YAAY,CAAC;EACzF,YAAY,YAAoB,WAC9B,OAAO,YAAY,EAAE,cAAc,OAAO,CAAC;EAC7C,mBAAmB,YAAoB,UACrC,OAAO,YAAY,EAAE,cAAc,EAAE,0BAA0B,MAAM,EAAE,CAAC;EAC1E;EACA,SAAS,eAAuB;GAC9B,MAAM,QAAQ,OAAO,OAAO;GAC5B,IAAI,OAAO,OAAO,WAAW,MAAM,IAAI,UAAU;EACnD;CACF;AACF"}
1
+ {"version":3,"file":"authoring.js","names":[],"sources":["../../../src/controls/slots/authoring.ts"],"sourcesContent":["import type { ComponentPropertyDefinition, SceneNode } from '@pairdraw/scene-graph'\nimport { propertyOwner } from '@pairdraw/scene-graph/components'\nimport {\n canCreateSlot,\n slotOwner,\n slotPropertyId,\n type SlotPropertyPatch\n} from '@pairdraw/scene-graph/slots'\n\nimport { useEditor } from '#vue/editor/context'\nimport { useSceneComputed } from '#vue/internal/scene-computed/use'\n\nimport { slotInstanceOptions, type SlotInstanceOption } from './instance'\n\n/** A slot property as its main component defines it. */\nexport interface SlotDefinitionControl {\n id: string\n name: string\n description: string\n minChildren?: number\n maxChildren?: number\n preferredOnly: boolean\n /** Components the slot prefers, resolved from the definition's preferred values. */\n preferred: SlotInstanceOption[]\n}\n\n/** The value a preferred-components list stores for a component: its key, else its id. */\nfunction preferredValue(component: SceneNode): string {\n return component.componentKey ?? component.id\n}\n\n/**\n * Slot properties of the selected main component or slot frame, with the actions that\n * create, configure, and remove them.\n */\nexport function useSlotAuthoring() {\n const editor = useEditor()\n const target = useSceneComputed(() => {\n const nodes = editor.getSelectedNodes()\n if (nodes.length !== 1) return undefined\n const [node] = nodes\n if (node.type === 'COMPONENT')\n return { owner: propertyOwner(editor.graph, node), frame: undefined, propertyId: undefined }\n const owner = slotOwner(editor.graph, node)\n if (!owner) return undefined\n const propertyId = slotPropertyId(node)\n if (!propertyId && !canCreateSlot(editor.graph, node)) return undefined\n return { owner, frame: node, propertyId }\n })\n const slots = useSceneComputed<SlotDefinitionControl[]>(() => {\n const current = target.value\n if (!current) return []\n return current.owner.componentPropertyDefinitions\n .filter((definition) => definition.type === 'SLOT')\n .filter((definition) => !current.frame || definition.id === current.propertyId)\n .map((definition) => {\n const values = new Set(definition.preferredValues)\n return {\n id: definition.id,\n name: definition.name,\n description: definition.description ?? '',\n minChildren: definition.slotSettings?.minChildren,\n maxChildren: definition.slotSettings?.maxChildren,\n preferredOnly: definition.slotSettings?.allowPreferredValuesOnly ?? false,\n preferred: slotInstanceOptions(editor.graph, definition).filter(\n (option) => option.preferred && values.size > 0\n )\n }\n })\n })\n /** Whether the selection is a frame that can become a slot. */\n const canCreate = useSceneComputed(() => !!target.value?.frame && !target.value.propertyId)\n const active = useSceneComputed(() => slots.value.length > 0 || canCreate.value)\n\n function update(propertyId: string, patch: SlotPropertyPatch) {\n const owner = target.value?.owner\n if (owner) editor.updateSlot(owner.id, propertyId, patch)\n }\n\n function definition(propertyId: string): ComponentPropertyDefinition | undefined {\n return target.value?.owner.componentPropertyDefinitions.find((item) => item.id === propertyId)\n }\n\n /** Components that can be marked preferred, the slot's current choices first. */\n function options(propertyId: string): SlotInstanceOption[] {\n const found = definition(propertyId)\n return found ? slotInstanceOptions(editor.graph, found) : []\n }\n\n function setPreferred(propertyId: string, componentId: string, preferred: boolean) {\n const found = definition(propertyId)\n const component = editor.graph.getNode(componentId)\n if (!found || !component) return\n const keys = new Set([component.id, component.componentKey, component.sourceLibraryKey])\n const rest = (found.preferredValues ?? []).filter((value) => !keys.has(value))\n update(propertyId, {\n preferredValues: preferred ? [...rest, preferredValue(component)] : rest\n })\n }\n\n return {\n active,\n canCreate,\n slots,\n options,\n create: () => editor.createSlot(),\n rename: (propertyId: string, name: string) => update(propertyId, { name }),\n describe: (propertyId: string, description: string) => update(propertyId, { description }),\n setLimits: (propertyId: string, limits: { minChildren?: number; maxChildren?: number }) =>\n update(propertyId, { slotSettings: limits }),\n setPreferredOnly: (propertyId: string, value: boolean) =>\n update(propertyId, { slotSettings: { allowPreferredValuesOnly: value } }),\n setPreferred,\n remove: (propertyId: string) => {\n const owner = target.value?.owner\n if (owner) editor.removeSlot(owner.id, propertyId)\n }\n }\n}\n"],"mappings":";;;;;;;AA2BA,SAAS,eAAe,WAA8B;CACpD,OAAO,UAAU,gBAAgB,UAAU;AAC7C;;;;;AAMA,SAAgB,mBAAmB;CACjC,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,uBAAuB;EACpC,MAAM,QAAQ,OAAO,iBAAiB;EACtC,IAAI,MAAM,WAAW,GAAG,OAAO,KAAA;EAC/B,MAAM,CAAC,QAAQ;EACf,IAAI,KAAK,SAAS,aAChB,OAAO;GAAE,OAAO,cAAc,OAAO,OAAO,IAAI;GAAG,OAAO,KAAA;GAAW,YAAY,KAAA;EAAU;EAC7F,MAAM,QAAQ,UAAU,OAAO,OAAO,IAAI;EAC1C,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,MAAM,aAAa,eAAe,IAAI;EACtC,IAAI,CAAC,cAAc,CAAC,cAAc,OAAO,OAAO,IAAI,GAAG,OAAO,KAAA;EAC9D,OAAO;GAAE;GAAO,OAAO;GAAM;EAAW;CAC1C,CAAC;CACD,MAAM,QAAQ,uBAAgD;EAC5D,MAAM,UAAU,OAAO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,CAAC;EACvF,MAAM,QAAQ,MAAM,mBAAmB,CAAC,EAAA,CAAG,QAAQ,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC;EAC7E,OAAO,YAAY,EACjB,iBAAiB,YAAY,CAAC,GAAG,MAAM,eAAe,SAAS,CAAC,IAAI,KACtE,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA,cAAc,OAAO,WAAW;EAChC,SAAS,YAAoB,SAAiB,OAAO,YAAY,EAAE,KAAK,CAAC;EACzE,WAAW,YAAoB,gBAAwB,OAAO,YAAY,EAAE,YAAY,CAAC;EACzF,YAAY,YAAoB,WAC9B,OAAO,YAAY,EAAE,cAAc,OAAO,CAAC;EAC7C,mBAAmB,YAAoB,UACrC,OAAO,YAAY,EAAE,cAAc,EAAE,0BAA0B,MAAM,EAAE,CAAC;EAC1E;EACA,SAAS,eAAuB;GAC9B,MAAM,QAAQ,OAAO,OAAO;GAC5B,IAAI,OAAO,OAAO,WAAW,MAAM,IAAI,UAAU;EACnD;CACF;AACF"}
@@ -105,7 +105,7 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
105
105
  editor.undo.runBatch(label, () => {
106
106
  for (const target of targets) {
107
107
  if (detach && editor.graph.getNode(target.id)?.boundVariables[detach]) editor.unbindVariable(target.id, detach);
108
- editor.updateNodeWithUndo(target.id, changes(target), label);
108
+ editor.updateNodeWithUndo(target.id, editor.layerChanges(target.id, changes(target)), label);
109
109
  }
110
110
  });
111
111
  }
@@ -304,11 +304,16 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
304
304
  beforePreview.clear();
305
305
  }
306
306
  for (const target of nodes.value) {
307
- if (!beforePreview.has(target.id)) beforePreview.set(target.id, {
308
- value: target[key],
309
- textStyleId: target.textStyleId
310
- });
311
- editor.updateNode(target.id, { [key]: value });
307
+ const own = editor.graph.getNode(target.id) ?? target;
308
+ if (!beforePreview.has(target.id)) {
309
+ const { textStyleId, styleRuns } = own;
310
+ beforePreview.set(target.id, {
311
+ value: own[key],
312
+ textStyleId,
313
+ styleRuns
314
+ });
315
+ }
316
+ editor.updateNode(target.id, editor.layerChanges(target.id, { [key]: value }));
312
317
  }
313
318
  }
314
319
  function commitProp(key, _value, previous) {
@@ -318,9 +323,11 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
318
323
  editor.undo.runBatch(`Change ${String(key)}`, () => {
319
324
  for (const target of targets) {
320
325
  const snapshot = snapshots.get(target.id);
326
+ const ranges = snapshot && editor.state.editingTextId !== target.id ? { styleRuns: snapshot.styleRuns } : {};
321
327
  editor.commitNodeUpdate(target.id, {
322
328
  [key]: snapshot ? snapshot.value : previous,
323
- ...snapshot ? { textStyleId: snapshot.textStyleId } : {}
329
+ ...snapshot ? { textStyleId: snapshot.textStyleId } : {},
330
+ ...ranges
324
331
  }, `Change ${String(key)}`);
325
332
  }
326
333
  });
@@ -330,9 +337,10 @@ function createTypographyActions({ editor, nodes, activeFormatting, supports, op
330
337
  }
331
338
  /** Puts back what a cancelled field previewed, as `cancelAxis` does for a font axis. */
332
339
  function cancelProp(key) {
333
- if (previewKey === key) for (const [id, before] of beforePreview) editor.updateNode(id, {
334
- [key]: before.value,
335
- textStyleId: before.textStyleId
340
+ if (previewKey === key) for (const [id, { value, textStyleId, styleRuns }] of beforePreview) editor.updateNode(id, {
341
+ [key]: value,
342
+ textStyleId,
343
+ styleRuns
336
344
  });
337
345
  previewKey = void 0;
338
346
  beforePreview.clear();