@streamoid/catalogix-chat 0.2.22 → 0.2.23

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 (2) hide show
  1. package/dist/index.js +142 -39
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/CatalogixChat.tsx
2
- import { useEffect as useEffect8 } from "react";
2
+ import { useEffect as useEffect9 } from "react";
3
3
 
4
4
  // src/api.ts
5
5
  var _config = {
@@ -3078,12 +3078,13 @@ function MapAttributesChat({
3078
3078
  }
3079
3079
 
3080
3080
  // src/EditFeed/index.tsx
3081
- import React8, { useState as useState8, useMemo as useMemo6, useCallback as useCallback6 } from "react";
3081
+ import React8, { useState as useState8, useMemo as useMemo6, useCallback as useCallback6, useRef as useRef5, useEffect as useEffect6 } from "react";
3082
3082
  import {
3083
3083
  AlertTriangle as AlertTriangle2,
3084
3084
  Check as Check3,
3085
3085
  ChevronDown as ChevronDown3,
3086
3086
  ChevronRight as ChevronRight3,
3087
+ HelpCircle,
3087
3088
  Pencil as Pencil3,
3088
3089
  Send as Send2,
3089
3090
  Loader2 as Loader26,
@@ -3152,19 +3153,101 @@ async function mergeFeed(fileUrl, feedFormat, changes) {
3152
3153
  }
3153
3154
  );
3154
3155
  }
3156
+ async function fetchValidValues(sourceMp, marketplaceOv, category, attribute) {
3157
+ const { catalogixBaseUrl } = getApiConfig();
3158
+ const params = new URLSearchParams({
3159
+ response_style: "light",
3160
+ category,
3161
+ attribute
3162
+ });
3163
+ const url = `${catalogixBaseUrl}/marketplaces/${sourceMp}/versions/${marketplaceOv}/structure?${params}`;
3164
+ const resp = await fetchJson(url);
3165
+ return resp[attribute] ?? Object.values(resp)[0] ?? [];
3166
+ }
3155
3167
  function EditableCell2({
3156
3168
  value,
3157
3169
  hasError,
3158
3170
  errorMessage,
3159
3171
  onChange,
3160
- readOnly
3172
+ readOnly,
3173
+ onFetchSuggestions
3161
3174
  }) {
3162
3175
  const [editing, setEditing] = useState8(false);
3163
3176
  const [draft, setDraft] = useState8(value);
3177
+ const [showSuggestions, setShowSuggestions] = useState8(false);
3178
+ const [suggestions, setSuggestions] = useState8(null);
3179
+ const [loadingSuggestions, setLoadingSuggestions] = useState8(false);
3180
+ const suggestionsRef = useRef5(null);
3181
+ useEffect6(() => {
3182
+ if (!showSuggestions) return;
3183
+ const handler = (e) => {
3184
+ if (suggestionsRef.current && !suggestionsRef.current.contains(e.target)) {
3185
+ setShowSuggestions(false);
3186
+ }
3187
+ };
3188
+ document.addEventListener("mousedown", handler);
3189
+ return () => document.removeEventListener("mousedown", handler);
3190
+ }, [showSuggestions]);
3191
+ const handleToggleSuggestions = useCallback6(
3192
+ async (e) => {
3193
+ e.stopPropagation();
3194
+ if (showSuggestions) {
3195
+ setShowSuggestions(false);
3196
+ return;
3197
+ }
3198
+ setShowSuggestions(true);
3199
+ if (suggestions !== null || !onFetchSuggestions) return;
3200
+ setLoadingSuggestions(true);
3201
+ try {
3202
+ const vals = await onFetchSuggestions();
3203
+ setSuggestions(vals);
3204
+ } catch {
3205
+ setSuggestions([]);
3206
+ } finally {
3207
+ setLoadingSuggestions(false);
3208
+ }
3209
+ },
3210
+ [showSuggestions, suggestions, onFetchSuggestions]
3211
+ );
3212
+ const selectSuggestion = useCallback6(
3213
+ (val) => {
3214
+ onChange(val);
3215
+ setDraft(val);
3216
+ setShowSuggestions(false);
3217
+ },
3218
+ [onChange]
3219
+ );
3164
3220
  const commit = useCallback6(() => {
3165
3221
  setEditing(false);
3166
3222
  if (draft !== value) onChange(draft);
3167
3223
  }, [draft, value, onChange]);
3224
+ const suggestionsPanel = showSuggestions && hasError && onFetchSuggestions ? /* @__PURE__ */ jsx22(
3225
+ "div",
3226
+ {
3227
+ ref: suggestionsRef,
3228
+ className: "absolute left-0 top-full z-20 mt-1 rounded border bg-popover p-1.5 shadow-md max-w-[280px]",
3229
+ children: loadingSuggestions ? /* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-1.5 text-[10px] text-muted-foreground px-1 py-0.5", children: [
3230
+ /* @__PURE__ */ jsx22(Loader26, { className: "h-3 w-3 animate-spin" }),
3231
+ "Loading valid values\u2026"
3232
+ ] }) : suggestions && suggestions.length > 0 ? /* @__PURE__ */ jsx22("div", { className: "flex flex-wrap gap-1 max-h-[120px] overflow-auto", children: suggestions.map((s) => /* @__PURE__ */ jsx22(
3233
+ "button",
3234
+ {
3235
+ type: "button",
3236
+ onClick: (e) => {
3237
+ e.stopPropagation();
3238
+ selectSuggestion(s);
3239
+ },
3240
+ className: cn(
3241
+ "inline-flex items-center rounded-md border px-1.5 py-0.5 text-[10px] font-medium transition-colors",
3242
+ "hover:bg-primary hover:text-primary-foreground cursor-pointer",
3243
+ "border-border bg-muted/40 text-foreground"
3244
+ ),
3245
+ children: s
3246
+ },
3247
+ s
3248
+ )) }) : /* @__PURE__ */ jsx22("p", { className: "text-[10px] text-muted-foreground px-1 py-0.5", children: "No valid values found." })
3249
+ }
3250
+ ) : null;
3168
3251
  if (readOnly) {
3169
3252
  return /* @__PURE__ */ jsxs11(
3170
3253
  "div",
@@ -3182,26 +3265,29 @@ function EditableCell2({
3182
3265
  );
3183
3266
  }
3184
3267
  if (editing) {
3185
- return /* @__PURE__ */ jsx22(
3186
- Input,
3187
- {
3188
- autoFocus: true,
3189
- value: draft,
3190
- onChange: (e) => setDraft(e.target.value),
3191
- onBlur: commit,
3192
- onKeyDown: (e) => {
3193
- if (e.key === "Enter") commit();
3194
- if (e.key === "Escape") {
3195
- setDraft(value);
3196
- setEditing(false);
3197
- }
3198
- },
3199
- className: cn(
3200
- "h-7 text-sm rounded px-1.5",
3201
- hasError && "border-destructive focus-visible:ring-destructive/30"
3202
- )
3203
- }
3204
- );
3268
+ return /* @__PURE__ */ jsxs11("div", { className: "relative", children: [
3269
+ /* @__PURE__ */ jsx22(
3270
+ Input,
3271
+ {
3272
+ autoFocus: true,
3273
+ value: draft,
3274
+ onChange: (e) => setDraft(e.target.value),
3275
+ onBlur: commit,
3276
+ onKeyDown: (e) => {
3277
+ if (e.key === "Enter") commit();
3278
+ if (e.key === "Escape") {
3279
+ setDraft(value);
3280
+ setEditing(false);
3281
+ }
3282
+ },
3283
+ className: cn(
3284
+ "h-7 text-sm rounded px-1.5",
3285
+ hasError && "border-destructive focus-visible:ring-destructive/30"
3286
+ )
3287
+ }
3288
+ ),
3289
+ suggestionsPanel
3290
+ ] });
3205
3291
  }
3206
3292
  return /* @__PURE__ */ jsxs11(
3207
3293
  "div",
@@ -3218,7 +3304,18 @@ function EditableCell2({
3218
3304
  children: [
3219
3305
  /* @__PURE__ */ jsx22("span", { className: "truncate max-w-[160px]", children: value }),
3220
3306
  /* @__PURE__ */ jsx22(Pencil3, { className: "h-3 w-3 shrink-0 opacity-0 group-hover:opacity-70 transition-opacity" }),
3221
- hasError && errorMessage && /* @__PURE__ */ jsx22("div", { className: "absolute left-0 top-full z-10 mt-1 hidden group-hover:block", children: /* @__PURE__ */ jsx22("div", { className: "rounded bg-destructive px-2 py-1 text-[10px] text-destructive-foreground shadow-md max-w-[260px] whitespace-normal", children: errorMessage }) })
3307
+ hasError && onFetchSuggestions && /* @__PURE__ */ jsx22(
3308
+ "button",
3309
+ {
3310
+ type: "button",
3311
+ onClick: handleToggleSuggestions,
3312
+ className: "shrink-0 rounded p-0.5 hover:bg-destructive/20 transition-colors",
3313
+ title: "Show valid values",
3314
+ children: /* @__PURE__ */ jsx22(HelpCircle, { className: "h-3 w-3" })
3315
+ }
3316
+ ),
3317
+ hasError && errorMessage && !showSuggestions && /* @__PURE__ */ jsx22("div", { className: "absolute left-0 top-full z-10 mt-1 hidden group-hover:block", children: /* @__PURE__ */ jsx22("div", { className: "rounded bg-destructive px-2 py-1 text-[10px] text-destructive-foreground shadow-md max-w-[260px] whitespace-normal", children: errorMessage }) }),
3318
+ suggestionsPanel
3222
3319
  ]
3223
3320
  }
3224
3321
  );
@@ -3474,7 +3571,13 @@ function EditFeed({
3474
3571
  hasError: !!cellErr,
3475
3572
  errorMessage: cellErr,
3476
3573
  onChange: (val) => handleCellChange(rowIdx, col, val),
3477
- readOnly: isLoading
3574
+ readOnly: isLoading,
3575
+ onFetchSuggestions: cellErr ? () => fetchValidValues(
3576
+ sourceMp,
3577
+ marketplaceOv,
3578
+ row["Category"] ?? "",
3579
+ col
3580
+ ) : void 0
3478
3581
  }
3479
3582
  ) }, col);
3480
3583
  })
