@daasboard/editor 0.0.0-stage → 0.1.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 (83) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +6 -2
  3. package/dist/camera/CameraInput.d.ts +106 -0
  4. package/dist/camera/CameraInput.js +398 -0
  5. package/dist/clipboard/ObjectClipboard.d.ts +40 -0
  6. package/dist/clipboard/ObjectClipboard.js +243 -0
  7. package/dist/clipboard/PasteCommitError.d.ts +4 -0
  8. package/dist/clipboard/PasteCommitError.js +7 -0
  9. package/dist/clipboard/carrier.d.ts +5 -0
  10. package/dist/clipboard/carrier.js +59 -0
  11. package/dist/clipboard/objects.d.ts +21 -0
  12. package/dist/clipboard/objects.js +362 -0
  13. package/dist/clipboard/placement.d.ts +11 -0
  14. package/dist/clipboard/placement.js +21 -0
  15. package/dist/clipboard/systemImages.d.ts +1 -0
  16. package/dist/clipboard/systemImages.js +24 -0
  17. package/dist/index.d.ts +23 -0
  18. package/dist/index.js +22 -0
  19. package/dist/input/TouchInput.d.ts +159 -0
  20. package/dist/input/TouchInput.js +656 -0
  21. package/dist/input/visiblePart.d.ts +8 -0
  22. package/dist/input/visiblePart.js +15 -0
  23. package/dist/interaction/InteractionLayer.d.ts +83 -0
  24. package/dist/interaction/InteractionLayer.js +520 -0
  25. package/dist/props/PropertyController.d.ts +130 -0
  26. package/dist/props/PropertyController.js +1448 -0
  27. package/dist/props/PropertyRegistry.d.ts +38 -0
  28. package/dist/props/PropertyRegistry.js +21 -0
  29. package/dist/props/builtinProperties.d.ts +23 -0
  30. package/dist/props/builtinProperties.js +350 -0
  31. package/dist/props/defaults.d.ts +6 -0
  32. package/dist/props/defaults.js +29 -0
  33. package/dist/selection/SelectionModel.d.ts +25 -0
  34. package/dist/selection/SelectionModel.js +79 -0
  35. package/dist/text/CanvasEditorView.d.ts +99 -0
  36. package/dist/text/CanvasEditorView.js +308 -0
  37. package/dist/text/InputSink.d.ts +157 -0
  38. package/dist/text/InputSink.js +841 -0
  39. package/dist/text/TextEditSession.d.ts +173 -0
  40. package/dist/text/TextEditSession.js +1328 -0
  41. package/dist/text/clipboard.d.ts +11 -0
  42. package/dist/text/clipboard.js +489 -0
  43. package/dist/text/commands.d.ts +48 -0
  44. package/dist/text/commands.js +329 -0
  45. package/dist/text/contextMirror.d.ts +51 -0
  46. package/dist/text/contextMirror.js +292 -0
  47. package/dist/text/flat.d.ts +35 -0
  48. package/dist/text/flat.js +556 -0
  49. package/dist/text/graphemes.d.ts +16 -0
  50. package/dist/text/graphemes.js +219 -0
  51. package/dist/text/index.d.ts +13 -0
  52. package/dist/text/index.js +13 -0
  53. package/dist/text/inputReducer.d.ts +24 -0
  54. package/dist/text/inputReducer.js +44 -0
  55. package/dist/text/keymap.d.ts +17 -0
  56. package/dist/text/keymap.js +148 -0
  57. package/dist/text/schema.d.ts +12 -0
  58. package/dist/text/schema.js +44 -0
  59. package/dist/text/sessionFocus.d.ts +20 -0
  60. package/dist/text/sessionFocus.js +51 -0
  61. package/dist/text/types.d.ts +114 -0
  62. package/dist/text/types.js +1 -0
  63. package/dist/tools/CreateTool.d.ts +78 -0
  64. package/dist/tools/CreateTool.js +258 -0
  65. package/dist/tools/SelectTool.d.ts +155 -0
  66. package/dist/tools/SelectTool.js +808 -0
  67. package/dist/tools/ToolManager.d.ts +63 -0
  68. package/dist/tools/ToolManager.js +146 -0
  69. package/dist/tools/connectorEndpoints.d.ts +17 -0
  70. package/dist/tools/connectorEndpoints.js +53 -0
  71. package/dist/tools/frameRotation.d.ts +8 -0
  72. package/dist/tools/frameRotation.js +66 -0
  73. package/dist/tools/gradientHandles.d.ts +67 -0
  74. package/dist/tools/gradientHandles.js +110 -0
  75. package/dist/tools/presetPaths.d.ts +5 -0
  76. package/dist/tools/presetPaths.js +49 -0
  77. package/dist/tools/snapResize.d.ts +7 -0
  78. package/dist/tools/snapResize.js +65 -0
  79. package/dist/tools/snapping.d.ts +30 -0
  80. package/dist/tools/snapping.js +280 -0
  81. package/dist/tools/transform.d.ts +52 -0
  82. package/dist/tools/transform.js +277 -0
  83. package/package.json +36 -3
