@formicoidea/labre-core 0.43.1 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/dist/_pkgs/affine-block-attachment/utils.js +4 -0
  2. package/dist/_pkgs/affine-block-bookmark/configs/toolbar.js +17 -4
  3. package/dist/_pkgs/affine-block-callout/commands/turn-callout-into.d.ts +43 -0
  4. package/dist/_pkgs/affine-block-callout/commands/turn-callout-into.js +109 -0
  5. package/dist/_pkgs/affine-block-callout/commands/turn-into-callout.d.ts +29 -0
  6. package/dist/_pkgs/affine-block-callout/commands/turn-into-callout.js +81 -0
  7. package/dist/_pkgs/affine-block-callout/configs/slash-menu.js +6 -4
  8. package/dist/_pkgs/affine-block-callout/configs/toolbar.d.ts +65 -0
  9. package/dist/_pkgs/affine-block-callout/configs/toolbar.js +178 -0
  10. package/dist/_pkgs/affine-block-callout/configs/turn-into.d.ts +8 -0
  11. package/dist/_pkgs/affine-block-callout/configs/turn-into.js +19 -0
  12. package/dist/_pkgs/affine-block-callout/translations.d.ts +4 -2
  13. package/dist/_pkgs/affine-block-callout/translations.js +4 -2
  14. package/dist/_pkgs/affine-block-callout/view.js +10 -1
  15. package/dist/_pkgs/affine-block-code/code-block-service.d.ts +13 -0
  16. package/dist/_pkgs/affine-block-code/code-block-service.js +26 -0
  17. package/dist/_pkgs/affine-block-code/code-block.d.ts +6 -0
  18. package/dist/_pkgs/affine-block-code/code-block.js +11 -2
  19. package/dist/_pkgs/affine-block-code/code-toolbar/components/lang-button.js +31 -8
  20. package/dist/_pkgs/affine-block-edgeless-text/edgeless-toolbar/config.d.ts +11 -0
  21. package/dist/_pkgs/affine-block-edgeless-text/svg-painter.d.ts +20 -0
  22. package/dist/_pkgs/affine-block-edgeless-text/svg-painter.js +76 -0
  23. package/dist/_pkgs/affine-block-edgeless-text/view.js +2 -0
  24. package/dist/_pkgs/affine-block-embed/configs/toolbar.js +11 -2
  25. package/dist/_pkgs/affine-block-embed/embed-iframe-block/configs/toolbar.js +11 -2
  26. package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/embed-edgeless-linked-doc-block.js +3 -1
  27. package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/configs/toolbar.js +7 -2
  28. package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/embed-edgeless-synced-doc-block.js +3 -1
  29. package/dist/_pkgs/affine-block-frame/commands.d.ts +27 -0
  30. package/dist/_pkgs/affine-block-frame/commands.js +49 -0
  31. package/dist/_pkgs/affine-block-frame/frame-manager.d.ts +16 -6
  32. package/dist/_pkgs/affine-block-frame/frame-manager.js +58 -22
  33. package/dist/_pkgs/affine-block-frame/frame-order.d.ts +43 -0
  34. package/dist/_pkgs/affine-block-frame/frame-order.js +93 -0
  35. package/dist/_pkgs/affine-block-frame/frame-tool.js +3 -1
  36. package/dist/_pkgs/affine-block-frame/index.d.ts +2 -0
  37. package/dist/_pkgs/affine-block-frame/index.js +2 -0
  38. package/dist/_pkgs/affine-block-frame/present/frame-order-menu.d.ts +10 -2
  39. package/dist/_pkgs/affine-block-frame/present/frame-order-menu.js +32 -18
  40. package/dist/_pkgs/affine-block-frame/view.js +6 -0
  41. package/dist/_pkgs/affine-block-image/utils.js +4 -1
  42. package/dist/_pkgs/affine-block-latex/adapters/markdown/preprocessor.d.ts +8 -0
  43. package/dist/_pkgs/affine-block-latex/adapters/markdown/preprocessor.js +9 -5
  44. package/dist/_pkgs/affine-block-note/configs/toolbar.d.ts +19 -0
  45. package/dist/_pkgs/affine-block-note/configs/toolbar.js +38 -23
  46. package/dist/_pkgs/affine-block-note/translations.d.ts +2 -1
  47. package/dist/_pkgs/affine-block-note/translations.js +14 -6
  48. package/dist/_pkgs/affine-block-root/configs/toolbar.js +48 -3
  49. package/dist/_pkgs/affine-block-root/edgeless/clipboard/clipboard.js +2 -1
  50. package/dist/_pkgs/affine-block-root/edgeless/clipboard/command.js +161 -83
  51. package/dist/_pkgs/affine-block-root/edgeless/clipboard/paste-order.d.ts +21 -0
  52. package/dist/_pkgs/affine-block-root/edgeless/clipboard/paste-order.js +85 -0
  53. package/dist/_pkgs/affine-block-root/edgeless/edgeless-root-block.d.ts +6 -0
  54. package/dist/_pkgs/affine-block-root/edgeless/edgeless-root-block.js +18 -1
  55. package/dist/_pkgs/affine-block-root/edgeless/utils/clone-utils.d.ts +9 -0
  56. package/dist/_pkgs/affine-block-root/edgeless/utils/clone-utils.js +28 -0
  57. package/dist/_pkgs/affine-block-root/keyboard/commands.js +9 -6
  58. package/dist/_pkgs/affine-block-root/preview/edgeless-root-preview-block.js +15 -2
  59. package/dist/_pkgs/affine-block-root/translations.d.ts +7 -2
  60. package/dist/_pkgs/affine-block-root/translations.js +10 -13
  61. package/dist/_pkgs/affine-block-surface/adapters/markdown/element-adapter/type.d.ts +1 -1
  62. package/dist/_pkgs/affine-block-surface/element-model/index.d.ts +1 -1
  63. package/dist/_pkgs/affine-block-surface/element-model/index.js +1 -1
  64. package/dist/_pkgs/affine-block-surface/extensions/audit.js +13 -61
  65. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/commands.d.ts +2 -0
  66. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/commands.js +71 -0
  67. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/index.d.ts +1 -0
  68. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/index.js +1 -0
  69. package/dist/_pkgs/affine-block-surface/extensions/clipboard-config.js +4 -0
  70. package/dist/_pkgs/affine-block-surface/extensions/crud-extension.js +4 -0
  71. package/dist/_pkgs/affine-block-surface/extensions/export-manager/export-manager.d.ts +12 -0
  72. package/dist/_pkgs/affine-block-surface/extensions/export-manager/export-manager.js +27 -7
  73. package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.d.ts +2 -1
  74. package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.js +22 -3
  75. package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.d.ts +6 -3
  76. package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.js +4 -2
  77. package/dist/_pkgs/affine-block-surface/extensions/export-svg/parts.d.ts +63 -0
  78. package/dist/_pkgs/affine-block-surface/extensions/export-svg/parts.js +67 -0
  79. package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.d.ts +62 -5
  80. package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.js +98 -18
  81. package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.d.ts +14 -0
  82. package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.js +82 -1
  83. package/dist/_pkgs/affine-block-surface/extensions/export-svg/toolbar.d.ts +2 -2
  84. package/dist/_pkgs/affine-block-surface/extensions/export-svg/toolbar.js +112 -10
  85. package/dist/_pkgs/affine-block-surface/extensions/export-svg/translations.d.ts +13 -0
  86. package/dist/_pkgs/affine-block-surface/extensions/export-svg/translations.js +33 -0
  87. package/dist/_pkgs/affine-block-surface/extensions/index.d.ts +3 -0
  88. package/dist/_pkgs/affine-block-surface/extensions/index.js +3 -0
  89. package/dist/_pkgs/affine-block-surface/extensions/reading-widget.d.ts +13 -6
  90. package/dist/_pkgs/affine-block-surface/extensions/reading-widget.js +26 -10
  91. package/dist/_pkgs/affine-block-surface/extensions/reading.d.ts +82 -6
  92. package/dist/_pkgs/affine-block-surface/extensions/reading.js +99 -21
  93. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/actions.d.ts +91 -0
  94. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/actions.js +285 -0
  95. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.d.ts +80 -0
  96. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.js +355 -0
  97. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/index.d.ts +3 -0
  98. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/index.js +3 -0
  99. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/tree.d.ts +137 -0
  100. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/tree.js +323 -0
  101. package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.d.ts +112 -4
  102. package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.js +86 -15
  103. package/dist/_pkgs/affine-block-surface/extensions/user-layers/actions.d.ts +76 -0
  104. package/dist/_pkgs/affine-block-surface/extensions/user-layers/actions.js +299 -0
  105. package/dist/_pkgs/affine-block-surface/extensions/user-layers/active-layer.d.ts +20 -0
  106. package/dist/_pkgs/affine-block-surface/extensions/user-layers/active-layer.js +34 -0
  107. package/dist/_pkgs/affine-block-surface/extensions/user-layers/commands.d.ts +67 -0
  108. package/dist/_pkgs/affine-block-surface/extensions/user-layers/commands.js +172 -0
  109. package/dist/_pkgs/affine-block-surface/extensions/user-layers/creation.d.ts +40 -0
  110. package/dist/_pkgs/affine-block-surface/extensions/user-layers/creation.js +69 -0
  111. package/dist/_pkgs/affine-block-surface/extensions/user-layers/index.d.ts +5 -0
  112. package/dist/_pkgs/affine-block-surface/extensions/user-layers/index.js +5 -0
  113. package/dist/_pkgs/affine-block-surface/extensions/user-layers/translations.d.ts +10 -0
  114. package/dist/_pkgs/affine-block-surface/extensions/user-layers/translations.js +14 -0
  115. package/dist/_pkgs/affine-block-surface/framework-background/facts.d.ts +55 -2
  116. package/dist/_pkgs/affine-block-surface/framework-background/facts.js +63 -1
  117. package/dist/_pkgs/affine-block-surface/framework-background/stacking.d.ts +16 -8
  118. package/dist/_pkgs/affine-block-surface/framework-background/stacking.js +26 -14
  119. package/dist/_pkgs/affine-block-surface/renderer/canvas-renderer.js +17 -3
  120. package/dist/_pkgs/affine-block-surface/renderer/dom-renderer.d.ts +3 -1
  121. package/dist/_pkgs/affine-block-surface/renderer/dom-renderer.js +22 -2
  122. package/dist/_pkgs/affine-block-surface/renderer/paint-predicate.d.ts +30 -0
  123. package/dist/_pkgs/affine-block-surface/renderer/paint-predicate.js +29 -0
  124. package/dist/_pkgs/affine-block-surface/surface-block.js +6 -0
  125. package/dist/_pkgs/affine-block-surface/surface-model.js +5 -0
  126. package/dist/_pkgs/affine-block-surface/surface-transformer.js +5 -0
  127. package/dist/_pkgs/affine-block-surface/tool/default-tool.js +28 -5
  128. package/dist/_pkgs/affine-block-surface/view.js +23 -1
  129. package/dist/_pkgs/affine-block-surface-ref/surface-ref-block.js +12 -2
  130. package/dist/_pkgs/affine-components/context-menu/button.js +14 -0
  131. package/dist/_pkgs/affine-components/filterable-list/index.js +30 -9
  132. package/dist/_pkgs/affine-components/icons/index.d.ts +0 -1
  133. package/dist/_pkgs/affine-components/icons/index.js +0 -1
  134. package/dist/_pkgs/affine-components/icons/text.d.ts +1 -0
  135. package/dist/_pkgs/affine-components/icons/text.js +11 -0
  136. package/dist/_pkgs/affine-components/portal/portal.d.ts +1 -1
  137. package/dist/_pkgs/affine-foundation/view.d.ts +8 -8
  138. package/dist/_pkgs/affine-fragment-adapter-panel/adapter-panel.d.ts +2 -2
  139. package/dist/_pkgs/affine-fragment-frame-panel/body/frame-panel-body.d.ts +34 -2
  140. package/dist/_pkgs/affine-fragment-frame-panel/body/frame-panel-body.js +194 -81
  141. package/dist/_pkgs/affine-fragment-frame-panel/card/frame-card.d.ts +7 -4
  142. package/dist/_pkgs/affine-fragment-frame-panel/card/frame-card.js +9 -24
  143. package/dist/_pkgs/affine-fragment-frame-panel/header/frame-panel-header.d.ts +1 -1
  144. package/dist/_pkgs/affine-fragment-frame-panel/header/frame-panel-header.js +8 -27
  145. package/dist/_pkgs/affine-fragment-frame-panel/index.d.ts +2 -0
  146. package/dist/_pkgs/affine-fragment-frame-panel/index.js +2 -0
  147. package/dist/_pkgs/affine-gfx-connector/element-renderer/connector-dom/index.js +3 -1
  148. package/dist/_pkgs/affine-gfx-connector/element-renderer/index.js +21 -4
  149. package/dist/_pkgs/affine-gfx-connector/text/edgeless-connector-label-editor.js +3 -2
  150. package/dist/_pkgs/affine-gfx-connector/toolbar/config.js +1 -1
  151. package/dist/_pkgs/affine-gfx-group/command/group-api.js +52 -1
  152. package/dist/_pkgs/affine-gfx-shape/element-renderer/shape/index.js +21 -3
  153. package/dist/_pkgs/affine-gfx-shape/text/edgeless-shape-text-editor.js +2 -0
  154. package/dist/_pkgs/affine-gfx-shape/toolbar/config.js +1 -1
  155. package/dist/_pkgs/affine-gfx-template/services/template-middlewares.d.ts +9 -0
  156. package/dist/_pkgs/affine-gfx-template/services/template-middlewares.js +23 -1
  157. package/dist/_pkgs/affine-gfx-template/services/template.js +2 -1
  158. package/dist/_pkgs/affine-gfx-text/edgeless-text-editor.js +2 -1
  159. package/dist/_pkgs/affine-gfx-text/element-renderer/index.js +20 -3
  160. package/dist/_pkgs/affine-gfx-text/element-renderer/utils.d.ts +67 -1
  161. package/dist/_pkgs/affine-gfx-text/element-renderer/utils.js +101 -0
  162. package/dist/_pkgs/affine-gfx-text/toolbar/actions.d.ts +11 -0
  163. package/dist/_pkgs/affine-gfx-text/toolbar/actions.js +53 -2
  164. package/dist/_pkgs/affine-gfx-text/toolbar/config.d.ts +11 -0
  165. package/dist/_pkgs/affine-gfx-text/toolbar/config.js +1 -1
  166. package/dist/_pkgs/affine-inline-preset/adapters/html/html-inline.d.ts +3 -0
  167. package/dist/_pkgs/affine-inline-preset/adapters/html/html-inline.js +31 -0
  168. package/dist/_pkgs/affine-inline-preset/adapters/html/inline-delta.d.ts +4 -0
  169. package/dist/_pkgs/affine-inline-preset/adapters/html/inline-delta.js +14 -0
  170. package/dist/_pkgs/affine-inline-preset/command/config.js +21 -3
  171. package/dist/_pkgs/affine-inline-preset/command/index.d.ts +1 -1
  172. package/dist/_pkgs/affine-inline-preset/command/index.js +1 -1
  173. package/dist/_pkgs/affine-inline-preset/command/text-style.d.ts +2 -1
  174. package/dist/_pkgs/affine-inline-preset/command/text-style.js +1 -0
  175. package/dist/_pkgs/affine-inline-preset/default-inline-manager.js +2 -1
  176. package/dist/_pkgs/affine-inline-preset/inline-spec.d.ts +4 -0
  177. package/dist/_pkgs/affine-inline-preset/inline-spec.js +14 -0
  178. package/dist/_pkgs/affine-inline-preset/translations.d.ts +2 -2
  179. package/dist/_pkgs/affine-inline-preset/translations.js +2 -2
  180. package/dist/_pkgs/affine-model/blocks/attachment/attachment-model.js +2 -0
  181. package/dist/_pkgs/affine-model/blocks/bookmark/bookmark-model.js +2 -0
  182. package/dist/_pkgs/affine-model/blocks/edgeless-text/edgeless-text-model.d.ts +1 -1
  183. package/dist/_pkgs/affine-model/blocks/edgeless-text/edgeless-text-model.js +2 -0
  184. package/dist/_pkgs/affine-model/blocks/embed/iframe/iframe-model.js +2 -0
  185. package/dist/_pkgs/affine-model/blocks/frame/frame-model.js +2 -0
  186. package/dist/_pkgs/affine-model/blocks/image/image-model.js +2 -0
  187. package/dist/_pkgs/affine-model/blocks/latex/latex-model.js +2 -0
  188. package/dist/_pkgs/affine-model/blocks/note/note-model.js +2 -0
  189. package/dist/_pkgs/affine-model/consts/text.d.ts +26 -0
  190. package/dist/_pkgs/affine-model/consts/text.js +25 -0
  191. package/dist/_pkgs/affine-model/elements/shape/shape.d.ts +6 -1
  192. package/dist/_pkgs/affine-model/elements/shape/shape.js +14 -1
  193. package/dist/_pkgs/affine-model/elements/text/text.d.ts +6 -1
  194. package/dist/_pkgs/affine-model/elements/text/text.js +13 -1
  195. package/dist/_pkgs/affine-model/utils/helper.js +2 -0
  196. package/dist/_pkgs/affine-model/utils/types.d.ts +2 -2
  197. package/dist/_pkgs/affine-rich-text/conversion.d.ts +25 -0
  198. package/dist/_pkgs/affine-rich-text/conversion.js +9 -0
  199. package/dist/_pkgs/affine-rich-text/index.d.ts +1 -1
  200. package/dist/_pkgs/affine-rich-text/index.js +1 -1
  201. package/dist/_pkgs/affine-shared/commands/model-crud/replace-selected-text-with-blocks.d.ts +1 -1
  202. package/dist/_pkgs/affine-shared/services/canvas-grid.d.ts +63 -0
  203. package/dist/_pkgs/affine-shared/services/canvas-grid.js +109 -0
  204. package/dist/_pkgs/affine-shared/services/canvas-local-visibility.d.ts +64 -0
  205. package/dist/_pkgs/affine-shared/services/canvas-local-visibility.js +192 -0
  206. package/dist/_pkgs/affine-shared/services/edit-props-store.d.ts +31 -4
  207. package/dist/_pkgs/affine-shared/services/edit-props-store.js +34 -0
  208. package/dist/_pkgs/affine-shared/services/editor-setting-service.d.ts +3 -0
  209. package/dist/_pkgs/affine-shared/services/editor-setting-service.js +7 -0
  210. package/dist/_pkgs/affine-shared/services/feature-flag-service.d.ts +4 -0
  211. package/dist/_pkgs/affine-shared/services/font-loader/config.d.ts +2 -2
  212. package/dist/_pkgs/affine-shared/services/font-loader/font-loader-service.d.ts +3 -3
  213. package/dist/_pkgs/affine-shared/services/index.d.ts +4 -1
  214. package/dist/_pkgs/affine-shared/services/index.js +4 -1
  215. package/dist/_pkgs/affine-shared/services/link-preview-service/link-preview-storage.d.ts +4 -4
  216. package/dist/_pkgs/affine-shared/services/outline-panel-service.d.ts +31 -0
  217. package/dist/_pkgs/affine-shared/services/outline-panel-service.js +17 -0
  218. package/dist/_pkgs/affine-shared/services/selection-pane-service.d.ts +44 -0
  219. package/dist/_pkgs/affine-shared/services/selection-pane-service.js +28 -0
  220. package/dist/_pkgs/affine-shared/services/telemetry-service/lifecycle.d.ts +69 -0
  221. package/dist/_pkgs/affine-shared/services/telemetry-service/telemetry-service.d.ts +2 -2
  222. package/dist/_pkgs/affine-shared/services/translation-service/chrome.d.ts +16 -0
  223. package/dist/_pkgs/affine-shared/services/translation-service/chrome.js +28 -0
  224. package/dist/_pkgs/affine-shared/styles/index.d.ts +1 -0
  225. package/dist/_pkgs/affine-shared/styles/index.js +1 -0
  226. package/dist/_pkgs/affine-shared/styles/panel-header.d.ts +31 -0
  227. package/dist/_pkgs/affine-shared/styles/panel-header.js +61 -0
  228. package/dist/_pkgs/affine-shared/styles/text.js +7 -7
  229. package/dist/_pkgs/affine-shared/types/index.d.ts +6 -0
  230. package/dist/_pkgs/affine-shared/utils/canvas-export-colors.d.ts +26 -0
  231. package/dist/_pkgs/affine-shared/utils/canvas-export-colors.js +127 -0
  232. package/dist/_pkgs/affine-shared/utils/file/filesys.d.ts +8 -11
  233. package/dist/_pkgs/affine-shared/utils/file/filesys.js +8 -11
  234. package/dist/_pkgs/affine-shared/utils/index.d.ts +3 -0
  235. package/dist/_pkgs/affine-shared/utils/index.js +3 -0
  236. package/dist/_pkgs/affine-shared/utils/label-mode.d.ts +47 -0
  237. package/dist/_pkgs/affine-shared/utils/label-mode.js +55 -0
  238. package/dist/_pkgs/affine-shared/utils/model/merge-to-code-model.js +7 -1
  239. package/dist/_pkgs/affine-shared/utils/model/transform-model.js +5 -0
  240. package/dist/_pkgs/affine-shared/utils/panel-reorder-drag.d.ts +85 -0
  241. package/dist/_pkgs/affine-shared/utils/panel-reorder-drag.js +162 -0
  242. package/dist/_pkgs/affine-widget-edgeless-selected-rect/utils.js +10 -3
  243. package/dist/_pkgs/affine-widget-edgeless-toolbar/catalogue/artefact-catalogue-widget.js +25 -49
  244. package/dist/_pkgs/affine-widget-edgeless-toolbar/effects.d.ts +4 -0
  245. package/dist/_pkgs/affine-widget-edgeless-toolbar/effects.js +4 -0
  246. package/dist/_pkgs/affine-widget-edgeless-toolbar/index.d.ts +4 -0
  247. package/dist/_pkgs/affine-widget-edgeless-toolbar/index.js +4 -0
  248. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/drop.d.ts +62 -0
  249. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/drop.js +94 -0
  250. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/labels.d.ts +17 -0
  251. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/labels.js +95 -0
  252. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-default.d.ts +10 -0
  253. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-default.js +31 -0
  254. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-tool.d.ts +26 -0
  255. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-tool.js +82 -0
  256. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-widget.d.ts +186 -0
  257. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-widget.js +1417 -0
  258. package/dist/_pkgs/affine-widget-edgeless-toolbar/translations.d.ts +52 -0
  259. package/dist/_pkgs/affine-widget-edgeless-toolbar/translations.js +161 -1
  260. package/dist/_pkgs/affine-widget-edgeless-toolbar/view.js +10 -0
  261. package/dist/_pkgs/affine-widget-note-slicer/note-slicer.js +7 -3
  262. package/dist/_pkgs/std/gfx/controller.d.ts +13 -0
  263. package/dist/_pkgs/std/gfx/controller.js +22 -2
  264. package/dist/_pkgs/std/gfx/grid.d.ts +31 -2
  265. package/dist/_pkgs/std/gfx/index.d.ts +3 -1
  266. package/dist/_pkgs/std/gfx/index.js +3 -1
  267. package/dist/_pkgs/std/gfx/interactivity/manager.js +7 -0
  268. package/dist/_pkgs/std/gfx/layer.js +73 -5
  269. package/dist/_pkgs/std/gfx/local-visibility.d.ts +88 -0
  270. package/dist/_pkgs/std/gfx/local-visibility.js +217 -0
  271. package/dist/_pkgs/std/gfx/model/gfx-block-model.d.ts +13 -0
  272. package/dist/_pkgs/std/gfx/model/surface/element-model.d.ts +34 -0
  273. package/dist/_pkgs/std/gfx/model/surface/element-model.js +65 -1
  274. package/dist/_pkgs/std/gfx/model/surface/surface-model.d.ts +27 -0
  275. package/dist/_pkgs/std/gfx/model/surface/surface-model.js +43 -0
  276. package/dist/_pkgs/std/gfx/model/surface/user-layers.d.ts +68 -0
  277. package/dist/_pkgs/std/gfx/model/surface/user-layers.js +127 -0
  278. package/dist/_pkgs/std/scope/std-scope.d.ts +1 -1
  279. package/dist/_pkgs/std/utils/layer.d.ts +10 -0
  280. package/dist/_pkgs/std/utils/layer.js +64 -13
  281. package/dist/_pkgs/std/view/element/gfx-block-component.js +10 -2
  282. package/dist/commands.js +6 -1
  283. package/dist/host-panels.d.ts +90 -0
  284. package/dist/host-panels.js +111 -0
  285. package/dist/translations.js +10 -6
  286. package/package.json +13 -2
  287. package/dist/_pkgs/affine-components/icons/file-icons-rc.d.ts +0 -1
  288. package/dist/_pkgs/affine-components/icons/file-icons-rc.js +0 -130
  289. package/dist/_pkgs/affine-fragment-frame-panel/utils/drag.d.ts +0 -27
  290. package/dist/_pkgs/affine-fragment-frame-panel/utils/drag.js +0 -96
  291. package/dist/_pkgs/affine-shared/services/sidebar-service.d.ts +0 -8
  292. package/dist/_pkgs/affine-shared/services/sidebar-service.js +0 -7
  293. package/dist/_pkgs/affine-shared/test-utils/affine-template.d.ts +0 -6
  294. package/dist/_pkgs/affine-shared/test-utils/affine-template.js +0 -258
  295. package/dist/_pkgs/affine-shared/test-utils/affine-test-utils.d.ts +0 -8
  296. package/dist/_pkgs/affine-shared/test-utils/affine-test-utils.js +0 -81
  297. package/dist/_pkgs/affine-shared/test-utils/create-test-host.d.ts +0 -23
  298. package/dist/_pkgs/affine-shared/test-utils/create-test-host.js +0 -187
  299. package/dist/_pkgs/affine-shared/test-utils/index.d.ts +0 -3
  300. package/dist/_pkgs/affine-shared/test-utils/index.js +0 -3
