sanity-plugin-latex-input 0.0.5 → 0.3.0-v3-studio.1

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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -1
  3. package/lib/cjs/index.js +83 -0
  4. package/lib/cjs/index.js.map +1 -0
  5. package/lib/esm/index.js +75 -0
  6. package/lib/esm/index.js.map +1 -0
  7. package/lib/types/index.d.ts +11 -0
  8. package/lib/types/index.d.ts.map +1 -0
  9. package/package.json +85 -36
  10. package/sanity.json +2 -18
  11. package/src/components/LatexPreview.tsx +41 -0
  12. package/src/index.tsx +34 -0
  13. package/v2-incompatible.js +11 -0
  14. package/.babelrc +0 -7
  15. package/.eslintrc +0 -11
  16. package/lib/components/Katex.css +0 -1012
  17. package/lib/components/LatexInput.js +0 -162
  18. package/lib/components/LatexPreview.css +0 -26
  19. package/lib/components/LatexPreview.js +0 -138
  20. package/lib/components/fonts/KaTeX_AMS-Regular.eot +0 -0
  21. package/lib/components/fonts/KaTeX_AMS-Regular.ttf +0 -0
  22. package/lib/components/fonts/KaTeX_AMS-Regular.woff +0 -0
  23. package/lib/components/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  24. package/lib/components/fonts/KaTeX_Caligraphic-Bold.eot +0 -0
  25. package/lib/components/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  26. package/lib/components/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  27. package/lib/components/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  28. package/lib/components/fonts/KaTeX_Caligraphic-Regular.eot +0 -0
  29. package/lib/components/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  30. package/lib/components/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  31. package/lib/components/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  32. package/lib/components/fonts/KaTeX_Fraktur-Bold.eot +0 -0
  33. package/lib/components/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  34. package/lib/components/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  35. package/lib/components/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  36. package/lib/components/fonts/KaTeX_Fraktur-Regular.eot +0 -0
  37. package/lib/components/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  38. package/lib/components/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  39. package/lib/components/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  40. package/lib/components/fonts/KaTeX_Main-Bold.eot +0 -0
  41. package/lib/components/fonts/KaTeX_Main-Bold.ttf +0 -0
  42. package/lib/components/fonts/KaTeX_Main-Bold.woff +0 -0
  43. package/lib/components/fonts/KaTeX_Main-Bold.woff2 +0 -0
  44. package/lib/components/fonts/KaTeX_Main-Italic.eot +0 -0
  45. package/lib/components/fonts/KaTeX_Main-Italic.ttf +0 -0
  46. package/lib/components/fonts/KaTeX_Main-Italic.woff +0 -0
  47. package/lib/components/fonts/KaTeX_Main-Italic.woff2 +0 -0
  48. package/lib/components/fonts/KaTeX_Main-Regular.eot +0 -0
  49. package/lib/components/fonts/KaTeX_Main-Regular.ttf +0 -0
  50. package/lib/components/fonts/KaTeX_Main-Regular.woff +0 -0
  51. package/lib/components/fonts/KaTeX_Main-Regular.woff2 +0 -0
  52. package/lib/components/fonts/KaTeX_Math-Italic.eot +0 -0
  53. package/lib/components/fonts/KaTeX_Math-Italic.ttf +0 -0
  54. package/lib/components/fonts/KaTeX_Math-Italic.woff +0 -0
  55. package/lib/components/fonts/KaTeX_Math-Italic.woff2 +0 -0
  56. package/lib/components/fonts/KaTeX_SansSerif-Regular.eot +0 -0
  57. package/lib/components/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  58. package/lib/components/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  59. package/lib/components/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  60. package/lib/components/fonts/KaTeX_Script-Regular.eot +0 -0
  61. package/lib/components/fonts/KaTeX_Script-Regular.ttf +0 -0
  62. package/lib/components/fonts/KaTeX_Script-Regular.woff +0 -0
  63. package/lib/components/fonts/KaTeX_Script-Regular.woff2 +0 -0
  64. package/lib/components/fonts/KaTeX_Size1-Regular.eot +0 -0
  65. package/lib/components/fonts/KaTeX_Size1-Regular.ttf +0 -0
  66. package/lib/components/fonts/KaTeX_Size1-Regular.woff +0 -0
  67. package/lib/components/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  68. package/lib/components/fonts/KaTeX_Size2-Regular.eot +0 -0
  69. package/lib/components/fonts/KaTeX_Size2-Regular.ttf +0 -0
  70. package/lib/components/fonts/KaTeX_Size2-Regular.woff +0 -0
  71. package/lib/components/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  72. package/lib/components/fonts/KaTeX_Size3-Regular.eot +0 -0
  73. package/lib/components/fonts/KaTeX_Size3-Regular.ttf +0 -0
  74. package/lib/components/fonts/KaTeX_Size3-Regular.woff +0 -0
  75. package/lib/components/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  76. package/lib/components/fonts/KaTeX_Size4-Regular.eot +0 -0
  77. package/lib/components/fonts/KaTeX_Size4-Regular.ttf +0 -0
  78. package/lib/components/fonts/KaTeX_Size4-Regular.woff +0 -0
  79. package/lib/components/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  80. package/lib/components/fonts/KaTeX_Typewriter-Regular.eot +0 -0
  81. package/lib/components/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  82. package/lib/components/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  83. package/lib/components/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  84. package/lib/config.js +0 -15
  85. package/lib/index.js +0 -16
  86. package/lib/schema.js +0 -31
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Sanity.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,93 @@
1
1
  # LaTeX input for Sanity