@@ -3525,7 +3628,7 @@ function EditFeed({
3525
3628
  }
3526
3629
 
3527
3630
  // src/Automations/ProductAutomation.tsx
3528
- import { useState as useState10, useEffect as useEffect6, useCallback as useCallback8, useRef as useRef5 } from "react";
3631
+ import { useState as useState10, useEffect as useEffect7, useCallback as useCallback8, useRef as useRef6 } from "react";
3529
3632
  import { ArrowLeft as ArrowLeft3, Search as Search4, Loader2 as Loader28, ChevronDown as ChevronDown4, Play } from "lucide-react";
3530
3633
 
3531
3634
  // src/Automations/api.ts
@@ -4014,14 +4117,14 @@ function ProductAutomation({
4014
4117
  const [loadingOptions, setLoadingOptions] = useState10({});
4015
4118
  const [schemaLoading, setSchemaLoading] = useState10(false);
4016
4119
  const [applying, setApplying] = useState10(false);
4017
- const configsRef = useRef5(configs);
4120
+ const configsRef = useRef6(configs);
4018
4121
  configsRef.current = configs;
4019
- const optionsRef = useRef5(options);
4122
+ const optionsRef = useRef6(options);
4020
4123
  optionsRef.current = options;
4021
- const loadingOptionsRef = useRef5(loadingOptions);
4124
+ const loadingOptionsRef = useRef6(loadingOptions);
4022
4125
  loadingOptionsRef.current = loadingOptions;
4023
4126
  const productsCount = selectedProducts.includes("all") ? excludedProducts.length === 0 ? totalProducts : totalProducts - excludedProducts.length : productsCountProp;
4024
- useEffect6(() => {
4127
+ useEffect7(() => {
4025
4128
  setLoading(true);
4026
4129
  fetchAutomationList(storeId, "product", true).then((data) => {
4027
4130
  const groups = {};
@@ -4037,7 +4140,7 @@ function ProductAutomation({
4037
4140
  if (sorted.length > 0) setExpandedGroups([sorted[0]]);
4038
4141
  }).catch(console.error).finally(() => setLoading(false));
4039
4142
  }, [storeId]);
4040
- useEffect6(() => {
4143
+ useEffect7(() => {
4041
4144
  if (!selected) {
4042
4145
  setSchema([]);
4043
4146
  setConfigs({});
@@ -4056,7 +4159,7 @@ function ProductAutomation({
4056
4159
  configsRef.current = defaults;
4057
4160
  }).catch(console.error).finally(() => setSchemaLoading(false));
4058
4161
  }, [selected, storeId]);
4059
- useEffect6(() => {
4162
+ useEffect7(() => {
4060
4163
  if (schema.length === 0) return;
4061
4164
  const flatItems = schema.flatMap((s) => s.mapping_parameters ?? [s]);
4062
4165
  for (const item of flatItems) {
@@ -4312,7 +4415,7 @@ function formatTimeSaved(totalSeconds) {
4312
4415
  }
4313
4416
 
4314
4417
  // src/Automations/StoreAutomation.tsx
4315
- import { useState as useState11, useEffect as useEffect7, useCallback as useCallback9, useRef as useRef6 } from "react";
4418
+ import { useState as useState11, useEffect as useEffect8, useCallback as useCallback9, useRef as useRef7 } from "react";
4316
4419
  import { ArrowLeft as ArrowLeft4, Settings } from "lucide-react";
4317
4420
  import { Fragment as Fragment6, jsx as jsx25, jsxs as jsxs14 } from "react/jsx-runtime";
4318
4421
  function StoreAutomation({
@@ -4326,7 +4429,7 @@ function StoreAutomation({
4326
4429
  const [automations, setAutomations] = useState11([]);
4327
4430
  const [selectedConfigs, setSelectedConfigs] = useState11({ ...enabledAutomations });
4328
4431
  const [selectedAutomation, setSelectedAutomation] = useState11(null);
4329
- useEffect7(() => {
4432
+ useEffect8(() => {
4330
4433
  setLoading(true);
4331
4434
  fetchAutomationList(storeId, "default").then((data) => {
4332
4435
  setAutomations(
@@ -4461,11 +4564,11 @@ function AutomationConfigEditor({
4461
4564
  );
4462
4565
  const [options, setOptions] = useState11({});
4463
4566
  const [loadingOptions, setLoadingOptions] = useState11({});
4464
- const configsRef = useRef6(configs);
4567
+ const configsRef = useRef7(configs);
4465
4568
  configsRef.current = configs;
4466
- const optionsRef = useRef6(options);
4569
+ const optionsRef = useRef7(options);
4467
4570
  optionsRef.current = options;
4468
- useEffect7(() => {
4571
+ useEffect8(() => {
4469
4572
  if (!automation.isEnabled) return;
4470
4573
  setSchemaLoading(true);
4471
4574
  fetchAutomationSchema(storeId, automation.automation, "default").then((items) => {
@@ -4480,7 +4583,7 @@ function AutomationConfigEditor({
4480
4583
  }
4481
4584
  }).catch(console.error).finally(() => setSchemaLoading(false));
4482
4585
  }, [storeId, automation, initialConfigs]);
4483
- useEffect7(() => {
4586
+ useEffect8(() => {
4484
4587
  if (schema.length === 0) return;
4485
4588
  for (const item of schema) {
4486
4589
  if (!item.curl) continue;
@@ -4611,7 +4714,7 @@ function CatalogixChat(props) {
4611
4714
  const filters = uiProps.filters ?? {};
4612
4715
  const selectedPageRange = uiProps.selectedPageRange ?? [];
4613
4716
  const enabledAutomations = uiProps.enabledAutomations ?? {};
4614
- useEffect8(() => {
4717
+ useEffect9(() => {
4615
4718
  configureApi({ catalogixBaseUrl });
4616
4719
  }, [catalogixBaseUrl]);
4617
4720
  if (section === "select_products") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamoid/catalogix-chat",
3
- "version": "0.2.22",
3
+ "version": "0.2.23",
4
4
  "description": "Catalogix chat components for the Streamoid chat host — store creation, product selection, automations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",