{"version":3,"file":"current-user-history.store-Ca48wRgT.js","sources":["../../../src/packages/user/current-user/history/current-user-history.store.ts"],"sourcesContent":["import { UMB_CURRENT_USER_HISTORY_STORE_CONTEXT } from './current-user-history.store.token.js';\r\nimport type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';\r\nimport { UmbId } from '@umbraco-cms/backoffice/id';\r\nimport { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';\r\nimport { UmbStoreBase } from '@umbraco-cms/backoffice/store';\r\n\r\nexport type UmbModelType = 'dialog' | 'sidebar';\r\n\r\nexport type UmbCurrentUserHistoryItem = {\r\n\tunique: string;\r\n\tpath: string;\r\n\tlabel: string | Array;\r\n\ticon?: string;\r\n};\r\n\r\nexport class UmbCurrentUserHistoryStore extends UmbStoreBase {\r\n\tpublic readonly history = this._data.asObservable();\r\n\tpublic readonly latestHistory = this._data.asObservablePart((historyItems) => historyItems.slice(-10));\r\n\r\n\tconstructor(host: UmbControllerHost) {\r\n\t\tsuper(\r\n\t\t\thost,\r\n\t\t\tUMB_CURRENT_USER_HISTORY_STORE_CONTEXT.toString(),\r\n\t\t\tnew UmbArrayState([], (x) => x.unique),\r\n\t\t);\r\n\t\tif (!('navigation' in window)) return;\r\n\t\t(window as any).navigation.addEventListener('navigate', (event: any) => {\r\n\t\t\tconst url = new URL(event.destination.url);\r\n\t\t\tconst historyItem = {\r\n\t\t\t\tunique: new UmbId().toString(),\r\n\t\t\t\tpath: url.pathname,\r\n\t\t\t\tlabel: event.destination.url.split('/').pop(),\r\n\t\t\t};\r\n\t\t\tthis.push(historyItem);\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Pushes a new history item to the history array\r\n\t * @public\r\n\t * @param {UmbCurrentUserHistoryItem} historyItem\r\n\t * @memberof UmbHistoryService\r\n\t */\r\n\tpublic push(historyItem: UmbCurrentUserHistoryItem): void {\r\n\t\tconst history = this._data.getValue();\r\n\t\tconst lastItem = history[history.length - 1];\r\n\r\n\t\t// This prevents duplicate entries in the history array.\r\n\t\tif (!lastItem || lastItem.path !== historyItem.path) {\r\n\t\t\tthis._data.setValue([...this._data.getValue(), historyItem]);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Clears the history array\r\n\t * @public\r\n\t * @memberof UmbHistoryService\r\n\t */\r\n\tpublic clear() {\r\n\t\tthis._data.setValue([]);\r\n\t}\r\n}\r\n\r\n// Default export for the globalContext manifest:\r\nexport default UmbCurrentUserHistoryStore;\r\n"],"names":["UmbCurrentUserHistoryStore","UmbStoreBase","host","UMB_CURRENT_USER_HISTORY_STORE_CONTEXT","UmbArrayState","x","historyItems","event","url","historyItem","UmbId","history","lastItem"],"mappings":";;;;AAeO,MAAMA,UAAmCC,EAAwC;AAAA,EAIvF,YAAYC,GAAyB;AAMhC,IALJ;AAAA,MACCA;AAAA,MACAC,EAAuC,SAAS;AAAA,MAChD,IAAIC,EAAyC,IAAI,CAACC,MAAMA,EAAE,MAAM;AAAA,IACjE,GARe,KAAA,UAAU,KAAK,MAAM,aAAa,GAClC,KAAA,gBAAgB,KAAK,MAAM,iBAAiB,CAACC,MAAiBA,EAAa,MAAM,GAAG,CAAC,GAQ9F,gBAAgB,UACrB,OAAe,WAAW,iBAAiB,YAAY,CAACC,MAAe;AACvE,YAAMC,IAAM,IAAI,IAAID,EAAM,YAAY,GAAG,GACnCE,IAAc;AAAA,QACnB,QAAQ,IAAIC,EAAM,EAAE,SAAS;AAAA,QAC7B,MAAMF,EAAI;AAAA,QACV,OAAOD,EAAM,YAAY,IAAI,MAAM,GAAG,EAAE,IAAI;AAAA,MAC7C;AACA,WAAK,KAAKE,CAAW;AAAA,IAAA,CACrB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASK,KAAKA,GAA8C;AACnD,UAAAE,IAAU,KAAK,MAAM,SAAS,GAC9BC,IAAWD,EAAQA,EAAQ,SAAS,CAAC;AAG3C,KAAI,CAACC,KAAYA,EAAS,SAASH,EAAY,SACzC,KAAA,MAAM,SAAS,CAAC,GAAG,KAAK,MAAM,YAAYA,CAAW,CAAC;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQM,QAAQ;AACT,SAAA,MAAM,SAAS,EAAE;AAAA,EAAA;AAExB;"}