sanity-plugin-latex-input 1.0.1 → 2.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) 2020 Sanity.io
3
+ Copyright (c) 2022 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,11 +1,41 @@
1
1
  # LaTeX input for Sanity
2
2
 
3
- https://sanity.io
3
+ > This is a **Sanity Studio v3** plugin.
4
+ > For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/latex-input/tree/studio-v2).
4
5
 
5
- ## Usage
6
+ ## What is it?
7
+
8
+ sanity-plugin-latex-input adds support for `latex` schema type, so it can be used in Portable Text Editor (PTE) in Sanity Studio.
9
+
10
+ ![latex-input preview](assets/latex-input.png)
6
11
 
12
+ ## Installation
13
+
14
+ ```sh
15
+ npm install --save sanity-plugin-latex-input@studio-v3
7
16
  ```
8
- sanity install sanity-plugin-latex-input
17
+
18
+ or
19
+
20
+ ```sh
21
+ yarn add sanity-plugin-latex-input@studio-v3
22
+ ```
23
+
24
+ ## Usage
25
+
26
+
27
+ Import and add the plugin to your studio config in sanity.config.ts (or .js):
28
+
29
+ ```ts
30
+ import { latexBlock } from "sanity-plugin-latex-input";
31
+
32
+ export default defineConfig({
33
+ /* ... */
34
+
35
+ plugins: [
36
+ latexInput()
37
+ ]
38
+ })
9
39
  ```
10
40
 
11
41
  You may now use the type name `latex` in your schema, such as in portable text.
