react-native-maplibre-gl-js 1.2.1 → 1.3.0

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.
Files changed (31) hide show
  1. package/lib/module/react-native/components-factory/createWebObjectAsComponent.js +8 -2
  2. package/lib/module/react-native/components-factory/createWebObjectAsComponent.js.map +1 -1
  3. package/lib/module/react-native/components-factory/hooks/useWebObjectMountOnLaunch.js +10 -56
  4. package/lib/module/react-native/components-factory/hooks/useWebObjectMountOnLaunch.js.map +1 -1
  5. package/lib/module/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.js +86 -0
  6. package/lib/module/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.js.map +1 -0
  7. package/lib/module/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.types.js +2 -0
  8. package/lib/module/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.types.js.map +1 -0
  9. package/lib/module/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.js +27 -6
  10. package/lib/module/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.js.map +1 -1
  11. package/lib/module/react-native/hooks/atoms/useMapAtoms.utils.js +17 -3
  12. package/lib/module/react-native/hooks/atoms/useMapAtoms.utils.js.map +1 -1
  13. package/lib/module/web/generated/webview_static_html.js +5 -2
  14. package/lib/module/web/generated/webview_static_html.js.map +1 -1
  15. package/lib/module/web/maplibre-gl-js/MapController.js +7 -0
  16. package/lib/module/web/maplibre-gl-js/MapController.js.map +1 -1
  17. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.d.ts.map +1 -1
  18. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountOnLaunch.d.ts +6 -4
  19. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountOnLaunch.d.ts.map +1 -1
  20. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.d.ts +19 -0
  21. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.d.ts.map +1 -0
  22. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.types.d.ts +8 -0
  23. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.types.d.ts.map +1 -0
  24. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.d.ts +10 -1
  25. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.d.ts.map +1 -1
  26. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.utils.d.ts +2 -1
  27. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.utils.d.ts.map +1 -1
  28. package/lib/typescript/src/web/generated/webview_static_html.d.ts +1 -1
  29. package/lib/typescript/src/web/generated/webview_static_html.d.ts.map +1 -1
  30. package/lib/typescript/src/web/maplibre-gl-js/MapController.d.ts.map +1 -1
  31. package/package.json +1 -1
@@ -4,16 +4,22 @@ import { forwardRef, useId } from 'react';
4
4
  import useWebObjectMountOnLaunch from "./hooks/useWebObjectMountOnLaunch.js";
5
5
  import useWebObjectMethodsProxy from "./hooks/useWebObjectMethodsProxy.js";
6
6
  import useWebObjectPropertiesUpdater from "./hooks/useWebObjectPropertiesUpdater.js";
7
+ import useWebObjectMountUnmountCallbacks from "./hooks/useWebObjectMountUnmountCallbacks.js";
7
8
  const createWebObjectAsComponent = objectType => {
8
9
  return /*#__PURE__*/forwardRef((props, ref) => {
9
10
  // UID of the web object.
10
11
  const id = useId();
12
+ // Callbacks to mount and unmount the web object.
13
+ const {
14
+ mount,
15
+ unmount
16
+ } = useWebObjectMountUnmountCallbacks(props, id, objectType);
11
17
  // Mount the web object on launch.
12
- useWebObjectMountOnLaunch(props, id, objectType);
18
+ useWebObjectMountOnLaunch(props, id, mount, unmount);
13
19
  // Forward a method call on the RN object to the web object.
14
20
  useWebObjectMethodsProxy(ref, id);
15
21
  // Update the web object properties when they changed in the component body.
16
- useWebObjectPropertiesUpdater(props, id);
22
+ useWebObjectPropertiesUpdater(props, mount, unmount);
17
23
  return null;
18
24
  });
19
25
  };
