@textbus/xnote 0.0.1-alpha.5 → 0.0.1-alpha.7

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.
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx, Fragment } from '@viewfly/core/jsx-runtime';
2
2
  import { withScopedCSS } from '@viewfly/scoped-css';
3
- import { Injectable, InjectFlags, Injector, inject, createSignal, onUnmounted, createRef, withAnnotation, onMounted, InjectionToken, viewfly, createDynamicRef, onUpdated, getCurrentInstance, watch, ReflectiveInjector } from '@viewfly/core';
3
+ import { Injectable, InjectFlags, Injector, inject, createSignal, onUnmounted, createRef, withAnnotation, onMounted, InjectionToken, viewfly, createDynamicRef, getCurrentInstance, onUpdated, watch, ReflectiveInjector } from '@viewfly/core';
4
4
  import { Subject, Selection, fromEvent, Subscription, Attribute, Keyboard, Commander, Controller, ContentType, Component, Registry, Slot, useContext, onBreak, createVNode, BehaviorSubject, onPaste, onFocus, onBlur, useDynamicShortcut, VTextNode, Query, QueryStateType, onContentInsert, onFocusIn, onFocusOut, onGetRanges, Formatter, onParentSlotUpdated, Textbus, RootComponentRef, filter, map, distinctUntilChanged, sampleTime, merge, debounceTime, throttleTime, delay, onCompositionStart } from '@textbus/core';
5
5
  import { VIEW_CONTAINER, DomAdapter, Input, SelectionBridge, VIEW_DOCUMENT, BrowserModule, Parser } from '@textbus/platform-browser';
6
6
  import { createPortal, DomRenderer, createApp, HTMLRenderer, OutputTranslator } from '@viewfly/platform-browser';
@@ -9,7 +9,7 @@ import highlightjs from 'highlight.js';
9
9
  import { ViewflyAdapter, ViewflyVDomAdapter } from '@textbus/adapter-viewfly';
10
10
  import { CollaborateModule } from '@textbus/collaborate';
11
11
 
12
- var css$j = undefined;
12
+ var scopedId$k = "vf-69b4db";
13
13
 
