Skip to content

Commit

Permalink
Render shortcut inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
electrikmilk committed Nov 24, 2023
1 parent 0472642 commit 6042761
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'framework7-icons';

import './style.css';

import {renderShortcut} from "~/render";
import {renderInputs, renderShortcut} from "~/render";

// @ts-ignore
import {parse} from 'plist/dist/plist-parse.js';
Expand Down Expand Up @@ -163,6 +163,8 @@ export class ShortcutPreview {
containers = [];
containers.push(container);

renderInputs(this.data);

if (this.data.WFWorkflowActions && this.data.WFWorkflowActions.length !== 0) {
renderShortcut(this.data.WFWorkflowActions);
} else {
Expand Down
75 changes: 73 additions & 2 deletions src/render.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ActionData, container, newContainer, prevContainer} from "~/main";
import {ActionDefinition, actions} from "~/actions";
import {ActionData, container, newContainer, prevContainer, ShortcutData} from "~/main";
import {ActionDefinition, actions, actionText} from "~/actions";
import {renderValue} from "~/value";

interface ActionParameters {
Expand Down Expand Up @@ -243,3 +243,74 @@ export function renderParameters(actionData: ActionDefinition | null, parameters

return li;
}

const contentItemTypes = {
"WFAppStoreAppContentItem": "App store apps",
"WFArticleContentItem": "Articles",
"WFContactContentItem": "Contacts",
"WFDateContentItem": "Dates",
"WFEmailAddressContentItem": "Email addresses",
"WFFolderContentItem": "Folder",
"WFGenericFileContentItem": "Files",
"WFImageContentItem": "Images",
"WFiTunesProductContentItem": "iTunes Products",
"WFLocationContentItem": "Locations",
"WFDCMapsLinkContentItem": "Map links",
"WFAVAssetContentItem": "Media",
"WFPDFContentItem": "PDFs",
"WFPhoneNumberContentItem": "Phone numbers",
"WFRichTextContentItem": "Rich Text",
"WFSafariWebPageContentItem": "Safari web pages",
"WFStringContentItem": "Text",
"WFNumberContentItem": "Number",
"WFURLContentItem": "URLs",
};

const workflowTypes = {
"MenuBar": "Menubar",
"QuickActions": "Quick Actions",
"ActionExtension": "Share Sheet",
"NCWidget": "Notifications Center",
"Sleep": "Sleep Mode",
"Watch": "Apple Watch",
"ReceivesOnScreenContent": "What's On Screen",
}

export function renderInputs(shortcut: ShortcutData) {
if (!shortcut.WFWorkflowHasShortcutInputVariables) {
return;
}
const card = document.createElement('div');
card.className = 'card sp-linked-action';

let inputs = [];
if (shortcut.WFWorkflowInputContentItemClasses) {
for (const input of shortcut.WFWorkflowInputContentItemClasses) {
// @ts-ignore
inputs.push(contentItemTypes[input]);
}
}

let workflows = [];
if (shortcut.WFWorkflowTypes) {
for (const workflow of shortcut.WFWorkflowTypes) {
// @ts-ignore
workflows.push(workflowTypes[workflow]);
}
}

const render = renderActionHeader({
title: 'Receives',
icon: 'layers_fill',
color: '#007aff',
background: 'transparent',
},
renderValue(inputs.length !== 0 ? inputs.join(', ') : null, 'No'),
actionText('input from'),
renderValue(workflows.length !== 0 ? workflows.join(', ') : null, 'Nowhere')
);

card.innerHTML = renderCardContent(render).outerHTML;

container.appendChild(card);
}

0 comments on commit 6042761

Please sign in to comment.