tinacms 2.7.6 → 2.7.7
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/dist/client.js +1 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +1 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.js +28 -23
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +27 -22
- package/dist/index.mjs.map +1 -0
- package/dist/node-cache-5e8db9f0.mjs +1 -0
- package/dist/node-cache-5e8db9f0.mjs.map +1 -0
- package/dist/react.js +1 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +1 -0
- package/dist/react.mjs.map +1 -0
- package/dist/rich-text/index.js +1 -0
- package/dist/rich-text/index.js.map +1 -0
- package/dist/rich-text/index.mjs +1 -0
- package/dist/rich-text/index.mjs.map +1 -0
- package/dist/rich-text/prism.js +2 -1
- package/dist/rich-text/prism.js.map +1 -0
- package/dist/rich-text/prism.mjs +2 -1
- package/dist/rich-text/prism.mjs.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-cache-5e8db9f0.mjs","sources":["../src/cache/node-cache.ts"],"sourcesContent":["import type { Cache } from './index';\n\n// Create the cache directory if it doesn't exist.\n// Returns the path of the cache directory.\nexport const makeCacheDir = async (\n dir: string,\n fs: any,\n path: any,\n os: any\n) => {\n const pathParts = dir.split(path.sep).filter(Boolean);\n const cacheHash = pathParts[pathParts.length - 1];\n const rootUser = pathParts[0];\n let cacheDir = dir;\n\n // Check if the root directory exists. If not, create the cache in the tmp directory.\n if (!fs.existsSync(path.join(path.sep, rootUser))) {\n cacheDir = path.join(os.tmpdir(), cacheHash);\n }\n\n try {\n fs.mkdirSync(cacheDir, { recursive: true });\n } catch (error) {\n throw new Error(`Failed to create cache directory: ${error.message}`);\n }\n\n return cacheDir;\n};\n\nexport const NodeCache = async (dir: string): Promise<Cache> => {\n // TODO: These will need to be changed from using require to import when we eventually move to ESM\n const fs = require('node:fs');\n const path = require('node:path');\n const os = require('node:os');\n\n const { createHash } = require('node:crypto');\n const cacheDir = await makeCacheDir(dir, fs, path, os);\n\n return {\n makeKey: (key: any) => {\n const input =\n key && key instanceof Object ? JSON.stringify(key) : key || '';\n return createHash('sha256').update(input).digest('hex');\n },\n get: async (key: string) => {\n let readValue: object | undefined;\n\n const cacheFilename = `${cacheDir}/${key}`;\n try {\n const data = await fs.promises.readFile(cacheFilename, 'utf-8');\n readValue = JSON.parse(data);\n } catch (e) {\n if (e.code !== 'ENOENT') {\n console.error(\n `Failed to read cache file to ${cacheFilename}: ${e.message}`\n );\n }\n }\n\n return readValue;\n },\n set: async (key: string, value: any) => {\n const cacheFilename = `${cacheDir}/${key}`;\n try {\n await fs.promises.writeFile(cacheFilename, JSON.stringify(value), {\n encoding: 'utf-8',\n flag: 'wx', // Don't overwrite existing caches\n });\n } catch (e) {\n if (e.code !== 'EEXIST') {\n console.error(\n `Failed to write cache file to ${cacheFilename}: ${e.message}`\n );\n }\n }\n },\n };\n};\n"],"names":[],"mappings":"AAIO,MAAM,eAAe,OAC1B,KACA,IACA,MACA,OACG;AACH,QAAM,YAAY,IAAI,MAAM,KAAK,GAAG,EAAE,OAAO,OAAO;AACpD,QAAM,YAAY,UAAU,UAAU,SAAS,CAAC;AAC1C,QAAA,WAAW,UAAU,CAAC;AAC5B,MAAI,WAAW;AAGX,MAAA,CAAC,GAAG,WAAW,KAAK,KAAK,KAAK,KAAK,QAAQ,CAAC,GAAG;AACjD,eAAW,KAAK,KAAK,GAAG,OAAA,GAAU,SAAS;AAAA,EAC7C;AAEI,MAAA;AACF,OAAG,UAAU,UAAU,EAAE,WAAW,KAAM,CAAA;AAAA,WACnC,OAAO;AACd,UAAM,IAAI,MAAM,qCAAqC,MAAM,OAAO,EAAE;AAAA,EACtE;AAEO,SAAA;AACT;AAEa,MAAA,YAAY,OAAO,QAAgC;AAExD,QAAA,KAAK,QAAQ,SAAS;AACtB,QAAA,OAAO,QAAQ,WAAW;AAC1B,QAAA,KAAK,QAAQ,SAAS;AAE5B,QAAM,EAAE,WAAA,IAAe,QAAQ,aAAa;AAC5C,QAAM,WAAW,MAAM,aAAa,KAAK,IAAI,MAAM,EAAE;AAE9C,SAAA;AAAA,IACL,SAAS,CAAC,QAAa;AACf,YAAA,QACJ,OAAO,eAAe,SAAS,KAAK,UAAU,GAAG,IAAI,OAAO;AAC9D,aAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA,IACxD;AAAA,IACA,KAAK,OAAO,QAAgB;AACtB,UAAA;AAEJ,YAAM,gBAAgB,GAAG,QAAQ,IAAI,GAAG;AACpC,UAAA;AACF,cAAM,OAAO,MAAM,GAAG,SAAS,SAAS,eAAe,OAAO;AAClD,oBAAA,KAAK,MAAM,IAAI;AAAA,eACpB,GAAG;AACN,YAAA,EAAE,SAAS,UAAU;AACf,kBAAA;AAAA,YACN,gCAAgC,aAAa,KAAK,EAAE,OAAO;AAAA,UAAA;AAAA,QAE/D;AAAA,MACF;AAEO,aAAA;AAAA,IACT;AAAA,IACA,KAAK,OAAO,KAAa,UAAe;AACtC,YAAM,gBAAgB,GAAG,QAAQ,IAAI,GAAG;AACpC,UAAA;AACF,cAAM,GAAG,SAAS,UAAU,eAAe,KAAK,UAAU,KAAK,GAAG;AAAA,UAChE,UAAU;AAAA,UACV,MAAM;AAAA;AAAA,QAAA,CACP;AAAA,eACM,GAAG;AACN,YAAA,EAAE,SAAS,UAAU;AACf,kBAAA;AAAA,YACN,iCAAiC,aAAa,KAAK,EAAE,OAAO;AAAA,UAAA;AAAA,QAEhE;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
package/dist/react.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sources":["../src/react.tsx"],"sourcesContent":["import React from 'react';\n\nexport function useTina<T extends object>(props: {\n query: string;\n variables: object;\n data: T;\n experimental___selectFormByFormId?: () => string | false | undefined;\n}): { data: T; isClient: boolean } {\n const stringifiedQuery = JSON.stringify({\n query: props.query,\n variables: props.variables,\n });\n const id = React.useMemo(\n () => hashFromQuery(stringifiedQuery),\n [stringifiedQuery]\n );\n const [data, setData] = React.useState(props.data);\n const [isClient, setIsClient] = React.useState(false);\n const [quickEditEnabled, setQuickEditEnabled] = React.useState(false);\n const [isInTinaIframe, setIsInTinaIframe] = React.useState(false);\n\n React.useEffect(() => {\n setIsClient(true);\n setData(props.data);\n parent.postMessage({\n type: 'url-changed',\n });\n }, [id]);\n\n React.useEffect(() => {\n if (quickEditEnabled) {\n const style = document.createElement('style');\n style.type = 'text/css';\n style.textContent = `\n [data-tina-field] {\n outline: 2px dashed rgba(34,150,254,0.5);\n transition: box-shadow ease-out 150ms;\n }\n [data-tina-field]:hover {\n box-shadow: inset 100vi 100vh rgba(34,150,254,0.3);\n outline: 2px solid rgba(34,150,254,1);\n cursor: pointer;\n }\n [data-tina-field-overlay] {\n outline: 2px dashed rgba(34,150,254,0.5);\n position: relative;\n }\n [data-tina-field-overlay]:hover {\n cursor: pointer;\n outline: 2px solid rgba(34,150,254,1);\n }\n [data-tina-field-overlay]::after {\n content: '';\n position: absolute;\n inset: 0;\n z-index: 20;\n transition: opacity ease-out 150ms;\n background-color: rgba(34,150,254,0.3);\n opacity: 0;\n }\n [data-tina-field-overlay]:hover::after {\n opacity: 1;\n }\n `;\n document.head.appendChild(style);\n document.body.classList.add('__tina-quick-editing-enabled');\n\n function mouseDownHandler(e) {\n const attributeNames = e.target.getAttributeNames();\n // If multiple attributes start with data-tina-field, only the first is used\n const tinaAttribute = attributeNames.find((name) =>\n name.startsWith('data-tina-field')\n );\n let fieldName;\n if (tinaAttribute) {\n e.preventDefault();\n e.stopPropagation();\n fieldName = e.target.getAttribute(tinaAttribute);\n } else {\n const ancestor = e.target.closest(\n '[data-tina-field], [data-tina-field-overlay]'\n );\n if (ancestor) {\n const attributeNames = ancestor.getAttributeNames();\n const tinaAttribute = attributeNames.find((name) =>\n name.startsWith('data-tina-field')\n );\n if (tinaAttribute) {\n e.preventDefault();\n e.stopPropagation();\n fieldName = ancestor.getAttribute(tinaAttribute);\n }\n }\n }\n if (fieldName) {\n if (isInTinaIframe) {\n parent.postMessage(\n { type: 'field:selected', fieldName: fieldName },\n window.location.origin\n );\n } else {\n // if (preview?.redirect) {\n // const tinaAdminBasePath = preview.redirect.startsWith('/')\n // ? preview.redirect\n // : `/${preview.redirect}`\n // const tinaAdminPath = `${tinaAdminBasePath}/index.html#/~${window.location.pathname}?active-field=${fieldName}`\n // window.location.assign(tinaAdminPath)\n // }\n }\n }\n }\n document.addEventListener('click', mouseDownHandler, true);\n\n return () => {\n document.removeEventListener('click', mouseDownHandler, true);\n document.body.classList.remove('__tina-quick-editing-enabled');\n style.remove();\n };\n }\n }, [quickEditEnabled, isInTinaIframe]);\n\n React.useEffect(() => {\n if (props?.experimental___selectFormByFormId) {\n parent.postMessage({\n type: 'user-select-form',\n formId: props.experimental___selectFormByFormId(),\n });\n }\n }, [id]);\n\n React.useEffect(() => {\n const { experimental___selectFormByFormId, ...rest } = props;\n parent.postMessage({ type: 'open', ...rest, id }, window.location.origin);\n window.addEventListener('message', (event) => {\n if (event.data.type === 'quickEditEnabled') {\n setQuickEditEnabled(event.data.value);\n }\n if (event.data.id === id && event.data.type === 'updateData') {\n setData(event.data.data);\n setIsInTinaIframe(true);\n // Ensure we still have a tina-field on the page\n const anyTinaField = document.querySelector('[data-tina-field]');\n if (anyTinaField) {\n parent.postMessage(\n { type: 'quick-edit', value: true },\n window.location.origin\n );\n } else {\n parent.postMessage(\n { type: 'quick-edit', value: false },\n window.location.origin\n );\n }\n }\n });\n\n return () => {\n parent.postMessage({ type: 'close', id }, window.location.origin);\n };\n }, [id, setQuickEditEnabled]);\n\n // Probably don't want to always do this on every data update,\n // Just needs to be done once when in non-edit mode\n // addMetadata(id, data, [])\n\n return { data, isClient };\n}\n\nexport function useEditState(): { edit: boolean } {\n const [edit, setEdit] = React.useState(false);\n React.useEffect(() => {\n if (typeof window !== 'undefined') {\n parent.postMessage({ type: 'isEditMode' }, window.location.origin);\n window.addEventListener('message', (event) => {\n if (event.data?.type === 'tina:editMode') {\n setEdit(true);\n }\n });\n }\n }, []);\n return { edit } as any;\n}\n\n/**\n * Grab the field name for the given attribute\n * to signal to Tina which DOM element the field\n * is working with.\n */\nexport const tinaField = <\n T extends\n | (object & {\n _content_source?: {\n queryId: string;\n path: (number | string)[];\n };\n })\n | undefined\n | null,\n>(\n object: T,\n property?: keyof Omit<NonNullable<T>, '__typename' | '_sys'>,\n index?: number\n) => {\n if (!object) {\n return '';\n }\n if (object._content_source) {\n if (!property) {\n return [\n object._content_source?.queryId,\n object._content_source.path.join('.'),\n ].join('---');\n }\n if (typeof index === 'number') {\n return [\n object._content_source?.queryId,\n [...object._content_source.path, property, index].join('.'),\n ].join('---');\n }\n return [\n object._content_source?.queryId,\n [...object._content_source.path, property].join('.'),\n ].join('---');\n }\n return '';\n};\n\nexport const addMetadata = <T extends object>(\n id: string,\n object: T & { type?: string; _content_source?: unknown },\n path: (string | number)[]\n): T => {\n Object.entries(object).forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (isScalarOrUndefined(item)) {\n return;\n }\n if (Array.isArray(item)) {\n return; // we don't expect arrays of arrays\n }\n const itemObject = item as object;\n addMetadata(id, itemObject, [...path, key, index]);\n });\n } else {\n if (isScalarOrUndefined(value)) {\n return;\n }\n const itemObject = value as object;\n addMetadata(id, itemObject, [...path, key]);\n }\n });\n // This is a rich-text field object\n if (object?.type === 'root') {\n return;\n }\n\n object._content_source = {\n queryId: id,\n path,\n };\n return object;\n};\nfunction isScalarOrUndefined(value: unknown) {\n const type = typeof value;\n if (type === 'string') return true;\n if (type === 'number') return true;\n if (type === 'boolean') return true;\n if (type === 'undefined') return true;\n\n if (value == null) return true;\n if (value instanceof String) return true;\n if (value instanceof Number) return true;\n if (value instanceof Boolean) return true;\n\n return false;\n}\n\n/**\n * This is a pretty rudimentary approach to hashing the query and variables to\n * ensure we treat multiple queries on the page uniquely. It's possible\n * that we would have collisions, and I'm not sure of the likeliness but seems\n * like it'd be rare.\n */\nexport const hashFromQuery = (input: string) => {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash + char) & 0xffffffff; // Apply bitwise AND to ensure non-negative value\n }\n const nonNegativeHash = Math.abs(hash);\n const alphanumericHash = nonNegativeHash.toString(36);\n return alphanumericHash;\n};\n"],"names":["attributeNames","tinaAttribute"],"mappings":";;;;AAEO,WAAS,QAA0B,OAKP;AAC3B,UAAA,mBAAmB,KAAK,UAAU;AAAA,MACtC,OAAO,MAAM;AAAA,MACb,WAAW,MAAM;AAAA,IAAA,CAClB;AACD,UAAM,KAAK,MAAM;AAAA,MACf,MAAM,cAAc,gBAAgB;AAAA,MACpC,CAAC,gBAAgB;AAAA,IAAA;AAEnB,UAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,MAAM,IAAI;AACjD,UAAM,CAAC,UAAU,WAAW,IAAI,MAAM,SAAS,KAAK;AACpD,UAAM,CAAC,kBAAkB,mBAAmB,IAAI,MAAM,SAAS,KAAK;AACpE,UAAM,CAAC,gBAAgB,iBAAiB,IAAI,MAAM,SAAS,KAAK;AAEhE,UAAM,UAAU,MAAM;AACpB,kBAAY,IAAI;AAChB,cAAQ,MAAM,IAAI;AAClB,aAAO,YAAY;AAAA,QACjB,MAAM;AAAA,MAAA,CACP;AAAA,IAAA,GACA,CAAC,EAAE,CAAC;AAEP,UAAM,UAAU,MAAM;AACpB,UAAI,kBAAkB;AAqCX,YAAA,mBAAT,SAA0B,GAAG;AACrB,gBAAA,iBAAiB,EAAE,OAAO,kBAAkB;AAElD,gBAAM,gBAAgB,eAAe;AAAA,YAAK,CAAC,SACzC,KAAK,WAAW,iBAAiB;AAAA,UAAA;AAE/B,cAAA;AACJ,cAAI,eAAe;AACjB,cAAE,eAAe;AACjB,cAA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AAAA,IAAA,CACD;AAEG,SAAA,iCAAQ,UAAS,QAAQ;AAC3B;AAAA,IACF;AAEA,WAAO,kBAAkB;AAAA,MACvB,SAAS;AAAA,MACT;AAAA,IAAA;AAEK,WAAA;AAAA,EACT;AACA,WAAS,oBAAoB,OAAgB;AAC3C,UAAM,OAAO,OAAO;AACpB,QAAI,SAAS;AAAiB,aAAA;AAC9B,QAAI,SAAS;AAAiB,aAAA;AAC9B,QAAI,SAAS;AAAkB,aAAA;AAC/B,QAAI,SAAS;AAAoB,aAAA;AAEjC,QAAI,SAAS;AAAa,aAAA;AAC1B,QAAI,iBAAiB;AAAe,aAAA;AACpC,QAAI,iBAAiB;AAAe,aAAA;AACpC,QAAI,iBAAiB;AAAgB,aAAA;AAE9B,WAAA;AAAA,EACT;AAQa,QAAA,gBAAgB,CAAC,UAAkB;AAC9C,QAAI,OAAO;AACX,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAC/B,YAAA,OAAO,MAAM,WAAW,CAAC;AACtB,cAAA,QAAQ,KAAK,OAAO,OAAQ;AAAA,IACvC;AACM,UAAA,kBAAkB,KAAK,IAAI,IAAI;AAC/B,UAAA,mBAAmB,gBAAgB,SAAS,EAAE;AAC7C,WAAA;AAAA,EACT;;;;;;;;"}
|
package/dist/react.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.mjs","sources":["../src/react.tsx"],"sourcesContent":["import React from 'react';\n\nexport function useTina<T extends object>(props: {\n query: string;\n variables: object;\n data: T;\n experimental___selectFormByFormId?: () => string | false | undefined;\n}): { data: T; isClient: boolean } {\n const stringifiedQuery = JSON.stringify({\n query: props.query,\n variables: props.variables,\n });\n const id = React.useMemo(\n () => hashFromQuery(stringifiedQuery),\n [stringifiedQuery]\n );\n const [data, setData] = React.useState(props.data);\n const [isClient, setIsClient] = React.useState(false);\n const [quickEditEnabled, setQuickEditEnabled] = React.useState(false);\n const [isInTinaIframe, setIsInTinaIframe] = React.useState(false);\n\n React.useEffect(() => {\n setIsClient(true);\n setData(props.data);\n parent.postMessage({\n type: 'url-changed',\n });\n }, [id]);\n\n React.useEffect(() => {\n if (quickEditEnabled) {\n const style = document.createElement('style');\n style.type = 'text/css';\n style.textContent = `\n [data-tina-field] {\n outline: 2px dashed rgba(34,150,254,0.5);\n transition: box-shadow ease-out 150ms;\n }\n [data-tina-field]:hover {\n box-shadow: inset 100vi 100vh rgba(34,150,254,0.3);\n outline: 2px solid rgba(34,150,254,1);\n cursor: pointer;\n }\n [data-tina-field-overlay] {\n outline: 2px dashed rgba(34,150,254,0.5);\n position: relative;\n }\n [data-tina-field-overlay]:hover {\n cursor: pointer;\n outline: 2px solid rgba(34,150,254,1);\n }\n [data-tina-field-overlay]::after {\n content: '';\n position: absolute;\n inset: 0;\n z-index: 20;\n transition: opacity ease-out 150ms;\n background-color: rgba(34,150,254,0.3);\n opacity: 0;\n }\n [data-tina-field-overlay]:hover::after {\n opacity: 1;\n }\n `;\n document.head.appendChild(style);\n document.body.classList.add('__tina-quick-editing-enabled');\n\n function mouseDownHandler(e) {\n const attributeNames = e.target.getAttributeNames();\n // If multiple attributes start with data-tina-field, only the first is used\n const tinaAttribute = attributeNames.find((name) =>\n name.startsWith('data-tina-field')\n );\n let fieldName;\n if (tinaAttribute) {\n e.preventDefault();\n e.stopPropagation();\n fieldName = e.target.getAttribute(tinaAttribute);\n } else {\n const ancestor = e.target.closest(\n '[data-tina-field], [data-tina-field-overlay]'\n );\n if (ancestor) {\n const attributeNames = ancestor.getAttributeNames();\n const tinaAttribute = attributeNames.find((name) =>\n name.startsWith('data-tina-field')\n );\n if (tinaAttribute) {\n e.preventDefault();\n e.stopPropagation();\n fieldName = ancestor.getAttribute(tinaAttribute);\n }\n }\n }\n if (fieldName) {\n if (isInTinaIframe) {\n parent.postMessage(\n { type: 'field:selected', fieldName: fieldName },\n window.location.origin\n );\n } else {\n // if (preview?.redirect) {\n // const tinaAdminBasePath = preview.redirect.startsWith('/')\n // ? preview.redirect\n // : `/${preview.redirect}`\n // const tinaAdminPath = `${tinaAdminBasePath}/index.html#/~${window.location.pathname}?active-field=${fieldName}`\n // window.location.assign(tinaAdminPath)\n // }\n }\n }\n }\n document.addEventListener('click', mouseDownHandler, true);\n\n return () => {\n document.removeEventListener('click', mouseDownHandler, true);\n document.body.classList.remove('__tina-quick-editing-enabled');\n style.remove();\n };\n }\n }, [quickEditEnabled, isInTinaIframe]);\n\n React.useEffect(() => {\n if (props?.experimental___selectFormByFormId) {\n parent.postMessage({\n type: 'user-select-form',\n formId: props.experimental___selectFormByFormId(),\n });\n }\n }, [id]);\n\n React.useEffect(() => {\n const { experimental___selectFormByFormId, ...rest } = props;\n parent.postMessage({ type: 'open', ...rest, id }, window.location.origin);\n window.addEventListener('message', (event) => {\n if (event.data.type === 'quickEditEnabled') {\n setQuickEditEnabled(event.data.value);\n }\n if (event.data.id === id && event.data.type === 'updateData') {\n setData(event.data.data);\n setIsInTinaIframe(true);\n // Ensure we still have a tina-field on the page\n const anyTinaField = document.querySelector('[data-tina-field]');\n if (anyTinaField) {\n parent.postMessage(\n { type: 'quick-edit', value: true },\n window.location.origin\n );\n } else {\n parent.postMessage(\n { type: 'quick-edit', value: false },\n window.location.origin\n );\n }\n }\n });\n\n return () => {\n parent.postMessage({ type: 'close', id }, window.location.origin);\n };\n }, [id, setQuickEditEnabled]);\n\n // Probably don't want to always do this on every data update,\n // Just needs to be done once when in non-edit mode\n // addMetadata(id, data, [])\n\n return { data, isClient };\n}\n\nexport function useEditState(): { edit: boolean } {\n const [edit, setEdit] = React.useState(false);\n React.useEffect(() => {\n if (typeof window !== 'undefined') {\n parent.postMessage({ type: 'isEditMode' }, window.location.origin);\n window.addEventListener('message', (event) => {\n if (event.data?.type === 'tina:editMode') {\n setEdit(true);\n }\n });\n }\n }, []);\n return { edit } as any;\n}\n\n/**\n * Grab the field name for the given attribute\n * to signal to Tina which DOM element the field\n * is working with.\n */\nexport const tinaField = <\n T extends\n | (object & {\n _content_source?: {\n queryId: string;\n path: (number | string)[];\n };\n })\n | undefined\n | null,\n>(\n object: T,\n property?: keyof Omit<NonNullable<T>, '__typename' | '_sys'>,\n index?: number\n) => {\n if (!object) {\n return '';\n }\n if (object._content_source) {\n if (!property) {\n return [\n object._content_source?.queryId,\n object._content_source.path.join('.'),\n ].join('---');\n }\n if (typeof index === 'number') {\n return [\n object._content_source?.queryId,\n [...object._content_source.path, property, index].join('.'),\n ].join('---');\n }\n return [\n object._content_source?.queryId,\n [...object._content_source.path, property].join('.'),\n ].join('---');\n }\n return '';\n};\n\nexport const addMetadata = <T extends object>(\n id: string,\n object: T & { type?: string; _content_source?: unknown },\n path: (string | number)[]\n): T => {\n Object.entries(object).forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n if (isScalarOrUndefined(item)) {\n return;\n }\n if (Array.isArray(item)) {\n return; // we don't expect arrays of arrays\n }\n const itemObject = item as object;\n addMetadata(id, itemObject, [...path, key, index]);\n });\n } else {\n if (isScalarOrUndefined(value)) {\n return;\n }\n const itemObject = value as object;\n addMetadata(id, itemObject, [...path, key]);\n }\n });\n // This is a rich-text field object\n if (object?.type === 'root') {\n return;\n }\n\n object._content_source = {\n queryId: id,\n path,\n };\n return object;\n};\nfunction isScalarOrUndefined(value: unknown) {\n const type = typeof value;\n if (type === 'string') return true;\n if (type === 'number') return true;\n if (type === 'boolean') return true;\n if (type === 'undefined') return true;\n\n if (value == null) return true;\n if (value instanceof String) return true;\n if (value instanceof Number) return true;\n if (value instanceof Boolean) return true;\n\n return false;\n}\n\n/**\n * This is a pretty rudimentary approach to hashing the query and variables to\n * ensure we treat multiple queries on the page uniquely. It's possible\n * that we would have collisions, and I'm not sure of the likeliness but seems\n * like it'd be rare.\n */\nexport const hashFromQuery = (input: string) => {\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n const char = input.charCodeAt(i);\n hash = ((hash << 5) - hash + char) & 0xffffffff; // Apply bitwise AND to ensure non-negative value\n }\n const nonNegativeHash = Math.abs(hash);\n const alphanumericHash = nonNegativeHash.toString(36);\n return alphanumericHash;\n};\n"],"names":["attributeNames","tinaAttribute"],"mappings":";AAEO,SAAS,QAA0B,OAKP;AAC3B,QAAA,mBAAmB,KAAK,UAAU;AAAA,IACtC,OAAO,MAAM;AAAA,IACb,WAAW,MAAM;AAAA,EAAA,CAClB;AACD,QAAM,KAAK,MAAM;AAAA,IACf,MAAM,cAAc,gBAAgB;AAAA,IACpC,CAAC,gBAAgB;AAAA,EAAA;AAEnB,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,MAAM,IAAI;AACjD,QAAM,CAAC,UAAU,WAAW,IAAI,MAAM,SAAS,KAAK;AACpD,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,MAAM,SAAS,KAAK;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,MAAM,SAAS,KAAK;AAEhE,QAAM,UAAU,MAAM;AACpB,gBAAY,IAAI;AAChB,YAAQ,MAAM,IAAI;AAClB,WAAO,YAAY;AAAA,MACjB,MAAM;AAAA,IAAA,CACP;AAAA,EAAA,GACA,CAAC,EAAE,CAAC;AAEP,QAAM,UAAU,MAAM;AACpB,QAAI,kBAAkB;AAqCX,UAAA,mBAAT,SAA0B,GAAG;AACrB,cAAA,iBAAiB,EAAE,OAAO,kBAAkB;AAElD,cAAM,gBAAgB,eAAe;AAAA,UAAK,CAAC,SACzC,KAAK,WAAW,iBAAiB;AAAA,QAAA;AAE/B,YAAA;AACJ,YAAI,eAAe;AACjB,YAAE,eAAe;AACjB,YAAE,gBAAgB;AACN,sBAAA,EAAE,OAAO,aAAa,aAAa;AAAA,QAAA,OAC1C;AACC,gBAAA,WAAW,EAAE,OAAO;AAAA,YACxB;AAAA,UAAA;AAEF,cAAI,UAAU;AACNA,kBAAAA,kBAAiB,SAAS;AAChC,kBAAMC,iBAAgBD,gBAAe;AAAA,cAAK,CAAC,SACzC,KAAK,WAAW,iBAAiB;AAAA,YAAA;AAEnC,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WAAA;AAC/B,MAAI,SAAS;AAAoB,WAAA;AAEjC,MAAI,SAAS;AAAa,WAAA;AAC1B,MAAI,iBAAiB;AAAe,WAAA;AACpC,MAAI,iBAAiB;AAAe,WAAA;AACpC,MAAI,iBAAiB;AAAgB,WAAA;AAE9B,SAAA;AACT;AAQa,MAAA,gBAAgB,CAAC,UAAkB;AAC9C,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAC/B,UAAA,OAAO,MAAM,WAAW,CAAC;AACtB,YAAA,QAAQ,KAAK,OAAO,OAAQ;AAAA,EACvC;AACM,QAAA,kBAAkB,KAAK,IAAI,IAAI;AAC/B,QAAA,mBAAmB,gBAAgB,SAAS,EAAE;AAC7C,SAAA;AACT;"}
|
package/dist/rich-text/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/rich-text/index.tsx"],"sourcesContent":["/**\n\n*/\n\nimport React from 'react';\n\ntype BaseComponents = {\n h1?: { children: JSX.Element };\n h2?: { children: JSX.Element };\n h3?: { children: JSX.Element };\n h4?: { children: JSX.Element };\n h5?: { children: JSX.Element };\n h6?: { children: JSX.Element };\n p?: { children: JSX.Element };\n a?: { url: string; children: JSX.Element };\n italic?: { children: JSX.Element };\n bold?: { children: JSX.Element };\n strikethrough?: { children: JSX.Element };\n underline?: { children: JSX.Element };\n code?: { children: JSX.Element };\n text?: { children: string };\n ul?: { children: JSX.Element };\n ol?: { children: JSX.Element };\n li?: { children: JSX.Element };\n lic?: { children: JSX.Element };\n block_quote?: { children: JSX.Element };\n code_block?: { lang?: string; value: string };\n mermaid?: { value: string };\n img?: { url: string; caption?: string; alt?: string };\n hr?: {};\n break?: {};\n maybe_mdx?: { children: JSX.Element };\n html?: { value: string };\n html_inline?: { value: string };\n // th?: { children: JSX.Element }\n // td?: { children: JSX.Element }\n // tr?: { children: JSX.Element }\n table?: {\n align?: ('left' | 'right' | 'center')[];\n tableRows: { tableCells: { value: TinaMarkdownContent }[] }[];\n };\n // Provide a fallback when a JSX component wasn't provided\n component_missing?: { name: string };\n};\n\ntype BaseComponentSignature = {\n [BK in keyof BaseComponents]: (props: BaseComponents[BK]) => JSX.Element;\n};\n\n/**\n * Define the allowed components and their props\n * ```ts\n * const components:\n * Components<{\n * BlockQuote: {\n * children: TinaMarkdownContent;\n * authorName: string;\n * };\n * }> = {\n * BlockQuote: (props: {\n * children: TinaMarkdownContent;\n * authorName: string;\n * }) => {\n * return (\n * <div>\n * <blockquote>\n * <TinaMarkdown content={props.children} />\n * {props.authorName}\n * </blockquote>\n * </div>\n * );\n * }\n * }\n * }\n * ```\n */\nexport type Components<ComponentAndProps extends object> = {\n [K in keyof ComponentAndProps]: (props: ComponentAndProps[K]) => JSX.Element;\n} & BaseComponentSignature;\n\nexport type TinaMarkdownContent = {\n type: string;\n children: TinaMarkdownContent[];\n};\n\nexport const TinaMarkdown = <\n CustomComponents extends { [key: string]: object } = any,\n>({\n content,\n components = {},\n}: {\n content: TinaMarkdownContent | TinaMarkdownContent[];\n components?:\n | Components<{}>\n | Components<{\n [BK in keyof CustomComponents]: (\n props: CustomComponents[BK]\n ) => JSX.Element;\n }>;\n}) => {\n if (!content) {\n return null;\n }\n const nodes = Array.isArray(content) ? content : content.children;\n if (!nodes) {\n return null;\n }\n return (\n <>\n {nodes.map((child, index) => {\n return <MemoNode components={components} key={index} child={child} />;\n })}\n </>\n );\n};\n\nconst Leaf = (props: {\n type: 'text';\n text: string;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n strikethrough?: boolean;\n code?: boolean;\n components: Pick<\n BaseComponentSignature,\n 'bold' | 'italic' | 'underline' | 'strikethrough' | 'code' | 'text'\n >;\n}) => {\n if (props.bold) {\n const { bold, ...rest } = props;\n if (props.components.bold) {\n const Component = props.components.bold;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <strong>\n <Leaf {...rest} />\n </strong>\n );\n }\n if (props.italic) {\n const { italic, ...rest } = props;\n if (props.components.italic) {\n const Component = props.components.italic;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <em>\n <Leaf {...rest} />\n </em>\n );\n }\n if (props.underline) {\n const { underline, ...rest } = props;\n if (props.components.underline) {\n const Component = props.components.underline;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <u>\n <Leaf {...rest} />\n </u>\n );\n }\n if (props.strikethrough) {\n const { strikethrough, ...rest } = props;\n if (props.components.strikethrough) {\n const Component = props.components.strikethrough;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <s>\n <Leaf {...rest} />\n </s>\n );\n }\n if (props.code) {\n const { code, ...rest } = props;\n if (props.components.code) {\n const Component = props.components.code;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <code>\n <Leaf {...rest} />\n </code>\n );\n }\n if (props.components.text) {\n const Component = props.components.text;\n return <Component>{props.text}</Component>;\n }\n return <>{props.text}</>;\n};\n\n// FIXME: this needs more testing. But in theory all props\n// are serializable anyway so the JSON.stringify comparison makes sense.\n// I haven't thought all the way through this though, and maybe it'll break\n// down with custom components in some way.\n// In general this component handles most things without too many issues but for\n// large bodies of text it becomes pretty painful to see as-you-type updates, especially\n// in Safari.\nconst MemoNode = (props) => {\n const MNode = React.useMemo(\n () => <Node {...props} />,\n [JSON.stringify(props)]\n );\n return MNode;\n};\nconst Node = ({ components, child }) => {\n const { children, ...props } = child;\n switch (child.type) {\n case 'h1':\n case 'h2':\n case 'h3':\n case 'h4':\n case 'h5':\n case 'h6':\n case 'p':\n case 'blockquote':\n case 'ol':\n case 'ul':\n case 'li':\n if (components[child.type]) {\n const Component = components[child.type];\n return (\n <Component {...props}>\n <TinaMarkdown components={components} content={children} />\n </Component>\n );\n }\n return React.createElement(child.type, {\n children: <TinaMarkdown components={components} content={children} />,\n });\n case 'lic': // List Item Content\n if (components.lic) {\n const Component = components.lic;\n return (\n <Component {...props}>\n <TinaMarkdown components={components} content={children} />\n </Component>\n );\n }\n return (\n <div>\n <TinaMarkdown components={components} content={child.children} />\n </div>\n );\n case 'img':\n if (components[child.type]) {\n const Component = components[child.type];\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Component {...props} />;\n }\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <img src={child.url} alt={child.alt} />;\n case 'a':\n if (components[child.type]) {\n const Component = components[child.type];\n return (\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n <Component {...props}>\n <TinaMarkdown components={components} content={children} />\n </Component>\n );\n }\n return (\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n <a href={child.url}>\n <TinaMarkdown components={components} content={children} />\n </a>\n );\n case 'mermaid':\n case 'code_block': {\n const value = child.value;\n if (components[child.type]) {\n const Component = components[child.type];\n return (\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n <Component {...props} />\n );\n }\n return (\n <pre>\n <code>{value}</code>\n </pre>\n );\n }\n case 'hr':\n if (components[child.type]) {\n const Component = components[child.type];\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Component {...props} />;\n }\n return <hr />;\n case 'break':\n if (components[child.type]) {\n const Component = components[child.type];\n return <Component {...props} />;\n }\n return <br />;\n case 'text':\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Leaf components={components} {...child} />;\n case 'mdxJsxTextElement':\n case 'mdxJsxFlowElement':\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n const Component = components[child.name];\n if (Component) {\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n const props = child.props ? child.props : {};\n return <Component {...props} />;\n } else {\n if (child.name === 'table') {\n const firstRowHeader = child.props?.firstRowHeader;\n const rows =\n (firstRowHeader\n ? child.props?.tableRows.filter((_, i) => i !== 0)\n : child.props?.tableRows) || [];\n const header = child.props?.tableRows?.at(0);\n const TableComponent =\n components['table'] || ((props) => <table {...props} />);\n const TrComponent =\n components['tr'] || ((props) => <tr {...props} />);\n const ThComponent =\n components['th'] ||\n ((props) => (\n <th style={{ textAlign: props?.align || 'auto' }} {...props} />\n ));\n const TdComponent =\n components['td'] ||\n ((props) => (\n <td style={{ textAlign: props?.align || 'auto' }} {...props} />\n ));\n const align = child.props?.align || [];\n return (\n <TableComponent>\n {firstRowHeader && (\n <thead>\n <TrComponent>\n {header.tableCells.map((c, i) => {\n return (\n <TinaMarkdown\n key={i}\n components={{\n p: (props) => (\n <ThComponent align={align[i]} {...props} />\n ),\n }}\n content={c.value}\n />\n );\n })}\n </TrComponent>\n </thead>\n )}\n <tbody>\n {rows.map((row, i) => {\n return (\n <TrComponent key={i}>\n {row?.tableCells?.map((c, i) => {\n return (\n <TinaMarkdown\n key={i}\n components={{\n p: (props) => (\n <TdComponent align={align[i]} {...props} />\n ),\n }}\n content={c.value}\n />\n );\n })}\n </TrComponent>\n );\n })}\n </tbody>\n </TableComponent>\n );\n }\n const ComponentMissing = components['component_missing'];\n if (ComponentMissing) {\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <ComponentMissing name={child.name} />;\n } else {\n return <span>{`No component provided for ${child.name}`}</span>;\n }\n }\n case 'table':\n const rows = child.children || [];\n const TableComponent =\n components['table'] ||\n ((props) => (\n <table style={{ border: '1px solid #EDECF3' }} {...props} />\n ));\n const TrComponent = components['tr'] || ((props) => <tr {...props} />);\n const TdComponent =\n components['td'] ||\n ((props) => (\n <td\n style={{\n textAlign: props?.align || 'auto',\n border: '1px solid #EDECF3',\n padding: '0.25rem',\n }}\n {...props}\n />\n ));\n const align = child.props?.align || [];\n return (\n <TableComponent>\n <tbody>\n {rows.map((row, i) => {\n return (\n <TrComponent key={i}>\n {row.children?.map((cell, i) => {\n return (\n <TinaMarkdown\n key={i}\n components={{\n p: (props) => (\n <TdComponent align={align[i]} {...props} />\n ),\n }}\n content={cell.children}\n />\n );\n })}\n </TrComponent>\n );\n })}\n </tbody>\n </TableComponent>\n );\n case 'maybe_mdx':\n /**\n * We don't want to render this as it's only displayed while editing an mdx node and should\n * be transformed before form submission\n */\n return null;\n case 'html':\n case 'html_inline':\n if (components[child.type]) {\n const Component = components[child.type];\n return <Component {...props} />;\n }\n return child.value;\n case 'invalid_markdown':\n return <pre>{child.value}</pre>;\n default:\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n if (typeof child.text === 'string') {\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Leaf components={components} {...child} />;\n }\n\n // console.log(`No tina renderer for ${child.type}`, child)\n }\n};\n"],"names":["Component","props","rows","TableComponent","TrComponent","TdComponent","align","_a","i"],"mappings":";;;;AAqFa,QAAA,eAAe,CAE1B;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,EAChB,MASM;AACJ,QAAI,CAAC,SAAS;AACL,aAAA;AAAA,IACT;AACA,UAAM,QAAQ,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ;AACzD,QAAI,CAAC,OAAO;AACH,aAAA;AAAA,IACT;AACA,WAEK,sBAAA,cAAA,MAAA,UAAA,MAAA,MAAM,IAAI,CAAC,OAAO,UAAU;AAC3B,aAAQ,sBAAA,cAAA,UAAA,EAAS,YAAwB,KAAK,OAAO,MAAc,CAAA;AAAA,IACpE,CAAA,CACH;AAAA,EAEJ;AAEA,QAAM,OAAO,CAAC,UAYR;AACJ,QAAI,MAAM,MAAM;AACd,YAAM,EAAE,MAAM,GAAG,KAAA,IAAS;AACtB,UAAA,MAAM,WAAW,MAAM;AACnB,cAAA,YAAY,MAAM,WAAW;AACnC,mDACG,WACC,MAAA,sBAAA,cAAC,MAAM,EAAA,GAAG,MAAM,CAClB;AAAA,MAEJ;AACA,iDACG,UACC,MAAA,sBAAA,cAAC,MAAM,EAAA,GAAG,MAAM,CAClB;AAAA,IAEJ;AACA,QAAI,MAAM,QAAQ;AAChB,YAA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ent":["/**\n\n*/\n\nimport React from 'react';\n\ntype BaseComponents = {\n h1?: { children: JSX.Element };\n h2?: { children: JSX.Element };\n h3?: { children: JSX.Element };\n h4?: { children: JSX.Element };\n h5?: { children: JSX.Element };\n h6?: { children: JSX.Element };\n p?: { children: JSX.Element };\n a?: { url: string; children: JSX.Element };\n italic?: { children: JSX.Element };\n bold?: { children: JSX.Element };\n strikethrough?: { children: JSX.Element };\n underline?: { children: JSX.Element };\n code?: { children: JSX.Element };\n text?: { children: string };\n ul?: { children: JSX.Element };\n ol?: { children: JSX.Element };\n li?: { children: JSX.Element };\n lic?: { children: JSX.Element };\n block_quote?: { children: JSX.Element };\n code_block?: { lang?: string; value: string };\n mermaid?: { value: string };\n img?: { url: string; caption?: string; alt?: string };\n hr?: {};\n break?: {};\n maybe_mdx?: { children: JSX.Element };\n html?: { value: string };\n html_inline?: { value: string };\n // th?: { children: JSX.Element }\n // td?: { children: JSX.Element }\n // tr?: { children: JSX.Element }\n table?: {\n align?: ('left' | 'right' | 'center')[];\n tableRows: { tableCells: { value: TinaMarkdownContent }[] }[];\n };\n // Provide a fallback when a JSX component wasn't provided\n component_missing?: { name: string };\n};\n\ntype BaseComponentSignature = {\n [BK in keyof BaseComponents]: (props: BaseComponents[BK]) => JSX.Element;\n};\n\n/**\n * Define the allowed components and their props\n * ```ts\n * const components:\n * Components<{\n * BlockQuote: {\n * children: TinaMarkdownContent;\n * authorName: string;\n * };\n * }> = {\n * BlockQuote: (props: {\n * children: TinaMarkdownContent;\n * authorName: string;\n * }) => {\n * return (\n * <div>\n * <blockquote>\n * <TinaMarkdown content={props.children} />\n * {props.authorName}\n * </blockquote>\n * </div>\n * );\n * }\n * }\n * }\n * ```\n */\nexport type Components<ComponentAndProps extends object> = {\n [K in keyof ComponentAndProps]: (props: ComponentAndProps[K]) => JSX.Element;\n} & BaseComponentSignature;\n\nexport type TinaMarkdownContent = {\n type: string;\n children: TinaMarkdownContent[];\n};\n\nexport const TinaMarkdown = <\n CustomComponents extends { [key: string]: object } = any,\n>({\n content,\n components = {},\n}: {\n content: TinaMarkdownContent | TinaMarkdownContent[];\n components?:\n | Components<{}>\n | Components<{\n [BK in keyof CustomComponents]: (\n props: CustomComponents[BK]\n ) => JSX.Element;\n }>;\n}) => {\n if (!content) {\n return null;\n }\n const nodes = Array.isArray(content) ? content : content.children;\n if (!nodes) {\n return null;\n }\n return (\n <>\n {nodes.map((child, index) => {\n return <MemoNode components={components} key={index} child={child} />;\n })}\n </>\n );\n};\n\nconst Leaf = (props: {\n type: 'text';\n text: string;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n strikethrough?: boolean;\n code?: boolean;\n components: Pick<\n BaseComponentSignature,\n 'bold' | 'italic' | 'underline' | 'strikethrough' | 'code' | 'text'\n >;\n}) => {\n if (props.bold) {\n const { bold, ...rest } = props;\n if (props.components.bold) {\n const Component = props.components.bold;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <strong>\n <Leaf {...rest} />\n </strong>\n );\n }\n if (props.italic) {\n const { italic, ...rest } = props;\n if (props.components.italic) {\n const Component = props.components.italic;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <em>\n <Leaf {...rest} />\n </em>\n );\n }\n if (props.underline) {\n const { underline, ...rest } = props;\n if (props.components.underline) {\n const Component = props.components.underline;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <u>\n <Leaf {...rest} />\n </u>\n );\n }\n if (props.strikethrough) {\n const { strikethrough, ...rest } = props;\n if (props.components.strikethrough) {\n const Component = props.components.strikethrough;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <s>\n <Leaf {...rest} />\n </s>\n );\n }\n if (props.code) {\n const { code, ...rest } = props;\n if (props.components.code) {\n const Component = props.components.code;\n return (\n <Component>\n <Leaf {...rest} />\n </Component>\n );\n }\n return (\n <code>\n <Leaf {...rest} />\n </code>\n );\n }\n if (props.components.text) {\n const Component = props.components.text;\n return <Component>{props.text}</Component>;\n }\n return <>{props.text}</>;\n};\n\n// FIXME: this needs more testing. But in theory all props\n// are serializable anyway so the JSON.stringify comparison makes sense.\n// I haven't thought all the way through this though, and maybe it'll break\n// down with custom components in some way.\n// In general this component handles most things without too many issues but for\n// large bodies of text it becomes pretty painful to see as-you-type updates, especially\n// in Safari.\nconst MemoNode = (props) => {\n const MNode = React.useMemo(\n () => <Node {...props} />,\n [JSON.stringify(props)]\n );\n return MNode;\n};\nconst Node = ({ components, child }) => {\n const { children, ...props } = child;\n switch (child.type) {\n case 'h1':\n case 'h2':\n case 'h3':\n case 'h4':\n case 'h5':\n case 'h6':\n case 'p':\n case 'blockquote':\n case 'ol':\n case 'ul':\n case 'li':\n if (components[child.type]) {\n const Component = components[child.type];\n return (\n <Component {...props}>\n <TinaMarkdown components={components} content={children} />\n </Component>\n );\n }\n return React.createElement(child.type, {\n children: <TinaMarkdown components={components} content={children} />,\n });\n case 'lic': // List Item Content\n if (components.lic) {\n const Component = components.lic;\n return (\n <Component {...props}>\n <TinaMarkdown components={components} content={children} />\n </Component>\n );\n }\n return (\n <div>\n <TinaMarkdown components={components} content={child.children} />\n </div>\n );\n case 'img':\n if (components[child.type]) {\n const Component = components[child.type];\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Component {...props} />;\n }\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <img src={child.url} alt={child.alt} />;\n case 'a':\n if (components[child.type]) {\n const Component = components[child.type];\n return (\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n <Component {...props}>\n <TinaMarkdown components={components} content={children} />\n </Component>\n );\n }\n return (\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n <a href={child.url}>\n <TinaMarkdown components={components} content={children} />\n </a>\n );\n case 'mermaid':\n case 'code_block': {\n const value = child.value;\n if (components[child.type]) {\n const Component = components[child.type];\n return (\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n <Component {...props} />\n );\n }\n return (\n <pre>\n <code>{value}</code>\n </pre>\n );\n }\n case 'hr':\n if (components[child.type]) {\n const Component = components[child.type];\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Component {...props} />;\n }\n return <hr />;\n case 'break':\n if (components[child.type]) {\n const Component = components[child.type];\n return <Component {...props} />;\n }\n return <br />;\n case 'text':\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Leaf components={components} {...child} />;\n case 'mdxJsxTextElement':\n case 'mdxJsxFlowElement':\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n const Component = components[child.name];\n if (Component) {\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n const props = child.props ? child.props : {};\n return <Component {...props} />;\n } else {\n if (child.name === 'table') {\n const firstRowHeader = child.props?.firstRowHeader;\n const rows =\n (firstRowHeader\n ? child.props?.tableRows.filter((_, i) => i !== 0)\n : child.props?.tableRows) || [];\n const header = child.props?.tableRows?.at(0);\n const TableComponent =\n components['table'] || ((props) => <table {...props} />);\n const TrComponent =\n components['tr'] || ((props) => <tr {...props} />);\n const ThComponent =\n components['th'] ||\n ((props) => (\n <th style={{ textAlign: props?.align || 'auto' }} {...props} />\n ));\n const TdComponent =\n components['td'] ||\n ((props) => (\n <td style={{ textAlign: props?.align || 'auto' }} {...props} />\n ));\n const align = child.props?.align || [];\n return (\n <TableComponent>\n {firstRowHeader && (\n <thead>\n <TrComponent>\n {header.tableCells.map((c, i) => {\n return (\n <TinaMarkdown\n key={i}\n components={{\n p: (props) => (\n <ThComponent align={align[i]} {...props} />\n ),\n }}\n content={c.value}\n />\n );\n })}\n </TrComponent>\n </thead>\n )}\n <tbody>\n {rows.map((row, i) => {\n return (\n <TrComponent key={i}>\n {row?.tableCells?.map((c, i) => {\n return (\n <TinaMarkdown\n key={i}\n components={{\n p: (props) => (\n <TdComponent align={align[i]} {...props} />\n ),\n }}\n content={c.value}\n />\n );\n })}\n </TrComponent>\n );\n })}\n </tbody>\n </TableComponent>\n );\n }\n const ComponentMissing = components['component_missing'];\n if (ComponentMissing) {\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <ComponentMissing name={child.name} />;\n } else {\n return <span>{`No component provided for ${child.name}`}</span>;\n }\n }\n case 'table':\n const rows = child.children || [];\n const TableComponent =\n components['table'] ||\n ((props) => (\n <table style={{ border: '1px solid #EDECF3' }} {...props} />\n ));\n const TrComponent = components['tr'] || ((props) => <tr {...props} />);\n const TdComponent =\n components['td'] ||\n ((props) => (\n <td\n style={{\n textAlign: props?.align || 'auto',\n border: '1px solid #EDECF3',\n padding: '0.25rem',\n }}\n {...props}\n />\n ));\n const align = child.props?.align || [];\n return (\n <TableComponent>\n <tbody>\n {rows.map((row, i) => {\n return (\n <TrComponent key={i}>\n {row.children?.map((cell, i) => {\n return (\n <TinaMarkdown\n key={i}\n components={{\n p: (props) => (\n <TdComponent align={align[i]} {...props} />\n ),\n }}\n content={cell.children}\n />\n );\n })}\n </TrComponent>\n );\n })}\n </tbody>\n </TableComponent>\n );\n case 'maybe_mdx':\n /**\n * We don't want to render this as it's only displayed while editing an mdx node and should\n * be transformed before form submission\n */\n return null;\n case 'html':\n case 'html_inline':\n if (components[child.type]) {\n const Component = components[child.type];\n return <Component {...props} />;\n }\n return child.value;\n case 'invalid_markdown':\n return <pre>{child.value}</pre>;\n default:\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n if (typeof child.text === 'string') {\n // @ts-ignore FIXME: TinaMarkdownContent needs to be a union of all possible node types\n return <Leaf components={components} {...child} />;\n }\n\n // console.log(`No tina renderer for ${child.type}`, child)\n }\n};\n"],"names":["Component","props","rows","TableComponent","TrComponent","TdComponent","align","_a","i"],"mappings":";AAqFO,MAAM,eAAe,CAE1B;AAAA,EACA;AAAA,EACA,aAAa,CAAC;AAChB,MASM;AACJ,MAAI,CAAC,SAAS;AACL,WAAA;AA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A,MAEH,CAAA,CACH,CACF;AAAA,IAEJ,KAAK;AAKI,aAAA;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACC,UAAA,WAAW,MAAM,IAAI,GAAG;AACpBD,cAAAA,aAAY,WAAW,MAAM,IAAI;AACvC,eAAQA,sBAAAA,cAAAA,YAAA,EAAW,GAAG,MAAO,CAAA;AAAA,MAC/B;AACA,aAAO,MAAM;AAAA,IACf,KAAK;AACI,aAAA,sBAAA,cAAC,OAAK,MAAA,MAAM,KAAM;AAAA,IAC3B;AAEM,UAAA,OAAO,MAAM,SAAS,UAAU;AAElC,eAAQ,sBAAA,cAAA,MAAA,EAAK,YAAyB,GAAG,MAAO,CAAA;AAAA,MAClD;AAAA,EAGJ;AACF;"}
|
package/dist/rich-text/prism.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
prismReactRenderer.Highlight,
|
|
8
8
|
{
|
|
9
9
|
theme: prismReactRenderer.themes[props.theme || "github"],
|
|
10
|
-
code: props.value,
|
|
10
|
+
code: props.value || "",
|
|
11
11
|
language: props.lang || ""
|
|
12
12
|
},
|
|
13
13
|
({ className, style, tokens, getLineProps, getTokenProps }) => /* @__PURE__ */ React.createElement("pre", { className, style }, tokens.map((line, i) => /* @__PURE__ */ React.createElement("div", { ...getLineProps({ line, key: i }) }, line.map((token, key) => /* @__PURE__ */ React.createElement("span", { ...getTokenProps({ token, key }) })))))
|
|
@@ -16,3 +16,4 @@
|
|
|
16
16
|
exports2.Prism = Prism;
|
|
17
17
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
18
18
|
});
|
|
19
|
+
//# sourceMappingURL=prism.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prism.js","sources":["../../src/rich-text/prism.tsx"],"sourcesContent":["/**\n\n*/\n\nimport React from 'react';\nimport { Highlight, themes } from 'prism-react-renderer';\n\nexport const Prism = (props: {\n value: string;\n lang?: string;\n theme?: keyof typeof themes;\n}) => {\n return (\n <Highlight\n theme={themes[props.theme || 'github']}\n code={props.value || ''}\n language={props.lang || ''}\n >\n {({ className, style, tokens, getLineProps, getTokenProps }) => (\n <pre className={className} style={style}>\n {tokens.map((line, i) => (\n <div {...getLineProps({ line, key: i })}>\n {line.map((token, key) => (\n <span {...getTokenProps({ token, key })} />\n ))}\n </div>\n ))}\n </pre>\n )}\n </Highlight>\n );\n};\n"],"names":["Highlight","themes"],"mappings":";;;;AAOa,QAAA,QAAQ,CAAC,UAIhB;AAEF,WAAA,sBAAA;AAAA,MAACA,mBAAA;AAAA,MAAA;AAAA,QACC,OAAOC,mBAAA,OAAO,MAAM,SAAS,QAAQ;AAAA,QACrC,MAAM,MAAM,SAAS;AAAA,QACrB,UAAU,MAAM,QAAQ;AAAA,MAAA;AAAA,MAEvB,CAAC,EAAE,WAAW,OAAO,QAAQ,cAAc,oBACzC,sBAAA,cAAA,OAAA,EAAI,WAAsB,MACxB,GAAA,OAAO,IAAI,CAAC,MAAM,MAChB,sBAAA,cAAA,OAAA,EAAK,GAAG,aAAa,EAAE,MAAM,KAAK,GAAG,EACnC,GAAA,KAAK,IAAI,CAAC,OAAO,QACf,sBAAA,cAAA,QAAA,EAAM,GAAG,cAAc,EAAE,OAAO,KAAK,GAAG,CAC1C,CACH,CACD,CACH;AAAA,IAAA;AAAA,EAIR;;;;"}
|
package/dist/rich-text/prism.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const Prism = (props) => {
|
|
|
5
5
|
Highlight,
|
|
6
6
|
{
|
|
7
7
|
theme: themes[props.theme || "github"],
|
|
8
|
-
code: props.value,
|
|
8
|
+
code: props.value || "",
|
|
9
9
|
language: props.lang || ""
|
|
10
10
|
},
|
|
11
11
|
({ className, style, tokens, getLineProps, getTokenProps }) => /* @__PURE__ */ React.createElement("pre", { className, style }, tokens.map((line, i) => /* @__PURE__ */ React.createElement("div", { ...getLineProps({ line, key: i }) }, line.map((token, key) => /* @__PURE__ */ React.createElement("span", { ...getTokenProps({ token, key }) })))))
|
|
@@ -14,3 +14,4 @@ const Prism = (props) => {
|
|
|
14
14
|
export {
|
|
15
15
|
Prism
|
|
16
16
|
};
|
|
17
|
+
//# sourceMappingURL=prism.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prism.mjs","sources":["../../src/rich-text/prism.tsx"],"sourcesContent":["/**\n\n*/\n\nimport React from 'react';\nimport { Highlight, themes } from 'prism-react-renderer';\n\nexport const Prism = (props: {\n value: string;\n lang?: string;\n theme?: keyof typeof themes;\n}) => {\n return (\n <Highlight\n theme={themes[props.theme || 'github']}\n code={props.value || ''}\n language={props.lang || ''}\n >\n {({ className, style, tokens, getLineProps, getTokenProps }) => (\n <pre className={className} style={style}>\n {tokens.map((line, i) => (\n <div {...getLineProps({ line, key: i })}>\n {line.map((token, key) => (\n <span {...getTokenProps({ token, key })} />\n ))}\n </div>\n ))}\n </pre>\n )}\n </Highlight>\n );\n};\n"],"names":[],"mappings":";;AAOa,MAAA,QAAQ,CAAC,UAIhB;AAEF,SAAA,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO,OAAO,MAAM,SAAS,QAAQ;AAAA,MACrC,MAAM,MAAM,SAAS;AAAA,MACrB,UAAU,MAAM,QAAQ;AAAA,IAAA;AAAA,IAEvB,CAAC,EAAE,WAAW,OAAO,QAAQ,cAAc,oBACzC,sBAAA,cAAA,OAAA,EAAI,WAAsB,MACxB,GAAA,OAAO,IAAI,CAAC,MAAM,MAChB,sBAAA,cAAA,OAAA,EAAK,GAAG,aAAa,EAAE,MAAM,KAAK,GAAG,EACnC,GAAA,KAAK,IAAI,CAAC,OAAO,QACf,sBAAA,cAAA,QAAA,EAAM,GAAG,cAAc,EAAE,OAAO,KAAK,GAAG,CAC1C,CACH,CACD,CACH;AAAA,EAAA;AAIR;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinacms",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@graphql-inspector/core": "^6.2.1",
|
|
67
67
|
"@headlessui/react": "2.1.8",
|
|
68
68
|
"@heroicons/react": "^1.0.6",
|
|
69
|
-
"@monaco-editor/react": "4.
|
|
69
|
+
"@monaco-editor/react": "4.7.0-rc.0",
|
|
70
70
|
"@radix-ui/react-checkbox": "^1.1.4",
|
|
71
71
|
"@radix-ui/react-dialog": "^1.1.6",
|
|
72
72
|
"@radix-ui/react-dropdown-menu": "^2.1.6",
|
|
@@ -130,8 +130,8 @@
|
|
|
130
130
|
"yup": "^1.6.1",
|
|
131
131
|
"zod": "^3.24.2",
|
|
132
132
|
"@tinacms/mdx": "1.6.2",
|
|
133
|
-
"@tinacms/
|
|
134
|
-
"@tinacms/
|
|
133
|
+
"@tinacms/schema-tools": "1.7.3",
|
|
134
|
+
"@tinacms/search": "1.0.44"
|
|
135
135
|
},
|
|
136
136
|
"devDependencies": {
|
|
137
137
|
"@graphql-tools/utils": "^10.8.1",
|