edytor 0.1.0-next.34 → 0.1.0-next.36

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 (256) hide show
  1. package/README.md +5 -2
  2. package/dist/block/block.svelte.d.ts +9 -3
  3. package/dist/block/block.svelte.js +14 -1
  4. package/dist/block/colors.d.ts +47 -0
  5. package/dist/block/colors.js +74 -0
  6. package/dist/cloudflare/DocumentRoom.d.ts +13 -513
  7. package/dist/cloudflare/DocumentRoom.js +102 -3721
  8. package/dist/cloudflare/room/access.d.ts +31 -0
  9. package/dist/cloudflare/room/access.js +226 -0
  10. package/dist/cloudflare/room/admission.d.ts +117 -0
  11. package/dist/cloudflare/room/admission.js +559 -0
  12. package/dist/cloudflare/room/context.d.ts +790 -0
  13. package/dist/cloudflare/room/context.js +293 -0
  14. package/dist/cloudflare/room/forged.d.ts +50 -0
  15. package/dist/cloudflare/room/forged.js +250 -0
  16. package/dist/cloudflare/room/frames.d.ts +24 -0
  17. package/dist/cloudflare/room/frames.js +37 -0
  18. package/dist/cloudflare/room/history.d.ts +100 -0
  19. package/dist/cloudflare/room/history.js +500 -0
  20. package/dist/cloudflare/room/moves.d.ts +60 -0
  21. package/dist/cloudflare/room/moves.js +419 -0
  22. package/dist/cloudflare/room/presence.d.ts +64 -0
  23. package/dist/cloudflare/room/presence.js +202 -0
  24. package/dist/cloudflare/room/purge.d.ts +16 -0
  25. package/dist/cloudflare/room/purge.js +114 -0
  26. package/dist/cloudflare/room/replicas.d.ts +51 -0
  27. package/dist/cloudflare/room/replicas.js +145 -0
  28. package/dist/cloudflare/room/scheduler.d.ts +39 -0
  29. package/dist/cloudflare/room/scheduler.js +122 -0
  30. package/dist/cloudflare/room/storage.d.ts +153 -0
  31. package/dist/cloudflare/room/storage.js +758 -0
  32. package/dist/cloudflare/room/updates.d.ts +89 -0
  33. package/dist/cloudflare/room/updates.js +328 -0
  34. package/dist/cloudflare/room/validation.d.ts +61 -0
  35. package/dist/cloudflare/room/validation.js +227 -0
  36. package/dist/cloudflare/routeDocumentSocket.js +2 -1
  37. package/dist/collaboration/history/HistoryPanel.svelte +531 -0
  38. package/dist/collaboration/history/HistoryPanel.svelte.d.ts +7 -0
  39. package/dist/collaboration/history/VersionHighlights.svelte +103 -0
  40. package/dist/collaboration/history/VersionHighlights.svelte.d.ts +9 -0
  41. package/dist/collaboration/history/client.d.ts +75 -0
  42. package/dist/collaboration/history/client.js +50 -0
  43. package/dist/collaboration/history/diff.d.ts +42 -0
  44. package/dist/collaboration/history/diff.js +99 -0
  45. package/dist/collaboration/history/index.d.ts +9 -0
  46. package/dist/collaboration/history/index.js +9 -0
  47. package/dist/collaboration/history/panel.d.ts +89 -0
  48. package/dist/collaboration/history/panel.js +28 -0
  49. package/dist/collaboration/history/versionHighlights.d.ts +9 -0
  50. package/dist/collaboration/history/versionHighlights.js +17 -0
  51. package/dist/components/Block.svelte +63 -0
  52. package/dist/components/Edytor.svelte +13 -3
  53. package/dist/components/Edytor.svelte.d.ts +7 -0
  54. package/dist/components/Suggestion.svelte +1 -1
  55. package/dist/crdt/doc/anchors.d.ts +17 -0
  56. package/dist/crdt/doc/anchors.js +83 -0
  57. package/dist/crdt/doc/capability.d.ts +56 -0
  58. package/dist/crdt/doc/capability.js +199 -0
  59. package/dist/crdt/doc/content.d.ts +12 -0
  60. package/dist/crdt/doc/content.js +75 -0
  61. package/dist/crdt/doc/delete.d.ts +14 -0
  62. package/dist/crdt/doc/delete.js +91 -0
  63. package/dist/crdt/doc/events.d.ts +9 -0
  64. package/dist/crdt/doc/events.js +63 -0
  65. package/dist/crdt/doc/funnel.d.ts +50 -0
  66. package/dist/crdt/doc/funnel.js +227 -0
  67. package/dist/crdt/doc/gate.d.ts +106 -0
  68. package/dist/crdt/doc/gate.js +118 -0
  69. package/dist/crdt/doc/history.d.ts +27 -0
  70. package/dist/crdt/doc/history.js +207 -0
  71. package/dist/crdt/doc/layout.d.ts +10 -0
  72. package/dist/crdt/doc/layout.js +190 -0
  73. package/dist/crdt/doc/meta.d.ts +19 -0
  74. package/dist/crdt/doc/meta.js +215 -0
  75. package/dist/crdt/doc/moves.d.ts +21 -0
  76. package/dist/crdt/doc/moves.js +254 -0
  77. package/dist/crdt/doc/plan.d.ts +28 -0
  78. package/dist/crdt/doc/plan.js +77 -0
  79. package/dist/crdt/doc/reads.d.ts +61 -0
  80. package/dist/crdt/doc/reads.js +240 -0
  81. package/dist/crdt/doc/seed.d.ts +38 -0
  82. package/dist/crdt/doc/seed.js +107 -0
  83. package/dist/crdt/doc/split-merge.d.ts +12 -0
  84. package/dist/crdt/doc/split-merge.js +180 -0
  85. package/dist/crdt/doc/steps.d.ts +57 -0
  86. package/dist/crdt/doc/steps.js +370 -0
  87. package/dist/crdt/doc/types.d.ts +302 -0
  88. package/dist/crdt/doc/types.js +1 -0
  89. package/dist/crdt/edytor-doc.d.ts +19 -504
  90. package/dist/crdt/edytor-doc.js +72 -2458
  91. package/dist/crdt/index.d.ts +4 -10
  92. package/dist/crdt/index.js +1 -1
  93. package/dist/crdt/placement/display.d.ts +106 -0
  94. package/dist/crdt/placement/display.js +339 -0
  95. package/dist/crdt/placement/model.d.ts +10 -171
  96. package/dist/crdt/placement/model.js +7 -558
  97. package/dist/crdt/placement/resolve.d.ts +38 -0
  98. package/dist/crdt/placement/resolve.js +169 -0
  99. package/dist/crdt/placement/source.d.ts +43 -0
  100. package/dist/crdt/placement/source.js +66 -0
  101. package/dist/crdt/semantics.d.ts +38 -5
  102. package/dist/crdt/semantics.js +25 -6
  103. package/dist/crdt/text/delete-index.d.ts +145 -0
  104. package/dist/crdt/text/delete-index.js +368 -0
  105. package/dist/crdt/text/deletes.d.ts +49 -0
  106. package/dist/crdt/text/deletes.js +2 -379
  107. package/dist/crdt/text/index/anchored.d.ts +17 -0
  108. package/dist/crdt/text/index/anchored.js +196 -0
  109. package/dist/crdt/text/index/cache.d.ts +16 -0
  110. package/dist/crdt/text/index/cache.js +171 -0
  111. package/dist/crdt/text/index/checks.d.ts +15 -0
  112. package/dist/crdt/text/index/checks.js +156 -0
  113. package/dist/crdt/text/index/claims.d.ts +18 -0
  114. package/dist/crdt/text/index/claims.js +213 -0
  115. package/dist/crdt/text/index/fold.d.ts +22 -0
  116. package/dist/crdt/text/index/fold.js +496 -0
  117. package/dist/crdt/text/index/layout.d.ts +21 -0
  118. package/dist/crdt/text/index/layout.js +124 -0
  119. package/dist/crdt/text/index/placement.d.ts +39 -0
  120. package/dist/crdt/text/index/placement.js +450 -0
  121. package/dist/crdt/text/index/records.d.ts +13 -0
  122. package/dist/crdt/text/index/records.js +140 -0
  123. package/dist/crdt/text/index/report.d.ts +18 -0
  124. package/dist/crdt/text/index/report.js +338 -0
  125. package/dist/crdt/text/index/shared.d.ts +64 -0
  126. package/dist/crdt/text/index/shared.js +102 -0
  127. package/dist/crdt/text/index/state.d.ts +213 -0
  128. package/dist/crdt/text/index/state.js +113 -0
  129. package/dist/crdt/text/index/streams.d.ts +20 -0
  130. package/dist/crdt/text/index/streams.js +197 -0
  131. package/dist/crdt/text/items.d.ts +8 -0
  132. package/dist/crdt/text/items.js +2 -0
  133. package/dist/crdt/text/model.d.ts +7 -53
  134. package/dist/crdt/text/model.js +7 -227
  135. package/dist/crdt/text/ranges.d.ts +20 -0
  136. package/dist/crdt/text/ranges.js +82 -0
  137. package/dist/crdt/text/runs.d.ts +10 -16
  138. package/dist/crdt/text/runs.js +39 -2486
  139. package/dist/crdt/text/streams.d.ts +45 -0
  140. package/dist/crdt/text/streams.js +138 -0
  141. package/dist/edytor.svelte.d.ts +6 -1
  142. package/dist/edytor.svelte.js +9 -3
  143. package/dist/index.d.ts +6 -2
  144. package/dist/index.js +6 -1
  145. package/dist/kinds.d.ts +7 -0
  146. package/dist/kinds.js +9 -2
  147. package/dist/labels.d.ts +340 -0
  148. package/dist/labels.js +334 -0
  149. package/dist/plugins/blockHandles/BlockHandle.svelte +4 -7
  150. package/dist/plugins/blockHandles/BlockHandleController.svelte.d.ts +4 -0
  151. package/dist/plugins/blockHandles/BlockHandleController.svelte.js +5 -0
  152. package/dist/plugins/blockHandles/blockHandlesPlugin.d.ts +3 -0
  153. package/dist/plugins/blockHandles/blockHandlesPlugin.js +3 -1
  154. package/dist/plugins/blockMenu/BlockMenu.svelte +88 -21
  155. package/dist/plugins/blockMenu/BlockMenuController.svelte.d.ts +44 -10
  156. package/dist/plugins/blockMenu/BlockMenuController.svelte.js +92 -19
  157. package/dist/plugins/code/CodeHeader.svelte +11 -8
  158. package/dist/plugins/code/CodePlugin.svelte +8 -3
  159. package/dist/plugins/code/languages.d.ts +16 -2
  160. package/dist/plugins/code/languages.js +5 -1
  161. package/dist/plugins/columns/ColumnResize.svelte +1 -1
  162. package/dist/plugins/columns/ColumnsPlugin.svelte +30 -9
  163. package/dist/plugins/columns/ColumnsPlugin.svelte.d.ts +8 -0
  164. package/dist/plugins/columns/resize.svelte.d.ts +6 -1
  165. package/dist/plugins/columns/resize.svelte.js +6 -1
  166. package/dist/plugins/find/FindBar.svelte +17 -16
  167. package/dist/plugins/find/FindController.svelte.d.ts +6 -1
  168. package/dist/plugins/find/FindController.svelte.js +6 -1
  169. package/dist/plugins/find/findPlugin.d.ts +3 -0
  170. package/dist/plugins/find/findPlugin.js +2 -1
  171. package/dist/plugins/icons.js +7 -0
  172. package/dist/plugins/image/ImageChrome.svelte +11 -10
  173. package/dist/plugins/image/ImageEmpty.svelte +19 -16
  174. package/dist/plugins/image/ImagePlugin.svelte +21 -4
  175. package/dist/plugins/image/ImagePlugin.svelte.d.ts +8 -0
  176. package/dist/plugins/image/controls.svelte.d.ts +6 -1
  177. package/dist/plugins/image/controls.svelte.js +6 -1
  178. package/dist/plugins/image/image.d.ts +5 -0
  179. package/dist/plugins/image/image.js +3 -0
  180. package/dist/plugins/index.d.ts +7 -2
  181. package/dist/plugins/index.js +5 -1
  182. package/dist/plugins/markdownShortcuts.js +99 -67
  183. package/dist/plugins/media/AudioPlugin.svelte +11 -5
  184. package/dist/plugins/media/BookmarkPlugin.svelte +26 -14
  185. package/dist/plugins/media/BookmarkPlugin.svelte.d.ts +5 -0
  186. package/dist/plugins/media/EmbedPlugin.svelte +25 -12
  187. package/dist/plugins/media/EmbedPlugin.svelte.d.ts +5 -0
  188. package/dist/plugins/media/FilePlugin.svelte +15 -8
  189. package/dist/plugins/media/MediaEmpty.svelte +14 -13
  190. package/dist/plugins/media/MediaEmpty.svelte.d.ts +3 -8
  191. package/dist/plugins/media/UrlPasteMenu.svelte +1 -1
  192. package/dist/plugins/media/VideoPlugin.svelte +11 -5
  193. package/dist/plugins/media/media.d.ts +12 -2
  194. package/dist/plugins/media/media.js +12 -13
  195. package/dist/plugins/media/urlPaste.svelte.d.ts +7 -2
  196. package/dist/plugins/media/urlPaste.svelte.js +9 -5
  197. package/dist/plugins/mention/MentionPlugin.svelte +163 -31
  198. package/dist/plugins/mention/MentionPlugin.svelte.d.ts +32 -2
  199. package/dist/plugins/page/PageLink.svelte +117 -0
  200. package/dist/plugins/page/PageLink.svelte.d.ts +11 -0
  201. package/dist/plugins/page/PagePlugin.svelte +112 -0
  202. package/dist/plugins/page/PagePlugin.svelte.d.ts +43 -0
  203. package/dist/plugins/page/page.d.ts +54 -0
  204. package/dist/plugins/page/page.js +42 -0
  205. package/dist/plugins/pageLink/PageLinkPlugin.svelte +169 -0
  206. package/dist/plugins/pageLink/PageLinkPlugin.svelte.d.ts +58 -0
  207. package/dist/plugins/richtext/RichTextPlugin.svelte +155 -63
  208. package/dist/plugins/richtext/RichTextPlugin.svelte.d.ts +23 -2
  209. package/dist/plugins/richtext/TodoCheckbox.svelte +35 -0
  210. package/dist/plugins/richtext/TodoCheckbox.svelte.d.ts +11 -0
  211. package/dist/plugins/richtext/labels.d.ts +5 -0
  212. package/dist/plugins/richtext/labels.js +3 -0
  213. package/dist/plugins/richtext/richTextOperations.d.ts +6 -1
  214. package/dist/plugins/richtext/richTextOperations.js +5 -0
  215. package/dist/plugins/slashMenu/SlashMenu.svelte +11 -7
  216. package/dist/plugins/slashMenu/SlashMenuController.svelte.d.ts +25 -29
  217. package/dist/plugins/slashMenu/SlashMenuController.svelte.js +47 -145
  218. package/dist/plugins/slashMenu/slashMenuPlugin.d.ts +3 -0
  219. package/dist/plugins/slashMenu/slashMenuPlugin.js +7 -25
  220. package/dist/plugins/suggestions/SuggestionBars.svelte +13 -6
  221. package/dist/plugins/suggestions/SuggestionBars.svelte.d.ts +2 -0
  222. package/dist/plugins/suggestions/suggestionsPlugin.d.ts +3 -0
  223. package/dist/plugins/suggestions/suggestionsPlugin.js +3 -1
  224. package/dist/plugins/toc/TableOfContents.svelte +83 -0
  225. package/dist/plugins/toc/TableOfContents.svelte.d.ts +7 -0
  226. package/dist/plugins/toc/TocPlugin.svelte +71 -0
  227. package/dist/plugins/toc/TocPlugin.svelte.d.ts +32 -0
  228. package/dist/plugins/toc/toc.d.ts +29 -0
  229. package/dist/plugins/toc/toc.js +10 -0
  230. package/dist/plugins/toolbar/LinkCard.svelte +8 -7
  231. package/dist/plugins/toolbar/Toolbar.svelte +21 -18
  232. package/dist/plugins/toolbar/ToolbarController.svelte.d.ts +9 -2
  233. package/dist/plugins/toolbar/ToolbarController.svelte.js +9 -2
  234. package/dist/plugins/toolbar/toolbarPlugin.d.ts +3 -0
  235. package/dist/plugins/toolbar/toolbarPlugin.js +2 -1
  236. package/dist/plugins/triggers/TriggerController.svelte.d.ts +131 -0
  237. package/dist/plugins/triggers/TriggerController.svelte.js +333 -0
  238. package/dist/plugins/triggers/TriggerMenu.svelte +144 -0
  239. package/dist/plugins/triggers/TriggerMenu.svelte.d.ts +7 -0
  240. package/dist/plugins/triggers/place.d.ts +15 -0
  241. package/dist/plugins/triggers/place.js +37 -0
  242. package/dist/plugins/triggers/triggers.d.ts +12 -0
  243. package/dist/plugins/triggers/triggers.js +87 -0
  244. package/dist/plugins.d.ts +124 -0
  245. package/dist/selection/selection.svelte.d.ts +22 -0
  246. package/dist/selection/selection.svelte.js +22 -0
  247. package/dist/session/announcer.svelte.d.ts +2 -1
  248. package/dist/session/announcer.svelte.js +15 -9
  249. package/dist/session/commands.d.ts +8 -2
  250. package/dist/session/commands.js +43 -7
  251. package/dist/session/inputRules.d.ts +20 -0
  252. package/dist/session/inputRules.js +128 -0
  253. package/dist/surface/attributes.js +4 -0
  254. package/dist/surface/projector.svelte.js +8 -1
  255. package/dist/themes/notion.css +130 -14
  256. package/package.json +4 -2
