@dile/crud 2.12.3 → 2.13.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.
@@ -0,0 +1,5 @@
1
+ import { DileAjaxInputSuggestions } from './src/DileAjaxInputSuggestions.js';
2
+
3
+ if (!customElements.get('dile-ajax-input-suggestions')) {
4
+ customElements.define('dile-ajax-input-suggestions', DileAjaxInputSuggestions);
5
+ }
@@ -0,0 +1 @@
1
+ export { DileAjaxInputSuggestions } from './src/DileAjaxInputSuggestions.js';
@@ -0,0 +1,59 @@
1
+ import { DileInputSuggestionsBase } from '@dile/ui/components/input-suggestions/index.js';
2
+ import { DileAxios } from '../../../lib/DileAxios.js';
3
+
4
+ /**
5
+ * # dile-ajax-input-suggestions
6
+ *
7
+ * Ajax variant of DileInputSuggestionsBase (`@dile/ui`), with the same request API as
8
+ * dile-ajax-select-crud-overlay. It requests the suggestions to `endpoint` with Axios
9
+ * (DileAxios), sending the typed text in `queryStringVariable`.
10
+ *
11
+ * How the list is extracted from the response, by priority:
12
+ * 1. `getSelectResultList(response)`, which receives the whole body;
13
+ * 2. `resultDataProperty`, name of the first-level property holding the array;
14
+ * 3. the whole body, when it already is the array.
15
+ */
16
+ export class DileAjaxInputSuggestions extends DileAxios(DileInputSuggestionsBase) {
17
+ static get properties() {
18
+ return {
19
+ endpoint: { type: String },
20
+ queryStringVariable: { type: String },
21
+ additionalQueryString: { type: Object },
22
+ resultDataProperty: { type: String },
23
+ maxResults: { type: Number },
24
+ pageParamName: { type: String },
25
+ getSelectResultList: { type: Object },
26
+ };
27
+ }
28
+
29
+ constructor() {
30
+ super();
31
+ this.queryStringVariable = 'q';
32
+ }
33
+
34
+ loadData() {
35
+ const requestId = this._requestId;
36
+ const params = { ...(this.additionalQueryString || {}) };
37
+ if (this.pageParamName && this.maxResults) {
38
+ params[this.pageParamName] = this.maxResults;
39
+ }
40
+ params[this.queryStringVariable] = this.keyword;
41
+ this.axiosInstance
42
+ .get(this.endpoint, { params })
43
+ .then((response) => {
44
+ const body = response.data;
45
+ this.setResults(body?.error ? [] : this.getResultList(body), requestId);
46
+ })
47
+ .catch(() => this.setResults([], requestId));
48
+ }
49
+
50
+ getResultList(body) {
51
+ if (typeof this.getSelectResultList === 'function') {
52
+ return this.getSelectResultList(body);
53
+ }
54
+ if (this.resultDataProperty) {
55
+ return body?.[this.resultDataProperty];
56
+ }
57
+ return body;
58
+ }
59
+ }
@@ -0,0 +1,5 @@
1
+ import { DileAjaxInputTags } from './src/DileAjaxInputTags.js';
2
+
3
+ if (!customElements.get('dile-ajax-input-tags')) {
4
+ customElements.define('dile-ajax-input-tags', DileAjaxInputTags);
5
+ }
@@ -0,0 +1 @@
1
+ export { DileAjaxInputTags } from './src/DileAjaxInputTags.js';
@@ -0,0 +1,10 @@
1
+ import { DileInputTagsMixin } from '@dile/ui/components/input-tags/index.js';
2
+ import { DileAjaxInputSuggestions } from '../../ajax-input-suggestions/src/DileAjaxInputSuggestions.js';
3
+
4
+ /**
5
+ * # dile-ajax-input-tags
6
+ *
7
+ * Tags editor that requests its suggestions to `endpoint`, with the same API as
8
+ * dile-ajax-input-suggestions. See DileInputTagsMixin in `@dile/ui`.
9
+ */
10
+ export class DileAjaxInputTags extends DileInputTagsMixin(DileAjaxInputSuggestions) {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "2.12.3",
3
+ "version": "2.13.0",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,12 +26,12 @@
26
26
  "homepage": "https://dile-components.com/",
27
27
  "dependencies": {
28
28
  "@dile/image-cropper": "^0.1.1",
29
- "@dile/ui": "^3.20.2",
29
+ "@dile/ui": "^3.21.0",
30
30
  "axios": "^1.19.0",
31
31
  "lit": "^2.7.0 || ^3.0.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "c6bb68030489b454927cbe7f36dd49388d87ff71"
36
+ "gitHead": "425f1cf93f61a2703365205c699b8a6fc64e538d"
37
37
  }