@powerhousedao/connect 1.0.4 → 1.0.5-dev.0
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/LICENSE +661 -0
- package/README.md +1 -0
- package/dist/.env +11 -6
- package/dist/assets/app-CcH3qGge.css +5805 -0
- package/dist/assets/app-D5aQi0aY.js +80396 -0
- package/dist/assets/app-loader-D5SWSIlq.js +31582 -0
- package/dist/assets/app-loader-DGByWxSG.css +5640 -0
- package/dist/assets/ccip-BmvACOxw.js +170 -0
- package/dist/assets/connect-loader-CvOC68Ih.mp4 +0 -0
- package/dist/assets/content-CjM3gin6.js +3967 -0
- package/dist/assets/home-bg-BEhF9NuW.png +0 -0
- package/dist/assets/index-D60iiT4f.js +2560 -0
- package/dist/assets/index-DIYv2p_P.js +12 -0
- package/dist/assets/index-d_545vU_.js +46565 -0
- package/dist/assets/main.DnroXr_4.js +105 -0
- package/dist/assets/powerhouse-rounded-CeKGGUG4.png +0 -0
- package/dist/assets/renown-short-hover-BiSLBV7L.png +0 -0
- package/dist/assets/rwa-report-Bb0W5-ac.png +0 -0
- package/dist/assets/style-Ce3V83BE.css +1658 -0
- package/dist/external-packages.js +5 -0
- package/dist/hmr.js +4 -0
- package/dist/icon.ico +0 -0
- package/dist/index.html +48 -10
- package/dist/modules/@powerhousedao/reactor-browser/chunk-2ESYSVXG.js +48 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-2ONJ2PX4.js +50 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-2X2M6BYG.js +2542 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-64UP3MVE.js +14171 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-7OQWVUC5.js +43 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-C7QRY43M.js +786 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-CO2RVWYY.js +67 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-DKDARAJS.js +0 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-F6NNSREE.js +2513 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-FQF4YAVC.js +11917 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-GDP7BUIH.js +45 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-IQTSFTNF.js +48 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-J5TYPY7U.js +36 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-LH2T6NLN.js +0 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-LRNZZ3SR.js +14 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-NHD6VUCD.js +53 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-OVGOA2P5.js +11 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-P6NJ6IAQ.js +12 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-QXHTR6KF.js +0 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-RGIB4DD4.js +162 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-U34SEKEB.js +250 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-U36SV333.js +0 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-UWJGRLW3.js +82 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-XBTEGV5M.js +17 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-Y7NTRTMT.js +25 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-YG67WAIS.js +0 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-YSOX63EM.js +178 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-YWKVPJNL.js +52 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-ZL5IPB6D.js +0 -0
- package/dist/modules/@powerhousedao/reactor-browser/chunk-ZWFCVUBU.js +113 -0
- package/dist/modules/@powerhousedao/reactor-browser/context/index.js +16 -0
- package/dist/modules/@powerhousedao/reactor-browser/context/read-mode.js +15 -0
- package/dist/modules/@powerhousedao/reactor-browser/crypto/browser.js +7 -0
- package/dist/modules/@powerhousedao/reactor-browser/crypto/index.js +7 -0
- package/dist/modules/@powerhousedao/reactor-browser/document-model.js +10 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/document-state.js +96 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/index.js +98 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useAddDebouncedOperations.js +11 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useConnectCrypto.js +12 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocument.js +7 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentDispatch.js +7 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentDrives.js +13 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentEditor.js +20 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActions.js +9 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes.js +14 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveContext.js +9 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useUiNodesContext.js +46 -0
- package/dist/modules/@powerhousedao/reactor-browser/hooks/useUserPermissions.js +7 -0
- package/dist/modules/@powerhousedao/reactor-browser/index.js +125 -0
- package/dist/modules/@powerhousedao/reactor-browser/reactor.js +11 -0
- package/dist/modules/@powerhousedao/reactor-browser/renown/constants.js +53 -0
- package/dist/modules/@powerhousedao/reactor-browser/renown/types.js +1 -0
- package/dist/modules/@powerhousedao/reactor-browser/storage/index.js +1 -0
- package/dist/modules/@powerhousedao/reactor-browser/storage/types.js +1 -0
- package/dist/modules/@powerhousedao/reactor-browser/uiNodes/constants.js +37 -0
- package/dist/modules/@powerhousedao/reactor-browser/uiNodes/types.js +1 -0
- package/dist/modules/@powerhousedao/reactor-browser/utils/export-document.js +8 -0
- package/dist/modules/@powerhousedao/reactor-browser/utils/index.js +9 -0
- package/dist/modules/@powerhousedao/reactor-browser/utils/signature.js +10 -0
- package/dist/service-worker.js +46 -2
- package/dist/swEnv.js +9 -8
- package/dist/vite-envs.sh +56 -35
- package/nginx.conf +93 -0
- package/nginx.sh +10 -0
- package/package.json +36 -50
- package/dist/assets/ArrowFilledRight-blx8xu7X-D3d8PUWh.js +0 -2
- package/dist/assets/ArrowFilledRight-blx8xu7X-D3d8PUWh.js.map +0 -1
- package/dist/assets/ArrowLeft-7pYNK4eX-8ZR_YHAJ.js +0 -2
- package/dist/assets/ArrowLeft-7pYNK4eX-8ZR_YHAJ.js.map +0 -1
- package/dist/assets/ArrowUp-Bbr_dwo_-C5ppCQo4.js +0 -2
- package/dist/assets/ArrowUp-Bbr_dwo_-C5ppCQo4.js.map +0 -1
- package/dist/assets/BarChart-B0G05Nfd-CHDJ7OaJ.js +0 -2
- package/dist/assets/BarChart-B0G05Nfd-CHDJ7OaJ.js.map +0 -1
- package/dist/assets/BaseArrowLeft-DBzhFHMt-Dkbf2sWs.js +0 -2
- package/dist/assets/BaseArrowLeft-DBzhFHMt-Dkbf2sWs.js.map +0 -1
- package/dist/assets/BaseArrowRight-DYQTBWAs-CkkPllYm.js +0 -2
- package/dist/assets/BaseArrowRight-DYQTBWAs-CkkPllYm.js.map +0 -1
- package/dist/assets/Braces-N-sH2Zyc-3LcexUsR.js +0 -2
- package/dist/assets/Braces-N-sH2Zyc-3LcexUsR.js.map +0 -1
- package/dist/assets/Branch-CWdBw1_P-CmGdOXsI.js +0 -2
- package/dist/assets/Branch-CWdBw1_P-CmGdOXsI.js.map +0 -1
- package/dist/assets/BrickGlobe-67zaG6_H-DP0By6z_.js +0 -2
- package/dist/assets/BrickGlobe-67zaG6_H-DP0By6z_.js.map +0 -1
- package/dist/assets/Briefcase-CedW3KRR-DO5_k15F.js +0 -2
- package/dist/assets/Briefcase-CedW3KRR-DO5_k15F.js.map +0 -1
- package/dist/assets/Calendar-C-6HV96D-YetudWvP.js +0 -2
- package/dist/assets/Calendar-C-6HV96D-YetudWvP.js.map +0 -1
- package/dist/assets/Caret-Ep0j0fz2-By3ojfim.js +0 -2
- package/dist/assets/Caret-Ep0j0fz2-By3ojfim.js.map +0 -1
- package/dist/assets/CaretDown-3X7LFYBf-C43xdKg8.js +0 -2
- package/dist/assets/CaretDown-3X7LFYBf-C43xdKg8.js.map +0 -1
- package/dist/assets/CaretSort-BkGdLETT-DVOzEEqR.js +0 -2
- package/dist/assets/CaretSort-BkGdLETT-DVOzEEqR.js.map +0 -1
- package/dist/assets/Check-DV-U4AEq-B582NMZp.js +0 -2
- package/dist/assets/Check-DV-U4AEq-B582NMZp.js.map +0 -1
- package/dist/assets/CheckCircle-DI5fEgGd-CVF4LDhR.js +0 -2
- package/dist/assets/CheckCircle-DI5fEgGd-CVF4LDhR.js.map +0 -1
- package/dist/assets/CheckCircleFill-C-F0v5mB-BSW1YMqM.js +0 -2
- package/dist/assets/CheckCircleFill-C-F0v5mB-BSW1YMqM.js.map +0 -1
- package/dist/assets/Checkmark-BXnfChpo-CyQitGI2.js +0 -2
- package/dist/assets/Checkmark-BXnfChpo-CyQitGI2.js.map +0 -1
- package/dist/assets/ChevronDown-ouBxrU-k-eUsCPXcB.js +0 -2
- package/dist/assets/ChevronDown-ouBxrU-k-eUsCPXcB.js.map +0 -1
- package/dist/assets/Circle-n3-Wh4HS-8dOehHQf.js +0 -2
- package/dist/assets/Circle-n3-Wh4HS-8dOehHQf.js.map +0 -1
- package/dist/assets/CircleInfo-BhZY3C2Q-CZgYK1h2.js +0 -2
- package/dist/assets/CircleInfo-BhZY3C2Q-CZgYK1h2.js.map +0 -1
- package/dist/assets/ClockFill-Bd0t48q7-CcfHiJtH.js +0 -2
- package/dist/assets/ClockFill-Bd0t48q7-CcfHiJtH.js.map +0 -1
- package/dist/assets/CloudSlash-B-zJBjaD-CxVyp-Ac.js +0 -2
- package/dist/assets/CloudSlash-B-zJBjaD-CxVyp-Ac.js.map +0 -1
- package/dist/assets/Collapse-DRDB8Czs-CGcuZQgy.js +0 -2
- package/dist/assets/Collapse-DRDB8Czs-CGcuZQgy.js.map +0 -1
- package/dist/assets/Connect-Dme-qfKq-CgniLji8.js +0 -2
- package/dist/assets/Connect-Dme-qfKq-CgniLji8.js.map +0 -1
- package/dist/assets/Discord-CAS0Cj7s-CcsBWpnf.js +0 -2
- package/dist/assets/Discord-CAS0Cj7s-CcsBWpnf.js.map +0 -1
- package/dist/assets/Drive-GMcgBcIY-CzahDx9j.js +0 -2
- package/dist/assets/Drive-GMcgBcIY-CzahDx9j.js.map +0 -1
- package/dist/assets/Ellipsis-XK8AwMEC-BuVBeYhB.js +0 -2
- package/dist/assets/Ellipsis-XK8AwMEC-BuVBeYhB.js.map +0 -1
- package/dist/assets/Error-BmIZ2ZUy-CphzuMLn.js +0 -2
- package/dist/assets/Error-BmIZ2ZUy-CphzuMLn.js.map +0 -1
- package/dist/assets/Exclamation-CVsNS_QS-DLccamql.js +0 -2
- package/dist/assets/Exclamation-CVsNS_QS-DLccamql.js.map +0 -1
- package/dist/assets/FilesEarmark-CyrCQy8E-Bhut4E02.js +0 -2
- package/dist/assets/FilesEarmark-CyrCQy8E-Bhut4E02.js.map +0 -1
- package/dist/assets/FolderClose-DG_qHisc-CH6NoBuu.js +0 -2
- package/dist/assets/FolderClose-DG_qHisc-CH6NoBuu.js.map +0 -1
- package/dist/assets/FolderOpen-kDoWFkJO-Cciutkdg.js +0 -2
- package/dist/assets/FolderOpen-kDoWFkJO-Cciutkdg.js.map +0 -1
- package/dist/assets/FolderPlus-CSBSl9lZ-CifD0ek9.js +0 -2
- package/dist/assets/FolderPlus-CSBSl9lZ-CifD0ek9.js.map +0 -1
- package/dist/assets/Forum-DZ-CkLFh-BwabccAX.js +0 -2
- package/dist/assets/Forum-DZ-CkLFh-BwabccAX.js.map +0 -1
- package/dist/assets/Gear-cUlHJ4q6-B9R2l_9_.js +0 -2
- package/dist/assets/Gear-cUlHJ4q6-B9R2l_9_.js.map +0 -1
- package/dist/assets/Github-0PLiINY0-CjkZIHCO.js +0 -2
- package/dist/assets/Github-0PLiINY0-CjkZIHCO.js.map +0 -1
- package/dist/assets/Globe-CIYqVkpa-CL530H46.js +0 -2
- package/dist/assets/Globe-CIYqVkpa-CL530H46.js.map +0 -1
- package/dist/assets/GlobeWww-DN4yKujh-Ci7aa5CE.js +0 -2
- package/dist/assets/GlobeWww-DN4yKujh-Ci7aa5CE.js.map +0 -1
- package/dist/assets/Hdd-Dn_LdJIh-CJ6x9Bve.js +0 -2
- package/dist/assets/Hdd-Dn_LdJIh-CJ6x9Bve.js.map +0 -1
- package/dist/assets/History-BP4SmaS_-P4WBKyqX.js +0 -2
- package/dist/assets/History-BP4SmaS_-P4WBKyqX.js.map +0 -1
- package/dist/assets/InfoSquare-C98JaLiz-yPcGR71f.js +0 -2
- package/dist/assets/InfoSquare-C98JaLiz-yPcGR71f.js.map +0 -1
- package/dist/assets/Link-BF7aZjVu-CXIVQOz6.js +0 -2
- package/dist/assets/Link-BF7aZjVu-CXIVQOz6.js.map +0 -1
- package/dist/assets/Linkedin-DJwIkS6q-Dkb5Tp_Z.js +0 -2
- package/dist/assets/Linkedin-DJwIkS6q-Dkb5Tp_Z.js.map +0 -1
- package/dist/assets/Lock-PyaFHdNS-D_qxRTye.js +0 -2
- package/dist/assets/Lock-PyaFHdNS-D_qxRTye.js.map +0 -1
- package/dist/assets/M-DozhhPMY-DBQw97P_.js +0 -2
- package/dist/assets/M-DozhhPMY-DBQw97P_.js.map +0 -1
- package/dist/assets/Pencil-D7lvxXIP-D830iveq.js +0 -2
- package/dist/assets/Pencil-D7lvxXIP-D830iveq.js.map +0 -1
- package/dist/assets/People-CUB8LYKf-CyJmMqcw.js +0 -2
- package/dist/assets/People-CUB8LYKf-CyJmMqcw.js.map +0 -1
- package/dist/assets/Person-DuL4PQzm-ttQR0nPy.js +0 -2
- package/dist/assets/Person-DuL4PQzm-ttQR0nPy.js.map +0 -1
- package/dist/assets/Plus-DPFWGJM4-BztpK8li.js +0 -2
- package/dist/assets/Plus-DPFWGJM4-BztpK8li.js.map +0 -1
- package/dist/assets/PlusCircle-BEnWRjHa-w5zztKGx.js +0 -2
- package/dist/assets/PlusCircle-BEnWRjHa-w5zztKGx.js.map +0 -1
- package/dist/assets/PowerhouseLogoSmall-CmO95IAS-CDGLkst3.js +0 -2
- package/dist/assets/PowerhouseLogoSmall-CmO95IAS-CDGLkst3.js.map +0 -1
- package/dist/assets/Project-BlXuclr0-EsBam9d0.js +0 -2
- package/dist/assets/Project-BlXuclr0-EsBam9d0.js.map +0 -1
- package/dist/assets/RedoArrow-BJeEsiph-BbidqIFP.js +0 -2
- package/dist/assets/RedoArrow-BJeEsiph-BbidqIFP.js.map +0 -1
- package/dist/assets/Renown-6m7hx37h-CItksi2j.js +0 -2
- package/dist/assets/Renown-6m7hx37h-CItksi2j.js.map +0 -1
- package/dist/assets/RenownHover-CQ0TZHZv-cYQgnwQW.js +0 -2
- package/dist/assets/RenownHover-CQ0TZHZv-cYQgnwQW.js.map +0 -1
- package/dist/assets/Ring-DKv0gnwT-CDHLz87h.js +0 -2
- package/dist/assets/Ring-DKv0gnwT-CDHLz87h.js.map +0 -1
- package/dist/assets/Save-BBxj68pn-BkUvn89C.js +0 -2
- package/dist/assets/Save-BBxj68pn-BkUvn89C.js.map +0 -1
- package/dist/assets/Search-YUJuRBLe-CecGUkZA.js +0 -2
- package/dist/assets/Search-YUJuRBLe-CecGUkZA.js.map +0 -1
- package/dist/assets/Server-Bfkkjui1-lBan_3Dm.js +0 -2
- package/dist/assets/Server-Bfkkjui1-lBan_3Dm.js.map +0 -1
- package/dist/assets/Settings-mbbylBS5-Cca-sV-_.js +0 -2
- package/dist/assets/Settings-mbbylBS5-Cca-sV-_.js.map +0 -1
- package/dist/assets/Synced-DKJXzPiw-Cui8pDsS.js +0 -2
- package/dist/assets/Synced-DKJXzPiw-Cui8pDsS.js.map +0 -1
- package/dist/assets/Syncing-aT9WSMFf-2VhhyCcX.js +0 -2
- package/dist/assets/Syncing-aT9WSMFf-2VhhyCcX.js.map +0 -1
- package/dist/assets/Trash-CgSbHk-P-DIYkVMER.js +0 -2
- package/dist/assets/Trash-CgSbHk-P-DIYkVMER.js.map +0 -1
- package/dist/assets/TrashFill-DN50ercb-Oqx67xXN.js +0 -2
- package/dist/assets/TrashFill-DN50ercb-Oqx67xXN.js.map +0 -1
- package/dist/assets/VariantArrowLeft-CnuX59_e-6Zt_Q3tm.js +0 -2
- package/dist/assets/VariantArrowLeft-CnuX59_e-6Zt_Q3tm.js.map +0 -1
- package/dist/assets/VerticalDots-C8QYf7et-CCxZfvjq.js +0 -2
- package/dist/assets/VerticalDots-C8QYf7et-CCxZfvjq.js.map +0 -1
- package/dist/assets/WarningFill-WowAvi5P-D5XCckM6.js +0 -2
- package/dist/assets/WarningFill-WowAvi5P-D5XCckM6.js.map +0 -1
- package/dist/assets/XTwitter-k3Pt8itk-mvLk8TKx.js +0 -2
- package/dist/assets/XTwitter-k3Pt8itk-mvLk8TKx.js.map +0 -1
- package/dist/assets/Xmark-8qnJCs2Y-CZ3t0Fap.js +0 -2
- package/dist/assets/Xmark-8qnJCs2Y-CZ3t0Fap.js.map +0 -1
- package/dist/assets/XmarkLight-GHzDR5_F-CloMvuzt.js +0 -2
- package/dist/assets/XmarkLight-GHzDR5_F-CloMvuzt.js.map +0 -1
- package/dist/assets/Youtube-i8V0IXUU-Bkiwoayp.js +0 -2
- package/dist/assets/Youtube-i8V0IXUU-Bkiwoayp.js.map +0 -1
- package/dist/assets/app-BdM_bCqD.js +0 -842
- package/dist/assets/app-BdM_bCqD.js.map +0 -1
- package/dist/assets/app-loader-B7xllAoS.js +0 -3
- package/dist/assets/app-loader-B7xllAoS.js.map +0 -1
- package/dist/assets/app-loader-D5wPX62N.css +0 -1
- package/dist/assets/browser-CwKAjz_f.js +0 -43
- package/dist/assets/browser-CwKAjz_f.js.map +0 -1
- package/dist/assets/browser-Dmr6AWWk.js +0 -2
- package/dist/assets/browser-Dmr6AWWk.js.map +0 -1
- package/dist/assets/ccip-BoVyVgwR.js +0 -2
- package/dist/assets/ccip-BoVyVgwR.js.map +0 -1
- package/dist/assets/content-BmCNR4Pw.js +0 -6
- package/dist/assets/content-BmCNR4Pw.js.map +0 -1
- package/dist/assets/editor-Cma-7Z7k.js +0 -2
- package/dist/assets/editor-Cma-7Z7k.js.map +0 -1
- package/dist/assets/editor-IMwm8pim.js +0 -2
- package/dist/assets/editor-IMwm8pim.js.map +0 -1
- package/dist/assets/editor-vgD9wEAH.js +0 -2
- package/dist/assets/editor-vgD9wEAH.js.map +0 -1
- package/dist/assets/editors-DQC0rqOg.js +0 -347
- package/dist/assets/editors-DQC0rqOg.js.map +0 -1
- package/dist/assets/index-BP2fj1j6.js +0 -16
- package/dist/assets/index-BP2fj1j6.js.map +0 -1
- package/dist/assets/index-SwNHx8hV.js +0 -3
- package/dist/assets/index-SwNHx8hV.js.map +0 -1
- package/dist/assets/index-T6Et30Eh-CdVwpIBO.js +0 -12
- package/dist/assets/index-T6Et30Eh-CdVwpIBO.js.map +0 -1
- package/dist/assets/main.DQ-aV7Qq.js +0 -2
- package/dist/assets/main.DQ-aV7Qq.js.map +0 -1
- package/dist/assets/root-BKJF0Yl6.js +0 -12
- package/dist/assets/root-BKJF0Yl6.js.map +0 -1
- package/dist/assets/router-Hd499Vrp.js +0 -12
- package/dist/assets/router-Hd499Vrp.js.map +0 -1
- package/dist/assets/useUiNodes-Ch-W4vsB.js +0 -107
- package/dist/assets/useUiNodes-Ch-W4vsB.js.map +0 -1
- package/dist/service-worker.js.map +0 -1
- package/dist/studio/cli.js +0 -6
- package/dist/studio/helpers.d.ts +0 -2
- package/dist/studio/index.d.ts +0 -20
- package/dist/studio/index.js +0 -580
- package/dist/studio/server.d.ts +0 -7
- package/dist/studio/vite-plugin.d.ts +0 -12
|
@@ -0,0 +1,3967 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
2
|
+
import { t as twMerge, B as Button, m as mergeClassNameProps, E as ERROR, M as MISSING, C as CONFLICT, S as SUCCESS, h as SYNCING, I as INITIAL_SYNC, i as ConnectDropdownMenu, u as useOnClickOutside, j as useEventListener, k as useCopyToClipboard, l as Select, n as ENSAvatar, P as Provider, o as Root3, T as Trigger, p as Portal, q as Content2, v as validateInitialState, w as validateStateSchemaName, x as validateModules, y as useUnwrappedReactor, z as useConnectDid, A as useConnectCrypto, D as useTranslation, F as useModal, G as useAtomValue, H as themeAtom, J as useUser, K as useUserPermissions, L as useUiNodes, N as exportFile, O as useGetDocumentModelModule, Q as addActionContext, U as signOperation, V as useDocumentDriveServer, W as useHotkeys, X as useGetEditor, Y as isSameDocument, Z as useNavigate, _ as ErrorBoundary, $ as DriveLayout, a0 as SearchBar, a1 as useAsyncReactor, a2 as useFilteredDocumentModels, a3 as useDriveEditor, a4 as useDocumentDriveById } from "./app-D5aQi0aY.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import React__default, { useState, useCallback, useMemo, useEffect, Fragment, useRef, useLayoutEffect, memo as memo$1, createElement, useSyncExternalStore, Suspense } from "react";
|
|
5
|
+
import { _ as Icon, aX as getDimensions, aY as READ, aZ as nodeOptionsMap, a_ as defaultFileOptions, a$ as DELETE, b0 as RENAME, b1 as WRITE, b2 as DUPLICATE, b3 as defaultFolderOptions, b4 as garbageCollect, b5 as sortOperations, b6 as UI_NODE, aO as DRIVE, ay as FILE, b7 as undo, b8 as redo, ac as logger, b9 as useDocumentDispatch, aP as FOLDER, ak as driveDocumentModelModule } from "./app-loader-D5SWSIlq.js";
|
|
6
|
+
import { useDocument, useDocumentEditorProps } from "@powerhousedao/reactor-browser";
|
|
7
|
+
import { useUiNodesContext, FILE as FILE$1 } from "@powerhousedao/reactor-browser/hooks/useUiNodesContext";
|
|
8
|
+
import { useDriveActionsWithUiNodes } from "@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes";
|
|
9
|
+
import { useDriveContext, DriveContextProvider } from "@powerhousedao/reactor-browser/hooks/useDriveContext";
|
|
10
|
+
import "@powerhousedao/reactor-browser/uiNodes/constants";
|
|
11
|
+
import { makeDriveDocumentStateHook } from "@powerhousedao/reactor-browser/hooks/document-state";
|
|
12
|
+
import { flushSync } from "react-dom";
|
|
13
|
+
import "./main.DnroXr_4.js";
|
|
14
|
+
const PaginationButton = ({ active = false, ...props }) => {
|
|
15
|
+
const className = twMerge("h-8 min-w-8 border border-solid border-gray-300 bg-white px-3 py-1 text-xs text-gray-900 hover:bg-gray-100", !active && "border-0");
|
|
16
|
+
return jsx(Button, { color: "light", size: "small", ...mergeClassNameProps(props, className), children: props.children });
|
|
17
|
+
};
|
|
18
|
+
const Pagination = (props) => {
|
|
19
|
+
const { pages = [], goToFirstPage, goToLastPage, goToNextPage, goToPreviousPage, goToPage, isNextPageAvailable, isPreviousPageAvailable, hiddenNextPages, firstPageLabel = "First", lastPageLabel = "Last", nextPageLabel = "Next", previousPageLabel = "Previous" } = props;
|
|
20
|
+
return jsxs("div", { className: "flex gap-x-1", children: [firstPageLabel ? jsx(PaginationButton, { disabled: !isPreviousPageAvailable, onClick: () => goToFirstPage(), children: firstPageLabel }) : null, previousPageLabel ? jsxs(PaginationButton, { disabled: !isPreviousPageAvailable, onClick: () => goToPreviousPage(), children: [jsx(Icon, { className: "rotate-90", name: "ChevronDown", size: 16 }), previousPageLabel] }) : null, pages.map((page) => jsx(PaginationButton, { active: page.active, onClick: () => goToPage(page.index), children: page.number }, page.index)), hiddenNextPages ? jsx("span", { className: "flex items-center justify-center px-2", children: "..." }) : null, nextPageLabel ? jsxs(PaginationButton, { disabled: !isNextPageAvailable, onClick: () => goToNextPage(), children: [nextPageLabel, jsx(Icon, { className: "-rotate-90", name: "ChevronDown", size: 16 })] }) : null, lastPageLabel ? jsx(PaginationButton, { disabled: !isNextPageAvailable, onClick: () => goToLastPage(), children: lastPageLabel }) : null] });
|
|
21
|
+
};
|
|
22
|
+
function usePagination(items, options) {
|
|
23
|
+
const { itemsPerPage = 20, initialPage = 0, pageRange = 3 } = options || {};
|
|
24
|
+
const [currentPage, setCurrentPage] = useState(initialPage);
|
|
25
|
+
const pageCount = Math.ceil(items.length / itemsPerPage);
|
|
26
|
+
const isNextPageAvailable = currentPage < pageCount - 1;
|
|
27
|
+
const isPreviousPageAvailable = currentPage > 0;
|
|
28
|
+
const goToNextPage = useCallback(() => {
|
|
29
|
+
if (isNextPageAvailable) {
|
|
30
|
+
setCurrentPage((prev) => prev + 1);
|
|
31
|
+
}
|
|
32
|
+
}, [isNextPageAvailable, setCurrentPage]);
|
|
33
|
+
const goToPreviousPage = useCallback(() => {
|
|
34
|
+
if (isPreviousPageAvailable) {
|
|
35
|
+
setCurrentPage((prev) => prev - 1);
|
|
36
|
+
}
|
|
37
|
+
}, [isPreviousPageAvailable, setCurrentPage]);
|
|
38
|
+
const goToLastPage = useCallback(() => {
|
|
39
|
+
setCurrentPage(pageCount - 1);
|
|
40
|
+
}, [pageCount]);
|
|
41
|
+
const goToFirstPage = useCallback(() => {
|
|
42
|
+
setCurrentPage(0);
|
|
43
|
+
}, []);
|
|
44
|
+
const goToPage = useCallback((page) => {
|
|
45
|
+
if (page >= 0 && page < pageCount) {
|
|
46
|
+
setCurrentPage(page);
|
|
47
|
+
}
|
|
48
|
+
}, [pageCount]);
|
|
49
|
+
const pageOffset = Math.floor((pageRange - 1) / 2);
|
|
50
|
+
const availableRange = Math.min(pageRange, pageCount);
|
|
51
|
+
const maxStartIndex = Math.max(pageCount - availableRange);
|
|
52
|
+
const startIndex = Math.min(maxStartIndex, Math.max(currentPage - pageOffset, 0));
|
|
53
|
+
const pages = useMemo(() => {
|
|
54
|
+
const range = [];
|
|
55
|
+
for (let i = startIndex; i < availableRange + startIndex; i++) {
|
|
56
|
+
range.push({
|
|
57
|
+
index: i,
|
|
58
|
+
active: i === currentPage,
|
|
59
|
+
number: i + 1
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return range;
|
|
63
|
+
}, [availableRange, startIndex, currentPage]);
|
|
64
|
+
const pageItems = items.slice(currentPage * itemsPerPage, (currentPage + 1) * itemsPerPage);
|
|
65
|
+
const hiddenNextPages = pages.length > 0 && pages.slice(-1)[0].index < pageCount - 1;
|
|
66
|
+
return {
|
|
67
|
+
pages,
|
|
68
|
+
goToPage,
|
|
69
|
+
pageItems,
|
|
70
|
+
pageCount,
|
|
71
|
+
currentPage,
|
|
72
|
+
goToLastPage,
|
|
73
|
+
goToFirstPage,
|
|
74
|
+
goToNextPage,
|
|
75
|
+
hiddenNextPages,
|
|
76
|
+
goToPreviousPage,
|
|
77
|
+
isNextPageAvailable,
|
|
78
|
+
isPreviousPageAvailable
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const useWindowSize = () => {
|
|
82
|
+
const [windowSize, setWindowSize] = useState({
|
|
83
|
+
innerWidth: window.innerWidth,
|
|
84
|
+
innerHeight: window.innerHeight
|
|
85
|
+
});
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
const windowSizeHandler = () => {
|
|
88
|
+
setWindowSize({
|
|
89
|
+
innerWidth: window.innerWidth,
|
|
90
|
+
innerHeight: window.innerHeight
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
window.addEventListener("resize", windowSizeHandler);
|
|
94
|
+
return () => {
|
|
95
|
+
window.removeEventListener("resize", windowSizeHandler);
|
|
96
|
+
};
|
|
97
|
+
}, []);
|
|
98
|
+
return windowSize;
|
|
99
|
+
};
|
|
100
|
+
const ConnectLoaderVideo = "/assets/connect-loader-CvOC68Ih.mp4";
|
|
101
|
+
function AnimatedLoader(props) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
const { style, size = 100, ...delegatedProps } = props;
|
|
104
|
+
const dimensions = getDimensions(size);
|
|
105
|
+
const _style = {
|
|
106
|
+
objectFit: "contain",
|
|
107
|
+
pointerEvents: "none",
|
|
108
|
+
...dimensions,
|
|
109
|
+
...style
|
|
110
|
+
};
|
|
111
|
+
const width = (_a = dimensions.width) == null ? void 0 : _a.replace("px", "");
|
|
112
|
+
const height = (_b = dimensions.height) == null ? void 0 : _b.replace("px", "");
|
|
113
|
+
return jsx("video", { autoPlay: true, height, loop: true, muted: true, playsInline: true, width, ...delegatedProps, style: _style, children: jsx("source", { src: ConnectLoaderVideo, type: "video/mp4" }) });
|
|
114
|
+
}
|
|
115
|
+
function Breadcrumbs(props) {
|
|
116
|
+
const { breadcrumbs, createEnabled, onBreadcrumbSelected } = props;
|
|
117
|
+
const [isCreating, setIsCreating] = useState(false);
|
|
118
|
+
const onCreate = props.createEnabled ? props.onCreate : void 0;
|
|
119
|
+
function onAddNew() {
|
|
120
|
+
setIsCreating(true);
|
|
121
|
+
}
|
|
122
|
+
const onSubmit = useCallback((name) => {
|
|
123
|
+
var _a;
|
|
124
|
+
if (!createEnabled || !onCreate)
|
|
125
|
+
return;
|
|
126
|
+
onCreate(name, (_a = breadcrumbs.at(-1)) == null ? void 0 : _a.id);
|
|
127
|
+
setIsCreating(false);
|
|
128
|
+
}, [breadcrumbs, createEnabled, onCreate]);
|
|
129
|
+
const onCancel = useCallback(() => {
|
|
130
|
+
setIsCreating(false);
|
|
131
|
+
}, []);
|
|
132
|
+
return jsxs("div", { className: "flex h-9 flex-row items-center gap-2 p-6 text-gray-500", children: [breadcrumbs.map((node) => jsxs(Fragment, { children: [jsx(Breadcrumb, { node, onClick: onBreadcrumbSelected }), jsx("span", { children: "/" })] }, node.id)), createEnabled && (isCreating ? jsx(NodeInput, { className: "text-gray-800", defaultValue: "New Folder", onCancel, onSubmit, placeholder: "New Folder" }) : jsxs("button", { type: "button", className: "ml-1 flex items-center justify-center gap-2 rounded-md bg-gray-50 px-2 py-1.5 transition-colors hover:bg-gray-200 hover:text-gray-800", onClick: onAddNew, children: [jsx(Icon, { name: "Plus", size: 14 }), "Add new"] }))] });
|
|
133
|
+
}
|
|
134
|
+
function Breadcrumb(props) {
|
|
135
|
+
const { node, onClick } = props;
|
|
136
|
+
return jsx("div", { className: "transition-colors last-of-type:text-gray-800 hover:text-gray-800", onClick: () => onClick(node), role: "button", children: node.name });
|
|
137
|
+
}
|
|
138
|
+
function useBreadcrumbs({ selectedNodePath, getNodeById, setSelectedNode }) {
|
|
139
|
+
const breadcrumbs = useMemo(() => selectedNodePath.map((node) => ({
|
|
140
|
+
id: node.id,
|
|
141
|
+
name: node.name
|
|
142
|
+
})), [selectedNodePath]);
|
|
143
|
+
const onBreadcrumbSelected = useCallback((breadcrumb) => {
|
|
144
|
+
const node = getNodeById(breadcrumb.id);
|
|
145
|
+
if (node) {
|
|
146
|
+
setSelectedNode(node);
|
|
147
|
+
} else {
|
|
148
|
+
console.error(`Node with id ${breadcrumb.id} not found`, breadcrumb);
|
|
149
|
+
}
|
|
150
|
+
}, [getNodeById, setSelectedNode]);
|
|
151
|
+
return {
|
|
152
|
+
breadcrumbs,
|
|
153
|
+
onBreadcrumbSelected
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function DefaultEditorLoader(props) {
|
|
157
|
+
const { message: message2 = "Loading editor", ...divProps } = props;
|
|
158
|
+
return jsx("div", { className: "grid h-full place-items-center", ...divProps, children: jsxs("div", { className: "-mt-20 grid place-items-center", children: [jsx("h3", { className: "mb-4 text-xl", children: message2 }), jsx(AnimatedLoader, {})] }) });
|
|
159
|
+
}
|
|
160
|
+
const DocumentToolbar = (props) => {
|
|
161
|
+
const { undo: undo2, canUndo, redo: redo2, canRedo, title, onClose, onExport, className, onShowRevisionHistory, onSwitchboardLinkClick } = props;
|
|
162
|
+
return jsxs("div", { className: twMerge("flex items-center justify-between", className), children: [jsx("div", { children: undo2 && redo2 && canUndo && canRedo && jsx(EditorUndoRedoButtons, { undo: undo2, canUndo, redo: redo2, canRedo }) }), jsx("div", { children: jsx("h2", { className: "text-sm font-semibold", children: title }) }), jsx("div", { children: jsx(EditorActionButtons, { onClose, onExport, onShowRevisionHistory, onSwitchboardLinkClick }) })] });
|
|
163
|
+
};
|
|
164
|
+
function EditorActionButtons(props) {
|
|
165
|
+
const { onSwitchboardLinkClick, onExport, onClose, onShowRevisionHistory } = props;
|
|
166
|
+
return jsxs("div", { className: "flex gap-x-2", children: [onSwitchboardLinkClick ? jsx("button", { className: "flex h-8 items-center gap-x-2 rounded border border-gray-200 px-3 text-sm font-semibold text-gray-900 active:opacity-50", onClick: onSwitchboardLinkClick, children: jsx(Icon, { name: "Drive", size: 16 }) }) : null, jsxs("button", { className: "flex h-8 items-center gap-x-2 rounded border border-gray-200 px-3 text-sm font-semibold text-gray-900 active:opacity-50", onClick: onExport, children: ["Export ", jsx(Icon, { name: "Save", size: 16 })] }), jsxs("button", { className: "flex h-8 items-center gap-x-2 whitespace-nowrap rounded border border-gray-200 px-3 text-sm font-semibold text-gray-900 active:opacity-50", onClick: onShowRevisionHistory, children: ["Revision history ", jsx(Icon, { name: "History", size: 16 })] }), jsx("button", { className: "grid size-8 place-items-center rounded border border-gray-200 active:opacity-50", onClick: onClose, children: jsx(Icon, { name: "Xmark" }) })] });
|
|
167
|
+
}
|
|
168
|
+
function EditorUndoRedoButtons(props) {
|
|
169
|
+
const { canUndo, canRedo, undo: undo2, redo: redo2 } = props;
|
|
170
|
+
const buttonStyles = "w-8 h-8 rounded-lg flex justify-center items-center rounded border border-gray-200";
|
|
171
|
+
return jsxs("div", { className: "flex gap-x-2 text-gray-500", children: [jsx("button", { className: buttonStyles, disabled: !canUndo, onClick: undo2, children: jsx(Icon, { className: twMerge("-scale-x-100", canUndo ? "text-gray-900 active:opacity-50" : "text-gray-500"), name: "RedoArrow", size: 18 }) }), jsx("button", { className: buttonStyles, disabled: !canRedo, onClick: redo2, children: jsx(Icon, { className: twMerge(canRedo ? "text-gray-900 active:opacity-50" : "text-gray-500"), name: "RedoArrow", size: 18 }) })] });
|
|
172
|
+
}
|
|
173
|
+
const syncIcons = {
|
|
174
|
+
SYNCING: "Syncing",
|
|
175
|
+
SUCCESS: "Synced",
|
|
176
|
+
CONFLICT: "Error",
|
|
177
|
+
MISSING: "Circle",
|
|
178
|
+
ERROR: "Error",
|
|
179
|
+
INITIAL_SYNC: "Syncing"
|
|
180
|
+
};
|
|
181
|
+
function SyncStatusIcon(props) {
|
|
182
|
+
const { syncStatus, className, overrideSyncIcons = {}, ...iconProps } = props;
|
|
183
|
+
const icons = { ...syncIcons, ...overrideSyncIcons };
|
|
184
|
+
const syncStatusIcons = {
|
|
185
|
+
[INITIAL_SYNC]: jsx(Icon, { size: 16, ...iconProps, className: twMerge("text-blue-900", className), name: icons[INITIAL_SYNC] }),
|
|
186
|
+
[SYNCING]: jsx(Icon, { size: 16, ...iconProps, className: twMerge("text-blue-900", className), name: icons[SYNCING] }),
|
|
187
|
+
[SUCCESS]: jsx(Icon, { size: 16, ...iconProps, className: twMerge("text-green-900", className), name: icons[SUCCESS] }),
|
|
188
|
+
[CONFLICT]: jsx(Icon, { size: 16, ...iconProps, className: twMerge("text-orange-900", className), name: icons[CONFLICT] }),
|
|
189
|
+
[MISSING]: jsx(Icon, { size: 16, ...iconProps, className: twMerge("text-red-900", className), name: icons[MISSING] }),
|
|
190
|
+
[ERROR]: jsx(Icon, { size: 16, ...iconProps, className: twMerge("text-red-900", className), name: icons[ERROR] })
|
|
191
|
+
};
|
|
192
|
+
return syncStatusIcons[syncStatus];
|
|
193
|
+
}
|
|
194
|
+
function FileItem(props) {
|
|
195
|
+
const { uiNode, className, customDocumentIconSrc, onSelectNode, onRenameNode, onDuplicateNode, onDeleteNode, isAllowedToCreateDocuments } = props;
|
|
196
|
+
const [mode, setMode] = useState(READ);
|
|
197
|
+
const [isDropdownMenuOpen, setIsDropdownMenuOpen] = useState(false);
|
|
198
|
+
const { dragProps } = useDrag({ uiNode });
|
|
199
|
+
const isReadMode = mode === READ;
|
|
200
|
+
const dropdownMenuHandlers = {
|
|
201
|
+
[DUPLICATE]: () => onDuplicateNode(uiNode),
|
|
202
|
+
[RENAME]: () => setMode(WRITE),
|
|
203
|
+
[DELETE]: () => onDeleteNode(uiNode)
|
|
204
|
+
};
|
|
205
|
+
const dropdownMenuOptions = Object.entries(nodeOptionsMap).map(([id, option]) => ({
|
|
206
|
+
...option,
|
|
207
|
+
id
|
|
208
|
+
})).filter((option) => defaultFileOptions.includes(option.id));
|
|
209
|
+
function onSubmit(name) {
|
|
210
|
+
onRenameNode(name, uiNode);
|
|
211
|
+
setMode(READ);
|
|
212
|
+
}
|
|
213
|
+
function onCancel() {
|
|
214
|
+
setMode(READ);
|
|
215
|
+
}
|
|
216
|
+
function onClick() {
|
|
217
|
+
onSelectNode(uiNode);
|
|
218
|
+
}
|
|
219
|
+
function onDropdownMenuOptionClick(itemId) {
|
|
220
|
+
const handler = dropdownMenuHandlers[itemId];
|
|
221
|
+
if (!handler) {
|
|
222
|
+
console.error(`No handler found for dropdown menu item: ${itemId}`);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
handler();
|
|
226
|
+
setIsDropdownMenuOpen(false);
|
|
227
|
+
}
|
|
228
|
+
const iconSrc = getDocumentIconSrc(uiNode.documentType, customDocumentIconSrc);
|
|
229
|
+
const iconNode = jsxs("div", { className: "relative", children: [jsx("img", { alt: "file icon", className: "max-w-none", height: 34, src: iconSrc, width: 32 }), isReadMode && uiNode.syncStatus && jsx("div", { className: "absolute bottom-[-2px] right-0 size-3 rounded-full bg-white", children: jsx("div", { className: "absolute left-[-2px] top-[-2px]", children: jsx(SyncStatusIcon, { overrideSyncIcons: { SUCCESS: "CheckCircleFill" }, syncStatus: uiNode.syncStatus }) }) })] });
|
|
230
|
+
const containerStyles = twMerge("group flex h-12 cursor-pointer select-none items-center rounded-lg bg-gray-200 px-2 text-gray-600 hover:text-gray-800", className);
|
|
231
|
+
const content = isReadMode ? jsxs("div", { className: "flex w-52 items-center justify-between", children: [jsxs("div", { className: "mr-2 truncate group-hover:mr-0", children: [jsx("div", { className: "max-h-6 truncate text-sm font-medium group-hover:text-gray-800", children: uiNode.name }), jsx("div", { className: "max-h-6 truncate text-xs font-medium text-gray-600 group-hover:text-gray-800", children: uiNode.documentType })] }), isAllowedToCreateDocuments ? jsx(ConnectDropdownMenu, { items: dropdownMenuOptions, onItemClick: onDropdownMenuOptionClick, onOpenChange: setIsDropdownMenuOpen, open: isDropdownMenuOpen, children: jsx("button", { className: twMerge("hidden group-hover:block", isDropdownMenuOpen && "block"), onClick: (e) => {
|
|
232
|
+
e.stopPropagation();
|
|
233
|
+
setIsDropdownMenuOpen(true);
|
|
234
|
+
}, children: jsx(Icon, { className: "text-gray-600", name: "VerticalDots" }) }) }) : null] }) : jsx(NodeInput, { className: "ml-3 flex-1 font-medium", defaultValue: uiNode.name, onCancel, onSubmit });
|
|
235
|
+
return jsx("div", { className: "relative w-64", onClick, children: jsx("div", { ...dragProps, className: containerStyles, children: jsxs("div", { className: "flex items-center", children: [jsx("div", { className: "mr-1.5", children: iconNode }), content] }) }) });
|
|
236
|
+
}
|
|
237
|
+
function FolderItem(props) {
|
|
238
|
+
const { uiNode, isAllowedToCreateDocuments, className, onRenameNode, onDuplicateNode, onDeleteNode, onSelectNode, onAddFile, onCopyNode, onMoveNode } = props;
|
|
239
|
+
const [mode, setMode] = useState(READ);
|
|
240
|
+
const [isDropdownMenuOpen, setIsDropdownMenuOpen] = useState(false);
|
|
241
|
+
const { dragProps } = useDrag({ ...props, uiNode });
|
|
242
|
+
const { isDropTarget, dropProps } = useDrop({
|
|
243
|
+
uiNode,
|
|
244
|
+
onAddFile,
|
|
245
|
+
onCopyNode,
|
|
246
|
+
onMoveNode
|
|
247
|
+
});
|
|
248
|
+
const isReadMode = mode === READ;
|
|
249
|
+
function onCancel() {
|
|
250
|
+
setMode(READ);
|
|
251
|
+
}
|
|
252
|
+
function onSubmit(name) {
|
|
253
|
+
onRenameNode(name, uiNode);
|
|
254
|
+
setMode(READ);
|
|
255
|
+
}
|
|
256
|
+
function onClick() {
|
|
257
|
+
onSelectNode(uiNode);
|
|
258
|
+
}
|
|
259
|
+
const dropdownMenuHandlers = {
|
|
260
|
+
[DUPLICATE]: () => onDuplicateNode(uiNode),
|
|
261
|
+
[RENAME]: () => setMode(WRITE),
|
|
262
|
+
[DELETE]: () => onDeleteNode(uiNode)
|
|
263
|
+
};
|
|
264
|
+
const dropdownMenuOptions = Object.entries(nodeOptionsMap).map(([id, option]) => ({
|
|
265
|
+
...option,
|
|
266
|
+
id
|
|
267
|
+
})).filter((option) => defaultFolderOptions.includes(option.id));
|
|
268
|
+
function onDropdownMenuOptionClick(itemId) {
|
|
269
|
+
const handler = dropdownMenuHandlers[itemId];
|
|
270
|
+
if (!handler) {
|
|
271
|
+
console.error(`No handler found for dropdown menu item: ${itemId}`);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
handler();
|
|
275
|
+
setIsDropdownMenuOpen(false);
|
|
276
|
+
}
|
|
277
|
+
const content = isReadMode || !isAllowedToCreateDocuments ? jsx("div", { className: "ml-3 max-h-6 truncate font-medium text-gray-600 group-hover:text-gray-800", children: uiNode.name }) : jsx(NodeInput, { className: "ml-3 font-medium", defaultValue: uiNode.name, onCancel, onSubmit });
|
|
278
|
+
const containerStyles = twMerge("group flex h-12 cursor-pointer select-none items-center rounded-lg bg-gray-200 px-2", className, isDropTarget && "bg-blue-100");
|
|
279
|
+
return jsx("div", { className: "relative w-64", onClick, children: jsxs("div", { ...dragProps, ...dropProps, className: containerStyles, children: [jsxs("div", { className: "flex items-center overflow-hidden", children: [jsx("div", { className: "p-1", children: jsxs("div", { className: "relative", children: [jsx(Icon, { name: "FolderClose", size: 24 }), isReadMode && uiNode.syncStatus ? jsx("div", { className: "absolute bottom-[-3px] right-[-2px] size-3 rounded-full bg-white", children: jsx("div", { className: "absolute left-[-2px] top-[-2px]", children: jsx(SyncStatusIcon, { overrideSyncIcons: {
|
|
280
|
+
SUCCESS: "CheckCircleFill"
|
|
281
|
+
}, syncStatus: uiNode.syncStatus }) }) }) : null] }) }), content] }), isReadMode && isAllowedToCreateDocuments ? jsx(ConnectDropdownMenu, { items: dropdownMenuOptions, onItemClick: onDropdownMenuOptionClick, onOpenChange: setIsDropdownMenuOpen, open: isDropdownMenuOpen, children: jsx("button", { className: twMerge("ml-auto hidden group-hover:block", isDropdownMenuOpen && "block"), onClick: (e) => {
|
|
282
|
+
e.stopPropagation();
|
|
283
|
+
setIsDropdownMenuOpen(true);
|
|
284
|
+
}, children: jsx(Icon, { className: "text-gray-600", name: "VerticalDots" }) }) }) : null] }) });
|
|
285
|
+
}
|
|
286
|
+
const millisecondsInWeek = 6048e5;
|
|
287
|
+
const millisecondsInDay = 864e5;
|
|
288
|
+
const constructFromSymbol = Symbol.for("constructDateFrom");
|
|
289
|
+
function constructFrom(date, value) {
|
|
290
|
+
if (typeof date === "function") return date(value);
|
|
291
|
+
if (date && typeof date === "object" && constructFromSymbol in date)
|
|
292
|
+
return date[constructFromSymbol](value);
|
|
293
|
+
if (date instanceof Date) return new date.constructor(value);
|
|
294
|
+
return new Date(value);
|
|
295
|
+
}
|
|
296
|
+
function toDate(argument, context) {
|
|
297
|
+
return constructFrom(context || argument, argument);
|
|
298
|
+
}
|
|
299
|
+
let defaultOptions = {};
|
|
300
|
+
function getDefaultOptions() {
|
|
301
|
+
return defaultOptions;
|
|
302
|
+
}
|
|
303
|
+
function startOfWeek(date, options) {
|
|
304
|
+
var _a, _b, _c, _d;
|
|
305
|
+
const defaultOptions2 = getDefaultOptions();
|
|
306
|
+
const weekStartsOn = (options == null ? void 0 : options.weekStartsOn) ?? ((_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.weekStartsOn) ?? defaultOptions2.weekStartsOn ?? ((_d = (_c = defaultOptions2.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.weekStartsOn) ?? 0;
|
|
307
|
+
const _date = toDate(date, options == null ? void 0 : options.in);
|
|
308
|
+
const day = _date.getDay();
|
|
309
|
+
const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
|
310
|
+
_date.setDate(_date.getDate() - diff);
|
|
311
|
+
_date.setHours(0, 0, 0, 0);
|
|
312
|
+
return _date;
|
|
313
|
+
}
|
|
314
|
+
function startOfISOWeek(date, options) {
|
|
315
|
+
return startOfWeek(date, { ...options, weekStartsOn: 1 });
|
|
316
|
+
}
|
|
317
|
+
function getISOWeekYear(date, options) {
|
|
318
|
+
const _date = toDate(date, options == null ? void 0 : options.in);
|
|
319
|
+
const year = _date.getFullYear();
|
|
320
|
+
const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
|
|
321
|
+
fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
|
|
322
|
+
fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
|
|
323
|
+
const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
|
|
324
|
+
const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
|
|
325
|
+
fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
|
|
326
|
+
fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
|
|
327
|
+
const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
|
|
328
|
+
if (_date.getTime() >= startOfNextYear.getTime()) {
|
|
329
|
+
return year + 1;
|
|
330
|
+
} else if (_date.getTime() >= startOfThisYear.getTime()) {
|
|
331
|
+
return year;
|
|
332
|
+
} else {
|
|
333
|
+
return year - 1;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function getTimezoneOffsetInMilliseconds(date) {
|
|
337
|
+
const _date = toDate(date);
|
|
338
|
+
const utcDate = new Date(
|
|
339
|
+
Date.UTC(
|
|
340
|
+
_date.getFullYear(),
|
|
341
|
+
_date.getMonth(),
|
|
342
|
+
_date.getDate(),
|
|
343
|
+
_date.getHours(),
|
|
344
|
+
_date.getMinutes(),
|
|
345
|
+
_date.getSeconds(),
|
|
346
|
+
_date.getMilliseconds()
|
|
347
|
+
)
|
|
348
|
+
);
|
|
349
|
+
utcDate.setUTCFullYear(_date.getFullYear());
|
|
350
|
+
return +date - +utcDate;
|
|
351
|
+
}
|
|
352
|
+
function normalizeDates(context, ...dates) {
|
|
353
|
+
const normalize = constructFrom.bind(
|
|
354
|
+
null,
|
|
355
|
+
dates.find((date) => typeof date === "object")
|
|
356
|
+
);
|
|
357
|
+
return dates.map(normalize);
|
|
358
|
+
}
|
|
359
|
+
function startOfDay(date, options) {
|
|
360
|
+
const _date = toDate(date, options == null ? void 0 : options.in);
|
|
361
|
+
_date.setHours(0, 0, 0, 0);
|
|
362
|
+
return _date;
|
|
363
|
+
}
|
|
364
|
+
function differenceInCalendarDays(laterDate, earlierDate, options) {
|
|
365
|
+
const [laterDate_, earlierDate_] = normalizeDates(
|
|
366
|
+
options == null ? void 0 : options.in,
|
|
367
|
+
laterDate,
|
|
368
|
+
earlierDate
|
|
369
|
+
);
|
|
370
|
+
const laterStartOfDay = startOfDay(laterDate_);
|
|
371
|
+
const earlierStartOfDay = startOfDay(earlierDate_);
|
|
372
|
+
const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
|
|
373
|
+
const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
|
|
374
|
+
return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
|
|
375
|
+
}
|
|
376
|
+
function startOfISOWeekYear(date, options) {
|
|
377
|
+
const year = getISOWeekYear(date, options);
|
|
378
|
+
const fourthOfJanuary = constructFrom(date, 0);
|
|
379
|
+
fourthOfJanuary.setFullYear(year, 0, 4);
|
|
380
|
+
fourthOfJanuary.setHours(0, 0, 0, 0);
|
|
381
|
+
return startOfISOWeek(fourthOfJanuary);
|
|
382
|
+
}
|
|
383
|
+
function isDate(value) {
|
|
384
|
+
return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
|
|
385
|
+
}
|
|
386
|
+
function isValid(date) {
|
|
387
|
+
return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
|
|
388
|
+
}
|
|
389
|
+
function startOfYear(date, options) {
|
|
390
|
+
const date_ = toDate(date, options == null ? void 0 : options.in);
|
|
391
|
+
date_.setFullYear(date_.getFullYear(), 0, 1);
|
|
392
|
+
date_.setHours(0, 0, 0, 0);
|
|
393
|
+
return date_;
|
|
394
|
+
}
|
|
395
|
+
const formatDistanceLocale = {
|
|
396
|
+
lessThanXSeconds: {
|
|
397
|
+
one: "less than a second",
|
|
398
|
+
other: "less than {{count}} seconds"
|
|
399
|
+
},
|
|
400
|
+
xSeconds: {
|
|
401
|
+
one: "1 second",
|
|
402
|
+
other: "{{count}} seconds"
|
|
403
|
+
},
|
|
404
|
+
halfAMinute: "half a minute",
|
|
405
|
+
lessThanXMinutes: {
|
|
406
|
+
one: "less than a minute",
|
|
407
|
+
other: "less than {{count}} minutes"
|
|
408
|
+
},
|
|
409
|
+
xMinutes: {
|
|
410
|
+
one: "1 minute",
|
|
411
|
+
other: "{{count}} minutes"
|
|
412
|
+
},
|
|
413
|
+
aboutXHours: {
|
|
414
|
+
one: "about 1 hour",
|
|
415
|
+
other: "about {{count}} hours"
|
|
416
|
+
},
|
|
417
|
+
xHours: {
|
|
418
|
+
one: "1 hour",
|
|
419
|
+
other: "{{count}} hours"
|
|
420
|
+
},
|
|
421
|
+
xDays: {
|
|
422
|
+
one: "1 day",
|
|
423
|
+
other: "{{count}} days"
|
|
424
|
+
},
|
|
425
|
+
aboutXWeeks: {
|
|
426
|
+
one: "about 1 week",
|
|
427
|
+
other: "about {{count}} weeks"
|
|
428
|
+
},
|
|
429
|
+
xWeeks: {
|
|
430
|
+
one: "1 week",
|
|
431
|
+
other: "{{count}} weeks"
|
|
432
|
+
},
|
|
433
|
+
aboutXMonths: {
|
|
434
|
+
one: "about 1 month",
|
|
435
|
+
other: "about {{count}} months"
|
|
436
|
+
},
|
|
437
|
+
xMonths: {
|
|
438
|
+
one: "1 month",
|
|
439
|
+
other: "{{count}} months"
|
|
440
|
+
},
|
|
441
|
+
aboutXYears: {
|
|
442
|
+
one: "about 1 year",
|
|
443
|
+
other: "about {{count}} years"
|
|
444
|
+
},
|
|
445
|
+
xYears: {
|
|
446
|
+
one: "1 year",
|
|
447
|
+
other: "{{count}} years"
|
|
448
|
+
},
|
|
449
|
+
overXYears: {
|
|
450
|
+
one: "over 1 year",
|
|
451
|
+
other: "over {{count}} years"
|
|
452
|
+
},
|
|
453
|
+
almostXYears: {
|
|
454
|
+
one: "almost 1 year",
|
|
455
|
+
other: "almost {{count}} years"
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
const formatDistance = (token, count, options) => {
|
|
459
|
+
let result;
|
|
460
|
+
const tokenValue = formatDistanceLocale[token];
|
|
461
|
+
if (typeof tokenValue === "string") {
|
|
462
|
+
result = tokenValue;
|
|
463
|
+
} else if (count === 1) {
|
|
464
|
+
result = tokenValue.one;
|
|
465
|
+
} else {
|
|
466
|
+
result = tokenValue.other.replace("{{count}}", count.toString());
|
|
467
|
+
}
|
|
468
|
+
if (options == null ? void 0 : options.addSuffix) {
|
|
469
|
+
if (options.comparison && options.comparison > 0) {
|
|
470
|
+
return "in " + result;
|
|
471
|
+
} else {
|
|
472
|
+
return result + " ago";
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return result;
|
|
476
|
+
};
|
|
477
|
+
function buildFormatLongFn(args) {
|
|
478
|
+
return (options = {}) => {
|
|
479
|
+
const width = options.width ? String(options.width) : args.defaultWidth;
|
|
480
|
+
const format2 = args.formats[width] || args.formats[args.defaultWidth];
|
|
481
|
+
return format2;
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
const dateFormats = {
|
|
485
|
+
full: "EEEE, MMMM do, y",
|
|
486
|
+
long: "MMMM do, y",
|
|
487
|
+
medium: "MMM d, y",
|
|
488
|
+
short: "MM/dd/yyyy"
|
|
489
|
+
};
|
|
490
|
+
const timeFormats = {
|
|
491
|
+
full: "h:mm:ss a zzzz",
|
|
492
|
+
long: "h:mm:ss a z",
|
|
493
|
+
medium: "h:mm:ss a",
|
|
494
|
+
short: "h:mm a"
|
|
495
|
+
};
|
|
496
|
+
const dateTimeFormats = {
|
|
497
|
+
full: "{{date}} 'at' {{time}}",
|
|
498
|
+
long: "{{date}} 'at' {{time}}",
|
|
499
|
+
medium: "{{date}}, {{time}}",
|
|
500
|
+
short: "{{date}}, {{time}}"
|
|
501
|
+
};
|
|
502
|
+
const formatLong = {
|
|
503
|
+
date: buildFormatLongFn({
|
|
504
|
+
formats: dateFormats,
|
|
505
|
+
defaultWidth: "full"
|
|
506
|
+
}),
|
|
507
|
+
time: buildFormatLongFn({
|
|
508
|
+
formats: timeFormats,
|
|
509
|
+
defaultWidth: "full"
|
|
510
|
+
}),
|
|
511
|
+
dateTime: buildFormatLongFn({
|
|
512
|
+
formats: dateTimeFormats,
|
|
513
|
+
defaultWidth: "full"
|
|
514
|
+
})
|
|
515
|
+
};
|
|
516
|
+
const formatRelativeLocale = {
|
|
517
|
+
lastWeek: "'last' eeee 'at' p",
|
|
518
|
+
yesterday: "'yesterday at' p",
|
|
519
|
+
today: "'today at' p",
|
|
520
|
+
tomorrow: "'tomorrow at' p",
|
|
521
|
+
nextWeek: "eeee 'at' p",
|
|
522
|
+
other: "P"
|
|
523
|
+
};
|
|
524
|
+
const formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
|
|
525
|
+
function buildLocalizeFn(args) {
|
|
526
|
+
return (value, options) => {
|
|
527
|
+
const context = (options == null ? void 0 : options.context) ? String(options.context) : "standalone";
|
|
528
|
+
let valuesArray;
|
|
529
|
+
if (context === "formatting" && args.formattingValues) {
|
|
530
|
+
const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
|
|
531
|
+
const width = (options == null ? void 0 : options.width) ? String(options.width) : defaultWidth;
|
|
532
|
+
valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
|
|
533
|
+
} else {
|
|
534
|
+
const defaultWidth = args.defaultWidth;
|
|
535
|
+
const width = (options == null ? void 0 : options.width) ? String(options.width) : args.defaultWidth;
|
|
536
|
+
valuesArray = args.values[width] || args.values[defaultWidth];
|
|
537
|
+
}
|
|
538
|
+
const index = args.argumentCallback ? args.argumentCallback(value) : value;
|
|
539
|
+
return valuesArray[index];
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
const eraValues = {
|
|
543
|
+
narrow: ["B", "A"],
|
|
544
|
+
abbreviated: ["BC", "AD"],
|
|
545
|
+
wide: ["Before Christ", "Anno Domini"]
|
|
546
|
+
};
|
|
547
|
+
const quarterValues = {
|
|
548
|
+
narrow: ["1", "2", "3", "4"],
|
|
549
|
+
abbreviated: ["Q1", "Q2", "Q3", "Q4"],
|
|
550
|
+
wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
|
|
551
|
+
};
|
|
552
|
+
const monthValues = {
|
|
553
|
+
narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
|
|
554
|
+
abbreviated: [
|
|
555
|
+
"Jan",
|
|
556
|
+
"Feb",
|
|
557
|
+
"Mar",
|
|
558
|
+
"Apr",
|
|
559
|
+
"May",
|
|
560
|
+
"Jun",
|
|
561
|
+
"Jul",
|
|
562
|
+
"Aug",
|
|
563
|
+
"Sep",
|
|
564
|
+
"Oct",
|
|
565
|
+
"Nov",
|
|
566
|
+
"Dec"
|
|
567
|
+
],
|
|
568
|
+
wide: [
|
|
569
|
+
"January",
|
|
570
|
+
"February",
|
|
571
|
+
"March",
|
|
572
|
+
"April",
|
|
573
|
+
"May",
|
|
574
|
+
"June",
|
|
575
|
+
"July",
|
|
576
|
+
"August",
|
|
577
|
+
"September",
|
|
578
|
+
"October",
|
|
579
|
+
"November",
|
|
580
|
+
"December"
|
|
581
|
+
]
|
|
582
|
+
};
|
|
583
|
+
const dayValues = {
|
|
584
|
+
narrow: ["S", "M", "T", "W", "T", "F", "S"],
|
|
585
|
+
short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
|
|
586
|
+
abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
587
|
+
wide: [
|
|
588
|
+
"Sunday",
|
|
589
|
+
"Monday",
|
|
590
|
+
"Tuesday",
|
|
591
|
+
"Wednesday",
|
|
592
|
+
"Thursday",
|
|
593
|
+
"Friday",
|
|
594
|
+
"Saturday"
|
|
595
|
+
]
|
|
596
|
+
};
|
|
597
|
+
const dayPeriodValues = {
|
|
598
|
+
narrow: {
|
|
599
|
+
am: "a",
|
|
600
|
+
pm: "p",
|
|
601
|
+
midnight: "mi",
|
|
602
|
+
noon: "n",
|
|
603
|
+
morning: "morning",
|
|
604
|
+
afternoon: "afternoon",
|
|
605
|
+
evening: "evening",
|
|
606
|
+
night: "night"
|
|
607
|
+
},
|
|
608
|
+
abbreviated: {
|
|
609
|
+
am: "AM",
|
|
610
|
+
pm: "PM",
|
|
611
|
+
midnight: "midnight",
|
|
612
|
+
noon: "noon",
|
|
613
|
+
morning: "morning",
|
|
614
|
+
afternoon: "afternoon",
|
|
615
|
+
evening: "evening",
|
|
616
|
+
night: "night"
|
|
617
|
+
},
|
|
618
|
+
wide: {
|
|
619
|
+
am: "a.m.",
|
|
620
|
+
pm: "p.m.",
|
|
621
|
+
midnight: "midnight",
|
|
622
|
+
noon: "noon",
|
|
623
|
+
morning: "morning",
|
|
624
|
+
afternoon: "afternoon",
|
|
625
|
+
evening: "evening",
|
|
626
|
+
night: "night"
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
const formattingDayPeriodValues = {
|
|
630
|
+
narrow: {
|
|
631
|
+
am: "a",
|
|
632
|
+
pm: "p",
|
|
633
|
+
midnight: "mi",
|
|
634
|
+
noon: "n",
|
|
635
|
+
morning: "in the morning",
|
|
636
|
+
afternoon: "in the afternoon",
|
|
637
|
+
evening: "in the evening",
|
|
638
|
+
night: "at night"
|
|
639
|
+
},
|
|
640
|
+
abbreviated: {
|
|
641
|
+
am: "AM",
|
|
642
|
+
pm: "PM",
|
|
643
|
+
midnight: "midnight",
|
|
644
|
+
noon: "noon",
|
|
645
|
+
morning: "in the morning",
|
|
646
|
+
afternoon: "in the afternoon",
|
|
647
|
+
evening: "in the evening",
|
|
648
|
+
night: "at night"
|
|
649
|
+
},
|
|
650
|
+
wide: {
|
|
651
|
+
am: "a.m.",
|
|
652
|
+
pm: "p.m.",
|
|
653
|
+
midnight: "midnight",
|
|
654
|
+
noon: "noon",
|
|
655
|
+
morning: "in the morning",
|
|
656
|
+
afternoon: "in the afternoon",
|
|
657
|
+
evening: "in the evening",
|
|
658
|
+
night: "at night"
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
const ordinalNumber = (dirtyNumber, _options) => {
|
|
662
|
+
const number = Number(dirtyNumber);
|
|
663
|
+
const rem100 = number % 100;
|
|
664
|
+
if (rem100 > 20 || rem100 < 10) {
|
|
665
|
+
switch (rem100 % 10) {
|
|
666
|
+
case 1:
|
|
667
|
+
return number + "st";
|
|
668
|
+
case 2:
|
|
669
|
+
return number + "nd";
|
|
670
|
+
case 3:
|
|
671
|
+
return number + "rd";
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return number + "th";
|
|
675
|
+
};
|
|
676
|
+
const localize = {
|
|
677
|
+
ordinalNumber,
|
|
678
|
+
era: buildLocalizeFn({
|
|
679
|
+
values: eraValues,
|
|
680
|
+
defaultWidth: "wide"
|
|
681
|
+
}),
|
|
682
|
+
quarter: buildLocalizeFn({
|
|
683
|
+
values: quarterValues,
|
|
684
|
+
defaultWidth: "wide",
|
|
685
|
+
argumentCallback: (quarter) => quarter - 1
|
|
686
|
+
}),
|
|
687
|
+
month: buildLocalizeFn({
|
|
688
|
+
values: monthValues,
|
|
689
|
+
defaultWidth: "wide"
|
|
690
|
+
}),
|
|
691
|
+
day: buildLocalizeFn({
|
|
692
|
+
values: dayValues,
|
|
693
|
+
defaultWidth: "wide"
|
|
694
|
+
}),
|
|
695
|
+
dayPeriod: buildLocalizeFn({
|
|
696
|
+
values: dayPeriodValues,
|
|
697
|
+
defaultWidth: "wide",
|
|
698
|
+
formattingValues: formattingDayPeriodValues,
|
|
699
|
+
defaultFormattingWidth: "wide"
|
|
700
|
+
})
|
|
701
|
+
};
|
|
702
|
+
function buildMatchFn(args) {
|
|
703
|
+
return (string, options = {}) => {
|
|
704
|
+
const width = options.width;
|
|
705
|
+
const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
|
|
706
|
+
const matchResult = string.match(matchPattern);
|
|
707
|
+
if (!matchResult) {
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
const matchedString = matchResult[0];
|
|
711
|
+
const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
|
|
712
|
+
const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
|
|
713
|
+
// [TODO] -- I challenge you to fix the type
|
|
714
|
+
findKey(parsePatterns, (pattern) => pattern.test(matchedString))
|
|
715
|
+
);
|
|
716
|
+
let value;
|
|
717
|
+
value = args.valueCallback ? args.valueCallback(key) : key;
|
|
718
|
+
value = options.valueCallback ? (
|
|
719
|
+
// [TODO] -- I challenge you to fix the type
|
|
720
|
+
options.valueCallback(value)
|
|
721
|
+
) : value;
|
|
722
|
+
const rest = string.slice(matchedString.length);
|
|
723
|
+
return { value, rest };
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
function findKey(object, predicate) {
|
|
727
|
+
for (const key in object) {
|
|
728
|
+
if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
|
|
729
|
+
return key;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return void 0;
|
|
733
|
+
}
|
|
734
|
+
function findIndex(array, predicate) {
|
|
735
|
+
for (let key = 0; key < array.length; key++) {
|
|
736
|
+
if (predicate(array[key])) {
|
|
737
|
+
return key;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return void 0;
|
|
741
|
+
}
|
|
742
|
+
function buildMatchPatternFn(args) {
|
|
743
|
+
return (string, options = {}) => {
|
|
744
|
+
const matchResult = string.match(args.matchPattern);
|
|
745
|
+
if (!matchResult) return null;
|
|
746
|
+
const matchedString = matchResult[0];
|
|
747
|
+
const parseResult = string.match(args.parsePattern);
|
|
748
|
+
if (!parseResult) return null;
|
|
749
|
+
let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
|
|
750
|
+
value = options.valueCallback ? options.valueCallback(value) : value;
|
|
751
|
+
const rest = string.slice(matchedString.length);
|
|
752
|
+
return { value, rest };
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
const matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
|
|
756
|
+
const parseOrdinalNumberPattern = /\d+/i;
|
|
757
|
+
const matchEraPatterns = {
|
|
758
|
+
narrow: /^(b|a)/i,
|
|
759
|
+
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
|
|
760
|
+
wide: /^(before christ|before common era|anno domini|common era)/i
|
|
761
|
+
};
|
|
762
|
+
const parseEraPatterns = {
|
|
763
|
+
any: [/^b/i, /^(a|c)/i]
|
|
764
|
+
};
|
|
765
|
+
const matchQuarterPatterns = {
|
|
766
|
+
narrow: /^[1234]/i,
|
|
767
|
+
abbreviated: /^q[1234]/i,
|
|
768
|
+
wide: /^[1234](th|st|nd|rd)? quarter/i
|
|
769
|
+
};
|
|
770
|
+
const parseQuarterPatterns = {
|
|
771
|
+
any: [/1/i, /2/i, /3/i, /4/i]
|
|
772
|
+
};
|
|
773
|
+
const matchMonthPatterns = {
|
|
774
|
+
narrow: /^[jfmasond]/i,
|
|
775
|
+
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
|
|
776
|
+
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
|
|
777
|
+
};
|
|
778
|
+
const parseMonthPatterns = {
|
|
779
|
+
narrow: [
|
|
780
|
+
/^j/i,
|
|
781
|
+
/^f/i,
|
|
782
|
+
/^m/i,
|
|
783
|
+
/^a/i,
|
|
784
|
+
/^m/i,
|
|
785
|
+
/^j/i,
|
|
786
|
+
/^j/i,
|
|
787
|
+
/^a/i,
|
|
788
|
+
/^s/i,
|
|
789
|
+
/^o/i,
|
|
790
|
+
/^n/i,
|
|
791
|
+
/^d/i
|
|
792
|
+
],
|
|
793
|
+
any: [
|
|
794
|
+
/^ja/i,
|
|
795
|
+
/^f/i,
|
|
796
|
+
/^mar/i,
|
|
797
|
+
/^ap/i,
|
|
798
|
+
/^may/i,
|
|
799
|
+
/^jun/i,
|
|
800
|
+
/^jul/i,
|
|
801
|
+
/^au/i,
|
|
802
|
+
/^s/i,
|
|
803
|
+
/^o/i,
|
|
804
|
+
/^n/i,
|
|
805
|
+
/^d/i
|
|
806
|
+
]
|
|
807
|
+
};
|
|
808
|
+
const matchDayPatterns = {
|
|
809
|
+
narrow: /^[smtwf]/i,
|
|
810
|
+
short: /^(su|mo|tu|we|th|fr|sa)/i,
|
|
811
|
+
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
|
|
812
|
+
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
|
|
813
|
+
};
|
|
814
|
+
const parseDayPatterns = {
|
|
815
|
+
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
|
|
816
|
+
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
|
|
817
|
+
};
|
|
818
|
+
const matchDayPeriodPatterns = {
|
|
819
|
+
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
|
|
820
|
+
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
|
|
821
|
+
};
|
|
822
|
+
const parseDayPeriodPatterns = {
|
|
823
|
+
any: {
|
|
824
|
+
am: /^a/i,
|
|
825
|
+
pm: /^p/i,
|
|
826
|
+
midnight: /^mi/i,
|
|
827
|
+
noon: /^no/i,
|
|
828
|
+
morning: /morning/i,
|
|
829
|
+
afternoon: /afternoon/i,
|
|
830
|
+
evening: /evening/i,
|
|
831
|
+
night: /night/i
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
const match = {
|
|
835
|
+
ordinalNumber: buildMatchPatternFn({
|
|
836
|
+
matchPattern: matchOrdinalNumberPattern,
|
|
837
|
+
parsePattern: parseOrdinalNumberPattern,
|
|
838
|
+
valueCallback: (value) => parseInt(value, 10)
|
|
839
|
+
}),
|
|
840
|
+
era: buildMatchFn({
|
|
841
|
+
matchPatterns: matchEraPatterns,
|
|
842
|
+
defaultMatchWidth: "wide",
|
|
843
|
+
parsePatterns: parseEraPatterns,
|
|
844
|
+
defaultParseWidth: "any"
|
|
845
|
+
}),
|
|
846
|
+
quarter: buildMatchFn({
|
|
847
|
+
matchPatterns: matchQuarterPatterns,
|
|
848
|
+
defaultMatchWidth: "wide",
|
|
849
|
+
parsePatterns: parseQuarterPatterns,
|
|
850
|
+
defaultParseWidth: "any",
|
|
851
|
+
valueCallback: (index) => index + 1
|
|
852
|
+
}),
|
|
853
|
+
month: buildMatchFn({
|
|
854
|
+
matchPatterns: matchMonthPatterns,
|
|
855
|
+
defaultMatchWidth: "wide",
|
|
856
|
+
parsePatterns: parseMonthPatterns,
|
|
857
|
+
defaultParseWidth: "any"
|
|
858
|
+
}),
|
|
859
|
+
day: buildMatchFn({
|
|
860
|
+
matchPatterns: matchDayPatterns,
|
|
861
|
+
defaultMatchWidth: "wide",
|
|
862
|
+
parsePatterns: parseDayPatterns,
|
|
863
|
+
defaultParseWidth: "any"
|
|
864
|
+
}),
|
|
865
|
+
dayPeriod: buildMatchFn({
|
|
866
|
+
matchPatterns: matchDayPeriodPatterns,
|
|
867
|
+
defaultMatchWidth: "any",
|
|
868
|
+
parsePatterns: parseDayPeriodPatterns,
|
|
869
|
+
defaultParseWidth: "any"
|
|
870
|
+
})
|
|
871
|
+
};
|
|
872
|
+
const enUS = {
|
|
873
|
+
code: "en-US",
|
|
874
|
+
formatDistance,
|
|
875
|
+
formatLong,
|
|
876
|
+
formatRelative,
|
|
877
|
+
localize,
|
|
878
|
+
match,
|
|
879
|
+
options: {
|
|
880
|
+
weekStartsOn: 0,
|
|
881
|
+
firstWeekContainsDate: 1
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
function getDayOfYear(date, options) {
|
|
885
|
+
const _date = toDate(date, options == null ? void 0 : options.in);
|
|
886
|
+
const diff = differenceInCalendarDays(_date, startOfYear(_date));
|
|
887
|
+
const dayOfYear = diff + 1;
|
|
888
|
+
return dayOfYear;
|
|
889
|
+
}
|
|
890
|
+
function getISOWeek(date, options) {
|
|
891
|
+
const _date = toDate(date, options == null ? void 0 : options.in);
|
|
892
|
+
const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
|
|
893
|
+
return Math.round(diff / millisecondsInWeek) + 1;
|
|
894
|
+
}
|
|
895
|
+
function getWeekYear(date, options) {
|
|
896
|
+
var _a, _b, _c, _d;
|
|
897
|
+
const _date = toDate(date, options == null ? void 0 : options.in);
|
|
898
|
+
const year = _date.getFullYear();
|
|
899
|
+
const defaultOptions2 = getDefaultOptions();
|
|
900
|
+
const firstWeekContainsDate = (options == null ? void 0 : options.firstWeekContainsDate) ?? ((_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.firstWeekContainsDate) ?? defaultOptions2.firstWeekContainsDate ?? ((_d = (_c = defaultOptions2.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.firstWeekContainsDate) ?? 1;
|
|
901
|
+
const firstWeekOfNextYear = constructFrom((options == null ? void 0 : options.in) || date, 0);
|
|
902
|
+
firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
|
|
903
|
+
firstWeekOfNextYear.setHours(0, 0, 0, 0);
|
|
904
|
+
const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
|
|
905
|
+
const firstWeekOfThisYear = constructFrom((options == null ? void 0 : options.in) || date, 0);
|
|
906
|
+
firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
|
|
907
|
+
firstWeekOfThisYear.setHours(0, 0, 0, 0);
|
|
908
|
+
const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
|
|
909
|
+
if (+_date >= +startOfNextYear) {
|
|
910
|
+
return year + 1;
|
|
911
|
+
} else if (+_date >= +startOfThisYear) {
|
|
912
|
+
return year;
|
|
913
|
+
} else {
|
|
914
|
+
return year - 1;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
function startOfWeekYear(date, options) {
|
|
918
|
+
var _a, _b, _c, _d;
|
|
919
|
+
const defaultOptions2 = getDefaultOptions();
|
|
920
|
+
const firstWeekContainsDate = (options == null ? void 0 : options.firstWeekContainsDate) ?? ((_b = (_a = options == null ? void 0 : options.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.firstWeekContainsDate) ?? defaultOptions2.firstWeekContainsDate ?? ((_d = (_c = defaultOptions2.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.firstWeekContainsDate) ?? 1;
|
|
921
|
+
const year = getWeekYear(date, options);
|
|
922
|
+
const firstWeek = constructFrom((options == null ? void 0 : options.in) || date, 0);
|
|
923
|
+
firstWeek.setFullYear(year, 0, firstWeekContainsDate);
|
|
924
|
+
firstWeek.setHours(0, 0, 0, 0);
|
|
925
|
+
const _date = startOfWeek(firstWeek, options);
|
|
926
|
+
return _date;
|
|
927
|
+
}
|
|
928
|
+
function getWeek(date, options) {
|
|
929
|
+
const _date = toDate(date, options == null ? void 0 : options.in);
|
|
930
|
+
const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
|
|
931
|
+
return Math.round(diff / millisecondsInWeek) + 1;
|
|
932
|
+
}
|
|
933
|
+
function addLeadingZeros(number, targetLength) {
|
|
934
|
+
const sign = number < 0 ? "-" : "";
|
|
935
|
+
const output = Math.abs(number).toString().padStart(targetLength, "0");
|
|
936
|
+
return sign + output;
|
|
937
|
+
}
|
|
938
|
+
const lightFormatters = {
|
|
939
|
+
// Year
|
|
940
|
+
y(date, token) {
|
|
941
|
+
const signedYear = date.getFullYear();
|
|
942
|
+
const year = signedYear > 0 ? signedYear : 1 - signedYear;
|
|
943
|
+
return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
|
|
944
|
+
},
|
|
945
|
+
// Month
|
|
946
|
+
M(date, token) {
|
|
947
|
+
const month = date.getMonth();
|
|
948
|
+
return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
|
|
949
|
+
},
|
|
950
|
+
// Day of the month
|
|
951
|
+
d(date, token) {
|
|
952
|
+
return addLeadingZeros(date.getDate(), token.length);
|
|
953
|
+
},
|
|
954
|
+
// AM or PM
|
|
955
|
+
a(date, token) {
|
|
956
|
+
const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
|
|
957
|
+
switch (token) {
|
|
958
|
+
case "a":
|
|
959
|
+
case "aa":
|
|
960
|
+
return dayPeriodEnumValue.toUpperCase();
|
|
961
|
+
case "aaa":
|
|
962
|
+
return dayPeriodEnumValue;
|
|
963
|
+
case "aaaaa":
|
|
964
|
+
return dayPeriodEnumValue[0];
|
|
965
|
+
case "aaaa":
|
|
966
|
+
default:
|
|
967
|
+
return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
// Hour [1-12]
|
|
971
|
+
h(date, token) {
|
|
972
|
+
return addLeadingZeros(date.getHours() % 12 || 12, token.length);
|
|
973
|
+
},
|
|
974
|
+
// Hour [0-23]
|
|
975
|
+
H(date, token) {
|
|
976
|
+
return addLeadingZeros(date.getHours(), token.length);
|
|
977
|
+
},
|
|
978
|
+
// Minute
|
|
979
|
+
m(date, token) {
|
|
980
|
+
return addLeadingZeros(date.getMinutes(), token.length);
|
|
981
|
+
},
|
|
982
|
+
// Second
|
|
983
|
+
s(date, token) {
|
|
984
|
+
return addLeadingZeros(date.getSeconds(), token.length);
|
|
985
|
+
},
|
|
986
|
+
// Fraction of second
|
|
987
|
+
S(date, token) {
|
|
988
|
+
const numberOfDigits = token.length;
|
|
989
|
+
const milliseconds = date.getMilliseconds();
|
|
990
|
+
const fractionalSeconds = Math.trunc(
|
|
991
|
+
milliseconds * Math.pow(10, numberOfDigits - 3)
|
|
992
|
+
);
|
|
993
|
+
return addLeadingZeros(fractionalSeconds, token.length);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
const dayPeriodEnum = {
|
|
997
|
+
midnight: "midnight",
|
|
998
|
+
noon: "noon",
|
|
999
|
+
morning: "morning",
|
|
1000
|
+
afternoon: "afternoon",
|
|
1001
|
+
evening: "evening",
|
|
1002
|
+
night: "night"
|
|
1003
|
+
};
|
|
1004
|
+
const formatters = {
|
|
1005
|
+
// Era
|
|
1006
|
+
G: function(date, token, localize2) {
|
|
1007
|
+
const era = date.getFullYear() > 0 ? 1 : 0;
|
|
1008
|
+
switch (token) {
|
|
1009
|
+
// AD, BC
|
|
1010
|
+
case "G":
|
|
1011
|
+
case "GG":
|
|
1012
|
+
case "GGG":
|
|
1013
|
+
return localize2.era(era, { width: "abbreviated" });
|
|
1014
|
+
// A, B
|
|
1015
|
+
case "GGGGG":
|
|
1016
|
+
return localize2.era(era, { width: "narrow" });
|
|
1017
|
+
// Anno Domini, Before Christ
|
|
1018
|
+
case "GGGG":
|
|
1019
|
+
default:
|
|
1020
|
+
return localize2.era(era, { width: "wide" });
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
// Year
|
|
1024
|
+
y: function(date, token, localize2) {
|
|
1025
|
+
if (token === "yo") {
|
|
1026
|
+
const signedYear = date.getFullYear();
|
|
1027
|
+
const year = signedYear > 0 ? signedYear : 1 - signedYear;
|
|
1028
|
+
return localize2.ordinalNumber(year, { unit: "year" });
|
|
1029
|
+
}
|
|
1030
|
+
return lightFormatters.y(date, token);
|
|
1031
|
+
},
|
|
1032
|
+
// Local week-numbering year
|
|
1033
|
+
Y: function(date, token, localize2, options) {
|
|
1034
|
+
const signedWeekYear = getWeekYear(date, options);
|
|
1035
|
+
const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
|
|
1036
|
+
if (token === "YY") {
|
|
1037
|
+
const twoDigitYear = weekYear % 100;
|
|
1038
|
+
return addLeadingZeros(twoDigitYear, 2);
|
|
1039
|
+
}
|
|
1040
|
+
if (token === "Yo") {
|
|
1041
|
+
return localize2.ordinalNumber(weekYear, { unit: "year" });
|
|
1042
|
+
}
|
|
1043
|
+
return addLeadingZeros(weekYear, token.length);
|
|
1044
|
+
},
|
|
1045
|
+
// ISO week-numbering year
|
|
1046
|
+
R: function(date, token) {
|
|
1047
|
+
const isoWeekYear = getISOWeekYear(date);
|
|
1048
|
+
return addLeadingZeros(isoWeekYear, token.length);
|
|
1049
|
+
},
|
|
1050
|
+
// Extended year. This is a single number designating the year of this calendar system.
|
|
1051
|
+
// The main difference between `y` and `u` localizers are B.C. years:
|
|
1052
|
+
// | Year | `y` | `u` |
|
|
1053
|
+
// |------|-----|-----|
|
|
1054
|
+
// | AC 1 | 1 | 1 |
|
|
1055
|
+
// | BC 1 | 1 | 0 |
|
|
1056
|
+
// | BC 2 | 2 | -1 |
|
|
1057
|
+
// Also `yy` always returns the last two digits of a year,
|
|
1058
|
+
// while `uu` pads single digit years to 2 characters and returns other years unchanged.
|
|
1059
|
+
u: function(date, token) {
|
|
1060
|
+
const year = date.getFullYear();
|
|
1061
|
+
return addLeadingZeros(year, token.length);
|
|
1062
|
+
},
|
|
1063
|
+
// Quarter
|
|
1064
|
+
Q: function(date, token, localize2) {
|
|
1065
|
+
const quarter = Math.ceil((date.getMonth() + 1) / 3);
|
|
1066
|
+
switch (token) {
|
|
1067
|
+
// 1, 2, 3, 4
|
|
1068
|
+
case "Q":
|
|
1069
|
+
return String(quarter);
|
|
1070
|
+
// 01, 02, 03, 04
|
|
1071
|
+
case "QQ":
|
|
1072
|
+
return addLeadingZeros(quarter, 2);
|
|
1073
|
+
// 1st, 2nd, 3rd, 4th
|
|
1074
|
+
case "Qo":
|
|
1075
|
+
return localize2.ordinalNumber(quarter, { unit: "quarter" });
|
|
1076
|
+
// Q1, Q2, Q3, Q4
|
|
1077
|
+
case "QQQ":
|
|
1078
|
+
return localize2.quarter(quarter, {
|
|
1079
|
+
width: "abbreviated",
|
|
1080
|
+
context: "formatting"
|
|
1081
|
+
});
|
|
1082
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
1083
|
+
case "QQQQQ":
|
|
1084
|
+
return localize2.quarter(quarter, {
|
|
1085
|
+
width: "narrow",
|
|
1086
|
+
context: "formatting"
|
|
1087
|
+
});
|
|
1088
|
+
// 1st quarter, 2nd quarter, ...
|
|
1089
|
+
case "QQQQ":
|
|
1090
|
+
default:
|
|
1091
|
+
return localize2.quarter(quarter, {
|
|
1092
|
+
width: "wide",
|
|
1093
|
+
context: "formatting"
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
},
|
|
1097
|
+
// Stand-alone quarter
|
|
1098
|
+
q: function(date, token, localize2) {
|
|
1099
|
+
const quarter = Math.ceil((date.getMonth() + 1) / 3);
|
|
1100
|
+
switch (token) {
|
|
1101
|
+
// 1, 2, 3, 4
|
|
1102
|
+
case "q":
|
|
1103
|
+
return String(quarter);
|
|
1104
|
+
// 01, 02, 03, 04
|
|
1105
|
+
case "qq":
|
|
1106
|
+
return addLeadingZeros(quarter, 2);
|
|
1107
|
+
// 1st, 2nd, 3rd, 4th
|
|
1108
|
+
case "qo":
|
|
1109
|
+
return localize2.ordinalNumber(quarter, { unit: "quarter" });
|
|
1110
|
+
// Q1, Q2, Q3, Q4
|
|
1111
|
+
case "qqq":
|
|
1112
|
+
return localize2.quarter(quarter, {
|
|
1113
|
+
width: "abbreviated",
|
|
1114
|
+
context: "standalone"
|
|
1115
|
+
});
|
|
1116
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
1117
|
+
case "qqqqq":
|
|
1118
|
+
return localize2.quarter(quarter, {
|
|
1119
|
+
width: "narrow",
|
|
1120
|
+
context: "standalone"
|
|
1121
|
+
});
|
|
1122
|
+
// 1st quarter, 2nd quarter, ...
|
|
1123
|
+
case "qqqq":
|
|
1124
|
+
default:
|
|
1125
|
+
return localize2.quarter(quarter, {
|
|
1126
|
+
width: "wide",
|
|
1127
|
+
context: "standalone"
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
// Month
|
|
1132
|
+
M: function(date, token, localize2) {
|
|
1133
|
+
const month = date.getMonth();
|
|
1134
|
+
switch (token) {
|
|
1135
|
+
case "M":
|
|
1136
|
+
case "MM":
|
|
1137
|
+
return lightFormatters.M(date, token);
|
|
1138
|
+
// 1st, 2nd, ..., 12th
|
|
1139
|
+
case "Mo":
|
|
1140
|
+
return localize2.ordinalNumber(month + 1, { unit: "month" });
|
|
1141
|
+
// Jan, Feb, ..., Dec
|
|
1142
|
+
case "MMM":
|
|
1143
|
+
return localize2.month(month, {
|
|
1144
|
+
width: "abbreviated",
|
|
1145
|
+
context: "formatting"
|
|
1146
|
+
});
|
|
1147
|
+
// J, F, ..., D
|
|
1148
|
+
case "MMMMM":
|
|
1149
|
+
return localize2.month(month, {
|
|
1150
|
+
width: "narrow",
|
|
1151
|
+
context: "formatting"
|
|
1152
|
+
});
|
|
1153
|
+
// January, February, ..., December
|
|
1154
|
+
case "MMMM":
|
|
1155
|
+
default:
|
|
1156
|
+
return localize2.month(month, { width: "wide", context: "formatting" });
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
// Stand-alone month
|
|
1160
|
+
L: function(date, token, localize2) {
|
|
1161
|
+
const month = date.getMonth();
|
|
1162
|
+
switch (token) {
|
|
1163
|
+
// 1, 2, ..., 12
|
|
1164
|
+
case "L":
|
|
1165
|
+
return String(month + 1);
|
|
1166
|
+
// 01, 02, ..., 12
|
|
1167
|
+
case "LL":
|
|
1168
|
+
return addLeadingZeros(month + 1, 2);
|
|
1169
|
+
// 1st, 2nd, ..., 12th
|
|
1170
|
+
case "Lo":
|
|
1171
|
+
return localize2.ordinalNumber(month + 1, { unit: "month" });
|
|
1172
|
+
// Jan, Feb, ..., Dec
|
|
1173
|
+
case "LLL":
|
|
1174
|
+
return localize2.month(month, {
|
|
1175
|
+
width: "abbreviated",
|
|
1176
|
+
context: "standalone"
|
|
1177
|
+
});
|
|
1178
|
+
// J, F, ..., D
|
|
1179
|
+
case "LLLLL":
|
|
1180
|
+
return localize2.month(month, {
|
|
1181
|
+
width: "narrow",
|
|
1182
|
+
context: "standalone"
|
|
1183
|
+
});
|
|
1184
|
+
// January, February, ..., December
|
|
1185
|
+
case "LLLL":
|
|
1186
|
+
default:
|
|
1187
|
+
return localize2.month(month, { width: "wide", context: "standalone" });
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
// Local week of year
|
|
1191
|
+
w: function(date, token, localize2, options) {
|
|
1192
|
+
const week = getWeek(date, options);
|
|
1193
|
+
if (token === "wo") {
|
|
1194
|
+
return localize2.ordinalNumber(week, { unit: "week" });
|
|
1195
|
+
}
|
|
1196
|
+
return addLeadingZeros(week, token.length);
|
|
1197
|
+
},
|
|
1198
|
+
// ISO week of year
|
|
1199
|
+
I: function(date, token, localize2) {
|
|
1200
|
+
const isoWeek = getISOWeek(date);
|
|
1201
|
+
if (token === "Io") {
|
|
1202
|
+
return localize2.ordinalNumber(isoWeek, { unit: "week" });
|
|
1203
|
+
}
|
|
1204
|
+
return addLeadingZeros(isoWeek, token.length);
|
|
1205
|
+
},
|
|
1206
|
+
// Day of the month
|
|
1207
|
+
d: function(date, token, localize2) {
|
|
1208
|
+
if (token === "do") {
|
|
1209
|
+
return localize2.ordinalNumber(date.getDate(), { unit: "date" });
|
|
1210
|
+
}
|
|
1211
|
+
return lightFormatters.d(date, token);
|
|
1212
|
+
},
|
|
1213
|
+
// Day of year
|
|
1214
|
+
D: function(date, token, localize2) {
|
|
1215
|
+
const dayOfYear = getDayOfYear(date);
|
|
1216
|
+
if (token === "Do") {
|
|
1217
|
+
return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
|
|
1218
|
+
}
|
|
1219
|
+
return addLeadingZeros(dayOfYear, token.length);
|
|
1220
|
+
},
|
|
1221
|
+
// Day of week
|
|
1222
|
+
E: function(date, token, localize2) {
|
|
1223
|
+
const dayOfWeek = date.getDay();
|
|
1224
|
+
switch (token) {
|
|
1225
|
+
// Tue
|
|
1226
|
+
case "E":
|
|
1227
|
+
case "EE":
|
|
1228
|
+
case "EEE":
|
|
1229
|
+
return localize2.day(dayOfWeek, {
|
|
1230
|
+
width: "abbreviated",
|
|
1231
|
+
context: "formatting"
|
|
1232
|
+
});
|
|
1233
|
+
// T
|
|
1234
|
+
case "EEEEE":
|
|
1235
|
+
return localize2.day(dayOfWeek, {
|
|
1236
|
+
width: "narrow",
|
|
1237
|
+
context: "formatting"
|
|
1238
|
+
});
|
|
1239
|
+
// Tu
|
|
1240
|
+
case "EEEEEE":
|
|
1241
|
+
return localize2.day(dayOfWeek, {
|
|
1242
|
+
width: "short",
|
|
1243
|
+
context: "formatting"
|
|
1244
|
+
});
|
|
1245
|
+
// Tuesday
|
|
1246
|
+
case "EEEE":
|
|
1247
|
+
default:
|
|
1248
|
+
return localize2.day(dayOfWeek, {
|
|
1249
|
+
width: "wide",
|
|
1250
|
+
context: "formatting"
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
// Local day of week
|
|
1255
|
+
e: function(date, token, localize2, options) {
|
|
1256
|
+
const dayOfWeek = date.getDay();
|
|
1257
|
+
const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
|
1258
|
+
switch (token) {
|
|
1259
|
+
// Numerical value (Nth day of week with current locale or weekStartsOn)
|
|
1260
|
+
case "e":
|
|
1261
|
+
return String(localDayOfWeek);
|
|
1262
|
+
// Padded numerical value
|
|
1263
|
+
case "ee":
|
|
1264
|
+
return addLeadingZeros(localDayOfWeek, 2);
|
|
1265
|
+
// 1st, 2nd, ..., 7th
|
|
1266
|
+
case "eo":
|
|
1267
|
+
return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
|
|
1268
|
+
case "eee":
|
|
1269
|
+
return localize2.day(dayOfWeek, {
|
|
1270
|
+
width: "abbreviated",
|
|
1271
|
+
context: "formatting"
|
|
1272
|
+
});
|
|
1273
|
+
// T
|
|
1274
|
+
case "eeeee":
|
|
1275
|
+
return localize2.day(dayOfWeek, {
|
|
1276
|
+
width: "narrow",
|
|
1277
|
+
context: "formatting"
|
|
1278
|
+
});
|
|
1279
|
+
// Tu
|
|
1280
|
+
case "eeeeee":
|
|
1281
|
+
return localize2.day(dayOfWeek, {
|
|
1282
|
+
width: "short",
|
|
1283
|
+
context: "formatting"
|
|
1284
|
+
});
|
|
1285
|
+
// Tuesday
|
|
1286
|
+
case "eeee":
|
|
1287
|
+
default:
|
|
1288
|
+
return localize2.day(dayOfWeek, {
|
|
1289
|
+
width: "wide",
|
|
1290
|
+
context: "formatting"
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
},
|
|
1294
|
+
// Stand-alone local day of week
|
|
1295
|
+
c: function(date, token, localize2, options) {
|
|
1296
|
+
const dayOfWeek = date.getDay();
|
|
1297
|
+
const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
|
|
1298
|
+
switch (token) {
|
|
1299
|
+
// Numerical value (same as in `e`)
|
|
1300
|
+
case "c":
|
|
1301
|
+
return String(localDayOfWeek);
|
|
1302
|
+
// Padded numerical value
|
|
1303
|
+
case "cc":
|
|
1304
|
+
return addLeadingZeros(localDayOfWeek, token.length);
|
|
1305
|
+
// 1st, 2nd, ..., 7th
|
|
1306
|
+
case "co":
|
|
1307
|
+
return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
|
|
1308
|
+
case "ccc":
|
|
1309
|
+
return localize2.day(dayOfWeek, {
|
|
1310
|
+
width: "abbreviated",
|
|
1311
|
+
context: "standalone"
|
|
1312
|
+
});
|
|
1313
|
+
// T
|
|
1314
|
+
case "ccccc":
|
|
1315
|
+
return localize2.day(dayOfWeek, {
|
|
1316
|
+
width: "narrow",
|
|
1317
|
+
context: "standalone"
|
|
1318
|
+
});
|
|
1319
|
+
// Tu
|
|
1320
|
+
case "cccccc":
|
|
1321
|
+
return localize2.day(dayOfWeek, {
|
|
1322
|
+
width: "short",
|
|
1323
|
+
context: "standalone"
|
|
1324
|
+
});
|
|
1325
|
+
// Tuesday
|
|
1326
|
+
case "cccc":
|
|
1327
|
+
default:
|
|
1328
|
+
return localize2.day(dayOfWeek, {
|
|
1329
|
+
width: "wide",
|
|
1330
|
+
context: "standalone"
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
// ISO day of week
|
|
1335
|
+
i: function(date, token, localize2) {
|
|
1336
|
+
const dayOfWeek = date.getDay();
|
|
1337
|
+
const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
|
|
1338
|
+
switch (token) {
|
|
1339
|
+
// 2
|
|
1340
|
+
case "i":
|
|
1341
|
+
return String(isoDayOfWeek);
|
|
1342
|
+
// 02
|
|
1343
|
+
case "ii":
|
|
1344
|
+
return addLeadingZeros(isoDayOfWeek, token.length);
|
|
1345
|
+
// 2nd
|
|
1346
|
+
case "io":
|
|
1347
|
+
return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
|
|
1348
|
+
// Tue
|
|
1349
|
+
case "iii":
|
|
1350
|
+
return localize2.day(dayOfWeek, {
|
|
1351
|
+
width: "abbreviated",
|
|
1352
|
+
context: "formatting"
|
|
1353
|
+
});
|
|
1354
|
+
// T
|
|
1355
|
+
case "iiiii":
|
|
1356
|
+
return localize2.day(dayOfWeek, {
|
|
1357
|
+
width: "narrow",
|
|
1358
|
+
context: "formatting"
|
|
1359
|
+
});
|
|
1360
|
+
// Tu
|
|
1361
|
+
case "iiiiii":
|
|
1362
|
+
return localize2.day(dayOfWeek, {
|
|
1363
|
+
width: "short",
|
|
1364
|
+
context: "formatting"
|
|
1365
|
+
});
|
|
1366
|
+
// Tuesday
|
|
1367
|
+
case "iiii":
|
|
1368
|
+
default:
|
|
1369
|
+
return localize2.day(dayOfWeek, {
|
|
1370
|
+
width: "wide",
|
|
1371
|
+
context: "formatting"
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
},
|
|
1375
|
+
// AM or PM
|
|
1376
|
+
a: function(date, token, localize2) {
|
|
1377
|
+
const hours = date.getHours();
|
|
1378
|
+
const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
|
|
1379
|
+
switch (token) {
|
|
1380
|
+
case "a":
|
|
1381
|
+
case "aa":
|
|
1382
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1383
|
+
width: "abbreviated",
|
|
1384
|
+
context: "formatting"
|
|
1385
|
+
});
|
|
1386
|
+
case "aaa":
|
|
1387
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1388
|
+
width: "abbreviated",
|
|
1389
|
+
context: "formatting"
|
|
1390
|
+
}).toLowerCase();
|
|
1391
|
+
case "aaaaa":
|
|
1392
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1393
|
+
width: "narrow",
|
|
1394
|
+
context: "formatting"
|
|
1395
|
+
});
|
|
1396
|
+
case "aaaa":
|
|
1397
|
+
default:
|
|
1398
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1399
|
+
width: "wide",
|
|
1400
|
+
context: "formatting"
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
},
|
|
1404
|
+
// AM, PM, midnight, noon
|
|
1405
|
+
b: function(date, token, localize2) {
|
|
1406
|
+
const hours = date.getHours();
|
|
1407
|
+
let dayPeriodEnumValue;
|
|
1408
|
+
if (hours === 12) {
|
|
1409
|
+
dayPeriodEnumValue = dayPeriodEnum.noon;
|
|
1410
|
+
} else if (hours === 0) {
|
|
1411
|
+
dayPeriodEnumValue = dayPeriodEnum.midnight;
|
|
1412
|
+
} else {
|
|
1413
|
+
dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
|
|
1414
|
+
}
|
|
1415
|
+
switch (token) {
|
|
1416
|
+
case "b":
|
|
1417
|
+
case "bb":
|
|
1418
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1419
|
+
width: "abbreviated",
|
|
1420
|
+
context: "formatting"
|
|
1421
|
+
});
|
|
1422
|
+
case "bbb":
|
|
1423
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1424
|
+
width: "abbreviated",
|
|
1425
|
+
context: "formatting"
|
|
1426
|
+
}).toLowerCase();
|
|
1427
|
+
case "bbbbb":
|
|
1428
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1429
|
+
width: "narrow",
|
|
1430
|
+
context: "formatting"
|
|
1431
|
+
});
|
|
1432
|
+
case "bbbb":
|
|
1433
|
+
default:
|
|
1434
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1435
|
+
width: "wide",
|
|
1436
|
+
context: "formatting"
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
},
|
|
1440
|
+
// in the morning, in the afternoon, in the evening, at night
|
|
1441
|
+
B: function(date, token, localize2) {
|
|
1442
|
+
const hours = date.getHours();
|
|
1443
|
+
let dayPeriodEnumValue;
|
|
1444
|
+
if (hours >= 17) {
|
|
1445
|
+
dayPeriodEnumValue = dayPeriodEnum.evening;
|
|
1446
|
+
} else if (hours >= 12) {
|
|
1447
|
+
dayPeriodEnumValue = dayPeriodEnum.afternoon;
|
|
1448
|
+
} else if (hours >= 4) {
|
|
1449
|
+
dayPeriodEnumValue = dayPeriodEnum.morning;
|
|
1450
|
+
} else {
|
|
1451
|
+
dayPeriodEnumValue = dayPeriodEnum.night;
|
|
1452
|
+
}
|
|
1453
|
+
switch (token) {
|
|
1454
|
+
case "B":
|
|
1455
|
+
case "BB":
|
|
1456
|
+
case "BBB":
|
|
1457
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1458
|
+
width: "abbreviated",
|
|
1459
|
+
context: "formatting"
|
|
1460
|
+
});
|
|
1461
|
+
case "BBBBB":
|
|
1462
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1463
|
+
width: "narrow",
|
|
1464
|
+
context: "formatting"
|
|
1465
|
+
});
|
|
1466
|
+
case "BBBB":
|
|
1467
|
+
default:
|
|
1468
|
+
return localize2.dayPeriod(dayPeriodEnumValue, {
|
|
1469
|
+
width: "wide",
|
|
1470
|
+
context: "formatting"
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
},
|
|
1474
|
+
// Hour [1-12]
|
|
1475
|
+
h: function(date, token, localize2) {
|
|
1476
|
+
if (token === "ho") {
|
|
1477
|
+
let hours = date.getHours() % 12;
|
|
1478
|
+
if (hours === 0) hours = 12;
|
|
1479
|
+
return localize2.ordinalNumber(hours, { unit: "hour" });
|
|
1480
|
+
}
|
|
1481
|
+
return lightFormatters.h(date, token);
|
|
1482
|
+
},
|
|
1483
|
+
// Hour [0-23]
|
|
1484
|
+
H: function(date, token, localize2) {
|
|
1485
|
+
if (token === "Ho") {
|
|
1486
|
+
return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
|
|
1487
|
+
}
|
|
1488
|
+
return lightFormatters.H(date, token);
|
|
1489
|
+
},
|
|
1490
|
+
// Hour [0-11]
|
|
1491
|
+
K: function(date, token, localize2) {
|
|
1492
|
+
const hours = date.getHours() % 12;
|
|
1493
|
+
if (token === "Ko") {
|
|
1494
|
+
return localize2.ordinalNumber(hours, { unit: "hour" });
|
|
1495
|
+
}
|
|
1496
|
+
return addLeadingZeros(hours, token.length);
|
|
1497
|
+
},
|
|
1498
|
+
// Hour [1-24]
|
|
1499
|
+
k: function(date, token, localize2) {
|
|
1500
|
+
let hours = date.getHours();
|
|
1501
|
+
if (hours === 0) hours = 24;
|
|
1502
|
+
if (token === "ko") {
|
|
1503
|
+
return localize2.ordinalNumber(hours, { unit: "hour" });
|
|
1504
|
+
}
|
|
1505
|
+
return addLeadingZeros(hours, token.length);
|
|
1506
|
+
},
|
|
1507
|
+
// Minute
|
|
1508
|
+
m: function(date, token, localize2) {
|
|
1509
|
+
if (token === "mo") {
|
|
1510
|
+
return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
|
|
1511
|
+
}
|
|
1512
|
+
return lightFormatters.m(date, token);
|
|
1513
|
+
},
|
|
1514
|
+
// Second
|
|
1515
|
+
s: function(date, token, localize2) {
|
|
1516
|
+
if (token === "so") {
|
|
1517
|
+
return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
|
|
1518
|
+
}
|
|
1519
|
+
return lightFormatters.s(date, token);
|
|
1520
|
+
},
|
|
1521
|
+
// Fraction of second
|
|
1522
|
+
S: function(date, token) {
|
|
1523
|
+
return lightFormatters.S(date, token);
|
|
1524
|
+
},
|
|
1525
|
+
// Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
|
|
1526
|
+
X: function(date, token, _localize) {
|
|
1527
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1528
|
+
if (timezoneOffset === 0) {
|
|
1529
|
+
return "Z";
|
|
1530
|
+
}
|
|
1531
|
+
switch (token) {
|
|
1532
|
+
// Hours and optional minutes
|
|
1533
|
+
case "X":
|
|
1534
|
+
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
|
1535
|
+
// Hours, minutes and optional seconds without `:` delimiter
|
|
1536
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1537
|
+
// so this token always has the same output as `XX`
|
|
1538
|
+
case "XXXX":
|
|
1539
|
+
case "XX":
|
|
1540
|
+
return formatTimezone(timezoneOffset);
|
|
1541
|
+
// Hours, minutes and optional seconds with `:` delimiter
|
|
1542
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1543
|
+
// so this token always has the same output as `XXX`
|
|
1544
|
+
case "XXXXX":
|
|
1545
|
+
case "XXX":
|
|
1546
|
+
// Hours and minutes with `:` delimiter
|
|
1547
|
+
default:
|
|
1548
|
+
return formatTimezone(timezoneOffset, ":");
|
|
1549
|
+
}
|
|
1550
|
+
},
|
|
1551
|
+
// Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
|
|
1552
|
+
x: function(date, token, _localize) {
|
|
1553
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1554
|
+
switch (token) {
|
|
1555
|
+
// Hours and optional minutes
|
|
1556
|
+
case "x":
|
|
1557
|
+
return formatTimezoneWithOptionalMinutes(timezoneOffset);
|
|
1558
|
+
// Hours, minutes and optional seconds without `:` delimiter
|
|
1559
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1560
|
+
// so this token always has the same output as `xx`
|
|
1561
|
+
case "xxxx":
|
|
1562
|
+
case "xx":
|
|
1563
|
+
return formatTimezone(timezoneOffset);
|
|
1564
|
+
// Hours, minutes and optional seconds with `:` delimiter
|
|
1565
|
+
// Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
|
|
1566
|
+
// so this token always has the same output as `xxx`
|
|
1567
|
+
case "xxxxx":
|
|
1568
|
+
case "xxx":
|
|
1569
|
+
// Hours and minutes with `:` delimiter
|
|
1570
|
+
default:
|
|
1571
|
+
return formatTimezone(timezoneOffset, ":");
|
|
1572
|
+
}
|
|
1573
|
+
},
|
|
1574
|
+
// Timezone (GMT)
|
|
1575
|
+
O: function(date, token, _localize) {
|
|
1576
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1577
|
+
switch (token) {
|
|
1578
|
+
// Short
|
|
1579
|
+
case "O":
|
|
1580
|
+
case "OO":
|
|
1581
|
+
case "OOO":
|
|
1582
|
+
return "GMT" + formatTimezoneShort(timezoneOffset, ":");
|
|
1583
|
+
// Long
|
|
1584
|
+
case "OOOO":
|
|
1585
|
+
default:
|
|
1586
|
+
return "GMT" + formatTimezone(timezoneOffset, ":");
|
|
1587
|
+
}
|
|
1588
|
+
},
|
|
1589
|
+
// Timezone (specific non-location)
|
|
1590
|
+
z: function(date, token, _localize) {
|
|
1591
|
+
const timezoneOffset = date.getTimezoneOffset();
|
|
1592
|
+
switch (token) {
|
|
1593
|
+
// Short
|
|
1594
|
+
case "z":
|
|
1595
|
+
case "zz":
|
|
1596
|
+
case "zzz":
|
|
1597
|
+
return "GMT" + formatTimezoneShort(timezoneOffset, ":");
|
|
1598
|
+
// Long
|
|
1599
|
+
case "zzzz":
|
|
1600
|
+
default:
|
|
1601
|
+
return "GMT" + formatTimezone(timezoneOffset, ":");
|
|
1602
|
+
}
|
|
1603
|
+
},
|
|
1604
|
+
// Seconds timestamp
|
|
1605
|
+
t: function(date, token, _localize) {
|
|
1606
|
+
const timestamp = Math.trunc(+date / 1e3);
|
|
1607
|
+
return addLeadingZeros(timestamp, token.length);
|
|
1608
|
+
},
|
|
1609
|
+
// Milliseconds timestamp
|
|
1610
|
+
T: function(date, token, _localize) {
|
|
1611
|
+
return addLeadingZeros(+date, token.length);
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
function formatTimezoneShort(offset, delimiter = "") {
|
|
1615
|
+
const sign = offset > 0 ? "-" : "+";
|
|
1616
|
+
const absOffset = Math.abs(offset);
|
|
1617
|
+
const hours = Math.trunc(absOffset / 60);
|
|
1618
|
+
const minutes = absOffset % 60;
|
|
1619
|
+
if (minutes === 0) {
|
|
1620
|
+
return sign + String(hours);
|
|
1621
|
+
}
|
|
1622
|
+
return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
|
|
1623
|
+
}
|
|
1624
|
+
function formatTimezoneWithOptionalMinutes(offset, delimiter) {
|
|
1625
|
+
if (offset % 60 === 0) {
|
|
1626
|
+
const sign = offset > 0 ? "-" : "+";
|
|
1627
|
+
return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
|
|
1628
|
+
}
|
|
1629
|
+
return formatTimezone(offset, delimiter);
|
|
1630
|
+
}
|
|
1631
|
+
function formatTimezone(offset, delimiter = "") {
|
|
1632
|
+
const sign = offset > 0 ? "-" : "+";
|
|
1633
|
+
const absOffset = Math.abs(offset);
|
|
1634
|
+
const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
|
|
1635
|
+
const minutes = addLeadingZeros(absOffset % 60, 2);
|
|
1636
|
+
return sign + hours + delimiter + minutes;
|
|
1637
|
+
}
|
|
1638
|
+
const dateLongFormatter = (pattern, formatLong2) => {
|
|
1639
|
+
switch (pattern) {
|
|
1640
|
+
case "P":
|
|
1641
|
+
return formatLong2.date({ width: "short" });
|
|
1642
|
+
case "PP":
|
|
1643
|
+
return formatLong2.date({ width: "medium" });
|
|
1644
|
+
case "PPP":
|
|
1645
|
+
return formatLong2.date({ width: "long" });
|
|
1646
|
+
case "PPPP":
|
|
1647
|
+
default:
|
|
1648
|
+
return formatLong2.date({ width: "full" });
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
const timeLongFormatter = (pattern, formatLong2) => {
|
|
1652
|
+
switch (pattern) {
|
|
1653
|
+
case "p":
|
|
1654
|
+
return formatLong2.time({ width: "short" });
|
|
1655
|
+
case "pp":
|
|
1656
|
+
return formatLong2.time({ width: "medium" });
|
|
1657
|
+
case "ppp":
|
|
1658
|
+
return formatLong2.time({ width: "long" });
|
|
1659
|
+
case "pppp":
|
|
1660
|
+
default:
|
|
1661
|
+
return formatLong2.time({ width: "full" });
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
const dateTimeLongFormatter = (pattern, formatLong2) => {
|
|
1665
|
+
const matchResult = pattern.match(/(P+)(p+)?/) || [];
|
|
1666
|
+
const datePattern = matchResult[1];
|
|
1667
|
+
const timePattern = matchResult[2];
|
|
1668
|
+
if (!timePattern) {
|
|
1669
|
+
return dateLongFormatter(pattern, formatLong2);
|
|
1670
|
+
}
|
|
1671
|
+
let dateTimeFormat;
|
|
1672
|
+
switch (datePattern) {
|
|
1673
|
+
case "P":
|
|
1674
|
+
dateTimeFormat = formatLong2.dateTime({ width: "short" });
|
|
1675
|
+
break;
|
|
1676
|
+
case "PP":
|
|
1677
|
+
dateTimeFormat = formatLong2.dateTime({ width: "medium" });
|
|
1678
|
+
break;
|
|
1679
|
+
case "PPP":
|
|
1680
|
+
dateTimeFormat = formatLong2.dateTime({ width: "long" });
|
|
1681
|
+
break;
|
|
1682
|
+
case "PPPP":
|
|
1683
|
+
default:
|
|
1684
|
+
dateTimeFormat = formatLong2.dateTime({ width: "full" });
|
|
1685
|
+
break;
|
|
1686
|
+
}
|
|
1687
|
+
return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
|
|
1688
|
+
};
|
|
1689
|
+
const longFormatters = {
|
|
1690
|
+
p: timeLongFormatter,
|
|
1691
|
+
P: dateTimeLongFormatter
|
|
1692
|
+
};
|
|
1693
|
+
const dayOfYearTokenRE = /^D+$/;
|
|
1694
|
+
const weekYearTokenRE = /^Y+$/;
|
|
1695
|
+
const throwTokens = ["D", "DD", "YY", "YYYY"];
|
|
1696
|
+
function isProtectedDayOfYearToken(token) {
|
|
1697
|
+
return dayOfYearTokenRE.test(token);
|
|
1698
|
+
}
|
|
1699
|
+
function isProtectedWeekYearToken(token) {
|
|
1700
|
+
return weekYearTokenRE.test(token);
|
|
1701
|
+
}
|
|
1702
|
+
function warnOrThrowProtectedError(token, format2, input) {
|
|
1703
|
+
const _message = message(token, format2, input);
|
|
1704
|
+
console.warn(_message);
|
|
1705
|
+
if (throwTokens.includes(token)) throw new RangeError(_message);
|
|
1706
|
+
}
|
|
1707
|
+
function message(token, format2, input) {
|
|
1708
|
+
const subject = token[0] === "Y" ? "years" : "days of the month";
|
|
1709
|
+
return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format2}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
|
|
1710
|
+
}
|
|
1711
|
+
const formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
|
|
1712
|
+
const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
1713
|
+
const escapedStringRegExp = /^'([^]*?)'?$/;
|
|
1714
|
+
const doubleQuoteRegExp = /''/g;
|
|
1715
|
+
const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
|
|
1716
|
+
function format(date, formatStr, options) {
|
|
1717
|
+
var _a, _b, _c, _d;
|
|
1718
|
+
const defaultOptions2 = getDefaultOptions();
|
|
1719
|
+
const locale = defaultOptions2.locale ?? enUS;
|
|
1720
|
+
const firstWeekContainsDate = defaultOptions2.firstWeekContainsDate ?? ((_b = (_a = defaultOptions2.locale) == null ? void 0 : _a.options) == null ? void 0 : _b.firstWeekContainsDate) ?? 1;
|
|
1721
|
+
const weekStartsOn = defaultOptions2.weekStartsOn ?? ((_d = (_c = defaultOptions2.locale) == null ? void 0 : _c.options) == null ? void 0 : _d.weekStartsOn) ?? 0;
|
|
1722
|
+
const originalDate = toDate(date, options == null ? void 0 : options.in);
|
|
1723
|
+
if (!isValid(originalDate)) {
|
|
1724
|
+
throw new RangeError("Invalid time value");
|
|
1725
|
+
}
|
|
1726
|
+
let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
|
|
1727
|
+
const firstCharacter = substring[0];
|
|
1728
|
+
if (firstCharacter === "p" || firstCharacter === "P") {
|
|
1729
|
+
const longFormatter = longFormatters[firstCharacter];
|
|
1730
|
+
return longFormatter(substring, locale.formatLong);
|
|
1731
|
+
}
|
|
1732
|
+
return substring;
|
|
1733
|
+
}).join("").match(formattingTokensRegExp).map((substring) => {
|
|
1734
|
+
if (substring === "''") {
|
|
1735
|
+
return { isToken: false, value: "'" };
|
|
1736
|
+
}
|
|
1737
|
+
const firstCharacter = substring[0];
|
|
1738
|
+
if (firstCharacter === "'") {
|
|
1739
|
+
return { isToken: false, value: cleanEscapedString(substring) };
|
|
1740
|
+
}
|
|
1741
|
+
if (formatters[firstCharacter]) {
|
|
1742
|
+
return { isToken: true, value: substring };
|
|
1743
|
+
}
|
|
1744
|
+
if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
|
|
1745
|
+
throw new RangeError(
|
|
1746
|
+
"Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
return { isToken: false, value: substring };
|
|
1750
|
+
});
|
|
1751
|
+
if (locale.localize.preprocessor) {
|
|
1752
|
+
parts = locale.localize.preprocessor(originalDate, parts);
|
|
1753
|
+
}
|
|
1754
|
+
const formatterOptions = {
|
|
1755
|
+
firstWeekContainsDate,
|
|
1756
|
+
weekStartsOn,
|
|
1757
|
+
locale
|
|
1758
|
+
};
|
|
1759
|
+
return parts.map((part) => {
|
|
1760
|
+
if (!part.isToken) return part.value;
|
|
1761
|
+
const token = part.value;
|
|
1762
|
+
if (isProtectedWeekYearToken(token) || isProtectedDayOfYearToken(token)) {
|
|
1763
|
+
warnOrThrowProtectedError(token, formatStr, String(date));
|
|
1764
|
+
}
|
|
1765
|
+
const formatter = formatters[token[0]];
|
|
1766
|
+
return formatter(originalDate, token, locale.localize, formatterOptions);
|
|
1767
|
+
}).join("");
|
|
1768
|
+
}
|
|
1769
|
+
function cleanEscapedString(input) {
|
|
1770
|
+
const matched = input.match(escapedStringRegExp);
|
|
1771
|
+
if (!matched) {
|
|
1772
|
+
return input;
|
|
1773
|
+
}
|
|
1774
|
+
return matched[1].replace(doubleQuoteRegExp, "'");
|
|
1775
|
+
}
|
|
1776
|
+
function NodeInput(props) {
|
|
1777
|
+
const { onSubmit, onCancel, defaultValue, className, minLength = 1, ...inputProps } = props;
|
|
1778
|
+
const [value, setValue] = useState(defaultValue ?? "");
|
|
1779
|
+
const ref = useRef(null);
|
|
1780
|
+
useOnClickOutside(ref, handleSubmit);
|
|
1781
|
+
useEventListener("keyup", (e) => {
|
|
1782
|
+
if (e.key === "Enter") {
|
|
1783
|
+
handleSubmit();
|
|
1784
|
+
}
|
|
1785
|
+
if (e.key === "Escape") {
|
|
1786
|
+
onCancel();
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
useLayoutEffect(() => {
|
|
1790
|
+
setTimeout(() => {
|
|
1791
|
+
var _a, _b, _c;
|
|
1792
|
+
(_a = ref.current) == null ? void 0 : _a.focus();
|
|
1793
|
+
(_b = ref.current) == null ? void 0 : _b.select();
|
|
1794
|
+
(_c = ref.current) == null ? void 0 : _c.scroll({ left: 9999 });
|
|
1795
|
+
}, 100);
|
|
1796
|
+
}, []);
|
|
1797
|
+
function handleSubmit() {
|
|
1798
|
+
if (value.length >= minLength) {
|
|
1799
|
+
onSubmit(value);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
return jsx("input", { ...inputProps, autoFocus: true, className: twMerge("bg-inherit text-inherit outline-none", className), minLength, onChange: (e) => setValue(e.target.value), ref, required: true, type: "text", value });
|
|
1803
|
+
}
|
|
1804
|
+
function Branch(props) {
|
|
1805
|
+
const { branch = "main" } = props;
|
|
1806
|
+
return jsxs("button", { className: "flex h-8 items-center gap-1 rounded-lg bg-slate-50 pl-1 pr-2 text-xs text-slate-100", children: [jsx(Icon, { name: "Branch" }), jsx("span", { children: "BRANCH" }), jsx("span", { className: "text-gray-900", children: branch })] });
|
|
1807
|
+
}
|
|
1808
|
+
function DocId(props) {
|
|
1809
|
+
const { docId } = props;
|
|
1810
|
+
const [, copy] = useCopyToClipboard();
|
|
1811
|
+
function handleCopy(text) {
|
|
1812
|
+
return () => {
|
|
1813
|
+
copy(text).catch((error) => {
|
|
1814
|
+
console.error("Failed to copy!", error);
|
|
1815
|
+
});
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
return jsxs("button", { className: "flex h-8 items-center gap-1 rounded-lg bg-slate-50 pl-1 pr-2 text-xs text-slate-100", onClick: handleCopy(docId), children: [jsx(Icon, { name: "Link" }), "DOC ID", jsx("span", { className: "text-gray-900", children: docId })] });
|
|
1819
|
+
}
|
|
1820
|
+
function Scope(props) {
|
|
1821
|
+
const { value, onChange } = props;
|
|
1822
|
+
const items = [
|
|
1823
|
+
{ displayValue: "Global scope", value: "global" },
|
|
1824
|
+
{ displayValue: "Local scope", value: "local" }
|
|
1825
|
+
];
|
|
1826
|
+
return jsx(Select, { absolutePositionMenu: true, containerClassName: "bg-slate-50 text-gray-500 rounded-lg w-fit text-xs z-10", id: "scope select", itemClassName: "py-2 text-gray-500 grid grid-cols-[auto,auto] gap-1", items, menuClassName: "min-w-0 text-gray-500", onChange, value });
|
|
1827
|
+
}
|
|
1828
|
+
function Header(props) {
|
|
1829
|
+
const { title, docId, scope, onChangeScope, onClose, className, ...divProps } = props;
|
|
1830
|
+
return jsxs("header", { className: twMerge("flex items-center justify-between bg-transparent", className), ...divProps, children: [jsxs("div", { className: "flex items-center gap-3", children: [jsx("button", { className: "shadow-button rounded-lg bg-gray-50 p-1 text-slate-100", onClick: onClose, children: jsx(Icon, { name: "VariantArrowLeft" }) }), jsx("h1", { className: "text-xs", children: title })] }), jsxs("div", { className: "flex items-center gap-2", children: [jsx(DocId, { docId }), jsx(Branch, {}), jsx(Scope, { onChange: onChangeScope, value: scope })] })] });
|
|
1831
|
+
}
|
|
1832
|
+
function memo(getDeps, fn, opts) {
|
|
1833
|
+
let deps = opts.initialDeps ?? [];
|
|
1834
|
+
let result;
|
|
1835
|
+
function memoizedFunction() {
|
|
1836
|
+
var _a, _b, _c, _d;
|
|
1837
|
+
let depTime;
|
|
1838
|
+
if (opts.key && ((_a = opts.debug) == null ? void 0 : _a.call(opts))) depTime = Date.now();
|
|
1839
|
+
const newDeps = getDeps();
|
|
1840
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
1841
|
+
if (!depsChanged) {
|
|
1842
|
+
return result;
|
|
1843
|
+
}
|
|
1844
|
+
deps = newDeps;
|
|
1845
|
+
let resultTime;
|
|
1846
|
+
if (opts.key && ((_b = opts.debug) == null ? void 0 : _b.call(opts))) resultTime = Date.now();
|
|
1847
|
+
result = fn(...newDeps);
|
|
1848
|
+
if (opts.key && ((_c = opts.debug) == null ? void 0 : _c.call(opts))) {
|
|
1849
|
+
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
1850
|
+
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
1851
|
+
const resultFpsPercentage = resultEndTime / 16;
|
|
1852
|
+
const pad = (str, num) => {
|
|
1853
|
+
str = String(str);
|
|
1854
|
+
while (str.length < num) {
|
|
1855
|
+
str = " " + str;
|
|
1856
|
+
}
|
|
1857
|
+
return str;
|
|
1858
|
+
};
|
|
1859
|
+
console.info(
|
|
1860
|
+
`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,
|
|
1861
|
+
`
|
|
1862
|
+
font-size: .6rem;
|
|
1863
|
+
font-weight: bold;
|
|
1864
|
+
color: hsl(${Math.max(
|
|
1865
|
+
0,
|
|
1866
|
+
Math.min(120 - 120 * resultFpsPercentage, 120)
|
|
1867
|
+
)}deg 100% 31%);`,
|
|
1868
|
+
opts == null ? void 0 : opts.key
|
|
1869
|
+
);
|
|
1870
|
+
}
|
|
1871
|
+
(_d = opts == null ? void 0 : opts.onChange) == null ? void 0 : _d.call(opts, result);
|
|
1872
|
+
return result;
|
|
1873
|
+
}
|
|
1874
|
+
memoizedFunction.updateDeps = (newDeps) => {
|
|
1875
|
+
deps = newDeps;
|
|
1876
|
+
};
|
|
1877
|
+
return memoizedFunction;
|
|
1878
|
+
}
|
|
1879
|
+
function notUndefined(value, msg) {
|
|
1880
|
+
if (value === void 0) {
|
|
1881
|
+
throw new Error(`Unexpected undefined${""}`);
|
|
1882
|
+
} else {
|
|
1883
|
+
return value;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
const approxEqual = (a, b) => Math.abs(a - b) < 1;
|
|
1887
|
+
const debounce = (targetWindow, fn, ms) => {
|
|
1888
|
+
let timeoutId;
|
|
1889
|
+
return function(...args) {
|
|
1890
|
+
targetWindow.clearTimeout(timeoutId);
|
|
1891
|
+
timeoutId = targetWindow.setTimeout(() => fn.apply(this, args), ms);
|
|
1892
|
+
};
|
|
1893
|
+
};
|
|
1894
|
+
const defaultKeyExtractor = (index) => index;
|
|
1895
|
+
const defaultRangeExtractor = (range) => {
|
|
1896
|
+
const start = Math.max(range.startIndex - range.overscan, 0);
|
|
1897
|
+
const end = Math.min(range.endIndex + range.overscan, range.count - 1);
|
|
1898
|
+
const arr = [];
|
|
1899
|
+
for (let i = start; i <= end; i++) {
|
|
1900
|
+
arr.push(i);
|
|
1901
|
+
}
|
|
1902
|
+
return arr;
|
|
1903
|
+
};
|
|
1904
|
+
const observeElementRect = (instance, cb) => {
|
|
1905
|
+
const element = instance.scrollElement;
|
|
1906
|
+
if (!element) {
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
const targetWindow = instance.targetWindow;
|
|
1910
|
+
if (!targetWindow) {
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
const handler = (rect) => {
|
|
1914
|
+
const { width, height } = rect;
|
|
1915
|
+
cb({ width: Math.round(width), height: Math.round(height) });
|
|
1916
|
+
};
|
|
1917
|
+
handler(element.getBoundingClientRect());
|
|
1918
|
+
if (!targetWindow.ResizeObserver) {
|
|
1919
|
+
return () => {
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
const observer = new targetWindow.ResizeObserver((entries) => {
|
|
1923
|
+
const run = () => {
|
|
1924
|
+
const entry = entries[0];
|
|
1925
|
+
if (entry == null ? void 0 : entry.borderBoxSize) {
|
|
1926
|
+
const box = entry.borderBoxSize[0];
|
|
1927
|
+
if (box) {
|
|
1928
|
+
handler({ width: box.inlineSize, height: box.blockSize });
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
handler(element.getBoundingClientRect());
|
|
1933
|
+
};
|
|
1934
|
+
instance.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
|
|
1935
|
+
});
|
|
1936
|
+
observer.observe(element, { box: "border-box" });
|
|
1937
|
+
return () => {
|
|
1938
|
+
observer.unobserve(element);
|
|
1939
|
+
};
|
|
1940
|
+
};
|
|
1941
|
+
const addEventListenerOptions = {
|
|
1942
|
+
passive: true
|
|
1943
|
+
};
|
|
1944
|
+
const supportsScrollend = typeof window == "undefined" ? true : "onscrollend" in window;
|
|
1945
|
+
const observeElementOffset = (instance, cb) => {
|
|
1946
|
+
const element = instance.scrollElement;
|
|
1947
|
+
if (!element) {
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
const targetWindow = instance.targetWindow;
|
|
1951
|
+
if (!targetWindow) {
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
let offset = 0;
|
|
1955
|
+
const fallback = instance.options.useScrollendEvent && supportsScrollend ? () => void 0 : debounce(
|
|
1956
|
+
targetWindow,
|
|
1957
|
+
() => {
|
|
1958
|
+
cb(offset, false);
|
|
1959
|
+
},
|
|
1960
|
+
instance.options.isScrollingResetDelay
|
|
1961
|
+
);
|
|
1962
|
+
const createHandler = (isScrolling) => () => {
|
|
1963
|
+
const { horizontal, isRtl } = instance.options;
|
|
1964
|
+
offset = horizontal ? element["scrollLeft"] * (isRtl && -1 || 1) : element["scrollTop"];
|
|
1965
|
+
fallback();
|
|
1966
|
+
cb(offset, isScrolling);
|
|
1967
|
+
};
|
|
1968
|
+
const handler = createHandler(true);
|
|
1969
|
+
const endHandler = createHandler(false);
|
|
1970
|
+
endHandler();
|
|
1971
|
+
element.addEventListener("scroll", handler, addEventListenerOptions);
|
|
1972
|
+
const registerScrollendEvent = instance.options.useScrollendEvent && supportsScrollend;
|
|
1973
|
+
if (registerScrollendEvent) {
|
|
1974
|
+
element.addEventListener("scrollend", endHandler, addEventListenerOptions);
|
|
1975
|
+
}
|
|
1976
|
+
return () => {
|
|
1977
|
+
element.removeEventListener("scroll", handler);
|
|
1978
|
+
if (registerScrollendEvent) {
|
|
1979
|
+
element.removeEventListener("scrollend", endHandler);
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
};
|
|
1983
|
+
const measureElement = (element, entry, instance) => {
|
|
1984
|
+
if (entry == null ? void 0 : entry.borderBoxSize) {
|
|
1985
|
+
const box = entry.borderBoxSize[0];
|
|
1986
|
+
if (box) {
|
|
1987
|
+
const size = Math.round(
|
|
1988
|
+
box[instance.options.horizontal ? "inlineSize" : "blockSize"]
|
|
1989
|
+
);
|
|
1990
|
+
return size;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
return Math.round(
|
|
1994
|
+
element.getBoundingClientRect()[instance.options.horizontal ? "width" : "height"]
|
|
1995
|
+
);
|
|
1996
|
+
};
|
|
1997
|
+
const elementScroll = (offset, {
|
|
1998
|
+
adjustments = 0,
|
|
1999
|
+
behavior
|
|
2000
|
+
}, instance) => {
|
|
2001
|
+
var _a, _b;
|
|
2002
|
+
const toOffset = offset + adjustments;
|
|
2003
|
+
(_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null ? void 0 : _b.call(_a, {
|
|
2004
|
+
[instance.options.horizontal ? "left" : "top"]: toOffset,
|
|
2005
|
+
behavior
|
|
2006
|
+
});
|
|
2007
|
+
};
|
|
2008
|
+
class Virtualizer {
|
|
2009
|
+
constructor(opts) {
|
|
2010
|
+
this.unsubs = [];
|
|
2011
|
+
this.scrollElement = null;
|
|
2012
|
+
this.targetWindow = null;
|
|
2013
|
+
this.isScrolling = false;
|
|
2014
|
+
this.scrollToIndexTimeoutId = null;
|
|
2015
|
+
this.measurementsCache = [];
|
|
2016
|
+
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
2017
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
2018
|
+
this.scrollRect = null;
|
|
2019
|
+
this.scrollOffset = null;
|
|
2020
|
+
this.scrollDirection = null;
|
|
2021
|
+
this.scrollAdjustments = 0;
|
|
2022
|
+
this.elementsCache = /* @__PURE__ */ new Map();
|
|
2023
|
+
this.observer = /* @__PURE__ */ (() => {
|
|
2024
|
+
let _ro = null;
|
|
2025
|
+
const get = () => {
|
|
2026
|
+
if (_ro) {
|
|
2027
|
+
return _ro;
|
|
2028
|
+
}
|
|
2029
|
+
if (!this.targetWindow || !this.targetWindow.ResizeObserver) {
|
|
2030
|
+
return null;
|
|
2031
|
+
}
|
|
2032
|
+
return _ro = new this.targetWindow.ResizeObserver((entries) => {
|
|
2033
|
+
entries.forEach((entry) => {
|
|
2034
|
+
const run = () => {
|
|
2035
|
+
this._measureElement(entry.target, entry);
|
|
2036
|
+
};
|
|
2037
|
+
this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
|
|
2038
|
+
});
|
|
2039
|
+
});
|
|
2040
|
+
};
|
|
2041
|
+
return {
|
|
2042
|
+
disconnect: () => {
|
|
2043
|
+
var _a;
|
|
2044
|
+
(_a = get()) == null ? void 0 : _a.disconnect();
|
|
2045
|
+
_ro = null;
|
|
2046
|
+
},
|
|
2047
|
+
observe: (target) => {
|
|
2048
|
+
var _a;
|
|
2049
|
+
return (_a = get()) == null ? void 0 : _a.observe(target, { box: "border-box" });
|
|
2050
|
+
},
|
|
2051
|
+
unobserve: (target) => {
|
|
2052
|
+
var _a;
|
|
2053
|
+
return (_a = get()) == null ? void 0 : _a.unobserve(target);
|
|
2054
|
+
}
|
|
2055
|
+
};
|
|
2056
|
+
})();
|
|
2057
|
+
this.range = null;
|
|
2058
|
+
this.setOptions = (opts2) => {
|
|
2059
|
+
Object.entries(opts2).forEach(([key, value]) => {
|
|
2060
|
+
if (typeof value === "undefined") delete opts2[key];
|
|
2061
|
+
});
|
|
2062
|
+
this.options = {
|
|
2063
|
+
debug: false,
|
|
2064
|
+
initialOffset: 0,
|
|
2065
|
+
overscan: 1,
|
|
2066
|
+
paddingStart: 0,
|
|
2067
|
+
paddingEnd: 0,
|
|
2068
|
+
scrollPaddingStart: 0,
|
|
2069
|
+
scrollPaddingEnd: 0,
|
|
2070
|
+
horizontal: false,
|
|
2071
|
+
getItemKey: defaultKeyExtractor,
|
|
2072
|
+
rangeExtractor: defaultRangeExtractor,
|
|
2073
|
+
onChange: () => {
|
|
2074
|
+
},
|
|
2075
|
+
measureElement,
|
|
2076
|
+
initialRect: { width: 0, height: 0 },
|
|
2077
|
+
scrollMargin: 0,
|
|
2078
|
+
gap: 0,
|
|
2079
|
+
indexAttribute: "data-index",
|
|
2080
|
+
initialMeasurementsCache: [],
|
|
2081
|
+
lanes: 1,
|
|
2082
|
+
isScrollingResetDelay: 150,
|
|
2083
|
+
enabled: true,
|
|
2084
|
+
isRtl: false,
|
|
2085
|
+
useScrollendEvent: false,
|
|
2086
|
+
useAnimationFrameWithResizeObserver: false,
|
|
2087
|
+
...opts2
|
|
2088
|
+
};
|
|
2089
|
+
};
|
|
2090
|
+
this.notify = (sync) => {
|
|
2091
|
+
var _a, _b;
|
|
2092
|
+
(_b = (_a = this.options).onChange) == null ? void 0 : _b.call(_a, this, sync);
|
|
2093
|
+
};
|
|
2094
|
+
this.maybeNotify = memo(
|
|
2095
|
+
() => {
|
|
2096
|
+
this.calculateRange();
|
|
2097
|
+
return [
|
|
2098
|
+
this.isScrolling,
|
|
2099
|
+
this.range ? this.range.startIndex : null,
|
|
2100
|
+
this.range ? this.range.endIndex : null
|
|
2101
|
+
];
|
|
2102
|
+
},
|
|
2103
|
+
(isScrolling) => {
|
|
2104
|
+
this.notify(isScrolling);
|
|
2105
|
+
},
|
|
2106
|
+
{
|
|
2107
|
+
key: false,
|
|
2108
|
+
debug: () => this.options.debug,
|
|
2109
|
+
initialDeps: [
|
|
2110
|
+
this.isScrolling,
|
|
2111
|
+
this.range ? this.range.startIndex : null,
|
|
2112
|
+
this.range ? this.range.endIndex : null
|
|
2113
|
+
]
|
|
2114
|
+
}
|
|
2115
|
+
);
|
|
2116
|
+
this.cleanup = () => {
|
|
2117
|
+
this.unsubs.filter(Boolean).forEach((d) => d());
|
|
2118
|
+
this.unsubs = [];
|
|
2119
|
+
this.observer.disconnect();
|
|
2120
|
+
this.scrollElement = null;
|
|
2121
|
+
this.targetWindow = null;
|
|
2122
|
+
};
|
|
2123
|
+
this._didMount = () => {
|
|
2124
|
+
return () => {
|
|
2125
|
+
this.cleanup();
|
|
2126
|
+
};
|
|
2127
|
+
};
|
|
2128
|
+
this._willUpdate = () => {
|
|
2129
|
+
var _a;
|
|
2130
|
+
const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
|
|
2131
|
+
if (this.scrollElement !== scrollElement) {
|
|
2132
|
+
this.cleanup();
|
|
2133
|
+
if (!scrollElement) {
|
|
2134
|
+
this.maybeNotify();
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
this.scrollElement = scrollElement;
|
|
2138
|
+
if (this.scrollElement && "ownerDocument" in this.scrollElement) {
|
|
2139
|
+
this.targetWindow = this.scrollElement.ownerDocument.defaultView;
|
|
2140
|
+
} else {
|
|
2141
|
+
this.targetWindow = ((_a = this.scrollElement) == null ? void 0 : _a.window) ?? null;
|
|
2142
|
+
}
|
|
2143
|
+
this.elementsCache.forEach((cached) => {
|
|
2144
|
+
this.observer.observe(cached);
|
|
2145
|
+
});
|
|
2146
|
+
this._scrollToOffset(this.getScrollOffset(), {
|
|
2147
|
+
adjustments: void 0,
|
|
2148
|
+
behavior: void 0
|
|
2149
|
+
});
|
|
2150
|
+
this.unsubs.push(
|
|
2151
|
+
this.options.observeElementRect(this, (rect) => {
|
|
2152
|
+
this.scrollRect = rect;
|
|
2153
|
+
this.maybeNotify();
|
|
2154
|
+
})
|
|
2155
|
+
);
|
|
2156
|
+
this.unsubs.push(
|
|
2157
|
+
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
2158
|
+
this.scrollAdjustments = 0;
|
|
2159
|
+
this.scrollDirection = isScrolling ? this.getScrollOffset() < offset ? "forward" : "backward" : null;
|
|
2160
|
+
this.scrollOffset = offset;
|
|
2161
|
+
this.isScrolling = isScrolling;
|
|
2162
|
+
this.maybeNotify();
|
|
2163
|
+
})
|
|
2164
|
+
);
|
|
2165
|
+
}
|
|
2166
|
+
};
|
|
2167
|
+
this.getSize = () => {
|
|
2168
|
+
if (!this.options.enabled) {
|
|
2169
|
+
this.scrollRect = null;
|
|
2170
|
+
return 0;
|
|
2171
|
+
}
|
|
2172
|
+
this.scrollRect = this.scrollRect ?? this.options.initialRect;
|
|
2173
|
+
return this.scrollRect[this.options.horizontal ? "width" : "height"];
|
|
2174
|
+
};
|
|
2175
|
+
this.getScrollOffset = () => {
|
|
2176
|
+
if (!this.options.enabled) {
|
|
2177
|
+
this.scrollOffset = null;
|
|
2178
|
+
return 0;
|
|
2179
|
+
}
|
|
2180
|
+
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
|
|
2181
|
+
return this.scrollOffset;
|
|
2182
|
+
};
|
|
2183
|
+
this.getFurthestMeasurement = (measurements, index) => {
|
|
2184
|
+
const furthestMeasurementsFound = /* @__PURE__ */ new Map();
|
|
2185
|
+
const furthestMeasurements = /* @__PURE__ */ new Map();
|
|
2186
|
+
for (let m = index - 1; m >= 0; m--) {
|
|
2187
|
+
const measurement = measurements[m];
|
|
2188
|
+
if (furthestMeasurementsFound.has(measurement.lane)) {
|
|
2189
|
+
continue;
|
|
2190
|
+
}
|
|
2191
|
+
const previousFurthestMeasurement = furthestMeasurements.get(
|
|
2192
|
+
measurement.lane
|
|
2193
|
+
);
|
|
2194
|
+
if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
|
|
2195
|
+
furthestMeasurements.set(measurement.lane, measurement);
|
|
2196
|
+
} else if (measurement.end < previousFurthestMeasurement.end) {
|
|
2197
|
+
furthestMeasurementsFound.set(measurement.lane, true);
|
|
2198
|
+
}
|
|
2199
|
+
if (furthestMeasurementsFound.size === this.options.lanes) {
|
|
2200
|
+
break;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
return furthestMeasurements.size === this.options.lanes ? Array.from(furthestMeasurements.values()).sort((a, b) => {
|
|
2204
|
+
if (a.end === b.end) {
|
|
2205
|
+
return a.index - b.index;
|
|
2206
|
+
}
|
|
2207
|
+
return a.end - b.end;
|
|
2208
|
+
})[0] : void 0;
|
|
2209
|
+
};
|
|
2210
|
+
this.getMeasurementOptions = memo(
|
|
2211
|
+
() => [
|
|
2212
|
+
this.options.count,
|
|
2213
|
+
this.options.paddingStart,
|
|
2214
|
+
this.options.scrollMargin,
|
|
2215
|
+
this.options.getItemKey,
|
|
2216
|
+
this.options.enabled
|
|
2217
|
+
],
|
|
2218
|
+
(count, paddingStart, scrollMargin, getItemKey, enabled) => {
|
|
2219
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
2220
|
+
return {
|
|
2221
|
+
count,
|
|
2222
|
+
paddingStart,
|
|
2223
|
+
scrollMargin,
|
|
2224
|
+
getItemKey,
|
|
2225
|
+
enabled
|
|
2226
|
+
};
|
|
2227
|
+
},
|
|
2228
|
+
{
|
|
2229
|
+
key: false
|
|
2230
|
+
}
|
|
2231
|
+
);
|
|
2232
|
+
this.getMeasurements = memo(
|
|
2233
|
+
() => [this.getMeasurementOptions(), this.itemSizeCache],
|
|
2234
|
+
({ count, paddingStart, scrollMargin, getItemKey, enabled }, itemSizeCache) => {
|
|
2235
|
+
if (!enabled) {
|
|
2236
|
+
this.measurementsCache = [];
|
|
2237
|
+
this.itemSizeCache.clear();
|
|
2238
|
+
return [];
|
|
2239
|
+
}
|
|
2240
|
+
if (this.measurementsCache.length === 0) {
|
|
2241
|
+
this.measurementsCache = this.options.initialMeasurementsCache;
|
|
2242
|
+
this.measurementsCache.forEach((item) => {
|
|
2243
|
+
this.itemSizeCache.set(item.key, item.size);
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
const min = this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
|
|
2247
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
2248
|
+
const measurements = this.measurementsCache.slice(0, min);
|
|
2249
|
+
for (let i = min; i < count; i++) {
|
|
2250
|
+
const key = getItemKey(i);
|
|
2251
|
+
const furthestMeasurement = this.options.lanes === 1 ? measurements[i - 1] : this.getFurthestMeasurement(measurements, i);
|
|
2252
|
+
const start = furthestMeasurement ? furthestMeasurement.end + this.options.gap : paddingStart + scrollMargin;
|
|
2253
|
+
const measuredSize = itemSizeCache.get(key);
|
|
2254
|
+
const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
|
|
2255
|
+
const end = start + size;
|
|
2256
|
+
const lane = furthestMeasurement ? furthestMeasurement.lane : i % this.options.lanes;
|
|
2257
|
+
measurements[i] = {
|
|
2258
|
+
index: i,
|
|
2259
|
+
start,
|
|
2260
|
+
size,
|
|
2261
|
+
end,
|
|
2262
|
+
key,
|
|
2263
|
+
lane
|
|
2264
|
+
};
|
|
2265
|
+
}
|
|
2266
|
+
this.measurementsCache = measurements;
|
|
2267
|
+
return measurements;
|
|
2268
|
+
},
|
|
2269
|
+
{
|
|
2270
|
+
key: false,
|
|
2271
|
+
debug: () => this.options.debug
|
|
2272
|
+
}
|
|
2273
|
+
);
|
|
2274
|
+
this.calculateRange = memo(
|
|
2275
|
+
() => [
|
|
2276
|
+
this.getMeasurements(),
|
|
2277
|
+
this.getSize(),
|
|
2278
|
+
this.getScrollOffset(),
|
|
2279
|
+
this.options.lanes
|
|
2280
|
+
],
|
|
2281
|
+
(measurements, outerSize, scrollOffset, lanes) => {
|
|
2282
|
+
return this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
|
|
2283
|
+
measurements,
|
|
2284
|
+
outerSize,
|
|
2285
|
+
scrollOffset,
|
|
2286
|
+
lanes
|
|
2287
|
+
}) : null;
|
|
2288
|
+
},
|
|
2289
|
+
{
|
|
2290
|
+
key: false,
|
|
2291
|
+
debug: () => this.options.debug
|
|
2292
|
+
}
|
|
2293
|
+
);
|
|
2294
|
+
this.getVirtualIndexes = memo(
|
|
2295
|
+
() => {
|
|
2296
|
+
let startIndex = null;
|
|
2297
|
+
let endIndex = null;
|
|
2298
|
+
const range = this.calculateRange();
|
|
2299
|
+
if (range) {
|
|
2300
|
+
startIndex = range.startIndex;
|
|
2301
|
+
endIndex = range.endIndex;
|
|
2302
|
+
}
|
|
2303
|
+
this.maybeNotify.updateDeps([this.isScrolling, startIndex, endIndex]);
|
|
2304
|
+
return [
|
|
2305
|
+
this.options.rangeExtractor,
|
|
2306
|
+
this.options.overscan,
|
|
2307
|
+
this.options.count,
|
|
2308
|
+
startIndex,
|
|
2309
|
+
endIndex
|
|
2310
|
+
];
|
|
2311
|
+
},
|
|
2312
|
+
(rangeExtractor, overscan, count, startIndex, endIndex) => {
|
|
2313
|
+
return startIndex === null || endIndex === null ? [] : rangeExtractor({
|
|
2314
|
+
startIndex,
|
|
2315
|
+
endIndex,
|
|
2316
|
+
overscan,
|
|
2317
|
+
count
|
|
2318
|
+
});
|
|
2319
|
+
},
|
|
2320
|
+
{
|
|
2321
|
+
key: false,
|
|
2322
|
+
debug: () => this.options.debug
|
|
2323
|
+
}
|
|
2324
|
+
);
|
|
2325
|
+
this.indexFromElement = (node) => {
|
|
2326
|
+
const attributeName = this.options.indexAttribute;
|
|
2327
|
+
const indexStr = node.getAttribute(attributeName);
|
|
2328
|
+
if (!indexStr) {
|
|
2329
|
+
console.warn(
|
|
2330
|
+
`Missing attribute name '${attributeName}={index}' on measured element.`
|
|
2331
|
+
);
|
|
2332
|
+
return -1;
|
|
2333
|
+
}
|
|
2334
|
+
return parseInt(indexStr, 10);
|
|
2335
|
+
};
|
|
2336
|
+
this._measureElement = (node, entry) => {
|
|
2337
|
+
const index = this.indexFromElement(node);
|
|
2338
|
+
const item = this.measurementsCache[index];
|
|
2339
|
+
if (!item) {
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
2342
|
+
const key = item.key;
|
|
2343
|
+
const prevNode = this.elementsCache.get(key);
|
|
2344
|
+
if (prevNode !== node) {
|
|
2345
|
+
if (prevNode) {
|
|
2346
|
+
this.observer.unobserve(prevNode);
|
|
2347
|
+
}
|
|
2348
|
+
this.observer.observe(node);
|
|
2349
|
+
this.elementsCache.set(key, node);
|
|
2350
|
+
}
|
|
2351
|
+
if (node.isConnected) {
|
|
2352
|
+
this.resizeItem(index, this.options.measureElement(node, entry, this));
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
this.resizeItem = (index, size) => {
|
|
2356
|
+
const item = this.measurementsCache[index];
|
|
2357
|
+
if (!item) {
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
const itemSize = this.itemSizeCache.get(item.key) ?? item.size;
|
|
2361
|
+
const delta = size - itemSize;
|
|
2362
|
+
if (delta !== 0) {
|
|
2363
|
+
if (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(item, delta, this) : item.start < this.getScrollOffset() + this.scrollAdjustments) {
|
|
2364
|
+
this._scrollToOffset(this.getScrollOffset(), {
|
|
2365
|
+
adjustments: this.scrollAdjustments += delta,
|
|
2366
|
+
behavior: void 0
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
this.pendingMeasuredCacheIndexes.push(item.index);
|
|
2370
|
+
this.itemSizeCache = new Map(this.itemSizeCache.set(item.key, size));
|
|
2371
|
+
this.notify(false);
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
this.measureElement = (node) => {
|
|
2375
|
+
if (!node) {
|
|
2376
|
+
this.elementsCache.forEach((cached, key) => {
|
|
2377
|
+
if (!cached.isConnected) {
|
|
2378
|
+
this.observer.unobserve(cached);
|
|
2379
|
+
this.elementsCache.delete(key);
|
|
2380
|
+
}
|
|
2381
|
+
});
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2384
|
+
this._measureElement(node, void 0);
|
|
2385
|
+
};
|
|
2386
|
+
this.getVirtualItems = memo(
|
|
2387
|
+
() => [this.getVirtualIndexes(), this.getMeasurements()],
|
|
2388
|
+
(indexes, measurements) => {
|
|
2389
|
+
const virtualItems = [];
|
|
2390
|
+
for (let k = 0, len = indexes.length; k < len; k++) {
|
|
2391
|
+
const i = indexes[k];
|
|
2392
|
+
const measurement = measurements[i];
|
|
2393
|
+
virtualItems.push(measurement);
|
|
2394
|
+
}
|
|
2395
|
+
return virtualItems;
|
|
2396
|
+
},
|
|
2397
|
+
{
|
|
2398
|
+
key: false,
|
|
2399
|
+
debug: () => this.options.debug
|
|
2400
|
+
}
|
|
2401
|
+
);
|
|
2402
|
+
this.getVirtualItemForOffset = (offset) => {
|
|
2403
|
+
const measurements = this.getMeasurements();
|
|
2404
|
+
if (measurements.length === 0) {
|
|
2405
|
+
return void 0;
|
|
2406
|
+
}
|
|
2407
|
+
return notUndefined(
|
|
2408
|
+
measurements[findNearestBinarySearch(
|
|
2409
|
+
0,
|
|
2410
|
+
measurements.length - 1,
|
|
2411
|
+
(index) => notUndefined(measurements[index]).start,
|
|
2412
|
+
offset
|
|
2413
|
+
)]
|
|
2414
|
+
);
|
|
2415
|
+
};
|
|
2416
|
+
this.getOffsetForAlignment = (toOffset, align, itemSize = 0) => {
|
|
2417
|
+
const size = this.getSize();
|
|
2418
|
+
const scrollOffset = this.getScrollOffset();
|
|
2419
|
+
if (align === "auto") {
|
|
2420
|
+
align = toOffset >= scrollOffset + size ? "end" : "start";
|
|
2421
|
+
}
|
|
2422
|
+
if (align === "center") {
|
|
2423
|
+
toOffset += (itemSize - size) / 2;
|
|
2424
|
+
} else if (align === "end") {
|
|
2425
|
+
toOffset -= size;
|
|
2426
|
+
}
|
|
2427
|
+
const scrollSizeProp = this.options.horizontal ? "scrollWidth" : "scrollHeight";
|
|
2428
|
+
const scrollSize = this.scrollElement ? "document" in this.scrollElement ? this.scrollElement.document.documentElement[scrollSizeProp] : this.scrollElement[scrollSizeProp] : 0;
|
|
2429
|
+
const maxOffset = scrollSize - size;
|
|
2430
|
+
return Math.max(Math.min(maxOffset, toOffset), 0);
|
|
2431
|
+
};
|
|
2432
|
+
this.getOffsetForIndex = (index, align = "auto") => {
|
|
2433
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
2434
|
+
const item = this.measurementsCache[index];
|
|
2435
|
+
if (!item) {
|
|
2436
|
+
return void 0;
|
|
2437
|
+
}
|
|
2438
|
+
const size = this.getSize();
|
|
2439
|
+
const scrollOffset = this.getScrollOffset();
|
|
2440
|
+
if (align === "auto") {
|
|
2441
|
+
if (item.end >= scrollOffset + size - this.options.scrollPaddingEnd) {
|
|
2442
|
+
align = "end";
|
|
2443
|
+
} else if (item.start <= scrollOffset + this.options.scrollPaddingStart) {
|
|
2444
|
+
align = "start";
|
|
2445
|
+
} else {
|
|
2446
|
+
return [scrollOffset, align];
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
|
|
2450
|
+
return [
|
|
2451
|
+
this.getOffsetForAlignment(toOffset, align, item.size),
|
|
2452
|
+
align
|
|
2453
|
+
];
|
|
2454
|
+
};
|
|
2455
|
+
this.isDynamicMode = () => this.elementsCache.size > 0;
|
|
2456
|
+
this.cancelScrollToIndex = () => {
|
|
2457
|
+
if (this.scrollToIndexTimeoutId !== null && this.targetWindow) {
|
|
2458
|
+
this.targetWindow.clearTimeout(this.scrollToIndexTimeoutId);
|
|
2459
|
+
this.scrollToIndexTimeoutId = null;
|
|
2460
|
+
}
|
|
2461
|
+
};
|
|
2462
|
+
this.scrollToOffset = (toOffset, { align = "start", behavior } = {}) => {
|
|
2463
|
+
this.cancelScrollToIndex();
|
|
2464
|
+
if (behavior === "smooth" && this.isDynamicMode()) {
|
|
2465
|
+
console.warn(
|
|
2466
|
+
"The `smooth` scroll behavior is not fully supported with dynamic size."
|
|
2467
|
+
);
|
|
2468
|
+
}
|
|
2469
|
+
this._scrollToOffset(this.getOffsetForAlignment(toOffset, align), {
|
|
2470
|
+
adjustments: void 0,
|
|
2471
|
+
behavior
|
|
2472
|
+
});
|
|
2473
|
+
};
|
|
2474
|
+
this.scrollToIndex = (index, { align: initialAlign = "auto", behavior } = {}) => {
|
|
2475
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
2476
|
+
this.cancelScrollToIndex();
|
|
2477
|
+
if (behavior === "smooth" && this.isDynamicMode()) {
|
|
2478
|
+
console.warn(
|
|
2479
|
+
"The `smooth` scroll behavior is not fully supported with dynamic size."
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
const offsetAndAlign = this.getOffsetForIndex(index, initialAlign);
|
|
2483
|
+
if (!offsetAndAlign) return;
|
|
2484
|
+
const [offset, align] = offsetAndAlign;
|
|
2485
|
+
this._scrollToOffset(offset, { adjustments: void 0, behavior });
|
|
2486
|
+
if (behavior !== "smooth" && this.isDynamicMode() && this.targetWindow) {
|
|
2487
|
+
this.scrollToIndexTimeoutId = this.targetWindow.setTimeout(() => {
|
|
2488
|
+
this.scrollToIndexTimeoutId = null;
|
|
2489
|
+
const elementInDOM = this.elementsCache.has(
|
|
2490
|
+
this.options.getItemKey(index)
|
|
2491
|
+
);
|
|
2492
|
+
if (elementInDOM) {
|
|
2493
|
+
const [latestOffset] = notUndefined(
|
|
2494
|
+
this.getOffsetForIndex(index, align)
|
|
2495
|
+
);
|
|
2496
|
+
if (!approxEqual(latestOffset, this.getScrollOffset())) {
|
|
2497
|
+
this.scrollToIndex(index, { align, behavior });
|
|
2498
|
+
}
|
|
2499
|
+
} else {
|
|
2500
|
+
this.scrollToIndex(index, { align, behavior });
|
|
2501
|
+
}
|
|
2502
|
+
});
|
|
2503
|
+
}
|
|
2504
|
+
};
|
|
2505
|
+
this.scrollBy = (delta, { behavior } = {}) => {
|
|
2506
|
+
this.cancelScrollToIndex();
|
|
2507
|
+
if (behavior === "smooth" && this.isDynamicMode()) {
|
|
2508
|
+
console.warn(
|
|
2509
|
+
"The `smooth` scroll behavior is not fully supported with dynamic size."
|
|
2510
|
+
);
|
|
2511
|
+
}
|
|
2512
|
+
this._scrollToOffset(this.getScrollOffset() + delta, {
|
|
2513
|
+
adjustments: void 0,
|
|
2514
|
+
behavior
|
|
2515
|
+
});
|
|
2516
|
+
};
|
|
2517
|
+
this.getTotalSize = () => {
|
|
2518
|
+
var _a;
|
|
2519
|
+
const measurements = this.getMeasurements();
|
|
2520
|
+
let end;
|
|
2521
|
+
if (measurements.length === 0) {
|
|
2522
|
+
end = this.options.paddingStart;
|
|
2523
|
+
} else if (this.options.lanes === 1) {
|
|
2524
|
+
end = ((_a = measurements[measurements.length - 1]) == null ? void 0 : _a.end) ?? 0;
|
|
2525
|
+
} else {
|
|
2526
|
+
const endByLane = Array(this.options.lanes).fill(null);
|
|
2527
|
+
let endIndex = measurements.length - 1;
|
|
2528
|
+
while (endIndex > 0 && endByLane.some((val) => val === null)) {
|
|
2529
|
+
const item = measurements[endIndex];
|
|
2530
|
+
if (endByLane[item.lane] === null) {
|
|
2531
|
+
endByLane[item.lane] = item.end;
|
|
2532
|
+
}
|
|
2533
|
+
endIndex--;
|
|
2534
|
+
}
|
|
2535
|
+
end = Math.max(...endByLane.filter((val) => val !== null));
|
|
2536
|
+
}
|
|
2537
|
+
return Math.max(
|
|
2538
|
+
end - this.options.scrollMargin + this.options.paddingEnd,
|
|
2539
|
+
0
|
|
2540
|
+
);
|
|
2541
|
+
};
|
|
2542
|
+
this._scrollToOffset = (offset, {
|
|
2543
|
+
adjustments,
|
|
2544
|
+
behavior
|
|
2545
|
+
}) => {
|
|
2546
|
+
this.options.scrollToFn(offset, { behavior, adjustments }, this);
|
|
2547
|
+
};
|
|
2548
|
+
this.measure = () => {
|
|
2549
|
+
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
2550
|
+
this.notify(false);
|
|
2551
|
+
};
|
|
2552
|
+
this.setOptions(opts);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
2556
|
+
while (low <= high) {
|
|
2557
|
+
const middle = (low + high) / 2 | 0;
|
|
2558
|
+
const currentValue = getCurrentValue(middle);
|
|
2559
|
+
if (currentValue < value) {
|
|
2560
|
+
low = middle + 1;
|
|
2561
|
+
} else if (currentValue > value) {
|
|
2562
|
+
high = middle - 1;
|
|
2563
|
+
} else {
|
|
2564
|
+
return middle;
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
if (low > 0) {
|
|
2568
|
+
return low - 1;
|
|
2569
|
+
} else {
|
|
2570
|
+
return 0;
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2573
|
+
function calculateRange({
|
|
2574
|
+
measurements,
|
|
2575
|
+
outerSize,
|
|
2576
|
+
scrollOffset,
|
|
2577
|
+
lanes
|
|
2578
|
+
}) {
|
|
2579
|
+
const lastIndex = measurements.length - 1;
|
|
2580
|
+
const getOffset = (index) => measurements[index].start;
|
|
2581
|
+
if (measurements.length <= lanes) {
|
|
2582
|
+
return {
|
|
2583
|
+
startIndex: 0,
|
|
2584
|
+
endIndex: lastIndex
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
let startIndex = findNearestBinarySearch(
|
|
2588
|
+
0,
|
|
2589
|
+
lastIndex,
|
|
2590
|
+
getOffset,
|
|
2591
|
+
scrollOffset
|
|
2592
|
+
);
|
|
2593
|
+
let endIndex = startIndex;
|
|
2594
|
+
if (lanes === 1) {
|
|
2595
|
+
while (endIndex < lastIndex && measurements[endIndex].end < scrollOffset + outerSize) {
|
|
2596
|
+
endIndex++;
|
|
2597
|
+
}
|
|
2598
|
+
} else if (lanes > 1) {
|
|
2599
|
+
const endPerLane = Array(lanes).fill(0);
|
|
2600
|
+
while (endIndex < lastIndex && endPerLane.some((pos) => pos < scrollOffset + outerSize)) {
|
|
2601
|
+
const item = measurements[endIndex];
|
|
2602
|
+
endPerLane[item.lane] = item.end;
|
|
2603
|
+
endIndex++;
|
|
2604
|
+
}
|
|
2605
|
+
const startPerLane = Array(lanes).fill(scrollOffset + outerSize);
|
|
2606
|
+
while (startIndex > 0 && startPerLane.some((pos) => pos >= scrollOffset)) {
|
|
2607
|
+
const item = measurements[startIndex];
|
|
2608
|
+
startPerLane[item.lane] = item.start;
|
|
2609
|
+
startIndex--;
|
|
2610
|
+
}
|
|
2611
|
+
startIndex = Math.max(0, startIndex - startIndex % lanes);
|
|
2612
|
+
endIndex = Math.min(lastIndex, endIndex + (lanes - 1 - endIndex % lanes));
|
|
2613
|
+
}
|
|
2614
|
+
return { startIndex, endIndex };
|
|
2615
|
+
}
|
|
2616
|
+
const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
|
2617
|
+
function useVirtualizerBase(options) {
|
|
2618
|
+
const rerender = React.useReducer(() => ({}), {})[1];
|
|
2619
|
+
const resolvedOptions = {
|
|
2620
|
+
...options,
|
|
2621
|
+
onChange: (instance2, sync) => {
|
|
2622
|
+
var _a;
|
|
2623
|
+
if (sync) {
|
|
2624
|
+
flushSync(rerender);
|
|
2625
|
+
} else {
|
|
2626
|
+
rerender();
|
|
2627
|
+
}
|
|
2628
|
+
(_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
const [instance] = React.useState(
|
|
2632
|
+
() => new Virtualizer(resolvedOptions)
|
|
2633
|
+
);
|
|
2634
|
+
instance.setOptions(resolvedOptions);
|
|
2635
|
+
useIsomorphicLayoutEffect(() => {
|
|
2636
|
+
return instance._didMount();
|
|
2637
|
+
}, []);
|
|
2638
|
+
useIsomorphicLayoutEffect(() => {
|
|
2639
|
+
return instance._willUpdate();
|
|
2640
|
+
});
|
|
2641
|
+
return instance;
|
|
2642
|
+
}
|
|
2643
|
+
function useVirtualizer(options) {
|
|
2644
|
+
return useVirtualizerBase({
|
|
2645
|
+
observeElementRect,
|
|
2646
|
+
observeElementOffset,
|
|
2647
|
+
scrollToFn: elementScroll,
|
|
2648
|
+
...options
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
function Address(props) {
|
|
2652
|
+
const { address, chainId } = props;
|
|
2653
|
+
const [, copy] = useCopyToClipboard();
|
|
2654
|
+
if (!address)
|
|
2655
|
+
return null;
|
|
2656
|
+
const shortenedAddress = formatEthAddress(address);
|
|
2657
|
+
function handleCopy(text) {
|
|
2658
|
+
return () => {
|
|
2659
|
+
copy(text).catch((error) => {
|
|
2660
|
+
console.error("Failed to copy!", error);
|
|
2661
|
+
});
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
const tooltipContent = jsxs("button", { className: "flex items-center gap-1", onClick: handleCopy(address), children: [address, jsx(Icon, { className: "inline-block text-gray-600", name: "FilesEarmark", size: 16 })] });
|
|
2665
|
+
return jsx(Tooltip, { content: tooltipContent, children: jsxs("span", { className: "flex w-fit cursor-pointer items-center gap-1 rounded-lg bg-gray-100 p-1 text-xs text-slate-100", children: [jsx(ENSAvatar, { address, chainId }), shortenedAddress] }) });
|
|
2666
|
+
}
|
|
2667
|
+
function Errors(props) {
|
|
2668
|
+
const { errors } = props;
|
|
2669
|
+
const hasErrors = !!(errors == null ? void 0 : errors.length);
|
|
2670
|
+
const color = hasErrors ? "text-red-800" : "text-green-700";
|
|
2671
|
+
const icon = hasErrors ? jsx(Icon, { name: "Exclamation", size: 16 }) : jsx(Icon, { name: "Check", size: 16 });
|
|
2672
|
+
const text = hasErrors ? `Error: ${errors[0]}` : "No errors";
|
|
2673
|
+
const content = jsxs("span", { className: twMerge("flex w-fit items-center rounded-lg border border-gray-200 px-2 py-1 text-xs", color, hasErrors && "cursor-pointer"), children: [icon, jsx("span", { className: twMerge("inline-block max-w-36 truncate"), children: text })] });
|
|
2674
|
+
const tooltipContent = errors == null ? void 0 : errors.map((message2, index) => jsxs("p", { className: "text-red-800", children: ["Error: ", message2] }, index));
|
|
2675
|
+
if (hasErrors)
|
|
2676
|
+
return jsx(Tooltip, { content: tooltipContent, children: content });
|
|
2677
|
+
return content;
|
|
2678
|
+
}
|
|
2679
|
+
function Operation(props) {
|
|
2680
|
+
const { operationType, operationInput } = props;
|
|
2681
|
+
const tooltipContent = jsx("code", { children: jsx("pre", { children: JSON.stringify(operationInput, null, 2) }) });
|
|
2682
|
+
return jsx(Tooltip, { content: tooltipContent, children: jsxs("span", { className: "flex cursor-pointer items-center gap-2 text-xs", children: [operationType, jsx(Icon, { className: "text-gray-300", name: "Braces", size: 16 })] }) });
|
|
2683
|
+
}
|
|
2684
|
+
function RevisionNumber(props) {
|
|
2685
|
+
const { operationIndex, eventId, stateHash } = props;
|
|
2686
|
+
const [, copy] = useCopyToClipboard();
|
|
2687
|
+
const revisionNumber = operationIndex + 1;
|
|
2688
|
+
const tooltipContent = jsxs("button", { className: "flex items-center gap-1", onClick: handleCopy(stateHash), children: ["Revision ", revisionNumber, " - Event ID: ", eventId, " - State Hash: ", stateHash, jsx(Icon, { className: "inline-block text-gray-600", name: "FilesEarmark", size: 16 })] });
|
|
2689
|
+
function handleCopy(text) {
|
|
2690
|
+
return () => {
|
|
2691
|
+
copy(text).catch((error) => {
|
|
2692
|
+
console.error("Failed to copy!", error);
|
|
2693
|
+
});
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2696
|
+
return jsx(Tooltip, { content: tooltipContent, children: jsxs("span", { className: "flex cursor-pointer items-center gap-2 text-xs text-gray-600", children: ["Revision ", revisionNumber, ".", jsx("a", { children: jsx(Icon, { className: "cursor-pointer text-slate-100", name: "Ellipsis", size: 14 }) })] }) });
|
|
2697
|
+
}
|
|
2698
|
+
function Signature(props) {
|
|
2699
|
+
const { signatures } = props;
|
|
2700
|
+
if (!(signatures == null ? void 0 : signatures.length))
|
|
2701
|
+
return null;
|
|
2702
|
+
const tooltipContent = jsxs("div", { className: "text-xs text-slate-300", children: [jsx("h3", { className: "mb-2", children: "Signature details:" }), signatures.map((signature, index) => jsxs("div", { className: "mb-2 last:mb-0", children: [jsxs("h4", { children: ["Signature #", index + 1, " -", " ", signature.isVerified ? "verified" : "unverified"] }), jsx("code", { children: jsx("pre", { children: JSON.stringify(signature, null, 2) }) })] }, signature.hash))] });
|
|
2703
|
+
return jsx(Tooltip, { content: tooltipContent, children: jsxs("span", { className: "flex w-fit cursor-pointer items-center gap-1 rounded-lg border border-gray-200 px-2 py-1", children: [jsx(VerificationStatus, { signatures }), " ", jsx(Icon, { className: "text-gray-300", name: "InfoSquare", size: 16 })] }) });
|
|
2704
|
+
}
|
|
2705
|
+
function VerificationStatus(props) {
|
|
2706
|
+
const { signatures } = props;
|
|
2707
|
+
if (!(signatures == null ? void 0 : signatures.length))
|
|
2708
|
+
return null;
|
|
2709
|
+
const signatureCount = signatures.length;
|
|
2710
|
+
const verifiedSignaturesCount = signatures.filter((signature) => signature.isVerified).length;
|
|
2711
|
+
const signatureText = signatureCount === 1 ? "signature" : "signatures";
|
|
2712
|
+
const verificationStatusText = `${verifiedSignaturesCount}/${signatureCount} ${signatureText} verified`;
|
|
2713
|
+
const color = verifiedSignaturesCount === 0 ? "text-red-800" : verifiedSignaturesCount === signatureCount ? "text-green-700" : "text-orange-700";
|
|
2714
|
+
return jsx("span", { className: `text-xs ${color}`, children: verificationStatusText });
|
|
2715
|
+
}
|
|
2716
|
+
function Timestamp(props) {
|
|
2717
|
+
const { timestamp } = props;
|
|
2718
|
+
const timestampNumber = typeof timestamp === "string" && !timestamp.includes("-") ? parseInt(timestamp) : timestamp;
|
|
2719
|
+
const date = new Date(timestampNumber);
|
|
2720
|
+
const shortDate = format(date, "HH:mm 'UTC'");
|
|
2721
|
+
const longDate = format(date, "eee, dd MMM yyyy HH:mm:ss 'UTC'");
|
|
2722
|
+
const tooltipContent = jsx("div", { children: longDate });
|
|
2723
|
+
return jsx(Tooltip, { content: tooltipContent, children: jsxs("span", { className: "cursor-pointer text-xs", children: ["committed at ", shortDate] }) });
|
|
2724
|
+
}
|
|
2725
|
+
function _Revision(props) {
|
|
2726
|
+
return jsxs("article", { className: "flex items-center justify-between rounded-xl border border-gray-200 bg-white px-4 py-2", children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx(RevisionNumber, { ...props }), jsx(Operation, { ...props }), jsx(Address, { ...props }), jsx(Timestamp, { ...props })] }), jsxs("div", { className: "flex items-center gap-1", children: [jsx(Signature, { ...props }), jsx(Errors, { ...props })] })] });
|
|
2727
|
+
}
|
|
2728
|
+
const Revision = memo$1(_Revision);
|
|
2729
|
+
function Skip(props) {
|
|
2730
|
+
const { operationIndex, skipCount } = props;
|
|
2731
|
+
const revisionNumber = operationIndex;
|
|
2732
|
+
const skippedRevisions = skipCount === 1 ? `${revisionNumber}` : `${revisionNumber} - ${revisionNumber + 1 - skipCount}`;
|
|
2733
|
+
return jsxs("article", { className: "grid grid-cols-[1fr,auto,1fr] items-center py-2", children: [jsx("div", { className: "h-px rounded-full bg-slate-100" }), jsxs("div", { className: "mx-3 text-xs text-slate-100", children: ["[Skipped Revision ", skippedRevisions, "]"] }), jsx("div", { className: "h-px rounded-full bg-slate-100" })] });
|
|
2734
|
+
}
|
|
2735
|
+
function makeRows(operations) {
|
|
2736
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2737
|
+
const revisionsAndSkips = [];
|
|
2738
|
+
const seenDays = /* @__PURE__ */ new Set();
|
|
2739
|
+
for (const operation of operations) {
|
|
2740
|
+
const day = operation.timestamp.split("T")[0];
|
|
2741
|
+
if (!seenDays.has(day)) {
|
|
2742
|
+
seenDays.add(day);
|
|
2743
|
+
revisionsAndSkips.push({
|
|
2744
|
+
type: "day",
|
|
2745
|
+
height: 32,
|
|
2746
|
+
timestamp: day
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
revisionsAndSkips.push({
|
|
2750
|
+
type: "revision",
|
|
2751
|
+
height: 46,
|
|
2752
|
+
operationIndex: operation.index,
|
|
2753
|
+
eventId: operation.id ?? "EVENT_ID_NOT_FOUND",
|
|
2754
|
+
stateHash: operation.hash,
|
|
2755
|
+
operationType: operation.type,
|
|
2756
|
+
operationInput: operation.input ?? {},
|
|
2757
|
+
address: (_b = (_a = operation.context) == null ? void 0 : _a.signer) == null ? void 0 : _b.user.address,
|
|
2758
|
+
chainId: (_d = (_c = operation.context) == null ? void 0 : _c.signer) == null ? void 0 : _d.user.chainId,
|
|
2759
|
+
timestamp: operation.timestamp,
|
|
2760
|
+
signatures: makeSignatures(((_f = (_e = operation.context) == null ? void 0 : _e.signer) == null ? void 0 : _f.signatures) ?? []),
|
|
2761
|
+
errors: operation.error ? [operation.error] : void 0
|
|
2762
|
+
});
|
|
2763
|
+
if (operation.skip > 0) {
|
|
2764
|
+
revisionsAndSkips.push({
|
|
2765
|
+
type: "skip",
|
|
2766
|
+
height: 34,
|
|
2767
|
+
operationIndex: operation.index,
|
|
2768
|
+
skipCount: operation.skip,
|
|
2769
|
+
timestamp: operation.timestamp
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
return revisionsAndSkips;
|
|
2774
|
+
}
|
|
2775
|
+
function makeSignatureFromSignatureArray(signatureArray) {
|
|
2776
|
+
const [signerAddress, hash, prevStateHash, signatureBytes] = signatureArray;
|
|
2777
|
+
return {
|
|
2778
|
+
signerAddress,
|
|
2779
|
+
hash,
|
|
2780
|
+
prevStateHash,
|
|
2781
|
+
signatureBytes,
|
|
2782
|
+
isVerified: true
|
|
2783
|
+
};
|
|
2784
|
+
}
|
|
2785
|
+
function makeSignatures(signaturesArray) {
|
|
2786
|
+
return signaturesArray == null ? void 0 : signaturesArray.map(makeSignatureFromSignatureArray);
|
|
2787
|
+
}
|
|
2788
|
+
function Day(props) {
|
|
2789
|
+
const { timestamp } = props;
|
|
2790
|
+
const formattedDate = format(timestamp, "MMM dd, yyyy");
|
|
2791
|
+
return jsxs("h2", { className: "-ml-6 flex items-center gap-1 bg-slate-50 py-2 text-xs text-slate-100", children: [jsx(Icon, { name: "Ring", size: 16 }), " Changes on ", formattedDate] });
|
|
2792
|
+
}
|
|
2793
|
+
function Timeline(props) {
|
|
2794
|
+
const { localOperations, globalOperations, scope } = props;
|
|
2795
|
+
const operations = scope === "local" ? localOperations : globalOperations;
|
|
2796
|
+
const initialNumRowsToShow = 100;
|
|
2797
|
+
const allRows = useMemo(() => makeRows(operations), [operations]);
|
|
2798
|
+
const [scrollAmount, setScrollAmount] = useState(0);
|
|
2799
|
+
const [numRowsToShow, setNumRowsToShow] = useState(initialNumRowsToShow);
|
|
2800
|
+
const [rows, setRows] = useState(() => allRows.slice(0, numRowsToShow));
|
|
2801
|
+
const parentRef = useRef(null);
|
|
2802
|
+
const hasNextPage = rows.length < allRows.length;
|
|
2803
|
+
const rowVirtualizer = useVirtualizer({
|
|
2804
|
+
count: rows.length,
|
|
2805
|
+
getScrollElement: () => parentRef.current,
|
|
2806
|
+
estimateSize: (i) => allRows[i].height,
|
|
2807
|
+
gap: 8
|
|
2808
|
+
});
|
|
2809
|
+
useEffect(() => {
|
|
2810
|
+
if (!hasNextPage)
|
|
2811
|
+
return;
|
|
2812
|
+
const ratio = Math.floor(scrollAmount / 46);
|
|
2813
|
+
const newNumRevisions = initialNumRowsToShow + ratio;
|
|
2814
|
+
setNumRowsToShow((prev) => newNumRevisions > prev ? newNumRevisions : prev);
|
|
2815
|
+
}, [scrollAmount, hasNextPage]);
|
|
2816
|
+
useEffect(() => {
|
|
2817
|
+
setRows(allRows.slice(0, numRowsToShow));
|
|
2818
|
+
}, [allRows, numRowsToShow]);
|
|
2819
|
+
const handleScroll = (e) => {
|
|
2820
|
+
setScrollAmount((prev) => {
|
|
2821
|
+
const n = prev + e.deltaY;
|
|
2822
|
+
if (n < 0) {
|
|
2823
|
+
return 0;
|
|
2824
|
+
}
|
|
2825
|
+
return n;
|
|
2826
|
+
});
|
|
2827
|
+
};
|
|
2828
|
+
useEffect(() => {
|
|
2829
|
+
window.addEventListener("wheel", handleScroll);
|
|
2830
|
+
return () => {
|
|
2831
|
+
window.removeEventListener("wheel", handleScroll);
|
|
2832
|
+
};
|
|
2833
|
+
}, []);
|
|
2834
|
+
return jsx("div", { className: "border-l border-slate-100", ref: parentRef, style: {
|
|
2835
|
+
height: `${rowVirtualizer.getTotalSize()}px`,
|
|
2836
|
+
width: "100%",
|
|
2837
|
+
position: "relative"
|
|
2838
|
+
}, children: rowVirtualizer.getVirtualItems().map((virtualRow) => {
|
|
2839
|
+
const row = rows[virtualRow.index];
|
|
2840
|
+
return jsxs("div", { style: {
|
|
2841
|
+
position: "absolute",
|
|
2842
|
+
top: 0,
|
|
2843
|
+
left: 16,
|
|
2844
|
+
width: "100%",
|
|
2845
|
+
height: `${virtualRow.size}px`,
|
|
2846
|
+
transform: `translateY(${virtualRow.start}px)`
|
|
2847
|
+
}, children: [row.type === "revision" && createElement(Revision, { ...row, key: virtualRow.key }), row.type === "skip" && jsx(Skip, { ...row }, virtualRow.key), row.type === "day" && jsx(Day, { ...row }, virtualRow.key)] }, virtualRow.index);
|
|
2848
|
+
}) });
|
|
2849
|
+
}
|
|
2850
|
+
function RevisionHistory(props) {
|
|
2851
|
+
const { documentTitle, documentId, globalOperations, localOperations, onClose, itemsPerPage = 100 } = props;
|
|
2852
|
+
const [scope, setScope] = useState("global");
|
|
2853
|
+
const visibleOperations = useMemo(() => {
|
|
2854
|
+
const operations = scope === "global" ? globalOperations : localOperations;
|
|
2855
|
+
return garbageCollect(sortOperations(operations)).sort((a, b) => b.index - a.index);
|
|
2856
|
+
}, [globalOperations, localOperations, scope]);
|
|
2857
|
+
const { pageItems, pages, goToPage, goToNextPage, goToPreviousPage, goToFirstPage, goToLastPage, hiddenNextPages, isNextPageAvailable, isPreviousPageAvailable } = usePagination(visibleOperations, {
|
|
2858
|
+
itemsPerPage
|
|
2859
|
+
});
|
|
2860
|
+
function onChangeScope(scope2) {
|
|
2861
|
+
goToFirstPage();
|
|
2862
|
+
setScope(scope2);
|
|
2863
|
+
}
|
|
2864
|
+
const showPagination = visibleOperations.length > itemsPerPage;
|
|
2865
|
+
const PaginationComponent = showPagination ? jsx("div", { className: "mt-4 flex w-full justify-end", children: jsx(Pagination, { firstPageLabel: "First Page", goToFirstPage, goToLastPage, goToNextPage, goToPage, goToPreviousPage, hiddenNextPages, isNextPageAvailable, isPreviousPageAvailable, lastPageLabel: "Last Page", nextPageLabel: "Next", pages, previousPageLabel: "Previous" }) }) : jsx("hr", { className: "h-12 border-none" });
|
|
2866
|
+
return jsxs(TooltipProvider, { children: [jsx(Header, { docId: documentId, onChangeScope, onClose, scope, title: documentTitle }), PaginationComponent, jsx("div", { className: "mt-4 flex justify-center rounded-md bg-slate-50 p-4", children: visibleOperations.length > 0 ? jsx("div", { className: "grid grid-cols-[minmax(min-content,1018px)]", children: jsx(Timeline, { globalOperations: scope === "global" ? pageItems : [], localOperations: scope === "local" ? pageItems : [], scope }) }) : jsx("h3", { className: "my-40 text-gray-600", children: "This document has no recorded operations yet." }) }), PaginationComponent] });
|
|
2867
|
+
}
|
|
2868
|
+
function Tooltip(props) {
|
|
2869
|
+
const { children, content, open, defaultOpen, onOpenChange, className, ...rest } = props;
|
|
2870
|
+
return jsxs(Root3, { defaultOpen, delayDuration: 0, onOpenChange, open, children: [jsx(Trigger, { asChild: true, children }), jsx(Portal, { children: jsx(Content2, { ...rest, className: twMerge("shadow-tooltip rounded-lg border border-gray-200 bg-white p-2 text-xs", className), children: content }) })] });
|
|
2871
|
+
}
|
|
2872
|
+
const TooltipProvider = Provider;
|
|
2873
|
+
const BUDGET = "powerhouse/budget-statement";
|
|
2874
|
+
const DEFAULT = "powerhouse/default";
|
|
2875
|
+
const MAKERDAO_RWA_PORTFOLIO = "makerdao/rwa-portfolio";
|
|
2876
|
+
const documentTypes = [BUDGET, DEFAULT, MAKERDAO_RWA_PORTFOLIO];
|
|
2877
|
+
const BudgetStatementImg = "data:image/png;base64,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";
|
|
2878
|
+
const MakerdaoRWAPortfolioImg = "/assets/rwa-report-Bb0W5-ac.png";
|
|
2879
|
+
const DefaultImg = "data:image/png;base64,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";
|
|
2880
|
+
const iconMap = {
|
|
2881
|
+
[BUDGET]: BudgetStatementImg,
|
|
2882
|
+
[DEFAULT]: DefaultImg,
|
|
2883
|
+
[MAKERDAO_RWA_PORTFOLIO]: MakerdaoRWAPortfolioImg
|
|
2884
|
+
};
|
|
2885
|
+
function useDrag(props) {
|
|
2886
|
+
const { uiNode } = props;
|
|
2887
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
2888
|
+
const onDragStart = useCallback((event) => {
|
|
2889
|
+
event.dataTransfer.setData(UI_NODE, JSON.stringify(uiNode));
|
|
2890
|
+
}, [uiNode]);
|
|
2891
|
+
const onDragEnd = useCallback(() => {
|
|
2892
|
+
setIsDragging(false);
|
|
2893
|
+
}, []);
|
|
2894
|
+
const allowedToDragNode = !!uiNode && uiNode.kind !== DRIVE;
|
|
2895
|
+
return useMemo(() => {
|
|
2896
|
+
const dragProps = allowedToDragNode ? {
|
|
2897
|
+
draggable: true,
|
|
2898
|
+
onDragStart,
|
|
2899
|
+
onDragEnd
|
|
2900
|
+
} : {
|
|
2901
|
+
draggable: false,
|
|
2902
|
+
onDragStart: void 0,
|
|
2903
|
+
onDragEnd: void 0
|
|
2904
|
+
};
|
|
2905
|
+
return {
|
|
2906
|
+
isDragging,
|
|
2907
|
+
dragProps
|
|
2908
|
+
};
|
|
2909
|
+
}, [allowedToDragNode, isDragging, onDragEnd, onDragStart]);
|
|
2910
|
+
}
|
|
2911
|
+
function useDrop(props) {
|
|
2912
|
+
const { uiNode, onAddFile, onCopyNode, onMoveNode } = props;
|
|
2913
|
+
const [isDropTarget, setIsDropTarget] = useState(false);
|
|
2914
|
+
const allowedToBeDropTarget = !!uiNode && uiNode.kind !== FILE;
|
|
2915
|
+
const onDragOver = useCallback((event) => {
|
|
2916
|
+
event.preventDefault();
|
|
2917
|
+
setIsDropTarget(true);
|
|
2918
|
+
}, []);
|
|
2919
|
+
const onDragLeave = useCallback(() => {
|
|
2920
|
+
setIsDropTarget(false);
|
|
2921
|
+
}, []);
|
|
2922
|
+
const onDrop = useCallback(async (event) => {
|
|
2923
|
+
event.preventDefault();
|
|
2924
|
+
event.stopPropagation();
|
|
2925
|
+
if (!uiNode)
|
|
2926
|
+
return;
|
|
2927
|
+
const droppedFiles = getDroppedFiles(event.dataTransfer.items).filter(Boolean);
|
|
2928
|
+
if (droppedFiles.length) {
|
|
2929
|
+
for (const file of droppedFiles) {
|
|
2930
|
+
if (file) {
|
|
2931
|
+
await onAddFile(file, uiNode);
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
} else {
|
|
2935
|
+
const altOrOptionKeyPressed = event.getModifierState("Alt");
|
|
2936
|
+
const data = event.dataTransfer.getData(UI_NODE);
|
|
2937
|
+
const droppedNode = JSON.parse(data);
|
|
2938
|
+
if (altOrOptionKeyPressed) {
|
|
2939
|
+
await onCopyNode(droppedNode, uiNode);
|
|
2940
|
+
} else {
|
|
2941
|
+
await onMoveNode(droppedNode, uiNode);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
setIsDropTarget(false);
|
|
2945
|
+
}, [onAddFile, onCopyNode, onMoveNode, uiNode]);
|
|
2946
|
+
return useMemo(() => {
|
|
2947
|
+
const dropProps = allowedToBeDropTarget ? { onDragOver, onDragLeave, onDrop } : {
|
|
2948
|
+
onDragOver: void 0,
|
|
2949
|
+
onDragLeave: void 0,
|
|
2950
|
+
onDrop: void 0
|
|
2951
|
+
};
|
|
2952
|
+
return {
|
|
2953
|
+
isDropTarget,
|
|
2954
|
+
dropProps
|
|
2955
|
+
};
|
|
2956
|
+
}, [allowedToBeDropTarget, isDropTarget, onDragLeave, onDragOver, onDrop]);
|
|
2957
|
+
}
|
|
2958
|
+
function getDroppedFiles(items) {
|
|
2959
|
+
const droppedFiles = Array.from(items).map((item) => item.kind === "file" ? item.getAsFile() : null).filter(Boolean);
|
|
2960
|
+
return droppedFiles;
|
|
2961
|
+
}
|
|
2962
|
+
function formatEthAddress(address) {
|
|
2963
|
+
return `${address.slice(0, 7)}...${address.slice(-5)}`;
|
|
2964
|
+
}
|
|
2965
|
+
function getDocumentIconSrc(documentType, customDocumentIconSrc) {
|
|
2966
|
+
if (customDocumentIconSrc) {
|
|
2967
|
+
return customDocumentIconSrc;
|
|
2968
|
+
}
|
|
2969
|
+
if (documentTypes.includes(documentType)) {
|
|
2970
|
+
return iconMap[documentType];
|
|
2971
|
+
}
|
|
2972
|
+
return iconMap[DEFAULT];
|
|
2973
|
+
}
|
|
2974
|
+
const validateDocument = (document2) => {
|
|
2975
|
+
const errors = [];
|
|
2976
|
+
if (document2.documentType !== "powerhouse/document-model") {
|
|
2977
|
+
return errors;
|
|
2978
|
+
}
|
|
2979
|
+
const doc = document2;
|
|
2980
|
+
const specs = doc.state.global.specifications[0];
|
|
2981
|
+
const initialStateErrors = Object.keys(specs.state).reduce((acc, scopeKey) => {
|
|
2982
|
+
const scope = scopeKey;
|
|
2983
|
+
return [
|
|
2984
|
+
...acc,
|
|
2985
|
+
...validateInitialState(
|
|
2986
|
+
specs.state[scope].initialValue,
|
|
2987
|
+
scope !== "global"
|
|
2988
|
+
).map((err) => ({
|
|
2989
|
+
...err,
|
|
2990
|
+
message: `${err.message}. Scope: ${scope}`,
|
|
2991
|
+
details: { ...err.details, scope }
|
|
2992
|
+
}))
|
|
2993
|
+
];
|
|
2994
|
+
}, []);
|
|
2995
|
+
const schemaStateErrors = Object.keys(specs.state).reduce((acc, scopeKey) => {
|
|
2996
|
+
var _a;
|
|
2997
|
+
const scope = scopeKey;
|
|
2998
|
+
const isGlobalScope = scope === "global";
|
|
2999
|
+
return [
|
|
3000
|
+
...acc,
|
|
3001
|
+
...validateStateSchemaName(
|
|
3002
|
+
specs.state[scope].schema,
|
|
3003
|
+
doc.name || ((_a = doc.state.global) == null ? void 0 : _a.name) || "",
|
|
3004
|
+
!isGlobalScope ? scope : "",
|
|
3005
|
+
!isGlobalScope
|
|
3006
|
+
).map((err) => ({
|
|
3007
|
+
...err,
|
|
3008
|
+
message: `${err.message}. Scope: ${scope}`,
|
|
3009
|
+
details: { ...err.details, scope }
|
|
3010
|
+
}))
|
|
3011
|
+
];
|
|
3012
|
+
}, []);
|
|
3013
|
+
const modulesErrors = validateModules(specs.modules);
|
|
3014
|
+
return [...initialStateErrors, ...schemaStateErrors, ...modulesErrors];
|
|
3015
|
+
};
|
|
3016
|
+
function useDocumentEditor(props) {
|
|
3017
|
+
const { driveId, documentId, documentType, documentModelModule, user } = props;
|
|
3018
|
+
const reactor = useUnwrappedReactor();
|
|
3019
|
+
const connectDid = useConnectDid();
|
|
3020
|
+
const { sign } = useConnectCrypto();
|
|
3021
|
+
const doc = useDocument(reactor, { documentId, driveId, documentType });
|
|
3022
|
+
const documentEditorProps = useDocumentEditorProps(reactor, {
|
|
3023
|
+
nodeId: documentId,
|
|
3024
|
+
driveId,
|
|
3025
|
+
document: doc,
|
|
3026
|
+
documentModelModule,
|
|
3027
|
+
connectDid,
|
|
3028
|
+
sign,
|
|
3029
|
+
user
|
|
3030
|
+
});
|
|
3031
|
+
return documentEditorProps;
|
|
3032
|
+
}
|
|
3033
|
+
function useEditorDispatch(node, documentDispatch, onAddOperation) {
|
|
3034
|
+
const user = useUser() || void 0;
|
|
3035
|
+
const connectDid = useConnectDid();
|
|
3036
|
+
const { sign } = useConnectCrypto();
|
|
3037
|
+
const documentType = (node == null ? void 0 : node.kind) === "DRIVE" ? "powerhouse/document-drive" : node == null ? void 0 : node.documentType;
|
|
3038
|
+
const getDocumentModelModule = useGetDocumentModelModule();
|
|
3039
|
+
const documentModelModule = useMemo(
|
|
3040
|
+
() => documentType ? getDocumentModelModule(documentType) : void 0,
|
|
3041
|
+
[documentType, getDocumentModelModule]
|
|
3042
|
+
);
|
|
3043
|
+
const dispatch = useCallback(
|
|
3044
|
+
(action, onErrorCallback) => {
|
|
3045
|
+
const callback = (operation, state) => {
|
|
3046
|
+
if (!(node == null ? void 0 : node.id)) return;
|
|
3047
|
+
const { prevState } = state;
|
|
3048
|
+
signOperation(
|
|
3049
|
+
operation,
|
|
3050
|
+
sign,
|
|
3051
|
+
node.id,
|
|
3052
|
+
prevState,
|
|
3053
|
+
documentModelModule == null ? void 0 : documentModelModule.reducer,
|
|
3054
|
+
user
|
|
3055
|
+
).then((op) => {
|
|
3056
|
+
var _a;
|
|
3057
|
+
(_a = window.documentEditorDebugTools) == null ? void 0 : _a.pushOperation(
|
|
3058
|
+
operation
|
|
3059
|
+
);
|
|
3060
|
+
return onAddOperation(op);
|
|
3061
|
+
}).catch(logger.error);
|
|
3062
|
+
};
|
|
3063
|
+
documentDispatch(
|
|
3064
|
+
addActionContext(action, connectDid, user),
|
|
3065
|
+
callback,
|
|
3066
|
+
onErrorCallback
|
|
3067
|
+
);
|
|
3068
|
+
},
|
|
3069
|
+
[
|
|
3070
|
+
documentDispatch,
|
|
3071
|
+
connectDid,
|
|
3072
|
+
documentModelModule == null ? void 0 : documentModelModule.reducer,
|
|
3073
|
+
onAddOperation,
|
|
3074
|
+
node,
|
|
3075
|
+
sign,
|
|
3076
|
+
user
|
|
3077
|
+
]
|
|
3078
|
+
);
|
|
3079
|
+
return dispatch;
|
|
3080
|
+
}
|
|
3081
|
+
function useEditorProps(document2, node, documentDispatch, onAddOperation) {
|
|
3082
|
+
const { t } = useTranslation();
|
|
3083
|
+
const { showModal } = useModal();
|
|
3084
|
+
const theme = useAtomValue(themeAtom);
|
|
3085
|
+
const user = useUser() || void 0;
|
|
3086
|
+
const userPermissions = useUserPermissions();
|
|
3087
|
+
const context = useMemo(() => ({ theme, user }), [theme, user]);
|
|
3088
|
+
const {
|
|
3089
|
+
selectedParentNode,
|
|
3090
|
+
selectedDocument,
|
|
3091
|
+
setSelectedNode,
|
|
3092
|
+
getDocumentModelModule
|
|
3093
|
+
} = useUiNodes();
|
|
3094
|
+
const canUndo = !!document2 && (document2.revision.global > 0 || document2.revision.local > 0);
|
|
3095
|
+
const canRedo = !!(document2 == null ? void 0 : document2.clipboard.length);
|
|
3096
|
+
const dispatch = useEditorDispatch(node, documentDispatch, onAddOperation);
|
|
3097
|
+
const handleUndo = useCallback(() => {
|
|
3098
|
+
dispatch(undo());
|
|
3099
|
+
}, [dispatch]);
|
|
3100
|
+
const handleRedo = useCallback(() => {
|
|
3101
|
+
dispatch(redo());
|
|
3102
|
+
}, [dispatch]);
|
|
3103
|
+
const onClose = useCallback(() => {
|
|
3104
|
+
setSelectedNode(selectedParentNode);
|
|
3105
|
+
}, [selectedParentNode, setSelectedNode]);
|
|
3106
|
+
const exportDocument = useCallback(
|
|
3107
|
+
(document22) => {
|
|
3108
|
+
const validationErrors = validateDocument(document22);
|
|
3109
|
+
if (validationErrors.length) {
|
|
3110
|
+
showModal("confirmationModal", {
|
|
3111
|
+
title: t("modals.exportDocumentWithErrors.title"),
|
|
3112
|
+
body: /* @__PURE__ */ jsxs("div", { children: [
|
|
3113
|
+
/* @__PURE__ */ jsx("p", { children: t("modals.exportDocumentWithErrors.body") }),
|
|
3114
|
+
/* @__PURE__ */ jsx("ul", { className: "mt-4 flex list-disc flex-col items-start px-4 text-xs", children: validationErrors.map((error, index) => /* @__PURE__ */ jsx("li", { children: error.message }, index)) })
|
|
3115
|
+
] }),
|
|
3116
|
+
cancelLabel: t("common.cancel"),
|
|
3117
|
+
continueLabel: t("common.export"),
|
|
3118
|
+
onCancel(closeModal) {
|
|
3119
|
+
closeModal();
|
|
3120
|
+
},
|
|
3121
|
+
onContinue(closeModal) {
|
|
3122
|
+
closeModal();
|
|
3123
|
+
return exportFile(document22, getDocumentModelModule);
|
|
3124
|
+
}
|
|
3125
|
+
});
|
|
3126
|
+
} else {
|
|
3127
|
+
return exportFile(document22, getDocumentModelModule);
|
|
3128
|
+
}
|
|
3129
|
+
},
|
|
3130
|
+
[getDocumentModelModule, showModal, t]
|
|
3131
|
+
);
|
|
3132
|
+
const onExport = useCallback(() => {
|
|
3133
|
+
if (selectedDocument) {
|
|
3134
|
+
return exportDocument(selectedDocument);
|
|
3135
|
+
}
|
|
3136
|
+
}, [exportDocument, selectedDocument]);
|
|
3137
|
+
const [revisionHistoryVisible, setRevisionHistoryVisible] = useState(false);
|
|
3138
|
+
const showRevisionHistory = useCallback(
|
|
3139
|
+
() => setRevisionHistoryVisible(true),
|
|
3140
|
+
[]
|
|
3141
|
+
);
|
|
3142
|
+
return {
|
|
3143
|
+
dispatch,
|
|
3144
|
+
revisionHistoryVisible,
|
|
3145
|
+
context,
|
|
3146
|
+
canUndo,
|
|
3147
|
+
canRedo,
|
|
3148
|
+
undo: handleUndo,
|
|
3149
|
+
redo: handleRedo,
|
|
3150
|
+
onClose,
|
|
3151
|
+
onExport,
|
|
3152
|
+
onShowRevisionHistory: showRevisionHistory,
|
|
3153
|
+
isAllowedToCreateDocuments: (userPermissions == null ? void 0 : userPermissions.isAllowedToCreateDocuments) ?? false,
|
|
3154
|
+
isAllowedToEditDocuments: (userPermissions == null ? void 0 : userPermissions.isAllowedToEditDocuments) ?? false
|
|
3155
|
+
};
|
|
3156
|
+
}
|
|
3157
|
+
function useSyncStatus(driveId, documentId) {
|
|
3158
|
+
const { getSyncStatusSync, onSyncStatus, documentDrives } = useDocumentDriveServer();
|
|
3159
|
+
const syncStatus = useSyncExternalStore(
|
|
3160
|
+
(onStoreChange) => {
|
|
3161
|
+
const unsub = onSyncStatus(onStoreChange);
|
|
3162
|
+
return unsub;
|
|
3163
|
+
},
|
|
3164
|
+
() => {
|
|
3165
|
+
var _a;
|
|
3166
|
+
const drive = documentDrives.find(
|
|
3167
|
+
(_drive) => _drive.state.global.id === driveId
|
|
3168
|
+
);
|
|
3169
|
+
if (!drive) return;
|
|
3170
|
+
const isReadDrive = "readContext" in drive;
|
|
3171
|
+
const _sharingType = !isReadDrive ? (_a = drive.state.local.sharingType) == null ? void 0 : _a.toUpperCase() : "PUBLIC";
|
|
3172
|
+
const sharingType = _sharingType === "PRIVATE" ? "LOCAL" : _sharingType;
|
|
3173
|
+
if (!documentId) {
|
|
3174
|
+
const status2 = getSyncStatusSync(
|
|
3175
|
+
driveId,
|
|
3176
|
+
sharingType
|
|
3177
|
+
);
|
|
3178
|
+
return status2;
|
|
3179
|
+
}
|
|
3180
|
+
const document2 = drive.state.global.nodes.find(
|
|
3181
|
+
(node) => node.id === documentId
|
|
3182
|
+
);
|
|
3183
|
+
if (!document2) return;
|
|
3184
|
+
if (!("synchronizationUnits" in document2)) return;
|
|
3185
|
+
const status = getSyncStatusSync(
|
|
3186
|
+
document2.synchronizationUnits[0].syncId,
|
|
3187
|
+
sharingType
|
|
3188
|
+
);
|
|
3189
|
+
return status;
|
|
3190
|
+
}
|
|
3191
|
+
);
|
|
3192
|
+
return syncStatus;
|
|
3193
|
+
}
|
|
3194
|
+
const useUndoRedoShortcuts = (props) => {
|
|
3195
|
+
var _a;
|
|
3196
|
+
const { undo: undo2, redo: redo2, canRedo, canUndo } = props;
|
|
3197
|
+
const { isMac } = ((_a = window.electronAPI) == null ? void 0 : _a.platformInfo) || {};
|
|
3198
|
+
let undoShortcut = "ctrl+z";
|
|
3199
|
+
let redoShortcut = "ctrl+y";
|
|
3200
|
+
if (isMac) {
|
|
3201
|
+
undoShortcut = "mod+z";
|
|
3202
|
+
redoShortcut = "mod+shift+z";
|
|
3203
|
+
}
|
|
3204
|
+
useHotkeys(
|
|
3205
|
+
undoShortcut,
|
|
3206
|
+
(event) => {
|
|
3207
|
+
event.preventDefault();
|
|
3208
|
+
if (canUndo) {
|
|
3209
|
+
undo2();
|
|
3210
|
+
}
|
|
3211
|
+
},
|
|
3212
|
+
{},
|
|
3213
|
+
[canUndo, undo2]
|
|
3214
|
+
);
|
|
3215
|
+
useHotkeys(
|
|
3216
|
+
redoShortcut,
|
|
3217
|
+
(event) => {
|
|
3218
|
+
event.preventDefault();
|
|
3219
|
+
if (canRedo) {
|
|
3220
|
+
redo2();
|
|
3221
|
+
}
|
|
3222
|
+
},
|
|
3223
|
+
{},
|
|
3224
|
+
[canRedo, redo2]
|
|
3225
|
+
);
|
|
3226
|
+
};
|
|
3227
|
+
function EditorLoader(props) {
|
|
3228
|
+
const [showLoading, setShowLoading] = useState(false);
|
|
3229
|
+
useEffect(() => {
|
|
3230
|
+
setTimeout(() => {
|
|
3231
|
+
setShowLoading(true);
|
|
3232
|
+
}, props.loadingTimeout ?? 200);
|
|
3233
|
+
}, [props]);
|
|
3234
|
+
if (!showLoading) return null;
|
|
3235
|
+
const { customEditorLoader, ...defaultProps } = props;
|
|
3236
|
+
if (customEditorLoader) return /* @__PURE__ */ jsx(Fragment$1, { children: customEditorLoader });
|
|
3237
|
+
return /* @__PURE__ */ jsx(DefaultEditorLoader, { ...defaultProps });
|
|
3238
|
+
}
|
|
3239
|
+
function EditorError({ message: message2 }) {
|
|
3240
|
+
return /* @__PURE__ */ jsx("div", { className: "flex size-full items-center justify-center", children: /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold", children: message2 }) });
|
|
3241
|
+
}
|
|
3242
|
+
function FallbackEditorError(props) {
|
|
3243
|
+
const message2 = props.error instanceof Error ? props.error.message : props.error;
|
|
3244
|
+
return /* @__PURE__ */ jsx(EditorError, { message: message2 });
|
|
3245
|
+
}
|
|
3246
|
+
const DocumentEditor = (props) => {
|
|
3247
|
+
const {
|
|
3248
|
+
fileNodeDocument,
|
|
3249
|
+
document: initialDocument,
|
|
3250
|
+
onClose,
|
|
3251
|
+
onChange,
|
|
3252
|
+
onExport,
|
|
3253
|
+
onAddOperation,
|
|
3254
|
+
onOpenSwitchboardLink
|
|
3255
|
+
} = props;
|
|
3256
|
+
const documentId = fileNodeDocument == null ? void 0 : fileNodeDocument.documentId;
|
|
3257
|
+
const [revisionHistoryVisible, setRevisionHistoryVisible] = useState(false);
|
|
3258
|
+
const theme = useAtomValue(themeAtom);
|
|
3259
|
+
const user = useUser() || void 0;
|
|
3260
|
+
const connectDid = useConnectDid();
|
|
3261
|
+
const { sign } = useConnectCrypto();
|
|
3262
|
+
const getDocumentModelModule = useGetDocumentModelModule();
|
|
3263
|
+
const getEditor = useGetEditor();
|
|
3264
|
+
const documentType = fileNodeDocument == null ? void 0 : fileNodeDocument.documentType;
|
|
3265
|
+
const documentModel = useMemo(
|
|
3266
|
+
() => documentType ? getDocumentModelModule(documentType) : void 0,
|
|
3267
|
+
[documentType, getDocumentModelModule]
|
|
3268
|
+
);
|
|
3269
|
+
const editor = useMemo(
|
|
3270
|
+
() => documentType ? getEditor(documentType) : void 0,
|
|
3271
|
+
[documentType, getEditor]
|
|
3272
|
+
);
|
|
3273
|
+
const [document2, _dispatch, error] = useDocumentDispatch(
|
|
3274
|
+
documentModel == null ? void 0 : documentModel.reducer,
|
|
3275
|
+
initialDocument
|
|
3276
|
+
);
|
|
3277
|
+
const context = useMemo(
|
|
3278
|
+
() => ({ theme, user }),
|
|
3279
|
+
[theme, user]
|
|
3280
|
+
);
|
|
3281
|
+
const userPermissions = useUserPermissions();
|
|
3282
|
+
const currentDocument = useRef({ ...fileNodeDocument, document: document2 });
|
|
3283
|
+
useEffect(() => {
|
|
3284
|
+
var _a;
|
|
3285
|
+
if (!(fileNodeDocument == null ? void 0 : fileNodeDocument.documentId) || !document2) return;
|
|
3286
|
+
if (!("documentId" in currentDocument.current) || currentDocument.current.documentId !== documentId) {
|
|
3287
|
+
currentDocument.current = { ...fileNodeDocument, document: document2 };
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
if (!isSameDocument(currentDocument.current.document, document2)) {
|
|
3291
|
+
currentDocument.current.document = document2;
|
|
3292
|
+
(_a = window.documentEditorDebugTools) == null ? void 0 : _a.setDocument(document2);
|
|
3293
|
+
onChange == null ? void 0 : onChange(documentId, document2);
|
|
3294
|
+
}
|
|
3295
|
+
}, [document2, documentId, fileNodeDocument, onChange]);
|
|
3296
|
+
const dispatch = useCallback(
|
|
3297
|
+
(action, onErrorCallback) => {
|
|
3298
|
+
const callback = (operation, state) => {
|
|
3299
|
+
if (!(fileNodeDocument == null ? void 0 : fileNodeDocument.documentId)) return;
|
|
3300
|
+
const { prevState } = state;
|
|
3301
|
+
signOperation(
|
|
3302
|
+
operation,
|
|
3303
|
+
sign,
|
|
3304
|
+
fileNodeDocument.documentId,
|
|
3305
|
+
prevState,
|
|
3306
|
+
documentModel == null ? void 0 : documentModel.reducer,
|
|
3307
|
+
user
|
|
3308
|
+
).then((op) => {
|
|
3309
|
+
var _a;
|
|
3310
|
+
(_a = window.documentEditorDebugTools) == null ? void 0 : _a.pushOperation(
|
|
3311
|
+
operation
|
|
3312
|
+
);
|
|
3313
|
+
return onAddOperation(op);
|
|
3314
|
+
}).catch(logger.error);
|
|
3315
|
+
};
|
|
3316
|
+
_dispatch(
|
|
3317
|
+
addActionContext(action, connectDid, user),
|
|
3318
|
+
callback,
|
|
3319
|
+
onErrorCallback
|
|
3320
|
+
);
|
|
3321
|
+
},
|
|
3322
|
+
[
|
|
3323
|
+
_dispatch,
|
|
3324
|
+
connectDid,
|
|
3325
|
+
documentModel == null ? void 0 : documentModel.reducer,
|
|
3326
|
+
onAddOperation,
|
|
3327
|
+
fileNodeDocument,
|
|
3328
|
+
sign,
|
|
3329
|
+
user
|
|
3330
|
+
]
|
|
3331
|
+
);
|
|
3332
|
+
const showRevisionHistory = useCallback(
|
|
3333
|
+
() => setRevisionHistoryVisible(true),
|
|
3334
|
+
[]
|
|
3335
|
+
);
|
|
3336
|
+
const hideRevisionHistory = useCallback(
|
|
3337
|
+
() => setRevisionHistoryVisible(false),
|
|
3338
|
+
[]
|
|
3339
|
+
);
|
|
3340
|
+
const handleUndo = useCallback(() => {
|
|
3341
|
+
dispatch(undo());
|
|
3342
|
+
}, [dispatch]);
|
|
3343
|
+
const handleRedo = useCallback(() => {
|
|
3344
|
+
dispatch(redo());
|
|
3345
|
+
}, [dispatch]);
|
|
3346
|
+
const isLoadingDocument = (fileNodeDocument == null ? void 0 : fileNodeDocument.status) === "LOADING" || !document2;
|
|
3347
|
+
const isLoadingEditor = editor === void 0 || !!document2 && editor && !editor.documentTypes.includes(document2.documentType) && !editor.documentTypes.includes("*");
|
|
3348
|
+
const canUndo = !!document2 && (document2.revision.global > 0 || document2.revision.local > 0);
|
|
3349
|
+
const canRedo = !!(document2 == null ? void 0 : document2.clipboard.length);
|
|
3350
|
+
useUndoRedoShortcuts({
|
|
3351
|
+
undo: handleUndo,
|
|
3352
|
+
redo: handleRedo,
|
|
3353
|
+
canUndo,
|
|
3354
|
+
canRedo
|
|
3355
|
+
});
|
|
3356
|
+
useEffect(() => {
|
|
3357
|
+
return () => {
|
|
3358
|
+
var _a;
|
|
3359
|
+
(_a = window.documentEditorDebugTools) == null ? void 0 : _a.clear();
|
|
3360
|
+
};
|
|
3361
|
+
}, []);
|
|
3362
|
+
const navigate = useNavigate();
|
|
3363
|
+
const { showModal } = useModal();
|
|
3364
|
+
const [editorError, setEditorError] = useState(void 0);
|
|
3365
|
+
useEffect(() => {
|
|
3366
|
+
if (editorError && editorError.documentId !== (fileNodeDocument == null ? void 0 : fileNodeDocument.documentId)) {
|
|
3367
|
+
setEditorError(void 0);
|
|
3368
|
+
}
|
|
3369
|
+
}, [editorError, fileNodeDocument, document2]);
|
|
3370
|
+
const handleEditorError = useCallback(
|
|
3371
|
+
(error2, info) => {
|
|
3372
|
+
setEditorError({
|
|
3373
|
+
error: error2,
|
|
3374
|
+
documentId,
|
|
3375
|
+
info
|
|
3376
|
+
});
|
|
3377
|
+
},
|
|
3378
|
+
[documentId]
|
|
3379
|
+
);
|
|
3380
|
+
if ((fileNodeDocument == null ? void 0 : fileNodeDocument.status) === "ERROR") {
|
|
3381
|
+
return /* @__PURE__ */ jsx(EditorError, { message: "Error loading document" });
|
|
3382
|
+
}
|
|
3383
|
+
if (isLoadingDocument || isLoadingEditor) {
|
|
3384
|
+
const message2 = isLoadingDocument ? "Loading document" : "Loading editor";
|
|
3385
|
+
return /* @__PURE__ */ jsx(EditorLoader, { message: message2 });
|
|
3386
|
+
}
|
|
3387
|
+
if (!fileNodeDocument) {
|
|
3388
|
+
return null;
|
|
3389
|
+
}
|
|
3390
|
+
if (!documentModel) {
|
|
3391
|
+
return /* @__PURE__ */ jsx(
|
|
3392
|
+
EditorError,
|
|
3393
|
+
{
|
|
3394
|
+
message: /* @__PURE__ */ jsxs("div", { className: "text-center leading-10", children: [
|
|
3395
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
3396
|
+
'Unable to open the document because the document model "',
|
|
3397
|
+
documentType,
|
|
3398
|
+
'" is not supported.'
|
|
3399
|
+
] }),
|
|
3400
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
3401
|
+
"Go to the",
|
|
3402
|
+
" ",
|
|
3403
|
+
/* @__PURE__ */ jsx(
|
|
3404
|
+
"button",
|
|
3405
|
+
{
|
|
3406
|
+
type: "button",
|
|
3407
|
+
className: "cursor-pointer underline",
|
|
3408
|
+
onClick: () => {
|
|
3409
|
+
showModal("settingsModal", {
|
|
3410
|
+
onRefresh: () => navigate(0)
|
|
3411
|
+
});
|
|
3412
|
+
},
|
|
3413
|
+
children: "package manager"
|
|
3414
|
+
}
|
|
3415
|
+
),
|
|
3416
|
+
" ",
|
|
3417
|
+
"to install this document model"
|
|
3418
|
+
] })
|
|
3419
|
+
] })
|
|
3420
|
+
}
|
|
3421
|
+
);
|
|
3422
|
+
}
|
|
3423
|
+
if (editor === null) {
|
|
3424
|
+
return /* @__PURE__ */ jsx(
|
|
3425
|
+
EditorError,
|
|
3426
|
+
{
|
|
3427
|
+
message: /* @__PURE__ */ jsxs("div", { className: "text-center leading-10", children: [
|
|
3428
|
+
/* @__PURE__ */ jsx("p", { children: "Unable to open the document because no editor has been found" }),
|
|
3429
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
3430
|
+
"Go to the",
|
|
3431
|
+
" ",
|
|
3432
|
+
/* @__PURE__ */ jsx(
|
|
3433
|
+
"button",
|
|
3434
|
+
{
|
|
3435
|
+
type: "button",
|
|
3436
|
+
className: "cursor-pointer underline",
|
|
3437
|
+
onClick: () => {
|
|
3438
|
+
showModal("settingsModal", {
|
|
3439
|
+
onRefresh: () => navigate(0)
|
|
3440
|
+
});
|
|
3441
|
+
},
|
|
3442
|
+
children: "package manager"
|
|
3443
|
+
}
|
|
3444
|
+
),
|
|
3445
|
+
" ",
|
|
3446
|
+
'an editor for the "$',
|
|
3447
|
+
documentType,
|
|
3448
|
+
'" document type'
|
|
3449
|
+
] })
|
|
3450
|
+
] })
|
|
3451
|
+
}
|
|
3452
|
+
);
|
|
3453
|
+
}
|
|
3454
|
+
const EditorComponent = editor.Component;
|
|
3455
|
+
const {
|
|
3456
|
+
disableExternalControls,
|
|
3457
|
+
documentToolbarEnabled,
|
|
3458
|
+
showSwitchboardLink
|
|
3459
|
+
} = editor.config || {};
|
|
3460
|
+
const handleSwitchboardLinkClick = showSwitchboardLink !== false ? onOpenSwitchboardLink : void 0;
|
|
3461
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative h-full", id: "document-editor-context", children: [
|
|
3462
|
+
documentToolbarEnabled && disableExternalControls && !revisionHistoryVisible && /* @__PURE__ */ jsx(
|
|
3463
|
+
DocumentToolbar,
|
|
3464
|
+
{
|
|
3465
|
+
onClose,
|
|
3466
|
+
onExport,
|
|
3467
|
+
onShowRevisionHistory: showRevisionHistory,
|
|
3468
|
+
title: fileNodeDocument.name || document2.name,
|
|
3469
|
+
onSwitchboardLinkClick: handleSwitchboardLinkClick
|
|
3470
|
+
}
|
|
3471
|
+
),
|
|
3472
|
+
!disableExternalControls && /* @__PURE__ */ jsxs("div", { className: "mb-4 flex justify-end gap-10", children: [
|
|
3473
|
+
/* @__PURE__ */ jsx(Button, { onClick: onExport, children: "Export" }),
|
|
3474
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-4", children: [
|
|
3475
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleUndo, disabled: !canUndo, children: "Undo" }),
|
|
3476
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleRedo, disabled: !canRedo, children: "Redo" })
|
|
3477
|
+
] }),
|
|
3478
|
+
/* @__PURE__ */ jsx("div", { className: "flex gap-4", children: /* @__PURE__ */ jsx(Button, { onClick: onClose, children: "Close" }) })
|
|
3479
|
+
] }),
|
|
3480
|
+
revisionHistoryVisible ? /* @__PURE__ */ jsx(
|
|
3481
|
+
RevisionHistory,
|
|
3482
|
+
{
|
|
3483
|
+
documentTitle: document2.name,
|
|
3484
|
+
documentId: fileNodeDocument.documentId,
|
|
3485
|
+
globalOperations: document2.operations.global,
|
|
3486
|
+
localOperations: document2.operations.local,
|
|
3487
|
+
onClose: hideRevisionHistory
|
|
3488
|
+
},
|
|
3489
|
+
documentId
|
|
3490
|
+
) : /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(EditorLoader, {}), children: /* @__PURE__ */ jsx(
|
|
3491
|
+
ErrorBoundary,
|
|
3492
|
+
{
|
|
3493
|
+
fallbackRender: FallbackEditorError,
|
|
3494
|
+
onError: handleEditorError,
|
|
3495
|
+
children: !(editorError == null ? void 0 : editorError.error) && /* @__PURE__ */ jsx(
|
|
3496
|
+
EditorComponent,
|
|
3497
|
+
{
|
|
3498
|
+
error,
|
|
3499
|
+
context,
|
|
3500
|
+
document: document2,
|
|
3501
|
+
documentNodeName: fileNodeDocument.name,
|
|
3502
|
+
dispatch,
|
|
3503
|
+
onClose,
|
|
3504
|
+
onExport,
|
|
3505
|
+
canUndo,
|
|
3506
|
+
canRedo,
|
|
3507
|
+
undo: handleUndo,
|
|
3508
|
+
redo: handleRedo,
|
|
3509
|
+
onSwitchboardLinkClick: handleSwitchboardLinkClick,
|
|
3510
|
+
onShowRevisionHistory: showRevisionHistory,
|
|
3511
|
+
isAllowedToCreateDocuments: (userPermissions == null ? void 0 : userPermissions.isAllowedToCreateDocuments) ?? false,
|
|
3512
|
+
isAllowedToEditDocuments: (userPermissions == null ? void 0 : userPermissions.isAllowedToEditDocuments) ?? false
|
|
3513
|
+
},
|
|
3514
|
+
documentId
|
|
3515
|
+
)
|
|
3516
|
+
},
|
|
3517
|
+
documentId
|
|
3518
|
+
) })
|
|
3519
|
+
] });
|
|
3520
|
+
};
|
|
3521
|
+
function DocumentEditorContainer() {
|
|
3522
|
+
const { t } = useTranslation();
|
|
3523
|
+
const { showModal } = useModal();
|
|
3524
|
+
const {
|
|
3525
|
+
selectedNode,
|
|
3526
|
+
selectedParentNode,
|
|
3527
|
+
isRemoteDrive,
|
|
3528
|
+
selectedDocument,
|
|
3529
|
+
fileNodeDocument,
|
|
3530
|
+
setSelectedNode,
|
|
3531
|
+
setSelectedDocument,
|
|
3532
|
+
openSwitchboardLink,
|
|
3533
|
+
addOperationToSelectedDocument,
|
|
3534
|
+
renameNode,
|
|
3535
|
+
getDocumentModelModule
|
|
3536
|
+
} = useUiNodes();
|
|
3537
|
+
const handleAddOperationToSelectedDocument = useCallback(
|
|
3538
|
+
async (operation) => {
|
|
3539
|
+
if (!selectedDocument) {
|
|
3540
|
+
throw new Error("No document selected");
|
|
3541
|
+
}
|
|
3542
|
+
if (!addOperationToSelectedDocument) {
|
|
3543
|
+
throw new Error("No add operation function defined");
|
|
3544
|
+
}
|
|
3545
|
+
await addOperationToSelectedDocument(operation);
|
|
3546
|
+
},
|
|
3547
|
+
[addOperationToSelectedDocument, selectedDocument]
|
|
3548
|
+
);
|
|
3549
|
+
const onDocumentChangeHandler = useCallback(
|
|
3550
|
+
(documentId, document2) => {
|
|
3551
|
+
if (documentId !== (fileNodeDocument == null ? void 0 : fileNodeDocument.documentId)) {
|
|
3552
|
+
return;
|
|
3553
|
+
}
|
|
3554
|
+
setSelectedDocument(document2);
|
|
3555
|
+
if (!!selectedNode && document2.name !== "" && selectedNode.name !== document2.name) {
|
|
3556
|
+
return renameNode(
|
|
3557
|
+
selectedNode.driveId,
|
|
3558
|
+
selectedNode.id,
|
|
3559
|
+
document2.name
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3562
|
+
},
|
|
3563
|
+
[
|
|
3564
|
+
fileNodeDocument == null ? void 0 : fileNodeDocument.documentId,
|
|
3565
|
+
renameNode,
|
|
3566
|
+
selectedNode,
|
|
3567
|
+
setSelectedDocument
|
|
3568
|
+
]
|
|
3569
|
+
);
|
|
3570
|
+
const onClose = useCallback(() => {
|
|
3571
|
+
setSelectedNode(selectedParentNode);
|
|
3572
|
+
}, [selectedParentNode, setSelectedNode]);
|
|
3573
|
+
const exportDocument = useCallback(
|
|
3574
|
+
(document2) => {
|
|
3575
|
+
const validationErrors = validateDocument(document2);
|
|
3576
|
+
if (validationErrors.length) {
|
|
3577
|
+
showModal("confirmationModal", {
|
|
3578
|
+
title: t("modals.exportDocumentWithErrors.title"),
|
|
3579
|
+
body: /* @__PURE__ */ jsxs("div", { children: [
|
|
3580
|
+
/* @__PURE__ */ jsx("p", { children: t("modals.exportDocumentWithErrors.body") }),
|
|
3581
|
+
/* @__PURE__ */ jsx("ul", { className: "mt-4 flex list-disc flex-col items-start px-4 text-xs", children: validationErrors.map((error, index) => /* @__PURE__ */ jsx("li", { children: error.message }, index)) })
|
|
3582
|
+
] }),
|
|
3583
|
+
cancelLabel: t("common.cancel"),
|
|
3584
|
+
continueLabel: t("common.export"),
|
|
3585
|
+
onCancel(closeModal) {
|
|
3586
|
+
closeModal();
|
|
3587
|
+
},
|
|
3588
|
+
onContinue(closeModal) {
|
|
3589
|
+
closeModal();
|
|
3590
|
+
return exportFile(document2, getDocumentModelModule);
|
|
3591
|
+
}
|
|
3592
|
+
});
|
|
3593
|
+
} else {
|
|
3594
|
+
return exportFile(document2, getDocumentModelModule);
|
|
3595
|
+
}
|
|
3596
|
+
},
|
|
3597
|
+
[getDocumentModelModule, showModal, t]
|
|
3598
|
+
);
|
|
3599
|
+
const onExport = useCallback(() => {
|
|
3600
|
+
if (selectedDocument) {
|
|
3601
|
+
return exportDocument(selectedDocument);
|
|
3602
|
+
}
|
|
3603
|
+
}, [exportDocument, selectedDocument]);
|
|
3604
|
+
const onOpenSwitchboardLink = useMemo(() => {
|
|
3605
|
+
return isRemoteDrive ? () => openSwitchboardLink(selectedNode) : void 0;
|
|
3606
|
+
}, [isRemoteDrive, openSwitchboardLink, selectedNode]);
|
|
3607
|
+
if (!fileNodeDocument) return null;
|
|
3608
|
+
return /* @__PURE__ */ jsx(
|
|
3609
|
+
"div",
|
|
3610
|
+
{
|
|
3611
|
+
className: "flex-1 rounded-2xl bg-gray-50 p-4",
|
|
3612
|
+
children: /* @__PURE__ */ jsx(
|
|
3613
|
+
DocumentEditor,
|
|
3614
|
+
{
|
|
3615
|
+
fileNodeDocument,
|
|
3616
|
+
document: selectedDocument,
|
|
3617
|
+
onChange: onDocumentChangeHandler,
|
|
3618
|
+
onClose,
|
|
3619
|
+
onExport,
|
|
3620
|
+
onAddOperation: handleAddOperationToSelectedDocument,
|
|
3621
|
+
onOpenSwitchboardLink
|
|
3622
|
+
}
|
|
3623
|
+
)
|
|
3624
|
+
},
|
|
3625
|
+
fileNodeDocument.documentId
|
|
3626
|
+
);
|
|
3627
|
+
}
|
|
3628
|
+
function getDocumentSpec(doc) {
|
|
3629
|
+
if ("documentModelState" in doc) {
|
|
3630
|
+
return doc.documentModelState;
|
|
3631
|
+
}
|
|
3632
|
+
return doc.documentModel;
|
|
3633
|
+
}
|
|
3634
|
+
const CreateDocument = ({ documentModels, createDocument }) => {
|
|
3635
|
+
return jsxs("div", { className: "px-6", children: [jsx("h3", { className: "mb-3 mt-4 text-xl font-bold text-gray-600", children: "New document" }), jsx("div", { className: "flex w-full flex-wrap gap-4", children: documentModels == null ? void 0 : documentModels.map((doc) => {
|
|
3636
|
+
const spec = getDocumentSpec(doc);
|
|
3637
|
+
return jsx(Button, { color: "light", "aria-details": spec.description, onClick: () => createDocument(doc), children: jsx("span", { className: "text-sm", children: spec.name }) }, spec.id);
|
|
3638
|
+
}) })] });
|
|
3639
|
+
};
|
|
3640
|
+
function sortUiNodesByName(a, b) {
|
|
3641
|
+
return a.name.localeCompare(b.name);
|
|
3642
|
+
}
|
|
3643
|
+
const GAP = 8;
|
|
3644
|
+
const ITEM_WIDTH = 256;
|
|
3645
|
+
const ITEM_HEIGHT = 48;
|
|
3646
|
+
const USED_SPACE = 420;
|
|
3647
|
+
function FileContentView(props) {
|
|
3648
|
+
const parentRef = useRef(null);
|
|
3649
|
+
const { t } = useTranslation();
|
|
3650
|
+
const windowSize = useWindowSize();
|
|
3651
|
+
const { fileNodes, ...fileProps } = props;
|
|
3652
|
+
const availableWidth = windowSize.innerWidth - USED_SPACE;
|
|
3653
|
+
const columnCount = Math.floor(availableWidth / (ITEM_WIDTH + GAP)) || 1;
|
|
3654
|
+
const rowCount = Math.ceil(fileNodes.length / columnCount);
|
|
3655
|
+
const rowVirtualizer = useVirtualizer({
|
|
3656
|
+
count: rowCount,
|
|
3657
|
+
getScrollElement: () => parentRef.current,
|
|
3658
|
+
estimateSize: (index) => {
|
|
3659
|
+
if (index > 0) {
|
|
3660
|
+
return ITEM_HEIGHT + GAP;
|
|
3661
|
+
}
|
|
3662
|
+
return ITEM_HEIGHT;
|
|
3663
|
+
},
|
|
3664
|
+
overscan: 5
|
|
3665
|
+
});
|
|
3666
|
+
const columnVirtualizer = useVirtualizer({
|
|
3667
|
+
horizontal: true,
|
|
3668
|
+
count: columnCount,
|
|
3669
|
+
getScrollElement: () => parentRef.current,
|
|
3670
|
+
estimateSize: (index) => {
|
|
3671
|
+
if (index > 0) {
|
|
3672
|
+
return ITEM_WIDTH + GAP;
|
|
3673
|
+
}
|
|
3674
|
+
return ITEM_WIDTH;
|
|
3675
|
+
},
|
|
3676
|
+
overscan: 5
|
|
3677
|
+
});
|
|
3678
|
+
const getItemIndex = (rowIndex, columnIndex) => rowIndex * columnCount + columnIndex;
|
|
3679
|
+
const getItem = (rowIndex, columnIndex) => {
|
|
3680
|
+
const index = getItemIndex(rowIndex, columnIndex);
|
|
3681
|
+
return fileNodes[index] || null;
|
|
3682
|
+
};
|
|
3683
|
+
if (fileNodes.length === 0) {
|
|
3684
|
+
return jsx("div", { className: "mb-8 text-sm text-gray-400", children: t("folderView.sections.documents.empty", {
|
|
3685
|
+
defaultValue: "No documents or files 📄"
|
|
3686
|
+
}) });
|
|
3687
|
+
}
|
|
3688
|
+
const renderItem = (rowIndex, columnIndex) => {
|
|
3689
|
+
const fileNode = getItem(rowIndex, columnIndex);
|
|
3690
|
+
if (!fileNode) {
|
|
3691
|
+
return null;
|
|
3692
|
+
}
|
|
3693
|
+
return jsx("div", { style: {
|
|
3694
|
+
marginLeft: columnIndex === 0 ? 0 : GAP
|
|
3695
|
+
}, children: jsx(FileItem, { uiNode: fileNode, ...fileProps }, fileNode.id) });
|
|
3696
|
+
};
|
|
3697
|
+
return jsx("div", { ref: parentRef, style: {
|
|
3698
|
+
height: `400px`,
|
|
3699
|
+
width: `100%`,
|
|
3700
|
+
overflow: "auto"
|
|
3701
|
+
}, children: jsx("div", { style: {
|
|
3702
|
+
height: `${rowVirtualizer.getTotalSize()}px`,
|
|
3703
|
+
width: `${columnVirtualizer.getTotalSize()}px`,
|
|
3704
|
+
position: "relative"
|
|
3705
|
+
}, children: rowVirtualizer.getVirtualItems().map((virtualRow) => jsx(React__default.Fragment, { children: columnVirtualizer.getVirtualItems().map((virtualColumn) => jsx("div", { style: {
|
|
3706
|
+
position: "absolute",
|
|
3707
|
+
top: 0,
|
|
3708
|
+
left: 0,
|
|
3709
|
+
marginTop: virtualRow.index === 0 ? 0 : GAP,
|
|
3710
|
+
width: `${virtualColumn.size}px`,
|
|
3711
|
+
height: `${virtualRow.size}px`,
|
|
3712
|
+
transform: `translateX(${virtualColumn.start}px) translateY(${virtualRow.start}px)`
|
|
3713
|
+
}, children: renderItem(virtualRow.index, virtualColumn.index) }, virtualColumn.key)) }, virtualRow.key)) }) });
|
|
3714
|
+
}
|
|
3715
|
+
function FolderView(props) {
|
|
3716
|
+
const { node, className, isDropTarget, containerProps, ...nodeProps } = props;
|
|
3717
|
+
const { t } = useTranslation();
|
|
3718
|
+
const folderNodes = node.children.filter((node2) => node2.kind === FOLDER).sort(sortUiNodesByName);
|
|
3719
|
+
const fileNodes = node.children.filter((node2) => node2.kind === FILE).sort(sortUiNodesByName);
|
|
3720
|
+
const folderCallbacks = {
|
|
3721
|
+
onSelectNode: (node2) => nodeProps.onSelectNode(node2),
|
|
3722
|
+
onRenameNode: (name, node2) => nodeProps.onRenameNode(name, node2),
|
|
3723
|
+
onDuplicateNode: (node2) => nodeProps.onDuplicateNode(node2),
|
|
3724
|
+
onDeleteNode: (node2) => nodeProps.onDeleteNode(node2)
|
|
3725
|
+
};
|
|
3726
|
+
const fileCallbacks = {
|
|
3727
|
+
onSelectNode: (node2) => nodeProps.onSelectNode(node2),
|
|
3728
|
+
onRenameNode: (name, node2) => nodeProps.onRenameNode(name, node2),
|
|
3729
|
+
onDuplicateNode: (node2) => nodeProps.onDuplicateNode(node2),
|
|
3730
|
+
onDeleteNode: (node2) => nodeProps.onDeleteNode(node2)
|
|
3731
|
+
};
|
|
3732
|
+
const baseNodeCallbacks = {
|
|
3733
|
+
onAddFile: async (file, parentNode) => {
|
|
3734
|
+
await nodeProps.onAddFile(file, parentNode);
|
|
3735
|
+
},
|
|
3736
|
+
onCopyNode: async (uiNode, targetNode) => {
|
|
3737
|
+
await nodeProps.onCopyNode(uiNode, targetNode);
|
|
3738
|
+
},
|
|
3739
|
+
onMoveNode: async (uiNode, targetNode) => {
|
|
3740
|
+
await nodeProps.onMoveNode(uiNode, targetNode);
|
|
3741
|
+
}
|
|
3742
|
+
};
|
|
3743
|
+
return jsxs("div", { className: twMerge("rounded-md border-2 border-transparent p-2", isDropTarget && "border-dashed border-blue-100", className), ...containerProps, children: [jsx(DriveLayout.ContentSection, { title: t("folderView.sections.folders.title", {
|
|
3744
|
+
defaultValue: "Folders"
|
|
3745
|
+
}), className: "mb-4", children: folderNodes.length > 0 ? folderNodes.map((folderNode) => jsx(FolderItem, { uiNode: folderNode, ...baseNodeCallbacks, ...folderCallbacks, isAllowedToCreateDocuments: nodeProps.isAllowedToCreateDocuments }, folderNode.id)) : jsx("div", { className: "mb-8 text-sm text-gray-400", children: t("folderView.sections.folders.empty", {
|
|
3746
|
+
defaultValue: "No documents or files 📄"
|
|
3747
|
+
}) }) }), jsx(DriveLayout.ContentSection, { title: t("folderView.sections.documents.title", {
|
|
3748
|
+
defaultValue: "Documents and files"
|
|
3749
|
+
}), children: jsx("div", { className: twMerge("w-full", fileNodes.length > 0 ? "min-h-[400px]" : "min-h-14"), children: jsx(FileContentView, { fileNodes, ...fileCallbacks, isAllowedToCreateDocuments: nodeProps.isAllowedToCreateDocuments }) }) })] });
|
|
3750
|
+
}
|
|
3751
|
+
function Editor(props) {
|
|
3752
|
+
const { document: document2, dispatch, className, children } = props;
|
|
3753
|
+
const { state: { global: { id: driveId } } } = document2;
|
|
3754
|
+
const { showSearchBar, isAllowedToCreateDocuments, documentModels, showCreateDocumentModal } = useDriveContext();
|
|
3755
|
+
const { driveNodes, selectedNode, selectedNodePath, getNodeById, setSelectedNode } = useUiNodesContext();
|
|
3756
|
+
const driveNode = useMemo(() => driveNodes.find((n) => n.id === driveId), [driveNodes, driveId]);
|
|
3757
|
+
const { addDocument, addFile, addFolder, renameNode, deleteNode, moveNode, copyNode, duplicateNode } = useDriveActionsWithUiNodes(document2, dispatch);
|
|
3758
|
+
const onCreateDocument = useCallback(async (documentModel) => {
|
|
3759
|
+
const { name } = await showCreateDocumentModal(documentModel);
|
|
3760
|
+
const document3 = documentModel.utils.createDocument();
|
|
3761
|
+
await addDocument(name, documentModel.documentModel.name, document3, selectedNode == null ? void 0 : selectedNode.id);
|
|
3762
|
+
}, [addDocument, showCreateDocumentModal, selectedNode == null ? void 0 : selectedNode.id]);
|
|
3763
|
+
const { isDropTarget, dropProps } = useDrop({
|
|
3764
|
+
uiNode: selectedNode,
|
|
3765
|
+
onAddFile: addFile,
|
|
3766
|
+
onCopyNode: copyNode,
|
|
3767
|
+
onMoveNode: moveNode
|
|
3768
|
+
});
|
|
3769
|
+
const { breadcrumbs, onBreadcrumbSelected } = useBreadcrumbs({
|
|
3770
|
+
selectedNodePath,
|
|
3771
|
+
getNodeById,
|
|
3772
|
+
setSelectedNode
|
|
3773
|
+
});
|
|
3774
|
+
if (!driveNode) {
|
|
3775
|
+
return jsx("div", { children: "Drive not found" });
|
|
3776
|
+
} else if ((selectedNode == null ? void 0 : selectedNode.kind) === FILE$1) {
|
|
3777
|
+
return jsx(Fragment$1, {});
|
|
3778
|
+
}
|
|
3779
|
+
return jsxs(DriveLayout, { className, children: [children, jsxs(DriveLayout.Header, { children: [jsx(Breadcrumbs, { breadcrumbs, createEnabled: isAllowedToCreateDocuments, onCreate: addFolder, onBreadcrumbSelected }), showSearchBar && jsx(SearchBar, {})] }), jsx(DriveLayout.Content, { children: jsx(FolderView, { node: selectedNode || driveNode, onSelectNode: setSelectedNode, onRenameNode: renameNode, onDuplicateNode: duplicateNode, onDeleteNode: deleteNode, onAddFile: addFile, onCopyNode: copyNode, onMoveNode: moveNode, isDropTarget, isAllowedToCreateDocuments }) }), jsx(DriveLayout.Footer, { children: isAllowedToCreateDocuments && jsx(CreateDocument, { documentModels, createDocument: onCreateDocument }) })] });
|
|
3780
|
+
}
|
|
3781
|
+
const GenericDriveExplorer = {
|
|
3782
|
+
Component: Editor
|
|
3783
|
+
};
|
|
3784
|
+
function useGetDriveDocuments(props) {
|
|
3785
|
+
const { driveId } = props;
|
|
3786
|
+
const [documents, setDocuments] = useState({});
|
|
3787
|
+
const { getDocumentsIds, onStrandUpdate, openFile } = useDocumentDriveServer();
|
|
3788
|
+
const fetchDocuments = async (_driveId, _documentIds) => {
|
|
3789
|
+
let documentIds = _documentIds;
|
|
3790
|
+
if (!documentIds || documentIds.length === 0) {
|
|
3791
|
+
documentIds = await getDocumentsIds(_driveId);
|
|
3792
|
+
}
|
|
3793
|
+
const getDocumentsPromise = documentIds.map(async (documentId) => {
|
|
3794
|
+
const document2 = await openFile(_driveId, documentId);
|
|
3795
|
+
return [documentId, document2];
|
|
3796
|
+
});
|
|
3797
|
+
const docs = await Promise.all(getDocumentsPromise);
|
|
3798
|
+
const newDocumentsState = docs.reduce(
|
|
3799
|
+
(acc, [documentId, document2]) => {
|
|
3800
|
+
acc[documentId] = {
|
|
3801
|
+
...document2.state,
|
|
3802
|
+
documentType: document2.documentType,
|
|
3803
|
+
revision: document2.revision,
|
|
3804
|
+
created: document2.created,
|
|
3805
|
+
lastModified: document2.lastModified
|
|
3806
|
+
};
|
|
3807
|
+
return acc;
|
|
3808
|
+
},
|
|
3809
|
+
{}
|
|
3810
|
+
);
|
|
3811
|
+
setDocuments((prevState) => ({
|
|
3812
|
+
...prevState,
|
|
3813
|
+
...newDocumentsState
|
|
3814
|
+
}));
|
|
3815
|
+
};
|
|
3816
|
+
useEffect(() => {
|
|
3817
|
+
if (driveId) {
|
|
3818
|
+
fetchDocuments(driveId).catch(console.error);
|
|
3819
|
+
}
|
|
3820
|
+
}, [driveId]);
|
|
3821
|
+
useEffect(() => {
|
|
3822
|
+
const removeListener = onStrandUpdate((update) => {
|
|
3823
|
+
if (driveId && update.driveId === driveId && update.documentId) {
|
|
3824
|
+
fetchDocuments(driveId, [update.documentId]).catch(
|
|
3825
|
+
console.error
|
|
3826
|
+
);
|
|
3827
|
+
}
|
|
3828
|
+
});
|
|
3829
|
+
return removeListener;
|
|
3830
|
+
}, [onStrandUpdate, driveId]);
|
|
3831
|
+
return [documents, fetchDocuments];
|
|
3832
|
+
}
|
|
3833
|
+
function DriveEditorError({ error }) {
|
|
3834
|
+
return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex max-w-[80%] flex-1 flex-col items-center justify-center", children: [
|
|
3835
|
+
/* @__PURE__ */ jsx("h1", { className: "mb-2 text-xl font-semibold", children: "Error" }),
|
|
3836
|
+
/* @__PURE__ */ jsx("i", { children: error instanceof Error ? error.message : error }),
|
|
3837
|
+
/* @__PURE__ */ jsx("pre", { children: JSON.stringify(error, null, 2) })
|
|
3838
|
+
] });
|
|
3839
|
+
}
|
|
3840
|
+
function useSelectedDocumentDrive() {
|
|
3841
|
+
const { selectedDriveNode } = useUiNodesContext();
|
|
3842
|
+
if (!selectedDriveNode) {
|
|
3843
|
+
throw new Error("No drive node selected");
|
|
3844
|
+
}
|
|
3845
|
+
const documentDrive = useDocumentDriveById(selectedDriveNode.id);
|
|
3846
|
+
if (!documentDrive.drive) {
|
|
3847
|
+
throw new Error(`Drive with id "${selectedDriveNode.id}" not found`);
|
|
3848
|
+
}
|
|
3849
|
+
return documentDrive.drive;
|
|
3850
|
+
}
|
|
3851
|
+
function DriveEditorContainer() {
|
|
3852
|
+
var _a;
|
|
3853
|
+
const {
|
|
3854
|
+
selectedDriveNode,
|
|
3855
|
+
setSelectedNode,
|
|
3856
|
+
selectedNode,
|
|
3857
|
+
selectedParentNode
|
|
3858
|
+
} = useUiNodesContext();
|
|
3859
|
+
const { addOperationToSelectedDrive } = useUiNodes();
|
|
3860
|
+
const documentDrive = useSelectedDocumentDrive();
|
|
3861
|
+
const [document2, _dispatch, error] = useDocumentDispatch(
|
|
3862
|
+
driveDocumentModelModule.reducer,
|
|
3863
|
+
documentDrive
|
|
3864
|
+
);
|
|
3865
|
+
const reactor = useAsyncReactor();
|
|
3866
|
+
const handleAddOperationToSelectedDrive = useCallback(
|
|
3867
|
+
async (operation) => {
|
|
3868
|
+
await addOperationToSelectedDrive(operation);
|
|
3869
|
+
},
|
|
3870
|
+
[addOperationToSelectedDrive]
|
|
3871
|
+
);
|
|
3872
|
+
const editorProps = useEditorProps(
|
|
3873
|
+
document2,
|
|
3874
|
+
selectedDriveNode,
|
|
3875
|
+
_dispatch,
|
|
3876
|
+
handleAddOperationToSelectedDrive
|
|
3877
|
+
);
|
|
3878
|
+
const { showModal } = useModal();
|
|
3879
|
+
const showCreateDocumentModal = useCallback(
|
|
3880
|
+
(documentModel) => {
|
|
3881
|
+
if (!selectedDriveNode) {
|
|
3882
|
+
throw new Error("No drive node selected");
|
|
3883
|
+
}
|
|
3884
|
+
showModal("createDocument", {
|
|
3885
|
+
documentModel,
|
|
3886
|
+
selectedParentNode,
|
|
3887
|
+
setSelectedNode
|
|
3888
|
+
});
|
|
3889
|
+
return Promise.resolve({ name: "New Document" });
|
|
3890
|
+
},
|
|
3891
|
+
[selectedDriveNode, selectedParentNode, setSelectedNode, showModal]
|
|
3892
|
+
);
|
|
3893
|
+
const { addFile, addDocument } = useDocumentDriveServer();
|
|
3894
|
+
const documentModels = useFilteredDocumentModels();
|
|
3895
|
+
const useDriveDocumentState = makeDriveDocumentStateHook(reactor);
|
|
3896
|
+
const driveContext = useMemo(
|
|
3897
|
+
() => ({
|
|
3898
|
+
showSearchBar: false,
|
|
3899
|
+
isAllowedToCreateDocuments: editorProps.isAllowedToCreateDocuments,
|
|
3900
|
+
documentModels: documentModels ?? [],
|
|
3901
|
+
selectedDriveNode,
|
|
3902
|
+
selectedNode,
|
|
3903
|
+
selectNode: setSelectedNode,
|
|
3904
|
+
addFile,
|
|
3905
|
+
showCreateDocumentModal,
|
|
3906
|
+
useSyncStatus,
|
|
3907
|
+
useDocumentEditorProps: useDocumentEditor,
|
|
3908
|
+
useDriveDocumentStates: useGetDriveDocuments,
|
|
3909
|
+
useDriveDocumentState,
|
|
3910
|
+
addDocument
|
|
3911
|
+
}),
|
|
3912
|
+
[
|
|
3913
|
+
reactor,
|
|
3914
|
+
editorProps.isAllowedToCreateDocuments,
|
|
3915
|
+
documentModels,
|
|
3916
|
+
selectedNode,
|
|
3917
|
+
setSelectedNode,
|
|
3918
|
+
addFile,
|
|
3919
|
+
addDocument,
|
|
3920
|
+
showCreateDocumentModal
|
|
3921
|
+
]
|
|
3922
|
+
);
|
|
3923
|
+
const driveEditor = useDriveEditor((_a = document2 == null ? void 0 : document2.meta) == null ? void 0 : _a.preferredEditor);
|
|
3924
|
+
if (!document2) {
|
|
3925
|
+
return null;
|
|
3926
|
+
}
|
|
3927
|
+
const DriveEditorComponent = (driveEditor == null ? void 0 : driveEditor.Component) ?? GenericDriveExplorer.Component;
|
|
3928
|
+
return /* @__PURE__ */ jsx(DriveContextProvider, { value: driveContext, children: /* @__PURE__ */ jsx(
|
|
3929
|
+
ErrorBoundary,
|
|
3930
|
+
{
|
|
3931
|
+
fallbackRender: DriveEditorError,
|
|
3932
|
+
children: /* @__PURE__ */ jsx(
|
|
3933
|
+
DriveEditorComponent,
|
|
3934
|
+
{
|
|
3935
|
+
...editorProps,
|
|
3936
|
+
onSwitchboardLinkClick: void 0,
|
|
3937
|
+
document: document2,
|
|
3938
|
+
error
|
|
3939
|
+
},
|
|
3940
|
+
selectedDriveNode == null ? void 0 : selectedDriveNode.id
|
|
3941
|
+
)
|
|
3942
|
+
},
|
|
3943
|
+
selectedDriveNode == null ? void 0 : selectedDriveNode.id
|
|
3944
|
+
) }, selectedDriveNode == null ? void 0 : selectedDriveNode.id);
|
|
3945
|
+
}
|
|
3946
|
+
function Content() {
|
|
3947
|
+
const uiNodes = useUiNodes();
|
|
3948
|
+
const { fileNodeDocument, selectedDriveNode, selectedNode, addFile } = uiNodes;
|
|
3949
|
+
useEffect(() => {
|
|
3950
|
+
var _a;
|
|
3951
|
+
return (_a = window.electronAPI) == null ? void 0 : _a.handleFileOpen(async (file) => {
|
|
3952
|
+
if (!selectedDriveNode || (selectedNode == null ? void 0 : selectedNode.kind) !== FILE) {
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3955
|
+
await addFile(
|
|
3956
|
+
file.content,
|
|
3957
|
+
selectedDriveNode.id,
|
|
3958
|
+
file.name,
|
|
3959
|
+
selectedNode.parentFolder
|
|
3960
|
+
);
|
|
3961
|
+
});
|
|
3962
|
+
}, [selectedDriveNode, selectedNode, addFile]);
|
|
3963
|
+
return /* @__PURE__ */ jsx("div", { className: "flex h-full flex-col overflow-hidden", id: "content-view", children: fileNodeDocument ? /* @__PURE__ */ jsx(DocumentEditorContainer, {}, fileNodeDocument.documentId) : selectedDriveNode ? /* @__PURE__ */ jsx(DriveEditorContainer, {}, selectedDriveNode.id) : null });
|
|
3964
|
+
}
|
|
3965
|
+
export {
|
|
3966
|
+
Content as default
|
|
3967
|
+
};
|