Skip to content

Commit

Permalink
Resolved #4484
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Aug 30, 2023
1 parent b3626c0 commit 96f844e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/survey-creator-core/src/components/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export class PageAdorner extends SurveyElementAdornerBase<PageModel> {
};
}
public dispose(): void {
super.dispose();
this.detachElement(this.page);
super.dispose();
this.onPropertyValueChangedCallback = undefined;
}
public get isGhost(): boolean {
Expand Down
1 change: 0 additions & 1 deletion packages/survey-creator-knockout/src/adorners/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export function createQuestionViewModel(
const implementor = new ImplementorBase(model);
ko.utils.domNodeDisposal.addDisposeCallback(componentInfo.element, () => {
implementor.dispose();
model.dispose();
});
return model;
}
Expand Down
27 changes: 14 additions & 13 deletions packages/survey-creator-knockout/src/string-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ import { LocalizableString } from "survey-core";
import { ImplementorBase } from "survey-knockout-ui";
const template = require("./string-editor.html");

function getEditorElement(element: HTMLElement) {
return (element.nextSibling as any).getElementsByClassName("sv-string-editor")[0];
};

export class StringEditorViewModel {
private implementor = undefined;
private baseModel: StringEditorViewModelBase;

getEditorElement = (element) => {
return element.nextSibling.getElementsByClassName(
"sv-string-editor"
)[0];
};

constructor(public locString: any, private creator: CreatorBase, element: any) {
this.baseModel = new StringEditorViewModelBase(locString, creator);
this.baseModel.getEditorElement = () => this.getEditorElement(element);
this.baseModel.getEditorElement = () => getEditorElement(element);
this.implementor = new ImplementorBase(this.baseModel);
this.focusEditor = () => {
this.getEditorElement(element).focus();
getEditorElement(element).focus();
};
this.baseModel.blurEditor = () => {
const editorElement = this.getEditorElement(element);
const editorElement = getEditorElement(element);
editorElement.blur();
editorElement.spellcheck = false;
};
Expand All @@ -34,7 +32,7 @@ export class StringEditorViewModel {
return locString;
}

public afterRender = ()=>{
public afterRender = () => {
this.baseModel.afterRender();
}

Expand All @@ -52,7 +50,7 @@ export class StringEditorViewModel {
return this.baseModel.placeholder;
}
public get contentEditable(): string {
return this.baseModel.contentEditable?"true":"false";
return this.baseModel.contentEditable ? "true" : "false";
}
public get characterCounter(): any {
return this.baseModel.characterCounter;
Expand Down Expand Up @@ -116,10 +114,12 @@ export class StringEditorViewModel {
public focusEditor: () => void;
public dispose(): void {
this.locString.onSearchChanged = undefined;
if (!!this.implementor) {
this.implementor.dispose();
this.implementor = undefined;
}
this.focusEditor = undefined;
this.baseModel.blurEditor = undefined;
this.implementor.dispose();
this.implementor = undefined;
this.baseModel.getEditorElement = undefined;
this.baseModel.dispose();
}
Expand Down Expand Up @@ -182,6 +182,7 @@ ko.components.register(editableStringRendererName, {

ko.utils.domNodeDisposal.addDisposeCallback(componentInfo.element, () => {
subscrib.dispose();
model.dispose();
});
return model;
},
Expand Down
16 changes: 10 additions & 6 deletions packages/survey-creator-react/src/StringEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ export class SurveyLocStringEditor extends CreatorModelElement<any, any> {
super(props);
this.state = { changed: 0 };
this.svStringEditorRef = React.createRef();
this.baseModel.getEditorElement = () => this.svStringEditorRef.current;
}
protected createModel(): void {
if (this.baseModel) {
this.baseModel.dispose();
}
this.baseModel = new StringEditorViewModelBase(this.locString, this.creator);
this.baseModel.blurEditor = () => {
this.svStringEditorRef.current.blur();
this.svStringEditorRef.current.spellcheck = false;
};
}
protected getUpdatedModelProps(): string[] {
return ["creator", "locString"];
Expand Down Expand Up @@ -46,7 +44,11 @@ export class SurveyLocStringEditor extends CreatorModelElement<any, any> {
public componentDidMount() {
super.componentDidMount();
if (!this.locString) return;
const self: SurveyLocStringEditor = this;
this.baseModel.getEditorElement = () => this.svStringEditorRef.current;
this.baseModel.blurEditor = () => {
this.svStringEditorRef.current.blur();
this.svStringEditorRef.current.spellcheck = false;
};
this.baseModel.afterRender();
this.locString.onStringChanged.add(this.onChangedHandler);
if (this.locString["__isEditing"]) {
Expand All @@ -60,6 +62,8 @@ export class SurveyLocStringEditor extends CreatorModelElement<any, any> {
}
public componentWillUnmount() {
super.componentWillUnmount();
this.baseModel.getEditorElement = undefined;
this.baseModel.blurEditor = undefined;
if (!this.locString) return;
this.locString.onStringChanged.remove(this.onChangedHandler);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/survey-creator-react/src/adorners/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class QuestionAdornerComponent extends CreatorModelElement<
protected rootRef: React.RefObject<HTMLDivElement>;

protected createModel(): void {
if (this.modelValue) {
this.modelValue.dispose();
}
this.modelValue = this.createQuestionViewModel();
}
protected createQuestionViewModel(): QuestionAdornerViewModel {
Expand Down

0 comments on commit 96f844e

Please sign in to comment.