plusui-native 0.2.86 → 0.2.87

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,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native",
3
- "version": "0.2.86",
3
+ "version": "0.2.87",
4
4
  "description": "PlusUI CLI - Build C++ desktop apps modern UI ",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -27,11 +27,11 @@
27
27
  "semver": "^7.6.0",
28
28
  "which": "^4.0.0",
29
29
  "execa": "^8.0.1",
30
- "plusui-native-builder": "^0.1.84",
31
- "plusui-native-connect": "^0.1.84"
30
+ "plusui-native-builder": "^0.1.85",
31
+ "plusui-native-connect": "^0.1.85"
32
32
  },
33
33
  "peerDependencies": {
34
- "plusui-native-connect": "^0.1.84"
34
+ "plusui-native-connect": "^0.1.85"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
@@ -1,7 +1,6 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import plusui from 'plusui';
3
- // Generated by `plusui connect` channel objects auto-created from name.on / name.emit usage:
4
- import { customFileDrop } from '../../Connections/connections.gen';
3
+ // Built-in features are exposed directly on the plusui object
5
4
 
6
5
  function App() {
7
6
  const [windowSize, setWindowSize] = useState({ width: 0, height: 0 });
@@ -10,7 +9,7 @@ function App() {
10
9
  const [canGoBack, setCanGoBack] = useState(false);
11
10
  const [canGoForward, setCanGoForward] = useState(false);
12
11
 
13
- // customFileDrop connect channel state
12
+ // Native FileDrop state
14
13
  const [isDragging, setIsDragging] = useState(false);
15
14
  const [droppedFiles, setDroppedFiles] = useState<{ name: string; size: number; type: string }[]>([]);
16
15
  const [backendMsg, setBackendMsg] = useState<string | null>(null);
@@ -38,14 +37,20 @@ function App() {
38
37
  plusui.browser.canGoBack().then(setCanGoBack);
39
38
  plusui.browser.canGoForward().then(setCanGoForward);
40
39
 
41
- // Listen for responses emitted from C++ via ch.customFileDrop.emit(...) in main.cpp
42
- const unsubChannel = customFileDrop.on((data: any) => {
43
- setBackendMsg(data?.message ?? JSON.stringify(data));
40
+ // Listen for native file drops
41
+ const unsubFileDrop = plusui.fileDrop.onFilesDropped((files: any[]) => {
42
+ setDroppedFiles(files);
43
+ setBackendMsg(`Native FileDrop: Received ${files.length} file(s)`);
44
44
  });
45
45
 
46
+ const unsubDragEnter = plusui.fileDrop.onDragEnter(() => setIsDragging(true));
47
+ const unsubDragLeave = plusui.fileDrop.onDragLeave(() => setIsDragging(false));
48
+
46
49
  return () => {
47
50
  unsubNav();
48
- unsubChannel();
51
+ unsubFileDrop();
52
+ unsubDragEnter();
53
+ unsubDragLeave();
49
54
  };
50
55
  }, []);
51
56
 
@@ -69,26 +74,14 @@ function App() {
69
74
  // App control
70
75
  const handleQuit = async () => await plusui.app.quit();
71
76
 
72
- // customFileDrop drag handlers — use HTML5 drag events to collect files, then
73
- // emit them to the C++ backend via the connect channel
74
- const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); setIsDragging(true); };
75
- const handleDragLeave = (e: React.DragEvent) => { e.preventDefault(); setIsDragging(false); };
76
- const handleDrop = (e: React.DragEvent) => {
77
- e.preventDefault();
78
- setIsDragging(false);
79
- const items = Array.from(e.dataTransfer.files).map(f => ({
80
- name: f.name, size: f.size, type: f.type || 'unknown',
81
- }));
82
- setDroppedFiles(items);
83
- setBackendMsg(null);
84
- // Emit to C++ — ch.customFileDrop.on() in main.cpp receives this
85
- customFileDrop.emit({ files: items });
86
- };
77
+ // Native FileDrop handlers
78
+ // The C++ native window automatically detects elements with class 'filedrop-zone'.
79
+ // We do not need HTML5 drag events, the C++ backend emits events directly.
87
80
 
88
81
  return (
89
82
  <div className="app">
90
83
  <header className="app-header">
91
- <h1>{{ PROJECT_NAME }}</h1>
84
+ <h1>{'{{ PROJECT_NAME }}'}</h1>
92
85
  <p>Built with PlusUI Framework</p>
93
86
  </header>
94
87
 
@@ -138,20 +131,16 @@ function App() {
138
131
  </div>
139
132
 
140
133
  <div className="card">
141
- <h2>Custom Channel — File Drop</h2>
134
+ <h2>Native FileDrop API</h2>
142
135
  <p style={{ fontSize: '0.85em', color: '#aaa', marginBottom: '1rem' }}>
143
- Drop files below. The frontend calls <code>customFileDrop.emit()</code> to send file
144
- info to C++. The C++ handler calls <code>ch.customFileDrop.emit()</code> to reply.
145
- The frontend receives the reply via <code>customFileDrop.on()</code>. Run{' '}
146
- <code>plusui connect</code> to regenerate the channel bindings from both sides.
136
+ Drop files below. The <code>plusui.fileDrop</code> API is handled natively in C++
137
+ which overrides standard browser drag-and-drop. It automatically detects elements
138
+ with the <code>.filedrop-zone</code> class or <code>data-dropzone="true"</code>.
147
139
  </p>
148
140
 
149
141
  <div
150
142
  className={`filedrop-zone ${isDragging ? 'filedrop-active' : ''}`}
151
- onDragOver={handleDragOver}
152
- onDragEnter={handleDragOver}
153
- onDragLeave={handleDragLeave}
154
- onDrop={handleDrop}
143
+ data-dropzone="true"
155
144
  >
156
145
  <div className="filedrop-content">
157
146
  <svg className="filedrop-icon" fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -200,25 +200,22 @@ int main() {
200
200
  initChannels(conn);
201
201
 
202
202
  // ========================================
203
- // CUSTOM FILE DROP CHANNEL
203
+ // NATIVE FILE DROP
204
204
  // ========================================
205
- // customFileDrop is a connect channel detected by `plusui connect`.
206
- // Frontend drops files emits via customFileDrop.emit({ files: [...] })
207
- // C++ receives here, processes, then emits back to the frontend.
208
- // Frontend receives the reply via customFileDrop.on() in App.tsx.
209
- customFileDrop.on([](const json& payload) {
210
- auto files = payload.value("files", json::array());
211
- int count = static_cast<int>(files.size());
212
- std::cout << "customFileDrop: received " << count << " file(s) from frontend" << std::endl;
213
- for (const auto& f : files) {
214
- std::cout << " - " << f.value("name", "?") << " (" << f.value("size", 0) << " bytes)" << std::endl;
205
+ // The PlusUI native file drop feature is enabled in WindowConfig.
206
+ // Frontend dropped files are automatically passed to C++ as JSON.
207
+ // Frontend also receives the 'plusui:fileDrop.filesDropped' event automatically.
208
+ mainWindow.onFileDrop([](const std::string& filesJson) {
209
+ try {
210
+ auto files = json::parse(filesJson);
211
+ int count = static_cast<int>(files.size());
212
+ std::cout << "Native FileDrop: received " << count << " file(s)" << std::endl;
213
+ for (const auto& f : files) {
214
+ std::cout << " - " << f.value("name", "?") << " (" << f.value("size", 0) << " bytes)" << std::endl;
215
+ }
216
+ } catch (const std::exception& e) {
217
+ std::cout << "Native FileDrop Error: " << e.what() << std::endl;
215
218
  }
216
- // Reply back to frontend — received by customFileDrop.on() in App.tsx
217
- customFileDrop.emit({
218
- {"processed", true},
219
- {"count", count},
220
- {"message", "C++ received " + std::to_string(count) + " file(s)"}
221
- });
222
219
  });
223
220
 
224
221
  // ========================================
@@ -1,7 +1,6 @@
1
1
  import { createSignal, onMount, onCleanup, Show, For } from 'solid-js';
2
2
  import plusui from 'plusui';
3
- // Generated by `plusui connect` channel objects auto-created from name.on / name.emit usage:
4
- import { customFileDrop } from '../../Connections/connections.gen';
3
+ // Built-in features are exposed directly on the plusui object
5
4
 
6
5
  function App() {
7
6
  const [windowSize, setWindowSize] = createSignal({ width: 0, height: 0 });
@@ -10,7 +9,7 @@ function App() {
10
9
  const [canGoBack, setCanGoBack] = createSignal(false);
11
10
  const [canGoForward, setCanGoForward] = createSignal(false);
12
11
 
13
- // customFileDrop connect channel state
12
+ // Native FileDrop state
14
13
  const [isDragging, setIsDragging] = createSignal(false);
15
14
  const [droppedFiles, setDroppedFiles] = createSignal<{ name: string; size: number; type: string }[]>([]);
16
15
  const [backendMsg, setBackendMsg] = createSignal<string | null>(null);
@@ -34,14 +33,20 @@ function App() {
34
33
  plusui.browser.canGoBack().then(setCanGoBack);
35
34
  plusui.browser.canGoForward().then(setCanGoForward);
36
35
 
37
- // Listen for responses emitted from C++ via ch.customFileDrop.emit(...) in main.cpp
38
- const unsubFileDrop = customFileDrop.on((data: any) => {
39
- setBackendMsg(data?.message ?? JSON.stringify(data));
36
+ // Listen for native file drops
37
+ const unsubFileDrop = plusui.fileDrop.onFilesDropped((files: any[]) => {
38
+ setDroppedFiles(files);
39
+ setBackendMsg(`Native FileDrop: Received ${files.length} file(s)`);
40
40
  });
41
41
 
42
+ const unsubDragEnter = plusui.fileDrop.onDragEnter(() => setIsDragging(true));
43
+ const unsubDragLeave = plusui.fileDrop.onDragLeave(() => setIsDragging(false));
44
+
42
45
  onCleanup(() => {
43
46
  unsubNav();
44
47
  unsubFileDrop();
48
+ unsubDragEnter();
49
+ unsubDragLeave();
45
50
  });
46
51
  });
47
52
 
@@ -65,26 +70,14 @@ function App() {
65
70
  // App control
66
71
  const handleQuit = async () => await plusui.app.quit();
67
72
 
68
- // customFileDrop drag handlers — use HTML5 drag events to collect files, then
69
- // emit them to the C++ backend via the connect channel
70
- const handleDragOver = (e: DragEvent) => { e.preventDefault(); setIsDragging(true); };
71
- const handleDragLeave = (e: DragEvent) => { e.preventDefault(); setIsDragging(false); };
72
- const handleDrop = (e: DragEvent) => {
73
- e.preventDefault();
74
- setIsDragging(false);
75
- const items = Array.from(e.dataTransfer?.files ?? []).map(f => ({
76
- name: f.name, size: f.size, type: f.type || 'unknown',
77
- }));
78
- setDroppedFiles(items);
79
- setBackendMsg(null);
80
- // Emit to C++ — ch.customFileDrop.on() in main.cpp receives this
81
- customFileDrop.emit({ files: items });
82
- };
73
+ // Native FileDrop handlers
74
+ // The C++ native window automatically detects elements with class 'filedrop-zone'.
75
+ // We do not need HTML5 drag events, the C++ backend emits events directly.
83
76
 
84
77
  return (
85
78
  <div class="app">
86
79
  <header class="app-header">
87
- <h1>{{ PROJECT_NAME }} App</h1>
80
+ <h1>{'{{ PROJECT_NAME }}'} App</h1>
88
81
  <p>Built with PlusUI Framework</p>
89
82
  </header>
90
83
 
@@ -134,20 +127,16 @@ function App() {
134
127
  </div>
135
128
 
136
129
  <div class="card">
137
- <h2>Custom Channel — File Drop</h2>
130
+ <h2>Native FileDrop API</h2>
138
131
  <p style={{ 'font-size': '0.85em', color: '#aaa', 'margin-bottom': '1rem' }}>
139
- Drop files below. The frontend calls <code>customFileDrop.emit()</code> to send file
140
- info to C++. The C++ handler calls <code>ch.customFileDrop.emit()</code> to reply.
141
- The frontend receives the reply via <code>customFileDrop.on()</code>. Run{' '}
142
- <code>plusui connect</code> to regenerate the channel bindings from both sides.
132
+ Drop files below. The <code>plusui.fileDrop</code> API is handled natively in C++
133
+ which overrides standard browser drag-and-drop. It automatically detects elements
134
+ with the <code>.filedrop-zone</code> class or <code>data-dropzone="true"</code>.
143
135
  </p>
144
136
 
145
137
  <div
146
138
  class={`filedrop-zone ${isDragging() ? 'filedrop-active' : ''}`}
147
- onDragOver={handleDragOver}
148
- onDragEnter={handleDragOver}
149
- onDragLeave={handleDragLeave}
150
- onDrop={handleDrop}
139
+ data-dropzone="true"
151
140
  >
152
141
  <div class="filedrop-content">
153
142
  <svg class="filedrop-icon" fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -194,25 +194,22 @@ int main() {
194
194
  initChannels(conn);
195
195
 
196
196
  // ========================================
197
- // CUSTOM FILE DROP CHANNEL
197
+ // NATIVE FILE DROP
198
198
  // ========================================
199
- // customFileDrop is a connect channel detected by `plusui connect`.
200
- // Frontend drops files emits via customFileDrop.emit({ files: [...] })
201
- // C++ receives here, processes, then emits back to the frontend.
202
- // Frontend receives the reply via customFileDrop.on() in App.tsx.
203
- customFileDrop.on([](const json& payload) {
204
- auto files = payload.value("files", json::array());
205
- int count = static_cast<int>(files.size());
206
- std::cout << "customFileDrop: received " << count << " file(s) from frontend" << std::endl;
207
- for (const auto& f : files) {
208
- std::cout << " - " << f.value("name", "?") << " (" << f.value("size", 0) << " bytes)" << std::endl;
199
+ // The PlusUI native file drop feature is enabled in WindowConfig.
200
+ // Frontend dropped files are automatically passed to C++ as JSON.
201
+ // Frontend also receives the 'plusui:fileDrop.filesDropped' event automatically.
202
+ mainWindow.onFileDrop([](const std::string& filesJson) {
203
+ try {
204
+ auto files = json::parse(filesJson);
205
+ int count = static_cast<int>(files.size());
206
+ std::cout << "Native FileDrop: received " << count << " file(s)" << std::endl;
207
+ for (const auto& f : files) {
208
+ std::cout << " - " << f.value("name", "?") << " (" << f.value("size", 0) << " bytes)" << std::endl;
209
+ }
210
+ } catch (const std::exception& e) {
211
+ std::cout << "Native FileDrop Error: " << e.what() << std::endl;
209
212
  }
210
- // Reply back to frontend — received by customFileDrop.on() in App.tsx
211
- customFileDrop.emit({
212
- {"processed", true},
213
- {"count", count},
214
- {"message", "C++ received " + std::to_string(count) + " file(s)"}
215
- });
216
213
  });
217
214
 
218
215
  // ========================================