@total_onion/onion-library 2.0.201 → 2.0.202

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/assembleAssetList.js +21 -2
  2. package/components/fields-core-css-sizing-vars-v3/core-css-sizing-vars-v3.scss +102 -74
  3. package/components/fields-core-root-variables-v3/core-root-variables-v3.scss +39 -37
  4. package/components/webc-loadmore-trigger/index.html +30 -0
  5. package/components/webc-loadmore-trigger/loadmore-trigger.css +20 -0
  6. package/components/webc-loadmore-trigger/loadmore-trigger.html +3 -0
  7. package/components/webc-loadmore-trigger/loadmore-trigger.js +23 -0
  8. package/components/webc-post-filter-module/dev-content/dev-content.js +38 -0
  9. package/components/webc-post-filter-module/index.html +30 -0
  10. package/components/webc-post-filter-module/post-filter-module.css +4 -0
  11. package/components/webc-post-filter-module/post-filter-module.html +11 -0
  12. package/components/webc-post-filter-module/post-filter-module.js +147 -0
  13. package/components/webc-post-grid-display-module/index.html +30 -0
  14. package/components/webc-post-grid-display-module/post-grid-display-module.css +20 -0
  15. package/components/webc-post-grid-display-module/post-grid-display-module.html +7 -0
  16. package/components/webc-post-grid-display-module/post-grid-display-module.js +37 -0
  17. package/components/webc-ptfg-9000/dev-content/dev-content.js +38 -0
  18. package/components/webc-ptfg-9000/index.html +51 -0
  19. package/components/webc-ptfg-9000/ptfg-9000.css +8 -0
  20. package/components/webc-ptfg-9000/ptfg-9000.html +6 -0
  21. package/components/webc-ptfg-9000/ptfg-9000.js +39 -0
  22. package/createJsAssets-v3.js +1 -1
  23. package/esbuild.mjs +39 -6
  24. package/onion-loader-local.js +1 -1
  25. package/package.json +1 -1
  26. package/public/assetList.mjs +78 -2
  27. package/public/block-group-container-v3/group-container-v3.css +26 -26
  28. package/public/block-post-info-v3/post-info-v3.css +429 -429
  29. package/public/block-post-type-filter-grid-v4/dev-content/dev-content.js +38 -0
  30. package/public/block-post-type-filter-grid-v4/post-type-filter-grid-v4.css +42 -0
  31. package/public/block-post-type-filter-grid-v4/post-type-filter-grid-v4.js +181 -0
  32. package/public/block-product-info-v3/product-info-v3.css +257 -257
  33. package/public/block-sub-group-container-v3/sub-group-container-v3.css +23 -23
  34. package/public/jsAssets.mjs +41 -3
  35. package/public/publicBundleBase.css +4800 -0
  36. package/public/{publicBundle.scss → publicBundleBase.scss} +6 -2
  37. package/public/publicBundle.css +0 -6392
@@ -8,20 +8,39 @@ const dynamicEntryPointsJs = globSync(`./components/block-*/*-v3.js`).map(
8
8
  return assetKey;
9
9
  }
10
10
  );
11
+ const dynamicEntryPointsJsV4 = globSync(`./components/block-*/*-v4.js`).map(
12
+ (filePath) => {
13
+ const assetKey = path.basename(filePath, '.js');
14
+ return assetKey;
15
+ }
16
+ );
11
17
  const dynamicEntryPointsScss = globSync(`./components/block-*/*-v3.scss`).map(
12
18
  (filePath) => {
13
19
  const assetKey = path.basename(filePath, '.js');
14
20
  return assetKey;
15
21
  }
16
22
  );
23
+ const dynamicEntryPointsCss = globSync(`./components/block-*/*-v4.css`).map(
24
+ (filePath) => {
25
+ const assetKey = path.basename(filePath, '.js');
26
+ return assetKey;
27
+ }
28
+ );
17
29
  const assetArrayJs = dynamicEntryPointsJs.map((entry) => {
18
30
  return `./components/block-${entry}/${entry}.js`;
19
31
  });
