Skip to content

Commit

Permalink
Merge pull request #44 from Stassi/feature/quick-start-tutorial-ts
Browse files Browse the repository at this point in the history
feature/quick-start-tutorial-ts
  • Loading branch information
Stassi authored Oct 5, 2024
2 parents febfe0f + d8cf2ee commit 15aa2a0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 35 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stassi/leaf",
"version": "0.0.43",
"version": "0.0.44",
"description": "Leaflet adapter.",
"keywords": [
"cartography",
Expand Down
2 changes: 1 addition & 1 deletion public/tutorial/quick-start/quick-start.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link href="../../style/theme.css" rel="stylesheet"/>
<link href="../../leaflet/leaflet.css" rel="stylesheet"/>
<link href="style/short.css" rel="stylesheet"/>
<script src="script/quick-start.js" type="module"></script>
<script src="dist/quick-start.js" type="module"></script>
</head>

<body>
Expand Down
64 changes: 39 additions & 25 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// noinspection JSUnusedGlobalSymbols

import commonjs from '@rollup/plugin-commonjs'
import inject from '@rollup/plugin-inject'
import terser from '@rollup/plugin-terser'
Expand All @@ -15,32 +13,48 @@ const modify: (modifyOptions: {
replace: string | ((match: string, element: string, value: string) => string)
}) => Plugin = untypedModify

const rollupConfig: RollupOptions = {
input: 'src/index.ts',
output: [
{
file: 'dist/leaf.js',
const rollupConfig: RollupOptions[] = [
{
input: 'src/index.ts',
output: [
{
file: 'dist/leaf.js',
format: 'esm',
sourcemap: true,
},
],
plugins: [
commonjs(),
modify({
find: /(?<element>.*)\.innerHTML\s*=\s*(?<value>.*);/,
replace: (_match: string, element: string, value: string): string =>
`${element}.innerHTML = DOMPurify.sanitize(${value});`,
}),
inject({
DOMPurify: 'dompurify',
}),
nodeResolve(),
typescript({
declaration: true,
exclude: ['rollup.config.ts', 'src/tutorial/**/*.ts'],
}),
terser(),
],
},
{
external: ['@stassi/leaf'],
input: 'src/tutorial/quick-start/quick-start.ts',
output: {
file: 'public/tutorial/quick-start/dist/quick-start.js',
format: 'esm',
paths: {
'@stassi/leaf': '../../../leaf/leaf.js',
},
sourcemap: true,
},
],
plugins: [
commonjs(),
modify({
find: /(?<element>.*)\.innerHTML\s*=\s*(?<value>.*);/,
replace: (_match: string, element: string, value: string): string =>
`${element}.innerHTML = DOMPurify.sanitize(${value});`,
}),
inject({
DOMPurify: 'dompurify',
}),
nodeResolve(),
typescript({
exclude: ['rollup.config.ts'],
}),
terser(),
],
}
plugins: [typescript(), terser()],
},
]

// eslint-disable-next-line import/no-default-export -- default export required by Rollup.js
export default rollupConfig
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { type LeafletMouseEvent, type Map } from 'leaflet'

import {
circle,
map as leafletMap,
marker,
polygon,
popup,
tileLayerOsm,
} from '../../../leaf/leaf.js'
} from '@stassi/leaf'

// noinspection JSUnusedGlobalSymbols
const map = leafletMap({
const map: Map = leafletMap({
center: [51.505, -0.09],
id: 'map',
onClick: ({ latlng: latitudeLongitude }) => {
onClick: ({ latlng: latitudeLongitude }: LeafletMouseEvent): void => {
popup({
htmlContent: `You clicked the map at ${latitudeLongitude}`,
htmlContent: `You clicked the map at ${latitudeLongitude.toString()}`,
latitudeLongitude,
map,
})
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"checkJs": true,
"declaration": true,
"esModuleInterop": true,
"lib": ["DOM", "ESNext"],
"module": "ESNext",
"moduleResolution": "node",
"outDir": "./dist",
"paths": {
"@stassi/leaf": ["src/index.ts"]
},
"strict": true,
"target": "ESNext"
},
Expand Down

0 comments on commit 15aa2a0

Please sign in to comment.