1 line
4.3 KiB
JavaScript
1 line
4.3 KiB
JavaScript
"use strict";(self.webpackChunkbeancount_web=self.webpackChunkbeancount_web||[]).push([[185],{1772:(t,e,n)=>{n.d(e,{A:()=>a});var s=n(9284),o=n(8828),i=n(712);const a=t=>{const e=(0,s.useRef)(null);return(0,i.jsx)(o.KE,{height:t.height||"75vh",defaultLanguage:"bean"===t.lang?"beancount":t.lang,theme:"light",onMount:(n,s)=>{e.current=n,n.onDidChangeModelContent((()=>{s.languages.register({id:"beancount"}),s.languages.setMonarchTokensProvider("beancount",{tokenizer:{root:[[/\*|\!/,"keyword"],[/\d{4}-\d{2}-\d{2}/,"number"],[/\b(Assets|Liabilities|Equity|Income|Expenses)(:[\w\-]+)+\b/,"type.identifier"],[/-?\d+(\.\d+)?\s*(USD|CNY|EUR)?/,"number"],[/;.*/,"comment"],[/^\s*(include|option|plugin)\b/,"keyword"],[/\".*\"/,"string"]]}}),s.languages.setLanguageConfiguration("beancount",{comments:{lineComment:";"},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:'"',close:'"'},{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"}]});const e=n.getValue();t.onContentChange&&"function"===typeof t.onContentChange&&t.onContentChange(e)}))},options:{selectOnLineNumbers:!0,automaticLayout:!0,scrollBeyondLastLine:!1,wordWrap:"on",fontFamily:"'Consolas', monospace",fontSize:14,lineHeight:20,fontWeight:"500"},...t})}},1185:(t,e,n)=>{n.r(e),n.d(e,{default:()=>y});var s=n(9379),o=n(9284);const i={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"path",attrs:{d:"M893.3 293.3L730.7 130.7c-7.5-7.5-16.7-13-26.7-16V112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V338.5c0-17-6.7-33.2-18.7-45.2zM384 184h256v104H384V184zm456 656H184V184h136v136c0 17.7 14.3 32 32 32h320c17.7 0 32-14.3 32-32V205.8l136 136V840zM512 442c-79.5 0-144 64.5-144 144s64.5 144 144 144 144-64.5 144-144-64.5-144-144-144zm0 224c-44.2 0-80-35.8-80-80s35.8-80 80-80 80 35.8 80 80-35.8 80-80 80z"}}]},name:"save",theme:"outlined"};var a=n(3768),h=function(t,e){return o.createElement(a.A,(0,s.A)((0,s.A)({},t),{},{ref:e,icon:i}))};const l=o.forwardRef(h);var c=n(4412),r=n(9636),d=n(1896),u=n(4760),g=n(2475),m=n(2069),p=n(1772),C=n(712);class f extends o.Component{constructor(){super(...arguments),this.theme=this.context.theme,this.state={loading:!1,lang:"beancount",path:null,files:[],rawContent:"",content:""},this.fetchFileDir=()=>{this.setState({loading:!0}),(0,u.hd)("/api/auth/file/dir").then((t=>{this.setState({files:t})})).finally((()=>{this.setState({loading:!1})}))},this.handldEditContent=t=>{this.setState({content:t})},this.handleChangeFile=t=>{let e=this.state.lang;const n=t.split(".");e=n[n.length-1],this.setState({path:t,lang:e},(()=>{this.fetchFileContent(t)}))},this.fetchFileContent=()=>{this.setState({loading:!0}),(0,u.hd)(`/api/auth/file/content?path=${this.state.path}`).then((t=>{this.setState({rawContent:t,content:t})})).finally((()=>{this.setState({loading:!1})}))},this.saveFileContent=()=>{const{path:t,content:e}=this.state;this.setState({loading:!0}),(0,u.hd)("/api/auth/file",{method:"POST",body:{path:t,content:e}}).then((()=>{this.setState({rawContent:e}),c.Ay.success("\u4fdd\u5b58\u6210\u529f")})).finally((()=>{this.setState({loading:!1})}))}}componentDidMount(){this.fetchFileDir()}render(){return this.context.theme!==this.theme&&(this.theme=this.context.theme),(0,C.jsxs)("div",{className:"edit-page",children:[(0,C.jsxs)("div",{children:[(0,C.jsx)(r.A,{showSearch:!0,placeholder:"\u8bf7\u9009\u62e9\u6e90\u6587\u4ef6",style:{width:"200px"},onChange:this.handleChangeFile,children:this.state.files.map((t=>(0,C.jsx)(r.A.Option,{value:t,children:t},t)))}),"\xa0\xa0",(0,C.jsx)(d.A,{type:"primary",icon:(0,C.jsx)(l,{}),disabled:this.state.rawContent===this.state.content||!this.state.path,loading:this.state.loading,onClick:this.saveFileContent,children:"\u4fdd\u5b58"})]}),(0,C.jsx)("div",{style:{marginTop:"1rem"},children:(0,C.jsx)(p.A,{lang:this.state.lang,value:this.state.content,onContentChange:this.handldEditContent})})]})}}f.contextType=g.A;const y=(0,m.A)(f)},2069:(t,e,n)=>{n.d(e,{A:()=>i});var s=n(9284),o=n(712);const i=t=>class extends s.Component{constructor(){super(...arguments),this.defaultCommodity={currency:"CNY",symbol:"\uffe5"},this.currentCommodity=window.localStorage.getItem("ledgerCurrency")}render(){return(0,o.jsx)(t,{...this.props,commodity:this.currentCommodity?JSON.parse(this.currentCommodity):this.defaultCommodity})}}}}]); |