external modules for behavior

This commit is contained in:
Kushan Joshi
2016-06-18 15:29:16 +05:30
parent f42736fb6c
commit 0939983515
16 changed files with 4707 additions and 65 deletions
-9
View File
@@ -44,7 +44,6 @@ $(BUILDJS_TARGETS): $(BUILDJS_SOURCES) build.js
MODULE_TARGETS = \
js/lib/id/index.js \
js/lib/id/behavior.js \
js/lib/id/modes.js \
js/lib/id/operations.js \
js/lib/id/presets.js \
@@ -63,10 +62,6 @@ js/lib/id/index.js: $(shell find modules/index.js -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD modules/index.js --no-strict -o $@
js/lib/id/behavior.js: $(shell find modules/behavior -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.behavior modules/behavior/index.js --no-strict -o $@
js/lib/id/modes.js: $(shell find modules/modes -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.modes modules/modes/index.js --no-strict -o $@
@@ -87,10 +82,6 @@ js/lib/id/services.js: $(shell find modules/services -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.services modules/services/index.js --no-strict -o $@
js/lib/id/svg.js: $(shell find modules/svg -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD.svg modules/svg/index.js --no-strict -o $@
js/lib/id/ui/index.js: $(shell find modules/ui -type f)
@rm -f $@
node_modules/.bin/rollup -f umd -n iD modules/ui/ui.js --no-strict -o $@
+1 -1
View File
@@ -34,9 +34,9 @@
<script src='js/lib/marked.js'></script>
<script src='js/id/id.js'></script>
<script src='js/lib/id/index.js'></script>
<script src='js/lib/id/behavior.js'></script>
<script src='js/lib/id/modes.js'></script>
<script src='js/lib/id/operations.js'></script>
<script src='js/lib/id/presets.js'></script>
+4629 -2
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -1,3 +1,4 @@
import { Browse } from '../modes/index';
import { Draw } from './draw';
export function AddWay(context) {
@@ -26,7 +27,7 @@ export function AddWay(context) {
context.map().dblclickEnable(true);
}, 1000);
context.enter(iD.modes.Browse(context));
context.enter(Browse(context));
};
addWay.tail = function(text) {
+2 -1
View File
@@ -1,3 +1,4 @@
import { cmd } from '../ui/core/index';
export function Copy(context) {
var keybinding = d3.keybinding('copy');
@@ -66,7 +67,7 @@ export function Copy(context) {
}
function copy() {
keybinding.on(iD.ui.cmd('⌘C'), doCopy);
keybinding.on(cmd('⌘C'), doCopy);
d3.select(document).call(keybinding);
return copy;
}
+3 -2
View File
@@ -1,3 +1,4 @@
import { prefixCSSProperty, prefixDOMProperty } from '../util/index';
/*
`iD.behavior.drag` is like `d3.behavior.drag`, with the following differences:
@@ -39,7 +40,7 @@ export function drag() {
};
};
var d3_event_userSelectProperty = iD.util.prefixCSSProperty('UserSelect'),
var d3_event_userSelectProperty = prefixCSSProperty('UserSelect'),
d3_event_userSelectSuppress = d3_event_userSelectProperty ?
function () {
var selection = d3.selection(),
@@ -134,7 +135,7 @@ export function drag() {
}
function drag(selection) {
var matchesSelector = iD.util.prefixDOMProperty('matchesSelector'),
var matchesSelector = prefixDOMProperty('matchesSelector'),
delegate = mousedown;
if (selector) {
+4 -3
View File
@@ -1,3 +1,4 @@
import { euclideanDistance, chooseEdge } from '../geo/index';
import { Edit } from './edit';
import { Hover } from './hover';
import { Tail } from './tail';
@@ -46,7 +47,7 @@ export function Draw(context) {
d3.select(window).on('mouseup.draw', function() {
var t2 = +new Date(),
p2 = point(),
dist = iD.geo.euclideanDistance(p1, p2);
dist = euclideanDistance(p1, p2);
element.on('mousemove.draw', mousemove);
d3.select(window).on('mouseup.draw', null);
@@ -92,7 +93,7 @@ export function Draw(context) {
mouse[1] > pad && mouse[1] < dims[1] - pad;
if (trySnap) {
var choice = iD.geo.chooseEdge(context.childNodes(d), context.mouse(), context.projection),
var choice = chooseEdge(context.childNodes(d), context.mouse(), context.projection),
edge = [d.nodes[choice.index - 1], d.nodes[choice.index]];
event.clickWay(choice.loc, edge);
} else {
@@ -110,7 +111,7 @@ export function Draw(context) {
function space() {
var currSpace = context.mouse();
if (cached.disableSpace && cached.lastSpace) {
var dist = iD.geo.euclideanDistance(cached.lastSpace, currSpace);
var dist = euclideanDistance(cached.lastSpace, currSpace);
if (dist > tolerance) {
cached.disableSpace = false;
}
+25 -20
View File
@@ -1,3 +1,8 @@
import { Node, Way } from '../core/index';
import { entitySelector } from '../util/index';
import { Browse, Select } from '../modes/index';
import { chooseEdge, edgeEqual } from '../geo/index';
import { AddEntity, AddVertex, MoveNode, AddMidpoint } from '../actions/index';
import { Draw } from './draw';
export function DrawWay(context, wayId, index, mode, baseGraph) {
@@ -10,21 +15,21 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
draw = Draw(context);
var startIndex = typeof index === 'undefined' ? way.nodes.length - 1 : 0,
start = iD.Node({loc: context.graph().entity(way.nodes[startIndex]).loc}),
end = iD.Node({loc: context.map().mouseCoordinates()}),
segment = iD.Way({
start = Node({loc: context.graph().entity(way.nodes[startIndex]).loc}),
end = Node({loc: context.map().mouseCoordinates()}),
segment = Way({
nodes: typeof index === 'undefined' ? [start.id, end.id] : [end.id, start.id],
tags: _.clone(way.tags)
});
var f = context[way.isDegenerate() ? 'replace' : 'perform'];
if (isArea) {
f(iD.actions.AddEntity(end),
iD.actions.AddVertex(wayId, end.id, index));
f(AddEntity(end),
AddVertex(wayId, end.id, index));
} else {
f(iD.actions.AddEntity(start),
iD.actions.AddEntity(end),
iD.actions.AddEntity(segment));
f(AddEntity(start),
AddEntity(end),
AddEntity(segment));
}
function move(datum) {
@@ -41,7 +46,7 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
mouse[1] > pad && mouse[1] < dims[1] - pad;
if (trySnap) {
loc = iD.geo.chooseEdge(context.childNodes(datum), context.mouse(), context.projection).loc;
loc = chooseEdge(context.childNodes(datum), context.mouse(), context.projection).loc;
}
}
@@ -49,17 +54,17 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
loc = context.map().mouseCoordinates();
}
context.replace(iD.actions.MoveNode(end.id, loc));
context.replace(MoveNode(end.id, loc));
}
function undone() {
finished = true;
context.enter(iD.modes.Browse(context));
context.enter(Browse(context));
}
function setActiveElements() {
var active = isArea ? [wayId, end.id] : [segment.id, start.id, end.id];
context.surface().selectAll(iD.util.entitySelector(active))
context.surface().selectAll(entitySelector(active))
.classed('active', true);
}
@@ -123,10 +128,10 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
var last = context.hasEntity(way.nodes[way.nodes.length - (isArea ? 2 : 1)]);
if (last && last.loc[0] === loc[0] && last.loc[1] === loc[1]) return;
var newNode = iD.Node({loc: loc});
var newNode = Node({loc: loc});
context.replace(
iD.actions.AddEntity(newNode),
AddEntity(newNode),
ReplaceTemporaryNode(newNode),
annotation);
@@ -141,13 +146,13 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
[way.nodes[0], way.nodes[1]];
// Avoid creating duplicate segments
if (!isArea && iD.geo.edgeEqual(edge, previousEdge))
if (!isArea && edgeEqual(edge, previousEdge))
return;
var newNode = iD.Node({ loc: loc });
var newNode = Node({ loc: loc });
context.perform(
iD.actions.AddMidpoint({ loc: loc, edge: edge}, newNode),
AddMidpoint({ loc: loc, edge: edge}, newNode),
ReplaceTemporaryNode(newNode),
annotation);
@@ -181,11 +186,11 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
if (context.hasEntity(wayId)) {
context.enter(
iD.modes.Select(context, [wayId])
Select(context, [wayId])
.suppressMenu(true)
.newFeature(true));
} else {
context.enter(iD.modes.Browse(context));
context.enter(Browse(context));
}
};
@@ -200,7 +205,7 @@ export function DrawWay(context, wayId, index, mode, baseGraph) {
}, 1000);
finished = true;
context.enter(iD.modes.Browse(context));
context.enter(Browse(context));
};
drawWay.tail = function(text) {
+5 -4
View File
@@ -1,9 +1,10 @@
import { stringQs, qsString } from '../util/index';
export function Hash(context) {
var s0 = null, // cached location.hash
lat = 90 - 1e-8; // allowable latitude range
var parser = function(map, s) {
var q = iD.util.stringQs(s);
var q = stringQs(s);
var args = (q.map || '').split('/').map(Number);
if (args.length < 3 || args.some(isNaN)) {
return true; // replace bogus hash
@@ -18,7 +19,7 @@ export function Hash(context) {
center = map.center(),
zoom = map.zoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)),
q = _.omit(iD.util.stringQs(location.hash.substring(1)), 'comment'),
q = _.omit(stringQs(location.hash.substring(1)), 'comment'),
newParams = {};
if (mode && mode.id === 'browse') {
@@ -36,7 +37,7 @@ export function Hash(context) {
'/' + center[0].toFixed(precision) +
'/' + center[1].toFixed(precision);
return '#' + iD.util.qsString(_.assign(q, newParams), true);
return '#' + qsString(_.assign(q, newParams), true);
};
function update() {
@@ -65,7 +66,7 @@ export function Hash(context) {
.on('hashchange.hash', hashchange);
if (location.hash) {
var q = iD.util.stringQs(location.hash.substring(1));
var q = stringQs(location.hash.substring(1));
if (q.id) context.zoomToEntity(q.id.split(',')[0], !q.map);
if (q.comment) context.storage('comment', q.comment);
hashchange();
+2 -1
View File
@@ -1,3 +1,4 @@
import { Entity } from '../core/index';
/*
The hover behavior adds the `.hover` class on mouseover to all elements to which
the identical datum is bound, and removes it on mouseout.
@@ -44,7 +45,7 @@ export function Hover() {
selection.selectAll('.hover-suppressed')
.classed('hover-suppressed', false);
if (target instanceof iD.Entity) {
if (target instanceof Entity) {
var selector = '.' + target.id;
if (target.type === 'relation') {
+8 -4
View File
@@ -1,3 +1,7 @@
import { Select } from '../modes/index';
import { Extent, pointInPolygon } from '../geo/index';
import { Lasso as uiLasso } from '../ui/core/index';
export function Lasso(context) {
var behavior = function(selection) {
@@ -18,7 +22,7 @@ export function Lasso(context) {
function mousemove() {
if (!lasso) {
lasso = iD.ui.Lasso(context);
lasso = uiLasso(context);
context.surface().call(lasso);
}
@@ -36,11 +40,11 @@ export function Lasso(context) {
var graph = context.graph(),
bounds = lasso.extent().map(context.projection.invert),
extent = iD.geo.Extent(normalize(bounds[0], bounds[1]));
extent = Extent(normalize(bounds[0], bounds[1]));
return _.map(context.intersects(extent).filter(function(entity) {
return entity.type === 'node' &&
iD.geo.pointInPolygon(context.projection(entity.loc), lasso.coordinates) &&
pointInPolygon(context.projection(entity.loc), lasso.coordinates) &&
!context.features().isHidden(entity, graph, entity.geometry(graph));
}), 'id');
}
@@ -56,7 +60,7 @@ export function Lasso(context) {
lasso.close();
if (ids.length) {
context.enter(iD.modes.Select(context, ids));
context.enter(Select(context, ids));
}
}
+13 -8
View File
@@ -1,3 +1,8 @@
import { Move as MoveMode } from '../modes/index';
import { Extent, pointInPolygon } from '../geo/index';
import { CopyEntities, ChangeTags, Move as MoveAction} from '../actions/index';
import { cmd } from '../ui/core/index';
export function Paste(context) {
var keybinding = d3.keybinding('paste');
@@ -24,18 +29,18 @@ export function Paste(context) {
var baseGraph = context.graph(),
mouse = context.mouse(),
projection = context.projection,
viewport = iD.geo.Extent(projection.clipExtent()).polygon();
viewport = Extent(projection.clipExtent()).polygon();
if (!iD.geo.pointInPolygon(mouse, viewport)) return;
if (!pointInPolygon(mouse, viewport)) return;
var extent = iD.geo.Extent(),
var extent = Extent(),
oldIDs = context.copyIDs(),
oldGraph = context.copyGraph(),
newIDs = [];
if (!oldIDs.length) return;
var action = iD.actions.CopyEntities(oldIDs, oldGraph);
var action = CopyEntities(oldIDs, oldGraph);
context.perform(action);
var copies = action.copies();
@@ -45,19 +50,19 @@ export function Paste(context) {
extent._extend(oldEntity.extent(oldGraph));
newIDs.push(newEntity.id);
context.perform(iD.actions.ChangeTags(newEntity.id, _.omit(newEntity.tags, omitTag)));
context.perform(ChangeTags(newEntity.id, _.omit(newEntity.tags, omitTag)));
}
// Put pasted objects where mouse pointer is..
var center = projection(extent.center()),
delta = [ mouse[0] - center[0], mouse[1] - center[1] ];
context.perform(iD.actions.Move(newIDs, delta, projection));
context.enter(iD.modes.Move(context, newIDs, baseGraph));
context.perform(MoveAction(newIDs, delta, projection));
context.enter(MoveMode(context, newIDs, baseGraph));
}
function paste() {
keybinding.on(iD.ui.cmd('⌘V'), doPaste);
keybinding.on(cmd('⌘V'), doPaste);
d3.select(document).call(keybinding);
return paste;
}
+8 -6
View File
@@ -1,3 +1,5 @@
import { Entity } from '../core/index';
import { Browse, Select as SelectMode } from '../modes/index';
export function Select(context) {
function keydown() {
if (d3.event && d3.event.shiftKey) {
@@ -18,25 +20,25 @@ export function Select(context) {
lasso = d3.select('#surface .lasso').node(),
mode = context.mode();
if (!(datum instanceof iD.Entity)) {
if (!(datum instanceof Entity)) {
if (!d3.event.shiftKey && !lasso && mode.id !== 'browse')
context.enter(iD.modes.Browse(context));
context.enter(Browse(context));
} else if (!d3.event.shiftKey && !lasso) {
// Avoid re-entering Select mode with same entity.
if (context.selectedIDs().length !== 1 || context.selectedIDs()[0] !== datum.id) {
context.enter(iD.modes.Select(context, [datum.id]));
context.enter(SelectMode(context, [datum.id]));
} else {
mode.suppressMenu(false).reselect();
}
} else if (context.selectedIDs().indexOf(datum.id) >= 0) {
var selectedIDs = _.without(context.selectedIDs(), datum.id);
context.enter(selectedIDs.length ?
iD.modes.Select(context, selectedIDs) :
iD.modes.Browse(context));
SelectMode(context, selectedIDs) :
Browse(context));
} else {
context.enter(iD.modes.Select(context, context.selectedIDs().concat([datum.id])));
context.enter(SelectMode(context, context.selectedIDs().concat([datum.id])));
}
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { setTransform } from '../util/index';
export function Tail() {
var text,
container,
@@ -21,7 +22,7 @@ export function Tail() {
var xoffset = ((d3.event.clientX + tooltipSize[0] + xmargin) > selectionSize[0]) ?
-tooltipSize[0] - xmargin : xmargin;
container.classed('left', xoffset > 0);
iD.util.setTransform(container, d3.event.clientX + xoffset, d3.event.clientY);
setTransform(container, d3.event.clientX + xoffset, d3.event.clientY);
}
function mouseleave() {
+3 -1
View File
@@ -1,5 +1,6 @@
import * as actions from './actions/index';
import * as geo from './geo/index';
import * as behavior from './behavior/index';
export { Connection } from './core/connection';
export { Difference } from './core/difference';
@@ -14,5 +15,6 @@ export { Way } from './core/way';
export {
actions,
geo
geo,
behavior
};
-1
View File
@@ -42,7 +42,6 @@
<script src='../js/id/id.js'></script>
<script src='../js/lib/id/index.js'></script>
<script src='../js/lib/id/behavior.js'></script>
<script src='../js/lib/id/modes.js'></script>
<script src='../js/lib/id/operations.js'></script>
<script src='../js/lib/id/presets.js'></script>