@textbus/adapter-viewfly 4.0.0-alpha.2 → 4.0.0-alpha.20

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,10 +1,10 @@
1
- import { JSXComponent, JSXInternal, Ref } from '@viewfly/core';
1
+ import { JSXComponent, JSXInternal, DynamicRef } from '@viewfly/core';
2
2
  import { Subject } from '@tanbo/stream';
3
3
  import { Component, ComponentInstance, ExtractComponentInstanceType, Slot, VElement, VTextNode } from '@textbus/core';
4
4
  import { DomAdapter } from '@textbus/platform-browser';
5
5
  export interface ViewComponentProps<T extends Component = Component> {
6
6
  component: ExtractComponentInstanceType<T>;
7
- rootRef: Ref<HTMLElement>;
7
+ rootRef: DynamicRef<HTMLElement>;
8
8
  }
9
9
  export interface ViewflyAdapterComponents {
10
10
  [key: string]: JSXInternal.ComponentSetup<ViewComponentProps>;
@@ -18,5 +18,5 @@ export declare class Adapter extends DomAdapter<JSXComponent, JSXInternal.Elemen
18
18
  private componentRefs;
19
19
  constructor(components: ViewflyAdapterComponents, mount: (host: HTMLElement, root: JSXComponent) => (void | (() => void)));
20
20
  componentRender(component: ComponentInstance): JSXInternal.JSXNode;
21
- slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | ComponentInstance>) => VElement): JSXInternal.Element;
21
+ slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | ComponentInstance>) => VElement, renderEnv?: any): JSXInternal.Element;
22
22
  }
@@ -1,4 +1,4 @@
1
- import { provide, onUpdated, useRef, jsx, Ref } from '@viewfly/core';
1
+ import { getCurrentInstance, onUpdated, createDynamicRef, jsx, DynamicRef } from '@viewfly/core';
2
2
  import { Subject } from '@tanbo/stream';
3
3
  import { makeError, VElement, VTextNode, replaceEmpty } from '@textbus/core';
4
4
  import { DomAdapter } from '@textbus/platform-browser';
