@j2inn/resolvable-ui-elements 1.0.4 → 1.1.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
@@ -1,36 +1,36 @@
1
- # What is resolvable-ui-elements?
2
- The main goal of this library is to enhance the flexibility of the UI code written, by adding a layer that separates the queries and information used to interact with the backend from the UI code, moving it to a separated JSON file.
3
-
4
- The JSON file (typically called `elements.json`) can be generated from a spreadsheet used to simplify the data management for a project UI.
5
-
6
-
7
- ## How do I get set up? ###
8
- To install this package run `npm i @j2inn/resolvable-ui-elements`
9
-
10
- ## Where do I get more info? ###
11
- See: https://finproducts.atlassian.net/wiki/spaces/ECO/pages/32881311778/Element+Types
12
-
13
- ## Codebase Structure ##
14
-
15
- src
16
- ├── resolvableElements
17
- │ ├── elements # Element classes implementation
18
- │ ├── interfacesGeneration # Code for generating interfaces from an elements.json file
19
- │ ├── react # React hooks to use resolvable elements.
20
- │ └── ...
21
- └── ...
22
-
23
- ## BE libraries dependencies ##
24
- If you decide to use the Resolver's `evalFuncName` feature, this library should be used in combination with [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext). The pod allows the usage of the wrapper function.
25
- ```typescript
26
- /**
27
- * Function name to be used for expressions eval,
28
- * used to enable custom backend permission check using elements path
29
- * @example
30
- * customEval(\`page/section/elementName\`, parametersDict)
31
- */
32
- evalFuncName?: string
33
- ```
34
-
35
- ### v1.0.4 ###
36
- Version 1.0.4 of this library introduces the usage of optional parameters in function evaluation. To be able to use them, [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext) 1.0.2+ should be used for the BE.
1
+ # What is resolvable-ui-elements?
2
+ The main goal of this library is to enhance the flexibility of the UI code written, by adding a layer that separates the queries and information used to interact with the backend from the UI code, moving it to a separated JSON file.
3
+
4
+ The JSON file (typically called `elements.json`) can be generated from a spreadsheet used to simplify the data management for a project UI.
5
+
6
+
7
+ ## How do I get set up? ###
8
+ To install this package run `npm i @j2inn/resolvable-ui-elements`
9
+
10
+ ## Where do I get more info? ###
11
+ See: https://finproducts.atlassian.net/wiki/spaces/ECO/pages/32881311778/Element+Types
12
+
13
+ ## Codebase Structure ##
14
+
15
+ src
16
+ ├── resolvableElements
17
+ │ ├── elements # Element classes implementation
18
+ │ ├── interfacesGeneration # Code for generating interfaces from an elements.json file
19
+ │ ├── react # React hooks to use resolvable elements.
20
+ │ └── ...
21
+ └── ...
22
+
23
+ ## BE libraries dependencies ##
24
+ If you decide to use the Resolver's `evalFuncName` feature, this library should be used in combination with [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext). The pod allows the usage of the wrapper function.
25
+ ```typescript
26
+ /**
27
+ * Function name to be used for expressions eval,
28
+ * used to enable custom backend permission check using elements path
29
+ * @example
30
+ * customEval(\`page/section/elementName\`, parametersDict)
31
+ */
32
+ evalFuncName?: string
33
+ ```
34
+
35
+ ### v1.0.4 ###
36
+ Version 1.0.4 of this library introduces the usage of optional parameters in function evaluation. To be able to use them, [finOemAuthzExt](https://bitbucket.org/finproducts/finoemauthzext) 1.0.2+ should be used for the BE.
@@ -1,20 +1,26 @@
1
1
  import { HDict } from 'haystack-core';
2
2
  import { ResolvableValueElement } from '../ResolvableValueElement';
3
3
  import { UiElementConstructorData, UiElementData } from '../UiElement';
4
+ import { ResolvableExprElementMeta } from './ResolvableExprElementMeta';
4
5
  /**
5
6
  * Resolves to the result of an expression.
6
7
  */
7
8
  export declare class ResolvableExprElement<T extends UiElementData> extends ResolvableValueElement<T> {
8
9
  #private;
9
- static collectionTypes: Set<string>;
10
10
  constructor(data: UiElementConstructorData<T>);
11
11
  refreshes: number;
12
+ protected getMeta: () => ResolvableExprElementMeta;
12
13
  protected doInitialize: (parameters: HDict) => Promise<void>;
13
14
  /**
14
15
  * Checks whether the declared resolvedType of this element is a collection.
15
16
  * @returns true if the resolvedType is a collection.
16
17
  */
17
18
  isExpectedResultACollection: () => boolean;
19
+ /**
20
+ * Checks whether the declared resolvedType of this element is a single value.
21
+ * @returns true if the resolvedType is a value.
22
+ */
23
+ isExpectedResultVal: () => boolean;
18
24
  protected doClose: () => Promise<void>;
19
25
  getParameterList: () => string[];
20
26
  }
@@ -8,33 +8,20 @@ const haystack_core_1 = require("haystack-core");
8
8
  const haystack_units_1 = require("haystack-units");
9
9
  const resolveTemplatedExpression_1 = require("../../resolveTemplatedExpression");
10
10
  const ResolvableValueElement_1 = require("../ResolvableValueElement");
11
+ const GRID_VAL_COLUMN_NAME = 'val';
11
12
  /**
12
13
  * Resolves to the result of an expression.
13
14
  */
14
15
  class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElement {
15
- static collectionTypes = new Set(['HGrid', 'HList']);
16
16
  constructor(data) {
17
17
  super(data);
18
18
  }
19
19
  refreshes = 0;
20
20
  #timeout;
21
+ getMeta = () => this._meta;
21
22
  doInitialize = async (parameters) => {
23
+ const { refreshAfter } = this.getMeta();
22
24
  await this.#updateValue(parameters);
23
- };
24
- #updateValue = async (parameters) => {
25
- const { expr, refreshAfter, path } = this
26
- ._meta;
27
- const grid = await this.resolver.evalExprElement(expr, parameters, path);
28
- // Identify when it's necessary to unpack the result `val` or not
29
- // since the eval wraps the result value in a grid's first dict `val` tag for non-collections.
30
- const val = grid[0]?.get('val');
31
- const shouldUnpackResult = !this.isExpectedResultACollection() && val;
32
- if (shouldUnpackResult) {
33
- this.value = val;
34
- }
35
- else {
36
- this.value = grid;
37
- }
38
25
  if (refreshAfter) {
39
26
  this.#timeout = setTimeout(() => {
40
27
  this.refreshes++;
@@ -42,14 +29,57 @@ class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElem
42
29
  }, haystack_core_1.HNum.make(refreshAfter, haystack_units_1.second).convertTo(haystack_units_1.millisecond).value);
43
30
  }
