@embedreach/components 0.1.18 → 0.1.19

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.
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import React__default, { createContext as createContext$1, Component, useReducer, useMemo, useEffect, createElement as createElement$1, useRef, useId as useId$2, useContext as useContext$1, useInsertionEffect, useCallback, Children, isValidElement, useLayoutEffect, useState, forwardRef, Fragment as Fragment$1 } from "react";
3
+ import React__default, { createContext as createContext$1, Component, useReducer, useMemo, useEffect, useContext as useContext$1, createElement as createElement$1, useRef, useId as useId$2, useInsertionEffect, useCallback, Children, isValidElement, useLayoutEffect, useState, forwardRef, Fragment as Fragment$1 } from "react";
4
4
  import * as ReactDOM from "react-dom";
5
5
  import ReactDOM__default from "react-dom";
6
6
  var Subscribable = class {
@@ -7873,7 +7873,7 @@ const createQueryClient = () => new QueryClient({
7873
7873
  }
7874
7874
  });
7875
7875
  const createDataContext = (reducer, actions, defaultValue, listeners) => {
7876
- const Context = React__default.createContext({
7876
+ const Context2 = React__default.createContext({
7877
7877
  state: defaultValue
7878
7878
  });
7879
7879
  const Provider2 = ({ children: children2 }) => {
@@ -7905,9 +7905,9 @@ const createDataContext = (reducer, actions, defaultValue, listeners) => {
7905
7905
  () => ({ state, ...boundActions }),
7906
7906
  [state, boundActions]
7907
7907
  );
7908
- return /* @__PURE__ */ jsx(Context.Provider, { value: contextValue, children: children2 });
7908
+ return /* @__PURE__ */ jsx(Context2.Provider, { value: contextValue, children: children2 });
7909
7909
  };
7910
- return { Context, Provider: Provider2 };
7910
+ return { Context: Context2, Provider: Provider2 };
7911
7911
  };
7912
7912
  const authReducer = (state, action) => {
7913
7913
  switch (action.type) {
@@ -8104,6 +8104,13 @@ const applyThemeStyles = (styles2) => {
8104
8104
  styleElement.textContent = cssText;
8105
8105
  document.head.appendChild(styleElement);
8106
8106
  };
8107
+ const mergeThemeStyles = (themeConfig, overrides) => {
8108
+ return {
8109
+ ...DEFAULT_THEME_STYLES,
8110
+ ...themeConfig?.styles || {},
8111
+ ...{}
8112
+ };
8113
+ };
8107
8114
  const themeReducer = (state, action) => {
8108
8115
  switch (action.type) {
8109
8116
  case "set_theme":
@@ -8134,7 +8141,7 @@ const themeReducer = (state, action) => {
8134
8141
  const setTheme = (dispatch) => (theme2) => dispatch({ type: "set_theme", payload: theme2 });
8135
8142
  const setLoading = (dispatch) => (loading2) => dispatch({ type: "set_loading", payload: loading2 });
8136
8143
  const setError = (dispatch) => (error2) => dispatch({ type: "set_error", payload: error2 });
8137
- const { Provider } = createDataContext(
8144
+ const { Context, Provider } = createDataContext(
8138
8145
  themeReducer,
8139
8146
  {
8140
8147
  setTheme,
@@ -8147,6 +8154,28 @@ const { Provider } = createDataContext(
8147
8154
  error: null
8148
8155
  }
8149
8156
  );
8157
+ const useThemeContext = () => {
8158
+ const context = useContext$1(Context);
8159
+ if (context === void 0) {
8160
+ throw new Error("useThemeContext must be used within a ThemeProvider");
8161
+ }
8162
+ const applyTheme = (themeConfig) => {
8163
+ if (!themeConfig) return;
8164
+ const mergedStyles = mergeThemeStyles(themeConfig);
8165
+ const finalTheme = {
8166
+ styles: mergedStyles
8167
+ };
8168
+ context.setTheme(finalTheme);
8169
+ };
8170
+ return {
8171
+ ...context.state,
8172
+ setTheme: context.setTheme,
8173
+ setLoading: context.setLoading,
8174
+ setError: context.setError,
8175
+ // Add the helper function
8176
+ applyTheme
8177
+ };
8178
+ };
8150
8179
  const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
8151
8180
  const htmlEntities = {
8152
8181
  "&": "&",
@@ -11589,6 +11618,7 @@ const I18nProvider = ({ children: children2 }) => {
11589
11618
  const ReachProvider = ({
11590
11619
  authToken: authToken2,
11591
11620
  tenantExternalId,
11621
+ theme: theme2,
11592
11622
  children: children2
11593
11623
  }) => {
11594
11624
  const [queryClient] = React__default.useState(() => {
@@ -11597,6 +11627,14 @@ const ReachProvider = ({
11597
11627
  }
11598
11628
  return createQueryClient();
11599
11629
  });
11630
+ const themeApplied = useRef(false);
11631
+ const { applyTheme } = useThemeContext();
11632
+ useEffect(() => {
11633
+ if (!themeApplied.current && theme2) {
11634
+ applyTheme(theme2);
11635
+ themeApplied.current = true;
11636
+ }
11637
+ }, [applyTheme, theme2]);
11600
11638
  return /* @__PURE__ */ jsxs(QueryClientProvider, { client: queryClient, children: [
11601
11639
  /* @__PURE__ */ jsx(
11602
11640
  D,
@@ -22581,15 +22619,15 @@ function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForD
22581
22619
  };
22582
22620
  }
22583
22621
  function createContext2(rootComponentName, defaultContext) {
22584
- const Context = React.createContext(defaultContext);
22622
+ const Context2 = React.createContext(defaultContext);
22585
22623
  const Provider2 = (props) => {
22586
22624
  const { children: children2, ...context } = props;
22587
22625
  const value = React.useMemo(() => context, Object.values(context));
22588
- return /* @__PURE__ */ jsx(Context.Provider, { value, children: children2 });
22626
+ return /* @__PURE__ */ jsx(Context2.Provider, { value, children: children2 });
22589
22627
  };
22590
22628
  Provider2.displayName = rootComponentName + "Provider";
22591
22629
  function useContext2(consumerName) {
22592
- const context = React.useContext(Context);
22630
+ const context = React.useContext(Context2);
22593
22631
  if (context) return context;
22594
22632
  if (defaultContext !== void 0) return defaultContext;
22595
22633
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
@@ -22604,14 +22642,14 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
22604
22642
  defaultContexts = [...defaultContexts, defaultContext];
22605
22643
  const Provider2 = (props) => {
22606
22644
  const { scope, children: children2, ...context } = props;
22607
- const Context = scope?.[scopeName]?.[index2] || BaseContext;
22645
+ const Context2 = scope?.[scopeName]?.[index2] || BaseContext;
22608
22646
  const value = React.useMemo(() => context, Object.values(context));
22609
- return /* @__PURE__ */ jsx(Context.Provider, { value, children: children2 });
22647
+ return /* @__PURE__ */ jsx(Context2.Provider, { value, children: children2 });
22610
22648
  };
22611
22649
  Provider2.displayName = rootComponentName + "Provider";
22612
22650
  function useContext2(consumerName, scope) {
22613
- const Context = scope?.[scopeName]?.[index2] || BaseContext;
22614
- const context = React.useContext(Context);
22651
+ const Context2 = scope?.[scopeName]?.[index2] || BaseContext;
22652
+ const context = React.useContext(Context2);
22615
22653
  if (context) return context;
22616
22654
  if (defaultContext !== void 0) return defaultContext;
22617
22655
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);