@sankhyalabs/core 1.0.42 → 1.0.43

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 (135) hide show
  1. package/.eslintignore +1 -1
  2. package/.eslintrc.cjs +34 -34
  3. package/README.md +54 -54
  4. package/dist/dataunit/DataUnit.d.ts +82 -82
  5. package/dist/dataunit/DataUnit.js +278 -278
  6. package/dist/dataunit/metadata/DataType.d.ts +9 -9
  7. package/dist/dataunit/metadata/DataType.js +36 -36
  8. package/dist/dataunit/metadata/UnitMetadata.d.ts +71 -71
  9. package/dist/dataunit/metadata/UnitMetadata.js +31 -31
  10. package/dist/dataunit/state/HistReducer.d.ts +10 -10
  11. package/dist/dataunit/state/HistReducer.js +27 -27
  12. package/dist/dataunit/state/StateManager.d.ts +57 -57
  13. package/dist/dataunit/state/StateManager.js +96 -96
  14. package/dist/dataunit/state/action/DataUnitAction.d.ts +28 -28
  15. package/dist/dataunit/state/action/DataUnitAction.js +33 -33
  16. package/dist/dataunit/state/slice/AddedRecordsSlice.d.ts +11 -11
  17. package/dist/dataunit/state/slice/AddedRecordsSlice.js +25 -25
  18. package/dist/dataunit/state/slice/ChangesSlice.d.ts +12 -12
  19. package/dist/dataunit/state/slice/ChangesSlice.js +72 -72
  20. package/dist/dataunit/state/slice/CurrentRecordsSlice.d.ts +11 -11
  21. package/dist/dataunit/state/slice/CurrentRecordsSlice.js +45 -45
  22. package/dist/dataunit/state/slice/RecordsSlice.d.ts +10 -10
  23. package/dist/dataunit/state/slice/RecordsSlice.js +43 -43
  24. package/dist/dataunit/state/slice/RemovedRecordsSlice.d.ts +9 -9
  25. package/dist/dataunit/state/slice/RemovedRecordsSlice.js +24 -24
  26. package/dist/dataunit/state/slice/SelectionSlice.d.ts +11 -11
  27. package/dist/dataunit/state/slice/SelectionSlice.js +111 -111
  28. package/dist/dataunit/state/slice/UnitMetadataSlice.d.ts +11 -11
  29. package/dist/dataunit/state/slice/UnitMetadataSlice.js +20 -20
  30. package/dist/http/AuthorizedServiceCaller.d.ts +11 -11
  31. package/dist/http/AuthorizedServiceCaller.js +53 -53
  32. package/dist/http/HttpProvider.d.ts +25 -25
  33. package/dist/http/HttpProvider.js +73 -73
  34. package/dist/http/RequestMetadata.d.ts +30 -30
  35. package/dist/http/RequestMetadata.js +24 -24
  36. package/dist/http/SkwHttpProvider.d.ts +9 -9
  37. package/dist/http/SkwHttpProvider.js +66 -66
  38. package/dist/index.d.ts +16 -16
  39. package/dist/index.js +17 -17
  40. package/dist/ui/FloatingManager.d.ts +24 -24
  41. package/dist/ui/FloatingManager.js +122 -122
  42. package/dist/utils/ApplicationContext.d.ts +5 -5
  43. package/dist/utils/ApplicationContext.js +16 -16
  44. package/dist/utils/CriteriaModel.d.ts +109 -109
  45. package/dist/utils/CriteriaModel.js +173 -173
  46. package/dist/utils/CriteriaParameter.d.ts +69 -69
  47. package/dist/utils/CriteriaParameter.js +82 -82
  48. package/dist/utils/DateUtils.d.ts +5 -5
  49. package/dist/utils/DateUtils.js +42 -42
  50. package/dist/utils/MaskFormatter.d.ts +126 -126
  51. package/dist/utils/MaskFormatter.js +275 -275
  52. package/dist/utils/NumberUtils.d.ts +53 -53
  53. package/dist/utils/NumberUtils.js +141 -141
  54. package/dist/utils/StringUtils.d.ts +18 -18
  55. package/dist/utils/StringUtils.js +53 -53
  56. package/dist/utils/TimeFormatter.d.ts +33 -33
  57. package/dist/utils/TimeFormatter.js +97 -97
  58. package/jest.config.ts +16 -16
  59. package/mock/http/XMLHttpRequest-mock.js +25 -25
  60. package/package.json +37 -37
  61. package/src/dataunit/DataUnit.ts +356 -356
  62. package/src/dataunit/metadata/DataType.ts +37 -37
  63. package/src/dataunit/metadata/UnitMetadata.ts +82 -82
  64. package/src/dataunit/state/HistReducer.ts +33 -33
  65. package/src/dataunit/state/StateManager.ts +141 -141
  66. package/src/dataunit/state/action/DataUnitAction.ts +50 -50
  67. package/src/dataunit/state/slice/AddedRecordsSlice.ts +32 -32
  68. package/src/dataunit/state/slice/ChangesSlice.ts +90 -90
  69. package/src/dataunit/state/slice/CurrentRecordsSlice.ts +53 -53
  70. package/src/dataunit/state/slice/RecordsSlice.ts +56 -56
  71. package/src/dataunit/state/slice/RemovedRecordsSlice.ts +29 -29
  72. package/src/dataunit/state/slice/SelectionSlice.ts +130 -130
  73. package/src/dataunit/state/slice/UnitMetadataSlice.ts +29 -29
  74. package/src/http/AuthorizedServiceCaller.ts +58 -58
  75. package/src/http/HttpProvider.ts +93 -93
  76. package/src/http/RequestMetadata.ts +41 -41
  77. package/src/http/SkwHttpProvider.ts +77 -77
  78. package/src/index.ts +44 -44
  79. package/src/ui/FloatingManager.ts +165 -165
  80. package/src/utils/ApplicationContext.ts +18 -18
  81. package/src/utils/CriteriaModel.ts +207 -207
  82. package/src/utils/CriteriaParameter.ts +107 -107
  83. package/src/utils/DateUtils.ts +52 -52
  84. package/src/utils/MaskFormatter.ts +322 -322
  85. package/src/utils/NumberUtils.ts +174 -174
  86. package/src/utils/StringUtils.ts +60 -60
  87. package/src/utils/TimeFormatter.ts +97 -97
  88. package/test/http/HttpProvider.spec.ts +34 -34
  89. package/test/http/SkwHttpProvider.ts.spec.ts +33 -33
  90. package/test/util/CriteriaModel.spec.ts +231 -231
  91. package/test/util/CriteriaParameter.spec.ts +51 -51
  92. package/test/util/MaskFormatter.spec.ts +138 -138
  93. package/test/util/NumberUtils.spec.ts +156 -156
  94. package/test/util/StringUtils.spec.ts +43 -43
  95. package/test/util/TimeFormatter.spec.ts +25 -25
  96. package/tsconfig.json +15 -15
  97. package/dist/application/Application.d.ts +0 -8
  98. package/dist/application/Application.js +0 -19
  99. package/dist/application/Application.js.map +0 -1
  100. package/dist/http/data-fetcher/HttpFetcher.d.ts +0 -14
  101. package/dist/http/data-fetcher/HttpFetcher.js +0 -164
  102. package/dist/http/data-fetcher/HttpFetcher.js.map +0 -1
  103. package/dist/http/data-fetcher/default/DefaultGraphQL.d.ts +0 -3
  104. package/dist/http/data-fetcher/default/DefaultGraphQL.js +0 -18
  105. package/dist/http/data-fetcher/default/DefaultGraphQL.js.map +0 -1
  106. package/dist/http/data-fetcher/default/application-config-fetcher.d.ts +0 -6
  107. package/dist/http/data-fetcher/default/application-config-fetcher.js +0 -21
  108. package/dist/http/data-fetcher/default/application-config-fetcher.js.map +0 -1
  109. package/dist/http/data-fetcher/default/data-unit-graphql.d.ts +0 -3
  110. package/dist/http/data-fetcher/default/data-unit-graphql.js +0 -18
  111. package/dist/http/data-fetcher/default/data-unit-graphql.js.map +0 -1
  112. package/dist/http/data-fetcher/default/dataunit-executor.d.ts +0 -10
  113. package/dist/http/data-fetcher/default/dataunit-executor.js +0 -56
  114. package/dist/http/data-fetcher/default/dataunit-executor.js.map +0 -1
  115. package/dist/http/data-fetcher/default/dataunit-fetcher.d.ts +0 -9
  116. package/dist/http/data-fetcher/default/dataunit-fetcher.js +0 -69
  117. package/dist/http/data-fetcher/default/dataunit-fetcher.js.map +0 -1
  118. package/dist/http/data-fetcher/default/form-config-fetcher.d.ts +0 -2
  119. package/dist/http/data-fetcher/default/form-config-fetcher.js +0 -3
  120. package/dist/http/data-fetcher/default/form-config-fetcher.js.map +0 -1
  121. package/dist/http/data-fetcher/default/grid-config-fetcher.d.ts +0 -2
  122. package/dist/http/data-fetcher/default/grid-config-fetcher.js +0 -3
  123. package/dist/http/data-fetcher/default/grid-config-fetcher.js.map +0 -1
  124. package/dist/http/data-fetcher/default/index.d.ts +0 -0
  125. package/dist/http/data-fetcher/default/index.js +0 -2
  126. package/dist/http/data-fetcher/default/index.js.map +0 -1
  127. package/dist/http/data-fetcher/default/sankhya-graphql.d.ts +0 -3
  128. package/dist/http/data-fetcher/default/sankhya-graphql.js +0 -8
  129. package/dist/http/data-fetcher/default/sankhya-graphql.js.map +0 -1
  130. package/dist/http/data-fetcher/graphql/DefaultGraphQl.d.ts +0 -3
  131. package/dist/http/data-fetcher/graphql/DefaultGraphQl.js +0 -18
  132. package/dist/http/data-fetcher/graphql/DefaultGraphQl.js.map +0 -1
  133. package/dist/http/data-fetcher/state/LoadStateManager.d.ts +0 -23
  134. package/dist/http/data-fetcher/state/LoadStateManager.js +0 -78
  135. package/dist/http/data-fetcher/state/LoadStateManager.js.map +0 -1
