edytor 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/README.md +19 -4
  2. package/dist/block/block.svelte.js +2 -4
  3. package/dist/clipboard/htmlFlow.d.ts +20 -7
  4. package/dist/clipboard/htmlFlow.js +23 -15
  5. package/dist/clipboard/serializeClipboardFragment.d.ts +37 -4
  6. package/dist/clipboard/serializeClipboardFragment.js +6 -4
  7. package/dist/clipboard/textBlocks.d.ts +8 -0
  8. package/dist/clipboard/textBlocks.js +6 -2
  9. package/dist/cloudflare/room/admission.js +3 -3
  10. package/dist/cloudflare/room/context.d.ts +1 -1
  11. package/dist/cloudflare/routeDocumentSocket.d.ts +17 -0
  12. package/dist/cloudflare/routeDocumentSocket.js +53 -0
  13. package/dist/collaboration/comments/client.d.ts +1 -1
  14. package/dist/collaboration/comments/client.js +1 -1
  15. package/dist/collaboration/remoteSelection.js +3 -3
  16. package/dist/components/Edytor.svelte +2 -10
  17. package/dist/components/Edytor.svelte.d.ts +1 -3
  18. package/dist/crdt/admission.d.ts +5 -10
  19. package/dist/crdt/admission.js +5 -11
  20. package/dist/crdt/doc/funnel.d.ts +7 -6
  21. package/dist/crdt/doc/funnel.js +10 -9
  22. package/dist/crdt/doc/gate.d.ts +0 -17
  23. package/dist/crdt/doc/gate.js +2 -41
  24. package/dist/crdt/doc/history.js +2 -2
  25. package/dist/crdt/document.d.ts +5 -14
  26. package/dist/crdt/document.js +5 -19
  27. package/dist/crdt/edytor-doc.d.ts +4 -4
  28. package/dist/crdt/edytor-doc.js +3 -7
  29. package/dist/crdt/index.d.ts +3 -3
  30. package/dist/crdt/index.js +2 -2
  31. package/dist/crdt/protocol.d.ts +2 -2
  32. package/dist/crdt/protocol.js +2 -2
  33. package/dist/crdt/providers/index.d.ts +1 -1
  34. package/dist/crdt/providers/room.d.ts +10 -9
  35. package/dist/crdt/providers/room.js +13 -10
  36. package/dist/crdt/providers/websocket.d.ts +1 -1
  37. package/dist/crdt/providers/websocket.js +28 -29
  38. package/dist/crdt/semantics.js +3 -1
  39. package/dist/dnd/autoScroll.d.ts +15 -7
  40. package/dist/dnd/autoScroll.js +10 -15
  41. package/dist/dnd/dropIndicator.js +2 -5
  42. package/dist/dnd/external.d.ts +6 -0
  43. package/dist/dnd/external.js +17 -0
  44. package/dist/dnd/geometry.d.ts +2 -0
  45. package/dist/dnd/geometry.js +3 -4
  46. package/dist/dnd/placement.d.ts +1 -1
  47. package/dist/dnd/pragmatic.d.ts +3 -1
  48. package/dist/dnd/pragmatic.js +12 -2
  49. package/dist/dnd/vendor/pragmatic/UPSTREAM.md +51 -18
  50. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/drop-target-for-external.d.ts +4 -0
  51. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/drop-target-for-external.js +6 -0
  52. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/element-adapter.d.ts +0 -2
  53. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/element-adapter.js +4 -22
  54. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/external-adapter-types.d.ts +26 -0
  55. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/external-adapter.d.ts +30 -0
  56. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/external-adapter.js +203 -0
  57. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/get-available-items.js +13 -0
  58. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/get-available-types.js +9 -0
  59. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/is-an-available-type.js +19 -0
  60. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/monitor-for-external.d.ts +4 -0
  61. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/adapter/monitor-for-external.js +6 -0
  62. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/honey-pot-fix/make-honey-pot-fix.js +4 -16
  63. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/internal-types.d.ts +1 -8
  64. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/make-adapter/make-drop-target.js +5 -6
  65. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/make-adapter/make-monitor.js +2 -3
  66. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/element/custom-native-drag-preview/set-custom-native-drag-preview.d.ts +1 -1
  67. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/element/custom-native-drag-preview/set-custom-native-drag-preview.js +6 -24
  68. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/contains-files.d.ts +2 -0
  69. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/contains-files.js +5 -0
  70. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/get-files.d.ts +3 -0
  71. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/get-files.js +12 -0
  72. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/public-utils/external/native-types.d.ts +12 -0
  73. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/changing-window/is-entering-window-in-safari.js +10 -0
  74. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/changing-window/is-entering-window.js +55 -0
  75. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/entry-point/external.d.ts +4 -0
  76. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/entry-point/external.js +8 -0
  77. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/internal-types.d.ts +0 -4
  78. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/over-element/get-scroll-by.js +16 -72
  79. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/over-element/try-scroll.js +1 -9
  80. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/shared/configuration.js +4 -29
  81. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/shared/get-scroll-change.js +2 -3
  82. package/dist/edytor.svelte.d.ts +2 -5
  83. package/dist/edytor.svelte.js +17 -31
  84. package/dist/events/onBeforeInput.js +1 -1
  85. package/dist/events/onDrop.d.ts +0 -6
  86. package/dist/events/onDrop.js +10 -23
  87. package/dist/events/onInput.d.ts +0 -12
  88. package/dist/events/onInput.js +1 -67
  89. package/dist/export/forms.d.ts +627 -0
  90. package/dist/export/forms.js +749 -0
  91. package/dist/export/index.d.ts +170 -0
  92. package/dist/export/index.js +161 -0
  93. package/dist/export/markdown.d.ts +41 -0
  94. package/dist/export/markdown.js +585 -0
  95. package/dist/export/markdownWriter.d.ts +9 -0
  96. package/dist/export/markdownWriter.js +133 -0
  97. package/dist/export/mdx.d.ts +15 -0
  98. package/dist/export/mdx.js +33 -0
  99. package/dist/index.d.ts +3 -3
  100. package/dist/index.js +1 -1
  101. package/dist/kinds.js +1 -1
  102. package/dist/plugins/anchored.svelte.d.ts +21 -25
  103. package/dist/plugins/anchored.svelte.js +23 -39
  104. package/dist/plugins/blockHandles/BlockHandleController.svelte.js +24 -32
  105. package/dist/plugins/blockHandles/dragPreview.d.ts +26 -7
  106. package/dist/plugins/blockHandles/dragPreview.js +33 -0
  107. package/dist/plugins/blockMenu/BlockMenuController.svelte.d.ts +5 -0
  108. package/dist/plugins/blockMenu/BlockMenuController.svelte.js +7 -2
  109. package/dist/plugins/blockMenu/blockMenuPlugin.js +5 -50
  110. package/dist/plugins/chrome.d.ts +27 -5
  111. package/dist/plugins/chrome.js +24 -9
  112. package/dist/plugins/code/CodePlugin.svelte +12 -9
  113. package/dist/plugins/code/header.svelte.js +7 -11
  114. package/dist/plugins/code/languageMenu.svelte.d.ts +5 -2
  115. package/dist/plugins/code/languageMenu.svelte.js +13 -20
  116. package/dist/plugins/columns/ColumnsPlugin.svelte +7 -20
  117. package/dist/plugins/columns/resize.svelte.d.ts +2 -3
  118. package/dist/plugins/columns/resize.svelte.js +2 -5
  119. package/dist/plugins/comments/CommentsController.svelte.d.ts +6 -0
  120. package/dist/plugins/comments/CommentsController.svelte.js +20 -0
  121. package/dist/plugins/equation/EquationPlugin.svelte +12 -22
  122. package/dist/plugins/equation/equation.svelte.d.ts +7 -15
  123. package/dist/plugins/equation/equation.svelte.js +13 -50
  124. package/dist/plugins/equation/tex.d.ts +17 -0
  125. package/dist/plugins/equation/tex.js +42 -0
  126. package/dist/plugins/fileDrop.d.ts +38 -23
  127. package/dist/plugins/fileDrop.js +82 -76
  128. package/dist/plugins/find/FindController.svelte.d.ts +5 -0
  129. package/dist/plugins/find/FindController.svelte.js +14 -14
  130. package/dist/plugins/find/findPlugin.js +1 -15
  131. package/dist/plugins/image/ImageChrome.svelte +8 -2
  132. package/dist/plugins/image/ImagePlugin.svelte +15 -52
  133. package/dist/plugins/image/controls.svelte.js +16 -2
  134. package/dist/plugins/image/toolbar.svelte.d.ts +5 -4
  135. package/dist/plugins/image/toolbar.svelte.js +21 -31
  136. package/dist/plugins/index.d.ts +1 -1
  137. package/dist/plugins/list.svelte.d.ts +9 -0
  138. package/dist/plugins/list.svelte.js +18 -0
  139. package/dist/plugins/marquee/marqueePlugin.js +0 -4
  140. package/dist/plugins/media/AudioPlugin.svelte +1 -1
  141. package/dist/plugins/media/BookmarkPlugin.svelte +6 -97
  142. package/dist/plugins/media/EmbedPlugin.svelte +5 -90
  143. package/dist/plugins/media/EmptySlot.svelte +36 -20
  144. package/dist/plugins/media/EmptySlot.svelte.d.ts +6 -15
  145. package/dist/plugins/media/FilePlugin.svelte +1 -19
  146. package/dist/plugins/media/MediaEmpty.svelte +2 -55
  147. package/dist/plugins/media/MediaEmpty.svelte.d.ts +18 -14
  148. package/dist/plugins/media/SourceBlock.svelte +142 -52
  149. package/dist/plugins/media/SourceBlock.svelte.d.ts +10 -4
  150. package/dist/plugins/media/VideoPlugin.svelte +1 -1
  151. package/dist/plugins/media/empty.svelte.js +2 -7
  152. package/dist/plugins/media/media.d.ts +2 -63
  153. package/dist/plugins/media/media.js +1 -194
  154. package/dist/plugins/media/sources.d.ts +60 -0
  155. package/dist/plugins/media/sources.js +165 -0
  156. package/dist/plugins/media/urlPaste.svelte.d.ts +2 -1
  157. package/dist/plugins/media/urlPaste.svelte.js +12 -21
  158. package/dist/plugins/mention/MentionPlugin.svelte +8 -35
  159. package/dist/plugins/page/PagePlugin.svelte +2 -9
  160. package/dist/plugins/page/page.js +1 -1
  161. package/dist/plugins/pageLink/PageLinkPlugin.svelte +6 -13
  162. package/dist/plugins/richtext/RichTextPlugin.svelte +85 -197
  163. package/dist/plugins/richtext/body.js +1 -1
  164. package/dist/plugins/richtext/calloutIcons.svelte.d.ts +2 -2
  165. package/dist/plugins/richtext/calloutIcons.svelte.js +5 -7
  166. package/dist/plugins/richtext/richTextOperations.d.ts +1 -19
  167. package/dist/plugins/richtext/richTextOperations.js +3 -49
  168. package/dist/plugins/slashMenu/SlashMenuController.svelte.d.ts +2 -0
  169. package/dist/plugins/slashMenu/SlashMenuController.svelte.js +7 -0
  170. package/dist/plugins/slashMenu/slashMenuPlugin.js +5 -14
  171. package/dist/plugins/table/TableChrome.svelte +2 -3
  172. package/dist/plugins/table/TablePlugin.svelte +20 -54
  173. package/dist/plugins/table/chrome.svelte.d.ts +5 -2
  174. package/dist/plugins/table/chrome.svelte.js +30 -54
  175. package/dist/plugins/table/table.js +3 -3
  176. package/dist/plugins/toc/TocPlugin.svelte +2 -4
  177. package/dist/plugins/toolbar/ToolbarController.svelte.d.ts +7 -0
  178. package/dist/plugins/toolbar/ToolbarController.svelte.js +20 -13
  179. package/dist/plugins/toolbar/toolbarPlugin.js +19 -53
  180. package/dist/plugins/triggers/TriggerController.svelte.d.ts +7 -2
  181. package/dist/plugins/triggers/TriggerController.svelte.js +11 -4
  182. package/dist/plugins/triggers/place.js +1 -2
  183. package/dist/plugins/triggers/triggers.d.ts +6 -1
  184. package/dist/plugins/triggers/triggers.js +12 -13
  185. package/dist/plugins/uploads.svelte.d.ts +5 -2
  186. package/dist/plugins/uploads.svelte.js +25 -15
  187. package/dist/plugins.d.ts +26 -0
  188. package/dist/plugins.js +0 -24
  189. package/dist/selection/replaceSelection.js +2 -2
  190. package/dist/selection/selection.svelte.d.ts +4 -10
  191. package/dist/selection/selection.svelte.js +7 -11
  192. package/dist/session/bindings.js +1 -1
  193. package/dist/session/commands.d.ts +7 -11
  194. package/dist/session/commands.js +13 -19
  195. package/dist/session/inputRules.js +1 -1
  196. package/dist/session/navigation.js +1 -1
  197. package/dist/session/suggestions.svelte.d.ts +0 -11
  198. package/dist/session/suggestions.svelte.js +15 -3
  199. package/dist/session/uploads.d.ts +8 -8
  200. package/dist/surface/lines.js +1 -3
  201. package/dist/surface/observer.svelte.d.ts +17 -1
  202. package/dist/surface/observer.svelte.js +72 -17
  203. package/dist/surface/overlay.d.ts +0 -14
  204. package/dist/surface/overlay.js +0 -25
  205. package/dist/surface/projector.svelte.js +1 -1
  206. package/dist/text/text.svelte.js +3 -13
  207. package/dist/utils/sanitize.d.ts +38 -0
  208. package/dist/utils/sanitize.js +82 -0
  209. package/dist/utils.d.ts +2 -0
  210. package/dist/utils.js +5 -0
  211. package/package.json +18 -1
  212. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/max-z-index.js +0 -3
  213. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop/util/supports-popover.js +0 -16
  214. package/dist/dnd/vendor/pragmatic/pragmatic-drag-and-drop-auto-scroll/shared/is-axis-allowed.js +0 -3
  215. package/dist/plugins/code/LanguageMenu.svelte +0 -25
  216. package/dist/plugins/code/LanguageMenu.svelte.d.ts +0 -9
  217. package/dist/plugins/equation/EquationEditor.svelte +0 -27
  218. package/dist/plugins/equation/EquationEditor.svelte.d.ts +0 -9
  219. package/dist/plugins/image/ImageToolbarHost.svelte +0 -37
  220. package/dist/plugins/image/ImageToolbarHost.svelte.d.ts +0 -9
  221. package/dist/plugins/richtext/CalloutIconPicker.svelte +0 -26
  222. package/dist/plugins/richtext/CalloutIconPicker.svelte.d.ts +0 -9
