@textbus/platform-browser 4.0.0-alpha.12 → 4.0.0-alpha.13

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,4 +1,4 @@
1
- import { ComponentLiteral, Module } from '@textbus/core';
1
+ import { Component, ComponentInstance, ComponentLiteral, Module, Textbus } from '@textbus/core';
2
2
  import { Provider } from '@viewfly/core';
3
3
  import { AttributeLoader, ComponentLoader, FormatLoader } from './parser';
4
4
  import { DomAdapter } from './dom-adapter';
@@ -17,8 +17,6 @@ export interface ViewOptions {
17
17
  formatLoaders?: FormatLoader<any>[];
18
18
  /** 属性加载器 */
19
19
  attributeLoaders?: AttributeLoader<any>[];
20
- /** 默认内容 */
21
- content?: string | ComponentLiteral;
22
20
  /** 使用 contentEditable 作为编辑器控制可编辑范围 */
23
21
  useContentEditable?: boolean;
24
22
  }
@@ -28,6 +26,21 @@ export declare class BrowserModule implements Module {
28
26
  providers: Provider[];
29
27
  private workbench;
30
28
  constructor(host: HTMLElement, config: ViewOptions);
29
+ /**
30
+ * 解析 HTML 并返回一个组件实例
31
+ * @param html 要解析的 HTML
32
+ * @param rootComponentLoader 文档根组件加载器
33
+ * @param textbus
34
+ */
35
+ readDocumentByHTML(html: string, rootComponentLoader: ComponentLoader, textbus: Textbus): ComponentInstance;
36
+ /**
37
+ * 将组件数据解析到组件实例中
38
+ * @param data 要解析的 JSON 数据
39
+ * @param rootComponent 根组件
40
+ * @param textbus
41
+ */
42
+ readDocumentByComponentLiteral(data: ComponentLiteral, rootComponent: Component, textbus: Textbus): ComponentInstance;
43
+ onAfterStartup(textbus: Textbus): void;
31
44
  onDestroy(): void;
32
45
  private static createLayout;
33
46
  }
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { Slot, Textbus, ViewAdapter, createBidirectionalMapping, ComponentInstance, VElement, VTextNode, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander, Scheduler, NativeSelectionBridge, FocusManager } from '@textbus/core';
2
+ import { Slot, Textbus, ViewAdapter, createBidirectionalMapping, ComponentInstance, VElement, VTextNode, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander, Scheduler, makeError, NativeSelectionBridge, FocusManager, Registry } from '@textbus/core';
3
3
  import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
4
4
  import { InjectionToken, Injectable, Inject, Optional } from '@viewfly/core';
5
5
 
@@ -2295,6 +2295,7 @@ NativeInput = __decorate([
2295
2295
  Controller])
2296
2296
  ], NativeInput);
2297
2297
 
2298
+ const browserErrorFn = makeError('BrowserModule');
2298
2299
  class BrowserModule {
2299
2300
  constructor(host, config) {
2300
2301
  this.host = host;
@@ -2357,6 +2358,35 @@ class BrowserModule {
2357
2358
  this.workbench = wrapper;
2358
2359
  this.host.append(wrapper);
2359
2360
  }
2361
+ /**
2362
+ * 解析 HTML 并返回一个组件实例
2363
+ * @param html 要解析的 HTML
2364
+ * @param rootComponentLoader 文档根组件加载器
2365
+ * @param textbus
2366
+ */
2367
+ readDocumentByHTML(html, rootComponentLoader, textbus) {
2368
+ const parser = textbus.get(Parser);
2369
+ const doc = parser.parseDoc(html, rootComponentLoader);
2370
+ if (doc instanceof ComponentInstance) {
2371
+ return doc;
2372
+ }
2373
+ throw browserErrorFn('rootComponentLoader must return a component instance.');
2374
+ }
2375
+ /**
2376
+ * 将组件数据解析到组件实例中
2377
+ * @param data 要解析的 JSON 数据
2378
+ * @param rootComponent 根组件
2379
+ * @param textbus
2380
+ */
2381
+ readDocumentByComponentLiteral(data, rootComponent, textbus) {
2382
+ const registry = textbus.get(Registry);
2383
+ return registry.createComponentByFactory(data, rootComponent);
2384
+ }
2385
+ onAfterStartup(textbus) {
2386
+ if (this.config.autoFocus) {
2387
+ textbus.focus();
2388
+ }
2389
+ }
2360
2390
  onDestroy() {
2361
2391
  this.workbench.remove();
2362
2392
  }
package/bundles/index.js CHANGED
@@ -2297,6 +2297,7 @@ NativeInput = __decorate([
2297
2297
  core$1.Controller])
2298
2298
  ], NativeInput);
2299
2299
 
2300
+ const browserErrorFn = core$1.makeError('BrowserModule');
2300
2301
  class BrowserModule {
2301
2302
  constructor(host, config) {
2302
2303
  this.host = host;
@@ -2359,6 +2360,35 @@ class BrowserModule {
2359
2360
  this.workbench = wrapper;
2360
2361
  this.host.append(wrapper);
2361
2362
  }
2363
+ /**
2364
+ * 解析 HTML 并返回一个组件实例
2365
+ * @param html 要解析的 HTML
2366
+ * @param rootComponentLoader 文档根组件加载器
2367
+ * @param textbus
2368
+ */
2369
+ readDocumentByHTML(html, rootComponentLoader, textbus) {
2370
+ const parser = textbus.get(exports.Parser);
2371
+ const doc = parser.parseDoc(html, rootComponentLoader);
2372
+ if (doc instanceof core$1.ComponentInstance) {
2373
+ return doc;
2374
+ }
2375
+ throw browserErrorFn('rootComponentLoader must return a component instance.');
2376
+ }
2377
+ /**
2378
+ * 将组件数据解析到组件实例中
2379
+ * @param data 要解析的 JSON 数据
2380
+ * @param rootComponent 根组件
2381
+ * @param textbus
2382
+ */
2383
+ readDocumentByComponentLiteral(data, rootComponent, textbus) {
2384
+ const registry = textbus.get(core$1.Registry);
2385
+ return registry.createComponentByFactory(data, rootComponent);
2386
+ }
2387
+ onAfterStartup(textbus) {
2388
+ if (this.config.autoFocus) {
2389
+ textbus.focus();
2390
+ }
2391
+ }
2362
2392
  onDestroy() {
2363
2393
  this.workbench.remove();
2364
2394
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "4.0.0-alpha.12",
3
+ "version": "4.0.0-alpha.13",
4
4
  "description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@tanbo/stream": "^1.2.0",
29
- "@textbus/core": "^4.0.0-alpha.12",
29
+ "@textbus/core": "^4.0.0-alpha.13",
30
30
  "@viewfly/core": "^0.3.0",
31
31
  "reflect-metadata": "^0.1.13"
32
32
  },
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/textbus/textbus.git/issues"
50
50
  },
51
- "gitHead": "3c0456c3f13888fdeefb4ed307ad643644a05e43"
51
+ "gitHead": "625efd792f5cc6d8008cdb007b4fe2adf6701189"
52
52
  }