markloom 0.5.1 → 0.7.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 (73) hide show
  1. package/PACKAGES.md +26 -0
  2. package/README.md +20 -2
  3. package/collab.md +60 -13
  4. package/dist/ai/index.cjs +5 -4
  5. package/dist/ai/index.d.cts +5 -4
  6. package/dist/ai/index.d.ts +5 -4
  7. package/dist/ai/index.js +4 -3
  8. package/dist/ai/theme.css +66 -102
  9. package/dist/{chunk-ZMTLSFLO.js → chunk-4Q7PAR2T.js} +5746 -1341
  10. package/dist/chunk-75EJ4ARB.cjs +642 -0
  11. package/dist/{chunk-JS527FDV.cjs → chunk-BMPCVT3B.cjs} +47 -39
  12. package/dist/{chunk-RLTHVQNQ.js → chunk-EFYT2223.js} +47 -39
  13. package/dist/chunk-HXABDVLZ.cjs +297 -0
  14. package/dist/{chunk-YIFOGP2D.cjs → chunk-I2LDEVLA.cjs} +499 -102
  15. package/dist/chunk-MQLRZQZL.js +642 -0
  16. package/dist/chunk-OVHASRID.cjs +4279 -0
  17. package/dist/chunk-PCSVBPOR.cjs +40 -0
  18. package/dist/{chunk-FCH7LZFI.js → chunk-PSAXWBNM.js} +450 -53
  19. package/dist/chunk-PZRWTLLB.cjs +858 -0
  20. package/dist/chunk-QO7JEZDB.js +4279 -0
  21. package/dist/chunk-WSJUXPAG.js +40 -0
  22. package/dist/{chunk-VXM7Q6P5.cjs → chunk-Y4IXQFWL.cjs} +6026 -1621
  23. package/dist/chunk-YLVSMDIO.js +858 -0
  24. package/dist/chunk-ZL6WT6OY.js +297 -0
  25. package/dist/client-BvvyHjhh.d.ts +250 -0
  26. package/dist/client-Ciy7Fa_k.d.cts +250 -0
  27. package/dist/collab/index.cjs +17 -4
  28. package/dist/collab/index.d.cts +18 -7
  29. package/dist/collab/index.d.ts +18 -7
  30. package/dist/collab/index.js +19 -6
  31. package/dist/{controller-DQITsFhy.d.cts → controller-CHznEhAR.d.cts} +277 -26
  32. package/dist/{controller-BNuuUM3E.d.ts → controller-DLqI8_jm.d.ts} +277 -26
  33. package/dist/index.cjs +119 -7
  34. package/dist/index.d.cts +138 -6
  35. package/dist/index.d.ts +138 -6
  36. package/dist/index.js +130 -18
  37. package/dist/io/index.cjs +1412 -0
  38. package/dist/io/index.d.cts +33 -0
  39. package/dist/io/index.d.ts +33 -0
  40. package/dist/io/index.js +1412 -0
  41. package/dist/react/index.cjs +9 -8
  42. package/dist/react/index.d.cts +5 -4
  43. package/dist/react/index.d.ts +5 -4
  44. package/dist/react/index.js +8 -7
  45. package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-CSnv8FKp.d.ts} +11 -9
  46. package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-DO1ygkx9.d.cts} +11 -9
  47. package/dist/types-BkHlmUFL.d.cts +34 -0
  48. package/dist/types-BkHlmUFL.d.ts +34 -0
  49. package/dist/versions-DNFf8zVz.d.cts +51 -0
  50. package/dist/versions-DOkOyh2J.d.ts +51 -0
  51. package/dist/view/index.cjs +259 -17
  52. package/dist/view/index.d.cts +277 -12
  53. package/dist/view/index.d.ts +277 -12
  54. package/dist/view/index.js +256 -14
  55. package/dist/view/theme.css +2093 -1577
  56. package/dist/word-count-BPw9G2Bg.d.ts +130 -0
  57. package/dist/word-count-DNLn1h_t.d.cts +130 -0
  58. package/io.md +38 -0
  59. package/package.json +25 -4
  60. package/dist/chunk-4JSJAHTB.js +0 -255
  61. package/dist/chunk-4TMHVNL6.cjs +0 -2297
  62. package/dist/chunk-ALZ3A5CS.cjs +0 -255
  63. package/dist/chunk-GQ2HHRGI.cjs +0 -16
  64. package/dist/chunk-LA5SBCGQ.js +0 -16
  65. package/dist/chunk-LEYAQNJA.js +0 -220
  66. package/dist/chunk-MFYF2A6U.js +0 -2297
  67. package/dist/chunk-YXQDCW4Y.cjs +0 -220
  68. package/dist/client-6KiH4kGK.d.ts +0 -144
  69. package/dist/client-ZRZj2nkq.d.cts +0 -144
  70. package/dist/comments-DlExS6f-.d.cts +0 -43
  71. package/dist/comments-PhnR7Gkn.d.ts +0 -43
  72. package/dist/step-BrvHIK7O.d.cts +0 -65
  73. package/dist/step-BrvHIK7O.d.ts +0 -65
