-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to ignore certain nodes in the document + locate node i…
…n the doc (#30)
- Loading branch information
Showing
26 changed files
with
344 additions
and
137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createEndpoint } from "../utils/createEndpoint"; | ||
|
||
export type HighlightNodeProps = { | ||
id: string; | ||
}; | ||
|
||
export const highlightNodeEndpoint = createEndpoint( | ||
"HIGHLIGHT_NODE", | ||
async ({ id }: HighlightNodeProps) => { | ||
const node = figma.getNodeById(id); | ||
|
||
if (node) { | ||
figma.viewport.scrollAndZoomIntoView([node]); | ||
} | ||
} | ||
); |
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
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,92 @@ | ||
import { TOLGEE_PLUGIN_CONFIG_NAME } from "@/constants"; | ||
import { | ||
ConfigChangeHandler, | ||
CurrentDocumentSettings, | ||
CurrentPageSettings, | ||
GlobalSettings, | ||
TolgeeConfig, | ||
} from "@/types"; | ||
import { emit } from "@create-figma-plugin/utilities"; | ||
import { setPageData } from "./pages"; | ||
|
||
const getGlobalSettings = async () => { | ||
const pluginData = await figma.clientStorage.getAsync( | ||
TOLGEE_PLUGIN_CONFIG_NAME | ||
); | ||
return pluginData ? (JSON.parse(pluginData) as Partial<GlobalSettings>) : {}; | ||
}; | ||
|
||
const setGlobalSettings = async (data: Partial<GlobalSettings>) => { | ||
await figma.clientStorage.setAsync( | ||
TOLGEE_PLUGIN_CONFIG_NAME, | ||
JSON.stringify(data) | ||
); | ||
}; | ||
|
||
export const deleteGlobalSettings = async () => { | ||
await figma.clientStorage.deleteAsync(TOLGEE_PLUGIN_CONFIG_NAME); | ||
}; | ||
|
||
export const getDocumentData = (): Partial<CurrentDocumentSettings> => { | ||
const pluginData = figma.root.getPluginData(TOLGEE_PLUGIN_CONFIG_NAME); | ||
const result = pluginData | ||
? (JSON.parse(pluginData) as Partial<CurrentDocumentSettings>) | ||
: {}; | ||
|
||
return { | ||
ignorePrefix: "_", | ||
ignoreNumbers: true, | ||
...result, | ||
}; | ||
}; | ||
|
||
const setDocumentData = (data: Partial<CurrentDocumentSettings>) => { | ||
figma.root.setPluginData(TOLGEE_PLUGIN_CONFIG_NAME, JSON.stringify(data)); | ||
}; | ||
|
||
export const deleteDocumentData = () => { | ||
figma.root.setPluginData(TOLGEE_PLUGIN_CONFIG_NAME, ""); | ||
}; | ||
|
||
const getPageData = (page = figma.currentPage) => { | ||
const pluginData = page.getPluginData(TOLGEE_PLUGIN_CONFIG_NAME); | ||
return pluginData | ||
? (JSON.parse(pluginData) as Partial<CurrentPageSettings>) | ||
: {}; | ||
}; | ||
|
||
export const deletePageData = (page = figma.currentPage) => { | ||
page.setPluginData(TOLGEE_PLUGIN_CONFIG_NAME, ""); | ||
}; | ||
|
||
export const getPluginData = async () => { | ||
return { | ||
...(await getGlobalSettings()), | ||
...getDocumentData(), | ||
...getPageData(), | ||
}; | ||
}; | ||
|
||
export const setPluginData = async (data: Partial<TolgeeConfig>) => { | ||
const { | ||
apiKey, | ||
apiUrl, | ||
language, | ||
namespace, | ||
namespacesDisabled, | ||
ignorePrefix, | ||
ignoreNumbers, | ||
} = data; | ||
await setGlobalSettings({ apiKey, apiUrl, ignorePrefix, ignoreNumbers }); | ||
setDocumentData({ | ||
apiKey, | ||
apiUrl, | ||
namespace, | ||
namespacesDisabled, | ||
ignorePrefix, | ||
ignoreNumbers, | ||
documentInfo: true, | ||
}); | ||
setPageData({ language, pageInfo: true }); | ||
emit<ConfigChangeHandler>("CONFIG_CHANGE", await getPluginData()); | ||
}; |
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
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,9 @@ | ||
.highlightButton { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
cursor: pointer; | ||
width: 20px; | ||
height: 20px; | ||
color: var(--figma-color-text-secondary); | ||
} |
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,5 @@ | ||
declare const styles: { | ||
readonly "highlightButton": string; | ||
}; | ||
export = styles; | ||
|
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,29 @@ | ||
import { useHighlightNodeMutation } from "@/ui/hooks/useHighlightNodeMutation"; | ||
import { h } from "preact"; | ||
|
||
import styles from "./LocateNodeButton.css"; | ||
import { MyLocation } from "@/ui/icons/SvgIcons"; | ||
|
||
type Props = { | ||
nodeId: string; | ||
}; | ||
|
||
export const LocateNodeButton = ({ nodeId }: Props) => { | ||
const highlightMutation = useHighlightNodeMutation(); | ||
|
||
const handleHighlight = () => { | ||
highlightMutation.mutate({ id: nodeId }); | ||
}; | ||
|
||
return ( | ||
<div | ||
data-cy="index_highlight_button" | ||
role="button" | ||
title="Locate on the page" | ||
onClick={handleHighlight} | ||
className={styles.highlightButton} | ||
> | ||
<MyLocation width={16} height={16} /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.