@@ -16,7 +16,7 @@ class Adapter extends DomAdapter {
16
16
  let isRoot = true;
17
17
  Object.keys(components).forEach(key => {
18
18
  this.components[key] = (props) => {
19
- const comp = provide([]);
19
+ const comp = getCurrentInstance();
20
20
  const textbusComponent = props.component;
21
21
  textbusComponent.changeMarker.onChange.subscribe(() => {
22
22
  if (textbusComponent.changeMarker.dirty) {
@@ -39,10 +39,9 @@ class Adapter extends DomAdapter {
39
39
  componentRender(component) {
40
40
  const comp = this.components[component.name] || this.components['*'];
41
41
  if (comp) {
42
- component.changeMarker.rendered();
43
42
  let ref = this.componentRefs.get(component);
44
43
  if (!ref) {
45
- ref = useRef(rootNode => {
44
+ ref = createDynamicRef(rootNode => {
46
45
  this.componentRootElementCaches.set(component, rootNode);
47
46
  return () => {
48
47
  this.componentRootElementCaches.remove(component);
@@ -57,8 +56,8 @@ class Adapter extends DomAdapter {
57
56
  }
58
57
  throw adapterError(`cannot found view component \`${component.name}\`!`);
59
58
  }
60
- slotRender(slot, slotHostRender) {
61
- const vElement = slot.toTree(slotHostRender);
59
+ slotRender(slot, slotHostRender, renderEnv) {
60
+ const vElement = slot.toTree(slotHostRender, renderEnv);
62
61
  this.slotRootVElementCaches.set(slot, vElement);
63
62
  const vNodeToJSX = (vNode) => {
64
63
  const children = [];
@@ -94,10 +93,13 @@ class Adapter extends DomAdapter {
94
93
  };
95
94
  const jsxNode = vNodeToJSX(vElement);
96
95
  const currentRef = jsxNode.props.ref;
97
- const ref = useRef(nativeNode => {
96
+ const ref = createDynamicRef(nativeNode => {
98
97
  this.slotRootNativeElementCaches.set(slot, nativeNode);
98
+ return () => {
99
+ this.slotRootNativeElementCaches.remove(slot);
100
+ };
99
101
  });
100
- if (currentRef instanceof Ref) {
102
+ if (currentRef instanceof DynamicRef) {
101
103
  jsxNode.props.ref = [currentRef, ref];
102
104
  }
103
105
  else if (Array.isArray(currentRef)) {
package/bundles/index.js CHANGED
@@ -18,7 +18,7 @@ class Adapter extends platformBrowser.DomAdapter {
18
18
  let isRoot = true;
19
19
  Object.keys(components).forEach(key => {
20
20
  this.components[key] = (props) => {
21
- const comp = core$1.provide([]);
21
+ const comp = core$1.getCurrentInstance();
22
22
  const textbusComponent = props.component;
23
23
  textbusComponent.changeMarker.onChange.subscribe(() => {
24
24
  if (textbusComponent.changeMarker.dirty) {
@@ -41,10 +41,9 @@ class Adapter extends platformBrowser.DomAdapter {
41
41
  componentRender(component) {
42
42
  const comp = this.components[component.name] || this.components['*'];
43
43
  if (comp) {
44
- component.changeMarker.rendered();
45
44
  let ref = this.componentRefs.get(component);
46
45
  if (!ref) {
47
- ref = core$1.useRef(rootNode => {
46
+ ref = core$1.createDynamicRef(rootNode => {
48
47
  this.componentRootElementCaches.set(component, rootNode);
49
48
  return () => {
50
49
  this.componentRootElementCaches.remove(component);
@@ -59,8 +58,8 @@ class Adapter extends platformBrowser.DomAdapter {
59
58
  }
60
59
  throw adapterError(`cannot found view component \`${component.name}\`!`);
61
60
  }
62
- slotRender(slot, slotHostRender) {
63
- const vElement = slot.toTree(slotHostRender);
61
+ slotRender(slot, slotHostRender, renderEnv) {
62
+ const vElement = slot.toTree(slotHostRender, renderEnv);
64
63
  this.slotRootVElementCaches.set(slot, vElement);
65
64
  const vNodeToJSX = (vNode) => {
66
65
  const children = [];
@@ -96,10 +95,13 @@ class Adapter extends platformBrowser.DomAdapter {
96
95
  };
97
96
  const jsxNode = vNodeToJSX(vElement);
98
97
  const currentRef = jsxNode.props.ref;
99
- const ref = core$1.useRef(nativeNode => {
98
+ const ref = core$1.createDynamicRef(nativeNode => {
100
99
  this.slotRootNativeElementCaches.set(slot, nativeNode);
100
+ return () => {
101
+ this.slotRootNativeElementCaches.remove(slot);
102
+ };
101
103
  });
102
- if (currentRef instanceof core$1.Ref) {
104
+ if (currentRef instanceof core$1.DynamicRef) {
103
105
  jsxNode.props.ref = [currentRef, ref];
104
106
  }
105
107
  else if (Array.isArray(currentRef)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/adapter-viewfly",
3
- "version": "4.0.0-alpha.2",
3
+ "version": "4.0.0-alpha.20",
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.0",
29
- "@textbus/core": "^4.0.0-alpha.1",
30
- "@textbus/platform-browser": "^4.0.0-alpha.1",
31
- "@viewfly/core": "^0.2.0"
29
+ "@textbus/core": "^4.0.0-alpha.20",
30
+ "@textbus/platform-browser": "^4.0.0-alpha.20",
31
+ "@viewfly/core": "^0.5.0"
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": "959ed2602f2e4ff05683f9c039f4dcbef93cee42"
51
+ "gitHead": "ed4e16ca55fe6fc4db88e9ba9e7bd2df30ef01b9"
52
52
  }