11import { useMemo } from 'react' ;
2- import objectID from 'bson-objectid' ;
32import blobUtil from 'blob-util' ;
43import mime from 'mime' ;
54import { PLAINTEXT_FILE_REGEX } from '../../../server/utils/fileUtils' ;
65
7- const defaultSketch = `function setup() {
8- createCanvas(400, 400);
9- }
10-
11- function draw() {
12- background(220);
13- }` ;
14-
15- const defaultHTML = `<!DOCTYPE html>
16- <html lang="en">
17- <head>
18- <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.js"></script>
19- <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/addons/p5.sound.min.js"></script>
20- <link rel="stylesheet" type="text/css" href="style.css">
21- <meta charset="utf-8" />
22-
23- </head>
24- <body>
25- <main>
26- </main>
27- <script src="sketch.js"></script>
28- </body>
29- </html>
30- ` ;
31-
32- const defaultCSS = `html, body {
33- margin: 0;
34- padding: 0;
35- }
36- canvas {
37- display: block;
38- }
39- ` ;
40-
416// https://gist.github.com/fnky/7d044b94070a35e552f3c139cdf80213
427export function useSelectors ( state , mapStateToSelectors ) {
438 const selectors = useMemo ( ( ) => mapStateToSelectors ( state ) , [ state ] ) ;
@@ -52,48 +17,6 @@ export function getFileSelectors(state) {
5217 } ;
5318}
5419
55- export function initialState ( ) {
56- const a = objectID ( ) . toHexString ( ) ;
57- const b = objectID ( ) . toHexString ( ) ;
58- const c = objectID ( ) . toHexString ( ) ;
59- const r = objectID ( ) . toHexString ( ) ;
60- return [
61- {
62- name : 'root' ,
63- id : r ,
64- _id : r ,
65- children : [ b , a , c ] ,
66- fileType : 'folder' ,
67- content : ''
68- } ,
69- {
70- name : 'sketch.js' ,
71- content : defaultSketch ,
72- id : a ,
73- _id : a ,
74- isSelectedFile : true ,
75- fileType : 'file' ,
76- children : [ ]
77- } ,
78- {
79- name : 'index.html' ,
80- content : defaultHTML ,
81- id : b ,
82- _id : b ,
83- fileType : 'file' ,
84- children : [ ]
85- } ,
86- {
87- name : 'style.css' ,
88- content : defaultCSS ,
89- id : c ,
90- _id : c ,
91- fileType : 'file' ,
92- children : [ ]
93- }
94- ] ;
95- }
96-
9720function sortedChildrenId ( state , children ) {
9821 const childrenArray = state . filter ( ( file ) => children . includes ( file . id ) ) ;
9922 childrenArray . sort ( ( a , b ) => ( a . name > b . name ? 1 : - 1 ) ) ;
0 commit comments