Skip to content

Commit

Permalink
changed all constructor names manually...
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianoNaraku committed Sep 14, 2023
1 parent 8700072 commit 546d613
Show file tree
Hide file tree
Showing 47 changed files with 417 additions and 163 deletions.
2 changes: 2 additions & 0 deletions sandbox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const a = 0;


/*
Expand Down
16 changes: 8 additions & 8 deletions src/api/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export class EcoreParser{
}

private static fixObjectPointers(parsedElements: DModelElement[]): void {
let dobjects: DObject[] = parsedElements.filter(e=>e.className === DObject.name) as any[];
let values: DValue[] = parsedElements.filter(e=>e.className === DValue.name) as any[];
let dobjects: DObject[] = parsedElements.filter(e=>e.className === DObject.cname) as any[];
let values: DValue[] = parsedElements.filter(e=>e.className === DValue.cname) as any[];
let lobjects: LObject[] = LPointerTargetable.fromArr(dobjects);
let m1pointermap: Dictionary<string, LObject> = { }; // "//@rootrefname.index@/refname.index/@....etc"
for (let o of lobjects){ m1pointermap[o.ecorePointer()] = o; }
Expand All @@ -209,7 +209,7 @@ export class EcoreParser{
private static tempfix_untilopennewtabisdone(parsedElements: DModelElement[], isMetamodel: boolean) {
// replaces current model with parsed model. this needs to be removed to open a new tab later on.
let model: DModel = null as any;
for (let elem of parsedElements) { if (elem.className === DModel.name) { model = elem as any; break; } }
for (let elem of parsedElements) { if (elem.className === DModel.cname) { model = elem as any; break; } }
SetRootFieldAction.new(isMetamodel ? "m2models" : "m1models", model.id, '+=', false); // it is pointer but no need to update pointedby's this time
}

Expand Down Expand Up @@ -276,7 +276,7 @@ export class EcoreParser{

if (replacekey === "extends") {
if (!target) continue;
Log.ex(target.className !== DClass.name, "found a class attempting to extend an object that is not a class", {target, dobj, replacePrimitiveMap, nameMap, idMap});
Log.ex(target.className !== DClass.cname, "found a class attempting to extend an object that is not a class", {target, dobj, replacePrimitiveMap, nameMap, idMap});
(target as DClass).extendedBy.push((dobj as DClass).id);
}
Log.ex(!target, "LinkAllNames() can't find type target:", {value, nameMap, replacePrimitiveMap, dobj, replacekey});
Expand All @@ -292,12 +292,12 @@ export class EcoreParser{
function DfromPtr<T extends DPointerTargetable>(id: Pointer<T>|null|undefined): T{ return !id ? undefined as any : (idMap[id] || idlookup[id]); }
function getLiteral(id: Pointer<DEnumerator>, ordinal: number): DEnumLiteral { return LPointerTargetable.fromD(DfromPtr(id))?.ordinals[ordinal]?.__raw; }
for (let elem of parsedElements) {
if (elem.className !== DValue.name) continue;
if (elem.className !== DValue.cname) continue;
let dval: DValue = elem as DValue;
let meta: DAttribute | DReference = DfromPtr(dval.instanceof as Pointer<DAttribute|DReference>);
if (!meta) continue;
let type: DEnumerator = DfromPtr(meta.type) as DEnumerator;
if (!type || type.className !== DEnumLiteral.name) continue;
if (!type || type.className !== DEnumLiteral.cname) continue;
let mapper = (v: unknown): Pointer<DEnumLiteral> => {
if (typeof v !== "number") { Log.e("found non-numeric value in a literal value.", v, dval); return v as any; }
let l = getLiteral(type.id, v);
Expand Down Expand Up @@ -537,7 +537,7 @@ export class EcoreParser{
generated.push(dValue); dValue.father = parent.id;
parent.features.push(dValue.id);
console.log("made dValue", {jsonvalues, dValue, meta, metaname: meta?.name});
if (meta && meta.className === DAttribute.name) { dValue.values = jsonvalues; return generated; }
if (meta && meta.className === DAttribute.cname) { dValue.values = jsonvalues; return generated; }

for (let v of jsonvalues) {
if (typeof v !== "object") { dValue.values.push(v); continue; }
Expand Down Expand Up @@ -837,7 +837,7 @@ export class EcoreParser{
return val; }

private static getEcoreTypeName(parent: DClassifier): string {
if (parent.className === DEnumerator.name || parent.className === DClass.name) return this.classTypePrefix + this.name;
if (parent.className === DEnumerator.cname || parent.className === DClass.cname) return this.classTypePrefix + this.name;
// return Type.classTypePrefix + parent.parent.name; problem: need L-object to navigate
return Log.ex("getEcoreTypeName failed", parent);
}
Expand Down
1 change: 1 addition & 0 deletions src/common/DV.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let ShortAttribETypes: typeof SAType = (window as any).ShortAttribETypes;

@RuntimeAccessible
export class DV {
static cname: string = "DV";
public static modelView(): string { return beautify(DefaultView.model()); } // damiano: che fa beautify? magari potremmo settarlo in LView.set_jsx invece che solo qui, così viene formattato anche l'input utente?
public static packageView(): string { return beautify(DefaultView.package()); }
public static classView(): string { return beautify(DefaultView.class()); }
Expand Down
13 changes: 10 additions & 3 deletions src/common/Geom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DPointerTargetable, RuntimeAccessible, windoww, Log, RuntimeAccessibleCl

@RuntimeAccessible
export abstract class IPoint extends RuntimeAccessibleClass {
static cname: string = "IPoint";
static subclasses: (typeof RuntimeAccessibleClass | string)[] = [];
static _extends: (typeof RuntimeAccessibleClass | string)[] = [];
public x!: number;
Expand Down Expand Up @@ -30,7 +31,7 @@ export abstract class IPoint extends RuntimeAccessibleClass {
if (y === null || y === undefined) thiss.y = undefined as Temporary;
else if (isNaN(+y)) { thiss.y = 0; }
else thiss.y = +y;
thiss.className = this.name;
thiss.className = this.cname;
}

public raw(): {x: number, y: number} { return {x: this.x, y: this.y}; }
Expand Down Expand Up @@ -178,6 +179,7 @@ export abstract class IPoint extends RuntimeAccessibleClass {

@RuntimeAccessible
export class GraphPoint extends IPoint{
static cname: string = "GraphPoint";
private dontmixwithPoint: any;
public static fromEvent(e: JQuery.ClickEvent | JQuery.MouseMoveEvent | JQuery.MouseUpEvent | JQuery.MouseDownEvent | JQuery.MouseEnterEvent | JQuery.MouseLeaveEvent | JQuery.MouseEventBase)
: GraphPoint | null {
Expand All @@ -194,6 +196,7 @@ export class GraphPoint extends IPoint{

@RuntimeAccessible
export class Point extends IPoint{
static cname: string = "Point";
private dontmixwithGPoint: any;
/// https://stackoverflow.com/questions/6073505/what-is-the-difference-between-screenx-y-clientx-y-and-pagex-y
public static fromEvent(e: JQuery.ClickEvent | JQuery.MouseMoveEvent | JQuery.MouseUpEvent | JQuery.MouseDownEvent | JQuery.MouseEnterEvent | JQuery.MouseLeaveEvent | JQuery.MouseEventBase)
Expand All @@ -209,6 +212,7 @@ RuntimeAccessibleClass.set_extend(IPoint, GraphPoint);
RuntimeAccessibleClass.set_extend(IPoint, Point);
@RuntimeAccessible
export abstract class ISize<PT extends IPoint = IPoint> extends RuntimeAccessibleClass {
static cname: string = "ISize";
static subclasses: (typeof RuntimeAccessibleClass | string)[] = [];
static _extends: (typeof RuntimeAccessibleClass | string)[] = [];
public x!: number;
Expand All @@ -225,7 +229,7 @@ export abstract class ISize<PT extends IPoint = IPoint> extends RuntimeAccessibl

static init_constructor(thiss: GObject, x: any = 0, y: any = 0, w: any = 0, h: any = 0, ...a: any): void {
thiss.id = "SIZE_" + (DPointerTargetable.maxID++) + "_" + new Date().getTime();
thiss.className = thiss.constructor.name;
thiss.className = (thiss.constructor as typeof RuntimeAccessibleClass).cname;
if (x === null || x === undefined) thiss.x = undefined as Temporary;
else if (isNaN(+x)) { thiss.x = 0; }
else thiss.x = +x;
Expand All @@ -238,7 +242,7 @@ export abstract class ISize<PT extends IPoint = IPoint> extends RuntimeAccessibl
if (h === null || h === undefined) thiss.h = undefined as Temporary;
else if (isNaN(+h)) { thiss.h = 0; }
else thiss.h = +h;
thiss.className = this.name; }
thiss.className = this.cname; }

public toString(letters: boolean=true, separator: string = " "): string {
if (letters) return JSON.stringify({x: this.x, y: this.y, w: this.w, h: this.h});
Expand Down Expand Up @@ -379,6 +383,7 @@ export abstract class ISize<PT extends IPoint = IPoint> extends RuntimeAccessibl

@RuntimeAccessible
export class Size extends ISize<Point> {
static cname: string = "Size";
static subclasses: any[] = [];
private static sizeofvar: HTMLElement;
private static $sizeofvar: JQuery<HTMLElement>;
Expand Down Expand Up @@ -437,6 +442,7 @@ export class Size extends ISize<Point> {

@RuntimeAccessible
export class GraphSize extends ISize<GraphPoint> {
static cname: string = "GraphSize";
private dontMixWithSize: any;

public static fromPoints(firstPt: GraphPoint, secondPt: GraphPoint): GraphSize {
Expand Down Expand Up @@ -637,6 +643,7 @@ RuntimeAccessibleClass.set_extend(ISize, Size);
RuntimeAccessibleClass.set_extend(ISize, GraphSize);
@RuntimeAccessible
export class Geom extends RuntimeAccessibleClass {
static cname: string = "Geom";

static isPositiveZero(m: number): boolean {
if (!!Object.is) { return Object.is(m, +0); }
Expand Down
34 changes: 24 additions & 10 deletions src/common/U.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
RuntimeAccessible,
Selectors,
TODO,
windoww
windoww, RuntimeAccessibleClass
} from "../joiner";
import Swal from "sweetalert2";
// import KeyDownEvent = JQuery.KeyDownEvent; // https://github.com/tombigel/detect-zoom broken 2013? but works
Expand All @@ -36,6 +36,7 @@ console.warn('loading ts U log');

@RuntimeAccessible
export class U {
static cname: string = "U";

public static getFromEnvironment(variable: string): string|number|boolean {
const value = process.env['REACT_APP_' + variable.toUpperCase()];
Expand Down Expand Up @@ -406,6 +407,8 @@ export class U {
if (scope) {
if (U.isStrict) {
for (let key in scope) {
key = key.trim();
if (!key) continue;
// anche se li assegno non cambiano i loro valori nel contesto fuori dall'eval, quindi lancio eccezioni con const.
prefixDeclarations += "const " + key + " = this." + key + "; ";
postfixDeclarations = "";
Expand All @@ -417,11 +420,17 @@ export class U {
}
if (scope && context) {
(context as any)._eval = _eval;
//console.log('pre eval jsx:', context, 'body:', {codeStr, Input: windoww.Input});
_ret = new (Function as any)(prefixDeclarations + "return eval( this._eval.codeStr );" + postfixDeclarations).call(context);
console.log('pre eval jsx SC:', context, 'body:', {codeStr, Input: windoww.Input, _eval,
f:prefixDeclarations + "return eval( " + codeStr + " );" + postfixDeclarations});
_ret = new (Function as any)(prefixDeclarations + "return eval( " + codeStr + " );" + postfixDeclarations).call(context);
delete (context as any)._eval; } else
if (!scope && context) { _ret = new (Function as any)( "return eval( this._eval._codeStr );").call(context); } else
if (!scope && context) {
console.log('pre eval jsx C:', context, 'body:', {codeStr, Input: windoww.Input, _eval,
f:new (Function as any)(prefixDeclarations + "return eval( this._eval.codeStr );" + postfixDeclarations)});
_ret = new (Function as any)( "return eval( this._eval._codeStr );").call(context); } else
if (scope && !context) {
console.log('pre eval jsx S:', context, 'body:', {codeStr, Input: windoww.Input, _eval,
f:new (Function as any)(prefixDeclarations + "return eval( this._eval.codeStr );" + postfixDeclarations)});
// NB: potrei creare lo scope con "let key = value;" per ogni chiave, ma dovrei fare json stringify e non è una serializzazione perfetta e può dare eccezioni(circolarità)
// console.log({isStrict: U.isStrict, eval: "eval(" + prefixDeclarations + codeStr + postfixDeclarations + ")"});
_ret = eval(prefixDeclarations + codeStr + postfixDeclarations); }
Expand Down Expand Up @@ -483,7 +492,7 @@ export class U {
private static evalContextFunction(code: string): any { eval(code); }
*/
public static highOrderFunctionExampleTyped<T extends (...args: any[]) => ReturnType<T>>(func: T): (...funcArgs: Parameters<T>) => ReturnType<T> {
const funcName = func.name;
const funcName = (func as any).cname || func.name;

// Return a new function that tracks how long the original took
return (...args: Parameters<T>): ReturnType<T> => {
Expand Down Expand Up @@ -681,7 +690,7 @@ export class U {
switch (typeof param) {
default: return typeof param;
case 'object':
return param?.constructor?.name || param?.className || "{_rawobject_}";
return (param?.constructor as typeof RuntimeAccessibleClass)?.cname || param?.className || "{_rawobject_}";
case 'function': // and others
return "geType for function todo: distinguish betweeen arrow and classic";
}
Expand Down Expand Up @@ -1084,6 +1093,7 @@ export class U {

}
export class DDate{
static cname: string = "DDate";

public static addDay(date: Date, offset: number, inplace: boolean): Date {
const ret: Date = inplace ? date : new Date(date);
Expand Down Expand Up @@ -1152,8 +1162,9 @@ export class myFileReader {
}

}

@RuntimeAccessible
export class Uarr{
static cname: string = "UArr";
public static arrayIntersection<T>(arr1: T[], arr2: T[]): T[]{
if (!arr1 || ! arr2) return null as any;
return arr1.filter( e => arr2.indexOf(e) >= 0);
Expand All @@ -1175,6 +1186,7 @@ export class Uarr{
}

export class FocusHistoryEntry {
static cname: string = "FocusHistoryEntry";
time: Date;
evt: JQuery.FocusInEvent;
element: Element;
Expand Down Expand Up @@ -1317,13 +1329,15 @@ export class ParseNumberOrBooleanOptions{

@RuntimeAccessible
export class Log{
static cname: string = "Log";
constructor() { }
// public static history: Dictionary<string, Dictionary<string, any[]>> = {}; // history['pe']['key'] = ...parameters
public static lastError: any[];
private static loggerMapping: Dictionary<string, LoggerInterface[]> = {} // takes function name returns logger list
public static registerLogger(logger: LoggerInterface, triggerAt: (typeof windoww.U.pe) & {name: string}) {
if (!Log.loggerMapping[triggerAt.name]) Log.loggerMapping[triggerAt.name] = [];
Log.loggerMapping[triggerAt.name].push(logger);
public static registerLogger(logger: LoggerInterface, triggerAt: (typeof windoww.U.pe) & {name: string, cname:string}) {
let tname: string = (triggerAt as any).cname || (triggerAt as any).name;
if (!Log.loggerMapping[tname]) Log.loggerMapping[tname] = [];
Log.loggerMapping[tname].push(logger);
}

static disableConsole(){
Expand Down
25 changes: 13 additions & 12 deletions src/common/UX.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
// U-functions that require jsx
@RuntimeAccessible
export class UX{
static cname: string = "UX";

static recursiveMap<T extends ReactNode | ReactNode[] | null | undefined>(children: T, fn: (rn: T, i: number, depthIndices: number[])=>T, depthIndices: number[] = []): T {
// NB: depthIndices is correct but if there is an expression children evaluated to false like {false && <jsx>},
Expand Down Expand Up @@ -55,9 +56,9 @@ export class UX{
// {'re.props.obj.id': re.props.obj?.id, 're.props.obj': re.props.obj, 'thiss.props.data.id': thiss.props.data.id, thiss, re, objid, ret, 'ret.props': ret.props});
return ret;*/
// case windoww.Components.GraphElement.name:
case windoww.Components.Input.name+"Component":
case windoww.Components.Select.name+"Component":
case windoww.Components.TextArea.name+"Component":
case windoww.Components.Input.cname+"Component":
case windoww.Components.Select.cname+"Component":
case windoww.Components.TextArea.cname+"Component":
// todo: can i do a injector that if the user provides a ModelElement list raw <div>{this.children}</div> it wraps them in DefaultNode?
const injectProps2: InputOwnProps | SelectOwnProps | TextAreaOwnProps = {} as any;
const parentnodeid = parentComponent.props.node?.id;
Expand All @@ -66,17 +67,17 @@ export class UX{
// but react needs to distinguish component A from other components, and he still doesn't have a key. in fact this is useless as this component can only have 1 child
injectProps2.key = re.props.key || (parentnodeid + "^input_"+index);
return React.cloneElement(re, injectProps2);
case windoww.Components.GraphElementComponent.name:
case windoww.Components.GraphElementComponent.cname:
// case windoww.Components.DefaultNode.name:
case windoww.Components.DefaultNodeComponent.name:
case windoww.Components.DefaultNodeComponent.cname:
// case windoww.Components.Graph.name:
// case windoww.Components.GraphComponent.name:
// case windoww.Components.GraphComponent.cname:
case "Graph": case "GraphComponent":
// case windoww.Components.Field.name:
// case windoww.Components.FieldComponent.name:
// case windoww.Components.FieldComponent.cname:
// case windoww.Components.Vertex.name:
case EdgeComponent.name:
case windoww.Components.VertexComponent.name:
case EdgeComponent.cname:
case windoww.Components.VertexComponent.cname:
const injectProps: GraphElementOwnProps = {} as any;
injectProps.parentViewId = parentComponent.props.view.id || (parentComponent.props.view as any); // re.props.view || thiss.props.view
injectProps.parentnodeid = parentComponent.props.node?.id;
Expand All @@ -94,10 +95,10 @@ export class UX{
default:
idbasename = injectProps.parentnodeid + "^" + dataid + "N";
break;
case windoww.Components.EdgePoint.name:
case windoww.Components.EdgePoint.cname:
idbasename = injectProps.parentnodeid + "^" + (dataid || re.props.startingSize?.id || indices.join(",")) + "EP";
break;
case EdgeComponent.name: case "DamEdge":
case EdgeComponent.cname: case "DamEdge":
let edgeProps:EdgeOwnProps = re.props;
let edgestart_id: Pointer<DGraphElement> | Pointer<DModelElement> = (edgeProps.start as any).id || edgeProps.start;
let edgeend_id: Pointer<DGraphElement> | Pointer<DModelElement> = (edgeProps.end as any).id || edgeProps.end;
Expand All @@ -111,7 +112,7 @@ export class UX{
injectProps.htmlindex = indices[indices.length - 1]; // re.props.node ? re.props.node.htmlindex : indices[indices.length - 1];
injectProps.key = re.props.key || injectProps.nodeid;
// console.log("cloning jsx:", re, injectProps);
Log.ex((injectProps.nodeid === injectProps.graphid||injectProps.nodeid === injectProps.parentnodeid) && type != "GraphComponent", "User manually assigned a invalid node id. please remove or change prop \"nodeid\"", {type: (re.type as any).WrappedComponent?.name || re.type}, {mycomponents: windoww.mycomponents, re, props:re.props});
Log.ex((injectProps.nodeid === injectProps.graphid||injectProps.nodeid === injectProps.parentnodeid) && type != "GraphComponent", "User manually assigned a invalid node id. please remove or change prop \"nodeid\"", {type: (re.type as any).WrappedComponent?.cname || re.type}, {mycomponents: windoww.mycomponents, re, props:re.props});
return React.cloneElement(re, injectProps);
}}

Expand Down
Loading

0 comments on commit 546d613

Please sign in to comment.