@object-ui/react 0.3.0 → 0.3.1

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 (40) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/SchemaRenderer.d.ts +7 -0
  3. package/dist/SchemaRenderer.js +7 -0
  4. package/dist/components/form/FieldFactory.d.ts +43 -0
  5. package/dist/components/form/FieldFactory.js +157 -0
  6. package/dist/components/form/FormRenderer.d.ts +40 -0
  7. package/dist/components/form/FormRenderer.js +87 -0
  8. package/dist/components/form/FormRenderer.test.d.ts +8 -0
  9. package/dist/components/form/FormRenderer.test.js +534 -0
  10. package/dist/components/form/index.d.ts +11 -0
  11. package/dist/components/form/index.js +9 -0
  12. package/dist/context/SchemaRendererContext.d.ts +13 -0
  13. package/dist/context/SchemaRendererContext.js +21 -0
  14. package/dist/context/index.d.ts +8 -1
  15. package/dist/context/index.js +8 -1
  16. package/dist/hooks/index.d.ts +9 -1
  17. package/dist/hooks/index.js +9 -1
  18. package/dist/hooks/useActionRunner.d.ts +32 -0
  19. package/dist/hooks/useActionRunner.js +65 -0
  20. package/dist/hooks/useExpression.d.ts +27 -0
  21. package/dist/hooks/useExpression.js +41 -0
  22. package/dist/index.d.ts +8 -0
  23. package/dist/index.js +8 -0
  24. package/dist/index.test.d.ts +7 -0
  25. package/dist/index.test.js +7 -0
  26. package/package.json +16 -4
  27. package/src/SchemaRenderer.tsx +8 -0
  28. package/src/components/form/FieldFactory.tsx +504 -0
  29. package/src/components/form/FormRenderer.test.tsx +599 -0
  30. package/src/components/form/FormRenderer.tsx +209 -0
  31. package/src/components/form/README.md +352 -0
  32. package/src/components/form/index.ts +12 -0
  33. package/src/context/SchemaRendererContext.tsx +40 -0
  34. package/src/context/index.ts +9 -1
  35. package/src/hooks/index.ts +11 -1
  36. package/src/hooks/useActionRunner.ts +81 -0
  37. package/src/hooks/useExpression.ts +56 -0
  38. package/src/index.test.ts +8 -0
  39. package/src/index.ts +9 -0
  40. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,65 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { useState, useCallback, useMemo } from 'react';