32
+ const assetArrayJsV4 = dynamicEntryPointsJsV4.map((entry) => {
33
+ return `./components/block-${entry}/${entry}.js`;
34
+ });
20
35
 
21
36
  const assetArrayScss = dynamicEntryPointsScss.map((entry) => {
22
37
  let filename = entry.replace('.scss', '');
23
38
  return `./components/block-${filename}/${filename}.scss`;
24
39
  });
40
+ const assetArrayCss = dynamicEntryPointsCss.map((entry) => {
41
+ let filename = entry.replace('.css', '');
42
+ return `./components/block-${filename}/${filename}.css`;
43
+ });
25
44
 
26
45
  // Create the directory path for the target file
27
46
  const jsModulePath = path.join('./public');
@@ -40,9 +59,9 @@ fs.mkdirSync(dirPath, {recursive: true});
40
59
  const data = `
41
60
  const dynamicAssets = ${JSON.stringify([
42
61
  ...assetArrayScss,
62
+ ...assetArrayCss,
43
63
  ...assetArrayJs,
44
- './public/dynamicBlockScss-v3.scss',
45
- './public/publicBundle.scss'
64
+ ...assetArrayJsV4
46
65
  ])};
47
66
  export default dynamicAssets;
48
67
  `;
@@ -2,96 +2,124 @@
2
2
  @use '../fields-core-functions-v3/core-functions-v3';
3
3
  @use '../../breakpoints';
4
4
  @mixin coreCssSizingVarsV3() {
5
- body {
6
- --screen-width: var(--screen-width-mobile);
7
- --font-reference: var(--font-reference-mobile);
8
- --design-reference: var(--mobile-design-reference);
9
- @include core-mixins-v3.device(breakpoints.$tabPortrait) {
10
- --screen-width: var(--screen-width-portrait);
11
- --font-reference: var(--font-reference-portrait);
12
- --design-reference: var(--portrait-design-reference);
5
+ @layer base-styles {
6
+ body {
7
+ --screen-width: var(--screen-width-mobile);
8
+ --font-reference: var(--font-reference-mobile);
9
+ --design-reference: var(--mobile-design-reference);
10
+ @include core-mixins-v3.device(breakpoints.$tabPortrait) {
11
+ --screen-width: var(--screen-width-portrait);
12
+ --font-reference: var(--font-reference-portrait);
13
+ --design-reference: var(--portrait-design-reference);
14
+ }
15
+ @include core-mixins-v3.device(breakpoints.$tabLandscape) {
16
+ --screen-width: var(--screen-width-landscape);
17
+ --font-reference: var(--font-reference-landscape);
18
+ --design-reference: var(--landscape-design-reference);
19
+ }
20
+ @include core-mixins-v3.device(breakpoints.$desktop) {
21
+ --screen-width: var(--screen-width-desktop);
22
+ --font-reference: var(--font-reference-desktop);
23
+ --design-reference: var(--desktop-design-reference);
24
+ }
25
+ @include core-mixins-v3.device(breakpoints.$desktop-fullhd) {
26
+ --screen-width: var(--screen-width-fullhd);
27
+ --font-reference: var(--font-reference-fullhd);
28
+ --design-reference: var(--fullhd-design-reference);
29
+ }
13
30
  }
14
- @include core-mixins-v3.device(breakpoints.$tabLandscape) {
15
- --screen-width: var(--screen-width-landscape);
16
- --font-reference: var(--font-reference-landscape);
17
- --design-reference: var(--landscape-design-reference);
18
- }
19
- @include core-mixins-v3.device(breakpoints.$desktop) {
20
- --screen-width: var(--screen-width-desktop);
21
- --font-reference: var(--font-reference-desktop);
22
- --design-reference: var(--desktop-design-reference);
23
- }
24
- @include core-mixins-v3.device(breakpoints.$desktop-fullhd) {
25
- --screen-width: var(--screen-width-fullhd);
26
- --font-reference: var(--font-reference-fullhd);
27
- --design-reference: var(--fullhd-design-reference);
28
- }
29
- }
30
- body {
31
- --global-inline-spacing: #{core-functions-v3.fluidSize(
32
- var(--mobile-inline),
33
- 'mobile'
34
- )};
31
+ body {
32
+ //defaults (can be overridden by cms or block code later on)
33
+ --mobile-inline: 20;
34
+ --portrait-inline: 40;
35
+ --landscape-inline: 40;
36
+ --desktop-inline: 40;
37
+ --screen-width-fullhd: 1920px;
38
+ --font-reference-fullhd: 1920px;
39
+ --screen-width-desktop: 1440px;
40
+ --font-reference-desktop: 1440px;
41
+ --screen-width-landscape: 100vw;
42
+ --font-reference-landscape: 100vw;
43
+ --screen-width-portrait: 100vw;
44
+ --font-reference-portrait: 100vw;
45
+ --font-reference-mobile: 375px;
46
+ --screen-width-mobile: 375px;
47
+ --screen-width-static: 1440px;
48
+ --fullhd-design-reference: 1920;
49
+ --desktop-design-reference: 1440;
50
+ --landscape-design-reference: 1440;
51
+ --portrait-design-reference: 1440;
52
+ --mobile-design-reference: 375;
35
53
 
36
- @include core-mixins-v3.device(breakpoints.$tabPortrait) {
37
54
  --global-inline-spacing: #{core-functions-v3.fluidSize(
38
- var(--portrait-inline),
39
- 'portrait'
55
+ var(--mobile-inline)
40
56
  )};
41
- }
42
57
 
43
- @include core-mixins-v3.device(breakpoints.$tabLandscape) {
44
- --global-inline-spacing: #{core-functions-v3.fluidSize(
45
- var(--landscape-inline),
46
- 'landscape'
47
- )};
48
- }
58
+ @include core-mixins-v3.device(breakpoints.$tabPortrait) {
59
+ --global-inline-spacing: #{core-functions-v3.fluidSize(
60
+ var(--portrait-inline, 40)
61
+ )};
62
+ }
49
63
 