package/README.md CHANGED
@@ -16,13 +16,16 @@
16
16
 
17
17
  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.
18
18
 
19
- > **Work in progress.** Edytor is a pre-release (`0.1.0-next.34`, `edytor@next` on npm) and not ready for production; the API changes between releases without a compatibility layer. The untagged `edytor@0.0.11` on npm predates the current API. Issues and PRs are welcome: when you report a bug, include the document's JSON value.
19
+ > **Work in progress.** Edytor is a pre-release (`0.1.0-next.36`, `edytor@next` on npm) and not ready for production; the API changes between releases without a compatibility layer. The untagged `edytor@0.0.11` on npm predates the current API. Issues and PRs are welcome: when you report a bug, include the document's JSON value.
20
20
 
21
21
  ## Features
22
22
 
23
- - **Notion-style editing out of the box.** `<Edytor />` alone is a rich text editor with images and block handles: headings, lists, to-dos, toggles, callouts, quotes, dividers, ten marks and Notion's hotkeys. Add the Notion theme, a block menu (drag one block, or every block the selection covers), a slash menu, a selection toolbar, markdown shortcuts (`markdownShortcutsPlugin`) and code blocks.
23
+ - **Notion-style editing out of the box.** `<Edytor />` alone is a rich text editor with images and 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 (`markdownShortcutsPlugin`) and code blocks.
24
+ - **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 `tocPlugin` lists the headings live ([Page](https://edytor.dev/docs/plugins/page), [Table of contents](https://edytor.dev/docs/plugins/table-of-contents)).
24
25
  - **Columns, opt-in.** List `columnsPlugin` 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)).
