Skip to content

Commit

Permalink
Merge pull request #20 from hlxsites/remove-mixin
Browse files Browse the repository at this point in the history
#474566 - remove mixin
  • Loading branch information
infloent authored Apr 30, 2024
2 parents 0b5de8a + 9e1bb10 commit b76b1be
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 200 deletions.
1 change: 0 additions & 1 deletion blocks/breadcrumbs/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default class Breadcrumbs extends ComponentBase {
...ComponentBase.loaderConfig,
targetsSelectors: 'main > div',
targetsSelectorsLimit: 1,
targetsAsContainers: true,
};

nestedComponentsConfig = {};
Expand Down
20 changes: 4 additions & 16 deletions blocks/columns/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class Columns {
const { currentAttributes } = collectAttributes(
data.componentName,
data.rawClasses,
[],
Columns.observedAttributes,
this.element,
);
Expand All @@ -32,9 +31,7 @@ export default class Columns {
const parent = this.element.parentElement;
const children = Array.from(parent.children);
parent.classList.add('raqn-grid');
let parentGridTemplateColumns = parent.style.getPropertyValue(
'--grid-template-columns',
);
let parentGridTemplateColumns = parent.style.getPropertyValue('--grid-template-columns');
if (!parentGridTemplateColumns) {
// we have no grid template columns yet
parentGridTemplateColumns = children
Expand All @@ -46,10 +43,7 @@ export default class Columns {
})
.join(' ');
// set the new grid template columns
parent.style.setProperty(
'--grid-template-columns',
parentGridTemplateColumns,
);
parent.style.setProperty('--grid-template-columns', parentGridTemplateColumns);
} else {
const { position } = this;
const prio = children.indexOf(this.element) + 1;
Expand All @@ -74,20 +68,14 @@ export default class Columns {
})
.join(' ');
// set the new grid template columns
parent.style.setProperty(
'--grid-template-columns',
parentGridTemplateColumns,
);
parent.style.setProperty('--grid-template-columns', parentGridTemplateColumns);
}
this.element.style.gridColumn = this.position;
this.element.style.gridRow = 1;
}
}

getAttribute(name) {
return (
this.element.getAttribute(name) ||
this.element.getAttribute(`data-${name}`)
);
return this.element.getAttribute(name) || this.element.getAttribute(`data-${name}`);
}
}
13 changes: 6 additions & 7 deletions blocks/section-metadata/section-metadata.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { collectAttributes } from '../../scripts/libs.js';
import ComponentBase from '../../scripts/component-base.js';
import ComponentMixin from '../../scripts/component-mixin.js';

