@importcsv/react 0.1.12 → 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.
package/build/index.js CHANGED
@@ -30213,13 +30213,19 @@ var getStepConfig = function (skipHeader, useConsolidated) {
30213
30213
  { label: "Validation", id: Steps.Validation },
30214
30214
  ];
30215
30215
  };
30216
- function useStepNavigation(initialStep, skipHeader, useConsolidated) {
30216
+ function useStepNavigation(initialStep, skipHeader, useConsolidated, isDemoMode) {
30217
30217
  var _a;
30218
30218
  if (useConsolidated === void 0) { useConsolidated = true; }
30219
+ if (isDemoMode === void 0) { isDemoMode = false; }
30219
30220
  var t = useTranslation().t;
30220
30221
  var translatedSteps = getStepConfig(skipHeader, useConsolidated).map(function (step) { return (__assign$1(__assign$1({}, step), { label: t(step.label) })); });
30221
- var stepper = useStepper(translatedSteps, StepEnum.Upload, skipHeader);
30222
- var _b = useMutableLocalStorage("tf_steps", ""), storageStep = _b[0], setStorageStep = _b[1];
30222
+ // Map initial step to stepper index for consolidated flow
30223
+ var initialStepperIndex = useConsolidated && initialStep === StepEnum.MapColumns ? 1 :
30224
+ useConsolidated && initialStep === StepEnum.Validation ? 2 :
30225
+ useConsolidated && initialStep === StepEnum.Complete ? 3 : 0;
30226
+ var stepper = useStepper(translatedSteps, initialStepperIndex, skipHeader);
30227
+ // Don't use localStorage in demo mode
30228
+ var _b = useMutableLocalStorage("tf_steps", isDemoMode ? "" : ""), storageStep = _b[0], setStorageStep = _b[1];
30223
30229
  var _c = React.useState(initialStep), currentStep = _c[0], setCurrentStep = _c[1];
30224
30230
  var goBack = function (backStep) {
30225
30231
  var targetStep = backStep !== undefined ? backStep : Math.max(0, currentStep - 1);
@@ -30244,6 +30250,10 @@ function useStepNavigation(initialStep, skipHeader, useConsolidated) {
30244
30250
  stepper.setCurrent(stepperIndex);
30245
30251
  };
30246
30252
  React.useEffect(function () {
30253
+ // In demo mode, don't use localStorage
30254
+ if (isDemoMode) {
30255
+ return;
30256
+ }
30247
30257
  var step = storageStep || 0;
30248
30258
  // Map the step to the correct stepper index for consolidated flow
30249
30259
  var stepperIndex = useConsolidated ?
@@ -30254,9 +30264,9 @@ function useStepNavigation(initialStep, skipHeader, useConsolidated) {
30254
30264
  : step;
30255
30265
  stepper.setCurrent(stepperIndex);
30256
30266
  setCurrentStep(step);
30257
- }, [storageStep]);
30267
+ }, [storageStep, isDemoMode]);
30258
30268
  return {
30259
- currentStep: storageStep || currentStep,
30269
+ currentStep: isDemoMode ? currentStep : (storageStep || currentStep),
30260
30270
  setStep: setStep,
30261
30271
  goBack: goBack,
30262
30272
  goNext: goNext,
@@ -32201,11 +32211,11 @@ styleInject(css_248z$4);
32201
32211
 
32202
32212
  function ConfigureImport(_a) {
32203
32213
  var _this = this;
32204
- var template = _a.template, data = _a.data, onSuccess = _a.onSuccess, onCancel = _a.onCancel, _b = _a.isSubmitting, isSubmitting = _b === void 0 ? false : _b, importerKey = _a.importerKey, backendUrl = _a.backendUrl;
32214
+ var template = _a.template, data = _a.data, onSuccess = _a.onSuccess, onCancel = _a.onCancel, _b = _a.isSubmitting, isSubmitting = _b === void 0 ? false : _b, importerKey = _a.importerKey, backendUrl = _a.backendUrl, _c = _a.isDemoMode, isDemoMode = _c === void 0 ? false : _c;
32205
32215
  var t = useTranslation().t;
32206
32216
  var selectedHeaderRow = 0; // Always use first row as headers
32207
- var _c = React.useState({}), columnMapping = _c[0], setColumnMapping = _c[1];
32208
- var _d = React.useState(null), error = _d[0], setError = _d[1];
32217
+ var _d = React.useState({}), columnMapping = _d[0], setColumnMapping = _d[1];
32218
+ var _e = React.useState(null), error = _e[0], setError = _e[1];
32209
32219
  var llmEnhancementCalled = React.useRef(false);
32210
32220
  // Get preview data (first 5 rows)
32211
32221
  React.useMemo(function () {
@@ -32384,7 +32394,7 @@ function ConfigureImport(_a) {
32384
32394
  columnMapping[idx].key !== field.key;
32385
32395
  return (jsxRuntime.jsx(SelectItem, __assign$1({ value: idx.toString(), disabled: isAlreadyMapped }, { children: isAlreadyMapped ? (jsxRuntime.jsxs("span", __assign$1({ className: "text-gray-400" }, { children: [header, " (mapped)"] }))) : (header) }), idx));
32386
32396
  })] })] })) })), jsxRuntime.jsx("td", __assign$1({ className: "px-6 py-4" }, { children: jsxRuntime.jsx(Text, __assign$1({ className: "text-sm text-gray-600 truncate max-w-[300px]", title: mappedColumn ? getSampleData(parseInt(mappedColumn)) : '' }, { children: mappedColumn ? (getSampleData(parseInt(mappedColumn)) || '-') : '' })) }))] }), field.key));
