@optiaxiom/globals 1.1.4 → 1.1.6

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
@@ -14,11 +14,12 @@ const SurfaceProvider = ({
14
14
  accept,
15
15
  children,
16
16
  executeTool,
17
+ reject,
17
18
  renderSuggestionValue,
18
19
  ...props
19
20
  }) => {
20
21
  const suggestion = props.suggestions.find(
21
- (s) => s.type !== "cards" && ("/" + props.path).endsWith("/" + s.surface)
22
+ (s) => ("/" + props.path).endsWith("/" + s.surface) && (s.type === "message" || s.type === "value" && s.value !== props.value)
22
23
  );
23
24
  const store = react.useContext(SuggestionContext);
24
25
  react.useEffect(() => {
@@ -28,6 +29,7 @@ const SurfaceProvider = ({
28
29
  return store.add(suggestion, {
29
30
  accept,
30
31
  executeTool,
32
+ reject,
31
33
  renderSuggestionValue
32
34
  });
33
35
  }, [
@@ -35,6 +37,7 @@ const SurfaceProvider = ({
35
37
  executeTool,
36
38
  props.suggestionAlert.registered,
37
39
  props.suggestionPopover.registered,
40
+ reject,
38
41
  renderSuggestionValue,
39
42
  store,
40
43
  suggestion
@@ -44,6 +47,7 @@ const SurfaceProvider = ({
44
47
  value: {
45
48
  accept,
46
49
  executeTool,
50
+ reject,
47
51
  renderSuggestionValue,
48
52
  ...props
49
53
  }
@@ -7,11 +7,12 @@ const SurfaceProvider = ({
7
7
  accept,
8
8
  children,
9
9
  executeTool,
10
+ reject,
10
11
  renderSuggestionValue,
11
12
  ...props
12
13
  }) => {
13
14
  const suggestion = props.suggestions.find(
14
- (s) => s.type !== "cards" && ("/" + props.path).endsWith("/" + s.surface)
15
+ (s) => ("/" + props.path).endsWith("/" + s.surface) && (s.type === "message" || s.type === "value" && s.value !== props.value)
15
16
  );
16
17
  const store = useContext(SuggestionContext);
17
18
  useEffect(() => {
@@ -21,6 +22,7 @@ const SurfaceProvider = ({
21
22
  return store.add(suggestion, {
22
23
  accept,
23
24
  executeTool,
25
+ reject,
24
26
  renderSuggestionValue
25
27
  });
26
28
  }, [
@@ -28,6 +30,7 @@ const SurfaceProvider = ({
28
30
  executeTool,
29
31
  props.suggestionAlert.registered,
30
32
  props.suggestionPopover.registered,
33
+ reject,
31
34
  renderSuggestionValue,
32
35
  store,
33
36
  suggestion
@@ -37,6 +40,7 @@ const SurfaceProvider = ({
37
40
  value: {
38
41
  accept,
39
42
  executeTool,
43
+ reject,
40
44
  renderSuggestionValue,
41
45
  ...props
42
46
  }
package/dist/index.d.ts CHANGED
@@ -26,11 +26,11 @@ declare const useModalContext: (consumerName: string) => {
26
26
  shardRef: RefObject<HTMLElement>;
27
27
  };
28
28
 
29
- type Surface<T extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> = {
29
+ type Surface = {
30
30
  /**
31
31
  * Optional data associated with this surface.
32
32
  */
33
- data?: T;
33
+ data?: Record<string, unknown>;
34
34
  /**
35
35
  * The surface name (used in surface path).
36
36
  */
@@ -39,8 +39,12 @@ type Surface<T extends Record<string, unknown> | undefined = Record<string, unkn
39
39
  * The surface type.
40
40
  */
41
41
  type: "action" | "cards" | "collection" | "dialog" | "page" | "product" | "property" | "resource" | "tab";
42
+ /**
43
+ * Optional value associated with this surface.
44
+ */
45
+ value?: unknown;
42
46
  };
43
- type SurfaceContextValue = {
47
+ type SurfaceContextValue<V = unknown> = {
44
48
  accept: (suggestionId: string) => void;
45
49
  executeTool: (name: string, parameters: unknown) => Promise<void> | void;
46
50
  metadata: Record<string, Omit<Surface, "name">>;
@@ -48,7 +52,7 @@ type SurfaceContextValue = {
48
52
  pageViewId: string | undefined;
49
53
  path: string;
50
54
  reject: (suggestionId: string) => void;
51
- renderSuggestionValue?: (value: unknown) => React.ReactNode;
55
+ renderSuggestionValue?: (value: V) => React.ReactNode;
52
56
  suggestionAlert: {
53
57
  register: () => () => void;
54
58
  registered: boolean;
@@ -58,8 +62,9 @@ type SurfaceContextValue = {
58
62
  registered: boolean;
59
63
  };
60
64
  suggestions: SurfaceSuggestion[];
61
- track: (interaction: SurfaceInteraction, metadata?: Record<string, Omit<Surface, "name">>) => void;
65
+ track: (interaction: SurfaceInteraction, surfaces?: Surface[]) => void;
62
66
  type: Surface["type"];
67
+ value?: V;
63
68
  };
64
69
  type SurfaceInteraction = {
65
70
  id?: string;
@@ -109,15 +114,15 @@ type SurfaceSuggestion = {
109
114
  };
110
115
  type: "message";
111
116
  });
112
- declare function useSurfaceContext(): SurfaceContextValue | null;
117
+ declare function useSurfaceContext(): SurfaceContextValue<unknown> | null;
113
118
  declare const unstable_SuggestionContext: react.Context<{
114
- add: (suggestion: Extract<SurfaceSuggestion, {
119
+ add: <V = unknown>(suggestion: Extract<SurfaceSuggestion, {
115
120
  type: "message" | "value";
116
- }>, surface: Pick<SurfaceContextValue, "accept" | "executeTool" | "renderSuggestionValue">) => () => void;
121
+ }>, surface: Pick<SurfaceContextValue<V>, "accept" | "executeTool" | "reject" | "renderSuggestionValue">) => () => void;
117
122
  } | null>;
118
- declare const unstable_SurfaceProvider: ({ accept, children, executeTool, renderSuggestionValue, ...props }: SurfaceContextValue & {
123
+ declare const unstable_SurfaceProvider: <V = unknown>({ accept, children, executeTool, reject, renderSuggestionValue, ...props }: SurfaceContextValue<V> & {
119
124
  children?: ReactNode;
120
- }) => react.FunctionComponentElement<react.ProviderProps<SurfaceContextValue | null>>;
125
+ }) => react.FunctionComponentElement<react.ProviderProps<SurfaceContextValue<unknown> | null>>;
121
126
  declare const unstable_useSurfaceContext: typeof useSurfaceContext;
122
127
 
123
128
  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.4",
10
+ "version": "1.1.6",
11
11
  "files": [
12
12
  "dist/**",
13
13
  "LICENSE"