@@ -1,71 +1,71 @@
1
- import { DataType } from "./DataType.js";
2
- export interface UnitMetadata {
3
- name: string;
4
- label: string;
5
- fields: Array<FieldDescriptor>;
6
- }
7
- export interface FieldDescriptor {
8
- name: string;
9
- label: string;
10
- dataType: DataType;
11
- userInterface?: UserInterface;
12
- defaultValue?: any;
13
- visible?: boolean;
14
- readOnly?: boolean;
15
- required?: boolean;
16
- properties?: any;
17
- dependencies?: Array<FieldDependency>;
18
- }
19
- export interface FieldDependency {
20
- masterFields: Array<string>;
21
- type: DependencyType;
22
- expression: string;
23
- }
24
- export interface Filter {
25
- name: string;
26
- expression: string;
27
- params?: Array<FilterParam>;
28
- }
29
- export interface FilterParam {
30
- name: string;
31
- value: any;
32
- }
33
- export interface Sort {
34
- field: string;
35
- mode: SortMode;
36
- dataType: DataType;
37
- }
38
- export interface FilterProvider {
39
- getFilter(dataUnit: string): Array<Filter> | undefined;
40
- }
41
- export interface SortingProvider {
42
- getSort(dataUnit: string): Array<Sort> | undefined;
43
- }
44
- export declare enum SortMode {
45
- ASC = "ASC",
46
- DESC = "DESC"
47
- }
48
- export declare enum DependencyType {
49
- SEARCHING = "SEARCHING",
50
- REQUIREMENT = "REQUIREMENT",
51
- VISIBILITY = "REQUIREMENT"
52
- }
53
- export declare enum UserInterface {
54
- FILE = "FILE",
55
- IMAGE = "IMAGE",
56
- DATE = "DATE",
57
- DATETIME = "DATETIME",
58
- TIME = "TIME",
59
- ELAPSEDTIME = "ELAPSEDTIME",
60
- CHECKBOX = "CHECKBOX",
61
- SWITCH = "SWITCH",
62
- OPTIONSELECTOR = "OPTIONSELECTOR",
63
- DECIMALNUMBER = "DECIMALNUMBER",
64
- INTEGERNUMBER = "INTEGERNUMBER",
65
- SEARCH = "SEARCH",
66
- SHORTTEXT = "SHORTTEXT",
67
- PASSWORD = "PASSWORD",
68
- MASKEDTEXT = "MASKEDTEXT",
69
- LONGTEXT = "LONGTEXT",
70
- HTML = "HTML"
71
- }
1
+ import { DataType } from "./DataType.js";
2
+ export interface UnitMetadata {
3
+ name: string;
4
+ label: string;
5
+ fields: Array<FieldDescriptor>;
6
+ }
7
+ export interface FieldDescriptor {
8
+ name: string;
9
+ label: string;
10
+ dataType: DataType;
11
+ userInterface?: UserInterface;
12
+ defaultValue?: any;
13
+ visible?: boolean;
14
+ readOnly?: boolean;
15
+ required?: boolean;
16
+ properties?: any;
17
+ dependencies?: Array<FieldDependency>;
18
+ }
19
+ export interface FieldDependency {
20
+ masterFields: Array<string>;
21
+ type: DependencyType;
22
+ expression: string;
23
+ }
24
+ export interface Filter {
25
+ name: string;
26
+ expression: string;
27
+ params?: Array<FilterParam>;
28
+ }
29
+ export interface FilterParam {
30
+ name: string;
31
+ value: any;
32
+ }
33
+ export interface Sort {
34
+ field: string;
35
+ mode: SortMode;
36
+ dataType: DataType;
37
+ }
38
+ export interface FilterProvider {
39
+ getFilter(dataUnit: string): Array<Filter> | undefined;
40
+ }
41
+ export interface SortingProvider {
42
+ getSort(dataUnit: string): Array<Sort> | undefined;
43
+ }
44
+ export declare enum SortMode {
45
+ ASC = "ASC",
46
+ DESC = "DESC"
47
+ }
48
+ export declare enum DependencyType {
49
+ SEARCHING = "SEARCHING",
50
+ REQUIREMENT = "REQUIREMENT",
51
+ VISIBILITY = "REQUIREMENT"
52
+ }
53
+ export declare enum UserInterface {
54
+ FILE = "FILE",
55
+ IMAGE = "IMAGE",
56
+ DATE = "DATE",
57
+ DATETIME = "DATETIME",
58
+ TIME = "TIME",
59
+ ELAPSEDTIME = "ELAPSEDTIME",
60
+ CHECKBOX = "CHECKBOX",
61
+ SWITCH = "SWITCH",
62
+ OPTIONSELECTOR = "OPTIONSELECTOR",
63
+ DECIMALNUMBER = "DECIMALNUMBER",
64
+ INTEGERNUMBER = "INTEGERNUMBER",
65
+ SEARCH = "SEARCH",
66
+ SHORTTEXT = "SHORTTEXT",
67
+ PASSWORD = "PASSWORD",
68
+ MASKEDTEXT = "MASKEDTEXT",
69
+ LONGTEXT = "LONGTEXT",
70
+ HTML = "HTML"
71
+ }
@@ -1,32 +1,32 @@
1
- export var SortMode;
2
- (function (SortMode) {
3
- SortMode["ASC"] = "ASC";
4
- SortMode["DESC"] = "DESC";
5
- })(SortMode || (SortMode = {}));
6
- export var DependencyType;
7
- (function (DependencyType) {
8
- DependencyType["SEARCHING"] = "SEARCHING";
9
- DependencyType["REQUIREMENT"] = "REQUIREMENT";
10
- DependencyType["VISIBILITY"] = "REQUIREMENT";
11
- })(DependencyType || (DependencyType = {}));
12
- export var UserInterface;
13
- (function (UserInterface) {
14
- UserInterface["FILE"] = "FILE";
15
- UserInterface["IMAGE"] = "IMAGE";
16
- UserInterface["DATE"] = "DATE";
17
- UserInterface["DATETIME"] = "DATETIME";
18
- UserInterface["TIME"] = "TIME";
19
- UserInterface["ELAPSEDTIME"] = "ELAPSEDTIME";
20
- UserInterface["CHECKBOX"] = "CHECKBOX";
21
- UserInterface["SWITCH"] = "SWITCH";
22
- UserInterface["OPTIONSELECTOR"] = "OPTIONSELECTOR";
23
- UserInterface["DECIMALNUMBER"] = "DECIMALNUMBER";
24
- UserInterface["INTEGERNUMBER"] = "INTEGERNUMBER";
25
- UserInterface["SEARCH"] = "SEARCH";
26
- UserInterface["SHORTTEXT"] = "SHORTTEXT";
27
- UserInterface["PASSWORD"] = "PASSWORD";
28
- UserInterface["MASKEDTEXT"] = "MASKEDTEXT";
29
- UserInterface["LONGTEXT"] = "LONGTEXT";
30
- UserInterface["HTML"] = "HTML";
31
- })(UserInterface || (UserInterface = {}));
1
+ export var SortMode;
2
+ (function (SortMode) {
3
+ SortMode["ASC"] = "ASC";
4
+ SortMode["DESC"] = "DESC";
5
+ })(SortMode || (SortMode = {}));
6
+ export var DependencyType;
7
+ (function (DependencyType) {
8
+ DependencyType["SEARCHING"] = "SEARCHING";
9
+ DependencyType["REQUIREMENT"] = "REQUIREMENT";
10
+ DependencyType["VISIBILITY"] = "REQUIREMENT";
11
+ })(DependencyType || (DependencyType = {}));
12
+ export var UserInterface;
13
+ (function (UserInterface) {
14
+ UserInterface["FILE"] = "FILE";
15
+ UserInterface["IMAGE"] = "IMAGE";
16
+ UserInterface["DATE"] = "DATE";
17
+ UserInterface["DATETIME"] = "DATETIME";
18
+ UserInterface["TIME"] = "TIME";
19
+ UserInterface["ELAPSEDTIME"] = "ELAPSEDTIME";
20
+ UserInterface["CHECKBOX"] = "CHECKBOX";
21
+ UserInterface["SWITCH"] = "SWITCH";
22
+ UserInterface["OPTIONSELECTOR"] = "OPTIONSELECTOR";
23
+ UserInterface["DECIMALNUMBER"] = "DECIMALNUMBER";
24
+ UserInterface["INTEGERNUMBER"] = "INTEGERNUMBER";
25
+ UserInterface["SEARCH"] = "SEARCH";
26
+ UserInterface["SHORTTEXT"] = "SHORTTEXT";
27
+ UserInterface["PASSWORD"] = "PASSWORD";
28
+ UserInterface["MASKEDTEXT"] = "MASKEDTEXT";
29
+ UserInterface["LONGTEXT"] = "LONGTEXT";
30
+ UserInterface["HTML"] = "HTML";
31
+ })(UserInterface || (UserInterface = {}));
32
32
  //# sourceMappingURL=UnitMetadata.js.map
