Skip to content

Commit

Permalink
Add dynamic suggestion to inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
danim1130 committed Dec 2, 2024
1 parent 6a2cf46 commit 433de12
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 135 deletions.
8 changes: 4 additions & 4 deletions components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"preference": "dist/components.js"
},
"dependencies": {
"@intechstudio/grid-uikit": "^1.20240813.1834",
"@intechstudio/grid-uikit": "^1.20241115.1558",
"typescript": "^5.5.4",
"ws": "^8.18.0"
}
Expand Down
2 changes: 1 addition & 1 deletion components/src/Preferences.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let currentlyConnected = false;
// @ts-ignore
const messagePort = createPackageMessagePort("package-photoshop");
const messagePort = createPackageMessagePort("package-photoshop", "preferences");
onMount(() => {
Expand Down
105 changes: 0 additions & 105 deletions components/src/SingleEventAction.svelte

This file was deleted.

81 changes: 81 additions & 0 deletions components/src/SingleEventDynamicAction.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<svelte:options customElement={{tag: 'single-event-dynamic-action', shadow: 'none'}} />
<script>
import { AtomicInput, AtomicSuggestions } from "@intechstudio/grid-uikit";
import { onMount } from "svelte";
let eventType = "";
let eventId = "";
let currentCodeValue = "";
let ref;
let suggestionElement;
let suggestions = undefined;
$: eventType && loadSuggestions();
function loadSuggestions(){
// @ts-ignore
let port = createPackageMessagePort("package-photoshop", "dynamic-action");
port.onmessage = (e) => {
const data = e.data;
if (data.type === "init-suggestions") {
suggestions = data.suggestions[eventType];
}
port.close();
};
port.start();
}
function handleConfigUpdate(config) {
const regex =
/^gps\("package-photoshop", "*(.*?)", "*(.*?)"\)$/;
if (currentCodeValue != config.script){
currentCodeValue = config.script;
const match = config.script.match(regex);
if (match) {
eventType = match[1] ?? "";
eventId = match[2] ?? "";
}
}
}
onMount(() => {
const event = new CustomEvent("updateConfigHandler", {
bubbles: true,
detail: { handler: handleConfigUpdate },
});
ref.dispatchEvent(event);
});
$: eventId, function() {
var code = `gps("package-photoshop", "${eventType}", "${eventId}")`;
if (currentCodeValue != code){
currentCodeValue = code;
const event = new CustomEvent("updateCode", {
bubbles: true,
detail: { script: String(code) },
});
if (ref){
ref.dispatchEvent(event);
}
}
}()
</script>
<single-event
class="{$$props.class} flex flex-col w-full pb-2 px-2 pointer-events-auto"
bind:this={ref}
>
<div class="w-full flex">
<div class="atomicInput">
<div class="text-gray-500 text-sm pb-1">Parameter ID</div>
<AtomicInput
inputValue={eventId}
suggestions={suggestions}
suggestionTarget={suggestionElement}
on:change={(e) => {
eventId = e.detail;
}}/>
</div>
</div>
<AtomicSuggestions bind:component={suggestionElement} />
</single-event>
67 changes: 67 additions & 0 deletions components/src/SingleEventStaticAction.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<svelte:options customElement={{tag: 'single-event-static-action', shadow: 'none'}} />
<script>
import { AtomicInput, AtomicSuggestions } from "@intechstudio/grid-uikit";
import { onMount } from "svelte";
import data from "./single_event_static_data.js"
let eventType = "";
let eventId = "";
let currentCodeValue = "";
let ref;
let suggestionElement;
$: suggestions = data[eventType];
function handleConfigUpdate(config) {
const regex =
/^gps\("package-photoshop", "*(.*?)", "*(.*?)"\)$/;
if (currentCodeValue != config.script){
currentCodeValue = config.script;
const match = config.script.match(regex);
if (match) {
eventType = match[1] ?? "";
eventId = match[2] ?? "";
}
}
}
onMount(() => {
const event = new CustomEvent("updateConfigHandler", {
bubbles: true,
detail: { handler: handleConfigUpdate },
});
ref.dispatchEvent(event);
});
$: eventId, function() {
var code = `gps("package-photoshop", "${eventType}", "${eventId}")`;
if (currentCodeValue != code){
currentCodeValue = code;
const event = new CustomEvent("updateCode", {
bubbles: true,
detail: { script: String(code) },
});
if (ref){
ref.dispatchEvent(event);
}
}
}()
</script>
<single-event
class="{$$props.class} flex flex-col w-full pb-2 px-2 pointer-events-auto"
bind:this={ref}
>
<div class="w-full flex">
<div class="atomicInput">
<div class="text-gray-500 text-sm pb-1">Parameter ID</div>
<AtomicInput
inputValue={eventId}
suggestions={suggestions}
suggestionTarget={suggestionElement}
on:change={(e) => {
eventId = e.detail;
}}/>
</div>
</div>
<AtomicSuggestions bind:component={suggestionElement} />
</single-event>
3 changes: 2 additions & 1 deletion components/src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Preferences from "./Preferences.svelte";
import SingleEventAction from "./SingleEventAction.svelte";
import SingleEventStaticAction from "./SingleEventStaticAction.svelte";
import SingleParameterSetAction from "./SingleParameterSetAction.svelte";
import SingleEventDynamicAction from "./SingleEventDynamicAction.svelte";
23 changes: 23 additions & 0 deletions components/src/single_event_static_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
"create-adjustment": [
{ info: "Solid Color", value: "solidColorLayer" },
{ info: "Gradient", value: "gradientLayer" },
{ info: "Pattern", value: "patternLayer" },
{ info: "Brightness", value: "brightnessEvent" },
{ info: "Levels", value: "levels" },
{ info: "Curves", value: "curves" },
{ info: "Exposure", value: "exposure" },
{ info: "Vibrance", value: "vibrance" },
{ info: "Hue/Saturation", value: "hueSaturation" },
{ info: "Color Balance", value: "colorBalance" },
{ info: "Black and White", value: "blackAndWhite" },
{ info: "Photo Filter", value: "photoFilter" },
{ info: "Channel Mixer", value: "channelMixer" },
{ info: "Color Lookup", value: "colorLookup" },
{ info: "Invert", value: "invert" },
{ info: "Posterize", value: "posterization" },
{ info: "Threshold", value: "thresholdClassEvent" },
{ info: "Gradient Map", value: "gradientMapClass" },
{ info: "Selective Color", value: "selectiveColor" },
],
};
28 changes: 28 additions & 0 deletions components/src/single_parameter_set_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default {
"tool-parameter": [
{ info: "Angle", value: "angle" },
{ info: "Flow", value: "flow" },
{ info: "Hardness", value: "hardness" },
//{info: "Mode", value : "mode"},
{ info: "Opacity", value: "opacity" },
{ info: "Pressure", value: "pressure" },
{ info: "Roundness", value: "roundness" },
{ info: "Size", value: "size" },
{ info: "Smoothing", value: "smoothing" },
{ info: "Spacing", value: "spacing" },
],
"image-adjustment": [
{ info: "Brightness", value: "brigthness" },
{ info: "Contrast", value: "contrast" },
{ info: "Hue", value: "hue" },
{ info: "Lightness", value: "lightness" },
{ info: "Saturation", value: "saturation" },
],
"adjust-adjustment": [
{ info: "Brightness", value: "brightness" },
{ info: "Contrast", value: "contrast" },
{ info: "Exposure", value: "exposure" },
{ info: "Offset", value: "offset" },
{ info: "Gamma", value: "gamma" },
],
};
Loading

0 comments on commit 433de12

Please sign in to comment.