craft-native 0.0.107 → 0.0.110

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/cli.js CHANGED
@@ -3303,7 +3303,7 @@ function pinCraftNativeDependency(packagePath, craftVersion) {
3303
3303
  `);
3304
3304
  }
3305
3305
  // package.json
3306
- var version = "0.0.107";
3306
+ var version = "0.0.110";
3307
3307
 
3308
3308
  // bin/cli.ts
3309
3309
  var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
package/dist/index.cjs CHANGED
@@ -310,7 +310,7 @@ function craftBinaryNotFoundMessage(triedPath) {
310
310
  `);
311
311
  }
312
312
  // package.json
313
- var version = "0.0.107";
313
+ var version = "0.0.110";
314
314
 
315
315
  // src/sdk-version.ts
316
316
  var SDK_VERSION = version;
package/dist/index.d.cts CHANGED
@@ -81,4 +81,4 @@ export declare function show(html: string, options?: WindowOptions): Promise<voi
81
81
  * Quick helper to load a URL
82
82
  */
83
83
  export declare function loadURL(url: string, options?: WindowOptions): Promise<void>;
84
- export type { WindowOptions, CraftSidebarAPI, AppConfig, CraftTrayAPI, CraftWindowAPI, CraftAppAPI, CraftBridgeAPI, Permission, HapticType, CameraOptions, PhotoPickerOptions, CraftMobileAPI, CraftFileSystemAPI, CraftDatabaseAPI, CraftHttpAPI, CraftCryptoAPI, CraftCapabilities, CapabilityNamespace, CapabilityNamespaceStatus, CapabilityAction, CraftPreferencesAPI, CraftPreferencesInfo, CraftSettingsAPI, PreferenceValue, CraftEventType, CraftEventMap, CraftEventHandler, CraftEventEmitter, IOSConfig, AndroidConfig, MacOSConfig, WindowsConfig, LinuxConfig, CraftAppConfig, } from './types.js';
84
+ export type { WindowOptions, CraftSidebarAPI, CraftNativeUIAPI, CraftContextMenuItem, CraftContextMenuResult, AppConfig, CraftTrayAPI, CraftWindowAPI, CraftAppAPI, CraftBridgeAPI, Permission, HapticType, CameraOptions, PhotoPickerOptions, CraftMobileAPI, CraftFileSystemAPI, CraftDatabaseAPI, CraftHttpAPI, CraftCryptoAPI, CraftCapabilities, CapabilityNamespace, CapabilityNamespaceStatus, CapabilityAction, CraftPreferencesAPI, CraftPreferencesInfo, CraftSettingsAPI, PreferenceValue, CraftEventType, CraftEventMap, CraftEventHandler, CraftEventEmitter, IOSConfig, AndroidConfig, MacOSConfig, WindowsConfig, LinuxConfig, CraftAppConfig, } from './types.js';
package/dist/index.d.ts CHANGED
@@ -81,4 +81,4 @@ export declare function show(html: string, options?: WindowOptions): Promise<voi
81
81
  * Quick helper to load a URL
82
82
  */
83
83
  export declare function loadURL(url: string, options?: WindowOptions): Promise<void>;
