Skip to content

Commit

Permalink
Merge branch 'feat/support-vendor-form-fields' into composer-capsules
Browse files Browse the repository at this point in the history
  • Loading branch information
haringsrob committed Mar 2, 2022
2 parents 88536ce + 127aef1 commit e68e8e9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ frontend/js/components/blocks/customs/*
!frontend/js/components/blocks/customs/.keep
frontend/js/components/customs/*
!frontend/js/components/customs/.keep
frontend/js/components/customs-vendor/*
!frontend/js/components/customs-vendor/.keep
.DS_Store
public/
tests/coverage
Expand Down
1 change: 1 addition & 0 deletions config/twill.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
'manifest_file' => 'twill-manifest.json',
'vendor_path' => 'vendor/area17/twill',
'custom_components_resource_path' => 'assets/js/components',
'vendor_components_resource_path' => 'assets/vendor/js/components',
'build_timeout' => 300,
'internal_icons' => [
'content-editor.svg',
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions frontend/js/main-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ importedComponents.keys().map(block => {
return Vue.component(componentName, importedComponents(block).default)
})

// Vendor form components
const importedVendorComponents = require.context('@/components/customs-vendor/', true, /\.(js|vue)$/i)
importedVendorComponents.keys().map(block => {
const componentName = extractComponentNameFromContextKey(block)
return Vue.component(componentName, importedVendorComponents(block).default)
})

/* eslint-disable no-new */
/* eslint no-unused-vars: "off" */
window[process.env.VUE_APP_NAME].vm = window.vm = new Vue({
Expand Down
24 changes: 24 additions & 0 deletions src/Commands/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ private function fullBuild()
$this->copyComponents();
sleep(1);

$this->copyVendorComponents();
sleep(1);

$this->info('');
$progressBar->setMessage("Building assets...\n\n");
$progressBar->advance();
Expand Down Expand Up @@ -208,9 +211,30 @@ private function copyComponents()
}

$this->filesystem->cleanDirectory($twillCustomComponentsPath);
$this->filesystem->put($twillCustomComponentsPath . '/.keep', '');

if ($this->filesystem->exists($localCustomComponentsPath)) {
$this->filesystem->copyDirectory($localCustomComponentsPath, $twillCustomComponentsPath);
}
}

/**
* @return void
*/
private function copyVendorComponents()
{
$localVendorComponentsPath = resource_path(config('twill.vendor_components_resource_path', 'assets/vendor/js/components'));
$twillVendorComponentsPath = base_path(config('twill.vendor_path')) . '/frontend/js/components/customs-vendor';

if (!$this->filesystem->exists($twillVendorComponentsPath)) {
$this->filesystem->makeDirectory($twillVendorComponentsPath, 0755, true);
}

$this->filesystem->cleanDirectory($twillVendorComponentsPath);
$this->filesystem->put($twillVendorComponentsPath . '/.keep', '');

if ($this->filesystem->exists($localVendorComponentsPath)) {
$this->filesystem->copyDirectory($localVendorComponentsPath, $twillVendorComponentsPath);
}
}
}
41 changes: 41 additions & 0 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace A17\Twill;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;

class PackageServiceProvider extends ServiceProvider
{
protected function registerVueComponentsDirectory($path)
{
$this->publishes(
[$path => resource_path(config('twill.vendor_components_resource_path'))],
'components'
);
}

protected function registerBlocksDirectory($path)
{
$blocks = Config::get('twill.block_editor.directories.source.blocks');

$blocks[] = [
'path' => $path,
'source' => 'vendor',
];

Config::set('twill.block_editor.directories.source.blocks', $blocks);
}

protected function registerRepeatersDirectory($path)
{
$repeaters = Config::get('twill.block_editor.directories.source.repeaters');

$repeaters[] = [
'path' => $path,
'source' => 'vendor',
];

Config::set('twill.block_editor.directories.source.repeaters', $repeaters);
}
}
10 changes: 9 additions & 1 deletion src/TwillServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ private function registerCommands(): void
}

/**
* Resolve and include a given view expression in the project, Twill internals or a package.
*
* @param string $view
* @param string $expression
* @return string
Expand All @@ -339,7 +341,13 @@ private function includeView($view, $expression): string
{
[$name] = str_getcsv($expression, ',', '\'');

$partialNamespace = view()->exists('admin.' . $view . $name) ? 'admin.' : 'twill::';
if (preg_match('/::/', $name)) {
// if there's a namespace separator, we'll assume it's a package
[$namespace, $name] = preg_split('/::/', $name);
$partialNamespace = "$namespace::admin.";
} else {
$partialNamespace = view()->exists('admin.' . $view . $name) ? 'admin.' : 'twill::';
}

$view = $partialNamespace . $view . $name;

Expand Down

0 comments on commit e68e8e9

Please sign in to comment.