@avs/go 0.13.71874 → 0.14.71999

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.
@@ -18,126 +18,134 @@
18
18
  * Advanced Visual Systems Inc. (http://www.avs.com)
19
19
  */
20
20
 
21
- import {PolymerElement, html} from '@polymer/polymer/polymer-element.js';
22
- import '@polymer/polymer/lib/elements/dom-repeat.js';
23
- import {afterNextRender} from '@polymer/polymer/lib/utils/render-status.js';
24
- import {AvsHttpMixin} from './avs-http-mixin.js';
25
- import {AvsDataSourceMixin} from './avs-data-source-mixin.js';
21
+ import { AvsElementBase } from './avs-element-base.js';
22
+ import { html } from 'lit';
23
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
24
+ import DOMPurify from 'dompurify';
26
25
 
27
26
  /**
28
- * `avs-go-dynamic-html` is a Polymer 3.0 element which requests HTML by instancing
27
+ * `avs-go-dynamic-html` is a Lit element which requests HTML by instancing
29
28
  * the `dynamicHtmlName` class on the AVS/Go server application running at `url`.
30
29
  * The HTML response is inserted into this element's shadow DOM.
31
30
  *
32
31
  * @customElement
33
- * @polymer
34
- * @appliesMixin AvsHttpMixin
35
- * @appliesMixin AvsDataSourceMixin
32
+ * @lit
36
33
  */
37
- export class AvsGoDynamicHtml extends AvsDataSourceMixin(AvsHttpMixin(PolymerElement)) {
34
+ export class AvsGoDynamicHtml extends AvsElementBase {
35
+ static properties = {
36
+ /**
37
+ * The URL to an instance of AVS/Go server application.
38
+ */
39
+ url: {
40
+ type: String
41
+ },
38
42
 
39
- static get template() {
40
- return html`
41
- <template is="dom-repeat" items="{{linkCss}}">
42
- <link rel="stylesheet" href="[[item]]">
43
- </template>
44
- <style>
45
- #htmlDiv {
46
- width: 100%;
47
- height: 100%;
48
- position: relative;
49
- }
50
- </style>
51
- <div id="htmlDiv"></div>
52
- `;
53
- }
43
+ /**
44
+ * Name of the data source registered in the library map on the server.
45
+ */
46
+ dataSourceName: {
47
+ type: String,
48
+ attribute: 'data-source-name'
49
+ },
54
50
 
55
- static get properties() {
56
- return {
57
- /**
58
- * The URL to an instance of AVS/Go server application.
59
- */
60
- url: {
61
- type: String
62
- },
63
- /**
64
- * An array of strings specifying CSS files for use in the dynamic html.
65
- */
66
- linkCss: {
67
- type: Array,
68
- value: function () {
69
- return [];
70
- }
71
- },
72
- /**
73
- * The name of the dynamic html registered in the library map on the server.
74
- */
75
- dynamicHtmlName: {
76
- type: String
77
- },
78
- /**
79
- * User properties passed directly to the server.
80
- */
81
- dynamicHtmlUserProperties: {
82
- type: Object,
83
- value: {}
84
- }
85
- }
86
- }
51
+ /**
52
+ * User properties as JSON passed directly to the data source on the server.
53
+ */
54
+ dataSourceUserProperties: {
55
+ type: String,
56
+ attribute: 'data-source-user-properties'
57
+ },
87
58
 
88
- /**
89
- * Assemble the model from our properties to send to the server.
90
- */
91
- _assembleModel() {
92
- if (this.dynamicHtmlName === undefined) {
93
- this._logError( JSON.stringify( {"GoType":1, "error":"\'dynamic-html-name\' property must be set to the name of the dynamic html registered in the library map on the server."} ) );
94
- return undefined;
95
- }
59
+ /**
60
+ * The name of the dynamic html registered in the library map on the server.
61
+ */
62
+ dynamicHtmlName: {
63
+ type: String,
64
+ attribute: 'dynamic-html-name'
65
+ },
96
66
 
97
- var model = {dynamicHtmlProperties:{}};
67
+ /**
68
+ * User properties as JSON passed directly to the dynamic html on the server.
69
+ */
70
+ dynamicHtmlUserProperties: {
71
+ type: String,
72
+ attribute: 'dynamic-html-user-properties'
73
+ },
98
74
 
99
- model.dynamicHtmlProperties.name = this.dynamicHtmlName;
100
- if (this.dynamicHtmlUserProperties !== undefined) {
101
- model.dynamicHtmlProperties.userProperties = this.dynamicHtmlUserProperties;
75
+ _html: {
76
+ state: true
102
77
  }
103
-
104
- this._addDataSourceProperties(model);
105
-
106
- return model;
107
78
  }
108
79
 
109
- /**
110
- * HTTP error handler.
111
- * @param event
112
- */
113
- _handleHttpError(event) {
114
-
80
+ render() {
81
+ return html`${unsafeHTML(this._html)}`;
115
82
  }
116
83
 
117
- /**
118
- * HTTP response handler.
119
- * @param json JSON parsed from HTTP response.
120
- */
121
- _handleHttpResponse(json) {
122
- if (json.html !== undefined) {
123
- this.$.htmlDiv.innerHTML = decodeURIComponent(json.html.replace(/\+/g, '%20'));
124
- }
125
- }
84
+ willUpdate(changedProperties) {
85
+ if (!this.url) {
86
+ if (changedProperties.has('url')) {
87
+ this._dispatchErrorEvent("'url' property must be set to an instance of AVS/Go server.");
88
+ }
89
+ return;
90
+ }
91
+ if (!this.dynamicHtmlName) {
92
+ if (changedProperties.has('dynamicHtmlName')) {
93
+ this._dispatchErrorEvent("'dynamic-html-name' property must be set to the name of the dynamicHtml registered in the library map on the AVS/Go server.");
94
+ }
95
+ return;
96
+ }
126
97
 
127
- /**
128
- *
129
- */
130
- connectedCallback() {
131
- super.connectedCallback();
98
+ // Assemble the model
99
+ const model = {
100
+ dynamicHtmlProperties: {
101
+ name: this.dynamicHtmlName
102
+ }
103
+ };
104
+ if (this.dynamicHtmlUserProperties) {
105
+ let dynamicHtmlUserProperties;
106
+ try {
107
+ dynamicHtmlUserProperties = JSON.parse(this.dynamicHtmlUserProperties);
108
+ }
109
+ catch (error) {
110
+ this._dispatchErrorEvent("Can't parse 'dynamic-html-user-properties'. " + error.message);
111
+ return;
112
+ }
113
+ model.dynamicHtmlProperties.userProperties = dynamicHtmlUserProperties;
114
+ }
132
115
 
133
- // Make sure all CSS and layout has been processed
134
- afterNextRender(this, function() {
135
- if (this.__initialized != true) {
136
- this._httpRequest(this.url, this._handleHttpResponse.bind(this), undefined, this._handleHttpError.bind(this), this._assembleModel());
137
- this.__initialized = true;
116
+ // Data source properties
117
+ if (this.dataSourceName) {
118
+ model.dataSourceProperties = {
119
+ name: this.dataSourceName
120
+ }
121
+ if (this.dataSourceUserProperties) {
122
+ let dataSourceUserProperties;
123
+ try {
124
+ dataSourceUserProperties = JSON.parse(this.dataSourceUserProperties);
125
+ }
126
+ catch (error) {
127
+ this._dispatchErrorEvent("Can't parse 'data-source-user-properties'. " + error.message);
128
+ return;
129
+ }
130
+ model.dataSourceProperties.userProperties = dataSourceUserProperties;
138
131
  }
139
- });
132
+ }
133
+
134
+ // Send the request
135
+ this._httpRequest(this.url,
136
+ (response) => {
137
+ if (response.html) {
138
+ const html = decodeURIComponent(response.html.replace(/\+/g, '%20'));
139
+ this._html = DOMPurify.sanitize(html);
140
+ }
141
+ else {
142
+ this._dispatchErrorEvent("Empty response from AVS/Go server.");
143
+ }
144
+ },
145
+ null,
146
+ model
147
+ );
140
148
  }
141
149
  }
142
150
 
143
- window.customElements.define('avs-go-dynamic-html', AvsGoDynamicHtml);
151
+ customElements.define('avs-go-dynamic-html', AvsGoDynamicHtml);
@@ -18,107 +18,135 @@
18
18
  * Advanced Visual Systems Inc. (http://www.avs.com)
19
19
  */
20
20
 
21
- import {PolymerElement} from '@polymer/polymer/polymer-element.js';
22
- import {AvsHttpMixin} from './avs-http-mixin.js';
23
- import {AvsDataSourceMixin} from './avs-data-source-mixin.js';
21
+ import { AvsElementBase } from './avs-element-base.js';
24
22
 
25
23
  /**
26
- * `avs-go-info` is a Polymer 3.0 element which requests JSON data by instancing
24
+ * `avs-go-info` is a Lit element which requests data by instancing
27
25
  * the `infoName` class on the AVS/Go server application running at `url`.
28
26
  * After setting both these properties call the `updateInfo()` method to send the request.
29
- * Attach a listener for the `avs-go-info-response` event to receive the JSON response.
27
+ * Attach a listener for the `avs-go-info-response` event to receive the response.
30
28
  *
31
29
  * Special case: use an `infoName` of `GetServerInfo` to request a listing of
32
30
  * data sources, themes, scenes, info and dynamic HTML available at `url`.
33
31
  *
34
32
  * @customElement
35
- * @polymer
36
- * @appliesMixin AvsHttpMixin
37
- * @appliesMixin AvsDataSourceMixin
33
+ * @lit
38
34
  */
39
- export class AvsGoInfo extends AvsDataSourceMixin(AvsHttpMixin(PolymerElement)) {
35
+ export class AvsGoInfo extends AvsElementBase {
36
+ static properties = {
37
+ /**
38
+ * The URL to an instance of AVS/Go server application.
39
+ */
40
+ url: {
41
+ type: String
42
+ },
40
43
 
41
- static get properties() {
42
- return {
43
- /**
44
- * The URL to an instance of AVS/Go server application.
45
- */
46
- url: {
47
- type: String
48
- },
49
- /**
50
- * The name of the info registered in the library map on the server.
51
- */
52
- infoName: {
53
- type: String
54
- },
55
- /**
56
- * User properties passed directly to the server.
57
- */
58
- infoUserProperties: {
59
- type: Object,
60
- value: {}
61
- }
44
+ /**
45
+ * Name of the data source registered in the library map on the server.
46
+ */
47
+ dataSourceName: {
48
+ type: String,
49
+ attribute: 'data-source-name'
50
+ },
51
+
52
+ /**
53
+ * User properties as JSON passed directly to the data source on the server.
54
+ */
55
+ dataSourceUserProperties: {
56
+ type: String,
57
+ attribute: 'data-source-user-properties'
58
+ },
59
+
60
+ /**
61
+ * The name of the info registered in the library map on the server.
62
+ */
63
+ infoName: {
64
+ type: String,
65
+ attribute: 'info-name'
66
+ },
67
+
68
+ /**
69
+ * User properties as JSON passed directly to the info on the server.
70
+ */
71
+ infoUserProperties: {
72
+ type: String,
73
+ attribute: 'info-user-properties'
62
74
  }
63
75
  }
64
-
65
76
 
66
77
  /**
67
78
  * Send the request to the server.
68
79
  */
69
80
  updateInfo() {
70
- // Use avs-http-mixin to send the model to the server
71
- var model = this._assembleModel();
72
- if (model !== undefined) {
73
- this._httpRequest(this.url, this._handleHttpResponse.bind(this), undefined, this._handleHttpError.bind(this), model);
81
+ if (!this.url) {
82
+ this._dispatchErrorEvent("'url' property must be set to an instance of AVS/Go server.");
83
+ return;
74
84
  }
75
- }
76
-
77
- /**
78
- * Assemble the model from our properties to send to the server.
79
- */
80
- _assembleModel() {
81
- if (this.infoName === undefined) {
82
- this._logError( JSON.stringify( {"GoType":1, "error":"\'info-name\' property must be set to the name of the info registered in the library map on the server."} ) );
83
- return undefined;
85
+ if (!this.infoName) {
86
+ this._dispatchErrorEvent("'info-name' property must be set to the name of the info registered in the library map on the AVS/Go server.");
87
+ return;
84
88
  }
85
89
 
86
- var model = {infoProperties:{}};
87
-
88
- model.infoProperties.name = this.infoName;
89
- if (this.infoUserProperties !== undefined) {
90
- model.infoProperties.userProperties = this.infoUserProperties;
90
+ // Assemble the model
91
+ const model = {
92
+ infoProperties: {
93
+ name: this.infoName
94
+ }
95
+ };
96
+ if (this.infoUserProperties) {
97
+ let infoUserProperties;
98
+ try {
99
+ infoUserProperties = JSON.parse(this.infoUserProperties);
100
+ }
101
+ catch (error) {
102
+ this._dispatchErrorEvent("Can't parse 'info-user-properties'. " + error.message);
103
+ return;
104
+ }
105
+ model.infoProperties.userProperties = infoUserProperties;
91
106
  }
92
-
93
- this._addDataSourceProperties(model);
94
-
95
- return model;
96
- }
97
-
98
- /**
99
- * HTTP error handler.
100
- * @param event
101
- */
102
- _handleHttpError(event) {
103
107
 
104
- }
108
+ // Data source properties
109
+ if (this.dataSourceName) {
110
+ model.dataSourceProperties = {
111
+ name: this.dataSourceName
112
+ }
113
+ if (this.dataSourceUserProperties) {
114
+ let dataSourceUserProperties;
115
+ try {
116
+ dataSourceUserProperties = JSON.parse(this.dataSourceUserProperties);
117
+ }
118
+ catch (error) {
119
+ this._dispatchErrorEvent("Can't parse 'data-source-user-properties'. " + error.message);
120
+ return;
121
+ }
122
+ model.dataSourceProperties.userProperties = dataSourceUserProperties;
123
+ }
124
+ }
105
125
 
106
- /**
107
- * HTTP response handler.
108
- * @param json JSON parsed from HTTP response.
109
- */
110
- _handleHttpResponse(json) {
111
- if (json.info !== undefined) {
112
- var infoJSON = JSON.parse(decodeURIComponent(json.info.replace(/\+/g, '%20')));
113
- var infoEvent = {detail: infoJSON};
126
+ // Send the request
127
+ this._httpRequest(this.url,
128
+ (response) => {
129
+ if (response.info) {
130
+ const info = JSON.parse(decodeURIComponent(response.info.replace(/\+/g, '%20')));
114
131
 
115
- /**
116
- * JSON response from server.
117
- * @event avs-go-info-response
118
- */
119
- this.dispatchEvent(new CustomEvent('avs-go-info-response', infoEvent));
120
- }
132
+ /**
133
+ * Info response from server.
134
+ * @event avs-go-info-response
135
+ */
136
+ this.dispatchEvent(new CustomEvent('avs-go-info-response', {
137
+ bubbles: true,
138
+ composed: true,
139
+ detail: info
140
+ }));
141
+ }
142
+ else {
143
+ this._dispatchErrorEvent("Empty response from AVS/Go server.");
144
+ }
145
+ },
146
+ null,
147
+ model
148
+ );
121
149
  }
122
150
  }
123
151
 
124
- window.customElements.define('avs-go-info', AvsGoInfo);
152
+ customElements.define('avs-go-info', AvsGoInfo);
package/src/avs-go.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2018 Advanced Visual Systems Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ * This product includes software developed at
18
+ * Advanced Visual Systems Inc. (http://www.avs.com)
19
+ */
20
+
21
+ import { AvsGoDataViz } from './avs-go-dataviz.js'
22
+ import { AvsGoInfo } from './avs-go-info.js'
23
+ import { AvsGoDynamicHtml } from './avs-go-dynamic-html.js'
package/src/constants.js CHANGED
@@ -18,4 +18,4 @@
18
18
  * Advanced Visual Systems Inc. (http://www.avs.com)
19
19
  */
20
20
 
21
- export var VERSION = '0.13.71874';
21
+ export var VERSION = '0.14.71999';
@@ -1,61 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2018 Advanced Visual Systems Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- * This product includes software developed at
18
- * Advanced Visual Systems Inc. (http://www.avs.com)
19
- */
20
-
21
- import {dedupingMixin} from '@polymer/polymer/lib/utils/mixin.js';
22
-
23
- /**
24
- * Mixin to add data source properties functionality.
25
- *
26
- * @polymer
27
- * @mixinFunction
28
- */
29
- export const AvsDataSourceMixin = dedupingMixin((superClass) => class extends superClass {
30
-
31
- static get properties() {
32
- return {
33
- /**
34
- * Name of the data source registered in the library map on the server.
35
- */
36
- dataSourceName: {
37
- type: String
38
- },
39
- /**
40
- * User properties for the data source passed directly to the server.
41
- */
42
- dataSourceUserProperties: {
43
- type: Object,
44
- value: {}
45
- }
46
- }
47
- }
48
-
49
- /**
50
- * Add data-source-name and data-source-user-properties to model.
51
- * @param model Model to add to.
52
- */
53
- _addDataSourceProperties(model) {
54
- if (this.dataSourceName !== undefined) {
55
- model.dataSourceProperties = {"name":this.dataSourceName};
56
- if (this.dataSourceUserProperties !== undefined) {
57
- model.dataSourceProperties.userProperties = this.dataSourceUserProperties;
58
- }
59
- }
60
- }
61
- });