@signal24/vue-foundation 4.4.0 → 4.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@signal24/vue-foundation",
3
3
  "type": "module",
4
- "version": "4.4.0",
4
+ "version": "4.5.1",
5
5
  "description": "Common components, directives, and helpers for Vue 3 apps",
6
6
  "module": "./dist/vue-foundation.es.js",
7
7
  "bin": {
@@ -53,7 +53,7 @@ export function showContextMenu(e: MouseEvent, config: ContextMenuConfig) {
53
53
  }
54
54
 
55
55
  if (item.shouldConfirm) {
56
- itemEl.addEventListener('click', () => confirmAction(itemEl, item.handler));
56
+ itemEl.addEventListener('click', e => confirmAction(e, itemEl, item.handler));
57
57
  } else {
58
58
  itemEl.addEventListener('click', () => item.handler());
59
59
  }
@@ -85,7 +85,7 @@ export function showContextMenu(e: MouseEvent, config: ContextMenuConfig) {
85
85
  wrapperEl.remove();
86
86
  }
87
87
 
88
- function confirmAction(itemEl: HTMLElement, handler: () => void) {
88
+ function confirmAction(e: MouseEvent, itemEl: HTMLElement, handler: () => void) {
89
89
  if (itemEl.classList.contains('pending-confirm')) {
90
90
  return handler();
91
91
  }
@@ -106,4 +106,3 @@ export function showContextMenu(e: MouseEvent, config: ContextMenuConfig) {
106
106
  }
107
107
 
108
108
  // TODO: actually de-select text rather than just using CSS to hide its selection
109
- // TODO: confirm isn't working
@@ -53,6 +53,8 @@ export function isApiError(err: any): err is IApiError {
53
53
  export function installApiClientInterceptors({ apiClient, onRequest, onError, CancelablePromise }: IWrappedApiClientOptions) {
54
54
  const originalRequest = apiClient.request.request.bind(apiClient.request);
55
55
  apiClient.request.request = (options: IRequestOptions) => {
56
+ options = rewriteOptionsForFileUpload(options);
57
+
56
58
  if (onRequest) {
57
59
  options = onRequest(options);
58
60
  }
@@ -82,3 +84,39 @@ export function installApiClientInterceptors({ apiClient, onRequest, onError, Ca
82
84
  });
83
85
  };
84
86
  }
87
+
88
+ export class FileUploadRequest {
89
+ constructor(blob: Blob) {
90
+ this.blob = blob;
91
+ }
92
+
93
+ validator = null;
94
+ lastModifiedDate = null;
95
+ size = 0;
96
+ path = '';
97
+ name = '';
98
+ type = '';
99
+ blob!: Blob;
100
+ }
101
+
102
+ function rewriteOptionsForFileUpload(options: IRequestOptions): IRequestOptions {
103
+ const hasFileUpload = typeof options.body === 'object' && Object.values(options.body).some(v => v instanceof FileUploadRequest);
104
+ if (!hasFileUpload) return options;
105
+
106
+ const formData: Record<string, any> = {};
107
+ const jsonBody: Record<string, any> = {};
108
+ for (const [key, value] of Object.entries(options.body)) {
109
+ if (value instanceof FileUploadRequest) {
110
+ formData[key] = value.blob;
111
+ } else {
112
+ jsonBody[key] = value;
113
+ }
114
+ }
115
+ formData._payload = new Blob([JSON.stringify(jsonBody)], { type: 'application/json' });
116
+
117
+ return {
118
+ ...options,
119
+ body: undefined,
120
+ formData
121
+ };
122
+ }