@blankdotpage/cake 0.1.44 → 0.1.46
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/dist/cake/extensions/italic/italic.d.ts.map +1 -1
- package/dist/cake/extensions/italic/italic.js +21 -1
- package/dist/cake/extensions/link/link.d.ts.map +1 -1
- package/dist/cake/extensions/link/link.js +98 -3
- package/dist/cake/shared/word-break.d.ts.map +1 -1
- package/dist/cake/shared/word-break.js +46 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"italic.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/italic/italic.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"italic.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/italic/italic.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,oBAAoB,CAAC;AAsC5B,eAAO,MAAM,eAAe,EAAE,aA+H7B,CAAC"}
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { CursorSourceBuilder } from "../../core/mapping/cursor-source-map";
|
|
2
2
|
const ITALIC_KIND = "italic";
|
|
3
|
+
function findItalicClose(source, start, end, marker) {
|
|
4
|
+
if (marker === "_") {
|
|
5
|
+
return source.indexOf("_", start + 1);
|
|
6
|
+
}
|
|
7
|
+
let fallback = -1;
|
|
8
|
+
for (let i = start + 1; i < end; i += 1) {
|
|
9
|
+
if (source[i] !== "*") {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const prevIsStar = source[i - 1] === "*";
|
|
13
|
+
const nextIsStar = source[i + 1] === "*";
|
|
14
|
+
if (!prevIsStar && !nextIsStar) {
|
|
15
|
+
return i;
|
|
16
|
+
}
|
|
17
|
+
if (fallback === -1) {
|
|
18
|
+
fallback = i;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return fallback;
|
|
22
|
+
}
|
|
3
23
|
export const italicExtension = (editor) => {
|
|
4
24
|
const disposers = [];
|
|
5
25
|
disposers.push(editor.registerToggleInline({ kind: ITALIC_KIND, markers: ["*", "_"] }));
|
|
@@ -34,7 +54,7 @@ export const italicExtension = (editor) => {
|
|
|
34
54
|
if (char === "*" && start > 0 && source[start - 1] === "*") {
|
|
35
55
|
return null;
|
|
36
56
|
}
|
|
37
|
-
const close = source
|
|
57
|
+
const close = findItalicClose(source, start, end, char);
|
|
38
58
|
if (close === -1 || close >= end) {
|
|
39
59
|
return null;
|
|
40
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/link/link.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/cake/extensions/link/link.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AA2F3D,8CAA8C;AAC9C,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,kCAAkC;AAClC,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,aAAa,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG,CAC/B,MAAM,EAAE,UAAU,KACf,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAAC;AAEnD,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAkYF,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AACvE,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,aAAa,CAAC"}
|
|
@@ -5,6 +5,73 @@ import { getDocLines } from "../../editor/selection/selection-layout";
|
|
|
5
5
|
import { cursorOffsetToVisibleOffset, getVisibleText, } from "../../editor/selection/visible-text";
|
|
6
6
|
import { ensureHttpsProtocol, isUrl } from "../../shared/url";
|
|
7
7
|
const LINK_KIND = "link";
|
|
8
|
+
function countBoundaryWrappers(fragment) {
|
|
9
|
+
let count = 0;
|
|
10
|
+
let index = 0;
|
|
11
|
+
while (index < fragment.length) {
|
|
12
|
+
if (fragment.startsWith("</u>", index)) {
|
|
13
|
+
count += 1;
|
|
14
|
+
index += 4;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (fragment.startsWith("<u>", index)) {
|
|
18
|
+
count += 1;
|
|
19
|
+
index += 3;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (fragment.startsWith("**", index)) {
|
|
23
|
+
count += 1;
|
|
24
|
+
index += 2;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (fragment.startsWith("~~", index)) {
|
|
28
|
+
count += 1;
|
|
29
|
+
index += 2;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const char = fragment[index] ?? "";
|
|
33
|
+
if (char === "*" || char === "_") {
|
|
34
|
+
count += 1;
|
|
35
|
+
}
|
|
36
|
+
index += 1;
|
|
37
|
+
}
|
|
38
|
+
return count;
|
|
39
|
+
}
|
|
40
|
+
function findEnclosingLinkRange(source, from, to) {
|
|
41
|
+
if (source.length === 0) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const start = Math.max(0, Math.min(from, source.length));
|
|
45
|
+
const end = Math.max(0, Math.min(to, source.length));
|
|
46
|
+
if (start >= end) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
let linkStart = source.lastIndexOf("[", start);
|
|
50
|
+
while (linkStart !== -1) {
|
|
51
|
+
// Skip image syntax 
|
|
52
|
+
if (linkStart > 0 && source[linkStart - 1] === "!") {
|
|
53
|
+
linkStart = source.lastIndexOf("[", linkStart - 1);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const labelClose = source.indexOf("](", linkStart + 1);
|
|
57
|
+
if (labelClose === -1) {
|
|
58
|
+
linkStart = source.lastIndexOf("[", linkStart - 1);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const urlClose = source.indexOf(")", labelClose + 2);
|
|
62
|
+
if (urlClose === -1) {
|
|
63
|
+
linkStart = source.lastIndexOf("[", linkStart - 1);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const labelStart = linkStart + 1;
|
|
67
|
+
const labelEnd = labelClose;
|
|
68
|
+
if (labelStart <= start && end <= labelEnd) {
|
|
69
|
+
return { linkStart, labelStart, labelEnd, urlClose };
|
|
70
|
+
}
|
|
71
|
+
linkStart = source.lastIndexOf("[", linkStart - 1);
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
8
75
|
function isDomSelectionInsideLink(editor) {
|
|
9
76
|
if (typeof window === "undefined") {
|
|
10
77
|
return false;
|
|
@@ -149,11 +216,39 @@ function installLinkExtension(editor, options) {
|
|
|
149
216
|
}
|
|
150
217
|
return null;
|
|
151
218
|
}
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
219
|
+
const innerFrom = state.map.cursorToSource(cursorStart, "forward");
|
|
220
|
+
const innerTo = state.map.cursorToSource(cursorEnd, "backward");
|
|
221
|
+
if (innerFrom === innerTo) {
|
|
155
222
|
return null;
|
|
156
223
|
}
|
|
224
|
+
// Treat wrap-link as a toggle when the selection is already within the
|
|
225
|
+
// same link label. This matches toolbar expectations for active link.
|
|
226
|
+
const existingLink = findEnclosingLinkRange(state.source, innerFrom, innerTo);
|
|
227
|
+
if (existingLink) {
|
|
228
|
+
const label = state.source.slice(existingLink.labelStart, existingLink.labelEnd);
|
|
229
|
+
const nextSource = state.source.slice(0, existingLink.linkStart) +
|
|
230
|
+
label +
|
|
231
|
+
state.source.slice(existingLink.urlClose + 1);
|
|
232
|
+
const nextState = state.runtime.createState(nextSource);
|
|
233
|
+
const nextStart = nextState.map.sourceToCursor(existingLink.linkStart, "forward");
|
|
234
|
+
const nextEnd = nextState.map.sourceToCursor(existingLink.linkStart + label.length, "backward");
|
|
235
|
+
return {
|
|
236
|
+
source: nextSource,
|
|
237
|
+
selection: {
|
|
238
|
+
start: nextStart.cursorOffset,
|
|
239
|
+
end: nextEnd.cursorOffset,
|
|
240
|
+
affinity: "forward",
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const outerFrom = state.map.cursorToSource(cursorStart, "backward");
|
|
245
|
+
const outerTo = state.map.cursorToSource(cursorEnd, "forward");
|
|
246
|
+
const leftBoundary = state.source.slice(outerFrom, innerFrom);
|
|
247
|
+
const rightBoundary = state.source.slice(innerTo, outerTo);
|
|
248
|
+
const hasNestedBoundaryWrappers = countBoundaryWrappers(leftBoundary) > 1 ||
|
|
249
|
+
countBoundaryWrappers(rightBoundary) > 1;
|
|
250
|
+
const from = hasNestedBoundaryWrappers ? outerFrom : innerFrom;
|
|
251
|
+
const to = hasNestedBoundaryWrappers ? outerTo : innerTo;
|
|
157
252
|
const label = state.source.slice(from, to);
|
|
158
253
|
const url = command.url ?? "";
|
|
159
254
|
const linkMarkdown = `[${label}](${url})`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"word-break.d.ts","sourceRoot":"","sources":["../../../src/cake/shared/word-break.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"word-break.d.ts","sourceRoot":"","sources":["../../../src/cake/shared/word-break.ts"],"names":[],"mappings":"AAuCA;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CA8BhC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CA0EhC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA8ClE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CA8DlE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { wordSegments } from "./segmenter";
|
|
2
|
+
const ZERO_WIDTH_PLACEHOLDER = "\u200B";
|
|
2
3
|
function getWordSegments(text) {
|
|
3
4
|
return wordSegments(text).map((seg) => ({
|
|
4
5
|
segment: seg.segment,
|
|
@@ -63,6 +64,51 @@ export function getWordBoundaries(text, offset) {
|
|
|
63
64
|
return { start: 0, end: 0 };
|
|
64
65
|
}
|
|
65
66
|
const clampedOffset = Math.max(0, Math.min(offset, maxLength));
|
|
67
|
+
// Zero-width placeholders are internal formatting artifacts used for
|
|
68
|
+
// pending mark state and should not split a "word" for double-click.
|
|
69
|
+
if (text.includes(ZERO_WIDTH_PLACEHOLDER)) {
|
|
70
|
+
const nonPlaceholderPrefixCounts = new Array(text.length + 1).fill(0);
|
|
71
|
+
let compactText = "";
|
|
72
|
+
let compactCount = 0;
|
|
73
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
74
|
+
const char = text[i] ?? "";
|
|
75
|
+
if (char !== ZERO_WIDTH_PLACEHOLDER) {
|
|
76
|
+
compactText += char;
|
|
77
|
+
compactCount += 1;
|
|
78
|
+
}
|
|
79
|
+
nonPlaceholderPrefixCounts[i + 1] = compactCount;
|
|
80
|
+
}
|
|
81
|
+
if (compactText.length === 0) {
|
|
82
|
+
return { start: 0, end: 0 };
|
|
83
|
+
}
|
|
84
|
+
const compactOffset = nonPlaceholderPrefixCounts[clampedOffset] ?? 0;
|
|
85
|
+
let adjustedCompactOffset = compactOffset;
|
|
86
|
+
if (adjustedCompactOffset >= compactText.length) {
|
|
87
|
+
adjustedCompactOffset = compactText.length - 1;
|
|
88
|
+
}
|
|
89
|
+
const compactChar = compactText[adjustedCompactOffset] ?? "";
|
|
90
|
+
if (compactChar === "\n" && adjustedCompactOffset > 0) {
|
|
91
|
+
adjustedCompactOffset = adjustedCompactOffset - 1;
|
|
92
|
+
}
|
|
93
|
+
const compactBounds = getWordBoundariesAt(compactText, adjustedCompactOffset);
|
|
94
|
+
const compactStart = compactBounds.start;
|
|
95
|
+
const compactEnd = compactBounds.end;
|
|
96
|
+
let rawStart = 0;
|
|
97
|
+
for (let i = 0; i < nonPlaceholderPrefixCounts.length; i += 1) {
|
|
98
|
+
if ((nonPlaceholderPrefixCounts[i] ?? 0) >= compactStart) {
|
|
99
|
+
rawStart = i;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let rawEnd = text.length;
|
|
104
|
+
for (let i = rawStart; i < nonPlaceholderPrefixCounts.length; i += 1) {
|
|
105
|
+
if ((nonPlaceholderPrefixCounts[i] ?? 0) >= compactEnd) {
|
|
106
|
+
rawEnd = i;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { start: rawStart, end: rawEnd };
|
|
111
|
+
}
|
|
66
112
|
let adjustedOffset = clampedOffset;
|
|
67
113
|
if (adjustedOffset >= maxLength) {
|
|
68
114
|
adjustedOffset = maxLength - 1;
|