saasufy-components 2.3.0 → 2.4.0

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.
@@ -223,8 +223,8 @@ class CollectionBrowser extends SocketConsumer {
223
223
  );
224
224
  let viewParams = Object.fromEntries(
225
225
  collectionViewParams.split(',')
226
- .map(pair => pair.split('='))
227
- .filter(([field]) => field)
226
+ .map(pair => pair.split('='))
227
+ .filter(([field]) => field)
228
228
  );
229
229
  if (this.collection) this.collection.destroy();
230
230
  this.isStale = true;
@@ -282,6 +282,8 @@ class CollectionBrowser extends SocketConsumer {
282
282
 
283
283
  (async () => {
284
284
  for await (let event of this.collection.listener('change')) {
285
+ // Ignore change events which originate from this collection instance.
286
+ if (!event.isRemote) continue;
285
287
  this.renderList();
286
288
  this.updatePageButtons();
287
289
  }
package/model-input.js CHANGED
@@ -23,6 +23,7 @@ class ModelInput extends SocketConsumer {
23
23
  'input-id',
24
24
  'list',
25
25
  'model-instance-property',
26
+ 'bind-to-collection',
26
27
  'type',
27
28
  'placeholder',
28
29
  'consumers',
@@ -65,6 +66,7 @@ class ModelInput extends SocketConsumer {
65
66
  render() {
66
67
  this.innerHTML = '';
67
68
  let modelInstanceProperty = this.getAttribute('model-instance-property');
69
+ let bindToCollection = this.hasAttribute('bind-to-collection');
68
70
  let showErrorMessage = this.hasAttribute('show-error-message');
69
71
  let inputId = this.getAttribute('input-id');
70
72
  let inputList = this.getAttribute('list');
@@ -80,41 +82,64 @@ class ModelInput extends SocketConsumer {
80
82
  let currentNode = this.parentNode;
81
83
  let model;
82
84
  let isModelLocal = false;
83
- if (modelInstanceProperty) {
85
+ if (bindToCollection) {
86
+ let collection;
84
87
  while (currentNode) {
85
- model = currentNode[modelInstanceProperty];
86
- if (model && modelType && (model.type !== modelType || !(model.fields || []).includes(modelField))) {
87
- model = null;
88
+ collection = currentNode.collection;
89
+ if (collection && (collection.type !== modelType || !(collection.fields || []).includes(modelField))) {
90
+ collection = null;
88
91
  }
89
- if (model) break;
92
+ if (collection && (!collection.agModels || !collection.agModels[modelId] || !collection.agModels[modelId].agFields[modelField])) {
93
+ collection = null;
94
+ }
95
+ if (collection) break;
90
96
  currentNode = currentNode.getRootNode().host || currentNode.parentNode;
91
97
  }
92
- if (!model) {
93
- throw new Error(
94
- `The ${
95
- this.nodeName.toLowerCase()
96
- } element failed to obtain a model via the specified model-instance-property - Ensure that the element is nested inside a parent element which exposes a model instance of the same type which has the relevant field`
97
- );
98
- };
99
- } else {
100
- this.socket = this.getSocket();
101
- model = new AGModel({
102
- socket: this.socket,
103
- type: modelType,
104
- id: modelId,
105
- fields: [ modelField ],
106
- enableRebound
107
- });
108
- if (!hideErrorLogs) {
109
- (async () => {
110
- for await (let { error } of model.listener('error')) {
111
- console.error(
112
- `Model input encountered an error: ${error.message}`
113
- );
98
+ if (collection) {
99
+ model = collection.agModels[modelId];
100
+ }
101
+ }
102
+ if (!model) {
103
+ currentNode = this.parentNode;
104
+ if (modelInstanceProperty) {
105
+ while (currentNode) {
106
+ model = currentNode[modelInstanceProperty];
107
+ if (model && modelType && (model.type !== modelType || !(model.fields || []).includes(modelField))) {
108
+ model = null;
114
109
  }
115
- })();
110
+ if (model && !model.agFields) {
111
+ model = null;
112
+ }
113
+ if (model) break;
114
+ currentNode = currentNode.getRootNode().host || currentNode.parentNode;
115
+ }
116
+ if (!model) {
117
+ throw new Error(
118
+ `The ${
119
+ this.nodeName.toLowerCase()
120
+ } element failed to obtain a model via the specified model-instance-property - Ensure that the element is nested inside a parent element which exposes a model instance of the same type which has the relevant field`
121
+ );
122
+ };
123
+ } else {
124
+ this.socket = this.getSocket();
125
+ model = new AGModel({
126
+ socket: this.socket,
127
+ type: modelType,
128
+ id: modelId,
129
+ fields: [ modelField ],
130
+ enableRebound
131
+ });
132
+ if (!hideErrorLogs) {
133
+ (async () => {
134
+ for await (let { error } of model.listener('error')) {
135
+ console.error(
136
+ `Model input encountered an error: ${error.message}`
137
+ );
138
+ }
139
+ })();
140
+ }
141
+ isModelLocal = true;
116
142
  }
117
- isModelLocal = true;
118
143
  }
119
144
  if (model.isLoaded) {
120
145
  this.setAttribute('is-loaded', '');
package/model-text.js CHANGED
@@ -21,6 +21,7 @@ class ModelText extends SocketConsumer {
21
21
  static get observedAttributes() {
22
22
  return [
23
23
  'model-instance-property',
24
+ 'bind-to-collection',
24
25
  'model-type',
25
26
  'model-id',
26
27
  'model-field',
@@ -37,6 +38,7 @@ class ModelText extends SocketConsumer {
37
38
  render() {
38
39
  this.innerHTML = '';
39
40
  let modelInstanceProperty = this.getAttribute('model-instance-property');
41
+ let bindToCollection = this.hasAttribute('bind-to-collection');
40
42
  let modelType = this.getAttribute('model-type');
41
43
  let modelId = this.getAttribute('model-id');
42
44
  let modelField = this.getAttribute('model-field');
@@ -44,40 +46,63 @@ class ModelText extends SocketConsumer {
44
46
  let currentNode = this.parentNode;
45
47
  let model;
46
48
  let isModelLocal = false;
47
- if (modelInstanceProperty) {
49
+ if (bindToCollection) {
50
+ let collection;
48
51
  while (currentNode) {
49
- model = currentNode[modelInstanceProperty];
50
- if (model && modelType && (model.type !== modelType || !(model.fields || []).includes(modelField))) {
51
- model = null;
52
+ collection = currentNode.collection;
53
+ if (collection && (collection.type !== modelType || !(collection.fields || []).includes(modelField))) {
54
+ collection = null;
52
55
  }
53
- if (model) break;
56
+ if (collection && (!collection.agModels || !collection.agModels[modelId] || !collection.agModels[modelId].agFields[modelField])) {
57
+ collection = null;
58
+ }
59
+ if (collection) break;
54
60
  currentNode = currentNode.getRootNode().host || currentNode.parentNode;
55
61
  }
56
- if (!model) {
57
- throw new Error(
58
- `The ${
59
- this.nodeName.toLowerCase()
60
- } element failed to obtain a model via the specified model-instance-property - Ensure that the element is nested inside a parent element which exposes a model instance of the same type which has the relevant field`
61
- );
62
- };
63
- } else {
64
- this.socket = this.getSocket();
65
- model = new AGModel({
66
- socket: this.socket,
67
- type: modelType,
68
- id: modelId,
69
- fields: [ modelField ]
70
- });
71
- if (!hideErrorLogs) {
72
- (async () => {
73
- for await (let { error } of model.listener('error')) {
74
- console.error(
75
- `Model input encountered an error: ${error.message}`
76
- );
62
+ if (collection) {
63
+ model = collection.agModels[modelId];
64
+ }
65
+ }
66
+ if (!model) {
67
+ currentNode = this.parentNode;
68
+ if (modelInstanceProperty) {
69
+ while (currentNode) {
70
+ model = currentNode[modelInstanceProperty];
71
+ if (model && modelType && (model.type !== modelType || !(model.fields || []).includes(modelField))) {
72
+ model = null;
77
73
  }
78
- })();
74
+ if (model && !model.agFields) {
75
+ model = null;
76
+ }
77
+ if (model) break;
78
+ currentNode = currentNode.getRootNode().host || currentNode.parentNode;
79
+ }
80
+ if (!model) {
81
+ throw new Error(
82
+ `The ${
83
+ this.nodeName.toLowerCase()
84
+ } element failed to obtain a model via the specified model-instance-property - Ensure that the element is nested inside a parent element which exposes a model instance of the same type which has the relevant field`
85
+ );
86
+ };
87
+ } else {
88
+ this.socket = this.getSocket();
89
+ model = new AGModel({
90
+ socket: this.socket,
91
+ type: modelType,
92
+ id: modelId,
93
+ fields: [ modelField ]
94
+ });
95
+ if (!hideErrorLogs) {
96
+ (async () => {
97
+ for await (let { error } of model.listener('error')) {
98
+ console.error(
99
+ `Model input encountered an error: ${error.message}`
100
+ );
101
+ }
102
+ })();
103
+ }
104
+ isModelLocal = true;
79
105
  }
80
- isModelLocal = true;
81
106
  }
82
107
  if (model.isLoaded) {
83
108
  this.setAttribute('is-loaded', '');
package/model-viewer.js CHANGED
@@ -104,6 +104,9 @@ class ModelViewer extends SocketConsumer {
104
104
  if (model && modelType && (model.type !== modelType || !(model.fields || []).includes(modelField))) {
105
105
  model = null;
106
106
  }
107
+ if (model && !model.agFields) {
108
+ model = null;
109
+ }
107
110
  if (model) break;
108
111
  currentNode = currentNode.getRootNode().host || currentNode.parentNode;
109
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {