generator-folklore 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/lib/generators/build/index.js +1 -1
  2. package/lib/generators/eslint/index.js +1 -1
  3. package/lib/generators/intl/index.js +1 -1
  4. package/lib/generators/laravel-mediatheque/index.js +18 -0
  5. package/lib/generators/laravel-mediatheque/instructions/ServiceProvider.php +26 -0
  6. package/lib/generators/laravel-panneau/index.js +45 -5
  7. package/lib/generators/laravel-panneau/instructions/ServiceProvider.php +21 -0
  8. package/lib/generators/laravel-panneau/instructions/config.php +13 -0
  9. package/lib/generators/laravel-panneau/templates/app/Contracts/Repositories/Pages.php +2 -2
  10. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Blocks/Image.php +15 -0
  11. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Blocks/Text.php +2 -0
  12. package/lib/generators/laravel-panneau/templates/app/Models/Block.php +1 -0
  13. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/.gitkeep +0 -0
  14. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/BlocksCollection.php +2 -0
  15. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/UsersCollection.php +10 -0
  16. package/lib/generators/laravel-panneau/templates/app/Panneau/PanneauServiceProvider.php +30 -4
  17. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/ImageBlock.php +30 -0
  18. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/TextBlock.php +3 -2
  19. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks.php +4 -1
  20. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages/Page.php +2 -2
  21. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages.php +2 -2
  22. package/lib/generators/laravel-panneau/templates/app/Repositories/Pages.php +2 -2
  23. package/lib/generators/laravel-panneau/templates/app/Resources/Blocks/ImageBlock.php +27 -0
  24. package/lib/generators/laravel-panneau/templates/app/Resources/Blocks/TextBlock.php +6 -1
  25. package/lib/generators/laravel-panneau/templates/config.php +29 -0
  26. package/lib/generators/laravel-panneau/templates/index.js +1 -1
  27. package/lib/generators/laravel-panneau/templates/lang/en/panneau.php +4 -0
  28. package/lib/generators/laravel-panneau/templates/lang/fr/panneau.php +4 -0
  29. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/panneau/fields/PageSlug.jsx +68 -0
  30. package/lib/generators/laravel-project/index.js +27 -12
  31. package/lib/generators/laravel-project/templates/laravel/app/Contracts/Repositories/Users.php +17 -0
  32. package/lib/generators/laravel-project/templates/laravel/app/Models/User.php +0 -30
  33. package/lib/generators/laravel-project/templates/laravel/app/Providers/AppServiceProvider.php +90 -15
  34. package/lib/generators/laravel-project/templates/laravel/app/Repositories/Users.php +4 -3
  35. package/lib/generators/laravel-project/templates/laravel/config/app.php +2 -2
  36. package/lib/generators/laravel-project/templates/laravel/config/image.php +204 -0
  37. package/lib/generators/prettier/index.js +1 -1
  38. package/lib/generators/react-app/index.js +2 -2
  39. package/lib/generators/stylelint/index.js +1 -1
  40. package/package.json +5 -4
  41. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Block.php +0 -22
  42. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Blocks.php +0 -87
  43. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Page.php +0 -51
  44. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlug.php +0 -34
  45. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlugLocalized.php +0 -18
  46. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/BlockWithBlocks.php +0 -110
@@ -92,7 +92,7 @@ module.exports = class AppGenerator extends _generator.default {
92
92
  },
93
93
 
94
94
  dependencies() {
95
- this.addDevDependencies(['@folklore/cli']);
95
+ this.addDevDependencies(['@folklore/cli@^0.0.47']);
96
96
  }
97
97
 
98
98
  };
@@ -32,7 +32,7 @@ module.exports = class EslintGenerator extends _generator.default {
32
32
  },
33
33
 
