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';
|
|
@@ -886,63 +885,16 @@ var zoompanPlugin = {
|
|
|
886
885
|
plugin: plugin
|
|
887
886
|
};
|
|
888
887
|
|
|
889
|
-
const NEXT_CLOUDINARY_ANALYTICS_ID = 'V';
|
|
890
|
-
|
|
891
|
-
var name = "next-cloudinary";
|
|
892
|
-
var version = "1.9.0";
|
|
893
|
-
var main = "dist/next-cloudinary.umd.js";
|
|
894
|
-
var module = "dist/next-cloudinary.module.js";
|
|
895
|
-
var source = "src/index.js";
|
|
896
|
-
var scripts = {
|
|
897
|
-
build: "microbundle --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
|
|
898
|
-
dev: "microbundle watch --no-compress --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react",
|
|
899
|
-
prepublishOnly: "cp ../README.md . && yarn build",
|
|
900
|
-
postpublish: "rm ./README.md",
|
|
901
|
-
test: "jest"
|
|
902
|
-
};
|
|
903
|
-
var dependencies = {
|
|
904
|
-
"@cloudinary/url-gen": "^1.8.6"
|
|
905
|
-
};
|
|
906
|
-
var devDependencies = {
|
|
907
|
-
"@babel/core": "^7.19.6",
|
|
908
|
-
"@babel/preset-env": "^7.19.4",
|
|
909
|
-
"@types/jest": "^29.2.0",
|
|
910
|
-
"babel-jest": "^29.2.2",
|
|
911
|
-
dotenv: "^16.0.3",
|
|
912
|
-
jest: "^29.2.2",
|
|
913
|
-
"jest-environment-jsdom": "^29.2.2",
|
|
914
|
-
microbundle: "^0.15.1"
|
|
915
|
-
};
|
|
916
|
-
var peerDependencies = {
|
|
917
|
-
next: "^12 || ^13",
|
|
918
|
-
react: "^17 || ^18"
|
|
919
|
-
};
|
|
920
|
-
var pkg = {
|
|
921
|
-
name: name,
|
|
922
|
-
version: version,
|
|
923
|
-
main: main,
|
|
924
|
-
module: module,
|
|
925
|
-
"umd:main": "dist/next-cloudinary.umd.js",
|
|
926
|
-
source: source,
|
|
927
|
-
scripts: scripts,
|
|
928
|
-
dependencies: dependencies,
|
|
929
|
-
devDependencies: devDependencies,
|
|
930
|
-
peerDependencies: peerDependencies
|
|
931
|
-
};
|
|
932
|
-
|
|
933
888
|
const transformationPlugins = [
|
|
934
889
|
// Background Removal must always come first
|
|
935
890
|
removeBackgroundPlugin, croppingPlugin, effectsPlugin, overlaysPlugin, namedTransformationsPlugin, underlaysPlugin, zoompanPlugin,
|
|
936
891
|
// Raw transformations needs to be last simply to make sure
|
|
937
892
|
// it's always expected to applied the same way
|
|
938
|
-
|
|
939
893
|
rawTransformationsPlugin];
|
|
940
894
|
let cld;
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
* constructCloudinaryUrl
|
|
895
|
+
/**
|
|
896
|
+
* constructCloudinaryUrl
|
|
944
897
|
*/
|
|
945
|
-
|
|
946
898
|
function constructCloudinaryUrl({
|
|
947
899
|
options,
|
|
948
900
|
config
|
|
@@ -951,54 +903,51 @@ function constructCloudinaryUrl({
|
|
|
951
903
|
cld = new Cloudinary(_extends({
|
|
952
904
|
cloud: {
|
|
953
905
|
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
|
|
906
|
+
},
|
|
907
|
+
url: {
|
|
908
|
+
// Used to avoid issues with SSR particularly for the blurred placeholder
|
|
909
|
+
analytics: false
|
|
954
910
|
}
|
|
955
911
|
}, config));
|
|
956
912
|
}
|
|
957
|
-
const publicId = getPublicId(options.src);
|
|
913
|
+
const publicId = getPublicId(options == null ? void 0 : options.src);
|
|
958
914
|
const cldImage = cld.image(publicId);
|
|
959
915
|
transformationPlugins.forEach(({
|
|
960
916
|
plugin
|
|
961
917
|
}) => {
|
|
918
|
+
// @ts-ignore
|
|
962
919
|
const {
|
|
963
920
|
options: pluginOptions
|
|
964
921
|
} = plugin({
|
|
965
922
|
cldImage,
|
|
966
923
|
options
|
|
967
924
|
}) || {};
|
|
968
|
-
if (pluginOptions != null && pluginOptions.format) {
|
|
925
|
+
if (pluginOptions != null && pluginOptions.format && options) {
|
|
969
926
|
options.format = pluginOptions.format;
|
|
970
927
|
}
|
|
971
|
-
if (pluginOptions != null && pluginOptions.width) {
|
|
928
|
+
if (pluginOptions != null && pluginOptions.width && options) {
|
|
972
929
|
options.resize = {
|
|
973
930
|
width: pluginOptions == null ? void 0 : pluginOptions.width
|
|
974
931
|
};
|
|
975
932
|
}
|
|
976
933
|
});
|
|
977
|
-
if (options.resize) {
|
|
934
|
+
if (options != null && options.resize) {
|
|
978
935
|
const {
|
|
979
936
|
width,
|
|
980
937
|
crop = 'scale'
|
|
981
938
|
} = options.resize;
|
|
982
939
|
cldImage.effect(`c_${crop},w_${width}`);
|
|
983
940
|
}
|
|
984
|
-
return cldImage.setDeliveryType(options.deliveryType || 'upload').format(options.format || 'auto').delivery(`q_${options.quality || 'auto'}`).toURL(
|
|
985
|
-
trackedAnalytics: {
|
|
986
|
-
sdkCode: NEXT_CLOUDINARY_ANALYTICS_ID,
|
|
987
|
-
sdkSemver: pkg.version,
|
|
988
|
-
techVersion: nextPkg.version
|
|
989
|
-
}
|
|
990
|
-
});
|
|
941
|
+
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();
|
|
991
942
|
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
*
|
|
997
|
-
*
|
|
998
|
-
*
|
|
999
|
-
* @return {string} The images public id
|
|
943
|
+
/**
|
|
944
|
+
* Retrieves the public id of a cloudiary image url. If no url is recognized it returns the parameter it self.
|
|
945
|
+
* If it's recognized that is a url and it's not possible to get the public id, it warns the user.
|
|
946
|
+
*
|
|
947
|
+
* @param {string} src The cloudiary url or public id.
|
|
948
|
+
*
|
|
949
|
+
* @return {string} The images public id
|
|
1000
950
|
*/
|
|
1001
|
-
|
|
1002
951
|
function getPublicId(src) {
|
|
1003
952
|
if (typeof src !== 'string') {
|
|
1004
953
|
throw new Error(`Invalid src of type ${typeof src}`);
|
|
@@ -1018,11 +967,9 @@ function getPublicId(src) {
|
|
|
1018
967
|
}
|
|
1019
968
|
return src;
|
|
1020
969
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
* createPlaceholderUrl
|
|
970
|
+
/**
|
|
971
|
+
* createPlaceholderUrl
|
|
1024
972
|
*/
|
|
1025
|
-
|
|
1026
973
|
function createPlaceholderUrl({
|
|
1027
974
|
src,
|
|
1028
975
|
placeholder = true,
|
|
@@ -1047,11 +994,9 @@ function createPlaceholderUrl({
|
|
|
1047
994
|
config
|
|
1048
995
|
});
|
|
1049
996
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
* pollForProcessingImage
|
|
997
|
+
/**
|
|
998
|
+
* pollForProcessingImage
|
|
1053
999
|
*/
|
|
1054
|
-
|
|
1055
1000
|
async function pollForProcessingImage(options) {
|
|
1056
1001
|
const {
|
|
1057
1002
|
src
|
|
@@ -1113,23 +1058,21 @@ const CldImage = props => {
|
|
|
1113
1058
|
CLD_OPTIONS.push(prop);
|
|
1114
1059
|
});
|
|
1115
1060
|
});
|
|
1116
|
-
|
|
1117
1061
|
// Construct the base Image component props by filtering out Cloudinary-specific props
|
|
1118
|
-
|
|
1119
|
-
|
|
1062
|
+
const imageProps = {
|
|
1063
|
+
alt: props.alt,
|
|
1064
|
+
src: props.src
|
|
1065
|
+
};
|
|
1120
1066
|
Object.keys(props).filter(key => !CLD_OPTIONS.includes(key)).forEach(key => imageProps[key] = props[key]);
|
|
1121
1067
|
const defaultImgKey = Object.keys(imageProps).map(key => `${key}:${imageProps[key]}`).join(';');
|
|
1122
1068
|
const [imgKey, setImgKey] = useState(defaultImgKey);
|
|
1123
|
-
|
|
1124
1069
|
// Construct Cloudinary-specific props by looking for values for any of the supported prop keys
|
|
1125
|
-
|
|
1126
1070
|
const cldOptions = {};
|
|
1127
1071
|
CLD_OPTIONS.forEach(key => {
|
|
1128
1072
|
if (props[key]) {
|
|
1129
1073
|
cldOptions[key] = props[key];
|
|
1130
1074
|
}
|
|
1131
1075
|
});
|
|
1132
|
-
|
|
1133
1076
|
// If we see a placeholder option, configure a Cloudinary-based URL.
|
|
1134
1077
|
// The resulting image will always be blurred per Next.js, so we're
|
|
1135
1078
|
// limited on options for placeholders.
|
|
@@ -1138,7 +1081,6 @@ const CldImage = props => {
|
|
|
1138
1081
|
// an Image component prop as opposed to simply the URL
|
|
1139
1082
|
//
|
|
1140
1083
|
// https://nextjs.org/docs/api-reference/next/image#blurdataurl
|
|
1141
|
-
|
|
1142
1084
|
if (imageProps.placeholder) {
|
|
1143
1085
|
const publicId = getPublicId(props.src);
|
|
1144
1086
|
imageProps.blurDataURL = createPlaceholderUrl({
|
|
@@ -1151,13 +1093,12 @@ const CldImage = props => {
|
|
|
1151
1093
|
}
|
|
1152
1094
|
if (props.src && props.preserveTransformations) {
|
|
1153
1095
|
const transformations = getTransformations(props.src, props.preserveTransformations);
|
|
1154
|
-
imageProps.rawTransformations
|
|
1096
|
+
const rawTransformations = imageProps.rawTransformations ? [...imageProps.rawTransformations] : [];
|
|
1097
|
+
imageProps.rawTransformations = [...rawTransformations, ...transformations];
|
|
1155
1098
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
* handleOnError
|
|
1099
|
+
/**
|
|
1100
|
+
* handleOnError
|
|
1159
1101
|
*/
|
|
1160
|
-
|
|
1161
1102
|
async function handleOnError(options) {
|
|
1162
1103
|
const result = await pollForProcessingImage({
|
|
1163
1104
|
src: options.target.src
|
|
@@ -1190,15 +1131,14 @@ const CldOgImage = _ref => {
|
|
|
1190
1131
|
width: props.width || IMAGE_WIDTH,
|
|
1191
1132
|
height: props.height || IMAGE_HEIGHT,
|
|
1192
1133
|
crop: props.crop || 'fill',
|
|
1193
|
-
gravity: props.gravity || 'center'
|
|
1134
|
+
gravity: props.gravity || 'center',
|
|
1135
|
+
alt: props.alt
|
|
1194
1136
|
});
|
|
1195
1137
|
const ogImageUrl = constructCloudinaryUrl({
|
|
1196
1138
|
options
|
|
1197
1139
|
});
|
|
1198
|
-
|
|
1199
1140
|
// We need to include the tags within the Next.js Head component rather than
|
|
1200
1141
|
// direcly adding them inside of the Head otherwise we get unexpected results
|
|
1201
|
-
|
|
1202
1142
|
return /*#__PURE__*/jsxs(Head, {
|
|
1203
1143
|
children: [/*#__PURE__*/jsx("meta", {
|
|
1204
1144
|
property: "og:image",
|
|
@@ -1238,12 +1178,10 @@ const CldUploadWidget = ({
|
|
|
1238
1178
|
const cloudinary = useRef();
|
|
1239
1179
|
const widget = useRef();
|
|
1240
1180
|
const signed = !!signatureEndpoint;
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
*
|
|
1244
|
-
* @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
|
|
1181
|
+
/**
|
|
1182
|
+
* generateSignature
|
|
1183
|
+
* @description Makes a request to an endpoint to sign Cloudinary parameters as part of widget creation
|
|
1245
1184
|
*/
|
|
1246
|
-
|
|
1247
1185
|
function generateSignature(callback, paramsToSign) {
|
|
1248
1186
|
fetch(signatureEndpoint, {
|
|
1249
1187
|
method: "POST",
|
|
@@ -1256,19 +1194,16 @@ const CldUploadWidget = ({
|
|
|
1256
1194
|
callback(signature);
|
|
1257
1195
|
});
|
|
1258
1196
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
*
|
|
1262
|
-
* @description Creates a new instance of the Cloudinary widget and stores in a ref
|
|
1197
|
+
/**
|
|
1198
|
+
* createWidget
|
|
1199
|
+
* @description Creates a new instance of the Cloudinary widget and stores in a ref
|
|
1263
1200
|
*/
|
|
1264
|
-
|
|
1265
1201
|
function createWidget() {
|
|
1266
1202
|
var _cloudinary$current;
|
|
1267
1203
|
// When creating a signed upload, you need to provide both your Cloudinary API Key
|
|
1268
1204
|
// as well as a signature generator function that will sign any paramters
|
|
1269
1205
|
// either on page load or during the upload process. Read more about signed uploads at:
|
|
1270
1206
|
// https://cloudinary.com/documentation/upload_widget#signed_uploads
|
|
1271
|
-
|
|
1272
1207
|
const uploadOptions = _extends({
|
|
1273
1208
|
cloudName: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
|
|
1274
1209
|
uploadPreset: uploadPreset || process.env.NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET,
|
|
@@ -1276,13 +1211,12 @@ const CldUploadWidget = ({
|
|
|
1276
1211
|
}, options);
|
|
1277
1212
|
if (signed) {
|
|
1278
1213
|
uploadOptions.uploadSignature = generateSignature;
|
|
1279
|
-
|
|
1280
1214
|
// No need for apiSecret here because of api/sign-cloudinary-params
|
|
1281
|
-
|
|
1282
1215
|
if (!uploadOptions.apiKey) {
|
|
1283
1216
|
return new Error("Signed Upload needs apiKey!");
|
|
1284
1217
|
}
|
|
1285
1218
|
}
|
|
1219
|
+
// @ts-ignore
|
|
1286
1220
|
return (_cloudinary$current = cloudinary.current) == null ? void 0 : _cloudinary$current.createUploadWidget(uploadOptions, function (error, result) {
|
|
1287
1221
|
// The callback is a bit more chatty than failed or success so
|
|
1288
1222
|
// only trigger when one of those are the case. You can additionally
|
|
@@ -1293,25 +1227,23 @@ const CldUploadWidget = ({
|
|
|
1293
1227
|
}
|
|
1294
1228
|
});
|
|
1295
1229
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
* open
|
|
1299
|
-
* @description When triggered, uses the current widget instance to open the upload modal
|
|
1230
|
+
/**
|
|
1231
|
+
* open
|
|
1232
|
+
* @description When triggered, uses the current widget instance to open the upload modal
|
|
1300
1233
|
*/
|
|
1301
|
-
|
|
1302
1234
|
function open() {
|
|
1303
1235
|
if (!(widget != null && widget.current)) {
|
|
1304
1236
|
widget.current = createWidget();
|
|
1305
1237
|
}
|
|
1238
|
+
// @ts-ignore
|
|
1306
1239
|
(widget == null ? void 0 : widget.current) && widget.current.open();
|
|
1307
1240
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
*
|
|
1311
|
-
* @description Stores the Cloudinary window instance to a ref when the widget script loads
|
|
1241
|
+
/**
|
|
1242
|
+
* handleOnLoad
|
|
1243
|
+
* @description Stores the Cloudinary window instance to a ref when the widget script loads
|
|
1312
1244
|
*/
|
|
1313
|
-
|
|
1314
1245
|
function handleOnLoad() {
|
|
1246
|
+
// @ts-ignore
|
|
1315
1247
|
cloudinary.current = window.cloudinary;
|
|
1316
1248
|
}
|
|
1317
1249
|
return /*#__PURE__*/jsxs(Fragment, {
|