@textbus/xnote 0.0.1-alpha.9 → 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.
Files changed (43) hide show
  1. package/README.md +103 -1
  2. package/bundles/components/_api.d.ts +2 -0
  3. package/bundles/components/dropdown/dropdown-menu.d.ts +4 -1
  4. package/bundles/components/dropdown/dropdown.d.ts +3 -1
  5. package/bundles/components/keymap/keymap.d.ts +5 -0
  6. package/bundles/components/menu-heading/menu-heading.d.ts +2 -0
  7. package/bundles/components/menu-item/menu-item.d.ts +2 -1
  8. package/bundles/components/popup/popup.d.ts +1 -1
  9. package/bundles/fonts/textbus.svg +3 -32
  10. package/bundles/fonts/textbus.ttf +0 -0
  11. package/bundles/fonts/textbus.woff +0 -0
  12. package/bundles/index.css +2 -2
  13. package/bundles/index.esm.css +2 -2
  14. package/bundles/index.esm.js +1586 -677
  15. package/bundles/index.js +1597 -672
  16. package/bundles/plugins/_api.d.ts +1 -0
  17. package/bundles/plugins/_common/attr.tool.d.ts +2 -2
  18. package/bundles/plugins/_common/color.tool.d.ts +2 -2
  19. package/bundles/plugins/left-toolbar/insert-tool.d.ts +1 -0
  20. package/bundles/plugins/link-jump/link-jump.d.ts +4 -0
  21. package/bundles/public-api.d.ts +1 -0
  22. package/bundles/services/editor.service.d.ts +4 -0
  23. package/bundles/textbus/components/SlotRender.d.ts +14 -0
  24. package/bundles/textbus/components/_api.d.ts +3 -0
  25. package/bundles/textbus/components/at/at-component.view.d.ts +6 -0
  26. package/bundles/textbus/components/at/at.component.d.ts +35 -0
  27. package/bundles/textbus/components/blockqoute/blockquote.component.d.ts +4 -1
  28. package/bundles/textbus/components/highlight-box/highlight-box.component.d.ts +1 -0
  29. package/bundles/textbus/components/image/image.component.d.ts +2 -1
  30. package/bundles/textbus/components/katex/katex-editor.d.ts +7 -0
  31. package/bundles/textbus/components/katex/katex.component.d.ts +16 -0
  32. package/bundles/textbus/components/list/list.component.d.ts +3 -0
  33. package/bundles/textbus/components/paragraph/paragraph.component.d.ts +1 -0
  34. package/bundles/textbus/components/root/root.component.d.ts +2 -0
  35. package/bundles/textbus/components/source-code/source-code.component.d.ts +2 -1
  36. package/bundles/textbus/components/table/components/resize-column.d.ts +2 -1
  37. package/bundles/textbus/components/table/components/scroll.d.ts +1 -2
  38. package/bundles/textbus/components/table/components/top-bar.d.ts +2 -2
  39. package/bundles/textbus/components/table/table-selection-awareness-delegate.d.ts +15 -0
  40. package/bundles/textbus/components/table/table.component.d.ts +1 -1
  41. package/bundles/textbus/components/todolist/todolist.component.d.ts +1 -0
  42. package/bundles/textbus/components/video/video.component.d.ts +1 -1
  43. package/package.json +35 -11
package/bundles/index.js CHANGED
@@ -8,10 +8,12 @@ var platformBrowser = require('@textbus/platform-browser');
8
8
  var platformBrowser$1 = require('@viewfly/platform-browser');
9
9
  var hooks = require('@viewfly/hooks');
10
10
  var highlightjs = require('highlight.js');
11
+ var Katex = require('katex');
11
12
  var adapterViewfly = require('@textbus/adapter-viewfly');
13
+ var color = require('@tanbo/color');
12
14
  var collaborate = require('@textbus/collaborate');
13
15
 
14
- var scopedId$k = "vf-3d0183";
16
+ var scopedId$n = "vf-d94b56";
15
17
 
16
18
  /******************************************************************************
17
19
  Copyright (c) Microsoft Corporation.
@@ -30,6 +32,18 @@ PERFORMANCE OF THIS SOFTWARE.
30
32
  /* global Reflect, Promise, SuppressedError, Symbol */
31
33
 
32
34
 
