@sanity/sdk-react 0.0.0-alpha.28 → 0.0.0-alpha.29

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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"stegaEncodeSourceMap.js","sources":["../../../../node_modules/.pnpm/@sanity+client@6.29.0/node_modules/@sanity/client/dist/_chunks-es/stegaEncodeSourceMap.js"],"sourcesContent":["import { C } from \"./stegaClean.js\";\nconst reKeySegment = /_key\\s*==\\s*['\"](.*)['\"]/;\nfunction isKeySegment(segment) {\n return typeof segment == \"string\" ? reKeySegment.test(segment.trim()) : typeof segment == \"object\" && \"_key\" in segment;\n}\nfunction toString(path) {\n if (!Array.isArray(path))\n throw new Error(\"Path is not an array\");\n return path.reduce((target, segment, i) => {\n const segmentType = typeof segment;\n if (segmentType === \"number\")\n return `${target}[${segment}]`;\n if (segmentType === \"string\")\n return `${target}${i === 0 ? \"\" : \".\"}${segment}`;\n if (isKeySegment(segment) && segment._key)\n return `${target}[_key==\"${segment._key}\"]`;\n if (Array.isArray(segment)) {\n const [from, to] = segment;\n return `${target}[${from}:${to}]`;\n }\n throw new Error(`Unsupported path segment \\`${JSON.stringify(segment)}\\``);\n }, \"\");\n}\nconst ESCAPE = {\n \"\\f\": \"\\\\f\",\n \"\\n\": \"\\\\n\",\n \"\\r\": \"\\\\r\",\n \"\t\": \"\\\\t\",\n \"'\": \"\\\\'\",\n \"\\\\\": \"\\\\\\\\\"\n}, UNESCAPE = {\n \"\\\\f\": \"\\f\",\n \"\\\\n\": `\n`,\n \"\\\\r\": \"\\r\",\n \"\\\\t\": \"\t\",\n \"\\\\'\": \"'\",\n \"\\\\\\\\\": \"\\\\\"\n};\nfunction jsonPath(path) {\n return `$${path.map((segment) => typeof segment == \"string\" ? `['${segment.replace(/[\\f\\n\\r\\t'\\\\]/g, (match) => ESCAPE[match])}']` : typeof segment == \"number\" ? `[${segment}]` : segment._key !== \"\" ? `[?(@._key=='${segment._key.replace(/['\\\\]/g, (match) => ESCAPE[match])}')]` : `[${segment._index}]`).join(\"\")}`;\n}\nfunction parseJsonPath(path) {\n const parsed = [], parseRe = /\\['(.*?)'\\]|\\[(\\d+)\\]|\\[\\?\\(@\\._key=='(.*?)'\\)\\]/g;\n let match;\n for (; (match = parseRe.exec(path)) !== null; ) {\n if (match[1] !== void 0) {\n const key = match[1].replace(/\\\\(\\\\|f|n|r|t|')/g, (m) => UNESCAPE[m]);\n parsed.push(key);\n continue;\n }\n if (match[2] !== void 0) {\n parsed.push(parseInt(match[2], 10));\n continue;\n }\n if (match[3] !== void 0) {\n const _key = match[3].replace(/\\\\(\\\\')/g, (m) => UNESCAPE[m]);\n parsed.push({\n _key,\n _index: -1\n });\n continue;\n }\n }\n return parsed;\n}\nfunction jsonPathToStudioPath(path) {\n return path.map((segment) => {\n if (typeof segment == \"string\" || typeof segment == \"number\")\n return segment;\n if (segment._key !== \"\")\n return { _key: segment._key };\n if (segment._index !== -1)\n return segment._index;\n throw new Error(`invalid segment:${JSON.stringify(segment)}`);\n });\n}\nfunction jsonPathToMappingPath(path) {\n return path.map((segment) => {\n if (typeof segment == \"string\" || typeof segment == \"number\")\n return segment;\n if (segment._index !== -1)\n return segment._index;\n throw new Error(`invalid segment:${JSON.stringify(segment)}`);\n });\n}\nfunction resolveMapping(resultPath, csm) {\n if (!csm?.mappings)\n return;\n const resultMappingPath = jsonPath(jsonPathToMappingPath(resultPath));\n if (csm.mappings[resultMappingPath] !== void 0)\n return {\n mapping: csm.mappings[resultMappingPath],\n matchedPath: resultMappingPath,\n pathSuffix: \"\"\n };\n const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length);\n if (mappings.length == 0)\n return;\n const [matchedPath, mapping] = mappings[0], pathSuffix = resultMappingPath.substring(matchedPath.length);\n return { mapping, matchedPath, pathSuffix };\n}\nfunction isArray(value) {\n return value !== null && Array.isArray(value);\n}\nfunction isRecord(value) {\n return typeof value == \"object\" && value !== null;\n}\nfunction walkMap(value, mappingFn, path = []) {\n if (isArray(value))\n return value.map((v, idx) => {\n if (isRecord(v)) {\n const _key = v._key;\n if (typeof _key == \"string\")\n return walkMap(v, mappingFn, path.concat({ _key, _index: idx }));\n }\n return walkMap(v, mappingFn, path.concat(idx));\n });\n if (isRecord(value)) {\n if (value._type === \"block\" || value._type === \"span\") {\n const result = { ...value };\n return value._type === \"block\" ? result.children = walkMap(value.children, mappingFn, path.concat(\"children\")) : value._type === \"span\" && (result.text = walkMap(value.text, mappingFn, path.concat(\"text\"))), result;\n }\n return Object.fromEntries(\n Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))])\n );\n }\n return mappingFn(value, path);\n}\nfunction encodeIntoResult(result, csm, encoder) {\n return walkMap(result, (value, path) => {\n if (typeof value != \"string\")\n return value;\n const resolveMappingResult = resolveMapping(path, csm);\n if (!resolveMappingResult)\n return value;\n const { mapping, matchedPath } = resolveMappingResult;\n if (mapping.type !== \"value\" || mapping.source.type !== \"documentValue\")\n return value;\n const sourceDocument = csm.documents[mapping.source.document], sourcePath = csm.paths[mapping.source.path], matchPathSegments = parseJsonPath(matchedPath), fullSourceSegments = parseJsonPath(sourcePath).concat(path.slice(matchPathSegments.length));\n return encoder({\n sourcePath: fullSourceSegments,\n sourceDocument,\n resultPath: path,\n value\n });\n });\n}\nconst DRAFTS_FOLDER = \"drafts\", VERSION_FOLDER = \"versions\", PATH_SEPARATOR = \".\", DRAFTS_PREFIX = `${DRAFTS_FOLDER}${PATH_SEPARATOR}`, VERSION_PREFIX = `${VERSION_FOLDER}${PATH_SEPARATOR}`;\nfunction isDraftId(id) {\n return id.startsWith(DRAFTS_PREFIX);\n}\nfunction isVersionId(id) {\n return id.startsWith(VERSION_PREFIX);\n}\nfunction isPublishedId(id) {\n return !isDraftId(id) && !isVersionId(id);\n}\nfunction getVersionFromId(id) {\n if (!isVersionId(id)) return;\n const [_versionPrefix, versionId, ..._publishedId] = id.split(PATH_SEPARATOR);\n return versionId;\n}\nfunction getPublishedId(id) {\n return isVersionId(id) ? id.split(PATH_SEPARATOR).slice(2).join(PATH_SEPARATOR) : isDraftId(id) ? id.slice(DRAFTS_PREFIX.length) : id;\n}\nfunction createEditUrl(options) {\n const {\n baseUrl,\n workspace: _workspace = \"default\",\n tool: _tool = \"default\",\n id: _id,\n type,\n path,\n projectId,\n dataset\n } = options;\n if (!baseUrl)\n throw new Error(\"baseUrl is required\");\n if (!path)\n throw new Error(\"path is required\");\n if (!_id)\n throw new Error(\"id is required\");\n if (baseUrl !== \"/\" && baseUrl.endsWith(\"/\"))\n throw new Error(\"baseUrl must not end with a slash\");\n const workspace = _workspace === \"default\" ? void 0 : _workspace, tool = _tool === \"default\" ? void 0 : _tool, id = getPublishedId(_id), stringifiedPath = Array.isArray(path) ? toString(jsonPathToStudioPath(path)) : path, searchParams = new URLSearchParams({\n baseUrl,\n id,\n type,\n path: stringifiedPath\n });\n if (workspace && searchParams.set(\"workspace\", workspace), tool && searchParams.set(\"tool\", tool), projectId && searchParams.set(\"projectId\", projectId), dataset && searchParams.set(\"dataset\", dataset), isPublishedId(_id))\n searchParams.set(\"perspective\", \"published\");\n else if (isVersionId(_id)) {\n const versionId = getVersionFromId(_id);\n searchParams.set(\"perspective\", versionId);\n }\n const segments = [baseUrl === \"/\" ? \"\" : baseUrl];\n workspace && segments.push(workspace);\n const routerParams = [\n \"mode=presentation\",\n `id=${id}`,\n `type=${type}`,\n `path=${encodeURIComponent(stringifiedPath)}`\n ];\n return tool && routerParams.push(`tool=${tool}`), segments.push(\"intent\", \"edit\", `${routerParams.join(\";\")}?${searchParams}`), segments.join(\"/\");\n}\nfunction resolveStudioBaseRoute(studioUrl) {\n let baseUrl = typeof studioUrl == \"string\" ? studioUrl : studioUrl.baseUrl;\n return baseUrl !== \"/\" && (baseUrl = baseUrl.replace(/\\/$/, \"\")), typeof studioUrl == \"string\" ? { baseUrl } : { ...studioUrl, baseUrl };\n}\nconst filterDefault = ({ sourcePath, resultPath, value }) => {\n if (isValidDate(value) || isValidURL(value))\n return !1;\n const endPath = sourcePath.at(-1);\n return !(sourcePath.at(-2) === \"slug\" && endPath === \"current\" || typeof endPath == \"string\" && (endPath.startsWith(\"_\") || endPath.endsWith(\"Id\")) || sourcePath.some(\n (path) => path === \"meta\" || path === \"metadata\" || path === \"openGraph\" || path === \"seo\"\n ) || hasTypeLike(sourcePath) || hasTypeLike(resultPath) || typeof endPath == \"string\" && denylist.has(endPath));\n}, denylist = /* @__PURE__ */ new Set([\n \"color\",\n \"colour\",\n \"currency\",\n \"email\",\n \"format\",\n \"gid\",\n \"hex\",\n \"href\",\n \"hsl\",\n \"hsla\",\n \"icon\",\n \"id\",\n \"index\",\n \"key\",\n \"language\",\n \"layout\",\n \"link\",\n \"linkAction\",\n \"locale\",\n \"lqip\",\n \"page\",\n \"path\",\n \"ref\",\n \"rgb\",\n \"rgba\",\n \"route\",\n \"secret\",\n \"slug\",\n \"status\",\n \"tag\",\n \"template\",\n \"theme\",\n \"type\",\n \"textTheme\",\n \"unit\",\n \"url\",\n \"username\",\n \"variant\",\n \"website\"\n]);\nfunction isValidDate(dateString) {\n return /^\\d{4}-\\d{2}-\\d{2}/.test(dateString) ? !!Date.parse(dateString) : !1;\n}\nfunction isValidURL(url) {\n try {\n new URL(url, url.startsWith(\"/\") ? \"https://acme.com\" : void 0);\n } catch {\n return !1;\n }\n return !0;\n}\nfunction hasTypeLike(path) {\n return path.some((segment) => typeof segment == \"string\" && segment.match(/type/i) !== null);\n}\nconst TRUNCATE_LENGTH = 20;\nfunction stegaEncodeSourceMap(result, resultSourceMap, config) {\n const { filter, logger, enabled } = config;\n if (!enabled) {\n const msg = \"config.enabled must be true, don't call this function otherwise\";\n throw logger?.error?.(`[@sanity/client]: ${msg}`, { result, resultSourceMap, config }), new TypeError(msg);\n }\n if (!resultSourceMap)\n return logger?.error?.(\"[@sanity/client]: Missing Content Source Map from response body\", {\n result,\n resultSourceMap,\n config\n }), result;\n if (!config.studioUrl) {\n const msg = \"config.studioUrl must be defined\";\n throw logger?.error?.(`[@sanity/client]: ${msg}`, { result, resultSourceMap, config }), new TypeError(msg);\n }\n const report = {\n encoded: [],\n skipped: []\n }, resultWithStega = encodeIntoResult(\n result,\n resultSourceMap,\n ({ sourcePath, sourceDocument, resultPath, value }) => {\n if ((typeof filter == \"function\" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, value })) === !1)\n return logger && report.skipped.push({\n path: prettyPathForLogging(sourcePath),\n value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? \"...\" : \"\"}`,\n length: value.length\n }), value;\n logger && report.encoded.push({\n path: prettyPathForLogging(sourcePath),\n value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? \"...\" : \"\"}`,\n length: value.length\n });\n const { baseUrl, workspace, tool } = resolveStudioBaseRoute(\n typeof config.studioUrl == \"function\" ? config.studioUrl(sourceDocument) : config.studioUrl\n );\n if (!baseUrl) return value;\n const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;\n return C(\n value,\n {\n origin: \"sanity.io\",\n href: createEditUrl({\n baseUrl,\n workspace,\n tool,\n id,\n type,\n path: sourcePath,\n ...!config.omitCrossDatasetReferenceData && { dataset, projectId }\n })\n },\n // We use custom logic to determine if we should skip encoding\n !1\n );\n }\n );\n if (logger) {\n const isSkipping = report.skipped.length, isEncoding = report.encoded.length;\n if ((isSkipping || isEncoding) && ((logger?.groupCollapsed || logger.log)?.(\"[@sanity/client]: Encoding source map into result\"), logger.log?.(\n `[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`\n )), report.encoded.length > 0 && (logger?.log?.(\"[@sanity/client]: Table of encoded paths\"), (logger?.table || logger.log)?.(report.encoded)), report.skipped.length > 0) {\n const skipped = /* @__PURE__ */ new Set();\n for (const { path } of report.skipped)\n skipped.add(path.replace(reKeySegment, \"0\").replace(/\\[\\d+\\]/g, \"[]\"));\n logger?.log?.(\"[@sanity/client]: List of skipped paths\", [...skipped.values()]);\n }\n (isSkipping || isEncoding) && logger?.groupEnd?.();\n }\n return resultWithStega;\n}\nfunction prettyPathForLogging(path) {\n return toString(jsonPathToStudioPath(path));\n}\nvar stegaEncodeSourceMap$1 = /* @__PURE__ */ Object.freeze({\n __proto__: null,\n stegaEncodeSourceMap\n});\nexport {\n encodeIntoResult,\n stegaEncodeSourceMap,\n stegaEncodeSourceMap$1\n};\n//# sourceMappingURL=stegaEncodeSourceMap.js.map\n"],"names":["reKeySegment","isKeySegment","segment","test","trim","toString","path","Array","isArray","Error","reduce","target","i","segmentType","_key","from","to","JSON","stringify"],"mappings":";AAeO,MAAMA,eAAe;AASrB,SAASC,aAAaC,SAA+C;AAC1E,SAAI,OAAOA,WAAY,WACdF,aAAaG,KAAKD,QAAQE,KAAA,CAAM,IAGlC,OAAOF,WAAY,YAAY,UAAUA;AAClD;AA8DO,SAASG,SAASC,MAAoB;AACvC,MAACC,CAAAA,MAAMC,QAAQF,IAAI,EACf,OAAA,IAAIG,MAAM,sBAAsB;AAGxC,SAAOH,KAAKI,OAAe,CAACC,QAAQT,SAASU,MAAM;AACjD,UAAMC,cAAc,OAAOX;AAC3B,QAAIW,gBAAgB,SACX,QAAGF,GAAAA,MAAM,IAAIT,OAAO;AAG7B,QAAIW,gBAAgB,SAEX,QAAA,GAAGF,MAAM,GADEC,MAAM,IAAI,KAAK,GACL,GAAGV,OAAO;AAGpC,QAAAD,aAAaC,OAAO,KAAKA,QAAQY,KACnC,QAAO,GAAGH,MAAM,WAAWT,QAAQY,IAAI;AAGrC,QAAAP,MAAMC,QAAQN,OAAO,GAAG;AACpB,YAAA,CAACa,MAAMC,EAAE,IAAId;AACnB,aAAO,GAAGS,MAAM,IAAII,IAAI,IAAIC,EAAE;AAAA,IAAA;AAGhC,UAAM,IAAIP,MAAM,8BAA8BQ,KAAKC,UAAUhB,OAAO,CAAC,IAAI;AAAA,EAAA,GACxE,EAAE;AACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_google_ignoreList":[0]}
@@ -1,19 +0,0 @@
1
- import {render, screen} from '@testing-library/react'
2
- import {describe, expect, it} from 'vitest'
3
-
4
- import {ResourceProvider} from '../../context/ResourceProvider'
5
- import {LoginFooter} from './LoginFooter'
6
-
7
- describe('LoginFooter', () => {
8
- it('renders footer links', () => {
9
- render(
10
- <ResourceProvider fallback={null}>
11
- <LoginFooter />
12
- </ResourceProvider>,
13
- )
14
- expect(screen.getByText('Community')).toBeInTheDocument()
15
- expect(screen.getByText('Docs')).toBeInTheDocument()
16
- expect(screen.getByText('Privacy')).toBeInTheDocument()
17
- expect(screen.getByText('sanity.io')).toBeInTheDocument()
18
- })
19
- })
@@ -1,51 +0,0 @@
1
- import {SanityLogo} from '@sanity/logos'
2
- import {Fragment} from 'react'
3
-
4
- const LINKS = [
5
- {
6
- url: 'https://slack.sanity.io/',
7
- i18nKey: 'workspaces.community-title',
8
- title: 'Community',
9
- },
10
- {
11
- url: 'https://www.sanity.io/docs',
12
- i18nKey: 'workspaces.docs-title',
13
- title: 'Docs',
14
- },
15
- {
16
- url: 'https://www.sanity.io/legal/privacy',
17
- i18nKey: 'workspaces.privacy-title',
18
- title: 'Privacy',
19
- },
20
- {
21
- url: 'https://www.sanity.io',
22
- i18nKey: 'workspaces.sanity-io-title',
23
- title: 'sanity.io',
24
- },
25
- ]
26
-
27
- /**
28
- * Default footer component for login screens showing Sanity branding and legal
29
- * links.
30
- *
31
- * @alpha
32
- */
33
- export function LoginFooter(): React.ReactNode {
34
- return (
35
- <div className="sc-login-footer">
36
- <SanityLogo className="sc-login-footer__logo" />
37
-
38
- <ul className="sc-login-footer__links">
39
- {LINKS.map((link) => (
40
- <Fragment key={link.title}>
41
- <li className="sc-login-footer__link">
42
- <a href={link.url} target="_blank" rel="noopener noreferrer">
43
- {link.title}
44
- </a>
45
- </li>
46
- </Fragment>
47
- ))}
48
- </ul>
49
- </div>
50
- )
51
- }