package/README.md CHANGED
@@ -17,11 +17,11 @@
17
17
 
18
18
  Edytor aims to be for Svelte what Slate.js is for React: a heavily customizable editor with an API to build any kind of collaborative rich text editor.
19
19
 
20
- > **2.0.** Edytor `2.0.0` is on npm as `edytor`: its API follows semantic versioning, and every change is listed in the changelog. It has no production track record yet: read the [limitations](https://edytor.dev/docs/reference/limitations) before you build on it. Issues and PRs are welcome: when you report a bug, include the document's JSON value.
20
+ > **3.0.** Edytor `3.0.0` is on npm as `edytor`: its API follows semantic versioning, and every change is listed in the changelog. It has no production track record yet: read the [limitations](https://edytor.dev/docs/reference/limitations) before you build on it. Issues and PRs are welcome: when you report a bug, include the document's JSON value.
21
21
 
22
22
  ## Features
23
23
 
24
- - **Notion-style editing out of the box.** `<Edytor />` alone is a rich text editor with block handles: headings, toggle headings, lists, to-dos, toggles, callouts, quotes, dividers, ten marks and Notion's hotkeys. Add the Notion theme, a block menu (block colours; drag one block, or every block the selection covers), a slash menu, a selection toolbar, markdown shortcuts (`createMarkdownShortcutsPlugin()`) code blocks and images (`createImagePlugin({ upload })`).
24
+ - **Notion-style editing out of the box.** `<Edytor />` alone is a rich text editor: headings, toggle headings, lists, to-dos, toggles, callouts, quotes, dividers, ten marks and Notion's hotkeys. Add the Notion theme and the plugins you want: block handles and a block menu (block colours; drag one block, or every block the selection covers), a slash menu, a selection toolbar, markdown shortcuts (`createMarkdownShortcutsPlugin()`), code blocks and images (`createImagePlugin({ upload })`). The package draws no chrome: each handle and menu is your snippet, or the ready-made registry item.
25
25
  - **Pages and a table of contents, opt-in.** `createPagePlugin` links a block to another document (a page per room, opened and named by your app), and `createTocPlugin()` lists the headings live ([Page](https://edytor.dev/docs/plugins/page), [Table of contents](https://edytor.dev/docs/plugins/table-of-contents)).
26
26
  - **Columns, opt-in.** List `createColumnsPlugin()` for Notion's multi-column layouts: drag a block to the edge of another to put them side by side, or pick "2 columns" to "5 columns"; drag the gap to resize. Layouts converge across collaborators and the room ([Columns](https://edytor.dev/docs/plugins/columns)).
27
27
  - **Tables, opt-in.** List `createTablePlugin()` for Notion's simple table: cells of text, <kbd>Tab</kbd> between them, rows and columns added, moved and deleted from the table's edges and grips, resizable columns, header row and column, HTML tables pasted and copied. Concurrent row and column edits converge on every replica ([Table](https://edytor.dev/docs/plugins/table)).
@@ -35,11 +35,12 @@ Edytor aims to be for Svelte what Slate.js is for React: a heavily customizable
35
35
  - **Real-time collaboration.** One `EdytorDocument` shared by any number of views, or none (headless). Presence cursors, identity-preserving moves, splits and merges, and undo that only takes back your own edits.
36
36
  - **Offline first.** A local IndexedDB copy and cross-tab sync; offline edits survive reloads and reach the server on reconnect.
37
37
  - **A Cloudflare Durable Object room.** `edytor/cloudflare` stores in SQLite, acknowledges after the write, binds identity to the socket and hibernates.
38
+ - **Import and export.** `edytor/export` turns a document into HTML or Markdown and back (`toHTML`, `toMarkdown`, `fromHTML`, `textToBlocks`), by each kind's own forms, in the browser, Node or a Worker; HTML import is sanitized ([Import and export](https://edytor.dev/docs/editor/import-export)).
38
39
  - **Headless and Worker-safe.** `edytor/crdt/edytor` runs in Node and Workers without Svelte.
39
40
 
40
41
  ## Install
41
42
 
42
- The pre-release is on npm under the `next` tag. Name the tag: a bare `edytor` is the old, incompatible `0.0.11`.
43
+ Edytor `3.0.0` is on npm under `latest`:
43
44
 
44
45
  ```bash
45
46
  pnpm add edytor
@@ -65,7 +66,21 @@ pnpm add edytor
65
66
 
66
67
  `<Edytor>` renders on the server and hydrates, so it works in any route. It includes rich text; each other block kind, block moves from the keyboard (`createArrowMovePlugin()`), and file drops (a media plugin given an `upload`) is a plugin you add, here code blocks; nesting blocks (<kbd>Tab</kbd>, drops inside a block) is the `allowNesting` option, off by default. `onChange` hands you the document after every change ([quick start](https://edytor.dev/docs/getting-started/quick-start)).
67
68
 
68
- The package draws no menu, toolbar or block handle: each is a snippet you pass its plugin ([menus and handles](https://edytor.dev/docs/customization/menus)). The demo's Notion-style ones are in [`src/routes/chrome`](https://github.com/beynar/edytor/tree/master/src/routes/chrome), ready to copy into your app ([ready-made menus](https://edytor.dev/docs/customization/ready-made-menus)).
69
+ The package draws no menu, toolbar or block handle: each is a snippet you pass its plugin ([menus and handles](https://edytor.dev/docs/customization/menus)). Notion-style ones, in shadcn-svelte, are a registry item you add to your app (`npx shadcn-svelte@latest add https://edytor.dev/r/edytor-chrome.json`), as plugins for your `<Edytor>` ([ready-made menus](https://edytor.dev/docs/customization/ready-made-menus)).
70
+
71
+ The fastest way to a full editor is the starter, a [shadcn-svelte](https://www.shadcn-svelte.com) registry item: every plugin, the ready-made menus and handles, comments, and a page with a cover, an icon, a title and typed properties, in one component copied into your app (Tailwind v4 and `shadcn-svelte init` first; [starter editor](https://edytor.dev/docs/starter)):
72
+
73
+ ```sh
74
+ npx shadcn-svelte@latest add https://edytor.dev/r/starter.json
75
+ ```
76
+
77
+ ```svelte
78
+ <script>
79
+ import { StarterEditor } from '$lib/components/edytor/starter/index.js';
80
+ </script>
81
+
82
+ <StarterEditor />
83
+ ```
69
84
 
70
85
  To collaborate, name a room and a server running the [`edytor/cloudflare` room](https://edytor.dev/docs/server/quick-start):
71
86
 
@@ -1,3 +1,4 @@
1
+ import { cleanups } from '../utils.js';
1
2
  import { Text } from '../text/text.svelte.js';
2
3
  /** Mark an element inside a block's markup as non-editable chrome (`block.void`, a preview's too). */
3
4
  export const voidChrome = (node) => {
@@ -336,10 +337,7 @@ export class Block {
336
337
  this.edytor.selection.keep(this);
337
338
  // A block laid out again with no commit moves the chrome beside it (the overlay measures).
338
339
  const unobserve = this.edytor.overlay.observe(node);
339
- const onDestroy = this.edytor.plugins.flatMap((plugin) => {
340
- const action = plugin.onBlockAttached?.({ node, block: this });
341
- return typeof action === 'function' ? [action] : [];
342
- });
340
+ const onDestroy = cleanups(this.edytor.plugins, (plugin) => plugin.onBlockAttached?.({ node, block: this }));
343
341
  return {
344
342
  destroy: () => {
345
343
  this.#viewState = read(node);
@@ -1,10 +1,20 @@
1
- import type { Edytor } from '../edytor.svelte.js';
2
1
  import type { Flow } from '../crdt/flow.js';
3
- import type { BlockDefinition } from '../plugins.js';
4
- import { type SerializableContent } from '../utils/json.js';
2
+ import { type JSONBlock, type SerializableContent } from '../utils/json.js';
3
+ import type { AtomForms, BlockForms, MarkForms } from './serializeClipboardFragment.js';
5
4
  /** What HTML import reads: the kind, mark and atom records, and the document's default child. */
6
- export type ImportKinds = Pick<Edytor, 'blocks' | 'marks'> & Partial<Pick<Edytor, 'inlineBlocks'>> & {
7
- document: Pick<Edytor['document'], 'defaultChild'>;
5
+ export type ImportKinds = {
6
+ readonly blocks: ReadonlyMap<string, BlockForms>;
7
+ readonly marks: ReadonlyMap<string, MarkForms>;
8
+ readonly inlineBlocks?: ReadonlyMap<string, AtomForms>;
9
+ readonly document: {
10
+ defaultChild: (parent: string | null) => string;
11
+ };
12
+ };
13
+ /** A `DOMParser` constructor: the browser's, or a server's (`linkedom`, `jsdom`, `happy-dom`). */
14
+ export type HtmlParser = new () => {
15
+ parseFromString(html: string, type: 'text/html'): {
16
+ body: Node | null;
17
+ };
8
18
  };
9
19
  type Values = Record<string, SerializableContent>;
10
20
  /**
@@ -13,9 +23,10 @@ type Values = Record<string, SerializableContent>;
13
23
  * none: an export form written as one (a callout's `<div data-edytor-callout>`)
14
24
  * is found by its `parse` hook only.
15
25
  */
16
- export declare const tagOf: (type: string, kind: BlockDefinition, data: Values) => string | undefined;
26
+ export declare const tagOf: (type: string, kind: BlockForms, data: Values) => string | undefined;
17
27
  /**
18
- * External HTML as a flow: the browser parses (inert: no script
28
+ * External HTML as lines (JSON blocks; a line without a `type` is its
29
+ * parent's default child): `parser` parses (inert: no script
19
30
  * runs, nothing loads), and the tag tables are the records inverted — a
20
31
  * catalogue kind's tag per preset (a content-less container takes its
21
32
  * default child's tag, one child per text line), a value-less mark's
@@ -27,5 +38,7 @@ export declare const tagOf: (type: string, kind: BlockDefinition, data: Values)
27
38
  * atom, never its text. Unknown
28
39
  * elements degrade to text runs; whitespace collapses as HTML renders it. `null` when the HTML carries nothing (`flow.shape`).
29
40
  */
41
+ export declare const linesOfHtml: (kinds: ImportKinds, html: string | undefined, parser?: HtmlParser | undefined) => JSONBlock[] | null;
42
+ /** External HTML as a flow (the paste's): {@link linesOfHtml}, with the browser's parser. */
30
43
  export declare const flowOfHtml: (kinds: ImportKinds, html: string | undefined) => Flow | null;
31
44
  export {};
@@ -1,6 +1,8 @@
1
1
  import { colorsOfClasses } from '../block/colors.js';
2
2
  import { isTextPart } from '../block/contentRange.js';
3
3
  import { jsonBlockToSpec } from '../utils/json.js';
4
+ /** Element and text nodes by their type, not their realm: a server parser's nodes are not this global's. */
5
+ const isElement = (node) => node?.nodeType === 1;
4
6
  /** Never content: their text is code, metadata or form state. */
5
7
  const SKIP = /^(script|style|template|noscript|svg|math|iframe|object|embed|canvas|video|audio|img|input|button|select|textarea|head|title|meta|link|base)$/;
6
8
  /** HTML's block-level elements: they start a line (a kind's tag does too). */
@@ -21,7 +23,7 @@ const sizeOf = (img, side) => {
21
23
  * email's tracking pixel). It is text, its `alt`, never a block.
22
24
  */
23
25
  const isGlyph = (node) => {
24
- if (!(node instanceof HTMLElement) || node.localName !== 'img')
26
+ if (!isElement(node) || node.localName !== 'img')
25
27
  return false;
26
28
  const alt = node.getAttribute('alt')?.trim() ?? '';
27
29
  if (alt && EMOJI_ALT.test(alt) && /[\p{Extended_Pictographic}\p{Regional_Indicator}]/u.test(alt))
@@ -61,7 +63,8 @@ export const tagOf = (type, kind, data) => {
61
63
  return undefined;
62
64
  };
63
65
  /**
64
- * External HTML as a flow: the browser parses (inert: no script
66
+ * External HTML as lines (JSON blocks; a line without a `type` is its
67
+ * parent's default child): `parser` parses (inert: no script
65
68
  * runs, nothing loads), and the tag tables are the records inverted — a
66
69
  * catalogue kind's tag per preset (a content-less container takes its
67
70
  * default child's tag, one child per text line), a value-less mark's
@@ -73,8 +76,8 @@ export const tagOf = (type, kind, data) => {
73
76
  * atom, never its text. Unknown
74
77
  * elements degrade to text runs; whitespace collapses as HTML renders it. `null` when the HTML carries nothing (`flow.shape`).
75
78
  */
76
- export const flowOfHtml = (kinds, html) => {
77
- if (!html || html.length > 8 * 1024 * 1024 || typeof DOMParser === 'undefined')
79
+ export const linesOfHtml = (kinds, html, parser = globalThis.DOMParser) => {
80
+ if (!html || html.length > 8 * 1024 * 1024 || !parser)
78
81
  return null;
79
82
  const { blocks, marks } = kinds;
80
83
  const atoms = kinds.inlineBlocks ?? new Map();
@@ -99,8 +102,9 @@ export const flowOfHtml = (kinds, html) => {
99
102
  return undefined;
100
103
  for (const [type, kind] of blocks) {
101
104
  const data = kind.parse?.(element);
105
+ // A kind of lines (a code block) takes its element's text, one child per line.
102
106
  if (data)
103
- return { type, kind, data };
107
+ return { type, kind, data, lines: kind.lines ? kind.defaultChild : undefined };
104
108
  }
105
109
  return byTag.get(element.localName);
106
110
  };
@@ -124,11 +128,10 @@ export const flowOfHtml = (kinds, html) => {
124
128
  return found;
125
129
  };
126
130
  // A kind's hook may claim an element of another namespace (an equation's MathML `<math>`).
127
- const isBlock = (node) => (node instanceof HTMLElement && BLOCK.test(node.localName)) ||
128
- (node instanceof Element && kindOf(node) !== undefined);
131
+ const isBlock = (node) => isElement(node) && (BLOCK.test(node.localName) || kindOf(node) !== undefined);
129
132
  /** A void kind's element (an image): it shows no text, so a line it is met in ends there. */
130
133
  const isVoid = (node) => {
131
- const claim = node instanceof Element ? kindOf(node) : undefined;
134
+ const claim = isElement(node) ? kindOf(node) : undefined;
132
135
  return claim?.kind.void === true;
133
136
  };
134
137
  const text = (line, value, marks, pre) => {
@@ -148,16 +151,16 @@ export const flowOfHtml = (kinds, html) => {
148
151
  line.content.push(Object.keys(marks).length ? { text: value, marks } : { text: value });
149
152
  };
150
153
  const inline = (node, at, marks, pre) => {
151
- if (node.nodeType === Node.TEXT_NODE)
154
+ if (node.nodeType === 3)
152
155
  return text(at.line(), node.textContent ?? '', marks, pre);
153
156
  if (isGlyph(node))
154
157
  return text(at.line(), node.getAttribute('alt') ?? '', marks, pre);
155
158
  if (isVoid(node))
156
159
  return at.apart(node);
157
- const atom = node instanceof Element ? atomOf(node) : undefined;
160
+ const atom = isElement(node) ? atomOf(node) : undefined;
158
161
  if (atom)
159
162
  return void at.line().content.push(atom);
160
- if (!(node instanceof HTMLElement) || SKIP.test(node.localName))
163
+ if (!isElement(node) || SKIP.test(node.localName))
161
164
  return;
162
165
  if (node.localName === 'br')
163
166
  return text(at.line(), '\n', marks, true);
@@ -286,12 +289,17 @@ export const flowOfHtml = (kinds, html) => {
286
289
  // Split: a text line left empty around a void element is not kept.
287
290
  return parts.filter((part) => !texts.has(part) || end(part).content.length > 0 || part.children !== undefined);
288
291
  };
289
- const body = new DOMParser().parseFromString(html, 'text/html').body;
292
+ const body = new parser().parseFromString(html, 'text/html').body;
293
+ if (!body)
294
+ return null;
290
295
  const lines = linesOf(body, undefined);
291
296
  const carries = (line) => line.content.length > 0 ||
292
297
  Boolean(line.children?.some(carries)) ||
293
298
  Boolean(line.type && blocks.get(line.type)?.void);
294
- return lines.some(carries)
295
- ? { lines: lines.map((line) => jsonBlockToSpec(line, true)) }
296
- : null;
299
+ return lines.some(carries) ? lines : null;
300
+ };
301
+ /** External HTML as a flow (the paste's): {@link linesOfHtml}, with the browser's parser. */
302
+ export const flowOfHtml = (kinds, html) => {
303
+ const lines = linesOfHtml(kinds, html);
304
+ return lines ? { lines: lines.map((line) => jsonBlockToSpec(line, true)) } : null;
297
305
  };
@@ -1,9 +1,42 @@
1
- import type { Edytor } from '../edytor.svelte.js';
2
- import type { EdytorClipboardFragment } from './types.js';
3
- /** The records the export reads: each kind, mark and atom declares its own forms. */
4
- export type ExportKinds = Pick<Edytor, 'blocks' | 'marks' | 'inlineBlocks'>;
1
+ /**
2
+ * The document's export forms, one reading for the clipboard and for
3
+ * `toHTML` / `toMarkdown` (`edytor/export`): each kind, mark and atom
4
+ * declares its own forms (`html`, `plain`, `markdown`; a mark's `tag` and
5
+ * `attributes`), and this module only walks the blocks. Pure: no view, no
6
+ * DOM, no Svelte.
7
+ */
8
+ import type { JSONBlock, SerializableContent } from '../utils/json.js';
9
+ import type { BlockDefinition, InlineBlockDefinition, MarkDefinition } from '../plugins.js';
10
+ import type { EdytorClipboardFragment, JSONContentPart } from './types.js';
11
+ /** A kind's export and import forms: the fields of its record the export and HTML import read. */
12
+ export type BlockForms = Pick<BlockDefinition, 'html' | 'plain' | 'markdown' | 'parse' | 'element' | 'contentElement' | 'void' | 'island' | 'lines' | 'rendersContent' | 'defaultChild' | 'itemKind'> & {
13
+ /** The data of each way to create the kind: HTML import finds a preset's tag. */
14
+ presets?: {
15
+ data?: Record<string, SerializableContent>;
16
+ }[];
17
+ };
18
+ /** A mark's export and import forms. */
19
+ export type MarkForms = Pick<MarkDefinition, 'tag' | 'attributes' | 'parse' | 'markdown'>;
20
+ /** An atom's export and import forms. */
21
+ export type AtomForms = Pick<InlineBlockDefinition, 'html' | 'plain' | 'markdown' | 'parse'>;
22
+ /** The records the export reads: each kind, mark and atom declares its own forms (a view is one). */
23
+ export type ExportKinds = {
24
+ readonly blocks: ReadonlyMap<string, BlockForms>;
25
+ readonly marks: ReadonlyMap<string, MarkForms>;
26
+ readonly inlineBlocks: ReadonlyMap<string, AtomForms>;
27
+ };
5
28
  export declare const encodeClipboardJson: (value: unknown) => string;
6
29
  /** `value` escaped for an HTML text or a double-quoted attribute: every kind's export reads it. */
7
30
  export declare const escapeHtml: (value: string) => string;
31
+ /** The content as HTML, or as plain text: an atom by its kind's form (`html`, `plain`). */
32
+ export declare const contentOf: (content: JSONContentPart[] | undefined, kinds: ExportKinds, html: boolean) => string;
33
+ /**
34
+ * How sibling blocks' HTML joins (`edytor/export` wraps a run of list items
35
+ * in its list): the blocks, their HTML, and their parent's `html` form.
36
+ * Without one, one after another (the clipboard's).
37
+ */
38
+ export type SiblingsHtml = (blocks: JSONBlock[], html: string[], parent?: BlockForms['html']) => string;
39
+ /** Blocks as HTML: the clipboard's and `toHTML`'s one reading of the kinds' forms. */
40
+ export declare const blocksToHtml: (blocks: JSONBlock[], kinds: ExportKinds, wrap: SiblingsHtml) => string;
8
41
  export declare const serializeClipboardFragmentToPlainText: (fragment: EdytorClipboardFragment, kinds: ExportKinds) => string;
9
42
  export declare const serializeClipboardFragmentToHtml: (fragment: EdytorClipboardFragment, kinds: ExportKinds) => string;
@@ -19,7 +19,7 @@ const textHtml = (part, kinds) => {
19
19
  return html;
20
20
  };
21
21
  /** The content as HTML, or as plain text: an atom by its kind's form (`html`, `plain`). */
22
- const contentOf = (content = [], kinds, html) => content
22
+ export const contentOf = (content = [], kinds, html) => content
23
23
  .map((part) => {
24
24
  if (isTextPart(part))
25
25
  return html ? textHtml(part, kinds) : part.text;
@@ -41,9 +41,9 @@ const withClasses = (html, classes) => classes
41
41
  })
42
42
  : html;
43
43
  /** A block and its subtree as HTML (its colours as Notion's classes), or as plain text. */
44
- const blockOf = (block, kinds, html) => {
44
+ const blockOf = (block, kinds, html, wrap) => {
45
45
  const content = contentOf(block.content, kinds, html);
46
- const kids = block.children?.map((child) => blockOf(child, kinds, html)) ?? [];
46
+ const kids = block.children?.map((child) => blockOf(child, kinds, html, wrap)) ?? [];
47
47
  const kind = kinds.blocks.get(block.type);
48
48
  if (!html) {
49
49
  const children = kids.filter(Boolean).join('\n');
@@ -51,8 +51,8 @@ const blockOf = (block, kinds, html) => {
51
51
  ? kind.plain(block, content, children)
52
52
  : [content, children].filter(Boolean).join('\n');
53
53
  }
54
- const children = kids.join('');
55
54
  const form = kind?.html;
55
+ const children = wrap ? wrap(block.children ?? [], kids, form) : kids.join('');
56
56
  const out = !form
57
57
  ? `<p>${content}</p>${children}`
58
58
  : typeof form === 'string'
@@ -61,6 +61,8 @@ const blockOf = (block, kinds, html) => {
61
61
  // A block's colours as Notion's export names them (`block-color-red`).
62
62
  return withClasses(out, colorClasses(block.data));
63
63
  };
64
+ /** Blocks as HTML: the clipboard's and `toHTML`'s one reading of the kinds' forms. */
65
+ export const blocksToHtml = (blocks, kinds, wrap) => wrap(blocks, blocks.map((block) => blockOf(block, kinds, true, wrap)));
64
66
  export const serializeClipboardFragmentToPlainText = (fragment, kinds) => fragment.kind === 'blocks'
65
67
  ? fragment.blocks.map((block) => blockOf(block, kinds, false)).join('\n')
66
68
  : contentOf(fragment.content, kinds, false);
@@ -21,5 +21,13 @@ export type TextToBlocksOptions = {
21
21
  };
22
22
  /** Whether `text` holds block markdown (one line of it is enough), as a paste reads it. */
23
23
  export declare const hasBlockMarkdown: (text: string) => boolean;
24
+ /**
25
+ * One line's kind, data and text, or `null` for a paragraph line: the one
26
+ * reading of a markdown line's block marker (`edytor/export`'s full reader
27
+ * reads its lines with it too).
28
+ */
29
+ export declare const lineKind: (line: string) => (Omit<JSONBlock, "content"> & {
30
+ text: string;
31
+ }) | null;
24
32
  /** `text` as blocks (see the module comment). */
25
33
  export declare const textToBlocks: (text: string, { markdown, type }?: TextToBlocksOptions) => JSONBlock[];
@@ -25,8 +25,12 @@ const runs = (text) => {
25
25
  const BLOCK_LINE = /^\s*(?:#{1,6}\s|[-*+]\s|\d+[.)]\s|>|```|(?:-{3,}|\*{3,}|_{3,})\s*$)/;
26
26
  /** Whether `text` holds block markdown (one line of it is enough), as a paste reads it. */
27
27
  export const hasBlockMarkdown = (text) => text.split(/\r?\n/).some((line) => BLOCK_LINE.test(line));
28
- /** One line's kind, data and text, or `null` for a paragraph line. */
29
- const lineKind = (line) => {
28
+ /**
29
+ * One line's kind, data and text, or `null` for a paragraph line: the one
30
+ * reading of a markdown line's block marker (`edytor/export`'s full reader
31
+ * reads its lines with it too).
32
+ */
33
+ export const lineKind = (line) => {
30
34
  let m = /^(#{1,6})\s+(.*)$/.exec(line);
31
35
  if (m)
32
36
  return { type: 'heading', data: { level: `h${Math.min(3, m[1].length)}` }, text: m[2] };
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { Y } from '../../crdt/engine.js';
13
13
  import * as E from '../../crdt/protocol.js';
14
- import { ChunkLimitError, ChunkSequenceError, CLOSE } from '../../crdt/providers/room.js';
14
+ import { ChunkError, CLOSE } from '../../crdt/providers/room.js';
15
15
  import { MAX_WAITING_DELETES, noTimers } from './shared.js';
16
16
  import { STORAGE_FAILURE, now, sync, tally } from './context.js';
17
17
  import { attributionWrites, BINDING_PREFIX, forgedAttributionDeletes, forgedDeletes, forgedWriters } from './forged.js';
@@ -168,7 +168,7 @@ export class Admission {
168
168
  }
169
169
  catch (error) {
170
170
  this.#chunkReaders.delete(ws);
171
- if (error instanceof ChunkLimitError) {
171
+ if (error instanceof ChunkError && error.limit !== undefined) {
172
172
  return this.#overQuota(ws, attachment.user, 'frame', {
173
173
  bytes: error.total,
174
174
  limit: error.limit
@@ -187,7 +187,7 @@ export class Admission {
187
187
  room.presence.depart(ws);
188
188
  return room.close(ws, CLOSE.fault, 'room busy');
189
189
  }
190
- if (error instanceof ChunkSequenceError) {
190
+ if (error instanceof ChunkError) {
191
191
  room.note({ reason: 'internal', detail: `chunks: ${error.message}` });
192
192
  room.presence.depart(ws);
193
193
  return room.close(ws, CLOSE.fault, 'chunk sequence lost');
@@ -536,7 +536,7 @@ export declare const crdt: {
536
536
  off<NAME extends "refused" | "status" | "failed" | "schema-mismatch" | "message-error" | "protocol-mismatch" | "synced" | "connection-close" | "connection-error" | "saved" | "permission-denied" | "expired" | "unreachable">(name: NAME, f: E.WebsocketProviderEvents[NAME]): void;
537
537
  };
538
538
  };
539
- watchComments: (server: string, roomName: string, listener: (message: E.CommentMessage) => void) => (() => void);
539
+ watchComments: (server: string | null, roomName: string, listener: (message: E.CommentMessage) => void) => (() => void);
540
540
  storeState: (idbPersistence: {
541
541
  db: IDBDatabase | null;
542
542
  name: string;
@@ -50,6 +50,23 @@ export type RouteDocumentOptions = {
50
50
  * your page from another site's. Omitted: every origin passes.
51
51
  */
52
52
  allowedOrigins?: readonly string[] | ((origin: string) => boolean);
53
+ /**
54
+ * Answer a page on another origin (the app on `app.example.com`, the
55
+ * room on `rooms.example.com`): `OPTIONS` preflights are answered `204`
56
+ * (`GET, POST`, the headers the page asked for), and every HTTP answer
57
+ * (comments, history, the probes) carries `Access-Control-Allow-Origin`.
58
+ * The origins are `allowedOrigins`: with a list or a predicate, the
59
+ * request's `Origin` is echoed (`Vary: Origin`) and `credentials: true`
60
+ * lets the page send its cookies (`fetch(…, { credentials: 'include' })`);
61
+ * without one, every origin gets `*` and no credentials. A preflight from
62
+ * an origin `allowedOrigins` refuses is answered `403`. `maxAge`: how long
63
+ * a browser keeps a preflight, in seconds (default 600). A WebSocket dial
64
+ * needs none of it. Omitted: no CORS headers, and `OPTIONS` answers `405`.
65
+ */
66
+ cors?: boolean | {
67
+ credentials?: boolean;
68
+ maxAge?: number;
69
+ };
53
70
  };
54
71
  /** The replica a client asked for in `?replica=<doc.clientID>` (or `param`), or `null`. */
55
72
  export declare const requestedReplica: (request: Request, param?: string) => number | null;
@@ -28,6 +28,50 @@ import { CLOSE, validRoomId } from '../crdt/providers/room.js';
28
28
  import { COMMENTS_HEADER, HISTORY_HEADER, HISTORY_KEY_HEADER, IDENTITY_HEADERS, PROBE_HEADER, closedSocket } from './room/shared.js';
29
29
  import { parseReplica } from './room/access.js';
30
30
  import { MAX_COMMENT_REQUEST_BYTES } from './room/comments.js';
31
+ /** The CORS headers `options.cors` gives an answer to `request` (none: `null`). */
32
+ const corsHeaders = (request, options) => {
33
+ const cors = options?.cors;
34
+ const origin = request.headers.get('Origin');
35
+ if (!cors || origin === null || !originAllowed(request, options))
36
+ return null;
37
+ const headers = new Headers();
38
+ if (options?.allowedOrigins === undefined) {
39
+ headers.set('Access-Control-Allow-Origin', '*');
40
+ return headers;
41
+ }
42
+ headers.set('Access-Control-Allow-Origin', origin);
43
+ headers.set('Vary', 'Origin');
44
+ if (typeof cors === 'object' && cors.credentials === true)
45
+ headers.set('Access-Control-Allow-Credentials', 'true');
46
+ return headers;
47
+ };
48
+ /**
49
+ * One HTTP route with `options.cors`: a preflight answered here, every other
50
+ * answer given its CORS headers (a `101` upgrade passes as it is).
51
+ */
52
+ const withCors = async (request, options, route) => {
53
+ const cors = options?.cors;
54
+ if (cors && request.method === 'OPTIONS' && request.headers.has('Origin')) {
55
+ const headers = corsHeaders(request, options);
56
+ if (headers === null)
57
+ return new Response('origin not allowed', { status: 403 });
58
+ headers.set('Access-Control-Allow-Methods', 'GET, POST');
59
+ headers.set('Access-Control-Allow-Headers', request.headers.get('Access-Control-Request-Headers') ?? 'Content-Type');
60
+ headers.set('Access-Control-Max-Age', String((typeof cors === 'object' ? cors.maxAge : undefined) ?? 600));
61
+ return new Response(null, { status: 204, headers });
62
+ }
63
+ const response = await route();
64
+ const headers = corsHeaders(request, options);
65
+ if (headers === null || response.status === 101)
66
+ return response;
67
+ const merged = new Headers(response.headers);
68
+ headers.forEach((value, name) => merged.set(name, value));
69
+ return new Response(response.body, {
70
+ status: response.status,
71
+ statusText: response.statusText,
72
+ headers: merged
73
+ });
74
+ };
31
75
  /** Is `request`'s `Origin` one `options` allows (no `Origin`, or no list: yes)? */
32
76
  const originAllowed = (request, options) => {
33
77
  const allowed = options?.allowedOrigins;
@@ -109,6 +153,9 @@ const identityHeaders = (identity) => {
109
153
  * `404` (the room keeps no history), `405` (another method).
110
154
  */
111
155
  export async function routeDocumentHistory(request, rooms, documentId, authorize, options) {
156
+ return withCors(request, options, () => routeHistory(request, rooms, documentId, authorize, options));
157
+ }
158
+ async function routeHistory(request, rooms, documentId, authorize, options) {
112
159
  const query = new URL(request.url).searchParams;
113
160
  const op = request.method === 'GET'
114
161
  ? query.has('key')
@@ -191,6 +238,9 @@ const bodyWithin = async (request, max) => {
191
238
  * comment bytes full), `429` (the user past the room's comment rate).
192
239
  */
193
240
  export async function routeDocumentComments(request, rooms, documentId, authorize, options) {
241
+ return withCors(request, options, () => routeComments(request, rooms, documentId, authorize, options));
242
+ }
243
+ async function routeComments(request, rooms, documentId, authorize, options) {
194
244
  const op = request.method === 'GET' ? 'list' : request.method === 'POST' ? 'post' : null;
195
245
  if (op === null)
196
246
  return new Response('method not allowed', { status: 405 });
@@ -215,6 +265,9 @@ export async function routeDocumentComments(request, rooms, documentId, authoriz
215
265
  .fetch(new Request(request.url, { method: op === 'post' ? 'POST' : 'GET', headers, body }));
216
266
  }
217
267
  export async function routeDocumentSocket(request, rooms, documentId, authorize, options) {
268
+ return withCors(request, options, () => routeSocket(request, rooms, documentId, authorize, options));
269
+ }
270
+ async function routeSocket(request, rooms, documentId, authorize, options) {
218
271
  // The probes: a plain GET, authorized like a dial, answered with JSON or
219
272
  // an HTTP status — `lastUpdated` and `snapshot` (the document).
220
273
  const query = new URL(request.url).searchParams;
@@ -48,7 +48,7 @@ export type CommentsClientOptions = {
48
48
  /**
49
49
  * The websocket sync's server URL (the `server` of `<Edytor>` or
50
50
  * `createWebsocketSync`), whose socket hears the room's changes. Default:
51
- * `server` read as `ws:`/`wss:`.
51
+ * every websocket sync of the same room on the page, whatever its URL.
52
52
  */
53
53
  socket?: string;
54
54
  /** Query parameters sent with each request (a token): an object, or a function read at every request. */
@@ -34,7 +34,7 @@ export const createCommentsClient = (options) => {
34
34
  assertRoomId(options.room);
35
35
  const server = options.server.replace(/\/+$/, '');
36
36
  const base = `${server.replace(/^ws/, 'http')}/${encodeURIComponent(options.room)}`;
37
- const socket = (options.socket ?? server.replace(/^http/, 'ws')).replace(/\/+$/, '');
37
+ const socket = options.socket?.replace(/\/+$/, '') ?? null;
38
38
  const request = async (method, body) => {
39
39
  const url = new URL(base);
40
40
  const params = typeof options.params === 'function' ? options.params() : options.params;
@@ -42,8 +42,8 @@ const getCaretRect = (point, origin, editor) => {
42
42
  const range = (point.node.ownerDocument ?? editor.ownerDocument).createRange();
43
43
  range.setStart(point.node, point.offset);
44
44
  range.collapse(true);
45
- const rect = typeof range.getBoundingClientRect === 'function' ? range.getBoundingClientRect() : null;
46
- if (rect && (rect.width || rect.height)) {
45
+ const rect = range.getBoundingClientRect();
46
+ if (rect.width || rect.height) {
47
47
  return toRemoteRect(rect, origin);
48
48
  }
49
49
  return getFallbackRect(point, origin, editor);
@@ -71,7 +71,7 @@ const getSelectionRects = (start, end, origin, editor) => {
71
71
  (end.text.node && renderSkipped(end.text.node))) {
72
72
  return [getFallbackRect(start, origin, editor)];
73
73
  }
74
- const clientRects = typeof range.getClientRects === 'function' ? Array.from(range.getClientRects()) : [];
74
+ const clientRects = Array.from(range.getClientRects());
75
75
  const seen = new Set();
76
76
  const rects = clientRects
77
77
  .filter((rect) => rect.width || rect.height)
@@ -5,11 +5,9 @@
5
5
  import { Edytor as EdytorClass, useEdytor } from '../edytor.svelte.js';
6
6
  import {
7
7
  SyncRefusedError,
8
- type Awareness,
9
8
  type DocChange,
10
9
  type DocumentActor,
11
- type EdytorDocument,
12
- type YDoc
10
+ type EdytorDocument
13
11
  } from '../crdt/index.js';
14
12
  import { CLOSE, validRoomId } from '../crdt/providers/room.js';
15
13
  import type { EdytorSync, WebsocketSyncOptions } from '../collaboration/index.js';
@@ -75,8 +73,6 @@
75
73
  edytor?: EdytorClass;
76
74
  /** The assembled document this view renders (see `crdt/document.ts`). */
77
75
  document?: EdytorDocument;
78
- doc?: YDoc;
79
- awareness?: Awareness;
80
76
  /** The local author (id, name, color) of the document this view owns: attribution and presence. */
81
77
  actor?: DocumentActor;
82
78
  /**
@@ -187,7 +183,6 @@
187
183
  edytor = $bindable(),
188
184
  // Aliased so the DOM `document` global keeps working in this scope.
189
185
  document: edytorDocument,
190
- doc,
191
186
  readonly = false,
192
187
  allowNesting = false,
193
188
  value = defaultValue,
@@ -200,7 +195,6 @@
200
195
  onSyncRefused,
201
196
  requireHydration,
202
197
  snapshot,
203
- awareness,
204
198
  actor,
205
199
  presence,
206
200
  onChange,
@@ -221,8 +215,6 @@
221
215
  allowNesting,
222
216
  plugins: defaultPlugins ? withDefaults(userPlugins) : userPlugins,
223
217
  document: edytorDocument,
224
- doc,
225
- awareness,
226
218
  actor,
227
219
  requireHydration,
228
220
  hotkeys,
@@ -294,7 +286,7 @@
294
286
  }
295
287
  });
296
288
 
297
- // The component owns the Edytor — release its doc/awareness/facade/
289
+ // The component owns the Edytor — release its facade/
298
290
  // undo-manager listeners so a shared doc doesn't retain dead mounts.
299
291
  // `onDestroy` also runs after a server render: a view-owned document
300
292
  // (and its awareness timer) must not outlive the request.
@@ -1,5 +1,5 @@
1
1
  import { Edytor as EdytorClass, useEdytor } from '../edytor.svelte.js';
2
- import { SyncRefusedError, type Awareness, type DocChange, type DocumentActor, type EdytorDocument, type YDoc } from '../crdt/index.js';
2
+ import { SyncRefusedError, type DocChange, type DocumentActor, type EdytorDocument } from '../crdt/index.js';
3
3
  import type { EdytorSync, WebsocketSyncOptions } from '../collaboration/index.js';
4
4
  import { type PresenceOptions } from '../collaboration/awarenessSelection.js';
5
5
  export { EdytorClass as EdytorContext, useEdytor };
@@ -21,8 +21,6 @@ export type EdytorProps = {
21
21
  edytor?: EdytorClass;
22
22
  /** The assembled document this view renders (see `crdt/document.ts`). */
23
23
  document?: EdytorDocument;
24
- doc?: YDoc;
25
- awareness?: Awareness;
26
24
  /** The local author (id, name, color) of the document this view owns: attribution and presence. */
27
25
  actor?: DocumentActor;
28
26
  /**