Skip to content

Commit bfe21f7

Browse files
committed
[FIX] Move utils to html_builder
1 parent 0222beb commit bfe21f7

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

addons/html_builder/static/src/plugins/background_option/background_option_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { applyFunDependOnSelectorAndExclude } from "@website/builder/plugins/utils";
1+
import { applyFunDependOnSelectorAndExclude } from "@html_builder/plugins/utils";
22
import { Plugin } from "@html_editor/plugin";
33
import { registry } from "@web/core/registry";
44

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function applyFunDependOnSelectorAndExclude(fn, rootEl, selectorParams) {
2+
const editingEls = getEditingEls(rootEl, selectorParams);
3+
if (!editingEls.length) {
4+
return false;
5+
}
6+
return Promise.all(editingEls.map((el) => fn(el)));
7+
}
8+
9+
export function getEditingEls(rootEl, { selector, exclude, applyTo }) {
10+
const closestSelector = rootEl.closest(selector);
11+
let editingEls = closestSelector ? [closestSelector] : [...rootEl.querySelectorAll(selector)];
12+
if (exclude) {
13+
editingEls = editingEls.filter((selectorEl) => !selectorEl.matches(exclude));
14+
}
15+
if (!applyTo) {
16+
return editingEls;
17+
}
18+
const targetEls = [];
19+
for (const editingEl of editingEls) {
20+
const applyToEls = applyTo ? editingEl.querySelectorAll(applyTo) : [editingEl];
21+
targetEls.push(...applyToEls);
22+
}
23+
return targetEls;
24+
}

addons/website/static/src/builder/plugins/options/parallax_option_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { applyFunDependOnSelectorAndExclude } from "@website/builder/plugins/utils";
1+
import { applyFunDependOnSelectorAndExclude } from "@html_builder/plugins/utils";
22
import { getSelectorParams } from "@html_builder/utils/utils";
33
import { Plugin } from "@html_editor/plugin";
44
import { registry } from "@web/core/registry";

addons/website/static/src/builder/plugins/options/process_steps_option_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BuilderAction } from "@html_builder/core/builder_action";
22
import { ClassAction } from "@html_builder/core/core_builder_action_plugin";
3-
import { applyFunDependOnSelectorAndExclude } from "@website/builder/plugins/utils";
3+
import { applyFunDependOnSelectorAndExclude } from "@html_builder/plugins/utils";
44
import { Plugin } from "@html_editor/plugin";
55
import { registry } from "@web/core/registry";
66
import { connectorOptionParams, ProcessStepsOption } from "./process_steps_option";

addons/website/static/src/builder/plugins/options/table_of_content_option_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { applyFunDependOnSelectorAndExclude } from "@website/builder/plugins/utils";
1+
import { applyFunDependOnSelectorAndExclude } from "@html_builder/plugins/utils";
22
import { Plugin } from "@html_editor/plugin";
33
import { registry } from "@web/core/registry";
44
import { BuilderAction } from "@html_builder/core/builder_action";
Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +0,0 @@
1-
export function applyFunDependOnSelectorAndExclude(fn, rootEl, selectorParams) {
2-
const editingEls = getEditingEls(rootEl, selectorParams);
3-
if (!editingEls.length) {
4-
return false;
5-
}
6-
return Promise.all(editingEls.map((el) => fn(el)));
7-
}
8-
9-
export function getEditingEls(rootEl, { selector, exclude, applyTo }) {
10-
const closestSelector = rootEl.closest(selector);
11-
let editingEls = closestSelector ? [closestSelector] : [...rootEl.querySelectorAll(selector)];
12-
if (exclude) {
13-
editingEls = editingEls.filter((selectorEl) => !selectorEl.matches(exclude));
14-
}
15-
if (!applyTo) {
16-
return editingEls;
17-
}
18-
const targetEls = [];
19-
for (const editingEl of editingEls) {
20-
const applyToEls = applyTo ? editingEl.querySelectorAll(applyTo) : [editingEl];
21-
targetEls.push(...applyToEls);
22-
}
23-
return targetEls;
24-
}

0 commit comments

Comments
 (0)