diff --git a/package.json b/package.json index 85c9989..c6e8727 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,6 @@ "description": "", "main": "build/app.js", "scripts": { - "build:dev": "webpack --mode development", - "build:prod": "webpack --mode production", - "build:watch": "webpack --mode development -w", - "start": "ts-node src/server.ts", "compile": "tsc", "compile:watch": "tsc -w", "app": "electron build/app.js", @@ -18,8 +14,7 @@ "files": [ "build/**/*", "node_modules/**/*", - "package.json", - "!node_modules/@material-ui/**/*" + "package.json" ], "appId": "com.prelude.ionian.app", "productName": "Ionian", @@ -33,20 +28,9 @@ "app": "." } }, - "browserslist": { - "production": [ - "> 10%" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version" - ] - }, "author": "", "license": "ISC", "dependencies": { - "@material-ui/core": "^4.11.2", - "@material-ui/icons": "^4.11.2", "jsonwebtoken": "^8.5.1", "knex": "^0.21.14", "koa": "^2.13.0", @@ -54,40 +38,19 @@ "koa-router": "^10.0.0", "natural-orderby": "^2.0.3", "node-stream-zip": "^1.12.0", - "react": "^17.0.1", - "react-dom": "^17.0.1", - "react-router-dom": "^5.2.0", "sqlite3": "^5.0.0" }, "devDependencies": { - "@babel/core": "^7.12.10", - "@babel/plugin-proposal-class-properties": "^7.12.1", - "@babel/plugin-proposal-object-rest-spread": "^7.12.1", - "@babel/preset-env": "^7.12.11", - "@babel/preset-react": "^7.12.10", - "@babel/preset-typescript": "^7.12.7", "@types/jsonwebtoken": "^8.5.0", "@types/knex": "^0.16.1", "@types/koa": "^2.11.6", "@types/koa-bodyparser": "^4.3.0", "@types/koa-router": "^7.4.1", "@types/node": "^14.14.16", - "@types/react": "^17.0.0", - "@types/react-dom": "^17.0.0", - "@types/react-router-dom": "^5.1.7", - "babel-core": "^6.26.3", - "babel-loader": "^8.2.2", - "css-loader": "^5.0.1", "electron": "^11.1.1", "electron-builder": "^22.9.1", "eslint-plugin-node": "^11.1.0", - "mini-css-extract-plugin": "^1.3.3", - "style-loader": "^2.0.0", "ts-json-schema-generator": "^0.82.0", - "ts-node": "^9.1.1", - "typescript": "^4.1.3", - "webpack": "^5.11.0", - "webpack-cli": "^4.2.0", - "webpack-dev-server": "^3.11.0" + "typescript": "^4.1.3" } } diff --git a/.babelrc b/src/client/.babelrc similarity index 100% rename from .babelrc rename to src/client/.babelrc diff --git a/src/client/component/galleryinfo.tsx b/src/client/component/galleryinfo.tsx index 886e2e4..a65f155 100644 --- a/src/client/component/galleryinfo.tsx +++ b/src/client/component/galleryinfo.tsx @@ -6,36 +6,11 @@ import {Link as RouterLink} from 'react-router-dom'; import { LoadingCircle, ContentInfo, NavList, NavItem } from './mod'; import {toQueryString} from '../accessor/util'; - const useStyles = makeStyles((theme:Theme)=>({ root:{ display:"grid", gridGap: theme.spacing(4), }, - anchor_thumbnail:{ - background: '#272733', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - [theme.breakpoints.up("sm")]:{ - width: theme.spacing(25), - height: theme.spacing(25), - flexShrink: 0, - } - }, - contentPaper:{ - overflowY:'hidden', - display:'flex', - flexDirection: 'column', - [theme.breakpoints.up("sm")]:{ - height:200, - flexDirection: 'row', - }, - }, - content_thumnail: { - maxWidth: '100%', - maxHeight: '100%', - }, })); export type GalleryProp = { @@ -49,6 +24,7 @@ export const GalleryInfo = (props: GalleryProp)=>{ const [state,setState]= useState({documents:undefined}); useEffect(()=>{ const load = (async ()=>{ + console.log("mounted"); const c = await ContentAccessor.findList(props.option); //todo : if c is undefined, retry to fetch 3 times. and show error message. setState({documents:c}); diff --git a/src/client/package.json b/src/client/package.json new file mode 100644 index 0000000..2696b80 --- /dev/null +++ b/src/client/package.json @@ -0,0 +1,51 @@ +{ + "name": "ionian-client", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build:dev": "webpack --mode development", + "build:prod": "webpack --mode production", + "build:watch": "webpack --mode development -w", + "type-check": "tsc --noEmit" + }, + "author": "", + "license": "ISC", + "browserslist": { + "production": [ + "> 10%" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version" + ] + }, + "dependencies": { + "@material-ui/core": "^4.11.2", + "@material-ui/icons": "^4.11.2", + "react": "^17.0.1", + "react-dom": "^17.0.1", + "react-router-dom": "^5.2.0" + }, + "devDependencies": { + "@babel/core": "^7.12.10", + "@babel/plugin-proposal-class-properties": "^7.12.1", + "@babel/plugin-proposal-object-rest-spread": "^7.12.1", + "@babel/preset-env": "^7.12.11", + "@babel/preset-react": "^7.12.10", + "@babel/preset-typescript": "^7.12.7", + "@types/react": "^17.0.0", + "@types/react-dom": "^17.0.0", + "@types/react-router-dom": "^5.1.7", + "babel-core": "^6.26.3", + "babel-loader": "^8.2.2", + "css-loader": "^5.0.1", + "eslint-plugin-node": "^11.1.0", + "mini-css-extract-plugin": "^1.3.3", + "style-loader": "^2.0.0", + "ts-json-schema-generator": "^0.82.0", + "typescript": "^4.1.3", + "webpack": "^5.15.0", + "webpack-cli": "^4.3.1" + } +} diff --git a/src/client/page/profile.tsx b/src/client/page/profile.tsx index 3ef63b5..b9fa9bb 100644 --- a/src/client/page/profile.tsx +++ b/src/client/page/profile.tsx @@ -27,7 +27,7 @@ export function ProfilePage(){ const permission_list =userctx.permission.map(p=>( )); - const isElectronContent = window['electron'] !== undefined; + const isElectronContent = (((window['electron'] as any) !== undefined) as boolean); const handle_open = ()=>set_pw_open(true); const handle_close = ()=>{ set_pw_open(false); @@ -36,7 +36,7 @@ export function ProfilePage(){ }; const handle_ok= ()=>{ if(isElectronContent){ - const elec = window['electron']; + const elec = window['electron'] as any; if(newpw == newpwch){ const success = elec.passwordReset(userctx.username,newpw); if(!success){ diff --git a/src/client/state.tsx b/src/client/state.tsx index 5a1fd97..2e20d78 100644 --- a/src/client/state.tsx +++ b/src/client/state.tsx @@ -50,8 +50,10 @@ export const doLogout = async ()=>{ method: 'POST', }); await res.json(); - localObj.refreshExpired = 0; - localObj.username = ""; - localObj.permission = []; + localObj = { + refreshExpired: 0, + username:"", + permission:[] + } window.localStorage.setItem("UserLoginContext", JSON.stringify(localObj)); } \ No newline at end of file diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json new file mode 100644 index 0000000..cec31c1 --- /dev/null +++ b/src/client/tsconfig.json @@ -0,0 +1,70 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./build", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} diff --git a/webpack.config.js b/src/client/webpack.config.js similarity index 53% rename from webpack.config.js rename to src/client/webpack.config.js index 32cba80..e560d30 100644 --- a/webpack.config.js +++ b/src/client/webpack.config.js @@ -2,9 +2,9 @@ const path = require("path"); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); module.exports = ()=>{return { - entry: './src/client/app.tsx', + entry: './app.tsx', output: { - path: path.resolve(__dirname, 'dist/js'), + path: path.resolve(__dirname, '../../dist/js'), filename: 'bundle.js' }, module: { @@ -14,6 +14,18 @@ module.exports = ()=>{return { exclude: /node_modules/, use: { loader: 'babel-loader', + options: { + babelrc: true,//why babelrc not working? why is webpack not reading '.babelrc'? + presets: [ + '@babel/preset-env', + '@babel/preset-typescript', + '@babel/preset-react' + ], + plugins: [ + '@babel/proposal-class-properties', + '@babel/proposal-object-rest-spread' + ] + } } }, { @@ -29,9 +41,5 @@ module.exports = ()=>{return { devtool: 'source-map', resolve: { extensions: ['.js','.css','.ts','.tsx'] - }, - devServer: { - historyApiFallback: true, - port: 3001 } };} \ No newline at end of file diff --git a/src/model/doc.ts b/src/model/doc.ts index 5134ce7..3203fb7 100644 --- a/src/model/doc.ts +++ b/src/model/doc.ts @@ -1,5 +1,6 @@ import {TagAccessor} from './tag'; import {check_type} from '../util/type_check' +import {JSONMap} from '../types/json'; export interface DocumentBody{ title : string, diff --git a/src/types/json.d.ts b/src/types/json.d.ts deleted file mode 100644 index 3ff8968..0000000 --- a/src/types/json.d.ts +++ /dev/null @@ -1,5 +0,0 @@ - -type JSONPrimitive = null|boolean|number|string; -interface JSONMap extends Record{} -interface JSONArray extends Array{}; -type JSONType = JSONMap|JSONPrimitive|JSONArray; \ No newline at end of file diff --git a/src/types/json.ts b/src/types/json.ts new file mode 100644 index 0000000..f927d45 --- /dev/null +++ b/src/types/json.ts @@ -0,0 +1,5 @@ + +export type JSONPrimitive = null|boolean|number|string; +export interface JSONMap extends Record{} +export interface JSONArray extends Array{}; +export type JSONType = JSONMap|JSONPrimitive|JSONArray; \ No newline at end of file diff --git a/src/util/type_check.js b/src/util/type_check.js new file mode 100644 index 0000000..0035642 --- /dev/null +++ b/src/util/type_check.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.check_type = void 0; +function check_type(obj, check_proto) { + for (const it in check_proto) { + let defined = check_proto[it]; + if (defined === undefined) + return false; + defined = defined.trim(); + if (defined.endsWith("[]")) { + if (!(obj[it] instanceof Array)) { + return false; + } + } + else if (defined !== typeof obj[it]) { + return false; + } + } + return true; +} +exports.check_type = check_type; +;