44
31
  };
32
+ #updateValue = async (parameters) => {
33
+ const { expr, path } = this.getMeta();
34
+ const grid = await this.resolver.evalExprElement(expr, parameters, path);
35
+ this.value = this.#unpackResult(grid);
36
+ };
37
+ /**
38
+ * Unpacks grid if expected `resolvedType` result requires it.
39
+ * @param grid result grid
40
+ * @returns unpacked value
41
+ */
42
+ #unpackResult = (grid) => {
43
+ // Identify when it's necessary to unpack the result from `val` column or not
44
+ if (this.isExpectedResultACollection()) {
45
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
46
+ this.#logValColumnNotFound(grid);
47
+ }
48
+ // Unpack val column into array
49
+ return grid.map((row) => row.get(GRID_VAL_COLUMN_NAME));
50
+ }
51
+ else if (this.isExpectedResultVal()) {
52
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
53
+ this.#logValColumnNotFound(grid);
54
+ }
55
+ // Unpack first dict val column into value
56
+ return grid[0]?.get(GRID_VAL_COLUMN_NAME);
57
+ }
58
+ else {
59
+ // Default to using the grid response as it is
60
+ return grid;
61
+ }
62
+ };
63
+ #logValColumnNotFound = (grid) => {
64
+ const { expr } = this.getMeta();
65
+ console.warn(`expected "${GRID_VAL_COLUMN_NAME}" column on expr result not found`, expr, grid);
66
+ grid.inspect();
67
+ };
45
68
  /**
46
69
  * Checks whether the declared resolvedType of this element is a collection.
47
70
  * @returns true if the resolvedType is a collection.
48
71
  */
