@j2inn/resolvable-ui-elements 0.0.2-beta.6 → 0.0.4-beta.1
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/dist/resolvableElements/elements/expr/ResolvableExprElement.d.ts +6 -0
- package/dist/resolvableElements/elements/expr/ResolvableExprElement.js +14 -1
- package/dist/resolvableElements/elements/expr/ResolvableExprElement.js.map +1 -1
- package/dist/resolvableElements/elements/function/FunctionElement.d.ts +2 -2
- package/dist/resolvableElements/elements/function/FunctionElement.js +6 -1
- package/dist/resolvableElements/elements/function/FunctionElement.js.map +1 -1
- package/dist/resolvableElements/elements/section/ResolvableSectionElement.d.ts +1 -1
- package/dist/resolvableElements/elements/section/SectionElementMeta.d.ts +3 -3
- package/dist/resolvableElements/react/SectionChecker.d.ts +1 -4
- package/dist/resolvableElements/react/SectionChecker.jsx +0 -3
- package/dist/resolvableElements/react/SectionChecker.jsx.map +1 -1
- package/dist/resolvableElements/react/useResolveSection.d.ts +1 -1
- package/dist_es/resolvableElements/elements/expr/ResolvableExprElement.d.ts +6 -0
- package/dist_es/resolvableElements/elements/expr/ResolvableExprElement.js +14 -1
- package/dist_es/resolvableElements/elements/expr/ResolvableExprElement.js.map +1 -1
- package/dist_es/resolvableElements/elements/function/FunctionElement.d.ts +2 -2
- package/dist_es/resolvableElements/elements/function/FunctionElement.js +6 -1
- package/dist_es/resolvableElements/elements/function/FunctionElement.js.map +1 -1
- package/dist_es/resolvableElements/elements/section/ResolvableSectionElement.d.ts +1 -1
- package/dist_es/resolvableElements/elements/section/SectionElementMeta.d.ts +3 -3
- package/dist_es/resolvableElements/react/SectionChecker.d.ts +1 -4
- package/dist_es/resolvableElements/react/SectionChecker.jsx +0 -3
- package/dist_es/resolvableElements/react/SectionChecker.jsx.map +1 -1
- package/dist_es/resolvableElements/react/useResolveSection.d.ts +1 -1
- package/package.json +7 -6
|
@@ -6,9 +6,15 @@ import { UiElementConstructorData, UiElementData } from '../UiElement';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class ResolvableExprElement<T extends UiElementData> extends ResolvableValueElement<T> {
|
|
8
8
|
#private;
|
|
9
|
+
static collectionTypes: Set<string>;
|
|
9
10
|
constructor(data: UiElementConstructorData<T>);
|
|
10
11
|
refreshes: number;
|
|
11
12
|
protected doInitialize: (parameters: HDict) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether the declared resolvedType of this element is a collection.
|
|
15
|
+
* @returns true if the resolvedType is a collection.
|
|
16
|
+
*/
|
|
17
|
+
isExpectedResultACollection: () => boolean;
|
|
12
18
|
protected doClose: () => Promise<void>;
|
|
13
19
|
getParameterList: () => string[];
|
|
14
20
|
}
|
|
@@ -12,6 +12,7 @@ const ResolvableValueElement_1 = require("../ResolvableValueElement");
|
|
|
12
12
|
* Resolves to the result of an expression.
|
|
13
13
|
*/
|
|
14
14
|
class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElement {
|
|
15
|
+
static collectionTypes = new Set(['HGrid', 'HList']);
|
|
15
16
|
constructor(data) {
|
|
16
17
|
super(data);
|
|
17
18
|
}
|
|
@@ -29,7 +30,10 @@ class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElem
|
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
32
|
const val = grid[0]?.get('val');
|
|
32
|
-
|
|
33
|
+
// Identify when it's necessary to unpack the result `val` or not
|
|
34
|
+
// since the eval wraps the result value in a grid's first dict `val` tag for non-collections.
|
|
35
|
+
const shouldUnpackResult = !this.isExpectedResultACollection() && val;
|
|
36
|
+
if (shouldUnpackResult) {
|
|
33
37
|
this.value = val;
|
|
34
38
|
}
|
|
35
39
|
else {
|
|
@@ -42,6 +46,15 @@ class ResolvableExprElement extends ResolvableValueElement_1.ResolvableValueElem
|
|
|
42
46
|
}, haystack_core_1.HNum.make(refreshAfter, haystack_units_1.second).convertTo(haystack_units_1.millisecond).value);
|
|
43
47
|
}
|
|
44
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Checks whether the declared resolvedType of this element is a collection.
|
|
51
|
+
* @returns true if the resolvedType is a collection.
|
|
52
|
+
*/
|
|
53
|
+
isExpectedResultACollection = () => {
|
|
54
|
+
const { resolvedType } = this._meta;
|
|
55
|
+
return (ResolvableExprElement.collectionTypes.has(resolvedType) ||
|
|
56
|
+
resolvedType.endsWith('[]'));
|
|
57
|
+
};
|
|
45
58
|
doClose = async () => {
|
|
46
59
|
if (this.#timeout) {
|
|
47
60
|
clearTimeout(this.#timeout);
|
|
@@ -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,iFAGyC;AAEzC,sEAAkE;AAIlE;;GAEG;AACH,MAAa,qBAEX,SAAQ,+CAAyB;IAClC,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,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IAC9B,CAAC,CAAA;IAED,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACzD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAEtE,MAAM,kBAAkB,GAAG,IAAA,sDAAyB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAEtE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;QAEzD,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE;YACnB,OAAO,CAAC,KAAK,CACZ,sCAAsC,EACtC,kBAAkB,EAClB,IAAI,CAAC,QAAQ,EAAE,CACf,CAAA;YACD,OAAM;SACN;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;QAE/B,IAAI,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAA2C;AAC3C,mDAAoD;AACpD,iFAGyC;AAEzC,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,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IAC9B,CAAC,CAAA;IAED,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACzD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAEtE,MAAM,kBAAkB,GAAG,IAAA,sDAAyB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAEtE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;QAEzD,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE;YACnB,OAAO,CAAC,KAAK,CACZ,sCAAsC,EACtC,kBAAkB,EAClB,IAAI,CAAC,QAAQ,EAAE,CACf,CAAA;YACD,OAAM;SACN;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;QAE/B,iEAAiE;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AAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA;;AAnFF,sDAoFC"}
|
|
@@ -7,6 +7,6 @@ export declare class FunctionElement<T extends UiElementData> extends UiElement<
|
|
|
7
7
|
#private;
|
|
8
8
|
constructor(data: UiElementConstructorData<T>);
|
|
9
9
|
}
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type FunctionResult = (parameters: Parameters) => Promise<HGrid>;
|
|
11
|
+
export type Parameters = Record<string, OptionalHVal | HaysonVal | undefined> | OptionalHVal | DictStore | undefined;
|
|
12
12
|
export declare const makeParametersDict: (parameters: Record<string, OptionalHVal | HaysonVal | undefined> | OptionalHVal | DictStore | undefined) => HDict;
|
|
@@ -21,7 +21,12 @@ class FunctionElement extends UiElement_1.UiElement {
|
|
|
21
21
|
const { expr } = this._meta;
|
|
22
22
|
return async (parameters) => {
|
|
23
23
|
const resolvedExpression = (0, resolveTemplatedExpression_1.resolveTemplateExpression)(expr, (0, exports.makeParametersDict)(parameters));
|
|
24
|
-
|
|
24
|
+
const result = await this.resolver.eval(resolvedExpression);
|
|
25
|
+
// Update watch records
|
|
26
|
+
if (!result.isError()) {
|
|
27
|
+
this.resolver.client.watch.update(result.filter('id and mod'));
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
25
30
|
};
|
|
26
31
|
};
|
|
27
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/function/FunctionElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAAgF;AAChF,iFAA4E;AAE5E,4CAIqB;AAGrB;;GAEG;AACH,MAAa,eAAyC,SAAQ,qBAAY;IACzE,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;SAClC;IACF,CAAC;IAED,cAAc,GAAG,GAAmB,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAA4B,CAAA;QAElD,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE;YAC3B,MAAM,kBAAkB,GAAG,IAAA,sDAAyB,EACnD,IAAI,EACJ,IAAA,0BAAkB,EAAC,UAAU,CAAC,CAC9B,CAAA;YAED,
|
|
1
|
+
{"version":3,"file":"FunctionElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/function/FunctionElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAAgF;AAChF,iFAA4E;AAE5E,4CAIqB;AAGrB;;GAEG;AACH,MAAa,eAAyC,SAAQ,qBAAY;IACzE,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;SAClC;IACF,CAAC;IAED,cAAc,GAAG,GAAmB,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAA4B,CAAA;QAElD,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE;YAC3B,MAAM,kBAAkB,GAAG,IAAA,sDAAyB,EACnD,IAAI,EACJ,IAAA,0BAAkB,EAAC,UAAU,CAAC,CAC9B,CAAA;YAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;YAE3D,uBAAuB;YACvB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE;gBACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;aAC9D;YAED,OAAO,MAAM,CAAA;QACd,CAAC,CAAA;IACF,CAAC,CAAA;CACD;AA3BD,0CA2BC;AAUM,MAAM,kBAAkB,GAAG,CACjC,UAIY,EACJ,EAAE;IACV,IAAI,CAAC,UAAU,EAAE;QAChB,OAAO,qBAAK,CAAC,IAAI,EAAE,CAAA;KACnB;IACD,IAAI,UAAU,YAAY,qBAAK,EAAE;QAChC,OAAO,UAAU,CAAA;KACjB;IAED,OAAO,qBAAK,CAAC,IAAI,CAChB,MAAM,CAAC,WAAW,CACjB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CACvD,CACD,CAAA;AACF,CAAC,CAAA;AAnBY,QAAA,kBAAkB,sBAmB9B"}
|
|
@@ -18,7 +18,7 @@ export declare class ResolvableSectionElement<T extends UiElementData<UiElementS
|
|
|
18
18
|
getParameterList: () => string[];
|
|
19
19
|
}
|
|
20
20
|
export declare const isChildUnresolvedSection: (value: unknown) => value is ChildUnresolvedSection;
|
|
21
|
-
export
|
|
21
|
+
export type ChildUnresolvedSection = [
|
|
22
22
|
string | undefined,
|
|
23
23
|
UiElementData<UiElementSectionMeta>
|
|
24
24
|
];
|
|
@@ -3,13 +3,13 @@ import { UiElementData, UiElementMeta } from '../UiElement';
|
|
|
3
3
|
export interface UiElementSectionMeta extends UiElementMeta {
|
|
4
4
|
resolutionType?: never;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export type ResolvedSection<T extends UiElementData<UiElementSectionMeta>> = T extends {
|
|
7
7
|
_resolved?: Record<string, unknown>;
|
|
8
8
|
} ? Required<T>['_resolved'] : Record<string, unknown>;
|
|
9
|
-
export
|
|
9
|
+
export type ParametersOfSection<T extends UiElementData> = T extends {
|
|
10
10
|
_parameters?: Record<string, HVal>;
|
|
11
11
|
} ? PartialExplicitUndefined<T['_parameters']> : undefined;
|
|
12
|
-
export
|
|
12
|
+
export type PartialExplicitUndefined<T> = {
|
|
13
13
|
[P in keyof T]: T[P] | null | undefined;
|
|
14
14
|
};
|
|
15
15
|
export declare const isSectionData: (element: UiElementData) => element is UiElementData<UiElementSectionMeta>;
|
|
@@ -3,7 +3,7 @@ import { UiElementData } from 'resolvableElements/elements/UiElement';
|
|
|
3
3
|
/**
|
|
4
4
|
* An utility type that allows a component to accept props with or without a 'section' property.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
7
7
|
section?: undefined;
|
|
8
8
|
});
|
|
9
9
|
/**
|
|
@@ -11,12 +11,9 @@ export declare type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
|
11
11
|
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
12
12
|
* If the 'section' prop is undefined, it returns an empty element.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
14
|
* @template P - Props of the original SectionComponent
|
|
17
15
|
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
18
16
|
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
19
|
-
*
|
|
20
17
|
* @example
|
|
21
18
|
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
22
19
|
* return <div>{section.title}</div>
|
|
@@ -10,12 +10,9 @@ const react_1 = __importDefault(require("react"));
|
|
|
10
10
|
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
11
11
|
* If the 'section' prop is undefined, it returns an empty element.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
13
|
* @template P - Props of the original SectionComponent
|
|
16
14
|
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
17
15
|
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
18
|
-
*
|
|
19
16
|
* @example
|
|
20
17
|
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
21
18
|
* return <div>{section.title}</div>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SectionChecker.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/SectionChecker.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AAUzB
|
|
1
|
+
{"version":3,"file":"SectionChecker.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/SectionChecker.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AAUzB;;;;;;;;;;;;GAYG;AACI,MAAM,cAAc,GAAG,CAC7B,gBAA6B,EAC5B,EAAE;IACH,MAAM,uBAAuB,GAAG,CAAC,KAAyB,EAAE,EAAE;QAC7D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAA;IAChE,CAAC,CAAA;IAED,OAAO,uBAAuB,CAAA;AAC/B,CAAC,CAAA;AARY,QAAA,cAAc,kBAQ1B"}
|
|
@@ -9,7 +9,7 @@ import { UiElementData } from '../elements/UiElement';
|
|
|
9
9
|
* @returns the resolved result of the section that will be updated and force rendering when a subvalue changes.
|
|
10
10
|
*/
|
|
11
11
|
export declare function useResolveSection<T extends UiElementData>(sectionData: T, parameters?: ParametersOfSection<T>): UseResolveSectionResult<T>;
|
|
12
|
-
export
|
|
12
|
+
export type UseResolveSectionResult<T extends UiElementData> = [
|
|
13
13
|
ResolvedSection<T>,
|
|
14
14
|
UseResolveSectionExtra<T>
|
|
15
15
|
];
|
|
@@ -6,9 +6,15 @@ import { UiElementConstructorData, UiElementData } from '../UiElement';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class ResolvableExprElement<T extends UiElementData> extends ResolvableValueElement<T> {
|
|
8
8
|
#private;
|
|
9
|
+
static collectionTypes: Set<string>;
|
|
9
10
|
constructor(data: UiElementConstructorData<T>);
|
|
10
11
|
refreshes: number;
|
|
11
12
|
protected doInitialize: (parameters: HDict) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether the declared resolvedType of this element is a collection.
|
|
15
|
+
* @returns true if the resolvedType is a collection.
|
|
16
|
+
*/
|
|
17
|
+
isExpectedResultACollection: () => boolean;
|
|
12
18
|
protected doClose: () => Promise<void>;
|
|
13
19
|
getParameterList: () => string[];
|
|
14
20
|
}
|
|
@@ -9,6 +9,7 @@ import { ResolvableValueElement } from '../ResolvableValueElement';
|
|
|
9
9
|
* Resolves to the result of an expression.
|
|
10
10
|
*/
|
|
11
11
|
export class ResolvableExprElement extends ResolvableValueElement {
|
|
12
|
+
static collectionTypes = new Set(['HGrid', 'HList']);
|
|
12
13
|
constructor(data) {
|
|
13
14
|
super(data);
|
|
14
15
|
}
|
|
@@ -26,7 +27,10 @@ export class ResolvableExprElement extends ResolvableValueElement {
|
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
28
29
|
const val = grid[0]?.get('val');
|
|
29
|
-
|
|
30
|
+
// Identify when it's necessary to unpack the result `val` or not
|
|
31
|
+
// since the eval wraps the result value in a grid's first dict `val` tag for non-collections.
|
|
32
|
+
const shouldUnpackResult = !this.isExpectedResultACollection() && val;
|
|
33
|
+
if (shouldUnpackResult) {
|
|
30
34
|
this.value = val;
|
|
31
35
|
}
|
|
32
36
|
else {
|
|
@@ -39,6 +43,15 @@ export class ResolvableExprElement extends ResolvableValueElement {
|
|
|
39
43
|
}, HNum.make(refreshAfter, second).convertTo(millisecond).value);
|
|
40
44
|
}
|
|
41
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Checks whether the declared resolvedType of this element is a collection.
|
|
48
|
+
* @returns true if the resolvedType is a collection.
|
|
49
|
+
*/
|
|
50
|
+
isExpectedResultACollection = () => {
|
|
51
|
+
const { resolvedType } = this._meta;
|
|
52
|
+
return (ResolvableExprElement.collectionTypes.has(resolvedType) ||
|
|
53
|
+
resolvedType.endsWith('[]'));
|
|
54
|
+
};
|
|
42
55
|
doClose = async () => {
|
|
43
56
|
if (this.#timeout) {
|
|
44
57
|
clearTimeout(this.#timeout);
|
|
@@ -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,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EACN,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,kCAAkC,CAAA;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAIlE;;GAEG;AACH,MAAM,OAAO,qBAEX,SAAQ,sBAAyB;IAClC,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,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IAC9B,CAAC,CAAA;IAED,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACzD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAEtE,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAEtE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;QAEzD,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE;YACnB,OAAO,CAAC,KAAK,CACZ,sCAAsC,EACtC,kBAAkB,EAClB,IAAI,CAAC,QAAQ,EAAE,CACf,CAAA;YACD,OAAM;SACN;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;QAE/B,IAAI,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"ResolvableExprElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/expr/ResolvableExprElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EACN,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,kCAAkC,CAAA;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAIlE;;GAEG;AACH,MAAM,OAAO,qBAEX,SAAQ,sBAAyB;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,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IAC9B,CAAC,CAAA;IAED,YAAY,GAAG,KAAK,EAAE,UAAiB,EAAiB,EAAE;QACzD,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,KAAkC,CAAA;QAEtE,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAEtE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;QAEzD,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE;YACnB,OAAO,CAAC,KAAK,CACZ,sCAAsC,EACtC,kBAAkB,EAClB,IAAI,CAAC,QAAQ,EAAE,CACf,CAAA;YACD,OAAM;SACN;QAED,MAAM,GAAG,GAAG,IAAI,CAA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CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACtB,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;SACF;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA"}
|
|
@@ -7,6 +7,6 @@ export declare class FunctionElement<T extends UiElementData> extends UiElement<
|
|
|
7
7
|
#private;
|
|
8
8
|
constructor(data: UiElementConstructorData<T>);
|
|
9
9
|
}
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type FunctionResult = (parameters: Parameters) => Promise<HGrid>;
|
|
11
|
+
export type Parameters = Record<string, OptionalHVal | HaysonVal | undefined> | OptionalHVal | DictStore | undefined;
|
|
12
12
|
export declare const makeParametersDict: (parameters: Record<string, OptionalHVal | HaysonVal | undefined> | OptionalHVal | DictStore | undefined) => HDict;
|
|
@@ -18,7 +18,12 @@ export class FunctionElement extends UiElement {
|
|
|
18
18
|
const { expr } = this._meta;
|
|
19
19
|
return async (parameters) => {
|
|
20
20
|
const resolvedExpression = resolveTemplateExpression(expr, makeParametersDict(parameters));
|
|
21
|
-
|
|
21
|
+
const result = await this.resolver.eval(resolvedExpression);
|
|
22
|
+
// Update watch records
|
|
23
|
+
if (!result.isError()) {
|
|
24
|
+
this.resolver.client.watch.update(result.filter('id and mod'));
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
22
27
|
};
|
|
23
28
|
};
|
|
24
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/function/FunctionElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAwB,KAAK,EAAuB,MAAM,eAAe,CAAA;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,OAAO,EACN,SAAS,GAGT,MAAM,cAAc,CAAA;AAGrB;;GAEG;AACH,MAAM,OAAO,eAAyC,SAAQ,SAAY;IACzE,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;SAClC;IACF,CAAC;IAED,cAAc,GAAG,GAAmB,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAA4B,CAAA;QAElD,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE;YAC3B,MAAM,kBAAkB,GAAG,yBAAyB,CACnD,IAAI,EACJ,kBAAkB,CAAC,UAAU,CAAC,CAC9B,CAAA;YAED,
|
|
1
|
+
{"version":3,"file":"FunctionElement.js","sourceRoot":"","sources":["../../../../src/resolvableElements/elements/function/FunctionElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAwB,KAAK,EAAuB,MAAM,eAAe,CAAA;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAE5E,OAAO,EACN,SAAS,GAGT,MAAM,cAAc,CAAA;AAGrB;;GAEG;AACH,MAAM,OAAO,eAAyC,SAAQ,SAAY;IACzE,YAAY,IAAiC;QAC5C,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;SAClC;IACF,CAAC;IAED,cAAc,GAAG,GAAmB,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAA4B,CAAA;QAElD,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE;YAC3B,MAAM,kBAAkB,GAAG,yBAAyB,CACnD,IAAI,EACJ,kBAAkB,CAAC,UAAU,CAAC,CAC9B,CAAA;YAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;YAE3D,uBAAuB;YACvB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE;gBACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;aAC9D;YAED,OAAO,MAAM,CAAA;QACd,CAAC,CAAA;IACF,CAAC,CAAA;CACD;AAUD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,UAIY,EACJ,EAAE;IACV,IAAI,CAAC,UAAU,EAAE;QAChB,OAAO,KAAK,CAAC,IAAI,EAAE,CAAA;KACnB;IACD,IAAI,UAAU,YAAY,KAAK,EAAE;QAChC,OAAO,UAAU,CAAA;KACjB;IAED,OAAO,KAAK,CAAC,IAAI,CAChB,MAAM,CAAC,WAAW,CACjB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CACvD,CACD,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -18,7 +18,7 @@ export declare class ResolvableSectionElement<T extends UiElementData<UiElementS
|
|
|
18
18
|
getParameterList: () => string[];
|
|
19
19
|
}
|
|
20
20
|
export declare const isChildUnresolvedSection: (value: unknown) => value is ChildUnresolvedSection;
|
|
21
|
-
export
|
|
21
|
+
export type ChildUnresolvedSection = [
|
|
22
22
|
string | undefined,
|
|
23
23
|
UiElementData<UiElementSectionMeta>
|
|
24
24
|
];
|
|
@@ -3,13 +3,13 @@ import { UiElementData, UiElementMeta } from '../UiElement';
|
|
|
3
3
|
export interface UiElementSectionMeta extends UiElementMeta {
|
|
4
4
|
resolutionType?: never;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export type ResolvedSection<T extends UiElementData<UiElementSectionMeta>> = T extends {
|
|
7
7
|
_resolved?: Record<string, unknown>;
|
|
8
8
|
} ? Required<T>['_resolved'] : Record<string, unknown>;
|
|
9
|
-
export
|
|
9
|
+
export type ParametersOfSection<T extends UiElementData> = T extends {
|
|
10
10
|
_parameters?: Record<string, HVal>;
|
|
11
11
|
} ? PartialExplicitUndefined<T['_parameters']> : undefined;
|
|
12
|
-
export
|
|
12
|
+
export type PartialExplicitUndefined<T> = {
|
|
13
13
|
[P in keyof T]: T[P] | null | undefined;
|
|
14
14
|
};
|
|
15
15
|
export declare const isSectionData: (element: UiElementData) => element is UiElementData<UiElementSectionMeta>;
|
|
@@ -3,7 +3,7 @@ import { UiElementData } from 'resolvableElements/elements/UiElement';
|
|
|
3
3
|
/**
|
|
4
4
|
* An utility type that allows a component to accept props with or without a 'section' property.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
7
7
|
section?: undefined;
|
|
8
8
|
});
|
|
9
9
|
/**
|
|
@@ -11,12 +11,9 @@ export declare type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
|
11
11
|
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
12
12
|
* If the 'section' prop is undefined, it returns an empty element.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
14
|
* @template P - Props of the original SectionComponent
|
|
17
15
|
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
18
16
|
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
19
|
-
*
|
|
20
17
|
* @example
|
|
21
18
|
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
22
19
|
* return <div>{section.title}</div>
|
|
@@ -4,12 +4,9 @@ import React from 'react';
|
|
|
4
4
|
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
5
5
|
* If the 'section' prop is undefined, it returns an empty element.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
7
|
* @template P - Props of the original SectionComponent
|
|
10
8
|
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
11
9
|
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
12
|
-
*
|
|
13
10
|
* @example
|
|
14
11
|
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
15
12
|
* return <div>{section.title}</div>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SectionChecker.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/SectionChecker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB
|
|
1
|
+
{"version":3,"file":"SectionChecker.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/SectionChecker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,gBAA6B,EAC5B,EAAE;IACH,MAAM,uBAAuB,GAAG,CAAC,KAAyB,EAAE,EAAE;QAC7D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAA;IAChE,CAAC,CAAA;IAED,OAAO,uBAAuB,CAAA;AAC/B,CAAC,CAAA"}
|
|
@@ -9,7 +9,7 @@ import { UiElementData } from '../elements/UiElement';
|
|
|
9
9
|
* @returns the resolved result of the section that will be updated and force rendering when a subvalue changes.
|
|
10
10
|
*/
|
|
11
11
|
export declare function useResolveSection<T extends UiElementData>(sectionData: T, parameters?: ParametersOfSection<T>): UseResolveSectionResult<T>;
|
|
12
|
-
export
|
|
12
|
+
export type UseResolveSectionResult<T extends UiElementData> = [
|
|
13
13
|
ResolvedSection<T>,
|
|
14
14
|
UseResolveSectionExtra<T>
|
|
15
15
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j2inn/resolvable-ui-elements",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"dist_es/**/*"
|
|
24
24
|
],
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"haystack-core": "^2.0.
|
|
27
|
-
"haystack-nclient": "^3.0.
|
|
28
|
-
"haystack-react": "^3.0.
|
|
29
|
-
"haystack-units": "^1.0.
|
|
26
|
+
"haystack-core": "^2.0.44",
|
|
27
|
+
"haystack-nclient": "^3.0.32-beta.1",
|
|
28
|
+
"haystack-react": "^3.0.16",
|
|
29
|
+
"haystack-units": "^1.0.22",
|
|
30
30
|
"react": "^18.2.0",
|
|
31
31
|
"react-dom": "^18.2.0"
|
|
32
32
|
},
|
|
@@ -48,5 +48,6 @@
|
|
|
48
48
|
"rimraf": "^3.0.2",
|
|
49
49
|
"ts-jest": "^28.0.8",
|
|
50
50
|
"typescript": "^4.8.2"
|
|
51
|
-
}
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {}
|
|
52
53
|
}
|