@scaleflex/widget-canva 4.4.0 → 4.5.0

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
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.5.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.4.0...v4.5.0) (2025-10-08)
7
+
8
+ **Note:** Version bump only for package @scaleflex/widget-canva
9
+
10
+
11
+
12
+
13
+
6
14
  # [4.4.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.1.0...v4.4.0) (2025-10-07)
7
15
 
8
16
  **Note:** Version bump only for package @scaleflex/widget-canva
@@ -0,0 +1,69 @@
1
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
+ import { useState, useEffect } from 'react';
8
+ import { LoaderView } from '@scaleflex/widget-common';
9
+ import loadCanvaSDK from './utils/loadCanvaSDK';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ var openedBlockStyles = {
12
+ display: 'flex',
13
+ justifyContent: 'center',
14
+ alignItems: 'center',
15
+ marginTop: 50
16
+ };
17
+ var CanvaWorkspace = function CanvaWorkspace(_ref) {
18
+ var pluginOpts = _ref.pluginOpts,
19
+ addDesign = _ref.addDesign,
20
+ i18n = _ref.i18n,
21
+ canvaApi = _ref.canvaApi,
22
+ setCanvaApi = _ref.setCanvaApi,
23
+ closePlugin = _ref.closePlugin;
24
+ var apiKey = pluginOpts.apiKey,
25
+ designType = pluginOpts.designType,
26
+ fileType = pluginOpts.fileType;
27
+ var _useState = useState(true),
28
+ _useState2 = _slicedToArray(_useState, 2),
29
+ isLoading = _useState2[0],
30
+ setIsLoading = _useState2[1];
31
+ var createDesign = function createDesign(api) {
32
+ setIsLoading(false);
33
+ if (!canvaApi) {
34
+ setCanvaApi(api);
35
+ }
36
+ api.createDesign({
37
+ design: {
38
+ type: designType
39
+ },
40
+ editor: {
41
+ fileType: fileType
42
+ },
43
+ onDesignPublish: function onDesignPublish(opts) {
44
+ addDesign(opts);
45
+ },
46
+ onDesignClose: function onDesignClose() {
47
+ closePlugin();
48
+ }
49
+ });
50
+ };
51
+ useEffect(function () {
52
+ if (!window.Canva || !window.Canva.DesignButton || !canvaApi) {
53
+ loadCanvaSDK().then(function () {
54
+ window.Canva.DesignButton.initialize({
55
+ apiKey: apiKey
56
+ }).then(createDesign);
57
+ });
58
+ } else {
59
+ createDesign(canvaApi);
60
+ }
61
+ }, []);
62
+ return isLoading ? /*#__PURE__*/_jsx(LoaderView, {
63
+ loaderLabel: i18n('loaderLoadingLabel')
64
+ }) : /*#__PURE__*/_jsx("div", {
65
+ style: openedBlockStyles,
66
+ children: i18n('canvaOpenedInModalHint')
67
+ });
68
+ };
69
+ export default CanvaWorkspace;
@@ -0,0 +1,6 @@
1
+ export default {
2
+ canvaPluginTitle: 'Canva (Design & upload)',
3
+ canvaOpenedInModalHint: 'Canva is opened in an external modal',
4
+ canvaFailedToFetchDesignFileMetaError: 'Failed to fetch the meta of the design file',
5
+ canvaFailedToFetchDesignFileMessage: 'Failed to fetch the design file'
6
+ };
package/lib/index.js ADDED
@@ -0,0 +1,178 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
5
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
6
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
9
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
12
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
13
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
14
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
16
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
+ import { Plugin } from '@scaleflex/widget-core';
18
+ import Explorer from '@scaleflex/widget-explorer';
19
+ import Translator from '@scaleflex/widget-utils/lib/Translator';
20
+ import { CanvaIcon } from '@scaleflex/widget-icons';
21
+ import { RequestClient } from '@scaleflex/widget-companion-client';
22
+ import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
23
+ import defaultLocale from './defaultLocale';
24
+ import CanvaWorkspace from './CanvaWorkspace';
25
+ var DEV_API_KEY = '6PlJP_VARP0ey8hLCNQQsp1P';
26
+ var PROD_API_KEY = 'xdXpp6KdBRtRAJbPGs64yEl-';
27
+
28
+ // TODO: find a way to show version of the current plugin
29
+ // why solution below isn't good?
30
+ // first import doesn't work with webpack 5 as it was deprecated
31
+ // second import fixes webpack 5 issue as it was mentioned in their docs
32
+ // but it exposes our package.json to the client and it is mentioned as security rist in mutiple places
33
+ // https://github.com/axelpale/genversion
34
+ // https://stackoverflow.com/questions/64993118/error-should-not-import-the-named-export-version-imported-as-version
35
+ // https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code/10855054#10855054
36
+ // import { version } from '../package.json'
37
+ // import packageInfo from '../package.json'
38
+ var Canva = /*#__PURE__*/function (_Plugin) {
39
+ // static VERSION = packageInfo.version
40
+
41
+ function Canva(filerobot) {
42
+ var _this;
43
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
44
+ _classCallCheck(this, Canva);
45
+ _this = _callSuper(this, Canva, [filerobot, opts]);
46
+ _defineProperty(_this, "i18nInit", function () {
47
+ _this.translator = new Translator([_this.defaultLocale, _this.filerobot.locale, _this.opts.locale]);
48
+ _this.i18n = _this.translator.translate.bind(_this.translator);
49
+ _this.i18nArray = _this.translator.translateArray.bind(_this.translator);
50
+ });
51
+ _defineProperty(_this, "getFileType", function (type) {
52
+ return type.substring(type.lastIndexOf('/') + 1);
53
+ });
54
+ _defineProperty(_this, "getFileNameFromUrl", function (_ref) {
55
+ var url = _ref.url,
56
+ type = _ref.type;
57
+ return url.substring(url.lastIndexOf('/') + 1) + ".".concat(type);
58
+ });
59
+ _defineProperty(_this, "getMeta", function (url) {
60
+ return _this.client.post('url/meta', {
61
+ url: url
62
+ }).then(function (res) {
63
+ if (res.error) {
64
+ _this.filerobot.log('[Canva] Error:');
65
+ _this.filerobot.log(res.error);
66
+ throw new Error(_this.i18n('canvaFailedToFetchDesignFileMetaError'));
67
+ }
68
+ return res;
69
+ });
70
+ });
71
+ _defineProperty(_this, "addDesign", function (design) {
72
+ if (!design.exportUrl) {
73
+ return;
74
+ }
75
+ return _this.getMeta(design.exportUrl).then(function (meta) {
76
+ var tagFile = {
77
+ source: _this.id,
78
+ name: "".concat(design.designTitle, "-").concat(design.designId, ".").concat(_this.getFileType(meta.type)) || _this.getFileNameFromUrl({
79
+ url: design.exportUrl,
80
+ type: _this.getFileType(meta.type)
81
+ }),
82
+ type: meta.type,
83
+ data: {
84
+ size: meta.size
85
+ },
86
+ isRemote: true,
87
+ body: {
88
+ url: design.exportUrl
89
+ },
90
+ preview: design.exportUrl,
91
+ remote: {
92
+ companionUrl: _this.client.companionUrl,
93
+ url: "".concat(_this.hostname, "/url/get"),
94
+ body: {
95
+ fileId: design.designId,
96
+ url: design.exportUrl
97
+ },
98
+ providerOptions: _this.client.opts
99
+ }
100
+ };
101
+ return tagFile;
102
+ }).then(function (tagFile) {
103
+ _this.filerobot.log('[Canva] Adding remote file');
104
+ try {
105
+ _this.filerobot.addFile(tagFile);
106
+ } catch (err) {
107
+ if (!err.isRestriction) {
108
+ _this.filerobot.log(err);
109
+ }
110
+ }
111
+ })["catch"](function (err) {
112
+ _this.filerobot.log(err);
113
+ _this.filerobot.info({
114
+ message: _this.i18n('canvaFailedToFetchDesignFileMessage'),
115
+ details: err
116
+ }, 'error', 5000);
117
+ });
118
+ });
119
+ _defineProperty(_this, "setCanvaApi", function (canvaApi) {
120
+ _this.canvaApi = canvaApi;
121
+ });
122
+ _this.id = PLUGINS_IDS.CANVA;
123
+ _this.type = 'acquirer';
124
+ _this.icon = CanvaIcon;
125
+ _this.title = 'Canva';
126
+ _this.render = _this.render.bind(_this);
127
+ _this.canvaApi = undefined;
128
+ var defaultOptions = {
129
+ apiKey: _this.filerobot.opts.dev ? DEV_API_KEY : PROD_API_KEY,
130
+ designType: 'A4Document',
131
+ fileType: 'png'
132
+ };
133
+ _this.opts = _objectSpread(_objectSpread({}, defaultOptions), opts);
134
+ _this.defaultLocale = {
135
+ strings: defaultLocale
136
+ };
137
+ _this.i18nInit();
138
+
139
+ // !TODO: Check why this.i18n('canvaPluginTitle') doesn't render the proper title.
140
+ // this.title = this.opts.title || this.i18n('canvaPluginTitle')
141
+
142
+ _this.client = new RequestClient(filerobot, {
143
+ companionHeaders: _this.opts.companionHeaders
144
+ });
145
+ _this.hostname = _this.client.companionUrl;
146
+ if (!_this.hostname) {
147
+ throw new Error('Companion hostname is required');
148
+ }
149
+ return _this;
150
+ }
151
+ _inherits(Canva, _Plugin);
152
+ return _createClass(Canva, [{
153
+ key: "install",
154
+ value: function install() {
155
+ if (Explorer) {
156
+ this.mount(Explorer, this);
157
+ }
158
+ }
159
+ }, {
160
+ key: "uninstall",
161
+ value: function uninstall() {
162
+ this.unmount();
163
+ }
164
+ }, {
165
+ key: "render",
166
+ value: function render() {
167
+ return CanvaWorkspace({
168
+ pluginOpts: this.opts,
169
+ addDesign: this.addDesign,
170
+ i18n: this.i18n,
171
+ canvaApi: this.canvaApi,
172
+ setCanvaApi: this.setCanvaApi,
173
+ closePlugin: this.parent.hideAllPanelsAndShowAddFilesPanel
174
+ });
175
+ }
176
+ }]);
177
+ }(Plugin);
178
+ export { Canva as default };
@@ -0,0 +1,11 @@
1
+ var loadCanvaSDK = function loadCanvaSDK() {
2
+ return new Promise(function (resolve, reject) {
3
+ var scriptElement = document.createElement('script');
4
+ scriptElement.src = 'https://sdk.canva.com/designbutton/v2/api.js';
5
+ scriptElement.async = true;
6
+ scriptElement.onload = resolve;
7
+ scriptElement.onerror = reject;
8
+ document.body.appendChild(scriptElement);
9
+ });
10
+ };
11
+ export default loadCanvaSDK;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scaleflex/widget-canva",
3
3
  "description": "Create your own design & customize it then upload it through the widget on the go.",
4
- "version": "4.4.0",
4
+ "version": "4.5.0",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
7
7
  "types": "types/index.d.ts",
@@ -9,10 +9,10 @@
9
9
  "access": "public"
10
10
  },
11
11
  "dependencies": {
12
- "@scaleflex/widget-common": "^4.4.0",
13
- "@scaleflex/widget-companion-client": "^4.4.0",
14
- "@scaleflex/widget-icons": "^4.4.0",
15
- "@scaleflex/widget-utils": "^4.4.0"
12
+ "@scaleflex/widget-common": "^4.5.0",
13
+ "@scaleflex/widget-companion-client": "^4.5.0",
14
+ "@scaleflex/widget-icons": "^4.5.0",
15
+ "@scaleflex/widget-utils": "^4.5.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "react": "^19.0.0",
@@ -29,5 +29,5 @@
29
29
  "/lib",
30
30
  "/types"
31
31
  ],
32
- "gitHead": "04b8ec545c4f10be89f5a44eed954acf8433360c"
32
+ "gitHead": "df64ca68034ed6c33e123e7dfa215176aa0a1196"
33
33
  }