Skip to content

Commit

Permalink
fix: initialize custom block in editorjs
Browse files Browse the repository at this point in the history
(cherry picked from commit 58c5a33)
  • Loading branch information
shariquerik authored and mergify[bot] committed May 18, 2023
1 parent bbeaa9e commit 8f91cf9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
62 changes: 62 additions & 0 deletions frappe/public/js/frappe/views/workspace/blocks/custom_block.js
@@ -0,0 +1,62 @@
import Block from "./block.js";
export default class CustomBlock extends Block {
static get toolbox() {
return {
title: "Custom Block",
icon: frappe.utils.icon("edit", "sm"),
};
}

static get isReadOnlySupported() {
return true;
}

constructor({ data, api, config, readOnly, block }) {
super({ data, api, config, readOnly, block });
this.col = this.data.col ? this.data.col : "12";
this.allow_customization = !this.readOnly;
this.options = {
allow_sorting: this.allow_customization,
allow_create: this.allow_customization,
allow_delete: this.allow_customization,
allow_hiding: false,
allow_edit: true,
allow_resize: true,
min_width: 2,
};
}

render() {
this.wrapper = document.createElement("div");
this.new("custom_block");

if (this.data && this.data.custom_block_name) {
let has_data = this.make("custom_block", this.data.custom_block_name);
if (!has_data) return;
}

if (!this.readOnly) {
$(this.wrapper).find(".widget").addClass("custom_block edit-mode");
this.add_settings_button();
this.add_new_block_button();
}

return this.wrapper;
}

validate(savedData) {
if (!savedData.custom_block_name) {
return false;
}

return true;
}

save() {
return {
custom_block_name: this.wrapper.getAttribute("custom_block_name"),
col: this.get_col(),
new: this.new_block_widget,
};
}
}
2 changes: 2 additions & 0 deletions frappe/public/js/frappe/views/workspace/blocks/index.js
Expand Up @@ -8,6 +8,7 @@ import Spacer from "./spacer";
import Onboarding from "./onboarding";
import QuickList from "./quick_list";
import NumberCard from "./number_card";
import CustomBlock from "./custom_block";

// import tunes
import HeaderSize from "./header_size";
Expand All @@ -24,6 +25,7 @@ frappe.workspace_block.blocks = {
onboarding: Onboarding,
quick_list: QuickList,
number_card: NumberCard,
custom_block: CustomBlock,
};

frappe.workspace_block.tunes = {
Expand Down
7 changes: 7 additions & 0 deletions frappe/public/js/frappe/views/workspace/workspace.js
Expand Up @@ -400,6 +400,7 @@ frappe.views.Workspace = class Workspace {
this.editor.configuration.tools.onboarding.config.page_data = this.page_data;
this.editor.configuration.tools.quick_list.config.page_data = this.page_data;
this.editor.configuration.tools.number_card.config.page_data = this.page_data;
this.editor.configuration.tools.custom_block.config.page_data = this.page_data;
this.editor.render({ blocks: this.content || [] });
});
} else {
Expand Down Expand Up @@ -1352,6 +1353,12 @@ frappe.views.Workspace = class Workspace {
page_data: this.page_data || [],
},
},
custom_block: {
class: this.blocks["custom_block"],
config: {
page_data: this.page_data || [],
},
},
spacer: this.blocks["spacer"],
HeaderSize: frappe.workspace_block.tunes["header_size"],
};
Expand Down

0 comments on commit 8f91cf9

Please sign in to comment.