@textbus/xnote 0.0.1-alpha.12 → 0.0.1-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bundles/index.js CHANGED
@@ -8,10 +8,11 @@ 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 color = require('@tanbo/color');
11
12
  var adapterViewfly = require('@textbus/adapter-viewfly');
12
13
  var collaborate = require('@textbus/collaborate');
13
14
 
14
- var scopedId$k = "vf-3d0183";
15
+ var scopedId$l = "vf-3d0183";
15
16
 
16
17
  /******************************************************************************
17
18
  Copyright (c) Microsoft Corporation.
@@ -132,7 +133,7 @@ function Button(props) {
132
133
  subscription.unsubscribe();
133
134
  });
134
135
  }
135
- return scopedCss.withScopedCSS(scopedId$k, () => {
136
+ return scopedCss.withScopedCSS(scopedId$l, () => {
136
137
  return (jsxRuntime.jsxs("button", Object.assign({ type: "button" }, props, { class: [
137
138
  'btn',
138
139
  {
@@ -144,10 +145,10 @@ function Button(props) {
144
145
  });
145
146
  }
146
147
 
147
- var scopedId$j = "vf-ac7e8d";
148
+ var scopedId$k = "vf-ac7e8d";
148
149
 
149
150
  function ComponentToolbar(props) {
150
- return scopedCss.withScopedCSS(scopedId$j, () => {
151
+ return scopedCss.withScopedCSS(scopedId$k, () => {
151
152
  return (jsxRuntime.jsx("div", { class: "component-toolbar", style: props.style, children: jsxRuntime.jsx("div", { class: [
152
153
  'toolbar',
153
154
  {
@@ -157,15 +158,15 @@ function ComponentToolbar(props) {
157
158
  });
158
159
  }
159
160
 
160
- var scopedId$i = "vf-ede279";
161
+ var scopedId$j = "vf-ede279";
161
162
 
162
163
  function Divider() {
163
- return scopedCss.withScopedCSS(scopedId$i, () => {
164
+ return scopedCss.withScopedCSS(scopedId$j, () => {
164
165
  return jsxRuntime.jsx("div", { class: "divider" });
165
166
  });
166
167
  }
167
168
 
168
- var scopedId$h = "vf-4c1803";
169
+ var scopedId$i = "vf-4c1803";
169
170
 
170
171
  function DragResize(props) {
171
172
  const isShow = core.createSignal(false);
@@ -273,16 +274,16 @@ function DragResize(props) {
273
274
  unUp.unsubscribe();
274
275
  });
275
276
  }
276
- return scopedCss.withScopedCSS(scopedId$h, () => {
277
+ return scopedCss.withScopedCSS(scopedId$i, () => {
277
278
  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
279
  active: isShow()
279
280
  }], 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" })] })] })] }));
280
281
  });
281
282
  }
282
283
 
283
- var scopedId$g = "vf-a99c5e";
284
+ var scopedId$h = "vf-a99c5e";
284
285
 
285
- var scopedId$f = "vf-ab6f55";
286
+ var scopedId$g = "vf-ab6f55";
286
287
 
287
288
  const DropdownMenuPortal = core.withAnnotation({
288
289
  providers: [
@@ -293,7 +294,7 @@ const DropdownMenuPortal = core.withAnnotation({
293
294
  const menuRef = core.createRef();
294
295
  let timer = null;
295
296
  const delay = 10;
296
- core.onMounted(() => {
297
+ function update() {
297
298
  const menuElement = menuRef.current;
298
299
  if (props.abreast) {
299
300
  const btnEle = props.triggerRef.current;
@@ -353,19 +354,28 @@ const DropdownMenuPortal = core.withAnnotation({
353
354
  }, delay);
354
355
  }
355
356
  }
357
+ }
358
+ core.onUpdated(() => {
359
+ update();
356
360
  });
357
361
  core.onUnmounted(() => {
358
362
  clearTimeout(timer);
359
363
  });
360
364
  function onEnter() {
365
+ if (props.noTrigger) {
366
+ return;
367
+ }
361
368
  dropdownContextService.canHide = false;
362
369
  dropdownContextService.open();
363
370
  }
364
371
  function onLeave() {
372
+ if (props.noTrigger) {
373
+ return;
374
+ }
365
375
  dropdownContextService.canHide = true;
366
376
  dropdownContextService.hide();
367
377
  }
368
- return platformBrowser$1.createPortal(scopedCss.withScopedCSS(scopedId$f, () => {
378
+ return platformBrowser$1.createPortal(scopedCss.withScopedCSS(scopedId$g, () => {
369
379
  return (jsxRuntime.jsx("div", { onMouseenter: onEnter, onMouseleave: onLeave, ref: menuRef, style: {
370
380
  width: props.width
371
381
  }, class: "dropdown-menu", children: jsxRuntime.jsx("div", { class: "dropdown-menu-content", children: props.children }) }));
@@ -397,6 +407,9 @@ const Dropdown = core.withAnnotation({
397
407
  });
398
408
  const subscription = new core$1.Subscription();
399
409
  core.onMounted(() => {
410
+ if (props.trigger === 'none') {
411
+ return;
412
+ }
400
413
  if (props.trigger === 'click') {
401
414
  subscription.add(core$1.fromEvent(triggerRef.current, 'click').subscribe(toggle));
402
415
  return;
@@ -422,14 +435,14 @@ const Dropdown = core.withAnnotation({
422
435
  return {
423
436
  isShow(b) {
424
437
  if (b) {
425
- dropdownContextService.hide(false);
438
+ dropdownContextService.open();
426
439
  }
427
440
  else {
428
- dropdownContextService.open();
441
+ dropdownContextService.hide(false);
429
442
  }
430
443
  },
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) ?
444
+ $render: scopedCss.withScopedCSS(scopedId$h, () => {
445
+ 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, { noTrigger: props.trigger === 'none', width: props.width, abreast: props.abreast, triggerRef: triggerRef, children: Array.isArray(props.menu) ?
433
446
  props.menu.map(menu => {
434
447
  return (jsxRuntime.jsx("div", { class: "dropdown-menu-item", onClick: () => {
435
448
  var _a;
@@ -444,6 +457,14 @@ const Dropdown = core.withAnnotation({
444
457
  };
445
458
  });
446
459
 
460
+ var scopedId$f = "vf-acaa5f";
461
+
462
+ function MenuHeading(props) {
463
+ return scopedCss.withScopedCSS(scopedId$f, () => {
464
+ return (jsxRuntime.jsx("div", { class: "menu-heading", children: props.children }));
465
+ });
466
+ }
467
+
447
468
  var scopedId$e = "vf-678daa";
448
469
 
449
470
  function MenuItem(props) {
@@ -605,11 +626,192 @@ function registerHeadingShortcut(textbus) {
605
626
  const commonAncestorSlot = selection.commonAncestorSlot;
606
627
  commonAncestorSlot.cut();
607
628
  commander.applyAttribute(headingAttr, 'h' + content.length);
629
+ selection.setPosition(commonAncestorSlot, 0);
608
630
  return true;
609
631
  }
610
632
  });
611
633
  }
612
634
 
635
+ function useBlockContent(slot) {
636
+ const textbus = core$1.useContext();
637
+ const selection = textbus.get(core$1.Selection);
638
+ core$1.onBreak(ev => {
639
+ if (typeof slot === 'function' ? slot(ev.target) : ev.target === slot) {
640
+ const p = new ParagraphComponent(textbus);
641
+ ev.target.insert(p);
642
+ selection.setPosition(p.state.slot, 0);
643
+ ev.preventDefault();
644
+ }
645
+ });
646
+ core$1.onContentInsert(ev => {
647
+ if ((typeof slot === 'function' ? slot(ev.target) : ev.target === slot) &&
648
+ (typeof ev.data.content === 'string' || ev.data.content.type !== core$1.ContentType.BlockComponent)) {
649
+ const p = new ParagraphComponent(textbus);
650
+ const childSlot = p.state.slot;
651
+ childSlot.insert(ev.data.content);
652
+ ev.target.insert(p);
653
+ selection.setPosition(childSlot, childSlot.index);
654
+ ev.preventDefault();
655
+ }
656
+ });
657
+ }
658
+
659
+ class BlockquoteComponent extends core$1.Component {
660
+ static fromJSON(textbus, json) {
661
+ const slot = textbus.get(core$1.Registry).createSlot(json.slot);
662
+ return new BlockquoteComponent(textbus, {
663
+ slot
664
+ });
665
+ }
666
+ constructor(textbus, state = {
667
+ slot: new core$1.Slot([
668
+ core$1.ContentType.BlockComponent
669
+ ])
670
+ }) {
671
+ super(textbus, state);
672
+ }
673
+ setup() {
674
+ useBlockContent(this.state.slot);
675
+ }
676
+ }
677
+ BlockquoteComponent.type = core$1.ContentType.BlockComponent;
678
+ BlockquoteComponent.componentName = 'BlockquoteComponent';
679
+ BlockquoteComponent.zenCoding = {
680
+ key: ' ',
681
+ match(content, textbus) {
682
+ const selection = textbus.get(core$1.Selection);
683
+ if (selection.commonAncestorComponent instanceof ParagraphComponent) {
684
+ return /^>$/.test(content);
685
+ }
686
+ return false;
687
+ },
688
+ createState(_, textbus) {
689
+ const selection = textbus.get(core$1.Selection);
690
+ const commonAncestorSlot = selection.commonAncestorSlot;
691
+ const slot = new core$1.Slot([
692
+ core$1.ContentType.BlockComponent
693
+ ]);
694
+ if (commonAncestorSlot === null || commonAncestorSlot === void 0 ? void 0 : commonAncestorSlot.hasAttribute(textIndentAttr)) {
695
+ slot.setAttribute(textIndentAttr, commonAncestorSlot.getAttribute(textIndentAttr));
696
+ }
697
+ return {
698
+ slot
699
+ };
700
+ }
701
+ };
702
+ function BlockquoteView(props) {
703
+ const adapter = core.inject(platformBrowser.DomAdapter);
704
+ const readonly = useReadonly();
705
+ const output = useOutput();
706
+ return () => {
707
+ const slot = props.component.state.slot;
708
+ return (jsxRuntime.jsx("blockquote", { class: "xnote-blockquote", ref: props.rootRef, "data-component": props.component.name, children: adapter.slotRender(slot, children => {
709
+ return core$1.createVNode('div', null, children);
710
+ }, readonly() || output()) }));
711
+ };
712
+ }
713
+ const blockquoteComponentLoader = {
714
+ match(element) {
715
+ return element.tagName === 'BLOCKQUOTE';
716
+ },
717
+ read(element, textbus, slotParser) {
718
+ const delta = slotParser(new core$1.Slot([
719
+ core$1.ContentType.BlockComponent,
720
+ core$1.ContentType.InlineComponent,
721
+ core$1.ContentType.Text
722
+ ]), element).toDelta();
723
+ const slot = new core$1.Slot([
724
+ core$1.ContentType.BlockComponent,
725
+ ]);
726
+ deltaToBlock(delta, textbus).forEach(i => {
727
+ slot.insert(i);
728
+ });
729
+ return new BlockquoteComponent(textbus, {
730
+ slot
731
+ });
732
+ },
733
+ };
734
+
735
+ class HighlightBoxComponent extends core$1.Component {
736
+ static fromJSON(textbus, json) {
737
+ return new HighlightBoxComponent(textbus, {
738
+ type: json.type,
739
+ slot: textbus.get(core$1.Registry).createSlot(json.slot)
740
+ });
741
+ }
742
+ constructor(textbus, state = {
743
+ type: '',
744
+ slot: new core$1.Slot([
745
+ core$1.ContentType.BlockComponent,
746
+ ])
747
+ }) {
748
+ super(textbus, state);
749
+ }
750
+ setup() {
751
+ useBlockContent(this.state.slot);
752
+ }
753
+ }
754
+ HighlightBoxComponent.defaultTypes = ['❤️', '💡', '📌', '✅', '❎', '👍', '🎉', '🚫', '❗'];
755
+ HighlightBoxComponent.componentName = 'HighlightBoxComponent';
756
+ HighlightBoxComponent.type = core$1.ContentType.BlockComponent;
757
+ function HighlightBoxView(props) {
758
+ const adapter = core.inject(platformBrowser.DomAdapter);
759
+ const readonly = useReadonly();
760
+ const output = useOutput();
761
+ const emoji = [];
762
+ for (let i = 0x1F600; i <= 0x1F64F; i++) {
763
+ emoji.push(i);
764
+ }
765
+ const dropdownRef = core.createRef();
766
+ function setType(type) {
767
+ var _a;
768
+ (_a = dropdownRef.current) === null || _a === void 0 ? void 0 : _a.isShow(false);
769
+ props.component.state.type = type;
770
+ }
771
+ return () => {
772
+ const { state, name } = props.component;
773
+ if (readonly() || output()) {
774
+ 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 => {
775
+ return core$1.createVNode('div', {
776
+ class: 'xnote-highlight-box-content'
777
+ }, children);
778
+ }, readonly() || output())] }));
779
+ }
780
+ 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 => {
781
+ return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
782
+ }), jsxRuntime.jsx("div", { class: "xnote-highlight-box-heading", children: "\u66F4\u591A" }), emoji.map(i => {
783
+ const icon = String.fromCodePoint(i);
784
+ return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
785
+ })] }), children: jsxRuntime.jsx("div", { class: "xnote-highlight-box-icon", children: jsxRuntime.jsx("button", { type: "button", children: state.type || '❤️' }) }) }) }), adapter.slotRender(state.slot, children => {
786
+ return core$1.createVNode('div', {
787
+ class: 'xnote-highlight-box-content'
788
+ }, children);
789
+ }, readonly() || output())] }));
790
+ };
791
+ }
792
+ const highlightBoxComponentLoader = {
793
+ match(element) {
794
+ return element.tagName === 'DIV' && element.dataset.component === HighlightBoxComponent.componentName;
795
+ },
796
+ read(element, textbus, slotParser) {
797
+ const delta = slotParser(new core$1.Slot([
798
+ core$1.ContentType.BlockComponent,
799
+ core$1.ContentType.InlineComponent,
800
+ core$1.ContentType.Text
801
+ ]), element.querySelector('.xnote-highlight-box-content')).toDelta();
802
+ const slot = new core$1.Slot([
803
+ core$1.ContentType.BlockComponent,
804
+ ]);
805
+ deltaToBlock(delta, textbus).forEach(i => {
806
+ slot.insert(i);
807
+ });
808
+ return new HighlightBoxComponent(textbus, {
809
+ type: element.dataset.icon || '',
810
+ slot
811
+ });
812
+ }
813
+ };
814
+
613
815
  class ParagraphComponent extends core$1.Component {
614
816
  static fromJSON(textbus, json) {
615
817
  const slot = textbus.get(core$1.Registry).createSlot(json.slot);
@@ -630,12 +832,20 @@ class ParagraphComponent extends core$1.Component {
630
832
  const commander = injector.get(core$1.Commander);
631
833
  const selection = injector.get(core$1.Selection);
632
834
  core$1.onBreak(ev => {
835
+ const isEmpty = this.state.slot.isEmpty;
633
836
  const afterSlot = ev.target.cut(ev.data.index);
634
837
  afterSlot.removeAttribute(headingAttr);
635
838
  const nextParagraph = new ParagraphComponent(injector, {
636
839
  slot: afterSlot
637
840
  });
638
- commander.insertAfter(nextParagraph, this);
841
+ if (isEmpty && (this.parentComponent instanceof BlockquoteComponent ||
842
+ this.parentComponent instanceof HighlightBoxComponent)) {
843
+ commander.insertAfter(nextParagraph, this.parentComponent);
844
+ commander.removeComponent(this);
845
+ }
846
+ else {
847
+ commander.insertAfter(nextParagraph, this);
848
+ }
639
849
  selection.setPosition(afterSlot, 0);
640
850
  ev.preventDefault();
641
851
  });
@@ -1424,30 +1634,6 @@ function AttrTool(props) {
1424
1634
  });
1425
1635
  }
1426
1636
 
1427
- function useBlockContent(slot) {
1428
- const textbus = core$1.useContext();
1429
- const selection = textbus.get(core$1.Selection);
1430
- core$1.onBreak(ev => {
1431
- if (typeof slot === 'function' ? slot(ev.target) : ev.target === slot) {
1432
- const p = new ParagraphComponent(textbus);
1433
- ev.target.insert(p);
1434
- selection.setPosition(p.state.slot, 0);
1435
- ev.preventDefault();
1436
- }
1437
- });
1438
- core$1.onContentInsert(ev => {
1439
- if ((typeof slot === 'function' ? slot(ev.target) : ev.target === slot) &&
1440
- (typeof ev.data.content === 'string' || ev.data.content.type !== core$1.ContentType.BlockComponent)) {
1441
- const p = new ParagraphComponent(textbus);
1442
- const childSlot = p.state.slot;
1443
- childSlot.insert(ev.data.content);
1444
- ev.target.insert(p);
1445
- selection.setPosition(childSlot, childSlot.index);
1446
- ev.preventDefault();
1447
- }
1448
- });
1449
- }
1450
-
1451
1637
  const defaultRowHeight = 30;
1452
1638
  const defaultColumnWidth = 100;
1453
1639
  class TableComponent extends core$1.Component {
@@ -1790,14 +1976,20 @@ TodolistComponent.zenCoding = {
1790
1976
  return false;
1791
1977
  },
1792
1978
  key: ' ',
1793
- createState(content) {
1979
+ createState(content, textbus) {
1980
+ const selection = textbus.get(core$1.Selection);
1981
+ const commonAncestorSlot = selection.commonAncestorSlot;
1982
+ const slot = new core$1.Slot([
1983
+ core$1.ContentType.InlineComponent,
1984
+ core$1.ContentType.Text
1985
+ ]);
1986
+ if (commonAncestorSlot === null || commonAncestorSlot === void 0 ? void 0 : commonAncestorSlot.hasAttribute(textIndentAttr)) {
1987
+ slot.setAttribute(textIndentAttr, commonAncestorSlot.getAttribute(textIndentAttr));
1988
+ }
1794
1989
  const isChecked = content.charAt(1) === 'x';
1795
1990
  return {
1796
1991
  checked: isChecked,
1797
- slot: new core$1.Slot([
1798
- core$1.ContentType.InlineComponent,
1799
- core$1.ContentType.Text
1800
- ])
1992
+ slot
1801
1993
  };
1802
1994
  }
1803
1995
  };
@@ -1854,76 +2046,6 @@ const todolistComponentLoader = {
1854
2046
  }
1855
2047
  };
1856
2048
 
1857
- class BlockquoteComponent extends core$1.Component {
1858
- static fromJSON(textbus, json) {
1859
- const slot = textbus.get(core$1.Registry).createSlot(json.slot);
1860
- return new BlockquoteComponent(textbus, {
1861
- slot
1862
- });
1863
- }
1864
- constructor(textbus, state = {
1865
- slot: new core$1.Slot([
1866
- core$1.ContentType.BlockComponent
1867
- ])
1868
- }) {
1869
- super(textbus, state);
1870
- }
1871
- setup() {
1872
- useBlockContent(this.state.slot);
1873
- }
1874
- }
1875
- BlockquoteComponent.type = core$1.ContentType.BlockComponent;
1876
- BlockquoteComponent.componentName = 'BlockquoteComponent';
1877
- BlockquoteComponent.zenCoding = {
1878
- key: ' ',
1879
- match(content, textbus) {
1880
- const selection = textbus.get(core$1.Selection);
1881
- if (selection.commonAncestorComponent instanceof ParagraphComponent) {
1882
- return /^>$/.test(content);
1883
- }
1884
- return false;
1885
- },
1886
- createState() {
1887
- return {
1888
- slot: new core$1.Slot([
1889
- core$1.ContentType.BlockComponent
1890
- ])
1891
- };
1892
- }
1893
- };
1894
- function BlockquoteView(props) {
1895
- const adapter = core.inject(platformBrowser.DomAdapter);
1896
- const readonly = useReadonly();
1897
- const output = useOutput();
1898
- return () => {
1899
- const slot = props.component.state.slot;
1900
- return (jsxRuntime.jsx("blockquote", { class: "xnote-blockquote", ref: props.rootRef, "data-component": props.component.name, children: adapter.slotRender(slot, children => {
1901
- return core$1.createVNode('div', null, children);
1902
- }, readonly() || output()) }));
1903
- };
1904
- }
1905
- const blockquoteComponentLoader = {
1906
- match(element) {
1907
- return element.tagName === 'BLOCKQUOTE';
1908
- },
1909
- read(element, textbus, slotParser) {
1910
- const delta = slotParser(new core$1.Slot([
1911
- core$1.ContentType.BlockComponent,
1912
- core$1.ContentType.InlineComponent,
1913
- core$1.ContentType.Text
1914
- ]), element).toDelta();
1915
- const slot = new core$1.Slot([
1916
- core$1.ContentType.BlockComponent,
1917
- ]);
1918
- deltaToBlock(delta, textbus).forEach(i => {
1919
- slot.insert(i);
1920
- });
1921
- return new BlockquoteComponent(textbus, {
1922
- slot
1923
- });
1924
- },
1925
- };
1926
-
1927
2049
  class ListComponent extends core$1.Component {
1928
2050
  static fromJSON(textbus, json) {
1929
2051
  return new ListComponent(textbus, {
@@ -2037,14 +2159,20 @@ ListComponent.zenCoding = {
2037
2159
  }
2038
2160
  return false;
2039
2161
  },
2040
- createState(content) {
2162
+ createState(content, textbus) {
2163
+ const selection = textbus.get(core$1.Selection);
2164
+ const commonAncestorSlot = selection.commonAncestorSlot;
2165
+ const slot = new core$1.Slot([
2166
+ core$1.ContentType.InlineComponent,
2167
+ core$1.ContentType.Text
2168
+ ]);
2169
+ if (commonAncestorSlot === null || commonAncestorSlot === void 0 ? void 0 : commonAncestorSlot.hasAttribute(textIndentAttr)) {
2170
+ slot.setAttribute(textIndentAttr, commonAncestorSlot.getAttribute(textIndentAttr));
2171
+ }
2041
2172
  return {
2042
2173
  type: /[-+*]/.test(content) ? 'UnorderedList' : 'OrderedList',
2043
2174
  reorder: true,
2044
- slot: new core$1.Slot([
2045
- core$1.ContentType.InlineComponent,
2046
- core$1.ContentType.Text
2047
- ])
2175
+ slot
2048
2176
  };
2049
2177
  }
2050
2178
  };
@@ -2256,86 +2384,6 @@ function useActiveBlock() {
2256
2384
  };
2257
2385
  }
2258
2386
 
2259
- class HighlightBoxComponent extends core$1.Component {
2260
- static fromJSON(textbus, json) {
2261
- return new HighlightBoxComponent(textbus, {
2262
- type: json.type,
2263
- slot: textbus.get(core$1.Registry).createSlot(json.slot)
2264
- });
2265
- }
2266
- constructor(textbus, state = {
2267
- type: '',
2268
- slot: new core$1.Slot([
2269
- core$1.ContentType.BlockComponent,
2270
- ])
2271
- }) {
2272
- super(textbus, state);
2273
- }
2274
- setup() {
2275
- useBlockContent(this.state.slot);
2276
- }
2277
- }
2278
- HighlightBoxComponent.defaultTypes = ['❤️', '💡', '📌', '✅', '❎', '👍', '🎉', '🚫', '❗'];
2279
- HighlightBoxComponent.componentName = 'HighlightBoxComponent';
2280
- HighlightBoxComponent.type = core$1.ContentType.BlockComponent;
2281
- function HighlightBoxView(props) {
2282
- const adapter = core.inject(platformBrowser.DomAdapter);
2283
- const readonly = useReadonly();
2284
- const output = useOutput();
2285
- const emoji = [];
2286
- for (let i = 0x1F600; i <= 0x1F64F; i++) {
2287
- emoji.push(i);
2288
- }
2289
- const dropdownRef = core.createRef();
2290
- function setType(type) {
2291
- var _a;
2292
- (_a = dropdownRef.current) === null || _a === void 0 ? void 0 : _a.isShow(false);
2293
- props.component.state.type = type;
2294
- }
2295
- return () => {
2296
- const { state, name } = props.component;
2297
- if (readonly() || output()) {
2298
- 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 => {
2299
- return core$1.createVNode('div', {
2300
- class: 'xnote-highlight-box-content'
2301
- }, children);
2302
- }, readonly() || output())] }));
2303
- }
2304
- 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 => {
2305
- return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
2306
- }), jsxRuntime.jsx(Divider, {}), emoji.map(i => {
2307
- const icon = String.fromCodePoint(i);
2308
- return (jsxRuntime.jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
2309
- })] }), children: jsxRuntime.jsx("div", { class: "xnote-highlight-box-icon", children: jsxRuntime.jsx("button", { type: "button", children: state.type || '❤️' }) }) }) }), adapter.slotRender(state.slot, children => {
2310
- return core$1.createVNode('div', {
2311
- class: 'xnote-highlight-box-content'
2312
- }, children);
2313
- }, readonly() || output())] }));
2314
- };
2315
- }
2316
- const highlightBoxComponentLoader = {
2317
- match(element) {
2318
- return element.tagName === 'DIV' && element.dataset.component === HighlightBoxComponent.componentName;
2319
- },
2320
- read(element, textbus, slotParser) {
2321
- const delta = slotParser(new core$1.Slot([
2322
- core$1.ContentType.BlockComponent,
2323
- core$1.ContentType.InlineComponent,
2324
- core$1.ContentType.Text
2325
- ]), element.querySelector('.xnote-highlight-box-content')).toDelta();
2326
- const slot = new core$1.Slot([
2327
- core$1.ContentType.BlockComponent,
2328
- ]);
2329
- deltaToBlock(delta, textbus).forEach(i => {
2330
- slot.insert(i);
2331
- });
2332
- return new HighlightBoxComponent(textbus, {
2333
- type: element.dataset.icon || '',
2334
- slot
2335
- });
2336
- }
2337
- };
2338
-
2339
2387
  function useBlockTransform() {
2340
2388
  const commander = core.inject(core$1.Commander);
2341
2389
  const textbus = core.inject(core$1.Textbus);
@@ -3108,6 +3156,9 @@ const isSupportFont = (function () {
3108
3156
  function FontFamilyTool() {
3109
3157
  const currentFontFamily = core.createSignal('');
3110
3158
  const fontFamilyOptions = [{
3159
+ label: '默认',
3160
+ value: ''
3161
+ }, {
3111
3162
  label: '宋体',
3112
3163
  value: 'SimSun, STSong'
3113
3164
  }, {
@@ -3158,7 +3209,7 @@ function FontFamilyTool() {
3158
3209
  const result = query.queryFormat(fontFamilyFormatter);
3159
3210
  const isHighlight = result.state === core$1.QueryStateType.Enabled;
3160
3211
  highlight.set(isHighlight);
3161
- currentFontFamily.set(isHighlight ? result.value : '默认');
3212
+ currentFontFamily.set(isHighlight ? result.value : '');
3162
3213
  });
3163
3214
  core.onUnmounted(() => {
3164
3215
  subscription.unsubscribe();
@@ -3166,7 +3217,7 @@ function FontFamilyTool() {
3166
3217
  return () => {
3167
3218
  var _a;
3168
3219
  return (jsxRuntime.jsx(Dropdown, { onCheck: check, menu: fontFamilyOptions.map(i => {
3169
- const disabled = !i.value.split(',').map(i => isSupportFont(i.trim())).some(v => v);
3220
+ const disabled = i.value ? !i.value.split(',').map(i => isSupportFont(i.trim())).some(v => v) : false;
3170
3221
  return {
3171
3222
  label: jsxRuntime.jsx(MenuItem, { disabled: disabled, checked: currentFontFamily() === i.value, children: i.label }),
3172
3223
  disabled,
@@ -3558,7 +3609,7 @@ function InsertTool(props) {
3558
3609
  }
3559
3610
  }
3560
3611
  return scopedCss.withScopedCSS(scopedId$8, () => {
3561
- 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" })] });
3612
+ 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-warning" }), children: "\u9AD8\u4EAE\u5757" })] });
3562
3613
  });
3563
3614
  }
3564
3615
 
@@ -3597,12 +3648,14 @@ const LeftToolbar = core.withAnnotation({
3597
3648
  const sub = core$1.fromEvent(docContentContainer, 'mousemove').pipe(core$1.filter(() => {
3598
3649
  return !isIgnoreMove;
3599
3650
  }), core$1.map(ev => {
3651
+ var _a;
3600
3652
  let currentNode = ev.target;
3601
3653
  while (currentNode) {
3602
3654
  const slot = adapter.getSlotByNativeNode(currentNode);
3603
3655
  if (slot) {
3604
- if ((slot === null || slot === void 0 ? void 0 : slot.parent) instanceof SourceCodeComponent || (slot === null || slot === void 0 ? void 0 : slot.parent) instanceof TableComponent) {
3605
- return null;
3656
+ if (((_a = slot === null || slot === void 0 ? void 0 : slot.parent) === null || _a === void 0 ? void 0 : _a.type) === core$1.ContentType.InlineComponent) {
3657
+ currentNode = currentNode.parentNode;
3658
+ continue;
3606
3659
  }
3607
3660
  return slot;
3608
3661
  }
@@ -3617,7 +3670,9 @@ const LeftToolbar = core.withAnnotation({
3617
3670
  activeSlot.set(slot);
3618
3671
  if (slot) {
3619
3672
  checkStates(slot);
3620
- isEmptyBlock.set(slot.parent instanceof ParagraphComponent && slot.isEmpty);
3673
+ isEmptyBlock.set((slot.parent instanceof ParagraphComponent && slot.isEmpty) ||
3674
+ slot.parent instanceof SourceCodeComponent ||
3675
+ slot.parent instanceof TableComponent);
3621
3676
  const nativeNode = adapter.getNativeNodeByComponent(slot.parent);
3622
3677
  updatePosition(draft => {
3623
3678
  const containerRect = docContentContainer.getBoundingClientRect();
@@ -3714,6 +3769,7 @@ const LeftToolbar = core.withAnnotation({
3714
3769
  isIgnoreMove = b;
3715
3770
  }
3716
3771
  return scopedCss.withScopedCSS(scopedId$7, () => {
3772
+ var _a;
3717
3773
  const position = positionSignal();
3718
3774
  const slot = activeSlot();
3719
3775
  let activeNode = jsxRuntime.jsx("span", { class: "xnote-icon-pilcrow" });
@@ -3741,6 +3797,8 @@ const LeftToolbar = core.withAnnotation({
3741
3797
  }
3742
3798
  }
3743
3799
  }
3800
+ const activeParentComponent = (_a = activeSlot()) === null || _a === void 0 ? void 0 : _a.parent;
3801
+ const needInsert = activeParentComponent instanceof TableComponent || activeParentComponent instanceof SourceCodeComponent;
3744
3802
  return (jsxRuntime.jsx("div", { class: "left-toolbar", ref: toolbarRef, children: jsxRuntime.jsx("div", { class: "left-toolbar-btn-wrap", ref: btnRef, style: {
3745
3803
  left: position.left + 'px',
3746
3804
  top: position.top + 'px',
@@ -3750,9 +3808,9 @@ const LeftToolbar = core.withAnnotation({
3750
3808
  right: 0,
3751
3809
  top: 0
3752
3810
  }, menu: isEmptyBlock() ?
3753
- jsxRuntime.jsx(InsertTool, { replace: true, slot: activeSlot() })
3811
+ jsxRuntime.jsx(InsertTool, { replace: !needInsert, slot: activeSlot() })
3754
3812
  :
3755
- 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, { 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() ?
3813
+ 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() ?
3756
3814
  jsxRuntime.jsx("span", { children: jsxRuntime.jsx("i", { class: "xnote-icon-plus" }) })
3757
3815
  :
3758
3816
  jsxRuntime.jsxs("span", { children: [activeNode, jsxRuntime.jsx("i", { style: "font-size: 12px", class: "xnote-icon-more" })] }) }) }) }) }));
@@ -4032,6 +4090,198 @@ class Matcher {
4032
4090
  }
4033
4091
  }
4034
4092
 
4093
+ class Organization {
4094
+ }
4095
+ function registerAtShortcut(textbus) {
4096
+ const keyboard = textbus.get(core$1.Keyboard);
4097
+ const selection = textbus.get(core$1.Selection);
4098
+ const commander = textbus.get(core$1.Commander);
4099
+ keyboard.addShortcut({
4100
+ keymap: {
4101
+ key: '@',
4102
+ shiftKey: true
4103
+ },
4104
+ action() {
4105
+ const { commonAncestorComponent } = selection;
4106
+ if (commonAncestorComponent instanceof SourceCodeComponent) {
4107
+ return false;
4108
+ }
4109
+ const at = new AtComponent(textbus);
4110
+ commander.insert(at);
4111
+ selection.setPosition(at.state.slot, 0);
4112
+ }
4113
+ });
4114
+ }
4115
+ class AtComponent extends core$1.Component {
4116
+ static fromJSON(textbus, { slot: slotState, userInfo }) {
4117
+ const registry = textbus.get(core$1.Registry);
4118
+ if (slotState) {
4119
+ const slot = registry.createSlot(slotState);
4120
+ return new AtComponent({
4121
+ slot
4122
+ });
4123
+ }
4124
+ return new AtComponent(textbus, {
4125
+ userInfo,
4126
+ });
4127
+ }
4128
+ constructor(textbus, state = {
4129
+ slot: new core$1.Slot([core$1.ContentType.Text])
4130
+ }) {
4131
+ if (!state.userInfo && !state.slot) {
4132
+ state.slot = new core$1.Slot([core$1.ContentType.Text]);
4133
+ }
4134
+ super(textbus, state);
4135
+ this.focus = new core$1.Subject();
4136
+ this.members = core.createSignal([]);
4137
+ this.selectedIndex = core.createSignal(0);
4138
+ }
4139
+ setup() {
4140
+ let isFocus = false;
4141
+ core$1.onFocus(() => {
4142
+ isFocus = true;
4143
+ this.focus.next(true);
4144
+ onChange.next();
4145
+ });
4146
+ core$1.onBlur(() => {
4147
+ isFocus = false;
4148
+ this.focus.next(false);
4149
+ });
4150
+ const organization = core$1.useContext(Organization);
4151
+ const selection = core$1.useContext(core$1.Selection);
4152
+ const commander = core$1.useContext(core$1.Commander);
4153
+ const onChange = new core$1.Subject();
4154
+ core$1.onContentInserted((ev) => {
4155
+ const key = this.state.slot.toString();
4156
+ if (key.length > 10) {
4157
+ selection.selectComponent(this);
4158
+ commander.insert(key);
4159
+ ev.preventDefault();
4160
+ return;
4161
+ }
4162
+ onChange.next();
4163
+ });
4164
+ core$1.onContentDeleted(() => {
4165
+ onChange.next();
4166
+ });
4167
+ core$1.onBreak((ev) => {
4168
+ const member = this.members()[this.selectedIndex()];
4169
+ if (member) {
4170
+ this.state.userInfo = Object.assign({}, member);
4171
+ }
4172
+ selection.selectComponentEnd(this);
4173
+ ev.preventDefault();
4174
+ });
4175
+ core$1.useDynamicShortcut({
4176
+ keymap: {
4177
+ key: ['ArrowDown', 'ArrowUp']
4178
+ },
4179
+ action: (key) => {
4180
+ let index = this.selectedIndex();
4181
+ if (key === 'ArrowUp') {
4182
+ if (index > 0) {
4183
+ index--;
4184
+ this.selectedIndex.set(index);
4185
+ }
4186
+ return;
4187
+ }
4188
+ if (index < this.members().length - 1) {
4189
+ index++;
4190
+ this.selectedIndex.set(index);
4191
+ }
4192
+ }
4193
+ });
4194
+ const subs = onChange.pipe(core$1.switchMap(() => {
4195
+ const key = this.state.slot.toString();
4196
+ return core$1.fromPromise(organization.getMembers(key));
4197
+ })).subscribe((members) => {
4198
+ this.members.set(members);
4199
+ this.selectedIndex.set(0);
4200
+ if (isFocus) {
4201
+ this.focus.next(true);
4202
+ }
4203
+ });
4204
+ core$1.onDestroy(() => {
4205
+ subs.unsubscribe();
4206
+ });
4207
+ }
4208
+ }
4209
+ AtComponent.componentName = 'AtComponent';
4210
+ AtComponent.type = core$1.ContentType.InlineComponent;
4211
+
4212
+ function AtComponentView(props) {
4213
+ const adapter = core.inject(platformBrowser.DomAdapter);
4214
+ const selection = core.inject(core$1.Selection);
4215
+ const dropdownRef = core.createRef();
4216
+ const subscription = props.component.focus.subscribe((b) => {
4217
+ if (dropdownRef.current && props.component.members().length) {
4218
+ dropdownRef.current.isShow(b);
4219
+ }
4220
+ });
4221
+ core.onUnmounted(() => {
4222
+ subscription.unsubscribe();
4223
+ });
4224
+ const readonly = useReadonly();
4225
+ const output = useOutput();
4226
+ const membersRef = core.createRef();
4227
+ core.onUpdated(() => {
4228
+ if (output() || readonly()) {
4229
+ return;
4230
+ }
4231
+ const container = membersRef.current;
4232
+ if (container) {
4233
+ const focusItem = container.children[props.component.selectedIndex()];
4234
+ if (focusItem) {
4235
+ focusItem.scrollIntoView({
4236
+ behavior: 'smooth',
4237
+ block: 'center'
4238
+ });
4239
+ }
4240
+ }
4241
+ });
4242
+ return () => {
4243
+ const { slot, userInfo } = props.component.state;
4244
+ const selectedIndex = props.component.selectedIndex();
4245
+ if (userInfo) {
4246
+ return (jsxRuntime.jsxs("span", { class: "xnote-at xnote-at-complete", ref: props.rootRef, "data-component": props.component.name, children: ["@", userInfo.name] }));
4247
+ }
4248
+ if (readonly() || output()) {
4249
+ return (jsxRuntime.jsxs("span", { class: "xnote-at", ref: props.rootRef, "data-component": props.component.name, children: [jsxRuntime.jsx("span", { children: "@" }), slot && adapter.slotRender(slot, children => {
4250
+ return core$1.createVNode('span', {
4251
+ class: 'xnote-at-input'
4252
+ }, children);
4253
+ })] }));
4254
+ }
4255
+ const members = props.component.members();
4256
+ return (jsxRuntime.jsx("span", { 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) => {
4257
+ let hsl = color.any2Hsl(member.color);
4258
+ if (hsl === 'unknown') {
4259
+ hsl = color.any2Hsl('#000');
4260
+ }
4261
+ const rgb = color.hsl2Rgb(hsl);
4262
+ const yiq = (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
4263
+ const color$1 = yiq >= 128 ? '#000' : '#fff';
4264
+ return (jsxRuntime.jsxs("div", { onClick: () => {
4265
+ props.component.state.userInfo = member;
4266
+ selection.selectComponentEnd(props.component);
4267
+ }, 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 }) :
4268
+ 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));
4269
+ }) }), children: [jsxRuntime.jsx("span", { children: "@" }), slot && adapter.slotRender(slot, children => {
4270
+ return core$1.createVNode('span', {
4271
+ class: 'xnote-at-input'
4272
+ }, children);
4273
+ })] }) }));
4274
+ };
4275
+ }
4276
+ const atComponentLoader = {
4277
+ match(element) {
4278
+ return element.dataset.component === AtComponent.componentName;
4279
+ },
4280
+ read(element, textbus) {
4281
+ return new AtComponent(textbus);
4282
+ }
4283
+ };
4284
+
4035
4285
  class RootComponent extends core$1.Component {
4036
4286
  constructor() {
4037
4287
  super(...arguments);
@@ -4049,6 +4299,17 @@ class RootComponent extends core$1.Component {
4049
4299
  this.onCompositionStart.next(ev);
4050
4300
  });
4051
4301
  }
4302
+ afterCheck() {
4303
+ const content = this.state.content;
4304
+ const lastContent = content.getContentAtIndex(content.length - 1);
4305
+ if (lastContent instanceof ParagraphComponent ||
4306
+ lastContent instanceof ListComponent ||
4307
+ lastContent instanceof TodolistComponent) {
4308
+ return;
4309
+ }
4310
+ content.retain(content.length);
4311
+ content.insert(new ParagraphComponent(this.textbus));
4312
+ }
4052
4313
  }
4053
4314
  RootComponent.componentName = 'RootComponent';
4054
4315
  RootComponent.type = core$1.ContentType.BlockComponent;
@@ -4063,6 +4324,9 @@ function RootView(props) {
4063
4324
  sub.unsubscribe();
4064
4325
  };
4065
4326
  });
4327
+ core.onUpdated(() => {
4328
+ props.component.afterCheck();
4329
+ });
4066
4330
  const readonly = useReadonly();
4067
4331
  const output = useOutput();
4068
4332
  return () => {
@@ -4190,7 +4454,7 @@ function ResizeColumn(props) {
4190
4454
  });
4191
4455
  }
4192
4456
 
4193
- var scopedId$4 = "vf-d64cf9";
4457
+ var scopedId$4 = "vf-39cb2c";
4194
4458
 
4195
4459
  function TopBar(props) {
4196
4460
  const editorService = core.inject(exports.EditorService);
@@ -4355,7 +4619,7 @@ function Scroll(props) {
4355
4619
  });
4356
4620
  }
4357
4621
 
4358
- var scopedId$2 = "vf-ef93c0";
4622
+ var scopedId$2 = "vf-aaece0";
4359
4623
 
4360
4624
  function LeftBar(props) {
4361
4625
  const editorService = core.inject(exports.EditorService);
@@ -4816,7 +5080,8 @@ class Editor extends core$1.Textbus {
4816
5080
  [HighlightBoxComponent.componentName]: HighlightBoxView,
4817
5081
  [ListComponent.componentName]: ListComponentView,
4818
5082
  [ImageComponent.componentName]: ImageView,
4819
- [VideoComponent.componentName]: VideoView
5083
+ [VideoComponent.componentName]: VideoView,
5084
+ [AtComponent.componentName]: AtComponentView,
4820
5085
  }, (host, root, injector) => {
4821
5086
  const appInjector = new core.ReflectiveInjector(injector, [{
4822
5087
  provide: OutputInjectionToken,
@@ -4832,6 +5097,7 @@ class Editor extends core$1.Textbus {
4832
5097
  const browserModule = new platformBrowser.BrowserModule(Object.assign({ renderTo: () => {
4833
5098
  return this.host;
4834
5099
  }, adapter, componentLoaders: [
5100
+ atComponentLoader,
4835
5101
  sourceCodeComponentLoader,
4836
5102
  tableComponentLoader,
4837
5103
  imageComponentLoader,
@@ -4871,7 +5137,8 @@ class Editor extends core$1.Textbus {
4871
5137
  [HighlightBoxComponent.componentName]: HighlightBoxView,
4872
5138
  [ListComponent.componentName]: ListComponentView,
4873
5139
  [ImageComponent.componentName]: ImageView,
4874
- [VideoComponent.componentName]: VideoView
5140
+ [VideoComponent.componentName]: VideoView,
5141
+ [AtComponent.componentName]: AtComponentView
4875
5142
  }, (host, root, injector) => {
4876
5143
  const appInjector = new core.ReflectiveInjector(injector, [{
4877
5144
  provide: OutputInjectionToken,
@@ -4900,7 +5167,8 @@ class Editor extends core$1.Textbus {
4900
5167
  TableComponent,
4901
5168
  HighlightBoxComponent,
4902
5169
  ListComponent,
4903
- VideoComponent
5170
+ VideoComponent,
5171
+ AtComponent
4904
5172
  ], formatters: [
4905
5173
  backgroundColorFormatter,
4906
5174
  boldFormatter,
@@ -4928,6 +5196,7 @@ class Editor extends core$1.Textbus {
4928
5196
  registerHeadingShortcut(textbus);
4929
5197
  registerTextAlignShortcut(textbus);
4930
5198
  registerTextIndentShortcut(textbus);
5199
+ registerAtShortcut(textbus);
4931
5200
  } }, editorConfig));
4932
5201
  this.editorConfig = editorConfig;
4933
5202
  this.translator = new platformBrowser$1.OutputTranslator();
@@ -4969,6 +5238,8 @@ class Editor extends core$1.Textbus {
4969
5238
  }
4970
5239
  }
4971
5240
 
5241
+ exports.AtComponent = AtComponent;
5242
+ exports.AtComponentView = AtComponentView;
4972
5243
  exports.AttrTool = AttrTool;
4973
5244
  exports.BlockTool = BlockTool;
4974
5245
  exports.BlockquoteComponent = BlockquoteComponent;
@@ -4997,7 +5268,9 @@ exports.LinkTool = LinkTool;
4997
5268
  exports.ListComponent = ListComponent;
4998
5269
  exports.ListComponentView = ListComponentView;
4999
5270
  exports.Matcher = Matcher;
5271
+ exports.MenuHeading = MenuHeading;
5000
5272
  exports.MenuItem = MenuItem;
5273
+ exports.Organization = Organization;
5001
5274
  exports.OutputInjectionToken = OutputInjectionToken;
5002
5275
  exports.ParagraphComponent = ParagraphComponent;
5003
5276
  exports.ParagraphView = ParagraphView;
@@ -5017,6 +5290,7 @@ exports.ToolbarPlugin = ToolbarPlugin;
5017
5290
  exports.UnderlineTool = UnderlineTool;
5018
5291
  exports.VideoComponent = VideoComponent;
5019
5292
  exports.VideoView = VideoView;
5293
+ exports.atComponentLoader = atComponentLoader;
5020
5294
  exports.autoComplete = autoComplete;
5021
5295
  exports.backgroundColorFormatLoader = backgroundColorFormatLoader;
5022
5296
  exports.backgroundColorFormatter = backgroundColorFormatter;
@@ -5044,6 +5318,7 @@ exports.linkFormatLoader = linkFormatLoader;
5044
5318
  exports.linkFormatter = linkFormatter;
5045
5319
  exports.listComponentLoader = listComponentLoader;
5046
5320
  exports.paragraphComponentLoader = paragraphComponentLoader;
5321
+ exports.registerAtShortcut = registerAtShortcut;
5047
5322
  exports.registerBoldShortcut = registerBoldShortcut;
5048
5323
  exports.registerCodeShortcut = registerCodeShortcut;
5049
5324
  exports.registerHeadingShortcut = registerHeadingShortcut;