49
72
  isExpectedResultACollection = () => {
50
- const { resolvedType } = this._meta;
51
- return (ResolvableExprElement.collectionTypes.has(resolvedType) ||
52
- resolvedType.endsWith('[]'));
73
+ const { resolvedType } = this.getMeta();
74
+ return resolvedType.endsWith('[]');
75
+ };
76
+ /**
77
+ * Checks whether the declared resolvedType of this element is a single value.
78
+ * @returns true if the resolvedType is a value.
79
+ */
80
+ isExpectedResultVal = () => {
81
+ const { resolvedType } = this.getMeta();
82
+ return resolvedType !== 'HGrid' && !this.isExpectedResultACollection();
53
83
  };
54
84
  doClose = async () => {
55
85
  if (this.#timeout) {
@@ -57,7 +87,7 @@ class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElem
57
87
  }
58
88
  };
59
89
  getParameterList = () => {
60
- const { expr } = this._meta;
90
+ const { expr } = this.getMeta();
61
91
  const parameters = [];
62
92
  if (expr) {
63
93
  (0, resolveTemplatedExpression_1.replaceTemplateVariables)(expr, (_, match) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAA2C;AAC3C,mDAAoD;AACpD,iFAA2E;AAE3E,sEAAkE;AAIlE;;GAEG;AACH,MAAa,qBAEX,SAAQ,+CAAyB;IAClC,MAAM,CAAC,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAEpD,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;IACZ,CAAC;IAED,SAAS,GAAG,CAAC,CAAA;IACb,QAAQ,CAAS;IAEP,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACnE,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IACpC,CAAC,CAAA;IAED,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACzD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,IAAI;aACvC,KAAkC,CAAA;QAEpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;QAExE,iEAAiE;QACjE,8FAA8F;QAC9F,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;QAC/B,MAAM,kBAAkB,GAAG,CAAC,IAAI,CAAC,2BAA2B,EAAE,IAAI,GAAG,CAAA;QACrE,IAAI,kBAAkB,EAAE;YACvB,IAAI,CAAC,KAAK,GAAG,GAAG,CAAA;SAChB;aAAM;YACN,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;SACjB;QAED,IAAI,YAAY,EAAE;YACjB,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC/B,IAAI,CAAC,SAAS,EAAE,CAAA;gBAChB,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;YAC9B,CAAC,EAAE,oBAAI,CAAC,IAAI,CAAC,YAAY,EAAE,uBAAM,CAAC,CAAC,SAAS,CAAC,4BAAW,CAAC,CAAC,KAAK,CAAsB,CAAA;SACrF;IACF,CAAC,CAAA;IAED;;;OAGG;IACH,2BAA2B,GAAG,GAAY,EAAE;QAC3C,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAEhE,OAAO,CACN,qBAAqB,CAAC,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;YACvD,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAC3B,CAAA;IACF,CAAC,CAAA;IAES,OAAO,GAAG,KAAK,IAAmB,EAAE;QAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SAC3B;IACF,CAAC,CAAA;IAED,gBAAgB,GAAmB,GAAG,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAExD,MAAM,UAAU,GAAa,EAAE,CAAA;QAE/B,IAAI,IAAI,EAAE;YACT,IAAA,qDAAwB,EAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBAC3C,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACtB,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA;;AAxEF,sDAyEC"}
1
+ {"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAAwD;AACxD,mDAAoD;A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,GAAG,KAAK,IAAmB,EAAE;QAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SAC3B;IACF,CAAC,CAAA;IAED,gBAAgB,GAAmB,GAAG,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAE/B,MAAM,UAAU,GAAa,EAAE,CAAA;QAE/B,IAAI,IAAI,EAAE;YACT,IAAA,qDAAwB,EAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBAC3C,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACtB,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA;CACD;AA7GD,sDA6GC"}
@@ -1,20 +1,26 @@
1
1
  import { HDict } from 'haystack-core';
2
2
  import { ResolvableValueElement } from '../ResolvableValueElement';
3
3
  import { UiElementConstructorData, UiElementData } from '../UiElement';
4
+ import { ResolvableExprElementMeta } from './ResolvableExprElementMeta';
4
5
  /**
5
6
  * Resolves to the result of an expression.
6
7
  */
7
8
  export declare class ResolvableExprElement<T extends UiElementData> extends ResolvableValueElement<T> {
8
9
  #private;
9
- static collectionTypes: Set<string>;
10
10
  constructor(data: UiElementConstructorData<T>);
11
11
  refreshes: number;
12
+ protected getMeta: () => ResolvableExprElementMeta;
12
13
  protected doInitialize: (parameters: HDict) => Promise<void>;
13
14
  /**
14
15
  * Checks whether the declared resolvedType of this element is a collection.
15
16
  * @returns true if the resolvedType is a collection.
16
17
  */
17
18
  isExpectedResultACollection: () => boolean;
19
+ /**
20
+ * Checks whether the declared resolvedType of this element is a single value.
21
+ * @returns true if the resolvedType is a value.
22
+ */
23
+ isExpectedResultVal: () => boolean;
18
24
  protected doClose: () => Promise<void>;
19
25
  getParameterList: () => string[];
20
26
  }
@@ -5,33 +5,20 @@ import { HNum } from 'haystack-core';
5
5
  import { millisecond, second } from 'haystack-units';
6
6
  import { replaceTemplateVariables } from '../../resolveTemplatedExpression';
7
7
  import { ResolvableValueElement } from '../ResolvableValueElement';
8
+ const GRID_VAL_COLUMN_NAME = 'val';
8
9
  /**
9
10
  * Resolves to the result of an expression.
10
11
  */
11
12
  export class ResolvableExprElement extends ResolvableValueElement {
12
- static collectionTypes = new Set(['HGrid', 'HList']);
13
13
  constructor(data) {
14
14
  super(data);
15
15
  }
16
16
  refreshes = 0;
17
17
  #timeout;
18
+ getMeta = () => this._meta;
18
19
  doInitialize = async (parameters) => {
20
+ const { refreshAfter } = this.getMeta();
19
21
  await this.#updateValue(parameters);
20
- };
21
- #updateValue = async (parameters) => {
22
- const { expr, refreshAfter, path } = this
23
- ._meta;
24
- const grid = await this.resolver.evalExprElement(expr, parameters, path);
25
- // Identify when it's necessary to unpack the result `val` or not
26
- // since the eval wraps the result value in a grid's first dict `val` tag for non-collections.
27
- const val = grid[0]?.get('val');
28
- const shouldUnpackResult = !this.isExpectedResultACollection() && val;
29
- if (shouldUnpackResult) {
30
- this.value = val;
31
- }
32
- else {
33
- this.value = grid;
34
- }
35
22
  if (refreshAfter) {
36
23
  this.#timeout = setTimeout(() => {
37
24
  this.refreshes++;
@@ -39,14 +26,57 @@ export class ResolvableExprElement extends ResolvableValueElement {
39
26
  }, HNum.make(refreshAfter, second).convertTo(millisecond).value);
40
27
  }
41
28
  };
29
+ #updateValue = async (parameters) => {
30
+ const { expr, path } = this.getMeta();
31
+ const grid = await this.resolver.evalExprElement(expr, parameters, path);
32
+ this.value = this.#unpackResult(grid);
33
+ };
34
+ /**
35
+ * Unpacks grid if expected `resolvedType` result requires it.
36
+ * @param grid result grid
37
+ * @returns unpacked value
38
+ */
39
+ #unpackResult = (grid) => {
40
+ // Identify when it's necessary to unpack the result from `val` column or not
41
+ if (this.isExpectedResultACollection()) {
42
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
43
+ this.#logValColumnNotFound(grid);
44
+ }
45
+ // Unpack val column into array
46
+ return grid.map((row) => row.get(GRID_VAL_COLUMN_NAME));
47
+ }
48
+ else if (this.isExpectedResultVal()) {
49
+ if (!grid.hasColumn(GRID_VAL_COLUMN_NAME)) {
50
+ this.#logValColumnNotFound(grid);
51
+ }
52
+ // Unpack first dict val column into value
53
+ return grid[0]?.get(GRID_VAL_COLUMN_NAME);
54
+ }
55
+ else {
56
+ // Default to using the grid response as it is
57
+ return grid;
58
+ }
59
+ };
60
+ #logValColumnNotFound = (grid) => {
61
+ const { expr } = this.getMeta();
62
+ console.warn(`expected "${GRID_VAL_COLUMN_NAME}" column on expr result not found`, expr, grid);
63
+ grid.inspect();
64
+ };
42
65
  /**
43
66
  * Checks whether the declared resolvedType of this element is a collection.
44
67
  * @returns true if the resolvedType is a collection.
45
68
  */
