@iebh/tera-fy 1.0.12 → 1.0.13

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.
@@ -21,6 +21,7 @@ export default class TeraFy {
21
21
  * @property {Number} modeTimeout How long entities have in 'detect' mode to identify themselves
22
22
  * @property {String} siteUrl The TERA URL to connect to
23
23
  * @property {String} restrictOrigin URL to restrict communications to
24
+ * @property {Array<String>} List of sandbox allowables for the embedded if in embed mode
24
25
  */
25
26
  settings = {
26
27
  devMode: true,
@@ -28,6 +29,18 @@ export default class TeraFy {
28
29
  modeTimeout: 300,
29
30
  siteUrl: 'https://tera-tools.com/embed',
30
31
  restrictOrigin: '*', // FIXME: Need to restrict this to TERA site
32
+ frameSandbox: [
33
+ 'allow-forms',
34
+ 'allow-modals',
35
+ 'allow-orientation-lock',
36
+ 'allow-pointer-lock',
37
+ 'allow-popups',
38
+ 'allow-popups-to-escape-sandbox',
39
+ 'allow-presentation',
40
+ 'allow-same-origin',
41
+ 'allow-scripts',
42
+ 'allow-top-navigation'
43
+ ],
31
44
  };
32
45
 
33
46
 
@@ -294,7 +307,7 @@ export default class TeraFy {
294
307
  ))
295
308
  .then(()=> Promise.all( // Init all plugins (with this outer module as the context)
296
309
  this.plugins.map(plugin =>
297
- plugin.init.call(context)
310
+ plugin.init.call(context, this.settings)
298
311
  )
299
312
  ))
300
313
  }
