@nocobase/plugin-map 0.12.0-alpha.2 → 0.12.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,3 +55,4 @@ export declare const createMapBlockSchema: (options: any) => import("@formily/re
55
55
  "x-read-pretty"?: boolean;
56
56
  "x-compile-omitted"?: string[];
57
57
  }>;
58
+ export declare const findNestedOption: (value: string[] | string, options?: any[]) => any;
@@ -1,6 +1,6 @@
1
1
  (function(global2, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("@nocobase/client"), require("react-i18next"), require("@ant-design/icons"), require("@formily/react"), require("ahooks"), require("antd"), require("react-router-dom"), require("lodash"), require("@formily/antd-v5"), require("@formily/shared")) : typeof define === "function" && define.amd ? define(["exports", "react", "@nocobase/client", "react-i18next", "@ant-design/icons", "@formily/react", "ahooks", "antd", "react-router-dom", "lodash", "@formily/antd-v5", "@formily/shared"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2["@nocobase/plugin-map"] = {}, global2.react, global2["@nocobase/client"], global2["react-i18next"], global2["@ant-design/icons"], global2["@formily/react"], global2.ahooks, global2.antd, global2["react-router-dom"], global2.lodash, global2["@formily/antd-v5"], global2["@formily/shared"]));
3
- })(this, function(exports2, React, client, reactI18next, icons, react, ahooks, antd, reactRouterDom, lodash, antdV5, shared) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("@nocobase/client"), require("react-i18next"), require("@ant-design/icons"), require("@formily/react"), require("ahooks"), require("antd"), require("react-router-dom"), require("lodash"), require("@formily/shared"), require("@formily/antd-v5")) : typeof define === "function" && define.amd ? define(["exports", "react", "@nocobase/client", "react-i18next", "@ant-design/icons", "@formily/react", "ahooks", "antd", "react-router-dom", "lodash", "@formily/shared", "@formily/antd-v5"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2["@nocobase/plugin-map"] = {}, global2.react, global2["@nocobase/client"], global2["react-i18next"], global2["@ant-design/icons"], global2["@formily/react"], global2.ahooks, global2.antd, global2["react-router-dom"], global2.lodash, global2["@formily/shared"], global2["@formily/antd-v5"]));
3
+ })(this, function(exports2, React, client, reactI18next, icons, react, ahooks, antd, reactRouterDom, lodash, shared, antdV5) {
4
4
  "use strict";
5
5
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
6
6
  function getDefaultExportFromCjs(x) {
@@ -39,10 +39,12 @@
39
39
  var jsxRuntimeExports = jsxRuntime.exports;
40
40
  const NAMESPACE = "map";
41
41
  function generateNTemplate(key) {
42
- return `{{t('${key}', { ns: '${NAMESPACE}' })}}`;
42
+ return `{{t('${key}', { ns: '${NAMESPACE}', nsMode: 'fallback' })}}`;
43
43
  }
44
44
  function useMapTranslation() {
45
- return reactI18next.useTranslation(NAMESPACE);
45
+ return reactI18next.useTranslation(NAMESPACE, {
46
+ nsMode: "fallback"
47
+ });
46
48
  }
47
49
  const MapActionInitializers = {
48
50
  title: "{{t('Configure actions')}}",
@@ -603,6 +605,7 @@
603
605
  content: t("Are you sure to clear the canvas?"),
604
606
  okText: t("Confirm"),
605
607
  cancelText: t("Cancel"),
608
+ getContainer: () => document.getElementById(id.current),
606
609
  onOk() {
607
610
  ok();
608
611
  }
@@ -842,11 +845,21 @@
842
845
  }
843
846
  );
844
847
  });
848
+ const getSource = (data, fields2, type) => {
849
+ const res = fields2 == null ? void 0 : fields2.reduce((obj, field, index) => {
850
+ if (index === fields2.length - 1 && (type === "o2m" || type === "m2m")) {
851
+ return obj == null ? void 0 : obj.map((item) => item[field]).filter((v) => v !== null && v !== void 0);
852
+ }
853
+ return obj == null ? void 0 : obj[field];
854
+ }, data);
855
+ return type === "o2m" || type === "m2m" ? res : [res];
856
+ };
845
857
  const AMapBlock = (props) => {
846
- var _a, _b, _c;
847
- const { fieldNames, dataSource = [], fixedBlock, zoom, setSelectedRecordKeys } = client.useProps(props);
848
- const { getField, getPrimaryKey } = client.useCollection();
849
- const field = getField(fieldNames == null ? void 0 : fieldNames.field);
858
+ var _a, _b, _c, _d;
859
+ const { collectionField, fieldNames, dataSource, fixedBlock, zoom, setSelectedRecordKeys } = client.useProps(props);
860
+ const { name: name2, getPrimaryKey } = client.useCollection();
861
+ const { getCollectionJoinField } = client.useCollectionManager();
862
+ const primaryKey = getPrimaryKey();
850
863
  const [isMapInitialization, setIsMapInitialization] = React.useState(false);
851
864
  const mapRef = React.useRef();
852
865
  const geometryUtils = (_b = (_a = mapRef.current) == null ? void 0 : _a.aMap) == null ? void 0 : _b.GeometryUtil;
@@ -876,21 +889,23 @@
876
889
  });
877
890
  };
