diff --git a/package.json b/package.json index 3726382..0b8176a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fiug/layout", - "version": "0.0.13", + "version": "0.0.14", "description": "page layout for browser applications", "main": "dist/layout.js", "exports": { diff --git a/src/events.js b/src/events.js index 4891d17..519d345 100644 --- a/src/events.js +++ b/src/events.js @@ -48,11 +48,12 @@ function follow(evt) { } let dragging = false; -let file; +let file, service; const dragStartMessage = (layout) => (e) => { - const { file: inputFile, source, dragStart, dragEnd, pointerId, pane, splitDirection } = JSON.parse(e.data); + const { file: inputFile, service: inputService, source, dragStart, dragEnd, pointerId, pane, splitDirection } = JSON.parse(e.data); //document.body.setPointerCapture(pointerId); file = inputFile || file; + service = inputService || service; if(dragStart){ dragging = true; @@ -70,7 +71,7 @@ const dragStartMessage = (layout) => (e) => { }[splitDirection]; const splitPane = document.getElementById(pane?.id); if(dir && splitPane){ - const editorFile = `?file=${file}`; + const editorFile = `?file=${file}&service=${service}`; const split = splitting.newPane(dir, splitPane, editorFile, layout); layout.onDrop({ type: "split", @@ -82,7 +83,7 @@ const dragStartMessage = (layout) => (e) => { } const tabbedPane = splitPane.classList.contains('tabbed'); if(!dir && tabbedPane){ - const editorFile = `/fiugd/beta/dist/editor.html?file=${file}`; + const editorFile = `?file=${file}&service=${service}`; layout.openTab({ pane: splitPane.id, file: editorFile @@ -160,6 +161,7 @@ export const dragStart = (ev, draggedEv) => { pointerId: ev.pointerId, dragStart: draggedEv.target.textContent, file: draggedEv.target.textContent, + service: draggedEv.service, source: location.href.split('/').pop() }); window.parent.postMessage(message, '*'); diff --git a/src/splitting.js b/src/splitting.js index 2db33fa..0b2ffdb 100644 --- a/src/splitting.js +++ b/src/splitting.js @@ -139,23 +139,20 @@ const addPane = (node, target, append, vertical, row, layout) => { }; export const newPane = (direction, node, target, layout) => { - try { - const row = node.parentNode.classList.contains('row'); - const column = node.parentNode.classList.contains('column'); - const horizontal = ["left", "right"].includes(direction); - const vertical = ["up", "down"].includes(direction); - const append = ["right", "down"].includes(direction); - - const operation = (() => { - if(column && horizontal) return addPane; - if(row && vertical) return addPane; - if(column && vertical) return split; - if(row && horizontal) return split; - })(); - if(!operation) return; - - return operation(node, target, append, vertical, row, layout); - } catch(e){ - debugger; - } + debugger; + const row = node.parentNode.classList.contains('row'); + const column = node.parentNode.classList.contains('column'); + const horizontal = ["left", "right"].includes(direction); + const vertical = ["up", "down"].includes(direction); + const append = ["right", "down"].includes(direction); + + const operation = (() => { + if(column && horizontal) return addPane; + if(row && vertical) return addPane; + if(column && vertical) return split; + if(row && horizontal) return split; + })(); + if(!operation) return; + + return operation(node, target, append, vertical, row, layout); }; diff --git a/src/state.js b/src/state.js index 9f91c35..be7f0b0 100644 --- a/src/state.js +++ b/src/state.js @@ -147,12 +147,16 @@ export const onDrop = (layout) => (args) => { file, height, width, tabbed, dragTo, pane, location, parent, sibling } = addedPane; + const siblingConfig = configFlat + .find(x => x.id === sibling); const parentConfig = configFlat .find(x => x.id === parent); const newPane = {}; if(!!width) newPane.width = width; if(!!height) newPane.height = height; - + if(siblingConfig?.module){ + newPane.module = siblingConfig.module; + } if(tabbed){ newPane.orient = "tabs"; newPane.id = pane; @@ -239,6 +243,7 @@ export const onDrop = (layout) => (args) => { } if(!splitPane && !addedPane) return; + debugger; layout.onChange(); }; diff --git a/src/utils.js b/src/utils.js index 6e5ed50..67548c1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -36,15 +36,14 @@ export function addParams(url, toAdd){ export const getFilename = (target="") => { const params = UrlParams(target); - const path = params.get('file'); - if(!path) return ""; + const path = params.get('file') || target; const filename = path.split("/").pop(); return filename; }; export const getFilepath = (target) => { const params = UrlParams(target); - const path = params.get('file'); + const path = params.get('file') || target; return path; };