@cocreate/events 1.27.0 → 1.27.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/events",
3
- "version": "1.27.0",
3
+ "version": "1.27.1",
4
4
  "description": "A simple events component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "events",
@@ -45,22 +45,18 @@
45
45
  },
46
46
  "main": "./src/index.js",
47
47
  "devDependencies": {
48
- "@babel/core": "^7.9.6",
49
- "@babel/preset-env": "^7.9.6",
50
- "babel-loader": "^8.1.0",
51
- "clean-webpack-plugin": "^3.0.0",
52
- "file-loader": "^6.2.0",
48
+ "css-loader": "^5.1.3",
49
+ "esbuild": "^0.25.2",
50
+ "esbuild-loader": "^4.3.0",
53
51
  "mini-css-extract-plugin": "^1.5.0",
54
- "style-loader": "^3.3.1",
55
- "terser-webpack-plugin": "^5.1.1",
56
52
  "webpack": "^5.24.4",
57
53
  "webpack-cli": "^4.5.0",
58
54
  "webpack-log": "^3.0.1"
59
55
  },
60
56
  "dependencies": {
61
- "@cocreate/actions": "^1.18.2",
62
- "@cocreate/element-prototype": "^1.23.0",
63
- "@cocreate/observer": "^1.16.1",
64
- "@cocreate/utils": "^1.33.7"
57
+ "@cocreate/actions": "^1.21.0",
58
+ "@cocreate/element-prototype": "^1.29.0",
59
+ "@cocreate/observer": "^1.18.0",
60
+ "@cocreate/utils": "^1.38.0"
65
61
  }
66
62
  }
package/src/index.js CHANGED
@@ -89,7 +89,7 @@ const CoCreateEvents = {
89
89
  }
90
90
  });
91
91
 
92
- let selector = `[${prefix}], [${prefix}-key], [${prefix}-attribute], [${prefix}-value], [${prefix}-action], [${prefix}-selector], [${prefix}-closest], [${prefix}-parent], [${prefix}-next], [${prefix}-previous], [${prefix}-preventDefault], [${prefix}-stopPropagation], [${prefix}-stopImmediatePropagation]`;
92
+ let selector = `[${prefix}], [${prefix}-key], [${prefix}-attribute], [${prefix}-value], [${prefix}-action], [${prefix}-query], [${prefix}-preventDefault], [${prefix}-stopPropagation], [${prefix}-stopImmediatePropagation]`;
93
93
 
