-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add placeholder directives for creating/deleting pins and launching p…
…ins/groups
- Loading branch information
1 parent
0cbe717
commit 9d8f8b8
Showing
7 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Placeholder, PlaceholderCategory, PlaceholderType } from "placeholders-toolkit"; | ||
import { createNewPin } from "../../Pins"; | ||
import { Group, createNewGroup } from "../../Groups"; | ||
import { StorageKey } from "../../constants"; | ||
import { getStorage } from "../../storage"; | ||
|
||
/** | ||
* Placeholder directive for creating a new pin. | ||
*/ | ||
const CreatePinDirective: Placeholder = { | ||
name: "createPin", | ||
regex: | ||
/{{createPin:(([^{]|{(?!{)|{{[\s\S]*?}})*?)(:(([^{]|{(?!{)|{{[\s\S]*?}})*?))?(:(([^{]|{(?!{)|{{[\s\S]*?}})*?))?}}/, | ||
rules: [], | ||
apply: async (str) => { | ||
const matches = str.match( | ||
/{{createPin:(([^{]|{(?!{)|{{[\s\S]*?}})*?)(:(([^{]|{(?!{)|{{[\s\S]*?}})*?))?(:(([^{]|{(?!{)|{{[\s\S]*?}})*?))?}}/, | ||
); | ||
const name = matches?.[1] || ""; | ||
const target = matches?.[4] || name; | ||
const group = matches?.[7] || "None"; | ||
if (!name) return { result: "" }; | ||
|
||
const allGroups: Group[] = await getStorage(StorageKey.LOCAL_GROUPS); | ||
if (group != "None" && !allGroups.some((g) => g.name == group)) { | ||
await createNewGroup(group, "None"); | ||
} | ||
|
||
await createNewPin( | ||
name, | ||
target, | ||
"None", | ||
group, | ||
"None", | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
); | ||
return { result: "" }; | ||
}, | ||
constant: false, | ||
fn: async (name, target, group) => | ||
(await CreatePinDirective.apply(`{{createPin:${name}:${target}:${group}}}`)).result, | ||
example: "{{createPin:myPinName:myPinTarget:myPinGroup}}", | ||
description: "Creates a new pin.", | ||
hintRepresentation: "{{createPin:...:...:...}}", | ||
fullRepresentation: "Create Pin", | ||
type: PlaceholderType.InteractiveDirective, | ||
categories: [PlaceholderCategory.Meta], | ||
}; | ||
|
||
export default CreatePinDirective; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Placeholder, PlaceholderCategory, PlaceholderType } from "placeholders-toolkit"; | ||
import { Pin, deletePin } from "../../Pins"; | ||
import { StorageKey } from "../../constants"; | ||
import { getStorage } from "../../storage"; | ||
|
||
/** | ||
* Placeholder directive for deleting a pin. | ||
*/ | ||
const DeletePinDirective: Placeholder = { | ||
name: "deletePin", | ||
regex: /{{deletePin:(([^{]|{(?!{)|{{[\s\S]*?}})*?)}}/, | ||
rules: [], | ||
apply: async (str) => { | ||
const matches = str.match(/{{deletePin:(([^{]|{(?!{)|{{[\s\S]*?}})*?)}}/); | ||
const pinRef = matches?.[1] || ""; | ||
if (!pinRef) return { result: "" }; | ||
|
||
const allPins: Pin[] = await getStorage(StorageKey.LOCAL_PINS); | ||
const pin = allPins.find((p) => p.name == pinRef || p.id.toString() == pinRef); | ||
if (!pin) return { result: "" }; | ||
|
||
await deletePin(pin, () => {}, true, true); | ||
return { result: "" }; | ||
}, | ||
constant: false, | ||
fn: async (pinRef) => (await DeletePinDirective.apply(`{{deletePin:${pinRef}}}`)).result, | ||
example: "{{deletePin:pinName}}", | ||
description: "Deletes a pin.", | ||
hintRepresentation: "{{deletePin:...}}", | ||
fullRepresentation: "Delete Pin", | ||
type: PlaceholderType.InteractiveDirective, | ||
categories: [PlaceholderCategory.Meta], | ||
}; | ||
|
||
export default DeletePinDirective; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Placeholder, PlaceholderCategory, PlaceholderType } from "placeholders-toolkit"; | ||
import { Pin, openPin } from "../../Pins"; | ||
import { getStorage } from "../../storage"; | ||
import { StorageKey } from "../../constants"; | ||
import { getPreferenceValues } from "@raycast/api"; | ||
import { ExtensionPreferences } from "../../preferences"; | ||
import { Group } from "../../Groups"; | ||
|
||
/** | ||
* Placeholder directive for opening/launching all pins in a target group. | ||
*/ | ||
const LaunchGroupDirective: Placeholder = { | ||
name: "launchGroup", | ||
regex: /{{(launchGroup|openGroup):(([^{]|{(?!{)|{{[\s\S]*?}})*?)}}/, | ||
rules: [], | ||
apply: async (str) => { | ||
const matches = str.match(/{{(launchGroup|openGroup):(([^{]|{(?!{)|{{[\s\S]*?}})*?)}}/); | ||
const targetRep = matches?.[2] || ""; | ||
if (!targetRep) return { result: "" }; | ||
const pins: Pin[] = (await getStorage(StorageKey.LOCAL_PINS)) || []; | ||
const groups: Group[] = (await getStorage(StorageKey.LOCAL_GROUPS)) || []; | ||
const target = groups.find((g) => g.name == targetRep || g.id.toString() == targetRep); | ||
if (!target) return { result: "" }; | ||
const groupPins = pins.filter((p) => p.group == target.name); | ||
const preferences = getPreferenceValues<ExtensionPreferences>(); | ||
await Promise.all(groupPins.map((p) => openPin(p, preferences))); | ||
return { result: "" }; | ||
}, | ||
constant: false, | ||
fn: async (target: string) => (await LaunchGroupDirective.apply(`{{launchPin:${target}}}`)).result, | ||
example: "{{launchPin:myPinName}}", | ||
description: "Opens the target pin.", | ||
hintRepresentation: "{{launchPin:...}}", | ||
fullRepresentation: "Launch Group", | ||
type: PlaceholderType.StaticDirective, | ||
categories: [PlaceholderCategory.Meta], | ||
}; | ||
|
||
export default LaunchGroupDirective; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Placeholder, PlaceholderCategory, PlaceholderType } from "placeholders-toolkit"; | ||
import { Pin, openPin } from "../../Pins"; | ||
import { getStorage } from "../../storage"; | ||
import { StorageKey } from "../../constants"; | ||
import { getPreferenceValues } from "@raycast/api"; | ||
import { ExtensionPreferences } from "../../preferences"; | ||
|
||
/** | ||
* Placeholder directive for opening/launching a target pin. | ||
*/ | ||
const LaunchPinDirective: Placeholder = { | ||
name: "launchPin", | ||
regex: /{{(launchPin|openPin|runPin):(([^{]|{(?!{)|{{[\s\S]*?}})*?)}}/, | ||
rules: [], | ||
apply: async (str) => { | ||
const matches = str.match(/{{(launchPin|openPin|runPin):(([^{]|{(?!{)|{{[\s\S]*?}})*?)}}/); | ||
const targetRep = matches?.[2] || ""; | ||
if (!targetRep) return { result: "" }; | ||
const pins: Pin[] = (await getStorage(StorageKey.LOCAL_PINS)) || []; | ||
const target = pins.find((p) => p.name == targetRep || p.id.toString() == targetRep); | ||
if (!target) return { result: "" }; | ||
const preferences = getPreferenceValues<ExtensionPreferences>(); | ||
openPin(target, preferences); | ||
return { result: "" }; | ||
}, | ||
constant: false, | ||
fn: async (target: string) => (await LaunchPinDirective.apply(`{{launchPin:${target}}}`)).result, | ||
example: "{{launchPin:myPinName}}", | ||
description: "Opens the target pin.", | ||
hintRepresentation: "{{launchPin:...}}", | ||
fullRepresentation: "Launch Pin", | ||
type: PlaceholderType.StaticDirective, | ||
categories: [PlaceholderCategory.Meta], | ||
}; | ||
|
||
export default LaunchPinDirective; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters