lunchboxjs 0.2.1019 → 2.0.0-beta.0
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/dist/lunchboxjs.es.d.ts +1 -1
- package/dist/lunchboxjs.js +6 -5
- package/dist/lunchboxjs.min.js +1 -1
- package/dist/lunchboxjs.module.js +6 -5
- package/dist/lunchboxjs.umd.d.ts +1 -1
- package/package.json +37 -82
- package/LICENSE.md +0 -7
- package/README.md +0 -17
- package/src/components/LunchboxEventHandlers.tsx +0 -237
- package/src/components/LunchboxWrapper/LunchboxScene.tsx +0 -8
- package/src/components/LunchboxWrapper/LunchboxWrapper.tsx +0 -341
- package/src/components/LunchboxWrapper/prepCanvas.ts +0 -55
- package/src/components/LunchboxWrapper/resizeCanvas.ts +0 -41
- package/src/components/autoGeneratedComponents.ts +0 -175
- package/src/components/index.ts +0 -31
- package/src/core/createNode.ts +0 -71
- package/src/core/extend.ts +0 -25
- package/src/core/index.ts +0 -7
- package/src/core/instantiateThreeObject/index.ts +0 -37
- package/src/core/instantiateThreeObject/processProps.ts +0 -40
- package/src/core/interaction.ts +0 -55
- package/src/core/minidom.ts +0 -256
- package/src/core/update.ts +0 -149
- package/src/core/updateObjectProp.ts +0 -153
- package/src/index.ts +0 -400
- package/src/keys.ts +0 -31
- package/src/nodeOps/createElement.ts +0 -34
- package/src/nodeOps/index.ts +0 -83
- package/src/nodeOps/insert.ts +0 -165
- package/src/nodeOps/remove.ts +0 -32
- package/src/plugins/bridge/BridgeComponent.tsx +0 -60
- package/src/plugins/bridge/bridge.ts +0 -9
- package/src/types.ts +0 -186
- package/src/utils/find.ts +0 -24
- package/src/utils/get.ts +0 -18
- package/src/utils/index.ts +0 -60
- package/src/utils/isNumber.ts +0 -87
- package/src/utils/set.ts +0 -14
package/src/nodeOps/insert.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isLunchboxDomComponent,
|
|
3
|
-
isLunchboxRootNode,
|
|
4
|
-
isLunchboxStandardNode,
|
|
5
|
-
} from '../utils'
|
|
6
|
-
import { MiniDom } from '../core/minidom'
|
|
7
|
-
import { Lunch } from '..'
|
|
8
|
-
|
|
9
|
-
export const insert = (
|
|
10
|
-
child: MiniDom.RendererBaseNode,
|
|
11
|
-
parent: MiniDom.RendererBaseNode | null,
|
|
12
|
-
anchor?: MiniDom.RendererBaseNode | null
|
|
13
|
-
) => {
|
|
14
|
-
if (!parent) {
|
|
15
|
-
throw new Error('missing parent')
|
|
16
|
-
}
|
|
17
|
-
// add to parent tree node if we have one
|
|
18
|
-
// let effectiveParent = parent ?? ensureRootNode()
|
|
19
|
-
parent.insertBefore(child, anchor)
|
|
20
|
-
|
|
21
|
-
// handle comment & text nodes
|
|
22
|
-
if (child.metaType === 'commentMeta' || child.metaType === 'textMeta') {
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// handle dom element
|
|
27
|
-
if (isLunchboxDomComponent(child)) {
|
|
28
|
-
if (isLunchboxDomComponent(parent) || isLunchboxRootNode(parent)) {
|
|
29
|
-
parent.domElement.appendChild(child.domElement)
|
|
30
|
-
} else {
|
|
31
|
-
// TODO: handle dom nodes as children of Lunchbox nodes
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// handle standard nodes
|
|
36
|
-
if (isLunchboxStandardNode(child)) {
|
|
37
|
-
// let effectiveParent = parent
|
|
38
|
-
let effectiveParentNodeType = parent.metaType
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
effectiveParentNodeType === 'textMeta' ||
|
|
42
|
-
effectiveParentNodeType === 'commentMeta'
|
|
43
|
-
) {
|
|
44
|
-
const path = parent.getPath() as MiniDom.RendererBaseNode[]
|
|
45
|
-
for (let i = path.length - 1; i >= 0; i--) {
|
|
46
|
-
if (
|
|
47
|
-
path[i].metaType !== 'textMeta' &&
|
|
48
|
-
path[i].metaType !== 'commentMeta'
|
|
49
|
-
) {
|
|
50
|
-
parent = path[i]
|
|
51
|
-
break
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
isLunchboxStandardNode(child) &&
|
|
58
|
-
child.instance?.isObject3D &&
|
|
59
|
-
isLunchboxStandardNode(parent) &&
|
|
60
|
-
parent.instance?.isObject3D
|
|
61
|
-
) {
|
|
62
|
-
parent.instance?.add?.(child.instance)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// add attached props
|
|
66
|
-
if (
|
|
67
|
-
child?.props?.attach &&
|
|
68
|
-
isLunchboxStandardNode(parent) &&
|
|
69
|
-
parent?.instance
|
|
70
|
-
) {
|
|
71
|
-
// if this element is a loader and the `src` attribute is being used,
|
|
72
|
-
// let's assume we want to create the loader and run `load`
|
|
73
|
-
const isUsingLoaderSugar =
|
|
74
|
-
child.type?.toLowerCase().endsWith('loader') &&
|
|
75
|
-
child.props.src &&
|
|
76
|
-
(child.props.attach || child.props.attachArray)
|
|
77
|
-
|
|
78
|
-
// run special loader behavior
|
|
79
|
-
if (isUsingLoaderSugar) {
|
|
80
|
-
runLoader(child, parent)
|
|
81
|
-
} else {
|
|
82
|
-
// update attached normally
|
|
83
|
-
attachToParentInstance(child, parent, child.props.attach)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// fire onAdded event
|
|
88
|
-
if (child.props?.onAdded) {
|
|
89
|
-
child.props.onAdded({
|
|
90
|
-
instance: child.instance,
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function runLoader<T>(
|
|
97
|
-
child: MiniDom.RendererStandardNode<T>,
|
|
98
|
-
parent: MiniDom.RendererStandardNode
|
|
99
|
-
) {
|
|
100
|
-
const loader = child.instance as any as Lunch.GenericThreeLoader
|
|
101
|
-
// ensure parent has attached spaces ready
|
|
102
|
-
parent.attached = parent.attached || {}
|
|
103
|
-
parent.attachedArray = parent.attachedArray || {}
|
|
104
|
-
|
|
105
|
-
// this should never be true, but just in case
|
|
106
|
-
if (!child.props.attach) return
|
|
107
|
-
|
|
108
|
-
if (child.type?.toLowerCase() === 'textureloader') {
|
|
109
|
-
// if this is a texture loader, immediately pass
|
|
110
|
-
// load function to parent attachment
|
|
111
|
-
const textureLoader = loader as any as THREE.TextureLoader
|
|
112
|
-
const inProgressTexture = textureLoader.load(child.props.src)
|
|
113
|
-
|
|
114
|
-
attachToParentInstance(
|
|
115
|
-
child,
|
|
116
|
-
parent,
|
|
117
|
-
child.props.attach,
|
|
118
|
-
inProgressTexture
|
|
119
|
-
)
|
|
120
|
-
} else {
|
|
121
|
-
// use a standard callback-based loader
|
|
122
|
-
loader.load(
|
|
123
|
-
child.props.src,
|
|
124
|
-
(loadedData) => {
|
|
125
|
-
attachToParentInstance(
|
|
126
|
-
child,
|
|
127
|
-
parent,
|
|
128
|
-
child.props.attach!,
|
|
129
|
-
loadedData
|
|
130
|
-
)
|
|
131
|
-
},
|
|
132
|
-
null,
|
|
133
|
-
(err) => {
|
|
134
|
-
throw new Error(err)
|
|
135
|
-
}
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function attachToParentInstance<T>(
|
|
141
|
-
child: MiniDom.RendererStandardNode<T>,
|
|
142
|
-
parent: MiniDom.RendererStandardNode,
|
|
143
|
-
key: string,
|
|
144
|
-
value?: any
|
|
145
|
-
) {
|
|
146
|
-
const finalValueToAttach = value ?? child.instance
|
|
147
|
-
const parentInstanceAsAny = parent.instance as any
|
|
148
|
-
|
|
149
|
-
if (child.props.attach === key) {
|
|
150
|
-
parent.attached = {
|
|
151
|
-
[key]: finalValueToAttach,
|
|
152
|
-
...(parent.attached || {}),
|
|
153
|
-
}
|
|
154
|
-
parentInstanceAsAny[key] = value ?? child.instance
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (child.props.attachArray === key) {
|
|
158
|
-
if (!parent.attachedArray[child.props.attachArray]) {
|
|
159
|
-
parent.attachedArray[child.props.attachArray] = []
|
|
160
|
-
}
|
|
161
|
-
parent.attachedArray[child.props.attachArray].push(finalValueToAttach)
|
|
162
|
-
// TODO: implement auto-attaching array
|
|
163
|
-
parentInstanceAsAny[key] = [parentInstanceAsAny[key]]
|
|
164
|
-
}
|
|
165
|
-
}
|
package/src/nodeOps/remove.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { MiniDom } from '../core'
|
|
2
|
-
import { isLunchboxStandardNode } from '../utils'
|
|
3
|
-
|
|
4
|
-
export const remove = (node: MiniDom.RendererBaseNode) => {
|
|
5
|
-
if (!node) return
|
|
6
|
-
// prep subtree
|
|
7
|
-
const subtree: MiniDom.BaseNode[] = []
|
|
8
|
-
node.walk((descendant) => {
|
|
9
|
-
subtree.push(descendant)
|
|
10
|
-
return true
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
// clean up subtree
|
|
14
|
-
subtree.forEach((n) => {
|
|
15
|
-
if (isLunchboxStandardNode(n)) {
|
|
16
|
-
// try to remove three object
|
|
17
|
-
n.instance?.removeFromParent?.()
|
|
18
|
-
|
|
19
|
-
// try to dispose three object
|
|
20
|
-
const dispose =
|
|
21
|
-
// calling `dispose` on a scene triggers an error,
|
|
22
|
-
// so let's ignore if this node is a scene
|
|
23
|
-
n.type !== 'scene' &&
|
|
24
|
-
((n.instance as any)?.dispose as (() => void) | null)
|
|
25
|
-
if (dispose) dispose.bind(n.instance)()
|
|
26
|
-
n.instance = null
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// drop tree node
|
|
30
|
-
n.drop()
|
|
31
|
-
})
|
|
32
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Component,
|
|
3
|
-
defineComponent,
|
|
4
|
-
getCurrentInstance,
|
|
5
|
-
inject,
|
|
6
|
-
onMounted,
|
|
7
|
-
onUnmounted,
|
|
8
|
-
PropType,
|
|
9
|
-
ref,
|
|
10
|
-
} from 'vue'
|
|
11
|
-
import { createApp, Lunch } from '../..'
|
|
12
|
-
|
|
13
|
-
export const BridgeComponent = defineComponent({
|
|
14
|
-
name: 'BridgeComponent',
|
|
15
|
-
props: {
|
|
16
|
-
app: {
|
|
17
|
-
type: Object as PropType<Lunch.App>,
|
|
18
|
-
},
|
|
19
|
-
root: {
|
|
20
|
-
type: Object as PropType<Component>,
|
|
21
|
-
},
|
|
22
|
-
appSetup: {
|
|
23
|
-
type: Function as PropType<(app: Lunch.App) => Lunch.App>,
|
|
24
|
-
default: (app: Lunch.App) => app,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
setup(props, ctx) {
|
|
28
|
-
// we need an app or root to mount
|
|
29
|
-
if (!props.app && !props.root) {
|
|
30
|
-
throw new Error('app or root required as <bridge> prop')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// prep container
|
|
34
|
-
const container = ref<HTMLDivElement>()
|
|
35
|
-
// create app
|
|
36
|
-
let app: Lunch.App | null = props.appSetup(
|
|
37
|
-
props.app ?? createApp(props.root!, ctx.attrs)
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
// get all provided values - this isn't in the types or docs, so it may be unstable
|
|
41
|
-
const provides = (getCurrentInstance() as any)?.provides ?? {}
|
|
42
|
-
// provide values
|
|
43
|
-
Object.keys(provides).forEach((key) => {
|
|
44
|
-
app?.provide(key, inject(key))
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// mount
|
|
48
|
-
onMounted(() => {
|
|
49
|
-
app?.mount(container.value)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
// unmount
|
|
53
|
-
onUnmounted(() => {
|
|
54
|
-
app?.unmount()
|
|
55
|
-
app = null
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
return () => <div ref={container} />
|
|
59
|
-
},
|
|
60
|
-
})
|
package/src/types.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
type RendererStandardNode<T = THREE.Object3D> =
|
|
2
|
-
import('./core').MiniDom.RendererStandardNode<T>
|
|
3
|
-
type RootNode = import('./core/minidom').MiniDom.RendererRootNode
|
|
4
|
-
type VNodeProps = import('vue').VNodeProps
|
|
5
|
-
type VueApp<T> = import('vue').App<T>
|
|
6
|
-
type WatchSource = import('vue').WatchSource
|
|
7
|
-
type WatchStopHandle = import('vue').WatchStopHandle
|
|
8
|
-
type ThreeCamera = import('three').Camera
|
|
9
|
-
type ThreeRenderer = import('three').Renderer
|
|
10
|
-
type ThreeScene = import('three').Scene
|
|
11
|
-
|
|
12
|
-
export declare namespace Lunch {
|
|
13
|
-
/** Lunchbox app. */
|
|
14
|
-
type App = Omit<VueApp<any>, 'config'> & {
|
|
15
|
-
clearCustomRender: () => void
|
|
16
|
-
config: Omit<VueApp<any>['config'], 'globalProperties'> & {
|
|
17
|
-
globalProperties: {
|
|
18
|
-
lunchbox: {
|
|
19
|
-
afterRender: Lunch.UpdateCallback[]
|
|
20
|
-
beforeRender: Lunch.UpdateCallback[]
|
|
21
|
-
camera: ThreeCamera | null
|
|
22
|
-
dpr: number
|
|
23
|
-
frameId: number
|
|
24
|
-
renderer: ThreeRenderer | null
|
|
25
|
-
scene: ThreeScene | null
|
|
26
|
-
watchStopHandle: WatchStopHandle | null
|
|
27
|
-
}
|
|
28
|
-
} & Record<string, any>
|
|
29
|
-
}
|
|
30
|
-
customRender: ((opts: UpdateCallbackProperties) => void) | null
|
|
31
|
-
extend: (v: Record<string, any>) => App
|
|
32
|
-
rootNode: RootNode
|
|
33
|
-
setCustomRender: (
|
|
34
|
-
update: (opts: UpdateCallbackProperties) => void
|
|
35
|
-
) => void
|
|
36
|
-
update: UpdateCallback
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type AppGlobals = App['config']['globalProperties']['lunchbox']
|
|
40
|
-
|
|
41
|
-
type AppGlobalsUpdate = (newValue: Partial<AppGlobals>) => void
|
|
42
|
-
|
|
43
|
-
interface CanvasProps {
|
|
44
|
-
dpr?: number
|
|
45
|
-
wrapperProps?: WrapperProps
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Lunchbox component catalogue. */
|
|
49
|
-
interface Catalogue {
|
|
50
|
-
[key: string]: {
|
|
51
|
-
new (...args: any): { [key: string]: any }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface CommentMeta extends MetaBase {
|
|
56
|
-
text: string
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
type CustomRenderFunctionSetter = (
|
|
60
|
-
render: (opts: Lunch.UpdateCallbackProperties) => void
|
|
61
|
-
) => void
|
|
62
|
-
|
|
63
|
-
interface DomMeta extends MetaBase {
|
|
64
|
-
domElement: HTMLElement
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
type EventCallback = (options: {
|
|
68
|
-
intersection: THREE.Intersection<any>
|
|
69
|
-
}) => void
|
|
70
|
-
|
|
71
|
-
// MAKE SURE THESE MATCH VALUES IN lib.isEventKey
|
|
72
|
-
type EventKey =
|
|
73
|
-
| 'onClick'
|
|
74
|
-
| 'onContextMenu'
|
|
75
|
-
| 'onDoubleClick'
|
|
76
|
-
| 'onPointerUp'
|
|
77
|
-
| 'onPointerDown'
|
|
78
|
-
| 'onPointerOver'
|
|
79
|
-
| 'onPointerOut'
|
|
80
|
-
| 'onPointerEnter'
|
|
81
|
-
| 'onPointerLeave'
|
|
82
|
-
| 'onPointerMove'
|
|
83
|
-
// | 'onPointerMissed'
|
|
84
|
-
// 'onUpdate' |
|
|
85
|
-
| 'onWheel'
|
|
86
|
-
|
|
87
|
-
interface GenericThreeLoader<T = any> {
|
|
88
|
-
load(
|
|
89
|
-
src: string,
|
|
90
|
-
onLoad: (data: T) => void,
|
|
91
|
-
onProgress: null,
|
|
92
|
-
onError: (error: any) => void
|
|
93
|
-
): void
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Meta info needed on a standard Lunchbox node. */
|
|
97
|
-
interface StandardMeta<T = THREE.Object3D> extends MetaBase {
|
|
98
|
-
attached: { [key: string]: any }
|
|
99
|
-
attachedArray: { [key: string]: Array<any> }
|
|
100
|
-
instance: T | null
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Meta info that every node needs. */
|
|
104
|
-
interface MetaBase {
|
|
105
|
-
name: string | null | undefined
|
|
106
|
-
metaType: MetaType
|
|
107
|
-
props: LunchboxMetaProps
|
|
108
|
-
type: string | null
|
|
109
|
-
uuid: Uuid
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
type MetaType =
|
|
113
|
-
| 'commentMeta'
|
|
114
|
-
| 'domMeta'
|
|
115
|
-
| 'standardMeta'
|
|
116
|
-
| 'metaBase'
|
|
117
|
-
| 'rootMeta'
|
|
118
|
-
| 'textMeta'
|
|
119
|
-
|
|
120
|
-
interface RootMeta extends MetaBase {
|
|
121
|
-
domElement: HTMLElement
|
|
122
|
-
isLunchboxRootNode: boolean
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
type ShadowSugar =
|
|
126
|
-
| boolean
|
|
127
|
-
| {
|
|
128
|
-
type: THREE.ShadowMapType
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
interface TextMeta extends MetaBase {
|
|
132
|
-
text: string
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Props that can be passed to any Lunchbox meta. */
|
|
136
|
-
type LunchboxMetaProps = VNodeProps & {
|
|
137
|
-
args?: Array<any>
|
|
138
|
-
attach?: string
|
|
139
|
-
onAdded?<T>(opts: { instance: T | null }): void
|
|
140
|
-
|
|
141
|
-
[key: string]: any
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
type LunchboxComponent<T = THREE.Object3D> = {
|
|
145
|
-
$el: Node<T>
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
type Node<T = THREE.Object3D> = RendererStandardNode<T>
|
|
149
|
-
|
|
150
|
-
type UpdateCallback = (properties: UpdateCallbackProperties) => void
|
|
151
|
-
|
|
152
|
-
interface UpdateCallbackProperties {
|
|
153
|
-
app: App
|
|
154
|
-
scene?: THREE.Scene | null
|
|
155
|
-
renderer?: THREE.Renderer | null
|
|
156
|
-
camera?: THREE.Camera | null
|
|
157
|
-
updateSource?: WatchSource | null
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Universally unique identifier. */
|
|
161
|
-
type Uuid = string
|
|
162
|
-
|
|
163
|
-
type SizePolicy = 'full' | 'container'
|
|
164
|
-
|
|
165
|
-
type Vector3AsArray = [number, number, number]
|
|
166
|
-
|
|
167
|
-
interface WrapperProps {
|
|
168
|
-
background?: string
|
|
169
|
-
cameraArgs?: any[]
|
|
170
|
-
cameraLook?: Vector3AsArray
|
|
171
|
-
cameraLookAt?: Vector3AsArray
|
|
172
|
-
cameraPosition?: Vector3AsArray
|
|
173
|
-
dpr?: number
|
|
174
|
-
ortho?: boolean
|
|
175
|
-
orthographic?: boolean
|
|
176
|
-
r3f?: boolean
|
|
177
|
-
// TODO: Why doesn't ConstructorParameters<THREE.WebGLRenderer> work here?
|
|
178
|
-
rendererArguments?: object
|
|
179
|
-
rendererProperties?: Partial<THREE.WebGLRenderer>
|
|
180
|
-
sizePolicy?: SizePolicy
|
|
181
|
-
shadow?: ShadowSugar
|
|
182
|
-
transparent?: boolean
|
|
183
|
-
zoom?: number
|
|
184
|
-
updateSource?: WatchSource | null
|
|
185
|
-
}
|
|
186
|
-
}
|
package/src/utils/find.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Lunch } from '..'
|
|
2
|
-
import { isLunchboxComponent, isLunchboxStandardNode } from '.'
|
|
3
|
-
import { isRef, isVNode } from 'vue'
|
|
4
|
-
|
|
5
|
-
export function find<T extends object>(target: any) {
|
|
6
|
-
target = isRef(target) ? target.value : target
|
|
7
|
-
|
|
8
|
-
// handle standard lunchbox node
|
|
9
|
-
if (isLunchboxStandardNode(target)) {
|
|
10
|
-
return (target as Lunch.Node<T>)?.instance
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// handle component
|
|
14
|
-
if (isLunchboxComponent(target)) {
|
|
15
|
-
return (target as Lunch.LunchboxComponent<T>)?.$el?.instance
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// handle vnode
|
|
19
|
-
if (isVNode(target)) {
|
|
20
|
-
return (target.el as Lunch.Node<T>)?.instance
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return null
|
|
24
|
-
}
|
package/src/utils/get.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const get = <T = unknown>(
|
|
2
|
-
obj: Record<string, any>,
|
|
3
|
-
path: string | string[],
|
|
4
|
-
defValue?: T
|
|
5
|
-
) => {
|
|
6
|
-
// If path is not defined or it has false value
|
|
7
|
-
if (!path) return undefined
|
|
8
|
-
// Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
|
|
9
|
-
// Regex explained: https://regexr.com/58j0k
|
|
10
|
-
const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g)
|
|
11
|
-
// Find value
|
|
12
|
-
const result = pathArray?.reduce(
|
|
13
|
-
(prevObj: Record<string, any>, key: string) => prevObj && prevObj[key],
|
|
14
|
-
obj
|
|
15
|
-
)
|
|
16
|
-
// If found value is undefined return default value; otherwise return the value
|
|
17
|
-
return result === undefined ? defValue : result
|
|
18
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Lunch } from '..'
|
|
2
|
-
|
|
3
|
-
export * from './find'
|
|
4
|
-
|
|
5
|
-
// replacement functions from lodash & https://youmightnotneed.com/lodash
|
|
6
|
-
export * from './get'
|
|
7
|
-
export * from './isNumber'
|
|
8
|
-
export * from './set'
|
|
9
|
-
|
|
10
|
-
// MAKE SURE THESE MATCH VALUES IN types.EventKey
|
|
11
|
-
/** Type check on whether target is a Lunchbox.EventKey */
|
|
12
|
-
export const isEventKey = (target: any): target is Lunch.EventKey => {
|
|
13
|
-
return [
|
|
14
|
-
'onClick',
|
|
15
|
-
'onContextMenu',
|
|
16
|
-
'onDoubleClick',
|
|
17
|
-
'onPointerUp',
|
|
18
|
-
'onPointerDown',
|
|
19
|
-
'onPointerOver',
|
|
20
|
-
'onPointerOut',
|
|
21
|
-
'onPointerEnter',
|
|
22
|
-
'onPointerLeave',
|
|
23
|
-
'onPointerMove',
|
|
24
|
-
// 'onPointerMissed',
|
|
25
|
-
// 'onUpdate',
|
|
26
|
-
'onWheel',
|
|
27
|
-
].includes(target)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const isLunchboxComponent = (
|
|
31
|
-
node: any
|
|
32
|
-
): node is Lunch.LunchboxComponent => {
|
|
33
|
-
return node?.$el && node?.$el?.hasOwnProperty?.('instance')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const isLunchboxDomComponent = (node: any): node is Lunch.DomMeta => {
|
|
37
|
-
if ((node as Lunch.MetaBase)?.metaType === 'domMeta') return true
|
|
38
|
-
|
|
39
|
-
return node?.props?.['data-lunchbox']
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const isLunchboxStandardNode = (
|
|
43
|
-
node: any
|
|
44
|
-
): node is Lunch.StandardMeta => {
|
|
45
|
-
return node?.metaType === 'standardMeta'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const isLunchboxRootNode = (node: any): node is Lunch.RootMeta => {
|
|
49
|
-
return node.isLunchboxRootNode
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const waitFor = async (get: () => any) => {
|
|
53
|
-
let output = get()
|
|
54
|
-
while (!output) {
|
|
55
|
-
await new Promise((resolve) => requestAnimationFrame(resolve))
|
|
56
|
-
output = get()
|
|
57
|
-
console.log(output)
|
|
58
|
-
}
|
|
59
|
-
return output
|
|
60
|
-
}
|
package/src/utils/isNumber.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
const buildIsNumber = () => {
|
|
2
|
-
/**
|
|
3
|
-
* lodash (Custom Build) <https://lodash.com/>
|
|
4
|
-
* Build: `lodash modularize exports="npm" -o ./`
|
|
5
|
-
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
|
|
6
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
7
|
-
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
8
|
-
* Available under MIT license <https://lodash.com/license>
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** `Object#toString` result references. */
|
|
12
|
-
const numberTag = '[object Number]'
|
|
13
|
-
|
|
14
|
-
/** Used for built-in method references. */
|
|
15
|
-
const objectProto = Object.prototype
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Used to resolve the
|
|
19
|
-
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
|
20
|
-
* of values.
|
|
21
|
-
*/
|
|
22
|
-
const objectToString = objectProto.toString
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
|
26
|
-
* and has a `typeof` result of "object".
|
|
27
|
-
*
|
|
28
|
-
* @static
|
|
29
|
-
* @memberOf _
|
|
30
|
-
* @since 4.0.0
|
|
31
|
-
* @category Lang
|
|
32
|
-
* @param {*} value The value to check.
|
|
33
|
-
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|
34
|
-
* @example
|
|
35
|
-
*
|
|
36
|
-
* _.isObjectLike({});
|
|
37
|
-
* // => true
|
|
38
|
-
*
|
|
39
|
-
* _.isObjectLike([1, 2, 3]);
|
|
40
|
-
* // => true
|
|
41
|
-
*
|
|
42
|
-
* _.isObjectLike(_.noop);
|
|
43
|
-
* // => false
|
|
44
|
-
*
|
|
45
|
-
* _.isObjectLike(null);
|
|
46
|
-
* // => false
|
|
47
|
-
*/
|
|
48
|
-
function isObjectLike(value: any) {
|
|
49
|
-
return !!value && typeof value == 'object'
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Checks if `value` is classified as a `Number` primitive or object.
|
|
54
|
-
*
|
|
55
|
-
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
|
|
56
|
-
* classified as numbers, use the `_.isFinite` method.
|
|
57
|
-
*
|
|
58
|
-
* @static
|
|
59
|
-
* @memberOf _
|
|
60
|
-
* @since 0.1.0
|
|
61
|
-
* @category Lang
|
|
62
|
-
* @param {*} value The value to check.
|
|
63
|
-
* @returns {boolean} Returns `true` if `value` is a number, else `false`.
|
|
64
|
-
* @example
|
|
65
|
-
*
|
|
66
|
-
* _.isNumber(3);
|
|
67
|
-
* // => true
|
|
68
|
-
*
|
|
69
|
-
* _.isNumber(Number.MIN_VALUE);
|
|
70
|
-
* // => true
|
|
71
|
-
*
|
|
72
|
-
* _.isNumber(Infinity);
|
|
73
|
-
* // => true
|
|
74
|
-
*
|
|
75
|
-
* _.isNumber('3');
|
|
76
|
-
* // => false
|
|
77
|
-
*/
|
|
78
|
-
const output = function isNumber(value: any) {
|
|
79
|
-
return (
|
|
80
|
-
typeof value == 'number' ||
|
|
81
|
-
(isObjectLike(value) && objectToString.call(value) == numberTag)
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
return output
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const isNumber = buildIsNumber()
|
package/src/utils/set.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const set = (
|
|
2
|
-
obj: Record<string, any>,
|
|
3
|
-
path: string | string[],
|
|
4
|
-
value: any
|
|
5
|
-
) => {
|
|
6
|
-
// Regex explained: https://regexr.com/58j0k
|
|
7
|
-
const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g)
|
|
8
|
-
|
|
9
|
-
pathArray?.reduce((acc: Record<string, any>, key: string, i: number) => {
|
|
10
|
-
if (acc[key] === undefined) acc[key] = {}
|
|
11
|
-
if (i === pathArray.length - 1) acc[key] = value
|
|
12
|
-
return acc[key]
|
|
13
|
-
}, obj)
|
|
14
|
-
}
|