@workos-inc/widgets 1.5.1 → 1.6.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.
- package/CHANGELOG.md +11 -0
- package/dist/cjs/admin-portal-domain-verification.client.cjs +32 -17
- package/dist/cjs/admin-portal-domain-verification.client.cjs.map +1 -1
- package/dist/cjs/admin-portal-domain-verification.client.d.cts +3 -2
- package/dist/cjs/{admin-portal-sso-connection-client.cjs → admin-portal-sso-connection.client.cjs} +58 -31
- package/dist/cjs/admin-portal-sso-connection.client.cjs.map +1 -0
- package/dist/cjs/admin-portal-sso-connection.client.d.cts +16 -0
- package/dist/cjs/api/api-provider.cjs +1 -1
- package/dist/cjs/api/api-provider.cjs.map +1 -1
- package/dist/cjs/api/api-provider.d.cts +1 -1
- package/dist/cjs/api/endpoint.cjs +62 -2
- package/dist/cjs/api/endpoint.cjs.map +1 -1
- package/dist/cjs/api/endpoint.d.cts +62 -1
- package/dist/cjs/{api-keys-client.cjs → api-keys.client.cjs} +42 -25
- package/dist/cjs/api-keys.client.cjs.map +1 -0
- package/dist/cjs/api-keys.client.d.cts +15 -0
- package/dist/cjs/index.cjs +9 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -2
- package/dist/cjs/lib/admin-portal-domain-verification.cjs +33 -34
- package/dist/cjs/lib/admin-portal-domain-verification.cjs.map +1 -1
- package/dist/cjs/lib/admin-portal-domain-verification.d.cts +10 -6
- package/dist/cjs/lib/admin-portal-sso-connection.cjs +79 -79
- package/dist/cjs/lib/admin-portal-sso-connection.cjs.map +1 -1
- package/dist/cjs/lib/admin-portal-sso-connection.d.cts +13 -6
- package/dist/cjs/lib/api-keys/api-keys.cjs +70 -66
- package/dist/cjs/lib/api-keys/api-keys.cjs.map +1 -1
- package/dist/cjs/lib/api-keys/api-keys.d.cts +16 -8
- package/dist/cjs/lib/constants.cjs +5 -2
- package/dist/cjs/lib/constants.cjs.map +1 -1
- package/dist/cjs/lib/constants.d.cts +2 -1
- package/dist/cjs/lib/elevated-access.cjs.map +1 -1
- package/dist/cjs/lib/empty-state.cjs +24 -8
- package/dist/cjs/lib/empty-state.cjs.map +1 -1
- package/dist/cjs/lib/empty-state.d.cts +6 -2
- package/dist/cjs/lib/generic-error.cjs +33 -24
- package/dist/cjs/lib/generic-error.cjs.map +1 -1
- package/dist/cjs/lib/generic-error.d.cts +5 -2
- package/dist/cjs/lib/identity-providers.cjs +2 -1
- package/dist/cjs/lib/identity-providers.cjs.map +1 -1
- package/dist/cjs/lib/identity-providers.d.cts +2 -2
- package/dist/cjs/lib/oauth-icons.cjs +12 -7
- package/dist/cjs/lib/oauth-icons.cjs.map +1 -1
- package/dist/cjs/lib/oauth-icons.d.cts +7 -3
- package/dist/cjs/lib/organization-switcher.cjs +62 -9
- package/dist/cjs/lib/organization-switcher.cjs.map +1 -1
- package/dist/cjs/lib/organization-switcher.d.cts +12 -9
- package/dist/cjs/lib/otp-input.cjs +1 -1
- package/dist/cjs/lib/otp-input.cjs.map +1 -1
- package/dist/cjs/lib/pipes.cjs +343 -0
- package/dist/cjs/lib/pipes.cjs.map +1 -0
- package/dist/cjs/lib/pipes.d.cts +19 -0
- package/dist/cjs/lib/provider-icon.cjs +0 -6
- package/dist/cjs/lib/provider-icon.cjs.map +1 -1
- package/dist/cjs/lib/provider-icon.d.cts +4 -1
- package/dist/cjs/lib/save-button.cjs.map +1 -1
- package/dist/cjs/lib/user-profile.cjs +77 -83
- package/dist/cjs/lib/user-profile.cjs.map +1 -1
- package/dist/cjs/lib/user-profile.d.cts +11 -7
- package/dist/cjs/lib/user-security.cjs +30 -24
- package/dist/cjs/lib/user-security.cjs.map +1 -1
- package/dist/cjs/lib/user-security.d.cts +10 -7
- package/dist/cjs/lib/user-sessions.cjs +19 -9
- package/dist/cjs/lib/user-sessions.cjs.map +1 -1
- package/dist/cjs/lib/user-sessions.d.cts +10 -6
- package/dist/cjs/lib/users-management.cjs +224 -216
- package/dist/cjs/lib/users-management.cjs.map +1 -1
- package/dist/cjs/lib/users-management.d.cts +10 -7
- package/dist/cjs/lib/utils.cjs +43 -0
- package/dist/cjs/lib/utils.cjs.map +1 -1
- package/dist/cjs/lib/utils.d.cts +29 -2
- package/dist/cjs/organization-switcher.client.cjs +45 -16
- package/dist/cjs/organization-switcher.client.cjs.map +1 -1
- package/dist/cjs/organization-switcher.client.d.cts +2 -1
- package/dist/cjs/pipes.client.cjs +64 -0
- package/dist/cjs/pipes.client.cjs.map +1 -0
- package/dist/cjs/pipes.client.d.cts +15 -0
- package/dist/cjs/user-profile.client.cjs +27 -10
- package/dist/cjs/user-profile.client.cjs.map +1 -1
- package/dist/cjs/user-profile.client.d.cts +4 -3
- package/dist/cjs/user-security.client.cjs +27 -10
- package/dist/cjs/user-security.client.cjs.map +1 -1
- package/dist/cjs/user-security.client.d.cts +3 -2
- package/dist/cjs/user-sessions.client.cjs +34 -16
- package/dist/cjs/user-sessions.client.cjs.map +1 -1
- package/dist/cjs/user-sessions.client.d.cts +4 -2
- package/dist/cjs/users-management.client.cjs +35 -18
- package/dist/cjs/users-management.client.cjs.map +1 -1
- package/dist/cjs/users-management.client.d.cts +3 -2
- package/dist/cjs/workos-widgets.client.cjs +7 -12
- package/dist/cjs/workos-widgets.client.cjs.map +1 -1
- package/dist/css/lib/provider-icon.css +16 -11
- package/dist/esm/admin-portal-domain-verification.client.d.ts +3 -2
- package/dist/esm/admin-portal-domain-verification.client.js +31 -17
- package/dist/esm/admin-portal-domain-verification.client.js.map +1 -1
- package/dist/esm/admin-portal-sso-connection.client.d.ts +16 -0
- package/dist/esm/{admin-portal-sso-connection-client.js → admin-portal-sso-connection.client.js} +57 -31
- package/dist/esm/admin-portal-sso-connection.client.js.map +1 -0
- package/dist/esm/api/api-provider.d.ts +1 -1
- package/dist/esm/api/api-provider.js +1 -1
- package/dist/esm/api/api-provider.js.map +1 -1
- package/dist/esm/api/endpoint.d.ts +62 -1
- package/dist/esm/api/endpoint.js +56 -2
- package/dist/esm/api/endpoint.js.map +1 -1
- package/dist/esm/api-keys.client.d.ts +15 -0
- package/dist/esm/api-keys.client.js +75 -0
- package/dist/esm/api-keys.client.js.map +1 -0
- package/dist/esm/index.d.ts +6 -2
- package/dist/esm/index.js +9 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/admin-portal-domain-verification.d.ts +10 -6
- package/dist/esm/lib/admin-portal-domain-verification.js +33 -34
- package/dist/esm/lib/admin-portal-domain-verification.js.map +1 -1
- package/dist/esm/lib/admin-portal-sso-connection.d.ts +13 -6
- package/dist/esm/lib/admin-portal-sso-connection.js +83 -80
- package/dist/esm/lib/admin-portal-sso-connection.js.map +1 -1
- package/dist/esm/lib/api-keys/api-keys.d.ts +16 -8
- package/dist/esm/lib/api-keys/api-keys.js +69 -54
- package/dist/esm/lib/api-keys/api-keys.js.map +1 -1
- package/dist/esm/lib/constants.d.ts +2 -1
- package/dist/esm/lib/constants.js +3 -1
- package/dist/esm/lib/constants.js.map +1 -1
- package/dist/esm/lib/elevated-access.js.map +1 -1
- package/dist/esm/lib/empty-state.d.ts +6 -2
- package/dist/esm/lib/empty-state.js +24 -8
- package/dist/esm/lib/empty-state.js.map +1 -1
- package/dist/esm/lib/generic-error.d.ts +5 -2
- package/dist/esm/lib/generic-error.js +33 -24
- package/dist/esm/lib/generic-error.js.map +1 -1
- package/dist/esm/lib/identity-providers.d.ts +2 -2
- package/dist/esm/lib/identity-providers.js +2 -1
- package/dist/esm/lib/identity-providers.js.map +1 -1
- package/dist/esm/lib/oauth-icons.d.ts +7 -3
- package/dist/esm/lib/oauth-icons.js +11 -6
- package/dist/esm/lib/oauth-icons.js.map +1 -1
- package/dist/esm/lib/organization-switcher.d.ts +12 -9
- package/dist/esm/lib/organization-switcher.js +54 -9
- package/dist/esm/lib/organization-switcher.js.map +1 -1
- package/dist/esm/lib/otp-input.js +1 -1
- package/dist/esm/lib/otp-input.js.map +1 -1
- package/dist/esm/lib/pipes.d.ts +19 -0
- package/dist/esm/lib/pipes.js +334 -0
- package/dist/esm/lib/pipes.js.map +1 -0
- package/dist/esm/lib/provider-icon.d.ts +4 -1
- package/dist/esm/lib/provider-icon.js +0 -8
- package/dist/esm/lib/provider-icon.js.map +1 -1
- package/dist/esm/lib/save-button.js.map +1 -1
- package/dist/esm/lib/user-profile.d.ts +11 -7
- package/dist/esm/lib/user-profile.js +82 -75
- package/dist/esm/lib/user-profile.js.map +1 -1
- package/dist/esm/lib/user-security.d.ts +10 -7
- package/dist/esm/lib/user-security.js +34 -25
- package/dist/esm/lib/user-security.js.map +1 -1
- package/dist/esm/lib/user-sessions.d.ts +10 -6
- package/dist/esm/lib/user-sessions.js +20 -9
- package/dist/esm/lib/user-sessions.js.map +1 -1
- package/dist/esm/lib/users-management.d.ts +10 -7
- package/dist/esm/lib/users-management.js +230 -217
- package/dist/esm/lib/users-management.js.map +1 -1
- package/dist/esm/lib/utils.d.ts +29 -2
- package/dist/esm/lib/utils.js +46 -1
- package/dist/esm/lib/utils.js.map +1 -1
- package/dist/esm/organization-switcher.client.d.ts +2 -1
- package/dist/esm/organization-switcher.client.js +44 -16
- package/dist/esm/organization-switcher.client.js.map +1 -1
- package/dist/esm/pipes.client.d.ts +15 -0
- package/dist/esm/pipes.client.js +42 -0
- package/dist/esm/pipes.client.js.map +1 -0
- package/dist/esm/user-profile.client.d.ts +4 -3
- package/dist/esm/user-profile.client.js +26 -10
- package/dist/esm/user-profile.client.js.map +1 -1
- package/dist/esm/user-security.client.d.ts +3 -2
- package/dist/esm/user-security.client.js +26 -10
- package/dist/esm/user-security.client.js.map +1 -1
- package/dist/esm/user-sessions.client.d.ts +4 -2
- package/dist/esm/user-sessions.client.js +33 -16
- package/dist/esm/user-sessions.client.js.map +1 -1
- package/dist/esm/users-management.client.d.ts +3 -2
- package/dist/esm/users-management.client.js +34 -18
- package/dist/esm/users-management.client.js.map +1 -1
- package/dist/esm/workos-widgets.client.js +7 -12
- package/dist/esm/workos-widgets.client.js.map +1 -1
- package/package.json +17 -10
- package/dist/cjs/admin-portal-sso-connection-client.cjs.map +0 -1
- package/dist/cjs/admin-portal-sso-connection-client.d.cts +0 -12
- package/dist/cjs/api-keys-client.cjs.map +0 -1
- package/dist/cjs/api-keys-client.d.cts +0 -10
- package/dist/esm/admin-portal-sso-connection-client.d.ts +0 -12
- package/dist/esm/admin-portal-sso-connection-client.js.map +0 -1
- package/dist/esm/api-keys-client.d.ts +0 -10
- package/dist/esm/api-keys-client.js +0 -60
- package/dist/esm/api-keys-client.js.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { OrganizationInfo
|
|
2
|
+
import { OrganizationInfo } from '../api/endpoint.cjs';
|
|
3
|
+
import { WidgetRootDomProps } from './utils.cjs';
|
|
3
4
|
import '@tanstack/react-query';
|
|
4
5
|
import '../api/widgets-api-client.cjs';
|
|
5
6
|
|
|
6
7
|
type OrganizationSwitcherVariant = "ghost" | "outline";
|
|
7
|
-
|
|
8
|
+
interface OrganizationSwitcherPassthroughProps extends WidgetRootDomProps {
|
|
8
9
|
switchToOrganization: ({ organizationId, }: {
|
|
9
10
|
organizationId: string;
|
|
10
11
|
}) => void;
|
|
@@ -20,15 +21,17 @@ type OrganizationSwitcherPassthroughProps = {
|
|
|
20
21
|
* words whole
|
|
21
22
|
*/
|
|
22
23
|
truncateBehavior?: "right" | "middle";
|
|
23
|
-
}
|
|
24
|
+
}
|
|
24
25
|
interface OrganizationSwitcherProps extends OrganizationSwitcherPassthroughProps {
|
|
25
26
|
organizations: OrganizationInfo[];
|
|
26
27
|
}
|
|
27
|
-
declare const OrganizationSwitcher:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
declare const OrganizationSwitcher: React.FC<OrganizationSwitcherProps>;
|
|
29
|
+
interface OrganizationSwitcherLoadingProps extends WidgetRootDomProps {
|
|
30
|
+
}
|
|
31
|
+
declare const OrganizationSwitcherLoading: React.FC<OrganizationSwitcherLoadingProps>;
|
|
32
|
+
interface OrganizationSwitcherErrorProps extends WidgetRootDomProps {
|
|
33
|
+
error: unknown;
|
|
31
34
|
}
|
|
32
|
-
declare function OrganizationSwitcherError(
|
|
35
|
+
declare function OrganizationSwitcherError({ error, ...domProps }: OrganizationSwitcherErrorProps): react_jsx_runtime.JSX.Element;
|
|
33
36
|
|
|
34
|
-
export { OrganizationSwitcher, OrganizationSwitcherError, OrganizationSwitcherLoading, type OrganizationSwitcherPassthroughProps, type OrganizationSwitcherProps };
|
|
37
|
+
export { OrganizationSwitcher, OrganizationSwitcherError, type OrganizationSwitcherErrorProps, OrganizationSwitcherLoading, type OrganizationSwitcherLoadingProps, type OrganizationSwitcherPassthroughProps, type OrganizationSwitcherProps };
|
|
@@ -59,7 +59,7 @@ const Root = React.forwardRef(
|
|
|
59
59
|
const childCount = React.Children.count(children);
|
|
60
60
|
const [value, setValue] = (0, import_react_use_controllable_state.useControllableState)({
|
|
61
61
|
prop: getValueAsArray(valueProp, childCount),
|
|
62
|
-
defaultProp: getValueAsArray(defaultValue, childCount),
|
|
62
|
+
defaultProp: getValueAsArray(defaultValue, childCount) ?? [],
|
|
63
63
|
onChange: (value2) => onValueChange?.(value2.join(""))
|
|
64
64
|
});
|
|
65
65
|
const hiddenInputRef = React.useRef(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/otp-input.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeRefs, useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport * as Form from \"@radix-ui/react-form\";\nimport { Grid } from \"@radix-ui/themes\";\nimport * as React from \"react\";\nimport { TextField } from \"./elements.js\";\n\ninterface OptContextType {\n value: string[];\n readOnly?: boolean;\n state?: \"valid\" | \"invalid\";\n onEnterPressed: () => void;\n onChildAdd: (input: HTMLInputElement) => void;\n onCharChange: (char: string, index: number) => void;\n allChildrenAdded: boolean;\n}\n\nconst OtpContext = React.createContext<OptContextType | undefined>(undefined);\n\ntype OtpRootProps = React.ComponentPropsWithoutRef<typeof Grid> & {\n onValueChange?: (value: string) => void;\n id?: string;\n name?: string;\n readOnly?: boolean;\n state?: \"valid\" | \"invalid\";\n value?: string;\n defaultValue?: string;\n autoSubmit?: boolean;\n};\n\nexport const Root = React.forwardRef<HTMLInputElement, OtpRootProps>(\n function Root(\n {\n name,\n id,\n defaultValue,\n value: valueProp,\n onValueChange,\n autoSubmit,\n children,\n readOnly,\n state,\n ...gridProps\n },\n forwardedRef,\n ) {\n const [lastCharIndex, setLastCharIndex] = React.useState<number>(0);\n const [allChildrenAdded, setAllChildrenAdded] =\n React.useState<boolean>(false);\n const childCount = React.Children.count(children);\n\n const [value, setValue] = useControllableState({\n prop: getValueAsArray(valueProp, childCount),\n defaultProp: getValueAsArray(defaultValue, childCount),\n onChange: (value) => onValueChange?.(value.join(\"\")),\n });\n\n const hiddenInputRef = React.useRef<HTMLInputElement>(null);\n const childrenRefs = React.useRef<HTMLInputElement[]>([]);\n\n const attemptAutoSubmit = React.useCallback(\n (enterPressed = false) => {\n if (\n autoSubmit &&\n value &&\n value.every((char) => char !== \"\") &&\n (enterPressed || lastCharIndex + 1 === childCount)\n ) {\n hiddenInputRef.current?.form?.requestSubmit();\n }\n },\n [value, childCount, lastCharIndex, autoSubmit],\n );\n\n const handleEnterPressed = React.useCallback(\n () => attemptAutoSubmit(true),\n [attemptAutoSubmit],\n );\n\n const handleChildAdd = React.useCallback(\n (input: HTMLInputElement) => {\n if (input) {\n input.dataset.index = `${childrenRefs.current.length}`;\n childrenRefs.current.push(input);\n } else {\n childrenRefs.current.pop();\n }\n\n if (childrenRefs.current.length === childCount) {\n setAllChildrenAdded(true);\n }\n },\n [childCount],\n );\n\n const handleCharChange = React.useCallback(\n (char: string, index: number) => {\n setValue((previousValue) => {\n const arrayToCopy = previousValue ?? createEmptyArray(childCount);\n const newValue = [...arrayToCopy];\n newValue[index] = char;\n return newValue;\n });\n setLastCharIndex(index);\n },\n [childCount, setValue],\n );\n\n const otpContext = React.useMemo(\n () => ({\n value: value ?? createEmptyArray(childCount),\n readOnly,\n state,\n allChildrenAdded,\n onEnterPressed: handleEnterPressed,\n onChildAdd: handleChildAdd,\n onCharChange: handleCharChange,\n }),\n [\n value,\n allChildrenAdded,\n readOnly,\n state,\n childCount,\n handleEnterPressed,\n handleChildAdd,\n handleCharChange,\n ],\n );\n\n React.useEffect(attemptAutoSubmit, [attemptAutoSubmit]);\n\n return (\n <OtpContext.Provider value={otpContext}>\n <Grid\n columns={`repeat(${childCount}, 1fr)`}\n {...gridProps}\n onPaste={(event: React.ClipboardEvent<HTMLDivElement>) => {\n event.preventDefault();\n const pastedValue = event.clipboardData.getData(\"Text\");\n const sanitizedValue = pastedValue\n .replace(/[^\\d]/g, \"\")\n .slice(0, childCount);\n const value = sanitizedValue\n .padEnd(childCount, \"#\")\n .split(\"\")\n .map((char) => (char === \"#\" ? \"\" : char));\n\n setValue(value);\n setLastCharIndex(sanitizedValue.length - 1);\n\n const index = Math.min(sanitizedValue.length, childCount - 1);\n childrenRefs.current?.[index]?.focus();\n }}\n >\n {children}\n <input\n ref={composeRefs(forwardedRef, hiddenInputRef)}\n defaultValue={value?.join(\"\")}\n minLength={childCount}\n name={name}\n type=\"hidden\"\n />\n </Grid>\n </OtpContext.Provider>\n );\n },\n);\n\ninterface InputProps extends React.ComponentProps<typeof TextField> {\n autoComplete?: \"one-time-code\" | \"off\";\n}\n\nexport const Input = React.forwardRef<HTMLInputElement, InputProps>(\n function Input(\n { style, readOnly, autoComplete = \"off\", ...props },\n forwardedRef,\n ) {\n const otpContext = useOptContext();\n const inputRef = React.useRef<HTMLInputElement>(null);\n const composedInputRef = useComposedRefs(\n forwardedRef,\n inputRef,\n otpContext.onChildAdd,\n );\n\n const index = Number(inputRef.current?.dataset.index ?? -1);\n const char = otpContext.value[index] ?? \"\";\n\n return (\n <Form.Field name={`otp-${index}`} asChild>\n <Form.Control asChild>\n <TextField\n ref={composedInputRef}\n autoComplete={index === 0 ? autoComplete : \"off\"}\n color={otpContext.state === \"invalid\" ? \"red\" : undefined}\n inputMode=\"numeric\"\n maxLength={1}\n pattern=\"\\d{1}\"\n readOnly={readOnly ?? otpContext.readOnly}\n size=\"3\"\n value={char}\n variant={otpContext.state === \"invalid\" ? \"soft\" : undefined}\n style={{\n ...style,\n height: \"auto\",\n \"--text-field-padding\": 0,\n textAlign: \"center\",\n }}\n onChange={(event) => {\n // Only update the value if it matches the input pattern (number only)\n if (event.target.validity.valid) {\n const char = event.target.value;\n const index = Number(event.target.dataset.index ?? -1);\n otpContext.onCharChange(char, index);\n if (char !== \"\") {\n focusSibling(event.currentTarget, { back: char === \"\" });\n }\n }\n }}\n onKeyDown={(event) => {\n if (event.key === \"ArrowLeft\") {\n focusSibling(event.currentTarget, { back: true });\n event.preventDefault();\n } else if (event.key === \"ArrowRight\") {\n focusSibling(event.currentTarget);\n event.preventDefault();\n } else if (event.key === \"Backspace\" && char === \"\") {\n focusSibling(event.currentTarget, { back: true });\n } else if (event.key === \"Enter\" && char !== \"\") {\n otpContext.onEnterPressed();\n }\n }}\n {...props}\n />\n </Form.Control>\n </Form.Field>\n );\n },\n);\n\nconst useOptContext = () => {\n const optContext = React.useContext(OtpContext);\n\n if (!optContext) {\n throw new Error(\n \"OtpInput compound components cannot be rendered outside the OtpRoot component\",\n );\n }\n\n return optContext;\n};\n\nfunction focusSibling(input: HTMLInputElement, { back = false } = {}) {\n const sibling = back\n ? input.parentElement?.previousSibling\n : input.parentElement?.nextSibling;\n const siblingInput = sibling?.firstChild;\n if (siblingInput && siblingInput instanceof HTMLInputElement) {\n siblingInput?.focus();\n siblingInput?.select();\n }\n}\n\nconst getValueAsArray = (value: string | undefined, length: number) => {\n if (!value) {\n return undefined;\n }\n\n return createEmptyArray(length).map((_, index) => value?.[index] ?? \"\");\n};\n\nconst createEmptyArray = (length: number): string[] =>\n Array.from<string>({ length }).fill(\"\");\n"],"mapp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AAA,EACvB;AACF;AAEA,MAAM,kBAAkB,CAAC,OAA2B,WAAmB;AACrE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,SAAO,iBAAiB,MAAM,EAAE,IAAI,CAAC,GAAG,UAAU,QAAQ,KAAK,KAAK,EAAE;AACxE;AAEA,MAAM,mBAAmB,CAAC,WACxB,MAAM,KAAa,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE;","names":["Root","value","Input","char","index"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/otp-input.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeRefs, useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport * as Form from \"@radix-ui/react-form\";\nimport { Grid } from \"@radix-ui/themes\";\nimport * as React from \"react\";\nimport { TextField } from \"./elements.js\";\n\ninterface OptContextType {\n value: string[];\n readOnly?: boolean;\n state?: \"valid\" | \"invalid\";\n onEnterPressed: () => void;\n onChildAdd: (input: HTMLInputElement) => void;\n onCharChange: (char: string, index: number) => void;\n allChildrenAdded: boolean;\n}\n\nconst OtpContext = React.createContext<OptContextType | undefined>(undefined);\n\ntype OtpRootProps = React.ComponentPropsWithoutRef<typeof Grid> & {\n onValueChange?: (value: string) => void;\n id?: string;\n name?: string;\n readOnly?: boolean;\n state?: \"valid\" | \"invalid\";\n value?: string;\n defaultValue?: string;\n autoSubmit?: boolean;\n};\n\nexport const Root = React.forwardRef<HTMLInputElement, OtpRootProps>(\n function Root(\n {\n name,\n id,\n defaultValue,\n value: valueProp,\n onValueChange,\n autoSubmit,\n children,\n readOnly,\n state,\n ...gridProps\n },\n forwardedRef,\n ) {\n const [lastCharIndex, setLastCharIndex] = React.useState<number>(0);\n const [allChildrenAdded, setAllChildrenAdded] =\n React.useState<boolean>(false);\n const childCount = React.Children.count(children);\n\n const [value, setValue] = useControllableState({\n prop: getValueAsArray(valueProp, childCount),\n defaultProp: getValueAsArray(defaultValue, childCount) ?? [],\n onChange: (value) => onValueChange?.(value.join(\"\")),\n });\n\n const hiddenInputRef = React.useRef<HTMLInputElement>(null);\n const childrenRefs = React.useRef<HTMLInputElement[]>([]);\n\n const attemptAutoSubmit = React.useCallback(\n (enterPressed = false) => {\n if (\n autoSubmit &&\n value &&\n value.every((char) => char !== \"\") &&\n (enterPressed || lastCharIndex + 1 === childCount)\n ) {\n hiddenInputRef.current?.form?.requestSubmit();\n }\n },\n [value, childCount, lastCharIndex, autoSubmit],\n );\n\n const handleEnterPressed = React.useCallback(\n () => attemptAutoSubmit(true),\n [attemptAutoSubmit],\n );\n\n const handleChildAdd = React.useCallback(\n (input: HTMLInputElement) => {\n if (input) {\n input.dataset.index = `${childrenRefs.current.length}`;\n childrenRefs.current.push(input);\n } else {\n childrenRefs.current.pop();\n }\n\n if (childrenRefs.current.length === childCount) {\n setAllChildrenAdded(true);\n }\n },\n [childCount],\n );\n\n const handleCharChange = React.useCallback(\n (char: string, index: number) => {\n setValue((previousValue) => {\n const arrayToCopy = previousValue ?? createEmptyArray(childCount);\n const newValue = [...arrayToCopy];\n newValue[index] = char;\n return newValue;\n });\n setLastCharIndex(index);\n },\n [childCount, setValue],\n );\n\n const otpContext = React.useMemo(\n () => ({\n value: value ?? createEmptyArray(childCount),\n readOnly,\n state,\n allChildrenAdded,\n onEnterPressed: handleEnterPressed,\n onChildAdd: handleChildAdd,\n onCharChange: handleCharChange,\n }),\n [\n value,\n allChildrenAdded,\n readOnly,\n state,\n childCount,\n handleEnterPressed,\n handleChildAdd,\n handleCharChange,\n ],\n );\n\n React.useEffect(attemptAutoSubmit, [attemptAutoSubmit]);\n\n return (\n <OtpContext.Provider value={otpContext}>\n <Grid\n columns={`repeat(${childCount}, 1fr)`}\n {...gridProps}\n onPaste={(event: React.ClipboardEvent<HTMLDivElement>) => {\n event.preventDefault();\n const pastedValue = event.clipboardData.getData(\"Text\");\n const sanitizedValue = pastedValue\n .replace(/[^\\d]/g, \"\")\n .slice(0, childCount);\n const value = sanitizedValue\n .padEnd(childCount, \"#\")\n .split(\"\")\n .map((char) => (char === \"#\" ? \"\" : char));\n\n setValue(value);\n setLastCharIndex(sanitizedValue.length - 1);\n\n const index = Math.min(sanitizedValue.length, childCount - 1);\n childrenRefs.current?.[index]?.focus();\n }}\n >\n {children}\n <input\n ref={composeRefs(forwardedRef, hiddenInputRef)}\n defaultValue={value?.join(\"\")}\n minLength={childCount}\n name={name}\n type=\"hidden\"\n />\n </Grid>\n </OtpContext.Provider>\n );\n },\n);\n\ninterface InputProps extends React.ComponentProps<typeof TextField> {\n autoComplete?: \"one-time-code\" | \"off\";\n}\n\nexport const Input = React.forwardRef<HTMLInputElement, InputProps>(\n function Input(\n { style, readOnly, autoComplete = \"off\", ...props },\n forwardedRef,\n ) {\n const otpContext = useOptContext();\n const inputRef = React.useRef<HTMLInputElement>(null);\n const composedInputRef = useComposedRefs(\n forwardedRef,\n inputRef,\n otpContext.onChildAdd,\n );\n\n // FIXME: This should be refactored\n // eslint-disable-next-line react-hooks/refs\n const index = Number(inputRef.current?.dataset.index ?? -1);\n const char = otpContext.value[index] ?? \"\";\n\n return (\n <Form.Field name={`otp-${index}`} asChild>\n <Form.Control asChild>\n <TextField\n ref={composedInputRef}\n autoComplete={index === 0 ? autoComplete : \"off\"}\n color={otpContext.state === \"invalid\" ? \"red\" : undefined}\n inputMode=\"numeric\"\n maxLength={1}\n pattern=\"\\d{1}\"\n readOnly={readOnly ?? otpContext.readOnly}\n size=\"3\"\n value={char}\n variant={otpContext.state === \"invalid\" ? \"soft\" : undefined}\n style={{\n ...style,\n height: \"auto\",\n \"--text-field-padding\": 0,\n textAlign: \"center\",\n }}\n onChange={(event) => {\n // Only update the value if it matches the input pattern (number only)\n if (event.target.validity.valid) {\n const char = event.target.value;\n const index = Number(event.target.dataset.index ?? -1);\n otpContext.onCharChange(char, index);\n if (char !== \"\") {\n focusSibling(event.currentTarget, { back: char === \"\" });\n }\n }\n }}\n onKeyDown={(event) => {\n if (event.key === \"ArrowLeft\") {\n focusSibling(event.currentTarget, { back: true });\n event.preventDefault();\n } else if (event.key === \"ArrowRight\") {\n focusSibling(event.currentTarget);\n event.preventDefault();\n } else if (event.key === \"Backspace\" && char === \"\") {\n focusSibling(event.currentTarget, { back: true });\n } else if (event.key === \"Enter\" && char !== \"\") {\n otpContext.onEnterPressed();\n }\n }}\n {...props}\n />\n </Form.Control>\n </Form.Field>\n );\n },\n);\n\nconst useOptContext = () => {\n const optContext = React.useContext(OtpContext);\n\n if (!optContext) {\n throw new Error(\n \"OtpInput compound components cannot be rendered outside the OtpRoot component\",\n );\n }\n\n return optContext;\n};\n\nfunction focusSibling(input: HTMLInputElement, { back = false } = {}) {\n const sibling = back\n ? input.parentElement?.previousSibling\n : input.parentElement?.nextSibling;\n const siblingInput = sibling?.firstChild;\n if (siblingInput && siblingInput instanceof HTMLInputElement) {\n siblingInput?.focus();\n siblingInput?.select();\n }\n}\n\nconst getValueAsArray = (value: string | undefined, length: number) => {\n if (!value) {\n return undefined;\n }\n\n return createEmptyArray(length).map((_, index) => value?.[index] ?? \"\");\n};\n\nconst createEmptyArray = (length: number): string[] =>\n Array.from<string>({ length }).fill(\"\");\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwIQ;AAtIR,gCAA6C;AAC7C,0CAAqC;AACrC,WAAsB;AACtB,oBAAqB;AACrB,YAAuB;AACvB,sBAA0B;AAY1B,MAAM,aAAa,MAAM,cAA0C,MAAS;AAarE,MAAM,OAAO,MAAM;AAAA,EACxB,SAASA,MACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,GACA,cACA;AACA,UAAM,CAAC,eAAe,gBAAgB,IAAI,MAAM,SAAiB,CAAC;AAClE,UAAM,CAAC,kBAAkB,mBAAmB,IAC1C,M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E,MAAM,KAAK,CAAC;AAChD,kBAAM,eAAe;AAAA,UACvB,WAAW,MAAM,QAAQ,cAAc;AACrC,yBAAa,MAAM,aAAa;AAChC,kBAAM,eAAe;AAAA,UACvB,WAAW,MAAM,QAAQ,eAAe,SAAS,IAAI;AACnD,yBAAa,MAAM,eAAe,EAAE,MAAM,KAAK,CAAC;AAAA,UAClD,WAAW,MAAM,QAAQ,WAAW,SAAS,IAAI;AAC/C,uBAAW,eAAe;AAAA,UAC5B;AAAA,QACF;AAAA,QACC,GAAG;AAAA;AAAA,IACN,GACF,GACF;AAAA,EAEJ;AACF;AAEA,MAAM,gBAAgB,MAAM;AAC1B,QAAM,aAAa,MAAM,WAAW,UAAU;AAE9C,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,aAAa,OAAyB,EAAE,OAAO,MAAM,IAAI,CAAC,GAAG;AACpE,QAAM,UAAU,OACZ,MAAM,eAAe,kBACrB,MAAM,eAAe;AACzB,QAAM,eAAe,SAAS;AAC9B,MAAI,gBAAgB,wBAAwB,kBAAkB;AAC5D,kBAAc,MAAM;AACpB,kBAAc,OAAO;AAAA,EACvB;AACF;AAEA,MAAM,kBAAkB,CAAC,OAA2B,WAAmB;AACrE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,SAAO,iBAAiB,MAAM,EAAE,IAAI,CAAC,GAAG,UAAU,QAAQ,KAAK,KAAK,EAAE;AACxE;AAEA,MAAM,mBAAmB,CAAC,WACxB,MAAM,KAAa,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE;","names":["Root","value","Input","char","index"]}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var pipes_exports = {};
|
|
31
|
+
__export(pipes_exports, {
|
|
32
|
+
Pipes: () => Pipes,
|
|
33
|
+
PipesError: () => PipesError,
|
|
34
|
+
PipesLoading: () => PipesLoading
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(pipes_exports);
|
|
37
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
+
var import_themes = require("@radix-ui/themes");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var CardList = __toESM(require("./card-list.js"), 1);
|
|
41
|
+
var import_provider_icon = require("./provider-icon.js");
|
|
42
|
+
var import_react_icons = require("@radix-ui/react-icons");
|
|
43
|
+
var import_elements = require("./elements.js");
|
|
44
|
+
var import_icon_panel = require("./icon-panel.js");
|
|
45
|
+
var import_status = require("./status.js");
|
|
46
|
+
var import_endpoint = require("../api/endpoint.js");
|
|
47
|
+
var import_react_query = require("@tanstack/react-query");
|
|
48
|
+
var import_generic_error = require("./generic-error.js");
|
|
49
|
+
var import_utils = require("./utils.js");
|
|
50
|
+
const useOpenDataIntegrationAuthorizeUrl = (integration) => {
|
|
51
|
+
const getDataIntegrationAuthorizeUrl = (0, import_endpoint.useGetDataIntegrationAuthorizeUrlHook)();
|
|
52
|
+
const settings = (0, import_endpoint.useSettings)();
|
|
53
|
+
const baseUrl = settings.data?.authkitOrigin ?? "";
|
|
54
|
+
return (0, import_react.useCallback)(async () => {
|
|
55
|
+
const win = window.open(`${baseUrl}/pipes/redirecting`, "_blank");
|
|
56
|
+
const { url } = await getDataIntegrationAuthorizeUrl(integration.slug);
|
|
57
|
+
if (win) {
|
|
58
|
+
win.location = url;
|
|
59
|
+
}
|
|
60
|
+
}, [getDataIntegrationAuthorizeUrl, integration.slug, baseUrl]);
|
|
61
|
+
};
|
|
62
|
+
function ConnectIntegrationButton({
|
|
63
|
+
integration
|
|
64
|
+
}) {
|
|
65
|
+
const eventHandler = useOpenDataIntegrationAuthorizeUrl(integration);
|
|
66
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
67
|
+
import_themes.Button,
|
|
68
|
+
{
|
|
69
|
+
onClick: async () => {
|
|
70
|
+
try {
|
|
71
|
+
await eventHandler();
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
variant: "outline",
|
|
76
|
+
size: "2",
|
|
77
|
+
color: "gray",
|
|
78
|
+
children: "Connect"
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
function SharedCredentialsConnectIntegrationButton({
|
|
83
|
+
integration
|
|
84
|
+
}) {
|
|
85
|
+
const settings = (0, import_endpoint.useSettings)();
|
|
86
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
87
|
+
const eventHandler = useOpenDataIntegrationAuthorizeUrl(integration);
|
|
88
|
+
const logo = settings.data?.logoDarkPath ?? settings.data?.logoLightPath;
|
|
89
|
+
const appName = settings.data?.teamName ?? "This application";
|
|
90
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
91
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Dialog.Root, { open, onOpenChange: setOpen, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Dialog.Content, { maxWidth: "430px", children: [
|
|
92
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { justify: "center", align: "center", gap: "2", mt: "2", children: [
|
|
93
|
+
logo && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
94
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
95
|
+
import_icon_panel.IconPanel,
|
|
96
|
+
{
|
|
97
|
+
color: "panel",
|
|
98
|
+
style: { width: "48px", height: "48px" },
|
|
99
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
100
|
+
import_provider_icon.ProviderIcon,
|
|
101
|
+
{
|
|
102
|
+
size: "2",
|
|
103
|
+
provider: "workos",
|
|
104
|
+
style: { backgroundImage: `url(${logo})` }
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icons.DotsHorizontalIcon, {})
|
|
110
|
+
] }),
|
|
111
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
112
|
+
import_icon_panel.IconPanel,
|
|
113
|
+
{
|
|
114
|
+
color: "panel",
|
|
115
|
+
style: {
|
|
116
|
+
...logo ? { borderWidth: 0 } : void 0,
|
|
117
|
+
width: "48px",
|
|
118
|
+
height: "48px"
|
|
119
|
+
},
|
|
120
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_provider_icon.ProviderIcon, { size: "2", provider: "workos" })
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icons.DotsHorizontalIcon, {}),
|
|
124
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon_panel.IconPanel, { color: "panel", style: { width: "48px", height: "48px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_provider_icon.ProviderIcon, { size: "2", provider: integration.integrationType }) })
|
|
125
|
+
] }),
|
|
126
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Dialog.Title, { size: "2", mt: "5", mb: "5", weight: "bold", align: "center", children: [
|
|
127
|
+
appName,
|
|
128
|
+
" uses WorkOS to connect to ",
|
|
129
|
+
integration.name,
|
|
130
|
+
"."
|
|
131
|
+
] }),
|
|
132
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Card, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { direction: "column", gap: "4", children: [
|
|
133
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { gap: "2", align: "center", children: [
|
|
134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
135
|
+
import_icon_panel.IconPanel,
|
|
136
|
+
{
|
|
137
|
+
color: "gray",
|
|
138
|
+
style: { width: "32px", height: "32px" },
|
|
139
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icons.GlobeIcon, {})
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { direction: "column", children: [
|
|
143
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Text, { size: "1", weight: "bold", children: [
|
|
144
|
+
"You'll be redirected to sign in with ",
|
|
145
|
+
integration.name,
|
|
146
|
+
"."
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Text, { size: "1", children: "Authorize access to connect your account." })
|
|
149
|
+
] })
|
|
150
|
+
] }),
|
|
151
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { gap: "2", align: "center", children: [
|
|
152
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
153
|
+
import_icon_panel.IconPanel,
|
|
154
|
+
{
|
|
155
|
+
color: "gray",
|
|
156
|
+
style: { width: "32px", height: "32px" },
|
|
157
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icons.LockClosedIcon, {})
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { direction: "column", children: [
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Text, { size: "1", weight: "bold", children: "Your credentials remain secure." }),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Text, { size: "1", children: "WorkOS never sees your credentials." })
|
|
163
|
+
] })
|
|
164
|
+
] })
|
|
165
|
+
] }) }),
|
|
166
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { justify: "end", gap: "3", mt: "5", children: [
|
|
167
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Dialog.Close, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_elements.SecondaryButton, { children: "Cancel" }) }),
|
|
168
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
169
|
+
import_elements.PrimaryButton,
|
|
170
|
+
{
|
|
171
|
+
onClick: async () => {
|
|
172
|
+
try {
|
|
173
|
+
await eventHandler();
|
|
174
|
+
setOpen(false);
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
children: [
|
|
179
|
+
"Connect ",
|
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icons.ExternalLinkIcon, {})
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
] })
|
|
185
|
+
] }) }),
|
|
186
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
187
|
+
import_themes.Button,
|
|
188
|
+
{
|
|
189
|
+
onClick: () => setOpen(true),
|
|
190
|
+
variant: "outline",
|
|
191
|
+
size: "2",
|
|
192
|
+
color: "gray",
|
|
193
|
+
children: "Connect"
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
] });
|
|
197
|
+
}
|
|
198
|
+
function ProviderStatus({ integration }) {
|
|
199
|
+
const [disconnectOpen, setDisconnectOpen] = (0, import_react.useState)(false);
|
|
200
|
+
const authorizeEventHandler = useOpenDataIntegrationAuthorizeUrl(integration);
|
|
201
|
+
if (integration.installation) {
|
|
202
|
+
const text = integration.installation.state === import_endpoint.DataInstallationState.connected ? "Connected" : "Requires reauthorization";
|
|
203
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
204
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
205
|
+
DisconnectAccountDialog,
|
|
206
|
+
{
|
|
207
|
+
integration,
|
|
208
|
+
installation: integration.installation,
|
|
209
|
+
open: disconnectOpen,
|
|
210
|
+
onOpenChange: setDisconnectOpen
|
|
211
|
+
}
|
|
212
|
+
),
|
|
213
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
214
|
+
import_status.Status,
|
|
215
|
+
{
|
|
216
|
+
state: integration.installation.state === import_endpoint.DataInstallationState.connected ? "success" : "error",
|
|
217
|
+
children: text
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.DropdownMenu.Root, { children: [
|
|
221
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.DropdownMenu.Trigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
222
|
+
import_themes.IconButton,
|
|
223
|
+
{
|
|
224
|
+
radius: "full",
|
|
225
|
+
variant: "ghost",
|
|
226
|
+
color: "gray",
|
|
227
|
+
title: "Pipe actions",
|
|
228
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icons.DotsHorizontalIcon, {})
|
|
229
|
+
}
|
|
230
|
+
) }),
|
|
231
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.DropdownMenu.Content, { align: "end", children: [
|
|
232
|
+
integration.installation.state === import_endpoint.DataInstallationState.needs_reauthorization && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
233
|
+
import_themes.DropdownMenu.Item,
|
|
234
|
+
{
|
|
235
|
+
onClick: async () => {
|
|
236
|
+
try {
|
|
237
|
+
await authorizeEventHandler();
|
|
238
|
+
} catch {
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { gap: "4", width: "100%", justify: "between", align: "center", children: [
|
|
242
|
+
"Reauthorize",
|
|
243
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icons.ExternalLinkIcon, {})
|
|
244
|
+
] })
|
|
245
|
+
}
|
|
246
|
+
),
|
|
247
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_elements.DestructiveMenuItem, { onClick: () => setDisconnectOpen(true), children: "Disconnect account" })
|
|
248
|
+
] })
|
|
249
|
+
] })
|
|
250
|
+
] });
|
|
251
|
+
}
|
|
252
|
+
if (integration.credentialsType === "shared") {
|
|
253
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SharedCredentialsConnectIntegrationButton, { integration });
|
|
254
|
+
}
|
|
255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConnectIntegrationButton, { integration });
|
|
256
|
+
}
|
|
257
|
+
function DisconnectAccountDialog({
|
|
258
|
+
integration,
|
|
259
|
+
installation,
|
|
260
|
+
open,
|
|
261
|
+
onOpenChange
|
|
262
|
+
}) {
|
|
263
|
+
const queryClient = (0, import_react_query.useQueryClient)();
|
|
264
|
+
const {
|
|
265
|
+
mutate: deleteDataInstallation,
|
|
266
|
+
error,
|
|
267
|
+
reset,
|
|
268
|
+
isPending
|
|
269
|
+
} = (0, import_endpoint.useDeleteDataInstallation)({
|
|
270
|
+
mutation: {
|
|
271
|
+
onSuccess: () => {
|
|
272
|
+
onOpenChange(false);
|
|
273
|
+
queryClient.invalidateQueries({
|
|
274
|
+
queryKey: (0, import_endpoint.getMyDataIntegrationsQueryKey)()
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
(0, import_react.useEffect)(() => {
|
|
280
|
+
if (open) {
|
|
281
|
+
reset();
|
|
282
|
+
}
|
|
283
|
+
}, [open, reset]);
|
|
284
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.AlertDialog.Root, { open, onOpenChange, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.AlertDialog.Content, { style: { width: "80vw", maxWidth: "520px" }, children: [
|
|
285
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.AlertDialog.Title, { children: "Disconnect account" }),
|
|
286
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Callout.Root, { my: "5", color: "red", role: "alert", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Callout.Text, { children: "An error occurred while disconnecting your account. Please refresh the page and try again." }) }),
|
|
287
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.AlertDialog.Description, { children: [
|
|
288
|
+
"Are you sure you want to disconnect your",
|
|
289
|
+
" ",
|
|
290
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Text, { as: "span", weight: "bold", children: integration.name }),
|
|
291
|
+
" ",
|
|
292
|
+
"account?"
|
|
293
|
+
] }),
|
|
294
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { gap: "3", justify: "end", mt: "5", children: [
|
|
295
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.AlertDialog.Cancel, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_elements.SecondaryButton, { children: "Cancel" }) }),
|
|
296
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
297
|
+
import_elements.DestructiveButton,
|
|
298
|
+
{
|
|
299
|
+
disabled: isPending,
|
|
300
|
+
loading: isPending,
|
|
301
|
+
onClick: () => deleteDataInstallation({ installationId: installation.id }),
|
|
302
|
+
children: "Disconnect"
|
|
303
|
+
}
|
|
304
|
+
)
|
|
305
|
+
] })
|
|
306
|
+
] }) });
|
|
307
|
+
}
|
|
308
|
+
const PipesLoading = ({ count, ...domProps }) => {
|
|
309
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardList.Root, { ...getWidgetRootDomProps("loading", domProps), children: Array.from({ length: count }).map((_, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardList.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { direction: "row", justify: "between", align: "center", gap: "2", children: [
|
|
310
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { gap: "4", align: "center", children: [
|
|
311
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Skeleton, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon_panel.IconPanel, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_provider_icon.ProviderIcon, { provider: "google" }) }) }),
|
|
312
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Skeleton, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Text, { size: "2", weight: "bold", children: "Google Drive" }) })
|
|
313
|
+
] }),
|
|
314
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Skeleton, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Button, { disabled: true, children: "Connect" }) })
|
|
315
|
+
] }) }, index)) });
|
|
316
|
+
};
|
|
317
|
+
const Pipes = ({ integrations, ...domProps }) => {
|
|
318
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardList.Root, { ...getWidgetRootDomProps("resolved", domProps), children: integrations.map((integration) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardList.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { direction: "row", justify: "between", align: "center", gap: "2", children: [
|
|
319
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_themes.Flex, { gap: "4", align: "center", children: [
|
|
320
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon_panel.IconPanel, { color: "panel", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_provider_icon.ProviderIcon, { provider: integration.integrationType }) }),
|
|
321
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Text, { size: "2", weight: "bold", children: integration.name })
|
|
322
|
+
] }),
|
|
323
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProviderStatus, { integration })
|
|
324
|
+
] }) }, integration.id)) });
|
|
325
|
+
};
|
|
326
|
+
const PipesError = ({ error, ...domProps }) => {
|
|
327
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Card, { size: "2", ...getWidgetRootDomProps("error", domProps), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_generic_error.GenericError, { error }) });
|
|
328
|
+
};
|
|
329
|
+
function getWidgetRootDomProps(state, domProps) {
|
|
330
|
+
return (0, import_utils.getDomProps)({
|
|
331
|
+
...domProps,
|
|
332
|
+
isWidgetRoot: true,
|
|
333
|
+
widgetId: "pipes",
|
|
334
|
+
widgetState: state
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
338
|
+
0 && (module.exports = {
|
|
339
|
+
Pipes,
|
|
340
|
+
PipesError,
|
|
341
|
+
PipesLoading
|
|
342
|
+
});
|
|
343
|
+
//# sourceMappingURL=pipes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/pipes.tsx"],"sourcesContent":["\"use client\";\nimport {\n AlertDialog,\n Button,\n Callout,\n Card,\n Dialog,\n DropdownMenu,\n Flex,\n IconButton,\n Skeleton,\n Text,\n} from \"@radix-ui/themes\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport * as CardList from \"./card-list.js\";\nimport { ProviderIcon } from \"./provider-icon.js\";\nimport {\n DotsHorizontalIcon,\n ExternalLinkIcon,\n GlobeIcon,\n LockClosedIcon,\n} from \"@radix-ui/react-icons\";\nimport {\n DestructiveButton,\n DestructiveMenuItem,\n PrimaryButton,\n SecondaryButton,\n} from \"./elements.js\";\nimport { IconPanel } from \"./icon-panel.js\";\nimport { Status } from \"./status.js\";\nimport {\n DataIntegration,\n DataInstallation,\n useDeleteDataInstallation,\n useGetDataIntegrationAuthorizeUrlHook,\n getMyDataIntegrationsQueryKey,\n DataInstallationState,\n useSettings,\n} from \"../api/endpoint.js\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport { GenericError } from \"./generic-error.js\";\nimport { getDomProps, WidgetRootDomProps, WidgetRootState } from \"./utils.js\";\n\ninterface PipesProps extends WidgetRootDomProps {\n integrations: DataIntegration[];\n}\n\nconst useOpenDataIntegrationAuthorizeUrl = (integration: DataIntegration) => {\n const getDataIntegrationAuthorizeUrl =\n useGetDataIntegrationAuthorizeUrlHook();\n const settings = useSettings();\n const baseUrl = settings.data?.authkitOrigin ?? \"\";\n\n return useCallback(async () => {\n // need to do this synchronously in the event handler to avoid popup blocker notifications\n const win = window.open(`${baseUrl}/pipes/redirecting`, \"_blank\");\n // caller will catch\n const { url } = await getDataIntegrationAuthorizeUrl(integration.slug);\n if (win) {\n win.location = url;\n }\n }, [getDataIntegrationAuthorizeUrl, integration.slug, baseUrl]);\n};\n\nfunction ConnectIntegrationButton({\n integration,\n}: {\n integration: DataIntegration;\n}) {\n const eventHandler = useOpenDataIntegrationAuthorizeUrl(integration);\n\n return (\n <Button\n onClick={async () => {\n try {\n await eventHandler();\n } catch {\n // pass - error displayed in new tab\n }\n }}\n variant=\"outline\"\n size=\"2\"\n color=\"gray\"\n >\n Connect\n </Button>\n );\n}\n\nfunction SharedCredentialsConnectIntegrationButton({\n integration,\n}: {\n integration: DataIntegration;\n}) {\n const settings = useSettings();\n const [open, setOpen] = useState(false);\n const eventHandler = useOpenDataIntegrationAuthorizeUrl(integration);\n\n const logo = settings.data?.logoDarkPath ?? settings.data?.logoLightPath;\n const appName = settings.data?.teamName ?? \"This application\";\n\n return (\n <>\n <Dialog.Root open={open} onOpenChange={setOpen}>\n <Dialog.Content maxWidth=\"430px\">\n <Flex justify=\"center\" align=\"center\" gap=\"2\" mt=\"2\">\n {logo && (\n <>\n <IconPanel\n color=\"panel\"\n style={{ width: \"48px\", height: \"48px\" }}\n >\n <ProviderIcon\n size=\"2\"\n provider=\"workos\"\n style={{ backgroundImage: `url(${logo})` }}\n />\n </IconPanel>\n <DotsHorizontalIcon />\n </>\n )}\n <IconPanel\n color=\"panel\"\n style={{\n ...(logo ? { borderWidth: 0 } : undefined),\n width: \"48px\",\n height: \"48px\",\n }}\n >\n <ProviderIcon size=\"2\" provider=\"workos\" />\n </IconPanel>\n <DotsHorizontalIcon />\n <IconPanel color=\"panel\" style={{ width: \"48px\", height: \"48px\" }}>\n <ProviderIcon size=\"2\" provider={integration.integrationType} />\n </IconPanel>\n </Flex>\n <Dialog.Title size=\"2\" mt=\"5\" mb=\"5\" weight={\"bold\"} align=\"center\">\n {appName} uses WorkOS to connect to {integration.name}.\n </Dialog.Title>\n <Card>\n <Flex direction=\"column\" gap=\"4\">\n <Flex gap=\"2\" align=\"center\">\n <IconPanel\n color=\"gray\"\n style={{ width: \"32px\", height: \"32px\" }}\n >\n <GlobeIcon />\n </IconPanel>\n <Flex direction=\"column\">\n <Text size=\"1\" weight=\"bold\">\n You'll be redirected to sign in with {integration.name}\n .\n </Text>\n <Text size=\"1\">\n Authorize access to connect your account.\n </Text>\n </Flex>\n </Flex>\n <Flex gap=\"2\" align=\"center\">\n <IconPanel\n color=\"gray\"\n style={{ width: \"32px\", height: \"32px\" }}\n >\n <LockClosedIcon />\n </IconPanel>\n <Flex direction=\"column\">\n <Text size=\"1\" weight=\"bold\">\n Your credentials remain secure.\n </Text>\n <Text size=\"1\">WorkOS never sees your credentials.</Text>\n </Flex>\n </Flex>\n </Flex>\n </Card>\n <Flex justify=\"end\" gap=\"3\" mt=\"5\">\n <Dialog.Close>\n <SecondaryButton>Cancel</SecondaryButton>\n </Dialog.Close>\n <PrimaryButton\n onClick={async () => {\n try {\n await eventHandler();\n setOpen(false);\n } catch {\n // pass - error displayed in new tab\n }\n }}\n >\n Connect <ExternalLinkIcon />\n </PrimaryButton>\n </Flex>\n </Dialog.Content>\n </Dialog.Root>\n <Button\n onClick={() => setOpen(true)}\n variant=\"outline\"\n size=\"2\"\n color=\"gray\"\n >\n Connect\n </Button>\n </>\n );\n}\n\nfunction ProviderStatus({ integration }: { integration: DataIntegration }) {\n const [disconnectOpen, setDisconnectOpen] = useState(false);\n const authorizeEventHandler = useOpenDataIntegrationAuthorizeUrl(integration);\n\n if (integration.installation) {\n const text =\n integration.installation.state === DataInstallationState.connected\n ? \"Connected\"\n : \"Requires reauthorization\";\n\n return (\n <>\n <DisconnectAccountDialog\n integration={integration}\n installation={integration.installation}\n open={disconnectOpen}\n onOpenChange={setDisconnectOpen}\n />\n <Status\n state={\n integration.installation.state === DataInstallationState.connected\n ? \"success\"\n : \"error\"\n }\n >\n {text}\n </Status>\n <DropdownMenu.Root>\n <DropdownMenu.Trigger>\n <IconButton\n radius=\"full\"\n variant=\"ghost\"\n color=\"gray\"\n title=\"Pipe actions\"\n >\n <DotsHorizontalIcon />\n </IconButton>\n </DropdownMenu.Trigger>\n <DropdownMenu.Content align=\"end\">\n {integration.installation.state ===\n DataInstallationState.needs_reauthorization && (\n <DropdownMenu.Item\n onClick={async () => {\n try {\n await authorizeEventHandler();\n } catch {\n // pass - error displayed in new tab\n }\n }}\n >\n <Flex gap=\"4\" width=\"100%\" justify=\"between\" align=\"center\">\n Reauthorize\n <ExternalLinkIcon />\n </Flex>\n </DropdownMenu.Item>\n )}\n <DestructiveMenuItem onClick={() => setDisconnectOpen(true)}>\n Disconnect account\n </DestructiveMenuItem>\n </DropdownMenu.Content>\n </DropdownMenu.Root>\n </>\n );\n }\n\n if (integration.credentialsType === \"shared\") {\n return (\n <SharedCredentialsConnectIntegrationButton integration={integration} />\n );\n }\n\n return <ConnectIntegrationButton integration={integration} />;\n}\n\nfunction DisconnectAccountDialog({\n integration,\n installation,\n open,\n onOpenChange,\n}: {\n integration: DataIntegration;\n installation: DataInstallation;\n open: boolean;\n onOpenChange: (open: boolean) => void;\n}) {\n const queryClient = useQueryClient();\n const {\n mutate: deleteDataInstallation,\n error,\n reset,\n isPending,\n } = useDeleteDataInstallation({\n mutation: {\n onSuccess: () => {\n onOpenChange(false);\n queryClient.invalidateQueries({\n queryKey: getMyDataIntegrationsQueryKey(),\n });\n },\n },\n });\n\n useEffect(() => {\n if (open) {\n reset();\n }\n }, [open, reset]);\n\n return (\n <AlertDialog.Root open={open} onOpenChange={onOpenChange}>\n <AlertDialog.Content style={{ width: \"80vw\", maxWidth: \"520px\" }}>\n <AlertDialog.Title>Disconnect account</AlertDialog.Title>\n {error && (\n <Callout.Root my=\"5\" color=\"red\" role=\"alert\">\n <Callout.Text>\n An error occurred while disconnecting your account. Please refresh\n the page and try again.\n </Callout.Text>\n </Callout.Root>\n )}\n <AlertDialog.Description>\n Are you sure you want to disconnect your{\" \"}\n <Text as=\"span\" weight=\"bold\">\n {integration.name}\n </Text>{\" \"}\n account?\n </AlertDialog.Description>\n <Flex gap=\"3\" justify=\"end\" mt=\"5\">\n <AlertDialog.Cancel>\n <SecondaryButton>Cancel</SecondaryButton>\n </AlertDialog.Cancel>\n <DestructiveButton\n disabled={isPending}\n loading={isPending}\n onClick={() =>\n deleteDataInstallation({ installationId: installation.id })\n }\n >\n Disconnect\n </DestructiveButton>\n </Flex>\n </AlertDialog.Content>\n </AlertDialog.Root>\n );\n}\n\ninterface PipesLoadingProps extends WidgetRootDomProps {\n count: number;\n}\n\nconst PipesLoading: React.FC<PipesLoadingProps> = ({ count, ...domProps }) => {\n return (\n <CardList.Root {...getWidgetRootDomProps(\"loading\", domProps)}>\n {Array.from({ length: count }).map((_, index) => (\n <CardList.Item key={index}>\n <Flex direction=\"row\" justify=\"between\" align=\"center\" gap=\"2\">\n <Flex gap=\"4\" align=\"center\">\n <Skeleton>\n <IconPanel>\n <ProviderIcon provider=\"google\" />\n </IconPanel>\n </Skeleton>\n <Skeleton>\n <Text size=\"2\" weight=\"bold\">\n Google Drive\n </Text>\n </Skeleton>\n </Flex>\n <Skeleton>\n <Button disabled>Connect</Button>\n </Skeleton>\n </Flex>\n </CardList.Item>\n ))}\n </CardList.Root>\n );\n};\n\nconst Pipes: React.FC<PipesProps> = ({ integrations, ...domProps }) => {\n return (\n <CardList.Root {...getWidgetRootDomProps(\"resolved\", domProps)}>\n {integrations.map((integration) => (\n <CardList.Item key={integration.id}>\n <Flex direction=\"row\" justify=\"between\" align=\"center\" gap=\"2\">\n <Flex gap=\"4\" align=\"center\">\n <IconPanel color=\"panel\">\n <ProviderIcon provider={integration.integrationType} />\n </IconPanel>\n <Text size=\"2\" weight=\"bold\">\n {integration.name}\n </Text>\n </Flex>\n <ProviderStatus integration={integration} />\n </Flex>\n </CardList.Item>\n ))}\n </CardList.Root>\n );\n};\n\ninterface PipesErrorProps extends WidgetRootDomProps {\n error: unknown;\n}\n\nconst PipesError: React.FC<PipesErrorProps> = ({ error, ...domProps }) => {\n return (\n <Card size=\"2\" {...getWidgetRootDomProps(\"error\", domProps)}>\n <GenericError error={error} />\n </Card>\n );\n};\n\nfunction getWidgetRootDomProps(\n state: WidgetRootState,\n domProps: WidgetRootDomProps,\n) {\n return getDomProps({\n ...domProps,\n isWidgetRoot: true,\n widgetId: \"pipes\",\n widgetState: state,\n });\n}\n\nexport type { PipesProps, PipesLoadingProps, PipesErrorProps };\nexport { Pipes, PipesLoading, PipesError };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwEI;AAvEJ,oBAWO;AACP,mBAAiD;AACjD,eAA0B;AAC1B,2BAA6B;AAC7B,yBAKO;AACP,sBAKO;AACP,wBAA0B;AAC1B,oBAAuB;AACvB,sBAQO;AACP,yBAA+B;AAC/B,2BAA6B;AAC7B,mBAAiE;AAMjE,MAAM,qCAAqC,CAAC,gBAAiC;AAC3E,QAAM,qCACJ,uDAAsC;AACxC,QAAM,eAAW,6BAAY;AAC7B,QAAM,UAAU,SAAS,MAAM,iBAAiB;AAEhD,aAAO,0BAAY,YAAY;AAE7B,UAAM,MAAM,OAAO,KAAK,GAAG,OAAO,sBAAsB,QAAQ;AAEhE,UAAM,EAAE,IAAI,IAAI,MAAM,+BAA+B,YAAY,IAAI;AACrE,QAAI,KAAK;AACP,UAAI,WAAW;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,gCAAgC,YAAY,MAAM,OAAO,CAAC;AAChE;AAEA,SAAS,yBAAyB;AAAA,EAChC;AACF,GAEG;AACD,QAAM,eAAe,mCAAmC,WAAW;AAEnE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAS,YAAY;AACnB,YAAI;AACF,gBAAM,aAAa;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GACvD;AAAA,MACA,4CAAC,sBAAK,MAAK,KAAI,QAAO,QACnB,sBAAY,MACf;AAAA,OACF;AAAA,IACA,4CAAC,kBAAe,aAA0B;AAAA,KAC5C,KAXkB,YAAY,EAYhC,CACD,GACH;AAEJ;AAMA,MAAM,aAAwC,CAAC,EAAE,OAAO,GAAG,SAAS,MAAM;AACxE,SACE,4CAAC,sBAAK,MAAK,KAAK,GAAG,sBAAsB,SAAS,QAAQ,GACxD,sDAAC,qCAAa,OAAc,GAC9B;AAEJ;AAEA,SAAS,sBACP,OACA,UACA;AACA,aAAO,0BAAY;AAAA,IACjB,GAAG;AAAA,IACH,cAAc;AAAA,IACd,UAAU;AAAA,IACV,aAAa;AAAA,EACf,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataIntegration } from '../api/endpoint.cjs';
|
|
2
|
+
import { WidgetRootDomProps } from './utils.cjs';
|
|
3
|
+
import '@tanstack/react-query';
|
|
4
|
+
import '../api/widgets-api-client.cjs';
|
|
5
|
+
|
|
6
|
+
interface PipesProps extends WidgetRootDomProps {
|
|
7
|
+
integrations: DataIntegration[];
|
|
8
|
+
}
|
|
9
|
+
interface PipesLoadingProps extends WidgetRootDomProps {
|
|
10
|
+
count: number;
|
|
11
|
+
}
|
|
12
|
+
declare const PipesLoading: React.FC<PipesLoadingProps>;
|
|
13
|
+
declare const Pipes: React.FC<PipesProps>;
|
|
14
|
+
interface PipesErrorProps extends WidgetRootDomProps {
|
|
15
|
+
error: unknown;
|
|
16
|
+
}
|
|
17
|
+
declare const PipesError: React.FC<PipesErrorProps>;
|
|
18
|
+
|
|
19
|
+
export { Pipes, PipesError, type PipesErrorProps, PipesLoading, type PipesLoadingProps, type PipesProps };
|
|
@@ -36,7 +36,6 @@ var import_helpers = require("@radix-ui/themes/helpers");
|
|
|
36
36
|
var import_props = require("@radix-ui/themes/props");
|
|
37
37
|
var import_clsx = __toESM(require("clsx"), 1);
|
|
38
38
|
var React = __toESM(require("react"), 1);
|
|
39
|
-
var import_identity_providers = require("./identity-providers.js");
|
|
40
39
|
const ProviderIcon = React.forwardRef(
|
|
41
40
|
(props, forwardedRef) => {
|
|
42
41
|
const {
|
|
@@ -45,11 +44,6 @@ const ProviderIcon = React.forwardRef(
|
|
|
45
44
|
className,
|
|
46
45
|
...providerIconProps
|
|
47
46
|
} = (0, import_helpers.extractProps)(props, import_props.marginPropDefs);
|
|
48
|
-
if (!(0, import_identity_providers.isIdentityProvider)(provider)) {
|
|
49
|
-
throw new TypeError(
|
|
50
|
-
`ProviderIcon: "${provider}" is not a valid provider.`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
47
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
54
48
|
"div",
|
|
55
49
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/provider-icon.tsx"],"sourcesContent":["import { extractProps } from \"@radix-ui/themes/helpers\";\nimport { marginPropDefs, MarginProps } from \"@radix-ui/themes/props\";\nimport clsx from \"clsx\";\nimport * as React from \"react\";\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/provider-icon.tsx"],"sourcesContent":["import { extractProps } from \"@radix-ui/themes/helpers\";\nimport { marginPropDefs, type MarginProps } from \"@radix-ui/themes/props\";\nimport clsx from \"clsx\";\nimport * as React from \"react\";\nimport type { IdentityProvider } from \"./identity-providers.js\";\nimport type { DataIntegrationIntegrationType } from \"../api/endpoint.js\";\n\ninterface ProviderIconProps\n extends React.ComponentPropsWithRef<\"div\">,\n MarginProps {\n provider: IdentityProvider | keyof typeof DataIntegrationIntegrationType;\n size?: \"1\" | \"2\" | \"3\" | \"4\";\n}\n\nconst ProviderIcon = React.forwardRef<HTMLDivElement, ProviderIconProps>(\n (props, forwardedRef) => {\n const {\n provider,\n size = \"4\",\n className,\n ...providerIconProps\n } = extractProps(props, marginPropDefs);\n\n return (\n <div\n {...providerIconProps}\n ref={forwardedRef}\n className={clsx(\"woswidgets-provider-icon\", `size-${size}`, className)}\n data-provider={provider}\n />\n );\n },\n);\n\nProviderIcon.displayName = \"ProviderIcon\";\n\nexport { ProviderIcon };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBM;AAxBN,qBAA6B;AAC7B,mBAAiD;AACjD,kBAAiB;AACjB,YAAuB;AAWvB,MAAM,eAAe,MAAM;AAAA,EACzB,CAAC,OAAO,iBAAiB;AACvB,UAAM;AAAA,MACJ;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA,GAAG;AAAA,IACL,QAAI,6BAAa,OAAO,2BAAc;AAEtC,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK;AAAA,QACL,eAAW,YAAAA,SAAK,4BAA4B,QAAQ,IAAI,IAAI,SAAS;AAAA,QACrE,iBAAe;AAAA;AAAA,IACjB;AAAA,EAEJ;AACF;AAEA,aAAa,cAAc;","names":["clsx"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { MarginProps } from '@radix-ui/themes/props';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { IdentityProvider } from './identity-providers.cjs';
|
|
4
|
+
import { DataIntegrationIntegrationType } from '../api/endpoint.cjs';
|
|
5
|
+
import '@tanstack/react-query';
|
|
6
|
+
import '../api/widgets-api-client.cjs';
|
|
4
7
|
|
|
5
8
|
interface ProviderIconProps extends React.ComponentPropsWithRef<"div">, MarginProps {
|
|
6
|
-
provider: IdentityProvider;
|
|
9
|
+
provider: IdentityProvider | keyof typeof DataIntegrationIntegrationType;
|
|
7
10
|
size?: "1" | "2" | "3" | "4";
|
|
8
11
|
}
|
|
9
12
|
declare const ProviderIcon: React.ForwardRefExoticComponent<Omit<ProviderIconProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/save-button.tsx"],"sourcesContent":["import {\n ButtonProps,\n Flex,\n Slot,\n Slottable,\n Spinner,\n Text,\n} from \"@radix-ui/themes\";\nimport { CheckIcon } from \"@radix-ui/react-icons\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { namespaceClassNames } from \"./utils.js\";\n\nconst DONE_TIMEOUT_MS = 1500;\nconst SAVING_TIMEOUT_MS = 600;\n\ninterface SaveButtonProps extends ButtonProps {\n asChild?: boolean;\n children: React.ReactNode;\n loading?: boolean;\n done?: boolean;\n onDone?: () => void;\n}\n\nexport function SaveButton({\n asChild = false,\n children,\n loading,\n done,\n onDone,\n ...props\n}: SaveButtonProps) {\n const [state, setState] = useState<\"idle\" | \"loading\" | \"done\">(\n loading ? \"loading\" : done ? \"done\" : \"idle\",\n );\n const loadingStartTime = useRef<number | null>(null);\n const Button = asChild ? Slot : \"button\";\n\n useEffect(() => {\n if (loading) {\n setState(\"loading\");\n loadingStartTime.current = Date.now();\n } else if (done) {\n const currentTime = Date.now();\n const loadingDuration = loadingStartTime.current\n ? currentTime - loadingStartTime.current\n : 0;\n\n // If loading lasted less than 500 ms, wait for the remaining time\n const remainingDelay = Math.max(0, SAVING_TIMEOUT_MS - loadingDuration);\n\n let doneTimer: number | null = null;\n const savedTimer = window.setTimeout(() => {\n setState(\"done\");\n\n doneTimer = window.setTimeout(() => {\n onDone?.();\n }, DONE_TIMEOUT_MS);\n }, remainingDelay);\n\n return () => {\n window.clearTimeout(savedTimer);\n if (doneTimer !== null) {\n window.clearTimeout(doneTimer);\n }\n };\n } else if (!loading && !done) {\n setState(\"idle\");\n }\n }, [loading, done, onDone]);\n\n return (\n <Button\n {...props}\n className={namespaceClassNames(\"save-button\")}\n data-save-state={state}\n >\n <Slottable>{children}</Slottable>\n\n {state === \"loading\" && (\n <Flex\n as=\"span\"\n align=\"center\"\n justify=\"center\"\n position=\"absolute\"\n inset=\"0\"\n >\n <Spinner size=\"1\" />\n </Flex>\n )}\n\n {state === \"done\" && (\n <Flex\n as=\"span\"\n align=\"center\"\n justify=\"center\"\n position=\"absolute\"\n inset=\"0\"\n gap=\"1\"\n >\n <CheckIcon\n width=\"18px\"\n height=\"18px\"\n style={{ marginLeft: \"-4px\" }}\n className={namespaceClassNames(\"save-button__done-icon\")}\n />\n <Text className={namespaceClassNames(\"save-button__done-text\")}>\n Done\n </Text>\n </Flex>\n )}\n </Button>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/save-button.tsx"],"sourcesContent":["import {\n ButtonProps,\n Flex,\n Slot,\n Slottable,\n Spinner,\n Text,\n} from \"@radix-ui/themes\";\nimport { CheckIcon } from \"@radix-ui/react-icons\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { namespaceClassNames } from \"./utils.js\";\n\nconst DONE_TIMEOUT_MS = 1500;\nconst SAVING_TIMEOUT_MS = 600;\n\ninterface SaveButtonProps extends ButtonProps {\n asChild?: boolean;\n children: React.ReactNode;\n loading?: boolean;\n done?: boolean;\n onDone?: () => void;\n}\n\nexport function SaveButton({\n asChild = false,\n children,\n loading,\n done,\n onDone,\n ...props\n}: SaveButtonProps) {\n const [state, setState] = useState<\"idle\" | \"loading\" | \"done\">(\n loading ? \"loading\" : done ? \"done\" : \"idle\",\n );\n const loadingStartTime = useRef<number | null>(null);\n const Button = asChild ? Slot : \"button\";\n\n useEffect(() => {\n if (loading) {\n // FIXME: This should be refactored\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setState(\"loading\");\n loadingStartTime.current = Date.now();\n } else if (done) {\n const currentTime = Date.now();\n const loadingDuration = loadingStartTime.current\n ? currentTime - loadingStartTime.current\n : 0;\n\n // If loading lasted less than 500 ms, wait for the remaining time\n const remainingDelay = Math.max(0, SAVING_TIMEOUT_MS - loadingDuration);\n\n let doneTimer: number | null = null;\n const savedTimer = window.setTimeout(() => {\n setState(\"done\");\n\n doneTimer = window.setTimeout(() => {\n onDone?.();\n }, DONE_TIMEOUT_MS);\n }, remainingDelay);\n\n return () => {\n window.clearTimeout(savedTimer);\n if (doneTimer !== null) {\n window.clearTimeout(doneTimer);\n }\n };\n } else if (!loading && !done) {\n setState(\"idle\");\n }\n }, [loading, done, onDone]);\n\n return (\n <Button\n {...props}\n className={namespaceClassNames(\"save-button\")}\n data-save-state={state}\n >\n <Slottable>{children}</Slottable>\n\n {state === \"loading\" && (\n <Flex\n as=\"span\"\n align=\"center\"\n justify=\"center\"\n position=\"absolute\"\n inset=\"0\"\n >\n <Spinner size=\"1\" />\n </Flex>\n )}\n\n {state === \"done\" && (\n <Flex\n as=\"span\"\n align=\"center\"\n justify=\"center\"\n position=\"absolute\"\n inset=\"0\"\n gap=\"1\"\n >\n <CheckIcon\n width=\"18px\"\n height=\"18px\"\n style={{ marginLeft: \"-4px\" }}\n className={namespaceClassNames(\"save-button__done-icon\")}\n />\n <Text className={namespaceClassNames(\"save-button__done-text\")}>\n Done\n </Text>\n </Flex>\n )}\n </Button>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8EM;AA9EN,oBAOO;AACP,yBAA0B;AAC1B,mBAA4C;AAC5C,mBAAoC;AAEpC,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAUnB,SAAS,WAAW;AAAA,EACzB,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAoB;AAClB,QAAM,CAAC,OAAO,QAAQ,QAAI;AAAA,IACxB,UAAU,YAAY,OAAO,SAAS;AAAA,EACxC;AACA,QAAM,uBAAmB,qBAAsB,IAAI;AACnD,QAAM,SAAS,UAAU,qBAAO;AAEhC,8BAAU,MAAM;AACd,QAAI,SAAS;AAGX,eAAS,SAAS;AAClB,uBAAiB,UAAU,KAAK,IAAI;AAAA,IACtC,WAAW,MAAM;AACf,YAAM,cAAc,KAAK,IAAI;AAC7B,YAAM,kBAAkB,iBAAiB,UACrC,cAAc,iBAAiB,U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