craft-native 0.0.123 → 0.0.125
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/README.md +3 -0
- package/dist/android/src/index.d.ts +3 -0
- package/dist/android/src/index.js +22 -3
- package/dist/android/templates/AndroidManifest.xml.template +1 -1
- package/dist/android/templates/CraftNativeFlatList.kt.template +151 -7
- package/dist/android/templates/CraftNativeRefreshableFlatList.kt.template +29 -0
- package/dist/android/templates/MainActivity.kt.template +17 -0
- package/dist/android/templates/MainActivityNative.kt.template +1085 -84
- package/dist/android/templates/build.gradle.kts.app.template +1 -0
- package/dist/api/mobile.d.ts +250 -2
- package/dist/cli.js +3 -3
- package/dist/index.cjs +22 -1
- package/dist/index.js +22 -1
- package/dist/ios/src/index.d.ts +125 -3
- package/dist/ios/src/index.js +284 -47
- package/dist/ios/templates/CraftApp.swift +1186 -69
- package/dist/ios/templates/CraftHybrid.swift +1196 -0
- package/dist/ios/templates/CraftNativeActions.swift +310 -10
- package/dist/ios/templates/CraftNativeFlatList.swift +226 -17
- package/dist/ios/templates/CraftNativeScreen.swift +2217 -220
- package/dist/ios/templates/CraftNativeUI.swift +562 -0
- package/dist/ios/templates/Info.plist.template +2 -1
- package/dist/mobile.js +204 -0
- package/package.json +1 -1
package/dist/mobile.js
CHANGED
|
@@ -139,6 +139,14 @@ var haptics = {
|
|
|
139
139
|
navigator.vibrate(5);
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
|
+
async prepare(kind) {
|
|
143
|
+
const craft = getCraftMobile();
|
|
144
|
+
if (typeof window !== "undefined" && craft?.haptics?.prepare) {
|
|
145
|
+
try {
|
|
146
|
+
await craft.haptics.prepare(kind);
|
|
147
|
+
} catch {}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
142
150
|
async vibrate(pattern) {
|
|
143
151
|
const craft = getCraftMobile();
|
|
144
152
|
if (typeof window !== "undefined" && craft?.haptics) {
|
|
@@ -510,6 +518,12 @@ var lifecycle = {
|
|
|
510
518
|
};
|
|
511
519
|
document.addEventListener("visibilitychange", handler);
|
|
512
520
|
return () => document.removeEventListener("visibilitychange", handler);
|
|
521
|
+
},
|
|
522
|
+
onResume(callback) {
|
|
523
|
+
return onCraftEvent("craftResume", (detail) => callback({ backgroundedMs: Number(detail.backgroundedMs) || 0 }));
|
|
524
|
+
},
|
|
525
|
+
onMemoryWarning(callback) {
|
|
526
|
+
return onCraftEvent("craftMemoryWarning", () => callback());
|
|
513
527
|
}
|
|
514
528
|
};
|
|
515
529
|
function bridgeNotification(options, now = Date.now()) {
|
|
@@ -748,6 +762,184 @@ var splash = {
|
|
|
748
762
|
return postChrome({ type: "ready" });
|
|
749
763
|
}
|
|
750
764
|
};
|
|
765
|
+
function hybridHandler() {
|
|
766
|
+
if (typeof window === "undefined")
|
|
767
|
+
return null;
|
|
768
|
+
const handler = window.webkit?.messageHandlers?.craftHybrid;
|
|
769
|
+
return handler && typeof handler.postMessage === "function" ? handler : null;
|
|
770
|
+
}
|
|
771
|
+
function postHybrid(message) {
|
|
772
|
+
const handler = hybridHandler();
|
|
773
|
+
if (!handler)
|
|
774
|
+
return false;
|
|
775
|
+
try {
|
|
776
|
+
handler.postMessage(message);
|
|
777
|
+
return true;
|
|
778
|
+
} catch {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function isSnapshotName(name) {
|
|
783
|
+
return typeof name === "string" && /^[A-Za-z0-9_-][\w.-]{0,127}$/.test(name);
|
|
784
|
+
}
|
|
785
|
+
var snapshots = {
|
|
786
|
+
isAvailable() {
|
|
787
|
+
return hybridHandler() !== null;
|
|
788
|
+
},
|
|
789
|
+
set(name, value) {
|
|
790
|
+
if (!isSnapshotName(name))
|
|
791
|
+
throw new TypeError(`Snapshot names are letters, digits, ".", "_" and "-": ${String(name)}`);
|
|
792
|
+
const json = JSON.stringify(value);
|
|
793
|
+
if (json === undefined)
|
|
794
|
+
throw new TypeError(`Snapshot ${name} is not JSON`);
|
|
795
|
+
return postHybrid({ type: "snapshotSet", name, json });
|
|
796
|
+
},
|
|
797
|
+
remove(name) {
|
|
798
|
+
if (!isSnapshotName(name))
|
|
799
|
+
return false;
|
|
800
|
+
return postHybrid({ type: "snapshotRemove", name });
|
|
801
|
+
},
|
|
802
|
+
clear() {
|
|
803
|
+
return postHybrid({ type: "snapshotClear" });
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
function hybridPage() {
|
|
807
|
+
if (typeof window === "undefined")
|
|
808
|
+
return;
|
|
809
|
+
const page = window.__craftHybrid;
|
|
810
|
+
return page && typeof page.match === "function" ? page : undefined;
|
|
811
|
+
}
|
|
812
|
+
var hybrid = {
|
|
813
|
+
isActive() {
|
|
814
|
+
return hybridHandler() !== null;
|
|
815
|
+
},
|
|
816
|
+
nativeScreenFor(path) {
|
|
817
|
+
return hybridPage()?.match(path) ?? null;
|
|
818
|
+
},
|
|
819
|
+
open(path) {
|
|
820
|
+
if (typeof path !== "string" || !path.startsWith("/"))
|
|
821
|
+
throw new TypeError(`hybrid.open needs an app path: ${String(path)}`);
|
|
822
|
+
return postHybrid({ type: "open", path });
|
|
823
|
+
},
|
|
824
|
+
back() {
|
|
825
|
+
return postHybrid({ type: "back" });
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
async function callNative(namespace, method, args, fallback) {
|
|
829
|
+
const target = getCraftRoot()?.[namespace];
|
|
830
|
+
if (!target || typeof target[method] !== "function")
|
|
831
|
+
return fallback;
|
|
832
|
+
try {
|
|
833
|
+
const value = await target[method](...args);
|
|
834
|
+
return value === undefined || value === null ? fallback : value;
|
|
835
|
+
} catch {
|
|
836
|
+
return fallback;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
function hasNative(namespace) {
|
|
840
|
+
return Boolean(getCraftRoot()?.[namespace]);
|
|
841
|
+
}
|
|
842
|
+
var dialog = {
|
|
843
|
+
isAvailable() {
|
|
844
|
+
return hasNative("dialog");
|
|
845
|
+
},
|
|
846
|
+
async alert(options) {
|
|
847
|
+
await callNative("dialog", "alert", [options], undefined);
|
|
848
|
+
},
|
|
849
|
+
confirm(options) {
|
|
850
|
+
return callNative("dialog", "confirm", [options], false);
|
|
851
|
+
},
|
|
852
|
+
actionSheet(options) {
|
|
853
|
+
return callNative("dialog", "actionSheet", [options], null);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
var contextMenu = {
|
|
857
|
+
isAvailable() {
|
|
858
|
+
return hasNative("contextMenu");
|
|
859
|
+
},
|
|
860
|
+
show(options) {
|
|
861
|
+
return callNative("contextMenu", "show", [options], null);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var browser = {
|
|
865
|
+
isAvailable() {
|
|
866
|
+
return hasNative("browser");
|
|
867
|
+
},
|
|
868
|
+
async open(url, options = {}) {
|
|
869
|
+
if (hasNative("browser"))
|
|
870
|
+
return callNative("browser", "open", [url, options], { cancelled: true });
|
|
871
|
+
if (options.mode !== "auth" && typeof window !== "undefined" && typeof window.open === "function") {
|
|
872
|
+
window.open(url, "_blank", "noopener");
|
|
873
|
+
return { cancelled: false };
|
|
874
|
+
}
|
|
875
|
+
return { cancelled: true };
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
var symbols = {
|
|
879
|
+
image(name, options = {}) {
|
|
880
|
+
return callNative("symbols", "image", [name, options], null);
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
var statusBar = {
|
|
884
|
+
setStyle(style) {
|
|
885
|
+
return callNative("statusBar", "setStyle", [style], false);
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
var chrome = {
|
|
889
|
+
setUnderPageColor(color) {
|
|
890
|
+
return callNative("chrome", "setUnderPageColor", [color], false);
|
|
891
|
+
},
|
|
892
|
+
setKeyboardAccessory(visible) {
|
|
893
|
+
return callNative("chrome", "setKeyboardAccessory", [visible], false);
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
var refresh = {
|
|
897
|
+
isAvailable() {
|
|
898
|
+
return hasNative("refresh");
|
|
899
|
+
},
|
|
900
|
+
enable(options = {}) {
|
|
901
|
+
return callNative("refresh", "enable", [options], false);
|
|
902
|
+
},
|
|
903
|
+
disable() {
|
|
904
|
+
return callNative("refresh", "disable", [], false);
|
|
905
|
+
},
|
|
906
|
+
end() {
|
|
907
|
+
return callNative("refresh", "end", [], false);
|
|
908
|
+
},
|
|
909
|
+
onRefresh(callback) {
|
|
910
|
+
return onCraftEvent("craftRefresh", () => callback());
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
var background = {
|
|
914
|
+
complete(ok = true, id) {
|
|
915
|
+
return callNative("background", "complete", [ok, id], false);
|
|
916
|
+
},
|
|
917
|
+
onRefresh(callback) {
|
|
918
|
+
return onCraftEvent("craftBackgroundRefresh", (detail) => callback(detail));
|
|
919
|
+
},
|
|
920
|
+
onSilentPush(callback) {
|
|
921
|
+
return onCraftEvent("craftSilentPush", (detail) => callback(detail));
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
var appearance = {
|
|
925
|
+
get() {
|
|
926
|
+
const native = getCraftRoot()?.appearance;
|
|
927
|
+
if (native)
|
|
928
|
+
return native;
|
|
929
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function")
|
|
930
|
+
return null;
|
|
931
|
+
return {
|
|
932
|
+
contentSizeCategory: "large",
|
|
933
|
+
fontScale: 1,
|
|
934
|
+
reduceMotion: window.matchMedia("(prefers-reduced-motion: reduce)").matches,
|
|
935
|
+
reduceTransparency: window.matchMedia("(prefers-reduced-transparency: reduce)").matches,
|
|
936
|
+
colorScheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
|
937
|
+
};
|
|
938
|
+
},
|
|
939
|
+
onChange(callback) {
|
|
940
|
+
return onCraftEvent("craftAppearance", (detail) => callback(detail));
|
|
941
|
+
}
|
|
942
|
+
};
|
|
751
943
|
var appReview = {
|
|
752
944
|
async request() {
|
|
753
945
|
const craft = getCraftRoot();
|
|
@@ -927,10 +1119,14 @@ function getCraftMobile() {
|
|
|
927
1119
|
export {
|
|
928
1120
|
watchConnectivity,
|
|
929
1121
|
tabBar,
|
|
1122
|
+
symbols,
|
|
1123
|
+
statusBar,
|
|
930
1124
|
splash,
|
|
931
1125
|
speech,
|
|
1126
|
+
snapshots,
|
|
932
1127
|
share,
|
|
933
1128
|
secureStorage,
|
|
1129
|
+
refresh,
|
|
934
1130
|
pushNotifications,
|
|
935
1131
|
permissions,
|
|
936
1132
|
notifications,
|
|
@@ -940,13 +1136,21 @@ export {
|
|
|
940
1136
|
liveActivities,
|
|
941
1137
|
lifecycle,
|
|
942
1138
|
keepAwake,
|
|
1139
|
+
isSnapshotName,
|
|
1140
|
+
hybrid,
|
|
943
1141
|
health,
|
|
944
1142
|
haptics,
|
|
1143
|
+
dialog,
|
|
945
1144
|
device,
|
|
946
1145
|
deepLinks,
|
|
1146
|
+
contextMenu,
|
|
1147
|
+
chrome,
|
|
947
1148
|
camera,
|
|
1149
|
+
browser,
|
|
948
1150
|
bridgeNotification,
|
|
949
1151
|
biometrics,
|
|
1152
|
+
background,
|
|
1153
|
+
appearance,
|
|
950
1154
|
appReview,
|
|
951
1155
|
_webFallbackDeviceId,
|
|
952
1156
|
_resetWebFallbackDeviceIdForTests
|