mac-helper 0.2.0 → 0.3.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/lib/dialog.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { StandardAdditions } from '@jxa/types';
1
+ import type { StandardAdditions } from '@jxa/types';
2
+ export declare const dialog: {
3
+ prompt: typeof prompt;
4
+ chooseFromList: typeof chooseFromList;
5
+ chooseMultipleFromList: typeof chooseMultipleFromList;
6
+ };
7
+ declare function prompt(label: string, defaultValue?: string): Promise<string>;
2
8
  type ChooseOption = {
3
9
  label: string;
4
10
  value: string;
5
11
  };
6
12
  declare function chooseFromList(list: string[] | ChooseOption[], options?: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter): Promise<string | undefined>;
7
13
  declare function chooseMultipleFromList(list: string[] | ChooseOption[], options?: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter): Promise<string[]>;
8
- export declare const dialog: {
9
- chooseFromList: typeof chooseFromList;
10
- chooseMultipleFromList: typeof chooseMultipleFromList;
11
- };
12
14
  export {};
package/lib/dialog.js CHANGED
@@ -2,6 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dialog = void 0;
4
4
  const run_1 = require("@jxa/run");
5
+ exports.dialog = {
6
+ prompt,
7
+ chooseFromList,
8
+ chooseMultipleFromList,
9
+ };
10
+ async function prompt(label, defaultValue = '') {
11
+ return ((await (0, run_1.run)((label) => {
12
+ const app = Application.currentApplication();
13
+ app.includeStandardAdditions = true;
14
+ const response = app.displayDialog(label, { defaultAnswer: '' });
15
+ return response.textReturned;
16
+ }, label)) || defaultValue);
17
+ }
5
18
  async function runOnCurrentApp(method, ...args) {
6
19
  return await (0, run_1.run)((method, ...args) => {
7
20
  const app = Application.currentApplication();
@@ -59,10 +72,6 @@ async function chooseMultipleFromList(list, options = {}) {
59
72
  return valArr;
60
73
  }
61
74
  }
62
- exports.dialog = {
63
- chooseFromList,
64
- chooseMultipleFromList,
65
- };
66
75
  // dialog.chooseFromList(['hello', 'world']).then((selected) => {
67
76
  // console.log(selected)
68
77
  // })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mac-helper",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "useful helper for macOS",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -14,6 +14,7 @@
14
14
  "test:dev": "vitest --globals --testTimeout=30000",
15
15
  "test-cover": "vitest run --globals --coverage --testTimeout=30000",
16
16
  "dev": "tsc -w --incremental",
17
+ "typecheck": "tsc --noEmit",
17
18
  "build": "rm -rf lib; rm tsconfig.tsbuildinfo; tsc",
18
19
  "prepublishOnly": "pnpm test && pnpm build"
19
20
  },
package/src/dialog.ts CHANGED
@@ -1,5 +1,22 @@
1
1
  import { run } from '@jxa/run'
2
- import { StandardAdditions } from '@jxa/types'
2
+ import type { StandardAdditions } from '@jxa/types'
3
+
4
+ export const dialog = {
5
+ prompt,
6
+ chooseFromList,
7
+ chooseMultipleFromList,
8
+ }
9
+
10
+ async function prompt(label: string, defaultValue = ''): Promise<string> {
11
+ return (
12
+ (await run((label) => {
13
+ const app = Application.currentApplication()
14
+ app.includeStandardAdditions = true
15
+ const response = app.displayDialog(label, { defaultAnswer: '' })
16
+ return response.textReturned
17
+ }, label)) || defaultValue
18
+ )
19
+ }
3
20
 
4
21
  type AppMethod = 'chooseFromList'
5
22
 
@@ -12,7 +29,7 @@ async function runOnCurrentApp(method: AppMethod, ...args: any[]) {
12
29
  return app[method]?.(...args)
13
30
  },
14
31
  method,
15
- ...args
32
+ ...args,
16
33
  )
17
34
  }
18
35
 
@@ -20,7 +37,7 @@ type ChooseOption = { label: string; value: string }
20
37
 
21
38
  async function chooseFromList(
22
39
  list: string[] | ChooseOption[],
23
- options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {}
40
+ options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {},
24
41
  ): Promise<string | undefined> {
25
42
  let usingOption = false
26
43
  let showList: string[] = []
@@ -49,7 +66,7 @@ async function chooseFromList(
49
66
 
50
67
  async function chooseMultipleFromList(
51
68
  list: string[] | ChooseOption[],
52
- options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {}
69
+ options: StandardAdditions.StandardAdditions.ChooseFromListOptionalParameter = {},
53
70
  ): Promise<string[]> {
54
71
  let usingOption = false
55
72
  let showList: string[] = []
@@ -71,17 +88,12 @@ async function chooseMultipleFromList(
71
88
  return selected as string[]
72
89
  } else {
73
90
  const valArr = (selected as string[]).map(
74
- (label) => (list as ChooseOption[]).find((item) => item.label === label)!.value
91
+ (label) => (list as ChooseOption[]).find((item) => item.label === label)!.value,
75
92
  )
76
93
  return valArr
77
94
  }
78
95
  }
79
96
 
80
- export const dialog = {
81
- chooseFromList,
82
- chooseMultipleFromList,
83
- }
84
-
85
97
  // dialog.chooseFromList(['hello', 'world']).then((selected) => {
86
98
  // console.log(selected)
87
99
  // })