@sankhyalabs/sankhyablocks 1.3.31-beta.6 → 1.3.31

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.
Files changed (70) hide show
  1. package/dist/cjs/{index-532bcc28.js → index-1133bc2a.js} +9 -419
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/sankhyablocks.cjs.js +2 -2
  4. package/dist/cjs/snk-application.cjs.entry.js +98 -213
  5. package/dist/cjs/snk-pesquisa.cjs.entry.js +2 -2
  6. package/dist/cjs/teste-pesquisa.cjs.entry.js +1 -1
  7. package/dist/collection/collection-manifest.json +0 -4
  8. package/dist/collection/components/snk-application/snk-application.js +48 -165
  9. package/dist/collection/components/snk-pesquisa/snk-pesquisa.css +2 -2
  10. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +21 -52
  11. package/dist/collection/lib/http/data-fetcher/fetchers/grid-config-fetcher.js +3 -4
  12. package/dist/collection/lib/http/data-fetcher/fetchers/pesquisa-fetcher.js +1 -0
  13. package/dist/components/snk-application2.js +97 -213
  14. package/dist/components/snk-pesquisa2.js +1 -1
  15. package/dist/esm/{index-0b078db7.js → index-ffda6382.js} +10 -419
  16. package/dist/esm/loader.js +2 -2
  17. package/dist/esm/sankhyablocks.js +2 -2
  18. package/dist/esm/snk-application.entry.js +98 -213
  19. package/dist/esm/snk-pesquisa.entry.js +2 -2
  20. package/dist/esm/teste-pesquisa.entry.js +1 -1
  21. package/dist/sankhyablocks/{p-a8305c35.entry.js → p-2a7b4cb3.entry.js} +1 -1
  22. package/dist/sankhyablocks/{p-a670853c.entry.js → p-49fdec1f.entry.js} +1 -1
  23. package/dist/sankhyablocks/p-9bc9abe0.entry.js +69 -0
  24. package/dist/sankhyablocks/p-edcb9d8e.js +2 -0
  25. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  26. package/dist/types/components/snk-application/snk-application.d.ts +13 -90
  27. package/dist/types/components.d.ts +2 -334
  28. package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +0 -2
  29. package/dist/types/lib/http/data-fetcher/fetchers/grid-config-fetcher.d.ts +1 -1
  30. package/package.json +5 -5
  31. package/react/components.d.ts +0 -4
  32. package/react/components.js +0 -4
  33. package/react/components.js.map +1 -1
  34. package/dist/cjs/snk-data-unit.cjs.entry.js +0 -189
  35. package/dist/cjs/snk-form.cjs.entry.js +0 -95
  36. package/dist/cjs/snk-grid.cjs.entry.js +0 -64
  37. package/dist/cjs/snk-taskbar.cjs.entry.js +0 -140
  38. package/dist/cjs/taskbar-elements-9d47b416.js +0 -70
  39. package/dist/collection/components/snk-data-unit/snk-data-unit.css +0 -6
  40. package/dist/collection/components/snk-data-unit/snk-data-unit.js +0 -449
  41. package/dist/collection/components/snk-form/snk-form.css +0 -3
  42. package/dist/collection/components/snk-form/snk-form.js +0 -194
  43. package/dist/collection/components/snk-grid/snk-grid.css +0 -5
  44. package/dist/collection/components/snk-grid/snk-grid.js +0 -128
  45. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +0 -65
  46. package/dist/collection/components/snk-taskbar/snk-taskbar.css +0 -3
  47. package/dist/collection/components/snk-taskbar/snk-taskbar.js +0 -252
  48. package/dist/components/snk-data-unit.d.ts +0 -11
  49. package/dist/components/snk-data-unit.js +0 -213
  50. package/dist/components/snk-form.d.ts +0 -11
  51. package/dist/components/snk-form.js +0 -121
  52. package/dist/components/snk-grid.d.ts +0 -11
  53. package/dist/components/snk-grid.js +0 -88
  54. package/dist/components/snk-taskbar.d.ts +0 -11
  55. package/dist/components/snk-taskbar.js +0 -6
  56. package/dist/components/snk-taskbar2.js +0 -221
  57. package/dist/esm/snk-data-unit.entry.js +0 -185
  58. package/dist/esm/snk-form.entry.js +0 -91
  59. package/dist/esm/snk-grid.entry.js +0 -60
  60. package/dist/esm/snk-taskbar.entry.js +0 -136
  61. package/dist/esm/taskbar-elements-3ba30bf4.js +0 -68
  62. package/dist/sankhyablocks/p-3cb106f7.entry.js +0 -69
  63. package/dist/sankhyablocks/p-3fce3190.entry.js +0 -1
  64. package/dist/sankhyablocks/p-560fdf54.entry.js +0 -1
  65. package/dist/sankhyablocks/p-574764bf.js +0 -1
  66. package/dist/sankhyablocks/p-8f7b9a85.entry.js +0 -1
  67. package/dist/sankhyablocks/p-9c225717.entry.js +0 -1
  68. package/dist/sankhyablocks/p-a45dba1a.js +0 -2
  69. package/dist/types/components/snk-taskbar/elements/taskbar-elements.d.ts +0 -25
  70. package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +0 -45
