@backmatter/studio 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/UiKitPage-CgNMOqfE.js +172 -0
- package/dist/chunks/WorkspaceRoutes-DgRtdie8.js +87297 -0
- package/dist/chunks/abap-Y8Dl9g_6.js +6 -0
- package/dist/chunks/actionscript-3-DQVEcJUW.js +6 -0
- package/dist/chunks/ada-vP6ak0IW.js +6 -0
- package/dist/chunks/andromeeda-BbmzSJq1.js +4 -0
- package/dist/chunks/angular-html-DPB4Rf0C.js +32 -0
- package/dist/chunks/angular-ts-CTOR2ofC.js +21 -0
- package/dist/chunks/apache-BUjz-sD2.js +6 -0
- package/dist/chunks/apex-OyTfjCYK.js +6 -0
- package/dist/chunks/apl-CjNiDgad.js +16 -0
- package/dist/chunks/applescript-BPx7YFFu.js +6 -0
- package/dist/chunks/ara-Z2fSOxSw.js +6 -0
- package/dist/chunks/asciidoc-C1T9ziH6.js +6 -0
- package/dist/chunks/asm-BTWLY5ym.js +6 -0
- package/dist/chunks/astro-CFFExE8Q.js +18 -0
- package/dist/chunks/aurora-x-BwoVEUWZ.js +4 -0
- package/dist/chunks/awk-Fb0P9dkn.js +6 -0
- package/dist/chunks/ayu-dark-DJoqd4M9.js +4 -0
- package/dist/chunks/ayu-light-BzXEJRJ-.js +4 -0
- package/dist/chunks/ayu-mirage-BJ2oZGzi.js +4 -0
- package/dist/chunks/ballerina-oZK-YekG.js +6 -0
- package/dist/chunks/bat-0FvbqU9S.js +6 -0
- package/dist/chunks/beancount-DqJEb89h.js +6 -0
- package/dist/chunks/berry-DODBq_Ff.js +6 -0
- package/dist/chunks/bibtex-EULQRLY5.js +6 -0
- package/dist/chunks/bicep-BorU73w0.js +6 -0
- package/dist/chunks/bird2-CIjBSNj3.js +6 -0
- package/dist/chunks/blade-D0HyNvCw.js +20 -0
- package/dist/chunks/bsl-NkNNwerW.js +8 -0
- package/dist/chunks/c-eeMepfLm.js +6 -0
- package/dist/chunks/c3-BY5XW5ym.js +6 -0
- package/dist/chunks/cadence-02UX7mW8.js +6 -0
- package/dist/chunks/cairo-DM6WF2e3.js +8 -0
- package/dist/chunks/catppuccin-frappe-D3cH2rXe.js +4 -0
- package/dist/chunks/catppuccin-latte-C0LRGUW4.js +4 -0
- package/dist/chunks/catppuccin-macchiato-c5wQ11TT.js +4 -0
- package/dist/chunks/catppuccin-mocha-WMD6Qvya.js +4 -0
- package/dist/chunks/clarity-PKm5CwqM.js +6 -0
- package/dist/chunks/clojure-CXJfHrL3.js +6 -0
- package/dist/chunks/cmake-BJz8BOTU.js +6 -0
- package/dist/chunks/cobol-HihOMwht.js +10 -0
- package/dist/chunks/codeowners-Bt9yU6NX.js +6 -0
- package/dist/chunks/codeql-DHkodjjI.js +6 -0
- package/dist/chunks/coffee-DGBR_nr_.js +8 -0
- package/dist/chunks/common-lisp-EVqT9Zhp.js +6 -0
- package/dist/chunks/coq-B0L9upzn.js +6 -0
- package/dist/chunks/cpp-Cj177cuW.js +18 -0
- package/dist/chunks/crystal-CRJyc4G-.js +18 -0
- package/dist/chunks/csharp-CCgA4A09.js +6 -0
- package/dist/chunks/css-CECN5uSL.js +6 -0
- package/dist/chunks/csv-CmYOceLb.js +6 -0
- package/dist/chunks/cue-ZzumE7IT.js +6 -0
- package/dist/chunks/cypher-jpdmjtA6.js +6 -0
- package/dist/chunks/d-CBagWSwH.js +6 -0
- package/dist/chunks/dark-plus-pUHDTVV0.js +4 -0
- package/dist/chunks/dart-6ObCrKr9.js +6 -0
- package/dist/chunks/dashboard-XKKZuJGm.js +1736 -0
- package/dist/chunks/dax-CcDT-8dH.js +6 -0
- package/dist/chunks/define-studio-BYtYDGLX.js +33 -0
- package/dist/chunks/desktop-B93p9R9O.js +6 -0
- package/dist/chunks/diff-BxzP2J8R.js +6 -0
- package/dist/chunks/docker-CsHqm9tx.js +6 -0
- package/dist/chunks/dotenv-BMjVjUL1.js +6 -0
- package/dist/chunks/dracula-BtZx2Kac.js +4 -0
- package/dist/chunks/dracula-soft-BKa-aqBv.js +4 -0
- package/dist/chunks/dream-maker-PAx17jaB.js +6 -0
- package/dist/chunks/edge-BYQkOzbF.js +12 -0
- package/dist/chunks/elixir-Dh036GMp.js +8 -0
- package/dist/chunks/elm-BtNbw_Cd.js +8 -0
- package/dist/chunks/emacs-lisp-Cfxdx5D-.js +6 -0
- package/dist/chunks/erb-ScVOXVpH.js +10 -0
- package/dist/chunks/erlang-DNcDT8Hi.js +8 -0
- package/dist/chunks/everforest-dark-DMCBqXCK.js +4 -0
- package/dist/chunks/everforest-light-BbXl82Em.js +4 -0
- package/dist/chunks/fennel-N4WcXuKx.js +6 -0
- package/dist/chunks/fish-BTDEUgqH.js +6 -0
- package/dist/chunks/fluent-BMXUxfv1.js +6 -0
- package/dist/chunks/fortran-fixed-form-B67KFkXH.js +8 -0
- package/dist/chunks/fortran-free-form-CwqYvCLJ.js +6 -0
- package/dist/chunks/fsharp-CYOiIVNx.js +8 -0
- package/dist/chunks/gdresource-CvCIUjhi.js +10 -0
- package/dist/chunks/gdscript-DSAxJ_aS.js +6 -0
- package/dist/chunks/gdshader-Bk8fF6yr.js +6 -0
- package/dist/chunks/genie-DzUvd7U9.js +6 -0
- package/dist/chunks/gherkin-DHRaV0YP.js +6 -0
- package/dist/chunks/git-commit-Bd32YZ0K.js +8 -0
- package/dist/chunks/git-rebase-ZWUFO_T4.js +8 -0
- package/dist/chunks/github-dark-DenFmJkN.js +4 -0
- package/dist/chunks/github-dark-default-BJPUVz4H.js +4 -0
- package/dist/chunks/github-dark-dimmed-DUshB20C.js +4 -0
- package/dist/chunks/github-dark-high-contrast-D3aGCnF8.js +4 -0
- package/dist/chunks/github-light-JYsPkUQd.js +4 -0
- package/dist/chunks/github-light-default-D99KPAby.js +4 -0
- package/dist/chunks/github-light-high-contrast-BbmZE-Mp.js +4 -0
- package/dist/chunks/gleam-Bv284lvN.js +6 -0
- package/dist/chunks/glimmer-js-DkxNrfPT.js +14 -0
- package/dist/chunks/glimmer-ts-D6YZEmK_.js +14 -0
- package/dist/chunks/glsl-CkUcVZNK.js +8 -0
- package/dist/chunks/gn-XtJxiLa4.js +6 -0
- package/dist/chunks/gnuplot-yPG9-sE_.js +6 -0
- package/dist/chunks/go-CvFNMTvu.js +6 -0
- package/dist/chunks/graphql-CBu2ehBn.js +14 -0
- package/dist/chunks/groovy-CJQTphOW.js +6 -0
- package/dist/chunks/gruvbox-dark-hard-C5HOtKIh.js +4 -0
- package/dist/chunks/gruvbox-dark-medium-FVgwJHuz.js +4 -0
- package/dist/chunks/gruvbox-dark-soft-B46F314v.js +4 -0
- package/dist/chunks/gruvbox-light-hard-CJD38wDZ.js +4 -0
- package/dist/chunks/gruvbox-light-medium-BlIhMYTA.js +4 -0
- package/dist/chunks/gruvbox-light-soft-DoPHyLVZ.js +4 -0
- package/dist/chunks/hack-ItRNKiEb.js +10 -0
- package/dist/chunks/haml-NZLVzu_R.js +10 -0
- package/dist/chunks/handlebars-mxStpSE7.js +14 -0
- package/dist/chunks/haskell-WeIwNIP6.js +6 -0
- package/dist/chunks/haxe-TztHsm5T.js +6 -0
- package/dist/chunks/hcl-D438OF-I.js +6 -0
- package/dist/chunks/hjson-DYBUbqOl.js +6 -0
- package/dist/chunks/hlsl-Bk8TCZNL.js +6 -0
- package/dist/chunks/horizon-CJQ10nlf.js +4 -0
- package/dist/chunks/horizon-bright-CdkBZOMB.js +4 -0
- package/dist/chunks/houston-BDYrDoDW.js +4 -0
- package/dist/chunks/html-B50bmoVb.js +10 -0
- package/dist/chunks/html-derivative-C6bxFbFW.js +8 -0
- package/dist/chunks/http-DLvAkeD-.js +14 -0
- package/dist/chunks/hurl-CgkFN90t.js +12 -0
- package/dist/chunks/hxml-GbqSQCLa.js +8 -0
- package/dist/chunks/hy-Brt5EZ7-.js +6 -0
- package/dist/chunks/imba-CimUv-Uh.js +6 -0
- package/dist/chunks/index-CFAIR8GH.js +18924 -0
- package/dist/chunks/ini-BZIuRIvJ.js +6 -0
- package/dist/chunks/java-DY6VlHhP.js +6 -0
- package/dist/chunks/javascript-C25yR2R2.js +6 -0
- package/dist/chunks/jinja-CFW5uAwY.js +11 -0
- package/dist/chunks/jison-DdreslRX.js +8 -0
- package/dist/chunks/json-DxJze_jm.js +6 -0
- package/dist/chunks/json5-BT4Fjg39.js +6 -0
- package/dist/chunks/jsonc-CHjZD8gR.js +6 -0
- package/dist/chunks/jsonl-BGuvDmy9.js +6 -0
- package/dist/chunks/jsonnet-Bx2cfsXg.js +6 -0
- package/dist/chunks/jssm-BcADi6EI.js +6 -0
- package/dist/chunks/jsx-BtKADgXT.js +6 -0
- package/dist/chunks/julia-CZiKXNNP.js +16 -0
- package/dist/chunks/just-CEK2SJ_k.js +18 -0
- package/dist/chunks/kanagawa-dragon-CiKur4Hl.js +4 -0
- package/dist/chunks/kanagawa-lotus-BKu-smKu.js +4 -0
- package/dist/chunks/kanagawa-wave-CQwozSzG.js +4 -0
- package/dist/chunks/kdl-BNOv9TC3.js +6 -0
- package/dist/chunks/kotlin-ByBMgTeR.js +6 -0
- package/dist/chunks/kusto-DH_XitHS.js +6 -0
- package/dist/chunks/laserwave-6a00oqik.js +4 -0
- package/dist/chunks/latex-B8Egmqc5.js +8 -0
- package/dist/chunks/lean-BnVxaZxY.js +6 -0
- package/dist/chunks/less-B1GLI2Di.js +6 -0
- package/dist/chunks/light-plus-CZuVqSLX.js +4 -0
- package/dist/chunks/liquid-CHzkx3jT.js +14 -0
- package/dist/chunks/llvm-Bk2XctFf.js +6 -0
- package/dist/chunks/log-Al8wyEFV.js +6 -0
- package/dist/chunks/logo-DBa4JDzV.js +6 -0
- package/dist/chunks/lua-Bp3IRv7I.js +8 -0
- package/dist/chunks/luau-UQyhudEE.js +6 -0
- package/dist/chunks/make-CsMclxtr.js +6 -0
- package/dist/chunks/markdown-CrScaQ96.js +6 -0
- package/dist/chunks/marko-CJBA24Ri.js +14 -0
- package/dist/chunks/material-theme-D6KBX41T.js +4 -0
- package/dist/chunks/material-theme-darker-CkRroheE.js +4 -0
- package/dist/chunks/material-theme-lighter-BUBw43Yz.js +4 -0
- package/dist/chunks/material-theme-ocean-ClGX14Ja.js +4 -0
- package/dist/chunks/material-theme-palenight-C1RVm8K1.js +4 -0
- package/dist/chunks/matlab-BOAaUVP0.js +6 -0
- package/dist/chunks/mdc-C9YSUwVC.js +12 -0
- package/dist/chunks/mdx-BOhZZUJ8.js +6 -0
- package/dist/chunks/mermaid-C3rz4dYh.js +6 -0
- package/dist/chunks/min-dark-C7ak0t6c.js +4 -0
- package/dist/chunks/min-light-CKFxVcPp.js +4 -0
- package/dist/chunks/mipsasm-CTx18fBl.js +6 -0
- package/dist/chunks/mojo-EIZIZRTQ.js +6 -0
- package/dist/chunks/monokai-C1KBYcO0.js +4 -0
- package/dist/chunks/moonbit-B1TV0fG3.js +6 -0
- package/dist/chunks/move-Db4ltDq1.js +6 -0
- package/dist/chunks/narrat-DmhDCBs-.js +6 -0
- package/dist/chunks/nextflow-47kAzSl1.js +8 -0
- package/dist/chunks/nextflow-groovy-Drz_2V0j.js +6 -0
- package/dist/chunks/nginx-D7O4WoB1.js +8 -0
- package/dist/chunks/night-owl-Bm2rzalh.js +4 -0
- package/dist/chunks/night-owl-light-CBI5u5kw.js +4 -0
- package/dist/chunks/nim-QAjRdh9w.js +20 -0
- package/dist/chunks/nix-fTRXMGic.js +9 -0
- package/dist/chunks/nord-CC5OiUXg.js +4 -0
- package/dist/chunks/nushell-BGCPRlV5.js +6 -0
- package/dist/chunks/objective-c-Itk8tzmv.js +6 -0
- package/dist/chunks/objective-cpp-DGt5UKRO.js +6 -0
- package/dist/chunks/ocaml-eSVK32Eg.js +6 -0
- package/dist/chunks/odin-BItnF517.js +6 -0
- package/dist/chunks/one-dark-pro-DTA3VF0_.js +4 -0
- package/dist/chunks/one-light-LkMrt1Cf.js +4 -0
- package/dist/chunks/openscad-Sp5uZ6f2.js +6 -0
- package/dist/chunks/pascal-xy8pJNns.js +6 -0
- package/dist/chunks/perl-DkVrgJBg.js +16 -0
- package/dist/chunks/php-BIzsF_5x.js +18 -0
- package/dist/chunks/pkl-C-zSNmaA.js +6 -0
- package/dist/chunks/plastic-CSTz3KZp.js +4 -0
- package/dist/chunks/plsql-pVbGZfOv.js +6 -0
- package/dist/chunks/po-BNfHvqmm.js +6 -0
- package/dist/chunks/poimandres-C-VADXHD.js +4 -0
- package/dist/chunks/polar-CAZahv3u.js +6 -0
- package/dist/chunks/postcss-05aHdL-n.js +6 -0
- package/dist/chunks/powerquery-DI9HkTvs.js +6 -0
- package/dist/chunks/powershell-Clc4ydu-.js +6 -0
- package/dist/chunks/prisma-FZjmVtSl.js +6 -0
- package/dist/chunks/prolog-C5-yg4TO.js +6 -0
- package/dist/chunks/proto-C7QgialS.js +6 -0
- package/dist/chunks/pug-XOw9Q1Ho.js +12 -0
- package/dist/chunks/puppet-CUJHmnxV.js +6 -0
- package/dist/chunks/purescript-rUfGld-4.js +6 -0
- package/dist/chunks/python-BFNSHbwJ.js +6 -0
- package/dist/chunks/qml-rTNXsquU.js +8 -0
- package/dist/chunks/qmldir-BInDYbpo.js +6 -0
- package/dist/chunks/qss-AeJTysr_.js +6 -0
- package/dist/chunks/r-CSmzDPi7.js +6 -0
- package/dist/chunks/racket-B83wSAja.js +6 -0
- package/dist/chunks/raku-nEQ4ZJJ7.js +6 -0
- package/dist/chunks/razor-Ci8D0dQK.js +10 -0
- package/dist/chunks/red-7y8PH7HH.js +4 -0
- package/dist/chunks/reg-m_s_Kiip.js +6 -0
- package/dist/chunks/regexp-BazyLpPg.js +6 -0
- package/dist/chunks/rel-BcRfyd6Q.js +6 -0
- package/dist/chunks/riscv-Ce8MAQLP.js +6 -0
- package/dist/chunks/ron-DCEEQypA.js +6 -0
- package/dist/chunks/rose-pine-BKc3yVeu.js +4 -0
- package/dist/chunks/rose-pine-dawn-BulJcPZT.js +4 -0
- package/dist/chunks/rose-pine-moon-j6jiXKV8.js +4 -0
- package/dist/chunks/rosmsg-Cz0w1km8.js +6 -0
- package/dist/chunks/rst-DM32Wy3O.js +22 -0
- package/dist/chunks/ruby-BeqCs27h.js +30 -0
- package/dist/chunks/rust-CLzF9zIN.js +6 -0
- package/dist/chunks/sas-fpEvgATw.js +8 -0
- package/dist/chunks/sass-DxHp5rTx.js +6 -0
- package/dist/chunks/scala-D4grkFkl.js +6 -0
- package/dist/chunks/scheme-BCRWuEm4.js +6 -0
- package/dist/chunks/scss-B1FaCqwR.js +8 -0
- package/dist/chunks/sdbl-B7T8abf4.js +6 -0
- package/dist/chunks/shaderlab-Cr62-Wb4.js +8 -0
- package/dist/chunks/shellscript-InADTalH.js +6 -0
- package/dist/chunks/shellsession-DiDJNQdy.js +8 -0
- package/dist/chunks/slack-dark-i7wN4OET.js +4 -0
- package/dist/chunks/slack-ochin-ndHf0LoP.js +4 -0
- package/dist/chunks/smalltalk-BlI1_OkM.js +6 -0
- package/dist/chunks/snazzy-light-BlSJXAu4.js +4 -0
- package/dist/chunks/solarized-dark-UTmkh7lw.js +4 -0
- package/dist/chunks/solarized-light-BheCkDPT.js +4 -0
- package/dist/chunks/solidity-DUWnFhS6.js +6 -0
- package/dist/chunks/soy-C1-6njHa.js +8 -0
- package/dist/chunks/sparql-B0KWFEri.js +8 -0
- package/dist/chunks/splunk-CRXR8A9s.js +6 -0
- package/dist/chunks/sql-Cn_v3PB0.js +6 -0
- package/dist/chunks/ssh-config-DP-hNVbF.js +6 -0
- package/dist/chunks/stata-B8c5fTjX.js +8 -0
- package/dist/chunks/stylus-CyKEU1Ej.js +6 -0
- package/dist/chunks/surrealql-CQi7GQN7.js +8 -0
- package/dist/chunks/svelte-rYri41WT.js +14 -0
- package/dist/chunks/swift-DJpUqPLg.js +6 -0
- package/dist/chunks/synthwave-84-NU3C_KFZ.js +4 -0
- package/dist/chunks/system-verilog-BCm7smPJ.js +6 -0
- package/dist/chunks/systemd-C-4qm6XH.js +6 -0
- package/dist/chunks/talonscript-CFF3LF_O.js +6 -0
- package/dist/chunks/tasl-Cg_WBUAe.js +6 -0
- package/dist/chunks/tcl-DN7buRTF.js +6 -0
- package/dist/chunks/templ-Crs9Ui8q.js +12 -0
- package/dist/chunks/terraform-DGvcn9zM.js +6 -0
- package/dist/chunks/tex-AHxmLTL0.js +8 -0
- package/dist/chunks/tokyo-night-DP4TmcQl.js +4 -0
- package/dist/chunks/toml-DY62mUL_.js +6 -0
- package/dist/chunks/ts-tags-ioVe2PKw.js +41 -0
- package/dist/chunks/tsv-BtvSkaG0.js +6 -0
- package/dist/chunks/tsx-B8rCNbgL.js +6 -0
- package/dist/chunks/turtle-_H59FV7D.js +6 -0
- package/dist/chunks/twig-DwV2Fi4L.js +18 -0
- package/dist/chunks/typescript-RycA9KXf.js +6 -0
- package/dist/chunks/typespec-DWqp-kUU.js +6 -0
- package/dist/chunks/typst-D_1QKWns.js +6 -0
- package/dist/chunks/v-BPCNiyYe.js +6 -0
- package/dist/chunks/vala-uxaPR7d1.js +6 -0
- package/dist/chunks/vb-D8_c5-KN.js +6 -0
- package/dist/chunks/verilog-B-bybjPF.js +6 -0
- package/dist/chunks/vesper-BckBta1U.js +4 -0
- package/dist/chunks/vhdl-CUlNa8ac.js +6 -0
- package/dist/chunks/viml-DsfA-sWm.js +6 -0
- package/dist/chunks/vitesse-black-BoGvW84i.js +4 -0
- package/dist/chunks/vitesse-dark-Cym-eLtO.js +4 -0
- package/dist/chunks/vitesse-light-CcmG315c.js +4 -0
- package/dist/chunks/vue-DXEmyXn9.js +31 -0
- package/dist/chunks/vue-html-j9xNEdu3.js +8 -0
- package/dist/chunks/vue-vine-D41-N99t.js +18 -0
- package/dist/chunks/vyper-CPQuu50u.js +6 -0
- package/dist/chunks/wasm-BBXxrAl7.js +6 -0
- package/dist/chunks/wasm-DQxwEHae.js +7 -0
- package/dist/chunks/wenyan-pbVjoM9_.js +6 -0
- package/dist/chunks/wgsl-DY4iK1q1.js +6 -0
- package/dist/chunks/wikitext-Z-MoUasO.js +6 -0
- package/dist/chunks/wit-CQMQOlTg.js +6 -0
- package/dist/chunks/wolfram-Dz4KXISs.js +6 -0
- package/dist/chunks/xml-C2J0sS9M.js +8 -0
- package/dist/chunks/xsl-BmSZphgC.js +8 -0
- package/dist/chunks/yaml-DaO7k5B1.js +6 -0
- package/dist/chunks/zenscript-CxBjpf9c.js +6 -0
- package/dist/chunks/zig-Vm0PO9wB.js +6 -0
- package/dist/dashboard.js +8 -0
- package/dist/define.js +4 -0
- package/dist/index.js +317 -0
- package/dist/studio.css +2272 -0
- package/dist/styles.js +1 -0
- package/package.json +88 -0
- package/prose-node-shims/fs.ts +6 -0
- package/prose-node-shims/path.ts +16 -0
- package/prose-node-shims/sharp.ts +4 -0
- package/prose-ui-node-shim.ts +26 -0
- package/src/App.tsx +173 -0
- package/src/WorkspaceRoutes.tsx +38 -0
- package/src/api.ts +833 -0
- package/src/auth-client.ts +15 -0
- package/src/chat/ChangeCard.tsx +330 -0
- package/src/chat/ChatBar.tsx +238 -0
- package/src/chat/ChatMessage.tsx +478 -0
- package/src/chat/ChatPanel.tsx +406 -0
- package/src/chat/ChatProvider.tsx +661 -0
- package/src/chat/Composer.tsx +461 -0
- package/src/chat/DocListCard.tsx +322 -0
- package/src/chat/LiveStatus.tsx +83 -0
- package/src/chat/MentionPopover.tsx +164 -0
- package/src/chat/ModelPicker.tsx +113 -0
- package/src/chat/Shimmer.tsx +39 -0
- package/src/chat/ThreadHistory.tsx +268 -0
- package/src/chat/chat-context.ts +41 -0
- package/src/chat/chat-helpers.ts +402 -0
- package/src/chat/chat-state.ts +59 -0
- package/src/chat/icons.tsx +171 -0
- package/src/chat/useStickToBottom.ts +110 -0
- package/src/chrome/AppShell.tsx +100 -0
- package/src/chrome/AppSidebar.tsx +305 -0
- package/src/chrome/CommandPalette.tsx +559 -0
- package/src/chrome/ContentApiPopover.tsx +215 -0
- package/src/chrome/EditorActionsContext.tsx +63 -0
- package/src/chrome/EditorFocusContext.tsx +80 -0
- package/src/chrome/EditorStatusContext.tsx +84 -0
- package/src/chrome/NavItem.tsx +75 -0
- package/src/chrome/OpenSiteButton.tsx +148 -0
- package/src/chrome/StatusBar.tsx +73 -0
- package/src/chrome/UserMenu.tsx +130 -0
- package/src/chrome/WorkspaceNavContext.tsx +60 -0
- package/src/chrome/WorkspaceStatusBar.tsx +940 -0
- package/src/chrome/content-api-url.ts +111 -0
- package/src/chrome/content-type-groups.ts +32 -0
- package/src/chrome/hotkeys.ts +79 -0
- package/src/chrome/icons.tsx +191 -0
- package/src/chrome/open-site.ts +30 -0
- package/src/chrome/status-bar-action.ts +24 -0
- package/src/components/AppChromeContext.tsx +32 -0
- package/src/components/Shell.tsx +18 -0
- package/src/components/WorkspaceSwitcher.tsx +345 -0
- package/src/content-blocks/index.tsx +262 -0
- package/src/css.d.ts +2 -0
- package/src/dashboard.ts +5 -0
- package/src/define-studio.tsx +98 -0
- package/src/define.ts +12 -0
- package/src/index.css +123 -0
- package/src/index.ts +19 -0
- package/src/last-user.ts +40 -0
- package/src/last-workspace.ts +57 -0
- package/src/mcp/McpConnectorsPanel.tsx +872 -0
- package/src/mcp/parse-json.ts +52 -0
- package/src/pages/AcceptInvitePage.tsx +99 -0
- package/src/pages/BlockSettingsDialog.tsx +303 -0
- package/src/pages/BlocksList.tsx +402 -0
- package/src/pages/BodyProse.tsx +236 -0
- package/src/pages/DocEditorPage.tsx +1394 -0
- package/src/pages/EmbedChatPage.tsx +110 -0
- package/src/pages/EmbedPublishPage.tsx +259 -0
- package/src/pages/EnterPage.tsx +96 -0
- package/src/pages/GithubConnectPage.tsx +142 -0
- package/src/pages/LegacyWorkspaceRedirect.tsx +57 -0
- package/src/pages/LoginPage.tsx +335 -0
- package/src/pages/NewWorkspacePage.tsx +74 -0
- package/src/pages/RenderedBody.tsx +598 -0
- package/src/pages/ResumeHome.tsx +18 -0
- package/src/pages/SelectionBar.tsx +277 -0
- package/src/pages/SettingsGeneralPage.tsx +403 -0
- package/src/pages/SettingsGithubPage.tsx +277 -0
- package/src/pages/SettingsLayout.tsx +127 -0
- package/src/pages/SettingsMcpPage.tsx +30 -0
- package/src/pages/SettingsSchemaPage.tsx +93 -0
- package/src/pages/SettingsUsersPage.tsx +363 -0
- package/src/pages/TypeDocsPage.tsx +225 -0
- package/src/pages/UiKitPage.tsx +331 -0
- package/src/pages/UserSettingsPage.tsx +94 -0
- package/src/pages/WorkspaceHomeRedirect.tsx +17 -0
- package/src/pages/WorkspaceLayout.tsx +103 -0
- package/src/pages/WorkspacesPage.tsx +35 -0
- package/src/pages/blocks-list.ts +73 -0
- package/src/pages/body-blocks.ts +233 -0
- package/src/pages/body-mdx.tsx +82 -0
- package/src/pages/compile-body.ts +37 -0
- package/src/pages/host-env.ts +22 -0
- package/src/pages/html-to-markdown.ts +99 -0
- package/src/pages/preview-bridge.ts +46 -0
- package/src/pages/preview-split.ts +30 -0
- package/src/pages/preview-url.ts +92 -0
- package/src/pages/selection-format.ts +179 -0
- package/src/pages/type-docs.ts +9 -0
- package/src/replica/BootstrapSplash.tsx +80 -0
- package/src/replica/ReplicaProvider.tsx +267 -0
- package/src/replica/cache.ts +30 -0
- package/src/replica/idb.ts +89 -0
- package/src/replica/instance.ts +39 -0
- package/src/replica/pull.ts +23 -0
- package/src/replica/store.ts +497 -0
- package/src/replica/sync-cache.ts +51 -0
- package/src/replica/types.ts +119 -0
- package/src/replica/useReplica.ts +13 -0
- package/src/site.tsx +230 -0
- package/src/studio-config.ts +81 -0
- package/src/styles/themes.ts +49 -0
- package/src/styles/tokens.stylex.ts +58 -0
- package/src/styles.ts +11 -0
- package/src/theme/AccentOverride.tsx +29 -0
- package/src/theme/ThemeProvider.tsx +130 -0
- package/src/theme/apply-theme-class.ts +12 -0
- package/src/ui/BackLink.tsx +28 -0
- package/src/ui/Button.tsx +167 -0
- package/src/ui/ConfirmDialog.tsx +141 -0
- package/src/ui/Field.tsx +45 -0
- package/src/ui/Input.tsx +183 -0
- package/src/ui/ListRow.tsx +88 -0
- package/src/ui/Page.tsx +151 -0
- package/src/ui/Text.tsx +77 -0
- package/src/ui/Tooltip.tsx +85 -0
- package/src/ui/popup.ts +216 -0
- package/src/workspace/permissions.ts +17 -0
- package/src/workspace/types.ts +12 -0
- package/src/workspace-path.ts +98 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// packages/studio/src/pages/selection-format.ts
|
|
2
|
+
export type BlockFormat = "paragraph" | "heading" | "list" | "quote";
|
|
3
|
+
|
|
4
|
+
const BLOCK_SELECTOR = "p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote";
|
|
5
|
+
|
|
6
|
+
export function blockFormatOf(host: HTMLElement, range?: Range): BlockFormat {
|
|
7
|
+
const current = blockElement(host, range);
|
|
8
|
+
if (!current) return "paragraph";
|
|
9
|
+
return formatOfTag(current.tagName);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function applyBlockFormat(host: HTMLElement, format: BlockFormat, range?: Range): void {
|
|
13
|
+
const current = blockElement(host, range);
|
|
14
|
+
const html = current ? contentsHtml(current) : host.innerHTML;
|
|
15
|
+
host.replaceChildren(createBlock(format, html));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function marksAt(range: Range): { bold: boolean; italic: boolean; href: string | null } {
|
|
19
|
+
const element = elementFrom(range.startContainer);
|
|
20
|
+
return {
|
|
21
|
+
bold: Boolean(element?.closest("strong, b")),
|
|
22
|
+
italic: Boolean(element?.closest("em, i")),
|
|
23
|
+
href: element?.closest("a")?.getAttribute("href") ?? null,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function toggleInline(range: Range, tag: "strong" | "em"): void {
|
|
28
|
+
const existing = elementFrom(range.commonAncestorContainer)?.closest(tag);
|
|
29
|
+
if (
|
|
30
|
+
existing instanceof HTMLElement &&
|
|
31
|
+
existing.contains(range.startContainer) &&
|
|
32
|
+
existing.contains(range.endContainer)
|
|
33
|
+
) {
|
|
34
|
+
unwrap(existing);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
wrapRange(range, document.createElement(tag));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function applyLink(range: Range, href: string): void {
|
|
41
|
+
const existing = elementFrom(range.startContainer)?.closest("a");
|
|
42
|
+
const trimmed = href.trim();
|
|
43
|
+
if (
|
|
44
|
+
existing instanceof HTMLElement &&
|
|
45
|
+
existing.contains(range.startContainer) &&
|
|
46
|
+
existing.contains(range.endContainer)
|
|
47
|
+
) {
|
|
48
|
+
if (!trimmed) {
|
|
49
|
+
unwrap(existing);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
existing.setAttribute("href", trimmed);
|
|
53
|
+
selectContents(existing);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!trimmed) return;
|
|
57
|
+
const anchor = document.createElement("a");
|
|
58
|
+
anchor.setAttribute("href", trimmed);
|
|
59
|
+
anchor.setAttribute("target", "_blank");
|
|
60
|
+
anchor.setAttribute("rel", "noreferrer");
|
|
61
|
+
wrapRange(range, anchor);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function placeCaretAtEnd(host: HTMLElement): void {
|
|
65
|
+
const target = host.querySelector("p, h1, h2, h3, h4, h5, h6, li") ?? host;
|
|
66
|
+
host.focus();
|
|
67
|
+
const range = document.createRange();
|
|
68
|
+
range.selectNodeContents(target);
|
|
69
|
+
range.collapse(false);
|
|
70
|
+
const selection = window.getSelection();
|
|
71
|
+
if (!selection) return;
|
|
72
|
+
selection.removeAllRanges();
|
|
73
|
+
selection.addRange(range);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function blockElement(host: HTMLElement, range?: Range): HTMLElement | null {
|
|
77
|
+
const blocks = [...host.querySelectorAll(BLOCK_SELECTOR)].filter(
|
|
78
|
+
(element): element is HTMLElement => element instanceof HTMLElement,
|
|
79
|
+
);
|
|
80
|
+
if (blocks.length === 0) return null;
|
|
81
|
+
if (!range) return blocks[0] ?? null;
|
|
82
|
+
return (
|
|
83
|
+
blocks.find(
|
|
84
|
+
(element) =>
|
|
85
|
+
element.contains(range.startContainer) || element.contains(range.endContainer),
|
|
86
|
+
) ??
|
|
87
|
+
blocks[0] ??
|
|
88
|
+
null
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function formatOfTag(tag: string): BlockFormat {
|
|
93
|
+
if (tag === "UL" || tag === "OL") return "list";
|
|
94
|
+
if (tag === "BLOCKQUOTE") return "quote";
|
|
95
|
+
if (/^H[1-6]$/.test(tag)) return "heading";
|
|
96
|
+
return "paragraph";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function contentsHtml(element: HTMLElement): string {
|
|
100
|
+
const tag = element.tagName;
|
|
101
|
+
if (tag === "UL" || tag === "OL") {
|
|
102
|
+
return [...element.children]
|
|
103
|
+
.filter((child) => child.tagName === "LI")
|
|
104
|
+
.map((child) => child.innerHTML)
|
|
105
|
+
.filter(Boolean)
|
|
106
|
+
.join(" ");
|
|
107
|
+
}
|
|
108
|
+
if (tag === "BLOCKQUOTE") {
|
|
109
|
+
const inner = element.querySelector(BLOCK_SELECTOR);
|
|
110
|
+
if (inner instanceof HTMLElement && inner !== element) return contentsHtml(inner);
|
|
111
|
+
return element.innerHTML;
|
|
112
|
+
}
|
|
113
|
+
return element.innerHTML;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function createBlock(format: BlockFormat, html: string): HTMLElement {
|
|
117
|
+
if (format === "heading") {
|
|
118
|
+
const heading = document.createElement("h2");
|
|
119
|
+
heading.innerHTML = html;
|
|
120
|
+
return heading;
|
|
121
|
+
}
|
|
122
|
+
if (format === "list") {
|
|
123
|
+
const list = document.createElement("ul");
|
|
124
|
+
const item = document.createElement("li");
|
|
125
|
+
item.innerHTML = html;
|
|
126
|
+
list.appendChild(item);
|
|
127
|
+
return list;
|
|
128
|
+
}
|
|
129
|
+
if (format === "quote") {
|
|
130
|
+
const quote = document.createElement("blockquote");
|
|
131
|
+
const paragraph = document.createElement("p");
|
|
132
|
+
paragraph.innerHTML = html;
|
|
133
|
+
quote.appendChild(paragraph);
|
|
134
|
+
return quote;
|
|
135
|
+
}
|
|
136
|
+
const paragraph = document.createElement("p");
|
|
137
|
+
paragraph.innerHTML = html;
|
|
138
|
+
return paragraph;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function elementFrom(node: Node): Element | null {
|
|
142
|
+
return node instanceof Element ? node : node.parentElement;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function wrapRange(range: Range, wrapper: HTMLElement): void {
|
|
146
|
+
try {
|
|
147
|
+
range.surroundContents(wrapper);
|
|
148
|
+
} catch {
|
|
149
|
+
wrapper.appendChild(range.extractContents());
|
|
150
|
+
range.insertNode(wrapper);
|
|
151
|
+
}
|
|
152
|
+
selectContents(wrapper);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function unwrap(element: HTMLElement): void {
|
|
156
|
+
const parent = element.parentNode;
|
|
157
|
+
if (!parent) return;
|
|
158
|
+
const first = element.firstChild;
|
|
159
|
+
const last = element.lastChild;
|
|
160
|
+
while (element.firstChild) parent.insertBefore(element.firstChild, element);
|
|
161
|
+
element.remove();
|
|
162
|
+
if (!first || !last) return;
|
|
163
|
+
const range = document.createRange();
|
|
164
|
+
range.setStartBefore(first);
|
|
165
|
+
range.setEndAfter(last);
|
|
166
|
+
const selection = window.getSelection();
|
|
167
|
+
if (!selection) return;
|
|
168
|
+
selection.removeAllRanges();
|
|
169
|
+
selection.addRange(range);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function selectContents(element: HTMLElement): void {
|
|
173
|
+
const selection = window.getSelection();
|
|
174
|
+
if (!selection) return;
|
|
175
|
+
const range = document.createRange();
|
|
176
|
+
range.selectNodeContents(element);
|
|
177
|
+
selection.removeAllRanges();
|
|
178
|
+
selection.addRange(range);
|
|
179
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// packages/studio/src/pages/type-docs.ts
|
|
2
|
+
|
|
3
|
+
/** Slug order. A missing locale is not a language — data models omit it. */
|
|
4
|
+
export function compareTypeDocs(
|
|
5
|
+
a: { slug: string; locale?: string },
|
|
6
|
+
b: { slug: string; locale?: string },
|
|
7
|
+
) {
|
|
8
|
+
return a.slug.localeCompare(b.slug) || (a.locale ?? "").localeCompare(b.locale ?? "");
|
|
9
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// packages/studio/src/replica/BootstrapSplash.tsx
|
|
2
|
+
import { Snake } from "loading-dev";
|
|
3
|
+
import * as stylex from "@stylexjs/stylex";
|
|
4
|
+
import { Shimmer } from "../chat/Shimmer";
|
|
5
|
+
import { colors, space, type } from "../styles/tokens.stylex";
|
|
6
|
+
import { Text } from "../ui/Text";
|
|
7
|
+
|
|
8
|
+
export function BootstrapSplash({
|
|
9
|
+
error,
|
|
10
|
+
onRetry,
|
|
11
|
+
}: {
|
|
12
|
+
error?: string | null;
|
|
13
|
+
onRetry?: () => void;
|
|
14
|
+
}) {
|
|
15
|
+
return (
|
|
16
|
+
<div
|
|
17
|
+
{...stylex.props(styles.root)}
|
|
18
|
+
aria-busy={!error || undefined}
|
|
19
|
+
aria-live="polite"
|
|
20
|
+
>
|
|
21
|
+
<div {...stylex.props(styles.mark)}>
|
|
22
|
+
{error ? null : (
|
|
23
|
+
<span {...stylex.props(styles.spinner)}>
|
|
24
|
+
<Snake size={20} />
|
|
25
|
+
</span>
|
|
26
|
+
)}
|
|
27
|
+
<Text as="p" size="xs" tone="muted" weight="semibold">
|
|
28
|
+
{error ? "BACKMATTER" : <Shimmer>BACKMATTER</Shimmer>}
|
|
29
|
+
</Text>
|
|
30
|
+
</div>
|
|
31
|
+
{error ? (
|
|
32
|
+
<>
|
|
33
|
+
<Text tone="danger">{error}</Text>
|
|
34
|
+
{onRetry ? (
|
|
35
|
+
<button type="button" {...stylex.props(styles.retry)} onClick={onRetry}>
|
|
36
|
+
Retry
|
|
37
|
+
</button>
|
|
38
|
+
) : null}
|
|
39
|
+
</>
|
|
40
|
+
) : null}
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const styles = stylex.create({
|
|
46
|
+
root: {
|
|
47
|
+
display: "flex",
|
|
48
|
+
boxSizing: "border-box",
|
|
49
|
+
width: "100vw",
|
|
50
|
+
height: "100dvh",
|
|
51
|
+
flexDirection: "column",
|
|
52
|
+
alignItems: "center",
|
|
53
|
+
justifyContent: "center",
|
|
54
|
+
gap: space.lg,
|
|
55
|
+
backgroundColor: colors.bgApp,
|
|
56
|
+
color: colors.text,
|
|
57
|
+
},
|
|
58
|
+
mark: {
|
|
59
|
+
display: "flex",
|
|
60
|
+
flexDirection: "column",
|
|
61
|
+
alignItems: "center",
|
|
62
|
+
gap: space.sm,
|
|
63
|
+
},
|
|
64
|
+
spinner: {
|
|
65
|
+
display: "flex",
|
|
66
|
+
color: colors.textMuted,
|
|
67
|
+
},
|
|
68
|
+
retry: {
|
|
69
|
+
cursor: "pointer",
|
|
70
|
+
borderWidth: 1,
|
|
71
|
+
borderStyle: "solid",
|
|
72
|
+
borderColor: colors.border,
|
|
73
|
+
borderRadius: 4,
|
|
74
|
+
backgroundColor: colors.bgSurface,
|
|
75
|
+
color: colors.text,
|
|
76
|
+
paddingInline: space.xl,
|
|
77
|
+
paddingBlock: space.sm,
|
|
78
|
+
fontSize: type.sm,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// packages/studio/src/replica/ReplicaProvider.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { useLocation } from "react-router";
|
|
11
|
+
import {
|
|
12
|
+
checkoutBranch,
|
|
13
|
+
fetchAllWorkspaces,
|
|
14
|
+
fetchMe,
|
|
15
|
+
fetchReplica,
|
|
16
|
+
notifyWorkspaceChanged,
|
|
17
|
+
type ApiError,
|
|
18
|
+
type TreeChangeDetail,
|
|
19
|
+
} from "../api";
|
|
20
|
+
import { rememberLastUser } from "../last-user";
|
|
21
|
+
import { readLastWorkspace, rememberLastWorkspace } from "../last-workspace";
|
|
22
|
+
import { cmsWorkspaceSlug } from "../workspace-path";
|
|
23
|
+
import { BootstrapSplash } from "./BootstrapSplash";
|
|
24
|
+
import { replicaCacheFromSlot } from "./cache";
|
|
25
|
+
import { replicaBoot, replicaStore } from "./instance";
|
|
26
|
+
import { pullReplica } from "./pull";
|
|
27
|
+
import { useReplicaState } from "./useReplica";
|
|
28
|
+
|
|
29
|
+
export type ReplicaSession = {
|
|
30
|
+
user: { id: string; email: string };
|
|
31
|
+
bootstrapError: string | null;
|
|
32
|
+
retryBootstrap: () => void;
|
|
33
|
+
ensureWorkspace: (idOrSlug: string) => Promise<void>;
|
|
34
|
+
applyCheckout: (workspaceId: string, branch: string) => Promise<void>;
|
|
35
|
+
syncCheckout: (workspaceId: string, branch: string) => Promise<void>;
|
|
36
|
+
revalidate: (workspaceId: string, intendedBranch?: string) => Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const ReplicaSessionContext = createContext<ReplicaSession | null>(null);
|
|
40
|
+
|
|
41
|
+
export function useReplicaSession(): ReplicaSession {
|
|
42
|
+
const ctx = useContext(ReplicaSessionContext);
|
|
43
|
+
if (!ctx) {
|
|
44
|
+
throw new Error("useReplicaSession must be used within ReplicaProvider");
|
|
45
|
+
}
|
|
46
|
+
return ctx;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function errorMessage(err: unknown) {
|
|
50
|
+
return err instanceof Error ? err.message : "Could not load";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resolveWorkspaceId(idOrSlug: string) {
|
|
54
|
+
const state = replicaStore.getState();
|
|
55
|
+
return state.workspace(idOrSlug)?.id ?? state.workspaceBySlug(idOrSlug)?.id ?? idOrSlug;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function ReplicaProvider({
|
|
59
|
+
user,
|
|
60
|
+
children,
|
|
61
|
+
}: {
|
|
62
|
+
user: { id: string; email: string };
|
|
63
|
+
children: ReactNode;
|
|
64
|
+
}) {
|
|
65
|
+
const location = useLocation();
|
|
66
|
+
const slug = cmsWorkspaceSlug(location.pathname);
|
|
67
|
+
const [bootstrapError, setBootstrapError] = useState<string | null>(null);
|
|
68
|
+
const [bootGen, setBootGen] = useState(0);
|
|
69
|
+
|
|
70
|
+
const applyFetched = useCallback(
|
|
71
|
+
async (idOrSlug: string, intendedBranch?: string) => {
|
|
72
|
+
const id = resolveWorkspaceId(idOrSlug);
|
|
73
|
+
const state = replicaStore.getState();
|
|
74
|
+
const branch = intendedBranch ?? state.currentBranch(id);
|
|
75
|
+
const ok = await pullReplica({
|
|
76
|
+
workspaceId: idOrSlug,
|
|
77
|
+
cache: replicaCacheFromSlot(branch, branch ? state.checkout(id) : null),
|
|
78
|
+
intendedBranch,
|
|
79
|
+
fetchReplica,
|
|
80
|
+
store: replicaStore,
|
|
81
|
+
});
|
|
82
|
+
if (!ok) return;
|
|
83
|
+
const workspace = replicaStore.getState().workspace(id);
|
|
84
|
+
if (!workspace) return;
|
|
85
|
+
replicaStore.setActiveWorkspace(workspace.id);
|
|
86
|
+
const nextUser = replicaStore.getState().control?.user;
|
|
87
|
+
if (nextUser) rememberLastUser(nextUser);
|
|
88
|
+
rememberLastWorkspace(user.id, workspace.id);
|
|
89
|
+
},
|
|
90
|
+
[user.id],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const revalidate = useCallback(
|
|
94
|
+
async (workspaceId: string, intendedBranch?: string) => {
|
|
95
|
+
try {
|
|
96
|
+
await applyFetched(workspaceId, intendedBranch);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
replicaStore.setRefreshError(errorMessage(err));
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[applyFetched],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const ensureWorkspace = useCallback(
|
|
105
|
+
async (idOrSlug: string) => {
|
|
106
|
+
replicaStore.setActiveWorkspace(idOrSlug);
|
|
107
|
+
if (replicaStore.getState().ready) {
|
|
108
|
+
void revalidate(idOrSlug);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
await applyFetched(idOrSlug);
|
|
112
|
+
},
|
|
113
|
+
[applyFetched, revalidate],
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const syncCheckout = useCallback(
|
|
117
|
+
async (workspaceId: string, branch: string) => {
|
|
118
|
+
const id = resolveWorkspaceId(workspaceId);
|
|
119
|
+
const result = replicaStore.setCheckout(id, branch);
|
|
120
|
+
if (result === "miss") {
|
|
121
|
+
await applyFetched(id, branch);
|
|
122
|
+
} else {
|
|
123
|
+
void revalidate(id, branch);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
[applyFetched, revalidate],
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const applyCheckout = useCallback(
|
|
130
|
+
async (workspaceId: string, branch: string) => {
|
|
131
|
+
const id = resolveWorkspaceId(workspaceId);
|
|
132
|
+
await checkoutBranch(id, branch);
|
|
133
|
+
notifyWorkspaceChanged();
|
|
134
|
+
await syncCheckout(id, branch);
|
|
135
|
+
},
|
|
136
|
+
[syncCheckout],
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
let cancelled = false;
|
|
141
|
+
setBootstrapError(null);
|
|
142
|
+
|
|
143
|
+
async function boot() {
|
|
144
|
+
if (replicaStore.getState().sessionUserId !== user.id) {
|
|
145
|
+
await replicaStore.hydrate(user.id, slug ?? readLastWorkspace(user.id));
|
|
146
|
+
} else {
|
|
147
|
+
await replicaBoot;
|
|
148
|
+
}
|
|
149
|
+
if (cancelled) return;
|
|
150
|
+
|
|
151
|
+
if (slug) {
|
|
152
|
+
replicaStore.setActiveWorkspace(slug);
|
|
153
|
+
if (replicaStore.getState().ready) {
|
|
154
|
+
void revalidate(slug);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
await applyFetched(slug);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if (!cancelled) setBootstrapError(errorMessage(err));
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const last = readLastWorkspace(user.id);
|
|
166
|
+
if (last) {
|
|
167
|
+
replicaStore.setActiveWorkspace(last);
|
|
168
|
+
if (replicaStore.getState().control && replicaStore.getState().ready) {
|
|
169
|
+
void revalidate(last);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
await applyFetched(last);
|
|
174
|
+
if (cancelled) return;
|
|
175
|
+
if (replicaStore.getState().ready) return;
|
|
176
|
+
} catch (err) {
|
|
177
|
+
const apiErr = err as ApiError;
|
|
178
|
+
if (apiErr.status !== 404 && !replicaStore.getState().control) {
|
|
179
|
+
if (!cancelled) setBootstrapError(errorMessage(err));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
replicaStore.setActiveWorkspace(null);
|
|
186
|
+
if (replicaStore.getState().control) return;
|
|
187
|
+
try {
|
|
188
|
+
const workspaces = await fetchAllWorkspaces();
|
|
189
|
+
if (cancelled) return;
|
|
190
|
+
rememberLastUser(user);
|
|
191
|
+
replicaStore.applyControl({
|
|
192
|
+
user,
|
|
193
|
+
workspaces: workspaces.workspaces,
|
|
194
|
+
});
|
|
195
|
+
} catch (err) {
|
|
196
|
+
if (!cancelled) setBootstrapError(errorMessage(err));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void boot();
|
|
201
|
+
return () => {
|
|
202
|
+
cancelled = true;
|
|
203
|
+
};
|
|
204
|
+
}, [user, slug, bootGen, applyFetched, revalidate]);
|
|
205
|
+
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
function onTree(event: Event) {
|
|
208
|
+
const detail = (event as CustomEvent<TreeChangeDetail>).detail;
|
|
209
|
+
if (detail?.workspaceId && detail.remove) {
|
|
210
|
+
replicaStore.removeDoc(detail.workspaceId, detail);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (detail?.status && detail.workspaceId) {
|
|
214
|
+
replicaStore.patchDocStatus(detail.workspaceId, detail, detail.status);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const active =
|
|
218
|
+
detail?.workspaceId ??
|
|
219
|
+
(slug ? replicaStore.getState().workspaceBySlug(slug)?.id : undefined);
|
|
220
|
+
if (active) void revalidate(active);
|
|
221
|
+
}
|
|
222
|
+
function onHead() {
|
|
223
|
+
const id = slug
|
|
224
|
+
? replicaStore.getState().workspaceBySlug(slug)?.id
|
|
225
|
+
: null;
|
|
226
|
+
if (id) void revalidate(id);
|
|
227
|
+
}
|
|
228
|
+
window.addEventListener("backmatter:tree-changed", onTree);
|
|
229
|
+
window.addEventListener("backmatter:head-changed", onHead);
|
|
230
|
+
window.addEventListener("backmatter:workspace-changed", onHead);
|
|
231
|
+
return () => {
|
|
232
|
+
window.removeEventListener("backmatter:tree-changed", onTree);
|
|
233
|
+
window.removeEventListener("backmatter:head-changed", onHead);
|
|
234
|
+
window.removeEventListener("backmatter:workspace-changed", onHead);
|
|
235
|
+
};
|
|
236
|
+
}, [revalidate, slug]);
|
|
237
|
+
|
|
238
|
+
const value: ReplicaSession = {
|
|
239
|
+
user,
|
|
240
|
+
bootstrapError,
|
|
241
|
+
retryBootstrap: () => setBootGen((n) => n + 1),
|
|
242
|
+
ensureWorkspace,
|
|
243
|
+
applyCheckout,
|
|
244
|
+
syncCheckout,
|
|
245
|
+
revalidate,
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<ReplicaSessionContext.Provider value={value}>
|
|
250
|
+
{children}
|
|
251
|
+
</ReplicaSessionContext.Provider>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function ReplicaGate({ children }: { children: ReactNode }) {
|
|
256
|
+
const { bootstrapError, retryBootstrap } = useReplicaSession();
|
|
257
|
+
const state = useReplicaState();
|
|
258
|
+
if (!state.ready) {
|
|
259
|
+
return (
|
|
260
|
+
<BootstrapSplash
|
|
261
|
+
error={bootstrapError}
|
|
262
|
+
onRetry={bootstrapError ? retryBootstrap : undefined}
|
|
263
|
+
/>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return children;
|
|
267
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// packages/studio/src/replica/cache.ts
|
|
2
|
+
import type { ReplicaBranchSlot } from "./types";
|
|
3
|
+
|
|
4
|
+
export type ReplicaCache = {
|
|
5
|
+
branch: string;
|
|
6
|
+
headSha: string | null;
|
|
7
|
+
schemaVersion?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function replicaCacheFromSlot(
|
|
11
|
+
branch: string | null,
|
|
12
|
+
slot: ReplicaBranchSlot | null,
|
|
13
|
+
): ReplicaCache | undefined {
|
|
14
|
+
if (!branch || !slot) return undefined;
|
|
15
|
+
return {
|
|
16
|
+
branch,
|
|
17
|
+
headSha: slot.headSha,
|
|
18
|
+
...(slot.schema ? { schemaVersion: slot.schema.version } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function replicaQuery(cache: ReplicaCache): string {
|
|
23
|
+
const params = new URLSearchParams();
|
|
24
|
+
params.set("branch", cache.branch);
|
|
25
|
+
params.set("head", cache.headSha ?? "");
|
|
26
|
+
if (cache.schemaVersion !== undefined) {
|
|
27
|
+
params.set("schema", String(cache.schemaVersion));
|
|
28
|
+
}
|
|
29
|
+
return params.toString();
|
|
30
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// packages/studio/src/replica/idb.ts
|
|
2
|
+
import type { ReplicaPersistence, ReplicaRecord } from "./types";
|
|
3
|
+
|
|
4
|
+
const DB_NAME = "backmatter-replica";
|
|
5
|
+
const STORE = "records";
|
|
6
|
+
|
|
7
|
+
function memoryPersistence(): ReplicaPersistence {
|
|
8
|
+
const data = new Map<string, ReplicaRecord>();
|
|
9
|
+
return {
|
|
10
|
+
async load(userId) {
|
|
11
|
+
return data.get(userId) ?? null;
|
|
12
|
+
},
|
|
13
|
+
async save(record) {
|
|
14
|
+
data.set(record.userId, record);
|
|
15
|
+
},
|
|
16
|
+
async clear() {
|
|
17
|
+
data.clear();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function openDb(): Promise<IDBDatabase> {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const req = indexedDB.open(DB_NAME, 1);
|
|
25
|
+
req.onupgradeneeded = () => {
|
|
26
|
+
const db = req.result;
|
|
27
|
+
if (!db.objectStoreNames.contains(STORE)) {
|
|
28
|
+
db.createObjectStore(STORE);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
req.onsuccess = () => resolve(req.result);
|
|
32
|
+
req.onerror = () => reject(req.error ?? new Error("idb_open_failed"));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createIdbPersistence(): ReplicaPersistence {
|
|
37
|
+
if (typeof indexedDB === "undefined") return memoryPersistence();
|
|
38
|
+
|
|
39
|
+
const fallback = memoryPersistence();
|
|
40
|
+
let broken = false;
|
|
41
|
+
|
|
42
|
+
async function withStore<T>(
|
|
43
|
+
mode: IDBTransactionMode,
|
|
44
|
+
fn: (store: IDBObjectStore) => IDBRequest<T> | void,
|
|
45
|
+
): Promise<T | undefined> {
|
|
46
|
+
const db = await openDb();
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const tx = db.transaction(STORE, mode);
|
|
49
|
+
const store = tx.objectStore(STORE);
|
|
50
|
+
const req = fn(store);
|
|
51
|
+
tx.oncomplete = () => resolve(req ? req.result : undefined);
|
|
52
|
+
tx.onerror = () => reject(tx.error ?? new Error("idb_tx_failed"));
|
|
53
|
+
if (req) {
|
|
54
|
+
req.onerror = () => reject(req.error ?? new Error("idb_req_failed"));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
async load(userId) {
|
|
61
|
+
if (broken) return fallback.load(userId);
|
|
62
|
+
try {
|
|
63
|
+
const value = await withStore("readonly", (store) => store.get(userId));
|
|
64
|
+
return (value as ReplicaRecord | undefined) ?? null;
|
|
65
|
+
} catch {
|
|
66
|
+
broken = true;
|
|
67
|
+
return fallback.load(userId);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
async save(record) {
|
|
71
|
+
if (broken) return fallback.save(record);
|
|
72
|
+
try {
|
|
73
|
+
await withStore("readwrite", (store) => store.put(record, record.userId));
|
|
74
|
+
} catch {
|
|
75
|
+
broken = true;
|
|
76
|
+
await fallback.save(record);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async clear() {
|
|
80
|
+
if (broken) return fallback.clear();
|
|
81
|
+
try {
|
|
82
|
+
await withStore("readwrite", (store) => store.clear());
|
|
83
|
+
} catch {
|
|
84
|
+
broken = true;
|
|
85
|
+
await fallback.clear();
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// packages/studio/src/replica/instance.ts
|
|
2
|
+
import { readLastUser } from "../last-user";
|
|
3
|
+
import { readLastWorkspace } from "../last-workspace";
|
|
4
|
+
import { cmsWorkspaceSlug } from "../workspace-path";
|
|
5
|
+
import { createIdbPersistence } from "./idb";
|
|
6
|
+
import { createReplicaStore } from "./store";
|
|
7
|
+
import { clearSyncReplica, readSyncReplica, writeSyncReplica } from "./sync-cache";
|
|
8
|
+
|
|
9
|
+
export const replicaStore = createReplicaStore(createIdbPersistence());
|
|
10
|
+
|
|
11
|
+
function bootActiveHint() {
|
|
12
|
+
try {
|
|
13
|
+
const last = readLastUser();
|
|
14
|
+
if (!last) return { last: null, active: null as string | null };
|
|
15
|
+
const slug = cmsWorkspaceSlug(window.location.pathname);
|
|
16
|
+
return { last, active: slug ?? readLastWorkspace(last.id) };
|
|
17
|
+
} catch {
|
|
18
|
+
return { last: null, active: null as string | null };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const boot = bootActiveHint();
|
|
23
|
+
if (boot.last) {
|
|
24
|
+
const sync = readSyncReplica(boot.last.id);
|
|
25
|
+
if (sync) replicaStore.seed(sync);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
replicaStore.subscribe(() => {
|
|
29
|
+
const dump = replicaStore.dump();
|
|
30
|
+
if (!dump) {
|
|
31
|
+
clearSyncReplica();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
writeSyncReplica(dump);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const replicaBoot = boot.last
|
|
38
|
+
? replicaStore.hydrate(boot.last.id, boot.active)
|
|
39
|
+
: Promise.resolve();
|