@@ -0,0 +1,219 @@
1
+ const segmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(undefined, { granularity: "grapheme" }) : null;
2
+ const wordSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(undefined, { granularity: "word" }) : null;
3
+ const isHigh = (c) => c >= 0xd800 && c <= 0xdbff;
4
+ const isLow = (c) => c >= 0xdc00 && c <= 0xdfff;
5
+ function codePointBefore(text, i) {
6
+ const c = text.charCodeAt(i - 1);
7
+ return isLow(c) && i >= 2 && isHigh(text.charCodeAt(i - 2)) ? text.codePointAt(i - 2) : c;
8
+ }
9
+ const cpLen = (cp) => (cp > 0xffff ? 2 : 1);
10
+ const ZWJ = 0x200d;
11
+ const mark = /\p{M}/u;
12
+ const isExtender = (cp) => cp === 0xfe0e || cp === 0xfe0f || (cp >= 0x1f3fb && cp <= 0x1f3ff) || mark.test(String.fromCodePoint(cp));
13
+ const isRegionalIndicator = (cp) => cp >= 0x1f1e6 && cp <= 0x1f1ff;
14
+ function regionalIndicatorsBefore(text, i) {
15
+ let n = 0;
16
+ for (let k = i; k > 0;) {
17
+ const cp = codePointBefore(text, k);
18
+ if (!isRegionalIndicator(cp))
19
+ break;
20
+ n++;
21
+ k -= cpLen(cp);
22
+ }
23
+ return n;
24
+ }
25
+ export function nextGraphemeEndFallback(text, i) {
26
+ if (i >= text.length)
27
+ return text.length;
28
+ const first = text.codePointAt(i);
29
+ let j = i + cpLen(first);
30
+ if (isRegionalIndicator(first) && regionalIndicatorsBefore(text, i) % 2 === 0 && j < text.length && isRegionalIndicator(text.codePointAt(j)))
31
+ j += 2;
32
+ for (;;) {
33
+ if (j >= text.length)
34
+ break;
35
+ const cp = text.codePointAt(j);
36
+ if (isExtender(cp)) {
37
+ j += cpLen(cp);
38
+ continue;
39
+ }
40
+ if (cp === ZWJ) {
41
+ j += 1;
42
+ if (j < text.length)
43
+ j += cpLen(text.codePointAt(j));
44
+ continue;
45
+ }
46
+ break;
47
+ }
48
+ return j;
49
+ }
50
+ export function prevGraphemeStartFallback(text, i) {
51
+ if (i <= 0)
52
+ return 0;
53
+ let j = i;
54
+ for (;;) {
55
+ while (j > 0 && isExtender(codePointBefore(text, j)))
56
+ j -= cpLen(codePointBefore(text, j));
57
+ if (j === 0)
58
+ return 0;
59
+ const base = codePointBefore(text, j);
60
+ j -= cpLen(base);
61
+ if (isRegionalIndicator(base)) {
62
+ if (regionalIndicatorsBefore(text, j) % 2 === 1)
63
+ j -= 2;
64
+ return j;
65
+ }
66
+ if (j > 0 && text.charCodeAt(j - 1) === ZWJ) {
67
+ j -= 1;
68
+ if (j === 0)
69
+ return 0;
70
+ continue;
71
+ }
72
+ return j;
73
+ }
74
+ }
75
+ export function nextGraphemeEnd(text, i) {
76
+ if (i < 0)
77
+ i = 0;
78
+ if (i >= text.length)
79
+ return text.length;
80
+ if (segmenter) {
81
+ const seg = segmenter.segment(text).containing(i);
82
+ if (seg)
83
+ return seg.index + seg.segment.length;
84
+ }
85
+ return nextGraphemeEndFallback(text, i);
86
+ }
87
+ export function prevGraphemeStart(text, i) {
88
+ if (i <= 0)
89
+ return 0;
90
+ if (i > text.length)
91
+ i = text.length;
92
+ if (segmenter) {
93
+ const seg = segmenter.segment(text).containing(i - 1);
94
+ if (seg)
95
+ return seg.index;
96
+ }
97
+ return prevGraphemeStartFallback(text, i);
98
+ }
99
+ const lineBreak = /[\r\n\u2028\u2029]/u;
100
+ const horizontalSpace = /^\s+$/u;
101
+ const fallbackWord = /[\p{L}\p{N}\p{M}_]/u;
102
+ function segmentKind(text, wordLike) {
103
+ if (wordLike)
104
+ return "word";
105
+ if (lineBreak.test(text))
106
+ return "break";
107
+ return horizontalSpace.test(text) ? "space" : "symbol";
108
+ }
109
+ function wordLookup(text) {
110
+ if (wordSegmenter) {
111
+ const segments = wordSegmenter.segment(text);
112
+ return (offset) => {
113
+ const s = segments.containing(offset);
114
+ return s && { start: s.index, end: s.index + s.segment.length, kind: segmentKind(s.segment, !!s.isWordLike) };
115
+ };
116
+ }
117
+ const segments = [];
118
+ for (let start = 0; start < text.length;) {
119
+ const end = nextGraphemeEndFallback(text, start);
120
+ const grapheme = text.slice(start, end);
121
+ const kind = segmentKind(grapheme, fallbackWord.test(grapheme));
122
+ const last = segments[segments.length - 1];
123
+ if (last && last.kind === kind && (kind === "word" || kind === "space"))
124
+ last.end = end;
125
+ else
126
+ segments.push({ start, end, kind });
127
+ start = end;
128
+ }
129
+ return (offset) => {
130
+ let lo = 0;
131
+ let hi = segments.length - 1;
132
+ while (lo <= hi) {
133
+ const mid = (lo + hi) >>> 1;
134
+ const segment = segments[mid];
135
+ if (offset < segment.start)
136
+ hi = mid - 1;
137
+ else if (offset >= segment.end)
138
+ lo = mid + 1;
139
+ else
140
+ return segment;
141
+ }
142
+ return undefined;
143
+ };
144
+ }
145
+ export function nextWordEnd(text, i) {
146
+ i = Math.max(0, Math.min(text.length, i));
147
+ if (i === text.length)
148
+ return i;
149
+ const at = wordLookup(text);
150
+ let s = at(i);
151
+ const skippedSpace = s?.kind === "space";
152
+ while (s?.kind === "space")
153
+ s = at(s.end);
154
+ if (!s)
155
+ return text.length;
156
+ if (skippedSpace && s.kind === "break")
157
+ return s.start;
158
+ let end = s.end;
159
+ if (s.kind === "symbol") {
160
+ for (let next = at(end); next?.kind === "symbol"; next = at(end))
161
+ end = next.end;
162
+ }
163
+ return end;
164
+ }
165
+ export function nextWordStart(text, i) {
166
+ i = Math.max(0, Math.min(text.length, i));
167
+ if (i === text.length)
168
+ return i;
169
+ const at = wordLookup(text);
170
+ const s = at(i);
171
+ if (!s)
172
+ return text.length;
173
+ let end = s.end;
174
+ if (s.kind === "break")
175
+ return end;
176
+ if (s.kind === "symbol") {
177
+ for (let next = at(end); next?.kind === "symbol"; next = at(end))
178
+ end = next.end;
179
+ }
180
+ for (let next = at(end); next?.kind === "space"; next = at(end))
181
+ end = next.end;
182
+ return end;
183
+ }
184
+ export function prevWordStart(text, i) {
185
+ i = Math.max(0, Math.min(text.length, i));
186
+ if (i === 0)
187
+ return i;
188
+ const at = wordLookup(text);
189
+ let s = at(i - 1);
190
+ while (s?.kind === "space")
191
+ s = at(s.start - 1);
192
+ if (!s)
193
+ return 0;
194
+ let start = s.start;
195
+ if (s.kind === "symbol") {
196
+ for (let prev = at(start - 1); prev?.kind === "symbol"; prev = at(start - 1))
197
+ start = prev.start;
198
+ }
199
+ return start;
200
+ }
201
+ export function wordRangeAt(text, i, affinity = "downstream", includeTrailingSpace = false) {
202
+ return wordRanges(text)(i, affinity, includeTrailingSpace);
203
+ }
204
+ export function wordRanges(text) {
205
+ if (text.length === 0)
206
+ return () => ({ start: 0, end: 0 });
207
+ const at = wordLookup(text);
208
+ return (i, affinity = "downstream", includeTrailingSpace = false) => {
209
+ i = Math.max(0, Math.min(text.length, i));
210
+ const offset = i === text.length || (affinity === "upstream" && i > 0) ? i - 1 : i;
211
+ const s = at(offset);
212
+ let end = s.end;
213
+ if (includeTrailingSpace && s.kind !== "break") {
214
+ for (let next = at(end); next?.kind === "space"; next = at(end))
215
+ end = next.end;
216
+ }
217
+ return { start: s.start, end };
218
+ };
219
+ }
@@ -0,0 +1,13 @@
1
+ export * from "./types.js";
2
+ export { schema, INLINE_MARK_KEYS, PARAGRAPH_ATTR_KEYS, BOOLEAN_MARK_KEYS, paragraphType, markType, type InlineMarkKey, type ParagraphAttrKey, type ParagraphAlign, type ParagraphList, type BooleanMarkKey } from "./schema.js";
3
+ export { type Attrs, type Flat, EMPTY_ATTRS, ALL_ATTR_KEYS, isCodePointBoundary, snapDown, snapUp, sameAttrs, attrsEqual, formatChange, pmToFlat, pmToText, flatToPm, contentToPm, paragraphReadsAs, pmToContent, paragraphStarts, paragraphIndexAtOffset, paragraphIndexAtPos, pmPosToOffset, offsetToPmPos, diffToDelta, changedParagraphs, pmDiffToDelta, applyDeltaToFlat, } from "./flat.js";
4
+ export { CanvasEditorView, CARET_AFFINITY, VERTICAL_MOTION, buildLines, lineIndexIn, lineGeometry, caretRect, selectionRects, type CaretAffinity, type CanvasEditorViewProps, type LineInfo, type LineGeometry } from "./CanvasEditorView.js";
5
+ export * from "./commands.js";
6
+ export { buildKeymap, handleKey, keyCodeOf, isMacPlatform, isWindowsPlatform, resolveTextPlatform, type Keymap, type KeymapOptions } from "./keymap.js";
7
+ export { nextGraphemeEndFallback, prevGraphemeStartFallback } from "./graphemes.js";
8
+ export { TextEditSession, FROM_DOC, LABEL, BLINK_MS, type TextEditSessionOptions, type PointerPhase } from "./TextEditSession.js";
9
+ export { InputSink, type InputSinkOptions, type SinkElementLike, type SinkHostLike, type SinkEvent, type SinkKeyboardEvent, type SinkInputEvent, type SinkStaticRange, type SinkCompositionEvent, type SinkClipboardEvent, type SinkFocusEvent } from "./InputSink.js";
10
+ export { MIRROR_MAX_UNITS, MIRROR_GAP, mirrorWindow, toMirror, toFlat, selectionToFlat, diffText, compositionRange, domMirror, type MirrorSegment, type MirrorWindow, type MirrorText, type TextEdit, type SinkMirrorDom } from "./contextMirror.js";
11
+ export { watchSessionFocus, caretWhileFocused, type SessionFocusOptions, type SessionFocusEvent, type SessionFocusSource } from "./sessionFocus.js";
12
+ export { interpretBeforeInput, normalizePasteText, type InputAction, type DeleteUnit } from "./inputReducer.js";
13
+ export { serializeClipboard, parseClipboard, clipboardTransaction, type ClipboardContent } from "./clipboard.js";
@@ -0,0 +1,13 @@
1
+ export * from "./types.js";
2
+ export { schema, INLINE_MARK_KEYS, PARAGRAPH_ATTR_KEYS, BOOLEAN_MARK_KEYS, paragraphType, markType } from "./schema.js";
3
+ export { EMPTY_ATTRS, ALL_ATTR_KEYS, isCodePointBoundary, snapDown, snapUp, sameAttrs, attrsEqual, formatChange, pmToFlat, pmToText, flatToPm, contentToPm, paragraphReadsAs, pmToContent, paragraphStarts, paragraphIndexAtOffset, paragraphIndexAtPos, pmPosToOffset, offsetToPmPos, diffToDelta, changedParagraphs, pmDiffToDelta, applyDeltaToFlat, } from "./flat.js";
4
+ export { CanvasEditorView, CARET_AFFINITY, VERTICAL_MOTION, buildLines, lineIndexIn, lineGeometry, caretRect, selectionRects } from "./CanvasEditorView.js";
5
+ export * from "./commands.js";
6
+ export { buildKeymap, handleKey, keyCodeOf, isMacPlatform, isWindowsPlatform, resolveTextPlatform } from "./keymap.js";
7
+ export { nextGraphemeEndFallback, prevGraphemeStartFallback } from "./graphemes.js";
8
+ export { TextEditSession, FROM_DOC, LABEL, BLINK_MS } from "./TextEditSession.js";
9
+ export { InputSink } from "./InputSink.js";
10
+ export { MIRROR_MAX_UNITS, MIRROR_GAP, mirrorWindow, toMirror, toFlat, selectionToFlat, diffText, compositionRange, domMirror } from "./contextMirror.js";
11
+ export { watchSessionFocus, caretWhileFocused } from "./sessionFocus.js";
12
+ export { interpretBeforeInput, normalizePasteText } from "./inputReducer.js";
13
+ export { serializeClipboard, parseClipboard, clipboardTransaction } from "./clipboard.js";
@@ -0,0 +1,24 @@
1
+ export type DeleteUnit = "char" | "word" | "line";
2
+ export type InputAction = {
3
+ kind: "insertText";
4
+ text: string;
5
+ } | {
6
+ kind: "splitBlock";
7
+ } | {
8
+ kind: "insertLineBreak";
9
+ } | {
10
+ kind: "deleteBackward";
11
+ unit: DeleteUnit;
12
+ } | {
13
+ kind: "deleteForward";
14
+ unit: DeleteUnit;
15
+ } | {
16
+ kind: "paste";
17
+ text: string;
18
+ } | {
19
+ kind: "undo";
20
+ } | {
21
+ kind: "redo";
22
+ };
23
+ export declare function interpretBeforeInput(inputType: string, data: string | null): InputAction | null;
24
+ export declare function normalizePasteText(s: string): string;
@@ -0,0 +1,44 @@
1
+ export function interpretBeforeInput(inputType, data) {
2
+ switch (inputType) {
3
+ case "insertText":
4
+ case "insertReplacementText":
5
+ return data ? { kind: "insertText", text: data } : null;
6
+ case "insertCompositionText":
7
+ return null;
8
+ case "insertParagraph":
9
+ return { kind: "splitBlock" };
10
+ case "insertLineBreak":
11
+ return { kind: "insertLineBreak" };
12
+ case "deleteContentBackward":
13
+ return { kind: "deleteBackward", unit: "char" };
14
+ case "deleteWordBackward":
15
+ return { kind: "deleteBackward", unit: "word" };
16
+ case "deleteSoftLineBackward":
17
+ case "deleteHardLineBackward":
18
+ return { kind: "deleteBackward", unit: "line" };
19
+ case "deleteContentForward":
20
+ return { kind: "deleteForward", unit: "char" };
21
+ case "deleteWordForward":
22
+ return { kind: "deleteForward", unit: "word" };
23
+ case "deleteSoftLineForward":
24
+ case "deleteHardLineForward":
25
+ return { kind: "deleteForward", unit: "line" };
26
+ case "deleteContent":
27
+ return { kind: "deleteBackward", unit: "char" };
28
+ case "insertFromPaste":
29
+ return data ? { kind: "paste", text: data } : null;
30
+ case "historyUndo":
31
+ return { kind: "undo" };
32
+ case "historyRedo":
33
+ return { kind: "redo" };
34
+ default:
35
+ return null;
36
+ }
37
+ }
38
+ export function normalizePasteText(s) {
39
+ let out = s.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDFFF]/g, (part) => (part.length === 2 ? part : "\uFFFD"))
40
+ .replace(/\r\n?|\u2029/g, "\n");
41
+ if (out.endsWith("\n"))
42
+ out = out.slice(0, -1);
43
+ return out.replace(/[^\P{Cc}\t\n]/gu, "");
44
+ }
@@ -0,0 +1,17 @@
1
+ import { type HeadlessCommand } from "./commands.js";
2
+ import type { HeadlessEditorView, KeyInfo } from "./types.js";
3
+ export type Keymap = Record<string, HeadlessCommand>;
4
+ export interface KeymapOptions {
5
+ mac?: boolean;
6
+ windows?: boolean;
7
+ }
8
+ export declare function isMacPlatform(): boolean;
9
+ export declare function isWindowsPlatform(): boolean;
10
+ export declare function resolveTextPlatform(options?: KeymapOptions): {
11
+ mac: boolean;
12
+ windows: boolean;
13
+ };
14
+ export declare function buildKeymap(options?: KeymapOptions): Keymap;
15
+ export declare function keyCodeOf(key: string): number;
16
+ export declare function keyCodeFromCode(code: string, key?: string): number;
17
+ export declare function handleKey(view: HeadlessEditorView, key: KeyInfo, bindings?: Keymap): boolean;
@@ -0,0 +1,148 @@
1
+ import { keydownHandler } from "prosemirror-keymap";
2
+ import { backspace, del, docEnd, docStart, enter, indentListItem, insertHardBreak, lineBackspace, lineEnd, lineStart, moveChar, moveVertically, moveWord, selectAll, toggleBold, toggleMark, windowsWordDelete, wordBackspace, wordDelete } from "./commands.js";
3
+ function hostPlatform() {
4
+ if (typeof navigator === "undefined")
5
+ return "";
6
+ const nav = navigator;
7
+ return nav.userAgentData?.platform ?? nav.platform ?? "";
8
+ }
9
+ const APPLE_PLATFORM = /mac|iphone|ipad|ipod|\bios\b/i;
10
+ export function isMacPlatform() {
11
+ return APPLE_PLATFORM.test(hostPlatform());
12
+ }
13
+ export function isWindowsPlatform() {
14
+ return /Win/.test(hostPlatform());
15
+ }
16
+ export function resolveTextPlatform(options = {}) {
17
+ const mac = options.mac ?? (options.windows === true ? false : isMacPlatform());
18
+ return { mac, windows: !mac && (options.windows ?? isWindowsPlatform()) };
19
+ }
20
+ export function buildKeymap(options = {}) {
21
+ const { mac, windows } = resolveTextPlatform(options);
22
+ const map = {
23
+ ArrowLeft: moveChar("left", false),
24
+ "Shift-ArrowLeft": moveChar("left", true),
25
+ ArrowRight: moveChar("right", false),
26
+ "Shift-ArrowRight": moveChar("right", true),
27
+ ArrowUp: moveVertically("up", false),
28
+ "Shift-ArrowUp": moveVertically("up", true),
29
+ ArrowDown: moveVertically("down", false),
30
+ "Shift-ArrowDown": moveVertically("down", true),
31
+ Home: lineStart(false),
32
+ "Shift-Home": lineStart(true),
33
+ End: lineEnd(false),
34
+ "Shift-End": lineEnd(true),
35
+ "Mod-Home": docStart(false),
36
+ "Mod-Shift-Home": docStart(true),
37
+ "Mod-End": docEnd(false),
38
+ "Mod-Shift-End": docEnd(true),
39
+ Backspace: backspace,
40
+ Delete: del,
41
+ Enter: enter,
42
+ "Shift-Enter": insertHardBreak,
43
+ "Mod-a": selectAll,
44
+ "Mod-b": toggleBold,
45
+ "Mod-i": toggleMark("italic"),
46
+ "Mod-u": toggleMark("underline"),
47
+ "Mod-Shift-x": toggleMark("strike"),
48
+ Tab: indentListItem(1),
49
+ "Shift-Tab": indentListItem(-1),
50
+ };
51
+ if (mac) {
52
+ Object.assign(map, {
53
+ "Alt-ArrowLeft": moveWord("left", false),
54
+ "Alt-Shift-ArrowLeft": moveWord("left", true),
55
+ "Alt-ArrowRight": moveWord("right", false),
56
+ "Alt-Shift-ArrowRight": moveWord("right", true),
57
+ "Alt-Backspace": wordBackspace,
58
+ "Alt-Delete": wordDelete,
59
+ "Meta-ArrowLeft": lineStart(false),
60
+ "Meta-Shift-ArrowLeft": lineStart(true),
61
+ "Meta-ArrowRight": lineEnd(false),
62
+ "Meta-Shift-ArrowRight": lineEnd(true),
63
+ "Meta-ArrowUp": docStart(false),
64
+ "Meta-Shift-ArrowUp": docStart(true),
65
+ "Meta-ArrowDown": docEnd(false),
66
+ "Meta-Shift-ArrowDown": docEnd(true),
67
+ "Meta-Backspace": lineBackspace,
68
+ "Ctrl-a": lineStart(false),
69
+ "Ctrl-e": lineEnd(false),
70
+ });
71
+ }
72
+ else {
73
+ Object.assign(map, {
74
+ "Ctrl-ArrowLeft": moveWord("left", false),
75
+ "Ctrl-Shift-ArrowLeft": moveWord("left", true),
76
+ "Ctrl-ArrowRight": moveWord("right", false, windows),
77
+ "Ctrl-Shift-ArrowRight": moveWord("right", true, windows),
78
+ "Ctrl-Backspace": wordBackspace,
79
+ "Ctrl-Delete": windows ? windowsWordDelete : wordDelete,
80
+ });
81
+ }
82
+ return expandMod(map, mac);
83
+ }
84
+ function expandMod(bindings, mac) {
85
+ const out = {};
86
+ for (const name in bindings) {
87
+ const parts = name.split(/-(?!$)/);
88
+ const modIndex = parts.findIndex((p, i) => i < parts.length - 1 && /^mod$/i.test(p));
89
+ if (modIndex >= 0)
90
+ parts[modIndex] = mac ? "Meta" : "Ctrl";
91
+ out[parts.join("-")] = bindings[name];
92
+ }
93
+ return out;
94
+ }
95
+ const NAMED_KEY_CODES = {
96
+ Backspace: 8,
97
+ Tab: 9,
98
+ Enter: 13,
99
+ Escape: 27,
100
+ " ": 32,
101
+ End: 35,
102
+ Home: 36,
103
+ ArrowLeft: 37,
104
+ ArrowUp: 38,
105
+ ArrowRight: 39,
106
+ ArrowDown: 40,
107
+ Delete: 46,
108
+ };
109
+ export function keyCodeOf(key) {
110
+ const named = NAMED_KEY_CODES[key];
111
+ if (named !== undefined)
112
+ return named;
113
+ if (key.length === 1) {
114
+ const c = key.toUpperCase().charCodeAt(0);
115
+ if ((c >= 65 && c <= 90) || (c >= 48 && c <= 57))
116
+ return c;
117
+ }
118
+ return 0;
119
+ }
120
+ const isPrintableAscii = (key) => /^[\x20-\x7e]$/.test(key);
121
+ export function keyCodeFromCode(code, key) {
122
+ if (key !== undefined && isPrintableAscii(key))
123
+ return 0;
124
+ const m = /^Key([A-Z])$/.exec(code);
125
+ if (m)
126
+ return m[1].charCodeAt(0);
127
+ const d = /^Digit([0-9])$/.exec(code);
128
+ if (d)
129
+ return 48 + Number(d[1]);
130
+ return 0;
131
+ }
132
+ const handlers = new WeakMap();
133
+ function handlerFor(bindings) {
134
+ let h = handlers.get(bindings);
135
+ if (!h) {
136
+ const run = keydownHandler(bindings);
137
+ h = (view, key) => {
138
+ const event = { key: key.key, code: key.code, keyCode: keyCodeOf(key.key) || keyCodeFromCode(key.code, key.key), shiftKey: key.shiftKey, ctrlKey: key.ctrlKey, altKey: key.altKey, metaKey: key.metaKey };
139
+ return run(view, event);
140
+ };
141
+ handlers.set(bindings, h);
142
+ }
143
+ return h;
144
+ }
145
+ let defaultBindings;
146
+ export function handleKey(view, key, bindings = (defaultBindings ??= buildKeymap())) {
147
+ return handlerFor(bindings)(view, key);
148
+ }
@@ -0,0 +1,12 @@
1
+ import { Schema, type MarkType, type NodeType } from "prosemirror-model";
2
+ export type ParagraphAlign = "left" | "center" | "right" | "justify";
3
+ export type ParagraphList = "bullet" | "number" | "task";
4
+ export declare const schema: Schema<"text" | "doc" | "paragraph" | "hard_break", "color" | "weight" | "italic" | "underline" | "strike" | "size" | "family" | "letterSpacing" | "textCase" | "link">;
5
+ export declare const INLINE_MARK_KEYS: readonly ["weight", "italic", "underline", "strike", "color", "size", "family", "letterSpacing", "textCase", "link"];
6
+ export declare const PARAGRAPH_ATTR_KEYS: readonly ["align", "lineHeight", "list", "indent", "start", "checked"];
7
+ export type InlineMarkKey = (typeof INLINE_MARK_KEYS)[number];
8
+ export type ParagraphAttrKey = (typeof PARAGRAPH_ATTR_KEYS)[number];
9
+ export declare const BOOLEAN_MARK_KEYS: readonly ["italic", "underline", "strike"];
10
+ export type BooleanMarkKey = (typeof BOOLEAN_MARK_KEYS)[number];
11
+ export declare const paragraphType: NodeType;
12
+ export declare function markType(key: InlineMarkKey): MarkType;
@@ -0,0 +1,44 @@
1
+ import { Schema } from "prosemirror-model";
2
+ import { HARD_LINE_BREAK } from "@daasboard/doc";
3
+ export const schema = new Schema({
4
+ nodes: {
5
+ doc: { content: "paragraph+" },
6
+ paragraph: {
7
+ content: "(text | hard_break)*",
8
+ attrs: {
9
+ align: { default: null },
10
+ lineHeight: { default: null },
11
+ list: { default: null },
12
+ indent: { default: 0 },
13
+ start: { default: null },
14
+ checked: { default: null },
15
+ },
16
+ },
17
+ text: { inline: true },
18
+ hard_break: {
19
+ inline: true,
20
+ selectable: false,
21
+ linebreakReplacement: true,
22
+ leafText: () => HARD_LINE_BREAK,
23
+ },
24
+ },
25
+ marks: {
26
+ weight: { attrs: { value: {} } },
27
+ italic: { attrs: { value: { default: true } } },
28
+ underline: { attrs: { value: { default: true } } },
29
+ strike: { attrs: { value: { default: true } } },
30
+ link: { attrs: { href: {} }, inclusive: false },
31
+ color: { attrs: { value: {} } },
32
+ size: { attrs: { value: {} } },
33
+ family: { attrs: { value: {} } },
34
+ letterSpacing: { attrs: { value: {} } },
35
+ textCase: { attrs: { value: {} } },
36
+ },
37
+ });
38
+ export const INLINE_MARK_KEYS = ["weight", "italic", "underline", "strike", "color", "size", "family", "letterSpacing", "textCase", "link"];
39
+ export const PARAGRAPH_ATTR_KEYS = ["align", "lineHeight", "list", "indent", "start", "checked"];
40
+ export const BOOLEAN_MARK_KEYS = ["italic", "underline", "strike"];
41
+ export const paragraphType = schema.nodes.paragraph;
42
+ export function markType(key) {
43
+ return schema.marks[key];
44
+ }
@@ -0,0 +1,20 @@
1
+ import type { TextEditSession } from "./TextEditSession.js";
2
+ import type { TextSessionView } from "./types.js";
3
+ export interface SessionFocusEvent {
4
+ readonly target: EventTarget | null;
5
+ readonly relatedTarget?: EventTarget | null;
6
+ }
7
+ export interface SessionFocusSource {
8
+ addEventListener(type: string, listener: (e: SessionFocusEvent) => void): void;
9
+ removeEventListener(type: string, listener: (e: SessionFocusEvent) => void): void;
10
+ }
11
+ export interface SessionFocusOptions {
12
+ container: SessionFocusSource;
13
+ session: () => Pick<TextEditSession, "focus" | "blur"> | null;
14
+ sink: () => unknown;
15
+ owns: (target: EventTarget | null) => boolean;
16
+ activeElement?: () => EventTarget | null;
17
+ onChange?: () => void;
18
+ }
19
+ export declare function watchSessionFocus(o: SessionFocusOptions): () => void;
20
+ export declare function caretWhileFocused(view: TextSessionView, focused: () => boolean): TextSessionView;
@@ -0,0 +1,51 @@
1
+ export function watchSessionFocus(o) {
2
+ const active = o.activeElement ?? (() => (typeof document === "undefined" ? null : document.activeElement));
3
+ const isSink = (t) => !!t && t === o.sink();
4
+ const onFocusIn = (e) => {
5
+ const session = o.session();
6
+ if (!session || !isSink(e.target))
7
+ return;
8
+ session.focus();
9
+ o.onChange?.();
10
+ };
11
+ const onFocusOut = (e) => {
12
+ const session = o.session();
13
+ if (!session)
14
+ return;
15
+ if (isSink(e.target))
16
+ return void o.onChange?.();
17
+ if (!o.owns(e.target))
18
+ return;
19
+ const to = e.relatedTarget ?? null;
20
+ if (isSink(to) || o.owns(to))
21
+ return;
22
+ if (!to && o.owns(active()))
23
+ return;
24
+ session.blur();
25
+ };
26
+ o.container.addEventListener("focusin", onFocusIn);
27
+ o.container.addEventListener("focusout", onFocusOut);
28
+ return () => {
29
+ o.container.removeEventListener("focusin", onFocusIn);
30
+ o.container.removeEventListener("focusout", onFocusOut);
31
+ };
32
+ }
33
+ export function caretWhileFocused(view, focused) {
34
+ const caretVisible = (now) => focused() && view.caretVisible(now);
35
+ const bound = new WeakMap();
36
+ const blank = Object.create(Object.getPrototypeOf(view));
37
+ return new Proxy(blank, {
38
+ get(_, key) {
39
+ if (key === "caretVisible")
40
+ return caretVisible;
41
+ const value = Reflect.get(view, key, view);
42
+ if (typeof value !== "function")
43
+ return value;
44
+ let method = bound.get(value);
45
+ if (!method)
46
+ bound.set(value, (method = value.bind(view)));
47
+ return method;
48
+ },
49
+ has: (_, key) => key in view,
50
+ });
51
+ }