Skip to content

Commit

Permalink
feat: make the option askToFormat configurable (fix #252)
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Apr 17, 2023
1 parent 961628d commit 5e5494f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const editor = new JSONEditor({
- `mainMenuBar: boolean` Show the main menu bar. Default value is `true`.
- `navigationBar: boolean` Show the navigation bar with, where you can see the selected path and navigate through your document from there. Default value is `true`.
- `statusBar: boolean` Show a status bar at the bottom of the `'text'` editor, showing information about the cursor location and selected contents. Default value is `true`.
- `askToFormat: boolean` When `true` (default), the user will be asked whether he/she wants to format the JSON document when a compact document is loaded or pasted in `'text'` mode. Only applicable to `'text'` mode.
- `readOnly: boolean` Open the editor in read-only mode: no changes can be made, non-relevant buttons are hidden from the menu, and the context menu is not enabled. Default value is `false`.
- `indentation: number | string` Number of spaces use for indentation when stringifying JSON, or a string to be used as indentation like `'\t'` to use a tab as indentation, or `' '` to use 4 spaces (which is equivalent to configuring `indentation: 4`). See also property `tabSize`.
- `tabSize: number` When indentation is configured as a tab character (`indentation: '\t'`), `tabSize` configures how large a tab character is rendered. Default value is `4`. Only applicable to `text` mode.
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/JSONEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
export let mainMenuBar = true
export let navigationBar = true
export let statusBar = true
export let askToFormat = true
export let escapeControlCharacters = false
export let escapeUnicodeCharacters = false
export let flattenColumns = true
Expand Down Expand Up @@ -373,6 +374,7 @@
mainMenuBar,
navigationBar,
statusBar,
askToFormat,
escapeControlCharacters,
escapeUnicodeCharacters,
flattenColumns,
Expand Down Expand Up @@ -433,6 +435,7 @@
{indentation}
{tabSize}
{statusBar}
{askToFormat}
{mainMenuBar}
{navigationBar}
{escapeControlCharacters}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/modals/JSONEditorModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
export let mainMenuBar: boolean
export let navigationBar: boolean
export let statusBar: boolean
export let askToFormat: boolean
export let escapeControlCharacters: boolean
export let escapeUnicodeCharacters: boolean
export let flattenColumns: boolean
Expand Down Expand Up @@ -204,6 +205,7 @@
{indentation}
{tabSize}
{statusBar}
{askToFormat}
{mainMenuBar}
{navigationBar}
{escapeControlCharacters}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/modes/JSONEditorRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
export let mainMenuBar: boolean
export let navigationBar: boolean
export let statusBar: boolean
export let askToFormat: boolean
export let escapeControlCharacters: boolean
export let escapeUnicodeCharacters: boolean
export let flattenColumns: boolean
Expand Down Expand Up @@ -232,6 +233,7 @@
{tabSize}
{mainMenuBar}
{statusBar}
{askToFormat}
{escapeUnicodeCharacters}
{parser}
{validator}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modes/textmode/TextMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
export let readOnly: boolean
export let mainMenuBar: boolean
export let statusBar: boolean
export let askToFormat: boolean
export let externalContent: Content
export let indentation: number | string
export let tabSize: number
Expand Down Expand Up @@ -112,7 +113,6 @@
let onChangeDisabled = false
let acceptTooLarge = false
let askToFormat = true
let validationErrors: ValidationError[] = []
const linterCompartment = new Compartment()
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export interface JSONEditorPropsOptional {
mainMenuBar?: boolean
navigationBar?: boolean
statusBar?: boolean
askToFormat?: boolean
escapeControlCharacters?: boolean
escapeUnicodeCharacters?: boolean
flattenColumns?: true
Expand Down
6 changes: 6 additions & 0 deletions src/routes/development/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
const mainMenuBar = useLocalStorage('svelte-jsoneditor-demo-mainMenuBar', true)
const navigationBar = useLocalStorage('svelte-jsoneditor-demo-navigationBar', true)
const statusBar = useLocalStorage('svelte-jsoneditor-demo-statusBar', true)
const askToFormat = useLocalStorage('svelte-jsoneditor-demo-askToFormat', true)
const escapeControlCharacters = useLocalStorage(
'svelte-jsoneditor-demo-escapeControlCharacters',
false
Expand Down Expand Up @@ -396,6 +397,9 @@
<label>
<input type="checkbox" bind:checked={$statusBar} /> statusBar
</label>
<label>
<input type="checkbox" bind:checked={$askToFormat} /> askToFormat
</label>
<label>
<input type="checkbox" bind:checked={$escapeControlCharacters} /> escapeControlCharacters
</label>
Expand Down Expand Up @@ -630,6 +634,7 @@
mainMenuBar={$mainMenuBar}
navigationBar={$navigationBar}
statusBar={$statusBar}
askToFormat={$askToFormat}
escapeControlCharacters={$escapeControlCharacters}
escapeUnicodeCharacters={$escapeUnicodeCharacters}
flattenColumns={$flattenColumns}
Expand Down Expand Up @@ -678,6 +683,7 @@
mainMenuBar={$mainMenuBar}
navigationBar={$navigationBar}
statusBar={$statusBar}
askToFormat={$askToFormat}
escapeControlCharacters={$escapeControlCharacters}
escapeUnicodeCharacters={$escapeUnicodeCharacters}
flattenColumns={$flattenColumns}
Expand Down

0 comments on commit 5e5494f

Please sign in to comment.