@formicoidea/labre-core 0.42.0 → 0.45.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 (367) 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-into-callout.d.ts +29 -0
  4. package/dist/_pkgs/affine-block-callout/commands/turn-into-callout.js +81 -0
  5. package/dist/_pkgs/affine-block-callout/configs/slash-menu.js +6 -4
  6. package/dist/_pkgs/affine-block-callout/configs/turn-into.d.ts +8 -0
  7. package/dist/_pkgs/affine-block-callout/configs/turn-into.js +19 -0
  8. package/dist/_pkgs/affine-block-callout/translations.d.ts +4 -2
  9. package/dist/_pkgs/affine-block-callout/translations.js +4 -2
  10. package/dist/_pkgs/affine-block-callout/view.js +3 -0
  11. package/dist/_pkgs/affine-block-code/code-block-service.d.ts +13 -0
  12. package/dist/_pkgs/affine-block-code/code-block-service.js +26 -0
  13. package/dist/_pkgs/affine-block-code/code-block.d.ts +6 -0
  14. package/dist/_pkgs/affine-block-code/code-block.js +11 -2
  15. package/dist/_pkgs/affine-block-code/code-toolbar/components/lang-button.js +31 -8
  16. package/dist/_pkgs/affine-block-data-view/configs/tooltips.js +1 -1
  17. package/dist/_pkgs/affine-block-database/configs/tooltips.js +1 -1
  18. package/dist/_pkgs/affine-block-edgeless-text/edgeless-text-block.js +4 -2
  19. package/dist/_pkgs/affine-block-edgeless-text/edgeless-toolbar/config.d.ts +11 -0
  20. package/dist/_pkgs/affine-block-edgeless-text/svg-painter.d.ts +20 -0
  21. package/dist/_pkgs/affine-block-edgeless-text/svg-painter.js +76 -0
  22. package/dist/_pkgs/affine-block-edgeless-text/view.js +2 -0
  23. package/dist/_pkgs/affine-block-embed/common/iframe-sandbox.d.ts +39 -0
  24. package/dist/_pkgs/affine-block-embed/common/iframe-sandbox.js +39 -0
  25. package/dist/_pkgs/affine-block-embed/configs/toolbar.js +11 -2
  26. package/dist/_pkgs/affine-block-embed/embed-figma-block/embed-figma-block.js +2 -0
  27. package/dist/_pkgs/affine-block-embed/embed-iframe-block/components/embed-iframe-error-card.d.ts +14 -1
  28. package/dist/_pkgs/affine-block-embed/embed-iframe-block/components/embed-iframe-error-card.js +21 -2
  29. package/dist/_pkgs/affine-block-embed/embed-iframe-block/configs/toolbar.js +11 -2
  30. package/dist/_pkgs/affine-block-embed/embed-iframe-block/consts.d.ts +0 -2
  31. package/dist/_pkgs/affine-block-embed/embed-iframe-block/consts.js +2 -5
  32. package/dist/_pkgs/affine-block-embed/embed-iframe-block/embed-iframe-block.d.ts +1 -1
  33. package/dist/_pkgs/affine-block-embed/embed-iframe-block/embed-iframe-block.js +14 -6
  34. package/dist/_pkgs/affine-block-embed/embed-iframe-block/types.d.ts +16 -0
  35. package/dist/_pkgs/affine-block-embed/embed-iframe-block/types.js +17 -1
  36. package/dist/_pkgs/affine-block-embed/embed-loom-block/embed-loom-block.js +2 -0
  37. package/dist/_pkgs/affine-block-embed/embed-youtube-block/embed-youtube-block.js +2 -0
  38. package/dist/_pkgs/affine-block-embed/index.d.ts +1 -0
  39. package/dist/_pkgs/affine-block-embed/index.js +1 -0
  40. package/dist/_pkgs/affine-block-embed/translations.d.ts +8 -0
  41. package/dist/_pkgs/affine-block-embed/translations.js +28 -0
  42. package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/embed-edgeless-linked-doc-block.js +3 -1
  43. package/dist/_pkgs/affine-block-embed-doc/embed-linked-doc-block/embed-linked-doc-block.js +4 -2
  44. package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/configs/toolbar.js +7 -2
  45. package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/embed-edgeless-synced-doc-block.js +3 -1
  46. package/dist/_pkgs/affine-block-embed-doc/embed-synced-doc-block/embed-synced-doc-block.js +2 -2
  47. package/dist/_pkgs/affine-block-frame/frame-manager.d.ts +5 -0
  48. package/dist/_pkgs/affine-block-frame/frame-manager.js +53 -19
  49. package/dist/_pkgs/affine-block-frame/frame-tool.js +3 -1
  50. package/dist/_pkgs/affine-block-image/utils.js +4 -1
  51. package/dist/_pkgs/affine-block-latex/adapters/markdown/preprocessor.d.ts +8 -0
  52. package/dist/_pkgs/affine-block-latex/adapters/markdown/preprocessor.js +9 -5
  53. package/dist/_pkgs/affine-block-list/utils/get-list-icon.js +3 -1
  54. package/dist/_pkgs/affine-block-note/configs/tooltips.js +1 -1
  55. package/dist/_pkgs/affine-block-note/translations.d.ts +0 -1
  56. package/dist/_pkgs/affine-block-note/translations.js +0 -5
  57. package/dist/_pkgs/affine-block-root/adapters/html.js +2 -2
  58. package/dist/_pkgs/affine-block-root/commands/copy-link-commands.d.ts +2 -0
  59. package/dist/_pkgs/affine-block-root/commands/copy-link-commands.js +155 -0
  60. package/dist/_pkgs/affine-block-root/configs/toolbar.js +17 -1
  61. package/dist/_pkgs/affine-block-root/edgeless/clipboard/clipboard.js +2 -1
  62. package/dist/_pkgs/affine-block-root/edgeless/clipboard/command.js +161 -83
  63. package/dist/_pkgs/affine-block-root/edgeless/clipboard/paste-order.d.ts +21 -0
  64. package/dist/_pkgs/affine-block-root/edgeless/clipboard/paste-order.js +85 -0
  65. package/dist/_pkgs/affine-block-root/edgeless/edgeless-root-block.d.ts +6 -0
  66. package/dist/_pkgs/affine-block-root/edgeless/edgeless-root-block.js +18 -1
  67. package/dist/_pkgs/affine-block-root/edgeless/utils/clone-utils.d.ts +9 -0
  68. package/dist/_pkgs/affine-block-root/edgeless/utils/clone-utils.js +28 -0
  69. package/dist/_pkgs/affine-block-root/index.d.ts +1 -0
  70. package/dist/_pkgs/affine-block-root/index.js +1 -0
  71. package/dist/_pkgs/affine-block-root/keyboard/commands.js +9 -6
  72. package/dist/_pkgs/affine-block-root/preview/edgeless-root-preview-block.js +15 -2
  73. package/dist/_pkgs/affine-block-root/view.js +2 -0
  74. package/dist/_pkgs/affine-block-surface/adapters/markdown/element-adapter/type.d.ts +1 -1
  75. package/dist/_pkgs/affine-block-surface/element-model/index.d.ts +1 -1
  76. package/dist/_pkgs/affine-block-surface/element-model/index.js +1 -1
  77. package/dist/_pkgs/affine-block-surface/extensions/audit.js +13 -61
  78. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/commands.d.ts +2 -0
  79. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/commands.js +71 -0
  80. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/index.d.ts +1 -0
  81. package/dist/_pkgs/affine-block-surface/extensions/canvas-grid/index.js +1 -0
  82. package/dist/_pkgs/affine-block-surface/extensions/clipboard-config.js +4 -0
  83. package/dist/_pkgs/affine-block-surface/extensions/crud-extension.js +4 -0
  84. package/dist/_pkgs/affine-block-surface/extensions/export-manager/export-manager.d.ts +12 -0
  85. package/dist/_pkgs/affine-block-surface/extensions/export-manager/export-manager.js +27 -7
  86. package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.d.ts +2 -1
  87. package/dist/_pkgs/affine-block-surface/extensions/export-svg/command.js +22 -3
  88. package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.d.ts +6 -3
  89. package/dist/_pkgs/affine-block-surface/extensions/export-svg/index.js +4 -2
  90. package/dist/_pkgs/affine-block-surface/extensions/export-svg/parts.d.ts +63 -0
  91. package/dist/_pkgs/affine-block-surface/extensions/export-svg/parts.js +67 -0
  92. package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.d.ts +62 -5
  93. package/dist/_pkgs/affine-block-surface/extensions/export-svg/render.js +98 -18
  94. package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.d.ts +14 -0
  95. package/dist/_pkgs/affine-block-surface/extensions/export-svg/svg-context.js +82 -1
  96. package/dist/_pkgs/affine-block-surface/extensions/export-svg/toolbar.d.ts +2 -2
  97. package/dist/_pkgs/affine-block-surface/extensions/export-svg/toolbar.js +112 -10
  98. package/dist/_pkgs/affine-block-surface/extensions/export-svg/translations.d.ts +13 -0
  99. package/dist/_pkgs/affine-block-surface/extensions/export-svg/translations.js +33 -0
  100. package/dist/_pkgs/affine-block-surface/extensions/index.d.ts +3 -0
  101. package/dist/_pkgs/affine-block-surface/extensions/index.js +3 -0
  102. package/dist/_pkgs/affine-block-surface/extensions/interchange-import.js +13 -1
  103. package/dist/_pkgs/affine-block-surface/extensions/legend.d.ts +8 -0
  104. package/dist/_pkgs/affine-block-surface/extensions/legend.js +59 -3
  105. package/dist/_pkgs/affine-block-surface/extensions/morph-toolbar.js +4 -0
  106. package/dist/_pkgs/affine-block-surface/extensions/reading-widget.d.ts +13 -6
  107. package/dist/_pkgs/affine-block-surface/extensions/reading-widget.js +26 -10
  108. package/dist/_pkgs/affine-block-surface/extensions/reading.d.ts +82 -6
  109. package/dist/_pkgs/affine-block-surface/extensions/reading.js +99 -21
  110. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/actions.d.ts +80 -0
  111. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/actions.js +248 -0
  112. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.d.ts +82 -0
  113. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/commands.js +342 -0
  114. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/index.d.ts +3 -0
  115. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/index.js +3 -0
  116. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/tree.d.ts +137 -0
  117. package/dist/_pkgs/affine-block-surface/extensions/selection-pane/tree.js +323 -0
  118. package/dist/_pkgs/affine-block-surface/extensions/svg-sketch-translations.d.ts +3 -0
  119. package/dist/_pkgs/affine-block-surface/extensions/svg-sketch-translations.js +23 -0
  120. package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.d.ts +112 -4
  121. package/dist/_pkgs/affine-block-surface/extensions/svg-sketch.js +98 -19
  122. package/dist/_pkgs/affine-block-surface/extensions/user-layers/actions.d.ts +76 -0
  123. package/dist/_pkgs/affine-block-surface/extensions/user-layers/actions.js +299 -0
  124. package/dist/_pkgs/affine-block-surface/extensions/user-layers/active-layer.d.ts +20 -0
  125. package/dist/_pkgs/affine-block-surface/extensions/user-layers/active-layer.js +34 -0
  126. package/dist/_pkgs/affine-block-surface/extensions/user-layers/commands.d.ts +67 -0
  127. package/dist/_pkgs/affine-block-surface/extensions/user-layers/commands.js +172 -0
  128. package/dist/_pkgs/affine-block-surface/extensions/user-layers/creation.d.ts +40 -0
  129. package/dist/_pkgs/affine-block-surface/extensions/user-layers/creation.js +69 -0
  130. package/dist/_pkgs/affine-block-surface/extensions/user-layers/index.d.ts +5 -0
  131. package/dist/_pkgs/affine-block-surface/extensions/user-layers/index.js +5 -0
  132. package/dist/_pkgs/affine-block-surface/extensions/user-layers/translations.d.ts +10 -0
  133. package/dist/_pkgs/affine-block-surface/extensions/user-layers/translations.js +14 -0
  134. package/dist/_pkgs/affine-block-surface/framework-background/background-view.js +1 -1
  135. package/dist/_pkgs/affine-block-surface/framework-background/facts.d.ts +55 -2
  136. package/dist/_pkgs/affine-block-surface/framework-background/facts.js +63 -1
  137. package/dist/_pkgs/affine-block-surface/framework-background/fit.d.ts +36 -0
  138. package/dist/_pkgs/affine-block-surface/framework-background/fit.js +30 -0
  139. package/dist/_pkgs/affine-block-surface/framework-background/index.d.ts +1 -0
  140. package/dist/_pkgs/affine-block-surface/framework-background/index.js +1 -0
  141. package/dist/_pkgs/affine-block-surface/framework-background/stacking.d.ts +16 -8
  142. package/dist/_pkgs/affine-block-surface/framework-background/stacking.js +26 -14
  143. package/dist/_pkgs/affine-block-surface/renderer/canvas-renderer.js +17 -3
  144. package/dist/_pkgs/affine-block-surface/renderer/dom-renderer.d.ts +3 -1
  145. package/dist/_pkgs/affine-block-surface/renderer/dom-renderer.js +22 -2
  146. package/dist/_pkgs/affine-block-surface/renderer/element-highlight-overlay.js +2 -7
  147. package/dist/_pkgs/affine-block-surface/renderer/paint-predicate.d.ts +30 -0
  148. package/dist/_pkgs/affine-block-surface/renderer/paint-predicate.js +29 -0
  149. package/dist/_pkgs/affine-block-surface/surface-block.js +6 -0
  150. package/dist/_pkgs/affine-block-surface/surface-model.js +5 -0
  151. package/dist/_pkgs/affine-block-surface/surface-transformer.js +5 -0
  152. package/dist/_pkgs/affine-block-surface/tool/default-tool.js +28 -5
  153. package/dist/_pkgs/affine-block-surface/view.js +23 -1
  154. package/dist/_pkgs/affine-block-surface-ref/configs/tooltips.js +2 -2
  155. package/dist/_pkgs/affine-block-surface-ref/surface-ref-block.js +12 -2
  156. package/dist/_pkgs/affine-components/color-picker/palette-carousel.js +5 -0
  157. package/dist/_pkgs/affine-components/color-picker/styles.js +1 -1
  158. package/dist/_pkgs/affine-components/context-menu/button.js +17 -1
  159. package/dist/_pkgs/affine-components/filterable-list/index.js +30 -9
  160. package/dist/_pkgs/affine-components/icons/ai.js +3 -3
  161. package/dist/_pkgs/affine-components/icons/index.d.ts +0 -1
  162. package/dist/_pkgs/affine-components/icons/index.js +0 -1
  163. package/dist/_pkgs/affine-components/icons/list.js +7 -1
  164. package/dist/_pkgs/affine-components/icons/text.d.ts +1 -0
  165. package/dist/_pkgs/affine-components/icons/text.js +11 -0
  166. package/dist/_pkgs/affine-components/size-dropdown-menu/dropdown-menu.js +6 -1
  167. package/dist/_pkgs/affine-components/toolbar/index.d.ts +1 -1
  168. package/dist/_pkgs/affine-components/toolbar/index.js +1 -1
  169. package/dist/_pkgs/affine-components/toolbar/menu-button.d.ts +7 -0
  170. package/dist/_pkgs/affine-components/toolbar/menu-button.js +30 -0
  171. package/dist/_pkgs/affine-components/toolbar/picker-menu.d.ts +16 -1
  172. package/dist/_pkgs/affine-components/toolbar/picker-menu.js +2 -2
  173. package/dist/_pkgs/affine-components/toolbar/toolbar.d.ts +1 -0
  174. package/dist/_pkgs/affine-components/toolbar/toolbar.js +67 -0
  175. package/dist/_pkgs/affine-fragment-adapter-panel/adapter-panel.d.ts +2 -2
  176. package/dist/_pkgs/affine-fragment-frame-panel/card/frame-card-title-editor.js +1 -1
  177. package/dist/_pkgs/affine-fragment-frame-panel/card/frame-card.js +3 -3
  178. package/dist/_pkgs/affine-fragment-frame-panel/header/frame-panel-header.d.ts +1 -1
  179. package/dist/_pkgs/affine-fragment-frame-panel/header/frame-panel-header.js +8 -27
  180. package/dist/_pkgs/affine-fragment-frame-panel/index.d.ts +1 -0
  181. package/dist/_pkgs/affine-fragment-frame-panel/index.js +1 -0
  182. package/dist/_pkgs/affine-gfx-brush/toolbar/components/eraser/icons.js +1 -1
  183. package/dist/_pkgs/affine-gfx-connector/direction/direction-reveal.d.ts +11 -2
  184. package/dist/_pkgs/affine-gfx-connector/direction/direction-reveal.js +11 -2
  185. package/dist/_pkgs/affine-gfx-connector/element-renderer/connector-dom/index.js +3 -1
  186. package/dist/_pkgs/affine-gfx-connector/element-renderer/index.js +21 -4
  187. package/dist/_pkgs/affine-gfx-connector/text/edgeless-connector-label-editor.js +6 -4
  188. package/dist/_pkgs/affine-gfx-connector/toolbar/config.js +24 -8
  189. package/dist/_pkgs/affine-gfx-connector/translations.d.ts +3 -0
  190. package/dist/_pkgs/affine-gfx-connector/translations.js +23 -0
  191. package/dist/_pkgs/affine-gfx-group/command/group-api.js +52 -1
  192. package/dist/_pkgs/affine-gfx-mindmap/indicator-overlay/index.js +6 -2
  193. package/dist/_pkgs/affine-gfx-mindmap/toolbar/config.js +4 -2
  194. package/dist/_pkgs/affine-gfx-mindmap/translations.d.ts +6 -0
  195. package/dist/_pkgs/affine-gfx-mindmap/translations.js +10 -0
  196. package/dist/_pkgs/affine-gfx-shape/element-renderer/shape/index.js +21 -3
  197. package/dist/_pkgs/affine-gfx-shape/text/edgeless-shape-text-editor.js +2 -0
  198. package/dist/_pkgs/affine-gfx-shape/toolbar/config.js +5 -3
  199. package/dist/_pkgs/affine-gfx-shape/translations.d.ts +7 -0
  200. package/dist/_pkgs/affine-gfx-shape/translations.js +11 -0
  201. package/dist/_pkgs/affine-gfx-template/builtin/other.js +13 -7
  202. package/dist/_pkgs/affine-gfx-template/services/template-middlewares.d.ts +9 -0
  203. package/dist/_pkgs/affine-gfx-template/services/template-middlewares.js +23 -1
  204. package/dist/_pkgs/affine-gfx-template/services/template.js +2 -1
  205. package/dist/_pkgs/affine-gfx-template/toolbar/template-loading.js +1 -1
  206. package/dist/_pkgs/affine-gfx-template/translations.d.ts +5 -0
  207. package/dist/_pkgs/affine-gfx-template/translations.js +38 -0
  208. package/dist/_pkgs/affine-gfx-text/edgeless-text-editor.js +5 -3
  209. package/dist/_pkgs/affine-gfx-text/element-renderer/index.js +20 -3
  210. package/dist/_pkgs/affine-gfx-text/element-renderer/utils.d.ts +67 -1
  211. package/dist/_pkgs/affine-gfx-text/element-renderer/utils.js +101 -0
  212. package/dist/_pkgs/affine-gfx-text/toolbar/actions.d.ts +11 -0
  213. package/dist/_pkgs/affine-gfx-text/toolbar/actions.js +56 -3
  214. package/dist/_pkgs/affine-gfx-text/toolbar/config.d.ts +11 -0
  215. package/dist/_pkgs/affine-gfx-text/toolbar/config.js +1 -1
  216. package/dist/_pkgs/affine-gfx-text/translations.d.ts +8 -0
  217. package/dist/_pkgs/affine-gfx-text/translations.js +12 -0
  218. package/dist/_pkgs/affine-inline-latex/latex-node/latex-editor-menu.js +2 -1
  219. package/dist/_pkgs/affine-inline-preset/adapters/html/html-inline.d.ts +3 -0
  220. package/dist/_pkgs/affine-inline-preset/adapters/html/html-inline.js +31 -0
  221. package/dist/_pkgs/affine-inline-preset/adapters/html/inline-delta.d.ts +4 -0
  222. package/dist/_pkgs/affine-inline-preset/adapters/html/inline-delta.js +14 -0
  223. package/dist/_pkgs/affine-inline-preset/command/config.js +21 -3
  224. package/dist/_pkgs/affine-inline-preset/command/index.d.ts +1 -1
  225. package/dist/_pkgs/affine-inline-preset/command/index.js +1 -1
  226. package/dist/_pkgs/affine-inline-preset/command/text-style.d.ts +2 -1
  227. package/dist/_pkgs/affine-inline-preset/command/text-style.js +1 -0
  228. package/dist/_pkgs/affine-inline-preset/default-inline-manager.js +2 -1
  229. package/dist/_pkgs/affine-inline-preset/inline-spec.d.ts +4 -0
  230. package/dist/_pkgs/affine-inline-preset/inline-spec.js +14 -0
  231. package/dist/_pkgs/affine-inline-preset/translations.d.ts +2 -2
  232. package/dist/_pkgs/affine-inline-preset/translations.js +2 -2
  233. package/dist/_pkgs/affine-model/blocks/attachment/attachment-model.js +2 -0
  234. package/dist/_pkgs/affine-model/blocks/bookmark/bookmark-model.js +2 -0
  235. package/dist/_pkgs/affine-model/blocks/edgeless-text/edgeless-text-model.d.ts +1 -1
  236. package/dist/_pkgs/affine-model/blocks/edgeless-text/edgeless-text-model.js +2 -0
  237. package/dist/_pkgs/affine-model/blocks/embed/iframe/iframe-model.js +2 -0
  238. package/dist/_pkgs/affine-model/blocks/frame/frame-model.js +2 -0
  239. package/dist/_pkgs/affine-model/blocks/image/image-model.js +2 -0
  240. package/dist/_pkgs/affine-model/blocks/latex/latex-model.js +2 -0
  241. package/dist/_pkgs/affine-model/blocks/note/note-model.js +2 -0
  242. package/dist/_pkgs/affine-model/consts/text.d.ts +41 -2
  243. package/dist/_pkgs/affine-model/consts/text.js +50 -1
  244. package/dist/_pkgs/affine-model/elements/shape/shape.d.ts +6 -1
  245. package/dist/_pkgs/affine-model/elements/shape/shape.js +14 -1
  246. package/dist/_pkgs/affine-model/elements/text/text.d.ts +6 -1
  247. package/dist/_pkgs/affine-model/elements/text/text.js +13 -1
  248. package/dist/_pkgs/affine-model/utils/helper.js +2 -0
  249. package/dist/_pkgs/affine-rich-text/conversion.d.ts +25 -0
  250. package/dist/_pkgs/affine-rich-text/conversion.js +9 -0
  251. package/dist/_pkgs/affine-rich-text/index.d.ts +1 -1
  252. package/dist/_pkgs/affine-rich-text/index.js +1 -1
  253. package/dist/_pkgs/affine-shared/commands/model-crud/replace-selected-text-with-blocks.d.ts +1 -1
  254. package/dist/_pkgs/affine-shared/services/canvas-grid.d.ts +63 -0
  255. package/dist/_pkgs/affine-shared/services/canvas-grid.js +109 -0
  256. package/dist/_pkgs/affine-shared/services/canvas-local-visibility.d.ts +64 -0
  257. package/dist/_pkgs/affine-shared/services/canvas-local-visibility.js +192 -0
  258. package/dist/_pkgs/affine-shared/services/edit-props-store.d.ts +27 -0
  259. package/dist/_pkgs/affine-shared/services/edit-props-store.js +34 -0
  260. package/dist/_pkgs/affine-shared/services/editor-setting-service.d.ts +3 -0
  261. package/dist/_pkgs/affine-shared/services/editor-setting-service.js +7 -0
  262. package/dist/_pkgs/affine-shared/services/feature-flag-service.d.ts +4 -0
  263. package/dist/_pkgs/affine-shared/services/font-loader/config.d.ts +13 -2
  264. package/dist/_pkgs/affine-shared/services/font-loader/config.js +43 -54
  265. package/dist/_pkgs/affine-shared/services/index.d.ts +3 -0
  266. package/dist/_pkgs/affine-shared/services/index.js +3 -0
  267. package/dist/_pkgs/affine-shared/services/selection-pane-service.d.ts +44 -0
  268. package/dist/_pkgs/affine-shared/services/selection-pane-service.js +28 -0
  269. package/dist/_pkgs/affine-shared/services/telemetry-service/lifecycle.d.ts +69 -0
  270. package/dist/_pkgs/affine-shared/services/telemetry-service/telemetry-service.d.ts +2 -2
  271. package/dist/_pkgs/affine-shared/services/theme-service.d.ts +19 -0
  272. package/dist/_pkgs/affine-shared/services/theme-service.js +24 -0
  273. package/dist/_pkgs/affine-shared/services/translation-service/chrome.d.ts +25 -0
  274. package/dist/_pkgs/affine-shared/services/translation-service/chrome.js +90 -0
  275. package/dist/_pkgs/affine-shared/styles/index.d.ts +1 -0
  276. package/dist/_pkgs/affine-shared/styles/index.js +1 -0
  277. package/dist/_pkgs/affine-shared/styles/panel-header.d.ts +31 -0
  278. package/dist/_pkgs/affine-shared/styles/panel-header.js +61 -0
  279. package/dist/_pkgs/affine-shared/styles/text.js +7 -7
  280. package/dist/_pkgs/affine-shared/types/index.d.ts +6 -0
  281. package/dist/_pkgs/affine-shared/utils/canvas-export-colors.d.ts +26 -0
  282. package/dist/_pkgs/affine-shared/utils/canvas-export-colors.js +127 -0
  283. package/dist/_pkgs/affine-shared/utils/file/filesys.d.ts +8 -11
  284. package/dist/_pkgs/affine-shared/utils/file/filesys.js +8 -11
  285. package/dist/_pkgs/affine-shared/utils/index.d.ts +2 -0
  286. package/dist/_pkgs/affine-shared/utils/index.js +2 -0
  287. package/dist/_pkgs/affine-shared/utils/label-mode.d.ts +47 -0
  288. package/dist/_pkgs/affine-shared/utils/label-mode.js +55 -0
  289. package/dist/_pkgs/affine-shared/utils/model/merge-to-code-model.js +7 -1
  290. package/dist/_pkgs/affine-shared/utils/model/transform-model.js +5 -0
  291. package/dist/_pkgs/affine-widget-edgeless-dragging-area/edgeless-dragging-area-rect.js +2 -2
  292. package/dist/_pkgs/affine-widget-edgeless-selected-rect/utils.js +15 -4
  293. package/dist/_pkgs/affine-widget-edgeless-toolbar/catalogue/artefact-catalogue-widget.js +25 -49
  294. package/dist/_pkgs/affine-widget-edgeless-toolbar/config/types.d.ts +15 -0
  295. package/dist/_pkgs/affine-widget-edgeless-toolbar/config/utils.d.ts +1 -1
  296. package/dist/_pkgs/affine-widget-edgeless-toolbar/config/utils.js +7 -2
  297. package/dist/_pkgs/affine-widget-edgeless-toolbar/effects.d.ts +4 -0
  298. package/dist/_pkgs/affine-widget-edgeless-toolbar/effects.js +4 -0
  299. package/dist/_pkgs/affine-widget-edgeless-toolbar/index.d.ts +4 -0
  300. package/dist/_pkgs/affine-widget-edgeless-toolbar/index.js +4 -0
  301. package/dist/_pkgs/affine-widget-edgeless-toolbar/panel/font-family-panel.d.ts +18 -0
  302. package/dist/_pkgs/affine-widget-edgeless-toolbar/panel/font-family-panel.js +52 -6
  303. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/drop.d.ts +61 -0
  304. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/drop.js +91 -0
  305. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/labels.d.ts +17 -0
  306. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/labels.js +95 -0
  307. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-default.d.ts +10 -0
  308. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-default.js +31 -0
  309. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-tool.d.ts +26 -0
  310. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-tool.js +82 -0
  311. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-widget.d.ts +170 -0
  312. package/dist/_pkgs/affine-widget-edgeless-toolbar/selection-pane/selection-pane-widget.js +1381 -0
  313. package/dist/_pkgs/affine-widget-edgeless-toolbar/translations.d.ts +58 -0
  314. package/dist/_pkgs/affine-widget-edgeless-toolbar/translations.js +171 -1
  315. package/dist/_pkgs/affine-widget-edgeless-toolbar/view.js +10 -0
  316. package/dist/_pkgs/affine-widget-frame-title/edgeless-frame-title-editor.js +2 -1
  317. package/dist/_pkgs/affine-widget-note-slicer/note-slicer.js +7 -3
  318. package/dist/_pkgs/affine-widget-slash-menu/translations.d.ts +16 -0
  319. package/dist/_pkgs/affine-widget-slash-menu/translations.js +23 -1
  320. package/dist/_pkgs/affine-widget-toolbar/utils.js +57 -14
  321. package/dist/_pkgs/data-view/core/detail/field.js +2 -1
  322. package/dist/_pkgs/data-view/core/filter/literal/define.js +3 -1
  323. package/dist/_pkgs/data-view/core/group-by/renderer/boolean-group.js +1 -1
  324. package/dist/_pkgs/data-view/property-presets/checkbox/cell-renderer.js +8 -2
  325. package/dist/_pkgs/data-view/view-presets/kanban/pc/cell.js +1 -1
  326. package/dist/_pkgs/data-view/view-presets/kanban/pc/controller/drag.js +2 -1
  327. package/dist/_pkgs/data-view/view-presets/table/pc/controller/drag.js +2 -1
  328. package/dist/_pkgs/data-view/view-presets/table/pc/controller/selection.js +1 -1
  329. package/dist/_pkgs/data-view/view-presets/table/pc/header/vertical-indicator.js +2 -1
  330. package/dist/_pkgs/data-view/view-presets/table/pc/row/row-select-checkbox.js +3 -1
  331. package/dist/_pkgs/data-view/view-presets/table/pc-virtual/controller/drag.js +2 -1
  332. package/dist/_pkgs/data-view/view-presets/table/pc-virtual/controller/selection.js +1 -1
  333. package/dist/_pkgs/data-view/view-presets/table/pc-virtual/group/top/header/vertical-indicator.js +2 -1
  334. package/dist/_pkgs/data-view/view-presets/table/pc-virtual/row/row-header.js +3 -1
  335. package/dist/_pkgs/std/gfx/controller.d.ts +13 -0
  336. package/dist/_pkgs/std/gfx/controller.js +22 -2
  337. package/dist/_pkgs/std/gfx/grid.d.ts +31 -2
  338. package/dist/_pkgs/std/gfx/index.d.ts +3 -1
  339. package/dist/_pkgs/std/gfx/index.js +3 -1
  340. package/dist/_pkgs/std/gfx/interactivity/manager.js +7 -0
  341. package/dist/_pkgs/std/gfx/layer.js +73 -5
  342. package/dist/_pkgs/std/gfx/local-visibility.d.ts +88 -0
  343. package/dist/_pkgs/std/gfx/local-visibility.js +217 -0
  344. package/dist/_pkgs/std/gfx/model/gfx-block-model.d.ts +13 -0
  345. package/dist/_pkgs/std/gfx/model/surface/element-model.d.ts +34 -0
  346. package/dist/_pkgs/std/gfx/model/surface/element-model.js +65 -1
  347. package/dist/_pkgs/std/gfx/model/surface/role.d.ts +10 -5
  348. package/dist/_pkgs/std/gfx/model/surface/surface-model.d.ts +27 -0
  349. package/dist/_pkgs/std/gfx/model/surface/surface-model.js +43 -0
  350. package/dist/_pkgs/std/gfx/model/surface/user-layers.d.ts +68 -0
  351. package/dist/_pkgs/std/gfx/model/surface/user-layers.js +127 -0
  352. package/dist/_pkgs/std/utils/layer.d.ts +10 -0
  353. package/dist/_pkgs/std/utils/layer.js +64 -13
  354. package/dist/_pkgs/std/view/element/gfx-block-component.js +10 -2
  355. package/dist/commands.js +6 -2
  356. package/dist/translations.js +15 -6
  357. package/package.json +13 -2
  358. package/dist/_pkgs/affine-components/icons/file-icons-rc.d.ts +0 -1
  359. package/dist/_pkgs/affine-components/icons/file-icons-rc.js +0 -130
  360. package/dist/_pkgs/affine-shared/test-utils/affine-template.d.ts +0 -6
  361. package/dist/_pkgs/affine-shared/test-utils/affine-template.js +0 -258
  362. package/dist/_pkgs/affine-shared/test-utils/affine-test-utils.d.ts +0 -8
  363. package/dist/_pkgs/affine-shared/test-utils/affine-test-utils.js +0 -81
  364. package/dist/_pkgs/affine-shared/test-utils/create-test-host.d.ts +0 -23
  365. package/dist/_pkgs/affine-shared/test-utils/create-test-host.js +0 -187
  366. package/dist/_pkgs/affine-shared/test-utils/index.d.ts +0 -3
  367. package/dist/_pkgs/affine-shared/test-utils/index.js +0 -3