34
34
  dependencies() {
35
- this.addDevDependencies(['babel-preset-airbnb', '@babel/eslint-parser', 'eslint', 'eslint-config-airbnb', 'eslint-config-prettier', 'eslint-plugin-prettier', 'eslint-plugin-import', 'eslint-plugin-jsx-a11y', 'eslint-plugin-react', 'eslint-plugin-formatjs']);
35
+ this.addDevDependencies(['babel-preset-airbnb@^5.0.0', '@babel/eslint-parser@^7.0.0', 'eslint@^8.0.0', 'eslint-config-airbnb@^19.0.0', 'eslint-config-prettier@^8.0.0', 'eslint-plugin-prettier@^4.0.0', 'eslint-plugin-import@^2.0.0', 'eslint-plugin-jsx-a11y@^6.0.0', 'eslint-plugin-react@^7.0.0', 'eslint-plugin-formatjs@^4.0.0']);
36
36
  }
37
37
 
38
38
  };
@@ -76,7 +76,7 @@ module.exports = class IntlGenerator extends _generator.default {
76
76
  },
77
77
 
78
78
  dependencies() {
79
- this.addDevDependencies(['@folklore/cli']);
79
+ this.addDevDependencies(['@folklore/cli@^0.0.47']);
80
80
  }
81
81
 
82
82
  };
@@ -130,4 +130,22 @@ module.exports = class LaravelMediathequeGenerator extends _generator.default {
130
130
  };
131
131
  }
132
132
 
133
+ end() {
134
+ if (this.options.quiet) {
135
+ return;
136
+ }
137
+
138
+ console.log('\n\n');
139
+ console.log(_chalk.default.yellow('\n----------------------'));
140
+ console.log(_chalk.default.bold('Instructions'));
141
+ console.log(_chalk.default.yellow('----------------------\n\n'));
142
+ console.log(`1. Add to ${_chalk.default.bold.yellow('app/Providers/AppServiceProvider.php')}:`);
143
+ const serviceProvider = fs.readFileSync(_path.default.join(__dirname, './instructions/ServiceProvider.php'));
144
+ console.log('---');
145
+ console.log(highlight(serviceProvider.toString('utf-8'), {
146
+ language: 'php',
147
+ ignoreIllegals: true
148
+ }));
149
+ }
150
+
133
151
  };
@@ -0,0 +1,26 @@
1
+ <?php
2
+
3
+ class AppServiceProvider extends ServiceProvider
4
+ {
5
+ //...
6
+ public function register()
7
+ {
8
+ // ...
9
+
10
+ $this->registerMediatheque();
11
+ }
12
+
13
+ protected function registerMediatheque()
14
+ {
15
+ $this->app->bind(
16
+ \Folklore\Mediatheque\Contracts\Models\Media::class,
17
+ \App\Models\Media::class
18
+ );
19
+
20
+ $this->app->bind(
21
+ \Folklore\Mediatheque\Contracts\Models\File::class,
22
+ \App\Models\MediaFile::class
23
+ );
24
+ }
25
+ //...
26
+ }
@@ -2,6 +2,10 @@
2
2
 
3
3
  var _chalk = _interopRequireDefault(require("chalk"));
4
4
 
5
+ var _cliHighlight = require("cli-highlight");
6
+
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+
5
9
  var _glob = _interopRequireDefault(require("glob"));
6
10
 
7
11
  var _lodash = _interopRequireDefault(require("lodash"));
@@ -65,7 +69,18 @@ module.exports = class LaravelPanneauGenerator extends _generator.default {
65
69
  },
66
70
 
67
71
  packageJSON() {
68
- this.addDependencies(['@panneau/app@^1.0.0-alpha.193', '@panneau/core@^1.0.0-alpha.193']);
72
+ this.addDependencies(['@panneau/app@^1.0.3-alpha.1', '@panneau/core@^1.0.3-alpha.1', '@panneau/data@^1.0.3-alpha.1', '@panneau/field-text@^1.0.3-alpha.1', '@panneau/field-localized@^1.0.3-alpha.1']);
73
+ },
74
+
75
+ config() {
76
+ const source = this.templatePath('config.php');
77
+ const destination = this.destinationPath('config/panneau.php');
78
+
79
+ if (this.fs.exists(destination)) {
80
+ this.fs.delete(destination);
81
+ }
82
+
83
+ this.fs.copyTpl(source, destination, {});
69
84
  },