@@ -2,23 +2,34 @@ import {
2
2
  CALLOUT_VARIANTS,
3
3
  CommentPanel,
4
4
  Editor,
5
+ INLINE_PAIRS,
5
6
  MentionMenu,
6
7
  MentionPopovers,
8
+ SearchBar,
9
+ SuggestBar,
7
10
  TocPanel,
11
+ VersionsPanel,
8
12
  askInput,
9
13
  askLinkPopover,
14
+ askPopover,
10
15
  atomIsSelected,
16
+ autofocusSelection,
11
17
  blockExtensions,
12
18
  blockTransform,
19
+ blockTransformRange,
13
20
  boldMark,
14
21
  bubbleMenu,
15
22
  calloutVariantFromQuery,
16
23
  caret,
17
24
  chord,
25
+ clearFormatting,
26
+ clearMarks,
27
+ clipboardFromDataTransfer,
18
28
  closeAskInput,
19
29
  codeBlock,
20
30
  codeControls,
21
31
  codeMark,
32
+ createDragHandle,
22
33
  cycleCalloutVariant,
23
34
  decorationExtensions,
24
35
  defaultBlockRenderers,
@@ -27,29 +38,49 @@ import {
27
38
  diffSpan,
28
39
  dragHandle,
29
40
  embedBlock,
41
+ emptyGapPara,
42
+ ensureGaps,
43
+ expandToLink,
44
+ gapSteps,
30
45
  highlightMark,
31
46
  history,
32
47
  hrBlock,
48
+ htmlToPlainText,
33
49
  imageBlock,
50
+ imageFileFrom,
34
51
  indentItem,
52
+ inlinePairRule,
35
53
  inputRules,
36
54
  isAtom,
55
+ isBareUrl,
56
+ isCellBlockKind,
37
57
  isOpaque,
58
+ isSafeLinkUrl,
38
59
  italicMark,
60
+ joinPrevList,
61
+ keepsApart,
62
+ leafBlockPath,
39
63
  leafText,
40
64
  lineBoundaryBack,
41
65
  lineBoundaryFwd,
42
66
  linkMark,
67
+ linkTip,
43
68
  mapInput,
44
69
  mapPaste,
45
70
  mapPasteBlocks,
46
71
  markExtensions,
72
+ markdownLinkRule,
47
73
  markloomKit,
48
74
  marksAtCaret,
75
+ matchInlinePair,
49
76
  mentionMenu,
50
77
  mergeTextStyleAttrs,
78
+ nearestListPath,
51
79
  normalizeLinkUrl,
52
80
  outdentItem,
81
+ parseTypedLink,
82
+ parseTypedUrl,
83
+ projectDoc,
53
84
  renderCode,
54
85
  renderDoc,
55
86
  renderEmbed,
@@ -58,44 +89,84 @@ import {
58
89
  renderTable,
59
90
  renderToHtml,
60
91
  resolve,
61
- safeCssValue,
92
+ resolvePaste,
93
+ serializeBlock,
62
94
  serializeSelection,
63
95
  setAlign,
64
96
  setCalloutVariant,
97
+ setHeadingDepth,
98
+ setListType,
65
99
  setTextStyle,
66
100
  slashMenu,
101
+ soloImgFromHtml,
102
+ soloImgSrcFromHtml,
67
103
  strikeMark,
68
104
  subscriptMark,
105
+ suggest,
69
106
  superscriptMark,
107
+ tableAbove,
70
108
  tableBlock,
71
109
  textAlign,
72
110
  textStyleCss,
73
111
  textStyleMark,
74
112
  toggleMark,
75
113
  toggleMarkList,
114
+ tryEmbed,
115
+ tryHtmlBlocks,
116
+ tryImageFile,
117
+ tryImageUrl,
118
+ tryLinkMark,
119
+ tryLiteral,
120
+ tryMarkdown,
76
121
  twitchChannel,
77
122
  underlineMark,
123
+ urlAutolink,
124
+ urlAutolinkRule,
78
125
  wordBoundaryBack,
79
126
  wordBoundaryFwd,
80
127
  wrapList,
81
128
  youtubeId
82
- } from "../chunk-ZMTLSFLO.js";
83
- import "../chunk-LEYAQNJA.js";
129
+ } from "../chunk-4Q7PAR2T.js";
130
+ import "../chunk-YLVSMDIO.js";
84
131
  import {
132
+ SELECT_UNIT_TYPES,
85
133
  blockPlainText,
134
+ docExtent,
86
135
  domToPoint,
87
136
  elementChildren,
137
+ expandSelectAll,
88
138
  focusBlockId,
139
+ getLocale,
140
+ invalidateStructure,
141
+ isProgressiveSelectUnit,
142
+ isSelectUnit,
143
+ isSelectUnitType,
144
+ nodeExtent,
89
145
  pointToDom,
146
+ progressiveUnitPaths,
90
147
  readSelection,
91
148
  rootEl,
149
+ selectUnitPath,
150
+ selectionCovers,
151
+ setLocale,
92
152
  startAiWrite,
153
+ t,
93
154
  writeSelection
94
- } from "../chunk-FCH7LZFI.js";
95
- import "../chunk-MFYF2A6U.js";
96
- import "../chunk-4JSJAHTB.js";
97
- import "../chunk-RLTHVQNQ.js";
98
- import "../chunk-LA5SBCGQ.js";
155
+ } from "../chunk-PSAXWBNM.js";
156
+ import {
157
+ mdToDoc,
158
+ mdToDocAsync,
159
+ safeCssValue,
160
+ yieldToMain
161
+ } from "../chunk-QO7JEZDB.js";
162
+ import "../chunk-MQLRZQZL.js";
163
+ import "../chunk-EFYT2223.js";
164
+ import {
165
+ nodeAt
166
+ } from "../chunk-ZL6WT6OY.js";
167
+ import {
168
+ isText
169
+ } from "../chunk-WSJUXPAG.js";
99
170
 
