@e-llm-studio/instant-learning 1.3.22 → 1.3.24-alpha.2

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.
Files changed (50) hide show
  1. package/dist/cjs/features/LearningManagement/LearningManagement.js +27 -0
  2. package/dist/cjs/features/LearningManagement/LearningManagement.js.map +1 -1
  3. package/dist/cjs/features/LearningManagement/LearningTemplateLayout.js +4 -2
  4. package/dist/cjs/features/LearningManagement/LearningTemplateLayout.js.map +1 -1
  5. package/dist/cjs/features/LearningManagement/RuleContent/RuleContent.js +11 -1
  6. package/dist/cjs/features/LearningManagement/RuleContent/RuleContent.js.map +1 -1
  7. package/dist/cjs/features/LearningManagement/components/InstantLearningModalDynamic.js +39 -29
  8. package/dist/cjs/features/LearningManagement/components/InstantLearningModalDynamic.js.map +1 -1
  9. package/dist/cjs/features/LearningManagement/utils/learningFlow.js +92 -0
  10. package/dist/cjs/features/LearningManagement/utils/learningFlow.js.map +1 -1
  11. package/dist/cjs/schema-driven/components/FileUploadField.js +76 -13
  12. package/dist/cjs/schema-driven/components/FileUploadField.js.map +1 -1
  13. package/dist/cjs/schema-driven/components/FileUploadField.module.css.js +1 -1
  14. package/dist/cjs/schema-driven/components/PromptTextEditorField.js +100 -23
  15. package/dist/cjs/schema-driven/components/PromptTextEditorField.js.map +1 -1
  16. package/dist/cjs/schema-driven/utils/fileUploadService.js +46 -0
  17. package/dist/cjs/schema-driven/utils/fileUploadService.js.map +1 -1
  18. package/dist/features/LearningManagement/LearningManagement.js +27 -0
  19. package/dist/features/LearningManagement/LearningManagement.js.map +1 -1
  20. package/dist/features/LearningManagement/LearningTemplateLayout.js +4 -2
  21. package/dist/features/LearningManagement/LearningTemplateLayout.js.map +1 -1
  22. package/dist/features/LearningManagement/RuleContent/RuleContent.js +11 -1
  23. package/dist/features/LearningManagement/RuleContent/RuleContent.js.map +1 -1
  24. package/dist/features/LearningManagement/components/InstantLearningModalDynamic.js +41 -31
  25. package/dist/features/LearningManagement/components/InstantLearningModalDynamic.js.map +1 -1
  26. package/dist/features/LearningManagement/utils/learningFlow.js +92 -1
  27. package/dist/features/LearningManagement/utils/learningFlow.js.map +1 -1
  28. package/dist/schema-driven/components/FileUploadField.js +78 -15
  29. package/dist/schema-driven/components/FileUploadField.js.map +1 -1
  30. package/dist/schema-driven/components/FileUploadField.module.css.js +1 -1
  31. package/dist/schema-driven/components/PromptTextEditorField.js +100 -23
  32. package/dist/schema-driven/components/PromptTextEditorField.js.map +1 -1
  33. package/dist/schema-driven/utils/fileUploadService.js +45 -1
  34. package/dist/schema-driven/utils/fileUploadService.js.map +1 -1
  35. package/dist/types/src/features/LearningManagement/LearningManagement.d.ts +11 -1
  36. package/dist/types/src/features/LearningManagement/LearningManagement.d.ts.map +1 -1
  37. package/dist/types/src/features/LearningManagement/LearningManagementTest.d.ts.map +1 -1
  38. package/dist/types/src/features/LearningManagement/LearningTemplateLayout.d.ts +9 -0
  39. package/dist/types/src/features/LearningManagement/LearningTemplateLayout.d.ts.map +1 -1
  40. package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts +9 -0
  41. package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts.map +1 -1
  42. package/dist/types/src/features/LearningManagement/components/InstantLearningModalDynamic.d.ts.map +1 -1
  43. package/dist/types/src/features/LearningManagement/utils/learningFlow.d.ts +4 -0
  44. package/dist/types/src/features/LearningManagement/utils/learningFlow.d.ts.map +1 -1
  45. package/dist/types/src/schema-driven/components/FileUploadField.d.ts +1 -1
  46. package/dist/types/src/schema-driven/components/FileUploadField.d.ts.map +1 -1
  47. package/dist/types/src/schema-driven/components/PromptTextEditorField.d.ts.map +1 -1
  48. package/dist/types/src/schema-driven/utils/fileUploadService.d.ts +26 -0
  49. package/dist/types/src/schema-driven/utils/fileUploadService.d.ts.map +1 -1
  50. package/package.json +5 -5
