@cocreate/print 1.0.1 → 1.0.3

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 CHANGED
@@ -1,3 +1,20 @@
1
+ ## [1.0.3](https://github.com/CoCreate-app/CoCreate-print/compare/v1.0.2...v1.0.3) (2025-05-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * added css-loader ([5dbcad6](https://github.com/CoCreate-app/CoCreate-print/commit/5dbcad68fe262c6a270ebc7904b805735a1d3e68))
7
+ * update [@cocreate](https://github.com/cocreate) dependencies ([680c5ea](https://github.com/CoCreate-app/CoCreate-print/commit/680c5ea73f378ed8d862279ba7d5900b6011914b))
8
+ * update query attributes ([c81e808](https://github.com/CoCreate-app/CoCreate-print/commit/c81e8081a718e5725f34b5f82ea34dbc0b01c412))
9
+ * webpack.config and devdependencies ([0a7072b](https://github.com/CoCreate-app/CoCreate-print/commit/0a7072b0dfb21a962fa9e4d333dbba91befcb257))
10
+
11
+ ## [1.0.2](https://github.com/CoCreate-app/CoCreate-print/compare/v1.0.1...v1.0.2) (2024-12-14)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * dispatch printed event ([1acdb66](https://github.com/CoCreate-app/CoCreate-print/commit/1acdb66d9f7988fd5494a0f035c5227e1ba7d831))
17
+
1
18
  ## [1.0.1](https://github.com/CoCreate-app/CoCreate-print/compare/v1.0.0...v1.0.1) (2024-12-14)
2
19
 
3
20
 
package/docs/index.html CHANGED
@@ -180,7 +180,7 @@
180
180
  show="#eye-slash"
181
181
  hide="#eye, #demo-preview"
182
182
  toggle="code-height"
183
- toggle-selector="#demo-code"
183
+ toggle-query="#demo-code"
184
184
  ><i
185
185
  class="height:18px"
186
186
  src="/assets/svg/eye.svg"></i
@@ -192,7 +192,7 @@
192
192
  show="#eye, #demo-preview"
193
193
  hide="#eye-slash"
194
194
  toggle="code-height"
195
- toggle-selector="#demo-code"
195
+ toggle-query="#demo-code"
196
196
  ><i src="/assets/svg/eye-slash.svg"></i
197
197
  ></a>
198
198
  <a
@@ -215,7 +215,7 @@
215
215
  <a
216
216
  class="margin-right:5px"
217
217
  fullscreen
218
- fullscreen-selector="#playground"></a>
218
+ fullscreen-query="#playground"></a>
219
219
  </div>
220
220
  </div>
221
221
  <!-- End SandBox -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/print",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A simple print component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "print",
@@ -45,21 +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.20.0",
62
- "@cocreate/observer": "1.17.0",
63
- "@cocreate/utils": "1.37.0"
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"
64
61
  }
65
62
  }
package/src/index.js CHANGED
@@ -10,8 +10,7 @@ import { queryElements } from "@cocreate/utils";
10
10
  import Actions from "@cocreate/actions";
11
11
  import Observer from "@cocreate/observer";
12
12
 
13
- const selector =
14
- "[print-selector], [print-closest], [print-parent], [print-next], [print-previous]";
13
+ const selector = "[print-query]";
15
14
 
16
15
  function init(element) {
17
16
  if (!element) {
@@ -46,8 +45,10 @@ function initElement(element) {
46
45
  }
47
46
 
48
47
  function queryPrintElement(element) {
49
- let elements = queryElements({ element, prefix: "print" });
50
- if (elements === false) {
48
+ let elements = [];
49
+ if (element.hasAttribute("print-query")) {
50
+ elements = queryElements({ element, prefix: "print" });
51
+ } else {
51
52
  elements = [element];
52
53
  }
53
54
  print(elements);
@@ -110,6 +111,12 @@ function print(elements) {
110
111
  // Remove iframe after printing
111
112
  iframe.parentNode.removeChild(iframe);
112
113
  };
114
+
115
+ document.dispatchEvent(
116
+ new CustomEvent("printed", {
117
+ detail: { content }
118
+ })
119
+ );
113
120
  }
114
121
 
115
122
  init();
@@ -126,7 +133,7 @@ Actions.init([
126
133
 
127
134
  Observer.init({
128
135
  name: "CoCreatePrintAddedNodes",
129
- observe: ["addedNodes"],
136
+ types: ["addedNodes"],
130
137
  selector,
131
138
  callback(mutation) {
132
139
  initElement(mutation.target);
@@ -135,14 +142,8 @@ Observer.init({
135
142
 
136
143
  Observer.init({
137
144
  name: "CoCreatePrintObserver",
138
- observe: ["attributes"],
139
- attributeName: [
140
- "print-selector",
141
- "print-closest",
142
- "print-parent",
143
- "print-next",
144
- "print-previous"
145
- ],
145
+ types: ["attributes"],
146
+ attributeFilter: ["print-query"],
146
147
  selector,
147
148
  callback: function (mutation) {
148
149
  initElement(mutation.target);
package/webpack.config.js CHANGED
@@ -1,94 +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") isProduction = true;
9
-
10
- const config = {
11
- entry: {
12
- "CoCreate-print": "./src/index.js"
13
- },
14
- output: {
15
- path: path.resolve(__dirname, "dist"),
16
- filename: isProduction ? "[name].min.js" : "[name].js",
17
- libraryTarget: "umd",
18
- libraryExport: "default",
19
- library: ["CoCreate", "print"],
20
- globalObject: "this"
21
- },
22
-
23
- plugins: [
24
- new CleanWebpackPlugin(),
25
- new MiniCssExtractPlugin({
26
- filename: "[name].css"
27
- })
28
- ],
29
- // Default mode for Webpack is production.
30
- // Depending on mode Webpack will apply different things
31
- // on final bundle. For now we don't need production's JavaScript
32
- // minifying and other thing so let's set mode to development
33
- mode: isProduction ? "production" : "development",
34
- module: {
35
- rules: [
36
- {
37
- test: /.js$/,
38
- exclude: /(node_modules)/,
39
- use: {
40
- loader: "babel-loader",
41
- options: {
42
- plugins: [
43
- "@babel/plugin-transform-modules-commonjs"
44
- ]
45
- }
46
- }
47
- },
48
- {
49
- test: /.css$/i,
50
- use: [
51
- {
52
- loader: "style-loader",
53
- options: { injectType: "linkTag" }
54
- },
55
- "file-loader"
56
- ]
57
- }
58
- ]
59
- },
60
-
61
- // add source map
62
- ...(isProduction ? {} : { devtool: "eval-source-map" }),
63
-
64
- optimization: {
65
- minimize: true,
66
- minimizer: [
67
- new TerserPlugin({
68
- extractComments: true,
69
- // cache: true,
70
- parallel: true,
71
- // sourceMap: true, // Must be set to true if using source-maps in production
72
- terserOptions: {
73
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
74
- // extractComments: 'all',
75
- compress: {
76
- drop_console: true
77
- }
78
- }
79
- })
80
- ],
81
- splitChunks: {
82
- chunks: "all",
83
- minSize: 200,
84
- // maxSize: 99999,
85
- //minChunks: 1,
86
-
87
- cacheGroups: {
88
- defaultVendors: false
89
- }
90
- }
91
- }
92
- };
93
- return config;
94
- };
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-print": "./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", "print"],
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
+ };