Skip to content
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

Editor frontend API #3615

Merged
merged 29 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
61d6f8d
enh(editor): Wrap editor into a frontend API
juliusknorr Dec 29, 2022
8c6cd4d
enh(editor): Allow to setContent on the editor
juliusknorr Dec 29, 2022
988f99c
enh(Editor): Emit event on update
juliusknorr Dec 29, 2022
580bcf4
enh: Add event to load editor
juliusknorr Dec 29, 2022
2ee8534
fix(editor): Avoid errors when no parent component is present
juliusknorr Dec 29, 2022
dcaf534
feat: Add MarkdownContentEditor component
juliusknorr Dec 30, 2022
e914638
refactor: Make Wrapper component easier to reuse with default prop va…
juliusknorr Dec 30, 2022
d9ab846
refactor: Unify editor plugins for rich text editing in the RichText …
juliusknorr Dec 30, 2022
0c6345c
refactor: Allow to pass custom items/emit to mentions plugin
juliusknorr Dec 30, 2022
eb65c5f
chore: load script for direct editing outside of template
juliusknorr Dec 30, 2022
ccd5049
fix: Add fallback values for reading editors relative path
juliusknorr Dec 30, 2022
21adb2d
fix: Keep RichTextReader with previous extension set
juliusknorr Dec 30, 2022
ac03f67
chore: Update composer autoloader
juliusknorr Jan 19, 2023
e257f3d
fix(Wrapper): Avoid absolute positioning
juliusknorr Jan 27, 2023
160d64e
feat: Migrate to class based editor api and hook attachment/link/imag…
juliusknorr Jan 28, 2023
9a60337
fix: Only open image viewer on click to the actual image
juliusknorr Jan 28, 2023
78ee556
fix: Only render link previews if links start with http(s)
juliusknorr Jan 28, 2023
1d7cc11
fix: Move scroll container definition outside of core text components
juliusknorr Jan 28, 2023
e5b881d
docs: Add notes about the component integration to the readme
juliusknorr Jan 28, 2023
b78766b
fix: Implement onLoaded callback
juliusknorr Jan 28, 2023
1b76d99
fix: Set content for file editor
juliusknorr Feb 1, 2023
2da1f89
fix: Missing history plugin
juliusknorr Feb 1, 2023
9bc0880
fix(Menubar): Avoid negative offset on small screens
juliusknorr Jan 27, 2023
47b58c9
Expose focus command from createEditor
mejo- Feb 1, 2023
a0f9aa6
Fix imports and set webpackChunkName for async imports
mejo- Feb 1, 2023
4591c69
fix(MenuBar): Only preserve 100px for the right section
juliusknorr Feb 1, 2023
361a9d9
fix: Work around issue where numeric value is passed to prosemirror-m…
juliusknorr Feb 1, 2023
32f2cf8
Minor adjustments to README.md
mejo- Feb 1, 2023
49a898f
Compile assets
nextcloud-command Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ occ config:app:set text workspace_available --value=0

## 🏗 Development setup