50
- @include core-mixins-v3.device(breakpoints.$desktop) {
51
- --global-inline-spacing: #{core-functions-v3.fluidSize(
52
- var(--desktop-inline),
53
- 'desktop'
54
- )};
64
+ @include core-mixins-v3.device(breakpoints.$tabLandscape) {
65
+ --global-inline-spacing: #{core-functions-v3.fluidSize(
66
+ var(--landscape-inline, 40)
67
+ )};
68
+ }
69
+
70
+ @include core-mixins-v3.device(breakpoints.$desktop) {
71
+ --global-inline-spacing: #{core-functions-v3.fluidSize(
72
+ var(--desktop-inline, 40)
73
+ )};
74
+ }
55
75
  }
56
- }
57
76
 
58
- body {
59
- --heading-block-spacing: var(--heading-block-spacing-mobile);
77
+ body {
78
+ --heading-block-spacing: var(--heading-block-spacing-mobile);
60
79
 
61
- @include core-mixins-v3.device(breakpoints.$tabPortrait) {
62
- --heading-block-spacing: var(--heading-block-spacing-portrait);
63
- }
80
+ @include core-mixins-v3.device(breakpoints.$tabPortrait) {
81
+ --heading-block-spacing: var(--heading-block-spacing-portrait);
82
+ }
64
83
 
65
- @include core-mixins-v3.device(breakpoints.$tabLandscape) {
66
- --heading-block-spacing: var(--heading-block-spacing-desktop);
84
+ @include core-mixins-v3.device(breakpoints.$tabLandscape) {
85
+ --heading-block-spacing: var(--heading-block-spacing-desktop);
86
+ }
67
87
  }
68
- }
69
- body {
70
- --paragraph-block-spacing: var(--paragraph-block-spacing-mobile);
88
+ body {
89
+ --paragraph-block-spacing: var(--paragraph-block-spacing-mobile);
71
90
 
72
- @include core-mixins-v3.device(breakpoints.$tabPortrait) {
73
- --paragraph-block-spacing: var(--paragraph-block-spacing-portrait);
74
- }
91
+ @include core-mixins-v3.device(breakpoints.$tabPortrait) {
92
+ --paragraph-block-spacing: var(
93
+ --paragraph-block-spacing-portrait
94
+ );
95
+ }
75
96
 
76
- @include core-mixins-v3.device(breakpoints.$tabLandscape) {
77
- --paragraph-block-spacing: var(--paragraph-block-spacing-desktop);
97
+ @include core-mixins-v3.device(breakpoints.$tabLandscape) {
98
+ --paragraph-block-spacing: var(
99
+ --paragraph-block-spacing-desktop
100
+ );
101
+ }
78
102
  }
79
- }
80
- body {
81
- --list-item-block-spacing: var(--list-item-block-spacing-mobile);
103
+ body {
104
+ --list-item-block-spacing: var(--list-item-block-spacing-mobile);
82
105
 
83
- @include core-mixins-v3.device(breakpoints.$tabPortrait) {
84
- --list-item-block-spacing: var(--list-item-block-spacing-portrait);
85
- }
106
+ @include core-mixins-v3.device(breakpoints.$tabPortrait) {
107
+ --list-item-block-spacing: var(
108
+ --list-item-block-spacing-portrait
109
+ );
110
+ }
86
111
 
87
- @include core-mixins-v3.device(breakpoints.$tabLandscape) {
88
- --list-item-block-spacing: var(--list-item-block-spacing-desktop);
112
+ @include core-mixins-v3.device(breakpoints.$tabLandscape) {
113
+ --list-item-block-spacing: var(
114
+ --list-item-block-spacing-desktop
115
+ );
116
+ }
117
+ }
118
+ body {
119
+ --global-content-max-width: #{core-functions-v3.fluidSize(
120
+ var(--global-content-max-width-setting),
121
+ 'static'
122
+ )};
89
123
  }
90
- }
91
- body {
92
- --global-content-max-width: #{core-functions-v3.fluidSize(
93
- var(--global-content-max-width-setting),
94
- 'static'
95
- )};
96
124
  }
