-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,471 additions
and
316 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 |
---|---|---|
|
@@ -8,5 +8,5 @@ node_modules | |
.DS_Store | ||
coverage | ||
dist | ||
|
||
playground/.env | ||
.vercel |
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,90 @@ | ||
# Visual Editing | ||
|
||
--- | ||
|
||
## Overview | ||
|
||
`@nuxtjs/sanity` provides a simple method of integrating [visual editing](https://www.sanity.io/docs/visual-editing) in your Nuxt application. Before enabling this feature, make sure you have [Presentation](https://www.sanity.io/docs/presentation) installed in your studio. | ||
|
||
::alert{type="warning"} | ||
Installing `@sanity/client` is required for visual editing. The `minimal` client must not be enabled. | ||
:: | ||
|
||
## Configuration | ||
|
||
You can configure visual editing via the `sanity.visualEditing` key in your Nuxt config. The following options are available: | ||
|
||
#### `studioUrl` | ||
|
||
- **Required** | ||
- Type: **string** | ||
|
||
The URL of the Sanity Studio with Presentation installed. | ||
|
||
#### `token` | ||
|
||
- **Required** | ||
- Type: **string** | ||
|
||
A Sanity read token used for server side queries. This is required in order to fetch draft content. This value will not be exposed to the client. | ||
|
||
#### `mode` | ||
|
||
- Type: **string** | ||
- Default: **`'live-visual-editing'`** | ||
|
||
Accepts one of the following options: | ||
|
||
- **`'live-visual-editing'`** - Default behaviour. Lets the module handle setup to provide fully featured visual editing with live updates. Queries should be executed using `useSanityQuery`. | ||
- **`'visual-editing'`** - Used to enable visual editing without live updates, for example if fetching data using the Sanity client directly. Passing a custom `refresh` handler is recommended, as by default the entire app will refresh to display updates. | ||
- **`'custom'`** - The module will not handle any setup, instead the `useSanityVisualEditing` and/or `useSanityLiveMode` composables will need to be called manually. | ||
|
||
|
||
#### `previewMode` | ||
|
||
- Type: **boolean**, **object** | ||
- Default: **true** | ||
|
||
To enable preview mode with defaults, or optionally configure the endpoints used to enable and disable preview mode. If passing an object, the options that can be provided are: | ||
|
||
- `enable` - the path of the enable endpoint, defaults to `/preview/enable` | ||
- `disable` - the path of the disable endpoint, defaults to `/preview/disable` | ||
|
||
#### `stega` | ||
|
||
- Type: **boolean** | ||
- Default: **true** | ||
|
||
Used to enable or disable [stega](https://www.sanity.io/docs/loaders-and-overlays#1dbcc04a7093). | ||
|
||
|
||
#### `refresh` | ||
|
||
- Type: **function** | ||
|
||
An optional function for overriding the default handling of refresh events received from the studio. This is generally not need needed if the `mode` option is set to `live-visual-editing`. | ||
|
||
#### `zIndex` | ||
|
||
- Type: **number**, **string** | ||
- Default: **9999999** | ||
|
||
The CSS z-index on the root node that renders overlays. | ||
|
||
|
||
### Recommended Configuration | ||
|
||
For most use cases, the following minimum `visualEditing` configuration will suffice: | ||
|
||
```ts{}[nuxt.config.ts] | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/sanity'], | ||
sanity: { | ||
// ... Sanity config | ||
visualEditing: { | ||
token: process.env.NUXT_SANITY_VISUAL_EDITING_TOKEN, | ||
studioUrl: process.env.NUXT_SANITY_VISUAL_EDITING_STUDIO_URL, | ||
} | ||
}, | ||
}) | ||
``` |
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 |
---|---|---|
@@ -1,7 +1,68 @@ | ||
import { SanityHelper } from './src/runtime/composables' | ||
import type { ClientPerspective, StegaConfig } from '@sanity/client' | ||
import type { SanityHelper } from '#sanity-composables' | ||
import type { | ||
SanityVisualEditingMode, | ||
SanityVisualEditingRefreshHandler, | ||
SanityVisualEditingZIndex, | ||
} from './src/module' | ||
|
||
type nullish = null | undefined | void | ||
|
||
declare module '#app' { | ||
interface NuxtApp { | ||
_sanity?: Record<string, SanityHelper> | ||
} | ||
} | ||
|
||
declare module 'nuxt/schema' { | ||
interface RuntimeConfig { | ||
sanity: { | ||
visualEditing: | ||
| { | ||
previewMode: | ||
| false | ||
| { | ||
enable: string | ||
disable: string | ||
} | ||
mode: SanityVisualEditingMode | ||
studioUrl: string | ||
previewModeId: string | ||
token: string | ||
|
||
} | ||
| undefined | ||
} | ||
} | ||
|
||
interface PublicRuntimeConfig { | ||
sanity: { | ||
additionalClients: Record<string, any> | ||
apiVersion: string | ||
dataset: string | ||
disableSmartCdn: boolean | ||
perspective: ClientPerspective | ||
projectId: string | ||
stega: StegaConfig | ||
token: string | ||
useCdn: boolean | ||
visualEditing: | ||
| { | ||
previewMode: | ||
| false | ||
| { | ||
enable: string | ||
disable: string | ||
} | ||
mode: SanityVisualEditingMode, | ||
studioUrl: string | ||
refresh: SanityVisualEditingRefreshHandler, | ||
zIndex: SanityVisualEditingZIndex | ||
} | ||
| nullish | ||
} | ||
withCredentials: boolean | ||
} | ||
} | ||
|
||
export {} |
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,2 @@ | ||
# add a Viewer token issued from https://www.sanity.io/organizations/<org_id>/project/<project_id>/api#tokens | ||
NUXT_SANITY_VISUAL_EDITING_TOKEN= |
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
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
Oops, something went wrong.