@@ -2,6 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var useDynamicFormStore = require('../../../schema-driven/store/useDynamicFormStore.js');
6
+ var useLearningTemplateStore = require('../store/useLearningTemplateStore.js');
7
+
5
8
  const resolveIsEditMode = ({
6
9
  flow,
7
10
  editingRule,
@@ -10,6 +13,95 @@ const resolveIsEditMode = ({
10
13
  if (flow) return flow === "edit";
11
14
  return !!(editingRule || editingVariants && editingVariants.length > 0);
12
15
  };
16
+ const seedHostFormValues = (schema, input) => {
17
+ var _a, _b, _c, _d, _e, _f;
18
+ if (!input || Object.keys(input).length === 0) return;
19
+ const globalValues = {};
20
+ const variantValues = {};
21
+ const learningMetadata = {
22
+ ...(_b = (_a = input.learningMetadata) != null ? _a : input.learning_metadata) != null ? _b : {}
23
+ };
24
+ const metadataValues = (_c = learningMetadata.properties) != null ? _c : learningMetadata;
25
+ const hasValue = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
26
+ const normalizeFieldKey = (key) => key.replace(/[^a-z0-9]/gi, "").toLowerCase();
27
+ const unwrapValue = (value) => value && typeof value === "object" && !Array.isArray(value) && hasValue(value, "value") ? value.value : value;
28
+ const traverse = (properties = {}, inVariant = false) => {
29
+ Object.entries(properties).forEach(([propertyKey, node]) => {
30
+ var _a2, _b2, _c2, _d2;
31
+ const dataKey = node == null ? void 0 : node.data_key;
32
+ const cleanKey = typeof dataKey === "string" ? dataKey.replace(/^global\./, "") : propertyKey;
33
+ const sources = [input, metadataValues];
34
+ const aliases = {
35
+ rule_title: ["title", "ruleTitle"],
36
+ rule_description: ["description", "ruleDescription"],
37
+ wta: ["whenToApply", "when_to_apply"],
38
+ wnta: ["whenNotToApply", "when_not_to_apply"],
39
+ instruction_prompt: ["instructionPrompt"]
40
+ };
41
+ const candidateKeys = [cleanKey, dataKey, propertyKey, ...(_a2 = aliases[propertyKey]) != null ? _a2 : []].filter(Boolean);
42
+ let matchedKey;
43
+ let matchedSource;
44
+ for (const source of sources) {
45
+ matchedKey = candidateKeys.find((key) => hasValue(source, key));
46
+ if (!matchedKey) {
47
+ const normalizedCandidates = new Set(candidateKeys.map(normalizeFieldKey));
48
+ matchedKey = Object.keys(source).find((key) => normalizedCandidates.has(normalizeFieldKey(key)));
49
+ }
50
+ if (matchedKey) {
51
+ matchedSource = source;
52
+ break;
53
+ }
54
+ }
55
+ if (matchedKey) {
56
+ let value = unwrapValue(matchedSource[matchedKey]);
57
+ if ((node == null ? void 0 : node.bpa_ui_component) === "ConditionSection" && Array.isArray(value)) {
58
+ value = value.map((item) => typeof item === "string" ? item : item == null ? void 0 : item.text).filter((item) => typeof item === "string" && item.trim()).join(" OR ");
59
+ }
60
+ const isVariantField = inVariant && !String(dataKey != null ? dataKey : "").startsWith("global.");
61
+ if (isVariantField) {
62
+ (_b2 = variantValues.tier_1) != null ? _b2 : variantValues.tier_1 = {};
63
+ (_d2 = (_c2 = variantValues.tier_1)[0]) != null ? _d2 : _c2[0] = {};
64
+ variantValues.tier_1[0][cleanKey] = value;
65
+ } else {
66
+ globalValues[cleanKey] = value;
67
+ }
68
+ if ((node == null ? void 0 : node.core_field) === false) {
69
+ learningMetadata[propertyKey] = value;
70
+ }
71
+ if (propertyKey === "instruction_prompt" || cleanKey === "instructionPrompt") {
72
+ learningMetadata.instruction_prompt = value;
73
+ }
74
+ }
75
+ if (node == null ? void 0 : node.properties) {
76
+ const isVariantWrapper = (node == null ? void 0 : node.is_repeatable_variant) === true || (node == null ? void 0 : node.bpa_ui_component) === "VariantListWrapper";
77
+ traverse(node.properties, inVariant || isVariantWrapper);
78
+ }
79
+ });
80
+ };
81
+ const schemaRoot = (_d = schema == null ? void 0 : schema.teachMe) != null ? _d : schema;
82
+ if (schemaRoot == null ? void 0 : schemaRoot.properties) {
83
+ traverse(schemaRoot.properties);
84
+ } else {
85
+ Object.entries(input).forEach(([key, value]) => {
86
+ if (key !== "learningMetadata" && key !== "learning_metadata") globalValues[key] = value;
87
+ });
88
+ }
89
+ const explicitMetadata = (_e = input.learningMetadata) != null ? _e : input.learning_metadata;
90
+ if (explicitMetadata && typeof explicitMetadata === "object") {
91
+ Object.assign(learningMetadata, (_f = explicitMetadata.properties) != null ? _f : explicitMetadata);
92
+ }
93
+ if (hasValue(input, "instructionPrompt")) {
94
+ learningMetadata.instruction_prompt = input.instructionPrompt;
95
+ }
96
+ useDynamicFormStore.useDynamicFormStore.getState().initializeStore(globalValues, variantValues);
97
+ if (Object.keys(learningMetadata).length > 0) {
98
+ useLearningTemplateStore.useLearningTemplateStore.getState().setLearningMetadata({
99
+ ...useLearningTemplateStore.useLearningTemplateStore.getState().learningMetadata,
100
+ ...learningMetadata
101
+ });
102
+ }
103
+ };
13
104
 
14
105
  exports.resolveIsEditMode = resolveIsEditMode;
106
+ exports.seedHostFormValues = seedHostFormValues;
15
107
  //# sourceMappingURL=learningFlow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"learningFlow.js","sources":["../../../../../src/features/LearningManagement/utils/learningFlow.ts"],"sourcesContent":["import { RuleDefinition, RuleVariant } from '../types';\n\n/**\n * Explicit source of truth for which Teach Me flow the modal is in.\n *\n * - `\"create\"` → Create/Add UI, ALWAYS, regardless of whether the RHS has\n * pre-populated variant data (e.g. a draft variant seeded into `editingVariants`).\n * - `\"edit\"` → Edit UI for an existing rule/variant.\n *\n * Decoupling the flow from the mere presence of `editingVariants` is what lets a\n * draft variant be populated into the RHS while the form still behaves as a new\n * learning. See RuleContent's `handleEditVariant` for where a draft click sets\n * `flow = \"create\"`.\n */\nexport type InstantLearningFlow = 'create' | 'edit';\n\nexport interface ResolveIsEditModeArgs {\n /** Explicit flow. When provided it is the sole source of truth. */\n flow?: InstantLearningFlow | null;\n editingRule?: RuleDefinition | null;\n editingVariants?: RuleVariant[] | null;\n}\n\n/**\n * Single source of truth for \"is the modal in edit mode?\".\n *\n * When an explicit `flow` is provided it wins outright — so `flow === \"create\"`\n * always means Create/Add even when `editingVariants` is populated. When `flow`\n * is absent we fall back to the legacy heuristic (`editingRule || editingVariants`)\n * so existing callers that don't yet pass `flow` keep their exact behavior.\n */\nexport const resolveIsEditMode = ({\n flow,\n editingRule,\n editingVariants,\n}: ResolveIsEditModeArgs): boolean => {\n if (flow) return flow === 'edit';\n return !!(editingRule || (editingVariants && editingVariants.length > 0));\n};\n"],"names":[],"mappings":";;;;AA+BO,MAAM,oBAAoB,CAAC;AAAA,EAChC,IAAA;AAAA,EACA,WAAA;AAAA,EACA,eAAA;AACF,CAAsC,KAAA;AACpC,EAAI,IAAA,IAAA,SAAa,IAAS,KAAA,MAAA,CAAA;AAC1B,EAAA,OAAO,CAAC,EAAE,WAAgB,IAAA,eAAA,IAAmB,gBAAgB,MAAS,GAAA,CAAA,CAAA,CAAA;AACxE;;;;"}
1
+ {"version":3,"file":"learningFlow.js","sources":["../../../../../src/features/LearningManagement/utils/learningFlow.ts"],"sourcesContent":["import { useDynamicFormStore } from '../../../schema-driven/store/useDynamicFormStore';\nimport { useLearningTemplateStore } from '../store/useLearningTemplateStore';\nimport { RuleDefinition, RuleVariant } from '../types';\n\n/**\n * Explicit source of truth for which Teach Me flow the modal is in.\n *\n * - `\"create\"` → Create/Add UI, ALWAYS, regardless of whether the RHS has\n * pre-populated variant data (e.g. a draft variant seeded into `editingVariants`).\n * - `\"edit\"` → Edit UI for an existing rule/variant.\n *\n * Decoupling the flow from the mere presence of `editingVariants` is what lets a\n * draft variant be populated into the RHS while the form still behaves as a new\n * learning. See RuleContent's `handleEditVariant` for where a draft click sets\n * `flow = \"create\"`.\n */\nexport type InstantLearningFlow = 'create' | 'edit';\n\nexport interface ResolveIsEditModeArgs {\n /** Explicit flow. When provided it is the sole source of truth. */\n flow?: InstantLearningFlow | null;\n editingRule?: RuleDefinition | null;\n editingVariants?: RuleVariant[] | null;\n}\n\n/**\n * Single source of truth for \"is the modal in edit mode?\".\n *\n * When an explicit `flow` is provided it wins outright — so `flow === \"create\"`\n * always means Create/Add even when `editingVariants` is populated. When `flow`\n * is absent we fall back to the legacy heuristic (`editingRule || editingVariants`)\n * so existing callers that don't yet pass `flow` keep their exact behavior.\n */\n\nexport const resolveIsEditMode = ({\n flow,\n editingRule,\n editingVariants,\n}: ResolveIsEditModeArgs): boolean => {\n if (flow) return flow === 'edit';\n return !!(editingRule || (editingVariants && editingVariants.length > 0));\n};\n\n\n/** Seed host-provided values into both the schema-driven RHS store and legacy\n * learningMetadata store. Form values can be keyed by data_key or schema\n * property name; variant fields land in the first create variant. */\nexport const seedHostFormValues = (schema: any, input: Record<string, any>) => {\n if (!input || Object.keys(input).length === 0) return;\n\n const globalValues: Record<string, any> = {};\n const variantValues: Record<string, Record<number, Record<string, any>>> = {};\n const learningMetadata: Record<string, any> = {\n ...(input.learningMetadata ?? input.learning_metadata ?? {}),\n };\n const metadataValues = learningMetadata.properties ?? learningMetadata;\n const hasValue = (source: Record<string, any>, key: string) =>\n Object.prototype.hasOwnProperty.call(source, key);\n const normalizeFieldKey = (key: string) => key.replace(/[^a-z0-9]/gi, '').toLowerCase();\n const unwrapValue = (value: any) =>\n value && typeof value === 'object' && !Array.isArray(value) && hasValue(value, 'value')\n ? value.value\n : value;\n\n const traverse = (properties: Record<string, any> = {}, inVariant = false) => {\n Object.entries(properties).forEach(([propertyKey, node]) => {\n const dataKey = node?.data_key;\n const cleanKey = typeof dataKey === 'string' ? dataKey.replace(/^global\\./, '') : propertyKey;\n const sources = [input, metadataValues];\n const aliases: Record<string, string[]> = {\n rule_title: ['title', 'ruleTitle'],\n rule_description: ['description', 'ruleDescription'],\n wta: ['whenToApply', 'when_to_apply'],\n wnta: ['whenNotToApply', 'when_not_to_apply'],\n instruction_prompt: ['instructionPrompt'],\n };\n const candidateKeys = [cleanKey, dataKey, propertyKey, ...(aliases[propertyKey] ?? [])]\n .filter(Boolean) as string[];\n let matchedKey: string | undefined;\n let matchedSource: Record<string, any> | undefined;\n for (const source of sources) {\n matchedKey = candidateKeys.find((key) => hasValue(source, key));\n if (!matchedKey) {\n const normalizedCandidates = new Set(candidateKeys.map(normalizeFieldKey));\n matchedKey = Object.keys(source).find((key) => normalizedCandidates.has(normalizeFieldKey(key)));\n }\n if (matchedKey) {\n matchedSource = source;\n break;\n }\n }\n\n if (matchedKey) {\n let value = unwrapValue(matchedSource![matchedKey]);\n // ConditionSectionField displays conditions by splitting an OR-delimited\n // string. Accept host arrays too, so common formValues arrays render.\n if (node?.bpa_ui_component === 'ConditionSection' && Array.isArray(value)) {\n value = value\n .map((item: any) => typeof item === 'string' ? item : item?.text)\n .filter((item: any) => typeof item === 'string' && item.trim())\n .join(' OR ');\n }\n const isVariantField = inVariant && !String(dataKey ?? '').startsWith('global.');\n if (isVariantField) {\n variantValues.tier_1 ??= {};\n variantValues.tier_1[0] ??= {};\n variantValues.tier_1[0][cleanKey] = value;\n } else {\n globalValues[cleanKey] = value;\n }\n\n if (node?.core_field === false) {\n learningMetadata[propertyKey] = value;\n }\n if (propertyKey === 'instruction_prompt' || cleanKey === 'instructionPrompt') {\n learningMetadata.instruction_prompt = value;\n }\n }\n\n if (node?.properties) {\n const isVariantWrapper =\n node?.is_repeatable_variant === true || node?.bpa_ui_component === 'VariantListWrapper';\n traverse(node.properties, inVariant || isVariantWrapper);\n }\n });\n };\n\n const schemaRoot = schema?.teachMe ?? schema;\n if (schemaRoot?.properties) {\n traverse(schemaRoot.properties);\n } else {\n Object.entries(input).forEach(([key, value]) => {\n if (key !== 'learningMetadata' && key !== 'learning_metadata') globalValues[key] = value;\n });\n }\n\n // Preserve metadata supplied in its API shape while also accepting flat\n // property values from formValues.\n const explicitMetadata = input.learningMetadata ?? input.learning_metadata;\n if (explicitMetadata && typeof explicitMetadata === 'object') {\n Object.assign(learningMetadata, explicitMetadata.properties ?? explicitMetadata);\n }\n if (hasValue(input, 'instructionPrompt')) {\n learningMetadata.instruction_prompt = input.instructionPrompt;\n }\n\n useDynamicFormStore.getState().initializeStore(globalValues, variantValues);\n if (Object.keys(learningMetadata).length > 0) {\n useLearningTemplateStore.getState().setLearningMetadata({\n ...useLearningTemplateStore.getState().learningMetadata,\n ...learningMetadata,\n });\n }\n};"],"names":["_a","_b","_c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ning] = React.useState(null);
84
84
  const [sizeWarning, setSizeWarning] = React.useState(null);
85
+ const [emptyFileWarning, setEmptyFileWarning] = React.useState(null);
85
86
  const [limitWarning, setLimitWarning] = React.useState(null);
87
+ const [deleteWarning, setDeleteWarning] = React.useState(null);
88
+ const [deletingFileIds, setDeletingFileIds] = React.useState(() => /* @__PURE__ */ new Set());
86
89
  const fileInputRef = React.useRef(null);
87
90
  const { getGlobalField, getVariantField, clearAllMirages, getGlobalMirage, getVariantMirage } = useDynamicFormStore.useDynamicFormStore();
88
91
  const dataKey = (schema == null ? void 0 : schema.data_key) || id;
@@ -262,7 +265,9 @@ function FileUploadField(props) {
262
265
  setDuplicateWarning(null);
263
266
  setFormatWarning(null);
264
267
  setSizeWarning(null);
268
+ setEmptyFileWarning(null);
265
269
  setLimitWarning(null);
270
+ setDeleteWarning(null);
266
271
  const remainingSlots = isFinite(effectiveMaxUploads) ? Math.max(0, effectiveMaxUploads - filesList.length) : Infinity;
267
272
  if (remainingSlots <= 0) {
268
273
  setLimitWarning(
@@ -286,8 +291,11 @@ function FileUploadField(props) {
286
291
  const validFiles = [];
287
292
  const invalidFiles = [];
288
293
  const oversizedFiles = [];
294
+ const emptyFiles = [];
289
295
  for (const file of filesToProcess) {
290
- if (!fileUploadService.isFileAccepted(file, normalizedAccept)) {
296
+ if (file.size === 0) {
297
+ emptyFiles.push(file);
298
+ } else if (!fileUploadService.isFileAccepted(file, normalizedAccept)) {
291
299
  invalidFiles.push(file);
292
300
  } else if (effectiveMaxFileSizeBytes !== null && file.size > effectiveMaxFileSizeBytes) {
293
301
  oversizedFiles.push(file);
@@ -305,14 +313,23 @@ function FileUploadField(props) {
305
313
  const message = oversizedFiles.length === 1 ? `File "${oversizedNames}" exceeds the ${maxFileSizeLabel} per-file size limit.` : `Files "${oversizedNames}" exceed the ${maxFileSizeLabel} per-file size limit.`;
306
314
  setSizeWarning(message);
307
315
  }
316
+ if (emptyFiles.length > 0) {
317
+ const emptyNames = emptyFiles.map((file) => file.name).join(", ");
318
+ const message = emptyFiles.length === 1 ? `File "${emptyNames}" is empty and cannot be uploaded.` : `Files "${emptyNames}" are empty and cannot be uploaded.`;
319
+ setEmptyFileWarning(message);
320
+ }
308
321
  if (validFiles.length === 0) {
309
322
  if (fileInputRef.current) {
310
323
  fileInputRef.current.value = "";
311
324
  }
312
325
  return;
313
326
  }
327
+ const uploadTimestamp = Date.now();
328
+ const filesForUpload = validFiles.map(
329
+ (file, index) => fileUploadService.createTimestampedFile(file, uploadTimestamp, index)
330
+ );
314
331
  setIsUploading(true);
315
- const optimisticItems = validFiles.map((file, i) => {
332
+ const optimisticItems = filesForUpload.map((file, i) => {
316
333
  const isImg = fileUploadService.isImageFile(file.name, file.type);
317
334
  let previewBlobUrl = void 0;
318
335
  try {
@@ -337,7 +354,7 @@ function FileUploadField(props) {
337
354
  try {
338
355
  const result = await fileUploadService.uploadFilesBatch({
339
356
  projectId: resolvedProjectId || "",
340
- files: validFiles,
357
+ files: filesForUpload,
341
358
  token: resolvedToken,
342
359
  artifactUserName: resolvedUserName,
343
360
  artifactUserEmail: resolvedUserEmail,
@@ -477,25 +494,66 @@ function FileUploadField(props) {
477
494
  if (!isEditing) return;
478
495
  (_a2 = fileInputRef.current) == null ? void 0 : _a2.click();
479
496
  };
480
- const handleRemoveFile = (targetId, e) => {
497
+ const handleDeleteFile = async (file, e) => {
481
498
  e.stopPropagation();
482
499
  if (!isEditing || !onChange) return;
500
+ if (deletingFileIds.has(file.id)) return;
483
501
  setDuplicateWarning(null);
484
502
  setFormatWarning(null);
485
503
  setSizeWarning(null);
504
+ setEmptyFileWarning(null);
486
505
  setLimitWarning(null);
506
+ setDeleteWarning(null);
487
507
  if (fileInputRef.current) {
488
508
  fileInputRef.current.value = "";
489
509
  }
490
- const nextList = filesList.filter((item) => item.id !== targetId);
491
- onChange(nextList);
510
+ if (!file.url) {
511
+ if (file.status === "error") {
512
+ onChange(filesList.filter((item) => item.id !== file.id));
513
+ return;
514
+ }
515
+ setDeleteWarning(`Cannot delete "${file.name}": its storage path is unavailable.`);
516
+ return;
517
+ }
518
+ setDeletingFileIds((currentIds) => new Set(currentIds).add(file.id));
519
+ try {
520
+ const result = await fileUploadService.deleteFileFromGCS({
521
+ projectId: resolvedProjectId || "",
522
+ fileUrl: file.url,
523
+ token: resolvedToken
524
+ });
525
+ if (result.error) {
526
+ setDeleteWarning(`Failed to delete "${file.name}": ${result.error.errorMessage}`);
527
+ return;
528
+ }
529
+ if (file.url) {
530
+ setSignedUrlMap((currentUrls) => {
531
+ const nextUrls = { ...currentUrls };
532
+ delete nextUrls[file.url];
533
+ return nextUrls;
534
+ });
535
+ }
536
+ onChange(filesList.filter((item) => item.id !== file.id));
537
+ } catch (error) {
538
+ setDeleteWarning(
539
+ `Failed to delete "${file.name}": ${(error == null ? void 0 : error.message) || "Unexpected error"}`
540
+ );
541
+ } finally {
542
+ setDeletingFileIds((currentIds) => {
543
+ const nextIds = new Set(currentIds);
544
+ nextIds.delete(file.id);
545
+ return nextIds;
546
+ });
547
+ }
492
548
  };
493
549
  const inlineSnapshotRef = React.useRef(null);
494
550
  const handleInlineStart = () => {
495
551
  setDuplicateWarning(null);
496
552
  setFormatWarning(null);
497
553
  setSizeWarning(null);
554
+ setEmptyFileWarning(null);
498
555
  setLimitWarning(null);
556
+ setDeleteWarning(null);
499
557
  inlineSnapshotRef.current = JSON.parse(JSON.stringify(filesList));
500
558
  setActiveEditId == null ? void 0 : setActiveEditId(id);
501
559
  };
@@ -507,7 +565,9 @@ function FileUploadField(props) {
507
565
  setDuplicateWarning(null);
508
566
  setFormatWarning(null);
509
567
  setSizeWarning(null);
568
+ setEmptyFileWarning(null);
510
569
  setLimitWarning(null);
570
+ setDeleteWarning(null);
511
571
  setActiveEditId == null ? void 0 : setActiveEditId(null);
512
572
  };
513
573
  const handleInlineDone = () => {
@@ -642,10 +702,10 @@ function FileUploadField(props) {
642
702
  onChange: handleNativeFileChange
643
703
  }
644
704
  ),
645
- (duplicateWarning || formatWarning || sizeWarning || limitWarning) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: FileUploadField_module["default"].warningBanner, role: "alert", children: [
705
+ (duplicateWarning || formatWarning || sizeWarning || emptyFileWarning || limitWarning || deleteWarning) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: FileUploadField_module["default"].warningBanner, role: "alert", children: [
646
706
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: FileUploadField_module["default"].warningContent, children: [
647
707
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircle, { size: 16, color: "#D97706", style: { flexShrink: 0 } }),
648
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: FileUploadField_module["default"].warningText, children: [duplicateWarning, formatWarning, sizeWarning, limitWarning].filter(Boolean).join(" ") })
708
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: FileUploadField_module["default"].warningText, children: [duplicateWarning, formatWarning, sizeWarning, emptyFileWarning, limitWarning, deleteWarning].filter(Boolean).join(" ") })
649
709
  ] }),
650
710
  /* @__PURE__ */ jsxRuntime.jsx(
651
711
  "button",
@@ -655,7 +715,9 @@ function FileUploadField(props) {
655
715
  setDuplicateWarning(null);
656
716
  setFormatWarning(null);
657
717
  setSizeWarning(null);
718
+ setEmptyFileWarning(null);
658
719
  setLimitWarning(null);
720
+ setDeleteWarning(null);
659
721
  },
660
722
  className: FileUploadField_module["default"].warningCloseBtn,
661
723
  title: "Dismiss notification",
@@ -710,6 +772,7 @@ function FileUploadField(props) {
710
772
  var _a2, _b2;
711
773
  const extension = fileUploadService.getFileExtension(file.name || file.filename);
712
774
  const isItemUploading = file.status === "uploading";
775
+ const isItemDeleting = deletingFileIds.has(file.id);
713
776
  const hasError = file.status === "error";
714
777
  const isImg = fileUploadService.isImageFile(file.name || file.filename, file.type);
715
778
  const fileGcsUrl = file.url || "";
@@ -778,15 +841,15 @@ function FileUploadField(props) {
778
841
  ] })
779
842
  ] })
780
843
  ] }),
781
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: FileUploadField_module["default"].fileActionsRight, children: isItemUploading ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { size: 18, className: FileUploadField_module["default"].loadingSpinner }) : isEditing ? /* @__PURE__ */ jsxRuntime.jsx(
844
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: FileUploadField_module["default"].fileActionsRight, children: isItemUploading || isItemDeleting ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { size: 18, className: FileUploadField_module["default"].loadingSpinner }) : isEditing ? /* @__PURE__ */ jsxRuntime.jsx(
782
845
  "button",
783
846
  {
784
847
  type: "button",
785
848
  className: FileUploadField_module["default"].removeButton,
786
- title: "Remove file",
787
- "aria-label": `Remove ${file.name}`,
788
- onClick: (e) => handleRemoveFile(file.id, e),
789
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 18 })
849
+ title: "Delete file",
850
+ "aria-label": `Delete ${file.name}`,
851
+ onClick: (e) => void handleDeleteFile(file, e),
852
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 18 })
790
853
  }
791
854
  ) : null })
792
855
  ]