-
Notifications
You must be signed in to change notification settings - Fork 116
Use plugins resources instead of registries #3695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
addons/html_builder/static/src/builder/core_builder_action_plugin.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { Plugin } from "@html_editor/plugin"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| class CoreBuilderActionPlugin extends Plugin { | ||
| static id = "CoreBuilderAction"; | ||
| resources = { | ||
| builder_actions: actions, | ||
| }; | ||
| } | ||
| registry.category("website-plugins").add(CoreBuilderActionPlugin.id, CoreBuilderActionPlugin); | ||
|
|
||
| const styleMap = { | ||
| borderWidth: { | ||
| getValue: (editingElement) => { | ||
| return parseInt( | ||
| getComputedStyle(editingElement).getPropertyValue("border-width") | ||
| ).toString(); | ||
| }, | ||
| apply: (editingElement, value) => { | ||
| const parsedValue = parseInt(value); | ||
| const hasBorderClass = editingElement.classList.contains("border"); | ||
| if (!parsedValue || parsedValue < 0) { | ||
| if (hasBorderClass) { | ||
| editingElement.classList.remove("border"); | ||
| } | ||
| } else { | ||
| if (!hasBorderClass) { | ||
| editingElement.classList.add("border"); | ||
| } | ||
| } | ||
| editingElement.style.setProperty("border-width", `${parsedValue}px`, "important"); | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const actions = { | ||
| classAction: { | ||
| isActive: ({ editingElement, param: className }) => { | ||
| return editingElement.classList.contains(className); | ||
| }, | ||
| apply: ({ editingElement, param: className, value }) => { | ||
| editingElement.classList.add(className); | ||
| }, | ||
| clean: ({ editingElement, param: className, value }) => { | ||
| editingElement.classList.remove(className); | ||
| }, | ||
| }, | ||
| styleAction: { | ||
| getValue: ({ editingElement, param: styleName }) => { | ||
| return styleMap[styleName]?.getValue(editingElement); | ||
| }, | ||
| apply: ({ editingElement, param: styleName, value }) => { | ||
| styleMap[styleName]?.apply(editingElement, value); | ||
| }, | ||
| }, | ||
| attributeAction: { | ||
| getValue: ({ editingElement, param: attributeName }) => { | ||
| return editingElement.getAttribute(attributeName); | ||
| }, | ||
| isActive: ({ editingElement, param: attributeName, value }) => { | ||
| if (value) { | ||
| return ( | ||
| editingElement.hasAttribute(attributeName) && | ||
| editingElement.getAttribute(attributeName) === value | ||
| ); | ||
| } else { | ||
| return !editingElement.hasAttribute(attributeName); | ||
| } | ||
| }, | ||
| apply: ({ editingElement, param: attributeName, value }) => { | ||
| if (value) { | ||
| editingElement.setAttribute(attributeName, value); | ||
| } else { | ||
| editingElement.removeAttribute(attributeName); | ||
| } | ||
| }, | ||
| clean: ({ editingElement, param: attributeName }) => { | ||
| editingElement.removeAttribute(attributeName); | ||
| }, | ||
| }, | ||
| }; | ||
19 changes: 14 additions & 5 deletions
19
addons/html_builder/static/src/builder/options/alert_option.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| import { Plugin } from "@html_editor/plugin"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { withSequence } from "@html_editor/utils/resource"; | ||
|
|
||
| registry.category("sidebar-element-option").add("AlertOption", { | ||
| template: "html_builder.AlertOption", | ||
| selector: ".s_alert", | ||
| sequence: 5, | ||
| }); | ||
| class AlertOptionPlugin extends Plugin { | ||
| static id = "AlertOption"; | ||
| resources = { | ||
| builder_options: [ | ||
| withSequence(5, { | ||
| template: "html_builder.AlertOption", | ||
| selector: ".s_alert", | ||
| }), | ||
| ], | ||
| }; | ||
| } | ||
| registry.category("website-plugins").add(AlertOptionPlugin.id, AlertOptionPlugin); |
17 changes: 13 additions & 4 deletions
17
addons/html_builder/static/src/builder/options/alignment_option.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| import { Plugin } from "@html_editor/plugin"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| registry.category("sidebar-element-option").add("AlignmentOption", { | ||
| template: "html_builder.AlignmentOption", | ||
| selector: ".s_share, .s_text_highlight, .s_social_media, section", | ||
| }); | ||
| class AlignmentOptionPlugin extends Plugin { | ||
| static id = "AlignmentOption"; | ||
| resources = { | ||
| builder_options: [ | ||
| { | ||
| template: "html_builder.AlignmentOption", | ||
| selector: ".s_share, .s_text_highlight, .s_social_media", | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| registry.category("website-plugins").add(AlignmentOptionPlugin.id, AlignmentOptionPlugin); |
20 changes: 15 additions & 5 deletions
20
addons/html_builder/static/src/builder/options/block_alignment_option.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| import { Plugin } from "@html_editor/plugin"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { withSequence } from "@html_editor/utils/resource"; | ||
|
|
||
| registry.category("sidebar-element-option").add("BlockAlignmentOption", { | ||
| template: "html_builder.BlockAlignmentOption", | ||
| selector: ".s_alert, .s_blockquote, .s_text_highlight", | ||
| sequence: 30, | ||
| }); | ||
| class BlockAlignmentOptionPlugin extends Plugin { | ||
| static id = "BlockAlignmentOption"; | ||
| resources = { | ||
| builder_options: [ | ||
| withSequence(30, { | ||
| template: "html_builder.BlockAlignmentOption", | ||
| selector: ".s_alert, .s_blockquote, .s_text_highlight", | ||
| }), | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| registry.category("website-plugins").add(BlockAlignmentOptionPlugin.id, BlockAlignmentOptionPlugin); |
21 changes: 15 additions & 6 deletions
21
addons/html_builder/static/src/builder/options/border_option.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| import { Plugin } from "@html_editor/plugin"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| export const card_parent_handlers = | ||
| ".s_three_columns .row > div, .s_comparisons .row > div, .s_cards_grid .row > div, .s_cards_soft .row > div, .s_product_list .row > div"; | ||
|
|
||
| registry.category("sidebar-element-option").add("BorderOption", { | ||
| template: "html_builder.BorderOption", | ||
| selector: "section .row > div", | ||
| exclude: `.s_col_no_bgcolor, .s_col_no_bgcolor.row > div, .s_image_gallery .row > div, .s_masonry_block .s_col_no_resize, .s_text_cover .row > .o_not_editable, ${card_parent_handlers}`, | ||
| // TODO add border shadow. | ||
| }); | ||
| class BorderOptionPlugin extends Plugin { | ||
| static id = "BorderOption"; | ||
| resources = { | ||
| builder_options: [ | ||
| { | ||
| template: "html_builder.BorderOption", | ||
| selector: "section .row > div", | ||
| exclude: `.s_col_no_bgcolor, .s_col_no_bgcolor.row > div, .s_image_gallery .row > div, .s_masonry_block .s_col_no_resize, .s_text_cover .row > .o_not_editable, ${card_parent_handlers}`, | ||
| // TODO add border shadow. | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| registry.category("website-plugins").add(BorderOptionPlugin.id, BorderOptionPlugin); |
25 changes: 16 additions & 9 deletions
25
addons/html_builder/static/src/builder/options/content_width_option.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| import { Plugin } from "@html_editor/plugin"; | ||
| import { registry } from "@web/core/registry"; | ||
|
|
||
| // TODO to import in html_builder | ||
|
|
||
| registry.category("sidebar-element-option").add("ContentWidthOption", { | ||
| template: "html_builder.ContentWidthOption", | ||
| selector: "section, .s_carousel .carousel-item, .s_carousel_intro_item", | ||
| exclude: "[data-snippet] :not(.oe_structure) > [data-snippet]", | ||
| // TODO add target and remove applyTo in the template of ContentWidthOption ? | ||
| // target: "> .container, > .container-fluid, > .o_container_small", | ||
| }); | ||
| class ContentWidthOptionPlugin extends Plugin { | ||
| static id = "ContentWidthOption"; | ||
| resources = { | ||
| builder_options: [ | ||
| { | ||
| template: "html_builder.ContentWidthOption", | ||
| selector: "section, .s_carousel .carousel-item, .s_carousel_intro_item", | ||
| exclude: "[data-snippet] :not(.oe_structure) > [data-snippet]", | ||
| // TODO add target and remove applyTo in the template of ContentWidthOption ? | ||
| // target: "> .container, > .container-fluid, > .o_container_small", | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
| registry.category("website-plugins").add(ContentWidthOptionPlugin.id, ContentWidthOptionPlugin); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.