100
171
  // src/view/shiki-code-view.ts
101
172
  import { h } from "preact";
@@ -111,9 +182,9 @@ function shikiCodeView(highlight, langs) {
111
182
  // 标记:此叶是多 text 节点拼接,selection 按全文 offset 走
112
183
  "dangerouslySetInnerHTML": { __html: anchorEmptyLines(highlight(ctx.text, lang)) }
113
184
  });
114
- const copy = h("button", { "key": "copy", "data-copy": "", "type": "button", "contentEditable": "false", "tabIndex": -1, "aria-label": "\u590D\u5236\u4EE3\u7801" });
115
- const langBtn = h("button", { "key": "lang", "data-code-lang": "", "type": "button", "contentEditable": "false", "tabIndex": -1 }, lang || "\u7EAF\u6587\u672C");
116
- return h("div", { "key": ctx.key, "data-block-id": ctx.node.id ?? "", "data-code-block": "" }, [langBtn, copy, leaf]);
185
+ const copy = h("button", { "key": "copy", "data-copy": "", "type": "button", "contentEditable": "false", "tabIndex": -1, "aria-label": t("copyCode") });
186
+ const langBtn = ctx.editable === false ? null : h("button", { "key": "lang", "data-code-lang": "", "type": "button", "contentEditable": "false", "tabIndex": -1 }, lang || t("plainText"));
187
+ return h("div", { "key": ctx.key, "data-block-id": ctx.node.id ?? "", "data-code-block": "", "spellcheck": "false" }, [langBtn, copy, leaf]);
117
188
  }
