 830689f1cb
			
		
	
	830689f1cb
	
	
	
		
			
			* web: fix event propogation in search-select wrappers Two different patches, an older one that extracted long search blocks that were cut-and-pasted into a standalone component, and a newer one that fixed displaying placeholder values properly, conflicted and broke a relationship that allowed for the values to be propagated through those standalone components correctly. This restores the event handling and updates the listener set-ups with more idiomatic hooks into Lit's event system. * Updated search-select to properly render with Storybook, and provided a foundation for testing the Search-Select component with Storybook. * Accidentally deleted this line while making Sonar accept my test data. * Fixing a small issue that's bugged me for awhile: there's no reason to manually duplicate what code can duplicate. * Provided a storybook for testing out the flow search. Discovered along the way that I'd mis-used a prop-drilling technique which caused the currentFlow to be "undefined" when pass forward, giving rise to Marc's bug. I *think* this shakes out the last of the bugs. Events are passed up correctly and the initial value is recorded correctly. * Added comments and prettier had opinions. * Restoring old variable names; they didn't have to change after all. * fix lint Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
		
			
				
	
	
		
			91 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import fs from "fs";
 | |
| import path from "path";
 | |
| import { fileURLToPath } from "url";
 | |
| 
 | |
| const __dirname = fileURLToPath(new URL(".", import.meta.url));
 | |
| 
 | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any
 | |
| function* walkFilesystem(dir: string): Generator<string, undefined, any> {
 | |
|     const openeddir = fs.opendirSync(dir);
 | |
|     if (!openeddir) {
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     let d: fs.Dirent | null;
 | |
|     while ((d = openeddir?.readSync())) {
 | |
|         if (!d) {
 | |
|             break;
 | |
|         }
 | |
|         const entry = path.join(dir, d.name);
 | |
|         if (d.isDirectory()) yield* walkFilesystem(entry);
 | |
|         else if (d.isFile()) yield entry;
 | |
|     }
 | |
|     openeddir.close();
 | |
| }
 | |
| 
 | |
| const import_re = /^(import \w+ from .*\.css)";/;
 | |
| function extractImportLinesFromFile(path: string) {
 | |
|     const source = fs.readFileSync(path, { encoding: "utf8", flag: "r" });
 | |
|     const lines = source?.split("\n") ?? [];
 | |
|     return lines.filter((l) => import_re.test(l));
 | |
| }
 | |
| 
 | |
| function createOneImportLine(line: string) {
 | |
|     const importMatch = import_re.exec(line);
 | |
|     if (!importMatch) {
 | |
|         throw new Error("How did an unmatchable line get here?");
 | |
|     }
 | |
|     const importContent = importMatch[1];
 | |
|     if (!importContent) {
 | |
|         throw new Error("How did an unmatchable line get here!?");
 | |
|     }
 | |
|     return `    '${importContent}";',`;
 | |
| }
 | |
| 
 | |
| const isSourceFile = /\.ts$/;
 | |
| function getTheSourceFiles() {
 | |
|     return Array.from(walkFilesystem(path.join(__dirname, "..", "src"))).filter((path) =>
 | |
|         isSourceFile.test(path),
 | |
|     );
 | |
| }
 | |
| 
 | |
| function getTheImportLines(importPaths: string[]) {
 | |
|     const importLines: string[] = importPaths.reduce(
 | |
|         (acc: string[], path) => [...acc, extractImportLinesFromFile(path)].flat(),
 | |
|         [],
 | |
|     );
 | |
|     const uniqueImportLines = new Set(importLines);
 | |
|     const sortedImportLines = Array.from(uniqueImportLines.keys());
 | |
|     sortedImportLines.sort();
 | |
|     return sortedImportLines;
 | |
| }
 | |
| 
 | |
| const importPaths = getTheSourceFiles();
 | |
| const importLines = getTheImportLines(importPaths);
 | |
| 
 | |
| const outputFile = `
 | |
| // THIS IS A GENERATED FILE.  DO NOT EDIT BY HAND.
 | |
| //
 | |
| // This file is generated by the build-storybook-import-maps script in the UI's base directory.
 | |
| // This is a *hack* to work around an inconsistency in the way rollup, vite, and storybook
 | |
| // import CSS modules.
 | |
| //
 | |
| // Sometime around 2030 or so, the Javascript community may finally get its collective act together
 | |
| // and we'll have one unified way of doing this.  I can only hope.
 | |
| 
 | |
| const rawCssImportMaps = [
 | |
| ${importLines.map(createOneImportLine).join("\n")}
 | |
| ];
 | |
| 
 | |
| const cssImportMaps = rawCssImportMaps.reduce((acc, line) => (
 | |
| {...acc, [line]: line.replace(/\\.css/, ".css?inline")}), {});
 | |
| 
 | |
| export { cssImportMaps };
 | |
| export default cssImportMaps;
 | |
| `;
 | |
| 
 | |
| fs.writeFileSync(path.join(__dirname, "..", ".storybook", "css-import-maps.ts"), outputFile, {
 | |
|     encoding: "utf8",
 | |
|     flag: "w",
 | |
| });
 |