react-x11 2.43.0 → 2.44.0

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": "react-x11",
3
- "version": "2.43.0",
3
+ "version": "2.44.0",
4
4
  "description": "react renderer with X11 as a target",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -104,7 +104,7 @@
104
104
  "ical.js": "^2.2.1",
105
105
  "image-in-browser": "^3.6.0",
106
106
  "linebreak": "^1.1.0",
107
- "ntk": "^8.23.0",
107
+ "ntk": "^8.23.2",
108
108
  "react-reconciler": "^0.34.0",
109
109
  "yoga-layout": "^3.2.1"
110
110
  },
package/src/cocoa/app.js CHANGED
@@ -44,6 +44,7 @@ import { CocoaPlayer, canPlay } from './player.js';
44
44
  import { CocoaSurface } from './surface.js';
45
45
  import { CocoaSymbols } from './symbols.js';
46
46
  import { CocoaWindow, FRAME_SLACK_MS } from './window.js';
47
+ import { utiFromMime, wire } from './dnd.js';
47
48
  import { decodeKey, modifierMask } from './keymap.js';
48
49
  import { loadNative } from './native.js';
49
50
  import { requestAppKit, threadedChannel } from './threaded.js';
@@ -409,13 +410,53 @@ export class CocoaApp {
409
410
  // (docs/clipboard.md, "Two clipboards").
410
411
  const isClipboard = (selection = 'CLIPBOARD') => selection === 'CLIPBOARD';
411
412
  this.clipboard = {
413
+ // A write is one pasteboard item with every flavour under its UTI —
414
+ // dnd.js's table, then the system's — the way a drag offers its
415
+ // payload. Text alone keeps pasteboardWriteText, the verb every
416
+ // bridge has; anything else needs pasteboardWrite (windowkit/appkit
417
+ // #119), and a bridge without it keeps the text and says, once, what
418
+ // it dropped — an image that silently never reaches the pasteboard
419
+ // looks like a Copy that did nothing.
412
420
  write: (data, { selection } = {}) => {
413
421
  if (!isClipboard(selection)) return Promise.resolve();
422
+ if (typeof data === 'string') {
423
+ native.pasteboardWriteText(data);
424
+ return Promise.resolve();
425
+ }
426
+ const item = {};
427
+ for (const [type, value] of Object.entries(data ?? {})) {
428
+ const uti = utiFromMime(type, native);
429
+ if (uti && value != null && !(uti in item)) item[uti] = wire(value);
430
+ }
431
+ const TEXT = 'public.utf8-plain-text';
432
+ const raw = item[TEXT];
414
433
  const text =
415
- typeof data === 'string'
416
- ? data
417
- : (data?.UTF8_STRING ?? data?.STRING ?? '');
418
- native.pasteboardWriteText(String(text));
434
+ raw == null
435
+ ? ''
436
+ : typeof raw === 'string'
437
+ ? raw
438
+ : Buffer.from(raw).toString('utf8');
439
+ const others = Object.keys(item).filter((uti) => uti !== TEXT);
440
+ if (others.length === 0) {
441
+ native.pasteboardWriteText(text);
442
+ } else if (typeof native.pasteboardWrite === 'function') {
443
+ native.pasteboardWrite(item);
444
+ } else {
445
+ if (
446
+ !this._warnedPasteboardFlavours &&
447
+ process.env.NODE_ENV !== 'production'
448
+ ) {
449
+ this._warnedPasteboardFlavours = true;
450
+ console.warn(
451
+ `react-x11: clipboard.write() kept only the text — this ` +
452
+ `@windowkit/appkit has no pasteboardWrite, so ` +
453
+ `${others.join(', ')} did not reach the pasteboard. ` +
454
+ 'Update @windowkit/appkit to a release with pasteboardWrite ' +
455
+ '(windowkit/appkit#119).',
456
+ );
457
+ }
458
+ native.pasteboardWriteText(text);
459
+ }
419
460
  return Promise.resolve();
420
461
  },
421
462
  clear: (selection) => {
package/src/cocoa/dnd.js CHANGED
@@ -208,7 +208,7 @@ export function readPayload(native, types, carried = null) {
208
208
 
209
209
  /** A value as the pasteboard carries it: strings and bytes as they are,
210
210
  * anything else as JSON — the same rule the X transport applies. */
211
- const wire = (value) =>
211
+ export const wire = (value) =>
212
212
  typeof value === 'string' ||
213
213
  Buffer.isBuffer(value) ||
214
214
  ArrayBuffer.isView(value) ||