@factorialco/fcode-react-forms 3.7.1 → 3.8.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.
Files changed (25) hide show
  1. package/dist/components/json-schema-form/employee-fallback-widget.d.ts +11 -0
  2. package/dist/components/json-schema-form/employee-fallback-widget.test.d.ts +1 -0
  3. package/dist/components/json-schema-form/fcode-json-schema-form.d.ts +3 -2
  4. package/dist/components/json-schema-form/fields/index.d.ts +1 -0
  5. package/dist/components/json-schema-form/fields/pairing-field.d.ts +13 -0
  6. package/dist/components/json-schema-form/fields/pairing-field.test.d.ts +1 -0
  7. package/dist/components/json-schema-form/flat-const-options.d.ts +3 -0
  8. package/dist/components/json-schema-form/multistep/types.d.ts +2 -0
  9. package/dist/components/json-schema-form/oauth/types.d.ts +6 -0
  10. package/dist/components/json-schema-form/pairing/index.d.ts +2 -0
  11. package/dist/components/json-schema-form/pairing/pairing-state.d.ts +48 -0
  12. package/dist/components/json-schema-form/pairing/pairing-state.test.d.ts +1 -0
  13. package/dist/components/json-schema-form/pairing/parse-pairing.d.ts +16 -0
  14. package/dist/components/json-schema-form/pairing/parse-pairing.test.d.ts +1 -0
  15. package/dist/components/json-schema-form/pairing/prepare-pairing-rows.d.ts +12 -0
  16. package/dist/components/json-schema-form/pairing/prepare-pairing-rows.test.d.ts +1 -0
  17. package/dist/components/json-schema-form/pairing/types.d.ts +123 -0
  18. package/dist/fcode-form.cjs.js +67 -67
  19. package/dist/fcode-form.cjs.js.map +1 -1
  20. package/dist/fcode-form.es.js +9507 -9191
  21. package/dist/fcode-form.es.js.map +1 -1
  22. package/dist/fcode-form.umd.js +68 -68
  23. package/dist/fcode-form.umd.js.map +1 -1
  24. package/dist/index.d.ts +1 -0
  25. package/package.json +1 -1
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+ import { WidgetProps } from '@rjsf/utils';
3
+ /**
4
+ * `ui:widget: "employee"` wherever the host has not registered its own. The
5
+ * real employee picker only exists inside Factorial, which registers it over
6
+ * this one; anywhere else (the hosted `forms.js`, other embedders) the field
7
+ * must still render instead of failing the whole form with `No widget
8
+ * "employee"`. A field that lists its choices gets the theme's select; one
9
+ * that does not shows a notice (`ui:options.unavailableMessage` overrides it).
10
+ */
11
+ export declare const EmployeeFallbackWidget: (props: WidgetProps) => React.JSX.Element;
@@ -17,8 +17,9 @@ export interface FcodeJsonSchemaFormProps extends Omit<React.ComponentProps<type
17
17
  * — e.g. `Theme` from `@factorialco/rjsf-f0` to render f0 components instead
18
18
  * of the stylesheet-driven default theme. Individual `templates`, `widgets`
19
19
  * and `fields` props still take precedence over the theme. A theme may also
20
- * carry a `multistep` entry to restyle the `ui:steps` navigation and an
21
- * `oauth` entry to restyle the `ui:widget: "oauth"` connect control.
20
+ * carry a `multistep` entry to restyle the `ui:steps` navigation, an
21
+ * `oauth` entry to restyle the `ui:widget: "oauth"` connect control and a
22
+ * `pairing` entry to draw `ui:field: "pairing"` objects as a table.
22
23
  */
23
24
  rjsfTheme?: FcodeRjsfTheme;
24
25
  /**
@@ -2,3 +2,4 @@ export { JsonField as json } from './json-field';
2
2
  export { ButtonField as button } from './button-field';
3
3
  export { SourceCodeField as sourceCode } from './source-code-field';
4
4
  export { OauthField as oauth } from './oauth-field';
5
+ export { PairingField as pairing } from './pairing-field';
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ import { FieldProps } from '@rjsf/utils';
3
+ /**
4
+ * `ui:field: "pairing"` on an object whose properties pair Factorial records
5
+ * with the other system's: one row per property, its choices from the
6
+ * property's `oneOf`, and per-row hints (`x-fcode-suggestion`,
7
+ * `x-fcode-in-use`). The theme draws the table (`rjsfTheme.pairing.Table`);
8
+ * this field owns the rows and writes the same object the default renderer
9
+ * would, so the app reads its submission as before. A suggestion is never
10
+ * submitted until the admin accepts it. Without a theme table the object
11
+ * renders as ordinary fields.
12
+ */
13
+ export declare const PairingField: (props: FieldProps) => React.JSX.Element;
@@ -1,4 +1,7 @@
1
1
  import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';
