🚧 Working Map proxy
This commit is contained in:
parent
24e7d413f5
commit
abca8a809d
4 changed files with 27 additions and 9 deletions
20
lib/part.ts
20
lib/part.ts
|
@ -4,10 +4,27 @@ import { Snippet } from './snippet'
|
|||
import { Attributes } from './attributes'
|
||||
import { PointList } from './pointlist'
|
||||
|
||||
var pointProxy: any = {
|
||||
id: 'test',
|
||||
get: function(points, key: string, proxy: ProxyHandler<Map<any, any>>): Point {
|
||||
console.log(`getting ${key}`);
|
||||
return points.get(key);
|
||||
},
|
||||
set: function(points: Map<string, Point>, key: string, point: Point, proxy: ProxyHandler<Map<any, any>>) {
|
||||
console.log(arguments);
|
||||
console.log(`Args above. Setting ${key} to`, point);
|
||||
point.attributes.add('data-key', key);
|
||||
point.attributes.add('data-part', this.id);
|
||||
points.set(key, point);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export class Part {
|
||||
id: string;
|
||||
render: boolean;
|
||||
points: PointList = new PointList();
|
||||
points = new Proxy(new Map(), pointProxy);
|
||||
paths: { [index: string]: Path; } = {};
|
||||
snippets: { [index: string]: Snippet; } = {};
|
||||
attributes = new Attributes();
|
||||
|
@ -16,6 +33,7 @@ export class Part {
|
|||
constructor(id: string) {
|
||||
this.id = id;
|
||||
this.render = (id.substr(0,1) === '_') ? false : true;
|
||||
this.points = new Proxy(new Map(), pointProxy);
|
||||
this.points.origin = new Point(0,0);
|
||||
|
||||
return this;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Pattern } from '../pattern'
|
||||
import { Svg } from '../svg'
|
||||
import { Path } from '../path'
|
||||
import { Part } from '../part'
|
||||
import { Snippet } from '../snippet'
|
||||
import { Theme } from './theme';
|
||||
|
||||
|
@ -88,7 +89,7 @@ export class Designer extends Theme {
|
|||
decoratePoint(pointId: string, part: Part, svg: Svg): void {
|
||||
let point = part.points[pointId];
|
||||
point.attributes.add('id', svg.getUid());
|
||||
point.attributes.add('data-point', id);
|
||||
point.attributes.add('data-point', pointId);
|
||||
}
|
||||
|
||||
/** Decorares paths with extra info */
|
||||
|
@ -107,22 +108,23 @@ export class Designer extends Theme {
|
|||
decoratePath(pathId: string, part: Part, svg: Svg): void {
|
||||
let path = part.paths[pathId];
|
||||
if (!path.render) return false;
|
||||
let id: string;
|
||||
for (let op of path.ops) {
|
||||
switch(op.type) {
|
||||
case 'move':
|
||||
let id = svg.getUid();
|
||||
id = svg.getUid();
|
||||
part.snippets[id] = new Snippet(op.to, 'path-start-point', `Startpoint of path ${pathId}`);
|
||||
part.snippets[id].attributes.add('onmouseover', 'pointHover(evt)');
|
||||
part.snippets[id].attributes.add('id', svg.getUid());
|
||||
break;
|
||||
case 'line':
|
||||
let id = svg.getUid();
|
||||
id = svg.getUid();
|
||||
part.snippets[id] = new Snippet(op.to, 'path-point', `Line endpoint of path ${pathId}`);
|
||||
part.snippets[id].attributes.add('onmouseover', 'pointHover(evt)');
|
||||
part.snippets[id].attributes.add('id', svg.getUid());
|
||||
break;
|
||||
case 'curve':
|
||||
let id = svg.getUid();
|
||||
id = svg.getUid();
|
||||
part.snippets[id] = new Snippet(op.to, 'path-point', `Curve endpoint of path ${pathId}`);
|
||||
part.snippets[id].attributes.add('onmouseover', 'pointHover(evt)');
|
||||
part.snippets[id].attributes.add('id', svg.getUid());
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
"scripts": {
|
||||
"test": "mocha -r ts-node/register tests/*.test.js",
|
||||
"build": "tsc",
|
||||
"build-watch": "tsc -w",
|
||||
"run": "nodemon node dist/index.js",
|
||||
"run-watch": "nodemon node dist/index.js"
|
||||
"watch": "tsc -w"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue