forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '24ef8255b3f9b44cb54f49bc78fe3382a7070b1a' into glitch-s…
…oc/merge-upstream Conflicts: - `app/helpers/accounts_helper.rb`: Upstream removed a helper, textually adjacent to a glitch-soc-only one. Not really a conflict. Removed the helper as upstream did. - `app/views/layouts/embedded.html.haml`: Conflicts due to theming system. Adapted upstream's change to our theming system. - `app/views/statuses/_simple_status.html.haml`: Removed upstream, but we had local changes. Removed as upstream did.
- Loading branch information
Showing
126 changed files
with
991 additions
and
2,169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import './public-path'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import { afterInitialRender } from 'mastodon/../hooks/useRenderSignal'; | ||
|
||
import { start } from '../mastodon/common'; | ||
import { Status } from '../mastodon/features/standalone/status'; | ||
import { loadPolyfills } from '../mastodon/polyfills'; | ||
import ready from '../mastodon/ready'; | ||
|
||
start(); | ||
|
||
function loaded() { | ||
const mountNode = document.getElementById('mastodon-status'); | ||
|
||
if (mountNode) { | ||
const attr = mountNode.getAttribute('data-props'); | ||
|
||
if (!attr) return; | ||
|
||
const props = JSON.parse(attr) as { id: string; locale: string }; | ||
const root = createRoot(mountNode); | ||
|
||
root.render(<Status {...props} />); | ||
} | ||
} | ||
|
||
function main() { | ||
ready(loaded).catch((error: unknown) => { | ||
console.error(error); | ||
}); | ||
} | ||
|
||
loadPolyfills() | ||
.then(main) | ||
.catch((error: unknown) => { | ||
console.error(error); | ||
}); | ||
|
||
interface SetHeightMessage { | ||
type: 'setHeight'; | ||
id: string; | ||
height: number; | ||
} | ||
|
||
function isSetHeightMessage(data: unknown): data is SetHeightMessage { | ||
if ( | ||
data && | ||
typeof data === 'object' && | ||
'type' in data && | ||
data.type === 'setHeight' | ||
) | ||
return true; | ||
else return false; | ||
} | ||
|
||
window.addEventListener('message', (e) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- typings are not correct, it can be null in very rare cases | ||
if (!e.data || !isSetHeightMessage(e.data) || !window.parent) return; | ||
|
||
const data = e.data; | ||
|
||
// We use a timeout to allow for the React page to render before calculating the height | ||
afterInitialRender(() => { | ||
window.parent.postMessage( | ||
{ | ||
type: 'setHeight', | ||
id: data.id, | ||
height: document.getElementsByTagName('html')[0]?.scrollHeight, | ||
}, | ||
'*', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This hook allows a component to signal that it's done rendering in a way that | ||
// can be used by e.g. our embed code to determine correct iframe height | ||
|
||
let renderSignalReceived = false; | ||
|
||
type Callback = () => void; | ||
|
||
let onInitialRender: Callback; | ||
|
||
export const afterInitialRender = (callback: Callback) => { | ||
if (renderSignalReceived) { | ||
callback(); | ||
} else { | ||
onInitialRender = callback; | ||
} | ||
}; | ||
|
||
export const useRenderSignal = () => { | ||
return () => { | ||
if (renderSignalReceived) { | ||
return; | ||
} | ||
|
||
renderSignalReceived = true; | ||
|
||
if (typeof onInitialRender !== 'undefined') { | ||
window.requestAnimationFrame(() => { | ||
onInitialRender(); | ||
}); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { useRef, useState, useCallback } from 'react'; | ||
|
||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
import ContentCopyIcon from '@/material-icons/400-24px/content_copy.svg?react'; | ||
import { useTimeout } from 'mastodon/../hooks/useTimeout'; | ||
import { Icon } from 'mastodon/components/icon'; | ||
|
||
export const CopyPasteText: React.FC<{ value: string }> = ({ value }) => { | ||
const inputRef = useRef<HTMLTextAreaElement>(null); | ||
const [copied, setCopied] = useState(false); | ||
const [focused, setFocused] = useState(false); | ||
const [setAnimationTimeout] = useTimeout(); | ||
|
||
const handleInputClick = useCallback(() => { | ||
setCopied(false); | ||
|
||
if (inputRef.current) { | ||
inputRef.current.focus(); | ||
inputRef.current.select(); | ||
inputRef.current.setSelectionRange(0, value.length); | ||
} | ||
}, [setCopied, value]); | ||
|
||
const handleButtonClick = useCallback( | ||
(e: React.MouseEvent) => { | ||
e.stopPropagation(); | ||
void navigator.clipboard.writeText(value); | ||
inputRef.current?.blur(); | ||
setCopied(true); | ||
setAnimationTimeout(() => { | ||
setCopied(false); | ||
}, 700); | ||
}, | ||
[setCopied, setAnimationTimeout, value], | ||
); | ||
|
||
const handleKeyUp = useCallback( | ||
(e: React.KeyboardEvent) => { | ||
if (e.key !== ' ') return; | ||
void navigator.clipboard.writeText(value); | ||
setCopied(true); | ||
setAnimationTimeout(() => { | ||
setCopied(false); | ||
}, 700); | ||
}, | ||
[setCopied, setAnimationTimeout, value], | ||
); | ||
|
||
const handleFocus = useCallback(() => { | ||
setFocused(true); | ||
}, [setFocused]); | ||
|
||
const handleBlur = useCallback(() => { | ||
setFocused(false); | ||
}, [setFocused]); | ||
|
||
return ( | ||
<div | ||
className={classNames('copy-paste-text', { copied, focused })} | ||
tabIndex={0} | ||
role='button' | ||
onClick={handleInputClick} | ||
onKeyUp={handleKeyUp} | ||
> | ||
<textarea | ||
readOnly | ||
value={value} | ||
ref={inputRef} | ||
onClick={handleInputClick} | ||
onFocus={handleFocus} | ||
onBlur={handleBlur} | ||
/> | ||
|
||
<button className='button' onClick={handleButtonClick}> | ||
<Icon id='copy' icon={ContentCopyIcon} />{' '} | ||
{copied ? ( | ||
<FormattedMessage id='copypaste.copied' defaultMessage='Copied' /> | ||
) : ( | ||
<FormattedMessage | ||
id='copypaste.copy_to_clipboard' | ||
defaultMessage='Copy to clipboard' | ||
/> | ||
)} | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.