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: hidden value plugins #397

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
11 changes: 10 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import BooleanToggle from './plugins/value/components/BooleanToggle.svelte'
import ColorPicker from './plugins/value/components/ColorPicker.svelte'
import EditableValue from './plugins/value/components/EditableValue.svelte'
import EnumValue from './plugins/value/components/EnumValue.svelte'
import HiddenValue from './plugins/value/components/HiddenValue.svelte'
import ReadonlyValue from './plugins/value/components/ReadonlyValue.svelte'
import TimestampTag from './plugins/value/components/TimestampTag.svelte'

Expand All @@ -13,7 +14,15 @@ export * from './types.js'
// value plugins
export { renderValue } from './plugins/value/renderValue.js'
export { renderJSONSchemaEnum } from './plugins/value/renderJSONSchemaEnum.js'
export { BooleanToggle, ColorPicker, EditableValue, EnumValue, ReadonlyValue, TimestampTag }
export {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BooleanToggle,
ColorPicker,
EditableValue,
EnumValue,
HiddenValue,
ReadonlyValue,
TimestampTag
}

// validator plugins
export * from './plugins/validator/createAjvValidator.js'
Expand Down
45 changes: 45 additions & 0 deletions src/lib/plugins/value/components/HiddenValue.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<svelte:options immutable={true} />

<script>
import Icon from 'svelte-awesome'
import { faLock } from '@fortawesome/free-solid-svg-icons'
import { createValueSelection } from 'svelte-jsoneditor'

export let value
export let path
export let readOnly
export let onSelect

$: hiddenValue = '*'.repeat(String(value).length)

function handleValueDoubleClick(event) {
if (!readOnly) {
event.preventDefault()
event.stopPropagation()

// open in edit mode
onSelect(createValueSelection(path, true))
}
}
</script>

<div
role="button"
tabindex="-1"
class="jse-value jse-readonly-password"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename the class to jse-hidden-value?

data-type="selectable-value"
on:dblclick={handleValueDoubleClick}
>
<Icon data={faLock} />
{hiddenValue}
</div>

<style>
.jse-readonly-password {
padding: 0 5px;
}

.jse-readonly-password:hover {
background: #ededed;
}
</style>