70
85
 
71
86
  routes() {
@@ -107,10 +122,6 @@ module.exports = class LaravelPanneauGenerator extends _generator.default {
107
122
  this.fs.copyTpl(source, destination, {});
108
123
  },
109
124
 
110
- npmDependencies() {
111
- this.addDependencies(['@panneau/app@^1.0.0-alpha.193', '@panneau/core@^1.0.0-alpha.193', '@panneau/data@^1.0.0-alpha.193', '@panneau/field-text@^1.0.0-alpha.193', '@panneau/field-localized@^1.0.0-alpha.193']);
112
- },
113
-
114
125
  files() {
115
126
  const folders = ['app', 'resources', 'lang'];
116
127
  folders.forEach(folder => {
@@ -169,4 +180,33 @@ module.exports = class LaravelPanneauGenerator extends _generator.default {
169
180
  };
170
181
  }
171
182
 
183
+ end() {
184
+ if (this.options.quiet) {
185
+ return;
186
+ }
187
+
188
+ console.log('\n\n');
189
+ console.log(_chalk.default.yellow('\n----------------------'));
190
+ console.log(_chalk.default.bold('Instructions'));
191
+ console.log(_chalk.default.yellow('----------------------\n\n'));
192
+ console.log(`1. Add to ${_chalk.default.bold.yellow('app/Providers/AppServiceProvider.php')}:`);
193
+
194
+ const serviceProvider = _fs.default.readFileSync(_path.default.join(__dirname, './instructions/ServiceProvider.php'));
195
+
196
+ console.log('---');
197
+ console.log((0, _cliHighlight.highlight)(serviceProvider.toString('utf-8'), {
198
+ language: 'php',
199
+ ignoreIllegals: true
200
+ }));
201
+ console.log(`\n2. Add to ${_chalk.default.bold.yellow('config/app.php')}:`);
202
+
203
+ const config = _fs.default.readFileSync(_path.default.join(__dirname, './instructions/config.php'));
204
+
205
+ console.log('---');
206
+ console.log((0, _cliHighlight.highlight)(config.toString('utf-8'), {
207
+ language: 'php',
208
+ ignoreIllegals: true
209
+ }));
210
+ }
211
+
172
212
  };
@@ -0,0 +1,21 @@
1
+ <?php
2
+
3
+ class AppServiceProvider extends ServiceProvider
4
+ {
5
+ //...
6
+ protected function registerRepositories()
7
+ {
8
+ //...
9
+
10
+ $this->app->bind(
11
+ \Folklore\Contracts\Repositories\Pages::class,
12
+ \App\Repositories\Pages::class
13
+ );
14
+
15
+ $this->app->bind(
16
+ \App\Contracts\Repositories\Pages::class,
17
+ \App\Repositories\Pages::class
18
+ );
19
+ }
20
+ //...
21
+ }
@@ -0,0 +1,13 @@
1
+ <?php
2
+
3
+ return [
4
+ // ...
5
+
6
+ 'providers' => [
7
+ // ...
8
+
9
+ App\Panneau\PanneauServiceProvider::class,
10
+ ],
11
+
12
+ // ...
13
+ ];
@@ -13,7 +13,7 @@ interface Pages extends BasePages
13
13
 
14
14
  public function findBySlug(string $slug, string $locale = null): ?PageResource;
15
15
 
16
- public function create(array $data): PageResource;
16
+ public function create($data): PageResource;
17
17
 
18
- public function update(string $id, array $data): ?PageResource;
18
+ public function update(string $id, $data): ?PageResource;
19
19
  }
@@ -0,0 +1,15 @@
1
+ <?php
2
+
3
+ namespace App\Contracts\Resources\Blocks;
4
+
5
+ use App\Contracts\Resources\Block as BaseBlock;
6
+ use Folklore\Contracts\Resources\Image as ImageContract;
7
+
8
+ interface Image extends BaseBlock
9
+ {
10
+ public function image(): ?ImageContract;
11
+
12
+ public function caption(string $locale): ?string;
13
+
14
+ public function credits(string $locale): ?string;
15
+ }
@@ -6,5 +6,7 @@ use App\Contracts\Resources\Block as BaseBlock;
6
6
 
7
7
  interface Text extends BaseBlock
8
8
  {
9
+ public function title(string $locale): ?string;
10
+
9
11
  public function body(string $locale): ?string;
10
12
  }
@@ -8,5 +8,6 @@ class Block extends BaseBlock
8
8
  {
9
9
  protected $typeResources = [
10
10
  'text' => \App\Resources\Blocks\TextBlock::class,
11
+ 'image' => \App\Resources\Blocks\ImageBlock::class,
11
12
  ];
12
13
  }
@@ -2,6 +2,8 @@
2
2
 
3
3
  namespace App\Panneau\Http\Resources;
4
4
 
5
+ use Folklore\Http\Resources\Collection;
6
+
5
7
  class BlocksCollection extends Collection
6
8
  {
7
9
  public $collects = BlockResource::class;
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Resources;
4
+
5
+ use Folklore\Http\Resources\Collection;
6
+
7
+ class UsersCollection extends Collection
8
+ {
9
+ public $collects = UserResource::class;
10
+ }
@@ -5,7 +5,9 @@ namespace App\Panneau;
5
5
  use Illuminate\Support\ServiceProvider as BaseServiceProvider;
6
6
  use Illuminate\Contracts\View\Factory as ViewFactory;
7
7
  use Illuminate\Support\Facades\Gate;
8
+ use Panneau\Fields\Upload as UploadField;
8
9
  use Panneau\Support\LocalizedField;
10
+ use Folklore\Panneau\Fields\PageSlug as PageSlugField;
9
11
  use Panneau\Support\Facade as Panneau;
10
12
 
11
13
  class PanneauServiceProvider extends BaseServiceProvider
@@ -27,13 +29,35 @@ class PanneauServiceProvider extends BaseServiceProvider
27
29
  */
28
30
  public function boot()
29
31
  {
30
- LocalizedField::setLocalesResolver(function () {
31
- return config('locale.locales');
32
- });
33
-
32
+ $this->bootFields();
34
33
  $this->bootViews();
35
34
  }
36
35
 
36
+ protected function bootFields()
37
+ {
38
+ $this->app->booted(function () {
39
+ LocalizedField::setLocalesResolver(function () {
40
+ return config('locale.locales');
41
+ });
42
+
43
+ UploadField::setEndpoint(route('panneau.upload'));
44
+
45
+ PageSlugField::setRoutesResolver(function ($locale) {
46
+ return [
47
+ 'page' => url()->routeForReactRouter($locale . '.page', [
48
+ 'withoutPatterns' => config('panneau.routes.without_patterns', true),
49
+ ]),
50
+ 'page_with_parent' => url()->routeForReactRouter(
51
+ $locale . '.page_with_parent',
52
+ [
53
+ 'withoutPatterns' => config('panneau.routes.without_patterns', true),
54
+ ]
55
+ ),
56
+ ];
57
+ });
58
+ });
59
+ }
60
+
37
61
  protected function bootViews()
38
62
  {
39
63
  $view = $this->app[ViewFactory::class];
@@ -42,6 +66,8 @@ class PanneauServiceProvider extends BaseServiceProvider
42
66
  $view->composer('panneau::app', \App\Panneau\Composers\AppComposer::class);
43
67
 
44
68
  Panneau::serving(function () use ($view) {
69
+ $view->composer('errors::*', \Panneau\Composers\PanneauComposer::class);
70
+ $view->composer('errors::*', \Panneau\Composers\AppComposer::class);
45
71
  $view->composer('errors::*', \App\Panneau\Composers\AppComposer::class);
46
72
  });
47
73
  }
@@ -0,0 +1,30 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Resources\Blocks;
4
+
5
+ use Panneau\Support\ResourceType;
6
+ use Panneau\Fields\Image;
7
+ use Panneau\Fields\HtmlLocalized;
8
+ use Panneau\Fields\TextLocalized;
9
+
10
+ class ImageBlock extends ResourceType
11
+ {
12
+ public function id(): string
13
+ {
14
+ return 'image';
15
+ }
16
+
17
+ public function name(): string
18
+ {
19
+ return trans('panneau.blocks_image');
20
+ }
21
+
22
+ public function fields(): array
23
+ {
24
+ return [
25
+ Image::make('image')->withTransLabel('panneau.fields.image'),
26
+ HtmlLocalized::make('caption')->withTransLabel('panneau.fields.caption'),
27
+ TextLocalized::make('credits')->withTransLabel('panneau.fields.credits'),
28
+ ];
29
+ }
30
+ }
@@ -3,6 +3,7 @@
3
3
  namespace App\Panneau\Resources\Blocks;
4
4
 
5
5
  use Panneau\Support\ResourceType;
6
+ use Panneau\Fields\TextLocalized;
6
7
  use Panneau\Fields\HtmlLocalized;
7
8
 
8
9
  class TextBlock extends ResourceType
@@ -20,8 +21,8 @@ class TextBlock extends ResourceType
20
21
  public function fields(): array
21
22
  {
22
23
  return [
23
- HtmlLocalized::make('body')
24
- ->withTransLabel('panneau.fields.body'),
24
+ TextLocalized::make('title')->withTransLabel('panneau.fields.title'),
25
+ HtmlLocalized::make('body')->withTransLabel('panneau.fields.body'),
25
26
  ];
26
27
  }
27
28
  }
@@ -16,7 +16,10 @@ class Blocks extends Resource
16
16
  'hideInNavbar' => true,
17
17
  ];
