next-cloudinary 1.9.0 → 1.11.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/dist/components/CldImage/CldImage.d.ts +3 -0
- package/dist/components/CldOgImage/CldOgImage.d.ts +7 -0
- package/dist/components/CldUploadButton/CldUploadButton.d.ts +11 -0
- package/dist/components/CldUploadWidget/CldUploadWidget.d.ts +9 -0
- package/dist/index.d.ts +7 -0
- package/dist/lib/cloudinary.d.ts +45 -0
- package/dist/next-cloudinary.js +48 -113
- package/dist/next-cloudinary.js.map +1 -1
- package/dist/next-cloudinary.modern.mjs +48 -116
- package/dist/next-cloudinary.modern.mjs.map +1 -1
- package/dist/next-cloudinary.module.js +48 -112
- package/dist/next-cloudinary.module.js.map +1 -1
- package/dist/next-cloudinary.umd.js +52 -116
- package/dist/next-cloudinary.umd.js.map +1 -1
- package/package.json +6 -3
- package/tsconfig.json +26 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('next/image'), require('@cloudinary/url-gen'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react', 'next/image', '@cloudinary/url-gen', '
|
|
4
|
-
(global = global || self, factory(global.nextCloudinary = {}, global.react, global.Image, global.urlGen, global.
|
|
5
|
-
})(this, (function (exports, react, Image, urlGen,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('next/image'), require('@cloudinary/url-gen'), require('react/jsx-runtime'), require('next/head'), require('next/script')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', 'next/image', '@cloudinary/url-gen', 'react/jsx-runtime', 'next/head', 'next/script'], factory) :
|
|
4
|
+
(global = global || self, factory(global.nextCloudinary = {}, global.react, global.Image, global.urlGen, global.jsxRuntime, global.Head, global.Script));
|
|
5
|
+
})(this, (function (exports, react, Image, urlGen, jsxRuntime, Head, Script) {
|
|
6
6
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
7
7
|
|
|
8
8
|
var Image__default = /*#__PURE__*/_interopDefaultLegacy(Image);
|
|
9
|
-
var nextPkg__default = /*#__PURE__*/_interopDefaultLegacy(nextPkg);
|
|
10
9
|
var Head__default = /*#__PURE__*/_interopDefaultLegacy(Head);
|
|
11
10
|
var Script__default = /*#__PURE__*/_interopDefaultLegacy(Script);
|
|
12
11
|
|
|
@@ -873,52 +872,8 @@
|
|
|
873
872
|
plugin: plugin
|
|
874
873
|
};
|
|
875
874
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
var name = "next-cloudinary";
|
|
879
|
-
var version = "1.9.0";
|
|
880
|
-
var main = "dist/next-cloudinary.umd.js";
|
|
881
|
-
var module = "dist/next-cloudinary.module.js";
|
|
882
|
-
var source = "src/index.js";
|
|
883
|
-
var scripts = {
|
|
884
|
-
build: "microbundle --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
|
|
885
|
-
dev: "microbundle watch --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
|
|
886
|
-
prepublishOnly: "cp ../README.md . && yarn build",
|
|
887
|
-
postpublish: "rm ./README.md",
|
|
888
|
-
test: "jest"
|
|
889
|
-
};
|
|
890
|
-
var dependencies = {
|
|
891
|
-
"@cloudinary/url-gen": "^1.8.6"
|
|
892
|
-
};
|
|
893
|
-
var devDependencies = {
|
|
894
|
-
"@babel/core": "^7.19.6",
|
|
895
|
-
"@babel/preset-env": "^7.19.4",
|
|
896
|
-
"@types/jest": "^29.2.0",
|
|
897
|
-
"babel-jest": "^29.2.2",
|
|
898
|
-
dotenv: "^16.0.3",
|
|
899
|
-
jest: "^29.2.2",
|
|
900
|
-
"jest-environment-jsdom": "^29.2.2",
|
|
901
|
-
microbundle: "^0.15.1"
|
|
902
|
-
};
|
|
903
|
-
var peerDependencies = {
|
|
904
|
-
next: "^12 || ^13",
|
|
905
|
-
react: "^17 || ^18"
|
|
906
|
-
};
|
|
907
|
-
var pkg = {
|
|
908
|
-
name: name,
|
|
909
|
-
version: version,
|
|
910
|
-
main: main,
|
|
911
|
-
module: module,
|
|
912
|
-
"umd:main": "dist/next-cloudinary.umd.js",
|
|
913
|
-
source: source,
|
|
914
|
-
scripts: scripts,
|
|
915
|
-
dependencies: dependencies,
|
|
916
|
-
devDependencies: devDependencies,
|
|
917
|
-
peerDependencies: peerDependencies
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
/**
|
|
921
|
-
* pollForProcessingImage
|
|
875
|
+
/**
|
|
876
|
+
* pollForProcessingImage
|
|
922
877
|
*/
|
|
923
878
|
|
|
924
879
|
function _catch(body, recover) {
|
|
@@ -974,14 +929,11 @@
|
|
|
974
929
|
removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, namedTransformationsPlugin, underlaysPlugin, zoompanPlugin,
|
|
975
930
|
// Raw transformations needs to be last simply to make sure
|
|
976
931
|
// it's always expected to applied the same way
|
|
977
|
-
|
|
978
932
|
rawTransformationsPlugin];
|
|
979
933
|
var cld;
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
* constructCloudinaryUrl
|
|
934
|
+
/**
|
|
935
|
+
* constructCloudinaryUrl
|
|
983
936
|
*/
|
|
984
|
-
|
|
985
937
|
function constructCloudinaryUrl(_ref) {
|
|
986
938
|
var options = _ref.options,
|
|
987
939
|
config = _ref.config;
|
|
@@ -989,52 +941,49 @@
|
|
|
989
941
|
cld = new urlGen.Cloudinary(_extends({
|
|
990
942
|
cloud: {
|
|
991
943
|
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
944
|
+
},
|
|
945
|
+
url: {
|
|
946
|
+
// Used to avoid issues with SSR particularly for the blurred placeholder
|
|
947
|
+
analytics: false
|
|
992
948
|
}
|
|
993
949
|
}, config));
|
|
994
950
|
}
|
|
995
|
-
var publicId = getPublicId(options.src);
|
|
951
|
+
var publicId = getPublicId(options == null ? void 0 : options.src);
|
|
996
952
|
var cldImage = cld.image(publicId);
|
|
997
953
|
transformationPlugins.forEach(function (_ref2) {
|
|
998
954
|
var plugin = _ref2.plugin;
|
|
955
|
+
// @ts-ignore
|
|
999
956
|
var _ref3 = plugin({
|
|
1000
957
|
cldImage: cldImage,
|
|
1001
958
|
options: options
|
|
1002
959
|
}) || {},
|
|
1003
960
|
pluginOptions = _ref3.options;
|
|
1004
|
-
if (pluginOptions != null && pluginOptions.format) {
|
|
961
|
+
if (pluginOptions != null && pluginOptions.format && options) {
|
|
1005
962
|
options.format = pluginOptions.format;
|
|
1006
963
|
}
|
|
1007
|
-
if (pluginOptions != null && pluginOptions.width) {
|
|
964
|
+
if (pluginOptions != null && pluginOptions.width && options) {
|
|
1008
965
|
options.resize = {
|
|
1009
966
|
width: pluginOptions == null ? void 0 : pluginOptions.width
|
|
1010
967
|
};
|
|
1011
968
|
}
|
|
1012
969
|
});
|
|
1013
|
-
if (options.resize) {
|
|
970
|
+
if (options != null && options.resize) {
|
|
1014
971
|
var _options$resize = options.resize,
|
|
1015
972
|
width = _options$resize.width,
|
|
1016
973
|
_options$resize$crop = _options$resize.crop,
|
|
1017
974
|
crop = _options$resize$crop === void 0 ? 'scale' : _options$resize$crop;
|
|
1018
975
|
cldImage.effect("c_" + crop + ",w_" + width);
|
|
1019
976
|
}
|
|
1020
|
-
return cldImage.setDeliveryType(options.deliveryType || 'upload').format(options.format || 'auto').delivery("q_" + (options.quality || 'auto')).toURL(
|
|
1021
|
-
trackedAnalytics: {
|
|
1022
|
-
sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
|
|
1023
|
-
sdkSemver: pkg.version,
|
|
1024
|
-
techVersion: nextPkg__default["default"].version
|
|
1025
|
-
}
|
|
1026
|
-
});
|
|
977
|
+
return cldImage.setDeliveryType((options == null ? void 0 : options.deliveryType) || 'upload').format((options == null ? void 0 : options.format) || 'auto').delivery("q_" + ((options == null ? void 0 : options.quality) || 'auto')).toURL();
|
|
1027
978
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
*
|
|
1031
|
-
*
|
|
1032
|
-
*
|
|
1033
|
-
*
|
|
1034
|
-
*
|
|
1035
|
-
* @return {string} The images public id
|
|
979
|
+
/**
|
|
980
|
+
* Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
|
|
981
|
+
* If it's recognized that is a url and it's not possible to get the public id, it warns the user.
|
|
982
|
+
*
|
|
983
|
+
* @param {string} src The cloudiary url or public id.
|
|
984
|
+
*
|
|
985
|
+
* @return {string} The images public id
|
|
1036
986
|
*/
|
|
1037
|
-
|
|
1038
987
|
function getPublicId(src) {
|
|
1039
988
|
if (typeof src !== 'string') {
|
|
1040
989
|
throw new Error("Invalid src of type " + typeof src);
|
|
@@ -1054,11 +1003,9 @@
|
|
|
1054
1003
|
}
|
|
1055
1004
|
return src;
|
|
1056
1005
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
* createPlaceholderUrl
|
|
1006
|
+
/**
|
|
1007
|
+
* createPlaceholderUrl
|
|
1060
1008
|
*/
|
|
1061
|
-
|
|
1062
1009
|
function createPlaceholderUrl(_ref4) {
|
|
1063
1010
|
var src = _ref4.src,
|
|
1064
1011
|
_ref4$placeholder = _ref4.placeholder,
|
|
@@ -1111,8 +1058,8 @@
|
|
|
1111
1058
|
}
|
|
1112
1059
|
|
|
1113
1060
|
var CldImage = function CldImage(props) {
|
|
1114
|
-
/**
|
|
1115
|
-
* handleOnError
|
|
1061
|
+
/**
|
|
1062
|
+
* handleOnError
|
|
1116
1063
|
*/
|
|
1117
1064
|
var handleOnError = function handleOnError(options) {
|
|
1118
1065
|
try {
|
|
@@ -1138,10 +1085,11 @@
|
|
|
1138
1085
|
CLD_OPTIONS.push(prop);
|
|
1139
1086
|
});
|
|
1140
1087
|
});
|
|
1141
|
-
|
|
1142
1088
|
// Construct the base Image component props by filtering out Cloudinary-specific props
|
|
1143
|
-
|
|
1144
|
-
|
|
1089
|
+
var imageProps = {
|
|
1090
|
+
alt: props.alt,
|
|
1091
|
+
src: props.src
|
|
1092
|
+
};
|
|
1145
1093
|
Object.keys(props).filter(function (key) {
|
|
1146
1094
|
return !CLD_OPTIONS.includes(key);
|
|
1147
1095
|
}).forEach(function (key) {
|
|
@@ -1153,16 +1101,13 @@
|
|
|
1153
1101
|
var _useState = react.useState(defaultImgKey),
|
|
1154
1102
|
imgKey = _useState[0],
|
|
1155
1103
|
setImgKey = _useState[1];
|
|
1156
|
-
|
|
1157
1104
|
// Construct Cloudinary-specific props by looking for values for any of the supported prop keys
|
|
1158
|
-
|
|
1159
1105
|
var cldOptions = {};
|
|
1160
1106
|
CLD_OPTIONS.forEach(function (key) {
|
|
1161
1107
|
if (props[key]) {
|
|
1162
1108
|
cldOptions[key] = props[key];
|
|
1163
1109
|
}
|
|
1164
1110
|
});
|
|
1165
|
-
|
|
1166
1111
|
// If we see a placeholder option, configure a Cloudinary-based URL.
|
|
1167
1112
|
// The resulting image will always be blurred per Next.js, so we're
|
|
1168
1113
|
// limited on options for placeholders.
|
|
@@ -1171,7 +1116,6 @@
|
|
|
1171
1116
|
// an Image component prop as opposed to simply the URL
|
|
1172
1117
|
//
|
|
1173
1118
|
// https://nextjs.org/docs/api-reference/next/image#blurdataurl
|
|
1174
|
-
|
|
1175
1119
|
if (imageProps.placeholder) {
|
|
1176
1120
|
var publicId = getPublicId(props.src);
|
|
1177
1121
|
imageProps.blurDataURL = createPlaceholderUrl({
|
|
@@ -1184,7 +1128,8 @@
|
|
|
1184
1128
|
}
|
|
1185
1129
|
if (props.src && props.preserveTransformations) {
|
|
1186
1130
|
var transformations = getTransformations(props.src, props.preserveTransformations);
|
|
1187
|
-
imageProps.rawTransformations
|
|
1131
|
+
var rawTransformations = imageProps.rawTransformations ? [].concat(imageProps.rawTransformations) : [];
|
|
1132
|
+
imageProps.rawTransformations = [].concat(rawTransformations, transformations);
|
|
1188
1133
|
}
|
|
1189
1134
|
return /*#__PURE__*/jsxRuntime.jsx(Image__default["default"], _extends({}, imageProps, {
|
|
1190
1135
|
loader: function loader(loaderOptions) {
|
|
@@ -1211,15 +1156,14 @@
|
|
|
1211
1156
|
width: props.width || IMAGE_WIDTH,
|
|
1212
1157
|
height: props.height || IMAGE_HEIGHT,
|
|
1213
1158
|
crop: props.crop || 'fill',
|
|
1214
|
-
gravity: props.gravity || 'center'
|
|
1159
|
+
gravity: props.gravity || 'center',
|
|
1160
|
+
alt: props.alt
|
|
1215
1161
|
});
|
|
1216
1162
|
var ogImageUrl = constructCloudinaryUrl({
|
|
1217
1163
|
options: options
|
|
1218
1164
|
});
|
|
1219
|
-
|
|
1220
1165
|
// We need to include the tags within the Next.js Head component rather than
|
|
1221
1166
|
// direcly adding them inside of the Head otherwise we get unexpected results
|
|
1222
|
-
|
|
1223
1167
|
return /*#__PURE__*/jsxRuntime.jsxs(Head__default["default"], {
|
|
1224
1168
|
children: [/*#__PURE__*/jsxRuntime.jsx("meta", {
|
|
1225
1169
|
property: "og:image",
|
|
@@ -1258,12 +1202,10 @@
|
|
|
1258
1202
|
var cloudinary = react.useRef();
|
|
1259
1203
|
var widget = react.useRef();
|
|
1260
1204
|
var signed = !!signatureEndpoint;
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
*
|
|
1264
|
-
* @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
|
|
1205
|
+
/**
|
|
1206
|
+
* generateSignature
|
|
1207
|
+
* @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
|
|
1265
1208
|
*/
|
|
1266
|
-
|
|
1267
1209
|
function generateSignature(callback, paramsToSign) {
|
|
1268
1210
|
fetch(signatureEndpoint, {
|
|
1269
1211
|
method: "POST",
|
|
@@ -1277,19 +1219,16 @@
|
|
|
1277
1219
|
callback(signature);
|
|
1278
1220
|
});
|
|
1279
1221
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
*
|
|
1283
|
-
* @description Creates a new instance of the Cloudinary widget and stores in a ref
|
|
1222
|
+
/**
|
|
1223
|
+
* createWidget
|
|
1224
|
+
* @description Creates a new instance of the Cloudinary widget and stores in a ref
|
|
1284
1225
|
*/
|
|
1285
|
-
|
|
1286
1226
|
function createWidget() {
|
|
1287
1227
|
var _cloudinary$current;
|
|
1288
1228
|
// When creating a signed upload, you need to provide both your Cloudinary API Key
|
|
1289
1229
|
// as well as a signature generator function that will sign any paramters
|
|
1290
1230
|
// either on page load or during the upload process. Read more about signed uploads at:
|
|
1291
1231
|
// https://cloudinary.com/documentation/upload_widget#signed_uploads
|
|
1292
|
-
|
|
1293
1232
|
var uploadOptions = _extends({
|
|
1294
1233
|
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
|
|
1295
1234
|
uploadPreset: uploadPreset || process.env.NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET,
|
|
@@ -1297,13 +1236,12 @@
|
|
|
1297
1236
|
}, options);
|
|
1298
1237
|
if (signed) {
|
|
1299
1238
|
uploadOptions.uploadSignature = generateSignature;
|
|
1300
|
-
|
|
1301
1239
|
// No need for apiSecret here because of api/sign-cloudinary-params
|
|
1302
|
-
|
|
1303
1240
|
if (!uploadOptions.apiKey) {
|
|
1304
1241
|
return new Error("Signed Upload needs apiKey!");
|
|
1305
1242
|
}
|
|
1306
1243
|
}
|
|
1244
|
+
// @ts-ignore
|
|
1307
1245
|
return (_cloudinary$current = cloudinary.current) == null ? void 0 : _cloudinary$current.createUploadWidget(uploadOptions, function (error, result) {
|
|
1308
1246
|
// The callback is a bit more chatty than failed or success so
|
|
1309
1247
|
// only trigger when one of those are the case. You can additionally
|
|
@@ -1314,25 +1252,23 @@
|
|
|
1314
1252
|
}
|
|
1315
1253
|
});
|
|
1316
1254
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
* open
|
|
1320
|
-
* @description When triggered, uses the current widget instance to open the upload modal
|
|
1255
|
+
/**
|
|
1256
|
+
* open
|
|
1257
|
+
* @description When triggered, uses the current widget instance to open the upload modal
|
|
1321
1258
|
*/
|
|
1322
|
-
|
|
1323
1259
|
function open() {
|
|
1324
1260
|
if (!(widget != null && widget.current)) {
|
|
1325
1261
|
widget.current = createWidget();
|
|
1326
1262
|
}
|
|
1263
|
+
// @ts-ignore
|
|
1327
1264
|
(widget == null ? void 0 : widget.current) && widget.current.open();
|
|
1328
1265
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
*
|
|
1332
|
-
* @description Stores the Cloudinary window instance to a ref when the widget script loads
|
|
1266
|
+
/**
|
|
1267
|
+
* handleOnLoad
|
|
1268
|
+
* @description Stores the Cloudinary window instance to a ref when the widget script loads
|
|
1333
1269
|
*/
|
|
1334
|
-
|
|
1335
1270
|
function handleOnLoad() {
|
|
1271
|
+
// @ts-ignore
|
|
1336
1272
|
cloudinary.current = window.cloudinary;
|
|
1337
1273
|
}
|
|
1338
1274
|
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|