@@ -1,10 +1,10 @@
1
- import { ActionReducer } from "./StateManager.js";
2
- import StateManager, { StateAction } from "./StateManager.js";
3
- declare class HistReducerImpl implements ActionReducer {
4
- sliceName: string;
5
- reduce(stateManager: StateManager, _currentState: void, action: StateAction): void;
6
- }
7
- export declare const HistReducer: HistReducerImpl;
8
- export declare const canUndo: (stateManager: StateManager) => boolean;
9
- export declare const canRedo: (stateManager: StateManager) => boolean;
10
- export {};
1
+ import { ActionReducer } from "./StateManager.js";
2
+ import StateManager, { StateAction } from "./StateManager.js";
3
+ declare class HistReducerImpl implements ActionReducer {
4
+ sliceName: string;
5
+ reduce(stateManager: StateManager, _currentState: void, action: StateAction): void;
6
+ }
7
+ export declare const HistReducer: HistReducerImpl;
8
+ export declare const canUndo: (stateManager: StateManager) => boolean;
9
+ export declare const canRedo: (stateManager: StateManager) => boolean;
10
+ export {};
@@ -1,28 +1,28 @@
1
- import { Action } from "./action/DataUnitAction.js";
2
- class HistReducerImpl {
3
- constructor() {
4
- this.sliceName = "";
5
- }
6
- reduce(stateManager, _currentState, action) {
7
- switch (action.type) {
8
- case Action.DATA_SAVED:
9
- case Action.EDITION_CANCELED:
10
- stateManager.clearUndo();
11
- break;
12
- case Action.CHANGE_UNDONE:
13
- stateManager.undo();
14
- break;
15
- case Action.CHANGE_REDONE:
16
- stateManager.redo();
17
- break;
18
- }
19
- }
20
- }
21
- export const HistReducer = new HistReducerImpl();
22
- export const canUndo = (stateManager) => {
23
- return stateManager.canUndo();
24
- };
25
- export const canRedo = (stateManager) => {
26
- return stateManager.canRedo();
27
- };
1
+ import { Action } from "./action/DataUnitAction.js";
2
+ class HistReducerImpl {
3
+ constructor() {
4
+ this.sliceName = "";
5
+ }
6
+ reduce(stateManager, _currentState, action) {
7
+ switch (action.type) {
8
+ case Action.DATA_SAVED:
9
+ case Action.EDITION_CANCELED:
10
+ stateManager.clearUndo();
11
+ break;
12
+ case Action.CHANGE_UNDONE:
13
+ stateManager.undo();
14
+ break;
15
+ case Action.CHANGE_REDONE:
16
+ stateManager.redo();
17
+ break;
18
+ }
19
+ }
20
+ }
21
+ export const HistReducer = new HistReducerImpl();
22
+ export const canUndo = (stateManager) => {
23
+ return stateManager.canUndo();
24
+ };
25
+ export const canRedo = (stateManager) => {
26
+ return stateManager.canRedo();
27
+ };
28
28
  //# sourceMappingURL=HistReducer.js.map
