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