@matreshka/bff 0.37.0 → 0.39.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/dist/components/inputs/input-component.d.ts +1 -1
- package/dist/core/actions/context-local-action-config.d.ts +13 -0
- package/dist/core/actions/context-local-action-config.js +7 -0
- package/dist/core/actions/dec-context-value.d.ts +7 -5
- package/dist/core/actions/dec-context-value.js +6 -2
- package/dist/core/actions/inc-context-value.d.ts +7 -5
- package/dist/core/actions/inc-context-value.js +6 -2
- package/dist/core/actions/set-context.d.ts +12 -4
- package/dist/core/actions/set-context.js +6 -1
- package/dist/core/actions/toggle-context-value.d.ts +7 -4
- package/dist/core/actions/toggle-context-value.js +6 -1
- package/dist/core/context/context-ref.d.ts +45 -11
- package/dist/core/context/context.d.ts +46 -10
- package/dist/core/types/context-value-ref.d.ts +23 -24
- package/dist/platforms/client-platform.d.ts +12 -0
- package/dist/platforms/client-platform.js +18 -0
- package/dist/platforms/index.d.ts +1 -0
- package/dist/platforms/index.js +1 -0
- package/dist/platforms/media.d.ts +89 -0
- package/dist/platforms/media.js +315 -0
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnySchemaContextRef, Componentable, StandaloneComponent, WritableContextRefOfValue } from "../../core";
|
|
2
2
|
import { Component, ComponentInitConfig, ComponentProperties } from "../component";
|
|
3
|
-
/** Ref на поле ввода: значение `ValueType | undefined
|
|
3
|
+
/** Ref на поле ввода: значение `ValueType | undefined`, путь должен быть writable. */
|
|
4
4
|
export type InputContextRef<ValueType> = WritableContextRefOfValue<ValueType | undefined>;
|
|
5
5
|
/** Ref на строковое поле ввода. */
|
|
6
6
|
export type StringInputContextRef = InputContextRef<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ActionConfig } from "./action";
|
|
2
|
+
/**
|
|
3
|
+
* Config локальной записи Context.
|
|
4
|
+
* `sync: false` пишет только клиентское зеркало и не шлёт `context-values`.
|
|
5
|
+
* Поле не входит в общий {@link ActionConfig}, чтобы не появиться у прочих действий.
|
|
6
|
+
*/
|
|
7
|
+
export type ContextLocalActionConfig = ActionConfig & {
|
|
8
|
+
sync?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** В payload попадает только явное отключение синхронизации. */
|
|
11
|
+
export declare function contextLocalSyncField(sync: boolean | undefined): {
|
|
12
|
+
sync: false;
|
|
13
|
+
} | Record<string, never>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contextLocalSyncField = contextLocalSyncField;
|
|
4
|
+
/** В payload попадает только явное отключение синхронизации. */
|
|
5
|
+
function contextLocalSyncField(sync) {
|
|
6
|
+
return sync === false ? { sync: false } : {};
|
|
7
|
+
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { ValueOrContextRef, WritableContextRefOfValue } from "../types/context-value-ref";
|
|
2
|
-
import {
|
|
2
|
+
import { ContextLocalActionConfig } from "./context-local-action-config";
|
|
3
3
|
import { NumberValueRef } from "./inc-context-value";
|
|
4
4
|
import { LocalAction } from "./local-action";
|
|
5
5
|
/**
|
|
6
|
-
* Уменьшение числового значения в Context на клиенте на `step
|
|
7
|
-
*
|
|
6
|
+
* Уменьшение числового значения в Context на клиенте на `step`.
|
|
7
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
8
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
8
9
|
*/
|
|
9
10
|
export declare class DecContextValue extends LocalAction {
|
|
10
11
|
private readonly ref;
|
|
11
12
|
private readonly step;
|
|
12
|
-
|
|
13
|
+
private readonly sync;
|
|
14
|
+
constructor(ref: NumberValueRef, step: ValueOrContextRef<number>, config?: ContextLocalActionConfig);
|
|
13
15
|
class(): string;
|
|
14
16
|
payload(): object;
|
|
15
17
|
}
|
|
@@ -18,4 +20,4 @@ export declare class DecContextValue extends LocalAction {
|
|
|
18
20
|
* Принимает только `ContextRef` с числовым значением.
|
|
19
21
|
* Без `step` клиент вычитает 1.
|
|
20
22
|
*/
|
|
21
|
-
export declare function decContextValue(ref: WritableContextRefOfValue<number | undefined>, step?: ValueOrContextRef<number>, config?:
|
|
23
|
+
export declare function decContextValue(ref: WritableContextRefOfValue<number | undefined>, step?: ValueOrContextRef<number>, config?: ContextLocalActionConfig): DecContextValue;
|
|
@@ -3,16 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DecContextValue = void 0;
|
|
4
4
|
exports.decContextValue = decContextValue;
|
|
5
5
|
const condition_operand_1 = require("../conditions/condition-operand");
|
|
6
|
+
const context_local_action_config_1 = require("./context-local-action-config");
|
|
6
7
|
const local_action_1 = require("./local-action");
|
|
7
8
|
/**
|
|
8
|
-
* Уменьшение числового значения в Context на клиенте на `step
|
|
9
|
-
*
|
|
9
|
+
* Уменьшение числового значения в Context на клиенте на `step`.
|
|
10
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
11
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
10
12
|
*/
|
|
11
13
|
class DecContextValue extends local_action_1.LocalAction {
|
|
12
14
|
constructor(ref, step, config = {}) {
|
|
13
15
|
super(config.conditions);
|
|
14
16
|
this.ref = ref;
|
|
15
17
|
this.step = step;
|
|
18
|
+
this.sync = config.sync;
|
|
16
19
|
}
|
|
17
20
|
class() {
|
|
18
21
|
return "dec-context-value";
|
|
@@ -21,6 +24,7 @@ class DecContextValue extends local_action_1.LocalAction {
|
|
|
21
24
|
return {
|
|
22
25
|
ref: this.ref,
|
|
23
26
|
step: (0, condition_operand_1.toSerializedOperand)(this.step),
|
|
27
|
+
...(0, context_local_action_config_1.contextLocalSyncField)(this.sync),
|
|
24
28
|
};
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { ContextRefOfValue, ValueOrContextRef, WritableContextRefOfValue } from "../types/context-value-ref";
|
|
2
|
-
import {
|
|
2
|
+
import { ContextLocalActionConfig } from "./context-local-action-config";
|
|
3
3
|
import { LocalAction } from "./local-action";
|
|
4
4
|
/** Ref на числовое поле контекста. */
|
|
5
5
|
export type NumberValueRef = ContextRefOfValue<number | undefined>;
|
|
6
6
|
/**
|
|
7
|
-
* Изменение числового значения в Context на клиенте на `step
|
|
8
|
-
*
|
|
7
|
+
* Изменение числового значения в Context на клиенте на `step`.
|
|
8
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
9
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
9
10
|
*/
|
|
10
11
|
export declare class IncContextValue extends LocalAction {
|
|
11
12
|
private readonly ref;
|
|
12
13
|
private readonly step;
|
|
13
|
-
|
|
14
|
+
private readonly sync;
|
|
15
|
+
constructor(ref: NumberValueRef, step: ValueOrContextRef<number>, config?: ContextLocalActionConfig);
|
|
14
16
|
class(): string;
|
|
15
17
|
payload(): object;
|
|
16
18
|
}
|
|
@@ -19,4 +21,4 @@ export declare class IncContextValue extends LocalAction {
|
|
|
19
21
|
* Принимает только `ContextRef` с числовым значением.
|
|
20
22
|
* Без `step` клиент прибавляет 1.
|
|
21
23
|
*/
|
|
22
|
-
export declare function incContextValue(ref: WritableContextRefOfValue<number | undefined>, step?: ValueOrContextRef<number>, config?:
|
|
24
|
+
export declare function incContextValue(ref: WritableContextRefOfValue<number | undefined>, step?: ValueOrContextRef<number>, config?: ContextLocalActionConfig): IncContextValue;
|
|
@@ -3,16 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IncContextValue = void 0;
|
|
4
4
|
exports.incContextValue = incContextValue;
|
|
5
5
|
const condition_operand_1 = require("../conditions/condition-operand");
|
|
6
|
+
const context_local_action_config_1 = require("./context-local-action-config");
|
|
6
7
|
const local_action_1 = require("./local-action");
|
|
7
8
|
/**
|
|
8
|
-
* Изменение числового значения в Context на клиенте на `step
|
|
9
|
-
*
|
|
9
|
+
* Изменение числового значения в Context на клиенте на `step`.
|
|
10
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
11
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
10
12
|
*/
|
|
11
13
|
class IncContextValue extends local_action_1.LocalAction {
|
|
12
14
|
constructor(ref, step, config = {}) {
|
|
13
15
|
super(config.conditions);
|
|
14
16
|
this.ref = ref;
|
|
15
17
|
this.step = step;
|
|
18
|
+
this.sync = config.sync;
|
|
16
19
|
}
|
|
17
20
|
class() {
|
|
18
21
|
return "inc-context-value";
|
|
@@ -21,6 +24,7 @@ class IncContextValue extends local_action_1.LocalAction {
|
|
|
21
24
|
return {
|
|
22
25
|
ref: this.ref,
|
|
23
26
|
step: (0, condition_operand_1.toSerializedOperand)(this.step),
|
|
27
|
+
...(0, context_local_action_config_1.contextLocalSyncField)(this.sync),
|
|
24
28
|
};
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import { JsonObject } from "@matreshka/client-bff-protocol/types/json";
|
|
2
|
+
import { Paths, PathValue } from "ts-essentials";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { Context, WritableContextPath, WritablePathValue } from "../context/context";
|
|
4
5
|
import { ValueOrContextRef } from "../types/context-value-ref";
|
|
5
|
-
import {
|
|
6
|
+
import { ContextLocalActionConfig } from "./context-local-action-config";
|
|
6
7
|
import { LocalAction } from "./local-action";
|
|
7
8
|
export type LocalContextPathPatch<T extends JsonObject, S extends z.ZodObject | undefined> = Partial<{
|
|
8
9
|
[K in WritableContextPath<T, S>]: ValueOrContextRef<WritablePathValue<S, K>>;
|
|
9
10
|
}>;
|
|
11
|
+
/** Patch по любому пути данных. Для `sync: false`, без проверки схемы. */
|
|
12
|
+
export type LocalDataPathPatch<T extends JsonObject> = Partial<{
|
|
13
|
+
[K in Paths<T>]: ValueOrContextRef<PathValue<T, K>>;
|
|
14
|
+
}>;
|
|
10
15
|
/**
|
|
11
|
-
* Локальная запись patch в Context на
|
|
16
|
+
* Локальная запись patch в Context на клиенте.
|
|
17
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
18
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
12
19
|
*/
|
|
13
20
|
export declare class SetContext<T extends JsonObject, S extends z.ZodObject | undefined> extends LocalAction {
|
|
14
21
|
private readonly context;
|
|
15
22
|
private readonly patch;
|
|
16
|
-
|
|
23
|
+
private readonly sync;
|
|
24
|
+
constructor(context: Context<T, S>, patch: LocalDataPathPatch<T>, config?: ContextLocalActionConfig);
|
|
17
25
|
class(): string;
|
|
18
26
|
payload(): object;
|
|
19
27
|
}
|
|
20
28
|
/** @internal */
|
|
21
|
-
export declare function createSetContext<T extends JsonObject, S extends z.ZodObject | undefined>(context: Context<T, S>, patch:
|
|
29
|
+
export declare function createSetContext<T extends JsonObject, S extends z.ZodObject | undefined>(context: Context<T, S>, patch: LocalDataPathPatch<T>, config?: ContextLocalActionConfig): SetContext<T, S>;
|
|
@@ -3,15 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SetContext = void 0;
|
|
4
4
|
exports.createSetContext = createSetContext;
|
|
5
5
|
const condition_operand_1 = require("../conditions/condition-operand");
|
|
6
|
+
const context_local_action_config_1 = require("./context-local-action-config");
|
|
6
7
|
const local_action_1 = require("./local-action");
|
|
7
8
|
/**
|
|
8
|
-
* Локальная запись patch в Context на
|
|
9
|
+
* Локальная запись patch в Context на клиенте.
|
|
10
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
11
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
9
12
|
*/
|
|
10
13
|
class SetContext extends local_action_1.LocalAction {
|
|
11
14
|
constructor(context, patch, config = {}) {
|
|
12
15
|
super(config.conditions);
|
|
13
16
|
this.context = context;
|
|
14
17
|
this.patch = patch;
|
|
18
|
+
this.sync = config.sync;
|
|
15
19
|
}
|
|
16
20
|
class() {
|
|
17
21
|
return "set-context";
|
|
@@ -23,6 +27,7 @@ class SetContext extends local_action_1.LocalAction {
|
|
|
23
27
|
key,
|
|
24
28
|
(0, condition_operand_1.toSerializedOperand)(value),
|
|
25
29
|
])),
|
|
30
|
+
...(0, context_local_action_config_1.contextLocalSyncField)(this.sync),
|
|
26
31
|
};
|
|
27
32
|
}
|
|
28
33
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { ContextRefOfValue, WritableContextRefOfValue } from "../types/context-value-ref";
|
|
2
|
-
import {
|
|
2
|
+
import { ContextLocalActionConfig } from "./context-local-action-config";
|
|
3
3
|
import { LocalAction } from "./local-action";
|
|
4
4
|
/** Ref на boolean-поле контекста. */
|
|
5
5
|
export type BooleanValueRef = ContextRefOfValue<boolean | undefined>;
|
|
6
6
|
/**
|
|
7
|
-
* Инверсия boolean-значения в Context на
|
|
7
|
+
* Инверсия boolean-значения в Context на клиенте.
|
|
8
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
9
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
8
10
|
*/
|
|
9
11
|
export declare class ToggleContextValue extends LocalAction {
|
|
10
12
|
private readonly ref;
|
|
11
|
-
|
|
13
|
+
private readonly sync;
|
|
14
|
+
constructor(ref: BooleanValueRef, config?: ContextLocalActionConfig);
|
|
12
15
|
class(): string;
|
|
13
16
|
payload(): object;
|
|
14
17
|
}
|
|
@@ -16,4 +19,4 @@ export declare class ToggleContextValue extends LocalAction {
|
|
|
16
19
|
* Функциональная форма {@link ToggleContextValue}.
|
|
17
20
|
* Принимает только `ContextRef` с boolean-значением.
|
|
18
21
|
*/
|
|
19
|
-
export declare function toggleContextValue(ref: WritableContextRefOfValue<boolean | undefined>, config?:
|
|
22
|
+
export declare function toggleContextValue(ref: WritableContextRefOfValue<boolean | undefined>, config?: ContextLocalActionConfig): ToggleContextValue;
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ToggleContextValue = void 0;
|
|
4
4
|
exports.toggleContextValue = toggleContextValue;
|
|
5
|
+
const context_local_action_config_1 = require("./context-local-action-config");
|
|
5
6
|
const local_action_1 = require("./local-action");
|
|
6
7
|
/**
|
|
7
|
-
* Инверсия boolean-значения в Context на
|
|
8
|
+
* Инверсия boolean-значения в Context на клиенте.
|
|
9
|
+
* По умолчанию синхронизируется на BFF через `context-values`.
|
|
10
|
+
* `config.sync: false` оставляет значение только в клиентском зеркале.
|
|
8
11
|
*/
|
|
9
12
|
class ToggleContextValue extends local_action_1.LocalAction {
|
|
10
13
|
constructor(ref, config = {}) {
|
|
11
14
|
super(config.conditions);
|
|
12
15
|
this.ref = ref;
|
|
16
|
+
this.sync = config.sync;
|
|
13
17
|
}
|
|
14
18
|
class() {
|
|
15
19
|
return "toggle-context-value";
|
|
@@ -17,6 +21,7 @@ class ToggleContextValue extends local_action_1.LocalAction {
|
|
|
17
21
|
payload() {
|
|
18
22
|
return {
|
|
19
23
|
ref: this.ref,
|
|
24
|
+
...(0, context_local_action_config_1.contextLocalSyncField)(this.sync),
|
|
20
25
|
};
|
|
21
26
|
}
|
|
22
27
|
}
|
|
@@ -2,7 +2,7 @@ import { JsonObject } from "@matreshka/client-bff-protocol/types/json";
|
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
3
|
import { Paths, PathValue } from "ts-essentials";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
5
|
+
import { ContextLocalActionConfig } from "../actions/context-local-action-config";
|
|
6
6
|
import { DecContextValue } from "../actions/dec-context-value";
|
|
7
7
|
import { IncContextValue } from "../actions/inc-context-value";
|
|
8
8
|
import { SetContext } from "../actions/set-context";
|
|
@@ -10,19 +10,53 @@ import { ToggleContextValue } from "../actions/toggle-context-value";
|
|
|
10
10
|
import type { ContextUpdateDelivery } from "../types/context-update-delivery";
|
|
11
11
|
import { ValueOrContextRef } from "../types/context-value-ref";
|
|
12
12
|
import { Context, WritableContextPath, WritablePathValue } from "./context";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
/** `0 extends 1 & any` даёт false; этот вариант корректно ловит `any`. */
|
|
14
|
+
type IsAny<T> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends any ? 1 : 2 ? true : false;
|
|
15
|
+
type SyncOnConfig = ContextLocalActionConfig & {
|
|
16
|
+
sync?: true;
|
|
17
|
+
};
|
|
18
|
+
type SyncOffConfig = ContextLocalActionConfig & {
|
|
19
|
+
sync: false;
|
|
18
20
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Writable для local.set без `sync: false`.
|
|
23
|
+
* `SchemaType = any` (дефолт Context) — считаем writable: иначе ломаются inputs.
|
|
24
|
+
* `PathType = any` — не writable, чтобы не открывать обе ветки conditional.
|
|
25
|
+
*/
|
|
26
|
+
type IsWritableLocalPath<ContextType extends JsonObject, PathType extends string, SchemaType extends z.ZodObject | undefined> = IsAny<PathType> extends true ? false : IsAny<SchemaType> extends true ? true : PathType extends WritableContextPath<ContextType, SchemaType> ? true : false;
|
|
27
|
+
type ValueMatches<Value, Expected> = IsAny<Value> extends true ? false : [Value] extends [never] ? false : [Value] extends [Expected] ? true : false;
|
|
28
|
+
type ContextRefLocalSet<ContextType extends JsonObject, PathType extends string, SchemaType extends z.ZodObject | undefined> = IsWritableLocalPath<ContextType, PathType, SchemaType> extends true ? {
|
|
29
|
+
set: (value: ValueOrContextRef<PathValue<ContextType, PathType>>, config?: ContextLocalActionConfig) => SetContext<any, any>;
|
|
30
|
+
} : {
|
|
31
|
+
set: (value: ValueOrContextRef<PathValue<ContextType, PathType>>, config: SyncOffConfig) => SetContext<any, any>;
|
|
32
|
+
};
|
|
33
|
+
type ContextRefLocalToggle<ContextType extends JsonObject, PathType extends string, SchemaType extends z.ZodObject | undefined> = ValueMatches<PathValue<ContextType, PathType>, boolean | undefined> extends true ? IsWritableLocalPath<ContextType, PathType, SchemaType> extends true ? ValueMatches<WritablePathValue<SchemaType, PathType>, boolean | undefined> extends true ? {
|
|
34
|
+
toggle: {
|
|
35
|
+
(config?: SyncOnConfig): ToggleContextValue;
|
|
36
|
+
(config: SyncOffConfig): ToggleContextValue;
|
|
37
|
+
};
|
|
38
|
+
} : {
|
|
39
|
+
toggle: (config: SyncOffConfig) => ToggleContextValue;
|
|
40
|
+
} : {
|
|
41
|
+
toggle: (config: SyncOffConfig) => ToggleContextValue;
|
|
42
|
+
} : {};
|
|
43
|
+
type ContextRefLocalNumeric<ContextType extends JsonObject, PathType extends string, SchemaType extends z.ZodObject | undefined> = ValueMatches<PathValue<ContextType, PathType>, number | undefined> extends true ? IsWritableLocalPath<ContextType, PathType, SchemaType> extends true ? ValueMatches<WritablePathValue<SchemaType, PathType>, number | undefined> extends true ? {
|
|
44
|
+
inc: {
|
|
45
|
+
(step?: ValueOrContextRef<number>, config?: SyncOnConfig): IncContextValue;
|
|
46
|
+
(step: ValueOrContextRef<number> | undefined, config: SyncOffConfig): IncContextValue;
|
|
47
|
+
};
|
|
48
|
+
dec: {
|
|
49
|
+
(step?: ValueOrContextRef<number>, config?: SyncOnConfig): DecContextValue;
|
|
50
|
+
(step: ValueOrContextRef<number> | undefined, config: SyncOffConfig): DecContextValue;
|
|
51
|
+
};
|
|
52
|
+
} : ContextRefLocalNumericSyncOff : ContextRefLocalNumericSyncOff : {};
|
|
53
|
+
type ContextRefLocalNumericSyncOff = {
|
|
54
|
+
inc: (step: ValueOrContextRef<number> | undefined, config: SyncOffConfig) => IncContextValue;
|
|
55
|
+
dec: (step: ValueOrContextRef<number> | undefined, config: SyncOffConfig) => DecContextValue;
|
|
22
56
|
};
|
|
23
57
|
/** Локальные действия по ref; `toggle` / `inc` / `dec` — по типу значения по пути. */
|
|
24
|
-
export type ContextRefLocalActions<ContextType extends JsonObject, PathType extends string, SchemaType extends z.ZodObject | undefined> = ContextRefLocalSet<ContextType, PathType, SchemaType> &
|
|
25
|
-
export type AnySchemaContextRef<ContextType extends JsonObject = any, PathType extends string = any> = ContextRef<ContextType, PathType, undefined> | ContextRef<ContextType, PathType, z.ZodObject>;
|
|
58
|
+
export type ContextRefLocalActions<ContextType extends JsonObject, PathType extends string, SchemaType extends z.ZodObject | undefined> = ContextRefLocalSet<ContextType, PathType, SchemaType> & ContextRefLocalToggle<ContextType, PathType, SchemaType> & ContextRefLocalNumeric<ContextType, PathType, SchemaType>;
|
|
59
|
+
export type AnySchemaContextRef<ContextType extends JsonObject = any, PathType extends string = any> = ContextRef<ContextType, PathType, undefined> | ContextRef<ContextType, PathType, z.ZodObject> | ContextRef<ContextType, PathType, any>;
|
|
26
60
|
export type ContextRefValueType<R extends AnySchemaContextRef> = R extends {
|
|
27
61
|
readonly __valueType?: infer ValueType;
|
|
28
62
|
} ? Exclude<ValueType, undefined> : R extends ContextRef<infer ContextType, infer PathType, any> ? PathValue<ContextType, PathType> : never;
|
|
@@ -2,10 +2,10 @@ import { JsonObject } from "@matreshka/client-bff-protocol/types/json";
|
|
|
2
2
|
import { BehaviorSubject, Observable } from "rxjs";
|
|
3
3
|
import { Paths, PathValue } from "ts-essentials";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
5
|
+
import { ContextLocalActionConfig } from "../actions/context-local-action-config";
|
|
6
6
|
import { DecContextValue } from "../actions/dec-context-value";
|
|
7
7
|
import { IncContextValue } from "../actions/inc-context-value";
|
|
8
|
-
import { LocalContextPathPatch } from "../actions/set-context";
|
|
8
|
+
import { LocalContextPathPatch, LocalDataPathPatch, SetContext } from "../actions/set-context";
|
|
9
9
|
import { ToggleContextValue } from "../actions/toggle-context-value";
|
|
10
10
|
import type { Client } from "../client";
|
|
11
11
|
import { ContextUpdateDelivery } from "../types/context-update-delivery";
|
|
@@ -20,12 +20,53 @@ export type ContextPathPatch<T extends JsonObject> = Partial<{
|
|
|
20
20
|
/** Входная форма данных, которые клиент может отправить в `context-values`. */
|
|
21
21
|
export type WritableSchemaInput<S extends z.ZodObject | undefined> = S extends z.ZodObject ? z.input<S> extends JsonObject ? z.input<S> : never : never;
|
|
22
22
|
/** Dotted-пути, разрешённые для клиентской записи (по `schema`). */
|
|
23
|
-
|
|
23
|
+
/** `0 extends 1 & any` даёт false; этот вариант корректно ловит `any`. */
|
|
24
|
+
type IsAny<T> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends any ? 1 : 2 ? true : false;
|
|
24
25
|
export type WritablePath<S extends z.ZodObject | undefined> = IsAny<S> extends true ? string : S extends z.ZodObject ? Paths<WritableSchemaInput<S>> : never;
|
|
25
26
|
/** Тип значения по writable-пути `P` (из `schema` input). */
|
|
26
|
-
export type WritablePathValue<S extends z.ZodObject | undefined, P extends string> = IsAny<S> extends true ?
|
|
27
|
+
export type WritablePathValue<S extends z.ZodObject | undefined, P extends string> = IsAny<S> extends true ? any : S extends z.ZodObject ? P extends Paths<WritableSchemaInput<S>> ? PathValue<WritableSchemaInput<S>, P> : never : never;
|
|
27
28
|
/** Пересечение путей контекста и путей `schema`, доступных для client write. */
|
|
28
29
|
export type WritableContextPath<T extends JsonObject, S extends z.ZodObject | undefined> = Extract<Paths<T>, WritablePath<S>>;
|
|
30
|
+
type BooleanDataPath<T extends JsonObject> = {
|
|
31
|
+
[K in Paths<T>]: PathValue<T, K> extends boolean | undefined ? K : never;
|
|
32
|
+
}[Paths<T>];
|
|
33
|
+
type NumberDataPath<T extends JsonObject> = {
|
|
34
|
+
[K in Paths<T>]: PathValue<T, K> extends number | undefined ? K : never;
|
|
35
|
+
}[Paths<T>];
|
|
36
|
+
type SyncOnConfig = ContextLocalActionConfig & {
|
|
37
|
+
sync?: true;
|
|
38
|
+
};
|
|
39
|
+
type SyncOffConfig = ContextLocalActionConfig & {
|
|
40
|
+
sync: false;
|
|
41
|
+
};
|
|
42
|
+
type WritableBooleanPath<T extends JsonObject, S extends z.ZodObject | undefined> = {
|
|
43
|
+
[K in WritableContextPath<T, S>]: PathValue<T, K> extends boolean | undefined ? WritablePathValue<S, K> extends boolean | undefined ? K : never : never;
|
|
44
|
+
}[WritableContextPath<T, S>];
|
|
45
|
+
type WritableNumberPath<T extends JsonObject, S extends z.ZodObject | undefined> = {
|
|
46
|
+
[K in WritableContextPath<T, S>]: PathValue<T, K> extends number | undefined ? WritablePathValue<S, K> extends number | undefined ? K : never : never;
|
|
47
|
+
}[WritableContextPath<T, S>];
|
|
48
|
+
type ContextLocalSet<T extends JsonObject, S extends z.ZodObject | undefined> = [WritableContextPath<T, S>] extends [never] ? {
|
|
49
|
+
set: (patch: LocalDataPathPatch<T>, config: SyncOffConfig) => SetContext<T, S>;
|
|
50
|
+
} : {
|
|
51
|
+
set: {
|
|
52
|
+
(patch: LocalContextPathPatch<T, S>, config?: SyncOnConfig): SetContext<T, S>;
|
|
53
|
+
(patch: LocalDataPathPatch<T>, config: SyncOffConfig): SetContext<T, S>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
type ContextLocalApi<T extends JsonObject, S extends z.ZodObject | undefined> = ContextLocalSet<T, S> & {
|
|
57
|
+
toggle: {
|
|
58
|
+
(path: WritableBooleanPath<T, S>, config?: SyncOnConfig): ToggleContextValue;
|
|
59
|
+
(path: BooleanDataPath<T>, config: SyncOffConfig): ToggleContextValue;
|
|
60
|
+
};
|
|
61
|
+
inc: {
|
|
62
|
+
(path: WritableNumberPath<T, S>, step?: ValueOrContextRef<number>, config?: SyncOnConfig): IncContextValue;
|
|
63
|
+
(path: NumberDataPath<T>, step: ValueOrContextRef<number> | undefined, config: SyncOffConfig): IncContextValue;
|
|
64
|
+
};
|
|
65
|
+
dec: {
|
|
66
|
+
(path: WritableNumberPath<T, S>, step?: ValueOrContextRef<number>, config?: SyncOnConfig): DecContextValue;
|
|
67
|
+
(path: NumberDataPath<T>, step: ValueOrContextRef<number> | undefined, config: SyncOffConfig): DecContextValue;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
29
70
|
/**
|
|
30
71
|
* Пустая strict-схема: клиент не может менять данные контекста через `context-values`.
|
|
31
72
|
* Используется во внутренних контекстах (ForEach, ItemList).
|
|
@@ -66,12 +107,7 @@ export declare class Context<T extends JsonObject, S extends z.ZodObject | undef
|
|
|
66
107
|
*/
|
|
67
108
|
readonly persistent: boolean;
|
|
68
109
|
/** Локальные (client-only) действия над данными этого контекста. */
|
|
69
|
-
readonly local:
|
|
70
|
-
set: (patch: LocalContextPathPatch<T, S>, config?: ActionConfig) => import("../actions/set-context").SetContext<T, S>;
|
|
71
|
-
toggle: <K extends WritableContextPath<T, S>>(path: PathValue<T, K> extends boolean | undefined ? WritablePathValue<S, K> extends boolean | undefined ? K : never : never, config?: ActionConfig) => ToggleContextValue;
|
|
72
|
-
inc: <K extends WritableContextPath<T, S>>(path: PathValue<T, K> extends number | undefined ? WritablePathValue<S, K> extends number | undefined ? K : never : never, step?: ValueOrContextRef<number>, config?: ActionConfig) => IncContextValue;
|
|
73
|
-
dec: <K extends WritableContextPath<T, S>>(path: PathValue<T, K> extends number | undefined ? WritablePathValue<S, K> extends number | undefined ? K : never : never, step?: ValueOrContextRef<number>, config?: ActionConfig) => DecContextValue;
|
|
74
|
-
};
|
|
110
|
+
readonly local: ContextLocalApi<T, S>;
|
|
75
111
|
/** Реактивное хранилище инициализации контекста */
|
|
76
112
|
private _init$;
|
|
77
113
|
readonly init$: Observable<void>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { JsonObject } from "@matreshka/client-bff-protocol/types/json";
|
|
2
1
|
import type { Observable } from "rxjs";
|
|
3
|
-
import {
|
|
2
|
+
import type { ContextLocalActionConfig } from "../actions/context-local-action-config";
|
|
3
|
+
import type { DecContextValue } from "../actions/dec-context-value";
|
|
4
|
+
import type { IncContextValue } from "../actions/inc-context-value";
|
|
4
5
|
import type { SetContext } from "../actions/set-context";
|
|
6
|
+
import type { ToggleContextValue } from "../actions/toggle-context-value";
|
|
5
7
|
import { AnySchemaContextRef, ContextRef, ContextRefValueType } from "../context/context-ref";
|
|
6
8
|
import type { ContextUpdateDelivery } from "./context-update-delivery";
|
|
7
9
|
/** Общая часть ref-типов по значению: маркер типа, чтение и запись. */
|
|
@@ -32,30 +34,11 @@ export type ContextRefOfValue<ValueType> = ValueRefBase<ValueType> & ContextRef<
|
|
|
32
34
|
* Ref `R` совместим с ожидаемым типом значения `ValueType` (проверка на call site).
|
|
33
35
|
*/
|
|
34
36
|
export type CompatibleContextRefOfValue<ValueType, R extends AnySchemaContextRef> = ValueType extends ContextRefValueType<R> ? R : never;
|
|
35
|
-
/**
|
|
36
|
-
* Эталонный writable ref для значения `ValueType`: путь `k` гарантированно есть
|
|
37
|
-
* в schema. Из него выводится `local`, так что при добавлении
|
|
38
|
-
* методов в `ContextRef.local` типы вручную переписывать не нужно.
|
|
39
|
-
*/
|
|
40
|
-
type WritableReferenceRef<ValueType> = ContextRef<{
|
|
41
|
-
k: Exclude<ValueType, undefined>;
|
|
42
|
-
} extends infer C extends JsonObject ? C : never, "k", z.ZodObject<{
|
|
43
|
-
k: z.ZodType<Exclude<ValueType, undefined>, Exclude<ValueType, undefined>>;
|
|
44
|
-
}>>;
|
|
45
|
-
/**
|
|
46
|
-
* Стирает привязку `SetContext` к конкретному контексту/schema, остальные
|
|
47
|
-
* сигнатуры `local` остаются как у `ContextRef.local`.
|
|
48
|
-
*/
|
|
49
|
-
type EraseLocalContext<Local> = {
|
|
50
|
-
[K in keyof Local]: Local[K] extends (...args: infer Args) => infer Result ? Result extends SetContext<any, any> ? (...args: Args) => SetContext<any, any> : Local[K] : Local[K];
|
|
51
|
-
};
|
|
52
37
|
/**
|
|
53
38
|
* Writable-ref с известным типом значения без generic по ref.
|
|
54
39
|
*
|
|
55
|
-
*
|
|
56
|
-
* `
|
|
57
|
-
* для эталонного writable ref, поэтому ref с путём вне schema не пройдёт
|
|
58
|
-
* проверку на call site.
|
|
40
|
+
* `local.set` с optional config — sync-on ветка; ref с путём вне schema
|
|
41
|
+
* (только `sync: false`) на call site не пройдёт.
|
|
59
42
|
*
|
|
60
43
|
* @example
|
|
61
44
|
* ```ts
|
|
@@ -65,8 +48,24 @@ type EraseLocalContext<Local> = {
|
|
|
65
48
|
* }
|
|
66
49
|
* ```
|
|
67
50
|
*/
|
|
51
|
+
type WritableLocalByValue<ValueType> = {
|
|
52
|
+
set(value: ValueOrContextRef<Exclude<ValueType, undefined>>, config?: ContextLocalActionConfig & {
|
|
53
|
+
sync?: true;
|
|
54
|
+
}): SetContext<any, any>;
|
|
55
|
+
} & ([Exclude<ValueType, undefined>] extends [boolean] ? {
|
|
56
|
+
toggle(config?: ContextLocalActionConfig & {
|
|
57
|
+
sync?: true;
|
|
58
|
+
}): ToggleContextValue;
|
|
59
|
+
} : {}) & ([Exclude<ValueType, undefined>] extends [number] ? {
|
|
60
|
+
inc(step?: ValueOrContextRef<number>, config?: ContextLocalActionConfig & {
|
|
61
|
+
sync?: true;
|
|
62
|
+
}): IncContextValue;
|
|
63
|
+
dec(step?: ValueOrContextRef<number>, config?: ContextLocalActionConfig & {
|
|
64
|
+
sync?: true;
|
|
65
|
+
}): DecContextValue;
|
|
66
|
+
} : {});
|
|
68
67
|
export type WritableContextRefOfValue<ValueType> = ContextRefOfValue<ValueType> & {
|
|
69
|
-
readonly local:
|
|
68
|
+
readonly local: WritableLocalByValue<ValueType>;
|
|
70
69
|
};
|
|
71
70
|
/** Статическое значение или ссылка на совместимое значение в контексте. */
|
|
72
71
|
export type ValueOrContextRef<ValueType> = ValueType | ContextRefOfValue<Exclude<ValueType, undefined>>;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { Audio, MediaConfig, Video } from "./media";
|
|
1
3
|
import { Platform } from "./platform";
|
|
2
4
|
/**
|
|
3
5
|
* Абстрактный класс, реализующий любую клиентскую платформу.
|
|
4
6
|
*/
|
|
5
7
|
export declare abstract class ClientPlatform extends Platform {
|
|
8
|
+
/**
|
|
9
|
+
* Создаёт `HTMLAudioElement` на клиенте вне DOM.
|
|
10
|
+
* Hot: элемент создаётся при вызове. Observable эмитит объект после ack.
|
|
11
|
+
*/
|
|
12
|
+
createAudio(config?: MediaConfig): Observable<Audio>;
|
|
13
|
+
/**
|
|
14
|
+
* Создаёт `HTMLVideoElement` на клиенте вне DOM.
|
|
15
|
+
* `Video.id` — ключ реестра, который позже сможет забрать видеокомпонент.
|
|
16
|
+
*/
|
|
17
|
+
createVideo(config?: MediaConfig): Observable<Video>;
|
|
6
18
|
}
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClientPlatform = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const media_1 = require("./media");
|
|
4
6
|
const platform_1 = require("./platform");
|
|
5
7
|
/**
|
|
6
8
|
* Абстрактный класс, реализующий любую клиентскую платформу.
|
|
7
9
|
*/
|
|
8
10
|
class ClientPlatform extends platform_1.Platform {
|
|
11
|
+
/**
|
|
12
|
+
* Создаёт `HTMLAudioElement` на клиенте вне DOM.
|
|
13
|
+
* Hot: элемент создаётся при вызове. Observable эмитит объект после ack.
|
|
14
|
+
*/
|
|
15
|
+
createAudio(config = {}) {
|
|
16
|
+
const audio = new media_1.Audio(this.client, config);
|
|
17
|
+
return audio.open().pipe((0, rxjs_1.map)(() => audio));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Создаёт `HTMLVideoElement` на клиенте вне DOM.
|
|
21
|
+
* `Video.id` — ключ реестра, который позже сможет забрать видеокомпонент.
|
|
22
|
+
*/
|
|
23
|
+
createVideo(config = {}) {
|
|
24
|
+
const video = new media_1.Video(this.client, config);
|
|
25
|
+
return video.open().pipe((0, rxjs_1.map)(() => video));
|
|
26
|
+
}
|
|
9
27
|
}
|
|
10
28
|
exports.ClientPlatform = ClientPlatform;
|
|
@@ -3,6 +3,7 @@ export * from "./browser-platform";
|
|
|
3
3
|
export * from "./client-platform";
|
|
4
4
|
export * from "./ios-platform";
|
|
5
5
|
export * from "./max-mini-app-platform";
|
|
6
|
+
export * from "./media";
|
|
6
7
|
export * from "./mobile-platform";
|
|
7
8
|
export * from "./platform";
|
|
8
9
|
export * from "./popover-show";
|
package/dist/platforms/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./browser-platform"), exports);
|
|
|
19
19
|
__exportStar(require("./client-platform"), exports);
|
|
20
20
|
__exportStar(require("./ios-platform"), exports);
|
|
21
21
|
__exportStar(require("./max-mini-app-platform"), exports);
|
|
22
|
+
__exportStar(require("./media"), exports);
|
|
22
23
|
__exportStar(require("./mobile-platform"), exports);
|
|
23
24
|
__exportStar(require("./platform"), exports);
|
|
24
25
|
__exportStar(require("./popover-show"), exports);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { MediaCrossOrigin } from "@matreshka/client-bff-protocol/enums/media-cross-origin";
|
|
2
|
+
import { MediaKind } from "@matreshka/client-bff-protocol/enums/media-kind";
|
|
3
|
+
import { MediaPreload } from "@matreshka/client-bff-protocol/enums/media-preload";
|
|
4
|
+
import { AnyBffToClientMessage } from "@matreshka/client-bff-protocol/messages/bff-to-client/bff-to-client-message";
|
|
5
|
+
import type { MediaElementConfig } from "@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-create-message";
|
|
6
|
+
import { Observable } from "rxjs";
|
|
7
|
+
import { ServerAction, type ServerActionHandler } from "../components/actions/server-action";
|
|
8
|
+
import { LocalAction } from "../core/actions/local-action";
|
|
9
|
+
import type { Client } from "../core/client";
|
|
10
|
+
import type { Componentable } from "../core/types/componentable";
|
|
11
|
+
export { MediaCrossOrigin, MediaKind, MediaPreload };
|
|
12
|
+
export type MediaProgressPayload = {
|
|
13
|
+
currentTime: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
};
|
|
16
|
+
export type MediaVolumePayload = {
|
|
17
|
+
volume: number;
|
|
18
|
+
muted: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type MediaRatePayload = {
|
|
21
|
+
playbackRate: number;
|
|
22
|
+
};
|
|
23
|
+
export type MediaErrorPayload = {
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
/** Одно действие или массив локальных и серверных, как `onClick` у компонента. */
|
|
27
|
+
export type MediaAction<Payload> = ServerAction<Componentable, Payload> | ServerActionHandler<Componentable, Payload> | LocalAction;
|
|
28
|
+
export type MediaActionList<Payload> = MediaAction<Payload> | MediaAction<Payload>[];
|
|
29
|
+
export type MediaEventConfig = {
|
|
30
|
+
onPlay?: MediaActionList<MediaProgressPayload>;
|
|
31
|
+
onPause?: MediaActionList<MediaProgressPayload>;
|
|
32
|
+
onPlaying?: MediaActionList<MediaProgressPayload>;
|
|
33
|
+
onWaiting?: MediaActionList<MediaProgressPayload>;
|
|
34
|
+
onEnded?: MediaActionList<MediaProgressPayload>;
|
|
35
|
+
onError?: MediaActionList<MediaErrorPayload>;
|
|
36
|
+
onLoadedMetadata?: MediaActionList<MediaProgressPayload>;
|
|
37
|
+
onSeeking?: MediaActionList<MediaProgressPayload>;
|
|
38
|
+
onSeeked?: MediaActionList<MediaProgressPayload>;
|
|
39
|
+
onVolumeChange?: MediaActionList<MediaVolumePayload>;
|
|
40
|
+
onRateChange?: MediaActionList<MediaRatePayload>;
|
|
41
|
+
onTimeUpdate?: MediaActionList<MediaProgressPayload>;
|
|
42
|
+
onEnterPictureInPicture?: MediaActionList<Record<string, never>>;
|
|
43
|
+
onLeavePictureInPicture?: MediaActionList<Record<string, never>>;
|
|
44
|
+
};
|
|
45
|
+
export type MediaConfig = MediaElementConfig & MediaEventConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Сессия `HTMLMediaElement` на клиенте. Элемент не входит в дерево компонентов.
|
|
48
|
+
* `id` — ключ клиентского реестра для будущего видеокомпонента.
|
|
49
|
+
*/
|
|
50
|
+
export declare abstract class Media {
|
|
51
|
+
protected readonly client: Client;
|
|
52
|
+
private readonly kind;
|
|
53
|
+
readonly id: string;
|
|
54
|
+
private readonly handlers;
|
|
55
|
+
private readonly rawConfig;
|
|
56
|
+
private sessionSubscription?;
|
|
57
|
+
private clientDestroySubscription?;
|
|
58
|
+
private ended;
|
|
59
|
+
constructor(client: Client, config: MediaConfig, kind: MediaKind);
|
|
60
|
+
play(): Observable<void>;
|
|
61
|
+
pause(): Observable<void>;
|
|
62
|
+
load(): Observable<void>;
|
|
63
|
+
seek(time: number): Observable<void>;
|
|
64
|
+
setSrc(src: string): Observable<void>;
|
|
65
|
+
setVolume(volume: number): Observable<void>;
|
|
66
|
+
setMuted(muted: boolean): Observable<void>;
|
|
67
|
+
setPlaybackRate(playbackRate: number): Observable<void>;
|
|
68
|
+
setLoop(loop: boolean): Observable<void>;
|
|
69
|
+
setPreload(preload: MediaPreload): Observable<void>;
|
|
70
|
+
destroy(): Observable<void>;
|
|
71
|
+
/** @internal */
|
|
72
|
+
open(): Observable<void>;
|
|
73
|
+
protected send(outgoingMessage: (scope: string) => AnyBffToClientMessage): Observable<void>;
|
|
74
|
+
private elementConfig;
|
|
75
|
+
private bindEvents;
|
|
76
|
+
private parseAction;
|
|
77
|
+
private serializeInteractions;
|
|
78
|
+
private startSession;
|
|
79
|
+
private emit;
|
|
80
|
+
private endSession;
|
|
81
|
+
}
|
|
82
|
+
export declare class Audio extends Media {
|
|
83
|
+
constructor(client: Client, config: MediaConfig);
|
|
84
|
+
}
|
|
85
|
+
export declare class Video extends Media {
|
|
86
|
+
constructor(client: Client, config: MediaConfig);
|
|
87
|
+
requestPictureInPicture(): Observable<void>;
|
|
88
|
+
exitPictureInPicture(): Observable<void>;
|
|
89
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Video = exports.Audio = exports.Media = exports.MediaPreload = exports.MediaKind = exports.MediaCrossOrigin = void 0;
|
|
4
|
+
const media_cross_origin_1 = require("@matreshka/client-bff-protocol/enums/media-cross-origin");
|
|
5
|
+
Object.defineProperty(exports, "MediaCrossOrigin", { enumerable: true, get: function () { return media_cross_origin_1.MediaCrossOrigin; } });
|
|
6
|
+
const media_kind_1 = require("@matreshka/client-bff-protocol/enums/media-kind");
|
|
7
|
+
Object.defineProperty(exports, "MediaKind", { enumerable: true, get: function () { return media_kind_1.MediaKind; } });
|
|
8
|
+
const media_preload_1 = require("@matreshka/client-bff-protocol/enums/media-preload");
|
|
9
|
+
Object.defineProperty(exports, "MediaPreload", { enumerable: true, get: function () { return media_preload_1.MediaPreload; } });
|
|
10
|
+
const media_create_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-create-message");
|
|
11
|
+
const media_destroy_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-destroy-message");
|
|
12
|
+
const media_exit_picture_in_picture_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-exit-picture-in-picture-message");
|
|
13
|
+
const media_load_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-load-message");
|
|
14
|
+
const media_pause_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-pause-message");
|
|
15
|
+
const media_play_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-play-message");
|
|
16
|
+
const media_request_picture_in_picture_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-request-picture-in-picture-message");
|
|
17
|
+
const media_seek_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-seek-message");
|
|
18
|
+
const media_set_loop_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-loop-message");
|
|
19
|
+
const media_set_muted_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-muted-message");
|
|
20
|
+
const media_set_playback_rate_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-playback-rate-message");
|
|
21
|
+
const media_set_preload_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-preload-message");
|
|
22
|
+
const media_set_src_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-src-message");
|
|
23
|
+
const media_set_volume_message_1 = require("@matreshka/client-bff-protocol/messages/bff-to-client/platforms/media-set-volume-message");
|
|
24
|
+
const media_event_messages_1 = require("@matreshka/client-bff-protocol/messages/client-to-bff/platforms/media-event-messages");
|
|
25
|
+
const rxjs_1 = require("rxjs");
|
|
26
|
+
const zod_1 = require("zod");
|
|
27
|
+
const server_action_1 = require("../components/actions/server-action");
|
|
28
|
+
const action_1 = require("../core/actions/action");
|
|
29
|
+
const local_action_1 = require("../core/actions/local-action");
|
|
30
|
+
const client_context_1 = require("../core/client-context");
|
|
31
|
+
const incoming_message_observer_1 = require("../core/utils/incoming-message-observer");
|
|
32
|
+
const targeted_client_platform_action_1 = require("./utils/targeted-client-platform-action");
|
|
33
|
+
function isMediaIncomingEvent(message) {
|
|
34
|
+
return (message instanceof media_event_messages_1.MediaPlayEventMessage ||
|
|
35
|
+
message instanceof media_event_messages_1.MediaPauseEventMessage ||
|
|
36
|
+
message instanceof media_event_messages_1.MediaPlayingEventMessage ||
|
|
37
|
+
message instanceof media_event_messages_1.MediaWaitingEventMessage ||
|
|
38
|
+
message instanceof media_event_messages_1.MediaEndedEventMessage ||
|
|
39
|
+
message instanceof media_event_messages_1.MediaLoadedMetadataEventMessage ||
|
|
40
|
+
message instanceof media_event_messages_1.MediaSeekingEventMessage ||
|
|
41
|
+
message instanceof media_event_messages_1.MediaSeekedEventMessage ||
|
|
42
|
+
message instanceof media_event_messages_1.MediaTimeUpdateEventMessage ||
|
|
43
|
+
message instanceof media_event_messages_1.MediaVolumeChangeEventMessage ||
|
|
44
|
+
message instanceof media_event_messages_1.MediaRateChangeEventMessage ||
|
|
45
|
+
message instanceof media_event_messages_1.MediaErrorEventMessage ||
|
|
46
|
+
message instanceof media_event_messages_1.MediaEnterPictureInPictureEventMessage ||
|
|
47
|
+
message instanceof media_event_messages_1.MediaLeavePictureInPictureEventMessage);
|
|
48
|
+
}
|
|
49
|
+
const mediaHandlersSchema = zod_1.z.array(zod_1.z.number().int().nonnegative());
|
|
50
|
+
const mediaProgressEventSchema = zod_1.z.strictObject({
|
|
51
|
+
currentTime: zod_1.z.number(),
|
|
52
|
+
duration: zod_1.z.number(),
|
|
53
|
+
handlers: mediaHandlersSchema,
|
|
54
|
+
});
|
|
55
|
+
const mediaVolumeEventSchema = zod_1.z.strictObject({
|
|
56
|
+
volume: zod_1.z.number(),
|
|
57
|
+
muted: zod_1.z.boolean(),
|
|
58
|
+
handlers: mediaHandlersSchema,
|
|
59
|
+
});
|
|
60
|
+
const mediaRateEventSchema = zod_1.z.strictObject({
|
|
61
|
+
playbackRate: zod_1.z.number(),
|
|
62
|
+
handlers: mediaHandlersSchema,
|
|
63
|
+
});
|
|
64
|
+
const mediaErrorEventSchema = zod_1.z.strictObject({
|
|
65
|
+
message: zod_1.z.string(),
|
|
66
|
+
handlers: mediaHandlersSchema,
|
|
67
|
+
});
|
|
68
|
+
const mediaPictureInPictureEventSchema = zod_1.z.strictObject({
|
|
69
|
+
handlers: mediaHandlersSchema,
|
|
70
|
+
});
|
|
71
|
+
function mediaEventSchema(message) {
|
|
72
|
+
if (message instanceof media_event_messages_1.MediaVolumeChangeEventMessage) {
|
|
73
|
+
return mediaVolumeEventSchema;
|
|
74
|
+
}
|
|
75
|
+
if (message instanceof media_event_messages_1.MediaRateChangeEventMessage) {
|
|
76
|
+
return mediaRateEventSchema;
|
|
77
|
+
}
|
|
78
|
+
if (message instanceof media_event_messages_1.MediaErrorEventMessage) {
|
|
79
|
+
return mediaErrorEventSchema;
|
|
80
|
+
}
|
|
81
|
+
if (message instanceof media_event_messages_1.MediaEnterPictureInPictureEventMessage ||
|
|
82
|
+
message instanceof media_event_messages_1.MediaLeavePictureInPictureEventMessage) {
|
|
83
|
+
return mediaPictureInPictureEventSchema;
|
|
84
|
+
}
|
|
85
|
+
return mediaProgressEventSchema;
|
|
86
|
+
}
|
|
87
|
+
function mediaEventName(message) {
|
|
88
|
+
if (message instanceof media_event_messages_1.MediaPlayEventMessage) {
|
|
89
|
+
return "play";
|
|
90
|
+
}
|
|
91
|
+
if (message instanceof media_event_messages_1.MediaPauseEventMessage) {
|
|
92
|
+
return "pause";
|
|
93
|
+
}
|
|
94
|
+
if (message instanceof media_event_messages_1.MediaPlayingEventMessage) {
|
|
95
|
+
return "playing";
|
|
96
|
+
}
|
|
97
|
+
if (message instanceof media_event_messages_1.MediaWaitingEventMessage) {
|
|
98
|
+
return "waiting";
|
|
99
|
+
}
|
|
100
|
+
if (message instanceof media_event_messages_1.MediaEndedEventMessage) {
|
|
101
|
+
return "ended";
|
|
102
|
+
}
|
|
103
|
+
if (message instanceof media_event_messages_1.MediaLoadedMetadataEventMessage) {
|
|
104
|
+
return "loadedmetadata";
|
|
105
|
+
}
|
|
106
|
+
if (message instanceof media_event_messages_1.MediaSeekingEventMessage) {
|
|
107
|
+
return "seeking";
|
|
108
|
+
}
|
|
109
|
+
if (message instanceof media_event_messages_1.MediaSeekedEventMessage) {
|
|
110
|
+
return "seeked";
|
|
111
|
+
}
|
|
112
|
+
if (message instanceof media_event_messages_1.MediaTimeUpdateEventMessage) {
|
|
113
|
+
return "timeupdate";
|
|
114
|
+
}
|
|
115
|
+
if (message instanceof media_event_messages_1.MediaVolumeChangeEventMessage) {
|
|
116
|
+
return "volumechange";
|
|
117
|
+
}
|
|
118
|
+
if (message instanceof media_event_messages_1.MediaRateChangeEventMessage) {
|
|
119
|
+
return "ratechange";
|
|
120
|
+
}
|
|
121
|
+
if (message instanceof media_event_messages_1.MediaErrorEventMessage) {
|
|
122
|
+
return "error";
|
|
123
|
+
}
|
|
124
|
+
if (message instanceof media_event_messages_1.MediaEnterPictureInPictureEventMessage) {
|
|
125
|
+
return "enterpictureinpicture";
|
|
126
|
+
}
|
|
127
|
+
return "leavepictureinpicture";
|
|
128
|
+
}
|
|
129
|
+
const EVENT_FIELDS = {
|
|
130
|
+
onPlay: "play",
|
|
131
|
+
onPause: "pause",
|
|
132
|
+
onPlaying: "playing",
|
|
133
|
+
onWaiting: "waiting",
|
|
134
|
+
onEnded: "ended",
|
|
135
|
+
onError: "error",
|
|
136
|
+
onLoadedMetadata: "loadedmetadata",
|
|
137
|
+
onSeeking: "seeking",
|
|
138
|
+
onSeeked: "seeked",
|
|
139
|
+
onVolumeChange: "volumechange",
|
|
140
|
+
onRateChange: "ratechange",
|
|
141
|
+
onTimeUpdate: "timeupdate",
|
|
142
|
+
onEnterPictureInPicture: "enterpictureinpicture",
|
|
143
|
+
onLeavePictureInPicture: "leavepictureinpicture",
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Сессия `HTMLMediaElement` на клиенте. Элемент не входит в дерево компонентов.
|
|
147
|
+
* `id` — ключ клиентского реестра для будущего видеокомпонента.
|
|
148
|
+
*/
|
|
149
|
+
class Media {
|
|
150
|
+
constructor(client, config, kind) {
|
|
151
|
+
this.client = client;
|
|
152
|
+
this.kind = kind;
|
|
153
|
+
this.id = "media-" + crypto.randomUUID();
|
|
154
|
+
this.handlers = new Map();
|
|
155
|
+
this.ended = false;
|
|
156
|
+
this.rawConfig = config;
|
|
157
|
+
this.bindEvents(config);
|
|
158
|
+
}
|
|
159
|
+
play() {
|
|
160
|
+
return this.send((scope) => new media_play_message_1.MediaPlayMessage(scope, { mediaId: this.id }));
|
|
161
|
+
}
|
|
162
|
+
pause() {
|
|
163
|
+
return this.send((scope) => new media_pause_message_1.MediaPauseMessage(scope, { mediaId: this.id }));
|
|
164
|
+
}
|
|
165
|
+
load() {
|
|
166
|
+
return this.send((scope) => new media_load_message_1.MediaLoadMessage(scope, { mediaId: this.id }));
|
|
167
|
+
}
|
|
168
|
+
seek(time) {
|
|
169
|
+
return this.send((scope) => new media_seek_message_1.MediaSeekMessage(scope, { mediaId: this.id, time }));
|
|
170
|
+
}
|
|
171
|
+
setSrc(src) {
|
|
172
|
+
return this.send((scope) => new media_set_src_message_1.MediaSetSrcMessage(scope, { mediaId: this.id, src }));
|
|
173
|
+
}
|
|
174
|
+
setVolume(volume) {
|
|
175
|
+
return this.send((scope) => new media_set_volume_message_1.MediaSetVolumeMessage(scope, { mediaId: this.id, volume }));
|
|
176
|
+
}
|
|
177
|
+
setMuted(muted) {
|
|
178
|
+
return this.send((scope) => new media_set_muted_message_1.MediaSetMutedMessage(scope, { mediaId: this.id, muted }));
|
|
179
|
+
}
|
|
180
|
+
setPlaybackRate(playbackRate) {
|
|
181
|
+
return this.send((scope) => new media_set_playback_rate_message_1.MediaSetPlaybackRateMessage(scope, {
|
|
182
|
+
mediaId: this.id,
|
|
183
|
+
playbackRate,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
setLoop(loop) {
|
|
187
|
+
return this.send((scope) => new media_set_loop_message_1.MediaSetLoopMessage(scope, { mediaId: this.id, loop }));
|
|
188
|
+
}
|
|
189
|
+
setPreload(preload) {
|
|
190
|
+
return this.send((scope) => new media_set_preload_message_1.MediaSetPreloadMessage(scope, { mediaId: this.id, preload }));
|
|
191
|
+
}
|
|
192
|
+
destroy() {
|
|
193
|
+
if (this.ended) {
|
|
194
|
+
return (0, rxjs_1.of)(undefined);
|
|
195
|
+
}
|
|
196
|
+
return this.send((scope) => new media_destroy_message_1.MediaDestroyMessage(scope, { mediaId: this.id })).pipe((0, rxjs_1.tap)(() => this.endSession()));
|
|
197
|
+
}
|
|
198
|
+
/** @internal */
|
|
199
|
+
open() {
|
|
200
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
201
|
+
outgoingMessage: (scope) => (0, client_context_1.runWithClient)(this.client, () => new media_create_message_1.MediaCreateMessage(scope, {
|
|
202
|
+
mediaId: this.id,
|
|
203
|
+
kind: this.kind,
|
|
204
|
+
config: this.elementConfig(),
|
|
205
|
+
interactions: this.serializeInteractions(),
|
|
206
|
+
})),
|
|
207
|
+
}).pipe((0, rxjs_1.tap)(() => this.startSession()));
|
|
208
|
+
}
|
|
209
|
+
send(outgoingMessage) {
|
|
210
|
+
return (0, targeted_client_platform_action_1.targetedClientPlatformAction)(this.client, {
|
|
211
|
+
outgoingMessage,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
elementConfig() {
|
|
215
|
+
const config = this.rawConfig;
|
|
216
|
+
return {
|
|
217
|
+
src: config.src,
|
|
218
|
+
volume: config.volume,
|
|
219
|
+
muted: config.muted,
|
|
220
|
+
loop: config.loop,
|
|
221
|
+
playbackRate: config.playbackRate,
|
|
222
|
+
preload: config.preload,
|
|
223
|
+
crossOrigin: config.crossOrigin,
|
|
224
|
+
autoplay: config.autoplay,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
bindEvents(config) {
|
|
228
|
+
Object.keys(EVENT_FIELDS).forEach((field) => {
|
|
229
|
+
const actions = config[field];
|
|
230
|
+
if (actions === undefined) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const list = (Array.isArray(actions) ? actions : [actions]).map((action) => this.parseAction(action));
|
|
234
|
+
this.handlers.set(EVENT_FIELDS[field], list);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
parseAction(action) {
|
|
238
|
+
if (action instanceof local_action_1.LocalAction || action instanceof server_action_1.ServerAction) {
|
|
239
|
+
return action;
|
|
240
|
+
}
|
|
241
|
+
if (action instanceof action_1.Action) {
|
|
242
|
+
throw new Error("Media events accept LocalAction, ServerAction, or a server function");
|
|
243
|
+
}
|
|
244
|
+
return new server_action_1.ServerAction(action);
|
|
245
|
+
}
|
|
246
|
+
serializeInteractions() {
|
|
247
|
+
const interactions = {};
|
|
248
|
+
this.handlers.forEach((actions, event) => {
|
|
249
|
+
interactions[event] = actions.map((action) => action.toJSON());
|
|
250
|
+
});
|
|
251
|
+
return interactions;
|
|
252
|
+
}
|
|
253
|
+
startSession() {
|
|
254
|
+
if (this.sessionSubscription || this.ended) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
this.sessionSubscription = this.client.incomingMessage$
|
|
258
|
+
.pipe((0, rxjs_1.filter)((message) => isMediaIncomingEvent(message) && message.target === this.id))
|
|
259
|
+
.subscribe((0, incoming_message_observer_1.incomingMessageObserver)(this.client, (message) => {
|
|
260
|
+
const parsed = mediaEventSchema(message).safeParse(message.payload);
|
|
261
|
+
if (!parsed.success) {
|
|
262
|
+
this.client.error$.next(`Invalid media event payload: ${message.type}`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const { handlers, ...payload } = parsed.data;
|
|
266
|
+
this.emit(mediaEventName(message), payload, handlers);
|
|
267
|
+
}));
|
|
268
|
+
this.clientDestroySubscription = this.client.destroy$
|
|
269
|
+
.pipe((0, rxjs_1.take)(1))
|
|
270
|
+
.subscribe(() => this.endSession());
|
|
271
|
+
}
|
|
272
|
+
emit(event, payload, handlers) {
|
|
273
|
+
const actions = this.handlers.get(event);
|
|
274
|
+
if (!actions) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
for (const index of handlers) {
|
|
278
|
+
const action = actions[index];
|
|
279
|
+
if (!(action instanceof server_action_1.ServerAction)) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
action.execute({
|
|
283
|
+
payload,
|
|
284
|
+
instance: { client: this.client },
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
endSession() {
|
|
289
|
+
if (this.ended) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
this.ended = true;
|
|
293
|
+
this.sessionSubscription?.unsubscribe();
|
|
294
|
+
this.clientDestroySubscription?.unsubscribe();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.Media = Media;
|
|
298
|
+
class Audio extends Media {
|
|
299
|
+
constructor(client, config) {
|
|
300
|
+
super(client, config, media_kind_1.MediaKind.Audio);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.Audio = Audio;
|
|
304
|
+
class Video extends Media {
|
|
305
|
+
constructor(client, config) {
|
|
306
|
+
super(client, config, media_kind_1.MediaKind.Video);
|
|
307
|
+
}
|
|
308
|
+
requestPictureInPicture() {
|
|
309
|
+
return this.send((scope) => new media_request_picture_in_picture_message_1.MediaRequestPictureInPictureMessage(scope, { mediaId: this.id }));
|
|
310
|
+
}
|
|
311
|
+
exitPictureInPicture() {
|
|
312
|
+
return this.send((scope) => new media_exit_picture_in_picture_message_1.MediaExitPictureInPictureMessage(scope, { mediaId: this.id }));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.Video = Video;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matreshka/bff",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.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/client-bff-protocol": "^0.
|
|
65
|
+
"@matreshka/client-bff-protocol": "^0.7.0",
|
|
66
66
|
"@matreshka/gateway-bff-protocol": "^0.1.0",
|
|
67
67
|
"@matreshka/shared": "^0.26.0",
|
|
68
68
|
"@simplewebauthn/server": "^13.1.1",
|