@j2inn/resolvable-ui-elements 2.0.0 → 2.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/dist/index.d.ts +12 -12
- package/dist/index.js +39 -39
- package/dist/resolvableElements/Resolver.d.ts +47 -47
- package/dist/resolvableElements/Resolver.js +57 -57
- package/dist/resolvableElements/elements/ResolvableElement.d.ts +14 -14
- package/dist/resolvableElements/elements/ResolvableElement.js +29 -29
- package/dist/resolvableElements/elements/ResolvableValueElement.d.ts +16 -16
- package/dist/resolvableElements/elements/ResolvableValueElement.js +38 -38
- package/dist/resolvableElements/elements/UiElement.d.ts +31 -31
- package/dist/resolvableElements/elements/UiElement.js +56 -56
- package/dist/resolvableElements/elements/expr/ResolvableExprElement.d.ts +26 -26
- package/dist/resolvableElements/elements/expr/ResolvableExprElement.js +105 -105
- package/dist/resolvableElements/elements/expr/ResolvableExprElementMeta.d.ts +10 -10
- package/dist/resolvableElements/elements/expr/ResolvableExprElementMeta.js +14 -14
- package/dist/resolvableElements/elements/function/FunctionElement.d.ts +12 -12
- package/dist/resolvableElements/elements/function/FunctionElement.js +41 -41
- package/dist/resolvableElements/elements/function/FunctionElementMeta.d.ts +9 -9
- package/dist/resolvableElements/elements/function/FunctionElementMeta.js +14 -14
- package/dist/resolvableElements/elements/list/ListElementMeta.d.ts +12 -12
- package/dist/resolvableElements/elements/list/ListElementMeta.js +14 -14
- package/dist/resolvableElements/elements/list/ResolvableListElement.d.ts +16 -16
- package/dist/resolvableElements/elements/list/ResolvableListElement.js +102 -102
- package/dist/resolvableElements/elements/makeElement.d.ts +7 -7
- package/dist/resolvableElements/elements/makeElement.js +40 -40
- package/dist/resolvableElements/elements/section/ResolvableSectionElement.d.ts +24 -24
- package/dist/resolvableElements/elements/section/ResolvableSectionElement.js +133 -122
- package/dist/resolvableElements/elements/section/ResolvableSectionElement.js.map +1 -1
- package/dist/resolvableElements/elements/section/SectionElementMeta.d.ts +16 -16
- package/dist/resolvableElements/elements/section/SectionElementMeta.js +11 -11
- package/dist/resolvableElements/elements/section/resolveSection.d.ts +12 -12
- package/dist/resolvableElements/elements/section/resolveSection.js +41 -41
- package/dist/resolvableElements/elements/tag/ResolvableTagElement.d.ts +18 -16
- package/dist/resolvableElements/elements/tag/ResolvableTagElement.js +113 -105
- package/dist/resolvableElements/elements/tag/ResolvableTagElement.js.map +1 -1
- package/dist/resolvableElements/elements/tag/ResolvableTagElementBatchProcessor.d.ts +25 -0
- package/dist/resolvableElements/elements/tag/ResolvableTagElementBatchProcessor.js +68 -0
- package/dist/resolvableElements/elements/tag/ResolvableTagElementBatchProcessor.js.map +1 -0
- package/dist/resolvableElements/elements/tag/TagElementMeta.d.ts +12 -12
- package/dist/resolvableElements/elements/tag/TagElementMeta.js +14 -14
- package/dist/resolvableElements/interfacesGeneration/generateInterfaces.d.ts +17 -17
- package/dist/resolvableElements/interfacesGeneration/generateInterfaces.js +134 -134
- package/dist/resolvableElements/interfacesGeneration/generateTypescriptInterfacesFile.d.ts +4 -4
- package/dist/resolvableElements/interfacesGeneration/generateTypescriptInterfacesFile.js +41 -41
- package/dist/resolvableElements/react/SectionChecker.d.ts +24 -24
- package/dist/resolvableElements/react/SectionChecker.jsx +27 -27
- package/dist/resolvableElements/react/useResolveSection.d.ts +21 -21
- package/dist/resolvableElements/react/useResolveSection.js +65 -65
- package/dist/resolvableElements/react/useResolverContext.d.ts +9 -9
- package/dist/resolvableElements/react/useResolverContext.jsx +64 -64
- package/dist/resolvableElements/resolveTemplatedExpression.d.ts +22 -22
- package/dist/resolvableElements/resolveTemplatedExpression.js +43 -43
- package/dist/useCurrentUser.d.ts +10 -10
- package/dist/useCurrentUser.jsx +48 -48
- package/dist_es/index.d.ts +12 -12
- package/dist_es/index.js +20 -20
- package/dist_es/resolvableElements/Resolver.d.ts +47 -47
- package/dist_es/resolvableElements/Resolver.js +53 -53
- package/dist_es/resolvableElements/elements/ResolvableElement.d.ts +14 -14
- package/dist_es/resolvableElements/elements/ResolvableElement.js +25 -25
- package/dist_es/resolvableElements/elements/ResolvableValueElement.d.ts +16 -16
- package/dist_es/resolvableElements/elements/ResolvableValueElement.js +32 -32
- package/dist_es/resolvableElements/elements/UiElement.d.ts +31 -31
- package/dist_es/resolvableElements/elements/UiElement.js +52 -52
- package/dist_es/resolvableElements/elements/expr/ResolvableExprElement.d.ts +26 -26
- package/dist_es/resolvableElements/elements/expr/ResolvableExprElement.js +101 -101
- package/dist_es/resolvableElements/elements/expr/ResolvableExprElementMeta.d.ts +10 -10
- package/dist_es/resolvableElements/elements/expr/ResolvableExprElementMeta.js +9 -9
- package/dist_es/resolvableElements/elements/function/FunctionElement.d.ts +12 -12
- package/dist_es/resolvableElements/elements/function/FunctionElement.js +36 -36
- package/dist_es/resolvableElements/elements/function/FunctionElementMeta.d.ts +9 -9
- package/dist_es/resolvableElements/elements/function/FunctionElementMeta.js +9 -9
- package/dist_es/resolvableElements/elements/list/ListElementMeta.d.ts +12 -12
- package/dist_es/resolvableElements/elements/list/ListElementMeta.js +9 -9
- package/dist_es/resolvableElements/elements/list/ResolvableListElement.d.ts +16 -16
- package/dist_es/resolvableElements/elements/list/ResolvableListElement.js +98 -98
- package/dist_es/resolvableElements/elements/makeElement.d.ts +7 -7
- package/dist_es/resolvableElements/elements/makeElement.js +36 -36
- package/dist_es/resolvableElements/elements/section/ResolvableSectionElement.d.ts +24 -24
- package/dist_es/resolvableElements/elements/section/ResolvableSectionElement.js +128 -117
- package/dist_es/resolvableElements/elements/section/ResolvableSectionElement.js.map +1 -1
- package/dist_es/resolvableElements/elements/section/SectionElementMeta.d.ts +16 -16
- package/dist_es/resolvableElements/elements/section/SectionElementMeta.js +6 -6
- package/dist_es/resolvableElements/elements/section/resolveSection.d.ts +12 -12
- package/dist_es/resolvableElements/elements/section/resolveSection.js +36 -36
- package/dist_es/resolvableElements/elements/tag/ResolvableTagElement.d.ts +18 -16
- package/dist_es/resolvableElements/elements/tag/ResolvableTagElement.js +109 -101
- package/dist_es/resolvableElements/elements/tag/ResolvableTagElement.js.map +1 -1
- package/dist_es/resolvableElements/elements/tag/ResolvableTagElementBatchProcessor.d.ts +25 -0
- package/dist_es/resolvableElements/elements/tag/ResolvableTagElementBatchProcessor.js +64 -0
- package/dist_es/resolvableElements/elements/tag/ResolvableTagElementBatchProcessor.js.map +1 -0
- package/dist_es/resolvableElements/elements/tag/TagElementMeta.d.ts +12 -12
- package/dist_es/resolvableElements/elements/tag/TagElementMeta.js +9 -9
- package/dist_es/resolvableElements/interfacesGeneration/generateInterfaces.d.ts +17 -17
- package/dist_es/resolvableElements/interfacesGeneration/generateInterfaces.js +128 -128
- package/dist_es/resolvableElements/interfacesGeneration/generateTypescriptInterfacesFile.d.ts +4 -4
- package/dist_es/resolvableElements/interfacesGeneration/generateTypescriptInterfacesFile.js +15 -15
- package/dist_es/resolvableElements/react/SectionChecker.d.ts +24 -24
- package/dist_es/resolvableElements/react/SectionChecker.jsx +20 -20
- package/dist_es/resolvableElements/react/useResolveSection.d.ts +21 -21
- package/dist_es/resolvableElements/react/useResolveSection.js +61 -61
- package/dist_es/resolvableElements/react/useResolverContext.d.ts +9 -9
- package/dist_es/resolvableElements/react/useResolverContext.jsx +36 -36
- package/dist_es/resolvableElements/resolveTemplatedExpression.d.ts +22 -22
- package/dist_es/resolvableElements/resolveTemplatedExpression.js +38 -38
- package/dist_es/useCurrentUser.d.ts +10 -10
- package/dist_es/useCurrentUser.jsx +20 -20
- package/package.json +2 -2
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
-
*/
|
|
4
|
-
import { HDict } from 'haystack-core';
|
|
5
|
-
import { Client } from 'haystack-nclient';
|
|
6
|
-
import { isResolvableValueElementMeta } from '../elements/ResolvableValueElement';
|
|
7
|
-
import { isChildUnresolvedSection, ResolvableSectionElement, } from '../elements/section/ResolvableSectionElement';
|
|
8
|
-
import { Resolver } from '../Resolver';
|
|
9
|
-
const ROOT_NAME = 'UiElementRoot';
|
|
10
|
-
const ELEMENT_INTERFACE_NAME = 'UiElementData';
|
|
11
|
-
export const generateInterfaces = (section) => {
|
|
12
|
-
return new SectionInterfacesGenerator(section).generate();
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Class for generating typescript interfaces from a section data.
|
|
16
|
-
*/
|
|
17
|
-
export class SectionInterfacesGenerator {
|
|
18
|
-
constructor(section) {
|
|
19
|
-
this.sectionData = section;
|
|
20
|
-
}
|
|
21
|
-
sectionData;
|
|
22
|
-
output = '';
|
|
23
|
-
#out = (str, indentation = 0) => {
|
|
24
|
-
this.output += this.#indent(indentation) + str + '\n';
|
|
25
|
-
};
|
|
26
|
-
#indent(indentation = 0) {
|
|
27
|
-
return '\t'.repeat(indentation);
|
|
28
|
-
}
|
|
29
|
-
generate = () => {
|
|
30
|
-
this.#generateImports();
|
|
31
|
-
const section = makeResolvableSectionElementMock(this.sectionData);
|
|
32
|
-
this.#generateSectionDefinition(section);
|
|
33
|
-
const result = this.output;
|
|
34
|
-
this.output = '';
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
#generateImports() {
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import { HDict } from 'haystack-core';
|
|
5
|
+
import { Client } from 'haystack-nclient';
|
|
6
|
+
import { isResolvableValueElementMeta } from '../elements/ResolvableValueElement';
|
|
7
|
+
import { isChildUnresolvedSection, ResolvableSectionElement, } from '../elements/section/ResolvableSectionElement';
|
|
8
|
+
import { Resolver } from '../Resolver';
|
|
9
|
+
const ROOT_NAME = 'UiElementRoot';
|
|
10
|
+
const ELEMENT_INTERFACE_NAME = 'UiElementData';
|
|
11
|
+
export const generateInterfaces = (section) => {
|
|
12
|
+
return new SectionInterfacesGenerator(section).generate();
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Class for generating typescript interfaces from a section data.
|
|
16
|
+
*/
|
|
17
|
+
export class SectionInterfacesGenerator {
|
|
18
|
+
constructor(section) {
|
|
19
|
+
this.sectionData = section;
|
|
20
|
+
}
|
|
21
|
+
sectionData;
|
|
22
|
+
output = '';
|
|
23
|
+
#out = (str, indentation = 0) => {
|
|
24
|
+
this.output += this.#indent(indentation) + str + '\n';
|
|
25
|
+
};
|
|
26
|
+
#indent(indentation = 0) {
|
|
27
|
+
return '\t'.repeat(indentation);
|
|
28
|
+
}
|
|
29
|
+
generate = () => {
|
|
30
|
+
this.#generateImports();
|
|
31
|
+
const section = makeResolvableSectionElementMock(this.sectionData);
|
|
32
|
+
this.#generateSectionDefinition(section);
|
|
33
|
+
const result = this.output;
|
|
34
|
+
this.output = '';
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
#generateImports() {
|
|
38
38
|
this.#out(`/* eslint-disable @typescript-eslint/no-namespace */
|
|
39
39
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
40
40
|
|
|
@@ -53,95 +53,95 @@ export const UI_ELEMENTS = json as UiElementRoot
|
|
|
53
53
|
//////////////////////////////////////////////////////////////////////////
|
|
54
54
|
// Interfaces
|
|
55
55
|
//////////////////////////////////////////////////////////////////////////
|
|
56
|
-
`);
|
|
57
|
-
}
|
|
58
|
-
#generateSectionDefinition(section, indentation = 0) {
|
|
59
|
-
this.generateInterface(section, indentation);
|
|
60
|
-
if (hasChildrenSections(section)) {
|
|
61
|
-
this.generateNamespace(section, indentation);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
generateInterface(section, indentation) {
|
|
65
|
-
const name = section.name ?? ROOT_NAME;
|
|
66
|
-
this.#out(`export interface ${capitalize(name)} extends UiElementData {`, indentation);
|
|
67
|
-
const parameters = section.getParameterList();
|
|
68
|
-
if (parameters.length > 0) {
|
|
69
|
-
this.#generateParametersProperty(parameters, indentation + 1);
|
|
70
|
-
}
|
|
71
|
-
this.#generateResolvedProperty(section, indentation + 1);
|
|
72
|
-
section.children.forEach((child) => this.#out(isChildUnresolvedSection(child)
|
|
73
|
-
? `${child[0]}: ${capitalize(name)}.${capitalize(child[0] ?? '')}`
|
|
74
|
-
: `${child.name}: ${ELEMENT_INTERFACE_NAME}`, indentation + 1));
|
|
75
|
-
this.#out(`}`, indentation);
|
|
76
|
-
}
|
|
77
|
-
#generateParametersProperty(parameters, indentation) {
|
|
78
|
-
this.#out(`_parameters?: {`, indentation);
|
|
79
|
-
parameters.forEach((param) => this.#out(`${param}: HCore.HVal`, indentation + 1));
|
|
80
|
-
this.#out(`}`, indentation);
|
|
81
|
-
}
|
|
82
|
-
#generateResolvedProperty(section, indentation) {
|
|
83
|
-
const name = section.name ?? ROOT_NAME;
|
|
84
|
-
if (section.children.length > 0) {
|
|
85
|
-
this.#out('_resolved?: {', indentation);
|
|
86
|
-
section.children.forEach((child) => this.#out(isChildUnresolvedSection(child)
|
|
87
|
-
? `${child[0]}?: ${capitalize(name)}.${capitalize(child[0] ?? '')}`
|
|
88
|
-
: `${child.name}?: ${getResolvedType(child)}`, indentation + 1));
|
|
89
|
-
this.#out('}', indentation);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.#out(`_resolved?: Record<string, unknown>`, indentation);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
generateNamespace(section, indentation) {
|
|
96
|
-
const name = section.name ?? ROOT_NAME;
|
|
97
|
-
this.#out(`export namespace ${capitalize(name)} {`, indentation);
|
|
98
|
-
section.children
|
|
99
|
-
.filter((child) => isChildUnresolvedSection(child))
|
|
100
|
-
.forEach((child) => {
|
|
101
|
-
if (isChildUnresolvedSection(child)) {
|
|
102
|
-
const section = makeResolvableSectionElementMock(child[1], child[0]);
|
|
103
|
-
this.#generateSectionDefinition(section, indentation + 1);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
this.#out(`}`, indentation);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
export function makeResolvableSectionElementMock(sectionData, name) {
|
|
110
|
-
return new ResolvableSectionElement({
|
|
111
|
-
name,
|
|
112
|
-
element: sectionData,
|
|
113
|
-
onUpdate: () => {
|
|
114
|
-
return;
|
|
115
|
-
},
|
|
116
|
-
resolver: new Resolver({
|
|
117
|
-
client: makeMockedClient(),
|
|
118
|
-
user: HDict.make({ userRole: 'su' }),
|
|
119
|
-
}),
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function makeMockedClient() {
|
|
123
|
-
return new Client({
|
|
124
|
-
base: new URL('http://localhost:8080'),
|
|
125
|
-
fetch: () => new Promise(() => {
|
|
126
|
-
return new Response();
|
|
127
|
-
}),
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function capitalize(str) {
|
|
131
|
-
return str.charAt(0)?.toUpperCase() + str.substring(1);
|
|
132
|
-
}
|
|
133
|
-
function getResolvedType(child) {
|
|
134
|
-
if (child._meta && isResolvableValueElementMeta(child._meta)) {
|
|
135
|
-
return child._meta.resolvedType.startsWith('H')
|
|
136
|
-
? 'HCore.' + child._meta.resolvedType
|
|
137
|
-
: child._meta.resolvedType;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return 'unknown';
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function hasChildrenSections(section) {
|
|
144
|
-
return (section.children.filter((child) => isChildUnresolvedSection(child))
|
|
145
|
-
.length > 0);
|
|
146
|
-
}
|
|
56
|
+
`);
|
|
57
|
+
}
|
|
58
|
+
#generateSectionDefinition(section, indentation = 0) {
|
|
59
|
+
this.generateInterface(section, indentation);
|
|
60
|
+
if (hasChildrenSections(section)) {
|
|
61
|
+
this.generateNamespace(section, indentation);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
generateInterface(section, indentation) {
|
|
65
|
+
const name = section.name ?? ROOT_NAME;
|
|
66
|
+
this.#out(`export interface ${capitalize(name)} extends UiElementData {`, indentation);
|
|
67
|
+
const parameters = section.getParameterList();
|
|
68
|
+
if (parameters.length > 0) {
|
|
69
|
+
this.#generateParametersProperty(parameters, indentation + 1);
|
|
70
|
+
}
|
|
71
|
+
this.#generateResolvedProperty(section, indentation + 1);
|
|
72
|
+
section.children.forEach((child) => this.#out(isChildUnresolvedSection(child)
|
|
73
|
+
? `${child[0]}: ${capitalize(name)}.${capitalize(child[0] ?? '')}`
|
|
74
|
+
: `${child.name}: ${ELEMENT_INTERFACE_NAME}`, indentation + 1));
|
|
75
|
+
this.#out(`}`, indentation);
|
|
76
|
+
}
|
|
77
|
+
#generateParametersProperty(parameters, indentation) {
|
|
78
|
+
this.#out(`_parameters?: {`, indentation);
|
|
79
|
+
parameters.forEach((param) => this.#out(`${param}: HCore.HVal`, indentation + 1));
|
|
80
|
+
this.#out(`}`, indentation);
|
|
81
|
+
}
|
|
82
|
+
#generateResolvedProperty(section, indentation) {
|
|
83
|
+
const name = section.name ?? ROOT_NAME;
|
|
84
|
+
if (section.children.length > 0) {
|
|
85
|
+
this.#out('_resolved?: {', indentation);
|
|
86
|
+
section.children.forEach((child) => this.#out(isChildUnresolvedSection(child)
|
|
87
|
+
? `${child[0]}?: ${capitalize(name)}.${capitalize(child[0] ?? '')}`
|
|
88
|
+
: `${child.name}?: ${getResolvedType(child)}`, indentation + 1));
|
|
89
|
+
this.#out('}', indentation);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.#out(`_resolved?: Record<string, unknown>`, indentation);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
generateNamespace(section, indentation) {
|
|
96
|
+
const name = section.name ?? ROOT_NAME;
|
|
97
|
+
this.#out(`export namespace ${capitalize(name)} {`, indentation);
|
|
98
|
+
section.children
|
|
99
|
+
.filter((child) => isChildUnresolvedSection(child))
|
|
100
|
+
.forEach((child) => {
|
|
101
|
+
if (isChildUnresolvedSection(child)) {
|
|
102
|
+
const section = makeResolvableSectionElementMock(child[1], child[0]);
|
|
103
|
+
this.#generateSectionDefinition(section, indentation + 1);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
this.#out(`}`, indentation);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function makeResolvableSectionElementMock(sectionData, name) {
|
|
110
|
+
return new ResolvableSectionElement({
|
|
111
|
+
name,
|
|
112
|
+
element: sectionData,
|
|
113
|
+
onUpdate: () => {
|
|
114
|
+
return;
|
|
115
|
+
},
|
|
116
|
+
resolver: new Resolver({
|
|
117
|
+
client: makeMockedClient(),
|
|
118
|
+
user: HDict.make({ userRole: 'su' }),
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function makeMockedClient() {
|
|
123
|
+
return new Client({
|
|
124
|
+
base: new URL('http://localhost:8080'),
|
|
125
|
+
fetch: () => new Promise(() => {
|
|
126
|
+
return new Response();
|
|
127
|
+
}),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function capitalize(str) {
|
|
131
|
+
return str.charAt(0)?.toUpperCase() + str.substring(1);
|
|
132
|
+
}
|
|
133
|
+
function getResolvedType(child) {
|
|
134
|
+
if (child._meta && isResolvableValueElementMeta(child._meta)) {
|
|
135
|
+
return child._meta.resolvedType.startsWith('H')
|
|
136
|
+
? 'HCore.' + child._meta.resolvedType
|
|
137
|
+
: child._meta.resolvedType;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return 'unknown';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function hasChildrenSections(section) {
|
|
144
|
+
return (section.children.filter((child) => isChildUnresolvedSection(child))
|
|
145
|
+
.length > 0);
|
|
146
|
+
}
|
|
147
147
|
//# sourceMappingURL=generateInterfaces.js.map
|
package/dist_es/resolvableElements/interfacesGeneration/generateTypescriptInterfacesFile.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate typescript interfaces file from json ui-elements data
|
|
3
|
-
*/
|
|
4
|
-
export default function generateTypescriptInterfacesFile(inputPath?: string, outputPath?: string): Promise<void>;
|
|
1
|
+
/**
|
|
2
|
+
* Generate typescript interfaces file from json ui-elements data
|
|
3
|
+
*/
|
|
4
|
+
export default function generateTypescriptInterfacesFile(inputPath?: string, outputPath?: string): Promise<void>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
-
*/
|
|
4
|
-
import * as fs from 'fs';
|
|
5
|
-
import { generateInterfaces } from './generateInterfaces';
|
|
6
|
-
/**
|
|
7
|
-
* Generate typescript interfaces file from json ui-elements data
|
|
8
|
-
*/
|
|
9
|
-
export default async function generateTypescriptInterfacesFile(inputPath = '../elements.json', outputPath = '../elements.ts') {
|
|
10
|
-
console.log(`Generating interfaces from ${inputPath} \n...`);
|
|
11
|
-
const json = fs.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
12
|
-
const result = generateInterfaces(JSON.parse(json));
|
|
13
|
-
fs.writeFileSync(outputPath, result);
|
|
14
|
-
console.log(`File successfully generated at: ${outputPath}`);
|
|
15
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import { generateInterfaces } from './generateInterfaces';
|
|
6
|
+
/**
|
|
7
|
+
* Generate typescript interfaces file from json ui-elements data
|
|
8
|
+
*/
|
|
9
|
+
export default async function generateTypescriptInterfacesFile(inputPath = '../elements.json', outputPath = '../elements.ts') {
|
|
10
|
+
console.log(`Generating interfaces from ${inputPath} \n...`);
|
|
11
|
+
const json = fs.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
12
|
+
const result = generateInterfaces(JSON.parse(json));
|
|
13
|
+
fs.writeFileSync(outputPath, result);
|
|
14
|
+
console.log(`File successfully generated at: ${outputPath}`);
|
|
15
|
+
}
|
|
16
16
|
//# sourceMappingURL=generateTypescriptInterfacesFile.js.map
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { UiElementData } from 'resolvableElements/elements/UiElement';
|
|
3
|
-
/**
|
|
4
|
-
* An utility type that allows a component to accept props with or without a 'section' property.
|
|
5
|
-
*/
|
|
6
|
-
export type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
7
|
-
section?: undefined;
|
|
8
|
-
});
|
|
9
|
-
/**
|
|
10
|
-
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
11
|
-
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
12
|
-
* If the 'section' prop is undefined, it returns an empty element.
|
|
13
|
-
*
|
|
14
|
-
* @template P - Props of the original SectionComponent
|
|
15
|
-
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
16
|
-
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
17
|
-
* @example
|
|
18
|
-
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
19
|
-
* return <div>{section.title}</div>
|
|
20
|
-
* })
|
|
21
|
-
*/
|
|
22
|
-
export declare const SectionChecker: <P extends {
|
|
23
|
-
section: UiElementData;
|
|
24
|
-
}>(SectionComponent: React.FC<P>) => (props: OptionalSection<P>) => JSX.Element;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UiElementData } from 'resolvableElements/elements/UiElement';
|
|
3
|
+
/**
|
|
4
|
+
* An utility type that allows a component to accept props with or without a 'section' property.
|
|
5
|
+
*/
|
|
6
|
+
export type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
7
|
+
section?: undefined;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
11
|
+
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
12
|
+
* If the 'section' prop is undefined, it returns an empty element.
|
|
13
|
+
*
|
|
14
|
+
* @template P - Props of the original SectionComponent
|
|
15
|
+
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
16
|
+
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
17
|
+
* @example
|
|
18
|
+
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
19
|
+
* return <div>{section.title}</div>
|
|
20
|
+
* })
|
|
21
|
+
*/
|
|
22
|
+
export declare const SectionChecker: <P extends {
|
|
23
|
+
section: UiElementData;
|
|
24
|
+
}>(SectionComponent: React.FC<P>) => (props: OptionalSection<P>) => JSX.Element;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
4
|
-
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
5
|
-
* If the 'section' prop is undefined, it returns an empty element.
|
|
6
|
-
*
|
|
7
|
-
* @template P - Props of the original SectionComponent
|
|
8
|
-
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
9
|
-
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
10
|
-
* @example
|
|
11
|
-
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
12
|
-
* return <div>{section.title}</div>
|
|
13
|
-
* })
|
|
14
|
-
*/
|
|
15
|
-
export const SectionChecker = (SectionComponent) => {
|
|
16
|
-
const CheckedSectionComponent = (props) => {
|
|
17
|
-
return !props.section ? <></> : <SectionComponent {...props}/>;
|
|
18
|
-
};
|
|
19
|
-
return CheckedSectionComponent;
|
|
20
|
-
};
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
4
|
+
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
5
|
+
* If the 'section' prop is undefined, it returns an empty element.
|
|
6
|
+
*
|
|
7
|
+
* @template P - Props of the original SectionComponent
|
|
8
|
+
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
9
|
+
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
10
|
+
* @example
|
|
11
|
+
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
12
|
+
* return <div>{section.title}</div>
|
|
13
|
+
* })
|
|
14
|
+
*/
|
|
15
|
+
export const SectionChecker = (SectionComponent) => {
|
|
16
|
+
const CheckedSectionComponent = (props) => {
|
|
17
|
+
return !props.section ? <></> : <SectionComponent {...props}/>;
|
|
18
|
+
};
|
|
19
|
+
return CheckedSectionComponent;
|
|
20
|
+
};
|
|
21
21
|
//# sourceMappingURL=SectionChecker.jsx.map
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { UiElementData } from '../elements/UiElement';
|
|
2
|
-
import { ResolvableSectionElement } from '../elements/section/ResolvableSectionElement';
|
|
3
|
-
import { ParametersOfSection, ResolvedSection } from '../elements/section/SectionElementMeta';
|
|
4
|
-
/**
|
|
5
|
-
* Resolves a section UI element.
|
|
6
|
-
* IMPORTANT: This hook requires a resolver react context defined. @See `ResolverProvider`.
|
|
7
|
-
* @param sectionData section data object
|
|
8
|
-
* @param parameters parameters for the resolution
|
|
9
|
-
* @returns the resolved result of the section that will be updated and force rendering when a subvalue changes.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useResolveSection<T extends UiElementData>(sectionData: T, parameters?: ParametersOfSection<T>): UseResolveSectionResult<T>;
|
|
12
|
-
export type UseResolveSectionResult<T extends UiElementData> = [
|
|
13
|
-
ResolvedSection<T>,
|
|
14
|
-
UseResolveSectionExtra<T>
|
|
15
|
-
];
|
|
16
|
-
export interface UseResolveSectionExtra<T extends UiElementData> {
|
|
17
|
-
refresh: () => void;
|
|
18
|
-
element?: ResolvableSectionElement<T>;
|
|
19
|
-
loads: number;
|
|
20
|
-
isLoading: boolean;
|
|
21
|
-
}
|
|
1
|
+
import { UiElementData } from '../elements/UiElement';
|
|
2
|
+
import { ResolvableSectionElement } from '../elements/section/ResolvableSectionElement';
|
|
3
|
+
import { ParametersOfSection, ResolvedSection } from '../elements/section/SectionElementMeta';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a section UI element.
|
|
6
|
+
* IMPORTANT: This hook requires a resolver react context defined. @See `ResolverProvider`.
|
|
7
|
+
* @param sectionData section data object
|
|
8
|
+
* @param parameters parameters for the resolution
|
|
9
|
+
* @returns the resolved result of the section that will be updated and force rendering when a subvalue changes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useResolveSection<T extends UiElementData>(sectionData: T, parameters?: ParametersOfSection<T>): UseResolveSectionResult<T>;
|
|
12
|
+
export type UseResolveSectionResult<T extends UiElementData> = [
|
|
13
|
+
ResolvedSection<T>,
|
|
14
|
+
UseResolveSectionExtra<T>
|
|
15
|
+
];
|
|
16
|
+
export interface UseResolveSectionExtra<T extends UiElementData> {
|
|
17
|
+
refresh: () => void;
|
|
18
|
+
element?: ResolvableSectionElement<T>;
|
|
19
|
+
loads: number;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
}
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
-
*/
|
|
4
|
-
import { useEffect, useReducer, useRef, useState } from 'react';
|
|
5
|
-
import { makeParametersDict } from '../elements/function/FunctionElement';
|
|
6
|
-
import { ResolvableSectionElement } from '../elements/section/ResolvableSectionElement';
|
|
7
|
-
import { areParametersValid } from '../elements/section/resolveSection';
|
|
8
|
-
import { useResolverContext } from './useResolverContext';
|
|
9
|
-
/**
|
|
10
|
-
* Resolves a section UI element.
|
|
11
|
-
* IMPORTANT: This hook requires a resolver react context defined. @See `ResolverProvider`.
|
|
12
|
-
* @param sectionData section data object
|
|
13
|
-
* @param parameters parameters for the resolution
|
|
14
|
-
* @returns the resolved result of the section that will be updated and force rendering when a subvalue changes.
|
|
15
|
-
*/
|
|
16
|
-
export function useResolveSection(sectionData, parameters) {
|
|
17
|
-
const [, update] = useReducer((count) => count + 1, 0);
|
|
18
|
-
const resolver = useResolverContext();
|
|
19
|
-
const [refreshes, refresh] = useReducer((count) => count + 1, 0);
|
|
20
|
-
const [loads, setLoads] = useState(0);
|
|
21
|
-
const [isLoading, setLoading] = useState(false);
|
|
22
|
-
const ref = useRef();
|
|
23
|
-
if (!ref.current) {
|
|
24
|
-
ref.current = new ResolvableSectionElement({
|
|
25
|
-
element: sectionData,
|
|
26
|
-
resolver,
|
|
27
|
-
onUpdate: update,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const parametersDict = makeParametersDict(parameters);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (areParametersValid(parameters)) {
|
|
33
|
-
ref.current = new ResolvableSectionElement({
|
|
34
|
-
element: sectionData,
|
|
35
|
-
resolver,
|
|
36
|
-
onUpdate: update,
|
|
37
|
-
});
|
|
38
|
-
setLoading(true);
|
|
39
|
-
const promise = ref.current
|
|
40
|
-
.initialize(parametersDict)
|
|
41
|
-
.then(() => setLoads(loads + 1))
|
|
42
|
-
.finally(() => setLoading(false));
|
|
43
|
-
return () => {
|
|
44
|
-
const sectionElement = ref.current;
|
|
45
|
-
promise.finally(() => {
|
|
46
|
-
sectionElement?.close();
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}, [sectionData, resolver, refreshes, parametersDict.toAxon()]);
|
|
52
|
-
return [
|
|
53
|
-
(ref.current.value ?? {}),
|
|
54
|
-
{
|
|
55
|
-
refresh: refresh,
|
|
56
|
-
element: ref.current,
|
|
57
|
-
loads,
|
|
58
|
-
isLoading,
|
|
59
|
-
},
|
|
60
|
-
];
|
|
61
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useReducer, useRef, useState } from 'react';
|
|
5
|
+
import { makeParametersDict } from '../elements/function/FunctionElement';
|
|
6
|
+
import { ResolvableSectionElement } from '../elements/section/ResolvableSectionElement';
|
|
7
|
+
import { areParametersValid } from '../elements/section/resolveSection';
|
|
8
|
+
import { useResolverContext } from './useResolverContext';
|
|
9
|
+
/**
|
|
10
|
+
* Resolves a section UI element.
|
|
11
|
+
* IMPORTANT: This hook requires a resolver react context defined. @See `ResolverProvider`.
|
|
12
|
+
* @param sectionData section data object
|
|
13
|
+
* @param parameters parameters for the resolution
|
|
14
|
+
* @returns the resolved result of the section that will be updated and force rendering when a subvalue changes.
|
|
15
|
+
*/
|
|
16
|
+
export function useResolveSection(sectionData, parameters) {
|
|
17
|
+
const [, update] = useReducer((count) => count + 1, 0);
|
|
18
|
+
const resolver = useResolverContext();
|
|
19
|
+
const [refreshes, refresh] = useReducer((count) => count + 1, 0);
|
|
20
|
+
const [loads, setLoads] = useState(0);
|
|
21
|
+
const [isLoading, setLoading] = useState(false);
|
|
22
|
+
const ref = useRef();
|
|
23
|
+
if (!ref.current) {
|
|
24
|
+
ref.current = new ResolvableSectionElement({
|
|
25
|
+
element: sectionData,
|
|
26
|
+
resolver,
|
|
27
|
+
onUpdate: update,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const parametersDict = makeParametersDict(parameters);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (areParametersValid(parameters)) {
|
|
33
|
+
ref.current = new ResolvableSectionElement({
|
|
34
|
+
element: sectionData,
|
|
35
|
+
resolver,
|
|
36
|
+
onUpdate: update,
|
|
37
|
+
});
|
|
38
|
+
setLoading(true);
|
|
39
|
+
const promise = ref.current
|
|
40
|
+
.initialize(parametersDict)
|
|
41
|
+
.then(() => setLoads(loads + 1))
|
|
42
|
+
.finally(() => setLoading(false));
|
|
43
|
+
return () => {
|
|
44
|
+
const sectionElement = ref.current;
|
|
45
|
+
promise.finally(() => {
|
|
46
|
+
sectionElement?.close();
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}, [sectionData, resolver, refreshes, parametersDict.toAxon()]);
|
|
52
|
+
return [
|
|
53
|
+
(ref.current.value ?? {}),
|
|
54
|
+
{
|
|
55
|
+
refresh: refresh,
|
|
56
|
+
element: ref.current,
|
|
57
|
+
loads,
|
|
58
|
+
isLoading,
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
62
|
//# sourceMappingURL=useResolveSection.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { Resolver } from '../Resolver';
|
|
3
|
-
export declare function useResolverContext(): Resolver;
|
|
4
|
-
interface ResolverProviderProps extends PropsWithChildren {
|
|
5
|
-
userRoleTagName?: string;
|
|
6
|
-
evalFuncName?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare const ResolverProvider: React.FC<ResolverProviderProps>;
|
|
9
|
-
export {};
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { Resolver } from '../Resolver';
|
|
3
|
+
export declare function useResolverContext(): Resolver;
|
|
4
|
+
interface ResolverProviderProps extends PropsWithChildren {
|
|
5
|
+
userRoleTagName?: string;
|
|
6
|
+
evalFuncName?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const ResolverProvider: React.FC<ResolverProviderProps>;
|
|
9
|
+
export {};
|