@nan0web/ui 1.0.1 → 1.0.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  |[Status](https://github.com/nan0web/monorepo/blob/main/system.md#написання-сценаріїв)|Documentation|Test coverage|Features|Npm version|
4
4
  |---|---|---|---|---|
5
- |🟢 `96.6%` |🧪 [English 🏴󠁧󠁢󠁥󠁮󠁧󠁿](https://github.com/nan0web/ui/blob/main/README.md)<br />[Українською 🇺🇦](https://github.com/nan0web/ui/blob/main/docs/uk/README.md) |🟡 `80.9%` |✅ d.ts 📜 system.md 🕹️ playground |— |
5
+ |🟢 `96.8%` |🧪 [English 🏴󠁧󠁢󠁥󠁮󠁧󠁿](https://github.com/nan0web/ui/blob/main/README.md)<br />[Українською 🇺🇦](https://github.com/nan0web/ui/blob/main/docs/uk/README.md) |🟡 `81.1%` |✅ d.ts 📜 system.md 🕹️ playground |1.0.1 |
6
6
 
7
7
  A lightweight, agnostic UI framework designed with the **nan0web philosophy**
8
8
  — one application logic, many UI implementations.
@@ -132,6 +132,12 @@ console.info(String(view.frame)) // ← "\rHello, world"
132
132
  `Frame` manages visual rendering with width and height limits.
133
133
  Useful for fixed-size terminals or UI blocks.
134
134
 
135
+ Render methods:
136
+
137
+ - `APPEND` – adds content after previous frame
138
+ - `REPLACE` – erases and replaces full frame area
139
+ - `VISIBLE` – renders only visible part of frame
140
+
135
141
  How to create a Frame with fixed size?
136
142
  ```js
137
143
  import { Frame } from '@nan0web/ui'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nan0web/ui",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "NaN•Web UI. One application logic (algorithm) and many UI.",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
package/src/README.md.js CHANGED
@@ -210,6 +210,12 @@ function testRender() {
210
210
  *
211
211
  * `Frame` manages visual rendering with width and height limits.
212
212
  * Useful for fixed-size terminals or UI blocks.
213
+ *
214
+ * Render methods:
215
+ *
216
+ * - `APPEND` – adds content after previous frame
217
+ * - `REPLACE` – erases and replaces full frame area
218
+ * - `VISIBLE` – renders only visible part of frame
213
219
  */
214
220
  it("How to create a Frame with fixed size?", () => {
215
221
  //import { Frame } from '@nan0web/ui'
@@ -225,6 +231,23 @@ function testRender() {
225
231
  console.info(rendered.includes("Frame content")) // ← true
226
232
  assert.ok(rendered.includes("Frame content"))
227
233
  })
234
+ it("How to create a Frame with different render methods?", () => {
235
+ //import { Frame } from '@nan0web/ui'
236
+
237
+ const frame = new Frame({
238
+ value: [["Frame content"]],
239
+ width: 20,
240
+ height: 5,
241
+ })
242
+
243
+ frame.renderMethod = Frame.RenderMethod.REPLACE
244
+ const renderedReplace = frame.render()
245
+ assert.ok(renderedReplace.includes("Frame content"))
246
+
247
+ frame.renderMethod = Frame.RenderMethod.VISIBLE
248
+ const renderedVisible = frame.render()
249
+ assert.ok(renderedVisible.includes("Frame content"))
250
+ })
228
251
 
229
252
  /**
230
253
  * @docs
@@ -0,0 +1,6 @@
1
+ export default class CancelError extends Error {
2
+ constructor(message = "Operation cancelled by user") {
3
+ super(message)
4
+ this.name = "CancelError"
5
+ }
6
+ }
@@ -1,5 +1,6 @@
1
1
  import Event from "@nan0web/event/oop"
2
2
  import InputMessage from "./Message/InputMessage.js"
3
+ import CancelError from "./Error/CancelError.js"
3
4
 
4
5
  /**
5
6
  * Abstract input adapter for UI implementations.
@@ -7,7 +8,8 @@ import InputMessage from "./Message/InputMessage.js"
7
8
  * @class InputAdapter
8
9
  * @extends Event
9
10
  */
10
- class InputAdapter extends Event {
11
+ export default class InputAdapter extends Event {
12
+ static CancelError = CancelError
11
13
  /**
12
14
  * Starts listening for input and emits an `input` event.
13
15
  *
@@ -36,6 +38,22 @@ class InputAdapter extends Event {
36
38
  isReady() {
37
39
  return true
38
40
  }
39
- }
40
41
 
41
- export default InputAdapter
42
+ /**
43
+ * Helper to ask a question.
44
+ * @param {string} question - Question to ask.
45
+ * @returns {Promise<string>}
46
+ */
47
+ async ask(question) {
48
+ throw new Error('ask() method must be implemented in subclass')
49
+ }
50
+
51
+ /**
52
+ * Generic selection prompt.
53
+ * @param {Object} config - Selection configuration.
54
+ * @returns {Promise<{ index: number, value: string | null }>}
55
+ */
56
+ async select(config) {
57
+ throw new Error('select() method must be implemented in subclass')
58
+ }
59
+ }
@@ -0,0 +1,3 @@
1
+ export default class CancelError extends Error {
2
+ constructor(message?: string);
3
+ }
@@ -1,11 +1,11 @@
1
- export default InputAdapter;
2
1
  /**
3
2
  * Abstract input adapter for UI implementations.
4
3
  *
5
4
  * @class InputAdapter
6
5
  * @extends Event
7
6
  */
8
- declare class InputAdapter extends Event {
7
+ export default class InputAdapter extends Event {
8
+ static CancelError: typeof CancelError;
9
9
  /**
10
10
  * Starts listening for input and emits an `input` event.
11
11
  *
@@ -24,5 +24,21 @@ declare class InputAdapter extends Event {
24
24
  * @returns {boolean} Always true in base class.
25
25
  */
26
26
  isReady(): boolean;
27
+ /**
28
+ * Helper to ask a question.
29
+ * @param {string} question - Question to ask.
30
+ * @returns {Promise<string>}
31
+ */
32
+ ask(question: string): Promise<string>;
33
+ /**
34
+ * Generic selection prompt.
35
+ * @param {Object} config - Selection configuration.
36
+ * @returns {Promise<{ index: number, value: string | null }>}
37
+ */
38
+ select(config: any): Promise<{
39
+ index: number;
40
+ value: string | null;
41
+ }>;
27
42
  }
28
43
  import Event from "@nan0web/event/oop";
44
+ import CancelError from "./Error/CancelError.js";