Skip to content

Commit bb713d7

Browse files
Merge branch 'hotfix/3.20.2'
2 parents 8fcff7d + 25eab1c commit bb713d7

File tree

12 files changed

+124
-35
lines changed

12 files changed

+124
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "worldbrain-extension",
3-
"version": "3.20.1",
3+
"version": "3.20.2",
44
"homepage": "https://memex.garden",
55
"repository": "https://github.com/WorldBrain/Memex",
66
"scripts": {

src/content-scripts/content_script/global.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,10 @@ export async function main(
11911191
deleteAnnotation: async (annotationId) => {
11921192
await annotationsFunctions.deleteAnnotation(annotationId)
11931193
},
1194+
tooltip: {
1195+
getState: tooltipUtils.getTooltipState,
1196+
setState: tooltipUtils.setTooltipState,
1197+
},
11941198
annotationsBG,
11951199
annotationsCache,
11961200
contentSharingBG,
@@ -1448,6 +1452,11 @@ export async function main(
14481452
}),
14491453
askAI: annotationsFunctions.askAI(),
14501454
createYoutubeTimestamp: annotationsFunctions.createYoutubeTimestamp,
1455+
tooltip: {
1456+
getState: tooltipUtils.getTooltipState,
1457+
setState: tooltipUtils.setTooltipState,
1458+
},
1459+
shouldInitTooltip: areHighlightsEnabled,
14511460
})
14521461

14531462
// 9. Check for page activity status

src/custom-lists/ui/CollectionPicker/components/SearchInput.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ export class PickerSearchInput extends React.Component<Props, State> {
5252
value={this.props.value}
5353
onChange={this.onChange}
5454
onKeyDown={(e) => {
55-
this.props.onKeyDown(e)
5655
e.stopPropagation()
56+
this.props.onKeyDown(e)
57+
}}
58+
onKeyUp={(event) => {
59+
event.stopPropagation()
5760
}}
5861
type={'input'}
5962
componentRef={this.props.searchInputRef}

src/custom-lists/ui/CollectionPicker/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class SpacePicker extends StatefulUIElement<
140140
}
141141

142142
private handleKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {
143+
event.stopPropagation()
143144
this.processEvent('keyPress', { event })
144145
}
145146

@@ -863,7 +864,9 @@ class SpacePicker extends StatefulUIElement<
863864
this.state.selectedListIds.length === 0
864865
}
865866
onChange={this.handleSearchInputChanged}
866-
onKeyDown={this.handleKeyPress}
867+
onKeyDown={(event) => {
868+
this.handleKeyPress(event)
869+
}}
867870
value={this.state.query}
868871
autoFocus={
869872
this.state.listIdToShowNewChildInput ||

src/custom-lists/ui/CollectionPicker/logic.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ export default class SpacePickerLogic extends UILogic<
538538
event: { event },
539539
previousState,
540540
}) => {
541+
event.stopPropagation()
541542
if (event.key === 'Enter') {
542543
const isCmdKey = event.metaKey || event.ctrlKey
543544
await this.handleEnterKeyPress(previousState, isCmdKey)
@@ -574,8 +575,6 @@ export default class SpacePickerLogic extends UILogic<
574575
this.dependencies.closePicker(event)
575576
return
576577
}
577-
578-
event.stopPropagation()
579578
}
580579