32387
- }) })] })) })), error && (jsxRuntime.jsx(Box, __assign$1({ className: "bg-red-50 border border-red-200 rounded-lg px-4 py-3" }, { children: jsxRuntime.jsx(Text, __assign$1({ className: "text-sm text-red-700" }, { children: error })) }))), jsxRuntime.jsxs(Flex, __assign$1({ justify: "between", className: "w-full pt-6 border-t border-gray-200" }, { children: [jsxRuntime.jsx(Button, __assign$1({ variant: "outline", onClick: onCancel, disabled: isSubmitting, size: "default" }, { children: t('Back') })), jsxRuntime.jsx(Button, __assign$1({ onClick: handleSubmit, isLoading: isSubmitting, disabled: !allRequiredFieldsMapped, size: "default", variant: "default" }, { children: t('Continue') }))] }))] })) })));
32397
+ }) })] })) })), error && (jsxRuntime.jsx(Box, __assign$1({ className: "bg-red-50 border border-red-200 rounded-lg px-4 py-3" }, { children: jsxRuntime.jsx(Text, __assign$1({ className: "text-sm text-red-700" }, { children: error })) }))), jsxRuntime.jsxs(Flex, __assign$1({ justify: "between", className: "w-full pt-6 border-t border-gray-200" }, { children: [!isDemoMode && onCancel && (jsxRuntime.jsx(Button, __assign$1({ variant: "outline", onClick: onCancel, disabled: isSubmitting, size: "default" }, { children: t('Back') }))), isDemoMode && jsxRuntime.jsx("div", {}), jsxRuntime.jsx(Button, __assign$1({ onClick: handleSubmit, isLoading: isSubmitting, disabled: !allRequiredFieldsMapped, size: "default", variant: "default" }, { children: t('Continue') }))] }))] })) })));
32388
32398
  }
32389
32399
 
