saasufy-components 3.17.1 → 3.19.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.
package/README.md CHANGED
@@ -259,6 +259,7 @@ Can also perform basic CRUD operations such as deleting or creating records by l
259
259
  - `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.
260
260
  - `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.
261
261
  - `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}}`.
262
+ - `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.
262
263
  - `auto-reset-page-offset`: If this attribute is present, the `collection-page-offset` will be reset to zero whenever the view params change.
263
264
  - `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}}`.
264
265
  - `hide-error-logs`: A flag which, when present, suppresses error logs from being printed to the console.
@@ -291,6 +292,7 @@ A form component for inserting data into collections.
291
292
  - `collection-type` (required): Specifies the type of collection to add the resource to when the form is submitted. This should match a `Model` available in your Saasufy service.
292
293
  - `collection-fields`: A comma-separated list of fields from the `Model` to display as input elements inside the form for the user to fill in. Each field name in this list can optionally be followed by an input element type after a `:` character. For example `collection-fields="qty:number, size:select(small,medium,large)` will create one input element with `type="number"` and one with `type=select` with options `small`, `medium` or `large`. To make a select field optional, you can prefix the list of options with a comma; e.g. `size:select(,small,medium,large)`. Supported input types include: `text`, `select`, `number`, `checkbox`, `radio`, `textarea`, `file` and `text-select`.
293
294
  - `model-values`: An optional list of key-value pairs in the format `field1=value1,field2=value2` to add to the newly created resource alongside the values collected from the user via the form. For non-string values, the type should be provided in the format `fieldName:type=value`; supported types are `string`, `number` and `boolean`. Unlike `collection-fields` which are rendered as input elements in the form, `model-values` are not shown to the user.
295
+ - `field-labels`: Allows you to specify custom input labels by mapping field names to more user-friendly labels in the format `fieldName1='Field Name 1',fieldName2='Field Name 2'`.
294
296
  - `submit-button-label`: Text to display on the submit button. If not specified, defaults to `Submit`.
295
297
  - `hide-submit-button`: Adding this attribute will hide the submit button from the form.
296
298
  - `success-message`: A message to show the user if the resource has been successfully added to the collection after submitting the form.
@@ -566,6 +568,7 @@ This component can be configured to provide its data to multiple components (con
566
568
  - `computable-value`: If this attribute is present, it will be possible to execute expressions using the `{{expression}}` syntax inside the `value` attribute.
567
569
  - `autocapitalize`: Can be `on` or `off` - It will set the auto-capitalize attribute on the inner input element. This is useful for mobile devices to enable or disable auto-capitalization of the first character which is typed into the input element.
568
570
  - `autocorrect`: Can be `on` or `off` - It will set the auto-correct attribute on the inner input element. This is useful for mobile devices to enable or disable auto-correct.
571
+ - `input-props`: Can be used to set additional attributes on the inner `input` element. Must be in the format `attr1=value1,attr2=value2`.
569
572
 
570
573
  ### input-combiner
571
574
 
@@ -101,6 +101,7 @@ class CollectionBrowser extends SocketConsumer {
101
101
  'collection-fields',
102
102
  'collection-view',
103
103
  'collection-view-params',
104
+ 'collection-view-primary-fields',
104
105
  'collection-page-size',
105
106
  'collection-page-offset',
106
107
  'collection-get-count',
@@ -250,6 +251,7 @@ class CollectionBrowser extends SocketConsumer {
250
251
  let collectionView = this.getAttribute('collection-view') || 'defaultView';
251
252
  let collectionPageSize = this.getAttribute('collection-page-size');
252
253
  let collectionViewParams = this.getAttribute('collection-view-params') || '';
254
+ let collectionViewPrimaryFields = this.getAttribute('collection-view-primary-fields');
253
255
  let collectionPageOffset = this.getAttribute('collection-page-offset');
254
256
  let collectionGetCount = this.hasAttribute('collection-get-count');
255
257
  let hideErrorLogs = this.hasAttribute('hide-error-logs');
@@ -257,6 +259,8 @@ class CollectionBrowser extends SocketConsumer {
257
259
  this.getAttribute('collection-reload-delay') || DEFAULT_RELOAD_DELAY
258
260
  );
259
261
  let { fieldValues: viewParams } = convertStringToFieldParams(collectionViewParams);
262
+ let viewPrimaryFields = collectionViewPrimaryFields ?
263
+ collectionViewPrimaryFields.split(',').map(fieldName => fieldName.trim()) : null;
260
264
 
261
265
  if (this.collection) this.collection.destroy();
262
266
  this.isStale = true;
@@ -267,6 +271,7 @@ class CollectionBrowser extends SocketConsumer {
267
271
  fields: collectionFields.split(',').map(field => field.trim()).filter(field => field),
268
272
  view: collectionView,
269
273
  viewParams,
274
+ viewPrimaryFields,
270
275
  pageSize: Number(collectionPageSize || 10),
271
276
  pageOffset: Number(collectionPageOffset || 0),
272
277
  changeReloadDelay: collectionReloadDelay,
package/input-provider.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  debouncer,
3
3
  renderTemplate,
4
- updateConsumerElements
4
+ updateConsumerElements,
5
+ convertStringToFieldParams
5
6
  } from './utils.js';
6
7
 
7
8
  const DEFAULT_DEBOUNCE_DELAY = 800;
@@ -24,7 +25,6 @@ class InputProvider extends HTMLElement {
24
25
 
25
26
  static get observedAttributes() {
26
27
  return [
27
- 'input-id',
28
28
  'list',
29
29
  'type',
30
30
  'placeholder',
@@ -34,7 +34,9 @@ class InputProvider extends HTMLElement {
34
34
  'value',
35
35
  'height',
36
36
  'autocapitalize',
37
- 'autocorrect'
37
+ 'autocorrect',
38
+ 'input-id',
39
+ 'input-props'
38
40
  ];
39
41
  }
40
42
 
@@ -99,6 +101,7 @@ class InputProvider extends HTMLElement {
99
101
  let options = this.getAttribute('options');
100
102
  let height = this.getAttribute('height');
101
103
  let value = this.getAttribute('value') || '';
104
+ let inputProps = this.getAttribute('input-props');
102
105
 
103
106
  let elementType;
104
107
  if (type === 'select') {
@@ -140,6 +143,15 @@ class InputProvider extends HTMLElement {
140
143
  if (placeholder) {
141
144
  this.inputElement.setAttribute('placeholder', placeholder);
142
145
  }
146
+ if (inputProps) {
147
+ let {
148
+ fieldNames: attrNames,
149
+ fieldValues: attrValues
150
+ } = convertStringToFieldParams(inputProps);
151
+ for (let attr of attrNames) {
152
+ this.inputElement.setAttribute(attr, attrValues[attr]);
153
+ }
154
+ }
143
155
 
144
156
  this.appendChild(this.inputElement);
145
157
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "3.17.1",
3
+ "version": "3.19.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {