@cocreate/elements 1.42.0 → 1.42.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/elements",
3
- "version": "1.42.0",
3
+ "version": "1.42.1",
4
4
  "description": "Fetch content into any html element by using html5 attributes to query data stored in CoCreate headless CMS. If data is changed it will instantly reflect in html tags as changes are broadcasted in realtime",
5
5
  "keywords": [
6
6
  "elements",
@@ -45,25 +45,21 @@
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.4",
62
- "@cocreate/crud-client": "^1.33.11",
63
- "@cocreate/element-prototype": "^1.23.0",
64
- "@cocreate/filter": "^1.15.1",
65
- "@cocreate/observer": "^1.16.3",
66
- "@cocreate/render": "^1.41.3",
67
- "@cocreate/utils": "^1.34.1"
57
+ "@cocreate/actions": "^1.21.0",
58
+ "@cocreate/crud-client": "^1.34.1",
59
+ "@cocreate/element-prototype": "^1.29.0",
60
+ "@cocreate/filter": "^1.33.1",
61
+ "@cocreate/observer": "^1.18.0",
62
+ "@cocreate/render": "^1.45.1",
63
+ "@cocreate/utils": "^1.38.0"
68
64
  }
69
65
  }
package/src/fetchSrc.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import observer from "@cocreate/observer";
2
+ import { ObjectId } from "@cocreate/utils";
2
3
 
3
4
  const selector =
4
5
  "[src]:not(img, video, audio, script, input, iframe, frame, link, source), [source], [stream]";
@@ -46,8 +47,12 @@ async function initElements(elements) {
46
47
  pathElement.getAttribute("path") || getPath();
47
48
  if (path) text = text.replaceAll("$relativePath", path);
48
49
  }
50
+
51
+ text = text.replaceAll("ObjectId()", () => {
52
+ // Generate a NEW ObjectId inside the function
53
+ return ObjectId().toString(); // Return its string representation
54
+ });
49
55
  element.setValue(text);
50
- initializing.delete(element);
51
56
  }
52
57
  }
53
58
  } catch (err) {
@@ -269,8 +274,9 @@ observer.init({
269
274
  if (
270
275
  mutation.oldValue !==
271
276
  mutation.target.getAttribute(mutation.attributeName)
272
- )
277
+ ) {
273
278
  init(mutation.target);
279
+ }
274
280
  }
275
281
  });
276
282
 
package/src/index.js CHANGED
@@ -68,9 +68,9 @@ async function init(element) {
68
68
  !(element instanceof HTMLCollection) &&
69
69
  !(element instanceof NodeList) &&
70
70
  !Array.isArray(element)
71
- )
71
+ ) {
72
72
  element = [element];
73
- else if (!element) {
73
+ } else if (!element) {
74
74
  element = document.querySelectorAll(selector);
75
75
  initSocket();
76
76
  }
@@ -850,11 +850,7 @@ async function getData(form) {
850
850
  if (attribute.includes("save", "delete")) continue;
851
851
  }
852
852
 
853
- if (
854
- element.matches(
855
- "[render-selector], [render-closest], [render-parent], [render-next], [render-previous]"
856
- )
857
- ) {
853
+ if (element.matches("[render-query]")) {
858
854
  let type = element.getAttribute("type");
859
855
  if (type !== "file") continue;
860
856
  }
@@ -997,7 +993,7 @@ async function getData(form) {
997
993
  }
998
994
 
999
995
  //dataKey should be used to group
1000
- let key = dataKey + Data.method;
996
+ let key = dataKey; //+ Data.method;
1001
997
  if (dataKeys.has(key)) {
1002
998
  let storedData = dataKeys.get(key)[Data.type];
1003
999
  dataKeys.get(key)[Data.type] = {
@@ -1314,6 +1310,9 @@ function initSocket() {
1314
1310
  if (data.rendered) return;
1315
1311
 
1316
1312
  data.rendered = true;
1313
+ if (data && data.key === "answers") {
1314
+ console.log("test");
1315
+ }
1317
1316
 
1318
1317
  setData(null, data);
1319
1318
  });
@@ -1514,8 +1513,8 @@ Observer.init({
1514
1513
  callback: function (mutation) {
1515
1514
  let currentValue = mutation.target.getAttribute(mutation.attributeName);
1516
1515
  if (currentValue !== mutation.oldValue) {
1517
- remove(mutation.target);
1518
1516
  if (mutation.target.tagName === "FORM") return;
1517
+ remove(mutation.target);
1519
1518
  init([mutation.target]);
1520
1519
  }
1521
1520
  }
@@ -1535,11 +1534,15 @@ Actions.init([
1535
1534
  callback: async (action) => {
1536
1535
  // TODO: use selector to target elements for deletion if element is apart of render get render get rendering element for more crud detils
1537
1536
  // this way any selector can be used to target crud deletions not just .selected
1538
- let elements = queryElements({
1539
- element: action.element,
1540
- prefix: "delete"
1541
- });
1542
- if (elements === false) elements = [action.element];
1537
+ let elements = [];
1538
+ if (action.element.hasAttribute("delete-query")) {
1539
+ elements = queryElements({
1540
+ element: action.element,
1541
+ prefix: "delete"
1542
+ });
1543
+ } else {
1544
+ elements = [action.element];
1545
+ }
1543
1546
 
1544
1547
  for (let i = 0; i < elements.length; i++) {
1545
1548
  const data = getObject(elements[i]);
package/src/value.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import Observer from "@cocreate/observer";
2
2
  import "@cocreate/element-prototype";
3
+ import { queryElements } from "@cocreate/utils";
3
4
 
4
- const selector =
5
- "[value-selector], [value-closest], [value-parent], [value-next], [value-previous], [value-document], [value-frame], [value-top]";
5
+ const selector = "[value-query]";
6
6
 
7
7
  /**
8
8
  * Initializes elements with value-* attributes to enable dynamic value retrieval and setting.
@@ -32,7 +32,7 @@ async function init(element) {
32
32
  * @param {HTMLElement} element - The element to initialize.
33
33
  */
34
34
  function initElement(element) {
35
- let targets = element.queryElements();
35
+ let targets = queryElements({ element, prefix: "value" });
36
36
 
37
37
  valueHandler(element, targets, true);
38
38
  }
@@ -43,7 +43,7 @@ function initElement(element) {
43
43
  * @param {HTMLElement} element - The element to set the value on.
44
44
  * @param {object} targets - An object containing elements retrieved by queryElements().
45
45
  */
46
- function valueHandler(element, targets = [], initialize) {
46
+ function valueHandler(element, targets, initialize) {
47
47
  let values = [];
48
48
  // TODO: consdier the potential of targets being an array of elements, should value be an array of the values?
49
49
  for (let i = 0; i < targets.length; i++) {
@@ -96,16 +96,7 @@ Observer.init({
96
96
  Observer.init({
97
97
  name: "CoCreateElementsAttributes",
98
98
  types: ["attributes"],
99
- attributeFilter: [
100
- "value-selector",
101
- "value-closest",
102
- "value-parent",
103
- "value-next",
104
- "value-previous",
105
- "value-document",
106
- "value-frame",
107
- "value-top"
108
- ],
99
+ attributeFilter: ["value-query"],
109
100
  callback: function (mutation) {
110
101
  let currentValue = mutation.target.getAttribute(mutation.attributeName);
111
102
  if (currentValue !== mutation.oldValue) {
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-elements": "./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", "elements"],
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-elements": "./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", "elements"],
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
+ };