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

Feature/update installation method #363

Open
wants to merge 42 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
300bd8b
Remove DLL
brianjhanson Jan 8, 2025
1035eb6
Vite in a working state
brianjhanson Jan 10, 2025
e43b7b7
Remove webpack
brianjhanson Jan 10, 2025
ebd6d4f
Cleaned up a tiny bit
brianjhanson Jan 17, 2025
dfb973b
Move JS into twig
brianjhanson Jan 20, 2025
8ce4e0a
Rough support for adding first party plugins
brianjhanson Jan 20, 2025
66841a1
Refactor into CKEditor Package Manager
brianjhanson Jan 21, 2025
331d562
Cleanup copy commands
brianjhanson Jan 21, 2025
cb72cd0
Remove CkePackageManager
brianjhanson Feb 5, 2025
b4ad538
package-lock updates
brianjhanson Feb 5, 2025
02a94cd
Build
brianjhanson Feb 5, 2025
fcd57c4
Refactor import maps
brianjhanson Feb 7, 2025
00e2ccb
Remove `$module` property
brianjhanson Feb 7, 2025
5d8e06f
Merge branch '5.x' of github.com:craftcms/ckeditor into feature/updat…
brianjhanson Feb 7, 2025
ee735c0
Composer update
brianjhanson Feb 7, 2025
595f90f
Better location for `registerJsImport`
brianjhanson Feb 10, 2025
f6f52ae
Update README.md
brianjhanson Feb 10, 2025
b4db116
Cleanup a bit
brianjhanson Feb 10, 2025
fe8b623
UI Translations working
brianjhanson Feb 10, 2025
a8c05d6
Remove unnecessary variable
brianjhanson Feb 10, 2025
bf25a05
Rename variable
brianjhanson Feb 10, 2025
9ec4970
Remove old JS import approach
brianjhanson Feb 10, 2025
689e948
ECS Fix
brianjhanson Feb 10, 2025
622999d
Fix pre-commit
brianjhanson Feb 10, 2025
7acd2f4
Fix english translation
brianjhanson Feb 11, 2025
8f6fb11
getAssetUrl
brianjhanson Feb 11, 2025
110589f
No timestamps
brianjhanson Feb 11, 2025
700a6ca
Relative URLs are important
brianjhanson Feb 11, 2025
51e26bc
Missed one
brianjhanson Feb 11, 2025
fac4f9f
Match properly
brianjhanson Feb 11, 2025
712a613
Update `localizedRefHandles`
brianjhanson Feb 12, 2025
b35feb9
Replace anchor with bookmark
brianjhanson Feb 17, 2025
a6f892c
Build
brianjhanson Feb 17, 2025
347af19
Update method for loading first party plugins
brianjhanson Feb 18, 2025
2ec1cfc
Cleaner registration process?
brianjhanson Feb 18, 2025
39a38ca
Build
brianjhanson Feb 18, 2025
0ef67ab
Update readme a bit
brianjhanson Feb 18, 2025
0ca15f6
Avoid loading plugins not included in the toolbar
brianjhanson Feb 18, 2025
5460592
Fix autocomplete
brianjhanson Feb 18, 2025
b00b697
Add import map shim
brianjhanson Feb 18, 2025
b16ccc4
Always load plugins without buttons
brianjhanson Feb 19, 2025
37b7dc7
Merge branch '5.x' of github.com:craftcms/ckeditor into feature/updat…
brianjhanson Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Add to path for GUIs (Tower, etc.)
PATH="/usr/local/bin:$PATH"
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh

npx lint-staged
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"**/*.php": [
"./vendor/bin/ecs check --ansi --fix",
"./vendor/bin/phpstan analyse"
"./vendor/bin/phpstan analyse --memory-limit=1G"
],
"*": "prettier --ignore-unknown --write"
}
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,34 @@ The command will generate a new content migration, which will need to be run on

## Adding CKEditor Plugins

