@kelet-ai/feedback-ui 0.7.0 → 1.0.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.
@@ -356,7 +356,7 @@
356
356
  }
357
357
  var jsxRuntimeExports = requireJsxRuntime();
358
358
  const KeletContext = require$$0$1.createContext(null);
359
- const KeletBaseUrl = "https://api.kelet.ai/api";
359
+ const DefaultKeletBaseUrl = "https://api.kelet.ai/api";
360
360
  const useKelet = () => {
361
361
  const context = require$$0$1.useContext(KeletContext);
362
362
  if (!context) {
@@ -376,7 +376,7 @@
376
376
  return context.feedback;
377
377
  }
378
378
  };
379
- const KeletProvider = ({ apiKey, project, children }) => {
379
+ const KeletProvider = ({ apiKey, project, baseUrl, children }) => {
380
380
  const parentContext = require$$0$1.useContext(KeletContext);
381
381
  const resolvedApiKey = apiKey || parentContext?.api_key;
382
382
  if (!resolvedApiKey) {
@@ -385,7 +385,8 @@
385
385
  );
386
386
  }
387
387
  const feedback = async (data) => {
388
- const url = `${KeletBaseUrl}/projects/${project}/feedback`;
388
+ const resolvedBaseUrl = baseUrl || DefaultKeletBaseUrl;
389
+ const url = `${resolvedBaseUrl}/projects/${project}/feedback`;
389
390
  const req = {
390
391
  tx_id: data.tx_id,
391
392
  source: data.source || "EXPLICIT",
@@ -1867,7 +1868,7 @@
1867
1868
  }
1868
1869
  return result;
1869
1870
  }
1870
- function formatDiff(oldValue, newValue, diffType = "git", context = 3) {
1871
+ function formatDiff(oldValue, newValue, diffType = "git", context = 1) {
1871
1872
  switch (diffType) {
1872
1873
  case "git":
1873
1874
  return formatGitDiff(oldValue, newValue, context);
@@ -1879,7 +1880,7 @@
1879
1880
  return formatGitDiff(oldValue, newValue, context);
1880
1881
  }
1881
1882
  }
1882
- function formatGitDiff(oldValue, newValue, context = 3) {
1883
+ function formatGitDiff(oldValue, newValue, context = 1) {
1883
1884
  const oldStr = stringify(oldValue);
1884
1885
  const newStr = stringify(newValue);
1885
1886
  const patch = createTwoFilesPatch(
@@ -1895,7 +1896,20 @@
1895
1896
  "",
1896
1897
  { context }
1897
1898
  );
1898
- return patch.split("\n").slice(2).join("\n");
1899
+ const lines = patch.split("\n");
1900
+ const filtered = lines.filter((line) => {
1901
+ if (!line) return false;
1902
+ if (line === "\") return false;
1903
+ if (line.startsWith("@@")) return false;
1904
+ if (line.startsWith("---") || line.startsWith("+++")) return false;
1905
+ if (line.startsWith(" ")) return false;
1906
+ if (line.startsWith("+") || line.startsWith("-")) return true;
1907
+ return false;
1908
+ });
1909
+ while (filtered.length && filtered[0].trim() === "") filtered.shift();
1910
+ while (filtered.length && filtered[filtered.length - 1].trim() === "")
1911
+ filtered.pop();
1912
+ return filtered.join("\n");
1899
1913
  }
1900
1914
  function formatObjectDiff(oldValue, newValue) {
1901
1915
  const differences = deepDiffExports.diff(oldValue, newValue) || [];
@@ -2008,19 +2022,22 @@
2008
2022
  function useStateChangeTracking(currentState, tx_id, options) {
2009
2023
  const defaultFeedbackHandler = useDefaultFeedbackHandler();
2010
2024
  const feedbackHandler = options?.onFeedback || defaultFeedbackHandler;
2011
- const debounceMs = options?.debounceMs ?? 1500;
2025
+ const debounceMs = options?.debounceMs ?? 3e3;
2012
2026
  const diffType = options?.diffType ?? "git";
2013
2027
  const compareWith = options?.compareWith;
2014
2028
  const defaultTriggerName = options?.default_trigger_name ?? "auto_state_change";
2015
2029
  const ignoreInitialNullish = options?.ignoreInitialNullish ?? true;
2016
2030
  const prevStateRef = require$$0$1.useRef(currentState);
2017
- const changeStartStateRef = require$$0$1.useRef(currentState);
2018
2031
  const isFirstRenderRef = require$$0$1.useRef(true);
2019
2032
  const initialStateRef = require$$0$1.useRef(currentState);
2033
+ const initialWasNullishRef = require$$0$1.useRef(currentState == null);
2020
2034
  const hasHadNonNullishStateRef = require$$0$1.useRef(
2021
2035
  currentState != null
2022
2036
  // != null catches both null and undefined
2023
2037
  );
2038
+ const hasEligibleBaselineRef = require$$0$1.useRef(
2039
+ !(ignoreInitialNullish && currentState == null)
2040
+ );
2024
2041
  const timeoutRef = require$$0$1.useRef(null);
2025
2042
  const currentTriggerNameRef = require$$0$1.useRef(void 0);
2026
2043
  const sendFeedback = require$$0$1.useCallback(
@@ -2055,7 +2072,7 @@
2055
2072
  const newTriggerName = trigger_name || defaultTriggerName;
2056
2073
  if (timeoutRef.current && currentTriggerNameRef.current && currentTriggerNameRef.current !== newTriggerName) {
2057
2074
  clearTimeout(timeoutRef.current);
2058
- const startState = changeStartStateRef.current;
2075
+ const startState = initialStateRef.current;
2059
2076
  const currentStateBeforeChange = currentState;
2060
2077
  sendFeedback(
2061
2078
  startState,
@@ -2072,39 +2089,41 @@
2072
2089
  if (isFirstRenderRef.current) {
2073
2090
  isFirstRenderRef.current = false;
2074
2091
  prevStateRef.current = currentState;
2075
- changeStartStateRef.current = currentState;
2092
+ if (!ignoreInitialNullish || currentState != null) {
2093
+ initialStateRef.current = currentState;
2094
+ hasEligibleBaselineRef.current = true;
2095
+ }
2076
2096
  return;
2077
2097
  }
2078
2098
  const prevState = prevStateRef.current;
2079
2099
  const isEqual = compareWith ? compareWith(prevState, currentState) : JSON.stringify(prevState) === JSON.stringify(currentState);
2080
2100
  if (!isEqual) {
2081
- const shouldIgnoreChange = ignoreInitialNullish && initialStateRef.current == null && // Initial state was nullish
2101
+ const shouldIgnoreChange = ignoreInitialNullish && initialWasNullishRef.current && // True initial state was nullish
2082
2102
  !hasHadNonNullishStateRef.current && // We haven't had non-nullish state before
2083
2103
  currentState != null;
2084
2104
  if (currentState != null) {
2085
2105
  hasHadNonNullishStateRef.current = true;
2086
2106
  }
2087
2107
  if (shouldIgnoreChange) {
2108
+ initialStateRef.current = currentState;
2109
+ hasEligibleBaselineRef.current = true;
2088
2110
  prevStateRef.current = currentState;
2089
- changeStartStateRef.current = currentState;
2090
2111
  return;
2091
2112
  }
2092
- if (!timeoutRef.current) {
2093
- changeStartStateRef.current = prevState;
2094
- }
2095
2113
  if (timeoutRef.current) {
2096
2114
  clearTimeout(timeoutRef.current);
2097
2115
  }
2098
2116
  prevStateRef.current = currentState;
2099
2117
  timeoutRef.current = setTimeout(() => {
2100
- const startState = changeStartStateRef.current;
2118
+ const startState = initialStateRef.current;
2101
2119
  const finalState = currentState;
2102
- sendFeedback(
2103
- startState,
2104
- finalState,
2105
- currentTriggerNameRef.current || defaultTriggerName
2106
- );
2107
- changeStartStateRef.current = finalState;
2120
+ if (hasEligibleBaselineRef.current) {
2121
+ sendFeedback(
2122
+ startState,
2123
+ finalState,
2124
+ currentTriggerNameRef.current || defaultTriggerName
2125
+ );
2126
+ }
2108
2127
  timeoutRef.current = null;
2109
2128
  }, debounceMs);
2110
2129
  }