plusui-native-core 0.1.42 → 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
 
@@ -1299,29 +1316,6 @@ void Window::navigate(const std::string &url) {
1299
1316
  webkit_web_view_load_uri(pImpl->gtkWebView, url.c_str());
1300
1317
  }
1301
1318
  #endif
1302
-
1303
- // Apply scrollbar hiding CSS if configured
1304
- if (!pImpl->config.scrollbars) {
1305
- std::string hideScrollbars = kHideScrollbarsScript;
1306
- // Schedule this to run after a short delay to ensure DOM is ready
1307
- #ifdef _WIN32
1308
- if (pImpl->ready && pImpl->webview) {
1309
- pImpl->webview->ExecuteScript(
1310
- std::wstring(hideScrollbars.begin(), hideScrollbars.end()).c_str(),
1311
- nullptr);
1312
- }
1313
- #elif defined(__APPLE__)
1314
- if (pImpl->wkWebView) {
1315
- NSString *js = [NSString stringWithUTF8String:hideScrollbars.c_str()];
1316
- [pImpl->wkWebView evaluateJavaScript:js completionHandler:nil];
1317
- }
1318
- #else
1319
- if (pImpl->gtkWebView) {
1320
- webkit_web_view_run_javascript(pImpl->gtkWebView, hideScrollbars.c_str(),
1321
- nullptr, nullptr, nullptr);
1322
- }
1323
- #endif
1324
- }
1325
1319
  }
1326
1320
 
1327
1321
  void Window::loadURL(const std::string &url) {
@@ -1654,30 +1648,47 @@ void Window::setWebviewDragDropEnabled(bool enabled) {
1654
1648
  // Enable webview drag-drop by removing our prevention handlers
1655
1649
  script = R"(
1656
1650
  (function() {
1657
- if (window.__plusui_dragDropDisabled) {
1658
- 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
+ });
1659
1658
  }
1659
+ delete window.__plusui_dragDropBlocker;
1660
+ delete window.__plusui_dragDropEvents;
1661
+ delete window.__plusui_dragDropDisabled;
1662
+ delete window.__plusui_nativeFileDropOnly;
1660
1663
  })();
1661
1664
  )";
1662
1665
  } else {
1663
1666
  // Disable webview drag-drop by preventing default behavior
1664
1667
  script = R"(
1665
1668
  (function() {
1666
- if (window.__plusui_dragDropDisabled) return; // Already disabled
1669
+ if (window.__plusui_nativeFileDropOnly) return;
1670
+ window.__plusui_nativeFileDropOnly = true;
1667
1671
  window.__plusui_dragDropDisabled = true;
1668
1672
 
1669
- ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(function(eventName) {
1670
- document.addEventListener(eventName, function(e) {
1671
- if (e.target === document.body || e.target === document.documentElement || e.target === document) {
1672
- e.preventDefault();
1673
- e.stopPropagation();
1674
- }
1675
- }, 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;
1676
1688
 
1677
- window.addEventListener(eventName, function(e) {
1678
- e.preventDefault();
1679
- e.stopPropagation();
1680
- }, true);
1689
+ window.__plusui_dragDropEvents.forEach(function(eventName) {
1690
+ window.addEventListener(eventName, block, true);
1691
+ document.addEventListener(eventName, block, true);
1681
1692
  });
1682
1693
  })();
1683
1694
  )";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "files": [