Skip to content

Commit

Permalink
Merge pull request #57 from frappe/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
surajshetty3416 authored Jan 11, 2024
2 parents 6fa416a + 0b60cf2 commit 8e4e549
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frontend/src/builder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare interface BlockStyleMap {
}

declare interface BlockAttributeMap {
[key: string]: string;
[key: string]: string | number | null | undefined;
}

declare interface BlockOptions {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/BlockEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ watchEffect(() => {
props.block.getStyle("bottom");
props.block.getStyle("right");
props.block.getStyle("position");
props.block.rawStyles;
const parentBlock = props.block.getParentBlock();
parentBlock?.getStyle("display");
parentBlock?.getStyle("justifyContent");
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/ObjectEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const pasteObj = (e: ClipboardEvent) => {
const map = new Map(Object.entries(props.obj));
try {
const objString = text.match(/{[^{}]+}/)?.[0];
if (!objString) return new Error("Invalid object");
if (!objString) throw new Error("Invalid object");
const obj = new Function("return " + objString)();
if (typeof obj === "object") {
for (const [key, value] of Object.entries(obj)) {
Expand All @@ -91,7 +91,6 @@ const pasteObj = (e: ClipboardEvent) => {
}
map.delete("");
}
e.preventDefault();
emit("update:obj", mapToObject(map));
}
};
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/utils/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Block implements BlockOptions {
referenceBlockId?: string;
isRepeaterBlock?: boolean;
visibilityCondition?: string;
customAttributes?: BlockAttributeMap;
customAttributes: BlockAttributeMap;
constructor(options: BlockOptions) {
this.element = options.element;
this.innerHTML = options.innerHTML;
Expand Down Expand Up @@ -409,7 +409,12 @@ class Block implements BlockOptions {
return store.findParentBlock(this.blockId);
}
canHaveChildren(): boolean {
return (this.isContainer() || this.isRoot() || this.isDiv()) && !this.isExtendedFromComponent();
return !(
this.isImage() ||
this.isSVG() ||
(this.isText() && !this.isLink()) ||
this.isExtendedFromComponent()
);
}
updateStyles(styles: BlockStyleObjects) {
this.baseStyles = Object.assign({}, this.baseStyles, styles.baseStyles);
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/utils/blockController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,25 @@ const blockController = {
},
setRawStyles: (rawStyles: BlockStyleMap) => {
store.selectedBlocks.forEach((block) => {
block.rawStyles = rawStyles;
Object.keys(block.rawStyles).forEach((key) => {
if (!rawStyles[key]) {
delete block.rawStyles[key];
}
});
Object.assign(block.rawStyles, rawStyles);
});
},
getCustomAttributes: () => {
return blockController.isBLockSelected() && store.selectedBlocks[0].customAttributes;
},
setCustomAttributes: (customAttributes: BlockAttributeMap) => {
store.selectedBlocks.forEach((block) => {
block.customAttributes = customAttributes;
Object.keys(block.customAttributes).forEach((key) => {
if (!customAttributes[key]) {
delete block.customAttributes[key];
}
});
Object.assign(block.customAttributes, customAttributes);
});
},
getParentBlock: () => {
Expand Down

0 comments on commit 8e4e549

Please sign in to comment.