saasufy-components 4.5.0 → 5.0.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
@@ -6,7 +6,7 @@ Components for Saasufy
6
6
  - [socket-provider](#socket-provider)
7
7
 
8
8
  ### Collections of resources
9
- - [collection-browser](#collection-browser)
9
+ - [collection-viewer](#collection-viewer)
10
10
  - [collection-adder](#collection-adder)
11
11
  - [collection-adder-form](#collection-adder-form)
12
12
  - [collection-deleter](#collection-deleter)
@@ -256,7 +256,7 @@ A Saasufy component which integrates with data from Saasufy is known as a `socke
256
256
  - `socket-options`: Can be used to set options on the inner `socket`. Must be in the format `option1:type1=value1,option2:type2=value2`; the type of each option can be string, boolean or number. If not specified, the default type is string.
257
257
  - `disconnect-on-deauth`: If this attribute is set, the underlying socket will be disconnected if the socket becomes unauthenticated. This means that components will not receive real-time updates until the user's next interaction (which will cause the socket to reconnect). If this attribute is not set, the socket will attempt to reconnect immediately after losing authentication.
258
258
 
259
- ### collection-browser
259
+ ### collection-viewer
260
260
 
261
261
  Used for rendering collections as lists, tables or other sequences based on a specific view using a template.
262
262
  Supports pagination by allowing you to specify custom buttons or links to navigate between pages.
@@ -265,13 +265,13 @@ Can also perform basic CRUD operations such as deleting or creating records by l
265
265
  **Import**
266
266
 
267
267
  ```html
268
- <script src="https://saasufy.com/node_modules/saasufy-components/collection-browser.js" type="module" defer></script>
268
+ <script src="https://saasufy.com/node_modules/saasufy-components/collection-viewer.js" type="module" defer></script>
269
269
  ```
270
270
 
271
271
  **Example usage**
272
272
 
273
273
  ```html
274
- <collection-browser
274
+ <collection-viewer
275
275
  collection-type="Chat"
276
276
  collection-fields="username,message,createdAt"
277
277
  collection-view="recentView"
@@ -280,11 +280,9 @@ Can also perform basic CRUD operations such as deleting or creating records by l
280
280
  >
281
281
  <template slot="item">
282
282
  <div>
283
- <div class="chat-username">
284
- <b>{{Chat.username}}</b>
285
- </div>
286
- <div class="chat-message">{{Chat.message}}</div>
287
- <div class="chat-created-at">{{date(Chat.createdAt)}}</div>
283
+ <div>{{Chat.username}}</div>
284
+ <div>{{Chat.message}}</div>
285
+ <div>{{date(Chat.createdAt)}}</div>
288
286
  </div>
289
287
  </template>
290
288
 
@@ -295,7 +293,7 @@ Can also perform basic CRUD operations such as deleting or creating records by l
295
293
  </template>
296
294
 
297
295
  <div slot="viewport" class="chat-viewport"></div>
298
- </collection-browser>
296
+ </collection-viewer>
299
297
  ```
300
298
 
301
299
  **Attributes**
@@ -305,11 +303,11 @@ Can also perform basic CRUD operations such as deleting or creating records by l
305
303
  - `collection-view` (required): Determines the view of the collection. This should match one of the `Views` defined in your Saasufy service under that specific `Model`.
306
304
  - `collection-view-params` (required): Parameters for the view, specified as comma-separated key-value pairs (e.g., key1=value1,key2=value2). These parameters can customize the behavior of the collection view. The keys must match `paramFields` specified in your Saasufy service under the relevant `View`.
307
305
  - `collection-page-size`: Sets how many items from the collection are displayed at once. This is useful for pagination, allowing users to navigate through large sets of data in chunks.
308
- - `collection-page-offset`: Indicates the current page offset in the collection's data. It’s like telling the browser which page of data you want to display initially.
306
+ - `collection-page-offset`: Indicates the current page offset in the collection's data. It’s like telling the viewer which page of data you want to display initially.
309
307
  - `collection-get-count`: If this attribute is present, the component will get the record count of the target view. The count can be rendered into the template by prefixing the model name with a dollar sign and accessing the `count` property like this: `{{$MyModelName.count}}`.
310
308
  - `collection-view-primary-fields`: An optional list of field names to specify which specific `collection-view-params` to watch for real time updates. Fewer primary fields means that the view will be exposed to a broader range of real time updates but at the cost of performance. It is generally recommended to have just one primary field.
311
309
  - `auto-reset-page-offset`: If this attribute is present, the `collection-page-offset` will be reset to zero whenever the view params change.
312
- - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `collection-browser` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `SubChat`, then `{{Chat.message}}` would become `{{SubChat.message}}`.
310
+ - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `collection-viewer` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `SubChat`, then `{{Chat.message}}` would become `{{SubChat.message}}`.
313
311
  - `hide-error-logs`: A flag which, when present, suppresses error logs from being printed to the console.
314
312
  - `max-show-loader`: If this attribute is present, your slotted `loader` element will be shown as often as possible; this includes situations where the collection is merely refreshing itself. It is disabled by default.
315
313
 
@@ -389,8 +387,8 @@ This component is similar to the `collection-adder` component except that it req
389
387
 
390
388
  ### collection-deleter
391
389
 
392
- A component which can be placed anywhere inside a `collection-browser` component to delete a specific item from a collection as a result of a user action (e.g. on click).
393
- It supports either immediate deletion or deletion upon confirmation; in the latter case, the parent `collection-browser` must have a `confirm-modal` component slotted into its `modal` slot.
390
+ A component which can be placed anywhere inside a `collection-viewer` component to delete a specific item from a collection as a result of a user action (e.g. on click).
391
+ It supports either immediate deletion or deletion upon confirmation; in the latter case, the parent `collection-viewer` must have a `confirm-modal` component slotted into its `modal` slot.
394
392
 
395
393
  **Import**
396
394
 
@@ -401,14 +399,14 @@ It supports either immediate deletion or deletion upon confirmation; in the latt
401
399
  **Example usage**
402
400
 
403
401
  ```html
404
- <!-- Must be placed somewhere inside a collection-browser component, typically inside the slotted item template. -->
402
+ <!-- Must be placed somewhere inside a collection-viewer component, typically inside the slotted item template. -->
405
403
  <collection-deleter model-id="{{Product.id}}" onclick="deleteItem()">&#x2715;</collection-deleter>
406
404
  ```
407
405
 
408
406
  OR (with confirmation step)
409
407
 
410
408
  ```html
411
- <!-- Must be placed somewhere inside a collection-browser component, typically inside the slotted item template. -->
409
+ <!-- Must be placed somewhere inside a collection-viewer component, typically inside the slotted item template. -->
412
410
  <collection-deleter model-id="{{Product.id}}" confirm-message="Are you sure you want to delete the {{Product.name}} product?" onclick="confirmDeleteItem()">&#x2715;</collection-deleter>
413
411
  ```
414
412
 
@@ -418,10 +416,10 @@ OR (with confirmation step)
418
416
  - `onclick` (required): The logic to execute to delete the item. Should be either `deleteItem()` or `confirmDeleteItem()`.
419
417
  - `confirm-message`: The confirmation message to show the user when this component's `confirmDeleteItem()` function is invoked.
420
418
 
421
- If `confirmDeleteItem()` is used, then the parent `collection-browser` must have a `confirm-modal` element slotted into it as shown here:
419
+ If `confirmDeleteItem()` is used, then the parent `collection-viewer` must have a `confirm-modal` element slotted into it as shown here:
422
420
 
423
421
  ```html
424
- <collection-browser
422
+ <collection-viewer
425
423
  collection-type="Product"
426
424
  collection-fields="name,qty"
427
425
  collection-view="alphabeticalView"
@@ -430,7 +428,7 @@ If `confirmDeleteItem()` is used, then the parent `collection-browser` must have
430
428
  >
431
429
  <template slot="item">
432
430
  <div>
433
- <div class="chat-message">{{Product.name}}</div>
431
+ <div>{{Product.name}}</div>
434
432
  <collection-deleter model-id="{{Product.id}}" confirm-message="Are you sure you want to delete the {{Product.name}} product?" onclick="confirmDeleteItem()">&#x2715;</collection-deleter>
435
433
  </div>
436
434
  </template>
@@ -439,12 +437,12 @@ If `confirmDeleteItem()` is used, then the parent `collection-browser` must have
439
437
 
440
438
  <!-- The confirm-modal element must be specified here with slot="modal" to prompt the user for confirmation -->
441
439
  <confirm-modal slot="modal" title="Delete confirmation" message="" confirm-button-label="Delete"></confirm-modal>
442
- </collection-browser>
440
+ </collection-viewer>
443
441
  ```
444
442
 
445
443
  ### collection-reducer
446
444
 
447
- Similar to the `collection-browser` component but designed to render collections in combined format. For example, to combine values from multiple records into a single item.
445
+ Similar to the `collection-viewer` component but designed to render collections in combined format. For example, to combine values from multiple records into a single item.
448
446
  A common use case is to extract and join values to pass to other child components via their attributes.
449
447
 
450
448
  **Import**
@@ -489,7 +487,7 @@ A common use case is to extract and join values to pass to other child component
489
487
  </collection-reducer>
490
488
  ```
491
489
 
492
- Unlike with `collection-browser` or `model-viewer`, the template variable references not a single model instance but an array of model instances.
490
+ Unlike with `collection-viewer` or `model-viewer`, the template variable references not a single model instance but an array of model instances.
493
491
  In the example above, the name of the first element can be accessed with `{{Category[0].name}}`.
494
492
 
495
493
  **Attributes**
@@ -499,9 +497,9 @@ In the example above, the name of the first element can be accessed with `{{Cate
499
497
  - `collection-view` (required): Determines the view of the collection. This should match one of the `Views` defined in your Saasufy service under that specific `Model`.
500
498
  - `collection-view-params` (required): Parameters for the view, specified as comma-separated key-value pairs (e.g., key1=value1,key2=value2). These parameters can customize the behavior of the collection view. The keys must match `paramFields` specified in your Saasufy service under the relevant `View`.
501
499
  - `collection-page-size`: Sets how many items from the collection are displayed at once. This is useful for pagination, allowing users to navigate through large sets of data in chunks.
502
- - `collection-page-offset`: Indicates the current page offset in the collection's data. It’s like telling the browser which page of data you want to display initially.
500
+ - `collection-page-offset`: Indicates the current page offset in the collection's data. It’s like telling the viewer which page of data you want to display initially.
503
501
  - `collection-get-count`: If this attribute is present, the component will get the record count of the target view. The count can be rendered into the template by prefixing the model name with a dollar sign and accessing the `count` property like this: `{{$MyModelName.count}}`.
504
- - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `collection-browser` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `SubChat`, then `{{Chat.message}}` would become `{{SubChat.message}}`.
502
+ - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `collection-viewer` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `SubChat`, then `{{Chat.message}}` would become `{{SubChat.message}}`.
505
503
  - `hide-error-logs`: A flag which, when present, suppresses error logs from being printed to the console.
506
504
 
507
505
  ### model-input
@@ -586,7 +584,7 @@ Used to displaying a field of a model instance in real time.
586
584
 
587
585
  ### model-viewer
588
586
 
589
- Used for rendering a single model resource using a template. This is the single-model alternative to the `collection-browser` which works with collections of models.
587
+ Used for rendering a single model resource using a template. This is the single-model alternative to the `collection-viewer` which works with collections of models.
590
588
 
591
589
  **Import**
592
590
 
@@ -619,14 +617,14 @@ Used for rendering a single model resource using a template. This is the single-
619
617
  - `model-type` (required): Specifies the type of model to bind to. This should match a `Model` available in your Saasufy service.
620
618
  - `model-id` (required): The id of the model instance/record to bind to.
621
619
  - `model-fields` (required): A comma-separated list of fields to bind to. Note that unlike with `model-input` and `model-text`, the attribute name is plural and can bind to multiple fields.
622
- - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `model-browser` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `MyProduct`, then `{{Product.name}}` would become `{{MyProduct.name}}`.
620
+ - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `model-viewer` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `MyProduct`, then `{{Product.name}}` would become `{{MyProduct.name}}`.
623
621
  - `fields-slice-to`: Optional attribute which can be used to trim strings down to a maximum number of characters when reading. The format is `fieldName1=number1,fieldName2=number2`. This is useful when dealing with potentially very long field values. Note that it may affect caching if the same field is being referenced in multiple parts of the application at the same time within the same `socket-provider`.
624
622
  - `hide-error-logs`: A flag which, when present, suppresses error logs from being printed to the console.
625
623
 
626
624
  ### input-provider
627
625
 
628
626
  An input component which can pass data to other components (or HTML elements) via custom attributes.
629
- A common use case for it is to pass user input to `collection-browser` or `model-viewer` components to then fetch data from Saasufy.
627
+ A common use case for it is to pass user input to `collection-viewer` or `model-viewer` components to then fetch data from Saasufy.
630
628
  This component can be configured to provide its data to multiple components (consumers) via custom attributes.
631
629
 
632
630
  **Import**
@@ -667,7 +665,7 @@ This component can be configured to provide its data to multiple components (con
667
665
  ### input-combiner
668
666
 
669
667
  A component which can be used to combine data from multiple `input-provider` components and pass the combined data to other components (or HTML elements) via custom attributes.
670
- A common use case for it is to pass user input to `collection-browser` or `model-viewer` components to then fetch data from Saasufy.
668
+ A common use case for it is to pass user input to `collection-viewer` or `model-viewer` components to then fetch data from Saasufy.
671
669
  This component can be configured to provide its data to multiple components (consumers) via custom attributes.
672
670
 
673
671
  **Import**
@@ -679,7 +677,7 @@ This component can be configured to provide its data to multiple components (con
679
677
  **Example usage**
680
678
 
681
679
  The following example shows how to bind multiple `input-provider` components to an `input-combiner`.
682
- In this example, the `input-combiner` component forwards the combined, formatted values to the `collection-view-params` attribute of a `company-browser` component.
680
+ In this example, the `input-combiner` component forwards the combined, formatted values to the `collection-view-params` attribute of a `company-viewer` component.
683
681
 
684
682
  Note that the `value` inside the `provider-template` attribute of the `input-combiner` is an object with keys that represent the `name` attribute of the different source `input-provider` components.
685
683
  The `combineFilters` function produces a combined query string (joined with `%AND%`) by iterating over the `value` object which holds different parts of the query as provided by different `input-provider` components.
@@ -707,7 +705,7 @@ The `combineFilters` function produces a combined query string (joined with `%AN
707
705
 
708
706
  <input-combiner
709
707
  class="search-combiner"
710
- consumers=".company-browser:collection-view-params"
708
+ consumers=".company-viewer:collection-view-params"
711
709
  provider-template="query='{{combineFilters(value)}}'"
712
710
  ></input-combiner>
713
711
  ```
@@ -918,7 +916,7 @@ The `render-group` will only render its content once all the components specifie
918
916
  ### if-group
919
917
 
920
918
  A component which exposes a `show-content` property which can be set to true or false to show or hide its content.
921
- It's intended to be placed inside a `model-viewer`, `collection-browser` or `collection-reducer` component such that the true/false value of the `show-content` attribute can be computed using a template `{{expression}}` placeholder. This component requires a template and a viewport to be slotted in. The content of the template will not be processed unless the `show-content` condition is met.
919
+ It's intended to be placed inside a `model-viewer`, `collection-viewer` or `collection-reducer` component such that the true/false value of the `show-content` attribute can be computed using a template `{{expression}}` placeholder. This component requires a template and a viewport to be slotted in. The content of the template will not be processed unless the `show-content` condition is met.
922
920
 
923
921
  **Import**
924
922
 
@@ -942,7 +940,7 @@ It's intended to be placed inside a `model-viewer`, `collection-browser` or `col
942
940
  ### switch-group
943
941
 
944
942
  A component which exposes a `show-cases` property which can be set to key-value pairs in the format `key1=true,key2=false`. It can be used to conditionally display multiple slotted elements based on multiple conditions. It helps to keep HTML clean when the conditions are complex.
945
- This element is intended to be placed inside a `model-viewer`, `collection-browser` or `collection-reducer` component such that the true/false values of the `show-cases` attribute can be computed using template `{{expression}}` placeholders. This component requires one or more templates and a viewport to be slotted in. The content of the templates will not be processed unless the `show-cases` condition is met. All templates must have a `slot="content"` attribute and a name attribute in the format `name="key1"` where the value `key1` corresponds to the key specified inside the `show-cases` attribute of the `switch-group`.
943
+ This element is intended to be placed inside a `model-viewer`, `collection-viewer` or `collection-reducer` component such that the true/false values of the `show-cases` attribute can be computed using template `{{expression}}` placeholders. This component requires one or more templates and a viewport to be slotted in. The content of the templates will not be processed unless the `show-cases` condition is met. All templates must have a `slot="content"` attribute and a name attribute in the format `name="key1"` where the value `key1` corresponds to the key specified inside the `show-cases` attribute of the `switch-group`.
946
944
 
947
945
  **Import**
948
946
 
@@ -1008,7 +1006,7 @@ A component which can be used to group together multiple `collection-adder` comp
1008
1006
 
1009
1007
  ### confirm-modal
1010
1008
 
1011
- A modal component to prompt the user for confirmation before performing sensitive operations. Can be slotted into a `collection-browser` component.
1009
+ A modal component to prompt the user for confirmation before performing sensitive operations. Can be slotted into a `collection-viewer` component.
1012
1010
 
1013
1011
  **Import**
1014
1012
 
@@ -1019,7 +1017,7 @@ A modal component to prompt the user for confirmation before performing sensitiv
1019
1017
  **Example usage**
1020
1018
 
1021
1019
  ```html
1022
- <collection-browser
1020
+ <collection-viewer
1023
1021
  collection-type="Product"
1024
1022
  collection-fields="name,qty"
1025
1023
  collection-view="alphabeticalView"
@@ -1028,16 +1026,16 @@ A modal component to prompt the user for confirmation before performing sensitiv
1028
1026
  >
1029
1027
  <template slot="item">
1030
1028
  <div>
1031
- <div class="chat-message">{{Product.name}}</div>
1029
+ <div>{{Product.name}}</div>
1032
1030
  <collection-deleter model-id="{{Product.id}}" confirm-message="Are you sure you want to delete the {{Product.name}} product?" onclick="confirmDeleteItem()">&#x2715;</collection-deleter>
1033
1031
  </div>
1034
1032
  </template>
1035
1033
 
1036
- <div slot="viewport" class="chat-viewport"></div>
1034
+ <div slot="viewport"></div>
1037
1035
 
1038
1036
  <!-- The confirm-modal element must be specified here with slot="modal" to prompt the user for confirmation -->
1039
1037
  <confirm-modal slot="modal" title="Delete confirmation" message="" confirm-button-label="Delete"></confirm-modal>
1040
- </collection-browser>
1038
+ </collection-viewer>
1041
1039
  ```
1042
1040
 
1043
1041
  **Attributes**
@@ -289,6 +289,16 @@ class CollectionAdder extends SocketConsumer {
289
289
  field
290
290
  }"${extraAttributesString} />`
291
291
  );
292
+ } else if (inputType === 'number') {
293
+ items.push(
294
+ `<input class="collection-adder-input" type="${
295
+ inputType
296
+ }" name="${
297
+ field
298
+ }" placeholder="${
299
+ inputLabel
300
+ }" step="any"${extraAttributesString} />`
301
+ );
292
302
  } else {
293
303
  items.push(
294
304
  `<input class="collection-adder-input" type="${
@@ -4,7 +4,7 @@ import { renderTemplate, convertStringToFieldParams } from './utils.js';
4
4
 
5
5
  const DEFAULT_RELOAD_DELAY = 0;
6
6
 
7
- class CollectionBrowser extends SocketConsumer {
7
+ class CollectionViewer extends SocketConsumer {
8
8
  constructor() {
9
9
  super();
10
10
  this.isReady = false;
@@ -351,7 +351,7 @@ class CollectionBrowser extends SocketConsumer {
351
351
  (async () => {
352
352
  for await (let { error } of this.collection.listener('error')) {
353
353
  console.error(
354
- `Collection browser encountered an error: ${error.message}`
354
+ `Collection viewer encountered an error: ${error.message}`
355
355
  );
356
356
  }
357
357
  })();
@@ -359,4 +359,4 @@ class CollectionBrowser extends SocketConsumer {
359
359
  }
360
360
  }
361
361
 
362
- window.customElements.define('collection-browser', CollectionBrowser);
362
+ window.customElements.define('collection-viewer', CollectionViewer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "4.5.0",
3
+ "version": "5.0.1",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/styles.css CHANGED
@@ -167,14 +167,14 @@ collection-adder .collection-adder-form-content > label {
167
167
  align-self: flex-start;
168
168
  }
169
169
 
170
- collection-browser {
170
+ collection-viewer {
171
171
  display: flex;
172
172
  flex-wrap: wrap;
173
173
  justify-content: center;
174
174
  gap: 10px;
175
175
  }
176
176
 
177
- collection-browser > [slot=viewport] {
177
+ collection-viewer > [slot=viewport] {
178
178
  display: flex;
179
179
  flex-direction: column;
180
180
  }
@@ -183,20 +183,20 @@ collection-browser > [slot=viewport] {
183
183
  cursor: pointer;
184
184
  }
185
185
 
186
- collection-browser > [slot=previous-page] {
186
+ collection-viewer > [slot=previous-page] {
187
187
  cursor: pointer;
188
188
  flex-shrink: 1;
189
189
  width: auto;
190
190
  }
191
191
 
192
- collection-browser > [slot=page-number] {
192
+ collection-viewer > [slot=page-number] {
193
193
  display: flex;
194
194
  justify-content: center;
195
195
  align-items: center;
196
196
  min-width: 30px;
197
197
  }
198
198
 
199
- collection-browser > [slot=next-page] {
199
+ collection-viewer > [slot=next-page] {
200
200
  cursor: pointer;
201
201
  flex-shrink: 1;
202
202
  width: auto;