@nan0web/ui 1.0.1 → 1.0.3

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 (46) hide show
  1. package/README.md +8 -35
  2. package/package.json +7 -2
  3. package/src/App/Core/CoreApp.js +14 -19
  4. package/src/App/Core/UI.js +5 -5
  5. package/src/App/User/UserApp.js +4 -19
  6. package/src/App/User/UserUI.js +4 -4
  7. package/src/App/User/index.js +0 -6
  8. package/src/App/index.js +0 -3
  9. package/src/README.md.js +22 -23
  10. package/src/StdIn.js +1 -3
  11. package/src/core/Error/CancelError.js +6 -0
  12. package/src/core/Error/index.js +9 -0
  13. package/src/core/Form/Form.js +36 -18
  14. package/src/core/Form/Input.js +16 -7
  15. package/src/core/Form/Message.js +6 -9
  16. package/src/core/InputAdapter.js +25 -3
  17. package/src/core/Message/InputMessage.js +11 -11
  18. package/src/core/Message/OutputMessage.js +1 -1
  19. package/src/core/index.js +2 -0
  20. package/src/index.js +1 -0
  21. package/types/App/Core/CoreApp.d.ts +9 -9
  22. package/types/App/Core/UI.d.ts +5 -5
  23. package/types/App/Core/Widget.d.ts +1 -1
  24. package/types/App/User/Command/Message.d.ts +2 -3
  25. package/types/App/User/Command/Options.d.ts +9 -2
  26. package/types/App/User/Command/index.d.ts +1 -4
  27. package/types/App/User/UserApp.d.ts +10 -7
  28. package/types/App/User/UserUI.d.ts +0 -9
  29. package/types/App/User/index.d.ts +0 -4
  30. package/types/App/index.d.ts +1 -3
  31. package/types/Frame/Frame.d.ts +5 -5
  32. package/types/View/View.d.ts +3 -3
  33. package/types/core/Error/CancelError.d.ts +3 -0
  34. package/types/core/Error/index.d.ts +6 -0
  35. package/types/core/Form/Form.d.ts +12 -6
  36. package/types/core/Form/Input.d.ts +20 -7
  37. package/types/core/Form/Message.d.ts +10 -4
  38. package/types/core/InputAdapter.d.ts +20 -2
  39. package/types/core/Message/InputMessage.d.ts +5 -5
  40. package/types/core/Message/OutputMessage.d.ts +1 -1
  41. package/types/core/Stream.d.ts +1 -1
  42. package/types/core/StreamEntry.d.ts +1 -1
  43. package/types/core/index.d.ts +1 -0
  44. package/types/index.d.ts +1 -0
  45. package/src/App/Command/Options.js +0 -78
  46. package/src/App/Command/index.js +0 -9
@@ -1,11 +1,13 @@
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
+ /** @returns {typeof CancelError} */
10
+ get CancelError(): typeof CancelError;
9
11
  /**
10
12
  * Starts listening for input and emits an `input` event.
11
13
  *
@@ -24,5 +26,21 @@ declare class InputAdapter extends Event {
24
26
  * @returns {boolean} Always true in base class.
25
27
  */
26
28
  isReady(): boolean;
29
+ /**
30
+ * Helper to ask a question.
31
+ * @param {string} question - Question to ask.
32
+ * @returns {Promise<string>}
33
+ */
34
+ ask(question: string): Promise<string>;
35
+ /**
36
+ * Generic selection prompt.
37
+ * @param {Object} config - Selection configuration.
38
+ * @returns {Promise<{ index: number, value: string | null }>}
39
+ */
40
+ select(config: any): Promise<{
41
+ index: number;
42
+ value: string | null;
43
+ }>;
27
44
  }
28
45
  import Event from "@nan0web/event/oop";
46
+ import CancelError from "./Error/CancelError.js";
@@ -1,4 +1,4 @@
1
- /** @typedef {Message | string | null} InputMessageValue */
1
+ /** @typedef {Partial<Message> | null} InputMessageValue */
2
2
  /**
3
3
  * Represents a message input with value, options, and metadata.
4
4
  */
