@cocreate/events 1.27.0 → 1.27.2
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/CHANGELOG.md +18 -0
- package/demo/click.html +83 -83
- package/demo/hover.html +65 -65
- package/demo/index.html +124 -124
- package/demo/observer.html +36 -33
- package/demo/selected.html +78 -78
- package/demo/set-value.html +2 -2
- package/docs/index.html +350 -346
- package/package.json +8 -12
- package/src/index.js +86 -57
- package/webpack.config.js +65 -90
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/events",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.2",
|
|
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
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
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.
|
|
62
|
-
"@cocreate/element-prototype": "^1.
|
|
63
|
-
"@cocreate/observer": "^1.
|
|
64
|
-
"@cocreate/utils": "^1.
|
|
57
|
+
"@cocreate/actions": "^1.21.1",
|
|
58
|
+
"@cocreate/element-prototype": "^1.29.1",
|
|
59
|
+
"@cocreate/observer": "^1.18.1",
|
|
60
|
+
"@cocreate/utils": "^1.39.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}-
|
|
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}-
|
|
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}-
|
|
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)
|
|
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)
|
|
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
|
-
|
|
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")
|
|
505
|
-
|
|
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))
|
|
506
|
+
if (!Array.isArray(values)) {
|
|
507
|
+
values = [values];
|
|
508
|
+
}
|
|
509
509
|
}
|
|
510
510
|
|
|
511
|
-
if ((targetAttribute && !values) || values.length === 0)
|
|
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 === "")
|
|
522
|
-
|
|
523
|
+
else if (ifValue || ifValue === "") {
|
|
524
|
+
ifValue = [ifValue];
|
|
525
|
+
} else {
|
|
526
|
+
ifValue = values;
|
|
527
|
+
}
|
|
523
528
|
|
|
524
|
-
if (!Array.isArray(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
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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)
|
|
552
|
-
|
|
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)
|
|
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
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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-
|
|
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
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
module.exports = (env, argv) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
};
|