├── .eslintrc ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── UPGRADING.md ├── composer.json ├── config └── nova-menu-collapsed.php ├── dist ├── js │ └── tool.js └── mix-manifest.json ├── nova.mix.js ├── package.json ├── resources └── js │ └── tool.js ├── src ├── MenuCollapsed.php └── ToolServiceProvider.php └── webpack.mix.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["eslint:recommended", "plugin:vue/essential", "prettier"], 3 | "globals": { 4 | "Nova": true 5 | }, 6 | "env": { 7 | "browser": true, 8 | "node": true 9 | }, 10 | "rules": { 11 | "vue/html-indent": ["error", 2], 12 | "vue/custom-event-name-casing": "off", 13 | "vue/no-mutating-props": "off" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Release Notes 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2022 Artem Stepanenko 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nova Menu Collapsed 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/stepanenko3/nova-menu-collapsed.svg?style=flat-square)](https://packagist.org/packages/stepanenko3/nova-menu-collapsed) 4 | [![Total Downloads](https://img.shields.io/packagist/dt/stepanenko3/nova-menu-collapsed.svg?style=flat-square)](https://packagist.org/packages/stepanenko3/nova-menu-collapsed) 5 | [![License](https://poser.pugx.org/stepanenko3/nova-menu-collapsed/license)](https://packagist.org/packages/stepanenko3/nova-menu-collapsed) 6 | 7 | This tool gives you the ability to set the default collapse state for Nova 4.0 menu items. 8 | 9 | ## Requirements 10 | 11 | - `php: >=8.0` 12 | - `laravel/nova: ^4.0` 13 | 14 | ## Installation 15 | 16 | Install the package in a Laravel Nova project via Composer and edit the configuration file 17 | 18 | ```bash 19 | # Install the package 20 | composer require stepanenko3/nova-menu-collapsed 21 | 22 | # Publish the configuration file and edit it to your preference 23 | php artisan vendor:publish --provider="Stepanenko3\NovaMenuCollapsed\ToolServiceProvider" --tag="config" 24 | ``` 25 | 26 | Register the tool with Nova in the `tools()` method of the `NovaServiceProvider`: 27 | 28 | ```php 29 | // in app/Providers/NovaServiceProvider.php 30 | 31 | public function tools() 32 | { 33 | return [ 34 | // ... 35 | new \Stepanenko3\NovaMenuCollapsed\MenuCollapsed, 36 | ]; 37 | } 38 | ``` 39 | 40 | ### Setting up 41 | 42 | After publishing the configuration file, you have to make some required changes in `config/nova-menu-collapsed.php`: 43 | 44 | ```php 45 | 'collapsed' => true, 46 | ``` 47 | 48 | ## Credits 49 | 50 | - [Artem Stepanenko](https://github.com/stepanenko3) 51 | 52 | ## License 53 | 54 | Nova Menu Builder is open-sourced software licensed under the [MIT license](LICENSE.md). 55 | -------------------------------------------------------------------------------- /UPGRADING.md: -------------------------------------------------------------------------------- 1 | # Upgrading 2 | 3 | ## To 1.0.0 4 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stepanenko3/nova-menu-collapsed", 3 | "description": "This Laravel Nova package allows you to set menu state collapsed as default", 4 | "keywords": [ 5 | "laravel", 6 | "nova", 7 | "menu" 8 | ], 9 | "license": "MIT", 10 | "require": { 11 | "php": ">=8.0", 12 | "laravel/nova": "^4.0" 13 | }, 14 | "repositories": [ 15 | { 16 | "type": "path", 17 | "url": "../nova" 18 | } 19 | ], 20 | "autoload": { 21 | "psr-4": { 22 | "Stepanenko3\\NovaMenuCollapsed\\": "src/" 23 | } 24 | }, 25 | "extra": { 26 | "laravel": { 27 | "providers": [ 28 | "Stepanenko3\\NovaMenuCollapsed\\ToolServiceProvider" 29 | ] 30 | } 31 | }, 32 | "config": { 33 | "sort-packages": true 34 | }, 35 | "minimum-stability": "dev", 36 | "prefer-stable": true 37 | } 38 | -------------------------------------------------------------------------------- /config/nova-menu-collapsed.php: -------------------------------------------------------------------------------- 1 | true, 5 | ]; 6 | -------------------------------------------------------------------------------- /dist/js/tool.js: -------------------------------------------------------------------------------- 1 | (()=>{function n(o){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];o.filter((function(n){return n.collapsable&&n.items&&n.items.length>0})).forEach((function(o){!function(n){var o=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],t="nova.navigation.".concat(n.key,".collapsed");localStorage.getItem(t)||localStorage.setItem(t,o)}(o,t),o.items.length>0&&n(o.items,t)}))}Nova.booting((function(){n(Nova.config("mainMenu"),Nova.config("novaMenuCollapsed"))}))})(); -------------------------------------------------------------------------------- /dist/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/js/tool.js": "/js/tool.js" 3 | } 4 | -------------------------------------------------------------------------------- /nova.mix.js: -------------------------------------------------------------------------------- 1 | const mix = require('laravel-mix') 2 | const webpack = require('webpack') 3 | const path = require('path') 4 | 5 | class NovaExtension { 6 | name() { 7 | return '' 8 | } 9 | 10 | register(name) { 11 | this.name = name 12 | } 13 | 14 | webpackConfig(webpackConfig) { 15 | webpackConfig.externals = { 16 | vue: 'Vue', 17 | } 18 | 19 | webpackConfig.resolve.alias = { 20 | ...(webpackConfig.resolve.alias || {}), 21 | 'laravel-nova': path.join( 22 | __dirname, 23 | 'vendor/laravel/nova/resources/js/mixins/packages.js' 24 | ), 25 | } 26 | 27 | webpackConfig.output = { 28 | uniqueName: this.name, 29 | } 30 | } 31 | } 32 | 33 | mix.extend('nova', new NovaExtension()) 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "mix", 6 | "watch": "mix watch", 7 | "watch-poll": "mix watch -- --watch-options-poll=1000", 8 | "hot": "mix watch --hot", 9 | "prod": "npm run production", 10 | "production": "mix --production", 11 | "nova:install": "npm --prefix='../../vendor/laravel/nova' ci" 12 | }, 13 | "devDependencies": { 14 | "@vue/compiler-sfc": "^3.2.22", 15 | "laravel-mix": "^6.0.41", 16 | "postcss": "^8.3.11", 17 | "vue-loader": "^16.8.3" 18 | }, 19 | "dependencies": {} 20 | } 21 | -------------------------------------------------------------------------------- /resources/js/tool.js: -------------------------------------------------------------------------------- 1 | function setMenuItemCollapsed(menuItem, collapsed = true) { 2 | const key = `nova.navigation.${menuItem.key}.collapsed`; 3 | 4 | if (localStorage.getItem(key)) 5 | return; 6 | 7 | localStorage.setItem(key, collapsed); 8 | } 9 | 10 | function collapseMenuRecursive(menu, collapsed = true) { 11 | menu 12 | .filter(menuItem => menuItem.collapsable && menuItem.items && menuItem.items.length > 0) 13 | .forEach(menuItem => { 14 | setMenuItemCollapsed(menuItem, collapsed); 15 | 16 | if (menuItem.items.length > 0) { 17 | collapseMenuRecursive(menuItem.items, collapsed); 18 | } 19 | }); 20 | } 21 | 22 | Nova.booting(function () { 23 | const menu = Nova.config('mainMenu'); 24 | 25 | collapseMenuRecursive(menu, Nova.config('novaMenuCollapsed')); 26 | }); 27 | -------------------------------------------------------------------------------- /src/MenuCollapsed.php: -------------------------------------------------------------------------------- 1 | config('nova-menu-collapsed.collapsed'), 20 | ]); 21 | 22 | Nova::script('nova-menu-collapsed', __DIR__ . '/../dist/js/tool.js'); 23 | } 24 | 25 | /** 26 | * Build the menu that renders the navigation links for the tool. 27 | * 28 | * @param \Illuminate\Http\Request $request 29 | * @return mixed 30 | */ 31 | public function menu(Request $request) 32 | { 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/ToolServiceProvider.php: -------------------------------------------------------------------------------- 1 | config(); 17 | } 18 | 19 | /** 20 | * Register any application services. 21 | * 22 | * @return void 23 | */ 24 | public function register() 25 | { 26 | // 27 | } 28 | 29 | private function config() 30 | { 31 | if ($this->app->runningInConsole()) { 32 | // Publish config 33 | $this->publishes([ 34 | __DIR__ . '/../config/' => config_path(), 35 | ], 'config'); 36 | } 37 | 38 | $this->mergeConfigFrom( 39 | __DIR__ . '/../config/nova-menu-collapsed.php', 40 | 'nova-menu-collapsed' 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | let mix = require('laravel-mix') 2 | 3 | require('./nova.mix') 4 | 5 | mix 6 | .setPublicPath('dist') 7 | .js('resources/js/tool.js', 'js') 8 | .vue({ version: 3 }) 9 | .nova('stepanenko3/nova-menu-collpsed') 10 | --------------------------------------------------------------------------------