@sanity/code-input 2.30.2-shopify.0 → 3.0.0-studio-v3.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.
- package/README.md +65 -9
- package/lib/cjs/index.js +1348 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/esm/index.js +1340 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/types/index.d.ts +48 -0
- package/lib/types/index.d.ts.map +1 -0
- package/package.json +53 -15
- package/src/CodeInput.tsx +332 -0
- package/src/PreviewCode.tsx +88 -0
- package/src/config.ts +46 -0
- package/src/createHighlightMarkers.ts +24 -0
- package/src/editorSupport.ts +31 -0
- package/src/getMedia.tsx +95 -0
- package/src/groq.ts +630 -0
- package/src/index.ts +12 -0
- package/src/schema.tsx +69 -0
- package/src/types.ts +26 -0
- package/dist/dts/CodeInput.d.ts +0 -22
- package/dist/dts/CodeInput.d.ts.map +0 -1
- package/dist/dts/PreviewCode.d.ts +0 -9
- package/dist/dts/PreviewCode.d.ts.map +0 -1
- package/dist/dts/config.d.ts +0 -16
- package/dist/dts/config.d.ts.map +0 -1
- package/dist/dts/createHighlightMarkers.d.ts +0 -4
- package/dist/dts/createHighlightMarkers.d.ts.map +0 -1
- package/dist/dts/deprecatedSchema.d.ts +0 -12
- package/dist/dts/deprecatedSchema.d.ts.map +0 -1
- package/dist/dts/editorSupport.d.ts +0 -28
- package/dist/dts/editorSupport.d.ts.map +0 -1
- package/dist/dts/getMedia.d.ts +0 -3
- package/dist/dts/getMedia.d.ts.map +0 -1
- package/dist/dts/groq.d.ts +0 -376
- package/dist/dts/groq.d.ts.map +0 -1
- package/dist/dts/schema.d.ts +0 -44
- package/dist/dts/schema.d.ts.map +0 -1
- package/dist/dts/types.d.ts +0 -29
- package/dist/dts/types.d.ts.map +0 -1
- package/lib/@types/css.d.js +0 -1
- package/lib/CodeInput.js +0 -325
- package/lib/PreviewCode.js +0 -79
- package/lib/config.js +0 -103
- package/lib/createHighlightMarkers.js +0 -31
- package/lib/deprecatedSchema.js +0 -26
- package/lib/editorSupport.js +0 -55
- package/lib/getMedia.js +0 -110
- package/lib/groq.js +0 -414
- package/lib/schema.js +0 -69
- package/lib/types.js +0 -5
- package/sanity.json +0 -28
- package/tsconfig.json +0 -26
package/README.md
CHANGED
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
# @sanity/code-input
|
|
2
2
|
|
|
3
|
+
> **NOTE**
|
|
4
|
+
>
|
|
5
|
+
> This is the **Sanity Studio v3 version** of @sanity/code-input.
|
|
6
|
+
>
|
|
7
|
+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/code-input).
|
|
8
|
+
|
|
9
|
+
## What is it?
|
|
10
|
+
|
|
3
11
|
Code input for [Sanity](https://sanity.io/).
|
|
4
12
|
|
|
5
13
|
Currently only a subset of languages and features are exposed, over time we will implement a richer set of options.
|
|
6
14
|
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
Click lines to highlight them.
|
|
18
|
+
|
|
7
19
|
## Installation
|
|
8
20
|
|
|
9
21
|
```
|
|
10
|
-
|
|
22
|
+
npm install --save @sanity/code-input@studio-v3
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
or
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
yarn add @sanity/code-input@studio-v3
|
|
11
29
|
```
|
|
12
30
|
|
|
13
31
|
## Usage
|
|
14
32
|
|
|
15
|
-
|
|
33
|
+
Add it as a plugin in sanity.config.ts (or .js):
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { codeInput } from "@sanity/code-input";
|
|
37
|
+
|
|
38
|
+
export default createConfig({
|
|
39
|
+
// ...
|
|
40
|
+
plugins: [
|
|
41
|
+
codeInput(),
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Now you can use the `code` type in your schema types:
|
|
16
47
|
|
|
17
48
|
```js
|
|
18
49
|
// [...]
|
|
@@ -28,8 +59,6 @@ Use it in your schema types:
|
|
|
28
59
|
}
|
|
29
60
|
```
|
|
30
61
|
|
|
31
|
-
Note that the above only works if you import and use the `all:part:@sanity/base/schema-type` part in your schema.
|
|
32
|
-
|
|
33
62
|
## Options
|
|
34
63
|
|
|
35
64
|
- `language` - Default language for this code field
|
|
@@ -37,16 +66,20 @@ Note that the above only works if you import and use the `all:part:@sanity/base/
|
|
|
37
66
|
- `theme` - Name of the theme to use.
|
|
38
67
|
- Possible values include: `['github', 'monokai', 'terminal', 'tomorrow']`.
|
|
39
68
|
- For the full list and a live playground, refer to the [react-ace page](http://securingsincity.github.io/react-ace/).
|
|
69
|
+
- Default value: 'tomorrow'
|
|
70
|
+
- `darkTheme` - Name of the theme to use when Studio is using dark mode. See `theme` options for supported values.
|
|
71
|
+
- Default value: `'monokai'`
|
|
40
72
|
- `withFilename` - Boolean option to display input field for filename
|
|
41
73
|
|
|
42
74
|
```js
|
|
43
75
|
// ...fields...
|
|
44
76
|
{
|
|
45
77
|
name: 'exampleUsage',
|
|
46
|
-
title: '
|
|
78
|
+
title: 'Code with all options',
|
|
47
79
|
type: 'code',
|
|
48
80
|
options: {
|
|
49
|
-
theme: '
|
|
81
|
+
theme: 'github',
|
|
82
|
+
darkTheme: 'terminal',
|
|
50
83
|
language: 'js',
|
|
51
84
|
languageAlternatives: [
|
|
52
85
|
{title: 'Javascript', value: 'js'},
|
|
@@ -59,6 +92,8 @@ Note that the above only works if you import and use the `all:part:@sanity/base/
|
|
|
59
92
|
}
|
|
60
93
|
```
|
|
61
94
|
|
|
95
|
+

|
|
96
|
+
|
|
62
97
|
## Add support for more languages
|
|
63
98
|
|
|
64
99
|
Only a subset of languages are supported by default (see full list [here](https://github.com/sanity-io/sanity/blob/current/packages/@sanity/code-input/src/config.ts#L4)). You can add support for other languages by importing the ace mode yourself, and specifying `mode` for the `languageAlternatives` schema config.
|
|
@@ -93,7 +128,8 @@ import 'ace-builds/src-noconflict/mode-rust'
|
|
|
93
128
|
_type: 'code',
|
|
94
129
|
language: 'js',
|
|
95
130
|
highlightedLines: [1, 2],
|
|
96
|
-
code: 'const foo = "bar"\nconsole.log(foo.toUpperCase())\n// BAR'
|
|
131
|
+
code: 'const foo = "bar"\nconsole.log(foo.toUpperCase())\n// BAR',
|
|
132
|
+
filename: 'available when enabled'
|
|
97
133
|
}
|
|
98
134
|
```
|
|
99
135
|
|
|
@@ -122,8 +158,6 @@ export function Code(props) {
|
|
|
122
158
|
/>
|
|
123
159
|
)
|
|
124
160
|
}
|
|
125
|
-
|
|
126
|
-
export default Code
|
|
127
161
|
```
|
|
128
162
|
|
|
129
163
|
Other syntax highlighters include:
|
|
@@ -136,3 +170,25 @@ Other syntax highlighters include:
|
|
|
136
170
|
## License
|
|
137
171
|
|
|
138
172
|
MIT-licensed. See LICENSE.
|
|
173
|
+
|
|
174
|
+
## Develop & test
|
|
175
|
+
|
|
176
|
+
Make sure to run `npm run build` once, then run
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
npm run link-watch
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
In another shell, `cd` to your test studio and run:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
npx yalc add @sanity/code-input --link && yarn install
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Now, changes in this repo will be automatically built and pushed to the studio,
|
|
189
|
+
triggering hotreload. Yalc avoids issues with react-hooks that are typical when using yarn/npm link.
|
|
190
|
+
|
|
191
|
+
### About build & watch
|
|
192
|
+
|
|
193
|
+
This plugin uses [@sanity/plugin-sdk](https://github.com/sanity-io/plugin-sdk)
|
|
194
|
+
with default configuration for build & watch scripts.
|