Skip to content

Commit 065bbe4

Browse files
committed
JS-8812: fix
1 parent b53e5ef commit 065bbe4

File tree

6 files changed

+62
-27
lines changed

6 files changed

+62
-27
lines changed

src/json/text.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,14 @@
619619
"editorControlDescription0": "Show description",
620620
"editorControlDescription1": "Hide description",
621621

622-
"editorPagePasteLink": "Paste as link",
622+
"editorPagePasteAsHeader": "Paste as",
623+
"editorPagePasteLink": "URL",
624+
"editorPagePasteBookmark": "Bookmark",
625+
"editorPagePasteText": "Plain Text",
626+
"editorPagePasteEmbed": "Embed",
627+
"editorPagePasteObject": "Object",
623628
"editorPageCreateBookmarkObject": "Create Bookmark Object",
624629
"editorPageCreateBookmark": "Create Bookmark",
625-
"editorPagePasteText": "Paste as text",
626-
"editorPagePasteEmbed": "Paste as embed",
627630

628631
"blockNameParagraph": "Text",
629632
"blockNameHeader1": "Title",

src/scss/menu/select.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,5 @@
131131
/* Shortcut conflict */
132132
.menu.menuSelect.shortcutConflict {
133133
.content { height: unset !important; }
134-
.menuLabel { padding: 8px 16px 0px; @include text-small; color: var(--color-text-secondary); }
135-
.menuLabel {
136-
b { font-weight: 500; }
137-
}
138134
}
139135
}

