@iebh/tera-fy 1.0.4 → 1.0.5

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.
@@ -20,7 +20,7 @@ export default class TeraFy {
20
20
  */
21
21
  settings = {
22
22
  devMode: true,
23
- siteUrl: 'http://localhost:5173/embed',
23
+ siteUrl: 'https://tera-tools.com/embed',
24
24
  restrictOrigin: '*', // DEBUG: Need to restrict this to TERA site
25
25
  };
26
26
 
@@ -186,10 +186,10 @@ export default class TeraFy {
186
186
  /**
187
187
  * Setup the TERA-fy client singleton
188
188
  *
189
- * @param {Object} [options] Additional options to merge into `settings`
189
+ * @param {Object} [options] Additional options to merge into `settings` via `set`
190
190
  */
191
191
  constructor(options) {
192
- Object.assign(this.settings, options);
192
+ if (options) this.set(options);
193
193
  }
194
194
 
195
195
 
@@ -309,7 +309,7 @@ export default class TeraFy {
309
309
  }
310
310
  // }}}
311
311
 
312
- // Utility - debug(), use(), toggleFullscreen() {{{
312
+ // Utility - debug(), use(), mixin(), toggleFullscreen() {{{
313
313
 
314
314
  /**
315
315
  * Debugging output function
@@ -359,11 +359,36 @@ export default class TeraFy {
359
359
  if (typeof mod != 'function') throw new Error('Expected use() call to be provided with a class initalizer');
360
360
 
361
361
  let singleton = new mod(this, options);
362
+ this.mixin(this, singleton);
363
+
362
364
  this.plugins.push(singleton);
363
365
  return this;
364
366
  }
365
367
 
366
368
 
369
+ /**
370
+ * Internal function used by use() to merge an external declared singleton against this object
371
+ *
372
+ * @param {Object} target Initalied class instance to extend
373
+ * @param {Object} source Initalized source object to extend from
374
+ */
375
+ mixin(target, source) {
376
+ Object.getOwnPropertyNames(Object.getPrototypeOf(source))
377
+ .filter(prop => !['constructor', 'prototype', 'name'].includes(prop))
378
+ .forEach((prop) => {
379
+ console.log('Merge method', prop);
380
+ Object.defineProperty(
381
+ target,
382
+ prop,
383
+ {
384
+ value: source[prop].bind(target),
385
+ enumerable: false,
386
+ },
387
+ );
388
+ });
389
+ }
390
+
391
+
367
392
  /**
368
393
  * Fit the nested TERA server to a full-screen
369
394
  * This is usually because the server component wants to perform some user activity like calling $prompt
@@ -377,6 +402,5 @@ export default class TeraFy {
377
402
  globalThis.document.body.classList.toggle('tera-fy-focus', isFocused === 'toggle' ? undefined : isFocused);
378
403
  return this;
379
404
  }
380
-
381
405
  // }}}
382
406
  }
package/package.json CHANGED
@@ -1,22 +1,27 @@
1
1
  {
2
2
  "name": "@iebh/tera-fy",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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
9
  "build:docs": "jsdoc2md --files lib/terafy.*.js lib/plugins/*.js >api.md",
10
- "lint": "eslint ./lib"
10
+ "lint": "eslint ."
11
11
  },
12
12
  "type": "module",
13
13
  "imports": {
14
14
  "#terafy": "./lib/terafy.client.js"
15
15
  },
16
16
  "exports": {
17
- ".": "./lib/terafy.client.js",
17
+ ".": {
18
+ "browser": "./lib/terafy.client.js",
19
+ "import": "./lib/terafy.client.js",
20
+ "require": "./dist/terafy.js",
21
+ "default": "./dist/terafy.js"
22
+ },
18
23
  "./server": "./lib/terafy.server.js",
19
- "./plugins/*": "./lib/plugins/*.js"
24
+ "./plugins/*": "./plugins/*.js"
20
25
  },
21
26
  "repository": {
22
27
  "type": "git",
@@ -1,5 +1,5 @@
1
1
  import TeraFyPluginBase from './base.js';
2
- import diff from 'just-diff';
2
+ import {diff} from 'just-diff';
3
3
  import {reactive, watch} from 'vue';
4
4
 
5
5
  /**
@@ -62,4 +62,41 @@ export default class TeraFyPluginVue extends TeraFyPluginBase {
62
62
  })
63
63
  }
64
64
 
65
+
66
+ /**
67
+ * Provide a Vue@3 compatible plugin
68
+ */
69
+ vuePlugin() {
70
+ let context = this;
71
+
72
+ return {
73
+
74
+ /**
75
+ * Install into Vue as a generic Vue@3 plugin
76
+ *
77
+ * @param {Object} [options] Additional options to mutate behaviour
78
+ * @param {String} [options.globalName='$tera'] Globa property to allocate this service as
79
+ * @param {Objecct} [options.bindOptions] Options passed to `bindProjectState()`
80
+ *
81
+ * @returns {VuePlugin} A plugin matching the Vue@3 spec
82
+ */
83
+ install(app, options) {
84
+ let settings = {
85
+ globalName: '$tera',
86
+ stateOptions: {
87
+ autoRequire: true,
88
+ write: true,
89
+ },
90
+ ...options,
91
+ };
92
+
93
+ app.config.globalProperties[settings.globalName] = {
94
+ // Create project binding
95
+ // state: context.bindProjectState(settings.stateOptions),
96
+ };
97
+ },
98
+
99
+ };
100
+ }
101
+
65
102
  }
File without changes