sanity-plugin-latex-input 2.0.6 → 3.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Sanity.io
3
+ Copyright (c) 2026 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
- # LaTeX input for Sanity
1
+ # sanity-plugin-latex-input
2
2
 
3
- > This is a **Sanity Studio v3** plugin.
4
3
  > For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/latex-input/tree/studio-v2).
5
4
 
6
5
  ## What is it?
@@ -12,29 +11,20 @@ sanity-plugin-latex-input adds support for `latex` schema type, so it can be use
12
11
  ## Installation
13
12
 
14
13
  ```sh
15
- npm install --save sanity-plugin-latex-input
16
- ```
17
-
18
- or
19
-
20
- ```sh
21
- yarn add sanity-plugin-latex-input
14
+ npm install sanity-plugin-latex-input
22
15
  ```
23
16
 
24
17
  ## Usage
25
18
 
26
-
27
- Import and add the plugin to your studio config in sanity.config.ts (or .js):
19
+ Import and add the plugin to your studio config in `sanity.config.ts` (or `.js`):
28
20
 
29
21
  ```ts
30
- import { latexInput } from "sanity-plugin-latex-input";
22
+ import {latexInput} from 'sanity-plugin-latex-input'
31
23
 
32
24
  export default defineConfig({
33
25
  /* ... */
34
26
 
35
- plugins: [
36
- latexInput()
37
- ]
27
+ plugins: [latexInput()],
38
28
  })
39
29
  ```
40
30
 
@@ -42,14 +32,13 @@ You may now use the type name `latex` in your schema, such as in portable text.
42
32
 
43
33
  ## Example schema definition for portable text
44
34
 
45
- ```
46
- import React from 'react'
35
+ ```ts
47
36
  const mathInlineIcon = () => (
48
37
  <span>
49
- <span style={{ fontWeight: 'bold' }}>∑</span>b
38
+ <span style={{fontWeight: 'bold'}}>∑</span>b
50
39
  </span>
51
40
  )
52
- const mathIcon = () => <span style={{ fontWeight: 'bold' }}>∑</span>
41
+ const mathIcon = () => <span style={{fontWeight: 'bold'}}>∑</span>
53
42
 
54
43
  export default {
55
44
  name: 'portableTextWithLatex',
@@ -59,11 +48,9 @@ export default {
59
48
  {
60
49
  type: 'block',
61
50
  title: 'Block',
62
- of: [
63
- { type: 'latex', icon: mathInlineIcon, title: 'Inline math' },
64
- ],
51
+ of: [{type: 'latex', icon: mathInlineIcon, title: 'Inline math'}],
65
52
  },
66
- { type: 'latex', icon: mathIcon, title: 'Math block' },
53
+ {type: 'latex', icon: mathIcon, title: 'Math block'},
67
54
  ],
68
55
  }