@@ -39,3 +69,22 @@ export default {
39
69
  ```
40
70
 
41
71
  The Portable Text editor will render a preview of the contents with KaTeX.
72
+
73
+ ## License
74
+
75
+ 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,2 @@
1
+ function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}import{defineType as n,definePlugin as o}from"sanity";import{jsx as i,Fragment as c}from"react/jsx-runtime";import{useState as p,useMemo as a}from"react";import l from"katex";import"katex/dist/katex.min.css";const s=e=>{const t=e.value&&e.value.body||"",r="inline"===e.layout,[n,o]=p("");return a((()=>{o(l.renderToString(t,{displayMode:!r,throwOnError:!1}))}),[t,r]),i(c,{children:i(r?"span":"div",{dangerouslySetInnerHTML:{__html:n}})})},b=n(t(t({type:"object",name:"latex"},{components:{preview:s}}),{},{fields:[{title:"LaTeX content",name:"body",type:"text"}],preview:{select:{body:"body"},prepare:e=>e}})),u=o({name:"latex-block-plugin",schema:{types:[b]}});export{s as LatexPreview,u as latexInput,b as latexSchema};
2
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
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\ninterface SchemaDefinition {\n body?: string;\n}\n\nexport interface LatexPreviewProps {\n value?: SchemaDefinition;\n layout?: string;\n}\n\nexport const 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","import { defineType, ObjectDefinition, type PreviewValue } 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 } } as {}), //TODO revert this change when rc.1 is released\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) {\n return selection as unknown as PreviewValue;\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":["LatexPreview","props","latex","value","body","isInline","layout","html","setHtml","useState","useMemo","KaTeX","renderToString","displayMode","throwOnError","jsx","Fragment","children","dangerouslySetInnerHTML","__html","latexSchema","defineType","_objectSpread","type","name","components","preview","fields","title","select","prepare","selection","latexInput","definePlugin","schema","types"],"mappings":"u4BAaa,MAAAA,EAAgBC,IAC3B,MAAMC,EAASD,EAAME,OAASF,EAAME,MAAMC,MAAS,GAC7CC,EAA4B,WAAjBJ,EAAMK,QAChBC,EAAMC,GAAWC,EAAiB,IAYvC,OAFFC,GATmB,KACjBF,EACEG,EAAMC,eAAeV,EAAO,CAC1BW,aAAcR,EACdS,cAAc,IAElB,GAGkB,CAACZ,EAAOG,IAE1BU,EAAAC,EAAA,CACGC,SAEEF,IAAA,OAGA,MAHA,CAAKG,wBAAyB,CAAEC,OAAQZ,MAK7C,EChBSa,EAAcC,EAAWC,EAAAA,EAAA,CACpCC,KAAM,SACNC,KAAM,SACF,CAAEC,WAAY,CAAEC,QAAS1B,KAAe,CAAA,EAAA,CAC5C2B,OAAQ,CACN,CACEC,MAAO,gBACPJ,KAAM,OACND,KAAM,SAGVG,QAAS,CACPG,OAAQ,CACNzB,KAAM,QAER0B,QAAQC,GACCA,MCjCAC,EAAaC,EAAa,CACrCT,KAAM,qBACNU,OAAQ,CACNC,MAAO,CAACf"}
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("sanity"),o=require("react/jsx-runtime"),i=require("react"),a=require("katex");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("katex/dist/katex.min.css");var u=c(a);const s=e=>{const t=e.value&&e.value.body||"",r="inline"===e.layout,[n,a]=i.useState("");return i.useMemo((()=>{a(u.default.renderToString(t,{displayMode:!r,throwOnError:!1}))}),[t,r]),o.jsx(o.Fragment,{children:r?o.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):o.jsx("div",{dangerouslySetInnerHTML:{__html:n}})})},l=n.defineType(t(t({type:"object",name:"latex"},{components:{preview:s}}),{},{fields:[{title:"LaTeX content",name:"body",type:"text"}],preview:{select:{body:"body"},prepare:e=>e}})),p=n.definePlugin({name:"latex-block-plugin",schema:{types:[l]}});exports.LatexPreview=s,exports.latexInput=p,exports.latexSchema=l;
2
+ //# 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 React, { useMemo, useState } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css';\n\ninterface SchemaDefinition {\n body?: string;\n}\n\nexport interface LatexPreviewProps {\n value?: SchemaDefinition;\n layout?: string;\n}\n\nexport const 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","import { defineType, ObjectDefinition, type PreviewValue } 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 } } as {}), //TODO revert this change when rc.1 is released\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) {\n return selection as unknown as PreviewValue;\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":["LatexPreview","props","latex","value","body","isInline","layout","html","setHtml","useState","useMemo","KaTeX","renderToString","displayMode","throwOnError","jsx","Fragment","children","dangerouslySetInnerHTML","__html","latexSchema","defineType","_objectSpread","type","name","components","preview","fields","title","select","prepare","selection","latexInput","definePlugin","schema","types"],"mappings":"+8BAaa,MAAAA,EAAgBC,IAC3B,MAAMC,EAASD,EAAME,OAASF,EAAME,MAAMC,MAAS,GAC7CC,EAA4B,WAAjBJ,EAAMK,QAChBC,EAAMC,GAAWC,WAAiB,IAYvC,OAFFC,EAAAA,SATmB,KACjBF,EACEG,EAAA,QAAMC,eAAeV,EAAO,CAC1BW,aAAcR,EACdS,cAAc,IAElB,GAGkB,CAACZ,EAAOG,IAE1BU,EAAAA,IAAAC,EAAAA,SAAA,CACGC,WAEEF,EAAAA,IAAA,OAAA,CAAKG,wBAAyB,CAAEC,OAAQZ,KAGxCQ,EAAAA,IAAA,MAAA,CAAIG,wBAAyB,CAAEC,OAAQZ,MAE5C,EChBSa,EAAcC,EAAAA,WAAWC,EAAAA,EAAA,CACpCC,KAAM,SACNC,KAAM,SACF,CAAEC,WAAY,CAAEC,QAAS1B,KAAe,CAAA,EAAA,CAC5C2B,OAAQ,CACN,CACEC,MAAO,gBACPJ,KAAM,OACND,KAAM,SAGVG,QAAS,CACPG,OAAQ,CACNzB,KAAM,QAER0B,QAAQC,GACCA,MCjCAC,EAAaC,EAAAA,aAAa,CACrCT,KAAM,qBACNU,OAAQ,CACNC,MAAO,CAACf"}
@@ -0,0 +1,50 @@
1
+ /// <reference types="react" />
2
+
3
+ import { ObjectDefinition } from 'sanity';
4
+ import { Plugin as Plugin_2 } from 'sanity';
5
+ import { PreviewConfig } from 'sanity';
6
+
7
+ /**
8
+ * @public
9
+ */
10
+ export declare interface LatexDefinition
11
+ extends Omit<ObjectDefinition, 'type' | 'fields'> {
12
+ type: typeof latexTypeName;
13
+ }
14
+
15
+ export declare const latexInput: Plugin_2<void>;
16
+
17
+ export declare const LatexPreview: (props: LatexPreviewProps) => JSX.Element;
18
+
19
+ export declare interface LatexPreviewProps {
20
+ value?: SchemaDefinition;
21
+ layout?: string;
22
+ }
23
+
24
+ export declare const latexSchema: {
25
+ type: 'object';
26
+ name: 'latex';
27
+ } & Omit<ObjectDefinition, 'preview'> & {
28
+ preview?:
29
+ | PreviewConfig<
30
+ {
31
+ body: string;
32
+ },
33
+ Record<'body', any>
34
+ >
35
+ | undefined;
36
+ };
37
+
38
+ declare const latexTypeName: 'latex';
39
+
40
+ declare interface SchemaDefinition {
41
+ body?: string;
42
+ }
43
+
44
+ export {};
45
+
46
+ declare module '@sanity/types' {
47
+ interface IntrinsicDefinitions {
48
+ latex: LatexDefinition;
49
+ }
50
+ }
package/package.json CHANGED
@@ -1,30 +1,54 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "name": "sanity-plugin-latex-input",
3
+ "version": "2.0.0",
4
+ "description": "Latex input for Portable Text Editor in Sanity Studio V3.",
5
+ "keywords": [
6
+ "sanity",
7
+ "plugin",
8
+ "latex"
9
+ ],
10
+ "homepage": "https://github.com/sanity-io/latex-input#readme",
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"
17
+ },
3
18
  "license": "MIT",
4
- "main": "dist/index.js",
5
- "typings": "dist/index.d.ts",
19
+ "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"
29
+ },
30
+ "main": "./lib/index.js",
31
+ "module": "./lib/index.esm.js",
32
+ "source": "./src/index.ts",
33
+ "types": "./lib/src/index.d.ts",
6
34
  "files": [
7
- "dist",
8
35
  "src",
36
+ "lib",
37
+ "v2-incompatible.js",
9
38
  "sanity.json"
10
39
  ],
11
- "engines": {
12
- "node": ">=10"
13
- },
14
40
  "scripts": {
15
- "start": "tsdx watch",
16
- "build": "tsdx build",
17
- "test": "tsdx test --passWithNoTests",
18
- "lint": "tsdx lint",
19
- "prepare": "tsdx build"
20
- },
21
- "peerDependencies": {
22
- "react": ">=16"
23
- },
24
- "husky": {
25
- "hooks": {
26
- "pre-commit": "tsdx lint"
27
- }
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"
28
52
  },
29
53
  "prettier": {
30
54
  "printWidth": 80,
@@ -32,30 +56,48 @@
32
56
  "singleQuote": true,
33
57
  "trailingComma": "es5"
34
58
  },
35
- "name": "sanity-plugin-latex-input",
36
- "author": "Sanity.io <hello@sanity.io>",
37
- "bugs": {
38
- "url": "https://github.com/sanity-io/latex-input"
39
- },
40
- "keywords": [
41
- "sanity",
42
- "plugin",
43
- "latex"
44
- ],
45
- "homepage": "https://github.com/sanity-io/latex-input#readme",
46
- "module": "dist/sanity-plugin-latex-input.esm.js",
47
- "devDependencies": {
48
- "@types/react": "^16.9.34",
49
- "@types/react-dom": "^16.9.7",
50
- "husky": "^4.2.5",
51
- "react": "^16.13.1",
52
- "react-dom": "^16.13.1",
53
- "tsdx": "^0.13.2",
54
- "tslib": "^1.11.2",
55
- "typescript": "^3.8.3"
56
- },
57
59
  "dependencies": {
60
+ "@sanity/incompatible-plugin": "^1.0.4",
58
61
  "@types/katex": "^0.11.0",
62
+ "@types/styled-components": "^5.1.25",
59
63
  "katex": "^0.11.1"
64
+ },
65
+ "devDependencies": {
66
+ "@commitlint/cli": "^17.2.0",
67
+ "@commitlint/config-conventional": "^17.2.0",
68
+ "@sanity/pkg-utils": "^1.17.2",
69
+ "@sanity/plugin-kit": "^2.1.6",
70
+ "@sanity/semantic-release-preset": "^2.0.2",
71
+ "@types/jest": "^27.5.0",
72
+ "@types/react": "^18",
73
+ "@types/react-dom": "^18",
74
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
75
+ "@typescript-eslint/parser": "^5.42.0",
76
+ "eslint": "^8.26.0",
77
+ "eslint-config-prettier": "^8.5.0",
78
+ "eslint-config-sanity": "^6.0.0",
79
+ "eslint-plugin-prettier": "^4.2.1",
80
+ "eslint-plugin-react": "^7.31.10",
81
+ "eslint-plugin-react-hooks": "^4.6.0",
82
+ "husky": "^8.0.1",
83
+ "lint-staged": "^13.0.3",
84
+ "prettier": "^2.7.1",
85
+ "prettier-plugin-packagejson": "^2.3.0",
86
+ "react": "^18",
87
+ "react-dom": "^18",
88
+ "rimraf": "^3.0.2",
89
+ "sanity": "3.0.0-rc.2",
90
+ "standard-version": "^9.3.2",
91
+ "styled-components": "^5.3.5",
92
+ "typescript": "^4.8.4"
93
+ },
94
+ "peerDependencies": {
95
+ "react": "^18",
96
+ "react-dom": "^18",
97
+ "sanity": "dev-preview || 3.0.0-rc.2",
98
+ "styled-components": "^5.3.5"
99
+ },
100
+ "engines": {
101
+ "node": ">=14"
60
102
  }
61
103
  }
package/sanity.json CHANGED
@@ -1,12 +1,8 @@
1
1
  {
2
- "paths": {
3
- "source": "./src",
4
- "compiled": "./dist"
5
- },
6
2
  "parts": [
7
3
  {
8
- "implements": "part:@sanity/base/schema-type",
9
- "path": "index.js"
4
+ "implements": "part:@sanity/base/sanity-root",
5
+ "path": "./v2-incompatible.js"
10
6
  }
11
7
  ]
12
8
  }
@@ -1,17 +1,17 @@
1
- import React, { useState, useMemo } from 'react';
1
+ import React, { useMemo, useState } from 'react';
2
2
  import KaTeX from 'katex';
3
- import 'katex/dist/katex.min.css?raw';
3
+ import 'katex/dist/katex.min.css';
4
4
 
5
- type SchemaDefinition = {
5
+ interface SchemaDefinition {
6
6
  body?: string;
7
- };
7
+ }
8
8
 
9
- type PreviewProps = {
9
+ export interface LatexPreviewProps {
10
10
  value?: SchemaDefinition;
11
11
  layout?: string;
12
- };
12
+ }
13
13
 
14
- const LatexPreview = (props: PreviewProps) => {
14
+ export const LatexPreview = (props: LatexPreviewProps) => {
15
15
  const latex = (props.value && props.value.body) || '';
16
16
  const isInline = props.layout === 'inline';
17
17
  const [html, setHtml] = useState<string>('');
@@ -25,10 +25,15 @@ const LatexPreview = (props: PreviewProps) => {
25
25
  };
26
26
 
27
27
  useMemo(createHtml, [latex, isInline]);
28
- if (isInline) {
29
- return <span dangerouslySetInnerHTML={{ __html: html }} />;
30
- }
31
- return <div dangerouslySetInnerHTML={{ __html: html }} />;
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
+ );
32
39
  };
33
-
34
- export default LatexPreview;
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
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 ADDED
@@ -0,0 +1,9 @@
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 ADDED
@@ -0,0 +1,40 @@
1
+ import { defineType, ObjectDefinition, type PreviewValue } 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 } } as {}), //TODO revert this change when rc.1 is released
25
+ fields: [
26
+ {
27
+ title: 'LaTeX content',
28
+ name: 'body',
29
+ type: 'text',
30
+ },
31
+ ],
32
+ preview: {
33
+ select: {
34
+ body: 'body',
35
+ },
36
+ prepare(selection) {
37
+ return selection as unknown as PreviewValue;
38
+ },
39
+ },
40
+ });
@@ -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
+ })
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import 'katex/dist/katex.min.css?raw';
3
- declare type SchemaDefinition = {
4
- body?: string;
5
- };
6
- declare type PreviewProps = {
7
- value?: SchemaDefinition;
8
- layout?: string;
9
- };
10
- declare const LatexPreview: (props: PreviewProps) => JSX.Element;
11
- export default LatexPreview;
package/dist/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- /// <reference types="react" />
2
- declare const _default: {
3
- name: string;
4
- type: string;
5
- fields: {
6
- title: string;
7
- name: string;
8
- type: string;
9
- }[];
10
- preview: {
11
- select: {
12
- body: string;
13
- };
14
- prepare(selection: object): object;
15
- component: (props: {
16
- value?: {
17
- body?: string | undefined;
18
- } | undefined;
19
- layout?: string | undefined;
20
- }) => JSX.Element;
21
- };
22
- };
23
- export default _default;
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./sanity-plugin-latex-input.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./sanity-plugin-latex-input.cjs.development.js')
8
- }
@@ -1,64 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var React = require('react');
8
- var React__default = _interopDefault(React);
9
- var KaTeX = _interopDefault(require('katex'));
10
- require('katex/dist/katex.min.css?raw');
11
-
12
- var LatexPreview = function LatexPreview(props) {
13
- var latex = props.value && props.value.body || '';
14
- var isInline = props.layout === 'inline';
15
-
16
- var _useState = React.useState(''),
17
- html = _useState[0],
18
- setHtml = _useState[1];
19
-
20
- var createHtml = function createHtml() {
21
- setHtml(KaTeX.renderToString(latex, {
22
- displayMode: !isInline,
23
- throwOnError: false
24
- }));
25
- };
26
-
27
- React.useMemo(createHtml, [latex, isInline]);
28
-
29
- if (isInline) {
30
- return React__default.createElement("span", {
31
- dangerouslySetInnerHTML: {
32
- __html: html
33
- }
34
- });
35
- }
36
-
37
- return React__default.createElement("div", {
38
- dangerouslySetInnerHTML: {
39
- __html: html
40
- }
41
- });
42
- };
43
-
44
- var index = {
45
- name: 'latex',
46
- type: 'object',
47
- fields: [{
48
- title: 'LaTeX content',
49
- name: 'body',
50
- type: 'text'
51
- }],
52
- preview: {
53
- select: {
54
- body: 'body'
55
- },
56
- prepare: function prepare(selection) {
57
- return selection;
58
- },
59
- component: LatexPreview
60
- }
61
- };
62
-
63
- exports.default = index;
64
- //# sourceMappingURL=sanity-plugin-latex-input.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanity-plugin-latex-input.cjs.development.js","sources":["../src/components/LatexPreview.tsx","../src/index.tsx"],"sourcesContent":["import React, { useState, useMemo } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css?raw';\n\ntype SchemaDefinition = {\n body?: string;\n};\n\ntype PreviewProps = {\n value?: SchemaDefinition;\n layout?: string;\n};\n\nconst LatexPreview = (props: PreviewProps) => {\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 if (isInline) {\n return <span dangerouslySetInnerHTML={{ __html: html }} />;\n }\n return <div dangerouslySetInnerHTML={{ __html: html }} />;\n};\n\nexport default LatexPreview;\n","import LatexPreview from './components/LatexPreview';\n\nexport default {\n name: 'latex',\n type: 'object',\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: object) {\n return selection;\n },\n component: LatexPreview,\n },\n};\n"],"names":["LatexPreview","props","latex","value","body","isInline","layout","useState","html","setHtml","createHtml","KaTeX","renderToString","displayMode","throwOnError","useMemo","React","dangerouslySetInnerHTML","__html","name","type","fields","title","preview","select","prepare","selection","component"],"mappings":";;;;;;;;;;;AAaA,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;AACnB,MAAMC,KAAK,GAAID,KAAK,CAACE,KAAN,IAAeF,KAAK,CAACE,KAAN,CAAYC,IAA5B,IAAqC,EAAnD;AACA,MAAMC,QAAQ,GAAGJ,KAAK,CAACK,MAAN,KAAiB,QAAlC;;kBACwBC,cAAQ,CAAS,EAAT;MAAzBC;MAAMC;;AACb,MAAMC,UAAU,GAAG,SAAbA,UAAa;AACjBD,IAAAA,OAAO,CACLE,KAAK,CAACC,cAAN,CAAqBV,KAArB,EAA4B;AAC1BW,MAAAA,WAAW,EAAE,CAACR,QADY;AAE1BS,MAAAA,YAAY,EAAE;AAFY,KAA5B,CADK,CAAP;AAMD,GAPD;;AASAC,EAAAA,aAAO,CAACL,UAAD,EAAa,CAACR,KAAD,EAAQG,QAAR,CAAb,CAAP;;AACA,MAAIA,QAAJ,EAAc;AACZ,WAAOW,4BAAA,OAAA;AAAMC,MAAAA,uBAAuB,EAAE;AAAEC,QAAAA,MAAM,EAAEV;AAAV;KAA/B,CAAP;AACD;;AACD,SAAOQ,4BAAA,MAAA;AAAKC,IAAAA,uBAAuB,EAAE;AAAEC,MAAAA,MAAM,EAAEV;AAAV;GAA9B,CAAP;AACD,CAlBD;;ACXA,YAAe;AACbW,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,IAAI,EAAE,QAFO;AAGbC,EAAAA,MAAM,EAAE,CACN;AACEC,IAAAA,KAAK,EAAE,eADT;AAEEH,IAAAA,IAAI,EAAE,MAFR;AAGEC,IAAAA,IAAI,EAAE;AAHR,GADM,CAHK;AAUbG,EAAAA,OAAO,EAAE;AACPC,IAAAA,MAAM,EAAE;AACNpB,MAAAA,IAAI,EAAE;AADA,KADD;AAIPqB,IAAAA,OAJO,mBAICC,SAJD;AAKL,aAAOA,SAAP;AACD,KANM;AAOPC,IAAAA,SAAS,EAAE3B;AAPJ;AAVI,CAAf;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),r=e(t),n=e(require("katex"));require("katex/dist/katex.min.css?raw"),exports.default={name:"latex",type:"object",fields:[{title:"LaTeX content",name:"body",type:"text"}],preview:{select:{body:"body"},prepare:function(e){return e},component:function(e){var o=e.value&&e.value.body||"",a="inline"===e.layout,u=t.useState(""),i=u[0],l=u[1];return t.useMemo((function(){l(n.renderToString(o,{displayMode:!a,throwOnError:!1}))}),[o,a]),r.createElement(a?"span":"div",{dangerouslySetInnerHTML:{__html:i}})}}};
2
- //# sourceMappingURL=sanity-plugin-latex-input.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanity-plugin-latex-input.cjs.production.min.js","sources":["../src/index.tsx","../src/components/LatexPreview.tsx"],"sourcesContent":["import LatexPreview from './components/LatexPreview';\n\nexport default {\n name: 'latex',\n type: 'object',\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: object) {\n return selection;\n },\n component: LatexPreview,\n },\n};\n","import React, { useState, useMemo } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css?raw';\n\ntype SchemaDefinition = {\n body?: string;\n};\n\ntype PreviewProps = {\n value?: SchemaDefinition;\n layout?: string;\n};\n\nconst LatexPreview = (props: PreviewProps) => {\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 if (isInline) {\n return <span dangerouslySetInnerHTML={{ __html: html }} />;\n }\n return <div dangerouslySetInnerHTML={{ __html: html }} />;\n};\n\nexport default LatexPreview;\n"],"names":["name","type","fields","title","preview","select","body","prepare","selection","component","props","latex","value","isInline","layout","useState","html","setHtml","useMemo","KaTeX","renderToString","displayMode","throwOnError","React","dangerouslySetInnerHTML","__html"],"mappings":"sPAEe,CACbA,KAAM,QACNC,KAAM,SACNC,OAAQ,CACN,CACEC,MAAO,gBACPH,KAAM,OACNC,KAAM,SAGVG,QAAS,CACPC,OAAQ,CACNC,KAAM,QAERC,iBAAQC,UACCA,GAETC,UCNiB,SAACC,OACdC,EAASD,EAAME,OAASF,EAAME,MAAMN,MAAS,GAC7CO,EAA4B,WAAjBH,EAAMI,SACCC,WAAiB,IAAlCC,OAAMC,cAUbC,WATmB,WACjBD,EACEE,EAAMC,eAAeT,EAAO,CAC1BU,aAAcR,EACdS,cAAc,OAKA,CAACX,EAAOE,IAEnBU,gBADLV,gBACWW,wBAAyB,CAAEC,OAAQT"}
@@ -1,57 +0,0 @@
1
- import React, { useState, useMemo } from 'react';
2
- import KaTeX from 'katex';
3
- import 'katex/dist/katex.min.css?raw';
4
-
5
- var LatexPreview = function LatexPreview(props) {
6
- var latex = props.value && props.value.body || '';
7
- var isInline = props.layout === 'inline';
8
-
9
- var _useState = useState(''),
10
- html = _useState[0],
11
- setHtml = _useState[1];
12
-
13
- var createHtml = function createHtml() {
14
- setHtml(KaTeX.renderToString(latex, {
15
- displayMode: !isInline,
16
- throwOnError: false
17
- }));
18
- };
19
-
20
- useMemo(createHtml, [latex, isInline]);
21
-
22
- if (isInline) {
23
- return React.createElement("span", {
24
- dangerouslySetInnerHTML: {
25
- __html: html
26
- }
27
- });
28
- }
29
-
30
- return React.createElement("div", {
31
- dangerouslySetInnerHTML: {
32
- __html: html
33
- }
34
- });
35
- };
36
-
37
- var index = {
38
- name: 'latex',
39
- type: 'object',
40
- fields: [{
41
- title: 'LaTeX content',
42
- name: 'body',
43
- type: 'text'
44
- }],
45
- preview: {
46
- select: {
47
- body: 'body'
48
- },
49
- prepare: function prepare(selection) {
50
- return selection;
51
- },
52
- component: LatexPreview
53
- }
54
- };
55
-
56
- export default index;
57
- //# sourceMappingURL=sanity-plugin-latex-input.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanity-plugin-latex-input.esm.js","sources":["../src/components/LatexPreview.tsx","../src/index.tsx"],"sourcesContent":["import React, { useState, useMemo } from 'react';\nimport KaTeX from 'katex';\nimport 'katex/dist/katex.min.css?raw';\n\ntype SchemaDefinition = {\n body?: string;\n};\n\ntype PreviewProps = {\n value?: SchemaDefinition;\n layout?: string;\n};\n\nconst LatexPreview = (props: PreviewProps) => {\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 if (isInline) {\n return <span dangerouslySetInnerHTML={{ __html: html }} />;\n }\n return <div dangerouslySetInnerHTML={{ __html: html }} />;\n};\n\nexport default LatexPreview;\n","import LatexPreview from './components/LatexPreview';\n\nexport default {\n name: 'latex',\n type: 'object',\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: object) {\n return selection;\n },\n component: LatexPreview,\n },\n};\n"],"names":["LatexPreview","props","latex","value","body","isInline","layout","useState","html","setHtml","createHtml","KaTeX","renderToString","displayMode","throwOnError","useMemo","React","dangerouslySetInnerHTML","__html","name","type","fields","title","preview","select","prepare","selection","component"],"mappings":";;;;AAaA,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;AACnB,MAAMC,KAAK,GAAID,KAAK,CAACE,KAAN,IAAeF,KAAK,CAACE,KAAN,CAAYC,IAA5B,IAAqC,EAAnD;AACA,MAAMC,QAAQ,GAAGJ,KAAK,CAACK,MAAN,KAAiB,QAAlC;;kBACwBC,QAAQ,CAAS,EAAT;MAAzBC;MAAMC;;AACb,MAAMC,UAAU,GAAG,SAAbA,UAAa;AACjBD,IAAAA,OAAO,CACLE,KAAK,CAACC,cAAN,CAAqBV,KAArB,EAA4B;AAC1BW,MAAAA,WAAW,EAAE,CAACR,QADY;AAE1BS,MAAAA,YAAY,EAAE;AAFY,KAA5B,CADK,CAAP;AAMD,GAPD;;AASAC,EAAAA,OAAO,CAACL,UAAD,EAAa,CAACR,KAAD,EAAQG,QAAR,CAAb,CAAP;;AACA,MAAIA,QAAJ,EAAc;AACZ,WAAOW,mBAAA,OAAA;AAAMC,MAAAA,uBAAuB,EAAE;AAAEC,QAAAA,MAAM,EAAEV;AAAV;KAA/B,CAAP;AACD;;AACD,SAAOQ,mBAAA,MAAA;AAAKC,IAAAA,uBAAuB,EAAE;AAAEC,MAAAA,MAAM,EAAEV;AAAV;GAA9B,CAAP;AACD,CAlBD;;ACXA,YAAe;AACbW,EAAAA,IAAI,EAAE,OADO;AAEbC,EAAAA,IAAI,EAAE,QAFO;AAGbC,EAAAA,MAAM,EAAE,CACN;AACEC,IAAAA,KAAK,EAAE,eADT;AAEEH,IAAAA,IAAI,EAAE,MAFR;AAGEC,IAAAA,IAAI,EAAE;AAHR,GADM,CAHK;AAUbG,EAAAA,OAAO,EAAE;AACPC,IAAAA,MAAM,EAAE;AACNpB,MAAAA,IAAI,EAAE;AADA,KADD;AAIPqB,IAAAA,OAJO,mBAICC,SAJD;AAKL,aAAOA,SAAP;AACD,KANM;AAOPC,IAAAA,SAAS,EAAE3B;AAPJ;AAVI,CAAf;;;;"}
package/src/.DS_Store DELETED
Binary file
Binary file
Binary file
package/src/index.tsx DELETED
@@ -1,22 +0,0 @@
1
- import LatexPreview from './components/LatexPreview';
2
-
3
- export default {
4
- name: 'latex',
5
- type: 'object',
6
- fields: [
7
- {
8
- title: 'LaTeX content',
9
- name: 'body',
10
- type: 'text',
11
- },
12
- ],
13
- preview: {
14
- select: {
15
- body: 'body',
16
- },
17
- prepare(selection: object) {
18
- return selection;
19
- },
20
- component: LatexPreview,
21
- },
22
- };