sliftutils 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -0
- package/builders/generateIndexDts.js +13 -9
- package/builders/hotReload.ts +3 -0
- package/index.d.ts +264 -264
- package/nodejs/exampleFile.ts +6 -0
- package/nodejs/server.ts +8 -10
- package/package.json +1 -1
- package/spec.txt +0 -3
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# sliftutils
|
|
2
|
+
|
|
3
|
+
A build system and utility library for MobX + Preact projects.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
### 1. Setup
|
|
8
|
+
|
|
9
|
+
The first thing you should do is call the setup function. They will give you a lot of boilerplate code which you can delete or keep (I recommend commiting first, so you can pick which boilerplate changes you want):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx slift-setup
|
|
13
|
+
# or
|
|
14
|
+
npx sliftsetup
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. Build or Watch
|
|
18
|
+
|
|
19
|
+
After setup, you can either **build** your project or **watch** for changes:
|
|
20
|
+
|
|
21
|
+
#### Build Commands
|
|
22
|
+
```bash
|
|
23
|
+
npx build-nodejs # Build Node.js application
|
|
24
|
+
npx build-web # Build web application
|
|
25
|
+
npx build-extension # Build browser extension
|
|
26
|
+
npx build-electron # Build Electron application
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Watch Commands
|
|
30
|
+
```bash
|
|
31
|
+
npx slift-watch --port 9876 "nodejs/*.ts" "nodejs/*.tsx" "yarn build-nodejs"
|
|
32
|
+
npx slift-watch --port 9877 "web/*.ts" "web/*.tsx" "yarn build-web"
|
|
33
|
+
npx slift-watch --port 9878 "extension/*.ts" "extension/*.tsx" "yarn build-extension"
|
|
34
|
+
npx slift-watch --port 9879 "electron/*.ts" "electron/*.tsx" "yarn build-electron"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 3. Run
|
|
38
|
+
|
|
39
|
+
After building, you can call the run functions:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
node ./build-nodejs/server.js # Run built Node.js app
|
|
43
|
+
node ./builders/webRun.js # Run web application
|
|
44
|
+
node ./node_modules/electron/cli.js ./build-electron/electronMain.js # Run Electron app
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or you can add your own scripts with special parameters if you want.
|
|
48
|
+
|
|
49
|
+
## Hot Reloading
|
|
50
|
+
|
|
51
|
+
### Optional Hot Reloading Function
|
|
52
|
+
|
|
53
|
+
You can optionally call the hot reloading function in your code if you want automatic reloading during development:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { enableHotReloading } from "sliftutils/builders/hotReload";
|
|
57
|
+
|
|
58
|
+
async function main() {
|
|
59
|
+
await enableHotReloading();
|
|
60
|
+
// Your application code here
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
main().catch(console.error);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Running Node.js Scripts Directly
|
|
67
|
+
|
|
68
|
+
Node.js scripts can be called directly with **typenode** without needing to bundle them:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
typenode ./nodejs/server.ts
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
When you call scripts directly with typenode, you can use hot reloading which allows you to hot reload per file by setting the `module.hotreload` flag or adding a `hotreload.flag` file.
|
|
75
|
+
|
|
76
|
+
#### Per-File Hot Reloading
|
|
77
|
+
|
|
78
|
+
To enable hot reloading for specific files, set the `module.hotreload` flag at the top of your file:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// Either set this flag on the files you want to hot reload
|
|
82
|
+
module.hotreload = true;
|
|
83
|
+
|
|
84
|
+
export function exampleFunction() {
|
|
85
|
+
return "Hello from exampleFile.ts";
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Alternatively, you can add a file called `hotreload.flag` in a folder, and everything in that folder and all child files will hot reload.
|
|
90
|
+
|
|
91
|
+
See `nodejs/exampleFile.ts` for an example of how to use the hot reload flag.
|
|
92
|
+
|
|
93
|
+
## Utilities
|
|
94
|
+
|
|
95
|
+
This package includes many utilities for MobX + Preact projects. To see what utilities are available, read the `index.d.ts` file in the package. The utilities will work with any MobX + Preact type projects.
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
|
100
|
+
|
|
@@ -3,41 +3,45 @@ const path = require("path");
|
|
|
3
3
|
|
|
4
4
|
function getAllDtsFiles(dir, fileList = []) {
|
|
5
5
|
const files = fs.readdirSync(dir);
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
for (const file of files) {
|
|
8
8
|
const filePath = path.join(dir, file);
|
|
9
9
|
const stat = fs.statSync(filePath);
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
if (stat.isDirectory()) {
|
|
12
12
|
getAllDtsFiles(filePath, fileList);
|
|
13
13
|
} else if (file.endsWith(".d.ts")) {
|
|
14
14
|
fileList.push(filePath);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
return fileList;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function generateIndexDts() {
|
|
22
22
|
const renderUtilsPath = path.join(__dirname, "..", "render-utils");
|
|
23
23
|
const dtsFiles = getAllDtsFiles(renderUtilsPath);
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
const modules = dtsFiles
|
|
26
26
|
.map(filePath => {
|
|
27
27
|
const relativePath = path.relative(renderUtilsPath, filePath);
|
|
28
28
|
const withoutExt = relativePath.replace(/\.d\.ts$/, "");
|
|
29
29
|
const modulePath = "sliftutils/render-utils/" + withoutExt.replace(/\\/g, "/");
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
const content = fs.readFileSync(filePath, "utf8");
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const indentedContent = content
|
|
33
|
+
.split("\n")
|
|
34
|
+
.map(line => line ? " " + line : line)
|
|
35
|
+
.join("\n");
|
|
36
|
+
|
|
37
|
+
return `declare module "${modulePath}" {\n${indentedContent}\n}`;
|
|
34
38
|
})
|
|
35
39
|
.sort()
|
|
36
40
|
.join("\n\n");
|
|
37
|
-
|
|
41
|
+
|
|
38
42
|
const outputPath = path.join(__dirname, "..", "index.d.ts");
|
|
39
43
|
const header = `// Auto-generated file. Do not edit manually.\n// Generated by: yarn generate-index-dts\n\n`;
|
|
40
|
-
|
|
44
|
+
|
|
41
45
|
fs.writeFileSync(outputPath, header + modules + "\n", "utf8");
|
|
42
46
|
console.log(`Generated ${outputPath} with ${dtsFiles.length} module declarations`);
|
|
43
47
|
}
|
package/builders/hotReload.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { watchFilesAndTriggerHotReloading } from "socket-function/hot/HotReloadController";
|
|
1
2
|
import { isInBrowser, isInChromeExtension, isInChromeExtensionBackground, isInChromeExtensionContentScript } from "../misc/environment";
|
|
2
3
|
|
|
3
4
|
const DEFAULT_WATCH_PORT = 9876;
|
|
@@ -14,6 +15,8 @@ export async function enableHotReloading(config?: {
|
|
|
14
15
|
watchPortHotReload(config?.port, () => {
|
|
15
16
|
window.location.reload();
|
|
16
17
|
});
|
|
18
|
+
} else {
|
|
19
|
+
watchFilesAndTriggerHotReloading();
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
|
package/index.d.ts
CHANGED
|
@@ -2,331 +2,331 @@
|
|
|
2
2
|
// Generated by: yarn generate-index-dts
|
|
3
3
|
|
|
4
4
|
declare module "sliftutils/render-utils/DropdownCustom" {
|
|
5
|
-
import preact from "preact";
|
|
6
|
-
import { LengthOrPercentage } from "typesafecss/cssTypes";
|
|
7
|
-
export declare class DropdownCustom<T> extends preact.Component<{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
value: T;
|
|
12
|
-
onChange: (value: T, index: number) => void;
|
|
13
|
-
maxWidth?: LengthOrPercentage;
|
|
14
|
-
options: {
|
|
5
|
+
import preact from "preact";
|
|
6
|
+
import { LengthOrPercentage } from "typesafecss/cssTypes";
|
|
7
|
+
export declare class DropdownCustom<T> extends preact.Component<{
|
|
8
|
+
class?: string;
|
|
9
|
+
optionClass?: string;
|
|
10
|
+
title?: string;
|
|
15
11
|
value: T;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
onChange: (value: T, index: number) => void;
|
|
13
|
+
maxWidth?: LengthOrPercentage;
|
|
14
|
+
options: {
|
|
15
|
+
value: T;
|
|
16
|
+
label: (isOpen: boolean) => preact.ComponentChild;
|
|
17
|
+
}[];
|
|
18
|
+
}> {
|
|
19
|
+
synced: {
|
|
20
|
+
isOpen: boolean;
|
|
21
|
+
tempIndexSelected: number | null;
|
|
22
|
+
};
|
|
23
|
+
onUnmount: (() => void)[];
|
|
24
|
+
componentDidMount(): void;
|
|
25
|
+
componentDidUnmount(): void;
|
|
26
|
+
render(): preact.JSX.Element;
|
|
27
|
+
}
|
|
28
28
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
declare module "sliftutils/render-utils/FullscreenModal" {
|
|
32
|
-
import preact from "preact";
|
|
33
|
-
export declare function showFullscreenModal(contents: preact.ComponentChildren): void;
|
|
34
|
-
export declare class FullscreenModal extends preact.Component<{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}> {
|
|
42
|
-
|
|
43
|
-
}
|
|
32
|
+
import preact from "preact";
|
|
33
|
+
export declare function showFullscreenModal(contents: preact.ComponentChildren): void;
|
|
34
|
+
export declare class FullscreenModal extends preact.Component<{
|
|
35
|
+
parentState?: {
|
|
36
|
+
open: boolean;
|
|
37
|
+
};
|
|
38
|
+
onCancel?: () => void;
|
|
39
|
+
style?: preact.JSX.CSSProperties;
|
|
40
|
+
outerStyle?: preact.JSX.CSSProperties;
|
|
41
|
+
}> {
|
|
42
|
+
render(): preact.JSX.Element;
|
|
43
|
+
}
|
|
44
44
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
declare module "sliftutils/render-utils/Input" {
|
|
48
|
-
import preact from "preact";
|
|
49
|
-
export type InputProps = (preact.JSX.HTMLAttributes<HTMLInputElement> & {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
export declare class Input extends preact.Component<InputProps> {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
48
|
+
import preact from "preact";
|
|
49
|
+
export type InputProps = (preact.JSX.HTMLAttributes<HTMLInputElement> & {
|
|
50
|
+
/** ONLY throttles onChangeValue */
|
|
51
|
+
throttle?: number;
|
|
52
|
+
flavor?: "large" | "small" | "none";
|
|
53
|
+
focusOnMount?: boolean;
|
|
54
|
+
textarea?: boolean;
|
|
55
|
+
/** Update on key stroke, not on blur (just does onInput = onChange, as onInput already does this) */
|
|
56
|
+
hot?: boolean;
|
|
57
|
+
/** Updates arrow keys with modifier behavior to use larger numbers, instead of decimals. */
|
|
58
|
+
integer?: boolean;
|
|
59
|
+
/** Only works with number/integer */
|
|
60
|
+
reverseArrowKeyDirection?: boolean;
|
|
61
|
+
inputRef?: (x: HTMLInputElement | null) => void;
|
|
62
|
+
/** Don't blur on enter key */
|
|
63
|
+
noEnterKeyBlur?: boolean;
|
|
64
|
+
noFocusSelect?: boolean;
|
|
65
|
+
inputKey?: string;
|
|
66
|
+
fillWidth?: boolean;
|
|
67
|
+
autocompleteValues?: string[];
|
|
68
|
+
/** Forces the input to update when focused. Usually we hold updates, to prevent the user's
|
|
69
|
+
* typing to be interrupted by background updates.
|
|
70
|
+
* NOTE: "hot" is usually required when using this.
|
|
71
|
+
*/
|
|
72
|
+
forceInputValueUpdatesWhenFocused?: boolean;
|
|
73
|
+
onChangeValue?: (value: string) => void;
|
|
74
|
+
});
|
|
75
|
+
export declare class Input extends preact.Component<InputProps> {
|
|
76
|
+
onFocusText: string;
|
|
77
|
+
firstFocus: boolean;
|
|
78
|
+
elem: HTMLInputElement | null;
|
|
79
|
+
lastValue: unknown;
|
|
80
|
+
lastChecked: unknown;
|
|
81
|
+
onChangeThrottle: undefined | {
|
|
82
|
+
throttle: number;
|
|
83
|
+
run: (newValue: string) => void;
|
|
84
|
+
};
|
|
85
|
+
render(): preact.JSX.Element;
|
|
86
|
+
}
|
|
87
87
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
declare module "sliftutils/render-utils/InputLabel" {
|
|
91
|
-
import preact from "preact";
|
|
92
|
-
import { InputProps } from "./Input";
|
|
93
|
-
import { URLParamStr } from "./URLParam";
|
|
94
|
-
export type InputLabelProps = Omit<InputProps, "label" | "title"> & {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
};
|
|
111
|
-
export declare const startGuessDateRange: number;
|
|
112
|
-
export declare const endGuessDateRange: number;
|
|
113
|
-
export declare class InputLabel extends preact.Component<InputLabelProps> {
|
|
114
|
-
synced: {
|
|
115
|
-
editting: boolean;
|
|
116
|
-
editInputValue: string;
|
|
117
|
-
editUpdateSeqNum: number;
|
|
91
|
+
import preact from "preact";
|
|
92
|
+
import { InputProps } from "./Input";
|
|
93
|
+
import { URLParamStr } from "./URLParam";
|
|
94
|
+
export type InputLabelProps = Omit<InputProps, "label" | "title"> & {
|
|
95
|
+
label?: preact.ComponentChild;
|
|
96
|
+
number?: boolean;
|
|
97
|
+
/** A number, AND, an integer. Changes behavior arrow arrow keys as well */
|
|
98
|
+
integer?: boolean;
|
|
99
|
+
checkbox?: boolean;
|
|
100
|
+
edit?: boolean;
|
|
101
|
+
alwaysShowPencil?: boolean;
|
|
102
|
+
outerClass?: string;
|
|
103
|
+
maxDecimals?: number;
|
|
104
|
+
percent?: boolean;
|
|
105
|
+
editClass?: string;
|
|
106
|
+
fontSize?: number;
|
|
107
|
+
tooltip?: string;
|
|
108
|
+
fillWidth?: boolean;
|
|
109
|
+
useDateUI?: boolean;
|
|
118
110
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
export declare class
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
export declare const startGuessDateRange: number;
|
|
112
|
+
export declare const endGuessDateRange: number;
|
|
113
|
+
export declare class InputLabel extends preact.Component<InputLabelProps> {
|
|
114
|
+
synced: {
|
|
115
|
+
editting: boolean;
|
|
116
|
+
editInputValue: string;
|
|
117
|
+
editUpdateSeqNum: number;
|
|
118
|
+
};
|
|
119
|
+
render(): preact.JSX.Element;
|
|
120
|
+
}
|
|
121
|
+
export declare class InputLabelURL extends preact.Component<InputLabelProps & {
|
|
122
|
+
persisted: URLParamStr;
|
|
123
|
+
}> {
|
|
124
|
+
render(): preact.JSX.Element;
|
|
125
|
+
}
|
|
126
126
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
declare module "sliftutils/render-utils/InputPicker" {
|
|
130
|
-
import preact from "preact";
|
|
131
|
-
export type InputOption<T> = {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
export type FullInputOption<T> = {
|
|
137
|
-
value: T;
|
|
138
|
-
label: preact.ComponentChild;
|
|
139
|
-
matchText: string;
|
|
140
|
-
};
|
|
141
|
-
export declare class InputPickerURL extends preact.Component<{
|
|
142
|
-
label?: preact.ComponentChild;
|
|
143
|
-
options: (string | InputOption<string>)[];
|
|
144
|
-
allowNonOptions?: boolean;
|
|
145
|
-
value: {
|
|
146
|
-
value: string;
|
|
130
|
+
import preact from "preact";
|
|
131
|
+
export type InputOption<T> = {
|
|
132
|
+
value: T;
|
|
133
|
+
label?: preact.ComponentChild;
|
|
134
|
+
matchText?: string;
|
|
147
135
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
label?: preact.ComponentChild;
|
|
153
|
-
picked: T[];
|
|
154
|
-
options: InputOption<T>[];
|
|
155
|
-
addPicked: (value: T) => void;
|
|
156
|
-
removePicked: (value: T) => void;
|
|
157
|
-
allowNonOptions?: boolean;
|
|
158
|
-
}> {
|
|
159
|
-
synced: {
|
|
160
|
-
pendingText: string;
|
|
161
|
-
focused: boolean;
|
|
136
|
+
export type FullInputOption<T> = {
|
|
137
|
+
value: T;
|
|
138
|
+
label: preact.ComponentChild;
|
|
139
|
+
matchText: string;
|
|
162
140
|
};
|
|
163
|
-
|
|
164
|
-
|
|
141
|
+
export declare class InputPickerURL extends preact.Component<{
|
|
142
|
+
label?: preact.ComponentChild;
|
|
143
|
+
options: (string | InputOption<string>)[];
|
|
144
|
+
allowNonOptions?: boolean;
|
|
145
|
+
value: {
|
|
146
|
+
value: string;
|
|
147
|
+
};
|
|
148
|
+
}> {
|
|
149
|
+
render(): preact.JSX.Element;
|
|
150
|
+
}
|
|
151
|
+
export declare class InputPicker<T> extends preact.Component<{
|
|
152
|
+
label?: preact.ComponentChild;
|
|
153
|
+
picked: T[];
|
|
154
|
+
options: InputOption<T>[];
|
|
155
|
+
addPicked: (value: T) => void;
|
|
156
|
+
removePicked: (value: T) => void;
|
|
157
|
+
allowNonOptions?: boolean;
|
|
158
|
+
}> {
|
|
159
|
+
synced: {
|
|
160
|
+
pendingText: string;
|
|
161
|
+
focused: boolean;
|
|
162
|
+
};
|
|
163
|
+
render(): preact.JSX.Element;
|
|
164
|
+
}
|
|
165
165
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
declare module "sliftutils/render-utils/LocalStorageParam" {
|
|
169
|
-
export declare class LocalStorageParamStr {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
169
|
+
export declare class LocalStorageParamStr {
|
|
170
|
+
readonly storageKey: string;
|
|
171
|
+
private defaultValue;
|
|
172
|
+
private state;
|
|
173
|
+
lastSetValue: string;
|
|
174
|
+
constructor(storageKey: string, defaultValue?: string);
|
|
175
|
+
forceUpdate(): void;
|
|
176
|
+
get(): string;
|
|
177
|
+
set(value: string): void;
|
|
178
|
+
get value(): string;
|
|
179
|
+
set value(value: string);
|
|
180
|
+
}
|
|
181
181
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
declare module "sliftutils/render-utils/SyncedController" {
|
|
185
|
-
import { SocketRegistered } from "socket-function/SocketFunctionTypes";
|
|
186
|
-
type RemapFunction<T> = T extends (...args: infer Args) => Promise<infer Return> ? {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
} : T;
|
|
199
|
-
export declare function getSyncedController<T extends SocketRegistered>(controller: T, config?: {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}): {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
185
|
+
import { SocketRegistered } from "socket-function/SocketFunctionTypes";
|
|
186
|
+
type RemapFunction<T> = T extends (...args: infer Args) => Promise<infer Return> ? {
|
|
187
|
+
(...args: Args): Return | undefined;
|
|
188
|
+
promise(...args: Args): Promise<Return>;
|
|
189
|
+
refresh(...args: Args): void;
|
|
190
|
+
refreshAll(): void;
|
|
191
|
+
reset(...args: Args): void;
|
|
192
|
+
resetAll(): void;
|
|
193
|
+
isLoading(...args: Args): boolean;
|
|
194
|
+
setCache(cache: {
|
|
195
|
+
args: Args;
|
|
196
|
+
result: Return;
|
|
197
|
+
}): void;
|
|
198
|
+
} : T;
|
|
199
|
+
export declare function getSyncedController<T extends SocketRegistered>(controller: T, config?: {
|
|
200
|
+
/** When a controller call for a write finishes, we refresh all readers.
|
|
201
|
+
* - Invalidation is global, across all controllers.
|
|
202
|
+
*/
|
|
203
|
+
reads?: {
|
|
204
|
+
[key in keyof T["nodes"][""]]?: string[];
|
|
205
|
+
};
|
|
206
|
+
writes?: {
|
|
207
|
+
[key in keyof T["nodes"][""]]?: string[];
|
|
208
|
+
};
|
|
209
|
+
}): {
|
|
210
|
+
(nodeId: string): {
|
|
211
|
+
[fnc in keyof T["nodes"][""]]: RemapFunction<T["nodes"][""][fnc]>;
|
|
212
|
+
} & {
|
|
213
|
+
resetAll(): void;
|
|
214
|
+
refreshAll(): void;
|
|
215
|
+
anyPending(): boolean;
|
|
216
|
+
};
|
|
213
217
|
resetAll(): void;
|
|
214
218
|
refreshAll(): void;
|
|
215
219
|
anyPending(): boolean;
|
|
220
|
+
rerenderAll(): void;
|
|
216
221
|
};
|
|
217
|
-
|
|
218
|
-
refreshAll(): void;
|
|
219
|
-
anyPending(): boolean;
|
|
220
|
-
rerenderAll(): void;
|
|
221
|
-
};
|
|
222
|
-
export {};
|
|
222
|
+
export {};
|
|
223
223
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
declare module "sliftutils/render-utils/SyncedLoadingIndicator" {
|
|
227
|
-
import * as preact from "preact";
|
|
228
|
-
export declare class SyncedLoadingIndicator extends preact.Component<{
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}> {
|
|
233
|
-
|
|
234
|
-
}
|
|
227
|
+
import * as preact from "preact";
|
|
228
|
+
export declare class SyncedLoadingIndicator extends preact.Component<{
|
|
229
|
+
controller: {
|
|
230
|
+
anyPending: () => boolean;
|
|
231
|
+
};
|
|
232
|
+
}> {
|
|
233
|
+
render(): preact.JSX.Element | null;
|
|
234
|
+
}
|
|
235
235
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
declare module "sliftutils/render-utils/Table" {
|
|
239
|
-
import preact from "preact";
|
|
240
|
-
import { JSXFormatter } from "./GenericFormat";
|
|
241
|
-
export type ColumnType<T = unknown, Row extends RowType = RowType> = undefined | null | {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
};
|
|
246
|
-
export type RowType = {
|
|
247
|
-
[columnName: string]: unknown;
|
|
248
|
-
};
|
|
249
|
-
export type ColumnsType = {
|
|
250
|
-
[columnName: string]: ColumnType;
|
|
251
|
-
};
|
|
252
|
-
export type TableType<RowT extends RowType = RowType> = {
|
|
253
|
-
columns: {
|
|
254
|
-
[columnName in keyof RowT]?: ColumnType<RowT[columnName], RowT>;
|
|
239
|
+
import preact from "preact";
|
|
240
|
+
import { JSXFormatter } from "./GenericFormat";
|
|
241
|
+
export type ColumnType<T = unknown, Row extends RowType = RowType> = undefined | null | {
|
|
242
|
+
center?: boolean;
|
|
243
|
+
title?: preact.ComponentChild;
|
|
244
|
+
formatter?: JSXFormatter<T, Row>;
|
|
255
245
|
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
export declare class Table<RowT extends RowType> extends preact.Component<TableType<RowT> & {
|
|
259
|
-
class?: string;
|
|
260
|
-
cellClass?: string;
|
|
261
|
-
initialLimit?: number;
|
|
262
|
-
lineLimit?: number;
|
|
263
|
-
characterLimit?: number;
|
|
264
|
-
excludeEmptyColumns?: boolean;
|
|
265
|
-
}> {
|
|
266
|
-
state: {
|
|
267
|
-
limit: number;
|
|
246
|
+
export type RowType = {
|
|
247
|
+
[columnName: string]: unknown;
|
|
268
248
|
};
|
|
269
|
-
|
|
270
|
-
|
|
249
|
+
export type ColumnsType = {
|
|
250
|
+
[columnName: string]: ColumnType;
|
|
251
|
+
};
|
|
252
|
+
export type TableType<RowT extends RowType = RowType> = {
|
|
253
|
+
columns: {
|
|
254
|
+
[columnName in keyof RowT]?: ColumnType<RowT[columnName], RowT>;
|
|
255
|
+
};
|
|
256
|
+
rows: RowT[];
|
|
257
|
+
};
|
|
258
|
+
export declare class Table<RowT extends RowType> extends preact.Component<TableType<RowT> & {
|
|
259
|
+
class?: string;
|
|
260
|
+
cellClass?: string;
|
|
261
|
+
initialLimit?: number;
|
|
262
|
+
lineLimit?: number;
|
|
263
|
+
characterLimit?: number;
|
|
264
|
+
excludeEmptyColumns?: boolean;
|
|
265
|
+
}> {
|
|
266
|
+
state: {
|
|
267
|
+
limit: number;
|
|
268
|
+
};
|
|
269
|
+
render(): preact.JSX.Element;
|
|
270
|
+
}
|
|
271
271
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
declare module "sliftutils/render-utils/URLParam" {
|
|
275
|
-
export declare class URLParamStr {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
export declare function batchUrlUpdate<T>(code: () => T): T;
|
|
287
|
-
export declare function createLink(params: [URLParamStr, string][]): string;
|
|
275
|
+
export declare class URLParamStr {
|
|
276
|
+
readonly urlKey: string;
|
|
277
|
+
private state;
|
|
278
|
+
lastSetValue: string;
|
|
279
|
+
constructor(urlKey: string);
|
|
280
|
+
forceUpdate(): void;
|
|
281
|
+
get(): string;
|
|
282
|
+
set(value: string): void;
|
|
283
|
+
get value(): string;
|
|
284
|
+
set value(value: string);
|
|
285
|
+
}
|
|
286
|
+
export declare function batchUrlUpdate<T>(code: () => T): T;
|
|
287
|
+
export declare function createLink(params: [URLParamStr, string][]): string;
|
|
288
288
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
declare module "sliftutils/render-utils/asyncObservable" {
|
|
292
|
-
export declare function asyncCache<Args, T>(getValue: (args: Args) => Promise<T>): {
|
|
293
|
-
|
|
294
|
-
};
|
|
292
|
+
export declare function asyncCache<Args, T>(getValue: (args: Args) => Promise<T>): {
|
|
293
|
+
(args: Args): T | undefined;
|
|
294
|
+
};
|
|
295
295
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
declare module "sliftutils/render-utils/mobxTyped" {
|
|
299
|
-
export declare function configureMobxNextFrameScheduler(): void;
|
|
299
|
+
export declare function configureMobxNextFrameScheduler(): void;
|
|
300
300
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
declare module "sliftutils/render-utils/modal" {
|
|
304
|
-
import preact from "preact";
|
|
305
|
-
export declare function showModal(config: {
|
|
306
|
-
|
|
307
|
-
}): {
|
|
308
|
-
|
|
309
|
-
};
|
|
304
|
+
import preact from "preact";
|
|
305
|
+
export declare function showModal(config: {
|
|
306
|
+
contents: preact.ComponentChildren;
|
|
307
|
+
}): {
|
|
308
|
+
close: () => void;
|
|
309
|
+
};
|
|
310
310
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
declare module "sliftutils/render-utils/observer" {
|
|
314
|
-
import * as preact from "preact";
|
|
315
|
-
import { Reaction } from "mobx";
|
|
316
|
-
export declare function observer<T extends {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}>(Constructor: T): {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
} & T;
|
|
314
|
+
import * as preact from "preact";
|
|
315
|
+
import { Reaction } from "mobx";
|
|
316
|
+
export declare function observer<T extends {
|
|
317
|
+
new (...args: any[]): {
|
|
318
|
+
render(): preact.ComponentChild;
|
|
319
|
+
forceUpdate(callback?: () => void): void;
|
|
320
|
+
componentWillUnmount?(): void;
|
|
321
|
+
};
|
|
322
|
+
}>(Constructor: T): {
|
|
323
|
+
new (...args: any[]): {
|
|
324
|
+
reaction: Reaction;
|
|
325
|
+
componentWillUnmount(): void;
|
|
326
|
+
render(...args: any[]): preact.ComponentChild;
|
|
327
|
+
forceUpdate(callback?: () => void): void;
|
|
328
|
+
};
|
|
329
|
+
readonly name: string;
|
|
330
|
+
} & T;
|
|
331
331
|
|
|
332
332
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Either set this flag on the files you want to hot reload, or add a file called hotreload.flag and that folder, everything in it and all the child uh files will hot reload.
|
|
2
|
+
module.hotreload = true;
|
|
3
|
+
|
|
4
|
+
export function exampleFunction() {
|
|
5
|
+
return "Hello from exampleFile.ts";
|
|
6
|
+
}
|
package/nodejs/server.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { delay } from "socket-function/src/batching";
|
|
2
|
+
import { exampleFunction } from "./exampleFile";
|
|
3
|
+
import { enableHotReloading } from "../builders/hotReload";
|
|
2
4
|
|
|
3
5
|
async function main() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const port = 3000;
|
|
10
|
-
server.listen(port, () => {
|
|
11
|
-
console.log(`Server running at http://localhost:${port}/`);
|
|
12
|
-
});
|
|
6
|
+
await enableHotReloading();
|
|
7
|
+
while (true) {
|
|
8
|
+
console.log(exampleFunction());
|
|
9
|
+
await delay(1000);
|
|
10
|
+
}
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
main().catch(console.error);
|
package/package.json
CHANGED