@nan0web/ui 1.1.0 → 1.5.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 +48 -14
- package/package.json +25 -13
- package/src/App/Command/DepsCommand.js +5 -9
- package/src/App/Core/CoreApp.js +18 -17
- package/src/App/Core/UI.js +11 -15
- package/src/App/Core/Widget.js +6 -10
- package/src/App/Core/index.js +3 -3
- package/src/App/Scenario.js +4 -4
- package/src/App/User/Command/Message.js +1 -1
- package/src/App/User/Command/index.js +1 -1
- package/src/App/User/UserApp.js +28 -21
- package/src/App/User/UserUI.js +2 -2
- package/src/App/User/index.js +2 -2
- package/src/App/index.js +5 -10
- package/src/Component/Process/Input.js +10 -17
- package/src/Component/Process/Process.js +3 -5
- package/src/Component/Process/index.js +2 -2
- package/src/Component/SortableList/SortableList.js +100 -0
- package/src/Component/SortableList/index.js +3 -0
- package/src/Component/Welcome/Input.js +2 -4
- package/src/Component/Welcome/Welcome.js +5 -9
- package/src/Component/Welcome/index.js +2 -2
- package/src/Component/index.js +5 -3
- package/src/Frame/Frame.js +163 -146
- package/src/Frame/Props.js +20 -20
- package/src/Locale.js +17 -18
- package/src/Model/User/User.js +3 -6
- package/src/Model/index.js +1 -1
- package/src/README.md.js +119 -94
- package/src/StdIn.js +8 -12
- package/src/StdOut.js +23 -27
- package/src/View/RenderOptions.js +1 -1
- package/src/View/View.js +40 -36
- package/src/core/Error/CancelError.js +2 -2
- package/src/core/Error/index.js +3 -5
- package/src/core/Flow.js +347 -0
- package/src/core/Form/Form.js +35 -33
- package/src/core/Form/Input.js +21 -6
- package/src/core/Form/Message.js +3 -6
- package/src/core/Form/index.js +4 -8
- package/src/core/InputAdapter.js +4 -6
- package/src/core/Message/Message.js +9 -12
- package/src/core/Message/OutputMessage.js +19 -17
- package/src/core/Message/index.js +2 -2
- package/src/core/OutputAdapter.js +12 -10
- package/src/core/Stream.js +1 -1
- package/src/core/StreamEntry.js +2 -2
- package/src/core/UiAdapter.js +31 -30
- package/src/core/index.js +33 -10
- package/src/functions.js +8 -15
- package/src/index.js +21 -32
- package/types/App/Command/DepsCommand.d.ts +1 -1
- package/types/App/Command/Options.d.ts +37 -40
- package/types/App/Command/index.d.ts +6 -6
- package/types/App/Core/CoreApp.d.ts +2 -2
- package/types/App/Core/UI.d.ts +4 -4
- package/types/App/Core/Widget.d.ts +4 -4
- package/types/App/Core/index.d.ts +3 -3
- package/types/App/Scenario.d.ts +1 -1
- package/types/App/User/Command/Message.d.ts +1 -1
- package/types/App/User/Command/Options.d.ts +29 -29
- package/types/App/User/Command/index.d.ts +1 -1
- package/types/App/User/UserApp.d.ts +5 -5
- package/types/App/User/index.d.ts +2 -2
- package/types/App/index.d.ts +4 -4
- package/types/Component/Process/Process.d.ts +2 -2
- package/types/Component/Process/index.d.ts +2 -2
- package/types/Component/SortableList/SortableList.d.ts +58 -0
- package/types/Component/SortableList/index.d.ts +2 -0
- package/types/Component/Welcome/Input.d.ts +1 -1
- package/types/Component/Welcome/Welcome.d.ts +1 -1
- package/types/Component/Welcome/index.d.ts +2 -2
- package/types/Component/index.d.ts +5 -3
- package/types/Frame/Frame.d.ts +1 -1
- package/types/Frame/Props.d.ts +1 -1
- package/types/Model/index.d.ts +1 -1
- package/types/StdIn.d.ts +2 -2
- package/types/StdOut.d.ts +1 -1
- package/types/View/View.d.ts +7 -7
- package/types/core/Error/index.d.ts +1 -1
- package/types/core/Flow.d.ts +320 -0
- package/types/core/Form/Form.d.ts +2 -2
- package/types/core/Form/Input.d.ts +11 -0
- package/types/core/Form/Message.d.ts +1 -1
- package/types/core/Form/index.d.ts +3 -3
- package/types/core/InputAdapter.d.ts +2 -2
- package/types/core/Intent.d.ts +65 -68
- package/types/core/Message/InputMessage.d.ts +65 -65
- package/types/core/Message/Message.d.ts +1 -1
- package/types/core/Message/OutputMessage.d.ts +1 -1
- package/types/core/Message/index.d.ts +2 -2
- package/types/core/Stream.d.ts +1 -1
- package/types/core/UiAdapter.d.ts +5 -5
- package/types/core/index.d.ts +4 -3
- package/types/index.d.ts +10 -10
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless Sortable List — pure data model with callbacks.
|
|
3
|
+
* Platform-agnostic: works in Node.js, browser, CLI, anywhere.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const list = SortableList.create({
|
|
7
|
+
* items: ['a', 'b', 'c'],
|
|
8
|
+
* onChange: (items) => console.log(items),
|
|
9
|
+
* })
|
|
10
|
+
* list.moveUp(1) // ['b', 'a', 'c']
|
|
11
|
+
*/
|
|
12
|
+
class SortableList {
|
|
13
|
+
/** @type {any[]} */
|
|
14
|
+
#items
|
|
15
|
+
|
|
16
|
+
/** @type {any[]} */
|
|
17
|
+
#initial
|
|
18
|
+
|
|
19
|
+
/** @type {function|undefined} */
|
|
20
|
+
#onChange
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {object} [opts]
|
|
24
|
+
* @param {any[]} [opts.items]
|
|
25
|
+
* @param {function} [opts.onChange]
|
|
26
|
+
*/
|
|
27
|
+
constructor({ items = [], onChange } = {}) {
|
|
28
|
+
this.#initial = [...items]
|
|
29
|
+
this.#items = [...items]
|
|
30
|
+
this.#onChange = onChange
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Factory method.
|
|
35
|
+
* @param {object} opts
|
|
36
|
+
* @returns {SortableList}
|
|
37
|
+
*/
|
|
38
|
+
static create(opts) {
|
|
39
|
+
return new SortableList(opts)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Move item at index up (swap with previous).
|
|
44
|
+
* No-op if already at top.
|
|
45
|
+
* @param {number} index
|
|
46
|
+
*/
|
|
47
|
+
moveUp(index) {
|
|
48
|
+
if (index <= 0 || index >= this.#items.length) return
|
|
49
|
+
const temp = this.#items[index - 1]
|
|
50
|
+
this.#items[index - 1] = this.#items[index]
|
|
51
|
+
this.#items[index] = temp
|
|
52
|
+
this.#onChange?.(this.getItems())
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Move item at index down (swap with next).
|
|
57
|
+
* No-op if already at bottom.
|
|
58
|
+
* @param {number} index
|
|
59
|
+
*/
|
|
60
|
+
moveDown(index) {
|
|
61
|
+
if (index < 0 || index >= this.#items.length - 1) return
|
|
62
|
+
const temp = this.#items[index + 1]
|
|
63
|
+
this.#items[index + 1] = this.#items[index]
|
|
64
|
+
this.#items[index] = temp
|
|
65
|
+
this.#onChange?.(this.getItems())
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns a copy of the current item order.
|
|
70
|
+
* @returns {any[]}
|
|
71
|
+
*/
|
|
72
|
+
getItems() {
|
|
73
|
+
return [...this.#items]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Move item from one position to another (drag-n-drop).
|
|
78
|
+
* No-op if indices are equal or out of bounds.
|
|
79
|
+
* @param {number} from - source index
|
|
80
|
+
* @param {number} to - target index
|
|
81
|
+
*/
|
|
82
|
+
moveTo(from, to) {
|
|
83
|
+
if (from === to) return
|
|
84
|
+
if (from < 0 || from >= this.#items.length) return
|
|
85
|
+
if (to < 0 || to >= this.#items.length) return
|
|
86
|
+
const [item] = this.#items.splice(from, 1)
|
|
87
|
+
this.#items.splice(to, 0, item)
|
|
88
|
+
this.#onChange?.(this.getItems())
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Restores the initial order.
|
|
93
|
+
*/
|
|
94
|
+
reset() {
|
|
95
|
+
this.#items = [...this.#initial]
|
|
96
|
+
this.#onChange?.(this.getItems())
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default SortableList
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { User } from
|
|
1
|
+
import { User } from '../../Model/index.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents input data for the Welcome component.
|
|
@@ -14,9 +14,7 @@ class WelcomeInput {
|
|
|
14
14
|
* @param {User|object} [props.user=new User()] - User data
|
|
15
15
|
*/
|
|
16
16
|
constructor(props = {}) {
|
|
17
|
-
const {
|
|
18
|
-
user = new User(),
|
|
19
|
-
} = props
|
|
17
|
+
const { user = new User() } = props
|
|
20
18
|
this.user = user
|
|
21
19
|
}
|
|
22
20
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { empty } from
|
|
2
|
-
import WelcomeInput from
|
|
1
|
+
import { empty } from '@nan0web/types'
|
|
2
|
+
import WelcomeInput from './Input.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Renders a welcome message for a user.
|
|
@@ -10,17 +10,13 @@ import WelcomeInput from "./Input.js"
|
|
|
10
10
|
function Welcome(props = {}) {
|
|
11
11
|
const input = WelcomeInput.from(props)
|
|
12
12
|
if (empty(input)) {
|
|
13
|
-
throw new Error(
|
|
13
|
+
throw new Error('User is required')
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
return [
|
|
17
|
-
["Welcome", " ", input.user.name, "!"],
|
|
18
|
-
["What can we do today great?"],
|
|
19
|
-
[""],
|
|
20
|
-
]
|
|
16
|
+
return [['Welcome', ' ', input.user.name, '!'], ['What can we do today great?'], ['']]
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
Welcome.Input = WelcomeInput
|
|
24
|
-
Welcome.ask = async () =>
|
|
20
|
+
Welcome.ask = async () => ''
|
|
25
21
|
|
|
26
22
|
export default Welcome
|
package/src/Component/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import Welcome from
|
|
2
|
-
import Process from
|
|
1
|
+
import Welcome from './Welcome/index.js'
|
|
2
|
+
import Process from './Process/index.js'
|
|
3
|
+
import SortableList from './SortableList/index.js'
|
|
3
4
|
|
|
4
|
-
export { Welcome, Process }
|
|
5
|
+
export { Welcome, Process, SortableList }
|
|
5
6
|
|
|
6
7
|
export default {
|
|
7
8
|
Welcome,
|
|
8
9
|
Process,
|
|
10
|
+
SortableList,
|
|
9
11
|
}
|