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