This file contains hidden or 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
import React from "react"; | |
import sanityClient from "part:@sanity/base/client"; | |
import userStore from "part:@sanity/base/user"; | |
// A more involved custom action example, doing some queries etc. | |
export default function Custom(props) { | |
// const {draft, published, id, type} = props | |
// Common operation in custom actions are to inspect the document (draft || |
This file contains hidden or 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
import React, {useState} from "react" | |
import { PublishAction } from 'part:@sanity/base/document-actions'; | |
const ConfirmDialog = ({onClick, onCancel}) => { | |
return ( | |
<> | |
<button onClick={onClick}>Yes</button> | |
<button onClick={onCancel}>Cancel</button> | |
</> | |
) |
This file contains hidden or 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
require("dotenv").config(); | |
const fs = require("fs"); | |
const { groqStore, groq } = require("@sanity/groq-store"); | |
const store = groqStore({ | |
projectId: process.env.SANITY_PROJECT_ID, | |
dataset: process.env.SANITY_DATASET, | |
listen: true, | |
overlayDrafts: true, | |
token: process.env.SANITY_TOKEN || "", |
This file contains hidden or 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
// Find all nested instances of _type `type` | |
const findAssets = (object, type, results = []) => { | |
if (object instanceof Object) { | |
if (object["_type"] === type) { | |
results.push(object); | |
return; | |
} | |
for (const key of Object.keys(object)) { | |
const value = object[key]; |
This file contains hidden or 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
// Exif orientation value to css transform mapping | |
type Rotation = string; | |
const rotations: Record<number, Rotation> = { | |
1: "rotate(0deg)", | |
2: "rotateY(180deg)", | |
3: "rotate(180deg)", | |
4: "rotate(180deg) rotateY(180deg)", | |
5: "rotate(270deg) rotateY(180deg)", | |
6: "rotate(90deg)", | |
7: "rotate(90deg) rotateY(180deg)", |
This file contains hidden or 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
Show hidden characters
{ | |
"Client": { | |
"scope": "javascript,typescript", | |
"prefix": "sanity client", | |
"body": [ | |
"const sanityClient = require('@sanity/client')", | |
"const client = sanityClient({", | |
"projectId: '${1:your-project-id}',", | |
"dataset: '${2:production}',", | |
"token: 'sanity-auth-token', // or leave blank to be anonymous user", |
This file contains hidden or 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
import React, { useRef } from 'react' | |
import { map } from 'rxjs/operators' | |
import { createWeightedSearch } from 'part:@sanity/base/search/weighted' | |
import client from 'part:@sanity/base/client' | |
import ExternalReferenceInput from './ExternalReferenceInput' | |
const ExternalReference = props => { | |
const { type } = props | |
const { options } = type | |
const { dataset } = options |
This file contains hidden or 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
import React, { | |
useEffect, useState | |
} from 'react' | |
import DefaultPane from '@sanity/components/lib/panes/DefaultPane' | |
import client from 'part:@sanity/base/client' | |
const CustomPane = (props) => { | |
const [groups, setGroups] = useState([]) | |
useEffect(() => { |
This file contains hidden or 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
type SanityClientOptions = { | |
projectId: string; | |
dataset: string; | |
token?: string; | |
useCdn?: boolean; | |
}; | |
type QueryParameters = Record<string, string | number>; | |
const sanityClient = (options: SanityClientOptions) => { |
This file contains hidden or 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
import { FaExternalLinkAlt } from 'react-icons/fa' | |
/** | |
* This is the schema definition for the rich text fields used for | |
* for this blog studio. When you import it in schemas.js it can be | |
* reused in other parts of the studio with: | |
* { | |
* name: 'someName', | |
* title: 'Some title', | |
* type: 'blockContent' | |
* } |