@@ -0,0 +1,127 @@
1
+ /**
2
+ * The colour functions html2canvas 1.4.1 cannot parse. Its parser knows hex,
3
+ * `rgb[a]()`, `hsl[a]()` and keywords and THROWS on anything else, aborting
4
+ * the whole export. `color(` is what Chrome computes `color-mix(in srgb, …)`
5
+ * to; `color-mix` and `light-dark` are here for a computed value that keeps
6
+ * them. `color-mix` precedes `color` so the longer name wins.
7
+ */
8
+ const MODERN_COLOR_FUNCTION = /\b(?:oklch|oklab|lch|lab|hwb|color-mix|color|light-dark)\(/gi;
9
+ /**
10
+ * Every computed property html2canvas reads a colour from. Shorthands are
11
+ * absent on purpose: html2canvas reads the longhands.
12
+ */
13
+ const COLOR_PROPERTIES = [
14
+ 'color',
15
+ 'background-color',
16
+ 'background-image',
17
+ 'border-top-color',
18
+ 'border-right-color',
19
+ 'border-bottom-color',
20
+ 'border-left-color',
21
+ 'outline-color',
22
+ 'text-decoration-color',
23
+ '-webkit-text-stroke-color',
24
+ 'text-shadow',
25
+ 'box-shadow',
26
+ 'caret-color',
27
+ 'fill',
28
+ 'stroke',
29
+ ];
30
+ let probe;
31
+ const resolved = new Map();
32
+ /**
33
+ * The browser's own reading of a colour, through a 1×1 canvas: paint it, read
34
+ * the pixel back. Reading `fillStyle` back is not enough — recent engines keep
35
+ * the modern syntax there. Cached per string, since a theme repeats a handful
36
+ * of colours across every node. Where no 2D context exists the colour comes
37
+ * back unchanged: there is nothing to rasterise with either.
38
+ */
39
+ const resolveColorThroughCanvas = color => {
40
+ const cached = resolved.get(color);
41
+ if (cached !== undefined)
42
+ return cached;
43
+ probe ??= Object.assign(document.createElement('canvas'), {
44
+ width: 1,
45
+ height: 1,
46
+ }).getContext('2d', { willReadFrequently: true });
47
+ if (!probe)
48
+ return color;
49
+ probe.clearRect(0, 0, 1, 1);
50
+ probe.fillStyle = color;
51
+ probe.fillRect(0, 0, 1, 1);
52
+ const [r, g, b, a] = probe.getImageData(0, 0, 1, 1).data;
53
+ const legacy = a === 255
54
+ ? `rgb(${r}, ${g}, ${b})`
55
+ : `rgba(${r}, ${g}, ${b}, ${Number((a / 255).toFixed(3))})`;
56
+ resolved.set(color, legacy);
57
+ return legacy;
58
+ };
59
+ /**
60
+ * `value` with every modern colour function in it replaced by what `resolve`
61
+ * makes of it — the whole of `oklch(0.7 0.1 200)`, or each colour of a
62
+ * `box-shadow` list. A value with none comes back as the same string. Also
63
+ * what the `backgroundColor` option of html2canvas goes through.
64
+ */
65
+ export function toLegacyColors(value, resolve = resolveColorThroughCanvas) {
66
+ MODERN_COLOR_FUNCTION.lastIndex = 0;
67
+ let match = MODERN_COLOR_FUNCTION.exec(value);
68
+ if (!match)
69
+ return value;
70
+ let out = '';
71
+ let from = 0;
72
+ while (match) {
73
+ // Balanced parentheses: `color-mix()` nests whole colours.
74
+ let end = match.index + match[0].length;
75
+ for (let depth = 1; end < value.length && depth > 0; end++) {
76
+ if (value[end] === '(')
77
+ depth++;
78
+ else if (value[end] === ')')
79
+ depth--;
80
+ }
81
+ out +=
82
+ value.slice(from, match.index) + resolve(value.slice(match.index, end));
83
+ from = end;
84
+ MODERN_COLOR_FUNCTION.lastIndex = end;
85
+ match = MODERN_COLOR_FUNCTION.exec(value);
86
+ }
87
+ return out + value.slice(from);
88
+ }
89
+ /**
90
+ * Rewrites, inline on the html2canvas CLONE, every computed colour html2canvas
91
+ * would choke on, so a host theme in `oklch()` (or the library's own
92
+ * `color-mix()`) cannot abort a PNG/PDF export or a "copy as image". Call it
93
+ * first in every `onclone`.
94
+ *
95
+ * html2canvas parses the computed style of the captured subtree AND of the
96
+ * clone's `<html>` and `<body>` (their background), so those two are covered
97
+ * too; shadow roots are already flattened into the clone by then. The resolved
98
+ * value is written over whatever produced it — a CSS variable, a stylesheet
99
+ * rule — as an `!important` inline declaration, which is what the computed
100
+ * style then reports. Every value is read before any is written, so the
101
+ * cascade is recomputed once rather than once per node.
102
+ */
103
+ export function normalizeCanvasExportColors(documentClone, subtree, resolve = resolveColorThroughCanvas) {
104
+ const view = documentClone.defaultView ?? window;
105
+ const nodes = new Set([
106
+ documentClone.documentElement,
107
+ documentClone.body,
108
+ subtree,
109
+ ...subtree.querySelectorAll('*'),
110
+ ]);
111
+ const writes = [];
112
+ for (const node of nodes) {
113
+ const style = node?.style;
114
+ if (!node || !style)
115
+ continue;
116
+ const computed = view.getComputedStyle(node);
117
+ for (const property of COLOR_PROPERTIES) {
118
+ const value = computed.getPropertyValue(property);
119
+ const legacy = toLegacyColors(value, resolve);
120
+ if (legacy !== value)
121
+ writes.push([style, property, legacy]);
122
+ }
123
+ }
124
+ for (const [style, property, legacy] of writes) {
125
+ style.setProperty(property, legacy, 'important');
126
+ }
127
+ }
@@ -55,17 +55,14 @@ export declare function getImageFilesFromLocal(): Promise<File[]>;
55
55
  /**
56
56
  * A name a file system will accept, minus the extension.
57
57
  *
58
- * The sanitiser the framework exports each wrote for themselves
59
- * (`wardleySafeFilename`, `c4SafeFilename`, BPMN's) — same five steps, same
60
- * 120-character ceiling — lifted here for the callers that belong to no
61
- * framework at all. The generic SVG export (ADR 0025) is the first of them: it
62
- * writes a file for ELEVEN kinds of board, so it has no framework's fallback to
63
- * borrow and takes one as a parameter instead.
64
- *
65
- * The three framework copies stay where they are: each is part of an
66
- * interchange capability with its own format id and its own declared fallback
67
- * (`map`, `board`, `process`), and rewriting them to call this one would touch
68
- * three exported APIs for no behaviour change.
58
+ * Every file the library writes is named through it: the generic SVG export
59
+ * (ADR 0025), which writes a file for every kind of board and so takes its
60
+ * fallback as a parameter, and the framework interchanges, whose exported
61
+ * sanitisers (`wardleySafeFilename`, `c4SafeFilename`, `bpmnSafeFilename`,
62
+ * `umlSafeFilename`) keep their names and signatures and only supply their own
63
+ * fallback word. They were verbatim copies of this rule;
64
+ * `safe-filename-parity.unit.spec.ts` in `packages/affine/all` holds every one
65
+ * to it, because what a downloaded file is called is visible behaviour.
69
66
  */
70
67
  export declare function safeFilename(raw: string | undefined, fallback: string): string;
71
68
  export declare function downloadBlob(blob: Blob, name: string): void;
@@ -191,17 +191,14 @@ export async function getImageFilesFromLocal() {
191
191
  /**
192
192
  * A name a file system will accept, minus the extension.
193
193
  *
194
- * The sanitiser the framework exports each wrote for themselves
195
- * (`wardleySafeFilename`, `c4SafeFilename`, BPMN's) — same five steps, same
196
- * 120-character ceiling — lifted here for the callers that belong to no
197
- * framework at all. The generic SVG export (ADR 0025) is the first of them: it
198
- * writes a file for ELEVEN kinds of board, so it has no framework's fallback to
199
- * borrow and takes one as a parameter instead.
200
- *
201
- * The three framework copies stay where they are: each is part of an
202
- * interchange capability with its own format id and its own declared fallback
203
- * (`map`, `board`, `process`), and rewriting them to call this one would touch
204
- * three exported APIs for no behaviour change.
194
+ * Every file the library writes is named through it: the generic SVG export
195
+ * (ADR 0025), which writes a file for every kind of board and so takes its
196
+ * fallback as a parameter, and the framework interchanges, whose exported
197
+ * sanitisers (`wardleySafeFilename`, `c4SafeFilename`, `bpmnSafeFilename`,
198
+ * `umlSafeFilename`) keep their names and signatures and only supply their own
199
+ * fallback word. They were verbatim copies of this rule;
200
+ * `safe-filename-parity.unit.spec.ts` in `packages/affine/all` holds every one
201
+ * to it, because what a downloaded file is called is visible behaviour.
205
202
  */
206
203
  export function safeFilename(raw, fallback) {
207
204
  const safe = (raw ?? '')
@@ -1,5 +1,6 @@
1
1
  export * from './auto-scroll.js';
2
2
  export * from './button-popper.js';
3
+ export * from './canvas-export-colors.js';
3
4
  export * from './collapsed/index.js';
4
5
  export * from './computing.js';
5
6
  export * from './dnd/index.js';
@@ -13,9 +14,11 @@ export * from './fractional-indexing.js';
13
14
  export * from './image.js';
14
15
  export * from './insert.js';
15
16
  export * from './is-abort-error.js';
17
+ export * from './label-mode.js';
16
18
  export * from './link-preview-refresh.js';
17
19
  export * from './math.js';
18
20
  export * from './model/index.js';
21
+ export * from './panel-reorder-drag.js';
19
22
  export * from './popper-position.js';
20
23
  export * from './print-to-pdf.js';
21
24
  export * from './reference.js';
@@ -1,5 +1,6 @@
1
1
  export * from './auto-scroll.js';
2
2
  export * from './button-popper.js';
3
+ export * from './canvas-export-colors.js';
3
4
  export * from './collapsed/index.js';
4
5
  export * from './computing.js';
5
6
  export * from './dnd/index.js';
@@ -13,9 +14,11 @@ export * from './fractional-indexing.js';
13
14
  export * from './image.js';
14
15
  export * from './insert.js';
15
16
  export * from './is-abort-error.js';
17
+ export * from './label-mode.js';
16
18
  export * from './link-preview-refresh.js';
17
19
  export * from './math.js';
18
20
  export * from './model/index.js';
21
+ export * from './panel-reorder-drag.js';
19
22
  export * from './popper-position.js';
20
23
  export * from './print-to-pdf.js';
21
24
  export * from './reference.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Whether a catalogue symbol can carry its name INSIDE it, or the name must
3
+ * GRAVITATE around it (rule R38, `docs/add-a-framework/02-framework-rules.md`;
4
+ * ADR 0029).
5
+ *
6
+ * The rule has one criterion, the symbol's size: a normal-size text — 18 model
7
+ * units, the size Wardley's prominent labels and BPMN's inner text use — of two
8
+ * five-letter words must fit legibly inside the shape at its canonical creation
9
+ * size, without enlarging it. If it does not, the label is a free text element
10
+ * grouped with the symbol (R16) instead of the shape's own `text`.
11
+ *
12
+ * The test is arithmetic on the preset, so a framework's spec can assert its
13
+ * label mode for every kind without a canvas:
14
+ *
15
+ * - the inner box is the shape minus the native shape text insets
16
+ * (`SHAPE_TEXT_VERTICAL_PADDING` = 10, `SHAPE_TEXT_PADDING` = 20 in
17
+ * `@labre/affine-model`, the defaults below);
18
+ * - a non-rectangular silhouette only offers the rectangle inscribed in it:
19
+ * ≈ 1/√2 of each side for an ellipse (0.7), half of each side for a diamond;
20
+ * - the probe is "Hello World" (two five-letter words and a space), set on one
21
+ * line or broken into two lines of five letters; it fits if either layout
22
+ * fits.
23
+ *
24
+ * Average advance 0.5 em: Inter's advances for the probe itself ("Hello World"
25
+ * ≈ 5.4 em) average 0.49 em, which is what decides a 140-wide annotation at 18
26
+ * units — a generic 0.55 em prose average would reject a box the probe
27
+ * visibly fits. Line height 1.2 em, the renderer's default for single-spaced
28
+ * canvas text.
29
+ *
30
+ * ponytail: no real font metrics — a fixed per-glyph average and a fixed line
31
+ * height, so a shape within a few units of the threshold may be judged wrongly
32
+ * for a font other than Inter. The upgrade is to measure the probe with the
33
+ * shape renderer's `wrapText` / `getLineHeight` in a browser-mode spec.
34
+ */
35
+ export interface InscribedLabelProbe {
36
+ /** Canonical creation width, model units. */
37
+ w: number;
38
+ /** Canonical creation height, model units. */
39
+ h: number;
40
+ /** Native shape type: `ellipse`, `diamond`, `rect`, or a polygon name. */
41
+ shapeType: string;
42
+ /** Reference size of the fit test, not a mandate for the label's own size. */
43
+ fontSize?: number;
44
+ /** `[vertical, horizontal]` inset, as the native shape pads its text. */
45
+ padding?: [number, number];
46
+ }
47
+ export declare const fitsInscribedLabel: ({ w, h, shapeType, fontSize, padding, }: InscribedLabelProbe) => boolean;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Whether a catalogue symbol can carry its name INSIDE it, or the name must
3
+ * GRAVITATE around it (rule R38, `docs/add-a-framework/02-framework-rules.md`;
4
+ * ADR 0029).
5
+ *
6
+ * The rule has one criterion, the symbol's size: a normal-size text — 18 model
7
+ * units, the size Wardley's prominent labels and BPMN's inner text use — of two
8
+ * five-letter words must fit legibly inside the shape at its canonical creation
9
+ * size, without enlarging it. If it does not, the label is a free text element
10
+ * grouped with the symbol (R16) instead of the shape's own `text`.
11
+ *
12
+ * The test is arithmetic on the preset, so a framework's spec can assert its
13
+ * label mode for every kind without a canvas:
14
+ *
15
+ * - the inner box is the shape minus the native shape text insets
16
+ * (`SHAPE_TEXT_VERTICAL_PADDING` = 10, `SHAPE_TEXT_PADDING` = 20 in
17
+ * `@labre/affine-model`, the defaults below);
18
+ * - a non-rectangular silhouette only offers the rectangle inscribed in it:
19
+ * ≈ 1/√2 of each side for an ellipse (0.7), half of each side for a diamond;
20
+ * - the probe is "Hello World" (two five-letter words and a space), set on one
21
+ * line or broken into two lines of five letters; it fits if either layout
22
+ * fits.
23
+ *
24
+ * Average advance 0.5 em: Inter's advances for the probe itself ("Hello World"
25
+ * ≈ 5.4 em) average 0.49 em, which is what decides a 140-wide annotation at 18
26
+ * units — a generic 0.55 em prose average would reject a box the probe
27
+ * visibly fits. Line height 1.2 em, the renderer's default for single-spaced
28
+ * canvas text.
29
+ *
30
+ * ponytail: no real font metrics — a fixed per-glyph average and a fixed line
31
+ * height, so a shape within a few units of the threshold may be judged wrongly
32
+ * for a font other than Inter. The upgrade is to measure the probe with the
33
+ * shape renderer's `wrapText` / `getLineHeight` in a browser-mode spec.
34
+ */
35
+ /** The probe: two five-letter words, as in "Hello World". */
36
+ const PROBE_WORD_LENGTH = 5;
37
+ const PROBE_ONE_LINE_LENGTH = 2 * PROBE_WORD_LENGTH + 1;
38
+ /** Average Inter advance over the probe, in em. */
39
+ const AVERAGE_ADVANCE_EM = 0.5;
40
+ const LINE_HEIGHT_EM = 1.2;
41
+ /** Share of each side of the inner box a silhouette leaves usable. */
42
+ const INSCRIBED_FACTOR = Object.assign(Object.create(null), { ellipse: 0.7, diamond: 0.5 });
43
+ export const fitsInscribedLabel = ({ w, h, shapeType, fontSize = 18, padding = [10, 20], }) => {
44
+ const factor = INSCRIBED_FACTOR[shapeType] ?? 1;
45
+ const innerW = (w - 2 * padding[1]) * factor;
46
+ const innerH = (h - 2 * padding[0]) * factor;
47
+ if (innerW <= 0 || innerH <= 0)
48
+ return false;
49
+ const advance = AVERAGE_ADVANCE_EM * fontSize;
50
+ const lineHeight = LINE_HEIGHT_EM * fontSize;
51
+ const oneLine = PROBE_ONE_LINE_LENGTH * advance <= innerW && lineHeight <= innerH;
52
+ if (oneLine)
53
+ return true;
54
+ return PROBE_WORD_LENGTH * advance <= innerW && 2 * lineHeight <= innerH;
55
+ };
@@ -18,7 +18,13 @@ export function mergeToCodeModel(models) {
18
18
  })
