@oxy.so/services 14.11.0 → 14.13.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 (78) hide show
  1. package/ios/OxyIdentityModule.swift +49 -1
  2. package/lib/commonjs/assets/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  3. package/lib/commonjs/assets/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  4. package/lib/commonjs/assets/assets/fonts/icons/manifest.json +5 -4
  5. package/lib/commonjs/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  6. package/lib/commonjs/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  7. package/lib/commonjs/assets/fonts/icons/manifest.json +5 -4
  8. package/lib/commonjs/ui/icons/subsetGlyphMaps.js +1 -0
  9. package/lib/commonjs/ui/icons/subsetGlyphMaps.js.map +1 -1
  10. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +16 -63
  11. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
  12. package/lib/commonjs/ui/screens/ProfileLinkForm.js +125 -0
  13. package/lib/commonjs/ui/screens/ProfileLinkForm.js.map +1 -0
  14. package/lib/commonjs/ui/screens/ProfileLinksEditor.js +85 -0
  15. package/lib/commonjs/ui/screens/ProfileLinksEditor.js.map +1 -0
  16. package/lib/commonjs/ui/screens/linkFormat.js +22 -10
  17. package/lib/commonjs/ui/screens/linkFormat.js.map +1 -1
  18. package/lib/module/assets/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  19. package/lib/module/assets/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  20. package/lib/module/assets/assets/fonts/icons/manifest.json +5 -4
  21. package/lib/module/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  22. package/lib/module/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  23. package/lib/module/assets/fonts/icons/manifest.json +5 -4
  24. package/lib/module/ui/icons/subsetGlyphMaps.js +1 -0
  25. package/lib/module/ui/icons/subsetGlyphMaps.js.map +1 -1
  26. package/lib/module/ui/screens/EditProfileFieldScreen.js +17 -65
  27. package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
  28. package/lib/module/ui/screens/ProfileLinkForm.js +121 -0
  29. package/lib/module/ui/screens/ProfileLinkForm.js.map +1 -0
  30. package/lib/module/ui/screens/ProfileLinksEditor.js +81 -0
  31. package/lib/module/ui/screens/ProfileLinksEditor.js.map +1 -0
  32. package/lib/module/ui/screens/linkFormat.js +21 -9
  33. package/lib/module/ui/screens/linkFormat.js.map +1 -1
  34. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts +1 -1
  35. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/ui/icons/subsetGlyphMaps.d.ts +1 -0
  37. package/lib/typescript/commonjs/ui/icons/subsetGlyphMaps.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/ui/screens/ProfileLinkForm.d.ts +18 -0
  40. package/lib/typescript/commonjs/ui/screens/ProfileLinkForm.d.ts.map +1 -0
  41. package/lib/typescript/commonjs/ui/screens/ProfileLinksEditor.d.ts +14 -0
  42. package/lib/typescript/commonjs/ui/screens/ProfileLinksEditor.d.ts.map +1 -0
  43. package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts +14 -2
  44. package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/ui/utils/identityCrypto.d.ts +5 -0
  46. package/lib/typescript/commonjs/ui/utils/identityCrypto.d.ts.map +1 -1
  47. package/lib/typescript/module/ui/icons/Ionicons.d.ts +1 -1
  48. package/lib/typescript/module/ui/icons/Ionicons.d.ts.map +1 -1
  49. package/lib/typescript/module/ui/icons/subsetGlyphMaps.d.ts +1 -0
  50. package/lib/typescript/module/ui/icons/subsetGlyphMaps.d.ts.map +1 -1
  51. package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  52. package/lib/typescript/module/ui/screens/ProfileLinkForm.d.ts +18 -0
  53. package/lib/typescript/module/ui/screens/ProfileLinkForm.d.ts.map +1 -0
  54. package/lib/typescript/module/ui/screens/ProfileLinksEditor.d.ts +14 -0
  55. package/lib/typescript/module/ui/screens/ProfileLinksEditor.d.ts.map +1 -0
  56. package/lib/typescript/module/ui/screens/linkFormat.d.ts +14 -2
  57. package/lib/typescript/module/ui/screens/linkFormat.d.ts.map +1 -1
  58. package/lib/typescript/module/ui/utils/identityCrypto.d.ts +5 -0
  59. package/lib/typescript/module/ui/utils/identityCrypto.d.ts.map +1 -1
  60. package/package.json +7 -7
  61. package/src/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  62. package/src/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  63. package/src/assets/fonts/icons/manifest.json +5 -4
  64. package/src/ui/icons/subsetGlyphMaps.ts +1 -0
  65. package/src/ui/screens/EditProfileFieldScreen.tsx +19 -85
  66. package/src/ui/screens/ProfileLinkForm.tsx +131 -0
  67. package/src/ui/screens/ProfileLinksEditor.tsx +98 -0
  68. package/src/ui/screens/__tests__/linkFormat.test.ts +51 -8
  69. package/src/ui/screens/linkFormat.ts +28 -9
  70. package/lib/commonjs/ui/screens/LinkListEditor.js +0 -105
  71. package/lib/commonjs/ui/screens/LinkListEditor.js.map +0 -1
  72. package/lib/module/ui/screens/LinkListEditor.js +0 -99
  73. package/lib/module/ui/screens/LinkListEditor.js.map +0 -1
  74. package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts +0 -25
  75. package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts.map +0 -1
  76. package/lib/typescript/module/ui/screens/LinkListEditor.d.ts +0 -25
  77. package/lib/typescript/module/ui/screens/LinkListEditor.d.ts.map +0 -1
  78. package/src/ui/screens/LinkListEditor.tsx +0 -113
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/services",
3
- "version": "14.11.0",
3
+ "version": "14.13.0",
4
4
  "description": "OxyHQ Expo/React Native SDK — UI components, screens, and native features",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -176,14 +176,14 @@
