@textbus/xnote 0.0.1-alpha.4 → 0.0.1-alpha.6

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 }) }));
@@ -397,6 +387,8 @@ const Dropdown = withAnnotation({
397
387
  const dropdownRef = createRef();
398
388
  onMounted(() => {
399
389
  const sub = dropdownContextService.onOpenStateChange.subscribe(b => {
390
+ var _a;
391
+ (_a = props.onExpendStateChange) === null || _a === void 0 ? void 0 : _a.call(props, b);
400
392
  isShow.set(b);
401
393
  });
402
394
  return () => sub.unsubscribe();
@@ -434,7 +426,7 @@ const Dropdown = withAnnotation({
434
426
  dropdownContextService.open();
435
427
  }
436
428
  },
437
- $render: withScopedCSS(css$g, () => {
429
+ $render: withScopedCSS(scopedId$g, () => {
438
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) ?
439
431
  props.menu.map(menu => {
440
432
  return (jsx("div", { class: "dropdown-menu-item", onClick: () => {
@@ -450,7 +442,7 @@ const Dropdown = withAnnotation({
450
442
  };
451
443
  });
452
444
 
453
- var css$e = undefined;
445
+ var scopedId$e = "vf-64f71d";
454
446
 
455
447
  function MenuItem(props) {
456
448
  const dropdownContextService = inject(DropdownContextService, InjectFlags.Optional, null);
@@ -470,7 +462,7 @@ function MenuItem(props) {
470
462
  }
471
463
  (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, props.value);
472
464
  }
473
- return withScopedCSS(css$e, () => {
465
+ return withScopedCSS(scopedId$e, () => {
474
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 ?
475
467
  jsx("div", { class: "arrow", children: jsx("span", { class: "xnote-icon-arrow-right" }) }) :
476
468
  jsx("div", { class: [
@@ -480,11 +472,11 @@ function MenuItem(props) {
480
472
  });
481
473
  }
482
474
 
483
- var css$d = undefined;
475
+ var scopedId$d = "vf-a23c47";
484
476
 
485
477
  function Popup(props) {
486
478
  const host = inject(VIEW_CONTAINER);
487
- return createPortal(withScopedCSS(css$d, () => {
479
+ return createPortal(withScopedCSS(scopedId$d, () => {
488
480
  return (jsx("div", { class: "popup", style: {
489
481
  left: props.left + 'px',
490
482
  top: props.top + 'px'
@@ -492,15 +484,15 @@ function Popup(props) {
492
484
  }), host);
493
485
  }
494
486
 
495
- var css$c = undefined;
487
+ var scopedId$c = "vf-216815";
496
488
 
497
489
  function ToolbarItem(props) {
498
- return withScopedCSS(css$c, () => {
490
+ return withScopedCSS(scopedId$c, () => {
499
491
  return (jsx("div", { class: "toolbar-item", children: props.children }));
500
492
  });
501
493
  }
502
494
 
503
- var css$b = undefined;
495
+ var scopedId$b = "vf-2a8a65";
504
496
 
505
497
  let RefreshService = class RefreshService {
506
498
  constructor() {
@@ -600,14 +592,14 @@ function ParagraphView(props) {
600
592
  }
601
593
  const paragraphComponentLoader = {
602
594
  match(element) {
603
- return element.dataset.compoment === ParagraphComponent.name || element.tagName === 'P';
595
+ return element.dataset.compoment === ParagraphComponent.name || /P|H[1-6]/.test(element.tagName);
604
596
  },
605
597
  read(element, textbus, slotParser) {
606
598
  const delta = slotParser(new Slot([
607
599
  ContentType.Text,
608
600
  ContentType.InlineComponent,
609
601
  ContentType.BlockComponent
610
- ]), element.tagName === 'P' ? element : element.children[0]).toDelta();
602
+ ]), /P|H[1-6]/.test(element.tagName) ? element : element.children[0]).toDelta();
611
603
  const results = deltaToBlock(delta, textbus);
612
604
  if (results.length === 1) {
613
605
  return results[0];
@@ -940,6 +932,15 @@ class SourceCodeComponent extends Component {
940
932
  }
941
933
  });
942
934
  }
935
+ removeSlot(slot) {
936
+ const slots = this.state.slots;
937
+ const index = slots.findIndex(i => i.slot === slot);
938
+ if (index > -1) {
939
+ slots.splice(index, 1);
940
+ return true;
941
+ }
942
+ return false;
943
+ }
943
944
  }
944
945
  SourceCodeComponent.type = ContentType.BlockComponent;
945
946
  SourceCodeComponent.componentName = 'SourceCodeComponent';
@@ -1074,11 +1075,11 @@ function SourceCodeView(props) {
1074
1075
  return textNode;
1075
1076
  });
1076
1077
  }
1077
- return (jsxs("pre", { ref: props.rootRef, class: {
1078
+ return (jsxs("div", { ref: props.rootRef, class: {
1078
1079
  'xnote-source-code': true,
1079
1080
  'xnote-source-code-line-number': state.lineNumber,
1080
1081
  [state.theme || 'github']: true
1081
- }, lang: state.lang, "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 => {
1082
+ }, "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 => {
1082
1083
  return {
1083
1084
  label: jsx(MenuItem, { checked: state.lang === item.value, children: item.label || 'Plain Text' }),
1084
1085
  value: item.value
@@ -1125,10 +1126,10 @@ function SourceCodeView(props) {
1125
1126
  children.push(br);
1126
1127
  }
1127
1128
  }
1128
- return createVNode('div', {
1129
+ return createVNode('pre', {
1129
1130
  class: 'xnote-source-code-line' + (item.emphasize ? ' xnote-source-code-line-emphasize' : '')
1130
1131
  }, [
1131
- createVNode('div', { class: 'xnote-source-code-line-content' }, children)
1132
+ createVNode('span', { class: 'xnote-source-code-line-content' }, children)
1132
1133
  ]);
1133
1134
  }, readonly());
1134
1135
  }) }), jsx("span", { class: "xnote-source-code-lang", children: lang })] })] }));
@@ -1136,12 +1137,13 @@ function SourceCodeView(props) {
1136
1137
  }
1137
1138
  const sourceCodeComponentLoader = {
1138
1139
  match(element) {
1139
- return element.tagName === 'PRE';
1140
+ return element.tagName === 'DIV' && element.dataset.component === SourceCodeComponent.componentName ||
1141
+ element.tagName === 'PRE';
1140
1142
  },
1141
1143
  read(el, textbus) {
1142
- const lines = el.querySelectorAll('.xnote-source-code-line');
1143
1144
  let slots = [];
1144
- if (lines.length) {
1145
+ if (el.tagName === 'DIV') {
1146
+ const lines = el.querySelectorAll('.xnote-source-code-line');
1145
1147
  slots = Array.from(lines).map(i => {
1146
1148
  const code = i.innerText.replace(/[\s\n]+$/, '');
1147
1149
  const item = createCodeSlot();
@@ -1162,9 +1164,10 @@ const sourceCodeComponentLoader = {
1162
1164
  });
1163
1165
  }
1164
1166
  return new SourceCodeComponent(textbus, {
1165
- lang: el.getAttribute('lang') || '',
1166
- theme: el.getAttribute('theme') || '',
1167
- lineNumber: !el.classList.contains('xnote-source-code-hide-line-number'),
1167
+ lang: el.dataset.lang || '',
1168
+ theme: el.dataset.theme || '',
1169
+ lineNumber: !!el.dataset.lineNumber || true,
1170
+ autoBreak: !!el.dataset.autoBreak || true,
1168
1171
  slots
1169
1172
  });
1170
1173
  },
@@ -1318,7 +1321,7 @@ function AttrTool(props) {
1318
1321
  break;
1319
1322
  }
1320
1323
  }
1321
- return withScopedCSS(css$b, () => {
1324
+ return withScopedCSS(scopedId$b, () => {
1322
1325
  const states = checkStates();
1323
1326
  return (jsx(Dropdown, { style: props.style, abreast: props.abreast, onCheck: updateAttr, trigger: 'hover', menu: [
1324
1327
  {
@@ -1908,6 +1911,25 @@ class ListComponent extends Component {
1908
1911
  selection.setPosition(slot, 0);
1909
1912
  }
1910
1913
  });
1914
+ useDynamicShortcut({
1915
+ keymap: {
1916
+ key: 'Tab'
1917
+ },
1918
+ action: () => {
1919
+ updateAfterList(this);
1920
+ return false;
1921
+ }
1922
+ });
1923
+ useDynamicShortcut({
1924
+ keymap: {
1925
+ key: 'Tab',
1926
+ shiftKey: true
1927
+ },
1928
+ action: () => {
1929
+ Promise.resolve().then(() => updateAfterList(this));
1930
+ return false;
1931
+ }
1932
+ });
1911
1933
  }
1912
1934
  }
1913
1935
  ListComponent.componentName = 'ListComponent';
@@ -2221,17 +2243,16 @@ function useBlockTransform() {
2221
2243
  commander.unApplyAttribute(headingAttr);
2222
2244
  commander.transform({
2223
2245
  targetType: ParagraphComponent.type,
2224
- multipleSlot: false,
2225
2246
  slotFactory() {
2226
2247
  return new Slot([
2227
2248
  ContentType.InlineComponent,
2228
2249
  ContentType.Text
2229
2250
  ]);
2230
2251
  },
2231
- stateFactory(slot) {
2232
- return new ParagraphComponent(textbus, {
2252
+ stateFactory(slots) {
2253
+ return slots.map(slot => new ParagraphComponent(textbus, {
2233
2254
  slot
2234
- });
2255
+ }));
2235
2256
  }
2236
2257
  });
2237
2258
  break;
@@ -2250,17 +2271,18 @@ function useBlockTransform() {
2250
2271
  commander.unApplyAttribute(headingAttr);
2251
2272
  commander.transform({
2252
2273
  targetType: TodolistComponent.type,
2253
- multipleSlot: false,
2254
2274
  slotFactory() {
2255
2275
  return new Slot([
2256
2276
  ContentType.InlineComponent,
2257
2277
  ContentType.Text
2258
2278
  ]);
2259
2279
  },
2260
- stateFactory(slot) {
2261
- return new TodolistComponent(textbus, {
2262
- checked: false,
2263
- slot
2280
+ stateFactory(slots) {
2281
+ return slots.map(slot => {
2282
+ return new TodolistComponent(textbus, {
2283
+ checked: false,
2284
+ slot
2285
+ });
2264
2286
  });
2265
2287
  }
2266
2288
  });
@@ -2270,18 +2292,19 @@ function useBlockTransform() {
2270
2292
  {
2271
2293
  commander.transform({
2272
2294
  targetType: ListComponent.type,
2273
- multipleSlot: false,
2274
2295
  slotFactory() {
2275
2296
  return new Slot([
2276
2297
  ContentType.InlineComponent,
2277
2298
  ContentType.Text
2278
2299
  ]);
2279
2300
  },
2280
- stateFactory(slot) {
2281
- return new ListComponent(textbus, {
2282
- type: value === 'ol' ? 'OrderedList' : 'UnorderedList',
2283
- reorder: true,
2284
- slot
2301
+ stateFactory(slots) {
2302
+ return slots.map((slot, index) => {
2303
+ return new ListComponent(textbus, {
2304
+ type: value === 'ol' ? 'OrderedList' : 'UnorderedList',
2305
+ reorder: index === 0,
2306
+ slot
2307
+ });
2285
2308
  });
2286
2309
  }
2287
2310
  });
@@ -2329,16 +2352,17 @@ function useBlockTransform() {
2329
2352
  if (state.state === QueryStateType.Enabled) {
2330
2353
  commander.transform({
2331
2354
  targetType: ParagraphComponent.type,
2332
- multipleSlot: false,
2333
2355
  slotFactory() {
2334
2356
  return new Slot([
2335
2357
  ContentType.InlineComponent,
2336
2358
  ContentType.Text
2337
2359
  ]);
2338
2360
  },
2339
- stateFactory(slot) {
2340
- return new ParagraphComponent(textbus, {
2341
- slot
2361
+ stateFactory(slots) {
2362
+ return slots.map(slot => {
2363
+ return new ParagraphComponent(textbus, {
2364
+ slot
2365
+ });
2342
2366
  });
2343
2367
  }
2344
2368
  });
@@ -2346,24 +2370,23 @@ function useBlockTransform() {
2346
2370
  else {
2347
2371
  commander.transform({
2348
2372
  targetType: SourceCodeComponent.type,
2349
- multipleSlot: true,
2350
2373
  slotFactory() {
2351
2374
  return new Slot([
2352
2375
  ContentType.Text
2353
2376
  ]);
2354
2377
  },
2355
2378
  stateFactory(slots) {
2356
- return new SourceCodeComponent(textbus, {
2357
- lang: '',
2358
- lineNumber: true,
2359
- autoBreak: true,
2360
- slots: slots.map(slot => {
2361
- return {
2362
- slot,
2363
- emphasize: false
2364
- };
2365
- })
2366
- });
2379
+ return [new SourceCodeComponent(textbus, {
2380
+ lang: '',
2381
+ lineNumber: true,
2382
+ autoBreak: true,
2383
+ slots: slots.map(slot => {
2384
+ return {
2385
+ slot,
2386
+ emphasize: false
2387
+ };
2388
+ })
2389
+ })];
2367
2390
  }
2368
2391
  });
2369
2392
  }
@@ -2412,7 +2435,7 @@ function useBlockTransform() {
2412
2435
  function BlockTool() {
2413
2436
  const checkStates = useActiveBlock();
2414
2437
  const transform = useBlockTransform();
2415
- return withScopedCSS(css$b, () => {
2438
+ return withScopedCSS(scopedId$b, () => {
2416
2439
  const states = checkStates();
2417
2440
  const types = [
2418
2441
  [states.paragraph, 'xnote-icon-pilcrow'],
@@ -2843,7 +2866,7 @@ function CodeTool() {
2843
2866
  };
2844
2867
  }
2845
2868
 
2846
- var css$a = undefined;
2869
+ var scopedId$a = "vf-1fbbdf";
2847
2870
 
2848
2871
  function ColorTool(props) {
2849
2872
  const query = inject(Query);
@@ -2891,7 +2914,7 @@ function ColorTool(props) {
2891
2914
  '#90a0e5',
2892
2915
  '#c596e0',
2893
2916
  ];
2894
- return withScopedCSS(css$a, () => {
2917
+ return withScopedCSS(scopedId$a, () => {
2895
2918
  const vm = viewModel();
2896
2919
  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: {
2897
2920
  active: textColor() === ''
@@ -3099,7 +3122,7 @@ function ItalicTool() {
3099
3122
  };
3100
3123
  }
3101
3124
 
3102
- var css$9 = undefined;
3125
+ var scopedId$9 = "vf-269a0b";
3103
3126
 
3104
3127
  function LinkTool(props) {
3105
3128
  const selectionBridge = inject(SelectionBridge);
@@ -3130,7 +3153,7 @@ function LinkTool(props) {
3130
3153
  onUnmounted(() => {
3131
3154
  sub.unsubscribe();
3132
3155
  });
3133
- return withScopedCSS(css$9, () => {
3156
+ return withScopedCSS(scopedId$9, () => {
3134
3157
  const containerRect = container.getBoundingClientRect();
3135
3158
  const rect = isShow() ? selectionBridge.getRect({
3136
3159
  slot: selection.focusSlot,
@@ -3199,18 +3222,107 @@ function UnderlineTool() {
3199
3222
  };
3200
3223
  }
3201
3224
 
3202
- var css$8 = undefined;
3225
+ var scopedId$8 = "vf-cf8e1c";
3226
+
3227
+ class FileUploader {
3228
+ }
3229
+
3230
+ class ImageComponent extends Component {
3231
+ static fromJSON(textbus, json) {
3232
+ return new ImageComponent(textbus, Object.assign({}, json));
3233
+ }
3234
+ }
3235
+ ImageComponent.type = ContentType.InlineComponent;
3236
+ ImageComponent.componentName = 'ImageComponent';
3237
+ function ImageView(props) {
3238
+ const { name, state } = props.component;
3239
+ const imageRef = createRef();
3240
+ const readonly = useReadonly();
3241
+ const output = useOutput();
3242
+ return () => {
3243
+ if (readonly() || output()) {
3244
+ return (jsx("div", { class: "xnote-image", ref: props.rootRef, "data-component": name, children: jsx("img", { alt: "", src: state.src, style: {
3245
+ width: state.width,
3246
+ height: state.height
3247
+ } }) }));
3248
+ }
3249
+ 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: {
3250
+ width: state.width,
3251
+ height: state.height
3252
+ } }) }) }));
3253
+ };
3254
+ }
3255
+ const imageComponentLoader = {
3256
+ match(element) {
3257
+ return element.tagName === 'IMG' || element.dataset.component === ImageComponent.componentName;
3258
+ },
3259
+ read(element, textbus) {
3260
+ var _a;
3261
+ return new ImageComponent(textbus, {
3262
+ src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('img')) === null || _a === void 0 ? void 0 : _a.src) || ''
3263
+ });
3264
+ }
3265
+ };
3266
+
3267
+ class VideoComponent extends Component {
3268
+ static fromJSON(textbus, json) {
3269
+ return new VideoComponent(textbus, Object.assign({}, json));
3270
+ }
3271
+ setup() {
3272
+ //
3273
+ }
3274
+ }
3275
+ VideoComponent.type = ContentType.InlineComponent;
3276
+ VideoComponent.componentName = 'VideoComponent';
3277
+ function VideoView(props) {
3278
+ const { name, state } = props.component;
3279
+ const videoRef = createRef();
3280
+ const readonly = useReadonly();
3281
+ const output = useOutput();
3282
+ return () => {
3283
+ if (readonly() || output()) {
3284
+ return (jsx("div", { class: "xnote-video", "data-component": name, children: jsx("video", { ref: videoRef, src: state.src, style: {
3285
+ width: state.width,
3286
+ height: state.height
3287
+ } }) }));
3288
+ }
3289
+ 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: {
3290
+ width: state.width,
3291
+ height: state.height
3292
+ } }) }) }));
3293
+ };
3294
+ }
3295
+ const videoComponentLoader = {
3296
+ match(element) {
3297
+ return element.tagName === 'IMG' || element.dataset.component === VideoComponent.componentName;
3298
+ },
3299
+ read(element, textbus) {
3300
+ var _a;
3301
+ return new VideoComponent(textbus, {
3302
+ src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('video')) === null || _a === void 0 ? void 0 : _a.src) || ''
3303
+ });
3304
+ }
3305
+ };
3203
3306
 
3204
3307
  function InsertTool(props) {
3205
3308
  const commander = inject(Commander);
3206
3309
  const selection = inject(Selection);
3207
3310
  const textbus = inject(Textbus);
3311
+ const fileUploader = inject(FileUploader, InjectFlags.Optional, null);
3208
3312
  function insert(type) {
3209
3313
  var _a;
3210
3314
  const component = (_a = props.slot) === null || _a === void 0 ? void 0 : _a.parent;
3211
3315
  if (!component) {
3212
3316
  return;
3213
3317
  }
3318
+ function insertComponent(comp) {
3319
+ if (props.replace) {
3320
+ commander.replaceComponent(component, comp);
3321
+ }
3322
+ else {
3323
+ commander.insertAfter(comp, component);
3324
+ }
3325
+ }
3214
3326
  switch (type) {
3215
3327
  case 'h1':
3216
3328
  case 'h2':
@@ -3225,12 +3337,12 @@ function InsertTool(props) {
3225
3337
  ContentType.Text
3226
3338
  ]);
3227
3339
  if (/h[1-6]/.test(type)) {
3228
- slot.setAttribute(headingAttr, +type.substring(1));
3340
+ slot.setAttribute(headingAttr, type);
3229
3341
  }
3230
3342
  const p = new ParagraphComponent(textbus, {
3231
3343
  slot
3232
3344
  });
3233
- commander.insertAfter(p, component);
3345
+ insertComponent(p);
3234
3346
  selection.setPosition(slot, 0);
3235
3347
  }
3236
3348
  break;
@@ -3246,7 +3358,7 @@ function InsertTool(props) {
3246
3358
  reorder: true,
3247
3359
  type: type === 'ol' ? 'OrderedList' : 'UnorderedList'
3248
3360
  });
3249
- commander.insertAfter(list, component);
3361
+ insertComponent(list);
3250
3362
  selection.setPosition(slot, 0);
3251
3363
  }
3252
3364
  break;
@@ -3263,14 +3375,14 @@ function InsertTool(props) {
3263
3375
  emphasize: false
3264
3376
  }]
3265
3377
  });
3266
- commander.insertAfter(comp, component);
3378
+ insertComponent(comp);
3267
3379
  selection.setPosition(slot, 0);
3268
3380
  }
3269
3381
  break;
3270
3382
  case 'table':
3271
3383
  {
3272
3384
  const table = new TableComponent(textbus);
3273
- commander.insertAfter(table, component);
3385
+ insertComponent(table);
3274
3386
  selection.setPosition(table.state.rows[0].cells[0].slot, 0);
3275
3387
  }
3276
3388
  break;
@@ -3284,31 +3396,47 @@ function InsertTool(props) {
3284
3396
  slot,
3285
3397
  checked: false
3286
3398
  });
3287
- commander.insertAfter(comp, component);
3399
+ insertComponent(comp);
3288
3400
  selection.setPosition(slot, 0);
3289
3401
  }
3290
3402
  break;
3291
3403
  case 'image':
3404
+ if (fileUploader) {
3405
+ Promise.resolve(fileUploader.uploadFile('image')).then(url => {
3406
+ const img = new ImageComponent(textbus, {
3407
+ src: url
3408
+ });
3409
+ commander.insert(img);
3410
+ });
3411
+ }
3292
3412
  break;
3293
3413
  case 'video':
3414
+ if (fileUploader) {
3415
+ Promise.resolve(fileUploader.uploadFile('video')).then(url => {
3416
+ const img = new VideoComponent(textbus, {
3417
+ src: url
3418
+ });
3419
+ commander.insert(img);
3420
+ });
3421
+ }
3294
3422
  break;
3295
3423
  case 'highlightBox':
3296
3424
  {
3297
3425
  const p = new ParagraphComponent(textbus);
3298
3426
  const comp = new HighlightBoxComponent(textbus);
3299
3427
  comp.state.slot.insert(p);
3300
- commander.insertAfter(comp, component);
3428
+ insertComponent(comp);
3301
3429
  selection.setPosition(p.state.slot, 0);
3302
3430
  }
3303
3431
  break;
3304
3432
  }
3305
3433
  }
3306
- return withScopedCSS(css$8, () => {
3434
+ return withScopedCSS(scopedId$8, () => {
3307
3435
  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" })] });
3308
3436
  });
3309
3437
  }
3310
3438
 
3311
- var css$7 = undefined;
3439
+ var scopedId$7 = "vf-b05292";
3312
3440
 
3313
3441
  const LeftToolbar = withAnnotation({
3314
3442
  providers: [RefreshService]
@@ -3336,11 +3464,12 @@ const LeftToolbar = withAnnotation({
3336
3464
  top: 0,
3337
3465
  display: false
3338
3466
  });
3467
+ let isIgnoreMove = false;
3339
3468
  onMounted(() => {
3340
3469
  const rootComponent = rootComponentRef.component;
3341
3470
  const docContentContainer = adapter.getNativeNodeBySlot(rootComponent.state.content);
3342
3471
  const sub = fromEvent(docContentContainer, 'mousemove').pipe(filter(() => {
3343
- return selection.isCollapsed;
3472
+ return !isIgnoreMove;
3344
3473
  }), map(ev => {
3345
3474
  let currentNode = ev.target;
3346
3475
  while (currentNode) {
@@ -3467,7 +3596,10 @@ const LeftToolbar = withAnnotation({
3467
3596
  }
3468
3597
  }
3469
3598
  const isEmptyBlock = createSignal(true);
3470
- return withScopedCSS(css$7, () => {
3599
+ function changeIgnoreMove(b) {
3600
+ isIgnoreMove = b;
3601
+ }
3602
+ return withScopedCSS(scopedId$7, () => {
3471
3603
  const position = positionSignal();
3472
3604
  const slot = activeSlot();
3473
3605
  let activeNode = jsx("span", { class: "xnote-icon-pilcrow" });
@@ -3499,11 +3631,14 @@ const LeftToolbar = withAnnotation({
3499
3631
  left: position.left + 'px',
3500
3632
  top: position.top + 'px',
3501
3633
  display: position.display && selection.isCollapsed ? 'block' : 'none'
3502
- }, children: jsx(Dropdown, { abreast: true, style: {
3634
+ }, children: jsx(Dropdown, { onExpendStateChange: changeIgnoreMove, abreast: true, style: {
3503
3635
  position: 'absolute',
3504
3636
  right: 0,
3505
3637
  top: 0
3506
- }, menu: jsxs(Fragment, { children: [jsxs("div", { class: "btn-group", children: [jsx(Button, { ordinary: true, highlight: states.paragraph, onClick: () => transform('paragraph'), children: jsx("span", { class: "xnote-icon-pilcrow" }) }), jsx(Button, { ordinary: true, highlight: states.h1, onClick: () => transform('h1'), children: jsx("span", { class: "xnote-icon-heading-h1" }) }), jsx(Button, { ordinary: true, highlight: states.h2, onClick: () => transform('h2'), children: jsx("span", { class: "xnote-icon-heading-h2" }) }), jsx(Button, { ordinary: true, highlight: states.h3, onClick: () => transform('h3'), children: jsx("span", { class: "xnote-icon-heading-h3" }) }), jsx(Button, { ordinary: true, highlight: states.h4, onClick: () => transform('h4'), children: jsx("span", { class: "xnote-icon-heading-h4" }) }), jsx(Button, { ordinary: true, highlight: states.todolist, onClick: () => transform('todolist'), children: jsx("span", { class: "xnote-icon-checkbox-checked" }) }), jsx(Button, { ordinary: true, highlight: states.orderedList, onClick: () => transform('ol'), children: jsx("span", { class: "xnote-icon-list-numbered" }) }), jsx(Button, { ordinary: true, highlight: states.unorderedList, onClick: () => transform('ul'), children: jsx("span", { class: "xnote-icon-list" }) }), jsx(Button, { ordinary: true, highlight: states.blockquote, onClick: () => transform('blockquote'), children: jsx("span", { class: "xnote-icon-quotes-right" }) }), jsx(Button, { ordinary: true, highlight: states.sourceCode, onClick: () => transform('sourceCode'), children: jsx("span", { class: "xnote-icon-source-code" }) })] }), jsx(Divider, {}), jsx(AttrTool, { style: { display: 'block' }, abreast: true, applyBefore: applyBefore, queryBefore: queryBefore, queryAfter: queryAfter, children: jsx(MenuItem, { arrow: true, icon: jsx("span", { class: "xnote-icon-indent-decrease" }), children: "\u7F29\u8FDB\u548C\u5BF9\u9F50" }) }), jsx(ColorTool, { style: { display: 'block' }, abreast: true, applyBefore: applyBefore, queryBefore: queryBefore, queryAfter: queryAfter, children: jsx(MenuItem, { arrow: true, icon: jsx("span", { class: "xnote-icon-color" }), children: "\u989C\u8272" }) }), jsx(Divider, {}), jsx(MenuItem, { onClick: copy, icon: jsx("span", { class: "xnote-icon-copy" }), children: "\u590D\u5236" }), jsx(MenuItem, { onClick: remove, icon: jsx("span", { class: "xnote-icon-bin" }), children: "\u5220\u9664" }), jsx(MenuItem, { onClick: cut, icon: jsx("span", { class: "xnote-icon-cut" }), children: "\u526A\u5207" }), jsx(Divider, {}), jsx(Dropdown, { style: { display: 'block' }, abreast: true, menu: jsx(InsertTool, { slot: activeSlot() }), children: jsx(MenuItem, { arrow: true, icon: jsx("span", { class: "xnote-icon-plus" }), children: "\u5728\u4E0B\u9762\u6DFB\u52A0" }) })] }), children: jsx("button", { type: "button", class: "left-toolbar-btn", children: isEmptyBlock() ?
3638
+ }, menu: isEmptyBlock() ?
3639
+ jsx(InsertTool, { replace: true, slot: activeSlot() })
3640
+ :
3641
+ jsxs(Fragment, { children: [jsxs("div", { class: "btn-group", children: [jsx(Button, { ordinary: true, highlight: states.paragraph, onClick: () => transform('paragraph'), children: jsx("span", { class: "xnote-icon-pilcrow" }) }), jsx(Button, { ordinary: true, highlight: states.h1, onClick: () => transform('h1'), children: jsx("span", { class: "xnote-icon-heading-h1" }) }), jsx(Button, { ordinary: true, highlight: states.h2, onClick: () => transform('h2'), children: jsx("span", { class: "xnote-icon-heading-h2" }) }), jsx(Button, { ordinary: true, highlight: states.h3, onClick: () => transform('h3'), children: jsx("span", { class: "xnote-icon-heading-h3" }) }), jsx(Button, { ordinary: true, highlight: states.h4, onClick: () => transform('h4'), children: jsx("span", { class: "xnote-icon-heading-h4" }) }), jsx(Button, { ordinary: true, highlight: states.todolist, onClick: () => transform('todolist'), children: jsx("span", { class: "xnote-icon-checkbox-checked" }) }), jsx(Button, { ordinary: true, highlight: states.orderedList, onClick: () => transform('ol'), children: jsx("span", { class: "xnote-icon-list-numbered" }) }), jsx(Button, { ordinary: true, highlight: states.unorderedList, onClick: () => transform('ul'), children: jsx("span", { class: "xnote-icon-list" }) }), jsx(Button, { ordinary: true, highlight: states.blockquote, onClick: () => transform('blockquote'), children: jsx("span", { class: "xnote-icon-quotes-right" }) }), jsx(Button, { ordinary: true, highlight: states.sourceCode, onClick: () => transform('sourceCode'), children: jsx("span", { class: "xnote-icon-source-code" }) })] }), jsx(Divider, {}), jsx(AttrTool, { style: { display: 'block' }, abreast: true, applyBefore: applyBefore, queryBefore: queryBefore, queryAfter: queryAfter, children: jsx(MenuItem, { arrow: true, icon: jsx("span", { class: "xnote-icon-indent-decrease" }), children: "\u7F29\u8FDB\u548C\u5BF9\u9F50" }) }), jsx(ColorTool, { style: { display: 'block' }, abreast: true, applyBefore: applyBefore, queryBefore: queryBefore, queryAfter: queryAfter, children: jsx(MenuItem, { arrow: true, icon: jsx("span", { class: "xnote-icon-color" }), children: "\u989C\u8272" }) }), jsx(Divider, {}), jsx(MenuItem, { onClick: copy, icon: jsx("span", { class: "xnote-icon-copy" }), children: "\u590D\u5236" }), jsx(MenuItem, { onClick: remove, icon: jsx("span", { class: "xnote-icon-bin" }), children: "\u5220\u9664" }), jsx(MenuItem, { onClick: cut, icon: jsx("span", { class: "xnote-icon-cut" }), children: "\u526A\u5207" }), jsx(Divider, {}), jsx(Dropdown, { style: { display: 'block' }, abreast: true, menu: jsx(InsertTool, { slot: activeSlot() }), children: jsx(MenuItem, { arrow: true, icon: jsx("span", { class: "xnote-icon-plus" }), children: "\u5728\u4E0B\u9762\u6DFB\u52A0" }) })] }), children: jsx("button", { type: "button", class: "left-toolbar-btn", children: isEmptyBlock() ?
3507
3642
  jsx("span", { children: jsx("i", { class: "xnote-icon-plus" }) })
3508
3643
  :
3509
3644
  jsxs("span", { children: [activeNode, jsx("i", { style: "font-size: 12px", class: "xnote-icon-more" })] }) }) }) }) }));
@@ -3527,7 +3662,7 @@ class LeftToolbarPlugin {
3527
3662
  nativeRenderer: new DomRenderer(),
3528
3663
  autoUpdate: true
3529
3664
  });
3530
- const viewDocument = injector.get(VIEW_DOCUMENT);
3665
+ const viewDocument = injector.get(VIEW_CONTAINER);
3531
3666
  const host = document.createElement('div');
3532
3667
  viewDocument.appendChild(host);
3533
3668
  this.app.mount(host);
@@ -3538,7 +3673,7 @@ class LeftToolbarPlugin {
3538
3673
  }
3539
3674
  }
3540
3675
 
3541
- var css$6 = undefined;
3676
+ var scopedId$6 = "vf-fee98b";
3542
3677
 
3543
3678
  let EditorService = class EditorService {
3544
3679
  constructor() {
@@ -3555,7 +3690,7 @@ const Toolbar = withAnnotation({
3555
3690
  providers: [RefreshService]
3556
3691
  }, function Toolbar() {
3557
3692
  const selection = inject(Selection);
3558
- const viewDocument = inject(VIEW_DOCUMENT);
3693
+ const viewDocument = inject(VIEW_CONTAINER);
3559
3694
  const bridge = inject(SelectionBridge);
3560
3695
  const textbus = inject(Textbus);
3561
3696
  const editorService = inject(EditorService);
@@ -3648,7 +3783,7 @@ const Toolbar = withAnnotation({
3648
3783
  mousedownSubscription.unsubscribe();
3649
3784
  mouseupSubscription.unsubscribe();
3650
3785
  });
3651
- return withScopedCSS(css$6, () => {
3786
+ return withScopedCSS(scopedId$6, () => {
3652
3787
  const p = viewPosition();
3653
3788
  return (jsxs("div", { class: "toolbar", ref: toolbarRef, style: {
3654
3789
  left: p.left + 'px',
@@ -3783,72 +3918,35 @@ class Matcher {
3783
3918
  }
3784
3919
  }
3785
3920
 
3786
- class ImageComponent extends Component {
3787
- static fromJSON(textbus, json) {
3788
- return new ImageComponent(textbus, Object.assign({}, json));
3789
- }
3790
- }
3791
- ImageComponent.type = ContentType.InlineComponent;
3792
- ImageComponent.componentName = 'ImageComponent';
3793
- function ImageView(props) {
3794
- const { name, state } = props.component;
3795
- const imageRef = createRef();
3796
- const readonly = useReadonly();
3797
- const output = useOutput();
3798
- return () => {
3799
- if (readonly() || output()) {
3800
- return (jsx("div", { class: "xnote-image", ref: props.rootRef, "data-component": name, children: jsx("img", { alt: "", src: state.src, style: {
3801
- width: state.width,
3802
- height: state.height
3803
- } }) }));
3804
- }
3805
- 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: {
3806
- width: state.width,
3807
- height: state.height
3808
- } }) }) }));
3809
- };
3810
- }
3811
- const imageComponentLoader = {
3812
- match(element) {
3813
- return element.tagName === 'IMG' || element.dataset.component === ImageComponent.componentName;
3814
- },
3815
- read(element, textbus) {
3816
- var _a;
3817
- return new ImageComponent(textbus, {
3818
- src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('img')) === null || _a === void 0 ? void 0 : _a.src) || ''
3819
- });
3820
- }
3821
- };
3822
-
3823
3921
  class RootComponent extends Component {
3824
3922
  constructor() {
3825
3923
  super(...arguments);
3826
3924
  this.onCompositionStart = new Subject();
3827
3925
  }
3828
3926
  static fromJSON(textbus, json) {
3829
- const heading = textbus.get(Registry).createSlot(json.heading);
3927
+ // const heading = textbus.get(Registry).createSlot(json.heading)
3830
3928
  const content = textbus.get(Registry).createSlot(json.content);
3831
3929
  return new RootComponent(textbus, {
3832
- heading,
3930
+ // heading,
3833
3931
  content
3834
3932
  });
3835
3933
  }
3836
3934
  setup() {
3837
- const textbus = useContext();
3838
- const selection = textbus.get(Selection);
3839
- onBreak(ev => {
3840
- if (ev.target === this.state.heading) {
3841
- const afterContent = ev.target.cut(ev.data.index);
3842
- const p = new ParagraphComponent(textbus, {
3843
- slot: afterContent
3844
- });
3845
- const body = this.state.content;
3846
- body.retain(0);
3847
- body.insert(p);
3848
- selection.setPosition(afterContent, 0);
3849
- ev.preventDefault();
3850
- }
3851
- });
3935
+ // const textbus = useContext()
3936
+ // const selection = textbus.get(Selection)
3937
+ // onBreak(ev => {
3938
+ // if (ev.target === this.state.heading) {
3939
+ // const afterContent = ev.target.cut(ev.data.index)
3940
+ // const p = new ParagraphComponent(textbus, {
3941
+ // slot: afterContent
3942
+ // })
3943
+ // const body = this.state.content
3944
+ // body.retain(0)
3945
+ // body.insert(p)
3946
+ // selection.setPosition(afterContent, 0)
3947
+ // ev.preventDefault()
3948
+ // }
3949
+ // })
3852
3950
  useBlockContent(this.state.content);
3853
3951
  onCompositionStart(ev => {
3854
3952
  this.onCompositionStart.next(ev);
@@ -3870,37 +3968,27 @@ RootComponent.componentName = 'RootComponent';
3870
3968
  RootComponent.type = ContentType.BlockComponent;
3871
3969
  function RootView(props) {
3872
3970
  const adapter = inject(DomAdapter);
3873
- const { heading, content } = props.component.state;
3971
+ const { content } = props.component.state;
3874
3972
  const ref = createDynamicRef(node => {
3875
- const sub = props.component.onCompositionStart.subscribe(ev => {
3876
- if (ev.target === heading) {
3877
- node.children[0].dataset.placeholder = '';
3878
- }
3879
- else {
3880
- node.children[1].dataset.placeholder = '';
3881
- }
3973
+ const sub = props.component.onCompositionStart.subscribe(() => {
3974
+ node.children[0].dataset.placeholder = '';
3882
3975
  });
3883
3976
  return () => {
3884
3977
  sub.unsubscribe();
3885
3978
  };
3886
3979
  });
3887
- onUpdated(() => {
3888
- props.component.afterCheck();
3889
- });
3980
+ // onUpdated(() => {
3981
+ // props.component.afterCheck()
3982
+ // })
3890
3983
  const readonly = useReadonly();
3891
3984
  return () => {
3892
3985
  const { rootRef } = props;
3893
- return (jsxs("div", { class: "xnote-root", ref: [rootRef, ref], children: [adapter.slotRender(heading, children => {
3894
- return (createVNode('div', {
3895
- class: 'xnote-title',
3896
- 'data-placeholder': heading.isEmpty ? '请输入标题' : ''
3897
- }, children));
3898
- }, readonly()), adapter.slotRender(content, children => {
3899
- return (createVNode('div', {
3900
- class: 'xnote-content',
3901
- 'data-placeholder': content.isEmpty ? '请输入内容' : ''
3902
- }, children));
3903
- }, readonly())] }));
3986
+ return (jsx("div", { class: "xnote-root", ref: [rootRef, ref], children: adapter.slotRender(content, children => {
3987
+ return (createVNode('div', {
3988
+ class: 'xnote-content',
3989
+ 'data-placeholder': content.isEmpty ? '请输入内容' : ''
3990
+ }, children));
3991
+ }, readonly()) }));
3904
3992
  };
3905
3993
  }
3906
3994
  const rootComponentLoader = {
@@ -3925,7 +4013,7 @@ const rootComponentLoader = {
3925
4013
  }
3926
4014
  };
3927
4015
 
3928
- var css$5 = undefined;
4016
+ var scopedId$5 = "vf-681de2";
3929
4017
 
3930
4018
  let TableService = class TableService {
3931
4019
  constructor() {
@@ -4012,12 +4100,12 @@ function ResizeColumn(props) {
4012
4100
  });
4013
4101
  return () => sub.unsubscribe();
4014
4102
  });
4015
- return withScopedCSS(css$5, () => {
4103
+ return withScopedCSS(scopedId$5, () => {
4016
4104
  return jsx("div", { ref: dragLineRef, class: ['drag-line'] });
4017
4105
  });
4018
4106
  }
4019
4107
 
4020
- var css$4 = undefined;
4108
+ var scopedId$4 = "vf-d64cf9";
4021
4109
 
4022
4110
  function TopBar(props) {
4023
4111
  const editorService = inject(EditorService);
@@ -4085,7 +4173,7 @@ function TopBar(props) {
4085
4173
  s.unsubscribe();
4086
4174
  });
4087
4175
  const deleteIndex = createSignal(null);
4088
- return withScopedCSS(css$4, () => {
4176
+ return withScopedCSS(scopedId$4, () => {
4089
4177
  const { state, tableSelection } = props.component;
4090
4178
  const position = tableSelection();
4091
4179
  return (jsx("div", { class: ['top-bar', {
@@ -4138,7 +4226,7 @@ function TopBar(props) {
4138
4226
  });
4139
4227
  }
4140
4228
 
4141
- var css$3 = undefined;
4229
+ var scopedId$3 = "vf-b1149b";
4142
4230
 
4143
4231
  function Scroll(props) {
4144
4232
  const scrollRef = createRef();
@@ -4170,7 +4258,7 @@ function Scroll(props) {
4170
4258
  draft.rightEnd = el.scrollLeft === el.scrollWidth - el.offsetWidth;
4171
4259
  });
4172
4260
  });
4173
- return withScopedCSS(css$3, () => {
4261
+ return withScopedCSS(scopedId$3, () => {
4174
4262
  return jsx("div", { ref: [scrollRef, props.scrollRef], class: ['scroll-container', {
4175
4263
  'left-end': showShadow().leftEnd,
4176
4264
  'right-end': showShadow().rightEnd,
@@ -4182,7 +4270,7 @@ function Scroll(props) {
4182
4270
  });
4183
4271
  }
4184
4272
 
4185
- var css$2 = undefined;
4273
+ var scopedId$2 = "vf-ef93c0";
4186
4274
 
4187
4275
  function LeftBar(props) {
4188
4276
  const editorService = inject(EditorService);
@@ -4256,7 +4344,7 @@ function LeftBar(props) {
4256
4344
  textbus.focus();
4257
4345
  });
4258
4346
  }
4259
- return withScopedCSS(css$2, () => {
4347
+ return withScopedCSS(scopedId$2, () => {
4260
4348
  const { state, tableSelection } = props.component;
4261
4349
  const position = tableSelection();
4262
4350
  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) => {
@@ -4304,7 +4392,7 @@ function LeftBar(props) {
4304
4392
  });
4305
4393
  }
4306
4394
 
4307
- var css$1 = undefined;
4395
+ var scopedId$1 = "vf-d4c4a9";
4308
4396
 
4309
4397
  function sum(numbers) {
4310
4398
  return numbers.reduce((a, b) => a + b, 0);
@@ -4337,7 +4425,7 @@ function ResizeRow(props) {
4337
4425
  });
4338
4426
  return () => sub.unsubscribe();
4339
4427
  });
4340
- return withScopedCSS(css$1, () => {
4428
+ return withScopedCSS(scopedId$1, () => {
4341
4429
  return jsx("div", { ref: dragLineRef, style: {
4342
4430
  display: styles().visible ? 'block' : 'none',
4343
4431
  top: styles().top + 'px',
@@ -4346,7 +4434,7 @@ function ResizeRow(props) {
4346
4434
  });
4347
4435
  }
4348
4436
 
4349
- var css = undefined;
4437
+ var scopedId = "vf-4a5ad1";
4350
4438
 
4351
4439
  function SelectionMask(props) {
4352
4440
  const [styles, updateStyles] = useProduce({
@@ -4399,7 +4487,7 @@ function SelectionMask(props) {
4399
4487
  onUnmounted(() => {
4400
4488
  s.unsubscribe();
4401
4489
  });
4402
- return withScopedCSS(css, () => {
4490
+ return withScopedCSS(scopedId, () => {
4403
4491
  const style = styles();
4404
4492
  return (jsx("div", { class: "mask", style: {
4405
4493
  display: style.visible ? 'block' : 'none',
@@ -4697,48 +4785,8 @@ function autoComplete(table) {
4697
4785
  });
4698
4786
  }
4699
4787
 
4700
- class VideoComponent extends Component {
4701
- static fromJSON(textbus, json) {
4702
- return new VideoComponent(textbus, Object.assign({}, json));
4703
- }
4704
- setup() {
4705
- //
4706
- }
4707
- }
4708
- VideoComponent.type = ContentType.InlineComponent;
4709
- VideoComponent.componentName = 'VideoComponent';
4710
- function VideoView(props) {
4711
- const { name, state } = props.component;
4712
- const videoRef = createRef();
4713
- const readonly = useReadonly();
4714
- const output = useOutput();
4715
- return () => {
4716
- if (readonly() || output()) {
4717
- return (jsx("div", { class: "xnote-video", "data-component": name, children: jsx("video", { ref: videoRef, src: state.src, style: {
4718
- width: state.width,
4719
- height: state.height
4720
- } }) }));
4721
- }
4722
- 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: {
4723
- width: state.width,
4724
- height: state.height
4725
- } }) }) }));
4726
- };
4727
- }
4728
- const videoComponentLoader = {
4729
- match(element) {
4730
- return element.tagName === 'IMG' || element.dataset.component === VideoComponent.componentName;
4731
- },
4732
- read(element, textbus) {
4733
- var _a;
4734
- return new VideoComponent(textbus, {
4735
- src: element instanceof HTMLImageElement ? element.src : ((_a = element.querySelector('video')) === null || _a === void 0 ? void 0 : _a.src) || ''
4736
- });
4737
- }
4738
- };
4739
-
4740
- function createXNote(host_1) {
4741
- return __awaiter(this, arguments, void 0, function* (host, config = {}) {
4788
+ class Editor extends Textbus {
4789
+ constructor(editorConfig) {
4742
4790
  const adapter = new ViewflyAdapter({
4743
4791
  [ParagraphComponent.componentName]: ParagraphView,
4744
4792
  [RootComponent.componentName]: RootView,
@@ -4762,38 +4810,9 @@ function createXNote(host_1) {
4762
4810
  app.destroy();
4763
4811
  };
4764
4812
  });
4765
- const vDomAdapter = new ViewflyVDomAdapter({
4766
- [ParagraphComponent.componentName]: ParagraphView,
4767
- [RootComponent.componentName]: RootView,
4768
- [BlockquoteComponent.componentName]: BlockquoteView,
4769
- [TodolistComponent.componentName]: TodolistView,
4770
- [SourceCodeComponent.componentName]: SourceCodeView,
4771
- [TableComponent.componentName]: TableComponentView,
4772
- [HighlightBoxComponent.componentName]: HighlightBoxView,
4773
- [ListComponent.componentName]: ListComponentView,
4774
- [ImageComponent.componentName]: ImageView,
4775
- [VideoComponent.componentName]: VideoView
4776
- }, (host, root, injector) => {
4777
- const appInjector = new ReflectiveInjector(injector, [{
4778
- provide: OutputInjectionToken,
4779
- useValue: true
4780
- }, {
4781
- provide: DomAdapter,
4782
- useFactory() {
4783
- return vDomAdapter;
4784
- }
4785
- }]);
4786
- const app = createApp(root, {
4787
- context: appInjector,
4788
- nativeRenderer: new HTMLRenderer()
4789
- }).mount(host);
4790
- return () => {
4791
- app.destroy();
4792
- };
4793
- });
4794
4813
  const browserModule = new BrowserModule({
4795
- renderTo() {
4796
- return host;
4814
+ renderTo: () => {
4815
+ return this.host;
4797
4816
  },
4798
4817
  adapter,
4799
4818
  componentLoaders: [
@@ -4826,15 +4845,39 @@ function createXNote(host_1) {
4826
4845
  ]
4827
4846
  });
4828
4847
  const modules = [browserModule];
4829
- if (config.collaborateConfig) {
4830
- modules.push(new CollaborateModule(config.collaborateConfig));
4848
+ if (editorConfig.collaborateConfig) {
4849
+ modules.push(new CollaborateModule(editorConfig.collaborateConfig));
4831
4850
  }
4832
- const textbus = new Textbus({
4833
- additionalAdapters: [vDomAdapter],
4834
- zenCoding: true,
4835
- readonly: config.readonly,
4836
- imports: modules,
4837
- components: [
4851
+ const vDomAdapter = new ViewflyVDomAdapter({
4852
+ [ParagraphComponent.componentName]: ParagraphView,
4853
+ [RootComponent.componentName]: RootView,
4854
+ [BlockquoteComponent.componentName]: BlockquoteView,
4855
+ [TodolistComponent.componentName]: TodolistView,
4856
+ [SourceCodeComponent.componentName]: SourceCodeView,
4857
+ [TableComponent.componentName]: TableComponentView,
4858
+ [HighlightBoxComponent.componentName]: HighlightBoxView,
4859
+ [ListComponent.componentName]: ListComponentView,
4860
+ [ImageComponent.componentName]: ImageView,
4861
+ [VideoComponent.componentName]: VideoView
4862
+ }, (host, root, injector) => {
4863
+ const appInjector = new ReflectiveInjector(injector, [{
4864
+ provide: OutputInjectionToken,
4865
+ useValue: true
4866
+ }, {
4867
+ provide: DomAdapter,
4868
+ useFactory: () => {
4869
+ return vDomAdapter;
4870
+ }
4871
+ }]);
4872
+ const app = createApp(root, {
4873
+ context: appInjector,
4874
+ nativeRenderer: new HTMLRenderer()
4875
+ }).mount(host);
4876
+ return () => {
4877
+ app.destroy();
4878
+ };
4879
+ });
4880
+ super(Object.assign({ additionalAdapters: [vDomAdapter], imports: modules, components: [
4838
4881
  ImageComponent,
4839
4882
  ParagraphComponent,
4840
4883
  RootComponent,
@@ -4845,8 +4888,7 @@ function createXNote(host_1) {
4845
4888
  HighlightBoxComponent,
4846
4889
  ListComponent,
4847
4890
  VideoComponent
4848
- ],
4849
- formatters: [
4891
+ ], formatters: [
4850
4892
  backgroundColorFormatter,
4851
4893
  boldFormatter,
4852
4894
  codeFormatter,
@@ -4857,18 +4899,14 @@ function createXNote(host_1) {
4857
4899
  linkFormatter,
4858
4900
  strikeThroughFormatter,
4859
4901
  underlineFormatter
4860
- ],
4861
- attributes: [
4902
+ ], attributes: [
4862
4903
  headingAttr,
4863
4904
  textAlignAttr,
4864
4905
  textIndentAttr
4865
- ],
4866
- providers: [],
4867
- plugins: [
4906
+ ], plugins: [
4868
4907
  new LeftToolbarPlugin(),
4869
4908
  new ToolbarPlugin(),
4870
- ],
4871
- onAfterStartup(textbus) {
4909
+ ], onAfterStartup(textbus) {
4872
4910
  registerBoldShortcut(textbus);
4873
4911
  registerCodeShortcut(textbus);
4874
4912
  registerItalicShortcut(textbus);
@@ -4877,32 +4915,34 @@ function createXNote(host_1) {
4877
4915
  registerHeadingShortcut(textbus);
4878
4916
  registerTextAlignShortcut(textbus);
4879
4917
  registerTextIndentShortcut(textbus);
4880
- }
4881
- });
4918
+ } }, editorConfig));
4919
+ this.editorConfig = editorConfig;
4920
+ this.translator = new OutputTranslator();
4921
+ this.vDomAdapter = vDomAdapter;
4922
+ }
4923
+ mount(host) {
4924
+ this.host = host;
4882
4925
  let rootComp;
4926
+ const config = this.editorConfig;
4883
4927
  if (config.content) {
4884
- const parser = textbus.get(Parser);
4928
+ const parser = this.get(Parser);
4885
4929
  const doc = parser.parseDoc(config.content, rootComponentLoader);
4886
- rootComp = doc instanceof Component ? doc : new RootComponent(textbus, {
4887
- heading: new Slot([ContentType.Text]),
4930
+ rootComp = doc instanceof Component ? doc : new RootComponent(this, {
4931
+ // heading: new Slot([ContentType.Text]),
4888
4932
  content: doc
4889
4933
  });
4890
4934
  }
4891
4935
  else {
4892
- rootComp = new RootComponent(textbus, {
4893
- heading: new Slot([ContentType.Text]),
4936
+ rootComp = new RootComponent(this, {
4937
+ // heading: new Slot([ContentType.Text]),
4894
4938
  content: new Slot([ContentType.Text, ContentType.InlineComponent, ContentType.BlockComponent])
4895
4939
  });
4896
4940
  }
4897
- yield textbus.render(rootComp);
4898
- const translator = new OutputTranslator();
4899
- return {
4900
- textbus,
4901
- getHTML() {
4902
- return translator.transform(vDomAdapter.host);
4903
- }
4904
- };
4905
- });
4941
+ return this.render(rootComp);
4942
+ }
4943
+ getHTML() {
4944
+ return this.translator.transform(this.vDomAdapter.host);
4945
+ }
4906
4946
  }
4907
4947
 
4908
- 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 };
4948
+ 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 };