src/ts/component/editor/page.tsx

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,26 +1989,47 @@ const EditorPage = observer(forwardRef<I.BlockRef, Props>((props, ref) => {
19891989
const length = block.getLength();
19901990
const position = length ? I.BlockPosition.Bottom : I.BlockPosition.Replace;
19911991
const processor = U.Embed.getProcessorByUrl(url);
1992-
const canBlock = !isInsideTable && !isLocal;
1993-
1992+
const canBookmark = !isInsideTable && !isLocal;
1993+
1994+
// Check if URL is an Anytype object link in the same space (but not the current page)
1995+
const linkParam = U.Common.getLinkParamFromUrl(url);
1996+
const isAnytypeObject = linkParam.isInside && linkParam.target;
1997+
const isSameSpace = !linkParam.spaceId || (linkParam.spaceId == S.Common.space);
1998+
const isSameObject = linkParam.target == rootId;
1999+
const canObject = isAnytypeObject && isSameSpace && !isSameObject && canBookmark;
19942000
const options: any[] = [
1995-
!currentMark ? { id: 'link', name: translate('editorPagePasteLink') } : null,
1996-
canBlock ? { id: 'block', name: translate('editorPageCreateBookmark') } : null,
1997-
{ id: 'cancel', name: translate('editorPagePasteText') },
1998-
].filter(it => it);
2001+
{ name: translate('editorPagePasteAsHeader'), isSection: true }
2002+
];
19992003

20002004
if (processor !== null) {
2005+
// Embed-compatible URL: Embed first
20012006
options.push({ id: 'embed', name: translate('editorPagePasteEmbed') });
20022007
};
20032008

2009+
// Build options based on URL type
2010+
if (canObject) {
2011+
// Anytype Object Link: Object, Bookmark, URL, Plain Text
2012+
options.push({ id: 'object', name: translate('editorPagePasteObject') });
2013+
};
2014+
2015+
if (canBookmark) {
2016+
options.push({ id: 'bookmark', name: translate('editorPagePasteBookmark') });
2017+
};
2018+
2019+
if (!currentMark) {
2020+
options.push({ id: 'link', name: translate('editorPagePasteLink') });
2021+
};
2022+
2023+
options.push({ id: 'cancel', name: translate('editorPagePasteText') });
2024+
20042025
S.Common.clearTimeout('blockContext');
20052026

2006-
const menuParam = {
2027+
const menuParam = {
20072028
component: 'select',
20082029
element: `#block-${focused}`,
2009-
recalcRect: () => {
2030+
recalcRect: () => {
20102031
const rect = U.Common.getSelectionRect();
2011-
return rect ? { ...rect, y: rect.y + win.scrollTop() } : null;
2032+
return rect ? { ...rect, y: rect.y + win.scrollTop() } : null;
20122033
},
20132034
offsetX: () => {
20142035
const rect = U.Common.getSelectionRect();
@@ -2025,12 +2046,33 @@ const EditorPage = observer(forwardRef<I.BlockRef, Props>((props, ref) => {
20252046
data: {
20262047
value: '',
20272048
options,
2049+
noFilter: true,
20282050
onSelect: (event: any, item: any) => {
20292051
let marks = U.Common.objectCopy(block.content.marks || []);
20302052
let value = block.content.text;
20312053
let to = 0;
20322054

20332055
switch (item.id) {
2056+
case 'object': {
2057+
const targetId = linkParam.target;
2058+
const newBlock = {
2059+
type: I.BlockType.Link,
2060+
content: {
2061+
...U.Data.defaultLinkSettings(),
2062+
targetBlockId: targetId,
2063+
},
2064+
};
2065+
2066+
C.BlockCreate(rootId, focused, position, newBlock, (message: any) => {
2067+
if (!message.error.code) {
2068+
blockCreate(message.blockId, I.BlockPosition.Bottom, { type: I.BlockType.Text });
2069+
2070+
analytics.event('CreateBlock', { middleTime: message.middleTime, type: I.BlockType.Link });
2071+
};
2072+
});
2073+
break;
2074+
};
2075+
20342076
case 'link': {
20352077
if (currentFrom == currentTo) {
20362078
value = U.String.insert(value, url + ' ', currentFrom, currentFrom);
@@ -2040,7 +2082,7 @@ const EditorPage = observer(forwardRef<I.BlockRef, Props>((props, ref) => {
20402082
} else {
20412083
to = currentTo;
20422084
};
2043-
2085+
20442086
marks.push({ type: I.MarkType.Link, range: { from: currentFrom, to }, param: url });
20452087

20462088
U.Data.blockSetText(rootId, block.id, value, marks, true, () => {
@@ -2050,7 +2092,7 @@ const EditorPage = observer(forwardRef<I.BlockRef, Props>((props, ref) => {
20502092
break;
20512093
};
20522094

2053-
case 'block': {
2095+
case 'bookmark': {
20542096
const bookmark = S.Record.getBookmarkType();
20552097

20562098
C.BlockBookmarkCreateAndFetch(rootId, focused, position, url, bookmark?.defaultTemplateId, (message: any) => {

src/ts/component/menu/select.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,6 @@ const MenuSelect = observer(forwardRef<I.MenuRef, I.Menu>((props, ref) => {
368368
/>
369369
) : ''}
370370

371-
{menuLabel ? (
372-
<Label className="menuLabel" text={menuLabel} />
373-
) : ''}
374-
375371
<div className="items">
376372
{content}
377373
</div>

src/ts/component/popup/shortcut.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ const PopupShortcut = forwardRef<{}, I.Popup>((props, ref) => {
310310
const item = J.Shortcut.getItems()[editingId];
311311

312312
let menuLabel = U.String.sprintf(translate('popupShortcutConflict'), conflict.symbols.join(''), conflict.name);
313-
let options = [
313+
let options: any[] = [
314314
{ id: 'override', name: translate('popupShortcutOverride') },
315315
{ id: 'reset', name: translate('commonRemove') },
316316
];
@@ -332,6 +332,8 @@ const PopupShortcut = forwardRef<{}, I.Popup>((props, ref) => {
332332
keyboard.setShortcutEditing(false);
333333
window.clearTimeout(timeout.current);
334334

335+
options.unshift({ name: menuLabel, isSection: true });
336+
335337
S.Menu.open('select', {
336338
element: `#${getId()} #item-${editingId}`,
337339
horizontal: I.MenuDirection.Center,
@@ -344,7 +346,6 @@ const PopupShortcut = forwardRef<{}, I.Popup>((props, ref) => {
344346
},
345347
data: {
346348
options,
347-
menuLabel,
348349
noVirtualisation: true,
349350
onSelect: (e, item) => {
350351
updated = true;

src/ts/lib/focus.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class Focus {
4747
};
4848
this.backup = U.Common.objectCopy(this.state);
4949

50-
console.log('Focus set:', JSON.stringify(this.state, null, 3));
51-
console.trace();
52-
5350
C.BlockSetCarriage(keyboard.getRootId(), id, range);
5451
return this;
5552
};

0 commit comments

Comments
 (0)