19
19
  .filter(Boolean)
20
20
  .join('\n');
21
- models.forEach(model => doc.deleteBlock(model));
21
+ // Add first and delete only once the code block exists: `addBlock` returns
22
+ // an id even when the parent rejected the flavour (a callout only takes
23
+ // paragraphs and lists), and deleting first lost the text (#418).
22
24
  const id = doc.addBlock('affine:code', { text: new Text(text) }, parent, index);
25
+ if (!doc.getModelById(id)) {
26
+ return null;
27
+ }
28
+ models.forEach(model => doc.deleteBlock(model));
23
29
  return id;
24
30
  }
@@ -12,7 +12,12 @@ export function transformModel(model, flavour, props) {
12
12
  const index = parent.children.indexOf(model);
13
13
  // Sometimes the new block can not be added due to some reason, e.g. invalid schema check.
14
14
  // So we need to try to add the new block first, and if it fails, we will not delete the old block.
15
+ // `addBlock` returns an id even when the schema check threw (`transact`
16
+ // swallows it), so only `getModelById` proves the block exists (#418).
15
17
  const id = doc.addBlock(flavour, blockProps, parent, index);
18
+ if (!doc.getModelById(id)) {
19
+ return null;
20
+ }
16
21
  doc.deleteBlock(model, {
17
22
  deleteChildren: false,
18
23
  });
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The ONE drag-to-reorder gesture of the side panels (ADR 0034):
3
+ * the frame panel's cards and the selection pane's rows.
4
+ *
5
+ * Why it exists: the two panels each wrote their own drag and the two
6
+ * drifted. The frame panel's (`fragments/frame-panel/src/utils/drag.ts`, now
7
+ * deleted) ran on mouse events, never refused a read-only document, drew the
8
+ * drop line at 0 for a drop after the last card, and had no way out but the
9
+ * release. The selection pane's (hand-written in `selection-pane-widget.ts`)
10
+ * ran on pointer events, refused read-only and showed a `not-allowed` cursor,
11
+ * and swallowed Escape. Only the threshold was shared, and a comment held the
12
+ * rest together. Both panels now hand this controller what is theirs — the
13
+ * rows, the drop rule, the ghost, the write — and it owns the gesture:
14
+ *
15
+ * - pointer events, listened to on the document in the CAPTURE phase from the
16
+ * press to the end, so a panel that stops its own events' propagation (the
17
+ * pane does, to keep the canvas out of them) still sees every move;
18
+ * - a read-only document never starts one: the press adds no listener;
19
+ * - a press becomes a drag past {@link panelDragStarted} — called here and
20
+ * nowhere else — and only then is anything picked up;
21
+ * - over the whole viewport, a mask carries the cursor: `grabbing` over a gap
22
+ * that takes the drop, `not-allowed` elsewhere (its geometry stays in each
23
+ * panel's stylesheet, the controller sets the cursor and nothing else);
24
+ * - Escape or `pointercancel` CANCELS: nothing is written, the release that
25
+ * follows writes nothing, and the Escape does not reach the panel (which
26
+ * would close it);
27
+ * - the click that follows a release or a cancel is not a click: the panel
28
+ * asks {@link PanelReorderDrag.consumeSwallowedClick} in its click handler.
29
+ *
30
+ * Multi-selection is the panel's business: `onPickUp` decides what moves,
31
+ * `dropAt` skips the rows that move with it.
32
+ */
33
+ /** A pointer position, in client coordinates. */
34
+ export interface PanelDragPoint {
35
+ clientX: number;
36
+ clientY: number;
37
+ }
38
+ export interface PanelReorderDragOptions<Drop> {
39
+ /** Read at the press: a read-only document never starts a drag. */
40
+ readonly: () => boolean;
41
+ /** The rows, top first, read LIVE at every move. */
42
+ rows: () => readonly HTMLElement[];
43
+ /** The box a drop must land in; outside it, or `null`, refuses. */
44
+ bounds: () => HTMLElement | null;
45
+ /** The press became a drag: select what moves, build the ghost. */
46
+ onPickUp: (press: PanelDragPoint) => void;
47
+ /**
48
+ * What a release at the gap `gap` — before `rows()[gap]`, `rows().length`
49
+ * after the last — would do, or `null` to refuse it.
50
+ */
51
+ dropAt: (gap: number, point: PanelDragPoint) => Drop | null;
52
+ /** Every move of a drag: draw the ghost at `ghost`, the line for `drop`. */
53
+ onMove: (drop: Drop | null, ghost: PanelDragPoint) => void;
54
+ /** The release, over a gap that takes it. Before `onEnd`. */
55
+ onDrop: (drop: Drop) => void;
56
+ /** A drag ended — dropped, refused, cancelled or disposed. Always last. */
57
+ onEnd: () => void;
58
+ /** The cursor mask: appended to `host()` on pick-up, removed at the end. */
59
+ mask: {
60
+ host: () => ParentNode | null;
61
+ className: string;
62
+ testId?: string;
63
+ };
64
+ /** Carries `data-drag="valid" | "invalid"` while a drag is live. */
65
+ stateHost?: () => HTMLElement | null;
66
+ }
67
+ export interface PanelReorderDrag {
68
+ /** Hand it the row's `pointerdown`. */
69
+ press(event: PointerEvent): void;
70
+ /**
71
+ * Whether the click being handled follows a drag's release or cancel —
72
+ * answered `true` once, then `false`.
73
+ */
74
+ consumeSwallowedClick(): boolean;
75
+ /** Whether a press has become a drag that has not ended yet. */
76
+ readonly dragging: boolean;
77
+ /** Ends a live drag (`onEnd`, nothing written) and removes the listeners. */
78
+ dispose(): void;
79
+ }
80
+ /**
81
+ * The gap a pointer at `clientY` is over: how many rows have their middle
82
+ * above it. `0` is before the first row, `rects.length` after the last.
83
+ */
84
+ export declare function panelReorderGap(rects: readonly DOMRect[], clientY: number): number;
85
+ export declare function createPanelReorderDrag<Drop>(options: PanelReorderDragOptions<Drop>): PanelReorderDrag;
@@ -0,0 +1,162 @@
1
+ import { panelDragStarted } from '../styles/panel-header.js';
2
+ /**
3
+ * The gap a pointer at `clientY` is over: how many rows have their middle
4
+ * above it. `0` is before the first row, `rects.length` after the last.
5
+ */
6
+ export function panelReorderGap(rects, clientY) {
7
+ let gap = 0;
8
+ for (const rect of rects) {
9
+ if (clientY > rect.top + rect.height / 2)
10
+ gap++;
11
+ }
12
+ return gap;
13
+ }
14
+ export function createPanelReorderDrag(options) {
15
+ let start = null;
16
+ let dragging = false;
17
+ let listening = null;
18
+ let mask = null;
19
+ let swallowClick = false;
20
+ const point = (event) => ({
21
+ clientX: event.clientX,
22
+ clientY: event.clientY,
23
+ });
24
+ const resolve = (at) => {
25
+ const bounds = options.bounds();
26
+ if (!bounds)
27
+ return null;
28
+ const box = bounds.getBoundingClientRect();
29
+ if (at.clientX < box.left ||
30
+ at.clientX > box.right ||
31
+ at.clientY < box.top ||
32
+ at.clientY > box.bottom) {
33
+ return null;
34
+ }
35
+ const rects = options.rows().map(row => row.getBoundingClientRect());
36
+ return options.dropAt(panelReorderGap(rects, at.clientY), at);
37
+ };
38
+ const show = (drop) => {
39
+ if (mask)
40
+ mask.style.cursor = drop ? 'grabbing' : 'not-allowed';
41
+ const host = options.stateHost?.();
42
+ if (host)
43
+ host.dataset.drag = drop ? 'valid' : 'invalid';
44
+ };
45
+ const unlisten = () => {
46
+ if (!listening)
47
+ return;
48
+ listening.removeEventListener('pointermove', onPointerMove, true);
49
+ listening.removeEventListener('pointerup', onPointerUp, true);
50
+ listening.removeEventListener('pointercancel', onPointerCancel, true);
51
+ listening.removeEventListener('keydown', onKeydown, true);
52
+ listening = null;
53
+ };
54
+ /** Back to idle; `onEnd` only when something was picked up. */
55
+ const finish = () => {
56
+ unlisten();
57
+ start = null;
58
+ if (!dragging)
59
+ return;
60
+ dragging = false;
61
+ mask?.remove();
62
+ mask = null;
63
+ const host = options.stateHost?.();
64
+ if (host)
65
+ delete host.dataset.drag;
66
+ options.onEnd();
67
+ };
68
+ const cancel = () => {
69
+ if (dragging)
70
+ swallowClick = true;
71
+ finish();
72
+ };
73
+ const pickUp = (event) => {
74
+ dragging = true;
75
+ const host = options.mask.host();
76
+ if (host) {
77
+ const doc = event.target?.ownerDocument ?? document;
78
+ mask = doc.createElement('div');
79
+ mask.className = options.mask.className;
80
+ if (options.mask.testId)
81
+ mask.dataset.testid = options.mask.testId;
82
+ mask.style.cursor = 'grabbing';
83
+ host.append(mask);
84
+ }
85
+ options.onPickUp({ clientX: start.x, clientY: start.y });
86
+ };
87
+ function onPointerMove(event) {
88
+ if (!start)
89
+ return;
90
+ if (!dragging) {
91
+ if (!panelDragStarted(start, { x: event.clientX, y: event.clientY })) {
92
+ return;
93
+ }
94
+ pickUp(event);
95
+ }
96
+ const at = point(event);
97
+ const drop = resolve(at);
98
+ show(drop);
99
+ options.onMove(drop, at);
100
+ }
101
+ function onPointerUp(event) {
102
+ if (!dragging) {
103
+ // A press that never became a drag: the click that follows is a click.
104
+ finish();
105
+ return;
106
+ }
107
+ const drop = resolve(point(event));
108
+ swallowClick = true;
109
+ try {
110
+ if (drop !== null)
111
+ options.onDrop(drop);
112
+ }
113
+ finally {
114
+ finish();
115
+ }
116
+ }
117
+ function onPointerCancel() {
118
+ cancel();
119
+ }
120
+ function onKeydown(event) {
121
+ if (event.key !== 'Escape')
122
+ return;
123
+ if (!dragging) {
124
+ // A press still under the threshold: forget it, and let the Escape do
125
+ // what it does in the panel.
126
+ finish();
127
+ return;
128
+ }
129
+ event.stopPropagation();
130
+ event.preventDefault();
131
+ cancel();
132
+ }
133
+ return {
134
+ press(event) {
135
+ // Any new press clears a click left armed by a release or a cancel
136
+ // that no click followed (released over another element).
137
+ swallowClick = false;
138
+ if (event.button !== 0 || start)
139
+ return;
140
+ if (options.readonly())
141
+ return;
142
+ start = { x: event.clientX, y: event.clientY };
143
+ const doc = event.target?.ownerDocument ?? document;
144
+ doc.addEventListener('pointermove', onPointerMove, true);
145
+ doc.addEventListener('pointerup', onPointerUp, true);
146
+ doc.addEventListener('pointercancel', onPointerCancel, true);
147
+ doc.addEventListener('keydown', onKeydown, true);
148
+ listening = doc;
149
+ },
150
+ consumeSwallowedClick() {
151
+ const swallowed = swallowClick;
152
+ swallowClick = false;
153
+ return swallowed;
154
+ },
155
+ get dragging() {
156
+ return dragging;
157
+ },
158
+ dispose() {
159
+ finish();
160
+ },
161
+ };
162
+ }
@@ -1,4 +1,4 @@
1
- import { EdgelessCRUDIdentifier, isNoteBlock, Overlay, } from '../affine-block-surface/index.js';
1
+ import { applyCreationLayer, EdgelessCRUDIdentifier, isNoteBlock, Overlay, sourceLayerOf, } from '../affine-block-surface/index.js';
2
2
  import { ShapeFactory } from '../affine-gfx-shape/index.js';
3
3
  import { getShapeRadius, getShapeType, GroupElementModel, ShapeElementModel, } from '../affine-model/index.js';
4
4
  import { getChromeAccentColor } from '../affine-shared/services/index.js';
@@ -230,6 +230,9 @@ export function createEdgelessElement(edgeless, current, bound) {
230
230
  ...current.serialize(),
231
231
  text: new Y.Text(),
232
232
  xywh: bound.serialize(),
233
+ // `serialize()` names no layer for a default-layer shape: ask for the
234
+ // source's explicitly, or the clone lands in the active layer.
235
+ layer: sourceLayerOf(current),
233
236
  });
234
237
  if (!id)
235
238
  return null;
@@ -237,12 +240,16 @@ export function createEdgelessElement(edgeless, current, bound) {
237
240
  }
238
241
  else if (isNoteBlock(current)) {
239
242
  const { store } = edgeless;
240
- id = store.addBlock('affine:note', {
243
+ const props = {
241
244
  background: current.props.background,
242
245
  displayMode: current.props.displayMode,
243
246
  edgeless: current.props.edgeless,
244
247
  xywh: bound.serialize(),
245
- }, edgeless.model.id);
248
+ // Beside its source, not in the viewer's active layer (ADR 0031 §6).
249
+ layer: sourceLayerOf(current),
250
+ };
251
+ applyCreationLayer(edgeless.std, props);
252
+ id = store.addBlock('affine:note', props, edgeless.model.id);
246
253
  const note = store.getBlock(id)?.model;
247
254
  if (!note) {
248
255
  throw new BlockSuiteError(ErrorCode.GfxBlockElementError, 'Note block is not found after creation');