sanity-plugin-cloudinary 0.2.2 → 1.0.0-v3-studio.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/LICENSE +1 -1
- package/README.md +160 -66
- package/lib/index.esm.js +2 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/src/index.d.ts +35 -0
- package/package.json +67 -41
- package/sanity.json +3 -15
- package/src/arrayFunctions.tsx +71 -0
- package/src/components/AssetDiff.tsx +44 -0
- package/src/components/AssetPreview.tsx +41 -0
- package/src/components/CloudinaryInput.tsx +61 -0
- package/src/components/SecretsConfigView.tsx +39 -0
- package/src/components/VideoPlayer.tsx +62 -0
- package/src/components/WidgetInput.tsx +66 -0
- package/src/components/asset-source/CloudinaryAssetSource.tsx +155 -0
- package/src/components/asset-source/Icon.tsx +93 -0
- package/src/index.ts +30 -0
- package/src/schema/cloudinaryAsset.ts +101 -0
- package/src/schema/cloudinaryAssetDerived.ts +26 -0
- package/src/typings.d.ts +74 -0
- package/src/utils.ts +115 -0
- package/v2-incompatible.js +11 -0
- package/dist/arrayFunctions.js +0 -82
- package/dist/arrayFunctions.js.map +0 -1
- package/dist/components/AssetDiff.js +0 -62
- package/dist/components/AssetDiff.js.map +0 -1
- package/dist/components/AssetPreview.js +0 -46
- package/dist/components/AssetPreview.js.map +0 -1
- package/dist/components/CloudinaryInput.js +0 -90
- package/dist/components/CloudinaryInput.js.map +0 -1
- package/dist/components/SecretsConfigView.js +0 -37
- package/dist/components/SecretsConfigView.js.map +0 -1
- package/dist/components/VideoPlayer.js +0 -70
- package/dist/components/VideoPlayer.js.map +0 -1
- package/dist/components/WidgetInput.js +0 -87
- package/dist/components/WidgetInput.js.map +0 -1
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/schema/cloudinary.js +0 -19
- package/dist/schema/cloudinary.js.map +0 -1
- package/dist/schema/cloudinaryAsset.js +0 -100
- package/dist/schema/cloudinaryAsset.js.map +0 -1
- package/dist/schema/cloudinaryAssetDerived.js +0 -22
- package/dist/schema/cloudinaryAssetDerived.js.map +0 -1
- package/dist/typings.d.js +0 -8
- package/dist/typings.d.js.map +0 -1
- package/dist/utils.js +0 -92
- package/dist/utils.js.map +0 -1
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _CloudinaryInput = _interopRequireDefault(require("../components/CloudinaryInput"));
|
|
9
|
-
|
|
10
|
-
var _AssetDiff = _interopRequireDefault(require("../components/AssetDiff"));
|
|
11
|
-
|
|
12
|
-
var _AssetPreview = _interopRequireDefault(require("../components/AssetPreview"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
var _default = {
|
|
17
|
-
type: 'object',
|
|
18
|
-
name: 'cloudinary.asset',
|
|
19
|
-
fields: [{
|
|
20
|
-
type: 'string',
|
|
21
|
-
name: 'public_id'
|
|
22
|
-
}, {
|
|
23
|
-
type: 'string',
|
|
24
|
-
name: 'resource_type' // "image", "?"
|
|
25
|
-
|
|
26
|
-
}, {
|
|
27
|
-
type: 'string',
|
|
28
|
-
name: 'type' // "upload", "?"
|
|
29
|
-
|
|
30
|
-
}, {
|
|
31
|
-
type: 'string',
|
|
32
|
-
name: 'format' // "jpg"
|
|
33
|
-
|
|
34
|
-
}, {
|
|
35
|
-
type: 'number',
|
|
36
|
-
name: 'version'
|
|
37
|
-
}, {
|
|
38
|
-
type: 'url',
|
|
39
|
-
name: 'url'
|
|
40
|
-
}, {
|
|
41
|
-
type: 'url',
|
|
42
|
-
name: 'secure_url'
|
|
43
|
-
}, {
|
|
44
|
-
type: 'number',
|
|
45
|
-
name: 'width'
|
|
46
|
-
}, {
|
|
47
|
-
type: 'number',
|
|
48
|
-
name: 'height'
|
|
49
|
-
}, {
|
|
50
|
-
type: 'number',
|
|
51
|
-
name: 'bytes'
|
|
52
|
-
}, {
|
|
53
|
-
type: 'number',
|
|
54
|
-
name: 'duration' // can be null
|
|
55
|
-
|
|
56
|
-
}, {
|
|
57
|
-
type: 'array',
|
|
58
|
-
name: 'tags',
|
|
59
|
-
of: [{
|
|
60
|
-
type: 'string'
|
|
61
|
-
}]
|
|
62
|
-
}, {
|
|
63
|
-
type: 'datetime',
|
|
64
|
-
name: 'created_at'
|
|
65
|
-
}, {
|
|
66
|
-
type: 'array',
|
|
67
|
-
name: 'derived',
|
|
68
|
-
of: [{
|
|
69
|
-
type: 'cloudinary.assetDerived'
|
|
70
|
-
}]
|
|
71
|
-
}, {
|
|
72
|
-
type: 'string',
|
|
73
|
-
name: 'access_mode'
|
|
74
|
-
} // context array of unknown content
|
|
75
|
-
// metadata array of unknown content
|
|
76
|
-
],
|
|
77
|
-
inputComponent: _CloudinaryInput.default,
|
|
78
|
-
diffComponent: _AssetDiff.default,
|
|
79
|
-
preview: {
|
|
80
|
-
select: {
|
|
81
|
-
url: 'url',
|
|
82
|
-
resource_type: 'resource_type',
|
|
83
|
-
derived: 'derived.0.url'
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
prepare(_ref) {
|
|
87
|
-
var url = _ref.url,
|
|
88
|
-
derived = _ref.derived,
|
|
89
|
-
resource_type = _ref.resource_type;
|
|
90
|
-
return {
|
|
91
|
-
resource_type,
|
|
92
|
-
url: derived || url
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
component: _AssetPreview.default
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
exports.default = _default;
|
|
100
|
-
//# sourceMappingURL=cloudinaryAsset.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/cloudinaryAsset.ts"],"names":["type","name","fields","of","inputComponent","CloudinaryInput","diffComponent","AssetDiff","preview","select","url","resource_type","derived","prepare","component","AssetPreview"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;eAiBe;AACbA,EAAAA,IAAI,EAAE,QADO;AAEbC,EAAAA,IAAI,EAAE,kBAFO;AAGbC,EAAAA,MAAM,EAAE,CACN;AACEF,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GADM,EAKN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE,eAFR,CAGE;;AAHF,GALM,EAUN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE,MAFR,CAGE;;AAHF,GAVM,EAeN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE,QAFR,CAGE;;AAHF,GAfM,EAoBN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GApBM,EAwBN;AACED,IAAAA,IAAI,EAAE,KADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GAxBM,EA4BN;AACED,IAAAA,IAAI,EAAE,KADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GA5BM,EAgCN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GAhCM,EAoCN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GApCM,EAwCN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GAxCM,EA4CN;AACED,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE,UAFR,CAGE;;AAHF,GA5CM,EAiDN;AACED,IAAAA,IAAI,EAAE,OADR;AAEEC,IAAAA,IAAI,EAAE,MAFR;AAGEE,IAAAA,EAAE,EAAE,CAAC;AAAEH,MAAAA,IAAI,EAAE;AAAR,KAAD;AAHN,GAjDM,EAsDN;AACEA,IAAAA,IAAI,EAAE,UADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GAtDM,EA0DN;AACED,IAAAA,IAAI,EAAE,OADR;AAEEC,IAAAA,IAAI,EAAE,SAFR;AAGEE,IAAAA,EAAE,EAAE,CAAC;AAAEH,MAAAA,IAAI,EAAE;AAAR,KAAD;AAHN,GA1DM,EA+DN;AACEA,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GA/DM,CAmEN;AACA;AApEM,GAHK;AAyEbG,EAAAA,cAAc,EAAEC,wBAzEH;AA0EbC,EAAAA,aAAa,EAAEC,kBA1EF;AA2EbC,EAAAA,OAAO,EAAE;AACPC,IAAAA,MAAM,EAAE;AACNC,MAAAA,GAAG,EAAE,KADC;AAENC,MAAAA,aAAa,EAAE,eAFT;AAGNC,MAAAA,OAAO,EAAE;AAHH,KADD;;AAMPC,IAAAA,OAAO,OAAuC;AAAA,UAApCH,GAAoC,QAApCA,GAAoC;AAAA,UAA/BE,OAA+B,QAA/BA,OAA+B;AAAA,UAAtBD,aAAsB,QAAtBA,aAAsB;AAC5C,aAAO;AACLA,QAAAA,aADK;AAELD,QAAAA,GAAG,EAAEE,OAAO,IAAIF;AAFX,OAAP;AAID,KAXM;;AAYPI,IAAAA,SAAS,EAAEC;AAZJ;AA3EI,C","sourcesContent":["import CloudinaryInput from '../components/CloudinaryInput';\nimport AssetDiff from '../components/AssetDiff';\nimport AssetPreview from '../components/AssetPreview';\nimport { CloudinaryAssetDerived } from './cloudinaryAssetDerived';\n\nexport type CloudinaryAsset = {\n _type: string;\n _key?: string;\n _version: number;\n public_id: string;\n resource_type: string;\n type: string;\n format: string;\n version: number;\n url: string;\n secure_url: string;\n derived?: CloudinaryAssetDerived[];\n};\n\nexport default {\n type: 'object',\n name: 'cloudinary.asset',\n fields: [\n {\n type: 'string',\n name: 'public_id',\n },\n {\n type: 'string',\n name: 'resource_type',\n // \"image\", \"?\"\n },\n {\n type: 'string',\n name: 'type',\n // \"upload\", \"?\"\n },\n {\n type: 'string',\n name: 'format',\n // \"jpg\"\n },\n {\n type: 'number',\n name: 'version',\n },\n {\n type: 'url',\n name: 'url',\n },\n {\n type: 'url',\n name: 'secure_url',\n },\n {\n type: 'number',\n name: 'width',\n },\n {\n type: 'number',\n name: 'height',\n },\n {\n type: 'number',\n name: 'bytes',\n },\n {\n type: 'number',\n name: 'duration',\n // can be null\n },\n {\n type: 'array',\n name: 'tags',\n of: [{ type: 'string' }],\n },\n {\n type: 'datetime',\n name: 'created_at',\n },\n {\n type: 'array',\n name: 'derived',\n of: [{ type: 'cloudinary.assetDerived' }],\n },\n {\n type: 'string',\n name: 'access_mode',\n },\n // context array of unknown content\n // metadata array of unknown content\n ],\n inputComponent: CloudinaryInput,\n diffComponent: AssetDiff,\n preview: {\n select: {\n url: 'url',\n resource_type: 'resource_type',\n derived: 'derived.0.url',\n },\n prepare({ url, derived, resource_type }: any) {\n return {\n resource_type,\n url: derived || url,\n };\n },\n component: AssetPreview,\n },\n};\n"],"file":"cloudinaryAsset.js"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
type: 'object',
|
|
9
|
-
name: 'cloudinary.assetDerived',
|
|
10
|
-
fields: [{
|
|
11
|
-
type: 'string',
|
|
12
|
-
name: 'raw_transformation'
|
|
13
|
-
}, {
|
|
14
|
-
type: 'url',
|
|
15
|
-
name: 'url'
|
|
16
|
-
}, {
|
|
17
|
-
type: 'url',
|
|
18
|
-
name: 'secure_url'
|
|
19
|
-
}]
|
|
20
|
-
};
|
|
21
|
-
exports.default = _default;
|
|
22
|
-
//# sourceMappingURL=cloudinaryAssetDerived.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/cloudinaryAssetDerived.ts"],"names":["type","name","fields"],"mappings":";;;;;;eAMe;AACbA,EAAAA,IAAI,EAAE,QADO;AAEbC,EAAAA,IAAI,EAAE,yBAFO;AAGbC,EAAAA,MAAM,EAAE,CACN;AACEF,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GADM,EAKN;AACED,IAAAA,IAAI,EAAE,KADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GALM,EASN;AACED,IAAAA,IAAI,EAAE,KADR;AAEEC,IAAAA,IAAI,EAAE;AAFR,GATM;AAHK,C","sourcesContent":["export type CloudinaryAssetDerived = {\n raw_transformation: string;\n url: string;\n secure_url: string;\n};\n\nexport default {\n type: 'object',\n name: 'cloudinary.assetDerived',\n fields: [\n {\n type: 'string',\n name: 'raw_transformation',\n },\n {\n type: 'url',\n name: 'url',\n },\n {\n type: 'url',\n name: 'secure_url',\n },\n ],\n};\n"],"file":"cloudinaryAssetDerived.js"}
|
package/dist/typings.d.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var React = _interopRequireWildcard(require("react"));
|
|
4
|
-
|
|
5
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
6
|
-
|
|
7
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
8
|
-
//# sourceMappingURL=typings.d.js.map
|
package/dist/typings.d.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/typings.d.ts"],"names":[],"mappings":";;AAAA","sourcesContent":["import * as React from 'react';\n\nexport type InsertHandlerParams = {\n assets: CloudinaryAssetResponse[];\n};\n\ndeclare global {\n interface Window {\n cloudinary: {\n openMediaLibrary: (config: any, callbacks: any) => void;\n };\n }\n}\n\ndeclare module '*.css' {\n const content: { [className: string]: CSSProperties };\n export default content;\n}\n\nexport type CloudinaryDerivative = {\n url: string;\n secure_url: string;\n raw_transformation: string;\n};\n\nexport type CloudinaryAssetResponse = {\n public_id: string;\n resource_type: string;\n type: string;\n url: string;\n tags: string[];\n secure_url: string;\n format: string;\n width: number;\n height: number;\n bytes: number;\n derived?: CloudinaryDerivative[];\n};\n\ndeclare module 'part:@sanity/components/buttons/default' {\n interface Props {\n color?: string;\n children?: any;\n onClick?: any;\n inverted?: boolean;\n disabled?: boolean;\n title?: string;\n kind?: 'default' | 'simple';\n }\n export default class DefaultButton extends React.Component<Props, any> {}\n}\n\ndeclare module 'part:@sanity/components/buttons/button-grid' {\n interface Props {\n align?: string;\n }\n export default class ButtonGrid extends React.Component<Props, any> {}\n}\n\ndeclare module 'part:@sanity/components/fieldsets/default' {\n const shim: any;\n export default shim;\n}\n"],"file":"typings.d.js"}
|
package/dist/utils.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.assetUrl = assetUrl;
|
|
7
|
-
exports.loadJS = loadJS;
|
|
8
|
-
exports.openMediaSelector = void 0;
|
|
9
|
-
|
|
10
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
-
|
|
12
|
-
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."); }
|
|
13
|
-
|
|
14
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
|
|
16
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
17
|
-
|
|
18
|
-
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
-
|
|
20
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
|
|
22
|
-
var widgetSrc = 'https://media-library.cloudinary.com/global/all.js';
|
|
23
|
-
|
|
24
|
-
function assetUrl(asset) {
|
|
25
|
-
if (asset.derived && asset.derived.length > 0) {
|
|
26
|
-
var _asset$derived = _slicedToArray(asset.derived, 1),
|
|
27
|
-
derived = _asset$derived[0];
|
|
28
|
-
|
|
29
|
-
if (derived.secure_url) {
|
|
30
|
-
return derived.secure_url;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return derived.url;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (asset.secure_url) {
|
|
37
|
-
return asset.secure_url;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return asset.url;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
var openMediaSelector = (cloudName, apiKey, multiple, insertHandler, selectedAsset) => {
|
|
44
|
-
loadJS(widgetSrc, () => {
|
|
45
|
-
var options = {
|
|
46
|
-
cloud_name: cloudName,
|
|
47
|
-
api_key: apiKey,
|
|
48
|
-
insert_caption: 'Select',
|
|
49
|
-
multiple
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
if (selectedAsset) {
|
|
53
|
-
options.asset = {
|
|
54
|
-
public_id: selectedAsset.public_id,
|
|
55
|
-
type: selectedAsset.type,
|
|
56
|
-
resource_type: selectedAsset.resource_type
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
window.cloudinary.openMediaLibrary(options, {
|
|
61
|
-
insertHandler
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
exports.openMediaSelector = openMediaSelector;
|
|
67
|
-
|
|
68
|
-
function loadJS(url, callback) {
|
|
69
|
-
var existingScript = document.getElementById('damWidget');
|
|
70
|
-
|
|
71
|
-
if (!existingScript) {
|
|
72
|
-
var script = document.createElement('script');
|
|
73
|
-
script.src = url;
|
|
74
|
-
script.id = 'damWidget';
|
|
75
|
-
document.body.appendChild(script);
|
|
76
|
-
|
|
77
|
-
script.onload = () => {
|
|
78
|
-
if (callback) {
|
|
79
|
-
return callback();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return true;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (existingScript && callback) {
|
|
87
|
-
return callback();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"names":["widgetSrc","assetUrl","asset","derived","length","secure_url","url","openMediaSelector","cloudName","apiKey","multiple","insertHandler","selectedAsset","loadJS","options","cloud_name","api_key","insert_caption","public_id","type","resource_type","window","cloudinary","openMediaLibrary","callback","existingScript","document","getElementById","script","createElement","src","id","body","appendChild","onload"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGA,IAAMA,SAAS,GAAG,oDAAlB;;AAEO,SAASC,QAAT,CAAkBC,KAAlB,EAA0C;AAC/C,MAAIA,KAAK,CAACC,OAAN,IAAiBD,KAAK,CAACC,OAAN,CAAcC,MAAd,GAAuB,CAA5C,EAA+C;AAAA,wCAC3BF,KAAK,CAACC,OADqB;AAAA,QACtCA,OADsC;;AAE7C,QAAIA,OAAO,CAACE,UAAZ,EAAwB;AACtB,aAAOF,OAAO,CAACE,UAAf;AACD;;AACD,WAAOF,OAAO,CAACG,GAAf;AACD;;AACD,MAAIJ,KAAK,CAACG,UAAV,EAAsB;AACpB,WAAOH,KAAK,CAACG,UAAb;AACD;;AACD,SAAOH,KAAK,CAACI,GAAb;AACD;;AAEM,IAAMC,iBAAiB,GAAG,CAC/BC,SAD+B,EAE/BC,MAF+B,EAG/BC,QAH+B,EAI/BC,aAJ+B,EAK/BC,aAL+B,KAM5B;AACHC,EAAAA,MAAM,CAACb,SAAD,EAAY,MAAM;AACtB,QAAMc,OAA4B,GAAG;AACnCC,MAAAA,UAAU,EAAEP,SADuB;AAEnCQ,MAAAA,OAAO,EAAEP,MAF0B;AAGnCQ,MAAAA,cAAc,EAAE,QAHmB;AAInCP,MAAAA;AAJmC,KAArC;;AAOA,QAAIE,aAAJ,EAAmB;AACjBE,MAAAA,OAAO,CAACZ,KAAR,GAAgB;AACdgB,QAAAA,SAAS,EAAEN,aAAa,CAACM,SADX;AAEdC,QAAAA,IAAI,EAAEP,aAAa,CAACO,IAFN;AAGdC,QAAAA,aAAa,EAAER,aAAa,CAACQ;AAHf,OAAhB;AAKD;;AAEDC,IAAAA,MAAM,CAACC,UAAP,CAAkBC,gBAAlB,CAAmCT,OAAnC,EAA4C;AAAEH,MAAAA;AAAF,KAA5C;AACD,GAjBK,CAAN;AAkBD,CAzBM;;;;AA2BA,SAASE,MAAT,CAAgBP,GAAhB,EAA6BkB,QAA7B,EAAmD;AACxD,MAAMC,cAAc,GAAGC,QAAQ,CAACC,cAAT,CAAwB,WAAxB,CAAvB;;AACA,MAAI,CAACF,cAAL,EAAqB;AACnB,QAAMG,MAAM,GAAGF,QAAQ,CAACG,aAAT,CAAuB,QAAvB,CAAf;AACAD,IAAAA,MAAM,CAACE,GAAP,GAAaxB,GAAb;AACAsB,IAAAA,MAAM,CAACG,EAAP,GAAY,WAAZ;AACAL,IAAAA,QAAQ,CAACM,IAAT,CAAcC,WAAd,CAA0BL,MAA1B;;AACAA,IAAAA,MAAM,CAACM,MAAP,GAAgB,MAAM;AACpB,UAAIV,QAAJ,EAAc;AACZ,eAAOA,QAAQ,EAAf;AACD;;AACD,aAAO,IAAP;AACD,KALD;AAMD;;AACD,MAAIC,cAAc,IAAID,QAAtB,EAAgC;AAC9B,WAAOA,QAAQ,EAAf;AACD;;AACD,SAAO,IAAP;AACD","sourcesContent":["import { CloudinaryAsset } from './schema/cloudinaryAsset';\nimport { InsertHandlerParams } from './typings';\n\nconst widgetSrc = 'https://media-library.cloudinary.com/global/all.js';\n\nexport function assetUrl(asset: CloudinaryAsset) {\n if (asset.derived && asset.derived.length > 0) {\n const [derived] = asset.derived;\n if (derived.secure_url) {\n return derived.secure_url;\n }\n return derived.url;\n }\n if (asset.secure_url) {\n return asset.secure_url;\n }\n return asset.url;\n}\n\nexport const openMediaSelector = (\n cloudName: string,\n apiKey: string,\n multiple: boolean,\n insertHandler: (params: InsertHandlerParams) => void,\n selectedAsset?: CloudinaryAsset\n) => {\n loadJS(widgetSrc, () => {\n const options: Record<string, any> = {\n cloud_name: cloudName,\n api_key: apiKey,\n insert_caption: 'Select',\n multiple,\n };\n\n if (selectedAsset) {\n options.asset = {\n public_id: selectedAsset.public_id,\n type: selectedAsset.type,\n resource_type: selectedAsset.resource_type,\n };\n }\n\n window.cloudinary.openMediaLibrary(options, { insertHandler });\n });\n};\n\nexport function loadJS(url: string, callback: () => void) {\n const existingScript = document.getElementById('damWidget');\n if (!existingScript) {\n const script = document.createElement('script');\n script.src = url;\n script.id = 'damWidget';\n document.body.appendChild(script);\n script.onload = () => {\n if (callback) {\n return callback();\n }\n return true;\n };\n }\n if (existingScript && callback) {\n return callback();\n }\n return true;\n}\n"],"file":"utils.js"}
|