@vnejs/plugins.canvas.filter 0.1.1 → 0.1.3
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/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/modules/filter.d.ts +13 -0
- package/dist/modules/filter.js +27 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/dist/utils/filter.d.ts +17 -0
- package/dist/utils/filter.js +1 -0
- package/package.json +33 -6
- package/src/index.ts +6 -0
- package/src/modules/filter.ts +43 -0
- package/src/types.ts +10 -0
- package/src/utils/filter.ts +20 -0
- package/tsconfig.json +9 -0
- package/const/const.js +0 -1
- package/const/events.js +0 -4
- package/index.js +0 -8
- package/modules/filter.js +0 -32
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.canvas.filter.contract";
|
|
3
|
+
import { LayerFilter } from "./modules/filter.js";
|
|
4
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [LayerFilter]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { FilterPluginConstants, FilterPluginEvents, FilterPluginParams } from "../types.js";
|
|
3
|
+
import type { FilterSetPayload, FilterState, FilterUnsetPayload } from "../utils/filter.js";
|
|
4
|
+
export declare class LayerFilter extends Module<FilterPluginEvents, FilterPluginConstants, Record<string, never>, FilterPluginParams, FilterState> {
|
|
5
|
+
name: string;
|
|
6
|
+
subscribe: () => void;
|
|
7
|
+
onFilterSet: ({ layer, name, value, duration, args }?: FilterSetPayload) => Promise<unknown[] | undefined>;
|
|
8
|
+
onFilterUnset: ({ layer, duration }?: FilterUnsetPayload) => Promise<unknown[] | undefined>;
|
|
9
|
+
onStateSet: ({ [this.name]: state }?: Record<string, FilterState>) => Promise<void>;
|
|
10
|
+
onStateClear: () => Promise<(unknown[] | undefined)[]>;
|
|
11
|
+
emitLayerPropsUpdate: (layer: string, filter: string, duration: number) => Promise<unknown[]> | undefined;
|
|
12
|
+
getDefaultState: () => FilterState;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
export class LayerFilter extends Module {
|
|
3
|
+
name = "layer.filter";
|
|
4
|
+
subscribe = () => {
|
|
5
|
+
this.on(this.EVENTS.LAYER_FILTER.SET, this.onFilterSet);
|
|
6
|
+
this.on(this.EVENTS.LAYER_FILTER.UNSET, this.onFilterUnset);
|
|
7
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
8
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
9
|
+
};
|
|
10
|
+
onFilterSet = async ({ layer = "", name = "", value = "", duration = 0, args = [] } = {}) => {
|
|
11
|
+
const filterFn = this.PARAMS.LAYER_FILTER.FILTERS[name];
|
|
12
|
+
const filter = value || (filterFn ? filterFn(...args) : "");
|
|
13
|
+
this.state[layer] = filter;
|
|
14
|
+
return this.emitLayerPropsUpdate(layer, this.state[layer], duration);
|
|
15
|
+
};
|
|
16
|
+
onFilterUnset = async ({ layer = "", duration = 0 } = {}) => {
|
|
17
|
+
delete this.state[layer];
|
|
18
|
+
return this.emitLayerPropsUpdate(layer, "", duration);
|
|
19
|
+
};
|
|
20
|
+
onStateSet = async ({ [this.name]: state = {} } = {}) => {
|
|
21
|
+
await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.UNSET, { layer, duration: 0 })));
|
|
22
|
+
await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.SET, { layer, value: state[layer], duration: 0 })));
|
|
23
|
+
};
|
|
24
|
+
onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.UNSET, { layer, duration: 0 })));
|
|
25
|
+
emitLayerPropsUpdate = (layer, filter, duration) => this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { filter }, duration });
|
|
26
|
+
getDefaultState = () => ({});
|
|
27
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/plugins.canvas.filter.contract";
|
|
3
|
+
import type { PluginName as LayerPluginName, SubscribeEvents as LayerSubscribeEvents } from "@vnejs/plugins.canvas.layer.contract";
|
|
4
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
5
|
+
export type FilterPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<LayerPluginName, LayerSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
|
|
6
|
+
export type FilterPluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
|
|
7
|
+
export type FilterPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type FilterState = Record<string, string>;
|
|
2
|
+
export type FilterSetPayload = {
|
|
3
|
+
layer?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
value?: string;
|
|
6
|
+
duration?: number;
|
|
7
|
+
args?: unknown[];
|
|
8
|
+
};
|
|
9
|
+
export type FilterUnsetPayload = {
|
|
10
|
+
layer?: string;
|
|
11
|
+
duration?: number;
|
|
12
|
+
};
|
|
13
|
+
export type FilterStateSetPayload = {
|
|
14
|
+
value?: string;
|
|
15
|
+
layer?: string;
|
|
16
|
+
duration?: number;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.canvas.filter",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
5
20
|
"scripts": {
|
|
6
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
7
23
|
"publish:major:plugin": "npm run publish:major",
|
|
8
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
9
25
|
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
-
"publish:major": "
|
|
11
|
-
"publish:minor": "
|
|
12
|
-
"publish:patch": "
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
13
29
|
},
|
|
14
30
|
"author": "",
|
|
15
31
|
"license": "ISC",
|
|
16
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.canvas.filter.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/module": "~0.0.1",
|
|
37
|
+
"@vnejs/plugins.canvas.layer.contract": "~0.0.1",
|
|
38
|
+
"@vnejs/plugins.core.state.contract": "~0.0.1",
|
|
39
|
+
"@vnejs/shared": "~0.0.9"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@vnejs/configs.ts-common": "~0.0.1"
|
|
43
|
+
}
|
|
17
44
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.canvas.filter.contract";
|
|
3
|
+
|
|
4
|
+
import { LayerFilter } from "./modules/filter.js";
|
|
5
|
+
|
|
6
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [LayerFilter]);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
import type { FilterPluginConstants, FilterPluginEvents, FilterPluginParams } from "../types.js";
|
|
4
|
+
import type { FilterSetPayload, FilterState, FilterStateSetPayload, FilterUnsetPayload } from "../utils/filter.js";
|
|
5
|
+
|
|
6
|
+
export class LayerFilter extends Module<FilterPluginEvents, FilterPluginConstants, Record<string, never>, FilterPluginParams, FilterState> {
|
|
7
|
+
name = "layer.filter";
|
|
8
|
+
|
|
9
|
+
subscribe = () => {
|
|
10
|
+
this.on(this.EVENTS.LAYER_FILTER.SET, this.onFilterSet);
|
|
11
|
+
this.on(this.EVENTS.LAYER_FILTER.UNSET, this.onFilterUnset);
|
|
12
|
+
|
|
13
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
14
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
onFilterSet = async ({ layer = "", name = "", value = "", duration = 0, args = [] }: FilterSetPayload = {}) => {
|
|
18
|
+
const filterFn = this.PARAMS.LAYER_FILTER.FILTERS[name as keyof typeof this.PARAMS.LAYER_FILTER.FILTERS];
|
|
19
|
+
const filter = value || (filterFn ? (filterFn as (...filterArgs: unknown[]) => string)(...args) : "");
|
|
20
|
+
|
|
21
|
+
this.state[layer] = filter!;
|
|
22
|
+
|
|
23
|
+
return this.emitLayerPropsUpdate(layer, this.state[layer], duration);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
onFilterUnset = async ({ layer = "", duration = 0 }: FilterUnsetPayload = {}) => {
|
|
27
|
+
delete this.state[layer];
|
|
28
|
+
|
|
29
|
+
return this.emitLayerPropsUpdate(layer, "", duration);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
onStateSet = async ({ [this.name]: state = {} }: Record<string, FilterState> = {}) => {
|
|
33
|
+
await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.UNSET, { layer, duration: 0 })));
|
|
34
|
+
await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.SET, { layer, value: state[layer], duration: 0 } satisfies FilterStateSetPayload)));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.UNSET, { layer, duration: 0 })));
|
|
38
|
+
|
|
39
|
+
emitLayerPropsUpdate = (layer: string, filter: string, duration: number) =>
|
|
40
|
+
this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { filter }, duration });
|
|
41
|
+
|
|
42
|
+
getDefaultState = (): FilterState => ({});
|
|
43
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/plugins.canvas.filter.contract";
|
|
3
|
+
import type { PluginName as LayerPluginName, SubscribeEvents as LayerSubscribeEvents } from "@vnejs/plugins.canvas.layer.contract";
|
|
4
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
5
|
+
|
|
6
|
+
export type FilterPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<LayerPluginName, LayerSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
|
|
7
|
+
|
|
8
|
+
export type FilterPluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
|
|
9
|
+
|
|
10
|
+
export type FilterPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type FilterState = Record<string, string>;
|
|
2
|
+
|
|
3
|
+
export type FilterSetPayload = {
|
|
4
|
+
layer?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
duration?: number;
|
|
8
|
+
args?: unknown[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type FilterUnsetPayload = {
|
|
12
|
+
layer?: string;
|
|
13
|
+
duration?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type FilterStateSetPayload = {
|
|
17
|
+
value?: string;
|
|
18
|
+
layer?: string;
|
|
19
|
+
duration?: number;
|
|
20
|
+
};
|
package/tsconfig.json
ADDED
package/const/const.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ACTIONS = { SET: "set", UNSET: "unset" };
|
package/const/events.js
DELETED
package/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { regPlugin } from "@vnejs/shared";
|
|
2
|
-
|
|
3
|
-
import * as constants from "./const/const";
|
|
4
|
-
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
5
|
-
|
|
6
|
-
import { LayerFilter } from "./modules/filter";
|
|
7
|
-
|
|
8
|
-
regPlugin("LAYER_FILTER", { constants, events: SUBSCRIBE_EVENTS }, [LayerFilter]);
|
package/modules/filter.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Module } from "@vnejs/module";
|
|
2
|
-
|
|
3
|
-
export class LayerFilter extends Module {
|
|
4
|
-
name = "layer.filter";
|
|
5
|
-
|
|
6
|
-
subscribe = () => {
|
|
7
|
-
this.on(this.EVENTS.LAYER_FILTER.SET, this.onFilterSet);
|
|
8
|
-
this.on(this.EVENTS.LAYER_FILTER.UNSET, this.onFilterUnset);
|
|
9
|
-
|
|
10
|
-
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
11
|
-
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
onFilterSet = async ({ layer = "", name = "", duration = 0 } = {}) => {
|
|
15
|
-
this.state[layer] = name;
|
|
16
|
-
|
|
17
|
-
return this.emitLayerPropsUpdate(layer, name, duration);
|
|
18
|
-
};
|
|
19
|
-
onFilterUnset = async ({ layer = "", duration = 0 } = {}) => {
|
|
20
|
-
delete this.state[layer];
|
|
21
|
-
|
|
22
|
-
return this.emitLayerPropsUpdate(layer, "", duration);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
onStateSet = async ({ [this.name]: state = {} } = {}) => {
|
|
26
|
-
await Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.UNSET, { layer, duration: 0 })));
|
|
27
|
-
await Promise.all(Object.keys(state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.SET, { layer, name: state[layer], duration: 0 })));
|
|
28
|
-
};
|
|
29
|
-
onStateClear = () => Promise.all(Object.keys(this.state).map((layer) => this.emit(this.EVENTS.LAYER_FILTER.UNSET, { layer, duration: 0 })));
|
|
30
|
-
|
|
31
|
-
emitLayerPropsUpdate = (layer, filter, duration) => this.emit(this.EVENTS.LAYER.PROPS_UPDATE, { layer, props: { filter }, duration });
|
|
32
|
-
}
|