@oliasoft-open-source/charts-library 4.1.2 → 4.1.3

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/index.js CHANGED
@@ -25099,6 +25099,7 @@ const getDraggableData = (options) => {
25099
25099
  };
25100
25100
  const UPSERT_HIDDEN_STATE = "UPSERT_HIDDEN_STATE";
25101
25101
  const TOGGLE_ANNOTATION_VISIBILITY = "TOGGLE_ANNOTATION_VISIBILITY";
25102
+ const RESET_STATE = "RESET_STATE";
25102
25103
  const legendInitialState = {
25103
25104
  hiddenStates: [],
25104
25105
  annotation: [],
@@ -25106,6 +25107,9 @@ const legendInitialState = {
25106
25107
  };
25107
25108
  const legendReducer = (state, action) => {
25108
25109
  switch (action.type) {
25110
+ case RESET_STATE: {
25111
+ return action.payload;
25112
+ }
25109
25113
  case UPSERT_HIDDEN_STATE: {
25110
25114
  const { label, hidden, datasetIndex } = action.payload;
25111
25115
  const existingIndex = state.hiddenStates.findIndex(
@@ -25229,6 +25233,15 @@ const getAnnotation = ({
25229
25233
  const shouldGenerateAnnotations = showAnnotations && annotationsData && (annotationsData == null ? void 0 : annotationsData.length);
25230
25234
  return shouldGenerateAnnotations ? generateAnnotations(annotationsData, visibleAnnotationsIndexes) ?? [] : [];
25231
25235
  };
25236
+ const useReset = (state, dispatch, dependencies) => {
25237
+ const prevState = useRef(state);
25238
+ useEffect(() => {
25239
+ if (!isEqual(state, prevState == null ? void 0 : prevState.current)) {
25240
+ dispatch({ type: "RESET_STATE", payload: state });
25241
+ prevState.current = state;
25242
+ }
25243
+ }, [...dependencies]);
25244
+ };
25232
25245
  const LegendContext = createContext$2(void 0);
25233
25246
  const LegendProvider = ({ children, options }) => {
25234
25247
  const { showAnnotations = true, annotationsData = [] } = (options == null ? void 0 : options.annotations) ?? {};
@@ -25247,7 +25260,11 @@ const LegendProvider = ({ children, options }) => {
25247
25260
  legendReducer,
25248
25261
  initialState2
25249
25262
  );
25250
- const contextValue = useMemo(() => ({ state, dispatch }), [state, dispatch]);
25263
+ const contextValue = useMemo(
25264
+ () => ({ state, dispatch }),
25265
+ [state, options, dispatch]
25266
+ );
25267
+ useReset(initialState2, dispatch, [options]);
25251
25268
  return /* @__PURE__ */ jsx(LegendContext.Provider, { value: contextValue, children });
25252
25269
  };
25253
25270
  const useLegend = () => {