# DotCamp library client

The DotCamp pattern library in the block editor, shared by every DotCamp plugin
(Tableberg, Ultimate Blocks, ...). Patterns come from the DotCamp Pattern Library
server on blockslibrary.com.

One copy ships inside each plugin. On a site with several DotCamp plugins only the
newest copy runs, so the site gets one "Library" button and one modal with a tab per
product.

## Add it to a plugin

```bash
composer require dotcamp/library-client:^1.0
```

The package is on GitHub, not Packagist, so the plugin's `composer.json` needs the
repository first:

```json
"repositories": [
    { "type": "vcs", "url": "https://github.com/DotCamp/dotcamp-pattern-library-client" }
]
```

Then, in the plugin's main file (not through Composer's autoloader, see `load.php`):

```php
require_once __DIR__ . '/vendor/dotcamp/library-client/load.php';

add_action( 'dotcamp_library_register', function ( $library ) {
    $library->register_product( array(
        'slug'             => 'tableberg',
        'label'            => 'Tableberg',
        'version'          => TABLEBERG_VERSION,
        'block_namespaces' => array( 'tableberg' ),
    ) );
} );
```

All fields are described on `Library::register_product()`.

A block placeholder can open the library on its own product, replacing the empty block
with the chosen pattern:

```js
window.dotcampLibrary?.open( { product: 'tableberg', replaceClientId: clientId } );
```

## Develop

- `npm install`, then `npm run build` (or `npm start` while editing `js/`). Commit `build/`.
- `php tests/loader-test.php` runs the loader tests (no WordPress needed).
- `wp eval-file tests/wp-test.php` tests the client, sanitizer, routes and image import. Run it
  from a WordPress site where no plugin loads another copy of the library (Local's
  blockslibrary.local works).
- CI (`.github/workflows/ci.yml`) checks the syntax on PHP 7.0 to 8.5 and runs the tests.
- Decisions and the reasons behind them: [docs/DECISIONS.md](docs/DECISIONS.md).
- Making a release: [docs/RELEASING.md](docs/RELEASING.md).
