@factorialco/fcode-react-forms 3.3.0 → 3.4.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/dist/components/json-schema-form/fcode-json-schema-form.d.ts +2 -1
- package/dist/components/json-schema-form/fields/index.d.ts +1 -0
- package/dist/components/json-schema-form/fields/oauth-field.d.ts +9 -0
- package/dist/components/json-schema-form/multistep/types.d.ts +2 -0
- package/dist/components/json-schema-form/oauth/default-connect-control.d.ts +8 -0
- package/dist/components/json-schema-form/oauth/index.d.ts +5 -0
- package/dist/components/json-schema-form/oauth/oauth-callback-page.test.d.ts +1 -0
- package/dist/components/json-schema-form/oauth/oauth-connect.d.ts +26 -0
- package/dist/components/json-schema-form/oauth/oauth-widget.d.ts +9 -0
- package/dist/components/json-schema-form/oauth/oauth-widget.test.d.ts +1 -0
- package/dist/components/json-schema-form/oauth/parse-oauth-options.d.ts +9 -0
- package/dist/components/json-schema-form/oauth/parse-oauth-options.test.d.ts +1 -0
- package/dist/components/json-schema-form/oauth/resolve-oauth-value.d.ts +8 -0
- package/dist/components/json-schema-form/oauth/resolve-oauth-value.test.d.ts +1 -0
- package/dist/components/json-schema-form/oauth/types.d.ts +78 -0
- package/dist/components/json-schema-form/oauth/use-oauth-flow.d.ts +12 -0
- package/dist/fcode-form.cjs.js +65 -65
- package/dist/fcode-form.cjs.js.map +1 -1
- package/dist/fcode-form.es.js +6564 -6178
- package/dist/fcode-form.es.js.map +1 -1
- package/dist/fcode-form.umd.js +78 -78
- package/dist/fcode-form.umd.js.map +1 -1
- package/dist/hooks/use-form-specs.d.ts +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/services/fcode.d.ts +1 -1
- package/dist/styles.css +32 -0
- package/dist/types.d.ts +5 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/is-http-url.d.ts +7 -0
- package/dist/utils/is-http-url.test.d.ts +1 -0
- package/dist/utils/oauth-popup.d.ts +30 -0
- package/dist/utils/oauth-popup.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -12,7 +12,8 @@ export interface FcodeJsonSchemaFormProps extends Omit<React.ComponentProps<type
|
|
|
12
12
|
* — e.g. `Theme` from `@factorialco/rjsf-f0` to render f0 components instead
|
|
13
13
|
* of the stylesheet-driven default theme. Individual `templates`, `widgets`
|
|
14
14
|
* and `fields` props still take precedence over the theme. A theme may also
|
|
15
|
-
* carry a `multistep` entry to restyle the `ui:steps` navigation
|
|
15
|
+
* carry a `multistep` entry to restyle the `ui:steps` navigation and an
|
|
16
|
+
* `oauth` entry to restyle the `ui:widget: "oauth"` connect control.
|
|
16
17
|
*/
|
|
17
18
|
rjsfTheme?: FcodeRjsfTheme;
|
|
18
19
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FieldProps } from '@rjsf/utils';
|
|
3
|
+
/**
|
|
4
|
+
* `ui:field: "oauth"` for object properties, whose value is every parameter
|
|
5
|
+
* the callback page received. RJSF ignores `ui:widget` on objects, and a custom
|
|
6
|
+
* field renders no label of its own, so the title and description are drawn
|
|
7
|
+
* with the same templates `ObjectField` uses.
|
|
8
|
+
*/
|
|
9
|
+
export declare const OauthField: (props: FieldProps) => React.JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { ThemeProps } from '@rjsf/core';
|
|
3
|
+
import { OauthThemeComponents } from '../oauth/types';
|
|
3
4
|
export type StepsLayout = 'tabs' | 'sidebar';
|
|
4
5
|
/** One step as authored in the schema's `ui['ui:steps'].steps` array. */
|
|
5
6
|
export interface StepDefinition {
|
|
@@ -51,4 +52,5 @@ export interface MultistepThemeComponents {
|
|
|
51
52
|
}
|
|
52
53
|
export type FcodeRjsfTheme = ThemeProps & {
|
|
53
54
|
multistep?: MultistepThemeComponents;
|
|
55
|
+
oauth?: OauthThemeComponents;
|
|
54
56
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { OauthConnectControlProps, OauthThemeComponents } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* The stylesheet-driven connect control. The class names are a contract with
|
|
5
|
+
* `styles/styles.css`; `type="button"` keeps it from submitting the form.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DefaultOauthConnectControl: ({ id, status, label, disabled, errorMessage, onClick, }: OauthConnectControlProps) => React.JSX.Element;
|
|
8
|
+
export declare const DefaultOauth: OauthThemeComponents;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { OauthWidget } from './oauth-widget';
|
|
2
|
+
export { OauthConnect } from './oauth-connect';
|
|
3
|
+
export { DefaultOauth } from './default-connect-control';
|
|
4
|
+
export { parseOauthOptions } from './parse-oauth-options';
|
|
5
|
+
export type { FcodeFormContext, OauthCompletionMessage, OauthConnectControlProps, OauthConnectStatus, OauthOnComplete, OauthResult, OauthThemeComponents, OauthWidgetConfig, } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Registry, UIOptionsType } from '@rjsf/utils';
|
|
3
|
+
import { JSONSchema7 } from '../../../types';
|
|
4
|
+
export interface OauthConnectProps {
|
|
5
|
+
id: string;
|
|
6
|
+
schema: JSONSchema7;
|
|
7
|
+
uiOptions: UIOptionsType | undefined;
|
|
8
|
+
registry: Registry;
|
|
9
|
+
value: unknown;
|
|
10
|
+
onChange: (value: unknown) => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The connect control's behaviour, shared by the `oauth` widget (string and
|
|
16
|
+
* boolean properties) and the `oauth` field (object properties). Rendering is
|
|
17
|
+
* delegated to the theme's `ConnectControl`, found through `formContext.fcode`.
|
|
18
|
+
*
|
|
19
|
+
* `onComplete: "submit"` and `"reload"` run from an effect rather than from
|
|
20
|
+
* the completion callback: the message arrives outside React's event system,
|
|
21
|
+
* and the submit must see the value RJSF has already committed. A failed
|
|
22
|
+
* attempt reloads straight away in every mode (there is no value to wait for,
|
|
23
|
+
* and the server has to mint a fresh authorization URL); a cancelled one only
|
|
24
|
+
* in `reload` mode.
|
|
25
|
+
*/
|
|
26
|
+
export declare const OauthConnect: ({ id, schema, uiOptions, registry, value, onChange, disabled, readonly, }: OauthConnectProps) => React.JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { WidgetProps } from '@rjsf/utils';
|
|
3
|
+
/**
|
|
4
|
+
* `ui:widget: "oauth"` for string and boolean properties. Being a widget, the
|
|
5
|
+
* label, description, required marker and validation errors come from the
|
|
6
|
+
* theme's `FieldTemplate`; object properties use the `oauth` field instead,
|
|
7
|
+
* since RJSF never consults `ui:widget` for objects.
|
|
8
|
+
*/
|
|
9
|
+
export declare const OauthWidget: ({ id, schema, options, registry, value, onChange, disabled, readonly, }: WidgetProps) => React.JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UIOptionsType } from '@rjsf/utils';
|
|
2
|
+
import { GenericObjectType, JSONSchema7 } from '../../../types';
|
|
3
|
+
import { OauthWidgetConfig } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Validates the schema-authored `ui:options` of an `oauth` field, in the same
|
|
6
|
+
* warn-and-degrade spirit as `ui:steps`: a bad option falls back to its
|
|
7
|
+
* default, and a bad URL disables the control rather than breaking the form.
|
|
8
|
+
*/
|
|
9
|
+
export declare const parseOauthOptions: (uiOptions: UIOptionsType | GenericObjectType | undefined, schema: JSONSchema7) => OauthWidgetConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OauthSuccess, OauthValueKind } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The value an `oauth` field takes after a successful flow, by property type:
|
|
4
|
+
* a boolean is simply `true`; a string takes the callback page's `value`
|
|
5
|
+
* (an opaque handle such as a connection id); an object takes every parameter
|
|
6
|
+
* the callback page received, minus the ones that describe the outcome.
|
|
7
|
+
*/
|
|
8
|
+
export declare const resolveOauthValue: (kind: OauthValueKind, result: OauthSuccess) => true | string | Record<string, string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type OauthOnComplete = 'none' | 'submit' | 'reload';
|
|
3
|
+
export type OauthValueKind = 'boolean' | 'string' | 'object';
|
|
4
|
+
export type OauthConnectStatus = 'idle' | 'pending' | 'connected';
|
|
5
|
+
/** A validated `ui:options` declaration for an `oauth` field. */
|
|
6
|
+
export interface OauthWidgetConfig {
|
|
7
|
+
/** `null` when missing or not an http(s) URL: the control renders disabled. */
|
|
8
|
+
authorizationUrl: string | null;
|
|
9
|
+
connectLabel: string;
|
|
10
|
+
connectedLabel: string;
|
|
11
|
+
pendingLabel: string;
|
|
12
|
+
onComplete: OauthOnComplete;
|
|
13
|
+
popup: {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
};
|
|
17
|
+
/** Milliseconds between the completion message and closing the popup. */
|
|
18
|
+
closeDelay: number;
|
|
19
|
+
valueKind: OauthValueKind;
|
|
20
|
+
}
|
|
21
|
+
/** What `oauth-callback.html` posts to the window that opened it. */
|
|
22
|
+
export interface OauthCompletionMessage {
|
|
23
|
+
source: 'fcode-forms';
|
|
24
|
+
type: 'oauth-completed';
|
|
25
|
+
status: 'success' | 'error';
|
|
26
|
+
value?: string;
|
|
27
|
+
message?: string;
|
|
28
|
+
/** Every query parameter the callback page received. */
|
|
29
|
+
params: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
export interface OauthOutcome {
|
|
32
|
+
status: 'success' | 'error';
|
|
33
|
+
value?: string;
|
|
34
|
+
message?: string;
|
|
35
|
+
params: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
export type OauthSuccess = OauthOutcome & {
|
|
38
|
+
status: 'success';
|
|
39
|
+
};
|
|
40
|
+
export type OauthResult = OauthOutcome | {
|
|
41
|
+
status: 'cancelled';
|
|
42
|
+
} | {
|
|
43
|
+
status: 'blocked';
|
|
44
|
+
};
|
|
45
|
+
export interface OauthConnectControlProps {
|
|
46
|
+
id: string;
|
|
47
|
+
status: OauthConnectStatus;
|
|
48
|
+
/** The label for the current status, resolved from the schema's options. */
|
|
49
|
+
label: string;
|
|
50
|
+
disabled: boolean;
|
|
51
|
+
errorMessage?: string;
|
|
52
|
+
/** Must be called synchronously from the click, or popup blockers step in. */
|
|
53
|
+
onClick: (event: React.MouseEvent<HTMLElement>) => void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The component a theme contributes to render the connect control. The flow
|
|
57
|
+
* itself (popup, completion message, form reaction) lives in the SDK.
|
|
58
|
+
*/
|
|
59
|
+
export interface OauthThemeComponents {
|
|
60
|
+
ConnectControl: React.ComponentType<OauthConnectControlProps>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* What `FcodeJsonSchemaForm` and `FcodeForm` place under `formContext.fcode`
|
|
64
|
+
* for the SDK's own widgets. Embedder-provided `formContext` keys are kept
|
|
65
|
+
* alongside it.
|
|
66
|
+
*/
|
|
67
|
+
export interface FcodeFormContext {
|
|
68
|
+
fcode?: {
|
|
69
|
+
oauth?: OauthThemeComponents;
|
|
70
|
+
/**
|
|
71
|
+
* Refetches the form specs bypassing the cache. The `oauth` widget calls
|
|
72
|
+
* it for `onComplete: "reload"` and after any failed attempt, so the
|
|
73
|
+
* server can mint a fresh authorization URL. `FcodeForm` provides it; an
|
|
74
|
+
* embedder rendering `FcodeJsonSchemaForm` itself can set its own.
|
|
75
|
+
*/
|
|
76
|
+
reloadFormSpecs?: () => void;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { OauthResult, OauthWidgetConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Drives one field's OAuth popup. `start` is synchronous on purpose: it has to
|
|
5
|
+
* run inside the click for popup blockers to allow the window, and f0's button
|
|
6
|
+
* treats a returned promise as a loading state. A click while the popup is
|
|
7
|
+
* open brings it back to the front instead of opening a second one.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useOauthFlow: (config: OauthWidgetConfig, id: string, onResult: (result: OauthResult) => void) => {
|
|
10
|
+
pending: boolean;
|
|
11
|
+
start: (event?: React.SyntheticEvent) => void;
|
|
12
|
+
};
|