Comparing version 1.1.4 to 1.1.5
import Workspace from './src/workspace'; | ||
export * from './src/brick'; | ||
export * from './src/util'; | ||
export * from './src/types'; | ||
export { Workspace }; |
import React from 'react'; | ||
export var BrickOutput; | ||
(function (BrickOutput) { | ||
BrickOutput[BrickOutput["void"] = 0] = "void"; | ||
BrickOutput[BrickOutput["string"] = 1] = "string"; | ||
BrickOutput[BrickOutput["number"] = 2] = "number"; | ||
BrickOutput[BrickOutput["boolean"] = 3] = "boolean"; | ||
BrickOutput[BrickOutput["array"] = 4] = "array"; | ||
BrickOutput[BrickOutput["any"] = 5] = "any"; | ||
})(BrickOutput || (BrickOutput = {})); | ||
export var AtomicBrickEnum; | ||
(function (AtomicBrickEnum) { | ||
AtomicBrickEnum[AtomicBrickEnum["atomic_text"] = 1] = "atomic_text"; | ||
AtomicBrickEnum[AtomicBrickEnum["atomic_boolean"] = 2] = "atomic_boolean"; | ||
AtomicBrickEnum[AtomicBrickEnum["atomic_dropdown"] = 3] = "atomic_dropdown"; | ||
AtomicBrickEnum[AtomicBrickEnum["atomic_input_string"] = 4] = "atomic_input_string"; | ||
AtomicBrickEnum[AtomicBrickEnum["atomic_input_number"] = 5] = "atomic_input_number"; | ||
AtomicBrickEnum[AtomicBrickEnum["atomic_param"] = 6] = "atomic_param"; | ||
AtomicBrickEnum[AtomicBrickEnum["atomic_button"] = 7] = "atomic_button"; | ||
})(AtomicBrickEnum || (AtomicBrickEnum = {})); | ||
import { gen_id } from './util'; | ||
export const get_ancestor = (bricks, brick) => { | ||
let ancestor = brick; | ||
while (ancestor.ui.parent) { | ||
ancestor = bricks[ancestor.ui.parent]; | ||
} | ||
return ancestor; | ||
}; | ||
export const clone = (brick, with_ui = true) => { | ||
let root; | ||
const do_clone = (b, prev, parent = undefined) => { | ||
const id = gen_id(); | ||
root = root || id; | ||
const res = Object.assign({}, b, { parts: b.parts ? b.parts.map(i => do_clone(i, undefined, id)) : undefined, inputs: b.inputs ? b.inputs.map(i => do_clone(i, undefined, id)) : undefined, root, prev: b.output ? undefined : prev, id }); | ||
if (with_ui) { | ||
res.ui = Object.assign({}, b.ui, { parent: parent, delegate: b.output ? undefined : parent }); | ||
delete res.ui.is_toolbox_brick; | ||
delete res.ui.is_removing; | ||
delete res.ui.is_ghost; | ||
} | ||
if (b.next !== undefined) { | ||
res.next = b.next === null ? null : do_clone(b.next, id); | ||
} | ||
return res; | ||
}; | ||
const root_brick = do_clone(brick, undefined); | ||
root_brick.root = undefined; | ||
root_brick.ui.offset = { | ||
x: 0, | ||
y: 0, | ||
}; | ||
root_brick.is_root = true; | ||
return root_brick; | ||
}; | ||
export const get_tail = (b) => { | ||
let tail = b; | ||
while (tail.next) { | ||
tail = tail.next; | ||
} | ||
return tail; | ||
}; | ||
export const for_each_brick = (b, tail, cb, range = { | ||
inputs: true, | ||
parts: true, | ||
next: true, | ||
}) => { | ||
const for_each_child_brick = (brick) => { | ||
cb(brick); | ||
range.inputs && brick.inputs && brick.inputs.forEach(i => for_each_child_brick(i)); | ||
range.parts && brick.parts && brick.parts.forEach(i => for_each_child_brick(i)); | ||
if (tail && brick.id === tail.id) { | ||
return; | ||
} | ||
range.next && brick.next && for_each_child_brick(brick.next); | ||
}; | ||
for_each_child_brick(b); | ||
}; | ||
import { BrickOutput, } from './types'; | ||
class BrickComponent extends React.Component { | ||
@@ -79,0 +4,0 @@ constructor(props) { |
@@ -26,1 +26,57 @@ export const gen_id = () => Math.random().toString(32); | ||
}; | ||
export const get_ancestor = (bricks, brick) => { | ||
let ancestor = brick; | ||
while (ancestor.ui.parent) { | ||
ancestor = bricks[ancestor.ui.parent]; | ||
} | ||
return ancestor; | ||
}; | ||
export const clone = (brick, with_ui = true) => { | ||
let root; | ||
const do_clone = (b, prev, parent = undefined) => { | ||
const id = gen_id(); | ||
root = root || id; | ||
const res = Object.assign({}, b, { parts: b.parts ? b.parts.map(i => do_clone(i, undefined, id)) : undefined, inputs: b.inputs ? b.inputs.map(i => do_clone(i, undefined, id)) : undefined, root, prev: b.output ? undefined : prev, id }); | ||
if (with_ui) { | ||
res.ui = Object.assign({}, b.ui, { parent: parent, delegate: b.output ? undefined : parent }); | ||
delete res.ui.is_toolbox_brick; | ||
delete res.ui.is_removing; | ||
delete res.ui.is_ghost; | ||
} | ||
if (b.next !== undefined) { | ||
res.next = b.next === null ? null : do_clone(b.next, id); | ||
} | ||
return res; | ||
}; | ||
const root_brick = do_clone(brick, undefined); | ||
root_brick.root = undefined; | ||
root_brick.ui.offset = { | ||
x: 0, | ||
y: 0, | ||
}; | ||
root_brick.is_root = true; | ||
return root_brick; | ||
}; | ||
export const get_tail = (b) => { | ||
let tail = b; | ||
while (tail.next) { | ||
tail = tail.next; | ||
} | ||
return tail; | ||
}; | ||
export const for_each_brick = (b, tail, cb, range = { | ||
inputs: true, | ||
parts: true, | ||
next: true, | ||
}) => { | ||
const for_each_child_brick = (brick) => { | ||
cb(brick); | ||
range.inputs && brick.inputs && brick.inputs.forEach(i => for_each_child_brick(i)); | ||
range.parts && brick.parts && brick.parts.forEach(i => for_each_child_brick(i)); | ||
if (tail && brick.id === tail.id) { | ||
return; | ||
} | ||
range.next && brick.next && for_each_child_brick(brick.next); | ||
}; | ||
for_each_child_brick(b); | ||
}; |
import React from 'react'; | ||
import styles from './styles/index.less'; | ||
import BrickComponent from './brick'; | ||
import { deduplicate, distance_2d, flatten, get_global_offset, } from './util'; | ||
import { clone, for_each_brick, get_ancestor, get_tail, AtomicBrickEnum, BrickOutput, } from './brick'; | ||
import { deduplicate, distance_2d, flatten, get_global_offset, clone, get_ancestor, for_each_brick, get_tail, } from './util'; | ||
import { AtomicBrickEnum, BrickOutput, } from './types'; | ||
import ContextMenu from './dummy/context_menu'; | ||
@@ -405,2 +405,11 @@ import Input from './dummy/input'; | ||
}; | ||
this.on_wheel = (e) => { | ||
e.preventDefault(); | ||
this.froggy_offset.x -= e.deltaX; | ||
this.froggy_offset.y -= e.deltaY; | ||
this.froggy_ref.current.style.left = `${this.froggy_offset.x}px`; | ||
this.froggy_ref.current.style.top = `${this.froggy_offset.y}px`; | ||
this.toolbox_ref.current.style.left = `${-this.froggy_offset.x}px`; | ||
this.toolbox_ref.current.style.top = `${-this.froggy_offset.y}px`; | ||
}; | ||
this.froggy_ref = React.createRef(); | ||
@@ -636,3 +645,3 @@ this.toolbox_ref = React.createRef(); | ||
render() { | ||
return React.createElement("div", { ref: this.froggy_wrap_ref, key: this.props.id, className: styles.froggyWrap, onMouseDown: this.on_mouse_down_middleware, onTouchStart: this.on_mouse_down_middleware, onMouseMove: this.on_mouse_move_middleware, onTouchMove: this.on_mouse_move_middleware, onMouseUp: this.on_mouse_up_middleware, onTouchEnd: this.on_mouse_up_middleware }, | ||
return React.createElement("div", { ref: this.froggy_wrap_ref, key: this.props.id, className: styles.froggyWrap, onMouseDown: this.on_mouse_down_middleware, onTouchStart: this.on_mouse_down_middleware, onMouseMove: this.on_mouse_move_middleware, onTouchMove: this.on_mouse_move_middleware, onMouseUp: this.on_mouse_up_middleware, onTouchEnd: this.on_mouse_up_middleware, onWheel: this.on_wheel }, | ||
React.createElement("div", { ref: this.froggy_ref, className: styles.froggy, style: { | ||
@@ -642,3 +651,3 @@ left: `${this.froggy_offset.x}px`, | ||
} }, | ||
React.createElement("div", { className: styles.toolbox, ref: this.toolbox_ref, onTouchStart: (e) => e.stopPropagation(), onMouseDown: (e) => e.stopPropagation(), style: { | ||
React.createElement("div", { className: styles.toolbox, ref: this.toolbox_ref, onTouchStart: (e) => e.stopPropagation(), onMouseDown: (e) => e.stopPropagation(), onWheel: (e) => e.stopPropagation(), style: { | ||
left: `${-this.froggy_offset.x}px`, | ||
@@ -645,0 +654,0 @@ top: `${-this.froggy_offset.y}px`, |
@@ -11,3 +11,3 @@ import control from './control'; | ||
Brick, | ||
} from '../../src/brick'; | ||
} from '../../'; | ||
@@ -14,0 +14,0 @@ const categories = { |
import Workspace from './src/workspace'; | ||
export * from './src/brick'; | ||
export * from './src/util'; | ||
export * from './src/types'; | ||
export { Workspace }; |
{ | ||
"name": "froggy", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -0,1 +1,6 @@ | ||
import { | ||
Brick, | ||
BrickId, | ||
} from './types'; | ||
export const gen_id = () => Math.random().toString(32); | ||
@@ -29,2 +34,81 @@ | ||
return res; | ||
}; | ||
}; | ||
export const get_ancestor = (bricks, brick: Brick) => { | ||
let ancestor = brick; | ||
while (ancestor.ui.parent) { | ||
ancestor = bricks[ancestor.ui.parent]; | ||
} | ||
return ancestor; | ||
}; | ||
export const clone = (brick: Brick, with_ui = true) => { | ||
let root; | ||
const do_clone = (b: Brick, prev: BrickId, parent = undefined) => { | ||
const id = gen_id(); | ||
root = root || id; | ||
const res = { | ||
...b, | ||
parts: b.parts ? b.parts.map(i => do_clone(i, undefined, id)) : undefined, | ||
inputs: b.inputs ? b.inputs.map(i => do_clone(i, undefined, id)) : undefined, | ||
root, | ||
prev: b.output ? undefined : prev, | ||
id, | ||
} as Brick; | ||
if (with_ui) { | ||
res.ui = { | ||
...b.ui, | ||
parent: parent, | ||
delegate: b.output ? undefined : parent, | ||
}; | ||
delete res.ui.is_toolbox_brick; | ||
delete res.ui.is_removing; | ||
delete res.ui.is_ghost; | ||
} | ||
if (b.next !== undefined) { | ||
res.next = b.next === null ? null : do_clone(b.next, id); | ||
} | ||
return res; | ||
}; | ||
const root_brick = do_clone(brick, undefined); | ||
root_brick.root = undefined; | ||
root_brick.ui.offset = { | ||
x: 0, | ||
y: 0, | ||
}; | ||
root_brick.is_root = true; | ||
return root_brick as Brick; | ||
}; | ||
export const get_tail = (b: Brick) => { | ||
let tail = b; | ||
while (tail.next) { | ||
tail = tail.next; | ||
} | ||
return tail; | ||
}; | ||
export const for_each_brick = ( | ||
b: Brick, | ||
tail: Brick, | ||
cb: Function, | ||
range: { | ||
inputs?: boolean, | ||
parts?: boolean, | ||
next?: boolean, | ||
} = { | ||
inputs: true, | ||
parts: true, | ||
next: true, | ||
}) => { | ||
const for_each_child_brick = (brick: Brick) => { | ||
cb(brick); | ||
range.inputs && brick.inputs && brick.inputs.forEach(i => for_each_child_brick(i)); | ||
range.parts && brick.parts && brick.parts.forEach(i => for_each_child_brick(i)); | ||
if (tail && brick.id === tail.id) { | ||
return; | ||
} | ||
range.next && brick.next && for_each_child_brick(brick.next); | ||
}; | ||
for_each_child_brick(b); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166346
52
3698