@tsed/schema-formio 7.0.0-beta.2 → 7.0.0-beta.20
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/jest.config.js +1 -1
- package/lib/cjs/components/anyToComponent.js +1 -1
- package/lib/cjs/components/anyToComponent.js.map +1 -1
- package/lib/cjs/components/propertiesToComponents.js +8 -3
- package/lib/cjs/components/propertiesToComponents.js.map +1 -1
- package/lib/cjs/decorators/customConditional.js +1 -2
- package/lib/cjs/decorators/customConditional.js.map +1 -1
- package/lib/cjs/index.js +52 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/utils/getFormioSchema.js +13 -1
- package/lib/cjs/utils/getFormioSchema.js.map +1 -1
- package/lib/esm/components/anyToComponent.js +3 -3
- package/lib/esm/components/anyToComponent.js.map +1 -1
- package/lib/esm/components/arrayToComponent.js +2 -2
- package/lib/esm/components/booleanToComponent.js +1 -1
- package/lib/esm/components/dateToComponent.js +1 -1
- package/lib/esm/components/defaultToComponent.js +2 -2
- package/lib/esm/components/enumToComponent.js +1 -1
- package/lib/esm/components/mapToComponent.js +1 -1
- package/lib/esm/components/nestedToComponent.js +1 -1
- package/lib/esm/components/numberToComponent.js +1 -1
- package/lib/esm/components/objectToEditGrid.js +1 -1
- package/lib/esm/components/panelToComponent.js +1 -1
- package/lib/esm/components/propertiesToComponents.js +9 -4
- package/lib/esm/components/propertiesToComponents.js.map +1 -1
- package/lib/esm/components/stringToComponent.js +1 -1
- package/lib/esm/decorators/conditional.js +1 -1
- package/lib/esm/decorators/currency.js +1 -1
- package/lib/esm/decorators/customClass.js +1 -1
- package/lib/esm/decorators/customConditional.js +2 -3
- package/lib/esm/decorators/customConditional.js.map +1 -1
- package/lib/esm/decorators/dataSourceJson.js +1 -1
- package/lib/esm/decorators/dataSourceUrl.js +1 -1
- package/lib/esm/decorators/errorLabel.js +1 -1
- package/lib/esm/decorators/errorMessage.js +1 -1
- package/lib/esm/decorators/form.js +1 -1
- package/lib/esm/decorators/hidden.js +1 -1
- package/lib/esm/decorators/inputTags.js +1 -1
- package/lib/esm/decorators/label.js +1 -1
- package/lib/esm/decorators/mask.js +1 -1
- package/lib/esm/decorators/maxWords.js +1 -1
- package/lib/esm/decorators/minWords.js +1 -1
- package/lib/esm/decorators/modalEdit.js +1 -1
- package/lib/esm/decorators/multiple.js +1 -1
- package/lib/esm/decorators/openWhenEmpty.js +1 -1
- package/lib/esm/decorators/password.js +1 -1
- package/lib/esm/decorators/placeholder.js +1 -1
- package/lib/esm/decorators/prefix.js +1 -1
- package/lib/esm/decorators/select.js +1 -1
- package/lib/esm/decorators/suffix.js +1 -1
- package/lib/esm/decorators/tableView.js +1 -1
- package/lib/esm/decorators/textCase.js +1 -1
- package/lib/esm/decorators/textarea.js +1 -1
- package/lib/esm/decorators/tooltip.js +1 -1
- package/lib/esm/decorators/validate.js +1 -1
- package/lib/esm/index.js +52 -4
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/utils/getFormioSchema.js +15 -3
- package/lib/esm/utils/getFormioSchema.js.map +1 -1
- package/lib/types/index.d.ts +50 -2
- package/lib/types/utils/getFormioSchema.d.ts +14 -2
- package/package.json +37 -12
- package/readme.md +9 -6
- package/tsconfig.compile.esm.json +1 -12
- package/lib/cjs/components/index.js +0 -17
- package/lib/cjs/components/index.js.map +0 -1
- package/lib/cjs/decorators/index.js +0 -34
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/esm/components/index.js +0 -14
- package/lib/esm/components/index.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -31
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/types/components/index.d.ts +0 -13
- package/lib/types/decorators/index.d.ts +0 -30
package/jest.config.js
CHANGED
|
@@ -5,7 +5,7 @@ const FormioMappersContainer_1 = require("../registries/FormioMappersContainer")
|
|
|
5
5
|
const getRef_1 = require("../utils/getRef");
|
|
6
6
|
function anyToComponent(schema, options) {
|
|
7
7
|
schema = (0, getRef_1.getRef)(schema, options);
|
|
8
|
-
switch (schema
|
|
8
|
+
switch (schema?.type) {
|
|
9
9
|
case "object":
|
|
10
10
|
if (!schema.properties && !schema.$ref) {
|
|
11
11
|
return (0, FormioMappersContainer_1.execMapper)("map", schema, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anyToComponent.js","sourceRoot":"","sources":["../../../src/components/anyToComponent.ts"],"names":[],"mappings":";;;AAAA,iFAAsF;AACtF,4CAAuC;AAEvC,SAAgB,cAAc,CAAC,MAAW,EAAE,OAAY;IACtD,MAAM,GAAG,IAAA,eAAM,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"anyToComponent.js","sourceRoot":"","sources":["../../../src/components/anyToComponent.ts"],"names":[],"mappings":";;;AAAA,iFAAsF;AACtF,4CAAuC;AAEvC,SAAgB,cAAc,CAAC,MAAW,EAAE,OAAY;IACtD,MAAM,GAAG,IAAA,eAAM,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC,QAAQ,MAAM,EAAE,IAAI,EAAE;QACpB,KAAK,QAAQ;YACX,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;gBACtC,OAAO,IAAA,mCAAU,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;aAC3C;YAED,OAAO,IAAA,mCAAU,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C,KAAK,OAAO;YACV,OAAO,IAAA,mCAAU,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9C,KAAK,QAAQ;YACX,OAAO,IAAA,mCAAU,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C,KAAK,SAAS;YACZ,OAAO,IAAA,mCAAU,EAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAChD,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,IAAA,mCAAU,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KAChD;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAtBD,wCAsBC;AAED,IAAA,6CAAoB,EAAC,KAAK,EAAE,cAAc,CAAC,CAAC","sourcesContent":["import {execMapper, registerFormioMapper} from \"../registries/FormioMappersContainer\";\nimport {getRef} from \"../utils/getRef\";\n\nexport function anyToComponent(schema: any, options: any) {\n schema = getRef(schema, options);\n\n switch (schema?.type) {\n case \"object\":\n if (!schema.properties && !schema.$ref) {\n return execMapper(\"map\", schema, options);\n }\n\n return execMapper(\"nested\", schema, options);\n case \"array\":\n return execMapper(\"array\", schema, options);\n case \"string\":\n return execMapper(\"string\", schema, options);\n case \"boolean\":\n return execMapper(\"boolean\", schema, options);\n case \"integer\":\n case \"number\":\n return execMapper(\"number\", schema, options);\n }\n\n return {};\n}\n\nregisterFormioMapper(\"any\", anyToComponent);\n"]}
|
|
@@ -6,7 +6,7 @@ const change_case_1 = require("change-case");
|
|
|
6
6
|
const FormioMappersContainer_1 = require("../registries/FormioMappersContainer");
|
|
7
7
|
function bindResolvers(component, options) {
|
|
8
8
|
if (component.data) {
|
|
9
|
-
const data = component.data;
|
|
9
|
+
const data = { ...component.data };
|
|
10
10
|
Object.entries(data).forEach(([key, resolver]) => {
|
|
11
11
|
if ((0, core_1.isFunction)(resolver)) {
|
|
12
12
|
options.resolvers.push(async (form) => {
|
|
@@ -14,7 +14,12 @@ function bindResolvers(component, options) {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
+
return {
|
|
18
|
+
...component,
|
|
19
|
+
data
|
|
20
|
+
};
|
|
17
21
|
}
|
|
22
|
+
return component;
|
|
18
23
|
}
|
|
19
24
|
function mapValidation(key, base, schema, propSchema) {
|
|
20
25
|
const required = (schema.required || []).includes(key);
|
|
@@ -54,13 +59,13 @@ function propertiesToComponents(schema, options) {
|
|
|
54
59
|
Object.entries(schema.properties).forEach(([key, propSchema]) => {
|
|
55
60
|
const tabsOptions = propSchema["x-formiotabs"];
|
|
56
61
|
const base = (0, FormioMappersContainer_1.execMapper)("any", propSchema, { parentKey: key, ...options });
|
|
57
|
-
|
|
62
|
+
let component = (0, core_1.cleanObject)({
|
|
58
63
|
key,
|
|
59
64
|
...base,
|
|
60
65
|
label: base.label == false ? undefined : base.label || propSchema.title || (0, change_case_1.sentenceCase)(key),
|
|
61
66
|
validate: mapValidation(key, base, schema, propSchema)
|
|
62
67
|
});
|
|
63
|
-
bindResolvers(component, options);
|
|
68
|
+
component = bindResolvers(component, options);
|
|
64
69
|
if (tabsOptions) {
|
|
65
70
|
if (!tabs.pushed) {
|
|
66
71
|
components.push(tabs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertiesToComponents.js","sourceRoot":"","sources":["../../../src/components/propertiesToComponents.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;
|
|
1
|
+
{"version":3,"file":"propertiesToComponents.js","sourceRoot":"","sources":["../../../src/components/propertiesToComponents.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AAEnD,6CAAyC;AACzC,iFAAsF;AAEtF,SAAS,aAAa,CAAC,SAA0B,EAAE,OAAY;IAC7D,IAAI,SAAS,CAAC,IAAI,EAAE;QAClB,MAAM,IAAI,GAAG,EAAC,GAAG,SAAS,CAAC,IAAI,EAAC,CAAC;QAEjC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE;YAC/C,IAAI,IAAA,iBAAU,EAAC,QAAQ,CAAC,EAAE;gBACxB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAgB,EAAE,EAAE;oBAChD,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,QAAQ,CA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,CAAC,GAAG,EAAE;oBACnC,GAAG,WAAW;oBACd,UAAU,EAAE,EAAE;iBACf,CAAC,CAAC;aACJ;YAED,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SACjE;aAAM;YACL,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC5B;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;QACxB,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAQ,CAAC;KACxD;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAjDD,wDAiDC;AAED,IAAA,6CAAoB,EAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC","sourcesContent":["import {cleanObject, isFunction} from \"@tsed/core\";\nimport {FormioComponent, FormioForm} from \"@tsed/formio-types\";\nimport {sentenceCase} from \"change-case\";\nimport {execMapper, registerFormioMapper} from \"../registries/FormioMappersContainer\";\n\nfunction bindResolvers(component: FormioComponent, options: any) {\n if (component.data) {\n const data = {...component.data};\n\n Object.entries(data).forEach(([key, resolver]) => {\n if (isFunction(resolver)) {\n options.resolvers.push(async (form: FormioForm) => {\n data[key] = await resolver({...options, component, form});\n });\n }\n });\n\n return {\n ...component,\n data\n };\n }\n\n return component;\n}\n\nfunction mapValidation(key: string, base: FormioComponent, schema: any, propSchema: any) {\n const required = (schema.required || []).includes(key);\n const validate = {\n ...(base.validate || {}),\n required,\n pattern: propSchema.pattern,\n minLength: !required || (required && propSchema.minLength > 1) ? propSchema.minLength : undefined,\n maxLength: propSchema.maxLength,\n min: propSchema.minimum,\n max: propSchema.maximum\n };\n\n switch (propSchema.type) {\n case \"string\":\n if (propSchema.minLength === 0 && validate.required) {\n validate.minLength = undefined;\n validate.required = false;\n }\n break;\n case \"boolean\":\n validate.required = false;\n break;\n }\n\n return cleanObject(validate);\n}\n\nexport function propertiesToComponents(schema: any, options: any): any[] {\n const tabs = {\n label: \"Tabs\",\n key: \"tabs\",\n type: \"tabs\",\n input: false,\n tableView: false,\n components: new Map<string, any>(),\n pushed: false\n };\n const components: any[] = [];\n\n Object.entries(schema.properties).forEach(([key, propSchema]: [string, any]) => {\n const tabsOptions = propSchema[\"x-formiotabs\"];\n const base = execMapper(\"any\", propSchema, {parentKey: key, ...options});\n\n let component = cleanObject({\n key,\n ...base,\n label: base.label == false ? undefined : base.label || propSchema.title || sentenceCase(key),\n validate: mapValidation(key, base, schema, propSchema)\n });\n\n component = bindResolvers(component, options);\n\n if (tabsOptions) {\n if (!tabs.pushed) {\n components.push(tabs);\n tabs.pushed = true;\n }\n\n if (!tabs.components.has(tabsOptions.key)) {\n tabs.components.set(tabsOptions.key, {\n ...tabsOptions,\n components: []\n });\n }\n\n tabs.components.get(tabsOptions.key).components.push(component);\n } else {\n components.push(component);\n }\n });\n\n if (tabs.components.size) {\n tabs.components = [...tabs.components.values()] as any;\n }\n\n return components;\n}\n\nregisterFormioMapper(\"properties\", propertiesToComponents);\n"]}
|
|
@@ -8,8 +8,7 @@ function sanitize(customConditional) {
|
|
|
8
8
|
const [signature, ...fn] = str.split("=>");
|
|
9
9
|
let content = fn.join("=>");
|
|
10
10
|
if (!signature.includes("{")) {
|
|
11
|
-
|
|
12
|
-
content = content.replace(new RegExp(reg, "gi"), "");
|
|
11
|
+
content = content.replace(new RegExp(`${signature.trim()}.`, "gi"), "");
|
|
13
12
|
}
|
|
14
13
|
return `show = ${content.trim()}`;
|
|
15
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customConditional.js","sourceRoot":"","sources":["../../../src/decorators/customConditional.ts"],"names":[],"mappings":";;;AAIA,2CAAsC;AACtC,qCAAqC;AAiDrC,SAAS,QAAQ,CAAC,iBAA2B;IAC3C,MAAM,GAAG,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAEzC,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE5B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC5B,
|
|
1
|
+
{"version":3,"file":"customConditional.js","sourceRoot":"","sources":["../../../src/decorators/customConditional.ts"],"names":[],"mappings":";;;AAIA,2CAAsC;AACtC,qCAAqC;AAiDrC,SAAS,QAAQ,CAAC,iBAA2B;IAC3C,MAAM,GAAG,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAEzC,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE5B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC5B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;KACzE;IAED,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,iBAAgE;IAChG,IAAI,IAAA,gBAAS,EAAC,iBAAiB,CAAC,EAAE;QAChC,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;KACjD;IAED,OAAO,IAAA,qBAAS,EAAC;QACf,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC;AARD,8CAQC","sourcesContent":["import {FormioComponent, FormioForm, FormioSubmission} from \"@tsed/formio-types\";\nimport type {Moment} from \"moment\";\nimport type {LoDashStatic} from \"lodash\";\nimport type {Utils} from \"formiojs\";\nimport {Component} from \"./component\";\nimport {isArrowFn} from \"@tsed/core\";\n\nexport interface CustomConditionalCtx<Value = any, Data = any, Row = any> {\n /**\n * The complete submission object.\n */\n form: FormioForm;\n /**\n * The complete submission object.\n */\n submission: FormioSubmission<Data>;\n /**\n * The complete submission data object.\n */\n data: Data;\n /**\n * Contextual \"row\" data, used within DataGrid, EditGrid, and Container components\n */\n row: Row;\n /**\n * The current component JSON\n */\n component: FormioComponent;\n /**\n * The current component instance.\n */\n instance: any;\n /**\n * The current value of the component.\n */\n value: Value;\n /**\n * The moment.js library for date manipulation.\n */\n moment: Moment;\n /**\n * An instance of Lodash.\n */\n _: LoDashStatic;\n /**\n * An instance of the FormioUtils object.\n */\n utils: typeof Utils;\n /**\n * An alias for \"utils\".\n */\n util: typeof Utils;\n}\n\nfunction sanitize(customConditional: Function) {\n const str = customConditional.toString();\n\n const [signature, ...fn] = str.split(\"=>\");\n let content = fn.join(\"=>\");\n\n if (!signature.includes(\"{\")) {\n content = content.replace(new RegExp(`${signature.trim()}.`, \"gi\"), \"\");\n }\n\n return `show = ${content.trim()}`;\n}\n\n/**\n * Adds custom conditional rule to display or not the input form.\n * @decorator\n * @formio\n * @property\n * @schema\n * @param customConditional\n */\nexport function CustomConditional(customConditional: string | ((ctx: CustomConditionalCtx) => any)) {\n if (isArrowFn(customConditional)) {\n customConditional = sanitize(customConditional);\n }\n\n return Component({\n customConditional\n });\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,8 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
tslib_1.__exportStar(require("./components/anyToComponent"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./components/arrayToComponent"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./components/booleanToComponent"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./components/dateToComponent"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./components/defaultToComponent"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./components/enumToComponent"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./components/mapToComponent"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./components/nestedToComponent"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./components/numberToComponent"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./components/objectToEditGrid"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./components/panelToComponent"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./components/propertiesToComponents"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./components/stringToComponent"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./decorators/component"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./decorators/conditional"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./decorators/currency"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./decorators/customClass"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./decorators/customConditional"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./decorators/dataSourceJson"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./decorators/dataSourceUrl"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./decorators/errorLabel"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./decorators/errorMessage"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./decorators/form"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./decorators/hidden"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./decorators/inputTags"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./decorators/label"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./decorators/mask"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./decorators/maxWords"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./decorators/minWords"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./decorators/modalEdit"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./decorators/multiple"), exports);
|
|
38
|
+
tslib_1.__exportStar(require("./decorators/openWhenEmpty"), exports);
|
|
39
|
+
tslib_1.__exportStar(require("./decorators/password"), exports);
|
|
40
|
+
tslib_1.__exportStar(require("./decorators/placeholder"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./decorators/prefix"), exports);
|
|
42
|
+
tslib_1.__exportStar(require("./decorators/select"), exports);
|
|
43
|
+
tslib_1.__exportStar(require("./decorators/suffix"), exports);
|
|
44
|
+
tslib_1.__exportStar(require("./decorators/tableView"), exports);
|
|
45
|
+
tslib_1.__exportStar(require("./decorators/tabs"), exports);
|
|
46
|
+
tslib_1.__exportStar(require("./decorators/textCase"), exports);
|
|
47
|
+
tslib_1.__exportStar(require("./decorators/textarea"), exports);
|
|
48
|
+
tslib_1.__exportStar(require("./decorators/tooltip"), exports);
|
|
49
|
+
tslib_1.__exportStar(require("./decorators/validate"), exports);
|
|
50
|
+
tslib_1.__exportStar(require("./domain/FormioDataResolver"), exports);
|
|
51
|
+
tslib_1.__exportStar(require("./registries/FormioMappersContainer"), exports);
|
|
52
|
+
tslib_1.__exportStar(require("./registries/FormsContainer"), exports);
|
|
53
|
+
tslib_1.__exportStar(require("./utils/getFormioProps"), exports);
|
|
54
|
+
tslib_1.__exportStar(require("./utils/getFormioSchema"), exports);
|
|
55
|
+
tslib_1.__exportStar(require("./utils/getRef"), exports);
|
|
8
56
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,sEAA4C;AAC5C,wEAA8C;AAC9C,0EAAgD;AAChD,uEAA6C;AAC7C,0EAAgD;AAChD,uEAA6C;AAC7C,sEAA4C;AAC5C,yEAA+C;AAC/C,yEAA+C;AAC/C,wEAA8C;AAC9C,wEAA8C;AAC9C,8EAAoD;AACpD,yEAA+C;AAC/C,iEAAuC;AACvC,mEAAyC;AACzC,gEAAsC;AACtC,mEAAyC;AACzC,yEAA+C;AAC/C,sEAA4C;AAC5C,qEAA2C;AAC3C,kEAAwC;AACxC,oEAA0C;AAC1C,4DAAkC;AAClC,8DAAoC;AACpC,iEAAuC;AACvC,6DAAmC;AACnC,4DAAkC;AAClC,gEAAsC;AACtC,gEAAsC;AACtC,iEAAuC;AACvC,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,mEAAyC;AACzC,8DAAoC;AACpC,8DAAoC;AACpC,8DAAoC;AACpC,iEAAuC;AACvC,4DAAkC;AAClC,gEAAsC;AACtC,gEAAsC;AACtC,+DAAqC;AACrC,gEAAsC;AACtC,sEAA4C;AAC5C,8EAAoD;AACpD,sEAA4C;AAC5C,iEAAuC;AACvC,kEAAwC;AACxC,yDAA+B","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/anyToComponent\";\nexport * from \"./components/arrayToComponent\";\nexport * from \"./components/booleanToComponent\";\nexport * from \"./components/dateToComponent\";\nexport * from \"./components/defaultToComponent\";\nexport * from \"./components/enumToComponent\";\nexport * from \"./components/mapToComponent\";\nexport * from \"./components/nestedToComponent\";\nexport * from \"./components/numberToComponent\";\nexport * from \"./components/objectToEditGrid\";\nexport * from \"./components/panelToComponent\";\nexport * from \"./components/propertiesToComponents\";\nexport * from \"./components/stringToComponent\";\nexport * from \"./decorators/component\";\nexport * from \"./decorators/conditional\";\nexport * from \"./decorators/currency\";\nexport * from \"./decorators/customClass\";\nexport * from \"./decorators/customConditional\";\nexport * from \"./decorators/dataSourceJson\";\nexport * from \"./decorators/dataSourceUrl\";\nexport * from \"./decorators/errorLabel\";\nexport * from \"./decorators/errorMessage\";\nexport * from \"./decorators/form\";\nexport * from \"./decorators/hidden\";\nexport * from \"./decorators/inputTags\";\nexport * from \"./decorators/label\";\nexport * from \"./decorators/mask\";\nexport * from \"./decorators/maxWords\";\nexport * from \"./decorators/minWords\";\nexport * from \"./decorators/modalEdit\";\nexport * from \"./decorators/multiple\";\nexport * from \"./decorators/openWhenEmpty\";\nexport * from \"./decorators/password\";\nexport * from \"./decorators/placeholder\";\nexport * from \"./decorators/prefix\";\nexport * from \"./decorators/select\";\nexport * from \"./decorators/suffix\";\nexport * from \"./decorators/tableView\";\nexport * from \"./decorators/tabs\";\nexport * from \"./decorators/textCase\";\nexport * from \"./decorators/textarea\";\nexport * from \"./decorators/tooltip\";\nexport * from \"./decorators/validate\";\nexport * from \"./domain/FormioDataResolver\";\nexport * from \"./registries/FormioMappersContainer\";\nexport * from \"./registries/FormsContainer\";\nexport * from \"./utils/getFormioProps\";\nexport * from \"./utils/getFormioSchema\";\nexport * from \"./utils/getRef\";\n"]}
|
|
@@ -4,9 +4,21 @@ exports.getFormioSchema = void 0;
|
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
const schema_1 = require("@tsed/schema");
|
|
6
6
|
const FormioMappersContainer_1 = require("../registries/FormioMappersContainer");
|
|
7
|
-
require("../components");
|
|
8
7
|
const FormsContainer_1 = require("../registries/FormsContainer");
|
|
9
8
|
const change_case_1 = require("change-case");
|
|
9
|
+
require("../components/anyToComponent");
|
|
10
|
+
require("../components/arrayToComponent");
|
|
11
|
+
require("../components/booleanToComponent");
|
|
12
|
+
require("../components/dateToComponent");
|
|
13
|
+
require("../components/defaultToComponent");
|
|
14
|
+
require("../components/enumToComponent");
|
|
15
|
+
require("../components/mapToComponent");
|
|
16
|
+
require("../components/nestedToComponent");
|
|
17
|
+
require("../components/numberToComponent");
|
|
18
|
+
require("../components/objectToEditGrid");
|
|
19
|
+
require("../components/panelToComponent");
|
|
20
|
+
require("../components/propertiesToComponents");
|
|
21
|
+
require("../components/stringToComponent");
|
|
10
22
|
async function getFormioSchema(model, options = {}) {
|
|
11
23
|
if (!model) {
|
|
12
24
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFormioSchema.js","sourceRoot":"","sources":["../../../src/utils/getFormioSchema.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAC1C,yCAA+E;AAE/E,iFAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"getFormioSchema.js","sourceRoot":"","sources":["../../../src/utils/getFormioSchema.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAC1C,yCAA+E;AAE/E,iFAAgE;AAChE,iEAA4D;AAC5D,6CAAsC;AACtC,wCAAsC;AACtC,0CAAwC;AACxC,4CAA0C;AAC1C,yCAAuC;AACvC,4CAA0C;AAC1C,yCAAuC;AACvC,wCAAsC;AACtC,2CAAyC;AACzC,2CAAyC;AACzC,0CAAwC;AACxC,0CAAwC;AACxC,gDAA8C;AAC9C,2CAAyC;AAElC,KAAK,UAAU,eAAe,CACnC,KAA+B,EAC/B,UAA6B,EAAE;IAE/B,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,EAAE;QACnB,OAAO,eAAe,CAAC,+BAAc,CAAC,GAAG,CAAC,KAAK,CAAc,EAAE,OAAO,CAAC,CAAC;KACzE;IAED,MAAM,MAAM,GAAG,wBAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,MAAM,EAAE;QACnC,GAAG,OAAO;QACV,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACrC,MAAM,WAAW,GAAG,IAAA,uBAAS,EAAC,IAAI,CAAC,CAAC;IACpC,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,MAAM,UAAU,GAAG,IAAA,mCAAU,EAAC,YAAY,EAAE,MAAM,EAAE,EAAC,GAAG,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS,EAAC,CAAC,CAAC;IAC9G,MAAM,IAAI,GAAG;QACX,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,EAAE;QACV,gBAAgB,EAAE,EAAE;QACpB,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAM,aAAa,EAAE,EAAE,CAAC;QAC3C,IAAI,EAAE,WAAW;QACjB,WAAW;QACX,UAAU;KACX,CAAC;IAEF,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7E,OAAO,IAA6B,CAAC;AACvC,CAAC;AAtCD,0CAsCC","sourcesContent":["import {isString, Type} from \"@tsed/core\";\nimport {getJsonSchema, JsonEntityStore, JsonSchemaOptions} from \"@tsed/schema\";\nimport {FormioForm} from \"@tsed/formio-types\";\nimport {execMapper} from \"../registries/FormioMappersContainer\";\nimport {FormsContainer} from \"../registries/FormsContainer\";\nimport {paramCase} from \"change-case\";\nimport \"../components/anyToComponent\";\nimport \"../components/arrayToComponent\";\nimport \"../components/booleanToComponent\";\nimport \"../components/dateToComponent\";\nimport \"../components/defaultToComponent\";\nimport \"../components/enumToComponent\";\nimport \"../components/mapToComponent\";\nimport \"../components/nestedToComponent\";\nimport \"../components/numberToComponent\";\nimport \"../components/objectToEditGrid\";\nimport \"../components/panelToComponent\";\nimport \"../components/propertiesToComponents\";\nimport \"../components/stringToComponent\";\n\nexport async function getFormioSchema(\n model: string | any | undefined,\n options: JsonSchemaOptions = {}\n): Promise<Omit<FormioForm, \"_id\" | \"deleted\" | \"owner\"> | undefined> {\n if (!model) {\n return undefined;\n }\n\n if (isString(model)) {\n return getFormioSchema(FormsContainer.get(model) as Type<any>, options);\n }\n\n const entity = JsonEntityStore.from(model);\n const schema = getJsonSchema(entity, {\n ...options,\n customKeys: true\n });\n\n const name = entity.schema.getName();\n const machineName = paramCase(name);\n const resolvers: Promise<any>[] = [];\n const components = execMapper(\"properties\", schema, {...options, definitions: schema.definitions, resolvers});\n const form = {\n title: name,\n type: \"form\",\n display: \"form\",\n tags: [],\n access: [],\n submissionAccess: [],\n ...entity.store.get<any>(\"formio:form\", {}),\n name: machineName,\n machineName,\n components\n };\n\n await Promise.all(resolvers.map((resolver: any) => resolver(form, options)));\n\n return form as unknown as FormioForm;\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
2
|
-
import { getRef } from "../utils/getRef";
|
|
1
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
2
|
+
import { getRef } from "../utils/getRef.js";
|
|
3
3
|
export function anyToComponent(schema, options) {
|
|
4
4
|
schema = getRef(schema, options);
|
|
5
|
-
switch (schema
|
|
5
|
+
switch (schema?.type) {
|
|
6
6
|
case "object":
|
|
7
7
|
if (!schema.properties && !schema.$ref) {
|
|
8
8
|
return execMapper("map", schema, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anyToComponent.js","sourceRoot":"","sources":["../../../src/components/anyToComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,OAAY;IACtD,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"anyToComponent.js","sourceRoot":"","sources":["../../../src/components/anyToComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,OAAY;IACtD,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC,QAAQ,MAAM,EAAE,IAAI,EAAE;QACpB,KAAK,QAAQ;YACX,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;gBACtC,OAAO,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;aAC3C;YAED,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C,KAAK,OAAO;YACV,OAAO,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9C,KAAK,QAAQ;YACX,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C,KAAK,SAAS;YACZ,OAAO,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAChD,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KAChD;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,oBAAoB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC","sourcesContent":["import {execMapper, registerFormioMapper} from \"../registries/FormioMappersContainer\";\nimport {getRef} from \"../utils/getRef\";\n\nexport function anyToComponent(schema: any, options: any) {\n schema = getRef(schema, options);\n\n switch (schema?.type) {\n case \"object\":\n if (!schema.properties && !schema.$ref) {\n return execMapper(\"map\", schema, options);\n }\n\n return execMapper(\"nested\", schema, options);\n case \"array\":\n return execMapper(\"array\", schema, options);\n case \"string\":\n return execMapper(\"string\", schema, options);\n case \"boolean\":\n return execMapper(\"boolean\", schema, options);\n case \"integer\":\n case \"number\":\n return execMapper(\"number\", schema, options);\n }\n\n return {};\n}\n\nregisterFormioMapper(\"any\", anyToComponent);\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cleanObject } from "@tsed/core";
|
|
2
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
3
|
-
import { getRef } from "../utils/getRef";
|
|
2
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
3
|
+
import { getRef } from "../utils/getRef.js";
|
|
4
4
|
export function arrayToComponent(schema, options) {
|
|
5
5
|
const itemSchema = schema.items.$ref ? getRef(schema.items, options) : schema.items;
|
|
6
6
|
const { type } = itemSchema;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanObject } from "@tsed/core";
|
|
2
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
2
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
3
3
|
function booleanToComponent(schema, options) {
|
|
4
4
|
const component = execMapper("default", schema, options);
|
|
5
5
|
return cleanObject({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
1
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
2
2
|
function dateToComponent(schema, options) {
|
|
3
3
|
const component = execMapper("default", schema, options);
|
|
4
4
|
const base = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cleanObject } from "@tsed/core";
|
|
2
|
-
import { registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
3
|
-
import { getFormioProps } from "../utils/getFormioProps";
|
|
2
|
+
import { registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
3
|
+
import { getFormioProps } from "../utils/getFormioProps.js";
|
|
4
4
|
export function defaultToComponent(schema, options) {
|
|
5
5
|
const formioProps = getFormioProps(schema);
|
|
6
6
|
return cleanObject({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanObject } from "@tsed/core";
|
|
2
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
2
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
3
3
|
export function enumToComponent(schema, options) {
|
|
4
4
|
const component = execMapper("default", schema, options);
|
|
5
5
|
const values = schema.enum.map((value) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
1
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
2
2
|
export function mapToComponent(schema, options) {
|
|
3
3
|
return {
|
|
4
4
|
...execMapper("default", schema, options),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sentenceCase } from "change-case";
|
|
2
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
2
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
3
3
|
export function nestedToComponent(schema, options) {
|
|
4
4
|
return {
|
|
5
5
|
...execMapper("default", schema, options),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanObject, getValue } from "@tsed/core";
|
|
2
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
2
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
3
3
|
export function numberToComponent(schema, options) {
|
|
4
4
|
const component = execMapper("default", schema, options);
|
|
5
5
|
return cleanObject({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
1
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
2
2
|
export function objectToEditGrid(schema, options) {
|
|
3
3
|
return {
|
|
4
4
|
...execMapper("default", schema, options),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
1
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
2
2
|
export function panelToComponent(schema, options) {
|
|
3
3
|
return {
|
|
4
4
|
...execMapper("default", schema, options),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { cleanObject, isFunction } from "@tsed/core";
|
|
2
2
|
import { sentenceCase } from "change-case";
|
|
3
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
3
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
4
4
|
function bindResolvers(component, options) {
|
|
5
5
|
if (component.data) {
|
|
6
|
-
const data = component.data;
|
|
6
|
+
const data = { ...component.data };
|
|
7
7
|
Object.entries(data).forEach(([key, resolver]) => {
|
|
8
8
|
if (isFunction(resolver)) {
|
|
9
9
|
options.resolvers.push(async (form) => {
|
|
@@ -11,7 +11,12 @@ function bindResolvers(component, options) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
+
return {
|
|
15
|
+
...component,
|
|
16
|
+
data
|
|
17
|
+
};
|
|
14
18
|
}
|
|
19
|
+
return component;
|
|
15
20
|
}
|
|
16
21
|
function mapValidation(key, base, schema, propSchema) {
|
|
17
22
|
const required = (schema.required || []).includes(key);
|
|
@@ -51,13 +56,13 @@ export function propertiesToComponents(schema, options) {
|
|
|
51
56
|
Object.entries(schema.properties).forEach(([key, propSchema]) => {
|
|
52
57
|
const tabsOptions = propSchema["x-formiotabs"];
|
|
53
58
|
const base = execMapper("any", propSchema, { parentKey: key, ...options });
|
|
54
|
-
|
|
59
|
+
let component = cleanObject({
|
|
55
60
|
key,
|
|
56
61
|
...base,
|
|
57
62
|
label: base.label == false ? undefined : base.label || propSchema.title || sentenceCase(key),
|
|
58
63
|
validate: mapValidation(key, base, schema, propSchema)
|
|
59
64
|
});
|
|
60
|
-
bindResolvers(component, options);
|
|
65
|
+
component = bindResolvers(component, options);
|
|
61
66
|
if (tabsOptions) {
|
|
62
67
|
if (!tabs.pushed) {
|
|
63
68
|
components.push(tabs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertiesToComponents.js","sourceRoot":"","sources":["../../../src/components/propertiesToComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"propertiesToComponents.js","sourceRoot":"","sources":["../../../src/components/propertiesToComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AACzC,OAAO,EAAC,UAAU,EAAE,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAEtF,SAAS,aAAa,CAAC,SAA0B,EAAE,OAAY;IAC7D,IAAI,SAAS,CAAC,IAAI,EAAE;QAClB,MAAM,IAAI,GAAG,EAAC,GAAG,SAAS,CAAC,IAAI,EAAC,CAAC;QAEjC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE;YAC/C,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;gBACxB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAgB,EAAE,EAAE;oBAChD,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,QAAQ,CAAC,EAAC,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;gBAC5D,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,SAAS;YACZ,IAAI;SACL,CAAC;KACH;IAED,OAAO,SAAS,CAAC;A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AAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC5B;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;QACxB,IAAI,CAAC,UAAU,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAQ,CAAC;KACxD;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,oBAAoB,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC","sourcesContent":["import {cleanObject, isFunction} from \"@tsed/core\";\nimport {FormioComponent, FormioForm} from \"@tsed/formio-types\";\nimport {sentenceCase} from \"change-case\";\nimport {execMapper, registerFormioMapper} from \"../registries/FormioMappersContainer\";\n\nfunction bindResolvers(component: FormioComponent, options: any) {\n if (component.data) {\n const data = {...component.data};\n\n Object.entries(data).forEach(([key, resolver]) => {\n if (isFunction(resolver)) {\n options.resolvers.push(async (form: FormioForm) => {\n data[key] = await resolver({...options, component, form});\n });\n }\n });\n\n return {\n ...component,\n data\n };\n }\n\n return component;\n}\n\nfunction mapValidation(key: string, base: FormioComponent, schema: any, propSchema: any) {\n const required = (schema.required || []).includes(key);\n const validate = {\n ...(base.validate || {}),\n required,\n pattern: propSchema.pattern,\n minLength: !required || (required && propSchema.minLength > 1) ? propSchema.minLength : undefined,\n maxLength: propSchema.maxLength,\n min: propSchema.minimum,\n max: propSchema.maximum\n };\n\n switch (propSchema.type) {\n case \"string\":\n if (propSchema.minLength === 0 && validate.required) {\n validate.minLength = undefined;\n validate.required = false;\n }\n break;\n case \"boolean\":\n validate.required = false;\n break;\n }\n\n return cleanObject(validate);\n}\n\nexport function propertiesToComponents(schema: any, options: any): any[] {\n const tabs = {\n label: \"Tabs\",\n key: \"tabs\",\n type: \"tabs\",\n input: false,\n tableView: false,\n components: new Map<string, any>(),\n pushed: false\n };\n const components: any[] = [];\n\n Object.entries(schema.properties).forEach(([key, propSchema]: [string, any]) => {\n const tabsOptions = propSchema[\"x-formiotabs\"];\n const base = execMapper(\"any\", propSchema, {parentKey: key, ...options});\n\n let component = cleanObject({\n key,\n ...base,\n label: base.label == false ? undefined : base.label || propSchema.title || sentenceCase(key),\n validate: mapValidation(key, base, schema, propSchema)\n });\n\n component = bindResolvers(component, options);\n\n if (tabsOptions) {\n if (!tabs.pushed) {\n components.push(tabs);\n tabs.pushed = true;\n }\n\n if (!tabs.components.has(tabsOptions.key)) {\n tabs.components.set(tabsOptions.key, {\n ...tabsOptions,\n components: []\n });\n }\n\n tabs.components.get(tabsOptions.key).components.push(component);\n } else {\n components.push(component);\n }\n });\n\n if (tabs.components.size) {\n tabs.components = [...tabs.components.values()] as any;\n }\n\n return components;\n}\n\nregisterFormioMapper(\"properties\", propertiesToComponents);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanObject } from "@tsed/core";
|
|
2
|
-
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer";
|
|
2
|
+
import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js";
|
|
3
3
|
export function stringToComponent(schema, options) {
|
|
4
4
|
if (schema.format) {
|
|
5
5
|
const component = execMapper("default", schema, options);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Component } from "./component";
|
|
1
|
+
import { Component } from "./component.js";
|
|
2
2
|
import { isArrowFn } from "@tsed/core";
|
|
3
3
|
function sanitize(customConditional) {
|
|
4
4
|
const str = customConditional.toString();
|
|
5
5
|
const [signature, ...fn] = str.split("=>");
|
|
6
6
|
let content = fn.join("=>");
|
|
7
7
|
if (!signature.includes("{")) {
|
|
8
|
-
|
|
9
|
-
content = content.replace(new RegExp(reg, "gi"), "");
|
|
8
|
+
content = content.replace(new RegExp(`${signature.trim()}.`, "gi"), "");
|
|
10
9
|
}
|
|
11
10
|
return `show = ${content.trim()}`;
|
|
12
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customConditional.js","sourceRoot":"","sources":["../../../src/decorators/customConditional.ts"],"names":[],"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iB,CAAC,EAAE;QAChC,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;KACjD;IAED,OAAO,SAAS,CAAC;QACf,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {FormioComponent, FormioForm, FormioSubmission} from \"@tsed/formio-types\";\nimport type {Moment} from \"moment\";\nimport type {LoDashStatic} from \"lodash\";\nimport type {Utils} from \"formiojs\";\nimport {Component} from \"./component\";\nimport {isArrowFn} from \"@tsed/core\";\n\nexport interface CustomConditionalCtx<Value = any, Data = any, Row = any> {\n /**\n * The complete submission object.\n */\n form: FormioForm;\n /**\n * The complete submission object.\n */\n submission: FormioSubmission<Data>;\n /**\n * The complete submission data object.\n */\n data: Data;\n /**\n * Contextual \"row\" data, used within DataGrid, EditGrid, and Container components\n */\n row: Row;\n /**\n * The current component JSON\n */\n component: FormioComponent;\n /**\n * The current component instance.\n */\n instance: any;\n /**\n * The current value of the component.\n */\n value: Value;\n /**\n * The moment.js library for date manipulation.\n */\n moment: Moment;\n /**\n * An instance of Lodash.\n */\n _: LoDashStatic;\n /**\n * An instance of the FormioUtils object.\n */\n utils: typeof Utils;\n /**\n * An alias for \"utils\".\n */\n util: typeof Utils;\n}\n\nfunction sanitize(customConditional: Function) {\n const str = customConditional.toString();\n\n const [signature, ...fn] = str.split(\"=>\");\n let content = fn.join(\"=>\");\n\n if (!signature.includes(\"{\")) {\n content = content.replace(new RegExp(`${signature.trim()}.`, \"gi\"), \"\");\n }\n\n return `show = ${content.trim()}`;\n}\n\n/**\n * Adds custom conditional rule to display or not the input form.\n * @decorator\n * @formio\n * @property\n * @schema\n * @param customConditional\n */\nexport function CustomConditional(customConditional: string | ((ctx: CustomConditionalCtx) => any)) {\n if (isArrowFn(customConditional)) {\n customConditional = sanitize(customConditional);\n }\n\n return Component({\n customConditional\n });\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nameOf, StoreSet, useDecorators } from "@tsed/core";
|
|
2
2
|
import { Name } from "@tsed/schema";
|
|
3
3
|
import { paramCase } from "change-case";
|
|
4
|
-
import { FormsContainer } from "../registries/FormsContainer";
|
|
4
|
+
import { FormsContainer } from "../registries/FormsContainer.js";
|
|
5
5
|
/**
|
|
6
6
|
* Expose the model as Formio Form.
|
|
7
7
|
* @param form
|