@@ -346,7 +359,7 @@ export default class TeraFy {
346
359
  this.dom.iframe = document.createElement('iframe')
347
360
 
348
361
  // Queue up event chain when document loads
349
- this.dom.iframe.setAttribute('sandbox', 'allow-downloads allow-scripts allow-same-origin');
362
+ this.dom.iframe.setAttribute('sandbox', this.settings.frameSandbox.join(' '));
350
363
  this.dom.iframe.addEventListener('load', ()=> {
351
364
  this.debug('Embed frame ready');
352
365
  resolve();
@@ -504,7 +517,7 @@ export default class TeraFy {
504
517
  * Include a TeraFy client plugin
505
518
  *
506
519
  * @param {Object} The module function to include. Invoked as `(teraClient:TeraFy, options:Object)`
507
- * @param {Object} [options] Additional options to mutate behaviour
520
+ * @param {Object} [options] Additional options to mutate behaviour during construction (pass options to init() to intialize later options)
508
521
  *
509
522
  * @returns {TeraFy} This chainable terafy instance
510
523
  */
@@ -94,9 +94,8 @@ export default class TeraFyServer {
94
94
  });
95
95
  case TeraFyServer.SERVERMODE_WINDOW:
96
96
  // Server is the top-level window so we need to send messages to an embedded iFrame
97
- debugger; // FIXME: THIS IS ALL UNTESTED
98
- var iFrame = document.querySelector('iframe#tera-fy');
99
- if (!iFrame) throw new Error('Cannot locate TERA-FY client iFrame');
97
+ var iFrame = document.querySelector('iframe#external');
98
+ if (!iFrame) throw new Error('Cannot locate TERA-FY top-level->iFrame#external');
100
99
 
101
100
  return mixin(this, {
102
101
  sendRaw(message) {
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@iebh/tera-fy",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "TERA website worker",
5
5
  "scripts": {
6
6
  "dev": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.js --outfile=dist/terafy.js --minify --sourcemap --serve --servedir=.",
7
7
  "build": "concurrently 'npm:build:*'",
8
8
  "build:client": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.js --outfile=dist/terafy.js --minify --sourcemap",
9
+ "build:client:es2019": "esbuild --platform=browser --format=esm --target=es2019 --bundle lib/terafy.client.js --outfile=dist/terafy.es2019.js --minify --sourcemap",
10
+ "build:plugins-vue2:es2019": "esbuild --platform=browser --format=esm --target=es2019 --bundle plugins/vue2.js --outfile=dist/plugin.vue2.es2019.js --minify --sourcemap",
9
11
  "build:docs:api": "documentation build lib/terafy.client.js --format html --config documentation.yml --output docs/",
10
12
  "build:docs:markdown": "documentation build lib/terafy.client.js --format md --markdown-toc --output api.md",
11
13
  "lint": "eslint ."
package/plugins/vue2.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import {cloneDeep} from 'lodash-es';
2
2
  import TeraFyPluginBase from './base.js';
3
- import Vue from 'vue';
4
3
 
5
4
  /**
6
5
  * Vue2 observables plugin
@@ -9,6 +8,8 @@ import Vue from 'vue';
9
8
  * This function is expected to be included via the `terafy.use(MODULE, OPTIONS)` syntax rather than directly
10
9
  *
11
10
  * @class TeraFyPluginVue
11
+ * @param {Object} options Options when initalizing
12
+ * @param {Vue} options.Vue Vue instance to bind against
12
13
  *
13
14
  * @example Implementation within a Vue2 project `src/main.js`:
14
15
  * // Include the main Tera-Fy core
@@ -17,7 +18,9 @@ import Vue from 'vue';
17
18
  * let terafy = new TeraFy()
18
19
  * .set('devMode', true) // Uncomment this line if you want TeraFy to be chatty
19
20
  * .set('siteUrl', 'http://localhost:8000/embed') // Uncomment this line if running TERA locally
20
- * .use(TerafyVue) // Add the Vue plugin
21
+ * .use(TerafyVue, { // Add the Vue plugin
22
+ * vue: window.Vue, // Assumes Vue is available on the window object
23
+ * })
21
24
  *
22
25
  * // Include after app boot
23
26
  * const app = new Vue({ ... })
@@ -26,6 +29,13 @@ import Vue from 'vue';
26
29
  */
27
30
  export default class TeraFyPluginVue2 extends TeraFyPluginBase {
28
31
 
32
+ /**
33
+ * Local Vue@2 library to use, set during constuctor
34
+ * @type {Vue}
35
+ */
36
+ Vue;
37
+
38
+
29
39
  /**
30
40
  * Return a Vue Observable object that can be read/written which whose changes will transparently be written back to the TERA server instance
31
41
  *
@@ -72,7 +82,7 @@ export default class TeraFyPluginVue2 extends TeraFyPluginBase {
72
82
  this.debug('Got project snapshot', snapshot);
73
83
 
74
84
  // Create initial Observable
75
- let stateObservable = Vue.observable(snapshot);
85
+ let stateObservable = this.Vue.observable(snapshot);
76
86
 
77
87
  // Allocate to component
78
88
  settings.component[settings.componentKey] = stateObservable;
@@ -80,9 +90,9 @@ export default class TeraFyPluginVue2 extends TeraFyPluginBase {
80
90
  // Watch for remote changes and update
81
91
  let skipUpdate = 0; // How many subsequent WRITE operations to ignore (set when reading)
82
92
  if (settings.read) {
83
- this.events.on(`update:projects/${stateReactive.id}`, newState => {
93
+ this.events.on(`update:projects/${stateObservable.id}`, newState => {
84
94
  skipUpdate++; // Skip next update as we're updating our own state anyway
85
- Object.assign(stateReactive, newState);
95
+ Object.assign(stateObservable, newState);
86
96
  });
87
97
  }
88
98
 
@@ -120,9 +130,10 @@ export default class TeraFyPluginVue2 extends TeraFyPluginBase {
120
130
 
121
131
  /**
122
132
  * List of available projects for the current session
133
+ * Initalized during constructor
123
134
  * @type {VueReactive<Array<Object>>}
124
135
  */
125
- projects = Vue.observable([]);
136
+ projects;
126
137
 
127
138
 
128
139
  /**
@@ -136,7 +147,9 @@ export default class TeraFyPluginVue2 extends TeraFyPluginBase {
136
147
  /**
137
148
  * Install into Vue@2
138
149
  *
139
- * @param {Object} [options] Additional options to mutate behaviour (defaults to the main teraFy settings)
150
+ * @param {Object} options Additional options to mutate behaviour (defaults to the main teraFy settings)
151
+ * @param {Object} options.app Root level Vue app to bind against
152
+ * @param {Vue} options.Vue Vue@2 instance to bind against
140
153
  * @param {String} [options.globalName='$tera'] Global property to allocate this service as within Vue2
141
154
  * @param {Boolean} [options.subscribeState=true] Setup `vm.$tera.state` as a live binding on init
142
155
  * @param {Boolean} [options.subscribeList=true] Setup `vm.$tera.projects` as a list of accesible projects on init
@@ -146,20 +159,30 @@ export default class TeraFyPluginVue2 extends TeraFyPluginBase {
146
159
  */
147
160
  init(options) {
148
161
  let settings = {
162
+ app: null,
163
+ Vue: null,
149
164
  globalName: '$tera',
150
165
  subscribeState: true,
151
166
  subscribeProjects: true,
152
167
  stateOptions: {
168
+ read: true,
153
169
  write: true,
154
170
  },
155
171
  ...options,
156
172
  };
173
+
174
+ if (!settings.Vue) throw new Error('Vue instance to use must be specified in init options as `Vue`');
175
+ this.Vue = options.Vue;
176
+
157
177
  if (!this.settings.app) throw new Error('Need to specify the root level Vue2 app during init');
158
178
  settings.stateOptions.app = this.settings.app;
159
179
 
180
+ // Create observable binding for projects
181
+ this.projects = this.Vue.observable([])
182
+
160
183
  // Make this module available globally
161
184
  if (settings.globalName)
162
- Vue.prototype[settings.globalName] = this;
185
+ this.Vue.prototype[settings.globalName] = this;
163
186
 
164
187
  // Bind `state` to the active project
165
188
  // Initialize state to null
@@ -178,7 +201,7 @@ export default class TeraFyPluginVue2 extends TeraFyPluginBase {
178
201
 
179
202
  // Fetch available projects
180
203
  settings.subscribeProjects && this.getProjects()
181
- .then(projects => this.projects = Vue.observable(projects))
204
+ .then(projects => this.projects = this.Vue.observable(projects))
182
205
  .then(()=> this.debug('INFO', 'Loaded projects', this.projects)),
183
206
  ]))
184
207
  }