@textbus/adapter-viewfly 4.0.0-alpha.31 → 4.0.0-alpha.33

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 { JSXInternal, JSXNode, DynamicRef } from '@viewfly/core';
1
+ import { DynamicRef, JSXNode } from '@viewfly/core';
2
2
  import { Subject } from '@tanbo/stream';
3
3
  import { Component, Slot, VElement, VTextNode } from '@textbus/core';
4
4
  import { DomAdapter } from '@textbus/platform-browser';
@@ -31,7 +31,12 @@ class Adapter extends DomAdapter {
31
31
  isRoot = false;
32
32
  }
33
33
  onUpdated(() => {
34
+ this.componentRendingStack.pop();
34
35
  textbusComponent.changeMarker.rendered();
36
+ if (!this.componentRootElementCaches.get(textbusComponent)) {
37
+ // eslint-disable-next-line max-len
38
+ throw adapterError(`Component \`${textbusComponent.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`);
39
+ }
35
40
  });
36
41
  const component = props.component;
37
42
  const instance = components[key](props);
@@ -39,18 +44,14 @@ class Adapter extends DomAdapter {
39
44
  return () => {
40
45
  component.__slots__.length = 0;
41
46
  this.componentRendingStack.push(component);
42
- const vNode = instance();
43
- this.componentRendingStack.pop();
44
- return vNode;
47
+ return instance();
45
48
  };
46
49
  }
47
50
  const self = this;
48
51
  return Object.assign(Object.assign({}, instance), { $render() {
49
52
  component.__slots__.length = 0;
50
53
  self.componentRendingStack.push(component);
51
- const vNode = instance.$render();
52
- self.componentRendingStack.pop();
53
- return vNode;
54
+ return instance.$render();
54
55
  } });
55
56
  };
56
57
  });
