@object-ui/react 6.0.4 → 6.2.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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @object-ui/react
2
2
 
3
+ ## 6.2.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [fe3c1d3]
8
+ - Updated dependencies [ec8dcde]
9
+ - @object-ui/data-objectstack@6.2.0
10
+ - @object-ui/types@6.2.0
11
+ - @object-ui/core@6.2.0
12
+ - @object-ui/i18n@6.2.0
13
+
14
+ ## 6.1.0
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [991b62d]
19
+ - @object-ui/core@6.1.0
20
+ - @object-ui/types@6.1.0
21
+ - @object-ui/data-objectstack@6.1.0
22
+ - @object-ui/i18n@6.1.0
23
+
3
24
  ## 6.0.4
4
25
 
5
26
  ### Patch Changes
@@ -5,6 +5,25 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import { type ReactNode } from 'react';
9
+ /**
10
+ * Provider for the global predicate scope. Wraps children so any
11
+ * descendant `useCondition` / `useExpression` call has access to
12
+ * top-level variables (e.g. `features.multiOrgEnabled`).
13
+ *
14
+ * Most consumers should not use this directly — the app-shell's
15
+ * `ExpressionProvider` already feeds it. It's exported for hosts that
16
+ * want a custom shell.
17
+ */
18
+ export declare function PredicateScopeProvider({ scope, children, }: {
19
+ scope: Record<string, any>;
20
+ children: ReactNode;
21
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<Record<string, any>>>;
22
+ /**
23
+ * Read the current global predicate scope. Returns an empty object when
24
+ * no provider is mounted.
25
+ */
26
+ export declare function usePredicateScope(): Record<string, any>;
8
27
  /**
9
28
  * Normalize a schema-supplied predicate (`visible` / `enabled` / `disabled` /
10
29
  * `hidden`) into the `${expr}` template form expected by `useCondition`.
@@ -5,8 +5,39 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- import { useMemo } from 'react';
8
+ import { createContext, createElement, useContext, useMemo } from 'react';
9
9
  import { ExpressionEvaluator } from '@object-ui/core';
10
+ /**
11
+ * Global predicate scope — populated by host shells (e.g. app-shell's
12
+ * `ExpressionProvider`) so renderers like action buttons can resolve
13
+ * deployment-level flags (`features`, `user`, `app`, …) without needing
14
+ * to import the host shell directly.
15
+ *
16
+ * `useCondition` / `useExpression` merge this scope under the
17
+ * locally-passed `context`, so per-row `record` overrides still win.
18
+ * Defaults to an empty object so components used outside a provider
19
+ * keep behaving exactly as before.
20
+ */
21
+ const PredicateScopeContext = createContext({});
22
+ /**
23
+ * Provider for the global predicate scope. Wraps children so any
24
+ * descendant `useCondition` / `useExpression` call has access to
25
+ * top-level variables (e.g. `features.multiOrgEnabled`).
26
+ *
27
+ * Most consumers should not use this directly — the app-shell's
28
+ * `ExpressionProvider` already feeds it. It's exported for hosts that
29
+ * want a custom shell.
30
+ */
31
+ export function PredicateScopeProvider({ scope, children, }) {
32
+ return createElement(PredicateScopeContext.Provider, { value: scope }, children);
33
+ }
34
+ /**
35
+ * Read the current global predicate scope. Returns an empty object when
36
+ * no provider is mounted.
37
+ */
38
+ export function usePredicateScope() {
39
+ return useContext(PredicateScopeContext);
40
+ }
10
41
  /**
11
42
  * Normalize a schema-supplied predicate (`visible` / `enabled` / `disabled` /
12
43
  * `hidden`) into the `${expr}` template form expected by `useCondition`.
@@ -46,11 +77,14 @@ export function toPredicateInput(value) {
46
77
  * ```
47
78
  */
48
79
  export function useExpression(expression, context = {}) {
80
+ const scope = usePredicateScope();
49
81
  // We evaluate directly without caching the evaluator to avoid issues with context changes
50
82
  return useMemo(() => {
51
- const evaluator = new ExpressionEvaluator(context);
83
+ // Merge global scope under the local context — local wins so per-row
84
+ // `record` overrides still take precedence over `features` etc.
85
+ const evaluator = new ExpressionEvaluator({ ...scope, ...context });
52
86
  return evaluator.evaluate(expression);
53
- }, [expression, context]);
87
+ }, [expression, context, scope]);
54
88
  }
55
89
  /**
56
90
  * Hook for evaluating conditional expressions
@@ -62,9 +96,10 @@ export function useExpression(expression, context = {}) {
62
96
  * ```
63
97
  */
64
98
  export function useCondition(condition, context = {}) {
99
+ const scope = usePredicateScope();
65
100
  // We evaluate directly without caching the evaluator to avoid issues with context changes
66
101
  return useMemo(() => {
67
- const evaluator = new ExpressionEvaluator(context);
102
+ const evaluator = new ExpressionEvaluator({ ...scope, ...context });
68
103
  return evaluator.evaluateCondition(condition);
69
- }, [condition, context]);
104
+ }, [condition, context, scope]);
70
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/react",
3
- "version": "6.0.4",
3
+ "version": "6.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "React bindings and SchemaRenderer component for Object UI",
@@ -24,19 +24,19 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@objectstack/spec": "^5.2.0",
27
+ "@objectstack/spec": "^6.7.1",
28
28
  "react-hook-form": "^7.76.1",
29
- "@object-ui/core": "6.0.4",
30
- "@object-ui/data-objectstack": "6.0.4",
31
- "@object-ui/i18n": "6.0.4",
32
- "@object-ui/types": "6.0.4"
29
+ "@object-ui/core": "6.2.0",
30
+ "@object-ui/data-objectstack": "6.2.0",
31
+ "@object-ui/i18n": "6.2.0",
32
+ "@object-ui/types": "6.2.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "^18.0.0 || ^19.0.0",
36
36
  "react-dom": "^18.0.0 || ^19.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@types/react": "19.2.14",
39
+ "@types/react": "19.2.15",
40
40
  "@types/react-dom": "19.2.3",
41
41
  "typescript": "^6.0.3"
42
42
  },