97
125
  } // End of mixin
@@ -2,43 +2,45 @@
2
2
  @use '../../breakpoints';
3
3
 
4
4
  @mixin coreRootVariablesV3() {
5
- body {
6
- //Font weights
7
- --weight-thin: 100;
8
- --weight-extra-light: 200;
9
- --weight-light: 300;
10
- --weight-medium: 400;
11
- --weight-demi-bold: 500;
12
- --weight-demi-bold-plus: 600;
13
- --weight-bold: 700;
14
- --weight-extra-bold: 800;
15
- --weight-extra-bold-plus: 900;
16
- --default-text-colour-mobile: var(--theme-primary-text-colour);
17
- --default-text-colour-desktop: var(--theme-primary-text-colour);
18
- // When you are in the WP preview - the screen width var now now needs to match the width of the WP editor preview box.
19
- .wp-toolbar & {
20
- --screen-width-mobile: 360px;
21
- --font-reference-mobile: 360px;
22
- --screen-width: 360px;
23
- --font-reference: 360px;
24
- @include core-mixins-v3.device(breakpoints.$tabPortrait) {
25
- --screen-width-portrait: 768px;
26
- --screen-width-landscape: 768px;
27
- --screen-width-desktop: 768px;
28
- --screen-width-static: 768px;
29
- --screen-width: 768px;
30
- --font-reference: 768px;
31
- }
32
- @include core-mixins-v3.device(breakpoints.$tabLandscape) {
33
- --screen-width-portrait: 840px;
34
- --screen-width-landscape: 840px;
35
- --screen-width-desktop: 840px;
36
- --screen-width-static: 840px;
37
- --screen-width: 840px;
38
- --font-reference-portrait: 840px;
39
- --font-reference-landscape: 840px;
40
- --font-reference-desktop: 840px;
41
- --font-reference: 840px;
5
+ @layer base-styles {
6
+ body {
7
+ //Font weights
8
+ --weight-thin: 100;
9
+ --weight-extra-light: 200;
10
+ --weight-light: 300;
11
+ --weight-medium: 400;
12
+ --weight-demi-bold: 500;
13
+ --weight-demi-bold-plus: 600;
14
+ --weight-bold: 700;
15
+ --weight-extra-bold: 800;
16
+ --weight-extra-bold-plus: 900;
17
+ --default-text-colour-mobile: var(--theme-primary-text-colour);
18
+ --default-text-colour-desktop: var(--theme-primary-text-colour);
19
+ // When you are in the WP preview - the screen width var now now needs to match the width of the WP editor preview box.
20
+ .wp-toolbar & {
21
+ --screen-width-mobile: 360px;
22
+ --font-reference-mobile: 360px;
23
+ --screen-width: 360px;
24
+ --font-reference: 360px;
25
+ @include core-mixins-v3.device(breakpoints.$tabPortrait) {
26
+ --screen-width-portrait: 768px;
27
+ --screen-width-landscape: 768px;
28
+ --screen-width-desktop: 768px;
29
+ --screen-width-static: 768px;
30
+ --screen-width: 768px;
31
+ --font-reference: 768px;
32
+ }
33
+ @include core-mixins-v3.device(breakpoints.$tabLandscape) {
34
+ --screen-width-portrait: 840px;
35
+ --screen-width-landscape: 840px;
36
+ --screen-width-desktop: 840px;
37
+ --screen-width-static: 840px;
38
+ --screen-width: 840px;
39
+ --font-reference-portrait: 840px;
40
+ --font-reference-landscape: 840px;
41
+ --font-reference-desktop: 840px;
42
+ --font-reference: 840px;
43
+ }
42
44
  }
43
45
  }
44
46
  }
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <link rel="stylesheet" href="../../public/publicBundleBase.css" />
7
+ <link rel="stylesheet" href="./loadmore-trigger.css" />
8
+ <title>PTFG</title>
9
+ <style>
10
+ body {
11
+ background-color: #e7b8b8;
12
+ }
13
+ main {
14
+ max-width: 600px;
15
+ margin-inline: auto;
16
+ padding: 50px;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <main class="main-container"></main>
22
+ <script async type="module">
23
+ const template = await fetch("./loadmore-trigger.html");
24
+ const html = await template.text();
25
+ document.querySelector(".main-container").innerHTML = html;
26
+ import blockjs from "./loadmore-trigger.js";
27
+ blockjs();
28
+ </script>
29
+ </body>
30
+ </html>
@@ -0,0 +1,20 @@
1
+ post-grid-display-module-v4 {
2
+ --padding-block-multiplier-mobile-top: 1;
3
+ --padding-inline-multiplier-mobile-right: 1;
4
+ --padding-block-multiplier-mobile-bottom: 1;
5
+ --padding-inline-multiplier-mobile-left: 1;
6
+
7
+ display: grid;
8
+ background-color: hotpink;
9
+ .post-grid-display-module-v4__grid-container {
10
+ place-self: stretch;
11
+ display: grid;
12
+ padding: 10px;
13
+ gap: 10px;
14
+ grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
15
+ }
16
+ .post-grid-display-module-v4__post-image {
17
+ width: 100%;
18
+ height: auto;
19
+ }
20
+ }
@@ -0,0 +1,3 @@
1
+ <loadmore-trigger id="loadmore-trigger" data-posts="" class="loadmore-trigger">
2
+ <button class="loadmore-trigger">Load More</button>
3
+ </loadmore-trigger>
@@ -0,0 +1,23 @@
1
+ export default function loadmoreTriggerJs(options = {}) {
2
+ try {
3
+ customElements.define(
4
+ 'loadmore-trigger',
5
+ class extends HTMLElement {
6
+ // static observedAttributes = ['data-posts'];
7
+ constructor() {
8
+ super();
9
+ }
10
+ connectedCallback() {
11
+ console.log('Display module added to page.');
12
+ this.classList.add('loaded');
13
+ }
14
+
15
+ attributeChangedCallback(name, oldValue, newValue) {
16
+ // console.log(`Attribute ${name} has changed.`);
17
+ }
18
+ }
19
+ );
20
+ } catch (error) {
21
+ console.error(error);
22
+ }
23
+ }
@@ -0,0 +1,38 @@
1
+ export const devContentDogz = [
2
+ {
3
+ postname: 'Dogz-1',
4
+ 'post-link': '#',
5
+ 'image-src': 'https://place-puppy.com/puppy/y:100/x:100',
6
+ categories: new Set([1, 5])
7
+ },
8
+ {
9
+ postname: 'Dogz-2',
10
+ 'post-link': '#',
11
+ 'image-src': 'https://place-puppy.com/puppy/y:100/x:100',
12
+
13
+ categories: new Set([2])
14
+ },
15
+ {
16
+ postname: 'Dogz-3',
17
+ 'post-link': '#',
18
+ 'image-src': 'https://place-puppy.com/puppy/y:100/x:100',
19
+
20
+ categories: new Set([1, 3])
21
+ },
22
+ {
23
+ postname: 'Dogz-4',
24
+ 'post-link': '#',
25
+ 'image-src': 'https://place-puppy.com/puppy/y:100/x:100',
26
+
27
+ categories: new Set([4])
28
+ }
29
+ ];
30
+
31
+ export const devContentCategories = [
32
+ {name: 'grumpy', id: '1', parentid: '6'},
33
+ {name: 'fluffy', id: '2', parentid: '6'},
34
+ {name: 'happy', id: '3', parentid: '6'},
35
+ {name: 'sleepy', id: '4', parentid: '6'},
36
+ {name: 'sweet', id: '5', parentid: '6'},
37
+ {name: 'hounds', id: '6', parentid: null}
38
+ ];
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <link rel="stylesheet" href="../../public/publicBundleBase.css" />
7
+ <link rel="stylesheet" href="./post-filter-module.css" />
8
+ <title>PTFG</title>
9
+ <style>
10
+ body {
11
+ background-color: #e7b8b8;
12
+ }
13
+ main {
14
+ max-width: 600px;
15
+ margin-inline: auto;
16
+ padding: 50px;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <main class="main-container"></main>
22
+ <script async type="module">
23
+ const template = await fetch("./post-filter-module.html");
24
+ const html = await template.text();
25
+ document.querySelector(".main-container").innerHTML = html;
26
+ import blockjs from "./post-filter-module.js";
27
+ blockjs();
28
+ </script>
29
+ </body>
30
+ </html>
@@ -0,0 +1,4 @@
1
+ post-filter-module {
2
+ display: block;
3
+ background-color: aquamarine;
4
+ }
@@ -0,0 +1,11 @@
1
+ <post-filter-module
2
+ id="filter-module"
3
+ data-dev="true"
4
+ data-devcontent="Dogz"
5
+ data-enableclear="true"
6
+ class="post-filter-module__filter"
7
+ >
8
+ <div class="post-filter-module__filter-container">
9
+ <div class="post-filter-module__filter-categories-display"></div>
10
+ </div>
11
+ </post-filter-module>
@@ -0,0 +1,147 @@
1
+ export default function postfiltermoduleJs(options = {}) {
2
+ try {
3
+ customElements.define(
4
+ 'post-filter-module',
5
+ class extends HTMLElement {
6
+ constructor() {
7
+ super();
8
+ this.enableLogs = this.dataset.enablelogs;
9
+ this.filterState = {
10
+ allposts: new Set(),
11
+ filteredposts: new Set(),
12
+ activefilters: new Set(),
13
+ setActiveFilters: function (newState) {
14
+ Object.assign(this.filterState, newState);
15
+ this.dispatchEvent(
16
+ new CustomEvent('activefilters-updated')
17
+ );
18
+ },
19
+ setFilteredPosts: function (newState) {
20
+ Object.assign(this.filterState, newState);
21
+ this.dispatchEvent(
22
+ new CustomEvent('filteredposts-updated')
23
+ );
24
+ }
25
+ };
26
+ this.filterCategoriesDisplay = this.querySelector(
27
+ '.post-filter-module__filter-categories-display'
28
+ );
29
+
30
+ if (this.dataset.enableclear) {
31
+ this.filterCategoriesDisplay.insertAdjacentHTML(
32
+ 'beforeend',
33
+ `<button class="post-filter-module__clear-filters-button">Clear Filters</button>`
34
+ );
35
+ this.clearFiltersButton = this.querySelector(
36
+ '.post-filter-module__clear-filters-button'
37
+ );
38
+ this.clearFiltersButton.addEventListener(
39
+ 'click',
40
+ this.clearFilters.bind(this)
41
+ );
42
+ }
43
+ this.setStateButton = this.querySelector(
44
+ '.post-filter-module__set-state-button'
45
+ );
46
+
47
+ this.addEventListener(
48
+ 'activefilters-updated',
49
+ this.filterPosts.bind(this)
50
+ );
51
+ this.devMode = this.dataset.dev;
52
+ this.devModeContent = this.dataset.devcontent;
53
+ }
54
+ async connectedCallback() {
55
+ console.log('Filter Module element added to page.');
56
+ let data;
57
+ if (this.devMode) {
58
+ data = await import('./dev-content/dev-content.js');
59
+ }
60
+ this.filterState.allposts =
61
+ data[`devContent${this.devModeContent}`];
62
+ this.filterState.categories = data[`devContentCategories`];
63
+ this.filterState.categories.forEach((category) => {
64
+ if (category.parentid) {
65
+ this.filterCategoriesDisplay.insertAdjacentHTML(
66
+ 'beforeend',
67
+ `<button class="post-filter-module__category-button" data-categoryid="${category.id}">${category.name}</button>`
68
+ );
69
+ }
70
+ });
71
+
72
+ this.categorybuttons = this.querySelectorAll(
73
+ '.post-filter-module__category-button'
74
+ );
75
+
76
+ this.categorybuttons.forEach((button) => {
77
+ button.addEventListener('click', () => {
78
+ if (
79
+ this.filterState.activefilters.has(
80
+ Number(button.dataset.categoryid)
81
+ )
82
+ ) {
83
+ const newActiveFilters = new Set(
84
+ this.filterState.activefilters
85
+ );
86
+ newActiveFilters.delete(
87
+ Number(button.dataset.categoryid)
88
+ );
89
+ this.filterState.setActiveFilters.bind(this)({
90
+ activefilters: newActiveFilters
91
+ });
92
+ } else {
93
+ const newActiveFilters = new Set(
94
+ this.filterState.activefilters
95
+ );
96
+ newActiveFilters.add(
97
+ Number(button.dataset.categoryid)
98
+ );
99
+ this.filterState.setActiveFilters.bind(this)({
100
+ activefilters: newActiveFilters
101
+ });
102
+ }
103
+ });
104
+ });
105
+ this.filterState.setFilteredPosts.bind(this)({
106
+ filteredposts: this.filterState.allposts
107
+ });
108
+
109
+ this.classList.add('loaded');
110
+ }
111
+
112
+ attributeChangedCallback(name, oldValue, newValue) {
113
+ // console.log(`Attribute ${name} has changed.`);
114
+ }
115
+ filterPosts(event) {
116
+ if (this.filterState.activefilters.size === 0) {
117
+ this.filterState.setFilteredPosts.bind(this)({
118
+ filteredposts: this.filterState.allposts
119
+ });
120
+ return;
121
+ }
122
+
123
+ const newFilteredPosts = this.filterState.allposts.filter(
124
+ (post) => {
125
+ return (
126
+ this.filterState.activefilters.intersection(
127
+ post.categories
128
+ ).size > 0
129
+ );
130
+ }
131
+ );
132
+
133
+ this.filterState.setFilteredPosts.bind(this)({
134
+ filteredposts: newFilteredPosts
135
+ });
136
+ }
137
+ clearFilters(event) {
138
+ this.filterState.setActiveFilters.bind(this)({
139
+ activefilters: new Set()
140
+ });
141
+ }
142
+ }
143
+ );
144
+ } catch (error) {
145
+ console.error(error);
146
+ }
147
+ }