iwgt 2.4.11 → 2.4.13

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.
@@ -0,0 +1,412 @@
1
+ /**
2
+ * Утилиты для создания настроек виджетов с валидацией
3
+ */
4
+ import { validateSetting, isValidSettingType } from '../types/settings.js';
5
+ /**
6
+ * Создает текстовую настройку
7
+ */
8
+ export function createTextSetting(config) {
9
+ const setting = {
10
+ type: 'text',
11
+ name: config.name,
12
+ label: config.label,
13
+ value: config.value,
14
+ help: config.help,
15
+ general: config.general,
16
+ general_position: config.general_position,
17
+ general_label: config.general_label,
18
+ enable_server_reload: config.enable_server_reload,
19
+ hide_mobile: config.hide_mobile,
20
+ class: config.class,
21
+ placeholder: config.placeholder
22
+ };
23
+ const validation = validateSetting(setting);
24
+ if (!validation.isValid) {
25
+ throw new Error(`Некорректная текстовая настройка "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
26
+ }
27
+ return setting;
28
+ }
29
+ /**
30
+ * Создает числовую настройку
31
+ */
32
+ export function createNumberSetting(config) {
33
+ const setting = {
34
+ type: 'number',
35
+ name: config.name,
36
+ label: config.label,
37
+ value: config.value,
38
+ min: config.min,
39
+ max: config.max,
40
+ step: config.step,
41
+ unit: config.unit,
42
+ with_btns: config.with_btns,
43
+ help: config.help,
44
+ general: config.general,
45
+ general_position: config.general_position,
46
+ general_label: config.general_label,
47
+ enable_server_reload: config.enable_server_reload,
48
+ hide_mobile: config.hide_mobile,
49
+ class: config.class
50
+ };
51
+ const validation = validateSetting(setting);
52
+ if (!validation.isValid) {
53
+ throw new Error(`Некорректная числовая настройка "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
54
+ }
55
+ return setting;
56
+ }
57
+ /**
58
+ * Создает настройку-чекбокс
59
+ */
60
+ export function createCheckboxSetting(config) {
61
+ const setting = {
62
+ type: 'checkbox',
63
+ name: config.name,
64
+ label: config.label,
65
+ value: config.value,
66
+ help: config.help,
67
+ general: config.general,
68
+ general_position: config.general_position,
69
+ general_label: config.general_label,
70
+ enable_server_reload: config.enable_server_reload,
71
+ hide_mobile: config.hide_mobile,
72
+ class: config.class
73
+ };
74
+ const validation = validateSetting(setting);
75
+ if (!validation.isValid) {
76
+ throw new Error(`Некорректная настройка-чекбокс "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
77
+ }
78
+ return setting;
79
+ }
80
+ /**
81
+ * Создает настройку-селект
82
+ */
83
+ export function createSelectSetting(config) {
84
+ const setting = {
85
+ type: 'select',
86
+ name: config.name,
87
+ label: config.label,
88
+ options: config.options,
89
+ value: config.value,
90
+ help: config.help,
91
+ general: config.general,
92
+ general_position: config.general_position,
93
+ general_label: config.general_label,
94
+ enable_server_reload: config.enable_server_reload,
95
+ hide_mobile: config.hide_mobile,
96
+ class: config.class
97
+ };
98
+ const validation = validateSetting(setting);
99
+ if (!validation.isValid) {
100
+ throw new Error(`Некорректная настройка-селект "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
101
+ }
102
+ return setting;
103
+ }
104
+ /**
105
+ * Создает настройку-ползунок
106
+ */
107
+ export function createRangeSetting(config) {
108
+ const setting = {
109
+ type: 'range',
110
+ name: config.name,
111
+ label: config.label,
112
+ value: config.value,
113
+ min: config.min,
114
+ max: config.max,
115
+ step: config.step,
116
+ unit: config.unit,
117
+ with_btns: config.with_btns,
118
+ help: config.help,
119
+ general: config.general,
120
+ general_position: config.general_position,
121
+ general_label: config.general_label,
122
+ enable_server_reload: config.enable_server_reload,
123
+ hide_mobile: config.hide_mobile,
124
+ class: config.class
125
+ };
126
+ const validation = validateSetting(setting);
127
+ if (!validation.isValid) {
128
+ throw new Error(`Некорректная настройка-ползунок "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
129
+ }
130
+ return setting;
131
+ }
132
+ /**
133
+ * Создает настройку-группу кнопок
134
+ */
135
+ export function createButtonGroupSetting(config) {
136
+ const setting = {
137
+ type: 'button-group',
138
+ name: config.name,
139
+ label: config.label,
140
+ options: config.options,
141
+ value: config.value,
142
+ help: config.help,
143
+ general: config.general,
144
+ general_position: config.general_position,
145
+ general_label: config.general_label,
146
+ enable_server_reload: config.enable_server_reload,
147
+ hide_mobile: config.hide_mobile,
148
+ class: config.class
149
+ };
150
+ const validation = validateSetting(setting);
151
+ if (!validation.isValid) {
152
+ throw new Error(`Некорректная настройка-группа кнопок "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
153
+ }
154
+ return setting;
155
+ }
156
+ /**
157
+ * Создает настройку-файл
158
+ */
159
+ export function createFileSetting(config) {
160
+ const setting = {
161
+ type: 'file',
162
+ name: config.name,
163
+ label: config.label,
164
+ value: config.value,
165
+ 'with-generate-logo': config['with-generate-logo'],
166
+ help: config.help,
167
+ general: config.general,
168
+ general_position: config.general_position,
169
+ general_label: config.general_label,
170
+ enable_server_reload: config.enable_server_reload,
171
+ hide_mobile: config.hide_mobile,
172
+ class: config.class
173
+ };
174
+ const validation = validateSetting(setting);
175
+ if (!validation.isValid) {
176
+ throw new Error(`Некорректная настройка-файл "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
177
+ }
178
+ return setting;
179
+ }
180
+ /**
181
+ * Создает настройку-цвет
182
+ */
183
+ export function createColorSetting(config) {
184
+ const setting = {
185
+ type: 'color',
186
+ name: config.name,
187
+ label: config.label,
188
+ value: config.value,
189
+ clearable: config.clearable,
190
+ fallback: config.fallback,
191
+ help: config.help,
192
+ general: config.general,
193
+ general_position: config.general_position,
194
+ general_label: config.general_label,
195
+ enable_server_reload: config.enable_server_reload,
196
+ hide_mobile: config.hide_mobile,
197
+ class: config.class
198
+ };
199
+ const validation = validateSetting(setting);
200
+ if (!validation.isValid) {
201
+ throw new Error(`Некорректная настройка-цвет "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
202
+ }
203
+ return setting;
204
+ }
205
+ /**
206
+ * Создает настройку-блог
207
+ */
208
+ export function createBlogSetting(config) {
209
+ const setting = {
210
+ type: 'blog',
211
+ name: config.name,
212
+ label: config.label,
213
+ value: config.value,
214
+ edit_admin_link: config.edit_admin_link,
215
+ help: config.help,
216
+ general: config.general,
217
+ general_position: config.general_position,
218
+ general_label: config.general_label,
219
+ enable_server_reload: config.enable_server_reload,
220
+ hide_mobile: config.hide_mobile,
221
+ class: config.class
222
+ };
223
+ const validation = validateSetting(setting);
224
+ if (!validation.isValid) {
225
+ throw new Error(`Некорректная настройка-блог "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
226
+ }
227
+ return setting;
228
+ }
229
+ /**
230
+ * Валидирует массив настроек
231
+ */
232
+ export function validateSettings(settings) {
233
+ const errors = [];
234
+ settings.forEach(setting => {
235
+ const validation = validateSetting(setting);
236
+ if (!validation.isValid) {
237
+ errors.push({
238
+ setting: setting.name || 'unnamed',
239
+ errors: validation.errors.map((e) => e.message)
240
+ });
241
+ }
242
+ });
243
+ return {
244
+ isValid: errors.length === 0,
245
+ errors
246
+ };
247
+ }
248
+ /**
249
+ * Создает информационную настройку
250
+ */
251
+ export function createInfoSetting(config) {
252
+ const setting = {
253
+ type: 'info',
254
+ name: config.name,
255
+ label: config.label,
256
+ value: config.value,
257
+ help: config.help,
258
+ general: config.general,
259
+ general_position: config.general_position,
260
+ general_label: config.general_label,
261
+ enable_server_reload: config.enable_server_reload,
262
+ hide_mobile: config.hide_mobile,
263
+ class: config.class
264
+ };
265
+ const validation = validateSetting(setting);
266
+ if (!validation.isValid) {
267
+ throw new Error(`Некорректная информационная настройка "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
268
+ }
269
+ return setting;
270
+ }
271
+ /**
272
+ * Создает настройку описания текущей страницы
273
+ */
274
+ export function createCurrentPageDescriptionSetting(config) {
275
+ const setting = {
276
+ type: 'current-page-description',
277
+ name: config.name,
278
+ label: config.label,
279
+ value: config.value,
280
+ help: config.help,
281
+ general: config.general,
282
+ general_position: config.general_position,
283
+ general_label: config.general_label,
284
+ enable_server_reload: config.enable_server_reload,
285
+ hide_mobile: config.hide_mobile,
286
+ class: config.class
287
+ };
288
+ const validation = validateSetting(setting);
289
+ if (!validation.isValid) {
290
+ throw new Error(`Некорректная настройка описания страницы "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
291
+ }
292
+ return setting;
293
+ }
294
+ /**
295
+ * Создает настройку группы иконок
296
+ */
297
+ export function createIconGroupSetting(config) {
298
+ const setting = {
299
+ type: 'icon_group',
300
+ name: config.name,
301
+ label: config.label,
302
+ value: config.value,
303
+ help: config.help,
304
+ general: config.general,
305
+ general_position: config.general_position,
306
+ general_label: config.general_label,
307
+ enable_server_reload: config.enable_server_reload,
308
+ hide_mobile: config.hide_mobile,
309
+ class: config.class
310
+ };
311
+ const validation = validateSetting(setting);
312
+ if (!validation.isValid) {
313
+ throw new Error(`Некорректная настройка группы иконок "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
314
+ }
315
+ return setting;
316
+ }
317
+ /**
318
+ * Создает настройку ссылки на виджет
319
+ */
320
+ export function createLinkToWidgetSetting(config) {
321
+ const setting = {
322
+ type: 'link-to-widget',
323
+ name: config.name,
324
+ label: config.label,
325
+ value: config.value,
326
+ help: config.help,
327
+ general: config.general,
328
+ general_position: config.general_position,
329
+ general_label: config.general_label,
330
+ enable_server_reload: config.enable_server_reload,
331
+ hide_mobile: config.hide_mobile,
332
+ class: config.class
333
+ };
334
+ const validation = validateSetting(setting);
335
+ if (!validation.isValid) {
336
+ throw new Error(`Некорректная настройка ссылки на виджет "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
337
+ }
338
+ return setting;
339
+ }
340
+ /**
341
+ * Создает настройку переключателя кнопок
342
+ */
343
+ export function createButtonSwitchSetting(config) {
344
+ const setting = {
345
+ type: 'button_switch',
346
+ name: config.name,
347
+ label: config.label,
348
+ value: config.value,
349
+ help: config.help,
350
+ general: config.general,
351
+ general_position: config.general_position,
352
+ general_label: config.general_label,
353
+ enable_server_reload: config.enable_server_reload,
354
+ hide_mobile: config.hide_mobile,
355
+ class: config.class
356
+ };
357
+ const validation = validateSetting(setting);
358
+ if (!validation.isValid) {
359
+ throw new Error(`Некорректная настройка переключателя кнопок "${config.name}": ${validation.errors.map((e) => e.message).join(', ')}`);
360
+ }
361
+ return setting;
362
+ }
363
+ /**
364
+ * Создает настройку с автоматическим определением типа
365
+ */
366
+ export function createSetting(config) {
367
+ if (!isValidSettingType(config.type)) {
368
+ throw new Error(`Неизвестный тип настройки: ${config.type}. Доступные типы: ${['text', 'rich-text', 'number', 'checkbox', 'select', 'range', 'button-group', 'file', 'color', 'blog', 'info', 'current-page-description', 'icon_group', 'link-to-widget', 'button_switch'].join(', ')}`);
369
+ }
370
+ const { type, name, label, ...rest } = config;
371
+ switch (type) {
372
+ case 'text':
373
+ return createTextSetting({ name, label, ...rest });
374
+ case 'rich-text':
375
+ return createTextSetting({ name, label, ...rest }); // Используем текстовую настройку
376
+ case 'number':
377
+ return createNumberSetting({ name, label, ...rest });
378
+ case 'checkbox':
379
+ return createCheckboxSetting({ name, label, ...rest });
380
+ case 'select':
381
+ if (!rest.options) {
382
+ throw new Error(`Для типа select обязательно поле options`);
383
+ }
384
+ return createSelectSetting({ name, label, ...rest });
385
+ case 'range':
386
+ return createRangeSetting({ name, label, ...rest });
387
+ case 'button-group':
388
+ if (!rest.options) {
389
+ throw new Error(`Для типа button-group обязательно поле options`);
390
+ }
391
+ return createButtonGroupSetting({ name, label, ...rest });
392
+ case 'file':
393
+ return createFileSetting({ name, label, ...rest });
394
+ case 'color':
395
+ return createColorSetting({ name, label, ...rest });
396
+ case 'blog':
397
+ return createBlogSetting({ name, label, ...rest });
398
+ case 'info':
399
+ return createInfoSetting({ name, label, ...rest });
400
+ case 'current-page-description':
401
+ return createCurrentPageDescriptionSetting({ name, label, ...rest });
402
+ case 'icon_group':
403
+ return createIconGroupSetting({ name, label, ...rest });
404
+ case 'link-to-widget':
405
+ return createLinkToWidgetSetting({ name, label, ...rest });
406
+ case 'button_switch':
407
+ return createButtonSwitchSetting({ name, label, ...rest });
408
+ default:
409
+ throw new Error(`Тип ${type} не поддерживается`);
410
+ }
411
+ }
412
+ //# sourceMappingURL=settings.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iwgt",
3
- "version": "2.4.11",
3
+ "version": "2.4.13",
4
4
  "description": "MCP server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",