@fulate/vue 1.0.19 → 3.0.2
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/README.md +30 -42
- package/dist/chunks/{renderer-DidU2yIP.js → renderer-D5hdLgxq.js} +7 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -12
- package/dist/renderer.d.ts +1 -1
- package/dist/vue-shape.d.ts +6 -7
- package/dist/yoga.js +1 -1
- package/package.json +39 -39
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# `@fulate/vue`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
frame runtime;每个挂载的应用只拥有自己的 content/overlay Layer 和 Vue 生命周期。
|
|
3
|
+
提供 Fulate 的 Vue 渲染器,以及在图元中嵌入 Vue 组件的 `VueShape`。
|
|
5
4
|
|
|
6
5
|
## 创建与挂载
|
|
7
6
|
|
|
@@ -9,25 +8,28 @@ frame runtime;每个挂载的应用只拥有自己的 content/overlay Layer
|
|
|
9
8
|
import { createApp } from "@fulate/vue";
|
|
10
9
|
|
|
11
10
|
const app = createApp(App);
|
|
12
|
-
app.mount(container);
|
|
13
|
-
// 或:app.mount(root); // 使用已有 Root,Root 仍由调用方拥有
|
|
14
|
-
|
|
11
|
+
app.mount(container); // 也可传入选择器或已有 Root
|
|
15
12
|
app.unmount();
|
|
16
13
|
```
|
|
17
14
|
|
|
18
|
-
传入
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
传入 DOM 容器或选择器时,app 自动创建 Root,并在卸载时释放。传入已有 Root 时,app 只释放自己
|
|
16
|
+
创建的 Layer,调用方仍需释放 Root。一个 Root 只能承载一个 Fulate Vue app;卸载后的 app 不能重新挂载。
|
|
17
|
+
|
|
18
|
+
使用 Flex 标签时导入 `@fulate/vue/yoga`;`@fulate/components` 已完成该注册。
|
|
19
|
+
`f-vector-path` 创建 UI `EditorVectorPath`,接受 Core 路径命令或 `VectorPathGeometry`;
|
|
20
|
+
`f-polygon` 接受顶点数组或路径几何。
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
## 场景事件
|
|
23
|
+
|
|
24
|
+
Canvas 标签支持 `@click` / `onClick` 和捕获监听 `@click.capture` / `onClickCapture`。
|
|
25
|
+
传播与停止规则见 [Core 事件指南](../core/docs/guides/events-and-animation.md)。
|
|
24
26
|
|
|
25
27
|
## VueShape 与自定义元素
|
|
26
28
|
|
|
27
|
-
`VueShape`
|
|
29
|
+
`VueShape` 进入活动 Root 时挂载组件,离开时卸载。它支持两种 props 模式。
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
手动模式通过 `setComponentProps()` 整体替换 props;同一引用不触发更新。需要保存或复制组件时,
|
|
32
|
+
先注册名称:
|
|
31
33
|
|
|
32
34
|
```ts
|
|
33
35
|
import { VueShape, registerVueComponent } from "@fulate/vue";
|
|
@@ -37,9 +39,7 @@ const badge = new VueShape({ width: 120, height: 32 }, { label: "Ready" })
|
|
|
37
39
|
.bindComponent(Badge);
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
时注册一次 properties resolver。resolver 读取包含 configured/runtime 的最终 effective Properties,
|
|
42
|
-
每次返回完整 props;Fulate 通过同一 `setComponentProps()` 路径整体替换:
|
|
42
|
+
映射模式通过自定义 Properties 生成完整 props,配置和运行态属性变化都会重新映射:
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
45
|
class KeyValueShape extends VueShape<KeyValueProperties, KeyValueOption> {
|
|
@@ -55,12 +55,9 @@ class KeyValueShape extends VueShape<KeyValueProperties, KeyValueOption> {
|
|
|
55
55
|
}
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
JSON、Clipboard 或 History;mapped 业务类型由其具体 type factory 恢复。manual 模式仍保存组件名称和
|
|
60
|
-
手动 component props,`fromVueToFulate()` 与基础 `vueClipboardPlugin` 的行为不变。
|
|
58
|
+
两种模式互斥。映射结果不保存到文件或 History;自定义类型需提供自己的 codec。
|
|
61
59
|
|
|
62
|
-
每个 `VueShape`
|
|
63
|
-
派生类型可作为泛型参数保留具体类型:
|
|
60
|
+
每个 `VueShape` 拥有独立 Vue app。组件在 `setup()` 中可取得宿主:
|
|
64
61
|
|
|
65
62
|
```ts
|
|
66
63
|
import { useFulateHost } from "@fulate/vue";
|
|
@@ -68,36 +65,27 @@ import { useFulateHost } from "@fulate/vue";
|
|
|
68
65
|
const shape = useFulateHost<KeyValueShape>();
|
|
69
66
|
```
|
|
70
67
|
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
外层 Vue app 的 `provide()` 不会自动传入这些独立 app。组件尺寸通过 `useVueShapeSize()` 读取,
|
|
69
|
+
过渡动画使用 `FTransition`。
|
|
73
70
|
|
|
74
|
-
自定义 Canvas 元素通过 `registerElement("f-widget", Widget)`
|
|
75
|
-
`<f-widget />`。未知元素会在 renderer 创建时自然抛错,不另设兼容路径。
|
|
71
|
+
自定义 Canvas 元素通过 `registerElement("f-widget", Widget)` 注册后,可在模板中使用 `<f-widget />`。
|
|
76
72
|
|
|
77
73
|
## Root 与 overlay
|
|
78
74
|
|
|
79
|
-
`createApp()`
|
|
80
|
-
|
|
81
|
-
返回的 cleanup 必须在场景销毁时调用。
|
|
75
|
+
`createApp()` 创建内容层和浮层,通过 `FULATE_ROOT_KEY`、`FULATE_OVERLAY_KEY` 注入给组件。
|
|
76
|
+
手工管理场景时,为 `VueShape` 注册浮层,并在销毁时清理:
|
|
82
77
|
|
|
83
78
|
```ts
|
|
79
|
+
import { registerVueOverlay } from "@fulate/vue";
|
|
80
|
+
|
|
84
81
|
const unregister = registerVueOverlay(root, overlayLayer);
|
|
85
|
-
//
|
|
82
|
+
// 挂载并使用 VueShape。
|
|
86
83
|
unregister();
|
|
87
84
|
```
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
`animate()` 与 Root frame 路径完成。`registerVueOverlay()` 和组件 overlay 定位的 cleanup 绑定
|
|
91
|
-
所属 Root 生命周期;`useOverlayPosition()` 的异步结果只在 task、引用和挂载状态仍有效时安装。
|
|
86
|
+
## 文件与剪贴板
|
|
92
87
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
`vueClipboardPlugin` 是按 `Select` 实例显式安装的 clipboard adapter:
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
const select = new Select().useClipboard(vueClipboardPlugin);
|
|
99
|
-
```
|
|
88
|
+
将 `vueShapeV2Codec` 加入文件与剪贴板共用的 codec map,完整组合见[Tools IO 指南](../tools/README.md#原生场景与文件-io)。
|
|
100
89
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
全局 Select 行为,也不读取旧格式。
|
|
90
|
+
手动模式保存组件名称、props 和元素数据,恢复前必须注册组件。映射模式的自定义类型由业务 codec 恢复,
|
|
91
|
+
不保存派生 props。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Element, Shape, parseEventOptionKey } from "@fulate/core";
|
|
2
|
+
import { Circle, EditorVectorPath, Group, Image, Line, LineTree, Polygon, Rectangle, RippleOverlay, ScrollView, Text, Triangle, Workspace } from "@fulate/ui";
|
|
3
3
|
import { isFunction } from "lodash-es";
|
|
4
|
-
import {
|
|
4
|
+
import { createRenderer, markRaw } from "vue";
|
|
5
5
|
//#region packages/vue/src/renderer.ts
|
|
6
6
|
var elementConstructors = new Map([
|
|
7
7
|
["f-element", Element],
|
|
@@ -10,6 +10,7 @@ var elementConstructors = new Map([
|
|
|
10
10
|
["f-circle", Circle],
|
|
11
11
|
["f-triangle", Triangle],
|
|
12
12
|
["f-polygon", Polygon],
|
|
13
|
+
["f-vector-path", EditorVectorPath],
|
|
13
14
|
["f-text", Text],
|
|
14
15
|
["f-image", Image],
|
|
15
16
|
["f-workspace", Workspace],
|
|
@@ -29,9 +30,6 @@ function getRegisteredElement(type) {
|
|
|
29
30
|
function isEventProp(key) {
|
|
30
31
|
return /^on[A-Z]/.test(key);
|
|
31
32
|
}
|
|
32
|
-
function toEventName(key) {
|
|
33
|
-
return key.slice(2).toLowerCase();
|
|
34
|
-
}
|
|
35
33
|
function forEachEventHandler(value, callback) {
|
|
36
34
|
if (Array.isArray(value)) value.forEach((item) => forEachEventHandler(item, callback));
|
|
37
35
|
else if (isFunction(value)) callback(value);
|
|
@@ -73,9 +71,9 @@ var renderer = createRenderer({
|
|
|
73
71
|
patchProp(el, key, prevValue, nextValue) {
|
|
74
72
|
if (placeholders.has(el)) return;
|
|
75
73
|
if (isEventProp(key)) {
|
|
76
|
-
const eventName =
|
|
77
|
-
forEachEventHandler(prevValue, (handler) => el.removeEventListener(eventName, handler));
|
|
78
|
-
forEachEventHandler(nextValue, (handler) => el.addEventListener(eventName, handler));
|
|
74
|
+
const { eventName, capture } = parseEventOptionKey(key);
|
|
75
|
+
forEachEventHandler(prevValue, (handler) => el.removeEventListener(eventName, handler, { capture }));
|
|
76
|
+
forEachEventHandler(nextValue, (handler) => el.addEventListener(eventName, handler, { capture }));
|
|
79
77
|
return;
|
|
80
78
|
}
|
|
81
79
|
if (!initialElements.has(el)) el.setOptions({ [key]: nextValue });
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { createApp } from "./app";
|
|
|
4
4
|
export type { FulateApp, FulateAppMountOptions } from "./app";
|
|
5
5
|
export { FULATE_HOST_KEY, FULATE_OVERLAY_KEY, FULATE_ROOT_KEY, VUE_SHAPE_SIZE_KEY, registerVueOverlay, useFulateHost } from "./context";
|
|
6
6
|
export { FTransition } from "./transition";
|
|
7
|
-
export { VueShape, fromVueToFulate, registerVueComponent,
|
|
7
|
+
export { VueShape, fromVueToFulate, registerVueComponent, vueShapeV2Codec } from "./vue-shape";
|
|
8
8
|
export type { VueComponentPropsResolver, VueShapeJSON } from "./vue-shape";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as getRegisteredElement, r as registerElement, t as baseCreateApp } from "./chunks/renderer-
|
|
2
|
-
import { BaseTransition, defineComponent, getCurrentInstance, h, inject, markRaw, mergeProps, onBeforeUnmount, reactive, shallowRef } from "vue";
|
|
1
|
+
import { n as getRegisteredElement, r as registerElement, t as baseCreateApp } from "./chunks/renderer-D5hdLgxq.js";
|
|
3
2
|
import { Layer, Root } from "@fulate/core";
|
|
4
|
-
import { cloneDeep, has, isString, isUndefined } from "lodash-es";
|
|
5
3
|
import { Rectangle, RectangleProperties, RectangleTransform } from "@fulate/ui";
|
|
4
|
+
import { cloneDeep, has, isString, isUndefined } from "lodash-es";
|
|
5
|
+
import { BaseTransition, defineComponent, getCurrentInstance, h, inject, markRaw, mergeProps, onBeforeUnmount, reactive, shallowRef } from "vue";
|
|
6
6
|
//#region packages/vue/src/context.ts
|
|
7
7
|
var FULATE_ROOT_KEY = "__fulate_root";
|
|
8
8
|
var FULATE_OVERLAY_KEY = "__fulate_overlay";
|
|
@@ -397,9 +397,11 @@ var VueShape = class extends Rectangle {
|
|
|
397
397
|
if (this.componentPropsResolver) this.setComponentProps(this.componentPropsResolver(properties));
|
|
398
398
|
}
|
|
399
399
|
/** manual 模式保存 component metadata;mapped 模式只保存 Properties。 */
|
|
400
|
+
getPersistentChildren() {
|
|
401
|
+
return [];
|
|
402
|
+
}
|
|
400
403
|
toJSON() {
|
|
401
404
|
const json = super.toJSON();
|
|
402
|
-
delete json.children;
|
|
403
405
|
if (this.componentPropsResolver) return json;
|
|
404
406
|
return {
|
|
405
407
|
...json,
|
|
@@ -408,13 +410,11 @@ var VueShape = class extends Rectangle {
|
|
|
408
410
|
};
|
|
409
411
|
}
|
|
410
412
|
};
|
|
411
|
-
var
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const { type: _type,
|
|
415
|
-
|
|
416
|
-
if (!comp) return;
|
|
417
|
-
return fromVueToFulate(comp, shapeProps, componentProps);
|
|
413
|
+
var vueShapeV2Codec = {
|
|
414
|
+
encode: (element) => element.toJSON(),
|
|
415
|
+
decode(data) {
|
|
416
|
+
const { type: _type, component, componentProps, ...shapeProps } = data;
|
|
417
|
+
return fromVueToFulate(vueCompRegistry.get(component), shapeProps, componentProps);
|
|
418
418
|
}
|
|
419
419
|
};
|
|
420
420
|
/** 从彼此独立的 Rectangle options 和 Vue component props 创建 VueShape。 */
|
|
@@ -422,4 +422,4 @@ function fromVueToFulate(comp, options = {}, componentProps = {}) {
|
|
|
422
422
|
return markRaw(new VueShape(options, componentProps)).bindComponent(comp);
|
|
423
423
|
}
|
|
424
424
|
//#endregion
|
|
425
|
-
export { FTransition, FULATE_HOST_KEY, FULATE_OVERLAY_KEY, FULATE_ROOT_KEY, VUE_SHAPE_SIZE_KEY, VueShape, createApp, fromVueToFulate, getRegisteredElement, registerElement, registerVueComponent, registerVueOverlay, useFulateHost,
|
|
425
|
+
export { FTransition, FULATE_HOST_KEY, FULATE_OVERLAY_KEY, FULATE_ROOT_KEY, VUE_SHAPE_SIZE_KEY, VueShape, createApp, fromVueToFulate, getRegisteredElement, registerElement, registerVueComponent, registerVueOverlay, useFulateHost, vueShapeV2Codec };
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Renderer } from "vue";
|
|
2
1
|
import { Element } from "@fulate/core";
|
|
2
|
+
import { type Renderer } from "vue";
|
|
3
3
|
export type ElementConstructor<T extends Element = Element> = new (options?: any) => T;
|
|
4
4
|
export declare function registerElement(type: string, Constructor: ElementConstructor): void;
|
|
5
5
|
export declare function getRegisteredElement(type: string): ElementConstructor | undefined;
|
package/dist/vue-shape.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ElementV2Codec } from "@fulate/core";
|
|
2
|
+
import { type ElementPayload, type ElementTransformClass, type Layer, type PropertyChanges, type Root } from "@fulate/core";
|
|
2
3
|
import { Rectangle, RectangleProperties, type RectangleOption } from "@fulate/ui";
|
|
3
4
|
import { type Component } from "vue";
|
|
4
5
|
export declare function registerVueComponent(name: string, comp: Component): void;
|
|
5
6
|
/** 将当前 effective Properties 映射为完整 Vue component props。 */
|
|
6
7
|
export type VueComponentPropsResolver<P extends RectangleProperties = RectangleProperties> = (properties: Readonly<P>) => Record<string, unknown>;
|
|
7
|
-
export type VueShapeJSON
|
|
8
|
+
export type VueShapeJSON = ElementPayload & {
|
|
8
9
|
component?: string;
|
|
9
10
|
componentProps?: Record<string, unknown>;
|
|
10
11
|
};
|
|
@@ -33,11 +34,9 @@ export declare class VueShape<P extends RectangleProperties = RectanglePropertie
|
|
|
33
34
|
private syncSize;
|
|
34
35
|
private syncComponentProps;
|
|
35
36
|
/** manual 模式保存 component metadata;mapped 模式只保存 Properties。 */
|
|
36
|
-
|
|
37
|
+
getPersistentChildren(): any[];
|
|
38
|
+
toJSON(): VueShapeJSON;
|
|
37
39
|
}
|
|
38
|
-
export declare const
|
|
39
|
-
readonly type: "vue-component";
|
|
40
|
-
readonly deserialize: (data: Record<string, any>) => VueShape<RectangleProperties, RectangleOption<any>>;
|
|
41
|
-
};
|
|
40
|
+
export declare const vueShapeV2Codec: ElementV2Codec;
|
|
42
41
|
/** 从彼此独立的 Rectangle options 和 Vue component props 创建 VueShape。 */
|
|
43
42
|
export declare function fromVueToFulate(comp: Component, options?: RectangleOption<VueShape>, componentProps?: Record<string, unknown>): VueShape;
|
package/dist/yoga.js
CHANGED
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@fulate/vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
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
|
-
},
|
|
12
|
-
"./yoga": {
|
|
13
|
-
"types": "./dist/yoga.d.ts",
|
|
14
|
-
"import": "./dist/yoga.js"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"scripts": {
|
|
22
|
-
"test": "vitest run",
|
|
23
|
-
"test:watch": "vitest"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@fulate/core": "
|
|
27
|
-
"@fulate/ui": "
|
|
28
|
-
"lodash-es": "^4.17.22"
|
|
29
|
-
},
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"vue": "^3.5.0",
|
|
32
|
-
"@fulate/yoga": "
|
|
33
|
-
},
|
|
34
|
-
"peerDependenciesMeta": {
|
|
35
|
-
"@fulate/yoga": {
|
|
36
|
-
"optional": true
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@fulate/vue",
|
|
3
|
+
"version": "3.0.2",
|
|
4
|
+
"type": "module",
|
|
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
|
+
},
|
|
12
|
+
"./yoga": {
|
|
13
|
+
"types": "./dist/yoga.d.ts",
|
|
14
|
+
"import": "./dist/yoga.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@fulate/core": "3.0.2",
|
|
27
|
+
"@fulate/ui": "3.0.2",
|
|
28
|
+
"lodash-es": "^4.17.22"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"vue": "^3.5.0",
|
|
32
|
+
"@fulate/yoga": "^3.0.2"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@fulate/yoga": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|