{"version":3,"file":"ngxs-devtools-plugin.mjs","sources":["../../../packages/devtools-plugin/src/symbols.ts","../../../packages/devtools-plugin/src/devtools.plugin.ts","../../../packages/devtools-plugin/src/devtools.module.ts","../../../packages/devtools-plugin/index.ts","../../../packages/devtools-plugin/ngxs-devtools-plugin.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\n/**\n * Interface for the redux-devtools-extension API.\n */\nexport interface NgxsDevtoolsExtension {\n  init(state: any): void;\n  send(action: any, state?: any): void;\n  subscribe(fn: (message: NgxsDevtoolsAction) => void): VoidFunction;\n}\n\nexport interface NgxsDevtoolsAction {\n  type: string;\n  payload: any;\n  state: any;\n  id: number;\n  source: string;\n}\n\nexport interface NgxsDevtoolsOptions {\n  /**\n   * The name of the extension\n   */\n  name?: string;\n\n  /**\n   * Whether the dev tools is enabled or note. Useful for setting during production.\n   */\n  disabled?: boolean;\n\n  /**\n   * Max number of entiries to keep.\n   */\n  maxAge?: number;\n\n  /**\n   * If more than one action is dispatched in the indicated interval, all new actions will be collected\n   * and sent at once. It is the joint between performance and speed. When set to 0, all actions will be\n   * sent instantly. Set it to a higher value when experiencing perf issues (also maxAge to a lower value).\n   * Default is 500 ms.\n   */\n  latency?: number;\n\n  /**\n   * string or array of strings as regex - actions types to be hidden in the monitors (while passed to the reducers).\n   * If actionsWhitelist specified, actionsBlacklist is ignored.\n   */\n  actionsBlacklist?: string | string[];\n\n  /**\n   * string or array of strings as regex - actions types to be shown in the monitors (while passed to the reducers).\n   * If actionsWhitelist specified, actionsBlacklist is ignored.\n   */\n  actionsWhitelist?: string | string[];\n\n  /**\n   * called for every action before sending, takes state and action object, and returns true in case it allows\n   * sending the current data to the monitor. Use it as a more advanced version of\n   * actionsBlacklist/actionsWhitelist parameters\n   */\n  predicate?: (state: any, action: any) => boolean;\n\n  /**\n   * Reformat actions before sending to dev tools\n   */\n  actionSanitizer?: (action: any) => void;\n\n  /**\n   * Reformat state before sending to devtools\n   */\n  stateSanitizer?: (state: any) => void;\n\n  /**\n   * If set to true, will include stack trace for every dispatched action\n   */\n  trace?: boolean | (() => string);\n\n  /**\n   * Maximum stack trace frames to be stored (in case trace option was provided as true)\n   */\n  traceLimit?: number;\n\n  /**\n   * https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md#serialize\n   */\n  serialize?:\n    | boolean\n    | {\n        /**\n         * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode).\n         * - `false` - will handle also circular references.\n         * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions.\n         * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys.\n         *   For each of them you can indicate if to include (by setting as `true`).\n         *   For `function` key you can also specify a custom function which handles serialization.\n         *   See [`jsan`](https://github.com/kolodny/jsan) for more details.\n         */\n        options?:\n          | undefined\n          | boolean\n          | {\n              date?: true;\n              regex?: true;\n              undefined?: true;\n              error?: true;\n              symbol?: true;\n              map?: true;\n              set?: true;\n              function?: true | ((fn: (...args: any[]) => any) => string);\n            };\n        /**\n         * [JSON replacer function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) used for both actions and states stringify.\n         * In addition, you can specify a data type by adding a [`__serializedType__`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/helpers/index.js#L4)\n         * key. So you can deserialize it back while importing or persisting data.\n         * Moreover, it will also [show a nice preview showing the provided custom type](https://cloud.githubusercontent.com/assets/7957859/21814330/a17d556a-d761-11e6-85ef-159dd12f36c5.png):\n         */\n        replacer?: (key: string, value: unknown) => any;\n        /**\n         * [JSON `reviver` function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter)\n         * used for parsing the imported actions and states. See [`remotedev-serialize`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/immutable/serialize.js#L8-L41)\n         * as an example on how to serialize special data types and get them back.\n         */\n        reviver?: (key: string, value: unknown) => any;\n      };\n}\n\nexport const NGXS_DEVTOOLS_OPTIONS = new InjectionToken<NgxsDevtoolsOptions>(\n  'NGXS_DEVTOOLS_OPTIONS'\n);\n","import { DestroyRef, inject, Injectable, Injector, NgZone, ɵglobal } from '@angular/core';\nimport { Store } from '@ngxs/store';\nimport {\n  InitState,\n  getActionTypeFromInstance,\n  NgxsNextPluginFn,\n  NgxsPlugin\n} from '@ngxs/store/plugins';\nimport { tap, catchError } from 'rxjs';\n\nimport { NGXS_DEVTOOLS_OPTIONS, NgxsDevtoolsAction, NgxsDevtoolsExtension } from './symbols';\n\nconst enum ReduxDevtoolsActionType {\n  Dispatch = 'DISPATCH',\n  Action = 'ACTION'\n}\n\nconst enum ReduxDevtoolsPayloadType {\n  JumpToAction = 'JUMP_TO_ACTION',\n  JumpToState = 'JUMP_TO_STATE',\n  ToggleAction = 'TOGGLE_ACTION',\n  ImportState = 'IMPORT_STATE'\n}\n\n/**\n * Adds support for the Redux Devtools extension:\n * http://extension.remotedev.io/\n */\n@Injectable()\nexport class NgxsReduxDevtoolsPlugin implements NgxsPlugin {\n  private _injector = inject(Injector);\n  private _ngZone = inject(NgZone);\n  private _options = inject(NGXS_DEVTOOLS_OPTIONS);\n\n  private devtoolsExtension: NgxsDevtoolsExtension | null = null;\n  private readonly globalDevtools =\n    ɵglobal['__REDUX_DEVTOOLS_EXTENSION__'] || ɵglobal['devToolsExtension'];\n\n  private unsubscribe: VoidFunction | null = null;\n\n  constructor() {\n    this.connect();\n\n    inject(DestroyRef).onDestroy(() => {\n      this.unsubscribe?.();\n      this.globalDevtools?.disconnect();\n    });\n  }\n\n  /**\n   * Lazy get the store for circular dependency issues\n   */\n  private get store(): Store {\n    return this._injector.get<Store>(Store);\n  }\n\n  /**\n   * Middleware handle function\n   */\n  handle(state: any, action: any, next: NgxsNextPluginFn) {\n    if (!this.devtoolsExtension || this._options.disabled) {\n      return next(state, action);\n    }\n\n    return next(state, action).pipe(\n      catchError(error => {\n        const newState = this.store.snapshot();\n        this.sendToDevTools(state, action, newState);\n        throw error;\n      }),\n      tap(newState => {\n        this.sendToDevTools(state, action, newState);\n      })\n    );\n  }\n\n  private sendToDevTools(state: any, action: any, newState: any) {\n    const type = getActionTypeFromInstance(action);\n    // if init action, send initial state to dev tools\n    const isInitAction = type === InitState.type;\n    if (isInitAction) {\n      this.devtoolsExtension!.init(state);\n    } else {\n      this.devtoolsExtension!.send({ ...action, action: null, type }, newState);\n    }\n  }\n\n  /**\n   * Handle the action from the dev tools subscription\n   */\n  dispatched(action: NgxsDevtoolsAction) {\n    if (action.type === ReduxDevtoolsActionType.Dispatch) {\n      if (\n        action.payload.type === ReduxDevtoolsPayloadType.JumpToAction ||\n        action.payload.type === ReduxDevtoolsPayloadType.JumpToState\n      ) {\n        const prevState = JSON.parse(action.state);\n        // This makes the DevTools and Router plugins compatible with each other.\n        // We check for the existence of the `router` state and ensure it has the\n        // `trigger` property, confirming that it is our router state (coming from `@ngxs/router-plugin`).\n        // This enables a time-traveling feature, as it not only restores the state but\n        // also allows the `RouterState` to navigate back when the action is jumped.\n        if (prevState.router?.trigger) {\n          prevState.router.trigger = 'devtools';\n        }\n        this.store.reset(prevState);\n      } else if (action.payload.type === ReduxDevtoolsPayloadType.ToggleAction) {\n        console.warn('Skip is not supported at this time.');\n      } else if (action.payload.type === ReduxDevtoolsPayloadType.ImportState) {\n        const { actionsById, computedStates, currentStateIndex } =\n          action.payload.nextLiftedState;\n        this.devtoolsExtension!.init(computedStates[0].state);\n        Object.keys(actionsById)\n          .filter(actionId => actionId !== '0')\n          .forEach(actionId =>\n            this.devtoolsExtension!.send(actionsById[actionId], computedStates[actionId].state)\n          );\n        this.store.reset(computedStates[currentStateIndex].state);\n      }\n    } else if (action.type === ReduxDevtoolsActionType.Action) {\n      const actionPayload = JSON.parse(action.payload);\n      this.store.dispatch(actionPayload);\n    }\n  }\n\n  private connect(): void {\n    if (!this.globalDevtools || this._options.disabled) {\n      return;\n    }\n\n    // The `connect` method adds a `message` event listener to communicate\n    // with an extension through `window.postMessage` and handle message events.\n    // Since we only handle two specific events, we aim to avoid unnecessary change\n    // detections triggered by events that the extension sends, but we don't need to handle.\n    this.devtoolsExtension = this._ngZone.runOutsideAngular(\n      () => <NgxsDevtoolsExtension>this.globalDevtools.connect(this._options)\n    );\n\n    this.unsubscribe = this.devtoolsExtension.subscribe(action => {\n      if (\n        action.type === ReduxDevtoolsActionType.Dispatch ||\n        action.type === ReduxDevtoolsActionType.Action\n      ) {\n        this.dispatched(action);\n      }\n    });\n  }\n}\n","import {\n  NgModule,\n  ModuleWithProviders,\n  InjectionToken,\n  EnvironmentProviders,\n  makeEnvironmentProviders\n} from '@angular/core';\nimport { withNgxsPlugin } from '@ngxs/store';\n\nimport { NgxsDevtoolsOptions, NGXS_DEVTOOLS_OPTIONS } from './symbols';\nimport { NgxsReduxDevtoolsPlugin } from './devtools.plugin';\n\nexport function devtoolsOptionsFactory(options: NgxsDevtoolsOptions) {\n  return {\n    name: 'NGXS',\n    ...options\n  };\n}\n\nexport const USER_OPTIONS = new InjectionToken('USER_OPTIONS');\n\n@NgModule()\nexport class NgxsReduxDevtoolsPluginModule {\n  static forRoot(\n    options?: NgxsDevtoolsOptions\n  ): ModuleWithProviders<NgxsReduxDevtoolsPluginModule> {\n    return {\n      ngModule: NgxsReduxDevtoolsPluginModule,\n      providers: [\n        withNgxsPlugin(NgxsReduxDevtoolsPlugin),\n        {\n          provide: USER_OPTIONS,\n          useValue: options\n        },\n        {\n          provide: NGXS_DEVTOOLS_OPTIONS,\n          useFactory: devtoolsOptionsFactory,\n          deps: [USER_OPTIONS]\n        }\n      ]\n    };\n  }\n}\n\nexport function withNgxsReduxDevtoolsPlugin(\n  options?: NgxsDevtoolsOptions\n): EnvironmentProviders {\n  return makeEnvironmentProviders([\n    withNgxsPlugin(NgxsReduxDevtoolsPlugin),\n    {\n      provide: USER_OPTIONS,\n      useValue: options\n    },\n    {\n      provide: NGXS_DEVTOOLS_OPTIONS,\n      useFactory: devtoolsOptionsFactory,\n      deps: [USER_OPTIONS]\n    }\n  ]);\n}\n","/**\n * The public api for consumers of @ngxs/devtools-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["ɵglobal"],"mappings":";;;;;;MA8Ha,qBAAqB,GAAG,IAAI,cAAc,CACrD,uBAAuB;;ACnHzB,IAAW,uBAGV;AAHD,CAAA,UAAW,uBAAuB,EAAA;AAChC,IAAA,uBAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACrB,IAAA,uBAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EAHU,uBAAuB,KAAvB,uBAAuB,GAGjC,EAAA,CAAA,CAAA;AAED,IAAW,wBAKV;AALD,CAAA,UAAW,wBAAwB,EAAA;AACjC,IAAA,wBAAA,CAAA,cAAA,CAAA,GAAA,gBAA+B;AAC/B,IAAA,wBAAA,CAAA,aAAA,CAAA,GAAA,eAA6B;AAC7B,IAAA,wBAAA,CAAA,cAAA,CAAA,GAAA,eAA8B;AAC9B,IAAA,wBAAA,CAAA,aAAA,CAAA,GAAA,cAA4B;AAC9B,CAAC,EALU,wBAAwB,KAAxB,wBAAwB,GAKlC,EAAA,CAAA,CAAA;AAED;;;AAGG;MAEU,uBAAuB,CAAA;AAC1B,IAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC5B,IAAA,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;AACxB,IAAA,QAAQ,GAAG,MAAM,CAAC,qBAAqB,CAAC;IAExC,iBAAiB,GAAiC,IAAI;IAC7C,cAAc,GAC7BA,OAAO,CAAC,8BAA8B,CAAC,IAAIA,OAAO,CAAC,mBAAmB,CAAC;IAEjE,WAAW,GAAwB,IAAI;AAE/C,IAAA,WAAA,GAAA;QACE,IAAI,CAAC,OAAO,EAAE;AAEd,QAAA,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,MAAK;AAChC,YAAA,IAAI,CAAC,WAAW,IAAI;AACp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