Skip to content

Commit

Permalink
Merge f8781ec into 0ce7bf4
Browse files Browse the repository at this point in the history
  • Loading branch information
PIGNOSE committed Jun 17, 2018
2 parents 0ce7bf4 + f8781ec commit 520fc4d
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 39 deletions.
15 changes: 10 additions & 5 deletions dist/formulize.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/formulize.umd.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/types/formulize.interface.d.ts
Expand Up @@ -2,19 +2,24 @@
/// <reference types="mocha" />
/// <reference types="jquery" />
import { OptionText, PipeParse, PipeInsert } from './option.interface';
import { Tree } from 'metric-parser/dist/types/tree/simple.tree/type';
export * from 'metric-parser/dist/types/ast.d';
export * from 'metric-parser/dist/types/tree/simple.tree/type.d';
export interface FormulizeGlobal extends NodeJS.Global {
window: Window;
document: Document;
HTMLElement: typeof HTMLElement;
$: JQueryStatic;
jQuery: JQueryStatic;
}
export interface FormulizeOptions {
export interface FormulizeOptions extends FormulizeEventOptions {
id?: string;
text?: OptionText;
pipe?: OptionPipe;
}
export interface FormulizeEventOptions {
input?<T extends Tree>(value: T): void;
}
export interface OptionPipe {
insert?: PipeInsert;
parse?: PipeParse;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/formulize.plugin.method.d.ts
Expand Up @@ -6,7 +6,7 @@ export declare function methodBinder(this: JQuery, name: string, ...args: any[])
export declare class MethodBase implements FormulizePluginMethods {
protected formulize: UI;
constructor(formulize: UI);
pick(): void;
pick(position: Position): void;
clear(): void;
blur(): void;
setData(data: Tree): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/ui/ui.dom.d.ts
@@ -1,12 +1,12 @@
import { FormulizeOptions } from '../formulize.interface';
export declare abstract class UIDom {
options: Readonly<FormulizeOptions>;
protected wrapper: JQuery;
protected container: JQuery;
protected statusBox: JQuery;
protected textBox: JQuery;
protected cursor: JQuery;
protected elem: HTMLElement;
protected options: FormulizeOptions;
protected readonly cursorIndex: number;
protected readonly dragElem: JQuery;
protected initializeDOM(): void;
Expand Down
1 change: 1 addition & 0 deletions dist/types/ui/ui.interface.d.ts
Expand Up @@ -14,3 +14,4 @@ export interface Behavior {
doBehavior: () => any;
}
export declare type FormulizeData = string | number | HTMLElement | JQuery | any;
export declare type FormulizeEvent = 'input';
3 changes: 2 additions & 1 deletion dist/types/ui/ui.pipe.d.ts
@@ -1,6 +1,7 @@
import { UIAnalyzer } from './ui.analyzer';
import { FormulizeData } from './ui.interface';
import { FormulizeData, FormulizeEvent } from './ui.interface';
export declare class UIPipe extends UIAnalyzer {
protected pipeInsert(data: FormulizeData): any;
protected pipeParse(elem: HTMLElement): any;
protected pipeTrigger(name: FormulizeEvent, value: any): void;
}
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -68,6 +68,7 @@
"@types/jquery": "^3.3.2",
"@types/jsdom": "11.0.4",
"@types/mocha": "^5.2.2",
"@types/node": "^10.3.3",
"chai": "^4.1.2",
"coveralls": "^3.0.1",
"jquery": "^3.3.1",
Expand Down
8 changes: 7 additions & 1 deletion src/formulize.interface.ts
@@ -1,21 +1,27 @@
import { OptionText, PipeParse, PipeInsert } from './option.interface';
import { Tree } from 'metric-parser/dist/types/tree/simple.tree/type';

export * from 'metric-parser/dist/types/ast.d';
export * from 'metric-parser/dist/types/tree/simple.tree/type.d';

export interface FormulizeGlobal extends NodeJS.Global {
window: Window;
document: Document;
HTMLElement: typeof HTMLElement;
$: JQueryStatic;
jQuery: JQueryStatic;
}

export interface FormulizeOptions {
export interface FormulizeOptions extends FormulizeEventOptions {
id?: string;
text?: OptionText,
pipe?: OptionPipe
}

export interface FormulizeEventOptions {
input?<T extends Tree>(value: T): void
}

export interface OptionPipe {
insert?: PipeInsert;
parse?: PipeParse;
Expand Down
4 changes: 2 additions & 2 deletions src/formulize.plugin.method.ts
Expand Up @@ -24,8 +24,8 @@ export class MethodBase implements FormulizePluginMethods {
this.formulize = formulize;
}

pick(): void {
this.formulize.pick();
pick(position: Position): void {
this.formulize.pick(position);
}

clear(): void {
Expand Down
4 changes: 1 addition & 3 deletions src/ui/ui.dom.ts
@@ -1,16 +1,14 @@
import { FormulizeOptions } from '../formulize.interface';
import { defaultOptions } from '../option.value';
import { UIElementHelper } from './ui.element.helper';
import { FormulizeTokenHelper } from '../token.helper';

export abstract class UIDom {
public options: Readonly<FormulizeOptions>;
protected wrapper: JQuery;
protected container: JQuery;
protected statusBox: JQuery;
protected textBox: JQuery;
protected cursor: JQuery;
protected elem: HTMLElement;
protected options: FormulizeOptions;

protected get cursorIndex(): number {
return this.cursor
Expand Down
2 changes: 2 additions & 0 deletions src/ui/ui.interface.ts
Expand Up @@ -17,3 +17,5 @@ export interface Behavior {
}

export type FormulizeData = string | number | HTMLElement | JQuery | any;

export type FormulizeEvent = 'input';
6 changes: 2 additions & 4 deletions src/ui/ui.manager.ts
Expand Up @@ -5,7 +5,6 @@ import { UIElementHelper } from './ui.element.helper';
import { ElementPosition, FormulizeData, Position } from './ui.interface';
import { UIHelper } from './ui.helper';
import { UIPipe } from './ui.pipe';
import { ParseData } from 'metric-parser/dist/types/parser/parser';

export abstract class UIManager extends UIPipe {
protected prevCursorIndex = 0;
Expand Down Expand Up @@ -46,8 +45,7 @@ export abstract class UIManager extends UIPipe {

protected triggerUpdate(): void {
this.validate();
$(this.elem)
.triggerHandler(`${this.options.id}.input`, this.getData());
this.pipeTrigger('input', this.getData());
}

private getExpression(): FormulizeData[] {
Expand Down Expand Up @@ -123,7 +121,7 @@ export abstract class UIManager extends UIPipe {
diff: { x: diffX, y: diffY }
};
})
.filter(unitPosition => !!unitPosition);
.filter(unitPosition => unitPosition);;
const maxY = Math.max(...closestUnitPositions.map(unitPosition => unitPosition.y));
const filteredUnitPositions = closestUnitPositions.filter(unitPosition => unitPosition.y === maxY).length
? closestUnitPositions.filter(unitPosition => unitPosition.y === maxY)
Expand Down
9 changes: 8 additions & 1 deletion src/ui/ui.pipe.ts
@@ -1,5 +1,5 @@
import { UIAnalyzer } from './ui.analyzer';
import { FormulizeData } from './ui.interface';
import { FormulizeData, FormulizeEvent } from './ui.interface';
import { UIHelper } from './ui.helper';

export class UIPipe extends UIAnalyzer {
Expand All @@ -20,4 +20,11 @@ export class UIPipe extends UIAnalyzer {

return this.options.pipe.parse(elem);
}

protected pipeTrigger(name: FormulizeEvent, value: any): void {
$(this.elem).triggerHandler(`${this.options.id}.${name}`, value);
const eventPipe: Function = (<any>this.options)[name];
if (eventPipe)
eventPipe(value);
}
}

0 comments on commit 520fc4d

Please sign in to comment.