Revert focus specific logic in other components and simplify

This commit is contained in:
Andrew Kingston 2022-06-13 16:11:12 +01:00
parent f6b55efbec
commit 22df82dd9d
25 changed files with 37 additions and 235 deletions

View File

@ -1,8 +1,7 @@
<script> <script>
import "@spectrum-css/actionbutton/dist/index-vars.css" import "@spectrum-css/actionbutton/dist/index-vars.css"
import { createEventDispatcher, getContext } from "svelte" import { createEventDispatcher } from "svelte"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const context = getContext("builderFocus")
export let quiet = false export let quiet = false
export let emphasized = false export let emphasized = false
@ -14,14 +13,6 @@
export let size = "M" export let size = "M"
export let active = false export let active = false
export let fullWidth = false export let fullWidth = false
export let autofocus = false
let focus = false
let actionButton
$: focus = autofocus && actionButton !== undefined
$: if (focus) {
actionButton.focus()
}
function longPress(element) { function longPress(element) {
if (!longPressable) return if (!longPressable) return
@ -46,7 +37,6 @@
<button <button
data-cy={dataCy} data-cy={dataCy}
bind:this={actionButton}
use:longPress use:longPress
class:spectrum-ActionButton--quiet={quiet} class:spectrum-ActionButton--quiet={quiet}
class:spectrum-ActionButton--emphasized={emphasized} class:spectrum-ActionButton--emphasized={emphasized}
@ -54,17 +44,9 @@
class:fullWidth class:fullWidth
class="spectrum-ActionButton spectrum-ActionButton--size{size}" class="spectrum-ActionButton spectrum-ActionButton--size{size}"
class:active class:active
class:is-focused={focus}
{disabled} {disabled}
on:longPress on:longPress
on:click|preventDefault on:click|preventDefault
on:focus={() => {
focus = true
}}
on:blur={() => {
focus = false
if (context) context.clear()
}}
> >
{#if longPressable} {#if longPressable}
<svg <svg
@ -98,10 +80,4 @@
.active svg { .active svg {
color: var(--spectrum-global-color-blue-600); color: var(--spectrum-global-color-blue-600);
} }
button.is-focused {
border-color: var(
--spectrum-textfield-m-border-color-down,
var(--spectrum-alias-border-color-mouse-focus)
);
}
</style> </style>

View File

@ -13,7 +13,6 @@
export let options = [] export let options = []
export let getOptionLabel = option => extractProperty(option, "label") export let getOptionLabel = option => extractProperty(option, "label")
export let getOptionValue = option => extractProperty(option, "value") export let getOptionValue = option => extractProperty(option, "value")
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = e => {
@ -36,7 +35,6 @@
{options} {options}
{placeholder} {placeholder}
{readonly} {readonly}
{autofocus}
{getOptionLabel} {getOptionLabel}
{getOptionValue} {getOptionValue}
on:change={onChange} on:change={onChange}

View File

@ -3,29 +3,21 @@
import "@spectrum-css/popover/dist/index-vars.css" import "@spectrum-css/popover/dist/index-vars.css"
import "@spectrum-css/menu/dist/index-vars.css" import "@spectrum-css/menu/dist/index-vars.css"
import { fly } from "svelte/transition" import { fly } from "svelte/transition"
import { createEventDispatcher, getContext } from "svelte" import { createEventDispatcher } from "svelte"
export let value = null export let value = null
export let id = null export let id = null
export let placeholder = "Choose an option or type" export let placeholder = "Choose an option or type"
export let disabled = false export let disabled = false
export let readonly = false export let readonly = false
export let autofocus = false
export let error = null export let error = null
export let options = [] export let options = []
export let getOptionLabel = option => option export let getOptionLabel = option => option
export let getOptionValue = option => option export let getOptionValue = option => option
const context = getContext("builderFocus")
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let open = false let open = false
let focus = false let focus = false
let comboInput
$: focus = autofocus && comboInput !== undefined
$: if (focus) {
comboInput.focus()
}
const selectOption = value => { const selectOption = value => {
dispatch("change", value) dispatch("change", value)
@ -57,16 +49,10 @@
class:is-focused={open || focus} class:is-focused={open || focus}
> >
<input <input
bind:this={comboInput}
{id} {id}
type="text" type="text"
on:focus={() => { on:focus={() => (focus = true)}
focus = true on:blur={() => (focus = false)}
}}
on:blur={() => {
focus = false
context.clear()
}}
on:change={onType} on:change={onType}
value={value || ""} value={value || ""}
placeholder={placeholder || ""} placeholder={placeholder || ""}

View File

@ -13,7 +13,6 @@
export let readonly = false export let readonly = false
export let autocomplete = false export let autocomplete = false
export let sort = false export let sort = false
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: selectedLookupMap = getSelectedLookupMap(value) $: selectedLookupMap = getSelectedLookupMap(value)
@ -86,5 +85,4 @@
{getOptionValue} {getOptionValue}
onSelectOption={toggleOption} onSelectOption={toggleOption}
{sort} {sort}
{autofocus}
/> />

View File

@ -3,7 +3,7 @@
import "@spectrum-css/popover/dist/index-vars.css" import "@spectrum-css/popover/dist/index-vars.css"
import "@spectrum-css/menu/dist/index-vars.css" import "@spectrum-css/menu/dist/index-vars.css"
import { fly } from "svelte/transition" import { fly } from "svelte/transition"
import { createEventDispatcher, getContext } from "svelte" import { createEventDispatcher } from "svelte"
import clickOutside from "../../Actions/click_outside" import clickOutside from "../../Actions/click_outside"
import Search from "./Search.svelte" import Search from "./Search.svelte"
@ -26,18 +26,9 @@
export let autoWidth = false export let autoWidth = false
export let autocomplete = false export let autocomplete = false
export let sort = false export let sort = false
export let autofocus = false
const context = getContext("builderFocus")
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let searchTerm = null let searchTerm = null
let focus = false
let pickerButton
$: focus = autofocus && pickerButton !== undefined
$: if (focus) {
pickerButton.focus()
}
$: sortedOptions = getSortedOptions(options, getOptionLabel, sort) $: sortedOptions = getSortedOptions(options, getOptionLabel, sort)
$: filteredOptions = getFilteredOptions( $: filteredOptions = getFilteredOptions(
@ -89,24 +80,7 @@
class:is-invalid={!!error} class:is-invalid={!!error}
class:is-open={open} class:is-open={open}
aria-haspopup="listbox" aria-haspopup="listbox"
class:is-focused={focus}
bind:this={pickerButton}
on:mousedown={onClick} on:mousedown={onClick}
on:keydown={e => {
var keycode = e.key
if (focus) {
if (keycode === "Enter") {
onClick(e)
}
}
}}
on:focus={() => {
focus = true
}}
on:blur={() => {
focus = false
if (context) context.clear()
}}
> >
{#if fieldIcon} {#if fieldIcon}
<span class="icon-Placeholder-Padding"> <span class="icon-Placeholder-Padding">

View File

@ -16,7 +16,6 @@
export let autoWidth = false export let autoWidth = false
export let autocomplete = false export let autocomplete = false
export let sort = false export let sort = false
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let open = false let open = false
@ -75,7 +74,6 @@
{fieldIcon} {fieldIcon}
{autocomplete} {autocomplete}
{sort} {sort}
{autofocus}
isPlaceholder={value == null || value === ""} isPlaceholder={value == null || value === ""}
placeholderOption={placeholder} placeholderOption={placeholder}
isOptionSelected={option => option === value} isOptionSelected={option => option === value}

View File

@ -14,7 +14,6 @@
export let getOptionLabel = option => option export let getOptionLabel = option => option
export let getOptionValue = option => option export let getOptionValue = option => option
export let sort = false export let sort = false
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = e => {
@ -36,6 +35,5 @@
{getOptionValue} {getOptionValue}
on:change={onChange} on:change={onChange}
on:click on:click
{autofocus}
/> />
</Field> </Field>

View File

@ -18,7 +18,6 @@
export let autoWidth = false export let autoWidth = false
export let sort = false export let sort = false
export let tooltip = "" export let tooltip = ""
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = e => {
@ -45,7 +44,6 @@
{placeholder} {placeholder}
{autoWidth} {autoWidth}
{sort} {sort}
{autofocus}
{getOptionLabel} {getOptionLabel}
{getOptionValue} {getOptionValue}
{getOptionIcon} {getOptionIcon}

View File

@ -20,7 +20,6 @@ import analytics, { Events } from "analytics"
import { import {
findComponentType, findComponentType,
findComponentParent, findComponentParent,
findComponentPath,
findClosestMatchingComponent, findClosestMatchingComponent,
findAllMatchingComponents, findAllMatchingComponents,
findComponent, findComponent,
@ -423,21 +422,6 @@ export const getFrontendStore = () => {
store.update(state => { store.update(state => {
state.currentView = "component" state.currentView = "component"
state.selectedComponentId = componentInstance._id state.selectedComponentId = componentInstance._id
const focusSetting = resolveComponentFocus(
asset?.props,
componentInstance
)
if (focusSetting) {
state.builderFocus = [
{
key: focusSetting.key,
target: state.selectedComponentId,
location: "component_settings",
},
]
}
return state return state
}) })
@ -680,32 +664,5 @@ export const getFrontendStore = () => {
}, },
} }
// Determine the initial focus for newly created components
// Take into account the fact that data providers should be
// skipped if they will be inherited from the path
const resolveComponentFocus = (asset_props, componentInstance) => {
const definition = store.actions.components.getDefinition(
componentInstance._component
)
let providerIdx = -1
let required = definition.settings.filter((s, idx) => {
if (s.type === "dataProvider") {
providerIdx = idx
}
return s.required
})
if (providerIdx > -1) {
const path = findComponentPath(asset_props, componentInstance._id)
const providers = path.filter(c =>
c._component?.endsWith("/dataprovider")
)
if (providers.length) {
required = required.splice(providerIdx, 1)
}
}
return required[0]
}
return store return store
} }

View File

@ -18,7 +18,6 @@
export let options export let options
export let allowJS = true export let allowJS = true
export let appendBindingsAsOptions = true export let appendBindingsAsOptions = true
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let bindingDrawer let bindingDrawer
@ -62,7 +61,6 @@
on:pick={e => onChange(e.detail, true)} on:pick={e => onChange(e.detail, true)}
{placeholder} {placeholder}
options={allOptions} options={allOptions}
{autofocus}
/> />
{#if !disabled} {#if !disabled}
<div <div

View File

@ -68,7 +68,7 @@
customTheme: $store.customTheme, customTheme: $store.customTheme,
previewDevice: $store.previewDevice, previewDevice: $store.previewDevice,
messagePassing: $store.clientFeatures.messagePassing, messagePassing: $store.clientFeatures.messagePassing,
isBudibaseEvent: true isBudibaseEvent: true,
} }
$: json = JSON.stringify(previewData) $: json = JSON.stringify(previewData)
@ -148,21 +148,6 @@
} }
}) })
const resolveFocus = (data) => {
if($store.builderFocus){
const comp = $store.builderFocus.reduce((acc, item)=>{
acc = item.target
return acc
}, "")
if(data.id !== comp){
store.update(state => {
delete state.builderFocus
return state
})
}
}
}
const handleBudibaseEvent = async event => { const handleBudibaseEvent = async event => {
const { type, data } = event.data || event.detail const { type, data } = event.data || event.detail
if (!type) { if (!type) {
@ -172,7 +157,6 @@
try { try {
if (type === "select-component" && data.id) { if (type === "select-component" && data.id) {
store.actions.components.select({ _id: data.id }) store.actions.components.select({ _id: data.id })
resolveFocus(data)
} else if (type === "update-prop") { } else if (type === "update-prop") {
await store.actions.components.updateProp(data.prop, data.value) await store.actions.components.updateProp(data.prop, data.value)
} else if (type === "delete-component" && data.id) { } else if (type === "delete-component" && data.id) {
@ -206,12 +190,8 @@
store.actions.components.copy(source, true) store.actions.components.copy(source, true)
await store.actions.components.paste(destination, data.mode) await store.actions.components.paste(destination, data.mode)
} }
} else if(type == "builder-focus") { } else if (type === "highlight-setting") {
store.update(state => ({ console.log(data.setting)
...state,
builderFocus :
[...data]
}))
} else { } else {
console.warn(`Client sent unknown event type: ${type}`) console.warn(`Client sent unknown event type: ${type}`)
} }

View File

@ -73,15 +73,6 @@
return true return true
} }
const isFocused = setting => {
if (!$store.builderFocus) {
return false
}
return (
setting.required === true && $store.builderFocus[0].key === setting.key
)
}
</script> </script>
{#each sections as section, idx (section.name)} {#each sections as section, idx (section.name)}
@ -116,7 +107,6 @@
{componentBindings} {componentBindings}
{componentInstance} {componentInstance}
{componentDefinition} {componentDefinition}
autofocus={isFocused(setting)}
/> />
{/if} {/if}
{/each} {/each}

View File

@ -6,7 +6,6 @@
import { createEventDispatcher, onMount } from "svelte" import { createEventDispatcher, onMount } from "svelte"
export let value export let value
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const getValue = component => `{{ literal ${makePropSafe(component._id)} }}` const getValue = component => `{{ literal ${makePropSafe(component._id)} }}`
@ -25,7 +24,6 @@
<Select <Select
{value} {value}
{autofocus}
placeholder={null} placeholder={null}
on:change on:change
options={providers} options={providers}

View File

@ -25,7 +25,6 @@
export let otherSources export let otherSources
export let showAllQueries export let showAllQueries
export let bindings = [] export let bindings = []
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const arrayTypes = ["attachment", "array"] const arrayTypes = ["attachment", "array"]
@ -159,7 +158,6 @@
value={text} value={text}
options={[text]} options={[text]}
on:click={dropdownRight.show} on:click={dropdownRight.show}
{autofocus}
/> />
{#if value?.type === "query"} {#if value?.type === "query"}
<i class="ri-settings-5-line" on:click={openQueryParamsDrawer} /> <i class="ri-settings-5-line" on:click={openQueryParamsDrawer} />

View File

@ -10,7 +10,6 @@
export let componentInstance = {} export let componentInstance = {}
export let value = "" export let value = ""
export let placeholder export let placeholder
export let autofocus = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($currentAsset, componentInstance) $: datasource = getDatasourceForProvider($currentAsset, componentInstance)
@ -38,10 +37,4 @@
} }
</script> </script>
<Select <Select {placeholder} value={boundValue} on:change={onChange} {options} />
{placeholder}
value={boundValue}
on:change={onChange}
{options}
{autofocus}
/>

View File

@ -10,7 +10,6 @@
export let componentInstance export let componentInstance
export let value export let value
export let type export let type
export let autofocus = false
$: form = findClosestMatchingComponent( $: form = findClosestMatchingComponent(
$currentAsset?.props, $currentAsset?.props,
@ -41,4 +40,4 @@
} }
</script> </script>
<Combobox on:change {value} {options} {autofocus} /> <Combobox on:change {value} {options} />

View File

@ -15,7 +15,6 @@
export let value = "" export let value = ""
export let maxIconsPerPage = 30 export let maxIconsPerPage = 30
export let autofocus = false
let searchTerm = "" let searchTerm = ""
let selectedLetter = "A" let selectedLetter = "A"
@ -118,7 +117,7 @@
</script> </script>
<div bind:this={buttonAnchor}> <div bind:this={buttonAnchor}>
<ActionButton on:click={dropdown.show} {autofocus}> <ActionButton on:click={dropdown.show}>
{displayValue} {displayValue}
</ActionButton> </ActionButton>
</div> </div>

View File

@ -10,7 +10,6 @@
export let componentInstance = {} export let componentInstance = {}
export let value = "" export let value = ""
export let placeholder export let placeholder
export let autofocus
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: datasource = getDatasourceForProvider($currentAsset, componentInstance) $: datasource = getDatasourceForProvider($currentAsset, componentInstance)
@ -32,10 +31,4 @@
} }
</script> </script>
<Multiselect <Multiselect {placeholder} value={boundValue} on:change={setValue} {options} />
{placeholder}
value={boundValue}
on:change={setValue}
{options}
{autofocus}
/>

View File

@ -4,8 +4,6 @@
readableToRuntimeBinding, readableToRuntimeBinding,
runtimeToReadableBinding, runtimeToReadableBinding,
} from "builderStore/dataBinding" } from "builderStore/dataBinding"
import { setContext } from "svelte"
import { store } from "builderStore"
export let label = "" export let label = ""
export let componentInstance = {} export let componentInstance = {}
@ -18,7 +16,6 @@
export let bindings = [] export let bindings = []
export let componentBindings = [] export let componentBindings = []
export let nested = false export let nested = false
export let autofocus = false
$: allBindings = getAllBindings(bindings, componentBindings, nested) $: allBindings = getAllBindings(bindings, componentBindings, nested)
$: safeValue = getSafeValue(value, props.defaultValue, allBindings) $: safeValue = getSafeValue(value, props.defaultValue, allBindings)
@ -63,28 +60,6 @@
? defaultValue ? defaultValue
: enriched : enriched
} }
setContext("builderFocus", {
clear: () => {
if (!$store?.builderFocus) {
return
}
store.update(state => {
const updatedFocus = $store?.builderFocus?.filter(focus => {
return (
focus.location === "component_settings" &&
focus.target !== componentInstance._id
)
})
if (updatedFocus?.length > 0) {
state.builderFocus = updatedFocus
} else {
delete state.builderFocus
}
return state
})
},
})
</script> </script>
<div class="property-control" data-cy={`setting-${key}`}> <div class="property-control" data-cy={`setting-${key}`}>
@ -107,7 +82,6 @@
{key} {key}
{type} {type}
{...props} {...props}
{autofocus}
/> />
</div> </div>
</div> </div>
@ -119,6 +93,13 @@
flex-direction: column; flex-direction: column;
justify-content: flex-start; justify-content: flex-start;
align-items: stretch; align-items: stretch;
padding: 4px 8px;
margin: -6px -10px;
border: 2px solid transparent;
border-radius: 4px;
}
.property-control.highlighted {
border-color: var(--spectrum-global-color-blue-400);
} }
.label { .label {
padding-bottom: var(--spectrum-global-dimension-size-65); padding-bottom: var(--spectrum-global-dimension-size-65);

View File

@ -4,7 +4,6 @@
export let value export let value
export let bindings export let bindings
export let autofocus
$: urlOptions = $store.screens $: urlOptions = $store.screens
.map(screen => screen.routing?.route) .map(screen => screen.routing?.route)
@ -17,5 +16,4 @@
on:change on:change
options={urlOptions} options={urlOptions}
appendBindingsAsOptions={false} appendBindingsAsOptions={false}
{autofocus}
/> />

View File

@ -1167,7 +1167,8 @@
{ {
"type": "boolean", "type": "boolean",
"label": "New Tab", "label": "New Tab",
"key": "openInNewTab" "key": "openInNewTab",
"required": true
}, },
{ {
"type": "select", "type": "select",
@ -1176,6 +1177,7 @@
"defaultValue": "M", "defaultValue": "M",
"showInBar": true, "showInBar": true,
"barStyle": "picker", "barStyle": "picker",
"required": true,
"options": [ "options": [
{ {
"label": "Small", "label": "Small",
@ -1196,7 +1198,8 @@
"label": "Color", "label": "Color",
"key": "color", "key": "color",
"showInBar": true, "showInBar": true,
"barSeparator": false "barSeparator": false,
"required": true
}, },
{ {
"type": "boolean", "type": "boolean",
@ -1205,7 +1208,8 @@
"showInBar": true, "showInBar": true,
"barIcon": "TagBold", "barIcon": "TagBold",
"barTitle": "Bold text", "barTitle": "Bold text",
"barSeparator": false "barSeparator": false,
"required": true
}, },
{ {
"type": "boolean", "type": "boolean",
@ -1214,7 +1218,8 @@
"showInBar": true, "showInBar": true,
"barIcon": "TagItalic", "barIcon": "TagItalic",
"barTitle": "Italic text", "barTitle": "Italic text",
"barSeparator": false "barSeparator": false,
"required": true
}, },
{ {
"type": "boolean", "type": "boolean",

View File

@ -5,26 +5,20 @@
const { styleable } = getContext("sdk") const { styleable } = getContext("sdk")
const component = getContext("component") const component = getContext("component")
$: focusSetting = $component.missingRequiredSettings?.[0] $: requiredSetting = $component.missingRequiredSettings?.[0]
</script> </script>
{#if $builderStore.inBuilder && focusSetting} {#if $builderStore.inBuilder && requiredSetting}
<div use:styleable={$component.styles}> <div use:styleable={$component.styles}>
<div class="component-placeholder"> <div class="component-placeholder">
<span> <span>
Add the <mark>{focusSetting?.label}</mark> setting to start using your component Add the <mark>{requiredSetting.label}</mark> setting to start using your
&nbsp; component &nbsp;
</span> </span>
<span <span
class="spectrum-Link" class="spectrum-Link"
on:click={() => { on:click={() => {
builderStore.actions.setFocus([ builderStore.actions.highlightSetting(requiredSetting.key)
{
location: "component_settings",
key: focusSetting.key,
target: $component.id,
},
])
}} }}
> >
Show me Show me

View File

@ -1,6 +1,5 @@
<script> <script>
import { getContext } from "svelte" import { getContext } from "svelte"
import Placeholder from "./Placeholder.svelte"
const { linkable, styleable, builderStore } = getContext("sdk") const { linkable, styleable, builderStore } = getContext("sdk")
const component = getContext("component") const component = getContext("component")
@ -80,11 +79,7 @@
{componentText} {componentText}
</div> </div>
{:else if $builderStore.inBuilder || componentText} {:else if $builderStore.inBuilder || componentText}
{#if !url && !text} {#if externalLink || openInNewTab}
<div use:styleable={{ ...$component.styles, empty: true }}>
<Placeholder />
</div>
{:else if externalLink || openInNewTab}
<a <a
{target} {target}
href={sanitizedUrl} href={sanitizedUrl}

View File

@ -76,9 +76,7 @@
{#if !formContext} {#if !formContext}
<Placeholder text="Form components need to be wrapped in a form" /> <Placeholder text="Form components need to be wrapped in a form" />
{:else if !fieldState} {:else if !fieldState}
{#if $builderStore.inBuilder} <Placeholder />
<Placeholder />
{/if}
{:else if schemaType && schemaType !== type && type !== "options"} {:else if schemaType && schemaType !== type && type !== "options"}
<Placeholder <Placeholder
text="This Field setting is the wrong data type for this component" text="This Field setting is the wrong data type for this component"

View File

@ -76,8 +76,8 @@ const createBuilderStore = () => {
} }
store.update(state => ({ ...state, editMode: enabled })) store.update(state => ({ ...state, editMode: enabled }))
}, },
setFocus: data => { highlightSetting: setting => {
window.parent.postMessage({ type: "builder-focus", data }) dispatchEvent("highlight-setting", { setting })
}, },
} }
return { return {