randmarcomps 1.152.0 → 1.154.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.
@@ -48,6 +48,15 @@ export declare interface AiGeneratedContentProps {
48
48
  data: any;
49
49
  }
50
50
 
51
+ declare interface ApiKeyContextType {
52
+ apiKey: string | null;
53
+ setApiKey: (key: string) => void;
54
+ }
55
+
56
+ export declare const ApiKeyProvider: ({ children }: {
57
+ children: ReactNode;
58
+ }) => JSX.Element;
59
+
51
60
  export declare function AreaChart({ data, units, unitsPosition, width, height, className }: AreaChartProps): JSX.Element;
52
61
 
53
62
  export declare interface AreaChartProps {
@@ -582,6 +591,8 @@ export declare interface TopbarProps {
582
591
  searchPlaceholder?: string;
583
592
  }
584
593
 
594
+ export declare const useApiKey: () => ApiKeyContextType;
595
+
585
596
  export declare function useIsMobile(): boolean;
586
597
 
587
598
  export declare function useSidebar(): SidebarContext;
@@ -7,7 +7,7 @@ var Ve = (e, t, n) => Yr(e, typeof t != "symbol" ? t + "" : t, n), Xr = (e, t, n
7
7
  var De = (e, t, n) => (Xr(e, t, "read from private field"), n ? n.call(e) : t.get(e)), at = (e, t, n) => t.has(e) ? Sr("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n);
8
8
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
9
9
  import * as React from "react";
10
- import React__default, { forwardRef, createElement, useState, useLayoutEffect, useEffect, isValidElement, Children, PureComponent, useRef, useImperativeHandle, useCallback, useMemo, cloneElement, useContext, createContext, Component, useDebugValue, Fragment as Fragment$1 } from "react";
10
+ import React__default, { forwardRef, createElement, useState, useLayoutEffect, useEffect, createContext, useContext, isValidElement, Children, PureComponent, useRef, useImperativeHandle, useCallback, useMemo, cloneElement, Component, useDebugValue, Fragment as Fragment$1 } from "react";
11
11
  import * as ReactDOM from "react-dom";
12
12
  import ReactDOM__default from "react-dom";
13
13
  import { Link, useLocation, useParams } from "react-router-dom";
@@ -9476,6 +9476,15 @@ function Toaster() {
9476
9476
  /* @__PURE__ */ jsx(ToastViewport, {})
9477
9477
  ] });
9478
9478
  }
9479
+ const ApiKeyContext = createContext(void 0), ApiKeyProvider = ({ children: e }) => {
9480
+ const [t, n] = useState(null);
9481
+ return /* @__PURE__ */ jsx(ApiKeyContext.Provider, { value: { apiKey: t, setApiKey: n }, children: e });
9482
+ }, useApiKey = () => {
9483
+ const e = useContext(ApiKeyContext);
9484
+ if (!e)
9485
+ throw new Error("useApiKey must be used within an ApiKeyProvider");
9486
+ return e;
9487
+ };
9479
9488
  var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
9480
9489
  function getDefaultExportFromCjs(e) {
9481
9490
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
@@ -58854,22 +58863,38 @@ Dt = new WeakMap(), je = new WeakMap(), Ft = new WeakMap(), qt = new WeakMap(),
58854
58863
  renderUnrecognized: () => null
58855
58864
  });
58856
58865
  var source_default = JsxParser;
58857
- function GetJSXFromAI(e, t) {
58858
- const n = "In addition to basic html tags, You have access to these beautiful Handmade Components: Button.", o = "Here is the data to display to the user (If a Handmade Component fits, use it. Otherwise, use regular html tags):", l = "Only output JSX with proper syntax. No text before, or after, and no need to define a code region with backticks (```). Start with <> and end with </>.", u = JSON.stringify(t);
58859
- return `<p>Work in progress. prompt=${[e, n, l, o, u, l].join(`\r
58860
- `)}</p>`;
58866
+ const GetJSXFromAI = async (e, t, n, o = 3) => {
58867
+ const l = "In addition to basic html tags, You have access to these beautiful Handmade Components: Button.", u = "Here is the data to display to the user (If a Handmade Component is a perfect fit for the data, use it. Otherwise, use regular html tags):", d = "Only output a single JSX code snippet. Start with <> and end with </>. All other code will be ignored, so make sure to place all CSS styles inline. Use CSS flex layouts when there is a lot of stuff to display.", f = JSON.stringify(n), p = [t, l, d, u, f, d].join(`\r
58868
+ `), b = await new GoogleGenAI({ apiKey: e }).chats.create({
58869
+ model: "gemini-2.0-flash-lite"
58870
+ }).sendMessage({ message: p }), _ = trimJSXString(b.text ?? "");
58871
+ return _ || (o == 0 ? "<p>Failed to generate. Reload the page.</p>" : await GetJSXFromAI(e, t, n, o - 1));
58872
+ };
58873
+ function trimJSXString(e) {
58874
+ const t = e.indexOf("<"), n = e.lastIndexOf("</");
58875
+ return t === -1 || n === -1 ? "" : e.slice(t, e.indexOf(">", n) + 1);
58861
58876
  }
58862
58877
  function AiGeneratedContent(e) {
58863
- const { appID: t } = useParams(), n = useMemo(() => !e.prompt || !e.data ? "..." : GetJSXFromAI(e.prompt, e.data), [e.prompt, e.data]);
58864
- return /* @__PURE__ */ jsx(
58878
+ const { appID: t } = useParams(), [n, o] = useState(""), { apiKey: l } = useApiKey();
58879
+ return useEffect(() => {
58880
+ if (!l || !e.prompt || !e.data) return;
58881
+ o("");
58882
+ let u = !1;
58883
+ return GetJSXFromAI(l, e.prompt, e.data).then((d) => {
58884
+ u || o(d);
58885
+ }), () => {
58886
+ u = !0;
58887
+ };
58888
+ }, [e.prompt, e.data, o, l]), n ? /* @__PURE__ */ jsx(
58865
58889
  source_default,
58866
58890
  {
58867
58891
  bindings: {
58868
58892
  appID: t
58869
58893
  },
58894
+ components: { Button },
58870
58895
  jsx: n
58871
58896
  }
58872
- );
58897
+ ) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-32 w-32", children: /* @__PURE__ */ jsx(Bot, { className: "m-auto align-middle h-full" }) }) });
58873
58898
  }
58874
58899
  const CountryFlag = ({ countryCode: e, className: t = "" }) => {
58875
58900
  const [n, o] = useState(null), [l, u] = useState(!1);
@@ -61064,6 +61089,7 @@ function SalesOverviewData({
61064
61089
  export {
61065
61090
  ActiveOrdersCard,
61066
61091
  AiGeneratedContent,
61092
+ ApiKeyProvider,
61067
61093
  AreaChart,
61068
61094
  Avatar,
61069
61095
  AvatarFallback,
@@ -61186,6 +61212,7 @@ export {
61186
61212
  badgeVariants,
61187
61213
  buttonVariants,
61188
61214
  toast,
61215
+ useApiKey,
61189
61216
  useIsMobile,
61190
61217
  useSidebar,
61191
61218
  useToast