editable.ts 0.0.1
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 +21 -0
- package/README.md +571 -0
- package/dist/editable.umd.cjs +2 -0
- package/dist/editable.umd.cjs.map +1 -0
- package/lib/block.d.ts +13 -0
- package/lib/block.d.ts.map +1 -0
- package/lib/block.js +58 -0
- package/lib/block.js.map +1 -0
- package/lib/clipboard.d.ts +22 -0
- package/lib/clipboard.d.ts.map +1 -0
- package/lib/clipboard.js +154 -0
- package/lib/clipboard.js.map +1 -0
- package/lib/config.d.ts +37 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +64 -0
- package/lib/config.js.map +1 -0
- package/lib/content.d.ts +37 -0
- package/lib/content.d.ts.map +1 -0
- package/lib/content.js +526 -0
- package/lib/content.js.map +1 -0
- package/lib/core.d.ts +97 -0
- package/lib/core.d.ts.map +1 -0
- package/lib/core.js +261 -0
- package/lib/core.js.map +1 -0
- package/lib/create-default-behavior.d.ts +31 -0
- package/lib/create-default-behavior.d.ts.map +1 -0
- package/lib/create-default-behavior.js +178 -0
- package/lib/create-default-behavior.js.map +1 -0
- package/lib/create-default-events.d.ts +152 -0
- package/lib/create-default-events.d.ts.map +1 -0
- package/lib/create-default-events.js +183 -0
- package/lib/create-default-events.js.map +1 -0
- package/lib/cursor.d.ts +68 -0
- package/lib/cursor.d.ts.map +1 -0
- package/lib/cursor.js +354 -0
- package/lib/cursor.js.map +1 -0
- package/lib/dispatcher.d.ts +78 -0
- package/lib/dispatcher.d.ts.map +1 -0
- package/lib/dispatcher.js +416 -0
- package/lib/dispatcher.js.map +1 -0
- package/lib/eventable.d.ts +2 -0
- package/lib/eventable.d.ts.map +1 -0
- package/lib/eventable.js +104 -0
- package/lib/eventable.js.map +1 -0
- package/lib/feature-detection.d.ts +12 -0
- package/lib/feature-detection.d.ts.map +1 -0
- package/lib/feature-detection.js +42 -0
- package/lib/feature-detection.js.map +1 -0
- package/lib/highlight-support.d.ts +24 -0
- package/lib/highlight-support.d.ts.map +1 -0
- package/lib/highlight-support.js +172 -0
- package/lib/highlight-support.js.map +1 -0
- package/lib/highlight-text.d.ts +21 -0
- package/lib/highlight-text.d.ts.map +1 -0
- package/lib/highlight-text.js +147 -0
- package/lib/highlight-text.js.map +1 -0
- package/lib/keyboard.d.ts +33 -0
- package/lib/keyboard.d.ts.map +1 -0
- package/lib/keyboard.js +189 -0
- package/lib/keyboard.js.map +1 -0
- package/lib/monitored-highlighting.d.ts +28 -0
- package/lib/monitored-highlighting.d.ts.map +1 -0
- package/lib/monitored-highlighting.js +194 -0
- package/lib/monitored-highlighting.js.map +1 -0
- package/lib/node-iterator.d.ts +16 -0
- package/lib/node-iterator.d.ts.map +1 -0
- package/lib/node-iterator.js +97 -0
- package/lib/node-iterator.js.map +1 -0
- package/lib/node-type.d.ts +13 -0
- package/lib/node-type.d.ts.map +1 -0
- package/lib/node-type.js +15 -0
- package/lib/node-type.js.map +1 -0
- package/lib/parser.d.ts +89 -0
- package/lib/parser.d.ts.map +1 -0
- package/lib/parser.js +251 -0
- package/lib/parser.js.map +1 -0
- package/lib/plugins/highlighting/match-collection.d.ts +7 -0
- package/lib/plugins/highlighting/match-collection.d.ts.map +1 -0
- package/lib/plugins/highlighting/match-collection.js +62 -0
- package/lib/plugins/highlighting/match-collection.js.map +1 -0
- package/lib/plugins/highlighting/spellcheck-service.d.ts +12 -0
- package/lib/plugins/highlighting/spellcheck-service.d.ts.map +1 -0
- package/lib/plugins/highlighting/spellcheck-service.js +24 -0
- package/lib/plugins/highlighting/spellcheck-service.js.map +1 -0
- package/lib/plugins/highlighting/text-search.d.ts +10 -0
- package/lib/plugins/highlighting/text-search.d.ts.map +1 -0
- package/lib/plugins/highlighting/text-search.js +92 -0
- package/lib/plugins/highlighting/text-search.js.map +1 -0
- package/lib/plugins/highlighting/whitespace-highlighting.d.ts +14 -0
- package/lib/plugins/highlighting/whitespace-highlighting.d.ts.map +1 -0
- package/lib/plugins/highlighting/whitespace-highlighting.js +52 -0
- package/lib/plugins/highlighting/whitespace-highlighting.js.map +1 -0
- package/lib/quotes.d.ts +8 -0
- package/lib/quotes.d.ts.map +1 -0
- package/lib/quotes.js +170 -0
- package/lib/quotes.js.map +1 -0
- package/lib/range-container.d.ts +22 -0
- package/lib/range-container.d.ts.map +1 -0
- package/lib/range-container.js +52 -0
- package/lib/range-container.js.map +1 -0
- package/lib/range-save-restore.d.ts +13 -0
- package/lib/range-save-restore.d.ts.map +1 -0
- package/lib/range-save-restore.js +153 -0
- package/lib/range-save-restore.js.map +1 -0
- package/lib/selection-watcher.d.ts +55 -0
- package/lib/selection-watcher.d.ts.map +1 -0
- package/lib/selection-watcher.js +126 -0
- package/lib/selection-watcher.js.map +1 -0
- package/lib/selection.d.ts +74 -0
- package/lib/selection.d.ts.map +1 -0
- package/lib/selection.js +341 -0
- package/lib/selection.js.map +1 -0
- package/lib/smartQuotes.d.ts +16 -0
- package/lib/smartQuotes.d.ts.map +1 -0
- package/lib/smartQuotes.js +92 -0
- package/lib/smartQuotes.js.map +1 -0
- package/lib/util/binary_search.d.ts +23 -0
- package/lib/util/binary_search.d.ts.map +1 -0
- package/lib/util/binary_search.js +137 -0
- package/lib/util/binary_search.js.map +1 -0
- package/lib/util/clone-deep.d.ts +8 -0
- package/lib/util/clone-deep.d.ts.map +1 -0
- package/lib/util/clone-deep.js +10 -0
- package/lib/util/clone-deep.js.map +1 -0
- package/lib/util/dom.d.ts +43 -0
- package/lib/util/dom.d.ts.map +1 -0
- package/lib/util/dom.js +272 -0
- package/lib/util/dom.js.map +1 -0
- package/lib/util/element.d.ts +10 -0
- package/lib/util/element.d.ts.map +1 -0
- package/lib/util/element.js +29 -0
- package/lib/util/element.js.map +1 -0
- package/lib/util/error.d.ts +2 -0
- package/lib/util/error.d.ts.map +1 -0
- package/lib/util/error.js +16 -0
- package/lib/util/error.js.map +1 -0
- package/lib/util/log.d.ts +2 -0
- package/lib/util/log.d.ts.map +1 -0
- package/lib/util/log.js +18 -0
- package/lib/util/log.js.map +1 -0
- package/lib/util/merge.d.ts +6 -0
- package/lib/util/merge.d.ts.map +1 -0
- package/lib/util/merge.js +31 -0
- package/lib/util/merge.js.map +1 -0
- package/lib/util/string.d.ts +25 -0
- package/lib/util/string.d.ts.map +1 -0
- package/lib/util/string.js +68 -0
- package/lib/util/string.js.map +1 -0
- package/lib/util/viewport.d.ts +6 -0
- package/lib/util/viewport.d.ts.map +1 -0
- package/lib/util/viewport.js +8 -0
- package/lib/util/viewport.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// See: https://en.wikipedia.org/wiki/Whitespace_character
|
|
2
|
+
const characters = {
|
|
3
|
+
'A0': 'no-break space', // \\u00A0
|
|
4
|
+
'2000': 'en quad', // \\u2000
|
|
5
|
+
'2001': 'em quad', // \\u2001
|
|
6
|
+
'2002': 'en space', // \\u2002
|
|
7
|
+
'2003': 'em space', // \\u2003
|
|
8
|
+
'2004': 'three-per-em space', // \\u2004
|
|
9
|
+
'2005': 'four-per-em space', // \\u2005
|
|
10
|
+
'2006': 'six-per-em space', // \\u2006
|
|
11
|
+
'2007': 'figure space', // \\u2007
|
|
12
|
+
'2008': 'punctuation space', // \\u2008
|
|
13
|
+
'2009': 'thin space', // \\u2009
|
|
14
|
+
'200A': 'hair space', // \\u200A
|
|
15
|
+
'202F': 'narrow no-break space', // \\u202F
|
|
16
|
+
'205F': 'medium mathematical space', // \\u205F
|
|
17
|
+
'3000': 'ideographic space' // \\u3000
|
|
18
|
+
};
|
|
19
|
+
// The no-break space is not highlighted as this can cause problems.
|
|
20
|
+
// Browser can insert no-break spaces when typing at the end of
|
|
21
|
+
// a paragraph and the highlighting prevents browsers from converting
|
|
22
|
+
// the no-break space back to a normal space when the user keeps typing.
|
|
23
|
+
const specialWhitespaceChars = '\\u2000-\\u200A\\u202F\\u205F\\u3000';
|
|
24
|
+
const specialWhitespaceCharsRegex = new RegExp(`[${specialWhitespaceChars}]`, 'g');
|
|
25
|
+
export default class WhitespaceHighlighting {
|
|
26
|
+
constructor(markerNode) {
|
|
27
|
+
this.marker = markerNode;
|
|
28
|
+
}
|
|
29
|
+
findMatches(text) {
|
|
30
|
+
if (!text)
|
|
31
|
+
return;
|
|
32
|
+
const matches = [...text.matchAll(specialWhitespaceCharsRegex)];
|
|
33
|
+
return matches.map((entry) => this.prepareMatch(entry));
|
|
34
|
+
}
|
|
35
|
+
prepareMatch(match) {
|
|
36
|
+
const startIndex = match.index;
|
|
37
|
+
const unicode = getUnicode(match[0]);
|
|
38
|
+
const description = characters[unicode] || 'unknown whitespace';
|
|
39
|
+
return {
|
|
40
|
+
startIndex,
|
|
41
|
+
endIndex: startIndex + match.length,
|
|
42
|
+
match: match[0],
|
|
43
|
+
title: `${description} (\\u${unicode})`,
|
|
44
|
+
marker: this.marker
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function getUnicode(character) {
|
|
49
|
+
const code = character.charCodeAt(0);
|
|
50
|
+
return `${code.toString(16).toUpperCase()}`;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=whitespace-highlighting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whitespace-highlighting.js","sourceRoot":"","sources":["../../../src/plugins/highlighting/whitespace-highlighting.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAE1D,MAAM,UAAU,GAAG;IACjB,IAAI,EAAE,gBAAgB,EAAE,UAAU;IAClC,MAAM,EAAE,SAAS,EAAE,UAAU;IAC7B,MAAM,EAAE,SAAS,EAAE,UAAU;IAC7B,MAAM,EAAE,UAAU,EAAE,UAAU;IAC9B,MAAM,EAAE,UAAU,EAAE,UAAU;IAC9B,MAAM,EAAE,oBAAoB,EAAE,UAAU;IACxC,MAAM,EAAE,mBAAmB,EAAE,UAAU;IACvC,MAAM,EAAE,kBAAkB,EAAE,UAAU;IACtC,MAAM,EAAE,cAAc,EAAE,UAAU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M;SACpB,CAAA;IACH,CAAC;CACF;AAED,SAAS,UAAU,CAAE,SAAiB;IACpC,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;IACpC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAA;AAC7C,CAAC"}
|
package/lib/quotes.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotes.d.ts","sourceRoot":"","sources":["../src/quotes.ts"],"names":[],"mappings":"AAuCA,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAID,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,YAAY,GAAG,MAAM,CAYxF"}
|
package/lib/quotes.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
const doubleQuotePairs = [
|
|
2
|
+
['«', '»'], // ch german, french
|
|
3
|
+
['»', '«'], // danish
|
|
4
|
+
['"', '"'], // danish, not specified
|
|
5
|
+
['“', '”'], // english US
|
|
6
|
+
['”', '”'], // swedish
|
|
7
|
+
['“', '“'], // chinese simplified
|
|
8
|
+
['„', '“'] // german
|
|
9
|
+
];
|
|
10
|
+
const singleQuotePairs = [
|
|
11
|
+
['‘', '’'], // english UK
|
|
12
|
+
['‹', '›'], // ch german, french
|
|
13
|
+
['‚', '‘'], // german
|
|
14
|
+
['’', '’'], // swedish
|
|
15
|
+
['›', '‹'], // danish
|
|
16
|
+
[`'`, `'`], // danish, not specified
|
|
17
|
+
[`‘`, `’`] // chinese simplified
|
|
18
|
+
];
|
|
19
|
+
const apostrophe = [
|
|
20
|
+
'’', // german
|
|
21
|
+
`'` // default
|
|
22
|
+
];
|
|
23
|
+
const quotesRegex = /([‘’‹›‚'«»"“”„])(?![^<]*?>)/g;
|
|
24
|
+
// whitespace end of tag, or any dash (normal, en or em-dash)
|
|
25
|
+
// or any opening double quote
|
|
26
|
+
const beforeOpeningQuote = /\s|[>\-–—«»”"“„]/;
|
|
27
|
+
// whitespace begin of tag, or any dash (normal, en or em-dash)
|
|
28
|
+
// or any closing quote, or any punctuation
|
|
29
|
+
const afterClosingQuote = /\s|[<\-–—«»”"“‘’‹›'.;?:,]/;
|
|
30
|
+
let replacements;
|
|
31
|
+
export function replaceAllQuotes(str, replaceQuotesRules) {
|
|
32
|
+
replacements = replaceQuotesRules || {};
|
|
33
|
+
replacements.quotes = replacements.quotes || [undefined, undefined];
|
|
34
|
+
replacements.singleQuotes = replacements.singleQuotes || [undefined, undefined];
|
|
35
|
+
const matches = getAllQuotes(str);
|
|
36
|
+
if (matches.length > 0) {
|
|
37
|
+
replaceMatchedQuotes(matches, 0);
|
|
38
|
+
return replaceExistingQuotes(str, matches);
|
|
39
|
+
}
|
|
40
|
+
return str;
|
|
41
|
+
}
|
|
42
|
+
function replaceMatchedQuotes(matches, position) {
|
|
43
|
+
while (position < matches.length) {
|
|
44
|
+
const closingTag = findClosingQuote(matches, position);
|
|
45
|
+
if (closingTag) {
|
|
46
|
+
matches[position].replace = closingTag.type === 'double'
|
|
47
|
+
? replacements.quotes?.[0]
|
|
48
|
+
: replacements.singleQuotes?.[0];
|
|
49
|
+
matches[closingTag.position].replace = closingTag.type === 'double'
|
|
50
|
+
? replacements.quotes?.[1]
|
|
51
|
+
: replacements.singleQuotes?.[1];
|
|
52
|
+
if (closingTag.position !== position + 1) {
|
|
53
|
+
const nestedMatches = matches.slice(position + 1, closingTag.position);
|
|
54
|
+
if (nestedMatches && nestedMatches.length > 0) {
|
|
55
|
+
replaceMatchedQuotes(nestedMatches, 0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
position = closingTag.position + 1;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
matches[position].replace = replaceApostrophe(matches[position].char);
|
|
62
|
+
position += 1;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function findClosingQuote(matches, position) {
|
|
67
|
+
if (position === matches.length - 1)
|
|
68
|
+
return undefined;
|
|
69
|
+
const current = matches[position];
|
|
70
|
+
const openingQuote = current.char;
|
|
71
|
+
if (current.before && !beforeOpeningQuote.test(current.before))
|
|
72
|
+
return undefined;
|
|
73
|
+
const possibleClosingSingleQuotes = getPossibleClosingQuotes(openingQuote, singleQuotePairs);
|
|
74
|
+
const possibleClosingDoubleQuotes = getPossibleClosingQuotes(openingQuote, doubleQuotePairs);
|
|
75
|
+
// Also allow straight quotes as potential closers when we have quote pairs (they can be converted)
|
|
76
|
+
// But only for the same quote type (straight double quote for double quotes, straight single quote for single quotes)
|
|
77
|
+
let allPossibleDoubleClosers = possibleClosingDoubleQuotes;
|
|
78
|
+
let allPossibleSingleClosers = possibleClosingSingleQuotes;
|
|
79
|
+
const hasStraightQuoteFallback = (possibleClosingDoubleQuotes.length > 0 && !possibleClosingDoubleQuotes.includes('"')) ||
|
|
80
|
+
(possibleClosingSingleQuotes.length > 0 && !possibleClosingSingleQuotes.includes("'"));
|
|
81
|
+
// Only add straight double quote if this is a double quote type (has double quote pairs defined)
|
|
82
|
+
if (possibleClosingDoubleQuotes.length > 0 && !possibleClosingDoubleQuotes.includes('"')) {
|
|
83
|
+
allPossibleDoubleClosers = [...possibleClosingDoubleQuotes, '"'];
|
|
84
|
+
}
|
|
85
|
+
// Only add straight single quote if this is a single quote type (has single quote pairs defined)
|
|
86
|
+
if (possibleClosingSingleQuotes.length > 0 && !possibleClosingSingleQuotes.includes("'")) {
|
|
87
|
+
allPossibleSingleClosers = [...possibleClosingSingleQuotes, "'"];
|
|
88
|
+
}
|
|
89
|
+
// Check if opening quote is itself a straight quote - if so, prefer outermost match
|
|
90
|
+
const isStraightQuote = openingQuote === '"' || openingQuote === "'";
|
|
91
|
+
// Prefer exact pair matches over straight quote fallbacks
|
|
92
|
+
// For straight quote fallbacks or straight quotes themselves, prefer outermost match to avoid incorrect nested matching
|
|
93
|
+
let bestStraightQuoteMatch;
|
|
94
|
+
for (let i = position + 1; i < matches.length; i++) {
|
|
95
|
+
const candidateChar = matches[i].char;
|
|
96
|
+
const candidateAfter = matches[i].after;
|
|
97
|
+
const passesAfterCheck = (candidateAfter && afterClosingQuote.test(candidateAfter)) || !candidateAfter;
|
|
98
|
+
if (passesAfterCheck) {
|
|
99
|
+
if (allPossibleSingleClosers.includes(candidateChar)) {
|
|
100
|
+
// Check if this is an exact pair match (not a straight quote fallback)
|
|
101
|
+
const isExactMatch = possibleClosingSingleQuotes.includes(candidateChar);
|
|
102
|
+
// For straight quotes themselves, always prefer outermost match
|
|
103
|
+
if (isExactMatch && !isStraightQuote) {
|
|
104
|
+
// Return immediately for exact pair matches (except for straight quotes)
|
|
105
|
+
return { position: i, type: 'single' };
|
|
106
|
+
}
|
|
107
|
+
// For straight quote fallbacks or straight quotes themselves, continue searching for the outermost match
|
|
108
|
+
if (hasStraightQuoteFallback || isStraightQuote) {
|
|
109
|
+
if (!bestStraightQuoteMatch || (bestStraightQuoteMatch.type === 'single' && i > bestStraightQuoteMatch.position)) {
|
|
110
|
+
bestStraightQuoteMatch = { position: i, type: 'single' };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return { position: i, type: 'single' };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (allPossibleDoubleClosers.includes(candidateChar)) {
|
|
118
|
+
// Check if this is an exact pair match (not a straight quote fallback)
|
|
119
|
+
const isExactMatch = possibleClosingDoubleQuotes.includes(candidateChar);
|
|
120
|
+
// For straight quotes themselves, always prefer outermost match
|
|
121
|
+
if (isExactMatch && !isStraightQuote) {
|
|
122
|
+
// Return immediately for exact pair matches (except for straight quotes)
|
|
123
|
+
return { position: i, type: 'double' };
|
|
124
|
+
}
|
|
125
|
+
// For straight quote fallbacks or straight quotes themselves, continue searching for the outermost match
|
|
126
|
+
if (hasStraightQuoteFallback || isStraightQuote) {
|
|
127
|
+
if (!bestStraightQuoteMatch || (bestStraightQuoteMatch.type === 'double' && i > bestStraightQuoteMatch.position)) {
|
|
128
|
+
bestStraightQuoteMatch = { position: i, type: 'double' };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return { position: i, type: 'double' };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Return the outermost straight quote match if we found one
|
|
138
|
+
if (bestStraightQuoteMatch) {
|
|
139
|
+
return bestStraightQuoteMatch;
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
function getPossibleClosingQuotes(openingQuote, pairs) {
|
|
144
|
+
return pairs.filter((quotePair) => quotePair[0] === openingQuote).map((quotePair) => quotePair[1]);
|
|
145
|
+
}
|
|
146
|
+
function replaceApostrophe(quote) {
|
|
147
|
+
if (apostrophe.includes(quote)) {
|
|
148
|
+
return replacements.apostrophe;
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
function getAllQuotes(str) {
|
|
153
|
+
return [...str.matchAll(quotesRegex)].map((match) => {
|
|
154
|
+
const index = match.index;
|
|
155
|
+
return {
|
|
156
|
+
char: match[1],
|
|
157
|
+
before: index > 0 ? str[index - 1] : '',
|
|
158
|
+
after: (index + 1) < str.length ? str[index + 1] : ''
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function replaceExistingQuotes(str, matches) {
|
|
163
|
+
let index = 0;
|
|
164
|
+
return str.replace(quotesRegex, (match) => {
|
|
165
|
+
const replacement = matches[index].replace || matches[index].char;
|
|
166
|
+
index += 1;
|
|
167
|
+
return replacement;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=quotes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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M,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAA;QACjE,KAAK,IAAI,CAAC,CAAA;QACV,OAAO,WAAW,CAAA;IACpB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Cursor from './cursor.js';
|
|
2
|
+
import Selection from './selection.js';
|
|
3
|
+
/** RangeContainer
|
|
4
|
+
*
|
|
5
|
+
* primarily used to compare ranges
|
|
6
|
+
* its designed to work with undefined ranges as well
|
|
7
|
+
* so we can easily compare them without checking for undefined
|
|
8
|
+
* all the time
|
|
9
|
+
*/
|
|
10
|
+
export default class RangeContainer {
|
|
11
|
+
host: HTMLElement | undefined;
|
|
12
|
+
range: Range | undefined;
|
|
13
|
+
isAnythingSelected: boolean;
|
|
14
|
+
isCursor: boolean;
|
|
15
|
+
isSelection: boolean;
|
|
16
|
+
constructor(editableHost?: HTMLElement | any, range?: Range);
|
|
17
|
+
getCursor(): Cursor | undefined;
|
|
18
|
+
getSelection(): Selection | undefined;
|
|
19
|
+
forceCursor(): Cursor | undefined;
|
|
20
|
+
isDifferentFrom(otherRangeContainer?: RangeContainer): boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=range-container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range-container.d.ts","sourceRoot":"","sources":["../src/range-container.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAGtC;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,cAAc;IAC1B,IAAI,EAAE,WAAW,GAAG,SAAS,CAAA;IAC7B,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;IACxB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,QAAQ,EAAE,OAAO,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;gBAEd,YAAY,CAAC,EAAE,WAAW,GAAG,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK;IAa5D,SAAS,IAAK,MAAM,GAAG,SAAS;IAKhC,YAAY,IAAK,SAAS,GAAG,SAAS;IAKtC,WAAW,IAAK,MAAM,GAAG,SAAS;IAOlC,eAAe,CAAE,mBAAmB,GAAE,cAAqC,GAAG,OAAO;CAOtF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Cursor from './cursor.js';
|
|
2
|
+
import Selection from './selection.js';
|
|
3
|
+
import { rangesAreEqual } from './util/dom.js';
|
|
4
|
+
/** RangeContainer
|
|
5
|
+
*
|
|
6
|
+
* primarily used to compare ranges
|
|
7
|
+
* its designed to work with undefined ranges as well
|
|
8
|
+
* so we can easily compare them without checking for undefined
|
|
9
|
+
* all the time
|
|
10
|
+
*/
|
|
11
|
+
export default class RangeContainer {
|
|
12
|
+
constructor(editableHost, range) {
|
|
13
|
+
this.host = editableHost && editableHost.jquery
|
|
14
|
+
? editableHost[0]
|
|
15
|
+
: editableHost;
|
|
16
|
+
// Safari 17 seems to modify the range instance on the fly which breaks later comparisons.
|
|
17
|
+
// We clone the range at the time of the RangeContainer creation.
|
|
18
|
+
// https://developer.apple.com/documentation/safari-release-notes/safari-17-release-notes#New-Features
|
|
19
|
+
this.range = range?.cloneRange();
|
|
20
|
+
this.isAnythingSelected = (range !== undefined);
|
|
21
|
+
this.isCursor = (this.isAnythingSelected && range.collapsed);
|
|
22
|
+
this.isSelection = (this.isAnythingSelected && !this.isCursor);
|
|
23
|
+
}
|
|
24
|
+
getCursor() {
|
|
25
|
+
if (this.isCursor && this.host && this.range)
|
|
26
|
+
return new Cursor(this.host, this.range);
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
getSelection() {
|
|
30
|
+
if (this.isSelection && this.host && this.range)
|
|
31
|
+
return new Selection(this.host, this.range);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
forceCursor() {
|
|
35
|
+
if (!this.isSelection)
|
|
36
|
+
return this.getCursor();
|
|
37
|
+
const selection = this.getSelection();
|
|
38
|
+
if (selection)
|
|
39
|
+
return selection.deleteContent();
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
isDifferentFrom(otherRangeContainer = new RangeContainer()) {
|
|
43
|
+
const self = this.range;
|
|
44
|
+
const other = otherRangeContainer.range;
|
|
45
|
+
if (self && other)
|
|
46
|
+
return !rangesAreEqual(self, other);
|
|
47
|
+
if (!self && other)
|
|
48
|
+
return false;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=range-container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range-container.js","sourceRoot":"","sources":["../src/range-container.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAC,cAAc,EAAC,MAAM,eAAe,CAAA;AAE5C;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,cAAc;IAOjC,YAAa,YAAgC,EAAE,KAAa;QAC1D,IAAI,CAAC,IAAI,GAAG,YAAY,IAAK,YAAoB,CAAC,MAAM;YACtD,CAAC,CAAE,YAAoB,CAAC,CAAC,CAAC;YAC1B,CAAC,CAAC,YAAY,CAAA;QAChB,0FAA0F;QAC1F,iEAAiE;QACjE,sGAAsG;QACtG,IAAI,CAAC,KAAK,GAAG,KAAK,EAAE,UAAU,EAAE,CAAA;QAChC,IAAI,CAAC,kBAAkB,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAA;QAC/C,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,KAAM,CAAC,SAAS,CAAC,CAAA;QAC7D,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAChE,CAAC;IAED,SAAS;QACP,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QACtF,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAY;QACV,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QAC5F,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,WAAW;QACT,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,SAAS,EAAE,CAAA;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;QACrC,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC,aAAa,EAAE,CAAA;QAC/C,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,eAAe,CAAE,sBAAsC,IAAI,cAAc,EAAE;QACzE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,CAAA;QACvC,IAAI,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACtD,IAAI,CAAC,IAAI,IAAI,KAAK;YAAE,OAAO,KAAK,CAAA;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function insertRangeBoundaryMarker(range: Range, atStart: boolean): HTMLElement;
|
|
2
|
+
export declare function setRangeBoundary(host: HTMLElement, range: Range, markerId: string, atStart: boolean): void;
|
|
3
|
+
export interface RangeInfo {
|
|
4
|
+
markerId?: string;
|
|
5
|
+
startMarkerId?: string;
|
|
6
|
+
endMarkerId?: string;
|
|
7
|
+
collapsed: boolean;
|
|
8
|
+
host?: HTMLElement;
|
|
9
|
+
restored?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function save(range: Range): RangeInfo;
|
|
12
|
+
export declare function restore(host: HTMLElement, rangeInfo: RangeInfo): Range | undefined;
|
|
13
|
+
//# sourceMappingURL=range-save-restore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range-save-restore.d.ts","sourceRoot":"","sources":["../src/range-save-restore.ts"],"names":[],"mappings":"AAoBA,wBAAgB,yBAAyB,CAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,WAAW,CAoDtF;AAED,wBAAgB,gBAAgB,CAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAK3G;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,IAAI,CAAE,KAAK,EAAE,KAAK,GAAG,SAAS,CAmC7C;AAED,wBAAgB,OAAO,CAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,KAAK,GAAG,SAAS,CAsCnF"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import error from './util/error.js';
|
|
2
|
+
import * as nodeType from './node-type.js';
|
|
3
|
+
import { createRange, normalizeBoundaries } from './util/dom.js';
|
|
4
|
+
/**
|
|
5
|
+
* Inspired by the Selection save and restore module for Rangy by Tim Down
|
|
6
|
+
* Saves and restores ranges using invisible marker elements in the DOM.
|
|
7
|
+
*/
|
|
8
|
+
let boundaryMarkerId = 0;
|
|
9
|
+
// (U+FEFF) zero width no-break space
|
|
10
|
+
const markerTextChar = '\ufeff';
|
|
11
|
+
function isSecondChildOfCommonAncestor(range, rangeContainer) {
|
|
12
|
+
const parent = range.commonAncestorContainer;
|
|
13
|
+
if (parent.nodeType === 3)
|
|
14
|
+
return false; // if we are on the text node it can't be a parent
|
|
15
|
+
const possibleChild = rangeContainer.parentElement;
|
|
16
|
+
return possibleChild?.parentElement === parent;
|
|
17
|
+
}
|
|
18
|
+
export function insertRangeBoundaryMarker(range, atStart) {
|
|
19
|
+
const container = range.commonAncestorContainer;
|
|
20
|
+
// If ownerDocument is null the commonAncestorContainer is window.document
|
|
21
|
+
if (!container.ownerDocument) {
|
|
22
|
+
error('Cannot save range: range is empty');
|
|
23
|
+
throw new Error('Cannot save range: range is empty');
|
|
24
|
+
}
|
|
25
|
+
const ownerDoc = container.ownerDocument;
|
|
26
|
+
if (!ownerDoc.defaultView) {
|
|
27
|
+
error('Cannot save range: document has no defaultView');
|
|
28
|
+
throw new Error('Cannot save range: document has no defaultView');
|
|
29
|
+
}
|
|
30
|
+
// Create the marker element containing a single
|
|
31
|
+
// invisible character using DOM methods and insert it
|
|
32
|
+
const doc = ownerDoc.defaultView.document;
|
|
33
|
+
const markerEl = doc.createElement('span');
|
|
34
|
+
markerEl.id = `editable-range-boundary-${++boundaryMarkerId}`;
|
|
35
|
+
markerEl.setAttribute('data-editable', 'remove');
|
|
36
|
+
markerEl.style.lineHeight = '0';
|
|
37
|
+
markerEl.style.display = 'none';
|
|
38
|
+
markerEl.appendChild(doc.createTextNode(markerTextChar));
|
|
39
|
+
// This logic can expand the selection by inserting the marker before the element
|
|
40
|
+
// of the start or end container. In some cases this prevents breaking up existing tags.
|
|
41
|
+
// The solution is not perfect, but has been here a while.
|
|
42
|
+
// And it is somewhat inconsistent as it check if the container is a second grade child
|
|
43
|
+
// of the common ancestor.
|
|
44
|
+
// It can help to prevent the nuking of e.g. comments when formatting like bold
|
|
45
|
+
// is applied.
|
|
46
|
+
const directlyBeforeFormatTag = atStart && isSecondChildOfCommonAncestor(range, range.startContainer);
|
|
47
|
+
const directlyAfterFormatTag = !atStart && isSecondChildOfCommonAncestor(range, range.endContainer);
|
|
48
|
+
if (directlyBeforeFormatTag) {
|
|
49
|
+
const startParentElem = range.startContainer.parentElement;
|
|
50
|
+
if (startParentElem && startParentElem.parentElement) {
|
|
51
|
+
startParentElem.parentElement.insertBefore(markerEl, startParentElem);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (directlyAfterFormatTag) {
|
|
55
|
+
const endParentElem = range.endContainer.parentElement;
|
|
56
|
+
if (endParentElem && endParentElem.parentElement) {
|
|
57
|
+
endParentElem.parentElement.insertBefore(markerEl, endParentElem.nextSibling);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Clone the Range and collapse to the appropriate boundary point
|
|
62
|
+
const boundaryRange = range.cloneRange();
|
|
63
|
+
boundaryRange.collapse(atStart);
|
|
64
|
+
boundaryRange.insertNode(markerEl);
|
|
65
|
+
}
|
|
66
|
+
return markerEl;
|
|
67
|
+
}
|
|
68
|
+
export function setRangeBoundary(host, range, markerId, atStart) {
|
|
69
|
+
const markerEl = getMarker(host, markerId);
|
|
70
|
+
if (!markerEl)
|
|
71
|
+
return console.log('Marker element has been removed. Cannot restore selection.');
|
|
72
|
+
range[atStart ? 'setStartBefore' : 'setEndBefore'](markerEl);
|
|
73
|
+
markerEl.remove();
|
|
74
|
+
}
|
|
75
|
+
export function save(range) {
|
|
76
|
+
let rangeInfo;
|
|
77
|
+
let startEl;
|
|
78
|
+
let endEl;
|
|
79
|
+
// insert markers
|
|
80
|
+
if (range.collapsed) {
|
|
81
|
+
endEl = insertRangeBoundaryMarker(range, false);
|
|
82
|
+
rangeInfo = {
|
|
83
|
+
markerId: endEl.id,
|
|
84
|
+
collapsed: true
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
endEl = insertRangeBoundaryMarker(range, false);
|
|
89
|
+
startEl = insertRangeBoundaryMarker(range, true);
|
|
90
|
+
rangeInfo = {
|
|
91
|
+
startMarkerId: startEl.id,
|
|
92
|
+
endMarkerId: endEl.id,
|
|
93
|
+
collapsed: false
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// Adjust each range's boundaries to lie between its markers
|
|
97
|
+
if (range.collapsed) {
|
|
98
|
+
range.setStartBefore(endEl);
|
|
99
|
+
range.collapse(true);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
range.setEndBefore(endEl);
|
|
103
|
+
if (startEl) {
|
|
104
|
+
range.setStartAfter(startEl);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return rangeInfo;
|
|
108
|
+
}
|
|
109
|
+
export function restore(host, rangeInfo) {
|
|
110
|
+
if (rangeInfo.restored)
|
|
111
|
+
return;
|
|
112
|
+
const range = createRange();
|
|
113
|
+
if (rangeInfo.collapsed) {
|
|
114
|
+
if (!rangeInfo.markerId) {
|
|
115
|
+
console.log('Marker ID is missing. Cannot restore selection.');
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
const markerEl = getMarker(host, rangeInfo.markerId);
|
|
119
|
+
if (markerEl) {
|
|
120
|
+
markerEl.style.display = 'inline';
|
|
121
|
+
const previousNode = markerEl.previousSibling;
|
|
122
|
+
// Workaround for rangy issue 17
|
|
123
|
+
if (previousNode && previousNode.nodeType === nodeType.textNode) {
|
|
124
|
+
markerEl.remove();
|
|
125
|
+
range.setStart(previousNode, previousNode.length);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
range.setStartBefore(markerEl);
|
|
129
|
+
range.collapse(true);
|
|
130
|
+
markerEl.remove();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
console.log('Marker element has been removed. Cannot restore selection.');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (rangeInfo.startMarkerId && rangeInfo.endMarkerId) {
|
|
139
|
+
setRangeBoundary(host, range, rangeInfo.startMarkerId, true);
|
|
140
|
+
setRangeBoundary(host, range, rangeInfo.endMarkerId, false);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
console.log('Marker IDs are missing. Cannot restore selection.');
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
normalizeBoundaries(range);
|
|
148
|
+
return range;
|
|
149
|
+
}
|
|
150
|
+
function getMarker(host, id) {
|
|
151
|
+
return host.querySelector(`#${id}`);
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=range-save-restore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range-save-restore.js","sourceRoot":"","sources":["../src/range-save-restore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAA;AACnC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAE9D;;;GAGG;AACH,IAAI,gBAAgB,GAAG,CAAC,CAAA;AAExB,qCAAqC;AACrC,MAAM,cAAc,GAAG,QAAQ,CAAA;AAE/B,SAAS,6BAA6B,CAAE,KAAY,EAAE,cAAoB;IACxE,MAAM,MAAM,GAAG,KAAK,CAAC,uBAAuB,CAAA;IAC5C,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA,CAAC,kDAAkD;IAC1F,MAAM,aAAa,GAAG,cAAc,CAAC,aAAa,CAAA;IAClD,OAAO,aAAa,EAAE,aAAa,KAAK,MAAM,CAAA;AAChD,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAE,KAAY,EAAE,OAAgB;IACvE,MAAM,SAAS,GAAG,KAAK,CAAC,uBAAuB,CAAA;IAE/C,0EAA0E;IAC1E,IAAI,C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AM,YAAY,GAAG,QAAQ,CAAC,eAAe,CAAA;YAE7C,gCAAgC;YAChC,IAAI,YAAY,IAAI,YAAY,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBAChE,QAAQ,CAAC,MAAM,EAAE,CAAA;gBACjB,KAAK,CAAC,QAAQ,CAAC,YAAY,EAAG,YAAqB,CAAC,MAAM,CAAC,CAAA;YAC7D,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;gBAC9B,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;gBACpB,QAAQ,CAAC,MAAM,EAAE,CAAA;YACnB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAA;QAC3E,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,SAAS,CAAC,aAAa,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;YACrD,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;YAC5D,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAA;YAChE,OAAO,SAAS,CAAA;QAClB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAC1B,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,SAAS,CAAE,IAAiB,EAAE,EAAU;IAC/C,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import RangeContainer from './range-container.js';
|
|
2
|
+
import Cursor from './cursor.js';
|
|
3
|
+
import Selection from './selection.js';
|
|
4
|
+
import type Dispatcher from './dispatcher.js';
|
|
5
|
+
/**
|
|
6
|
+
* The SelectionWatcher module watches for selection changes inside
|
|
7
|
+
* of editable blocks.
|
|
8
|
+
*
|
|
9
|
+
* @module core
|
|
10
|
+
* @submodule selectionWatcher
|
|
11
|
+
*/
|
|
12
|
+
export default class SelectionWatcher {
|
|
13
|
+
dispatcher: Dispatcher;
|
|
14
|
+
win: Window;
|
|
15
|
+
selection: globalThis.Selection | null | undefined;
|
|
16
|
+
currentSelection: Cursor | Selection | undefined;
|
|
17
|
+
currentRange: RangeContainer | undefined;
|
|
18
|
+
constructor(dispatcher: Dispatcher, win?: Window);
|
|
19
|
+
/**
|
|
20
|
+
* Updates the internal selection pointer to the current selection.
|
|
21
|
+
* Returns true if no exception occurred.
|
|
22
|
+
*/
|
|
23
|
+
syncSelection(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Return a RangeContainer if the current selection is within an editable
|
|
26
|
+
* otherwise return an empty RangeContainer
|
|
27
|
+
*/
|
|
28
|
+
getRangeContainer(): RangeContainer;
|
|
29
|
+
/**
|
|
30
|
+
* Gets a fresh RangeContainer with the current selection or cursor.
|
|
31
|
+
*
|
|
32
|
+
* @return RangeContainer instance
|
|
33
|
+
*/
|
|
34
|
+
getFreshRange(): RangeContainer;
|
|
35
|
+
/**
|
|
36
|
+
* Gets a fresh RangeContainer with the current selection or cursor.
|
|
37
|
+
*
|
|
38
|
+
* @return Either a Cursor or Selection instance or undefined if
|
|
39
|
+
* there is neither a selection or cursor.
|
|
40
|
+
*/
|
|
41
|
+
getFreshSelection(): Cursor | Selection | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Get the selection set by the last selectionChanged event.
|
|
44
|
+
* Sometimes the event does not fire fast enough and the selection
|
|
45
|
+
* you get is not the one the user sees.
|
|
46
|
+
* In those cases use #getFreshSelection()
|
|
47
|
+
*
|
|
48
|
+
* @return Either a Cursor or Selection instance or undefined if
|
|
49
|
+
* there is neither a selection or cursor.
|
|
50
|
+
*/
|
|
51
|
+
getSelection(): Cursor | Selection | undefined;
|
|
52
|
+
forceCursor(): Cursor | undefined;
|
|
53
|
+
selectionChanged(): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=selection-watcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-watcher.d.ts","sourceRoot":"","sources":["../src/selection-watcher.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,sBAAsB,CAAA;AACjD,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAEtC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IAC5B,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,UAAU,CAAC,SAAS,GAAG,IAAI,GAAG,SAAS,CAAA;IAClD,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAA;IAChD,YAAY,EAAE,cAAc,GAAG,SAAS,CAAA;gBAElC,UAAU,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,MAAM;IAQjD;;;OAGG;IACH,aAAa;IAWb;;;MAGE;IACF,iBAAiB;IAuBjB;;;;MAIE;IACF,aAAa;IAIb;;;;;MAKE;IACF,iBAAiB,IAAK,MAAM,GAAG,SAAS,GAAG,SAAS;IAQpD;;;;;;;;MAQE;IACF,YAAY;IAIZ,WAAW;IAKX,gBAAgB;CA2BjB"}
|