diff --git a/projects/common/util/copy.ts b/projects/common/util/copy.ts new file mode 100644 index 0000000000000000000000000000000000000000..f0ec6f1f4478c4245b147fa3c442a74d4ef22264 --- /dev/null +++ b/projects/common/util/copy.ts @@ -0,0 +1,11 @@ +export abstract class Copy { + static getCopy(objectToCopy: any): any { + if (objectToCopy instanceof Array) { + return [...objectToCopy]; + } + if (objectToCopy instanceof Object) { + return { ...objectToCopy }; + } + return objectToCopy; + } +} diff --git a/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-model-properties.component.ts b/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-model-properties.component.ts index 1f186a1df78f7fd0dfe4571d8fb33a531009bb7b..e657bf2b903f25c1020b6f67397860ef63755ae7 100644 --- a/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-model-properties.component.ts +++ b/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-model-properties.component.ts @@ -31,7 +31,10 @@ export class ElementModelPropertiesComponent { addOption(property: string, value: string): void { (this.combinedProperties[property] as string[]).push(value); - this.updateModel.emit({ property: property, value: this.combinedProperties[property] as string[] }); + this.updateModel.emit({ + property: property, + value: [...this.combinedProperties[property] as string[]] + }); } reorderOptions(property: string, event: CdkDragDrop<string[]>): void { diff --git a/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-properties.component.ts b/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-properties.component.ts index b5ecd7f96b8b2c9d52213c9d8f742eb7c3b5854e..ea49f58df839ec9b88db0ea08c31a55c733d5b4d 100644 --- a/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-properties.component.ts +++ b/projects/editor/src/app/components/unit-view/page-view/properties-panel/element-properties.component.ts @@ -70,9 +70,8 @@ export class ElementPropertiesComponent implements OnInit, OnDestroy { Object.keys(this.combinedProperties).forEach((property: keyof UIElement) => { if (Object.prototype.hasOwnProperty.call(flattenedSelectedElements[i], property)) { if (Array.isArray(flattenedSelectedElements[i][property])) { - if (flattenedSelectedElements[i][property]!.toString() === this.combinedProperties[property]!.toString()) { - // @ts-ignore TODO - flattenedSelectedElements[property] = flattenedSelectedElements[i][property]; + if (flattenedSelectedElements[i][property]?.toString() === this.combinedProperties[property]?.toString()) { + this.combinedProperties[property] = flattenedSelectedElements[i][property]; } } if (flattenedSelectedElements[i][property] !== this.combinedProperties[property]) { diff --git a/projects/editor/src/app/services/unit.service.ts b/projects/editor/src/app/services/unit.service.ts index 545bbd872af3b02685797070df48349c819d15c9..a4ed699fa7665598760fbbcf5cc59785de350068 100644 --- a/projects/editor/src/app/services/unit.service.ts +++ b/projects/editor/src/app/services/unit.service.ts @@ -25,6 +25,7 @@ import { LikertElementRow } from '../../../../common/ui-elements/likert/likert-e import { SelectionService } from './selection.service'; import { ElementFactory } from '../../../../common/util/element.factory'; import { ClozeParser } from '../util/cloze-parser'; +import { Copy } from '../../../../common/util/copy'; @Injectable({ providedIn: 'root' @@ -260,7 +261,7 @@ export class UnitService { } else if (property === 'text' && element.type === 'cloze') { element.setProperty('parts', ClozeParser.createClozeParts(value as string, this.idService)); } else { - element.setProperty(property, value); + element.setProperty(property, Copy.getCopy(value)); } } this.elementPropertyUpdated.next();