2
+ export declare const isConstOption: (option: unknown) => option is {
3
+ const: unknown;
4
+ };
2
5
  /**
3
6
  * Rewrites every `oneOf`/`anyOf` that only lists `{ const, title }` options
4
7
  * into the equivalent `enum`. Labels are not needed to validate, and AJV
@@ -1,6 +1,7 @@
1
1
  import { default as React } from 'react';
2
2
  import { ThemeProps } from '@rjsf/core';
3
3
  import { OauthThemeComponents } from '../oauth/types';
4
+ import { PairingThemeComponents } from '../pairing/types';
4
5
  export type StepsLayout = 'tabs' | 'sidebar';
5
6
  /** An in-form step as authored in the schema's `ui['ui:steps'].steps` array. */
6
7
  /** A step's own button labels, overriding the flow's `config` ones. */
@@ -149,4 +150,5 @@ export interface MultistepThemeComponents {
149
150
  export type FcodeRjsfTheme = ThemeProps & {
150
151
  multistep?: MultistepThemeComponents;
151
152
  oauth?: OauthThemeComponents;
153
+ pairing?: PairingThemeComponents;
152
154
  };
@@ -1,5 +1,6 @@
1
1
  import { KeptFiles } from '../../../utils/kept-files';
2
2
  import { default as React } from 'react';
3
+ import { PairingThemeComponents } from '../pairing/types';
3
4
  export type OauthOnComplete = 'none' | 'submit' | 'reload';
4
5
  export type OauthValueKind = 'boolean' | 'string' | 'object';
5
6
  export type OauthConnectStatus = 'idle' | 'pending' | 'connected';
@@ -76,6 +77,11 @@ export interface OauthThemeComponents {
76
77
  export interface FcodeFormContext {
77
78
  fcode?: {
78
79
  oauth?: OauthThemeComponents;
80
+ /**
81
+ * Draws `ui:field: "pairing"` objects. Without it they render as ordinary
82
+ * fields, which is what the hosted bundle's default theme does.
83
+ */
84
+ pairing?: PairingThemeComponents;
79
85
  /**
80
86
  * Refetches the form specs bypassing the cache. The `oauth` widget calls
81
87
  * it for `onComplete: "reload"` and after any failed attempt, so the
@@ -0,0 +1,2 @@
1
+ export { parsePairingConfig, parsePairingRows } from './parse-pairing';
2
+ export type { PairingLabels, PairingOption, PairingRowStatus, PairingSuggestion, PairingTableProps, PairingTableRow, PairingThemeComponents, } from './types';
@@ -0,0 +1,48 @@
1
+ import { GenericObjectType } from '../../../types';
2
+ import { PairingLabels, PairingRowSpec, PairingRowStatus, PairingTableRow } from './types';
3
+ export type PairingData = GenericObjectType;
4
+ /** The row's value as a choice; anything that is not a string reads as unpaired. */
5
+ export declare const rowValue: (data: PairingData, row: PairingRowSpec) => string;
6
+ /**
7
+ * Whether the row holds a choice. A stored `""` counts only where the row
8
+ * offers it: then it is the admin's explicit "not mapped".
9
+ */
10
+ export declare const hasValue: (data: PairingData, row: PairingRowSpec) => boolean;
11
+ export declare const rowStatus: (data: PairingData, row: PairingRowSpec) => PairingRowStatus;
12
+ /** The row shows a suggestion it does not hold yet. */
13
+ export declare const isPending: (data: PairingData, row: PairingRowSpec) => boolean;
14
+ /**
15
+ * The value after setting one row. Every other key the object holds is kept.
16
+ * `""` is the explicit "not mapped" choice. Clearing (`null`) sets the key to
17
+ * `undefined`, which JSON leaves out of the submission and which keeps RJSF
18
+ * from filling a stored default back in.
19
+ */
20
+ export declare const setRow: (data: PairingData, row: PairingRowSpec, value: string | null) => PairingData;
21
+ /** Rows showing a suggestion the admin has not taken yet. */
22
+ export declare const pendingRows: (data: PairingData, rows: PairingRowSpec[]) => PairingRowSpec[];
23
+ /** Pairs every pending row with its suggestion. */
24
+ export declare const acceptAll: (data: PairingData, rows: PairingRowSpec[]) => PairingData;
25
+ /** Whether the schema marks any row in use, which narrows the list by default. */
26
+ export declare const canFilter: (rows: PairingRowSpec[]) => boolean;
27
+ /**
28
+ * The rows to list. With rows marked in use, that is those in use plus any row
29
+ * that is paired or suggested, in schema order, then the rows the admin added,
30
+ * in the order they were added. Without such marks, every row.
31
+ */
32
+ export declare const visibleRows: (data: PairingData, rows: PairingRowSpec[], added: string[]) => PairingRowSpec[];
33
+ /** Rows with no value and no suggestion, or whose stored pair is gone. */
34
+ export declare const needsChoiceRows: (data: PairingData, rows: PairingRowSpec[]) => PairingRowSpec[];
35
+ /**
36
+ * The listed rows while the "needs a choice" filter is on: the rows that
37
+ * needed a choice when it was turned on (`kept`), so a row paired meanwhile
38
+ * stays in place instead of vanishing mid-edit. `null` means the filter is off.
39
+ */
40
+ export declare const filteredRows: (listed: PairingRowSpec[], kept: string[] | null) => PairingRowSpec[];
41
+ export declare const formatLabel: (template: string, values: Record<string, number | string>) => string;
42
+ export declare const tableRow: (data: PairingData, row: PairingRowSpec, labels: PairingLabels, error?: string | null) => PairingTableRow;
43
+ /**
44
+ * The rows with the suggestions the admin dismissed (by clearing a shown
45
+ * suggestion) taken away, so those rows read as needing a choice.
46
+ */
47
+ export declare const withoutDismissed: (rows: PairingRowSpec[], dismissed: string[]) => PairingRowSpec[];
48
+ export declare const summaryLabel: (rows: PairingTableRow[], labels: PairingLabels) => string;
@@ -0,0 +1,16 @@
1
+ import { GenericObjectType } from '../../../types';
2
+ import { PairingConfig, PairingLabels, PairingRowSpec } from './types';
3
+ export declare const DEFAULT_PAIRING_LABELS: PairingLabels;
4
+ /**
5
+ * Validates the schema-authored `ui:options` of a pairing field in the same
6
+ * warn-and-degrade spirit as `ui:steps` and `oauth`: a bad option falls back
7
+ * to its default instead of breaking the form.
8
+ */
9
+ export declare const parsePairingConfig: (uiOptions: GenericObjectType | undefined) => PairingConfig;
10
+ /**
11
+ * Reads the rows of a `ui:field: "pairing"` object, in property order. Choices
12
+ * come from a row's `oneOf`, or from its `enum` labelled by the row's
13
+ * `ui:enumNames` (the form the SDK rewrites `oneOf` rows into), or, for a row
14
+ * with neither, from the section's shared `x-fcode-choices`.
15
+ */
16
+ export declare const parsePairingRows: (schema: GenericObjectType, uiSchema?: GenericObjectType) => PairingRowSpec[];
@@ -0,0 +1,12 @@
1
+ import { GenericObjectType } from '../../../types';
2
+ /**
3
+ * Prepares the rows of every `ui:field: "pairing"` object, wherever it is
4
+ * marked: on the property itself (`ui`, `uiSchema`, `ui:schema`) or in the
5
+ * root `ui`/`uiSchema` map, which, like the rest of the SDK, is matched by
6
+ * property name at any depth. For each row it applies the section's shared
7
+ * `x-fcode-choices`, rewrites a `oneOf` of string constants into an `enum`
8
+ * (see `asEnum`) and sets aside a stored pair that is no longer a choice.
9
+ * Runs on the raw form specs, before their `ui` keys are lifted into the
10
+ * uiSchema.
11
+ */
12
+ export declare const preparePairingRows: <T extends GenericObjectType>(schema: T) => T;
@@ -0,0 +1,123 @@
1
+ import { default as React } from 'react';
2
+ /** A choice on the other system's side of a row, or a row offered to add. */
3
+ export interface PairingOption {
4
+ value: string;
5
+ label: string;
6
+ }
7
+ /** A proposal the app made for a row, shown until the admin accepts it. */
8
+ export interface PairingSuggestion {
9
+ value: string;
10
+ /** The title of the suggested option. */
11
+ label: string;
12
+ /** Why the app proposes it; empty when the app gave no reason. */
13
+ reason: string;
14
+ }
15
+ /** One property of a `ui:field: "pairing"` object, as the schema describes it. */
16
+ export interface PairingRowSpec {
17
+ /** The property name: the key the submission carries. */
18
+ id: string;
19
+ /** The Factorial side of the row: the property's title. */
20
+ label: string;
21
+ options: PairingOption[];
22
+ suggestion: PairingSuggestion | null;
23
+ inUse: boolean;
24
+ /**
25
+ * The property offers a `""` choice ("not mapped"), listed among `options`.
26
+ * A stored `""` is then the admin's explicit choice, not an empty row.
27
+ */
28
+ allowsEmpty: boolean;
29
+ /** A stored pair whose record is no longer among the choices. */
30
+ unavailable: string | null;
31
+ }
32
+ /** Every piece of text the table shows, overridable from `ui:options.labels`. */
33
+ export interface PairingLabels {
34
+ status: string;
35
+ confirmed: string;
36
+ /** The status of a suggested row whose suggestion carries no reason. */
37
+ suggested: string;
38
+ needsChoice: string;
39
+ /** A stored pair no longer among the choices; `{value}` is that pair. */
40
+ unavailable: string;
41
+ accept: string;
42
+ /** `{count}` is replaced by the number of pending suggestions. */
43
+ acceptAll: string;
44
+ /** `{confirmed}` and `{toReview}` are replaced by the listed rows' counts. */
45
+ summary: string;
46
+ placeholder: string;
47
+ addRow: string;
48
+ /** The "needs a choice" filter; `{count}` is replaced by the rows it lists. */
49
+ needsChoiceFilter: string;
50
+ empty: string;
51
+ }
52
+ /** The validated `ui:options` of a pairing field. */
53
+ export interface PairingConfig {
54
+ /** Header labels of the Factorial column and the other system's column. */
55
+ columns: [string, string];
56
+ /** Shown above the table when rows are marked in use. */
57
+ inUseNote: string | null;
58
+ labels: PairingLabels;
59
+ }
60
+ export type PairingRowStatus = 'confirmed' | 'suggested' | 'unavailable' | 'open';
61
+ /** A listed row, ready to draw. */
62
+ export interface PairingTableRow {
63
+ id: string;
64
+ label: string;
65
+ /**
66
+ * The row's current value, what the form submits; `""` while unpaired, or,
67
+ * on a confirmed row, the explicit "not mapped" choice.
68
+ */
69
+ value: string;
70
+ /**
71
+ * What the select shows: the value, or, on a suggested row, the suggestion,
72
+ * which is not part of the form's value until accepted.
73
+ */
74
+ shownValue: string;
75
+ /** `shownValue` is a suggestion not chosen yet: draw it as such. */
76
+ pending: boolean;
77
+ options: PairingOption[];
78
+ status: PairingRowStatus;
79
+ /** The text for the status ("Suggested" on a suggested row). */
80
+ statusLabel: string;
81
+ suggestion: PairingSuggestion | null;
82
+ /** The validation message for the row, once the form has been validated. */
83
+ error: string | null;
84
+ }
85
+ /** What the SDK hands the theme's pairing table. */
86
+ export interface PairingTableProps {
87
+ id: string;
88
+ columns: [string, string];
89
+ labels: PairingLabels;
90
+ /** The listed rows, in display order. */
91
+ rows: PairingTableRow[];
92
+ /** e.g. "12 confirmed, 30 to review". */
93
+ summary: string;
94
+ pendingCount: number;
95
+ /** e.g. "Accept 30 suggestions". */
96
+ acceptAllLabel: string;
97
+ inUseNote: string | null;
98
+ /**
99
+ * The "needs a choice" filter: present while some listed row needs a choice,
100
+ * or while it is on. `label` already carries the count.
101
+ */
102
+ filter: {
103
+ active: boolean;
104
+ label: string;
105
+ onToggle: () => void;
106
+ } | null;
107
+ /** Rows not listed yet that the admin can add; `value` is the row id. */
108
+ addable: PairingOption[];
109
+ disabled: boolean;
110
+ /** `null` clears the row. */
111
+ onChange: (rowId: string, value: string | null) => void;
112
+ onAccept: (rowId: string) => void;
113
+ onAcceptAll: () => void;
114
+ onAdd: (rowId: string) => void;
115
+ }
116
+ /**
117
+ * The component a theme contributes to draw `ui:field: "pairing"` objects.
118
+ * The SDK owns parsing, row state and the submitted values; without it the
119
+ * object renders as ordinary fields.
120
+ */
121
+ export interface PairingThemeComponents {
122
+ Table: React.ComponentType<PairingTableProps>;
123
+ }