@knowlearning/agents 0.0.8 → 0.0.9

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.
@@ -1,4 +1,5 @@
1
1
  // TODO: export browser, node, deno, and generic agents
2
2
  export { default as BrowserAgent } from '../agents/browser/embedded.js'
3
3
  export { default as GenericAgent } from '../agents/generic.js'
4
- export { default as createPersistentVuexStore } from '../persistence/vuex.js'
4
+ export { default as vuexCreatePersistentStore } from '../persistence/vuex.js'
5
+ export { default as vueContentComponent } from '../vue/3/content.vue'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "package/node.js",
6
6
  "browser": "package/browser.js",
@@ -0,0 +1,58 @@
1
+ import { createApp, watchEffect } from 'npm/unscoped/vue/3.2.39'
2
+ import content from "./content.vue"
3
+
4
+ // TODO: probably want to make this a util, and better fleshed out (with white instead of blacklist)
5
+ function isScopeSerializable(v) {
6
+ return !(
7
+ v instanceof HTMLElement
8
+ )
9
+ }
10
+
11
+ export default async function (module) {
12
+ const component = { ...module.default } // copy component since we will mess with mounted and data functions
13
+
14
+ if (!component.ephemeral) {
15
+ const state = await Agent.mutate()
16
+
17
+ if (component.data) {
18
+ const origDataFn = component.data
19
+ component.data = function dataProxy() {
20
+ if (Object.keys(state).length === 0) {
21
+ const startState = origDataFn.apply(this, arguments)
22
+ Object.assign(state, startState)
23
+ }
24
+ return state
25
+ }
26
+ }
27
+ else if (component.setup) {
28
+ const origSetupFn = component.setup
29
+ const isReactiveRef = r => r && r.__v_isRef
30
+ component.setup = function setupProxy(a, b) { // need to specifically add this here, otherwise second argument not passed in arguments array (probably because of webpack optimization...)
31
+ const refs = origSetupFn.call(this, a, b)
32
+ if (state) {
33
+ Object
34
+ .entries(state)
35
+ .filter(([k]) => isReactiveRef(refs[k]))
36
+ .forEach(([k, v]) => refs[k].value = v)
37
+ }
38
+ watchEffect(() => {
39
+ interact(
40
+ Object
41
+ .entries(refs)
42
+ .filter(([_,r]) => isReactiveRef(r) && isScopeSerializable(r.value) )
43
+ .reduce((acc, [key, ref]) => {
44
+ acc[key] = ref.value
45
+ return acc
46
+ }, {})
47
+ )
48
+ })
49
+ return refs
50
+ }
51
+ }
52
+ }
53
+
54
+ document.body.innerHTML = ''
55
+ const app = createApp(component)
56
+ app.component('Content', content)
57
+ app.mount(document.body)
58
+ }
@@ -0,0 +1,55 @@
1
+ <template>
2
+ <iframe
3
+ :ref="el => setup(el)"
4
+ class="wrapper"
5
+ allow="camera;microphone"
6
+ />
7
+ </template>
8
+
9
+ <script>
10
+ export default {
11
+ props: {
12
+ id: {
13
+ type: String,
14
+ required: true
15
+ },
16
+ scope: {
17
+ type: String,
18
+ required: false
19
+ }
20
+ },
21
+ unmounted() {
22
+ if (this.experience) this.experience.remove()
23
+ },
24
+ methods: {
25
+ setup(iframe) {
26
+ if (!iframe || this.iframe === iframe) return
27
+
28
+ const { id, scope } = this
29
+ this.iframe = iframe
30
+ this.experience = new Agent.Experience({ content: id, scope }, iframe)
31
+
32
+ /*
33
+ const { handle } = this.experience
34
+ // if save or edit are listened to, attach handler
35
+ if (this.$attrs.onSave) {
36
+ handle('save', () => new Promise((resolve, reject) => this.$emit('save', { resolve, reject })))
37
+ }
38
+ if (this.$attrs.onEdit) handle('edit', () => this.$emit('edit'))
39
+ */
40
+ }
41
+ }
42
+ }
43
+
44
+ </script>
45
+
46
+ <style scoped>
47
+
48
+ .wrapper
49
+ {
50
+ width: 100%;
51
+ height: 100%;
52
+ border: none;
53
+ }
54
+
55
+ </style>