@dragcraft/widgets 0.0.1
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/LICENSE +21 -0
- package/dist/index.d.mts +65 -0
- package/dist/index.mjs +47 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT hackycy <https://github.com/hackycy>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ContainerDefinition, CoreWidgetMeta, DesignerEngine, WidgetMeta } from "@dragcraft/core";
|
|
2
|
+
import { Component } from "vue";
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Complete widget definition combining metadata and Vue component.
|
|
6
|
+
* Used for registering widgets with the engine and renderer.
|
|
7
|
+
*/
|
|
8
|
+
interface WidgetDefinition<Meta extends CoreWidgetMeta = CoreWidgetMeta> {
|
|
9
|
+
/** Widget metadata for core registry */
|
|
10
|
+
meta: Meta;
|
|
11
|
+
/** Vue component for rendering in canvas */
|
|
12
|
+
component: Component;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Widget group name type.
|
|
16
|
+
* Accepts any string to support custom groups beyond built-in ones.
|
|
17
|
+
*/
|
|
18
|
+
type WidgetGroup = string;
|
|
19
|
+
/**
|
|
20
|
+
* Widget group configuration with localized titles.
|
|
21
|
+
*/
|
|
22
|
+
interface WidgetGroupConfig {
|
|
23
|
+
name: string;
|
|
24
|
+
title: string;
|
|
25
|
+
/** i18n message key for title; overrides `title` when i18n is active */
|
|
26
|
+
titleKey?: string;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/helpers.d.ts
|
|
30
|
+
declare function defineContainerWidget<Meta extends WidgetMeta & {
|
|
31
|
+
container: ContainerDefinition;
|
|
32
|
+
}>(definition: WidgetDefinition<Meta>): WidgetDefinition<Meta>;
|
|
33
|
+
/**
|
|
34
|
+
* Registers a list of widget definitions with the given DesignerEngine.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { registerWidgets } from '@dragcraft/widgets'
|
|
39
|
+
*
|
|
40
|
+
* registerWidgets(engine, myWidgetDefinitions)
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function registerWidgets<Meta extends WidgetMeta>(engine: DesignerEngine, definitions: WidgetDefinition<Meta>[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Builds a component map from widget definitions.
|
|
46
|
+
* Maps each widget's `type` to its Vue component.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { buildComponentMap } from '@dragcraft/widgets'
|
|
51
|
+
*
|
|
52
|
+
* const componentMap = buildComponentMap(myWidgetDefinitions)
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function buildComponentMap<Meta extends WidgetMeta>(definitions: WidgetDefinition<Meta>[]): Record<string, Component>;
|
|
56
|
+
/**
|
|
57
|
+
* Extracts all WidgetMeta from widget definitions.
|
|
58
|
+
*/
|
|
59
|
+
declare function getWidgetMetas<Meta extends WidgetMeta>(definitions: WidgetDefinition<Meta>[]): Meta[];
|
|
60
|
+
/**
|
|
61
|
+
* Filters widget definitions by group name.
|
|
62
|
+
*/
|
|
63
|
+
declare function filterByGroup<Meta extends WidgetMeta>(definitions: WidgetDefinition<Meta>[], group: string): WidgetDefinition<Meta>[];
|
|
64
|
+
//#endregion
|
|
65
|
+
export { type WidgetDefinition, type WidgetGroup, type WidgetGroupConfig, buildComponentMap, defineContainerWidget, filterByGroup, getWidgetMetas, registerWidgets };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/helpers.ts
|
|
2
|
+
function defineContainerWidget(definition) {
|
|
3
|
+
return definition;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Registers a list of widget definitions with the given DesignerEngine.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { registerWidgets } from '@dragcraft/widgets'
|
|
11
|
+
*
|
|
12
|
+
* registerWidgets(engine, myWidgetDefinitions)
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function registerWidgets(engine, definitions) {
|
|
16
|
+
for (const def of definitions) engine.registerWidget(def.meta);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Builds a component map from widget definitions.
|
|
20
|
+
* Maps each widget's `type` to its Vue component.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { buildComponentMap } from '@dragcraft/widgets'
|
|
25
|
+
*
|
|
26
|
+
* const componentMap = buildComponentMap(myWidgetDefinitions)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function buildComponentMap(definitions) {
|
|
30
|
+
const map = {};
|
|
31
|
+
for (const def of definitions) map[def.meta.type] = def.component;
|
|
32
|
+
return map;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extracts all WidgetMeta from widget definitions.
|
|
36
|
+
*/
|
|
37
|
+
function getWidgetMetas(definitions) {
|
|
38
|
+
return definitions.map((def) => def.meta);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Filters widget definitions by group name.
|
|
42
|
+
*/
|
|
43
|
+
function filterByGroup(definitions, group) {
|
|
44
|
+
return definitions.filter((def) => def.meta.group === group);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { buildComponentMap, defineContainerWidget, filterByGroup, getWidgetMetas, registerWidgets };
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dragcraft/widgets",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "@dragcraft/widgets",
|
|
6
|
+
"author": "hackycy <hackycy@outlook.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/hackycy/dragcraft#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/hackycy/dragcraft.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/hackycy/dragcraft/issues",
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.mjs",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.mjs",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"vue": ">=3.0.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@dragcraft/core": "0.0.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"vitest": "^4.0.7",
|
|
34
|
+
"vue": "^3.5.27"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown",
|
|
38
|
+
"dev": "tsdown --watch",
|
|
39
|
+
"lint": "eslint",
|
|
40
|
+
"release": "bumpp",
|
|
41
|
+
"start": "tsx src/index.ts",
|
|
42
|
+
"test": "vitest",
|
|
43
|
+
"typecheck": "tsc"
|
|
44
|
+
}
|
|
45
|
+
}
|