@@ -1,57 +1,57 @@
1
- /**
2
- * Essa classe representa uma interpretação do padrão de projetos Flux.
3
- * No padrão Flux os dados da aplicação são chamados de "estado" e existem
4
- * algumas regras para gerenciamento/manipulação desse estado:
5
- *
6
- * 1 - O estado é imutável.
7
- * 2 - Toda modificação de estado é representada por uma "ação".
8
- * 3 - Quando "ações" acontecem a "store" cria um novo estado e notifica a todos interessados.
9
- *
10
- * Nessa interpretação desse design pattern, o StateManager faz o papel da store,
11
- * notificando os manipuladores de estado (handlers), que são responsáveis por pedaços
12
- * do estado (slices).
13
- *
14
- * O StateManager mantém dois tipos de estados: "Histórico" e "Não Histórico". No estado
15
- * "Histórico", sempre que uma alteração de estado acontece, o estado anterior é guardado em
16
- * uma pilha, o que permite que possamos voltar no tempo, desfazendo algumas ações
17
- */
18
- export default class StateManager {
19
- private _reducers;
20
- private _past;
21
- private _future;
22
- private _present;
23
- private _nonHist;
24
- private _histClean;
25
- constructor(reducers: Array<ActionReducer>);
26
- process(action: StateAction): void;
27
- select(sliceName: string, selector: (state: any) => any): any;
28
- private isHistoric;
29
- private updateSlice;
30
- private getSlice;
31
- canUndo(): boolean;
32
- canRedo(): boolean;
33
- undo(): void;
34
- redo(): void;
35
- clearUndo(): void;
36
- persist(): void;
37
- }
38
- /**
39
- * Baseado no padrão Flux, qualquer alteração de estado parte de uma ação.
40
- * Essa ação pode conter um payload ou não.
41
- */
42
- export interface StateAction {
43
- /**
44
- * O tipo da ação representa o que aconteceu. Com base nesse tipo
45
- * os manipuladores de estado agem criando um novo estado.
46
- */
47
- type: string;
48
- /**
49
- * Muitas ações contém informações importantes para compor o novo estado.
50
- * Isso é chamado de payload.
51
- */
52
- payload?: any;
53
- }
54
- export interface ActionReducer {
55
- sliceName: string;
56
- reduce(stateManager: StateManager, state: any, action: StateAction): any;
57
- }
1
+ /**
2
+ * Essa classe representa uma interpretação do padrão de projetos Flux.
3
+ * No padrão Flux os dados da aplicação são chamados de "estado" e existem
4
+ * algumas regras para gerenciamento/manipulação desse estado:
5
+ *
6
+ * 1 - O estado é imutável.
7
+ * 2 - Toda modificação de estado é representada por uma "ação".
8
+ * 3 - Quando "ações" acontecem a "store" cria um novo estado e notifica a todos interessados.
9
+ *
10
+ * Nessa interpretação desse design pattern, o StateManager faz o papel da store,
11
+ * notificando os manipuladores de estado (handlers), que são responsáveis por pedaços
12
+ * do estado (slices).
13
+ *
14
+ * O StateManager mantém dois tipos de estados: "Histórico" e "Não Histórico". No estado
15
+ * "Histórico", sempre que uma alteração de estado acontece, o estado anterior é guardado em
16
+ * uma pilha, o que permite que possamos voltar no tempo, desfazendo algumas ações
17
+ */
18
+ export default class StateManager {
19
+ private _reducers;
20
+ private _past;
21
+ private _future;
22
+ private _present;
23
+ private _nonHist;
24
+ private _histClean;
25
+ constructor(reducers: Array<ActionReducer>);
26
+ process(action: StateAction): void;
27
+ select(sliceName: string, selector: (state: any) => any): any;
28
+ private isHistoric;
29
+ private updateSlice;
30
+ private getSlice;
31
+ canUndo(): boolean;
32
+ canRedo(): boolean;
33
+ undo(): void;
34
+ redo(): void;
35
+ clearUndo(): void;
36
+ persist(): void;
37
+ }
38
+ /**
39
+ * Baseado no padrão Flux, qualquer alteração de estado parte de uma ação.
40
+ * Essa ação pode conter um payload ou não.
41
+ */
42
+ export interface StateAction {
43
+ /**
44
+ * O tipo da ação representa o que aconteceu. Com base nesse tipo
45
+ * os manipuladores de estado agem criando um novo estado.
46
+ */
47
+ type: string;
48
+ /**
49
+ * Muitas ações contém informações importantes para compor o novo estado.
50
+ * Isso é chamado de payload.
51
+ */
52
+ payload?: any;
53
+ }
54
+ export interface ActionReducer {
55
+ sliceName: string;
56
+ reduce(stateManager: StateManager, state: any, action: StateAction): any;
57
+ }
@@ -1,97 +1,97 @@
1
- /**
2
- * Essa classe representa uma interpretação do padrão de projetos Flux.
3
- * No padrão Flux os dados da aplicação são chamados de "estado" e existem
4
- * algumas regras para gerenciamento/manipulação desse estado:
5
- *
6
- * 1 - O estado é imutável.
7
- * 2 - Toda modificação de estado é representada por uma "ação".
8
- * 3 - Quando "ações" acontecem a "store" cria um novo estado e notifica a todos interessados.
9
- *
10
- * Nessa interpretação desse design pattern, o StateManager faz o papel da store,
11
- * notificando os manipuladores de estado (handlers), que são responsáveis por pedaços
12
- * do estado (slices).
13
- *
14
- * O StateManager mantém dois tipos de estados: "Histórico" e "Não Histórico". No estado
15
- * "Histórico", sempre que uma alteração de estado acontece, o estado anterior é guardado em
16
- * uma pilha, o que permite que possamos voltar no tempo, desfazendo algumas ações
17
- */
18
- export default class StateManager {
19
- constructor(reducers) {
20
- this._past = [];
21
- this._future = [];
22
- this._present = {};
23
- this._nonHist = {};
24
- this._histClean = false;
25
- this._reducers = reducers;
26
- }
27
- process(action) {
28
- const oldPresent = this._present;
29
- let hasHistChange = false;
30
- this._histClean = false;
31
- this._reducers.forEach(reducer => {
32
- const sliceName = reducer.sliceName;
33
- const isHistoric = this.isHistoric(sliceName);
34
- const oldSlice = this.getSlice(sliceName, isHistoric);
35
- const newSlice = reducer.reduce(this, oldSlice, action);
36
- if (newSlice !== oldSlice) {
37
- this.updateSlice(sliceName, newSlice, isHistoric);
38
- hasHistChange || (hasHistChange = isHistoric);
39
- }
40
- });
41
- if (hasHistChange && !this._histClean) {
42
- this._past.push(oldPresent);
43
- this._future = [];
44
- document.dispatchEvent(new CustomEvent("undoableAction", { detail: this }));
45
- }
46
- }
47
- select(sliceName, selector) {
48
- const isHistoric = this.isHistoric(sliceName);
49
- return selector(this.getSlice(sliceName, isHistoric));
50
- }
51
- isHistoric(slice) {
52
- return slice.startsWith("hist::");
53
- }
54
- updateSlice(name, slice, isHistoric) {
55
- if (isHistoric) {
56
- this._present = Object.assign(Object.assign({}, this._present), { [name]: slice });
57
- if (slice === undefined) {
58
- delete this._present[name];
59
- }
60
- }
61
- else {
62
- this._nonHist = Object.assign(Object.assign({}, this._nonHist), { [name]: slice });
63
- if (slice === undefined) {
64
- delete this._nonHist[name];
65
- }
66
- }
67
- }
68
- getSlice(name, isHistoric) {
69
- return isHistoric ? this._present[name] : this._nonHist[name];
70
- }
71
- canUndo() {
72
- return this._past.length > 0;
73
- }
74
- canRedo() {
75
- return this._future.length > 0;
76
- }
77
- undo() {
78
- if (this.canUndo()) {
79
- this._future.push(this._present);
80
- this._present = this._past.pop();
81
- }
82
- }
83
- redo() {
84
- if (this.canRedo()) {
85
- this._past.push(this._present);
86
- this._present = this._future.pop();
87
- }
88
- }
89
- clearUndo() {
90
- this._histClean = true;
91
- this._past = [];
92
- this._future = [];
93
- }
94
- persist() {
95
- }
96
- }
1
+ /**
2
+ * Essa classe representa uma interpretação do padrão de projetos Flux.
3
+ * No padrão Flux os dados da aplicação são chamados de "estado" e existem
4
+ * algumas regras para gerenciamento/manipulação desse estado:
5
+ *
6
+ * 1 - O estado é imutável.
7
+ * 2 - Toda modificação de estado é representada por uma "ação".
8
+ * 3 - Quando "ações" acontecem a "store" cria um novo estado e notifica a todos interessados.
9
+ *
10
+ * Nessa interpretação desse design pattern, o StateManager faz o papel da store,
11
+ * notificando os manipuladores de estado (handlers), que são responsáveis por pedaços
12
+ * do estado (slices).
13
+ *
14
+ * O StateManager mantém dois tipos de estados: "Histórico" e "Não Histórico". No estado
15
+ * "Histórico", sempre que uma alteração de estado acontece, o estado anterior é guardado em
16
+ * uma pilha, o que permite que possamos voltar no tempo, desfazendo algumas ações
17
+ */
18
+ export default class StateManager {
19
+ constructor(reducers) {
20
+ this._past = [];
21
+ this._future = [];
22
+ this._present = {};
23
+ this._nonHist = {};
24
+ this._histClean = false;
25
+ this._reducers = reducers;
26
+ }
27
+ process(action) {
28
+ const oldPresent = this._present;
29
+ let hasHistChange = false;
30
+ this._histClean = false;
31
+ this._reducers.forEach(reducer => {
32
+ const sliceName = reducer.sliceName;
33
+ const isHistoric = this.isHistoric(sliceName);
34
+ const oldSlice = this.getSlice(sliceName, isHistoric);
35
+ const newSlice = reducer.reduce(this, oldSlice, action);
36
+ if (newSlice !== oldSlice) {
37
+ this.updateSlice(sliceName, newSlice, isHistoric);
38
+ hasHistChange || (hasHistChange = isHistoric);
39
+ }
40
+ });
41
+ if (hasHistChange && !this._histClean) {
42
+ this._past.push(oldPresent);
43
+ this._future = [];
44
+ document.dispatchEvent(new CustomEvent("undoableAction", { detail: this }));
45
+ }
46
+ }
47
+ select(sliceName, selector) {
48
+ const isHistoric = this.isHistoric(sliceName);
49
+ return selector(this.getSlice(sliceName, isHistoric));
50
+ }
51
+ isHistoric(slice) {
52
+ return slice.startsWith("hist::");
53
+ }
54
+ updateSlice(name, slice, isHistoric) {
55
+ if (isHistoric) {
56
+ this._present = Object.assign(Object.assign({}, this._present), { [name]: slice });
57
+ if (slice === undefined) {
58
+ delete this._present[name];
59
+ }
60
+ }
61
+ else {
62
+ this._nonHist = Object.assign(Object.assign({}, this._nonHist), { [name]: slice });
63
+ if (slice === undefined) {
64
+ delete this._nonHist[name];
65
+ }
66
+ }
67
+ }
68
+ getSlice(name, isHistoric) {
69
+ return isHistoric ? this._present[name] : this._nonHist[name];
70
+ }
71
+ canUndo() {
72
+ return this._past.length > 0;
73
+ }
74
+ canRedo() {
75
+ return this._future.length > 0;
76
+ }
77
+ undo() {
78
+ if (this.canUndo()) {
79
+ this._future.push(this._present);
80
+ this._present = this._past.pop();
81
+ }
82
+ }
83
+ redo() {
84
+ if (this.canRedo()) {
85
+ this._past.push(this._present);
86
+ this._present = this._future.pop();
87
+ }
88
+ }
89
+ clearUndo() {
90
+ this._histClean = true;
91
+ this._past = [];
92
+ this._future = [];
93
+ }
94
+ persist() {
95
+ }
96
+ }
97
97
  //# sourceMappingURL=StateManager.js.map
