@conloca/cms-spa 0.1.13 → 0.1.14

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.
@@ -2,7 +2,7 @@ import { BlockTypeSelect, BoldItalicUnderlineToggles, CreateLink, DiffSourceTogg
2
2
  import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import "@mdxeditor/editor/style.css";
4
4
  import { Folder, FolderPlus, Search, Upload, X } from "lucide-react";
5
- import { useAssetFolders, useAssetUsage, useCreateFolder, useDeleteAsset, useFolderTree as useFolderTree$1, useImportAssetUrl, useMoveAssets, useUpdateAssetMetadata, useUploadAsset } from "@conloca/content-api-client";
5
+ import { useAssetFolders, useAssetUsage, useBulkDeleteAssets, useCreateFolder, useDeleteAsset, useFolderTree as useFolderTree$1, useImportAssetUrl, useMoveAssets, useUpdateAssetMetadata, useUploadAsset } from "@conloca/content-api-client";
6
6
  import { clsx } from "clsx";
7
7
  import { twMerge } from "tailwind-merge";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -239,6 +239,153 @@ async function buildUploadFormData(file, alt, folder) {
239
239
  return formData;
240
240
  }
241
241
 
242
+ //#endregion
243
+ //#region src/hooks/useUploadFlow.ts
244
+ const ACCEPTED_TYPES = "image/jpeg,image/png,image/gif,image/webp,image/svg+xml,image/avif";
245
+ function useUploadFlow({ folder, onUploadComplete, onSuccess }) {
246
+ const [isDragOver, setIsDragOver] = useState(false);
247
+ const [altText, setAltText] = useState("");
248
+ const [pendingFile, setPendingFile] = useState(null);
249
+ const [activeTab, setActiveTab] = useState("file");
250
+ const [importUrl, setImportUrl] = useState("");
251
+ const [uploadProgress, setUploadProgress] = useState(null);
252
+ const fileInputRef = useRef(null);
253
+ const uploadMutation = useUploadAsset();
254
+ const importMutation = useImportAssetUrl();
255
+ const previewUrl = useMemo(() => {
256
+ if (!pendingFile) return null;
257
+ return URL.createObjectURL(pendingFile);
258
+ }, [pendingFile]);
259
+ useEffect(() => {
260
+ return () => {
261
+ if (previewUrl) URL.revokeObjectURL(previewUrl);
262
+ };
263
+ }, [previewUrl]);
264
+ const isUploading = uploadMutation.isPending || importMutation.isPending || (uploadProgress?.inProgress ?? false);
265
+ const error = uploadMutation.error || importMutation.error;
266
+ const reset = useCallback(() => {
267
+ setPendingFile(null);
268
+ setAltText("");
269
+ setImportUrl("");
270
+ setUploadProgress(null);
271
+ setActiveTab("file");
272
+ setIsDragOver(false);
273
+ if (fileInputRef.current) fileInputRef.current.value = "";
274
+ }, []);
275
+ const handleSingleFile = useCallback((file) => {
276
+ setPendingFile(file);
277
+ setAltText("");
278
+ }, []);
279
+ const handleMultipleFiles = useCallback(async (files) => {
280
+ if (files.length === 0) return;
281
+ if (files.length === 1) {
282
+ handleSingleFile(files[0]);
283
+ return;
284
+ }
285
+ setUploadProgress({
286
+ total: files.length,
287
+ completed: 0,
288
+ failed: 0,
289
+ inProgress: true
290
+ });
291
+ const uploadPromises = files.map(async (file) => {
292
+ const formData = await buildUploadFormData(file, void 0, folder);
293
+ return uploadMutation.mutateAsync(formData);
294
+ });
295
+ const results = await Promise.allSettled(uploadPromises);
296
+ const completed = results.filter((r) => r.status === "fulfilled").length;
297
+ const failed = results.filter((r) => r.status === "rejected").length;
298
+ setUploadProgress({
299
+ total: files.length,
300
+ completed,
301
+ failed,
302
+ inProgress: false
303
+ });
304
+ setTimeout(() => {
305
+ setUploadProgress(null);
306
+ if (completed > 0) onUploadComplete?.();
307
+ onSuccess?.();
308
+ }, 2e3);
309
+ }, [
310
+ folder,
311
+ uploadMutation,
312
+ handleSingleFile,
313
+ onUploadComplete,
314
+ onSuccess
315
+ ]);
316
+ const handleFiles = useCallback((fileList) => {
317
+ if (!fileList || fileList.length === 0) return;
318
+ handleMultipleFiles(Array.from(fileList));
319
+ }, [handleMultipleFiles]);
320
+ const handleDragOver = useCallback((e) => {
321
+ e.preventDefault();
322
+ setIsDragOver(true);
323
+ }, []);
324
+ const handleDragLeave = useCallback((e) => {
325
+ e.preventDefault();
326
+ setIsDragOver(false);
327
+ }, []);
328
+ const handleDrop = useCallback((e) => {
329
+ e.preventDefault();
330
+ setIsDragOver(false);
331
+ handleFiles(e.dataTransfer.files);
332
+ }, [handleFiles]);
333
+ const handleUpload = async () => {
334
+ if (!pendingFile) return;
335
+ const formData = await buildUploadFormData(pendingFile, altText || void 0, folder);
336
+ uploadMutation.mutate(formData, { onSuccess: () => {
337
+ setPendingFile(null);
338
+ setAltText("");
339
+ if (fileInputRef.current) fileInputRef.current.value = "";
340
+ onUploadComplete?.();
341
+ onSuccess?.();
342
+ } });
343
+ };
344
+ const handleImportUrl = () => {
345
+ if (!importUrl.trim()) return;
346
+ importMutation.mutate({
347
+ url: importUrl.trim(),
348
+ alt: altText || void 0,
349
+ folder
350
+ }, { onSuccess: () => {
351
+ setImportUrl("");
352
+ setAltText("");
353
+ onUploadComplete?.();
354
+ onSuccess?.();
355
+ } });
356
+ };
357
+ const handleCancel = () => {
358
+ setPendingFile(null);
359
+ setAltText("");
360
+ if (fileInputRef.current) fileInputRef.current.value = "";
361
+ };
362
+ return {
363
+ isDragOver,
364
+ altText,
365
+ setAltText,
366
+ pendingFile,
367
+ activeTab,
368
+ setActiveTab,
369
+ importUrl,
370
+ setImportUrl,
371
+ uploadProgress,
372
+ fileInputRef,
373
+ previewUrl,
374
+ isUploading,
375
+ error,
376
+ uploadMutationIsPending: uploadMutation.isPending,
377
+ importMutationIsPending: importMutation.isPending,
378
+ handleFiles,
379
+ handleDragOver,
380
+ handleDragLeave,
381
+ handleDrop,
382
+ handleUpload,
383
+ handleImportUrl,
384
+ handleCancel,
385
+ reset
386
+ };
387
+ }
388
+
242
389
  //#endregion
243
390
  //#region src/utils/cn.ts
244
391
  function cn$1(...inputs) {
@@ -676,39 +823,12 @@ function MediaLibrary({ folder: initialFolder = "/", onFolderChange, showToolbar
676
823
 
677
824
  //#endregion
678
825
  //#region src/components/media/UploadModal.tsx
679
- const ACCEPTED_TYPES = "image/jpeg,image/png,image/gif,image/webp,image/svg+xml,image/avif";
680
826
  function UploadModal({ isOpen, onClose, folder, onUploadComplete }) {
681
- const [activeTab, setActiveTab] = useState("file");
682
- const [isDragOver, setIsDragOver] = useState(false);
683
- const [pendingFile, setPendingFile] = useState(null);
684
- const [altText, setAltText] = useState("");
685
- const [customName, setCustomName] = useState("");
686
- const [importUrl, setImportUrl] = useState("");
687
- const [uploadProgress, setUploadProgress] = useState(null);
688
- const fileInputRef = useRef(null);
689
- const uploadMutation = useUploadAsset();
690
- const importMutation = useImportAssetUrl();
691
- const previewUrl = useMemo(() => {
692
- if (!pendingFile) return null;
693
- return URL.createObjectURL(pendingFile);
694
- }, [pendingFile]);
695
- useEffect(() => {
696
- return () => {
697
- if (previewUrl) URL.revokeObjectURL(previewUrl);
698
- };
699
- }, [previewUrl]);
700
- const isUploading = uploadMutation.isPending || importMutation.isPending || (uploadProgress?.inProgress ?? false);
701
- const error = uploadMutation.error || importMutation.error;
702
- const resetState = useCallback(() => {
703
- setPendingFile(null);
704
- setAltText("");
705
- setCustomName("");
706
- setImportUrl("");
707
- setUploadProgress(null);
708
- setActiveTab("file");
709
- setIsDragOver(false);
710
- if (fileInputRef.current) fileInputRef.current.value = "";
711
- }, []);
827
+ const { activeTab, setActiveTab, isDragOver, pendingFile, altText, setAltText, importUrl, setImportUrl, uploadProgress, fileInputRef, previewUrl, isUploading, error, uploadMutationIsPending, importMutationIsPending, handleFiles, handleDragOver, handleDragLeave, handleDrop, handleUpload, handleImportUrl, handleCancel, reset } = useUploadFlow({
828
+ folder,
829
+ onUploadComplete,
830
+ onSuccess: onClose
831
+ });
712
832
  useEffect(() => {
713
833
  if (!isOpen) return;
714
834
  const handleKeyDown = (e) => {
@@ -718,91 +838,8 @@ function UploadModal({ isOpen, onClose, folder, onUploadComplete }) {
718
838
  return () => document.removeEventListener("keydown", handleKeyDown);
719
839
  }, [isOpen, onClose]);
720
840
  useEffect(() => {
721
- if (!isOpen) resetState();
722
- }, [isOpen, resetState]);
723
- const handleSingleFile = useCallback((file) => {
724
- setPendingFile(file);
725
- setAltText("");
726
- setCustomName("");
727
- }, []);
728
- const handleMultipleFiles = useCallback(async (files) => {
729
- if (files.length === 0) return;
730
- if (files.length === 1) {
731
- handleSingleFile(files[0]);
732
- return;
733
- }
734
- setUploadProgress({
735
- total: files.length,
736
- completed: 0,
737
- failed: 0,
738
- inProgress: true
739
- });
740
- const uploadPromises = files.map(async (file) => {
741
- const formData = await buildUploadFormData(file, void 0, folder);
742
- return uploadMutation.mutateAsync(formData);
743
- });
744
- const results = await Promise.allSettled(uploadPromises);
745
- const completed = results.filter((r) => r.status === "fulfilled").length;
746
- const failed = results.filter((r) => r.status === "rejected").length;
747
- setUploadProgress({
748
- total: files.length,
749
- completed,
750
- failed,
751
- inProgress: false
752
- });
753
- setTimeout(() => {
754
- if (completed > 0) onUploadComplete?.();
755
- onClose();
756
- }, 2e3);
757
- }, [
758
- folder,
759
- uploadMutation,
760
- handleSingleFile,
761
- onUploadComplete,
762
- onClose
763
- ]);
764
- const handleFiles = useCallback((fileList) => {
765
- if (!fileList || fileList.length === 0) return;
766
- handleMultipleFiles(Array.from(fileList));
767
- }, [handleMultipleFiles]);
768
- const handleDragOver = useCallback((e) => {
769
- e.preventDefault();
770
- setIsDragOver(true);
771
- }, []);
772
- const handleDragLeave = useCallback((e) => {
773
- e.preventDefault();
774
- setIsDragOver(false);
775
- }, []);
776
- const handleDrop = useCallback((e) => {
777
- e.preventDefault();
778
- setIsDragOver(false);
779
- handleFiles(e.dataTransfer.files);
780
- }, [handleFiles]);
781
- const handleUpload = async () => {
782
- if (!pendingFile) return;
783
- const formData = await buildUploadFormData(pendingFile, altText || void 0, folder);
784
- uploadMutation.mutate(formData, { onSuccess: () => {
785
- onUploadComplete?.();
786
- onClose();
787
- } });
788
- };
789
- const handleImportUrl = () => {
790
- if (!importUrl.trim()) return;
791
- importMutation.mutate({
792
- url: importUrl.trim(),
793
- alt: altText || void 0,
794
- folder
795
- }, { onSuccess: () => {
796
- onUploadComplete?.();
797
- onClose();
798
- } });
799
- };
800
- const handleCancel = () => {
801
- setPendingFile(null);
802
- setAltText("");
803
- setCustomName("");
804
- if (fileInputRef.current) fileInputRef.current.value = "";
805
- };
841
+ if (!isOpen) reset();
842
+ }, [isOpen, reset]);
806
843
  if (!isOpen) return null;
807
844
  return /* @__PURE__ */ jsx("div", {
808
845
  className: "fixed inset-0 bg-black/50 flex items-center justify-center z-50",
@@ -862,59 +899,37 @@ function UploadModal({ isOpen, onClose, folder, onUploadComplete }) {
862
899
  ]
863
900
  }), pendingFile ? /* @__PURE__ */ jsxs("div", {
864
901
  className: "space-y-4",
865
- children: [
866
- /* @__PURE__ */ jsxs("div", {
867
- className: "flex items-center gap-3",
868
- children: [/* @__PURE__ */ jsx("div", {
869
- className: "w-16 h-16 bg-grey-09 rounded overflow-hidden flex-shrink-0",
870
- children: /* @__PURE__ */ jsx("img", {
871
- src: previewUrl,
872
- alt: "Preview",
873
- className: "w-full h-full object-contain"
874
- })
875
- }), /* @__PURE__ */ jsxs("div", {
876
- className: "flex-1 min-w-0",
877
- children: [/* @__PURE__ */ jsx("p", {
878
- className: "text-sm font-medium text-grey-01 truncate",
879
- children: pendingFile.name
880
- }), /* @__PURE__ */ jsxs("p", {
881
- className: "text-xs text-grey-04",
882
- children: [(pendingFile.size / 1024).toFixed(1), " KB"]
883
- })]
884
- })]
885
- }),
886
- /* @__PURE__ */ jsxs("div", { children: [
887
- /* @__PURE__ */ jsx("label", {
888
- htmlFor: "custom-name",
889
- className: "block text-xs text-grey-04 uppercase tracking-wide mb-1",
890
- children: "Asset Name (optional)"
891
- }),
892
- /* @__PURE__ */ jsx("input", {
893
- id: "custom-name",
894
- type: "text",
895
- value: customName,
896
- onChange: (e) => setCustomName(e.target.value),
897
- placeholder: pendingFile.name,
898
- className: "w-full px-3 py-2 border border-grey-09 rounded text-sm focus:outline-none focus:ring-2 focus:ring-azure-04 focus:border-azure-04"
899
- }),
900
- /* @__PURE__ */ jsx("p", {
901
- className: "mt-1 text-xs text-grey-07",
902
- children: "Leave blank to use original filename"
902
+ children: [/* @__PURE__ */ jsxs("div", {
903
+ className: "flex items-center gap-3",
904
+ children: [/* @__PURE__ */ jsx("div", {
905
+ className: "w-16 h-16 bg-grey-09 rounded overflow-hidden flex-shrink-0",
906
+ children: /* @__PURE__ */ jsx("img", {
907
+ src: previewUrl,
908
+ alt: "Preview",
909
+ className: "w-full h-full object-contain"
903
910
  })
904
- ] }),
905
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("label", {
906
- htmlFor: "alt-text",
907
- className: "block text-xs text-grey-04 uppercase tracking-wide mb-1",
908
- children: "Alt Text"
909
- }), /* @__PURE__ */ jsx("input", {
910
- id: "alt-text",
911
- type: "text",
912
- value: altText,
913
- onChange: (e) => setAltText(e.target.value),
914
- placeholder: "Describe the image for accessibility",
915
- className: "w-full px-3 py-2 border border-grey-09 rounded text-sm focus:outline-none focus:ring-2 focus:ring-azure-04 focus:border-azure-04"
916
- })] })
917
- ]
911
+ }), /* @__PURE__ */ jsxs("div", {
912
+ className: "flex-1 min-w-0",
913
+ children: [/* @__PURE__ */ jsx("p", {
914
+ className: "text-sm font-medium text-grey-01 truncate",
915
+ children: pendingFile.name
916
+ }), /* @__PURE__ */ jsxs("p", {
917
+ className: "text-xs text-grey-04",
918
+ children: [(pendingFile.size / 1024).toFixed(1), " KB"]
919
+ })]
920
+ })]
921
+ }), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("label", {
922
+ htmlFor: "alt-text",
923
+ className: "block text-xs text-grey-04 uppercase tracking-wide mb-1",
924
+ children: "Alt Text"
925
+ }), /* @__PURE__ */ jsx("input", {
926
+ id: "alt-text",
927
+ type: "text",
928
+ value: altText,
929
+ onChange: (e) => setAltText(e.target.value),
930
+ placeholder: "Describe the image for accessibility",
931
+ className: "w-full px-3 py-2 border border-grey-09 rounded text-sm focus:outline-none focus:ring-2 focus:ring-azure-04 focus:border-azure-04"
932
+ })] })]
918
933
  }) : /* @__PURE__ */ jsxs("div", {
919
934
  onDragOver: handleDragOver,
920
935
  onDragLeave: handleDragLeave,
@@ -994,13 +1009,13 @@ function UploadModal({ isOpen, onClose, folder, onUploadComplete }) {
994
1009
  onClick: handleUpload,
995
1010
  disabled: isUploading || !pendingFile,
996
1011
  className: "flex items-center gap-2 px-4 py-2 bg-azure-04 text-white text-sm rounded hover:bg-azure-03 disabled:opacity-50 transition-colors",
997
- children: [/* @__PURE__ */ jsx(Upload, { className: "w-4 h-4" }), uploadMutation.isPending ? "Uploading..." : "Upload"]
1012
+ children: [/* @__PURE__ */ jsx(Upload, { className: "w-4 h-4" }), uploadMutationIsPending ? "Uploading..." : "Upload"]
998
1013
  }) : /* @__PURE__ */ jsxs("button", {
999
1014
  type: "button",
1000
1015
  onClick: handleImportUrl,
1001
1016
  disabled: isUploading || !importUrl.trim(),
1002
1017
  className: "flex items-center gap-2 px-4 py-2 bg-azure-04 text-white text-sm rounded hover:bg-azure-03 disabled:opacity-50 transition-colors",
1003
- children: [/* @__PURE__ */ jsx(Upload, { className: "w-4 h-4" }), importMutation.isPending ? "Importing..." : "Import"]
1018
+ children: [/* @__PURE__ */ jsx(Upload, { className: "w-4 h-4" }), importMutationIsPending ? "Importing..." : "Import"]
1004
1019
  })]
1005
1020
  })
