@visactor/vgrammar-core 0.11.0 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/graph/canvas-renderer.js +3 -1
- package/cjs/graph/canvas-renderer.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/interactions/utils.js +1 -1
- package/cjs/interactions/utils.js.map +1 -1
- package/cjs/types/grammar.d.ts +1 -0
- package/cjs/types/grammar.js.map +1 -1
- package/cjs/view/View.js +18 -13
- package/cjs/view/View.js.map +1 -1
- package/cjs/view/grammar-base.d.ts +1 -1
- package/cjs/view/grammar-base.js.map +1 -1
- package/es/graph/canvas-renderer.js +3 -1
- package/es/graph/canvas-renderer.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/interactions/utils.js +1 -1
- package/es/interactions/utils.js.map +1 -1
- package/es/types/grammar.d.ts +1 -0
- package/es/types/grammar.js.map +1 -1
- package/es/view/View.js +17 -13
- package/es/view/View.js.map +1 -1
- package/es/view/grammar-base.d.ts +1 -1
- package/es/view/grammar-base.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/view/grammar-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,IAAI,aAAa,GAAG,CAAC,CAAC,CAAC;AAEvB,MAAM,OAAgB,WAAY,SAAQ,YAAY;IAkBpD,YAAY,IAAW;QACrB,KAAK,EAAE,CAAC;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IACnB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAES,eAAe,CAAI,IAAa,EAAE,SAAiB;QAC3D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;YAChC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SACjE;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;CACF","file":"grammar-base.js","sourcesContent":["import { array, EventEmitter, isNil, isString, isValid } from '@visactor/vutils';\nimport type { GrammarType, IGrammarBase, IView, IGrammarTask, BaseEventHandler } from '../types';\nimport { parseOptions } from '../parse/option';\nimport { parseFunctionType } from '../parse/util';\nimport type { Nil } from '../types/base';\nimport { HOOK_EVENT } from '../graph/enums';\n\nlet grammarBaseId = -1;\n\nexport abstract class GrammarBase extends EventEmitter implements IGrammarBase {\n readonly grammarType: GrammarType;\n\n readonly uid: number;\n protected _id: string;\n protected _name: string;\n\n protected spec: any = {};\n\n view: IView;\n rank: number;\n\n // FIXME: adapt current implementation of dataflow, refactor after dataflow design is finished\n grammarSource: IGrammarBase;\n references: Map<IGrammarBase, number> = new Map();\n targets: IGrammarBase[] = [];\n transforms: IGrammarTask[] = [];\n\n constructor(view: IView) {\n super();\n this.view = view;\n this.uid = ++grammarBaseId;\n }\n\n parse(spec: any): this {\n this.id(spec.id);\n this.name(spec.name);\n this.depend(spec.dependency);\n return this;\n }\n\n depend(grammars: IGrammarBase[] | IGrammarBase | string[] | string) {\n if (this.spec?.dependency) {\n const lastGrammars = array(this.spec.dependency).map(grammar => {\n return isString(grammar) ? this.view.getGrammarById(grammar) : grammar;\n });\n this.detach(lastGrammars);\n }\n this.spec.dependency = grammars;\n const currentGrammars = array(grammars).map(grammar => {\n return isString(grammar) ? this.view.getGrammarById(grammar) : grammar;\n });\n this.attach(currentGrammars);\n\n this.commit();\n return this;\n }\n\n addEventListener(type: string, handler: BaseEventHandler, options?: any) {\n let callback = handler;\n if (!(options && options.trap === false)) {\n callback = handler;\n (callback as any).raw = handler;\n }\n if (options && options.target) {\n (callback as any).target = options.target;\n }\n this.on(type, callback);\n return this;\n }\n\n removeEventListener(type: string, handler?: BaseEventHandler) {\n if (handler) {\n this.off(type, handler);\n } else {\n this.off(type);\n }\n return this;\n }\n\n emit<T extends EventEmitter.EventNames<string | symbol>>(\n event: T,\n ...args: EventEmitter.EventArgs<string | symbol, T>\n ): boolean {\n this.view?.emit?.(event, ...args);\n return super.emit(event, ...args);\n }\n\n emitGrammarEvent<T extends EventEmitter.EventNames<string | symbol>>(\n event: T,\n ...args: EventEmitter.EventArgs<string | symbol, T>\n ): boolean {\n return super.emit(event, ...args);\n }\n\n abstract evaluate(upstream: any, parameters: any): this | this;\n abstract output(): any;\n\n evaluateTransform(transforms: IGrammarTask[], upstream: any, parameters: any) {\n if (!transforms || !transforms.length) {\n return upstream;\n }\n let currentUpstreamData = upstream;\n let i = 0;\n const n = transforms.length;\n\n while (i < n) {\n const task = transforms[i];\n\n this.emit(HOOK_EVENT.BEFORE_TRANSFORM, task.type);\n currentUpstreamData = task.transform(\n task.isRawOptions ? task.options : parseOptions(task.options, parameters),\n currentUpstreamData,\n parameters,\n this.view\n );\n i++;\n this.emit(HOOK_EVENT.AFTER_TRANSFORM, task.type);\n }\n\n return currentUpstreamData;\n }\n\n set(value: any): boolean {\n // do nothing\n return false;\n }\n\n id(): string;\n id(id: string): this;\n id(id?: string) {\n if (arguments.length) {\n this.view.grammars.unrecord(this);\n this._id = id;\n this.view.grammars.record(this);\n return this;\n }\n return this._id;\n }\n\n name(): string;\n name(name: string): this;\n name(name?: string) {\n if (arguments.length) {\n this._name = name;\n return this;\n }\n return this._name;\n }\n\n attach(reference: IGrammarBase | IGrammarBase[], count: number = 1) {\n array(reference)\n .filter(ref => !isNil(ref))\n .forEach(ref => {\n if (isNil(reference)) {\n return;\n }\n if (!ref.targets.includes(this)) {\n ref.targets.push(this);\n }\n this.references.set(ref, (this.references.get(ref) ?? 0) + count);\n });\n return this;\n }\n\n detach(reference: IGrammarBase | IGrammarBase[], count: number = 1) {\n array(reference)\n .filter(ref => !isNil(ref))\n .forEach(ref => {\n const refCount = this.references.get(ref) - count;\n if (refCount > 0) {\n this.references.set(ref, refCount - 1);\n } else {\n this.references.delete(ref);\n if (ref.targets.includes(this)) {\n ref.targets = ref.targets.filter(target => target !== this);\n }\n }\n });\n return this;\n }\n\n detachAll() {\n this.references.forEach((count, ref) => {\n this.detach(ref, count);\n });\n }\n\n link(source: IGrammarBase) {\n this.grammarSource = source;\n }\n\n run() {\n const upstream = this.grammarSource?.output();\n const parameters = this.parameters();\n return this.evaluate(upstream, parameters);\n }\n\n commit() {\n this.view.commit(this);\n }\n\n parameters() {\n const params: any = {};\n this.references.forEach((count, ref) => {\n // upstream reference with no valid id will not be recorded in parameters\n if (isValid(ref.id())) {\n params[ref.id() as string] = ref.output();\n }\n });\n return params;\n }\n\n getSpec() {\n return this.spec;\n }\n\n reuse(grammar: IGrammarBase) {\n return this;\n }\n\n clear() {\n this.spec = null;\n this.view = null;\n }\n\n release() {\n this.clear();\n }\n\n protected setFunctionSpec<T>(spec: T | Nil, specField: string) {\n if (!isNil(this.spec[specField])) {\n this.detach(parseFunctionType(this.spec[specField], this.view));\n }\n this.spec[specField] = spec;\n this.attach(parseFunctionType(spec, this.view));\n this.commit();\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/view/grammar-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,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AE,EAAY,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;aAC3C;QACH,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,OAAqB;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAES,eAAe,CAAI,IAAa,EAAE,SAAiB;QAC3D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;YAChC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SACjE;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;CACF","file":"grammar-base.js","sourcesContent":["import { array, EventEmitter, isNil, isString, isValid } from '@visactor/vutils';\nimport type { GrammarType, IGrammarBase, IView, IGrammarTask, BaseEventHandler } from '../types';\nimport { parseOptions } from '../parse/option';\nimport { parseFunctionType } from '../parse/util';\nimport type { Nil } from '../types/base';\nimport { HOOK_EVENT } from '../graph/enums';\n\nlet grammarBaseId = -1;\n\nexport abstract class GrammarBase extends EventEmitter implements IGrammarBase {\n readonly grammarType: GrammarType;\n\n readonly uid: number;\n protected _id: string;\n protected _name: string;\n\n protected spec: any = {};\n\n view: IView;\n rank: number;\n\n // FIXME: adapt current implementation of dataflow, refactor after dataflow design is finished\n grammarSource: IGrammarBase;\n references: Map<IGrammarBase, number> = new Map();\n targets: IGrammarBase[] = [];\n transforms: IGrammarTask[] = [];\n\n constructor(view: IView) {\n super();\n this.view = view;\n this.uid = ++grammarBaseId;\n }\n\n parse(spec: any): this {\n this.id(spec.id);\n this.name(spec.name);\n this.depend(spec.dependency);\n return this;\n }\n\n depend(grammars: IGrammarBase[] | IGrammarBase | string[] | string) {\n if (this.spec?.dependency) {\n const lastGrammars = array(this.spec.dependency).map(grammar => {\n return isString(grammar) ? this.view.getGrammarById(grammar) : grammar;\n });\n this.detach(lastGrammars);\n }\n this.spec.dependency = grammars;\n const currentGrammars = array(grammars).map(grammar => {\n return isString(grammar) ? this.view.getGrammarById(grammar) : grammar;\n });\n this.attach(currentGrammars);\n\n this.commit();\n return this;\n }\n\n addEventListener(type: string, handler: BaseEventHandler, options?: any) {\n let callback = handler;\n if (!(options && options.trap === false)) {\n callback = handler;\n (callback as any).raw = handler;\n }\n if (options && options.target) {\n (callback as any).target = options.target;\n }\n this.on(type, callback);\n return this;\n }\n\n removeEventListener(type: string, handler?: BaseEventHandler) {\n if (handler) {\n this.off(type, handler);\n } else {\n this.off(type);\n }\n return this;\n }\n\n emit<T extends EventEmitter.EventNames<string | symbol>>(\n event: T,\n ...args: EventEmitter.EventArgs<string | symbol, T>\n ): boolean {\n this.view?.emit?.(event, ...args);\n return super.emit(event, ...args);\n }\n\n emitGrammarEvent<T extends EventEmitter.EventNames<string | symbol>>(\n event: T,\n ...args: EventEmitter.EventArgs<string | symbol, T>\n ): boolean {\n return super.emit(event, ...args);\n }\n\n abstract evaluate(upstream: any, parameters: any): this;\n abstract output(): any;\n\n evaluateTransform(transforms: IGrammarTask[], upstream: any, parameters: any) {\n if (!transforms || !transforms.length) {\n return upstream;\n }\n let currentUpstreamData = upstream;\n let i = 0;\n const n = transforms.length;\n\n while (i < n) {\n const task = transforms[i];\n\n this.emit(HOOK_EVENT.BEFORE_TRANSFORM, task.type);\n currentUpstreamData = task.transform(\n task.isRawOptions ? task.options : parseOptions(task.options, parameters),\n currentUpstreamData,\n parameters,\n this.view\n );\n i++;\n this.emit(HOOK_EVENT.AFTER_TRANSFORM, task.type);\n }\n\n return currentUpstreamData;\n }\n\n set(value: any): boolean {\n // do nothing\n return false;\n }\n\n id(): string;\n id(id: string): this;\n id(id?: string) {\n if (arguments.length) {\n this.view.grammars.unrecord(this);\n this._id = id;\n this.view.grammars.record(this);\n return this;\n }\n return this._id;\n }\n\n name(): string;\n name(name: string): this;\n name(name?: string) {\n if (arguments.length) {\n this._name = name;\n return this;\n }\n return this._name;\n }\n\n attach(reference: IGrammarBase | IGrammarBase[], count: number = 1) {\n array(reference)\n .filter(ref => !isNil(ref))\n .forEach(ref => {\n if (isNil(reference)) {\n return;\n }\n if (!ref.targets.includes(this)) {\n ref.targets.push(this);\n }\n this.references.set(ref, (this.references.get(ref) ?? 0) + count);\n });\n return this;\n }\n\n detach(reference: IGrammarBase | IGrammarBase[], count: number = 1) {\n array(reference)\n .filter(ref => !isNil(ref))\n .forEach(ref => {\n const refCount = this.references.get(ref) - count;\n if (refCount > 0) {\n this.references.set(ref, refCount - 1);\n } else {\n this.references.delete(ref);\n if (ref.targets.includes(this)) {\n ref.targets = ref.targets.filter(target => target !== this);\n }\n }\n });\n return this;\n }\n\n detachAll() {\n this.references.forEach((count, ref) => {\n this.detach(ref, count);\n });\n }\n\n link(source: IGrammarBase) {\n this.grammarSource = source;\n }\n\n run() {\n const upstream = this.grammarSource?.output();\n const parameters = this.parameters();\n return this.evaluate(upstream, parameters);\n }\n\n commit() {\n this.view.commit(this);\n }\n\n parameters() {\n const params: any = {};\n this.references.forEach((count, ref) => {\n // upstream reference with no valid id will not be recorded in parameters\n if (isValid(ref.id())) {\n params[ref.id() as string] = ref.output();\n }\n });\n return params;\n }\n\n getSpec() {\n return this.spec;\n }\n\n reuse(grammar: IGrammarBase) {\n return this;\n }\n\n clear() {\n this.spec = null;\n this.view = null;\n }\n\n release() {\n this.clear();\n }\n\n protected setFunctionSpec<T>(spec: T | Nil, specField: string) {\n if (!isNil(this.spec[specField])) {\n this.detach(parseFunctionType(this.spec[specField], this.view));\n }\n this.spec[specField] = spec;\n this.attach(parseFunctionType(spec, this.view));\n this.commit();\n return this;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vgrammar-core",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "VGrammar is a visual grammar library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"grammar",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@visactor/vgrammar-coordinate": "0.11.
|
|
28
|
-
"@visactor/vgrammar-util": "0.11.
|
|
27
|
+
"@visactor/vgrammar-coordinate": "0.11.2",
|
|
28
|
+
"@visactor/vgrammar-util": "0.11.2",
|
|
29
29
|
"@visactor/vscale": "~0.17.3",
|
|
30
|
-
"@visactor/vrender-core": "0.17.
|
|
31
|
-
"@visactor/vrender-kits": "0.17.
|
|
32
|
-
"@visactor/vrender-components": "0.17.
|
|
30
|
+
"@visactor/vrender-core": "0.17.16",
|
|
31
|
+
"@visactor/vrender-kits": "0.17.16",
|
|
32
|
+
"@visactor/vrender-components": "0.17.16",
|
|
33
33
|
"@visactor/vutils": "~0.17.3",
|
|
34
34
|
"@visactor/vdataset": "~0.17.3"
|
|
35
35
|
},
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@types/jest": "~29.5.0",
|
|
46
46
|
"typescript": "4.9.5",
|
|
47
47
|
"@internal/bundler": "0.0.1",
|
|
48
|
-
"@internal/ts-config": "0.0.1",
|
|
49
48
|
"@internal/eslint-config": "0.0.1",
|
|
49
|
+
"@internal/ts-config": "0.0.1",
|
|
50
50
|
"@internal/jest-config": "0.0.1"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|