react-formule 1.5.0 → 1.7.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 (31) hide show
  1. package/README.md +129 -5
  2. package/dist/admin/components/SchemaCodeEditor.d.ts +8 -0
  3. package/dist/admin/utils/fieldTypes.d.ts +1667 -549
  4. package/dist/admin/utils/index.d.ts +1 -1
  5. package/dist/ai/AiChatFooter.d.ts +9 -0
  6. package/dist/ai/AiDiff.d.ts +9 -0
  7. package/dist/ai/AiSettingsDialog.d.ts +7 -0
  8. package/dist/ai/defaults.d.ts +4 -0
  9. package/dist/ai/hooks.d.ts +4 -0
  10. package/dist/ai/utils.d.ts +5 -0
  11. package/dist/contexts/CustomizationContext.d.ts +3 -1
  12. package/dist/exposed.d.ts +1 -1
  13. package/dist/forms/Form.d.ts +2 -0
  14. package/dist/forms/fields/base/CodeEditorField.d.ts +1 -2
  15. package/dist/forms/templates/ArrayFieldTemplates/AccordionArrayFieldTemplate.d.ts +1 -1
  16. package/dist/forms/templates/ArrayFieldTemplates/LayerArrayFieldTemplate.d.ts +1 -1
  17. package/dist/forms/templates/utils/index.d.ts +1 -0
  18. package/dist/forms/widgets/base/MaskedInput/MaskedInput.d.ts +2 -1
  19. package/dist/forms/widgets/base/RichEditorWidget.d.ts +10 -1
  20. package/dist/forms/widgets/base/SliderWidget.d.ts +25 -0
  21. package/dist/forms/widgets/base/index.d.ts +3 -0
  22. package/dist/index.d.ts +8 -0
  23. package/dist/react-formule.js +87300 -81900
  24. package/dist/react-formule.umd.cjs +576 -457
  25. package/dist/store/schemaWizard.d.ts +1 -1
  26. package/dist/types/index.d.ts +74 -0
  27. package/dist/utils/CodeDiffViewer.d.ts +2 -1
  28. package/dist/utils/FieldMessageTag.d.ts +4 -0
  29. package/package.json +6 -3
  30. package/dist/admin/formComponents/widgets/SliderWidget.d.ts +0 -14
  31. package/dist/admin/formComponents/widgets/index.d.ts +0 -5
@@ -24,7 +24,7 @@ export type SchemaWizardState = typeof initialState;
24
24
  export declare const schemaInit: import('@reduxjs/toolkit').ActionCreatorWithPayload<{
25
25
  data: any;
26
26
  id: any;
27
- }, "schemaWizard/schemaInit">, enableCreateMode: import('@reduxjs/toolkit').ActionCreatorWithoutPayload<"schemaWizard/enableCreateMode">, selectProperty: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/selectProperty">, updateSchemaByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateSchemaByPath">, updateUiSchemaByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateUiSchemaByPath">, addByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/addByPath">, deleteByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/deleteByPath">, renameIdByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/renameIdByPath">, updateRequired: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateRequired">, updateFormData: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateFormData">, addFile: import('@reduxjs/toolkit').ActionCreatorWithPayload<{
27
+ }, "schemaWizard/schemaInit">, enableCreateMode: import('@reduxjs/toolkit').ActionCreatorWithoutPayload<"schemaWizard/enableCreateMode">, selectProperty: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/selectProperty">, updateByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateByPath">, updateSchemaByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateSchemaByPath">, updateUiSchemaByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateUiSchemaByPath">, addByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/addByPath">, deleteByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/deleteByPath">, renameIdByPath: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/renameIdByPath">, updateRequired: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateRequired">, updateFormData: import('@reduxjs/toolkit').ActionCreatorWithPayload<any, "schemaWizard/updateFormData">, addFile: import('@reduxjs/toolkit').ActionCreatorWithPayload<{
28
28
  uid: string;
29
29
  objectUrl: string;
30
30
  }, "schemaWizard/addFile">, removeNewFile: import('@reduxjs/toolkit').ActionCreatorWithPayload<{
@@ -18,6 +18,73 @@ export type CustomFunctions = {
18
18
  fetchFile: (uid: string) => string | Promise<string>;
19
19
  };
20
20
  };
