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
import { useState, useEffect } from 'react' | |
import resolveConfig from 'tailwindcss/resolveConfig' | |
import throttle from 'lodash.throttle' | |
import tailwindConfig from '../tailwind.config.js' | |
const findKeyByValue = (object, value) => | |
Object.keys(object).find((key) => object[key] === value) | |
const getDeviceConfig = (width) => { | |
const fullConfig = resolveConfig(tailwindConfig) |
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 has been generated by Sanity TypeGen. | |
* Command: `sanity typegen generate` | |
* | |
* Any modifications made directly to this file will be overwritten the next time | |
* the TypeScript definitions are generated. Please make changes to the Sanity | |
* schema definitions and/or GROQ queries if you need to update these types. | |
* | |
* For more information on how to use Sanity TypeGen, visit the official documentation: |
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
import type { KeyedObject, TypedObject } from "sanity"; | |
import PageBuilderContent from "./pageBuilderContent"; | |
import PageBuilderColumns from "./pageBuilderColumns"; | |
const Components = { | |
pageBuilderContent: PageBuilderContent, | |
pageBuilderColumns: PageBuilderColumns, | |
}; |
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
import slugify from 'slugify' | |
/** | |
* Slug field which will append a 'prefix' so that your slug is the complete path to the file | |
* And so that retrieving the slug from a reference to a document is a ready-made link | |
* | |
* Example with no prefix: | |
* `office` becomes `/office` | |
* | |
* Example with `office` prefix: |
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
// ./pages/api/preview.ts | |
import { groq } from "next-sanity"; | |
import { previewClient } from "../../lib/sanity.client"; | |
import { NextApiRequest, NextApiResponse } from "next"; | |
export const STUDIO_URL_DEV = "http://localhost:3333"; | |
export const STUDIO_URL_PROD = "https://replace-with-yours.sanity.studio"; | |
export const WEBSITE_URL_DEV = "http://localhost:3000"; |
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
import {useEffect, useState} from 'react' | |
import {ImageAsset, ObjectInputProps, Reference, set, unset, useClient} from 'sanity' | |
type ExtendedImageValue = { | |
asset: Reference | |
lqip?: string | |
blurHash?: string | |
} | |
export default function ImageExtendedInput(props: ObjectInputProps<ExtendedImageValue>) { |
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
import {SlugSourceFn, SlugifierFn, defineField, defineType} from 'sanity' | |
import get from 'lodash/get' | |
// Fetch the category's slug – if present – and append the post's title | |
const handleSlugSource: SlugSourceFn = async (doc, context) => { | |
const categoryRef = get(doc, `category._ref`) | |
if (categoryRef) { | |
const client = context.getClient({apiVersion: `2023-07-01`}) | |
const categorySlug = await client.fetch(`*[_id == $id][0].slug.current`, {id: categoryRef}) |
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
import S from '@sanity/desk-tool/structure-builder' | |
import userStore from 'part:@sanity/base/user' | |
// Get the logged in user | |
const getCurrentUser = () => { | |
userStore.me.subscribe((user) => { | |
// Instead of a local variable, we use this window object to re-use it through the Studio | |
if (user) { | |
window._sanityUser = user ?? undefined | |
} |
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
import {useState, useEffect, useCallback} from 'react' | |
import {useToast, Card, Button, Stack, Text, Code} from '@sanity/ui' | |
import {extractWithPath} from '@sanity/mutator' | |
import { | |
Preview, | |
DocumentActionProps, | |
SanityDocument, | |
useClient, | |
useSchema, | |
pathToString, |
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
import React, {useEffect, useState, useRef} from 'react' | |
import documentStore from 'part:@sanity/base/datastore/document' | |
import {catchError, distinctUntilChanged} from 'rxjs/operators' | |
import isEqual from 'react-fast-compare' | |
type Params = Record<string, string | number | boolean | string[]> | |
interface ListenQueryOptions { | |
tag?: string | |
apiVersion?: string |
NewerOlder