@@ -13,7 +13,7 @@ export default class InputMessage {
13
13
  /**
14
14
  * Creates a new InputMessage instance.
15
15
  * @param {object} props - Input message properties
16
- * @param {InputMessageValue} [props.value=""] - Input value
16
+ * @param {InputMessageValue} [props.value=null] - Input value
17
17
  * @param {string[]|string} [props.options=[]] - Available options
18
18
  * @param {boolean} [props.waiting=false] - Waiting state flag
19
19
  * @param {boolean} [props.escaped=false] - Sets value to escape when true
@@ -24,8 +24,8 @@ export default class InputMessage {
24
24
  waiting?: boolean | undefined;
25
25
  escaped?: boolean | undefined;
26
26
  });
27
- /** @type {InputMessageValue} Input value */
28
- value: InputMessageValue;
27
+ /** @type {Message} Input value */
28
+ value: Message;
29
29
  /** @type {string[]} Available options for this input */
30
30
  options: string[];
31
31
  /** @type {boolean} Whether this input is waiting for response */
@@ -67,5 +67,5 @@ export default class InputMessage {
67
67
  toString(): string;
68
68
  #private;
69
69
  }
70
- export type InputMessageValue = Message | string | null;
70
+ export type InputMessageValue = Partial<Message> | null;
71
71
  import { Message } from "@nan0web/co";
@@ -27,7 +27,7 @@ export default class OutputMessage extends UIMessage {
27
27
  /** @type {number} */
28
28
  priority: number;
29
29
  /** @param {string[]|string} value */
30
- set content(arg: string[]);
30
+ set content(value: string[] | string);
31
31
  /** @returns {string[]} */
32
32
  get content(): string[];
33
33
  /** @returns {number} */
@@ -22,6 +22,6 @@ export default class UIStream {
22
22
  * @param {Function} [onComplete] - Called with (item) when done.
23
23
  * @returns {Promise<void>}
24
24
  */
25
- static process(signal: AbortSignal, generator: Function, onProgress?: Function | undefined, onError?: Function | undefined, onComplete?: Function | undefined): Promise<void>;
25
+ static process(signal: AbortSignal, generator: Function, onProgress?: Function, onError?: Function, onComplete?: Function): Promise<void>;
26
26
  }
27
27
  import StreamEntry from "./StreamEntry.js";
@@ -21,7 +21,7 @@ export default class StreamEntry {
21
21
  done?: boolean | undefined;
22
22
  cancelled?: boolean | undefined;
23
23
  error?: string | undefined;
24
- } | undefined);
24
+ });
25
25
  /**
26
26
  * The value of the stream entry.
27
27
  * @type {any}
@@ -7,3 +7,4 @@ export { default as OutputMessage } from "./Message/OutputMessage.js";
7
7
  export { default as FormMessage } from "./Form/Message.js";
8
8
  export { default as FormInput } from "./Form/Input.js";
9
9
  export { default as UIForm } from "./Form/Form.js";
10
+ export { default as Error, CancelError } from "./Error/index.js";
package/types/index.d.ts CHANGED
@@ -18,3 +18,4 @@ import Model from "./Model/index.js";
18
18
  import Component from "./Component/index.js";
19
19
  import App from "./App/index.js";
20
20
  export { Frame, FrameProps, Locale, StdIn, StdOut, View, RenderOptions, Model, Component, App };
21
+ export { default as Error, CancelError } from "./core/Error/index.js";
@@ -1,78 +0,0 @@
1
- /**
2
- * Represents command options with default values.
3
- * Provides utilities for handling command line options.
4
- */
5
- class CommandOptions {
6
- /**
7
- * Default option values.
8
- * @type {object}
9
- * @property {boolean} help - Whether help is requested
10
- * @property {string} cwd - Current working directory
11
- */
12
- static DEFAULTS = {
13
- help: false,
14
- cwd: "",
15
- }
16
-
17
- /** @type {boolean} Whether help is requested */
18
- help
19
-
20
- /** @type {string} Current working directory */
21
- cwd
22
-
23
- /**
24
- * Creates a new CommandOptions instance.
25
- * @param {object} props - The properties for command options
26
- * @param {boolean} [props.help=false] - Whether help is requested
27
- * @param {string} [props.cwd=""] - Current working directory
28
- */
29
- constructor(props = {}) {
30
- const {
31
- help = CommandOptions.DEFAULTS.help,
32
- cwd = CommandOptions.DEFAULTS.cwd,
33
- } = props
34
- this.help = Boolean(help)
35
- this.cwd = String(cwd)
36
- }
37
-
38
- /** @type {Record<string, any>} */
39
- get DEFAULTS() {
40
- return /** @type {typeof CommandOptions} */ (this.constructor).DEFAULTS
41
- }
42
-
43
- /**
44
- * Checks if all options have their default values.
45
- * @returns {boolean} True if all options are at their default values, false otherwise
46
- */
47
- get empty() {
48
- return Object.entries(this).every(
49
- ([key, value]) => CommandOptions.DEFAULTS[key] === value
50
- )
51
- }
52
-
53
- /**
54
- * Converts the options to a string representation.
55
- * @returns {string} String representation of the options or "<no options>" if none set
56
- */
57
- toString() {
58
- const opts = Object.entries(this).map(([key, value]) => {
59
- if (this.DEFAULTS[key] === value) return false
60
- const prefix = true === value ? "--" : "-"
61
- return `${prefix}${key}${value ? ` ${value}` : ""}`
62
- }).filter(Boolean)
63
- if (0 === opts.length) return "<no options>"
64
- return opts.join(" ")
65
- }
66
-
67
- /**
68
- * Creates a CommandOptions instance from the given props.
69
- * @param {CommandOptions|object} props - The properties to create from
70
- * @returns {CommandOptions} A CommandOptions instance
71
- */
72
- static from(props) {
73
- if (props instanceof CommandOptions) return props
74
- return new this(props)
75
- }
76
- }
77
-
78
- export default CommandOptions
@@ -1,9 +0,0 @@
1
- import { CommandMessage } from "@nan0web/co"
2
- import CommandOptions from "./Options.js"
3
-
4
- export { CommandMessage, CommandOptions }
5
-
6
- export default {
7
- Message: CommandMessage,
8
- Options: CommandOptions,
9
- }