@textbus/xnote 0.0.1-alpha.10 → 0.0.1-alpha.12

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.
@@ -647,14 +647,14 @@ function ParagraphView(props) {
647
647
  const output = useOutput();
648
648
  return () => {
649
649
  const slot = props.component.state.slot;
650
- return (jsx("div", { class: "xnote-paragraph", ref: props.rootRef, "data-component": ParagraphComponent.name, children: adapter.slotRender(slot, children => {
650
+ return (jsx("div", { class: "xnote-paragraph", ref: props.rootRef, "data-component": ParagraphComponent.componentName, children: adapter.slotRender(slot, children => {
651
651
  return (createVNode('p', null, children));
652
652
  }, readonly() || output()) }));
653
653
  };
654
654
  }
655
655
  const paragraphComponentLoader = {
656
656
  match(element) {
657
- return element.dataset.compoment === ParagraphComponent.name || /P|H[1-6]/.test(element.tagName);
657
+ return element.dataset.compoment === ParagraphComponent.componentName || /P|H[1-6]/.test(element.tagName);
658
658
  },
659
659
  read(element, textbus, slotParser) {
660
660
  const content = /P|H[1-6]/.test(element.tagName) ? element : element.children[0];
@@ -4042,7 +4042,7 @@ class RootComponent extends Component {
4042
4042
  });
4043
4043
  }
4044
4044
  setup() {
4045
- useBlockContent(this.state.content);
4045
+ useBlockContent((slot) => slot === this.state.content);
4046
4046
  onCompositionStart(ev => {
4047
4047
  this.onCompositionStart.next(ev);
4048
4048
  });
@@ -4065,7 +4065,7 @@ function RootView(props) {
4065
4065
  const output = useOutput();
4066
4066
  return () => {
4067
4067
  const { rootRef } = props;
4068
- return (jsx("div", { class: "xnote-root", ref: [rootRef, ref], children: adapter.slotRender(content, children => {
4068
+ return (jsx("div", { class: "xnote-root", ref: [rootRef, ref], "data-comopnent": props.component.name, children: adapter.slotRender(content, children => {
4069
4069
  return (createVNode('div', {
4070
4070
  class: 'xnote-content',
4071
4071
  'data-placeholder': content.isEmpty ? '请输入内容' : ''
@@ -4084,9 +4084,7 @@ const rootComponentLoader = {
4084
4084
  ContentType.Text
4085
4085
  ]), element).toDelta();
4086
4086
  const slot = new Slot([
4087
- ContentType.BlockComponent,
4088
- ContentType.InlineComponent,
4089
- ContentType.Text
4087
+ ContentType.BlockComponent
4090
4088
  ]);
4091
4089
  deltaToBlock(delta, textbus).forEach(i => {
4092
4090
  slot.insert(i);
@@ -4940,9 +4938,22 @@ class Editor extends Textbus {
4940
4938
  if (config.content) {
4941
4939
  const parser = this.get(Parser);
4942
4940
  const doc = parser.parseDoc(config.content, rootComponentLoader);
4943
- rootComp = doc instanceof Component ? doc : new RootComponent(this, {
4944
- content: doc
4945
- });
4941
+ if (doc instanceof Component) {
4942
+ rootComp = doc;
4943
+ }
4944
+ else {
4945
+ const content = new Slot([
4946
+ ContentType.BlockComponent
4947
+ ]);
4948
+ if (doc instanceof Slot) {
4949
+ deltaToBlock(doc.toDelta(), this).forEach(i => {
4950
+ content.insert(i);
4951
+ });
4952
+ }
4953
+ rootComp = new RootComponent(this, {
4954
+ content
4955
+ });
4956
+ }
4946
4957
  }
4947
4958
  else {
4948
4959
  rootComp = new RootComponent(this, {
package/bundles/index.js CHANGED
@@ -649,14 +649,14 @@ function ParagraphView(props) {
649
649
  const output = useOutput();
650
650
  return () => {
651
651
  const slot = props.component.state.slot;
652
- return (jsxRuntime.jsx("div", { class: "xnote-paragraph", ref: props.rootRef, "data-component": ParagraphComponent.name, children: adapter.slotRender(slot, children => {
652
+ return (jsxRuntime.jsx("div", { class: "xnote-paragraph", ref: props.rootRef, "data-component": ParagraphComponent.componentName, children: adapter.slotRender(slot, children => {
653
653
  return (core$1.createVNode('p', null, children));
654
654
  }, readonly() || output()) }));
655
655
  };
656
656
  }
657
657
  const paragraphComponentLoader = {
658
658
  match(element) {
659
- return element.dataset.compoment === ParagraphComponent.name || /P|H[1-6]/.test(element.tagName);
659
+ return element.dataset.compoment === ParagraphComponent.componentName || /P|H[1-6]/.test(element.tagName);
660
660
  },
661
661
  read(element, textbus, slotParser) {
662
662
  const content = /P|H[1-6]/.test(element.tagName) ? element : element.children[0];
@@ -4044,7 +4044,7 @@ class RootComponent extends core$1.Component {
4044
4044
  });
4045
4045
  }
4046
4046
  setup() {
4047
- useBlockContent(this.state.content);
4047
+ useBlockContent((slot) => slot === this.state.content);
4048
4048
  core$1.onCompositionStart(ev => {
4049
4049
  this.onCompositionStart.next(ev);
4050
4050
  });
@@ -4067,7 +4067,7 @@ function RootView(props) {
4067
4067
  const output = useOutput();
4068
4068
  return () => {
4069
4069
  const { rootRef } = props;
4070
- return (jsxRuntime.jsx("div", { class: "xnote-root", ref: [rootRef, ref], children: adapter.slotRender(content, children => {
4070
+ return (jsxRuntime.jsx("div", { class: "xnote-root", ref: [rootRef, ref], "data-comopnent": props.component.name, children: adapter.slotRender(content, children => {
4071
4071
  return (core$1.createVNode('div', {
4072
4072
  class: 'xnote-content',
4073
4073
  'data-placeholder': content.isEmpty ? '请输入内容' : ''
@@ -4086,9 +4086,7 @@ const rootComponentLoader = {
4086
4086
  core$1.ContentType.Text
4087
4087
  ]), element).toDelta();
4088
4088
  const slot = new core$1.Slot([
4089
- core$1.ContentType.BlockComponent,
4090
- core$1.ContentType.InlineComponent,
4091
- core$1.ContentType.Text
4089
+ core$1.ContentType.BlockComponent
4092
4090
  ]);
4093
4091
  deltaToBlock(delta, textbus).forEach(i => {
4094
4092
  slot.insert(i);
@@ -4942,9 +4940,22 @@ class Editor extends core$1.Textbus {
4942
4940
  if (config.content) {
4943
4941
  const parser = this.get(platformBrowser.Parser);
4944
4942
  const doc = parser.parseDoc(config.content, rootComponentLoader);
4945
- rootComp = doc instanceof core$1.Component ? doc : new RootComponent(this, {
4946
- content: doc
4947
- });
4943
+ if (doc instanceof core$1.Component) {
4944
+ rootComp = doc;
4945
+ }
4946
+ else {
4947
+ const content = new core$1.Slot([
4948
+ core$1.ContentType.BlockComponent
4949
+ ]);
4950
+ if (doc instanceof core$1.Slot) {
4951
+ deltaToBlock(doc.toDelta(), this).forEach(i => {
4952
+ content.insert(i);
4953
+ });
4954
+ }
4955
+ rootComp = new RootComponent(this, {
4956
+ content
4957
+ });
4958
+ }
4948
4959
  }
4949
4960
  else {
4950
4961
  rootComp = new RootComponent(this, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/xnote",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.12",
4
4
  "description": "Viewfly project.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -14,10 +14,10 @@
14
14
  "test": "echo \"Error: no test specified\" && exit 1"
15
15
  },
16
16
  "dependencies": {
17
- "@textbus/adapter-viewfly": "^4.0.0-alpha.49",
18
- "@textbus/collaborate": "^4.0.0-alpha.49",
19
- "@textbus/core": "^4.0.0-alpha.49",
20
- "@textbus/platform-browser": "^4.0.0-alpha.49",
17
+ "@textbus/adapter-viewfly": "^4.0.0-alpha.50",
18
+ "@textbus/collaborate": "^4.0.0-alpha.50",
19
+ "@textbus/core": "^4.0.0-alpha.50",
20
+ "@textbus/platform-browser": "^4.0.0-alpha.50",
21
21
  "@viewfly/core": "^1.0.0-alpha.4",
22
22
  "@viewfly/hooks": "^1.0.0-alpha.4",
23
23
  "@viewfly/platform-browser": "^1.0.0-alpha.4",