Craft CMS plugins can register additional CKEditor plugins to extend its functionality.
### First Party plugins
If you'd like to include any of the [first party packages](https://github.com/ckeditor/ckeditor5/tree/master/packages) from CKEditor, you can call `CkeditorConfig::registerFirstPartyPackage()` in the `init` function of a custom module.

The first step is to create a [DLL-compatible](https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/alternative-setups/dll-builds.html) package which provides the CKEditor plugin(s) you wish to add.
```php
use craft\ckeditor\helpers\CkeditorConfig;

- If you’re including one of CKEditor’s [first-party packages](https://github.com/ckeditor/ckeditor5/tree/master/packages), it will already include a `build` directory with a DLL-compatible package inside it.
- If you’re creating a custom CKEditor plugin, use [CKEditor’s package generator](https://ckeditor.com/docs/ckeditor5/latest/framework/plugins/package-generator/using-package-generator.html) to scaffold it, and run its [`dll:build` command](https://ckeditor.com/docs/ckeditor5/latest/framework/plugins/package-generator/javascript-package.html#dllbuild) to create a DLL-compatible package.
class Site extends BaseModule
{
public function init(): void
{
parent::init();

// Register a package with toolbar items and multiple plugins
CkeditorConfig::registerFirstPartyPackage(['SpecialCharacters', 'SpecialCharactersEssentials'], ['specialCharacters']);

// Register a package with a single plugin.
CkeditorConfig::registerFirstPartyPackage(['ImageResize']);
}
}
```

### Custom plugins
- If you’re creating a custom CKEditor plugin, use [CKEditor’s package generator](https://ckeditor.com/docs/ckeditor5/latest/framework/plugins/package-generator/using-package-generator.html) to scaffold it.

> [!TIP]
> Check out CKEditor’s [Implementing an inline widget](https://ckeditor.com/docs/ckeditor5/latest/framework/tutorials/implementing-an-inline-widget.html) tutorial for an in-depth look at how to create a custom CKEditor plugin.
> Check out CKEditor’s [Creating a basic plugin](https://ckeditor.com/docs/ckeditor5/latest/framework/tutorials/creating-simple-plugin-timestamp.html) tutorial for an in-depth look at how to create a custom CKEditor plugin.
Once the CKEditor package is in place in your Craft plugin, create an [asset bundle](https://craftcms.com/docs/4.x/extend/asset-bundles.html) which extends [`BaseCkeditorPackageAsset`](src/web/assets/BaseCkeditorPackageAsset.php). The asset bundle defines the package’s build directory, filename, a list of CKEditor plugin names provided by the package, and any toolbar items that should be made available via the plugin.
Once the CKEditor package is in place in your Craft plugin, create an [asset bundle](https://craftcms.com/docs/4.x/extend/asset-bundles.html) which extends [`BaseCkeditorPackageAsset`](src/web/assets/BaseCkeditorPackageAsset.php). The asset bundle defines the package’s build directory, filename, namespace, a list of CKEditor plugin names provided by the package, and any toolbar items that should be made available via the plugin.

For example, here’s an asset bundle which defines a “Tokens” plugin:

Expand All @@ -335,9 +352,11 @@ use craft\ckeditor\web\assets\BaseCkeditorPackageAsset;
class TokensAsset extends BaseCkeditorPackageAsset
{
public $sourcePath = __DIR__ . '/build';

public string $namespace = '@craftcms/ckeditor5-tokens';

public $js = [
'tokens.js',
['tokens.js', 'type' => 'module']
];

public array $pluginNames = [
Expand All @@ -353,5 +372,7 @@ class TokensAsset extends BaseCkeditorPackageAsset
Finally, ensure your asset bundle is registered whenever the core CKEditor asset bundle is. Add the following code to your plugin’s `init()` method:

```php
\craft\ckeditor\Plugin::registerCkeditorPackage(TokensAsset::class);
\craft\ckeditor\Plugin::registerCkeditorPackage(TokensAsset::class, 'tokens.js');
```

The second parameter should point to the main entry file for your javascript. In most cases, it will be the same as the only item in you `$js` array.
Loading
Loading