Skip to content

Commit

Permalink
Add prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Apr 23, 2024
1 parent 9a7d225 commit baa8821
Show file tree
Hide file tree
Showing 47 changed files with 2,521 additions and 1,484 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
104 changes: 56 additions & 48 deletions lib/components/button.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { defineComponent, h, type PropType, ref, type SlotsType, warn, watch } from 'vue';
import {
defineComponent,
h,
type PropType,
ref,
type SlotsType,
warn,
watch,
} from "vue";

export enum ButtonType {
DEFAULT = 'default',
TEXT = 'text',
MDI = 'mdi',
SIMPLE_ICON = 'simple-icons',
DEFAULT = "default",
TEXT = "text",
MDI = "mdi",
SIMPLE_ICON = "simple-icons",
}

export const ButtonTypeValues = Object.values(ButtonType);
Expand All @@ -15,67 +23,67 @@ interface Default {
}

const types: { [key in ButtonType]?: Default } = {
[ ButtonType.TEXT ] : undefined,
[ ButtonType.MDI ] : {
size : 21,
viewbox: '0 0 24 24'
[ButtonType.TEXT]: undefined,
[ButtonType.MDI]: {
size: 21,
viewbox: "0 0 24 24",
},
[ ButtonType.SIMPLE_ICON ]: {
size : 21,
viewbox: '0 0 24 24'
[ButtonType.SIMPLE_ICON]: {
size: 21,
viewbox: "0 0 24 24",
},
[ButtonType.DEFAULT]: {
size: 0,
viewbox: "0 0 0 0",
},
[ ButtonType.DEFAULT ] : {
size : 0,
viewbox: '0 0 0 0'
}
};


export default /*#__PURE__*/ defineComponent({
name : 'MglButton',
name: "MglButton",
props: {
type : {
type : String as PropType<ButtonType | 'default' | 'text' | 'mdi' | 'simple-icons'>,
default : ButtonType.DEFAULT,
type: {
type: String as PropType<
ButtonType | "default" | "text" | "mdi" | "simple-icons"
>,
default: ButtonType.DEFAULT,
validator: (v: ButtonType) => {
return ButtonTypeValues.indexOf(v) !== -1;
}
return ButtonTypeValues.indexOf(v) !== -1;
},
},
path : {
type: String as PropType<string>
path: {
type: String as PropType<string>,
},
size : Number as PropType<number>,
viewbox: String as PropType<string>
size: Number as PropType<number>,
viewbox: String as PropType<string>,
},
slots: Object as SlotsType<{ default: {} }>,
setup(props, { slots }) {

if (!props.path && props.type !== ButtonType.TEXT) {
warn('property `path` must be set on MaplibreButton');
warn("property `path` must be set on MaplibreButton");
}

const defaults = ref(types[ props.type ] || types.default);
watch(() => props.type, v => defaults.value = types[ v ] || types.default);
const defaults = ref(types[props.type] || types.default);
watch(
() => props.type,
(v) => (defaults.value = types[v] || types.default),
);

return () => {
if (props.type === ButtonType.TEXT) {
return h('button', { type: 'button' }, slots.default?.({}));
return h("button", { type: "button" }, slots.default?.({}));
}
return h('button', { type: 'button', 'class': 'maplibregl-ctrl-icon' },
[
h(
'svg',
{
width : props.size || defaults.value!.size,
height : props.size || defaults.value!.size,
viewBox: props.viewbox || defaults.value!.viewbox
},
h('path', { fill: 'currentColor', d: props.path })
),
slots.default?.({})
]
);
return h("button", { type: "button", class: "maplibregl-ctrl-icon" }, [
h(
"svg",
{
width: props.size || defaults.value!.size,
height: props.size || defaults.value!.size,
viewBox: props.viewbox || defaults.value!.viewbox,
},
h("path", { fill: "currentColor", d: props.path }),
),
slots.default?.({}),
]);
};

}
},
});
44 changes: 26 additions & 18 deletions lib/components/controls/attribution.control.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { defineComponent, inject, onBeforeUnmount, type PropType } from 'vue';
import { AttributionControl } from 'maplibre-gl';
import { Position, type PositionProp, PositionValues } from '@/lib/components/controls/position.enum';
import { isInitializedSymbol, mapSymbol } from '@/lib/types';
import { usePositionWatcher } from '@/lib/composable/usePositionWatcher';
import { defineComponent, inject, onBeforeUnmount, type PropType } from "vue";
import { AttributionControl } from "maplibre-gl";
import {
Position,
type PositionProp,
PositionValues,
} from "@/lib/components/controls/position.enum";
import { isInitializedSymbol, mapSymbol } from "@/lib/types";
import { usePositionWatcher } from "@/lib/composable/usePositionWatcher";

export default /*#__PURE__*/ defineComponent({
name : 'MglAttributionControl',
name: "MglAttributionControl",
props: {
position : {
type : String as PropType<PositionProp>,
position: {
type: String as PropType<PositionProp>,
validator: (v: Position) => {
return PositionValues.indexOf(v) !== -1;
}
return PositionValues.indexOf(v) !== -1;
},
},
compact : Boolean as PropType<boolean>,
customAttribution: [ String, Array ] as PropType<string | string[]>
compact: Boolean as PropType<boolean>,
customAttribution: [String, Array] as PropType<string | string[]>,
},
setup(props) {
const map = inject(mapSymbol)!,
isInitialized = inject(isInitializedSymbol)!,
control = new AttributionControl({ compact: props.compact, customAttribution: props.customAttribution });
const map = inject(mapSymbol)!,
isInitialized = inject(isInitializedSymbol)!,
control = new AttributionControl({
compact: props.compact,
customAttribution: props.customAttribution,
});

usePositionWatcher(() => props.position, map, control);
onBeforeUnmount(() => isInitialized.value && map.value!.removeControl(control));

}
onBeforeUnmount(
() => isInitialized.value && map.value!.removeControl(control),
);
},
});
88 changes: 52 additions & 36 deletions lib/components/controls/custom.control.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import { createCommentVNode, defineComponent, h, inject, nextTick, onBeforeUnmount, type PropType, ref, Ref, type SlotsType, Teleport, watch } from 'vue';
import { Position, type PositionProp, PositionValues } from '@/lib/components/controls/position.enum';
import type { ControlPosition, IControl } from 'maplibre-gl';
import { isInitializedSymbol, mapSymbol } from '@/lib/types';
import { usePositionWatcher } from '@/lib/composable/usePositionWatcher';

import {
createCommentVNode,
defineComponent,
h,
inject,
nextTick,
onBeforeUnmount,
type PropType,
ref,
Ref,
type SlotsType,
Teleport,
watch,
} from "vue";
import {
Position,
type PositionProp,
PositionValues,
} from "@/lib/components/controls/position.enum";
import type { ControlPosition, IControl } from "maplibre-gl";
import { isInitializedSymbol, mapSymbol } from "@/lib/types";
import { usePositionWatcher } from "@/lib/composable/usePositionWatcher";

export class CustomControl implements IControl {

public static readonly CONTROL_CLASS = 'maplibregl-ctrl';
public static readonly CONTROL_GROUP_CLASS = 'maplibregl-ctrl-group';
public static readonly CONTROL_CLASS = "maplibregl-ctrl";
public static readonly CONTROL_GROUP_CLASS = "maplibregl-ctrl-group";

public readonly container: HTMLDivElement;

constructor(private isAdded: Ref<boolean>, noClasses: boolean) {
this.container = document.createElement('div');
constructor(
private isAdded: Ref<boolean>,
noClasses: boolean,
) {
this.container = document.createElement("div");
this.setClasses(noClasses);
}

Expand All @@ -22,7 +40,7 @@ export class CustomControl implements IControl {
}

onAdd(): HTMLElement {
nextTick(() => this.isAdded.value = true);
nextTick(() => (this.isAdded.value = true));
return this.container;
}

Expand All @@ -40,45 +58,43 @@ export class CustomControl implements IControl {
this.container.classList.add(CustomControl.CONTROL_GROUP_CLASS);
}
}

}

export default /*#__PURE__*/ defineComponent({
name : 'MglCustomControl',
name: "MglCustomControl",
props: {
position : {
type : String as PropType<PositionProp>,
position: {
type: String as PropType<PositionProp>,
validator: (v: Position) => {
return PositionValues.indexOf(v) !== -1;
}
return PositionValues.indexOf(v) !== -1;
},
},
noClasses: {
type : Boolean as PropType<boolean>,
default: false
}
type: Boolean as PropType<boolean>,
default: false,
},
},
slots: Object as SlotsType<{ default: {} }>,
setup(props, { slots }) {

const map = inject(mapSymbol)!,
isInitialized = inject(isInitializedSymbol)!,
isAdded = ref(false),
control = new CustomControl(isAdded, props.noClasses!);
const map = inject(mapSymbol)!,
isInitialized = inject(isInitializedSymbol)!,
isAdded = ref(false),
control = new CustomControl(isAdded, props.noClasses!);

usePositionWatcher(() => props.position, map, control);
watch(() => props.noClasses, v => control.setClasses(v!));
onBeforeUnmount(() => isInitialized.value && map.value?.removeControl(control));
watch(
() => props.noClasses,
(v) => control.setClasses(v!),
);
onBeforeUnmount(
() => isInitialized.value && map.value?.removeControl(control),
);

return () => {
if (!isAdded.value) {
return createCommentVNode('custom-component');
return createCommentVNode("custom-component");
}
return h(
Teleport as any,
{ to: control.container },
slots.default?.({})
);
return h(Teleport as any, { to: control.container }, slots.default?.({}));
};

}
},
});
Loading

0 comments on commit baa8821

Please sign in to comment.