edytor 0.1.0-next.30 → 0.1.0-next.32

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Edytor contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -15,11 +15,11 @@
15
15
 
16
16
  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.
17
17
 
18
- > **Work in progress.** Edytor is a pre-release (`0.1.0-next.30`, `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.
18
+ > **Work in progress.** Edytor is a pre-release (`0.1.0-next.32`, `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
19
 
20
20
  ## Features
21
21
 
22
- - **Notion-style editing out of the box.** `<Edytor />` alone is a rich text editor with images: headings, lists, to-dos, toggles, callouts, quotes, dividers, ten marks, Notion's markdown shortcuts and hotkeys. Add the Notion theme, block handles with a block menu (drag one block, or every block the selection covers), a slash menu, a selection toolbar and code blocks.
22
+ - **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
23
  - **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)).
24
24
  - **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.
25
25
  - **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.
@@ -4,6 +4,7 @@
4
4
  import type { SerializableContent } from '../../utils/json.js';
5
5
  import type { HotKey } from '../../session/keymap.js';
6
6
  import {
7
+ pastedLink,
7
8
  richTextOperations,
8
9
  sanitizeLinkHref,
9
10
  sanitizeCssColorValue,
@@ -141,6 +142,19 @@
141
142
  ])
142
143
  )
143
144
  },
145
+ // Pasting a link over selected text links it (Notion), where the toolbar
146
+ // offers a link: a text range outside code blocks and voids.
147
+ onPaste: ({ e, prevent }) => {
148
+ const { selection } = edytor;
149
+ const { value, projection } = selection;
150
+ if (value.kind !== 'text' || selection.state.isCollapsed) return;
151
+ if (projection.islandRoot !== null || projection.voidRoot !== null) return;
152
+ const href = pastedLink(e.clipboardData?.getData('text/plain'));
153
+ if (href)
154
+ prevent(() =>
155
+ edytor.dispatcher.run('insertFromPaste', () => operations.setLinkAtRange({ href }))
156
+ );
157
+ },
144
158
  onBeforeInput: ({ e, prevent }) => {
145
159
  const { inputType, data } = e;
146
160
  if (isNativeFormatInputType(inputType)) {
@@ -17,13 +17,20 @@ export declare const sanitizeCssColorValue: (value: unknown) => string | null;
17
17
  /**
18
18
  * Scheme allowlist for link hrefs. `javascript:`/`data:`/`vbscript:`
19
19
  * payloads can arrive through native `insertLink`, pasted HTML, or a
20
- * malicious collaborator — and Svelte renders `href` verbatim. The URL
21
- * parser is used rather than a regex so whitespace/case obfuscation
22
- * (`java\tscript:`) can't slip through. Scheme-less hrefs (relative
23
- * paths, anchors, queries, protocol-relative) are not scriptable and
24
- * pass through.
20
+ * malicious collaborator — and Svelte renders `href` verbatim. The href is
21
+ * read as the browser's URL parser reads it: it strips C0 controls and
22
+ * spaces at both ends and tab/newline/CR anywhere (`\u0001javascript:` is
23
+ * `javascript:` to a browser), then resolves it against a base; only an
24
+ * allowed scheme, or a relative href that stays relative, passes.
25
25
  */
26
26
  export declare const sanitizeLinkHref: (href: unknown) => string | null;
27
+ /**
28
+ * The URL a paste carries when its plain text is one link and nothing else
29
+ * (surrounding whitespace aside): `http:`/`https:` with a host, or
30
+ * `mailto:`. `null` for anything else — words, several URLs, a bare
31
+ * domain, a scriptable scheme.
32
+ */
33
+ export declare const pastedLink: (plain: string | undefined | null) => string | null;
27
34
  export declare const richTextOperations: (edytor: Edytor) => {
28
35
  /**
29
36
  * Insert a `divider` void block at the caret — the native
@@ -26,27 +26,45 @@ export const sanitizeCssColorValue = (value) => {
26
26
  /**
27
27
  * Scheme allowlist for link hrefs. `javascript:`/`data:`/`vbscript:`
28
28
  * payloads can arrive through native `insertLink`, pasted HTML, or a
29
- * malicious collaborator — and Svelte renders `href` verbatim. The URL
30
- * parser is used rather than a regex so whitespace/case obfuscation
31
- * (`java\tscript:`) can't slip through. Scheme-less hrefs (relative
32
- * paths, anchors, queries, protocol-relative) are not scriptable and
33
- * pass through.
29
+ * malicious collaborator — and Svelte renders `href` verbatim. The href is
30
+ * read as the browser's URL parser reads it: it strips C0 controls and
31
+ * spaces at both ends and tab/newline/CR anywhere (`\u0001javascript:` is
32
+ * `javascript:` to a browser), then resolves it against a base; only an
33
+ * allowed scheme, or a relative href that stays relative, passes.
34
34
  */
35
35
  export const sanitizeLinkHref = (href) => {
36
36
  // Marks arrive from untrusted sources too (synced peers, paste) —
37
37
  // reject non-strings outright instead of throwing on `.replace`.
38
38
  if (typeof href !== 'string')
39
39
  return null;
40
- // WHATWG URL preprocessing removes tab/newline/CR before parsing —
41
- // doing it here too means `java\tscript:` collapses back to a
42
- // detectable scheme instead of slipping through as "scheme-less".
43
- const trimmed = href.replace(/[\t\n\r]/g, '').trim();
40
+ // eslint-disable-next-line no-control-regex
41
+ const trimmed = href.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, '');
44
42
  if (!trimmed)
45
43
  return null;
46
- if (!/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(trimmed))
47
- return trimmed;
48
44
  try {
49
- return SAFE_LINK_PROTOCOLS.has(new URL(trimmed).protocol) ? trimmed : null;
45
+ // A relative href resolves to the base's `https:`: it names no scheme of its own.
46
+ return SAFE_LINK_PROTOCOLS.has(new URL(trimmed, 'https://relative.invalid/').protocol)
47
+ ? trimmed
48
+ : null;
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ };
54
+ /**
55
+ * The URL a paste carries when its plain text is one link and nothing else
56
+ * (surrounding whitespace aside): `http:`/`https:` with a host, or
57
+ * `mailto:`. `null` for anything else — words, several URLs, a bare
58
+ * domain, a scriptable scheme.
59
+ */
60
+ export const pastedLink = (plain) => {
61
+ const text = plain?.trim();
62
+ if (!text || /\s/.test(text))
63
+ return null;
64
+ try {
65
+ const url = new URL(text);
66
+ const web = (url.protocol === 'http:' || url.protocol === 'https:') && url.host;
67
+ return web || (url.protocol === 'mailto:' && url.pathname) ? sanitizeLinkHref(text) : null;
50
68
  }
51
69
  catch {
52
70
  return null;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "edytor",
3
- "version": "0.1.0-next.30",
3
+ "license": "MIT",
4
+ "version": "0.1.0-next.32",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "git+https://github.com/beynar/edytor.git"