9
+ import { ActionRunner } from '@object-ui/core';
10
+ /**
11
+ * Hook for executing actions with loading state
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const { execute, loading, error, result } = useActionRunner({ data: formData });
16
+ *
17
+ * const handleClick = () => {
18
+ * execute({
19
+ * type: 'action',
20
+ * api: '/api/save',
21
+ * successMessage: 'Saved successfully!'
22
+ * });
23
+ * };
24
+ * ```
25
+ */
26
+ export function useActionRunner(context = {}) {
27
+ const [loading, setLoading] = useState(false);
28
+ const [error, setError] = useState(null);
29
+ const [result, setResult] = useState(null);
30
+ const runner = useMemo(() => new ActionRunner(context), [JSON.stringify(context)]);
31
+ const execute = useCallback(async (action) => {
32
+ setLoading(true);
33
+ setError(null);
34
+ setResult(null);
35
+ try {
36
+ const actionResult = await runner.execute(action);
37
+ setResult(actionResult);
38
+ if (!actionResult.success) {
39
+ setError(actionResult.error || 'Action failed');
40
+ }
41
+ return actionResult;
42
+ }
43
+ catch (err) {
44
+ const errorMessage = err.message;
45
+ setError(errorMessage);
46
+ const failureResult = { success: false, error: errorMessage };
47
+ setResult(failureResult);
48
+ return failureResult;
49
+ }
50
+ finally {
51
+ setLoading(false);
52
+ }
53
+ }, [runner]);
54
+ const updateContext = useCallback((newContext) => {
55
+ runner.updateContext(newContext);
56
+ }, [runner]);
57
+ return {
58
+ execute,
59
+ loading,
60
+ error,
61
+ result,
62
+ updateContext,
63
+ runner
64
+ };
65
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * Hook for evaluating expressions with dynamic context
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const isVisible = useExpression('${data.age >= 18}', { data });
14
+ * const label = useExpression('Hello ${user.name}!', { user });
15
+ * ```
16
+ */
17
+ export declare function useExpression(expression: string | boolean | number | null | undefined, context?: Record<string, any>): any;
18
+ /**
19
+ * Hook for evaluating conditional expressions
20
+ * Returns a boolean value
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const isVisible = useCondition('${data.status === "active"}', { data });
25
+ * ```
26
+ */
27
+ export declare function useCondition(condition: string | boolean | undefined, context?: Record<string, any>): boolean;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { useMemo } from 'react';
9
+ import { ExpressionEvaluator } from '@object-ui/core';
10
+ /**
11
+ * Hook for evaluating expressions with dynamic context
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const isVisible = useExpression('${data.age >= 18}', { data });
16
+ * const label = useExpression('Hello ${user.name}!', { user });
17
+ * ```
18
+ */
19
+ export function useExpression(expression, context = {}) {
20
+ // We evaluate directly without caching the evaluator to avoid issues with context changes
21
+ return useMemo(() => {
22
+ const evaluator = new ExpressionEvaluator(context);
23
+ return evaluator.evaluate(expression);
24
+ }, [expression, context]);
25
+ }
26
+ /**
27
+ * Hook for evaluating conditional expressions
28
+ * Returns a boolean value
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * const isVisible = useCondition('${data.status === "active"}', { data });
33
+ * ```
34
+ */
35
+ export function useCondition(condition, context = {}) {
36
+ // We evaluate directly without caching the evaluator to avoid issues with context changes
37
+ return useMemo(() => {
38
+ const evaluator = new ExpressionEvaluator(context);
39
+ return evaluator.evaluateCondition(condition);
40
+ }, [condition, context]);
41
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
1
8
  export * from './SchemaRenderer';
2
9
  export * from './hooks';
3
10
  export * from './context';
11
+ export * from './components/form';
package/dist/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
1
8
  export * from './SchemaRenderer';
2
9
  export * from './hooks'; // will be empty for now
3
10
  export * from './context'; // will be empty for now
11
+ export * from './components/form';
@@ -1 +1,8 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
1
8
  export {};
@@ -1,3 +1,10 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
1
8
  import { describe, it, expect } from 'vitest';
2
9
  describe('react', () => {
3
10
  it('should work', () => {
package/package.json CHANGED
@@ -1,19 +1,31 @@
1
1
  {
2
2
  "name": "@object-ui/react",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
+ "description": "React bindings and SchemaRenderer component for Object UI",
6
+ "homepage": "https://www.objectui.org",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/objectstack-ai/objectui.git",
10
+ "directory": "packages/react"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/objectstack-ai/objectui/issues"
14
+ },
5
15
  "main": "dist/index.js",
6
16
  "types": "dist/index.d.ts",
7
17
  "dependencies": {
8
- "@object-ui/core": "0.3.0"
18
+ "@objectstack/spec": "^0.3.3",
19
+ "react-hook-form": "^7.71.1",
20
+ "@object-ui/core": "0.3.1"
9
21
  },
10
22
  "peerDependencies": {
11
23
  "react": "^18.0.0 || ^19.0.0",
12
24
  "react-dom": "^18.0.0 || ^19.0.0"
13
25
  },
14
26
  "devDependencies": {
15
- "@types/react": "^18.2.0",
16
- "@types/react-dom": "^18.2.0",
27
+ "@types/react": "^19.2.9",
28
+ "@types/react-dom": "^19.2.3",
17
29
  "typescript": "^5.9.3"
18
30
  },
19
31
  "scripts": {
@@ -1,3 +1,11 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
1
9
  import React, { forwardRef } from 'react';
2
10
  import { SchemaNode, ComponentRegistry } from '@object-ui/core';
3
11