-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add DirectEditing for mobile app support #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Whiteboard\DirectEditing; | ||
|
|
||
| use OCP\DirectEditing\ACreateEmpty; | ||
| use OCP\IL10N; | ||
|
|
||
| class WhiteboardCreator extends ACreateEmpty { | ||
|
|
||
| public const CREATOR_ID = 'whiteboard'; | ||
|
|
||
| public function __construct( | ||
| private IL10N $l10n, | ||
| ) { | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getId(): string { | ||
| return self::CREATOR_ID; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getName(): string { | ||
| return $this->l10n->t('whiteboard'); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getExtension(): string { | ||
| return 'whiteboard'; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getMimetype(): string { | ||
| return 'application/vnd.excalidraw+json'; | ||
| } | ||
| } | ||
This file contains hidden or 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,98 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Whiteboard\DirectEditing; | ||
|
|
||
| use OCA\Whiteboard\AppInfo\Application; | ||
| use OCA\Whiteboard\Exception\UnauthorizedException; | ||
| use OCA\Whiteboard\Service\Authentication\AuthenticateUserServiceFactory; | ||
| use OCA\Whiteboard\Service\ConfigService; | ||
| use OCA\Whiteboard\Service\JWTService; | ||
| use OCP\AppFramework\Http\NotFoundResponse; | ||
| use OCP\AppFramework\Http\Response; | ||
| use OCP\AppFramework\Http\TemplateResponse; | ||
| use OCP\AppFramework\Services\IInitialState; | ||
| use OCP\DirectEditing\IEditor; | ||
| use OCP\DirectEditing\IToken; | ||
| use OCP\Files\InvalidPathException; | ||
| use OCP\Files\NotFoundException; | ||
| use OCP\IL10N; | ||
| use OCP\Util; | ||
|
|
||
| class WhiteboardDirectEditor implements IEditor { | ||
|
|
||
| /** @psalm-suppress PossiblyUnusedMethod */ | ||
| public function __construct( | ||
| private IL10N $l10n, | ||
| private IInitialState $initialState, | ||
| private ConfigService $configService, | ||
| private JWTService $jwtService, | ||
| private AuthenticateUserServiceFactory $authenticateUserServiceFactory, | ||
| ) { | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getId(): string { | ||
| return Application::APP_ID; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getName(): string { | ||
| return $this->l10n->t('Whiteboard'); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getMimetypes(): array { | ||
| return [ | ||
| 'application/vnd.excalidraw+json', | ||
| ]; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getMimetypesOptional(): array { | ||
| return []; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getCreators(): array { | ||
| return [ | ||
| new WhiteboardCreator($this->l10n), | ||
| ]; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function isSecure(): bool { | ||
| return false; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function open(IToken $token): Response { | ||
| $token->useTokenScope(); | ||
|
|
||
| try { | ||
| $file = $token->getFile(); | ||
|
|
||
| Util::addScript('whiteboard', 'whiteboard-main'); | ||
| Util::addStyle('whiteboard', 'whiteboard-main'); | ||
| Util::addScript('text', 'text-editor'); | ||
|
|
||
| $user = $this->authenticateUserServiceFactory->create(null)->authenticate(); | ||
| $jwt = $this->jwtService->generateJWT($user, $file, false); | ||
|
|
||
| $this->initialState->provideInitialState('file_id', $file->getId()); | ||
| $this->initialState->provideInitialState('directEditing', true); | ||
| $this->initialState->provideInitialState('jwt', $jwt); | ||
| $this->initialState->provideInitialState('collabBackendUrl', $this->configService->getCollabBackendUrl()); | ||
|
|
||
| return new TemplateResponse(Application::APP_ID, 'directEditing', [], 'base'); | ||
| } catch (InvalidPathException|NotFoundException|UnauthorizedException) { | ||
| return new NotFoundResponse(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Whiteboard\Listener; | ||
|
|
||
| use OCA\Whiteboard\DirectEditing\WhiteboardDirectEditor; | ||
| use OCP\DirectEditing\RegisterDirectEditorEvent; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
|
|
||
| /** @template-implements IEventListener<Event|RegisterDirectEditorEvent> */ | ||
| /** | ||
| * @psalm-suppress UndefinedClass | ||
| * @psalm-suppress MissingTemplateParam | ||
| */ | ||
| final class RegisterDirectEditorListener implements IEventListener { | ||
|
|
||
| /** @psalm-suppress PossiblyUnusedMethod */ | ||
| public function __construct( | ||
| private WhiteboardDirectEditor $editor, | ||
| ) { | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function handle(Event $event): void { | ||
| if (!$event instanceof RegisterDirectEditorEvent) { | ||
| return; | ||
| } | ||
| $event->register($this->editor); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,51 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| DirectEditingMobileInterface?: { | ||
| [key: string]: (arg?: string) => void | ||
| } | ||
| webkit?: { | ||
| messageHandlers?: { | ||
| DirectEditingMobileInterface?: { | ||
| postMessage: (message: unknown) => void | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export function callMobileMessage(messageName: string, attributes?: unknown): void { | ||
| let message: unknown = messageName | ||
| if (typeof attributes !== 'undefined') { | ||
| message = { | ||
| MessageName: messageName, | ||
| Values: attributes, | ||
| } | ||
| } | ||
|
|
||
| let attributesString: string | null = null | ||
| try { | ||
| attributesString = JSON.stringify(attributes) | ||
| } catch { | ||
| attributesString = null | ||
| } | ||
|
|
||
| if (window.DirectEditingMobileInterface | ||
| && typeof window.DirectEditingMobileInterface[messageName] === 'function') { | ||
| if (attributesString === null || typeof attributesString === 'undefined') { | ||
| window.DirectEditingMobileInterface[messageName]() | ||
| } else { | ||
| window.DirectEditingMobileInterface[messageName](attributesString) | ||
| } | ||
| } | ||
|
|
||
| if (window.webkit?.messageHandlers?.DirectEditingMobileInterface) { | ||
| window.webkit.messageHandlers.DirectEditingMobileInterface.postMessage(message) | ||
| } | ||
|
|
||
| window.postMessage(message) | ||
| } |
This file contains hidden or 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,30 @@ | ||
| <?php | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| ?> | ||
|
|
||
| <style> | ||
| body { | ||
| position: fixed; | ||
| background-color: var(--color-main-background); | ||
| } | ||
|
|
||
| #whiteboard-app { | ||
| width: 100%; | ||
| height: 100%; | ||
| position: fixed; | ||
| } | ||
|
|
||
| #body-public footer { | ||
| position: static; | ||
| left: auto; | ||
| bottom: auto; | ||
| transform: none; | ||
| width: auto; | ||
| max-width: none; | ||
| } | ||
| </style> | ||
|
|
||
| <div id="whiteboard-app" class="whiteboard"></div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.