@@ -1 +1 @@
1
- {"version":3,"names":["forwardRef","useId","useWebObjectMountOnLaunch","useWebObjectMethodsProxy","useWebObjectPropertiesUpdater","createWebObjectAsComponent","objectType","props","ref","id"],"sourceRoot":"../../../../src","sources":["react-native/components-factory/createWebObjectAsComponent.ts"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,KAAK,QAAQ,OAAO;AAOzC,OAAOC,yBAAyB,MAAM,sCAAmC;AACzE,OAAOC,wBAAwB,MAAM,qCAAkC;AACvE,OAAOC,6BAA6B,MAAM,0CAAuC;AAEjF,MAAMC,0BAA0B,GAI9BC,UAAyB,IACU;EACnC,oBAAON,UAAU,CAAa,CAACO,KAAK,EAAEC,GAAG,KAAK;IAC5C;IACA,MAAMC,EAAE,GAAGR,KAAK,CAAC,CAAC;IAClB;IACAC,yBAAyB,CAAQK,KAAK,EAAEE,EAAE,EAAEH,UAAU,CAAC;IACvD;IACAH,wBAAwB,CAAMK,GAAG,EAAEC,EAAE,CAAC;IACtC;IACAL,6BAA6B,CAAQG,KAAK,EAAWE,EAAE,CAAC;IAExD,OAAO,IAAI;EACb,CAAC,CAAC;AACJ,CAAC;AAED,eAAeJ,0BAA0B","ignoreList":[]}
1
+ {"version":3,"names":["forwardRef","useId","useWebObjectMountOnLaunch","useWebObjectMethodsProxy","useWebObjectPropertiesUpdater","useWebObjectMountUnmountCallbacks","createWebObjectAsComponent","objectType","props","ref","id","mount","unmount"],"sourceRoot":"../../../../src","sources":["react-native/components-factory/createWebObjectAsComponent.ts"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,KAAK,QAAQ,OAAO;AAOzC,OAAOC,yBAAyB,MAAM,sCAAmC;AACzE,OAAOC,wBAAwB,MAAM,qCAAkC;AACvE,OAAOC,6BAA6B,MAAM,0CAAuC;AACjF,OAAOC,iCAAiC,MAAM,8CAA2C;AAEzF,MAAMC,0BAA0B,GAI9BC,UAAyB,IACU;EACnC,oBAAOP,UAAU,CAAa,CAACQ,KAAK,EAAEC,GAAG,KAAK;IAC5C;IACA,MAAMC,EAAE,GAAGT,KAAK,CAAC,CAAC;IAClB;IACA,MAAM;MAAEU,KAAK;MAAEC;IAAQ,CAAC,GAAGP,iCAAiC,CAC1DG,KAAK,EACLE,EAAE,EACFH,UACF,CAAC;IACD;IACAL,yBAAyB,CAAQM,KAAK,EAAEE,EAAE,EAAEC,KAAK,EAAEC,OAAO,CAAC;IAC3D;IACAT,wBAAwB,CAAMM,GAAG,EAAEC,EAAE,CAAC;IACtC;IACAN,6BAA6B,CAAQI,KAAK,EAAEG,KAAK,EAAEC,OAAO,CAAC;IAE3D,OAAO,IAAI;EACb,CAAC,CAAC;AACJ,CAAC;AAED,eAAeN,0BAA0B","ignoreList":[]}
@@ -1,69 +1,23 @@
1
1
  "use strict";
2
2
 
3
- import { useCallback, useEffect, useRef } from 'react';
4
- import useMapAtoms from "../../hooks/atoms/useMapAtoms.js";
5
-
3
+ import { useEffect } from 'react';
6
4
  /**
7
- * Mount the web object once the React Native one is mounted.
5
+ * Mount and unmount the web object once the React Native one is mounted /
6
+ * unmounted.
8
7
  * @param props - The RN object props.
9
8
  * @param objectId - The ID of the web object that owns the method.
10
- * @param objectType - The type of the associated web object.
9
+ * @param mount - Callback.
10
+ * @param unmount - Callback.
11
11
  */
12
- const useWebObjectMountOnLaunch = (props, objectId, objectType) => {
13
- // Refs.
14
- const isMounted = useRef(false);
15
- // States.
16
- // - Global.
17
- const {
18
- isWebWorldReady,
19
- dispatchMessage,
20
- setWebObjectListeners,
21
- deleteWebObjectListeners
22
- } = useMapAtoms();
23
- const mount = useCallback(() => {
24
- // Mount the component as a web object on the web world.
25
- dispatchMessage({
26
- type: `webObjectMount`,
27
- payload: {
28
- objectId: objectId,
29
- objectType,
30
- options: props.options ?? {},
31
- listeners: props.listeners ?? {}
32
- }
33
- });
34
- // Register listeners on event from the web world.
35
- setWebObjectListeners({
36
- objectId: objectId,
37
- listeners: props.listeners ?? {}
38
- });
39
- isMounted.current = true;
40
- }, [objectId, objectType, props.options, props.listeners, dispatchMessage, setWebObjectListeners]);
41
- const unmount = useCallback(() => {
42
- dispatchMessage({
43
- type: `webObjectUnmount`,
44
- payload: {
45
- objectId
46
- }
47
- });
48
- deleteWebObjectListeners({
49
- objectId
50
- });
51
- isMounted.current = false;
52
- }, [objectId, dispatchMessage, deleteWebObjectListeners]);
53
-
54
- // On mount/unmount update the web object.
12
+ const useWebObjectMountOnLaunch = (props, objectId, mount, unmount) => {
13
+ // On mount/unmount, do the same for the web object.
55
14
  useEffect(() => {
56
- if (!isWebWorldReady) {
57
- return;
58
- }
59
- if (!isMounted.current) {
60
- mount();
61
- }
15
+ mount();
62
16
  // TODO verify if we unmount here? it sure that it must not be in this
63
17
  // use effect, otherwise on start if mount then unmount then mount, but
64
18
  // we may have to unmount in another effect
65
- //return unmount
66
- }, [objectId, isWebWorldReady, dispatchMessage, props, unmount, mount]);
19
+ //return unmount()
20
+ }, [objectId, props, mount, unmount]);
67
21
  };
68
22
  export default useWebObjectMountOnLaunch;
69
23
  //# sourceMappingURL=useWebObjectMountOnLaunch.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useRef","useMapAtoms","useWebObjectMountOnLaunch","props","objectId","objectType","isMounted","isWebWorldReady","dispatchMessage","setWebObjectListeners","deleteWebObjectListeners","mount","type","payload","options","listeners","current","unmount"],"sourceRoot":"../../../../../src","sources":["react-native/components-factory/hooks/useWebObjectMountOnLaunch.ts"],"mappings":";;AAAA,SAA+BA,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAG5E,OAAOC,WAAW,MAAM,kCAA+B;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,GAAGA,CAChCC,KAA6B,EAC7BC,QAAgB,EAChBC,UAAyB,KACtB;EACH;EACA,MAAMC,SAAS,GAAGN,MAAM,CAAU,KAAK,CAAC;EACxC;EACA;EACA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AAC,CAAC;AACzE,CAAC;AAED,eAAeT,yBAAyB","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useWebObjectMountOnLaunch","props","objectId","mount","unmount"],"sourceRoot":"../../../../../src","sources":["react-native/components-factory/hooks/useWebObjectMountOnLaunch.ts"],"mappings":";;AAAA,SAA+BA,SAAS,QAAQ,OAAO;AAIvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,GAAGA,CAChCC,KAA6B,EAC7BC,QAAgB,EAChBC,KAAuD,EACvDC,OAAyD,KACtD;EACH;EACAL,SAAS,CAAC,MAAM;IACdI,KAAK,CAAC,CAAC;IACP;IACA;IACA;IACA;EACF,CAAC,EAAE,CAACD,QAAQ,EAAED,KAAK,EAAEE,KAAK,EAAEC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED,eAAeJ,yBAAyB","ignoreList":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useRef } from 'react';
4
+ import useMapAtoms from "../../hooks/atoms/useMapAtoms.js";
5
+ /**
6
+ * @param props - The RN object props.
7
+ * @param objectId - The ID of the web object that owns the method.
8
+ * @param objectType - The type of the associated web object.
9
+ * @returns – The callbacks used to mount and unmount the web object. They
10
+ * internally handle edge cases where execution must be prevented, with no
11
+ * external management required. They allow (un)mounting the web objects with
12
+ * their options, but also their listeners.
13
+ */
14
+ const useWebObjectMountUnmountCallbacks = (props, objectId, objectType) => {
15
+ // Refs.
16
+ const areOptionsMounted = useRef(false);
17
+ const areListenersMounted = useRef(false);
18
+ // States.
19
+ // - Global.
20
+ const {
21
+ isWebWorldReady,
22
+ dispatchMessage,
23
+ setWebObjectListeners,
24
+ deleteWebObjectListeners
25
+ } = useMapAtoms();
26
+ const mount = useCallback(({
27
+ options = true,
28
+ listeners = true
29
+ } = {}) => {
30
+ if (!isWebWorldReady) {
31
+ return;
32
+ }
33
+ // Mount the component as a web object within the web world.
34
+ if (options && !areOptionsMounted.current) {
35
+ dispatchMessage({
36
+ type: `webObjectMount`,
37
+ payload: {
38
+ objectId: objectId,
39
+ objectType,
40
+ options: props.options ?? {},
41
+ listeners: props.listeners ?? {}
42
+ }
43
+ });
44
+ areOptionsMounted.current = true;
45
+ }
46
+ // Register listeners on event from the web world.
47
+ if (listeners && !areListenersMounted.current) {
48
+ setWebObjectListeners({
49
+ objectId: objectId,
50
+ listeners: props.listeners ?? {}
51
+ });
52
+ areListenersMounted.current = true;
53
+ }
54
+ }, [objectId, objectType, props.options, props.listeners, isWebWorldReady, dispatchMessage, setWebObjectListeners]);
55
+ const unmount = useCallback(({
56
+ options = true,
57
+ listeners = true
58
+ } = {}) => {
59
+ if (!isWebWorldReady) {
60
+ return;
61
+ }
62
+ // Mount the component as a web object within the web world.
63
+ if (options && areOptionsMounted.current) {
64
+ dispatchMessage({
65
+ type: `webObjectUnmount`,
66
+ payload: {
67
+ objectId
68
+ }
69
+ });
70
+ areOptionsMounted.current = false;
71
+ }
72
+ // Register listeners on event from the web world.
73
+ if (listeners && areListenersMounted.current) {
74
+ deleteWebObjectListeners({
75
+ objectId
76
+ });
77
+ areListenersMounted.current = false;
78
+ }
79
+ }, [objectId, isWebWorldReady, dispatchMessage, deleteWebObjectListeners]);
80
+ return {
81
+ mount,
82
+ unmount
83
+ };
84
+ };
85
+ export default useWebObjectMountUnmountCallbacks;
86
+ //# sourceMappingURL=useWebObjectMountUnmountCallbacks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useRef","useMapAtoms","useWebObjectMountUnmountCallbacks","props","objectId","objectType","areOptionsMounted","areListenersMounted","isWebWorldReady","dispatchMessage","setWebObjectListeners","deleteWebObjectListeners","mount","options","listeners","current","type","payload","unmount"],"sourceRoot":"../../../../../src","sources":["react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.ts"],"mappings":";;AACA,SAA+BA,WAAW,EAAEC,MAAM,QAAQ,OAAO;AAEjE,OAAOC,WAAW,MAAM,kCAA+B;AAGvD;AACA;AACA;AAC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zB,CAAC;IACCc,OAAO,GAAG,IAAI;IACdC,SAAS,GAAG;EACgB,CAAC,GAAG,CAAC,CAAC,KAAK;IACvC,IAAI,CAACN,eAAe,EAAE;MACpB;IACF;IACA;IACA,IAAIK,OAAO,IAAIP,iBAAiB,CAACS,OAAO,EAAE;MACxCN,eAAe,CAAC;QACdO,IAAI,EAAE,kBAAkB;QACxBC,OAAO,EAAE;UAAEb;QAAS;MACtB,CAAC,CAAC;MACFE,iBAAiB,CAACS,OAAO,GAAG,KAAK;IACnC;IACA;IACA,IAAID,SAAS,IAAIP,mBAAmB,CAACQ,OAAO,EAAE;MAC5CJ,wBAAwB,CAAC;QAAEP;MAAS,CAAC,CAAC;MACtCG,mBAAmB,CAACQ,OAAO,GAAG,KAAK;IACrC;EACF,CAAC,EACD,CAACX,QAAQ,EAAEI,eAAe,EAAEC,eAAe,EAAEE,wBAAwB,CACvE,CAAC;EAED,OAAO;IAAEC,KAAK;IAAEM;EAAQ,CAAC;AAC3B,CAAC;AAED,eAAehB,iCAAiC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=useWebObjectMountUnmountCallbacks.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["react-native/components-factory/hooks/useWebObjectMountUnmountCallbacks.types.ts"],"mappings":"","ignoreList":[]}
@@ -1,14 +1,35 @@
1
1
  "use strict";
2
2
 
3
- import { useEffect } from 'react';
4
- export const useWebObjectPropertiesUpdater = (props, id) => {
3
+ import { useEffect, useMemo, useRef } from 'react';
4
+ import { stableStringify } from "../../hooks/atoms/useMapAtoms.utils.js";
5
+ /**
6
+ * Propagate any change in the component props to the web world, by unmounting
7
+ * and mounting the web object with the new options.
8
+ * @param props - The RN object props.
9
+ * @param mount - Callback.
10
+ * @param unmount - Callback.
11
+ */
12
+ export const useWebObjectPropertiesUpdater = (props, mount, unmount) => {
5
13
  // Refs.
6
- //const previousProps = useRef<Record<string, any>>({})
14
+ const optionsAsStringPrevious = useRef('');
15
+ const optionsAsString = useMemo(() => stableStringify(props.options), [props]);
7
16
 
17
+ // Mount options only when they have changed (mounted in the web world).
18
+ // Listeners are always mounted: they are inexpensive (mounted in the RN
19
+ // world) and cannot be reliably compared when declared inline in the
20
+ // component, as they change on every render.
8
21
  useEffect(() => {
9
- // TODO compare previous and new props and update only if new.
10
- return;
11
- }, [id, props]);
22
+ const areOptionsEqual = optionsAsStringPrevious.current === optionsAsString;
23
+ unmount({
24
+ options: !areOptionsEqual,
25
+ listeners: true
26
+ });
27
+ mount({
28
+ options: !areOptionsEqual,
29
+ listeners: true
30
+ });
31
+ optionsAsStringPrevious.current = optionsAsString;
32
+ }, [mount, unmount, optionsAsStringPrevious, optionsAsString, props.listeners]);
12
33
  };
13
34
  export default useWebObjectPropertiesUpdater;
14
35
  //# sourceMappingURL=useWebObjectPropertiesUpdater.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useWebObjectPropertiesUpdater","props","id"],"sourceRoot":"../../../../../src","sources":["react-native/components-factory/hooks/useWebObjectPropertiesUpdater.ts"],"mappings":";;AACA,SAASA,SAAS,QAAQ,OAAO;AAEjC,OAAO,MAAMC,6BAA6B,GAAGA,CAG3CC,KAAY,EACZC,EAAU,KACP;EACH;EACA;;EAEAH,SAAS,CAAC,MAAM;IACd;IACA;EACF,CAAC,EAAE,CAACG,EAAE,EAAED,KAAK,CAAC,CAAC;AACjB,CAAC;AAED,eAAeD,6BAA6B","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useMemo","useRef","stableStringify","useWebObjectPropertiesUpdater","props","mount","unmount","optionsAsStringPrevious","optionsAsString","options","areOptionsEqual","current","listeners"],"sourceRoot":"../../../../../src","sources":["react-native/components-factory/hooks/useWebObjectPropertiesUpdater.ts"],"mappings":";;AACA,SAA+BA,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AACxE,SAASC,eAAe,QAAQ,wCAAqC;AAGrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,6BAA6B,GAAGA,CAG3CC,KAA6B,EAC7BC,KAAuD,EACvDC,OAAyD,KACtD;EACH;EACA,MAAMC,uBAAuB,GAAGN,MAAM,CAAS,EAAE,CAAC;EAElD,MAAMO,eAAe,GAAGR,OAAO,CAAC,MAAME,eAAe,CAACE,KAAK,CAACK,OAAO,CAAC,EAAE,CAACL,KAAK,CAAC,CAAC;;EAE9E;EACA;EACA;EACA;EACAL,SAAS,CAAC,MAAM;IACd,MAAMW,eAAe,GAAGH,uBAAuB,CAACI,OAAO,KAAKH,eAAe;IAC3EF,OAAO,CAAC;MAAEG,OAAO,EAAE,CAACC,eAAe;MAAEE,SAAS,EAAE;IAAK,CAAC,CAAC;IACvDP,KAAK,CAAC;MAAEI,OAAO,EAAE,CAACC,eAAe;MAAEE,SAAS,EAAE;IAAK,CAAC,CAAC;IACrDL,uBAAuB,CAACI,OAAO,GAAGH,eAAe;EACnD,CAAC,EAAE,CACDH,KAAK,EACLC,OAAO,EACPC,uBAAuB,EACvBC,eAAe,EACfJ,KAAK,CAACQ,SAAS,CAChB,CAAC;AACJ,CAAC;AAED,eAAeT,6BAA6B","ignoreList":[]}
@@ -2,17 +2,31 @@
2
2
 
3
3
  /**
4
4
  * Stable stringify for messages that may contain functions. Keep the function
5
- * members as '...' to allow identification of the object type (by default a
5
+ * members as '...' to allow identification of the object type (by default, a
6
6
  * function cannot be stringified and is removed from the final string).
7
+ * Keys are sorted alphabetically to ensure consistent output.
7
8
  * @param message - The message to be stringified.
8
9
  * @returns - The stringified message.
9
10
  */
10
11
  export const stableStringify = message => {
11
- return JSON.stringify(message, (_, value) => {
12
+ const replacer = (_, value) => {
12
13
  if (typeof value === 'function') {
13
14
  return '...';
14
15
  }
15
16
  return value;
16
- });
17
+ };
18
+ const sortKeys = obj => {
19
+ if (Array.isArray(obj)) {
20
+ return obj.map(sortKeys);
21
+ } else if (obj !== null && typeof obj === 'object') {
22
+ const sortedObj = {};
23
+ Object.keys(obj).sort().forEach(key => {
24
+ sortedObj[key] = sortKeys(obj[key]);
25
+ });
26
+ return sortedObj;
27
+ }
28
+ return obj;
29
+ };
30
+ return JSON.stringify(sortKeys(message), replacer);
17
31
  };
18
32
  //# sourceMappingURL=useMapAtoms.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["stableStringify","message","JSON","stringify","_","value"],"sourceRoot":"../../../../../src","sources":["react-native/hooks/atoms/useMapAtoms.utils.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,eAAe,GAAIC,OAAY,IAAa;EACvD,OAAOC,IAAI,CAACC,SAAS,CAACF,OAAO,EAAE,CAACG,CAAC,EAAEC,KAAK,KAAK;IAC3C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MAC/B,OAAO,KAAK;IACd;IACA,OAAOA,KAAK;EACd,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["stableStringify","message","replacer","_","value","sortKeys","obj","Array","isArray","map","sortedObj","Object","keys","sort","forEach","key","JSON","stringify"],"sourceRoot":"../../../../../src","sources":["react-native/hooks/atoms/useMapAtoms.utils.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,eAAe,GAAIC,OAAY,IAAa;EACvD,MAAMC,QAAQ,GAAGA,CAACC,CAAS,EAAEC,KAAU,KAAK;IAC1C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MAC/B,OAAO,KAAK;IACd;IACA,OAAOA,KAAK;EACd,CAAC;EAED,MAAMC,QAAQ,GAAIC,GAAQ,IAAU;IAClC,IAAIC,KAAK,CAACC,OAAO,CAACF,GAAG,CAAC,EAAE;MACtB,OAAOA,GAAG,CAACG,GAAG,CAACJ,QAAQ,CAAC;IAC1B,CAAC,MAAM,IAAIC,GAAG,KAAK,IAAI,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE;MAClD,MAAMI,SAA8B,GAAG,CAAC,CAAC;MACzCC,MAAM,CAACC,IAAI,CAACN,GAAG,CAAC,CACbO,IAAI,CAAC,CAAC,CACNC,OAAO,CAAEC,GAAG,IAAK;QAChBL,SAAS,CAACK,GAAG,CAAC,GAAGV,QAAQ,CAACC,GAAG,CAACS,GAAG,CAAC,CAAC;MACrC,CAAC,CAAC;MACJ,OAAOL,SAAS;IAClB;IACA,OAAOJ,GAAG;EACZ,CAAC;EAED,OAAOU,IAAI,CAACC,SAAS,CAACZ,QAAQ,CAACJ,OAAO,CAAC,EAAEC,QAAQ,CAAC;AACpD,CAAC","ignoreList":[]}
@@ -23359,6 +23359,11 @@ uniform mat4 u_projection_matrix;
23359
23359
  message.payload.objectId,
23360
23360
  message.payload.listeners
23361
23361
  );
23362
+ this.#objects.entries().forEach(([, object]) => {
23363
+ if (!(object instanceof import_maplibre_gl.default.Map)) {
23364
+ object.addTo(map);
23365
+ }
23366
+ });
23362
23367
  break;
23363
23368
  }
23364
23369
  case "marker": {
@@ -23420,8 +23425,6 @@ uniform mat4 u_projection_matrix;
23420
23425
  if (!this.#runIfSpecialMethod(message, object)) {
23421
23426
  result = await this.#runNormalMethod(message, object);
23422
23427
  }
23423
- if (!(object instanceof import_maplibre_gl.default.Map)) {
23424
- }
23425
23428
  this.reactNativeBridge.postMessage({
23426
23429
  type: "webObjectMethodResponse",
23427
23430
  payload: { requestId: message.payload.requestId, result }