Skip to content

Commit

Permalink
Revert "feat(core): remove slate-children/slate-leaves/SlateChildren/…
Browse files Browse the repository at this point in the history
…SlateLeaves"
  • Loading branch information
pubuzhixing8 committed May 30, 2024
1 parent d884a25 commit e2cb948
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-buttons-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"slate-angular": patch
---

Revert "feat(core): remove slate-children/slate-leaves/SlateChildren/SlateLeaves"
19 changes: 19 additions & 0 deletions packages/src/components/children/children.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Descendant } from 'slate';
import { SlateChildrenContext, SlateViewContext } from '../../view/context';
import { ViewContainer } from '../../view/container';
import { NgFor } from '@angular/common';

@Component({
selector: 'slate-children',
template: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true
})
export class SlateChildren extends ViewContainer<any> {
@Input() children: Descendant[];

@Input() context: SlateChildrenContext;

@Input() viewContext: SlateViewContext;
}
5 changes: 3 additions & 2 deletions packages/src/components/editable/editable.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { SlateChildrenContext, SlateViewContext } from '../../view/context';
import { ComponentType, ViewType } from '../../types/view';
import { HistoryEditor } from 'slate-history';
import { isDecoratorRangeListEqual } from '../../utils';
import { isDecoratorRangeListEqual, check, normalize } from '../../utils';
import { SlatePlaceholder } from '../../types/feature';
import { restoreDom } from '../../utils/restore-dom';
import { SlateChildren } from '../children/children.component';
import { SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN } from '../element/default-element.component.token';
import { SLATE_DEFAULT_TEXT_COMPONENT_TOKEN, SLATE_DEFAULT_VOID_TEXT_COMPONENT_TOKEN } from '../text/token';
import { SlateVoidText } from '../text/void-text.component';
Expand Down Expand Up @@ -108,7 +109,7 @@ const forceOnDOMPaste = IS_SAFARI;
}
],
standalone: true,
imports: [SlateStringTemplate]
imports: [SlateChildren, SlateStringTemplate]
})
export class SlateEditable implements OnInit, OnChanges, OnDestroy, AfterViewChecked, DoCheck {
viewContext: SlateViewContext;
Expand Down
4 changes: 3 additions & 1 deletion packages/src/components/element/default-element.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { BaseElementComponent } from '../../view/base';
import { SlateChildren } from '../children/children.component';

@Component({
selector: 'div[slateDefaultElement]',
template: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true
standalone: true,
imports: [SlateChildren]
})
export class SlateDefaultElement extends BaseElementComponent {}
4 changes: 3 additions & 1 deletion packages/src/components/element/element.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { BaseElementComponent } from '../../view/base';
import { SlateChildren } from '../children/children.component';

@Component({
selector: '[slateElement]',
template: '<ng-content></ng-content>',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true
standalone: true,
imports: [SlateChildren]
})
export class SlateElement extends BaseElementComponent {}
30 changes: 30 additions & 0 deletions packages/src/components/leaves/leaves.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
Input,
OnChanges,
OnInit,
QueryList,
SimpleChanges,
ViewChildren
} from '@angular/core';
import { Text } from 'slate';
import { SlateLeafContext, SlateTextContext } from '../../view/context';
import { ViewContainer } from '../../view/container';
import { NgFor } from '@angular/common';

@Component({
selector: 'slate-leaves',
template: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [NgFor]
})
export class SlateLeaves extends ViewContainer<any> {
initialized = false;
leafContexts: SlateLeafContext[];
leaves: Text[];

@Input() context: SlateTextContext;
}
4 changes: 3 additions & 1 deletion packages/src/components/text/default-text.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { BaseTextComponent } from '../../view/base';
import { SlateLeaves } from '../leaves/leaves.component';

@Component({
selector: 'span[slateDefaultText]',
Expand All @@ -8,6 +9,7 @@ import { BaseTextComponent } from '../../view/base';
host: {
'data-slate-node': 'text'
},
standalone: true
standalone: true,
imports: [SlateLeaves]
})
export class SlateDefaultText extends BaseTextComponent {}
5 changes: 4 additions & 1 deletion packages/src/components/text/void-text.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component, ChangeDetectionStrategy, OnInit, OnChanges } from '@angular/core';
import { BaseTextComponent } from '../../view/base';
import { AngularEditor } from '../../plugins/angular-editor';
import { SlateLeaves } from '../leaves/leaves.component';

@Component({
selector: 'span[slateVoidText]',
Expand All @@ -10,7 +12,8 @@ import { BaseTextComponent } from '../../view/base';
class: 'slate-spacer',
'data-slate-node': 'text'
},
standalone: true
standalone: true,
imports: [SlateLeaves]
})
export class SlateVoidText extends BaseTextComponent implements OnInit, OnChanges {
ngOnInit() {
Expand Down
6 changes: 5 additions & 1 deletion packages/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { SlateElement } from './components/element/element.component';
import { SlateDefaultElement } from './components/element/default-element.component';
import { SlateString } from './components/string/string.component';
import { SlateStringTemplate } from './components/string/template.component';
import { SlateChildren } from './components/children/children.component';
import { SlateChildrenOutlet } from './components/children/children-outlet.component';
import { SlateBlockCard } from './components/block-card/block-card.component';
import { SlateDefaultLeaf } from './components/leaf/default-leaf.component';
import { SlateLeaves } from './components/leaves/leaves.component';
import { SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN } from './components/element/default-element.component.token';
import { SlateDefaultString } from './components/string/default-string.component';

Expand All @@ -23,12 +25,14 @@ import { SlateDefaultString } from './components/string/default-string.component
SlateDefaultText,
SlateString,
SlateStringTemplate,
SlateChildren,
SlateBlockCard,
SlateLeaves,
SlateDefaultLeaf,
SlateDefaultString,
SlateChildrenOutlet
],
exports: [SlateEditable, SlateChildrenOutlet, SlateElement, SlateString, SlateDefaultString],
exports: [SlateEditable, SlateChildren, SlateChildrenOutlet, SlateElement, SlateLeaves, SlateString, SlateDefaultString],
providers: [
{
provide: SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN,
Expand Down
2 changes: 2 additions & 0 deletions packages/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export * from './components/editable/editable.component';
export * from './components/element/element.component';
export * from './components/string/string.component';
export * from './components/string/default-string.component';
export * from './components/children/children.component';
export * from './components/children/children-outlet.component';
export * from './components/leaves/leaves.component';
export * from './module';
export * from './types/error';
export * from './view/base';
Expand Down

0 comments on commit e2cb948

Please sign in to comment.