General fixes for bindings and the undo/redo behaviour

This commit is contained in:
Dean 2023-07-18 16:46:35 +01:00
parent eb7d883ce2
commit e77a105bb2
10 changed files with 35 additions and 13 deletions

View File

@ -30,6 +30,7 @@
setContext("drawer-actions", { setContext("drawer-actions", {
hide, hide,
show, show,
headless,
}) })
const easeInOutQuad = x => { const easeInOutQuad = x => {

View File

@ -1,6 +1,7 @@
<script> <script>
import { Label } from "@budibase/bbui" import { Label } from "@budibase/bbui"
import { onMount, createEventDispatcher } from "svelte" import { onMount, createEventDispatcher } from "svelte"
import { FIND_ANY_HBS_REGEX } from "@budibase/string-templates"
import { import {
autocompletion, autocompletion,
@ -78,7 +79,7 @@
// For handlebars only. // For handlebars only.
const bindStyle = new MatchDecorator({ const bindStyle = new MatchDecorator({
regexp: /{{[."#\-\w\s\][]*}}/g, regexp: FIND_ANY_HBS_REGEX,
decoration: () => { decoration: () => {
return Decoration.mark({ return Decoration.mark({
tag: "span", tag: "span",

View File

@ -1,6 +1,7 @@
<script> <script>
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
import { onMount } from "svelte" import { onMount } from "svelte"
import { isBuilderInputFocused } from "helpers"
export let store export let store
@ -8,9 +9,16 @@
if (!(e.ctrlKey || e.metaKey)) { if (!(e.ctrlKey || e.metaKey)) {
return return
} }
if (e.shiftKey && e.key === "Z") {
let keyLowerCase = e.key.toLowerCase()
// Ignore events when typing
if (isBuilderInputFocused(e)) {
return
}
if (e.shiftKey && keyLowerCase === "z") {
store.redo() store.redo()
} else if (e.key === "z") { } else if (keyLowerCase === "z") {
store.undo() store.undo()
} }
} }

View File

@ -339,7 +339,7 @@
</Tab> </Tab>
{/if} {/if}
<div class="drawer-actions"> <div class="drawer-actions">
{#if drawerActions?.hide} {#if typeof drawerActions.hide === "function" && drawerActions.headless}
<Button <Button
secondary secondary
quiet quiet
@ -350,7 +350,7 @@
Cancel Cancel
</Button> </Button>
{/if} {/if}
{#if bindingDrawerActions?.save} {#if typeof bindingDrawerActions?.save === "function" && drawerActions.headless}
<Button <Button
cta cta
disabled={!valid} disabled={!valid}

View File

@ -29,3 +29,15 @@ export const lowercase = s => s.substring(0, 1).toLowerCase() + s.substring(1)
export const get_name = s => (!s ? "" : last(s.split("/"))) export const get_name = s => (!s ? "" : last(s.split("/")))
export const get_capitalised_name = name => pipe(name, [get_name, capitalise]) export const get_capitalised_name = name => pipe(name, [get_name, capitalise])
export const isBuilderInputFocused = e => {
const activeTag = document.activeElement?.tagName.toLowerCase()
const inCodeEditor = document.activeElement?.classList?.contains("cm-content")
if (
(inCodeEditor || ["input", "textarea"].indexOf(activeTag) !== -1) &&
e.key !== "Escape"
) {
return true
}
return false
}

View File

@ -7,4 +7,5 @@ export {
get_name, get_name,
get_capitalised_name, get_capitalised_name,
lowercase, lowercase,
isBuilderInputFocused,
} from "./helpers" } from "./helpers"

View File

@ -5,6 +5,7 @@
import { goto, isActive } from "@roxi/routify" import { goto, isActive } from "@roxi/routify"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { isBuilderInputFocused } from "helpers"
let confirmDeleteDialog let confirmDeleteDialog
let confirmEjectDialog let confirmEjectDialog
@ -100,13 +101,7 @@
return return
} }
// Ignore events when typing // Ignore events when typing
const activeTag = document.activeElement?.tagName.toLowerCase() if (isBuilderInputFocused(e)) {
const inCodeEditor =
document.activeElement?.classList?.contains("cm-content")
if (
(inCodeEditor || ["input", "textarea"].indexOf(activeTag) !== -1) &&
e.key !== "Escape"
) {
return return
} }
// Key events are always for the selected component // Key events are always for the selected component

View File

@ -18,6 +18,7 @@ module.exports.doesContainString = templates.doesContainString
module.exports.disableEscaping = templates.disableEscaping module.exports.disableEscaping = templates.disableEscaping
module.exports.findHBSBlocks = templates.findHBSBlocks module.exports.findHBSBlocks = templates.findHBSBlocks
module.exports.convertToJS = templates.convertToJS module.exports.convertToJS = templates.convertToJS
module.exports.FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
if (!process.env.NO_JS) { if (!process.env.NO_JS) {
const { VM } = require("vm2") const { VM } = require("vm2")
@ -28,7 +29,7 @@ if (!process.env.NO_JS) {
setJSRunner((js, context) => { setJSRunner((js, context) => {
const vm = new VM({ const vm = new VM({
sandbox: context, sandbox: context,
timeout: 1000 timeout: 1000,
}) })
return vm.run(js) return vm.run(js)
}) })

View File

@ -389,3 +389,5 @@ module.exports.convertToJS = hbs => {
js += "`;" js += "`;"
return `${varBlock}${js}` return `${varBlock}${js}`
} }
module.exports.FIND_ANY_HBS_REGEX = FIND_ANY_HBS_REGEX

View File

@ -20,6 +20,7 @@ export const doesContainString = templates.doesContainString
export const disableEscaping = templates.disableEscaping export const disableEscaping = templates.disableEscaping
export const findHBSBlocks = templates.findHBSBlocks export const findHBSBlocks = templates.findHBSBlocks
export const convertToJS = templates.convertToJS export const convertToJS = templates.convertToJS
export const FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
if (process && !process.env.NO_JS) { if (process && !process.env.NO_JS) {
/** /**