@vuu-ui/vuu-data-editing 3.3.11 → 3.3.13
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/package.json +6 -6
- package/src/EditButtons.js +6 -12
- package/src/EditSession.js +3 -0
- package/src/index.js +1 -0
- package/src/useEditState.js +15 -0
- package/types/EditSession.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/useEditState.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.3.
|
|
2
|
+
"version": "3.3.13",
|
|
3
3
|
"description": "Shared data editing APIs and React components for VUU UI",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"author": "heswell",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@salt-ds/core": "1.54.1",
|
|
15
|
-
"@vuu-ui/vuu-ui-controls": "3.3.
|
|
16
|
-
"@vuu-ui/vuu-utils": "3.3.
|
|
15
|
+
"@vuu-ui/vuu-ui-controls": "3.3.13",
|
|
16
|
+
"@vuu-ui/vuu-utils": "3.3.13"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@vuu-ui/vuu-data-types": "3.3.
|
|
20
|
-
"@vuu-ui/vuu-protocol-types": "3.3.
|
|
21
|
-
"@vuu-ui/vuu-table-types": "3.3.
|
|
19
|
+
"@vuu-ui/vuu-data-types": "3.3.13",
|
|
20
|
+
"@vuu-ui/vuu-protocol-types": "3.3.13",
|
|
21
|
+
"@vuu-ui/vuu-table-types": "3.3.13"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^19.2.3"
|
package/src/EditButtons.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Button } from "@salt-ds/core";
|
|
3
|
-
import { useCallback
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { useEditState } from "./useEditState.js";
|
|
4
5
|
const EditButtons = ({ canCancel, canSave, confirmCancel, confirmSave, editSession, hasSelection = false, onCancel, onDelete, onSave, saveLabel = "Save" })=>{
|
|
5
|
-
const
|
|
6
|
+
const editState = useEditState(editSession);
|
|
7
|
+
const isDirty = editSession?.isDirty ?? false;
|
|
6
8
|
const handleSave = useCallback(async ()=>{
|
|
7
9
|
if (confirmSave) {
|
|
8
10
|
const confirmed = await confirmSave();
|
|
@@ -15,24 +17,16 @@ const EditButtons = ({ canCancel, canSave, confirmCancel, confirmSave, editSessi
|
|
|
15
17
|
onSave
|
|
16
18
|
]);
|
|
17
19
|
const handleCancel = useCallback(async ()=>{
|
|
18
|
-
if (confirmCancel) {
|
|
20
|
+
if (confirmCancel && isDirty) {
|
|
19
21
|
const confirmed = await confirmCancel();
|
|
20
22
|
if (!confirmed) return;
|
|
21
23
|
}
|
|
22
24
|
onCancel?.();
|
|
23
25
|
}, [
|
|
24
26
|
confirmCancel,
|
|
27
|
+
isDirty,
|
|
25
28
|
onCancel
|
|
26
29
|
]);
|
|
27
|
-
useEffect(()=>{
|
|
28
|
-
if (editSession) {
|
|
29
|
-
setEditState(editSession.editState);
|
|
30
|
-
editSession.on("editState", setEditState);
|
|
31
|
-
return ()=>editSession.removeListener("editState", setEditState);
|
|
32
|
-
}
|
|
33
|
-
}, [
|
|
34
|
-
editSession
|
|
35
|
-
]);
|
|
36
30
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
37
31
|
children: [
|
|
38
32
|
onDelete && /*#__PURE__*/ jsx(Button, {
|
package/src/EditSession.js
CHANGED
|
@@ -66,6 +66,9 @@ class EditSession extends EventEmitter {
|
|
|
66
66
|
if (this.#isStale) return "stale";
|
|
67
67
|
return 0 === this.#editCount && 0 === this.#deleteCount && 0 === this.#addCount ? "clean" : "dirty";
|
|
68
68
|
}
|
|
69
|
+
get isDirty() {
|
|
70
|
+
return "clean" !== this.editState;
|
|
71
|
+
}
|
|
69
72
|
#emitEditStateChange(oldState, force = false) {
|
|
70
73
|
const newState = this.editState;
|
|
71
74
|
if (force || newState !== oldState) this.emit("editState", newState);
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { DataEditingProvider, useEditSession } from "./DataEditingProvider.js";
|
|
2
2
|
export { useCellEdited } from "./useCellEdited.js";
|
|
3
|
+
export { useEditState } from "./useEditState.js";
|
|
3
4
|
export { getVuuEditMessage, isEditRowReadOnly, isInlineEditingSession, withDataRowEditErrors } from "./edit-utils.js";
|
|
4
5
|
export { EditButtons } from "./EditButtons.js";
|
|
5
6
|
export { EditModeProvider, useEditMode } from "./EditModeProvider.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
+
function useEditState(editSession) {
|
|
3
|
+
const subscribe = useCallback((onStoreChange)=>{
|
|
4
|
+
if (!editSession) return ()=>void 0;
|
|
5
|
+
editSession.on("editState", onStoreChange);
|
|
6
|
+
return ()=>editSession.removeListener("editState", onStoreChange);
|
|
7
|
+
}, [
|
|
8
|
+
editSession
|
|
9
|
+
]);
|
|
10
|
+
const getSnapshot = useCallback(()=>editSession?.editState ?? "clean", [
|
|
11
|
+
editSession
|
|
12
|
+
]);
|
|
13
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
14
|
+
}
|
|
15
|
+
export { useEditState };
|
package/types/EditSession.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export declare class EditSession extends EventEmitter<EditSessionEvents> {
|
|
|
58
58
|
get deleteCount(): number;
|
|
59
59
|
get addCount(): number;
|
|
60
60
|
get editState(): EditState;
|
|
61
|
+
get isDirty(): boolean;
|
|
61
62
|
get newRowState(): NewRowState;
|
|
62
63
|
isNewRow(key: string): key is "__vuu_new_row__";
|
|
63
64
|
isNewRowFinalColumn(columnName: string): boolean;
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { DataEditingProvider, useEditSession } from "./DataEditingProvider";
|
|
2
2
|
export { useCellEdited } from "./useCellEdited";
|
|
3
|
+
export { useEditState } from "./useEditState";
|
|
3
4
|
export { getVuuEditMessage, isInlineEditingSession, isEditRowReadOnly, withDataRowEditErrors, } from "./edit-utils";
|
|
4
5
|
export { EditButtons, type EditButtonProps } from "./EditButtons";
|
|
5
6
|
export { EditModeProvider, useEditMode, type EditModeContextProps, } from "./EditModeProvider";
|