@nan0web/ui 1.0.0
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/.datasets/README.dataset.jsonl +12 -0
- package/.editorconfig +20 -0
- package/CONTRIBUTING.md +42 -0
- package/LICENSE +15 -0
- package/README.md +238 -0
- package/docs/uk/README.md +240 -0
- package/package.json +64 -0
- package/playground/User.js +52 -0
- package/playground/currency.exchange.js +48 -0
- package/playground/i18n/index.js +21 -0
- package/playground/i18n/uk.js +53 -0
- package/playground/language.form.js +25 -0
- package/playground/main.js +72 -0
- package/playground/registration.form.js +58 -0
- package/playground/topup.telephone.js +62 -0
- package/src/App/Command/Options.js +78 -0
- package/src/App/Command/index.js +9 -0
- package/src/App/Core/CoreApp.js +129 -0
- package/src/App/Core/UI.js +116 -0
- package/src/App/Core/Widget.js +67 -0
- package/src/App/Core/index.js +11 -0
- package/src/App/Scenario.js +45 -0
- package/src/App/User/Command/Message.js +44 -0
- package/src/App/User/Command/Options.js +48 -0
- package/src/App/User/Command/index.js +11 -0
- package/src/App/User/UserApp.js +73 -0
- package/src/App/User/UserApp.test.js +56 -0
- package/src/App/User/UserUI.js +20 -0
- package/src/App/User/UserUI.test.js +51 -0
- package/src/App/User/index.js +15 -0
- package/src/App/index.js +22 -0
- package/src/Component/Process/Input.js +70 -0
- package/src/Component/Process/Process.js +26 -0
- package/src/Component/Process/index.js +5 -0
- package/src/Component/Welcome/Input.js +50 -0
- package/src/Component/Welcome/Welcome.js +26 -0
- package/src/Component/Welcome/index.js +5 -0
- package/src/Component/index.js +9 -0
- package/src/Frame/Frame.js +591 -0
- package/src/Frame/Frame.test.js +429 -0
- package/src/Frame/Props.js +102 -0
- package/src/Locale.js +119 -0
- package/src/Model/User/User.js +56 -0
- package/src/Model/index.js +7 -0
- package/src/README.md.js +371 -0
- package/src/StdIn.js +111 -0
- package/src/StdOut.js +99 -0
- package/src/View/RenderOptions.js +48 -0
- package/src/View/View.js +289 -0
- package/src/View/View.test.js +77 -0
- package/src/core/Form/Form.js +289 -0
- package/src/core/Form/Form.test.js +116 -0
- package/src/core/Form/Input.js +116 -0
- package/src/core/Form/Input.test.js +58 -0
- package/src/core/Form/Message.js +86 -0
- package/src/core/Form/Message.test.js +54 -0
- package/src/core/Form/index.js +11 -0
- package/src/core/InputAdapter.js +41 -0
- package/src/core/InputAdapter.test.js +35 -0
- package/src/core/Message/InputMessage.js +119 -0
- package/src/core/Message/InputMessage.test.js +45 -0
- package/src/core/Message/Message.js +77 -0
- package/src/core/Message/Message.test.js +58 -0
- package/src/core/Message/OutputMessage.js +143 -0
- package/src/core/Message/OutputMessage.test.js +61 -0
- package/src/core/Message/index.js +7 -0
- package/src/core/OutputAdapter.js +50 -0
- package/src/core/OutputAdapter.test.js +35 -0
- package/src/core/Stream.js +71 -0
- package/src/core/Stream.test.js +78 -0
- package/src/core/StreamEntry.js +59 -0
- package/src/core/index.js +13 -0
- package/src/functions.js +38 -0
- package/src/index.js +34 -0
- package/src/index.test.js +14 -0
- package/src/models/SimpleUser.js +18 -0
- package/stories/App/AppView.js +15 -0
- package/stories/App/AppView.test.js +22 -0
- package/stories/App/RenderOptions.js +14 -0
- package/stories/nodejs/interface.test.js +27 -0
- package/system.md +187 -0
- package/system1.md +137 -0
- package/task.md +181 -0
- package/tsconfig.json +23 -0
- package/types/App/Command/Options.d.ts +46 -0
- package/types/App/Command/index.d.ts +8 -0
- package/types/App/Core/CoreApp.d.ts +70 -0
- package/types/App/Core/UI.d.ts +49 -0
- package/types/App/Core/Widget.d.ts +40 -0
- package/types/App/Core/index.d.ts +10 -0
- package/types/App/Scenario.d.ts +26 -0
- package/types/App/User/Command/Message.d.ts +30 -0
- package/types/App/User/Command/Options.d.ts +27 -0
- package/types/App/User/Command/index.d.ts +8 -0
- package/types/App/User/UserApp.d.ts +31 -0
- package/types/App/User/UserUI.d.ts +18 -0
- package/types/App/User/index.d.ts +12 -0
- package/types/App/index.d.ts +14 -0
- package/types/Component/Process/Input.d.ts +48 -0
- package/types/Component/Process/Process.d.ts +13 -0
- package/types/Component/Process/index.d.ts +4 -0
- package/types/Component/Welcome/Input.d.ts +34 -0
- package/types/Component/Welcome/Welcome.d.ts +13 -0
- package/types/Component/Welcome/index.d.ts +4 -0
- package/types/Component/index.d.ts +8 -0
- package/types/Frame/Frame.d.ts +186 -0
- package/types/Frame/Props.d.ts +77 -0
- package/types/Locale.d.ts +55 -0
- package/types/Model/User/User.d.ts +36 -0
- package/types/Model/index.d.ts +6 -0
- package/types/StdIn.d.ts +62 -0
- package/types/StdOut.d.ts +52 -0
- package/types/View/RenderOptions.d.ts +29 -0
- package/types/View/View.d.ts +115 -0
- package/types/core/Form/Form.d.ts +123 -0
- package/types/core/Form/Input.d.ts +69 -0
- package/types/core/Form/Message.d.ts +28 -0
- package/types/core/Form/index.d.ts +5 -0
- package/types/core/InputAdapter.d.ts +28 -0
- package/types/core/Message/InputMessage.d.ts +71 -0
- package/types/core/Message/Message.d.ts +50 -0
- package/types/core/Message/OutputMessage.d.ts +53 -0
- package/types/core/Message/index.d.ts +5 -0
- package/types/core/OutputAdapter.d.ts +33 -0
- package/types/core/Stream.d.ts +27 -0
- package/types/core/StreamEntry.d.ts +45 -0
- package/types/core/index.d.ts +9 -0
- package/types/functions.d.ts +3 -0
- package/types/index.d.ts +20 -0
- package/types/models/SimpleUser.d.ts +21 -0
- package/vitest.config.js +26 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract form for data entry.
|
|
3
|
+
*
|
|
4
|
+
* @class UIForm
|
|
5
|
+
* @extends FormMessage
|
|
6
|
+
* @property {FormInput[]} fields - Form fields.
|
|
7
|
+
* @property {Object} state - Current form state (field values).
|
|
8
|
+
* @property {string} title - Form title.
|
|
9
|
+
* @property {Object} schema - Validation schema (optional).
|
|
10
|
+
*/
|
|
11
|
+
export default class UIForm extends FormMessage {
|
|
12
|
+
/** @type {Object<string,Function>} */
|
|
13
|
+
static _validators: {
|
|
14
|
+
[x: string]: Function;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Register a custom validator that can be referenced by name in a schema.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} name - Identifier used in schema.validator.
|
|
20
|
+
* @param {(value:any)=>true|string} fn - Function returns true if valid,
|
|
21
|
+
* otherwise returns an error message.
|
|
22
|
+
*/
|
|
23
|
+
static addValidator(name: string, fn: (value: any) => true | string): void;
|
|
24
|
+
/**
|
|
25
|
+
* @param {*} input
|
|
26
|
+
* @returns {UIForm}
|
|
27
|
+
*/
|
|
28
|
+
static from(input: any): UIForm;
|
|
29
|
+
/**
|
|
30
|
+
* Auto‑generates form fields from a plain object.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} data - Example data object; its own enumerable keys become field names.
|
|
33
|
+
* @param {Object<string, Partial<import("./Input.js").default>>} [overrides={}]
|
|
34
|
+
* Optional per‑field overrides (e.g. type, required, label).
|
|
35
|
+
*
|
|
36
|
+
* @returns {UIForm} Form with Array of `FormInput` instances as form.fields
|
|
37
|
+
*
|
|
38
|
+
* Example:
|
|
39
|
+
* const fields = generateFieldsFromObject({ name: "", age: 0 }, {
|
|
40
|
+
* age: { type: FormInput.TYPES.NUMBER, required: true }
|
|
41
|
+
* })
|
|
42
|
+
*/
|
|
43
|
+
static parse(data: any, overrides?: {
|
|
44
|
+
[x: string]: Partial<FormInput>;
|
|
45
|
+
} | undefined): UIForm;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new UIForm.
|
|
48
|
+
*
|
|
49
|
+
* @param {Object} [props={}] - Form properties.
|
|
50
|
+
* @param {string} [props.title] - Form title.
|
|
51
|
+
* @param {FormInput[]} [props.fields=[]] - Form fields.
|
|
52
|
+
* @param {Object} [props.state={}] - Initial form state.
|
|
53
|
+
* @param {Object} [props.schema] - Validation schema.
|
|
54
|
+
*/
|
|
55
|
+
constructor(props?: {
|
|
56
|
+
title?: string | undefined;
|
|
57
|
+
fields?: FormInput[] | undefined;
|
|
58
|
+
state?: any;
|
|
59
|
+
schema?: any;
|
|
60
|
+
} | undefined);
|
|
61
|
+
/** @type {FormInput[]} */ fields: FormInput[];
|
|
62
|
+
/** @type {Object} */ state: any;
|
|
63
|
+
/** @type {string} */ title: string;
|
|
64
|
+
meta: {
|
|
65
|
+
title: string;
|
|
66
|
+
fields: any[];
|
|
67
|
+
initialState: any;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Returns a new UIForm instance with updated state.
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} data - Partial state to merge.
|
|
73
|
+
* @returns {UIForm}
|
|
74
|
+
*/
|
|
75
|
+
setData(data: any): UIForm;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves a field definition by its name.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} name - Field name.
|
|
80
|
+
* @returns {FormInput|undefined}
|
|
81
|
+
*/
|
|
82
|
+
getField(name: string): FormInput | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Returns current form values.
|
|
85
|
+
*
|
|
86
|
+
* @returns {Object}
|
|
87
|
+
*/
|
|
88
|
+
getValues(): any;
|
|
89
|
+
/**
|
|
90
|
+
* Validates the entire form.
|
|
91
|
+
*
|
|
92
|
+
* @returns {{isValid: boolean, errors: Object}} Validation result.
|
|
93
|
+
*/
|
|
94
|
+
validate(): {
|
|
95
|
+
isValid: boolean;
|
|
96
|
+
errors: any;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Validates a single field.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} fieldName - Name of the field.
|
|
102
|
+
* @param {*} value - Value to validate.
|
|
103
|
+
* @returns {{isValid: boolean, errors: Object}}
|
|
104
|
+
*/
|
|
105
|
+
validateField(fieldName: string, value: any): {
|
|
106
|
+
isValid: boolean;
|
|
107
|
+
errors: any;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Validates a value against a schema.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} fieldName - Name of the field.
|
|
113
|
+
* @param {*} value - Value to validate.
|
|
114
|
+
* @param {Object} schema - Validation schema.
|
|
115
|
+
* @returns {{isValid: boolean, errors: Object}}
|
|
116
|
+
*/
|
|
117
|
+
validateValue(fieldName: string, value: any, schema: any): {
|
|
118
|
+
isValid: boolean;
|
|
119
|
+
errors: any;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
import FormMessage from "./Message.js";
|
|
123
|
+
import FormInput from "./Input.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form input field descriptor.
|
|
3
|
+
*
|
|
4
|
+
* @class FormInput
|
|
5
|
+
* @property {string} name - Field name.
|
|
6
|
+
* @property {string} label - Display label.
|
|
7
|
+
* @property {string} type - Input type (text, email, number, select, etc.).
|
|
8
|
+
* @property {boolean} required - Whether the field is required.
|
|
9
|
+
* @property {string} placeholder - Placeholder text.
|
|
10
|
+
* @property {Array<string>} options - Select options (if type is 'select').
|
|
11
|
+
* @property {Function|null} validator - Custom validation function.
|
|
12
|
+
* @property {*} defaultValue - Default value.
|
|
13
|
+
*/
|
|
14
|
+
export default class FormInput {
|
|
15
|
+
/**
|
|
16
|
+
* Predefined input types.
|
|
17
|
+
*/
|
|
18
|
+
static TYPES: {
|
|
19
|
+
TEXT: string;
|
|
20
|
+
EMAIL: string;
|
|
21
|
+
NUMBER: string;
|
|
22
|
+
SELECT: string;
|
|
23
|
+
CHECKBOX: string;
|
|
24
|
+
TEXTAREA: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @param {*} input
|
|
28
|
+
* @returns {FormInput}
|
|
29
|
+
*/
|
|
30
|
+
static from(input: any): FormInput;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new form input.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} props - Input properties.
|
|
35
|
+
* @param {string} props.name - Field name.
|
|
36
|
+
* @param {string} [props.label=props.name] - Display label.
|
|
37
|
+
* @param {string} [props.type='text'] - Input type.
|
|
38
|
+
* @param {boolean} [props.required=false] - Is required.
|
|
39
|
+
* @param {string} [props.placeholder=''] - Placeholder.
|
|
40
|
+
* @param {Array<string>} [props.options=[]] - Select options.
|
|
41
|
+
* @param {Function} [props.validator=null] - Custom validator.
|
|
42
|
+
* @param {*} [props.defaultValue=null] - Default value.
|
|
43
|
+
*/
|
|
44
|
+
constructor(props: {
|
|
45
|
+
name: string;
|
|
46
|
+
label?: string | undefined;
|
|
47
|
+
type?: string | undefined;
|
|
48
|
+
required?: boolean | undefined;
|
|
49
|
+
placeholder?: string | undefined;
|
|
50
|
+
options?: string[] | undefined;
|
|
51
|
+
validator?: Function | undefined;
|
|
52
|
+
defaultValue?: any;
|
|
53
|
+
});
|
|
54
|
+
/** @type {string} */ name: string;
|
|
55
|
+
/** @type {string} */ label: string;
|
|
56
|
+
/** @type {string} */ type: string;
|
|
57
|
+
/** @type {boolean} */ required: boolean;
|
|
58
|
+
/** @type {string} */ placeholder: string;
|
|
59
|
+
/** @type {Array<string>} */ options: Array<string>;
|
|
60
|
+
/** @type {Function|null} */ validator: Function | null;
|
|
61
|
+
/** @type {*} */ defaultValue: any;
|
|
62
|
+
requireValidType(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Serialises the input to a plain JSON object.
|
|
65
|
+
*
|
|
66
|
+
* @returns {Object}
|
|
67
|
+
*/
|
|
68
|
+
toJSON(): any;
|
|
69
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FormMessage – specialized OutputMessage for forms.
|
|
3
|
+
*
|
|
4
|
+
* @class FormMessage
|
|
5
|
+
* @extends OutputMessage
|
|
6
|
+
*/
|
|
7
|
+
export default class FormMessage extends OutputMessage {
|
|
8
|
+
data: any;
|
|
9
|
+
schema: any;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a new FormMessage with merged data.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} newData - Data to merge.
|
|
14
|
+
* @returns {FormMessage}
|
|
15
|
+
*/
|
|
16
|
+
addData(newData: any): FormMessage;
|
|
17
|
+
/**
|
|
18
|
+
* Validates the provided data against the schema.
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} data - Data to validate.
|
|
21
|
+
* @returns {{isValid: boolean, errors: Object}}
|
|
22
|
+
*/
|
|
23
|
+
validateData(data: any): {
|
|
24
|
+
isValid: boolean;
|
|
25
|
+
errors: any;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
import OutputMessage from "../Message/OutputMessage.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default InputAdapter;
|
|
2
|
+
/**
|
|
3
|
+
* Abstract input adapter for UI implementations.
|
|
4
|
+
*
|
|
5
|
+
* @class InputAdapter
|
|
6
|
+
* @extends Event
|
|
7
|
+
*/
|
|
8
|
+
declare class InputAdapter extends Event {
|
|
9
|
+
/**
|
|
10
|
+
* Starts listening for input and emits an `input` event.
|
|
11
|
+
*
|
|
12
|
+
* @returns {void}
|
|
13
|
+
*/
|
|
14
|
+
start(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Stops listening for input. Default implementation does nothing.
|
|
17
|
+
*
|
|
18
|
+
* @returns {void}
|
|
19
|
+
*/
|
|
20
|
+
stop(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether the adapter is ready to receive input.
|
|
23
|
+
*
|
|
24
|
+
* @returns {boolean} Always true in base class.
|
|
25
|
+
*/
|
|
26
|
+
isReady(): boolean;
|
|
27
|
+
}
|
|
28
|
+
import Event from "@nan0web/event/oop";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** @typedef {Message | string | null} InputMessageValue */
|
|
2
|
+
/**
|
|
3
|
+
* Represents a message input with value, options, and metadata.
|
|
4
|
+
*/
|
|
5
|
+
export default class InputMessage {
|
|
6
|
+
static ESCAPE: string;
|
|
7
|
+
/**
|
|
8
|
+
* Creates an InputMessage instance from the given value.
|
|
9
|
+
* @param {InputMessage|object|string} value - The value to create from
|
|
10
|
+
* @returns {InputMessage} An InputMessage instance
|
|
11
|
+
*/
|
|
12
|
+
static from(value: InputMessage | object | string): InputMessage;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new InputMessage instance.
|
|
15
|
+
* @param {object} props - Input message properties
|
|
16
|
+
* @param {InputMessageValue} [props.value=""] - Input value
|
|
17
|
+
* @param {string[]|string} [props.options=[]] - Available options
|
|
18
|
+
* @param {boolean} [props.waiting=false] - Waiting state flag
|
|
19
|
+
* @param {boolean} [props.escaped=false] - Sets value to escape when true
|
|
20
|
+
*/
|
|
21
|
+
constructor(props?: {
|
|
22
|
+
value?: InputMessageValue | undefined;
|
|
23
|
+
options?: string | string[] | undefined;
|
|
24
|
+
waiting?: boolean | undefined;
|
|
25
|
+
escaped?: boolean | undefined;
|
|
26
|
+
});
|
|
27
|
+
/** @type {InputMessageValue} Input value */
|
|
28
|
+
value: InputMessageValue;
|
|
29
|
+
/** @type {string[]} Available options for this input */
|
|
30
|
+
options: string[];
|
|
31
|
+
/** @type {boolean} Whether this input is waiting for response */
|
|
32
|
+
waiting: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the input value is empty.
|
|
35
|
+
* @returns {boolean} True if value is empty or null, false otherwise
|
|
36
|
+
*/
|
|
37
|
+
get empty(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the timestamp when input was created.
|
|
40
|
+
* @returns {number} Creation timestamp
|
|
41
|
+
*/
|
|
42
|
+
get time(): number;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the escape value.
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
get ESCAPE(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if the input is an escape sequence.
|
|
50
|
+
* @returns {boolean} True if input value is escape sequence, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
get escaped(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Validates if the input has a non-empty value.
|
|
55
|
+
* @returns {boolean} True if input is valid, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
get isValid(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Converts the input to a plain object representation.
|
|
60
|
+
* @returns {object} Object with all properties including timestamp
|
|
61
|
+
*/
|
|
62
|
+
toObject(): object;
|
|
63
|
+
/**
|
|
64
|
+
* Converts the input to a string representation including timestamp.
|
|
65
|
+
* @returns {string} String representation with timestamp and value
|
|
66
|
+
*/
|
|
67
|
+
toString(): string;
|
|
68
|
+
#private;
|
|
69
|
+
}
|
|
70
|
+
export type InputMessageValue = Message | string | null;
|
|
71
|
+
import { Message } from "@nan0web/co";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export default UIMessage;
|
|
2
|
+
/**
|
|
3
|
+
* Base UI message class.
|
|
4
|
+
*
|
|
5
|
+
* @class UIMessage
|
|
6
|
+
* @extends BaseMessage
|
|
7
|
+
*/
|
|
8
|
+
declare class UIMessage extends BaseMessage {
|
|
9
|
+
static TYPES: {
|
|
10
|
+
TEXT: string;
|
|
11
|
+
FORM: string;
|
|
12
|
+
PROGRESS: string;
|
|
13
|
+
ERROR: string;
|
|
14
|
+
INFO: string;
|
|
15
|
+
SUCCESS: string;
|
|
16
|
+
WARNING: string;
|
|
17
|
+
COMMAND: string;
|
|
18
|
+
NAVIGATION: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Creates a UIMessage instance from plain data.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} data - Message data.
|
|
24
|
+
* @returns {UIMessage}
|
|
25
|
+
*/
|
|
26
|
+
static from(data: any): UIMessage;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a UIMessage.
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} [input={}] - Message properties.
|
|
31
|
+
*/
|
|
32
|
+
constructor(input?: any);
|
|
33
|
+
/** @type {string} */
|
|
34
|
+
type: string;
|
|
35
|
+
/** @type {string} */
|
|
36
|
+
id: string;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the message type is valid.
|
|
39
|
+
*
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
isValidType(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether the message contains any body content.
|
|
45
|
+
*
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
isEmpty(): boolean;
|
|
49
|
+
}
|
|
50
|
+
import { Message as BaseMessage } from "@nan0web/co";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OutputMessage – message sent from the system to the UI.
|
|
3
|
+
*
|
|
4
|
+
* @class OutputMessage
|
|
5
|
+
* @extends UIMessage
|
|
6
|
+
*/
|
|
7
|
+
export default class OutputMessage extends UIMessage {
|
|
8
|
+
static PRIORITY: {
|
|
9
|
+
LOW: number;
|
|
10
|
+
NORMAL: number;
|
|
11
|
+
HIGH: number;
|
|
12
|
+
CRITICAL: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Creates an OutputMessage from plain input.
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} input - Message data.
|
|
18
|
+
* @returns {OutputMessage}
|
|
19
|
+
*/
|
|
20
|
+
static from(input: any): OutputMessage;
|
|
21
|
+
/** @type {string[]} */
|
|
22
|
+
body: string[];
|
|
23
|
+
/** @type {Object} */
|
|
24
|
+
meta: any;
|
|
25
|
+
/** @type {Error|null} */
|
|
26
|
+
error: Error | null;
|
|
27
|
+
/** @type {number} */
|
|
28
|
+
priority: number;
|
|
29
|
+
/** @param {string[]|string} value */
|
|
30
|
+
set content(arg: string[]);
|
|
31
|
+
/** @returns {string[]} */
|
|
32
|
+
get content(): string[];
|
|
33
|
+
/** @returns {number} */
|
|
34
|
+
get size(): number;
|
|
35
|
+
/** @returns {boolean} */
|
|
36
|
+
get isError(): boolean;
|
|
37
|
+
/** @returns {boolean} */
|
|
38
|
+
get isInfo(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Combines multiple messages into a new one.
|
|
41
|
+
*
|
|
42
|
+
* @param {...OutputMessage} messages - Messages to combine.
|
|
43
|
+
* @returns {OutputMessage}
|
|
44
|
+
*/
|
|
45
|
+
combine(...messages: OutputMessage[]): OutputMessage;
|
|
46
|
+
/**
|
|
47
|
+
* Serialises the message to a plain JSON object.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Object}
|
|
50
|
+
*/
|
|
51
|
+
toJSON(): any;
|
|
52
|
+
}
|
|
53
|
+
import UIMessage from "./Message.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export default OutputAdapter;
|
|
2
|
+
/**
|
|
3
|
+
* Abstract output adapter for UI implementations.
|
|
4
|
+
*
|
|
5
|
+
* @class OutputAdapter
|
|
6
|
+
* @extends Event
|
|
7
|
+
*/
|
|
8
|
+
declare class OutputAdapter extends Event {
|
|
9
|
+
/**
|
|
10
|
+
* Renders a message to the user.
|
|
11
|
+
*
|
|
12
|
+
* @param {OutputMessage|FormMessage} message - Message to render.
|
|
13
|
+
* @throws {Error} If not overridden by a subclass.
|
|
14
|
+
*/
|
|
15
|
+
render(message: OutputMessage | FormMessage): void;
|
|
16
|
+
/**
|
|
17
|
+
* Shows progress of a long‑running operation.
|
|
18
|
+
*
|
|
19
|
+
* @param {number} progress - Progress value in range 0‑1.
|
|
20
|
+
* @param {Object} [metadata={}] - Additional metadata.
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
progress(progress: number, metadata?: any): void;
|
|
24
|
+
/**
|
|
25
|
+
* Stops the output stream. Default implementation does nothing.
|
|
26
|
+
*
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
stop(): void;
|
|
30
|
+
}
|
|
31
|
+
import Event from '@nan0web/event/oop';
|
|
32
|
+
import OutputMessage from './Message/OutputMessage.js';
|
|
33
|
+
import FormMessage from './Form/Message.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agnostic UI stream for processing progress.
|
|
3
|
+
*
|
|
4
|
+
* @class UIStream
|
|
5
|
+
*/
|
|
6
|
+
export default class UIStream {
|
|
7
|
+
/**
|
|
8
|
+
* Creates an async generator that runs the supplied processor function.
|
|
9
|
+
*
|
|
10
|
+
* @param {AbortSignal} signal - Abort signal.
|
|
11
|
+
* @param {() => Promise<StreamEntry>} processorFn - Async function that returns a result.
|
|
12
|
+
* @returns {() => AsyncGenerator<StreamEntry>} Async generator function.
|
|
13
|
+
*/
|
|
14
|
+
static createProcessor(signal: AbortSignal, processorFn: () => Promise<StreamEntry>): () => AsyncGenerator<StreamEntry>;
|
|
15
|
+
/**
|
|
16
|
+
* Runs a generator with progress callbacks and abort handling.
|
|
17
|
+
*
|
|
18
|
+
* @param {AbortSignal} signal - Abort signal.
|
|
19
|
+
* @param {Function} generator - Function returning an async iterator.
|
|
20
|
+
* @param {Function} [onProgress] - Called with (progress, item).
|
|
21
|
+
* @param {Function} [onError] - Called with (errorMessage, item).
|
|
22
|
+
* @param {Function} [onComplete] - Called with (item) when done.
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
25
|
+
static process(signal: AbortSignal, generator: Function, onProgress?: Function | undefined, onError?: Function | undefined, onComplete?: Function | undefined): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
import StreamEntry from "./StreamEntry.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an entry in a stream with value, completion status, cancellation status, and error message.
|
|
3
|
+
*/
|
|
4
|
+
export default class StreamEntry {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a StreamEntry instance from the given input.
|
|
7
|
+
* @param {any} input - The input to create a StreamEntry from.
|
|
8
|
+
* @returns {StreamEntry} A new or existing StreamEntry instance.
|
|
9
|
+
*/
|
|
10
|
+
static from(input: any): StreamEntry;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new StreamEntry instance.
|
|
13
|
+
* @param {Object} [input={}] - Input object to initialize the stream entry.
|
|
14
|
+
* @param {any} [input.value] - The value for the stream entry.
|
|
15
|
+
* @param {boolean} [input.done] - Whether the stream entry is completed.
|
|
16
|
+
* @param {boolean} [input.cancelled] - Whether the stream entry is cancelled.
|
|
17
|
+
* @param {string} [input.error] - Error message for the stream entry.
|
|
18
|
+
*/
|
|
19
|
+
constructor(input?: {
|
|
20
|
+
value?: any;
|
|
21
|
+
done?: boolean | undefined;
|
|
22
|
+
cancelled?: boolean | undefined;
|
|
23
|
+
error?: string | undefined;
|
|
24
|
+
} | undefined);
|
|
25
|
+
/**
|
|
26
|
+
* The value of the stream entry.
|
|
27
|
+
* @type {any}
|
|
28
|
+
*/
|
|
29
|
+
value: any;
|
|
30
|
+
/**
|
|
31
|
+
* Indicates if the stream entry is done (completed).
|
|
32
|
+
* @type {boolean}
|
|
33
|
+
*/
|
|
34
|
+
done: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Indicates if the stream entry has been cancelled.
|
|
37
|
+
* @type {boolean}
|
|
38
|
+
*/
|
|
39
|
+
cancelled: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Error message associated with the stream entry.
|
|
42
|
+
* @type {string}
|
|
43
|
+
*/
|
|
44
|
+
error: string;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as InputAdapter } from "./InputAdapter.js";
|
|
2
|
+
export { default as OutputAdapter } from "./OutputAdapter.js";
|
|
3
|
+
export { default as UIStream } from "./Stream.js";
|
|
4
|
+
export { default as UIMessage } from "./Message/Message.js";
|
|
5
|
+
export { default as InputMessage } from "./Message/InputMessage.js";
|
|
6
|
+
export { default as OutputMessage } from "./Message/OutputMessage.js";
|
|
7
|
+
export { default as FormMessage } from "./Form/Message.js";
|
|
8
|
+
export { default as FormInput } from "./Form/Input.js";
|
|
9
|
+
export { default as UIForm } from "./Form/Form.js";
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { default as FormMessage } from "./core/Form/Message.js";
|
|
2
|
+
export { default as FormInput } from "./core/Form/Input.js";
|
|
3
|
+
export { default as InputAdapter } from "./core/InputAdapter.js";
|
|
4
|
+
export { default as InputMessage } from "./core/Message/InputMessage.js";
|
|
5
|
+
export { default as OutputAdapter } from "./core/OutputAdapter.js";
|
|
6
|
+
export { default as OutputMessage } from "./core/Message/OutputMessage.js";
|
|
7
|
+
export { default as UIForm } from "./core/Form/Form.js";
|
|
8
|
+
export { default as UIMessage } from "./core/Message/Message.js";
|
|
9
|
+
export { default as UIStream } from "./core/Stream.js";
|
|
10
|
+
import Frame from "./Frame/Frame.js";
|
|
11
|
+
import FrameProps from "./Frame/Props.js";
|
|
12
|
+
import Locale from "./Locale.js";
|
|
13
|
+
import StdIn from "./StdIn.js";
|
|
14
|
+
import StdOut from "./StdOut.js";
|
|
15
|
+
import View from "./View/View.js";
|
|
16
|
+
import RenderOptions from "./View/RenderOptions.js";
|
|
17
|
+
import Model from "./Model/index.js";
|
|
18
|
+
import Component from "./Component/index.js";
|
|
19
|
+
import App from "./App/index.js";
|
|
20
|
+
export { Frame, FrameProps, Locale, StdIn, StdOut, View, RenderOptions, Model, Component, App };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain model without any UI‑specific extensions.
|
|
3
|
+
*
|
|
4
|
+
* The form for this model will be generated automatically from its properties.
|
|
5
|
+
*/
|
|
6
|
+
export default class SimpleUser {
|
|
7
|
+
/**
|
|
8
|
+
* @param {Object} data
|
|
9
|
+
* @param {string} [data.name]
|
|
10
|
+
* @param {string} [data.email]
|
|
11
|
+
* @param {number | null} [data.age]
|
|
12
|
+
*/
|
|
13
|
+
constructor({ name, email, age }?: {
|
|
14
|
+
name?: string | undefined;
|
|
15
|
+
email?: string | undefined;
|
|
16
|
+
age?: number | null | undefined;
|
|
17
|
+
});
|
|
18
|
+
name: string;
|
|
19
|
+
email: string;
|
|
20
|
+
age: number | null;
|
|
21
|
+
}
|
package/vitest.config.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import process from "node:process"
|
|
2
|
+
import { defineConfig } from "vitest/config"
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
sourcemap: true,
|
|
7
|
+
environment: "node",
|
|
8
|
+
cache: false,
|
|
9
|
+
root: process.cwd(),
|
|
10
|
+
coverage: {
|
|
11
|
+
provider: "v8",
|
|
12
|
+
},
|
|
13
|
+
exclude: [
|
|
14
|
+
"apps/**",
|
|
15
|
+
"node_modules/**",
|
|
16
|
+
],
|
|
17
|
+
isolate: false,
|
|
18
|
+
// Try to force inline source maps for best debugging
|
|
19
|
+
// (Vite will use inline source maps for dev by default)
|
|
20
|
+
},
|
|
21
|
+
resolve: {
|
|
22
|
+
alias: {
|
|
23
|
+
"@": "/src",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
})
|