1006
1021
  ]
@@ -1158,6 +1173,7 @@ var MDXEditorErrorBoundary = class extends React.Component {
1158
1173
  * This component wraps MDXEditor with ImagePickerDialog and keyboard shortcuts.
1159
1174
  */
1160
1175
  const CMSMDXEditor = React.forwardRef(({ value, onChange, onSave, readOnly = false }, ref) => {
1176
+ const insertImageRef = useRef(null);
1161
1177
  useEffect(() => {
1162
1178
  const handleKeyDown = (e) => {
1163
1179
  if ((e.ctrlKey || e.metaKey) && e.key === "s") {
@@ -1166,7 +1182,8 @@ const CMSMDXEditor = React.forwardRef(({ value, onChange, onSave, readOnly = fal
1166
1182
  }
1167
1183
  if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === "i") {
1168
1184
  e.preventDefault();
1169
- document.querySelector("[aria-label=\"Insert image\"]")?.click();
1185
+ if (insertImageRef.current) insertImageRef.current.click();
1186
+ else console.warn("[CMSMDXEditor] InsertImage ref not attached — toolbar may not be rendered");
1170
1187
  }
1171
1188
  };
1172
1189
  document.addEventListener("keydown", handleKeyDown);
@@ -1219,7 +1236,7 @@ const CMSMDXEditor = React.forwardRef(({ value, onChange, onSave, readOnly = fal
1219
1236
  /* @__PURE__ */ jsx(BlockTypeSelect, {}),
1220
1237
  /* @__PURE__ */ jsx(Separator, {}),
1221
1238
  /* @__PURE__ */ jsx(CreateLink, {}),
1222
- /* @__PURE__ */ jsx(InsertImage, {}),
1239
+ React.createElement(InsertImage, { ref: insertImageRef }),
1223
1240
  /* @__PURE__ */ jsx(InsertTable, {}),
1224
1241
  /* @__PURE__ */ jsx(InsertThematicBreak, {}),
1225
1242
  /* @__PURE__ */ jsx(Separator, {}),
@@ -1512,5 +1529,5 @@ function MDXContent(props) {
1512
1529
  }
1513
1530
 
1514
1531
  //#endregion
1515
- export { getUIConfig as _, MediaLibrary as a, useClickOutside as b, FolderTreeSidebar as c, useDeleteAsset as d, useFolderTree$1 as f, configureUI as g, useSiteBaseUrl as h, UploadModal as i, cn$1 as l, useUpdateAssetMetadata as m, CMSMDXEditorModal as n, MediaToolbar as o, useMoveAssets as p, ImagePicker as r, buildAssetServeUrl as s, MDXContent as t, useAssetUsage as u, useErrorModal as v, useDialogState as y };
1516
- //# sourceMappingURL=puck-DjVdP1zb.mjs.map
1532
+ export { configureUI as _, MediaLibrary as a, useDialogState as b, FolderTreeSidebar as c, useBulkDeleteAssets as d, useDeleteAsset as f, useSiteBaseUrl as g, useUpdateAssetMetadata as h, UploadModal as i, cn$1 as l, useMoveAssets as m, CMSMDXEditorModal as n, MediaToolbar as o, useFolderTree$1 as p, ImagePicker as r, buildAssetServeUrl as s, MDXContent as t, useAssetUsage as u, getUIConfig as v, useClickOutside as x, useErrorModal as y };
1533
+ //# sourceMappingURL=puck-CvjeYQRH.mjs.map