@nan0web/ui 1.0.0 → 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.
Files changed (42) hide show
  1. package/README.md +7 -1
  2. package/package.json +6 -1
  3. package/src/README.md.js +23 -0
  4. package/src/core/Error/CancelError.js +6 -0
  5. package/src/core/InputAdapter.js +21 -3
  6. package/types/core/Error/CancelError.d.ts +3 -0
  7. package/types/core/InputAdapter.d.ts +18 -2
  8. package/.datasets/README.dataset.jsonl +0 -12
  9. package/.editorconfig +0 -20
  10. package/CONTRIBUTING.md +0 -42
  11. package/docs/uk/README.md +0 -240
  12. package/playground/User.js +0 -52
  13. package/playground/currency.exchange.js +0 -48
  14. package/playground/i18n/index.js +0 -21
  15. package/playground/i18n/uk.js +0 -53
  16. package/playground/language.form.js +0 -25
  17. package/playground/main.js +0 -72
  18. package/playground/registration.form.js +0 -58
  19. package/playground/topup.telephone.js +0 -62
  20. package/src/App/User/UserApp.test.js +0 -56
  21. package/src/App/User/UserUI.test.js +0 -51
  22. package/src/Frame/Frame.test.js +0 -429
  23. package/src/View/View.test.js +0 -77
  24. package/src/core/Form/Form.test.js +0 -116
  25. package/src/core/Form/Input.test.js +0 -58
  26. package/src/core/Form/Message.test.js +0 -54
  27. package/src/core/InputAdapter.test.js +0 -35
  28. package/src/core/Message/InputMessage.test.js +0 -45
  29. package/src/core/Message/Message.test.js +0 -58
  30. package/src/core/Message/OutputMessage.test.js +0 -61
  31. package/src/core/OutputAdapter.test.js +0 -35
  32. package/src/core/Stream.test.js +0 -78
  33. package/src/index.test.js +0 -14
  34. package/stories/App/AppView.js +0 -15
  35. package/stories/App/AppView.test.js +0 -22
  36. package/stories/App/RenderOptions.js +0 -14
  37. package/stories/nodejs/interface.test.js +0 -27
  38. package/system.md +0 -187
  39. package/system1.md +0 -137
  40. package/task.md +0 -181
  41. package/tsconfig.json +0 -23
  42. package/vitest.config.js +0 -26