176
176
  "delete-dts.js": "find ./lib/commonjs ./lib/module \\( -name '*.d.js*' -o -name '*.d.ts' \\) -delete"
177
177
  },
178
178
  "dependencies": {
179
- "@oxy.so/contracts": "^6.12.0",
179
+ "@oxy.so/contracts": "^6.13.0",
180
180
  "color": "^5.0.3",
181
181
  "@peable.to/sdk": "^4.0.0"
182
182
  },
183
183
  "devDependencies": {
184
184
  "@expo/app-integrity": "~58.0.2",
185
185
  "@expo/vector-icons": "^15.1.1",
186
- "@oxy.so/core": "7.34.0",
186
+ "@oxy.so/core": "7.36.0",
187
187
  "@react-native-async-storage/async-storage": "^3.1.1",
188
188
  "@react-native-community/netinfo": "^12.0.1",
189
189
  "@react-native/babel-preset": "^0.88.1",
@@ -196,7 +196,7 @@
196
196
  "@types/jest": "^30.0.0",
197
197
  "@types/node": "^26.6.6",
198
198
  "@types/react": "*",
199
- "@oxy.so/bloom": "17.8.1",
199
+ "@oxy.so/bloom": "17.15.0",
200
200
  "copyfiles": "^2.4.1",
201
201
  "expo-clipboard": "~58.0.4",
202
202
  "expo-constants": "~58.0.15",
@@ -229,14 +229,14 @@
229
229
  "zustand": "^5.0.16",
230
230
  "expo-video": "~58.0.13"
231
231
  },
232
- "//@oxy.so/bloom": "Bloom 11.1.0 adds the shared grouped sections, usage card, subscription plans, frame appearance and overlay navigation APIs used by this SDK. First-party Bloom peers remain open above this tested minimum.",
232
+ "//@oxy.so/bloom": "Bloom 17.15.0 adds SortableChipRow (the profile links editor). First-party Bloom peers remain open above this tested minimum.",
233
233
  "//@oxy.so/core": "Core 7.34.0 supplies `@oxy.so/core/host` (the session host contract, ADR 0058), `createUserEventSocket` and `session.sessionId`, which the provider's host mode is built on; 7.13.0 supplies the `usernamePolicy.*`, `actionErrors.*` and `signin.errors.{network,invalidInput,server}` strings every username field and failure toast is worded with; 7.9.1 fences ordinary authenticated HTTP requests across session changes during auth preflight, which organization claim and creation require; 7.9.0 supplies `deviceComparisonCode`, the short code `OxyDeviceSignIn` prints; 7.8.0 supplies the device sign-in request's `approvalUrl` and the `signin.device.*` strings `OxyDeviceSignIn` shows; 7.7.0 supplies the bounded native asset file adapter and phase progress installed by OxyProvider; 7.6.0 forwards guest locale and first-touch campaign metadata through signup; 7.3.0 supplies `users.lookupMany`, with which the account members screen fails (and retries) a profile read whose chunk failed instead of caching those members as handle-less; 7.2.0 supplies `assets.cachedUrl`, with which `useFileDownloadUrl` answers an already-resolved URL in its first render; 6.16.0 supplies `requireServerVerdict` and `onHolderRejected`, with which the cold boot checks a session it painted from the cache; 6.13.0 supplies the `accounts.settings.*` strings (picture, categories) the account settings speak in every language; 6.12.0 supplies `fileManagement.contentLost` and the `lost` file status a lost file is listed with; 6.11.0 supplies the `follow.errors.*` strings the follow error codes are worded with; 6.4.0 the `follow.*` strings the follow buttons read for every verb and language; 6.1.0 the `oxy.auth.email.{startChange,change,remove}` and `oxy.auth.password.remove` the sign-in & security panels call. Keep one Core instance per app; raise this floor with the root catalogue when new runtime APIs are required.",
