@tinacms/app 2.2.2 → 2.2.4

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.
@@ -4,23 +4,23 @@
4
4
 
5
5
  */
6
6
 
7
- import React from 'react'
8
- import MonacoEditor, { useMonaco, loader } from '@monaco-editor/react'
7
+ import React from 'react';
8
+ import MonacoEditor, { useMonaco, loader } from '@monaco-editor/react';
9
9
  /**
10
10
  * MDX is built directly to the app because of how we load dependencies.
11
11
  * Since we drop the package.json in to the end users folder, we can't
12
12
  * easily install the current version of the mdx package in all scenarios
13
13
  * (when we're working in the monorepo, or working with a tagged npm version)
14
14
  */
15
- import { parseMDX, stringifyMDX } from '@tinacms/mdx'
16
- import { useDebounce } from './use-debounce'
17
- import type * as monaco from 'monaco-editor'
15
+ import { parseMDX, stringifyMDX } from '@tinacms/mdx';
16
+ import { useDebounce } from './use-debounce';
17
+ import type * as monaco from 'monaco-editor';
18
18
  import {
19
19
  buildError,
20
20
  ErrorMessage,
21
21
  InvalidMarkdownElement,
22
- } from './error-message'
23
- import { RichTextType } from 'tinacms'
22
+ } from './error-message';
23
+ import { RichTextType } from 'tinacms';
24
24
 
25
25
  export const uuid = () => {
26
26
  // @ts-ignore
@@ -29,15 +29,15 @@ export const uuid = () => {
29
29
  c ^
30
30
  (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
31
31
  ).toString(16)
32
- )
33
- }
32
+ );
33
+ };
34
34
 
35
- type Monaco = typeof monaco
35
+ type Monaco = typeof monaco;
36
36
 
37
37
  // 0.33.0 has a bug https://github.com/microsoft/monaco-editor/issues/2947
38
38
  loader.config({
39
39
  paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.31.1/min/vs' },
40
- })
40
+ });
41
41
 
42
42
  /**
43
43
  * Since monaco lazy-loads we may have a delay from when the block is inserted
@@ -45,81 +45,81 @@ loader.config({
45
45
  *
46
46
  * Will try for 3 seconds before moving on
47
47
  */
48
- let retryCount = 0
48
+ let retryCount = 0;
49
49
  const retryFocus = (ref) => {
50
50
  if (ref.current) {
51
- ref.current.focus()
51
+ ref.current.focus();
52
52
  } else {
53
53
  if (retryCount < 30) {
54
54
  setTimeout(() => {
55
- retryCount = retryCount + 1
56
- retryFocus(ref)
57
- }, 100)
55
+ retryCount = retryCount + 1;
56
+ retryFocus(ref);
57
+ }, 100);
58
58
  }
59
59
  }
60
- }
60
+ };
61
61
 
62
62
  export const RawEditor = (props: RichTextType) => {
63
- const monaco = useMonaco() as Monaco
63
+ const monaco = useMonaco() as Monaco;
64
64
  const monacoEditorRef =
65
- React.useRef<monaco.editor.IStandaloneCodeEditor>(null)
66
- const [height, setHeight] = React.useState(100)
67
- const id = React.useMemo(() => uuid(), [])
68
- const field = props.field
65
+ React.useRef<monaco.editor.IStandaloneCodeEditor>(null);
66
+ const [height, setHeight] = React.useState(100);
67
+ const id = React.useMemo(() => uuid(), []);
68
+ const field = props.field;
69
69
  const inputValue = React.useMemo(() => {
70
70
  // @ts-ignore no access to the rich-text type from this package
71
- const res = stringifyMDX(props.input.value, field, (value) => value)
72
- return typeof props.input.value === 'string' ? props.input.value : res
73
- }, [])
74
- const [value, setValue] = React.useState(inputValue)
75
- const [error, setError] = React.useState<InvalidMarkdownElement>(null)
71
+ const res = stringifyMDX(props.input.value, field, (value) => value);
72
+ return typeof props.input.value === 'string' ? props.input.value : res;
73
+ }, []);
74
+ const [value, setValue] = React.useState(inputValue);
75
+ const [error, setError] = React.useState<InvalidMarkdownElement>(null);
76
76
 
77
- const debouncedValue = useDebounce(value, 500)
77
+ const debouncedValue = useDebounce(value, 500);
78
78
 
