Skip to content

Commit

Permalink
fix wq/map.js AMD build
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Feb 14, 2022
1 parent ca1e4da commit 29ec39b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/leaflet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"leaflet.wms": "^0.2.0",
"mustache": "^4.0.1",
"react-leaflet": "^2.7.0",
"react-leaflet-draw": "^0.19.0",
"react-leaflet-draw": "0.19.0",
"react-leaflet-markercluster": "^2.0.0"
},
"devDependencies": {
Expand Down
32 changes: 29 additions & 3 deletions packages/leaflet/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import json from '@rollup/plugin-json';
import * as path from 'path';
import { makeBanner, wqDeps, babelAMD, outputAMD } from '../../rollup-utils.js';

const banners = {
Expand Down Expand Up @@ -31,9 +32,34 @@ const banners = {
'redux-orm/src/index.js': { id: 'redux-orm', external: true }
};
function resolveId(id) {
if (id.startsWith('default-from:')) {
return id;
}
return deps[id];
}

function load(id) {
if (id.startsWith('default-from:')) {
const file = path.resolve(id.split(':')[1]);
return `import mod from '${file}'; export default mod`;
}
if (id.endsWith('geotools/index.js')) {
return ['GeoHelp', 'GeoLocate', 'GeoCode', 'GeoCoords']
.map(emptyComponent)
.join('\n');
} else if (
id.endsWith('GeoTools.js') ||
id.endsWith('StickyMap.js') ||
id.endsWith('OffscreenMaps.js')
) {
return emptyComponent();
}
}
function emptyComponent(name) {
const exp = name ? 'export' : 'export default';
return `${exp} function ${name || 'Empty'}() { return null; }`;
}

const replaceConf = {
'process.env.NODE_ENV': '"production"',

Expand Down Expand Up @@ -66,7 +92,7 @@ const replaceConf = {
export default [
// AMD (for wq.app Python package)
{
input: 'packages/leaflet/src/index.js',
input: 'default-from:packages/leaflet/src/index.js',
external: [
'leaflet',
'leaflet.markercluster',
Expand All @@ -93,7 +119,7 @@ export default [
"import Draw from './overlays/Draw'\n" +
"import Accuracy from './overlays/Accuracy'\n"
}),
{ resolveId },
{ resolveId, load },
wqDeps('.'),
babelAMD({ jsx: true }),
resolve({
Expand Down Expand Up @@ -131,7 +157,7 @@ export default [
output: outputAMD('mapserv', banners.mapserv, 'leaflet'),
plugins: [
replace(replaceConf),
{ resolveId },
{ resolveId, load },
wqDeps('.'),
babelAMD({ jsx: true }),
resolve({
Expand Down
8 changes: 8 additions & 0 deletions packages/map/src/components/AutoMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export default function AutoMap({
);
}

AutoMap.makeComponent = props => {
function Component() {
return <AutoMap {...props} />;
}

return Component;
};

AutoMap.propTypes = {
name: PropTypes.string,
containerStyle: PropTypes.object,
Expand Down
7 changes: 4 additions & 3 deletions packages/map/src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ map.runComponent = 'OffscreenMaps';
map.run = function ($page, routeInfo) {
var mapconf = map.config.maps[routeInfo.page],
mode = routeInfo.mode,
form = routeInfo.form,
context = routeInfo.context,
form = routeInfo.page_config.form,
maps = [];
if (!mapconf) {
return;
Expand All @@ -335,12 +336,12 @@ map.run = function ($page, routeInfo) {
const fieldName = mapname === 'main' ? 'geometry' : mapname,
{ type } = form.find(field => field.name === fieldName) || {},
$field = $page.find(`[name=${fieldName}]`),
value = routeInfo.context[fieldName],
value = context[fieldName],
setValue = data => $field.val(JSON.stringify(data));

Component = EmbeddedGeo.makeComponent({ type, value, setValue });
} else {
Component = AutoMap;
Component = AutoMap.makeComponent({ context });
}

const detach = reactRenderer.attach(Component, $div[0], this.app);
Expand Down

0 comments on commit 29ec39b

Please sign in to comment.