@embeddable/sdk 1.0.4 → 1.0.6
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/dist/context/EmbeddableProvider.d.ts +7 -7
- package/dist/context/EmbeddableProvider.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useEmbeddableData.d.ts +3 -1
- package/dist/hooks/useEmbeddableData.d.ts.map +1 -1
- package/dist/hooks/useFormSubmission.d.ts +15 -0
- package/dist/hooks/useFormSubmission.d.ts.map +1 -0
- package/dist/hooks/useVote.d.ts +15 -0
- package/dist/hooks/useVote.d.ts.map +1 -0
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +4 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -2
- package/dist/types/index.d.ts +27 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/useVote-2D5ATpt5.cjs +10 -0
- package/dist/{useLocalStorage-BaS2J0KR.js → useVote-Bg2pBlaS.js} +135 -2
- package/dist/utils/config.d.ts +2 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/useLocalStorage-BCg_U2UB.cjs +0 -10
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { EmbeddableConfig } from '../types';
|
|
3
3
|
|
|
4
|
-
interface EmbeddableContextType {
|
|
4
|
+
interface EmbeddableContextType<T = Record<string, any>> {
|
|
5
5
|
config: EmbeddableConfig | null;
|
|
6
6
|
setConfig: (config: EmbeddableConfig) => void;
|
|
7
|
-
data:
|
|
8
|
-
setData: (data:
|
|
7
|
+
data: T;
|
|
8
|
+
setData: (data: T) => void;
|
|
9
9
|
}
|
|
10
|
-
interface EmbeddableProviderProps {
|
|
10
|
+
interface EmbeddableProviderProps<T = Record<string, any>> {
|
|
11
11
|
config?: EmbeddableConfig;
|
|
12
|
-
data?:
|
|
12
|
+
data?: T;
|
|
13
13
|
children: ReactNode;
|
|
14
14
|
}
|
|
15
|
-
export declare function EmbeddableProvider({ config: initialConfig, data: initialData, children, }: EmbeddableProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
export declare function useEmbeddableContext(): EmbeddableContextType
|
|
15
|
+
export declare function EmbeddableProvider<T = Record<string, any>>({ config: initialConfig, data: initialData, children, }: EmbeddableProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare function useEmbeddableContext<T = Record<string, any>>(): EmbeddableContextType<T>;
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=EmbeddableProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmbeddableProvider.d.ts","sourceRoot":"","sources":["../../src/context/EmbeddableProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,UAAU,qBAAqB;
|
|
1
|
+
{"version":3,"file":"EmbeddableProvider.d.ts","sourceRoot":"","sources":["../../src/context/EmbeddableProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,SAAS,EAAmC,MAAM,OAAO,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,UAAU,qBAAqB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACrD,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,SAAS,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC9C,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;CAC5B;AAoBD,UAAU,uBAAuB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACvD,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAC1D,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,WAAW,EACjB,QAAQ,GACT,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAiC5B;AAED,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,qBAAqB,CAAC,CAAC,CAAC,CAMxF"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ export { useApi } from './useApi';
|
|
|
2
2
|
export { useDebounce } from './useDebounce';
|
|
3
3
|
export { useEmbeddableConfig, useEmbeddableConfigSafe } from './useEmbeddableConfig';
|
|
4
4
|
export { useEmbeddableData } from './useEmbeddableData';
|
|
5
|
+
export { useFormSubmission } from './useFormSubmission';
|
|
5
6
|
export { useLocalStorage } from './useLocalStorage';
|
|
7
|
+
export { useVote } from './useVote';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
* Hook to access the global Embeddable data
|
|
3
3
|
* @returns The current data
|
|
4
4
|
*/
|
|
5
|
-
export declare function useEmbeddableData
|
|
5
|
+
export declare function useEmbeddableData<T = Record<string, any>>(): {
|
|
6
|
+
data: T;
|
|
7
|
+
};
|
|
6
8
|
//# sourceMappingURL=useEmbeddableData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEmbeddableData.d.ts","sourceRoot":"","sources":["../../src/hooks/useEmbeddableData.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"useEmbeddableData.d.ts","sourceRoot":"","sources":["../../src/hooks/useEmbeddableData.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAIxE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FormSubmissionOptions, FormSubmissionResponse } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React hook for handling form submissions with loading, error states, and validation
|
|
5
|
+
* @param options - Optional configuration for the hook including payload validation and collection name
|
|
6
|
+
* @returns Object with submit function and state management
|
|
7
|
+
*/
|
|
8
|
+
export declare function useFormSubmission<TPayload = Record<string, any>>(options?: FormSubmissionOptions): {
|
|
9
|
+
submit: (payload: TPayload) => Promise<FormSubmissionResponse>;
|
|
10
|
+
reset: () => void;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: string | null;
|
|
13
|
+
success: boolean;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=useFormSubmission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormSubmission.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormSubmission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAU9F;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,qBAAqB;sBAS7E,QAAQ,KAAG,OAAO,CAAC,sBAAsB,CAAC;;aAnBnD,OAAO;WACT,MAAM,GAAG,IAAI;aACX,OAAO;EAwFjB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VoteOptions, VoteResponse } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React hook for handling votes with loading, error states
|
|
5
|
+
* @param options - Optional configuration for the hook including collection name
|
|
6
|
+
* @returns Object with vote function and state management
|
|
7
|
+
*/
|
|
8
|
+
export declare function useVote(options?: VoteOptions): {
|
|
9
|
+
vote: (voteFor: string) => Promise<VoteResponse>;
|
|
10
|
+
reset: () => void;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: string | null;
|
|
13
|
+
success: boolean;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=useVote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVote.d.ts","sourceRoot":"","sources":["../../src/hooks/useVote.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAQ,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAUhE;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW;oBASzB,MAAM,KAAG,OAAO,CAAC,YAAY,CAAC;;aAnBvC,OAAO;WACT,MAAM,GAAG,IAAI;aACX,OAAO;EA4EjB"}
|
package/dist/hooks.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useVote-2D5ATpt5.cjs");exports.useApi=e.useApi,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableConfigSafe=e.useEmbeddableConfigSafe,exports.useEmbeddableData=e.useEmbeddableData,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.useVote=e.useVote;
|
package/dist/hooks.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { a, b, c, d, e, f } from "./
|
|
1
|
+
import { a, b, c, d, e, f, g, h } from "./useVote-Bg2pBlaS.js";
|
|
2
2
|
export {
|
|
3
3
|
a as useApi,
|
|
4
4
|
b as useDebounce,
|
|
5
5
|
c as useEmbeddableConfig,
|
|
6
6
|
d as useEmbeddableConfigSafe,
|
|
7
7
|
e as useEmbeddableData,
|
|
8
|
-
f as
|
|
8
|
+
f as useFormSubmission,
|
|
9
|
+
g as useLocalStorage,
|
|
10
|
+
h as useVote
|
|
9
11
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useVote-2D5ATpt5.cjs"),s=require("./storage-3dk6ww91.cjs"),o=require("./utils.cjs");exports.EmbeddableProvider=e.EmbeddableProvider,exports.useApi=e.useApi,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableConfigSafe=e.useEmbeddableConfigSafe,exports.useEmbeddableContext=e.useEmbeddableContext,exports.useEmbeddableData=e.useEmbeddableData,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.useVote=e.useVote,exports.createApiClient=s.createApiClient,exports.storage=s.storage,exports.debounce=o.debounce;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E, a, b, c, d, u, e, f } from "./
|
|
1
|
+
import { E, a, b, c, d, u, e, f, g, h } from "./useVote-Bg2pBlaS.js";
|
|
2
2
|
import { c as c2, s } from "./storage-CRPDfSRn.js";
|
|
3
3
|
import { debounce } from "./utils.js";
|
|
4
4
|
export {
|
|
@@ -12,5 +12,7 @@ export {
|
|
|
12
12
|
d as useEmbeddableConfigSafe,
|
|
13
13
|
u as useEmbeddableContext,
|
|
14
14
|
e as useEmbeddableData,
|
|
15
|
-
f as
|
|
15
|
+
f as useFormSubmission,
|
|
16
|
+
g as useLocalStorage,
|
|
17
|
+
h as useVote
|
|
16
18
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -25,4 +25,31 @@ export interface EmbeddableConfig {
|
|
|
25
25
|
_containerId?: string;
|
|
26
26
|
_shadowRoot?: ShadowRoot;
|
|
27
27
|
}
|
|
28
|
+
export interface FormSubmission<TPayload = Record<string, any>> {
|
|
29
|
+
widgetId: string;
|
|
30
|
+
collectionName: string;
|
|
31
|
+
payload: TPayload;
|
|
32
|
+
}
|
|
33
|
+
export interface FormSubmissionResponse {
|
|
34
|
+
id?: string;
|
|
35
|
+
success: boolean;
|
|
36
|
+
message?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface FormSubmissionOptions {
|
|
39
|
+
collectionName?: string;
|
|
40
|
+
validatePayload?: (payload: any) => string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface Vote {
|
|
43
|
+
widgetId: string;
|
|
44
|
+
collectionName: string;
|
|
45
|
+
voteFor: string;
|
|
46
|
+
}
|
|
47
|
+
export interface VoteResponse {
|
|
48
|
+
id?: string;
|
|
49
|
+
success: boolean;
|
|
50
|
+
message?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface VoteOptions {
|
|
53
|
+
collectionName?: string;
|
|
54
|
+
}
|
|
28
55
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;IACnC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;CACtC;AAED,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;IACnC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;CACtC;AAED,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAGD,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,QAAQ,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;CACnD;AAGD,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";const e=require("react"),r=require("./storage-3dk6ww91.cjs");var t,n={exports:{}},o={};var a,s={};
|
|
2
|
+
/**
|
|
3
|
+
* @license React
|
|
4
|
+
* react-jsx-runtime.development.js
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/"production"===process.env.NODE_ENV?n.exports=function(){if(t)return o;t=1;var r=e,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function u(e,r,t){var o,a={},u=null,l=null;for(o in void 0!==t&&(u=""+t),void 0!==r.key&&(u=""+r.key),void 0!==r.ref&&(l=r.ref),r)s.call(r,o)&&!c.hasOwnProperty(o)&&(a[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps)void 0===a[o]&&(a[o]=r[o]);return{$$typeof:n,type:e,key:u,ref:l,props:a,_owner:i.current}}return o.Fragment=a,o.jsx=u,o.jsxs=u,o}():n.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var r,t=e,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),l=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),b=Symbol.iterator,v=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=v.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}function w(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case o:return"Portal";case c:return"Profiler";case i:return"StrictMode";case p:return"Suspense";case d:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case l:return w(e)+".Consumer";case u:return w(e._context)+".Provider";case f:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case y:var r=e.displayName||null;return null!==r?r:k(e.type)||"Memo";case g:var t=e,n=t._payload,s=t._init;try{return k(s(n))}catch(m){return null}}return null}r=Symbol.for("react.module.reference");var _,S,E,O,j,C,P,R=Object.assign,x=0;function T(){}T.__reactDisabledLog=!0;var $,N=v.ReactCurrentDispatcher;function D(e,r,t){if(void 0===$)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);$=n&&n[1]||""}return"\n"+$+e}var F,I=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||I)return"";var t,n=F.get(e);if(void 0!==n)return n;I=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=N.current,N.current=null,function(){if(0===x){_=console.log,S=console.info,E=console.warn,O=console.error,j=console.group,C=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:T,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}x++}();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(y){t=y}Reflect.construct(e,[],s)}else{try{s.call()}catch(y){t=y}e.call(s.prototype)}}else{try{throw Error()}catch(y){t=y}e()}}catch(g){if(g&&t&&"string"==typeof g.stack){for(var i=g.stack.split("\n"),c=t.stack.split("\n"),u=i.length-1,l=c.length-1;u>=1&&l>=0&&i[u]!==c[l];)l--;for(;u>=1&&l>=0;u--,l--)if(i[u]!==c[l]){if(1!==u||1!==l)do{if(u--,--l<0||i[u]!==c[l]){var f="\n"+i[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&F.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{I=!1,N.current=o,function(){if(0===--x){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:R({},e,{value:_}),info:R({},e,{value:S}),warn:R({},e,{value:E}),error:R({},e,{value:O}),group:R({},e,{value:j}),groupCollapsed:R({},e,{value:C}),groupEnd:R({},e,{value:P})})}x<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",d=p?D(p):"";return"function"==typeof e&&F.set(e,d),d}function A(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return D(e);switch(e){case p:return D("Suspense");case d:return D("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case f:return U(e.render,!1);case y:return A(e.type,r,t);case g:var o=e,a=o._payload,s=o._init;try{return A(s(a),r,t)}catch(i){}}return""}F=new L;var W=Object.prototype.hasOwnProperty,z={},V=v.ReactDebugCurrentFrame;function M(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);V.setExtraStackFrame(t)}else V.setExtraStackFrame(null)}var J=Array.isArray;function Y(e){return J(e)}function q(e){return""+e}function B(e){if(function(e){try{return q(e),!1}catch(r){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),q(e)}var H,K,X=v.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,t,o,a){var s,i={},c=null,u=null;for(s in void 0!==t&&(B(t),c=""+t),function(e){if(W.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(B(r.key),c=""+r.key),function(e){if(W.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(u=r.ref,function(e){"string"==typeof e.ref&&X.current}(r)),r)W.call(r,s)&&!G.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var l=e.defaultProps;for(s in l)void 0===i[s]&&(i[s]=l[s])}if(c||u){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){H||(H=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(i,f),u&&function(e,r){var t=function(){K||(K=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(i,f)}return function(e,r,t,o,a,s,i){var c={$$typeof:n,type:e,key:r,ref:t,props:i,_owner:s,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(e,c,u,a,o,X.current,i)}var Z,ee=v.ReactCurrentOwner,re=v.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function se(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),te(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),te(null)}}}function ie(e,r){if("object"==typeof e)if(Y(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&se(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=b&&e[b]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,s=o.call(e);!(a=s.next()).done;)ne(a.value)&&se(a.value,r)}}function ce(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==f&&t.$$typeof!==y)return;r=t.propTypes}if(r){var n=k(t);!function(e,r,t,n,o){var a=Function.call.bind(W);for(var s in e)if(a(e,s)){var i=void 0;try{if("function"!=typeof e[s]){var c=Error((n||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}i=e[s](r,s,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(u){i=u}!i||i instanceof Error||(M(o),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,s,typeof i),M(null)),i instanceof Error&&!(i.message in z)&&(z[i.message]=!0,M(o),h("Failed %s type: %s",t,i.message),M(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ue={};function le(e,t,o,s,b,v){var w=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===c||e===i||e===p||e===d||e===m||"object"==typeof e&&null!==e&&(e.$$typeof===g||e.$$typeof===y||e.$$typeof===u||e.$$typeof===l||e.$$typeof===f||e.$$typeof===r||void 0!==e.getModuleId)}(e);if(!w){var _,S="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(S+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),S+=oe(),null===e?_="null":Y(e)?_="array":void 0!==e&&e.$$typeof===n?(_="<"+(k(e.type)||"Unknown")+" />",S=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,S)}var E=Q(e,t,o,b,v);if(null==E)return E;if(w){var O=t.children;if(void 0!==O)if(s)if(Y(O)){for(var j=0;j<O.length;j++)ie(O[j],e);Object.freeze&&Object.freeze(O)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ie(O,e)}if(W.call(t,"key")){var C=k(e),P=Object.keys(t).filter((function(e){return"key"!==e})),R=P.length>0?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}";ue[C+R]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',R,C,P.length>0?"{"+P.join(": ..., ")+": ...}":"{}",C),ue[C+R]=!0)}return e===a?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(E):ce(E),E}var fe=function(e,r,t){return le(e,r,t,!1)},pe=function(e,r,t){return le(e,r,t,!0)};s.Fragment=a,s.jsx=fe,s.jsxs=pe}()),s);var i=n.exports;const c={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},u=e.createContext({config:{...c},setConfig:()=>{},data:{},setData:()=>{}});function l(){const r=e.useContext(u);if(!r)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return r}function f(){const{config:e}=l();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e}const p="https://events.embeddable.co";exports.EmbeddableProvider=function({config:r,data:t,children:n}){const[o,a]=e.useState(c),[s,l]=e.useState(t||{});return e.useEffect((()=>{a({...c,...r})}),[r]),e.useEffect((()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&l(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[]),i.jsx(u.Provider,{value:{config:o,setConfig:a,data:s,setData:l},children:n})},exports.useApi=function(t){const n=t;if(!n)throw new Error("No API configuration provided. Either pass a config parameter or wrap your app with EmbeddableProvider.");const[o,a]=e.useState({data:null,loading:!1,error:null}),s=r.createApiClient(n),i=e.useCallback((async(e,r,t)=>{a((e=>({...e,loading:!0,error:null})));try{let n;switch(e){case"get":n=await s.get(r);break;case"post":n=await s.post(r,t);break;case"put":n=await s.put(r,t);break;case"delete":n=await s.delete(r);break;default:throw new Error(`Unsupported method: ${e}`)}return a({data:n.data,loading:!1,error:n.success?null:n.error||"Unknown error"}),n}catch(n){const e=n instanceof Error?n.message:"Unknown error";return a({data:null,loading:!1,error:e}),{data:null,success:!1,error:e}}}),[s]);return{...o,get:e.useCallback((e=>i("get",e)),[i]),post:e.useCallback(((e,r)=>i("post",e,r)),[i]),put:e.useCallback(((e,r)=>i("put",e,r)),[i]),delete:e.useCallback((e=>i("delete",e)),[i]),reset:e.useCallback((()=>{a({data:null,loading:!1,error:null})}),[])}},exports.useDebounce=function(r,t){const[n,o]=e.useState(r);return e.useEffect((()=>{const e=setTimeout((()=>{o(r)}),t);return()=>{clearTimeout(e)}}),[r,t]),n},exports.useEmbeddableConfig=f,exports.useEmbeddableConfigSafe=function(){const{config:e}=l();return e},exports.useEmbeddableContext=l,exports.useEmbeddableData=function(){const{data:e}=l();return{data:e}},exports.useFormSubmission=function(r){const{widgetId:t}=f(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,submit:e.useCallback((async e=>{o({loading:!0,error:null,success:!1});try{if(null==r?void 0:r.validatePayload){const t=r.validatePayload(e);if(t)return o({loading:!1,error:t,success:!1}),{success:!1,message:t}}const n={payload:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"submissions"},a=await fetch(`${p}/api/submissions`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(n)}),s=await a.json();if(!a.ok){const e=s.message||s.error||`HTTP ${a.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}return o({loading:!1,error:null,success:!0}),{id:s.id||s._id,success:!0,message:s.message||"Submission successful"}}catch(n){const e=n instanceof Error?n.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useLocalStorage=function(t,n,o={}){const[a,s]=e.useState((()=>{const e=r.storage.get(t,o);return null!==e?e:n})),i=e.useCallback((e=>{try{const n=e instanceof Function?e(a):e;s(n),r.storage.set(t,n,o)}catch(n){}}),[t,a,o]),c=e.useCallback((()=>{try{s(n),r.storage.remove(t,o)}catch(e){}}),[t,n,o]);return e.useEffect((()=>{const e=e=>{const{prefix:r=""}=o,n=r+t;if(e.key===n&&null!==e.newValue)try{const{deserialize:r=JSON.parse}=o,t=r(e.newValue);s(t)}catch(a){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,o]),[a,i,c]},exports.useVote=function(r){const{widgetId:t}=f(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,vote:e.useCallback((async e=>{o({loading:!0,error:null,success:!1});try{const n={voteFor:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"votes"},a=await fetch(`${p}/api/votes`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(n)}),s=await a.json();if(!a.ok){const e=s.message||s.error||`HTTP ${a.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}return o({loading:!1,error:null,success:!0}),{id:s.id||s._id,success:!0,message:s.message||"Vote submitted successfully"}}catch(n){const e=n instanceof Error?n.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}};
|
|
@@ -1080,7 +1080,78 @@ function useEmbeddableConfigSafe() {
|
|
|
1080
1080
|
}
|
|
1081
1081
|
function useEmbeddableData() {
|
|
1082
1082
|
const { data } = useEmbeddableContext();
|
|
1083
|
-
return data;
|
|
1083
|
+
return { data };
|
|
1084
|
+
}
|
|
1085
|
+
const EVENTS_BASE_URL = "https://events.embeddable.co";
|
|
1086
|
+
function useFormSubmission(options) {
|
|
1087
|
+
const { widgetId } = useEmbeddableConfig();
|
|
1088
|
+
const [state, setState] = useState({
|
|
1089
|
+
loading: false,
|
|
1090
|
+
error: null,
|
|
1091
|
+
success: false
|
|
1092
|
+
});
|
|
1093
|
+
const submit = useCallback(
|
|
1094
|
+
async (payload) => {
|
|
1095
|
+
setState({ loading: true, error: null, success: false });
|
|
1096
|
+
try {
|
|
1097
|
+
if (options == null ? void 0 : options.validatePayload) {
|
|
1098
|
+
const validationError = options.validatePayload(payload);
|
|
1099
|
+
if (validationError) {
|
|
1100
|
+
setState({ loading: false, error: validationError, success: false });
|
|
1101
|
+
return {
|
|
1102
|
+
success: false,
|
|
1103
|
+
message: validationError
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
const submission = {
|
|
1108
|
+
payload,
|
|
1109
|
+
widgetId,
|
|
1110
|
+
collectionName: (options == null ? void 0 : options.collectionName) || "submissions"
|
|
1111
|
+
};
|
|
1112
|
+
const response = await fetch(`${EVENTS_BASE_URL}/api/submissions`, {
|
|
1113
|
+
method: "POST",
|
|
1114
|
+
headers: {
|
|
1115
|
+
"Content-Type": "application/json"
|
|
1116
|
+
},
|
|
1117
|
+
// Explicitly set credentials to 'omit' for CORS support
|
|
1118
|
+
credentials: "omit",
|
|
1119
|
+
body: JSON.stringify(submission)
|
|
1120
|
+
});
|
|
1121
|
+
const data = await response.json();
|
|
1122
|
+
if (!response.ok) {
|
|
1123
|
+
const errorMessage = data.message || data.error || `HTTP ${response.status}`;
|
|
1124
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1125
|
+
return {
|
|
1126
|
+
success: false,
|
|
1127
|
+
message: errorMessage
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
setState({ loading: false, error: null, success: true });
|
|
1131
|
+
return {
|
|
1132
|
+
id: data.id || data._id,
|
|
1133
|
+
success: true,
|
|
1134
|
+
message: data.message || "Submission successful"
|
|
1135
|
+
};
|
|
1136
|
+
} catch (error) {
|
|
1137
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1138
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1139
|
+
return {
|
|
1140
|
+
success: false,
|
|
1141
|
+
message: errorMessage
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
[options, widgetId]
|
|
1146
|
+
);
|
|
1147
|
+
const reset = useCallback(() => {
|
|
1148
|
+
setState({ loading: false, error: null, success: false });
|
|
1149
|
+
}, []);
|
|
1150
|
+
return {
|
|
1151
|
+
...state,
|
|
1152
|
+
submit,
|
|
1153
|
+
reset
|
|
1154
|
+
};
|
|
1084
1155
|
}
|
|
1085
1156
|
function useLocalStorage(key, initialValue, options = {}) {
|
|
1086
1157
|
const [storedValue, setStoredValue] = useState(() => {
|
|
@@ -1126,6 +1197,66 @@ function useLocalStorage(key, initialValue, options = {}) {
|
|
|
1126
1197
|
}, [key, options]);
|
|
1127
1198
|
return [storedValue, setValue, removeValue];
|
|
1128
1199
|
}
|
|
1200
|
+
function useVote(options) {
|
|
1201
|
+
const { widgetId } = useEmbeddableConfig();
|
|
1202
|
+
const [state, setState] = useState({
|
|
1203
|
+
loading: false,
|
|
1204
|
+
error: null,
|
|
1205
|
+
success: false
|
|
1206
|
+
});
|
|
1207
|
+
const vote = useCallback(
|
|
1208
|
+
async (voteFor) => {
|
|
1209
|
+
setState({ loading: true, error: null, success: false });
|
|
1210
|
+
try {
|
|
1211
|
+
const voteData = {
|
|
1212
|
+
voteFor,
|
|
1213
|
+
widgetId,
|
|
1214
|
+
collectionName: (options == null ? void 0 : options.collectionName) || "votes"
|
|
1215
|
+
};
|
|
1216
|
+
const response = await fetch(`${EVENTS_BASE_URL}/api/votes`, {
|
|
1217
|
+
method: "POST",
|
|
1218
|
+
headers: {
|
|
1219
|
+
"Content-Type": "application/json"
|
|
1220
|
+
},
|
|
1221
|
+
// Explicitly set credentials to 'omit' for CORS support
|
|
1222
|
+
credentials: "omit",
|
|
1223
|
+
body: JSON.stringify(voteData)
|
|
1224
|
+
});
|
|
1225
|
+
const data = await response.json();
|
|
1226
|
+
if (!response.ok) {
|
|
1227
|
+
const errorMessage = data.message || data.error || `HTTP ${response.status}`;
|
|
1228
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1229
|
+
return {
|
|
1230
|
+
success: false,
|
|
1231
|
+
message: errorMessage
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
setState({ loading: false, error: null, success: true });
|
|
1235
|
+
return {
|
|
1236
|
+
id: data.id || data._id,
|
|
1237
|
+
success: true,
|
|
1238
|
+
message: data.message || "Vote submitted successfully"
|
|
1239
|
+
};
|
|
1240
|
+
} catch (error) {
|
|
1241
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1242
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1243
|
+
return {
|
|
1244
|
+
success: false,
|
|
1245
|
+
message: errorMessage
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
},
|
|
1249
|
+
[options, widgetId]
|
|
1250
|
+
);
|
|
1251
|
+
const reset = useCallback(() => {
|
|
1252
|
+
setState({ loading: false, error: null, success: false });
|
|
1253
|
+
}, []);
|
|
1254
|
+
return {
|
|
1255
|
+
...state,
|
|
1256
|
+
vote,
|
|
1257
|
+
reset
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1129
1260
|
export {
|
|
1130
1261
|
EmbeddableProvider as E,
|
|
1131
1262
|
useApi as a,
|
|
@@ -1133,6 +1264,8 @@ export {
|
|
|
1133
1264
|
useEmbeddableConfig as c,
|
|
1134
1265
|
useEmbeddableConfigSafe as d,
|
|
1135
1266
|
useEmbeddableData as e,
|
|
1136
|
-
|
|
1267
|
+
useFormSubmission as f,
|
|
1268
|
+
useLocalStorage as g,
|
|
1269
|
+
useVote as h,
|
|
1137
1270
|
useEmbeddableContext as u
|
|
1138
1271
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,iCAAiC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react"),r=require("./storage-3dk6ww91.cjs");var t,n={exports:{}},o={};var a,i={};
|
|
2
|
-
/**
|
|
3
|
-
* @license React
|
|
4
|
-
* react-jsx-runtime.development.js
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/"production"===process.env.NODE_ENV?n.exports=function(){if(t)return o;t=1;var r=e,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,s=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function u(e,r,t){var o,a={},u=null,l=null;for(o in void 0!==t&&(u=""+t),void 0!==r.key&&(u=""+r.key),void 0!==r.ref&&(l=r.ref),r)i.call(r,o)&&!c.hasOwnProperty(o)&&(a[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps)void 0===a[o]&&(a[o]=r[o]);return{$$typeof:n,type:e,key:u,ref:l,props:a,_owner:s.current}}return o.Fragment=a,o.jsx=u,o.jsxs=u,o}():n.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var r,t=e,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),l=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),b=Symbol.for("react.offscreen"),g=Symbol.iterator,m=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=m.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}function w(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case o:return"Portal";case c:return"Profiler";case s:return"StrictMode";case p:return"Suspense";case d:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case l:return w(e)+".Consumer";case u:return w(e._context)+".Provider";case f:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case y:var r=e.displayName||null;return null!==r?r:k(e.type)||"Memo";case v:var t=e,n=t._payload,i=t._init;try{return k(i(n))}catch(b){return null}}return null}r=Symbol.for("react.module.reference");var _,E,S,O,j,R,x,C=Object.assign,P=0;function T(){}T.__reactDisabledLog=!0;var $,D=m.ReactCurrentDispatcher;function N(e,r,t){if(void 0===$)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);$=n&&n[1]||""}return"\n"+$+e}var F,I=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||I)return"";var t,n=F.get(e);if(void 0!==n)return n;I=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=D.current,D.current=null,function(){if(0===P){_=console.log,E=console.info,S=console.warn,O=console.error,j=console.group,R=console.groupCollapsed,x=console.groupEnd;var e={configurable:!0,enumerable:!0,value:T,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}P++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(y){t=y}Reflect.construct(e,[],i)}else{try{i.call()}catch(y){t=y}e.call(i.prototype)}}else{try{throw Error()}catch(y){t=y}e()}}catch(v){if(v&&t&&"string"==typeof v.stack){for(var s=v.stack.split("\n"),c=t.stack.split("\n"),u=s.length-1,l=c.length-1;u>=1&&l>=0&&s[u]!==c[l];)l--;for(;u>=1&&l>=0;u--,l--)if(s[u]!==c[l]){if(1!==u||1!==l)do{if(u--,--l<0||s[u]!==c[l]){var f="\n"+s[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&F.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{I=!1,D.current=o,function(){if(0===--P){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:C({},e,{value:_}),info:C({},e,{value:E}),warn:C({},e,{value:S}),error:C({},e,{value:O}),group:C({},e,{value:j}),groupCollapsed:C({},e,{value:R}),groupEnd:C({},e,{value:x})})}P<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",d=p?N(p):"";return"function"==typeof e&&F.set(e,d),d}function A(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case p:return N("Suspense");case d:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case f:return U(e.render,!1);case y:return A(e.type,r,t);case v:var o=e,a=o._payload,i=o._init;try{return A(i(a),r,t)}catch(s){}}return""}F=new L;var W=Object.prototype.hasOwnProperty,z={},M=m.ReactDebugCurrentFrame;function V(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);M.setExtraStackFrame(t)}else M.setExtraStackFrame(null)}var Y=Array.isArray;function q(e){return Y(e)}function B(e){return""+e}function J(e){if(function(e){try{return B(e),!1}catch(r){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),B(e)}var K,X,H=m.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,t,o,a){var i,s={},c=null,u=null;for(i in void 0!==t&&(J(t),c=""+t),function(e){if(W.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(J(r.key),c=""+r.key),function(e){if(W.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(u=r.ref,function(e){"string"==typeof e.ref&&H.current}(r)),r)W.call(r,i)&&!G.hasOwnProperty(i)&&(s[i]=r[i]);if(e&&e.defaultProps){var l=e.defaultProps;for(i in l)void 0===s[i]&&(s[i]=l[i])}if(c||u){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){K||(K=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(s,f),u&&function(e,r){var t=function(){X||(X=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(s,f)}return function(e,r,t,o,a,i,s){var c={$$typeof:n,type:e,key:r,ref:t,props:s,_owner:i,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(e,c,u,a,o,H.current,s)}var Z,ee=m.ReactCurrentOwner,re=m.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function ie(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),te(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),te(null)}}}function se(e,r){if("object"==typeof e)if(q(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&ie(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=g&&e[g]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)ne(a.value)&&ie(a.value,r)}}function ce(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==f&&t.$$typeof!==y)return;r=t.propTypes}if(r){var n=k(t);!function(e,r,t,n,o){var a=Function.call.bind(W);for(var i in e)if(a(e,i)){var s=void 0;try{if("function"!=typeof e[i]){var c=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}s=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(u){s=u}!s||s instanceof Error||(V(o),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof s),V(null)),s instanceof Error&&!(s.message in z)&&(z[s.message]=!0,V(o),h("Failed %s type: %s",t,s.message),V(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ue={};function le(e,t,o,i,g,m){var w=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===c||e===s||e===p||e===d||e===b||"object"==typeof e&&null!==e&&(e.$$typeof===v||e.$$typeof===y||e.$$typeof===u||e.$$typeof===l||e.$$typeof===f||e.$$typeof===r||void 0!==e.getModuleId)}(e);if(!w){var _,E="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(E+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),E+=oe(),null===e?_="null":q(e)?_="array":void 0!==e&&e.$$typeof===n?(_="<"+(k(e.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,E)}var S=Q(e,t,o,g,m);if(null==S)return S;if(w){var O=t.children;if(void 0!==O)if(i)if(q(O)){for(var j=0;j<O.length;j++)se(O[j],e);Object.freeze&&Object.freeze(O)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else se(O,e)}if(W.call(t,"key")){var R=k(e),x=Object.keys(t).filter((function(e){return"key"!==e})),C=x.length>0?"{key: someKey, "+x.join(": ..., ")+": ...}":"{key: someKey}";ue[R+C]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',C,R,x.length>0?"{"+x.join(": ..., ")+": ...}":"{}",R),ue[R+C]=!0)}return e===a?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(S):ce(S),S}var fe=function(e,r,t){return le(e,r,t,!1)},pe=function(e,r,t){return le(e,r,t,!0)};i.Fragment=a,i.jsx=fe,i.jsxs=pe}()),i);var s=n.exports;const c={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},u=e.createContext({config:{...c},setConfig:()=>{},data:{},setData:()=>{}});function l(){const r=e.useContext(u);if(!r)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return r}exports.EmbeddableProvider=function({config:r,data:t,children:n}){const[o,a]=e.useState(c),[i,l]=e.useState(t||{});return e.useEffect((()=>{a({...c,...r})}),[r]),e.useEffect((()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&l(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[]),s.jsx(u.Provider,{value:{config:o,setConfig:a,data:i,setData:l},children:n})},exports.useApi=function(t){const n=t;if(!n)throw new Error("No API configuration provided. Either pass a config parameter or wrap your app with EmbeddableProvider.");const[o,a]=e.useState({data:null,loading:!1,error:null}),i=r.createApiClient(n),s=e.useCallback((async(e,r,t)=>{a((e=>({...e,loading:!0,error:null})));try{let n;switch(e){case"get":n=await i.get(r);break;case"post":n=await i.post(r,t);break;case"put":n=await i.put(r,t);break;case"delete":n=await i.delete(r);break;default:throw new Error(`Unsupported method: ${e}`)}return a({data:n.data,loading:!1,error:n.success?null:n.error||"Unknown error"}),n}catch(n){const e=n instanceof Error?n.message:"Unknown error";return a({data:null,loading:!1,error:e}),{data:null,success:!1,error:e}}}),[i]);return{...o,get:e.useCallback((e=>s("get",e)),[s]),post:e.useCallback(((e,r)=>s("post",e,r)),[s]),put:e.useCallback(((e,r)=>s("put",e,r)),[s]),delete:e.useCallback((e=>s("delete",e)),[s]),reset:e.useCallback((()=>{a({data:null,loading:!1,error:null})}),[])}},exports.useDebounce=function(r,t){const[n,o]=e.useState(r);return e.useEffect((()=>{const e=setTimeout((()=>{o(r)}),t);return()=>{clearTimeout(e)}}),[r,t]),n},exports.useEmbeddableConfig=function(){const{config:e}=l();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e},exports.useEmbeddableConfigSafe=function(){const{config:e}=l();return e},exports.useEmbeddableContext=l,exports.useEmbeddableData=function(){const{data:e}=l();return e},exports.useLocalStorage=function(t,n,o={}){const[a,i]=e.useState((()=>{const e=r.storage.get(t,o);return null!==e?e:n})),s=e.useCallback((e=>{try{const n=e instanceof Function?e(a):e;i(n),r.storage.set(t,n,o)}catch(n){}}),[t,a,o]),c=e.useCallback((()=>{try{i(n),r.storage.remove(t,o)}catch(e){}}),[t,n,o]);return e.useEffect((()=>{const e=e=>{const{prefix:r=""}=o,n=r+t;if(e.key===n&&null!==e.newValue)try{const{deserialize:r=JSON.parse}=o,t=r(e.newValue);i(t)}catch(a){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,o]),[a,s,c]};
|