@inkeep/cxkit-primitives 0.5.16 → 0.5.18
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),J=require("../../providers/config-provider.cjs"),V=require("../../hooks/use-media-query.cjs"),X=require("./search-query.graphql.cjs"),Y=require("./transform-results.cjs"),Z=require("../../providers/search-events-provider.cjs"),ee=require("../../hooks/use-instant-update.cjs"),te=require("../../utils/graphql-client.cjs"),se=()=>{const{baseSettings:L,searchSettings:N}=J.useInkeepConfig(),{apiKey:S,aiApiBaseUrl:O,userAuthToken:l}=L,{maxResults:R,placeholder:Q,defaultQuery:x,debounceTimeMs:q,onQueryChange:B,searchFunctionsRef:F,tabs:i}=N,{logEvent:C}=Z.useSearchEvents(),[c,T]=t.useState(x),k=t.useRef(null),[v,E]=t.useState(!1),[H,h]=t.useState(null),[$,a]=t.useState("NONE"),z=t.useCallback(e=>{a(e)},[]),[d,f]=t.useState([]),s=Y.useTransformResults(d,c),M=typeof i?.[0]=="string"?i[0]:i[0][0],[y,w]=t.useState(M),{disableTransition:I,disabled:D}=ee.useInstantUpdate(),K=t.useCallback(e=>{I(),w(e);const r=s[e][0].id;a(r)},[s,I]);t.useEffect(()=>{let e=y in s?y:Object.keys(s)[0];if(!s[e]?.length){const n=Object.keys(s).find(u=>s[u]?.length);n?e=n:e=M}if(!e)return;w(e);const r=s[e]?.[0];r&&a(r.id)},[s]);const b=V.useMediaQuery("(max-width: 768px)"),o=t.useRef({}),m=t.useRef(null),g=t.useRef(null);t.useImperativeHandle(F,()=>({updateQuery(e){T(e)},focusInput:()=>{k.current?.focus()}}));const A=`${O}/graphql`,P=t.useMemo(()=>({Authorization:`Bearer ${S}`,"Content-Type":"application/json",...l?{"User-Token":l}:{}}),[S,l]),U=t.useCallback(async e=>{m.current&&m.current.abort();const r=new AbortController;m.current=r;try{E(!0),h(null);const u=(await te.graphqlRequest(A,X.default,{searchInput:e},P))?.search.searchHits;o.current[e.searchQuery]=u,f(u)}catch(n){if(n.name==="AbortError")return;h("Failed to fetch search results. Please try again.")}E(!1)},[A,P]),_=t.useCallback(e=>{const r=o.current[e.searchQuery];C({eventName:"search_query_response_received",properties:{searchQuery:e.searchQuery,totalResults:r?.length}})},[]),j=t.useCallback(e=>{if(g.current&&window.clearTimeout(g.current),!e.searchQuery){f([]),h(null);return}g.current=window.setTimeout(()=>{C({eventName:"search_query_submitted",properties:{searchQuery:e.searchQuery}}),o.current[e.searchQuery]?(f(o.current[e.searchQuery]),_(e)):U(e).then(()=>{_(e)})},q)},[q,U]),p=t.useMemo(()=>({searchQuery:c,filters:{limit:R}}),[c,R]);t.useEffect(()=>{B?.(p.searchQuery),j(p)},[j,p]);const W=t.useCallback(e=>T(e.target.value),[]),G=t.useMemo(()=>Q||(b?"Search...":"Search for anything..."),[Q,b]);return{results:s,resultsList:d,hasContent:d.length>0||v,loading:v,error:H,query:c,onInput:W,placeholder:G,tab:y,onTabChange:K,selectedItem:$,setSelectedItem:a,onSelectedItemChange:z,transitionsDisabled:D,inputRef:k,isMobile:b}};exports.useInkeepSearch=se;
|
|
@@ -1,139 +1,140 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useState as s, useRef as l, useCallback as n, useEffect as
|
|
3
|
-
import { useInkeepConfig as
|
|
4
|
-
import { useMediaQuery as
|
|
5
|
-
import
|
|
6
|
-
import { useTransformResults as
|
|
7
|
-
import { useSearchEvents as
|
|
8
|
-
import { useInstantUpdate as
|
|
9
|
-
import { graphqlRequest as
|
|
10
|
-
const
|
|
11
|
-
const { baseSettings:
|
|
12
|
-
maxResults:
|
|
13
|
-
placeholder:
|
|
14
|
-
defaultQuery:
|
|
15
|
-
debounceTimeMs:
|
|
16
|
-
onQueryChange:
|
|
17
|
-
searchFunctionsRef:
|
|
18
|
-
|
|
2
|
+
import { useState as s, useRef as l, useCallback as n, useEffect as B, useImperativeHandle as Z, useMemo as T } from "react";
|
|
3
|
+
import { useInkeepConfig as ee } from "../../providers/config-provider.js";
|
|
4
|
+
import { useMediaQuery as te } from "../../hooks/use-media-query.js";
|
|
5
|
+
import re from "./search-query.graphql.js";
|
|
6
|
+
import { useTransformResults as se } from "./transform-results.js";
|
|
7
|
+
import { useSearchEvents as ne } from "../../providers/search-events-provider.js";
|
|
8
|
+
import { useInstantUpdate as oe } from "../../hooks/use-instant-update.js";
|
|
9
|
+
import { graphqlRequest as ce } from "../../utils/graphql-client.js";
|
|
10
|
+
const pe = () => {
|
|
11
|
+
const { baseSettings: F, searchSettings: H } = ee(), { apiKey: S, aiApiBaseUrl: P, userAuthToken: h } = F, {
|
|
12
|
+
maxResults: C,
|
|
13
|
+
placeholder: v,
|
|
14
|
+
defaultQuery: $,
|
|
15
|
+
debounceTimeMs: k,
|
|
16
|
+
onQueryChange: z,
|
|
17
|
+
searchFunctionsRef: D,
|
|
18
|
+
tabs: f
|
|
19
|
+
} = H, { logEvent: w } = ne(), [c, q] = s($), E = l(null), [A, I] = s(!1), [K, m] = s(null), [W, a] = s("NONE"), G = n((e) => {
|
|
19
20
|
a(e);
|
|
20
|
-
}, []), [
|
|
21
|
+
}, []), [d, p] = s([]), t = se(d, c), _ = typeof f?.[0] == "string" ? f[0] : f[0][0], [y, x] = s(_), { disableTransition: L, disabled: J } = oe(), V = n(
|
|
21
22
|
(e) => {
|
|
22
|
-
|
|
23
|
+
L(), x(e);
|
|
23
24
|
const r = t[e][0].id;
|
|
24
25
|
a(r);
|
|
25
26
|
},
|
|
26
|
-
[t,
|
|
27
|
+
[t, L]
|
|
27
28
|
);
|
|
28
|
-
|
|
29
|
-
let e =
|
|
29
|
+
B(() => {
|
|
30
|
+
let e = y in t ? y : Object.keys(t)[0];
|
|
30
31
|
if (!t[e]?.length) {
|
|
31
32
|
const o = Object.keys(t).find((i) => t[i]?.length);
|
|
32
|
-
o ? e = o : e =
|
|
33
|
+
o ? e = o : e = _;
|
|
33
34
|
}
|
|
34
35
|
if (!e) return;
|
|
35
|
-
|
|
36
|
+
x(e);
|
|
36
37
|
const r = t[e]?.[0];
|
|
37
38
|
r && a(r.id);
|
|
38
39
|
}, [t]);
|
|
39
|
-
const
|
|
40
|
-
|
|
40
|
+
const b = te("(max-width: 768px)"), u = l({}), g = l(null), Q = l(null);
|
|
41
|
+
Z(D, () => ({
|
|
41
42
|
updateQuery(e) {
|
|
42
|
-
|
|
43
|
+
q(e);
|
|
43
44
|
},
|
|
44
45
|
focusInput: () => {
|
|
45
|
-
|
|
46
|
+
E.current?.focus();
|
|
46
47
|
}
|
|
47
48
|
}));
|
|
48
|
-
const
|
|
49
|
+
const M = `${P}/graphql`, N = T(
|
|
49
50
|
() => ({
|
|
50
|
-
Authorization: `Bearer ${
|
|
51
|
+
Authorization: `Bearer ${S}`,
|
|
51
52
|
"Content-Type": "application/json",
|
|
52
53
|
...h ? { "User-Token": h } : {}
|
|
53
54
|
}),
|
|
54
|
-
[
|
|
55
|
-
),
|
|
55
|
+
[S, h]
|
|
56
|
+
), U = n(
|
|
56
57
|
async (e) => {
|
|
57
|
-
|
|
58
|
+
g.current && g.current.abort();
|
|
58
59
|
const r = new AbortController();
|
|
59
|
-
|
|
60
|
+
g.current = r;
|
|
60
61
|
try {
|
|
61
|
-
|
|
62
|
-
const i = (await
|
|
63
|
-
u.current[e.searchQuery] = i,
|
|
62
|
+
I(!0), m(null);
|
|
63
|
+
const i = (await ce(M, re, { searchInput: e }, N))?.search.searchHits;
|
|
64
|
+
u.current[e.searchQuery] = i, p(i);
|
|
64
65
|
} catch (o) {
|
|
65
66
|
if (o.name === "AbortError")
|
|
66
67
|
return;
|
|
67
|
-
|
|
68
|
+
m("Failed to fetch search results. Please try again.");
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
+
I(!1);
|
|
70
71
|
},
|
|
71
|
-
[
|
|
72
|
-
),
|
|
72
|
+
[M, N]
|
|
73
|
+
), j = n((e) => {
|
|
73
74
|
const r = u.current[e.searchQuery];
|
|
74
|
-
|
|
75
|
+
w({
|
|
75
76
|
eventName: "search_query_response_received",
|
|
76
77
|
properties: {
|
|
77
78
|
searchQuery: e.searchQuery,
|
|
78
79
|
totalResults: r?.length
|
|
79
80
|
}
|
|
80
81
|
});
|
|
81
|
-
}, []),
|
|
82
|
+
}, []), O = n(
|
|
82
83
|
(e) => {
|
|
83
|
-
if (
|
|
84
|
-
|
|
84
|
+
if (Q.current && window.clearTimeout(Q.current), !e.searchQuery) {
|
|
85
|
+
p([]), m(null);
|
|
85
86
|
return;
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
Q.current = window.setTimeout(() => {
|
|
89
|
+
w({
|
|
89
90
|
eventName: "search_query_submitted",
|
|
90
91
|
properties: {
|
|
91
92
|
searchQuery: e.searchQuery
|
|
92
93
|
}
|
|
93
|
-
}), u.current[e.searchQuery] ? (
|
|
94
|
-
|
|
94
|
+
}), u.current[e.searchQuery] ? (p(u.current[e.searchQuery]), j(e)) : U(e).then(() => {
|
|
95
|
+
j(e);
|
|
95
96
|
});
|
|
96
|
-
},
|
|
97
|
+
}, k);
|
|
97
98
|
},
|
|
98
|
-
[
|
|
99
|
-
),
|
|
99
|
+
[k, U]
|
|
100
|
+
), R = T(
|
|
100
101
|
() => ({
|
|
101
102
|
searchQuery: c,
|
|
102
103
|
filters: {
|
|
103
|
-
limit:
|
|
104
|
+
limit: C
|
|
104
105
|
}
|
|
105
106
|
}),
|
|
106
|
-
[c,
|
|
107
|
+
[c, C]
|
|
107
108
|
);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}, [
|
|
111
|
-
const
|
|
112
|
-
(e) =>
|
|
109
|
+
B(() => {
|
|
110
|
+
z?.(R.searchQuery), O(R);
|
|
111
|
+
}, [O, R]);
|
|
112
|
+
const X = n(
|
|
113
|
+
(e) => q(e.target.value),
|
|
113
114
|
[]
|
|
114
|
-
),
|
|
115
|
-
() =>
|
|
116
|
-
[
|
|
115
|
+
), Y = T(
|
|
116
|
+
() => v || (b ? "Search..." : "Search for anything..."),
|
|
117
|
+
[v, b]
|
|
117
118
|
);
|
|
118
119
|
return {
|
|
119
120
|
results: t,
|
|
120
|
-
resultsList:
|
|
121
|
-
hasContent:
|
|
122
|
-
loading:
|
|
123
|
-
error:
|
|
121
|
+
resultsList: d,
|
|
122
|
+
hasContent: d.length > 0 || A,
|
|
123
|
+
loading: A,
|
|
124
|
+
error: K,
|
|
124
125
|
query: c,
|
|
125
|
-
onInput:
|
|
126
|
-
placeholder:
|
|
127
|
-
tab:
|
|
128
|
-
onTabChange:
|
|
129
|
-
selectedItem:
|
|
126
|
+
onInput: X,
|
|
127
|
+
placeholder: Y,
|
|
128
|
+
tab: y,
|
|
129
|
+
onTabChange: V,
|
|
130
|
+
selectedItem: W,
|
|
130
131
|
setSelectedItem: a,
|
|
131
|
-
onSelectedItemChange:
|
|
132
|
-
transitionsDisabled:
|
|
133
|
-
inputRef:
|
|
134
|
-
isMobile:
|
|
132
|
+
onSelectedItemChange: G,
|
|
133
|
+
transitionsDisabled: J,
|
|
134
|
+
inputRef: E,
|
|
135
|
+
isMobile: b
|
|
135
136
|
};
|
|
136
137
|
};
|
|
137
138
|
export {
|
|
138
|
-
|
|
139
|
+
pe as useInkeepSearch
|
|
139
140
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),b=require("./user-provider.cjs"),p=t.createContext(void 0),f=({children:e})=>{const{baseSettings:s,componentType:n}=B.useInkeepConfig(),{apiKey:o,analyticsApiBaseUrl:r,tags:i,privacyPreferences:d,env:E}=s,{userProperties:c}=b.useUser(),a=t.useMemo(()=>({widgetLibraryVersion:"0.5.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),b=require("./user-provider.cjs"),p=t.createContext(void 0),f=({children:e})=>{const{baseSettings:s,componentType:n}=B.useInkeepConfig(),{apiKey:o,analyticsApiBaseUrl:r,tags:i,privacyPreferences:d,env:E}=s,{userProperties:c}=b.useUser(),a=t.useMemo(()=>({widgetLibraryVersion:"0.5.18",componentType:n,tags:i}),[n,i]),u=!d.optOutAllAnalytics&&E!=="development",g={logEvent:t.useCallback(async v=>{const m={...a,...v.properties},l={eventName:v.eventName,properties:m,userProperties:c};u&&y.logEvent(l,o,r),s.onEvent?.(l)},[u,s,o,r,c,a])};return P.jsx(p.Provider,{value:g,children:e})},x=()=>{const e=t.useContext(p);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=f;exports.useBaseEvents=x;
|
|
@@ -7,7 +7,7 @@ import { useUser as b } from "./user-provider.js";
|
|
|
7
7
|
const m = x(void 0), U = ({ children: e }) => {
|
|
8
8
|
const { baseSettings: t, componentType: o } = C(), { apiKey: n, analyticsApiBaseUrl: s, tags: r, privacyPreferences: u, env: l } = t, { userProperties: i } = b(), a = d(
|
|
9
9
|
() => ({
|
|
10
|
-
widgetLibraryVersion: "0.5.
|
|
10
|
+
widgetLibraryVersion: "0.5.18",
|
|
11
11
|
componentType: o,
|
|
12
12
|
tags: r
|
|
13
13
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/cxkit-primitives",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Inkeep, Inc. Customer License (IICL) v1.1",
|
|
6
6
|
"homepage": "",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"rehype-raw": "7.0.0",
|
|
59
59
|
"unist-util-visit": "^5.0.0",
|
|
60
60
|
"use-sync-external-store": "^1.4.0",
|
|
61
|
-
"@inkeep/cxkit-color-mode": "0.5.
|
|
62
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
63
|
-
"@inkeep/cxkit-types": "0.5.
|
|
61
|
+
"@inkeep/cxkit-color-mode": "0.5.18",
|
|
62
|
+
"@inkeep/cxkit-theme": "0.5.18",
|
|
63
|
+
"@inkeep/cxkit-types": "0.5.18"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@biomejs/biome": "1.9.4",
|