From 86c9a37ef03991ded17d1336bde8da407bafe19e Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 17:42:55 -0400 Subject: [PATCH 01/18] add store currentLines based on currentBoxes --- src/cache.js | 12 ++ src/store/currentBoxes.js | 9 -- src/store/currentLines.js | 299 ++++++++++++++++++++++++++++++++++++++ src/store/currentSpace.js | 26 +++- src/store/history.js | 19 ++- src/store/store.js | 2 + src/utils.js | 2 +- 7 files changed, 350 insertions(+), 19 deletions(-) create mode 100644 src/store/currentLines.js diff --git a/src/cache.js b/src/cache.js index 9c0b398b9..9a252b782 100644 --- a/src/cache.js +++ b/src/cache.js @@ -178,6 +178,18 @@ export default { space.cacheDate = Date.now() this.storeLocal(`space-${spaceId}`, space) }, 200), + updateSpaceLinesDebounced: debounce(function (lines, spaceId) { + lines = utils.denormalizeItems(lines) + let space = this.space(spaceId) + if (!utils.objectHasKeys(space)) { + console.warn(updateErrorMessage) + return + } + lines = utils.denormalizeItems(lines) + space.lines = lines + space.cacheDate = Date.now() + this.storeLocal(`space-${spaceId}`, space) + }, 200), addToSpace ({ cards, connections, connectionTypes }, spaceId) { let space = this.space(spaceId) space.cards = space.cards || [] diff --git a/src/store/currentBoxes.js b/src/store/currentBoxes.js index ca5b86f93..7620ce930 100644 --- a/src/store/currentBoxes.js +++ b/src/store/currentBoxes.js @@ -369,7 +369,6 @@ export default { y: endCursor.y - prevCursor.y } let boxes = context.getters.isSelected - boxes = boxes.filter(box => !box.isLocked) boxes = boxes.filter(box => context.rootGetters['currentUser/canEditBox'](box)) // prevent boxes bunching up at 0 boxes.forEach(box => { @@ -483,14 +482,6 @@ export default { const boxes = boxIds.map(id => getters.byId(id)) return boxes }, - isNotLocked: (state, getters) => { - let boxes = getters.all - return boxes.filter(box => !box.isLocked) - }, - isLocked: (state, getters) => { - let boxes = getters.all - return boxes.filter(box => box.isLocked) - }, colors: (state, getters) => { const boxes = getters.all let colors = boxes.map(box => box.color) diff --git a/src/store/currentLines.js b/src/store/currentLines.js new file mode 100644 index 000000000..5a22e9b54 --- /dev/null +++ b/src/store/currentLines.js @@ -0,0 +1,299 @@ +// import utils from '@/utils.js' +import cache from '@/cache.js' +import utils from '@/utils.js' + +import { nanoid } from 'nanoid' +import randomColor from 'randomcolor' +import uniq from 'lodash-es/uniq' + +// normalized state +// https://github.com/vuejs/vuejs.org/issues/1636 + +let currentSpaceId +let prevMovePositions = {} + +export default { + namespaced: true, + state: { + ids: [], + lines: {} + }, + mutations: { + + // init + + clear: (state) => { + state.ids = [] + state.lines = {} + }, + restore: (state, lines) => { + let ids = [] + lines.forEach(line => { + ids.push(line.id) + state.lines[line.id] = line + }) + state.ids = state.ids.concat(ids) + }, + + // create + + create: (state, line) => { + state.ids.push(line.id) + state.lines[line.id] = line + cache.updateSpace('lines', state.lines, currentSpaceId) + }, + + // update + + update: (state, line) => { + const keys = Object.keys(line) + keys.forEach(key => { + state.lines[line.id][key] = line[key] + }) + cache.updateSpace('lines', state.lines, currentSpaceId) + }, + move: (state, { lines, spaceId }) => { + lines.forEach(line => { + state.lines[line.id].y = line.y + }) + cache.updateSpaceLinesDebounced(state.lines, currentSpaceId) + }, + + // broadcast + + moveWhileDraggingBroadcast: (state, { lines }) => { + lines.forEach(line => { + const element = document.querySelector(`.line[data-line-id="${line.id}"]`) + element.style.left = line.x + 'px' + element.style.top = line.y + 'px' + }) + }, + moveBroadcast: (state, { lines }) => { + lines.forEach(updated => { + const line = state.lines[updated.id] + if (!line) { return } + line.x = updated.x + line.y = updated.y + }) + cache.updateSpaceLinesDebounced(state.lines, currentSpaceId) + }, + + // remove + + remove: (state, lineToRemove) => { + if (!lineToRemove) { return } + const line = state.lines[lineToRemove.id] + if (!line) { return } + state.ids = state.ids.filter(id => id !== line.id) + delete state.lines[line.id] + cache.updateSpace('lines', state.lines, currentSpaceId) + } + }, + actions: { + + // init + + updateSpaceId: (context, spaceId) => { + currentSpaceId = spaceId + }, + mergeUnique: (context, { newItems, itemType }) => { + newItems.forEach(newLine => { + let shouldUpdate + let prevLine = context.getters.byId(newLine.id) + let line = { id: newLine.id } + let keys = Object.keys(newLine) + keys = keys.filter(key => key !== 'id') + keys.forEach(key => { + if (prevLine[key] !== newLine[key]) { + line[key] = newLine[key] + shouldUpdate = true + } + }) + if (!shouldUpdate) { return } + context.commit('update', line) + }) + }, + mergeRemove: (context, { removeItems, itemType }) => { + removeItems.forEach(line => { + context.commit('remove', line) + }) + }, + + // create + + add: (context, { line, shouldResize }) => { + const count = context.state.ids.length + const minLineSize = 70 + const isThemeDark = context.rootState.currentUser.theme === 'dark' + let color = randomColor({ luminosity: 'light' }) + if (isThemeDark) { + color = randomColor({ luminosity: 'dark' }) + } + line = { + id: line.id || nanoid(), + spaceId: currentSpaceId, + userId: context.rootState.currentUser.id, + y: line.y, + color: line.color || color, + fill: line.fill || 'filled', // empty, filled + name: line.name || `Line ${count}` + } + context.dispatch('history/add', { lines: [line] }, { root: true }) + context.commit('create', line) + context.dispatch('api/addToQueue', { name: 'createLine', body: line }, { root: true }) + context.dispatch('broadcast/update', { updates: line, type: 'createLine', handler: 'currentLines/create' }, { root: true }) + if (shouldResize) { + context.dispatch('history/pause', null, { root: true }) + context.commit('currentUserIsResizingLine', true, { root: true }) + context.commit('currentUserIsResizingLineIds', [line.id], { root: true }) + } + }, + + // update + + update: (context, line) => { + context.dispatch('history/add', { lines: [line] }, { root: true }) + context.commit('update', line) + context.dispatch('api/addToQueue', { name: 'updateLine', body: line }, { root: true }) + context.dispatch('broadcast/update', { updates: line, type: 'updateLine', handler: 'currentLines/update' }, { root: true }) + }, + updateName (context, { line, newName }) { + const canEditLine = context.rootGetters['currentUser/canEditLine'](line) + if (!canEditLine) { return } + context.dispatch('update', { + id: line.id, + name: newName + }) + }, + + // move + + move: (context, { endCursor, prevCursor, delta }) => { + const zoom = context.rootGetters.spaceCounterZoomDecimal + if (!endCursor || !prevCursor) { return } + endCursor = { + x: endCursor.x * zoom, + y: endCursor.y * zoom + } + delta = delta || { + x: endCursor.x - prevCursor.x, + y: endCursor.y - prevCursor.y + } + let lines = context.getters.isSelected + lines = lines.filter(line => context.rootGetters['currentUser/canEditLine'](line)) + // prevent lines bunching up at 0 + lines.forEach(line => { + if (!line) { return } + if (line.x === 0) { delta.x = Math.max(0, delta.x) } + if (line.y === 0) { delta.y = Math.max(0, delta.y) } + }) + lines = lines.filter(line => Boolean(line)) + // prevent lines with null or negative positions + lines = utils.clone(lines) + lines = lines.map(line => { + let position + if (prevMovePositions[line.id]) { + position = prevMovePositions[line.id] + } else { + position = utils.linePositionFromElement(line.id) + } + line.x = position.x + line.y = position.y + // x + if (line.x === undefined || line.x === null) { + delete line.x + } else { + line.x = Math.max(0, line.x + delta.x) + line.x = Math.round(line.x) + } + // y + if (line.y === undefined || line.y === null) { + delete line.y + } else { + line.y = Math.max(0, line.y + delta.y) + line.y = Math.round(line.y) + } + line = { + name: line.name, + x: line.x, + y: line.y, + id: line.id + } + prevMovePositions[line.id] = line + return line + }) + // update + context.commit('move', { lines }) + context.commit('linesWereDragged', true, { root: true }) + context.dispatch('broadcast/update', { updates: { lines }, type: 'moveLines', handler: 'currentLines/moveWhileDraggingBroadcast' }, { root: true }) + }, + afterMove: (context) => { + prevMovePositions = {} + const currentDraggingLineId = context.rootState.currentDraggingLineId + const spaceId = context.rootState.currentSpace.id + let lineIds = context.getters.isSelectedIds + lineIds = lineIds.filter(line => Boolean(line)) + if (!lineIds.length) { return } + let lines = lineIds.map(id => { + let line = context.getters.byId(id) + if (!line) { return } + line = utils.clone(line) + if (!line) { return } + const position = utils.linePositionFromElement(id) + line.x = position.x + line.y = position.y + const { x, y } = line + return { id, x, y } + }) + lines = lines.filter(line => Boolean(line)) + context.commit('move', { lines, spaceId }) + lines = lines.filter(line => line) + lines.forEach(line => { + context.dispatch('api/addToQueue', { + name: 'updateLine', + body: line + }, { root: true }) + }) + const line = context.getters.byId(currentDraggingLineId) + context.dispatch('broadcast/update', { updates: { lines }, type: 'moveLines', handler: 'currentLines/moveBroadcast' }, { root: true }) + context.dispatch('history/resume', null, { root: true }) + context.dispatch('history/add', { lines, useSnapshot: true }, { root: true }) + }, + + // remove + + remove: (context, line) => { + context.dispatch('api/addToQueue', { name: 'removeLine', body: line }, { root: true }) + context.dispatch('broadcast/update', { updates: line, type: 'removeLine', handler: 'currentLines/remove' }, { root: true }) + context.commit('remove', line) + context.dispatch('history/add', { lines: [line], isRemoved: true }, { root: true }) + } + }, + getters: { + byId: (state) => (id) => { + return state.lines[id] + }, + all: (state) => { + return state.ids.map(id => state.lines[id]) + }, + isSelectedIds: (state, getters, rootState, rootGetters) => { + const currentDraggingId = rootState.currentDraggingLineId + const multipleSelectedIds = rootState.multipleLinesSelectedIds + let lineIds = multipleSelectedIds.concat(currentDraggingId) + lineIds = uniq(lineIds) + lineIds = lineIds.filter(id => Boolean(id)) + return lineIds + }, + isSelected: (state, getters) => { + const lineIds = getters.isSelectedIds + const lines = lineIds.map(id => getters.byId(id)) + return lines + }, + colors: (state, getters) => { + const lines = getters.all + let colors = lines.map(line => line.color) + colors = colors.filter(color => Boolean(color)) + return uniq(colors) + } + } +} diff --git a/src/store/currentSpace.js b/src/store/currentSpace.js index 0b6974ff6..9d457c8ce 100644 --- a/src/store/currentSpace.js +++ b/src/store/currentSpace.js @@ -347,6 +347,7 @@ const currentSpace = { space.connections = [] space.cards = [] space.boxes = [] + space.lines = [] } else { space.connectionTypes[0].color = randomColor({ luminosity: 'light' }) space.cards[1].x = space.cards[1].x + random(0, 20) @@ -603,9 +604,9 @@ const currentSpace = { context.dispatch('currentConnections/updateSpaceId', space.id, { root: true }) context.dispatch('currentBoxes/updateSpaceId', space.id, { root: true }) }, - restoreSpaceInChunks: (context, { space, isRemote, addCards, addConnections, addConnectionTypes, addBoxes }) => { + restoreSpaceInChunks: (context, { space, isRemote, addCards, addConnections, addConnectionTypes, addBoxes, addLines }) => { if (!utils.objectHasKeys(space)) { return } - console.log('🌱 Restoring space', space, { 'isRemote': isRemote, addCards, addConnections, addConnectionTypes, addBoxes }) + console.log('🌱 Restoring space', space, { 'isRemote': isRemote, addCards, addConnections, addConnectionTypes, addBoxes, addLines }) const chunkSize = 50 const timeStart = utils.normalizeToUnixTime(new Date()) const origin = { x: window.scrollX, y: window.scrollY } @@ -617,6 +618,7 @@ const currentSpace = { cards = utils.normalizeItems(cards) connections = utils.normalizeItems(connections) let boxes = addBoxes || space.boxes || [] + let lines = addLines || space.lines || [] // sort cards const cardIds = Object.keys(cards) cards = cardIds.map(id => { @@ -646,6 +648,7 @@ const currentSpace = { context.commit('currentCards/clear', null, { root: true }) context.commit('currentConnections/clear', null, { root: true }) context.commit('currentBoxes/clear', null, { root: true }) + context.commit('currentLines/clear', null, { root: true }) context.dispatch('updateModulesSpaceId', space) } context.commit('isLoadingSpace', true, { root: true }) @@ -665,13 +668,14 @@ const currentSpace = { // restore space if (!primaryChunks.length) { context.commit('currentBoxes/restore', boxes, { root: true }) + context.commit('currentLines/restore', lines, { root: true }) context.dispatch('restoreSpaceComplete', { space, isRemote, timeStart }) return } - // restore types + // restore other items context.commit('currentConnections/restoreTypes', connectionTypes, { root: true }) - // restore boxes context.commit('currentBoxes/restore', boxes, { root: true }) + context.commit('currentLines/restore', lines, { root: true }) // restore chunks primaryChunks.forEach((chunk, index) => { defer(function () { @@ -708,10 +712,12 @@ const currentSpace = { let cards = context.rootState.currentCards.ids.length let connections = context.rootState.currentConnections.ids.length let boxes = context.rootState.currentBoxes.ids.length + let lines = context.rootState.currentLines.ids.length console.log(`${emoji} Restore space complete in ${timeEnd - timeStart}ms,`, { cards, connections, boxes, + lines, spaceName: space.name, isRemote, cardUsers: context.rootGetters['currentCards/userIds'] @@ -798,11 +804,17 @@ const currentSpace = { const boxResults = utils.mergeSpaceKeyValues({ prevItems: boxes, newItems: remoteSpace.boxes }) context.dispatch('currentBoxes/mergeUnique', { newItems: boxResults.updateItems, itemType: 'box' }, { root: true }) context.dispatch('currentBoxes/mergeRemove', { removeItems: boxResults.removeItems, itemType: 'box' }, { root: true }) + // lines + const lines = context.rootGetters['currentBoxes/all'] + const lineResults = utils.mergeSpaceKeyValues({ prevItems: lines, newItems: remoteSpace.lines }) + context.dispatch('currentBoxes/mergeUnique', { newItems: lineResults.updateItems, itemType: 'line' }, { root: true }) + context.dispatch('currentBoxes/mergeRemove', { removeItems: lineResults.removeItems, itemType: 'line' }, { root: true }) console.log('🎑 Merge space', { cards: cardResults, types: connectionTypeReults, connections: connectionResults, boxes: boxResults, + lines: lineResults, localSpace: space, space: remoteSpace }) @@ -812,7 +824,8 @@ const currentSpace = { addCards: cardResults.addItems, addConnectionTypes: connectionTypeReults.addItems, addConnections: connectionResults.addItems, - addBoxes: boxResults.addItems + addBoxes: boxResults.addItems, + addLines: lineResults.addItems }) }, loadLastSpace: async (context) => { @@ -1140,7 +1153,8 @@ const currentSpace = { itemColors: (state, getters, rootState, rootGetters) => { const cardColors = rootGetters['currentCards/colors'] const boxColors = rootGetters['currentBoxes/colors'] - const colors = cardColors.concat(boxColors) + const lineColors = rootGetters['currentLines/colors'] + const colors = cardColors.concat(boxColors).concat(lineColors) return uniq(colors) }, diff --git a/src/store/history.js b/src/store/history.js index d82ecc7d6..a40278364 100644 --- a/src/store/history.js +++ b/src/store/history.js @@ -74,7 +74,7 @@ const self = { patches: [], pointer: 0, isPaused: false, - snapshots: { cards: {}, connections: {}, connectionTypes: {}, boxes: {} } + snapshots: { cards: {}, connections: {}, connectionTypes: {}, boxes: {}, lines: {} } }, mutations: { add: (state, patch) => { @@ -140,7 +140,8 @@ const self = { const connections = utils.clone(context.rootState.currentConnections.connections) const connectionTypes = utils.clone(context.rootState.currentConnections.types) const boxes = utils.clone(context.rootState.currentBoxes.boxes) - context.commit('snapshots', { cards, connections, connectionTypes, boxes }) + const lines = utils.clone(context.rootState.currentLines.lines) + context.commit('snapshots', { cards, connections, connectionTypes, boxes, lines }) }, pause: (context) => { if (context.state.isPaused) { return } @@ -153,7 +154,7 @@ const self = { // Add Patch - add: (context, { cards, connections, connectionTypes, boxes, useSnapshot, isRemoved }) => { + add: (context, { cards, connections, connectionTypes, boxes, lines, useSnapshot, isRemoved }) => { if (context.state.isPaused) { return } let patch = [] // cards @@ -200,6 +201,18 @@ const self = { }) patch = patch.concat(boxes) } + // lines + if (lines) { + lines = lines.map(line => { + let previous = context.rootGetters['currentlines/byId'](line.id) + if (useSnapshot) { + previous = context.state.snapshots['lines'][line.id] + } + return normalizeUpdates({ item: line, itemType: 'line', previous, isRemoved }) + }) + patch = patch.concat(lines) + } + // all context.commit('add', patch) // context.commit('trim') }, diff --git a/src/store/store.js b/src/store/store.js index 1f38a458c..3b0d819be 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -12,6 +12,7 @@ import currentSpace from '@/store/currentSpace.js' import currentCards from '@/store/currentCards.js' import currentConnections from '@/store/currentConnections.js' import currentBoxes from '@/store/currentBoxes.js' +import currentLines from '@/store/currentLines.js' import upload from '@/store/upload.js' import userNotifications from '@/store/userNotifications.js' // store plugins @@ -1753,6 +1754,7 @@ const store = createStore({ currentCards, currentConnections, currentBoxes, + currentLines, upload, userNotifications }, diff --git a/src/utils.js b/src/utils.js index 462cd8bb6..1f4570f77 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1168,7 +1168,7 @@ export default { return space }, emptySpace (spaceId) { - return { id: spaceId, moonPhase: '', background: '', backgroundTint: '', cards: [], connections: [], connectionTypes: [], boxes: [], tags: [], users: [], userId: '', collaborators: [], spectators: [], clients: [], isHidden: false, visits: 0 } + return { id: spaceId, moonPhase: '', background: '', backgroundTint: '', cards: [], connections: [], connectionTypes: [], boxes: [], lines: [], tags: [], users: [], userId: '', collaborators: [], spectators: [], clients: [], isHidden: false, visits: 0 } }, clearSpaceMeta (space, type) { space.originSpaceId = space.id From a3d38777ce39cce11941c3b9d10a0b2b162d8322 Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 17:51:10 -0400 Subject: [PATCH 02/18] stub vertical segmented toolbar buttons --- src/App.vue | 31 +++++++++++++++---------------- src/components/Toolbar.vue | 4 +++- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/App.vue b/src/App.vue index 653dd99b4..52f7c8c05 100644 --- a/src/App.vue +++ b/src/App.vue @@ -739,22 +739,21 @@ dialog &:last-child border-top-right-radius var(--entity-radius) border-bottom-right-radius var(--entity-radius) - // &.vertical - // display flex - // flex-direction column - // .button-wrap - // button - // min-width 24px - // border-radius 0 - // margin-bottom -1px - // &:first-child - // button - // border-top-left-radius var(--small-entity-radius) - // border-top-right-radius var(--small-entity-radius) - // &:last-child - // button - // border-bottom-left-radius var(--small-entity-radius) - // border-bottom-right-radius var(--small-entity-radius) + &.vertical + display flex + flex-direction column + button + min-width 24px + border-radius 0 + margin-bottom -1px + &:first-child + border-top-left-radius var(--entity-radius) + border-top-right-radius var(--entity-radius) + &:last-child + border-bottom-left-radius var(--entity-radius) + border-bottom-right-radius var(--entity-radius) + button + button + margin-left 0 button + button, label + button, diff --git a/src/components/Toolbar.vue b/src/components/Toolbar.vue index e7721209f..ba10efed2 100644 --- a/src/components/Toolbar.vue +++ b/src/components/Toolbar.vue @@ -1,11 +1,13 @@ + - - From 10b266c13565d44d0cf00a9f98a198bf7979764d Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 18:34:21 -0400 Subject: [PATCH 06/18] revert box islocked --- src/store/currentBoxes.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/store/currentBoxes.js b/src/store/currentBoxes.js index 7620ce930..ca5b86f93 100644 --- a/src/store/currentBoxes.js +++ b/src/store/currentBoxes.js @@ -369,6 +369,7 @@ export default { y: endCursor.y - prevCursor.y } let boxes = context.getters.isSelected + boxes = boxes.filter(box => !box.isLocked) boxes = boxes.filter(box => context.rootGetters['currentUser/canEditBox'](box)) // prevent boxes bunching up at 0 boxes.forEach(box => { @@ -482,6 +483,14 @@ export default { const boxes = boxIds.map(id => getters.byId(id)) return boxes }, + isNotLocked: (state, getters) => { + let boxes = getters.all + return boxes.filter(box => !box.isLocked) + }, + isLocked: (state, getters) => { + let boxes = getters.all + return boxes.filter(box => box.isLocked) + }, colors: (state, getters) => { const boxes = getters.all let colors = boxes.map(box => box.color) From d6c6d63093d95831eed87f3cc6726d403d0d7945 Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 18:35:00 -0400 Subject: [PATCH 07/18] typo --- src/components/subsections/CardBoxActions.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/subsections/CardBoxActions.vue b/src/components/subsections/CardBoxActions.vue index d4a817248..b1848f30b 100644 --- a/src/components/subsections/CardBoxActions.vue +++ b/src/components/subsections/CardBoxActions.vue @@ -38,7 +38,7 @@ section.subsection.style-actions(v-if="visible" @click.left.stop="closeDialogs") //- Lock .button-wrap - button(:disabled="!canEditAll" @click="toggleIsLocked" :class="{active: isLocked}" title="Lock Card to Background") + button(:disabled="!canEditAll" @click="toggleIsLocked" :class="{active: isLocked}" title="Lock to Background") img.icon(src="@/assets/lock.svg") //- Comment .button-wrap(v-if="isCards") From bb57913d551d4097310106fe3a5d6d45a795c0c1 Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 18:47:08 -0400 Subject: [PATCH 08/18] typo --- src/store/history.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/history.js b/src/store/history.js index a40278364..178d389f0 100644 --- a/src/store/history.js +++ b/src/store/history.js @@ -204,7 +204,7 @@ const self = { // lines if (lines) { lines = lines.map(line => { - let previous = context.rootGetters['currentlines/byId'](line.id) + let previous = context.rootGetters['currentLines/byId'](line.id) if (useSnapshot) { previous = context.state.snapshots['lines'][line.id] } From 57baa33414885df21acabb5c3a2aa633f06f5953 Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 18:49:30 -0400 Subject: [PATCH 09/18] add isHorizontal for future use, stub add line --- src/components/Toolbar.vue | 2 +- src/store/currentLines.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Toolbar.vue b/src/components/Toolbar.vue index 7b8124cbb..96ab794f8 100644 --- a/src/components/Toolbar.vue +++ b/src/components/Toolbar.vue @@ -41,7 +41,7 @@ const toggleToolbar = (value) => { const addLine = () => { store.dispatch('closeAllDialogs') store.dispatch('clearMultipleSelected') - console.log('♥️♥️♥️♥️') + store.dispatch('currentLines/add', { y: 200 }) } diff --git a/src/store/currentLines.js b/src/store/currentLines.js index 5a22e9b54..1a51cff98 100644 --- a/src/store/currentLines.js +++ b/src/store/currentLines.js @@ -136,7 +136,8 @@ export default { y: line.y, color: line.color || color, fill: line.fill || 'filled', // empty, filled - name: line.name || `Line ${count}` + name: line.name || `Line ${count}`, + isHorizontal: line.isHorizontal || true } context.dispatch('history/add', { lines: [line] }, { root: true }) context.commit('create', line) From 69b463325e210cb5d222112b53473422b69e900e Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 18:52:08 -0400 Subject: [PATCH 10/18] cleanup, comment out currently unused line.x pieces --- src/store/currentLines.js | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/store/currentLines.js b/src/store/currentLines.js index 1a51cff98..ba9dce7d6 100644 --- a/src/store/currentLines.js +++ b/src/store/currentLines.js @@ -64,7 +64,7 @@ export default { moveWhileDraggingBroadcast: (state, { lines }) => { lines.forEach(line => { const element = document.querySelector(`.line[data-line-id="${line.id}"]`) - element.style.left = line.x + 'px' + // element.style.left = line.x + 'px' element.style.top = line.y + 'px' }) }, @@ -72,7 +72,7 @@ export default { lines.forEach(updated => { const line = state.lines[updated.id] if (!line) { return } - line.x = updated.x + // line.x = updated.x line.y = updated.y }) cache.updateSpaceLinesDebounced(state.lines, currentSpaceId) @@ -121,7 +121,7 @@ export default { // create - add: (context, { line, shouldResize }) => { + add: (context, line) => { const count = context.state.ids.length const minLineSize = 70 const isThemeDark = context.rootState.currentUser.theme === 'dark' @@ -135,7 +135,6 @@ export default { userId: context.rootState.currentUser.id, y: line.y, color: line.color || color, - fill: line.fill || 'filled', // empty, filled name: line.name || `Line ${count}`, isHorizontal: line.isHorizontal || true } @@ -143,11 +142,6 @@ export default { context.commit('create', line) context.dispatch('api/addToQueue', { name: 'createLine', body: line }, { root: true }) context.dispatch('broadcast/update', { updates: line, type: 'createLine', handler: 'currentLines/create' }, { root: true }) - if (shouldResize) { - context.dispatch('history/pause', null, { root: true }) - context.commit('currentUserIsResizingLine', true, { root: true }) - context.commit('currentUserIsResizingLineIds', [line.id], { root: true }) - } }, // update @@ -185,7 +179,7 @@ export default { // prevent lines bunching up at 0 lines.forEach(line => { if (!line) { return } - if (line.x === 0) { delta.x = Math.max(0, delta.x) } + // if (line.x === 0) { delta.x = Math.max(0, delta.x) } if (line.y === 0) { delta.y = Math.max(0, delta.y) } }) lines = lines.filter(line => Boolean(line)) @@ -198,15 +192,15 @@ export default { } else { position = utils.linePositionFromElement(line.id) } - line.x = position.x + // line.x = position.x line.y = position.y // x - if (line.x === undefined || line.x === null) { - delete line.x - } else { - line.x = Math.max(0, line.x + delta.x) - line.x = Math.round(line.x) - } + // if (line.x === undefined || line.x === null) { + // delete line.x + // } else { + // line.x = Math.max(0, line.x + delta.x) + // line.x = Math.round(line.x) + // } // y if (line.y === undefined || line.y === null) { delete line.y @@ -216,7 +210,6 @@ export default { } line = { name: line.name, - x: line.x, y: line.y, id: line.id } @@ -225,7 +218,7 @@ export default { }) // update context.commit('move', { lines }) - context.commit('linesWereDragged', true, { root: true }) + // context.commit('linesWereDragged', true, { root: true }) context.dispatch('broadcast/update', { updates: { lines }, type: 'moveLines', handler: 'currentLines/moveWhileDraggingBroadcast' }, { root: true }) }, afterMove: (context) => { @@ -241,10 +234,10 @@ export default { line = utils.clone(line) if (!line) { return } const position = utils.linePositionFromElement(id) - line.x = position.x + // line.x = position.x line.y = position.y - const { x, y } = line - return { id, x, y } + // const { x, y } = line + return { id, y: line.y } }) lines = lines.filter(line => Boolean(line)) context.commit('move', { lines, spaceId }) From 693f8180db08d6904ba60d69ae6d19e3af63a67c Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 23:07:43 -0400 Subject: [PATCH 11/18] draw lines --- src/components/Box.vue | 1 + src/components/Boxes.vue | 3 +- src/components/Line.vue | 88 +++++++++++++++++++++++++++++++ src/components/Lines.vue | 22 ++++++++ src/components/SelectAllBelow.vue | 1 + src/views/Space.vue | 3 ++ 6 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/components/Line.vue create mode 100644 src/components/Lines.vue diff --git a/src/components/Box.vue b/src/components/Box.vue index 0869d9f23..29de4495f 100644 --- a/src/components/Box.vue +++ b/src/components/Box.vue @@ -627,6 +627,7 @@ export default { min-height var(--min-box-size) min-width var(--min-box-size) pointer-events none + z-index -1 &.hover box-shadow var(--hover-shadow) &.active diff --git a/src/components/Boxes.vue b/src/components/Boxes.vue index 365aa3155..9b7774a6f 100644 --- a/src/components/Boxes.vue +++ b/src/components/Boxes.vue @@ -15,8 +15,7 @@ export default { }, computed: { isPainting () { return this.$store.state.currentUserIsPainting }, - unlockedBoxes () { return this.$store.getters['currentBoxes/isNotLocked'] }, - spaceZoomDecimal () { return this.$store.getters.spaceZoomDecimal } + unlockedBoxes () { return this.$store.getters['currentBoxes/isNotLocked'] } } } diff --git a/src/components/Line.vue b/src/components/Line.vue new file mode 100644 index 000000000..18ba28bff --- /dev/null +++ b/src/components/Line.vue @@ -0,0 +1,88 @@ + + + + + diff --git a/src/components/Lines.vue b/src/components/Lines.vue new file mode 100644 index 000000000..84e3a83ee --- /dev/null +++ b/src/components/Lines.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/src/components/SelectAllBelow.vue b/src/components/SelectAllBelow.vue index 460c20ffe..89b14b131 100644 --- a/src/components/SelectAllBelow.vue +++ b/src/components/SelectAllBelow.vue @@ -43,6 +43,7 @@ export default { if (this.$store.state.currentUserIsDraggingCard) { return } if (this.$store.state.currentUserIsDraggingBox) { return } if (this.$store.state.isEmbedMode) { return } + if (event.target.closest('.line')) { return } const edgeThreshold = 30 let header = document.querySelector('header').getBoundingClientRect().height let footer = document.querySelector('.footer-wrap footer') diff --git a/src/views/Space.vue b/src/views/Space.vue index 129d9214d..7741b1069 100644 --- a/src/views/Space.vue +++ b/src/views/Space.vue @@ -6,6 +6,7 @@ main#space.space( :style="styles" :data-zoom="spaceZoomDecimal" ) + Lines Connections(:startCursor="startCursor") Boxes Cards @@ -37,6 +38,7 @@ import ScrollAtEdgesHandler from '@/components/ScrollAtEdgesHandler.vue' import NotificationsWithPosition from '@/components/NotificationsWithPosition.vue' import BoxSelecting from '@/components/BoxSelecting.vue' import Boxes from '@/components/Boxes.vue' +import Lines from '@/components/Lines.vue' import Cards from '@/components/Cards.vue' import Connections from '@/components/Connections.vue' import LockedItemButtons from '@/components/LockedItemButtons.vue' @@ -64,6 +66,7 @@ export default { NotificationsWithPosition, BoxSelecting, Boxes, + Lines, Cards, LockedItemButtons, Connections, From 5767ca67d990671dd092a6682bb4ffbbda400847 Mon Sep 17 00:00:00 2001 From: pirijan Date: Sat, 19 Aug 2023 23:26:30 -0400 Subject: [PATCH 12/18] fix box click --- src/components/Box.vue | 1 - src/components/Line.vue | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Box.vue b/src/components/Box.vue index 29de4495f..0869d9f23 100644 --- a/src/components/Box.vue +++ b/src/components/Box.vue @@ -627,7 +627,6 @@ export default { min-height var(--min-box-size) min-width var(--min-box-size) pointer-events none - z-index -1 &.hover box-shadow var(--hover-shadow) &.active diff --git a/src/components/Line.vue b/src/components/Line.vue index 18ba28bff..49fa3468d 100644 --- a/src/components/Line.vue +++ b/src/components/Line.vue @@ -84,5 +84,6 @@ const horizontalLineStyles = computed(() => { .line-horizontal left 0 height 1px - // z-index -1 + z-index -1 + position relative From 9f2522401f3f0df75d9d0f3cc4b276d3dba9b12b Mon Sep 17 00:00:00 2001 From: pirijan Date: Sun, 20 Aug 2023 21:31:49 -0400 Subject: [PATCH 13/18] isSelectingAllBelow to global state --- src/components/Line.vue | 13 ++++++++++--- src/components/SelectAllBelow.vue | 16 ++++++++-------- src/store/store.js | 5 +++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/components/Line.vue b/src/components/Line.vue index 49fa3468d..5cb6b0a1e 100644 --- a/src/components/Line.vue +++ b/src/components/Line.vue @@ -12,14 +12,19 @@ const props = defineProps({ // styles const styles = computed(() => { - return { + let styles = { top: props.line.y + 'px' } + return styles }) const infoStyles = computed(() => { - return { + let styles = { backgroundColor: props.line.color } + if (store.state.isSelectingAllBelow) { + styles.pointerEvents = 'none' + } + return styles }) const horizontalLineStyles = computed(() => { return { @@ -31,7 +36,9 @@ const horizontalLineStyles = computed(() => {