@@ -1,28 +1,28 @@
1
- import { StateAction } from "../StateManager.js";
2
- export declare class DataUnitAction implements StateAction {
3
- private _type;
4
- private _payload;
5
- constructor(type: Action, payload?: any);
6
- get type(): Action;
7
- get payload(): any;
8
- }
9
- export declare enum Action {
10
- LOADING_METADATA = "loadingMetadata",
11
- METADATA_LOADED = "metadataLoaded",
12
- LOADING_DATA = "loadingData",
13
- DATA_LOADED = "dataLoaded",
14
- SAVING_DATA = "savingData",
15
- DATA_SAVED = "dataSaved",
16
- REMOVING_RECORDS = "removingRecords",
17
- RECORDS_REMOVED = "recordsRemoved",
18
- RECORDS_ADDED = "recordsAdded",
19
- RECORDS_COPIED = "recordsCopied",
20
- DATA_CHANGED = "dataChanged",
21
- EDITION_CANCELED = "editionCanceled",
22
- CHANGE_UNDONE = "changeUndone",
23
- CHANGE_REDONE = "changeRedone",
24
- SELECTION_CHANGED = "selectionChanged",
25
- NEXT_SELECTED = "nextSelected",
26
- PREVIOUS_SELECTED = "previousSelected",
27
- STATE_CHANGED = "stateChanged"
28
- }
1
+ import { StateAction } from "../StateManager.js";
2
+ export declare class DataUnitAction implements StateAction {
3
+ private _type;
4
+ private _payload;
5
+ constructor(type: Action, payload?: any);
6
+ get type(): Action;
7
+ get payload(): any;
8
+ }
9
+ export declare enum Action {
10
+ LOADING_METADATA = "loadingMetadata",
11
+ METADATA_LOADED = "metadataLoaded",
12
+ LOADING_DATA = "loadingData",
13
+ DATA_LOADED = "dataLoaded",
14
+ SAVING_DATA = "savingData",
15
+ DATA_SAVED = "dataSaved",
16
+ REMOVING_RECORDS = "removingRecords",
17
+ RECORDS_REMOVED = "recordsRemoved",
18
+ RECORDS_ADDED = "recordsAdded",
19
+ RECORDS_COPIED = "recordsCopied",
20
+ DATA_CHANGED = "dataChanged",
21
+ EDITION_CANCELED = "editionCanceled",
22
+ CHANGE_UNDONE = "changeUndone",
23
+ CHANGE_REDONE = "changeRedone",
24
+ SELECTION_CHANGED = "selectionChanged",
25
+ NEXT_SELECTED = "nextSelected",
26
+ PREVIOUS_SELECTED = "previousSelected",
27
+ STATE_CHANGED = "stateChanged"
28
+ }