next-sanity 0.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +910 -0
- package/dist/_chunks/NextStudioLoading-8cf56cdf.js +127 -0
- package/dist/_chunks/NextStudioLoading-8cf56cdf.js.map +1 -0
- package/dist/_chunks/NextStudioLoading-bf57e61a.cjs +131 -0
- package/dist/_chunks/NextStudioLoading-bf57e61a.cjs.map +1 -0
- package/dist/index.cjs +26 -0
- package/dist/index.cjs.js +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/preview.cjs +19 -0
- package/dist/preview.cjs.js +6 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.ts +20 -0
- package/dist/preview.js +2 -0
- package/dist/preview.js.map +1 -0
- package/dist/studio/head.cjs +51 -0
- package/dist/studio/head.cjs.js +5 -0
- package/dist/studio/head.cjs.map +1 -0
- package/dist/studio/head.d.ts +79 -0
- package/dist/studio/head.js +46 -0
- package/dist/studio/head.js.map +1 -0
- package/dist/studio/index.cjs +111 -0
- package/dist/studio/index.cjs.js +10 -0
- package/dist/studio/index.cjs.map +1 -0
- package/dist/studio/index.d.ts +88 -0
- package/dist/studio/index.js +96 -0
- package/dist/studio/index.js.map +1 -0
- package/dist/studio/loading.cjs +8 -0
- package/dist/studio/loading.cjs.js +5 -0
- package/dist/studio/loading.cjs.map +1 -0
- package/dist/studio/loading.d.ts +23 -0
- package/dist/studio/loading.js +2 -0
- package/dist/studio/loading.js.map +1 -0
- package/dist/webhook.cjs +54 -0
- package/dist/webhook.cjs.js +6 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.ts +31 -0
- package/dist/webhook.js +42 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +207 -0
- package/src/client.ts +2 -0
- package/src/index.ts +3 -0
- package/src/preview/definePreview.tsx +37 -0
- package/src/preview/index.ts +2 -0
- package/src/studio/NextStudio.tsx +61 -0
- package/src/studio/NextStudioClientOnly.tsx +15 -0
- package/src/studio/NextStudioLayout.tsx +46 -0
- package/src/studio/NextStudioLoading.tsx +120 -0
- package/src/studio/NextStudioNoScript.tsx +40 -0
- package/src/studio/head/NextStudioHead.tsx +112 -0
- package/src/studio/head/apple-touch-icon.png +0 -0
- package/src/studio/head/favicon.ico +0 -0
- package/src/studio/head/favicon.svg +7 -0
- package/src/studio/head/index.ts +1 -0
- package/src/studio/index.ts +6 -0
- package/src/studio/loading.ts +1 -0
- package/src/studio/usePrefersColorScheme.ts +30 -0
- package/src/studio/useTheme.ts +13 -0
- package/src/webhook/config.ts +18 -0
- package/src/webhook/index.ts +2 -0
- package/src/webhook/parseBody.ts +44 -0
- package/src/webhook/readBody.ts +10 -0
package/dist/webhook.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var sanityWebhook = require('@sanity/webhook');
|
|
7
|
+
function _interopDefaultCompat(e) {
|
|
8
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
9
|
+
default: e
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
var sanityWebhook__default = /*#__PURE__*/_interopDefaultCompat(sanityWebhook);
|
|
13
|
+
const config = {
|
|
14
|
+
api: {
|
|
15
|
+
/**
|
|
16
|
+
* Next.js will by default parse the body, which can lead to invalid signatures.
|
|
17
|
+
*/
|
|
18
|
+
bodyParser: false
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.
|
|
22
|
+
*/
|
|
23
|
+
runtime: "nodejs"
|
|
24
|
+
};
|
|
25
|
+
async function _readBody(readable) {
|
|
26
|
+
const chunks = [];
|
|
27
|
+
for await (const chunk of readable) {
|
|
28
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
29
|
+
}
|
|
30
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
31
|
+
}
|
|
32
|
+
const {
|
|
33
|
+
isValidSignature,
|
|
34
|
+
SIGNATURE_HEADER_NAME
|
|
35
|
+
} = sanityWebhook__default.default;
|
|
36
|
+
async function parseBody(req, secret) {
|
|
37
|
+
let waitForContentLakeEventualConsistency = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
38
|
+
let signature = req.headers[SIGNATURE_HEADER_NAME];
|
|
39
|
+
if (Array.isArray(signature)) {
|
|
40
|
+
signature = signature[0];
|
|
41
|
+
}
|
|
42
|
+
const body = await _readBody(req);
|
|
43
|
+
const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null;
|
|
44
|
+
if (validSignature !== false && waitForContentLakeEventualConsistency) {
|
|
45
|
+
await new Promise(resolve => setTimeout(resolve, 1e3));
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
body: body.trim() && JSON.parse(body),
|
|
49
|
+
isValidSignature: validSignature
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.config = config;
|
|
53
|
+
exports.parseBody = parseBody;
|
|
54
|
+
//# sourceMappingURL=webhook.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.cjs","sources":["../src/webhook/config.ts","../src/webhook/readBody.ts","../src/webhook/parseBody.ts"],"sourcesContent":["import type {PageConfig} from 'next/types'\n\n/**\n * Configurates the API function with the right runtime and body parsing to handle Sanity Webhook events.\n * @public\n */\nexport const config: PageConfig = {\n api: {\n /**\n * Next.js will by default parse the body, which can lead to invalid signatures.\n */\n bodyParser: false,\n },\n /**\n * `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.\n */\n runtime: 'nodejs',\n}\n","import type {NextApiRequest} from 'next'\n\n/** @internal */\nexport async function _readBody(readable: NextApiRequest): Promise<string> {\n const chunks = []\n for await (const chunk of readable) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks).toString('utf8')\n}\n","import type {SanityDocument} from '@sanity/types'\nimport sanityWebhook from '@sanity/webhook'\nimport type {NextApiRequest} from 'next'\n\n// As `@sanity/webhook` isn't shipping ESM, extracting from the default export have the best ecosystem support\nconst {isValidSignature, SIGNATURE_HEADER_NAME} = sanityWebhook\n\nimport {_readBody as readBody} from './readBody'\n\n/** @public */\nexport type ParseBody = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: SanityDocument\n}\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody(\n req: NextApiRequest,\n secret?: string,\n waitForContentLakeEventualConsistency: boolean = true\n): Promise<ParseBody> {\n let signature = req.headers[SIGNATURE_HEADER_NAME]!\n if (Array.isArray(signature)) {\n signature = signature[0]\n }\n\n const body = await readBody(req)\n const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 1000))\n }\n\n return {\n body: body.trim() && JSON.parse(body),\n isValidSignature: validSignature,\n }\n}\n"],"names":["config","api","bodyParser","runtime","_readBody","readable","chunks","chunk","push","Buffer","from","concat","toString","isValidSignature","SIGNATURE_HEADER_NAME","sanityWebhook","parseBody","req","secret","waitForContentLakeEventualConsistency","signature","headers","Array","isArray","body","readBody","validSignature","trim","Promise","resolve","setTimeout","JSON","parse"],"mappings":";;;;;;;;;;;;AAMO,MAAMA,MAAqB,GAAA;EAChCC,GAAK,EAAA;IAAA;AAAA;AAAA;IAIHC,UAAY,EAAA;EACd,CAAA;EAAA;AAAA;AAAA;EAIAC,OAAS,EAAA;AACX,CAAA;ACdA,eAAsBC,UAAUC,QAA2C,EAAA;EACzE,MAAMC,SAAS,EAAC;EAChB,WAAA,MAAiBC,SAASF,QAAU,EAAA;IAC3BC,MAAA,CAAAE,IAAA,CAAK,OAAOD,KAAU,KAAA,QAAA,GAAWE,OAAOC,IAAK,CAAAH,KAAK,IAAIA,KAAK,CAAA;EACpE;EACA,OAAOE,MAAO,CAAAE,MAAA,CAAOL,MAAM,CAAA,CAAEM,SAAS,MAAM,CAAA;AAC9C;ACJA,MAAM;EAACC,gBAAkB;EAAAC;AAAyB,CAAA,GAAAC,8BAAA;AAiBlD,eAAsBC,SACpB,CAAAC,GAAA,EACAC,MACA,EACoB;EAAA,IADpBC,qCAAA,uEAAiD,IAC7B;EAChB,IAAAC,SAAA,GAAYH,GAAI,CAAAI,OAAA,CAAQP,qBAAqB,CAAA;EAC7C,IAAAQ,KAAA,CAAMC,OAAQ,CAAAH,SAAS,CAAG,EAAA;IAC5BA,SAAA,GAAYA,UAAU,CAAC,CAAA;EACzB;EAEM,MAAAI,IAAA,GAAO,MAAMC,SAAA,CAASR,GAAG,CAAA;EACzB,MAAAS,cAAA,GAAiBR,SAASL,gBAAiB,CAAAW,IAAA,EAAMJ,WAAWF,MAAO,CAAAS,IAAA,EAAM,CAAI,GAAA,IAAA;EAE/E,IAAAD,cAAA,KAAmB,SAASP,qCAAuC,EAAA;IACrE,MAAM,IAAIS,OAAQ,CAACC,WAAYC,UAAW,CAAAD,OAAA,EAAS,GAAI,CAAC,CAAA;EAC1D;EAEO,OAAA;IACLL,MAAMA,IAAK,CAAAG,IAAA,EAAU,IAAAI,IAAA,CAAKC,MAAMR,IAAI,CAAA;IACpCX,gBAAkB,EAAAa;EAAA,CACpB;AACF;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {NextApiRequest} from 'next'
|
|
2
|
+
import type {PageConfig} from 'next/types'
|
|
3
|
+
import type {SanityDocument} from '@sanity/types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configurates the API function with the right runtime and body parsing to handle Sanity Webhook events.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare const config: PageConfig
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export declare type ParseBody = {
|
|
13
|
+
/**
|
|
14
|
+
* If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`
|
|
15
|
+
*/
|
|
16
|
+
isValidSignature: boolean | null
|
|
17
|
+
body: SanityDocument
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries
|
|
22
|
+
* without worrying about getting stale data.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseBody(
|
|
26
|
+
req: NextApiRequest,
|
|
27
|
+
secret?: string,
|
|
28
|
+
waitForContentLakeEventualConsistency?: boolean
|
|
29
|
+
): Promise<ParseBody>
|
|
30
|
+
|
|
31
|
+
export {}
|
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import sanityWebhook from '@sanity/webhook';
|
|
2
|
+
const config = {
|
|
3
|
+
api: {
|
|
4
|
+
/**
|
|
5
|
+
* Next.js will by default parse the body, which can lead to invalid signatures.
|
|
6
|
+
*/
|
|
7
|
+
bodyParser: false
|
|
8
|
+
},
|
|
9
|
+
/**
|
|
10
|
+
* `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.
|
|
11
|
+
*/
|
|
12
|
+
runtime: "nodejs"
|
|
13
|
+
};
|
|
14
|
+
async function _readBody(readable) {
|
|
15
|
+
const chunks = [];
|
|
16
|
+
for await (const chunk of readable) {
|
|
17
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
18
|
+
}
|
|
19
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
20
|
+
}
|
|
21
|
+
const {
|
|
22
|
+
isValidSignature,
|
|
23
|
+
SIGNATURE_HEADER_NAME
|
|
24
|
+
} = sanityWebhook;
|
|
25
|
+
async function parseBody(req, secret) {
|
|
26
|
+
let waitForContentLakeEventualConsistency = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
27
|
+
let signature = req.headers[SIGNATURE_HEADER_NAME];
|
|
28
|
+
if (Array.isArray(signature)) {
|
|
29
|
+
signature = signature[0];
|
|
30
|
+
}
|
|
31
|
+
const body = await _readBody(req);
|
|
32
|
+
const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null;
|
|
33
|
+
if (validSignature !== false && waitForContentLakeEventualConsistency) {
|
|
34
|
+
await new Promise(resolve => setTimeout(resolve, 1e3));
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
body: body.trim() && JSON.parse(body),
|
|
38
|
+
isValidSignature: validSignature
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export { config, parseBody };
|
|
42
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sources":["../src/webhook/config.ts","../src/webhook/readBody.ts","../src/webhook/parseBody.ts"],"sourcesContent":["import type {PageConfig} from 'next/types'\n\n/**\n * Configurates the API function with the right runtime and body parsing to handle Sanity Webhook events.\n * @public\n */\nexport const config: PageConfig = {\n api: {\n /**\n * Next.js will by default parse the body, which can lead to invalid signatures.\n */\n bodyParser: false,\n },\n /**\n * `@sanity/webhook` isn't updated to support the edge runtime yet, and currently requires Node.js APIs such as Buffer.\n */\n runtime: 'nodejs',\n}\n","import type {NextApiRequest} from 'next'\n\n/** @internal */\nexport async function _readBody(readable: NextApiRequest): Promise<string> {\n const chunks = []\n for await (const chunk of readable) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks).toString('utf8')\n}\n","import type {SanityDocument} from '@sanity/types'\nimport sanityWebhook from '@sanity/webhook'\nimport type {NextApiRequest} from 'next'\n\n// As `@sanity/webhook` isn't shipping ESM, extracting from the default export have the best ecosystem support\nconst {isValidSignature, SIGNATURE_HEADER_NAME} = sanityWebhook\n\nimport {_readBody as readBody} from './readBody'\n\n/** @public */\nexport type ParseBody = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: SanityDocument\n}\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody(\n req: NextApiRequest,\n secret?: string,\n waitForContentLakeEventualConsistency: boolean = true\n): Promise<ParseBody> {\n let signature = req.headers[SIGNATURE_HEADER_NAME]!\n if (Array.isArray(signature)) {\n signature = signature[0]\n }\n\n const body = await readBody(req)\n const validSignature = secret ? isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 1000))\n }\n\n return {\n body: body.trim() && JSON.parse(body),\n isValidSignature: validSignature,\n }\n}\n"],"names":["config","api","bodyParser","runtime","_readBody","readable","chunks","chunk","push","Buffer","from","concat","toString","isValidSignature","SIGNATURE_HEADER_NAME","sanityWebhook","parseBody","req","secret","waitForContentLakeEventualConsistency","signature","headers","Array","isArray","body","readBody","validSignature","trim","Promise","resolve","setTimeout","JSON","parse"],"mappings":";AAMO,MAAMA,MAAqB,GAAA;EAChCC,GAAK,EAAA;IAAA;AAAA;AAAA;IAIHC,UAAY,EAAA;EACd,CAAA;EAAA;AAAA;AAAA;EAIAC,OAAS,EAAA;AACX,CAAA;ACdA,eAAsBC,UAAUC,QAA2C,EAAA;EACzE,MAAMC,SAAS,EAAC;EAChB,WAAA,MAAiBC,SAASF,QAAU,EAAA;IAC3BC,MAAA,CAAAE,IAAA,CAAK,OAAOD,KAAU,KAAA,QAAA,GAAWE,OAAOC,IAAK,CAAAH,KAAK,IAAIA,KAAK,CAAA;EACpE;EACA,OAAOE,MAAO,CAAAE,MAAA,CAAOL,MAAM,CAAA,CAAEM,SAAS,MAAM,CAAA;AAC9C;ACJA,MAAM;EAACC,gBAAkB;EAAAC;AAAyB,CAAA,GAAAC,aAAA;AAiBlD,eAAsBC,SACpB,CAAAC,GAAA,EACAC,MACA,EACoB;EAAA,IADpBC,qCAAA,uEAAiD,IAC7B;EAChB,IAAAC,SAAA,GAAYH,GAAI,CAAAI,OAAA,CAAQP,qBAAqB,CAAA;EAC7C,IAAAQ,KAAA,CAAMC,OAAQ,CAAAH,SAAS,CAAG,EAAA;IAC5BA,SAAA,GAAYA,UAAU,CAAC,CAAA;EACzB;EAEM,MAAAI,IAAA,GAAO,MAAMC,SAAA,CAASR,GAAG,CAAA;EACzB,MAAAS,cAAA,GAAiBR,SAASL,gBAAiB,CAAAW,IAAA,EAAMJ,WAAWF,MAAO,CAAAS,IAAA,EAAM,CAAI,GAAA,IAAA;EAE/E,IAAAD,cAAA,KAAmB,SAASP,qCAAuC,EAAA;IACrE,MAAM,IAAIS,OAAQ,CAACC,WAAYC,UAAW,CAAAD,OAAA,EAAS,GAAI,CAAC,CAAA;EAC1D;EAEO,OAAA;IACLL,MAAMA,IAAK,CAAAG,IAAA,EAAU,IAAAI,IAAA,CAAKC,MAAMR,IAAI,CAAA;IACpCX,gBAAkB,EAAAa;EAAA,CACpB;AACF;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "next-sanity",
|
|
3
|
+
"version": "0.0.0-dev.0",
|
|
4
|
+
"description": "Sanity.io toolkit for Next.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sanity",
|
|
7
|
+
"sanity.io",
|
|
8
|
+
"next.js",
|
|
9
|
+
"studio",
|
|
10
|
+
"studio-v3",
|
|
11
|
+
"live",
|
|
12
|
+
"preview"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/sanity-io/next-sanity#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/sanity-io/next-sanity/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+ssh://git@github.com/sanity-io/next-sanity.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"source": "./src/index.ts",
|
|
30
|
+
"require": "./dist/index.cjs",
|
|
31
|
+
"node": {
|
|
32
|
+
"import": "./dist/index.cjs.js",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./preview": {
|
|
39
|
+
"types": "./dist/preview.d.ts",
|
|
40
|
+
"source": "./src/preview/index.ts",
|
|
41
|
+
"require": "./dist/preview.cjs",
|
|
42
|
+
"node": {
|
|
43
|
+
"import": "./dist/preview.cjs.js",
|
|
44
|
+
"require": "./dist/preview.cjs"
|
|
45
|
+
},
|
|
46
|
+
"import": "./dist/preview.js",
|
|
47
|
+
"default": "./dist/preview.js"
|
|
48
|
+
},
|
|
49
|
+
"./studio": {
|
|
50
|
+
"types": "./dist/studio/index.d.ts",
|
|
51
|
+
"source": "./src/studio/index.ts",
|
|
52
|
+
"require": "./dist/studio/index.cjs",
|
|
53
|
+
"node": {
|
|
54
|
+
"import": "./dist/studio/index.cjs.js",
|
|
55
|
+
"require": "./dist/studio/index.cjs"
|
|
56
|
+
},
|
|
57
|
+
"import": "./dist/studio/index.js",
|
|
58
|
+
"default": "./dist/studio/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./studio/head": {
|
|
61
|
+
"types": "./dist/studio/head.d.ts",
|
|
62
|
+
"source": "./src/studio/head/index.ts",
|
|
63
|
+
"require": "./dist/studio/head.cjs",
|
|
64
|
+
"node": {
|
|
65
|
+
"import": "./dist/studio/head.cjs.js",
|
|
66
|
+
"require": "./dist/studio/head.cjs"
|
|
67
|
+
},
|
|
68
|
+
"import": "./dist/studio/head.js",
|
|
69
|
+
"default": "./dist/studio/head.js"
|
|
70
|
+
},
|
|
71
|
+
"./studio/loading": {
|
|
72
|
+
"types": "./dist/studio/loading.d.ts",
|
|
73
|
+
"source": "./src/studio/loading.ts",
|
|
74
|
+
"require": "./dist/studio/loading.cjs",
|
|
75
|
+
"node": {
|
|
76
|
+
"import": "./dist/studio/loading.cjs.js",
|
|
77
|
+
"require": "./dist/studio/loading.cjs"
|
|
78
|
+
},
|
|
79
|
+
"import": "./dist/studio/loading.js",
|
|
80
|
+
"default": "./dist/studio/loading.js"
|
|
81
|
+
},
|
|
82
|
+
"./webhook": {
|
|
83
|
+
"types": "./dist/webhook.d.ts",
|
|
84
|
+
"source": "./src/webhook/index.ts",
|
|
85
|
+
"require": "./dist/webhook.cjs",
|
|
86
|
+
"node": {
|
|
87
|
+
"import": "./dist/webhook.cjs.js",
|
|
88
|
+
"require": "./dist/webhook.cjs"
|
|
89
|
+
},
|
|
90
|
+
"import": "./dist/webhook.js",
|
|
91
|
+
"default": "./dist/webhook.js"
|
|
92
|
+
},
|
|
93
|
+
"./package.json": "./package.json"
|
|
94
|
+
},
|
|
95
|
+
"main": "./dist/index.cjs",
|
|
96
|
+
"module": "./dist/index.js",
|
|
97
|
+
"source": "./src/index.ts",
|
|
98
|
+
"types": "./dist/index.d.ts",
|
|
99
|
+
"typesVersions": {
|
|
100
|
+
"*": {
|
|
101
|
+
"preview": [
|
|
102
|
+
"./dist/preview.d.ts"
|
|
103
|
+
],
|
|
104
|
+
"studio": [
|
|
105
|
+
"./dist/studio/index.d.ts"
|
|
106
|
+
],
|
|
107
|
+
"studio/head": [
|
|
108
|
+
"./dist/studio/head.d.ts"
|
|
109
|
+
],
|
|
110
|
+
"studio/loading": [
|
|
111
|
+
"./dist/studio/loading.d.ts"
|
|
112
|
+
],
|
|
113
|
+
"webhook": [
|
|
114
|
+
"./dist/webhook.d.ts"
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"typings": "dist/index.d.ts",
|
|
119
|
+
"files": [
|
|
120
|
+
"dist",
|
|
121
|
+
"src"
|
|
122
|
+
],
|
|
123
|
+
"scripts": {
|
|
124
|
+
"prebuild": "npm run clean",
|
|
125
|
+
"build": "pkg build --strict && pkg --strict",
|
|
126
|
+
"clean": "rimraf dist",
|
|
127
|
+
"coverage": "npm test -- --coverage",
|
|
128
|
+
"dev": "next",
|
|
129
|
+
"format": "npm run prettier -- --write . && eslint --fix .",
|
|
130
|
+
"lint": "eslint --max-warnings 0 .",
|
|
131
|
+
"prepublishOnly": "npm run build",
|
|
132
|
+
"prettier": "npx prettier --ignore-path .gitignore",
|
|
133
|
+
"test": "jest",
|
|
134
|
+
"test:node-esm-cjs": "node test.mjs && node test.cjs",
|
|
135
|
+
"type-check": "tsc --noEmit",
|
|
136
|
+
"update:icons": "cp node_modules/@sanity/server/static/favicons/{apple-touch-icon.png,favicon.ico,favicon.svg} src/studio/head"
|
|
137
|
+
},
|
|
138
|
+
"browserslist": [
|
|
139
|
+
"> 0.2% and supports es6-module and supports es6-module-dynamic-import and not dead and not IE 11",
|
|
140
|
+
"maintained node versions"
|
|
141
|
+
],
|
|
142
|
+
"prettier": {
|
|
143
|
+
"bracketSpacing": false,
|
|
144
|
+
"printWidth": 98,
|
|
145
|
+
"semi": false,
|
|
146
|
+
"singleQuote": true
|
|
147
|
+
},
|
|
148
|
+
"dependencies": {
|
|
149
|
+
"@sanity/client": "0.0.0-dev.3",
|
|
150
|
+
"@sanity/preview-kit": "0.0.0-dev.1",
|
|
151
|
+
"@sanity/webhook": "^2",
|
|
152
|
+
"groq": "^3"
|
|
153
|
+
},
|
|
154
|
+
"devDependencies": {
|
|
155
|
+
"@rollup/plugin-url": "^8.0.1",
|
|
156
|
+
"@sanity/eslint-config-studio": "^2.0.1",
|
|
157
|
+
"@sanity/image-url": "^1.0.2",
|
|
158
|
+
"@sanity/pkg-utils": "^2.2.5",
|
|
159
|
+
"@sanity/semantic-release-preset": "^4.0.0",
|
|
160
|
+
"@sanity/ui": "^1.2.4",
|
|
161
|
+
"@sanity/vision": "^3.4.0",
|
|
162
|
+
"@types/eventsource": "^1.1.11",
|
|
163
|
+
"@types/jest": "^29.4.0",
|
|
164
|
+
"@types/react": "^18.0.28",
|
|
165
|
+
"@types/react-dom": "^18.0.11",
|
|
166
|
+
"@types/styled-components": "^5.1.26",
|
|
167
|
+
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
168
|
+
"autoprefixer": "^10.4.13",
|
|
169
|
+
"eslint": "^8.34.0",
|
|
170
|
+
"eslint-config-next": "13.1.6",
|
|
171
|
+
"eslint-config-prettier": "^8.6.0",
|
|
172
|
+
"eslint-config-sanity": "^6.0.0",
|
|
173
|
+
"eslint-gitignore": "^0.1.0",
|
|
174
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
175
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
176
|
+
"groqd": "^0.7.0",
|
|
177
|
+
"jest": "^29.4.3",
|
|
178
|
+
"jest-environment-jsdom": "^29.4.3",
|
|
179
|
+
"ls-engines": "^0.9.0",
|
|
180
|
+
"next": "13.1.6",
|
|
181
|
+
"postcss": "^8.4.21",
|
|
182
|
+
"prettier": "^2.8.4",
|
|
183
|
+
"prettier-plugin-packagejson": "^2.4.3",
|
|
184
|
+
"prettier-plugin-tailwindcss": "^0.2.3",
|
|
185
|
+
"react": "^18.2.0",
|
|
186
|
+
"react-dom": "^18.2.0",
|
|
187
|
+
"react-is": "^18.2.0",
|
|
188
|
+
"rollup": "^3.16.0",
|
|
189
|
+
"sanity": "^3.4.0",
|
|
190
|
+
"styled-components": "^5.3.6",
|
|
191
|
+
"tailwindcss": "^3.2.7",
|
|
192
|
+
"typescript": "^4.9.5",
|
|
193
|
+
"url-loader": "^4.1.1"
|
|
194
|
+
},
|
|
195
|
+
"peerDependencies": {
|
|
196
|
+
"@sanity/icons": "^2",
|
|
197
|
+
"@sanity/types": "^3",
|
|
198
|
+
"@sanity/ui": "^1",
|
|
199
|
+
"next": "^13",
|
|
200
|
+
"react": "^18",
|
|
201
|
+
"sanity": "^3",
|
|
202
|
+
"styled-components": "^5.2"
|
|
203
|
+
},
|
|
204
|
+
"engines": {
|
|
205
|
+
"node": ">=16"
|
|
206
|
+
}
|
|
207
|
+
}
|
package/src/client.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
import type {GroqStore} from '@sanity/groq-store'
|
|
3
|
+
import {
|
|
4
|
+
type Params,
|
|
5
|
+
type PreviewConfig,
|
|
6
|
+
type UsePreview,
|
|
7
|
+
_checkAuth,
|
|
8
|
+
_definePreview,
|
|
9
|
+
_lazyEventSourcePolyfill,
|
|
10
|
+
_lazyGroqStore,
|
|
11
|
+
} from '@sanity/preview-kit'
|
|
12
|
+
import {cache, use} from 'react'
|
|
13
|
+
|
|
14
|
+
const lazyEventSourcePolyfill = cache(_lazyEventSourcePolyfill)
|
|
15
|
+
const lazyGroqStore = cache(_lazyGroqStore)
|
|
16
|
+
const checkAuth = cache(_checkAuth)
|
|
17
|
+
const preload = cache((store: GroqStore, query: string, params?: Params) =>
|
|
18
|
+
store.query<any>(query, params)
|
|
19
|
+
)
|
|
20
|
+
// */
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
/*
|
|
26
|
+
export const definePreview = (config: PreviewConfig): UsePreview =>
|
|
27
|
+
_definePreview({
|
|
28
|
+
...config,
|
|
29
|
+
importEventSourcePolyfill: () => use(lazyEventSourcePolyfill()),
|
|
30
|
+
importGroqStore: () => use(lazyGroqStore()),
|
|
31
|
+
checkAuth: (projectId, token) => use(checkAuth(projectId, token)),
|
|
32
|
+
preload: (store, query, params) => use(preload(store, query, params)),
|
|
33
|
+
})
|
|
34
|
+
// */
|
|
35
|
+
|
|
36
|
+
export type {Params, PreviewConfig, UsePreview} from '@sanity/preview-kit'
|
|
37
|
+
export {definePreview} from '@sanity/preview-kit'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {memo} from 'react'
|
|
2
|
+
import {Studio, type StudioProps} from 'sanity'
|
|
3
|
+
|
|
4
|
+
import {NextStudioClientOnly} from './NextStudioClientOnly'
|
|
5
|
+
import {NextStudioLayout} from './NextStudioLayout'
|
|
6
|
+
import {NextStudioLoading, type NextStudioLoadingProps} from './NextStudioLoading'
|
|
7
|
+
|
|
8
|
+
export type {NextStudioLoadingProps}
|
|
9
|
+
|
|
10
|
+
/** @beta */
|
|
11
|
+
export interface NextStudioProps extends StudioProps {
|
|
12
|
+
children?: React.ReactNode
|
|
13
|
+
/**
|
|
14
|
+
* Render the <noscript> tag
|
|
15
|
+
* @defaultValue true
|
|
16
|
+
* @alpha
|
|
17
|
+
*/
|
|
18
|
+
unstable__noScript?: NextStudioLoadingProps['unstable__noScript']
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render
|
|
22
|
+
* It's a drop-in replacement for `import {Studio} from 'sanity'`
|
|
23
|
+
*/
|
|
24
|
+
const NextStudioComponent = ({
|
|
25
|
+
children,
|
|
26
|
+
config,
|
|
27
|
+
unstable__noScript,
|
|
28
|
+
scheme,
|
|
29
|
+
...props
|
|
30
|
+
}: NextStudioProps) => (
|
|
31
|
+
<NextStudioClientOnly
|
|
32
|
+
fallback={
|
|
33
|
+
<NextStudioLoading
|
|
34
|
+
unstable__noScript={unstable__noScript}
|
|
35
|
+
config={config}
|
|
36
|
+
scheme={scheme}
|
|
37
|
+
/>
|
|
38
|
+
}
|
|
39
|
+
>
|
|
40
|
+
<NextStudioLayout config={config} scheme={scheme}>
|
|
41
|
+
{children || <Studio config={config} scheme={scheme} unstable_globalStyles {...props} />}
|
|
42
|
+
</NextStudioLayout>
|
|
43
|
+
</NextStudioClientOnly>
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Override how the Studio renders by passing children.
|
|
48
|
+
* This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:
|
|
49
|
+
* ```
|
|
50
|
+
* import {StudioProvider, StudioLayout} from 'sanity'
|
|
51
|
+
* import {NextStudio} from 'next-sanity/studio'
|
|
52
|
+
* <NextStudio config={config}>
|
|
53
|
+
* <StudioProvider config={config}>
|
|
54
|
+
* <CustomComponentThatUsesContextFromStudioProvider />
|
|
55
|
+
* <StudioLayout />
|
|
56
|
+
* </StudioProvider>
|
|
57
|
+
* </NextStudio>
|
|
58
|
+
* ```
|
|
59
|
+
* @beta
|
|
60
|
+
*/
|
|
61
|
+
export const NextStudio = memo(NextStudioComponent)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {type ReactNode, startTransition, useEffect, useState} from 'react'
|
|
2
|
+
|
|
3
|
+
/** @alpha */
|
|
4
|
+
export type NextStudioClientOnlyProps = {
|
|
5
|
+
children: ReactNode
|
|
6
|
+
fallback: ReactNode
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** @alpha */
|
|
10
|
+
export function NextStudioClientOnly({children, fallback}: NextStudioClientOnlyProps) {
|
|
11
|
+
const [mounted, setMounted] = useState(false)
|
|
12
|
+
useEffect(() => startTransition(() => setMounted(true)), [])
|
|
13
|
+
|
|
14
|
+
return <>{mounted ? children : fallback}</>
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import {memo} from 'react'
|
|
3
|
+
import type {StudioProps} from 'sanity'
|
|
4
|
+
import styled from 'styled-components'
|
|
5
|
+
|
|
6
|
+
import {useTheme} from './useTheme'
|
|
7
|
+
|
|
8
|
+
/** @alpha */
|
|
9
|
+
export interface NextStudioLayoutProps extends Pick<StudioProps, 'config' | 'scheme'> {
|
|
10
|
+
children: React.ReactNode
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type LayoutProps = {
|
|
14
|
+
$bg: string
|
|
15
|
+
$fontFamily: string
|
|
16
|
+
}
|
|
17
|
+
const Layout = styled.div<LayoutProps>`
|
|
18
|
+
font-family: ${({$fontFamily}) => $fontFamily};
|
|
19
|
+
background-color: ${({$bg}: any) => $bg};
|
|
20
|
+
height: 100vh;
|
|
21
|
+
max-height: 100dvh;
|
|
22
|
+
overscroll-behavior: none;
|
|
23
|
+
-webkit-font-smoothing: antialiased;
|
|
24
|
+
overflow: auto;
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
const NextStudioLayoutComponent = ({
|
|
28
|
+
children,
|
|
29
|
+
config,
|
|
30
|
+
scheme = 'light',
|
|
31
|
+
}: NextStudioLayoutProps) => {
|
|
32
|
+
const theme = useTheme(config)
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Layout
|
|
36
|
+
data-ui="NextStudioLayout"
|
|
37
|
+
$fontFamily={theme.fonts.text.family}
|
|
38
|
+
$bg={theme.color[scheme].default.base.bg}
|
|
39
|
+
>
|
|
40
|
+
{children}
|
|
41
|
+
</Layout>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @alpha */
|
|
46
|
+
export const NextStudioLayout = memo(NextStudioLayoutComponent)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/* eslint-disable no-warning-comments */
|
|
2
|
+
// Intentionally not using `styled-components` to ensure it works in any `next` setup.
|
|
3
|
+
// Whether 'styled-components' SSR is setup or not.
|
|
4
|
+
|
|
5
|
+
import {SpinnerIcon} from '@sanity/icons'
|
|
6
|
+
import {_responsive, rem} from '@sanity/ui'
|
|
7
|
+
import type {Config, SingleWorkspace, StudioProps} from 'sanity'
|
|
8
|
+
|
|
9
|
+
import {NextStudioNoScript} from './NextStudioNoScript'
|
|
10
|
+
import {useTheme} from './useTheme'
|
|
11
|
+
|
|
12
|
+
/** @alpha */
|
|
13
|
+
export interface NextStudioLoadingProps extends Pick<StudioProps, 'scheme'> {
|
|
14
|
+
/**
|
|
15
|
+
* If your Studio Config has a custom theme you can pass it here to ensure the loading screen matches your theme.
|
|
16
|
+
*/
|
|
17
|
+
config?: Config | Required<Pick<SingleWorkspace, 'theme'>>
|
|
18
|
+
/**
|
|
19
|
+
* Render the <noscript> tag
|
|
20
|
+
* @defaultValue true
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
unstable__noScript?: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const keyframes = `
|
|
27
|
+
from {
|
|
28
|
+
transform: rotate(0deg);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
to {
|
|
32
|
+
transform: rotate(360deg);
|
|
33
|
+
}
|
|
34
|
+
`
|
|
35
|
+
|
|
36
|
+
export function NextStudioLoading(props: NextStudioLoadingProps) {
|
|
37
|
+
const {config, scheme = 'light', unstable__noScript = true} = props
|
|
38
|
+
const id = 'next-sanity-spinner'
|
|
39
|
+
const theme = useTheme(config)
|
|
40
|
+
const {fonts, media} = theme
|
|
41
|
+
|
|
42
|
+
const styles: any = _responsive(media, [2], (size: number) => {
|
|
43
|
+
const {ascenderHeight, descenderHeight, lineHeight, iconSize} = fonts.text.sizes[size]
|
|
44
|
+
const capHeight = lineHeight - ascenderHeight - descenderHeight
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
wrapper: {
|
|
48
|
+
display: 'block',
|
|
49
|
+
animation: `${id} 500ms linear infinite`,
|
|
50
|
+
color: theme.color[scheme].default.muted.default.enabled.muted.fg,
|
|
51
|
+
width: rem(capHeight),
|
|
52
|
+
height: rem(capHeight),
|
|
53
|
+
},
|
|
54
|
+
svg: {
|
|
55
|
+
display: 'block',
|
|
56
|
+
width: rem(iconSize),
|
|
57
|
+
height: rem(iconSize),
|
|
58
|
+
margin: (capHeight - iconSize) / 2,
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
})[0]
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<>
|
|
65
|
+
{unstable__noScript && <NextStudioNoScript />}
|
|
66
|
+
<div
|
|
67
|
+
style={{
|
|
68
|
+
fontFamily: fonts.text.family,
|
|
69
|
+
backgroundColor: theme.color[scheme].default.base.bg,
|
|
70
|
+
height: '100vh',
|
|
71
|
+
maxHeight: '100dvh',
|
|
72
|
+
overscrollBehavior: 'none',
|
|
73
|
+
WebkitFontSmoothing: 'antialiased',
|
|
74
|
+
overflow: 'auto',
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
<div
|
|
78
|
+
data-ui="Flex"
|
|
79
|
+
style={{
|
|
80
|
+
display: 'flex',
|
|
81
|
+
minWidth: 0,
|
|
82
|
+
minHeight: 0,
|
|
83
|
+
alignItems: 'center',
|
|
84
|
+
justifyContent: 'center',
|
|
85
|
+
flexDirection: 'column',
|
|
86
|
+
height: '100%',
|
|
87
|
+
margin: 0,
|
|
88
|
+
padding: 0,
|
|
89
|
+
// @TODO use rem calc
|
|
90
|
+
gap: '10px',
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<style key={scheme}>{`@keyframes ${id} {${keyframes}}`}</style>
|
|
94
|
+
<div
|
|
95
|
+
data-ui="Text"
|
|
96
|
+
style={{
|
|
97
|
+
position: 'relative',
|
|
98
|
+
// @TODO read from theme
|
|
99
|
+
fontWeight: 400,
|
|
100
|
+
// @TODO read from theme
|
|
101
|
+
padding: '1px 0px',
|
|
102
|
+
// @TODO use rem calc
|
|
103
|
+
fontSize: '1rem',
|
|
104
|
+
// @TODO use rem calc
|
|
105
|
+
lineHeight: 'calc(1.3125)',
|
|
106
|
+
// @TODO use rem calc
|
|
107
|
+
transform: 'translateY(-5px)',
|
|
108
|
+
color: theme.color[scheme].default.muted.default.enabled.muted.fg,
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<span>Loading…</span>
|
|
112
|
+
</div>
|
|
113
|
+
<div data-ui="Spinner" style={styles.wrapper}>
|
|
114
|
+
<SpinnerIcon style={styles.svg} />
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
</>
|
|
119
|
+
)
|
|
120
|
+
}
|