@textbus/adapter-viewfly 4.0.0-alpha.25 → 4.0.0-alpha.26

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,13 +1,13 @@
1
1
  import { JSXInternal, JSXNode, DynamicRef } from '@viewfly/core';
2
2
  import { Subject } from '@tanbo/stream';
3
- import { Component, ComponentInstance, ExtractComponentInstanceType, Slot, VElement, VTextNode } from '@textbus/core';
3
+ import { Component, Slot, VElement, VTextNode } from '@textbus/core';
4
4
  import { DomAdapter } from '@textbus/platform-browser';
5
- export interface ViewComponentProps<T extends Component = Component> {
6
- component: ExtractComponentInstanceType<T>;
5
+ export interface ViewComponentProps<T extends Component> {
6
+ component: T;
7
7
  rootRef: DynamicRef<HTMLElement>;
8
8
  }
9
9
  export interface ViewflyAdapterComponents {
10
- [key: string]: JSXInternal.ComponentSetup<ViewComponentProps>;
10
+ [key: string]: JSXInternal.ComponentSetup<ViewComponentProps<any>>;
11
11
  }
12
12
  /**
13
13
  * Textbus 桥接 [Viewfly](https://viewfly.org) 渲染能力适配器,用于在 Viewfly 项目中渲染 Textbus 数据
@@ -16,7 +16,8 @@ export declare class Adapter extends DomAdapter<JSXNode, JSXInternal.Element> {
16
16
  onViewUpdated: Subject<void>;
17
17
  private components;
18
18
  private componentRefs;
19
+ private componentRendingStack;
19
20
  constructor(components: ViewflyAdapterComponents, mount: (host: HTMLElement, root: JSXNode) => (void | (() => void)));
20
- componentRender(component: ComponentInstance): JSXInternal.ViewNode;
21
- slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | ComponentInstance>) => VElement, renderEnv?: any): JSXInternal.Element;
21
+ componentRender(component: Component): JSXInternal.ViewNode;
22
+ slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | Component>) => VElement, renderEnv?: any): JSXInternal.Element;
22
23
  }
@@ -13,6 +13,7 @@ class Adapter extends DomAdapter {
13
13
  this.onViewUpdated = new Subject();
14
14
  this.components = {};
15
15
  this.componentRefs = new WeakMap();
16
+ this.componentRendingStack = [];
16
17
  let isRoot = true;
17
18
  Object.keys(components).forEach(key => {
18
19
  this.components[key] = (props) => {
@@ -32,7 +33,25 @@ class Adapter extends DomAdapter {
32
33
  onUpdated(() => {
33
34
  textbusComponent.changeMarker.rendered();
34
35
  });
35
- return components[key](props);
36
+ const component = props.component;
37
+ const instance = components[key](props);
38
+ if (typeof instance === 'function') {
39
+ return () => {
40
+ component.__slots__.length = 0;
41
+ this.componentRendingStack.push(component);
42
+ const vNode = instance();
43
+ this.componentRendingStack.pop();
44
+ return vNode;
45
+ };
46
+ }
47
+ const self = this;
48
+ return Object.assign(Object.assign({}, instance), { $render() {
49
+ component.__slots__.length = 0;
50
+ self.componentRendingStack.push(component);
51
+ const vNode = instance.$render();
52
+ self.componentRendingStack.pop();
53
+ return vNode;
54
+ } });
36
55
  };
37
56
  });
38
57
  }
@@ -57,6 +76,8 @@ class Adapter extends DomAdapter {
57
76
  throw adapterError(`cannot found view component \`${component.name}\`!`);
58
77
  }
59
78
  slotRender(slot, slotHostRender, renderEnv) {
79
+ const context = this.componentRendingStack[this.componentRendingStack.length - 1];
80
+ context.__slots__.push(slot);
60
81
  const vElement = slot.toTree(slotHostRender, renderEnv);
61
82
  this.slotRootVElementCaches.set(slot, vElement);
62
83
  const vNodeToJSX = (vNode) => {
package/bundles/index.js CHANGED
@@ -15,6 +15,7 @@ class Adapter extends platformBrowser.DomAdapter {
15
15
  this.onViewUpdated = new stream.Subject();
16
16
  this.components = {};
17
17
  this.componentRefs = new WeakMap();
18
+ this.componentRendingStack = [];
18
19
  let isRoot = true;
19
20
  Object.keys(components).forEach(key => {
20
21
  this.components[key] = (props) => {
@@ -34,7 +35,25 @@ class Adapter extends platformBrowser.DomAdapter {
34
35
  core$1.onUpdated(() => {
35
36
  textbusComponent.changeMarker.rendered();
36
37
  });
37
- return components[key](props);
38
+ const component = props.component;
39
+ const instance = components[key](props);
40
+ if (typeof instance === 'function') {
41
+ return () => {
42
+ component.__slots__.length = 0;
43
+ this.componentRendingStack.push(component);
44
+ const vNode = instance();
45
+ this.componentRendingStack.pop();
46
+ return vNode;
47
+ };
48
+ }
49
+ const self = this;
50
+ return Object.assign(Object.assign({}, instance), { $render() {
51
+ component.__slots__.length = 0;
52
+ self.componentRendingStack.push(component);
53
+ const vNode = instance.$render();
54
+ self.componentRendingStack.pop();
55
+ return vNode;
56
+ } });
38
57
  };
39
58
  });
40
59
  }
@@ -59,6 +78,8 @@ class Adapter extends platformBrowser.DomAdapter {
59
78
  throw adapterError(`cannot found view component \`${component.name}\`!`);
60
79
  }
61
80
  slotRender(slot, slotHostRender, renderEnv) {
81
+ const context = this.componentRendingStack[this.componentRendingStack.length - 1];
82
+ context.__slots__.push(slot);
62
83
  const vElement = slot.toTree(slotHostRender, renderEnv);
63
84
  this.slotRootVElementCaches.set(slot, vElement);
64
85
  const vNodeToJSX = (vNode) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/adapter-viewfly",
3
- "version": "4.0.0-alpha.25",
3
+ "version": "4.0.0-alpha.26",
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.3",
29
- "@textbus/core": "^4.0.0-alpha.24",
30
- "@textbus/platform-browser": "^4.0.0-alpha.24",
29
+ "@textbus/core": "^4.0.0-alpha.26",
30
+ "@textbus/platform-browser": "^4.0.0-alpha.26",
31
31
  "@viewfly/core": "^0.6.0"
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": "645474a99de28e9b641535d31a028ae0b233266d"
51
+ "gitHead": "36aff3db9897ccd73ba4533972991d537778bd6e"
52
52
  }