@web-applets/sdk 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -52,11 +52,11 @@ Now let's build out a basic web applet that will say hello when we send it an ac
52
52
  </html>
53
53
  ```
54
54
 
55
- Let's add some Web Applets functionality, so this can respond to a `set_name` action:
55
+ Let's add some Web Applets functionality, so this can respond to a `set_name` action. You can do this by adding actions that a model can call, with each on accepting a parameters object that we can describe using JSONSchema.
56
56
 
57
57
  `public/manifest.json`:
58
58
 
59
- ```json
59
+ ```js
60
60
  {
61
61
  // ...
62
62
  "actions": [
@@ -69,7 +69,8 @@ Let's add some Web Applets functionality, so this can respond to a `set_name` ac
69
69
  "name": {
70
70
  "type": "string"
71
71
  }
72
- }
72
+ },
73
+ "required": ["name"]
73
74
  }
74
75
  }
75
76
  ]
@@ -84,7 +85,7 @@ import { applets } from '@web-applets/sdk';
84
85
  const context = applets.getContext();
85
86
 
86
87
  // Define a 'set_name' action, and make it update the shared data object with the new name
87
- context.addActionHandler('set_name', ({ name }) => {
88
+ context.setActionHandler('set_name', ({ name }) => {
88
89
  context.data = { name };
89
90
  });
90
91
 
@@ -71,13 +71,14 @@ export class AppletFrame extends HTMLElement {
71
71
  }
72
72
  }
73
73
  resizeContainer(dimensions) {
74
- this.container.style.height = `${dimensions.height + 2}px`;
74
+ this.style.height = `${dimensions.height}px`;
75
75
  }
76
76
  get styles() {
77
77
  return /*css*/ `
78
78
  :host {
79
79
  display: flex;
80
80
  flex-direction: column;
81
+ height: 350px;
81
82
  }
82
83
 
83
84
  iframe {
@@ -42,7 +42,7 @@ export async function load(url, container
42
42
  // } else {
43
43
  // container.setAttribute('sandbox', 'allow-scripts allow-forms');
44
44
  // }
45
- container.setAttribute('sandbox', 'allow-scripts allow-forms');
45
+ container.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin');
46
46
  container.src = url;
47
47
  const applet = new Applet(manifest, container.contentWindow);
48
48
  return new Promise((resolve) => {
@@ -32,7 +32,6 @@ export class AppletContext extends EventTarget {
32
32
  // Document not yet loaded, we'll add an event listener to call when it does
33
33
  window.addEventListener('DOMContentLoaded', this.initialize.bind(this));
34
34
  }
35
- this.createResizeObserver();
36
35
  this.attachListeners();
37
36
  }
38
37
  async initialize() {
@@ -60,6 +59,7 @@ export class AppletContext extends EventTarget {
60
59
  this.dispatchEvent(readyEvent);
61
60
  if (typeof this.onready === 'function')
62
61
  this.onready(readyEvent);
62
+ this.createResizeObserver();
63
63
  }
64
64
  createResizeObserver() {
65
65
  const resizeObserver = new ResizeObserver((entries) => {
@@ -50,6 +50,8 @@ export class AppletMessageRelay {
50
50
  return;
51
51
  if (messageEvent.data.type !== messageType)
52
52
  return;
53
+ if (messageEvent.source !== this.target)
54
+ return;
53
55
  const message = new AppletMessage(messageEvent.data.type, messageEvent.data);
54
56
  // Wait for the callback to complete, then send a 'resolve' event
55
57
  // with the message ID.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web-applets/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "The Web Applets SDK, for creating & hosting Web Applets.",
5
5
  "author": "Rupert Manfredi <rupert@unternet.co>",
6
6
  "license": "MIT",
@@ -23,9 +23,5 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "^5.6.2"
26
- },
27
- "dependencies": {
28
- "marked": "^14.1.3",
29
- "vite": "^5.4.7"
30
26
  }
31
27
  }