mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 02:24:57 +01:00 
			
		
		
		
	Update eslint and all plugins. Many plugins still do not ship type definitions so I had to add stubs. Also, I had to put a few typescript error expectations because if some unknown error in the types. `eslint-plugin-no-jquery` is disabled because it's not compatible with eslint 9 flat config (https://github.com/wikimedia/eslint-plugin-no-jquery/issues/311).
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import {reactive} from 'vue';
 | |
| import {GET} from '../modules/fetch.ts';
 | |
| import {pathEscapeSegments} from '../utils/url.ts';
 | |
| import {createElementFromHTML} from '../utils/dom.ts';
 | |
| import {html} from '../utils/html.ts';
 | |
| 
 | |
| export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) {
 | |
|   const store = reactive({
 | |
|     rootFiles: [],
 | |
|     selectedItem: props.treePath,
 | |
| 
 | |
|     async loadChildren(treePath: string, subPath: string = '') {
 | |
|       const response = await GET(`${props.repoLink}/tree-view/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}?sub_path=${encodeURIComponent(subPath)}`);
 | |
|       const json = await response.json();
 | |
|       const poolSvgs = [];
 | |
|       for (const [svgId, svgContent] of Object.entries(json.renderedIconPool ?? {})) {
 | |
|         if (!document.querySelector(`.global-svg-icon-pool #${svgId}`)) poolSvgs.push(svgContent);
 | |
|       }
 | |
|       if (poolSvgs.length) {
 | |
|         const svgContainer = createElementFromHTML(html`<div class="global-svg-icon-pool tw-hidden"></div>`);
 | |
|         svgContainer.innerHTML = poolSvgs.join('');
 | |
|         document.body.append(svgContainer);
 | |
|       }
 | |
|       return json.fileTreeNodes ?? null;
 | |
|     },
 | |
| 
 | |
|     async loadViewContent(url: string) {
 | |
|       url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`;
 | |
|       const response = await GET(url);
 | |
|       document.querySelector('.repo-view-content').innerHTML = await response.text();
 | |
|     },
 | |
| 
 | |
|     async navigateTreeView(treePath: string) {
 | |
|       const url = store.buildTreePathWebUrl(treePath);
 | |
|       window.history.pushState({treePath, url}, null, url);
 | |
|       store.selectedItem = treePath;
 | |
|       await store.loadViewContent(url);
 | |
|     },
 | |
| 
 | |
|     buildTreePathWebUrl(treePath: string) {
 | |
|       return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
 | |
|     },
 | |
|   });
 | |
|   return store;
 | |
| }
 |