@innspel/react-native 0.9.1 → 0.9.2

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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/InnspelProvider.tsx
2
- import { createContext as createContext3, useCallback as useCallback3, useContext as useContext4, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
2
+ import { createContext as createContext3, useCallback as useCallback3, useContext as useContext4, useMemo as useMemo4, useRef as useRef4, useState as useState4 } from "react";
3
3
  import { View as View9 } from "react-native";
4
4
 
5
5
  // src/skjermbilde.ts
@@ -355,7 +355,7 @@ import {
355
355
  InnspelApiError,
356
356
  InnspelQueueFullError
357
357
  } from "@innspel/core";
358
- import { useCallback as useCallback2, useContext as useContext3, useEffect, useRef as useRef2, useState as useState3 } from "react";
358
+ import { useCallback as useCallback2, useContext as useContext3, useEffect, useRef as useRef3, useState as useState3 } from "react";
359
359
  import { KeyboardAvoidingView, Modal, Pressable as Pressable5, View as View8 } from "react-native";
360
360
  import { initialWindowMetrics, SafeAreaInsetsContext } from "react-native-safe-area-context";
361
361
 
@@ -517,11 +517,11 @@ function Ikon({
517
517
  }
518
518
 
519
519
  // src/widget/Felt.tsx
520
- import { useMemo, useState } from "react";
520
+ import { useMemo as useMemo2, useState } from "react";
521
521
  import { Pressable as Pressable2, ScrollView, Text as Text2, TextInput, View as View2 } from "react-native";
522
522
 
523
523
  // src/widget/primitiver.tsx
524
- import "react";
524
+ import { useMemo, useRef } from "react";
525
525
  import { Pressable, Text, View } from "react-native";
526
526
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
527
527
  function Btn({
@@ -534,10 +534,12 @@ function Btn({
534
534
  accessibilityLabel,
535
535
  grow,
536
536
  testID,
537
- busy
537
+ busy,
538
+ trykkForbiForelder
538
539
  }) {
539
540
  const tema = useTema();
540
541
  const c = tema.color;
542
+ const forbi = useTrykkForbiForelder(onPress, !!disabled, tema.touch / 2);
541
543
  const bakgrunn = variant === "primary" ? c.actionPrimary : variant === "secondary" ? c.surfaceRaised : "transparent";
542
544
  const tekstfarge = variant === "primary" ? c.onActionPrimary : variant === "danger" ? c.danger : c.actionSecondaryText;
543
545
  const kant = variant === "ghost" ? "transparent" : variant === "primary" ? c.actionPrimary : c.actionSecondaryBorder;
@@ -551,6 +553,7 @@ function Btn({
551
553
  accessibilityState: { disabled: !!disabled, busy: !!busy },
552
554
  disabled,
553
555
  onPress,
556
+ ...trykkForbiForelder ? forbi : {},
554
557
  style: {
555
558
  minHeight: tema.touch,
556
559
  borderRadius: tema.radius.md,
@@ -583,6 +586,37 @@ function Btn({
583
586
  hint ? /* @__PURE__ */ jsx2(Hint, { children: hint }) : null
584
587
  ] });
585
588
  }
589
+ function useTrykkForbiForelder(onPress, laast, slingring) {
590
+ const start = useRef(null);
591
+ const fikkResponder = useRef(false);
592
+ const siste = useRef({ onPress, laast });
593
+ siste.current = { onPress, laast };
594
+ return useMemo(
595
+ () => ({
596
+ onPressIn: () => {
597
+ fikkResponder.current = true;
598
+ },
599
+ onTouchStart: (e) => {
600
+ start.current = { x: e.nativeEvent.pageX, y: e.nativeEvent.pageY };
601
+ },
602
+ onTouchEnd: (e) => {
603
+ const s = start.current;
604
+ start.current = null;
605
+ const innenfor = s !== null && Math.abs(e.nativeEvent.pageX - s.x) <= slingring && Math.abs(e.nativeEvent.pageY - s.y) <= slingring;
606
+ setTimeout(() => {
607
+ const tatt = fikkResponder.current;
608
+ fikkResponder.current = false;
609
+ if (!tatt && innenfor && !siste.current.laast) siste.current.onPress?.();
610
+ }, 0);
611
+ },
612
+ onTouchCancel: () => {
613
+ start.current = null;
614
+ fikkResponder.current = false;
615
+ }
616
+ }),
617
+ [slingring]
618
+ );
619
+ }
586
620
  function H({ children, sub }) {
587
621
  const tema = useTema();
588
622
  return /* @__PURE__ */ jsxs(View, { style: { gap: tema.space.xs }, children: [
@@ -940,7 +974,7 @@ function Felt({
940
974
  const full = brukt >= textMaxLength;
941
975
  const visTeller = brukt >= textMaxLength * 0.8;
942
976
  const uavklart = funn.find((f) => !beholdt.includes(f.match));
943
- const linjer = useMemo(() => {
977
+ const linjer = useMemo2(() => {
944
978
  const etiketter = {
945
979
  screen: "Skjerm",
946
980
  appVersion: "Appversjon",
@@ -1217,7 +1251,8 @@ function Felt({
1217
1251
  disabled: forKort || sender,
1218
1252
  busy: sender,
1219
1253
  hint: forKort ? tekst.forKort(minTextLength) : harVedlegg ? tekst.sendHintMedBilde : void 0,
1220
- onPress: onSend
1254
+ onPress: onSend,
1255
+ trykkForbiForelder: true
1221
1256
  }
1222
1257
  ) })
1223
1258
  ] });
@@ -1550,7 +1585,7 @@ function MineInnspill({
1550
1585
 
1551
1586
  // src/widget/Skjermbilde.tsx
1552
1587
  import { skaler, strokTilRekter, treffer, trykkTilRekt } from "@innspel/core";
1553
- import { useCallback, useMemo as useMemo2, useRef, useState as useState2 } from "react";
1588
+ import { useCallback, useMemo as useMemo3, useRef as useRef2, useState as useState2 } from "react";
1554
1589
  import { Image as Image2, Pressable as Pressable4, StyleSheet, Text as Text7, View as View7 } from "react-native";
1555
1590
  import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
1556
1591
  function Skjermbilde({
@@ -1569,13 +1604,13 @@ function Skjermbilde({
1569
1604
  const [allTekst, setAllTekst] = useState2(false);
1570
1605
  const [egne, setEgne] = useState2([]);
1571
1606
  const [ramme, setRamme] = useState2(null);
1572
- const strok = useRef([]);
1573
- const visning = useMemo2(() => {
1607
+ const strok = useRef2([]);
1608
+ const visning = useMemo3(() => {
1574
1609
  if (!ramme) return null;
1575
1610
  const s = Math.min(ramme.width / bilde.width, ramme.height / bilde.height);
1576
1611
  return { width: Math.floor(bilde.width * s), height: Math.floor(bilde.height * s) };
1577
1612
  }, [ramme, bilde.width, bilde.height]);
1578
- const automasker = useMemo2(
1613
+ const automasker = useMemo3(
1579
1614
  () => visning ? automaskerRot.map((r) => skaler(r, rotStorrelse, visning)) : [],
1580
1615
  [automaskerRot, rotStorrelse, visning]
1581
1616
  );
@@ -1792,7 +1827,7 @@ function Widget({
1792
1827
  const tema = useTema();
1793
1828
  const insets = useContext3(SafeAreaInsetsContext) ?? initialWindowMetrics?.insets ?? { top: 0, bottom: 0, left: 0, right: 0 };
1794
1829
  const skjermbilde = useSkjermbilde();
1795
- const previewRef = useRef2(null);
1830
+ const previewRef = useRef3(null);
1796
1831
  const [steg, setSteg] = useState3("valg");
1797
1832
  const [spor, setSpor] = useState3("feil");
1798
1833
  const [verdi, setVerdi] = useState3("");
@@ -1833,9 +1868,23 @@ function Widget({
1833
1868
  setVedlegg(void 0);
1834
1869
  setKomponerer(false);
1835
1870
  }, []);
1871
+ const [mineDirekte, setMineDirekte] = useState3(false);
1872
+ const [stegForMine, setStegForMine] = useState3("valg");
1873
+ const stegRef = useRef3(steg);
1874
+ stegRef.current = steg;
1875
+ const harUtkast = verdi.trim().length > 0 || vedlegg !== void 0;
1836
1876
  const lukk = useCallback2(() => {
1877
+ onLukk();
1878
+ if (stegRef.current === "mine" && mineDirekte) {
1879
+ setSteg(stegForMine);
1880
+ setMineDirekte(false);
1881
+ }
1882
+ }, [onLukk, mineDirekte, stegForMine]);
1883
+ const lukkOgNullstill = useCallback2(() => {
1837
1884
  onLukk();
1838
1885
  nullstill();
1886
+ setMineDirekte(false);
1887
+ setStegForMine("valg");
1839
1888
  }, [onLukk, nullstill]);
1840
1889
  useEffect(() => {
1841
1890
  if (!synlig) return;
@@ -1845,8 +1894,8 @@ function Widget({
1845
1894
  if (!client.isAnonymous) {
1846
1895
  void client.subjects.submissions().then(setMine).catch(() => void 0);
1847
1896
  }
1848
- if (apneOpsjoner?.view === "mine" && !client.isAnonymous) void visMine();
1849
- else if (apneOpsjoner?.track) velgSpor(apneOpsjoner.track);
1897
+ if (apneOpsjoner?.view === "mine" && !client.isAnonymous) void visMine(true);
1898
+ else if (apneOpsjoner?.track && !harUtkast) void velgSpor(apneOpsjoner.track);
1850
1899
  }, [synlig]);
1851
1900
  const hentKort = useCallback2(async () => {
1852
1901
  setLasterKort(true);
@@ -1944,6 +1993,11 @@ function Widget({
1944
1993
  }, []);
1945
1994
  const gaaTilbake = useCallback2(() => {
1946
1995
  setFeil(void 0);
1996
+ if (steg === "mine") {
1997
+ if (mineDirekte) lukk();
1998
+ else setSteg("valg");
1999
+ return;
2000
+ }
1947
2001
  if (steg === "skjermbilde") {
1948
2002
  setBilde(void 0);
1949
2003
  setAutomasker([]);
@@ -1955,7 +2009,12 @@ function Widget({
1955
2009
  return;
1956
2010
  }
1957
2011
  setSteg("valg");
1958
- }, [steg, spor, kort.length]);
2012
+ }, [steg, spor, kort.length, mineDirekte, lukk]);
2013
+ const androidTilbake = useCallback2(() => {
2014
+ if (steg === "valg") lukk();
2015
+ else if (steg === "kvittering") lukkOgNullstill();
2016
+ else gaaTilbake();
2017
+ }, [steg, lukk, lukkOgNullstill, gaaTilbake]);
1959
2018
  const send = useCallback2(async () => {
1960
2019
  setSender(true);
1961
2020
  setFeil(void 0);
@@ -2002,7 +2061,13 @@ function Widget({
2002
2061
  },
2003
2062
  [client]
2004
2063
  );
2005
- const visMine = useCallback2(async () => {
2064
+ const visMine = useCallback2(async (direkte = false) => {
2065
+ if (direkte) {
2066
+ if (stegRef.current !== "mine") setStegForMine(stegRef.current);
2067
+ } else {
2068
+ setStegForMine("valg");
2069
+ }
2070
+ setMineDirekte(direkte);
2006
2071
  setSteg("mine");
2007
2072
  setLasterMine(true);
2008
2073
  try {
@@ -2013,13 +2078,18 @@ function Widget({
2013
2078
  setLasterMine(false);
2014
2079
  }
2015
2080
  }, [client]);
2081
+ const nyttFraMine = useCallback2(() => {
2082
+ setMineDirekte(false);
2083
+ if (harUtkast) setSteg(stegForMine);
2084
+ else nullstill();
2085
+ }, [harUtkast, stegForMine, nullstill]);
2016
2086
  return /* @__PURE__ */ jsx9(
2017
2087
  Modal,
2018
2088
  {
2019
2089
  visible: synlig,
2020
2090
  transparent: true,
2021
2091
  animationType: "slide",
2022
- onRequestClose: lukk,
2092
+ onRequestClose: androidTilbake,
2023
2093
  accessibilityViewIsModal: true,
2024
2094
  children: /* @__PURE__ */ jsx9(
2025
2095
  KeyboardAvoidingView,
@@ -2057,7 +2127,7 @@ function Widget({
2057
2127
  testID: "lukk",
2058
2128
  accessibilityRole: "button",
2059
2129
  accessibilityLabel: tekst.lukk,
2060
- onPress: lukk,
2130
+ onPress: steg === "kvittering" ? lukkOgNullstill : lukk,
2061
2131
  style: { minWidth: tema.touch, minHeight: tema.touch, alignItems: "center", justifyContent: "center" },
2062
2132
  children: /* @__PURE__ */ jsx9(Ikon, { navn: "close-outline", farge: tema.color.textSecondary })
2063
2133
  }
@@ -2075,7 +2145,7 @@ function Widget({
2075
2145
  ikon: "list-outline",
2076
2146
  label: mine.length > 0 ? tekst.mineMedAntall(mine.length) : tekst.mineTittel,
2077
2147
  accessibilityLabel: mine.length > 0 ? tekst.mineEtikett(mine.length) : tekst.mineTittel,
2078
- onPress: visMine
2148
+ onPress: () => void visMine()
2079
2149
  }
2080
2150
  ) : null
2081
2151
  ] }) : null,
@@ -2139,7 +2209,7 @@ function Widget({
2139
2209
  ...kvittering.nr ? { saksnummer: kvittering.nr } : {},
2140
2210
  ...kvittering.vedlegg ? { vedlegg: kvittering.vedlegg } : {},
2141
2211
  ...kvittering.frist ? { frist: kvittering.frist } : {},
2142
- onLukk: lukk
2212
+ onLukk: lukkOgNullstill
2143
2213
  }
2144
2214
  ) : null,
2145
2215
  steg === "mine" ? /* @__PURE__ */ jsx9(
@@ -2148,7 +2218,7 @@ function Widget({
2148
2218
  rader: mine,
2149
2219
  laster: lasterMine,
2150
2220
  ...tenantName ? { tenantName } : {},
2151
- onNytt: nullstill
2221
+ onNytt: nyttFraMine
2152
2222
  }
2153
2223
  ) : null
2154
2224
  ]
@@ -2191,9 +2261,9 @@ function InnspelProvider({
2191
2261
  }) {
2192
2262
  const [synlig, setSynlig] = useState4(false);
2193
2263
  const [apneOpsjoner, setApneOpsjoner] = useState4();
2194
- const registrert = useRef3(false);
2195
- const rootRef = useRef3(null);
2196
- const privat = useMemo3(createPrivateRegistry, []);
2264
+ const registrert = useRef4(false);
2265
+ const rootRef = useRef4(null);
2266
+ const privat = useMemo4(createPrivateRegistry, []);
2197
2267
  const open = useCallback3(
2198
2268
  async (options) => {
2199
2269
  setApneOpsjoner(options);
@@ -2206,9 +2276,9 @@ function InnspelProvider({
2206
2276
  client.registerPresenter({ open });
2207
2277
  registrert.current = true;
2208
2278
  }
2209
- const tema = useMemo3(() => byggTema(theme, colorScheme), [theme, colorScheme]);
2210
- const verdi = useMemo3(() => ({ client, open, close }), [client, open, close]);
2211
- const skjermbilde = useMemo3(
2279
+ const tema = useMemo4(() => byggTema(theme, colorScheme), [theme, colorScheme]);
2280
+ const verdi = useMemo4(() => ({ client, open, close }), [client, open, close]);
2281
+ const skjermbilde = useMemo4(
2212
2282
  () => ({ adapter: screenshot ?? null, rootRef, privat }),
2213
2283
  [screenshot, privat]
2214
2284
  );
@@ -2238,11 +2308,11 @@ function useInnspel() {
2238
2308
  }
2239
2309
 
2240
2310
  // src/InnspelPrivate.tsx
2241
- import { useEffect as useEffect2, useRef as useRef4 } from "react";
2311
+ import { useEffect as useEffect2, useRef as useRef5 } from "react";
2242
2312
  import { View as View10 } from "react-native";
2243
2313
  import { jsx as jsx11 } from "react/jsx-runtime";
2244
2314
  function InnspelPrivate({ children, style }) {
2245
- const ref = useRef4(null);
2315
+ const ref = useRef5(null);
2246
2316
  const kontekst = useSkjermbilde();
2247
2317
  const registrer = kontekst?.privat.register;
2248
2318
  useEffect2(() => {