saasufy-components 1.5.0 → 1.5.1

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.
package/README.md CHANGED
@@ -25,6 +25,13 @@ Used for displaying and editing a field of a model instance in real time.
25
25
 
26
26
  Used for rendering models using a template.
27
27
 
28
+ ### input-provider
29
+
30
+ An input component which can pass data to other components (or HTML elements) via custom attributes.
31
+ A common use case for it is to pass user input to `collection-browser` or `model-viewer` to display relevant data loaded from Saasufy (e.g. based on a user query).
32
+ This component can be configured to provide its data to multiple components (consumers) via custom attributes.
33
+ Note that an `input-provider` only targets elements which are downstream from its parent element in the HTML hierarchy.
34
+
28
35
  ### confirm-modal
29
36
 
30
37
  A modal component to prompt the user for confirmation before performing sensitive operations.
@@ -91,6 +91,7 @@ class CollectionBrowser extends SocketConsumer {
91
91
  'collection-view-params',
92
92
  'collection-page-size',
93
93
  'collection-page-offset',
94
+ 'type-alias',
94
95
  'hide-error-logs'
95
96
  ];
96
97
  }
@@ -158,11 +159,12 @@ class CollectionBrowser extends SocketConsumer {
158
159
  if (noItemTemplate && !this.collection.value.length) {
159
160
  viewportNode.innerHTML = noItemTemplate.innerHTML;
160
161
  } else if (itemTemplate) {
162
+ let type = this.getAttribute('type-alias') || this.collection.type;
161
163
  let items = [];
162
164
  for (let modelItem of this.collection.value) {
163
165
  let itemString = renderTemplate(
164
166
  itemTemplate.innerHTML,
165
- { [this.collection.type]: modelItem }
167
+ { [type]: modelItem }
166
168
  );
167
169
  items.push(itemString);
168
170
  }
package/input-provider.js CHANGED
@@ -128,11 +128,19 @@ class InputProvider extends HTMLElement {
128
128
  let matchingElements = parentElement.querySelectorAll(selector);
129
129
  if (attributeName) {
130
130
  for (let element of matchingElements) {
131
- element.setAttribute(attributeName, value);
131
+ if (typeof value === 'boolean') {
132
+ if (value) {
133
+ element.setAttribute(attributeName, '');
134
+ } else {
135
+ element.removeAttribute(attributeName);
136
+ }
137
+ } else {
138
+ element.setAttribute(attributeName, value);
139
+ }
132
140
  }
133
141
  } else {
134
142
  for (let element of matchingElements) {
135
- if (element.nodeType === 'INPUT') {
143
+ if (element.nodeName === 'INPUT') {
136
144
  if (element.type === 'checkbox') {
137
145
  if (value) {
138
146
  element.setAttribute('checked', '');
@@ -164,11 +172,13 @@ class InputProvider extends HTMLElement {
164
172
  let onInputChange = (event) => {
165
173
  debounce(async () => {
166
174
  if (event.target.value === this.lastValue) return;
167
- this.lastValue = event.target.value;
168
175
  if (inputElement.type === 'checkbox') {
169
- this.updateConsumerElements(consumers, !!inputElement.checked);
176
+ let checked = !!inputElement.checked;
177
+ this.lastValue = checked;
178
+ this.updateConsumerElements(consumers, checked);
170
179
  return;
171
180
  }
181
+ this.lastValue = event.target.value;
172
182
  if (event.target.value === '') {
173
183
  this.updateConsumerElements(consumers, '');
174
184
  } else {
package/model-viewer.js CHANGED
@@ -29,6 +29,7 @@ class ModelViewer extends SocketConsumer {
29
29
  'model-type',
30
30
  'model-id',
31
31
  'model-fields',
32
+ 'type-alias',
32
33
  'hide-error-logs'
33
34
  ];
34
35
  }
@@ -55,9 +56,10 @@ class ModelViewer extends SocketConsumer {
55
56
  if (noItemTemplate && !this.modelValueExists(modelValue)) {
56
57
  viewportNode.innerHTML = noItemTemplate.innerHTML;
57
58
  } else if (itemTemplate) {
59
+ let type = this.getAttribute('type-alias') || this.model.type;
58
60
  let itemString = renderTemplate(
59
61
  itemTemplate.innerHTML,
60
- { [this.model.type]: modelValue }
62
+ { [type]: modelValue }
61
63
  );
62
64
  viewportNode.innerHTML = itemString;
63
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,7 +20,7 @@
20
20
  "ag-collection": "^3.3.0",
21
21
  "ag-model": "^1.4.1",
22
22
  "expr-eval": "^2.0.2",
23
- "socketcluster-client": "^19.0.2"
23
+ "socketcluster-client": "^19.1.0"
24
24
  },
25
25
  "bugs": {
26
26
  "url": "https://github.com/Saasufy/saasufy-components/issues"
package/socket.js CHANGED
@@ -41,14 +41,6 @@ export class SocketProvider extends HTMLElement {
41
41
 
42
42
  attributeChangedCallback(name, oldValue, newValue) {
43
43
  if (!this.isReady) return;
44
- let sanitizedURL = this.getSanitizedURL();
45
- if (
46
- this.saasufySocket &&
47
- this.saasufySocket.transport &&
48
- this.saasufySocket.transport.uri() !== sanitizedURL
49
- ) {
50
- this.saasufySocket.disconnect();
51
- }
52
44
  this.getSocket();
53
45
  }
54
46
 
@@ -58,18 +50,6 @@ export class SocketProvider extends HTMLElement {
58
50
  }
59
51
  }
60
52
 
61
- getSocket() {
62
- if (this.saasufySocket) {
63
- this.saasufySocket.options = {
64
- ...this.saasufySocket.options,
65
- ...this.getSocketOptions()
66
- };
67
- this.saasufySocket.connect();
68
- return this.saasufySocket;
69
- }
70
- return this.createSocket();
71
- }
72
-
73
53
  getSanitizedURL() {
74
54
  let url = this.getAttribute('url') || '';
75
55
  return url.trim();
@@ -105,6 +85,20 @@ export class SocketProvider extends HTMLElement {
105
85
  return socketOptions;
106
86
  }
107
87
 
88
+ getSocket() {
89
+ if (this.saasufySocket) {
90
+ if (this.saasufySocket.uri() !== this.getSanitizedURL()) {
91
+ this.saasufySocket.connect(
92
+ this.getSocketOptions()
93
+ );
94
+ } else {
95
+ this.saasufySocket.connect();
96
+ }
97
+ return this.saasufySocket;
98
+ }
99
+ return this.createSocket();
100
+ }
101
+
108
102
  createSocket() {
109
103
  let socketOptions = this.getSocketOptions();
110
104
  this.saasufySocket = create(socketOptions);
@@ -122,6 +116,13 @@ export class SocketConsumer extends HTMLElement {
122
116
  if (socket) break;
123
117
  currentNode = currentNode.getRootNode().host || currentNode.parentNode;
124
118
  }
119
+ if (!socket) {
120
+ throw new Error(
121
+ `The ${
122
+ this.nodeName.toLowerCase()
123
+ } element failed to obtain a socket - Make sure it is nested inside a socket-provider element`
124
+ );
125
+ }
125
126
  return socket;
126
127
  }
127
128
  }