@vuu-ui/vuu-data-react 0.13.8 → 0.13.10
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/cjs/data-editing/EditForm.css.js +6 -0
- package/cjs/data-editing/EditForm.css.js.map +1 -0
- package/cjs/data-editing/EditForm.js +90 -0
- package/cjs/data-editing/EditForm.js.map +1 -0
- package/cjs/data-editing/UnsavedChangesReport.css.js +6 -0
- package/cjs/data-editing/UnsavedChangesReport.css.js.map +1 -0
- package/cjs/data-editing/UnsavedChangesReport.js +29 -0
- package/cjs/data-editing/UnsavedChangesReport.js.map +1 -0
- package/cjs/data-editing/edit-rule-validation-checker.js +41 -0
- package/cjs/data-editing/edit-rule-validation-checker.js.map +1 -0
- package/cjs/data-editing/edit-validation-rules.js +52 -0
- package/cjs/data-editing/edit-validation-rules.js.map +1 -0
- package/cjs/data-editing/form-edit-state.js +26 -0
- package/cjs/data-editing/form-edit-state.js.map +1 -0
- package/cjs/data-editing/get-data-item-edit-control.js +56 -0
- package/cjs/data-editing/get-data-item-edit-control.js.map +1 -0
- package/cjs/data-editing/useEditForm.js +249 -0
- package/cjs/data-editing/useEditForm.js.map +1 -0
- package/cjs/datasource-provider/RestDataSourceProvider.js +78 -0
- package/cjs/datasource-provider/RestDataSourceProvider.js.map +1 -0
- package/cjs/datasource-provider/VuuDataSourceProvider.js +34 -0
- package/cjs/datasource-provider/VuuDataSourceProvider.js.map +1 -0
- package/cjs/datasource-provider/useAutoLoginToVuuServer.js +54 -0
- package/cjs/datasource-provider/useAutoLoginToVuuServer.js.map +1 -0
- package/cjs/hooks/useLookupValues.js +100 -0
- package/cjs/hooks/useLookupValues.js.map +1 -0
- package/cjs/hooks/useSessionDataSource.js +72 -0
- package/cjs/hooks/useSessionDataSource.js.map +1 -0
- package/cjs/hooks/useTypeaheadSuggestions.js +41 -0
- package/cjs/hooks/useTypeaheadSuggestions.js.map +1 -0
- package/cjs/hooks/useVisualLinks.js +83 -0
- package/cjs/hooks/useVisualLinks.js.map +1 -0
- package/cjs/hooks/useVuuMenuActions.js +362 -0
- package/cjs/hooks/useVuuMenuActions.js.map +1 -0
- package/cjs/hooks/useVuuTables.js +38 -0
- package/cjs/hooks/useVuuTables.js.map +1 -0
- package/cjs/index.js +40 -1556
- package/cjs/index.js.map +1 -1
- package/cjs/session-editing-form/SessionEditingForm.css.js +6 -0
- package/cjs/session-editing-form/SessionEditingForm.css.js.map +1 -0
- package/cjs/session-editing-form/SessionEditingForm.js +269 -0
- package/cjs/session-editing-form/SessionEditingForm.js.map +1 -0
- package/esm/data-editing/EditForm.css.js +4 -0
- package/esm/data-editing/EditForm.css.js.map +1 -0
- package/esm/data-editing/EditForm.js +88 -0
- package/esm/data-editing/EditForm.js.map +1 -0
- package/esm/data-editing/UnsavedChangesReport.css.js +4 -0
- package/esm/data-editing/UnsavedChangesReport.css.js.map +1 -0
- package/esm/data-editing/UnsavedChangesReport.js +27 -0
- package/esm/data-editing/UnsavedChangesReport.js.map +1 -0
- package/esm/data-editing/edit-rule-validation-checker.js +37 -0
- package/esm/data-editing/edit-rule-validation-checker.js.map +1 -0
- package/esm/data-editing/edit-validation-rules.js +50 -0
- package/esm/data-editing/edit-validation-rules.js.map +1 -0
- package/esm/data-editing/form-edit-state.js +23 -0
- package/esm/data-editing/form-edit-state.js.map +1 -0
- package/esm/data-editing/get-data-item-edit-control.js +54 -0
- package/esm/data-editing/get-data-item-edit-control.js.map +1 -0
- package/esm/data-editing/useEditForm.js +247 -0
- package/esm/data-editing/useEditForm.js.map +1 -0
- package/esm/datasource-provider/RestDataSourceProvider.js +75 -0
- package/esm/datasource-provider/RestDataSourceProvider.js.map +1 -0
- package/esm/datasource-provider/VuuDataSourceProvider.js +32 -0
- package/esm/datasource-provider/VuuDataSourceProvider.js.map +1 -0
- package/esm/datasource-provider/useAutoLoginToVuuServer.js +52 -0
- package/esm/datasource-provider/useAutoLoginToVuuServer.js.map +1 -0
- package/esm/hooks/useLookupValues.js +98 -0
- package/esm/hooks/useLookupValues.js.map +1 -0
- package/esm/hooks/useSessionDataSource.js +70 -0
- package/esm/hooks/useSessionDataSource.js.map +1 -0
- package/esm/hooks/useTypeaheadSuggestions.js +38 -0
- package/esm/hooks/useTypeaheadSuggestions.js.map +1 -0
- package/esm/hooks/useVisualLinks.js +81 -0
- package/esm/hooks/useVisualLinks.js.map +1 -0
- package/esm/hooks/useVuuMenuActions.js +358 -0
- package/esm/hooks/useVuuMenuActions.js.map +1 -0
- package/esm/hooks/useVuuTables.js +36 -0
- package/esm/hooks/useVuuTables.js.map +1 -0
- package/esm/index.js +15 -1535
- package/esm/index.js.map +1 -1
- package/esm/session-editing-form/SessionEditingForm.css.js +4 -0
- package/esm/session-editing-form/SessionEditingForm.css.js.map +1 -0
- package/esm/session-editing-form/SessionEditingForm.js +267 -0
- package/esm/session-editing-form/SessionEditingForm.js.map +1 -0
- package/package.json +14 -14
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var editFormCss = ".EditForm {\n display: flex;\n flex-direction: column;\n gap: var(--salt-spacing-400);\n height: 100%;\n padding: var(--salt-spacing-200) var(--salt-spacing-200)\n var(--salt-spacing-200) var(--salt-spacing-400);\n width: 100%;\n}\n\n.EditForm-form-fields {\n display: flex;\n flex-direction: column;\n gap: var(--salt-spacing-400);\n}\n\n.EditForm-buttons {\n align-items: center;\n display: flex;\n gap: var(--salt-spacing-200);\n justify-content: flex-end;\n}\n\n.EditForm-field {\n display: flex;\n\n .saltFormField {\n flex: 1 1 auto;\n }\n\n .EditForm-edit-indicator {\n flex: 0 0 14px;\n position: relative;\n }\n\n &[data-edited=\"true\"] {\n .EditForm-edit-indicator:after {\n background-color: var(--salt-content-secondary-foreground);\n border-radius: 5px;\n content: \"\";\n height: 10px;\n position: absolute;\n top: 50%;\n right: -3px;\n width: 10px;\n }\n }\n}\n";
|
|
4
|
+
|
|
5
|
+
module.exports = editFormCss;
|
|
6
|
+
//# sourceMappingURL=EditForm.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditForm.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var core = require('@salt-ds/core');
|
|
5
|
+
var styles = require('@salt-ds/styles');
|
|
6
|
+
var window = require('@salt-ds/window');
|
|
7
|
+
var cx = require('clsx');
|
|
8
|
+
var editValidationRules = require('./edit-validation-rules.js');
|
|
9
|
+
var useEditForm = require('./useEditForm.js');
|
|
10
|
+
var EditForm$1 = require('./EditForm.css.js');
|
|
11
|
+
var getDataItemEditControl = require('./get-data-item-edit-control.js');
|
|
12
|
+
|
|
13
|
+
const classBase = "EditForm";
|
|
14
|
+
editValidationRules.registerRules();
|
|
15
|
+
const EditForm = ({
|
|
16
|
+
className,
|
|
17
|
+
dataSource,
|
|
18
|
+
formFieldDescriptors,
|
|
19
|
+
onSubmit: onSubmitProp,
|
|
20
|
+
...htmlAttributes
|
|
21
|
+
}) => {
|
|
22
|
+
const targetWindow = window.useWindow();
|
|
23
|
+
styles.useComponentCssInjection({
|
|
24
|
+
testId: "vuu-edit-form",
|
|
25
|
+
css: EditForm$1,
|
|
26
|
+
window: targetWindow
|
|
27
|
+
});
|
|
28
|
+
const {
|
|
29
|
+
editedFields,
|
|
30
|
+
editEntity,
|
|
31
|
+
errorMessages,
|
|
32
|
+
formFieldsContainerRef,
|
|
33
|
+
isClean,
|
|
34
|
+
ok,
|
|
35
|
+
onCancel,
|
|
36
|
+
onChange,
|
|
37
|
+
onCommit,
|
|
38
|
+
onFocus,
|
|
39
|
+
onSubmit
|
|
40
|
+
} = useEditForm.useEditForm({
|
|
41
|
+
dataSource,
|
|
42
|
+
formFieldDescriptors,
|
|
43
|
+
onSubmit: onSubmitProp
|
|
44
|
+
});
|
|
45
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
46
|
+
"div",
|
|
47
|
+
{
|
|
48
|
+
...htmlAttributes,
|
|
49
|
+
className: cx(classBase, className),
|
|
50
|
+
onFocus,
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `${classBase}-form-fields`, ref: formFieldsContainerRef, children: formFieldDescriptors.map((dataDescriptor) => {
|
|
53
|
+
const { name, label = name } = dataDescriptor;
|
|
54
|
+
const errorMessage = errorMessages[name];
|
|
55
|
+
const isEdited = !isClean && editedFields.includes(name);
|
|
56
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
57
|
+
"div",
|
|
58
|
+
{
|
|
59
|
+
className: `${classBase}-field`,
|
|
60
|
+
"data-edited": isEdited,
|
|
61
|
+
children: [
|
|
62
|
+
/* @__PURE__ */ jsxRuntime.jsxs(core.FormField, { "data-field": name, children: [
|
|
63
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.FormFieldLabel, { children: label }),
|
|
64
|
+
getDataItemEditControl.getDataItemEditControl({
|
|
65
|
+
InputProps: {
|
|
66
|
+
onChange,
|
|
67
|
+
value: editEntity?.[name]?.toString() ?? ""
|
|
68
|
+
},
|
|
69
|
+
dataDescriptor,
|
|
70
|
+
errorMessage,
|
|
71
|
+
onCommit
|
|
72
|
+
})
|
|
73
|
+
] }),
|
|
74
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `${classBase}-edit-indicator` })
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
name
|
|
78
|
+
);
|
|
79
|
+
}) }),
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${classBase}-buttons`, children: [
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Button, { disabled: isClean, onClick: onCancel, children: "Cancel" }),
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Button, { onClick: onSubmit, disabled: !ok || isClean, children: "Save" })
|
|
83
|
+
] })
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
exports.EditForm = EditForm;
|
|
90
|
+
//# sourceMappingURL=EditForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditForm.js","sources":["../../src/data-editing/EditForm.tsx"],"sourcesContent":["import { Button, FormField, FormFieldLabel } from \"@salt-ds/core\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport cx from \"clsx\";\nimport { HTMLAttributes } from \"react\";\nimport { registerRules } from \"./edit-validation-rules\";\nimport { EditFormHookProps, useEditForm } from \"./useEditForm\";\n\nimport editFormCss from \"./EditForm.css\";\nimport { getDataItemEditControl } from \"./get-data-item-edit-control\";\n\nconst classBase = \"EditForm\";\n\nregisterRules();\n\nexport interface EditFormProps\n extends EditFormHookProps,\n Omit<HTMLAttributes<HTMLDivElement>, \"onSubmit\"> {}\n\nexport const EditForm = ({\n className,\n dataSource,\n formFieldDescriptors,\n onSubmit: onSubmitProp,\n ...htmlAttributes\n}: EditFormProps) => {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"vuu-edit-form\",\n css: editFormCss,\n window: targetWindow,\n });\n\n const {\n editedFields,\n editEntity,\n errorMessages,\n formFieldsContainerRef,\n isClean,\n ok,\n onCancel,\n onChange,\n onCommit,\n onFocus,\n onSubmit,\n } = useEditForm({\n dataSource,\n formFieldDescriptors,\n onSubmit: onSubmitProp,\n });\n\n return (\n <div\n {...htmlAttributes}\n className={cx(classBase, className)}\n onFocus={onFocus}\n >\n <div className={`${classBase}-form-fields`} ref={formFieldsContainerRef}>\n {formFieldDescriptors.map((dataDescriptor) => {\n const { name, label = name } = dataDescriptor;\n const errorMessage = errorMessages[name];\n const isEdited = !isClean && editedFields.includes(name);\n\n return (\n <div\n className={`${classBase}-field`}\n key={name}\n data-edited={isEdited}\n >\n <FormField data-field={name}>\n <FormFieldLabel>{label}</FormFieldLabel>\n {getDataItemEditControl({\n InputProps: {\n onChange,\n value: editEntity?.[name]?.toString() ?? \"\",\n },\n dataDescriptor,\n errorMessage,\n onCommit,\n })}\n </FormField>\n <div className={`${classBase}-edit-indicator`} />\n </div>\n );\n })}\n </div>\n <div className={`${classBase}-buttons`}>\n <Button disabled={isClean} onClick={onCancel}>\n Cancel\n </Button>\n <Button onClick={onSubmit} disabled={!ok || isClean}>\n Save\n </Button>\n </div>\n </div>\n );\n};\n"],"names":["registerRules","useWindow","useComponentCssInjection","editFormCss","useEditForm","jsxs","jsx","FormField","FormFieldLabel","getDataItemEditControl","Button"],"mappings":";;;;;;;;;;;;AAWA,MAAM,SAAY,GAAA,UAAA;AAElBA,iCAAc,EAAA;AAMP,MAAM,WAAW,CAAC;AAAA,EACvB,SAAA;AAAA,EACA,UAAA;AAAA,EACA,oBAAA;AAAA,EACA,QAAU,EAAA,YAAA;AAAA,EACV,GAAG;AACL,CAAqB,KAAA;AACnB,EAAA,MAAM,eAAeC,gBAAU,EAAA;AAC/B,EAAyBC,+BAAA,CAAA;AAAA,IACvB,MAAQ,EAAA,eAAA;AAAA,IACR,GAAK,EAAAC,UAAA;AAAA,IACL,MAAQ,EAAA;AAAA,GACT,CAAA;AAED,EAAM,MAAA;AAAA,IACJ,YAAA;AAAA,IACA,UAAA;AAAA,IACA,aAAA;AAAA,IACA,sBAAA;AAAA,IACA,OAAA;AAAA,IACA,EAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,MACEC,uBAAY,CAAA;AAAA,IACd,UAAA;AAAA,IACA,oBAAA;AAAA,IACA,QAAU,EAAA;AAAA,GACX,CAAA;AAED,EACE,uBAAAC,eAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACE,GAAG,cAAA;AAAA,MACJ,SAAA,EAAW,EAAG,CAAA,SAAA,EAAW,SAAS,CAAA;AAAA,MAClC,OAAA;AAAA,MAEA,QAAA,EAAA;AAAA,wBAACC,cAAA,CAAA,KAAA,EAAA,EAAI,SAAW,EAAA,CAAA,EAAG,SAAS,CAAA,YAAA,CAAA,EAAgB,KAAK,sBAC9C,EAAA,QAAA,EAAA,oBAAA,CAAqB,GAAI,CAAA,CAAC,cAAmB,KAAA;AAC5C,UAAA,MAAM,EAAE,IAAA,EAAM,KAAQ,GAAA,IAAA,EAAS,GAAA,cAAA;AAC/B,UAAM,MAAA,YAAA,GAAe,cAAc,IAAI,CAAA;AACvC,UAAA,MAAM,QAAW,GAAA,CAAC,OAAW,IAAA,YAAA,CAAa,SAAS,IAAI,CAAA;AAEvD,UACE,uBAAAD,eAAA;AAAA,YAAC,KAAA;AAAA,YAAA;AAAA,cACC,SAAA,EAAW,GAAG,SAAS,CAAA,MAAA,CAAA;AAAA,cAEvB,aAAa,EAAA,QAAA;AAAA,cAEb,QAAA,EAAA;AAAA,gCAACA,eAAA,CAAAE,cAAA,EAAA,EAAU,cAAY,IACrB,EAAA,QAAA,EAAA;AAAA,kCAAAD,cAAA,CAACE,uBAAgB,QAAM,EAAA,KAAA,EAAA,CAAA;AAAA,kBACtBC,6CAAuB,CAAA;AAAA,oBACtB,UAAY,EAAA;AAAA,sBACV,QAAA;AAAA,sBACA,KAAO,EAAA,UAAA,GAAa,IAAI,CAAA,EAAG,UAAc,IAAA;AAAA,qBAC3C;AAAA,oBACA,cAAA;AAAA,oBACA,YAAA;AAAA,oBACA;AAAA,mBACD;AAAA,iBACH,EAAA,CAAA;AAAA,gCACCH,cAAA,CAAA,KAAA,EAAA,EAAI,SAAW,EAAA,CAAA,EAAG,SAAS,CAAmB,eAAA,CAAA,EAAA;AAAA;AAAA,aAAA;AAAA,YAf1C;AAAA,WAgBP;AAAA,SAEH,CACH,EAAA,CAAA;AAAA,wBACCD,eAAA,CAAA,KAAA,EAAA,EAAI,SAAW,EAAA,CAAA,EAAG,SAAS,CAC1B,QAAA,CAAA,EAAA,QAAA,EAAA;AAAA,0BAAAC,cAAA,CAACI,WAAO,EAAA,EAAA,QAAA,EAAU,OAAS,EAAA,OAAA,EAAS,UAAU,QAE9C,EAAA,QAAA,EAAA,CAAA;AAAA,0BACAJ,cAAA,CAACI,eAAO,OAAS,EAAA,QAAA,EAAU,UAAU,CAAC,EAAA,IAAM,SAAS,QAErD,EAAA,MAAA,EAAA;AAAA,SACF,EAAA;AAAA;AAAA;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var unsavedChangesCss = ".vuuUnsavedChanges-table {\n border-collapse: collapse;\n width: 100%;\n}\n\n.vuuUnsavedChanges-row {\n box-sizing: content-box;\n border-bottom: solid 1px var(--salt-separable-secondary-borderColor);\n height: 32px;\n\n td {\n padding: 0 var(--salt-spacing-200);\n }\n}\n\n.vuuUnsavedChanges-fieldName {\n text-transform: capitalize;\n}\n\n.vuuUnsavedChanges-new {\n font-weight: bold;\n}\n";
|
|
4
|
+
|
|
5
|
+
module.exports = unsavedChangesCss;
|
|
6
|
+
//# sourceMappingURL=UnsavedChangesReport.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnsavedChangesReport.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var styles = require('@salt-ds/styles');
|
|
5
|
+
var window = require('@salt-ds/window');
|
|
6
|
+
var formEditState = require('./form-edit-state.js');
|
|
7
|
+
var UnsavedChangesReport$1 = require('./UnsavedChangesReport.css.js');
|
|
8
|
+
|
|
9
|
+
const classBase = "vuuUnsavedChanges";
|
|
10
|
+
const UnsavedChangesReport = ({
|
|
11
|
+
entity,
|
|
12
|
+
editedEntity
|
|
13
|
+
}) => {
|
|
14
|
+
const targetWindow = window.useWindow();
|
|
15
|
+
styles.useComponentCssInjection({
|
|
16
|
+
testId: "vuu-unsaved-changes-report",
|
|
17
|
+
css: UnsavedChangesReport$1,
|
|
18
|
+
window: targetWindow
|
|
19
|
+
});
|
|
20
|
+
const { editedFields } = formEditState.buildFormEditState(entity, editedEntity);
|
|
21
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classBase, children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: `${classBase}-table`, children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: editedFields.map((fieldName, i) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: `${classBase}-row`, children: [
|
|
22
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { className: `${classBase}-fieldName`, children: fieldName }),
|
|
23
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { className: `${classBase}-old`, children: entity[fieldName] }),
|
|
24
|
+
/* @__PURE__ */ jsxRuntime.jsx("td", { className: `${classBase}-new`, children: editedEntity[fieldName] })
|
|
25
|
+
] }, i)) }) }) });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.UnsavedChangesReport = UnsavedChangesReport;
|
|
29
|
+
//# sourceMappingURL=UnsavedChangesReport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnsavedChangesReport.js","sources":["../../src/data-editing/UnsavedChangesReport.tsx"],"sourcesContent":["import { Entity } from \"@vuu-ui/vuu-utils\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { buildFormEditState } from \"./form-edit-state\";\n\nimport unsavedChangesCss from \"./UnsavedChangesReport.css\";\n\nconst classBase = \"vuuUnsavedChanges\";\n\nexport interface UnsavedChangesReportProps<T extends Entity = Entity> {\n entity: T;\n editedEntity: T;\n}\n\nexport const UnsavedChangesReport = ({\n entity,\n editedEntity,\n}: UnsavedChangesReportProps) => {\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"vuu-unsaved-changes-report\",\n css: unsavedChangesCss,\n window: targetWindow,\n });\n\n const { editedFields } = buildFormEditState(entity, editedEntity);\n\n return (\n <div className={classBase}>\n <table className={`${classBase}-table`}>\n <tbody>\n {editedFields.map((fieldName, i) => (\n <tr className={`${classBase}-row`} key={i}>\n <td className={`${classBase}-fieldName`}>{fieldName}</td>\n <td className={`${classBase}-old`}>{entity[fieldName]}</td>\n <td className={`${classBase}-new`}>{editedEntity[fieldName]}</td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n};\n"],"names":["useWindow","useComponentCssInjection","unsavedChangesCss","buildFormEditState","jsx"],"mappings":";;;;;;;;AAOA,MAAM,SAAY,GAAA,mBAAA;AAOX,MAAM,uBAAuB,CAAC;AAAA,EACnC,MAAA;AAAA,EACA;AACF,CAAiC,KAAA;AAC/B,EAAA,MAAM,eAAeA,gBAAU,EAAA;AAC/B,EAAyBC,+BAAA,CAAA;AAAA,IACvB,MAAQ,EAAA,4BAAA;AAAA,IACR,GAAK,EAAAC,sBAAA;AAAA,IACL,MAAQ,EAAA;AAAA,GACT,CAAA;AAED,EAAA,MAAM,EAAE,YAAA,EAAiB,GAAAC,gCAAA,CAAmB,QAAQ,YAAY,CAAA;AAEhE,EACE,uBAAAC,cAAA,CAAC,SAAI,SAAW,EAAA,SAAA,EACd,yCAAC,OAAM,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,CAC5B,MAAA,CAAA,EAAA,QAAA,kBAAAA,cAAA,CAAC,WACE,QAAa,EAAA,YAAA,CAAA,GAAA,CAAI,CAAC,SAAW,EAAA,CAAA,qCAC3B,IAAG,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,CACzB,IAAA,CAAA,EAAA,QAAA,EAAA;AAAA,oBAAAA,cAAA,CAAC,IAAG,EAAA,EAAA,SAAA,EAAW,CAAG,EAAA,SAAS,cAAe,QAAU,EAAA,SAAA,EAAA,CAAA;AAAA,oBACpDA,cAAA,CAAC,QAAG,SAAW,EAAA,CAAA,EAAG,SAAS,CAAS,IAAA,CAAA,EAAA,QAAA,EAAA,MAAA,CAAO,SAAS,CAAE,EAAA,CAAA;AAAA,oBACtDA,cAAA,CAAC,QAAG,SAAW,EAAA,CAAA,EAAG,SAAS,CAAS,IAAA,CAAA,EAAA,QAAA,EAAA,YAAA,CAAa,SAAS,CAAE,EAAA;AAAA,GAAA,EAAA,EAHtB,CAIxC,CACD,CACH,EAAA,CAAA,EACF,CACF,EAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vuuUtils = require('@vuu-ui/vuu-utils');
|
|
4
|
+
|
|
5
|
+
const OK = { ok: true };
|
|
6
|
+
const NO_VALIDATION_RULES = [];
|
|
7
|
+
function getEditValidationRules(descriptor, editPhase) {
|
|
8
|
+
if (vuuUtils.isTypeDescriptor(descriptor.type)) {
|
|
9
|
+
return editPhase === "*" ? descriptor.type.rules ?? [] : descriptor.type.rules?.filter(
|
|
10
|
+
({ phase: a = "commit" }) => a === editPhase
|
|
11
|
+
) ?? NO_VALIDATION_RULES;
|
|
12
|
+
}
|
|
13
|
+
return NO_VALIDATION_RULES;
|
|
14
|
+
}
|
|
15
|
+
const buildValidationChecker = (rules) => (value, editPhase) => applyRules(rules, value, editPhase);
|
|
16
|
+
function applyRules(rules, value, editPhase = "commit") {
|
|
17
|
+
const result = { ok: true };
|
|
18
|
+
for (const rule of rules) {
|
|
19
|
+
const { phase = "commit" } = rule;
|
|
20
|
+
if (editPhase === "*" || phase === editPhase) {
|
|
21
|
+
const applyRuleToValue = vuuUtils.getEditRuleValidator(rule.name);
|
|
22
|
+
if (applyRuleToValue) {
|
|
23
|
+
const res = applyRuleToValue(rule, value);
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
result.ok = false;
|
|
26
|
+
(result.messages ?? (result.messages = [])).push(res.message);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
throw Error(
|
|
30
|
+
`editable-utils applyRules, no validator registered for rule '${rule.name}'`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.OK = OK;
|
|
39
|
+
exports.buildValidationChecker = buildValidationChecker;
|
|
40
|
+
exports.getEditValidationRules = getEditValidationRules;
|
|
41
|
+
//# sourceMappingURL=edit-rule-validation-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-rule-validation-checker.js","sources":["../../src/data-editing/edit-rule-validation-checker.ts"],"sourcesContent":["import type {\n DataValueDescriptor,\n DataValueValidationChecker,\n DataValueValidationResult,\n EditPhase,\n EditRuleValidationSuccessResult,\n EditValidationRule,\n} from \"@vuu-ui/vuu-data-types\";\nimport type { VuuRowDataItemType } from \"@vuu-ui/vuu-protocol-types\";\nimport { getEditRuleValidator, isTypeDescriptor } from \"@vuu-ui/vuu-utils\";\n\nexport const OK: EditRuleValidationSuccessResult = { ok: true };\n\nconst NO_VALIDATION_RULES: EditValidationRule[] = [] as const;\n\nexport function getEditValidationRules(\n descriptor: DataValueDescriptor,\n editPhase: EditPhase | \"*\",\n) {\n if (isTypeDescriptor(descriptor.type)) {\n return editPhase === \"*\"\n ? (descriptor.type.rules ?? [])\n : (descriptor.type.rules?.filter(\n ({ phase: a = \"commit\" }) => a === editPhase,\n ) ?? NO_VALIDATION_RULES);\n }\n\n return NO_VALIDATION_RULES;\n}\n\nexport const buildValidationChecker =\n (rules: EditValidationRule[]): DataValueValidationChecker =>\n (value: VuuRowDataItemType | undefined, editPhase: EditPhase | \"*\") =>\n applyRules(rules, value, editPhase);\n\nfunction applyRules(\n rules: EditValidationRule[],\n value?: VuuRowDataItemType,\n editPhase: EditPhase | \"*\" = \"commit\",\n) {\n const result: { ok: boolean; messages?: string[] } = { ok: true };\n for (const rule of rules) {\n const { phase = \"commit\" } = rule;\n if (editPhase === \"*\" || phase === editPhase) {\n const applyRuleToValue = getEditRuleValidator(rule.name);\n if (applyRuleToValue) {\n const res = applyRuleToValue(rule, value);\n if (!res.ok) {\n result.ok = false;\n (result.messages ?? (result.messages = [])).push(res.message);\n }\n } else {\n throw Error(\n `editable-utils applyRules, no validator registered for rule '${rule.name}'`,\n );\n }\n }\n }\n return result as DataValueValidationResult;\n}\n"],"names":["isTypeDescriptor","getEditRuleValidator"],"mappings":";;;;AAWa,MAAA,EAAA,GAAsC,EAAE,EAAA,EAAI,IAAK;AAE9D,MAAM,sBAA4C,EAAC;AAEnC,SAAA,sBAAA,CACd,YACA,SACA,EAAA;AACA,EAAI,IAAAA,yBAAA,CAAiB,UAAW,CAAA,IAAI,CAAG,EAAA;AACrC,IAAO,OAAA,SAAA,KAAc,MAChB,UAAW,CAAA,IAAA,CAAK,SAAS,EAAC,GAC1B,UAAW,CAAA,IAAA,CAAK,KAAO,EAAA,MAAA;AAAA,MACtB,CAAC,EAAE,KAAA,EAAO,CAAI,GAAA,QAAA,OAAe,CAAM,KAAA;AAAA,KAChC,IAAA,mBAAA;AAAA;AAGX,EAAO,OAAA,mBAAA;AACT;AAEa,MAAA,sBAAA,GACX,CAAC,KACD,KAAA,CAAC,OAAuC,SACtC,KAAA,UAAA,CAAW,KAAO,EAAA,KAAA,EAAO,SAAS;AAEtC,SAAS,UACP,CAAA,KAAA,EACA,KACA,EAAA,SAAA,GAA6B,QAC7B,EAAA;AACA,EAAM,MAAA,MAAA,GAA+C,EAAE,EAAA,EAAI,IAAK,EAAA;AAChE,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAM,MAAA,EAAE,KAAQ,GAAA,QAAA,EAAa,GAAA,IAAA;AAC7B,IAAI,IAAA,SAAA,KAAc,GAAO,IAAA,KAAA,KAAU,SAAW,EAAA;AAC5C,MAAM,MAAA,gBAAA,GAAmBC,6BAAqB,CAAA,IAAA,CAAK,IAAI,CAAA;AACvD,MAAA,IAAI,gBAAkB,EAAA;AACpB,QAAM,MAAA,GAAA,GAAM,gBAAiB,CAAA,IAAA,EAAM,KAAK,CAAA;AACxC,QAAI,IAAA,CAAC,IAAI,EAAI,EAAA;AACX,UAAA,MAAA,CAAO,EAAK,GAAA,KAAA;AACZ,UAAC,CAAA,MAAA,CAAO,aAAa,MAAO,CAAA,QAAA,GAAW,EAAK,CAAA,EAAA,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA;AAC9D,OACK,MAAA;AACL,QAAM,MAAA,KAAA;AAAA,UACJ,CAAA,6DAAA,EAAgE,KAAK,IAAI,CAAA,CAAA;AAAA,SAC3E;AAAA;AACF;AACF;AAEF,EAAO,OAAA,MAAA;AACT;;;;;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vuuUtils = require('@vuu-ui/vuu-utils');
|
|
4
|
+
var editRuleValidationChecker = require('./edit-rule-validation-checker.js');
|
|
5
|
+
|
|
6
|
+
const isString = (value) => typeof value === "string";
|
|
7
|
+
const NUMERIC = /^(?:[0-9]|\.)+$/;
|
|
8
|
+
const CharValidatorNumeric = (rule, value) => {
|
|
9
|
+
if (isString(value)) {
|
|
10
|
+
if (value.trim() === "") {
|
|
11
|
+
return editRuleValidationChecker.OK;
|
|
12
|
+
} else if (value.match(NUMERIC)) {
|
|
13
|
+
return editRuleValidationChecker.OK;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return { ok: false, message: "only numeric characters are permitted" };
|
|
17
|
+
};
|
|
18
|
+
const ValueValidatorInteger = (rule, value) => {
|
|
19
|
+
if (isString(value)) {
|
|
20
|
+
if (value.trim() === "") {
|
|
21
|
+
return editRuleValidationChecker.OK;
|
|
22
|
+
} else {
|
|
23
|
+
if (!value.match(NUMERIC)) {
|
|
24
|
+
return {
|
|
25
|
+
ok: false,
|
|
26
|
+
message: "value must be an integer, invalid character"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (parseFloat(value) === parseInt(value)) {
|
|
30
|
+
return editRuleValidationChecker.OK;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { ok: false, message: "must be an integer value" };
|
|
35
|
+
};
|
|
36
|
+
const registerRules = () => {
|
|
37
|
+
vuuUtils.registerComponent(
|
|
38
|
+
"char-numeric",
|
|
39
|
+
CharValidatorNumeric,
|
|
40
|
+
"data-edit-validator",
|
|
41
|
+
{}
|
|
42
|
+
);
|
|
43
|
+
vuuUtils.registerComponent(
|
|
44
|
+
"value-integer",
|
|
45
|
+
ValueValidatorInteger,
|
|
46
|
+
"data-edit-validator",
|
|
47
|
+
{}
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.registerRules = registerRules;
|
|
52
|
+
//# sourceMappingURL=edit-validation-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-validation-rules.js","sources":["../../src/data-editing/edit-validation-rules.ts"],"sourcesContent":["import type { EditRuleValidator } from \"@vuu-ui/vuu-data-types\";\nimport type { VuuRowDataItemType } from \"@vuu-ui/vuu-protocol-types\";\nimport { registerComponent } from \"@vuu-ui/vuu-utils\";\nimport { OK } from \"./edit-rule-validation-checker\";\n\nconst isString = (value?: VuuRowDataItemType): value is string =>\n typeof value === \"string\";\n\nconst NUMERIC = /^(?:[0-9]|\\.)+$/;\n\nconst CharValidatorNumeric: EditRuleValidator = (rule, value) => {\n if (isString(value)) {\n if (value.trim() === \"\") {\n return OK;\n } else if (value.match(NUMERIC)) {\n return OK;\n }\n }\n return { ok: false, message: \"only numeric characters are permitted\" };\n};\n\nconst ValueValidatorInteger: EditRuleValidator = (rule, value) => {\n if (isString(value)) {\n if (value.trim() === \"\") {\n return OK;\n } else {\n if (!value.match(NUMERIC)) {\n return {\n ok: false,\n message: \"value must be an integer, invalid character\",\n };\n }\n if (parseFloat(value) === parseInt(value)) {\n return OK;\n }\n }\n }\n return { ok: false, message: \"must be an integer value\" };\n};\n\nexport const registerRules = () => {\n registerComponent(\n \"char-numeric\",\n CharValidatorNumeric,\n \"data-edit-validator\",\n {},\n );\n registerComponent(\n \"value-integer\",\n ValueValidatorInteger,\n \"data-edit-validator\",\n {},\n );\n};\n"],"names":["OK","registerComponent"],"mappings":";;;;;AAKA,MAAM,QAAW,GAAA,CAAC,KAChB,KAAA,OAAO,KAAU,KAAA,QAAA;AAEnB,MAAM,OAAU,GAAA,iBAAA;AAEhB,MAAM,oBAAA,GAA0C,CAAC,IAAA,EAAM,KAAU,KAAA;AAC/D,EAAI,IAAA,QAAA,CAAS,KAAK,CAAG,EAAA;AACnB,IAAI,IAAA,KAAA,CAAM,IAAK,EAAA,KAAM,EAAI,EAAA;AACvB,MAAO,OAAAA,4BAAA;AAAA,KACE,MAAA,IAAA,KAAA,CAAM,KAAM,CAAA,OAAO,CAAG,EAAA;AAC/B,MAAO,OAAAA,4BAAA;AAAA;AACT;AAEF,EAAA,OAAO,EAAE,EAAA,EAAI,KAAO,EAAA,OAAA,EAAS,uCAAwC,EAAA;AACvE,CAAA;AAEA,MAAM,qBAAA,GAA2C,CAAC,IAAA,EAAM,KAAU,KAAA;AAChE,EAAI,IAAA,QAAA,CAAS,KAAK,CAAG,EAAA;AACnB,IAAI,IAAA,KAAA,CAAM,IAAK,EAAA,KAAM,EAAI,EAAA;AACvB,MAAO,OAAAA,4BAAA;AAAA,KACF,MAAA;AACL,MAAA,IAAI,CAAC,KAAA,CAAM,KAAM,CAAA,OAAO,CAAG,EAAA;AACzB,QAAO,OAAA;AAAA,UACL,EAAI,EAAA,KAAA;AAAA,UACJ,OAAS,EAAA;AAAA,SACX;AAAA;AAEF,MAAA,IAAI,UAAW,CAAA,KAAK,CAAM,KAAA,QAAA,CAAS,KAAK,CAAG,EAAA;AACzC,QAAO,OAAAA,4BAAA;AAAA;AACT;AACF;AAEF,EAAA,OAAO,EAAE,EAAA,EAAI,KAAO,EAAA,OAAA,EAAS,0BAA2B,EAAA;AAC1D,CAAA;AAEO,MAAM,gBAAgB,MAAM;AACjC,EAAAC,0BAAA;AAAA,IACE,cAAA;AAAA,IACA,oBAAA;AAAA,IACA,qBAAA;AAAA,IACA;AAAC,GACH;AACA,EAAAA,0BAAA;AAAA,IACE,eAAA;AAAA,IACA,qBAAA;AAAA,IACA,qBAAA;AAAA,IACA;AAAC,GACH;AACF;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const CLEAN_FORM = {
|
|
4
|
+
isClean: true,
|
|
5
|
+
editedFields: []
|
|
6
|
+
};
|
|
7
|
+
const buildFormEditState = (entity, newEntity) => {
|
|
8
|
+
if (entity === void 0) {
|
|
9
|
+
return CLEAN_FORM;
|
|
10
|
+
} else {
|
|
11
|
+
const editedFields = [];
|
|
12
|
+
for (const [fieldName, value] of Object.entries(entity)) {
|
|
13
|
+
if (value !== newEntity[fieldName]) {
|
|
14
|
+
editedFields.push(fieldName);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
isClean: editedFields.length === 0,
|
|
19
|
+
editedFields
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.CLEAN_FORM = CLEAN_FORM;
|
|
25
|
+
exports.buildFormEditState = buildFormEditState;
|
|
26
|
+
//# sourceMappingURL=form-edit-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-edit-state.js","sources":["../../src/data-editing/form-edit-state.ts"],"sourcesContent":["import { Entity } from \"@vuu-ui/vuu-utils\";\n\nexport type FormEditState = {\n isClean: boolean;\n editedFields: string[];\n};\n\nexport const CLEAN_FORM: FormEditState = {\n isClean: true,\n editedFields: [],\n};\n\nexport const buildFormEditState = (\n entity: Entity | undefined,\n newEntity: Entity,\n): FormEditState => {\n if (entity === undefined) {\n return CLEAN_FORM;\n } else {\n const editedFields: string[] = [];\n for (const [fieldName, value] of Object.entries(entity)) {\n if (value !== newEntity[fieldName]) {\n editedFields.push(fieldName);\n }\n }\n\n return {\n isClean: editedFields.length === 0,\n editedFields,\n };\n }\n};\n"],"names":[],"mappings":";;AAOO,MAAM,UAA4B,GAAA;AAAA,EACvC,OAAS,EAAA,IAAA;AAAA,EACT,cAAc;AAChB;AAEa,MAAA,kBAAA,GAAqB,CAChC,MAAA,EACA,SACkB,KAAA;AAClB,EAAA,IAAI,WAAW,KAAW,CAAA,EAAA;AACxB,IAAO,OAAA,UAAA;AAAA,GACF,MAAA;AACL,IAAA,MAAM,eAAyB,EAAC;AAChC,IAAA,KAAA,MAAW,CAAC,SAAW,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,MAAM,CAAG,EAAA;AACvD,MAAI,IAAA,KAAA,KAAU,SAAU,CAAA,SAAS,CAAG,EAAA;AAClC,QAAA,YAAA,CAAa,KAAK,SAAS,CAAA;AAAA;AAC7B;AAGF,IAAO,OAAA;AAAA,MACL,OAAA,EAAS,aAAa,MAAW,KAAA,CAAA;AAAA,MACjC;AAAA,KACF;AAAA;AAEJ;;;;;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var vuuUiControls = require('@vuu-ui/vuu-ui-controls');
|
|
5
|
+
var vuuUtils = require('@vuu-ui/vuu-utils');
|
|
6
|
+
|
|
7
|
+
const getDataItemEditControl = ({
|
|
8
|
+
InputProps: InputProps2,
|
|
9
|
+
TypeaheadProps,
|
|
10
|
+
commitWhenCleared,
|
|
11
|
+
dataDescriptor,
|
|
12
|
+
errorMessage,
|
|
13
|
+
onCommit,
|
|
14
|
+
table
|
|
15
|
+
}) => {
|
|
16
|
+
const handleCommitNumber = (evt, value) => {
|
|
17
|
+
onCommit(evt, value.toString());
|
|
18
|
+
};
|
|
19
|
+
if (dataDescriptor.editable === false) {
|
|
20
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
21
|
+
vuuUiControls.VuuInput,
|
|
22
|
+
{
|
|
23
|
+
variant: "secondary",
|
|
24
|
+
...InputProps2,
|
|
25
|
+
onCommit,
|
|
26
|
+
readOnly: true
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
} else if (vuuUtils.isDateTimeDataValue(dataDescriptor)) {
|
|
30
|
+
return /* @__PURE__ */ jsxRuntime.jsx(vuuUiControls.VuuDatePicker, { onCommit: handleCommitNumber });
|
|
31
|
+
} else if (dataDescriptor.serverDataType === "string" && table) {
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
33
|
+
vuuUiControls.VuuTypeaheadInput,
|
|
34
|
+
{
|
|
35
|
+
...InputProps2,
|
|
36
|
+
...TypeaheadProps,
|
|
37
|
+
column: dataDescriptor.name,
|
|
38
|
+
onCommit,
|
|
39
|
+
table
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
vuuUiControls.VuuInput,
|
|
45
|
+
{
|
|
46
|
+
variant: "secondary",
|
|
47
|
+
...InputProps2,
|
|
48
|
+
commitWhenCleared,
|
|
49
|
+
onCommit,
|
|
50
|
+
errorMessage
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.getDataItemEditControl = getDataItemEditControl;
|
|
56
|
+
//# sourceMappingURL=get-data-item-edit-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-data-item-edit-control.js","sources":["../../src/data-editing/get-data-item-edit-control.tsx"],"sourcesContent":["import type {\n DataValueDescriptor,\n TableSchemaTable,\n} from \"@vuu-ui/vuu-data-types\";\nimport {\n VuuDatePicker,\n VuuInput,\n VuuTypeaheadInput,\n VuuTypeaheadInputProps,\n} from \"@vuu-ui/vuu-ui-controls\";\nimport { CommitHandler, isDateTimeDataValue } from \"@vuu-ui/vuu-utils\";\nimport { InputProps } from \"@salt-ds/core\";\n\nexport interface DataItemEditControlProps {\n InputProps?: Partial<InputProps>;\n TypeaheadProps?: Pick<VuuTypeaheadInputProps, \"highlightFirstSuggestion\">;\n commitWhenCleared?: boolean;\n /**\n * A table column or form field Descriptor.\n */\n dataDescriptor: DataValueDescriptor;\n errorMessage?: string;\n onCommit: CommitHandler<HTMLElement>;\n table?: TableSchemaTable;\n}\n\nexport type ValidationStatus = \"initial\" | true | string;\n\nexport const getDataItemEditControl = ({\n InputProps,\n TypeaheadProps,\n commitWhenCleared,\n dataDescriptor,\n errorMessage,\n onCommit,\n table,\n}: DataItemEditControlProps) => {\n const handleCommitNumber: CommitHandler<HTMLElement, number> = (\n evt,\n value,\n ) => {\n onCommit(evt, value.toString());\n };\n\n if (dataDescriptor.editable === false) {\n return (\n <VuuInput\n variant=\"secondary\"\n {...InputProps}\n onCommit={onCommit}\n readOnly\n />\n );\n } else if (isDateTimeDataValue(dataDescriptor)) {\n return <VuuDatePicker onCommit={handleCommitNumber} />;\n } else if (dataDescriptor.serverDataType === \"string\" && table) {\n return (\n <VuuTypeaheadInput\n {...InputProps}\n {...TypeaheadProps}\n column={dataDescriptor.name}\n onCommit={onCommit}\n table={table}\n />\n );\n }\n return (\n <VuuInput\n variant=\"secondary\"\n {...InputProps}\n commitWhenCleared={commitWhenCleared}\n onCommit={onCommit}\n errorMessage={errorMessage}\n />\n );\n};\n"],"names":["InputProps","jsx","VuuInput","isDateTimeDataValue","VuuDatePicker","VuuTypeaheadInput"],"mappings":";;;;;;AA4BO,MAAM,yBAAyB,CAAC;AAAA,EACrC,UAAAA,EAAAA,WAAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAgC,KAAA;AAC9B,EAAM,MAAA,kBAAA,GAAyD,CAC7D,GAAA,EACA,KACG,KAAA;AACH,IAAS,QAAA,CAAA,GAAA,EAAK,KAAM,CAAA,QAAA,EAAU,CAAA;AAAA,GAChC;AAEA,EAAI,IAAA,cAAA,CAAe,aAAa,KAAO,EAAA;AACrC,IACE,uBAAAC,cAAA;AAAA,MAACC,sBAAA;AAAA,MAAA;AAAA,QACC,OAAQ,EAAA,WAAA;AAAA,QACP,GAAGF,WAAAA;AAAA,QACJ,QAAA;AAAA,QACA,QAAQ,EAAA;AAAA;AAAA,KACV;AAAA,GAEJ,MAAA,IAAWG,4BAAoB,CAAA,cAAc,CAAG,EAAA;AAC9C,IAAO,uBAAAF,cAAA,CAACG,2BAAc,EAAA,EAAA,QAAA,EAAU,kBAAoB,EAAA,CAAA;AAAA,GAC3C,MAAA,IAAA,cAAA,CAAe,cAAmB,KAAA,QAAA,IAAY,KAAO,EAAA;AAC9D,IACE,uBAAAH,cAAA;AAAA,MAACI,+BAAA;AAAA,MAAA;AAAA,QACE,GAAGL,WAAAA;AAAA,QACH,GAAG,cAAA;AAAA,QACJ,QAAQ,cAAe,CAAA,IAAA;AAAA,QACvB,QAAA;AAAA,QACA;AAAA;AAAA,KACF;AAAA;AAGJ,EACE,uBAAAC,cAAA;AAAA,IAACC,sBAAA;AAAA,IAAA;AAAA,MACC,OAAQ,EAAA,WAAA;AAAA,MACP,GAAGF,WAAAA;AAAA,MACJ,iBAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var vuuPopups = require('@vuu-ui/vuu-popups');
|
|
5
|
+
var vuuUtils = require('@vuu-ui/vuu-utils');
|
|
6
|
+
var core = require('@salt-ds/core');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var UnsavedChangesReport = require('./UnsavedChangesReport.js');
|
|
9
|
+
var editRuleValidationChecker = require('./edit-rule-validation-checker.js');
|
|
10
|
+
var formEditState = require('./form-edit-state.js');
|
|
11
|
+
|
|
12
|
+
const CLEAN_VALIDATION = {
|
|
13
|
+
ok: true,
|
|
14
|
+
messages: {}
|
|
15
|
+
};
|
|
16
|
+
const getValidationChecker = (descriptor, editPhase) => {
|
|
17
|
+
const rules = editRuleValidationChecker.getEditValidationRules(descriptor, editPhase) ?? [];
|
|
18
|
+
return editRuleValidationChecker.buildValidationChecker(rules);
|
|
19
|
+
};
|
|
20
|
+
const nextValidationState = (state, dataDescriptor, value) => {
|
|
21
|
+
const check = getValidationChecker(dataDescriptor, "change");
|
|
22
|
+
const result = check(value, "change");
|
|
23
|
+
const { name } = dataDescriptor;
|
|
24
|
+
const { ok: wasOk, messages: existingMessages } = state;
|
|
25
|
+
if (result.ok) {
|
|
26
|
+
if (!wasOk) {
|
|
27
|
+
const fieldsInError = Object.keys(existingMessages);
|
|
28
|
+
if (fieldsInError.includes(name)) {
|
|
29
|
+
if (fieldsInError.length === 1) {
|
|
30
|
+
return { ok: true, messages: {} };
|
|
31
|
+
} else {
|
|
32
|
+
const messages = { ...existingMessages };
|
|
33
|
+
delete messages[name];
|
|
34
|
+
return { ok: false, messages };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
messages: {
|
|
42
|
+
...existingMessages,
|
|
43
|
+
[name]: result.messages.join("\n")
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return state;
|
|
48
|
+
};
|
|
49
|
+
function find(descriptors, fieldname) {
|
|
50
|
+
const d = descriptors.find(({ name }) => name === fieldname);
|
|
51
|
+
if (d) {
|
|
52
|
+
return d;
|
|
53
|
+
}
|
|
54
|
+
throw Error(`DataValueDescriptor not found for field ${fieldname}`);
|
|
55
|
+
}
|
|
56
|
+
const getField = (target) => {
|
|
57
|
+
const fieldElement = vuuUtils.queryClosest(target, "[data-field]");
|
|
58
|
+
if (fieldElement) {
|
|
59
|
+
return fieldElement.dataset.field;
|
|
60
|
+
} else {
|
|
61
|
+
throw Error("no field ");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const useEditForm = ({
|
|
65
|
+
dataSource,
|
|
66
|
+
formFieldDescriptors,
|
|
67
|
+
onSubmit
|
|
68
|
+
}) => {
|
|
69
|
+
const { showDialog, closeDialog } = vuuPopups.useDialogContext();
|
|
70
|
+
const currentDataSource = react.useRef(void 0);
|
|
71
|
+
const formFieldsContainerRef = react.useRef(null);
|
|
72
|
+
const entityRef = react.useRef(void 0);
|
|
73
|
+
const focusedFieldRef = react.useRef("");
|
|
74
|
+
const originalEntityRef = react.useRef(void 0);
|
|
75
|
+
const formEditStateRef = react.useRef(formEditState.CLEAN_FORM);
|
|
76
|
+
const validationStateRef = react.useRef({
|
|
77
|
+
ok: true,
|
|
78
|
+
messages: {}
|
|
79
|
+
});
|
|
80
|
+
const [entity, _setEntity] = react.useState();
|
|
81
|
+
const [, forceUpdate] = react.useState({});
|
|
82
|
+
const setFormEditState = react.useCallback((newState) => {
|
|
83
|
+
formEditStateRef.current = newState;
|
|
84
|
+
}, []);
|
|
85
|
+
const setEntity = react.useCallback(
|
|
86
|
+
(newEntity) => {
|
|
87
|
+
setFormEditState(
|
|
88
|
+
formEditState.buildFormEditState(originalEntityRef.current, newEntity)
|
|
89
|
+
);
|
|
90
|
+
entityRef.current = newEntity;
|
|
91
|
+
_setEntity(newEntity);
|
|
92
|
+
},
|
|
93
|
+
[setFormEditState]
|
|
94
|
+
);
|
|
95
|
+
const submitChanges = react.useCallback(async () => {
|
|
96
|
+
const rpcResponse = await currentDataSource.current?.rpcCall?.(
|
|
97
|
+
vuuUtils.viewportRpcRequest("VP_BULK_EDIT_SUBMIT_RPC")
|
|
98
|
+
);
|
|
99
|
+
console.log({ rpcResponse });
|
|
100
|
+
}, []);
|
|
101
|
+
const showSaveOrDiscardPrompt = react.useCallback(async () => {
|
|
102
|
+
const { current: currentEntity } = entityRef;
|
|
103
|
+
const { current: originalEntity } = originalEntityRef;
|
|
104
|
+
let resolver = void 0;
|
|
105
|
+
const save = async () => {
|
|
106
|
+
await submitChanges();
|
|
107
|
+
closeDialog();
|
|
108
|
+
resolver?.("saved");
|
|
109
|
+
};
|
|
110
|
+
const discard = () => {
|
|
111
|
+
closeDialog();
|
|
112
|
+
resolver?.("discarded");
|
|
113
|
+
};
|
|
114
|
+
requestAnimationFrame(() => {
|
|
115
|
+
showDialog(
|
|
116
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
117
|
+
UnsavedChangesReport.UnsavedChangesReport,
|
|
118
|
+
{
|
|
119
|
+
entity: originalEntity,
|
|
120
|
+
editedEntity: currentEntity
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
"Unsaved Changes",
|
|
124
|
+
[
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Button, { onClick: discard, children: "Discard Changes" }, "cancel"),
|
|
126
|
+
/* @__PURE__ */ jsxRuntime.jsx(core.Button, { onClick: save, children: "Save Changes" }, "submit")
|
|
127
|
+
],
|
|
128
|
+
true
|
|
129
|
+
// hideCloseButton
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
resolver = resolve;
|
|
134
|
+
});
|
|
135
|
+
}, [closeDialog, showDialog, submitChanges]);
|
|
136
|
+
react.useMemo(async () => {
|
|
137
|
+
if (dataSource) {
|
|
138
|
+
if (formEditStateRef.current.isClean === false) {
|
|
139
|
+
await showSaveOrDiscardPrompt();
|
|
140
|
+
}
|
|
141
|
+
currentDataSource.current = dataSource;
|
|
142
|
+
originalEntityRef.current = void 0;
|
|
143
|
+
const columnMap = vuuUtils.buildColumnMap(dataSource.columns);
|
|
144
|
+
dataSource?.subscribe({ range: vuuUtils.Range(0, 1) }, (message) => {
|
|
145
|
+
if (vuuUtils.messageHasDataRows(message)) {
|
|
146
|
+
const [row] = message.rows;
|
|
147
|
+
if (row) {
|
|
148
|
+
const entity2 = vuuUtils.dataSourceRowToEntity(row, columnMap);
|
|
149
|
+
if (originalEntityRef.current === void 0) {
|
|
150
|
+
originalEntityRef.current = entity2;
|
|
151
|
+
setEntity(entity2);
|
|
152
|
+
}
|
|
153
|
+
const { editedFields: editedFields2 } = formEditState.buildFormEditState(
|
|
154
|
+
entityRef.current,
|
|
155
|
+
entity2
|
|
156
|
+
);
|
|
157
|
+
if (editedFields2.length === 1) {
|
|
158
|
+
setEntity(entity2);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}, [dataSource, setEntity, showSaveOrDiscardPrompt]);
|
|
165
|
+
const setValidationState = react.useCallback((state) => {
|
|
166
|
+
validationStateRef.current = state;
|
|
167
|
+
forceUpdate({});
|
|
168
|
+
}, []);
|
|
169
|
+
const handleFieldCommit = react.useCallback(
|
|
170
|
+
(_, value) => {
|
|
171
|
+
const { current: fieldName } = focusedFieldRef;
|
|
172
|
+
const dataDescriptor = find(formFieldDescriptors, fieldName);
|
|
173
|
+
const { current: state } = validationStateRef;
|
|
174
|
+
const newState = nextValidationState(state, dataDescriptor, value);
|
|
175
|
+
if (newState !== state) {
|
|
176
|
+
setValidationState(newState);
|
|
177
|
+
}
|
|
178
|
+
if (newState.ok && dataSource?.tableSchema) {
|
|
179
|
+
const { key } = dataSource.tableSchema;
|
|
180
|
+
const keyValue = entity?.[key];
|
|
181
|
+
dataSource?.applyEdit(keyValue, fieldName, value).then((rpcResponse) => {
|
|
182
|
+
console.log({ rpcResponse });
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
[dataSource, entity, formFieldDescriptors, setValidationState]
|
|
187
|
+
);
|
|
188
|
+
const handleFieldChange = react.useCallback(
|
|
189
|
+
(evt) => {
|
|
190
|
+
const { current: fieldName } = focusedFieldRef;
|
|
191
|
+
if (fieldName) {
|
|
192
|
+
const input = vuuUtils.queryClosest(evt.target, "input", true);
|
|
193
|
+
const dataDescriptor = find(formFieldDescriptors, fieldName);
|
|
194
|
+
const value = input.value;
|
|
195
|
+
const { current: state } = validationStateRef;
|
|
196
|
+
const newState = nextValidationState(state, dataDescriptor, value);
|
|
197
|
+
if (newState !== state) {
|
|
198
|
+
setValidationState(newState);
|
|
199
|
+
}
|
|
200
|
+
setEntity({ ...entity, [fieldName]: value });
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
[entity, formFieldDescriptors, setEntity, setValidationState]
|
|
204
|
+
);
|
|
205
|
+
const handleFormSubmit = react.useCallback(async () => {
|
|
206
|
+
submitChanges();
|
|
207
|
+
setFormEditState(formEditState.CLEAN_FORM);
|
|
208
|
+
originalEntityRef.current = entity;
|
|
209
|
+
onSubmit?.();
|
|
210
|
+
forceUpdate({});
|
|
211
|
+
}, [entity, onSubmit, setFormEditState, submitChanges]);
|
|
212
|
+
const handleFormCancel = react.useCallback(async () => {
|
|
213
|
+
setFormEditState(formEditState.CLEAN_FORM);
|
|
214
|
+
setValidationState(CLEAN_VALIDATION);
|
|
215
|
+
setEntity(originalEntityRef.current);
|
|
216
|
+
}, [setEntity, setFormEditState, setValidationState]);
|
|
217
|
+
const handleFocus = react.useCallback((evt) => {
|
|
218
|
+
if (formFieldsContainerRef.current?.contains(evt.target)) {
|
|
219
|
+
const fieldName = getField(evt.target);
|
|
220
|
+
if (fieldName) {
|
|
221
|
+
if (fieldName) {
|
|
222
|
+
focusedFieldRef.current = fieldName;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, []);
|
|
227
|
+
const {
|
|
228
|
+
current: { ok, messages: errorMessages }
|
|
229
|
+
} = validationStateRef;
|
|
230
|
+
const {
|
|
231
|
+
current: { isClean, editedFields }
|
|
232
|
+
} = formEditStateRef;
|
|
233
|
+
return {
|
|
234
|
+
editedFields,
|
|
235
|
+
editEntity: entity,
|
|
236
|
+
errorMessages,
|
|
237
|
+
formFieldsContainerRef,
|
|
238
|
+
isClean,
|
|
239
|
+
ok,
|
|
240
|
+
onCancel: handleFormCancel,
|
|
241
|
+
onChange: handleFieldChange,
|
|
242
|
+
onCommit: handleFieldCommit,
|
|
243
|
+
onFocus: handleFocus,
|
|
244
|
+
onSubmit: handleFormSubmit
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
exports.useEditForm = useEditForm;
|
|
249
|
+
//# sourceMappingURL=useEditForm.js.map
|