platejs 54.0.0-beta.2 → 54.0.0-beta.4

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 (255) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +56 -0
  3. package/dist/{AIChatRequestContext-BMVWhfPV.d.ts → AIChatRequestContext-DrUahdTc.d.ts} +2 -2
  4. package/dist/{BaseSuggestionPlugin-DBl3fqnm.d.ts → BaseSuggestionPlugin-_7Ka6nY3.d.ts} +7 -3
  5. package/dist/{PlateStatic-DhNv2ejp.d.ts → PlateStatic-D3Cb-QwH.d.ts} +7 -7
  6. package/dist/ai/index.d.ts +1 -1
  7. package/dist/ai/react/AIChatPlugin.js +113 -78
  8. package/dist/ai/react/CopilotPlugin.js +1 -1
  9. package/dist/ai/react/index.d.ts +23 -16
  10. package/dist/authored/index.d.ts +4 -4
  11. package/dist/code-block/codemirror/createCodeMirrorAdapter.js +12 -9
  12. package/dist/code-block/codemirror/index.d.ts +1 -1
  13. package/dist/{combobox-DkBGgyd3.d.ts → combobox-Dr0OYZIE.d.ts} +2 -2
  14. package/dist/{comparison-types-CYnJ35qU.d.ts → comparison-types-DdwE6mYq-BogsHoUO.d.ts} +10 -2
  15. package/dist/compiler/index.d.ts +2 -2
  16. package/dist/{core-BJG8l_mk.d.ts → core-BqR-fEDp.d.ts} +493 -116
  17. package/dist/diff/index.d.ts +2 -2
  18. package/dist/docs/ai.md +4 -3
  19. package/dist/docs/api/core/plate-components.md +0 -19
  20. package/dist/docs/api/core/plate-controller.md +5 -3
  21. package/dist/docs/api/core/plate-plugin.md +3 -0
  22. package/dist/docs/api/core/plate-store.md +3 -3
  23. package/dist/docs/api/core.md +45 -5
  24. package/dist/docs/api/dom.md +11 -4
  25. package/dist/docs/api/editor-transforms.md +2 -1
  26. package/dist/docs/api/react-hooks.md +45 -13
  27. package/dist/docs/authored-changes.md +9 -4
  28. package/dist/docs/basic-blocks.md +42 -29
  29. package/dist/docs/block-placeholder.md +4 -2
  30. package/dist/docs/blockquote.md +5 -3
  31. package/dist/docs/board.md +118 -10
  32. package/dist/docs/code-block.md +47 -0
  33. package/dist/docs/comment.md +2 -2
  34. package/dist/docs/discussion.md +1 -1
  35. package/dist/docs/document-model.md +15 -3
  36. package/dist/docs/docx.md +1 -1
  37. package/dist/docs/dom-coverage.md +5 -0
  38. package/dist/docs/editor.md +50 -4
  39. package/dist/docs/examples/editable-voids.md +2 -3
  40. package/dist/docs/external-text.md +2 -0
  41. package/dist/docs/field.md +370 -0
  42. package/dist/docs/find.md +9 -6
  43. package/dist/docs/form.md +2 -0
  44. package/dist/docs/heading.md +6 -0
  45. package/dist/docs/installation/manual.md +0 -4
  46. package/dist/docs/link.md +3 -3
  47. package/dist/docs/llms.txt +4 -2
  48. package/dist/docs/markdown.md +270 -14
  49. package/dist/docs/plugin-components.md +13 -10
  50. package/dist/docs/plugin-input-rules.md +66 -15
  51. package/dist/docs/prompt-editor.md +205 -0
  52. package/dist/docs/roots.md +8 -6
  53. package/dist/docs/rtl.md +6 -4
  54. package/dist/docs/selection.md +7 -4
  55. package/dist/docs/suggestion.md +1 -1
  56. package/dist/docs/toolbar.md +26 -30
  57. package/dist/docs/upload.md +106 -17
  58. package/dist/docx/export/index.d.ts +3 -3
  59. package/dist/docx/export/lib/docxStaticComponents.js +12 -2
  60. package/dist/docx/export/lib/exportDocx.js +46 -17
  61. package/dist/docx/export/lib/internal/xml-builder.js +11 -16
  62. package/dist/docx/export/lib/reviewPart.js +1 -1
  63. package/dist/docx/export/lib/reviewProjection.js +52 -10
  64. package/dist/docx/import/index.d.ts +4 -4
  65. package/dist/docx/paste/index.d.ts +4 -4
  66. package/dist/dom/index.d.ts +1 -6
  67. package/dist/dom/plite-dom.internal.js +2 -2
  68. package/dist/excalidraw/index.d.ts +3 -2
  69. package/dist/excalidraw/react/index.d.ts +3 -2
  70. package/dist/facade.js +2 -2
  71. package/dist/features/basic-nodes/lib/BaseBlockPlugins.js +13 -5
  72. package/dist/features/basic-nodes/lib/BaseHeadingPlugins.js +32 -10
  73. package/dist/features/board/index.d.ts +2 -2
  74. package/dist/features/board/lib/BaseBoardPlugin.js +14 -1
  75. package/dist/features/board/lib/boardStroke.internal.js +13 -1
  76. package/dist/features/board/lib/boardTypes.internal.js +16 -0
  77. package/dist/features/callout/index.d.ts +3 -2
  78. package/dist/features/code-block/lib/BaseCodeBlockPlugin.js +14 -5
  79. package/dist/features/combobox/index.d.ts +2 -2
  80. package/dist/features/comments/BaseCommentsPlugin.js +33 -17
  81. package/dist/features/comments/index.d.ts +1 -1
  82. package/dist/features/date/index.d.ts +3 -2
  83. package/dist/features/details/index.d.ts +3 -2
  84. package/dist/features/details/lib/BaseDetailsPlugin.js +25 -12
  85. package/dist/features/field/index.d.ts +2 -0
  86. package/dist/features/field/index.js +4 -0
  87. package/dist/features/field/lib/BaseFieldPlugin.js +360 -0
  88. package/dist/features/field/lib/applyFieldValues.js +188 -0
  89. package/dist/features/field/lib/fieldRules.internal.js +204 -0
  90. package/dist/features/find/index.d.ts +3 -2
  91. package/dist/features/footnote/index.d.ts +1 -1
  92. package/dist/features/ink/index.d.ts +1 -1
  93. package/dist/features/ink/lib/BaseInkPlugin.js +126 -103
  94. package/dist/features/ink/lib/inkCodec.internal.js +130 -0
  95. package/dist/features/ink/lib/inkGone.internal.js +229 -48
  96. package/dist/features/ink/lib/inkPlaces.internal.js +534 -64
  97. package/dist/features/layout/index.d.ts +1 -1
  98. package/dist/features/link/lib/BaseLinkPlugin.js +6 -4
  99. package/dist/features/lint/index.d.ts +3 -2
  100. package/dist/features/media/index.d.ts +2 -2
  101. package/dist/features/media/index.js +2 -2
  102. package/dist/features/media/lib/media/parseMediaUrl.js +11 -1
  103. package/dist/features/media/lib/media-embed/BaseMediaEmbedPlugin.js +206 -4
  104. package/dist/features/mention/index.d.ts +5 -4
  105. package/dist/features/suggestion/index.d.ts +1 -1
  106. package/dist/features/table/index.d.ts +1 -1
  107. package/dist/features/table/lib/BaseTablePlugin.js +64 -15
  108. package/dist/features/table/lib/internal/selection.js +4 -2
  109. package/dist/features/toc/index.d.ts +1 -1
  110. package/dist/features/upload/index.d.ts +2 -2
  111. package/dist/features/upload/lib/BaseUploadPlugin.js +464 -250
  112. package/dist/history/index.d.ts +2 -2
  113. package/dist/html/index.d.ts +3 -3
  114. package/dist/html/server/index.d.ts +1 -1
  115. package/dist/{htmlTypes-DjeFG3P8.d.ts → htmlTypes-eT2ZGDAj.d.ts} +2 -31
  116. package/dist/hyperscript/index.d.ts +1 -1
  117. package/dist/{index-DzD6BIFJ.d.ts → index-B33E1CRJ.d.ts} +295 -6
  118. package/dist/{index-Cl77E9yr.d.ts → index-B7moSod7.d.ts} +2 -2
  119. package/dist/{index-hsC_sOn2.d.ts → index-B8-5Sr7I.d.ts} +35 -5
  120. package/dist/{index-BiQerPJS.d.ts → index-B8QJDAmG.d.ts} +2 -2
  121. package/dist/{index-BBKGrsG3.d.ts → index-BTx5oK7k.d.ts} +1 -1
  122. package/dist/{index-iaZOhA76.d.ts → index-BWPcE4ac-Cto_IsNs.d.ts} +7 -1
  123. package/dist/{index-BU6k1Aev.d.ts → index-BXjLmx1n-CXk17buG.d.ts} +4781 -4584
  124. package/dist/{index-kLKMc-pI.d.ts → index-BXwU9QH6.d.ts} +2 -2
  125. package/dist/{index-DTgaSxKr.d.ts → index-BkwR-5hH.d.ts} +40 -4
  126. package/dist/{index-Bq3sdm3S.d.ts → index-BsV2McRr.d.ts} +5 -4
  127. package/dist/index-C9Fu-P4E.d.ts +773 -0
  128. package/dist/{index-D5W-p9bS.d.ts → index-Ca48r1ng.d.ts} +49 -4
  129. package/dist/{index-CcZbqPqk.d.ts → index-Cob_iBdu.d.ts} +116 -41
  130. package/dist/{index-Bxfvicyy.d.ts → index-CpY7Xnxw.d.ts} +4 -3
  131. package/dist/{index-BkR7-GLI.d.ts → index-DNQXzU-X.d.ts} +2 -2
  132. package/dist/{index-D1CFXA-i.d.ts → index-DPowErHa.d.ts} +471 -141
  133. package/dist/{index-DaM37gF6.d.ts → index-DShbzec2.d.ts} +38 -23
  134. package/dist/{index-DC_MNGyu.d.ts → index-DYdObeFQ.d.ts} +3 -3
  135. package/dist/{index-Bc2Yg_2j.d.ts → index-Dq3Jlj8O-BJ6NxZm0.d.ts} +2 -2
  136. package/dist/{index-CT7miqQN.d.ts → index-DwWQVwQt.d.ts} +29 -11
  137. package/dist/{index-xdmCBvlT.d.ts → index-JWgwL5l3.d.ts} +5 -2
  138. package/dist/{index-DLA2DUR2.d.ts → index-M781pyx9.d.ts} +4 -3
  139. package/dist/{index-DdIRduDG.d.ts → index-d7io3MzC.d.ts} +3 -2
  140. package/dist/index.d.ts +4 -4
  141. package/dist/{react/internal → internal}/penStroke.internal.js +1 -1
  142. package/dist/internal/plugin/OverridePlugin.js +101 -119
  143. package/dist/internal/plugin/collectPlateNodeMappings.js +5 -1
  144. package/dist/internal/plugin/pastedUploadFiles.js +4 -0
  145. package/dist/internal/plugin/resolvePlugin.js +1 -1
  146. package/dist/internal/plugin/resolvePlugins.js +3 -0
  147. package/dist/internal/plugin/uploadDrafts.js +6 -0
  148. package/dist/internal/utils/mergePlugins.js +1 -0
  149. package/dist/lib/plugins/element-id/ElementIdPlugin.js +14 -18
  150. package/dist/lib/plugins/html/HtmlPlugin.js +9 -0
  151. package/dist/lib/plugins/html/htmlSafety.js +1 -1
  152. package/dist/lib/plugins/input-rules/InputRulesPlugin.js +77 -28
  153. package/dist/lib/plugins/input-rules/inputRuleVeto.internal.js +16 -0
  154. package/dist/markdown/index.d.ts +2 -2
  155. package/dist/markdown/index.js +3 -1
  156. package/dist/markdown/lib/MarkdownPlugin.js +14 -11
  157. package/dist/markdown/lib/RawHtmlPlugin.js +26 -0
  158. package/dist/markdown/lib/deserializer/mdastToSlate.js +12 -2
  159. package/dist/markdown/lib/internal/markdownConversion.js +776 -74
  160. package/dist/markdown/lib/internal/markdownDiagnostics.js +18 -7
  161. package/dist/markdown/lib/internal/markdownFootnoteWriter.js +35 -0
  162. package/dist/markdown/lib/internal/markdownFrontmatter.js +102 -0
  163. package/dist/markdown/lib/internal/markdownIntrinsics.js +125 -43
  164. package/dist/markdown/lib/internal/markdownLine.js +5 -3
  165. package/dist/markdown/lib/internal/markdownMappings.js +19 -7
  166. package/dist/markdown/lib/internal/markdownOpenTail.js +381 -0
  167. package/dist/markdown/lib/internal/markdownRawHtml.js +353 -0
  168. package/dist/markdown/lib/internal/markdownSegments.js +57 -48
  169. package/dist/markdown/lib/internal/markdownTags.js +29 -9
  170. package/dist/markdown/lib/serializer/convertNodesSerialize.js +10 -8
  171. package/dist/markdown/lib/serializer/convertPhrasingSerialize.js +226 -0
  172. package/dist/markdown/lib/serializer/listToMdastTree.js +2 -0
  173. package/dist/math/index.d.ts +3 -2
  174. package/dist/math/react/index.d.ts +4 -3
  175. package/dist/migrations/index.d.ts +3 -3
  176. package/dist/migrations/migratePlateV54.js +4 -6
  177. package/dist/migrations/migratePlateV54RetiredMarks.internal.js +23 -8
  178. package/dist/migrations/migratePlateV54Suggestions.internal.js +2 -2
  179. package/dist/migrations/v53-manifest.internal.js +4 -0
  180. package/dist/pagination/index.d.ts +1 -1
  181. package/dist/pagination/react/index.d.ts +4 -4
  182. package/dist/react/components/EditorContentView.internal.js +42 -23
  183. package/dist/react/components/EditorProvider.js +5 -5
  184. package/dist/react/components/Plate.js +102 -128
  185. package/dist/react/components/PlateContainer.js +40 -32
  186. package/dist/react/components/PlateController.js +28 -16
  187. package/dist/react/components/PlateRoot.internal.js +3 -2
  188. package/dist/react/core.js +4 -4
  189. package/dist/react/features/board/BoardSurface.js +116 -87
  190. package/dist/react/features/board/boardClipboard.internal.js +15 -5
  191. package/dist/react/features/board/boardExport.internal.js +470 -0
  192. package/dist/react/features/board/boardGesture.internal.js +6 -3
  193. package/dist/react/features/board/boardIndex.internal.js +7 -18
  194. package/dist/react/features/board/boardPictureStyles.internal.js +415 -0
  195. package/dist/react/features/board/boardPictures.internal.js +19 -13
  196. package/dist/react/features/board/boardView.internal.js +190 -50
  197. package/dist/react/features/board/boardVoice.internal.js +10 -11
  198. package/dist/react/features/board/index.d.ts +108 -18
  199. package/dist/react/features/callout/index.d.ts +3 -2
  200. package/dist/react/features/combobox/index.d.ts +8 -8
  201. package/dist/react/features/comments/index.d.ts +6 -5
  202. package/dist/react/features/date/index.d.ts +4 -3
  203. package/dist/react/features/details/index.d.ts +4 -3
  204. package/dist/react/features/field/FieldPlugin.js +35 -0
  205. package/dist/react/features/field/index.d.ts +315 -0
  206. package/dist/react/features/field/index.js +2 -0
  207. package/dist/react/features/footnote/index.d.ts +7 -6
  208. package/dist/react/features/format-painter/index.d.ts +4 -3
  209. package/dist/react/features/ink/InkContent.js +313 -0
  210. package/dist/react/features/ink/index.d.ts +57 -33
  211. package/dist/react/features/ink/index.js +2 -2
  212. package/dist/react/features/ink/inkCapture.internal.js +39 -17
  213. package/dist/react/features/ink/inkInput.internal.js +1 -1
  214. package/dist/react/features/ink/inkLayout.internal.js +6 -3
  215. package/dist/react/features/ink/inkPaint.internal.js +78 -2
  216. package/dist/react/features/ink/inkPlacement.internal.js +332 -104
  217. package/dist/react/features/ink/inkWatch.internal.js +7 -5
  218. package/dist/react/features/layout/index.d.ts +5 -4
  219. package/dist/react/features/media/index.d.ts +5 -4
  220. package/dist/react/features/mention/index.d.ts +6 -5
  221. package/dist/react/features/resizable/Resizable.js +4 -6
  222. package/dist/react/features/resizable/index.d.ts +5 -5
  223. package/dist/react/features/suggestion/index.d.ts +6 -5
  224. package/dist/react/features/table/TablePlugin.js +4 -11
  225. package/dist/react/features/table/index.d.ts +10 -8
  226. package/dist/react/features/table/useTableResize.js +10 -1
  227. package/dist/react/features/toc/index.d.ts +2 -2
  228. package/dist/react/features/upload/index.d.ts +11 -6
  229. package/dist/react/index.d.ts +6 -6
  230. package/dist/react/index.js +4 -4
  231. package/dist/react/internal/plate-context.js +434 -188
  232. package/dist/react/plite-react.js +2 -2
  233. package/dist/react/plugins/navigation-feedback/NavigationFeedbackPlugin.js +12 -10
  234. package/dist/react/stores/plate/useEditor.js +32 -14
  235. package/dist/react/stores/plate/useEditorHistory.js +55 -0
  236. package/dist/react/stores/plate/useEditorSelector.js +79 -21
  237. package/dist/react/utils/BlockPlaceholderPlugin.js +5 -2
  238. package/dist/react/utils/pipeRenderElement.internal.js +1 -1
  239. package/dist/react/utils/pluginRenderElement.internal.js +1 -1
  240. package/dist/react/virtualized.d.ts +4 -4
  241. package/dist/{source-CNKy99Th.d.ts → source-BGohy8vH.d.ts} +4 -4
  242. package/dist/static/index.d.ts +18 -18
  243. package/dist/static/internal/renderStaticHtmlWithOverrides.js +2 -2
  244. package/dist/static/internal/staticPresentation.js +4 -4
  245. package/dist/static/internal/writeStaticSelectionClipboardData.js +7 -2
  246. package/dist/tabbable/index.d.ts +1 -1
  247. package/dist/tabbable/react/index.d.ts +3 -3
  248. package/dist/testing/index.d.ts +3 -3
  249. package/dist/yjs/index.d.ts +1 -1
  250. package/dist/yjs/react/index.d.ts +6 -6
  251. package/package.json +20 -2
  252. package/dist/markdown/lib/serializer/convertTextsSerialize.js +0 -163
  253. package/dist/react/components/EditorSelectionView.js +0 -40
  254. package/dist/react/features/ink/InkLayer.js +0 -218
  255. package/dist/react/internal/createPlateTargetScope.js +0 -62
