utopia-ui 3.0.62 → 3.0.64

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.esm.js CHANGED
@@ -1168,183 +1168,6 @@ function FilterControl() {
1168
1168
  }, children: jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', fill: 'none', viewBox: '0 0 24 24', strokeWidth: 2.3, stroke: 'currentColor', className: 'size-6', children: jsx("path", { strokeLinecap: 'round', strokeLinejoin: 'round', d: 'M12 3c2.755 0 5.455.232 8.083.678.533.09.917.556.917 1.096v1.044a2.25 2.25 0 0 1-.659 1.591l-5.432 5.432a2.25 2.25 0 0 0-.659 1.591v2.927a2.25 2.25 0 0 1-1.244 2.013L9.75 21v-6.568a2.25 2.25 0 0 0-.659-1.591L3.659 7.409A2.25 2.25 0 0 1 3 5.818V4.774c0-.54.384-1.006.917-1.096A48.32 48.32 0 0 1 12 3Z' }) }) })] })) }));
1169
1169
  }
1170
1170
 
1171
- /**
1172
- * @category Templates
1173
- */
1174
- function MapOverlayPage({ children, className, backdrop, card = true, }) {
1175
- const closeScreen = () => {
1176
- navigate(`/${window.location.search ? window.location.search : ''}`);
1177
- };
1178
- const navigate = useNavigate();
1179
- const overlayRef = createRef();
1180
- const backdropRef = createRef();
1181
- useEffect(() => {
1182
- if (overlayRef.current !== null) {
1183
- DomEvent.disableClickPropagation(overlayRef.current);
1184
- DomEvent.disableScrollPropagation(overlayRef.current);
1185
- }
1186
- if (backdropRef.current !== null && backdrop) {
1187
- DomEvent.disableClickPropagation(backdropRef.current);
1188
- DomEvent.disableScrollPropagation(backdropRef.current);
1189
- }
1190
- // eslint-disable-next-line react-hooks/exhaustive-deps
1191
- }, [overlayRef, backdropRef]);
1192
- return (jsx("div", { className: `tw-absolute tw-h-full tw-w-full tw-m-auto ${backdrop && 'tw-z-[2000]'}`, children: jsx("div", { ref: backdropRef, className: `${backdrop && 'tw-backdrop-brightness-75'} tw-h-full tw-w-full tw-grid tw-place-items-center tw-m-auto`, children: jsxs("div", { ref: overlayRef, className: `${card && 'tw-card tw-card-body'} tw-shadow-xl tw-bg-base-100 tw-p-6 ${className && className} ${!backdrop && 'tw-z-[2000]'} tw-absolute tw-top-0 tw-bottom-0 tw-right-0 tw-left-0 tw-m-auto`, children: [children, jsx("button", { className: 'tw-btn tw-btn-sm tw-btn-circle tw-btn-ghost tw-absolute tw-right-2 tw-top-2', onClick: () => closeScreen(), children: "\u2715" })] }) }) }));
1193
- }
1194
-
1195
- /**
1196
- * @category Auth
1197
- */
1198
- function LoginPage() {
1199
- const [email, setEmail] = useState('');
1200
- const [password, setPassword] = useState('');
1201
- const { login, loading } = useAuth();
1202
- const navigate = useNavigate();
1203
- // eslint-disable-next-line react-hooks/exhaustive-deps
1204
- const onLogin = async () => {
1205
- await toast.promise(login({ email, password }), {
1206
- success: {
1207
- render({ data }) {
1208
- navigate('/');
1209
- return `Hi ${data?.first_name}`;
1210
- },
1211
- // other options
1212
- icon: '✌️',
1213
- },
1214
- error: {
1215
- render({ data }) {
1216
- return `${data}`;
1217
- },
1218
- autoClose: 10000,
1219
- },
1220
- pending: 'logging in ...',
1221
- });
1222
- };
1223
- useEffect(() => {
1224
- const keyDownHandler = (event) => {
1225
- if (event.key === 'Enter') {
1226
- event.preventDefault();
1227
- onLogin();
1228
- }
1229
- };
1230
- document.addEventListener('keydown', keyDownHandler);
1231
- return () => {
1232
- document.removeEventListener('keydown', keyDownHandler);
1233
- };
1234
- }, [onLogin]);
1235
- return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Login" }), jsx("input", { type: 'email', placeholder: 'E-Mail', value: email, onChange: (e) => setEmail(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("input", { type: 'password', placeholder: 'Password', onChange: (e) => setPassword(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-text-right tw-text-primary', children: jsx(Link, { to: '/reset-password', children: jsx("span", { className: 'tw-text-sm tw-inline-block hover:tw-text-primary hover:tw-underline hover:tw-cursor-pointer tw-transition tw-duration-200', children: "Forgot Password?" }) }) }), jsx("div", { className: 'tw-card-actions', children: jsx("button", { className: loading
1236
- ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
1237
- : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onLogin(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Login' }) })] }));
1238
- }
1239
-
1240
- /**
1241
- * @category Auth
1242
- */
1243
- function SignupPage() {
1244
- const [email, setEmail] = useState('');
1245
- const [userName, setUserName] = useState('');
1246
- const [password, setPassword] = useState('');
1247
- const { register, loading } = useAuth();
1248
- const navigate = useNavigate();
1249
- // eslint-disable-next-line react-hooks/exhaustive-deps
1250
- const onRegister = async () => {
1251
- await toast.promise(register({ email, password }, userName), {
1252
- success: {
1253
- render({ data }) {
1254
- navigate('/');
1255
- return `Hi ${data?.first_name}`;
1256
- },
1257
- // other options
1258
- icon: '✌️',
1259
- },
1260
- error: {
1261
- render({ data }) {
1262
- return `${data}`;
1263
- },
1264
- autoClose: 10000,
1265
- },
1266
- pending: 'creating new user ...',
1267
- });
1268
- };
1269
- useEffect(() => {
1270
- const keyDownHandler = (event) => {
1271
- if (event.key === 'Enter') {
1272
- event.preventDefault();
1273
- onRegister();
1274
- }
1275
- };
1276
- document.addEventListener('keydown', keyDownHandler);
1277
- return () => {
1278
- document.removeEventListener('keydown', keyDownHandler);
1279
- };
1280
- }, [onRegister]);
1281
- return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Sign Up" }), jsx("input", { type: 'text', placeholder: 'Name', value: userName, onChange: (e) => setUserName(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("input", { type: 'email', placeholder: 'E-Mail', value: email, onChange: (e) => setEmail(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("input", { type: 'password', placeholder: 'Password', onChange: (e) => setPassword(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-card-actions tw-mt-4', children: jsx("button", { className: loading
1282
- ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
1283
- : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onRegister(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Sign Up' }) })] }));
1284
- }
1285
-
1286
- /**
1287
- * @category Auth
1288
- */
1289
- // eslint-disable-next-line react/prop-types
1290
- function RequestPasswordPage({ resetUrl }) {
1291
- const [email, setEmail] = useState('');
1292
- const { requestPasswordReset, loading } = useAuth();
1293
- const navigate = useNavigate();
1294
- const onReset = async () => {
1295
- await toast.promise(requestPasswordReset(email, resetUrl), {
1296
- success: {
1297
- render() {
1298
- navigate('/');
1299
- return 'Check your mailbox';
1300
- },
1301
- // other options
1302
- icon: '📬',
1303
- },
1304
- error: {
1305
- render({ data }) {
1306
- return `${data}`;
1307
- },
1308
- },
1309
- pending: 'sending email ...',
1310
- });
1311
- };
1312
- return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Reset Password" }), jsx("input", { type: 'email', placeholder: 'E-Mail', value: email, onChange: (e) => setEmail(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-card-actions tw-mt-4', children: jsx("button", { className: loading
1313
- ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
1314
- : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onReset(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Send' }) })] }));
1315
- }
1316
-
1317
- /**
1318
- * @category Auth
1319
- */
1320
- function SetNewPasswordPage() {
1321
- const [password, setPassword] = useState('');
1322
- const { passwordReset, loading } = useAuth();
1323
- const navigate = useNavigate();
1324
- const onReset = async () => {
1325
- const token = window.location.search.split('token=')[1];
1326
- // eslint-disable-next-line no-console
1327
- console.log(token);
1328
- await toast.promise(passwordReset(token, password), {
1329
- success: {
1330
- render() {
1331
- navigate('/');
1332
- return 'New password set';
1333
- },
1334
- },
1335
- error: {
1336
- render({ data }) {
1337
- return `${data}`;
1338
- },
1339
- },
1340
- pending: 'setting password ...',
1341
- });
1342
- };
1343
- return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Set new Password" }), jsx("input", { type: 'password', placeholder: 'Password', onChange: (e) => setPassword(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-card-actions tw-mt-4', children: jsx("button", { className: loading
1344
- ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
1345
- : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onReset(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Set' }) })] }));
1346
- }
1347
-
1348
1171
  const GratitudeControl = () => {
1349
1172
  const navigate = useNavigate();
1350
1173
  const { isAuthenticated } = useAuth();
@@ -3070,14 +2893,14 @@ function ItemFormPopup(props) {
3070
2893
  map.closePopup();
3071
2894
  }
3072
2895
  else {
3073
- const item = items.find((i) => i.user_created?.id === user?.id && i.layer?.itemType.name === props.layer.itemType.name);
2896
+ const item = items.find((i) => i.user_created?.id === user?.id && i.layer?.id === props.layer.id);
3074
2897
  const uuid = crypto.randomUUID();
3075
2898
  let success = false;
3076
2899
  try {
3077
- props.layer.onlyOnePerOwner &&
2900
+ props.layer.userProfileLayer &&
3078
2901
  item &&
3079
2902
  (await props.layer.api?.updateItem({ ...formItem, id: item.id }));
3080
- (!props.layer.onlyOnePerOwner || !item) &&
2903
+ (!props.layer.userProfileLayer || !item) &&
3081
2904
  (await props.layer.api?.createItem({
3082
2905
  ...formItem,
3083
2906
  id: uuid,
@@ -3090,14 +2913,13 @@ function ItemFormPopup(props) {
3090
2913
  toast.error(error.toString());
3091
2914
  }
3092
2915
  if (success) {
3093
- if (props.layer.onlyOnePerOwner && item)
2916
+ if (props.layer.userProfileLayer && item)
3094
2917
  updateItem({ ...item, ...formItem });
3095
- if (!props.layer.onlyOnePerOwner || !item) {
2918
+ if (!props.layer.userProfileLayer || !item) {
3096
2919
  addItem({
3097
2920
  ...formItem,
3098
2921
  name: (formItem.name ? formItem.name : user?.first_name) ?? '',
3099
2922
  user_created: user ?? undefined,
3100
- type: props.layer.itemType,
3101
2923
  id: uuid,
3102
2924
  layer: props.layer,
3103
2925
  public_edit: !user,
@@ -3254,9 +3076,9 @@ const ItemViewPopup = forwardRef((props, ref) => {
3254
3076
  setLoading(true);
3255
3077
  let success = false;
3256
3078
  try {
3257
- !props.item.layer?.onlyOnePerOwner &&
3079
+ !props.item.layer?.userProfileLayer &&
3258
3080
  (await props.item.layer?.api?.deleteItem(props.item.id));
3259
- props.item.layer?.onlyOnePerOwner &&
3081
+ props.item.layer?.userProfileLayer &&
3260
3082
  (await props.item.layer.api?.updateItem({ id: props.item.id, position: null }));
3261
3083
  success = true;
3262
3084
  // eslint-disable-next-line no-catch-all/no-catch-all
@@ -3266,8 +3088,8 @@ const ItemViewPopup = forwardRef((props, ref) => {
3266
3088
  toast.error(error.toString());
3267
3089
  }
3268
3090
  if (success) {
3269
- !props.item.layer?.onlyOnePerOwner && removeItem(props.item);
3270
- props.item.layer?.onlyOnePerOwner && updadateItem({ ...props.item, position: undefined });
3091
+ !props.item.layer?.userProfileLayer && removeItem(props.item);
3092
+ props.item.layer?.userProfileLayer && updadateItem({ ...props.item, position: undefined });
3271
3093
  toast.success('Item deleted');
3272
3094
  }
3273
3095
  setLoading(false);
@@ -3288,7 +3110,7 @@ const ItemViewPopup = forwardRef((props, ref) => {
3288
3110
  /**
3289
3111
  * @category Map
3290
3112
  */
3291
- const Layer = ({ data, children, name = 'places', menuIcon = 'MapPinIcon', menuText = 'add new place', menuColor = '#2E7D32', markerIcon = 'point', markerShape = 'circle', markerDefaultColor = '#777', markerDefaultColor2 = 'RGBA(35, 31, 32, 0.2)', api, itemType, onlyOnePerOwner = false, customEditLink, customEditParameter,
3113
+ const Layer = ({ data, children, name = 'places', menuIcon = 'MapPinIcon', menuText = 'add new place', menuColor = '#2E7D32', markerIcon = 'point', markerShape = 'circle', markerDefaultColor = '#777', markerDefaultColor2 = 'RGBA(35, 31, 32, 0.2)', api, itemType, userProfileLayer = false, customEditLink, customEditParameter,
3292
3114
  // eslint-disable-next-line camelcase
3293
3115
  public_edit_items, listed = true, setItemFormPopup, itemFormPopup, clusterRef, }) => {
3294
3116
  const filterTags = useFilterTags();
@@ -3325,7 +3147,7 @@ public_edit_items, listed = true, setItemFormPopup, itemFormPopup, clusterRef, }
3325
3147
  markerDefaultColor2,
3326
3148
  api,
3327
3149
  itemType,
3328
- onlyOnePerOwner,
3150
+ userProfileLayer,
3329
3151
  // Can we just use editCallback for all cases?
3330
3152
  customEditLink,
3331
3153
  customEditParameter,
@@ -3351,7 +3173,7 @@ public_edit_items, listed = true, setItemFormPopup, itemFormPopup, clusterRef, }
3351
3173
  markerDefaultColor2,
3352
3174
  api,
3353
3175
  itemType,
3354
- onlyOnePerOwner,
3176
+ userProfileLayer,
3355
3177
  customEditLink,
3356
3178
  customEditParameter,
3357
3179
  // eslint-disable-next-line camelcase
@@ -3587,17 +3409,15 @@ const StartEndView = ({ item }) => {
3587
3409
  return (jsxs("div", { className: 'tw-flex tw-flex-row tw-mb-4 tw-mt-1', children: [jsxs("div", { className: 'tw-basis-2/5 tw-flex tw-flex-row', children: [jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', className: 'tw-h-4 tw-w-4 tw-mr-2', fill: 'none', viewBox: '0 0 24 24', stroke: 'currentColor', strokeWidth: 2, children: jsx("path", { strokeLinecap: 'round', strokeLinejoin: 'round', d: 'M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z' }) }), jsx("time", { className: 'tw-align-middle', dateTime: item && item.start ? item.start.substring(0, 10) : '', children: item && item.start ? new Date(item.start).toLocaleDateString() : '' })] }), jsx("div", { className: 'tw-basis-1/5 tw-place-content-center', children: jsx("span", { children: "-" }) }), jsxs("div", { className: 'tw-basis-2/5 tw-flex tw-flex-row', children: [jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', className: 'tw-h-4 tw-w-4 tw-mr-2', fill: 'none', viewBox: '0 0 24 24', stroke: 'currentColor', strokeWidth: 2, children: jsx("path", { strokeLinecap: 'round', strokeLinejoin: 'round', d: 'M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z' }) }), jsx("time", { className: 'tw-align-middle', dateTime: item && item.end ? item.end.substring(0, 10) : '', children: item && item.end ? new Date(item.end).toLocaleDateString() : '' })] })] }));
3588
3410
  };
3589
3411
 
3590
- function NavBar({ appName, userType }) {
3412
+ function NavBar({ appName }) {
3591
3413
  const { isAuthenticated, user, logout } = useAuth();
3592
3414
  const [userProfile, setUserProfile] = useState({});
3593
3415
  const items = useItems();
3594
3416
  useEffect(() => {
3595
- const profile = user &&
3596
- items.find((i) => i.user_created?.id === user.id && i.layer?.itemType.name === userType);
3417
+ const profile = user && items.find((i) => i.user_created?.id === user.id && i.layer?.userProfileLayer);
3597
3418
  profile
3598
3419
  ? setUserProfile(profile)
3599
3420
  : setUserProfile({ id: crypto.randomUUID(), name: user?.first_name ?? '', text: '' });
3600
- // eslint-disable-next-line react-hooks/exhaustive-deps
3601
3421
  }, [user, items]);
3602
3422
  // useEffect(() => {}, [userProfile])
3603
3423
  const nameRef = useRef(null);
@@ -3638,23 +3458,20 @@ function NavBar({ appName, userType }) {
3638
3458
  return jsx(Fragment, {});
3639
3459
  }
3640
3460
 
3641
- const SetAppState = ({ assetsApi, userType, }) => {
3461
+ const SetAppState = ({ assetsApi }) => {
3642
3462
  const setAppState = useSetAppState();
3643
3463
  useEffect(() => {
3644
3464
  setAppState({ assetsApi });
3645
3465
  // eslint-disable-next-line react-hooks/exhaustive-deps
3646
3466
  }, [assetsApi]);
3647
- useEffect(() => {
3648
- setAppState({ userType });
3649
- }, [setAppState, userType]);
3650
3467
  return jsx(Fragment, {});
3651
3468
  };
3652
3469
 
3653
3470
  /**
3654
3471
  * @category AppShell
3655
3472
  */
3656
- function AppShell({ appName, children, assetsApi, userType, }) {
3657
- return (jsx(ContextWrapper, { children: jsxs("div", { className: 'tw-flex tw-flex-col tw-h-full', children: [jsx(SetAppState, { assetsApi: assetsApi, userType: userType }), jsx(NavBar, { userType: userType, appName: appName }), jsx("div", { id: 'app-content', className: 'tw-flex-grow', children: children })] }) }));
3473
+ function AppShell({ appName, children, assetsApi, }) {
3474
+ return (jsx(ContextWrapper, { children: jsxs("div", { className: 'tw-flex tw-flex-col tw-h-full', children: [jsx(SetAppState, { assetsApi: assetsApi }), jsx(NavBar, { appName: appName }), jsx("div", { id: 'app-content', className: 'tw-flex-grow', children: children })] }) }));
3658
3475
  }
3659
3476
 
3660
3477
  function SidebarSubmenu({ submenu, name, icon, }) {
@@ -3752,6 +3569,183 @@ const Sitemap = ({ url }) => {
3752
3569
  return (jsxs("div", { children: [jsx("h1", { children: "Sitemap" }), jsx("textarea", { value: sitemap, readOnly: true, rows: items.length + 4, cols: 80 })] }));
3753
3570
  };
3754
3571
 
3572
+ /**
3573
+ * @category Templates
3574
+ */
3575
+ function MapOverlayPage({ children, className, backdrop, card = true, }) {
3576
+ const closeScreen = () => {
3577
+ navigate(`/${window.location.search ? window.location.search : ''}`);
3578
+ };
3579
+ const navigate = useNavigate();
3580
+ const overlayRef = createRef();
3581
+ const backdropRef = createRef();
3582
+ useEffect(() => {
3583
+ if (overlayRef.current !== null) {
3584
+ DomEvent.disableClickPropagation(overlayRef.current);
3585
+ DomEvent.disableScrollPropagation(overlayRef.current);
3586
+ }
3587
+ if (backdropRef.current !== null && backdrop) {
3588
+ DomEvent.disableClickPropagation(backdropRef.current);
3589
+ DomEvent.disableScrollPropagation(backdropRef.current);
3590
+ }
3591
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3592
+ }, [overlayRef, backdropRef]);
3593
+ return (jsx("div", { className: `tw-absolute tw-h-full tw-w-full tw-m-auto ${backdrop && 'tw-z-[2000]'}`, children: jsx("div", { ref: backdropRef, className: `${backdrop && 'tw-backdrop-brightness-75'} tw-h-full tw-w-full tw-grid tw-place-items-center tw-m-auto`, children: jsxs("div", { ref: overlayRef, className: `${card && 'tw-card tw-card-body'} tw-shadow-xl tw-bg-base-100 tw-p-6 ${className && className} ${!backdrop && 'tw-z-[2000]'} tw-absolute tw-top-0 tw-bottom-0 tw-right-0 tw-left-0 tw-m-auto`, children: [children, jsx("button", { className: 'tw-btn tw-btn-sm tw-btn-circle tw-btn-ghost tw-absolute tw-right-2 tw-top-2', onClick: () => closeScreen(), children: "\u2715" })] }) }) }));
3594
+ }
3595
+
3596
+ /**
3597
+ * @category Auth
3598
+ */
3599
+ function LoginPage() {
3600
+ const [email, setEmail] = useState('');
3601
+ const [password, setPassword] = useState('');
3602
+ const { login, loading } = useAuth();
3603
+ const navigate = useNavigate();
3604
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3605
+ const onLogin = async () => {
3606
+ await toast.promise(login({ email, password }), {
3607
+ success: {
3608
+ render({ data }) {
3609
+ navigate('/');
3610
+ return `Hi ${data?.first_name}`;
3611
+ },
3612
+ // other options
3613
+ icon: '✌️',
3614
+ },
3615
+ error: {
3616
+ render({ data }) {
3617
+ return `${data}`;
3618
+ },
3619
+ autoClose: 10000,
3620
+ },
3621
+ pending: 'logging in ...',
3622
+ });
3623
+ };
3624
+ useEffect(() => {
3625
+ const keyDownHandler = (event) => {
3626
+ if (event.key === 'Enter') {
3627
+ event.preventDefault();
3628
+ onLogin();
3629
+ }
3630
+ };
3631
+ document.addEventListener('keydown', keyDownHandler);
3632
+ return () => {
3633
+ document.removeEventListener('keydown', keyDownHandler);
3634
+ };
3635
+ }, [onLogin]);
3636
+ return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Login" }), jsx("input", { type: 'email', placeholder: 'E-Mail', value: email, onChange: (e) => setEmail(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("input", { type: 'password', placeholder: 'Password', onChange: (e) => setPassword(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-text-right tw-text-primary', children: jsx(Link, { to: '/reset-password', children: jsx("span", { className: 'tw-text-sm tw-inline-block hover:tw-text-primary hover:tw-underline hover:tw-cursor-pointer tw-transition tw-duration-200', children: "Forgot Password?" }) }) }), jsx("div", { className: 'tw-card-actions', children: jsx("button", { className: loading
3637
+ ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
3638
+ : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onLogin(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Login' }) })] }));
3639
+ }
3640
+
3641
+ /**
3642
+ * @category Auth
3643
+ */
3644
+ function SignupPage() {
3645
+ const [email, setEmail] = useState('');
3646
+ const [userName, setUserName] = useState('');
3647
+ const [password, setPassword] = useState('');
3648
+ const { register, loading } = useAuth();
3649
+ const navigate = useNavigate();
3650
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3651
+ const onRegister = async () => {
3652
+ await toast.promise(register({ email, password }, userName), {
3653
+ success: {
3654
+ render({ data }) {
3655
+ navigate('/');
3656
+ return `Hi ${data?.first_name}`;
3657
+ },
3658
+ // other options
3659
+ icon: '✌️',
3660
+ },
3661
+ error: {
3662
+ render({ data }) {
3663
+ return `${data}`;
3664
+ },
3665
+ autoClose: 10000,
3666
+ },
3667
+ pending: 'creating new user ...',
3668
+ });
3669
+ };
3670
+ useEffect(() => {
3671
+ const keyDownHandler = (event) => {
3672
+ if (event.key === 'Enter') {
3673
+ event.preventDefault();
3674
+ onRegister();
3675
+ }
3676
+ };
3677
+ document.addEventListener('keydown', keyDownHandler);
3678
+ return () => {
3679
+ document.removeEventListener('keydown', keyDownHandler);
3680
+ };
3681
+ }, [onRegister]);
3682
+ return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Sign Up" }), jsx("input", { type: 'text', placeholder: 'Name', value: userName, onChange: (e) => setUserName(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("input", { type: 'email', placeholder: 'E-Mail', value: email, onChange: (e) => setEmail(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("input", { type: 'password', placeholder: 'Password', onChange: (e) => setPassword(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-card-actions tw-mt-4', children: jsx("button", { className: loading
3683
+ ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
3684
+ : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onRegister(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Sign Up' }) })] }));
3685
+ }
3686
+
3687
+ /**
3688
+ * @category Auth
3689
+ */
3690
+ // eslint-disable-next-line react/prop-types
3691
+ function RequestPasswordPage({ resetUrl }) {
3692
+ const [email, setEmail] = useState('');
3693
+ const { requestPasswordReset, loading } = useAuth();
3694
+ const navigate = useNavigate();
3695
+ const onReset = async () => {
3696
+ await toast.promise(requestPasswordReset(email, resetUrl), {
3697
+ success: {
3698
+ render() {
3699
+ navigate('/');
3700
+ return 'Check your mailbox';
3701
+ },
3702
+ // other options
3703
+ icon: '📬',
3704
+ },
3705
+ error: {
3706
+ render({ data }) {
3707
+ return `${data}`;
3708
+ },
3709
+ },
3710
+ pending: 'sending email ...',
3711
+ });
3712
+ };
3713
+ return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Reset Password" }), jsx("input", { type: 'email', placeholder: 'E-Mail', value: email, onChange: (e) => setEmail(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-card-actions tw-mt-4', children: jsx("button", { className: loading
3714
+ ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
3715
+ : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onReset(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Send' }) })] }));
3716
+ }
3717
+
3718
+ /**
3719
+ * @category Auth
3720
+ */
3721
+ function SetNewPasswordPage() {
3722
+ const [password, setPassword] = useState('');
3723
+ const { passwordReset, loading } = useAuth();
3724
+ const navigate = useNavigate();
3725
+ const onReset = async () => {
3726
+ const token = window.location.search.split('token=')[1];
3727
+ // eslint-disable-next-line no-console
3728
+ console.log(token);
3729
+ await toast.promise(passwordReset(token, password), {
3730
+ success: {
3731
+ render() {
3732
+ navigate('/');
3733
+ return 'New password set';
3734
+ },
3735
+ },
3736
+ error: {
3737
+ render({ data }) {
3738
+ return `${data}`;
3739
+ },
3740
+ },
3741
+ pending: 'setting password ...',
3742
+ });
3743
+ };
3744
+ return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-max-w-xs tw-h-fit', children: [jsx("h2", { className: 'tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center', children: "Set new Password" }), jsx("input", { type: 'password', placeholder: 'Password', onChange: (e) => setPassword(e.target.value), className: 'tw-input tw-input-bordered tw-w-full tw-max-w-xs' }), jsx("div", { className: 'tw-card-actions tw-mt-4', children: jsx("button", { className: loading
3745
+ ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary'
3746
+ : 'tw-btn tw-btn-primary tw-btn-block', onClick: () => onReset(), children: loading ? jsx("span", { className: 'tw-loading tw-loading-spinner' }) : 'Set' }) })] }));
3747
+ }
3748
+
3755
3749
  function Subtitle({ styleClass, children }) {
3756
3750
  return jsx("div", { className: `tw-text-xl tw-font-semibold ${styleClass}`, children: children });
3757
3751
  }
@@ -3852,7 +3846,7 @@ const MoonCalendar = () => {
3852
3846
  const SelectUser = () => {
3853
3847
  const appState = useAppState();
3854
3848
  const items = useItems();
3855
- const users = items.filter((i) => i.layer?.itemType.name === appState.userType);
3849
+ const users = items.filter((i) => i.layer?.userProfileLayer);
3856
3850
  const [selectedUsers, setSelectedUsers] = useState([]);
3857
3851
  return (jsxs(MapOverlayPage, { backdrop: true, className: 'tw-h-3/4 tw-w-80', children: [jsx("div", { className: 'tw-text-center tw-text-xl tw-font-bold tw-mb-4', children: "Gratitude to ..." }), jsx("div", { className: 'tw-overflow-x-auto tw-w-full fade', children: jsx("table", { className: 'tw-table tw-w-full', children: jsx("tbody", { children: users.map((u, k) => {
3858
3852
  return (jsxs("tr", { children: [jsx("td", { children: jsx("input", { type: 'checkbox', onChange: () => setSelectedUsers((prev) => [...prev, u.id]), className: 'tw-checkbox tw-checkbox-sm' }) }), jsx("td", { children: jsxs("div", { className: 'tw-flex tw-items-center tw-space-x-3', children: [u.image ? (jsx("div", { className: 'tw-avatar', children: jsx("div", { className: 'tw-mask tw-mask-circle tw-w-8 tw-h-8', children: jsx("img", { src: appState.assetsApi.url + u.image + '?width=40&heigth=40', alt: 'Avatar' }) }) })) : (jsx("div", { className: 'tw-mask tw-mask-circle tw-text-xl md:tw-text-2xl tw-bg-slate-200 tw-rounded-full tw-w-8 tw-h-8' })), jsx("div", { children: jsx("div", { className: 'tw-font-bold', children: u.name }) })] }) })] }, k));
@@ -4116,7 +4110,7 @@ const AttestationForm = ({ api }) => {
4116
4110
  items.find((i) =>
4117
4111
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4118
4112
  i.user_created?.id === to[0].directus_users_id &&
4119
- i.layer?.itemType.name === 'player')?.id +
4113
+ i.layer?.userProfileLayer === true)?.id +
4120
4114
  '?tab=2'));
4121
4115
  };
4122
4116
  const [selectedEmoji, setSelectedEmoji] = useState('select badge');
@@ -4391,7 +4385,6 @@ const onUpdateItem = async (state, item, tags, addTag, setLoading, navigate, upd
4391
4385
  ...changedItem,
4392
4386
  layer: item.layer,
4393
4387
  user_created: user,
4394
- type: item.layer?.itemType,
4395
4388
  }))
4396
4389
  .then(() => {
4397
4390
  setLoading(false);
@@ -4406,12 +4399,7 @@ const ContactInfoView = ({ item, heading }) => {
4406
4399
  const [profileOwner, setProfileOwner] = useState();
4407
4400
  const items = useItems();
4408
4401
  useEffect(() => {
4409
- // eslint-disable-next-line no-console
4410
- console.log('user:', items.find((i) => i.user_created?.id === item.user_created?.id &&
4411
- i.layer?.itemType.name === appState.userType));
4412
- setProfileOwner(items.find((i) => i.user_created?.id === item.user_created?.id &&
4413
- i.layer?.itemType.name === appState.userType));
4414
- // eslint-disable-next-line react-hooks/exhaustive-deps
4402
+ setProfileOwner(items.find((i) => i.user_created?.id === item.user_created?.id && i.layer?.userProfileLayer));
4415
4403
  }, [item, items]);
4416
4404
  return (jsxs("div", { className: 'tw-bg-base-200 tw-mb-6 tw-mt-6 tw-p-6', children: [jsx("h2", { className: 'tw-text-lg tw-font-semibold', children: heading }), jsxs("div", { className: 'tw-mt-4 tw-flex tw-items-center', children: [profileOwner?.image && (jsx(ConditionalLink, { url: '/item/' + profileOwner?.id, children: jsx("div", { className: 'tw-mr-5 tw-flex tw-items-center tw-justify-center', children: jsx("div", { className: 'tw-avatar', children: jsx("div", { className: 'tw-w-20 tw-h-20 tw-bg-gray-200 rounded-full tw-flex tw-items-center tw-justify-center overflow-hidden', children: jsx("img", { src: appState.assetsApi.url + profileOwner?.image, alt: profileOwner?.name, className: 'tw-w-full tw-h-full tw-object-cover' }) }) }) }) })), jsxs("div", { className: 'tw-text-sm tw-flex-grow', children: [jsx("p", { className: 'tw-font-semibold', children: profileOwner?.name }), item.contact && (jsx("p", { children: jsxs("a", { href: `mailto:${item.contact}`, className: 'tw-mt-2 tw-text-green-500 tw-inline-flex tw-items-center', children: [jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', className: 'tw-w-4 tw-h-4 tw-mr-1', children: [jsx("path", { d: 'M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z' }), jsx("polyline", { points: '22,6 12,13 2,6' })] }), item.contact] }) })), item.telephone && (jsx("p", { children: jsxs("a", { href: `tel:${item.telephone}`, className: 'tw-mt-2 tw-text-green-500 tw-inline-flex tw-items-center tw-whitespace-nowrap', children: [jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', className: 'tw-w-4 tw-h-4 tw-mr-1', children: jsx("path", { d: 'M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07 19.5 19.5 0 01-6-6 19.79 19.79 0 01-3.07-8.67A2 2 0 014.11 2h3a2 2 0 012 1.72 12.84 12.84 0 00.7 2.81 2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7A2 2 0 0122 16.92z' }) }), item.telephone] }) }))] })] })] }));
4417
4405
  };
@@ -4545,7 +4533,8 @@ const get = (value, path, defaultValue) => {
4545
4533
  const ProfileTextView = ({ item, dataField = 'text', heading, hideWhenEmpty, }) => {
4546
4534
  const text = get(item, dataField);
4547
4535
  if (typeof text !== 'string') {
4548
- throw new Error('ProfileTextView: text is not a string');
4536
+ // eslint-disable-next-line no-console
4537
+ console.log('123');
4549
4538
  }
4550
4539
  return (jsxs("div", { className: 'tw-my-10 tw-mt-2 tw-px-6', children: [!(text === '' && hideWhenEmpty) && (jsx("h2", { className: 'tw-text-lg tw-font-semibold', children: heading })), jsx("div", { className: 'tw-mt-2 tw-text-sm', children: jsx(TextView, { itemId: item.id, rawText: text }) })] }));
4551
4540
  };
@@ -5299,14 +5288,20 @@ function ProfileForm() {
5299
5288
  const item = items.find((i) => i.id === itemId);
5300
5289
  item && setItem(item);
5301
5290
  if (!item) {
5302
- const layer = layers.find((l) => l.itemType.name === appState.userType);
5303
- setItem({
5304
- id: crypto.randomUUID(),
5305
- name: user?.first_name ?? '',
5306
- text: '',
5307
- layer,
5308
- new: true,
5309
- });
5291
+ if (items.some((i) => i.user_created?.id === user?.id && i.layer?.userProfileLayer)) {
5292
+ navigate('/');
5293
+ toast.error('Item does not exist');
5294
+ }
5295
+ else {
5296
+ const layer = layers.find((l) => l.userProfileLayer);
5297
+ setItem({
5298
+ id: crypto.randomUUID(),
5299
+ name: user?.first_name ?? '',
5300
+ text: '',
5301
+ layer,
5302
+ new: true,
5303
+ });
5304
+ }
5310
5305
  }
5311
5306
  // eslint-disable-next-line react-hooks/exhaustive-deps
5312
5307
  }, [items]);
@@ -5397,11 +5392,11 @@ function Quests() {
5397
5392
  const items = useItems();
5398
5393
  useEffect(() => {
5399
5394
  setProfie(items.find((i) => i.user_created?.id === user?.id &&
5400
- i.layer?.itemType.name === 'user' &&
5395
+ i.layer?.userProfileLayer &&
5401
5396
  i.user_created?.id != null));
5402
5397
  }, [items, user]);
5403
5398
  return (jsx(Fragment, { children: questsOpen ? (jsx("div", { className: 'tw-card tw-w-48 tw-bg-base-100 tw-shadow-xl tw-absolute tw-bottom-4 tw-left-4 tw-z-[2000]', children: jsxs("div", { className: 'tw-card-body tw-p-4 tw-pt-0', children: [jsx("div", { className: 'tw-card-actions tw-justify-end', children: jsx("label", { className: 'tw-btn tw-btn-sm tw-btn-circle tw-btn-ghost tw-absolute tw-right-1 tw-top-1', onClick: () => setQuestsOpen(false), children: "\u2715" }) }), jsxs("h2", { className: 'tw-card-title tw-m-auto ', children: ["Level 1", jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', fill: 'none', viewBox: '0 0 24 24', strokeWidth: 1.5, stroke: '#aaa', className: 'tw-w-5 tw-h-5 tw-cursor-pointer', children: jsx("path", { strokeLinecap: 'round', strokeLinejoin: 'round', d: 'M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9 5.25h.008v.008H12v-.008z' }) })] }), jsxs("ul", { className: 'tw-flex-row', children: [jsx("li", { children: jsxs("label", { className: 'tw-label tw-justify-normal tw-pt-1 tw-pb-0', children: [jsx("input", { type: 'checkbox', readOnly: true, className: 'tw-checkbox tw-checkbox-xs tw-checkbox-success', checked: isAuthenticated || false }), jsx("span", { className: 'tw-text-sm tw-label-text tw-mx-2', children: "Sign Up" })] }) }), jsx("li", { children: jsxs("label", { className: 'tw-label tw-justify-normal tw-pt-1 tw-pb-0', children: [jsx("input", { type: 'checkbox', readOnly: true, className: 'tw-checkbox tw-checkbox-xs tw-checkbox-success', checked: !!profile?.text }), jsx("span", { className: 'tw-text-sm tw-label-text tw-mx-2', children: "Fill Profile" })] }) }), jsx("li", { children: jsxs("label", { className: 'tw-label tw-justify-normal tw-pt-1 tw-pb-0', children: [jsx("input", { type: 'checkbox', readOnly: true, className: 'tw-checkbox tw-checkbox-xs tw-checkbox-success', checked: !!profile?.image }), jsx("span", { className: 'tw-text-sm tw-label-text tw-mx-2', children: "Upload Avatar" })] }) })] }), ' '] }) })) : ('') }));
5404
5399
  }
5405
5400
 
5406
- export { AppShell, AttestationForm, AuthProvider, CardPage, Content, ItemForm, ItemView, Layer, LoginPage, MapOverlayPage, MarketView, Modal, MoonCalendar, OverlayItemsIndexPage, Permissions, PlusButton, PopupButton, PopupCheckboxInput, PopupStartEndInput, PopupTextAreaInput, PopupTextInput, ProfileForm, ProfileView, Quests, RequestPasswordPage, SelectBox, SelectUser, SetNewPasswordPage, SideBar, SignupPage, Sitemap, StartEndView, Tags, TextAreaInput, TextInput, TextView, TitleCard, UserSettings, UtopiaMap, useAuth };
5401
+ export { AppShell, AttestationForm, AuthProvider, CardPage, Content, ItemForm, ItemView, Layer, LoginPage, MapOverlayPage, MarketView, Modal, MoonCalendar, OverlayItemsIndexPage, Permissions, PopupButton, PopupCheckboxInput, PopupStartEndInput, PopupTextAreaInput, PopupTextInput, ProfileForm, ProfileView, Quests, RequestPasswordPage, SelectBox, SelectUser, SetNewPasswordPage, SideBar, SignupPage, Sitemap, StartEndView, Tags, TextAreaInput, TextInput, TextView, TitleCard, UserSettings, UtopiaMap };
5407
5402
  //# sourceMappingURL=index.esm.js.map