@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,42 +1,42 @@
1
- /**
2
- * Representa as propriedades necessárias para se executar uma requisição.
3
- */
4
- export class RequestMetadata {
5
-
6
- /** A URL a ser chamada */
7
- public url: string;
8
-
9
- /** O verbo HTTP */
10
- public method: Method;
11
-
12
- /** Tempo limite de espera pela resposta */
13
- public timeout: number = 30000;
14
-
15
- /** Headers para serem enviados na requisição */
16
- public headers: Array<Header>;
17
-
18
- /**
19
- * @param {string} url A URL que deve ser chamada.
20
- * @param {Method} method O Método da requisição (GET, PUT, POST ou DELETE).
21
- */
22
- public constructor(url: string, method: Method, headers?:Array<Header>) {
23
- this.url = url;
24
- this.method = method;
25
- this.headers = headers || [];
26
- }
27
-
28
- }
29
-
30
- /** Representa os verbos HTTP suportados */
31
- export enum Method {
32
- GET,
33
- PUT,
34
- POST,
35
- DELETE
36
- }
37
-
38
- /** Headers HTTP */
39
- export interface Header{
40
- name: string;
41
- value: string;
1
+ /**
2
+ * Representa as propriedades necessárias para se executar uma requisição.
3
+ */
4
+ export class RequestMetadata {
5
+
6
+ /** A URL a ser chamada */
7
+ public url: string;
8
+
9
+ /** O verbo HTTP */
10
+ public method: Method;
11
+
12
+ /** Tempo limite de espera pela resposta */
13
+ public timeout: number = 30000;
14
+
15
+ /** Headers para serem enviados na requisição */
16
+ public headers: Array<Header>;
17
+
18
+ /**
19
+ * @param {string} url A URL que deve ser chamada.
20
+ * @param {Method} method O Método da requisição (GET, PUT, POST ou DELETE).
21
+ */
22
+ public constructor(url: string, method: Method, headers?:Array<Header>) {
23
+ this.url = url;
24
+ this.method = method;
25
+ this.headers = headers || [];
26
+ }
27
+
28
+ }
29
+
30
+ /** Representa os verbos HTTP suportados */
31
+ export enum Method {
32
+ GET,
33
+ PUT,
34
+ POST,
35
+ DELETE
36
+ }
37
+
38
+ /** Headers HTTP */
39
+ export interface Header{
40
+ name: string;
41
+ value: string;
42
42
  }
@@ -1,78 +1,78 @@
1
- import { HttpProvider } from "./HttpProvider.js"
2
- import { Header } from "./RequestMetadata.js";
3
-
4
- export class SkwHttpProvider{
5
- static _counter:number = 0;
6
-
7
- static STATUS_ERROR:number = 0;
8
- static STATUS_OK:number = 1;
9
- static STATUS_INFO:number = 2;
10
- static STATUS_TIMEOUT:number = 3;
11
- static STATUS_CANCELED:number = 4;
12
-
13
- public static callService(serviceName: string, content: Object): Promise<Object>{
14
- return new Promise<Object>((resolve, reject) => {
15
- let host:string = "http://192.168.1.218:8503/mge/";
16
- let appName:string = "ListaTarefa";
17
- let module = 'mge';
18
- this._counter++;
19
-
20
- if (serviceName.indexOf("@") > -1) {
21
- let s = serviceName.split("@");
22
- module = s[0];
23
- serviceName = s[1];
24
- }
25
-
26
- let url = `${host}/${module}/service.sbr?serviceName=${serviceName}&counter=${this._counter}&application=${appName}&outputType=json&preventTransform=false`;
27
-
28
- let requestContent = {
29
- serviceName: serviceName,
30
- requestBody: content
31
- };
32
-
33
- let headers = new Headers();
34
-
35
- headers.append("Content-Type", "application/json")
36
- //headers.append("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
37
- //headers.append("Access-Control-Allow-Origin", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
38
-
39
- fetch(url, {
40
- body: JSON.stringify(requestContent),
41
- method: 'POST',
42
- headers: headers
43
- })
44
- .then( res => res.json())
45
- .then( (data) => {
46
- console.log(data);
47
- });
48
-
49
- /*HttpProvider.post(url, requestContent, headers)
50
- .then(res => {
51
- if (!res.hasOwnProperty('status') ||
52
- res.status == this.STATUS_ERROR ||
53
- res.status == this.STATUS_TIMEOUT) {
54
-
55
- let statusMessage = res.statusMessage;
56
-
57
- if (!statusMessage) {
58
- statusMessage = 'Erro não identificado.'
59
- }
60
- //TODO: No futuro, exibir mensagens de erro. (MessageUtils.showError)
61
- reject(new Error(statusMessage));
62
- }else if (res.status == this.STATUS_CANCELED) {
63
- if (res.statusMessage){
64
- console.warn(res.statusMessage);
65
- }
66
- }else{
67
- resolve(res);
68
- }
69
-
70
- if (res.status == this.STATUS_INFO) {
71
- //TODO: No futuro, exibir mensagens de erro. (MessageUtils.showAlert)
72
- console.info(res.statusMessage);
73
- }
74
- })
75
- .catch((e)=>{reject(e)});*/
76
- })
77
- }
1
+ import { HttpProvider } from "./HttpProvider.js"
2
+ import { Header } from "./RequestMetadata.js";
3
+
4
+ export class SkwHttpProvider{
5
+ static _counter:number = 0;
6
+
7
+ static STATUS_ERROR:number = 0;
8
+ static STATUS_OK:number = 1;
9
+ static STATUS_INFO:number = 2;
10
+ static STATUS_TIMEOUT:number = 3;
11
+ static STATUS_CANCELED:number = 4;
12
+
13
+ public static callService(serviceName: string, content: Object): Promise<Object>{
14
+ return new Promise<Object>((resolve, reject) => {
15
+ let host:string = "http://192.168.1.218:8503/mge/";
16
+ let appName:string = "ListaTarefa";
17
+ let module = 'mge';
18
+ this._counter++;
19
+
20
+ if (serviceName.indexOf("@") > -1) {
21
+ let s = serviceName.split("@");
22
+ module = s[0];
23
+ serviceName = s[1];
24
+ }
25
+
26
+ let url = `${host}/${module}/service.sbr?serviceName=${serviceName}&counter=${this._counter}&application=${appName}&outputType=json&preventTransform=false`;
27
+
28
+ let requestContent = {
29
+ serviceName: serviceName,
30
+ requestBody: content
31
+ };
32
+
33
+ let headers = new Headers();
34
+
35
+ headers.append("Content-Type", "application/json")
36
+ //headers.append("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
37
+ //headers.append("Access-Control-Allow-Origin", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
38
+
39
+ fetch(url, {
40
+ body: JSON.stringify(requestContent),
41
+ method: 'POST',
42
+ headers: headers
43
+ })
44
+ .then( res => res.json())
45
+ .then( (data) => {
46
+ console.log(data);
47
+ });
48
+
49
+ /*HttpProvider.post(url, requestContent, headers)
50
+ .then(res => {
51
+ if (!res.hasOwnProperty('status') ||
52
+ res.status == this.STATUS_ERROR ||
53
+ res.status == this.STATUS_TIMEOUT) {
54
+
55
+ let statusMessage = res.statusMessage;
56
+
57
+ if (!statusMessage) {
58
+ statusMessage = 'Erro não identificado.'
59
+ }
60
+ //TODO: No futuro, exibir mensagens de erro. (MessageUtils.showError)
61
+ reject(new Error(statusMessage));
62
+ }else if (res.status == this.STATUS_CANCELED) {
63
+ if (res.statusMessage){
64
+ console.warn(res.statusMessage);
65
+ }
66
+ }else{
67
+ resolve(res);
68
+ }
69
+
70
+ if (res.status == this.STATUS_INFO) {
71
+ //TODO: No futuro, exibir mensagens de erro. (MessageUtils.showAlert)
72
+ console.info(res.statusMessage);
73
+ }
74
+ })
75
+ .catch((e)=>{reject(e)});*/
76
+ })
77
+ }
78
78
  }
package/src/index.ts CHANGED
@@ -1,44 +1,44 @@
1
- import { StringUtils } from "./utils/StringUtils.js";
2
- import { NumberUtils } from "./utils/NumberUtils.js";
3
- import { MaskFormatter } from "./utils/MaskFormatter.js";
4
- import FloatingManager from "./ui/FloatingManager.js";
5
- import DateUtils from "./utils/DateUtils.js";
6
- import { TimeFormatter } from "./utils/TimeFormatter.js";
7
- import { HttpProvider } from "./http/HttpProvider.js";
8
- import { SkwHttpProvider } from "./http/SkwHttpProvider.js";
9
- import { RequestMetadata } from "./http/RequestMetadata.js";
10
- import { AuthorizedServiceCaller } from "./http/AuthorizedServiceCaller.js";
11
- import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor} from "./dataunit/DataUnit.js";
12
- import { DataType } from "./dataunit/metadata/DataType.js";
13
- import { UnitMetadata, FieldDescriptor, UserInterface, Sort, Filter } from "./dataunit/metadata/UnitMetadata.js";
14
- import { DataUnitAction, Action } from "./dataunit/state/action/DataUnitAction.js";
15
- import ApplicationContext from "./utils/ApplicationContext.js";
16
-
17
- /*Classes públicas no pacote*/
18
- export {
19
- StringUtils,
20
- MaskFormatter,
21
- NumberUtils,
22
- FloatingManager,
23
- DateUtils,
24
- TimeFormatter,
25
- SkwHttpProvider,
26
- HttpProvider,
27
- RequestMetadata,
28
- AuthorizedServiceCaller,
29
- DataUnit,
30
- Record,
31
- SavedRecord,
32
- DataType,
33
- UnitMetadata,
34
- FieldDescriptor,
35
- UserInterface,
36
- DataUnitAction,
37
- Action,
38
- Change,
39
- Sort,
40
- Filter,
41
- ChangeOperation,
42
- DUActionInterceptor,
43
- ApplicationContext
44
- };
1
+ import { StringUtils } from "./utils/StringUtils.js";
2
+ import { NumberUtils } from "./utils/NumberUtils.js";
3
+ import { MaskFormatter } from "./utils/MaskFormatter.js";
4
+ import FloatingManager from "./ui/FloatingManager.js";
5
+ import DateUtils from "./utils/DateUtils.js";
6
+ import { TimeFormatter } from "./utils/TimeFormatter.js";
7
+ import { HttpProvider } from "./http/HttpProvider.js";
8
+ import { SkwHttpProvider } from "./http/SkwHttpProvider.js";
9
+ import { RequestMetadata } from "./http/RequestMetadata.js";
10
+ import { AuthorizedServiceCaller } from "./http/AuthorizedServiceCaller.js";
11
+ import DataUnit, {SavedRecord, Record, Change, ChangeOperation, DUActionInterceptor} from "./dataunit/DataUnit.js";
12
+ import { DataType } from "./dataunit/metadata/DataType.js";
13
+ import { UnitMetadata, FieldDescriptor, UserInterface, Sort, Filter } from "./dataunit/metadata/UnitMetadata.js";
14
+ import { DataUnitAction, Action } from "./dataunit/state/action/DataUnitAction.js";
15
+ import ApplicationContext from "./utils/ApplicationContext.js";
16
+
17
+ /*Classes públicas no pacote*/
18
+ export {
19
+ StringUtils,
20
+ MaskFormatter,
21
+ NumberUtils,
22
+ FloatingManager,
23
+ DateUtils,
24
+ TimeFormatter,
25
+ SkwHttpProvider,
26
+ HttpProvider,
27
+ RequestMetadata,
28
+ AuthorizedServiceCaller,
29
+ DataUnit,
30
+ Record,
31
+ SavedRecord,
32
+ DataType,
33
+ UnitMetadata,
34
+ FieldDescriptor,
35
+ UserInterface,
36
+ DataUnitAction,
37
+ Action,
38
+ Change,
39
+ Sort,
40
+ Filter,
41
+ ChangeOperation,
42
+ DUActionInterceptor,
43
+ ApplicationContext
44
+ };
@@ -1,166 +1,166 @@
1
- interface FloatingOptions {
2
- autoClose: boolean;
3
- top?: string;
4
- left?: string;
5
- right?: string;
6
- bottom?: string;
7
- innerClickTest?: Function;
8
- }
9
-
10
- class FloatingEntry {
11
-
12
- private weakRefParent?: WeakRef<HTMLElement>;
13
- private weakRefContent?: WeakRef<HTMLElement>;
14
- private strongRefParent?: HTMLElement;
15
- private strongRefContent?: HTMLElement;
16
- public options: FloatingOptions;
17
-
18
- constructor(parent: HTMLElement, content: HTMLElement, opts: FloatingOptions) {
19
- try{
20
- this.weakRefParent = new WeakRef(parent);
21
- this.weakRefContent = new WeakRef(content);
22
- } catch(error){
23
- this.strongRefParent = parent;
24
- this.strongRefContent = content;
25
- }
26
- this.options = opts;
27
- }
28
-
29
- public get parent():HTMLElement|undefined{
30
- if(this.weakRefParent){
31
- return this.weakRefParent.deref();
32
- }
33
- return this.strongRefParent
34
- }
35
-
36
- public get content():HTMLElement|undefined{
37
- if(this.weakRefContent){
38
- return this.weakRefContent.deref();
39
- }
40
- return this.strongRefContent;
41
- }
42
- }
43
-
44
- export default class FloatingManager {
45
-
46
- private static initialized: boolean;
47
- private static entries: Array<FloatingEntry>;
48
-
49
- private static init() {
50
- FloatingManager.entries = [];
51
- document.addEventListener('mousedown', FloatingManager.handleDocumentEvent);
52
- document.addEventListener('keydown', FloatingManager.handleKeyboardEvent);
53
- FloatingManager.initialized = true;
54
- }
55
-
56
- private static innerClick(container: HTMLElement, node: HTMLElement) {
57
- if (container.contains(node)) {
58
- return true;
59
- }
60
-
61
- if (container.shadowRoot && container.shadowRoot.contains(node)) {
62
- return true;
63
- }
64
-
65
- return false;
66
- }
67
-
68
- private static doClose(id: number, entry: FloatingEntry, target?: HTMLElement) {
69
- if (!target || entry.options.autoClose) {
70
- const parent: HTMLElement | undefined = entry.parent;
71
- const content: HTMLElement | undefined = entry.content;
72
-
73
- if (parent && content) {
74
- const innerClickFunction: Function = entry.options.innerClickTest ? entry.options.innerClickTest : FloatingManager.innerClick;
75
-
76
- if (!target || !innerClickFunction(content, target)) {
77
- content.remove();
78
- delete FloatingManager.entries[id];
79
- }
80
- } else {
81
- delete FloatingManager.entries[id];
82
- }
83
- }
84
- }
85
-
86
- private static handleDocumentEvent(event: Event) {
87
-
88
- FloatingManager.entries.forEach((entry, index) => {
89
- FloatingManager.doClose(index, entry, event.composedPath()[0] as HTMLElement);
90
- });
91
- }
92
-
93
- private static handleKeyboardEvent(event: KeyboardEvent) {
94
- if (event.key === 'Escape') {
95
- for (let index: number = FloatingManager.entries.length; index >= 0; index--) {
96
- const entry: FloatingEntry = FloatingManager.entries[index];
97
- if (entry) {
98
- FloatingManager.close(index);
99
- break;
100
- }
101
- }
102
- }
103
- }
104
-
105
- private static applyStyle(element: HTMLElement, propertyName: string, value?: string) {
106
- if (value) {
107
- element.style.setProperty(propertyName, value);
108
- }
109
- }
110
-
111
- private static getFloatIndex(content: HTMLElement, parent: HTMLElement): number {
112
-
113
- for (let index: number = 0; index < FloatingManager.entries.length; index++) {
114
- const entry: FloatingEntry = FloatingManager.entries[index];
115
- if (entry && content === entry.content && parent === entry.parent) {
116
- return index;
117
- }
118
- }
119
- return -1;
120
- }
121
-
122
- public static isFloating(id: number){
123
- return FloatingManager.entries[id] !== undefined;
124
- }
125
-
126
- public static float(content: HTMLElement, parent: HTMLElement, options: FloatingOptions = { autoClose: true }): number {
127
-
128
- if (!FloatingManager.initialized) {
129
- FloatingManager.init();
130
- }
131
-
132
- const alreadyFloatingIndex = FloatingManager.getFloatIndex(content, parent);
133
-
134
- if (alreadyFloatingIndex > -1) {
135
- return alreadyFloatingIndex;
136
- }
137
-
138
- content.style.position = 'absolute';
139
- FloatingManager.applyStyle(content, "top", options.top);
140
- FloatingManager.applyStyle(content, "left", options.left);
141
- FloatingManager.applyStyle(content, "right", options.right);
142
- FloatingManager.applyStyle(content, "bottom", options.bottom);
143
-
144
- parent.appendChild(content);
145
- FloatingManager.entries.push(new FloatingEntry(parent, content, options));
146
-
147
- return FloatingManager.entries.length - 1;
148
- }
149
-
150
- public static updateFloatPosition(content: HTMLElement, parent: HTMLElement, options: FloatingOptions = { autoClose: true }) {
151
- const alreadyFloatingIndex = FloatingManager.getFloatIndex(content, parent);
152
- if (alreadyFloatingIndex > -1) {
153
- FloatingManager.applyStyle(content, "top", options.top);
154
- FloatingManager.applyStyle(content, "left", options.left);
155
- FloatingManager.applyStyle(content, "right", options.right);
156
- FloatingManager.applyStyle(content, "bottom", options.bottom);
157
- }
158
-
159
- }
160
-
161
- public static close(id: number) {
162
- if (FloatingManager.entries[id]) {
163
- FloatingManager.doClose(id, FloatingManager.entries[id], undefined);
164
- }
165
- }
1
+ interface FloatingOptions {
2
+ autoClose: boolean;
3
+ top?: string;
4
+ left?: string;
5
+ right?: string;
6
+ bottom?: string;
7
+ innerClickTest?: Function;
8
+ }
9
+
10
+ class FloatingEntry {
11
+
12
+ private weakRefParent?: WeakRef<HTMLElement>;
13
+ private weakRefContent?: WeakRef<HTMLElement>;
14
+ private strongRefParent?: HTMLElement;
15
+ private strongRefContent?: HTMLElement;
16
+ public options: FloatingOptions;
17
+
18
+ constructor(parent: HTMLElement, content: HTMLElement, opts: FloatingOptions) {
19
+ try{
20
+ this.weakRefParent = new WeakRef(parent);
21
+ this.weakRefContent = new WeakRef(content);
22
+ } catch(error){
23
+ this.strongRefParent = parent;
24
+ this.strongRefContent = content;
25
+ }
26
+ this.options = opts;
27
+ }
28
+
29
+ public get parent():HTMLElement|undefined{
30
+ if(this.weakRefParent){
31
+ return this.weakRefParent.deref();
32
+ }
33
+ return this.strongRefParent
34
+ }
35
+
36
+ public get content():HTMLElement|undefined{
37
+ if(this.weakRefContent){
38
+ return this.weakRefContent.deref();
39
+ }
40
+ return this.strongRefContent;
41
+ }
42
+ }
43
+
44
+ export default class FloatingManager {
45
+
46
+ private static initialized: boolean;
47
+ private static entries: Array<FloatingEntry>;
48
+
49
+ private static init() {
50
+ FloatingManager.entries = [];
51
+ document.addEventListener('mousedown', FloatingManager.handleDocumentEvent);
52
+ document.addEventListener('keydown', FloatingManager.handleKeyboardEvent);
53
+ FloatingManager.initialized = true;
54
+ }
55
+
56
+ private static innerClick(container: HTMLElement, node: HTMLElement) {
57
+ if (container.contains(node)) {
58
+ return true;
59
+ }
60
+
61
+ if (container.shadowRoot && container.shadowRoot.contains(node)) {
62
+ return true;
63
+ }
64
+
65
+ return false;
66
+ }
67
+
68
+ private static doClose(id: number, entry: FloatingEntry, target?: HTMLElement) {
69
+ if (!target || entry.options.autoClose) {
70
+ const parent: HTMLElement | undefined = entry.parent;
71
+ const content: HTMLElement | undefined = entry.content;
72
+
73
+ if (parent && content) {
74
+ const innerClickFunction: Function = entry.options.innerClickTest ? entry.options.innerClickTest : FloatingManager.innerClick;
75
+
76
+ if (!target || !innerClickFunction(content, target)) {
77
+ content.remove();
78
+ delete FloatingManager.entries[id];
79
+ }
80
+ } else {
81
+ delete FloatingManager.entries[id];
82
+ }
83
+ }
84
+ }
85
+
86
+ private static handleDocumentEvent(event: Event) {
87
+
88
+ FloatingManager.entries.forEach((entry, index) => {
89
+ FloatingManager.doClose(index, entry, event.composedPath()[0] as HTMLElement);
90
+ });
91
+ }
92
+
93
+ private static handleKeyboardEvent(event: KeyboardEvent) {
94
+ if (event.key === 'Escape') {
95
+ for (let index: number = FloatingManager.entries.length; index >= 0; index--) {
96
+ const entry: FloatingEntry = FloatingManager.entries[index];
97
+ if (entry) {
98
+ FloatingManager.close(index);
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ private static applyStyle(element: HTMLElement, propertyName: string, value?: string) {
106
+ if (value) {
107
+ element.style.setProperty(propertyName, value);
108
+ }
109
+ }
110
+
111
+ private static getFloatIndex(content: HTMLElement, parent: HTMLElement): number {
112
+
113
+ for (let index: number = 0; index < FloatingManager.entries.length; index++) {
114
+ const entry: FloatingEntry = FloatingManager.entries[index];
115
+ if (entry && content === entry.content && parent === entry.parent) {
116
+ return index;
117
+ }
118
+ }
119
+ return -1;
120
+ }
121
+
122
+ public static isFloating(id: number){
123
+ return FloatingManager.entries[id] !== undefined;
124
+ }
125
+
126
+ public static float(content: HTMLElement, parent: HTMLElement, options: FloatingOptions = { autoClose: true }): number {
127
+
128
+ if (!FloatingManager.initialized) {
129
+ FloatingManager.init();
130
+ }
131
+
132
+ const alreadyFloatingIndex = FloatingManager.getFloatIndex(content, parent);
133
+
134
+ if (alreadyFloatingIndex > -1) {
135
+ return alreadyFloatingIndex;
136
+ }
137
+
138
+ content.style.position = 'absolute';
139
+ FloatingManager.applyStyle(content, "top", options.top);
140
+ FloatingManager.applyStyle(content, "left", options.left);
141
+ FloatingManager.applyStyle(content, "right", options.right);
142
+ FloatingManager.applyStyle(content, "bottom", options.bottom);
143
+
144
+ parent.appendChild(content);
145
+ FloatingManager.entries.push(new FloatingEntry(parent, content, options));
146
+
147
+ return FloatingManager.entries.length - 1;
148
+ }
149
+
150
+ public static updateFloatPosition(content: HTMLElement, parent: HTMLElement, options: FloatingOptions = { autoClose: true }) {
151
+ const alreadyFloatingIndex = FloatingManager.getFloatIndex(content, parent);
152
+ if (alreadyFloatingIndex > -1) {
153
+ FloatingManager.applyStyle(content, "top", options.top);
154
+ FloatingManager.applyStyle(content, "left", options.left);
155
+ FloatingManager.applyStyle(content, "right", options.right);
156
+ FloatingManager.applyStyle(content, "bottom", options.bottom);
157
+ }
158
+
159
+ }
160
+
161
+ public static close(id: number) {
162
+ if (FloatingManager.entries[id]) {
163
+ FloatingManager.doClose(id, FloatingManager.entries[id], undefined);
164
+ }
165
+ }
166
166
  }