From 4d16584266e36d7ee321b84e289ba08d095a2b10 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Sun, 19 Feb 2023 08:18:43 -0800 Subject: [PATCH] fix: serializing disabled interactions (#6847) * feat: add own property getters for disabled interactions * feat: add serialization of disabled attributes --- core/block.ts | 30 ++++++++++++++++++++++++++++++ core/serialization/blocks.ts | 21 +++++++++++++++++++++ tests/mocha/serializer_test.js | 15 +++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/core/block.ts b/core/block.ts index d9d0455e2..34c862119 100644 --- a/core/block.ts +++ b/core/block.ts @@ -795,6 +795,15 @@ export class Block implements IASTNodeLocation, IDeletable { !this.workspace.options.readOnly; } + /** + * Return whether this block's own deletable property is true or false. + * + * @returns True if the block's deletable property is true, false otherwise. + */ + isOwnDeletable(): boolean { + return this.deletable_; + } + /** * Set whether this block is deletable or not. * @@ -808,12 +817,23 @@ export class Block implements IASTNodeLocation, IDeletable { * Get whether this block is movable or not. * * @returns True if movable. + * @internal */ isMovable(): boolean { return this.movable_ && !this.isShadow_ && !this.isDeadOrDying() && !this.workspace.options.readOnly; } + /** + * Return whether this block's own movable property is true or false. + * + * @returns True if the block's movable property is true, false otherwise. + * @internal + */ + isOwnMovable(): boolean { + return this.movable_; + } + /** * Set whether this block is movable or not. * @@ -882,12 +902,22 @@ export class Block implements IASTNodeLocation, IDeletable { * Get whether this block is editable or not. * * @returns True if editable. + * @internal */ isEditable(): boolean { return this.editable_ && !this.isDeadOrDying() && !this.workspace.options.readOnly; } + /** + * Return whether this block's own editable property is true or false. + * + * @returns True if the block's editable property is true, false otherwise. + */ + isOwnEditable(): boolean { + return this.editable_; + } + /** * Set whether this block is editable or not. * diff --git a/core/serialization/blocks.ts b/core/serialization/blocks.ts index 61c416da6..2152a12d1 100644 --- a/core/serialization/blocks.ts +++ b/core/serialization/blocks.ts @@ -48,6 +48,9 @@ export interface State { x?: number; y?: number; collapsed?: boolean; + deletable?: boolean; + movable?: boolean; + editable?: boolean; enabled?: boolean; inline?: boolean; data?: string; @@ -142,6 +145,15 @@ function saveAttributes(block: Block, state: State) { if (!block.isEnabled()) { state['enabled'] = false; } + if (!block.isOwnDeletable()) { + state['deletable'] = false; + } + if (!block.isOwnMovable()) { + state['movable'] = false; + } + if (!block.isOwnEditable()) { + state['editable'] = false; + } if (block.inputsInline !== undefined && block.inputsInline !== block.inputsInlineDefault) { state['inline'] = block.inputsInline; @@ -437,6 +449,15 @@ function loadAttributes(block: Block, state: State) { if (state['collapsed']) { block.setCollapsed(true); } + if (state['deletable'] === false) { + block.setDeletable(false); + } + if (state['movable'] === false) { + block.setMovable(false); + } + if (state['editable'] === false) { + block.setEditable(false); + } if (state['enabled'] === false) { block.setEnabled(false); } diff --git a/tests/mocha/serializer_test.js b/tests/mocha/serializer_test.js index 8cbf49f68..0a09b1725 100644 --- a/tests/mocha/serializer_test.js +++ b/tests/mocha/serializer_test.js @@ -73,10 +73,25 @@ Serializer.Attributes.Disabled = new SerializerTestCase('Disabled', '' + '' + ''); +Serializer.Attributes.NotDeletable = new SerializerTestCase('Deletable', + '' + + '' + + ''); +Serializer.Attributes.NotMovable = new SerializerTestCase('Movable', + '' + + '' + + ''); +Serializer.Attributes.NotEditable = new SerializerTestCase('Editable', + '' + + '' + + ''); Serializer.Attributes.testCases = [ Serializer.Attributes.Basic, Serializer.Attributes.Collapsed, Serializer.Attributes.Disabled, + Serializer.Attributes.NotDeletable, + Serializer.Attributes.NotMovable, + Serializer.Attributes.NotEditable, ]; Serializer.Attributes.Inline = new SerializerTestSuite('Inline');