@optiaxiom/globals 1.1.7 → 1.1.8

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/cjs/index.js CHANGED
@@ -10,20 +10,22 @@ const [ModalProvider, useModalContext] = reactContext.createContext("@optiaxiom/
10
10
 
11
11
  const SuggestionContext = react.createContext(null);
12
12
  const SurfaceContext = react.createContext(null);
13
- const SurfaceProvider = ({
14
- accept,
15
- children,
16
- executeTool,
17
- reject,
18
- renderSuggestionValue,
19
- ...props
20
- }) => {
21
- const suggestion = props.suggestions.find(
22
- (s) => ("/" + props.path).endsWith("/" + s.surface) && (s.type === "message" || s.type === "value" && s.value !== props.value)
23
- );
13
+ const SurfaceProvider = (props) => {
14
+ const {
15
+ accept,
16
+ children,
17
+ disabled,
18
+ executeTool,
19
+ reject,
20
+ renderSuggestionValue,
21
+ ...rest
22
+ } = props;
24
23
  const store = react.useContext(SuggestionContext);
24
+ const suggestion = !disabled && "suggestions" in rest ? rest.suggestions?.find(
25
+ (s) => ("/" + rest.path).endsWith("/" + s.surface) && (s.type === "message" || s.type === "value" && s.value !== rest.value)
26
+ ) : void 0;
25
27
  react.useEffect(() => {
26
- if (!store || !suggestion || suggestion.type === "cards" || props.suggestionAlert.registered || props.suggestionPopover.registered) {
28
+ if (disabled || !store || !suggestion || suggestion.type === "cards" || rest.suggestionAlert?.registered || rest.suggestionPopover?.registered) {
27
29
  return;
28
30
  }
29
31
  return store.add(suggestion, {
@@ -33,23 +35,24 @@ const SurfaceProvider = ({
33
35
  renderSuggestionValue
34
36
  });
35
37
  }, [
38
+ disabled,
36
39
  accept,
37
40
  executeTool,
38
- props.suggestionAlert.registered,
39
- props.suggestionPopover.registered,
41
+ rest.suggestionAlert?.registered,
40
42
  reject,
41
43
  renderSuggestionValue,
42
44
  store,
43
- suggestion
45
+ suggestion,
46
+ rest.suggestionPopover?.registered
44
47
  ]);
45
48
  return react.createElement(SurfaceContext.Provider, {
46
49
  children,
47
- value: {
50
+ value: disabled ? null : {
48
51
  accept,
49
52
  executeTool,
50
53
  reject,
51
54
  renderSuggestionValue,
52
- ...props
55
+ ...rest
53
56
  }
54
57
  });
55
58
  };
@@ -3,20 +3,22 @@ import { createContext, useContext, useEffect, createElement } from 'react';
3
3
 
4
4
  const SuggestionContext = createContext(null);
5
5
  const SurfaceContext = createContext(null);
6
- const SurfaceProvider = ({
7
- accept,
8
- children,
9
- executeTool,
10
- reject,
11
- renderSuggestionValue,
12
- ...props
13
- }) => {
14
- const suggestion = props.suggestions.find(
15
- (s) => ("/" + props.path).endsWith("/" + s.surface) && (s.type === "message" || s.type === "value" && s.value !== props.value)
16
- );
6
+ const SurfaceProvider = (props) => {
7
+ const {
8
+ accept,
9
+ children,
10
+ disabled,
11
+ executeTool,
12
+ reject,
13
+ renderSuggestionValue,
14
+ ...rest
15
+ } = props;
17
16
  const store = useContext(SuggestionContext);
17
+ const suggestion = !disabled && "suggestions" in rest ? rest.suggestions?.find(
18
+ (s) => ("/" + rest.path).endsWith("/" + s.surface) && (s.type === "message" || s.type === "value" && s.value !== rest.value)
19
+ ) : void 0;
18
20
  useEffect(() => {
19
- if (!store || !suggestion || suggestion.type === "cards" || props.suggestionAlert.registered || props.suggestionPopover.registered) {
21
+ if (disabled || !store || !suggestion || suggestion.type === "cards" || rest.suggestionAlert?.registered || rest.suggestionPopover?.registered) {
20
22
  return;
21
23
  }
22
24
  return store.add(suggestion, {
@@ -26,23 +28,24 @@ const SurfaceProvider = ({
26
28
  renderSuggestionValue
27
29
  });
28
30
  }, [
31
+ disabled,
29
32
  accept,
30
33
  executeTool,
31
- props.suggestionAlert.registered,
32
- props.suggestionPopover.registered,
34
+ rest.suggestionAlert?.registered,
33
35
  reject,
34
36
  renderSuggestionValue,
35
37
  store,
36
- suggestion
38
+ suggestion,
39
+ rest.suggestionPopover?.registered
37
40
  ]);
38
41
  return createElement(SurfaceContext.Provider, {
39
42
  children,
40
- value: {
43
+ value: disabled ? null : {
41
44
  accept,
42
45
  executeTool,
43
46
  reject,
44
47
  renderSuggestionValue,
45
- ...props
48
+ ...rest
46
49
  }
47
50
  });
48
51
  };
package/dist/index.d.ts CHANGED
@@ -38,7 +38,7 @@ type Surface = {
38
38
  /**
39
39
  * The surface type.
40
40
  */
41
- type: "action" | "cards" | "collection" | "dialog" | "page" | "product" | "property" | "resource" | "tab";
41
+ type: "action" | "cards" | "dialog" | "group" | "page" | "product" | "property" | "resource" | "tab";
42
42
  /**
43
43
  * Optional value associated with this surface.
44
44
  */
@@ -121,9 +121,13 @@ declare const unstable_SuggestionContext: react.Context<{
121
121
  type: "message" | "value";
122
122
  }>, surface: Pick<SurfaceContextValue<V>, "accept" | "executeTool" | "reject" | "renderSuggestionValue">) => () => void;
123
123
  } | null>;
124
- declare const unstable_SurfaceProvider: <V = unknown>({ accept, children, executeTool, reject, renderSuggestionValue, ...props }: SurfaceContextValue<V> & {
124
+ declare const unstable_SurfaceProvider: <V = unknown>(props: (Partial<SurfaceContextValue<V>> & {
125
125
  children?: ReactNode;
126
- }) => react.FunctionComponentElement<react.ProviderProps<SurfaceContextValue<unknown> | null>>;
126
+ disabled: true;
127
+ }) | (SurfaceContextValue<V> & {
128
+ children?: ReactNode;
129
+ disabled?: false;
130
+ })) => react.FunctionComponentElement<react.ProviderProps<SurfaceContextValue<unknown> | null>>;
127
131
  declare const unstable_useSurfaceContext: typeof useSurfaceContext;
128
132
 
129
133
  declare const theme: MapLeafNodes<{
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "git+https://github.com/optimizely-axiom/optiaxiom.git"
8
8
  },
9
9
  "type": "module",
10
- "version": "1.1.7",
10
+ "version": "1.1.8",
11
11
  "files": [
12
12
  "dist/**",
13
13
  "LICENSE"