35
+ function __rest(s, e) {
36
+ var t = {};
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
+ t[p] = s[p];
39
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
+ t[p[i]] = s[p[i]];
43
+ }
44
+ return t;
45
+ }
46
+
33
47
  function __decorate(decorators, target, key, desc) {
34
48
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
49
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -73,7 +87,7 @@ exports.DropdownContextService = DropdownContextService_1 = class DropdownContex
73
87
  this.canHide = true;
74
88
  this.openStateChangeEvent = new core$1.Subject();
75
89
  this.timer = null;
76
- this.parentDropdownContextService = this.injector.get(DropdownContextService_1, core.InjectFlags.SkipSelf, null);
90
+ this.parentDropdownContextService = this.injector.get(DropdownContextService_1, null, core.InjectFlags.SkipSelf);
77
91
  this.onOpenStateChange = this.openStateChangeEvent.asObservable();
78
92
  dropdownService.onSiblingOpen.subscribe(id => {
79
93
  if (id === this.id) {
@@ -122,7 +136,7 @@ exports.DropdownContextService = DropdownContextService_1 = __decorate([
122
136
  ], exports.DropdownContextService);
123
137
 
124
138
  function Button(props) {
125
- const dropdownContextService = core.inject(exports.DropdownContextService, core.InjectFlags.Optional, null);
139
+ const dropdownContextService = core.inject(exports.DropdownContextService, null);
126
140
  const isActive = core.createSignal((dropdownContextService === null || dropdownContextService === void 0 ? void 0 : dropdownContextService.isOpen) || false);
127
141
  if (dropdownContextService) {
128
142
  const subscription = dropdownContextService.onOpenStateChange.subscribe(b => {
@@ -132,7 +146,7 @@ function Button(props) {
132
146
  subscription.unsubscribe();
133
147
  });
134
148
  }
135
- return scopedCss.withScopedCSS(scopedId$k, () => {
149
+ return scopedCss.withScopedCSS(scopedId$n, () => {
136
150
  return (jsxRuntime.jsxs("button", Object.assign({ type: "button" }, props, { class: [
137
151
  'btn',
138
152
  {
@@ -144,10 +158,10 @@ function Button(props) {
144
158
  });
145
159
  }
146
160
 
147
- var scopedId$j = "vf-ac7e8d";
161
+ var scopedId$m = "vf-ac7e8d";
148
162
 
149
163
  function ComponentToolbar(props) {
150
- return scopedCss.withScopedCSS(scopedId$j, () => {
164
+ return scopedCss.withScopedCSS(scopedId$m, () => {
151
165
  return (jsxRuntime.jsx("div", { class: "component-toolbar", style: props.style, children: jsxRuntime.jsx("div", { class: [
152
166
  'toolbar',
153
167
  {
@@ -157,15 +171,15 @@ function ComponentToolbar(props) {
157
171
  });
158
172
  }
159
173
 
160
- var scopedId$i = "vf-ede279";
174
+ var scopedId$l = "vf-ede279";
161
175
 
162
176
  function Divider() {
163
- return scopedCss.withScopedCSS(scopedId$i, () => {
177
+ return scopedCss.withScopedCSS(scopedId$l, () => {
164
178
  return jsxRuntime.jsx("div", { class: "divider" });
165
179
  });
166
180
  }
167
181
 
168
- var scopedId$h = "vf-4c1803";
182
+ var scopedId$k = "vf-8abf2c";
169
183
 
170
184
  function DragResize(props) {
171
185
  const isShow = core.createSignal(false);
@@ -186,7 +200,7 @@ function DragResize(props) {
186
200
  isShow.set(true);
187
201
  const width = ref.current.offsetWidth;
188
202
  const height = ref.current.offsetHeight;
189
- mask.current.innerText = `${Math.round(width)}px * ${Math.round(height)}px`;
203
+ sizeText.set(`${Math.round(width)}px * ${Math.round(height)}px`);
190
204
  });
191
205
  function selectComponent() {
192
206
  selection.selectComponent(component, true);
@@ -263,7 +277,7 @@ function DragResize(props) {
263
277
  }
264
278
  ele.style.width = endWidth + 'px';
265
279
  ele.style.height = endHeight + 'px';
266
- mask.current.innerText = `${Math.round(endWidth)}px * ${Math.round(endHeight)}px`;
280
+ sizeText.set(`${Math.round(endWidth)}px * ${Math.round(endHeight)}px`);
267
281
  });
268
282
  const unUp = core$1.fromEvent(document, 'mouseup').subscribe(() => {
269
283
  component.state.width = endWidth + 'px';
@@ -273,16 +287,17 @@ function DragResize(props) {
273
287
  unUp.unsubscribe();
274
288
  });
275
289
  }
276
- return scopedCss.withScopedCSS(scopedId$h, () => {
290
+ const sizeText = core.createSignal(`${component.state.width}*${component.state.height}`);
291
+ return scopedCss.withScopedCSS(scopedId$k, () => {
277
292
  return (jsxRuntime.jsxs("div", { class: "drag-resize", onClick: selectComponent, children: [jsxRuntime.jsx("div", { class: "container", ref: ref, children: props.children }), jsxRuntime.jsxs("div", { class: ['resize-tool', {
278
293
  active: isShow()
279
- }], children: [jsxRuntime.jsxs("div", { class: "mask", ref: mask, children: [component.state.width, "*", component.state.height] }), jsxRuntime.jsxs("div", { class: "btn-group", ref: btnGroup, onMousedown: drag, children: [jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" })] })] })] }));
294
+ }], children: [jsxRuntime.jsx("div", { class: "mask", ref: mask, children: sizeText() }), jsxRuntime.jsxs("div", { class: "btn-group", ref: btnGroup, onMousedown: drag, children: [jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" }), jsxRuntime.jsx("button", { type: "button" })] })] })] }));
280
295
  });
281
296
  }
282
297
 
283
- var scopedId$g = "vf-a99c5e";
298
+ var scopedId$j = "vf-a99c5e";
284
299
 
285
- var scopedId$f = "vf-41a617";
300
+ var scopedId$i = "vf-8a05e9";
286
301
 
287
302
  const DropdownMenuPortal = core.withAnnotation({
288
303
  providers: [
@@ -290,11 +305,14 @@ const DropdownMenuPortal = core.withAnnotation({
290
305
  ]
291
306
  }, function DropdownMenuPortal(props) {
292
307
  const dropdownContextService = core.inject(exports.DropdownContextService);
308
+ const container = core.inject(platformBrowser.VIEW_CONTAINER);
293
309
  const menuRef = core.createRef();
294
310
  let timer = null;
295
311
  const delay = 10;
296
- core.onMounted(() => {
312
+ function update() {
297
313
  const menuElement = menuRef.current;
314
+ menuElement.style.height = 'auto';
315
+ const containerRect = container.getBoundingClientRect();
298
316
  if (props.abreast) {
299
317
  const btnEle = props.triggerRef.current;
300
318
  const screenHeight = document.documentElement.clientHeight;
@@ -309,19 +327,19 @@ const DropdownMenuPortal = core.withAnnotation({
309
327
  else if (offsetTop + maxHeight > screenHeight - 10) {
310
328
  offsetTop = screenHeight - 10 - maxHeight;
311
329
  }
312
- menuElement.style.top = offsetTop + 'px';
330
+ menuElement.style.top = offsetTop - containerRect.top + 'px';
313
331
  const triggerRect = props.triggerRef.current.getBoundingClientRect();
314
332
  const leftDistance = triggerRect.left;
315
333
  const isToLeft = leftDistance >= menuElement.offsetWidth + 20;
316
- if (isToLeft) {
317
- menuElement.style.left = leftDistance - menuElement.offsetWidth - 20 + 'px';
334
+ if (isToLeft && props.toLeft) {
335
+ menuElement.style.left = leftDistance - menuElement.offsetWidth - 20 - containerRect.left + 'px';
318
336
  timer = setTimeout(() => {
319
337
  menuElement.style.transform = 'translateX(10px)';
320
338
  menuElement.style.opacity = '1';
321
339
  }, delay);
322
340
  }
323
341
  else {
324
- menuElement.style.left = triggerRect.right + 20 + 'px';
342
+ menuElement.style.left = triggerRect.right + 20 - containerRect.left + 'px';
325
343
  timer = setTimeout(() => {
326
344
  menuElement.style.transform = 'translateX(-10px)';
327
345
  menuElement.style.opacity = '1';
@@ -333,12 +351,12 @@ const DropdownMenuPortal = core.withAnnotation({
333
351
  const documentClientHeight = document.documentElement.clientHeight;
334
352
  const bottomDistance = documentClientHeight - triggerRect.bottom;
335
353
  const isToTop = bottomDistance < 200 && triggerRect.top > bottomDistance;
336
- menuElement.style.left = triggerRect.left + 'px';
354
+ menuElement.style.left = triggerRect.left - containerRect.left + 'px';
337
355
  if (isToTop) {
338
356
  const maxHeight = Math.max(menuElement.scrollHeight, menuElement.offsetHeight);
339
357
  const height = Math.min(triggerRect.top - 20, maxHeight, 400);
340
358
  menuElement.style.height = height + 'px';
341
- menuElement.style.top = triggerRect.top - 20 - height + 'px';
359
+ menuElement.style.top = triggerRect.top - 20 - height - containerRect.top + 'px';
342
360
  timer = setTimeout(() => {
343
361
  menuElement.style.transform = 'translateY(10px)';
344
362
  menuElement.style.opacity = '1';
@@ -346,30 +364,41 @@ const DropdownMenuPortal = core.withAnnotation({
346
364
  }
347
365
  else {
348
366
  menuElement.style.height = Math.min(bottomDistance - 20, menuElement.scrollHeight) + 'px';
349
- menuElement.style.top = triggerRect.bottom + 20 + 'px';
367
+ menuElement.style.top = triggerRect.bottom + 20 - containerRect.top + 'px';
350
368
  timer = setTimeout(() => {
351
369
  menuElement.style.transform = 'translateY(-10px)';
352
370
  menuElement.style.opacity = '1';
353
371
  }, delay);
354
372
  }
355
373
  }
374
+ }
375
+ core.onUpdated(() => {
376
+ update();
356
377
  });
357
378
  core.onUnmounted(() => {
358
379
  clearTimeout(timer);
359
380
  });
360
381
  function onEnter() {
382
+ if (props.noTrigger) {
383
+ return;
384
+ }
361
385
  dropdownContextService.canHide = false;
362
386
  dropdownContextService.open();
363
387
  }
364
388
  function onLeave() {
389
+ if (props.noTrigger) {
390
+ return;
391
+ }
365
392
  dropdownContextService.canHide = true;
366
393
  dropdownContextService.hide();
367
394
  }
368
- return platformBrowser$1.createPortal(scopedCss.withScopedCSS(scopedId$f, () => {
395
+ return platformBrowser$1.createPortal(scopedCss.withScopedCSS(scopedId$i, () => {
369
396
  return (jsxRuntime.jsx("div", { onMouseenter: onEnter, onMouseleave: onLeave, ref: menuRef, style: {
370
397
  width: props.width
371
- }, class: "dropdown-menu", children: jsxRuntime.jsx("div", { class: "dropdown-menu-content", children: props.children }) }));
372
- }), document.body);
398
+ }, class: "dropdown-menu", children: jsxRuntime.jsx("div", { class: "dropdown-menu-content", style: {
399
+ padding: props.padding
400
+ }, children: props.children }) }));
401
+ }), container);
373
402
  });
374
403
 
375
404
  const Dropdown = core.withAnnotation({
@@ -397,6 +426,9 @@ const Dropdown = core.withAnnotation({
397
426
  });
398
427
  const subscription = new core$1.Subscription();
399
428
  core.onMounted(() => {
429
+ if (props.trigger === 'none') {
430
+ return;
431
+ }
400
432
  if (props.trigger === 'click') {
401
433
  subscription.add(core$1.fromEvent(triggerRef.current, 'click').subscribe(toggle));
402
434
  return;
@@ -422,14 +454,14 @@ const Dropdown = core.withAnnotation({
422
454
  return {
423
455
  isShow(b) {
424
456
  if (b) {
425
- dropdownContextService.hide(false);
457
+ dropdownContextService.open();
426
458
  }
427
459
  else {
428
- dropdownContextService.open();
460
+ dropdownContextService.hide(false);
429
461
  }
430
462
  },
431
- $render: scopedCss.withScopedCSS(scopedId$g, () => {
432
- return (jsxRuntime.jsxs("div", { class: ['dropdown', props.class], style: props.style, ref: dropdownRef, children: [jsxRuntime.jsxs("div", { class: "dropdown-btn", ref: triggerRef, children: [jsxRuntime.jsx("div", { class: "dropdown-btn-inner", children: props.children }), jsxRuntime.jsx("div", { class: "dropdown-btn-arrow" })] }), isShow() && jsxRuntime.jsx(DropdownMenuPortal, { width: props.width, abreast: props.abreast, triggerRef: triggerRef, children: Array.isArray(props.menu) ?
463
+ $render: scopedCss.withScopedCSS(scopedId$j, () => {
464
+ return (jsxRuntime.jsxs("div", { class: ['dropdown', props.class], style: props.style, ref: dropdownRef, children: [jsxRuntime.jsxs("div", { class: "dropdown-btn", ref: triggerRef, children: [jsxRuntime.jsx("div", { class: "dropdown-btn-inner", children: props.children }), jsxRuntime.jsx("div", { class: "dropdown-btn-arrow" })] }), isShow() && jsxRuntime.jsx(DropdownMenuPortal, { toLeft: props.toLeft, padding: props.padding, noTrigger: props.trigger === 'none', width: props.width, abreast: props.abreast, triggerRef: triggerRef, children: Array.isArray(props.menu) ?
433
465
  props.menu.map(menu => {
434
466
  return (jsxRuntime.jsx("div", { class: "dropdown-menu-item", onClick: () => {
435
467
  var _a;
@@ -444,10 +476,54 @@ const Dropdown = core.withAnnotation({
444
476
  };
445
477
  });
446
478
 
447
- var scopedId$e = "vf-678daa";
479
+ var scopedId$h = "vf-c32a7b";
480
+
481
+ function Keymap(props) {
482
+ const arr = [];
483
+ const keymap = props.keymap;
484
+ if (keymap.ctrlKey) {
485
+ arr.push(platformBrowser.isMac() ? jsxRuntime.jsx("span", { class: "xnote-icon-command" }) : jsxRuntime.jsx("span", { children: "Ctrl" }));
486
+ }
487
+ if (keymap.shiftKey) {
488
+ if (arr.length) {
489
+ arr.push('+');
490
+ }
491
+ arr.push(platformBrowser.isMac() ? jsxRuntime.jsx("span", { class: "xnote-icon-shift" }) : jsxRuntime.jsx("span", { children: "Shift" }));
492
+ }
493
+ if (keymap.altKey) {
494
+ if (arr.length) {
495
+ arr.push('+');
496
+ }
497
+ arr.push(platformBrowser.isMac() ? jsxRuntime.jsx("span", { class: "xnote-icon-opt" }) : jsxRuntime.jsx("span", { children: "Alt" }));
498
+ }
499
+ if (keymap.key) {
500
+ if (arr.length) {
501
+ arr.push('+');
502
+ }
503
+ if (Array.isArray(keymap.key)) {
504
+ arr.push(jsxRuntime.jsx("span", { children: keymap.key.join('/') }));
505
+ }
506
+ else {
507
+ arr.push(jsxRuntime.jsx("span", { children: keymap.key }));
508
+ }
509
+ }
510
+ return scopedCss.withScopedCSS(scopedId$h, () => {
511
+ return (jsxRuntime.jsx("span", { class: "keymap", children: arr }));
512
+ });
513
+ }
514
+
515
+ var scopedId$g = "vf-acaa5f";
516
+
517
+ function MenuHeading(props) {
518
+ return scopedCss.withScopedCSS(scopedId$g, () => {
519
+ return (jsxRuntime.jsx("div", { class: "menu-heading", children: props.children }));
520
+ });
521
+ }
522
+
523
+ var scopedId$f = "vf-c3b9dc";
448
524
 
449
525
  function MenuItem(props) {
450
- const dropdownContextService = core.inject(exports.DropdownContextService, core.InjectFlags.Optional, null);
526
+ const dropdownContextService = core.inject(exports.DropdownContextService, null);
451
527
  const isActive = core.createSignal((dropdownContextService === null || dropdownContextService === void 0 ? void 0 : dropdownContextService.isOpen) || false);
452
528
  if (dropdownContextService) {
453
529
  const subscription = dropdownContextService.onOpenStateChange.subscribe(b => {
@@ -464,8 +540,8 @@ function MenuItem(props) {
464
540
  }
465
541
  (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, props.value);
466
542
  }
467
- return scopedCss.withScopedCSS(scopedId$e, () => {
468
- return (jsxRuntime.jsxs("div", { class: ['menu-item', { disabled: props.disabled, active: props.arrow && isActive() }], onClick: click, children: [jsxRuntime.jsxs("div", { children: [props.icon && jsxRuntime.jsx("span", { class: "menu-icon", children: props.icon }), props.children] }), props.arrow ?
543
+ return scopedCss.withScopedCSS(scopedId$f, () => {
544
+ return (jsxRuntime.jsxs("div", { class: ['menu-item', { disabled: props.disabled, active: props.arrow && isActive() }], onClick: click, children: [jsxRuntime.jsxs("div", { class: "menu-item-content", children: [jsxRuntime.jsxs("div", { children: [props.icon && jsxRuntime.jsx("span", { class: "menu-icon", children: props.icon }), props.children] }), jsxRuntime.jsx("div", { children: props.desc })] }), props.arrow ?
469
545
  jsxRuntime.jsx("div", { class: "arrow", children: jsxRuntime.jsx("span", { class: "xnote-icon-arrow-right" }) }) :
470
546
  jsxRuntime.jsx("div", { class: [
471
547
  'menu-check',
@@ -474,11 +550,11 @@ function MenuItem(props) {
474
550
  });
475
551
  }
476
552
 
477
- var scopedId$d = "vf-a23c47";
553
+ var scopedId$e = "vf-a23c47";
478
554
 
479
555
  function Popup(props) {
480
556
  const host = core.inject(platformBrowser.VIEW_CONTAINER);
481
- return platformBrowser$1.createPortal(scopedCss.withScopedCSS(scopedId$d, () => {
557
+ return platformBrowser$1.createPortal(scopedCss.withScopedCSS(scopedId$e, () => {
482
558
  return (jsxRuntime.jsx("div", { class: "popup", style: {
483
559
  left: props.left + 'px',
484
560
  top: props.top + 'px'
@@ -486,15 +562,15 @@ function Popup(props) {
486
562
  }), host);
487
563
  }
488
564
 
489
- var scopedId$c = "vf-216815";
565
+ var scopedId$d = "vf-216815";
490
566
 
491
567
  function ToolbarItem(props) {
492
- return scopedCss.withScopedCSS(scopedId$c, () => {
568
+ return scopedCss.withScopedCSS(scopedId$d, () => {
493
569
  return (jsxRuntime.jsx("div", { class: "toolbar-item", children: props.children }));
494
570
  });
495
571
  }
496
572
 
497
- var scopedId$b = "vf-2a8a65";
573
+ var scopedId$c = "vf-2a8a65";
498
574
 
499
575
  exports.RefreshService = class RefreshService {
500
576
  constructor() {
@@ -556,6 +632,308 @@ function useOutput() {
556
632
  return core.createSignal(core.inject(OutputInjectionToken));
557
633
  }
558
634
 
635
+ const headingAttr = new core$1.Attribute('Heading', {
636
+ render(node, formatValue) {
637
+ node.classes.add('xnote-' + formatValue);
638
+ }
639
+ });
640
+ const headingAttrLoader = {
641
+ match(element) {
642
+ return /H[1-6]/.test(element.tagName) || /(^|\s)xnote-h[1-6](\s|$)/.test(element.className);
643
+ },
644
+ read(element) {
645
+ if (/H[1-6]/.test(element.tagName)) {
646
+ return {
647
+ attribute: headingAttr,
648
+ value: element.tagName.toLowerCase()
649
+ };
650
+ }
651
+ return {
652
+ attribute: headingAttr,
653
+ value: element.className.substring(6)
654
+ };
655
+ }
656
+ };
657
+ function registerHeadingShortcut(textbus) {
658
+ const keyboard = textbus.get(core$1.Keyboard);
659
+ const commander = textbus.get(core$1.Commander);
660
+ const selection = textbus.get(core$1.Selection);
661
+ keyboard.addShortcut({
662
+ keymap: {
663
+ key: '0123456'.split(''),
664
+ ctrlKey: true
665
+ },
666
+ action(key) {
667
+ if (key === '0') {
668
+ commander.unApplyAttribute(headingAttr);
669
+ return;
670
+ }
671
+ commander.applyAttribute(headingAttr, 'h' + key);
672
+ }
673
+ });
674
+ keyboard.addZenCodingInterceptor({
675
+ match(content) {
676
+ return /^#{1,6}$/.test(content);
677
+ },
678
+ try(key) {
679
+ return key === ' ';
680
+ },
681
+ action(content) {
682
+ if (selection.commonAncestorComponent instanceof SourceCodeComponent) {
683
+ return false;
684
+ }
685
+ const commonAncestorSlot = selection.commonAncestorSlot;
686
+ commonAncestorSlot.cut();
687
+ commander.applyAttribute(headingAttr, 'h' + content.length);
688
+ selection.setPosition(commonAncestorSlot, 0);
689
+ return true;
690
+ }
691
+ });
692
+ }
693
+
694
+ function useBlockContent(slot) {
695
+ const textbus = core$1.useContext();
696
+ const selection = textbus.get(core$1.Selection);
697
+ core$1.onBreak(ev => {
698
+ if (typeof slot === 'function' ? slot(ev.target) : ev.target === slot) {
699
+ const p = new ParagraphComponent(textbus);
700
+ ev.target.insert(p);
701
+ selection.setPosition(p.state.slot, 0);
702
+ ev.preventDefault();
703
+ }
704
+ });
705
+ core$1.onContentInsert(ev => {
706
+ if ((typeof slot === 'function' ? slot(ev.target) : ev.target === slot) &&
707
+ (typeof ev.data.content === 'string' || ev.data.content.type !== core$1.ContentType.BlockComponent)) {
708
+ const p = new ParagraphComponent(textbus);
709
+ const childSlot = p.state.slot;
710
+ childSlot.insert(ev.data.content);
711
+ ev.target.insert(p);
712
+ selection.setPosition(childSlot, childSlot.index);
713
+ ev.preventDefault();
714
+ }
715
+ });
716
+ }
717
+
718
+ function SlotRender(props) {
719
+ const adapter = core.inject(platformBrowser.DomAdapter);
720
+ const instance = core.getCurrentInstance();
721
+ const slot = props.slot;
722
+ const sub = core$1.merge(slot.__changeMarker__.onChange, slot.__changeMarker__.onForceChange).subscribe(() => {
723
+ if (props.slot.__changeMarker__.dirty) {
724
+ instance.markAsDirtied();
725
+ }
726
+ });
727
+ core.onUnmounted(() => {
728
+ sub.unsubscribe();
729
+ });
730
+ return () => {
731
+ const { slot, tag = 'div', renderEnv = false, elRef, elKey } = props, rest = __rest(props, ["slot", "tag", "renderEnv", "elRef", "elKey"]);
732
+ return adapter.slotRender(slot, children => {
733
+ return core$1.createVNode(tag, Object.assign({ ref: elRef, key: elKey }, rest), children);
734
+ }, renderEnv);
735
+ };
736
+ }
737
+
738
+ class BlockquoteComponent extends core$1.Component {
739
+ static fromJSON(textbus, json) {
740
+ const slot = textbus.get(core$1.Registry).createSlot(json.slot);
741
+ return new BlockquoteComponent(textbus, {
742
+ slot
743
+ });
744
+ }
745
+ constructor(textbus, state = {
746
+ slot: new core$1.Slot([
747
+ core$1.ContentType.BlockComponent
748
+ ])
749
+ }) {
750
+ super(textbus, state);
751
+ }
752
+ getSlots() {
753
+ return [this.state.slot];
754
+ }
755
+ setup() {
756
+ useBlockContent(this.state.slot);
757
+ }
758
+ }
759
+ BlockquoteComponent.type = core$1.ContentType.BlockComponent;
760
+ BlockquoteComponent.componentName = 'BlockquoteComponent';
761
+ BlockquoteComponent.zenCoding = {
762
+ key: ' ',
763
+ match(content, textbus) {
764
+ const selection = textbus.get(core$1.Selection);
765
+ if (selection.commonAncestorComponent instanceof ParagraphComponent) {
766
+ return /^>$/.test(content);
767
+ }
768
+ return false;
769
+ },
770
+ createState(_, textbus) {
771
+ const selection = textbus.get(core$1.Selection);
772
+ const commonAncestorSlot = selection.commonAncestorSlot;
773
+ const slot = new core$1.Slot([
774
+ core$1.ContentType.BlockComponent
775
+ ]);
776
+ if (commonAncestorSlot === null || commonAncestorSlot === void 0 ? void 0 : commonAncestorSlot.hasAttribute(textIndentAttr)) {
777
+ slot.setAttribute(textIndentAttr, commonAncestorSlot.getAttribute(textIndentAttr));
778
+ }
779
+ return {
780
+ slot
781
+ };
782
+ }
783
+ };
784
+ function toBlockquote(textbus) {
785
+ const query = textbus.get(core$1.Query);
786
+ const commander = textbus.get(core$1.Commander);
787
+ const selection = textbus.get(core$1.Selection);
788
+ const state = query.queryComponent(BlockquoteComponent);
789
+ if (state.state === core$1.QueryStateType.Enabled) {
790
+ const current = state.value;
791
+ const parent = current.parent;
792
+ const index = parent.indexOf(current);
793
+ parent.retain(index);
794
+ commander.removeComponent(current);
795
+ current.slots.at(0).sliceContent().forEach(i => {
796
+ parent.insert(i);
797
+ });
798
+ }
799
+ else {
800
+ const block = new BlockquoteComponent(textbus);
801
+ const slot = block.state.slot;
802
+ if (selection.startSlot === selection.endSlot) {
803
+ const parentComponent = selection.startSlot.parent;
804
+ const parentSlot = parentComponent.parent;
805
+ const position = parentSlot.indexOf(parentComponent);
806
+ slot.insert(parentComponent);
807
+ parentSlot.retain(position);
808
+ parentSlot.insert(block);
809
+ }
810
+ else {
811
+ const commonAncestorSlot = selection.commonAncestorSlot;
812
+ const scope = selection.getCommonAncestorSlotScope();
813
+ commonAncestorSlot.cut(scope.startOffset, scope.endOffset).sliceContent().forEach(i => {
814
+ slot.insert(i);
815
+ });
816
+ commonAncestorSlot.retain(scope.startOffset);
817
+ commonAncestorSlot.insert(block);
818
+ }
819
+ }
820
+ }
821
+ function registerBlockquoteShortcut(textbus) {
822
+ const keyboard = textbus.get(core$1.Keyboard);
823
+ keyboard.addShortcut({
824
+ keymap: {
825
+ ctrlKey: true,
826
+ key: '\''
827
+ },
828
+ action() {
829
+ toBlockquote(textbus);
830
+ }
831
+ });
832
+ }
833
+ function BlockquoteView(props) {
834
+ const readonly = useReadonly();
835
+ const output = useOutput();
836
+ return () => {
837
+ const slot = props.component.state.slot;
838
+ return (jsxRuntime.jsx("blockquote", { class: "xnote-blockquote", ref: props.rootRef, "data-component": props.component.name, children: jsxRuntime.jsx(SlotRender, { slot: slot, renderEnv: readonly() || output() }) }));
839
+ };
840
+ }
841
+ const blockquoteComponentLoader = {
842
+ match(element, returnableContentTypes) {
843
+ return returnableContentTypes.includes(core$1.ContentType.BlockComponent) && element.tagName === 'BLOCKQUOTE';
844
+ },
845
+ read(element, textbus, slotParser) {
846
+ const delta = slotParser(new core$1.Slot([
847
+ core$1.ContentType.BlockComponent,
848
+ core$1.ContentType.InlineComponent,
849
+ core$1.ContentType.Text
850
+ ]), element).toDelta();
851
+ const slot = new core$1.Slot([
852
+ core$1.ContentType.BlockComponent,
853
+ ]);
854
+ deltaToBlock(delta, textbus).forEach(i => {
855
+ slot.insert(i);
856
+ });
857
+ return new BlockquoteComponent(textbus, {
858
+ slot
859
+ });
860
+ },
861
+ };
862
+
863
+ class HighlightBoxComponent extends core$1.Component {
864
+ static fromJSON(textbus, json) {
865
+ return new HighlightBoxComponent(textbus, {
866
+ type: json.type,
867
+ slot: textbus.get(core$1.Registry).createSlot(json.slot)
868
+ });
869
+ }
870
+ constructor(textbus, state = {
871
+ type: '',
872
+ slot: new core$1.Slot([
873
+ core$1.ContentType.BlockComponent,
874
+ ])
875
+ }) {
876
+ super(textbus, state);
877
+ }
878
+ getSlots() {
879
+ return [this.state.slot];
880
+ }
881
+ setup() {
882
+ useBlockContent(this.state.slot);
883
+ }
884
+ }
885
+ HighlightBoxComponent.defaultTypes = ['❤️', '💡', '📌', '✅', '❎', '👍', '🎉', '🚫', '❗'];
886
+ HighlightBoxComponent.componentName = 'HighlightBoxComponent';
887
+ HighlightBoxComponent.type = core$1.ContentType.BlockComponent;
888
+ function HighlightBoxView(props) {
889
+ const readonly = useReadonly();
890
+ const output = useOutput();
891
+ const emoji = [];
892
+ for (let i = 0x1F600; i <= 0x1F64F; i++) {
893
+ emoji.push(i);
894
+ }
895
+ const dropdownRef = core.createRef();
896
+ function setType(type) {
897
+ var _a;
898
+ (_a = dropdownRef.current) === null || _a === void 0 ? void 0 : _a.isShow(false);
899
+ props.component.state.type = type;
900
+ }
901
+ return () => {
902
+ const { state, name } = props.component;
903
+ if (readonly() || output()) {
904
+ return (jsxRuntime.jsxs("div", { "data-component": name, ref: props.rootRef, "data-icon": state.type, class: "xnote-highlight-box", children: [jsxRuntime.jsx("div", { class: "xnote-highlight-box-left", children: jsxRuntime.jsx("div", { class: "xnote-highlight-box-icon", children: jsxRuntime.jsx("button", { type: "button", children: state.type || '❤️' }) }) }), jsxRuntime.jsx(SlotRender, { slot: state.slot, class: 'xnote-highlight-box-content', renderEnv: readonly() || output() })] }));
905
+ }
906
+ return (jsxRuntime.jsxs("div", { "data-component": name, ref: props.rootRef, "data-icon": state.type, class: "xnote-highlight-box", children: [jsxRuntime.jsx("div", { class: "xnote-highlight-box-left", children: jsxRuntime.jsx(Dropdown, { trigger: "click", ref: dropdownRef, width: "282px", menu: jsxRuntime.jsxs("div", { class: "xnote-highlight-box-icons", children: [jsxRuntime.jsx("div", { class: "xnote-highlight-box-heading", children: "\u5E38\u7528" }), HighlightBoxComponent.defaultTypes.map(icon => {
907
+ return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
908
+ }), jsxRuntime.jsx("div", { class: "xnote-highlight-box-heading", children: "\u66F4\u591A" }), emoji.map(i => {
909
+ const icon = String.fromCodePoint(i);
910
+ return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
911
+ })] }), children: jsxRuntime.jsx("div", { class: "xnote-highlight-box-icon", children: jsxRuntime.jsx("button", { type: "button", children: state.type || '❤️' }) }) }) }), jsxRuntime.jsx(SlotRender, { slot: state.slot, class: 'xnote-highlight-box-content', renderEnv: readonly() || output() })] }));
912
+ };
913
+ }
914
+ const highlightBoxComponentLoader = {
915
+ match(element) {
916
+ return element.tagName === 'DIV' && element.dataset.component === HighlightBoxComponent.componentName;
917
+ },
918
+ read(element, textbus, slotParser) {
919
+ const delta = slotParser(new core$1.Slot([
920
+ core$1.ContentType.BlockComponent,
921
+ core$1.ContentType.InlineComponent,
922
+ core$1.ContentType.Text
923
+ ]), element.querySelector('.xnote-highlight-box-content')).toDelta();
924
+ const slot = new core$1.Slot([
925
+ core$1.ContentType.BlockComponent,
926
+ ]);
927
+ deltaToBlock(delta, textbus).forEach(i => {
928
+ slot.insert(i);
929
+ });
930
+ return new HighlightBoxComponent(textbus, {
931
+ type: element.dataset.icon || '',
932
+ slot
933
+ });
934
+ }
935
+ };
936
+
559
937
  class ParagraphComponent extends core$1.Component {
560
938
  static fromJSON(textbus, json) {
561
939
  const slot = textbus.get(core$1.Registry).createSlot(json.slot);
@@ -571,16 +949,28 @@ class ParagraphComponent extends core$1.Component {
571
949
  }) {
572
950
  super(textbus, state);
573
951
  }
952
+ getSlots() {
953
+ return [this.state.slot];
954
+ }
574
955
  setup() {
575
956
  const injector = core$1.useContext();
576
957
  const commander = injector.get(core$1.Commander);
577
958
  const selection = injector.get(core$1.Selection);
578
959
  core$1.onBreak(ev => {
960
+ const isEmpty = this.state.slot.isEmpty;
579
961
  const afterSlot = ev.target.cut(ev.data.index);
962
+ afterSlot.removeAttribute(headingAttr);
580
963
  const nextParagraph = new ParagraphComponent(injector, {
581
964
  slot: afterSlot
582
965
  });
583
- commander.insertAfter(nextParagraph, this);
966
+ if (isEmpty && (this.parentComponent instanceof BlockquoteComponent ||
967
+ this.parentComponent instanceof HighlightBoxComponent)) {
968
+ commander.insertAfter(nextParagraph, this.parentComponent);
969
+ commander.removeComponent(this);
970
+ }
971
+ else {
972
+ commander.insertAfter(nextParagraph, this);
973
+ }
584
974
  selection.setPosition(afterSlot, 0);
585
975
  ev.preventDefault();
586
976
  });
@@ -589,22 +979,30 @@ class ParagraphComponent extends core$1.Component {
589
979
  ParagraphComponent.componentName = 'ParagraphComponent';
590
980
  ParagraphComponent.type = core$1.ContentType.BlockComponent;
591
981
  function ParagraphView(props) {
592
- const adapter = core.inject(platformBrowser.DomAdapter);
593
982
  const readonly = useReadonly();
594
983
  const output = useOutput();
595
984
  return () => {
596
985
  const slot = props.component.state.slot;
597
- return (jsxRuntime.jsx("div", { class: "xnote-paragraph", ref: props.rootRef, "data-component": ParagraphComponent.name, children: adapter.slotRender(slot, children => {
598
- return (core$1.createVNode('p', null, children));
599
- }, readonly() || output()) }));
986
+ return (jsxRuntime.jsx("div", { class: "xnote-paragraph", ref: props.rootRef, "data-component": ParagraphComponent.componentName, children: jsxRuntime.jsx(SlotRender, { tag: "div", slot: slot, renderEnv: readonly() || output() }) }));
600
987
  };
601
988
  }
602
989
  const paragraphComponentLoader = {
603
- match(element) {
604
- return element.dataset.compoment === ParagraphComponent.name || /P|H[1-6]/.test(element.tagName);
990
+ match(element, returnableContentTypes) {
991
+ return returnableContentTypes.includes(core$1.ContentType.BlockComponent) && (element.dataset.component === ParagraphComponent.componentName || /^P|H[1-6]$/.test(element.tagName));
605
992
  },
606
993
  read(element, textbus, slotParser) {
607
- const content = /P|H[1-6]/.test(element.tagName) ? element : element.children[0];
994
+ let content;
995
+ if (/^P|H[1-6]$/.test(element.tagName)) {
996
+ content = element;
997
+ }
998
+ else {
999
+ content = element.children[0];
1000
+ if (!content) {
1001
+ const p = document.createElement('p');
1002
+ p.append(element.innerText);
1003
+ content = p;
1004
+ }
1005
+ }
608
1006
  const delta = slotParser(new core$1.Slot([
609
1007
  core$1.ContentType.Text,
610
1008
  core$1.ContentType.InlineComponent,
@@ -680,6 +1078,15 @@ const languageList = [{
680
1078
  }, {
681
1079
  label: 'Go',
682
1080
  value: 'Go'
1081
+ }, {
1082
+ label: 'Kotlin',
1083
+ value: 'kotlin'
1084
+ }, {
1085
+ label: 'Python',
1086
+ value: 'python'
1087
+ }, {
1088
+ label: 'PHP',
1089
+ value: 'php'
683
1090
  }, {
684
1091
  label: 'JSON',
685
1092
  value: 'JSON',
@@ -704,6 +1111,9 @@ const languageList = [{
704
1111
  }, {
705
1112
  label: 'Shell',
706
1113
  value: 'shell',
1114
+ }, {
1115
+ label: 'Katex',
1116
+ value: 'latex',
707
1117
  }, {
708
1118
  label: 'Yaml',
709
1119
  value: 'yaml',
@@ -722,11 +1132,16 @@ const languageList = [{
722
1132
  }, {
723
1133
  label: 'Dart',
724
1134
  value: 'dart',
1135
+ }, {
1136
+ label: 'Rust',
1137
+ value: 'rust',
725
1138
  }, {
726
1139
  label: '',
727
1140
  value: '',
728
1141
  }];
729
1142
  const sourceCodeThemes = [
1143
+ 'xnote-dark',
1144
+ 'xnote-dark-blue',
730
1145
  'github',
731
1146
  'atom-one-dark',
732
1147
  'foundation',
@@ -782,12 +1197,17 @@ class SourceCodeComponent extends core$1.Component {
782
1197
  theme: json.theme
783
1198
  });
784
1199
  }
1200
+ getSlots() {
1201
+ return this.state.slots.map(i => i.slot);
1202
+ }
785
1203
  setup() {
786
1204
  const textbus = core$1.useContext();
787
1205
  const selection = core$1.useContext(core$1.Selection);
788
1206
  core$1.onBreak(ev => {
789
1207
  const slots = this.state.slots;
790
- if (ev.target.isEmpty && ev.target === slots[slots.length - 1].slot) {
1208
+ const parentComponent = selection.commonAncestorComponent;
1209
+ const parentSlot = parentComponent.parent;
1210
+ if (parentSlot && ev.target.isEmpty && ev.target === slots[slots.length - 1].slot) {
791
1211
  const prevSlot = slots[slots.length - 2];
792
1212
  if (prevSlot === null || prevSlot === void 0 ? void 0 : prevSlot.slot.isEmpty) {
793
1213
  const slot = new core$1.Slot([
@@ -797,8 +1217,6 @@ class SourceCodeComponent extends core$1.Component {
797
1217
  const paragraph = new ParagraphComponent(textbus, {
798
1218
  slot
799
1219
  });
800
- const parentComponent = selection.commonAncestorComponent;
801
- const parentSlot = parentComponent.parent;
802
1220
  const index = parentSlot.indexOf(parentComponent);
803
1221
  parentSlot.retain(index + 1);
804
1222
  slots.pop();
@@ -826,6 +1244,12 @@ class SourceCodeComponent extends core$1.Component {
826
1244
  });
827
1245
  ev.preventDefault();
828
1246
  });
1247
+ core$1.onSlotApplyFormat(ev => {
1248
+ ev.preventDefault();
1249
+ });
1250
+ core$1.onSlotSetAttribute(ev => {
1251
+ ev.preventDefault();
1252
+ });
829
1253
  core$1.onPaste(ev => {
830
1254
  const codeList = [];
831
1255
  const sourceCode = ev.data.text;
@@ -949,11 +1373,15 @@ class SourceCodeComponent extends core$1.Component {
949
1373
  SourceCodeComponent.type = core$1.ContentType.BlockComponent;
950
1374
  SourceCodeComponent.componentName = 'SourceCodeComponent';
951
1375
  SourceCodeComponent.zenCoding = {
952
- key: 'Enter',
953
- match(c) {
954
- const matchString = languageList.map(i => i.label || i.value).concat('js', 'ts').join('|').replace(/\+/, '\\+');
955
- const reg = new RegExp(`^\`\`\`(${matchString})$`, 'i');
956
- return reg.test(c);
1376
+ key: ['Enter', ' '],
1377
+ match(c, textbus) {
1378
+ const selection = textbus.get(core$1.Selection);
1379
+ if (selection.commonAncestorComponent instanceof ParagraphComponent) {
1380
+ const matchString = languageList.map(i => i.label || i.value).concat('js', 'ts').join('|').replace(/\+/, '\\+');
1381
+ const reg = new RegExp(`^\`\`\`(${matchString})$`, 'i');
1382
+ return reg.test(c);
1383
+ }
1384
+ return false;
957
1385
  },
958
1386
  createState(content) {
959
1387
  const matchString = content.replace(/`/g, '').replace(/\+/, '\\+');
@@ -1020,7 +1448,7 @@ function SourceCodeView(props) {
1020
1448
  }
1021
1449
  const input = core.inject(platformBrowser.Input);
1022
1450
  function updateCaret() {
1023
- input.caret.refresh(false);
1451
+ input.caret.refresh();
1024
1452
  }
1025
1453
  const readonly = useReadonly();
1026
1454
  const output = useOutput();
@@ -1057,28 +1485,6 @@ function SourceCodeView(props) {
1057
1485
  }
1058
1486
  }
1059
1487
  }
1060
- function nodesToVNodes(slot, nodes, index) {
1061
- return nodes.map(i => {
1062
- const location = {
1063
- slot,
1064
- startIndex: index,
1065
- endIndex: index + i.textContent.length
1066
- };
1067
- if (i.nodeType === Node.ELEMENT_NODE) {
1068
- const childNodes = Array.from(i.childNodes);
1069
- const vEle = core$1.createVNode('span', {
1070
- class: i.className
1071
- }, nodesToVNodes(slot, childNodes, index));
1072
- index = location.endIndex;
1073
- vEle.location = Object.assign({}, location);
1074
- return vEle;
1075
- }
1076
- index = location.endIndex;
1077
- const textNode = new core$1.VTextNode(i.textContent);
1078
- textNode.location = location;
1079
- return textNode;
1080
- });
1081
- }
1082
1488
  return (jsxRuntime.jsxs("div", { ref: props.rootRef, class: {
1083
1489
  'xnote-source-code': true,
1084
1490
  'xnote-source-code-line-number': state.lineNumber,
@@ -1109,7 +1515,7 @@ function SourceCodeView(props) {
1109
1515
  }
1110
1516
  ], children: [jsxRuntime.jsx("div", { class: "xnote-source-code-line-number-bg", style: {
1111
1517
  width: Math.max(String(slots.length).length, 2.5) + 'em'
1112
- } }), jsxRuntime.jsx("div", { onScroll: updateCaret, class: {
1518
+ } }), jsxRuntime.jsx("pre", { onScroll: updateCaret, class: {
1113
1519
  'xnote-source-code-content': true,
1114
1520
  'xnote-source-code-content-highlight': blockHighlight
1115
1521
  }, style: {
@@ -1130,7 +1536,7 @@ function SourceCodeView(props) {
1130
1536
  children.push(br);
1131
1537
  }
1132
1538
  }
1133
- return core$1.createVNode('pre', {
1539
+ return core$1.createVNode('div', {
1134
1540
  class: 'xnote-source-code-line' + (item.emphasize ? ' xnote-source-code-line-emphasize' : '')
1135
1541
  }, [
1136
1542
  core$1.createVNode('span', { class: 'xnote-source-code-line-content' }, children)
@@ -1139,10 +1545,33 @@ function SourceCodeView(props) {
1139
1545
  }) }), jsxRuntime.jsx("span", { class: "xnote-source-code-lang", children: lang })] })] }));
1140
1546
  };
1141
1547
  }
1548
+ function nodesToVNodes(slot, nodes, index) {
1549
+ return nodes.map(i => {
1550
+ const location = {
1551
+ slot,
1552
+ startIndex: index,
1553
+ endIndex: index + i.textContent.length
1554
+ };
1555
+ if (i.nodeType === Node.ELEMENT_NODE) {
1556
+ const childNodes = Array.from(i.childNodes);
1557
+ const vEle = core$1.createVNode('span', {
1558
+ class: i.className
1559
+ }, nodesToVNodes(slot, childNodes, index));
1560
+ index = location.endIndex;
1561
+ vEle.location = Object.assign({}, location);
1562
+ return vEle;
1563
+ }
1564
+ index = location.endIndex;
1565
+ const textNode = new core$1.VTextNode(i.textContent);
1566
+ textNode.location = location;
1567
+ return textNode;
1568
+ });
1569
+ }
1142
1570
  const sourceCodeComponentLoader = {
1143
- match(element) {
1144
- return (element.tagName === 'DIV' && element.dataset.component === SourceCodeComponent.componentName) ||
1145
- element.tagName === 'PRE';
1571
+ match(element, returnableContentTypes) {
1572
+ return returnableContentTypes.includes(core$1.ContentType.BlockComponent) &&
1573
+ ((element.tagName === 'DIV' && element.dataset.component === SourceCodeComponent.componentName) ||
1574
+ element.tagName === 'PRE');
1146
1575
  },
1147
1576
  read(el, textbus) {
1148
1577
  let slots = [];
@@ -1270,15 +1699,26 @@ function AttrTool(props) {
1270
1699
  textIndent: 0
1271
1700
  });
1272
1701
  function updateCheckStates() {
1273
- var _a, _b;
1274
- (_a = props.queryBefore) === null || _a === void 0 ? void 0 : _a.call(props);
1702
+ if (!props.slot && !selection.isSelected) {
1703
+ return;
1704
+ }
1275
1705
  setCheckStates(draft => {
1276
- const textAlignState = query.queryAttribute(textAlignAttr);
1277
- const textIndentState = query.queryAttribute(textIndentAttr);
1706
+ const range = props.slot ? {
1707
+ startSlot: props.slot,
1708
+ endSlot: props.slot,
1709
+ startOffset: 0,
1710
+ endOffset: props.slot.length
1711
+ } : {
1712
+ startSlot: selection.startSlot,
1713
+ startOffset: selection.startOffset,
1714
+ endSlot: selection.endSlot,
1715
+ endOffset: selection.endOffset
1716
+ };
1717
+ const textAlignState = query.queryAttributeByRange(textAlignAttr, range);
1718
+ const textIndentState = query.queryAttributeByRange(textIndentAttr, range);
1278
1719
  draft.textAlign = textAlignState.state === core$1.QueryStateType.Enabled ? textAlignState.value : 'left';
1279
1720
  draft.textIndent = textIndentState.state === core$1.QueryStateType.Enabled ? textIndentState.value : 0;
1280
1721
  });
1281
- (_b = props.queryAfter) === null || _b === void 0 ? void 0 : _b.call(props);
1282
1722
  }
1283
1723
  updateCheckStates();
1284
1724
  const subscription = refreshService.onRefresh.subscribe(() => {
@@ -1325,110 +1765,35 @@ function AttrTool(props) {
1325
1765
  break;
1326
1766
  }
1327
1767
  }
1328
- return scopedCss.withScopedCSS(scopedId$b, () => {
1768
+ return scopedCss.withScopedCSS(scopedId$c, () => {
1329
1769
  const states = checkStates();
1330
- return (jsxRuntime.jsx(Dropdown, { style: props.style, abreast: props.abreast, onCheck: updateAttr, trigger: 'hover', menu: [
1770
+ return (jsxRuntime.jsx(Dropdown, { width: 'auto', style: props.style, abreast: props.abreast, onCheck: updateAttr, trigger: 'hover', menu: [
1331
1771
  {
1332
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-left" }), checked: states.textAlign === 'left', children: "\u5DE6\u5BF9\u9F50" }),
1772
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-left" }), desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'L', ctrlKey: true } }), checked: states.textAlign === 'left', children: "\u5DE6\u5BF9\u9F50" }),
1333
1773
  value: 't-l'
1334
1774
  }, {
1335
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-right" }), checked: states.textAlign === 'right', children: "\u53F3\u5BF9\u9F50" }),
1775
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-right" }), desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'R', ctrlKey: true } }), checked: states.textAlign === 'right', children: "\u53F3\u5BF9\u9F50" }),
1336
1776
  value: 't-r'
1337
1777
  }, {
1338
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-center" }), checked: states.textAlign === 'center', children: "\u5C45\u4E2D\u5BF9\u9F50" }),
1778
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-center" }), desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'E', ctrlKey: true } }), checked: states.textAlign === 'center', children: "\u5C45\u4E2D\u5BF9\u9F50" }),
1339
1779
  value: 't-c'
1340
1780
  }, {
1341
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-justify" }), checked: states.textAlign === 'justify', children: "\u5206\u6563\u5BF9\u9F50" }),
1781
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paragraph-justify" }), desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'J', ctrlKey: true } }), checked: states.textAlign === 'justify', children: "\u5206\u6563\u5BF9\u9F50" }),
1342
1782
  value: 't-j'
1343
1783
  }, {
1344
1784
  label: jsxRuntime.jsx(Divider, {}),
1345
1785
  value: ''
1346
1786
  }, {
1347
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-indent-increase" }), children: "\u589E\u52A0\u7F29\u8FDB" }),
1787
+ label: jsxRuntime.jsx(MenuItem, { desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'Tab' } }), icon: jsxRuntime.jsx("span", { class: "xnote-icon-indent-increase" }), children: "\u589E\u52A0\u7F29\u8FDB" }),
1348
1788
  value: 'i+'
1349
1789
  }, {
1350
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-indent-decrease" }), children: "\u51CF\u5C11\u7F29\u8FDB" }),
1790
+ label: jsxRuntime.jsx(MenuItem, { desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'Tab', shiftKey: true } }), icon: jsxRuntime.jsx("span", { class: "xnote-icon-indent-decrease" }), children: "\u51CF\u5C11\u7F29\u8FDB" }),
1351
1791
  value: 'i-'
1352
1792
  }
1353
1793
  ], children: props.children || jsxRuntime.jsx(Button, { arrow: true, highlight: false, children: jsxRuntime.jsx("span", { class: `xnote-icon-paragraph-${states.textAlign || 'left'} icon` }) }) }));
1354
1794
  });
1355
1795
  }
1356
1796
 
1357
- const headingAttr = new core$1.Attribute('Heading', {
1358
- render(node, formatValue) {
1359
- node.classes.add('xnote-' + formatValue);
1360
- }
1361
- });
1362
- const headingAttrLoader = {
1363
- match(element) {
1364
- return /H[1-6]/.test(element.tagName) || /(^|\s)xnote-h[1-6](\s|$)/.test(element.className);
1365
- },
1366
- read(element) {
1367
- if (/H[1-6]/.test(element.tagName)) {
1368
- return {
1369
- attribute: headingAttr,
1370
- value: element.tagName.toLowerCase()
1371
- };
1372
- }
1373
- return {
1374
- attribute: headingAttr,
1375
- value: element.className.substring(6)
1376
- };
1377
- }
1378
- };
1379
- function registerHeadingShortcut(textbus) {
1380
- const keyboard = textbus.get(core$1.Keyboard);
1381
- const commander = textbus.get(core$1.Commander);
1382
- const selection = textbus.get(core$1.Selection);
1383
- keyboard.addShortcut({
1384
- keymap: {
1385
- key: '123456'.split(''),
1386
- ctrlKey: true
1387
- },
1388
- action(key) {
1389
- commander.applyAttribute(headingAttr, 'h' + key);
1390
- }
1391
- });
1392
- keyboard.addZenCodingInterceptor({
1393
- match(content) {
1394
- return /^#{1,6}$/.test(content);
1395
- },
1396
- try(key) {
1397
- return key === ' ';
1398
- },
1399
- action(content) {
1400
- const commonAncestorSlot = selection.commonAncestorSlot;
1401
- commonAncestorSlot.cut();
1402
- commander.applyAttribute(headingAttr, 'h' + content.length);
1403
- return true;
1404
- }
1405
- });
1406
- }
1407
-
1408
- function useBlockContent(slot) {
1409
- const textbus = core$1.useContext();
1410
- const selection = textbus.get(core$1.Selection);
1411
- core$1.onBreak(ev => {
1412
- if (typeof slot === 'function' ? slot(ev.target) : ev.target === slot) {
1413
- const p = new ParagraphComponent(textbus);
1414
- ev.target.insert(p);
1415
- selection.setPosition(p.state.slot, 0);
1416
- ev.preventDefault();
1417
- }
1418
- });
1419
- core$1.onContentInsert(ev => {
1420
- if ((typeof slot === 'function' ? slot(ev.target) : ev.target === slot) &&
1421
- (typeof ev.data.content === 'string' || ev.data.content.type !== core$1.ContentType.BlockComponent)) {
1422
- const p = new ParagraphComponent(textbus);
1423
- const childSlot = p.state.slot;
1424
- childSlot.insert(ev.data.content);
1425
- ev.target.insert(p);
1426
- selection.setPosition(childSlot, childSlot.index);
1427
- ev.preventDefault();
1428
- }
1429
- });
1430
- }
1431
-
1432
1797
  const defaultRowHeight = 30;
1433
1798
  const defaultColumnWidth = 100;
1434
1799
  class TableComponent extends core$1.Component {
@@ -1451,17 +1816,18 @@ class TableComponent extends core$1.Component {
1451
1816
  });
1452
1817
  }
1453
1818
  constructor(textbus, state = {
1454
- layoutWidth: Array.from({ length: 3 }).fill(100),
1819
+ layoutWidth: Array.from({ length: 5 }).fill(100),
1455
1820
  rows: Array.from({ length: 3 }).map(() => {
1456
1821
  return {
1457
1822
  height: defaultRowHeight,
1458
- cells: Array.from({ length: 3 }).map(() => {
1823
+ cells: Array.from({ length: 5 }).map(() => {
1824
+ const p = new ParagraphComponent(textbus);
1825
+ const slot = new core$1.Slot([core$1.ContentType.BlockComponent]);
1826
+ slot.insert(p);
1459
1827
  return {
1460
1828
  rowspan: 1,
1461
1829
  colspan: 1,
1462
- slot: new core$1.Slot([
1463
- core$1.ContentType.BlockComponent
1464
- ])
1830
+ slot
1465
1831
  };
1466
1832
  })
1467
1833
  };
@@ -1472,7 +1838,11 @@ class TableComponent extends core$1.Component {
1472
1838
  this.focus = new core$1.Subject();
1473
1839
  this.tableSelection = core.createSignal(null);
1474
1840
  }
1841
+ getSlots() {
1842
+ return this.state.rows.map(i => i.cells.map(j => j.slot)).flat();
1843
+ }
1475
1844
  setup() {
1845
+ const selection = core$1.useContext(core$1.Selection);
1476
1846
  core$1.onFocusIn(() => {
1477
1847
  this.focus.next(true);
1478
1848
  });
@@ -1482,12 +1852,42 @@ class TableComponent extends core$1.Component {
1482
1852
  useBlockContent((slot) => {
1483
1853
  return slot.parent === this;
1484
1854
  });
1485
- core$1.onGetRanges(ev => {
1486
- const selectPosition = this.tableSelection();
1855
+ const sub = selection.onChange.subscribe(() => {
1856
+ if (selection.commonAncestorComponent !== this || selection.isCollapsed) {
1857
+ this.tableSelection.set(null);
1858
+ }
1859
+ });
1860
+ core$1.onDestroy(() => {
1861
+ sub.unsubscribe();
1862
+ });
1863
+ const findPosition = (slot) => {
1864
+ let cell = slot;
1865
+ while ((cell === null || cell === void 0 ? void 0 : cell.parent) && cell.parent !== this) {
1866
+ cell = cell.parentSlot;
1867
+ }
1868
+ if (cell) {
1869
+ const rows = this.state.rows;
1870
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
1871
+ const row = rows[rowIndex].cells;
1872
+ for (let colIndex = 0; colIndex < row.length; colIndex++) {
1873
+ const item = row[colIndex].slot;
1874
+ if (item === cell) {
1875
+ return {
1876
+ rowIndex,
1877
+ colIndex
1878
+ };
1879
+ }
1880
+ }
1881
+ }
1882
+ }
1883
+ return null;
1884
+ };
1885
+ const select = (ev, selectPosition) => {
1886
+ this.tableSelection.set(selectPosition);
1487
1887
  if (selectPosition) {
1488
1888
  const cells = [];
1489
- this.state.rows.slice(selectPosition.startRow, selectPosition.endRow + 1).forEach(row => {
1490
- cells.push(...row.cells.slice(selectPosition.startColumn, selectPosition.endColumn + 1).map(i => i.slot));
1889
+ this.state.rows.slice(selectPosition.startRow, selectPosition.endRow).forEach(row => {
1890
+ cells.push(...row.cells.slice(selectPosition.startColumn, selectPosition.endColumn).map(i => i.slot));
1491
1891
  });
1492
1892
  ev.useRanges(cells.map(i => {
1493
1893
  return {
@@ -1498,33 +1898,64 @@ class TableComponent extends core$1.Component {
1498
1898
  }));
1499
1899
  ev.preventDefault();
1500
1900
  }
1501
- });
1502
- }
1503
- afterContentCheck() {
1504
- const selection = this.selection;
1505
- const rows = this.state.rows;
1506
- rows.forEach(row => {
1507
- row.cells.forEach(cell => {
1508
- const slot = cell.slot;
1509
- if (slot.isEmpty) {
1510
- const childSlot = new core$1.Slot([
1511
- core$1.ContentType.Text,
1512
- core$1.ContentType.InlineComponent
1513
- ]);
1514
- const p = new ParagraphComponent(this.textbus, {
1515
- slot: childSlot
1516
- });
1517
- slot.insert(p);
1518
- if (slot === selection.anchorSlot) {
1519
- selection.setAnchor(childSlot, 0);
1520
- }
1521
- if (slot === selection.focusSlot) {
1522
- selection.setFocus(childSlot, 0);
1901
+ };
1902
+ core$1.onGetRanges(ev => {
1903
+ var _a;
1904
+ const startPosition = findPosition(selection.startSlot);
1905
+ const endPosition = findPosition(selection.endSlot);
1906
+ if (startPosition && endPosition) {
1907
+ if (startPosition.rowIndex === endPosition.rowIndex && startPosition.colIndex === endPosition.colIndex) {
1908
+ if (selection.startSlot === selection.endSlot && selection.startOffset === 0 && selection.endOffset === ((_a = selection.startSlot) === null || _a === void 0 ? void 0 : _a.length)) {
1909
+ select(ev, {
1910
+ startColumn: startPosition.colIndex,
1911
+ startRow: startPosition.rowIndex,
1912
+ endColumn: endPosition.colIndex + 1,
1913
+ endRow: endPosition.rowIndex + 1
1914
+ });
1915
+ return;
1523
1916
  }
1917
+ select(ev, null);
1918
+ return;
1524
1919
  }
1525
- });
1920
+ const [startColumn, endColumn] = [startPosition.colIndex, endPosition.colIndex].sort((a, b) => a - b);
1921
+ const [startRow, endRow] = [startPosition.rowIndex, endPosition.rowIndex].sort((a, b) => a - b);
1922
+ select(ev, {
1923
+ startColumn,
1924
+ startRow,
1925
+ endColumn: endColumn + 1,
1926
+ endRow: endRow + 1
1927
+ });
1928
+ }
1929
+ else {
1930
+ select(ev, null);
1931
+ }
1526
1932
  });
1527
1933
  }
1934
+ // afterContentCheck() {
1935
+ // const selection = this.selection
1936
+ // const rows = this.state.rows
1937
+ // rows.forEach(row => {
1938
+ // row.cells.forEach(cell => {
1939
+ // const slot = cell.slot
1940
+ // if (slot.isEmpty) {
1941
+ // const childSlot = new Slot([
1942
+ // ContentType.Text,
1943
+ // ContentType.InlineComponent
1944
+ // ])
1945
+ // const p = new ParagraphComponent(this.textbus, {
1946
+ // slot: childSlot
1947
+ // })
1948
+ // slot.insert(p)
1949
+ // if (slot === selection.anchorSlot) {
1950
+ // selection.setAnchor(childSlot, 0)
1951
+ // }
1952
+ // if (slot === selection.focusSlot) {
1953
+ // selection.setFocus(childSlot, 0)
1954
+ // }
1955
+ // }
1956
+ // })
1957
+ // })
1958
+ // }
1528
1959
  deleteColumn(index) {
1529
1960
  this.state.layoutWidth.splice(index, 1);
1530
1961
  this.state.rows.forEach(row => {
@@ -1647,12 +2078,16 @@ class TodolistComponent extends core$1.Component {
1647
2078
  checked: json.checked
1648
2079
  });
1649
2080
  }
2081
+ getSlots() {
2082
+ return [this.state.slot];
2083
+ }
1650
2084
  setup() {
1651
2085
  const textbus = core$1.useContext();
1652
2086
  const commander = core$1.useContext(core$1.Commander);
1653
2087
  const selection = core$1.useContext(core$1.Selection);
1654
2088
  core$1.onBreak(ev => {
1655
2089
  const slot = ev.target.cut(ev.data.index);
2090
+ slot.removeAttribute(headingAttr);
1656
2091
  if (ev.target.isEmpty && slot.isEmpty) {
1657
2092
  const beforeIndex = this.parent.indexOf(this);
1658
2093
  const beforeComponent = this.parent.getContentAtIndex(beforeIndex - 1);
@@ -1700,21 +2135,32 @@ class TodolistComponent extends core$1.Component {
1700
2135
  TodolistComponent.type = core$1.ContentType.BlockComponent;
1701
2136
  TodolistComponent.componentName = 'TodoListComponent';
1702
2137
  TodolistComponent.zenCoding = {
1703
- match: /^\[(x|\s)?\]$/,
2138
+ match(content, textbus) {
2139
+ const selection = textbus.get(core$1.Selection);
2140
+ if (selection.commonAncestorComponent instanceof ParagraphComponent) {
2141
+ return /^\[(x|\s)?\]$/.test(content);
2142
+ }
2143
+ return false;
2144
+ },
1704
2145
  key: ' ',
1705
- createState(content) {
2146
+ createState(content, textbus) {
2147
+ const selection = textbus.get(core$1.Selection);
2148
+ const commonAncestorSlot = selection.commonAncestorSlot;
2149
+ const slot = new core$1.Slot([
2150
+ core$1.ContentType.InlineComponent,
2151
+ core$1.ContentType.Text
2152
+ ]);
2153
+ if (commonAncestorSlot === null || commonAncestorSlot === void 0 ? void 0 : commonAncestorSlot.hasAttribute(textIndentAttr)) {
2154
+ slot.setAttribute(textIndentAttr, commonAncestorSlot.getAttribute(textIndentAttr));
2155
+ }
1706
2156
  const isChecked = content.charAt(1) === 'x';
1707
2157
  return {
1708
2158
  checked: isChecked,
1709
- slot: new core$1.Slot([
1710
- core$1.ContentType.InlineComponent,
1711
- core$1.ContentType.Text
1712
- ])
2159
+ slot
1713
2160
  };
1714
2161
  }
1715
2162
  };
1716
2163
  function TodolistView(props) {
1717
- const adapter = core.inject(platformBrowser.DomAdapter);
1718
2164
  const component = props.component;
1719
2165
  const state = component.state;
1720
2166
  function toggle() {
@@ -1743,11 +2189,7 @@ function TodolistView(props) {
1743
2189
  marginLeft: indent * 24 + 'px',
1744
2190
  justifyContent: align[component.state.slot.getAttribute(textAlignAttr)],
1745
2191
  textAlign: component.state.slot.getAttribute(textAlignAttr) === 'justify' ? 'justify' : void 0
1746
- }, children: [jsxRuntime.jsx("div", { class: "xnote-todolist-icon", onClick: toggle, children: jsxRuntime.jsx("span", { "data-checked": checked, class: [checked ? 'xnote-icon-checkbox-checked' : 'xnote-icon-checkbox-unchecked'] }) }), adapter.slotRender(slot, children => {
1747
- return core$1.createVNode('div', {
1748
- class: 'xnote-todolist-content'
1749
- }, children);
1750
- }, readonly() || output())] }));
2192
+ }, children: [jsxRuntime.jsx("div", { class: "xnote-todolist-icon", onClick: toggle, children: jsxRuntime.jsx("span", { "data-checked": checked, class: [checked ? 'xnote-icon-checkbox-checked' : 'xnote-icon-checkbox-unchecked'] }) }), jsxRuntime.jsx(SlotRender, { slot: slot, tag: 'div', class: 'xnote-todolist-content', renderEnv: readonly() || output() })] }));
1751
2193
  };
1752
2194
  }
1753
2195
  const todolistComponentLoader = {
@@ -1766,68 +2208,40 @@ const todolistComponentLoader = {
1766
2208
  }
1767
2209
  };
1768
2210
 
1769
- class BlockquoteComponent extends core$1.Component {
1770
- static fromJSON(textbus, json) {
1771
- const slot = textbus.get(core$1.Registry).createSlot(json.slot);
1772
- return new BlockquoteComponent(textbus, {
1773
- slot
1774
- });
1775
- }
1776
- constructor(textbus, state = {
1777
- slot: new core$1.Slot([
1778
- core$1.ContentType.BlockComponent
1779
- ])
1780
- }) {
1781
- super(textbus, state);
1782
- }
1783
- setup() {
1784
- useBlockContent(this.state.slot);
1785
- }
2211
+ function toList(textbus, type) {
2212
+ const commander = textbus.get(core$1.Commander);
2213
+ commander.transform({
2214
+ targetType: ListComponent.type,
2215
+ slotFactory() {
2216
+ return new core$1.Slot([
2217
+ core$1.ContentType.InlineComponent,
2218
+ core$1.ContentType.Text
2219
+ ]);
2220
+ },
2221
+ stateFactory(slots) {
2222
+ return slots.map((slot, index) => {
2223
+ return new ListComponent(textbus, {
2224
+ type,
2225
+ reorder: index === 0,
2226
+ slot
2227
+ });
2228
+ });
2229
+ }
2230
+ });
1786
2231
  }
1787
- BlockquoteComponent.type = core$1.ContentType.BlockComponent;
1788
- BlockquoteComponent.componentName = 'BlockquoteComponent';
1789
- BlockquoteComponent.zenCoding = {
1790
- key: ' ',
1791
- match: /^>$/,
1792
- createState() {
1793
- return {
1794
- slot: new core$1.Slot([
1795
- core$1.ContentType.BlockComponent
1796
- ])
1797
- };
1798
- }
1799
- };
1800
- function BlockquoteView(props) {
1801
- const adapter = core.inject(platformBrowser.DomAdapter);
1802
- const readonly = useReadonly();
1803
- const output = useOutput();
1804
- return () => {
1805
- const slot = props.component.state.slot;
1806
- return (jsxRuntime.jsx("blockquote", { class: "xnote-blockquote", ref: props.rootRef, "data-component": props.component.name, children: adapter.slotRender(slot, children => {
1807
- return core$1.createVNode('div', null, children);
1808
- }, readonly() || output()) }));
1809
- };
2232
+ function registerListShortcut(textbus) {
2233
+ const keyboard = textbus.get(core$1.Keyboard);
2234
+ keyboard.addShortcut({
2235
+ keymap: {
2236
+ key: ['o', 'u'],
2237
+ ctrlKey: true,
2238
+ shiftKey: true
2239
+ },
2240
+ action(key) {
2241
+ toList(textbus, key === 'o' ? 'OrderedList' : 'UnorderedList');
2242
+ }
2243
+ });
1810
2244
  }
1811
- const blockquoteComponentLoader = {
1812
- match(element) {
1813
- return element.tagName === 'BLOCKQUOTE';
1814
- },
1815
- read(element, textbus, slotParser) {
1816
- const delta = slotParser(new core$1.Slot([
1817
- core$1.ContentType.BlockComponent,
1818
- ]), element).toDelta();
1819
- const slot = new core$1.Slot([
1820
- core$1.ContentType.BlockComponent,
1821
- ]);
1822
- deltaToBlock(delta, textbus).forEach(i => {
1823
- slot.insert(i);
1824
- });
1825
- return new BlockquoteComponent(textbus, {
1826
- slot
1827
- });
1828
- },
1829
- };
1830
-
1831
2245
  class ListComponent extends core$1.Component {
1832
2246
  static fromJSON(textbus, json) {
1833
2247
  return new ListComponent(textbus, {
@@ -1836,6 +2250,9 @@ class ListComponent extends core$1.Component {
1836
2250
  slot: textbus.get(core$1.Registry).createSlot(json.slot)
1837
2251
  });
1838
2252
  }
2253
+ getSlots() {
2254
+ return [this.state.slot];
2255
+ }
1839
2256
  setup() {
1840
2257
  const textbus = core$1.useContext();
1841
2258
  const commander = core$1.useContext(core$1.Commander);
@@ -1849,8 +2266,7 @@ class ListComponent extends core$1.Component {
1849
2266
  const afterContent = parentSlot.sliceContent(index + 1);
1850
2267
  for (const item of afterContent) {
1851
2268
  if (item instanceof ListComponent &&
1852
- item.state.type === 'OrderedList' &&
1853
- item.state.slot.getAttribute(textIndentAttr) === this.state.slot.getAttribute(textIndentAttr)) {
2269
+ item.state.type === 'OrderedList') {
1854
2270
  if (item.state.reorder) {
1855
2271
  break;
1856
2272
  }
@@ -1863,6 +2279,7 @@ class ListComponent extends core$1.Component {
1863
2279
  });
1864
2280
  core$1.onBreak(ev => {
1865
2281
  const slot = ev.target.cut(ev.data.index);
2282
+ slot.removeAttribute(headingAttr);
1866
2283
  if (ev.target.isEmpty && slot.isEmpty) {
1867
2284
  const beforeIndex = this.parent.indexOf(this);
1868
2285
  const beforeComponent = this.parent.getContentAtIndex(beforeIndex - 1);
@@ -1913,7 +2330,7 @@ class ListComponent extends core$1.Component {
1913
2330
  key: 'Tab'
1914
2331
  },
1915
2332
  action: () => {
1916
- updateAfterList(this);
2333
+ Promise.resolve().then(() => updateAfterList(this));
1917
2334
  return false;
1918
2335
  }
1919
2336
  });
@@ -1933,15 +2350,27 @@ ListComponent.componentName = 'ListComponent';
1933
2350
  ListComponent.type = core$1.ContentType.BlockComponent;
1934
2351
  ListComponent.zenCoding = {
1935
2352
  key: ' ',
1936
- match: /^([1-9]\.|[+*])$/,
1937
- createState(content) {
2353
+ match(content, textbus) {
2354
+ const selection = textbus.get(core$1.Selection);
2355
+ if (selection.commonAncestorComponent instanceof ParagraphComponent) {
2356
+ return /^([1-9]\.|[+*-])$/.test(content);
2357
+ }
2358
+ return false;
2359
+ },
2360
+ createState(content, textbus) {
2361
+ const selection = textbus.get(core$1.Selection);
2362
+ const commonAncestorSlot = selection.commonAncestorSlot;
2363
+ const slot = new core$1.Slot([
2364
+ core$1.ContentType.InlineComponent,
2365
+ core$1.ContentType.Text
2366
+ ]);
2367
+ if (commonAncestorSlot === null || commonAncestorSlot === void 0 ? void 0 : commonAncestorSlot.hasAttribute(textIndentAttr)) {
2368
+ slot.setAttribute(textIndentAttr, commonAncestorSlot.getAttribute(textIndentAttr));
2369
+ }
1938
2370
  return {
1939
2371
  type: /[-+*]/.test(content) ? 'UnorderedList' : 'OrderedList',
1940
2372
  reorder: true,
1941
- slot: new core$1.Slot([
1942
- core$1.ContentType.InlineComponent,
1943
- core$1.ContentType.Text
1944
- ])
2373
+ slot
1945
2374
  };
1946
2375
  }
1947
2376
  };
@@ -1963,7 +2392,6 @@ function numberToLetter(num) {
1963
2392
  }).join('');
1964
2393
  }
1965
2394
  function ListComponentView(props) {
1966
- const adapter = core.inject(platformBrowser.DomAdapter);
1967
2395
  const component = props.component;
1968
2396
  function reorder(is) {
1969
2397
  component.state.reorder = is;
@@ -1990,7 +2418,8 @@ function ListComponentView(props) {
1990
2418
  return () => {
1991
2419
  const ListType = component.state.type === 'UnorderedList' ? 'ul' : 'ol';
1992
2420
  const ulIcons = ['•', '◦', '▪'];
1993
- let icon = '';
2421
+ let icon;
2422
+ let listStep = 0;
1994
2423
  const indent = component.state.slot.getAttribute(textIndentAttr) || 0;
1995
2424
  if (ListType === 'ul') {
1996
2425
  icon = ulIcons[indent % 3];
@@ -1998,7 +2427,6 @@ function ListComponentView(props) {
1998
2427
  else {
1999
2428
  const parentSlot = component.parent;
2000
2429
  const index = parentSlot.indexOf(component);
2001
- let listStep = 0;
2002
2430
  if (!component.state.reorder) {
2003
2431
  const beforeContent = parentSlot.sliceContent(0, index);
2004
2432
  while (beforeContent.length) {
@@ -2029,7 +2457,7 @@ function ListComponentView(props) {
2029
2457
  icon = numberToLetter(listStep) + '.';
2030
2458
  }
2031
2459
  }
2032
- return (jsxRuntime.jsx(ListType, { ref: props.rootRef, "data-component": component.name, class: "xnote-list", style: {
2460
+ return (jsxRuntime.jsx(ListType, { ref: props.rootRef, "data-component": component.name, "data-reorder": (listStep === 0) + '', class: "xnote-list", style: {
2033
2461
  marginLeft: indent * 24 + 'px'
2034
2462
  }, children: jsxRuntime.jsxs("li", { style: {
2035
2463
  justifyContent: align[component.state.slot.getAttribute(textAlignAttr)],
@@ -2037,16 +2465,12 @@ function ListComponentView(props) {
2037
2465
  }, children: [jsxRuntime.jsx("div", { class: "xnote-list-type", children: (component.state.type === 'UnorderedList' || readonly() || output()) ?
2038
2466
  jsxRuntime.jsx("span", { class: "xnote-order-btn", children: icon })
2039
2467
  :
2040
- jsxRuntime.jsx(Dropdown, { menu: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MenuItem, { onClick: () => reorder(false), children: "\u7EE7\u7EED\u7F16\u53F7" }), jsxRuntime.jsx(MenuItem, { onClick: () => reorder(true), children: "\u91CD\u65B0\u7F16\u53F7" })] }), children: jsxRuntime.jsx(Button, { style: { color: 'inherit' }, children: icon }) }) }), adapter.slotRender(component.state.slot, children => {
2041
- return core$1.createVNode('div', {
2042
- class: 'xnote-list-content'
2043
- }, children);
2044
- }, readonly() || output())] }) }));
2468
+ jsxRuntime.jsx(Dropdown, { menu: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MenuItem, { onClick: () => reorder(false), children: "\u7EE7\u7EED\u7F16\u53F7" }), jsxRuntime.jsx(MenuItem, { onClick: () => reorder(true), children: "\u91CD\u65B0\u7F16\u53F7" })] }), children: jsxRuntime.jsx(Button, { style: { color: 'inherit' }, children: icon }) }) }), jsxRuntime.jsx(SlotRender, { slot: component.state.slot, class: 'xnote-list-content', renderEnv: readonly() || output() })] }) }));
2045
2469
  };
2046
2470
  }
2047
2471
  const listComponentLoader = {
2048
- match(element) {
2049
- return element.tagName === 'UL' || element.tagName === 'OL';
2472
+ match(element, returnableContentTypes) {
2473
+ return returnableContentTypes.includes(core$1.ContentType.BlockComponent) && (element.tagName === 'UL' || element.tagName === 'OL');
2050
2474
  },
2051
2475
  read(element, textbus, slotParser) {
2052
2476
  const type = element.tagName === 'OL' ? 'OrderedList' : 'UnorderedList';
@@ -2057,7 +2481,7 @@ const listComponentLoader = {
2057
2481
  ]), element.querySelector('.xnote-list-content') || document.createElement('div'));
2058
2482
  return new ListComponent(textbus, {
2059
2483
  slot,
2060
- reorder: true,
2484
+ reorder: element.dataset.reorder !== 'false',
2061
2485
  type
2062
2486
  });
2063
2487
  }
@@ -2100,119 +2524,58 @@ function useActiveBlock() {
2100
2524
  sourceCode: false,
2101
2525
  highlightBox: false
2102
2526
  });
2103
- function updateCheckStates() {
2527
+ function updateCheckStates(range) {
2104
2528
  setCheckStates(draft => {
2105
- const heading = query.queryAttribute(headingAttr);
2106
- draft.paragraph = query.queryComponent(ParagraphComponent).state === core$1.QueryStateType.Enabled;
2529
+ const heading = query.queryAttributeByRange(headingAttr, range);
2530
+ draft.paragraph = query.queryComponentByRange(ParagraphComponent, range).state === core$1.QueryStateType.Enabled;
2107
2531
  draft.h1 = draft.h2 = draft.h3 = draft.h4 = draft.h5 = draft.h6 = false;
2108
2532
  if (heading.state === core$1.QueryStateType.Enabled) {
2109
2533
  draft[heading.value] = true;
2110
2534
  draft.paragraph = false;
2111
2535
  }
2112
- const queryList = query.queryComponent(ListComponent);
2536
+ const queryList = query.queryComponentByRange(ListComponent, range);
2113
2537
  draft.unorderedList = queryList.state === core$1.QueryStateType.Enabled && queryList.value.state.type === 'UnorderedList';
2114
2538
  draft.orderedList = queryList.state === core$1.QueryStateType.Enabled && queryList.value.state.type === 'OrderedList';
2115
- draft.table = query.queryComponent(TableComponent).state === core$1.QueryStateType.Enabled;
2116
- draft.todolist = query.queryComponent(TodolistComponent).state === core$1.QueryStateType.Enabled;
2117
- draft.blockquote = query.queryComponent(BlockquoteComponent).state === core$1.QueryStateType.Enabled;
2118
- draft.sourceCode = query.queryComponent(SourceCodeComponent).state === core$1.QueryStateType.Enabled;
2539
+ draft.table = query.queryComponentByRange(TableComponent, range).state === core$1.QueryStateType.Enabled;
2540
+ draft.todolist = query.queryComponentByRange(TodolistComponent, range).state === core$1.QueryStateType.Enabled;
2541
+ draft.blockquote = query.queryComponentByRange(BlockquoteComponent, range).state === core$1.QueryStateType.Enabled;
2542
+ draft.sourceCode = query.queryComponentByRange(SourceCodeComponent, range).state === core$1.QueryStateType.Enabled;
2119
2543
  });
2120
2544
  }
2121
- updateCheckStates();
2122
2545
  const subscription = refreshService.onRefresh.subscribe(() => {
2123
- updateCheckStates();
2546
+ if (!selection.isSelected) {
2547
+ return;
2548
+ }
2549
+ updateCheckStates({
2550
+ startOffset: selection.startOffset,
2551
+ startSlot: selection.startSlot,
2552
+ endSlot: selection.endSlot,
2553
+ endOffset: selection.endOffset
2554
+ });
2124
2555
  });
2125
2556
  core.onUnmounted(() => {
2126
2557
  subscription.unsubscribe();
2127
2558
  });
2128
2559
  return function (slot = null) {
2129
2560
  if (slot) {
2130
- const snapshot = selection.createSnapshot();
2131
- selection.setBaseAndExtent(slot, 0, slot, slot.length);
2132
- updateCheckStates();
2133
- snapshot.restore();
2561
+ updateCheckStates({
2562
+ startOffset: 0,
2563
+ endOffset: slot.length,
2564
+ startSlot: slot,
2565
+ endSlot: slot
2566
+ });
2134
2567
  }
2135
- return checkStates();
2136
- };
2137
- }
2138
-
2139
- class HighlightBoxComponent extends core$1.Component {
2140
- static fromJSON(textbus, json) {
2141
- return new HighlightBoxComponent(textbus, {
2142
- type: json.type,
2143
- slot: textbus.get(core$1.Registry).createSlot(json.slot)
2144
- });
2145
- }
2146
- constructor(textbus, state = {
2147
- type: '',
2148
- slot: new core$1.Slot([
2149
- core$1.ContentType.BlockComponent,
2150
- ])
2151
- }) {
2152
- super(textbus, state);
2153
- }
2154
- setup() {
2155
- useBlockContent(this.state.slot);
2156
- }
2157
- }
2158
- HighlightBoxComponent.defaultTypes = ['❤️', '💡', '📌', '✅', '❎', '👍', '🎉', '🚫', '❗'];
2159
- HighlightBoxComponent.componentName = 'HighlightBoxComponent';
2160
- HighlightBoxComponent.type = core$1.ContentType.BlockComponent;
2161
- function HighlightBoxView(props) {
2162
- const adapter = core.inject(platformBrowser.DomAdapter);
2163
- const readonly = useReadonly();
2164
- const output = useOutput();
2165
- const emoji = [];
2166
- for (let i = 0x1F600; i <= 0x1F64F; i++) {
2167
- emoji.push(i);
2168
- }
2169
- const dropdownRef = core.createRef();
2170
- function setType(type) {
2171
- var _a;
2172
- (_a = dropdownRef.current) === null || _a === void 0 ? void 0 : _a.isShow(false);
2173
- props.component.state.type = type;
2174
- }
2175
- return () => {
2176
- const { state, name } = props.component;
2177
- if (readonly() || output()) {
2178
- return (jsxRuntime.jsxs("div", { "data-component": name, ref: props.rootRef, "data-icon": state.type, class: "xnote-highlight-box", children: [jsxRuntime.jsx("div", { class: "xnote-highlight-box-left", children: jsxRuntime.jsx("div", { class: "xnote-highlight-box-icon", children: jsxRuntime.jsx("button", { type: "button", children: state.type || '❤️' }) }) }), adapter.slotRender(state.slot, children => {
2179
- return core$1.createVNode('div', {
2180
- class: 'xnote-highlight-box-content'
2181
- }, children);
2182
- }, readonly() || output())] }));
2568
+ else if (selection.isSelected) {
2569
+ updateCheckStates({
2570
+ startOffset: selection.startOffset,
2571
+ startSlot: selection.startSlot,
2572
+ endSlot: selection.endSlot,
2573
+ endOffset: selection.endOffset
2574
+ });
2183
2575
  }
2184
- return (jsxRuntime.jsxs("div", { "data-component": name, ref: props.rootRef, "data-icon": state.type, class: "xnote-highlight-box", children: [jsxRuntime.jsx("div", { class: "xnote-highlight-box-left", children: jsxRuntime.jsx(Dropdown, { trigger: "click", ref: dropdownRef, width: "260px", menu: jsxRuntime.jsxs("div", { class: "xnote-highlight-box-icons", children: [HighlightBoxComponent.defaultTypes.map(icon => {
2185
- return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
2186
- }), jsxRuntime.jsx(Divider, {}), emoji.map(i => {
2187
- const icon = String.fromCodePoint(i);
2188
- return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
2189
- })] }), children: jsxRuntime.jsx("div", { class: "xnote-highlight-box-icon", children: jsxRuntime.jsx("button", { type: "button", children: state.type || '❤️' }) }) }) }), adapter.slotRender(state.slot, children => {
2190
- return core$1.createVNode('div', {
2191
- class: 'xnote-highlight-box-content'
2192
- }, children);
2193
- }, readonly() || output())] }));
2576
+ return checkStates();
2194
2577
  };
2195
2578
  }
2196
- const highlightBoxComponentLoader = {
2197
- match(element) {
2198
- return element.tagName === 'DIV' && element.dataset.component === HighlightBoxComponent.componentName;
2199
- },
2200
- read(element, textbus, slotParser) {
2201
- const delta = slotParser(new core$1.Slot([
2202
- core$1.ContentType.BlockComponent,
2203
- ]), element.querySelector('.xnote-highlight-box-content')).toDelta();
2204
- const slot = new core$1.Slot([
2205
- core$1.ContentType.BlockComponent,
2206
- ]);
2207
- deltaToBlock(delta, textbus).forEach(i => {
2208
- slot.insert(i);
2209
- });
2210
- return new HighlightBoxComponent(textbus, {
2211
- type: element.dataset.icon || '',
2212
- slot
2213
- });
2214
- }
2215
- };
2216
2579
 
2217
2580
  function useBlockTransform() {
2218
2581
  const commander = core.inject(core$1.Commander);
@@ -2280,62 +2643,10 @@ function useBlockTransform() {
2280
2643
  break;
2281
2644
  case 'ol':
2282
2645
  case 'ul':
2283
- {
2284
- commander.transform({
2285
- targetType: ListComponent.type,
2286
- slotFactory() {
2287
- return new core$1.Slot([
2288
- core$1.ContentType.InlineComponent,
2289
- core$1.ContentType.Text
2290
- ]);
2291
- },
2292
- stateFactory(slots) {
2293
- return slots.map((slot, index) => {
2294
- return new ListComponent(textbus, {
2295
- type: value === 'ol' ? 'OrderedList' : 'UnorderedList',
2296
- reorder: index === 0,
2297
- slot
2298
- });
2299
- });
2300
- }
2301
- });
2302
- }
2646
+ toList(textbus, value === 'ol' ? 'OrderedList' : 'UnorderedList');
2303
2647
  break;
2304
2648
  case 'blockquote':
2305
- {
2306
- const state = query.queryComponent(BlockquoteComponent);
2307
- if (state.state === core$1.QueryStateType.Enabled) {
2308
- const current = state.value;
2309
- const parent = current.parent;
2310
- const index = parent.indexOf(current);
2311
- parent.retain(index);
2312
- commander.removeComponent(current);
2313
- current.__slots__.get(0).sliceContent().forEach(i => {
2314
- parent.insert(i);
2315
- });
2316
- }
2317
- else {
2318
- const block = new BlockquoteComponent(textbus);
2319
- const slot = block.state.slot;
2320
- if (selection.startSlot === selection.endSlot) {
2321
- const parentComponent = selection.startSlot.parent;
2322
- const parentSlot = parentComponent.parent;
2323
- const position = parentSlot.indexOf(parentComponent);
2324
- slot.insert(parentComponent);
2325
- parentSlot.retain(position);
2326
- parentSlot.insert(block);
2327
- }
2328
- else {
2329
- const commonAncestorSlot = selection.commonAncestorSlot;
2330
- const scope = selection.getCommonAncestorSlotScope();
2331
- commonAncestorSlot.cut(scope.startOffset, scope.endOffset).sliceContent().forEach(i => {
2332
- slot.insert(i);
2333
- });
2334
- commonAncestorSlot.retain(scope.startOffset);
2335
- commonAncestorSlot.insert(block);
2336
- }
2337
- }
2338
- }
2649
+ toBlockquote(textbus);
2339
2650
  break;
2340
2651
  case 'sourceCode':
2341
2652
  {
@@ -2372,6 +2683,8 @@ function useBlockTransform() {
2372
2683
  lineNumber: true,
2373
2684
  autoBreak: true,
2374
2685
  slots: slots.map(slot => {
2686
+ slot.cleanFormats();
2687
+ slot.cleanAttributes();
2375
2688
  return {
2376
2689
  slot,
2377
2690
  emphasize: false
@@ -2392,7 +2705,7 @@ function useBlockTransform() {
2392
2705
  const index = parent.indexOf(current);
2393
2706
  parent.retain(index);
2394
2707
  commander.removeComponent(current);
2395
- current.__slots__.get(0).sliceContent().forEach(i => {
2708
+ current.slots.at(0).sliceContent().forEach(i => {
2396
2709
  parent.insert(i);
2397
2710
  });
2398
2711
  }
@@ -2426,7 +2739,7 @@ function useBlockTransform() {
2426
2739
  function BlockTool() {
2427
2740
  const checkStates = useActiveBlock();
2428
2741
  const transform = useBlockTransform();
2429
- return scopedCss.withScopedCSS(scopedId$b, () => {
2742
+ return scopedCss.withScopedCSS(scopedId$c, () => {
2430
2743
  const states = checkStates();
2431
2744
  const types = [
2432
2745
  [states.paragraph, 'xnote-icon-pilcrow'],
@@ -2441,7 +2754,7 @@ function BlockTool() {
2441
2754
  [states.todolist, 'xnote-icon-checkbox-checked'],
2442
2755
  [states.blockquote, 'xnote-icon-quotes-right'],
2443
2756
  [states.sourceCode, 'xnote-icon-source-code'],
2444
- [states.highlightBox, 'xnote-icon-paint-bucket'],
2757
+ [states.highlightBox, 'xnote-icon-highlight-box'],
2445
2758
  ];
2446
2759
  let currentType = 'xnote-icon-pilcrow';
2447
2760
  for (const t of types) {
@@ -2450,27 +2763,48 @@ function BlockTool() {
2450
2763
  break;
2451
2764
  }
2452
2765
  }
2453
- return (jsxRuntime.jsx(Dropdown, { onCheck: transform, trigger: 'hover', menu: [
2766
+ return (jsxRuntime.jsx(Dropdown, { width: 'auto', onCheck: transform, trigger: 'hover', menu: [
2454
2767
  {
2455
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" }), checked: states.paragraph, children: "\u6B63\u6587" }),
2768
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" }), desc: jsxRuntime.jsx(Keymap, { keymap: {
2769
+ ctrlKey: true,
2770
+ key: '0'
2771
+ } }), checked: states.paragraph, children: "\u6B63\u6587" }),
2456
2772
  value: 'paragraph'
2457
2773
  }, {
2458
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h1" }), checked: states.h1, children: "\u4E00\u7EA7\u6807\u9898" }),
2774
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h1" }), desc: jsxRuntime.jsx(Keymap, { keymap: {
2775
+ ctrlKey: true,
2776
+ key: '1'
2777
+ } }), checked: states.h1, children: "\u4E00\u7EA7\u6807\u9898" }),
2459
2778
  value: 'h1'
2460
2779
  }, {
2461
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h2" }), checked: states.h2, children: "\u4E8C\u7EA7\u6807\u9898" }),
2780
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h2" }), desc: jsxRuntime.jsx(Keymap, { keymap: {
2781
+ ctrlKey: true,
2782
+ key: '2'
2783
+ } }), checked: states.h2, children: "\u4E8C\u7EA7\u6807\u9898" }),
2462
2784
  value: 'h2'
2463
2785
  }, {
2464
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h3" }), checked: states.h3, children: "\u4E09\u7EA7\u6807\u9898" }),
2786
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h3" }), desc: jsxRuntime.jsx(Keymap, { keymap: {
2787
+ ctrlKey: true,
2788
+ key: '3'
2789
+ } }), checked: states.h3, children: "\u4E09\u7EA7\u6807\u9898" }),
2465
2790
  value: 'h3'
2466
2791
  }, {
2467
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h4" }), checked: states.h4, children: "\u56DB\u7EA7\u6807\u9898" }),
2792
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h4" }), desc: jsxRuntime.jsx(Keymap, { keymap: {
2793
+ ctrlKey: true,
2794
+ key: '4'
2795
+ } }), checked: states.h4, children: "\u56DB\u7EA7\u6807\u9898" }),
2468
2796
  value: 'h4'
2469
2797
  }, {
2470
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h5" }), checked: states.h5, children: "\u4E94\u7EA7\u6807\u9898" }),
2798
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h5" }), desc: jsxRuntime.jsx(Keymap, { keymap: {
2799
+ ctrlKey: true,
2800
+ key: '5'
2801
+ } }), checked: states.h5, children: "\u4E94\u7EA7\u6807\u9898" }),
2471
2802
  value: 'h5'
2472
2803
  }, {
2473
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h6" }), checked: states.h6, children: "\u516D\u7EA7\u6807\u9898" }),
2804
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h6" }), desc: jsxRuntime.jsx(Keymap, { keymap: {
2805
+ ctrlKey: true,
2806
+ key: '6'
2807
+ } }), checked: states.h6, children: "\u516D\u7EA7\u6807\u9898" }),
2474
2808
  value: 'h6'
2475
2809
  }, {
2476
2810
  label: jsxRuntime.jsx(Divider, {}),
@@ -2479,19 +2813,19 @@ function BlockTool() {
2479
2813
  label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-checkbox-checked" }), checked: states.todolist, children: "\u5F85\u529E\u4E8B\u9879" }),
2480
2814
  value: 'todolist'
2481
2815
  }, {
2482
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-list-numbered" }), checked: states.orderedList, children: "\u6709\u5E8F\u5217\u8868" }),
2816
+ label: jsxRuntime.jsx(MenuItem, { desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'O', shiftKey: true, ctrlKey: true } }), icon: jsxRuntime.jsx("span", { class: "xnote-icon-list-numbered" }), checked: states.orderedList, children: "\u6709\u5E8F\u5217\u8868" }),
2483
2817
  value: 'ol'
2484
2818
  }, {
2485
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-list" }), checked: states.unorderedList, children: "\u65E0\u5E8F\u5217\u8868" }),
2819
+ label: jsxRuntime.jsx(MenuItem, { desc: jsxRuntime.jsx(Keymap, { keymap: { key: 'U', shiftKey: true, ctrlKey: true } }), icon: jsxRuntime.jsx("span", { class: "xnote-icon-list" }), checked: states.unorderedList, children: "\u65E0\u5E8F\u5217\u8868" }),
2486
2820
  value: 'ul'
2487
2821
  }, {
2488
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-quotes-right" }), checked: states.blockquote, children: "\u5F15\u7528" }),
2822
+ label: jsxRuntime.jsx(MenuItem, { desc: jsxRuntime.jsx(Keymap, { keymap: { key: '\'', ctrlKey: true } }), icon: jsxRuntime.jsx("span", { class: "xnote-icon-quotes-right" }), checked: states.blockquote, children: "\u5F15\u7528" }),
2489
2823
  value: 'blockquote'
2490
2824
  }, {
2491
2825
  label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-source-code" }), checked: states.sourceCode, children: "\u4EE3\u7801\u5757" }),
2492
2826
  value: 'sourceCode'
2493
2827
  }, {
2494
- label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-paint-bucket" }), checked: states.highlightBox, children: "\u9AD8\u4EAE\u5757" }),
2828
+ label: jsxRuntime.jsx(MenuItem, { icon: jsxRuntime.jsx("span", { class: "xnote-icon-hightlight-box" }), checked: states.highlightBox, children: "\u9AD8\u4EAE\u5757" }),
2495
2829
  value: 'highlightBox'
2496
2830
  }
2497
2831
  ], children: jsxRuntime.jsx(Button, { arrow: true, highlight: false, children: jsxRuntime.jsx("span", { class: currentType }) }) }));
@@ -2857,12 +3191,13 @@ function CodeTool() {
2857
3191
  };
2858
3192
  }
2859
3193
 
2860
- var scopedId$a = "vf-1fbbdf";
3194
+ var scopedId$b = "vf-accb31";
2861
3195
 
2862
3196
  function ColorTool(props) {
2863
3197
  const query = core.inject(core$1.Query);
2864
3198
  const refreshService = core.inject(exports.RefreshService);
2865
3199
  const commander = core.inject(core$1.Commander);
3200
+ const selection = core.inject(core$1.Selection);
2866
3201
  const textColor = core.createSignal('');
2867
3202
  const backgroundColor = core.createSignal('');
2868
3203
  const [viewModel] = hooks.useProduce({
@@ -2870,13 +3205,24 @@ function ColorTool(props) {
2870
3205
  disabled: false,
2871
3206
  });
2872
3207
  function updateCheckState() {
2873
- var _a, _b;
2874
- (_a = props.queryBefore) === null || _a === void 0 ? void 0 : _a.call(props);
2875
- const textState = query.queryFormat(colorFormatter);
2876
- const backgroundState = query.queryFormat(backgroundColorFormatter);
3208
+ if (!props.slot && !selection.isSelected) {
3209
+ return;
3210
+ }
3211
+ const range = props.slot ? {
3212
+ startSlot: props.slot,
3213
+ endSlot: props.slot,
3214
+ startOffset: 0,
3215
+ endOffset: props.slot.length
3216
+ } : {
3217
+ startSlot: selection.startSlot,
3218
+ startOffset: selection.startOffset,
3219
+ endSlot: selection.endSlot,
3220
+ endOffset: selection.endOffset
3221
+ };
3222
+ const textState = query.queryFormatByRange(colorFormatter, range);
3223
+ const backgroundState = query.queryFormatByRange(backgroundColorFormatter, range);
2877
3224
  textColor.set(textState.state === core$1.QueryStateType.Enabled ? textState.value : '');
2878
3225
  backgroundColor.set(backgroundState.state === core$1.QueryStateType.Enabled ? backgroundState.value : '');
2879
- (_b = props.queryAfter) === null || _b === void 0 ? void 0 : _b.call(props);
2880
3226
  }
2881
3227
  const sub = refreshService.onRefresh.subscribe(() => {
2882
3228
  updateCheckState();
@@ -2886,6 +3232,7 @@ function ColorTool(props) {
2886
3232
  sub.unsubscribe();
2887
3233
  });
2888
3234
  const textColors = [
3235
+ '#000',
2889
3236
  '#aaa',
2890
3237
  '#ff2e2e',
2891
3238
  '#ff8d45',
@@ -2895,6 +3242,7 @@ function ColorTool(props) {
2895
3242
  '#1296db',
2896
3243
  '#617fff',
2897
3244
  '#c459ff',
3245
+ '#fff',
2898
3246
  ];
2899
3247
  const backgroundColors = [
2900
3248
  '#aaa',
@@ -2906,15 +3254,16 @@ function ColorTool(props) {
2906
3254
  '#90a0e5',
2907
3255
  '#c596e0',
2908
3256
  ];
2909
- return scopedCss.withScopedCSS(scopedId$a, () => {
3257
+ return scopedCss.withScopedCSS(scopedId$b, () => {
2910
3258
  const vm = viewModel();
2911
- return (jsxRuntime.jsx(Dropdown, { style: props.style, abreast: props.abreast, trigger: 'hover', menu: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { class: "color-type", children: "\u6587\u5B57\u989C\u8272" }), jsxRuntime.jsxs("div", { class: "text-colors", children: [jsxRuntime.jsx("div", { class: {
3259
+ return (jsxRuntime.jsx(Dropdown, { style: props.style, width: '180px', abreast: props.abreast, trigger: 'hover', menu: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { class: "color-type", children: "\u6587\u5B57\u989C\u8272" }), jsxRuntime.jsxs("div", { class: "text-colors", children: [jsxRuntime.jsx("div", { class: {
3260
+ 'no-background': true,
2912
3261
  active: textColor() === ''
2913
3262
  }, onClick: () => {
2914
3263
  var _a;
2915
3264
  (_a = props.applyBefore) === null || _a === void 0 ? void 0 : _a.call(props);
2916
3265
  commander.unApplyFormat(colorFormatter);
2917
- }, children: "A" }), textColors.map(c => {
3266
+ } }), textColors.map(c => {
2918
3267
  return jsxRuntime.jsx("div", { class: {
2919
3268
  active: textColor() === c
2920
3269
  }, onClick: () => {
@@ -2974,6 +3323,9 @@ const isSupportFont = (function () {
2974
3323
  function FontFamilyTool() {
2975
3324
  const currentFontFamily = core.createSignal('');
2976
3325
  const fontFamilyOptions = [{
3326
+ label: '默认',
3327
+ value: ''
3328
+ }, {
2977
3329
  label: '宋体',
2978
3330
  value: 'SimSun, STSong'
2979
3331
  }, {
@@ -3015,7 +3367,12 @@ function FontFamilyTool() {
3015
3367
  }];
3016
3368
  const commander = core.inject(core$1.Commander);
3017
3369
  function check(v) {
3018
- commander.applyFormat(fontFamilyFormatter, v);
3370
+ if (v) {
3371
+ commander.applyFormat(fontFamilyFormatter, v);
3372
+ }
3373
+ else {
3374
+ commander.unApplyFormat(fontFamilyFormatter);
3375
+ }
3019
3376
  }
3020
3377
  const refreshService = core.inject(exports.RefreshService);
3021
3378
  const query = core.inject(core$1.Query);
@@ -3024,7 +3381,7 @@ function FontFamilyTool() {
3024
3381
  const result = query.queryFormat(fontFamilyFormatter);
3025
3382
  const isHighlight = result.state === core$1.QueryStateType.Enabled;
3026
3383
  highlight.set(isHighlight);
3027
- currentFontFamily.set(isHighlight ? result.value : '默认');
3384
+ currentFontFamily.set(isHighlight ? result.value : '');
3028
3385
  });
3029
3386
  core.onUnmounted(() => {
3030
3387
  subscription.unsubscribe();
@@ -3032,7 +3389,7 @@ function FontFamilyTool() {
3032
3389
  return () => {
3033
3390
  var _a;
3034
3391
  return (jsxRuntime.jsx(Dropdown, { onCheck: check, menu: fontFamilyOptions.map(i => {
3035
- const disabled = !i.value.split(',').map(i => isSupportFont(i.trim())).some(v => v);
3392
+ const disabled = i.value ? !i.value.split(',').map(i => isSupportFont(i.trim())).some(v => v) : false;
3036
3393
  return {
3037
3394
  label: jsxRuntime.jsx(MenuItem, { disabled: disabled, checked: currentFontFamily() === i.value, children: i.label }),
3038
3395
  disabled,
@@ -3064,7 +3421,12 @@ function FontSizeTool() {
3064
3421
  ];
3065
3422
  const commander = core.inject(core$1.Commander);
3066
3423
  function check(v) {
3067
- commander.applyFormat(fontSizeFormatter, v);
3424
+ if (v) {
3425
+ commander.applyFormat(fontSizeFormatter, v);
3426
+ }
3427
+ else {
3428
+ commander.unApplyFormat(fontSizeFormatter);
3429
+ }
3068
3430
  }
3069
3431
  const refreshService = core.inject(exports.RefreshService);
3070
3432
  const query = core.inject(core$1.Query);
@@ -3114,12 +3476,30 @@ function ItalicTool() {
3114
3476
  };
3115
3477
  }
3116
3478
 
3117
- var scopedId$9 = "vf-269a0b";
3479
+ var scopedId$a = "vf-e74208";
3480
+
3481
+ exports.EditorService = class EditorService {
3482
+ constructor() {
3483
+ this.hideInlineToolbar = false;
3484
+ this.canShowLeftToolbar = true;
3485
+ this.onLeftToolbarCanVisibleChange = new core$1.Subject();
3486
+ }
3487
+ changeLeftToolbarVisible(b) {
3488
+ this.canShowLeftToolbar = b;
3489
+ this.onLeftToolbarCanVisibleChange.next();
3490
+ }
3491
+ };
3492
+ exports.EditorService = __decorate([
3493
+ core.Injectable({
3494
+ provideIn: 'root'
3495
+ })
3496
+ ], exports.EditorService);
3118
3497
 
3119
3498
  function LinkTool(props) {
3120
3499
  const selectionBridge = core.inject(platformBrowser.SelectionBridge);
3121
3500
  const selection = core.inject(core$1.Selection);
3122
3501
  const commander = core.inject(core$1.Commander);
3502
+ const editorService = core.inject(exports.EditorService);
3123
3503
  const container = core.inject(platformBrowser.VIEW_CONTAINER);
3124
3504
  const isShow = core.createSignal(false);
3125
3505
  const inputRef = core.createRef();
@@ -3140,22 +3520,24 @@ function LinkTool(props) {
3140
3520
  isClickFromSelf = false;
3141
3521
  return;
3142
3522
  }
3523
+ editorService.hideInlineToolbar = false;
3143
3524
  isShow.set(false);
3144
3525
  });
3145
3526
  core.onUnmounted(() => {
3146
3527
  sub.unsubscribe();
3147
3528
  });
3148
- return scopedCss.withScopedCSS(scopedId$9, () => {
3529
+ return scopedCss.withScopedCSS(scopedId$a, () => {
3149
3530
  const containerRect = container.getBoundingClientRect();
3150
3531
  const rect = isShow() ? selectionBridge.getRect({
3151
3532
  slot: selection.focusSlot,
3152
3533
  offset: selection.focusOffset
3153
3534
  }) : {};
3154
3535
  return (jsxRuntime.jsxs("span", { children: [jsxRuntime.jsx(Button, { onClick: () => {
3536
+ var _a;
3155
3537
  isShow.set(true);
3156
3538
  isClickFromSelf = true;
3157
- setTimeout(() => { var _a; return (_a = props.hideToolbar) === null || _a === void 0 ? void 0 : _a.call(props); }, 10);
3158
- }, arrow: true, children: jsxRuntime.jsx("span", { class: "xnote-icon-link" }) }), isShow() &&
3539
+ (_a = props.hideToolbar) === null || _a === void 0 ? void 0 : _a.call(props);
3540
+ }, children: jsxRuntime.jsx("span", { class: "xnote-icon-link" }) }), isShow() &&
3159
3541
  jsxRuntime.jsx(Popup, { left: rect.left - containerRect.left, top: rect.top + rect.height - containerRect.top, children: jsxRuntime.jsxs("form", { onSubmit: setLink, onClick: () => {
3160
3542
  isClickFromSelf = true;
3161
3543
  }, class: "input-group", children: [jsxRuntime.jsx("input", { ref: inputRef, placeholder: "\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740", type: "text" }), jsxRuntime.jsx(Button, { type: "submit", children: "\u786E\u5B9A" })] }) })] }));
@@ -3214,7 +3596,7 @@ function UnderlineTool() {
3214
3596
  };
3215
3597
  }
3216
3598
 
3217
- var scopedId$8 = "vf-cf8e1c";
3599
+ var scopedId$9 = "vf-cf8e1c";
3218
3600
 
3219
3601
  class FileUploader {
3220
3602
  }
@@ -3223,6 +3605,9 @@ class ImageComponent extends core$1.Component {
3223
3605
  static fromJSON(textbus, json) {
3224
3606
  return new ImageComponent(textbus, Object.assign({}, json));
3225
3607
  }
3608
+ getSlots() {
3609
+ return [];
3610
+ }
3226
3611
  }
3227
3612
  ImageComponent.type = core$1.ContentType.InlineComponent;
3228
3613
  ImageComponent.componentName = 'ImageComponent';
@@ -3249,9 +3634,11 @@ const imageComponentLoader = {
3249
3634
  return element.tagName === 'IMG' || element.dataset.component === ImageComponent.componentName;
3250
3635
  },
3251
3636
  read(element, textbus) {
3252
- var _a;
3637
+ const img = element instanceof HTMLImageElement ? element : (element.querySelector('img') || document.createElement('img'));
3253
3638
  return new ImageComponent(textbus, {
3254
- src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('img')) === null || _a === void 0 ? void 0 : _a.src) || ''
3639
+ src: img.src,
3640
+ width: img.style.width || 'auto',
3641
+ height: img.style.height || 'auto'
3255
3642
  });
3256
3643
  }
3257
3644
  };
@@ -3260,8 +3647,8 @@ class VideoComponent extends core$1.Component {
3260
3647
  static fromJSON(textbus, json) {
3261
3648
  return new VideoComponent(textbus, Object.assign({}, json));
3262
3649
  }
3263
- setup() {
3264
- //
3650
+ getSlots() {
3651
+ return [];
3265
3652
  }
3266
3653
  }
3267
3654
  VideoComponent.type = core$1.ContentType.InlineComponent;
@@ -3273,7 +3660,7 @@ function VideoView(props) {
3273
3660
  const output = useOutput();
3274
3661
  return () => {
3275
3662
  if (readonly() || output()) {
3276
- return (jsxRuntime.jsx("div", { class: "xnote-video", "data-component": name, children: jsxRuntime.jsx("video", { ref: videoRef, src: state.src, style: {
3663
+ return (jsxRuntime.jsx("div", { class: "xnote-video", ref: props.rootRef, "data-component": name, children: jsxRuntime.jsx("video", { ref: videoRef, src: state.src, style: {
3277
3664
  width: state.width,
3278
3665
  height: state.height
3279
3666
  } }) }));
@@ -3286,12 +3673,169 @@ function VideoView(props) {
3286
3673
  }
3287
3674
  const videoComponentLoader = {
3288
3675
  match(element) {
3289
- return element.tagName === 'IMG' || element.dataset.component === VideoComponent.componentName;
3676
+ return element.tagName === 'VIDEO' || element.dataset.component === VideoComponent.componentName;
3290
3677
  },
3291
3678
  read(element, textbus) {
3292
- var _a;
3679
+ const video = element instanceof HTMLVideoElement ? element : (element.querySelector('video') || document.createElement('video'));
3293
3680
  return new VideoComponent(textbus, {
3294
- src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('video')) === null || _a === void 0 ? void 0 : _a.src) || ''
3681
+ src: video.src,
3682
+ width: video.style.width || 'auto',
3683
+ height: video.style.height || 'auto'
3684
+ });
3685
+ }
3686
+ };
3687
+
3688
+ class KatexEditor extends core$1.Textbus {
3689
+ constructor() {
3690
+ const adapter = new adapterViewfly.ViewflyAdapter({
3691
+ [SourceCodeComponent.componentName]: SourceCodeView
3692
+ }, (host, root, injector) => {
3693
+ const appInjector = new core.ReflectiveInjector(injector, [{
3694
+ provide: OutputInjectionToken,
3695
+ useValue: true
3696
+ }]);
3697
+ const app = platformBrowser$1.createApp(root, {
3698
+ context: appInjector
3699
+ }).mount(host);
3700
+ return () => {
3701
+ app.destroy();
3702
+ };
3703
+ });
3704
+ const browserModule = new platformBrowser.BrowserModule({
3705
+ adapter,
3706
+ renderTo: () => {
3707
+ return this.host;
3708
+ }
3709
+ });
3710
+ super({
3711
+ components: [
3712
+ SourceCodeComponent
3713
+ ],
3714
+ imports: [browserModule]
3715
+ });
3716
+ this.onValueChange = new core$1.Subject();
3717
+ }
3718
+ mount(host, code) {
3719
+ this.host = host;
3720
+ const model = new SourceCodeComponent(this, {
3721
+ lineNumber: true,
3722
+ autoBreak: true,
3723
+ lang: 'latex',
3724
+ theme: 'github',
3725
+ slots: code.split('\n').map(i => {
3726
+ const slot = new core$1.Slot([core$1.ContentType.Text]);
3727
+ slot.insert(i);
3728
+ return {
3729
+ slot,
3730
+ emphasize: false
3731
+ };
3732
+ })
3733
+ });
3734
+ this.onChange.subscribe(() => {
3735
+ const str = model.state.slots.map(i => {
3736
+ if (i.slot.isEmpty) {
3737
+ return '';
3738
+ }
3739
+ return i.slot.toString();
3740
+ }).join('\n');
3741
+ this.onValueChange.next(str);
3742
+ });
3743
+ return this.render(model);
3744
+ }
3745
+ }
3746
+
3747
+ class KatexComponent extends core$1.Component {
3748
+ static fromJSON(textbus, state) {
3749
+ return new KatexComponent(textbus, state);
3750
+ }
3751
+ constructor(textbus, state = {
3752
+ text: '% \\f is defined as #1f(#2) using the macro\n' +
3753
+ '\\f\\relax{x} = \\int_{-\\infty}^\\infty\n' +
3754
+ '\\f\\hat\\xi\\,e^{2 \\pi i \\xi x}\n' +
3755
+ '\\,d\\xi'
3756
+ }) {
3757
+ super(textbus, state);
3758
+ }
3759
+ getSlots() {
3760
+ return [];
3761
+ }
3762
+ }
3763
+ KatexComponent.componentName = 'KatexComponent';
3764
+ KatexComponent.type = core$1.ContentType.InlineComponent;
3765
+ function domToVDom(el) {
3766
+ const attrs = {};
3767
+ el.getAttributeNames().forEach(key => {
3768
+ attrs[key] = el.getAttribute(key);
3769
+ });
3770
+ attrs.children = Array.from(el.childNodes).map(child => {
3771
+ if (child.nodeType === Node.ELEMENT_NODE) {
3772
+ return domToVDom(child);
3773
+ }
3774
+ return child.textContent || '';
3775
+ });
3776
+ return core.jsx(el.tagName.toLowerCase(), attrs);
3777
+ }
3778
+ function KatexComponentView(props) {
3779
+ function toDOM(value) {
3780
+ let htmlString;
3781
+ try {
3782
+ htmlString = Katex.renderToString(value, {
3783
+ displayMode: true,
3784
+ leqno: false,
3785
+ fleqn: false,
3786
+ throwOnError: true,
3787
+ errorColor: '#cc0000',
3788
+ strict: 'warn',
3789
+ output: 'html',
3790
+ trust: false,
3791
+ macros: { '\\f': '#1f(#2)' }
3792
+ });
3793
+ }
3794
+ catch (e) {
3795
+ htmlString = '<span style="color: red">公式错误</span>';
3796
+ }
3797
+ return new DOMParser().parseFromString(htmlString, 'text/html').body.children[0];
3798
+ }
3799
+ const selection = core.inject(core$1.Textbus);
3800
+ const editorRef = core.createDynamicRef(node => {
3801
+ const editor = new KatexEditor();
3802
+ editor.mount(node, props.component.state.text).then(() => {
3803
+ editor.focus();
3804
+ });
3805
+ selection.blur();
3806
+ const subscription = editor.onValueChange.subscribe((value) => {
3807
+ props.component.state.text = value;
3808
+ }).add(core$1.fromEvent(node, 'mousedown').subscribe(ev => ev.stopPropagation()), core$1.fromEvent(document, 'mousedown').subscribe(() => {
3809
+ var _a;
3810
+ (_a = dropdownRef.current) === null || _a === void 0 ? void 0 : _a.isShow(false);
3811
+ }));
3812
+ return () => {
3813
+ subscription.unsubscribe();
3814
+ editor.destroy();
3815
+ };
3816
+ });
3817
+ const dropdownRef = core.createRef();
3818
+ const output = useOutput();
3819
+ const readonly = useReadonly();
3820
+ return () => {
3821
+ const text = props.component.state.text;
3822
+ return (jsxRuntime.jsx("span", { onClick: () => {
3823
+ var _a;
3824
+ (_a = dropdownRef.current) === null || _a === void 0 ? void 0 : _a.isShow(true);
3825
+ }, ref: props.rootRef, "data-component": KatexComponent.componentName, "data-katex": encodeURIComponent(text), class: "xnote-katex", children: (output() || readonly()) ?
3826
+ domToVDom(toDOM(text))
3827
+ :
3828
+ jsxRuntime.jsx(Dropdown, { padding: '0', ref: dropdownRef, trigger: 'none', width: '600px', menu: jsxRuntime.jsx("div", { class: "xnote-katex-input", ref: editorRef }), children: domToVDom(toDOM(text)) }) }));
3829
+ };
3830
+ }
3831
+ const katexComponentLoader = {
3832
+ match(element) {
3833
+ return element.dataset.component === KatexComponent.componentName;
3834
+ },
3835
+ read(element, textbus) {
3836
+ const value = element.dataset.katex || '';
3837
+ return new KatexComponent(textbus, {
3838
+ text: decodeURIComponent(value)
3295
3839
  });
3296
3840
  }
3297
3841
  };
@@ -3300,7 +3844,8 @@ function InsertTool(props) {
3300
3844
  const commander = core.inject(core$1.Commander);
3301
3845
  const selection = core.inject(core$1.Selection);
3302
3846
  const textbus = core.inject(core$1.Textbus);
3303
- const fileUploader = core.inject(FileUploader, core.InjectFlags.Optional, null);
3847
+ const fileUploader = core.inject(FileUploader, null);
3848
+ const dropdownContextService = core.inject(exports.DropdownContextService);
3304
3849
  function insert(type) {
3305
3850
  var _a;
3306
3851
  const component = (_a = props.slot) === null || _a === void 0 ? void 0 : _a.parent;
@@ -3314,6 +3859,8 @@ function InsertTool(props) {
3314
3859
  else {
3315
3860
  commander.insertAfter(comp, component);
3316
3861
  }
3862
+ dropdownContextService.canHide = true;
3863
+ dropdownContextService.hide(false);
3317
3864
  }
3318
3865
  switch (type) {
3319
3866
  case 'h1':
@@ -3375,7 +3922,9 @@ function InsertTool(props) {
3375
3922
  {
3376
3923
  const table = new TableComponent(textbus);
3377
3924
  insertComponent(table);
3378
- selection.setPosition(table.state.rows[0].cells[0].slot, 0);
3925
+ textbus.nextTick(() => {
3926
+ selection.selectFirstPosition(table, true, true);
3927
+ });
3379
3928
  }
3380
3929
  break;
3381
3930
  case 'todolist':
@@ -3394,7 +3943,7 @@ function InsertTool(props) {
3394
3943
  break;
3395
3944
  case 'image':
3396
3945
  if (fileUploader) {
3397
- Promise.resolve(fileUploader.uploadFile('image')).then(url => {
3946
+ Promise.resolve().then(() => fileUploader.uploadFile('image')).then(url => {
3398
3947
  const img = new ImageComponent(textbus, {
3399
3948
  src: url
3400
3949
  });
@@ -3404,7 +3953,7 @@ function InsertTool(props) {
3404
3953
  break;
3405
3954
  case 'video':
3406
3955
  if (fileUploader) {
3407
- Promise.resolve(fileUploader.uploadFile('video')).then(url => {
3956
+ Promise.resolve().then(() => fileUploader.uploadFile('video')).then(url => {
3408
3957
  const img = new VideoComponent(textbus, {
3409
3958
  src: url
3410
3959
  });
@@ -3421,14 +3970,23 @@ function InsertTool(props) {
3421
3970
  selection.setPosition(p.state.slot, 0);
3422
3971
  }
3423
3972
  break;
3973
+ case 'katex':
3974
+ {
3975
+ const p = new ParagraphComponent(textbus);
3976
+ const comp = new KatexComponent(textbus);
3977
+ p.state.slot.insert(comp);
3978
+ insertComponent(p);
3979
+ selection.selectComponent(comp);
3980
+ }
3981
+ break;
3424
3982
  }
3425
3983
  }
3426
- return scopedCss.withScopedCSS(scopedId$8, () => {
3427
- return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { class: "btn-group", children: [jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('paragraph'), children: jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h1'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h1" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h2'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h2" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h3'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h3" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h4'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h4" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h5'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h5" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h6'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h6" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('ol'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list-numbered" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('ul'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('sourceCode'), children: jsxRuntime.jsx("span", { class: "xnote-icon-source-code" }) })] }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(MenuItem, { onClick: () => insert('table'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-table" }), children: "\u8868\u683C" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('todolist'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-checkbox-checked" }), children: "\u5F85\u529E\u5217\u8868" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('image'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-image" }), children: "\u56FE\u7247" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('video'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-video" }), children: "\u89C6\u9891" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('highlightBox'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-warning" }), children: "\u9AD8\u4EAE\u5757" })] });
3984
+ return scopedCss.withScopedCSS(scopedId$9, () => {
3985
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [props.hideTitle ? null : jsxRuntime.jsx(MenuHeading, { children: props.replace ? '替换为' : '在下面添加' }), jsxRuntime.jsxs("div", { class: "btn-group", children: [jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('paragraph'), children: jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h1'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h1" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h2'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h2" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h3'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h3" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h4'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h4" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h5'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h5" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('h6'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h6" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('ol'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list-numbered" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('ul'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list" }) }), jsxRuntime.jsx(Button, { ordinary: true, onClick: () => insert('sourceCode'), children: jsxRuntime.jsx("span", { class: "xnote-icon-source-code" }) })] }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(MenuItem, { onClick: () => insert('table'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-table" }), children: "\u8868\u683C" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('todolist'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-checkbox-checked" }), children: "\u5F85\u529E\u5217\u8868" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('image'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-image" }), children: "\u56FE\u7247" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('video'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-video" }), children: "\u89C6\u9891" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('highlightBox'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-hightlight-box" }), children: "\u9AD8\u4EAE\u5757" }), jsxRuntime.jsx(MenuItem, { onClick: () => insert('katex'), icon: jsxRuntime.jsx("span", { class: "xnote-icon-function" }), children: "\u6570\u5B66\u516C\u5F0F" })] });
3428
3986
  });
3429
3987
  }
3430
3988
 
3431
- var scopedId$7 = "vf-b05292";
3989
+ var scopedId$8 = "vf-b05292";
3432
3990
 
3433
3991
  const LeftToolbar = core.withAnnotation({
3434
3992
  providers: [exports.RefreshService]
@@ -3438,6 +3996,7 @@ const LeftToolbar = core.withAnnotation({
3438
3996
  const selection = core.inject(core$1.Selection);
3439
3997
  const rootComponentRef = core.inject(core$1.RootComponentRef);
3440
3998
  const refreshService = core.inject(exports.RefreshService);
3999
+ const editorService = core.inject(exports.EditorService);
3441
4000
  const checkStates = useActiveBlock();
3442
4001
  const toBlock = useBlockTransform();
3443
4002
  const activeSlot = core.createSignal(null);
@@ -3456,6 +4015,14 @@ const LeftToolbar = core.withAnnotation({
3456
4015
  top: 0,
3457
4016
  display: false
3458
4017
  });
4018
+ const sub = editorService.onLeftToolbarCanVisibleChange.subscribe(() => {
4019
+ updatePosition(d => {
4020
+ d.display = editorService.canShowLeftToolbar;
4021
+ });
4022
+ });
4023
+ core.onUnmounted(() => {
4024
+ sub.unsubscribe();
4025
+ });
3459
4026
  let isIgnoreMove = false;
3460
4027
  core.onMounted(() => {
3461
4028
  const rootComponent = rootComponentRef.component;
@@ -3463,12 +4030,14 @@ const LeftToolbar = core.withAnnotation({
3463
4030
  const sub = core$1.fromEvent(docContentContainer, 'mousemove').pipe(core$1.filter(() => {
3464
4031
  return !isIgnoreMove;
3465
4032
  }), core$1.map(ev => {
4033
+ var _a;
3466
4034
  let currentNode = ev.target;
3467
4035
  while (currentNode) {
3468
4036
  const slot = adapter.getSlotByNativeNode(currentNode);
3469
4037
  if (slot) {
3470
- if ((slot === null || slot === void 0 ? void 0 : slot.parent) instanceof SourceCodeComponent || (slot === null || slot === void 0 ? void 0 : slot.parent) instanceof TableComponent) {
3471
- return null;
4038
+ if (((_a = slot === null || slot === void 0 ? void 0 : slot.parent) === null || _a === void 0 ? void 0 : _a.type) === core$1.ContentType.InlineComponent) {
4039
+ currentNode = currentNode.parentNode;
4040
+ continue;
3472
4041
  }
3473
4042
  return slot;
3474
4043
  }
@@ -3483,7 +4052,9 @@ const LeftToolbar = core.withAnnotation({
3483
4052
  activeSlot.set(slot);
3484
4053
  if (slot) {
3485
4054
  checkStates(slot);
3486
- isEmptyBlock.set(slot.parent instanceof ParagraphComponent && slot.isEmpty);
4055
+ isEmptyBlock.set((slot.parent instanceof ParagraphComponent && slot.isEmpty) ||
4056
+ slot.parent instanceof SourceCodeComponent ||
4057
+ slot.parent instanceof TableComponent);
3487
4058
  const nativeNode = adapter.getNativeNodeByComponent(slot.parent);
3488
4059
  updatePosition(draft => {
3489
4060
  const containerRect = docContentContainer.getBoundingClientRect();
@@ -3535,19 +4106,7 @@ const LeftToolbar = core.withAnnotation({
3535
4106
  bindLeave();
3536
4107
  isShow.set(true);
3537
4108
  }));
3538
- });
3539
- let snapshot = null;
3540
- function queryBefore() {
3541
- const slot = activeSlot();
3542
- if (slot) {
3543
- snapshot = selection.createSnapshot();
3544
- selection.selectSlot(slot);
3545
- }
3546
- }
3547
- function queryAfter() {
3548
- snapshot === null || snapshot === void 0 ? void 0 : snapshot.restore();
3549
- snapshot = null;
3550
- }
4109
+ });
3551
4110
  function applyBefore() {
3552
4111
  const slot = activeSlot();
3553
4112
  if (slot) {
@@ -3579,7 +4138,7 @@ const LeftToolbar = core.withAnnotation({
3579
4138
  if (!slot) {
3580
4139
  return;
3581
4140
  }
3582
- if (slot.parent.__slots__.length <= 1) {
4141
+ if (slot.parent.slots.length <= 1) {
3583
4142
  commander.removeComponent(slot.parent);
3584
4143
  }
3585
4144
  else {
@@ -3591,20 +4150,21 @@ const LeftToolbar = core.withAnnotation({
3591
4150
  function changeIgnoreMove(b) {
3592
4151
  isIgnoreMove = b;
3593
4152
  }
3594
- return scopedCss.withScopedCSS(scopedId$7, () => {
4153
+ return scopedCss.withScopedCSS(scopedId$8, () => {
4154
+ var _a;
3595
4155
  const position = positionSignal();
3596
4156
  const slot = activeSlot();
3597
4157
  let activeNode = jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" });
3598
- const states = checkStates();
4158
+ const states = checkStates(slot);
3599
4159
  if (slot) {
3600
4160
  const types = [
3601
4161
  [states.paragraph, jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" })],
3602
4162
  [states.sourceCode, jsxRuntime.jsx("span", { class: "xnote-icon-source-code" })],
3603
4163
  [states.blockquote, jsxRuntime.jsx("span", { class: "xnote-icon-quotes-right" })],
3604
4164
  [states.todolist, jsxRuntime.jsx("span", { class: "xnote-icon-checkbox-checked" })],
3605
- [states.table, jsxRuntime.jsx("span", { class: "xnote-icon-table" })],
3606
4165
  [states.unorderedList, jsxRuntime.jsx("span", { class: "xnote-icon-list" })],
3607
4166
  [states.orderedList, jsxRuntime.jsx("span", { class: "xnote-icon-list-numbered" })],
4167
+ [states.table, jsxRuntime.jsx("span", { class: "xnote-icon-table" })],
3608
4168
  [states.h1, jsxRuntime.jsx("span", { class: "xnote-icon-heading-h1" })],
3609
4169
  [states.h2, jsxRuntime.jsx("span", { class: "xnote-icon-heading-h2" })],
3610
4170
  [states.h3, jsxRuntime.jsx("span", { class: "xnote-icon-heading-h3" })],
@@ -3619,18 +4179,20 @@ const LeftToolbar = core.withAnnotation({
3619
4179
  }
3620
4180
  }
3621
4181
  }
4182
+ const activeParentComponent = (_a = activeSlot()) === null || _a === void 0 ? void 0 : _a.parent;
4183
+ const needInsert = activeParentComponent instanceof TableComponent || activeParentComponent instanceof SourceCodeComponent;
3622
4184
  return (jsxRuntime.jsx("div", { class: "left-toolbar", ref: toolbarRef, children: jsxRuntime.jsx("div", { class: "left-toolbar-btn-wrap", ref: btnRef, style: {
3623
4185
  left: position.left + 'px',
3624
4186
  top: position.top + 'px',
3625
- display: position.display && selection.isCollapsed ? 'block' : 'none'
3626
- }, children: jsxRuntime.jsx(Dropdown, { onExpendStateChange: changeIgnoreMove, abreast: true, style: {
4187
+ display: position.display && selection.isCollapsed && editorService.canShowLeftToolbar ? 'block' : 'none'
4188
+ }, children: jsxRuntime.jsx(Dropdown, { toLeft: true, onExpendStateChange: changeIgnoreMove, abreast: true, style: {
3627
4189
  position: 'absolute',
3628
4190
  right: 0,
3629
4191
  top: 0
3630
4192
  }, menu: isEmptyBlock() ?
3631
- jsxRuntime.jsx(InsertTool, { replace: true, slot: activeSlot() })
4193
+ jsxRuntime.jsx(InsertTool, { replace: !needInsert, slot: activeSlot() })
3632
4194
  :
3633
- jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { class: "btn-group", children: [jsxRuntime.jsx(Button, { ordinary: true, highlight: states.paragraph, onClick: () => transform('paragraph'), children: jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h1, onClick: () => transform('h1'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h1" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h2, onClick: () => transform('h2'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h2" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h3, onClick: () => transform('h3'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h3" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h4, onClick: () => transform('h4'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h4" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.todolist, onClick: () => transform('todolist'), children: jsxRuntime.jsx("span", { class: "xnote-icon-checkbox-checked" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.orderedList, onClick: () => transform('ol'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list-numbered" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.unorderedList, onClick: () => transform('ul'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.blockquote, onClick: () => transform('blockquote'), children: jsxRuntime.jsx("span", { class: "xnote-icon-quotes-right" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.sourceCode, onClick: () => transform('sourceCode'), children: jsxRuntime.jsx("span", { class: "xnote-icon-source-code" }) })] }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(AttrTool, { style: { display: 'block' }, abreast: true, applyBefore: applyBefore, queryBefore: queryBefore, queryAfter: queryAfter, children: jsxRuntime.jsx(MenuItem, { arrow: true, icon: jsxRuntime.jsx("span", { class: "xnote-icon-indent-decrease" }), children: "\u7F29\u8FDB\u548C\u5BF9\u9F50" }) }), jsxRuntime.jsx(ColorTool, { style: { display: 'block' }, abreast: true, applyBefore: applyBefore, queryBefore: queryBefore, queryAfter: queryAfter, children: jsxRuntime.jsx(MenuItem, { arrow: true, icon: jsxRuntime.jsx("span", { class: "xnote-icon-color" }), children: "\u989C\u8272" }) }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(MenuItem, { onClick: copy, icon: jsxRuntime.jsx("span", { class: "xnote-icon-copy" }), children: "\u590D\u5236" }), jsxRuntime.jsx(MenuItem, { onClick: remove, icon: jsxRuntime.jsx("span", { class: "xnote-icon-bin" }), children: "\u5220\u9664" }), jsxRuntime.jsx(MenuItem, { onClick: cut, icon: jsxRuntime.jsx("span", { class: "xnote-icon-cut" }), children: "\u526A\u5207" }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(Dropdown, { style: { display: 'block' }, abreast: true, menu: jsxRuntime.jsx(InsertTool, { slot: activeSlot() }), children: jsxRuntime.jsx(MenuItem, { arrow: true, icon: jsxRuntime.jsx("span", { class: "xnote-icon-plus" }), children: "\u5728\u4E0B\u9762\u6DFB\u52A0" }) })] }), children: jsxRuntime.jsx("button", { type: "button", class: "left-toolbar-btn", children: isEmptyBlock() ?
4195
+ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { class: "btn-group", children: [jsxRuntime.jsx(Button, { ordinary: true, highlight: states.paragraph, onClick: () => transform('paragraph'), children: jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h1, onClick: () => transform('h1'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h1" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h2, onClick: () => transform('h2'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h2" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h3, onClick: () => transform('h3'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h3" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.h4, onClick: () => transform('h4'), children: jsxRuntime.jsx("span", { class: "xnote-icon-heading-h4" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.todolist, onClick: () => transform('todolist'), children: jsxRuntime.jsx("span", { class: "xnote-icon-checkbox-checked" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.orderedList, onClick: () => transform('ol'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list-numbered" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.unorderedList, onClick: () => transform('ul'), children: jsxRuntime.jsx("span", { class: "xnote-icon-list" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.blockquote, onClick: () => transform('blockquote'), children: jsxRuntime.jsx("span", { class: "xnote-icon-quotes-right" }) }), jsxRuntime.jsx(Button, { ordinary: true, highlight: states.sourceCode, onClick: () => transform('sourceCode'), children: jsxRuntime.jsx("span", { class: "xnote-icon-source-code" }) })] }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(AttrTool, { style: { display: 'block' }, abreast: true, slot: slot, applyBefore: applyBefore, children: jsxRuntime.jsx(MenuItem, { arrow: true, icon: jsxRuntime.jsx("span", { class: "xnote-icon-indent-decrease" }), children: "\u7F29\u8FDB\u548C\u5BF9\u9F50" }) }), jsxRuntime.jsx(ColorTool, { style: { display: 'block' }, abreast: true, applyBefore: applyBefore, children: jsxRuntime.jsx(MenuItem, { arrow: true, icon: jsxRuntime.jsx("span", { class: "xnote-icon-color" }), children: "\u989C\u8272" }) }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(MenuItem, { onClick: copy, icon: jsxRuntime.jsx("span", { class: "xnote-icon-copy" }), children: "\u590D\u5236" }), jsxRuntime.jsx(MenuItem, { onClick: remove, icon: jsxRuntime.jsx("span", { class: "xnote-icon-bin" }), children: "\u5220\u9664" }), jsxRuntime.jsx(MenuItem, { onClick: cut, icon: jsxRuntime.jsx("span", { class: "xnote-icon-cut" }), children: "\u526A\u5207" }), jsxRuntime.jsx(Divider, {}), jsxRuntime.jsx(Dropdown, { style: { display: 'block' }, abreast: true, menu: jsxRuntime.jsx(InsertTool, { hideTitle: true, slot: activeSlot() }), children: jsxRuntime.jsx(MenuItem, { arrow: true, icon: jsxRuntime.jsx("span", { class: "xnote-icon-plus" }), children: "\u5728\u4E0B\u9762\u6DFB\u52A0" }) })] }), children: jsxRuntime.jsx("button", { type: "button", class: "left-toolbar-btn", children: isEmptyBlock() ?
3634
4196
  jsxRuntime.jsx("span", { children: jsxRuntime.jsx("i", { class: "xnote-icon-plus" }) })
3635
4197
  :
3636
4198
  jsxRuntime.jsxs("span", { children: [activeNode, jsxRuntime.jsx("i", { style: "font-size: 12px", class: "xnote-icon-more" })] }) }) }) }) }));
@@ -3665,24 +4227,74 @@ class LeftToolbarPlugin {
3665
4227
  }
3666
4228
  }
3667
4229
 
3668
- var scopedId$6 = "vf-fee98b";
4230
+ var scopedId$7 = "vf-3073ba";
3669
4231
 
3670
- exports.EditorService = class EditorService {
3671
- constructor() {
3672
- this.hideInlineToolbar = false;
4232
+ function LinkJump() {
4233
+ const selection = core.inject(core$1.Selection);
4234
+ const query = core.inject(core$1.Query);
4235
+ const bridge = core.inject(platformBrowser.SelectionBridge);
4236
+ const container = core.inject(platformBrowser.VIEW_CONTAINER);
4237
+ const href = core.createSignal('');
4238
+ const ref = core.createRef();
4239
+ const isShow = core.createSignal(false);
4240
+ function onSelectionChange() {
4241
+ if (selection.isCollapsed) {
4242
+ const queryState = query.queryFormat(linkFormatter);
4243
+ if (queryState.state === core$1.QueryStateType.Enabled) {
4244
+ const rect = bridge.getRect({
4245
+ slot: selection.startSlot,
4246
+ offset: selection.startOffset
4247
+ });
4248
+ if (rect) {
4249
+ const offsetRect = container.getBoundingClientRect();
4250
+ Object.assign(ref.current.style, {
4251
+ left: rect.left - offsetRect.left + 'px',
4252
+ top: rect.top - offsetRect.top + 'px'
4253
+ });
4254
+ isShow.set(true);
4255
+ let url = queryState.value.href;
4256
+ if (url.indexOf('://') < 0) {
4257
+ url = 'http://' + url;
4258
+ }
4259
+ href.set(url);
4260
+ return;
4261
+ }
4262
+ }
4263
+ }
4264
+ isShow.set(false);
3673
4265
  }
3674
- };
3675
- exports.EditorService = __decorate([
3676
- core.Injectable({
3677
- provideIn: 'root'
3678
- })
3679
- ], exports.EditorService);
4266
+ selection.onChange.pipe(core$1.delay()).subscribe(() => {
4267
+ onSelectionChange();
4268
+ });
4269
+ function cleanLink() {
4270
+ isShow.set(false);
4271
+ const commonAncestorSlot = selection.commonAncestorSlot;
4272
+ const index = selection.focusOffset;
4273
+ const ranges = commonAncestorSlot.getFormatRangesByFormatter(linkFormatter, 0, commonAncestorSlot.length);
4274
+ ranges.forEach(range => {
4275
+ if (range.startIndex < index && range.endIndex >= index) {
4276
+ commonAncestorSlot.applyFormat(linkFormatter, {
4277
+ startIndex: range.startIndex,
4278
+ endIndex: range.endIndex,
4279
+ value: null
4280
+ });
4281
+ }
4282
+ });
4283
+ }
4284
+ return platformBrowser$1.createPortal(scopedCss.withScopedCSS(scopedId$7, () => {
4285
+ return (jsxRuntime.jsxs("div", { ref: ref, class: "link-jump-plugin", style: { display: isShow() ? '' : 'none' }, children: [jsxRuntime.jsx("span", { onClick: cleanLink, children: "\u6E05\u9664" }), jsxRuntime.jsx("a", { target: "_blank", href: href(), children: "\u8DF3\u8F6C" })] }));
4286
+ }), container);
4287
+ }
4288
+
4289
+ var scopedId$6 = "vf-fee98b";
3680
4290
 
3681
4291
  const Toolbar = core.withAnnotation({
3682
4292
  providers: [exports.RefreshService]
3683
4293
  }, function Toolbar() {
3684
4294
  const selection = core.inject(core$1.Selection);
3685
4295
  const viewDocument = core.inject(platformBrowser.VIEW_CONTAINER);
4296
+ const rootComponentRef = core.inject(core$1.RootComponentRef);
4297
+ const adapter = core.inject(platformBrowser.DomAdapter);
3686
4298
  const bridge = core.inject(platformBrowser.SelectionBridge);
3687
4299
  const textbus = core.inject(core$1.Textbus);
3688
4300
  const editorService = core.inject(exports.EditorService);
@@ -3704,7 +4316,7 @@ const Toolbar = core.withAnnotation({
3704
4316
  const toolbarRef = core.createRef();
3705
4317
  function getTop() {
3706
4318
  const docRect = viewDocument.getBoundingClientRect();
3707
- const toolbarRect = toolbarRef.current.getBoundingClientRect();
4319
+ const toolbarHeight = 36;
3708
4320
  // const documentHeight = document.documentElement.clientHeight
3709
4321
  const selectionFocusRect = bridge.getRect({
3710
4322
  slot: selection.focusSlot,
@@ -3713,14 +4325,12 @@ const Toolbar = core.withAnnotation({
3713
4325
  if (!selectionFocusRect) {
3714
4326
  return null;
3715
4327
  }
3716
- // console.log(selectionFocusRect.top, toolbarRect.height)
3717
4328
  const centerLeft = selectionFocusRect.left;
3718
- const toBottom = selectionFocusRect.top < toolbarRect.height + 10;
4329
+ const toBottom = selectionFocusRect.top < toolbarHeight + 10;
3719
4330
  const top = toBottom ?
3720
4331
  selectionFocusRect.top + selectionFocusRect.height - docRect.top + 10 :
3721
- selectionFocusRect.top - docRect.top - toolbarRect.height - 10;
4332
+ selectionFocusRect.top - docRect.top - toolbarHeight - 10;
3722
4333
  updateViewPosition(draft => {
3723
- draft.isHide = false;
3724
4334
  draft.transitionDuration = .15;
3725
4335
  draft.left = centerLeft - docRect.left;
3726
4336
  draft.top = top + 10;
@@ -3741,13 +4351,15 @@ const Toolbar = core.withAnnotation({
3741
4351
  sub.unsubscribe();
3742
4352
  });
3743
4353
  function bindMouseup() {
3744
- mouseupSubscription = core$1.fromEvent(viewDocument, 'mouseup').pipe(core$1.filter(ev => {
4354
+ const docElement = adapter.getNativeNodeByComponent(rootComponentRef.component);
4355
+ mouseupSubscription = core$1.fromEvent(docElement, 'mouseup').pipe(core$1.filter(ev => {
3745
4356
  return !ev.composedPath().includes(toolbarRef.current);
3746
4357
  }), core$1.delay(100), core$1.filter(() => {
3747
4358
  return !selection.isCollapsed && !(selection.commonAncestorComponent instanceof SourceCodeComponent);
3748
4359
  }), core$1.map(getTop), core$1.delay(200)).subscribe((top) => {
3749
4360
  if (top !== null) {
3750
4361
  updateViewPosition(draft => {
4362
+ draft.isHide = false;
3751
4363
  draft.opacity = 1;
3752
4364
  draft.top = top;
3753
4365
  });
@@ -3766,10 +4378,10 @@ const Toolbar = core.withAnnotation({
3766
4378
  });
3767
4379
  bindMouseup();
3768
4380
  });
4381
+ const instance = core.getCurrentInstance();
3769
4382
  function hideToolbar() {
3770
- updateViewPosition(draft => {
3771
- draft.isHide = true;
3772
- });
4383
+ editorService.hideInlineToolbar = true;
4384
+ instance.markAsDirtied();
3773
4385
  }
3774
4386
  core.onUnmounted(() => {
3775
4387
  mousedownSubscription.unsubscribe();
@@ -3910,6 +4522,222 @@ class Matcher {
3910
4522
  }
3911
4523
  }
3912
4524
 
4525
+ class Organization {
4526
+ }
4527
+ function registerAtShortcut(textbus) {
4528
+ const keyboard = textbus.get(core$1.Keyboard);
4529
+ const selection = textbus.get(core$1.Selection);
4530
+ const commander = textbus.get(core$1.Commander);
4531
+ keyboard.addShortcut({
4532
+ keymap: {
4533
+ key: '@',
4534
+ shiftKey: true
4535
+ },
4536
+ action() {
4537
+ const { commonAncestorComponent } = selection;
4538
+ if (commonAncestorComponent instanceof SourceCodeComponent) {
4539
+ return false;
4540
+ }
4541
+ const at = new AtComponent(textbus);
4542
+ commander.insert(at);
4543
+ selection.setPosition(at.state.slot, 0);
4544
+ }
4545
+ });
4546
+ }
4547
+ class AtComponent extends core$1.Component {
4548
+ static fromJSON(textbus, { slot: slotState, userInfo }) {
4549
+ const registry = textbus.get(core$1.Registry);
4550
+ if (slotState) {
4551
+ const slot = registry.createSlot(slotState);
4552
+ return new AtComponent(textbus, {
4553
+ slot
4554
+ });
4555
+ }
4556
+ return new AtComponent(textbus, {
4557
+ userInfo,
4558
+ });
4559
+ }
4560
+ constructor(textbus, state = {
4561
+ slot: new core$1.Slot([core$1.ContentType.Text])
4562
+ }) {
4563
+ if (!state.userInfo && !state.slot) {
4564
+ state.slot = new core$1.Slot([core$1.ContentType.Text]);
4565
+ }
4566
+ super(textbus, state);
4567
+ this.focus = new core$1.Subject();
4568
+ this.members = core.createSignal([]);
4569
+ this.selectedIndex = core.createSignal(0);
4570
+ }
4571
+ getSlots() {
4572
+ if (this.state.slot) {
4573
+ return [this.state.slot];
4574
+ }
4575
+ return [];
4576
+ }
4577
+ setup() {
4578
+ let isFocus = false;
4579
+ core$1.onFocus(() => {
4580
+ isFocus = true;
4581
+ this.focus.next(true);
4582
+ onChange.next();
4583
+ });
4584
+ core$1.onBlur(() => {
4585
+ isFocus = false;
4586
+ this.focus.next(false);
4587
+ setTimeout(() => {
4588
+ if (this.parent && !this.state.userInfo) {
4589
+ const slot = this.state.slot;
4590
+ let text = '@';
4591
+ if (slot) {
4592
+ text += slot.isEmpty ? '' : slot.toString();
4593
+ }
4594
+ const snapshot = selection.createSnapshot();
4595
+ selection.selectComponent(this);
4596
+ commander.insert(text);
4597
+ snapshot.restore(true);
4598
+ }
4599
+ });
4600
+ });
4601
+ const organization = core$1.useContext(Organization);
4602
+ const selection = core$1.useContext(core$1.Selection);
4603
+ const commander = core$1.useContext(core$1.Commander);
4604
+ const onChange = new core$1.Subject();
4605
+ core$1.onContentInserted((ev) => {
4606
+ const key = this.state.slot.toString();
4607
+ if (key.length > 10) {
4608
+ selection.selectComponent(this);
4609
+ commander.insert(key);
4610
+ ev.preventDefault();
4611
+ return;
4612
+ }
4613
+ onChange.next();
4614
+ });
4615
+ core$1.onContentDeleted(() => {
4616
+ onChange.next();
4617
+ });
4618
+ core$1.onBreak((ev) => {
4619
+ const member = this.members()[this.selectedIndex()];
4620
+ if (member) {
4621
+ this.state.userInfo = Object.assign({}, member);
4622
+ }
4623
+ selection.selectComponentEnd(this);
4624
+ ev.preventDefault();
4625
+ });
4626
+ core$1.useDynamicShortcut({
4627
+ keymap: {
4628
+ key: ['ArrowDown', 'ArrowUp']
4629
+ },
4630
+ action: (key) => {
4631
+ let index = this.selectedIndex();
4632
+ if (key === 'ArrowUp') {
4633
+ if (index > 0) {
4634
+ index--;
4635
+ this.selectedIndex.set(index);
4636
+ }
4637
+ return;
4638
+ }
4639
+ if (index < this.members().length - 1) {
4640
+ index++;
4641
+ this.selectedIndex.set(index);
4642
+ }
4643
+ }
4644
+ });
4645
+ const subs = onChange.pipe(core$1.switchMap(() => {
4646
+ const key = this.state.slot.toString();
4647
+ return core$1.fromPromise(organization.getMembers(key));
4648
+ })).subscribe((members) => {
4649
+ this.members.set(members);
4650
+ this.selectedIndex.set(0);
4651
+ if (isFocus) {
4652
+ this.focus.next(true);
4653
+ }
4654
+ });
4655
+ core$1.onDestroy(() => {
4656
+ subs.unsubscribe();
4657
+ });
4658
+ }
4659
+ }
4660
+ AtComponent.componentName = 'AtComponent';
4661
+ AtComponent.type = core$1.ContentType.InlineComponent;
4662
+
4663
+ function AtComponentView(props) {
4664
+ const selection = core.inject(core$1.Selection);
4665
+ const dropdownRef = core.createRef();
4666
+ const subscription = props.component.focus.subscribe((b) => {
4667
+ if (dropdownRef.current && props.component.members().length) {
4668
+ dropdownRef.current.isShow(b);
4669
+ }
4670
+ });
4671
+ core.onUnmounted(() => {
4672
+ subscription.unsubscribe();
4673
+ });
4674
+ const readonly = useReadonly();
4675
+ const output = useOutput();
4676
+ const membersRef = core.createRef();
4677
+ core.onUpdated(() => {
4678
+ if (output() || readonly()) {
4679
+ return;
4680
+ }
4681
+ const container = membersRef.current;
4682
+ if (container) {
4683
+ const focusItem = container.children[props.component.selectedIndex()];
4684
+ if (focusItem) {
4685
+ const itemRect = focusItem.getBoundingClientRect();
4686
+ const dropdownMenu = container.parentNode.parentNode;
4687
+ const containerRect = dropdownMenu.getBoundingClientRect();
4688
+ if (itemRect.top - 5 < containerRect.top) {
4689
+ dropdownMenu.scrollTop += itemRect.top - 5 - containerRect.top;
4690
+ }
4691
+ else if (itemRect.bottom + 5 > containerRect.bottom) {
4692
+ dropdownMenu.scrollTop += itemRect.bottom + 5 - containerRect.bottom;
4693
+ }
4694
+ }
4695
+ }
4696
+ });
4697
+ return () => {
4698
+ const { slot, userInfo } = props.component.state;
4699
+ const selectedIndex = props.component.selectedIndex();
4700
+ if (userInfo) {
4701
+ return (jsxRuntime.jsxs("div", { class: "xnote-at xnote-at-complete", "data-info": encodeURIComponent(JSON.stringify(userInfo)), ref: props.rootRef, "data-component": props.component.name, children: [jsxRuntime.jsx("span", { children: "@" }), userInfo.name] }));
4702
+ }
4703
+ if (readonly() || output()) {
4704
+ return (jsxRuntime.jsxs("div", { class: "xnote-at", ref: props.rootRef, "data-component": props.component.name, children: [jsxRuntime.jsx("span", { children: "@" }), slot && jsxRuntime.jsx(SlotRender, { slot: slot, class: 'xnote-at-input', tag: "span" })] }));
4705
+ }
4706
+ const members = props.component.members();
4707
+ return (jsxRuntime.jsx("div", { class: "xnote-at", ref: props.rootRef, "data-component": props.component.name, children: jsxRuntime.jsxs(Dropdown, { trigger: 'none', ref: dropdownRef, menu: jsxRuntime.jsx("div", { class: "xnote-at-menu", ref: membersRef, children: members.map((member, index) => {
4708
+ let hsl = color.any2Hsl(member.color);
4709
+ if (hsl === 'unknown') {
4710
+ hsl = color.any2Hsl('#000');
4711
+ }
4712
+ const rgb = color.hsl2Rgb(hsl);
4713
+ const yiq = (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
4714
+ const color$1 = yiq >= 128 ? '#000' : '#fff';
4715
+ return (jsxRuntime.jsxs("div", { onClick: () => {
4716
+ props.component.state.userInfo = member;
4717
+ selection.selectComponentEnd(props.component);
4718
+ }, class: ['xnote-at-member', { selected: index === selectedIndex }], children: [jsxRuntime.jsx("div", { class: "xnote-at-member-avatar", children: member.avatar ? jsxRuntime.jsx("img", { src: member.avatar, alt: member.name }) :
4719
+ jsxRuntime.jsx("span", { class: "xnote-at-member-avatar-bg", style: { background: member.color, color: color$1 }, children: member.name }) }), jsxRuntime.jsxs("div", { class: "xnote-at-member-info", children: [jsxRuntime.jsx("div", { class: "xnote-at-member-name", children: member.name }), jsxRuntime.jsx("div", { class: "xnote-at-member-desc", children: member.groupName })] })] }, member.id));
4720
+ }) }), children: [jsxRuntime.jsx("span", { children: "@" }), slot && jsxRuntime.jsx(SlotRender, { slot: slot, tag: 'span', class: 'xnote-at-input' })] }) }));
4721
+ };
4722
+ }
4723
+ const atComponentLoader = {
4724
+ match(element) {
4725
+ return element.dataset.component === AtComponent.componentName;
4726
+ },
4727
+ read(element, textbus, slotParser) {
4728
+ const data = element.dataset.info;
4729
+ if (data) {
4730
+ return new AtComponent(textbus, {
4731
+ userInfo: JSON.parse(decodeURIComponent(data))
4732
+ });
4733
+ }
4734
+ const slot = slotParser(new core$1.Slot([core$1.ContentType.Text]), element.querySelector('.xnote-at-input') || document.createElement('div'));
4735
+ return new AtComponent(textbus, {
4736
+ slot
4737
+ });
4738
+ }
4739
+ };
4740
+
3913
4741
  class RootComponent extends core$1.Component {
3914
4742
  constructor() {
3915
4743
  super(...arguments);
@@ -3921,17 +4749,36 @@ class RootComponent extends core$1.Component {
3921
4749
  content
3922
4750
  });
3923
4751
  }
4752
+ getSlots() {
4753
+ return [this.state.content];
4754
+ }
3924
4755
  setup() {
3925
- useBlockContent(this.state.content);
4756
+ useBlockContent((slot) => slot === this.state.content);
3926
4757
  core$1.onCompositionStart(ev => {
3927
4758
  this.onCompositionStart.next(ev);
3928
4759
  });
4760
+ core$1.onSlotSetAttribute(ev => {
4761
+ ev.preventDefault();
4762
+ });
4763
+ core$1.onSlotApplyFormat(ev => {
4764
+ ev.preventDefault();
4765
+ });
4766
+ }
4767
+ afterCheck() {
4768
+ const content = this.state.content;
4769
+ const lastContent = content.getContentAtIndex(content.length - 1);
4770
+ if (lastContent instanceof ParagraphComponent ||
4771
+ lastContent instanceof ListComponent ||
4772
+ lastContent instanceof TodolistComponent) {
4773
+ return;
4774
+ }
4775
+ content.retain(content.length);
4776
+ content.insert(new ParagraphComponent(this.textbus));
3929
4777
  }
3930
4778
  }
3931
4779
  RootComponent.componentName = 'RootComponent';
3932
4780
  RootComponent.type = core$1.ContentType.BlockComponent;
3933
4781
  function RootView(props) {
3934
- const adapter = core.inject(platformBrowser.DomAdapter);
3935
4782
  const { content } = props.component.state;
3936
4783
  const ref = core.createDynamicRef(node => {
3937
4784
  const sub = props.component.onCompositionStart.subscribe(() => {
@@ -3941,16 +4788,14 @@ function RootView(props) {
3941
4788
  sub.unsubscribe();
3942
4789
  };
3943
4790
  });
4791
+ core.onUpdated(() => {
4792
+ props.component.afterCheck();
4793
+ });
3944
4794
  const readonly = useReadonly();
3945
4795
  const output = useOutput();
3946
4796
  return () => {
3947
4797
  const { rootRef } = props;
3948
- return (jsxRuntime.jsx("div", { class: "xnote-root", ref: [rootRef, ref], children: adapter.slotRender(content, children => {
3949
- return (core$1.createVNode('div', {
3950
- class: 'xnote-content',
3951
- 'data-placeholder': content.isEmpty ? '请输入内容' : ''
3952
- }, children));
3953
- }, readonly() || output()) }));
4798
+ return (jsxRuntime.jsx("div", { class: "xnote-root", dir: "auto", ref: [rootRef, ref], "data-component": props.component.name, children: jsxRuntime.jsx(SlotRender, { slot: content, tag: "div", class: "xnote-content", "data-placeholder": content.isEmpty ? '请输入内容' : '', renderEnv: readonly() || output() }) }));
3954
4799
  };
3955
4800
  }
3956
4801
  const rootComponentLoader = {
@@ -3964,9 +4809,7 @@ const rootComponentLoader = {
3964
4809
  core$1.ContentType.Text
3965
4810
  ]), element).toDelta();
3966
4811
  const slot = new core$1.Slot([
3967
- core$1.ContentType.BlockComponent,
3968
- core$1.ContentType.InlineComponent,
3969
- core$1.ContentType.Text
4812
+ core$1.ContentType.BlockComponent
3970
4813
  ]);
3971
4814
  deltaToBlock(delta, textbus).forEach(i => {
3972
4815
  slot.insert(i);
@@ -3993,6 +4836,7 @@ TableService = __decorate([
3993
4836
  function ResizeColumn(props) {
3994
4837
  const dragLineRef = core.createRef();
3995
4838
  let activeCol = null;
4839
+ const editorService = core.inject(exports.EditorService);
3996
4840
  core.onMounted(() => {
3997
4841
  const { tableRef } = props;
3998
4842
  let isDrag = false;
@@ -4025,6 +4869,7 @@ function ResizeColumn(props) {
4025
4869
  }
4026
4870
  })).add(core$1.fromEvent(dragLineRef.current, 'mousedown').subscribe(downEvent => {
4027
4871
  isDrag = true;
4872
+ editorService.changeLeftToolbarVisible(false);
4028
4873
  props.onActiveStateChange(true);
4029
4874
  const x = downEvent.clientX;
4030
4875
  const layoutWidth = props.component.state.layoutWidth;
@@ -4032,16 +4877,20 @@ function ResizeColumn(props) {
4032
4877
  const initLeft = layoutWidth.slice(0, activeCol).reduce((a, b) => a + b, 0);
4033
4878
  const minWidth = 30;
4034
4879
  const minLeft = initLeft - initWidth + minWidth;
4880
+ const layoutWidthArr = layoutWidth.slice();
4035
4881
  const moveEvent = core$1.fromEvent(document, 'mousemove').subscribe(moveEvent => {
4036
4882
  const distanceX = moveEvent.clientX - x;
4037
4883
  dragLineRef.current.style.left = Math.max(initLeft + distanceX, minLeft) + 'px';
4038
- props.component.state.layoutWidth[activeCol - 1] = Math.max(initWidth + distanceX, minWidth);
4884
+ layoutWidthArr[activeCol - 1] = Math.max(initWidth + distanceX, minWidth);
4885
+ props.layoutWidth.set(layoutWidthArr.slice());
4039
4886
  }).add(core$1.fromEvent(document, 'mouseup').subscribe(upEvent => {
4040
4887
  isDrag = false;
4888
+ editorService.changeLeftToolbarVisible(true);
4041
4889
  props.onActiveStateChange(false);
4042
4890
  moveEvent.unsubscribe();
4043
4891
  const distanceX = upEvent.clientX - x;
4044
4892
  props.component.state.layoutWidth[activeCol - 1] = Math.max(initWidth + distanceX, minWidth);
4893
+ props.layoutWidth.set(props.component.state.layoutWidth);
4045
4894
  }));
4046
4895
  }));
4047
4896
  return () => {
@@ -4067,7 +4916,7 @@ function ResizeColumn(props) {
4067
4916
  });
4068
4917
  }
4069
4918
 
4070
- var scopedId$4 = "vf-d64cf9";
4919
+ var scopedId$4 = "vf-39cb2c";
4071
4920
 
4072
4921
  function TopBar(props) {
4073
4922
  const editorService = core.inject(exports.EditorService);
@@ -4142,7 +4991,7 @@ function TopBar(props) {
4142
4991
  active: props.isFocus()
4143
4992
  }], children: jsxRuntime.jsxs("div", { class: "toolbar-wrapper", children: [jsxRuntime.jsx("div", { class: "insert-bar", children: jsxRuntime.jsx("table", { style: {
4144
4993
  transform: `translateX(${-leftDistance()}px)`
4145
- }, children: jsxRuntime.jsx("tbody", { children: jsxRuntime.jsx("tr", { children: state.layoutWidth.map((i, index) => {
4994
+ }, children: jsxRuntime.jsx("tbody", { children: jsxRuntime.jsx("tr", { children: props.layoutWidth().map((i, index) => {
4146
4995
  return (jsxRuntime.jsx("td", { style: { width: i + 'px', minWidth: i + 'px' }, children: jsxRuntime.jsxs("div", { class: "tool-container", children: [index === 0 && (jsxRuntime.jsx("span", { onMouseenter: () => {
4147
4996
  tableService.onInsertColumnBefore.next(0);
4148
4997
  }, onMouseleave: () => {
@@ -4168,7 +5017,7 @@ function TopBar(props) {
4168
5017
  }, children: jsxRuntime.jsx("span", { class: "xnote-icon-bin" }) }) }) })] }) }));
4169
5018
  }) }) }) }) }), jsxRuntime.jsx("div", { class: ['action-bar', { active: props.isFocus() }], children: jsxRuntime.jsx("table", { style: {
4170
5019
  transform: `translateX(${-leftDistance()}px)`
4171
- }, children: jsxRuntime.jsx("tbody", { children: jsxRuntime.jsx("tr", { children: state.layoutWidth.map((i, index) => {
5020
+ }, children: jsxRuntime.jsx("tbody", { children: jsxRuntime.jsx("tr", { children: props.layoutWidth().map((i, index) => {
4172
5021
  return jsxRuntime.jsx("td", { onClick: ev => {
4173
5022
  mouseDownFromToolbar = true;
4174
5023
  if (!ev.shiftKey) {
@@ -4188,7 +5037,7 @@ function TopBar(props) {
4188
5037
  });
4189
5038
  }
4190
5039
 
4191
- var scopedId$3 = "vf-b1149b";
5040
+ var scopedId$3 = "vf-7bef30";
4192
5041
 
4193
5042
  function Scroll(props) {
4194
5043
  const scrollRef = core.createRef();
@@ -4202,37 +5051,41 @@ function Scroll(props) {
4202
5051
  const el = scrollRef.current;
4203
5052
  function update() {
4204
5053
  if (props.isFocus()) {
4205
- input.caret.refresh(false);
5054
+ input.caret.refresh();
4206
5055
  }
4207
5056
  updateShowShadow(draft => {
4208
5057
  draft.leftEnd = el.scrollLeft === 0;
4209
5058
  draft.rightEnd = el.scrollLeft === el.scrollWidth - el.offsetWidth;
4210
5059
  });
4211
5060
  }
4212
- update();
5061
+ setTimeout(update);
4213
5062
  const s = core$1.fromEvent(el, 'scroll').subscribe(update);
4214
5063
  return () => s.unsubscribe();
4215
5064
  });
4216
5065
  core.onUpdated(() => {
4217
5066
  const el = scrollRef.current;
4218
- updateShowShadow(draft => {
4219
- draft.leftEnd = el.scrollLeft === 0;
4220
- draft.rightEnd = el.scrollLeft === el.scrollWidth - el.offsetWidth;
5067
+ setTimeout(() => {
5068
+ updateShowShadow(draft => {
5069
+ draft.leftEnd = el.scrollLeft === 0;
5070
+ draft.rightEnd = el.scrollLeft === el.scrollWidth - el.offsetWidth;
5071
+ });
4221
5072
  });
4222
5073
  });
4223
5074
  return scopedCss.withScopedCSS(scopedId$3, () => {
4224
- return jsxRuntime.jsx("div", { ref: [scrollRef, props.scrollRef], class: ['scroll-container', {
5075
+ return jsxRuntime.jsx("div", { ref: [scrollRef], class: ['scroll-container', {
4225
5076
  'left-end': showShadow().leftEnd,
4226
5077
  'right-end': showShadow().rightEnd,
4227
5078
  'active': props.isFocus(),
4228
5079
  // 'hide-selection': isSelectColumn()
4229
5080
  }], onScroll: ev => {
4230
- tableService.onScroll.next(ev.target.scrollLeft);
5081
+ setTimeout(() => {
5082
+ tableService.onScroll.next(ev.target.scrollLeft);
5083
+ }, 30);
4231
5084
  }, children: props.children });
4232
5085
  });
4233
5086
  }
4234
5087
 
4235
- var scopedId$2 = "vf-ef93c0";
5088
+ var scopedId$2 = "vf-aaece0";
4236
5089
 
4237
5090
  function LeftBar(props) {
4238
5091
  const editorService = core.inject(exports.EditorService);
@@ -4432,9 +5285,9 @@ function SelectionMask(props) {
4432
5285
  updateStyles(draft => {
4433
5286
  draft.visible = true;
4434
5287
  draft.left = sum(state.layoutWidth.slice(0, selection.startColumn));
4435
- draft.top = sum(trs.slice(0, selection.startRow).map(i => i.offsetHeight)) + topCompensation;
5288
+ draft.top = trs[selection.startRow].offsetTop + topCompensation;
4436
5289
  draft.width = sum(state.layoutWidth.slice(selection.startColumn, selection.endColumn)) - 1 + 'px';
4437
- draft.height = sum(trs.slice(selection.startRow, selection.endRow).map(i => i.offsetHeight)) + heightCompensation + 'px';
5290
+ draft.height = trs[selection.endRow - 1].offsetTop + trs[selection.endRow - 1].offsetHeight + heightCompensation - draft.top + 'px';
4438
5291
  });
4439
5292
  }
4440
5293
  else {
@@ -4463,81 +5316,25 @@ function SelectionMask(props) {
4463
5316
  });
4464
5317
  }
4465
5318
 
5319
+ // import { SlotRender } from '../SlotRender'
4466
5320
  const TableComponentView = core.withAnnotation({
4467
5321
  providers: [TableService]
4468
5322
  }, function TableComponentView(props) {
4469
5323
  const adapter = core.inject(platformBrowser.DomAdapter);
5324
+ const editorService = core.inject(exports.EditorService);
4470
5325
  const isFocus = core.createSignal(false);
5326
+ const layoutWidth = core.createSignal(props.component.state.layoutWidth);
4471
5327
  const subscription = props.component.focus.subscribe(b => {
4472
5328
  isFocus.set(b);
5329
+ if (!b) {
5330
+ editorService.hideInlineToolbar = false;
5331
+ }
4473
5332
  });
4474
5333
  core.onUnmounted(() => {
4475
5334
  subscription.unsubscribe();
4476
5335
  });
4477
5336
  const tableRef = core.createRef();
4478
- const scrollRef = core.createRef();
4479
5337
  const isResizeColumn = core.createSignal(false);
4480
- const selection = core.inject(core$1.Selection);
4481
- const findPosition = (slot) => {
4482
- let cell = slot;
4483
- while ((cell === null || cell === void 0 ? void 0 : cell.parent) && cell.parent !== props.component) {
4484
- cell = cell.parentSlot;
4485
- }
4486
- if (cell) {
4487
- const rows = props.component.state.rows;
4488
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
4489
- const row = rows[rowIndex].cells;
4490
- for (let colIndex = 0; colIndex < row.length; colIndex++) {
4491
- const item = row[colIndex].slot;
4492
- if (item === cell) {
4493
- return {
4494
- rowIndex,
4495
- colIndex
4496
- };
4497
- }
4498
- }
4499
- }
4500
- }
4501
- return null;
4502
- };
4503
- core.onMounted(() => {
4504
- const sub = selection.onChange.subscribe(() => {
4505
- var _a;
4506
- if (selection.commonAncestorComponent !== props.component || selection.isCollapsed) {
4507
- props.component.tableSelection.set(null);
4508
- return;
4509
- }
4510
- const startPosition = findPosition(selection.startSlot);
4511
- const endPosition = findPosition(selection.endSlot);
4512
- if (startPosition && endPosition) {
4513
- if (startPosition.rowIndex === endPosition.rowIndex && startPosition.colIndex === endPosition.colIndex) {
4514
- if (selection.startSlot === selection.endSlot && selection.startOffset === 0 && selection.endOffset === ((_a = selection.startSlot) === null || _a === void 0 ? void 0 : _a.length)) {
4515
- props.component.tableSelection.set({
4516
- startColumn: startPosition.colIndex,
4517
- startRow: startPosition.rowIndex,
4518
- endColumn: endPosition.colIndex + 1,
4519
- endRow: endPosition.rowIndex + 1
4520
- });
4521
- return;
4522
- }
4523
- props.component.tableSelection.set(null);
4524
- return;
4525
- }
4526
- const [startColumn, endColumn] = [startPosition.colIndex, endPosition.colIndex].sort((a, b) => a - b);
4527
- const [startRow, endRow] = [startPosition.rowIndex, endPosition.rowIndex].sort((a, b) => a - b);
4528
- props.component.tableSelection.set({
4529
- startColumn,
4530
- startRow,
4531
- endColumn: endColumn + 1,
4532
- endRow: endRow + 1
4533
- });
4534
- }
4535
- else {
4536
- props.component.tableSelection.set(null);
4537
- }
4538
- });
4539
- return () => sub.unsubscribe();
4540
- });
4541
5338
  const rowMapping = new WeakMap();
4542
5339
  const readonly = useReadonly();
4543
5340
  const output = useOutput();
@@ -4550,45 +5347,42 @@ const TableComponentView = core.withAnnotation({
4550
5347
  }
4551
5348
  rowMapping.set(row, Math.random());
4552
5349
  });
4553
- Promise.resolve().then(() => {
4554
- props.component.afterContentCheck();
4555
- });
4556
5350
  if (readonly() || output()) {
4557
- return (jsxRuntime.jsx("div", { class: "xnote-table", "data-component": props.component.name, "data-layout-width": state.layoutWidth, ref: props.rootRef, children: jsxRuntime.jsx("div", { class: "xnote-table-container", children: jsxRuntime.jsxs("table", { class: [
4558
- 'xnote-table-content',
4559
- {
4560
- 'hide-selection': props.component.tableSelection()
4561
- }
4562
- ], children: [jsxRuntime.jsx("colgroup", { children: state.layoutWidth.map(w => {
4563
- return jsxRuntime.jsx("col", { style: { width: w + 'px', minWidth: w + 'px' } });
4564
- }) }), jsxRuntime.jsx("tbody", { children: rows.map((row) => {
4565
- return (jsxRuntime.jsx("tr", { children: row.cells.map(cell => {
4566
- return adapter.slotRender(cell.slot, children => {
4567
- return core$1.createVNode('td', {
4568
- key: cell.slot.id
4569
- }, children);
4570
- }, readonly() || output());
4571
- }) }, rowMapping.get(row)));
4572
- }) })] }) }) }));
4573
- }
4574
- return (jsxRuntime.jsxs("div", { class: "xnote-table", "data-component": props.component.name, "data-layout-width": state.layoutWidth, ref: props.rootRef, children: [jsxRuntime.jsx(TopBar, { isFocus: isFocus, component: props.component, scrollRef: scrollRef }), jsxRuntime.jsx(LeftBar, { tableRef: tableRef, isFocus: isFocus, component: props.component }), jsxRuntime.jsx(Scroll, { scrollRef: scrollRef, isFocus: isFocus, children: jsxRuntime.jsxs("div", { class: "xnote-table-container", children: [jsxRuntime.jsxs("table", { ref: tableRef, class: [
4575
- 'xnote-table-content',
4576
- {
4577
- 'hide-selection': props.component.tableSelection()
4578
- }
4579
- ], children: [jsxRuntime.jsx("colgroup", { children: state.layoutWidth.map(w => {
4580
- return jsxRuntime.jsx("col", { style: { width: w + 'px', minWidth: w + 'px' } });
4581
- }) }), jsxRuntime.jsx("tbody", { children: rows.map((row) => {
4582
- return (jsxRuntime.jsx("tr", { children: row.cells.map(cell => {
4583
- return adapter.slotRender(cell.slot, children => {
4584
- return core$1.createVNode('td', {
4585
- key: cell.slot.id
4586
- }, children);
4587
- }, readonly() || output());
4588
- }) }, rowMapping.get(row)));
4589
- }) })] }), jsxRuntime.jsx(ResizeColumn, { tableRef: tableRef, component: props.component, onActiveStateChange: isActive => {
4590
- isResizeColumn.set(isActive);
4591
- } }), jsxRuntime.jsx(SelectionMask, { tableRef: tableRef, component: props.component })] }) }), jsxRuntime.jsx(ResizeRow, { component: props.component, tableRef: tableRef })] }));
5351
+ return (jsxRuntime.jsx("div", { class: "xnote-table", "data-component": props.component.name, "data-layout-width": state.layoutWidth, children: jsxRuntime.jsx("div", { class: "xnote-table-inner", ref: props.rootRef, children: jsxRuntime.jsx("div", { class: "xnote-table-container", children: jsxRuntime.jsxs("table", { class: [
5352
+ 'xnote-table-content',
5353
+ {
5354
+ 'hide-selection': props.component.tableSelection()
5355
+ }
5356
+ ], children: [jsxRuntime.jsx("colgroup", { children: layoutWidth().map(w => {
5357
+ return jsxRuntime.jsx("col", { style: { width: w + 'px', minWidth: w + 'px' } });
5358
+ }) }), jsxRuntime.jsx("tbody", { children: rows.map((row) => {
5359
+ return (jsxRuntime.jsx("tr", { children: row.cells.map(cell => {
5360
+ return adapter.slotRender(cell.slot, children => {
5361
+ return core$1.createVNode('td', {
5362
+ key: cell.slot.id
5363
+ }, children);
5364
+ }, readonly() || output());
5365
+ }) }, rowMapping.get(row)));
5366
+ }) })] }) }) }) }));
5367
+ }
5368
+ return (jsxRuntime.jsx("div", { class: "xnote-table", "data-component": props.component.name, "data-layout-width": `[${state.layoutWidth.join(',')}]`, children: jsxRuntime.jsxs("div", { class: "xnote-table-inner", ref: props.rootRef, children: [jsxRuntime.jsx(TopBar, { isFocus: isFocus, layoutWidth: layoutWidth, component: props.component }), jsxRuntime.jsx(LeftBar, { tableRef: tableRef, isFocus: isFocus, component: props.component }), jsxRuntime.jsx(Scroll, { isFocus: isFocus, children: jsxRuntime.jsxs("div", { class: "xnote-table-container", children: [jsxRuntime.jsxs("table", { ref: tableRef, class: [
5369
+ 'xnote-table-content',
5370
+ {
5371
+ 'hide-selection': props.component.tableSelection()
5372
+ }
5373
+ ], children: [jsxRuntime.jsx("colgroup", { children: layoutWidth().map(w => {
5374
+ return jsxRuntime.jsx("col", { style: { width: w + 'px', minWidth: w + 'px' } });
5375
+ }) }), jsxRuntime.jsx("tbody", { children: rows.map((row) => {
5376
+ return (jsxRuntime.jsx("tr", { children: row.cells.map(cell => {
5377
+ return adapter.slotRender(cell.slot, children => {
5378
+ return core$1.createVNode('td', {
5379
+ key: cell.slot.id
5380
+ }, children);
5381
+ }, readonly() || output());
5382
+ }) }, rowMapping.get(row)));
5383
+ }) })] }), jsxRuntime.jsx(ResizeColumn, { tableRef: tableRef, component: props.component, layoutWidth: layoutWidth, onActiveStateChange: isActive => {
5384
+ isResizeColumn.set(isActive);
5385
+ } }), jsxRuntime.jsx(SelectionMask, { tableRef: tableRef, component: props.component })] }) }), jsxRuntime.jsx(ResizeRow, { component: props.component, tableRef: tableRef })] }) }));
4592
5386
  };
4593
5387
  });
4594
5388
  const tableComponentLoader = {
@@ -4596,10 +5390,11 @@ const tableComponentLoader = {
4596
5390
  return element.dataset.component === TableComponent.componentName || element.tagName === 'TABLE';
4597
5391
  },
4598
5392
  read(element, textbus, slotParser) {
5393
+ let content = element;
4599
5394
  if (element.tagName === 'DIV') {
4600
- element = element.querySelector('.xnote-table-content');
5395
+ content = element.querySelector('.xnote-table-content');
4601
5396
  }
4602
- const { tHead, tBodies, tFoot } = element;
5397
+ const { tHead, tBodies, tFoot } = content;
4603
5398
  const headers = [];
4604
5399
  const bodies = [];
4605
5400
  if (tHead) {
@@ -4617,6 +5412,8 @@ const tableComponentLoader = {
4617
5412
  });
4618
5413
  const delta = slotParser(new core$1.Slot([
4619
5414
  core$1.ContentType.BlockComponent,
5415
+ core$1.ContentType.InlineComponent,
5416
+ core$1.ContentType.Text
4620
5417
  ]), cell).toDelta();
4621
5418
  const results = deltaToBlock(delta, textbus);
4622
5419
  results.forEach(i => {
@@ -4642,6 +5439,8 @@ const tableComponentLoader = {
4642
5439
  });
4643
5440
  const delta = slotParser(new core$1.Slot([
4644
5441
  core$1.ContentType.BlockComponent,
5442
+ core$1.ContentType.InlineComponent,
5443
+ core$1.ContentType.Text
4645
5444
  ]), cell).toDelta();
4646
5445
  const results = deltaToBlock(delta, textbus);
4647
5446
  results.forEach(i => {
@@ -4737,6 +5536,88 @@ function autoComplete(table) {
4737
5536
  });
4738
5537
  }
4739
5538
 
5539
+ function findFocusCell(table, slot) {
5540
+ var _a;
5541
+ while (slot) {
5542
+ if (table.slots.includes(slot)) {
5543
+ return slot;
5544
+ }
5545
+ slot = (_a = slot.parent) === null || _a === void 0 ? void 0 : _a.parent;
5546
+ }
5547
+ return null;
5548
+ }
5549
+ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate extends platformBrowser.CollaborateSelectionAwarenessDelegate {
5550
+ constructor(domAdapter, selection) {
5551
+ super();
5552
+ this.domAdapter = domAdapter;
5553
+ this.selection = selection;
5554
+ }
5555
+ getRects(abstractSelection) {
5556
+ const { focusSlot, anchorSlot } = abstractSelection;
5557
+ const focusPaths = this.selection.getPathsBySlot(focusSlot);
5558
+ const anchorPaths = this.selection.getPathsBySlot(anchorSlot);
5559
+ const focusIsStart = core$1.Selection.compareSelectionPaths(focusPaths, anchorPaths);
5560
+ let startSlot;
5561
+ let endSlot;
5562
+ if (focusIsStart) {
5563
+ startSlot = focusSlot;
5564
+ endSlot = anchorSlot;
5565
+ }
5566
+ else {
5567
+ startSlot = anchorSlot;
5568
+ endSlot = focusSlot;
5569
+ }
5570
+ const commonAncestorComponent = core$1.Selection.getCommonAncestorComponent(startSlot, endSlot);
5571
+ if (!(commonAncestorComponent instanceof TableComponent)) {
5572
+ return false;
5573
+ }
5574
+ const range = getSelectedRanges(commonAncestorComponent, findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
5575
+ const rows = commonAncestorComponent.state.rows;
5576
+ const startFocusSlot = rows[range.startRow].cells[range.startColumn].slot;
5577
+ const endFocusSlot = rows[range.endRow].cells[range.endColumn].slot;
5578
+ const renderer = this.domAdapter;
5579
+ const startRect = renderer.getNativeNodeBySlot(startFocusSlot).getBoundingClientRect();
5580
+ const endRect = renderer.getNativeNodeBySlot(endFocusSlot).getBoundingClientRect();
5581
+ return [{
5582
+ left: startRect.left,
5583
+ top: startRect.top,
5584
+ width: endRect.left + endRect.width - startRect.left,
5585
+ height: endRect.top + endRect.height - startRect.top
5586
+ }];
5587
+ }
5588
+ };
5589
+ TableSelectionAwarenessDelegate = __decorate([
5590
+ core.Injectable(),
5591
+ __metadata("design:paramtypes", [platformBrowser.DomAdapter,
5592
+ core$1.Selection])
5593
+ ], TableSelectionAwarenessDelegate);
5594
+ function getSelectedRanges(component, startSlot, endSlot) {
5595
+ const p1 = finedPosition(component, startSlot);
5596
+ const p2 = finedPosition(component, endSlot);
5597
+ return {
5598
+ startRow: Math.min(p1.rowIndex, p2.rowIndex),
5599
+ endRow: Math.max(p1.rowIndex, p2.rowIndex),
5600
+ startColumn: Math.min(p1.columnIndex, p2.columnIndex),
5601
+ endColumn: Math.max(p1.columnIndex, p2.columnIndex)
5602
+ };
5603
+ }
5604
+ function finedPosition(component, slot) {
5605
+ const rows = component.state.rows;
5606
+ for (let i = 0; i < rows.length; i++) {
5607
+ const row = rows[i];
5608
+ for (let j = 0; j < row.cells.length; j++) {
5609
+ const cell = row.cells[j].slot;
5610
+ if (cell === slot) {
5611
+ return {
5612
+ rowIndex: i,
5613
+ columnIndex: j
5614
+ };
5615
+ }
5616
+ }
5617
+ }
5618
+ return null;
5619
+ }
5620
+
4740
5621
  class Editor extends core$1.Textbus {
4741
5622
  constructor(editorConfig = {}) {
4742
5623
  const adapter = new adapterViewfly.ViewflyAdapter({
@@ -4749,13 +5630,15 @@ class Editor extends core$1.Textbus {
4749
5630
  [HighlightBoxComponent.componentName]: HighlightBoxView,
4750
5631
  [ListComponent.componentName]: ListComponentView,
4751
5632
  [ImageComponent.componentName]: ImageView,
4752
- [VideoComponent.componentName]: VideoView
5633
+ [VideoComponent.componentName]: VideoView,
5634
+ [AtComponent.componentName]: AtComponentView,
5635
+ [KatexComponent.componentName]: KatexComponentView,
4753
5636
  }, (host, root, injector) => {
4754
5637
  const appInjector = new core.ReflectiveInjector(injector, [{
4755
5638
  provide: OutputInjectionToken,
4756
5639
  useValue: false
4757
5640
  }]);
4758
- const app = platformBrowser$1.createApp(root, {
5641
+ const app = platformBrowser$1.createApp(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [root, jsxRuntime.jsx(LinkJump, {})] }), {
4759
5642
  context: appInjector
4760
5643
  }).mount(host);
4761
5644
  return () => {
@@ -4764,16 +5647,18 @@ class Editor extends core$1.Textbus {
4764
5647
  });
4765
5648
  const browserModule = new platformBrowser.BrowserModule(Object.assign({ renderTo: () => {
4766
5649
  return this.host;
4767
- }, adapter, componentLoaders: [
5650
+ }, useContentEditable: platformBrowser.isMobileBrowser(), adapter, componentLoaders: [
5651
+ atComponentLoader,
4768
5652
  sourceCodeComponentLoader,
5653
+ listComponentLoader,
4769
5654
  tableComponentLoader,
4770
5655
  imageComponentLoader,
4771
- videoComponentLoader,
4772
5656
  highlightBoxComponentLoader,
4773
5657
  blockquoteComponentLoader,
4774
- paragraphComponentLoader,
5658
+ videoComponentLoader,
4775
5659
  todolistComponentLoader,
4776
- listComponentLoader,
5660
+ katexComponentLoader,
5661
+ paragraphComponentLoader,
4777
5662
  ], formatLoaders: [
4778
5663
  backgroundColorFormatLoader,
4779
5664
  boldFormatLoader,
@@ -4793,6 +5678,10 @@ class Editor extends core$1.Textbus {
4793
5678
  const modules = [browserModule];
4794
5679
  if (editorConfig.collaborateConfig) {
4795
5680
  modules.push(new collaborate.CollaborateModule(editorConfig.collaborateConfig));
5681
+ browserModule.providers.push({
5682
+ provide: platformBrowser.CollaborateSelectionAwarenessDelegate,
5683
+ useClass: TableSelectionAwarenessDelegate
5684
+ });
4796
5685
  }
4797
5686
  const vDomAdapter = new adapterViewfly.ViewflyVDomAdapter({
4798
5687
  [ParagraphComponent.componentName]: ParagraphView,
@@ -4804,7 +5693,9 @@ class Editor extends core$1.Textbus {
4804
5693
  [HighlightBoxComponent.componentName]: HighlightBoxView,
4805
5694
  [ListComponent.componentName]: ListComponentView,
4806
5695
  [ImageComponent.componentName]: ImageView,
4807
- [VideoComponent.componentName]: VideoView
5696
+ [VideoComponent.componentName]: VideoView,
5697
+ [AtComponent.componentName]: AtComponentView,
5698
+ [KatexComponent.componentName]: KatexComponentView
4808
5699
  }, (host, root, injector) => {
4809
5700
  const appInjector = new core.ReflectiveInjector(injector, [{
4810
5701
  provide: OutputInjectionToken,
@@ -4833,7 +5724,9 @@ class Editor extends core$1.Textbus {
4833
5724
  TableComponent,
4834
5725
  HighlightBoxComponent,
4835
5726
  ListComponent,
4836
- VideoComponent
5727
+ VideoComponent,
5728
+ AtComponent,
5729
+ KatexComponent
4837
5730
  ], formatters: [
4838
5731
  backgroundColorFormatter,
4839
5732
  boldFormatter,
@@ -4861,6 +5754,9 @@ class Editor extends core$1.Textbus {
4861
5754
  registerHeadingShortcut(textbus);
4862
5755
  registerTextAlignShortcut(textbus);
4863
5756
  registerTextIndentShortcut(textbus);
5757
+ registerAtShortcut(textbus);
5758
+ registerListShortcut(textbus);
5759
+ registerBlockquoteShortcut(textbus);
4864
5760
  } }, editorConfig));
4865
5761
  this.editorConfig = editorConfig;
4866
5762
  this.translator = new platformBrowser$1.OutputTranslator();
@@ -4873,9 +5769,22 @@ class Editor extends core$1.Textbus {
4873
5769
  if (config.content) {
4874
5770
  const parser = this.get(platformBrowser.Parser);
4875
5771
  const doc = parser.parseDoc(config.content, rootComponentLoader);
4876
- rootComp = doc instanceof core$1.Component ? doc : new RootComponent(this, {
4877
- content: doc
4878
- });
5772
+ if (doc instanceof core$1.Component) {
5773
+ rootComp = doc;
5774
+ }
5775
+ else {
5776
+ const content = new core$1.Slot([
5777
+ core$1.ContentType.BlockComponent
5778
+ ]);
5779
+ if (doc instanceof core$1.Slot) {
5780
+ deltaToBlock(doc.toDelta(), this).forEach(i => {
5781
+ content.insert(i);
5782
+ });
5783
+ }
5784
+ rootComp = new RootComponent(this, {
5785
+ content
5786
+ });
5787
+ }
4879
5788
  }
4880
5789
  else {
4881
5790
  rootComp = new RootComponent(this, {
@@ -4889,6 +5798,8 @@ class Editor extends core$1.Textbus {
4889
5798
  }
4890
5799
  }
4891
5800
 
5801
+ exports.AtComponent = AtComponent;
5802
+ exports.AtComponentView = AtComponentView;
4892
5803
  exports.AttrTool = AttrTool;
4893
5804
  exports.BlockTool = BlockTool;
4894
5805
  exports.BlockquoteComponent = BlockquoteComponent;
@@ -4903,6 +5814,7 @@ exports.DragResize = DragResize;
4903
5814
  exports.Dropdown = Dropdown;
4904
5815
  exports.DropdownMenuPortal = DropdownMenuPortal;
4905
5816
  exports.Editor = Editor;
5817
+ exports.FileUploader = FileUploader;
4906
5818
  exports.FontFamilyTool = FontFamilyTool;
4907
5819
  exports.FontSizeTool = FontSizeTool;
4908
5820
  exports.HighlightBoxComponent = HighlightBoxComponent;
@@ -4911,13 +5823,19 @@ exports.ImageComponent = ImageComponent;
4911
5823
  exports.ImageView = ImageView;
4912
5824
  exports.InsertTool = InsertTool;
4913
5825
  exports.ItalicTool = ItalicTool;
5826
+ exports.KatexComponent = KatexComponent;
5827
+ exports.KatexComponentView = KatexComponentView;
5828
+ exports.Keymap = Keymap;
4914
5829
  exports.LeftToolbar = LeftToolbar;
4915
5830
  exports.LeftToolbarPlugin = LeftToolbarPlugin;
5831
+ exports.LinkJump = LinkJump;
4916
5832
  exports.LinkTool = LinkTool;
4917
5833
  exports.ListComponent = ListComponent;
4918
5834
  exports.ListComponentView = ListComponentView;
4919
5835
  exports.Matcher = Matcher;
5836
+ exports.MenuHeading = MenuHeading;
4920
5837
  exports.MenuItem = MenuItem;
5838
+ exports.Organization = Organization;
4921
5839
  exports.OutputInjectionToken = OutputInjectionToken;
4922
5840
  exports.ParagraphComponent = ParagraphComponent;
4923
5841
  exports.ParagraphView = ParagraphView;
@@ -4937,6 +5855,7 @@ exports.ToolbarPlugin = ToolbarPlugin;
4937
5855
  exports.UnderlineTool = UnderlineTool;
4938
5856
  exports.VideoComponent = VideoComponent;
4939
5857
  exports.VideoView = VideoView;
5858
+ exports.atComponentLoader = atComponentLoader;
4940
5859
  exports.autoComplete = autoComplete;
4941
5860
  exports.backgroundColorFormatLoader = backgroundColorFormatLoader;
4942
5861
  exports.backgroundColorFormatter = backgroundColorFormatter;
@@ -4959,15 +5878,19 @@ exports.imageComponentLoader = imageComponentLoader;
4959
5878
  exports.isSupportFont = isSupportFont;
4960
5879
  exports.italicFormatLoader = italicFormatLoader;
4961
5880
  exports.italicFormatter = italicFormatter;
5881
+ exports.katexComponentLoader = katexComponentLoader;
4962
5882
  exports.languageList = languageList;
4963
5883
  exports.linkFormatLoader = linkFormatLoader;
4964
5884
  exports.linkFormatter = linkFormatter;
4965
5885
  exports.listComponentLoader = listComponentLoader;
4966
5886
  exports.paragraphComponentLoader = paragraphComponentLoader;
5887
+ exports.registerAtShortcut = registerAtShortcut;
5888
+ exports.registerBlockquoteShortcut = registerBlockquoteShortcut;
4967
5889
  exports.registerBoldShortcut = registerBoldShortcut;
4968
5890
  exports.registerCodeShortcut = registerCodeShortcut;
4969
5891
  exports.registerHeadingShortcut = registerHeadingShortcut;
4970
5892
  exports.registerItalicShortcut = registerItalicShortcut;
5893
+ exports.registerListShortcut = registerListShortcut;
4971
5894
  exports.registerStrikeThroughShortcut = registerStrikeThroughShortcut;
4972
5895
  exports.registerTextAlignShortcut = registerTextAlignShortcut;
4973
5896
  exports.registerTextIndentShortcut = registerTextIndentShortcut;
@@ -4982,6 +5905,8 @@ exports.textAlignAttr = textAlignAttr;
4982
5905
  exports.textAlignAttrLoader = textAlignAttrLoader;
4983
5906
  exports.textIndentAttr = textIndentAttr;
4984
5907
  exports.textIndentAttrLoader = textIndentAttrLoader;
5908
+ exports.toBlockquote = toBlockquote;
5909
+ exports.toList = toList;
4985
5910
  exports.todolistComponentLoader = todolistComponentLoader;
4986
5911
  exports.toggleBold = toggleBold;
4987
5912
  exports.toggleCode = toggleCode;