234
234
  "//react-native": "React Native 0.81 to 0.88, React 19.1+ and Expo SDK 54 to 58. The floors are the Expo SDK 54 stack (react-native 0.81.6, react 19.1.4, react-native-web 0.21.4, expo 54.0.38 and the module versions its bundledNativeModules.json pins), which compat/expo-54 installs as an external consumer and checks on every CI run (`bun check.mjs`): every peer here admits that stack, services' published src typechecks against its types, and <OxyProvider> mounts and settles its cold boot on iOS (React Native 0.81), web (react-native-web 0.21) and react-native-macos 0.81 with the native modules macOS lacks absent. Astro, Oxy's browser, runs react-native-macos 0.81 (0.83 is its latest release), which is why the floor is not 0.85. The SDK 56 floors these replaced were the versions current when the ranges were first written, not measurements.",
235
235
  "peerDependencies": {
236
236
  "@expo/app-integrity": ">=0.1.10 <59.0.0",
237
237
  "@expo/vector-icons": "^15.0.3",
238
- "@oxy.so/bloom": ">=11.1.0",
239
- "@oxy.so/core": "^7.34.0",
238
+ "@oxy.so/bloom": ">=17.15.0",
239
+ "@oxy.so/core": "^7.36.0",
240
240
  "@react-native-async-storage/async-storage": ">=2.0.0 <4.0.0",
241
241
  "@react-native-community/netinfo": ">=11.4.1 <13.0.0",
242
242
  "@tanstack/query-async-storage-persister": "^5.101",
@@ -5,8 +5,8 @@
5
5
  "ionicons": {
6
6
  "fontFamily": "OxyServicesIonicons",
7
7
  "file": "src/assets/fonts/icons/OxyServicesIonicons.ttf",
8
- "bytes": 42552,
9
- "sha256": "e96171a1057f9bdd8c84f4bda471bba65eefee63b00aefd88a04f06b12fbb84d",
8
+ "bytes": 42812,
9
+ "sha256": "d205e01496e2edf27c1a716c18fae32f2508fd1c5c60d3b5a515135c62c151cb",
10
10
  "names": [
11
11
  "add",
12
12
  "add-circle-outline",
@@ -120,6 +120,7 @@
120
120
  "repeat-outline",
121
121
  "resize",
122
122
  "rocket",
123
+ "save",
123
124
  "scale",
124
125
  "school-outline",
125
126
  "search",
@@ -153,7 +154,7 @@
153
154
  "fontFamily": "OxyServicesMaterialCommunityIcons",
154
155
  "file": "src/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf",
155
156
  "bytes": 29268,
156
- "sha256": "51b5f47ec2eaf09a7ef0d8f4400350c854805698fb139afa0e9f31f29479165e",
157
+ "sha256": "b1df564c8c2bc69877db8fd82327e9f850cdf675822a03310f5fac3cbb5a0d4d",
157
158
  "names": [
158
159
  "account",
159
160
  "account-circle",
@@ -354,5 +355,5 @@
354
355
  }
355
356
  },
356
357
  "glyphMapsFile": "src/ui/icons/subsetGlyphMaps.ts",
357
- "glyphMapsSha256": "8aef398b9836d5501ff4cdc2f0b13b36e9f42fa5a118833312d6a8847f6b61ff"
358
+ "glyphMapsSha256": "5c85241254c4d3eca548478eaf10377f8c29be6e6f515e03d67a3e675d358966"
358
359
  }
@@ -111,6 +111,7 @@ export const ioniconsGlyphMap = {
111
111
  "repeat-outline": 62768,
112
112
  "resize": 62770,
113
113
  "rocket": 62791,
114
+ "save": 62800,
114
115
  "scale": 62803,
115
116
  "school-outline": 62813,
116
117
  "search": 62815,
@@ -33,17 +33,9 @@ import { useOxy } from '../context/oxyRuntimeContext';
33
33
  import { useProfileEditing } from '../hooks/useProfileEditing';
34
34
  import { toast } from '@oxy.so/bloom/toast';
35
35
  import { accountNameInvalidKey, accountNameInvalidMessage, isValidAccountName } from '@oxy.so/core';
36
- import {
37
- getLinkTitle,
38
- getLinkDescription,
39
- linkIdentity,
40
- linksToListItems,
41
- normalizeLinkInput,
42
- type LinkInputError,
43
- } from './linkFormat';
44
- import { LinkListEditor } from './LinkListEditor';
36
+ import { getLinkTitle, getLinkDescription, linksToListItems } from './linkFormat';
37
+ import { ProfileLinksEditor } from './ProfileLinksEditor';
45
38
  import type { LinkListItem } from './linkFormat';
46
- import { PROFILE_LINKS_MAX } from '@oxy.so/contracts/client';
47
39
 
48
40
  /**
49
41
  * Field types supported by EditProfileFieldScreen
@@ -221,7 +213,6 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
221
213
  () => buildInitialProfileState(user, fieldType).listItems,
222
214
  );
223
215
  const [newItemValue, setNewItemValue] = useState('');
224
- const [linkInputError, setLinkInputError] = useState<LinkInputError | null>(null);
225
216
 
226
217
  const [phoneCountry, setPhoneCountry] = useState(() => {
227
218
  const phone = fieldValues.phone?.replace(/[\s()-]/g, '') || '';
@@ -453,32 +444,9 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
453
444
  name: newItemValue.trim(),
454
445
  };
455
446
  setListItems((prev) => [...prev, newItem]);
456
- } else if (fieldType === 'links') {
457
- if (listItems.length >= PROFILE_LINKS_MAX) {
458
- setLinkInputError('limit');
459
- return;
460
- }
461
- const result = normalizeLinkInput(newItemValue);
462
- if ('error' in result) {
463
- setLinkInputError(result.error);
464
- return;
465
- }
466
- const identity = linkIdentity(result.url);
467
- if (listItems.some((item) => linkIdentity(String(item.url || '')) === identity)) {
468
- setLinkInputError('already-added');
469
- return;
470
- }
471
- const newItem = {
472
- id: `link-${Date.now()}`,
473
- url: result.url,
474
- title: getLinkTitle(result.url),
475
- description: getLinkDescription(result.url),
476
- };
477
- setListItems((prev) => [...prev, newItem]);
478
- setLinkInputError(null);
479
447
  }
480
448
  setNewItemValue('');
481
- }, [newItemValue, fieldType, listItems]);
449
+ }, [newItemValue, fieldType]);
482
450
 
483
451
  // Remove item from list
484
452
  const handleRemoveItem = useCallback((id: string) => {
@@ -704,36 +672,24 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
704
672
  );
705
673
  };
706
674
 
707
- const linkInputErrorMessage = (error: LinkInputError): string => {
708
- switch (error) {
709
- case 'empty':
710
- return t('editProfile.items.links.errors.empty') || 'Enter a link.';
711
- case 'insecure':
712
- return t('editProfile.items.links.errors.insecure') || 'Links must start with https://.';
713
- case 'already-added':
714
- return (
715
- t('editProfile.items.links.errors.duplicate') || 'That link is already on your profile.'
716
- );
717
- case 'limit':
718
- return (
719
- t('editProfile.items.links.errors.limit', { count: PROFILE_LINKS_MAX }) ||
720
- `You can add up to ${PROFILE_LINKS_MAX} links.`
721
- );
722
- default:
723
- return t('editProfile.items.links.errors.invalid') || 'Enter a valid link.';
675
+ // Links are edited as chips (reorder, add, edit); locations stay a text list.
676
+ const renderListContent = () => {
677
+ if (fieldType === 'links') {
678
+ return (
679
+ <GroupedSection
680
+ title={`${t('editProfile.items.links.yourLinks') || 'Your Links'} (${listItems.length})`}
681
+ >
682
+ <ProfileLinksEditor
683
+ items={listItems as LinkListItem[]}
684
+ onChange={(items) => setListItems(items as EditableListItem[])}
685
+ disabled={isSaving}
686
+ />
687
+ </GroupedSection>
688
+ );
724
689
  }
725
- };
726
690
 
727
- // Render list content (locations or links)
728
- const renderListContent = () => {
729
- const addLabel =
730
- fieldType === 'locations'
731
- ? t('editProfile.items.locations.add') || 'Add Location'
732
- : t('editProfile.items.links.add') || 'Add Link';
733
- const listTitle =
734
- fieldType === 'locations'
735
- ? t('editProfile.items.locations.yourLocations') || 'Your Locations'
736
- : t('editProfile.items.links.yourLinks') || 'Your Links';
691
+ const addLabel = t('editProfile.items.locations.add') || 'Add Location';
692
+ const listTitle = t('editProfile.items.locations.yourLocations') || 'Your Locations';
737
693
 
738
694
  return (
739
695
  <>
@@ -749,7 +705,6 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
749
705
  autoCorrect={false}
750
706
  onSubmitEditing={handleAddItem}
751
707
  returnKeyType="done"
752
- keyboardType={fieldType === 'links' ? 'url' : 'default'}
753
708
  />
754
709
  </TextField>
755
710
  </View>
@@ -764,27 +719,6 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
764
719
  />
765
720
  </View>
766
721
 
767
- {fieldType === 'links' && linkInputError && (
768
- <TextFieldHint>{linkInputErrorMessage(linkInputError)}</TextFieldHint>
769
- )}
770
-
771
- {fieldType === 'links' && listItems.length > 0 && (
772
- <GroupedSection title={`${listTitle} (${listItems.length})`}>
773
- <LinkListEditor
774
- items={listItems as LinkListItem[]}
775
- onChange={(items) => setListItems(items as EditableListItem[])}
776
- disabled={isSaving}
777
- labels={{
778
- title: t('editProfile.items.links.linkTitle') || 'Title',
779
- moveUp: t('editProfile.items.links.moveUp') || 'Move up',
780
- moveDown: t('editProfile.items.links.moveDown') || 'Move down',
781
- remove: t('common.remove') || 'Remove',
782
- removeNamed: (title) => `${t('common.remove') || 'Remove'} ${title}`,
783
- }}
784
- />
785
- </GroupedSection>
786
- )}
787
-
788
722
  {fieldType === 'locations' && listItems.length > 0 && (
789
723
  <GroupedSection title={`${listTitle} (${listItems.length})`}>
790
724
  {listItems.map((item) => (
@@ -0,0 +1,131 @@
1
+ import { useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { Button } from '@oxy.so/bloom/button';
4
+ import { Card } from '@oxy.so/bloom/card';
5
+ import { Field } from '@oxy.so/bloom/field';
6
+ import type { SurfaceControls } from '@oxy.so/bloom/surfaces';
7
+ import { TextField, TextFieldInput } from '@oxy.so/bloom/text-field';
8
+ import { PROFILE_LINK_TITLE_MAX } from '@oxy.so/contracts/client';
9
+ import { useI18n } from '../hooks/useI18n';
10
+ import {
11
+ clampLinkTitle,
12
+ linkIdentity,
13
+ normalizeLinkInput,
14
+ type LinkFormResult,
15
+ type LinkInputError,
16
+ type LinkListItem,
17
+ } from './linkFormat';
18
+
19
+ interface ProfileLinkFormProps {
20
+ /** The presenting surface (from `surfaces.present`); its dismiss result is the form's answer. */
21
+ surface: SurfaceControls;
22
+ /** The link being edited. Absent when adding one. */
23
+ link?: LinkListItem;
24
+ /** The addresses already on the profile, other than this link's own. */
25
+ existingUrls: readonly string[];
26
+ }
27
+
28
+ /**
29
+ * The form for one profile link: its address and an optional title. Saving
30
+ * dismisses the surface with the link to keep; removing dismisses it with a
31
+ * remove. A blank title is left blank, so the profile shows the address.
32
+ */
33
+ export function ProfileLinkForm({ surface, link, existingUrls }: ProfileLinkFormProps) {
34
+ const { t } = useI18n();
35
+ const [input, setInput] = useState(link?.url ?? '');
36
+ const [title, setTitle] = useState(link?.title ?? '');
37
+ const [error, setError] = useState<LinkInputError | null>(null);
38
+
39
+ const errorMessage = (kind: LinkInputError): string => {
40
+ switch (kind) {
41
+ case 'empty':
42
+ return t('editProfile.items.links.errors.empty') || 'Enter a link.';
43
+ case 'insecure':
44
+ return t('editProfile.items.links.errors.insecure') || 'Links must start with https://.';
45
+ case 'already-added':
46
+ return (
47
+ t('editProfile.items.links.errors.duplicate') || 'That link is already on your profile.'
48
+ );
49
+ default:
50
+ return t('editProfile.items.links.errors.invalid') || 'Enter a valid link.';
51
+ }
52
+ };
53
+
54
+ const save = () => {
55
+ const normalized = normalizeLinkInput(input);
56
+ if ('error' in normalized) {
57
+ setError(normalized.error);
58
+ return;
59
+ }
60
+ const identity = linkIdentity(normalized.url);
61
+ if (existingUrls.some((url) => linkIdentity(url) === identity)) {
62
+ setError('already-added');
63
+ return;
64
+ }
65
+ const result: LinkFormResult = {
66
+ kind: 'save',
67
+ url: normalized.url,
68
+ title: clampLinkTitle(title.trim()),
69
+ };
70
+ surface.dismiss(result);
71
+ };
72
+
73
+ const remove = () => {
74
+ const result: LinkFormResult = { kind: 'remove' };
75
+ surface.dismiss(result);
76
+ };
77
+
78
+ return (
79
+ <Card className="gap-space-16 p-space-16">
80
+ <Field
81
+ label={t('editProfile.items.links.form.urlLabel') || 'Link'}
82
+ error={error ? errorMessage(error) : undefined}
83
+ >
84
+ <TextField>
85
+ <TextFieldInput
86
+ label={t('editProfile.items.links.form.urlLabel') || 'Link'}
87
+ placeholder={t('editProfile.items.links.placeholder') || 'Enter URL'}
88
+ value={input}
89
+ onChangeText={(value: string) => {
90
+ setInput(value);
91
+ setError(null);
92
+ }}
93
+ autoCapitalize="none"
94
+ autoCorrect={false}
95
+ keyboardType="url"
96
+ isInvalid={error !== null}
97
+ autoFocus={!link}
98
+ />
99
+ </TextField>
100
+ </Field>
101
+ <Field label={t('editProfile.items.links.form.titleLabel') || 'Title'}>
102
+ <TextField>
103
+ <TextFieldInput
104
+ label={t('editProfile.items.links.form.titleLabel') || 'Title'}
105
+ placeholder={t('editProfile.items.links.form.titlePlaceholder') || 'Optional'}
106
+ value={title}
107
+ onChangeText={(value: string) => setTitle(clampLinkTitle(value))}
108
+ maxLength={PROFILE_LINK_TITLE_MAX}
109
+ />
110
+ </TextField>
111
+ </Field>
112
+ <View className="flex-row justify-between items-center gap-space-8">
113
+ {link ? (
114
+ <Button appearance="plain" tone="danger" onPress={remove}>
115
+ {t('editProfile.items.links.form.remove') || 'Remove'}
116
+ </Button>
117
+ ) : (
118
+ <View />
119
+ )}
120
+ <View className="flex-row gap-space-8">
121
+ <Button appearance="subtle" tone="neutral" onPress={() => surface.dismiss()}>
122
+ {t('common.cancel') || 'Cancel'}
123
+ </Button>
124
+ <Button appearance="solid" tone="accent" onPress={save}>
125
+ {t('common.save') || 'Save'}
126
+ </Button>
127
+ </View>
128
+ </View>
129
+ </Card>
130
+ );
131
+ }
@@ -0,0 +1,98 @@
1
+ import { View } from 'react-native';
2
+ import { Button } from '@oxy.so/bloom/button';
3
+ import { Chip } from '@oxy.so/bloom/chip';
4
+ import { SortableChipRow } from '@oxy.so/bloom/sortable-chip-row';
5
+ import { surfaces } from '@oxy.so/bloom/surfaces';
6
+ import { PROFILE_LINKS_MAX } from '@oxy.so/contracts/client';
7
+ import { useI18n } from '../hooks/useI18n';
8
+ import { ProfileLinkForm } from './ProfileLinkForm';
9
+ import {
10
+ applyLinkFormResult,
11
+ getLinkTitle,
12
+ type LinkFormResult,
13
+ type LinkListItem,
14
+ } from './linkFormat';
15
+
16
+ interface ProfileLinksEditorProps {
17
+ items: LinkListItem[];
18
+ onChange: (items: LinkListItem[]) => void;
19
+ disabled?: boolean;
20
+ }
21
+
22
+ let linkCounter = 0;
23
+ /** A fresh id for a link added in this editing session. */
24
+ const newLinkId = (): string => {
25
+ linkCounter += 1;
26
+ return `link-new-${Date.now().toString(36)}-${linkCounter}`;
27
+ };
28
+
29
+ /** The text a link's pill shows: its title, else its address without the scheme. */
30
+ const pillLabel = (item: LinkListItem): string => item.title || getLinkTitle(item.url);
31
+
32
+ /**
33
+ * The profile's links as pills, in the order they are shown, reordered by
34
+ * dragging. Tapping a pill edits that link; "Add link" appears until the profile
35
+ * holds the maximum. Changes stay local until the profile is saved.
36
+ */
37
+ export function ProfileLinksEditor({ items, onChange, disabled = false }: ProfileLinksEditorProps) {
38
+ const { t } = useI18n();
39
+
40
+ const openForm = async (index: number | null) => {
41
+ const link = index === null ? undefined : items[index];
42
+ const result = await surfaces.present<LinkFormResult | undefined>((surface) => (
43
+ <ProfileLinkForm
44
+ surface={surface}
45
+ link={link}
46
+ existingUrls={items.filter((_, i) => i !== index).map((item) => item.url)}
47
+ />
48
+ ));
49
+ if (!result) return;
50
+ onChange(applyLinkFormResult(items, index, result, PROFILE_LINKS_MAX, newLinkId));
51
+ };
52
+
53
+ const rowItems = items.map((item, index) => ({
54
+ key: item.id,
55
+ label: pillLabel(item),
56
+ node: (
57
+ <Chip
58
+ size="md"
59
+ variant="subtle"
60
+ accessibilityLabel={t('editProfile.items.links.editLink', {
61
+ defaultValue: 'Edit {{label}}',
62
+ label: pillLabel(item),
63
+ })}
64
+ onPress={() => void openForm(index)}
65
+ disabled={disabled}
66
+ >
67
+ {pillLabel(item)}
68
+ </Chip>
69
+ ),
70
+ }));
71
+
72
+ return (
73
+ <SortableChipRow
74
+ items={rowItems}
75
+ disabled={disabled}
76
+ onReorder={(keys) => {
77
+ const byKey = new Map(items.map((item) => [item.id, item]));
78
+ onChange(keys.flatMap((key) => (byKey.has(key) ? [byKey.get(key) as LinkListItem] : [])));
79
+ }}
80
+ accessibilityLabel={t('editProfile.items.links.title') || 'Links'}
81
+ trailing={
82
+ items.length < PROFILE_LINKS_MAX ? (
83
+ <View>
84
+ <Button
85
+ appearance="outline"
86
+ tone="neutral"
87
+ size="sm"
88
+ disabled={disabled}
89
+ onPress={() => void openForm(null)}
90
+ >
91
+ {t('editProfile.items.links.form.add') || 'Add link'}
92
+ </Button>
93
+ </View>
94
+ ) : null
95
+ }
96
+ />
97
+ );
98
+ }
@@ -4,7 +4,7 @@ import {
4
4
  getLinkDescription,
5
5
  linkIdentity,
6
6
  linksToListItems,
7
- moveLinkItem,
7
+ applyLinkFormResult,
8
8
  normalizeLinkInput,
9
9
  } from '../linkFormat';
10
10
 
@@ -112,14 +112,57 @@ describe('clampLinkTitle', () => {
112
112
  });
113
113
  });
