Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
sanity-plugin-hotspot-array
Advanced tools
A configurable Custom Input for Arrays that will add and update items by clicking on an Image
A configurable Custom Input for Arrays that will add and update items by clicking on an Image
sanity install hotspot-array
Import the HotspotArray
component from this package, into your schema. And insert it as the inputComponent
of an array
field.
import HotspotArray from 'sanity-plugin-hotspot-array'
export default {
name: `product`,
title: `Product`,
type: `document`,
fields: [
{
name: `hotspots`,
type: `array`,
inputComponent: HotspotArray,
of: [
// see `Spot object` setup below
],
options: {
// see `Image and description paths` setup below
imageHotspotPathRoot: `document`,
hotspotImagePath: `featureImage`,
hotspotDescriptionPath: `details`,
// see `Custom tooltip` setup below
hotspotTooltip: undefined,
},
},
// ...all your other fields
],
}
The plugin makes a number of assumptions to add and update data in the array. Including:
array
field is an array of objectsx
and y
The custom input has the current values of all fields in the document by default, and so can "pick" the image out of the document by its path.
For example, if you want to add hotspots to an image, and that image is uploaded to the document field of featuredImage
, your fields options
would look like:
options: {
hotspotImagePath: `featureImage`
}
Alternatively, you may supply 'parent' to the imageHotspotPathRoot
option to pick from the parent object instead. Using 'parent' as imageHotspotPathRoot
in favor of the default 'document' may be required, e.g. if your schema of hotspots array is defined as a child of another array, and therefore you can not reference dynamically the correct field in a 'document' specified by hotspotImagePath
.
In this case, if the image is uploaded to the parent object field of featuredImage
, your fields options
would look like:
options: {
imageHotspotPathRoot: `parent`,
hotspotImagePath: `featureImage`
}
The custom input can also pre-fill a string or text field with a description of the position of the spot to make them easier to identify. Add a path relative to the spot object for this field.
options: {
hotspotDescriptionPath: `details`
}
Here's an example object schema complete with initial values, validation, fieldsets and a styled preview.
{
name: 'spot',
type: 'object',
fieldsets: [{name: 'position', options: {columns: 2}}],
fields: [
{name: 'details', type: 'text', rows: 2},
{
name: 'x',
type: 'number',
readOnly: true,
fieldset: 'position',
initialValue: 50,
validation: (Rule) => Rule.required().min(0).max(100),
},
{
name: 'y',
type: 'number',
readOnly: true,
fieldset: 'position',
initialValue: 50,
validation: (Rule) => Rule.required().min(0).max(100),
},
],
preview: {
select: {
title: 'details',
x: 'x',
y: 'y',
},
prepare({title, x, y}) {
return {
title,
subtitle: x && y ? `${x}% x ${y}%` : `No position set`,
}
},
},
}
You can customise the Tooltip to display any Component, it will accept a single prop spot
which contains the values of the object.
In this example our spot
object has a reference
field to the product
schema type, and will show a Document Preview.
// Setup a custom tooltip component
import Preview from 'part:@sanity/base/preview'
import schema from 'part:@sanity/base/schema'
import {Box} from '@sanity/ui'
export default function ProductPreview({spot}) {
return (
<Box padding={2} style={{minWidth: 200}}>
{spot?.product?._ref ? (
<Preview value={{_id: spot.product._ref}} type={schema.get(`product`)} />
) : (
`No Reference Selected`
)}
</Box>
)
}
Then back in your schema definition
import HotspotArray from 'sanity-plugin-hotspot-array'
import ProductPreview from '../../components/ProductPreview'
options: {
hotspotImagePath: `hotspotImage`,
hotspotTooltip: ProductPreview,
},
MIT © See LICENSE
FAQs
A configurable Custom Input for Arrays that will add and update items by clicking on an Image
We found that sanity-plugin-hotspot-array demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 65 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.