Skip to content

Commit 762f958

Browse files
Improve a bunch of thingsn on ai chat/spaces/annotations
1 parent 7a06420 commit 762f958

24 files changed

Lines changed: 1915 additions & 1835 deletions

File tree

external/@worldbrain/memex-common

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"watch:prod:mv2": "npm run build:clean && MANIFEST_VERSION=2 webpack --watch --env.prod",
1919
"watch:notif:mv2": "npm run build:clean && MANIFEST_VERSION=2 webpack --watch --env.notifs",
2020
"watch:prod": "npm run build:clean && webpack --watch --env.prod",
21-
"watch:notif": "webpack --watch --env.notifs",
22-
"watch:clean": "npm run cache:clean && npm run watch:notif",
23-
"watch:clean:mv2": "npm run cache:clean && npm run watch:notif:mv2",
21+
"watch:notif": "NODE_OPTIONS=--openssl-legacy-provider webpack --watch --env.notifs",
22+
"watch:clean": "NODE_OPTIONS=--openssl-legacy-provider npm run cache:clean && npm run watch:notif",
23+
"watch:clean:mv2": "NODE_OPTIONS=--openssl-legacy-provider npm run cache:clean && npm run watch:notif:mv2",
2424
"watch:fb-emu": "USE_FIREBASE_EMULATOR=true yarn watch:clean:mv2",
2525
"cache:clean": "rimraf ./node_modules/.cache",
2626
"stats": "webpack --profile -1json > stats.json",
@@ -55,7 +55,6 @@
5555
}
5656
},
5757
"dependencies": {
58-
"@hello-pangea/dnd": "^16.6.0",
5958
"@josephg/resolvable": "^1.0.0",
6059
"@popperjs/core": "^2.11.6",
6160
"@sentry/node": "^6.14.3",
@@ -127,6 +126,7 @@
127126
"qrcode": "^1.4.2",
128127
"query-string": "^4.3.4",
129128
"queue": "^5.0.0",
129+
"range-slider-input": "^2.4.5",
130130
"raven-for-redux": "^1.3.1",
131131
"raven-js": "^3.23.3",
132132
"react": "17.0.0-rc.1",
@@ -210,13 +210,14 @@
210210
"@types/pdfjs-dist": "^2.1.6",
211211
"@types/pg": "^8.6.5",
212212
"@types/qrcode": "^1.3.4",
213-
"@types/react": "^17.0.0",
213+
"@types/react": "^17.0.80",
214+
"@types/react-dom": "17.0.25",
214215
"@types/react-onclickoutside": "^6.7.3",
215216
"@types/react-redux": "^6.0.6",
216217
"@types/selenium-webdriver": "^4.0.0-alpha.7",
217218
"@types/simple-peer": "^6.1.6",
218219
"@types/sinon": "^7.0.3",
219-
"@types/styled-components": "^5.1.4",
220+
"@types/styled-components": "^5.1.25",
220221
"@types/tinycolor2": "^1.4.4",
221222
"@types/turndown": "^5.0.4",
222223
"@types/url-regex": "^4.1.0",
@@ -228,7 +229,7 @@
228229
"babel-jest": "^28.1.1",
229230
"babel-loader": "^8.1.0",
230231
"babel-register": "^6.26.0",
231-
"better-sqlite3": "^7.5.3",
232+
"better-sqlite3": "^12.5.0",
232233
"cheerio": "^1.0.0-rc.12",
233234
"chrome-webstore-upload": "^0.2.2",
234235
"copy-webpack-plugin": "^4.5.1",

src/annotations/components/AnnotationEditable.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ export default class AnnotationEditable extends React.Component<Props, State> {
283283
prevProps.highlightColorSettings !=
284284
this.props.highlightColorSettings
285285
) {
286-
const defaultHighlightSettings = this.props.highlightColorSettings.find(
287-
(setting) => setting.id === 'default',
288-
)
286+
const defaultHighlightSettings =
287+
this.props.highlightColorSettings.find(
288+
(setting) => setting.id === 'default',
289+
)
289290
if (defaultHighlightSettings?.color) {
290291
this.setState({
291292
defaultHighlightColor: defaultHighlightSettings.color,
@@ -374,9 +375,8 @@ export default class AnnotationEditable extends React.Component<Props, State> {
374375
// this.props.onRemoveFromListBtnClick(event as any)
375376
} else {
376377
// Perform action for "Enter" key
377-
const {
378-
annotationFooterDependencies: footerDeps,
379-
} = this.props
378+
const { annotationFooterDependencies: footerDeps } =
379+
this.props
380380
event.stopPropagation()
381381
footerDeps.onDeleteIconClick(event as any)
382382
break
@@ -507,8 +507,8 @@ export default class AnnotationEditable extends React.Component<Props, State> {
507507
ref={this.highlightsBarRef}
508508
onClick={() =>
509509
this.setState({
510-
showHighlightColorPicker: !this.state
511-
.showHighlightColorPicker,
510+
showHighlightColorPicker:
511+
!this.state.showHighlightColorPicker,
512512
})
513513
}
514514
barColor={barColor}
@@ -977,7 +977,7 @@ export default class AnnotationEditable extends React.Component<Props, State> {
977977
template.
978978
</span>
979979
),
980-
ButtonText: 'Cite',
980+
ButtonText: 'Share',
981981
active:
982982
this.props.copyPasterAnnotationInstanceId ===
983983
this.props.unifiedId,
@@ -1479,9 +1479,9 @@ export default class AnnotationEditable extends React.Component<Props, State> {
14791479
this.spacePickerBodyButtonRef,
14801480
'lists-bar',
14811481
)} */}
1482-
<AutoAddButtonContainer>
1482+
{/* <AutoAddButtonContainer>
14831483
{this.renderAutoAddedIndicator()}
1484-
</AutoAddButtonContainer>
1484+
</AutoAddButtonContainer> */}
14851485
</AnnotationBox>
14861486
{this.state.showQuickTutorial && (
14871487
<PopoutBox
@@ -1772,7 +1772,7 @@ const HighlightActionsBox = styled.div<{}>`
17721772
top: 0px;
17731773
grid-gap: 5px;
17741774
background: ${(props) => props.theme.colors.black}95;
1775-
padding: 5px;
1775+
padding: 2px;
17761776
17771777
backdrop-filter: blur(5px);
17781778
border-radius: 8px;
@@ -1810,8 +1810,8 @@ const NoteText = styled(Markdown)`
18101810
const ActionBox = styled.div`
18111811
z-index: 100000;
18121812
position: absolute;
1813-
right: 15px;
1814-
top: 15px;
1813+
right: 5px;
1814+
top: 5px;
18151815
`
18161816

18171817
const HighlightStyled = styled.div<{ hasComment: boolean }>`
@@ -2011,7 +2011,7 @@ const CreationInfoBox = styled.div`
20112011
display: flex;
20122012
align-items: center;
20132013
grid-gap: 10px;
2014-
padding-left: 30px;
2014+
padding-left: 5px;
20152015
margin-bottom: -2px;
20162016
`
20172017

src/common-ui/components/prompt-templates/index.tsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ export default class PromptTemplatesComponent extends UIElement<
303303
'setTemplateEdit',
304304
{
305305
id: index,
306-
value: (event.target as HTMLTextAreaElement)
306+
value: (
307+
event.target as HTMLTextAreaElement
308+
)
307309
.value,
308310
},
309311
)
@@ -323,7 +325,9 @@ export default class PromptTemplatesComponent extends UIElement<
323325
event.metaKey
324326
) {
325327
if (
326-
(event.target as HTMLTextAreaElement)
328+
(
329+
event.target as HTMLTextAreaElement
330+
)
327331
.value
328332
.length >
329333
0
@@ -333,7 +337,9 @@ export default class PromptTemplatesComponent extends UIElement<
333337
'saveEditTemplate',
334338
{
335339
id: index,
336-
text: (event.target as HTMLTextAreaElement)
340+
text: (
341+
event.target as HTMLTextAreaElement
342+
)
337343
.value,
338344
},
339345
)
@@ -343,6 +349,16 @@ export default class PromptTemplatesComponent extends UIElement<
343349
'Enter'
344350
) {
345351
// Allow Enter to function normally for new lines
352+
} else if (
353+
event.key ===
354+
'Escape'
355+
) {
356+
this.processEvent(
357+
'cancelEditTemplate',
358+
{
359+
id: index,
360+
},
361+
)
346362
} else {
347363
// Handle other keys if needed
348364
}
@@ -360,12 +376,13 @@ export default class PromptTemplatesComponent extends UIElement<
360376
fontSize="12px"
361377
padding="2px 4px;"
362378
onClick={() => {
363-
let content = this
364-
.state
365-
.promptTemplatesArray[
366-
index
367-
]
368-
.isEditing
379+
let content =
380+
this
381+
.state
382+
.promptTemplatesArray[
383+
index
384+
]
385+
.isEditing
369386

370387
if (
371388
content !=
@@ -483,7 +500,7 @@ const Title = styled.div`
483500
`
484501

485502
const ContentBlock = styled.div`
486-
padding: 0 5px 5px 5px;
503+
padding: 0 10px 5px 10px;
487504
width: 100%;
488505
box-sizing: border-box;
489506
display: flex;
@@ -602,7 +619,8 @@ const Row = styled.div<{
602619
}
603620
604621
&:hover {
605-
${ActionsContainer} { // if DeleteButtonContainer is not under an hovered ContainerSection
622+
${ActionsContainer} {
623+
// if DeleteButtonContainer is not under an hovered ContainerSection
606624
display: flex;
607625
}
608626
}
@@ -616,8 +634,6 @@ const Row = styled.div<{
616634
css`
617635
outline: 1px solid ${(props) => props.theme.colors.greyScale3};
618636
`}
619-
620-
621637
`
622638

623639
const TemplateRowTitle = styled.div<{

src/common-ui/components/prompt-templates/logic.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import { UIEventHandler, UILogic } from 'ui-logic-core'
1212
import { AI_PROMPT_DEFAULTS } from 'src/sidebar/annotations-sidebar/constants'
1313
import { marked } from 'marked'
1414

15-
type EventHandler<
16-
EventName extends keyof PromptTemplatesEvent
17-
> = UIEventHandler<PromptTemplatesState, PromptTemplatesEvent, EventName>
15+
type EventHandler<EventName extends keyof PromptTemplatesEvent> =
16+
UIEventHandler<PromptTemplatesState, PromptTemplatesEvent, EventName>
1817

1918
export default class PromptTemplatesLogic extends UILogic<
2019
PromptTemplatesState,
@@ -150,6 +149,44 @@ export default class PromptTemplatesLogic extends UILogic<
150149
updatedTemplates,
151150
)
152151
}
152+
cancelEditTemplate: EventHandler<'cancelEditTemplate'> = async ({
153+
event,
154+
previousState,
155+
}) => {
156+
const currentTemplates = previousState.promptTemplatesArray
157+
const templateBeingEdited = currentTemplates[event.id]
158+
const editValue =
159+
templateBeingEdited?.isEditing ?? previousState.editValue
160+
161+
// If the template is empty (or just whitespace), remove it
162+
if (!editValue || editValue.trim().length === 0) {
163+
const updatedTemplates = currentTemplates.filter(
164+
(_, index) => index !== event.id,
165+
)
166+
167+
this.emitMutation({
168+
promptTemplatesArray: { $set: updatedTemplates },
169+
editValue: { $set: null },
170+
})
171+
172+
// Save the updated list of templates
173+
await this.syncSettings.openAI.set(
174+
'promptSuggestions',
175+
updatedTemplates,
176+
)
177+
} else {
178+
// Otherwise, just cancel the edit
179+
const updatedTemplates = [...currentTemplates]
180+
updatedTemplates[event.id] = {
181+
...currentTemplates[event.id],
182+
isEditing: null,
183+
}
184+
this.emitMutation({
185+
promptTemplatesArray: { $set: updatedTemplates },
186+
editValue: { $set: null },
187+
})
188+
}
189+
}
153190
startNewTemplate: EventHandler<'startNewTemplate'> = async ({
154191
event,
155192
previousState,

src/common-ui/components/prompt-templates/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type PromptTemplatesEvent = UIEvent<{
2020
focusTemplate: { id: number }
2121
setTemplateEdit: { id: number; value: string }
2222
saveEditTemplate: { id: number; text: string }
23+
cancelEditTemplate: { id: number }
2324
startNewTemplate: { text: string }
2425
deleteTemplate: { id: number }
2526
reorderTemplates: { oldIndex: number; newIndex: number }

src/content-scripts/content_script/in-page-ui-injections.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,39 @@ export const main: InPageUIInjectionsMain = async ({
6161
options.imageElements,
6262
options.contentScriptsBG,
6363
)
64-
} else if (component === 'search-engine-integration') {
65-
const url = window.location.href
66-
const matched = utils.matchURL(url) as SearchEngineName | false
64+
}
65+
// else if (component === 'search-engine-integration') {
66+
// const url = window.location.href
67+
// const matched = utils.matchURL(url) as SearchEngineName | false
6768

68-
if (matched) {
69-
const searchInjection =
70-
(await syncSettings.searchInjection.get(
71-
'searchEnginesEnabled',
72-
)) ?? constants.SEARCH_INJECTION_DEFAULT
73-
if (searchInjection[matched]) {
74-
try {
75-
const query = utils.fetchQuery(url)
69+
// if (matched) {
70+
// const searchInjection =
71+
// (await syncSettings.searchInjection.get(
72+
// 'searchEnginesEnabled',
73+
// )) ?? constants.SEARCH_INJECTION_DEFAULT
74+
// if (searchInjection[matched]) {
75+
// try {
76+
// const query = utils.fetchQuery(url)
7677

77-
await handleRenderSearchInjection(
78-
query,
79-
matched,
80-
syncSettings,
81-
() =>
82-
searchDisplayProps.bgScriptBG.openOptionsTab(
83-
{
84-
query: 'settings',
85-
},
86-
),
87-
searchDisplayProps.searchBG,
88-
searchDisplayProps.openPDFinViewer,
89-
)
90-
} catch (err) {
91-
console.error(err)
92-
}
93-
}
94-
}
95-
}
78+
// await handleRenderSearchInjection(
79+
// query,
80+
// matched,
81+
// syncSettings,
82+
// () =>
83+
// searchDisplayProps.bgScriptBG.openOptionsTab(
84+
// {
85+
// query: 'settings',
86+
// },
87+
// ),
88+
// searchDisplayProps.searchBG,
89+
// searchDisplayProps.openPDFinViewer,
90+
// )
91+
// } catch (err) {
92+
// console.error(err)
93+
// }
94+
// }
95+
// }
96+
// }
9697
},
9798
)
9899
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ export const AddNew = styled.div`
6464
justify-content: center;
6565
align-items: center;
6666
color: ${(props) => props.theme.colors.black};
67-
background: ${(props) => props.theme.colors.white};
67+
/* background: ${(props) => props.theme.colors.white}; */
6868
font-size: ${fontSizeSmall}px;
6969
font-weight: 500;
7070
min-height: 20px;
7171
height: fit-content;
72-
padding: 8px 20px;
72+
padding: 3px 20px;
7373
word-break: break-word;
7474
cursor: pointer;
7575
border-radius: 5px;

0 commit comments

Comments
 (0)