@cocreate/clipboard 1.0.0 → 1.1.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.
@@ -22,13 +22,13 @@ jobs:
22
22
  runs-on: ubuntu-latest
23
23
  steps:
24
24
  - name: Checkout
25
- uses: actions/checkout@v3
25
+ uses: actions/checkout@v4
26
26
  - name: Setup Node.js
27
- uses: actions/setup-node@v3
27
+ uses: actions/setup-node@v4
28
28
  with:
29
- node-version: 14
29
+ node-version: 22 # Required for the latest semantic-release plugins
30
30
  - name: Semantic Release
31
- uses: cycjimmy/semantic-release-action@v3
31
+ uses: cycjimmy/semantic-release-action@v4 # Update to v4 for better Node 20+ support
32
32
  id: semantic
33
33
  with:
34
34
  extra_plugins: |
@@ -36,9 +36,8 @@ jobs:
36
36
  @semantic-release/git
37
37
  @semantic-release/github
38
38
  env:
39
- GITHUB_TOKEN: "${{ secrets.GITHUB }}"
39
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # Use the built-in token if possible
40
40
  NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
41
41
  outputs:
42
42
  new_release_published: "${{ steps.semantic.outputs.new_release_published }}"
43
43
  new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
44
-
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [1.1.1](https://github.com/CoCreate-app/CoCreate-clipboard/compare/v1.1.0...v1.1.1) (2026-01-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update worklow ([c54f11a](https://github.com/CoCreate-app/CoCreate-clipboard/commit/c54f11a9df499522afc5805d99538099d7314704))
7
+
8
+ # [1.1.0](https://github.com/CoCreate-app/CoCreate-clipboard/compare/v1.0.0...v1.1.0) (2025-05-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * added css-loader ([03d2c12](https://github.com/CoCreate-app/CoCreate-clipboard/commit/03d2c12b1f56ced186877939c15e81932ed6e871))
14
+ * update [@cocreate](https://github.com/cocreate) dependencies ([22fa8a8](https://github.com/CoCreate-app/CoCreate-clipboard/commit/22fa8a8329001ba632b2430ae564c941090a6c09))
15
+ * update query attributes ([48297b3](https://github.com/CoCreate-app/CoCreate-clipboard/commit/48297b37408552c5c765d812124ff510e65e7751))
16
+ * webpack.config and devdependencies ([bd741fc](https://github.com/CoCreate-app/CoCreate-clipboard/commit/bd741fca61bd135a811f743689d2ba5faaaa13bd))
17
+
18
+
19
+ ### Features
20
+
21
+ * handles rich text editors and plain text editors ([3cfd47b](https://github.com/CoCreate-app/CoCreate-clipboard/commit/3cfd47ba9f3837f87aa7c46644edcfb28dc304b9))
22
+
1
23
  # 1.0.0 (2024-12-14)
2
24
 
3
25
 
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,18 +1,10 @@
1
1
  {
2
2
  "name": "@cocreate/clipboard",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "A simple clipboard component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "clipboard",
7
- "cocreate",
8
- "low-code-framework",
9
- "no-code-framework",
10
- "cocreatejs",
11
- "cocreatejs-component",
12
- "cocreate-framework",
13
- "no-code",
14
7
  "low-code",
15
- "collaborative-framework",
16
8
  "realtime",
17
9
  "realtime-framework",
18
10
  "collaboration",
@@ -45,21 +37,18 @@
45
37
  },
46
38
  "main": "./src/index.js",
47
39
  "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",
40
+ "css-loader": "^5.1.3",
41
+ "esbuild": "^0.25.2",
42
+ "esbuild-loader": "^4.3.0",
53
43
  "mini-css-extract-plugin": "^1.5.0",
54
- "style-loader": "^3.3.1",
55
- "terser-webpack-plugin": "^5.1.1",
56
44
  "webpack": "^5.24.4",
57
45
  "webpack-cli": "^4.5.0",
58
46
  "webpack-log": "^3.0.1"
59
47
  },
60
48
  "dependencies": {
61
- "@cocreate/actions": "1.20.0",
62
- "@cocreate/observer": "1.17.0",
63
- "@cocreate/utils": "1.37.0"
49
+ "@cocreate/actions": "^1.21.1",
50
+ "@cocreate/element-prototype": "^1.29.1",
51
+ "@cocreate/observer": "^1.18.1",
52
+ "@cocreate/utils": "^1.39.0"
64
53
  }
65
54
  }
package/src/index.js CHANGED
@@ -10,28 +10,22 @@ 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
- "[clipboard-selector], [clipboard-closest], [clipboard-parent], [clipboard-next], [clipboard-previous]";
13
+ const selector = "[clipboard-query]";
15
14
 
16
15
  function init(element) {
17
16
  if (!element) {
18
17
  element = document.querySelectorAll(selector);
19
- for (let i = 0; i < element.length; i++) {
18
+ } else if (
19
+ !(element instanceof HTMLCollection) &&
20
+ !(element instanceof NodeList) &&
21
+ !Array.isArray(element)
22
+ ) {
23
+ element = [element];
24
+ }
25
+ for (let i = 0; i < element.length; i++) {
26
+ if (element[i].matches(selector)) {
20
27
  initElement(element[i]);
21
28
  }
22
- } else {
23
- if (
24
- !(element instanceof HTMLCollection) &&
25
- !(element instanceof NodeList) &&
26
- !Array.isArray(element)
27
- ) {
28
- element = [element];
29
- }
30
- for (let i = 0; i < element.length; i++) {
31
- if (element[i].matches(selector)) {
32
- initElement(element[i]);
33
- }
34
- }
35
29
  }
36
30
  }
37
31
 
@@ -46,14 +40,17 @@ function initElement(element) {
46
40
  }
47
41
 
48
42
  function queryClipboardElement(element) {
49
- let elements = queryElements({ element, prefix: "clipboard" });
50
- if (elements === false) {
43
+ let elements = [];
44
+ if (element.hasAttribute("clipboard-query")) {
45
+ elements = queryElements({ element, prefix: "clipboard" });
46
+ } else {
51
47
  elements = [element];
52
48
  }
53
- clipboard(elements);
49
+
50
+ clipboard(element, elements);
54
51
  }
55
52
 
56
- async function clipboard(elements) {
53
+ async function clipboard(element, elements) {
57
54
  if (!elements) return;
58
55
  if (
59
56
  !(elements instanceof HTMLCollection) &&
@@ -64,27 +61,49 @@ async function clipboard(elements) {
64
61
  }
65
62
 
66
63
  try {
67
- // Collect values from all elements
68
- let content = "";
64
+ const clipboardItems = [];
69
65
 
70
66
  for (let element of elements) {
71
- const value = await element.getValue();
72
- if (value) {
73
- content += `${value}\n`; // Separate values by newline
67
+ let value = await element.getValue();
68
+ const valueType = element.getAttribute("clipboard-value-type");
69
+ if (valueType === "innerText") {
70
+ value = value.replace(/<[^>]*>/g, "");
71
+ new ClipboardItem({
72
+ "text/plain": new Blob([value], {
73
+ type: "text/plain"
74
+ })
75
+ });
76
+ } else if (typeof value === "string") {
77
+ // Handle string content as plain text
78
+ clipboardItems.push(
79
+ new ClipboardItem({
80
+ "text/plain": new Blob([value], { type: "text/plain" }),
81
+ "text/html": new Blob([value], {
82
+ type: "text/html"
83
+ }) // Render as code block in rich editors
84
+ })
85
+ );
86
+ } else if (value instanceof Blob) {
87
+ // Handle Blob content directly
88
+ clipboardItems.push(
89
+ new ClipboardItem({
90
+ [value.type]: value
91
+ })
92
+ );
93
+ } else {
94
+ console.warn("Unsupported value type for clipboard:", value);
74
95
  }
75
96
  }
76
97
 
77
- // Remove trailing newline
78
- content = content.trim();
79
-
80
- // Copy to clipboard
81
- await navigator.clipboard.writeText(content);
82
-
83
- console.log("Copied to clipboard:", content);
98
+ if (clipboardItems.length > 0) {
99
+ await navigator.clipboard.write(clipboardItems);
100
+ } else {
101
+ console.warn("No valid content to copy to clipboard.");
102
+ }
84
103
 
85
- document.dispatchEvent(
104
+ element.dispatchEvent(
86
105
  new CustomEvent("clipboarded", {
87
- detail: { content }
106
+ detail: { clipboardItems }
88
107
  })
89
108
  );
90
109
  } catch (error) {
@@ -99,14 +118,14 @@ Actions.init([
99
118
  name: "clipboard",
100
119
  endEvent: "clipboarded",
101
120
  callback: (action) => {
102
- queryClipboardElement(action.element);
121
+ queryClipboardElement(action);
103
122
  }
104
123
  }
105
124
  ]);
106
125
 
107
126
  Observer.init({
108
127
  name: "CoCreateClipboardAddedNodes",
109
- observe: ["addedNodes"],
128
+ types: ["addedNodes"],
110
129
  selector,
111
130
  callback(mutation) {
112
131
  initElement(mutation.target);
@@ -115,14 +134,8 @@ Observer.init({
115
134
 
116
135
  Observer.init({
117
136
  name: "CoCreateClipboardObserver",
118
- observe: ["attributes"],
119
- attributeName: [
120
- "clipboard-selector",
121
- "clipboard-closest",
122
- "clipboard-parent",
123
- "clipboard-next",
124
- "clipboard-previous"
125
- ],
137
+ types: ["attributes"],
138
+ attributeFilter: ["clipboard-query"],
126
139
  selector,
127
140
  callback: function (mutation) {
128
141
  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-clipboard": "./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", "clipboard"],
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-clipboard": "./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", "clipboard"],
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
+ };