581580
openListInWebUI: EventHandler<'openListInWebUI'> = async ({ event }) => {

src/custom-lists/ui/space-edit-menu/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ export default class SpaceEditMenuContainer extends StatefulUIElement<
147147
onKeyDown={
148148
this.handleNameEditInputKeyDown
149149
}
150+
onKeyUp={(event) => {
151+
event.stopPropagation()
152+
}}
150153
autoFocus
151154
/>
152155
</Container>

src/custom-lists/ui/space-email-invites/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ export default class SpaceEmailInvites extends StatefulUIElement<
126126
: null
127127
}
128128
onKeyDown={this.handleAddInviteInputKeyDown}
129+
onKeyUp={(event) => {
130+
event.stopPropagation()
131+
}}
129132
/>
130133
{this.shouldShowInviteBtn &&
131134
this.state.emailInvitesCreateState !== 'running' &&

src/in-page-ui/ribbon/react/containers/ribbon/logic.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,15 +1063,13 @@ export class RibbonContainerLogic extends UILogic<
10631063

10641064
setState(!currentSetting)
10651065
try {
1066+
await this.dependencies.tooltip.setState(!currentSetting)
10661067
if (currentSetting === true) {
10671068
await this.dependencies.inPageUI.removeTooltip()
10681069
} else {
1069-
await this.dependencies.tooltip.setState(!currentSetting)
10701070
await this.dependencies.inPageUI.toggleTooltip()
1071-
10721071
await this.dependencies.inPageUI.showTooltip()
10731072
}
1074-
await this.dependencies.tooltip.setState(!currentSetting)
10751073
} catch (err) {
10761074
setState(!currentSetting)
10771075
throw err

src/in-page-ui/shared-state/shared-in-page-ui-state.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ export class SharedInPageUIState implements SharedInPageUIInterface {
267267
}
268268

269269
async showTooltip(options?: ToolTipActionOptions) {
270+
if (this.componentsSetUp.tooltip) {
271+
await this.options.loadComponent('tooltip')
272+
}
273+
270274
const maybeEmitAction = () => {
271275
if (options) {
272276
this._emitAction({
@@ -275,12 +279,6 @@ export class SharedInPageUIState implements SharedInPageUIInterface {
275279
})
276280
}
277281
}
278-
279-
if (this.componentsShown.tooltip) {
280-
maybeEmitAction()
281-
return
282-
}
283-
284282
await this._setState('tooltip', true)
285283
maybeEmitAction()
286284
return
@@ -320,7 +318,10 @@ export class SharedInPageUIState implements SharedInPageUIInterface {
320318
}
321319

322320
private async _setState(component: InPageUIComponent, visible: boolean) {
323-
if (this.componentsShown[component] === visible) {
321+
if (
322+
this.componentsShown[component] === visible &&
323+
component !== 'tooltip'
324+
) {
324325
return
325326
}
326327

src/in-page-ui/tooltip/content_script/components/index.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { cloneSelectionAsPseudoObject } from '@worldbrain/memex-common/lib/annot
4848

4949
interface TooltipRootProps {
5050
mount: InPageUIRootMount
51-
params: Omit<Props, 'onTooltipInit'>
51+
params: Props
5252
onTooltipInit: (showTooltip: () => void) => void
5353
toggleTooltipState: (state: boolean) => Promise<void>
5454
analyticsBG: AnalyticsCoreInterface
@@ -72,6 +72,11 @@ interface TooltipRootProps {
7272
preventHideTooltip?: boolean,
7373
): Promise<any | null>
7474
getWindow: () => Window
75+
tooltip: {
76+
getState: () => void
77+
setState: (tooltipValue: boolean) => void
78+
}
79+
shouldInitTooltip: boolean
7580
}
7681

7782
interface TooltipRootState {
@@ -369,12 +374,23 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
369374
saveAnnotation = async (
370375
commentState: string,
371376
color?: HighlightColor['id'],
377+
unifiedId?: string,
378+
dontUpdateState?: boolean,
372379
) => {
373-
const currentAnnotation = this.state.currentAnnotation
380+
let currentAnnotation = undefined
381+
let comment = commentState
382+
383+
if (unifiedId) {
384+
currentAnnotation = this.props.annotationsCache.annotations.byId[
385+
unifiedId
386+
]
387+
} else {
388+
currentAnnotation = this.state.currentAnnotation
389+
}
390+
374391
const existingHighlight = this.props.annotationsCache.annotations.byId[
375392
currentAnnotation.unifiedId
376393
]
377-
const comment = commentState
378394

379395
this.props.annotationsCache.updateAnnotation(
380396
{
@@ -408,6 +424,10 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
408424
} catch (err) {
409425
console.log(err)
410426
}
427+
428+
if (dontUpdateState) {
429+
return
430+
}
411431
this.setState({
412432
currentAnnotation: {
413433
...currentAnnotation,
@@ -533,6 +553,8 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
533553
}
534554
showColorPicker={this.state.showColorPicker}
535555
toggleTooltipState={props.toggleTooltipState}
556+
tooltip={props.params.tooltip}
557+
shouldInitTooltip={props.shouldInitTooltip}
536558
/>
537559
</ThemeProvider>
538560
</StyleSheetManager>
@@ -566,6 +588,8 @@ export function setupUIContainer(
566588
createHighlight={params.createHighlight}
567589
getWindow={params.getWindow}
568590
toggleTooltipState={props.toggleTooltipState}
591+
tooltip={params.tooltip}
592+
shouldInitTooltip={params.shouldInitTooltip}
569593
/>,
570594
mount.rootElement,
571595
)

src/in-page-ui/tooltip/content_script/interactions.ts

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ let manualOverride = false
5757

5858
let removeTooltipStateChangeListener: () => void
5959

60+
let shouldInitTooltip = true // You can set this based on your conditions
61+
62+
export const setShouldInitTooltip = (value: boolean) => {
63+
shouldInitTooltip = value
64+
}
65+
6066
interface TooltipInsertDependencies extends TooltipDependencies {
6167
mount: InPageUIRootMount
6268
}
@@ -103,6 +109,7 @@ export const insertTooltip = async (params: TooltipInsertDependencies) => {
103109
askAI: shortcutToKeyStrs(state.askAI),
104110
}
105111
},
112+
106113
onTooltipHide: () => params.inPageUI.hideTooltip(),
107114
onTooltipClose: () => params.inPageUI.removeTooltip(),
108115
toggleTooltipState: async (state: boolean) => {
@@ -154,7 +161,13 @@ export const insertTooltip = async (params: TooltipInsertDependencies) => {
154161
params.inPageUI.events.on(
155162
'tooltipAction',
156163
(event, callback) => {
157-
handleExternalAction(event, callback)
164+
if (event.annotationCacheId || event.openForSpaces) {
165+
handleExternalAction(event, callback)
166+
callback(true)
167+
} else {
168+
setShouldInitTooltip(true)
169+
}
170+
158171
callback(true)
159172
},
160173
)
@@ -186,6 +199,11 @@ export const insertTooltip = async (params: TooltipInsertDependencies) => {
186199
// Placeholder function, replace with actual implementation
187200
},
188201
openImageInPreview: async (src: string) => null,
202+
tooltip: {
203+
getState: params.tooltip.getState,
204+
setState: params.tooltip.setState,
205+
},
206+
shouldInitTooltip: shouldInitTooltip,
189207
},
190208
{
191209
annotationsBG: params.annotationsBG,
@@ -203,9 +221,13 @@ export const insertTooltip = async (params: TooltipInsertDependencies) => {
203221
createHighlight: params.createHighlight,
204222
getWindow: () => window,
205223
toggleTooltipState: params.toggleTooltipState,
224+
tooltip: {
225+
getState: params.tooltip.getState,
226+
setState: params.tooltip.setState,
227+
},
228+
shouldInitTooltip: shouldInitTooltip,
206229
},
207230
)
208-
209231
setupTooltipTrigger(() => {
210232
params.inPageUI.showTooltip()
211233
}, null)
@@ -279,16 +301,35 @@ export const removeTooltip = (options?: { override?: boolean }) => {
279301
// }
280302

281303
export const showContentTooltip = async (params: TooltipInsertDependencies) => {
282-
if (!showTooltip) {
304+
if (showTooltip == null) {
283305
await insertTooltip(params)
284306
}
285307

286-
if (userSelectedText()) {
287-
const position = calculateTooltipPostion()
288-
showTooltip(position)
308+
// There seems to be a race condition with the tooltip setup function to get the "showtooltip" function
309+
// This is a temporary fix to keep trying to get the showtooltip function until it is available
310+
311+
let attempts = 0
312+
const maxAttempts = 20 // 5 seconds total
313+
const baseDelay = 50
314+
315+
while (showTooltip == null && attempts < maxAttempts) {
316+
await new Promise((resolve) =>
317+
setTimeout(resolve, baseDelay * Math.pow(1.5, attempts)),
318+
)
319+
320+
attempts++
321+
}
322+
323+
if (showTooltip == null) {
324+
console.error(
325+
'Failed to initialize showTooltip after multiple attempts',
326+
)
327+
return
289328
}
290-
}
291329

330+
const position = calculateTooltipPosition()
331+
showTooltip(position)
332+
}
292333
/**
293334
* Checks for certain conditions before triggering the tooltip.
294335
* i) Whether the selection made by the user is just text.
@@ -325,7 +366,7 @@ export const conditionallyTriggerTooltip = delayed(
325366
// } else if (positioning === 'mouse' && event) {
326367
// position = calculateTooltipPostion()
327368
// }
328-
position = calculateTooltipPostion()
369+
position = calculateTooltipPosition()
329370
analytics.trackEvent({
330371
category: 'InPageTooltip',
331372
action: 'showTooltip',
@@ -340,17 +381,22 @@ export const conditionallyTriggerTooltip = delayed(
340381
10,
341382
)
342383

343-
export function calculateTooltipPostion(): TooltipPosition {
344-
const range = document.getSelection().getRangeAt(0)
384+
export function calculateTooltipPosition(): TooltipPosition {
385+
const selection = document.getSelection()
386+
if (!selection || selection.rangeCount === 0) {
387+
// Return a default position if there's no selection
388+
return { x: window.innerWidth / 2, y: window.innerHeight / 2 }
389+
}
390+
391+
const range = selection.getRangeAt(0)
345392
const boundingRect = range.getBoundingClientRect()
346-
// x = position of element from the left + half of it's width
393+
394+
// x = position of element from the left + half of its width
347395
const x = boundingRect.left + boundingRect.width / 2
348-
// y = scroll height from top + pixels from top + height of element - offset
396+
// y = scroll height from top + pixels from top + height of element
349397
const y = window.pageYOffset + boundingRect.top + boundingRect.height
350-
return {
351-
x,
352-
y,
353-
}
398+
399+
return { x, y }
354400
}
355401

356402
function isAnchorOrContentEditable(selected) {

0 commit comments

Comments
 (0)