114
114
 
115
- describe('moveLinkItem', () => {
116
- it('swaps an entry with its neighbour', () => {
117
- expect(moveLinkItem(['a', 'b', 'c'], 1, -1)).toEqual(['b', 'a', 'c']);
118
- expect(moveLinkItem(['a', 'b', 'c'], 1, 1)).toEqual(['a', 'c', 'b']);
115
+ describe('applyLinkFormResult', () => {
116
+ const item = (id: string, url: string, title = '') => ({
117
+ id,
118
+ url,
119
+ title,
120
+ description: `Link to ${url}`,
119
121
  });
122
+ const existing = [item('a', 'https://a.test/'), item('b', 'https://b.test/')];
123
+ const newId = () => 'new-1';
120
124
 
121
- it('leaves the list alone at either end', () => {
122
- expect(moveLinkItem(['a', 'b'], 0, -1)).toEqual(['a', 'b']);
123
- expect(moveLinkItem(['a', 'b'], 1, 1)).toEqual(['a', 'b']);
125
+ it('appends a saved link, with its title and description', () => {
126
+ const next = applyLinkFormResult(
127
+ existing,
128
+ null,
129
+ { kind: 'save', url: 'https://c.test/', title: 'Site' },
130
+ 10,
131
+ newId,
132
+ );
133
+ expect(next[2]).toEqual({
134
+ id: 'new-1',
135
+ url: 'https://c.test/',
136
+ title: 'Site',
137
+ description: 'Link to https://c.test/',
138
+ });
139
+ });
140
+
141
+ it('replaces the link being edited and keeps its id', () => {
142
+ const next = applyLinkFormResult(
143
+ existing,
144
+ 1,
145
+ { kind: 'save', url: 'https://b2.test/', title: '' },
146
+ 10,
147
+ newId,
148
+ );
149
+ expect(next[1]).toMatchObject({ id: 'b', url: 'https://b2.test/', title: '' });
150
+ expect(next).toHaveLength(2);
151
+ });
152
+
153
+ it('refuses a new link once the profile is full', () => {
154
+ const next = applyLinkFormResult(
155
+ existing,
156
+ null,
157
+ { kind: 'save', url: 'https://c.test/', title: '' },
158
+ 2,
159
+ newId,
160
+ );
161
+ expect(next).toEqual(existing);
162
+ });
163
+
164
+ it('removes the link being edited, and nothing for a new one', () => {
165
+ expect(applyLinkFormResult(existing, 0, { kind: 'remove' }, 10, newId)).toEqual([existing[1]]);
166
+ expect(applyLinkFormResult(existing, null, { kind: 'remove' }, 10, newId)).toEqual(existing);
124
167
  });
125
168
  });
@@ -84,14 +84,33 @@ export function clampLinkTitle(title: string): string {
84
84
  return Array.from(title).slice(0, PROFILE_LINK_TITLE_MAX).join('');
85
85
  }
86
86
 
87
- /** A copy of the list with the entry at the index moved one place: -1 up, +1 down. */
88
- export function moveLinkItem<T>(items: readonly T[], index: number, delta: -1 | 1): T[] {
89
- const target = index + delta;
90
- if (index < 0 || index >= items.length || target < 0 || target >= items.length) {
91
- return [...items];
87
+ /** What the link form hands back when it is dismissed. */
88
+ export type LinkFormResult = { kind: 'save'; url: string; title: string } | { kind: 'remove' };
89
+
90
+ /**
91
+ * The list after a link form result. A save appends a new link (if the profile
92
+ * has room) or replaces the link at `index`; a remove drops it. `newId` makes
93
+ * the id of an appended link, so the caller decides how ids are minted.
94
+ */
95
+ export function applyLinkFormResult(
96
+ items: readonly LinkListItem[],
97
+ index: number | null,
98
+ result: LinkFormResult,
99
+ maxLinks: number,
100
+ newId: () => string,
101
+ ): LinkListItem[] {
102
+ if (result.kind === 'remove') {
103
+ return index === null ? [...items] : items.filter((_, i) => i !== index);
104
+ }
105
+ const title = clampLinkTitle(result.title.trim());
106
+ const saved: LinkListItem = {
107
+ id: index === null ? newId() : (items[index]?.id ?? newId()),
108
+ url: result.url,
109
+ title,
110
+ description: getLinkDescription(result.url),
111
+ };
112
+ if (index === null) {
113
+ return items.length >= maxLinks ? [...items] : [...items, saved];
92
114
  }
93
- const next = [...items];
94
- const [moved] = next.splice(index, 1);
95
- next.splice(target, 0, moved as T);
96
- return next;
115
+ return items.map((item, i) => (i === index ? saved : item));
97
116
  }