@textbus/platform-browser 4.0.0-alpha.0 → 4.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,58 @@
1
- import { ComponentInstance, Slot, ViewAdapter, NodeLocation, VElement } from '@textbus/core';
1
+ import { ComponentInstance, Slot, ViewAdapter, NodeLocation, VElement, VTextNode } from '@textbus/core';
2
2
  /**
3
- * Textbus PC 端浏览器渲染能力实现
3
+ * Textbus PC 端浏览器渲染能力桥接器抽象类,提供了 DOM 元素查询能力,具体渲染能力由各前端框架实现相应桥接
4
4
  */
5
- export declare abstract class DomAdapter<ViewComponent, ViewElement> extends ViewAdapter<ViewElement> {
5
+ export declare abstract class DomAdapter<ViewComponent, ViewElement> extends ViewAdapter {
6
6
  private mount;
7
7
  host: HTMLElement;
8
- protected componentRootElementCaches: WeakMap<ComponentInstance<unknown, unknown, unknown>, HTMLElement>;
8
+ protected componentRootElementCaches: {
9
+ set: {
10
+ (key: ComponentInstance<unknown, unknown, unknown>, value: HTMLElement): void;
11
+ (key: HTMLElement, value: ComponentInstance<unknown, unknown, unknown>): void;
12
+ };
13
+ get: {
14
+ (key: ComponentInstance<unknown, unknown, unknown>): HTMLElement;
15
+ (key: HTMLElement): ComponentInstance<unknown, unknown, unknown>;
16
+ };
17
+ remove: (key: HTMLElement | ComponentInstance<unknown, unknown, unknown>) => void;
18
+ };
9
19
  protected slotRootNativeElementCaches: {
10
20
  set: {
11
- (key: Slot<any>, value: Node): void;
12
- (key: Node, value: Slot<any>): void;
21
+ (key: Slot<any>, value: HTMLElement): void;
22
+ (key: HTMLElement, value: Slot<any>): void;
13
23
  };
14
24
  get: {
15
- (key: Slot<any>): Node;
16
- (key: Node): Slot<any>;
25
+ (key: Slot<any>): HTMLElement;
26
+ (key: HTMLElement): Slot<any>;
17
27
  };
18
- remove: (key: Node | Slot<any>) => void;
28
+ remove: (key: HTMLElement | Slot<any>) => void;
19
29
  };
20
30
  protected slotRootVElementCaches: WeakMap<Slot<any>, VElement>;
21
31
  protected constructor(mount: (host: HTMLElement, viewComponent: ViewComponent) => (void | (() => void)));
22
32
  render(rootComponent: ComponentInstance): void | (() => void);
23
33
  abstract componentRender(component: ComponentInstance): ViewComponent;
34
+ abstract slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | ComponentInstance>) => VElement): ViewElement;
24
35
  copy(): void;
36
+ /**
37
+ * 根据组件获取组件的根 DOM 节点
38
+ * @param component
39
+ */
25
40
  getNativeNodeByComponent(component: ComponentInstance): HTMLElement | null;
41
+ /**
42
+ * 根据 DOM 节点,获对对应的组件根节点,如传入的 DOM 节点不为组件的根节点,则返回 null
43
+ * @param node
44
+ */
45
+ getComponentByNativeNode(node: HTMLElement): ComponentInstance | null;
46
+ /**
47
+ * 根据插槽获取插槽的根 DOM 节点
48
+ * @param slot
49
+ */
26
50
  getNativeNodeBySlot(slot: Slot): HTMLElement | null;
51
+ /**
52
+ * 根据 DOM 节点,获对对应的插槽根节点,如传入的 DOM 节点不为插槽的根节点,则返回 null
53
+ * @param node
54
+ */
55
+ getSlotByNativeNode(node: HTMLElement): Slot | null;
27
56
  /**
28
57
  * 获取插槽内容节点集合
29
58
  * @param slot
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { Slot, ViewAdapter, createBidirectionalMapping, VElement, VTextNode, ComponentInstance, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander, Scheduler, NativeSelectionBridge } from '@textbus/core';
2
+ import { Slot, ViewAdapter, createBidirectionalMapping, ComponentInstance, VElement, VTextNode, Controller, Selection, RootComponentRef, ContentType, Event, invokeListener, Keyboard, Commander, Scheduler, NativeSelectionBridge } from '@textbus/core';
3
3
  import { InjectionToken, Injectable, Inject, Injector, Optional } from '@viewfly/core';
4
4
  import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
5
5
 
@@ -301,7 +301,7 @@ class Input {
301
301
  }
302
302
 
303
303
  /**
304
- * Textbus PC 端浏览器渲染能力实现
304
+ * Textbus PC 端浏览器渲染能力桥接器抽象类,提供了 DOM 元素查询能力,具体渲染能力由各前端框架实现相应桥接
305
305
  */
306
306
  class DomAdapter extends ViewAdapter {
307
307
  constructor(mount) {
@@ -322,7 +322,9 @@ class DomAdapter extends ViewAdapter {
322
322
  id: 'textbus-' + Number((Math.random() + '').substring(2)).toString(16)
323
323
  }
324
324
  });
