@oxy.so/services 14.4.0 → 14.5.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.
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +56 -23
- package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/LinkListEditor.js +105 -0
- package/lib/commonjs/ui/screens/LinkListEditor.js.map +1 -0
- package/lib/commonjs/ui/screens/linkFormat.js +75 -3
- package/lib/commonjs/ui/screens/linkFormat.js.map +1 -1
- package/lib/module/ui/screens/EditProfileFieldScreen.js +59 -25
- package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
- package/lib/module/ui/screens/LinkListEditor.js +99 -0
- package/lib/module/ui/screens/LinkListEditor.js.map +1 -0
- package/lib/module/ui/screens/linkFormat.js +71 -3
- package/lib/module/ui/screens/linkFormat.js.map +1 -1
- package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts +25 -0
- package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts +23 -5
- package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/LinkListEditor.d.ts +25 -0
- package/lib/typescript/module/ui/screens/LinkListEditor.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/linkFormat.d.ts +23 -5
- package/lib/typescript/module/ui/screens/linkFormat.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/ui/screens/EditProfileFieldScreen.tsx +76 -28
- package/src/ui/screens/LinkListEditor.tsx +113 -0
- package/src/ui/screens/__tests__/linkFormat.test.ts +57 -1
- package/src/ui/screens/linkFormat.ts +63 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { useState, useCallback, useMemo } from 'react';
|
|
2
|
-
import { View,
|
|
3
|
-
import { ExpoImage } from '../components/ExpoImage';
|
|
2
|
+
import { View, type TextInputProps } from 'react-native';
|
|
4
3
|
import Ionicons from '../icons/Ionicons';
|
|
5
4
|
import type { BaseScreenProps } from '../types/navigation';
|
|
6
5
|
import { useTheme } from '@oxy.so/bloom/theme';
|
|
@@ -20,7 +19,17 @@ import { useOxy } from '../context/oxyRuntimeContext';
|
|
|
20
19
|
import { useProfileEditing } from '../hooks/useProfileEditing';
|
|
21
20
|
import { toast } from '@oxy.so/bloom/toast';
|
|
22
21
|
import { accountNameInvalidKey, accountNameInvalidMessage, isValidAccountName } from '@oxy.so/core';
|
|
23
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
getLinkTitle,
|
|
24
|
+
getLinkDescription,
|
|
25
|
+
linkIdentity,
|
|
26
|
+
linksToListItems,
|
|
27
|
+
normalizeLinkInput,
|
|
28
|
+
type LinkInputError,
|
|
29
|
+
} from './linkFormat';
|
|
30
|
+
import { LinkListEditor } from './LinkListEditor';
|
|
31
|
+
import type { LinkListItem } from './linkFormat';
|
|
32
|
+
import { PROFILE_LINKS_MAX } from '@oxy.so/contracts/client';
|
|
24
33
|
|
|
25
34
|
/**
|
|
26
35
|
* Field types supported by EditProfileFieldScreen
|
|
@@ -194,6 +203,7 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
|
|
|
194
203
|
() => buildInitialProfileState(user, fieldType).listItems,
|
|
195
204
|
);
|
|
196
205
|
const [newItemValue, setNewItemValue] = useState('');
|
|
206
|
+
const [linkInputError, setLinkInputError] = useState<LinkInputError | null>(null);
|
|
197
207
|
|
|
198
208
|
const [phoneCountry, setPhoneCountry] = useState(() => {
|
|
199
209
|
const phone = fieldValues.phone?.replace(/[\s()-]/g, '') || '';
|
|
@@ -404,16 +414,31 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
|
|
|
404
414
|
};
|
|
405
415
|
setListItems((prev) => [...prev, newItem]);
|
|
406
416
|
} else if (fieldType === 'links') {
|
|
417
|
+
if (listItems.length >= PROFILE_LINKS_MAX) {
|
|
418
|
+
setLinkInputError('limit');
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const result = normalizeLinkInput(newItemValue);
|
|
422
|
+
if ('error' in result) {
|
|
423
|
+
setLinkInputError(result.error);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const identity = linkIdentity(result.url);
|
|
427
|
+
if (listItems.some((item) => linkIdentity(String(item.url || '')) === identity)) {
|
|
428
|
+
setLinkInputError('already-added');
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
407
431
|
const newItem = {
|
|
408
432
|
id: `link-${Date.now()}`,
|
|
409
|
-
url:
|
|
410
|
-
title: getLinkTitle(
|
|
411
|
-
description: getLinkDescription(
|
|
433
|
+
url: result.url,
|
|
434
|
+
title: getLinkTitle(result.url),
|
|
435
|
+
description: getLinkDescription(result.url),
|
|
412
436
|
};
|
|
413
437
|
setListItems((prev) => [...prev, newItem]);
|
|
438
|
+
setLinkInputError(null);
|
|
414
439
|
}
|
|
415
440
|
setNewItemValue('');
|
|
416
|
-
}, [newItemValue, fieldType]);
|
|
441
|
+
}, [newItemValue, fieldType, listItems]);
|
|
417
442
|
|
|
418
443
|
// Remove item from list
|
|
419
444
|
const handleRemoveItem = useCallback((id: string) => {
|
|
@@ -610,6 +635,26 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
|
|
|
610
635
|
);
|
|
611
636
|
};
|
|
612
637
|
|
|
638
|
+
const linkInputErrorMessage = (error: LinkInputError): string => {
|
|
639
|
+
switch (error) {
|
|
640
|
+
case 'empty':
|
|
641
|
+
return t('editProfile.items.links.errors.empty') || 'Enter a link.';
|
|
642
|
+
case 'insecure':
|
|
643
|
+
return t('editProfile.items.links.errors.insecure') || 'Links must start with https://.';
|
|
644
|
+
case 'already-added':
|
|
645
|
+
return (
|
|
646
|
+
t('editProfile.items.links.errors.duplicate') || 'That link is already on your profile.'
|
|
647
|
+
);
|
|
648
|
+
case 'limit':
|
|
649
|
+
return (
|
|
650
|
+
t('editProfile.items.links.errors.limit', { count: PROFILE_LINKS_MAX }) ||
|
|
651
|
+
`You can add up to ${PROFILE_LINKS_MAX} links.`
|
|
652
|
+
);
|
|
653
|
+
default:
|
|
654
|
+
return t('editProfile.items.links.errors.invalid') || 'Enter a valid link.';
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
|
|
613
658
|
// Render list content (locations or links)
|
|
614
659
|
const renderListContent = () => {
|
|
615
660
|
const addLabel =
|
|
@@ -650,27 +695,38 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
|
|
|
650
695
|
/>
|
|
651
696
|
</View>
|
|
652
697
|
|
|
653
|
-
{
|
|
698
|
+
{fieldType === 'links' && linkInputError && (
|
|
699
|
+
<TextFieldHint>{linkInputErrorMessage(linkInputError)}</TextFieldHint>
|
|
700
|
+
)}
|
|
701
|
+
|
|
702
|
+
{fieldType === 'links' && listItems.length > 0 && (
|
|
703
|
+
<GroupedSection title={`${listTitle} (${listItems.length})`}>
|
|
704
|
+
<LinkListEditor
|
|
705
|
+
items={listItems as LinkListItem[]}
|
|
706
|
+
onChange={(items) => setListItems(items as EditableListItem[])}
|
|
707
|
+
disabled={isSaving}
|
|
708
|
+
labels={{
|
|
709
|
+
title: t('editProfile.items.links.linkTitle') || 'Title',
|
|
710
|
+
moveUp: t('editProfile.items.links.moveUp') || 'Move up',
|
|
711
|
+
moveDown: t('editProfile.items.links.moveDown') || 'Move down',
|
|
712
|
+
remove: t('common.remove') || 'Remove',
|
|
713
|
+
removeNamed: (title) => `${t('common.remove') || 'Remove'} ${title}`,
|
|
714
|
+
}}
|
|
715
|
+
/>
|
|
716
|
+
</GroupedSection>
|
|
717
|
+
)}
|
|
718
|
+
|
|
719
|
+
{fieldType === 'locations' && listItems.length > 0 && (
|
|
654
720
|
<GroupedSection title={`${listTitle} (${listItems.length})`}>
|
|
655
721
|
{listItems.map((item) => (
|
|
656
722
|
<GroupedSectionItem
|
|
657
723
|
key={item.id}
|
|
658
|
-
title={String(
|
|
659
|
-
description={fieldType === 'links' ? String(item.url) : undefined}
|
|
660
|
-
icon={
|
|
661
|
-
fieldType === 'links' && item.image ? (
|
|
662
|
-
<ExpoImage
|
|
663
|
-
source={{ uri: item.image }}
|
|
664
|
-
style={styles.linkImage}
|
|
665
|
-
contentFit="cover"
|
|
666
|
-
/>
|
|
667
|
-
) : undefined
|
|
668
|
-
}
|
|
724
|
+
title={String(item.name)}
|
|
669
725
|
rightElement={
|
|
670
726
|
<Button
|
|
671
727
|
onPress={() => handleRemoveItem(item.id)}
|
|
672
728
|
disabled={isSaving}
|
|
673
|
-
accessibilityLabel={`${t('common.remove') || 'Remove'} ${
|
|
729
|
+
accessibilityLabel={`${t('common.remove') || 'Remove'} ${String(item.name)}`}
|
|
674
730
|
icon={
|
|
675
731
|
<Ionicons name="trash-outline" size={18} color={bloomTheme.colors.negative} />
|
|
676
732
|
}
|
|
@@ -710,12 +766,4 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
|
|
|
710
766
|
);
|
|
711
767
|
};
|
|
712
768
|
|
|
713
|
-
const styles = StyleSheet.create({
|
|
714
|
-
linkImage: {
|
|
715
|
-
width: 40,
|
|
716
|
-
height: 40,
|
|
717
|
-
borderRadius: 8,
|
|
718
|
-
},
|
|
719
|
-
});
|
|
720
|
-
|
|
721
769
|
export default React.memo(EditProfileFieldScreen);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
4
|
+
import { TextField, TextFieldInput, TextFieldLabel } from '@oxy.so/bloom/text-field';
|
|
5
|
+
import { Text } from '@oxy.so/bloom/typography';
|
|
6
|
+
import { useTheme } from '@oxy.so/bloom/theme';
|
|
7
|
+
import { PROFILE_LINK_TITLE_MAX } from '@oxy.so/contracts/client';
|
|
8
|
+
import Ionicons from '../icons/Ionicons';
|
|
9
|
+
import { clampLinkTitle, moveLinkItem, type LinkListItem } from './linkFormat';
|
|
10
|
+
|
|
11
|
+
interface LinkListEditorProps {
|
|
12
|
+
items: LinkListItem[];
|
|
13
|
+
onChange: (items: LinkListItem[]) => void;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Visible and accessible strings, resolved by the caller. */
|
|
16
|
+
labels: {
|
|
17
|
+
title: string;
|
|
18
|
+
moveUp: string;
|
|
19
|
+
moveDown: string;
|
|
20
|
+
remove: string;
|
|
21
|
+
/** `{{title}}` is replaced with the link's title. */
|
|
22
|
+
removeNamed: (title: string) => string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The profile's ordered link list. Each link has an editable title and can move
|
|
28
|
+
* up or down; order is the profile's display order, and the server stores it as
|
|
29
|
+
* the array's index. Reordering uses buttons rather than drag: a drag gesture
|
|
30
|
+
* would not reach a screen reader, and a button does.
|
|
31
|
+
*/
|
|
32
|
+
export function LinkListEditor({ items, onChange, disabled, labels }: LinkListEditorProps) {
|
|
33
|
+
const bloomTheme = useTheme();
|
|
34
|
+
|
|
35
|
+
const setTitle = useCallback(
|
|
36
|
+
(id: string, title: string) => {
|
|
37
|
+
onChange(
|
|
38
|
+
items.map((item) => (item.id === id ? { ...item, title: clampLinkTitle(title) } : item)),
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
[items, onChange],
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const move = useCallback(
|
|
45
|
+
(index: number, delta: -1 | 1) => onChange(moveLinkItem(items, index, delta)),
|
|
46
|
+
[items, onChange],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const remove = useCallback(
|
|
50
|
+
(id: string) => onChange(items.filter((item) => item.id !== id)),
|
|
51
|
+
[items, onChange],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<View className="gap-space-12">
|
|
56
|
+
{items.map((item, index) => {
|
|
57
|
+
const shownTitle = item.title || item.url;
|
|
58
|
+
return (
|
|
59
|
+
<View key={item.id} className="gap-space-8 pb-space-12 border-b border-border">
|
|
60
|
+
<TextField disabled={disabled}>
|
|
61
|
+
<TextFieldLabel>{labels.title}</TextFieldLabel>
|
|
62
|
+
<TextFieldInput
|
|
63
|
+
label={labels.title}
|
|
64
|
+
value={item.title}
|
|
65
|
+
onChangeText={(value) => setTitle(item.id, value)}
|
|
66
|
+
maxLength={PROFILE_LINK_TITLE_MAX}
|
|
67
|
+
autoCorrect
|
|
68
|
+
/>
|
|
69
|
+
</TextField>
|
|
70
|
+
<View className="flex-row items-center gap-space-8">
|
|
71
|
+
<Text className="flex-1 text-muted-foreground" numberOfLines={1}>
|
|
72
|
+
{item.url}
|
|
73
|
+
</Text>
|
|
74
|
+
<Button
|
|
75
|
+
onPress={() => move(index, -1)}
|
|
76
|
+
disabled={disabled || index === 0}
|
|
77
|
+
accessibilityLabel={labels.moveUp}
|
|
78
|
+
icon={
|
|
79
|
+
<Ionicons name="chevron-up" size={18} color={bloomTheme.colors.textSecondary} />
|
|
80
|
+
}
|
|
81
|
+
iconOnly
|
|
82
|
+
tone="neutral"
|
|
83
|
+
appearance="plain"
|
|
84
|
+
/>
|
|
85
|
+
<Button
|
|
86
|
+
onPress={() => move(index, 1)}
|
|
87
|
+
disabled={disabled || index === items.length - 1}
|
|
88
|
+
accessibilityLabel={labels.moveDown}
|
|
89
|
+
icon={
|
|
90
|
+
<Ionicons name="chevron-down" size={18} color={bloomTheme.colors.textSecondary} />
|
|
91
|
+
}
|
|
92
|
+
iconOnly
|
|
93
|
+
tone="neutral"
|
|
94
|
+
appearance="plain"
|
|
95
|
+
/>
|
|
96
|
+
<Button
|
|
97
|
+
onPress={() => remove(item.id)}
|
|
98
|
+
disabled={disabled}
|
|
99
|
+
accessibilityLabel={labels.removeNamed(shownTitle)}
|
|
100
|
+
icon={
|
|
101
|
+
<Ionicons name="trash-outline" size={18} color={bloomTheme.colors.negative} />
|
|
102
|
+
}
|
|
103
|
+
iconOnly
|
|
104
|
+
tone="danger"
|
|
105
|
+
appearance="plain"
|
|
106
|
+
/>
|
|
107
|
+
</View>
|
|
108
|
+
</View>
|
|
109
|
+
);
|
|
110
|
+
})}
|
|
111
|
+
</View>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
clampLinkTitle,
|
|
3
|
+
getLinkTitle,
|
|
4
|
+
getLinkDescription,
|
|
5
|
+
linkIdentity,
|
|
6
|
+
linksToListItems,
|
|
7
|
+
moveLinkItem,
|
|
8
|
+
normalizeLinkInput,
|
|
9
|
+
} from '../linkFormat';
|
|
2
10
|
|
|
3
11
|
describe('linkFormat', () => {
|
|
4
12
|
describe('getLinkTitle', () => {
|
|
@@ -67,3 +75,51 @@ describe('linkFormat', () => {
|
|
|
67
75
|
});
|
|
68
76
|
});
|
|
69
77
|
});
|
|
78
|
+
|
|
79
|
+
describe('normalizeLinkInput', () => {
|
|
80
|
+
it('adds https to a bare host and keeps its path', () => {
|
|
81
|
+
expect(normalizeLinkInput(' example.com/me ')).toEqual({ url: 'https://example.com/me' });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('refuses plain http rather than upgrading it silently', () => {
|
|
85
|
+
expect(normalizeLinkInput('http://example.com')).toEqual({ error: 'insecure' });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('reports empty and unparseable input', () => {
|
|
89
|
+
expect(normalizeLinkInput(' ')).toEqual({ error: 'empty' });
|
|
90
|
+
expect(normalizeLinkInput('not a link')).toEqual({ error: 'invalid' });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('linkIdentity', () => {
|
|
95
|
+
it('treats www, a trailing slash and host case as the same page', () => {
|
|
96
|
+
expect(linkIdentity('https://WWW.Example.com/me/')).toBe(
|
|
97
|
+
linkIdentity('https://example.com/me'),
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('keeps the query, which can name a different page', () => {
|
|
102
|
+
expect(linkIdentity('https://example.com/a?x=1')).not.toBe(
|
|
103
|
+
linkIdentity('https://example.com/a'),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('clampLinkTitle', () => {
|
|
109
|
+
it('cuts to the title limit by characters, not UTF-16 units', () => {
|
|
110
|
+
const emoji = '🙂'.repeat(50);
|
|
111
|
+
expect(Array.from(clampLinkTitle(emoji))).toHaveLength(40);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
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']);
|
|
119
|
+
});
|
|
120
|
+
|
|
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']);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pure link
|
|
3
|
-
*
|
|
4
|
-
* rendering the whole React Native screen.
|
|
2
|
+
* Pure link helpers for the profile "links" editor. Kept out of the screen
|
|
3
|
+
* component so they can be unit-tested without rendering React Native.
|
|
5
4
|
*/
|
|
5
|
+
import { PROFILE_LINK_TITLE_MAX } from '@oxy.so/contracts/client';
|
|
6
6
|
|
|
7
7
|
/** Strip the protocol and any trailing slash from a link URL for display. */
|
|
8
8
|
export const getLinkTitle = (url: string): string =>
|
|
@@ -35,3 +35,63 @@ export function linksToListItems(links: readonly unknown[]): LinkListItem[] {
|
|
|
35
35
|
};
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/** Why a typed link cannot be added to the profile. */
|
|
40
|
+
export type LinkInputError = 'empty' | 'invalid' | 'insecure' | 'already-added' | 'limit';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Normalize a typed link to the absolute https URL it names, or say why it
|
|
44
|
+
* cannot be added. A bare host (`example.com/me`) gets `https://` in front; a
|
|
45
|
+
* plain `http://` link is refused rather than silently upgraded, so the reader
|
|
46
|
+
* sees the address they typed is the address that is saved.
|
|
47
|
+
*/
|
|
48
|
+
export function normalizeLinkInput(input: string): { url: string } | { error: LinkInputError } {
|
|
49
|
+
const trimmed = input.trim();
|
|
50
|
+
if (!trimmed) return { error: 'empty' };
|
|
51
|
+
|
|
52
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed);
|
|
53
|
+
let parsed: URL;
|
|
54
|
+
try {
|
|
55
|
+
parsed = new URL(hasScheme ? trimmed : `https://${trimmed}`);
|
|
56
|
+
} catch {
|
|
57
|
+
return { error: 'invalid' };
|
|
58
|
+
}
|
|
59
|
+
if (parsed.protocol === 'http:') return { error: 'insecure' };
|
|
60
|
+
if (parsed.protocol !== 'https:' || !parsed.hostname.includes('.')) {
|
|
61
|
+
return { error: 'invalid' };
|
|
62
|
+
}
|
|
63
|
+
return { url: parsed.toString() };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The identity two links share when they point at the same page: host without
|
|
68
|
+
* `www.`, path without a trailing slash, and the query. Used to refuse a second
|
|
69
|
+
* copy of a link already on the profile.
|
|
70
|
+
*/
|
|
71
|
+
export function linkIdentity(url: string): string {
|
|
72
|
+
try {
|
|
73
|
+
const parsed = new URL(url);
|
|
74
|
+
const host = parsed.hostname.toLowerCase().replace(/^www\./, '');
|
|
75
|
+
const path = parsed.pathname.replace(/\/+$/, '');
|
|
76
|
+
return `${host}${path}${parsed.search}`;
|
|
77
|
+
} catch {
|
|
78
|
+
return url.trim().toLowerCase();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Trim a title to the editor's limit, counting characters rather than UTF-16 units. */
|
|
83
|
+
export function clampLinkTitle(title: string): string {
|
|
84
|
+
return Array.from(title).slice(0, PROFILE_LINK_TITLE_MAX).join('');
|
|
85
|
+
}
|
|
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];
|
|
92
|
+
}
|
|
93
|
+
const next = [...items];
|
|
94
|
+
const [moved] = next.splice(index, 1);
|
|
95
|
+
next.splice(target, 0, moved as T);
|
|
96
|
+
return next;
|
|
97
|
+
}
|