@@ -1,4 +1,6 @@
1
- import { readAuthoredView, subscribeEditorViewState } from "../../../facade.js";
1
+ import { isDocumentView, readAuthoredView, subscribeEditorViewState } from "../../../facade.js";
2
+ import { getCompiledPlateModelBinding } from "../../../internal/plugin/compilePlateModel.js";
3
+ import { PLUGINS } from "../../../utils/plate-keys.js";
2
4
  import { ElementApi, PathApi, SelectionApi, createEditorView } from "../../../core.js";
3
5
  import { frameTakes } from "../../../features/board/lib/boardFrame.internal.js";
4
6
  import { BOARD_STYLE_KEYS, parseBoardStyle } from "../../../features/board/lib/boardStyle.internal.js";
@@ -8,11 +10,13 @@ import { BaseBoardFramePlugin } from "../../../features/board/lib/BaseBoardFrame
8
10
  import { BaseBoardGeoPlugin } from "../../../features/board/lib/BaseBoardGeoPlugin.js";
9
11
  import { BaseBoardImagePlugin } from "../../../features/board/lib/BaseBoardImagePlugin.js";
10
12
  import { BaseBoardNotePlugin } from "../../../features/board/lib/BaseBoardNotePlugin.js";
11
- import { BaseBoardStrokePlugin } from "../../../features/board/lib/BaseBoardStrokePlugin.js";
12
13
  import { shapeIdOf } from "../../../features/board/lib/boardCopy.internal.js";