Currently this app requires the main branch of the [Viewer app](https://github.com/nextcloud/viewer).
Currently, this app requires the main branch of the [Viewer app](https://github.com/nextcloud/viewer).

1. ☁ Clone this app into the `apps` folder of your Nextcloud: `git clone https://github.com/nextcloud/text.git`
2. 👩‍💻 In the folder of the app, run the command `make` to install dependencies and build the Javascript.
3. ✅ Enable the app through the app management of your Nextcloud
4. 🎉 Partytime! Help fix [some issues](https://github.com/nextcloud/text/issues) and [review pull requests](https://github.com/nextcloud/text/pulls) 👍

### 🧙 Advanced development stuff

To build the Javascript whenever you make changes, instead of the full `make` you can also run `npm run build`. Or run `npm run watch` to rebuild on every file save.

#### 🐞 Testing the app
Currently this app uses three different kinds of tests:

Currently, this app uses three different kinds of tests:

For testing the backend (PHP) [Psalm](https://psalm.dev/) and [PHPUnit](https://phpunit.de/) are used,
you can run the testcases (placed in `tests/`) using the composer scripts `psalm` and `test:unit`.
Expand All @@ -57,3 +59,56 @@ Or you might set the `CYPRESS_baseUrl` environment variable for a custom nextclo
- The mime type needs to be known by Nextcloud server (see https://github.com/nextcloud/server/pull/24488 for how this can be added)
- Once that is there, please open a pull request to add them to https://github.com/nextcloud/text/blob/12df66ffdd3d71cc696438e2e4ec60fa17b89a64/src/helpers/mime.js#L35-L61
- You can test them like other mime types in cypress/e2e/files.spec.js


## 🛠️ Integrate text in your app

## Load the editor

In order to load the editor in your app, you'll need to dispatch an event.

```php
if (class_exists(LoadEditor::class)) {
$this->eventDispatcher->dispatchTyped(new LoadEditor());
}
```

### Integrate a file editor

Make sure to check if OCA.Text is available as the Text app needs to be enabled. If you want your app to work without Text being installed, you will need to provide an editor fallback on your own.


```js
window.OCA.Text.createEditor({
el: document.getElementById('my-editor-div'),
fileId: 12345,
filePath: '/Readme.md',
}).then((editor) => {
// Once ready you can access the editor instance and call methods like:

editor.setContent('new content') // Beware: this will overwrite the content read from the source file
editor.setReadOnly(true)
editor.insertAtCursor('<h1>Heading</h1>')

// Make sure to destory the editor instance once you remove the dom element
editor.destroy()
})
```

### Markdown based content editor

```js
window.OCA.Text.createEditor({
el: document.getElementById('my-editor-div'),
content: 'initial content',
}).then((editor) => {
// Once ready you can access the editor instance and call methods like:

editor.setContent('new content')
editor.setReadOnly(true)
editor.insertAtCursor('<h1>Heading</h1>')

// Make sure to destory the editor instance once you remove the dom element
editor.destroy()
})
```
2 changes: 2 additions & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'OCA\\Text\\Db\\StepMapper' => $baseDir . '/../lib/Db/StepMapper.php',
'OCA\\Text\\DirectEditing\\TextDirectEditor' => $baseDir . '/../lib/DirectEditing/TextDirectEditor.php',
'OCA\\Text\\DirectEditing\\TextDocumentCreator' => $baseDir . '/../lib/DirectEditing/TextDocumentCreator.php',
'OCA\\Text\\Event\\LoadEditor' => $baseDir . '/../lib/Event/LoadEditor.php',
'OCA\\Text\\Exception\\DocumentHasUnsavedChangesException' => $baseDir . '/../lib/Exception/DocumentHasUnsavedChangesException.php',
'OCA\\Text\\Exception\\DocumentSaveConflictException' => $baseDir . '/../lib/Exception/DocumentSaveConflictException.php',
'OCA\\Text\\Exception\\UploadException' => $baseDir . '/../lib/Exception/UploadException.php',
Expand All @@ -34,6 +35,7 @@
'OCA\\Text\\Listeners\\BeforeNodeRenamedListener' => $baseDir . '/../lib/Listeners/BeforeNodeRenamedListener.php',
'OCA\\Text\\Listeners\\FilesLoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/FilesLoadAdditionalScriptsListener.php',
'OCA\\Text\\Listeners\\FilesSharingLoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php',
'OCA\\Text\\Listeners\\LoadEditorListener' => $baseDir . '/../lib/Listeners/LoadEditorListener.php',
'OCA\\Text\\Listeners\\LoadViewerListener' => $baseDir . '/../lib/Listeners/LoadViewerListener.php',
'OCA\\Text\\Listeners\\NodeCopiedListener' => $baseDir . '/../lib/Listeners/NodeCopiedListener.php',
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => $baseDir . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
Expand Down
2 changes: 2 additions & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ComposerStaticInitText
'OCA\\Text\\Db\\StepMapper' => __DIR__ . '/..' . '/../lib/Db/StepMapper.php',
'OCA\\Text\\DirectEditing\\TextDirectEditor' => __DIR__ . '/..' . '/../lib/DirectEditing/TextDirectEditor.php',
'OCA\\Text\\DirectEditing\\TextDocumentCreator' => __DIR__ . '/..' . '/../lib/DirectEditing/TextDocumentCreator.php',
'OCA\\Text\\Event\\LoadEditor' => __DIR__ . '/..' . '/../lib/Event/LoadEditor.php',
'OCA\\Text\\Exception\\DocumentHasUnsavedChangesException' => __DIR__ . '/..' . '/../lib/Exception/DocumentHasUnsavedChangesException.php',
'OCA\\Text\\Exception\\DocumentSaveConflictException' => __DIR__ . '/..' . '/../lib/Exception/DocumentSaveConflictException.php',
'OCA\\Text\\Exception\\UploadException' => __DIR__ . '/..' . '/../lib/Exception/UploadException.php',
Expand All @@ -49,6 +50,7 @@ class ComposerStaticInitText
'OCA\\Text\\Listeners\\BeforeNodeRenamedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeNodeRenamedListener.php',
'OCA\\Text\\Listeners\\FilesLoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/FilesLoadAdditionalScriptsListener.php',
'OCA\\Text\\Listeners\\FilesSharingLoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php',
'OCA\\Text\\Listeners\\LoadEditorListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadEditorListener.php',
'OCA\\Text\\Listeners\\LoadViewerListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadViewerListener.php',
'OCA\\Text\\Listeners\\NodeCopiedListener' => __DIR__ . '/..' . '/../lib/Listeners/NodeCopiedListener.php',
'OCA\\Text\\Listeners\\RegisterDirectEditorEventListener' => __DIR__ . '/..' . '/../lib/Listeners/RegisterDirectEditorEventListener.php',
Expand Down
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/highlight/diff-js-js.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading