-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
209 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
123 changes: 81 additions & 42 deletions
123
...ite9-server-java/src/main/resources/static/public/behaviours/labels/place/labels-place.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,101 @@ | ||
import { getMainSvg } from '/public/bundles/screen.js' | ||
import { parseStyle } from '/public/bundles/css.js' | ||
import { hasLastSelected, parseInfo, getContainingDiagram, reverseDirection, createUniqueId } from '/public/bundles/api.js' | ||
|
||
const PLACEMENTS = [ "top-left", "top", "top-right", "left", "none", "right", "bottom-left", "bottom", "bottom-right" ]; | ||
const STYLE_NAME = '--kite9-label-placement' | ||
|
||
export function labelableSelector() { | ||
const labelables = Array.from(getMainSvg().querySelectorAll("[k9-ui~=label].selected")); | ||
return labelables; | ||
function getPlacement(command, e) { | ||
const adlElement = command.getADLDom(e.getAttribute("id")); | ||
var style = parseStyle(adlElement.getAttribute("style")); | ||
var l = style[STYLE_NAME]; | ||
return l; | ||
} | ||
|
||
export function createPlaceLabelStep(e, templateUri, command) { | ||
const info = parseInfo(e); | ||
const end = info.end; | ||
const linkId = info.terminates ? info.terminates : e.getAttribute("id"); | ||
const newId = createUniqueId(); | ||
function drawPlacement(event, cm, placement, selected) { | ||
if (placement == null) { | ||
placement = "none"; | ||
} | ||
|
||
command.push({ | ||
"type": 'InsertUrl', | ||
"fragmentId": linkId, | ||
"uriStr": templateUri, | ||
"newId" : newId, | ||
}); | ||
var out = cm.addControl(event, "/public/behaviours/labels/place/" + placement.toLowerCase().replace("_","-") + ".svg", | ||
"placement (" + placement + ")", | ||
undefined); | ||
|
||
if (end) { | ||
command.push({ | ||
"type": "ReplaceAttr", | ||
"fragmentId": newId, | ||
"name": "end", | ||
"to" : end, | ||
"from" : e.getAttribute("end") | ||
}); | ||
var img = out.children[0]; | ||
|
||
if (selected == placement) { | ||
img.setAttribute("class", "selected"); | ||
} | ||
|
||
return img; | ||
} | ||
|
||
|
||
export function initPlaceLabelContextMenuCallback(command, templateUri, selector, action) { | ||
export function initPlaceLabelContextMenuCallback(placementProperty, command, selector) { | ||
|
||
if (selector == undefined) { | ||
selector = labelableSelector; | ||
} | ||
|
||
if (action == undefined) { | ||
action = createInsertLabelStep; | ||
selector = function () { | ||
return getMainSvg().querySelectorAll("[id][k9-ui~=place].selected"); | ||
} | ||
} | ||
|
||
/** | ||
* Provides a label option for the context menu | ||
* Provides a placement option for the context menu | ||
*/ | ||
return function(event, contextMenu) { | ||
|
||
const selectedElements = hasLastSelected(selector()); | ||
|
||
if (selectedElements.length > 0) { | ||
contextMenu.addControl(event, "/public/behaviours/labels/place/place.svg", "Add Label", | ||
function(e2, selector) { | ||
contextMenu.destroy(); | ||
selectedElements.forEach(e => action(e, templateUri, command)); | ||
command.perform(); | ||
} | ||
) | ||
return function (event, contextMenu) { | ||
|
||
const e = hasLastSelected(selector()); | ||
|
||
if (e.length> 0) { | ||
const ls = hasLastSelected(e, true); | ||
const placement = getPlacement(command, ls); | ||
var img = drawPlacement(event, contextMenu, placement); | ||
|
||
img.addEventListener("click", formEvent => { | ||
contextMenu.clear(); | ||
placementProperty.populateForm(formEvent, contextMenu, e); | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
export function initLabelPlacementPropertyFormCallback(command) { | ||
|
||
return function(propertyOwner, contextEvent, contextMenu, selectedElements) { | ||
const ls = hasLastSelected(selectedElements, true); | ||
const placement = getPlacement(command, ls); | ||
|
||
PLACEMENTS.forEach(s => { | ||
var img2 = drawPlacement(event, contextMenu, s, placement); | ||
if (placement != s) { | ||
img2.setAttribute("title", s); | ||
img2.addEventListener("click", (formEvent) => propertyOwner.setProperty(contextEvent, formEvent, contextMenu, selectedElements)); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export function initLabelPlacementPropertySetCallback(command) { | ||
|
||
return function(propertyOwner, contextEvent, formEvent, contextMenu, selectedElements) { | ||
|
||
const placement = formEvent.currentTarget.getAttribute("title"); | ||
selectedElements.forEach(e => { | ||
|
||
const existing = getPlacement(command, e); | ||
const id = e.getAttribute("id"); | ||
|
||
if (PLACEMENTS.includes(placement)) { | ||
command.push({ | ||
fragmentId: id, | ||
type: 'ReplaceStyle', | ||
name: STYLE_NAME, | ||
to: placement, | ||
from: getPlacement(command, e) | ||
}); | ||
} | ||
}); | ||
|
||
} | ||
} | ||
} | ||
|
File renamed without changes
5 changes: 5 additions & 0 deletions
5
...9-server-java/src/main/resources/static/public/behaviours/labels/place/none.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
server/kite9-server-java/src/main/resources/static/public/bundles/css.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** From: https://github.com/joshwnj/style-attr */ | ||
|
||
export function parseStyle(raw, opts) { | ||
opts = opts || {} | ||
raw = raw || "" | ||
|
||
var preserveNumbers = opts.preserveNumbers; | ||
var trim = function (s) { return s.trim(); }; | ||
var obj = {}; | ||
|
||
getKeyValueChunks(raw) | ||
.map(trim) | ||
.filter(Boolean) | ||
.forEach(function (item) { | ||
// split with `.indexOf` rather than `.split` because the value may also contain colons. | ||
var pos = item.indexOf(':'); | ||
var key = item.substr(0, pos).trim(); | ||
var val = item.substr(pos + 1).trim(); | ||
if (preserveNumbers && isNumeric(val)) { | ||
val = Number(val); | ||
} | ||
|
||
obj[key] = val; | ||
}); | ||
|
||
return obj; | ||
} | ||
|
||
function isNumeric(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
} | ||
|
||
function getKeyValueChunks(raw) { | ||
var chunks = []; | ||
var offset = 0; | ||
var sep = ';'; | ||
var hasUnclosedUrl = /url\([^\)]+$/; | ||
var chunk = ''; | ||
var nextSplit; | ||
while (offset < raw.length) { | ||
nextSplit = raw.indexOf(sep, offset); | ||
if (nextSplit === -1) { nextSplit = raw.length; } | ||
|
||
chunk += raw.substring(offset, nextSplit); | ||
|
||
// data URIs can contain semicolons, so make sure we get the whole thing | ||
if (hasUnclosedUrl.test(chunk)) { | ||
chunk += ';'; | ||
offset = nextSplit + 1; | ||
continue; | ||
} | ||
|
||
chunks.push(chunk); | ||
chunk = ''; | ||
offset = nextSplit + 1; | ||
} | ||
|
||
return chunks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
server/kite9-server-java/src/main/resources/static/public/templates/labels/labels.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.