Skip to content

Commit

Permalink
Merge branch 'hotfix/3.19.67'
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Jul 17, 2024
2 parents 0c2b289 + b992276 commit 835dcc2
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 47 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "worldbrain-extension",
"version": "3.19.66",
"version": "3.19.67",
"homepage": "https://memex.garden",
"repository": "https://github.com/WorldBrain/Memex",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion src/background-script/html-to-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ export function htmlToMarkdown(
if (!html?.length) {
return ''
}

const { document: doc } = parseHTML(html)

const turndownService = new TurndownService({
headingStyle: 'atx',
hr: '---',
codeBlockStyle: 'fenced',
})

applyCustomRules?.(turndownService)
const markdown = turndownService.turndown(doc)

let markdown = turndownService.turndown(doc)

// Replace escaped double brackets with unescaped double brackets
markdown = markdown.replace(/\\\[\\\[/g, '[[')
markdown = markdown.replace(/\\\]\\\]/g, ']]')

return markdown
}
13 changes: 1 addition & 12 deletions src/common-ui/components/prompt-templates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import TutorialBox from '../../../../external/@worldbrain/memex-common/ts/common
import styled, { css } from 'styled-components'
import Icon from '../../../../external/@worldbrain/memex-common/ts/common-ui/components/icon'
import ReactDOM from 'react-dom'
import TextField from '@worldbrain/memex-common/lib/common-ui/components/text-field'
import TextArea from '@worldbrain/memex-common/lib/common-ui/components/text-area'
import { getKeyName } from '@worldbrain/memex-common/lib/utils/os-specific-key-names'

Expand Down Expand Up @@ -101,17 +100,6 @@ export default class PromptTemplatesComponent extends UIElement<
getRootElement={this.props.getRootElement}
tutorialId={'useTemplates'}
/>
{/* <Icon
filePath={icons.helpIcon}
heightAndWidth="18px"
padding={'5px'}
onClick={() =>
window.open(
'https://links.memex.garden/tutorials/text-exporter',
)
}
/> */}

<PrimaryAction
label={'New'}
onClick={() =>
Expand Down Expand Up @@ -430,6 +418,7 @@ export default class PromptTemplatesComponent extends UIElement<

const TextAreaContainer = styled.div`
position: relative;
margin-top: 3px;
`
const TextAreaSaveButton = styled.div`
position: absolute;
Expand Down
22 changes: 12 additions & 10 deletions src/common-ui/components/prompt-templates/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from './types'
import { UIEventHandler, UILogic } from 'ui-logic-core'
import { AI_PROMPT_DEFAULTS } from 'src/sidebar/annotations-sidebar/constants'
import { marked } from 'marked'

type EventHandler<
EventName extends keyof PromptTemplatesEvent
Expand Down Expand Up @@ -94,7 +95,7 @@ export default class PromptTemplatesLogic extends UILogic<
const currentTemplates = previousState.promptTemplatesArray

this.dependencies.onTemplateSelect(
currentTemplates[selectedTemplate].text,
marked.parse(currentTemplates[selectedTemplate].text),
)
}
setTemplateEdit: EventHandler<'setTemplateEdit'> = async ({
Expand All @@ -105,17 +106,18 @@ export default class PromptTemplatesLogic extends UILogic<
const currentTemplates = previousState.promptTemplatesArray
const editValue =
event.value || currentTemplates[selectedTemplate]?.text
const updatedTemplates = currentTemplates?.map((template, index) => {
if (index === selectedTemplate) {
return { ...template, isEditing: editValue }

if (currentTemplates[selectedTemplate]) {
currentTemplates[selectedTemplate] = {
...currentTemplates[selectedTemplate],
isEditing: editValue,
}
return template
})

this.emitMutation({
promptTemplatesArray: { $set: updatedTemplates },
editValue: { $set: editValue },
})
this.emitMutation({
promptTemplatesArray: { $set: currentTemplates },
editValue: { $set: editValue },
})
}
}

saveEditTemplate: EventHandler<'saveEditTemplate'> = async ({
Expand Down
17 changes: 13 additions & 4 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,6 @@ export async function main(
})
anchor = { quote, descriptor }
}
if (quote?.length === 0 && !drawRectangle) {
highlightCreateState = 'success'
return
}

if (
!(await pageActionAllowed(
Expand All @@ -652,6 +648,19 @@ export async function main(
return
}

if (
(quote?.length === 0 || !selection) &&
window.location.href.includes('youtube.com')
) {
await inPageUI.showSidebar({
action: 'youtube_timestamp',
})
return
} else if (quote?.length === 0 && !drawRectangle) {
highlightCreateState = 'success'
return
}

const highlightColorSettingStorage = await getHighlightColorSettings()
const highlightColor = color ?? highlightColorSettingStorage[0].id

Expand Down
1 change: 0 additions & 1 deletion src/copy-paster/components/TemplateEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export default class TemplateEditor extends PureComponent<

renderPremadeTemplatesList() {
if (this.state.showPremadeTemplatesModal) {
console.log('render')
return (
<PopoutBox
getPortalRoot={this.props.getRootElement}
Expand Down
14 changes: 4 additions & 10 deletions src/in-page-ui/keyboard-shortcuts/content_script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,10 @@ function getShortcutHandlers({
return
},
createHighlight: async () => {
const isYouTube = isUrlYTVideo(window.location.href)

if (isYouTube) {
await annotationFunctions.createYoutubeTimestamp()
} else {
await annotationFunctions.createHighlight(
cloneSelectionAsPseudoObject(window.getSelection()),
null,
)
}
await annotationFunctions.createHighlight(
cloneSelectionAsPseudoObject(window.getSelection()),
null,
)

inPageUI.hideTooltip()
},
Expand Down
11 changes: 8 additions & 3 deletions src/readwise-integration/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,14 @@ export class ReadwiseBackground {
return null
}

return annotationToReadwise(annotation, {
pageData,
})
const annotationForReadWise = await annotationToReadwise(
annotation,
{
pageData,
},
)

return annotationForReadWise
} catch (e) {
console.error(e)
Raven.captureException(e)
Expand Down
13 changes: 9 additions & 4 deletions src/sidebar/annotations-sidebar/containers/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,13 @@ export class SidebarContainerLogic extends UILogic<
if (
this.options.windowAPI.location.href.includes('youtube.com/watch')
) {
const sidebarContainerWidth = document.getElementById('secondary')
.clientWidth
const sidebarWidthNumber = parseFloat(
SIDEBAR_WIDTH_STORAGE_KEY.replace('px', ''),
)
const sidebarContainerWidth =
document.getElementById('secondary')?.clientWidth ??
sidebarWidthNumber

sidebarWidth = sidebarContainerWidth - 50 + 'px'
}

Expand Down Expand Up @@ -3542,7 +3547,7 @@ export class SidebarContainerLogic extends UILogic<
isEditing: null,
isFocused: false,
}))
prompt = syncsettings[0].text
prompt = marked.parse(syncsettings[0].text)
}

if (event.textToProcess) {
Expand Down Expand Up @@ -3580,7 +3585,7 @@ export class SidebarContainerLogic extends UILogic<
isEditing: null,
isFocused: false,
}))
prompt = syncsettings[0].text
prompt = marked.parse(syncsettings[0].text)
}

let retries = 0
Expand Down

0 comments on commit 835dcc2

Please sign in to comment.