improve session api
This commit is contained in:
parent
a9042e4b05
commit
5b514e07f9
2 changed files with 90 additions and 60 deletions
|
@ -13,12 +13,28 @@ class SessionManager {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
get current() {
|
update<T extends BaseSession>(...args: Parameters<T['update']>) {
|
||||||
return this._current
|
this._current.update.call(null, ...args)
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
set current(session: BaseSession) {
|
start(session: BaseSession) {
|
||||||
this._current = session
|
this._current = session
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
compplete<T extends BaseSession>(...args: Parameters<T['complete']>) {
|
||||||
|
this._current.complete.call(null, ...args)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel<T extends BaseSession>(...args: Parameters<T['cancel']>) {
|
||||||
|
this._current.cancel.call(null, ...args)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
get current() {
|
||||||
|
return this._current
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
128
state/state.ts
128
state/state.ts
|
@ -1003,39 +1003,40 @@ const state = createState({
|
||||||
|
|
||||||
// Editing
|
// Editing
|
||||||
startEditSession(data) {
|
startEditSession(data) {
|
||||||
session.current = new Sessions.EditSession(data)
|
session.start(new Sessions.EditSession(data))
|
||||||
},
|
},
|
||||||
updateEditSession(data, payload: { change: Partial<Shape> }) {
|
updateEditSession(data, payload: { change: Partial<Shape> }) {
|
||||||
session.current.update(data, payload.change)
|
session.update<Sessions.EditSession>(data, payload.change)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Brushing
|
// Brushing
|
||||||
startBrushSession(data, payload: PointerInfo) {
|
startBrushSession(data, payload: PointerInfo) {
|
||||||
session.current = new Sessions.BrushSession(
|
session.start(
|
||||||
data,
|
new Sessions.BrushSession(data, screenToWorld(payload.point, data))
|
||||||
screenToWorld(payload.point, data)
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateBrushSession(data, payload: PointerInfo) {
|
updateBrushSession(data, payload: PointerInfo) {
|
||||||
session.current.update(data, screenToWorld(payload.point, data))
|
session.update<Sessions.BrushSession>(
|
||||||
|
data,
|
||||||
|
screenToWorld(payload.point, data)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Rotating
|
// Rotating
|
||||||
startRotateSession(data, payload: PointerInfo) {
|
startRotateSession(data, payload: PointerInfo) {
|
||||||
session.current = new Sessions.RotateSession(
|
session.start(
|
||||||
data,
|
new Sessions.RotateSession(data, screenToWorld(payload.point, data))
|
||||||
screenToWorld(payload.point, data)
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
keyUpdateRotateSession(data, payload: PointerInfo) {
|
keyUpdateRotateSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.RotateSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(inputs.pointer.point, data),
|
screenToWorld(inputs.pointer.point, data),
|
||||||
payload.shiftKey
|
payload.shiftKey
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateRotateSession(data, payload: PointerInfo) {
|
updateRotateSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.RotateSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(payload.point, data),
|
screenToWorld(payload.point, data),
|
||||||
payload.shiftKey
|
payload.shiftKey
|
||||||
|
@ -1044,16 +1045,18 @@ const state = createState({
|
||||||
|
|
||||||
// Dragging / Translating
|
// Dragging / Translating
|
||||||
startTranslateSession(data) {
|
startTranslateSession(data) {
|
||||||
session.current = new Sessions.TranslateSession(
|
session.start(
|
||||||
data,
|
new Sessions.TranslateSession(
|
||||||
screenToWorld(inputs.pointer.origin, data)
|
data,
|
||||||
|
screenToWorld(inputs.pointer.origin, data)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
keyUpdateTranslateSession(
|
keyUpdateTranslateSession(
|
||||||
data,
|
data,
|
||||||
payload: { shiftKey: boolean; altKey: boolean }
|
payload: { shiftKey: boolean; altKey: boolean }
|
||||||
) {
|
) {
|
||||||
session.current.update(
|
session.update<Sessions.TranslateSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(inputs.pointer.point, data),
|
screenToWorld(inputs.pointer.point, data),
|
||||||
payload.shiftKey,
|
payload.shiftKey,
|
||||||
|
@ -1061,7 +1064,7 @@ const state = createState({
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateTranslateSession(data, payload: PointerInfo) {
|
updateTranslateSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.TranslateSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(payload.point, data),
|
screenToWorld(payload.point, data),
|
||||||
payload.shiftKey,
|
payload.shiftKey,
|
||||||
|
@ -1080,30 +1083,30 @@ const state = createState({
|
||||||
const shapeId = Array.from(getSelectedIds(data).values())[0]
|
const shapeId = Array.from(getSelectedIds(data).values())[0]
|
||||||
const handleId = payload.target
|
const handleId = payload.target
|
||||||
|
|
||||||
session.current = new Sessions.HandleSession(
|
session.start(
|
||||||
data,
|
new Sessions.HandleSession(
|
||||||
shapeId,
|
data,
|
||||||
handleId,
|
shapeId,
|
||||||
screenToWorld(inputs.pointer.origin, data)
|
handleId,
|
||||||
|
screenToWorld(inputs.pointer.origin, data)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
keyUpdateHandleSession(
|
keyUpdateHandleSession(
|
||||||
data,
|
data,
|
||||||
payload: { shiftKey: boolean; altKey: boolean }
|
payload: { shiftKey: boolean; altKey: boolean }
|
||||||
) {
|
) {
|
||||||
session.current.update(
|
session.update<Sessions.HandleSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(inputs.pointer.point, data),
|
screenToWorld(inputs.pointer.point, data),
|
||||||
payload.shiftKey,
|
payload.shiftKey
|
||||||
payload.altKey
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateHandleSession(data, payload: PointerInfo) {
|
updateHandleSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.HandleSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(payload.point, data),
|
screenToWorld(payload.point, data),
|
||||||
payload.shiftKey,
|
payload.shiftKey
|
||||||
payload.altKey
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1113,59 +1116,67 @@ const state = createState({
|
||||||
payload: PointerInfo & { target: Corner | Edge }
|
payload: PointerInfo & { target: Corner | Edge }
|
||||||
) {
|
) {
|
||||||
const point = screenToWorld(inputs.pointer.origin, data)
|
const point = screenToWorld(inputs.pointer.origin, data)
|
||||||
session.current =
|
session.start(
|
||||||
getSelectedIds(data).size === 1
|
getSelectedIds(data).size === 1
|
||||||
? new Sessions.TransformSingleSession(data, payload.target, point)
|
? new Sessions.TransformSingleSession(data, payload.target, point)
|
||||||
: new Sessions.TransformSession(data, payload.target, point)
|
: new Sessions.TransformSession(data, payload.target, point)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
startDrawTransformSession(data, payload: PointerInfo) {
|
startDrawTransformSession(data, payload: PointerInfo) {
|
||||||
session.current = new Sessions.TransformSingleSession(
|
session.start(
|
||||||
data,
|
new Sessions.TransformSingleSession(
|
||||||
Corner.BottomRight,
|
data,
|
||||||
screenToWorld(payload.point, data),
|
Corner.BottomRight,
|
||||||
true
|
screenToWorld(payload.point, data),
|
||||||
|
true
|
||||||
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
keyUpdateTransformSession(data, payload: PointerInfo) {
|
keyUpdateTransformSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.TransformSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(inputs.pointer.point, data),
|
screenToWorld(inputs.pointer.point, data),
|
||||||
payload.shiftKey,
|
payload.shiftKey
|
||||||
payload.altKey
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateTransformSession(data, payload: PointerInfo) {
|
updateTransformSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.TransformSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(payload.point, data),
|
screenToWorld(payload.point, data),
|
||||||
payload.shiftKey,
|
payload.shiftKey
|
||||||
payload.altKey
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Direction
|
// Direction
|
||||||
startDirectionSession(data) {
|
startDirectionSession(data) {
|
||||||
session.current = new Sessions.DirectionSession(
|
session.start(
|
||||||
data,
|
new Sessions.DirectionSession(
|
||||||
screenToWorld(inputs.pointer.origin, data)
|
data,
|
||||||
|
screenToWorld(inputs.pointer.origin, data)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateDirectionSession(data, payload: PointerInfo) {
|
updateDirectionSession(data, payload: PointerInfo) {
|
||||||
session.current.update(data, screenToWorld(payload.point, data))
|
session.update<Sessions.DirectionSession>(
|
||||||
|
data,
|
||||||
|
screenToWorld(payload.point, data)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Drawing
|
// Drawing
|
||||||
startDrawSession(data, payload: PointerInfo) {
|
startDrawSession(data, payload: PointerInfo) {
|
||||||
const id = Array.from(getSelectedIds(data).values())[0]
|
const id = Array.from(getSelectedIds(data).values())[0]
|
||||||
session.current = new Sessions.DrawSession(
|
session.start(
|
||||||
data,
|
new Sessions.DrawSession(
|
||||||
id,
|
data,
|
||||||
screenToWorld(inputs.pointer.origin, data),
|
id,
|
||||||
payload.shiftKey
|
screenToWorld(inputs.pointer.origin, data),
|
||||||
|
payload.shiftKey
|
||||||
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
keyUpdateDrawSession(data, payload: PointerInfo) {
|
keyUpdateDrawSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.DrawSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(inputs.pointer.point, data),
|
screenToWorld(inputs.pointer.point, data),
|
||||||
payload.pressure,
|
payload.pressure,
|
||||||
|
@ -1173,7 +1184,7 @@ const state = createState({
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateDrawSession(data, payload: PointerInfo) {
|
updateDrawSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.DrawSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(payload.point, data),
|
screenToWorld(payload.point, data),
|
||||||
payload.pressure,
|
payload.pressure,
|
||||||
|
@ -1184,22 +1195,25 @@ const state = createState({
|
||||||
// Arrow
|
// Arrow
|
||||||
startArrowSession(data, payload: PointerInfo) {
|
startArrowSession(data, payload: PointerInfo) {
|
||||||
const id = Array.from(getSelectedIds(data).values())[0]
|
const id = Array.from(getSelectedIds(data).values())[0]
|
||||||
session.current = new Sessions.ArrowSession(
|
|
||||||
data,
|
session.start(
|
||||||
id,
|
new Sessions.ArrowSession(
|
||||||
screenToWorld(inputs.pointer.origin, data),
|
data,
|
||||||
payload.shiftKey
|
id,
|
||||||
|
screenToWorld(inputs.pointer.origin, data),
|
||||||
|
payload.shiftKey
|
||||||
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
keyUpdateArrowSession(data, payload: PointerInfo) {
|
keyUpdateArrowSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.ArrowSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(inputs.pointer.point, data),
|
screenToWorld(inputs.pointer.point, data),
|
||||||
payload.shiftKey
|
payload.shiftKey
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
updateArrowSession(data, payload: PointerInfo) {
|
updateArrowSession(data, payload: PointerInfo) {
|
||||||
session.current.update(
|
session.update<Sessions.ArrowSession>(
|
||||||
data,
|
data,
|
||||||
screenToWorld(payload.point, data),
|
screenToWorld(payload.point, data),
|
||||||
payload.shiftKey
|
payload.shiftKey
|
||||||
|
|
Loading…
Reference in a new issue