46
69
  isExpectedResultACollection = () => {
47
- const { resolvedType } = this._meta;
48
- return (ResolvableExprElement.collectionTypes.has(resolvedType) ||
49
- resolvedType.endsWith('[]'));
70
+ const { resolvedType } = this.getMeta();
71
+ return resolvedType.endsWith('[]');
72
+ };
73
+ /**
74
+ * Checks whether the declared resolvedType of this element is a single value.
75
+ * @returns true if the resolvedType is a value.
76
+ */
77
+ isExpectedResultVal = () => {
78
+ const { resolvedType } = this.getMeta();
79
+ return resolvedType !== 'HGrid' && !this.isExpectedResultACollection();
50
80
  };
51
81
  doClose = async () => {
52
82
  if (this.#timeout) {
@@ -54,7 +84,7 @@ export class ResolvableExprElement extends ResolvableValueElement {
54
84
  }
55
85
  };
56
86
  getParameterList = () => {
57
- const { expr } = this._meta;
87
+ const { expr } = this.getMeta();
58
88
  const parameters = [];
59
89
  if (expr) {
60
90
  replaceTemplateVariables(expr, (_, match) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAS,IAAI,EAAE,MAA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,SAAS,EAAE,CAAA;gBAChB,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;YAC9B,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,KAAK,CAAsB,CAAA;SACrF;IACF,CAAC,CAAA;IAED;;;OAGG;IACH,2BAA2B,GAAG,GAAY,EAAE;QAC3C,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAEhE,OAAO,CACN,qBAAqB,CAAC,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;YACvD,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAC3B,CAAA;IACF,CAAC,CAAA;IAES,OAAO,GAAG,KAAK,IAAmB,EAAE;QAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SAC3B;IACF,CAAC,CAAA;IAED,gBAAgB,GAAmB,GAAG,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAExD,MAAM,UAAU,GAAa,EAAE,CAAA;QAE/B,IAAI,IAAI,EAAE;YACT,wBAAwB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBAC3C,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACtB,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA"}
1
+ {"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAgB,IAAI,EAAQ,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,wBAAwB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,CAAC,2BAA2B,EAAE,CAAA;IACvE,CAAC,CAAA;IAES,OAAO,GAAG,KAAK,IAAmB,EAAE;QAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SAC3B;IACF,CAAC,CAAA;IAED,gBAAgB,GAAmB,GAAG,EAAE;QACvC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAE/B,MAAM,UAAU,GAAa,EAAE,CAAA;QAE/B,IAAI,IAAI,EAAE;YACT,wBAAwB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBAC3C,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACtB,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA;CACD"}
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "@j2inn/resolvable-ui-elements",
3
- "version": "1.0.4",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "module": "dist_es/index.js",
8
- "scripts": {
9
- "clean": "rimraf ./dist && rimraf ./dist_es",
10
- "prebuild": "npm run clean && npm run lint && npm run test",
11
- "build": "tsc && npm run-script build:es",
12
- "build:es": "tsc --module ESNext --outDir dist_es",
13
- "checktypes": "tsc --noEmit",
14
- "format": "prettier-eslint --list-different --write \"$(pwd)/src/**/*.{ts,tsx,js,jsx}\"",
15
- "lint": "eslint --fix --ext ts,tsx,js,jsx src/",
16
- "test": "jest --passWithNoTests",
17
- "prepack": "npm run lint && npm run test && npm run build"
18
- },
19
- "author": "",
20
- "license": "ISC",
21
- "files": [
22
- "dist/**/*",
23
- "dist_es/**/*"
24
- ],
25
- "peerDependencies": {
26
- "haystack-core": "^2.0.45",
27
- "haystack-nclient": "^3.0.32",
28
- "haystack-react": "^3.0.17",
29
- "haystack-units": "^1.0.22",
30
- "react": "^18.2.0",
31
- "react-dom": "^18.2.0"
32
- },
33
- "devDependencies": {
34
- "@types/jest": "^27.4.0",
35
- "@types/node": "^15.0.2",
36
- "@types/react": "^18.0.18",
37
- "@types/react-dom": "^18.0.6",
38
- "@typescript-eslint/eslint-plugin": "^5.28.0",
39
- "@typescript-eslint/parser": "^5.28.0",
40
- "eslint": "^7.32.0",
41
- "eslint-config-prettier": "^8.3.0",
42
- "eslint-plugin-jest": "^26.1.3",
43
- "eslint-plugin-prettier": "^4.0.0",
44
- "eslint-plugin-react": "^7.29.4",
45
- "prettier": "^2.6.1",
46
- "prettier-eslint": "^13.0.0",
47
- "prettier-eslint-cli": "^5.0.1",
48
- "rimraf": "^3.0.2",
49
- "ts-jest": "^28.0.8",
50
- "typescript": "^4.8.2"
51
- }
52
- }
1
+ {
2
+ "name": "@j2inn/resolvable-ui-elements",
3
+ "version": "1.1.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist_es/index.js",
8
+ "scripts": {
9
+ "clean": "rimraf ./dist && rimraf ./dist_es",
10
+ "prebuild": "npm run clean && npm run lint && npm run test",
11
+ "build": "tsc && npm run-script build:es",
12
+ "build:es": "tsc --module ESNext --outDir dist_es",
13
+ "checktypes": "tsc --noEmit",
14
+ "format": "prettier-eslint --list-different --write \"$(pwd)/src/**/*.{ts,tsx,js,jsx}\"",
15
+ "lint": "eslint --fix --ext ts,tsx,js,jsx src/",
16
+ "test": "jest --passWithNoTests",
17
+ "prepack": "npm run lint && npm run test && npm run build"
18
+ },
19
+ "author": "",
20
+ "license": "ISC",
21
+ "files": [
22
+ "dist/**/*",
23
+ "dist_es/**/*"
24
+ ],
25
+ "peerDependencies": {
26
+ "haystack-core": "^2.0.45",
27
+ "haystack-nclient": "^3.0.32",
28
+ "haystack-react": "^3.0.17",
29
+ "haystack-units": "^1.0.22",
30
+ "react": "^18.2.0",
31
+ "react-dom": "^18.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/jest": "^27.4.0",
35
+ "@types/node": "^15.0.2",
36
+ "@types/react": "^18.0.18",
37
+ "@types/react-dom": "^18.0.6",
38
+ "@typescript-eslint/eslint-plugin": "^5.28.0",
39
+ "@typescript-eslint/parser": "^5.28.0",
40
+ "eslint": "^7.32.0",
41
+ "eslint-config-prettier": "^8.3.0",
42
+ "eslint-plugin-jest": "^26.1.3",
43
+ "eslint-plugin-prettier": "^4.0.0",
44
+ "eslint-plugin-react": "^7.29.4",
45
+ "prettier": "^2.6.1",
46
+ "prettier-eslint": "^13.0.0",
47
+ "prettier-eslint-cli": "^5.0.1",
48
+ "rimraf": "^3.0.2",
49
+ "ts-jest": "^28.0.8",
50
+ "typescript": "^4.8.2"
51
+ }
52
+ }