@@ -1,6 +1,7 @@
1
1
  import { ShapeStyle, ShapeType, StrokeStyle, TextAlign, } from '../../affine-model/index.js';
2
2
  import DOMPurify from 'dompurify';
3
- import { SVG_SKETCH_CURRENT_COLOR, SVG_SKETCH_CURVE, SVG_SKETCH_EMPTY, SVG_SKETCH_EMPTY_BOX, SVG_SKETCH_EMPTY_TEXT, SVG_SKETCH_FLAT_POLYGON, SVG_SKETCH_FONT_UNIT, SVG_SKETCH_HIDDEN_DISPLAY, SVG_SKETCH_HIDDEN_VISIBILITY, SVG_SKETCH_LONE_POINT, SVG_SKETCH_OPACITY, SVG_SKETCH_PAINT_SERVER, SVG_SKETCH_PERCENT_RADIUS, SVG_SKETCH_REMOVED, SVG_SKETCH_REMOVED_ATTRIBUTE, SVG_SKETCH_SKIPPED, SVG_SKETCH_SWITCH, SVG_SKETCH_TRANSFORM, } from './svg-sketch-translations.js';
3
+ import { InterchangeImportError, } from './interchange.js';
4
+ import { SVG_SKETCH_CURRENT_COLOR, SVG_SKETCH_CURVE, SVG_SKETCH_EMPTY, SVG_SKETCH_EMPTY_BOX, SVG_SKETCH_EMPTY_TEXT, SVG_SKETCH_ERROR_MALFORMED_XML, SVG_SKETCH_ERROR_NOT_SVG, SVG_SKETCH_ERROR_SANITIZED_AWAY, SVG_SKETCH_FLAT_POLYGON, SVG_SKETCH_FONT_UNIT, SVG_SKETCH_HIDDEN_DISPLAY, SVG_SKETCH_HIDDEN_VISIBILITY, SVG_SKETCH_LONE_POINT, SVG_SKETCH_OPACITY, SVG_SKETCH_PAINT_SERVER, SVG_SKETCH_PERCENT_RADIUS, SVG_SKETCH_REMOVED, SVG_SKETCH_REMOVED_ATTRIBUTE, SVG_SKETCH_SKIPPED, SVG_SKETCH_SWITCH, SVG_SKETCH_TRANSFORM, } from './svg-sketch-translations.js';
4
5
  /**
5
6
  * **SVG → a canvas sketch.** The platform's VISUAL-tier importer, shared by
6
7
  * every framework that declares it (`docs/adr/0012`, P2).
@@ -11,9 +12,11 @@ import { SVG_SKETCH_CURRENT_COLOR, SVG_SKETCH_CURVE, SVG_SKETCH_EMPTY, SVG_SKETC
11
12
  * a one-paragraph statement of its heuristics and its known failure modes" —
12
13
  * answered ONCE, here, because every framework that declares `…:svg:import`
13
14
  * wraps this one function and therefore owes the same statement. It is
14
- * referenced by `bpmn:svg:import` and by `wardley:svg:import`; a framework that
15
- * ever wants a narrower or wider guess writes its own parser and its own
16
- * paragraph beside it._
15
+ * referenced by `bpmn:svg:import`; a framework that ever wants a narrower or
16
+ * wider guess writes its own parser and its own paragraph beside it. Wardley
17
+ * did (ADR 0032): a framework may CLAIM nodes before the walk below
18
+ * ({@link sanitizeSvg}, {@link sketchSvgTree}), and then owes its own statement
19
+ * for what it claims — this one still covers everything it leaves here._
17
20
  *
18
21
  * **What it guesses.** An SVG carries a rendering, not a model, so this reader
19
22
  * recognises GEOMETRY and nothing else: `<rect>` becomes a rectangle,
@@ -164,8 +167,12 @@ function numbers(raw) {
164
167
  * Every note is a `warning`. The other four kinds would be lies here:
165
168
  * `carried` and `quarantined` describe a payload this tier does not write, and
166
169
  * `substituted-id` and `invented-layout` describe promises it does not make.
170
+ *
171
+ * Exported so a framework that claims part of a picture first (ADR 0032 §2)
172
+ * hands the SAME notebook to {@link sanitizeSvg} and {@link sketchSvgTree}: one
173
+ * file, one de-duplication, one list of remarks.
167
174
  */