@@ -82,6 +83,24 @@ class Adapter extends DomAdapter {
82
83
  this.slotRootVElementCaches.set(slot, vElement);
83
84
  const vNodeToJSX = (vNode) => {
84
85
  const children = [];
86
+ if (this.composition && this.composition.slot === slot) {
87
+ this.insertCompositionByIndex(slot, vNode, this.composition, () => {
88
+ const ref = createDynamicRef(node => {
89
+ this.compositionNode = node;
90
+ return () => {
91
+ this.compositionNode = null;
92
+ };
93
+ });
94
+ return new VElement('span', {
95
+ style: {
96
+ textDecoration: 'underline'
97
+ },
98
+ ref
99
+ }, [
100
+ new VTextNode(this.composition.text)
101
+ ]);
102
+ });
103
+ }
85
104
  for (let i = 0; i < vNode.children.length; i++) {
86
105
  const child = vNode.children[i];
87
106
  if (child instanceof VElement) {
@@ -97,6 +116,8 @@ class Adapter extends DomAdapter {
97
116
  }
98
117
  }
99
118
  }
119
+ const key = vNode.attrs.get('key');
120
+ vNode.attrs.delete('key');
100
121
  const props = Object.assign({}, (Array.from(vNode.attrs).reduce((a, b) => {
101
122
  a[b[0]] = b[1];
102
123
  return a;
@@ -113,7 +134,7 @@ class Adapter extends DomAdapter {
113
134
  if (children.length) {
114
135
  props.children = children;
115
136
  }
116
- return jsx(vNode.tagName, props);
137
+ return jsx(vNode.tagName, props, key);
117
138
  };
118
139
  const jsxNode = vNodeToJSX(vElement);
119
140
  const currentRef = jsxNode.props.ref;
package/bundles/index.js CHANGED
@@ -33,7 +33,12 @@ class Adapter extends platformBrowser.DomAdapter {
33
33
  isRoot = false;
34
34
  }
35
35
  core$1.onUpdated(() => {
36
+ this.componentRendingStack.pop();
36
37
  textbusComponent.changeMarker.rendered();
38
+ if (!this.componentRootElementCaches.get(textbusComponent)) {
39
+ // eslint-disable-next-line max-len
40
+ throw adapterError(`Component \`${textbusComponent.name}\` is not bound to rootRef, you must bind rootRef to the root element node of the component view.`);
41
+ }
37
42
  });
38
43
  const component = props.component;
39
44
  const instance = components[key](props);
@@ -41,18 +46,14 @@ class Adapter extends platformBrowser.DomAdapter {
41
46
  return () => {
42
47
  component.__slots__.length = 0;
43
48
  this.componentRendingStack.push(component);
44
- const vNode = instance();
45
- this.componentRendingStack.pop();
46
- return vNode;
49
+ return instance();
47
50
  };
48
51
  }
49
52
  const self = this;
50
53
  return Object.assign(Object.assign({}, instance), { $render() {
51
54
  component.__slots__.length = 0;
52
55
  self.componentRendingStack.push(component);
53
- const vNode = instance.$render();
54
- self.componentRendingStack.pop();
55
- return vNode;
56
+ return instance.$render();
56
57
  } });
57
58
  };
58
59
  });
@@ -84,6 +85,24 @@ class Adapter extends platformBrowser.DomAdapter {
84
85
  this.slotRootVElementCaches.set(slot, vElement);
85
86
  const vNodeToJSX = (vNode) => {
86
87
  const children = [];
88
+ if (this.composition && this.composition.slot === slot) {
89
+ this.insertCompositionByIndex(slot, vNode, this.composition, () => {
90
+ const ref = core$1.createDynamicRef(node => {
91
+ this.compositionNode = node;
92
+ return () => {
93
+ this.compositionNode = null;
94
+ };
95
+ });
96
+ return new core.VElement('span', {
97
+ style: {
98
+ textDecoration: 'underline'
99
+ },
100
+ ref
101
+ }, [
102
+ new core.VTextNode(this.composition.text)
103
+ ]);
104
+ });
105
+ }
87
106
  for (let i = 0; i < vNode.children.length; i++) {
88
107
  const child = vNode.children[i];
89
108
  if (child instanceof core.VElement) {
@@ -99,6 +118,8 @@ class Adapter extends platformBrowser.DomAdapter {
99
118
  }
100
119
  }
101
120
  }
121
+ const key = vNode.attrs.get('key');
122
+ vNode.attrs.delete('key');
102
123
  const props = Object.assign({}, (Array.from(vNode.attrs).reduce((a, b) => {
103
124
  a[b[0]] = b[1];
104
125
  return a;
@@ -115,7 +136,7 @@ class Adapter extends platformBrowser.DomAdapter {
115
136
  if (children.length) {
116
137
  props.children = children;
117
138
  }
118
- return core$1.jsx(vNode.tagName, props);
139
+ return core$1.jsx(vNode.tagName, props, key);
119
140
  };
120
141
  const jsxNode = vNodeToJSX(vElement);
121
142
  const currentRef = jsxNode.props.ref;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/adapter-viewfly",
3
- "version": "4.0.0-alpha.31",
3
+ "version": "4.0.0-alpha.33",
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,9 +26,9 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@tanbo/stream": "^1.2.3",
29
- "@textbus/core": "^4.0.0-alpha.31",
30
- "@textbus/platform-browser": "^4.0.0-alpha.31",
31
- "@viewfly/core": "^0.6.1"
29
+ "@textbus/core": "^4.0.0-alpha.33",
30
+ "@textbus/platform-browser": "^4.0.0-alpha.33",
31
+ "@viewfly/core": "^0.6.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@rollup/plugin-commonjs": "^23.0.2",
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/textbus/textbus.git/issues"
50
50
  },
51
- "gitHead": "54c13967d549e9c3795eb821d84ce3e811139630"
51
+ "gitHead": "5eb73f9a388d331946a8579aa6eaa23cc44bffe0"
52
52
  }