26
+ - **Mentions, page links and your own triggers.** `createMentionPlugin` (`@` people) and `createPageLinkPlugin` (`[[` pages) take your app's search; a plugin's `inputRules` (`:smile:` → 😄) and `triggers` (a menu on a typed character) declare the rest ([Input rules and triggers](https://edytor.dev/docs/plugins/input-rules)).
25
27
  - **Your markup.** Blocks, marks and inline atoms render through your Svelte snippets; the slash menu, toolbar, block menu and handles take a snippet and keep their behavior.
28
+ - **Your language.** Every word the chrome shows or says, slash keywords included, comes from a labels dictionary each plugin takes; English by default ([Localization](https://edytor.dev/docs/customization/localization)).
26
29
  - **Synced properties.** `block.data`, `atom.data` and `edytor.data` read and write like plain objects (`bind:value={block.data.title}`); each property and each array item syncs on its own, so concurrent edits of different properties, or of different items of one array, merge.
27
30
  - **AI suggestions.** `edytor.suggestions.add(position, content)` proposes text, paragraphs, lists, to-dos or images after, before or inside a block, at the end of its text, or in place of the selection; it streams in, shows only on your screen, and becomes one undo step when accepted ([Suggestions](https://edytor.dev/docs/editor/suggestions)).
28
31
  - **Plugins that can veto anything.** Every command is prepared before it writes; plugins see the command and each planned step and can refuse or replace it.
@@ -160,10 +160,16 @@ export declare class Block {
160
160
  ops: import("../crdt/index.js").DataPatch[];
161
161
  atom?: string;
162
162
  }) => void;
163
- addInlineBlock: (payload: {
164
- index: number;
163
+ /**
164
+ * Insert an inline atom: at `offset` of the block's content (block
165
+ * offsets, an inline atom counting 1; a caret's), or at `index` of the
166
+ * text segment `text`. One `addInlineBlock` operation (its payload names
167
+ * the segment). Answers the text segment right after the atom, where a
168
+ * caret goes (`null` when it was not written, `undefined` when refused).
169
+ */
170
+ addInlineBlock: (payload: BlockOperations["addInlineBlock"] | {
171
+ offset: number;
165
172
  block: JSONInlineBlock;
166
- text: Text;
167
173
  }) => Text | null | undefined;
168
174
  normalizeContent: () => void;
169
175
  normalizeChildren: () => void;
@@ -294,7 +294,20 @@ export class Block {
294
294
  pushContentIntoBlock = batch('pushContentIntoBlock', pushContentIntoBlock);
295
295
  removeInlineBlock = batch('removeInlineBlock', removeInlineBlock, prepareRemoveInline);
296
296
  patchData = batch('patchData', patchData, preparePatch);
297
- addInlineBlock = batch('addInlineBlock', addInlineBlock, undefined, textAfterAtom);
297
+ #addInline = batch('addInlineBlock', addInlineBlock, undefined, textAfterAtom);
298
+ /**
299
+ * Insert an inline atom: at `offset` of the block's content (block
300
+ * offsets, an inline atom counting 1; a caret's), or at `index` of the
301
+ * text segment `text`. One `addInlineBlock` operation (its payload names
302
+ * the segment). Answers the text segment right after the atom, where a
303
+ * caret goes (`null` when it was not written, `undefined` when refused).
304
+ */
305
+ addInlineBlock = (payload) => {
306
+ if (!('offset' in payload))
307
+ return this.#addInline(payload);
308
+ const at = this.textAtOffset(Math.max(0, payload.offset));
309
+ return at ? this.#addInline({ index: at.offset, text: at.text, block: payload.block }) : null;
310
+ };
298
311
  normalizeContent = batch('normalizeContent', normalizeContent);
299
312
  normalizeChildren = batch('normalizeChildren', normalizeChildren);
300
313
  /** @deprecated `edytor.suggestions.add({ end: block.id }, …)`. */
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Block colours (Notion's "Color" in the block menu): a block's text colour
3
+ * and background, by palette name, in two data leaves, `data.color` and
4
+ * `data.background`. Each is one property of the block, so two people
5
+ * colouring it at once keep one value each (per-leaf last writer), and
6
+ * Turn into keeps them (a retype sets only the leaves it names).
7
+ *
8
+ * The core renders a valid name as `data-edytor-color` and
9
+ * `data-edytor-background` on the block element (`Block.svelte`, owned by
10
+ * the attribute table), and its stylesheet paints the bundled names from
11
+ * theme tokens (`--edytor-color-<name>`, `--edytor-background-<name>`).
12
+ */
13
+ import type { Block } from './block.svelte.js';
14
+ import type { Edytor } from '../edytor.svelte.js';
15
+ /** Notion's palette: the colour names a block may hold, in menu order ("Default" is none). */
16
+ export declare const BLOCK_COLORS: readonly ["gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", "red"];
17
+ /**
18
+ * Notion's light values of the palette: the fallbacks of the theme tokens
19
+ * (`--edytor-color-<name>`, `--edytor-background-<name>`), as the core's
20
+ * stylesheet (`Block.svelte`) and the Notion theme write them.
21
+ */
22
+ export declare const BLOCK_PALETTE: Record<(typeof BLOCK_COLORS)[number], {
23
+ color: string;
24
+ background: string;
25
+ }>;
26
+ /** A block's colour fields: its text colour and its background. */
27
+ export type BlockColorField = 'color' | 'background';
28
+ /** `value` as a colour name, or `undefined`. */
29
+ export declare const colorName: (value: unknown) => string | undefined;
30
+ /** The block element's colour attributes for `data` (absent when it holds none). */
31
+ export declare const colorAttributes: (data: Readonly<Record<string, unknown>> | undefined) => {
32
+ 'data-edytor-color': string | undefined;
33
+ 'data-edytor-background': string | undefined;
34
+ };
35
+ /**
36
+ * Whether `block` takes a colour: a block showing its own text (a
37
+ * paragraph, a heading, a list item, a toggle, a callout), not a void (a
38
+ * divider, an image), an island (a code block) or one of its lines.
39
+ */
40
+ export declare const colorable: (block: Block) => boolean;
41
+ /**
42
+ * Set `field` of every colourable block of `blocks` to `value` (`null`
43
+ * removes it: the default), as one command and one undo step; each block
44
+ * is its own data write (`patchData`), so an extension vetoing one keeps
45
+ * that block as it was. Answers whether any block changed.
46
+ */
47
+ export declare const setBlockColor: (edytor: Edytor, blocks: Iterable<Block>, field: BlockColorField, value: string | null) => boolean;
@@ -0,0 +1,74 @@
1
+ /** Notion's palette: the colour names a block may hold, in menu order ("Default" is none). */
2
+ export const BLOCK_COLORS = [
3
+ 'gray',
4
+ 'brown',
5
+ 'orange',
6
+ 'yellow',
7
+ 'green',
8
+ 'blue',
9
+ 'purple',
10
+ 'pink',
11
+ 'red'
12
+ ];
13
+ /**
14
+ * Notion's light values of the palette: the fallbacks of the theme tokens
15
+ * (`--edytor-color-<name>`, `--edytor-background-<name>`), as the core's
16
+ * stylesheet (`Block.svelte`) and the Notion theme write them.
17
+ */
18
+ export const BLOCK_PALETTE = {
19
+ gray: { color: '#7d7a75', background: '#f0efed' },
20
+ brown: { color: '#9f765a', background: '#f5ede9' },
21
+ orange: { color: '#d27b2d', background: '#fbebde' },
22
+ yellow: { color: '#cb9434', background: '#f9f3dc' },
23
+ green: { color: '#50946e', background: '#e8f1ec' },
24
+ blue: { color: '#387dc9', background: '#e5f2fc' },
25
+ purple: { color: '#9a6bb4', background: '#f3ebf9' },
26
+ pink: { color: '#c14c8a', background: '#fae9f1' },
27
+ red: { color: '#cf5148', background: '#fce9e7' }
28
+ };
29
+ /**
30
+ * A colour name the core renders: lowercase letters, digits and hyphens,
31
+ * starting with a letter (an app's own name, such as `teal`, renders too,
32
+ * and its stylesheet paints it). Anything else renders nothing.
33
+ */
34
+ const NAME = /^[a-z][a-z0-9-]{0,31}$/;
35
+ /** `value` as a colour name, or `undefined`. */
36
+ export const colorName = (value) => typeof value === 'string' && NAME.test(value) ? value : undefined;
37
+ /** The block element's colour attributes for `data` (absent when it holds none). */
38
+ export const colorAttributes = (data) => ({
39
+ 'data-edytor-color': colorName(data?.color),
40
+ 'data-edytor-background': colorName(data?.background)
41
+ });
42
+ /**
43
+ * Whether `block` takes a colour: a block showing its own text (a
44
+ * paragraph, a heading, a list item, a toggle, a callout), not a void (a
45
+ * divider, an image), an island (a code block) or one of its lines.
46
+ */
47
+ export const colorable = (block) => {
48
+ const { facade } = block.edytor;
49
+ const line = block.parent && !block.parent.isRoot && facade.isLines(block.parent.id);
50
+ return (!block.isRoot &&
51
+ block.rendersContent &&
52
+ !facade.isVoid(block.id) &&
53
+ !facade.isIsland(block.id) &&
54
+ !line);
55
+ };
56
+ /**
57
+ * Set `field` of every colourable block of `blocks` to `value` (`null`
58
+ * removes it: the default), as one command and one undo step; each block
59
+ * is its own data write (`patchData`), so an extension vetoing one keeps
60
+ * that block as it was. Answers whether any block changed.
61
+ */
62
+ export const setBlockColor = (edytor, blocks, field, value) => {
63
+ const name = value === null ? undefined : colorName(value);
64
+ if (value !== null && name === undefined)
65
+ return false;
66
+ const painted = [...blocks].filter((block) => colorable(block) && edytor.facade.blockDataOf(block.id)?.[field] !== name);
67
+ if (!painted.length)
68
+ return false;
69
+ const applied = edytor.dispatcher.each('setBlockColor', painted, (block) => {
70
+ block.patchData({ ops: [{ path: [field], value: name }] });
71
+ return edytor.dispatcher.last?.status === 'applied';
72
+ });
73
+ return applied.some(Boolean);
74
+ };