@vyr/vue 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/package.json +22 -0
- package/src/actor/TemplateActor.ts +25 -0
- package/src/actor/VueActor.ts +230 -0
- package/src/actor/index.ts +2 -0
- package/src/descriptor/TemplateDescriptor.ts +15 -0
- package/src/descriptor/VueDescriptor.ts +25 -0
- package/src/descriptor/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/interpreter/TemplateInterpreter.ts +18 -0
- package/src/interpreter/VueInterpreter.ts +45 -0
- package/src/interpreter/index.ts +2 -0
- package/src/locale/Language.ts +10 -0
- package/src/locale/LanguageProvider.ts +15 -0
- package/src/locale/index.ts +2 -0
- package/src/shims-vue.d.ts +5 -0
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vyr/vue",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"author": "",
|
|
7
|
+
"sideEffects": true,
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@vyr/locale": "0.0.1",
|
|
11
|
+
"@vyr/engine": "0.0.1",
|
|
12
|
+
"vue": "3.5.22"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"package.json",
|
|
16
|
+
"src/"
|
|
17
|
+
],
|
|
18
|
+
"vyr": {
|
|
19
|
+
"type": "universal",
|
|
20
|
+
"order": 10
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { h, VNode } from "vue"
|
|
2
|
+
import { Generate } from "@vyr/engine";
|
|
3
|
+
import { VueDescriptor } from "../descriptor";
|
|
4
|
+
import { VueActor, VyrVueChildren, VyrVueInstance } from "./VueActor";
|
|
5
|
+
|
|
6
|
+
class TemplateActor extends VueActor {
|
|
7
|
+
|
|
8
|
+
getWrapper() {
|
|
9
|
+
return null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getWrapperVNode(instance: VyrVueInstance, content: VNode, descriptor: VueDescriptor) {
|
|
13
|
+
return content
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getContent(instance: VyrVueInstance, children: VyrVueChildren, descriptor: VueDescriptor) {
|
|
17
|
+
const component = this.getComponent()
|
|
18
|
+
|
|
19
|
+
return h(component, { style: { display: 'contents' }, key: Generate.uuid() }, this.getSlots(children))
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
TemplateActor
|
|
25
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { App, createApp, h, markRaw, resolveDynamicComponent, VNode, ComponentPublicInstance } from 'vue'
|
|
2
|
+
import { ArrayUtils, Asset, HTMLActor, RoutineDescriptor, RoutineInterpreter, StyleDescriptor, UpdateArgs } from "@vyr/engine"
|
|
3
|
+
import { TemplateDescriptor, VueDescriptor } from "../descriptor"
|
|
4
|
+
|
|
5
|
+
interface VyrVueProps {
|
|
6
|
+
[k: string]: any
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface VyrVueRaw {
|
|
10
|
+
instances: any[]
|
|
11
|
+
app: App | null
|
|
12
|
+
wrapper: HTMLElement | null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface VyrVueInstance extends ComponentPublicInstance {
|
|
16
|
+
actor: VueActor
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface VyrVueChildren {
|
|
20
|
+
[k: string]: (slot?: any) => (VNode | VNode[])
|
|
21
|
+
default: (slot?: any) => (VNode[])
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class VueActor extends HTMLActor {
|
|
25
|
+
readonly children: VueActor[] = []
|
|
26
|
+
style: { [k: string]: any } = {}
|
|
27
|
+
props: VyrVueProps = {}
|
|
28
|
+
raw: VyrVueRaw = markRaw({
|
|
29
|
+
instances: [],
|
|
30
|
+
app: null,
|
|
31
|
+
wrapper: null,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
add(actor: VueActor) {
|
|
35
|
+
if (actor instanceof VueActor) {
|
|
36
|
+
ArrayUtils.insert(this.children, actor)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
remove(actor: VueActor) {
|
|
41
|
+
if (actor instanceof VueActor) {
|
|
42
|
+
ArrayUtils.remove(this.children, actor)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getWrapper(): HTMLElement | null {
|
|
47
|
+
if (this.raw.instances.length > 1) {
|
|
48
|
+
return null
|
|
49
|
+
} else if (this.raw.instances.length === 1) {
|
|
50
|
+
return this.raw.instances[0].$el
|
|
51
|
+
} else {
|
|
52
|
+
const graphics = HTMLActor.getGraphics(this)
|
|
53
|
+
const parent = graphics.getParent(this.uuid)
|
|
54
|
+
if (parent instanceof VueDescriptor) return null
|
|
55
|
+
const descriptor = graphics.variableProxy.get<VueDescriptor>(this.uuid, graphics, { delta: 0 })
|
|
56
|
+
const vnode = this.createVNode(descriptor)
|
|
57
|
+
this.raw.app = markRaw(createApp(vnode, { actor: this }))
|
|
58
|
+
const plugins = VueDescriptor.getPlugins()
|
|
59
|
+
for (const plugin of plugins) {
|
|
60
|
+
let args = plugin.args
|
|
61
|
+
if (typeof plugin.args === 'function') {
|
|
62
|
+
args = plugin.args()
|
|
63
|
+
}
|
|
64
|
+
this.raw.app.use(plugin.content, args)
|
|
65
|
+
}
|
|
66
|
+
const component = this.raw.app.mount(document.createElement('div'))
|
|
67
|
+
return component.$el
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
update(descriptor: VueDescriptor, args: UpdateArgs) {
|
|
72
|
+
this.style = this.getWrapperStyle(descriptor, args)
|
|
73
|
+
this.props = this.getProps(descriptor, args)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
dispose() {
|
|
77
|
+
this.cleanInteraction()
|
|
78
|
+
if (this.raw.app === null) return
|
|
79
|
+
this.raw.app.unmount()
|
|
80
|
+
this.raw.app = null
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
createVNode(descriptor: VueDescriptor) {
|
|
84
|
+
const self = this
|
|
85
|
+
const vnode = {
|
|
86
|
+
props: ['actor'],
|
|
87
|
+
setup() {
|
|
88
|
+
const VYR_STORE = {}
|
|
89
|
+
|
|
90
|
+
return { VYR_STORE }
|
|
91
|
+
},
|
|
92
|
+
render() {
|
|
93
|
+
const _instance = this as VyrVueInstance
|
|
94
|
+
const children = self.getChildren(_instance, { delta: 0 })
|
|
95
|
+
const content = _instance.actor.getContent(_instance, children, descriptor)
|
|
96
|
+
|
|
97
|
+
return self.getWrapperVNode(this as any, content, descriptor)
|
|
98
|
+
},
|
|
99
|
+
mounted() {
|
|
100
|
+
//@ts-ignore
|
|
101
|
+
ArrayUtils.insert(this.actor.raw.instances, this)
|
|
102
|
+
},
|
|
103
|
+
beforeUnmount() {
|
|
104
|
+
//@ts-ignore
|
|
105
|
+
ArrayUtils.remove(this.actor.raw.instances, this)
|
|
106
|
+
},
|
|
107
|
+
} as unknown as VyrVueInstance
|
|
108
|
+
|
|
109
|
+
return vnode as unknown as VNode
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getChildren(instance: VyrVueInstance, args: UpdateArgs) {
|
|
113
|
+
const { actor } = instance
|
|
114
|
+
|
|
115
|
+
const _default: VNode[] = []
|
|
116
|
+
const slots: VyrVueChildren = {
|
|
117
|
+
default: () => _default,
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (Array.isArray(actor.children) === false) return slots
|
|
121
|
+
|
|
122
|
+
const graphics = HTMLActor.getGraphics(actor)
|
|
123
|
+
|
|
124
|
+
for (let i = 0; i < actor.children.length; i++) {
|
|
125
|
+
const attr = { key: i, actor: actor.children[i] }
|
|
126
|
+
const descriptor = graphics.variableProxy.get<VueDescriptor>(attr.actor.uuid, graphics, args)
|
|
127
|
+
const component = attr.actor.createVNode(descriptor)
|
|
128
|
+
|
|
129
|
+
if (descriptor instanceof TemplateDescriptor) {
|
|
130
|
+
if (descriptor.slotName) {
|
|
131
|
+
const slot = h(component, attr)
|
|
132
|
+
slots[descriptor.slotName] = () => slot
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
_default.push(h(component, attr))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return slots
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getWrapperAttrs(instance: VyrVueInstance) {
|
|
143
|
+
const attrs = {
|
|
144
|
+
class: HTMLActor.className,
|
|
145
|
+
[HTMLActor.uuidKey]: instance.actor.uuid,
|
|
146
|
+
style: instance.actor.style,
|
|
147
|
+
}
|
|
148
|
+
return attrs
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getWrapperVNode(instance: VyrVueInstance, content: VNode, descriptor: VueDescriptor) {
|
|
152
|
+
const attrs = this.getWrapperAttrs(instance)
|
|
153
|
+
|
|
154
|
+
return h('div', attrs, [content])
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
getContent(instance: VyrVueInstance, children: VyrVueChildren, descriptor: VueDescriptor) {
|
|
158
|
+
const component = this.getComponent()
|
|
159
|
+
|
|
160
|
+
const attrs = this.getComponentAttrs(instance, descriptor)
|
|
161
|
+
|
|
162
|
+
return h(component, attrs, children)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getProps(descriptor: VueDescriptor, args: UpdateArgs) {
|
|
166
|
+
return {}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getInteractionProps(descriptor: VueDescriptor, instance: VyrVueInstance, args: UpdateArgs) {
|
|
170
|
+
const interactions: { [k: string]: any } = {}
|
|
171
|
+
const graphics = HTMLActor.getGraphics(this)
|
|
172
|
+
//@ts-ignore
|
|
173
|
+
const eventArgs = { ...args, trigger: descriptor, VYR_STORE: instance.VYR_STORE }
|
|
174
|
+
for (const interaction of descriptor.interactions) {
|
|
175
|
+
if (interaction.url) {
|
|
176
|
+
const routine = Asset.get<RoutineDescriptor>(interaction.url)
|
|
177
|
+
const interpreter = graphics.getInterpreter<RoutineInterpreter>(routine)
|
|
178
|
+
const listener = (e: Event) => {
|
|
179
|
+
if (e instanceof Event) e.stopPropagation()
|
|
180
|
+
interpreter.do(interaction.inputs, routine, eventArgs)
|
|
181
|
+
}
|
|
182
|
+
const eventKey = 'on' + interaction.type.charAt(0).toUpperCase() + interaction.type.slice(1)
|
|
183
|
+
interactions[eventKey] = listener
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return interactions
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
getComponent() {
|
|
190
|
+
return resolveDynamicComponent('div') as VNode
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
getComponentAttrs(instance: VyrVueInstance, descriptor: VueDescriptor, ...args: any[]) {
|
|
194
|
+
const className = [...this.getStyleClass(descriptor, { delta: 0 })]
|
|
195
|
+
if (descriptor.active) className.push(StyleDescriptor.activeName)
|
|
196
|
+
const interactions = this.getInteractionProps(descriptor, instance, { delta: 0 })
|
|
197
|
+
|
|
198
|
+
const attrs = {
|
|
199
|
+
...this.props,
|
|
200
|
+
...interactions,
|
|
201
|
+
class: className,
|
|
202
|
+
[HTMLActor.uuidKey]: this.uuid,
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return attrs
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
getSlots(children: VyrVueChildren) {
|
|
209
|
+
//@ts-ignore
|
|
210
|
+
const slots: VyrVueChildren = {}
|
|
211
|
+
const keys = Object.keys(children)
|
|
212
|
+
for (const key of keys) {
|
|
213
|
+
const value = children[key]()
|
|
214
|
+
const values = Array.isArray(value) ? value : [value]
|
|
215
|
+
slots[key] = function (slot: any) {
|
|
216
|
+
return values.map(child => h(child, {
|
|
217
|
+
onVnodeMounted(vnode) {
|
|
218
|
+
if (!vnode.component) return
|
|
219
|
+
//@ts-ignore
|
|
220
|
+
Object.assign(vnode.component.setupState['VYR_STORE'], { slot })
|
|
221
|
+
}
|
|
222
|
+
}))
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return slots
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export { VyrVueProps, VyrVueChildren, VyrVueInstance, VueActor }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DeserializationObject } from "@vyr/engine"
|
|
2
|
+
import { VueDescriptor } from "./VueDescriptor"
|
|
3
|
+
|
|
4
|
+
class TemplateDescriptor extends VueDescriptor {
|
|
5
|
+
static type = 'Template'
|
|
6
|
+
slotName: string
|
|
7
|
+
|
|
8
|
+
constructor(descriptor: Partial<DeserializationObject<TemplateDescriptor>> = {}) {
|
|
9
|
+
super(descriptor)
|
|
10
|
+
this.slotName = descriptor.slotName ?? 'default'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
VueDescriptor.register(TemplateDescriptor)
|
|
14
|
+
|
|
15
|
+
export { TemplateDescriptor }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Plugin } from "vue";
|
|
2
|
+
import { DeserializationObject, HTMLDescriptor } from "@vyr/engine";
|
|
3
|
+
|
|
4
|
+
const privateState = {
|
|
5
|
+
plugins: [] as { content: Plugin, args?: any }[],
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class VueDescriptor extends HTMLDescriptor {
|
|
9
|
+
static use(content: Plugin, args?: any) {
|
|
10
|
+
privateState.plugins.push({ content, args })
|
|
11
|
+
}
|
|
12
|
+
static getPlugins() {
|
|
13
|
+
return [...privateState.plugins]
|
|
14
|
+
}
|
|
15
|
+
static type = 'Vue'
|
|
16
|
+
|
|
17
|
+
constructor(descriptor: Partial<DeserializationObject<VueDescriptor>> = {}) {
|
|
18
|
+
super(descriptor)
|
|
19
|
+
this.width = descriptor.width ?? -1
|
|
20
|
+
this.height = descriptor.height ?? -1
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
HTMLDescriptor.register(VueDescriptor)
|
|
24
|
+
|
|
25
|
+
export { VueDescriptor }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { reactive } from "vue";
|
|
2
|
+
import { UpdateArgs } from "@vyr/engine";
|
|
3
|
+
import { TemplateDescriptor } from "../descriptor";
|
|
4
|
+
import { TemplateActor } from "../actor";
|
|
5
|
+
import { VueInterpreter } from "./VueInterpreter";
|
|
6
|
+
|
|
7
|
+
class TemplateInterpreter extends VueInterpreter {
|
|
8
|
+
static type = TemplateDescriptor.type
|
|
9
|
+
|
|
10
|
+
protected createActor(descriptor: TemplateDescriptor, args: UpdateArgs) {
|
|
11
|
+
return reactive(new TemplateActor(descriptor.uuid)) as TemplateActor
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
VueInterpreter.register(TemplateInterpreter)
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
TemplateInterpreter
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { reactive } from 'vue'
|
|
2
|
+
import { Descriptor, HTMLActor, Interpreter, PickupObject, UpdateArgs } from '@vyr/engine'
|
|
3
|
+
import { VueDescriptor } from '../descriptor'
|
|
4
|
+
import { VueActor } from '../actor'
|
|
5
|
+
|
|
6
|
+
class VueInterpreter extends Interpreter {
|
|
7
|
+
static type = VueDescriptor.type
|
|
8
|
+
|
|
9
|
+
protected createActor(descriptor: VueDescriptor, args: UpdateArgs) {
|
|
10
|
+
return reactive(new VueActor(descriptor.uuid)) as VueActor
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
update(descriptor: VueDescriptor, args: UpdateArgs) {
|
|
14
|
+
super.update(descriptor, args)
|
|
15
|
+
const actor = this.getActor<VueActor>(descriptor, args)
|
|
16
|
+
actor.update(descriptor, args)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
mount(descriptor: VueDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
20
|
+
super.mount(descriptor, args, parentInterpreter, parentDescriptor)
|
|
21
|
+
const actor = this.getActor<VueActor>(descriptor, args)
|
|
22
|
+
const parentActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor, args)
|
|
23
|
+
parentActor.add(actor)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
unmount(descriptor: VueDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
|
|
27
|
+
const actor = this.getActor<VueActor>(descriptor, args)
|
|
28
|
+
const parentActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor, args)
|
|
29
|
+
parentActor.remove(actor)
|
|
30
|
+
super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
free(descriptor: VueDescriptor, args: UpdateArgs) {
|
|
34
|
+
const actor = this.getActor<VueActor>(descriptor, args)
|
|
35
|
+
actor.dispose()
|
|
36
|
+
super.free(descriptor, args)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pickup(descriptor: VueDescriptor, args: UpdateArgs, result: PickupObject[]) {
|
|
40
|
+
result.push({ uuid: descriptor.uuid, generatedBy: descriptor.generatedBy })
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
Interpreter.register(VueInterpreter)
|
|
44
|
+
|
|
45
|
+
export { VueInterpreter }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Locale } from "@vyr/locale";
|
|
2
|
+
import { zhCnLanguageProvider, ZhCNLanguageProvider } from "./LanguageProvider";
|
|
3
|
+
|
|
4
|
+
Locale.register(zhCnLanguageProvider)
|
|
5
|
+
|
|
6
|
+
const language = Locale.getLanguage<ZhCNLanguageProvider>(zhCnLanguageProvider.name)
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
language
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LanguageProvider } from '@vyr/locale'
|
|
2
|
+
|
|
3
|
+
interface ZhCNLanguageProvider extends LanguageProvider {
|
|
4
|
+
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const zhCnLanguageProvider: ZhCNLanguageProvider = {
|
|
8
|
+
id: 'zh_CN',
|
|
9
|
+
name: '@vyr/vue',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
ZhCNLanguageProvider,
|
|
14
|
+
zhCnLanguageProvider,
|
|
15
|
+
}
|