13
14
  import { keepsBoardRatio } from "../../../features/board/lib/boardRatio.internal.js";
15
+ import { boardTypesOf } from "../../../features/board/lib/boardTypes.internal.js";
14
16
  import { BaseBoardPlugin } from "../../../features/board/lib/BaseBoardPlugin.js";
17
+ import { uploadDraftsOf } from "../../../internal/plugin/uploadDrafts.js";
15
18
  import { createBoardIndex } from "./boardIndex.internal.js";
19
+ import { BOARD_PLACE_SIZE } from "./boardPick.internal.js";
16
20
  import { createBoardVoice } from "./boardVoice.internal.js";
17
21
  import { attachBoardKeys, takeTextTab } from "./boardKeys.internal.js";
18
22
  import { attachBoardClipboard } from "./boardClipboard.internal.js";
@@ -34,6 +38,11 @@ const ZOOM_STEPS = [
34
38
  const WHEEL_STEP_ZOOM = 100;
35
39
  const FIT_PADDING = 32;
36
40
  const PICTURE_GAP = 16;
41
+ const FILE_DRAG_EVENTS = [
42
+ "dragenter",
43
+ "dragover",
44
+ "drop"
45
+ ];
37
46
  const percentOf = (zoom) => Math.round(zoom * 100);
38
47
  const clampZoom = (zoom) => Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom));