79
79
  React.useEffect(() => {
80
80
  // @ts-ignore no access to the rich-text type from this package
81
- const parsedValue = parseMDX(value, field, (value) => value)
81
+ const parsedValue = parseMDX(value, field, (value) => value);
82
82
  if (
83
83
  parsedValue.children[0] &&
84
84
  parsedValue.children[0].type === 'invalid_markdown'
85
85
  ) {
86
- const invalidMarkdown = parsedValue.children[0]
87
- setError(invalidMarkdown)
86
+ const invalidMarkdown = parsedValue.children[0];
87
+ setError(invalidMarkdown);
88
88
  } else {
89
- setError(null)
89
+ setError(null);
90
90
  }
91
- props.input.onChange(parsedValue)
92
- }, [JSON.stringify(debouncedValue)])
91
+ props.input.onChange(parsedValue);
92
+ }, [JSON.stringify(debouncedValue)]);
93
93
 
94
94
  React.useEffect(() => {
95
95
  if (monacoEditorRef.current) {
96
96
  if (error) {
97
- const errorMessage = buildError(error)
97
+ const errorMessage = buildError(error);
98
98
  monaco.editor.setModelMarkers(monacoEditorRef.current.getModel(), id, [
99
99
  {
100
100
  ...errorMessage.position,
101
101
  message: errorMessage.message,
102
102
  severity: 8,
103
103
  },
104
- ])
104
+ ]);
105
105
  } else {
106
106
  monaco.editor.setModelMarkers(
107
107
  monacoEditorRef.current.getModel(),
108
108
  id,
109
109
  []
110
- )
110
+ );
111
111
  }
112
112
  }
113
- }, [JSON.stringify(error), monacoEditorRef.current])
113
+ }, [JSON.stringify(error), monacoEditorRef.current]);
114
114
 
115
115
  React.useEffect(() => {
116
116
  if (monaco) {
117
- monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true)
117
+ monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true);
118
118
  monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
119
119
  // disable errors
120
120
  noSemanticValidation: true,
121
121
  noSyntaxValidation: true,
122
- })
122
+ });
123
123
  // TODO: autocomplete suggestions
124
124
  // monaco.languages.registerCompletionItemProvider('markdown', {
125
125
  // provideCompletionItems: function (model, position) {
@@ -143,24 +143,24 @@ export const RawEditor = (props: RichTextType) => {
143
143
  // },
144
144
  // })
145
145
  }
146
- }, [monaco])
146
+ }, [monaco]);
147
147
 
148
148
  function handleEditorDidMount(
149
149
  monacoEditor: monaco.editor.IStandaloneCodeEditor,
150
150
  monaco: Monaco
151
151
  ) {
152
- monacoEditorRef.current = monacoEditor
152
+ monacoEditorRef.current = monacoEditor;
153
153
  monacoEditor.onDidContentSizeChange(() => {
154
154
  // FIXME: if the window is too tall the performance degrades, come up with a nice
155
155
  // balance between the two
156
- setHeight(Math.min(Math.max(100, monacoEditor.getContentHeight()), 1000))
157
- monacoEditor.layout()
158
- })
156
+ setHeight(Math.min(Math.max(100, monacoEditor.getContentHeight()), 1000));
157
+ monacoEditor.layout();
158
+ });
159
159
  }
160
160
 
161
161
  return (
162
- <div className="relative">
163
- <div className="sticky top-1 w-full flex justify-between mb-2 z-50 max-w-full bg-white">
162
+ <div className='relative'>
163
+ <div className='sticky top-1 w-full flex justify-between mb-2 z-50 max-w-full bg-white'>
164
164
  <Button onClick={() => props.setRawMode(false)}>
165
165
  View in rich-text editor 📝
166
166
  </Button>
@@ -204,16 +204,16 @@ export const RawEditor = (props: RichTextType) => {
204
204
  value={value}
205
205
  onChange={(value) => {
206
206
  try {
207
- setValue(value)
207
+ setValue(value);
208
208
  } catch (e) {
209
- console.log('error', e)
209
+ console.log('error', e);
210
210
  }
211
211
  }}
212
212
  />
213
213
  </div>
214
214
  </div>
215
- )
216
- }
215
+ );
216
+ };
217
217
 
