@nan0web/ui 1.0.3 → 1.0.4
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 +18 -20
- package/package.json +15 -16
- package/src/App/Core/UI.js +0 -46
- package/src/App/Core/Widget.js +4 -6
- package/src/App/User/Command/Message.js +23 -37
- package/src/App/User/Command/index.js +3 -8
- package/src/App/User/UserApp.js +30 -10
- package/src/README.md.js +33 -33
- package/src/StdIn.js +12 -13
- package/src/View/View.js +5 -5
- package/src/core/Form/Form.js +8 -6
- package/src/core/Form/Input.js +1 -1
- package/src/core/Form/Message.js +6 -5
- package/src/core/InputAdapter.js +2 -2
- package/src/core/Message/Message.js +109 -19
- package/src/core/Message/OutputMessage.js +7 -7
- package/src/core/Message/index.js +3 -4
- package/src/core/Stream.js +10 -10
- package/src/core/UiAdapter.js +189 -0
- package/src/core/index.js +3 -6
- package/src/index.js +4 -4
- package/types/App/Core/UI.d.ts +0 -10
- package/types/App/Core/Widget.d.ts +6 -7
- package/types/App/User/Command/Message.d.ts +15 -28
- package/types/App/User/Command/index.d.ts +3 -4
- package/types/App/User/UserApp.d.ts +14 -7
- package/types/StdIn.d.ts +13 -13
- package/types/View/View.d.ts +6 -6
- package/types/core/Form/Form.d.ts +2 -5
- package/types/core/Form/Input.d.ts +1 -1
- package/types/core/Form/Message.d.ts +5 -10
- package/types/core/Intent.d.ts +91 -0
- package/types/core/Message/Message.d.ts +58 -15
- package/types/core/Message/OutputMessage.d.ts +3 -3
- package/types/core/Message/index.d.ts +3 -4
- package/types/core/Stream.d.ts +5 -4
- package/types/core/UiAdapter.d.ts +104 -0
- package/types/core/index.d.ts +2 -3
- package/types/index.d.ts +4 -4
- package/src/App/User/Command/Options.js +0 -48
- package/src/core/Message/InputMessage.js +0 -119
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import CommandOptions from "../../Command/Options.js"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Extends CommandOptions to include user-specific options.
|
|
5
|
-
*/
|
|
6
|
-
class UserAppCommandOptions extends CommandOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Default option values including inherited ones.
|
|
9
|
-
* @type {object}
|
|
10
|
-
* @property {boolean} help - Whether help is requested
|
|
11
|
-
* @property {string} cwd - Current working directory
|
|
12
|
-
* @property {string} user - User name
|
|
13
|
-
*/
|
|
14
|
-
static DEFAULTS = {
|
|
15
|
-
...CommandOptions.DEFAULTS,
|
|
16
|
-
user: "",
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** @type {string} User name */
|
|
20
|
-
user
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new UserAppCommandOptions instance.
|
|
24
|
-
* @param {object} props - Options properties
|
|
25
|
-
* @param {boolean} [props.help=false] - Whether help is requested
|
|
26
|
-
* @param {string} [props.cwd=""] - Current working directory
|
|
27
|
-
* @param {string} [props.user=""] - User name
|
|
28
|
-
*/
|
|
29
|
-
constructor(props = {}) {
|
|
30
|
-
const {
|
|
31
|
-
user = UserAppCommandOptions.DEFAULTS.user,
|
|
32
|
-
} = props
|
|
33
|
-
super(props)
|
|
34
|
-
this.user = String(user)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Creates a UserAppCommandOptions instance from the given props.
|
|
39
|
-
* @param {UserAppCommandOptions|object} props - The properties to create from
|
|
40
|
-
* @returns {UserAppCommandOptions} A UserAppCommandOptions instance
|
|
41
|
-
*/
|
|
42
|
-
static from(props) {
|
|
43
|
-
if (props instanceof UserAppCommandOptions) return props
|
|
44
|
-
return new this(props)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default UserAppCommandOptions
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { notEmpty } from "@nan0web/types"
|
|
2
|
-
import { Message } from "@nan0web/co"
|
|
3
|
-
|
|
4
|
-
/** @typedef {Partial<Message> | null} InputMessageValue */
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Represents a message input with value, options, and metadata.
|
|
8
|
-
*/
|
|
9
|
-
export default class InputMessage {
|
|
10
|
-
static ESCAPE = String.fromCharCode(27)
|
|
11
|
-
/** @type {Message} Input value */
|
|
12
|
-
value
|
|
13
|
-
|
|
14
|
-
/** @type {string[]} Available options for this input */
|
|
15
|
-
options
|
|
16
|
-
|
|
17
|
-
/** @type {boolean} Whether this input is waiting for response */
|
|
18
|
-
waiting
|
|
19
|
-
|
|
20
|
-
/** @type {number} Timestamp when input was created */
|
|
21
|
-
#time
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates a new InputMessage instance.
|
|
25
|
-
* @param {object} props - Input message properties
|
|
26
|
-
* @param {InputMessageValue} [props.value=null] - Input value
|
|
27
|
-
* @param {string[]|string} [props.options=[]] - Available options
|
|
28
|
-
* @param {boolean} [props.waiting=false] - Waiting state flag
|
|
29
|
-
* @param {boolean} [props.escaped=false] - Sets value to escape when true
|
|
30
|
-
*/
|
|
31
|
-
constructor(props = {}) {
|
|
32
|
-
if ("string" === typeof props) {
|
|
33
|
-
props = { value: { body: props } }
|
|
34
|
-
}
|
|
35
|
-
const {
|
|
36
|
-
value = { body: "" },
|
|
37
|
-
waiting = false,
|
|
38
|
-
options = [],
|
|
39
|
-
escaped = false,
|
|
40
|
-
} = props
|
|
41
|
-
this.#time = Date.now()
|
|
42
|
-
this.waiting = Boolean(waiting)
|
|
43
|
-
|
|
44
|
-
// Properly handle string options by converting to array
|
|
45
|
-
this.options = Array.isArray(options) ? options.map(String) : [String(options)]
|
|
46
|
-
this.value = Message.from(escaped ? { body: this.ESCAPE } : value)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Checks if the input value is empty.
|
|
51
|
-
* @returns {boolean} True if value is empty or null, false otherwise
|
|
52
|
-
*/
|
|
53
|
-
get empty() {
|
|
54
|
-
if (this.value instanceof Message) {
|
|
55
|
-
return this.value.empty
|
|
56
|
-
}
|
|
57
|
-
return null === this.value || 0 === String(this.value).length
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Gets the timestamp when input was created.
|
|
62
|
-
* @returns {number} Creation timestamp
|
|
63
|
-
*/
|
|
64
|
-
get time() {
|
|
65
|
-
return this.#time
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Returns the escape value.
|
|
70
|
-
* @returns {string}
|
|
71
|
-
*/
|
|
72
|
-
get ESCAPE() {
|
|
73
|
-
return /** @type {typeof InputMessage} */ (this.constructor).ESCAPE
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Checks if the input is an escape sequence.
|
|
78
|
-
* @returns {boolean} True if input value is escape sequence, false otherwise
|
|
79
|
-
*/
|
|
80
|
-
get escaped() {
|
|
81
|
-
return this.ESCAPE === this.value.body
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Validates if the input has a non-empty value.
|
|
86
|
-
* @returns {boolean} True if input is valid, false otherwise
|
|
87
|
-
*/
|
|
88
|
-
get isValid() {
|
|
89
|
-
// An input is valid only if it has a non-empty value and is not an escape sequence
|
|
90
|
-
return notEmpty(this.value) && this.value.body !== this.ESCAPE
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Converts the input to a plain object representation.
|
|
95
|
-
* @returns {object} Object with all properties including timestamp
|
|
96
|
-
*/
|
|
97
|
-
toObject() {
|
|
98
|
-
return { ...this, time: this.time }
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Converts the input to a string representation including timestamp.
|
|
103
|
-
* @returns {string} String representation with timestamp and value
|
|
104
|
-
*/
|
|
105
|
-
toString() {
|
|
106
|
-
const date = new Date(this.time)
|
|
107
|
-
return `${date.toISOString().split(".")[0]} ${this.value}`
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Creates an InputMessage instance from the given value.
|
|
112
|
-
* @param {InputMessage|object|string} value - The value to create from
|
|
113
|
-
* @returns {InputMessage} An InputMessage instance
|
|
114
|
-
*/
|
|
115
|
-
static from(value) {
|
|
116
|
-
if (value instanceof InputMessage) return value
|
|
117
|
-
return new this(value)
|
|
118
|
-
}
|
|
119
|
-
}
|