14
14
  /******************************************************************************
15
15
  Copyright (c) Microsoft Corporation.
@@ -39,16 +39,6 @@ function __metadata(metadataKey, metadataValue) {
39
39
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
40
40
  }
41
41
 
42
- function __awaiter(thisArg, _arguments, P, generator) {
43
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
44
- return new (P || (P = Promise))(function (resolve, reject) {
45
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
46
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
47
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
48
- step((generator = generator.apply(thisArg, _arguments || [])).next());
49
- });
50
- }
51
-
52
42
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
53
43
  var e = new Error(message);
54
44
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -140,7 +130,7 @@ function Button(props) {
140
130
  subscription.unsubscribe();
141
131
  });
142
132
  }
143
- return withScopedCSS(css$j, () => {
133
+ return withScopedCSS(scopedId$k, () => {
144
134
  return (jsxs("button", Object.assign({ type: "button" }, props, { class: [
145
135
  'btn',
146
136
  {
@@ -152,10 +142,10 @@ function Button(props) {
152
142
  });
153
143
  }
154
144
 
155
- var css$i = undefined;
145
+ var scopedId$j = "vf-ac7e8d";
156
146
 
157
147
  function ComponentToolbar(props) {
158
- return withScopedCSS(css$i, () => {
148
+ return withScopedCSS(scopedId$j, () => {
159
149
  return (jsx("div", { class: "component-toolbar", style: props.style, children: jsx("div", { class: [
160
150
  'toolbar',
161
151
  {
@@ -165,15 +155,15 @@ function ComponentToolbar(props) {
165
155
  });
166
156
  }
167
157
 
168
- var css$h = undefined;
158
+ var scopedId$i = "vf-ede279";
169
159
 
170
160
  function Divider() {
171
- return withScopedCSS(css$h, () => {
161
+ return withScopedCSS(scopedId$i, () => {
172
162
  return jsx("div", { class: "divider" });
173
163
  });
174
164
  }
175
165
 
176
- var style = undefined;
166
+ var scopedId$h = "vf-4c1803";
177
167
 
178
168
  function DragResize(props) {
179
169
  const isShow = createSignal(false);
@@ -281,16 +271,16 @@ function DragResize(props) {
281
271
  unUp.unsubscribe();
282
272
  });
283
273
  }
284
- return withScopedCSS(style, () => {
274
+ return withScopedCSS(scopedId$h, () => {
285
275
  return (jsxs("div", { class: "drag-resize", onClick: selectComponent, children: [jsx("div", { class: "container", ref: ref, children: props.children }), jsxs("div", { class: ['resize-tool', {
286
276
  active: isShow()
287
277
  }], children: [jsxs("div", { class: "mask", ref: mask, children: [component.state.width, "*", component.state.height] }), jsxs("div", { class: "btn-group", ref: btnGroup, onMousedown: drag, children: [jsx("button", { type: "button" }), jsx("button", { type: "button" }), jsx("button", { type: "button" }), jsx("button", { type: "button" }), jsx("button", { type: "button" }), jsx("button", { type: "button" }), jsx("button", { type: "button" }), jsx("button", { type: "button" })] })] })] }));
288
278
  });
289
279
  }
290
280
 
291
- var css$g = undefined;
281
+ var scopedId$g = "vf-a99c5e";
292
282
 
293
- var css$f = undefined;
283
+ var scopedId$f = "vf-41a617";
294
284
 
295
285
  const DropdownMenuPortal = withAnnotation({
296
286
  providers: [
@@ -373,7 +363,7 @@ const DropdownMenuPortal = withAnnotation({
373
363
  dropdownContextService.canHide = true;
374
364
  dropdownContextService.hide();
375
365
  }
376
- return createPortal(withScopedCSS(css$f, () => {
366
+ return createPortal(withScopedCSS(scopedId$f, () => {
377
367
  return (jsx("div", { onMouseenter: onEnter, onMouseleave: onLeave, ref: menuRef, style: {
378
368
  width: props.width
379
369
  }, class: "dropdown-menu", children: jsx("div", { class: "dropdown-menu-content", children: props.children }) }));
@@ -436,7 +426,7 @@ const Dropdown = withAnnotation({
436
426
  dropdownContextService.open();
437
427
  }
438
428
  },
439
- $render: withScopedCSS(css$g, () => {
429
+ $render: withScopedCSS(scopedId$g, () => {
440
430
  return (jsxs("div", { class: ['dropdown', props.class], style: props.style, ref: dropdownRef, children: [jsxs("div", { class: "dropdown-btn", ref: triggerRef, children: [jsx("div", { class: "dropdown-btn-inner", children: props.children }), jsx("div", { class: "dropdown-btn-arrow" })] }), isShow() && jsx(DropdownMenuPortal, { width: props.width, abreast: props.abreast, triggerRef: triggerRef, children: Array.isArray(props.menu) ?
441
431
  props.menu.map(menu => {
442
432
  return (jsx("div", { class: "dropdown-menu-item", onClick: () => {
@@ -452,7 +442,7 @@ const Dropdown = withAnnotation({
452
442
  };
453
443
  });
454
444
 
455
- var css$e = undefined;
445
+ var scopedId$e = "vf-64f71d";
456
446
 
457
447
  function MenuItem(props) {
458
448
  const dropdownContextService = inject(DropdownContextService, InjectFlags.Optional, null);
@@ -472,7 +462,7 @@ function MenuItem(props) {
472
462
  }
473
463
  (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, props.value);
474
464
  }
475
- return withScopedCSS(css$e, () => {
465
+ return withScopedCSS(scopedId$e, () => {
476
466
  return (jsxs("div", { class: ['menu-item', { disabled: props.disabled, active: props.arrow && isActive() }], onClick: click, children: [jsxs("div", { children: [props.icon && jsx("span", { class: "menu-icon", children: props.icon }), props.children] }), props.arrow ?
477
467
  jsx("div", { class: "arrow", children: jsx("span", { class: "xnote-icon-arrow-right" }) }) :
478
468
  jsx("div", { class: [
@@ -482,11 +472,11 @@ function MenuItem(props) {
482
472
  });
483
473
  }
484
474
 
485
- var css$d = undefined;
475
+ var scopedId$d = "vf-a23c47";
486
476
 
487
477
  function Popup(props) {
488
478
  const host = inject(VIEW_CONTAINER);
489
- return createPortal(withScopedCSS(css$d, () => {
479
+ return createPortal(withScopedCSS(scopedId$d, () => {
490
480
  return (jsx("div", { class: "popup", style: {
491
481
  left: props.left + 'px',
492
482
  top: props.top + 'px'
@@ -494,15 +484,15 @@ function Popup(props) {
494
484
  }), host);
495
485
  }
496
486
 
497
- var css$c = undefined;
487
+ var scopedId$c = "vf-216815";
498
488
 
499
489
  function ToolbarItem(props) {
500
- return withScopedCSS(css$c, () => {
490
+ return withScopedCSS(scopedId$c, () => {
501
491
  return (jsx("div", { class: "toolbar-item", children: props.children }));
502
492
  });
503
493
  }
504
494
 
505
- var css$b = undefined;
495
+ var scopedId$b = "vf-2a8a65";
506
496
 
507
497
  let RefreshService = class RefreshService {
508
498
  constructor() {
@@ -558,6 +548,12 @@ function useReadonly() {
558
548
  return is;
559
549
  }
560
550
 
551
+ const OutputInjectionToken = new InjectionToken('OutputInjectionToken');
552
+
553
+ function useOutput() {
554
+ return createSignal(inject(OutputInjectionToken));
555
+ }
556
+
561
557
  class ParagraphComponent extends Component {
562
558
  static fromJSON(textbus, json) {
563
559
  const slot = textbus.get(Registry).createSlot(json.slot);
@@ -593,11 +589,12 @@ ParagraphComponent.type = ContentType.BlockComponent;
593
589
  function ParagraphView(props) {
594
590
  const adapter = inject(DomAdapter);
595
591
  const readonly = useReadonly();
592
+ const output = useOutput();
596
593
  return () => {
597
594
  const slot = props.component.state.slot;
598
595
  return (jsx("div", { class: "xnote-paragraph", ref: props.rootRef, "data-component": ParagraphComponent.name, children: adapter.slotRender(slot, children => {
599
596
  return (createVNode('p', null, children));
600
- }, readonly()) }));
597
+ }, readonly() || output()) }));
601
598
  };
602
599
  }
603
600
  const paragraphComponentLoader = {
@@ -605,11 +602,12 @@ const paragraphComponentLoader = {
605
602
  return element.dataset.compoment === ParagraphComponent.name || /P|H[1-6]/.test(element.tagName);
606
603
  },
607
604
  read(element, textbus, slotParser) {
605
+ const content = /P|H[1-6]/.test(element.tagName) ? element : element.children[0];
608
606
  const delta = slotParser(new Slot([
609
607
  ContentType.Text,
610
608
  ContentType.InlineComponent,
611
609
  ContentType.BlockComponent
612
- ]), /P|H[1-6]/.test(element.tagName) ? element : element.children[0]).toDelta();
610
+ ]), content).toDelta();
613
611
  const results = deltaToBlock(delta, textbus);
614
612
  if (results.length === 1) {
615
613
  return results[0];
@@ -650,12 +648,6 @@ function deltaToBlock(delta, textbus) {
650
648
  return results;
651
649
  }
652
650
 
653
- const OutputInjectionToken = new InjectionToken('OutputInjectionToken');
654
-
655
- function useOutput() {
656
- return createSignal(inject(OutputInjectionToken));
657
- }
658
-
659
651
  const languageList = [{
660
652
  label: 'JavaScript',
661
653
  value: 'JavaScript',
@@ -1089,7 +1081,7 @@ function SourceCodeView(props) {
1089
1081
  'xnote-source-code': true,
1090
1082
  'xnote-source-code-line-number': state.lineNumber,
1091
1083
  [state.theme || 'github']: true
1092
- }, "data-lang": state.lang, "data-component": props.component.name, "data-auto-break": state.autoBreak, "data-theme": state.theme || null, "data-line-number": state.lineNumber, children: [(!readonly() && !output()) && jsxs(ComponentToolbar, { visible: isFocus(), children: [jsx(ToolbarItem, { children: jsx(Dropdown, { onCheck: changeLang, trigger: 'hover', menu: languageList.map(item => {
1084
+ }, "data-lang": state.lang, "data-component": props.component.name, "data-auto-break": state.autoBreak + '', "data-theme": state.theme || null, "data-line-number": state.lineNumber + '', children: [(!readonly() && !output()) && jsxs(ComponentToolbar, { visible: isFocus(), children: [jsx(ToolbarItem, { children: jsx(Dropdown, { onCheck: changeLang, trigger: 'hover', menu: languageList.map(item => {
1093
1085
  return {
1094
1086
  label: jsx(MenuItem, { checked: state.lang === item.value, children: item.label || 'Plain Text' }),
1095
1087
  value: item.value
@@ -1147,7 +1139,7 @@ function SourceCodeView(props) {
1147
1139
  }
1148
1140
  const sourceCodeComponentLoader = {
1149
1141
  match(element) {
1150
- return element.tagName === 'DIV' && element.dataset.component === SourceCodeComponent.componentName ||
1142
+ return (element.tagName === 'DIV' && element.dataset.component === SourceCodeComponent.componentName) ||
1151
1143
  element.tagName === 'PRE';
1152
1144
  },
1153
1145
  read(el, textbus) {
@@ -1176,8 +1168,8 @@ const sourceCodeComponentLoader = {
1176
1168
  return new SourceCodeComponent(textbus, {
1177
1169
  lang: el.dataset.lang || '',
1178
1170
  theme: el.dataset.theme || '',
1179
- lineNumber: !!el.dataset.lineNumber || true,
1180
- autoBreak: !!el.dataset.autoBreak || true,
1171
+ lineNumber: el.dataset.lineNumber === 'true',
1172
+ autoBreak: el.dataset.autoBreak === 'true',
1181
1173
  slots
1182
1174
  });
1183
1175
  },
@@ -1331,7 +1323,7 @@ function AttrTool(props) {
1331
1323
  break;
1332
1324
  }
1333
1325
  }
1334
- return withScopedCSS(css$b, () => {
1326
+ return withScopedCSS(scopedId$b, () => {
1335
1327
  const states = checkStates();
1336
1328
  return (jsx(Dropdown, { style: props.style, abreast: props.abreast, onCheck: updateAttr, trigger: 'hover', menu: [
1337
1329
  {
@@ -1367,12 +1359,18 @@ const headingAttr = new Attribute('Heading', {
1367
1359
  });
1368
1360
  const headingAttrLoader = {
1369
1361
  match(element) {
1370
- return /H[1-6]/.test(element.tagName);
1362
+ return /H[1-6]/.test(element.tagName) || /(^|\s)xnote-h[1-6](\s|$)/.test(element.className);
1371
1363
  },
1372
1364
  read(element) {
1365
+ if (/H[1-6]/.test(element.tagName)) {
1366
+ return {
1367
+ attribute: headingAttr,
1368
+ value: element.tagName.toLowerCase()
1369
+ };
1370
+ }
1373
1371
  return {
1374
1372
  attribute: headingAttr,
1375
- value: element.tagName.toLowerCase()
1373
+ value: element.className.substring(6)
1376
1374
  };
1377
1375
  }
1378
1376
  };
@@ -1635,7 +1633,7 @@ function registerStrikeThroughShortcut(textbus) {
1635
1633
  }
1636
1634
  const strikeThroughFormatLoader = {
1637
1635
  match(element) {
1638
- return /strike|del|s/i.test(element.tagName) || /line-through/.test(element.style.textDecoration);
1636
+ return /^(strike|del|s)$/i.test(element.tagName) || /line-through/.test(element.style.textDecoration);
1639
1637
  },
1640
1638
  read() {
1641
1639
  return {
@@ -1753,7 +1751,7 @@ function TodolistView(props) {
1753
1751
  return createVNode('div', {
1754
1752
  class: 'xnote-todolist-content'
1755
1753
  }, children);
1756
- }, readonly())] }));
1754
+ }, readonly() || output())] }));
1757
1755
  };
1758
1756
  }
1759
1757
  const todolistComponentLoader = {
@@ -1810,11 +1808,12 @@ BlockquoteComponent.zenCoding = {
1810
1808
  function BlockquoteView(props) {
1811
1809
  const adapter = inject(DomAdapter);
1812
1810
  const readonly = useReadonly();
1811
+ const output = useOutput();
1813
1812
  return () => {
1814
1813
  const slot = props.component.state.slot;
1815
1814
  return (jsx("blockquote", { class: "xnote-blockquote", ref: props.rootRef, "data-component": props.component.name, children: adapter.slotRender(slot, children => {
1816
1815
  return createVNode('div', null, children);
1817
- }, readonly()) }));
1816
+ }, readonly() || output()) }));
1818
1817
  };
1819
1818
  }
1820
1819
  const blockquoteComponentLoader = {
@@ -1921,6 +1920,25 @@ class ListComponent extends Component {
1921
1920
  selection.setPosition(slot, 0);
1922
1921
  }
1923
1922
  });
1923
+ useDynamicShortcut({
1924
+ keymap: {
1925
+ key: 'Tab'
1926
+ },
1927
+ action: () => {
1928
+ updateAfterList(this);
1929
+ return false;
1930
+ }
1931
+ });
1932
+ useDynamicShortcut({
1933
+ keymap: {
1934
+ key: 'Tab',
1935
+ shiftKey: true
1936
+ },
1937
+ action: () => {
1938
+ Promise.resolve().then(() => updateAfterList(this));
1939
+ return false;
1940
+ }
1941
+ });
1924
1942
  }
1925
1943
  }
1926
1944
  ListComponent.componentName = 'ListComponent';
@@ -2035,7 +2053,7 @@ function ListComponentView(props) {
2035
2053
  return createVNode('div', {
2036
2054
  class: 'xnote-list-content'
2037
2055
  }, children);
2038
- }, readonly())] }) }));
2056
+ }, readonly() || output())] }) }));
2039
2057
  };
2040
2058
  }
2041
2059
  const listComponentLoader = {
@@ -2175,7 +2193,7 @@ function HighlightBoxView(props) {
2175
2193
  return createVNode('div', {
2176
2194
  class: 'xnote-highlight-box-content'
2177
2195
  }, children);
2178
- }, readonly())] }));
2196
+ }, readonly() || output())] }));
2179
2197
  }
2180
2198
  return (jsxs("div", { "data-component": name, ref: props.rootRef, "data-icon": state.type, class: "xnote-highlight-box", children: [jsx("div", { class: "xnote-highlight-box-left", children: jsx(Dropdown, { trigger: "click", ref: dropdownRef, width: "260px", menu: jsxs("div", { class: "xnote-highlight-box-icons", children: [HighlightBoxComponent.defaultTypes.map(icon => {
2181
2199
  return (jsx("button", { onClick: () => setType(icon), type: "button", children: icon }));
@@ -2186,7 +2204,7 @@ function HighlightBoxView(props) {
2186
2204
  return createVNode('div', {
2187
2205
  class: 'xnote-highlight-box-content'
2188
2206
  }, children);
2189
- }, readonly())] }));
2207
+ }, readonly() || output())] }));
2190
2208
  };
2191
2209
  }
2192
2210
  const highlightBoxComponentLoader = {
@@ -2234,17 +2252,16 @@ function useBlockTransform() {
2234
2252
  commander.unApplyAttribute(headingAttr);
2235
2253
  commander.transform({
2236
2254
  targetType: ParagraphComponent.type,
2237
- multipleSlot: false,
2238
2255
  slotFactory() {
2239
2256
  return new Slot([
2240
2257
  ContentType.InlineComponent,
2241
2258
  ContentType.Text
2242
2259
  ]);
2243
2260
  },
2244
- stateFactory(slot) {
2245
- return new ParagraphComponent(textbus, {
2261
+ stateFactory(slots) {
2262
+ return slots.map(slot => new ParagraphComponent(textbus, {
2246
2263
  slot
2247
- });
2264
+ }));
2248
2265
  }
2249
2266
  });
2250
2267
  break;
@@ -2263,17 +2280,18 @@ function useBlockTransform() {
2263
2280
  commander.unApplyAttribute(headingAttr);
2264
2281
  commander.transform({
2265
2282
  targetType: TodolistComponent.type,
2266
- multipleSlot: false,
2267
2283
  slotFactory() {
2268
2284
  return new Slot([
2269
2285
  ContentType.InlineComponent,
2270
2286
  ContentType.Text
2271
2287
  ]);
2272
2288
  },
2273
- stateFactory(slot) {
2274
- return new TodolistComponent(textbus, {
2275
- checked: false,
2276
- slot
2289
+ stateFactory(slots) {
2290
+ return slots.map(slot => {
2291
+ return new TodolistComponent(textbus, {
2292
+ checked: false,
2293
+ slot
2294
+ });
2277
2295
  });
2278
2296
  }
2279
2297
  });
@@ -2283,18 +2301,19 @@ function useBlockTransform() {
2283
2301
  {
2284
2302
  commander.transform({
2285
2303
  targetType: ListComponent.type,
2286
- multipleSlot: false,
2287
2304
  slotFactory() {
2288
2305
  return new Slot([
2289
2306
  ContentType.InlineComponent,
2290
2307
  ContentType.Text
2291
2308
  ]);
2292
2309
  },
2293
- stateFactory(slot) {
2294
- return new ListComponent(textbus, {
2295
- type: value === 'ol' ? 'OrderedList' : 'UnorderedList',
2296
- reorder: true,
2297
- slot
2310
+ stateFactory(slots) {
2311
+ return slots.map((slot, index) => {
2312
+ return new ListComponent(textbus, {
2313
+ type: value === 'ol' ? 'OrderedList' : 'UnorderedList',
2314
+ reorder: index === 0,
2315
+ slot
2316
+ });
2298
2317
  });
2299
2318
  }
2300
2319
  });
@@ -2342,16 +2361,17 @@ function useBlockTransform() {
2342
2361
  if (state.state === QueryStateType.Enabled) {
2343
2362
  commander.transform({
2344
2363
  targetType: ParagraphComponent.type,
2345
- multipleSlot: false,
2346
2364
  slotFactory() {
2347
2365
  return new Slot([
2348
2366
  ContentType.InlineComponent,
2349
2367
  ContentType.Text
2350
2368
  ]);
2351
2369
  },
2352
- stateFactory(slot) {
2353
- return new ParagraphComponent(textbus, {
2354
- slot
2370
+ stateFactory(slots) {
2371
+ return slots.map(slot => {
2372
+ return new ParagraphComponent(textbus, {
2373
+ slot
2374
+ });
2355
2375
  });
2356
2376
  }
2357
2377
  });
@@ -2359,24 +2379,23 @@ function useBlockTransform() {
2359
2379
  else {
2360
2380
  commander.transform({
2361
2381
  targetType: SourceCodeComponent.type,
2362
- multipleSlot: true,
2363
2382
  slotFactory() {
2364
2383
  return new Slot([
2365
2384
  ContentType.Text
2366
2385
  ]);
2367
2386
  },
2368
2387
  stateFactory(slots) {
2369
- return new SourceCodeComponent(textbus, {
2370
- lang: '',
2371
- lineNumber: true,
2372
- autoBreak: true,
2373
- slots: slots.map(slot => {
2374
- return {
2375
- slot,
2376
- emphasize: false
2377
- };
2378
- })
2379
- });
2388
+ return [new SourceCodeComponent(textbus, {
2389
+ lang: '',
2390
+ lineNumber: true,
2391
+ autoBreak: true,
2392
+ slots: slots.map(slot => {
2393
+ return {
2394
+ slot,
2395
+ emphasize: false
2396
+ };
2397
+ })
2398
+ })];
2380
2399
  }
2381
2400
  });
2382
2401
  }
@@ -2425,7 +2444,7 @@ function useBlockTransform() {
2425
2444
  function BlockTool() {
2426
2445
  const checkStates = useActiveBlock();
2427
2446
  const transform = useBlockTransform();
2428
- return withScopedCSS(css$b, () => {
2447
+ return withScopedCSS(scopedId$b, () => {
2429
2448
  const states = checkStates();
2430
2449
  const types = [
2431
2450
  [states.paragraph, 'xnote-icon-pilcrow'],
@@ -2856,7 +2875,7 @@ function CodeTool() {
2856
2875
  };
2857
2876
  }
2858
2877
 
2859
- var css$a = undefined;
2878
+ var scopedId$a = "vf-1fbbdf";
2860
2879
 
2861
2880
  function ColorTool(props) {
2862
2881
  const query = inject(Query);
@@ -2891,6 +2910,7 @@ function ColorTool(props) {
2891
2910
  '#ffdf14',
2892
2911
  '#5eec75',
2893
2912
  '#5dfaff',
2913
+ '#1296db',
2894
2914
  '#617fff',
2895
2915
  '#c459ff',
2896
2916
  ];
@@ -2904,7 +2924,7 @@ function ColorTool(props) {
2904
2924
  '#90a0e5',
2905
2925
  '#c596e0',
2906
2926
  ];
2907
- return withScopedCSS(css$a, () => {
2927
+ return withScopedCSS(scopedId$a, () => {
2908
2928
  const vm = viewModel();
2909
2929
  return (jsx(Dropdown, { style: props.style, abreast: props.abreast, trigger: 'hover', menu: jsxs("div", { children: [jsx("div", { class: "color-type", children: "\u6587\u5B57\u989C\u8272" }), jsxs("div", { class: "text-colors", children: [jsx("div", { class: {
2910
2930
  active: textColor() === ''
@@ -3112,7 +3132,7 @@ function ItalicTool() {
3112
3132
  };
3113
3133
  }
3114
3134
 
3115
- var css$9 = undefined;
3135
+ var scopedId$9 = "vf-269a0b";
3116
3136
 
3117
3137
  function LinkTool(props) {
3118
3138
  const selectionBridge = inject(SelectionBridge);
@@ -3143,7 +3163,7 @@ function LinkTool(props) {
3143
3163
  onUnmounted(() => {
3144
3164
  sub.unsubscribe();
3145
3165
  });
3146
- return withScopedCSS(css$9, () => {
3166
+ return withScopedCSS(scopedId$9, () => {
3147
3167
  const containerRect = container.getBoundingClientRect();
3148
3168
  const rect = isShow() ? selectionBridge.getRect({
3149
3169
  slot: selection.focusSlot,
@@ -3212,12 +3232,93 @@ function UnderlineTool() {
3212
3232
  };
3213
3233
  }
3214
3234
 
3215
- var css$8 = undefined;
3235
+ var scopedId$8 = "vf-cf8e1c";
3236
+
3237
+ class FileUploader {
3238
+ }
3239
+
3240
+ class ImageComponent extends Component {
3241
+ static fromJSON(textbus, json) {
3242
+ return new ImageComponent(textbus, Object.assign({}, json));
3243
+ }
3244
+ }
3245
+ ImageComponent.type = ContentType.InlineComponent;
3246
+ ImageComponent.componentName = 'ImageComponent';
3247
+ function ImageView(props) {
3248
+ const { name, state } = props.component;
3249
+ const imageRef = createRef();
3250
+ const readonly = useReadonly();
3251
+ const output = useOutput();
3252
+ return () => {
3253
+ if (readonly() || output()) {
3254
+ return (jsx("div", { class: "xnote-image", ref: props.rootRef, "data-component": name, children: jsx("img", { alt: "", src: state.src, style: {
3255
+ width: state.width,
3256
+ height: state.height
3257
+ } }) }));
3258
+ }
3259
+ return (jsx("div", { class: "xnote-image", ref: props.rootRef, "data-component": name, children: jsx(DragResize, { source: imageRef, component: props.component, children: jsx("img", { alt: "", ref: imageRef, src: state.src, style: {
3260
+ width: state.width,
3261
+ height: state.height
3262
+ } }) }) }));
3263
+ };
3264
+ }
3265
+ const imageComponentLoader = {
3266
+ match(element) {
3267
+ return element.tagName === 'IMG' || element.dataset.component === ImageComponent.componentName;
3268
+ },
3269
+ read(element, textbus) {
3270
+ var _a;
3271
+ return new ImageComponent(textbus, {
3272
+ src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('img')) === null || _a === void 0 ? void 0 : _a.src) || ''
3273
+ });
3274
+ }
3275
+ };
3276
+
3277
+ class VideoComponent extends Component {
3278
+ static fromJSON(textbus, json) {
3279
+ return new VideoComponent(textbus, Object.assign({}, json));
3280
+ }
3281
+ setup() {
3282
+ //
3283
+ }
3284
+ }
3285
+ VideoComponent.type = ContentType.InlineComponent;
3286
+ VideoComponent.componentName = 'VideoComponent';
3287
+ function VideoView(props) {
3288
+ const { name, state } = props.component;
3289
+ const videoRef = createRef();
3290
+ const readonly = useReadonly();
3291
+ const output = useOutput();
3292
+ return () => {
3293
+ if (readonly() || output()) {
3294
+ return (jsx("div", { class: "xnote-video", "data-component": name, children: jsx("video", { ref: videoRef, src: state.src, style: {
3295
+ width: state.width,
3296
+ height: state.height
3297
+ } }) }));
3298
+ }
3299
+ return (jsx("div", { ref: props.rootRef, class: "xnote-video", "data-component": name, children: jsx(DragResize, { source: videoRef, component: props.component, children: jsx("video", { ref: videoRef, src: state.src, style: {
3300
+ width: state.width,
3301
+ height: state.height
3302
+ } }) }) }));
3303
+ };
3304
+ }
3305
+ const videoComponentLoader = {
3306
+ match(element) {
3307
+ return element.tagName === 'IMG' || element.dataset.component === VideoComponent.componentName;
3308
+ },
3309
+ read(element, textbus) {
3310
+ var _a;
3311
+ return new VideoComponent(textbus, {
3312
+ src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('video')) === null || _a === void 0 ? void 0 : _a.src) || ''
3313
+ });
3314
+ }
3315
+ };
3216
3316
 
3217
3317
  function InsertTool(props) {
3218
3318
  const commander = inject(Commander);
3219
3319
  const selection = inject(Selection);
3220
3320
  const textbus = inject(Textbus);
3321
+ const fileUploader = inject(FileUploader, InjectFlags.Optional, null);
3221
3322
  function insert(type) {
3222
3323
  var _a;
3223
3324
  const component = (_a = props.slot) === null || _a === void 0 ? void 0 : _a.parent;
@@ -3310,8 +3411,24 @@ function InsertTool(props) {
3310
3411
  }
3311
3412
  break;
3312
3413
  case 'image':
3414
+ if (fileUploader) {
3415
+ Promise.resolve(fileUploader.uploadFile('image')).then(url => {
3416
+ const img = new ImageComponent(textbus, {
3417
+ src: url
3418
+ });
3419
+ commander.insert(img);
3420
+ });
3421
+ }
3313
3422
  break;
3314
3423
  case 'video':
3424
+ if (fileUploader) {
3425
+ Promise.resolve(fileUploader.uploadFile('video')).then(url => {
3426
+ const img = new VideoComponent(textbus, {
3427
+ src: url
3428
+ });
3429
+ commander.insert(img);
3430
+ });
3431
+ }
3315
3432
  break;
3316
3433
  case 'highlightBox':
3317
3434
  {
@@ -3324,12 +3441,12 @@ function InsertTool(props) {
3324
3441
  break;
3325
3442
  }
3326
3443
  }
3327
- return withScopedCSS(css$8, () => {
3444
+ return withScopedCSS(scopedId$8, () => {
3328
3445
  return jsxs(Fragment, { children: [jsxs("div", { class: "btn-group", children: [jsx(Button, { ordinary: true, onClick: () => insert('paragraph'), children: jsx("span", { class: "xnote-icon-pilcrow" }) }), jsx(Button, { ordinary: true, onClick: () => insert('h1'), children: jsx("span", { class: "xnote-icon-heading-h1" }) }), jsx(Button, { ordinary: true, onClick: () => insert('h2'), children: jsx("span", { class: "xnote-icon-heading-h2" }) }), jsx(Button, { ordinary: true, onClick: () => insert('h3'), children: jsx("span", { class: "xnote-icon-heading-h3" }) }), jsx(Button, { ordinary: true, onClick: () => insert('h4'), children: jsx("span", { class: "xnote-icon-heading-h4" }) }), jsx(Button, { ordinary: true, onClick: () => insert('h5'), children: jsx("span", { class: "xnote-icon-heading-h5" }) }), jsx(Button, { ordinary: true, onClick: () => insert('h6'), children: jsx("span", { class: "xnote-icon-heading-h6" }) }), jsx(Button, { ordinary: true, onClick: () => insert('ol'), children: jsx("span", { class: "xnote-icon-list-numbered" }) }), jsx(Button, { ordinary: true, onClick: () => insert('ul'), children: jsx("span", { class: "xnote-icon-list" }) }), jsx(Button, { ordinary: true, onClick: () => insert('sourceCode'), children: jsx("span", { class: "xnote-icon-source-code" }) })] }), jsx(Divider, {}), jsx(MenuItem, { onClick: () => insert('table'), icon: jsx("span", { class: "xnote-icon-table" }), children: "\u8868\u683C" }), jsx(MenuItem, { onClick: () => insert('todolist'), icon: jsx("span", { class: "xnote-icon-checkbox-checked" }), children: "\u5F85\u529E\u5217\u8868" }), jsx(MenuItem, { onClick: () => insert('image'), icon: jsx("span", { class: "xnote-icon-image" }), children: "\u56FE\u7247" }), jsx(MenuItem, { onClick: () => insert('video'), icon: jsx("span", { class: "xnote-icon-video" }), children: "\u89C6\u9891" }), jsx(MenuItem, { onClick: () => insert('highlightBox'), icon: jsx("span", { class: "xnote-icon-warning" }), children: "\u9AD8\u4EAE\u5757" })] });
3329
3446
  });
3330
3447
  }
3331
3448
 
3332
- var css$7 = undefined;
3449
+ var scopedId$7 = "vf-b05292";
3333
3450
 
3334
3451
  const LeftToolbar = withAnnotation({
3335
3452
  providers: [RefreshService]
@@ -3492,7 +3609,7 @@ const LeftToolbar = withAnnotation({
3492
3609
  function changeIgnoreMove(b) {
3493
3610
  isIgnoreMove = b;
3494
3611
  }
3495
- return withScopedCSS(css$7, () => {
3612
+ return withScopedCSS(scopedId$7, () => {
3496
3613
  const position = positionSignal();
3497
3614
  const slot = activeSlot();
3498
3615
  let activeNode = jsx("span", { class: "xnote-icon-pilcrow" });
@@ -3566,7 +3683,7 @@ class LeftToolbarPlugin {
3566
3683
  }
3567
3684
  }
3568
3685
 
3569
- var css$6 = undefined;
3686
+ var scopedId$6 = "vf-fee98b";
3570
3687
 
3571
3688
  let EditorService = class EditorService {
3572
3689
  constructor() {
@@ -3676,7 +3793,7 @@ const Toolbar = withAnnotation({
3676
3793
  mousedownSubscription.unsubscribe();
3677
3794
  mouseupSubscription.unsubscribe();
3678
3795
  });
3679
- return withScopedCSS(css$6, () => {
3796
+ return withScopedCSS(scopedId$6, () => {
3680
3797
  const p = viewPosition();
3681
3798
  return (jsxs("div", { class: "toolbar", ref: toolbarRef, style: {
3682
3799
  left: p.left + 'px',
@@ -3811,72 +3928,35 @@ class Matcher {
3811
3928
  }
3812
3929
  }
3813
3930
 
3814
- class ImageComponent extends Component {
3815
- static fromJSON(textbus, json) {
3816
- return new ImageComponent(textbus, Object.assign({}, json));
3817
- }
3818
- }
3819
- ImageComponent.type = ContentType.InlineComponent;
3820
- ImageComponent.componentName = 'ImageComponent';
3821
- function ImageView(props) {
3822
- const { name, state } = props.component;
3823
- const imageRef = createRef();
3824
- const readonly = useReadonly();
3825
- const output = useOutput();
3826
- return () => {
3827
- if (readonly() || output()) {
3828
- return (jsx("div", { class: "xnote-image", ref: props.rootRef, "data-component": name, children: jsx("img", { alt: "", src: state.src, style: {
3829
- width: state.width,
3830
- height: state.height
3831
- } }) }));
3832
- }
3833
- return (jsx("div", { class: "xnote-image", ref: props.rootRef, "data-component": name, children: jsx(DragResize, { source: imageRef, component: props.component, children: jsx("img", { alt: "", ref: imageRef, src: state.src, style: {
3834
- width: state.width,
3835
- height: state.height
3836
- } }) }) }));
3837
- };
3838
- }
3839
- const imageComponentLoader = {
3840
- match(element) {
3841
- return element.tagName === 'IMG' || element.dataset.component === ImageComponent.componentName;
3842
- },
3843
- read(element, textbus) {
3844
- var _a;
3845
- return new ImageComponent(textbus, {
3846
- src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('img')) === null || _a === void 0 ? void 0 : _a.src) || ''
3847
- });
3848
- }
3849
- };
3850
-
3851
3931
  class RootComponent extends Component {
3852
3932
  constructor() {
3853
3933
  super(...arguments);
3854
3934
  this.onCompositionStart = new Subject();
3855
3935
  }
3856
3936
  static fromJSON(textbus, json) {
3857
- const heading = textbus.get(Registry).createSlot(json.heading);
3937
+ // const heading = textbus.get(Registry).createSlot(json.heading)
3858
3938
  const content = textbus.get(Registry).createSlot(json.content);
3859
3939
  return new RootComponent(textbus, {
3860
- heading,
3940
+ // heading,
3861
3941
  content
3862
3942
  });
3863
3943
  }
3864
3944
  setup() {
3865
- const textbus = useContext();
3866
- const selection = textbus.get(Selection);
3867
- onBreak(ev => {
3868
- if (ev.target === this.state.heading) {
3869
- const afterContent = ev.target.cut(ev.data.index);
3870
- const p = new ParagraphComponent(textbus, {
3871
- slot: afterContent
3872
- });
3873
- const body = this.state.content;
3874
- body.retain(0);
3875
- body.insert(p);
3876
- selection.setPosition(afterContent, 0);
3877
- ev.preventDefault();
3878
- }
3879
- });
3945
+ // const textbus = useContext()
3946
+ // const selection = textbus.get(Selection)
3947
+ // onBreak(ev => {
3948
+ // if (ev.target === this.state.heading) {
3949
+ // const afterContent = ev.target.cut(ev.data.index)
3950
+ // const p = new ParagraphComponent(textbus, {
3951
+ // slot: afterContent
3952
+ // })
3953
+ // const body = this.state.content
3954
+ // body.retain(0)
3955
+ // body.insert(p)
3956
+ // selection.setPosition(afterContent, 0)
3957
+ // ev.preventDefault()
3958
+ // }
3959
+ // })
3880
3960
  useBlockContent(this.state.content);
3881
3961
  onCompositionStart(ev => {
3882
3962
  this.onCompositionStart.next(ev);
@@ -3898,37 +3978,28 @@ RootComponent.componentName = 'RootComponent';
3898
3978
  RootComponent.type = ContentType.BlockComponent;
3899
3979
  function RootView(props) {
3900
3980
  const adapter = inject(DomAdapter);
3901
- const { heading, content } = props.component.state;
3981
+ const { content } = props.component.state;
3902
3982
  const ref = createDynamicRef(node => {
3903
- const sub = props.component.onCompositionStart.subscribe(ev => {
3904
- if (ev.target === heading) {
3905
- node.children[0].dataset.placeholder = '';
3906
- }
3907
- else {
3908
- node.children[1].dataset.placeholder = '';
3909
- }
3983
+ const sub = props.component.onCompositionStart.subscribe(() => {
3984
+ node.children[0].dataset.placeholder = '';
3910
3985
  });
3911
3986
  return () => {
3912
3987
  sub.unsubscribe();
3913
3988
  };
3914
3989
  });
3915
- onUpdated(() => {
3916
- props.component.afterCheck();
3917
- });
3990
+ // onUpdated(() => {
3991
+ // props.component.afterCheck()
3992
+ // })
3918
3993
  const readonly = useReadonly();
3994
+ const output = useOutput();
3919
3995
  return () => {
3920
3996
  const { rootRef } = props;
3921
- return (jsxs("div", { class: "xnote-root", ref: [rootRef, ref], children: [adapter.slotRender(heading, children => {
3922
- return (createVNode('div', {
3923
- class: 'xnote-title',
3924
- 'data-placeholder': heading.isEmpty ? '请输入标题' : ''
3925
- }, children));
3926
- }, readonly()), adapter.slotRender(content, children => {
3927
- return (createVNode('div', {
3928
- class: 'xnote-content',
3929
- 'data-placeholder': content.isEmpty ? '请输入内容' : ''
3930
- }, children));
3931
- }, readonly())] }));
3997
+ return (jsx("div", { class: "xnote-root", ref: [rootRef, ref], children: adapter.slotRender(content, children => {
3998
+ return (createVNode('div', {
3999
+ class: 'xnote-content',
4000
+ 'data-placeholder': content.isEmpty ? '请输入内容' : ''
4001
+ }, children));
4002
+ }, readonly() || output()) }));
3932
4003
  };
3933
4004
  }
3934
4005
  const rootComponentLoader = {
@@ -3953,7 +4024,7 @@ const rootComponentLoader = {
3953
4024
  }
3954
4025
  };
3955
4026
 
3956
- var css$5 = undefined;
4027
+ var scopedId$5 = "vf-681de2";
3957
4028
 
3958
4029
  let TableService = class TableService {
3959
4030
  constructor() {
@@ -4040,12 +4111,12 @@ function ResizeColumn(props) {
4040
4111
  });
4041
4112
  return () => sub.unsubscribe();
4042
4113
  });
4043
- return withScopedCSS(css$5, () => {
4114
+ return withScopedCSS(scopedId$5, () => {
4044
4115
  return jsx("div", { ref: dragLineRef, class: ['drag-line'] });
4045
4116
  });
4046
4117
  }
4047
4118
 
4048
- var css$4 = undefined;
4119
+ var scopedId$4 = "vf-d64cf9";
4049
4120
 
4050
4121
  function TopBar(props) {
4051
4122
  const editorService = inject(EditorService);
@@ -4113,7 +4184,7 @@ function TopBar(props) {
4113
4184
  s.unsubscribe();
4114
4185
  });
4115
4186
  const deleteIndex = createSignal(null);
4116
- return withScopedCSS(css$4, () => {
4187
+ return withScopedCSS(scopedId$4, () => {
4117
4188
  const { state, tableSelection } = props.component;
4118
4189
  const position = tableSelection();
4119
4190
  return (jsx("div", { class: ['top-bar', {
@@ -4166,7 +4237,7 @@ function TopBar(props) {
4166
4237
  });
4167
4238
  }
4168
4239
 
4169
- var css$3 = undefined;
4240
+ var scopedId$3 = "vf-b1149b";
4170
4241
 
4171
4242
  function Scroll(props) {
4172
4243
  const scrollRef = createRef();
@@ -4198,7 +4269,7 @@ function Scroll(props) {
4198
4269
  draft.rightEnd = el.scrollLeft === el.scrollWidth - el.offsetWidth;
4199
4270
  });
4200
4271
  });
4201
- return withScopedCSS(css$3, () => {
4272
+ return withScopedCSS(scopedId$3, () => {
4202
4273
  return jsx("div", { ref: [scrollRef, props.scrollRef], class: ['scroll-container', {
4203
4274
  'left-end': showShadow().leftEnd,
4204
4275
  'right-end': showShadow().rightEnd,
@@ -4210,7 +4281,7 @@ function Scroll(props) {
4210
4281
  });
4211
4282
  }
4212
4283
 
4213
- var css$2 = undefined;
4284
+ var scopedId$2 = "vf-ef93c0";
4214
4285
 
4215
4286
  function LeftBar(props) {
4216
4287
  const editorService = inject(EditorService);
@@ -4284,7 +4355,7 @@ function LeftBar(props) {
4284
4355
  textbus.focus();
4285
4356
  });
4286
4357
  }
4287
- return withScopedCSS(css$2, () => {
4358
+ return withScopedCSS(scopedId$2, () => {
4288
4359
  const { state, tableSelection } = props.component;
4289
4360
  const position = tableSelection();
4290
4361
  return (jsxs("div", { class: ['left-bar', { active: props.isFocus() }], children: [jsx("div", { class: "insert-bar", children: jsx("table", { ref: insertBarRef, children: jsx("tbody", { children: state.rows.map((_, index) => {
@@ -4332,7 +4403,7 @@ function LeftBar(props) {
4332
4403
  });
4333
4404
  }
4334
4405
 
4335
- var css$1 = undefined;
4406
+ var scopedId$1 = "vf-d4c4a9";
4336
4407
 
4337
4408
  function sum(numbers) {
4338
4409
  return numbers.reduce((a, b) => a + b, 0);
@@ -4365,7 +4436,7 @@ function ResizeRow(props) {
4365
4436
  });
4366
4437
  return () => sub.unsubscribe();
4367
4438
  });
4368
- return withScopedCSS(css$1, () => {
4439
+ return withScopedCSS(scopedId$1, () => {
4369
4440
  return jsx("div", { ref: dragLineRef, style: {
4370
4441
  display: styles().visible ? 'block' : 'none',
4371
4442
  top: styles().top + 'px',
@@ -4374,7 +4445,7 @@ function ResizeRow(props) {
4374
4445
  });
4375
4446
  }
4376
4447
 
4377
- var css = undefined;
4448
+ var scopedId = "vf-4a5ad1";
4378
4449
 
4379
4450
  function SelectionMask(props) {
4380
4451
  const [styles, updateStyles] = useProduce({
@@ -4427,7 +4498,7 @@ function SelectionMask(props) {
4427
4498
  onUnmounted(() => {
4428
4499
  s.unsubscribe();
4429
4500
  });
4430
- return withScopedCSS(css, () => {
4501
+ return withScopedCSS(scopedId, () => {
4431
4502
  const style = styles();
4432
4503
  return (jsx("div", { class: "mask", style: {
4433
4504
  display: style.visible ? 'block' : 'none',
@@ -4545,7 +4616,7 @@ const TableComponentView = withAnnotation({
4545
4616
  return createVNode('td', {
4546
4617
  key: cell.slot.id
4547
4618
  }, children);
4548
- }, readonly());
4619
+ }, readonly() || output());
4549
4620
  }) }, rowMapping.get(row)));
4550
4621
  }) })] }) }) }));
4551
4622
  }
@@ -4562,7 +4633,7 @@ const TableComponentView = withAnnotation({
4562
4633
  return createVNode('td', {
4563
4634
  key: cell.slot.id
4564
4635
  }, children);
4565
- }, readonly());
4636
+ }, readonly() || output());
4566
4637
  }) }, rowMapping.get(row)));
4567
4638
  }) })] }), jsx(ResizeColumn, { tableRef: tableRef, component: props.component, onActiveStateChange: isActive => {
4568
4639
  isResizeColumn.set(isActive);
@@ -4725,48 +4796,8 @@ function autoComplete(table) {
4725
4796
  });
4726
4797
  }
4727
4798
 
4728
- class VideoComponent extends Component {
4729
- static fromJSON(textbus, json) {
4730
- return new VideoComponent(textbus, Object.assign({}, json));
4731
- }
4732
- setup() {
4733
- //
4734
- }
4735
- }
4736
- VideoComponent.type = ContentType.InlineComponent;
4737
- VideoComponent.componentName = 'VideoComponent';
4738
- function VideoView(props) {
4739
- const { name, state } = props.component;
4740
- const videoRef = createRef();
4741
- const readonly = useReadonly();
4742
- const output = useOutput();
4743
- return () => {
4744
- if (readonly() || output()) {
4745
- return (jsx("div", { class: "xnote-video", "data-component": name, children: jsx("video", { ref: videoRef, src: state.src, style: {
4746
- width: state.width,
4747
- height: state.height
4748
- } }) }));
4749
- }
4750
- return (jsx("div", { ref: props.rootRef, class: "xnote-video", "data-component": name, children: jsx(DragResize, { source: videoRef, component: props.component, children: jsx("video", { ref: videoRef, src: state.src, style: {
4751
- width: state.width,
4752
- height: state.height
4753
- } }) }) }));
4754
- };
4755
- }
4756
- const videoComponentLoader = {
4757
- match(element) {
4758
- return element.tagName === 'IMG' || element.dataset.component === VideoComponent.componentName;
4759
- },
4760
- read(element, textbus) {
4761
- var _a;
4762
- return new VideoComponent(textbus, {
4763
- src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('video')) === null || _a === void 0 ? void 0 : _a.src) || ''
4764
- });
4765
- }
4766
- };
4767
-
4768
- function createXNote(host_1) {
4769
- return __awaiter(this, arguments, void 0, function* (host, config = {}) {
4799
+ class Editor extends Textbus {
4800
+ constructor(editorConfig = {}) {
4770
4801
  const adapter = new ViewflyAdapter({
4771
4802
  [ParagraphComponent.componentName]: ParagraphView,
4772
4803
  [RootComponent.componentName]: RootView,
@@ -4790,6 +4821,38 @@ function createXNote(host_1) {
4790
4821
  app.destroy();
4791
4822
  };
4792
4823
  });
4824
+ const browserModule = new BrowserModule(Object.assign({ renderTo: () => {
4825
+ return this.host;
4826
+ }, adapter, componentLoaders: [
4827
+ sourceCodeComponentLoader,
4828
+ tableComponentLoader,
4829
+ imageComponentLoader,
4830
+ videoComponentLoader,
4831
+ highlightBoxComponentLoader,
4832
+ blockquoteComponentLoader,
4833
+ paragraphComponentLoader,
4834
+ todolistComponentLoader,
4835
+ listComponentLoader,
4836
+ ], formatLoaders: [
4837
+ backgroundColorFormatLoader,
4838
+ boldFormatLoader,
4839
+ codeFormatLoader,
4840
+ colorFormatLoader,
4841
+ fontFamilyFormatLoader,
4842
+ fontSizeFormatLoader,
4843
+ italicFormatLoader,
4844
+ linkFormatLoader,
4845
+ strikeThroughFormatLoader,
4846
+ underlineFormatLoader
4847
+ ], attributeLoaders: [
4848
+ headingAttrLoader,
4849
+ textAlignAttrLoader,
4850
+ textIndentAttrLoader
4851
+ ] }, editorConfig.viewOptions));
4852
+ const modules = [browserModule];
4853
+ if (editorConfig.collaborateConfig) {
4854
+ modules.push(new CollaborateModule(editorConfig.collaborateConfig));
4855
+ }
4793
4856
  const vDomAdapter = new ViewflyVDomAdapter({
4794
4857
  [ParagraphComponent.componentName]: ParagraphView,
4795
4858
  [RootComponent.componentName]: RootView,
@@ -4807,7 +4870,7 @@ function createXNote(host_1) {
4807
4870
  useValue: true
4808
4871
  }, {
4809
4872
  provide: DomAdapter,
4810
- useFactory() {
4873
+ useFactory: () => {
4811
4874
  return vDomAdapter;
4812
4875
  }
4813
4876
  }]);
@@ -4819,50 +4882,7 @@ function createXNote(host_1) {
4819
4882
  app.destroy();
4820
4883
  };
4821
4884
  });
4822
- const browserModule = new BrowserModule({
4823
- renderTo() {
4824
- return host;
4825
- },
4826
- adapter,
4827
- componentLoaders: [
4828
- highlightBoxComponentLoader,
4829
- blockquoteComponentLoader,
4830
- paragraphComponentLoader,
4831
- sourceCodeComponentLoader,
4832
- todolistComponentLoader,
4833
- tableComponentLoader,
4834
- listComponentLoader,
4835
- imageComponentLoader,
4836
- videoComponentLoader
4837
- ],
4838
- formatLoaders: [
4839
- backgroundColorFormatLoader,
4840
- boldFormatLoader,
4841
- codeFormatLoader,
4842
- colorFormatLoader,
4843
- fontFamilyFormatLoader,
4844
- fontSizeFormatLoader,
4845
- italicFormatLoader,
4846
- linkFormatLoader,
4847
- strikeThroughFormatLoader,
4848
- underlineFormatLoader
4849
- ],
4850
- attributeLoaders: [
4851
- headingAttrLoader,
4852
- textAlignAttrLoader,
4853
- textIndentAttrLoader
4854
- ]
4855
- });
4856
- const modules = [browserModule];
4857
- if (config.collaborateConfig) {
4858
- modules.push(new CollaborateModule(config.collaborateConfig));
4859
- }
4860
- const textbus = new Textbus({
4861
- additionalAdapters: [vDomAdapter],
4862
- zenCoding: true,
4863
- readonly: config.readonly,
4864
- imports: modules,
4865
- components: [
4885
+ super(Object.assign({ zenCoding: true, additionalAdapters: [vDomAdapter], imports: modules, components: [
4866
4886
  ImageComponent,
4867
4887
  ParagraphComponent,
4868
4888
  RootComponent,
@@ -4873,8 +4893,7 @@ function createXNote(host_1) {
4873
4893
  HighlightBoxComponent,
4874
4894
  ListComponent,
4875
4895
  VideoComponent
4876
- ],
4877
- formatters: [
4896
+ ], formatters: [
4878
4897
  backgroundColorFormatter,
4879
4898
  boldFormatter,
4880
4899
  codeFormatter,
@@ -4885,18 +4904,14 @@ function createXNote(host_1) {
4885
4904
  linkFormatter,
4886
4905
  strikeThroughFormatter,
4887
4906
  underlineFormatter
4888
- ],
4889
- attributes: [
4907
+ ], attributes: [
4890
4908
  headingAttr,
4891
4909
  textAlignAttr,
4892
4910
  textIndentAttr
4893
- ],
4894
- providers: [],
4895
- plugins: [
4911
+ ], plugins: [
4896
4912
  new LeftToolbarPlugin(),
4897
4913
  new ToolbarPlugin(),
4898
- ],
4899
- onAfterStartup(textbus) {
4914
+ ], onAfterStartup(textbus) {
4900
4915
  registerBoldShortcut(textbus);
4901
4916
  registerCodeShortcut(textbus);
4902
4917
  registerItalicShortcut(textbus);
@@ -4905,32 +4920,34 @@ function createXNote(host_1) {
4905
4920
  registerHeadingShortcut(textbus);
4906
4921
  registerTextAlignShortcut(textbus);
4907
4922
  registerTextIndentShortcut(textbus);
4908
- }
4909
- });
4923
+ } }, editorConfig));
4924
+ this.editorConfig = editorConfig;
4925
+ this.translator = new OutputTranslator();
4926
+ this.vDomAdapter = vDomAdapter;
4927
+ }
4928
+ mount(host) {
4929
+ this.host = host;
4910
4930
  let rootComp;
4931
+ const config = this.editorConfig;
4911
4932
  if (config.content) {
4912
- const parser = textbus.get(Parser);
4933
+ const parser = this.get(Parser);
4913
4934
  const doc = parser.parseDoc(config.content, rootComponentLoader);
4914
- rootComp = doc instanceof Component ? doc : new RootComponent(textbus, {
4915
- heading: new Slot([ContentType.Text]),
4935
+ rootComp = doc instanceof Component ? doc : new RootComponent(this, {
4936
+ // heading: new Slot([ContentType.Text]),
4916
4937
  content: doc
4917
4938
  });
4918
4939
  }
4919
4940
  else {
4920
- rootComp = new RootComponent(textbus, {
4921
- heading: new Slot([ContentType.Text]),
4941
+ rootComp = new RootComponent(this, {
4942
+ // heading: new Slot([ContentType.Text]),
4922
4943
  content: new Slot([ContentType.Text, ContentType.InlineComponent, ContentType.BlockComponent])
4923
4944
  });
4924
4945
  }
4925
- yield textbus.render(rootComp);
4926
- const translator = new OutputTranslator();
4927
- return {
4928
- textbus,
4929
- getHTML() {
4930
- return translator.transform(vDomAdapter.host);
4931
- }
4932
- };
4933
- });
4946
+ return this.render(rootComp);
4947
+ }
4948
+ getHTML() {
4949
+ return this.translator.transform(this.vDomAdapter.host);
4950
+ }
4934
4951
  }
4935
4952
 
4936
- export { AttrTool, BlockTool, BlockquoteComponent, BlockquoteView, BoldTool, Button, CodeTool, ColorTool, ComponentToolbar, Divider, DragResize, Dropdown, DropdownContextService, DropdownMenuPortal, DropdownService, EditorService, FontFamilyTool, FontSizeTool, HighlightBoxComponent, HighlightBoxView, ImageComponent, ImageView, InsertTool, ItalicTool, LeftToolbar, LeftToolbarPlugin, LinkTool, ListComponent, ListComponentView, Matcher, MenuItem, OutputInjectionToken, ParagraphComponent, ParagraphView, Popup, RefreshService, RootComponent, RootView, SourceCodeComponent, SourceCodeView, StrikeThroughTool, TableComponent, TableComponentView, TodolistComponent, TodolistView, Toolbar, ToolbarItem, ToolbarPlugin, UnderlineTool, VideoComponent, VideoView, autoComplete, backgroundColorFormatLoader, backgroundColorFormatter, blockquoteComponentLoader, boldFormatLoader, boldFormatter, codeFormatLoader, codeFormatter, colorFormatLoader, colorFormatter, createXNote, deltaToBlock, fontFamilyFormatLoader, fontFamilyFormatter, fontSizeFormatLoader, fontSizeFormatter, headingAttr, headingAttrLoader, highlightBoxComponentLoader, imageComponentLoader, isSupportFont, italicFormatLoader, italicFormatter, languageList, linkFormatLoader, linkFormatter, listComponentLoader, paragraphComponentLoader, registerBoldShortcut, registerCodeShortcut, registerHeadingShortcut, registerItalicShortcut, registerStrikeThroughShortcut, registerTextAlignShortcut, registerTextIndentShortcut, registerUnderlineShortcut, rootComponentLoader, sourceCodeComponentLoader, sourceCodeThemes, strikeThroughFormatLoader, strikeThroughFormatter, tableComponentLoader, textAlignAttr, textAlignAttrLoader, textIndentAttr, textIndentAttrLoader, todolistComponentLoader, toggleBold, toggleCode, toggleItalic, toggleStrikeThrough, toggleUnderline, underlineFormatLoader, underlineFormatter, useActiveBlock, useBlockContent, useBlockTransform, useOutput, useReadonly, videoComponentLoader };
4953
+ export { AttrTool, BlockTool, BlockquoteComponent, BlockquoteView, BoldTool, Button, CodeTool, ColorTool, ComponentToolbar, Divider, DragResize, Dropdown, DropdownContextService, DropdownMenuPortal, DropdownService, Editor, EditorService, FontFamilyTool, FontSizeTool, HighlightBoxComponent, HighlightBoxView, ImageComponent, ImageView, InsertTool, ItalicTool, LeftToolbar, LeftToolbarPlugin, LinkTool, ListComponent, ListComponentView, Matcher, MenuItem, OutputInjectionToken, ParagraphComponent, ParagraphView, Popup, RefreshService, RootComponent, RootView, SourceCodeComponent, SourceCodeView, StrikeThroughTool, TableComponent, TableComponentView, TodolistComponent, TodolistView, Toolbar, ToolbarItem, ToolbarPlugin, UnderlineTool, VideoComponent, VideoView, autoComplete, backgroundColorFormatLoader, backgroundColorFormatter, blockquoteComponentLoader, boldFormatLoader, boldFormatter, codeFormatLoader, codeFormatter, colorFormatLoader, colorFormatter, deltaToBlock, fontFamilyFormatLoader, fontFamilyFormatter, fontSizeFormatLoader, fontSizeFormatter, headingAttr, headingAttrLoader, highlightBoxComponentLoader, imageComponentLoader, isSupportFont, italicFormatLoader, italicFormatter, languageList, linkFormatLoader, linkFormatter, listComponentLoader, paragraphComponentLoader, registerBoldShortcut, registerCodeShortcut, registerHeadingShortcut, registerItalicShortcut, registerStrikeThroughShortcut, registerTextAlignShortcut, registerTextIndentShortcut, registerUnderlineShortcut, rootComponentLoader, sourceCodeComponentLoader, sourceCodeThemes, strikeThroughFormatLoader, strikeThroughFormatter, tableComponentLoader, textAlignAttr, textAlignAttrLoader, textIndentAttr, textIndentAttrLoader, todolistComponentLoader, toggleBold, toggleCode, toggleItalic, toggleStrikeThrough, toggleUnderline, underlineFormatLoader, underlineFormatter, useActiveBlock, useBlockContent, useBlockTransform, useOutput, useReadonly, videoComponentLoader };