18
18
 
19
- public static $types = [\App\Panneau\Resources\Blocks\TextBlock::class];
19
+ public static $types = [
20
+ \App\Panneau\Resources\Blocks\TextBlock::class,
21
+ \App\Panneau\Resources\Blocks\ImageBlock::class,
22
+ ];
20
23
 
21
24
  public function name(): string
22
25
  {
@@ -3,8 +3,8 @@
3
3
  namespace App\Panneau\Resources\Pages;
4
4
 
5
5
  use Panneau\Support\ResourceType;
6
- use App\Panneau\Fields\Blocks;
7
- use App\Panneau\Fields\Page as PageField;
6
+ use Folklore\Panneau\Fields\Blocks;
7
+ use Folklore\Panneau\Fields\Page as PageField;
8
8
 
9
9
  class Page extends ResourceType
10
10
  {
@@ -1,9 +1,9 @@
1
1
  <?php
2
2
  namespace App\Panneau\Resources;
3
3
 
4
- use App\Panneau\Fields\ImageLocalized;
5
- use App\Panneau\Fields\PageSlugLocalized;
4
+ use Folklore\Panneau\Fields\PageSlugLocalized;
6
5
  use Panneau\Fields\TextLocalized;
6
+ use Panneau\Fields\ImageLocalized;
7
7
  use Panneau\Fields\Toggle;
8
8
  use Panneau\Support\Resource;
9
9
 
@@ -30,12 +30,12 @@ class Pages extends BasePages implements PagesContract
30
30
  return parent::findBySlug($slug, $locale);
31
31
  }
32
32
 
33
- public function create(array $data): PageContract
33
+ public function create($data): PageContract
34
34
  {
35
35
  return parent::create($data);
36
36
  }
37
37
 
38
- public function update(string $id, array $data): ?PageContract
38
+ public function update(string $id, $data): ?PageContract
39
39
  {
40
40
  return parent::update($id, $data);
41
41
  }
@@ -0,0 +1,27 @@
1
+ <?php
2
+
3
+ namespace App\Resources\Blocks;
4
+
5
+ use Folklore\Resources\Block;
6
+ use App\Contracts\Resources\Blocks\Text as TextBlockContract;
7
+ use Folklore\Contracts\Resources\Image as ImageContract;
8
+ use Folklore\Resources\Image;
9
+
10
+ class ImageBlock extends Block implements TextBlockContract
11
+ {
12
+ public function image(): ?ImageContract
13
+ {
14
+ $image = data_get($this->data, 'image');
15
+ return isset($image) ? new Image($image) : null;
16
+ }
17
+
18
+ public function caption(string $locale): ?string
19
+ {
20
+ return data_get($this->data, 'caption.' . $locale);
21
+ }
22
+
23
+ public function credits(string $locale): ?string
24
+ {
25
+ return data_get($this->data, 'credits.' . $locale);
26
+ }
27
+ }
@@ -1,12 +1,17 @@
1
1
  <?php
2
2
 
3
- namespace App\Resources\Pages;
3
+ namespace App\Resources\Blocks;
4
4
 
5
5
  use Folklore\Resources\Block;
6
6
  use App\Contracts\Resources\Blocks\Text as TextBlockContract;
7
7
 
8
8
  class TextBlock extends Block implements TextBlockContract
9
9
  {
10
+ public function title(string $locale): ?string
11
+ {
12
+ return data_get($this->data, 'title.' . $locale);
13
+ }
14
+
10
15
  public function body(string $locale): ?string
11
16
  {
12
17
  return data_get($this->data, 'body.' . $locale);
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ return [
4
+ 'intl' => [
5
+ 'locale' => 'fr',
6
+ 'locales' => ['fr', 'en'],
7
+ 'translations' => ['panneau::resources', 'panneau'],
8
+ ],
9
+
10
+ 'resources' => [
11
+ \App\Panneau\Resources\Blocks::class,
12
+ \App\Panneau\Resources\Pages::class,
13
+ \App\Panneau\Resources\Users::class,
14
+ ],
15
+
16
+ 'routes' => [
17
+ // Path to the routes file that will be automatically loaded. Set to null
18
+ // to prevent auto-loading of routes.
19
+ 'map' => base_path('routes/panneau.php'),
20
+
21
+ 'prefix' => 'panneau',
22
+
23
+ 'middleware' => [\Panneau\Http\Middleware\DispatchHandlingRequestEvent::class],
24
+
25
+ 'custom' => [],
26
+
27
+ 'without_patterns' => true,
28
+ ],
29
+ ];
@@ -17,7 +17,7 @@ function renderApp(Container, props) {
17
17
 
18
18
  function loadContainer({ isPanneau = false }) {
19
19
  return isPanneau
20
- ? import('./components/Panneau')
20
+ ? import('./components/Panneau').then(({ default: Container }) => Container)
21
21
  : import('./components/Container').then(({ default: Container }) => Container);
22
22
  }
23
23
 
@@ -6,6 +6,8 @@ return [
6
6
  'url' => 'Address',
7
7
  'published' => 'Published',
8
8
  'description_short' => 'Short description',
9
+ 'caption' => 'Caption',
10
+ 'credits' => 'Credits',
9
11
  'name' => 'Name',
10
12
  'email' => 'Email',
11
13
  'password' => 'Password',
@@ -13,6 +15,7 @@ return [
13
15
  'body' => 'Text',
14
16
  'parent' => 'Parent',
15
17
  'blocks' => 'Blocks',
18
+ 'role' => 'Role',
16
19
 
17
20
  'page' => 'Page',
18
21
  'pages' => 'Pages',
@@ -30,6 +33,7 @@ return [
30
33
  'blocks' => 'Blocks',
31
34
  'no_blocks' => 'No blocks',
32
35
  'add_block' => 'Add a block',
36
+ 'select_block' => 'Select a block...',
33
37
  ],
34
38
 
35
39
  'filters' => [
@@ -6,6 +6,8 @@ return [
6
6
  'url' => 'Adresse',
7
7
  'published' => 'Publié',
8
8
  'description_short' => 'Description courte',
9
+ 'caption' => 'Libellé',
10
+ 'credits' => 'Crédits',
9
11
  'name' => 'Nom',
10
12
  'email' => 'Courriel',
11
13
  'password' => 'Mot de passe',
@@ -13,6 +15,7 @@ return [
13
15
  'body' => 'Texte',
14
16
  'parent' => 'Parent',
15
17
  'blocks' => 'Blocs',
18
+ 'role' => 'Rôle',
16
19
 
17
20
  'page' => 'Page',
18
21
  'pages' => 'Pages',
@@ -30,6 +33,7 @@ return [
30
33
  'blocks' => 'Blocs',
31
34
  'no_blocks' => 'Aucun bloc',
32
35
  'add_block' => 'Ajouter un bloc',
36
+ 'select_block' => 'Sélectionner un bloc...',
33
37
  ],
34
38
 
35
39
  'filters' => [
@@ -0,0 +1,68 @@
1
+ /* eslint-disable react/jsx-props-no-spreading */
2
+ import { useFormValue } from '@panneau/core/contexts';
3
+ import TextField from '@panneau/field-text';
4
+ import classNames from 'classnames';
5
+ import PropTypes from 'prop-types';
6
+ import React from 'react';
7
+ import { generatePath } from 'react-router';
8
+
9
+ const propTypes = {
10
+ fieldLocale: PropTypes.string,
11
+ value: PropTypes.string,
12
+ className: PropTypes.string,
13
+ routes: PropTypes.objectOf(PropTypes.string).isRequired,
14
+ };
15
+
16
+ const defaultProps = {
17
+ fieldLocale: null,
18
+ value: null,
19
+ className: null,
20
+ };
21
+
22
+ const PageSlugField = ({ routes, fieldLocale, className, value, ...props }) => {
23
+ const page = useFormValue();
24
+ const { parent = null, handle = null } = page || {};
25
+ const { slug: parentSlug } = parent || {};
26
+ const { page: pageRoute = null, page_with_parent: pageWithParentRoute = null } = routes || {};
27
+ let url =
28
+ pageRoute !== null
29
+ ? generatePath(pageRoute, {
30
+ page: 'REPLACE',
31
+ })
32
+ : null;
33
+ if (parent !== null && pageWithParentRoute !== null) {
34
+ url = generatePath(pageWithParentRoute, {
35
+ parent: parentSlug !== null ? parentSlug[fieldLocale] || null : null,
36
+ page: 'REPLACE',
37
+ });
38
+ }
39
+ if (handle === 'home') {
40
+ url = `/${fieldLocale}`;
41
+ }
42
+
43
+ return (
44
+ <TextField
45
+ prepend={
46
+ url !== null
47
+ ? `${window.location.protocol}//${window.location.host}${url.replace(
48
+ 'REPLACE',
49
+ '',
50
+ )}`
51
+ : null
52
+ }
53
+ className={classNames([
54
+ 'flex-nowrap',
55
+ {
56
+ [className]: className !== null,
57
+ },
58
+ ])}
59
+ value={handle === 'home' ? null : value}
60
+ {...props}
61
+ />
62
+ );
63
+ };
64
+
65
+ PageSlugField.propTypes = propTypes;
66
+ PageSlugField.defaultProps = defaultProps;
67
+
68
+ export default PageSlugField;