32390
32400
  /**
@@ -35799,14 +35809,18 @@ function IframeWrapper(_a) {
35799
35809
 
35800
35810
  function Main(props) {
35801
35811
  var _this = this;
35802
- var _a = props.isModal, isModal = _a === void 0 ? true : _a, _b = props.modalOnCloseTriggered, modalOnCloseTriggered = _b === void 0 ? function () { return null; } : _b, onComplete = props.onComplete, customStyles = props.customStyles, showDownloadTemplateButton = props.showDownloadTemplateButton, skipHeaderRowSelection = props.skipHeaderRowSelection, importerKey = props.importerKey, _c = props.backendUrl, backendUrl = _c === void 0 ? config.apiBaseUrl : _c, user = props.user, metadata = props.metadata, _d = props.useIframe, useIframe = _d === void 0 ? true : _d;
35812
+ var _a = props.isModal, isModal = _a === void 0 ? true : _a, _b = props.modalOnCloseTriggered, modalOnCloseTriggered = _b === void 0 ? function () { return null; } : _b, onComplete = props.onComplete, customStyles = props.customStyles, showDownloadTemplateButton = props.showDownloadTemplateButton, skipHeaderRowSelection = props.skipHeaderRowSelection, importerKey = props.importerKey, _c = props.backendUrl, backendUrl = _c === void 0 ? config.apiBaseUrl : _c, user = props.user, metadata = props.metadata, _d = props.useIframe, useIframe = _d === void 0 ? true : _d, // Default to using iframe for CSS isolation
35813
+ demoData = props.demoData;
35803
35814
  var skipHeader = skipHeaderRowSelection !== null && skipHeaderRowSelection !== void 0 ? skipHeaderRowSelection : false;
35815
+ var isDemoMode = !!demoData;
35804
35816
  var t = useTranslation().t;
35805
35817
  // Apply custom styles
35806
35818
  useCustomStyles(parseObjectOrStringJSON("customStyles", customStyles));
35807
35819
  // Stepper handler - using consolidated flow
35808
35820
  var useConsolidatedFlow = true; // Using consolidated flow to combine header selection and mapping
35809
- var _e = useStepNavigation(StepEnum.Upload, skipHeader, useConsolidatedFlow), currentStep = _e.currentStep, setStep = _e.setStep, goNext = _e.goNext, goBack = _e.goBack, stepper = _e.stepper;
35821
+ // Start at MapColumns step if demo mode is active
35822
+ var initialStep = isDemoMode ? StepEnum.MapColumns : StepEnum.Upload;
35823
+ var _e = useStepNavigation(initialStep, skipHeader, useConsolidatedFlow, isDemoMode), currentStep = _e.currentStep, setStep = _e.setStep, goNext = _e.goNext, goBack = _e.goBack, stepper = _e.stepper;
35810
35824
  // Error handling
35811
35825
  var _f = React.useState(null), initializationError = _f[0], setInitializationError = _f[1];
35812
35826
  var _g = React.useState(null), dataError = _g[0], setDataError = _g[1];
@@ -35831,6 +35845,29 @@ function Main(props) {
35831
35845
  var _p = React.useState(false), includeUnmatchedColumns = _p[0], setIncludeUnmatchedColumns = _p[1];
35832
35846
  var _q = React.useState(false), filterInvalidRows = _q[0], setFilterInvalidRows = _q[1];
35833
35847
  var _r = React.useState(false), disableOnInvalidRows = _r[0], setDisableOnInvalidRows = _r[1];
35848
+ // Initialize demo data if provided
35849
+ React.useEffect(function () {
35850
+ if (isDemoMode && demoData) {
35851
+ // Parse the demo CSV content
35852
+ papaparse_min.parse(demoData.csvContent, {
35853
+ complete: function (results) {
35854
+ var csvData = results.data;
35855
+ var isNotBlankRow = function (row) { return row.some(function (cell) { return cell.toString().trim() !== ""; }); };
35856
+ var rows = csvData.filter(isNotBlankRow).map(function (row, index) { return ({ index: index, values: row }); });
35857
+ setData({
35858
+ fileName: demoData.fileName,
35859
+ rows: rows,
35860
+ sheetList: [],
35861
+ errors: results.errors.map(function (error) { return error.message; }),
35862
+ });
35863
+ // Ensure we're on the correct step after data is loaded
35864
+ if (currentStep === StepEnum.Upload) {
35865
+ setStep(StepEnum.MapColumns);
35866
+ }
35867
+ },
35868
+ });
35869
+ }
35870
+ }, [isDemoMode, demoData]);
35834
35871
  // Fetch schema from the backend using importerKey
35835
35872
  React.useEffect(function () {
35836
35873
  var fetchSchema = function () { return __awaiter(_this, void 0, void 0, function () {
@@ -36133,7 +36170,7 @@ function Main(props) {
36133
36170
  setColumnMapping(mapping);
36134
36171
  setSelectedHeaderRow(headerRow);
36135
36172
  goNext();
36136
- }, onCancel: function () { return goBack(StepEnum.Upload); }, isSubmitting: isSubmitting, importerKey: importerKey, backendUrl: backendUrl }));
36173
+ }, onCancel: isDemoMode ? undefined : function () { return goBack(StepEnum.Upload); }, isSubmitting: isSubmitting, importerKey: importerKey, backendUrl: backendUrl, isDemoMode: isDemoMode }));
36137
36174
  }
36138
36175
  case StepEnum.Validation:
36139
36176
  return (jsxRuntime.jsx(Validation, { template: parsedTemplate, data: data, columnMapping: columnMapping, selectedHeaderRow: selectedHeaderRow, onSuccess: handleValidationComplete, onCancel: handleBackToMapColumns, isSubmitting: isSubmitting, backendUrl: backendUrl, importerKey: importerKey, filterInvalidRows: filterInvalidRows, disableOnInvalidRows: disableOnInvalidRows }));
@@ -37829,9 +37866,9 @@ styleInject(css_248z);
37829
37866
 
37830
37867
  var CSVImporter = React.forwardRef(function (importerProps, forwardRef) {
37831
37868
  // Destructure all known props from CSVImporterProps
37832
- var _a = importerProps.isModal, isModal = _a === void 0 ? true : _a, _b = importerProps.modalIsOpen, modalIsOpen = _b === void 0 ? true : _b, _c = importerProps.modalOnCloseTriggered, modalOnCloseTriggered = _c === void 0 ? function () { return null; } : _c, modalCloseOnOutsideClick = importerProps.modalCloseOnOutsideClick, _d = importerProps.darkMode, darkMode = _d === void 0 ? false : _d, _e = importerProps.primaryColor, primaryColor = _e === void 0 ? "#2563eb" : _e, className = importerProps.className, onComplete = importerProps.onComplete, customStyles = importerProps.customStyles, showDownloadTemplateButton = importerProps.showDownloadTemplateButton, skipHeaderRowSelection = importerProps.skipHeaderRowSelection, language = importerProps.language, customTranslations = importerProps.customTranslations, importerKey = importerProps.importerKey, backendUrl = importerProps.backendUrl, user = importerProps.user, metadata = importerProps.metadata,
37869
+ var _a = importerProps.isModal, isModal = _a === void 0 ? true : _a, _b = importerProps.modalIsOpen, modalIsOpen = _b === void 0 ? true : _b, _c = importerProps.modalOnCloseTriggered, modalOnCloseTriggered = _c === void 0 ? function () { return null; } : _c, modalCloseOnOutsideClick = importerProps.modalCloseOnOutsideClick, _d = importerProps.darkMode, darkMode = _d === void 0 ? false : _d, _e = importerProps.primaryColor, primaryColor = _e === void 0 ? "#2563eb" : _e, className = importerProps.className, onComplete = importerProps.onComplete, customStyles = importerProps.customStyles, showDownloadTemplateButton = importerProps.showDownloadTemplateButton, skipHeaderRowSelection = importerProps.skipHeaderRowSelection, language = importerProps.language, customTranslations = importerProps.customTranslations, importerKey = importerProps.importerKey, backendUrl = importerProps.backendUrl, user = importerProps.user, metadata = importerProps.metadata, demoData = importerProps.demoData,
37833
37870
  // Any remaining props will be valid DOM props
37834
- domProps = __rest$1(importerProps, ["isModal", "modalIsOpen", "modalOnCloseTriggered", "modalCloseOnOutsideClick", "darkMode", "primaryColor", "className", "onComplete", "customStyles", "showDownloadTemplateButton", "skipHeaderRowSelection", "language", "customTranslations", "importerKey", "backendUrl", "user", "metadata"]);
37871
+ domProps = __rest$1(importerProps, ["isModal", "modalIsOpen", "modalOnCloseTriggered", "modalCloseOnOutsideClick", "darkMode", "primaryColor", "className", "onComplete", "customStyles", "showDownloadTemplateButton", "skipHeaderRowSelection", "language", "customTranslations", "importerKey", "backendUrl", "user", "metadata", "demoData"]);
37835
37872
  var ref = forwardRef !== null && forwardRef !== void 0 ? forwardRef : React.useRef(null);
37836
37873
  var current = ref === null || ref === void 0 ? void 0 : ref.current;
37837
37874
  React.useEffect(function () {
@@ -37872,7 +37909,7 @@ var CSVImporter = React.forwardRef(function (importerProps, forwardRef) {
37872
37909
  // domProps should only contain valid DOM attributes
37873
37910
  var elementProps = __assign$1(__assign$1(__assign$1({ ref: ref }, (isModal ? { onClick: backdropClick } : {})), { className: domElementClass, "data-theme": darkMode ? "dark" : "light", style: { colorScheme: darkMode ? "dark" : "light" } }), domProps);
37874
37911
  // Create a new component that properly passes only the props that Importer needs
37875
- var ImporterComponent = function () { return (jsxRuntime.jsx(Providers, __assign$1({ primaryColor: primaryColor }, { children: jsxRuntime.jsx(Main, { isModal: isModal, modalIsOpen: modalIsOpen, modalOnCloseTriggered: modalOnCloseTriggered, modalCloseOnOutsideClick: modalCloseOnOutsideClick, darkMode: darkMode, primaryColor: primaryColor, className: className, onComplete: onComplete, customStyles: customStyles, showDownloadTemplateButton: showDownloadTemplateButton, skipHeaderRowSelection: skipHeaderRowSelection, language: language, customTranslations: customTranslations, importerKey: importerKey, backendUrl: backendUrl, user: user, metadata: metadata }) }))); };
37912
+ var ImporterComponent = function () { return (jsxRuntime.jsx(Providers, __assign$1({ primaryColor: primaryColor }, { children: jsxRuntime.jsx(Main, { isModal: isModal, modalIsOpen: modalIsOpen, modalOnCloseTriggered: modalOnCloseTriggered, modalCloseOnOutsideClick: modalCloseOnOutsideClick, darkMode: darkMode, primaryColor: primaryColor, className: className, onComplete: onComplete, customStyles: customStyles, showDownloadTemplateButton: showDownloadTemplateButton, skipHeaderRowSelection: skipHeaderRowSelection, language: language, customTranslations: customTranslations, importerKey: importerKey, backendUrl: backendUrl, user: user, metadata: metadata, demoData: demoData }) }))); };
37876
37913
  return isModal ? (jsxRuntime.jsx("div", __assign$1({ className: "csvImporter" }, { children: jsxRuntime.jsx("dialog", __assign$1({}, elementProps, { children: jsxRuntime.jsx(ImporterComponent, {}) })) }))) : (jsxRuntime.jsx("div", __assign$1({}, elementProps, { children: jsxRuntime.jsx(ImporterComponent, {}) })));
37877
37914
  });
37878
37915