878
891
  const removeSelection = () => {
892
+ var _a2, _b2, _c2;
879
893
  if (!mapRef.current)
880
894
  return;
881
- mapRef.current.mouseTool().close(true);
882
- mapRef.current.editor().setTarget(null);
883
- mapRef.current.editor().close();
895
+ (_a2 = mapRef.current) == null ? void 0 : _a2.mouseTool().close(true);
896
+ (_b2 = mapRef.current) == null ? void 0 : _b2.editor().setTarget(null);
897
+ (_c2 = mapRef.current) == null ? void 0 : _c2.editor().close();
884
898
  };
885
899
  React.useEffect(() => {
900
+ var _a2, _b2, _c2, _d2;
886
901
  if (selectingMode !== "selection") {
887
902
  return;
888
903
  }
889
- if (!mapRef.current.editor()) {
890
- mapRef.current.createEditor("polygon");
891
- mapRef.current.createMouseTool("polygon");
904
+ if (!((_a2 = mapRef.current) == null ? void 0 : _a2.editor())) {
905
+ (_b2 = mapRef.current) == null ? void 0 : _b2.createEditor("polygon");
906
+ (_c2 = mapRef.current) == null ? void 0 : _c2.createMouseTool("polygon");
892
907
  } else {
893
- mapRef.current.executeMouseTool("polygon");
908
+ (_d2 = mapRef.current) == null ? void 0 : _d2.executeMouseTool("polygon");
894
909
  }
895
910
  return () => {
896
911
  removeSelection();
@@ -899,8 +914,9 @@
899
914
  React.useEffect(() => {
900
915
  if (selectingMode) {
901
916
  return () => {
917
+ var _a2;
902
918
  if (!selectingModeRef.current) {
903
- mapRef.current.map.getAllOverlays().forEach((o) => {
919
+ (_a2 = mapRef.current) == null ? void 0 : _a2.map.getAllOverlays().forEach((o) => {
904
920
  setOverlayOptions(o, false);
905
921
  });
906
922
  }
@@ -908,48 +924,54 @@
908
924
  }
909
925
  }, [selectingMode]);
910
926
  const onSelectingComplete = ahooks.useMemoizedFn(() => {
911
- const selectingOverlay = mapRef.current.editor().getTarget();
912
- const overlays = mapRef.current.map.getAllOverlays();
913
- const selectedOverlays = overlays.filter((o) => {
927
+ var _a2, _b2, _c2;
928
+ const selectingOverlay = (_a2 = mapRef.current) == null ? void 0 : _a2.editor().getTarget();
929
+ const overlays = (_b2 = mapRef.current) == null ? void 0 : _b2.map.getAllOverlays();
930
+ const selectedOverlays = overlays == null ? void 0 : overlays.filter((o) => {
914
931
  if (o === selectingOverlay || o.getExtData().id === void 0)
915
932
  return;
916
933
  if ("getPosition" in o) {
917
- return geometryUtils.isPointInRing(o.getPosition(), selectingOverlay.getPath());
934
+ return geometryUtils.isPointInRing(o.getPosition(), selectingOverlay == null ? void 0 : selectingOverlay.getPath());
918
935
  }
919
- return geometryUtils.doesRingRingIntersect(o.getPath(), selectingOverlay.getPath());
936
+ return geometryUtils.doesRingRingIntersect(o.getPath(), selectingOverlay == null ? void 0 : selectingOverlay.getPath());
920
937
  });
921
- const ids = selectedOverlays.map((o) => {
938
+ const ids = selectedOverlays == null ? void 0 : selectedOverlays.map((o) => {
922
939
  setOverlayOptions(o, true);
923
940
  return o.getExtData().id;
924
941
  });
925
- setSelectedRecordKeys((lastIds) => ids.concat(lastIds));
926
- selectingOverlay.remove();
927
- mapRef.current.editor().close();
942
+ setSelectedRecordKeys((lastIds) => ids == null ? void 0 : ids.concat(lastIds));
943
+ selectingOverlay == null ? void 0 : selectingOverlay.remove();
944
+ (_c2 = mapRef.current) == null ? void 0 : _c2.editor().close();
928
945
  });
929
946
  React.useEffect(() => {
930
- var _a2;
931
- if (!field || !mapRef.current)
947
+ var _a2, _b2;
948
+ if (!collectionField || !mapRef.current || !dataSource)
932
949
  return;
950
+ const fieldPaths = Array.isArray(fieldNames == null ? void 0 : fieldNames.field) && (fieldNames == null ? void 0 : fieldNames.field.length) > 1 ? fieldNames == null ? void 0 : fieldNames.field.slice(0, -1) : fieldNames == null ? void 0 : fieldNames.field;
951
+ const cf = getCollectionJoinField([name2, ...fieldPaths].flat().join("."));
933
952
  const overlays = dataSource.map((item) => {
934
- const data = item[fieldNames == null ? void 0 : fieldNames.field];
935
- if (!data)
936
- return;
937
- const overlay = mapRef.current.setOverlay(field.type, data, {
938
- strokeColor: "#4e9bff",
939
- fillColor: "#4e9bff",
940
- cursor: "pointer",
941
- label: {
942
- direction: "bottom",
943
- offset: [0, 5],
944
- content: (fieldNames == null ? void 0 : fieldNames.marker) ? compile(item[fieldNames.marker]) : void 0
945
- },
946
- extData: {
947
- id: item[getPrimaryKey()]
948
- }
953
+ const data = getSource(item, fieldNames == null ? void 0 : fieldNames.field, cf == null ? void 0 : cf.interface);
954
+ if (!(data == null ? void 0 : data.length))
955
+ return [];
956
+ return data == null ? void 0 : data.filter(Boolean).map((mapItem) => {
957
+ var _a3;
958
+ const overlay = (_a3 = mapRef.current) == null ? void 0 : _a3.setOverlay(collectionField.type, mapItem, {
959
+ strokeColor: "#4e9bff",
960
+ fillColor: "#4e9bff",
961
+ cursor: "pointer",
962
+ label: {
963
+ direction: "bottom",
964
+ offset: [0, 5],
965
+ content: (fieldNames == null ? void 0 : fieldNames.marker) ? compile(item[fieldNames.marker]) : void 0
966
+ },
967
+ extData: {
968
+ id: item[primaryKey]
969
+ }
970
+ });
971
+ return overlay;
949
972
  });
950
- return overlay;
951
- }).filter(Boolean);
952
- (_a2 = mapRef.current.map) == null ? void 0 : _a2.setFitView(overlays);
973
+ }).flat().filter(Boolean);
974
+ (_b2 = (_a2 = mapRef.current) == null ? void 0 : _a2.map) == null ? void 0 : _b2.setFitView(overlays);
953
975
  const events = overlays.map((o) => {
954
976
  const onClick = (e) => {
955
977
  const overlay = e.target;
@@ -965,8 +987,8 @@
965
987
  }
966
988
  return;
967
989
  }
968
- const data = dataSource == null ? void 0 : dataSource.find((item) => {
969
- return extData.id === item[getPrimaryKey()];
990
+ const data = dataSource.find((item) => {
991
+ return extData.id === item[primaryKey];
970
992
  });
971
993
  if (isConnected) {
972
994
  setPrevSelected((prev) => {
@@ -977,7 +999,7 @@
977
999
  return null;
978
1000
  } else {
979
1001
  selectMarker$1(o);
980
- doFilter(data[getPrimaryKey()], (target) => target.field || getPrimaryKey(), "$eq");
1002
+ doFilter(data[primaryKey], (target) => target.field || primaryKey, "$eq");
981
1003
  }
982
1004
  return o;
983
1005
  });
@@ -996,7 +1018,7 @@
996
1018
  });
997
1019
  events.forEach((e) => e());
998
1020
  };
999
- }, [dataSource, isMapInitialization, fieldNames, field.type, isConnected]);
1021
+ }, [dataSource, isMapInitialization, fieldNames, name2, primaryKey, collectionField.type, isConnected]);
1000
1022
  React.useEffect(() => {
1001
1023
  setTimeout(() => {
1002
1024
  setSelectedRecordKeys([]);
@@ -1023,7 +1045,7 @@
1023
1045
  top: 10px;
1024
1046
  z-index: 999;
1025
1047
  `,
1026
- children: isMapInitialization && !mapRef.current.errMessage ? /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Space, { direction: "vertical", children: [
1048
+ children: isMapInitialization && !((_c = mapRef.current) == null ? void 0 : _c.errMessage) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Space, { direction: "vertical", children: [
1027
1049
  /* @__PURE__ */ jsxRuntimeExports.jsx(
1028
1050
  antd.Button,
1029
1051
  {
@@ -1068,7 +1090,7 @@
1068
1090
  /* @__PURE__ */ jsxRuntimeExports.jsx(
1069
1091
  AMapComponent,
1070
1092
  {
1071
- ...(_c = field == null ? void 0 : field.uiSchema) == null ? void 0 : _c["x-component-props"],
1093
+ ...(_d = collectionField == null ? void 0 : collectionField.uiSchema) == null ? void 0 : _d["x-component-props"],
1072
1094
  ref: mapRefCallback,
1073
1095
  style: { height: fixedBlock ? "100%" : null },
1074
1096
  zoom,
@@ -1401,9 +1423,9 @@
1401
1423
  });
1402
1424
  });
1403
1425
  }
1404
- importLibrary(name) {
1426
+ importLibrary(name2) {
1405
1427
  this.execute();
1406
- return google.maps.importLibrary(name);
1428
+ return google.maps.importLibrary(name2);
1407
1429
  }
1408
1430
  /**
1409
1431
  * Load the Google Maps JavaScript API script with a callback.
@@ -1927,6 +1949,7 @@
1927
1949
  content: t("Are you sure to clear the canvas?"),
1928
1950
  okText: t("Confirm"),
1929
1951
  cancelText: t("Cancel"),
1952
+ getContainer: () => mapContainerRef.current,
1930
1953
  onOk() {
1931
1954
  ok();
1932
1955
  }
@@ -2056,13 +2079,10 @@
2056
2079
  border: 1px solid #0000f5;
2057
2080
  `;
2058
2081
  const GoogleMapsBlock = (props) => {
2059
- const { fieldNames, dataSource = [], fixedBlock, zoom, setSelectedRecordKeys } = client.useProps(props);
2060
- const { getField, getPrimaryKey } = client.useCollection();
2061
- const { marker: markerName, field: fieldName } = fieldNames || {
2062
- marker: "id",
2063
- field: "id"
2064
- };
2065
- const field = getField(fieldName);
2082
+ const { collectionField, fieldNames, dataSource, fixedBlock, zoom, setSelectedRecordKeys } = client.useProps(props);
2083
+ const { getPrimaryKey } = client.useCollection();
2084
+ const primaryKey = getPrimaryKey();
2085
+ const { marker: markerName = "id" } = fieldNames;
2066
2086
  const [isMapInitialization, setIsMapInitialization] = React.useState(false);
2067
2087
  const mapRef = React.useRef();
2068
2088
  const [record, setRecord] = React.useState();
@@ -2072,9 +2092,10 @@
2072
2092
  const { isConnected, doFilter } = client.useFilterAPI();
2073
2093
  const [, setPrevSelected] = React.useState(null);
2074
2094
  const selectingModeRef = React.useRef(selectingMode);
2075
- const selectionOverlayRef = React.useRef();
2095
+ const selectionOverlayRef = React.useRef(null);
2076
2096
  const overlaysRef = React.useRef([]);
2077
2097
  selectingModeRef.current = selectingMode;
2098
+ const { getCollectionJoinField } = client.useCollectionManager();
2078
2099
  const setOverlayOptions = (overlay, state) => {
2079
2100
  const selected = typeof state !== "undefined" ? !state : overlay.get(OVERLAY_SELECtED);
2080
2101
  overlay.set(OVERLAY_SELECtED, !selected);
@@ -2091,20 +2112,22 @@
2091
2112
  });
2092
2113
  };
2093
2114
  React.useEffect(() => {
2115
+ var _a, _b, _c, _d;
2094
2116
  if (selectingMode !== "selection") {
2095
2117
  return;
2096
2118
  }
2097
- if (!mapRef.current.drawingManager) {
2098
- mapRef.current.drawingManager = mapRef.current.createDraw(true, {
2119
+ if (mapRef.current && !((_a = mapRef.current) == null ? void 0 : _a.drawingManager)) {
2120
+ mapRef.current.drawingManager = (_b = mapRef.current) == null ? void 0 : _b.createDraw(true, {
2099
2121
  editable: true,
2100
2122
  draggable: true
2101
2123
  });
2102
2124
  }
2103
2125
  const listenerSet = /* @__PURE__ */ new Set();
2104
- mapRef.current.drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
2105
- mapRef.current.drawingManager.addListener("overlaycomplete", (event) => {
2126
+ (_c = mapRef.current) == null ? void 0 : _c.drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
2127
+ (_d = mapRef.current) == null ? void 0 : _d.drawingManager.addListener("overlaycomplete", (event) => {
2128
+ var _a2;
2106
2129
  const polygon2 = event.overlay;
2107
- mapRef.current.drawingManager.setDrawingMode(null);
2130
+ (_a2 = mapRef.current) == null ? void 0 : _a2.drawingManager.setDrawingMode(null);
2108
2131
  selectionOverlayRef.current = polygon2;
2109
2132
  const path = polygon2.getPath();
2110
2133
  ["insert_at", "remove_at", "set_at"].forEach((key) => {
@@ -2113,17 +2136,17 @@
2113
2136
  });
2114
2137
  });
2115
2138
  return () => {
2116
- var _a, _b;
2139
+ var _a2, _b2, _c2, _d2;
2117
2140
  listenerSet.forEach((i) => {
2118
2141
  i();
2119
2142
  });
2120
2143
  if (!mapRef.current)
2121
2144
  return;
2122
- (_a = selectionOverlayRef.current) == null ? void 0 : _a.unbindAll();
2123
- (_b = selectionOverlayRef.current) == null ? void 0 : _b.setMap(null);
2145
+ (_a2 = selectionOverlayRef.current) == null ? void 0 : _a2.unbindAll();
2146
+ (_b2 = selectionOverlayRef.current) == null ? void 0 : _b2.setMap(null);
2124
2147
  selectionOverlayRef.current = null;
2125
- mapRef.current.drawingManager.setDrawingMode(null);
2126
- mapRef.current.drawingManager.unbindAll();
2148
+ (_c2 = mapRef.current) == null ? void 0 : _c2.drawingManager.setDrawingMode(null);
2149
+ (_d2 = mapRef.current) == null ? void 0 : _d2.drawingManager.unbindAll();
2127
2150
  };
2128
2151
  }, [selectingMode]);
2129
2152
  React.useEffect(() => {
@@ -2138,6 +2161,7 @@
2138
2161
  }
2139
2162
  }, [selectingMode]);
2140
2163
  const onSelectingComplete = ahooks.useMemoizedFn(() => {
2164
+ var _a;
2141
2165
  const overlay = selectionOverlayRef.current;
2142
2166
  const overlays = overlaysRef.current;
2143
2167
  const poly = google.maps.geometry.poly;
@@ -2159,35 +2183,42 @@
2159
2183
  return o.get(OVERLAY_KEY);
2160
2184
  });
2161
2185
  setSelectedRecordKeys((lastIds) => ids.concat(lastIds));
2162
- overlay.unbindAll();
2163
- overlay.setMap(null);
2164
- mapRef.current.drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
2186
+ overlay == null ? void 0 : overlay.unbindAll();
2187
+ overlay == null ? void 0 : overlay.setMap(null);
2188
+ (_a = mapRef.current) == null ? void 0 : _a.drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
2165
2189
  });
2166
2190
  React.useEffect(() => {
2167
- var _a;
2168
- if (!field || !((_a = mapRef.current) == null ? void 0 : _a.map))
2191
+ var _a, _b;
2192
+ if (!collectionField || !(dataSource == null ? void 0 : dataSource.length) || !((_a = mapRef.current) == null ? void 0 : _a.map))
2169
2193
  return;
2194
+ const fieldPaths = Array.isArray(fieldNames == null ? void 0 : fieldNames.field) && (fieldNames == null ? void 0 : fieldNames.field.length) > 1 ? fieldNames == null ? void 0 : fieldNames.field.slice(0, -1) : fieldNames == null ? void 0 : fieldNames.field;
2195
+ const cf = getCollectionJoinField([name, ...fieldPaths].flat().join("."));
2170
2196
  const overlays = dataSource.map((item) => {
2171
- const data = item[fieldNames == null ? void 0 : fieldNames.field];
2172
- if (!data)
2173
- return;
2174
- const overlay = mapRef.current.setOverlay(field.type, data, {
2175
- strokeColor: "#4e9bff",
2176
- fillColor: "#4e9bff",
2177
- cursor: "pointer",
2178
- label: {
2179
- className: labelClass,
2180
- fontFamily: "inherit",
2181
- fontSize: "13px",
2182
- color: "#333",
2183
- text: (fieldNames == null ? void 0 : fieldNames.marker) ? compile(item[markerName]) : void 0
2184
- }
2197
+ const data = getSource(item, fieldNames == null ? void 0 : fieldNames.field, cf == null ? void 0 : cf.interface);
2198
+ if (!(data == null ? void 0 : data.length))
2199
+ return [];
2200
+ return data == null ? void 0 : data.filter(Boolean).map((mapItem) => {
2201
+ var _a2;
2202
+ if (!data)
2203
+ return;
2204
+ const overlay = (_a2 = mapRef.current) == null ? void 0 : _a2.setOverlay(collectionField.type, mapItem, {
2205
+ strokeColor: "#4e9bff",
2206
+ fillColor: "#4e9bff",
2207
+ cursor: "pointer",
2208
+ label: {
2209
+ className: labelClass,
2210
+ fontFamily: "inherit",
2211
+ fontSize: "13px",
2212
+ color: "#333",
2213
+ text: (fieldNames == null ? void 0 : fieldNames.marker) ? compile(item[markerName]) : void 0
2214
+ }
2215
+ });
2216
+ overlay == null ? void 0 : overlay.set(OVERLAY_KEY, item[primaryKey]);
2217
+ return overlay;
2185
2218
  });
2186
- overlay.set(OVERLAY_KEY, item[getPrimaryKey()]);
2187
- return overlay;
2188
- }).filter(Boolean);
2219
+ }).flat().filter(Boolean);
2189
2220
  overlaysRef.current = overlays;
2190
- mapRef.current.setFitView(overlays);
2221
+ (_b = mapRef.current) == null ? void 0 : _b.setFitView(overlays);
2191
2222
  const events = overlays.map((o) => {
2192
2223
  const onClick = (event) => {
2193
2224
  const overlay = o;
@@ -2195,7 +2226,7 @@
2195
2226
  if (!id)
2196
2227
  return;
2197
2228
  const data = dataSource == null ? void 0 : dataSource.find((item) => {
2198
- return id === item[getPrimaryKey()];
2229
+ return id === item[primaryKey];
2199
2230
  });
2200
2231
  if (isConnected) {
2201
2232
  setPrevSelected((prev) => {
@@ -2206,7 +2237,7 @@
2206
2237
  return null;
2207
2238
  } else {
2208
2239
  selectMarker(overlay);
2209
- doFilter(data[getPrimaryKey()], (target) => target.field || getPrimaryKey(), "$eq");
2240
+ doFilter(data[primaryKey], (target) => target.field || primaryKey, "$eq");
2210
2241
  }
2211
2242
  return overlay;
2212
2243
  });
@@ -2226,7 +2257,7 @@
2226
2257
  });
2227
2258
  events.forEach((e) => e());
2228
2259
  };
2229
- }, [dataSource, isMapInitialization, markerName, field.type, isConnected]);
2260
+ }, [dataSource, isMapInitialization, markerName, collectionField.type, isConnected]);
2230
2261
  React.useEffect(() => {
2231
2262
  setTimeout(() => {
2232
2263
  setSelectedRecordKeys([]);
@@ -2539,10 +2570,13 @@
2539
2570
  const MapBlock = (props) => {
2540
2571
  var _a;
2541
2572
  const { fieldNames } = client.useProps(props);
2542
- const { getField } = client.useCollection();
2543
- const field = getField(fieldNames == null ? void 0 : fieldNames.field);
2544
- const fieldComponentProps = (_a = field == null ? void 0 : field.uiSchema) == null ? void 0 : _a["x-component-props"];
2545
- return /* @__PURE__ */ jsxRuntimeExports.jsx(MapBlockComponent, { ...fieldComponentProps, ...props });
2573
+ const { getCollectionJoinField } = client.useCollectionManager();
2574
+ const { name: name2 } = client.useCollection();
2575
+ const collectionField = React.useMemo(() => {
2576
+ return getCollectionJoinField([name2, fieldNames == null ? void 0 : fieldNames.field].flat().join("."));
2577
+ }, [name2, fieldNames == null ? void 0 : fieldNames.field]);
2578
+ const fieldComponentProps = (_a = collectionField == null ? void 0 : collectionField.uiSchema) == null ? void 0 : _a["x-component-props"];
2579
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MapBlockComponent, { ...fieldComponentProps, ...props, collectionField });
2546
2580
  };
2547
2581
  const MapBlockContext = React.createContext({});
2548
2582
  const InternalMapBlockProvider = (props) => {
@@ -2569,7 +2603,13 @@
2569
2603
  ) }) });
2570
2604
  };
2571
2605
  const MapBlockProvider = (props) => {
2572
- return /* @__PURE__ */ jsxRuntimeExports.jsx(client.BlockProvider, { ...props, params: { ...props.params, paginate: false }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(InternalMapBlockProvider, { ...props }) });
2606
+ const { params, fieldNames } = props;
2607
+ const appends = params.appends || [];
2608
+ const { field } = fieldNames || {};
2609
+ if (Array.isArray(field) && field.length > 1) {
2610
+ appends.push(field[0]);
2611
+ }
2612
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.BlockProvider, { ...props, params: { ...params, appends, paginate: false }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(InternalMapBlockProvider, { ...props }) });
2573
2613
  };
2574
2614
  const useMapBlockContext = () => {
2575
2615
  return React.useContext(MapBlockContext);
@@ -2583,15 +2623,101 @@
2583
2623
  zoom: ((_d = (_c = ctx == null ? void 0 : ctx.field) == null ? void 0 : _c.componentProps) == null ? void 0 : _d.zoom) || 13
2584
2624
  };
2585
2625
  };
2626
+ const createMapBlockSchema = (options) => {
2627
+ const { collection, resource, fieldNames, ...others } = options;
2628
+ const schema = {
2629
+ type: "void",
2630
+ "x-acl-action": `${resource || collection}:list`,
2631
+ "x-decorator": "MapBlockProvider",
2632
+ "x-decorator-props": {
2633
+ collection,
2634
+ resource: resource || collection,
2635
+ action: "list",
2636
+ fieldNames,
2637
+ params: {
2638
+ paginate: false
2639
+ },
2640
+ ...others
2641
+ },
2642
+ "x-designer": "MapBlockDesigner",
2643
+ "x-component": "CardItem",
2644
+ // 保存当前筛选区块所能过滤的数据区块
2645
+ "x-filter-targets": [],
2646
+ properties: {
2647
+ actions: {
2648
+ type: "void",
2649
+ "x-initializer": "MapActionInitializers",
2650
+ "x-component": "ActionBar",
2651
+ "x-component-props": {
2652
+ style: {
2653
+ marginBottom: 16
2654
+ }
2655
+ },
2656
+ properties: {}
2657
+ },
2658
+ [shared.uid()]: {
2659
+ type: "void",
2660
+ "x-component": "MapBlock",
2661
+ "x-component-props": {
2662
+ useProps: "{{ useMapBlockProps }}"
2663
+ },
2664
+ properties: {
2665
+ drawer: {
2666
+ type: "void",
2667
+ "x-component": "Action.Drawer",
2668
+ "x-component-props": {
2669
+ className: "nb-action-popup"
2670
+ },
2671
+ title: '{{ t("View record") }}',
2672
+ properties: {
2673
+ tabs: {
2674
+ type: "void",
2675
+ "x-component": "Tabs",
2676
+ "x-component-props": {},
2677
+ "x-initializer": "TabPaneInitializers",
2678
+ properties: {
2679
+ tab1: {
2680
+ type: "void",
2681
+ title: '{{t("Details")}}',
2682
+ "x-component": "Tabs.TabPane",
2683
+ "x-designer": "Tabs.Designer",
2684
+ "x-component-props": {},
2685
+ properties: {
2686
+ grid: {
2687
+ type: "void",
2688
+ "x-component": "Grid",
2689
+ "x-initializer": "RecordBlockInitializers",
2690
+ properties: {}
2691
+ }
2692
+ }
2693
+ }
2694
+ }
2695
+ }
2696
+ }
2697
+ }
2698
+ }
2699
+ }
2700
+ }
2701
+ };
2702
+ return schema;
2703
+ };
2704
+ const findNestedOption = (value, options = []) => {
2705
+ if (typeof value === "string") {
2706
+ value = [value];
2707
+ }
2708
+ return value == null ? void 0 : value.reduce((cur, v, index) => {
2709
+ const matched = cur == null ? void 0 : cur.find((item) => item.value === v);
2710
+ return index === value.length - 1 ? matched : matched == null ? void 0 : matched.children;
2711
+ }, options);
2712
+ };
2586
2713
  const MapBlockDesigner = () => {
2587
- var _a, _b, _c, _d, _e;
2588
- const { name, title } = client.useCollection();
2714
+ var _a, _b, _c, _d, _e, _f;
2715
+ const { name: name2, title } = client.useCollection();
2589
2716
  const field = react.useField();
2590
2717
  const fieldSchema = react.useFieldSchema();
2591
- const dataSource = client.useCollectionFilterOptions(name);
2718
+ const dataSource = client.useCollectionFilterOptions(name2);
2592
2719
  const { service } = useMapBlockContext();
2593
- const { t: mapT } = useMapTranslation();
2594
- const { t } = reactI18next.useTranslation();
2720
+ const { t } = useMapTranslation();
2595
2721
  const { dn } = client.useDesignable();
2596
2722
  const { getCollectionFieldsOptions } = client.useCollectionManager();
2597
2723
  const collection = client.useCollection();
@@ -2600,17 +2726,21 @@
2600
2726
  const fieldNames = ((_d = fieldSchema == null ? void 0 : fieldSchema["x-decorator-props"]) == null ? void 0 : _d["fieldNames"]) || {};
2601
2727
  const defaultZoom = ((_e = fieldSchema == null ? void 0 : fieldSchema["x-component-props"]) == null ? void 0 : _e["zoom"]) || 13;
2602
2728
  const template = client.useSchemaTemplate();
2603
- const mapFieldOptions = getCollectionFieldsOptions(collection == null ? void 0 : collection.name, ["point", "lineString", "polygon"]);
2729
+ const mapFieldOptions = getCollectionFieldsOptions(collection == null ? void 0 : collection.name, ["point", "lineString", "polygon"], {
2730
+ association: ["o2o", "obo", "oho", "o2m", "m2o", "m2m"]
2731
+ });
2604
2732
  const markerFieldOptions = getCollectionFieldsOptions(collection == null ? void 0 : collection.name, "string");
2605
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(client.GeneralSchemaDesigner, { template, title: title || name, children: [
2733
+ const isPointField = ((_f = findNestedOption(fieldNames.field, mapFieldOptions)) == null ? void 0 : _f.type) === "point";
2734
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(client.GeneralSchemaDesigner, { template, title: title || name2, children: [
2606
2735
  /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaSettings.BlockTitleItem, {}),
2607
2736
  /* @__PURE__ */ jsxRuntimeExports.jsx(client.FixedBlockDesignerItem, {}),
2608
2737
  /* @__PURE__ */ jsxRuntimeExports.jsx(
2609
- client.SchemaSettings.SelectItem,
2738
+ client.SchemaSettings.CascaderItem,
2610
2739
  {
2611
- title: mapT("Map field"),
2740
+ title: t("Map field"),
2612
2741
  value: fieldNames.field,
2613
2742
  options: mapFieldOptions,
2743
+ allowClear: false,
2614
2744
  onChange: (v) => {
2615
2745
  const fieldNames2 = field.decoratorProps.fieldNames || {};
2616
2746
  fieldNames2["field"] = v;
@@ -2627,10 +2757,10 @@
2627
2757
  }
2628
2758
  }
2629
2759
  ),
2630
- /* @__PURE__ */ jsxRuntimeExports.jsx(
2760
+ isPointField ? /* @__PURE__ */ jsxRuntimeExports.jsx(
2631
2761
  client.SchemaSettings.SelectItem,
2632
2762
  {
2633
- title: mapT("Marker field"),
2763
+ title: t("Marker field"),
2634
2764
  value: fieldNames.marker,
2635
2765
  options: markerFieldOptions,
2636
2766
  onChange: (v) => {
@@ -2648,17 +2778,17 @@
2648
2778
  dn.refresh();
2649
2779
  }
2650
2780
  }
2651
- ),
2781
+ ) : null,
2652
2782
  /* @__PURE__ */ jsxRuntimeExports.jsx(
2653
2783
  client.SchemaSettings.ModalItem,
2654
2784
  {
2655
- title: mapT("The default zoom level of the map"),
2785
+ title: t("The default zoom level of the map"),
2656
2786
  schema: {
2657
2787
  type: "object",
2658
- title: mapT("Set default zoom level"),
2788
+ title: t("Set default zoom level"),
2659
2789
  properties: {
2660
2790
  zoom: {
2661
- title: mapT("Zoom"),
2791
+ title: t("Zoom"),
2662
2792
  default: defaultZoom,
2663
2793
  "x-component": "InputNumber",
2664
2794
  "x-decorator": "FormItem",
@@ -2720,7 +2850,7 @@
2720
2850
  ),
2721
2851
  /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaSettings.ConnectDataBlocks, { type: client.FilterBlockType.TABLE, emptyDescription: t("No blocks to connect") }),
2722
2852
  /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaSettings.Divider, {}),
2723
- /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaSettings.Template, { componentName: "Map", collectionName: name, resourceName: defaultResource }),
2853
+ /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaSettings.Template, { componentName: "Map", collectionName: name2, resourceName: defaultResource }),
2724
2854
  /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaSettings.Divider, {}),
2725
2855
  /* @__PURE__ */ jsxRuntimeExports.jsx(
2726
2856
  client.SchemaSettings.Remove,
@@ -2733,84 +2863,6 @@
2733
2863
  )
2734
2864
  ] });
2735
2865
  };
2736
- const createMapBlockSchema = (options) => {
2737
- const { collection, resource, fieldNames, ...others } = options;
2738
- const schema = {
2739
- type: "void",
2740
- "x-acl-action": `${resource || collection}:list`,
2741
- "x-decorator": "MapBlockProvider",
2742
- "x-decorator-props": {
2743
- collection,
2744
- resource: resource || collection,
2745
- action: "list",
2746
- fieldNames,
2747
- params: {
2748
- paginate: false
2749
- },
2750
- ...others
2751
- },
2752
- "x-designer": "MapBlockDesigner",
2753
- "x-component": "CardItem",
2754
- // 保存当前筛选区块所能过滤的数据区块
2755
- "x-filter-targets": [],
2756
- properties: {
2757
- actions: {
2758
- type: "void",
2759
- "x-initializer": "MapActionInitializers",
2760
- "x-component": "ActionBar",
2761
- "x-component-props": {
2762
- style: {
2763
- marginBottom: 16
2764
- }
2765
- },
2766
- properties: {}
2767
- },
2768
- [shared.uid()]: {
2769
- type: "void",
2770
- "x-component": "MapBlock",
2771
- "x-component-props": {
2772
- useProps: "{{ useMapBlockProps }}"
2773
- },
2774
- properties: {
2775
- drawer: {
2776
- type: "void",
2777
- "x-component": "Action.Drawer",
2778
- "x-component-props": {
2779
- className: "nb-action-popup"
2780
- },
2781
- title: '{{ t("View record") }}',
2782
- properties: {
2783
- tabs: {
2784
- type: "void",
2785
- "x-component": "Tabs",
2786
- "x-component-props": {},
2787
- "x-initializer": "TabPaneInitializers",
2788
- properties: {
2789
- tab1: {
2790
- type: "void",
2791
- title: '{{t("Details")}}',
2792
- "x-component": "Tabs.TabPane",
2793
- "x-designer": "Tabs.Designer",
2794
- "x-component-props": {},
2795
- properties: {
2796
- grid: {
2797
- type: "void",
2798
- "x-component": "Grid",
2799
- "x-initializer": "RecordBlockInitializers",
2800
- properties: {}
2801
- }
2802
- }
2803
- }
2804
- }
2805
- }
2806
- }
2807
- }
2808
- }
2809
- }
2810
- }
2811
- };
2812
- return schema;
2813
- };
2814
2866
  const MapBlockInitializer = (props) => {
2815
2867
  const { insert } = props;
2816
2868
  const options = React.useContext(react.SchemaOptionsContext);
@@ -2824,7 +2876,9 @@
2824
2876
  componentType: "Map",
2825
2877
  icon: /* @__PURE__ */ jsxRuntimeExports.jsx(icons.TableOutlined, {}),
2826
2878
  onCreateBlockSchema: async ({ item }) => {
2827
- const mapFieldOptions = getCollectionFieldsOptions(item.name, ["point", "lineString", "polygon"]);
2879
+ const mapFieldOptions = getCollectionFieldsOptions(item.name, ["point", "lineString", "polygon"], {
2880
+ association: ["o2o", "obo", "oho", "o2m", "m2o", "m2m"]
2881
+ });
2828
2882
  const markerFieldOptions = getCollectionFieldsOptions(item.name, "string");
2829
2883
  const values = await client.FormDialog(
2830
2884
  t("Create map block"),
@@ -2839,9 +2893,11 @@
2839
2893
  title: t("Map field"),
2840
2894
  enum: mapFieldOptions,
2841
2895
  required: true,
2842
- "x-component": "Select",
2896
+ "x-component": "Cascader",
2843
2897
  "x-decorator": "FormItem",
2844
- default: (_a = mapFieldOptions[0]) == null ? void 0 : _a.value
2898
+ default: mapFieldOptions.length ? [mapFieldOptions[0].value, (_a = mapFieldOptions[0].children) == null ? void 0 : _a[0].value].filter(
2899
+ (v) => v !== void 0 && v !== null
2900
+ ) : []
2845
2901
  },
2846
2902
  marker: {
2847
2903
  title: t("Marker field"),
@@ -2850,16 +2906,13 @@
2850
2906
  "x-decorator": "FormItem",
2851
2907
  "x-reactions": (field) => {
2852
2908
  const value = field.form.values.field;
2853
- console.log("🚀 ~ file: MapBlockInitializer.tsx:45 ~ values ~ value:", value);
2854
- console.log(
2855
- "🚀 ~ file: MapBlockInitializer.tsx:50 ~ values ~ mapFieldOptions:",
2856
- mapFieldOptions
2857
- );
2858
- if (!value) {
2909
+ if (!(value == null ? void 0 : value.length)) {
2859
2910
  return;
2860
2911
  }
2861
- const item2 = mapFieldOptions.find((item3) => item3.value === value).type;
2862
- field.hidden = item2 !== "point";
2912
+ const item2 = findNestedOption(value, mapFieldOptions);
2913
+ if (item2) {
2914
+ field.hidden = item2.type !== "point";
2915
+ }
2863
2916
  }
2864
2917
  }
2865
2918
  }
@@ -0,0 +1 @@
1
+ export declare const getSource: (data: Record<string, any>, fields?: string[], type?: string) => any;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nocobase/plugin-map",
3
3
  "displayName": "Map",
4
4
  "displayName.zh-CN": "地图",
5
- "version": "0.12.0-alpha.2",
5
+ "version": "0.12.0-alpha.4",
6
6
  "description": "Provide map fields and blocks",
7
7
  "description.zh-CN": "提供地图字段和区块",
8
8
  "license": "AGPL-3.0",
@@ -34,5 +34,5 @@
34
34
  "@nocobase/test": "0.x",
35
35
  "@nocobase/utils": "0.x"
36
36
  },
37
- "gitHead": "a95e9e2666f0318c955113a4735bc005a2c9a767"
37
+ "gitHead": "215dc3b2437c501ca903b56cc378ab5e81c8a11c"
38
38
  }