325
- this.componentRootElementCaches = new WeakMap();
325
+ this.componentRootElementCaches = createBidirectionalMapping(a => {
326
+ return a instanceof ComponentInstance;
327
+ });
326
328
  this.slotRootNativeElementCaches = createBidirectionalMapping(a => {
327
329
  return a instanceof Slot;
328
330
  });
@@ -335,12 +337,34 @@ class DomAdapter extends ViewAdapter {
335
337
  copy() {
336
338
  document.execCommand('copy');
337
339
  }
340
+ /**
341
+ * 根据组件获取组件的根 DOM 节点
342
+ * @param component
343
+ */
338
344
  getNativeNodeByComponent(component) {
339
345
  return this.componentRootElementCaches.get(component) || null;
340
346
  }
347
+ /**
348
+ * 根据 DOM 节点,获对对应的组件根节点,如传入的 DOM 节点不为组件的根节点,则返回 null
349
+ * @param node
350
+ */
351
+ getComponentByNativeNode(node) {
352
+ return this.componentRootElementCaches.get(node) || null;
353
+ }
354
+ /**
355
+ * 根据插槽获取插槽的根 DOM 节点
356
+ * @param slot
357
+ */
341
358
  getNativeNodeBySlot(slot) {
342
359
  return this.slotRootNativeElementCaches.get(slot) || null;
343
360
  }
361
+ /**
362
+ * 根据 DOM 节点,获对对应的插槽根节点,如传入的 DOM 节点不为插槽的根节点,则返回 null
363
+ * @param node
364
+ */
365
+ getSlotByNativeNode(node) {
366
+ return this.slotRootNativeElementCaches.get(node) || null;
367
+ }
344
368
  /**
345
369
  * 获取插槽内容节点集合
346
370
  * @param slot
package/bundles/index.js CHANGED
@@ -303,7 +303,7 @@ class Input {
303
303
  }
304
304
 
305
305
  /**
306
- * Textbus PC 端浏览器渲染能力实现
306
+ * Textbus PC 端浏览器渲染能力桥接器抽象类,提供了 DOM 元素查询能力,具体渲染能力由各前端框架实现相应桥接
307
307
  */
308
308
  class DomAdapter extends core$1.ViewAdapter {
309
309
  constructor(mount) {
@@ -324,7 +324,9 @@ class DomAdapter extends core$1.ViewAdapter {
324
324
  id: 'textbus-' + Number((Math.random() + '').substring(2)).toString(16)
325
325
  }
326
326
  });
327
- this.componentRootElementCaches = new WeakMap();
327
+ this.componentRootElementCaches = core$1.createBidirectionalMapping(a => {
328
+ return a instanceof core$1.ComponentInstance;
329
+ });
328
330
  this.slotRootNativeElementCaches = core$1.createBidirectionalMapping(a => {
329
331
  return a instanceof core$1.Slot;
330
332
  });
@@ -337,12 +339,34 @@ class DomAdapter extends core$1.ViewAdapter {
337
339
  copy() {
338
340
  document.execCommand('copy');
339
341
  }
342
+ /**
343
+ * 根据组件获取组件的根 DOM 节点
344
+ * @param component
345
+ */
340
346
  getNativeNodeByComponent(component) {
341
347
  return this.componentRootElementCaches.get(component) || null;
342
348
  }
349
+ /**
350
+ * 根据 DOM 节点,获对对应的组件根节点,如传入的 DOM 节点不为组件的根节点,则返回 null
351
+ * @param node
352
+ */
353
+ getComponentByNativeNode(node) {
354
+ return this.componentRootElementCaches.get(node) || null;
355
+ }
356
+ /**
357
+ * 根据插槽获取插槽的根 DOM 节点
358
+ * @param slot
359
+ */
343
360
  getNativeNodeBySlot(slot) {
344
361
  return this.slotRootNativeElementCaches.get(slot) || null;
345
362
  }
363
+ /**
364
+ * 根据 DOM 节点,获对对应的插槽根节点,如传入的 DOM 节点不为插槽的根节点,则返回 null
365
+ * @param node
366
+ */
367
+ getSlotByNativeNode(node) {
368
+ return this.slotRootNativeElementCaches.get(node) || null;
369
+ }
346
370
  /**
347
371
  * 获取插槽内容节点集合
348
372
  * @param slot
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "4.0.0-alpha.0",
3
+ "version": "4.0.0-alpha.1",
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,8 +26,8 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@tanbo/stream": "^1.2.0",
29
- "@textbus/core": "^4.0.0-alpha.0",
30
- "@viewfly/core": "^0.1.0",
29
+ "@textbus/core": "^4.0.0-alpha.1",
30
+ "@viewfly/core": "^0.2.0",
31
31
  "reflect-metadata": "^0.1.13"
32
32
  },
33
33
  "devDependencies": {
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/textbus/textbus.git/issues"
50
50
  },
51
- "gitHead": "cf4fd289b73bc777124a32fe42bb58eba05a34f1"
51
+ "gitHead": "c66a476c5776f8cf719ebb0f9e7adebb391f82c1"
52
52
  }