94
94
  observer.init({
95
95
  name: "CoCreateEventattributes",
@@ -97,11 +97,7 @@ const CoCreateEvents = {
97
97
  attributeFilter: [
98
98
  `${prefix}-key`,
99
99
  `${prefix}-value`,
100
- `${prefix}-selector`,
101
- `${prefix}-closest`,
102
- `${prefix}-parent`,
103
- `${prefix}-next`,
104
- `${prefix}-previous`,
100
+ `${prefix}-query`,
105
101
  `${prefix}-events`,
106
102
  `${prefix}-bubbles`,
107
103
  `${prefix}-cancelable`,
@@ -174,15 +170,7 @@ const CoCreateEvents = {
174
170
  if (attribute.name === "observe-target") {
175
171
  target = attribute.value;
176
172
  break;
177
- } else if (
178
- [
179
- `${prefix}-selector`,
180
- `${prefix}-closest`,
181
- `${prefix}-parent`,
182
- `${prefix}-next`,
183
- `${prefix}-previous`
184
- ].includes(attribute.name)
185
- ) {
173
+ } else if ([`${prefix}-query`].includes(attribute.name)) {
186
174
  target = attribute.value;
187
175
  break;
188
176
  }
@@ -371,7 +359,7 @@ const CoCreateEvents = {
371
359
  prefixes[prefix].events
372
360
  );
373
361
 
374
- // let selector = `[${prefix}], [${prefix}-key], [${prefix}-value], [${prefix}-selector], [${prefix}-closest], [${prefix}-parent], [${prefix}-next], [${prefix}-previous]`
362
+ // let selector = `[${prefix}], [${prefix}-key], [${prefix}-value], [${prefix}-query]`
375
363
 
376
364
  // let parentElement = target.parentElement;
377
365
  // if (parentElement) {
@@ -473,7 +461,9 @@ const CoCreateEvents = {
473
461
  values = localStorage.getItem(key);
474
462
  } else if ((key = element.getAttribute("localstorage-set"))) {
475
463
  values = await element.getValue();
476
- if (values) localStorage.setItem(key, values);
464
+ if (values) {
465
+ localStorage.setItem(key, values);
466
+ }
477
467
  }
478
468
 
479
469
  // if (!key || !values)
@@ -486,29 +476,41 @@ const CoCreateEvents = {
486
476
  element,
487
477
  prefix: `${prefix}-value`
488
478
  });
489
- if (valueElements) {
479
+ if (valueElements.length) {
490
480
  let elementValues = [];
491
- for (let i = 0; i < valueElements.length; i++)
481
+ for (let i = 0; i < valueElements.length; i++) {
492
482
  elementValues.push(valueElements[i].getValue());
493
-
494
- if (elementValues.length) values = elementValues;
483
+ }
484
+ if (elementValues.length) {
485
+ values = elementValues;
486
+ }
495
487
  }
496
488
  }
497
489
 
498
- if (values === null)
490
+ if (values === null) {
499
491
  values = element.getAttribute(`${prefix}-if-value`);
500
- if (values === null) values = element.getAttribute(prefix);
492
+ }
493
+ if (values === null) {
494
+ values = element.getAttribute(prefix);
495
+ }
501
496
  }
502
497
 
503
498
  if (values || values === "") {
504
- if (typeof values === "string") values = values.split(",");
505
- else if (!Array.isArray(values)) values = [values];
499
+ if (typeof values === "string") {
500
+ values = values.split(",");
501
+ } else if (!Array.isArray(values)) {
502
+ values = [values];
503
+ }
506
504
  } else {
507
505
  values = await element.getValue();
508
- if (!Array.isArray(values)) values = [values];
506
+ if (!Array.isArray(values)) {
507
+ values = [values];
508
+ }
509
509
  }
510
510
 
511
- if ((targetAttribute && !values) || values.length === 0) return;
511
+ if ((targetAttribute && !values) || values.length === 0) {
512
+ return;
513
+ }
512
514
 
513
515
  let ifCondition = element.getAttribute(`${prefix}-if`);
514
516
  let elseCondition = element.getAttribute(`${prefix}-else`);
@@ -518,29 +520,51 @@ const CoCreateEvents = {
518
520
  if (!ifValue && ifValue !== "")
519
521
  ifValue = (await element.getValue()) || values;
520
522
  //values // await element.getValue()
521
- else if (ifValue || ifValue === "") ifValue = [ifValue];
522
- else ifValue = values;
523
+ else if (ifValue || ifValue === "") {
524
+ ifValue = [ifValue];
525
+ } else {
526
+ ifValue = values;
527
+ }
523
528
 
524
- if (!Array.isArray(ifValue)) ifValue = [ifValue];
529
+ if (!Array.isArray(ifValue)) {
530
+ ifValue = [ifValue];
531
+ }
525
532
  }
526
533
 
527
534
  //TODO: improved resize toggling of values
528
535
  // let hasCondition = this.elements2.get(element)
529
- if (ifCondition && evaluateCondition(ifCondition, ifValue)) {
530
- // if (hasCondition && hasCondition.condition === ifCondition) {
531
- // return
532
- // } else
533
- // this.elements2.set(element, { condition: ifCondition })
534
- } else if (
535
- elseCondition &&
536
- evaluateCondition(elseCondition, ifValue)
537
- ) {
538
- // if (hasCondition && hasCondition.condition === elseCondition) {
539
- // return
540
- // } else
541
- // this.elements2.set(element, { condition: elseCondition })
542
- } else if (ifCondition || elseCondition) {
543
- return;
536
+ if (ifCondition) {
537
+ if (evaluateCondition(ifCondition, ifValue)) {
538
+ // Action 1: Condition exists and evaluates true
539
+ // console.log("Executing Action 1 for ifCondition:", ifCondition); // Optional debug log
540
+ // Replace this comment with your actual code for Path 1
541
+ // e.g., this.elements2.set(element, { condition: ifCondition });
542
+
543
+ // Assuming we stop processing for this element once a condition is met and actioned
544
+ return;
545
+ } else {
546
+ // Condition existed but evaluated false. Stop processing.
547
+ // Corresponds to the original `else if (ifCondition || elseCondition) { return; }` for the ifCondition case
548
+ return;
549
+ }
550
+ }
551
+
552
+ // If we reach here, ifCondition was falsy (didn't exist)
553
+ // Now check the 'else' condition
554
+ if (elseCondition) {
555
+ if (evaluateCondition(elseCondition, ifValue)) {
556
+ // Action 2: Condition exists and evaluates true
557
+ // console.log("Executing Action 2 for elseCondition:", elseCondition); // Optional debug log
558
+ // Replace this comment with your actual code for Path 2
559
+ // e.g., this.elements2.set(element, { condition: elseCondition });
560
+
561
+ // Assuming we stop processing for this element once a condition is met and actioned
562
+ return;
563
+ } else {
564
+ // Condition existed but evaluated false. Stop processing.
565
+ // Corresponds to the original `else if (ifCondition || elseCondition) { return; }` for the elseCondition case
566
+ return;
567
+ }
544
568
  }
545
569
 
546
570
  let targetText = element.getAttribute(`${prefix}-text`);
@@ -548,12 +572,17 @@ const CoCreateEvents = {
548
572
  let targetKey = element.getAttribute(`${prefix}-key`);
549
573
 
550
574
  if (prefix === "selected") {
551
- if (el !== element) element.removeAttribute("selected");
552
- else element.setAttribute("selected", "");
575
+ if (el !== element) {
576
+ element.removeAttribute("selected");
577
+ } else {
578
+ element.setAttribute("selected", "");
579
+ }
553
580
  }
554
581
 
555
582
  let deactivate = false;
556
- if (el !== element) deactivate = true;
583
+ if (el !== element) {
584
+ deactivate = true;
585
+ }
557
586
  // values = values.map(x => x.trim());
558
587
 
559
588
  values = values.map((x) => {
@@ -564,14 +593,14 @@ const CoCreateEvents = {
564
593
  }
565
594
  return x; // Return the updated x
566
595
  });
567
-
568
- let targetElements = queryElements({
569
- element,
570
- prefix,
571
- selector: params
572
- });
573
-
574
- if (targetElements === false) {
596
+ let targetElements;
597
+ if (element.hasAttribute(`${prefix}-query`)) {
598
+ targetElements = queryElements({
599
+ element,
600
+ prefix,
601
+ selector: params
602
+ });
603
+ } else {
575
604
  targetElements = [element];
576
605
  }
577
606
 
@@ -1080,7 +1109,7 @@ async function handleElementProcessingWithBackoff(element) {
1080
1109
  if (element.hasAttribute("onload-attribute")) {
1081
1110
  /* ... */
1082
1111
  }
1083
- if (element.hasAttribute("onload-next")) {
1112
+ if (element.hasAttribute("onload-query")) {
1084
1113
  /* ... */
1085
1114
  }
1086
1115
  } else {
package/webpack.config.js CHANGED
@@ -1,90 +1,65 @@
1
- const path = require("path")
2
- const TerserPlugin = require("terser-webpack-plugin")
3
- const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4
- const { CleanWebpackPlugin } = require("clean-webpack-plugin")
5
-
6
- module.exports = (env, argv) => {
7
- let isProduction = false
8
- if (argv.mode === 'production')
9
- isProduction = true
10
-
11
- const config = {
12
- entry: {
13
- "CoCreate-events": "./src/index.js",
14
- },
15
- output: {
16
- path: path.resolve(__dirname, "dist"),
17
- filename: isProduction ? "[name].min.js" : "[name].js",
18
- libraryTarget: "umd",
19
- libraryExport: "default",
20
- library: ["CoCreate", "events"],
21
- globalObject: "this",
22
- },
23
-
24
- plugins: [
25
- new CleanWebpackPlugin(),
26
- new MiniCssExtractPlugin({
27
- filename: "[name].css",
28
- }),
29
- ],
30
- // Default mode for Webpack is production.
31
- // Depending on mode Webpack will apply different things
32
- // on final bundle. For now we don't need production's JavaScript
33
- // minifying and other thing so let's set mode to development
34
- mode: isProduction ? "production" : "development",
35
- module: {
36
- rules: [
37
- {
38
- test: /.js$/,
39
- exclude: /(node_modules)/,
40
- use: {
41
- loader: "babel-loader",
42
- options: {
43
- plugins: ["@babel/plugin-transform-modules-commonjs"],
44
- },
45
- },
46
- },
47
- {
48
- test: /.css$/i,
49
- use: [
50
- { loader: "style-loader", options: { injectType: "linkTag" } },
51
- "file-loader",
52
- ],
53
- },
54
- ],
55
- },
56
-
57
- // add source map
58
- ...(isProduction ? {} : { devtool: "eval-source-map" }),
59
-
60
- optimization: {
61
- minimize: true,
62
- minimizer: [
63
- new TerserPlugin({
64
- extractComments: true,
65
- // cache: true,
66
- parallel: true,
67
- // sourceMap: true, // Must be set to true if using source-maps in production
68
- terserOptions: {
69
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
70
- // extractComments: 'all',
71
- compress: {
72
- drop_console: true,
73
- },
74
- },
75
- }),
76
- ],
77
- splitChunks: {
78
- chunks: "all",
79
- minSize: 200,
80
- // maxSize: 99999,
81
- //minChunks: 1,
82
-
83
- cacheGroups: {
84
- defaultVendors: false,
85
- },
86
- },
87
- },
88
- }
89
- return config
90
- }
1
+ const path = require("path");
2
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
3
+ const { EsbuildPlugin } = require("esbuild-loader");
4
+ const { FileUploader } = require("@cocreate/webpack");
5
+
6
+ module.exports = async (env, argv) => {
7
+ const isProduction = argv && argv.mode === "production";
8
+ const config = {
9
+ entry: {
10
+ "CoCreate-events": "./src/index.js"
11
+ },
12
+ output: {
13
+ path: path.resolve(__dirname, "dist"),
14
+ filename: isProduction ? "[name].min.js" : "[name].js",
15
+ libraryExport: "default",
16
+ library: ["CoCreate", "events"],
17
+ clean: true
18
+ },
19
+ plugins: [
20
+ new MiniCssExtractPlugin({
21
+ filename: isProduction ? "[name].min.css" : "[name].css"
22
+ }),
23
+ new FileUploader(env, argv)
24
+ ],
25
+ mode: isProduction ? "production" : "development",
26
+ devtool: isProduction ? "source-map" : "eval-source-map",
27
+ module: {
28
+ rules: [
29
+ {
30
+ test: /.js$/,
31
+ exclude: /node_modules/,
32
+ use: {
33
+ loader: "esbuild-loader",
34
+ options: {
35
+ loader: "js",
36
+ target: "es2017"
37
+ }
38
+ }
39
+ },
40
+ {
41
+ test: /.css$/i,
42
+ use: [MiniCssExtractPlugin.loader, "css-loader"]
43
+ }
44
+ ]
45
+ },
46
+ optimization: {
47
+ minimize: isProduction,
48
+ minimizer: [
49
+ new EsbuildPlugin({
50
+ target: "es2017",
51
+ css: true
52
+ })
53
+ ],
54
+ splitChunks: {
55
+ cacheGroups: {
56
+ defaultVendors: false
57
+ }
58
+ }
59
+ },
60
+ performance: {
61
+ hints: isProduction ? "warning" : false
62
+ }
63
+ };
64
+ return config;
65
+ };