2
2
 
3
- https://sanity.io
3
+ > **NOTE**
4
+ >
5
+ > This is the **Sanity Studio v3 version** of sanity-plugin-latex-input.
6
+ >
7
+ > For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/latex-input).
8
+
9
+ ## What is it?
10
+
11
+ sanity-plugin-latex-input adds support for `latex` schema type, so it can be used in Portable Text Editor (PTE) in Sanity Studio.
12
+
13
+ ![latex-input preview](assets/latex-input.png)
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ npm install --save sanity-plugin-latex-input@studio-v3
19
+ ```
20
+
21
+ or
22
+
23
+ ```sh
24
+ yarn add sanity-plugin-latex-input@studio-v3
25
+ ```
26
+
27
+ ## Usage
28
+
29
+
30
+ Import and add the plugin to your studio config in sanity.config.ts (or .js):
31
+
32
+ ```ts
33
+ import { latexBlock } from "sanity-plugin-latex-input";
34
+
35
+ export default createConfig({
36
+ /* ... */
37
+
38
+ plugins: [
39
+ latexInput()
40
+ ]
41
+ })
42
+ ```
43
+
44
+ You may now use the type name `latex` in your schema, such as in portable text.
45
+
46
+ ## Example schema definition for portable text
47
+
48
+ ```
49
+ import React from 'react'
50
+ const mathInlineIcon = () => (
51
+ <span>
52
+ <span style={{ fontWeight: 'bold' }}>∑</span>b
53
+ </span>
54
+ )
55
+ const mathIcon = () => <span style={{ fontWeight: 'bold' }}>∑</span>
56
+
57
+ export default {
58
+ name: 'portableTextWithLatex',
59
+ type: 'array',
60
+ title: 'Body',
61
+ of: [
62
+ {
63
+ type: 'block',
64
+ title: 'Block',
65
+ of: [
66
+ { type: 'latex', icon: mathInlineIcon, title: 'Inline math' },
67
+ ],
68
+ },
69
+ { type: 'latex', icon: mathIcon, title: 'Math block' },
70
+ ],
71
+ }
72
+ ```
73
+
74
+ The Portable Text editor will render a preview of the contents with KaTeX.
75
+
76
+ ## License
77
+
78
+ MIT-licensed. See LICENSE.
79
+
80
+ ## Develop & test
81
+
82
+ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
83
+ with default configuration for build & watch scripts.
84
+
85
+ See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
86
+ on how to run this plugin with hotreload in the studio.
87
+
88
+ ### Release new version
89
+
90
+ Run ["CI & Release" workflow](https://github.com/sanity-io/latex-input/actions/workflows/main.yml).
91
+ Make sure to select the v3 branch and check "Release new version".
92
+
93
+ Semantic release will only release on configured branches, so it is safe to run release on any branch.
@@ -0,0 +1,83 @@
1
+ var $dyHF6$sanity = require("sanity");
2
+ var $dyHF6$reactjsxruntime = require("react/jsx-runtime");
3
+ var $dyHF6$react = require("react");
4
+ var $dyHF6$katex = require("katex");
5
+ require("katex/dist/katex.min.css");
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
+ }
10
+ function $parcel$interopDefault(a) {
11
+ return a && a.__esModule ? a.default : a;
12
+ }
13
+
14
+ $parcel$export(module.exports, "latexInput", () => $329a1cedcedb1349$export$17b0a661cd4afef9);
15
+ $parcel$export(module.exports, "LatexPreview", () => $a18100092750648b$export$2e2bcd8739ae039);
16
+
17
+
18
+
19
+
20
+ const $a18100092750648b$var$LatexPreview = (props)=>{
21
+ const latex = props.value && props.value.body || "";
22
+ const isInline = props.layout === "inline";
23
+ const [html, setHtml] = (0, $dyHF6$react.useState)("");
24
+ const createHtml = ()=>{
25
+ setHtml((0, ($parcel$interopDefault($dyHF6$katex))).renderToString(latex, {
26
+ displayMode: !isInline,
27
+ throwOnError: false
28
+ }));
29
+ };
30
+ (0, $dyHF6$react.useMemo)(createHtml, [
31
+ latex,
32
+ isInline
33
+ ]);
34
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$reactjsxruntime.Fragment), {
35
+ children: isInline ? // eslint-disable-next-line react/no-danger
36
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("span", {
37
+ dangerouslySetInnerHTML: {
38
+ __html: html
39
+ }
40
+ }) : // eslint-disable-next-line react/no-danger
41
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("div", {
42
+ dangerouslySetInnerHTML: {
43
+ __html: html
44
+ }
45
+ })
46
+ });
47
+ };
48
+ var $a18100092750648b$export$2e2bcd8739ae039 = $a18100092750648b$var$LatexPreview;
49
+
50
+
51
+
52
+ const $329a1cedcedb1349$export$17b0a661cd4afef9 = (0, $dyHF6$sanity.createPlugin)({
53
+ name: "latex-block-plugin",
54
+ schema: {
55
+ types: [
56
+ (0, $dyHF6$sanity.defineType)({
57
+ type: "object",
58
+ name: "latex",
59
+ components: {
60
+ preview: (0, $a18100092750648b$export$2e2bcd8739ae039)
61
+ },
62
+ fields: [
63
+ {
64
+ title: "LaTeX content",
65
+ name: "body",
66
+ type: "text"
67
+ },
68
+ ],
69
+ preview: {
70
+ select: {
71
+ body: "body"
72
+ },
73
+ prepare (selection) {
74
+ return selection;
75
+ }
76
+ }
77
+ }),
78
+ ]
79
+ }
80
+ });
81
+
82
+
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;ACAA;;;;AAaA,MAAM,kCAAY,GAAG,CAAC,KAAwB,GAAK;IACjD,MAAM,KAAK,GAAG,AAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,IAAK,EAAE,AAAC;IACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,KAAK,QAAQ,AAAC;IAC3C,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAA,GAAA,qBAAQ,CAAA,CAAS,EAAE,CAAC,AAAC;IAC7C,MAAM,UAAU,GAAG,IAAM;QACvB,OAAO,CACL,CAAA,GAAA,sCAAK,CAAA,CAAC,cAAc,CAAC,KAAK,EAAE;YAC1B,WAAW,EAAE,CAAC,QAAQ;YACtB,YAAY,EAAE,KAAK;SACpB,CAAC,CACH,CAAC;KACH,AAAC;IAEF,CAAA,GAAA,oBAAO,CAAA,CAAC,UAAU,EAAE;QAAC,KAAK;QAAE,QAAQ;KAAC,CAAC,CAAC;IACvC,qBACE;kBACG,QAAQ,GACP,2CAA2C;sBAC3C,gCAAC,MAAI;YAAC,uBAAuB,EAAE;gBAAE,MAAM,EAAE,IAAI;aAAE;UAAI,GAEnD,2CAA2C;sBAC3C,gCAAC,KAAG;YAAC,uBAAuB,EAAE;gBAAE,MAAM,EAAE,IAAI;aAAE;UAAI,AACnD;MACA,CACH;CACH,AAAC;IAEF,wCAA4B,GAAb,kCAAY;;ADxC3B;;AAKO,MAAM,yCAAU,GAAG,CAAA,GAAA,0BAAY,CAAA,CAAC;IACrC,IAAI,EAAE,oBAAoB;IAC1B,MAAM,EAAE;QACN,KAAK,EAAE;YACL,CAAA,GAAA,wBAAU,CAAA,CAAC;gBACT,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE;oBACV,OAAO,EAAE,CAAA,GAAA,wCAAY,CAAA;iBACtB;gBACD,MAAM,EAAE;oBACN;wBACE,KAAK,EAAE,eAAe;wBACtB,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,MAAM;qBACb;iBACF;gBACD,OAAO,EAAE;oBACP,MAAM,EAAE;wBACN,IAAI,EAAE,MAAM;qBACb;oBACD,OAAO,EAAC,SAAuB,EAAE;wBAC/B,OAAO,SAAS,CAAC;qBAClB;iBACF;aACF,CAAC;SACH;KACF;CACF,CAAC,AAAC","sources":["src/index.tsx","src/components/LatexPreview.tsx"],"sourcesContent":["import LatexPreview, { LatexPreviewProps } from './components/LatexPreview';\nimport { createPlugin, defineType, type PreviewValue } from 'sanity';\n\nexport { LatexPreview, type LatexPreviewProps };\n\nexport const latexInput = createPlugin({\n name: 'latex-block-plugin',\n schema: {\n types: [\n defineType({\n type: 'object',\n name: 'latex',\n components: {\n preview: LatexPreview,\n },\n fields: [\n {\n title: 'LaTeX content',\n name: 'body',\n type: 'text',\n },\n ],\n preview: {\n select: {\n body: 'body',\n },\n prepare(selection: PreviewValue) {\n return selection;\n },\n },\n }),\n ],\n },\n});\n","import React, { useMemo, useState } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css';\n\ntype SchemaDefinition = {\n body?: string;\n};\n\nexport type LatexPreviewProps = {\n value?: SchemaDefinition;\n layout?: string;\n};\n\nconst LatexPreview = (props: LatexPreviewProps) => {\n const latex = (props.value && props.value.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\nexport default LatexPreview;\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../"}
@@ -0,0 +1,75 @@
1
+ import {createPlugin as $7XdDa$createPlugin, defineType as $7XdDa$defineType} from "sanity";
2
+ import {jsx as $7XdDa$jsx, Fragment as $7XdDa$Fragment} from "react/jsx-runtime";
3
+ import {useState as $7XdDa$useState, useMemo as $7XdDa$useMemo} from "react";
4
+ import $7XdDa$katex from "katex";
5
+ import "katex/dist/katex.min.css";
6
+
7
+
8
+
9
+
10
+
11
+ const $7dfe52883a1c33dd$var$LatexPreview = (props)=>{
12
+ const latex = props.value && props.value.body || "";
13
+ const isInline = props.layout === "inline";
14
+ const [html, setHtml] = (0, $7XdDa$useState)("");
15
+ const createHtml = ()=>{
16
+ setHtml((0, $7XdDa$katex).renderToString(latex, {
17
+ displayMode: !isInline,
18
+ throwOnError: false
19
+ }));
20
+ };
21
+ (0, $7XdDa$useMemo)(createHtml, [
22
+ latex,
23
+ isInline
24
+ ]);
25
+ return /*#__PURE__*/ (0, $7XdDa$jsx)((0, $7XdDa$Fragment), {
26
+ children: isInline ? // eslint-disable-next-line react/no-danger
27
+ /*#__PURE__*/ (0, $7XdDa$jsx)("span", {
28
+ dangerouslySetInnerHTML: {
29
+ __html: html
30
+ }
31
+ }) : // eslint-disable-next-line react/no-danger
32
+ /*#__PURE__*/ (0, $7XdDa$jsx)("div", {
33
+ dangerouslySetInnerHTML: {
34
+ __html: html
35
+ }
36
+ })
37
+ });
38
+ };
39
+ var $7dfe52883a1c33dd$export$2e2bcd8739ae039 = $7dfe52883a1c33dd$var$LatexPreview;
40
+
41
+
42
+
43
+ const $357f50a17451fe9f$export$17b0a661cd4afef9 = (0, $7XdDa$createPlugin)({
44
+ name: "latex-block-plugin",
45
+ schema: {
46
+ types: [
47
+ (0, $7XdDa$defineType)({
48
+ type: "object",
49
+ name: "latex",
50
+ components: {
51
+ preview: (0, $7dfe52883a1c33dd$export$2e2bcd8739ae039)
52
+ },
53
+ fields: [
54
+ {
55
+ title: "LaTeX content",
56
+ name: "body",
57
+ type: "text"
58
+ },
59
+ ],
60
+ preview: {
61
+ select: {
62
+ body: "body"
63
+ },
64
+ prepare (selection) {
65
+ return selection;
66
+ }
67
+ }
68
+ }),
69
+ ]
70
+ }
71
+ });
72
+
73
+
74
+ export {$357f50a17451fe9f$export$17b0a661cd4afef9 as latexInput, $7dfe52883a1c33dd$export$2e2bcd8739ae039 as LatexPreview};
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;ACAA;;;;AAaA,MAAM,kCAAY,GAAG,CAAC,KAAwB,GAAK;IACjD,MAAM,KAAK,GAAG,AAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,IAAK,EAAE,AAAC;IACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,KAAK,QAAQ,AAAC;IAC3C,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAA,GAAA,eAAQ,CAAA,CAAS,EAAE,CAAC,AAAC;IAC7C,MAAM,UAAU,GAAG,IAAM;QACvB,OAAO,CACL,CAAA,GAAA,YAAK,CAAA,CAAC,cAAc,CAAC,KAAK,EAAE;YAC1B,WAAW,EAAE,CAAC,QAAQ;YACtB,YAAY,EAAE,KAAK;SACpB,CAAC,CACH,CAAC;KACH,AAAC;IAEF,CAAA,GAAA,cAAO,CAAA,CAAC,UAAU,EAAE;QAAC,KAAK;QAAE,QAAQ;KAAC,CAAC,CAAC;IACvC,qBACE;kBACG,QAAQ,GACP,2CAA2C;sBAC3C,gBAAC,MAAI;YAAC,uBAAuB,EAAE;gBAAE,MAAM,EAAE,IAAI;aAAE;UAAI,GAEnD,2CAA2C;sBAC3C,gBAAC,KAAG;YAAC,uBAAuB,EAAE;gBAAE,MAAM,EAAE,IAAI;aAAE;UAAI,AACnD;MACA,CACH;CACH,AAAC;IAEF,wCAA4B,GAAb,kCAAY;;ADxC3B;;AAKO,MAAM,yCAAU,GAAG,CAAA,GAAA,mBAAY,CAAA,CAAC;IACrC,IAAI,EAAE,oBAAoB;IAC1B,MAAM,EAAE;QACN,KAAK,EAAE;YACL,CAAA,GAAA,iBAAU,CAAA,CAAC;gBACT,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE;oBACV,OAAO,EAAE,CAAA,GAAA,wCAAY,CAAA;iBACtB;gBACD,MAAM,EAAE;oBACN;wBACE,KAAK,EAAE,eAAe;wBACtB,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,MAAM;qBACb;iBACF;gBACD,OAAO,EAAE;oBACP,MAAM,EAAE;wBACN,IAAI,EAAE,MAAM;qBACb;oBACD,OAAO,EAAC,SAAuB,EAAE;wBAC/B,OAAO,SAAS,CAAC;qBAClB;iBACF;aACF,CAAC;SACH;KACF;CACF,CAAC,AAAC","sources":["src/index.tsx","src/components/LatexPreview.tsx"],"sourcesContent":["import LatexPreview, { LatexPreviewProps } from './components/LatexPreview';\nimport { createPlugin, defineType, type PreviewValue } from 'sanity';\n\nexport { LatexPreview, type LatexPreviewProps };\n\nexport const latexInput = createPlugin({\n name: 'latex-block-plugin',\n schema: {\n types: [\n defineType({\n type: 'object',\n name: 'latex',\n components: {\n preview: LatexPreview,\n },\n fields: [\n {\n title: 'LaTeX content',\n name: 'body',\n type: 'text',\n },\n ],\n preview: {\n select: {\n body: 'body',\n },\n prepare(selection: PreviewValue) {\n return selection;\n },\n },\n }),\n ],\n },\n});\n","import React, { useMemo, useState } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css';\n\ntype SchemaDefinition = {\n body?: string;\n};\n\nexport type LatexPreviewProps = {\n value?: SchemaDefinition;\n layout?: string;\n};\n\nconst LatexPreview = (props: LatexPreviewProps) => {\n const latex = (props.value && props.value.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\nexport default LatexPreview;\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../"}
@@ -0,0 +1,11 @@
1
+ type SchemaDefinition = {
2
+ body?: string;
3
+ };
4
+ export type LatexPreviewProps = {
5
+ value?: SchemaDefinition;
6
+ layout?: string;
7
+ };
8
+ export default LatexPreview;
9
+ export const latexInput: import("sanity").Plugin<void>;
10
+
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAIA,wBAAwB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,gCAAgC;IAC9B,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA6BF,4BAA4B;ACnC5B,OAAO,MAAM,yCA4BX,CAAC","sources":["src/src/components/LatexPreview.tsx","src/src/index.tsx","src/index.tsx"],"sourcesContent":[null,null,"import LatexPreview, { LatexPreviewProps } from './components/LatexPreview';\nimport { createPlugin, defineType, type PreviewValue } from 'sanity';\n\nexport { LatexPreview, type LatexPreviewProps };\n\nexport const latexInput = createPlugin({\n name: 'latex-block-plugin',\n schema: {\n types: [\n defineType({\n type: 'object',\n name: 'latex',\n components: {\n preview: LatexPreview,\n },\n fields: [\n {\n title: 'LaTeX content',\n name: 'body',\n type: 'text',\n },\n ],\n preview: {\n select: {\n body: 'body',\n },\n prepare(selection: PreviewValue) {\n return selection;\n },\n },\n }),\n ],\n },\n});\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../"}
package/package.json CHANGED
@@ -1,49 +1,98 @@
1
1
  {
2
2
  "name": "sanity-plugin-latex-input",
3
- "version": "0.0.5",
4
- "description": "LaTeX input for Sanity",
5
- "author": "hello@bengler.no",
6
- "homepage": "https://github.com/sanity-io/latex-input#readme",
7
- "public": true,
8
- "keywords": [
9
- "sanity",
10
- "pluign",
11
- "latex",
12
- "input"
3
+ "author": "Sanity.io <hello@sanity.io>",
4
+ "version": "0.3.0-v3-studio.1",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/sanity-io/latex-input.git"
9
+ },
10
+ "source": "./src/index.tsx",
11
+ "exports": {
12
+ ".": {
13
+ "require": "./lib/cjs/index.js",
14
+ "default": "./lib/esm/index.js"
15
+ }
16
+ },
17
+ "main": "./lib/cjs/index.js",
18
+ "module": "./lib/esm/index.js",
19
+ "types": "./lib/types/index.d.ts",
20
+ "files": [
21
+ "src",
22
+ "lib",
23
+ "v2-incompatible.js",
24
+ "sanity.json"
13
25
  ],
14
- "main": "lib/index.js",
15
- "license": "ISC",
16
- "bugs": {
17
- "url": "https://github.com/sanity-io/latex-input/issues"
26
+ "engines": {
27
+ "node": ">=14.0.0"
18
28
  },
19
29
  "scripts": {
20
- "build": "babel src -d lib --copy-files",
21
- "test": "echo \"Error: no test specified\" && exit 1"
30
+ "clean": "rimraf lib",
31
+ "prebuild": "npm run clean && plugin-kit verify-package --silent",
32
+ "build": "parcel build --no-cache",
33
+ "watch": "parcel watch",
34
+ "link-watch": "plugin-kit link-watch",
35
+ "prepublishOnly": "npm run build",
36
+ "compile": "tsc --noEmit",
37
+ "lint": "eslint .",
38
+ "lint:fix": "eslint . --fix",
39
+ "format": "prettier src -w",
40
+ "prepare": "husky install"
22
41
  },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/sanity-io/latex-input.git"
42
+ "prettier": {
43
+ "printWidth": 80,
44
+ "semi": true,
45
+ "singleQuote": true,
46
+ "trailingComma": "es5"
26
47
  },
27
- "devDependencies": {
28
- "babel-cli": "^6.24.1",
29
- "babel-eslint": "^7.2.3",
30
- "babel-plugin-syntax-class-properties": "^6.13.0",
31
- "babel-plugin-transform-class-properties": "^6.24.1",
32
- "babel-preset-es2015": "^6.24.1",
33
- "babel-preset-react": "^6.24.1",
34
- "eslint": "^4.3.0",
35
- "eslint-config-sanity": "^2.1.4",
36
- "eslint-plugin-react": "^7.1.0"
48
+ "bugs": {
49
+ "url": "https://github.com/sanity-io/latex-input"
37
50
  },
51
+ "keywords": [
52
+ "sanity",
53
+ "plugin",
54
+ "latex"
55
+ ],
56
+ "homepage": "https://github.com/sanity-io/latex-input#readme",
38
57
  "peerDependencies": {
39
- "react": "15.x"
58
+ "react": "^17.0.0 || ^18.0.0",
59
+ "react-dom": "^17.0.0 || ^18.0.0",
60
+ "sanity": "dev-preview",
61
+ "styled-components": "^5.3.5"
40
62
  },
41
63
  "dependencies": {
42
- "@sanity/form-builder": "^0.114.1",
43
- "detect-browser": "^2.0.0",
44
- "katex": "^0.8.3",
45
- "prop-types": "^15.5.10",
46
- "react-ace": "5.0.1",
47
- "react-katex": "^1.2.0"
64
+ "@sanity/incompatible-plugin": "^1.0.1",
65
+ "@types/katex": "^0.11.0",
66
+ "@types/styled-components": "^5.1.25",
67
+ "katex": "^0.11.1"
68
+ },
69
+ "devDependencies": {
70
+ "@commitlint/cli": "^17.1.2",
71
+ "@commitlint/config-conventional": "^17.1.0",
72
+ "@parcel/packager-ts": "^2.6.0",
73
+ "@parcel/transformer-typescript-types": "^2.6.0",
74
+ "@sanity/plugin-kit": "^1.1.0-ecosystem-preset.5",
75
+ "@sanity/semantic-release-preset": "^2.0.1",
76
+ "@types/jest": "^27.5.0",
77
+ "@types/react": "^17.0.0 || ^18.0.0",
78
+ "@types/react-dom": "^17.0.0 || ^18.0.0",
79
+ "@typescript-eslint/eslint-plugin": "^5.12.0",
80
+ "@typescript-eslint/parser": "^5.12.0",
81
+ "eslint": "^8.7.0",
82
+ "eslint-config-prettier": "^8.3.0",
83
+ "eslint-config-sanity": "^5.1.0",
84
+ "eslint-plugin-prettier": "4.0.0",
85
+ "eslint-plugin-react": "^7.28.0",
86
+ "husky": "^8.0.1",
87
+ "lint-staged": "^13.0.3",
88
+ "parcel": "^2.6.0",
89
+ "prettier": "^2.5.1",
90
+ "react": "^17.0.0 || ^18.0.0",
91
+ "react-dom": "^17.0.0 || ^18.0.0",
92
+ "rimraf": "^3.0.2",
93
+ "sanity": "3.0.0-dev-preview.15",
94
+ "standard-version": "^9.3.2",
95
+ "styled-components": "^5.3.5",
96
+ "typescript": "4.7.4"
48
97
  }
49
98
  }
package/sanity.json CHANGED
@@ -1,24 +1,8 @@
1
1
  {
2
- "paths": {
3
- "source": "./src",
4
- "compiled": "./lib"
5
- },
6
2
  "parts": [
7
3
  {
8
- "name": "part:@sanity/form-builder/input/latex",
9
- "description": "An editor for code in sanity"
10
- },
11
- {
12
- "implements": "part:@sanity/form-builder/input/latex",
13
- "path": "components/index.js"
14
- },
15
- {
16
- "name": "part:@sanity/form-builder/input/latex/schema",
17
- "description": "An editor for code in sanity"
18
- },
19
- {
20
- "implements": "part:@sanity/form-builder/input/latex/schema",
21
- "path": "schema.js"
4
+ "implements": "part:@sanity/base/sanity-root",
5
+ "path": "./v2-incompatible.js"
22
6
  }
23
7
  ]
24
8
  }
@@ -0,0 +1,41 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import KaTeX from 'katex';
3
+ import 'katex/dist/katex.min.css';
4
+
5
+ type SchemaDefinition = {
6
+ body?: string;
7
+ };
8
+
9
+ export type LatexPreviewProps = {
10
+ value?: SchemaDefinition;
11
+ layout?: string;
12
+ };
13
+
14
+ const LatexPreview = (props: LatexPreviewProps) => {
15
+ const latex = (props.value && props.value.body) || '';
16
+ const isInline = props.layout === 'inline';
17
+ const [html, setHtml] = useState<string>('');
18
+ const createHtml = () => {
19
+ setHtml(
20
+ KaTeX.renderToString(latex, {
21
+ displayMode: !isInline,
22
+ throwOnError: false,
23
+ })
24
+ );
25
+ };
26
+
27
+ useMemo(createHtml, [latex, isInline]);
28
+ return (
29
+ <>
30
+ {isInline ? (
31
+ // eslint-disable-next-line react/no-danger
32
+ <span dangerouslySetInnerHTML={{ __html: html }} />
33
+ ) : (
34
+ // eslint-disable-next-line react/no-danger
35
+ <div dangerouslySetInnerHTML={{ __html: html }} />
36
+ )}
37
+ </>
38
+ );
39
+ };
40
+
41
+ export default LatexPreview;
package/src/index.tsx ADDED
@@ -0,0 +1,34 @@
1
+ import LatexPreview, { LatexPreviewProps } from './components/LatexPreview';
2
+ import { createPlugin, defineType, type PreviewValue } from 'sanity';
3
+
4
+ export { LatexPreview, type LatexPreviewProps };
5
+
6
+ export const latexInput = createPlugin({
7
+ name: 'latex-block-plugin',
8
+ schema: {
9
+ types: [
10
+ defineType({
11
+ type: 'object',
12
+ name: 'latex',
13
+ components: {
14
+ preview: LatexPreview,
15
+ },
16
+ fields: [
17
+ {
18
+ title: 'LaTeX content',
19
+ name: 'body',
20
+ type: 'text',
21
+ },
22
+ ],
23
+ preview: {
24
+ select: {
25
+ body: 'body',
26
+ },
27
+ prepare(selection: PreviewValue) {
28
+ return selection;
29
+ },
30
+ },
31
+ }),
32
+ ],
33
+ },
34
+ });
@@ -0,0 +1,11 @@
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: '^2.30.0',
9
+ },
10
+ sanityExchangeUrl,
11
+ })
package/.babelrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "presets": ["es2015", "react"],
3
- "plugins": [
4
- "syntax-class-properties",
5
- "transform-class-properties"
6
- ]
7
- }
package/.eslintrc DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "env": {
3
- "node": true,
4
- "browser": true
5
- },
6
- "parser": "babel-eslint",
7
- "extends": [
8
- "sanity",
9
- "sanity/react"
10
- ]
11
- }