Vuefy module
Quick start
Note: Supported Vue version at least 3
To start using the Vue version of the API, just connect the @mappable-world/mappable-vuefy
:
const mappableVue = await mappable.import('@mappable-world/mappable-vuefy');
const vuefy = mappableVue.vuefy.bindTo(Vue);
const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapMarker} = vuefy.module(mappable);
And then use any JS API objects as Vue components:
<template>
<MMap :location="location">
<MMapDefaultSchemeLayer />
<MMapDefaultFeaturesLayer />
<MMapMarker :coordinates="[34, 57]" draggable>
<div class="marker marker_pill">I'm marker!</div>
</MMapMarker>
</MMap>
</template>
Props Declaration for own custom classes
Vue components require explicit declaration of requisites so that Vue knows which external requisites passed to the component should be considered as fallthrough attributes.
For basic objects from the mappable
namespace, attributes are defined by default and no additional actions need to be done.
If you are a developer who creates your own objects (for example, within a separate package), then you can define which props will be in the component. The definition of props supports the Vue format. For example the custom class MMapSomeClass
:
type MMapSomeClassProps = {
id: string;
counter?: number;
};
export class MMapSomeClass extends mappable.MMapComplexEntity<MMapSomeClassProps> {
static [mappableVue.vuefy.optionsKey] = {props: ['id', 'counter']};
//...
}
In addition to declaring props using an array of strings, we can also use the object syntax:
export class MMapSomeClass extends mappable.MMapComplexEntity<MMapSomeClassProps> {
static [mappableVue.vuefy.optionsKey] = {
props: {
id: String,
counter: Number
}
};
//...
}
or with props validation:
export class MMapSomeClass extends mappable.MMapComplexEntity<MMapSomeClassProps> {
static [mappableVue.vuefy.optionsKey] = {
props: {
id: {type: String, required: true},
counter: {type: Number, required: false}
}
};
//...
}
Props Declaration for using third-party packages
If the developers of third-party packages have not defined the props for their classes, then you can specify them yourself when calling vuefy by passing them as the second argument:
const mappableVue = await mappable.import('@mappable-world/mappable-vuefy');
const vuefy = mappableVue.vuefy.bindTo(Vue);
const {MMapSomeClass as MMapSomeClassV} = vuefy.module(
{MMapSomeClass},
{
MMapSomeClass: ['id', 'counter']
}
);
Similarly, the syntax of the object and validation is supported.
Custom implementations for Vue mappable.MMapEntity entities
Use the overrideKey
key to define a custom implementation for vuefy:
type MMapSomeClassProps = {
id: string;
counter?: number;
};
export class MMapSomeClass extends mappable.MMapComplexEntity<MMapSomeClassProps> {
static [mappableVue.vuefy.overrideKey] = MMapSomeClassVuefyOverride;
//...
}
and
export const MMapSomeClassVuefyOverride: CustomVuefyFn<MMapSomeClass> = (
MMapSomeClassI, // it is same MMapSomeClass
props, // props declaration
{vuefy, Vue}
) => {
// Standard vuefy method
const MMapSomeClassVuefied = vuefy.entity(MMapSomeClassI, props);
const MMapSomeClassV = Vue.defineComponent({
props,
name: 'MMapSomeClassV',
components: {MMapSomeClassVuefied},
setup() {
//...
},
template: `<MMapSomeClassVuefied v-bind="$props" ... />`
});
return MMapSomeClassV;
};
and in the end app
const mappableVue = await mappable.import('@mappable-world/mappable-vuefy');
const vuefy = mappableVue.vuefy.bindTo(Vue);
const {MMapSomeClass as MMapSomeClassV} = vuefy.module({MMapSomeClass});
const app = createApp({
components: {MMapSomeClassV},
template: `<MMapSomeClassV id="some_id" />`
});
app.mount('#app');
Class: Context<_T>
Type parameters
Name |
---|
_T |
Constructors
constructor
new Context<_T
>(name
)
Type parameters
Name |
---|
_T |
Parameters
Name | Type |
---|---|
name |
string |
Properties
name
readonly name: string
Class: GenericComplexEntity<Props, DefaultProps, Root>
Entity that aggregates multiple Entities but looks basic from the outside.
Example
type MMapSomeComplexEntityProps = {
name?: string;
};
const defaultProps = {
name: 'entity'
};
class MMapSomeComplexEntity extends GenericComplexEntity<MMapSomeComplexEntityProps, typeof defaultProps> {
static defaultProps = defaultProps;
private _someEntity?: MMapSomeEntity; // MMapSomeEntity extends GenericEntity
protected _onAttach(): void {
this._someEntity = new MMapSomeEntity();
this.addChild(this._someEntity); // add someEntity as children
// ...
}
// ...
}
Type parameters
Name | Type | Description |
---|---|---|
Props |
Props |
Type of input props of the Entity. |
DefaultProps |
extends Object = {} |
Type of default input props of the Entity. |
Root |
extends GenericRootEntity <unknown > = GenericRootEntity <unknown > |
Root Entity Class. |
Constructors
constructor
new GenericComplexEntity<Props
, DefaultProps
, Root
>(props
, options?
)
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Object = {} |
Root |
extends GenericRootEntity <unknown , {}, Root > = GenericRootEntity <unknown , {}> |
Parameters
Name | Type | Description |
---|---|---|
props |
Props |
The value of input props. |
options? |
ComplexOptions <Root > |
Optional options object. |
Overrides
new GenericComplexEntity<Props
, DefaultProps
, Root
>(props
, children?
, options?
)
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Object = {} |
Root |
extends GenericRootEntity <unknown , {}, Root > = GenericRootEntity <unknown , {}> |
Parameters
Name | Type |
---|---|
props |
Props |
children? |
GenericEntity <unknown , {}, Root >[] |
options? |
Omit <ComplexOptions <Root >, "children" > |
Overrides
GenericEntity<Props, DefaultProps, Root>.constructor
Accessors
parent
get
parent(): null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
Get parent entity.
Returns
null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
Inherited from
GenericEntity.parent
root
get
root(): null
| Root
Get root entity.
Returns
null
| Root
Inherited from
GenericEntity.root
Methods
update
update(changedProps
): void
Method for updating props of Entity.
Parameters
Name | Type | Description |
---|---|---|
changedProps |
Partial <Props > |
New props values. |
Returns
void
Inherited from
Class: GenericEntity<Props, DefaultProps, Root>
Entity Base Class. It has event handlers for attaching, detaching and updating props. Has a method for providing and using context.
Example
type MMapSomeEntityProps = {
name?: string;
};
const defaultProps = {
name: 'entity'
};
class MMapSomeEntity extends GenericEntity<MMapSomeEntityProps, typeof defaultProps> {
static defaultProps = defaultProps;
public isAttached: boolean;
constructor(props: MMapSomeEntityProps) {
super(props);
this.isAttached = false
// Additional actions can be taken in the constructor of a class.
}
protected _onAttach(): void {
this.isAttached = true;
// Additional actions can be taken when an Entity is attached.
}
// ...
}
Type parameters
Name | Type | Description |
---|---|---|
Props |
Props |
Type of input props of the Entity. |
DefaultProps |
extends Object = {} |
Type of default input props of the Entity. |
Root |
extends GenericRootEntity <unknown > = GenericRootEntity <unknown > |
Root Entity Class. |
Constructors
constructor
new GenericEntity<Props
, DefaultProps
, Root
>(props
)
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Object = {} |
Root |
extends GenericRootEntity <unknown , {}, Root > = GenericRootEntity <unknown , {}> |
Parameters
Name | Type | Description |
---|---|---|
props |
Props |
The value of input props. |
Accessors
parent
get
parent(): null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
Get parent entity.
Returns
null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
root
get
root(): null
| Root
Get root entity.
Returns
null
| Root
Methods
update
update(changedProps
): void
Method for updating props of Entity.
Parameters
Name | Type | Description |
---|---|---|
changedProps |
Partial <Props > |
New props values. |
Returns
void
Class: GenericGroupEntity<Props, DefaultProps, Root>
Entity that aggregates multiple Entities, and allows you to publicly add and remove entities to a subtree.
Example
type MMapSomeGroupEntityProps = {
name?: string;
};
const defaultProps = {
name: 'entity'
};
class MMapSomeGroupEntity extends GenericGroupEntity<MMapSomeGroupEntityProps, typeof defaultProps> {
static defaultProps = defaultProps;
// ...
}
const groupEntity = new MMapSomeGroupEntity()
const someEntity = new MMapSomeEntity(); // MMapSomeEntity extends GenericEntity
groupEntity.addChild(someEntity); // add someEntity in MMapSomeGroupEntity object
groupEntity.removeChild(someEntity); // remove someEntity from MMapSomeGroupEntity object
Type parameters
Name | Type | Description |
---|---|---|
Props |
Props |
Type of input props of the Entity. |
DefaultProps |
extends Object = {} |
Type of default input props of the Entity. |
Root |
extends GenericRootEntity <unknown > = GenericRootEntity <unknown > |
Root Entity Class. |
Constructors
constructor
new GenericGroupEntity<Props
, DefaultProps
, Root
>(props
, options?
)
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Object = {} |
Root |
extends GenericRootEntity <unknown , {}, Root > = GenericRootEntity <unknown , {}> |
Parameters
Name | Type | Description |
---|---|---|
props |
Props |
The value of input props. |
options? |
ComplexOptions <Root > |
Optional options object. |
Inherited from
GenericComplexEntity.constructor
new GenericGroupEntity<Props
, DefaultProps
, Root
>(props
, children?
, options?
)
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Object = {} |
Root |
extends GenericRootEntity <unknown , {}, Root > = GenericRootEntity <unknown , {}> |
Parameters
Name | Type |
---|---|
props |
Props |
children? |
GenericEntity <unknown , {}, Root >[] |
options? |
Omit <ComplexOptions <Root >, "children" > |
Inherited from
GenericComplexEntity.constructor
Properties
children
readonly children: readonly GenericEntity<unknown, {}, Root>[]
Overrides
GenericComplexEntity.children
Accessors
parent
get
parent(): null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
Get parent entity.
Returns
null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
Inherited from
GenericComplexEntity.parent
root
get
root(): null
| Root
Get root entity.
Returns
null
| Root
Inherited from
GenericComplexEntity.root
Methods
addChild
addChild(child
, index?
): GenericGroupEntity
<Props
, DefaultProps
, Root
>
Parameters
Name | Type |
---|---|
child |
GenericEntity <unknown , {}, Root > |
index? |
number |
Returns
GenericGroupEntity
<Props
, DefaultProps
, Root
>
Overrides
GenericComplexEntity.addChild
removeChild
removeChild(child
): GenericGroupEntity
<Props
, DefaultProps
, Root
>
Parameters
Name | Type |
---|---|
child |
GenericEntity <unknown , {}, Root > |
Returns
GenericGroupEntity
<Props
, DefaultProps
, Root
>
Overrides
GenericComplexEntity.removeChild
update
update(changedProps
): void
Method for updating props of Entity.
Parameters
Name | Type | Description |
---|---|---|
changedProps |
Partial <Props > |
New props values. |
Returns
void
Inherited from
Class: GenericRootEntity<Props, DefaultProps>
Entity that is root and cannot be added anywhere
Example
type MMapProps = {
name?: string;
};
class MMap extends GenericRootEntity<MMapProps, typeof defaultProps> {
// ...
}
// Now we can specify their root element for the Entity
class MMapSomeEntity extends GenericEntity<MMapSomeEntityProps, typeof defaultProps, MMap> {
static defaultProps = defaultProps;
// ...
}
Type parameters
Name | Type | Description |
---|---|---|
Props |
Props |
Type of input props of the Entity. |
DefaultProps |
extends Object = {} |
Type of default input props of the Entity. |
Constructors
constructor
new GenericRootEntity<Props
, DefaultProps
>(props
, options?
)
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Object = {} |
Parameters
Name | Type | Description |
---|---|---|
props |
Props |
The value of input props. |
options? |
ComplexOptions <GenericRootEntity <unknown , {}>> |
Optional options object. |
Inherited from
GenericGroupEntity.constructor
new GenericRootEntity<Props
, DefaultProps
>(props
, children?
, options?
)
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Object = {} |
Parameters
Name | Type |
---|---|
props |
Props |
children? |
GenericEntity <unknown , {}, GenericRootEntity <unknown , {}>>[] |
options? |
Omit <ComplexOptions <GenericRootEntity <unknown , {}>>, "children" > |
Inherited from
GenericGroupEntity.constructor
Properties
children
readonly children: readonly GenericEntity<unknown, {}, GenericRootEntity<unknown, {}>>[]
Inherited from
Accessors
parent
get
parent(): null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
Get parent entity.
Returns
null
| GenericComplexEntity
<unknown
, {}, GenericRootEntity
<unknown
, {}>>
Inherited from
GenericGroupEntity.parent
root
get
root(): this
Get root entity.
Returns
this
Overrides
GenericGroupEntity.root
Methods
addChild
addChild(child
, index?
): GenericRootEntity
<Props
, DefaultProps
>
Parameters
Name | Type |
---|---|
child |
GenericEntity <unknown , {}, GenericRootEntity <unknown , {}>> |
index? |
number |
Returns
GenericRootEntity
<Props
, DefaultProps
>
Inherited from
destroy
Abstract
destroy(): void
Completely destroys the entity tree including the current entity
Returns
void
removeChild
removeChild(child
): GenericRootEntity
<Props
, DefaultProps
>
Parameters
Name | Type |
---|---|
child |
GenericEntity <unknown , {}, GenericRootEntity <unknown , {}>> |
Returns
GenericRootEntity
<Props
, DefaultProps
>
Inherited from
GenericGroupEntity.removeChild
update
update(changedProps
): void
Method for updating props of Entity.
Parameters
Name | Type | Description |
---|---|---|
changedProps |
Partial <Props > |
New props values. |
Returns
void
Inherited from
Interface: ComplexOptions<Root>
Type parameters
Name | Type |
---|---|
Root |
extends GenericRootEntity <unknown > = GenericRootEntity <unknown > |
Properties
children
optional children: GenericEntity<unknown, {}, Root>[]
container
optional container: boolean
Interface: VuefyModuleFn
Callable
VuefyModuleFn
VuefyModuleFn<TModule
>(module
, props?
): VuefiedModule
<TModule
>
Type parameters
Name | Type |
---|---|
TModule |
extends BaseModule = BaseModule |
Parameters
Name | Type |
---|---|
module |
TModule |
props? |
VuefyPropsModule <TModule > |
Returns
VuefiedModule
<TModule
>
Type Aliases
CustomVuefyFn
CustomVuefyFn<TEntity,
TExternalProps\>: (`ctor`: EntityConstructor<TEntity>, `props`: VuefyPropsObject<TExternalProps>, `params`: {
Vue: typeof TVue;
vuefy: {
context: VuefyContextFn;
entity: VuefyEntityFn;
module: VuefyModuleFn
}
}) => TVue.Component<TExternalProps>
Type parameters
Name | Type |
---|---|
TEntity |
extends DefaultEntity |
TExternalProps |
EntityProps <TEntity > |
Type declaration
(ctor
, props
, params
): TVue.Component
<TExternalProps
>
Parameters
Name | Type |
---|---|
ctor |
EntityConstructor <TEntity > |
props |
VuefyPropsObject <TExternalProps > |
params |
Object |
params.Vue |
typeof TVue |
params.vuefy |
Object |
params.vuefy.context |
VuefyContextFn |
params.vuefy.entity |
VuefyEntityFn |
params.vuefy.module |
VuefyModuleFn |
Returns
TVue.Component
<TExternalProps
>
CustomVuefyOptions
CustomVuefyOptions<TEntity,
TExternalProps\>: Object
Type parameters
Name | Type |
---|---|
TEntity |
extends DefaultEntity |
TExternalProps |
EntityProps <TEntity > |
Type declaration
Name | Type |
---|---|
props |
VuefyPropsObject <TExternalProps > | VuefyPropsArray <TExternalProps > |
GenericVuefy
GenericVuefy: Object
Type declaration
Name | Type |
---|---|
optionsKey |
typeof optionsKeyVuefy |
overrideKey |
typeof overrideKeyVuefy |
bindTo |
(Vue : __module ) => Vuefy |
Vuefy
Vuefy: Object
Type declaration
Name | Type |
---|---|
entity |
VuefyEntityFn |
module |
VuefyModuleFn |
Variables
vuefy
const vuefy: Readonly<GenericVuefy>
Module: <internal>
Type Aliases
BaseModule
BaseModule: Record<string | symbol, unknown>
ContextWatcherFn
ContextWatcherFn: () => void
Type declaration
(): void
Returns
void
DefaultContext
DefaultContext: Context<unknown>
DefaultCtor
DefaultCtor: EntityConstructor<DefaultEntity>
DefaultEntity
DefaultEntity: GenericEntity<unknown>
EntityConstructor
EntityConstructor<TEntity\>: (...`args`: any[]) => TEntity
Type parameters
Name | Type |
---|---|
TEntity |
extends GenericEntity <unknown > |
Type declaration
(...args
)
Parameters
Name | Type |
---|---|
...args |
any [] |
EntityProps
EntityProps<T\>: T extends GenericEntity<infer P> ? P : never
Type parameters
Name | Type |
---|---|
T |
extends GenericEntity <unknown > |
PropsFromCtor
PropsFromCtor<TCtor\>: EntityProps<InstanceType<TCtor>>
Type parameters
Name | Type |
---|---|
TCtor |
extends DefaultCtor |
VuefiedModule
VuefiedModule<TModule\>: { [Property in keyof TModule]: TModule[Property] extends DefaultCtor ? ReturnType<VuefyEntityFnGen<TModule[Property]\>\> : TModule[Property] extends typeof Context ? ReturnType<VuefyContextFn\> : TModule[Property] }
Type parameters
Name | Type |
---|---|
TModule |
extends BaseModule |
VuefyContextFn
VuefyContextFn: <TContext>(`context?`: TContext) => symbol
Type declaration
<TContext
>(context?
): symbol
Type parameters
Name | Type |
---|---|
TContext |
extends DefaultContext |
Parameters
Name | Type |
---|---|
context? |
TContext |
Returns
symbol
VuefyEntityFn
VuefyEntityFn: <TCtor, TProps>(...`args`: Parameters<VuefyEntityFnGen<TCtor, TProps>>) => ReturnType<VuefyEntityFnGen<TCtor, TProps>>
Type declaration
<TCtor
, TProps
>(...args
): ReturnType
<VuefyEntityFnGen
<TCtor
, TProps
>>
Type parameters
Name | Type |
---|---|
TCtor |
extends DefaultCtor |
TProps |
PropsFromCtor <TCtor > |
Parameters
Name | Type |
---|---|
...args |
Parameters <VuefyEntityFnGen <TCtor , TProps >> |
Returns
ReturnType
<VuefyEntityFnGen
<TCtor
, TProps
>>
VuefyEntityFnGen
VuefyEntityFnGen<TCtor,
TProps\>: (`ctor`: TCtor, `props?`: VuefyPropsObject<TProps> | VuefyPropsArray<TProps>, `displayName?`: string) => TVue.Component<TProps>
Type parameters
Name | Type |
---|---|
TCtor |
extends DefaultCtor |
TProps |
PropsFromCtor <TCtor > |
Type declaration
(ctor
, props?
, displayName?
): TVue.Component
<TProps
>
Parameters
Name | Type |
---|---|
ctor |
TCtor |
props? |
VuefyPropsObject <TProps > | VuefyPropsArray <TProps > |
displayName? |
string |
Returns
TVue.Component
<TProps
>
VuefyPropsArray
VuefyPropsArray<RawProps\>: keyof RawProps[]
Type parameters
Name |
---|
RawProps |
VuefyPropsModule
VuefyPropsModule<TModule\>: { [Key in keyof TModule]: TModule[Key] extends GenericEntity<infer Props\> ? VuefyPropsObject<Props\> \| VuefyPropsArray<Props\> : unknown }
Type parameters
Name | Type |
---|---|
TModule |
extends BaseModule |
VuefyPropsObject
VuefyPropsObject<RawProps\>: { [K in keyof RawProps]-?: TVue.PropType<RawProps[K]\> \| TVue.Prop<RawProps[K]\> }
Type parameters
Name |
---|
RawProps |
WithDefaults
WithDefaults<Props,
DefaultProps\>: Props & { [K in keyof DefaultProps]: K extends keyof Props ? NonNullable<Props[K]\> : never }
Type parameters
Name | Type |
---|---|
Props |
Props |
DefaultProps |
extends Partial <Props > |
Variables
optionsKeyVuefy
const optionsKeyVuefy: unique symbol
overrideKeyVuefy
const overrideKeyVuefy: unique symbol