Skip to content

Commit

Permalink
ts examples + vue
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew44-mappable committed Mar 6, 2024
1 parent 3215e92 commit 0cbf7e6
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 2 deletions.
22 changes: 22 additions & 0 deletions template/example/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type {MMapLocationRequest, LngLatBounds} from '@mappable-world/mappable-types';

mappable.import.loaders.unshift(async (pkg) => {
if (!pkg.startsWith('%PACKAGE_NAME%')) {
return;
}

if (location.href.includes('localhost')) {
await mappable.import.script(`/dist/index.js`);
} else {
await mappable.import.script(`https://unpkg.com/${pkg}/dist/index.js`);
}

return window['%PACKAGE_NAME%'];
});

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

export const LOCATION: MMapLocationRequest = {bounds: BOUNDS};
2 changes: 1 addition & 1 deletion template/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link rel="stylesheet" href="./common.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
30 changes: 30 additions & 0 deletions template/example/react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>React example %PACKAGE_NAME%</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="../common.ts"
></script>
<script
data-plugins="transform-modules-umd"
data-presets="react, typescript"
type="text/babel"
src="./index.tsx"
></script>

<link rel="stylesheet" href="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
40 changes: 40 additions & 0 deletions template/example/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/mappable-controls@0.0.1'));

const {MMapButtonExample} = reactify.module(await mappable.import('%PACKAGE_NAME%'));

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>
);
}
}
10 changes: 10 additions & 0 deletions template/example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"strict": false,
"rootDir": "",
"rootDirs": ["./", "../"],
"types": ["./types.d.ts"]
},
"include": ["./**/*.ts", "./**/*.tsx"]
}
14 changes: 14 additions & 0 deletions template/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 {};
28 changes: 28 additions & 0 deletions template/example/vanilla/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Vanilla example %PACKAGE_NAME%</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="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="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
22 changes: 22 additions & 0 deletions template/example/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/mappable-controls@0.0.1');
const {MMapButtonExample} = await mappable.import('%PACKAGE_NAME%');

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!')}))
);
}
29 changes: 29 additions & 0 deletions template/example/vue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Vue example %PACKAGE_NAME%</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="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="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
43 changes: 43 additions & 0 deletions template/example/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/mappable-controls@0.0.1'));

const {MMapButtonExample} = vuefy.module(await mappable.import('%PACKAGE_NAME%'));

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');
}
1 change: 1 addition & 0 deletions template/t_tpackage.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"ts-jest": "29.1.1",
"ts-loader": "9.4.4",
"typescript": "5.1.6",
"vue": "^3.4.21",
"webpack": "5.88.1",
"webpack-cli": "5.1.4",
"webpack-dev-server": "4.15.1"
Expand Down
3 changes: 2 additions & 1 deletion template/t_ttsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": ["@mappable-world/mappable-cli"],
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"typeRoots": ["./node_modules/@types", "./node_modules/@mappable-world"]
},
"include": ["./src", "./node_modules/@mappable-world/mappable-cli/index.d.ts"]
"include": ["./src", "./node_modules/@mappable-world/mappable-cli/index.d.ts"]
}

0 comments on commit 0cbf7e6

Please sign in to comment.