@aicayzer/inkkit 0.0.17 → 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.
- package/NOTICE +4 -2
- package/README.md +12 -6
- package/dist/THIRD-PARTY-NOTICES.txt +2742 -0
- package/dist/chunks/core-vtCr4MBS.js +56503 -0
- package/dist/chunks/highlight-Daj2fv_u.js +14122 -0
- package/dist/core.d.ts +4 -0
- package/dist/core.js +2 -0
- package/dist/editor.d.ts +261 -48
- package/dist/index.d.ts +1 -7
- package/dist/index.js +5 -2
- package/dist/style.css +242 -221
- package/dist/types.d.ts +143 -18
- package/package.json +26 -15
- package/dist/autolink.d.ts +0 -1
- package/dist/autolink.js +0 -18
- package/dist/callouts.d.ts +0 -26
- package/dist/callouts.js +0 -311
- package/dist/clipboard.d.ts +0 -11
- package/dist/clipboard.js +0 -261
- package/dist/code-fences.d.ts +0 -8
- package/dist/code-fences.js +0 -166
- package/dist/comments.d.ts +0 -55
- package/dist/comments.js +0 -494
- package/dist/decorations.d.ts +0 -2
- package/dist/decorations.js +0 -67
- package/dist/dialect.d.ts +0 -9
- package/dist/dialect.js +0 -358
- package/dist/editor.js +0 -2441
- package/dist/files.d.ts +0 -40
- package/dist/files.js +0 -133
- package/dist/highlight.d.ts +0 -1
- package/dist/highlight.js +0 -136
- package/dist/image-blocks.d.ts +0 -71
- package/dist/image-blocks.js +0 -286
- package/dist/images.d.ts +0 -51
- package/dist/images.js +0 -398
- package/dist/inline-highlight.d.ts +0 -6
- package/dist/inline-highlight.js +0 -112
- package/dist/labels.d.ts +0 -36
- package/dist/labels.js +0 -34
- package/dist/linked-syntax.d.ts +0 -48
- package/dist/linked-syntax.js +0 -320
- package/dist/literals.d.ts +0 -19
- package/dist/literals.js +0 -211
- package/dist/mermaid.d.ts +0 -8
- package/dist/mermaid.js +0 -321
- package/dist/outline.d.ts +0 -22
- package/dist/outline.js +0 -79
- package/dist/paste-html.d.ts +0 -23
- package/dist/paste-html.js +0 -441
- package/dist/paste.d.ts +0 -26
- package/dist/paste.js +0 -482
- package/dist/portable-files.d.ts +0 -10
- package/dist/portable-files.js +0 -36
- package/dist/preserve.d.ts +0 -21
- package/dist/preserve.js +0 -757
- package/dist/print.d.ts +0 -7
- package/dist/print.js +0 -409
- package/dist/reference-clipboard.d.ts +0 -8
- package/dist/reference-clipboard.js +0 -201
- package/dist/references.d.ts +0 -14
- package/dist/references.js +0 -368
- package/dist/search.d.ts +0 -15
- package/dist/search.js +0 -202
- package/dist/selection.d.ts +0 -1
- package/dist/selection.js +0 -59
- package/dist/source.d.ts +0 -16
- package/dist/source.js +0 -57
- package/dist/spreadsheet.d.ts +0 -3
- package/dist/spreadsheet.js +0 -275
- package/dist/table-alignment.d.ts +0 -2
- package/dist/table-alignment.js +0 -46
- package/dist/tables.d.ts +0 -27
- package/dist/tables.js +0 -322
- package/dist/tasks.d.ts +0 -3
- package/dist/tasks.js +0 -51
- package/dist/text-ranges.d.ts +0 -29
- package/dist/text-ranges.js +0 -256
- package/dist/types.js +0 -8
- package/dist/wiki-view.d.ts +0 -21
- package/dist/wiki-view.js +0 -78
package/dist/paste-html.js
DELETED
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
// Elements the HTML paste path hands to ProseMirror's parser. Anything else
|
|
2
|
-
// is kept as literal source, so a tag must be listed here or rewritten by
|
|
3
|
-
// `normalizeClipboardHTML` to avoid becoming a raw-HTML block.
|
|
4
|
-
const rich = new Set([
|
|
5
|
-
'P',
|
|
6
|
-
'H1',
|
|
7
|
-
'H2',
|
|
8
|
-
'H3',
|
|
9
|
-
'H4',
|
|
10
|
-
'H5',
|
|
11
|
-
'H6',
|
|
12
|
-
'STRONG',
|
|
13
|
-
'MARK',
|
|
14
|
-
'B',
|
|
15
|
-
'EM',
|
|
16
|
-
'I',
|
|
17
|
-
'S',
|
|
18
|
-
'DEL',
|
|
19
|
-
'STRIKE',
|
|
20
|
-
'CODE',
|
|
21
|
-
'PRE',
|
|
22
|
-
'BLOCKQUOTE',
|
|
23
|
-
'A',
|
|
24
|
-
'BR',
|
|
25
|
-
'HR',
|
|
26
|
-
'UL',
|
|
27
|
-
'OL',
|
|
28
|
-
'LI',
|
|
29
|
-
'TABLE',
|
|
30
|
-
'THEAD',
|
|
31
|
-
'TBODY',
|
|
32
|
-
'TFOOT',
|
|
33
|
-
'TR',
|
|
34
|
-
'TH',
|
|
35
|
-
'TD',
|
|
36
|
-
'IMG',
|
|
37
|
-
'SPAN',
|
|
38
|
-
'SUP',
|
|
39
|
-
'DIV',
|
|
40
|
-
'FONT',
|
|
41
|
-
'SECTION',
|
|
42
|
-
'ARTICLE',
|
|
43
|
-
'MAIN',
|
|
44
|
-
'HEADER',
|
|
45
|
-
'FOOTER',
|
|
46
|
-
]);
|
|
47
|
-
// Document furniture and form inputs hold no content of their own. A
|
|
48
|
-
// template never keeps `head`, so it is not listed.
|
|
49
|
-
const dropped = new Set(['STYLE', 'META', 'LINK', 'TITLE', 'SOURCE', 'INPUT']);
|
|
50
|
-
// The dialect has no underline, subscript or similar marks, so these keep
|
|
51
|
-
// their children and lose only the wrapper.
|
|
52
|
-
const unwrapped = new Set([
|
|
53
|
-
'U',
|
|
54
|
-
'SUB',
|
|
55
|
-
'SMALL',
|
|
56
|
-
'TIME',
|
|
57
|
-
'ABBR',
|
|
58
|
-
'CITE',
|
|
59
|
-
'DFN',
|
|
60
|
-
'VAR',
|
|
61
|
-
'INS',
|
|
62
|
-
'BDI',
|
|
63
|
-
'BDO',
|
|
64
|
-
'LABEL',
|
|
65
|
-
]);
|
|
66
|
-
const blockWrappers = new Set(['FIGURE', 'FIGCAPTION', 'DL', 'DD']);
|
|
67
|
-
const handled = new Set([
|
|
68
|
-
...dropped,
|
|
69
|
-
...unwrapped,
|
|
70
|
-
...blockWrappers,
|
|
71
|
-
'DT',
|
|
72
|
-
'PICTURE',
|
|
73
|
-
]);
|
|
74
|
-
export function isRichElement(element) {
|
|
75
|
-
return rich.has(element.tagName);
|
|
76
|
-
}
|
|
77
|
-
/** Whether normalisation enters the element, so its content may be rewritten. */
|
|
78
|
-
export function isRewrittenElement(element) {
|
|
79
|
-
return rich.has(element.tagName) || handled.has(element.tagName);
|
|
80
|
-
}
|
|
81
|
-
// `white-space` and its longhand `white-space-collapse` keep source spaces with
|
|
82
|
-
// these keywords. `pre-line` and `preserve-breaks` collapse spaces, so they are
|
|
83
|
-
// collapsed here too.
|
|
84
|
-
const keepingWhitespace = new Set([
|
|
85
|
-
'pre',
|
|
86
|
-
'pre-wrap',
|
|
87
|
-
'break-spaces',
|
|
88
|
-
'preserve',
|
|
89
|
-
'preserve-spaces',
|
|
90
|
-
]);
|
|
91
|
-
/**
|
|
92
|
-
* Whether the element's own inline style makes a browser keep the whitespace
|
|
93
|
-
* of its content, as copied editor code does with `white-space: pre`. The
|
|
94
|
-
* declarations are parsed, so case, spacing, comments, quoted text and
|
|
95
|
-
* `!important` do not matter. Style sheets are not consulted.
|
|
96
|
-
*/
|
|
97
|
-
export function keepsWhitespace(element) {
|
|
98
|
-
const style = element.getAttribute('style');
|
|
99
|
-
if (!style)
|
|
100
|
-
return false;
|
|
101
|
-
const winning = new Map();
|
|
102
|
-
for (const declaration of declarations(style)) {
|
|
103
|
-
const colon = declaration.indexOf(':');
|
|
104
|
-
if (colon < 0)
|
|
105
|
-
continue;
|
|
106
|
-
const name = declaration.slice(0, colon).trim().toLowerCase();
|
|
107
|
-
if (name !== 'white-space' && name !== 'white-space-collapse')
|
|
108
|
-
continue;
|
|
109
|
-
let value = declaration.slice(colon + 1).trim();
|
|
110
|
-
const important = /!\s*important$/i.test(value);
|
|
111
|
-
if (important)
|
|
112
|
-
value = value.replace(/!\s*important$/i, '');
|
|
113
|
-
const earlier = winning.get(name);
|
|
114
|
-
if (!earlier?.important || important)
|
|
115
|
-
winning.set(name, { value: value.trim().toLowerCase(), important });
|
|
116
|
-
}
|
|
117
|
-
return [...winning.values()].some(({ value }) => value.split(/\s+/).some((keyword) => keepingWhitespace.has(keyword)));
|
|
118
|
-
}
|
|
119
|
-
// Splits a style attribute at the semicolons that end declarations, ignoring
|
|
120
|
-
// those inside comments, quoted strings and parentheses such as `url(...)`.
|
|
121
|
-
function declarations(style) {
|
|
122
|
-
const result = [];
|
|
123
|
-
let current = '';
|
|
124
|
-
let quote = '';
|
|
125
|
-
let depth = 0;
|
|
126
|
-
for (let index = 0; index < style.length; index++) {
|
|
127
|
-
const character = style[index];
|
|
128
|
-
if (quote) {
|
|
129
|
-
current += character;
|
|
130
|
-
if (character === '\\' && index + 1 < style.length)
|
|
131
|
-
current += style[++index];
|
|
132
|
-
else if (character === quote)
|
|
133
|
-
quote = '';
|
|
134
|
-
}
|
|
135
|
-
else if (character === '/' && style[index + 1] === '*') {
|
|
136
|
-
const end = style.indexOf('*/', index + 2);
|
|
137
|
-
index = end < 0 ? style.length : end + 1;
|
|
138
|
-
}
|
|
139
|
-
else if (character === '"' || character === "'") {
|
|
140
|
-
quote = character;
|
|
141
|
-
current += character;
|
|
142
|
-
}
|
|
143
|
-
else if (character === '(') {
|
|
144
|
-
depth++;
|
|
145
|
-
current += character;
|
|
146
|
-
}
|
|
147
|
-
else if (character === ')') {
|
|
148
|
-
depth = Math.max(0, depth - 1);
|
|
149
|
-
current += character;
|
|
150
|
-
}
|
|
151
|
-
else if (character === ';' && depth === 0) {
|
|
152
|
-
result.push(current);
|
|
153
|
-
current = '';
|
|
154
|
-
}
|
|
155
|
-
else
|
|
156
|
-
current += character;
|
|
157
|
-
}
|
|
158
|
-
result.push(current);
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Rewrites common web-page elements to ones the importer already understands.
|
|
163
|
-
* Elements that will stay literal source are not entered, so their content is
|
|
164
|
-
* preserved exactly.
|
|
165
|
-
*/
|
|
166
|
-
export function normalizeClipboardHTML(root) {
|
|
167
|
-
for (const node of [...root.childNodes]) {
|
|
168
|
-
if (node.nodeType === Node.COMMENT_NODE) {
|
|
169
|
-
// Windows and some native apps leave the CF_HTML fragment markers in.
|
|
170
|
-
if (/^\s*(?:Start|End)Fragment\s*$/.test(node.data))
|
|
171
|
-
node.parentNode?.removeChild(node);
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
175
|
-
continue;
|
|
176
|
-
const element = node;
|
|
177
|
-
const tag = element.tagName;
|
|
178
|
-
if (!rich.has(tag) && !handled.has(tag))
|
|
179
|
-
continue;
|
|
180
|
-
if (dropped.has(tag)) {
|
|
181
|
-
const parent = element.parentElement;
|
|
182
|
-
element.remove();
|
|
183
|
-
if (parent)
|
|
184
|
-
removeEmptyParagraph(parent);
|
|
185
|
-
}
|
|
186
|
-
else if (tag === 'PICTURE') {
|
|
187
|
-
const image = element.querySelector('img');
|
|
188
|
-
if (image)
|
|
189
|
-
element.replaceWith(image);
|
|
190
|
-
else
|
|
191
|
-
element.remove();
|
|
192
|
-
}
|
|
193
|
-
else if (unwrapped.has(tag)) {
|
|
194
|
-
normalizeClipboardHTML(element);
|
|
195
|
-
element.replaceWith(...element.childNodes);
|
|
196
|
-
}
|
|
197
|
-
else if (tag === 'DT') {
|
|
198
|
-
normalizeClipboardHTML(element);
|
|
199
|
-
// Markdown has no definition lists. A bold term over its definition
|
|
200
|
-
// keeps which text names the other.
|
|
201
|
-
const term = element.ownerDocument.createElement('div');
|
|
202
|
-
boldInto(term, [...element.childNodes]);
|
|
203
|
-
element.replaceWith(term);
|
|
204
|
-
}
|
|
205
|
-
else if (blockWrappers.has(tag)) {
|
|
206
|
-
normalizeClipboardHTML(element);
|
|
207
|
-
const block = element.ownerDocument.createElement('div');
|
|
208
|
-
block.append(...element.childNodes);
|
|
209
|
-
element.replaceWith(block);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
if (tag === 'LI')
|
|
213
|
-
markTask(element);
|
|
214
|
-
normalizeClipboardHTML(element);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
// A paragraph whose only content was a dropped element would otherwise import
|
|
219
|
-
// as a blank paragraph.
|
|
220
|
-
function removeEmptyParagraph(from) {
|
|
221
|
-
let node = from;
|
|
222
|
-
while (node &&
|
|
223
|
-
['SPAN', 'FONT', 'STRONG', 'B', 'EM', 'I'].includes(node.tagName))
|
|
224
|
-
node = node.parentElement;
|
|
225
|
-
if (node?.tagName === 'P' &&
|
|
226
|
-
!node.textContent?.trim() &&
|
|
227
|
-
!node.querySelector('img,br,hr'))
|
|
228
|
-
node.remove();
|
|
229
|
-
}
|
|
230
|
-
const termBlocks = new Set(['P', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6']);
|
|
231
|
-
const blocks = new Set([
|
|
232
|
-
...termBlocks,
|
|
233
|
-
'BLOCKQUOTE',
|
|
234
|
-
'PRE',
|
|
235
|
-
'UL',
|
|
236
|
-
'OL',
|
|
237
|
-
'LI',
|
|
238
|
-
'TABLE',
|
|
239
|
-
'THEAD',
|
|
240
|
-
'TBODY',
|
|
241
|
-
'TFOOT',
|
|
242
|
-
'TR',
|
|
243
|
-
'TH',
|
|
244
|
-
'TD',
|
|
245
|
-
'SECTION',
|
|
246
|
-
'ARTICLE',
|
|
247
|
-
'MAIN',
|
|
248
|
-
'HEADER',
|
|
249
|
-
'FOOTER',
|
|
250
|
-
'HR',
|
|
251
|
-
]);
|
|
252
|
-
// Bolds the inline content of a term. Paragraphs, headings and divisions
|
|
253
|
-
// inside it each become one bold paragraph; other blocks are kept as they are.
|
|
254
|
-
function boldInto(target, nodes) {
|
|
255
|
-
const document = target.ownerDocument;
|
|
256
|
-
let run;
|
|
257
|
-
const paragraph = (content) => {
|
|
258
|
-
if (!content.some((node) => node.textContent?.trim() || isImage(node)))
|
|
259
|
-
return undefined;
|
|
260
|
-
const block = document.createElement('p');
|
|
261
|
-
const strong = document.createElement('strong');
|
|
262
|
-
strong.append(...content);
|
|
263
|
-
block.append(strong);
|
|
264
|
-
target.append(block);
|
|
265
|
-
return strong;
|
|
266
|
-
};
|
|
267
|
-
for (const node of nodes) {
|
|
268
|
-
const element = node.nodeType === Node.ELEMENT_NODE ? node : null;
|
|
269
|
-
if (element && blocks.has(element.tagName)) {
|
|
270
|
-
run = undefined;
|
|
271
|
-
if (element.tagName === 'P' || /^H[1-6]$/.test(element.tagName))
|
|
272
|
-
paragraph([...element.childNodes]);
|
|
273
|
-
else if (element.tagName === 'DIV')
|
|
274
|
-
boldInto(target, [...element.childNodes]);
|
|
275
|
-
else
|
|
276
|
-
target.append(element);
|
|
277
|
-
}
|
|
278
|
-
else if (run)
|
|
279
|
-
run.append(node);
|
|
280
|
-
else if (node.textContent?.trim() || isImage(node)) {
|
|
281
|
-
run = paragraph([node]);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
function isImage(node) {
|
|
286
|
-
return (node.nodeType === Node.ELEMENT_NODE &&
|
|
287
|
-
(node.tagName === 'IMG' ||
|
|
288
|
-
!!node.querySelector('img')));
|
|
289
|
-
}
|
|
290
|
-
// GitHub, Notion and similar pages render a task as a checkbox leading its
|
|
291
|
-
// list item, optionally inside a paragraph or label.
|
|
292
|
-
function leadingCheckbox(item) {
|
|
293
|
-
let node = item;
|
|
294
|
-
for (;;) {
|
|
295
|
-
const first = [...node.childNodes].find((child) => child.nodeType !== Node.COMMENT_NODE &&
|
|
296
|
-
!(child.nodeType === Node.TEXT_NODE && !child.textContent?.trim()));
|
|
297
|
-
if (first?.nodeType !== Node.ELEMENT_NODE)
|
|
298
|
-
return undefined;
|
|
299
|
-
const element = first;
|
|
300
|
-
if (element.tagName === 'INPUT')
|
|
301
|
-
return element.getAttribute('type')?.toLowerCase() === 'checkbox'
|
|
302
|
-
? element
|
|
303
|
-
: undefined;
|
|
304
|
-
if (!['P', 'LABEL', 'DIV', 'SPAN'].includes(element.tagName))
|
|
305
|
-
return undefined;
|
|
306
|
-
node = element;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
function markTask(item) {
|
|
310
|
-
const checkbox = leadingCheckbox(item);
|
|
311
|
-
if (!checkbox)
|
|
312
|
-
return;
|
|
313
|
-
item.setAttribute('data-item-type', 'task');
|
|
314
|
-
item.setAttribute('data-checked', String(checkbox.hasAttribute('checked')));
|
|
315
|
-
checkbox.remove();
|
|
316
|
-
}
|
|
317
|
-
const inline = new Set([
|
|
318
|
-
'STRONG',
|
|
319
|
-
'MARK',
|
|
320
|
-
'B',
|
|
321
|
-
'EM',
|
|
322
|
-
'I',
|
|
323
|
-
'S',
|
|
324
|
-
'DEL',
|
|
325
|
-
'STRIKE',
|
|
326
|
-
'A',
|
|
327
|
-
'SPAN',
|
|
328
|
-
'SUP',
|
|
329
|
-
'FONT',
|
|
330
|
-
]);
|
|
331
|
-
const space = /[ \t\r\n\f]+/g;
|
|
332
|
-
/**
|
|
333
|
-
* Collapses source whitespace the way a browser renders it: runs become one
|
|
334
|
-
* space, and none remains at the edges of a block or beside a line break.
|
|
335
|
-
* `pre`, `code`, elements that stay literal source and elements whose style
|
|
336
|
-
* keeps whitespace are not entered.
|
|
337
|
-
*/
|
|
338
|
-
export function collapseClipboardWhitespace(root) {
|
|
339
|
-
hoistEdgeSpace(root);
|
|
340
|
-
let trailing;
|
|
341
|
-
let start = true;
|
|
342
|
-
const trim = () => {
|
|
343
|
-
if (!trailing)
|
|
344
|
-
return;
|
|
345
|
-
trailing.data = trailing.data.slice(0, -1);
|
|
346
|
-
if (!trailing.data)
|
|
347
|
-
trailing.remove();
|
|
348
|
-
trailing = undefined;
|
|
349
|
-
};
|
|
350
|
-
const visit = (node) => {
|
|
351
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
352
|
-
const text = node;
|
|
353
|
-
let data = text.data.replace(space, ' ');
|
|
354
|
-
if ((start || trailing) && data.startsWith(' '))
|
|
355
|
-
data = data.slice(1);
|
|
356
|
-
if (!data)
|
|
357
|
-
return text.remove();
|
|
358
|
-
text.data = data;
|
|
359
|
-
start = false;
|
|
360
|
-
trailing = data.endsWith(' ') ? text : undefined;
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
364
|
-
return;
|
|
365
|
-
const element = node;
|
|
366
|
-
const tag = element.tagName;
|
|
367
|
-
if (keepsWhitespace(element)) {
|
|
368
|
-
// Treated like `code` inside a line and like `pre` as a block.
|
|
369
|
-
if (inline.has(tag) || tag === 'CODE' || tag === 'IMG') {
|
|
370
|
-
trailing = undefined;
|
|
371
|
-
start = false;
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
trim();
|
|
375
|
-
start = true;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
else if (inline.has(tag)) {
|
|
379
|
-
for (const child of [...element.childNodes])
|
|
380
|
-
visit(child);
|
|
381
|
-
}
|
|
382
|
-
else if (tag === 'BR') {
|
|
383
|
-
trim();
|
|
384
|
-
start = true;
|
|
385
|
-
}
|
|
386
|
-
else if (tag === 'CODE' || tag === 'IMG') {
|
|
387
|
-
trailing = undefined;
|
|
388
|
-
start = false;
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
trim();
|
|
392
|
-
start = true;
|
|
393
|
-
if (blocks.has(tag) && tag !== 'PRE' && tag !== 'HR')
|
|
394
|
-
for (const child of [...element.childNodes])
|
|
395
|
-
visit(child);
|
|
396
|
-
trim();
|
|
397
|
-
start = true;
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
for (const child of [...root.childNodes])
|
|
401
|
-
visit(child);
|
|
402
|
-
trim();
|
|
403
|
-
}
|
|
404
|
-
// Whitespace inside emphasis, links and similar wrappers cannot be written in
|
|
405
|
-
// Markdown, so it moves outside them.
|
|
406
|
-
function hoistEdgeSpace(node) {
|
|
407
|
-
for (const child of [...node.childNodes]) {
|
|
408
|
-
if (child.nodeType !== Node.ELEMENT_NODE)
|
|
409
|
-
continue;
|
|
410
|
-
const element = child;
|
|
411
|
-
if (keepsWhitespace(element))
|
|
412
|
-
continue;
|
|
413
|
-
if (inline.has(element.tagName)) {
|
|
414
|
-
hoistEdgeSpace(element);
|
|
415
|
-
const lead = edgeText(element, 'start');
|
|
416
|
-
const leading = lead?.data.match(/^[ \t\r\n\f]+/)?.[0];
|
|
417
|
-
if (lead && leading) {
|
|
418
|
-
lead.data = lead.data.slice(leading.length);
|
|
419
|
-
element.before(leading);
|
|
420
|
-
}
|
|
421
|
-
const tail = edgeText(element, 'end');
|
|
422
|
-
const trailing = tail?.data.match(/[ \t\r\n\f]+$/)?.[0];
|
|
423
|
-
if (tail && trailing) {
|
|
424
|
-
tail.data = tail.data.slice(0, -trailing.length);
|
|
425
|
-
element.after(trailing);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
else if (blocks.has(element.tagName) && element.tagName !== 'PRE')
|
|
429
|
-
hoistEdgeSpace(element);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
function edgeText(element, side) {
|
|
433
|
-
let node = side === 'start' ? element.firstChild : element.lastChild;
|
|
434
|
-
while (node && node.nodeType === Node.ELEMENT_NODE) {
|
|
435
|
-
if (!inline.has(node.tagName) ||
|
|
436
|
-
keepsWhitespace(node))
|
|
437
|
-
return undefined;
|
|
438
|
-
node = side === 'start' ? node.firstChild : node.lastChild;
|
|
439
|
-
}
|
|
440
|
-
return node?.nodeType === Node.TEXT_NODE ? node : undefined;
|
|
441
|
-
}
|
package/dist/paste.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Ctx } from '@milkdown/kit/ctx';
|
|
2
|
-
import { type ClipboardInput, type DocumentContext, type ImageAdapter } from './types.js';
|
|
3
|
-
export interface PasteControllerOptions {
|
|
4
|
-
ctx: () => Ctx;
|
|
5
|
-
context: () => DocumentContext;
|
|
6
|
-
adapter?: ImageAdapter;
|
|
7
|
-
onError?: (error: unknown) => void;
|
|
8
|
-
onPendingChanged?: () => void;
|
|
9
|
-
editable?: () => boolean;
|
|
10
|
-
literalText?: () => boolean;
|
|
11
|
-
}
|
|
12
|
-
export declare class PasteController {
|
|
13
|
-
private readonly options;
|
|
14
|
-
private active?;
|
|
15
|
-
private readonly key;
|
|
16
|
-
private dead;
|
|
17
|
-
get pending(): boolean;
|
|
18
|
-
readonly plugin: import("@milkdown/kit/utils").$Prose;
|
|
19
|
-
constructor(options: PasteControllerOptions);
|
|
20
|
-
paste(input: ClipboardInput): Promise<void>;
|
|
21
|
-
private anchor;
|
|
22
|
-
cancelPending(): void;
|
|
23
|
-
destroy(): void;
|
|
24
|
-
private assertContext;
|
|
25
|
-
private run;
|
|
26
|
-
}
|