Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New template for examples #8

Merged
merged 5 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
347 changes: 313 additions & 34 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"yargs": "17.7.2"
},
"devDependencies": {
"@mappable-world/mappable-types": "^0.0.3",
"@mappable-world/mappable-types": "^0.0.15",
"@types/got": "9.6.12",
"@types/jest": "29.5.2",
"@types/jsdom": "21.1.1",
Expand All @@ -36,6 +36,7 @@
"ts-loader": "9.4.4",
"ts-node": "^10.9.1",
"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
12 changes: 6 additions & 6 deletions template/example/common.js → template/example/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {MMapLocationRequest, LngLatBounds} from '@mappable-world/mappable-types';

mappable.import.loaders.unshift(async (pkg) => {
if (!pkg.startsWith('%PACKAGE_NAME%')) {
return;
Expand All @@ -10,13 +12,11 @@ mappable.import.loaders.unshift(async (pkg) => {
}

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

});

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

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const LOCATION = {bounds: BOUNDS};
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
64 changes: 0 additions & 64 deletions template/example/react.html

This file was deleted.

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>
);
}
}
9 changes: 9 additions & 0 deletions template/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"]
},
"include": ["./**/*.ts", "./**/*.tsx"]
}
20 changes: 20 additions & 0 deletions template/example/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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;
}
}

declare module '@mappable-world/mappable-types/import' {
interface Import {
(pkg: '%PACKAGE_NAME%'): Promise<typeof import('../src/index')>;
}
}
Comment on lines +14 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a part of generated package, not for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello! I have created a new pull request for the proposed changes


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

This file was deleted.

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');
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ exports[`MMap smoke test should make map 1`] = `
},
"nodeName": "span",
},
{
"attributes": {
"class": "mappable--map-copyrights__scale",
},
"nodeName": "div",
},
],
"nodeName": "div",
},
Expand Down
Loading
Loading