218
218
  const Button = (props) => {
219
219
  return (
@@ -223,14 +223,14 @@ const Button = (props) => {
223
223
  ? 'rounded-l-md border-r-0'
224
224
  : 'rounded-r-md border-l-0'
225
225
  } flex justify-center w-full shadow rounded-md bg-white cursor-pointer relative inline-flex items-center px-2 py-2 border border-gray-200 hover:text-white text-sm font-medium transition-all ease-out duration-150 hover:bg-blue-500 focus:z-10 focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500`}
226
- type="button"
226
+ type='button'
227
227
  onClick={props.onClick}
228
228
  >
229
- <span className="text-sm font-semibold tracking-wide align-baseline mr-1">
229
+ <span className='text-sm font-semibold tracking-wide align-baseline mr-1'>
230
230
  {props.children}
231
231
  </span>
232
232
  </button>
233
- )
234
- }
233
+ );
234
+ };
235
235
 
236
- export default RawEditor
236
+ export default RawEditor;
@@ -3,23 +3,23 @@
3
3
 
4
4
 
5
5
  */
6
- import { useState, useEffect } from 'react'
6
+ import { useState, useEffect } from 'react';
7
7
  export function useDebounce(value, delay) {
8
- const [debouncedValue, setDebouncedValue] = useState(value)
8
+ const [debouncedValue, setDebouncedValue] = useState(value);
9
9
  useEffect(
10
10
  () => {
11
11
  // Update debounced value after delay
12
12
  const handler = setTimeout(() => {
13
- setDebouncedValue(value)
14
- }, delay)
13
+ setDebouncedValue(value);
14
+ }, delay);
15
15
  // Cancel the timeout if value changes (also on delay change or unmount)
16
16
  // This is how we prevent debounced value from updating if value is changed ...
17
17
  // .. within the delay period. Timeout gets cleared and restarted.
18
18
  return () => {
19
- clearTimeout(handler)
20
- }
19
+ clearTimeout(handler);
20
+ };
21
21
  },
22
22
  [value, delay] // Only re-call effect if value or delay changes
23
- )
24
- return debouncedValue
23
+ );
24
+ return debouncedValue;
25
25
  }
package/src/global.css CHANGED
@@ -40,13 +40,13 @@
40
40
  --tina-font-size-7: 26px;
41
41
  --tina-font-size-8: 32px;
42
42
 
43
- --tina-font-family: 'Inter', sans-serif;
43
+ --tina-font-family: "Inter", sans-serif;
44
44
 
45
45
  --tina-font-weight-regular: 400;
46
46
  --tina-font-weight-bold: 600;
47
47
 
48
- --tina-shadow-big: 0px 2px 3px rgba(0, 0, 0, 0.05),
49
- 0 4px 12px rgba(0, 0, 0, 0.1);
48
+ --tina-shadow-big: 0px 2px 3px rgba(0, 0, 0, 0.05), 0 4px 12px
49
+ rgba(0, 0, 0, 0.1);
50
50
  --tina-shadow-small: 0px 2px 3px rgba(0, 0, 0, 0.12);
51
51
 
52
52
  --tina-timing-short: 85ms;
package/src/index.css CHANGED
@@ -1,5 +1,5 @@
1
- @import 'global.css';
2
- @import 'preflight.css';
1
+ @import "global.css";
2
+ @import "preflight.css";
3
3
  @tailwind base;
4
4
  @tailwind components;
5
5
  @tailwind utilities;
@@ -16,15 +16,15 @@
16
16
  body {
17
17
  margin: 0;
18
18
  padding: 0;
19
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
20
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
19
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
20
+ "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
21
21
  sans-serif;
22
22
  -webkit-font-smoothing: antialiased;
23
23
  -moz-osx-font-smoothing: grayscale;
24
24
  }
25
25
 
26
26
  code {
27
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
27
+ font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
28
28
  monospace;
29
29
  }
30
30
 
@@ -38,32 +38,32 @@ div.graphiql-explorer-root > div:last-child {
38
38
  }
39
39
 
40
40
  /* if the last block has margin-bottom it makes the text box larger but some of it isn't clickable */
41
- .tina-prose [data-slate-editor='true'] {
41
+ .tina-prose [data-slate-editor="true"] {
42
42
  padding-bottom: 0.5em;
43
43
  /* Outline is placed on the parent element for styling consistency with other elements */
44
44
  outline: none;
45
45
  }
46
46
  /* prose adds backticks, which look like they should be editable */
47
- .tina-prose [data-slate-editor='true'] .slate-code::before {
48
- content: '';
47
+ .tina-prose [data-slate-editor="true"] .slate-code::before {
48
+ content: "";
49
49
  }
50
- .tina-prose [data-slate-editor='true'] .slate-code::after {
51
- content: '';
50
+ .tina-prose [data-slate-editor="true"] .slate-code::after {
51
+ content: "";
52
52
  }
53
- .tina-prose [data-slate-editor='true'] .slate-code_block {
53
+ .tina-prose [data-slate-editor="true"] .slate-code_block {
54
54
  margin: 0;
55
55
  }
56
56
  /* code lines as part of a block don't need the same background formatting */
57
- .tina-prose [data-slate-editor='true'] .slate-code_block .slate-code {
57
+ .tina-prose [data-slate-editor="true"] .slate-code_block .slate-code {
58
58
  background: none;
59
59
  }
60
60
  /* prose makes the first p in a block slightly larger */
61
- .tina-prose [data-slate-editor='true'] p:first-of-type {
61
+ .tina-prose [data-slate-editor="true"] p:first-of-type {
62
62
  font-size: 1em;
63
63
  }
64
64
 
65
65
  /* experimental floating toolbar doesn't need a large text area */
66
- .with-toolbar [data-slate-editor='true'] {
66
+ .with-toolbar [data-slate-editor="true"] {
67
67
  min-height: 72px;
68
68
  }
69
69
 
@@ -190,7 +190,7 @@ div.graphiql-explorer-root > div:last-child {
190
190
  }
191
191
 
192
192
  .tina-date-field .rdtPicker td.rdtToday:before {
193
- content: '';
193
+ content: "";
194
194
  display: inline-block;
195
195
  border-left: 7px solid transparent;
196
196
  border-bottom: 7px solid var(--tina-color-primary);
@@ -1,42 +1,42 @@
1
- import { Field, Form, FormOptions, TinaCMS, TinaField } from 'tinacms'
1
+ import { Field, Form, FormOptions, TinaCMS, TinaField } from 'tinacms';
2
2
 
3
- export type FieldType = Field & TinaField
4
- export type FormValues = Record<string, unknown>
5
- export type FormType = Form<FormValues, FieldType>
3
+ export type FieldType = Field & TinaField;
4
+ export type FormValues = Record<string, unknown>;
5
+ export type FormType = Form<FormValues, FieldType>;
6
6
 
7
- type FormCreator = (formConfig: FormOptions<any>) => Form
7
+ type FormCreator = (formConfig: FormOptions<any>) => Form;
8
8
  interface GlobalFormOptions {
9
- icon?: any
10
- layout: 'fullscreen' | 'popup'
9
+ icon?: any;
10
+ layout: 'fullscreen' | 'popup';
11
11
  }
12
12
  type GlobalFormCreator = (
13
13
  formConfig: FormOptions<any>,
14
14
  options?: GlobalFormOptions
15
- ) => Form
15
+ ) => Form;
16
16
  interface GlobalFormOptions {
17
- icon?: any
18
- layout: 'fullscreen' | 'popup'
17
+ icon?: any;
18
+ layout: 'fullscreen' | 'popup';
19
19
  }
20
20
  export interface FormifyArgs {
21
- formConfig: FormOptions<any>
22
- createForm: FormCreator
23
- createGlobalForm: FormCreator
24
- skip?: () => void
21
+ formConfig: FormOptions<any>;
22
+ createForm: FormCreator;
23
+ createGlobalForm: FormCreator;
24
+ skip?: () => void;
25
25
  }
26
26
 
27
- export type FormifyCallback = (args: FormifyArgs, cms: TinaCMS) => Form | void
27
+ export type FormifyCallback = (args: FormifyArgs, cms: TinaCMS) => Form | void;
28
28
  export type onSubmitArgs = {
29
29
  /**
30
30
  * @deprecated queryString is actually a mutation string, use `mutationString` instead
31
31
  */
32
- queryString: string
33
- mutationString: string
34
- variables: object
35
- }
32
+ queryString: string;
33
+ mutationString: string;
34
+ variables: object;
35
+ };
36
36
 
37
37
  export const createForm = (formConfig: FormOptions<any, any>) => {
38
- return new Form(formConfig)
39
- }
38
+ return new Form(formConfig);
39
+ };
40
40
  export const createGlobalForm: GlobalFormCreator = (
41
41
  formConfig,
42
42
  options?: { icon?: any; layout: 'fullscreen' | 'popup' }
@@ -44,6 +44,6 @@ export const createGlobalForm: GlobalFormCreator = (
44
44
  const form = new Form({
45
45
  ...formConfig,
46
46
  global: { global: true, ...options },
47
- })
48
- return form
49
- }
47
+ });
48
+ return form;
49
+ };
@@ -1,8 +1,8 @@
1
- import React from 'react'
2
- import { TinaCMS } from 'tinacms'
1
+ import React from 'react';
2
+ import { TinaCMS } from 'tinacms';
3
3
 
4
4
  const ErrorModalContent = (props: { title: string; errors: string[] }) => {
5
- const { title, errors } = props
5
+ const { title, errors } = props;
6
6
  return (
7
7
  <>
8
8
  <div>{title}</div>
@@ -12,13 +12,13 @@ const ErrorModalContent = (props: { title: string; errors: string[] }) => {
12
12
  ))}
13
13
  </ul>
14
14
  </>
15
- )
16
- }
15
+ );
16
+ };
17
17
 
18
18
  export const showErrorModal = (
19
19
  title: string,
20
20
  errors: string[],
21
21
  cms: TinaCMS
22
22
  ) => {
23
- cms.alerts.error(() => <ErrorModalContent title={title} errors={errors} />)
24
- }
23
+ cms.alerts.error(() => <ErrorModalContent title={title} errors={errors} />);
24
+ };