Skip to content

Commit

Permalink
Refactoring examples and changing the structure of the main page (#3)
Browse files Browse the repository at this point in the history
* convert example from vanilla to typescript

* fix

* fix imports

* fix test

* add case template
  • Loading branch information
matthew44-mappable authored Apr 4, 2024
1 parent b391715 commit e64946d
Show file tree
Hide file tree
Showing 20 changed files with 565 additions and 138 deletions.
Empty file.
8 changes: 8 additions & 0 deletions example/case-template/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {MMapLocationRequest, LngLatBounds} from '@mappable-world/mappable-types';

const BOUNDS: LngLatBounds = [
[54.58311, 25.9985],
[56.30248, 24.47889]
];

export const LOCATION: MMapLocationRequest = {bounds: BOUNDS};
37 changes: 37 additions & 0 deletions example/case-template/react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!doctype html>
<html>
<head>
<title>React example mappable-default-ui-theme</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<script crossorigin src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script src="https://js.api.mappable.world/3.0/?apikey=%APIKEY%&lang=en_US"></script>

<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="../../index.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="../common.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="./index.tsx"
></script>

<link rel="stylesheet" href="../../index.css" />
<link rel="stylesheet" href="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
40 changes: 40 additions & 0 deletions example/case-template/react/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {LOCATION} from '../common';

window.map = null;

main();
async function main() {
const [mappableReact] = await Promise.all([mappable.import('@mappable-world/mappable-reactify'), mappable.ready]);
const reactify = mappableReact.reactify.bindTo(React, ReactDOM);

const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapControls} = reactify.module(mappable);

const {useState, useCallback} = React;

const {MMapZoomControl} = reactify.module(await mappable.import('@mappable-world/[email protected]'));

const {MMapButtonExample} = reactify.module(await mappable.import('@mappable-world/mappable-default-ui-theme'));

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('app')
);

function App() {
const [location, setLocation] = useState(LOCATION);
const onClick = useCallback(() => alert('Click!'), []);

return (
<MMap location={location} ref={(x) => (map = x)}>
<MMapDefaultSchemeLayer />
<MMapDefaultFeaturesLayer />
<MMapControls position="right">
<MMapZoomControl />
<MMapButtonExample text={'My button'} onClick={onClick} />
</MMapControls>
</MMap>
);
}
}
35 changes: 35 additions & 0 deletions example/case-template/vanilla/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<html>
<head>
<title>Vanilla example mappable-default-ui-theme</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script src="https://js.api.mappable.world/3.0/?apikey=%APIKEY%&lang=en_US"></script>

<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="../../index.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../common.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="./index.ts"
></script>

<link rel="stylesheet" href="../../index.css" />
<link rel="stylesheet" href="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
22 changes: 22 additions & 0 deletions example/case-template/vanilla/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {LOCATION} from '../common';
window.map = null;

main();
async function main() {
await mappable.ready;
const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapControls} = mappable;

const {MMapZoomControl} = await mappable.import('@mappable-world/[email protected]');
const {MMapButtonExample} = await mappable.import('@mappable-world/mappable-default-ui-theme');

map = new MMap(document.getElementById('app'), {location: LOCATION});

map.addChild(new MMapDefaultSchemeLayer({}));
map.addChild(new MMapDefaultFeaturesLayer({}));

map.addChild(
new MMapControls({position: 'right'})
.addChild(new MMapZoomControl({}))
.addChild(new MMapButtonExample({text: 'My button', onClick: () => alert('Click!')}))
);
}
36 changes: 36 additions & 0 deletions example/case-template/vue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!doctype html>
<html>
<head>
<title>Vue example mappable-default-ui-theme</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script crossorigin src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script src="https://js.api.mappable.world/3.0/?apikey=%APIKEY%&lang=en_US"></script>

<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="../../index.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../common.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="./index.ts"
></script>

<link rel="stylesheet" href="../../index.css" />
<link rel="stylesheet" href="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
43 changes: 43 additions & 0 deletions example/case-template/vue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {LOCATION} from '../common';

window.map = null;

main();
async function main() {
const [mappableVue] = await Promise.all([mappable.import('@mappable-world/mappable-vuefy'), mappable.ready]);
const vuefy = mappableVue.vuefy.bindTo(Vue);

const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapControls} = vuefy.module(mappable);

const {MMapZoomControl} = vuefy.module(await mappable.import('@mappable-world/[email protected]'));

const {MMapButtonExample} = vuefy.module(await mappable.import('@mappable-world/mappable-default-ui-theme'));

const app = Vue.createApp({
components: {
MMap,
MMapDefaultSchemeLayer,
MMapDefaultFeaturesLayer,
MMapControls,
MMapZoomControl,
MMapButtonExample
},
setup() {
const refMap = (ref) => {
window.map = ref?.entity;
};
const onClick = () => alert('Click!');
return {LOCATION, refMap, onClick};
},
template: `
<MMap :location="LOCATION" :ref="refMap">
<MMapDefaultSchemeLayer />
<MMapDefaultFeaturesLayer />
<MMapControls position="right">
<MMapZoomControl />
<MMapButtonExample text="My button" :onClick="onClick" />
</MMapControls>
</MMap>`
});
app.mount('#app');
}
File renamed without changes.
6 changes: 3 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<title>Example @mappable-world/mappable-default-ui-theme</title>
Expand All @@ -8,10 +8,10 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="./common.css" />
<link rel="stylesheet" href="./index.css" />
</head>
<body>
<iframe width="100%" height="500px" src="./vanilla.html" frameborder="0"></iframe>
<!-- <iframe width="100%" height="500px" src="./vanilla/index.html" frameborder="0"></iframe> -->
<div class="content">
<div class="version">%VERSION%</div>
%README%
Expand Down
13 changes: 2 additions & 11 deletions example/common.js → example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ mappable.import.loaders.unshift(async (pkg) => {
} else {
await mappable.import.script(`https://unpkg.com/${pkg}/dist/index.js`);
}

// @ts-ignore
return window['@mappable-world/mappable-default-ui-theme'];
})


const BOUNDS = [
[54.58311, 25.99850],
[56.30248, 24.47889]
];

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const LOCATION = {bounds: BOUNDS};
});
64 changes: 0 additions & 64 deletions example/react.html

This file was deleted.

9 changes: 9 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"strict": false,
"rootDirs": ["./", "../"],
"types": ["./types.d.ts", "../types/index.d.ts"]
},
"include": ["./**/*.ts", "./**/*.tsx"]
}
14 changes: 14 additions & 0 deletions example/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MMap} from '@mappable-world/mappable-types';

declare global {
const React: typeof import('react');
const ReactDOM: typeof import('react-dom');
const Vue: typeof import('@vue/runtime-dom');
let map: MMap;

interface Window {
map: MMap;
}
}

export {};
38 changes: 0 additions & 38 deletions example/vanilla.html

This file was deleted.

Loading

0 comments on commit e64946d

Please sign in to comment.