craft-native 0.0.91 → 0.0.94

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/dist/mobile.js CHANGED
@@ -457,11 +457,18 @@ var share = {
457
457
  return craft.share.share(options);
458
458
  }
459
459
  if (navigator.share) {
460
- await navigator.share({
461
- title: options.title,
462
- text: options.text,
463
- url: options.url
464
- });
460
+ try {
461
+ await navigator.share({
462
+ title: options.title,
463
+ text: options.text,
464
+ url: options.url
465
+ });
466
+ return true;
467
+ } catch (error) {
468
+ if (error instanceof DOMException && error.name === "AbortError")
469
+ return false;
470
+ throw error;
471
+ }
465
472
  } else {
466
473
  throw new Error("Share API not available");
467
474
  }
@@ -494,6 +501,13 @@ var lifecycle = {
494
501
  return () => document.removeEventListener("visibilitychange", handler);
495
502
  }
496
503
  };
504
+ function bridgeNotification(options, now = Date.now()) {
505
+ const { scheduleAt, ...rest } = options;
506
+ if (scheduleAt === undefined)
507
+ return rest;
508
+ const wait = Math.ceil(scheduleAt - now);
509
+ return wait > 0 ? { ...rest, delay: wait } : rest;
510
+ }
497
511
  var notifications = {
498
512
  async show(options) {
499
513
  const craft = getCraftMobile();
@@ -507,7 +521,7 @@ var notifications = {
507
521
  async schedule(options) {
508
522
  const craft = getCraftMobile();
509
523
  if (typeof window !== "undefined" && craft?.notifications) {
510
- return craft.notifications.schedule(options);
524
+ return craft.notifications.schedule(bridgeNotification(options));
511
525
  }
512
526
  throw new Error("Scheduled notifications not available in web");
513
527
  },
@@ -555,15 +569,16 @@ var deepLinks = {
555
569
  return craft.deepLinks.onLink((value) => {
556
570
  const url = normalizeDeepLinkURL(value);
557
571
  if (url)
558
- callback(url);
572
+ callback(url, { initial: value?.initial === true });
559
573
  }) ?? (() => {});
560
574
  }
561
575
  if (typeof globalThis === "undefined")
562
576
  return () => {};
563
577
  const listener = (event) => {
564
- const url = normalizeDeepLinkURL(event.detail);
578
+ const detail = event.detail;
579
+ const url = normalizeDeepLinkURL(detail);
565
580
  if (url)
566
- callback(url);
581
+ callback(url, { initial: detail?.initial === true });
567
582
  };
568
583
  globalThis.addEventListener("craftDeepLink", listener);
569
584
  return () => globalThis.removeEventListener("craftDeepLink", listener);
@@ -623,7 +638,22 @@ var pushNotifications = {
623
638
  return onCraftEvent("craftPushToken", (detail) => callback(String(detail.token ?? "")));
624
639
  },
625
640
  onNotification(callback) {
641
+ const craft = getCraftRoot();
642
+ if (craft?.notifications?.onTap) {
643
+ return craft.notifications.onTap((detail) => {
644
+ callback(detail ?? {});
645
+ }) ?? (() => {});
646
+ }
626
647
  return onCraftEvent("craftNotificationResponse", (detail) => callback(detail));
648
+ },
649
+ onReceive(callback) {
650
+ const craft = getCraftRoot();
651
+ if (craft?.notifications?.onReceive) {
652
+ return craft.notifications.onReceive((detail) => {
653
+ callback(detail ?? {});
654
+ }) ?? (() => {});
655
+ }
656
+ return onCraftEvent("craftNotificationReceived", (detail) => callback(detail));
627
657
  }
628
658
  };
629
659
  var health = {
@@ -771,6 +801,7 @@ export {
771
801
  device,
772
802
  deepLinks,
773
803
  camera,
804
+ bridgeNotification,
774
805
  biometrics,
775
806
  appReview,
776
807
  _webFallbackDeviceId,
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.91",
3
+ "version": "0.0.94",
4
4
  "type": "module",
5
5
  "description": "Build desktop apps with web languages - TypeScript SDK for Craft",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
@@ -94,6 +94,6 @@
94
94
  "@stacksjs/clapp": "^0.2.0",
95
95
  "@types/bun": "^1.2.0",
96
96
  "@types/node": "^22.0.0",
97
- "better-dx": "^0.2.7"
97
+ "better-dx": "^0.2.25"
98
98
  }
99
99
  }