plusui-native-core 0.1.43 → 0.1.45

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.
@@ -24,6 +24,7 @@ add_library(plusui STATIC
24
24
  Features/Bindings/CustomBindings/custom_bindings.cpp
25
25
  Features/App/app.cpp
26
26
  Features/Window/window.cpp
27
+ Features/FileDrop/filedrop.cpp
27
28
  Features/Browser/browser.cpp
28
29
  Features/Display/display.cpp
29
30
  Features/Tray/tray.cpp
@@ -3,6 +3,8 @@
3
3
  #include <mutex>
4
4
  #include <filesystem>
5
5
  #include <fstream>
6
+ #include <unordered_map>
7
+ #include <cctype>
6
8
 
7
9
  #ifdef _WIN32
8
10
  #define WIN32_LEAN_AND_MEAN
@@ -171,8 +173,10 @@ static std::string getMimeType(const std::string& filePath) {
171
173
  // Platform-specific helper to handle dropped files
172
174
  #ifdef _WIN32
173
175
  // Windows implementation for handling WM_DROPFILES message
174
- void HandleDropFiles(FileDrop::Impl* impl, HDROP hDrop) {
175
- if (!impl->enabled || !impl->filesDroppedCallback) {
176
+ void HandleDropFiles(bool enabled,
177
+ const std::function<void(const std::vector<FileInfo>&)>& filesDroppedCallback,
178
+ HDROP hDrop) {
179
+ if (!enabled || !filesDroppedCallback) {
176
180
  return;
177
181
  }
178
182
 
@@ -215,8 +219,8 @@ void HandleDropFiles(FileDrop::Impl* impl, HDROP hDrop) {
215
219
 
216
220
  DragFinish(hDrop);
217
221
 
218
- if (!files.empty() && impl->filesDroppedCallback) {
219
- impl->filesDroppedCallback(files);
222
+ if (!files.empty() && filesDroppedCallback) {
223
+ filesDroppedCallback(files);
220
224
  }
221
225
  }
222
226
  #endif
@@ -225,8 +229,10 @@ void HandleDropFiles(FileDrop::Impl* impl, HDROP hDrop) {
225
229
  // macOS implementation using NSPasteboard and drag&drop APIs
226
230
  // This would be implemented with Objective-C++ integration with NSView
227
231
  // For now, providing the interface structure
228
- void HandleMacDropFiles(FileDrop::Impl* impl, NSArray<NSURL*>* urls) {
229
- if (!impl->enabled || !impl->filesDroppedCallback) {
232
+ void HandleMacDropFiles(bool enabled,
233
+ const std::function<void(const std::vector<FileInfo>&)>& filesDroppedCallback,
234
+ NSArray<NSURL*>* urls) {
235
+ if (!enabled || !filesDroppedCallback) {
230
236
  return;
231
237
  }
232
238
 
@@ -256,16 +262,18 @@ void HandleMacDropFiles(FileDrop::Impl* impl, NSArray<NSURL*>* urls) {
256
262
  files.push_back(info);
257
263
  }
258
264
 
259
- if (!files.empty() && impl->filesDroppedCallback) {
260
- impl->filesDroppedCallback(files);
265
+ if (!files.empty() && filesDroppedCallback) {
266
+ filesDroppedCallback(files);
261
267
  }
262
268
  }
263
269
  #endif
264
270
 
265
271
  #ifdef __linux__
266
272
  // Linux/GTK implementation
267
- void HandleGtkDropFiles(FileDrop::Impl* impl, GtkSelectionData* data) {
268
- if (!impl->enabled || !impl->filesDroppedCallback) {
273
+ void HandleGtkDropFiles(bool enabled,
274
+ const std::function<void(const std::vector<FileInfo>&)>& filesDroppedCallback,
275
+ GtkSelectionData* data) {
276
+ if (!enabled || !filesDroppedCallback) {
269
277
  return;
270
278
  }
271
279
 
@@ -307,8 +315,8 @@ void HandleGtkDropFiles(FileDrop::Impl* impl, GtkSelectionData* data) {
307
315
  g_strfreev(uris);
308
316
  }
309
317
 
310
- if (!files.empty() && impl->filesDroppedCallback) {
311
- impl->filesDroppedCallback(files);
318
+ if (!files.empty() && filesDroppedCallback) {
319
+ filesDroppedCallback(files);
312
320
  }
313
321
  }
314
322
  #endif
@@ -767,6 +767,12 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
767
767
  Window win;
768
768
  win.pImpl->config = config;
769
769
 
770
+ // Pure native file-drop mode: when native FileDrop is enabled,
771
+ // fully disable browser/WebView drag-drop handling.
772
+ if (win.pImpl->config.enableFileDrop) {
773
+ win.pImpl->config.disableWebviewDragDrop = true;
774
+ }
775
+
770
776
  #ifdef _WIN32
771
777
  HWND hwnd = static_cast<HWND>(windowHandle);
772
778
 
@@ -829,24 +835,31 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
829
835
  // and allows the native FileDrop API to handle them instead
830
836
  if (pImpl->config.disableWebviewDragDrop) {
831
837
  std::string disableDragDropScript = R"(
832
- (function() {
833
- // Prevent default drag and drop behavior on document/window
834
- ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(function(eventName) {
835
- document.addEventListener(eventName, function(e) {
836
- // Only prevent default on document.body or document.documentElement
837
- // to allow custom drop zones to still work
838
- if (e.target === document.body || e.target === document.documentElement || e.target === document) {
839
- e.preventDefault();
840
- e.stopPropagation();
841
- }
842
- }, true);
843
-
844
- window.addEventListener(eventName, function(e) {
845
- e.preventDefault();
846
- e.stopPropagation();
847
- }, true);
848
- });
849
- })();
838
+ (function() {
839
+ if (window.__plusui_nativeFileDropOnly) return;
840
+ window.__plusui_nativeFileDropOnly = true;
841
+
842
+ var block = function(e) {
843
+ if (!e) return false;
844
+ e.preventDefault();
845
+ e.stopPropagation();
846
+ if (typeof e.stopImmediatePropagation === 'function') {
847
+ e.stopImmediatePropagation();
848
+ }
849
+ if (e.dataTransfer) {
850
+ try { e.dataTransfer.dropEffect = 'none'; } catch (_) {}
851
+ }
852
+ return false;
853
+ };
854
+
855
+ window.__plusui_dragDropEvents = ['dragenter', 'dragover', 'dragleave', 'drop'];
856
+ window.__plusui_dragDropBlocker = block;
857
+
858
+ window.__plusui_dragDropEvents.forEach(function(eventName) {
859
+ window.addEventListener(eventName, block, true);
860
+ document.addEventListener(eventName, block, true);
861
+ });
862
+ })();
850
863
  )";
851
864
  pImpl->webview->AddScriptToExecuteOnDocumentCreated(
852
865
  std::wstring(disableDragDropScript.begin(),
@@ -1175,17 +1188,21 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
1175
1188
  // Disable webview drag & drop behavior to allow native FileDrop API
1176
1189
  if (win.pImpl->config.disableWebviewDragDrop) {
1177
1190
  NSString *disableDragDropScript = @"(function() {"
1178
- "['dragenter', 'dragover', 'dragleave', 'drop'].forEach(function(eventName) {"
1179
- "document.addEventListener(eventName, function(e) {"
1180
- "if (e.target === document.body || e.target === document.documentElement || e.target === document) {"
1181
- "e.preventDefault();"
1182
- "e.stopPropagation();"
1183
- "}"
1184
- "}, true);"
1185
- "window.addEventListener(eventName, function(e) {"
1186
- "e.preventDefault();"
1187
- "e.stopPropagation();"
1188
- "}, true);"
1191
+ "if (window.__plusui_nativeFileDropOnly) return;"
1192
+ "window.__plusui_nativeFileDropOnly = true;"
1193
+ "var block = function(e) {"
1194
+ "if (!e) return false;"
1195
+ "e.preventDefault();"
1196
+ "e.stopPropagation();"
1197
+ "if (typeof e.stopImmediatePropagation === 'function') e.stopImmediatePropagation();"
1198
+ "if (e.dataTransfer) { try { e.dataTransfer.dropEffect = 'none'; } catch (_) {} }"
1199
+ "return false;"
1200
+ "};"
1201
+ "window.__plusui_dragDropEvents = ['dragenter','dragover','dragleave','drop'];"
1202
+ "window.__plusui_dragDropBlocker = block;"
1203
+ "window.__plusui_dragDropEvents.forEach(function(eventName) {"
1204
+ "window.addEventListener(eventName, block, true);"
1205
+ "document.addEventListener(eventName, block, true);"
1189
1206
  "});"
1190
1207
  "})();";
1191
1208
 
@@ -1631,30 +1648,47 @@ void Window::setWebviewDragDropEnabled(bool enabled) {
1631
1648
  // Enable webview drag-drop by removing our prevention handlers
1632
1649
  script = R"(
1633
1650
  (function() {
1634
- if (window.__plusui_dragDropDisabled) {
1635
- delete window.__plusui_dragDropDisabled;
1651
+ var events = window.__plusui_dragDropEvents || ['dragenter', 'dragover', 'dragleave', 'drop'];
1652
+ var blocker = window.__plusui_dragDropBlocker;
1653
+ if (blocker) {
1654
+ events.forEach(function(eventName) {
1655
+ window.removeEventListener(eventName, blocker, true);
1656
+ document.removeEventListener(eventName, blocker, true);
1657
+ });
1636
1658
  }
1659
+ delete window.__plusui_dragDropBlocker;
1660
+ delete window.__plusui_dragDropEvents;
1661
+ delete window.__plusui_dragDropDisabled;
1662
+ delete window.__plusui_nativeFileDropOnly;
1637
1663
  })();
1638
1664
  )";
1639
1665
  } else {
1640
1666
  // Disable webview drag-drop by preventing default behavior
1641
1667
  script = R"(
1642
1668
  (function() {
1643
- if (window.__plusui_dragDropDisabled) return; // Already disabled
1669
+ if (window.__plusui_nativeFileDropOnly) return;
1670
+ window.__plusui_nativeFileDropOnly = true;
1644
1671
  window.__plusui_dragDropDisabled = true;
1645
1672
 
1646
- ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(function(eventName) {
1647
- document.addEventListener(eventName, function(e) {
1648
- if (e.target === document.body || e.target === document.documentElement || e.target === document) {
1649
- e.preventDefault();
1650
- e.stopPropagation();
1651
- }
1652
- }, true);
1673
+ var block = function(e) {
1674
+ if (!e) return false;
1675
+ e.preventDefault();
1676
+ e.stopPropagation();
1677
+ if (typeof e.stopImmediatePropagation === 'function') {
1678
+ e.stopImmediatePropagation();
1679
+ }
1680
+ if (e.dataTransfer) {
1681
+ try { e.dataTransfer.dropEffect = 'none'; } catch (_) {}
1682
+ }
1683
+ return false;
1684
+ };
1685
+
1686
+ window.__plusui_dragDropEvents = ['dragenter', 'dragover', 'dragleave', 'drop'];
1687
+ window.__plusui_dragDropBlocker = block;
1653
1688
 
1654
- window.addEventListener(eventName, function(e) {
1655
- e.preventDefault();
1656
- e.stopPropagation();
1657
- }, true);
1689
+ window.__plusui_dragDropEvents.forEach(function(eventName) {
1690
+ window.addEventListener(eventName, block, true);
1691
+ document.addEventListener(eventName, block, true);
1658
1692
  });
1659
1693
  })();
1660
1694
  )";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.43",
3
+ "version": "0.1.45",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "files": [