@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.
Files changed (95) hide show
  1. package/README.md +48 -14
  2. package/package.json +25 -13
  3. package/src/App/Command/DepsCommand.js +5 -9
  4. package/src/App/Core/CoreApp.js +18 -17
  5. package/src/App/Core/UI.js +11 -15
  6. package/src/App/Core/Widget.js +6 -10
  7. package/src/App/Core/index.js +3 -3
  8. package/src/App/Scenario.js +4 -4
  9. package/src/App/User/Command/Message.js +1 -1
  10. package/src/App/User/Command/index.js +1 -1
  11. package/src/App/User/UserApp.js +28 -21
  12. package/src/App/User/UserUI.js +2 -2
  13. package/src/App/User/index.js +2 -2
  14. package/src/App/index.js +5 -10
  15. package/src/Component/Process/Input.js +10 -17
  16. package/src/Component/Process/Process.js +3 -5
  17. package/src/Component/Process/index.js +2 -2
  18. package/src/Component/SortableList/SortableList.js +100 -0
  19. package/src/Component/SortableList/index.js +3 -0
  20. package/src/Component/Welcome/Input.js +2 -4
  21. package/src/Component/Welcome/Welcome.js +5 -9
  22. package/src/Component/Welcome/index.js +2 -2
  23. package/src/Component/index.js +5 -3
  24. package/src/Frame/Frame.js +163 -146
  25. package/src/Frame/Props.js +20 -20
  26. package/src/Locale.js +17 -18
  27. package/src/Model/User/User.js +3 -6
  28. package/src/Model/index.js +1 -1
  29. package/src/README.md.js +119 -94
  30. package/src/StdIn.js +8 -12
  31. package/src/StdOut.js +23 -27
  32. package/src/View/RenderOptions.js +1 -1
  33. package/src/View/View.js +40 -36
  34. package/src/core/Error/CancelError.js +2 -2
  35. package/src/core/Error/index.js +3 -5
  36. package/src/core/Flow.js +347 -0
  37. package/src/core/Form/Form.js +35 -33
  38. package/src/core/Form/Input.js +21 -6
  39. package/src/core/Form/Message.js +3 -6
  40. package/src/core/Form/index.js +4 -8
  41. package/src/core/InputAdapter.js +4 -6
  42. package/src/core/Message/Message.js +9 -12
  43. package/src/core/Message/OutputMessage.js +19 -17
  44. package/src/core/Message/index.js +2 -2
  45. package/src/core/OutputAdapter.js +12 -10
  46. package/src/core/Stream.js +1 -1
  47. package/src/core/StreamEntry.js +2 -2
  48. package/src/core/UiAdapter.js +31 -30
  49. package/src/core/index.js +33 -10
  50. package/src/functions.js +8 -15
  51. package/src/index.js +21 -32
  52. package/types/App/Command/DepsCommand.d.ts +1 -1
  53. package/types/App/Command/Options.d.ts +37 -40
  54. package/types/App/Command/index.d.ts +6 -6
  55. package/types/App/Core/CoreApp.d.ts +2 -2
  56. package/types/App/Core/UI.d.ts +4 -4
  57. package/types/App/Core/Widget.d.ts +4 -4
  58. package/types/App/Core/index.d.ts +3 -3
  59. package/types/App/Scenario.d.ts +1 -1
  60. package/types/App/User/Command/Message.d.ts +1 -1
  61. package/types/App/User/Command/Options.d.ts +29 -29
  62. package/types/App/User/Command/index.d.ts +1 -1
  63. package/types/App/User/UserApp.d.ts +5 -5
  64. package/types/App/User/index.d.ts +2 -2
  65. package/types/App/index.d.ts +4 -4
  66. package/types/Component/Process/Process.d.ts +2 -2
  67. package/types/Component/Process/index.d.ts +2 -2
  68. package/types/Component/SortableList/SortableList.d.ts +58 -0
  69. package/types/Component/SortableList/index.d.ts +2 -0
  70. package/types/Component/Welcome/Input.d.ts +1 -1
  71. package/types/Component/Welcome/Welcome.d.ts +1 -1
  72. package/types/Component/Welcome/index.d.ts +2 -2
  73. package/types/Component/index.d.ts +5 -3
  74. package/types/Frame/Frame.d.ts +1 -1
  75. package/types/Frame/Props.d.ts +1 -1
  76. package/types/Model/index.d.ts +1 -1
  77. package/types/StdIn.d.ts +2 -2
  78. package/types/StdOut.d.ts +1 -1
  79. package/types/View/View.d.ts +7 -7
  80. package/types/core/Error/index.d.ts +1 -1
  81. package/types/core/Flow.d.ts +320 -0
  82. package/types/core/Form/Form.d.ts +2 -2
  83. package/types/core/Form/Input.d.ts +11 -0
  84. package/types/core/Form/Message.d.ts +1 -1
  85. package/types/core/Form/index.d.ts +3 -3
  86. package/types/core/InputAdapter.d.ts +2 -2
  87. package/types/core/Intent.d.ts +65 -68
  88. package/types/core/Message/InputMessage.d.ts +65 -65
  89. package/types/core/Message/Message.d.ts +1 -1
  90. package/types/core/Message/OutputMessage.d.ts +1 -1
  91. package/types/core/Message/index.d.ts +2 -2
  92. package/types/core/Stream.d.ts +1 -1
  93. package/types/core/UiAdapter.d.ts +5 -5
  94. package/types/core/index.d.ts +4 -3
  95. 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
@@ -0,0 +1,3 @@
1
+ import SortableList from './SortableList.js'
2
+
3
+ export default SortableList
@@ -1,4 +1,4 @@
1
- import { User } from "../../Model/index.js"
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 "@nan0web/types"
2
- import WelcomeInput from "./Input.js"
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("User is required")
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
@@ -1,5 +1,5 @@
1
- import Welcome from "./Welcome.js"
2
- import WelcomeInput from "./Input.js"
1
+ import Welcome from './Welcome.js'
2
+ import WelcomeInput from './Input.js'
3
3
 
4
4
  export default Welcome
5
5
  export { WelcomeInput }
@@ -1,9 +1,11 @@
1
- import Welcome from "./Welcome/index.js"
2
- import Process from "./Process/index.js"
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
  }