118
189
  };
119
190
  }
@@ -133,6 +204,63 @@ function anchorEmptyLines(html) {
133
204
  return pre.outerHTML;
134
205
  }
135
206
 
207
+ // src/view/open-async.ts
208
+ var ASYNC_MIN_BYTES = 48 * 1024;
209
+ async function openEditorAsync(root, md, opts = {}) {
210
+ const { budgetMs = 8, layoutMs = 25, headBlocks = 200, signal, ...eopts } = opts;
211
+ const source = eopts.source ?? md;
212
+ if (md.length < ASYNC_MIN_BYTES) {
213
+ const editor2 = new Editor(root, mdToDoc(md), { ...eopts, source });
214
+ return { editor: editor2, loaded: Promise.resolve(editor2.doc) };
215
+ }
216
+ let onHead;
217
+ const headP = new Promise((r) => {
218
+ onHead = r;
219
+ });
220
+ const fullP = mdToDocAsync(md, { budgetMs, headBlocks, onHead, signal });
221
+ const first = await Promise.race([headP, fullP]);
222
+ const wantEditable = eopts.editable !== false;
223
+ const editor = new Editor(root, first, { ...eopts, source, editable: false });
224
+ const loaded = (async () => {
225
+ try {
226
+ const doc = await fullP;
227
+ const total = doc.children.length;
228
+ let n = first.children.length;
229
+ let step = 128;
230
+ let perBlock = 0.05;
231
+ while (n < total) {
232
+ if (signal?.aborted)
233
+ throw Object.assign(new Error("openEditorAsync aborted"), { name: "AbortError" });
234
+ await yieldToMain();
235
+ const t0 = performance.now();
236
+ const take = Math.min(total - n, step);
237
+ n += take;
238
+ editor.replaceDoc({ ...doc, children: doc.children.slice(0, n) }, { notify: false, quiet: true });
239
+ const dt = performance.now() - t0;
240
+ perBlock = perBlock * 0.7 + dt / take * 0.3;
241
+ step = Math.max(128, Math.min(4096, Math.round(layoutMs / perBlock)));
242
+ }
243
+ editor.replaceDoc(doc, { notify: false });
244
+ if (wantEditable)
245
+ editor.setEditable(true);
246
+ if (eopts.autofocus != null && eopts.autofocus !== false && wantEditable) {
247
+ const sel = autofocusSelection(editor.doc, eopts.autofocus);
248
+ if (sel) {
249
+ root.focus({ preventScroll: true });
250
+ writeSelection(editor.root, editor.doc, sel);
251
+ }
252
+ }
253
+ return editor.doc;
254
+ } catch (e) {
255
+ editor.destroy();
256
+ throw e;
257
+ }
258
+ })();
259
+ loaded.catch(() => {
260
+ });
261
+ return { editor, loaded };
262
+ }
263
+
136
264
  // src/view/extensions/typography.ts
