@oinone/kunlun-event 6.2.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/oinone-kunlun-event.esm.js +15 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/src/bus/abstract/AbstractEventConsumer.d.ts +17 -0
- package/dist/types/src/bus/abstract/AbstractEventEngine.d.ts +21 -0
- package/dist/types/src/bus/abstract/AbstractEventProducer.d.ts +15 -0
- package/dist/types/src/bus/abstract/index.d.ts +2 -0
- package/dist/types/src/bus/bus/basic.d.ts +12 -0
- package/dist/types/src/bus/bus/html-event.d.ts +6 -0
- package/dist/types/src/bus/bus/html-keyboard-event.d.ts +6 -0
- package/dist/types/src/bus/bus/index.d.ts +18 -0
- package/dist/types/src/bus/hook/consumer.d.ts +1 -0
- package/dist/types/src/bus/hook/index.d.ts +2 -0
- package/dist/types/src/bus/hook/producer.d.ts +1 -0
- package/dist/types/src/bus/index.d.ts +5 -0
- package/dist/types/src/bus/operator/consumer.d.ts +11 -0
- package/dist/types/src/bus/operator/index.d.ts +2 -0
- package/dist/types/src/bus/operator/producer.d.ts +10 -0
- package/dist/types/src/bus/spi/consumer.d.ts +8 -0
- package/dist/types/src/bus/spi/index.d.ts +2 -0
- package/dist/types/src/bus/spi/producer.d.ts +8 -0
- package/dist/types/src/bus/typing/basic.d.ts +64 -0
- package/dist/types/src/bus/typing/category.d.ts +5 -0
- package/dist/types/src/bus/typing/index.d.ts +3 -0
- package/dist/types/src/bus/typing/keyboard.d.ts +16 -0
- package/dist/types/src/effects/effectbox.d.ts +3 -0
- package/dist/types/src/effects/fieldEffects.d.ts +61 -0
- package/dist/types/src/effects/index.d.ts +2 -0
- package/dist/types/src/effects/viewEffects.d.ts +69 -0
- package/dist/types/src/helper.d.ts +14 -0
- package/dist/types/src/html-event/basic/AbstractHTMLEventProducer.d.ts +7 -0
- package/dist/types/src/html-event/basic/HTMLEventConsumer.d.ts +4 -0
- package/dist/types/src/html-event/basic/HTMLEventProducer.d.ts +5 -0
- package/dist/types/src/html-event/basic/index.d.ts +3 -0
- package/dist/types/src/html-event/index.d.ts +2 -0
- package/dist/types/src/html-event/keyboard/HTMLKeyboardEventConsumer.d.ts +14 -0
- package/dist/types/src/html-event/keyboard/HTMLKeyboardEventProducer.d.ts +16 -0
- package/dist/types/src/html-event/keyboard/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +6 -0
- package/dist/types/src/lifecycle/heart.d.ts +75 -0
- package/dist/types/src/lifecycle/index.d.ts +2 -0
- package/dist/types/src/lifecycle/lifecycle.d.ts +7 -0
- package/dist/types/src/typing/index.d.ts +1 -0
- package/dist/types/src/typing/lifecycle.d.ts +92 -0
- package/index.ts +1 -0
- package/package.json +19 -0
- package/rollup.config.js +4 -0
- package/src/bus/abstract/AbstractEventConsumer.ts +79 -0
- package/src/bus/abstract/AbstractEventEngine.ts +79 -0
- package/src/bus/abstract/AbstractEventProducer.ts +64 -0
- package/src/bus/abstract/index.ts +2 -0
- package/src/bus/bus/basic.ts +124 -0
- package/src/bus/bus/html-event.ts +43 -0
- package/src/bus/bus/html-keyboard-event.ts +46 -0
- package/src/bus/bus/index.ts +46 -0
- package/src/bus/hook/consumer.ts +1 -0
- package/src/bus/hook/index.ts +2 -0
- package/src/bus/hook/producer.ts +1 -0
- package/src/bus/index.ts +5 -0
- package/src/bus/operator/consumer.ts +83 -0
- package/src/bus/operator/index.ts +2 -0
- package/src/bus/operator/producer.ts +56 -0
- package/src/bus/spi/consumer.ts +34 -0
- package/src/bus/spi/index.ts +2 -0
- package/src/bus/spi/producer.ts +27 -0
- package/src/bus/typing/basic.ts +126 -0
- package/src/bus/typing/category.ts +6 -0
- package/src/bus/typing/index.ts +3 -0
- package/src/bus/typing/keyboard.ts +21 -0
- package/src/effects/effectbox.ts +22 -0
- package/src/effects/fieldEffects.ts +99 -0
- package/src/effects/index.ts +2 -0
- package/src/effects/viewEffects.ts +111 -0
- package/src/helper.ts +31 -0
- package/src/html-event/basic/AbstractHTMLEventProducer.ts +30 -0
- package/src/html-event/basic/HTMLEventConsumer.ts +26 -0
- package/src/html-event/basic/HTMLEventProducer.ts +10 -0
- package/src/html-event/basic/index.ts +3 -0
- package/src/html-event/index.ts +2 -0
- package/src/html-event/keyboard/HTMLKeyboardEventConsumer.ts +160 -0
- package/src/html-event/keyboard/HTMLKeyboardEventProducer.ts +72 -0
- package/src/html-event/keyboard/index.ts +2 -0
- package/src/index.ts +6 -0
- package/src/lifecycle/heart.ts +160 -0
- package/src/lifecycle/index.ts +2 -0
- package/src/lifecycle/lifecycle.ts +29 -0
- package/src/typing/index.ts +1 -0
- package/src/typing/lifecycle.ts +104 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ConsumerOperator, ProducerOperator } from '../operator';
|
|
2
|
+
import { Basic } from './basic';
|
|
3
|
+
import { HTMLEvent } from './html-event';
|
|
4
|
+
import { HTMLKeyboardEvent } from './html-keyboard-event';
|
|
5
|
+
|
|
6
|
+
export class EventBus {
|
|
7
|
+
public static init = Basic.init;
|
|
8
|
+
|
|
9
|
+
public static startProducer = Basic.startProducer;
|
|
10
|
+
|
|
11
|
+
public static stopProducer = Basic.stopProducer;
|
|
12
|
+
|
|
13
|
+
public static publish = Basic.publish;
|
|
14
|
+
|
|
15
|
+
public static subscribe = Basic.subscribe;
|
|
16
|
+
|
|
17
|
+
public static unsubscribe = Basic.unsubscribe;
|
|
18
|
+
|
|
19
|
+
public static start = Basic.startConsumer;
|
|
20
|
+
|
|
21
|
+
public static stop = Basic.stopConsumer;
|
|
22
|
+
|
|
23
|
+
// public static constructProducer = ProducerOperator.construct;
|
|
24
|
+
|
|
25
|
+
// public static initProducer = ProducerOperator.init;
|
|
26
|
+
|
|
27
|
+
public static disposeProducer = ProducerOperator.dispose;
|
|
28
|
+
|
|
29
|
+
// public static constructConsumer = ConsumerOperator.construct;
|
|
30
|
+
|
|
31
|
+
// public static initConsumer = ConsumerOperator.init;
|
|
32
|
+
|
|
33
|
+
public static disposeConsumer = ConsumerOperator.dispose;
|
|
34
|
+
|
|
35
|
+
// public static initHTMLProducer = HTMLEvent.init;
|
|
36
|
+
|
|
37
|
+
// public static disposeHTMLProducer = HTMLEvent.dispose;
|
|
38
|
+
|
|
39
|
+
public static subscribeHTMLEvent = HTMLEvent.subscribe;
|
|
40
|
+
|
|
41
|
+
// public static initKeyboardProducer = HTMLKeyboardEvent.init;
|
|
42
|
+
|
|
43
|
+
// public static disposeKeyboardProducer = HTMLKeyboardEvent.dispose;
|
|
44
|
+
|
|
45
|
+
public static subscribeKeyboardEvent = HTMLKeyboardEvent.subscribe;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/bus/index.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useCurrentInstance } from '@oinone/kunlun-environment';
|
|
2
|
+
import { instantiate } from '@oinone/kunlun-shared';
|
|
3
|
+
import { selectorEventConsumer } from '../spi';
|
|
4
|
+
import {
|
|
5
|
+
EventConsumer,
|
|
6
|
+
EventConsumerConfig,
|
|
7
|
+
EventConsumerFunction,
|
|
8
|
+
EventConsumerOptions,
|
|
9
|
+
EventEngineOptions,
|
|
10
|
+
EventMessage
|
|
11
|
+
} from '../typing';
|
|
12
|
+
|
|
13
|
+
export class ConsumerOperator {
|
|
14
|
+
private static consumers: Map<string, EventConsumer<unknown, unknown, unknown>[]> = new Map<
|
|
15
|
+
string,
|
|
16
|
+
EventConsumer<unknown, unknown, unknown>[]
|
|
17
|
+
>();
|
|
18
|
+
|
|
19
|
+
public static getConsumers(message: EventMessage) {
|
|
20
|
+
return ConsumerOperator.consumers.get(ConsumerOperator.generatorKeyByMessage(message));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static construct<
|
|
24
|
+
K = string,
|
|
25
|
+
EV = unknown,
|
|
26
|
+
V = EV,
|
|
27
|
+
M extends EventMessage<V> = EventMessage<V>,
|
|
28
|
+
C extends EventConsumerConfig = EventConsumerConfig
|
|
29
|
+
>(
|
|
30
|
+
options: EventEngineOptions,
|
|
31
|
+
consumer: EventConsumerFunction<K, EV, V, M, C>,
|
|
32
|
+
consumerOptions?: EventConsumerOptions<EV, V, M, C>
|
|
33
|
+
): EventConsumer<K, EV, V, M, C> {
|
|
34
|
+
const ConsumerConstructor = selectorEventConsumer<K, EV, V, M, C>(options);
|
|
35
|
+
if (!ConsumerConstructor) {
|
|
36
|
+
throw new Error(`Unsupported consumer. category: ${options.category}, type: ${options.type}`);
|
|
37
|
+
}
|
|
38
|
+
const consumerInstance = instantiate(ConsumerConstructor, options.type, consumer, consumerOptions);
|
|
39
|
+
consumerInstance.el = useCurrentInstance().currentInstance?.vNode.el;
|
|
40
|
+
return consumerInstance;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static init<K = string, EV = unknown, V = EV>(consumer: EventConsumer<K, EV, V>): void {
|
|
44
|
+
const key = ConsumerOperator.generatorKeyByEngine(consumer);
|
|
45
|
+
let consumers = ConsumerOperator.consumers.get(key);
|
|
46
|
+
if (!consumers) {
|
|
47
|
+
consumers = [];
|
|
48
|
+
ConsumerOperator.consumers.set(key, consumers);
|
|
49
|
+
}
|
|
50
|
+
consumers.push(consumer);
|
|
51
|
+
consumer.start();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public static dispose<K = string, EV = unknown, V = EV>(consumer: EventConsumer<K, EV, V>): boolean {
|
|
55
|
+
const gk = ConsumerOperator.generatorKeyByEngine(consumer);
|
|
56
|
+
const ck = consumer.key;
|
|
57
|
+
const consumers = ConsumerOperator.consumers.get(gk);
|
|
58
|
+
if (!consumers) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const pos = consumers.findIndex((v) => v.key === ck);
|
|
62
|
+
if (pos === -1) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const deleteConsumers = consumers.splice(pos, 1);
|
|
66
|
+
for (const deleteConsumer of deleteConsumers) {
|
|
67
|
+
deleteConsumer.dispose();
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static generatorKey(category: string, type: string) {
|
|
73
|
+
return `${category}#${type}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public static generatorKeyByEngine<K = string, EV = unknown, V = EV>(consumer: EventConsumer<K, EV, V>) {
|
|
77
|
+
return `${consumer.category}#${consumer.type}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public static generatorKeyByMessage(message: EventMessage) {
|
|
81
|
+
return `${message.category}#${message.type}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { instantiate } from '@oinone/kunlun-shared';
|
|
2
|
+
import { selectorEventProducer } from '../spi';
|
|
3
|
+
import { EventCategoryType, EventEngineOptions, EventProducer, EventProducerOptions } from '../typing';
|
|
4
|
+
|
|
5
|
+
export class ProducerOperator {
|
|
6
|
+
private static producers: Map<string, EventProducer<unknown>> = new Map<
|
|
7
|
+
string,
|
|
8
|
+
EventProducer<unknown, unknown, unknown>
|
|
9
|
+
>();
|
|
10
|
+
|
|
11
|
+
public static getProducer<K = string, EV = unknown, V = EV>(
|
|
12
|
+
category: EventCategoryType,
|
|
13
|
+
type: string
|
|
14
|
+
): EventProducer<K, EV, V> | undefined {
|
|
15
|
+
return ProducerOperator.producers.get(ProducerOperator.generatorKey(category, type)) as
|
|
16
|
+
| EventProducer<K, EV, V>
|
|
17
|
+
| undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static construct<K = string, EV = unknown, V = EV>(
|
|
21
|
+
options: EventEngineOptions,
|
|
22
|
+
producerOptions?: EventProducerOptions<K, EV, V>
|
|
23
|
+
): EventProducer<K, EV, V> {
|
|
24
|
+
const ProducerConstructor = selectorEventProducer<K, EV, V>(options);
|
|
25
|
+
if (!ProducerConstructor) {
|
|
26
|
+
throw new Error(`Unsupported producer. category: ${options.category}, type: ${options.type}`);
|
|
27
|
+
}
|
|
28
|
+
return instantiate(ProducerConstructor, options.type, producerOptions);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public static init<K = string, EV = unknown, V = EV>(producer: EventProducer<K, EV, V>): void {
|
|
32
|
+
const key = ProducerOperator.generatorKeyByEngine(producer);
|
|
33
|
+
ProducerOperator.dispose(key);
|
|
34
|
+
ProducerOperator.producers.set(key, producer);
|
|
35
|
+
producer.start();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public static dispose<K = string, EV = unknown, V = EV>(key: string): EventProducer<K, EV, V> | undefined {
|
|
39
|
+
const producer = ProducerOperator.producers.get(key);
|
|
40
|
+
if (producer) {
|
|
41
|
+
ProducerOperator.producers.delete(key);
|
|
42
|
+
if (!producer.isDisposed) {
|
|
43
|
+
producer.dispose();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return producer as EventProducer<K, EV, V> | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public static generatorKey(category: string, type: string) {
|
|
50
|
+
return `${category}#${type}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public static generatorKeyByEngine<K = string, EV = unknown, V = EV>(producer: EventProducer<K, EV, V>) {
|
|
54
|
+
return `${producer.category}#${producer.type}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SPIOperator, SPIOptions } from '@oinone/kunlun-spi';
|
|
2
|
+
import { EventCategoryType, EventConsumerConfig, EventConsumerConstructor, EventMessage } from '../typing';
|
|
3
|
+
|
|
4
|
+
const EVENT_BUS_CONSUMER_KEY = Symbol('__event_bus_consumer');
|
|
5
|
+
|
|
6
|
+
export interface EventBusConsumerOptions extends SPIOptions {
|
|
7
|
+
category: EventCategoryType | EventCategoryType[];
|
|
8
|
+
type?: string | string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
SPIOperator.createStorage({
|
|
12
|
+
key: EVENT_BUS_CONSUMER_KEY,
|
|
13
|
+
matchKeys: ['category', 'type']
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export function registerEventConsumer<
|
|
17
|
+
K = string,
|
|
18
|
+
EV = unknown,
|
|
19
|
+
V = EV,
|
|
20
|
+
M extends EventMessage<V> = EventMessage<V>,
|
|
21
|
+
C extends EventConsumerConfig = EventConsumerConfig
|
|
22
|
+
>(options: EventBusConsumerOptions, constructor: EventConsumerConstructor<K, EV, V, M, C>) {
|
|
23
|
+
return SPIOperator.register(EVENT_BUS_CONSUMER_KEY, options, constructor);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function selectorEventConsumer<
|
|
27
|
+
K = string,
|
|
28
|
+
EV = unknown,
|
|
29
|
+
V = EV,
|
|
30
|
+
M extends EventMessage<V> = EventMessage<V>,
|
|
31
|
+
C extends EventConsumerConfig = EventConsumerConfig
|
|
32
|
+
>(options: EventBusConsumerOptions): EventConsumerConstructor<K, EV, V, M, C> | undefined {
|
|
33
|
+
return SPIOperator.selector(EVENT_BUS_CONSUMER_KEY, options);
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SPIOperator, SPIOptions } from '@oinone/kunlun-spi';
|
|
2
|
+
import { EventCategoryType, EventProducerConstructor } from '../typing';
|
|
3
|
+
|
|
4
|
+
const EVENT_BUS_PRODUCER_KEY = Symbol('__event_bus_producer');
|
|
5
|
+
|
|
6
|
+
export interface EventBusProducerOptions extends SPIOptions {
|
|
7
|
+
category: EventCategoryType | EventCategoryType[];
|
|
8
|
+
type?: string | string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
SPIOperator.createStorage({
|
|
12
|
+
key: EVENT_BUS_PRODUCER_KEY,
|
|
13
|
+
matchKeys: ['category', 'type']
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export function registerEventProducer<K = string, EV = unknown, V = EV>(
|
|
17
|
+
options: EventBusProducerOptions,
|
|
18
|
+
constructor: EventProducerConstructor<K, EV, V>
|
|
19
|
+
) {
|
|
20
|
+
return SPIOperator.register(EVENT_BUS_PRODUCER_KEY, options, constructor);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function selectorEventProducer<K = string, EV = unknown, V = EV>(
|
|
24
|
+
options: EventBusProducerOptions
|
|
25
|
+
): EventProducerConstructor<K, EV, V> | undefined {
|
|
26
|
+
return SPIOperator.selector(EVENT_BUS_PRODUCER_KEY, options);
|
|
27
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { EventCategoryType } from './category';
|
|
2
|
+
|
|
3
|
+
export interface EventEngine<K = string> {
|
|
4
|
+
key: string;
|
|
5
|
+
|
|
6
|
+
category: EventCategoryType;
|
|
7
|
+
|
|
8
|
+
type: K;
|
|
9
|
+
|
|
10
|
+
isActivated: boolean;
|
|
11
|
+
|
|
12
|
+
isDisposed: boolean;
|
|
13
|
+
|
|
14
|
+
start(): boolean;
|
|
15
|
+
|
|
16
|
+
stop(): boolean;
|
|
17
|
+
|
|
18
|
+
dispose(): boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface EventProducer<K = string, EV = unknown, V = EV> extends EventEngine<K> {
|
|
22
|
+
convert(ev: EV): EventMessage<V> | undefined;
|
|
23
|
+
|
|
24
|
+
publish(ev: EV): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type EventProducerConstructor<K = string, EV = unknown, V = EV> =
|
|
28
|
+
| (new (type: string, options?: EventProducerOptions<K, EV, V>) => EventProducer<K, EV, V>)
|
|
29
|
+
| EventProducer<K, EV, V>;
|
|
30
|
+
|
|
31
|
+
export interface EventProducerOptions<K = string, EV = unknown, V = EV> {
|
|
32
|
+
convert?: EventConvertFunction<K, EV, V>;
|
|
33
|
+
publish?: EventPublishFunction<K, EV, V>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type EventConvertFunction<K = string, EV = unknown, V = EV> = (
|
|
37
|
+
self: EventProducer<K, EV, V>,
|
|
38
|
+
ev: EV
|
|
39
|
+
) => EventMessage<V> | undefined;
|
|
40
|
+
|
|
41
|
+
export type EventPublishFunction<K = string, EV = unknown, V = EV> = (self: EventProducer<K, EV, V>, ev: EV) => void;
|
|
42
|
+
|
|
43
|
+
export interface EventConsumer<
|
|
44
|
+
K = string,
|
|
45
|
+
EV = unknown,
|
|
46
|
+
V = EV,
|
|
47
|
+
M extends EventMessage<V> = EventMessage<V>,
|
|
48
|
+
C extends EventConsumerConfig = EventConsumerConfig
|
|
49
|
+
> extends EventEngine<K> {
|
|
50
|
+
el?: HTMLElement;
|
|
51
|
+
|
|
52
|
+
config: C;
|
|
53
|
+
|
|
54
|
+
filter(ev: EV, message: M): boolean;
|
|
55
|
+
|
|
56
|
+
consumer(message: M): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type EventConsumerConstructor<
|
|
60
|
+
K = string,
|
|
61
|
+
EV = unknown,
|
|
62
|
+
V = EV,
|
|
63
|
+
M extends EventMessage<V> = EventMessage<V>,
|
|
64
|
+
C extends EventConsumerConfig = EventConsumerConfig
|
|
65
|
+
> = new (
|
|
66
|
+
type: string,
|
|
67
|
+
consumer: EventConsumerFunction<K, EV, V, M, C>,
|
|
68
|
+
options?: EventConsumerOptions<EV, V, M, C>
|
|
69
|
+
) => EventConsumer<K, EV, V, M, C>;
|
|
70
|
+
|
|
71
|
+
export interface EventConsumerOptions<
|
|
72
|
+
EV = unknown,
|
|
73
|
+
V = EV,
|
|
74
|
+
M extends EventMessage<V> = EventMessage<V>,
|
|
75
|
+
C extends EventConsumerConfig = EventConsumerConfig
|
|
76
|
+
> {
|
|
77
|
+
config?: C;
|
|
78
|
+
filter?: EventConsumerFilter<EV, V, M>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface EventConsumerConfig {
|
|
82
|
+
/**
|
|
83
|
+
* 作用范围
|
|
84
|
+
*/
|
|
85
|
+
scope?: EventConsumerScope;
|
|
86
|
+
/**
|
|
87
|
+
* 指针悬浮时启用
|
|
88
|
+
*/
|
|
89
|
+
pointerActivated?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* 隐藏时禁用
|
|
92
|
+
*/
|
|
93
|
+
invisibleDeactivated?: boolean;
|
|
94
|
+
|
|
95
|
+
[key: string]: unknown;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type EventConsumerFilter<EV = unknown, V = EV, M extends EventMessage<V> = EventMessage<V>> = (
|
|
99
|
+
ev: EV,
|
|
100
|
+
message: M
|
|
101
|
+
) => boolean;
|
|
102
|
+
|
|
103
|
+
export type EventConsumerFunction<
|
|
104
|
+
K = string,
|
|
105
|
+
EV = unknown,
|
|
106
|
+
V = EV,
|
|
107
|
+
M extends EventMessage<V> = EventMessage<V>,
|
|
108
|
+
C extends EventConsumerConfig = EventConsumerConfig
|
|
109
|
+
> = (self: EventConsumer, message: M) => void;
|
|
110
|
+
|
|
111
|
+
export interface EventMessage<V = unknown> {
|
|
112
|
+
category: EventCategoryType;
|
|
113
|
+
type: string;
|
|
114
|
+
origin: V;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type EventEngineOptions = {
|
|
118
|
+
category: EventCategoryType;
|
|
119
|
+
type: string | '*';
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export enum EventConsumerScope {
|
|
123
|
+
global = 'global',
|
|
124
|
+
view = 'view',
|
|
125
|
+
current = 'current'
|
|
126
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EventConsumerConfig, EventMessage } from './basic';
|
|
2
|
+
|
|
3
|
+
export interface KeyboardEventMessage extends EventMessage<KeyboardEvent> {
|
|
4
|
+
code: string;
|
|
5
|
+
key: string;
|
|
6
|
+
ctrl: boolean;
|
|
7
|
+
alt: boolean;
|
|
8
|
+
shift: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type KeyboardKeys = '*' | string | string[];
|
|
12
|
+
|
|
13
|
+
export type KeyboardType = 'keypress' | 'keyup' | 'keydown';
|
|
14
|
+
|
|
15
|
+
export const KeyboardTypes: KeyboardType[] = ['keypress', 'keyup', 'keydown'];
|
|
16
|
+
|
|
17
|
+
export interface HTMLKeyboardEventConsumerConfig extends EventConsumerConfig {
|
|
18
|
+
ctrl?: boolean;
|
|
19
|
+
alt?: boolean;
|
|
20
|
+
shift?: boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isStr, isFn } from '../helper';
|
|
2
|
+
import { LifeCycle, LifeCycleHeart } from '../lifecycle';
|
|
3
|
+
import { RegistryType, LifeCycleTypes } from '../typing';
|
|
4
|
+
|
|
5
|
+
function creatEffectHook<V, C>(lifeType: LifeCycleTypes, registryType: RegistryType) {
|
|
6
|
+
return (type: string, callback?: (ctx: C) => void) => {
|
|
7
|
+
if (!isStr(type)) {
|
|
8
|
+
throw new Error(`arg[0] must be string, but now is ${typeof type}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (callback) {
|
|
12
|
+
if (isFn(callback)) {
|
|
13
|
+
LifeCycleHeart.setType(registryType);
|
|
14
|
+
LifeCycleHeart.setLifeCycle(lifeType, type, new LifeCycle<C>(callback));
|
|
15
|
+
} else {
|
|
16
|
+
throw new Error(`arg[1] must be function`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { creatEffectHook };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { LifeCycleTypes, RegistryType } from '../typing';
|
|
2
|
+
import { creatEffectHook } from './effectbox';
|
|
3
|
+
|
|
4
|
+
function createFieldEffect<V = any, C = any>(lifeType: LifeCycleTypes) {
|
|
5
|
+
return creatEffectHook<V, C>(lifeType, RegistryType.FIELD);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 字段生命周期 字段创建前
|
|
10
|
+
*/
|
|
11
|
+
const onFieldBeforeCreate = createFieldEffect(LifeCycleTypes.ON_FIELD_BEFORE_CREATED);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 字段生命周期 字段已被创建
|
|
15
|
+
*/
|
|
16
|
+
const onFieldCreated = createFieldEffect(LifeCycleTypes.ON_FIELD_CREATED);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 字段生命周期 字段挂载前
|
|
20
|
+
*/
|
|
21
|
+
const onFieldBeforeMount = createFieldEffect(LifeCycleTypes.ON_FIELD_BEFORE_MOUNT);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 字段生命周期 字段已经挂载在页面上
|
|
25
|
+
*/
|
|
26
|
+
const onFieldMounted = createFieldEffect(LifeCycleTypes.ON_FIELD_MOUNTED);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 字段生命周期 字段修改前
|
|
30
|
+
*/
|
|
31
|
+
const onFieldBeforeUpdate = createFieldEffect(LifeCycleTypes.ON_FIELD_BEFORE_UPDATE);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 字段生命周期 字段已被修改
|
|
35
|
+
*/
|
|
36
|
+
const onFieldUpdated = createFieldEffect(LifeCycleTypes.ON_FIELD_UPDATED);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 字段生命周期 字段销毁前
|
|
40
|
+
*/
|
|
41
|
+
const onFieldBeforeUnmount = createFieldEffect(LifeCycleTypes.ON_FIELD_BEFORE_UNMOUNT);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 字段生命周期 字段已被销毁
|
|
45
|
+
*/
|
|
46
|
+
const onFieldUnmounted = createFieldEffect(LifeCycleTypes.ON_FIELD_UNMOUNTED);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 字段生命周期 单字段校验 校验开始
|
|
50
|
+
*/
|
|
51
|
+
const onFieldValidateStart = createFieldEffect(LifeCycleTypes.ON_FIELD_VALIDATE_START);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 字段生命周期 单字段校验 校验成功
|
|
55
|
+
*/
|
|
56
|
+
const onFieldValidateSuccess = createFieldEffect(LifeCycleTypes.ON_FIELD_VALIDATE_SUCCESS);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 字段生命周期 单字段校验 校验失败
|
|
60
|
+
*/
|
|
61
|
+
const onFieldValidateFailed = createFieldEffect(LifeCycleTypes.ON_FIELD_VALIDATE_FAILED);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 字段生命周期 单字段校验 校验结束
|
|
65
|
+
*/
|
|
66
|
+
const onFieldValidateEnd = createFieldEffect(LifeCycleTypes.ON_FIELD_VALIDATE_END);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 字段生命周期 字段获得焦点
|
|
70
|
+
*/
|
|
71
|
+
const onFieldFocus = createFieldEffect(LifeCycleTypes.ON_FIELD_FOCUS);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 字段生命周期 字段的值发生的修改(只有该字段发生了change方法才会触发,否则不触发)
|
|
75
|
+
*/
|
|
76
|
+
const onFieldValueChange = createFieldEffect(LifeCycleTypes.ON_FIELD_CHANGE);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 字段生命周期 字段失去焦点
|
|
80
|
+
*/
|
|
81
|
+
const onFieldBlur = createFieldEffect(LifeCycleTypes.ON_FIELD_BLUR);
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
onFieldBeforeCreate,
|
|
85
|
+
onFieldCreated,
|
|
86
|
+
onFieldBeforeMount,
|
|
87
|
+
onFieldMounted,
|
|
88
|
+
onFieldBeforeUpdate,
|
|
89
|
+
onFieldUpdated,
|
|
90
|
+
onFieldBeforeUnmount,
|
|
91
|
+
onFieldUnmounted,
|
|
92
|
+
onFieldValidateStart,
|
|
93
|
+
onFieldValidateSuccess,
|
|
94
|
+
onFieldValidateFailed,
|
|
95
|
+
onFieldValidateEnd,
|
|
96
|
+
onFieldFocus,
|
|
97
|
+
onFieldValueChange,
|
|
98
|
+
onFieldBlur
|
|
99
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { LifeCycleTypes, RegistryType } from '../typing';
|
|
2
|
+
import { creatEffectHook } from './effectbox';
|
|
3
|
+
|
|
4
|
+
function createViewEffect<V = any, C = any>(lifeType: LifeCycleTypes) {
|
|
5
|
+
return creatEffectHook<V, C>(lifeType, RegistryType.VIEW);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 视图生命周期 视图创建前
|
|
10
|
+
*/
|
|
11
|
+
const onViewBeforeCreated = createViewEffect(LifeCycleTypes.ON_VIEW_BEFORE_CREATED);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 视图生命周期 视图已被创建
|
|
15
|
+
*/
|
|
16
|
+
const onViewCreated = createViewEffect(LifeCycleTypes.ON_VIEW_CREATED);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 视图生命周期 视图挂载前
|
|
20
|
+
*/
|
|
21
|
+
const onViewBeforeMount = createViewEffect(LifeCycleTypes.ON_VIEW_BEFORE_MOUNT);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 视图生命周期 视图已经挂载在页面上
|
|
25
|
+
*/
|
|
26
|
+
const onViewMounted = createViewEffect(LifeCycleTypes.ON_VIEW_MOUNTED);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 视图生命周期 视图修改前
|
|
30
|
+
*/
|
|
31
|
+
const onViewBeforeUpdate = createViewEffect(LifeCycleTypes.ON_VIEW_BEFORE_UPDATE);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 视图生命周期 视图已被修改
|
|
35
|
+
*/
|
|
36
|
+
const onViewUpdated = createViewEffect(LifeCycleTypes.ON_VIEW_UPDATED);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 视图生命周期 视图销毁前
|
|
40
|
+
*/
|
|
41
|
+
const onViewBeforeUnmount = createViewEffect(LifeCycleTypes.ON_VIEW_BEFORE_UNMOUNT);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 视图生命周期 视图已被销毁
|
|
45
|
+
*/
|
|
46
|
+
const onViewUnmounted = createViewEffect(LifeCycleTypes.ON_VIEW_UNMOUNTED);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 视图生命周期 视图数据提交
|
|
50
|
+
*/
|
|
51
|
+
const onViewSubmit = createViewEffect(LifeCycleTypes.ON_VIEW_SUBMIT);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 视图生命周期 视图数据开始提交
|
|
55
|
+
*/
|
|
56
|
+
const onViewSubmitStart = createViewEffect(LifeCycleTypes.ON_VIEW_SUBMIT_START);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 视图生命周期 视图数据提交成功
|
|
60
|
+
*/
|
|
61
|
+
const onViewSubmitSuccess = createViewEffect(LifeCycleTypes.ON_VIEW_SUBMIT_SUCCESS);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 视图生命周期 视图数据提交失败
|
|
65
|
+
*/
|
|
66
|
+
const onViewSubmitFailed = createViewEffect(LifeCycleTypes.ON_VIEW_SUBMIT_FAILED);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 视图生命周期 视图数据提交结束
|
|
70
|
+
*/
|
|
71
|
+
const onViewSubmitEnd = createViewEffect(LifeCycleTypes.ON_VIEW_SUBMIT_END);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 视图生命周期 视图开始校验,只有表单页才会触发
|
|
75
|
+
*/
|
|
76
|
+
const onViewValidateStart = createViewEffect(LifeCycleTypes.ON_VIEW_VALIDATE_START);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 视图生命周期 视图校验成功,只有表单页才会触发
|
|
80
|
+
*/
|
|
81
|
+
const onViewValidateSuccess = createViewEffect(LifeCycleTypes.ON_VIEW_VALIDATE_SUCCESS);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 视图生命周期 视图校验失败,只有表单页才会触发
|
|
85
|
+
*/
|
|
86
|
+
const onViewValidateFailed = createViewEffect(LifeCycleTypes.ON_VIEW_VALIDATE_FAILED);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 视图生命周期 视图校验结束,只有表单页才会触发
|
|
90
|
+
*/
|
|
91
|
+
const onViewValidateEnd = createViewEffect(LifeCycleTypes.ON_VIEW_VALIDATE_END);
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
onViewBeforeCreated,
|
|
95
|
+
onViewCreated,
|
|
96
|
+
onViewBeforeMount,
|
|
97
|
+
onViewMounted,
|
|
98
|
+
onViewBeforeUpdate,
|
|
99
|
+
onViewUpdated,
|
|
100
|
+
onViewBeforeUnmount,
|
|
101
|
+
onViewUnmounted,
|
|
102
|
+
onViewSubmit,
|
|
103
|
+
onViewSubmitStart,
|
|
104
|
+
onViewSubmitSuccess,
|
|
105
|
+
onViewSubmitFailed,
|
|
106
|
+
onViewSubmitEnd,
|
|
107
|
+
onViewValidateStart,
|
|
108
|
+
onViewValidateSuccess,
|
|
109
|
+
onViewValidateFailed,
|
|
110
|
+
onViewValidateEnd
|
|
111
|
+
};
|