Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: force context menu #396

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lib/components/JSONEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
export let askToFormat = true
export let escapeControlCharacters = false
export let escapeUnicodeCharacters = false
export let forceContextMenu = false
export let flattenColumns = true
export let parser: JSONParser = JSON
export let validator: Validator | null = null
Expand Down Expand Up @@ -393,6 +394,7 @@
onPatch,

readOnly,
forceContextMenu,
indentation,
tabSize,
mainMenuBar,
Expand Down Expand Up @@ -462,6 +464,7 @@
{navigationBar}
{escapeControlCharacters}
{escapeUnicodeCharacters}
{forceContextMenu}
{flattenColumns}
{parser}
{parseMemoizeOne}
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 @@ -41,6 +41,7 @@
export let onPatch: OnPatch

export let readOnly: boolean
export let forceContextMenu: boolean
export let indentation: number | string
export let tabSize: number
export let mainMenuBar: boolean
Expand Down Expand Up @@ -244,6 +245,7 @@
{askToFormat}
{mainMenuBar}
{navigationBar}
{forceContextMenu}
{escapeControlCharacters}
{escapeUnicodeCharacters}
{flattenColumns}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/modals/TransformModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
export let indentation: number | string
export let escapeControlCharacters: boolean
export let escapeUnicodeCharacters: boolean
export let forceContextMenu: boolean
export let parser: JSONParser
export let parseMemoizeOne: JSONParser['parse']
export let validationParser: JSONParser
Expand Down Expand Up @@ -279,6 +280,7 @@
{indentation}
{escapeControlCharacters}
{escapeUnicodeCharacters}
{forceContextMenu}
{parser}
{parseMemoizeOne}
{onRenderValue}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/modes/JSONEditorRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
export let escapeControlCharacters: boolean
export let escapeUnicodeCharacters: boolean
export let flattenColumns: boolean
export let forceContextMenu: boolean
export let parser: JSONParser
export let parseMemoizeOne: JSONParser['parse']
export let validator: Validator | null
Expand Down Expand Up @@ -271,6 +272,7 @@
externalSelection={selection}
{readOnly}
{mainMenuBar}
{forceContextMenu}
{escapeControlCharacters}
{escapeUnicodeCharacters}
{flattenColumns}
Expand Down Expand Up @@ -301,6 +303,7 @@
{indentation}
{mainMenuBar}
{navigationBar}
{forceContextMenu}
{escapeControlCharacters}
{escapeUnicodeCharacters}
{parser}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/components/modes/tablemode/TableMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
debug('isSSR:', isSSR)

export let readOnly: boolean
export let forceContextMenu: boolean

export let externalContent: Content
export let externalSelection: JSONEditorSelection | null
export let mainMenuBar: boolean
Expand Down Expand Up @@ -979,7 +981,7 @@
}

function handleContextMenu(event: Event) {
if (readOnly || isEditingSelection(documentState.selection)) {
if ((readOnly && !forceContextMenu) || isEditingSelection(documentState.selection)) {
return
}

Expand Down Expand Up @@ -1028,7 +1030,7 @@
}

function handleContextMenuFromTableMenu(event: MouseEvent) {
if (readOnly) {
if (readOnly && !forceContextMenu) {
return
}

Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/modes/treemode/TreeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
const jump = createJump()

export let readOnly: boolean
export let forceContextMenu: boolean
export let externalContent: Content
export let externalSelection: JSONEditorSelection | null
export let mainMenuBar: boolean
Expand Down Expand Up @@ -1879,7 +1880,7 @@
}

function handleContextMenu(event?: Event) {
if (readOnly || isEditingSelection(documentState.selection)) {
if ((readOnly && !forceContextMenu) || isEditingSelection(documentState.selection)) {
return
}

Expand Down Expand Up @@ -1928,7 +1929,7 @@
}

function handleContextMenuFromTreeMenu(event: MouseEvent) {
if (readOnly) {
if (readOnly && !forceContextMenu) {
return
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export interface JSONEditorPropsOptional {
escapeControlCharacters?: boolean
escapeUnicodeCharacters?: boolean
flattenColumns?: true
forceContextMenu?: boolean
parser?: JSONParser
validator?: Validator | null
validationParser?: JSONParser
Expand Down
5 changes: 5 additions & 0 deletions src/routes/development/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
const validate = useLocalStorage('svelte-jsoneditor-demo-validate', false)
const validateArray = useLocalStorage('svelte-jsoneditor-demo-validate-array', false)
const readOnly = useLocalStorage('svelte-jsoneditor-demo-readOnly', false)
const forceContextMenu = useLocalStorage('svelte-jsoneditor-demo-forceContextMenu', false)
const mainMenuBar = useLocalStorage('svelte-jsoneditor-demo-mainMenuBar', true)
const navigationBar = useLocalStorage('svelte-jsoneditor-demo-navigationBar', true)
const statusBar = useLocalStorage('svelte-jsoneditor-demo-statusBar', true)
Expand Down Expand Up @@ -540,6 +541,9 @@
<label>
<input type="checkbox" bind:checked={$readOnly} /> readOnly
</label>
<label>
<input type="checkbox" bind:checked={$forceContextMenu} /> forceContextMenu
</label>
<label>
<input type="checkbox" bind:checked={$useCustomValueRenderer} /> Custom onRenderValue
</label>
Expand Down Expand Up @@ -767,6 +771,7 @@
escapeUnicodeCharacters={$escapeUnicodeCharacters}
flattenColumns={$flattenColumns}
readOnly={$readOnly}
forceContextMenu={$forceContextMenu}
indentation={$selectedIndentation}
tabSize={$tabSize}
parser={selectedParser}
Expand Down