Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(group): fix group status rendering issue #WIK-15171 #838

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/five-apples-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@plait/common': patch
'@plait/core': patch
---

add onStable observable stream to emit callback after new children have rendered completely

render group state by onStable status to resolve group throw exception when group element is in front of contained elements
26 changes: 17 additions & 9 deletions packages/common/src/core/group.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { OnInit, OnDestroy, ViewContainerRef, ChangeDetectorRef, ChangeDetectionStrategy, Component } from '@angular/core';
import { OnInit, OnDestroy, ChangeDetectorRef, ChangeDetectionStrategy, Component, inject, DestroyRef } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import {
OnContextChanged,
PlaitBoard,
PlaitContextService,
PlaitGroup,
PlaitPluginElementContext,
getElementsInGroup,
Expand All @@ -21,7 +23,9 @@ import { CommonPluginElement } from './plugin-element';
})
export class GroupComponent extends CommonPluginElement<PlaitGroup, PlaitBoard>
implements OnInit, OnDestroy, OnContextChanged<PlaitGroup, PlaitBoard> {
constructor(protected cdr: ChangeDetectorRef) {
contextService = inject(PlaitContextService);

constructor(protected cdr: ChangeDetectorRef, private destroyRef: DestroyRef) {
super(cdr);
}

Expand All @@ -46,16 +50,20 @@ export class GroupComponent extends CommonPluginElement<PlaitGroup, PlaitBoard>
ngOnInit(): void {
super.ngOnInit();
this.initializeGenerator();
this.contextService
.onStable()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
const elementsInGroup = getElementsInGroup(this.board, this.element, false, true);
const isPartialSelectGroup =
elementsInGroup.some(item => isSelectedElementOrGroup(this.board, item)) &&
!elementsInGroup.every(item => isSelectedElementOrGroup(this.board, item));
this.groupGenerator.processDrawing(this.element, this.getElementG(), isPartialSelectGroup);
});
}

onContextChanged(
value: PlaitPluginElementContext<PlaitGroup, PlaitBoard>,
previous: PlaitPluginElementContext<PlaitGroup, PlaitBoard>
) {
const elementsInGroup = getElementsInGroup(this.board, value.element, false, true);
const isPartialSelectGroup =
elementsInGroup.some(item => isSelectedElementOrGroup(this.board, item)) &&
!elementsInGroup.every(item => isSelectedElementOrGroup(this.board, item));
this.groupGenerator.processDrawing(value.element, this.getElementG(), isPartialSelectGroup);
}
) {}
}
8 changes: 6 additions & 2 deletions packages/core/src/board/board.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
QueryList,
SimpleChanges,
ViewChild,
ViewContainerRef
ViewContainerRef,
inject
} from '@angular/core';
import rough from 'roughjs/bin/rough';
import { RoughSVG } from 'roughjs/bin/svg';
Expand Down Expand Up @@ -75,7 +76,7 @@ import { BoardTransforms } from '../transforms/board';
import { PlaitTheme } from '../interfaces/theme';
import { withHotkey } from '../plugins/with-hotkey';
import { HOST_CLASS_NAME } from '../constants';
import { PlaitContextService } from '../services/image-context.service';
import { PlaitContextService } from '../services/context.service';
import { isPreventTouchMove } from '../utils/touch';
import { ZOOM_STEP } from '../constants/zoom';
import { withRelatedFragment } from '../plugins/with-related-fragment';
Expand Down Expand Up @@ -178,6 +179,8 @@ export class PlaitBoardComponent implements BoardComponentInterface, OnInit, OnC

listRender!: ListRender;

contextService = inject(PlaitContextService);

constructor(
public cdr: ChangeDetectorRef,
public viewContainerRef: ViewContainerRef,
Expand Down Expand Up @@ -437,6 +440,7 @@ export class PlaitBoardComponent implements BoardComponentInterface, OnInit, OnC

private updateListRender() {
this.listRender.update(this.board.children, this.initializeChildrenContext());
this.contextService.nextStable();
}

private initializeChildrenContext(): PlaitChildrenContext {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/list-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const createPluginComponent = (
viewContainerRef: ViewContainerRef,
childrenContext: PlaitChildrenContext
) => {
const componentRef = viewContainerRef.createComponent(componentType);
const componentRef = viewContainerRef.createComponent(componentType, { injector: viewContainerRef.injector });
const instance = componentRef.instance;
instance.context = context;
componentRef.changeDetectorRef.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export * from './plugins/with-selection';
export * from './plugins/with-moving';
export * from './plugins/with-options';
export * from './testing';
export * from './services/image-context.service';
export * from './services/context.service';
export * from './utils/debug';
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Injectable } from '@angular/core';
import { ImageEntry } from '../interfaces';
import { Subject } from 'rxjs';

@Injectable()
export class PlaitContextService {
private _stable = new Subject();

private uploadingFiles: ImageEntry[] = [];

getUploadingFile(url: string) {
Expand All @@ -16,4 +19,12 @@ export class PlaitContextService {
removeUploadingFile(fileEntry: ImageEntry) {
this.uploadingFiles = this.uploadingFiles.filter(file => file.url !== fileEntry.url);
}

onStable() {
return this._stable.asObservable();
}

nextStable() {
this._stable.next('');
}
}
Loading