168
- class Notebook {
175
+ export class SvgSketchNotebook {
169
176
  constructor() {
170
177
  this.seen = new Set();
171
178
  this.notes = [];
@@ -773,6 +780,8 @@ function walk(parent, frame, inherited, sketch) {
773
780
  }
774
781
  /** One element and whatever it contains, placed in its parent's frame. */
775
782
  function visit(element, frame, inherited, sketch) {
783
+ if (sketch.skip.has(element))
784
+ return;
776
785
  const name = nameOf(element);
777
786
  if (NON_RENDERING.has(name))
778
787
  return;
@@ -850,6 +859,68 @@ function emit(element, name, frame, paint, sketch) {
850
859
  sketch.notes.once(`skipped:${name}`, `\`<${name}>\` is not recognised and was skipped.`, SVG_SKETCH_SKIPPED, { name }, name);
851
860
  }
852
861
  }
862
+ /* ── The two passes, opened to a recogniser (ADR 0032 §2) ────────────── */
863
+ /**
864
+ * The second pass: a sanitised tree as sketch props, minus what a caller
865
+ * claimed.
866
+ *
867
+ * `skip` is the set of nodes a framework's recogniser already turned into its
868
+ * own artefacts; each one is left alone WITH its subtree, and everything else
869
+ * is read exactly as {@link parseSvgSketch} reads it. `place` composes a frame
870
+ * OUTSIDE the file's own viewport — `canvas = place.s · file + place.o` — so
871
+ * the remainder can land beside a board the recogniser laid out at another
872
+ * scale. Both default to nothing, which is {@link parseSvgSketch} itself.
873
+ *
874
+ * A framework that claims nodes owes its own heuristics statement for what it
875
+ * claims; this module's statement covers only what reaches this walk.
876
+ */
877
+ export function sketchSvgTree(root, notes, options = {}) {
878
+ const sketch = {
879
+ elements: [],
880
+ notes,
881
+ skip: options.skip ?? new Set(),
882
+ };
883
+ const place = options.place ?? IDENTITY;
884
+ const own = viewportFrame(root, IDENTITY);
885
+ // The root `<svg>` paints like any other element — a `fill` on it is what
886
+ // every shape under it inherits — and it establishes the outermost viewport.
887
+ walk(root, {
888
+ ox: own.ox * place.s + place.ox,
889
+ oy: own.oy * place.s + place.oy,
890
+ s: own.s * place.s,
891
+ }, paintOf(root, INITIAL_PAINT, notes), sketch);
892
+ return sketch.elements;
893
+ }
894
+ /**
895
+ * The frame a node's OWN attributes are read in — its `cx`, its `x1`, its
896
+ * `points` — composed exactly the way the walk composes it: the root's
897
+ * viewport, then every ancestor's translate and nested viewport, then the
898
+ * node's own `transform`. So a recogniser that reads a circle's centre through
899
+ * this lands it on the very point the sketch would have drawn it.
900
+ *
901
+ * The transforms the walk ignores are ignored here too, silently: the walk
902
+ * already says so once per kind when it meets them.
903
+ */
904
+ export function svgFrameOf(element) {
905
+ const path = [];
906
+ for (let at = element; at; at = at.parentElement) {
907
+ path.unshift(at);
908
+ }
909
+ // The outermost `<svg>` on the path is the root the walk starts from: its
910
+ // viewport is the identity's, and its own `transform` is never read.
911
+ const rootIndex = path.findIndex(node => nameOf(node) === 'svg');
912
+ if (rootIndex < 0)
913
+ return IDENTITY;
914
+ const quiet = new SvgSketchNotebook();
915
+ let frame = viewportFrame(path[rootIndex], IDENTITY);
916
+ for (const node of path.slice(rootIndex + 1)) {
917
+ frame = translated(node, frame, quiet);
918
+ if (node !== element && nameOf(node) === 'svg') {
919
+ frame = viewportFrame(node, frame);
920
+ }
921
+ }
922
+ return frame;
923
+ }
853
924
  /* ── The capability's function ────────────────────────────────────────── */
854
925
  /**
855
926
  * The document, sanitized, or an exception naming what is wrong with it.
@@ -866,8 +937,12 @@ function emit(element, name, frame, paint, sketch) {
866
937
  * handler attributes — handed over by whoever sent the file. The same
867
938
  * `USE_PROFILES: { svg: true }` guard is what the edgeless clipboard already
868
939
  * puts in front of a pasted SVG.
940
+ *
941
+ * The first of the two passes {@link parseSvgSketch} is made of, exported so a
942
+ * framework that recognises part of a picture reads the SAME sanitised tree
943
+ * the sketch walks (ADR 0032 §2, §7) — never the source.
869
944
  */
870
- function parseSvgRoot(source, notes) {
945
+ export function sanitizeSvg(source, notes) {
871
946
  const doc = new DOMParser().parseFromString(source, 'image/svg+xml');
872
947
  const error = doc.querySelector('parsererror');
873
948
  if (error) {
@@ -879,10 +954,15 @@ function parseSvgRoot(source, notes) {
879
954
  .split('\n')
880
955
  .map(line => line.trim())
881
956
  .filter(line => line.length > 0);
882
- throw new Error(`This file is not well-formed XML, so no drawing can be read out of it: ${summary.slice(0, 200)}`);
957
+ const detail = summary.slice(0, 200);
958
+ throw new InterchangeImportError(`This file is not well-formed XML, so no drawing can be read out of it: ${detail}`, {
959
+ messageKey: SVG_SKETCH_ERROR_MALFORMED_XML[0],
960
+ messageParams: { detail },
961
+ });
883
962
  }
884
963
  if (nameOf(doc.documentElement) !== 'svg') {
885
- throw new Error(`An SVG opens on <svg>; this one opens on <${doc.documentElement?.localName ?? 'nothing'}>.`);
964
+ const tag = doc.documentElement?.localName ?? 'nothing';
965
+ throw new InterchangeImportError(`An SVG opens on <svg>; this one opens on <${tag}>.`, { messageKey: SVG_SKETCH_ERROR_NOT_SVG[0], messageParams: { tag } });
886
966
  }
887
967
  const clean = DOMPurify.sanitize(source, {
888
968
  USE_PROFILES: { svg: true },
@@ -923,7 +1003,9 @@ function parseSvgRoot(source, notes) {
923
1003
  // overload, which answers an `HTMLElement` — the sanitized body wrapper.
924
1004
  const root = childElements(clean).find(child => nameOf(child) === 'svg');
925
1005
  if (!root) {
926
- throw new Error('Nothing survived sanitizing this SVG, so there is no drawing to read.');
1006
+ throw new InterchangeImportError(SVG_SKETCH_ERROR_SANITIZED_AWAY[1], {
1007
+ messageKey: SVG_SKETCH_ERROR_SANITIZED_AWAY[0],
1008
+ });
927
1009
  }
928
1010
  return root;
929
1011
  }
@@ -944,25 +1026,22 @@ export function parseSvgSketch(source, context = {}) {
944
1026
  // A sketch has no document-level name to take: what a board is CALLED is the
945
1027
  // document's business, not any element's. Same answer the BPMN reader gives.
946
1028
  void context;
947
- const sketch = { elements: [], notes: new Notebook() };
948
- const root = parseSvgRoot(source, sketch.notes);
949
- // The root `<svg>` paints like any other element — a `fill` on it is what
950
- // every shape under it inherits — and it establishes the outermost viewport.
951
- walk(root, viewportFrame(root, IDENTITY), paintOf(root, INITIAL_PAINT, sketch.notes), sketch);
952
- if (sketch.elements.length === 0) {
953
- sketch.notes.once('empty', 'No shape or text was recognised in this SVG, so nothing was drawn.', SVG_SKETCH_EMPTY);
1029
+ const notes = new SvgSketchNotebook();
1030
+ const elements = sketchSvgTree(sanitizeSvg(source, notes), notes);
1031
+ if (elements.length === 0) {
1032
+ notes.once('empty', 'No shape or text was recognised in this SVG, so nothing was drawn.', SVG_SKETCH_EMPTY);
954
1033
  }
955
1034
  return {
956
- elements: sketch.elements,
1035
+ elements,
957
1036
  report: {
958
- mapped: sketch.elements.length,
1037
+ mapped: elements.length,
959
1038
  // Always zero, and it is the tier's whole contract rather than an
960
1039
  // accident of this file: a visual import carries nothing and quarantines
961
1040
  // nothing, because it writes no `interchange` payload to carry anything
962
1041
  // IN (ADR 0012, P2). Pinned by an anti-decay test.
963
1042
  carried: 0,
964
1043
  quarantined: 0,
965
- notes: sketch.notes.notes,
1044
+ notes: notes.notes,
966
1045
  // …and no `sourceVersion`. An SVG declares a version of the SVG spec, not
967
1046
  // a version of a vocabulary this reader translates, so claiming one would
968
1047
  // be a fact about the file dressed up as a fact about the import.
@@ -0,0 +1,76 @@
1
+ import type { BlockStdScope } from '../../../std/index.js';
2
+ import { type GfxModel, type SurfaceBlockModel, type SurfaceLayerRecord } from '../../../std/gfx/index.js';
3
+ /** The layer records, bottom first. Empty while the surface has none. */
4
+ export declare function userLayersBottomUp(surface: SurfaceBlockModel | null): {
5
+ id: string;
6
+ record: SurfaceLayerRecord;
7
+ }[];
8
+ /**
9
+ * The name a layer row shows: its record's, or — for the default layer while
10
+ * it has no record — the name the first-layer creation would write ("Layer
11
+ * 1", ADR 0031 amendments). `null` for an id that is no layer.
12
+ *
13
+ * Reading it writes nothing: the default layer is shown from the start and
14
+ * recorded only by a gesture that needs the record.
15
+ */
16
+ export declare function userLayerName(std: BlockStdScope, id: string): string | null;
17
+ /**
18
+ * Create a user layer on top of the others and make it this viewer's active
19
+ * layer. Answers its id, or `null` when nothing was written.
20
+ *
21
+ * The FIRST creation writes two records in one transaction: `'@default'`,
22
+ * named through the seam ("Layer 1"), and the new one above it. That one
23
+ * write sets the whole `layers` prop, so two peers doing it at the same
24
+ * moment keep one record set (ADR 0031 open point 6, accepted for v1): the
25
+ * other peer's members fall back to the default layer, nothing is dropped.
26
+ */
27
+ export declare function createUserLayer(std: BlockStdScope, name?: string): string | null;
28
+ /**
29
+ * Rename a layer: one field of one record. Empty or unchanged writes nothing.
30
+ *
31
+ * The default layer with no record yet is renamed by recording it, named
32
+ * (ADR 0031 amendments): "unchanged" is then against the seed name it shows.
33
+ */
34
+ export declare function renameUserLayer(std: BlockStdScope, id: string, name: string): boolean;
35
+ /**
36
+ * Move a layer so it sits directly ABOVE `above` — `null` puts it at the
37
+ * bottom. One field (`index`) of one record; a reorder racing a peer's
38
+ * rename of the same layer merges.
39
+ */
40
+ export declare function reorderUserLayer(std: BlockStdScope, id: string, above: string | null): boolean;
41
+ /**
42
+ * Hide whole layers for EVERYONE, or show them again (ADR 0031 §7, stage
43
+ * 7): `hidden: true` on each record — one write per layer, never one per
44
+ * member — and the key REMOVED on show, never `false`. Answers how many
45
+ * records were written.
46
+ *
47
+ * Hiding the default layer while it has no record records it, hidden, with
48
+ * its seed name (ADR 0031 amendments); showing it has nothing to write.
49
+ */
50
+ export declare function setUserLayersHiddenForEveryone(std: BlockStdScope, ids: readonly string[], hidden: boolean): number;
51
+ /**
52
+ * Delete a user layer WITH its members, in one undo step (ADR 0031 §10).
53
+ * Answers how many models went with it, or `null` when nothing was written.
54
+ *
55
+ * The read-only refusal comes first, then one `captureSync()`, then one
56
+ * transaction: every top-level model whose effective layer is this one (a
57
+ * group or a mindmap takes its descendants with it), then the record. A
58
+ * connector of ANOTHER layer whose ends were here stays, loose, as when its
59
+ * ends are deleted any other way — the members are removed one by one, not
60
+ * through the "delete with connectors" path of the toolbar. A frame of this
61
+ * layer goes; what it holds from other layers stays. `'@default'` cannot be
62
+ * deleted.
63
+ */
64
+ export declare function deleteUserLayer(std: BlockStdScope, id: string): number | null;
65
+ /**
66
+ * Write `layer` on one model — set it, or REMOVE the key for the default
67
+ * layer (never the string `'@default'`). Inside the caller's transaction.
68
+ */
69
+ export declare function writeModelLayer(std: BlockStdScope, model: GfxModel, layer: string): void;
70
+ /**
71
+ * Move models to the layer `layerId`. Answers how many models were written —
72
+ * a grouped model moves its outermost group, so that may be fewer than asked.
73
+ * An unknown layer id writes nothing. The default layer always exists, record
74
+ * or not: moving there removes the `layer` key, a dangling id included.
75
+ */
76
+ export declare function moveModelsToUserLayer(std: BlockStdScope, ids: readonly string[], layerId: string): number;
@@ -0,0 +1,299 @@
1
+ import { translateKey } from '../../../affine-shared/services/index.js';
2
+ import { DEFAULT_LAYER_ID, GfxBlockElementModel, GfxControllerIdentifier, GfxPrimitiveElementModel, layerCarrierOf, ownLayerOf, } from '../../../std/gfx/index.js';
3
+ import { nanoid } from '../../../store/index.js';
4
+ import { generateKeyBetween } from 'fractional-indexing';
5
+ import { CanvasActiveLayer } from './active-layer.js';
6
+ import { LAYER_SEED_NAME } from './translations.js';
7
+ /**
8
+ * The user layers' writes (ADR 0031 §2, §5, stage 6). Every one of them:
9
+ *
10
+ * - refuses on a read-only document before reading anything else;
11
+ * - writes nothing when nothing would change;
12
+ * - takes ONE `captureSync()` first, so one gesture is one undo step;
13
+ * - writes ONE record, or ONE field of a record — never the whole `layers`
14
+ * prop, except the very first creation, which has no record to write into.
15
+ * That is what lets two peers' edits of two layers merge key by key.
16
+ *
17
+ * Reached through the `canvas.layer.*` commands, so a host's own pane gets
18
+ * the same guards by calling `runCommand`.
19
+ */
20
+ function surfaceOf(std) {
21
+ return std.get(GfxControllerIdentifier).surface;
22
+ }
23
+ /** The layer records, bottom first. Empty while the surface has none. */
24
+ export function userLayersBottomUp(surface) {
25
+ const layers = surface?.props.layers;
26
+ if (!layers)
27
+ return [];
28
+ return Object.entries(layers)
29
+ .filter(([, record]) => record && typeof record.index === 'string')
30
+ .map(([id, record]) => ({ id, record }))
31
+ .sort((a, b) => a.record.index === b.record.index
32
+ ? a.id < b.id
33
+ ? -1
34
+ : 1
35
+ : a.record.index < b.record.index
36
+ ? -1
37
+ : 1);
38
+ }
39
+ /** The seed a new layer is named with, resolved through the seam. */
40
+ function seedName(std, n) {
41
+ return translateKey(std, ...LAYER_SEED_NAME, { n });
42
+ }
43
+ /**
44
+ * The name a layer row shows: its record's, or — for the default layer while
45
+ * it has no record — the name the first-layer creation would write ("Layer
46
+ * 1", ADR 0031 amendments). `null` for an id that is no layer.
47
+ *
48
+ * Reading it writes nothing: the default layer is shown from the start and
49
+ * recorded only by a gesture that needs the record.
50
+ */
51
+ export function userLayerName(std, id) {
52
+ const record = surfaceOf(std)?.props.layers?.[id];
53
+ if (record)
54
+ return record.name;
55
+ return id === DEFAULT_LAYER_ID ? seedName(std, 1) : null;
56
+ }
57
+ /**
58
+ * Record the default layer, inside the caller's transaction: the whole
59
+ * `layers` prop while it is absent — as the first creation does — else the
60
+ * one `'@default'` key, below every other layer. The seed name unless the
61
+ * gesture says otherwise.
62
+ */
63
+ function recordDefaultLayer(std, surface, fields = {}) {
64
+ const bottom = userLayersBottomUp(surface)[0]?.record.index ?? null;
65
+ const record = {
66
+ name: seedName(std, 1),
67
+ index: generateKeyBetween(null, bottom),
68
+ ...fields,
69
+ };
70
+ if (!surface.props.layers) {
71
+ surface.props.layers = { [DEFAULT_LAYER_ID]: record };
72
+ }
73
+ else {
74
+ surface.props.layers[DEFAULT_LAYER_ID] = record;
75
+ }
76
+ }
77
+ /**
78
+ * Create a user layer on top of the others and make it this viewer's active
79
+ * layer. Answers its id, or `null` when nothing was written.
80
+ *
81
+ * The FIRST creation writes two records in one transaction: `'@default'`,
82
+ * named through the seam ("Layer 1"), and the new one above it. That one
83
+ * write sets the whole `layers` prop, so two peers doing it at the same
84
+ * moment keep one record set (ADR 0031 open point 6, accepted for v1): the
85
+ * other peer's members fall back to the default layer, nothing is dropped.
86
+ */
87
+ export function createUserLayer(std, name) {
88
+ if (std.store.readonly)
89
+ return null;
90
+ const surface = surfaceOf(std);
91
+ if (!surface)
92
+ return null;
93
+ const existing = userLayersBottomUp(surface);
94
+ const id = nanoid();
95
+ const seed = (n) => seedName(std, n);
96
+ std.store.captureSync();
97
+ std.store.transact(() => {
98
+ if (!existing.length) {
99
+ const bottom = generateKeyBetween(null, null);
100
+ surface.props.layers = {
101
+ [DEFAULT_LAYER_ID]: { name: seed(1), index: bottom },
102
+ [id]: {
103
+ name: name?.trim() || seed(2),
104
+ index: generateKeyBetween(bottom, null),
105
+ },
106
+ };
107
+ return;
108
+ }
109
+ const top = existing[existing.length - 1].record.index;
110
+ surface.props.layers[id] = {
111
+ name: name?.trim() || seed(existing.length + 1),
112
+ index: generateKeyBetween(top, null),
113
+ };
114
+ });
115
+ std.getOptional(CanvasActiveLayer)?.choose(id);
116
+ return id;
117
+ }
118
+ /**
119
+ * Rename a layer: one field of one record. Empty or unchanged writes nothing.
120
+ *
121
+ * The default layer with no record yet is renamed by recording it, named
122
+ * (ADR 0031 amendments): "unchanged" is then against the seed name it shows.
123
+ */
124
+ export function renameUserLayer(std, id, name) {
125
+ if (std.store.readonly)
126
+ return false;
127
+ const surface = surfaceOf(std);
128
+ const record = surface?.props.layers?.[id];
129
+ const shown = userLayerName(std, id);
130
+ const next = name.trim();
131
+ if (!surface || shown === null || !next || next === shown)
132
+ return false;
133
+ std.store.captureSync();
134
+ // Inside the store's transaction, not the props proxy's own: the proxy
135
+ // writes with its own origin, which the undo manager does not track.
136
+ std.store.transact(() => {
137
+ if (record)
138
+ record.name = next;
139
+ else
140
+ recordDefaultLayer(std, surface, { name: next });
141
+ });
142
+ return true;
143
+ }
144
+ /**
145
+ * Move a layer so it sits directly ABOVE `above` — `null` puts it at the
146
+ * bottom. One field (`index`) of one record; a reorder racing a peer's
147
+ * rename of the same layer merges.
148
+ */
149
+ export function reorderUserLayer(std, id, above) {
150
+ if (std.store.readonly || id === above)
151
+ return false;
152
+ const layers = userLayersBottomUp(surfaceOf(std));
153
+ const moving = layers.find(layer => layer.id === id);
154
+ if (!moving)
155
+ return false;
156
+ const others = layers.filter(layer => layer.id !== id);
157
+ let position = 0;
158
+ if (above !== null) {
159
+ const target = others.findIndex(layer => layer.id === above);
160
+ if (target === -1)
161
+ return false;
162
+ position = target + 1;
163
+ }
164
+ const current = layers.indexOf(moving);
165
+ if ((layers[current - 1]?.id ?? null) === above)
166
+ return false;
167
+ const lower = others[position - 1]?.record.index ?? null;
168
+ const upper = others[position]?.record.index ?? null;
169
+ if (lower !== null && upper !== null && lower >= upper)
170
+ return false;
171
+ std.store.captureSync();
172
+ std.store.transact(() => {
173
+ moving.record.index = generateKeyBetween(lower, upper);
174
+ });
175
+ return true;
176
+ }
177
+ /**
178
+ * Hide whole layers for EVERYONE, or show them again (ADR 0031 §7, stage
179
+ * 7): `hidden: true` on each record — one write per layer, never one per
180
+ * member — and the key REMOVED on show, never `false`. Answers how many
181
+ * records were written.
182
+ *
183
+ * Hiding the default layer while it has no record records it, hidden, with
184
+ * its seed name (ADR 0031 amendments); showing it has nothing to write.
185
+ */
186
+ export function setUserLayersHiddenForEveryone(std, ids, hidden) {
187
+ if (std.store.readonly)
188
+ return 0;
189
+ const surface = surfaceOf(std);
190
+ if (!surface)
191
+ return 0;
192
+ const layers = surface.props.layers;
193
+ const targets = ids
194
+ .map(id => layers?.[id])
195
+ .filter((record) => !!record && (record.hidden === true) !== hidden);
196
+ const recordDefault = hidden && ids.includes(DEFAULT_LAYER_ID) && !layers?.[DEFAULT_LAYER_ID];
197
+ if (!targets.length && !recordDefault)
198
+ return 0;
199
+ std.store.captureSync();
200
+ std.store.transact(() => {
201
+ for (const record of targets) {
202
+ if (hidden) {
203
+ record.hidden = true;
204
+ }
205
+ else {
206
+ delete record.hidden;
207
+ }
208
+ }
209
+ if (recordDefault)
210
+ recordDefaultLayer(std, surface, { hidden: true });
211
+ });
212
+ return targets.length + (recordDefault ? 1 : 0);
213
+ }
214
+ /**
215
+ * Delete a user layer WITH its members, in one undo step (ADR 0031 §10).
216
+ * Answers how many models went with it, or `null` when nothing was written.
217
+ *
218
+ * The read-only refusal comes first, then one `captureSync()`, then one
219
+ * transaction: every top-level model whose effective layer is this one (a
220
+ * group or a mindmap takes its descendants with it), then the record. A
221
+ * connector of ANOTHER layer whose ends were here stays, loose, as when its
222
+ * ends are deleted any other way — the members are removed one by one, not
223
+ * through the "delete with connectors" path of the toolbar. A frame of this
224
+ * layer goes; what it holds from other layers stays. `'@default'` cannot be
225
+ * deleted.
226
+ */
227
+ export function deleteUserLayer(std, id) {
228
+ if (std.store.readonly)
229
+ return null;
230
+ if (id === DEFAULT_LAYER_ID)
231
+ return null;
232
+ const surface = surfaceOf(std);
233
+ const layers = surface?.props.layers;
234
+ if (!surface || !layers?.[id])
235
+ return null;
236
+ const gfx = std.get(GfxControllerIdentifier);
237
+ const members = gfx.gfxElements.filter(model => surface.userLayers.effectiveLayerOf(model) === id);
238
+ const carriers = members.filter(model => layerCarrierOf(model) === model);
239
+ std.store.captureSync();
240
+ std.store.transact(() => {
241
+ for (const model of carriers) {
242
+ if (gfx.getElementById(model.id))
243
+ gfx.deleteElement(model);
244
+ }
245
+ delete layers[id];
246
+ });
247
+ std.store.captureSync();
248
+ return members.length;
249
+ }
250
+ /**
251
+ * Write `layer` on one model — set it, or REMOVE the key for the default
252
+ * layer (never the string `'@default'`). Inside the caller's transaction.
253
+ */
254
+ export function writeModelLayer(std, model, layer) {
255
+ if (layer === DEFAULT_LAYER_ID) {
256
+ if (model instanceof GfxPrimitiveElementModel) {
257
+ model.clearField('layer');
258
+ }
259
+ else if (model instanceof GfxBlockElementModel) {
260
+ delete model.props.layer;
261
+ }
262
+ return;
263
+ }
264
+ std.get(GfxControllerIdentifier).updateElement(model, { layer });
265
+ }
266
+ /**
267
+ * Move models to the layer `layerId`. Answers how many models were written —
268
+ * a grouped model moves its outermost group, so that may be fewer than asked.
269
+ * An unknown layer id writes nothing. The default layer always exists, record
270
+ * or not: moving there removes the `layer` key, a dangling id included.
271
+ */
272
+ export function moveModelsToUserLayer(std, ids, layerId) {
273
+ if (std.store.readonly)
274
+ return 0;
275
+ const surface = surfaceOf(std);
276
+ if (!surface)
277
+ return 0;
278
+ if (layerId !== DEFAULT_LAYER_ID && !surface.props.layers?.[layerId]) {
279
+ return 0;
280
+ }
281
+ const gfx = std.get(GfxControllerIdentifier);
282
+ const carriers = new Set();
283
+ for (const id of ids) {
284
+ const model = gfx.getElementById(id);
285
+ if (model instanceof GfxPrimitiveElementModel ||
286
+ model instanceof GfxBlockElementModel) {
287
+ carriers.add(layerCarrierOf(model));
288
+ }
289
+ }
290
+ const targets = [...carriers].filter(model => (ownLayerOf(model) ?? DEFAULT_LAYER_ID) !== layerId);
291
+ if (!targets.length)
292
+ return 0;
293
+ std.store.captureSync();
294
+ std.store.transact(() => {
295
+ for (const model of targets)
296
+ writeModelLayer(std, model, layerId);
297
+ });
298
+ return targets.length;
299
+ }
@@ -0,0 +1,20 @@
1
+ import { LifeCycleWatcher } from '../../../std/index.js';
2
+ /**
3
+ * The layer new elements land in, for THIS viewer (ADR 0031 §6): the one
4
+ * selected in the selection pane, or the default layer.
5
+ *
6
+ * Per viewer and per session — never stored, in the document or anywhere
7
+ * else: a reload starts on the default layer. A layer deleted or never
8
+ * created on this surface resolves to the default layer, so a stale choice
9
+ * cannot send new elements to a dangling id.
10
+ */
11
+ export declare class CanvasActiveLayer extends LifeCycleWatcher {
12
+ static key: string;
13
+ /** The chosen layer id, as chosen; read {@link resolve} for the effective one. */
14
+ readonly chosen$: import("@preact/signals-core").Signal<string>;
15
+ private get _surface();
16
+ /** The layer a new element lands in: the chosen one if it still exists. */
17
+ resolve(): string;
18
+ /** Make `id` the active layer for this viewer. */
19
+ choose(id: string): void;
20
+ }
@@ -0,0 +1,34 @@
1
+ import { LifeCycleWatcher } from '../../../std/index.js';
2
+ import { DEFAULT_LAYER_ID, GfxControllerIdentifier, } from '../../../std/gfx/index.js';
3
+ import { signal } from '@preact/signals-core';
4
+ /**
5
+ * The layer new elements land in, for THIS viewer (ADR 0031 §6): the one
6
+ * selected in the selection pane, or the default layer.
7
+ *
8
+ * Per viewer and per session — never stored, in the document or anywhere
9
+ * else: a reload starts on the default layer. A layer deleted or never
10
+ * created on this surface resolves to the default layer, so a stale choice
11
+ * cannot send new elements to a dangling id.
12
+ */
13
+ export class CanvasActiveLayer extends LifeCycleWatcher {
14
+ constructor() {
15
+ super(...arguments);
16
+ /** The chosen layer id, as chosen; read {@link resolve} for the effective one. */
17
+ this.chosen$ = signal(DEFAULT_LAYER_ID);
18
+ }
19
+ static { this.key = 'canvas-active-layer'; }
20
+ get _surface() {
21
+ return this.std.get(GfxControllerIdentifier).surface;
22
+ }
23
+ /** The layer a new element lands in: the chosen one if it still exists. */
24
+ resolve() {
25
+ const chosen = this.chosen$.value;
26
+ if (chosen === DEFAULT_LAYER_ID)
27
+ return DEFAULT_LAYER_ID;
28
+ return this._surface?.props.layers?.[chosen] ? chosen : DEFAULT_LAYER_ID;
29
+ }
30
+ /** Make `id` the active layer for this viewer. */
31
+ choose(id) {
32
+ this.chosen$.value = id;
33
+ }
34
+ }