@forge/react 11.6.1-next.1-experimental-f85d28a → 11.7.0-next.2
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/CHANGELOG.md +7 -7
- package/out/hooks/__test__/useObjectStore.test.d.ts +2 -0
- package/out/hooks/__test__/useObjectStore.test.d.ts.map +1 -0
- package/out/hooks/__test__/useObjectStore.test.js +542 -0
- package/out/hooks/types/objectStoreProps.d.ts +33 -0
- package/out/hooks/types/objectStoreProps.d.ts.map +1 -0
- package/out/hooks/types/objectStoreProps.js +2 -0
- package/out/hooks/useObjectStore.d.ts +9 -0
- package/out/hooks/useObjectStore.d.ts.map +1 -0
- package/out/hooks/useObjectStore.js +162 -0
- package/out/index.d.ts +1 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -1
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useObjectStore = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const bridge_1 = require("@forge/bridge");
|
|
6
|
+
// Helper function to update an object by key
|
|
7
|
+
const updateObjectByKey = (objects, key, updates) => objects.map((obj) => (obj.key === key ? { ...obj, ...updates } : obj));
|
|
8
|
+
function objectStoreReducer(state, action) {
|
|
9
|
+
switch (action.type) {
|
|
10
|
+
case 'ADD_OBJECTS':
|
|
11
|
+
return { objects: [...state.objects, ...action.payload] };
|
|
12
|
+
case 'UPDATE_OBJECT':
|
|
13
|
+
return { objects: updateObjectByKey(state.objects, action.payload.key, action.payload.updates) };
|
|
14
|
+
case 'UPLOAD_OBJECT_START':
|
|
15
|
+
// Add temp object with isUploading state
|
|
16
|
+
return {
|
|
17
|
+
objects: [...state.objects, { key: action.payload.tempKey, isUploading: true }]
|
|
18
|
+
};
|
|
19
|
+
case 'UPLOAD_OBJECT_SUCCESS':
|
|
20
|
+
// Replace temp object with real object
|
|
21
|
+
return {
|
|
22
|
+
objects: state.objects.map((obj) => (obj.key === action.payload.tempKey ? action.payload.object : obj))
|
|
23
|
+
};
|
|
24
|
+
case 'UPLOAD_OBJECT_ERROR':
|
|
25
|
+
// Replace temp object with error state
|
|
26
|
+
return {
|
|
27
|
+
objects: state.objects.map((obj) => obj.key === action.payload.tempKey
|
|
28
|
+
? { ...obj, isUploading: false, error: action.payload.error, success: false }
|
|
29
|
+
: obj)
|
|
30
|
+
};
|
|
31
|
+
case 'DELETE_START':
|
|
32
|
+
return {
|
|
33
|
+
objects: state.objects.map((obj) => action.payload.includes(obj.key) ? { ...obj, isDeleting: true, error: undefined } : obj)
|
|
34
|
+
};
|
|
35
|
+
case 'DELETE_SUCCESS':
|
|
36
|
+
return { objects: state.objects.filter((obj) => !action.payload.includes(obj.key)) };
|
|
37
|
+
case 'DELETE_ERROR':
|
|
38
|
+
return {
|
|
39
|
+
objects: state.objects.map((obj) => action.payload.keys.includes(obj.key) ? { ...obj, isDeleting: false, error: action.payload.error } : obj)
|
|
40
|
+
};
|
|
41
|
+
case 'DOWNLOAD_START':
|
|
42
|
+
return {
|
|
43
|
+
objects: state.objects.map((obj) => action.payload.includes(obj.key) ? { ...obj, isDownloading: true, error: undefined } : obj)
|
|
44
|
+
};
|
|
45
|
+
case 'DOWNLOAD_COMPLETE':
|
|
46
|
+
return {
|
|
47
|
+
objects: state.objects.map((obj) => {
|
|
48
|
+
if (action.payload.successfulKeys.includes(obj.key)) {
|
|
49
|
+
return { ...obj, isDownloading: false };
|
|
50
|
+
}
|
|
51
|
+
if (action.payload.failedKeys.includes(obj.key)) {
|
|
52
|
+
return { ...obj, isDownloading: false, error: 'Download failed' };
|
|
53
|
+
}
|
|
54
|
+
return obj;
|
|
55
|
+
})
|
|
56
|
+
};
|
|
57
|
+
default:
|
|
58
|
+
return state;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function useObjectStore(props = {}) {
|
|
62
|
+
const [state, dispatch] = (0, react_1.useReducer)(objectStoreReducer, {
|
|
63
|
+
objects: props.defaultValues || []
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Get a specific object from objectState by key
|
|
67
|
+
*/
|
|
68
|
+
const getObjectMetadata = (key) => {
|
|
69
|
+
const object = state.objects.find((obj) => obj.key === key);
|
|
70
|
+
if (!object) {
|
|
71
|
+
// eslint-disable-next-line no-console
|
|
72
|
+
console.warn(`No metadata found for object with key: ${key}`);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return object;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Upload objects and update objectState with results
|
|
79
|
+
*/
|
|
80
|
+
const uploadObjects = (0, react_1.useCallback)(async (params) => {
|
|
81
|
+
const timestamp = Date.now();
|
|
82
|
+
try {
|
|
83
|
+
const uploadPromises = await (0, bridge_1.createUploadPromises)(params);
|
|
84
|
+
const trackedUploadPromises = uploadPromises.map(async ({ promise, index, objectType, objectSize }) => {
|
|
85
|
+
const tempKey = `temp-upload-${timestamp}-${index}`;
|
|
86
|
+
dispatch({ type: 'UPLOAD_OBJECT_START', payload: { tempKey } });
|
|
87
|
+
try {
|
|
88
|
+
const result = await promise;
|
|
89
|
+
const objectState = {
|
|
90
|
+
key: result.key,
|
|
91
|
+
success: result.success,
|
|
92
|
+
status: result.status,
|
|
93
|
+
error: result.error,
|
|
94
|
+
objectType,
|
|
95
|
+
objectSize
|
|
96
|
+
};
|
|
97
|
+
dispatch({ type: 'UPLOAD_OBJECT_SUCCESS', payload: { tempKey, object: objectState } });
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
dispatch({
|
|
102
|
+
type: 'UPLOAD_OBJECT_ERROR',
|
|
103
|
+
payload: { tempKey, error: error instanceof Error ? error.message : 'Upload failed' }
|
|
104
|
+
});
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
await Promise.all(trackedUploadPromises);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}, []);
|
|
114
|
+
/**
|
|
115
|
+
* Delete objects by keys from state and backend
|
|
116
|
+
*/
|
|
117
|
+
const deleteObjects = (0, react_1.useCallback)(async (params) => {
|
|
118
|
+
dispatch({ type: 'DELETE_START', payload: params.keys });
|
|
119
|
+
try {
|
|
120
|
+
await bridge_1.objectStore.delete(params);
|
|
121
|
+
dispatch({ type: 'DELETE_SUCCESS', payload: params.keys });
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
dispatch({
|
|
125
|
+
type: 'DELETE_ERROR',
|
|
126
|
+
payload: { keys: params.keys, error: error instanceof Error ? error.message : 'Delete failed' }
|
|
127
|
+
});
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}, []);
|
|
131
|
+
/**
|
|
132
|
+
* Download objects by keys
|
|
133
|
+
*/
|
|
134
|
+
const downloadObjects = (0, react_1.useCallback)(async (params) => {
|
|
135
|
+
dispatch({ type: 'DOWNLOAD_START', payload: params.keys });
|
|
136
|
+
try {
|
|
137
|
+
const results = await bridge_1.objectStore.download(params);
|
|
138
|
+
const successfulKeys = results.filter((r) => r.success).map((r) => r.key);
|
|
139
|
+
const failedKeys = results.filter((r) => !r.success).map((r) => r.key);
|
|
140
|
+
dispatch({
|
|
141
|
+
type: 'DOWNLOAD_COMPLETE',
|
|
142
|
+
payload: { successfulKeys, failedKeys }
|
|
143
|
+
});
|
|
144
|
+
return results;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
dispatch({
|
|
148
|
+
type: 'DOWNLOAD_COMPLETE',
|
|
149
|
+
payload: { successfulKeys: [], failedKeys: params.keys }
|
|
150
|
+
});
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}, []);
|
|
154
|
+
return {
|
|
155
|
+
objectStates: state.objects,
|
|
156
|
+
getObjectMetadata,
|
|
157
|
+
uploadObjects,
|
|
158
|
+
deleteObjects,
|
|
159
|
+
downloadObjects
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
exports.useObjectStore = useObjectStore;
|
package/out/index.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export { useIssueProperty } from './hooks/useIssueProperty';
|
|
|
9
9
|
export { useTranslation, I18nProvider } from './hooks/useTranslation';
|
|
10
10
|
export { replaceUnsupportedDocumentNodes } from './components/utils/replaceUnsupportedDocumentNodes';
|
|
11
11
|
export { useForm } from './hooks/useForm';
|
|
12
|
+
export { useObjectStore } from './hooks/useObjectStore';
|
|
12
13
|
export * from './package-types';
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,cAAc,iBAAiB,CAAC"}
|
package/out/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useForm = exports.replaceUnsupportedDocumentNodes = exports.I18nProvider = exports.useTranslation = exports.useIssueProperty = exports.useSpaceProperty = exports.useContentProperty = exports.default = exports.usePermissions = exports.useConfig = exports.useProductContext = void 0;
|
|
3
|
+
exports.useObjectStore = exports.useForm = exports.replaceUnsupportedDocumentNodes = exports.I18nProvider = exports.useTranslation = exports.useIssueProperty = exports.useSpaceProperty = exports.useContentProperty = exports.default = exports.usePermissions = exports.useConfig = exports.useProductContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var useProductContext_1 = require("./hooks/useProductContext");
|
|
6
6
|
Object.defineProperty(exports, "useProductContext", { enumerable: true, get: function () { return useProductContext_1.useProductContext; } });
|
|
@@ -24,4 +24,6 @@ var replaceUnsupportedDocumentNodes_1 = require("./components/utils/replaceUnsup
|
|
|
24
24
|
Object.defineProperty(exports, "replaceUnsupportedDocumentNodes", { enumerable: true, get: function () { return replaceUnsupportedDocumentNodes_1.replaceUnsupportedDocumentNodes; } });
|
|
25
25
|
var useForm_1 = require("./hooks/useForm");
|
|
26
26
|
Object.defineProperty(exports, "useForm", { enumerable: true, get: function () { return useForm_1.useForm; } });
|
|
27
|
+
var useObjectStore_1 = require("./hooks/useObjectStore");
|
|
28
|
+
Object.defineProperty(exports, "useObjectStore", { enumerable: true, get: function () { return useObjectStore_1.useObjectStore; } });
|
|
27
29
|
tslib_1.__exportStar(require("./package-types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/react",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.0-next.2",
|
|
4
4
|
"description": "Forge React reconciler",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@atlaskit/adf-schema": "^48.0.0",
|
|
29
29
|
"@atlaskit/adf-utils": "^19.19.0",
|
|
30
30
|
"@atlaskit/forge-react-types": "^0.44.0",
|
|
31
|
-
"@forge/bridge": "^5.8.0-next.
|
|
31
|
+
"@forge/bridge": "^5.8.0-next.13",
|
|
32
32
|
"@forge/i18n": "0.0.7",
|
|
33
33
|
"@types/react": "^18.2.64",
|
|
34
34
|
"@types/react-reconciler": "^0.28.8",
|