// TODO the block for this component should not have content, the values should come only form class attribute as for any other component
// as for any other block. should replace the this.parentElement
export default class SectionMetadata extends ComponentBase {
async ready() {
const classes = [...this.querySelectorAll(':scope > div > div:first-child')]
.map((keyCell) => `${keyCell.textContent.trim()}-${keyCell.nextElementSibling.textContent.trim()}`);

const { currentAttributes } = collectAttributes('section-metadata', classes, await ComponentMixin.getMixins(), this.knownAttributes, this);
const classes = [...this.querySelectorAll(':scope > div > div:first-child')].map(
(keyCell) => `${keyCell.textContent.trim()}-${keyCell.nextElementSibling.textContent.trim()}`,
);

const { currentAttributes } = collectAttributes('section-metadata', classes, this.knownAttributes, this);
const section = this.parentElement;
Object.keys(currentAttributes).forEach((key) => {
if(key === 'class') {
if (key === 'class') {
section.setAttribute(key, currentAttributes[key]);
} else {
section.setAttribute(`data-${key}`, currentAttributes[key]);
}
});
await ComponentMixin.startAll(section);
}
}
1 change: 0 additions & 1 deletion head.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<style>body { display: none; }</style>
<link rel="stylesheet" href="/styles/styles.css" />
<script src="/scripts/pubsub.js" type="module"></script>
<script src="/scripts/component-mixin.js" type="module"></script>
<script src="/scripts/component-base.js" type="module"></script>
<script src="/scripts/component-loader.js" type="module"></script>
<script src="/scripts/libs.js" type="module"></script>
Expand Down
3 changes: 0 additions & 3 deletions mixins/column/column.css

This file was deleted.

86 changes: 0 additions & 86 deletions mixins/column/column.js

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/component-loader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { collectAttributes, loadModule, deepMerge, mergeUniqueArrays } from './libs.js';
// import ComponentBase from './component-base.js';

import ComponentMixin from './component-mixin.js';

export default class ComponentLoader {
constructor({ componentName, targets = [], loaderConfig, rawClasses, config, nestedComponentsConfig, active }) {
Expand Down Expand Up @@ -128,7 +125,6 @@ export default class ComponentLoader {
const { currentAttributes, nestedComponents } = collectAttributes(
this.componentName,
data.rawClasses,
await ComponentMixin.getMixins(),
this?.Handler?.knownAttributes,
componentElem,
);
Expand Down Expand Up @@ -172,7 +168,6 @@ export default class ComponentLoader {
const initListener = async (event) => {
if (event.detail.element === componentElem) {
componentElem.removeEventListener('initialized', initListener);
await ComponentMixin.startAll(componentElem);
componentElem.removeAttribute('isloading');
resolve(componentElem);
}
Expand Down
61 changes: 0 additions & 61 deletions scripts/component-mixin.js

This file was deleted.

9 changes: 1 addition & 8 deletions scripts/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ComponentLoader from './component-loader.js';
import ComponentMixin from './component-mixin.js';
import { globalConfig, eagerImage, getMeta, getMetaGroup } from './libs.js';

const component = {
Expand Down Expand Up @@ -105,8 +104,7 @@ const onLoadComponents = {

findLcp(data) {
return (
this.lcp.find(({ componentName }) => componentName === data.componentName) ||
data.lcp /* ||
this.lcp.find(({ componentName }) => componentName === data.componentName) || data.lcp /* ||
[...document.querySelectorAll('main > div > [class]:nth-child(-n+2)')].find((el) => el === data.block) */
);
},
Expand All @@ -127,16 +125,11 @@ const onLoadComponents = {

const globalInit = {
async init() {
this.loadMixins();
this.setLang();
this.initEagerImages();
onLoadComponents.init();
},

loadMixins() {
ComponentMixin.getMixins();
},

// TODO - maybe take this from the url structure.
setLang() {
document.documentElement.lang ||= 'en';
Expand Down
16 changes: 4 additions & 12 deletions scripts/libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function getMetaGroup(group) {
}));
}

export function collectAttributes(componentName, classes, mixins, knownAttributes = [], element = null) {
export function collectAttributes(componentName, classes, knownAttributes = [], element = null) {
const classesList = [];
const mediaAttributes = {};
const attributesValues = element?.attributesValues || {};
Expand All @@ -173,13 +173,11 @@ export function collectAttributes(componentName, classes, mixins, knownAttribute

const nestedComponentsNames = Object.keys(nestedComponents);

const mixinKnownAttributes = mixins.flatMap((mixin) => mixin.observedAttributes || []);
const attrs = classesList
.filter((c) => c !== componentName && c !== 'block')
.reduce((acc, c) => {
let value = c;
let isKnownAttribute = null;
let isMixinKnownAttributes = null;

const classBreakpoint = Object.keys(globalConfig.breakpoints).find((b) => c.startsWith(`${b}-`));
const activeBreakpoint = getBreakPoints().active.name;
Expand All @@ -203,11 +201,9 @@ export function collectAttributes(componentName, classes, mixins, knownAttribute
value = value.slice(key.length + 1);
} else {
isKnownAttribute = knownAttributes.find((attribute) => value.startsWith(`${attribute}-`));
isMixinKnownAttributes = mixinKnownAttributes.find((attribute) => value.startsWith(`${attribute}-`));
const getKnownAttribute = isKnownAttribute || isMixinKnownAttributes;
if (getKnownAttribute) {
key = getKnownAttribute;
value = value.slice(getKnownAttribute.length + 1);
if (isKnownAttribute) {
key = isKnownAttribute;
value = value.slice(isKnownAttribute.length + 1);
}
}

Expand All @@ -223,11 +219,7 @@ export function collectAttributes(componentName, classes, mixins, knownAttribute
if (isKnownAttribute) attributesValues[camelCaseKey][classBreakpoint] = value;
if (isClass) {
attributesValues[camelCaseKey][classBreakpoint] ??= '';
// if (attributesValues[camelCaseKey][classBreakpoint]) {
attributesValues[camelCaseKey][classBreakpoint] += `${value} `;
// } else {
// attributesValues[camelCaseKey][classBreakpoint] = value;
// }
}
// support multivalue attributes
} else if (acc[key]) {
Expand Down

0 comments on commit b76b1be

Please sign in to comment.