Skip to content

Commit

Permalink
fix(block-card): replace exception when change
Browse files Browse the repository at this point in the history
  • Loading branch information
Maple13 committed Jun 28, 2021
1 parent 6b3dab3 commit d311ce9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
3 changes: 2 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = {
'docs',
'decorate',
'pretter',
'types'
'types',
'block-card'
]
]
}
Expand Down
41 changes: 22 additions & 19 deletions packages/src/components/descendant/descendant.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ChangeDetectionStrategy, Component, ComponentRef, Input, OnChanges, OnInit } from "@angular/core";
import { SlateBlockCardComponent } from "../block-card/block-card.component";
import { ChangeDetectionStrategy, Component, ComponentRef, Input, OnChanges, OnInit } from '@angular/core';
import { SlateBlockCardComponent } from '../block-card/block-card.component';
import { ViewContainerItem } from '../../view/container-item';
import { Descendant, Editor, Range, Element } from "slate";
import { SlateChildrenContext, SlateElementContext, SlateTextContext, SlateViewContext } from "../../view/context";
import { AngularEditor } from "../../plugins/angular-editor";
import { NODE_TO_INDEX, NODE_TO_PARENT } from "../../utils/weak-maps";
import { SlateDefaultElementComponent } from "../element/default-element.component";
import { BaseElementComponent, BaseTextComponent } from "../../view/base";
import { SlateDefaultTextComponent } from "../text/default-text.component";
import { SlateVoidTextComponent } from "../text/void-text.component";
import { isDecoratorRangeListEqual } from "../../utils";
import { ViewType } from "../../types/view";
import { SlateErrorCode } from "../../types";
import { Descendant, Editor, Range, Element } from 'slate';
import { SlateChildrenContext, SlateElementContext, SlateTextContext, SlateViewContext } from '../../view/context';
import { AngularEditor } from '../../plugins/angular-editor';
import { NODE_TO_INDEX, NODE_TO_PARENT } from '../../utils/weak-maps';
import { SlateDefaultElementComponent } from '../element/default-element.component';
import { BaseElementComponent, BaseTextComponent } from '../../view/base';
import { SlateDefaultTextComponent } from '../text/default-text.component';
import { SlateVoidTextComponent } from '../text/void-text.component';
import { isDecoratorRangeListEqual } from '../../utils';
import { ViewType } from '../../types/view';
import { SlateErrorCode } from '../../types';

@Component({
selector: 'slate-descendant',
Expand Down Expand Up @@ -72,8 +72,11 @@ export class SlateDescendantComponent extends ViewContainerItem<SlateElementCont
}
const rootNodes = this.rootNodes;
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(SlateBlockCardComponent);
this.blockCardComponentRef = this.viewContainerRef.createComponent<SlateBlockCardComponent>(componentFactory, null, null);
this.blockCardComponentRef = this.viewContainerRef.createComponent(componentFactory, null, null);
this.blockCardComponentRef.instance.initializeCenter(rootNodes);

const firstRootNode = rootNodes[0];
firstRootNode.replaceWith(this.blockCardComponentRef.instance.nativeElement);
}

getCommonContext(): { selection: Range; decorations: Range[] } {
Expand Down Expand Up @@ -110,7 +113,7 @@ export class SlateDescendantComponent extends ViewContainerItem<SlateElementCont
'data-slate-key': key.id
},
decorate: this.context.decorate
}
};
if (isInline) {
elementContext.attributes['data-slate-inline'] = true;
}
Expand All @@ -127,7 +130,7 @@ export class SlateDescendantComponent extends ViewContainerItem<SlateElementCont
isLast: isLeafBlock && this.index === this.context.parent.children.length - 1,
parent: this.context.parent as Element,
text: this.descendant
}
};
return textContext;
}
}
Expand All @@ -150,7 +153,7 @@ export class SlateDescendantComponent extends ViewContainerItem<SlateElementCont
(!!prev.selection &&
!!next.selection &&
Range.equals(prev.selection, next.selection)))
)
);
}

memoizedTextContext(prev: SlateTextContext, next: SlateTextContext) {
Expand All @@ -159,7 +162,7 @@ export class SlateDescendantComponent extends ViewContainerItem<SlateElementCont
next.isLast === prev.isLast &&
next.text === prev.text &&
isDecoratorRangeListEqual(next.decorations, prev.decorations)
)
);
}

memoizedContext(prev: SlateElementContext | SlateTextContext, next: SlateElementContext | SlateTextContext): boolean {
Expand All @@ -169,4 +172,4 @@ export class SlateDescendantComponent extends ViewContainerItem<SlateElementCont
return this.memoizedTextContext(prev as SlateTextContext, next as SlateTextContext);
}
}
}
}

0 comments on commit d311ce9

Please sign in to comment.