39
48
  const scrollsBy = (delta, overflow, at, shown, total) => (overflow === "auto" || overflow === "scroll") && (delta > 0 ? Math.ceil(at + shown) < total : delta < 0 && at > 0);
@@ -72,13 +81,6 @@ const validStyle = (style) => {
72
81
  const showAs = (styles, key, shown) => {
73
82
  styles[key] = shown;
74
83
  };
75
- const TOOL_SHAPES = {
76
- arrow: BaseBoardArrowPlugin.name,
77
- frame: BaseBoardFramePlugin.name,
78
- geo: BaseBoardGeoPlugin.name,
79
- note: BaseBoardNotePlugin.name,
80
- pen: BaseBoardStrokePlugin.name
81
- };
82
84
  const subscribeTo = (listeners) => (listener) => {
83
85
  listeners.add(listener);
84
86
  return () => {
@@ -89,8 +91,11 @@ const SHAPES_EDITABLE = `[data-editor-content-root-slot="${BOARD_SHAPES_SLOT}"]
89
91
  const setShapeSelection = (tx, keys) => tx.selection.setNodes(keys, { mode: shapeSelectionMode(tx.schema, keys.flatMap((key) => tx.nodes.get(key)?.[0] ?? [])) });
90
92
  const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
91
93
  const keyOf = (node) => editor.read((state) => state.key(node));
92
- const board = keyOf(element);
93
94
  const root = editor.read.schema.getElementContentRoots(element)["shapes"] ?? "";
95
+ const shownBoard = mounted.read((state) => state.key(element));
96
+ const ownerBoard = editor.read.roots().find((entry) => entry.root === root)?.owners[0];
97
+ const board = ownerBoard && (ownerBoard.root ? createEditorView(editor, { root: ownerBoard.root }) : editor).key(ownerBoard.path);
98
+ if (!board) throw new Error("A board view needs its board in the editor.");
94
99
  const rootView = createEditorView(editor, { root });
95
100
  const boards = editor.plugin(BaseBoardPlugin);
96
101
  const shownBoards = mounted.plugin(BaseBoardPlugin);
@@ -98,6 +103,14 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
98
103
  const authored = readAuthoredView(shapes);
99
104
  return !shapes.read.view.isReadOnly() && !(authored && "preview" in authored);
100
105
  };
106
+ const takesPictureFiles = () => {
107
+ const image = editor.plugin(BaseBoardImagePlugin);
108
+ const holds = image.installed && editor.read.schema.element(image.schema.type)?.content?.allowedElementTypes || [];
109
+ return writable() && [PLUGINS.upload, PLUGINS.image].every((name) => {
110
+ const type = getCompiledPlateModelBinding(editor, name)?.elementType;
111
+ return !!type && holds.includes(type);
112
+ });
113
+ };
101
114
  let state = {
102
115
  camera: {
103
116
  x: 0,
@@ -107,6 +120,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
107
120
  nextStyle: {},
108
121
  selectedShapes: [],
109
122
  styles: {},
123
+ takesPictureFiles: takesPictureFiles(),
110
124
  tool: "select",
111
125
  toolLocked: false,
112
126
  writable: writable()
@@ -119,7 +133,15 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
119
133
  const notifyErasing = (ids) => {
120
134
  for (const id of ids) for (const listener of erasingListeners.get(id) ?? []) listener();
121
135
  };
122
- const takes = (type, key) => key === "geo" ? type === BaseBoardGeoPlugin.name : editor.read.schema.property({
136
+ const types = boardTypesOf(editor);
137
+ const toolShapes = {
138
+ arrow: () => BaseBoardArrowPlugin.name,
139
+ frame: () => BaseBoardFramePlugin.name,
140
+ geo: types.geo,
141
+ note: types.note,
142
+ pen: types.stroke
143
+ };
144
+ const takes = (type, key) => key === "geo" ? type === types.geo() : editor.read.schema.property({
123
145
  key,
124
146
  placement: "element",
125
147
  type
@@ -142,6 +164,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
142
164
  };
143
165
  const styleFor = (type, style) => {
144
166
  const taken = {};
167
+ if (type === void 0) return taken;
145
168
  const take = (key) => {
146
169
  if (style[key] !== void 0 && takes(type, key)) taken[key] = style[key];
147
170
  };
@@ -158,7 +181,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
158
181
  }];
159
182
  };
160
183
  const stylesOf = ({ nextStyle, selectedShapes, tool }) => {
161
- const next = TOOL_SHAPES[tool];
184
+ const next = toolShapes[tool]?.();
162
185
  const targets = tool === "select" ? styleTargets(selectedShapes).map(({ node }) => storedStylesOf(node)) : [];
163
186
  const styles = {};
164
187
  const valuesOf = (key) => {
@@ -206,9 +229,10 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
206
229
  }) ?? false,
207
230
  isEmpty: (block) => editor.read.nodes.isEmpty(block),
208
231
  keepsRatio: keepsBoardRatio(editor),
232
+ types,
209
233
  members: () => {
210
234
  const shown = new Map(shownView.read.children().map((node, at) => [ElementApi.isElement(node) ? shapeIdOf(node) : "", shownView.key([at])]));
211
- const entries = shownBoards.read.shapes(board).filter(({ id }) => shown.has(id));
235
+ const entries = shownBoards.read.shapes(shownBoard).filter(({ id }) => shown.has(id));
212
236
  renderedKeyOf = new Map(entries.flatMap(({ id, key }) => {
213
237
  const rendered = shown.get(id);
214
238
  return rendered ? [[key, rendered]] : [];
@@ -240,6 +264,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
240
264
  let layer = null;
241
265
  let zoomLayer = null;
242
266
  const focusTarget = React$1.createRef();
267
+ let pictureHost = null;
243
268
  let surface = null;
244
269
  let gestures = null;
245
270
  let interaction = null;
@@ -288,14 +313,16 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
288
313
  const listed = keys.size === 0 ? [] : index.entries().filter((entry) => keys.has(entry.key)).map(withShownNode);
289
314
  const selected = sameShapes(listed, state.selectedShapes) ? state.selectedShapes : listed;
290
315
  const canWrite = writable();
316
+ const takesFiles = takesPictureFiles();
291
317
  const styles = stylesOf({
292
318
  ...state,
293
319
  selectedShapes: selected
294
320
  });
295
- if (selected !== state.selectedShapes || canWrite !== state.writable || styles !== state.styles) publish({
321
+ if (selected !== state.selectedShapes || canWrite !== state.writable || takesFiles !== state.takesPictureFiles || styles !== state.styles) publish({
296
322
  ...state,
297
323
  selectedShapes: selected,
298
324
  styles,
325
+ takesPictureFiles: takesFiles,
299
326
  writable: canWrite
300
327
  });
301
328
  };
@@ -424,7 +451,9 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
424
451
  y: y + height / 2
425
452
  };
426
453
  };
427
- const selectedKeys = () => editor.read.selection.nodeMode() ? new Set(editor.read.selection.nodes().map(([node]) => keyOf(node))) : /* @__PURE__ */ new Set();
454
+ const shownLayoutOf = (node) => ElementApi.isElement(node) ? index.byId(shapeIdOf(node)) : void 0;
455
+ const selectedNodes = () => editor.read.selection.nodeMode() ? editor.read.selection.nodes() : [];
456
+ const selectedKeys = () => new Set(selectedNodes().flatMap(([node]) => shownLayoutOf(node)?.key ?? []));
428
457
  const selectedShapes = () => {
429
458
  const keys = selectedKeys();
430
459
  return index.entries().flatMap((entry) => {
@@ -496,7 +525,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
496
525
  };
497
526
  const editedShape = () => {
498
527
  const key = editedKey();
499
- return key ? index.layout(key) ?? null : null;
528
+ return (key && shownLayoutOf(editor.read.nodes.get(key)?.[0])) ?? null;
500
529
  };
501
530
  const focusRoot = () => {
502
531
  surface?.querySelector(SHAPES_EDITABLE)?.focus({ preventScroll: true });
@@ -511,12 +540,13 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
511
540
  editor.api.dom.deselect();
512
541
  return true;
513
542
  };
514
- const select = (keys) => {
515
- const order = new Map(index.entries().map((entry, at) => [entry.key, at]));
516
- const sorted = keys.toSorted((a, b) => (order.get(a) ?? 0) - (order.get(b) ?? 0));
543
+ const selectIds = (ids) => {
544
+ const order = new Map(index.entries().map((entry, at) => [entry.id, at]));
545
+ const sorted = ids.toSorted((a, b) => (order.get(a) ?? 0) - (order.get(b) ?? 0));
517
546
  deselectOnBoard();
518
- editor.update((tx) => setShapeSelection(tx, sorted));
547
+ editor.update((tx) => setShapeSelection(tx, sorted.flatMap((id) => tx.unique.holder("shapeId", id)?.key ?? [])));
519
548
  };
549
+ const select = (keys) => selectIds(keys.flatMap((key) => index.layout(key)?.id ?? []));
520
550
  const focusBoard = () => {
521
551
  const edited = editedShape();
522
552
  if (edited) select([edited.key]);
@@ -563,10 +593,9 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
563
593
  if (holder) setShapeSelection(tx, [holder.key]);
564
594
  return written;
565
595
  });
566
- const inserted = id && boards.read.shape(id);
567
- if (!inserted) return false;
596
+ if (!id || !boards.read.shape(id)) return false;
568
597
  if (!state.toolLocked) setState({ tool: "select" });
569
- select([inserted.key]);
598
+ selectIds([id]);
570
599
  return true;
571
600
  };
572
601
  const placeShape = (tool, box, { style, takesShapes = false }) => {
@@ -591,18 +620,14 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
591
620
  if (tool === "frame") return tx.plugin(BaseBoardFramePlugin).insert(box, { board });
592
621
  if (tool === "note") return tx.plugin(BaseBoardNotePlugin).insert({
593
622
  ...box,
594
- ...styleFor(BaseBoardNotePlugin.name, style)
623
+ ...styleFor(types.note(), style)
595
624
  }, { board });
596
625
  return tx.plugin(BaseBoardGeoPlugin).insert({
597
626
  ...box,
598
- ...styleFor(BaseBoardGeoPlugin.name, style)
627
+ ...styleFor(types.geo(), style)
599
628
  }, { board });
600
629
  });
601
630
  };
602
- const selectIds = (ids) => select(ids.flatMap((id) => {
603
- const shape = boards.read.shape(id);
604
- return shape ? [shape.key] : [];
605
- }));
606
631
  const land = (slice, place) => {
607
632
  const ids = write((tx) => tx.plugin(BaseBoardPlugin).insertCopy(slice, {
608
633
  board,
@@ -614,25 +639,59 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
614
639
  };
615
640
  const pendingPictures = createPendingPictures({
616
641
  editor,
617
- mounted,
642
+ shapes,
618
643
  writable
619
644
  });
620
- const landPictures = (images, point) => {
645
+ const landRow = (tx, children, sizes, point) => {
646
+ const width = sizes.reduce((total, box) => total + box.width, 0) + PICTURE_GAP * (sizes.length - 1);
647
+ let x = point.x - width / 2;
648
+ return children.flatMap((child, at) => {
649
+ const box = sizes[at];
650
+ const id = tx.plugin(BaseBoardImagePlugin).insert({
651
+ children: [child],
652
+ ...box,
653
+ x,
654
+ y: point.y - box.height / 2
655
+ }, { board });
656
+ x += box.width + PICTURE_GAP;
657
+ return id ?? [];
658
+ });
659
+ };
660
+ const landPictureFiles = (files, point, refused) => {
661
+ if (!surface || files.length === 0) return;
662
+ pendingPictures.load(surface, files, (sizes) => {
663
+ const ids = write((tx) => {
664
+ const upload = uploadDraftsOf(tx);
665
+ let taken = files;
666
+ let batch = upload?.admit(taken, { kind: "image" });
667
+ if (batch && "failure" in batch && batch.failure.code === "unsupported-file-type") {
668
+ const others = new Set(batch.failure.files);
669
+ taken = files.filter((file) => !others.has(file));
670
+ batch = upload?.admit(taken, { kind: "image" });
671
+ }
672
+ if (!batch || "failure" in batch) return [];
673
+ const landed = landRow(tx, batch.drafts, taken.map((file) => sizes[files.indexOf(file)]), point);
674
+ batch.fill(landed.flatMap((id) => {
675
+ const holder = tx.unique.holder("shapeId", id);
676
+ const shape = holder && tx.nodes.get(holder.key)?.[0];
677
+ const draft = shape && ElementApi.isElement(shape) && shape.children[0];
678
+ return draft && tx.key(draft) || [];
679
+ }));
680
+ return landed;
681
+ });
682
+ if (ids && ids.length > 0) selectIds(ids);
683
+ else refused?.();
684
+ });
685
+ };
686
+ const landPictures = (images, point, fallbackFiles = []) => {
621
687
  if (!surface) return;
622
- pendingPictures.load(surface, images, (loaded) => {
623
- const width = loaded.reduce((total, { size: box }) => total + box.width, 0) + PICTURE_GAP * (loaded.length - 1);
624
- let x = point.x - width / 2;
625
- const ids = write((tx) => loaded.flatMap(({ element: image, size: box }) => {
626
- const id = tx.plugin(BaseBoardImagePlugin).insert({
627
- children: [image],
628
- ...box,
629
- x,
630
- y: point.y - box.height / 2
631
- }, { board });
632
- x += box.width + PICTURE_GAP;
633
- return id ?? [];
634
- }));
635
- if (ids) selectIds(ids);
688
+ pendingPictures.load(surface, images.map(({ url }) => String(url)), (sizes, failed) => {
689
+ const landLinks = () => {
690
+ const ids = write((tx) => landRow(tx, images, sizes, point));
691
+ if (ids) selectIds(ids);
692
+ };
693
+ if (failed && fallbackFiles.length > 0) landPictureFiles(fallbackFiles, point, landLinks);
694
+ else landLinks();
636
695
  });
637
696
  };
638
697
  const paste = (data) => {
@@ -641,6 +700,37 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
641
700
  shownView.update((tx) => setShapeSelection(tx, keys));
642
701
  return !!shownView.api.dom.clipboard.insertData(data);
643
702
  };
703
+ const pasteNote = (data, point) => {
704
+ const { height, width } = BOARD_PLACE_SIZE.note;
705
+ return insertAndSelect((tx) => {
706
+ const id = tx.plugin(BaseBoardNotePlugin).insert({
707
+ height,
708
+ width,
709
+ x: point.x - width / 2,
710
+ y: point.y - height / 2,
711
+ ...styleFor(types.note(), state.nextStyle)
712
+ }, { board });
713
+ const holder = id && tx.unique.holder("shapeId", id);
714
+ const shape = holder && tx.nodes.get(holder.key);
715
+ if (shape) {
716
+ const at = {
717
+ offset: 0,
718
+ path: [
719
+ ...shape[1],
720
+ 0,
721
+ 0
722
+ ],
723
+ root
724
+ };
725
+ tx.selection.set({
726
+ anchor: at,
727
+ focus: at
728
+ });
729
+ shownView.api.dom.clipboard.insertData(data);
730
+ }
731
+ return id;
732
+ });
733
+ };
644
734
  const core = {
645
735
  replaceInteraction: (next) => {
646
736
  cancelInteraction();
@@ -670,9 +760,12 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
670
760
  viewBox,
671
761
  commit,
672
762
  edit: (key) => {
763
+ const id = index.layout(key)?.id;
764
+ if (!id || !boards.read.shape(id)) return;
673
765
  focusRoot();
674
766
  editor.update((tx) => {
675
- const end = tx.points.end(key);
767
+ const owned = tx.unique.holder("shapeId", id)?.key;
768
+ const end = owned && tx.points.end(owned);
676
769
  if (end) tx.selection.set(end);
677
770
  });
678
771
  },
@@ -690,6 +783,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
690
783
  },
691
784
  deselectOnBoard,
692
785
  land,
786
+ landPictureFiles,
693
787
  landPictures,
694
788
  leaveBoard: (backward) => {
695
789
  if (!writable()) {
@@ -719,6 +813,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
719
813
  });
720
814
  },
721
815
  paste,
816
+ pasteNote,
722
817
  place: placeShape,
723
818
  redo: () => {
724
819
  if (writable()) history?.redo();
@@ -747,6 +842,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
747
842
  slice: (ids) => boards.read.slice(ids),
748
843
  state: () => state,
749
844
  styleFor,
845
+ takesPictureFiles,
750
846
  toggleSelected: (key) => {
751
847
  const keys = selectedShapes().map((shape) => shape.key);
752
848
  select(keys.includes(key) ? keys.filter((held) => held !== key) : [...keys, key]);
@@ -794,10 +890,25 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
794
890
  y: camera.y + event.deltaY / camera.zoom
795
891
  });
796
892
  };
893
+ const onFileDrag = (event) => {
894
+ const data = event.dataTransfer;
895
+ if (!data || !Array.from(data.types).includes("Files") || editedShape() || !takesPictureFiles()) return;
896
+ event.preventDefault();
897
+ event.stopPropagation();
898
+ data.dropEffect = "copy";
899
+ mounted.api.dom.drag.indicate(null);
900
+ if (event.type !== "drop") return;
901
+ measure();
902
+ landPictureFiles(Array.from(data.files), boardPointAt({
903
+ x: event.clientX,
904
+ y: event.clientY
905
+ }));
906
+ };
797
907
  const keys = attachBoardKeys(host, core);
798
908
  gestures = attachBoardGestures(host, core, keys.spaceHeld);
799
909
  const detachClipboard = attachBoardClipboard(host, core);
800
910
  host.addEventListener("wheel", onWheel, { passive: false });
911
+ for (const type of FILE_DRAG_EVENTS) host.addEventListener(type, onFileDrag);
801
912
  return () => {
802
913
  gestures?.detach();
803
914
  gestures = null;
@@ -810,6 +921,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
810
921
  surface = null;
811
922
  resizeObserver.disconnect();
812
923
  host.removeEventListener("wheel", onWheel);
924
+ for (const type of FILE_DRAG_EVENTS) host.removeEventListener(type, onFileDrag);
813
925
  keys.detach();
814
926
  detachClipboard();
815
927
  pendingPictures.cancel();
@@ -818,8 +930,13 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
818
930
  index.update();
819
931
  shownVersion = index.version();
820
932
  refresh();
821
- return {
933
+ const view = {
822
934
  actions: {
935
+ exportPicture: async ({ format, kit }) => {
936
+ const selected = selectedShapes().map(({ id }) => id);
937
+ const [{ drawBoardPicture }, plugins] = await Promise.all([import("./boardExport.internal.js"), kit]);
938
+ return drawBoardPicture(view, selected, format, plugins);
939
+ },
823
940
  fit,
824
941
  focus: () => {
825
942
  core.focusBoard();
@@ -834,8 +951,8 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
834
951
  const valid = validStyle(style);
835
952
  if (Object.keys(valid).length === 0) return;
836
953
  const edited = editedKey();
837
- const keys = edited ? /* @__PURE__ */ new Set([edited]) : selectedKeys();
838
- const picks = state.tool === "select" ? boards.read.shapes(board).filter(({ key }) => keys.has(key)).flatMap(({ id, node }) => {
954
+ const ownerKeys = new Set(edited ? [edited] : selectedNodes().map(([node]) => keyOf(node)));
955
+ const picks = state.tool === "select" ? boards.read.shapes(board).filter(({ key }) => ownerKeys.has(key)).flatMap(({ id, node }) => {
839
956
  const taken = styleFor(node.type, valid);
840
957
  return Object.keys(taken).length > 0 ? [{
841
958
  id,
@@ -855,6 +972,9 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
855
972
  },
856
973
  setTool: core.setTool,
857
974
  setToolLocked: core.setToolLocked,
975
+ upload: (files) => {
976
+ if (takesPictureFiles()) landPictureFiles(files, viewCenter());
977
+ },
858
978
  zoomIn: core.zoomIn,
859
979
  zoomOut: core.zoomOut
860
980
  },
@@ -874,7 +994,8 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
874
994
  if (reshaped || reschemed || changed.hasAny("selection") || editor.read.selection.nodeMode()) showSelection();
875
995
  if (changed.hasAny("selection")) voice.selectionChanged();
876
996
  });
877
- const unsubscribeViewState = subscribeEditorViewState(shapes, () => {
997
+ const unsubscribeViewState = subscribeEditorViewState(shapes, (change) => {
998
+ if (change !== "readOnly" && change !== "authored") return;
878
999
  gestures?.refuseWrites();
879
1000
  shownView = createEditorView(mounted, { root });
880
1001
  follow();
@@ -895,6 +1016,24 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
895
1016
  if (!index.byId(id)) index.update();
896
1017
  return index.shownLayout(id);
897
1018
  },
1019
+ holdPictureHost: (host) => {
1020
+ pictureHost = host;
1021
+ },
1022
+ pictureSource: (selected) => {
1023
+ const host = pictureHost;
1024
+ if (!host?.isConnected) return null;
1025
+ index.update();
1026
+ const picked = new Set(selected);
1027
+ for (const id of selected) for (const member of index.membersOf(id) ?? []) picked.add(member);
1028
+ const authored = isDocumentView(editor) ? void 0 : readAuthoredView(shapes);
1029
+ return {
1030
+ editor,
1031
+ host,
1032
+ layouts: [...index.layouts()].filter(({ id }) => selected.length === 0 || picked.has(id)).sort((a, b) => a.rank - b.rank),
1033
+ projection: authored && ("preview" in authored ? authored.preview : "proposed"),
1034
+ root
1035
+ };
1036
+ },
898
1037
  renderWith: (next) => {
899
1038
  ({history, messages} = next);
900
1039
  },
@@ -928,6 +1067,7 @@ const createBoardView = (editor, mounted, element, initialMessages, shapes) => {
928
1067
  takeTextTab: (event) => takeTextTab(core, event),
929
1068
  viewport: () => viewport
930
1069
  };
1070
+ return view;
931
1071
  };
932
1072
  const BoardViewContext = React$1.createContext(null);
933
1073
  const useBoardViewContext = () => {
@@ -1,16 +1,7 @@
1
1
  import { NodeApi, screenReaderAnnouncementEffect } from "../../../core.js";
2
2
  import "../../../features/board/lib/boardFrame.internal.js";
3
- import { BaseBoardFramePlugin } from "../../../features/board/lib/BaseBoardFramePlugin.js";
4
- import { BaseBoardGeoPlugin } from "../../../features/board/lib/BaseBoardGeoPlugin.js";
5
- import { BaseBoardNotePlugin } from "../../../features/board/lib/BaseBoardNotePlugin.js";
6
- import { BaseBoardStrokePlugin } from "../../../features/board/lib/BaseBoardStrokePlugin.js";
3
+ import { boardTypesOf } from "../../../features/board/lib/boardTypes.internal.js";
7
4
  //#region src/react/features/board/boardVoice.internal.ts
8
- const KINDS = /* @__PURE__ */ new Map([
9
- [BaseBoardFramePlugin.name, "frame"],
10
- [BaseBoardGeoPlugin.name, "geo"],
11
- [BaseBoardNotePlugin.name, "note"],
12
- [BaseBoardStrokePlugin.name, "stroke"]
13
- ]);
14
5
  const textOf = (node) => {
15
6
  if (node.type === "boardFrame") return typeof node.name === "string" ? node.name : "";
16
7
  return node.children.map((child) => NodeApi.string(child)).filter(Boolean).join(" ");
@@ -26,10 +17,18 @@ const createBoardVoice = ({ editing, editor, index, members, messages, selectedS
26
17
  let owed = null;
27
18
  let pending = null;
28
19
  let selection = [];
20
+ const types = boardTypesOf(editor);
21
+ const kindOf = (type) => {
22
+ if (type === "boardFrame") return "frame";
23
+ if (type === types.geo()) return "geo";
24
+ if (type === types.note()) return "note";
25
+ if (type === types.stroke()) return "stroke";
26
+ return "shape";
27
+ };
29
28
  const describe = (entry, entries) => {
30
29
  const text = textOf(entry.node);
31
30
  if (entry.kind !== "arrow") return {
32
- kind: KINDS.get(entry.node.type) ?? "shape",
31
+ kind: kindOf(entry.node.type),
33
32
  text
34
33
  };
35
34
  const endOf = (side) => {