plusui-native-core 0.1.43 → 0.1.44

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
@@ -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.44",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "files": [