21
+ export type TokenUsage = {
22
+ prompt: number;
23
+ completion: number;
24
+ total: number;
25
+ cached?: number;
26
+ };
27
+ export type AISuggestion = {
28
+ schema: object;
29
+ uiSchema: object;
30
+ usage?: TokenUsage;
31
+ };
32
+ export type AIError = {
33
+ error: string;
34
+ usage?: TokenUsage;
35
+ };
36
+ export type AIResponse = AISuggestion | AIError;
37
+ /**
38
+ * Configuration for an AI Provider. New providers will override the defaults.
39
+ * If you want to add a new provider while keeping the defaults, you can import
40
+ * and include `...defaultProviders`.
41
+ */
42
+ export type AIProvider = {
43
+ /** Label for the AI provider in the UI */
44
+ label: ReactNode;
45
+ /**
46
+ * Optional provider API key. If not provided here, you should request it from the user,
47
+ * for example using the `AiSettingsDialog` component.
48
+ */
49
+ apiKey?: string;
50
+ /**
51
+ * Optional model identifier. If not provided, you need to pass a
52
+ * `fetchModels` function to be called by `AiSettingsDialog`.
53
+ */
54
+ model?: string;
55
+ /** Show this model as a recommended default in the `AiSettingsDialog` panel.
56
+ * If not provided, no model will be recommended.
57
+ */
58
+ recommendedModel?: {
59
+ id: string;
60
+ name: string;
61
+ };
62
+ /**
63
+ * Function to retrieve available models (used in the AiSettingsDialog component).
64
+ * Not needed when the api key and model are provided directly.
65
+ * @param apiKey - Provider API key
66
+ * @returns Promise containing an array of available models with their IDs and display names
67
+ */
68
+ fetchModels?: (apiKey: string) => Promise<{
69
+ id: string;
70
+ name: string;
71
+ }[]>;
72
+ /**
73
+ * Main function to generate schema modifications. You must use your own system prompt.
74
+ * @param prompt - User prompt
75
+ * @param currentSchema - Current form state (schema and uiSchema)
76
+ * @param fieldTypes - Field type specification
77
+ * @param apiKey - Provider API key
78
+ * @param model - Model identifier to use
79
+ * @returns Promise containing the generated schema (or otherwise error) with optional token usage information
80
+ */
81
+ generateSchema: (prompt: string, currentSchema: object, fieldTypes: object, apiKey: string, model: string) => Promise<AIResponse>;
82
+ };
83
+ export type AIConfig = {
84
+ providers: {
85
+ [key: string]: AIProvider;
86
+ };
87
+ };
21
88
  export type FormuleContextProps = {
22
89
  children: ReactNode;
23
90
  customFieldTypes?: object;
@@ -31,4 +98,11 @@ export type FormuleContextProps = {
31
98
  errorBoundary?: ReactNode;
32
99
  synchronizeState?: (state: SchemaWizardState) => void;
33
100
  transformSchema?: (schema: object) => object;
101
+ ai?: AIConfig;
102
+ };
103
+ export type CustomizationContextProps = Omit<FormuleContextProps, "children" | "customFieldTypes" | "synchronizeState" | "theme"> & {
104
+ allFieldTypes: object;
105
+ separator: string;
106
+ transformSchema: (schema: object) => object;
107
+ ai: AIConfig;
34
108
  };
@@ -3,6 +3,7 @@ type CodeDiffViewerProps = {
3
3
  right: string;
4
4
  lang?: string;
5
5
  height?: string;
6
+ unified?: boolean;
6
7
  };
7
- declare const CodeDiffViewer: ({ left, right, lang, height }: CodeDiffViewerProps) => import("react/jsx-runtime").JSX.Element;
8
+ declare const CodeDiffViewer: ({ left, right, lang, height, unified, }: CodeDiffViewerProps) => import("react/jsx-runtime").JSX.Element;
8
9
  export default CodeDiffViewer;
@@ -0,0 +1,4 @@
1
+ export declare const FieldMessageTag: ({ color, children }: {
2
+ color: any;
3
+ children: any;
4
+ }) => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-formule",
3
3
  "private": false,
4
- "version": "1.5.0",
4
+ "version": "1.7.0",
5
5
  "author": "CERN",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -32,6 +32,7 @@
32
32
  "prepare": "husky"
33
33
  },
34
34
  "dependencies": {
35
+ "@ant-design/icons": "^5.6.1",
35
36
  "@ant-design/pro-layout": "^7.16.4",
36
37
  "@codemirror/lang-json": "^6.0.1",
37
38
  "@codemirror/language": "^6.8.0",
@@ -43,10 +44,12 @@
43
44
  "@rjsf/core": "^5.21.0",
44
45
  "@rjsf/utils": "^5.21.0",
45
46
  "@rjsf/validator-ajv8": "^5.21.0",
46
- "antd": "^5.7.3",
47
+ "ajv": "^8.17.1",
48
+ "antd": "^5.26.0",
47
49
  "axios": "^1.4.0",
48
50
  "codemirror": "^6.0.1",
49
51
  "codemirror-json-schema": "0.7.1",
52
+ "just-diff": "^6.0.2",
50
53
  "katex": "^0.16.8",
51
54
  "markdown-it": "^13.0.1",
52
55
  "markdown-it-texmath": "^1.0.0",
@@ -93,7 +96,7 @@
93
96
  "vite": "^5.0.2",
94
97
  "vite-plugin-css-injected-by-js": "^3.3.0",
95
98
  "vite-plugin-dts": "^3.6.3",
96
- "vitest": "^0.34.6"
99
+ "vitest": "^2.1.8"
97
100
  },
98
101
  "peerDependencies": {
99
102
  "react": ">=18.2.0",
@@ -1,14 +0,0 @@
1
- import { default as PropTypes } from 'prop-types';
2
- export default SliderWidget;
3
- declare function SliderWidget({ schema, onChange, value }: {
4
- schema: any;
5
- onChange: any;
6
- value: any;
7
- }): import("react/jsx-runtime").JSX.Element;
8
- declare namespace SliderWidget {
9
- namespace propTypes {
10
- let schema: PropTypes.Requireable<object>;
11
- let onChange: PropTypes.Requireable<(...args: any[]) => any>;
12
- let value: PropTypes.Requireable<number>;
13
- }
14
- }
@@ -1,5 +0,0 @@
1
- import { default as SliderWidget } from './SliderWidget';
2
- export default widgets;
3
- declare namespace widgets {
4
- export { SliderWidget as slider };
5
- }