PR Feedback updates

This commit is contained in:
Dean 2023-05-31 11:26:03 +01:00
parent cd95df629e
commit 985c7eb56e
3 changed files with 46 additions and 19 deletions

View File

@ -77,7 +77,7 @@
// For handlebars only. // For handlebars only.
const bindStyle = new MatchDecorator({ const bindStyle = new MatchDecorator({
regexp: /{{[."#\-\w\s]*}}/g, regexp: /{{[."#\-\w\s\]\[]*}}/g,
decoration: () => { decoration: () => {
return Decoration.mark({ return Decoration.mark({
tag: "span", tag: "span",
@ -133,7 +133,7 @@
highlightSpecialChars(), highlightSpecialChars(),
autocompletion({ autocompletion({
override: [...completions], override: [...completions],
closeOnBlur: false, closeOnBlur: true,
icons: false, icons: false,
optionClass: () => "autocomplete-option", optionClass: () => "autocomplete-option",
}), }),
@ -148,7 +148,7 @@
keymap.of(buildKeymap()), keymap.of(buildKeymap()),
themeConfig.of([ themeConfig.of([
getDefaultTheme({ getDefaultTheme({
height, height: editorHeight,
resize, resize,
dark: isDark, dark: isDark,
}), }),
@ -181,6 +181,7 @@
}, },
{ {
scrollIntoView: true, scrollIntoView: true,
userEvent: "input.type",
} }
) )
view.dispatch(tr) view.dispatch(tr)
@ -213,6 +214,8 @@
}) })
} }
$: editorHeight = typeof height === "number" ? `${height}px` : height
// Init when all elements are ready // Init when all elements are ready
$: if (mounted && !isEditorInitialised) { $: if (mounted && !isEditorInitialised) {
isEditorInitialised = true isEditorInitialised = true
@ -229,7 +232,7 @@
editor.dispatch({ editor.dispatch({
effects: themeConfig.reconfigure([ effects: themeConfig.reconfigure([
getDefaultTheme({ getDefaultTheme({
height, height: editorHeight,
resize, resize,
dark: isDark, dark: isDark,
}), }),
@ -279,8 +282,6 @@
.code-editor :global(.autocomplete-option .cm-completionDetail) { .code-editor :global(.autocomplete-option .cm-completionDetail) {
background-color: var(--spectrum-global-color-gray-200); background-color: var(--spectrum-global-color-gray-200);
border-radius: var(--border-radius-s); border-radius: var(--border-radius-s);
padding: 2px 4px; padding: 4px 6px;
margin-left: 2px;
/* font-weight: 600; */
} }
</style> </style>

View File

@ -35,7 +35,7 @@ export const getDefaultTheme = opts => {
borderLeftColor: "var(--spectrum-alias-text-color)", borderLeftColor: "var(--spectrum-alias-text-color)",
}, },
"&": { "&": {
height: height ? `${height}px` : "", height: height ? `${height}` : "",
lineHeight: "1.3", lineHeight: "1.3",
border: border:
"var(--spectrum-alias-border-size-thin) solid var(--spectrum-alias-border-color)", "var(--spectrum-alias-border-size-thin) solid var(--spectrum-alias-border-color)",
@ -49,6 +49,7 @@ export const getDefaultTheme = opts => {
"& .cm-tooltip.cm-tooltip-autocomplete > ul": { "& .cm-tooltip.cm-tooltip-autocomplete > ul": {
fontFamily: fontFamily:
"var(--spectrum-alias-body-text-font-family, var(--spectrum-global-font-family-base))", "var(--spectrum-alias-body-text-font-family, var(--spectrum-global-font-family-base))",
maxHeight: "16em",
}, },
"& .cm-placeholder": { "& .cm-placeholder": {
color: "var(--spectrum-alias-text-color)", color: "var(--spectrum-alias-text-color)",
@ -62,6 +63,7 @@ export const getDefaultTheme = opts => {
"& .cm-completionDetail": { "& .cm-completionDetail": {
fontStyle: "unset", fontStyle: "unset",
textTransform: "uppercase", textTransform: "uppercase",
fontSize: "10px",
}, },
"& .info-bubble": { "& .info-bubble": {
fontSize: "var(--font-size-s)", fontSize: "var(--font-size-s)",
@ -145,7 +147,7 @@ export const buildSectionHeader = (type, sectionName, icon, rank) => {
} }
} }
export const helpersToCompletion = helpers => { export const helpersToCompletion = (helpers, mode) => {
const { type, name: sectionName, icon } = SECTIONS.HB_HELPER const { type, name: sectionName, icon } = SECTIONS.HB_HELPER
const helperSection = buildSectionHeader(type, sectionName, icon, 99) const helperSection = buildSectionHeader(type, sectionName, icon, 99)
@ -159,16 +161,19 @@ export const helpersToCompletion = helpers => {
type: "helper", type: "helper",
section: helperSection, section: helperSection,
detail: "FUNCTION", detail: "FUNCTION",
apply: (view, completion, from, to) => {
insertBinding(view, from, to, key, mode)
},
}) })
return acc return acc
}, []) }, [])
} }
export const getHelperCompletions = () => { export const getHelperCompletions = mode => {
const manifest = getManifest() const manifest = getManifest()
return Object.keys(manifest).reduce((acc, key) => { return Object.keys(manifest).reduce((acc, key) => {
acc = acc || [] acc = acc || []
return [...acc, ...helpersToCompletion(manifest[key])] return [...acc, ...helpersToCompletion(manifest[key], mode)]
}, []) }, [])
} }
@ -194,7 +199,7 @@ export const hbAutocomplete = baseCompletions => {
if (!bindingStart) { if (!bindingStart) {
return null return null
} }
// Accomodate spaces // Accommodate spaces
const match = bindingStart.text.match(/{{[\s]*/) const match = bindingStart.text.match(/{{[\s]*/)
const query = bindingStart.text.replace(match[0], "") const query = bindingStart.text.replace(match[0], "")
let filtered = bindingFilter(options, query) let filtered = bindingFilter(options, query)
@ -215,7 +220,7 @@ export const jsAutocomplete = baseCompletions => {
let options = baseCompletions || [] let options = baseCompletions || []
if (jsBinding) { if (jsBinding) {
// Accomodate spaces // Accommodate spaces
const match = jsBinding.text.match(/\$\("[\s]*/) const match = jsBinding.text.match(/\$\("[\s]*/)
const query = jsBinding.text.replace(match[0], "") const query = jsBinding.text.replace(match[0], "")
let filtered = bindingFilter(options, query) let filtered = bindingFilter(options, query)
@ -263,6 +268,7 @@ export const hbInsert = (value, from, to, text) => {
} else { } else {
parsedInsert = ` ${text} ` parsedInsert = ` ${text} `
} }
return parsedInsert return parsedInsert
} }
@ -296,6 +302,16 @@ export const insertBinding = (view, from, to, text, mode) => {
return return
} }
let bindingClosePattern = mode.name == "javascript" ? /[\s]*"\)/ : /[\s]*}}/
let sliced = view.state.doc?.toString().slice(to)
const rightBrace = sliced.match(bindingClosePattern)
let cursorPos = from + parsedInsert.length
if (rightBrace) {
cursorPos = from + parsedInsert.length + rightBrace[0].length
}
view.dispatch({ view.dispatch({
changes: { changes: {
from, from,
@ -303,7 +319,7 @@ export const insertBinding = (view, from, to, text, mode) => {
insert: parsedInsert, insert: parsedInsert,
}, },
selection: { selection: {
anchor: from + parsedInsert.length, anchor: cursorPos,
}, },
}) })
} }

View File

@ -195,10 +195,11 @@
completions={[ completions={[
hbAutocomplete([ hbAutocomplete([
...bindingCompletions, ...bindingCompletions,
...getHelperCompletions(), ...getHelperCompletions(editorMode),
]), ]),
]} ]}
placeholder="" placeholder=""
height="100%"
/> />
</div> </div>
<div class="binding-footer"> <div class="binding-footer">
@ -292,12 +293,13 @@
completions={[ completions={[
jsAutocomplete([ jsAutocomplete([
...bindingCompletions, ...bindingCompletions,
...getHelperCompletions(), ...getHelperCompletions(editorMode),
]), ]),
]} ]}
mode={EditorModes.JS} mode={EditorModes.JS}
bind:getCaretPosition bind:getCaretPosition
bind:insertAtPos bind:insertAtPos
height="100%"
/> />
</div> </div>
<div class="binding-footer"> <div class="binding-footer">
@ -349,6 +351,7 @@
</Button> </Button>
<Button <Button
cta cta
disabled={!valid}
on:click={() => { on:click={() => {
bindingDrawerActions.save() bindingDrawerActions.save()
}} }}
@ -419,12 +422,11 @@
width: 100%; width: 100%;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin-top: var(--spacing-m);
} }
.main-content { .main-content {
display: grid; display: grid;
grid-template-columns: 1fr; grid-template-columns: 1fr;
grid-template-rows: 270px; grid-template-rows: 315px;
} }
.main-content.binding-panel { .main-content.binding-panel {
grid-template-columns: 1fr 320px; grid-template-columns: 1fr 320px;
@ -436,11 +438,14 @@
} }
.editor { .editor {
padding: var(--spacing-xl); padding: var(--spacing-xl);
padding-bottom: 0px;
min-width: 0; min-width: 0;
display: flex;
flex-direction: column;
gap: var(--spacing-xl);
} }
.overlay-wrap { .overlay-wrap {
position: relative; position: relative;
flex: 1;
} }
.mode-overlay { .mode-overlay {
position: absolute; position: absolute;
@ -469,4 +474,9 @@
display: flex; display: flex;
gap: var(--spacing-l); gap: var(--spacing-l);
} }
.binding-drawer :global(.code-editor),
.binding-drawer :global(.code-editor > div) {
height: 100%;
}
</style> </style>