-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(list-render): support custom elements to set the position of chil…
…dren elements
- Loading branch information
1 parent
214bc20
commit 834aa0c
Showing
17 changed files
with
327 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'slate-angular': patch | ||
--- | ||
|
||
support custom elements to set the position of children elements |
6 changes: 3 additions & 3 deletions
6
demo/app/components/editable-button/editable-button.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/src/components/children/children-outlet.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ChangeDetectionStrategy, Component, ElementRef } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'slate-children-outlet', | ||
template: ``, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true | ||
}) | ||
export class SlateChildrenOutlet { | ||
constructor(private elementRef: ElementRef<HTMLElement>) {} | ||
getNativeElement() { | ||
return this.elementRef.nativeElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<slate-string-template #templateComponent></slate-string-template> | ||
<slate-string-template #templateComponent></slate-string-template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { createEditor, Element } from 'slate'; | ||
import { SlateEditable } from '../components/editable/editable.component'; | ||
import { withAngular } from '../plugins/with-angular'; | ||
import { SlateChildrenOutlet } from '../components/children/children-outlet.component'; | ||
import { BaseElementComponent } from '../view/base'; | ||
|
||
const customType = 'custom-with-outlet'; | ||
|
||
@Component({ | ||
selector: 'editable-with-outlet', | ||
template: `<slate-editable | ||
[editor]="editor" | ||
[(ngModel)]="value" | ||
(ngModelChange)="ngModelChange()" | ||
[renderElement]="renderElement()" | ||
></slate-editable> ` | ||
}) | ||
export class EditableWithOutletComponent { | ||
editor = withAngular(createEditor()); | ||
|
||
value: Element[] = createDefaultDocument() as Element[]; | ||
|
||
@ViewChild(SlateEditable, { static: true }) | ||
editableComponent: SlateEditable; | ||
|
||
renderElement() { | ||
return (element: Element) => { | ||
if ((element.type as any) === customType) { | ||
return TestElementWithOutletComponent; | ||
} | ||
return null; | ||
}; | ||
} | ||
|
||
ngModelChange() {} | ||
|
||
constructor() {} | ||
} | ||
|
||
export function createDefaultDocument() { | ||
return [ | ||
{ | ||
type: customType, | ||
children: [ | ||
{ | ||
type: 'paragraph', | ||
children: [{ text: 'This is editable text!' }] | ||
} | ||
] | ||
} | ||
]; | ||
} | ||
|
||
@Component({ | ||
selector: 'div[test-element-with-outlet]', | ||
template: ` | ||
<div>before</div> | ||
<slate-children-outlet></slate-children-outlet> | ||
<div>after</div> | ||
`, | ||
host: { | ||
class: 'test-element-with-outlet' | ||
}, | ||
standalone: true, | ||
imports: [SlateChildrenOutlet] | ||
}) | ||
export class TestElementWithOutletComponent extends BaseElementComponent<any> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.