package/system1.md DELETED
@@ -1,137 +0,0 @@
1
- # System Instructions for NaN•UI
2
-
3
- ## Overview
4
- NaN•UI is a Vanilla JavaScript UI framework designed to be platform-agnostic, working seamlessly in Node.js, browsers, and other environments that support ESM. The framework emphasizes minimal dependencies, clean class structures, and comprehensive testing with Vitest.
5
-
6
- ## Requirements
7
-
8
- ### JavaScript
9
- 1. **Pure Vanilla JS**: Only use vanilla JavaScript without platform-specific dependencies.
10
- 2. **Platform Abstraction**: Ensure the code works across different platforms.
11
- 3. **Minimal Dependencies**: Keep dependencies to a minimum.
12
- 4. **Class Structure**:
13
- - **Order of Class Elements**:
14
- - Static properties
15
- - Properties
16
- - Constructor
17
- - Getters
18
- - Setters
19
- - Base functions
20
- - Async functions
21
- - Static base functions
22
- - Static async functions
23
- 5. **Views**:
24
- - Each view must have a separate file and test file (`View/AppView.js` and `View/AppView.test.js`).
25
- 6. **Components**:
26
- - Each component must have a separate directory in `View/Component/*` or be registered from another directory with the following files:
27
- - `Component.js`
28
- - `Component.test.js`
29
- - `ComponentInput.js`
30
- - `index.js` (exporting the component and its input class).
31
-
32
- ### Vitest
33
- - All tests must run with Vitest.
34
- - Every model, component, and class must have its own test file to cover functionality in an isolated environment.
35
-
36
- ## Interfaces
37
-
38
- ### Views
39
- - **Widgets**: Control elements that include a view and the ability to input data.
40
- - **Output**: Data passed to the view in a specific format.
41
- - **Input**: Data required by the application, which can be provided via command line or user input.
42
-
43
- ### Cross-Platform
44
- - Extend basic UI with different apps (e.g., CLI, web).
45
- - **Core Application**: Minimal stdin/stdout implementation.
46
- - **CLI Application**: Utilizes libraries like `blessed` for rich CLI UI.
47
- - **Web Application**: Utilizes libraries like `lit` for rich web UI.
48
-
49
- ## Code Structure
50
-
51
- ### Core Application
52
- - **`src/App/Command/Args.js`**: Handles command arguments.
53
- - **`src/App/Command/Message.js`**: Parses and processes command messages.
54
- - **`src/App/Command/Options.js`**: Manages command options.
55
- - **`src/App/Core/CCoreApp.js`**: Abstract base class for all apps.
56
- - **`src/App/Core/UI.js`**: Abstract UI class to connect apps and widgets.
57
- - **`src/App/Core/Widget.js`**: Abstract widget class with input/output capabilities.
58
-
59
- ### User Application
60
- - **`src/App/User/UserApp.js`**: User-specific application logic.
61
- - **`src/App/User/UserUI.js`**: Connects UserApp and View.
62
-
63
- ### Components
64
- - **`src/Component/Process/Process.js`**: Process component with input handling.
65
- - **`src/Component/Welcome/Welcome.js`**: Welcome component with user input handling.
66
-
67
- ### Views
68
- - **`src/View/View.js`**: Main view class with rendering and input/output capabilities.
69
-
70
- ### Models
71
- - **`src/Model/User/User.js`**: User model class.
72
-
73
- ### Utilities
74
- - **`src/Frame/Frame.js`**: Handles frame rendering and formatting.
75
- - **`src/InputMessage.js`**: Manages input messages.
76
- - **`src/Locale.js`**: Handles localization and formatting.
77
- - **`src/StdIn.js`**: Manages standard input.
78
- - **`src/StdOut.js`**: Manages standard output.
79
-
80
- ## Testing
81
- - **Vitest**: All tests are written using Vitest.
82
- - **Test Files**: Each component, model, and class has a corresponding test file (e.g., `Component.test.js`, `Model.test.js`).
83
-
84
- ## Apps
85
- - **CLI App**: Located in `apps/cli/src/`, handles command-line interface.
86
- - **Web App**: Located in `apps/web/src/`, handles web interface.
87
-
88
- ## Example Usage
89
-
90
- ### CLI App
91
- ```javascript
92
- import process from "node:process"
93
- import { App, View, StdIn, StdOut, Frame, Component } from "@nan0web/ui"
94
-
95
- async function main(argv) {
96
- const app = new App.User.App({ argv })
97
- const view = new View({
98
- stdin: new StdIn({ processor: process.stdin }),
99
- stdout: new StdOut({ processor: process.stdout }),
100
- renderMethod: Frame.RenderMethod.VISIBLE,
101
- })
102
- view.register(Component.Welcome)
103
-
104
- const ui = new App.User.UI(app, view)
105
- await ui.process(argv)
106
- }
107
-
108
- main(process.argv.slice(2)).then(() => {
109
- process.exit(0)
110
- }).catch(err => {
111
- console.error("Error:", err)
112
- process.exit(1)
113
- })
114
- ```
115
-
116
- ### Web App
117
- ```javascript
118
- import React from "react"
119
- import UserDocumentsInput from "src/components/User/DocumentsInput.js"
120
-
121
- function UserDocumentsView(input = {}) {
122
- input = UserDocumentsInput.from(input)
123
- if (empty(input)) {
124
- throw new Error("Input data required in a format off UserDocumentsInput")
125
- }
126
-
127
- return <div>
128
- <h3>Documents</h3>
129
- <ul>
130
- {input.documents.map((d, i) => <li key={i}>{d.name}</li>)}
131
- </ul>
132
- </div>
133
- }
134
- ```
135
-
136
- ## Conclusion
137
- NaN•UI provides a robust, platform-agnostic framework for building UIs with minimal dependencies. The code is structured to ensure clarity, maintainability, and comprehensive test coverage. By following the outlined requirements and structure, developers can build scalable and maintainable UI components and applications.
package/task.md DELETED
@@ -1,181 +0,0 @@
1
- Інструкція для наступних кроків
2
-
3
- ## [+] Написання тестів для всіх класів
4
-
5
- План дій:
6
- - **Створити тестові файли** для кожного класу у тій самій директорії з суфіксом `.test.js`:
7
-
8
- ```
9
- src/
10
- ├── core/
11
- │ ├── Form/
12
- │ │ ├── Form.test.js
13
- │ │ ├── Message.test.js
14
- │ │ └── Input.test.js
15
- │ ├── Message/
16
- │ │ ├── InputMessage.test.js
17
- │ │ ├── Message.test.js
18
- │ │ ├── OutputMessage.test.js
19
- │ ├── InputAdapter.test.js
20
- │ ├── OutputAdapter.test.js
21
- │ └── Stream.test.js
22
- ```
23
- - **Використовувати `node:test`** для тестування базових класів (не `.jsx` компонентів)
24
-
25
- - **Тестувати всі можливі випадки**:
26
-
27
- - Конструктори з різними типами вхідних даних
28
- - Методи `from()` для нормалізації
29
- - Роботу з обов'язковими/необов'язковими полями
30
- - Валідацію форм
31
- - Поведінку потоків
32
- - **Використовувати асерти**:
33
- ```js
34
- import { describe, it } from "node:test"
35
- import { strict as assert } from "node:assert"
36
-
37
- describe("ClassName", () => {
38
- it("should create instance", () => {
39
- // Ваш тест
40
- })
41
- })
42
- ```
43
- - **Запуск тестів**:
44
-
45
- ```bash
46
- npm test
47
- # або
48
- node --test --experimental-worker
49
- ```
50
-
51
- ## [+] Написання прикладів використання (playground)
52
-
53
- План дій:
54
- - **Створити директорію** `playground/` у корені проекту
55
-
56
- - **Створити окремі файли** для різних сценаріїв:
57
-
58
- ```
59
- playground/
60
- ├── form-basic.js # Базова форма
61
- ├── form-advanced.js # Складна форма з різними типами полів
62
- ├── stream-basic.js # Базовий потік даних
63
- ├── stream-interactive.js # Інтерактивний потік
64
- ├── error-handling.js # Обробка помилок
65
- └── integration.js # Інтеграція з реальним додатком
66
- ```
67
- - **Кожен приклад має містити**:
68
-
69
- - Імпорти необхідних класів
70
- - Створення екземплярів
71
- - Налаштування обробників подій
72
- - Приклади використання
73
- - **Додати інструкцію** у `README.md` як запускати приклади:
74
- ```bash
75
- node playground/form-basic.js
76
- ```
77
- - **Перевірити працездатність** всіх прикладів
78
-
79
- ## [+] Написання JSDoc для всіх полів і функцій
80
-
81
- План дій:
82
- - **Пройтися по всім файлам** і додати JSDoc коментарі до:
83
-
84
- **Для класів:**
85
- ```js
86
- /**
87
- * Опис класу
88
- * @class
89
- * @extends {BaseClass}
90
- * @example
91
- * // Приклад використання
92
- * const instance = new ClassName()
93
- */
94
- ```
95
- **Для властивостей:**
96
- ```js
97
- /** @type {string} Опис властивості */
98
- propertyName
99
- ```
100
- **Для конструкторів:**
101
- ```js
102
- /**
103
- * Створює екземпляр класу
104
- * @param {Object} [props] - Властивості екземпляра
105
- * @param {string} [props.name=""] - Ім'я елемента
106
- * @param {boolean} [props.active=false] - Чи активний елемент
107
- */
108
- constructor(props = {}) { ... }
109
- ```
110
- **Для методів:**
111
- ```js
112
- /**
113
- * Опис методу
114
- * @param {string} paramName - Опис параметра
115
- * @returns {ReturnType} Опис поверненого значення
116
- * @throws {Error} Опис можливих помилок
117
- */
118
- methodName(paramName) { ... }
119
- ```
120
- - **Використовувати англійську мову** для всіх коментарів
121
-
122
- - **Перевірити сумісність** з TypeScript деклараціями (використання `@typedef`, `@template` тощо)
123
-
124
- - **Запуск `tsc --emitDeclarationOnly`** для перевірки генерації `.d.ts` файлів
125
-
126
- ## [ ] Написання README.md
127
-
128
- Структура README.md:
129
- - **Заголовок та короткий опис**
130
-
131
- ```
132
- # @nan0web/ui
133
- Агностичний UI фреймворк для багатошарових додатків.
134
- Одна логіка, багато інтерфейсів.
135
- ```
136
- - **Функціональність**
137
-
138
- - Базові повідомлення: `InputMessage`, `OutputMessage`
139
- - Форми та їх валідація
140
- - Потокові операції
141
- - Абстрактні адаптери
142
- - **Встановлення**
143
-
144
- ```bash
145
- npm install @nan0web/ui
146
- ```
147
- - **Приклади використання**
148
-
149
- ```js
150
- import { InputMessage, OutputMessage } from '@nan0web/ui'
151
- const input = InputMessage.from({ value: 'Hello' })
152
- const output = OutputMessage.from({ content: ['Hello World'] })
153
- ```
154
- - **Основні класи**
155
-
156
- - `UIMessage` - базовий клас для всіх повідомлень
157
- - `InputMessage` - для отримання даних від користувача
158
- - `OutputMessage` - для відображення даних
159
- - `UIForm` - для роботи з формами
160
- - `UIStream` - для асинхронних операцій
161
- - **API Документація**
162
-
163
- Посилання на файли з JSDoc
164
- - **Приклади**
165
-
166
- Посилання на директорію `playground/`
167
- - **Запуск тестів**
168
-
169
- ```bash
170
- npm test
171
- ```
172
- - **Ліцензія**
173
-
174
- ```
175
- MIT License
176
- ```
177
- Загальна послідовність дій:
178
- - **Спочатку напишіть тести** - це допоможе зрозуміти, чи все працює як очікувалось
179
- - **Потім створіть приклади** - вони стануть частиною документації
180
- - **Додайте JSDoc коментарі** - природно зробити це під час перегляду коду
181
- - **Напишіть README.md** - використовуючи матеріали з попередніх кроків
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "nodenext",
5
- "lib": ["esnext"],
6
- "declaration": true,
7
- "declarationMap": false,
8
- "emitDeclarationOnly": true,
9
- "outDir": "./types",
10
- "rootDir": "./src",
11
- "strict": true,
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "moduleResolution": "nodenext",
16
- "allowSyntheticDefaultImports": true,
17
- "noImplicitAny": false,
18
- "allowJs": true,
19
- "checkJs": true
20
- },
21
- "include": ["src/**/*"],
22
- "exclude": ["node_modules", "src/**/*.test.js", "src/README.md.js"]
23
- }
package/vitest.config.js DELETED
@@ -1,26 +0,0 @@
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
- })