From b43a151d174a70fc5f27a647665e29eac5541a05 Mon Sep 17 00:00:00 2001 From: Misode Date: Sat, 3 Jul 2021 01:12:54 +0200 Subject: [PATCH] Add buttons to move element order in a list --- src/app/schema/Octicon.ts | 2 ++ src/app/schema/renderHtml.ts | 16 ++++++++++++++-- src/styles/nodes.css | 23 ++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/app/schema/Octicon.ts b/src/app/schema/Octicon.ts index b9b97989..5d5d08aa 100644 --- a/src/app/schema/Octicon.ts +++ b/src/app/schema/Octicon.ts @@ -1,4 +1,6 @@ export const Octicon = { + chevron_down: '', + chevron_up: '', clippy: '', info: '', issue_opened: '', diff --git a/src/app/schema/renderHtml.ts b/src/app/schema/renderHtml.ts index a982e279..d0d38f42 100644 --- a/src/app/schema/renderHtml.ts +++ b/src/app/schema/renderHtml.ts @@ -88,7 +88,15 @@ export const renderHtml: Hook<[any, TreeProps], [string, string, string]> = { let body = '' if (Array.isArray(value)) { body = value.map((childValue, index) => { - const removeId = props.mounter.onClick(() => path.model.set(path.push(index), undefined)) + const onRemove = props.mounter.onClick(() => path.model.set(path.push(index), undefined)) + const onMoveUp = props.mounter.onClick(() => { + [value[index - 1], value[index]] = [value[index], value[index - 1]] + path.model.set(path, value) + }) + const onMoveDown = props.mounter.onClick(() => { + [value[index + 1], value[index]] = [value[index], value[index + 1]] + path.model.set(path, value) + }) const childPath = path.push(index).contextPush('entry') const category = children.category(childPath) const [cPrefix, cSuffix, cBody] = children.hook(this, childPath, childValue, props) @@ -96,7 +104,11 @@ export const renderHtml: Hook<[any, TreeProps], [string, string, string]> = {
${error(props.loc, childPath, props.mounter)} ${help(props.loc, childPath, props.mounter)} - + + ${value.length <= 1 ? '' : `
+ + +
`} ${cPrefix}