@basthon/console-react 0.3.1 → 0.3.3
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/lib/components/app.d.ts +1 -0
- package/lib/components/app.js +9 -4
- package/lib/gui/editor.d.ts +1 -3
- package/lib/gui/editor.js +3 -12
- package/lib/gui/gui.d.ts +1 -2
- package/lib/gui/gui.js +2 -3
- package/lib/state-manager.d.ts +1 -1
- package/lib/state-manager.js +8 -4
- package/package.json +1 -1
package/lib/components/app.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { FC, PropsWithChildren } from "react";
|
|
|
2
2
|
import { type BasthonContextProps } from "@basthon/gui-react";
|
|
3
3
|
import { type Theme } from "../state-manager";
|
|
4
4
|
interface InnerAppProps {
|
|
5
|
+
initFromStorage?: boolean;
|
|
5
6
|
forceTheme?: Theme;
|
|
6
7
|
compactHeader?: boolean;
|
|
7
8
|
onChangeEditor?: () => void;
|
package/lib/components/app.js
CHANGED
|
@@ -9,10 +9,10 @@ import { Header } from "./header";
|
|
|
9
9
|
import { MainContainer } from "./main-container";
|
|
10
10
|
import { Footer } from "./footer";
|
|
11
11
|
import * as styles from "./styles.module.scss";
|
|
12
|
-
const InnerApp = ({ forceTheme, compactHeader, onChangeEditor, children, }) => {
|
|
12
|
+
const InnerApp = ({ initFromStorage, forceTheme, compactHeader, onChangeEditor, children, }) => {
|
|
13
13
|
const gui = useGUI();
|
|
14
14
|
// state
|
|
15
|
-
const [state, dispatch] = stateManager.useReducer(gui.language);
|
|
15
|
+
const [state, dispatch] = stateManager.useReducer(gui.language, initFromStorage ?? true);
|
|
16
16
|
const language = stateManager.language(state);
|
|
17
17
|
const theme = forceTheme != null ? forceTheme : stateManager.theme(state);
|
|
18
18
|
// set data-theme for basthon-loader footer
|
|
@@ -29,9 +29,14 @@ const InnerApp = ({ forceTheme, compactHeader, onChangeEditor, children, }) => {
|
|
|
29
29
|
/**
|
|
30
30
|
* Main app setting up state manager, header, main container and footer.
|
|
31
31
|
*/
|
|
32
|
-
const ConsoleApp = ({ forceTheme, compactHeader, onChangeEditor, children, ...props }) => {
|
|
32
|
+
const ConsoleApp = ({ initFromStorage, forceTheme, compactHeader, onChangeEditor, children, ...props }) => {
|
|
33
33
|
props.GUI = GUI;
|
|
34
|
-
const innerProps = {
|
|
34
|
+
const innerProps = {
|
|
35
|
+
initFromStorage,
|
|
36
|
+
forceTheme,
|
|
37
|
+
compactHeader,
|
|
38
|
+
onChangeEditor,
|
|
39
|
+
};
|
|
35
40
|
return (_jsx(BasthonContext, { ...props, children: _jsx(InnerApp, { ...innerProps, children: children }) }));
|
|
36
41
|
};
|
|
37
42
|
export default ConsoleApp;
|
package/lib/gui/editor.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export default class Editor {
|
|
|
7
7
|
private _kernel;
|
|
8
8
|
private _editor;
|
|
9
9
|
private _onSetContent?;
|
|
10
|
-
private _silentChange;
|
|
11
10
|
constructor(element: HTMLElement, kernel: KernelBase, onSetContent?: (_: string) => void, onChange?: () => void);
|
|
12
11
|
/**
|
|
13
12
|
* Set Ace mode from language.
|
|
@@ -19,9 +18,8 @@ export default class Editor {
|
|
|
19
18
|
setTheme(theme: Theme): Promise<void>;
|
|
20
19
|
/**
|
|
21
20
|
* Dispatch action to set content.
|
|
22
|
-
* If silent is true, editor's onChange is not triggered.
|
|
23
21
|
*/
|
|
24
|
-
setContent(content: string
|
|
22
|
+
setContent(content: string): void;
|
|
25
23
|
/**
|
|
26
24
|
* Set Ace editor content.
|
|
27
25
|
*/
|
package/lib/gui/editor.js
CHANGED
|
@@ -4,7 +4,6 @@ import ace from "./ace";
|
|
|
4
4
|
*/
|
|
5
5
|
export default class Editor {
|
|
6
6
|
constructor(element, kernel, onSetContent, onChange) {
|
|
7
|
-
this._silentChange = false;
|
|
8
7
|
this._kernel = kernel;
|
|
9
8
|
this._onSetContent = onSetContent;
|
|
10
9
|
this._editor = ace.edit(element);
|
|
@@ -17,11 +16,7 @@ export default class Editor {
|
|
|
17
16
|
});
|
|
18
17
|
// connect onchange
|
|
19
18
|
if (onChange != null)
|
|
20
|
-
this._editor.session.on("change", () =>
|
|
21
|
-
if (!this._silentChange)
|
|
22
|
-
onChange();
|
|
23
|
-
this._silentChange = false;
|
|
24
|
-
});
|
|
19
|
+
this._editor.session.on("change", () => onChange());
|
|
25
20
|
/* editor's completion */
|
|
26
21
|
// removing all completers and keeping track of local completer
|
|
27
22
|
const localCompleter = this._editor.completers[1]; // any hint to detect this dynamically?
|
|
@@ -88,10 +83,8 @@ export default class Editor {
|
|
|
88
83
|
}
|
|
89
84
|
/**
|
|
90
85
|
* Dispatch action to set content.
|
|
91
|
-
* If silent is true, editor's onChange is not triggered.
|
|
92
86
|
*/
|
|
93
|
-
setContent(content
|
|
94
|
-
this._silentChange = silent === true;
|
|
87
|
+
setContent(content) {
|
|
95
88
|
this._onSetContent?.(content);
|
|
96
89
|
}
|
|
97
90
|
/**
|
|
@@ -99,9 +92,7 @@ export default class Editor {
|
|
|
99
92
|
*/
|
|
100
93
|
setContentNoDispatch(content) {
|
|
101
94
|
if (content != null)
|
|
102
|
-
this._editor.setValue(content);
|
|
103
|
-
this._editor.scrollToRow(0);
|
|
104
|
-
this._editor.gotoLine(0, 0, false);
|
|
95
|
+
this._editor.setValue(content, -1);
|
|
105
96
|
}
|
|
106
97
|
/**
|
|
107
98
|
* Get editor's content
|
package/lib/gui/gui.d.ts
CHANGED
|
@@ -39,9 +39,8 @@ export default class GUI extends GUIBase {
|
|
|
39
39
|
content(): string;
|
|
40
40
|
/**
|
|
41
41
|
* Set editor's content.
|
|
42
|
-
* If silent is true, editor's onChange is not triggered.
|
|
43
42
|
*/
|
|
44
|
-
setContent(content: string
|
|
43
|
+
setContent(content: string): void;
|
|
45
44
|
/**
|
|
46
45
|
* Notify the user with an error.
|
|
47
46
|
*/
|
package/lib/gui/gui.js
CHANGED
|
@@ -62,10 +62,9 @@ export default class GUI extends GUIBase {
|
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Set editor's content.
|
|
65
|
-
* If silent is true, editor's onChange is not triggered.
|
|
66
65
|
*/
|
|
67
|
-
setContent(content
|
|
68
|
-
this._editor?.setContent(content
|
|
66
|
+
setContent(content) {
|
|
67
|
+
this._editor?.setContent(content);
|
|
69
68
|
}
|
|
70
69
|
/**
|
|
71
70
|
* Notify the user with an error.
|
package/lib/state-manager.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ interface Action {
|
|
|
17
17
|
payload?: Theme | ViewMode | RightPanel | State | string;
|
|
18
18
|
}
|
|
19
19
|
declare const stateManager: {
|
|
20
|
-
useReducer: (language: Language) => readonly [{
|
|
20
|
+
useReducer: (language: Language, initFromStorage: boolean) => readonly [{
|
|
21
21
|
language: Language;
|
|
22
22
|
ready: boolean;
|
|
23
23
|
theme: Theme;
|
package/lib/state-manager.js
CHANGED
|
@@ -42,7 +42,8 @@ const reducer = (state, action) => {
|
|
|
42
42
|
const { type, payload } = action;
|
|
43
43
|
switch (type) {
|
|
44
44
|
case "init": {
|
|
45
|
-
|
|
45
|
+
if (state != null)
|
|
46
|
+
state = copy(payload);
|
|
46
47
|
state.ready = true;
|
|
47
48
|
return state;
|
|
48
49
|
}
|
|
@@ -77,16 +78,19 @@ const reducer = (state, action) => {
|
|
|
77
78
|
};
|
|
78
79
|
/* stateManager exposed as API */
|
|
79
80
|
const stateManager = {
|
|
80
|
-
useReducer: (language) => {
|
|
81
|
+
useReducer: (language, initFromStorage) => {
|
|
81
82
|
const [state, dispatch] = useImmerReducer(reducer, {
|
|
82
83
|
...initialState,
|
|
83
84
|
language,
|
|
84
85
|
});
|
|
85
86
|
// dispatch init from storage
|
|
86
87
|
useEffect(() => {
|
|
87
|
-
|
|
88
|
+
(async () => {
|
|
89
|
+
let payload = undefined;
|
|
90
|
+
if (initFromStorage)
|
|
91
|
+
payload = await stateFromStorage(language);
|
|
88
92
|
dispatch({ type: "init", payload });
|
|
89
|
-
});
|
|
93
|
+
})();
|
|
90
94
|
}, []);
|
|
91
95
|
return [state, dispatch];
|
|
92
96
|
},
|