@sametalmdr/word-editor 0.2.0-alpha → 0.3.0-alpha
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/CHANGELOG.md +108 -70
- package/LICENSE +21 -21
- package/README.md +286 -247
- package/dist/canvas/box-clipboard.js +238 -238
- package/dist/canvas/box-selection.js +80 -80
- package/dist/canvas/canvas-editor.js +502 -502
- package/dist/canvas/controller.js +717 -717
- package/dist/canvas/geometry.js +131 -131
- package/dist/canvas/gesture.d.ts +0 -1
- package/dist/canvas/gesture.js +289 -289
- package/dist/canvas/handles.js +212 -212
- package/dist/canvas/menu.js +82 -82
- package/dist/canvas/mode-controller.js +81 -81
- package/dist/canvas/nudge.js +108 -108
- package/dist/canvas/overlay.js +149 -149
- package/dist/canvas/snap.js +132 -132
- package/dist/canvas/viewport.js +112 -112
- package/dist/canvas/z-order.js +171 -171
- package/dist/commands/alignment.js +150 -150
- package/dist/commands/box.js +272 -272
- package/dist/commands/clipboard.js +93 -93
- package/dist/commands/graphemes.js +112 -112
- package/dist/commands/marks.js +153 -153
- package/dist/commands/paragraph-props.js +176 -176
- package/dist/commands/size.js +368 -368
- package/dist/commands/text.js +291 -291
- package/dist/docx.d.ts +1 -0
- package/dist/docx.js +15 -13
- package/dist/editor/editing-host.js +434 -434
- package/dist/element.js +41 -41
- package/dist/fonts/OFL-Carlito.txt +94 -0
- package/dist/fonts/calibri-metrics.d.ts +27 -0
- package/dist/fonts/calibri-metrics.js +88 -0
- package/dist/history/history.js +433 -433
- package/dist/index.js +63 -63
- package/dist/input/beforeinput.js +224 -224
- package/dist/input/clipboard.js +107 -107
- package/dist/input/composition.js +341 -341
- package/dist/input/keymap.js +54 -54
- package/dist/io/ooxml/custgeom.js +72 -72
- package/dist/io/ooxml/drawingml.js +232 -232
- package/dist/io/ooxml/edits.js +67 -67
- package/dist/io/ooxml/export-splice.js +880 -880
- package/dist/io/ooxml/export.js +365 -365
- package/dist/io/ooxml/fill.d.ts +93 -8
- package/dist/io/ooxml/fill.js +618 -562
- package/dist/io/ooxml/fit.d.ts +252 -0
- package/dist/io/ooxml/fit.js +598 -0
- package/dist/io/ooxml/import-gate.js +200 -200
- package/dist/io/ooxml/import.js +691 -691
- package/dist/io/ooxml/inflate.js +126 -126
- package/dist/io/ooxml/media.js +87 -87
- package/dist/io/ooxml/ns.d.ts +2 -0
- package/dist/io/ooxml/ns.js +26 -21
- package/dist/io/ooxml/numbering.js +290 -290
- package/dist/io/ooxml/opc-write.js +171 -171
- package/dist/io/ooxml/provenance.js +93 -93
- package/dist/io/ooxml/recipe.js +708 -708
- package/dist/io/ooxml/relationships.js +59 -59
- package/dist/io/ooxml/run-fonts.d.ts +89 -0
- package/dist/io/ooxml/run-fonts.js +378 -0
- package/dist/io/ooxml/slots.d.ts +4 -0
- package/dist/io/ooxml/slots.js +582 -581
- package/dist/io/ooxml/styles-resolve.js +257 -257
- package/dist/io/ooxml/units.js +43 -43
- package/dist/io/ooxml/value.js +120 -120
- package/dist/io/ooxml/xml-scan.js +616 -616
- package/dist/io/ooxml/zip-container.js +228 -228
- package/dist/io/ooxml/zip-reject.js +106 -106
- package/dist/measure/placement.js +83 -83
- package/dist/measure/report.js +75 -75
- package/dist/model/ids.js +70 -70
- package/dist/model/normalize.js +146 -146
- package/dist/model/position.js +283 -283
- package/dist/model/transaction.js +209 -209
- package/dist/platform/capabilities.js +25 -25
- package/dist/react/index.js +21 -21
- package/dist/selection/controller.js +315 -315
- package/dist/selection/dom-map.js +334 -334
- package/dist/state/editor-state.js +109 -109
- package/dist/styles.css +66 -66
- package/package.json +94 -93
package/dist/input/clipboard.js
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import { deleteSelection } from "../commands/text.js";
|
|
2
|
-
import { pasteText, serializeToText } from "../commands/clipboard.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* `paste` / `copy` / `cut` / `dragstart` / `drop` — the events outside the
|
|
6
|
-
* `beforeinput` matrix (plan §4). `beforeinput`'s own `insertFromPaste` is
|
|
7
|
-
* deliberately left a no-op in `input/beforeinput.js`: it does not reliably
|
|
8
|
-
* carry clipboard data across browsers, so the `paste` event is the one
|
|
9
|
-
* source of truth here.
|
|
10
|
-
*
|
|
11
|
-
* Every line of text in and out is `text/plain`, never `text/html` —
|
|
12
|
-
* ARCHITECTURE.md §2 says the browser's HTML is not the data model, and that
|
|
13
|
-
* holds in both directions: we do not parse HTML pasted in, and we do not
|
|
14
|
-
* write HTML out, so a paste into a different application never carries our
|
|
15
|
-
* internal structure by accident.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/** Splits on every line-ending style a `text/plain` clipboard payload can use. */
|
|
19
|
-
const LINE_SPLIT = /\r\n|\r|\n/;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The minimal surface of `DataTransfer` this module needs.
|
|
23
|
-
* @typedef {object} ClipboardDataLike
|
|
24
|
-
* @property {(type: string) => string} getData
|
|
25
|
-
* @property {(type: string, value: string) => void} setData
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @typedef {object} ClipboardEventLike
|
|
30
|
-
* @property {ClipboardDataLike | null} [clipboardData]
|
|
31
|
-
* @property {() => void} preventDefault
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @typedef {object} ClipboardContext
|
|
36
|
-
* @property {() => import("../state/editor-state.js").EditorState} getState
|
|
37
|
-
* @property {(tr: import("../model/transaction.js").Transaction) => void} dispatch
|
|
38
|
-
* @property {import("../model/ids.js").IdFactory} ids
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @param {ClipboardEventLike} event
|
|
43
|
-
* @param {ClipboardContext} context
|
|
44
|
-
* @returns {void}
|
|
45
|
-
*/
|
|
46
|
-
export function handlePaste(event, context) {
|
|
47
|
-
event.preventDefault();
|
|
48
|
-
|
|
49
|
-
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
50
|
-
if (text === "") {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const tr = pasteText(context.getState(), text.split(LINE_SPLIT), context.ids);
|
|
55
|
-
if (tr !== null) {
|
|
56
|
-
context.dispatch(tr);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @param {ClipboardEventLike} event
|
|
62
|
-
* @param {ClipboardContext} context
|
|
63
|
-
* @returns {void}
|
|
64
|
-
*/
|
|
65
|
-
export function handleCopy(event, context) {
|
|
66
|
-
event.preventDefault();
|
|
67
|
-
|
|
68
|
-
const state = context.getState();
|
|
69
|
-
event.clipboardData?.setData("text/plain", serializeToText(state.doc, state.selection));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Writes the selection to the clipboard, then deletes it — the same
|
|
74
|
-
* serialisation `copy` uses, plus one command. Not two separate operations
|
|
75
|
-
* dispatched independently: the deletion goes through `context.dispatch` exactly
|
|
76
|
-
* once, so it is one undo entry, matching what the user did in one keystroke.
|
|
77
|
-
* @param {ClipboardEventLike} event
|
|
78
|
-
* @param {ClipboardContext} context
|
|
79
|
-
* @returns {void}
|
|
80
|
-
*/
|
|
81
|
-
export function handleCut(event, context) {
|
|
82
|
-
event.preventDefault();
|
|
83
|
-
|
|
84
|
-
const state = context.getState();
|
|
85
|
-
event.clipboardData?.setData("text/plain", serializeToText(state.doc, state.selection));
|
|
86
|
-
|
|
87
|
-
const tr = deleteSelection(state, "input");
|
|
88
|
-
if (tr !== null) {
|
|
89
|
-
context.dispatch(tr);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @param {ClipboardEventLike} event
|
|
95
|
-
* @returns {void}
|
|
96
|
-
*/
|
|
97
|
-
export function handleDragStart(event) {
|
|
98
|
-
event.preventDefault();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @param {ClipboardEventLike} event
|
|
103
|
-
* @returns {void}
|
|
104
|
-
*/
|
|
105
|
-
export function handleDrop(event) {
|
|
106
|
-
event.preventDefault();
|
|
107
|
-
}
|
|
1
|
+
import { deleteSelection } from "../commands/text.js";
|
|
2
|
+
import { pasteText, serializeToText } from "../commands/clipboard.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `paste` / `copy` / `cut` / `dragstart` / `drop` — the events outside the
|
|
6
|
+
* `beforeinput` matrix (plan §4). `beforeinput`'s own `insertFromPaste` is
|
|
7
|
+
* deliberately left a no-op in `input/beforeinput.js`: it does not reliably
|
|
8
|
+
* carry clipboard data across browsers, so the `paste` event is the one
|
|
9
|
+
* source of truth here.
|
|
10
|
+
*
|
|
11
|
+
* Every line of text in and out is `text/plain`, never `text/html` —
|
|
12
|
+
* ARCHITECTURE.md §2 says the browser's HTML is not the data model, and that
|
|
13
|
+
* holds in both directions: we do not parse HTML pasted in, and we do not
|
|
14
|
+
* write HTML out, so a paste into a different application never carries our
|
|
15
|
+
* internal structure by accident.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Splits on every line-ending style a `text/plain` clipboard payload can use. */
|
|
19
|
+
const LINE_SPLIT = /\r\n|\r|\n/;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The minimal surface of `DataTransfer` this module needs.
|
|
23
|
+
* @typedef {object} ClipboardDataLike
|
|
24
|
+
* @property {(type: string) => string} getData
|
|
25
|
+
* @property {(type: string, value: string) => void} setData
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} ClipboardEventLike
|
|
30
|
+
* @property {ClipboardDataLike | null} [clipboardData]
|
|
31
|
+
* @property {() => void} preventDefault
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {object} ClipboardContext
|
|
36
|
+
* @property {() => import("../state/editor-state.js").EditorState} getState
|
|
37
|
+
* @property {(tr: import("../model/transaction.js").Transaction) => void} dispatch
|
|
38
|
+
* @property {import("../model/ids.js").IdFactory} ids
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {ClipboardEventLike} event
|
|
43
|
+
* @param {ClipboardContext} context
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
export function handlePaste(event, context) {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
|
|
49
|
+
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
50
|
+
if (text === "") {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const tr = pasteText(context.getState(), text.split(LINE_SPLIT), context.ids);
|
|
55
|
+
if (tr !== null) {
|
|
56
|
+
context.dispatch(tr);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {ClipboardEventLike} event
|
|
62
|
+
* @param {ClipboardContext} context
|
|
63
|
+
* @returns {void}
|
|
64
|
+
*/
|
|
65
|
+
export function handleCopy(event, context) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
|
|
68
|
+
const state = context.getState();
|
|
69
|
+
event.clipboardData?.setData("text/plain", serializeToText(state.doc, state.selection));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Writes the selection to the clipboard, then deletes it — the same
|
|
74
|
+
* serialisation `copy` uses, plus one command. Not two separate operations
|
|
75
|
+
* dispatched independently: the deletion goes through `context.dispatch` exactly
|
|
76
|
+
* once, so it is one undo entry, matching what the user did in one keystroke.
|
|
77
|
+
* @param {ClipboardEventLike} event
|
|
78
|
+
* @param {ClipboardContext} context
|
|
79
|
+
* @returns {void}
|
|
80
|
+
*/
|
|
81
|
+
export function handleCut(event, context) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
|
|
84
|
+
const state = context.getState();
|
|
85
|
+
event.clipboardData?.setData("text/plain", serializeToText(state.doc, state.selection));
|
|
86
|
+
|
|
87
|
+
const tr = deleteSelection(state, "input");
|
|
88
|
+
if (tr !== null) {
|
|
89
|
+
context.dispatch(tr);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {ClipboardEventLike} event
|
|
95
|
+
* @returns {void}
|
|
96
|
+
*/
|
|
97
|
+
export function handleDragStart(event) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {ClipboardEventLike} event
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
export function handleDrop(event) {
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
}
|