Skip to content

Commit

Permalink
chore: remove passing parser to function getEnforceString
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Aug 1, 2024
1 parent ff859f1 commit 5edb7c5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/lib/components/modes/tablemode/TableMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@
documentState,
selection,
readOnly,
parser,
onEditValue: handleEditValue,
onEditRow: handleEditRow,
Expand Down Expand Up @@ -1066,7 +1065,7 @@
const path = selection.path
const pointer = compileJSONPointer(path)
const value = getIn(json, path)
const enforceString = !getEnforceString(json, documentState, path, parser)
const enforceString = !getEnforceString(json, documentState, path)
const updatedValue = enforceString ? String(value) : stringConvert(String(value), parser)
debug('handleToggleEnforceString', { enforceString, value, updatedValue })
Expand Down Expand Up @@ -1830,7 +1829,7 @@
<JSONValue
{path}
value={value !== undefined ? value : ''}
enforceString={getEnforceString(json, documentState, path, parser)}
enforceString={getEnforceString(json, documentState, path)}
selection={isSelected ? selection : undefined}
searchResultItems={searchResultItemsByCell}
{context}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ContextMenuItem, DocumentState, JSONParser, JSONSelection } from 'svelte-jsoneditor'
import type { ContextMenuItem, DocumentState, JSONSelection } from 'svelte-jsoneditor'
import {
faCheckSquare,
faClone,
Expand All @@ -21,7 +21,6 @@ export default function ({
documentState,
selection,
readOnly,
parser,
onEditValue,
onEditRow,
onToggleEnforceString,
Expand All @@ -38,7 +37,6 @@ export default function ({
documentState: DocumentState | undefined
selection: JSONSelection | undefined
readOnly: boolean
parser: JSONParser
onEditValue: () => void
onEditRow: () => void
onToggleEnforceString: () => void
Expand Down Expand Up @@ -67,9 +65,7 @@ export default function ({
const canCut = !readOnly && hasSelectionContents

const enforceString =
selection !== undefined
? getEnforceString(json, documentState, getFocusPath(selection), parser)
: false
selection !== undefined ? getEnforceString(json, documentState, getFocusPath(selection)) : false

return [
{ type: 'separator' },
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modes/treemode/JSONNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
$: expanded = isExpandableState(state) ? state.expanded : false
let enforceString: boolean
$: enforceString = getEnforceString(value, state, [], context.parser)
$: enforceString = getEnforceString(value, state, [])
let visibleSections: VisibleSection[] | undefined
$: visibleSections = isArrayRecursiveState(state) ? state.visibleSections : undefined
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/modes/treemode/TreeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@
const path = getFocusPath(selection)
const pointer = compileJSONPointer(path)
const value = getIn(json, path)
const enforceString = !getEnforceString(json, documentState, path, parser)
const enforceString = !getEnforceString(json, documentState, path)
const updatedValue = enforceString ? String(value) : stringConvert(String(value), parser)
debug('handleToggleEnforceString', { enforceString, value, updatedValue })
Expand Down Expand Up @@ -1609,7 +1609,6 @@
documentState,
selection,
readOnly,
parser,
onEditKey: handleEditKey,
onEditValue: handleEditValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default function ({
documentState,
selection,
readOnly,
parser,
onEditKey,
onEditValue,
onToggleEnforceString,
Expand All @@ -64,7 +63,6 @@ export default function ({
documentState: DocumentState | undefined
selection: JSONSelection | undefined
readOnly: boolean
parser: JSONParser
onEditKey: () => void
onEditValue: () => void
onToggleEnforceString: () => void
Expand Down Expand Up @@ -131,9 +129,7 @@ export default function ({
!readOnly && (convertMode ? canConvert(selection) && isObjectOrArray(focusValue) : hasSelection)

const enforceString =
selection !== undefined
? getEnforceString(json, documentState, getFocusPath(selection), parser)
: false
selection !== undefined ? getEnforceString(json, documentState, getFocusPath(selection)) : false

function handleInsertOrConvert(type: InsertType) {
if (hasSelectionContents) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/logic/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export function createSearchAndReplaceOperations(
}
const currentValueText = typeof currentValue === 'string' ? currentValue : String(currentValue)

const enforceString = getEnforceString(json, documentState, path, parser)
const enforceString = getEnforceString(json, documentState, path)
const value = replaceText(currentValueText, replacementText, start, end)

const operations: JSONPatchOperation[] = [
Expand Down Expand Up @@ -402,7 +402,7 @@ export function createSearchAndReplaceAllOperations(
}
const currentValueText =
typeof currentValue === 'string' ? currentValue : String(currentValue)
const enforceString = getEnforceString(json, documentState, path, parser)
const enforceString = getEnforceString(json, documentState, path)
const value = replaceAllText(currentValueText, replacementText, items)

const operations: JSONPatchOperation[] = [
Expand Down

0 comments on commit 5edb7c5

Please sign in to comment.