137
265
  var SUBS = [
138
266
  { trigger: "-", from: "--", to: "\u2014" },
@@ -149,10 +277,31 @@ var SUBS = [
149
277
  { trigger: "4", from: "1/4", to: "\xBC" },
150
278
  { trigger: "4", from: "3/4", to: "\xBE" }
151
279
  ];
280
+ function inLiteral(ctx) {
281
+ const leaf = nodeAt(ctx.doc, ctx.leafPath);
282
+ if (isText(leaf) && leaf.marks?.some((m) => m.name === "code" || m.name === "link"))
283
+ return true;
284
+ let ticks = 0;
285
+ for (const ch of ctx.marker) {
286
+ if (ch === "`")
287
+ ticks++;
288
+ }
289
+ if (ticks % 2 === 1)
290
+ return true;
291
+ let start = ctx.marker.length;
292
+ while (start > 0 && !/\s/.test(ctx.marker[start - 1]))
293
+ start--;
294
+ const word = ctx.marker.slice(start);
295
+ return word.includes("://") || word.startsWith("www.");
296
+ }
297
+ function isCjk(ch) {
298
+ const c = ch.codePointAt(0) ?? 0;
299
+ return c >= 11904 && c <= 40959 || c >= 44032 && c <= 55215 || c >= 63744 && c <= 64255 || c >= 65280 && c <= 65519 || c >= 131072 && c <= 195103;
300
+ }
152
301
  function subRule() {
153
302
  return {
154
303
  match: (ctx) => {
155
- if (ctx.block.type === "code")
304
+ if (ctx.block.type === "code" || inLiteral(ctx))
156
305
  return null;
157
306
  const combined = ctx.marker + ctx.trigger;
158
307
  for (const s of SUBS) {
@@ -162,6 +311,8 @@ function subRule() {
162
311
  const at = ctx.offset - eaten;
163
312
  if (at < 0)
164
313
  return null;
314
+ if (s.from === "--" && ctx.leafIdx === 0 && ctx.block.type === "paragraph" && [...combined].every((ch) => ch === "-"))
315
+ return null;
165
316
  const steps = [
166
317
  { kind: "deleteText", path: ctx.leafPath, offset: at, length: eaten },
167
318
  { kind: "insertText", path: ctx.leafPath, offset: at, text: s.to }
@@ -175,10 +326,22 @@ function subRule() {
175
326
  function quoteRule(quote, open, close) {
176
327
  return {
177
328
  match: (ctx) => {
178
- if (ctx.block.type === "code" || ctx.trigger !== quote)
329
+ if (ctx.block.type === "code" || ctx.trigger !== quote || inLiteral(ctx))
179
330
  return null;
180
331
  const prev = ctx.marker.slice(-1);
181
- const to = prev === "" || prev === " " || prev === "\n" || prev === " " || prev === "(" || prev === "[" || prev === "{" ? open : close;
332
+ let to;
333
+ if (prev === "" || prev === " " || prev === "\n" || prev === " " || prev === "(" || prev === "[" || prev === "{") {
334
+ to = open;
335
+ } else {
336
+ let depth = 0;
337
+ for (const ch of ctx.marker) {
338
+ if (ch === open)
339
+ depth++;
340
+ else if (ch === close && depth > 0)
341
+ depth--;
342
+ }
343
+ to = depth > 0 ? close : isCjk(prev) ? open : close;
344
+ }
182
345
  const steps = [{ kind: "insertText", path: ctx.leafPath, offset: ctx.offset, text: to }];
183
346
  return { steps, selection: caret(ctx.leafPath.concat(ctx.offset + to.length)) };
184
347
  }
@@ -273,66 +436,124 @@ var comments = {
273
436
  name: "comments",
274
437
  marks: [{ name: "comment", tag: "span" }]
275
438
  };
439
+
440
+ // src/view/extensions/typora-keys.ts
441
+ var level = (depth) => (ctx) => ctx.sel ? setHeadingDepth(ctx.doc, ctx.sel, depth) : null;
442
+ var typoraKeys = {
443
+ name: "typoraKeys",
444
+ keymap: {
445
+ "Mod-0": level(0),
446
+ "Mod-1": level(1),
447
+ "Mod-2": level(2),
448
+ "Mod-3": level(3),
449
+ "Mod-4": level(4),
450
+ "Mod-5": level(5),
451
+ "Mod-6": level(6)
452
+ }
453
+ };
276
454
  export {
455
+ ASYNC_MIN_BYTES,
277
456
  CALLOUT_VARIANTS,
278
457
  CommentPanel,
279
458
  Editor,
459
+ INLINE_PAIRS,
280
460
  MentionMenu,
281
461
  MentionPopovers,
462
+ SELECT_UNIT_TYPES,
463
+ SearchBar,
464
+ SuggestBar,
282
465
  TocPanel,
466
+ VersionsPanel,
283
467
  askInput,
284
468
  askLinkPopover,
469
+ askPopover,
285
470
  atomIsSelected,
471
+ autofocusSelection,
286
472
  blockExtensions,
287
473
  blockPlainText,
288
474
  blockTransform,
475
+ blockTransformRange,
289
476
  boldMark,
290
477
  bubbleMenu,
291
478
  calloutVariantFromQuery,
292
479
  caret,
293
480
  chord,
481
+ clearFormatting,
482
+ clearMarks,
483
+ clipboardFromDataTransfer,
294
484
  closeAskInput,
295
485
  codeBlock,
296
486
  codeControls,
297
487
  codeMark,
298
488
  comments,
489
+ createDragHandle,
299
490
  cycleCalloutVariant,
300
491
  decorationExtensions,
301
492
  defaultBlockRenderers,
302
493
  defaultBlockTag,
303
494
  defaultMarkTag,
304
495
  diffSpan,
496
+ docExtent,
305
497
  domToPoint,
306
498
  dragHandle,
307
499
  elementChildren,
308
500
  embedBlock,
309
501
  emoji,
502
+ emptyGapPara,
503
+ ensureGaps,
504
+ expandSelectAll,
505
+ expandToLink,
310
506
  focusBlockId,
507
+ gapSteps,
508
+ getLocale,
311
509
  highlightMark,
312
510
  history,
313
511
  hrBlock,
512
+ htmlToPlainText,
314
513
  imageBlock,
514
+ imageFileFrom,
315
515
  indentItem,
516
+ inlinePairRule,
316
517
  inputRules,
518
+ invalidateStructure,
317
519
  invisibleCharacters,
318
520
  isAtom,
521
+ isBareUrl,
522
+ isCellBlockKind,
319
523
  isOpaque,
524
+ isProgressiveSelectUnit,
525
+ isSafeLinkUrl,
526
+ isSelectUnit,
527
+ isSelectUnitType,
320
528
  italicMark,
529
+ joinPrevList,
530
+ keepsApart,
531
+ leafBlockPath,
321
532
  leafText,
322
533
  lineBoundaryBack,
323
534
  lineBoundaryFwd,
324
535
  linkMark,
536
+ linkTip,
325
537
  mapInput,
326
538
  mapPaste,
327
539
  mapPasteBlocks,
328
540
  markExtensions,
541
+ markdownLinkRule,
329
542
  markloomKit,
330
543
  marksAtCaret,
544
+ matchInlinePair,
331
545
  mentionMenu,
332
546
  mergeTextStyleAttrs,
547
+ nearestListPath,
548
+ nodeExtent,
333
549
  normalizeLinkUrl,
550
+ openEditorAsync,
334
551
  outdentItem,
552
+ parseTypedLink,
553
+ parseTypedUrl,
335
554
  pointToDom,
555
+ progressiveUnitPaths,
556
+ projectDoc,
336
557
  readSelection,
337
558
  renderCode,
338
559
  renderDoc,
@@ -342,27 +563,48 @@ export {
342
563
  renderTable,
343
564
  renderToHtml,
344
565
  resolve,
566
+ resolvePaste,
345
567
  rootEl,
346
568
  safeCssValue,
569
+ selectUnitPath,
570
+ selectionCovers,
571
+ serializeBlock,
347
572
  serializeSelection,
348
573
  setAlign,
349
574
  setCalloutVariant,
575
+ setHeadingDepth,
576
+ setListType,
577
+ setLocale,
350
578
  setTextStyle,
351
579
  shikiCodeView,
352
580
  slashMenu,
581
+ soloImgFromHtml,
582
+ soloImgSrcFromHtml,
353
583
  startAiWrite,
354
584
  strikeMark,
355
585
  subscriptMark,
586
+ suggest,
356
587
  superscriptMark,
588
+ tableAbove,
357
589
  tableBlock,
358
590
  textAlign,
359
591
  textStyleCss,
360
592
  textStyleMark,
361
593
  toggleMark,
362
594
  toggleMarkList,
595
+ tryEmbed,
596
+ tryHtmlBlocks,
597
+ tryImageFile,
598
+ tryImageUrl,
599
+ tryLinkMark,
600
+ tryLiteral,
601
+ tryMarkdown,
363
602
  twitchChannel,
364
603
  typography,
604
+ typoraKeys,
365
605
  underlineMark,
606
+ urlAutolink,
607
+ urlAutolinkRule,
366
608
  wordBoundaryBack,
367
609
  wordBoundaryFwd,
368
610
  wrapList,