@matreshka/bff 0.19.0 → 0.20.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.
@@ -36,10 +36,10 @@ type DefaultInitConfigType = BoardInitConfig<Board>;
36
36
  export declare class Board<InitConfigType extends BoardInitConfig<any> = DefaultInitConfigType, PropertiesType extends BoardProperties = BoardProperties> extends Component<InitConfigType, PropertiesType> implements StandaloneComponent, ItemListHost {
37
37
  private readonly itemsSlot;
38
38
  private readonly itemListHostAdapter;
39
- setCenter(center: BoardPoint, instances?: ComponentInstance[]): void;
40
- setZoom(zoom: number, instances?: ComponentInstance[]): void;
41
- zoomIn(instances?: ComponentInstance[]): void;
42
- zoomOut(instances?: ComponentInstance[]): void;
39
+ setCenter(center: BoardPoint, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
40
+ setZoom(zoom: number, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
41
+ zoomIn(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
42
+ zoomOut(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
43
43
  constructor(config: InitConfigType);
44
44
  get hostInstances(): readonly ComponentInstance[];
45
45
  syncNestedItems(slot: string, items: NestedItemBase[]): void;
@@ -18,52 +18,16 @@ const board = (config) => new Board(config);
18
18
  exports.board = board;
19
19
  class Board extends component_1.Component {
20
20
  setCenter(center, instances) {
21
- if (instances) {
22
- instances
23
- .filter((instance) => instance.client)
24
- .forEach((instance) => {
25
- instance.client.outcomingMessage$.next(new board_set_center_message_1.BoardSetCenterMessage(instance.id, center));
26
- });
27
- }
28
- else {
29
- this.broadcast(new board_set_center_message_1.BoardSetCenterMessage(this.id, center));
30
- }
21
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new board_set_center_message_1.BoardSetCenterMessage(target, { ...center, actionScope }));
31
22
  }
32
23
  setZoom(zoom, instances) {
33
- if (instances) {
34
- instances
35
- .filter((instance) => instance.client)
36
- .forEach((instance) => {
37
- instance.client.outcomingMessage$.next(new board_set_zoom_message_1.BoardSetZoomMessage(instance.id, zoom));
38
- });
39
- }
40
- else {
41
- this.broadcast(new board_set_zoom_message_1.BoardSetZoomMessage(this.id, zoom));
42
- }
24
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new board_set_zoom_message_1.BoardSetZoomMessage(target, { zoom, actionScope }));
43
25
  }
44
26
  zoomIn(instances) {
45
- if (instances) {
46
- instances
47
- .filter((instance) => instance.client)
48
- .forEach((instance) => {
49
- instance.client.outcomingMessage$.next(new board_zoom_in_message_1.BoardZoomInMessage(instance.id));
50
- });
51
- }
52
- else {
53
- this.broadcast(new board_zoom_in_message_1.BoardZoomInMessage(this.id));
54
- }
27
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new board_zoom_in_message_1.BoardZoomInMessage(target, actionScope));
55
28
  }
56
29
  zoomOut(instances) {
57
- if (instances) {
58
- instances
59
- .filter((instance) => instance.client)
60
- .forEach((instance) => {
61
- instance.client.outcomingMessage$.next(new board_zoom_out_message_1.BoardZoomOutMessage(instance.id));
62
- });
63
- }
64
- else {
65
- this.broadcast(new board_zoom_out_message_1.BoardZoomOutMessage(this.id));
66
- }
30
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new board_zoom_out_message_1.BoardZoomOutMessage(target, actionScope));
67
31
  }
68
32
  constructor(config) {
69
33
  const itemsSlot = (0, item_list_1.createNestedItemsSlotState)(config.items);
@@ -68,7 +68,7 @@ export declare class Camera<ContentType extends ComponentTreeNode = ComponentTre
68
68
  /**
69
69
  * Отправляет на клиент команду переключения активной камеры устройства на указанную.
70
70
  */
71
- switchCamera(device: VideoInputDevice, instances?: ComponentInstance[]): this;
71
+ switchCamera(device: VideoInputDevice, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
72
72
  protected serializeRuleOverrides(overrides: Partial<PropertiesType>): Record<string, unknown>;
73
73
  serialize(): CameraConfig;
74
74
  }
@@ -72,21 +72,8 @@ class Camera extends component_1.Component {
72
72
  * Отправляет на клиент команду переключения активной камеры устройства на указанную.
73
73
  */
74
74
  switchCamera(device, instances) {
75
- if (instances) {
76
- instances
77
- .filter((instance) => instance.client)
78
- .forEach((instance) => {
79
- instance.client.outcomingMessage$.next(new camera_switch_message_1.CameraSwitchMessage(instance.id, {
80
- deviceId: device.deviceId,
81
- }));
82
- });
83
- }
84
- else {
85
- this.broadcast(new camera_switch_message_1.CameraSwitchMessage(this.id, {
86
- deviceId: device.deviceId,
87
- }));
88
- }
89
- return this;
75
+ const payload = { deviceId: device.deviceId };
76
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new camera_switch_message_1.CameraSwitchMessage(target, { ...payload, actionScope }));
90
77
  }
91
78
  serializeRuleOverrides(overrides) {
92
79
  const out = super.serializeRuleOverrides(overrides);
@@ -8,7 +8,7 @@ import type { Overlay as ClientOverlayShape } from "@matreshka/shared/types/cont
8
8
  import type { FontStackToken } from "@matreshka/shared/types/fonts";
9
9
  import type { GridItem } from "@matreshka/shared/types/grid-item";
10
10
  import type { ServerComponentConfig } from "@matreshka/shared/types/server-component-config";
11
- import { Subscription } from "rxjs";
11
+ import { Observable, Subscription } from "rxjs";
12
12
  import { Client, Componentable, ComponentInstance, LocalAction } from "../core";
13
13
  import { Condition } from "../core/conditions";
14
14
  import { ServerAction, ServerActionHandler } from "./actions/server-action";
@@ -119,13 +119,13 @@ export declare abstract class Component<InitConfigType extends ComponentInitConf
119
119
  private destroyHandlers;
120
120
  private _destroyInstance$;
121
121
  /** Сигнал о том, что инстанс компонента прекращено */
122
- readonly destroyInstance$: import("rxjs").Observable<ComponentInstance<Componentable>>;
122
+ readonly destroyInstance$: Observable<ComponentInstance<Componentable>>;
123
123
  private _startUsing$;
124
124
  /** Сигнал о том, что инстанс компонента началось (появилось первое инстанс) */
125
- readonly startUsing$: import("rxjs").Observable<void>;
125
+ readonly startUsing$: Observable<void>;
126
126
  private _stopUsing$;
127
127
  /** Сигнал о том, что инстанс компонента прекращено (завершилось последнее инстанс) */
128
- readonly stopUsing$: import("rxjs").Observable<void>;
128
+ readonly stopUsing$: Observable<void>;
129
129
  constructor(config: InitConfigType);
130
130
  /** Инициализация свойств, происходит при первом обращении к свойствам */
131
131
  protected initProperties(initValues: InitConfigType): PropertiesType;
@@ -136,6 +136,11 @@ export declare abstract class Component<InitConfigType extends ComponentInitConf
136
136
  protected bindActions(event: string, actions: ServerComponentAction<Componentable> | ServerComponentAction<Componentable>[]): void;
137
137
  /** Массовая установка внутренних server-only cleanup-обработчиков release stage. */
138
138
  protected bindDestroyActions(actions: ServerDestroyAction<Componentable> | ServerDestroyAction<Componentable>[]): void;
139
+ /**
140
+ * Hot Observable: команда pingable component command с ack клиента.
141
+ * По одному сообщению на каждый instance с подключённым клиентом.
142
+ */
143
+ protected dispatchComponentCommand(instances: ComponentInstance[] | undefined, createMessage: (instanceTarget: string, actionScope: string) => ComponentCommandMessage): Observable<void>;
139
144
  /** Рассылка сообщения всем подписанным клиентам данного компонента */
140
145
  protected broadcast(message: ComponentCommandMessage): void;
141
146
  /** Обработка взаимодействия */
@@ -43,6 +43,7 @@ const incoming_message_observer_1 = require("../core/utils/incoming-message-obse
43
43
  const serialize_component_tree_1 = require("../core/utils/serialize-component-tree");
44
44
  const track_created_instances_1 = require("../core/utils/track-created-instances");
45
45
  const server_action_1 = require("./actions/server-action");
46
+ const targeted_client_component_action_1 = require("./utils/targeted-client-component-action");
46
47
  /**
47
48
  * @typeParam InitConfigType - Тип конфигурации, используемой в конструкторе компонента
48
49
  * @typeParam PropertiesType - Тип свойств компонента
@@ -125,6 +126,21 @@ class Component {
125
126
  this.destroyHandlers.push(this.parseDestroyAction(action));
126
127
  });
127
128
  }
129
+ /**
130
+ * Hot Observable: команда pingable component command с ack клиента.
131
+ * По одному сообщению на каждый instance с подключённым клиентом.
132
+ */
133
+ dispatchComponentCommand(instances, createMessage) {
134
+ const targets = (instances ?? this.instances).filter((instance) => instance.client);
135
+ if (targets.length === 0) {
136
+ return (0, rxjs_1.of)(undefined);
137
+ }
138
+ const actions = targets.map((instance) => (0, targeted_client_component_action_1.targetedClientComponentAction)(instance.client, (actionScope) => createMessage(instance.id, actionScope)));
139
+ if (actions.length === 1) {
140
+ return actions[0];
141
+ }
142
+ return (0, rxjs_1.forkJoin)(actions).pipe((0, rxjs_1.map)(() => undefined));
143
+ }
128
144
  /** Рассылка сообщения всем подписанным клиентам данного компонента */
129
145
  broadcast(message) {
130
146
  new Set(this.instances
@@ -72,7 +72,7 @@ export declare class Dialog<InitConfigType extends DialogInitConfig<any> = Defau
72
72
  /**
73
73
  * Закрывает диалог, инициируя событие взаимодействия "close".
74
74
  */
75
- close(instances?: ComponentInstance[]): void;
75
+ close(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
76
76
  protected serializeRuleOverrides(overrides: Partial<PropertiesType>): Record<string, unknown>;
77
77
  protected serializeEntry(instance: ComponentInstance<this>): DialogConfig;
78
78
  serialize(instance?: ComponentInstance<this>): DialogConfig;
@@ -78,16 +78,7 @@ class Dialog extends entry_component_1.EntryComponent {
78
78
  * Закрывает диалог, инициируя событие взаимодействия "close".
79
79
  */
80
80
  close(instances) {
81
- if (instances) {
82
- instances
83
- .filter((instance) => instance.client)
84
- .forEach((instance) => {
85
- instance.client.outcomingMessage$.next(new dialog_close_message_1.DialogCloseMessage(instance.id));
86
- });
87
- }
88
- else {
89
- this.broadcast(new dialog_close_message_1.DialogCloseMessage(this.id));
90
- }
81
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new dialog_close_message_1.DialogCloseMessage(target, actionScope));
91
82
  }
92
83
  serializeRuleOverrides(overrides) {
93
84
  const out = super.serializeRuleOverrides(overrides);
@@ -32,60 +32,60 @@ export declare class TextEditor<RefType extends StringInputContextRef = StringIn
32
32
  *
33
33
  * @param value Строка HTML.
34
34
  */
35
- insertHTML(value: string, instances?: ComponentInstance[]): this;
35
+ insertHTML(value: string, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
36
36
  /**
37
37
  * Переключает курсивное начертание текста.
38
38
  */
39
- toggleItalic(instances?: ComponentInstance[]): this;
39
+ toggleItalic(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
40
40
  /**
41
41
  * Переключает полужирное начертание текста.
42
42
  */
43
- toggleBold(instances?: ComponentInstance[]): this;
43
+ toggleBold(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
44
44
  /**
45
45
  * Переключает подчеркивание текста.
46
46
  */
47
- toggleUnderline(instances?: ComponentInstance[]): this;
47
+ toggleUnderline(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
48
48
  /**
49
49
  * Выполняет операцию отмены последнего действия.
50
50
  */
51
- undo(instances?: ComponentInstance[]): this;
51
+ undo(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
52
52
  /**
53
53
  * Выполняет операцию повтора последнего отмененного действия.
54
54
  */
55
- redo(instances?: ComponentInstance[]): this;
55
+ redo(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
56
56
  /**
57
57
  * Применяет формат верхнего индекса к выделенному тексту.
58
58
  */
59
- superscript(instances?: ComponentInstance[]): this;
59
+ superscript(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
60
60
  /**
61
61
  * Вставляет нумерованный список.
62
62
  */
63
- insertOrderedList(instances?: ComponentInstance[]): this;
63
+ insertOrderedList(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
64
64
  /**
65
65
  * Вставляет маркированный список.
66
66
  */
67
- insertUnorderedList(instances?: ComponentInstance[]): this;
67
+ insertUnorderedList(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
68
68
  /**
69
69
  * Выравнивает текст по левому краю.
70
70
  */
71
- justifyLeft(instances?: ComponentInstance[]): this;
71
+ justifyLeft(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
72
72
  /**
73
73
  * Выравнивает текст по центру.
74
74
  */
75
- justifyCenter(instances?: ComponentInstance[]): this;
75
+ justifyCenter(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
76
76
  /**
77
77
  * Выравнивает текст по правому краю.
78
78
  */
79
- justifyRight(instances?: ComponentInstance[]): this;
79
+ justifyRight(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
80
80
  /**
81
81
  * Выравнивает текст по ширине.
82
82
  */
83
- justifyFull(instances?: ComponentInstance[]): this;
83
+ justifyFull(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
84
84
  /**
85
85
  * Форматирует блок с указанным тегом.
86
86
  *
87
87
  * @param tag Тег HTML для форматирования блока.
88
88
  */
89
- formatBlock(tag: string, instances?: ComponentInstance[]): this;
89
+ formatBlock(tag: string, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
90
90
  }
91
91
  export {};
@@ -55,209 +55,79 @@ class TextEditor extends input_component_1.InputComponent {
55
55
  */
56
56
  insertHTML(value, instances) {
57
57
  const payload = { value };
58
- if (instances) {
59
- instances
60
- .filter((instance) => instance.client)
61
- .forEach((instance) => {
62
- instance.client.outcomingMessage$.next(new text_editor_insert_html_message_1.TextEditorInsertHtmlMessage(instance.id, payload));
63
- });
64
- }
65
- else {
66
- this.broadcast(new text_editor_insert_html_message_1.TextEditorInsertHtmlMessage(this.id, payload));
67
- }
68
- return this;
58
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_insert_html_message_1.TextEditorInsertHtmlMessage(target, { ...payload, actionScope }));
69
59
  }
70
60
  /**
71
61
  * Переключает курсивное начертание текста.
72
62
  */
73
63
  toggleItalic(instances) {
74
- if (instances) {
75
- instances
76
- .filter((instance) => instance.client)
77
- .forEach((instance) => {
78
- instance.client.outcomingMessage$.next(new text_editor_toggle_italic_message_1.TextEditorToggleItalicMessage(instance.id));
79
- });
80
- }
81
- else {
82
- this.broadcast(new text_editor_toggle_italic_message_1.TextEditorToggleItalicMessage(this.id));
83
- }
84
- return this;
64
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_toggle_italic_message_1.TextEditorToggleItalicMessage(target, actionScope));
85
65
  }
86
66
  /**
87
67
  * Переключает полужирное начертание текста.
88
68
  */
89
69
  toggleBold(instances) {
90
- if (instances) {
91
- instances
92
- .filter((instance) => instance.client)
93
- .forEach((instance) => {
94
- instance.client.outcomingMessage$.next(new text_editor_toggle_bold_message_1.TextEditorToggleBoldMessage(instance.id));
95
- });
96
- }
97
- else {
98
- this.broadcast(new text_editor_toggle_bold_message_1.TextEditorToggleBoldMessage(this.id));
99
- }
100
- return this;
70
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_toggle_bold_message_1.TextEditorToggleBoldMessage(target, actionScope));
101
71
  }
102
72
  /**
103
73
  * Переключает подчеркивание текста.
104
74
  */
105
75
  toggleUnderline(instances) {
106
- if (instances) {
107
- instances
108
- .filter((instance) => instance.client)
109
- .forEach((instance) => {
110
- instance.client.outcomingMessage$.next(new text_editor_toggle_underline_message_1.TextEditorToggleUnderlineMessage(instance.id));
111
- });
112
- }
113
- else {
114
- this.broadcast(new text_editor_toggle_underline_message_1.TextEditorToggleUnderlineMessage(this.id));
115
- }
116
- return this;
76
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_toggle_underline_message_1.TextEditorToggleUnderlineMessage(target, actionScope));
117
77
  }
118
78
  /**
119
79
  * Выполняет операцию отмены последнего действия.
120
80
  */
121
81
  undo(instances) {
122
- if (instances) {
123
- instances
124
- .filter((instance) => instance.client)
125
- .forEach((instance) => {
126
- instance.client.outcomingMessage$.next(new text_editor_undo_message_1.TextEditorUndoMessage(instance.id));
127
- });
128
- }
129
- else {
130
- this.broadcast(new text_editor_undo_message_1.TextEditorUndoMessage(this.id));
131
- }
132
- return this;
82
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_undo_message_1.TextEditorUndoMessage(target, actionScope));
133
83
  }
134
84
  /**
135
85
  * Выполняет операцию повтора последнего отмененного действия.
136
86
  */
137
87
  redo(instances) {
138
- if (instances) {
139
- instances
140
- .filter((instance) => instance.client)
141
- .forEach((instance) => {
142
- instance.client.outcomingMessage$.next(new text_editor_redo_message_1.TextEditorRedoMessage(instance.id));
143
- });
144
- }
145
- else {
146
- this.broadcast(new text_editor_redo_message_1.TextEditorRedoMessage(this.id));
147
- }
148
- return this;
88
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_redo_message_1.TextEditorRedoMessage(target, actionScope));
149
89
  }
150
90
  /**
151
91
  * Применяет формат верхнего индекса к выделенному тексту.
152
92
  */
153
93
  superscript(instances) {
154
- if (instances) {
155
- instances
156
- .filter((instance) => instance.client)
157
- .forEach((instance) => {
158
- instance.client.outcomingMessage$.next(new text_editor_superscript_message_1.TextEditorSuperscriptMessage(instance.id));
159
- });
160
- }
161
- else {
162
- this.broadcast(new text_editor_superscript_message_1.TextEditorSuperscriptMessage(this.id));
163
- }
164
- return this;
94
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_superscript_message_1.TextEditorSuperscriptMessage(target, actionScope));
165
95
  }
166
96
  /**
167
97
  * Вставляет нумерованный список.
168
98
  */
169
99
  insertOrderedList(instances) {
170
- if (instances) {
171
- instances
172
- .filter((instance) => instance.client)
173
- .forEach((instance) => {
174
- instance.client.outcomingMessage$.next(new text_editor_insert_ordered_list_message_1.TextEditorInsertOrderedListMessage(instance.id));
175
- });
176
- }
177
- else {
178
- this.broadcast(new text_editor_insert_ordered_list_message_1.TextEditorInsertOrderedListMessage(this.id));
179
- }
180
- return this;
100
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_insert_ordered_list_message_1.TextEditorInsertOrderedListMessage(target, actionScope));
181
101
  }
182
102
  /**
183
103
  * Вставляет маркированный список.
184
104
  */
185
105
  insertUnorderedList(instances) {
186
- if (instances) {
187
- instances
188
- .filter((instance) => instance.client)
189
- .forEach((instance) => {
190
- instance.client.outcomingMessage$.next(new text_editor_insert_unordered_list_message_1.TextEditorInsertUnorderedListMessage(instance.id));
191
- });
192
- }
193
- else {
194
- this.broadcast(new text_editor_insert_unordered_list_message_1.TextEditorInsertUnorderedListMessage(this.id));
195
- }
196
- return this;
106
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_insert_unordered_list_message_1.TextEditorInsertUnorderedListMessage(target, actionScope));
197
107
  }
198
108
  /**
199
109
  * Выравнивает текст по левому краю.
200
110
  */
201
111
  justifyLeft(instances) {
202
- if (instances) {
203
- instances
204
- .filter((instance) => instance.client)
205
- .forEach((instance) => {
206
- instance.client.outcomingMessage$.next(new text_editor_justify_left_message_1.TextEditorJustifyLeftMessage(instance.id));
207
- });
208
- }
209
- else {
210
- this.broadcast(new text_editor_justify_left_message_1.TextEditorJustifyLeftMessage(this.id));
211
- }
212
- return this;
112
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_justify_left_message_1.TextEditorJustifyLeftMessage(target, actionScope));
213
113
  }
214
114
  /**
215
115
  * Выравнивает текст по центру.
216
116
  */
217
117
  justifyCenter(instances) {
218
- if (instances) {
219
- instances
220
- .filter((instance) => instance.client)
221
- .forEach((instance) => {
222
- instance.client.outcomingMessage$.next(new text_editor_justify_center_message_1.TextEditorJustifyCenterMessage(instance.id));
223
- });
224
- }
225
- else {
226
- this.broadcast(new text_editor_justify_center_message_1.TextEditorJustifyCenterMessage(this.id));
227
- }
228
- return this;
118
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_justify_center_message_1.TextEditorJustifyCenterMessage(target, actionScope));
229
119
  }
230
120
  /**
231
121
  * Выравнивает текст по правому краю.
232
122
  */
233
123
  justifyRight(instances) {
234
- if (instances) {
235
- instances
236
- .filter((instance) => instance.client)
237
- .forEach((instance) => {
238
- instance.client.outcomingMessage$.next(new text_editor_justify_right_message_1.TextEditorJustifyRightMessage(instance.id));
239
- });
240
- }
241
- else {
242
- this.broadcast(new text_editor_justify_right_message_1.TextEditorJustifyRightMessage(this.id));
243
- }
244
- return this;
124
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_justify_right_message_1.TextEditorJustifyRightMessage(target, actionScope));
245
125
  }
246
126
  /**
247
127
  * Выравнивает текст по ширине.
248
128
  */
249
129
  justifyFull(instances) {
250
- if (instances) {
251
- instances
252
- .filter((instance) => instance.client)
253
- .forEach((instance) => {
254
- instance.client.outcomingMessage$.next(new text_editor_justify_full_message_1.TextEditorJustifyFullMessage(instance.id));
255
- });
256
- }
257
- else {
258
- this.broadcast(new text_editor_justify_full_message_1.TextEditorJustifyFullMessage(this.id));
259
- }
260
- return this;
130
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_justify_full_message_1.TextEditorJustifyFullMessage(target, actionScope));
261
131
  }
262
132
  /**
263
133
  * Форматирует блок с указанным тегом.
@@ -266,17 +136,7 @@ class TextEditor extends input_component_1.InputComponent {
266
136
  */
267
137
  formatBlock(tag, instances) {
268
138
  const payload = { tag };
269
- if (instances) {
270
- instances
271
- .filter((instance) => instance.client)
272
- .forEach((instance) => {
273
- instance.client.outcomingMessage$.next(new text_editor_format_block_message_1.TextEditorFormatBlockMessage(instance.id, payload));
274
- });
275
- }
276
- else {
277
- this.broadcast(new text_editor_format_block_message_1.TextEditorFormatBlockMessage(this.id, payload));
278
- }
279
- return this;
139
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new text_editor_format_block_message_1.TextEditorFormatBlockMessage(target, { ...payload, actionScope }));
280
140
  }
281
141
  }
282
142
  exports.TextEditor = TextEditor;
@@ -61,10 +61,10 @@ export declare class Map<InitConfigType extends MapInitConfig<any> = DefaultInit
61
61
  latitude: number;
62
62
  longitude: number;
63
63
  altitude?: number;
64
- }, instances?: ComponentInstance[]): void;
65
- setZoom(zoom: number, instances?: ComponentInstance[]): void;
66
- zoomIn(instances?: ComponentInstance[]): void;
67
- zoomOut(instances?: ComponentInstance[]): void;
64
+ }, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
65
+ setZoom(zoom: number, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
66
+ zoomIn(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
67
+ zoomOut(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
68
68
  constructor(config: InitConfigType);
69
69
  get hostInstances(): readonly ComponentInstance[];
70
70
  syncNestedItems(slot: string, items: NestedItemBase[]): void;
@@ -14,52 +14,16 @@ const map = (config) => new Map(config);
14
14
  exports.map = map;
15
15
  class Map extends component_1.Component {
16
16
  setCenter(center, instances) {
17
- if (instances) {
18
- instances
19
- .filter((instance) => instance.client)
20
- .forEach((instance) => {
21
- instance.client.outcomingMessage$.next(new map_set_center_message_1.MapSetCenterMessage(instance.id, center));
22
- });
23
- }
24
- else {
25
- this.broadcast(new map_set_center_message_1.MapSetCenterMessage(this.id, center));
26
- }
17
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new map_set_center_message_1.MapSetCenterMessage(target, { ...center, actionScope }));
27
18
  }
28
19
  setZoom(zoom, instances) {
29
- if (instances) {
30
- instances
31
- .filter((instance) => instance.client)
32
- .forEach((instance) => {
33
- instance.client.outcomingMessage$.next(new map_set_zoom_message_1.MapSetZoomMessage(instance.id, zoom));
34
- });
35
- }
36
- else {
37
- this.broadcast(new map_set_zoom_message_1.MapSetZoomMessage(this.id, zoom));
38
- }
20
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new map_set_zoom_message_1.MapSetZoomMessage(target, { zoom, actionScope }));
39
21
  }
40
22
  zoomIn(instances) {
41
- if (instances) {
42
- instances
43
- .filter((instance) => instance.client)
44
- .forEach((instance) => {
45
- instance.client.outcomingMessage$.next(new map_zoom_in_message_1.MapZoomInMessage(instance.id));
46
- });
47
- }
48
- else {
49
- this.broadcast(new map_zoom_in_message_1.MapZoomInMessage(this.id));
50
- }
23
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new map_zoom_in_message_1.MapZoomInMessage(target, actionScope));
51
24
  }
52
25
  zoomOut(instances) {
53
- if (instances) {
54
- instances
55
- .filter((instance) => instance.client)
56
- .forEach((instance) => {
57
- instance.client.outcomingMessage$.next(new map_zoom_out_message_1.MapZoomOutMessage(instance.id));
58
- });
59
- }
60
- else {
61
- this.broadcast(new map_zoom_out_message_1.MapZoomOutMessage(this.id));
62
- }
26
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new map_zoom_out_message_1.MapZoomOutMessage(target, actionScope));
63
27
  }
64
28
  constructor(config) {
65
29
  const markersSlot = (0, item_list_1.createNestedItemsSlotState)(config.markers);
@@ -45,7 +45,7 @@ export declare class Popover<InitConfigType extends PopoverInitConfig<any> = Def
45
45
  /**
46
46
  * Закрывает всплывающее окно, инициируя действие "close".
47
47
  */
48
- close(instances?: ComponentInstance[]): void;
48
+ close(instances?: ComponentInstance[]): import("rxjs").Observable<void>;
49
49
  /**
50
50
  * Инициализирует свойства компонента.
51
51
  *
@@ -40,16 +40,7 @@ class Popover extends entry_component_1.EntryComponent {
40
40
  * Закрывает всплывающее окно, инициируя действие "close".
41
41
  */
42
42
  close(instances) {
43
- if (instances) {
44
- instances
45
- .filter((instance) => instance.client)
46
- .forEach((instance) => {
47
- instance.client.outcomingMessage$.next(new popover_close_message_1.PopoverCloseMessage(instance.id));
48
- });
49
- }
50
- else {
51
- this.broadcast(new popover_close_message_1.PopoverCloseMessage(this.id));
52
- }
43
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new popover_close_message_1.PopoverCloseMessage(target, actionScope));
53
44
  }
54
45
  /**
55
46
  * Инициализирует свойства компонента.
@@ -163,7 +163,7 @@ export declare class Stack<InitConfigType extends StackInitConfig<any> = Default
163
163
  * - {@link ScrollToPosition.End} — в конец;
164
164
  * - иное отрицательное `value` — отступ от конца (например `-16`).
165
165
  */
166
- scrollTo(value: number | ScrollToPosition, smooth?: boolean, instances?: ComponentInstance[]): this;
166
+ scrollTo(value: number | ScrollToPosition, smooth?: boolean, instances?: ComponentInstance[]): import("rxjs").Observable<void>;
167
167
  protected serializeRuleOverrides(overrides: Partial<PropertiesType>): Record<string, unknown>;
168
168
  serialize(instance?: ComponentInstance<this>): StackConfig;
169
169
  }
@@ -104,23 +104,8 @@ class Stack extends component_1.Component {
104
104
  * - иное отрицательное `value` — отступ от конца (например `-16`).
105
105
  */
106
106
  scrollTo(value, smooth = false, instances) {
107
- if (instances) {
108
- instances
109
- .filter((instance) => instance.client)
110
- .forEach((instance) => {
111
- instance.client.outcomingMessage$.next(new component_scroll_to_message_1.ComponentScrollToMessage(instance.id, {
112
- value,
113
- smooth,
114
- }));
115
- });
116
- }
117
- else {
118
- this.broadcast(new component_scroll_to_message_1.ComponentScrollToMessage(this.id, {
119
- value,
120
- smooth,
121
- }));
122
- }
123
- return this;
107
+ const payload = { value, smooth };
108
+ return this.dispatchComponentCommand(instances, (target, actionScope) => new component_scroll_to_message_1.ComponentScrollToMessage(target, { ...payload, actionScope }));
124
109
  }
125
110
  serializeRuleOverrides(overrides) {
126
111
  const out = super.serializeRuleOverrides(overrides);
@@ -0,0 +1,5 @@
1
+ import { ComponentCommandMessage } from "@matreshka/shared/messages/bff-to-client/component-command-message";
2
+ import { Observable } from "rxjs";
3
+ import { Client } from "../../core";
4
+ export declare const COMPONENT_ACTION_SCOPE_PREFIX = "component-action-";
5
+ export declare function targetedClientComponentAction(client: Client, outgoingMessage: (actionScope: string) => ComponentCommandMessage): Observable<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPONENT_ACTION_SCOPE_PREFIX = void 0;
4
+ exports.targetedClientComponentAction = targetedClientComponentAction;
5
+ const rxjs_1 = require("rxjs");
6
+ const targeted_client_action_1 = require("../../core/utils/targeted-client-action");
7
+ exports.COMPONENT_ACTION_SCOPE_PREFIX = "component-action-";
8
+ function targetedClientComponentAction(client, outgoingMessage) {
9
+ const result$ = new rxjs_1.ReplaySubject(1);
10
+ (0, targeted_client_action_1.startTargetedClientAction)(client, {
11
+ scopePrefix: exports.COMPONENT_ACTION_SCOPE_PREFIX,
12
+ start: (scope) => {
13
+ client.outcomingMessage$.next(outgoingMessage(scope));
14
+ },
15
+ }, {
16
+ next: () => {
17
+ result$.next(undefined);
18
+ result$.complete();
19
+ },
20
+ error: (error) => result$.error(error),
21
+ complete: () => result$.complete(),
22
+ closed: () => result$.closed,
23
+ });
24
+ return result$.asObservable();
25
+ }
@@ -0,0 +1,19 @@
1
+ import { AnyClientToBffMessage } from "@matreshka/shared/messages/client-to-bff/client-to-bff-message";
2
+ import { Client } from "../client";
3
+ export type TargetedClientActionTerminal<T> = {
4
+ next: (value: T) => void;
5
+ error: (error: Error) => void;
6
+ complete: () => void;
7
+ closed: () => boolean;
8
+ };
9
+ export type TargetedClientActionConfig<T> = {
10
+ scopePrefix: string;
11
+ start: (scope: string, client: Client) => void;
12
+ parseSuccess?: (unsafeMessage: AnyClientToBffMessage) => T | undefined;
13
+ parseFailure?: (unsafeMessage: AnyClientToBffMessage) => Error | undefined;
14
+ };
15
+ export declare function createTargetedActionScope(prefix: string): string;
16
+ export declare function startTargetedClientAction<T>(client: Client, config: TargetedClientActionConfig<T>, terminal: TargetedClientActionTerminal<T>): {
17
+ scope: string;
18
+ teardown: () => void;
19
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTargetedActionScope = createTargetedActionScope;
4
+ exports.startTargetedClientAction = startTargetedClientAction;
5
+ const action_completed_message_1 = require("@matreshka/shared/messages/client-to-bff/action-completed-message");
6
+ const error_message_1 = require("@matreshka/shared/messages/client-to-bff/error-message");
7
+ const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
8
+ const rxjs_1 = require("rxjs");
9
+ const v4_1 = require("zod/v4");
10
+ const incoming_message_observer_1 = require("./incoming-message-observer");
11
+ const errorMessagePayloadSchema = v4_1.z.strictObject({
12
+ message: v4_1.z.string(),
13
+ });
14
+ function createTargetedActionScope(prefix) {
15
+ return prefix + crypto.randomUUID();
16
+ }
17
+ function startTargetedClientAction(client, config, terminal) {
18
+ const scope = createTargetedActionScope(config.scopePrefix);
19
+ let finalized = false;
20
+ const teardown = () => {
21
+ if (finalized) {
22
+ return;
23
+ }
24
+ finalized = true;
25
+ subscription.unsubscribe();
26
+ destroySubscription.unsubscribe();
27
+ };
28
+ const finish = (notify) => {
29
+ notify();
30
+ teardown();
31
+ };
32
+ const subscription = client.incomingMessage$
33
+ .pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope), (0, rxjs_1.take)(1))
34
+ .subscribe((0, incoming_message_observer_1.incomingMessageObserver)(client, (unsafeMessage) => {
35
+ if (unsafeMessage instanceof error_message_1.ErrorMessage) {
36
+ const messagePayload = errorMessagePayloadSchema.parse(unsafeMessage.payload);
37
+ finish(() => terminal.error(new Error(messagePayload.message)));
38
+ return;
39
+ }
40
+ if (unsafeMessage instanceof action_completed_message_1.ActionCompletedMessage) {
41
+ finish(() => {
42
+ terminal.next(undefined);
43
+ terminal.complete();
44
+ });
45
+ return;
46
+ }
47
+ const failure = config.parseFailure?.(unsafeMessage);
48
+ if (failure) {
49
+ finish(() => terminal.error(failure));
50
+ return;
51
+ }
52
+ const value = config.parseSuccess?.(unsafeMessage);
53
+ if (value !== undefined) {
54
+ finish(() => {
55
+ terminal.next(value);
56
+ terminal.complete();
57
+ });
58
+ }
59
+ }));
60
+ const destroySubscription = client.destroy$.subscribe(() => {
61
+ if (!terminal.closed()) {
62
+ terminal.complete();
63
+ }
64
+ teardown();
65
+ });
66
+ config.start(scope, client);
67
+ return { scope, teardown };
68
+ }
@@ -1,72 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.targetedClientPlatformAction = targetedClientPlatformAction;
4
- const error_message_1 = require("@matreshka/shared/messages/client-to-bff/error-message");
5
- const platform_action_completed_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/platform-action-completed-message");
6
- const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
7
4
  const rxjs_1 = require("rxjs");
8
- const v4_1 = require("zod/v4");
9
- const incoming_message_observer_1 = require("../../core/utils/incoming-message-observer");
10
- const errorMessagePayloadSchema = v4_1.z.strictObject({
11
- message: v4_1.z.string(),
12
- });
13
- function startTargetedClientPlatformAction(client, config, terminal) {
14
- const scope = "platform-action-" + crypto.randomUUID();
15
- let finalized = false;
16
- const teardown = () => {
17
- if (finalized) {
18
- return;
19
- }
20
- finalized = true;
21
- subscription.unsubscribe();
22
- destroySubscription.unsubscribe();
23
- };
24
- const finish = (notify) => {
25
- notify();
26
- teardown();
27
- };
28
- const subscription = client.incomingMessage$
29
- .pipe((0, rxjs_1.filter)((unsafeMessage) => (0, targeted_message_1.isTargetedMessage)(unsafeMessage) && unsafeMessage.target === scope), (0, rxjs_1.take)(1))
30
- .subscribe((0, incoming_message_observer_1.incomingMessageObserver)(client, (unsafeMessage) => {
31
- if (unsafeMessage instanceof error_message_1.ErrorMessage) {
32
- const messagePayload = errorMessagePayloadSchema.parse(unsafeMessage.payload);
33
- finish(() => terminal.error(new Error(messagePayload.message)));
34
- return;
35
- }
36
- if (unsafeMessage instanceof platform_action_completed_message_1.PlatformActionCompletedMessage) {
37
- finish(() => {
38
- terminal.next(undefined);
39
- terminal.complete();
40
- });
41
- return;
42
- }
43
- const failure = config.parseFailure?.(unsafeMessage);
44
- if (failure) {
45
- finish(() => terminal.error(failure));
46
- return;
47
- }
48
- const value = config.parseSuccess?.(unsafeMessage);
49
- if (value !== undefined) {
50
- finish(() => {
51
- terminal.next(value);
52
- terminal.complete();
53
- });
54
- }
55
- }));
56
- const destroySubscription = client.destroy$.subscribe(() => {
57
- if (!terminal.closed()) {
58
- terminal.complete();
59
- }
60
- teardown();
61
- });
62
- const start = () => {
63
- client.outcomingMessage$.next(config.outgoingMessage(scope));
64
- };
65
- return { start, teardown };
66
- }
5
+ const targeted_client_action_1 = require("../../core/utils/targeted-client-action");
67
6
  function targetedClientPlatformAction(client, config) {
68
7
  const result$ = new rxjs_1.ReplaySubject(1);
69
- const { start } = startTargetedClientPlatformAction(client, config, {
8
+ (0, targeted_client_action_1.startTargetedClientAction)(client, {
9
+ scopePrefix: "platform-action-",
10
+ start: (scope) => {
11
+ client.outcomingMessage$.next(config.outgoingMessage(scope));
12
+ },
13
+ parseSuccess: config.parseSuccess,
14
+ parseFailure: config.parseFailure,
15
+ }, {
70
16
  next: (value) => {
71
17
  result$.next(value);
72
18
  result$.complete();
@@ -75,6 +21,5 @@ function targetedClientPlatformAction(client, config) {
75
21
  complete: () => result$.complete(),
76
22
  closed: () => result$.closed,
77
23
  });
78
- start();
79
24
  return result$.asObservable();
80
25
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.targetedClientPlatformStream = targetedClientPlatformStream;
4
+ const action_completed_message_1 = require("@matreshka/shared/messages/client-to-bff/action-completed-message");
4
5
  const error_message_1 = require("@matreshka/shared/messages/client-to-bff/error-message");
5
- const platform_action_completed_message_1 = require("@matreshka/shared/messages/client-to-bff/platforms/platform-action-completed-message");
6
6
  const targeted_message_1 = require("@matreshka/shared/messages/targeted-message");
7
7
  const rxjs_1 = require("rxjs");
8
8
  const v4_1 = require("zod/v4");
@@ -59,7 +59,7 @@ function targetedClientPlatformStream(client, config) {
59
59
  finishWithError(failure);
60
60
  return;
61
61
  }
62
- if (unsafeMessage instanceof platform_action_completed_message_1.PlatformActionCompletedMessage) {
62
+ if (unsafeMessage instanceof action_completed_message_1.ActionCompletedMessage) {
63
63
  finishComplete();
64
64
  return;
65
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matreshka/bff",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Matreshka BFF: server-driven UI runtime — routing, pages, context, component DSL, and platform APIs",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -62,7 +62,7 @@
62
62
  "vitest": "^4.1.0"
63
63
  },
64
64
  "dependencies": {
65
- "@matreshka/shared": "^0.19.0",
65
+ "@matreshka/shared": "^0.20.0",
66
66
  "@simplewebauthn/server": "^13.1.1",
67
67
  "@simplewebauthn/types": "^12.0.0",
68
68
  "fast-xml-parser": "^5.3.3",