refactor: add markdown visual editor source (#1088)
This commit is contained in:
@@ -19,3 +19,6 @@ packageExtensions:
|
||||
"@types/react-transition-group@*":
|
||||
peerDependencies:
|
||||
"@types/react": "*"
|
||||
"react-dev-utils@*":
|
||||
peerDependencies:
|
||||
"react-error-overlay": "*"
|
||||
@@ -9,6 +9,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn workspaces foreach --parallel run build",
|
||||
"lint": "yarn workspaces foreach --parallel run lint",
|
||||
"version": "node scripts/package-components.mjs && git add dist && git commit -m 'chore(release): components'"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
.env
|
||||
coverage
|
||||
node_modules
|
||||
ext.json
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"trailingComma": "es5",
|
||||
"jsxSingleQuote": false
|
||||
}
|
||||
@@ -6,18 +6,8 @@
|
||||
"Standard Notes",
|
||||
"Standard Notes Extensions"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/standardnotes/advanced-checklist.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/standardnotes/advanced-checklist/issues"
|
||||
},
|
||||
"sn": {
|
||||
"main": "build/index.html"
|
||||
},
|
||||
@@ -39,7 +29,7 @@
|
||||
"server-public": "http-server -p 3000 --cors",
|
||||
"server-root": "http-server ./ -p 3000 --cors",
|
||||
"server": "http-server ./build -p 3000 --cors",
|
||||
"pretty": "prettier --write 'src/**/*.{html,css,scss,js,jsx,ts,tsx,json}' README.md",
|
||||
"lint": "prettier --write 'src/**/*.{html,css,scss,js,jsx,ts,tsx,json}' README.md",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"eslintConfig": {
|
||||
|
||||
@@ -5,10 +5,7 @@ import type { RootState, AppDispatch } from './store'
|
||||
export const useAppDispatch = () => useDispatch<AppDispatch>()
|
||||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
|
||||
|
||||
export const useDidMount = (
|
||||
effect: React.EffectCallback,
|
||||
deps?: React.DependencyList
|
||||
) => {
|
||||
export const useDidMount = (effect: React.EffectCallback, deps?: React.DependencyList) => {
|
||||
const [didMount, setDidMount] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -32,7 +32,7 @@ const actionsWithGroup = isAnyOf(
|
||||
tasksGroupAdded,
|
||||
tasksGroupDeleted,
|
||||
tasksGroupMerged,
|
||||
tasksGroupCollapsed
|
||||
tasksGroupCollapsed,
|
||||
)
|
||||
|
||||
listenerMiddleware.startListening({
|
||||
|
||||
@@ -9,8 +9,7 @@ export const store = configureStore({
|
||||
tasks: tasksReducer,
|
||||
settings: settingsReducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().prepend(listenerMiddleware),
|
||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware().prepend(listenerMiddleware),
|
||||
})
|
||||
|
||||
export type AppDispatch = typeof store.dispatch
|
||||
|
||||
@@ -9,12 +9,8 @@ type CheckBoxInputProps = {
|
||||
|
||||
export const CheckBoxInput = forwardRef<HTMLInputElement, CheckBoxInputProps>(
|
||||
({ checked, disabled, testId, onChange }, ref) => {
|
||||
function onCheckBoxButtonClick({
|
||||
currentTarget,
|
||||
}: React.MouseEvent<SVGElement>) {
|
||||
!checked
|
||||
? currentTarget.classList.add('explode')
|
||||
: currentTarget.classList.remove('explode')
|
||||
function onCheckBoxButtonClick({ currentTarget }: React.MouseEvent<SVGElement>) {
|
||||
!checked ? currentTarget.classList.add('explode') : currentTarget.classList.remove('explode')
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -41,5 +37,5 @@ export const CheckBoxInput = forwardRef<HTMLInputElement, CheckBoxInputProps>(
|
||||
</svg>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -17,10 +17,7 @@ type CircularProgressBarProps = {
|
||||
percentage: number
|
||||
}
|
||||
|
||||
export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
|
||||
size,
|
||||
percentage,
|
||||
}) => {
|
||||
export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({ size, percentage }) => {
|
||||
const [progress, setProgress] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -34,18 +31,8 @@ export const CircularProgressBar: React.FC<CircularProgressBarProps> = ({
|
||||
const dash = (progress * circumference) / 100
|
||||
|
||||
return (
|
||||
<svg
|
||||
height={size}
|
||||
viewBox={viewBox}
|
||||
width={size}
|
||||
data-testid="circular-progress-bar"
|
||||
>
|
||||
<ProgressBarBackground
|
||||
cx={size / 2}
|
||||
cy={size / 2}
|
||||
r={radius}
|
||||
strokeWidth={strokeWidth}
|
||||
/>
|
||||
<svg height={size} viewBox={viewBox} width={size} data-testid="circular-progress-bar">
|
||||
<ProgressBarBackground cx={size / 2} cy={size / 2} r={radius} strokeWidth={strokeWidth} />
|
||||
<ProgressBarStroke
|
||||
cx={size / 2}
|
||||
cy={size / 2}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import '@reach/dialog/styles.css'
|
||||
|
||||
import React, { useRef } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogLabel,
|
||||
AlertDialogDescription,
|
||||
} from '@reach/alert-dialog'
|
||||
import { AlertDialog, AlertDialogLabel, AlertDialogDescription } from '@reach/alert-dialog'
|
||||
|
||||
import { sanitizeHtmlString } from '@standardnotes/utils'
|
||||
|
||||
@@ -32,11 +28,7 @@ export const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
||||
const cancelRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid={testId}
|
||||
onDismiss={cancelButtonCb}
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<AlertDialog data-testid={testId} onDismiss={cancelButtonCb} leastDestructiveRef={cancelRef}>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
|
||||
@@ -17,11 +17,7 @@ type MainTitleProps = {
|
||||
crossed?: boolean
|
||||
}
|
||||
|
||||
export const MainTitle: React.FC<MainTitleProps> = ({
|
||||
children,
|
||||
highlight = false,
|
||||
crossed = false,
|
||||
}) => {
|
||||
export const MainTitle: React.FC<MainTitleProps> = ({ children, highlight = false, crossed = false }) => {
|
||||
return (
|
||||
<Header1 className={`sk-h1 ${highlight ? 'info' : ''}`} crossed={crossed}>
|
||||
{children}
|
||||
|
||||
@@ -3,11 +3,7 @@ type RoundButtonProps = {
|
||||
onClick: () => void
|
||||
}
|
||||
|
||||
export const RoundButton: React.FC<RoundButtonProps> = ({
|
||||
testId,
|
||||
onClick,
|
||||
children,
|
||||
}) => {
|
||||
export const RoundButton: React.FC<RoundButtonProps> = ({ testId, onClick, children }) => {
|
||||
return (
|
||||
<button data-testid={testId} className="sn-icon-button" onClick={onClick}>
|
||||
{children}
|
||||
|
||||
@@ -26,24 +26,8 @@ type TextAreaInputProps = {
|
||||
onKeyUp?: (event: KeyboardEvent<HTMLTextAreaElement>) => void
|
||||
}
|
||||
|
||||
export const TextAreaInput = forwardRef<
|
||||
HTMLTextAreaElement,
|
||||
TextAreaInputProps
|
||||
>(
|
||||
(
|
||||
{
|
||||
value,
|
||||
className,
|
||||
dir = 'auto',
|
||||
disabled,
|
||||
spellCheck,
|
||||
testId,
|
||||
onChange,
|
||||
onKeyPress,
|
||||
onKeyUp,
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
export const TextAreaInput = forwardRef<HTMLTextAreaElement, TextAreaInputProps>(
|
||||
({ value, className, dir = 'auto', disabled, spellCheck, testId, onChange, onKeyPress, onKeyUp }, ref) => {
|
||||
return (
|
||||
<StyledTextArea
|
||||
className={className}
|
||||
@@ -58,5 +42,5 @@ export const TextAreaInput = forwardRef<
|
||||
value={value}
|
||||
/>
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -11,8 +11,7 @@ const StyledInput = styled.input<StyledInputProps>`
|
||||
background-color: unset;
|
||||
border: none;
|
||||
color: var(--sn-stylekit-foreground-color);
|
||||
font-size: ${({ textSize }) =>
|
||||
textSize === 'big' ? '1.125rem' : 'var(--sn-stylekit-font-size-h3)'};
|
||||
font-size: ${({ textSize }) => (textSize === 'big' ? '1.125rem' : 'var(--sn-stylekit-font-size-h3)')};
|
||||
font-weight: ${({ textSize }) => (textSize === 'big' ? '500' : '400')};
|
||||
height: auto;
|
||||
margin: 6px 0 6px 0;
|
||||
@@ -35,14 +34,7 @@ type TextInputProps = {
|
||||
autoFocus?: boolean
|
||||
dir?: 'ltr' | 'rtl' | 'auto'
|
||||
disabled?: boolean
|
||||
enterKeyHint?:
|
||||
| 'enter'
|
||||
| 'done'
|
||||
| 'go'
|
||||
| 'next'
|
||||
| 'previous'
|
||||
| 'search'
|
||||
| 'send'
|
||||
enterKeyHint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'
|
||||
placeholder?: string
|
||||
spellCheck?: boolean
|
||||
testId?: string
|
||||
@@ -68,7 +60,7 @@ export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
|
||||
onChange,
|
||||
onKeyPress,
|
||||
},
|
||||
ref
|
||||
ref,
|
||||
) => {
|
||||
return (
|
||||
<StyledInput
|
||||
@@ -88,5 +80,5 @@ export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
|
||||
value={value}
|
||||
/>
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
export const ChevronDownIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" className="sn-icon block">
|
||||
<path d="M6.17622 7.15015L10.0012 10.9751L13.8262 7.15015L15.0012 8.33348L10.0012 13.3335L5.00122 8.33348L6.17622 7.15015Z" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
export const ChevronUpIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" className="sn-icon block">
|
||||
<path d="M13.826 13.3335L10.001 9.5085L6.17597 13.3335L5.00097 12.1502L10.001 7.15017L15.001 12.1502L13.826 13.3335Z" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
@@ -6,14 +6,7 @@ export const DottedCircleIcon = () => {
|
||||
viewBox="0 0 20 20"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<rect
|
||||
x="0.5"
|
||||
y="0.5"
|
||||
width="19"
|
||||
height="19"
|
||||
rx="9.5"
|
||||
strokeDasharray="2 2"
|
||||
/>
|
||||
<rect x="0.5" y="0.5" width="19" height="19" rx="9.5" strokeDasharray="2 2" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
export const MergeIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" className="sn-icon block">
|
||||
<path d="M8 17L12 13H15.2C15.6 14.2 16.7 15 18 15C19.7 15 21 13.7 21 12C21 10.3 19.7 9 18 9C16.7 9 15.6 9.8 15.2 11H12L8 7V3H3V8H6L10.2 12L6 16H3V21H8V17Z" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
export const RenameIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" className="sn-icon block">
|
||||
<path d="M11.7167 7.5L12.5 8.28333L4.93333 15.8333H4.16667V15.0667L11.7167 7.5ZM14.7167 2.5C14.5083 2.5 14.2917 2.58333 14.1333 2.74167L12.6083 4.26667L15.7333 7.39167L17.2583 5.86667C17.5833 5.54167 17.5833 5 17.2583 4.69167L15.3083 2.74167C15.1417 2.575 14.9333 2.5 14.7167 2.5ZM11.7167 5.15833L2.5 14.375V17.5H5.625L14.8417 8.28333L11.7167 5.15833Z" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
@@ -2,9 +2,7 @@ type ReorderIconProps = {
|
||||
highlight?: boolean
|
||||
}
|
||||
|
||||
export const ReorderIcon: React.FC<ReorderIconProps> = ({
|
||||
highlight = false,
|
||||
}) => {
|
||||
export const ReorderIcon: React.FC<ReorderIconProps> = ({ highlight = false }) => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
export const TrashIcon = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="sn-icon block"
|
||||
>
|
||||
<svg viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" className="sn-icon block">
|
||||
<path d="M7.49992 2.5V3.33333H3.33325V5H4.16659V15.8333C4.16659 16.2754 4.34218 16.6993 4.65474 17.0118C4.9673 17.3244 5.39122 17.5 5.83325 17.5H14.1666C14.6086 17.5 15.0325 17.3244 15.3451 17.0118C15.6577 16.6993 15.8333 16.2754 15.8333 15.8333V5H16.6666V3.33333H12.4999V2.5H7.49992ZM5.83325 5H14.1666V15.8333H5.83325V5ZM7.49992 6.66667V14.1667H9.16658V6.66667H7.49992ZM10.8333 6.66667V14.1667H12.4999V6.66667H10.8333Z" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
@@ -38,8 +38,7 @@ $transition-duration: 750ms;
|
||||
.checkbox-square,
|
||||
.checkbox-mark {
|
||||
cursor: pointer;
|
||||
transition: stroke-dashoffset $transition-duration
|
||||
cubic-bezier(0.9, 0, 0.5, 1);
|
||||
transition: stroke-dashoffset $transition-duration cubic-bezier(0.9, 0, 0.5, 1);
|
||||
}
|
||||
|
||||
.checkbox-circle {
|
||||
|
||||
@@ -2,10 +2,7 @@ import './CheckBoxElementsDefs.scss'
|
||||
|
||||
export const CheckBoxElementsDefs = () => {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 0 0"
|
||||
style={{ position: 'absolute', zIndex: -1, opacity: 0 }}
|
||||
>
|
||||
<svg viewBox="0 0 0 0" style={{ position: 'absolute', zIndex: -1, opacity: 0 }}>
|
||||
<defs>
|
||||
<path
|
||||
id="checkbox-square"
|
||||
|
||||
@@ -229,9 +229,7 @@ describe('getPlainPreview', () => {
|
||||
|
||||
expect(getPlainPreview(groupedTasks)).toBe('2/5 tasks completed')
|
||||
expect(getPlainPreview([])).toBe('0/0 tasks completed')
|
||||
expect(getPlainPreview([{ name: 'Test', tasks: [] }])).toBe(
|
||||
'0/0 tasks completed'
|
||||
)
|
||||
expect(getPlainPreview([{ name: 'Test', tasks: [] }])).toBe('0/0 tasks completed')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { GroupPayload, TaskPayload } from '../features/tasks/tasks-slice'
|
||||
|
||||
export function arrayMoveMutable(
|
||||
array: any[],
|
||||
fromIndex: number,
|
||||
toIndex: number
|
||||
) {
|
||||
export function arrayMoveMutable(array: any[], fromIndex: number, toIndex: number) {
|
||||
const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex
|
||||
if (startIndex >= 0 && startIndex < array.length) {
|
||||
const endIndex = toIndex < 0 ? array.length + toIndex : toIndex
|
||||
@@ -14,11 +10,7 @@ export function arrayMoveMutable(
|
||||
}
|
||||
}
|
||||
|
||||
export function arrayMoveImmutable(
|
||||
array: any[],
|
||||
fromIndex: number,
|
||||
toIndex: number
|
||||
) {
|
||||
export function arrayMoveImmutable(array: any[], fromIndex: number, toIndex: number) {
|
||||
array = [...array]
|
||||
arrayMoveMutable(array, fromIndex, toIndex)
|
||||
return array
|
||||
@@ -43,9 +35,7 @@ export function groupTasksByCompletedStatus(tasks: TaskPayload[]) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getTaskArrayFromGroupedTasks(
|
||||
groupedTasks: GroupPayload[]
|
||||
): TaskPayload[] {
|
||||
export function getTaskArrayFromGroupedTasks(groupedTasks: GroupPayload[]): TaskPayload[] {
|
||||
let taskArray: TaskPayload[] = []
|
||||
|
||||
groupedTasks.forEach((group) => {
|
||||
@@ -124,10 +114,7 @@ export function isJsonString(rawString: string) {
|
||||
return true
|
||||
}
|
||||
|
||||
export function isLastActiveGroup(
|
||||
allGroups: GroupPayload[],
|
||||
groupName: string
|
||||
): boolean {
|
||||
export function isLastActiveGroup(allGroups: GroupPayload[], groupName: string): boolean {
|
||||
if (allGroups.length === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import reducer, {
|
||||
setCanEdit,
|
||||
setIsRunningOnMobile,
|
||||
setSpellCheckerEnabled,
|
||||
} from './settings-slice'
|
||||
import reducer, { setCanEdit, setIsRunningOnMobile, setSpellCheckerEnabled } from './settings-slice'
|
||||
import type { SettingsState } from './settings-slice'
|
||||
|
||||
it('should return the initial state', () => {
|
||||
return expect(
|
||||
reducer(undefined, {
|
||||
type: undefined,
|
||||
})
|
||||
}),
|
||||
).toEqual({
|
||||
canEdit: true,
|
||||
isRunningOnMobile: false,
|
||||
|
||||
@@ -28,6 +28,5 @@ const settingsSlice = createSlice({
|
||||
},
|
||||
})
|
||||
|
||||
export const { setCanEdit, setIsRunningOnMobile, setSpellCheckerEnabled } =
|
||||
settingsSlice.actions
|
||||
export const { setCanEdit, setIsRunningOnMobile, setSpellCheckerEnabled } = settingsSlice.actions
|
||||
export default settingsSlice.reducer
|
||||
|
||||
@@ -10,12 +10,8 @@ const group = 'default group'
|
||||
it('renders two buttons', () => {
|
||||
testRender(<CompletedTasksActions groupName={group} />)
|
||||
|
||||
expect(screen.getByTestId('reopen-completed-button')).toHaveTextContent(
|
||||
'Reopen Completed'
|
||||
)
|
||||
expect(screen.getByTestId('delete-completed-button')).toHaveTextContent(
|
||||
'Delete Completed'
|
||||
)
|
||||
expect(screen.getByTestId('reopen-completed-button')).toHaveTextContent('Reopen Completed')
|
||||
expect(screen.getByTestId('delete-completed-button')).toHaveTextContent('Delete Completed')
|
||||
})
|
||||
|
||||
it('should not render buttons if can not edit', () => {
|
||||
@@ -29,12 +25,8 @@ it('should not render buttons if can not edit', () => {
|
||||
|
||||
testRender(<CompletedTasksActions groupName={group} />, {}, defaultState)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('reopen-completed-button')
|
||||
).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByTestId('delete-completed-button')
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('reopen-completed-button')).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('delete-completed-button')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should dispatch openAllCompleted action', () => {
|
||||
@@ -45,18 +37,14 @@ it('should dispatch openAllCompleted action', () => {
|
||||
|
||||
const confirmDialog = screen.getByTestId('reopen-all-tasks-dialog')
|
||||
expect(confirmDialog).toBeInTheDocument()
|
||||
expect(confirmDialog).toHaveTextContent(
|
||||
`Are you sure you want to reopen completed tasks in the '${group}' group?`
|
||||
)
|
||||
expect(confirmDialog).toHaveTextContent(`Are you sure you want to reopen completed tasks in the '${group}' group?`)
|
||||
|
||||
const confirmButton = screen.getByTestId('confirm-dialog-button')
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
openAllCompleted({ groupName: group })
|
||||
)
|
||||
expect(dispatchedActions[0]).toMatchObject(openAllCompleted({ groupName: group }))
|
||||
})
|
||||
|
||||
it('should dispatch deleteCompleted action', () => {
|
||||
@@ -67,18 +55,14 @@ it('should dispatch deleteCompleted action', () => {
|
||||
|
||||
const confirmDialog = screen.getByTestId('delete-completed-tasks-dialog')
|
||||
expect(confirmDialog).toBeInTheDocument()
|
||||
expect(confirmDialog).toHaveTextContent(
|
||||
`Are you sure you want to delete completed tasks in the '${group}' group?`
|
||||
)
|
||||
expect(confirmDialog).toHaveTextContent(`Are you sure you want to delete completed tasks in the '${group}' group?`)
|
||||
|
||||
const confirmButton = screen.getByTestId('confirm-dialog-button')
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
deleteAllCompleted({ groupName: group })
|
||||
)
|
||||
expect(dispatchedActions[0]).toMatchObject(deleteAllCompleted({ groupName: group }))
|
||||
})
|
||||
|
||||
it('should dismiss dialogs', () => {
|
||||
|
||||
@@ -30,9 +30,7 @@ type CompletedTasksActionsProps = {
|
||||
groupName: string
|
||||
}
|
||||
|
||||
const CompletedTasksActions: React.FC<CompletedTasksActionsProps> = ({
|
||||
groupName,
|
||||
}) => {
|
||||
const CompletedTasksActions: React.FC<CompletedTasksActionsProps> = ({ groupName }) => {
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
@@ -46,16 +44,10 @@ const CompletedTasksActions: React.FC<CompletedTasksActionsProps> = ({
|
||||
|
||||
return (
|
||||
<div data-testid="completed-tasks-actions">
|
||||
<ActionButton
|
||||
onClick={() => setShowReopenDialog(true)}
|
||||
data-testid="reopen-completed-button"
|
||||
>
|
||||
<ActionButton onClick={() => setShowReopenDialog(true)} data-testid="reopen-completed-button">
|
||||
Reopen Completed
|
||||
</ActionButton>
|
||||
<ActionButton
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
data-testid="delete-completed-button"
|
||||
>
|
||||
<ActionButton onClick={() => setShowDeleteDialog(true)} data-testid="delete-completed-button">
|
||||
Delete Completed
|
||||
</ActionButton>
|
||||
{showReopenDialog && (
|
||||
@@ -65,8 +57,7 @@ const CompletedTasksActions: React.FC<CompletedTasksActionsProps> = ({
|
||||
confirmButtonCb={() => dispatch(openAllCompleted({ groupName }))}
|
||||
cancelButtonCb={() => setShowReopenDialog(false)}
|
||||
>
|
||||
Are you sure you want to reopen completed tasks in the '
|
||||
<strong>{groupName}</strong>' group?
|
||||
Are you sure you want to reopen completed tasks in the '<strong>{groupName}</strong>' group?
|
||||
</ConfirmDialog>
|
||||
)}
|
||||
{showDeleteDialog && (
|
||||
@@ -76,8 +67,7 @@ const CompletedTasksActions: React.FC<CompletedTasksActionsProps> = ({
|
||||
confirmButtonCb={() => dispatch(deleteAllCompleted({ groupName }))}
|
||||
cancelButtonCb={() => setShowDeleteDialog(false)}
|
||||
>
|
||||
Are you sure you want to delete completed tasks in the '
|
||||
<strong>{groupName}</strong>' group?
|
||||
Are you sure you want to delete completed tasks in the '<strong>{groupName}</strong>' group?
|
||||
</ConfirmDialog>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
ChangeEvent,
|
||||
createRef,
|
||||
FocusEvent,
|
||||
KeyboardEvent,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { ChangeEvent, createRef, FocusEvent, KeyboardEvent, useState } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
@@ -82,9 +76,7 @@ const CreateGroup: React.FC = () => {
|
||||
const [isCreateMode, setIsCreateMode] = useState(false)
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const spellCheckerEnabled = useAppSelector(
|
||||
(state) => state.settings.spellCheckerEnabled
|
||||
)
|
||||
const spellCheckerEnabled = useAppSelector((state) => state.settings.spellCheckerEnabled)
|
||||
const groupedTasks = useAppSelector((state) => state.tasks.groups)
|
||||
const taskGroupCount = groupedTasks.length
|
||||
|
||||
@@ -144,9 +136,7 @@ const CreateGroup: React.FC = () => {
|
||||
<TutorialContainer>
|
||||
<Tutorial>
|
||||
<ArrowVector style={{ marginRight: 140, marginBottom: 12 }} />
|
||||
<TutorialText>
|
||||
Get started by naming your first task group
|
||||
</TutorialText>
|
||||
<TutorialText>Get started by naming your first task group</TutorialText>
|
||||
</Tutorial>
|
||||
<EmptyContainer1 />
|
||||
<EmptyContainer2 />
|
||||
|
||||
@@ -79,6 +79,6 @@ test('pressing enter when input box is not empty, should create a new task', ()
|
||||
taskAdded({
|
||||
task: { id: 'my-fake-uuid', description: 'My awesome task' },
|
||||
groupName: defaultGroup.name,
|
||||
})
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -29,9 +29,7 @@ const CreateTask: React.FC<CreateTaskProps> = ({ group }) => {
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const spellCheckerEnabled = useAppSelector(
|
||||
(state) => state.settings.spellCheckerEnabled
|
||||
)
|
||||
const spellCheckerEnabled = useAppSelector((state) => state.settings.spellCheckerEnabled)
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const allGroups = useAppSelector((state) => state.tasks.groups)
|
||||
|
||||
@@ -51,9 +49,7 @@ const CreateTask: React.FC<CreateTaskProps> = ({ group }) => {
|
||||
return
|
||||
}
|
||||
|
||||
dispatch(
|
||||
taskAdded({ task: { id: uuidv4(), description: rawString }, groupName })
|
||||
)
|
||||
dispatch(taskAdded({ task: { id: uuidv4(), description: rawString }, groupName }))
|
||||
setTaskDraft('')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,7 @@ const Container = styled.div`
|
||||
|
||||
const InvalidContentError: React.FC = () => {
|
||||
const lastError = useAppSelector((state) => state.tasks.lastError)
|
||||
return (
|
||||
<Container>
|
||||
{lastError ||
|
||||
'An unknown error has occurred, and the content cannot be displayed.'}
|
||||
</Container>
|
||||
)
|
||||
return <Container>{lastError || 'An unknown error has occurred, and the content cannot be displayed.'}</Container>
|
||||
}
|
||||
|
||||
export default InvalidContentError
|
||||
|
||||
@@ -28,20 +28,12 @@ it('renders the alert dialog when no groups are available to merge', () => {
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
testRender(<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />, {}, defaultState)
|
||||
|
||||
const alertDialog = screen.getByTestId('merge-task-group-dialog')
|
||||
expect(alertDialog).toBeInTheDocument()
|
||||
expect(alertDialog).toHaveTextContent(
|
||||
`There are no other groups to merge '${defaultGroup}' with.`
|
||||
)
|
||||
expect(alertDialog).not.toHaveTextContent(
|
||||
`Select which group you want to merge '${defaultGroup}' into:`
|
||||
)
|
||||
expect(alertDialog).toHaveTextContent(`There are no other groups to merge '${defaultGroup}' with.`)
|
||||
expect(alertDialog).not.toHaveTextContent(`Select which group you want to merge '${defaultGroup}' into:`)
|
||||
|
||||
// There shouldn't be any radio buttons
|
||||
expect(screen.queryAllByRole('radio')).toHaveLength(0)
|
||||
@@ -90,20 +82,12 @@ it('renders the alert dialog when there are groups available to merge', () => {
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
testRender(<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />, {}, defaultState)
|
||||
|
||||
const alertDialog = screen.getByTestId('merge-task-group-dialog')
|
||||
expect(alertDialog).toBeInTheDocument()
|
||||
expect(alertDialog).toHaveTextContent(
|
||||
`Select which group you want to merge '${defaultGroup}' into:`
|
||||
)
|
||||
expect(alertDialog).not.toHaveTextContent(
|
||||
`There are no other groups to merge '${defaultGroup}' with.`
|
||||
)
|
||||
expect(alertDialog).toHaveTextContent(`Select which group you want to merge '${defaultGroup}' into:`)
|
||||
expect(alertDialog).not.toHaveTextContent(`There are no other groups to merge '${defaultGroup}' with.`)
|
||||
|
||||
const radioButtons = screen.queryAllByRole('radio')
|
||||
expect(radioButtons).toHaveLength(2)
|
||||
@@ -163,7 +147,7 @@ it('should close the dialog if no group is selected and the Merge button is clic
|
||||
const { mockStore } = testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
defaultState,
|
||||
)
|
||||
|
||||
const buttons = screen.queryAllByRole('button')
|
||||
@@ -225,7 +209,7 @@ it('should dispatch the action to merge groups', () => {
|
||||
const { mockStore } = testRender(
|
||||
<MergeTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
defaultState,
|
||||
)
|
||||
|
||||
const radioButtons = screen.queryAllByRole('radio')
|
||||
@@ -250,8 +234,6 @@ it('should dispatch the action to merge groups', () => {
|
||||
|
||||
dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
tasksGroupMerged({ groupName: defaultGroup, mergeWith: 'Testing' })
|
||||
)
|
||||
expect(dispatchedActions[0]).toMatchObject(tasksGroupMerged({ groupName: defaultGroup, mergeWith: 'Testing' }))
|
||||
expect(handleClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import '@reach/dialog/styles.css'
|
||||
|
||||
import React, { useRef, useState } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogLabel,
|
||||
AlertDialogDescription,
|
||||
} from '@reach/alert-dialog'
|
||||
import { AlertDialog, AlertDialogLabel, AlertDialogDescription } from '@reach/alert-dialog'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { tasksGroupMerged } from './tasks-slice'
|
||||
@@ -15,10 +11,7 @@ type MergeTaskGroupsProps = {
|
||||
handleClose: () => void
|
||||
}
|
||||
|
||||
const MergeTaskGroups: React.FC<MergeTaskGroupsProps> = ({
|
||||
groupName,
|
||||
handleClose,
|
||||
}) => {
|
||||
const MergeTaskGroups: React.FC<MergeTaskGroupsProps> = ({ groupName, handleClose }) => {
|
||||
const cancelRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
@@ -45,39 +38,25 @@ const MergeTaskGroups: React.FC<MergeTaskGroupsProps> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid="merge-task-group-dialog"
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<AlertDialog data-testid="merge-task-group-dialog" leastDestructiveRef={cancelRef}>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
<div className="sk-panel-content">
|
||||
<div className="sk-panel-section">
|
||||
<AlertDialogLabel className="sk-h3 sk-panel-section-title">
|
||||
Merging task groups
|
||||
</AlertDialogLabel>
|
||||
<AlertDialogLabel className="sk-h3 sk-panel-section-title">Merging task groups</AlertDialogLabel>
|
||||
|
||||
{mergeableGroups.length > 0 ? (
|
||||
<>
|
||||
<AlertDialogDescription className="sk-panel-row">
|
||||
<p className="color-foreground">
|
||||
Select which group you want to merge '
|
||||
<strong>{groupName}</strong>' into:
|
||||
Select which group you want to merge '<strong>{groupName}</strong>' into:
|
||||
</p>
|
||||
</AlertDialogDescription>
|
||||
<fieldset className="flex flex-col" onChange={handleChange}>
|
||||
{mergeableGroups.map((item) => (
|
||||
<label
|
||||
key={item.name}
|
||||
className="flex items-center mb-1"
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
value={item.name}
|
||||
checked={item.name === mergeWith}
|
||||
readOnly
|
||||
/>
|
||||
<label key={item.name} className="flex items-center mb-1">
|
||||
<input type="radio" value={item.name} checked={item.name === mergeWith} readOnly />
|
||||
{item.name}
|
||||
</label>
|
||||
))}
|
||||
@@ -86,24 +65,16 @@ const MergeTaskGroups: React.FC<MergeTaskGroupsProps> = ({
|
||||
) : (
|
||||
<AlertDialogDescription>
|
||||
<p className="color-foreground">
|
||||
There are no other groups to merge '
|
||||
<strong>{groupName}</strong>' with.
|
||||
There are no other groups to merge '<strong>{groupName}</strong>' with.
|
||||
</p>
|
||||
</AlertDialogDescription>
|
||||
)}
|
||||
|
||||
<div className="flex my-1 mt-4">
|
||||
<button
|
||||
className="sn-button small neutral"
|
||||
onClick={handleClose}
|
||||
ref={cancelRef}
|
||||
>
|
||||
<button className="sn-button small neutral" onClick={handleClose} ref={cancelRef}>
|
||||
{!mergeWith ? 'Close' : 'Cancel'}
|
||||
</button>
|
||||
<button
|
||||
className="sn-button small ml-2 info"
|
||||
onClick={handleMergeGroups}
|
||||
>
|
||||
<button className="sn-button small ml-2 info" onClick={handleMergeGroups}>
|
||||
Merge groups
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -20,32 +20,21 @@ const MigrateLegacyContent: React.FC = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid="migrate-legacy-content-dialog"
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<AlertDialog data-testid="migrate-legacy-content-dialog" leastDestructiveRef={cancelRef}>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
<div className="sk-panel-content">
|
||||
<div className="sk-panel-section">
|
||||
<AlertDialogLabel className="sk-h3 sk-panel-section-title">
|
||||
Are you sure you want to migrate legacy content to the new
|
||||
format?
|
||||
Are you sure you want to migrate legacy content to the new format?
|
||||
</AlertDialogLabel>
|
||||
|
||||
<div className="flex my-1 mt-4">
|
||||
<button
|
||||
className="sn-button small neutral"
|
||||
onClick={handleCancel}
|
||||
ref={cancelRef}
|
||||
>
|
||||
<button className="sn-button small neutral" onClick={handleCancel} ref={cancelRef}>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
className="sn-button small ml-2 info"
|
||||
onClick={handleMigrate}
|
||||
>
|
||||
<button className="sn-button small ml-2 info" onClick={handleMigrate}>
|
||||
Migrate
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -19,10 +19,7 @@ type GroupSummaryProps = {
|
||||
|
||||
const GroupSummary: React.FC<GroupSummaryProps> = ({ groups }) => {
|
||||
const totalGroups = groups.length
|
||||
const groupsToPreview = groups.slice(
|
||||
0,
|
||||
Math.min(totalGroups, GROUPS_PREVIEW_LIMIT)
|
||||
)
|
||||
const groupsToPreview = groups.slice(0, Math.min(totalGroups, GROUPS_PREVIEW_LIMIT))
|
||||
if (groupsToPreview.length === 0) {
|
||||
return <></>
|
||||
}
|
||||
@@ -35,16 +32,10 @@ const GroupSummary: React.FC<GroupSummaryProps> = ({ groups }) => {
|
||||
<div className="my-2">
|
||||
{groupsToPreview.map((group, index) => {
|
||||
const totalTasks = group.tasks.length
|
||||
const totalCompletedTasks = group.tasks.filter(
|
||||
(task) => task.completed === true
|
||||
).length
|
||||
const totalCompletedTasks = group.tasks.filter((task) => task.completed === true).length
|
||||
|
||||
return (
|
||||
<p
|
||||
data-testid="group-summary"
|
||||
key={`group-${group.name}`}
|
||||
className="mb-1"
|
||||
>
|
||||
<p data-testid="group-summary" key={`group-${group.name}`} className="mb-1">
|
||||
{truncateText(group.name, MAX_GROUP_DESCRIPTION_LENGTH)}
|
||||
<span className="px-2 neutral">
|
||||
{totalCompletedTasks}/{totalTasks}
|
||||
@@ -75,11 +66,7 @@ const NotePreview: React.FC<NotePreviewProps> = ({ groupedTasks }) => {
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-grow items-center mb-3">
|
||||
<svg
|
||||
data-testid="circular-progress-bar"
|
||||
className="sk-circular-progress"
|
||||
viewBox="0 0 18 18"
|
||||
>
|
||||
<svg data-testid="circular-progress-bar" className="sk-circular-progress" viewBox="0 0 18 18">
|
||||
<circle className="background" />
|
||||
<circle className={`progress p-${roundedPercentage}`} />
|
||||
</svg>
|
||||
|
||||
@@ -28,11 +28,7 @@ it('renders the alert dialog with an input box', () => {
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<RenameTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
testRender(<RenameTaskGroups groupName={defaultGroup} handleClose={handleClose} />, {}, defaultState)
|
||||
|
||||
const alertDialog = screen.getByTestId('rename-task-group-dialog')
|
||||
expect(alertDialog).toBeInTheDocument()
|
||||
@@ -78,14 +74,12 @@ it('should dispatch the action to merge groups', () => {
|
||||
const { mockStore } = testRender(
|
||||
<RenameTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
defaultState,
|
||||
)
|
||||
|
||||
const newGroupName = 'My new group name'
|
||||
|
||||
const inputBox = screen.getByTestId(
|
||||
'new-group-name-input'
|
||||
) as HTMLInputElement
|
||||
const inputBox = screen.getByTestId('new-group-name-input') as HTMLInputElement
|
||||
|
||||
fireEvent.change(inputBox, { target: { value: newGroupName } })
|
||||
|
||||
@@ -104,9 +98,7 @@ it('should dispatch the action to merge groups', () => {
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
tasksGroupRenamed({ groupName: defaultGroup, newName: newGroupName })
|
||||
)
|
||||
expect(dispatchedActions[0]).toMatchObject(tasksGroupRenamed({ groupName: defaultGroup, newName: newGroupName }))
|
||||
expect(handleClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
@@ -145,14 +137,12 @@ it('should dispatch the action to merge groups on Enter press', () => {
|
||||
const { mockStore } = testRender(
|
||||
<RenameTaskGroups groupName={defaultGroup} handleClose={handleClose} />,
|
||||
{},
|
||||
defaultState
|
||||
defaultState,
|
||||
)
|
||||
|
||||
const newGroupName = 'My new group name'
|
||||
|
||||
const inputBox = screen.getByTestId(
|
||||
'new-group-name-input'
|
||||
) as HTMLInputElement
|
||||
const inputBox = screen.getByTestId('new-group-name-input') as HTMLInputElement
|
||||
|
||||
fireEvent.change(inputBox, { target: { value: newGroupName } })
|
||||
fireEvent.keyPress(inputBox, {
|
||||
@@ -164,8 +154,6 @@ it('should dispatch the action to merge groups on Enter press', () => {
|
||||
|
||||
const dispatchedActions = mockStore.getActions()
|
||||
expect(dispatchedActions).toHaveLength(1)
|
||||
expect(dispatchedActions[0]).toMatchObject(
|
||||
tasksGroupRenamed({ groupName: defaultGroup, newName: newGroupName })
|
||||
)
|
||||
expect(dispatchedActions[0]).toMatchObject(tasksGroupRenamed({ groupName: defaultGroup, newName: newGroupName }))
|
||||
expect(handleClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import '@reach/dialog/styles.css'
|
||||
|
||||
import React, { KeyboardEvent, useRef, useState } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogLabel,
|
||||
AlertDialogDescription,
|
||||
} from '@reach/alert-dialog'
|
||||
import { AlertDialog, AlertDialogLabel, AlertDialogDescription } from '@reach/alert-dialog'
|
||||
|
||||
import { useAppDispatch } from '../../app/hooks'
|
||||
import { tasksGroupRenamed } from './tasks-slice'
|
||||
@@ -16,10 +12,7 @@ type RenameTaskGroupsProps = {
|
||||
handleClose: () => void
|
||||
}
|
||||
|
||||
const RenameTaskGroups: React.FC<RenameTaskGroupsProps> = ({
|
||||
groupName,
|
||||
handleClose,
|
||||
}) => {
|
||||
const RenameTaskGroups: React.FC<RenameTaskGroupsProps> = ({ groupName, handleClose }) => {
|
||||
const cancelRef = useRef<HTMLButtonElement>(null)
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
@@ -44,10 +37,7 @@ const RenameTaskGroups: React.FC<RenameTaskGroupsProps> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog
|
||||
data-testid="rename-task-group-dialog"
|
||||
leastDestructiveRef={cancelRef}
|
||||
>
|
||||
<AlertDialog data-testid="rename-task-group-dialog" leastDestructiveRef={cancelRef}>
|
||||
<div className="sk-modal-content">
|
||||
<div className="sn-component">
|
||||
<div className="sk-panel">
|
||||
@@ -69,11 +59,7 @@ const RenameTaskGroups: React.FC<RenameTaskGroupsProps> = ({
|
||||
</AlertDialogDescription>
|
||||
|
||||
<div className="flex my-1 mt-4">
|
||||
<button
|
||||
className="sn-button small neutral"
|
||||
onClick={handleClose}
|
||||
ref={cancelRef}
|
||||
>
|
||||
<button className="sn-button small neutral" onClick={handleClose} ref={cancelRef}>
|
||||
{renameTo.length === 0 ? 'Close' : 'Cancel'}
|
||||
</button>
|
||||
<button
|
||||
|
||||
@@ -31,14 +31,10 @@ it('renders the group name', () => {
|
||||
it('renders the number of completed tasks and total tasks', () => {
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />)
|
||||
|
||||
const completedTasks = defaultGroup.tasks.filter(
|
||||
(task) => task.completed
|
||||
).length
|
||||
const completedTasks = defaultGroup.tasks.filter((task) => task.completed).length
|
||||
const totalTasks = defaultGroup.tasks.length
|
||||
|
||||
expect(screen.getByTestId('task-group-stats')).toHaveTextContent(
|
||||
`${completedTasks}/${totalTasks}`
|
||||
)
|
||||
expect(screen.getByTestId('task-group-stats')).toHaveTextContent(`${completedTasks}/${totalTasks}`)
|
||||
})
|
||||
|
||||
it('renders the circular progress bar', () => {
|
||||
@@ -96,11 +92,7 @@ it('hides group options if can not edit', () => {
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<TaskGroup group={defaultGroup} isDragging={false} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />, {}, defaultState)
|
||||
|
||||
expect(screen.queryByTestId('task-group-options')).not.toBeInTheDocument()
|
||||
})
|
||||
@@ -114,11 +106,7 @@ it('shows a reorder icon when on mobile', () => {
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<TaskGroup group={defaultGroup} isDragging={false} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />, {}, defaultState)
|
||||
|
||||
expect(screen.queryByTestId('reorder-icon')).not.toBeInTheDocument()
|
||||
|
||||
@@ -130,11 +118,7 @@ it('shows a reorder icon when on mobile', () => {
|
||||
},
|
||||
}
|
||||
|
||||
testRender(
|
||||
<TaskGroup group={defaultGroup} isDragging={false} />,
|
||||
{},
|
||||
defaultState
|
||||
)
|
||||
testRender(<TaskGroup group={defaultGroup} isDragging={false} />, {}, defaultState)
|
||||
|
||||
expect(screen.getByTestId('reorder-icon')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -10,17 +10,8 @@ import TaskItemList from './TaskItemList'
|
||||
|
||||
import TaskGroupOptions from './TaskGroupOptions'
|
||||
|
||||
import {
|
||||
CircularProgressBar,
|
||||
GenericInlineText,
|
||||
MainTitle,
|
||||
RoundButton,
|
||||
} from '../../common/components'
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
ReorderIcon,
|
||||
ChevronUpIcon,
|
||||
} from '../../common/components/icons'
|
||||
import { CircularProgressBar, GenericInlineText, MainTitle, RoundButton } from '../../common/components'
|
||||
import { ChevronDownIcon, ReorderIcon, ChevronUpIcon } from '../../common/components/icons'
|
||||
|
||||
const TaskGroupContainer = styled.div<{ isLast?: boolean }>`
|
||||
background-color: var(--sn-stylekit-background-color);
|
||||
@@ -100,10 +91,7 @@ const TaskGroup: React.FC<TaskGroupProps> = ({
|
||||
<ReorderIcon highlight={isDragging} />
|
||||
</div>
|
||||
)}
|
||||
<MainTitle
|
||||
crossed={allTasksCompleted && collapsed}
|
||||
highlight={isDragging}
|
||||
>
|
||||
<MainTitle crossed={allTasksCompleted && collapsed} highlight={isDragging}>
|
||||
{groupName}
|
||||
</MainTitle>
|
||||
<CircularProgressBar size={18} percentage={percentageCompleted} />
|
||||
@@ -119,10 +107,7 @@ const TaskGroup: React.FC<TaskGroupProps> = ({
|
||||
</div>
|
||||
)}
|
||||
<div className="ml-3">
|
||||
<RoundButton
|
||||
testId="collapse-task-group"
|
||||
onClick={handleCollapse}
|
||||
>
|
||||
<RoundButton testId="collapse-task-group" onClick={handleCollapse}>
|
||||
{!collapsed ? <ChevronUpIcon /> : <ChevronDownIcon />}
|
||||
</RoundButton>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
DragDropContext,
|
||||
Draggable,
|
||||
Droppable,
|
||||
DropResult,
|
||||
} from 'react-beautiful-dnd'
|
||||
import { DragDropContext, Draggable, Droppable, DropResult } from 'react-beautiful-dnd'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '../../app/hooks'
|
||||
import { tasksGroupReordered } from './tasks-slice'
|
||||
@@ -32,16 +27,13 @@ const TaskGroupList: React.FC = () => {
|
||||
tasksGroupReordered({
|
||||
swapGroupIndex: source.index,
|
||||
withGroupIndex: destination.index,
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<DragDropContext data-testid="task-group-list" onDragEnd={onDragEnd}>
|
||||
<Droppable
|
||||
droppableId={'droppable-task-group-list'}
|
||||
isDropDisabled={!canEdit}
|
||||
>
|
||||
<Droppable droppableId={'droppable-task-group-list'} isDropDisabled={!canEdit}>
|
||||
{(provided) => (
|
||||
<div {...provided.droppableProps} ref={provided.innerRef}>
|
||||
{groupedTasks.map((group, index) => {
|
||||
@@ -52,12 +44,8 @@ const TaskGroupList: React.FC = () => {
|
||||
index={index}
|
||||
isDragDisabled={!canEdit}
|
||||
>
|
||||
{(
|
||||
{ innerRef, draggableProps, dragHandleProps },
|
||||
{ isDragging }
|
||||
) => {
|
||||
const { onTransitionEnd, ...restDraggableProps } =
|
||||
draggableProps
|
||||
{({ innerRef, draggableProps, dragHandleProps }, { isDragging }) => {
|
||||
const { onTransitionEnd, ...restDraggableProps } = draggableProps
|
||||
return (
|
||||
<TaskGroup
|
||||
key={`group-${group.name}`}
|
||||
|
||||
@@ -43,9 +43,7 @@ it('should dispatch tasksGroupDeleted action', () => {
|
||||
|
||||
const confirmDialog = screen.getByTestId('delete-task-group-dialog')
|
||||
expect(confirmDialog).toBeInTheDocument()
|
||||
expect(confirmDialog).toHaveTextContent(
|
||||
`Are you sure you want to delete the group '${groupName}'?`
|
||||
)
|
||||
expect(confirmDialog).toHaveTextContent(`Are you sure you want to delete the group '${groupName}'?`)
|
||||
|
||||
const confirmButton = screen.getByTestId('confirm-dialog-button')
|
||||
fireEvent.click(confirmButton)
|
||||
@@ -103,9 +101,7 @@ it('should close the delete task group dialog', () => {
|
||||
const cancelButton = screen.getByTestId('cancel-dialog-button')
|
||||
clickButton(cancelButton)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('trash-task-group-dialog')
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('trash-task-group-dialog')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should close the merge task group dialog', () => {
|
||||
@@ -120,9 +116,7 @@ it('should close the merge task group dialog', () => {
|
||||
const cancelButton = screen.queryAllByRole('button')[0]
|
||||
clickButton(cancelButton)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('merge-task-group-dialog')
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('merge-task-group-dialog')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should close the rename task group dialog', () => {
|
||||
@@ -137,7 +131,5 @@ it('should close the rename task group dialog', () => {
|
||||
const cancelButton = screen.queryAllByRole('button')[0]
|
||||
clickButton(cancelButton)
|
||||
|
||||
expect(
|
||||
screen.queryByTestId('rename-task-group-dialog')
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('rename-task-group-dialog')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -5,12 +5,7 @@ import VisuallyHidden from '@reach/visually-hidden'
|
||||
import { useAppDispatch } from '../../app/hooks'
|
||||
import { tasksGroupDeleted } from './tasks-slice'
|
||||
|
||||
import {
|
||||
MoreIcon,
|
||||
MergeIcon,
|
||||
TrashIcon,
|
||||
RenameIcon,
|
||||
} from '../../common/components/icons'
|
||||
import { MoreIcon, MergeIcon, TrashIcon, RenameIcon } from '../../common/components/icons'
|
||||
|
||||
import { ConfirmDialog } from '../../common/components'
|
||||
|
||||
@@ -36,24 +31,15 @@ const TaskGroupOptions: React.FC<TaskGroupOptionsProps> = ({ groupName }) => {
|
||||
<MoreIcon />
|
||||
</MenuButton>
|
||||
<MenuList>
|
||||
<MenuItem
|
||||
data-testid="delete-task-group"
|
||||
onSelect={() => setShowDeleteDialog(true)}
|
||||
>
|
||||
<MenuItem data-testid="delete-task-group" onSelect={() => setShowDeleteDialog(true)}>
|
||||
<TrashIcon />
|
||||
<span className="px-1">Delete group</span>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
data-testid="merge-task-group"
|
||||
onSelect={() => setShowMergeDialog(true)}
|
||||
>
|
||||
<MenuItem data-testid="merge-task-group" onSelect={() => setShowMergeDialog(true)}>
|
||||
<MergeIcon />
|
||||
<span className="px-1">Merge into another group</span>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
data-testid="rename-task-group"
|
||||
onSelect={() => setShowRenameDialog(true)}
|
||||
>
|
||||
<MenuItem data-testid="rename-task-group" onSelect={() => setShowRenameDialog(true)}>
|
||||
<RenameIcon />
|
||||
<span className="px-1">Rename</span>
|
||||
</MenuItem>
|
||||
@@ -68,22 +54,11 @@ const TaskGroupOptions: React.FC<TaskGroupOptionsProps> = ({ groupName }) => {
|
||||
confirmButtonCb={() => dispatch(tasksGroupDeleted({ groupName }))}
|
||||
cancelButtonCb={() => setShowDeleteDialog(false)}
|
||||
>
|
||||
Are you sure you want to delete the group '
|
||||
<strong>{groupName}</strong>'?
|
||||
Are you sure you want to delete the group '<strong>{groupName}</strong>'?
|
||||
</ConfirmDialog>
|
||||
)}
|
||||
{showMergeDialog && (
|
||||
<MergeTaskGroups
|
||||
groupName={groupName}
|
||||
handleClose={() => setShowMergeDialog(false)}
|
||||
/>
|
||||
)}
|
||||
{showRenameDialog && (
|
||||
<RenameTaskGroups
|
||||
groupName={groupName}
|
||||
handleClose={() => setShowRenameDialog(false)}
|
||||
/>
|
||||
)}
|
||||
{showMergeDialog && <MergeTaskGroups groupName={groupName} handleClose={() => setShowMergeDialog(false)} />}
|
||||
{showRenameDialog && <RenameTaskGroups groupName={groupName} handleClose={() => setShowRenameDialog(false)} />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
|
||||
import {
|
||||
taskDeleted,
|
||||
taskModified,
|
||||
TaskPayload,
|
||||
taskToggled,
|
||||
} from './tasks-slice'
|
||||
import { taskDeleted, taskModified, TaskPayload, taskToggled } from './tasks-slice'
|
||||
import { testRender } from '../../testUtils'
|
||||
import TaskItem from './TaskItem'
|
||||
|
||||
@@ -27,9 +22,7 @@ it('renders a check box and textarea input', async () => {
|
||||
test('clicking the check box should toggle the task as open/completed', () => {
|
||||
jest.useFakeTimers()
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
const { mockStore } = testRender(<TaskItem groupName={groupName} task={task} />)
|
||||
|
||||
const checkBox = screen.getByTestId('check-box-input')
|
||||
fireEvent.click(checkBox)
|
||||
@@ -43,7 +36,7 @@ test('clicking the check box should toggle the task as open/completed', () => {
|
||||
taskToggled({
|
||||
id: task.id,
|
||||
groupName,
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
fireEvent.click(checkBox)
|
||||
@@ -57,7 +50,7 @@ test('clicking the check box should toggle the task as open/completed', () => {
|
||||
taskToggled({
|
||||
id: task.id,
|
||||
groupName,
|
||||
})
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -66,13 +59,9 @@ test('changing the textarea input text should update the task description', asyn
|
||||
|
||||
const newTaskDescription = 'My new task'
|
||||
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
const { mockStore } = testRender(<TaskItem groupName={groupName} task={task} />)
|
||||
|
||||
const textAreaInput = screen.getByTestId(
|
||||
'text-area-input'
|
||||
) as HTMLTextAreaElement
|
||||
const textAreaInput = screen.getByTestId('text-area-input') as HTMLTextAreaElement
|
||||
fireEvent.change(textAreaInput, {
|
||||
target: { value: newTaskDescription },
|
||||
})
|
||||
@@ -96,14 +85,12 @@ test('changing the textarea input text should update the task description', asyn
|
||||
description: newTaskDescription,
|
||||
},
|
||||
groupName,
|
||||
})
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
test('clearing the textarea input text should delete the task', () => {
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
const { mockStore } = testRender(<TaskItem groupName={groupName} task={task} />)
|
||||
|
||||
const textAreaInput = screen.getByTestId('text-area-input')
|
||||
fireEvent.change(textAreaInput, {
|
||||
@@ -123,14 +110,12 @@ test('clearing the textarea input text should delete the task', () => {
|
||||
taskDeleted({
|
||||
id: task.id,
|
||||
groupName,
|
||||
})
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
test('pressing enter should not update the task description', () => {
|
||||
const { mockStore } = testRender(
|
||||
<TaskItem groupName={groupName} task={task} />
|
||||
)
|
||||
const { mockStore } = testRender(<TaskItem groupName={groupName} task={task} />)
|
||||
|
||||
const textAreaInput = screen.getByTestId('text-area-input')
|
||||
fireEvent.keyPress(textAreaInput, {
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
import './TaskItem.scss'
|
||||
|
||||
import {
|
||||
ChangeEvent,
|
||||
createRef,
|
||||
KeyboardEvent,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { ChangeEvent, createRef, KeyboardEvent, useEffect, useState } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import {
|
||||
taskDeleted,
|
||||
taskModified,
|
||||
TaskPayload,
|
||||
taskToggled,
|
||||
} from './tasks-slice'
|
||||
import { taskDeleted, taskModified, TaskPayload, taskToggled } from './tasks-slice'
|
||||
import { useAppDispatch, useAppSelector, useDidMount } from '../../app/hooks'
|
||||
|
||||
import { CheckBoxInput, TextAreaInput } from '../../common/components'
|
||||
@@ -53,20 +42,13 @@ export type TaskItemProps = {
|
||||
innerRef?: (element?: HTMLElement | null | undefined) => any
|
||||
}
|
||||
|
||||
const TaskItem: React.FC<TaskItemProps> = ({
|
||||
task,
|
||||
groupName,
|
||||
innerRef,
|
||||
...props
|
||||
}) => {
|
||||
const TaskItem: React.FC<TaskItemProps> = ({ task, groupName, innerRef, ...props }) => {
|
||||
const textAreaRef = createRef<HTMLTextAreaElement>()
|
||||
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const spellCheckEnabled = useAppSelector(
|
||||
(state) => state.settings.spellCheckerEnabled
|
||||
)
|
||||
const spellCheckEnabled = useAppSelector((state) => state.settings.spellCheckerEnabled)
|
||||
|
||||
const [completed, setCompleted] = useState(!!task.completed)
|
||||
const [description, setDescription] = useState(task.description)
|
||||
@@ -96,9 +78,7 @@ const TaskItem: React.FC<TaskItemProps> = ({
|
||||
? textAreaRef.current!.classList.add('cross-out')
|
||||
: textAreaRef.current!.classList.add('no-text-decoration')
|
||||
|
||||
const dispatchDelay = newCompletedState
|
||||
? DISPATCH_COMPLETED_DELAY_MS
|
||||
: DISPATCH_OPENED_DELAY_MS
|
||||
const dispatchDelay = newCompletedState ? DISPATCH_COMPLETED_DELAY_MS : DISPATCH_OPENED_DELAY_MS
|
||||
|
||||
setTimeout(() => {
|
||||
dispatch(taskToggled({ id: task.id, groupName }))
|
||||
@@ -135,9 +115,7 @@ const TaskItem: React.FC<TaskItemProps> = ({
|
||||
useDidMount(() => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
if (description !== task.description) {
|
||||
dispatch(
|
||||
taskModified({ task: { id: task.id, description }, groupName })
|
||||
)
|
||||
dispatch(taskModified({ task: { id: task.id, description }, groupName }))
|
||||
}
|
||||
}, 500)
|
||||
|
||||
@@ -145,18 +123,8 @@ const TaskItem: React.FC<TaskItemProps> = ({
|
||||
}, [description, groupName])
|
||||
|
||||
return (
|
||||
<Container
|
||||
data-testid="task-item"
|
||||
completed={completed}
|
||||
ref={innerRef}
|
||||
{...props}
|
||||
>
|
||||
<CheckBoxInput
|
||||
testId="check-box-input"
|
||||
checked={completed}
|
||||
disabled={!canEdit}
|
||||
onChange={onCheckBoxToggle}
|
||||
/>
|
||||
<Container data-testid="task-item" completed={completed} ref={innerRef} {...props}>
|
||||
<CheckBoxInput testId="check-box-input" checked={completed} disabled={!canEdit} onChange={onCheckBoxToggle} />
|
||||
<TextAreaInput
|
||||
testId="text-area-input"
|
||||
className="text-area-input"
|
||||
|
||||
@@ -52,9 +52,7 @@ it('renders the completed tasks container', () => {
|
||||
|
||||
testRender(<TaskItemList group={groupWithCompletedTask} />)
|
||||
|
||||
const completedTasksContainer = screen.getByTestId(
|
||||
'completed-tasks-container'
|
||||
)
|
||||
const completedTasksContainer = screen.getByTestId('completed-tasks-container')
|
||||
|
||||
expect(completedTasksContainer).toBeInTheDocument()
|
||||
expect(completedTasksContainer).toHaveTextContent('completed tasks')
|
||||
|
||||
@@ -39,19 +39,14 @@ const TaskItemList: React.FC<TaskItemListProps> = ({ group }) => {
|
||||
swapTaskIndex: source.index,
|
||||
withTaskIndex: destination.index,
|
||||
isSameSection: source.droppableId === destination.droppableId,
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Container data-testid="task-list">
|
||||
<DragDropContext onDragEnd={onDragEnd}>
|
||||
<TasksContainer
|
||||
testId="open-tasks-container"
|
||||
type="open"
|
||||
tasks={openTasks}
|
||||
groupName={group.name}
|
||||
/>
|
||||
<TasksContainer testId="open-tasks-container" type="open" tasks={openTasks} groupName={group.name} />
|
||||
|
||||
<TasksContainer
|
||||
testId="completed-tasks-container"
|
||||
@@ -59,9 +54,7 @@ const TaskItemList: React.FC<TaskItemListProps> = ({ group }) => {
|
||||
tasks={completedTasks}
|
||||
groupName={group.name}
|
||||
>
|
||||
{completedTasks.length > 0 && (
|
||||
<CompletedTasksActions groupName={group.name} />
|
||||
)}
|
||||
{completedTasks.length > 0 && <CompletedTasksActions groupName={group.name} />}
|
||||
</TasksContainer>
|
||||
</DragDropContext>
|
||||
</Container>
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import './TasksContainer.scss'
|
||||
|
||||
import React from 'react'
|
||||
import {
|
||||
Draggable,
|
||||
DraggingStyle,
|
||||
Droppable,
|
||||
NotDraggingStyle,
|
||||
} from 'react-beautiful-dnd'
|
||||
import { Draggable, DraggingStyle, Droppable, NotDraggingStyle } from 'react-beautiful-dnd'
|
||||
import styled from 'styled-components'
|
||||
import { CSSTransition, TransitionGroup } from 'react-transition-group'
|
||||
|
||||
@@ -27,13 +22,11 @@ const InnerTasksContainer = styled.div<{
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
${({ type, items }) =>
|
||||
type === 'completed' && items > 0 ? 'margin-bottom: 28px' : ''};
|
||||
${({ type, items }) => (type === 'completed' && items > 0 ? 'margin-bottom: 28px' : '')};
|
||||
`
|
||||
|
||||
const OuterContainer = styled.div<{ type: ContainerType; items: number }>`
|
||||
${({ type, items }) =>
|
||||
type === 'open' && items > 0 ? 'margin-bottom: 18px' : ''};
|
||||
${({ type, items }) => (type === 'open' && items > 0 ? 'margin-bottom: 18px' : '')};
|
||||
`
|
||||
|
||||
const SubTitleContainer = styled.div`
|
||||
@@ -49,10 +42,7 @@ const Wrapper = styled.div`
|
||||
color: var(--sn-stylekit-foreground-color);
|
||||
`
|
||||
|
||||
const getItemStyle = (
|
||||
isDragging: boolean,
|
||||
draggableStyle?: DraggingStyle | NotDraggingStyle
|
||||
) => ({
|
||||
const getItemStyle = (isDragging: boolean, draggableStyle?: DraggingStyle | NotDraggingStyle) => ({
|
||||
...draggableStyle,
|
||||
...(isDragging && {
|
||||
color: 'var(--sn-stylekit-info-color)',
|
||||
@@ -69,13 +59,7 @@ type TasksContainerProps = {
|
||||
testId?: string
|
||||
}
|
||||
|
||||
const TasksContainer: React.FC<TasksContainerProps> = ({
|
||||
groupName,
|
||||
tasks,
|
||||
type,
|
||||
testId,
|
||||
children,
|
||||
}) => {
|
||||
const TasksContainer: React.FC<TasksContainerProps> = ({ groupName, tasks, type, testId, children }) => {
|
||||
const canEdit = useAppSelector((state) => state.settings.canEdit)
|
||||
const droppableId = `${type}-tasks-droppable`
|
||||
|
||||
@@ -94,10 +78,7 @@ const TasksContainer: React.FC<TasksContainerProps> = ({
|
||||
ref={provided.innerRef}
|
||||
type={type}
|
||||
>
|
||||
<TransitionGroup
|
||||
component={null}
|
||||
childFactory={(child) => React.cloneElement(child)}
|
||||
>
|
||||
<TransitionGroup component={null} childFactory={(child) => React.cloneElement(child)}>
|
||||
{tasks.map((task, index) => {
|
||||
return (
|
||||
<CSSTransition
|
||||
@@ -128,7 +109,7 @@ const TasksContainer: React.FC<TasksContainerProps> = ({
|
||||
() => {
|
||||
node.classList.remove('explode')
|
||||
},
|
||||
false
|
||||
false,
|
||||
)
|
||||
}}
|
||||
onExited={(node: HTMLElement) => {
|
||||
@@ -146,18 +127,10 @@ const TasksContainer: React.FC<TasksContainerProps> = ({
|
||||
index={index}
|
||||
isDragDisabled={!canEdit}
|
||||
>
|
||||
{(
|
||||
{ innerRef, draggableProps, dragHandleProps },
|
||||
{ isDragging }
|
||||
) => {
|
||||
const { style, ...restDraggableProps } =
|
||||
draggableProps
|
||||
{({ innerRef, draggableProps, dragHandleProps }, { isDragging }) => {
|
||||
const { style, ...restDraggableProps } = draggableProps
|
||||
return (
|
||||
<div
|
||||
className="task-item"
|
||||
style={getItemStyle(isDragging, style)}
|
||||
{...restDraggableProps}
|
||||
>
|
||||
<div className="task-item" style={getItemStyle(isDragging, style)} {...restDraggableProps}>
|
||||
<TaskItem
|
||||
key={`task-item-${task.id}`}
|
||||
task={task}
|
||||
|
||||
@@ -22,7 +22,7 @@ it('should return the initial state', () => {
|
||||
return expect(
|
||||
reducer(undefined, {
|
||||
type: undefined,
|
||||
})
|
||||
}),
|
||||
).toEqual({ schemaVersion: '1.0.0', groups: [] })
|
||||
})
|
||||
|
||||
@@ -35,8 +35,8 @@ it('should handle a task being added to a non-existing group', () => {
|
||||
taskAdded({
|
||||
task: { id: 'some-id', description: 'A simple task' },
|
||||
groupName: 'Test',
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [],
|
||||
@@ -67,8 +67,8 @@ it('should handle a task being added to the existing tasks store', () => {
|
||||
taskAdded({
|
||||
task: { id: 'another-id', description: 'Another simple task' },
|
||||
groupName: 'Test',
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
@@ -117,8 +117,8 @@ it('should handle an existing task being modified', () => {
|
||||
taskModified({
|
||||
task: { id: 'some-id', description: 'Task description changed' },
|
||||
groupName: 'Test',
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
@@ -162,8 +162,8 @@ it('should not modify tasks if an invalid id is provided', () => {
|
||||
taskModified({
|
||||
task: { id: 'some-invalid-id', description: 'New description' },
|
||||
groupName: 'Test',
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
@@ -209,8 +209,8 @@ it('should keep completed field as-is, if task is modified', () => {
|
||||
description: 'New description',
|
||||
},
|
||||
groupName: 'Test',
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
@@ -248,9 +248,7 @@ it('should handle an existing task being toggled', () => {
|
||||
],
|
||||
}
|
||||
|
||||
expect(
|
||||
reducer(previousState, taskToggled({ id: 'some-id', groupName: 'Test' }))
|
||||
).toEqual({
|
||||
expect(reducer(previousState, taskToggled({ id: 'some-id', groupName: 'Test' }))).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
@@ -300,9 +298,7 @@ test('toggled tasks should be on top of the list', () => {
|
||||
],
|
||||
}
|
||||
|
||||
expect(
|
||||
reducer(previousState, taskToggled({ id: 'another-id', groupName: 'Test' }))
|
||||
).toEqual({
|
||||
expect(reducer(previousState, taskToggled({ id: 'another-id', groupName: 'Test' }))).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
@@ -352,9 +348,7 @@ it('should handle an existing completed task being toggled', () => {
|
||||
],
|
||||
}
|
||||
|
||||
expect(
|
||||
reducer(previousState, taskToggled({ id: 'some-id', groupName: 'Test' }))
|
||||
).toEqual({
|
||||
expect(reducer(previousState, taskToggled({ id: 'some-id', groupName: 'Test' }))).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
@@ -397,9 +391,7 @@ it('should handle an existing task being deleted', () => {
|
||||
],
|
||||
}
|
||||
|
||||
expect(
|
||||
reducer(previousState, taskDeleted({ id: 'some-id', groupName: 'Test' }))
|
||||
).toEqual({
|
||||
expect(reducer(previousState, taskDeleted({ id: 'some-id', groupName: 'Test' }))).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
@@ -447,9 +439,7 @@ it('should handle opening all tasks that are marked as completed', () => {
|
||||
],
|
||||
}
|
||||
|
||||
expect(
|
||||
reducer(previousState, openAllCompleted({ groupName: 'Test' }))
|
||||
).toEqual({
|
||||
expect(reducer(previousState, openAllCompleted({ groupName: 'Test' }))).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
@@ -509,9 +499,7 @@ it('should handle clear all completed tasks', () => {
|
||||
],
|
||||
}
|
||||
|
||||
expect(
|
||||
reducer(previousState, deleteAllCompleted({ groupName: 'Test' }))
|
||||
).toEqual({
|
||||
expect(reducer(previousState, deleteAllCompleted({ groupName: 'Test' }))).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
@@ -548,9 +536,7 @@ it('should handle loading tasks into the tasks store, if an invalid payload is p
|
||||
}
|
||||
|
||||
expect(reducer(previousState, tasksLoaded('null'))).toEqual(previousState)
|
||||
expect(reducer(previousState, tasksLoaded('undefined'))).toEqual(
|
||||
previousState
|
||||
)
|
||||
expect(reducer(previousState, tasksLoaded('undefined'))).toEqual(previousState)
|
||||
})
|
||||
|
||||
it('should initialize the storage with an empty object', () => {
|
||||
@@ -670,9 +656,7 @@ it('should handle loading tasks into the tasks store, with a valid payload', ()
|
||||
it('should handle adding a new task group', () => {
|
||||
const previousState: TasksState = { schemaVersion: '1.0.0', groups: [] }
|
||||
|
||||
expect(
|
||||
reducer(previousState, tasksGroupAdded({ groupName: 'New group' }))
|
||||
).toEqual({
|
||||
expect(reducer(previousState, tasksGroupAdded({ groupName: 'New group' }))).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
{
|
||||
@@ -701,9 +685,7 @@ it('should handle adding an existing task group', () => {
|
||||
],
|
||||
}
|
||||
|
||||
expect(
|
||||
reducer(previousState, tasksGroupAdded({ groupName: 'Existing group' }))
|
||||
).toEqual(previousState)
|
||||
expect(reducer(previousState, tasksGroupAdded({ groupName: 'Existing group' }))).toEqual(previousState)
|
||||
})
|
||||
|
||||
it('should handle reordering tasks from the same section', () => {
|
||||
@@ -744,8 +726,8 @@ it('should handle reordering tasks from the same section', () => {
|
||||
swapTaskIndex: 0,
|
||||
withTaskIndex: 1,
|
||||
isSameSection: true,
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
@@ -814,8 +796,8 @@ it('should handle reordering tasks from different sections', () => {
|
||||
swapTaskIndex: 0,
|
||||
withTaskIndex: 1,
|
||||
isSameSection: false,
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
groups: [
|
||||
@@ -893,7 +875,7 @@ it('should handle reordering task groups', () => {
|
||||
tasksGroupReordered({
|
||||
swapGroupIndex: 0,
|
||||
withGroupIndex: 1,
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
const expectedState = {
|
||||
@@ -978,10 +960,7 @@ it('should handle deleting groups', () => {
|
||||
],
|
||||
}
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupDeleted({ groupName: 'Testing' })
|
||||
)
|
||||
const currentState = reducer(previousState, tasksGroupDeleted({ groupName: 'Testing' }))
|
||||
|
||||
const expectedState = {
|
||||
schemaVersion: '1.0.0',
|
||||
@@ -1054,10 +1033,7 @@ it('should not merge the same group', () => {
|
||||
],
|
||||
}
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupMerged({ groupName: 'Testing', mergeWith: 'Testing' })
|
||||
)
|
||||
const currentState = reducer(previousState, tasksGroupMerged({ groupName: 'Testing', mergeWith: 'Testing' }))
|
||||
|
||||
expect(currentState).toEqual(previousState)
|
||||
})
|
||||
@@ -1104,7 +1080,7 @@ it('should handle merging groups', () => {
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupMerged({ groupName: 'Test group #3', mergeWith: 'Test group #2' })
|
||||
tasksGroupMerged({ groupName: 'Test group #3', mergeWith: 'Test group #2' }),
|
||||
)
|
||||
|
||||
expect(currentState).toMatchObject({
|
||||
@@ -1171,10 +1147,7 @@ it('should handle renaming a group', () => {
|
||||
],
|
||||
}
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupRenamed({ groupName: 'Testing', newName: 'Tested' })
|
||||
)
|
||||
const currentState = reducer(previousState, tasksGroupRenamed({ groupName: 'Testing', newName: 'Tested' }))
|
||||
|
||||
expect(currentState).toEqual({
|
||||
schemaVersion: '1.0.0',
|
||||
@@ -1245,10 +1218,7 @@ it("should rename a group and preserve it's current order", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupRenamed({ groupName: '2nd group', newName: 'Middle group' })
|
||||
)
|
||||
const currentState = reducer(previousState, tasksGroupRenamed({ groupName: '2nd group', newName: 'Middle group' }))
|
||||
|
||||
expect(currentState).toMatchObject({
|
||||
schemaVersion: '1.0.0',
|
||||
@@ -1330,10 +1300,7 @@ it('should handle collapsing groups', () => {
|
||||
],
|
||||
}
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupCollapsed({ groupName: 'Testing', collapsed: true })
|
||||
)
|
||||
const currentState = reducer(previousState, tasksGroupCollapsed({ groupName: 'Testing', collapsed: true }))
|
||||
|
||||
const expectedState = {
|
||||
schemaVersion: '1.0.0',
|
||||
@@ -1418,10 +1385,7 @@ it('should handle saving task draft for groups', () => {
|
||||
],
|
||||
}
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupDraft({ groupName: 'Tests', draft: 'Remember to ...' })
|
||||
)
|
||||
const currentState = reducer(previousState, tasksGroupDraft({ groupName: 'Tests', draft: 'Remember to ...' }))
|
||||
|
||||
const expectedState = {
|
||||
schemaVersion: '1.0.0',
|
||||
@@ -1495,10 +1459,7 @@ it('should handle setting a group as last active', () => {
|
||||
],
|
||||
}
|
||||
|
||||
const currentState = reducer(
|
||||
previousState,
|
||||
tasksGroupLastActive({ groupName: 'Testing' })
|
||||
)
|
||||
const currentState = reducer(previousState, tasksGroupLastActive({ groupName: 'Testing' }))
|
||||
|
||||
expect(currentState).toMatchObject({
|
||||
schemaVersion: '1.0.0',
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import {
|
||||
arrayMoveImmutable,
|
||||
isJsonString,
|
||||
parseMarkdownTasks,
|
||||
} from '../../common/utils'
|
||||
import { arrayMoveImmutable, isJsonString, parseMarkdownTasks } from '../../common/utils'
|
||||
|
||||
export type TasksState = {
|
||||
schemaVersion: string
|
||||
@@ -44,7 +40,7 @@ const tasksSlice = createSlice({
|
||||
action: PayloadAction<{
|
||||
task: { id: string; description: string }
|
||||
groupName: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName, task } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
@@ -63,7 +59,7 @@ const tasksSlice = createSlice({
|
||||
action: PayloadAction<{
|
||||
task: { id: string; description: string }
|
||||
groupName: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName, task } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
@@ -77,10 +73,7 @@ const tasksSlice = createSlice({
|
||||
currentTask.description = task.description
|
||||
currentTask.updatedAt = new Date()
|
||||
},
|
||||
taskDeleted(
|
||||
state,
|
||||
action: PayloadAction<{ id: string; groupName: string }>
|
||||
) {
|
||||
taskDeleted(state, action: PayloadAction<{ id: string; groupName: string }>) {
|
||||
const { id, groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
@@ -88,10 +81,7 @@ const tasksSlice = createSlice({
|
||||
}
|
||||
group.tasks = group.tasks.filter((task) => task.id !== id)
|
||||
},
|
||||
taskToggled(
|
||||
state,
|
||||
action: PayloadAction<{ id: string; groupName: string }>
|
||||
) {
|
||||
taskToggled(state, action: PayloadAction<{ id: string; groupName: string }>) {
|
||||
const { id, groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
if (!group) {
|
||||
@@ -140,10 +130,9 @@ const tasksSlice = createSlice({
|
||||
swapTaskIndex: number
|
||||
withTaskIndex: number
|
||||
isSameSection: boolean
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName, swapTaskIndex, withTaskIndex, isSameSection } =
|
||||
action.payload
|
||||
const { groupName, swapTaskIndex, withTaskIndex, isSameSection } = action.payload
|
||||
if (!isSameSection) {
|
||||
return
|
||||
}
|
||||
@@ -151,17 +140,13 @@ const tasksSlice = createSlice({
|
||||
if (!group) {
|
||||
return
|
||||
}
|
||||
group.tasks = arrayMoveImmutable(
|
||||
group.tasks,
|
||||
swapTaskIndex,
|
||||
withTaskIndex
|
||||
)
|
||||
group.tasks = arrayMoveImmutable(group.tasks, swapTaskIndex, withTaskIndex)
|
||||
},
|
||||
tasksGroupAdded(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
@@ -178,20 +163,16 @@ const tasksSlice = createSlice({
|
||||
action: PayloadAction<{
|
||||
swapGroupIndex: number
|
||||
withGroupIndex: number
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { swapGroupIndex, withGroupIndex } = action.payload
|
||||
state.groups = arrayMoveImmutable(
|
||||
state.groups,
|
||||
swapGroupIndex,
|
||||
withGroupIndex
|
||||
)
|
||||
state.groups = arrayMoveImmutable(state.groups, swapGroupIndex, withGroupIndex)
|
||||
},
|
||||
tasksGroupDeleted(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName } = action.payload
|
||||
state.groups = state.groups.filter((item) => item.name !== groupName)
|
||||
@@ -201,7 +182,7 @@ const tasksSlice = createSlice({
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
mergeWith: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName, mergeWith } = action.payload
|
||||
if (groupName === mergeWith) {
|
||||
@@ -224,7 +205,7 @@ const tasksSlice = createSlice({
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
newName: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName, newName } = action.payload
|
||||
if (groupName === newName) {
|
||||
@@ -241,7 +222,7 @@ const tasksSlice = createSlice({
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
collapsed: boolean
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName, collapsed } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
@@ -255,7 +236,7 @@ const tasksSlice = createSlice({
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
draft: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName, draft } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
@@ -268,7 +249,7 @@ const tasksSlice = createSlice({
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
groupName: string
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { groupName } = action.payload
|
||||
const group = state.groups.find((item) => item.name === groupName)
|
||||
@@ -277,10 +258,7 @@ const tasksSlice = createSlice({
|
||||
}
|
||||
group.lastActive = new Date()
|
||||
},
|
||||
tasksLegacyContentMigrated(
|
||||
state,
|
||||
{ payload }: PayloadAction<{ continue: boolean }>
|
||||
) {
|
||||
tasksLegacyContentMigrated(state, { payload }: PayloadAction<{ continue: boolean }>) {
|
||||
if (!state.legacyContent) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -10,11 +10,7 @@ import styled from 'styled-components'
|
||||
import { store } from './app/store'
|
||||
import { useAppDispatch, useAppSelector } from './app/hooks'
|
||||
import CreateGroup from './features/tasks/CreateGroup'
|
||||
import {
|
||||
setCanEdit,
|
||||
setIsRunningOnMobile,
|
||||
setSpellCheckerEnabled,
|
||||
} from './features/settings/settings-slice'
|
||||
import { setCanEdit, setIsRunningOnMobile, setSpellCheckerEnabled } from './features/settings/settings-slice'
|
||||
import { tasksLoaded } from './features/tasks/tasks-slice'
|
||||
import InvalidContentError from './features/tasks/InvalidContentError'
|
||||
import MigrateLegacyContent from './features/tasks/MigrateLegacyContent'
|
||||
@@ -69,8 +65,7 @@ const TaskEditor: React.FC = () => {
|
||||
onNoteValueChange: async (currentNote: any) => {
|
||||
note.current = currentNote
|
||||
|
||||
const editable =
|
||||
!currentNote.content.appData['org.standardnotes.sn'].locked ?? true
|
||||
const editable = !currentNote.content.appData['org.standardnotes.sn'].locked ?? true
|
||||
const spellCheckEnabled = currentNote.content.spellcheck
|
||||
|
||||
dispatch(setCanEdit(editable))
|
||||
@@ -106,16 +101,10 @@ const TaskEditor: React.FC = () => {
|
||||
|
||||
editorKit.current!.saveItemWithPresave(currentNote, () => {
|
||||
const { schemaVersion, groups } = store.getState().tasks
|
||||
currentNote.content.text = JSON.stringify(
|
||||
{ schemaVersion, groups },
|
||||
null,
|
||||
2
|
||||
)
|
||||
currentNote.content.text = JSON.stringify({ schemaVersion, groups }, null, 2)
|
||||
|
||||
currentNote.content.preview_plain = getPlainPreview(groups)
|
||||
currentNote.content.preview_html = renderToString(
|
||||
<NotePreview groupedTasks={groups} />
|
||||
)
|
||||
currentNote.content.preview_html = renderToString(<NotePreview groupedTasks={groups} />)
|
||||
})
|
||||
}, [])
|
||||
|
||||
@@ -186,5 +175,5 @@ ReactDOM.render(
|
||||
<TaskEditor />
|
||||
</Provider>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
document.getElementById('root'),
|
||||
)
|
||||
|
||||
@@ -17,20 +17,12 @@ const defaultMockState: RootState = {
|
||||
},
|
||||
}
|
||||
|
||||
export function testRender(
|
||||
ui: React.ReactElement,
|
||||
renderOptions?: RenderOptions,
|
||||
state?: Partial<RootState>
|
||||
) {
|
||||
export function testRender(ui: React.ReactElement, renderOptions?: RenderOptions, state?: Partial<RootState>) {
|
||||
const mockStore = configureStore()({
|
||||
...defaultMockState,
|
||||
...state,
|
||||
})
|
||||
function Wrapper({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactElement<any, string | React.JSXElementConstructor<any>>
|
||||
}) {
|
||||
function Wrapper({ children }: { children: React.ReactElement<any, string | React.JSXElementConstructor<any>> }) {
|
||||
return <Provider store={mockStore}>{children}</Provider>
|
||||
}
|
||||
return {
|
||||
|
||||
1
packages/components/src/org.standardnotes.markdown-visual/.gitignore
vendored
Normal file
1
packages/components/src/org.standardnotes.markdown-visual/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn run lint-staged
|
||||
@@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
@@ -0,0 +1,71 @@
|
||||
# markdown-visual
|
||||
|
||||
A lightweight WYSIWYG markdown editor, derivated from Milkdown editor
|
||||
|
||||
## Development
|
||||
|
||||
**Prerequisites:** Install [Node.js](https://nodejs.org/en/), [Yarn](https://classic.yarnpkg.com/en/docs/install/), and [Git](https://github.com/git-guides/install-git) on your computer.
|
||||
|
||||
The general instructions setting up an environment to develop Standard Notes extensions can be found [here](https://docs.standardnotes.com/extensions/local-setup). You can also follow these instructions:
|
||||
|
||||
1. Fork the [repository](https://github.com/standardnotes/markdown-visual) on GitHub.
|
||||
1. [Clone](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) your fork of the repository.
|
||||
1. Run `cd markdown-visual` to enter the `markdown-visual` directory.
|
||||
1. Run `yarn install` to install the dependencies on your machine as they are described in `yarn.lock`.
|
||||
|
||||
### Testing in the browser
|
||||
|
||||
1. To run the app in development mode, run `yarn start` and visit http://localhost:8001. Press `ctrl/cmd + C` to exit development mode.
|
||||
|
||||
### Testing in the Standard Notes app
|
||||
|
||||
1. Create an `ext.json` in the `public` directory. You have three options:
|
||||
1. Use `sample.ext.json`.
|
||||
1. Create `ext.json` as a copy of `sample.ext.json`.
|
||||
1. Follow the instructions [here](https://docs.standardnotes.com/extensions/local-setup) with `url: "http://localhost:8001/index.html"`.
|
||||
1. Install http-server using `npm install -g http-server` then run `http-server . -p 8080 --cors` to serve the root directory at http://localhost:8080.
|
||||
1. To build the app, run `yarn build`.
|
||||
1. Install the editor into the [web](https://app.standardnotes.com) or [desktop](https://standardnotes.com/download) app with `http://localhost:8080/sample.ext.json` or with your custom `ext.json`. Press `ctrl/cmd + C` to shut down the server.
|
||||
|
||||
### Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
#### `yarn start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:8001](http://localhost:8001) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
#### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
#### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
#### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
### Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"name": "@standardnotes/markdown-visual",
|
||||
"version": "1.0.7",
|
||||
"author": "Johnny Almonte <johnny@standardnotes.com>",
|
||||
"description": "A lightweight WYSIWYG markdown editor for Standard Notes, derived from Milkdown.",
|
||||
"keywords": [
|
||||
"Standard Notes",
|
||||
"Standard Notes Extensions"
|
||||
],
|
||||
"sn": {
|
||||
"main": "build/index.html"
|
||||
},
|
||||
"private": true,
|
||||
"homepage": ".",
|
||||
"scripts": {
|
||||
"analyze": "source-map-explorer 'build/static/js/*.js'",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
"lint": "prettier --write 'src/**/*.{html,css,scss,js,jsx,ts,tsx,json}' README.md",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@codemirror/lang-markdown": "^0.19.6",
|
||||
"@milkdown/core": "5.5.0",
|
||||
"@milkdown/plugin-clipboard": "5.5.0",
|
||||
"@milkdown/plugin-cursor": "5.5.0",
|
||||
"@milkdown/plugin-diagram": "5.5.0",
|
||||
"@milkdown/plugin-history": "5.5.0",
|
||||
"@milkdown/plugin-indent": "5.5.0",
|
||||
"@milkdown/plugin-listener": "5.5.0",
|
||||
"@milkdown/plugin-math": "5.5.0",
|
||||
"@milkdown/plugin-menu": "5.5.0",
|
||||
"@milkdown/plugin-prism": "5.5.0",
|
||||
"@milkdown/plugin-slash": "5.5.0",
|
||||
"@milkdown/plugin-tooltip": "5.5.0",
|
||||
"@milkdown/preset-commonmark": "5.5.0",
|
||||
"@milkdown/preset-gfm": "5.5.0",
|
||||
"@milkdown/prose": "5.5.0",
|
||||
"@milkdown/react": "5.5.0",
|
||||
"@milkdown/theme-nord": "5.5.0",
|
||||
"@standardnotes/editor-kit": "2.2.4",
|
||||
"@testing-library/dom": "^8.11.3",
|
||||
"@testing-library/jest-dom": "^5.16.2",
|
||||
"@testing-library/react": "^12.1.4",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/lodash": "^4.14.179",
|
||||
"@types/marked": "^4.0.2",
|
||||
"@types/node": "^17.0.21",
|
||||
"@types/react": "^17.0.40",
|
||||
"@types/react-dom": "^17.0.13",
|
||||
"@uiw/react-codemirror": "4.5.1",
|
||||
"husky": "*",
|
||||
"katex": "^0.15.2",
|
||||
"lint-staged": "*",
|
||||
"marked": "^4.0.12",
|
||||
"material-icons": "^1.10.8",
|
||||
"prettier": "*",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-icons": "^4.3.1",
|
||||
"react-scripts": "^5.0.0",
|
||||
"sass": "*",
|
||||
"sn-stylekit": "5.2.21",
|
||||
"source-map-explorer": "^2.5.2",
|
||||
"typescript": "*"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"lint-staged": {
|
||||
"README.md": [
|
||||
"prettier --write"
|
||||
],
|
||||
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
||||
"prettier --write"
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="description" content="A lightweight WYSIWYG markdown editor, derivated from Milkdown editor" />
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>Markdown Visual</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "Markdown Visual",
|
||||
"name": "Markdown Visual",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "markdown-visual",
|
||||
"version": "0.1.0",
|
||||
"author": "Johnny Almonte <johnny@standardnotes.com>",
|
||||
"description": "A lightweight WYSIWYG markdown editor, derivated from Milkdown editor",
|
||||
"keywords": [
|
||||
"Standard Notes",
|
||||
"Standard Notes Extensions"
|
||||
],
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/standardnotes/markdown-visual.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/standardnotes/markdown-visual/issues"
|
||||
},
|
||||
"sn": {
|
||||
"main": "build/index.html"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Markdown Visual - Dev",
|
||||
"note_type": "markdown",
|
||||
"file_type": "md",
|
||||
"interchangeable": false,
|
||||
"spellcheckControl": true,
|
||||
"identifier": "org.standardnotes.markdown-visual-dev",
|
||||
"content_type": "SN|Component",
|
||||
"area": "editor-editor",
|
||||
"version": "1.0.0",
|
||||
"description": "A lightweight WYSIWYG markdown editor, derivated from Milkdown editor",
|
||||
"url": "http://localhost:8001/",
|
||||
"marketing_url": "",
|
||||
"flags": ["New"]
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import './styles.scss'
|
||||
|
||||
import { basicSetup } from '@codemirror/basic-setup'
|
||||
import { markdown } from '@codemirror/lang-markdown'
|
||||
import CodeMirrorReact, { EditorView, ReactCodeMirrorRef } from '@uiw/react-codemirror'
|
||||
import { forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
||||
|
||||
export type CodeMirrorRef = {
|
||||
update: (markdown: string) => void
|
||||
}
|
||||
|
||||
type CodeMirrorProps = {
|
||||
onChange: (text: string) => void
|
||||
value?: string
|
||||
editable: boolean
|
||||
spellcheck: boolean
|
||||
}
|
||||
|
||||
const CodeMirror = (
|
||||
{ onChange, value, editable, spellcheck }: CodeMirrorProps,
|
||||
ref: React.ForwardedRef<CodeMirrorRef>,
|
||||
) => {
|
||||
const [hasFocus, setFocus] = useState(false)
|
||||
const editorRef = useRef<ReactCodeMirrorRef>(null)
|
||||
const extensions = [
|
||||
basicSetup,
|
||||
markdown(),
|
||||
EditorView.lineWrapping,
|
||||
EditorView.updateListener.of((update) => {
|
||||
if (update.focusChanged) {
|
||||
setFocus(update.view.hasFocus)
|
||||
}
|
||||
|
||||
if (update.docChanged) {
|
||||
const text = update.state.doc.toString()
|
||||
onChange(text)
|
||||
}
|
||||
}),
|
||||
]
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
update: (markdown: string) => {
|
||||
/**
|
||||
* This will prevent the CodeMirror editor from being updated again when an update
|
||||
* is sent back from the Milkdown editor.
|
||||
*/
|
||||
if (hasFocus) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!editable || !editorRef.current) {
|
||||
return
|
||||
}
|
||||
|
||||
const view = editorRef.current.view
|
||||
if (!view) {
|
||||
return
|
||||
}
|
||||
|
||||
const { state } = view
|
||||
if (!state) {
|
||||
return
|
||||
}
|
||||
|
||||
const document = state.doc
|
||||
if (!document) {
|
||||
return
|
||||
}
|
||||
|
||||
view.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: document.toString().length,
|
||||
insert: markdown,
|
||||
},
|
||||
})
|
||||
},
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className="codemirror-container">
|
||||
<CodeMirrorReact
|
||||
ref={editorRef}
|
||||
extensions={extensions}
|
||||
value={value}
|
||||
editable={editable}
|
||||
spellCheck={spellcheck}
|
||||
indentWithTab
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default forwardRef<CodeMirrorRef, CodeMirrorProps>(CodeMirror)
|
||||
@@ -0,0 +1,55 @@
|
||||
.container {
|
||||
.codemirror-container {
|
||||
overflow-y: auto;
|
||||
max-height: 100%;
|
||||
|
||||
.cm-theme-light {
|
||||
.cm-editor {
|
||||
background-color: var(--sn-stylekit-editor-background-color) !important;
|
||||
color: var(--sn-stylekit-editor-foreground-color) !important;
|
||||
font-family: var(--sn-stylekit-monospace-font);
|
||||
-webkit-overflow-scrolling: touch;
|
||||
font-size: calc(var(--sn-stylekit-font-size-editor) - 0.3rem);
|
||||
|
||||
@media only screen and (min-width: 768px) {
|
||||
font-size: calc(var(--sn-stylekit-font-size-editor) - 0.1rem);
|
||||
}
|
||||
|
||||
.cm-content {
|
||||
caret-color: var(--sn-stylekit-editor-foreground-color) !important;
|
||||
}
|
||||
|
||||
.cm-lineNumbers {
|
||||
color: var(--sn-stylekit-neutral-color) !important;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.cm-cursor {
|
||||
border-color: var(--sn-stylekit-info-color) !important;
|
||||
}
|
||||
|
||||
.cm-gutters {
|
||||
background-color: var(--sn-stylekit-background-color) !important;
|
||||
color: var(--sn-stylekit-editor-foreground-color) !important;
|
||||
border-color: var(--sn-stylekit-border-color) !important;
|
||||
}
|
||||
|
||||
.ͼb {
|
||||
color: var(--sn-stylekit-info-color) !important;
|
||||
}
|
||||
|
||||
.cm-selectionBackground {
|
||||
background: var(--sn-stylekit-info-color) !important;
|
||||
}
|
||||
|
||||
.cm-activeLine {
|
||||
background-color: var(--sn-stylekit-secondary-contrast-background-color) !important;
|
||||
}
|
||||
|
||||
.cm-activeLineGutter {
|
||||
background-color: var(--sn-stylekit-contrast-background-color) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { defaultValueCtx, Editor, editorViewOptionsCtx, rootCtx } from '@milkdown/core'
|
||||
import { clipboard } from '@milkdown/plugin-clipboard'
|
||||
import { cursor } from '@milkdown/plugin-cursor'
|
||||
import { diagram } from '@milkdown/plugin-diagram'
|
||||
import { history } from '@milkdown/plugin-history'
|
||||
import { indent } from '@milkdown/plugin-indent'
|
||||
import { listener, listenerCtx } from '@milkdown/plugin-listener'
|
||||
import { math } from '@milkdown/plugin-math'
|
||||
import { prism } from '@milkdown/plugin-prism'
|
||||
import { slash } from '@milkdown/plugin-slash'
|
||||
import { tooltip } from '@milkdown/plugin-tooltip'
|
||||
import { gfm } from '@milkdown/preset-gfm'
|
||||
import { nord } from '@milkdown/theme-nord'
|
||||
|
||||
import { menu } from './plugins/advanced-menu'
|
||||
import { MenuConfig } from './plugins/advanced-menu/config'
|
||||
|
||||
export type CreateEditorParams = {
|
||||
root: HTMLElement | null
|
||||
onChange: (text: string) => void
|
||||
value?: string
|
||||
menuConfig: MenuConfig
|
||||
editable: boolean
|
||||
spellcheck: boolean
|
||||
}
|
||||
|
||||
export const createEditor = ({ root, onChange, value, menuConfig, editable, spellcheck }: CreateEditorParams) => {
|
||||
const editor = Editor.make()
|
||||
.config((ctx) => {
|
||||
ctx.set(rootCtx, root)
|
||||
value && ctx.set(defaultValueCtx, value)
|
||||
|
||||
ctx.get(listenerCtx).markdownUpdated((_, markdown) => {
|
||||
onChange(markdown)
|
||||
})
|
||||
|
||||
ctx.set(editorViewOptionsCtx, {
|
||||
editable: () => editable,
|
||||
})
|
||||
|
||||
root?.setAttribute('spellcheck', JSON.stringify(spellcheck))
|
||||
})
|
||||
.use(nord)
|
||||
.use(clipboard)
|
||||
.use(gfm)
|
||||
.use(listener)
|
||||
.use(math)
|
||||
.use(indent)
|
||||
.use(prism)
|
||||
.use(slash)
|
||||
.use(tooltip)
|
||||
.use(diagram)
|
||||
.use(cursor)
|
||||
.use(history)
|
||||
.use(
|
||||
menu({
|
||||
config: menuConfig,
|
||||
}),
|
||||
)
|
||||
|
||||
return editor
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import './styles.scss'
|
||||
|
||||
import { editorViewCtx, parserCtx } from '@milkdown/core'
|
||||
import { Slice } from '@milkdown/prose'
|
||||
import { EditorRef, ReactEditor, useEditor } from '@milkdown/react'
|
||||
import { forwardRef, useImperativeHandle, useRef } from 'react'
|
||||
|
||||
import { createEditor, CreateEditorParams } from './editor'
|
||||
import { MenuConfig } from './plugins/advanced-menu/config'
|
||||
|
||||
export type MilkdownRef = {
|
||||
update: (markdown: string) => void
|
||||
}
|
||||
|
||||
type MilkdownProps = {
|
||||
onChange: CreateEditorParams['onChange']
|
||||
value?: CreateEditorParams['value']
|
||||
menuConfig: MenuConfig
|
||||
editable: CreateEditorParams['editable']
|
||||
spellcheck: CreateEditorParams['spellcheck']
|
||||
}
|
||||
|
||||
const Milkdown = (
|
||||
{ onChange, value, menuConfig, editable, spellcheck }: MilkdownProps,
|
||||
ref: React.ForwardedRef<MilkdownRef>,
|
||||
) => {
|
||||
const editorRef = useRef<EditorRef>(null)
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
update: (markdown: string) => {
|
||||
if (!editable || !editorRef.current) {
|
||||
return
|
||||
}
|
||||
|
||||
const editor = editorRef.current.get()
|
||||
if (!editor) {
|
||||
return
|
||||
}
|
||||
|
||||
editor.action((ctx) => {
|
||||
const view = ctx.get(editorViewCtx)
|
||||
const parser = ctx.get(parserCtx)
|
||||
const document = parser(markdown)
|
||||
if (!document) {
|
||||
return
|
||||
}
|
||||
|
||||
const state = view.state
|
||||
view.dispatch(
|
||||
state.tr.replace(0, state.doc.content.size, new Slice(document.content, 0, 0)).setMeta('addToHistory', false),
|
||||
)
|
||||
})
|
||||
},
|
||||
}))
|
||||
|
||||
const editor = useEditor(
|
||||
(root) => {
|
||||
return createEditor({
|
||||
root,
|
||||
onChange,
|
||||
value,
|
||||
menuConfig,
|
||||
editable,
|
||||
spellcheck,
|
||||
})
|
||||
},
|
||||
[value, onChange, value, menuConfig, editable, spellcheck],
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="milkdown-container">
|
||||
<ReactEditor ref={editorRef} editor={editor} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default forwardRef<MilkdownRef, MilkdownProps>(Milkdown)
|
||||
@@ -0,0 +1,3 @@
|
||||
# advanced-menu
|
||||
|
||||
An advanced menu plugin for [Milkdown editor](https://saul-mirone.github.io/milkdown/), which is heavily inspired on [@milkdown/plugin-menu](https://github.com/Saul-Mirone/milkdown/tree/main/packages/plugin-menu).
|
||||
@@ -0,0 +1,102 @@
|
||||
/* Copyright 2021, Milkdown by Mirone. */
|
||||
|
||||
import { css } from '@emotion/css'
|
||||
import { CmdKey, commandsCtx, Ctx } from '@milkdown/core'
|
||||
import type { Icon } from '@milkdown/design-system'
|
||||
import type { EditorView } from '@milkdown/prose'
|
||||
import type { Utils } from '@milkdown/utils'
|
||||
|
||||
import type { MenuCommonConfig } from './config'
|
||||
|
||||
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
|
||||
{
|
||||
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>
|
||||
}[Keys]
|
||||
|
||||
type Config<T = any> = {
|
||||
type: 'button'
|
||||
icon: Icon
|
||||
key?: CmdKey<T>
|
||||
callback?: () => void
|
||||
options?: T
|
||||
active?: (view?: EditorView) => boolean
|
||||
alwaysVisible: boolean
|
||||
} & MenuCommonConfig
|
||||
|
||||
export type ButtonConfig = RequireAtLeastOne<Config, 'key' | 'callback'>
|
||||
|
||||
export const button = (utils: Utils, config: Config, ctx: Ctx, view: EditorView) => {
|
||||
const buttonStyle = utils.getStyle((themeTool) => {
|
||||
return css`
|
||||
border: 0;
|
||||
box-sizing: unset;
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
padding: 0.25rem;
|
||||
margin: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: ${themeTool.palette('surface')};
|
||||
color: ${themeTool.palette('solid')};
|
||||
transition: all 0.4s ease-in-out;
|
||||
cursor: pointer;
|
||||
&.active,
|
||||
&:hover {
|
||||
background-color: ${themeTool.palette('secondary', 0.12)};
|
||||
color: ${themeTool.palette('primary')};
|
||||
}
|
||||
&:disabled {
|
||||
display: none;
|
||||
}
|
||||
`
|
||||
})
|
||||
|
||||
const $button = document.createElement('button')
|
||||
$button.setAttribute('type', 'button')
|
||||
$button.classList.add('button')
|
||||
|
||||
if (buttonStyle) {
|
||||
$button.classList.add(buttonStyle)
|
||||
}
|
||||
|
||||
const $label = utils.themeTool.slots.label(config.icon)
|
||||
if ($label) {
|
||||
$button.setAttribute('aria-label', $label)
|
||||
$button.setAttribute('title', $label)
|
||||
}
|
||||
|
||||
const $icon = utils.themeTool.slots.icon(config.icon)
|
||||
$button.appendChild($icon)
|
||||
$button.addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
config.callback && config.callback()
|
||||
config.key && ctx.get(commandsCtx).call(config.key, config.options)
|
||||
})
|
||||
|
||||
if (config.active) {
|
||||
const active = config.active()
|
||||
if (active) {
|
||||
$button.classList.add('active')
|
||||
} else {
|
||||
$button.classList.remove('active')
|
||||
}
|
||||
}
|
||||
|
||||
if (config.alwaysVisible) {
|
||||
$button.removeAttribute('disabled')
|
||||
return $button
|
||||
}
|
||||
|
||||
const disabled = !view.editable || (config.disabled && config.disabled(view))
|
||||
if (disabled) {
|
||||
$button.setAttribute('disabled', 'true')
|
||||
} else {
|
||||
$button.removeAttribute('disabled')
|
||||
}
|
||||
|
||||
return $button
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
import {
|
||||
InsertHr,
|
||||
InsertImage,
|
||||
LiftListItem,
|
||||
SinkListItem,
|
||||
WrapInBlockquote,
|
||||
WrapInBulletList,
|
||||
WrapInOrderedList,
|
||||
} from '@milkdown/preset-commonmark'
|
||||
import { InsertTable, TurnIntoTaskList } from '@milkdown/preset-gfm'
|
||||
import { EditorView, liftListItem, sinkListItem, wrapIn } from '@milkdown/prose'
|
||||
import { ButtonConfig } from './button'
|
||||
import { SelectConfig } from './select'
|
||||
|
||||
export type MenuCommonConfig = {
|
||||
disabled?: (view: EditorView) => boolean
|
||||
}
|
||||
|
||||
export type MenuConfigItem = SelectConfig | ButtonConfig
|
||||
export type MenuConfig = Array<Array<MenuConfigItem>>
|
||||
|
||||
export const menuConfig: any = [
|
||||
[
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'bulletList',
|
||||
key: WrapInBulletList,
|
||||
disabled: (view: EditorView) => {
|
||||
const { state } = view
|
||||
return !wrapIn(state.schema.nodes.bullet_list)(state)
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'orderedList',
|
||||
key: WrapInOrderedList,
|
||||
disabled: (view: EditorView) => {
|
||||
const { state } = view
|
||||
return !wrapIn(state.schema.nodes.ordered_list)(state)
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'taskList',
|
||||
key: TurnIntoTaskList,
|
||||
disabled: (view: EditorView) => {
|
||||
const { state } = view
|
||||
return !wrapIn(state.schema.nodes.task_list_item)(state)
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'liftList',
|
||||
key: LiftListItem,
|
||||
disabled: (view: EditorView) => {
|
||||
const { state } = view
|
||||
return !liftListItem(state.schema.nodes.list_item)(state)
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'sinkList',
|
||||
key: SinkListItem,
|
||||
disabled: (view: EditorView) => {
|
||||
const { state } = view
|
||||
return !sinkListItem(state.schema.nodes.list_item)(state)
|
||||
},
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'image',
|
||||
key: InsertImage,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'table',
|
||||
key: InsertTable,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'quote',
|
||||
key: WrapInBlockquote,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'divider',
|
||||
key: InsertHr,
|
||||
},
|
||||
],
|
||||
]
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2021, Milkdown by Mirone. */
|
||||
|
||||
import { css } from '@emotion/css'
|
||||
import { Utils } from '@milkdown/utils'
|
||||
|
||||
export type DividerConfig = {
|
||||
type: 'divider'
|
||||
group: HTMLElement[]
|
||||
}
|
||||
|
||||
export const divider = (utils: Utils, config: DividerConfig) => {
|
||||
const dividerStyle = utils.getStyle((themeTool) => {
|
||||
return css`
|
||||
flex-shrink: 0;
|
||||
width: ${themeTool.size.lineWidth};
|
||||
background-color: ${themeTool.palette('line')};
|
||||
margin: 0.75rem 1rem;
|
||||
`
|
||||
})
|
||||
|
||||
const $divider = document.createElement('div')
|
||||
$divider.classList.add('divider')
|
||||
|
||||
if (dividerStyle) {
|
||||
$divider.classList.add(dividerStyle)
|
||||
}
|
||||
|
||||
const disabled = config.group.every((x) => x.getAttribute('disabled') || x.classList.contains('disabled'))
|
||||
|
||||
if (disabled) {
|
||||
$divider.classList.add('disabled')
|
||||
} else {
|
||||
$divider.classList.remove('disabled')
|
||||
}
|
||||
|
||||
return $divider
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* Copyright 2021, Milkdown by Mirone. */
|
||||
|
||||
import { createCmd, createCmdKey, Ctx } from '@milkdown/core'
|
||||
import { EditorView, Plugin, PluginKey, selectParentNode } from '@milkdown/prose'
|
||||
import { createPlugin } from '@milkdown/utils'
|
||||
|
||||
import { MenuConfig, menuConfig } from './config'
|
||||
import { Manager } from './manager'
|
||||
import { HandleDOM, MenuBar } from './menuBar'
|
||||
|
||||
export type Options = {
|
||||
config: MenuConfig
|
||||
domHandler: HandleDOM
|
||||
}
|
||||
|
||||
export { menuConfig } from './config'
|
||||
|
||||
export const menu = createPlugin<string, Options>((utils, options) => {
|
||||
const config = options?.config ?? menuConfig
|
||||
const domHandler = options?.domHandler
|
||||
|
||||
let restoreDOM: (() => void) | null = null
|
||||
let menu: HTMLDivElement | null = null
|
||||
let manager: Manager | null = null
|
||||
|
||||
const SelectParent = createCmdKey()
|
||||
|
||||
const initIfNecessary = (ctx: Ctx, editorView: EditorView) => {
|
||||
if (!menu) {
|
||||
const [_menu, _restoreDOM] = MenuBar(utils, editorView, ctx, domHandler)
|
||||
menu = _menu
|
||||
restoreDOM = () => {
|
||||
_restoreDOM()
|
||||
menu = null
|
||||
manager = null
|
||||
}
|
||||
}
|
||||
|
||||
if (!manager) {
|
||||
manager = new Manager(config, utils, ctx, menu, editorView)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
commands: () => [createCmd(SelectParent, () => selectParentNode)],
|
||||
prosePlugins: (_, ctx) => {
|
||||
const plugin = new Plugin({
|
||||
key: new PluginKey('milkdown-advanced-menu'),
|
||||
view: (editorView) => {
|
||||
initIfNecessary(ctx, editorView)
|
||||
if (editorView.editable) {
|
||||
manager?.update(editorView)
|
||||
}
|
||||
return {
|
||||
update: (view) => manager?.update(view),
|
||||
destroy: () => restoreDOM?.(),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
return [plugin]
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,122 @@
|
||||
/* Copyright 2021, Milkdown by Mirone. */
|
||||
|
||||
import { Ctx } from '@milkdown/core'
|
||||
import { EditorView } from '@milkdown/prose'
|
||||
import { Utils } from '@milkdown/utils'
|
||||
|
||||
import { button, ButtonConfig } from './button'
|
||||
import { MenuConfig, MenuConfigItem } from './config'
|
||||
import { divider, DividerConfig } from './divider'
|
||||
import { select, SelectConfig } from './select'
|
||||
|
||||
type InnerConfig = (MenuConfigItem | DividerConfig) & { $: HTMLElement }
|
||||
|
||||
export class Manager {
|
||||
private config: InnerConfig[]
|
||||
|
||||
constructor(originalConfig: MenuConfig, private utils: Utils, private ctx: Ctx, menu: HTMLElement, view: EditorView) {
|
||||
this.config = originalConfig
|
||||
.map((xs) =>
|
||||
xs.map((x) => ({
|
||||
...x,
|
||||
$: this.$create(x, view),
|
||||
})),
|
||||
)
|
||||
.map((xs, i): Array<InnerConfig> => {
|
||||
if (i === originalConfig.length - 1) {
|
||||
return xs
|
||||
}
|
||||
const dividerConfig: DividerConfig = {
|
||||
type: 'divider',
|
||||
group: xs.map((x) => x.$),
|
||||
}
|
||||
return [
|
||||
...xs,
|
||||
{
|
||||
...dividerConfig,
|
||||
$: this.$create(dividerConfig, view),
|
||||
},
|
||||
]
|
||||
})
|
||||
.flat()
|
||||
|
||||
this.config.forEach((x) => menu.appendChild(x.$))
|
||||
}
|
||||
|
||||
public update(view: EditorView) {
|
||||
const enabled = view.editable
|
||||
|
||||
this.config.forEach((config) => {
|
||||
switch (config.type) {
|
||||
case 'button': {
|
||||
if (config.active) {
|
||||
const active = config.active(view)
|
||||
if (active) {
|
||||
config.$.classList.add('active')
|
||||
} else {
|
||||
config.$.classList.remove('active')
|
||||
}
|
||||
}
|
||||
|
||||
if (config.alwaysVisible) {
|
||||
config.$.removeAttribute('disabled')
|
||||
return
|
||||
}
|
||||
|
||||
const disabled = !enabled || (config.disabled && config.disabled(view))
|
||||
if (disabled) {
|
||||
config.$.setAttribute('disabled', 'true')
|
||||
} else {
|
||||
config.$.removeAttribute('disabled')
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'select': {
|
||||
if (config.alwaysVisible) {
|
||||
config.$.removeAttribute('disabled')
|
||||
return
|
||||
}
|
||||
|
||||
const disabled = !enabled || (config.disabled && config.disabled(view))
|
||||
if (disabled) {
|
||||
config.$.classList.add('disabled')
|
||||
config.$.children[0].setAttribute('disabled', 'true')
|
||||
} else {
|
||||
config.$.classList.remove('disabled')
|
||||
config.$.children[0].removeAttribute('disabled')
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'divider': {
|
||||
const disabled = config.group.every((x) => x.getAttribute('disabled') || x.classList.contains('disabled'))
|
||||
if (disabled) {
|
||||
config.$.classList.add('disabled')
|
||||
} else {
|
||||
config.$.classList.remove('disabled')
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private $create(item: ButtonConfig | DividerConfig | SelectConfig, view: EditorView): HTMLElement {
|
||||
const { utils, ctx } = this
|
||||
|
||||
switch (item.type) {
|
||||
case 'button': {
|
||||
return button(utils, item, ctx, view)
|
||||
}
|
||||
case 'select': {
|
||||
return select(utils, item, ctx, view)
|
||||
}
|
||||
case 'divider': {
|
||||
return divider(utils, item)
|
||||
}
|
||||
default:
|
||||
throw new Error()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/* Copyright 2021, Milkdown by Mirone. */
|
||||
|
||||
import { css } from '@emotion/css'
|
||||
import { Ctx, rootCtx } from '@milkdown/core'
|
||||
import { EditorView } from '@milkdown/prose'
|
||||
import { Utils } from '@milkdown/utils'
|
||||
|
||||
export const MenuBar = (utils: Utils, view: EditorView, ctx: Ctx, domHandler: HandleDOM = defaultDOMHandler) => {
|
||||
const menuWrapper = document.createElement('div')
|
||||
menuWrapper.classList.add('milkdown-menu-wrapper')
|
||||
const menu = document.createElement('div')
|
||||
menu.classList.add('milkdown-menu')
|
||||
|
||||
const editorDOM = view.dom as HTMLDivElement
|
||||
|
||||
const editorWrapperStyle = utils.getStyle((themeTool) => {
|
||||
return themeTool.mixin.scrollbar('y')
|
||||
})
|
||||
|
||||
if (editorWrapperStyle) {
|
||||
editorDOM.classList.add(editorWrapperStyle)
|
||||
}
|
||||
|
||||
const menuStyle = utils.getStyle((themeTool) => {
|
||||
const border = themeTool.mixin.border()
|
||||
const scrollbar = themeTool.mixin.scrollbar('x')
|
||||
const style = css`
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
overflow-x: auto;
|
||||
${border};
|
||||
${scrollbar};
|
||||
background: ${themeTool.palette('surface')};
|
||||
-webkit-overflow-scrolling: auto;
|
||||
.disabled {
|
||||
display: none;
|
||||
}
|
||||
`
|
||||
return style
|
||||
})
|
||||
|
||||
if (menuStyle) {
|
||||
menuStyle.split(' ').forEach((x) => menu.classList.add(x))
|
||||
}
|
||||
|
||||
const root = ctx.get(rootCtx)
|
||||
|
||||
const editorRoot = getRoot(root) as HTMLElement
|
||||
const milkdownDOM = editorDOM.parentElement
|
||||
|
||||
if (!milkdownDOM) {
|
||||
throw new Error('No parent node found')
|
||||
}
|
||||
|
||||
domHandler({
|
||||
menu,
|
||||
menuWrapper,
|
||||
editorDOM,
|
||||
editorRoot,
|
||||
milkdownDOM,
|
||||
})
|
||||
|
||||
const restoreDOM = () => {
|
||||
restore({
|
||||
menu,
|
||||
menuWrapper,
|
||||
editorDOM,
|
||||
editorRoot,
|
||||
milkdownDOM,
|
||||
})
|
||||
}
|
||||
|
||||
return [menu, restoreDOM] as const
|
||||
}
|
||||
|
||||
export type HandleDOMParams = {
|
||||
menu: HTMLDivElement
|
||||
menuWrapper: HTMLDivElement
|
||||
editorRoot: HTMLElement
|
||||
milkdownDOM: HTMLElement
|
||||
editorDOM: HTMLDivElement
|
||||
}
|
||||
|
||||
export type HandleDOM = (params: HandleDOMParams) => void
|
||||
|
||||
const restore: HandleDOM = ({ milkdownDOM, editorRoot, menu, menuWrapper }) => {
|
||||
editorRoot.appendChild(milkdownDOM)
|
||||
menuWrapper.remove()
|
||||
menu.remove()
|
||||
}
|
||||
|
||||
const defaultDOMHandler: HandleDOM = ({ menu, menuWrapper, editorRoot, milkdownDOM }) => {
|
||||
menuWrapper.appendChild(menu)
|
||||
editorRoot.replaceChild(menuWrapper, milkdownDOM)
|
||||
menuWrapper.appendChild(milkdownDOM)
|
||||
}
|
||||
|
||||
const getRoot = (root: string | Node | null | undefined) => {
|
||||
if (!root) return document.body
|
||||
if (typeof root === 'string') {
|
||||
const el = document.querySelector(root)
|
||||
if (el) return el
|
||||
return document.body
|
||||
}
|
||||
return root
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/* Copyright 2021, Milkdown by Mirone. */
|
||||
|
||||
import { css } from '@emotion/css'
|
||||
import { CmdKey, commandsCtx, Ctx } from '@milkdown/core'
|
||||
import { EditorView } from '@milkdown/prose'
|
||||
import { Utils } from '@milkdown/utils'
|
||||
|
||||
import type { MenuCommonConfig } from './config'
|
||||
|
||||
type SelectOptions = {
|
||||
id: string
|
||||
text: string
|
||||
}
|
||||
|
||||
export type SelectConfig<T = any> = {
|
||||
type: 'select'
|
||||
text: string
|
||||
options: SelectOptions[]
|
||||
active?: (view: EditorView) => string
|
||||
onSelect: (id: string, view: EditorView) => [key: CmdKey<T>, info?: T]
|
||||
alwaysVisible: boolean
|
||||
} & MenuCommonConfig
|
||||
|
||||
export const select = (utils: Utils, config: SelectConfig, ctx: Ctx, view: EditorView) => {
|
||||
const selectStyle = utils.getStyle((themeTool) => {
|
||||
return css`
|
||||
flex-shrink: 0;
|
||||
font-weight: 500;
|
||||
font-size: 0.875rem;
|
||||
${themeTool.mixin.border('right')};
|
||||
${themeTool.mixin.border('left')};
|
||||
.menu-selector {
|
||||
border: 0;
|
||||
box-sizing: unset;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
color: ${themeTool.palette('neutral', 0.87)};
|
||||
display: flex;
|
||||
padding: 0.25rem 0.5rem;
|
||||
margin: 0.5rem;
|
||||
background: ${themeTool.palette('secondary', 0.12)};
|
||||
width: 10.375rem;
|
||||
&:disabled {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.menu-selector-value {
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.menu-selector-list {
|
||||
width: calc(12.375rem);
|
||||
position: absolute;
|
||||
top: 3rem;
|
||||
background: ${themeTool.palette('surface')};
|
||||
${themeTool.mixin.border()};
|
||||
${themeTool.mixin.shadow()};
|
||||
border-bottom-left-radius: ${themeTool.size.radius};
|
||||
border-bottom-right-radius: ${themeTool.size.radius};
|
||||
z-index: 3;
|
||||
}
|
||||
.menu-selector-list-item {
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
padding: 0.75rem 1rem;
|
||||
line-height: 1.5rem;
|
||||
width: 100%;
|
||||
color: ${themeTool.palette('neutral', 0.87)};
|
||||
&:hover {
|
||||
background: ${themeTool.palette('secondary', 0.12)};
|
||||
color: ${themeTool.palette('primary')};
|
||||
}
|
||||
}
|
||||
&.fold {
|
||||
border-color: transparent;
|
||||
.menu-selector {
|
||||
background: unset;
|
||||
}
|
||||
.menu-selector-list {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
`
|
||||
})
|
||||
|
||||
const selectorWrapper = document.createElement('div')
|
||||
selectorWrapper.classList.add('menu-selector-wrapper', 'fold')
|
||||
|
||||
const selector = document.createElement('button')
|
||||
selector.setAttribute('type', 'button')
|
||||
selector.classList.add('menu-selector', 'fold')
|
||||
selector.addEventListener('mousedown', (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
selectorWrapper.classList.toggle('fold')
|
||||
selectorList.style.left = `${
|
||||
selectorWrapper.getBoundingClientRect().left - view.dom.getBoundingClientRect().left
|
||||
}px`
|
||||
})
|
||||
view.dom.addEventListener('click', () => {
|
||||
selectorWrapper.classList.add('fold')
|
||||
})
|
||||
|
||||
const selectorValue = document.createElement('span')
|
||||
selectorValue.classList.add('menu-selector-value')
|
||||
selectorValue.textContent = config.text
|
||||
|
||||
const selectorButton = utils.themeTool.slots.icon('downArrow')
|
||||
selectorButton.setAttribute('aria-hidden', 'true')
|
||||
|
||||
selectorWrapper.appendChild(selector)
|
||||
selector.appendChild(selectorValue)
|
||||
selector.appendChild(selectorButton)
|
||||
|
||||
const selectorList = document.createElement('div')
|
||||
selectorList.classList.add('menu-selector-list')
|
||||
config.options.forEach((option) => {
|
||||
const selectorListItem = document.createElement('button')
|
||||
selectorListItem.setAttribute('type', 'button')
|
||||
selectorListItem.dataset.id = option.id
|
||||
selectorListItem.textContent = option.text
|
||||
selectorListItem.classList.add('menu-selector-list-item')
|
||||
selectorList.appendChild(selectorListItem)
|
||||
})
|
||||
|
||||
selectorList.addEventListener('mousedown', (e) => {
|
||||
const { target } = e
|
||||
if (target instanceof HTMLButtonElement && target.dataset.id) {
|
||||
ctx.get(commandsCtx).call(...config.onSelect(target.dataset.id, view))
|
||||
selectorWrapper.classList.add('fold')
|
||||
}
|
||||
})
|
||||
|
||||
selectorWrapper.appendChild(selectorList)
|
||||
|
||||
if (selectStyle) {
|
||||
selectorWrapper.classList.add(selectStyle)
|
||||
}
|
||||
|
||||
if (config.alwaysVisible) {
|
||||
selector.removeAttribute('disabled')
|
||||
return selectorWrapper
|
||||
}
|
||||
|
||||
const disabled = !view.editable || (config.disabled && config.disabled(view))
|
||||
if (disabled) {
|
||||
selector.classList.add('disabled')
|
||||
selector.children[0].setAttribute('disabled', 'true')
|
||||
} else {
|
||||
selector.classList.remove('disabled')
|
||||
selector.children[0].removeAttribute('disabled')
|
||||
}
|
||||
|
||||
return selectorWrapper
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
.container {
|
||||
.milkdown-container {
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
flex-grow: 1;
|
||||
justify-content: flex-start;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
|
||||
> div {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.milkdown-menu-wrapper {
|
||||
position: relative;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
|
||||
.milkdown-menu {
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
left: 0;
|
||||
right: 0;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
overflow-x: auto;
|
||||
border: none;
|
||||
background: rgba(var(--surface), 1);
|
||||
background-color: var(--sn-stylekit-contrast-background-color);
|
||||
border-color: var(--sn-stylekit-border-color);
|
||||
position: absolute;
|
||||
|
||||
.button {
|
||||
background-color: var(--sn-stylekit-secondary-background-color);
|
||||
color: var(--sn-stylekit-neutral-color);
|
||||
-webkit-transition: none;
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.button.active {
|
||||
background-color: var(--sn-stylekit-neutral-color) !important;
|
||||
color: var(--sn-stylekit-neutral-contrast-color) !important;
|
||||
}
|
||||
|
||||
.divider {
|
||||
background-color: var(--sn-stylekit-border-color) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.milkdown {
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
box-shadow: none !important;
|
||||
background-color: var(--sn-stylekit-background-color) !important;
|
||||
color: var(--sn-stylekit-editor-foreground-color) !important;
|
||||
overflow: auto;
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background-color: var(--sn-stylekit-scrollbar-thumb-color);
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb:hover {
|
||||
background-color: var(--sn-stylekit-scrollbar-thumb-color);
|
||||
}
|
||||
|
||||
.emoji {
|
||||
height: 1.3rem !important;
|
||||
width: 1.3rem !important;
|
||||
}
|
||||
|
||||
.editor {
|
||||
padding-top: 4.125rem !important;
|
||||
padding-left: 1.25rem !important;
|
||||
padding-right: 1.25rem !important;
|
||||
padding-bottom: 0 !important;
|
||||
max-width: 100% !important;
|
||||
|
||||
> * {
|
||||
margin-top: 0 !important;
|
||||
margin-bottom: 0.875rem !important;
|
||||
}
|
||||
|
||||
h1.heading.h1 {
|
||||
font-size: 2.8rem !important;
|
||||
}
|
||||
|
||||
h2.heading.h2 {
|
||||
font-size: 2.3rem !important;
|
||||
}
|
||||
|
||||
h3.heading.h3 {
|
||||
font-size: 1.8rem !important;
|
||||
}
|
||||
|
||||
h4.heading.h4 {
|
||||
font-size: 1.5rem !important;
|
||||
}
|
||||
|
||||
h5.heading.h5 {
|
||||
font-size: 1rem !important;
|
||||
}
|
||||
|
||||
p.paragraph {
|
||||
font-size: var(--sn-stylekit-font-size-editor) !important;
|
||||
}
|
||||
|
||||
.strike-through {
|
||||
text-decoration-color: rgba(var(--sn-stylekit-editor-foreground-color), 0.5);
|
||||
}
|
||||
|
||||
.ProseMirror-gapcursor {
|
||||
caret-color: transparent;
|
||||
}
|
||||
|
||||
.tableWrapper table {
|
||||
border-color: var(--sn-stylekit-border-color);
|
||||
|
||||
th {
|
||||
color: var(--sn-stylekit-neutral-contrast-color);
|
||||
border: var(--lineWidth) solid var(--sn-stylekit-border-color);
|
||||
background-color: var(--sn-stylekit-neutral-color) !important;
|
||||
background-clip: padding-box;
|
||||
}
|
||||
|
||||
td {
|
||||
color: var(--sn-stylekit-paragraph-text-color);
|
||||
border: var(--lineWidth) solid var(--sn-stylekit-border-color);
|
||||
background: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.image,
|
||||
.system,
|
||||
.empty {
|
||||
background-color: var(--sn-stylekit-secondary-contrast-background-color);
|
||||
}
|
||||
|
||||
.empty .placeholder::before {
|
||||
color: var(--sn-stylekit-foreground-color);
|
||||
}
|
||||
|
||||
.code-inline {
|
||||
color: var(--sn-stylekit-background-color);
|
||||
background-color: var(--sn-stylekit-foreground-color);
|
||||
}
|
||||
}
|
||||
|
||||
.slash-dropdown {
|
||||
background-color: var(--sn-stylekit-contrast-background-color) !important;
|
||||
border-color: var(--sn-stylekit-border-color) !important;
|
||||
|
||||
.slash-dropdown-item {
|
||||
color: var(--sn-stylekit-paragraph-text-color) !important;
|
||||
|
||||
.icon {
|
||||
color: var(--sn-stylekit-paragraph-text-color) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.milkdown-emoji-filter {
|
||||
background-color: var(--sn-stylekit-contrast-background-color) !important;
|
||||
border-color: var(--sn-stylekit-border-color) !important;
|
||||
color: var(--sn-stylekit-paragraph-text-color) !important;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
background-color: var(--sn-stylekit-contrast-background-color) !important;
|
||||
border-color: var(--sn-stylekit-border-color) !important;
|
||||
|
||||
.icon {
|
||||
color: var(--sn-stylekit-paragraph-text-color) !important;
|
||||
}
|
||||
|
||||
.icon:not(:last-child)::after {
|
||||
width: 0 !important;
|
||||
right: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.tooltip-input {
|
||||
background-color: var(--sn-stylekit-contrast-background-color) !important;
|
||||
border-color: var(--sn-stylekit-border-color) !important;
|
||||
|
||||
button {
|
||||
color: var(--sn-stylekit-success-color) !important;
|
||||
}
|
||||
|
||||
input {
|
||||
color: var(--sn-stylekit-paragraph-text-color) !important;
|
||||
}
|
||||
|
||||
input::placeholder {
|
||||
color: var(--sn-stylekit-neutral-color) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import './styles.scss'
|
||||
|
||||
import PropTypes, { InferProps } from 'prop-types'
|
||||
import { memo } from 'react'
|
||||
|
||||
export const enum SplitViewDirection {
|
||||
Horizontal = 'horizontal',
|
||||
Vertical = 'vertical',
|
||||
}
|
||||
|
||||
const enum SplitViewType {
|
||||
Row = 'row',
|
||||
Column = 'column',
|
||||
}
|
||||
|
||||
const propTypes = {
|
||||
split: PropTypes.bool.isRequired,
|
||||
direction: PropTypes.oneOf([SplitViewDirection.Horizontal, SplitViewDirection.Vertical]).isRequired,
|
||||
children: PropTypes.arrayOf(PropTypes.element).isRequired,
|
||||
}
|
||||
|
||||
type SplitViewProps = InferProps<typeof propTypes>
|
||||
|
||||
const SplitView: React.FC<SplitViewProps> = ({ children, split, direction }) => {
|
||||
const childClassName = direction === SplitViewDirection.Horizontal ? SplitViewType.Column : SplitViewType.Row
|
||||
|
||||
return (
|
||||
<div className={`container ${direction}`}>
|
||||
<div className={`${childClassName} ${split ? 'half' : 'full'}`}>{children[0]}</div>
|
||||
{split && (
|
||||
<>
|
||||
<div className="separator" />
|
||||
<div className={`${childClassName} half`}>{children[1]}</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
SplitView.propTypes = propTypes
|
||||
|
||||
export default memo(SplitView)
|
||||
@@ -0,0 +1,51 @@
|
||||
.container > .separator {
|
||||
background-color: var(--sn-stylekit-border-color);
|
||||
}
|
||||
|
||||
.container.horizontal {
|
||||
flex-direction: row;
|
||||
overflow-x: clip;
|
||||
|
||||
.column {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.column.full {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.column.half {
|
||||
max-width: 50%;
|
||||
}
|
||||
|
||||
.separator {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
.column.half:last-child {
|
||||
max-width: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.container.vertical {
|
||||
flex-direction: column;
|
||||
overflow-y: clip;
|
||||
|
||||
$separator-height: 1%;
|
||||
|
||||
.row.full {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.row.half {
|
||||
height: 40%;
|
||||
}
|
||||
|
||||
.separator {
|
||||
height: $separator-height;
|
||||
}
|
||||
|
||||
.row.half:last-child {
|
||||
height: 60% - $separator-height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
import './stylesheets/main.scss'
|
||||
|
||||
import { Component, createRef, StrictMode } from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
|
||||
import CodeMirrorEditor, { CodeMirrorRef } from './components/CodeMirror'
|
||||
import MilkdownEditor, { MilkdownRef } from './components/Milkdown'
|
||||
import SplitView, { SplitViewDirection } from './components/SplitView'
|
||||
|
||||
import EditorKit, { EditorKitDelegate } from '@standardnotes/editor-kit'
|
||||
import { marked } from 'marked'
|
||||
|
||||
import { MenuConfig, menuConfig } from './components/Milkdown/plugins/advanced-menu/config'
|
||||
|
||||
enum TextChangeSource {
|
||||
Milkdown = 'milkdown',
|
||||
CodeMirror = 'codemirror',
|
||||
}
|
||||
|
||||
type AppProps = {}
|
||||
type AppState = {
|
||||
splitView: boolean
|
||||
editable: boolean
|
||||
spellcheck: boolean
|
||||
isLoading: boolean
|
||||
}
|
||||
|
||||
class AppWrapper extends Component<AppProps, AppState> {
|
||||
private editorKit?: EditorKit
|
||||
private prevText: string = ''
|
||||
|
||||
private milkdownRef = createRef<MilkdownRef>()
|
||||
private codeMirrorRef = createRef<CodeMirrorRef>()
|
||||
|
||||
constructor(props: AppProps) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
splitView: false,
|
||||
editable: true,
|
||||
spellcheck: true,
|
||||
isLoading: true,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.configureEditorKit()
|
||||
}
|
||||
|
||||
private configureEditorKit() {
|
||||
const editorKitDelegate: EditorKitDelegate = {
|
||||
setEditorRawText: (text: string) => {
|
||||
this.prevText = text.trim()
|
||||
|
||||
this.updateMilkdownText(this.prevText)
|
||||
this.updateCodeMirrorText(this.prevText)
|
||||
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
})
|
||||
},
|
||||
generateCustomPreview: (text: string) => {
|
||||
const htmlPreview = marked.parse(text)
|
||||
const tmpElement = document.createElement('div')
|
||||
tmpElement.innerHTML = htmlPreview
|
||||
|
||||
const preview = tmpElement.textContent || tmpElement.innerText || ''
|
||||
|
||||
return {
|
||||
plain: this.truncateString(preview).trim(),
|
||||
}
|
||||
},
|
||||
onNoteValueChange: async (note: any) => {
|
||||
const editable = !note.content.appData['org.standardnotes.sn'].locked ?? true
|
||||
const spellcheck = note.content.spellcheck
|
||||
|
||||
this.setState({
|
||||
editable,
|
||||
spellcheck,
|
||||
})
|
||||
},
|
||||
onNoteLockToggle: (locked: boolean) => {
|
||||
const editable = !locked
|
||||
|
||||
this.setState({
|
||||
editable,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
this.editorKit = new EditorKit(editorKitDelegate, {
|
||||
mode: 'markdown',
|
||||
supportsFileSafe: false,
|
||||
})
|
||||
}
|
||||
|
||||
private updateMilkdownText(text: string) {
|
||||
const { current } = this.milkdownRef
|
||||
if (current) {
|
||||
current.update(text)
|
||||
}
|
||||
}
|
||||
|
||||
private updateCodeMirrorText(text: string) {
|
||||
const { current } = this.codeMirrorRef
|
||||
if (current) {
|
||||
current.update(text)
|
||||
}
|
||||
}
|
||||
|
||||
private onTextChange = (text: string, source = TextChangeSource.Milkdown) => {
|
||||
if (this.prevText === text.trim()) {
|
||||
return
|
||||
}
|
||||
|
||||
this.prevText = text.trim()
|
||||
this.editorKit!.onEditorValueChanged(text)
|
||||
|
||||
/**
|
||||
* Bi-directional text update:
|
||||
*
|
||||
* - Codemirror <- Milkdown
|
||||
* - Milkdown -> Codemirror
|
||||
*/
|
||||
switch (source) {
|
||||
case TextChangeSource.CodeMirror:
|
||||
this.updateMilkdownText(this.prevText)
|
||||
break
|
||||
case TextChangeSource.Milkdown:
|
||||
default:
|
||||
this.updateCodeMirrorText(this.prevText)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
private toggleSplitView = () => {
|
||||
const { splitView } = this.state
|
||||
|
||||
this.setState({
|
||||
splitView: !splitView,
|
||||
})
|
||||
}
|
||||
|
||||
private getSplitViewDirection = (environment: string): SplitViewDirection => {
|
||||
const environmentDirectionMap: Record<string, SplitViewDirection> = {
|
||||
web: SplitViewDirection.Horizontal,
|
||||
desktop: SplitViewDirection.Horizontal,
|
||||
mobile: SplitViewDirection.Vertical,
|
||||
}
|
||||
return environmentDirectionMap[environment]
|
||||
}
|
||||
|
||||
private truncateString(text: string, limit = 90) {
|
||||
if (text.length <= limit) {
|
||||
return text
|
||||
}
|
||||
return text.substring(0, limit) + '...'
|
||||
}
|
||||
|
||||
render() {
|
||||
const { splitView, editable, spellcheck, isLoading } = this.state
|
||||
|
||||
if (isLoading) {
|
||||
return null
|
||||
}
|
||||
|
||||
const environment = this.editorKit?.environment ?? 'web'
|
||||
const splitViewDirection = this.getSplitViewDirection(environment)
|
||||
|
||||
const customMenu: MenuConfig = [
|
||||
...menuConfig,
|
||||
[
|
||||
{
|
||||
type: 'button',
|
||||
icon: 'code',
|
||||
active: () => splitView,
|
||||
callback: this.toggleSplitView,
|
||||
alwaysVisible: true,
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
return (
|
||||
<SplitView split={splitView} direction={splitViewDirection}>
|
||||
<MilkdownEditor
|
||||
ref={this.milkdownRef}
|
||||
onChange={this.onTextChange}
|
||||
value={this.prevText}
|
||||
menuConfig={customMenu}
|
||||
editable={editable}
|
||||
spellcheck={spellcheck}
|
||||
/>
|
||||
<CodeMirrorEditor
|
||||
ref={this.codeMirrorRef}
|
||||
onChange={(text) => this.onTextChange(text, TextChangeSource.CodeMirror)}
|
||||
value={this.prevText}
|
||||
editable={editable}
|
||||
spellcheck={spellcheck}
|
||||
/>
|
||||
</SplitView>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<StrictMode>
|
||||
<AppWrapper />
|
||||
</StrictMode>,
|
||||
document.getElementById('root'),
|
||||
)
|
||||
1
packages/components/src/org.standardnotes.markdown-visual/src/react-app-env.d.ts
vendored
Normal file
1
packages/components/src/org.standardnotes.markdown-visual/src/react-app-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
||||
@@ -0,0 +1,5 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom'
|
||||
@@ -0,0 +1,48 @@
|
||||
@import '~sn-stylekit/dist/stylekit.css';
|
||||
@import 'material-icons/iconfont/material-icons.css';
|
||||
@import 'katex/dist/katex.min.css';
|
||||
@import 'prism/material-light.css';
|
||||
|
||||
:root {
|
||||
--sn-stylekit-monospace-font: SFMono-Regular, Consolas, Liberation Mono, Menlo, 'Ubuntu Mono', courier, monospace;
|
||||
}
|
||||
|
||||
body,
|
||||
html {
|
||||
background-color: transparent;
|
||||
background-color: var(--sn-stylekit-background-color);
|
||||
font-family: var(--sn-stylekit-sans-serif-font);
|
||||
font-size: var(--sn-stylekit-font-size-editor);
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
* {
|
||||
// To prevent gray flash when focusing input on mobile Safari
|
||||
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||
font-family: var(--sn-stylekit-sans-serif-font);
|
||||
}
|
||||
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sn-component {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-size: var(--sn-stylekit-font-size-editor);
|
||||
min-height: 100vh;
|
||||
@media screen and (max-width: 420px) {
|
||||
min-height: -webkit-fill-available;
|
||||
}
|
||||
}
|
||||
|
||||
.container {
|
||||
flex: 1;
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
code[class*='language-'],
|
||||
pre[class*='language-'] {
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
color: #90a4ae;
|
||||
background: #fafafa;
|
||||
font-family: Roboto Mono, monospace;
|
||||
font-size: 1em;
|
||||
line-height: 1.5em;
|
||||
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
}
|
||||
|
||||
code[class*='language-']::-moz-selection,
|
||||
pre[class*='language-']::-moz-selection,
|
||||
code[class*='language-'] ::-moz-selection,
|
||||
pre[class*='language-'] ::-moz-selection {
|
||||
background: #cceae7;
|
||||
color: #263238;
|
||||
}
|
||||
|
||||
code[class*='language-']::selection,
|
||||
pre[class*='language-']::selection,
|
||||
code[class*='language-'] ::selection,
|
||||
pre[class*='language-'] ::selection {
|
||||
background: #cceae7;
|
||||
color: #263238;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*='language-'] {
|
||||
white-space: normal;
|
||||
border-radius: 0.2em;
|
||||
padding: 0.1em;
|
||||
}
|
||||
|
||||
pre[class*='language-'] {
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
margin: 0.5em 0;
|
||||
padding: 1.25em 1em;
|
||||
}
|
||||
|
||||
.language-css > code,
|
||||
.language-sass > code,
|
||||
.language-scss > code {
|
||||
color: #f76d47;
|
||||
}
|
||||
|
||||
[class*='language-'] .namespace {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.token.atrule {
|
||||
color: #7c4dff;
|
||||
}
|
||||
|
||||
.token.attr-name {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.attr-value {
|
||||
color: #f6a434;
|
||||
}
|
||||
|
||||
.token.attribute {
|
||||
color: #f6a434;
|
||||
}
|
||||
|
||||
.token.boolean {
|
||||
color: #7c4dff;
|
||||
}
|
||||
|
||||
.token.builtin {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.cdata {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.char {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.class {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.class-name {
|
||||
color: #6182b8;
|
||||
}
|
||||
|
||||
.token.comment {
|
||||
color: #aabfc9;
|
||||
}
|
||||
|
||||
.token.constant {
|
||||
color: #7c4dff;
|
||||
}
|
||||
|
||||
.token.deleted {
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
.token.doctype {
|
||||
color: #aabfc9;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
.token.function {
|
||||
color: #7c4dff;
|
||||
}
|
||||
|
||||
.token.hexcode {
|
||||
color: #f76d47;
|
||||
}
|
||||
|
||||
.token.id {
|
||||
color: #7c4dff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.important {
|
||||
color: #7c4dff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.token.inserted {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.keyword {
|
||||
color: #7c4dff;
|
||||
}
|
||||
|
||||
.token.number {
|
||||
color: #f76d47;
|
||||
}
|
||||
|
||||
.token.operator {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.prolog {
|
||||
color: #aabfc9;
|
||||
}
|
||||
|
||||
.token.property {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.pseudo-class {
|
||||
color: #f6a434;
|
||||
}
|
||||
|
||||
.token.pseudo-element {
|
||||
color: #f6a434;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #39adb5;
|
||||
}
|
||||
|
||||
.token.regex {
|
||||
color: #6182b8;
|
||||
}
|
||||
|
||||
.token.selector {
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
.token.string {
|
||||
color: #f6a434;
|
||||
}
|
||||
|
||||
.token.symbol {
|
||||
color: #7c4dff;
|
||||
}
|
||||
|
||||
.token.tag {
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
.token.unit {
|
||||
color: #f76d47;
|
||||
}
|
||||
|
||||
.token.url {
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
.token.variable {
|
||||
color: #e53935;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"types"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user