84
- export type { WindowOptions, CraftSidebarAPI, AppConfig, CraftTrayAPI, CraftWindowAPI, CraftAppAPI, CraftBridgeAPI, Permission, HapticType, CameraOptions, PhotoPickerOptions, CraftMobileAPI, CraftFileSystemAPI, CraftDatabaseAPI, CraftHttpAPI, CraftCryptoAPI, CraftCapabilities, CapabilityNamespace, CapabilityNamespaceStatus, CapabilityAction, CraftPreferencesAPI, CraftPreferencesInfo, CraftSettingsAPI, PreferenceValue, CraftEventType, CraftEventMap, CraftEventHandler, CraftEventEmitter, IOSConfig, AndroidConfig, MacOSConfig, WindowsConfig, LinuxConfig, CraftAppConfig, } from './types.js';
84
+ export type { WindowOptions, CraftSidebarAPI, CraftNativeUIAPI, CraftContextMenuItem, CraftContextMenuResult, AppConfig, CraftTrayAPI, CraftWindowAPI, CraftAppAPI, CraftBridgeAPI, Permission, HapticType, CameraOptions, PhotoPickerOptions, CraftMobileAPI, CraftFileSystemAPI, CraftDatabaseAPI, CraftHttpAPI, CraftCryptoAPI, CraftCapabilities, CapabilityNamespace, CapabilityNamespaceStatus, CapabilityAction, CraftPreferencesAPI, CraftPreferencesInfo, CraftSettingsAPI, PreferenceValue, CraftEventType, CraftEventMap, CraftEventHandler, CraftEventEmitter, IOSConfig, AndroidConfig, MacOSConfig, WindowsConfig, LinuxConfig, CraftAppConfig, } from './types.js';
package/dist/index.js CHANGED
@@ -58,7 +58,7 @@ function craftBinaryNotFoundMessage(triedPath) {
58
58
  `);
59
59
  }
60
60
  // package.json
61
- var version = "0.0.107";
61
+ var version = "0.0.110";
62
62
 
63
63
  // src/sdk-version.ts
64
64
  var SDK_VERSION = version;
@@ -3392,6 +3392,11 @@ struct CraftWebView: UIViewRepresentable {
3392
3392
  getBiometricType: function() { return Promise.resolve(craft.capabilities.biometric ? 'faceId' : null); },
3393
3393
  authenticate: function(reason) { return legacyAuthenticate(reason); }
3394
3394
  };
3395
+ // The app's own SQLite database (Documents/craft.db), as on Android.
3396
+ craft.db = {
3397
+ execute: function(sql, params) { return craft._invoke('dbExecute', { sql: sql, params: params || [] }); },
3398
+ query: function(sql, params) { return craft._invoke('dbQuery', { sql: sql, params: params || [] }); }
3399
+ };
3395
3400
  craft.secureStorage = {
3396
3401
  set: function(key, value) { return legacySecureStore.set(key, value).then(function() {}); },
3397
3402
  get: function(key) { return legacySecureStore.get(key); },
@@ -5044,6 +5049,34 @@ struct CraftWebView: UIViewRepresentable {
5044
5049
  }
5045
5050
 
5046
5051
  // MARK: - Local Database (SQLite)
5052
+ /// SQLite copies what it is given only when told to (SQLITE_TRANSIENT);
5053
+ /// with a nil destructor it keeps a pointer to a Swift string that is
5054
+ /// freed as soon as the bind call returns, and stores whatever is there
5055
+ /// later.
5056
+ private let sqliteTransient = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
5057
+
5058
+ /// Binds JSON-bridged values: strings, integers as 64-bit (JS numbers
5059
+ /// that are whole, such as millisecond timestamps), other numbers as
5060
+ /// doubles, booleans as 0/1, and null.
5061
+ private func bindParameters(_ statement: OpaquePointer?, _ params: [Any]) {
5062
+ for (index, param) in params.enumerated() {
5063
+ let idx = Int32(index + 1)
5064
+ if let str = param as? String {
5065
+ sqlite3_bind_text(statement, idx, str, -1, sqliteTransient)
5066
+ } else if let number = param as? NSNumber {
5067
+ if CFGetTypeID(number) == CFBooleanGetTypeID() {
5068
+ sqlite3_bind_int64(statement, idx, number.boolValue ? 1 : 0)
5069
+ } else if CFNumberIsFloatType(number), number.doubleValue.rounded() != number.doubleValue {
5070
+ sqlite3_bind_double(statement, idx, number.doubleValue)
5071
+ } else {
5072
+ sqlite3_bind_int64(statement, idx, number.int64Value)
5073
+ }
5074
+ } else {
5075
+ sqlite3_bind_null(statement, idx)
5076
+ }
5077
+ }
5078
+ }
5079
+
5047
5080
  private func dbExecute(sql: String, params: [Any]?, callbackId: String?) {
5048
5081
  guard let db = db else {
5049
5082
  rejectCallback(callbackId, error: "Database not initialized")
@@ -5054,18 +5087,7 @@ struct CraftWebView: UIViewRepresentable {
5054
5087
  if sqlite3_prepare_v2(db, sql, -1, &statement, nil) == SQLITE_OK {
5055
5088
  // Bind parameters
5056
5089
  if let params = params {
5057
- for (index, param) in params.enumerated() {
5058
- let idx = Int32(index + 1)
5059
- if let str = param as? String {
5060
- sqlite3_bind_text(statement, idx, str, -1, nil)
5061
- } else if let int = param as? Int {
5062
- sqlite3_bind_int(statement, idx, Int32(int))
5063
- } else if let double = param as? Double {
5064
- sqlite3_bind_double(statement, idx, double)
5065
- } else {
5066
- sqlite3_bind_null(statement, idx)
5067
- }
5068
- }
5090
+ bindParameters(statement, params)
5069
5091
  }
5070
5092
 
5071
5093
  if sqlite3_step(statement) == SQLITE_DONE {
@@ -5095,18 +5117,7 @@ struct CraftWebView: UIViewRepresentable {
5095
5117
  if sqlite3_prepare_v2(db, sql, -1, &statement, nil) == SQLITE_OK {
5096
5118
  // Bind parameters
5097
5119
  if let params = params {
5098
- for (index, param) in params.enumerated() {
5099
- let idx = Int32(index + 1)
5100
- if let str = param as? String {
5101
- sqlite3_bind_text(statement, idx, str, -1, nil)
5102
- } else if let int = param as? Int {
5103
- sqlite3_bind_int(statement, idx, Int32(int))
5104
- } else if let double = param as? Double {
5105
- sqlite3_bind_double(statement, idx, double)
5106
- } else {
5107
- sqlite3_bind_null(statement, idx)
5108
- }
5109
- }
5120
+ bindParameters(statement, params)
5110
5121
  }
5111
5122
 
5112
5123
  let columnCount = sqlite3_column_count(statement)
@@ -5119,7 +5130,8 @@ struct CraftWebView: UIViewRepresentable {
5119
5130
 
5120
5131
  switch type {
5121
5132
  case SQLITE_INTEGER:
5122
- row[columnName] = sqlite3_column_int(statement, i)
5133
+ // 64-bit: millisecond timestamps overflow Int32.
5134
+ row[columnName] = sqlite3_column_int64(statement, i)
5123
5135
  case SQLITE_FLOAT:
5124
5136
  row[columnName] = sqlite3_column_double(statement, i)
5125
5137
  case SQLITE_TEXT:
package/dist/types.d.ts CHANGED
@@ -1062,6 +1062,44 @@ export interface CraftWindowControls {
1062
1062
  */
1063
1063
  replicas: 'none' | null;
1064
1064
  }
1065
+ /** One row of a native context menu. */
1066
+ export interface CraftContextMenuItem {
1067
+ id: string;
1068
+ title: string;
1069
+ /** `'separator'` draws a divider; `'submenu'` nests `submenu` one level. */
1070
+ type?: 'standard' | 'separator' | 'submenu';
1071
+ /** SF Symbol name, e.g. `'archivebox'`. */
1072
+ icon?: string;
1073
+ /**
1074
+ * `'cmd+e'`, `'cmd+delete'`, `'cmd+shift+up'`: modifiers, then a character
1075
+ * or a key name (delete, forwarddelete, return, escape, tab, space, up,
1076
+ * down, left, right, home, end, pageup, pagedown, f1-f12, plus, minus).
1077
+ */
1078
+ shortcut?: string;
1079
+ enabled?: boolean;
1080
+ submenu?: CraftContextMenuItem[];
1081
+ }
1082
+ /** How a context menu closed. `id` is null when it was dismissed. */
1083
+ export interface CraftContextMenuResult {
1084
+ id: string | null;
1085
+ targetId: string;
1086
+ targetType: string;
1087
+ }
1088
+ export interface CraftNativeUIAPI {
1089
+ /**
1090
+ * Open a native context menu at the page point `x`/`y` (an event's
1091
+ * `clientX`/`clientY`). Resolves when the menu closes.
1092
+ */
1093
+ showContextMenu: (options: {
1094
+ items: CraftContextMenuItem[];
1095
+ x: number;
1096
+ y: number;
1097
+ targetId?: string;
1098
+ targetType?: string;
1099
+ }) => Promise<CraftContextMenuResult>;
1100
+ /** Every context menu's outcome. Returns an unsubscribe function. */
1101
+ onContextMenuAction: (callback: (result: CraftContextMenuResult) => void) => () => void;
1102
+ }
1065
1103
  export interface CraftBridgeAPI {
1066
1104
  /**
1067
1105
  * Where the platform drew this window's close/minimise/zoom buttons.
@@ -1111,6 +1149,11 @@ export interface CraftBridgeAPI {
1111
1149
  * Native sidebar APIs (macOS)
1112
1150
  */
1113
1151
  sidebar?: CraftSidebarAPI;
1152
+ /**
1153
+ * Native AppKit controls the page can open (macOS). Also reachable as
1154
+ * `craft.components`.
1155
+ */
1156
+ nativeUI?: CraftNativeUIAPI;
1114
1157
  /**
1115
1158
  * Crypto APIs
1116
1159
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.107",
3
+ "version": "0.0.110",
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>",