@@ -1,128 +0,0 @@
1
- import { ApplicationContext } from '@sankhyalabs/core';
2
- import { Component, Element, h, Prop, State, Event } from '@stencil/core';
3
- import { TaskbarElement } from '../snk-taskbar/elements/taskbar-elements';
4
- export class SnkGrid {
5
- getHeaderButtons() {
6
- return this._dataState && this._dataState.selectedRecords.length > 0 ? "UPDATE,CLONE,REMOVE,MORE_OPTIONS,DIVIDER,REFRESH" : "REFRESH";
7
- }
8
- actionClickHandler(evt) {
9
- if (evt.detail === TaskbarElement.CONFIG_GRID && this._grid) {
10
- this._grid.openGridConfig();
11
- }
12
- }
13
- componentWillLoad() {
14
- let parent = this._element.parentElement;
15
- while (parent) {
16
- if (parent.tagName.toUpperCase() === "SNK-DATA-UNIT") {
17
- this._snkDataUnit = parent;
18
- this._dataUnit = this._snkDataUnit.dataUnit;
19
- if (!this._dataUnit) {
20
- this._snkDataUnit.addEventListener("dataUnitReady", (evt) => {
21
- this._dataUnit = evt.detail;
22
- });
23
- }
24
- this._snkDataUnit.addEventListener("dataStateChange", (evt) => {
25
- this._dataState = evt.detail;
26
- });
27
- break;
28
- }
29
- parent = parent.parentElement;
30
- }
31
- }
32
- componentWillRender() {
33
- if (this._dataUnit && !this._configLoaded) {
34
- const snkApplication = ApplicationContext.getContextValue("__SNK__APPLICATION__");
35
- if (snkApplication) {
36
- snkApplication.loadGridConfig(this.configName).then(cfg => {
37
- this._gridConfig = cfg;
38
- this._configLoaded = true;
39
- });
40
- }
41
- }
42
- }
43
- render() {
44
- if (!this._configLoaded || !this._dataUnit) {
45
- return undefined;
46
- }
47
- return (h("div", { class: "ez-flex ez-flex--column ez-flex-item--auto ez-padding--large" },
48
- h("div", { class: "ez-row ez-padding-bottom--medium ez-margin-bottom--medium" },
49
- h("div", { class: "ez-col ez-col--sd-9 ez-col--tb-9 ez-align--bottom" },
50
- h("slot", null)),
51
- h("div", { class: "ez-col ez-col--sd-3 ez-col--tb-3 ez-align--right" },
52
- h("snk-taskbar", { onActionClick: evt => this.actionClickHandler(evt), key: "topTaskbar", dataUnit: this._dataUnit, buttons: "FORM_MODE,CONFIG_GRID,INSERT", primaryButton: "INSERT" }))),
53
- h("ez-grid", { ref: ref => this._grid = ref, dataUnit: this._dataUnit, key: "grid-" + this._snkDataUnit.entityName, config: this._gridConfig },
54
- h("snk-taskbar", { dataUnit: this._dataUnit, buttons: this.getHeaderButtons(), slot: "leftButtons", actionsList: this.actionsList }))));
55
- }
56
- static get is() { return "snk-grid"; }
57
- static get encapsulation() { return "scoped"; }
58
- static get originalStyleUrls() { return {
59
- "$": ["snk-grid.css"]
60
- }; }
61
- static get styleUrls() { return {
62
- "$": ["snk-grid.css"]
63
- }; }
64
- static get properties() { return {
65
- "configName": {
66
- "type": "string",
67
- "mutable": false,
68
- "complexType": {
69
- "original": "string",
70
- "resolved": "string",
71
- "references": {}
72
- },
73
- "required": false,
74
- "optional": false,
75
- "docs": {
76
- "tags": [],
77
- "text": "Nome usado para salvar/recuperar a configura\u00E7\u00E3o"
78
- },
79
- "attribute": "config-name",
80
- "reflect": false
81
- },
82
- "actionsList": {
83
- "type": "unknown",
84
- "mutable": false,
85
- "complexType": {
86
- "original": "Array<Action>",
87
- "resolved": "Action[]",
88
- "references": {
89
- "Array": {
90
- "location": "global"
91
- },
92
- "Action": {
93
- "location": "import",
94
- "path": "../snk-taskbar/snk-taskbar"
95
- }
96
- }
97
- },
98
- "required": false,
99
- "optional": false,
100
- "docs": {
101
- "tags": [],
102
- "text": "Lista de a\u00E7\u00F5es que devem ser usadas no bot\u00E3o \"Mais op\u00E7\u00F5es\""
103
- }
104
- }
105
- }; }
106
- static get states() { return {
107
- "_dataUnit": {},
108
- "_configLoaded": {},
109
- "_dataState": {}
110
- }; }
111
- static get events() { return [{
112
- "method": "actionClick",
113
- "name": "actionClick",
114
- "bubbles": true,
115
- "cancelable": true,
116
- "composed": true,
117
- "docs": {
118
- "tags": [],
119
- "text": "Emitido sempre que houver click de bot\u00E3o ou a\u00E7\u00E3o"
120
- },
121
- "complexType": {
122
- "original": "string",
123
- "resolved": "string",
124
- "references": {}
125
- }
126
- }]; }
127
- static get elementRef() { return "_element"; }
128
- }
@@ -1,65 +0,0 @@
1
- import { h } from "@stencil/core";
2
- export var TaskbarElement;
3
- (function (TaskbarElement) {
4
- TaskbarElement["PREVIOUS"] = "PREVIOUS";
5
- TaskbarElement["NEXT"] = "NEXT";
6
- TaskbarElement["REFRESH"] = "REFRESH";
7
- TaskbarElement["UPDATE"] = "UPDATE";
8
- TaskbarElement["CLONE"] = "CLONE";
9
- TaskbarElement["REMOVE"] = "REMOVE";
10
- TaskbarElement["INSERT"] = "INSERT";
11
- TaskbarElement["CANCEL"] = "CANCEL";
12
- TaskbarElement["SAVE"] = "SAVE";
13
- TaskbarElement["GRID_MODE"] = "GRID_MODE";
14
- TaskbarElement["FORM_MODE"] = "FORM_MODE";
15
- TaskbarElement["CONFIG_GRID"] = "CONFIG_GRID";
16
- TaskbarElement["MORE_OPTIONS"] = "MORE_OPTIONS";
17
- TaskbarElement["DIVIDER"] = "DIVIDER";
18
- })(TaskbarElement || (TaskbarElement = {}));
19
- export var AuthorizationElements;
20
- (function (AuthorizationElements) {
21
- AuthorizationElements["UPDATE"] = "UPDATE";
22
- AuthorizationElements["CLONE"] = "CLONE";
23
- AuthorizationElements["REMOVE"] = "REMOVE";
24
- AuthorizationElements["INSERT"] = "INSERT";
25
- AuthorizationElements["CONFIG_GRID"] = "CONFIG_GRID";
26
- })(AuthorizationElements || (AuthorizationElements = {}));
27
- export const buildElem = (element, className, getTitle, action, isEnabled, actions) => {
28
- switch (element) {
29
- case TaskbarElement.PREVIOUS:
30
- return iconButton("chevron-left", element, className, getTitle, action, isEnabled);
31
- case TaskbarElement.NEXT:
32
- return iconButton("chevron-right", element, className, getTitle, action, isEnabled);
33
- case TaskbarElement.REFRESH:
34
- return iconButton("sync", element, className, getTitle, action, isEnabled);
35
- case TaskbarElement.UPDATE:
36
- return iconButton("edit", element, className, getTitle, action, isEnabled);
37
- case TaskbarElement.CLONE:
38
- return iconButton("copy", element, className, getTitle, action, isEnabled);
39
- case TaskbarElement.REMOVE:
40
- return iconButton("delete", element, className, getTitle, action, isEnabled);
41
- case TaskbarElement.INSERT:
42
- return iconTextButton("plus", element, className, getTitle, action, isEnabled);
43
- case TaskbarElement.CANCEL:
44
- return h("ez-button", { label: getTitle(element), size: "small", enabled: isEnabled(element), onClick: () => action(element) });
45
- case TaskbarElement.SAVE:
46
- return iconTextButton("save", element, className, getTitle, action, isEnabled);
47
- case TaskbarElement.GRID_MODE:
48
- return iconButton("table", element, className, getTitle, action, isEnabled);
49
- case TaskbarElement.FORM_MODE:
50
- return iconButton("list", element, className, getTitle, action, isEnabled);
51
- case TaskbarElement.CONFIG_GRID:
52
- return iconButton("settings-inverted", element, className, getTitle, action, isEnabled);
53
- case TaskbarElement.MORE_OPTIONS:
54
- return h("ez-actions-button", { size: "small", class: className, enabled: isEnabled(element), onEzAction: (evt) => action(evt.detail.value), actions: actions });
55
- case TaskbarElement.DIVIDER:
56
- return h("hr", { class: "ez-divider-vertical ez-divider--dark ez-margin-horizontal--medium" });
57
- }
58
- };
59
- function iconButton(iconName, element, className, getTitle, action, isEnabled) {
60
- return h("ez-button", { key: iconName, title: getTitle(element), mode: "icon", size: "small", class: className, iconName: iconName, enabled: isEnabled(element), onClick: () => action(element) });
61
- }
62
- function iconTextButton(iconName, element, className, getTitle, action, isEnabled) {
63
- return h("ez-button", { key: iconName, title: getTitle(element), label: getTitle(element), size: "small", class: className, enabled: isEnabled(element), onClick: () => action(element) },
64
- h("ez-icon", { class: "ez-padding-right--small", slot: "leftIcon", iconName: iconName }));
65
- }
@@ -1,3 +0,0 @@
1
- :host {
2
- display: flex;
3
- }
@@ -1,252 +0,0 @@
1
- import { ApplicationContext } from '@sankhyalabs/core';
2
- import { Component, Event, h, Host, Prop, State, Watch } from '@stencil/core';
3
- import { TaskbarElement, buildElem, AuthorizationElements } from './elements/taskbar-elements';
4
- export class SnkTaskbar {
5
- observeButtons() {
6
- this._definitions = undefined;
7
- }
8
- // Internal methods
9
- elementsFromString(strButtons) {
10
- const elements = [];
11
- if (strButtons) {
12
- strButtons.split(",").forEach(buttonName => {
13
- buttonName = buttonName.trim();
14
- if (this.isAllowed(buttonName)) {
15
- elements.push(buttonName.trim());
16
- }
17
- });
18
- }
19
- return elements;
20
- }
21
- isAllowed(buttonName) {
22
- if (AuthorizationElements[buttonName]) {
23
- return this._permissions ? this._permissions.isSup || this._permissions[buttonName] : false;
24
- }
25
- return true;
26
- }
27
- getTitle(element) {
28
- const pt_br = {
29
- [TaskbarElement.UPDATE]: "Editar",
30
- [TaskbarElement.PREVIOUS]: "Anterior",
31
- [TaskbarElement.NEXT]: "Próximo",
32
- [TaskbarElement.REFRESH]: "Atualizar",
33
- [TaskbarElement.CLONE]: "Duplicar",
34
- [TaskbarElement.REMOVE]: "Excluir",
35
- [TaskbarElement.MORE_OPTIONS]: "Mais Opções",
36
- [TaskbarElement.INSERT]: "Cadastrar",
37
- [TaskbarElement.CANCEL]: "Cancelar",
38
- [TaskbarElement.SAVE]: "Salvar",
39
- [TaskbarElement.GRID_MODE]: "Modo Grade",
40
- [TaskbarElement.CONFIG_GRID]: "Configuração da grade",
41
- [TaskbarElement.FORM_MODE]: "Modo Formulário"
42
- };
43
- return pt_br[element] ? pt_br[element] : "";
44
- }
45
- elementClick(elem) {
46
- if (this.dataUnit) {
47
- switch (elem) {
48
- case TaskbarElement.PREVIOUS:
49
- this.dataUnit.previousRecord();
50
- break;
51
- case TaskbarElement.NEXT:
52
- this.dataUnit.nextRecord();
53
- break;
54
- case TaskbarElement.REFRESH:
55
- this.dataUnit.loadData();
56
- break;
57
- case TaskbarElement.CLONE:
58
- this.dataUnit.copySelected();
59
- break;
60
- case TaskbarElement.REMOVE:
61
- this.dataUnit.removeSelectedRecords();
62
- break;
63
- case TaskbarElement.INSERT:
64
- this.dataUnit.addRecord();
65
- break;
66
- case TaskbarElement.CANCEL:
67
- this.dataUnit.cancelEdition();
68
- break;
69
- case TaskbarElement.SAVE:
70
- this.dataUnit.saveData();
71
- break;
72
- }
73
- }
74
- this.actionClick.emit(elem);
75
- }
76
- isEnabled(elem) {
77
- return !(this.disabledButtons && this.disabledButtons.includes(elem));
78
- }
79
- getElement(index, def) {
80
- let element;
81
- let className = def === this.primaryButton ? "ez-button--primary " : "";
82
- if (index > 1) {
83
- className += "ez-padding-left--medium";
84
- }
85
- element = buildElem(def, className, elem => this.getTitle(elem), elem => this.elementClick(elem), elem => this.isEnabled(elem), this.actionsList);
86
- return element;
87
- }
88
- // Lifecycle
89
- componentWillLoad() {
90
- const snkApplication = ApplicationContext.getContextValue("__SNK__APPLICATION__");
91
- if (snkApplication) {
92
- snkApplication.getAllAccess().then(access => this._permissions = access);
93
- }
94
- else {
95
- this._permissions = {};
96
- }
97
- }
98
- componentWillRender() {
99
- if (this._definitions == undefined && this._permissions) {
100
- this._definitions = this.elementsFromString(this.buttons);
101
- }
102
- }
103
- render() {
104
- if (this._definitions === undefined) {
105
- return undefined;
106
- }
107
- let index = 0;
108
- return (h(Host, null, this._definitions.map((btn) => {
109
- if (btn === TaskbarElement.DIVIDER) {
110
- index = 0;
111
- }
112
- else {
113
- index++;
114
- }
115
- if (TaskbarElement[btn]) {
116
- return this.getElement(index, TaskbarElement[btn]);
117
- }
118
- else {
119
- index;
120
- return h("slot", { name: btn });
121
- }
122
- })));
123
- }
124
- static get is() { return "snk-taskbar"; }
125
- static get encapsulation() { return "scoped"; }
126
- static get originalStyleUrls() { return {
127
- "$": ["snk-taskbar.css"]
128
- }; }
129
- static get styleUrls() { return {
130
- "$": ["snk-taskbar.css"]
131
- }; }
132
- static get properties() { return {
133
- "buttons": {
134
- "type": "string",
135
- "mutable": false,
136
- "complexType": {
137
- "original": "string",
138
- "resolved": "string",
139
- "references": {}
140
- },
141
- "required": false,
142
- "optional": false,
143
- "docs": {
144
- "tags": [],
145
- "text": "Lista separada por virgula, contendo todos os elementos a serem criados"
146
- },
147
- "attribute": "buttons",
148
- "reflect": false
149
- },
150
- "actionsList": {
151
- "type": "unknown",
152
- "mutable": false,
153
- "complexType": {
154
- "original": "Array<Action>",
155
- "resolved": "Action[]",
156
- "references": {
157
- "Array": {
158
- "location": "global"
159
- },
160
- "Action": {
161
- "location": "local"
162
- }
163
- }
164
- },
165
- "required": false,
166
- "optional": false,
167
- "docs": {
168
- "tags": [],
169
- "text": "Lista de a\u00E7\u00F5es que devem ser usadas no bot\u00E3o \"Mais op\u00E7\u00F5es\""
170
- }
171
- },
172
- "primaryButton": {
173
- "type": "string",
174
- "mutable": false,
175
- "complexType": {
176
- "original": "string",
177
- "resolved": "string",
178
- "references": {}
179
- },
180
- "required": false,
181
- "optional": false,
182
- "docs": {
183
- "tags": [],
184
- "text": "Qual bot\u00E3o deve ter apar\u00EAncia prim\u00E1ria"
185
- },
186
- "attribute": "primary-button",
187
- "reflect": false
188
- },
189
- "disabledButtons": {
190
- "type": "unknown",
191
- "mutable": false,
192
- "complexType": {
193
- "original": "Array<string>",
194
- "resolved": "string[]",
195
- "references": {
196
- "Array": {
197
- "location": "global"
198
- }
199
- }
200
- },
201
- "required": false,
202
- "optional": false,
203
- "docs": {
204
- "tags": [],
205
- "text": "Array contendo todos os bot\u00F5es a serem desabilitados"
206
- }
207
- },
208
- "dataUnit": {
209
- "type": "unknown",
210
- "mutable": false,
211
- "complexType": {
212
- "original": "DataUnit",
213
- "resolved": "DataUnit",
214
- "references": {
215
- "DataUnit": {
216
- "location": "import",
217
- "path": "@sankhyalabs/core"
218
- }
219
- }
220
- },
221
- "required": false,
222
- "optional": false,
223
- "docs": {
224
- "tags": [],
225
- "text": "Inst\u00E2ncia do DataUnit"
226
- }
227
- }
228
- }; }
229
- static get states() { return {
230
- "_permissions": {}
231
- }; }
232
- static get events() { return [{
233
- "method": "actionClick",
234
- "name": "actionClick",
235
- "bubbles": true,
236
- "cancelable": true,
237
- "composed": true,
238
- "docs": {
239
- "tags": [],
240
- "text": "Emitido sempre que houver click de bot\u00E3o ou a\u00E7\u00E3o"
241
- },
242
- "complexType": {
243
- "original": "string",
244
- "resolved": "string",
245
- "references": {}
246
- }
247
- }]; }
248
- static get watchers() { return [{
249
- "propName": "buttons",
250
- "methodName": "observeButtons"
251
- }]; }
252
- }
@@ -1,11 +0,0 @@
1
- import type { Components, JSX } from "../types/components";
2
-
3
- interface SnkDataUnit extends Components.SnkDataUnit, HTMLElement {}
4
- export const SnkDataUnit: {
5
- prototype: SnkDataUnit;
6
- new (): SnkDataUnit;
7
- };
8
- /**
9
- * Used to define this component and all nested components recursively.
10
- */
11
- export const defineCustomElement: () => void;
@@ -1,213 +0,0 @@
1
- import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
2
- import { Action, ApplicationContext } from '@sankhyalabs/core';
3
- import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
4
-
5
- const snkDataUnitCss = ".sc-snk-data-unit-h{display:flex;flex-direction:column;height:100%}";
6
-
7
- const SnkDataUnit$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
8
- constructor() {
9
- super();
10
- this.__registerHost();
11
- this.dataStateChange = createEvent(this, "dataStateChange", 7);
12
- this.dataUnitReady = createEvent(this, "dataUnitReady", 7);
13
- this.insertionMode = createEvent(this, "insertionMode", 7);
14
- this._onDataUnitResolve = [];
15
- /**
16
- * Determina quantas linhas são retornadas por página
17
- */
18
- this.pageSize = 150;
19
- /**
20
- * Quando ativada essa propriedade faz com que haja uma carga imediata no DataUnit
21
- */
22
- this.autoLoad = true;
23
- this._dataUnitObserver = (action) => {
24
- let msg = this.getActionInfo(action.type);
25
- if (msg) {
26
- ApplicationUtils.info(msg);
27
- }
28
- if (action.type === Action.RECORDS_ADDED || action.type === Action.RECORDS_COPIED) {
29
- this.insertionMode.emit();
30
- }
31
- const duState = {
32
- insertionMode: false,
33
- hasNext: this.dataUnit.hasNext(),
34
- hasPrevious: this.dataUnit.hasPrevious(),
35
- copyMode: false,
36
- isDirty: this.dataUnit.isDirty(),
37
- selectedRecords: this.dataUnit.getSelectedRecords()
38
- };
39
- this.dataUnit.records.forEach(r => {
40
- if (r.__record__id__.startsWith('NEW_')) {
41
- duState.insertionMode = true;
42
- duState.copyMode || (duState.copyMode = r['__record__source__id__'] != undefined);
43
- }
44
- });
45
- this.dataState = duState;
46
- };
47
- }
48
- observePageSize() {
49
- if (this.dataUnit) {
50
- this.dataUnit.pageSize = this.pageSize;
51
- }
52
- }
53
- observeDataUnitName(newValue, oldValue) {
54
- if (oldValue != newValue) {
55
- this.dataUnit = undefined;
56
- this.dataUnitName = newValue;
57
- this.loadDataUnit();
58
- }
59
- }
60
- observeEntityName(newValue, oldValue) {
61
- if (oldValue != newValue) {
62
- this.dataUnit = undefined;
63
- this.entityName = newValue;
64
- this.loadDataUnit();
65
- }
66
- }
67
- observeDataState(newValue, oldValue) {
68
- if (oldValue != newValue) {
69
- this.dataStateChange.emit(newValue);
70
- }
71
- }
72
- observeDataUnit() {
73
- this.dataUnitReady.emit(this.dataUnit);
74
- }
75
- /**
76
- * Pode-se obter o dataUnit através desse método. Outra forma, é ouvir o evento de
77
- *
78
- * @returns dataUnit
79
- */
80
- async getDataUnit() {
81
- return new Promise((resolve) => {
82
- if (this.dataUnit) {
83
- resolve(this.dataUnit);
84
- }
85
- else {
86
- this._onDataUnitResolve.push(resolve);
87
- }
88
- });
89
- }
90
- async interceptAction(action) {
91
- return new Promise(resolve => {
92
- switch (action.type) {
93
- case Action.SAVING_DATA:
94
- if (this.beforeSave) {
95
- const continueAction = this.beforeSave(this.dataUnit);
96
- if (continueAction instanceof Promise) {
97
- continueAction.then(result => resolve(result ? action : undefined));
98
- }
99
- else {
100
- resolve(continueAction ? action : undefined);
101
- }
102
- }
103
- else {
104
- resolve(action);
105
- }
106
- break;
107
- case Action.DATA_SAVED:
108
- if (this.afterSave) {
109
- this.afterSave(this.dataUnit);
110
- }
111
- else {
112
- resolve(action);
113
- }
114
- break;
115
- case Action.EDITION_CANCELED:
116
- ApplicationUtils.confirm(this.i18n("components.warning"), this.i18n("components.confirmCancelEdition"))
117
- .then((result) => resolve(result ? action : undefined));
118
- break;
119
- case Action.REMOVING_RECORDS:
120
- ApplicationUtils.confirm(this.i18n("components.delete"), this.i18n("components.confirmRemoveRecord"), "delete", true, { btnConfirmDanger: true })
121
- .then((result) => resolve(result ? action : undefined));
122
- break;
123
- default:
124
- resolve(action);
125
- }
126
- });
127
- }
128
- getActionInfo(action) {
129
- if (this.messageBuilder) {
130
- return this.messageBuilder(action, this.dataState, this.dataUnit);
131
- }
132
- if (action === Action.EDITION_CANCELED) {
133
- return this.i18n("components.editionCanceled");
134
- }
135
- }
136
- async loadDataUnit() {
137
- if (!this.dataUnit) {
138
- const app = ApplicationContext.getContextValue("__SNK__APPLICATION__");
139
- if (app && this.entityName) {
140
- const cacheName = this.dataUnitName ? this.dataUnitName : this.entityName;
141
- this.dataUnit = await app.getDataUnit(this.entityName, cacheName);
142
- this.dataUnit.pageSize = this.pageSize;
143
- this.dataUnit.unsubscribe(this._dataUnitObserver);
144
- this.dataUnit.addInterceptor(this);
145
- this.dataUnit.subscribe(this._dataUnitObserver);
146
- let resolver;
147
- while (resolver = this._onDataUnitResolve.pop()) {
148
- resolver(this.dataUnit);
149
- }
150
- if (this.autoLoad) {
151
- this.dataUnit.loadData();
152
- }
153
- }
154
- }
155
- }
156
- i18n(key) {
157
- const pt_br = {
158
- "components.warning": "Aviso",
159
- "components.delete": "Excluir",
160
- "components.confirmRemoveRecord": "Deseja realmente excluir o registro atual?",
161
- "components.confirmCancelEdition": "As alterações realizadas serão descartadas<br/><br/><b>Você realmente gostaria de sair?</b>",
162
- "components.editionCanceled": "Todas as alterações foram descartadas.",
163
- };
164
- return pt_br[key];
165
- }
166
- //---------------------------------------------
167
- // Lifecycle web component
168
- //---------------------------------------------
169
- componentDidRender() {
170
- this.loadDataUnit();
171
- }
172
- render() {
173
- return (h(Host, null));
174
- }
175
- get element() { return this; }
176
- static get watchers() { return {
177
- "pageSize": ["observePageSize"],
178
- "dataUnitName": ["observeDataUnitName"],
179
- "entityName": ["observeEntityName"],
180
- "dataState": ["observeDataState"],
181
- "dataUnit": ["observeDataUnit"]
182
- }; }
183
- static get style() { return snkDataUnitCss; }
184
- }, [2, "snk-data-unit", {
185
- "dataState": [1040],
186
- "dataUnitName": [1, "data-unit-name"],
187
- "entityName": [1, "entity-name"],
188
- "pageSize": [2, "page-size"],
189
- "dataUnit": [1040],
190
- "messageBuilder": [16],
191
- "beforeSave": [16],
192
- "afterSave": [16],
193
- "autoLoad": [4, "auto-load"],
194
- "getDataUnit": [64]
195
- }]);
196
- function defineCustomElement$1() {
197
- if (typeof customElements === "undefined") {
198
- return;
199
- }
200
- const components = ["snk-data-unit"];
201
- components.forEach(tagName => { switch (tagName) {
202
- case "snk-data-unit":
203
- if (!customElements.get(tagName)) {
204
- customElements.define(tagName, SnkDataUnit$1);
205
- }
206
- break;
207
- } });
208
- }
209
-
210
- const SnkDataUnit = SnkDataUnit$1;
211
- const defineCustomElement = defineCustomElement$1;
212
-
213
- export { SnkDataUnit, defineCustomElement };
@@ -1,11 +0,0 @@
1
- import type { Components, JSX } from "../types/components";
2
-
3
- interface SnkForm extends Components.SnkForm, HTMLElement {}
4
- export const SnkForm: {
5
- prototype: SnkForm;
6
- new (): SnkForm;
7
- };
8
- /**
9
- * Used to define this component and all nested components recursively.
10
- */
11
- export const defineCustomElement: () => void;