69
56
  ```
@@ -73,18 +60,3 @@ The Portable Text editor will render a preview of the contents with KaTeX.
73
60
  ## License
74
61
 
75
62
  MIT-licensed. See LICENSE.
76
-
77
- ## Develop & test
78
-
79
- This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
80
- with default configuration for build & watch scripts.
81
-
82
- See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
83
- on how to run this plugin with hotreload in the studio.
84
-
85
- ### Release new version
86
-
87
- Run ["CI & Release" workflow](https://github.com/sanity-io/latex-input/actions/workflows/main.yml).
88
- Make sure to select the v3 branch and check "Release new version".
89
-
90
- Semantic release will only release on configured branches, so it is safe to run release on any branch.
@@ -0,0 +1,31 @@
1
+ import * as _$sanity from "sanity";
2
+ import { ObjectDefinition } from "sanity";
3
+ import * as _$react_jsx_runtime0 from "react/jsx-runtime";
4
+ declare const latexInput: _$sanity.Plugin<void>;
5
+ interface LatexPreviewProps {
6
+ body?: string;
7
+ layout?: string;
8
+ }
9
+ declare const LatexPreview: (props: LatexPreviewProps) => _$react_jsx_runtime0.JSX.Element;
10
+ declare const latexTypeName: "latex";
11
+ /**
12
+ * @public
13
+ */
14
+ interface LatexDefinition extends Omit<ObjectDefinition, 'type' | 'fields'> {
15
+ type: typeof latexTypeName;
16
+ }
17
+ declare module 'sanity' {
18
+ interface IntrinsicDefinitions {
19
+ latex: LatexDefinition;
20
+ }
21
+ }
22
+ declare const latexSchema: {
23
+ type: "object";
24
+ name: "latex";
25
+ } & Omit<ObjectDefinition, "preview"> & {
26
+ preview?: _$sanity.PreviewConfig<{
27
+ body: string;
28
+ }, Record<"body", any>> | undefined;
29
+ };
30
+ export { type LatexDefinition, LatexPreview, type LatexPreviewProps, latexInput, latexSchema };
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.tsx","../src/components/LatexPreview.tsx","../src/schema.ts"],"mappings":";;;cAIa,UAAA,EAKX,QAAA,CALqB,MAAA;AAAA,UCCN,iBAAA;EACf,IAAA;EACA,MAAA;AAAA;AAAA,cAKW,YAAA,GAAgB,KAAA,EAAO,iBAAA,KAAiB,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,cCR/C,aAAA;;;AFAN;UEKiB,eAAA,SAAwB,IAAA,CAAK,gBAAA;EAC5C,IAAA,SAAa,aAAA;AAAA;AAAA;EAAA,UAKI,oBAAA;IACf,KAAA,EAAO,eAAA;EAAA;AAAA;AAAA,cAIE,WAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import { defineType, definePlugin } from "sanity";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { c } from "react/compiler-runtime";
4
+ import { renderToString } from "katex";
5
+ import "katex/dist/katex.min.css";
6
+ const LatexPreview = (props) => {
7
+ const $ = c(6), latex = props?.body || "", isInline = props.layout === "inline", t0 = !isInline;
8
+ let t1;
9
+ $[0] !== latex || $[1] !== t0 ? (t1 = renderToString(latex, {
10
+ displayMode: t0,
11
+ throwOnError: !1
12
+ }), $[0] = latex, $[1] = t0, $[2] = t1) : t1 = $[2];
13
+ const html = t1;
14
+ let t2;
15
+ return $[3] !== html || $[4] !== isInline ? (t2 = isInline ? /* @__PURE__ */ jsx("span", { dangerouslySetInnerHTML: {
16
+ __html: html
17
+ } }) : /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: {
18
+ __html: html
19
+ } }), $[3] = html, $[4] = isInline, $[5] = t2) : t2 = $[5], t2;
20
+ }, latexSchema = defineType({
21
+ title: "Latex",
22
+ type: "object",
23
+ name: "latex",
24
+ components: {
25
+ preview: LatexPreview
26
+ },
27
+ fields: [{
28
+ title: "LaTeX content",
29
+ name: "body",
30
+ type: "text"
31
+ }],
32
+ preview: {
33
+ select: {
34
+ body: "body"
35
+ }
36
+ }
37
+ }), latexInput = definePlugin({
38
+ name: "latex-block-plugin",
39
+ schema: {
40
+ types: [latexSchema]
41
+ }
42
+ });
43
+ export {
44
+ LatexPreview,
45
+ latexInput,
46
+ latexSchema
47
+ };
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/components/LatexPreview.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["import {renderToString} from 'katex'\nimport {useMemo} from 'react'\n\nimport 'katex/dist/katex.min.css'\n\nexport interface LatexPreviewProps {\n body?: string\n layout?: string\n}\n\n// KaTeX's renderToString sanitizes its output and does not execute scripts,\n// making it safe to use with dangerouslySetInnerHTML for trusted LaTeX source content.\nexport const LatexPreview = (props: LatexPreviewProps) => {\n const latex = props?.body || ''\n const isInline = props.layout === 'inline'\n\n const html = useMemo(\n () =>\n renderToString(latex, {\n displayMode: !isInline,\n throwOnError: false,\n }),\n [latex, isInline],\n )\n\n return isInline ? (\n <span dangerouslySetInnerHTML={{__html: html}} />\n ) : (\n <div dangerouslySetInnerHTML={{__html: html}} />\n )\n}\n","import {defineType, type ObjectDefinition} from 'sanity'\n\nimport {LatexPreview} from './components/LatexPreview'\n\nconst latexTypeName = 'latex' as const\n\n/**\n * @public\n */\nexport interface LatexDefinition extends Omit<ObjectDefinition, 'type' | 'fields'> {\n type: typeof latexTypeName\n}\n\ndeclare module 'sanity' {\n // makes type: 'latex' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n latex: LatexDefinition\n }\n}\n\nexport const latexSchema = defineType({\n title: 'Latex',\n type: 'object',\n name: 'latex',\n components: {preview: LatexPreview},\n fields: [\n {\n title: 'LaTeX content',\n name: 'body',\n type: 'text',\n },\n ],\n preview: {\n select: {\n body: 'body',\n },\n },\n})\n","import {definePlugin} from 'sanity'\n\nimport {latexSchema} from './schema'\n\nexport const latexInput = definePlugin({\n name: 'latex-block-plugin',\n schema: {\n types: [latexSchema],\n },\n})\n"],"names":["LatexPreview","props","$","_c","latex","body","isInline","layout","t0","t1","renderToString","displayMode","throwOnError","html","t2","__html","latexSchema","defineType","title","type","name","components","preview","fields","select","latexInput","definePlugin","schema","types"],"mappings":";;;;;AAYO,MAAMA,eAAeC,CAAAA,UAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAC1BC,QAAcH,OAAKI,QAAL,IACdC,WAAiBL,MAAKM,WAAY,UAKfC,MAACF;AAAQ,MAAAG;AAAAP,IAAA,CAAA,MAAAE,SAAAF,SAAAM,MADxBC,KAAAC,eAAeN,OAAO;AAAA,IAAAO,aACPH;AAAAA,IAASI,cACR;AAAA,EAAA,CACf,GAACV,OAAAE,OAAAF,OAAAM,IAAAN,OAAAO,MAAAA,KAAAP,EAAA,CAAA;AALN,QAAAW,OAEIJ;AAKH,MAAAK;AAAA,SAAAZ,EAAA,CAAA,MAAAW,QAAAX,SAAAI,YAEMQ,KAAAR,WACL,oBAAA,QAAA,EAA+B,yBAAA;AAAA,IAAAS,QAASF;AAAAA,EAAAA,EAAI,CAAC,IAE7C,oBAAA,OAAA,EAA8B,yBAAA;AAAA,IAAAE,QAASF;AAAAA,EAAAA,GAAK,GAC7CX,OAAAW,MAAAX,OAAAI,UAAAJ,OAAAY,MAAAA,KAAAZ,EAAA,CAAA,GAJMY;AAIN,GCTUE,cAAcC,WAAW;AAAA,EACpCC,OAAO;AAAA,EACPC,MAAM;AAAA,EACNC,MAAM;AAAA,EACNC,YAAY;AAAA,IAACC,SAAStB;AAAAA,EAAAA;AAAAA,EACtBuB,QAAQ,CACN;AAAA,IACEL,OAAO;AAAA,IACPE,MAAM;AAAA,IACND,MAAM;AAAA,EAAA,CACP;AAAA,EAEHG,SAAS;AAAA,IACPE,QAAQ;AAAA,MACNnB,MAAM;AAAA,IAAA;AAAA,EACR;AAEJ,CAAC,GCjCYoB,aAAaC,aAAa;AAAA,EACrCN,MAAM;AAAA,EACNO,QAAQ;AAAA,IACNC,OAAO,CAACZ,WAAW;AAAA,EAAA;AAEvB,CAAC;"}
package/package.json CHANGED
@@ -1,100 +1,55 @@
1
1
  {
2
2
  "name": "sanity-plugin-latex-input",
3
- "version": "2.0.6",
4
- "description": "Latex input for Portable Text Editor in Sanity Studio V3.",
3
+ "version": "3.0.0",
4
+ "description": "LaTeX input for Portable Text Editor in Sanity Studio.",
5
5
  "keywords": [
6
- "sanity",
6
+ "latex",
7
7
  "plugin",
8
- "latex"
8
+ "sanity"
9
9
  ],
10
- "homepage": "https://github.com/sanity-io/latex-input#readme",
10
+ "homepage": "https://github.com/sanity-io/plugins/tree/main/plugins/sanity-plugin-latex-input#readme",
11
11
  "bugs": {
12
- "url": "https://github.com/sanity-io/latex-input/issues"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git@github.com:sanity-io/latex-input.git"
12
+ "url": "https://github.com/sanity-io/plugins/issues"
17
13
  },
18
14
  "license": "MIT",
19
15
  "author": "Sanity.io <hello@sanity.io>",
20
- "exports": {
21
- ".": {
22
- "types": "./lib/src/index.d.ts",
23
- "source": "./src/index.ts",
24
- "import": "./lib/index.esm.js",
25
- "require": "./lib/index.js",
26
- "default": "./lib/index.esm.js"
27
- },
28
- "./package.json": "./package.json"
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+ssh://git@github.com/sanity-io/plugins.git",
19
+ "directory": "plugins/sanity-plugin-latex-input"
29
20
  },
30
- "main": "./lib/index.js",
31
- "module": "./lib/index.esm.js",
32
- "source": "./src/index.ts",
33
- "types": "./lib/src/index.d.ts",
34
21
  "files": [
35
- "src",
36
- "lib",
37
- "v2-incompatible.js",
38
- "sanity.json"
22
+ "dist"
39
23
  ],
40
- "scripts": {
41
- "prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
42
- "build": "pkg-utils build --strict",
43
- "clean": "rimraf lib",
44
- "compile": "tsc --noEmit",
45
- "format": "prettier src -w",
46
- "link-watch": "plugin-kit link-watch",
47
- "lint": "eslint .",
48
- "lint:fix": "eslint . --fix",
49
- "prepare": "husky install",
50
- "prepublishOnly": "npm run build",
51
- "watch": "pkg-utils watch"
52
- },
53
- "prettier": {
54
- "printWidth": 80,
55
- "semi": true,
56
- "singleQuote": true,
57
- "trailingComma": "es5"
24
+ "type": "module",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": "./dist/index.js",
28
+ "./package.json": "./package.json"
58
29
  },
59
30
  "dependencies": {
60
- "@sanity/incompatible-plugin": "^1.0.4",
61
- "@types/katex": "^0.16.0",
62
- "katex": "^0.16.0"
31
+ "katex": "^0.17.0"
63
32
  },
64
33
  "devDependencies": {
65
- "@commitlint/cli": "^17.2.0",
66
- "@commitlint/config-conventional": "^17.2.0",
67
- "@sanity/pkg-utils": "^2.4.9",
68
- "@sanity/plugin-kit": "^2.1.19",
69
- "@sanity/semantic-release-preset": "^2.0.2",
70
- "@types/jest": "^27.5.0",
71
- "@types/react": "^18",
72
- "@types/react-dom": "^18",
73
- "@typescript-eslint/eslint-plugin": "^5.42.0",
74
- "@typescript-eslint/parser": "^5.42.0",
75
- "eslint": "^8.26.0",
76
- "eslint-config-prettier": "^8.5.0",
77
- "eslint-config-sanity": "^6.0.0",
78
- "eslint-plugin-prettier": "^4.2.1",
79
- "eslint-plugin-react": "^7.31.10",
80
- "eslint-plugin-react-hooks": "^4.6.0",
81
- "husky": "^8.0.1",
82
- "lint-staged": "^13.0.3",
83
- "prettier": "^2.7.1",
84
- "prettier-plugin-packagejson": "^2.3.0",
85
- "react": "^18",
86
- "react-dom": "^18",
87
- "rimraf": "^3.0.2",
88
- "sanity": "^3.0.1",
89
- "standard-version": "^9.3.2",
90
- "typescript": "^4.8.4"
34
+ "@sanity/pkg-utils": "^10.5.0",
35
+ "@types/react": "^19.2.14",
36
+ "@types/react-dom": "^19.2.3",
37
+ "babel-plugin-react-compiler": "^1.0.0",
38
+ "react": "^19.2.5",
39
+ "react-dom": "^19.2.5",
40
+ "sanity": "^5.21.0",
41
+ "@repo/package.config": "0.0.0",
42
+ "@repo/tsconfig": "0.0.0"
91
43
  },
92
44
  "peerDependencies": {
93
- "react": "^18",
94
- "react-dom": "^18",
95
- "sanity": "^3.0.0 || ^4.0.0-0"
45
+ "react": "^19.2",
46
+ "react-dom": "^19.2",
47
+ "sanity": "^5 || ^6.0.0-0"
96
48
  },
97
49
  "engines": {
98
- "node": ">=14"
50
+ "node": ">=20.19 <22 || >=22.12"
51
+ },
52
+ "scripts": {
53
+ "build": "pkg build --strict --check --clean"
99
54
  }
100
- }
55
+ }
package/lib/index.esm.js DELETED
@@ -1 +0,0 @@
1
- import{defineType as e,definePlugin as t}from"sanity";import{jsx as o,Fragment as r}from"react/jsx-runtime";import{useState as n,useMemo as i}from"react";import a from"katex";import"katex/dist/katex.min.css";const m=e=>{const t=(null==e?void 0:e.body)||"",m="inline"===e.layout,[l,p]=n("");return i((()=>{p(a.renderToString(t,{displayMode:!m,throwOnError:!1}))}),[t,m]),o(r,{children:o(m?"span":"div",{dangerouslySetInnerHTML:{__html:l}})})},l=e({type:"object",name:"latex",components:{preview:m},fields:[{title:"LaTeX content",name:"body",type:"text"}],preview:{select:{body:"body"}}}),p=t({name:"latex-block-plugin",schema:{types:[l]}});export{m as LatexPreview,p as latexInput,l as latexSchema};//# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/components/LatexPreview.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["import React, { useMemo, useState } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css';\n\nexport interface LatexPreviewProps {\n body?: string;\n layout?: string;\n}\n\nexport const LatexPreview = (props: LatexPreviewProps) => {\n const latex = props?.body || '';\n const isInline = props.layout === 'inline';\n const [html, setHtml] = useState<string>('');\n const createHtml = () => {\n setHtml(\n KaTeX.renderToString(latex, {\n displayMode: !isInline,\n throwOnError: false,\n })\n );\n };\n\n useMemo(createHtml, [latex, isInline]);\n return (\n <>\n {isInline ? (\n // eslint-disable-next-line react/no-danger\n <span dangerouslySetInnerHTML={{ __html: html }} />\n ) : (\n // eslint-disable-next-line react/no-danger\n <div dangerouslySetInnerHTML={{ __html: html }} />\n )}\n </>\n );\n};\n","import { defineType, ObjectDefinition } from 'sanity';\nimport { LatexPreview } from './components/LatexPreview';\n\nconst latexTypeName = 'latex' as const;\n\n/**\n * @public\n */\nexport interface LatexDefinition\n extends Omit<ObjectDefinition, 'type' | 'fields'> {\n type: typeof latexTypeName;\n}\n\ndeclare module '@sanity/types' {\n // makes type: 'latex' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n latex: LatexDefinition;\n }\n}\n\nexport const latexSchema = defineType({\n type: 'object',\n name: 'latex',\n components: { preview: LatexPreview },\n fields: [\n {\n title: 'LaTeX content',\n name: 'body',\n type: 'text',\n },\n ],\n preview: {\n select: {\n body: 'body',\n },\n },\n});\n","import { definePlugin } from 'sanity';\nimport { latexSchema } from './schema';\n\nexport const latexInput = definePlugin({\n name: 'latex-block-plugin',\n schema: {\n types: [latexSchema],\n },\n});\n"],"names":["defineType","definePlugin","jsx","Fragment","useState","useMemo","KaTeX","LatexPreview","props","latex","body","isInline","layout","html","setHtml","createHtml","renderToString","displayMode","throwOnError","children","dangerouslySetInnerHTML","__html","latexSchema","type","name","components","preview","fields","title","select","latexInput","schema","types"],"mappings":"qBASaA,kBAAAC,MAAA,uBAAAC,cAAAC,MAAA,uCAAAC,aAAAC,MAAA,eAAAC,MAAA,cAAA,2BAAA,MAAAC,EAAgBC,IACrB,MAAAC,SAAQD,WAAOE,OAAQ,GACvBC,EAA4B,WAAjBH,EAAMI,QAChBC,EAAMC,GAAWV,EAAiB,IAWzC,OADAC,GATmBU,KACjBD,EACER,EAAMU,eAAeP,EAAO,CAC1BQ,aAAcN,EACdO,cAAc,IAElB,GAGkB,CAACT,EAAOE,IAGvBT,EAAAC,EAAA,CAAAgB,WAAAR,EAEE,OAGA,MAHK,CAAAS,wBAAyB,CAAEC,OAAQR,MAK7C,ECZSS,EAActB,EAAW,CACpCuB,KAAM,SACNC,KAAM,QACNC,WAAY,CAAEC,QAASnB,GACvBoB,OAAQ,CACN,CACEC,MAAO,gBACPJ,KAAM,OACND,KAAM,SAGVG,QAAS,CACPG,OAAQ,CACNnB,KAAM,WC9BCoB,EAAa7B,EAAa,CACrCuB,KAAM,qBACNO,OAAQ,CACNC,MAAO,CAACV,aAEXf,kBAAAuB,gBAAAR"}
package/lib/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("sanity"),t=require("react/jsx-runtime"),r=require("react"),n=require("katex");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("katex/dist/katex.min.css");var i=a(n);const o=e=>{const n=(null==e?void 0:e.body)||"",a="inline"===e.layout,[o,s]=r.useState("");return r.useMemo((()=>{s(i.default.renderToString(n,{displayMode:!a,throwOnError:!1}))}),[n,a]),t.jsx(t.Fragment,{children:a?t.jsx("span",{dangerouslySetInnerHTML:{__html:o}}):t.jsx("div",{dangerouslySetInnerHTML:{__html:o}})})},s=e.defineType({type:"object",name:"latex",components:{preview:o},fields:[{title:"LaTeX content",name:"body",type:"text"}],preview:{select:{body:"body"}}}),l=e.definePlugin({name:"latex-block-plugin",schema:{types:[s]}});exports.LatexPreview=o,exports.latexInput=l,exports.latexSchema=s;//# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/components/LatexPreview.tsx","../src/schema.ts","../src/plugin.tsx"],"sourcesContent":["import React, { useMemo, useState } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css';\n\nexport interface LatexPreviewProps {\n body?: string;\n layout?: string;\n}\n\nexport const LatexPreview = (props: LatexPreviewProps) => {\n const latex = props?.body || '';\n const isInline = props.layout === 'inline';\n const [html, setHtml] = useState<string>('');\n const createHtml = () => {\n setHtml(\n KaTeX.renderToString(latex, {\n displayMode: !isInline,\n throwOnError: false,\n })\n );\n };\n\n useMemo(createHtml, [latex, isInline]);\n return (\n <>\n {isInline ? (\n // eslint-disable-next-line react/no-danger\n <span dangerouslySetInnerHTML={{ __html: html }} />\n ) : (\n // eslint-disable-next-line react/no-danger\n <div dangerouslySetInnerHTML={{ __html: html }} />\n )}\n </>\n );\n};\n","import { defineType, ObjectDefinition } from 'sanity';\nimport { LatexPreview } from './components/LatexPreview';\n\nconst latexTypeName = 'latex' as const;\n\n/**\n * @public\n */\nexport interface LatexDefinition\n extends Omit<ObjectDefinition, 'type' | 'fields'> {\n type: typeof latexTypeName;\n}\n\ndeclare module '@sanity/types' {\n // makes type: 'latex' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n latex: LatexDefinition;\n }\n}\n\nexport const latexSchema = defineType({\n type: 'object',\n name: 'latex',\n components: { preview: LatexPreview },\n fields: [\n {\n title: 'LaTeX content',\n name: 'body',\n type: 'text',\n },\n ],\n preview: {\n select: {\n body: 'body',\n },\n },\n});\n","import { definePlugin } from 'sanity';\nimport { latexSchema } from './schema';\n\nexport const latexInput = definePlugin({\n name: 'latex-block-plugin',\n schema: {\n types: [latexSchema],\n },\n});\n"],"names":["Object","defineProperty","exports","value","sanity","require","jsxRuntime","react","KaTeX","_interopDefaultCompat","e","default","KaTeX__default","LatexPreview","props","latex","body","isInline","layout","html","setHtml","useState","useMemo","createHtml","renderToString","displayMode","throwOnError","jsx","Fragment","children","dangerouslySetInnerHTML","__html","latexSchema","defineType","type","name","components","preview","fields","title","select","latexInput","definePlugin","schema","types"],"mappings":"AASa,aAAAA,OAAAC,eAAAC,QAAA,aAAA,CAAAC,OAAA,IAAA,IAAAC,EAAAC,QAAA,UAAAC,EAAAD,QAAA,qBAAAE,EAAAF,QAAA,SAAAG,EAAAH,QAAA,SAAA,SAAAI,EAAAC,GAAA,OAAAA,GAAA,iBAAAA,GAAA,YAAAA,EAAAA,EAAA,CAAAC,QAAAD,EAAA,CAAAL,QAAA,4BAAA,IAAAO,EAAAH,EAAAD,GAAA,MAAAK,EAAgBC,IACrB,MAAAC,SAAQD,WAAOE,OAAQ,GACvBC,EAA4B,WAAjBH,EAAMI,QAChBC,EAAMC,GAAWC,WAAiB,IAWzC,OADAC,EAAAA,SATmBC,KACjBH,EACEZ,EAAAG,QAAMa,eAAeT,EAAO,CAC1BU,aAAcR,EACdS,cAAc,IAElB,GAGkB,CAACX,EAAOE,IAGvBU,MAAAC,EAAAA,SAAA,CAAAC,SAAAZ,QAEE,OAAK,CAAAa,wBAAyB,CAAEC,OAAQZ,WAGxC,MAAI,CAAAW,wBAAyB,CAAEC,OAAQZ,MAE5C,ECZSa,EAAcC,EAAAA,WAAW,CACpCC,KAAM,SACNC,KAAM,QACNC,WAAY,CAAEC,QAASxB,GACvByB,OAAQ,CACN,CACEC,MAAO,gBACPJ,KAAM,OACND,KAAM,SAGVG,QAAS,CACPG,OAAQ,CACNxB,KAAM,WC9BCyB,EAAaC,eAAa,CACrCP,KAAM,qBACNQ,OAAQ,CACNC,MAAO,CAACZ,MAEX9B,QAAAW,aAAAA,EAAAX,QAAAuC,WAAAA,EAAAvC,QAAA8B,YAAAA"}
@@ -1,47 +0,0 @@
1
- import { ObjectDefinition } from 'sanity';
2
- import { Plugin as Plugin_2 } from 'sanity';
3
- import { PreviewConfig } from 'sanity';
4
- import { default as React_2 } from 'react';
5
-
6
- /**
7
- * @public
8
- */
9
- export declare interface LatexDefinition
10
- extends Omit<ObjectDefinition, 'type' | 'fields'> {
11
- type: typeof latexTypeName;
12
- }
13
-
14
- export declare const latexInput: Plugin_2<void>;
15
-
16
- export declare const LatexPreview: (
17
- props: LatexPreviewProps
18
- ) => React_2.JSX.Element;
19
-
20
- export declare interface LatexPreviewProps {
21
- body?: string;
22
- layout?: string;
23
- }
24
-
25
- export declare const latexSchema: {
26
- type: 'object';
27
- name: 'latex';
28
- } & Omit<ObjectDefinition, 'preview'> & {
29
- preview?:
30
- | PreviewConfig<
31
- {
32
- body: string;
33
- },
34
- Record<'body', any>
35
- >
36
- | undefined;
37
- };
38
-
39
- declare const latexTypeName: 'latex';
40
-
41
- export {};
42
-
43
- declare module '@sanity/types' {
44
- interface IntrinsicDefinitions {
45
- latex: LatexDefinition;
46
- }
47
- }
package/sanity.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "parts": [
3
- {
4
- "implements": "part:@sanity/base/sanity-root",
5
- "path": "./v2-incompatible.js"
6
- }
7
- ]
8
- }
@@ -1,35 +0,0 @@
1
- import React, { useMemo, useState } from 'react';
2
- import KaTeX from 'katex';
3
- import 'katex/dist/katex.min.css';
4
-
5
- export interface LatexPreviewProps {
6
- body?: string;
7
- layout?: string;
8
- }
9
-
10
- export const LatexPreview = (props: LatexPreviewProps) => {
11
- const latex = props?.body || '';
12
- const isInline = props.layout === 'inline';
13
- const [html, setHtml] = useState<string>('');
14
- const createHtml = () => {
15
- setHtml(
16
- KaTeX.renderToString(latex, {
17
- displayMode: !isInline,
18
- throwOnError: false,
19
- })
20
- );
21
- };
22
-
23
- useMemo(createHtml, [latex, isInline]);
24
- return (
25
- <>
26
- {isInline ? (
27
- // eslint-disable-next-line react/no-danger
28
- <span dangerouslySetInnerHTML={{ __html: html }} />
29
- ) : (
30
- // eslint-disable-next-line react/no-danger
31
- <div dangerouslySetInnerHTML={{ __html: html }} />
32
- )}
33
- </>
34
- );
35
- };
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export { latexInput } from './plugin';
2
-
3
- export {
4
- LatexPreview,
5
- type LatexPreviewProps,
6
- } from './components/LatexPreview';
7
-
8
- export { latexSchema, type LatexDefinition } from './schema';
package/src/plugin.tsx DELETED
@@ -1,9 +0,0 @@
1
- import { definePlugin } from 'sanity';
2
- import { latexSchema } from './schema';
3
-
4
- export const latexInput = definePlugin({
5
- name: 'latex-block-plugin',
6
- schema: {
7
- types: [latexSchema],
8
- },
9
- });
package/src/schema.ts DELETED
@@ -1,37 +0,0 @@
1
- import { defineType, ObjectDefinition } from 'sanity';
2
- import { LatexPreview } from './components/LatexPreview';
3
-
4
- const latexTypeName = 'latex' as const;
5
-
6
- /**
7
- * @public
8
- */
9
- export interface LatexDefinition
10
- extends Omit<ObjectDefinition, 'type' | 'fields'> {
11
- type: typeof latexTypeName;
12
- }
13
-
14
- declare module '@sanity/types' {
15
- // makes type: 'latex' narrow correctly when using defineType/defineField/defineArrayMember
16
- export interface IntrinsicDefinitions {
17
- latex: LatexDefinition;
18
- }
19
- }
20
-
21
- export const latexSchema = defineType({
22
- type: 'object',
23
- name: 'latex',
24
- components: { preview: LatexPreview },
25
- fields: [
26
- {
27
- title: 'LaTeX content',
28
- name: 'body',
29
- type: 'text',
30
- },
31
- ],
32
- preview: {
33
- select: {
34
- body: 'body',
35
- },
36
- },
37
- });
@@ -1,11 +0,0 @@
1
- const { showIncompatiblePluginDialog } = require('@sanity/incompatible-plugin');
2
- const { name, version, sanityExchangeUrl } = require('./package.json');
3
-
4
- export default showIncompatiblePluginDialog({
5
- name: name,
6
- versions: {
7
- v3: version,
8
- v2: '^1.0.0',
9
- },
10
- sanityExchangeUrl,
11
- });