@nan0web/ui 1.12.3 → 3.1.1
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/package.json +29 -20
- package/src/Component/index.js +1 -5
- package/src/Model/Element.js +183 -0
- package/src/Theme/AppTheme.js +19 -0
- package/src/Theme/CustomTheme.js +32 -0
- package/src/Theme/DarkLightTheme.js +34 -0
- package/src/Theme/Theme.js +25 -0
- package/src/Theme/atoms/Avatar.js +20 -0
- package/src/Theme/atoms/Badge.js +28 -0
- package/src/Theme/atoms/Button.js +88 -0
- package/src/Theme/atoms/Checkbox.js +26 -0
- package/src/Theme/atoms/Input.js +28 -0
- package/src/Theme/atoms/Radio.js +26 -0
- package/src/Theme/atoms/Select.js +16 -0
- package/src/Theme/atoms/TextArea.js +17 -0
- package/src/Theme/atoms/Typography.js +26 -0
- package/src/Theme/atoms/index.js +11 -0
- package/src/Theme/createTheme.js +22 -0
- package/src/Theme/index.js +20 -0
- package/src/Theme/molecules/Card.js +24 -0
- package/src/Theme/molecules/index.js +3 -0
- package/src/Theme/organisms/Modal.js +24 -0
- package/src/Theme/organisms/index.js +3 -0
- package/src/Theme/presets/HighContrastTheme.js +65 -0
- package/src/Theme/presets/NightTheme.js +66 -0
- package/src/Theme/presets/index.js +4 -0
- package/src/Theme/tokens.js +115 -0
- package/src/core/InputAdapter.js +1 -2
- package/src/core/Intent.js +22 -8
- package/src/core/Message/Message.js +3 -0
- package/src/core/OutputAdapter.js +9 -13
- package/src/core/index.js +7 -4
- package/src/domain/ModelAsApp.js +1 -1
- package/src/domain/app/IntentAuditor.js +53 -0
- package/src/domain/app/JsIntentAuditor.js +145 -0
- package/src/domain/app/PyIntentAuditor.js +144 -0
- package/src/domain/app/SnapshotAuditor.js +8 -8
- package/src/domain/components/ShellModel.js +2 -2
- package/src/index.js +35 -9
- package/src/inspect.js +3 -0
- package/src/utils/format.js +21 -0
- package/src/utils/processI18n.js +27 -0
- package/src/utils/resolveContext.js +79 -0
- package/types/Component/index.d.ts +1 -5
- package/types/Model/Element.d.ts +87 -0
- package/types/Theme/AppTheme.d.ts +14 -0
- package/types/Theme/CustomTheme.d.ts +21 -0
- package/types/Theme/DarkLightTheme.d.ts +16 -0
- package/types/Theme/Theme.d.ts +18 -0
- package/types/Theme/atoms/Avatar.d.ts +14 -0
- package/types/Theme/atoms/Badge.d.ts +22 -0
- package/types/Theme/atoms/Button.d.ts +144 -0
- package/types/Theme/atoms/Checkbox.d.ts +20 -0
- package/types/Theme/atoms/Input.d.ts +22 -0
- package/types/Theme/atoms/Radio.d.ts +20 -0
- package/types/Theme/atoms/Select.d.ts +15 -0
- package/types/Theme/atoms/TextArea.d.ts +17 -0
- package/types/Theme/atoms/Typography.d.ts +47 -0
- package/types/Theme/atoms/index.d.ts +10 -0
- package/types/Theme/createTheme.d.ts +7 -0
- package/types/Theme/index.d.ts +10 -0
- package/types/Theme/molecules/Card.d.ts +18 -0
- package/types/Theme/molecules/index.d.ts +2 -0
- package/types/Theme/organisms/Modal.d.ts +18 -0
- package/types/Theme/organisms/index.d.ts +2 -0
- package/types/Theme/presets/HighContrastTheme.d.ts +2 -0
- package/types/Theme/presets/NightTheme.d.ts +2 -0
- package/types/Theme/presets/index.d.ts +3 -0
- package/types/Theme/tokens.d.ts +119 -0
- package/types/core/Intent.d.ts +10 -7
- package/types/core/Message/Message.d.ts +3 -0
- package/types/core/OutputAdapter.d.ts +2 -4
- package/types/core/index.d.ts +5 -2
- package/types/domain/Document.d.ts +2 -1
- package/types/domain/FooterModel.d.ts +2 -1
- package/types/domain/ModelAsApp.d.ts +48 -48
- package/types/domain/app/IntentAuditor.d.ts +23 -0
- package/types/domain/app/JsIntentAuditor.d.ts +22 -0
- package/types/domain/app/PyIntentAuditor.d.ts +22 -0
- package/types/domain/app/SnapshotAuditor.d.ts +5 -6
- package/types/domain/components/ShellModel.d.ts +1 -5
- package/types/index.d.ts +7 -9
- package/types/inspect.d.ts +3 -0
- package/types/utils/format.d.ts +5 -0
- package/types/utils/processI18n.d.ts +8 -0
- package/types/utils/resolveContext.d.ts +21 -0
- package/src/App/Command/DepsCommand.js +0 -24
- package/src/App/Core/CoreApp.js +0 -125
- package/src/App/Core/UI.js +0 -63
- package/src/App/Core/Widget.js +0 -61
- package/src/App/Core/index.js +0 -11
- package/src/App/Scenario.js +0 -45
- package/src/App/User/Command/Message.js +0 -3
- package/src/App/User/Command/index.js +0 -5
- package/src/App/User/UserApp.js +0 -85
- package/src/App/User/UserUI.js +0 -20
- package/src/App/User/index.js +0 -9
- package/src/App/index.js +0 -14
- package/src/Component/Process/Input.js +0 -63
- package/src/Component/Process/Process.js +0 -24
- package/src/Component/Process/index.js +0 -5
- package/src/Component/Welcome/Input.js +0 -48
- package/src/Component/Welcome/Welcome.js +0 -22
- package/src/Component/Welcome/index.js +0 -5
- package/src/Frame/Frame.js +0 -608
- package/src/Frame/Props.js +0 -96
- package/src/StdIn.js +0 -100
- package/src/StdOut.js +0 -95
- package/src/View/RenderOptions.js +0 -48
- package/src/View/View.js +0 -306
- package/src/core/Message/index.js +0 -6
- package/types/App/Command/DepsCommand.d.ts +0 -14
- package/types/App/Core/CoreApp.d.ts +0 -70
- package/types/App/Core/UI.d.ts +0 -38
- package/types/App/Core/Widget.d.ts +0 -39
- package/types/App/Core/index.d.ts +0 -10
- package/types/App/Scenario.d.ts +0 -26
- package/types/App/User/Command/Message.d.ts +0 -2
- package/types/App/User/Command/index.d.ts +0 -3
- package/types/App/User/UserApp.d.ts +0 -41
- package/types/App/User/UserUI.d.ts +0 -9
- package/types/App/User/index.d.ts +0 -8
- package/types/App/index.d.ts +0 -12
- package/types/Component/Process/Input.d.ts +0 -48
- package/types/Component/Process/Process.d.ts +0 -13
- package/types/Component/Process/index.d.ts +0 -4
- package/types/Component/Welcome/Input.d.ts +0 -34
- package/types/Component/Welcome/Welcome.d.ts +0 -13
- package/types/Component/Welcome/index.d.ts +0 -4
- package/types/Frame/Frame.d.ts +0 -186
- package/types/Frame/Props.d.ts +0 -77
- package/types/StdIn.d.ts +0 -62
- package/types/StdOut.d.ts +0 -52
- package/types/View/RenderOptions.d.ts +0 -29
- package/types/View/View.d.ts +0 -124
- package/types/core/Message/index.d.ts +0 -4
package/src/App/Scenario.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import App from './index.js'
|
|
2
|
-
import UI from './Core/UI.js'
|
|
3
|
-
|
|
4
|
-
/** @typedef {import("./Core/CoreApp.js").default} CoreApp */
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Abstract Scenario class to test app logic.
|
|
8
|
-
* Scenarios run input commands and verify output.
|
|
9
|
-
*/
|
|
10
|
-
export default class Scenario {
|
|
11
|
-
/** @type {CoreApp} The app to run scenarios against */
|
|
12
|
-
app
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Creates a new Scenario instance.
|
|
16
|
-
* @param {CoreApp} app - App instance to run scenarios against
|
|
17
|
-
* @param {UI} ui - User interface
|
|
18
|
-
* @throws {TypeError} If app is not an App.Core.App instance
|
|
19
|
-
*/
|
|
20
|
-
constructor(app, ui) {
|
|
21
|
-
if (!(app instanceof App.Core.App)) {
|
|
22
|
-
throw new TypeError('Scenario requires a App.Core.App instance')
|
|
23
|
-
}
|
|
24
|
-
this.app = app
|
|
25
|
-
this.ui = ui
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Run scenario with input commands and expected output.
|
|
30
|
-
* @param {Array<any[]>} inputCommands - Array of command arrays
|
|
31
|
-
* @param {Array<any>} expectedOutputs - Expected outputs for each command
|
|
32
|
-
* @returns {Promise<boolean>} True if all outputs match expected
|
|
33
|
-
*/
|
|
34
|
-
async run(inputCommands, expectedOutputs) {
|
|
35
|
-
const commandMessages = inputCommands.map((arr) => App.Command.Message.parse(arr))
|
|
36
|
-
const outputs = await this.app.processCommands(commandMessages, this.ui)
|
|
37
|
-
if (outputs.length !== expectedOutputs.length) return false
|
|
38
|
-
for (let i = 0; i < outputs.length; i++) {
|
|
39
|
-
if (JSON.stringify(outputs[i]) !== JSON.stringify(expectedOutputs[i])) {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return true
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/App/User/UserApp.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Message } from '@nan0web/co'
|
|
2
|
-
import { notEmpty } from '@nan0web/types'
|
|
3
|
-
import CoreApp from '../Core/CoreApp.js'
|
|
4
|
-
import User from '../../Model/User/User.js'
|
|
5
|
-
import UserUI from './UserUI.js'
|
|
6
|
-
import UserAppCommandMessage from './Command/Message.js'
|
|
7
|
-
import DepsCommand from './Command/Message.js'
|
|
8
|
-
import UIStream from '../../core/Stream.js'
|
|
9
|
-
import { StreamEntry, UiMessage } from '../../core/index.js'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* UserApp requires user name and shows Welcome view.
|
|
13
|
-
* If user.name is provided in command input, ignores user input.
|
|
14
|
-
* User can change user data to see another Welcome view.
|
|
15
|
-
*/
|
|
16
|
-
export default class UserApp extends CoreApp {
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new UserApp instance.
|
|
19
|
-
* @param {Partial<CoreApp>} [props={}] - UserApp properties
|
|
20
|
-
*/
|
|
21
|
-
constructor(props = {}) {
|
|
22
|
-
super(props)
|
|
23
|
-
this.registerCommand('setUser', this.setUser.bind(this))
|
|
24
|
-
this.registerCommand('welcome', this.welcome.bind(this))
|
|
25
|
-
this.registerCommand('deps', this.handleDeps.bind(this)) // Register new command
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Handle deps command with async generator for stream processing.
|
|
30
|
-
* @param {DepsCommand} cmd - Command message with deps parameters
|
|
31
|
-
* @param {UserUI} ui - UI instance
|
|
32
|
-
* @returns {Promise<Object>} Command output
|
|
33
|
-
*/
|
|
34
|
-
async handleDeps(cmd, ui) {
|
|
35
|
-
// Example: Use async generator to stream deps processing
|
|
36
|
-
const processorFn = async () =>
|
|
37
|
-
new StreamEntry({
|
|
38
|
-
value: { message: `Deps command executed with fix: ${cmd.body.fix}` },
|
|
39
|
-
done: true,
|
|
40
|
-
})
|
|
41
|
-
const generatorFn = UIStream.createProcessor(new AbortController().signal, processorFn)
|
|
42
|
-
await UIStream.process(
|
|
43
|
-
new AbortController().signal,
|
|
44
|
-
generatorFn,
|
|
45
|
-
(progress, item) => ui.output && ui.output(item.value), // Fix to output the value
|
|
46
|
-
(error) => ui.output && ui.output([error]), // Assume ui has output method
|
|
47
|
-
(item) => ui.output && ui.output(item.value), // Fix complete callback
|
|
48
|
-
)
|
|
49
|
-
return { completed: true }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Set user data from params.
|
|
54
|
-
* @param {UserAppCommandMessage} cmd - Command message with user data
|
|
55
|
-
* @param {UserUI} ui - UI instance
|
|
56
|
-
* @returns {Promise<{ message: string }>} Welcome message
|
|
57
|
-
*/
|
|
58
|
-
async setUser(cmd, ui) {
|
|
59
|
-
this.state.user = User.from(cmd.body.user) // cmd is UserAppCommandMessage, has user
|
|
60
|
-
const frame = await this.welcome(cmd, ui)
|
|
61
|
-
return {
|
|
62
|
-
message: String(frame),
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Show welcome message for current user.
|
|
68
|
-
* @param {UserAppCommandMessage} cmd - Command message
|
|
69
|
-
* @param {UserUI} ui - UI instance
|
|
70
|
-
* @returns {Promise<string[][]>} Welcome view output
|
|
71
|
-
*/
|
|
72
|
-
async welcome(cmd, ui) {
|
|
73
|
-
if (cmd.body.user) {
|
|
74
|
-
// cmd is UserAppCommandMessage, has user
|
|
75
|
-
const user = User.from(cmd.body.user)
|
|
76
|
-
return ui.render('Welcome', { user })
|
|
77
|
-
}
|
|
78
|
-
if (notEmpty(this.user)) {
|
|
79
|
-
return ui.render('Welcome', { user: this.user })
|
|
80
|
-
}
|
|
81
|
-
const answer = await ui.ask(UiMessage.from('What is your name?'))
|
|
82
|
-
this.user = User.from(answer?.body)
|
|
83
|
-
return ui.render('Welcome', { user: this.user })
|
|
84
|
-
}
|
|
85
|
-
}
|
package/src/App/User/UserUI.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Message } from '@nan0web/co'
|
|
2
|
-
import App from '../Core/index.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* UserUI connects UserApp and View.
|
|
6
|
-
* It asks user for name if not provided in command input.
|
|
7
|
-
* Allows user to change user data to see another Welcome view.
|
|
8
|
-
*/
|
|
9
|
-
export default class UserUI extends App.UI {
|
|
10
|
-
/**
|
|
11
|
-
* Convert raw input to Message array.
|
|
12
|
-
* If user.name provided in rawInput, use it directly.
|
|
13
|
-
* Otherwise ask user for name.
|
|
14
|
-
* @param {any} rawInput - Raw input to convert
|
|
15
|
-
* @returns {Message[]} Array of command messages
|
|
16
|
-
*/
|
|
17
|
-
convertInput(rawInput) {
|
|
18
|
-
return [new Message({ body: rawInput })]
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/App/User/index.js
DELETED
package/src/App/index.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents input data for the Process component.
|
|
3
|
-
* Holds configuration for rendering a progress bar.
|
|
4
|
-
*/
|
|
5
|
-
class ProcessInput {
|
|
6
|
-
/** @type {string} Process name to display */
|
|
7
|
-
name
|
|
8
|
-
|
|
9
|
-
/** @type {number} Current progress index */
|
|
10
|
-
i
|
|
11
|
-
|
|
12
|
-
/** @type {number} Top limit for progress normalization */
|
|
13
|
-
top
|
|
14
|
-
|
|
15
|
-
/** @type {number} Width of the progress bar */
|
|
16
|
-
width
|
|
17
|
-
|
|
18
|
-
/** @type {string} Character to use for empty space */
|
|
19
|
-
space
|
|
20
|
-
|
|
21
|
-
/** @type {string} Character to use for filled progress */
|
|
22
|
-
char
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Creates a new ProcessInput instance.
|
|
26
|
-
* @param {object} props - Process input properties
|
|
27
|
-
* @param {string} [props.name="NaN•Coding"] - Process name
|
|
28
|
-
* @param {number} [props.i=0] - Current progress index
|
|
29
|
-
* @param {number} [props.top=9] - Top limit for progress normalization
|
|
30
|
-
* @param {number} [props.width=9] - Width of the progress bar
|
|
31
|
-
* @param {string} [props.space='•'] - Character for empty space
|
|
32
|
-
* @param {string} [props.char='*'] - Character for filled progress
|
|
33
|
-
*/
|
|
34
|
-
constructor(props = {}) {
|
|
35
|
-
const { name = 'NaN•Coding', i = 0, top = 9, width = 9, space = '•', char = '*' } = props
|
|
36
|
-
this.name = name
|
|
37
|
-
this.i = i
|
|
38
|
-
this.top = top
|
|
39
|
-
this.width = width
|
|
40
|
-
this.space = space
|
|
41
|
-
this.char = char
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Converts the input to a string representation.
|
|
46
|
-
* @returns {string} String representation of the ProcessInput
|
|
47
|
-
*/
|
|
48
|
-
toString() {
|
|
49
|
-
return `ProcessInput(name=${this.name}, i=${this.i}, top=${this.top}, width=${this.width}, space=${this.space}, char=${this.char})`
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Creates a ProcessInput instance from the given props.
|
|
54
|
-
* @param {ProcessInput|object} props - The properties to create from
|
|
55
|
-
* @returns {ProcessInput} A ProcessInput instance
|
|
56
|
-
*/
|
|
57
|
-
static from(props = {}) {
|
|
58
|
-
if (props instanceof ProcessInput) return props
|
|
59
|
-
return new ProcessInput(props)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export default ProcessInput
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import ProcessInput from './Input.js'
|
|
2
|
-
import View from '../../View/View.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Renders a progress bar based on input configuration.
|
|
6
|
-
* @this {View}
|
|
7
|
-
* @param {ProcessInput|object} props - Process component properties
|
|
8
|
-
* @returns {string[][]} Rendered progress bar as array of strings
|
|
9
|
-
*/
|
|
10
|
-
function Process(props = {}) {
|
|
11
|
-
const input = ProcessInput.from(props)
|
|
12
|
-
const valid = input.top || 1
|
|
13
|
-
const per = (input.i > valid ? valid : input.i) / valid
|
|
14
|
-
const done = per * input.width
|
|
15
|
-
const bar = input.char.repeat(done) + input.space.repeat(input.width - done)
|
|
16
|
-
// Provide empty options object to satisfy Locale.format signature
|
|
17
|
-
const format = this.locale.format(Number, {})
|
|
18
|
-
const num = format ? format(100 * per) : 100 * per
|
|
19
|
-
return [[`I am ${input.name} ${bar} ${num}`]]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
Process.Input = ProcessInput
|
|
23
|
-
|
|
24
|
-
export default Process
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { User } from '../../Model/index.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents input data for the Welcome component.
|
|
5
|
-
* Holds user data to display in the welcome message.
|
|
6
|
-
*/
|
|
7
|
-
class WelcomeInput {
|
|
8
|
-
/** @type {User} User data for welcome message */
|
|
9
|
-
user
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new WelcomeInput instance.
|
|
13
|
-
* @param {object} props - Welcome input properties
|
|
14
|
-
* @param {User|object} [props.user=new User()] - User data
|
|
15
|
-
*/
|
|
16
|
-
constructor(props = {}) {
|
|
17
|
-
const { user = new User() } = props
|
|
18
|
-
this.user = user
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Checks if the input is empty (no user data).
|
|
23
|
-
* @returns {boolean} True if user data is empty, false otherwise
|
|
24
|
-
*/
|
|
25
|
-
get empty() {
|
|
26
|
-
return this.user.empty
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the input to a string representation.
|
|
31
|
-
* @returns {string} String representation of the WelcomeInput
|
|
32
|
-
*/
|
|
33
|
-
toString() {
|
|
34
|
-
return `<WelcomeInput user=${this.user}>`
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Creates a WelcomeInput instance from the given props.
|
|
39
|
-
* @param {WelcomeInput|object} props - The properties to create from
|
|
40
|
-
* @returns {WelcomeInput} A WelcomeInput instance
|
|
41
|
-
*/
|
|
42
|
-
static from(props = {}) {
|
|
43
|
-
if (props instanceof WelcomeInput) return props
|
|
44
|
-
return new WelcomeInput(props)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default WelcomeInput
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { empty } from '@nan0web/types'
|
|
2
|
-
import WelcomeInput from './Input.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Renders a welcome message for a user.
|
|
6
|
-
* @param {WelcomeInput|object} props - Welcome component properties
|
|
7
|
-
* @returns {string[][]} Rendered welcome message as array of strings
|
|
8
|
-
* @throws {Error} If no user data is provided
|
|
9
|
-
*/
|
|
10
|
-
function Welcome(props = {}) {
|
|
11
|
-
const input = WelcomeInput.from(props)
|
|
12
|
-
if (empty(input)) {
|
|
13
|
-
throw new Error('User is required')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return [['Welcome', ' ', input.user.name, '!'], ['What can we do today great?'], ['']]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
Welcome.Input = WelcomeInput
|
|
20
|
-
Welcome.ask = async () => ''
|
|
21
|
-
|
|
22
|
-
export default Welcome
|