@wp-playground/client 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +38 -4
  2. package/index.d.ts +393 -161
  3. package/index.js +1158 -410
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Playground Client
2
2
 
3
- Provides a WordPress Playground client you can bind to a Playground iframe
4
- to control the embedded WordPress site. Here's how to use it:
3
+ Provides a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) that can be used to control a WordPress Playground iframe:
5
4
 
6
5
  ```ts
7
6
  import { connectPlayground } from '@wp-playground/client';
@@ -10,11 +9,46 @@ const client = await connectPlayground(
10
9
  // An iframe pointing to https://playground.wordpress.net/remote.html
11
10
  document.getElementById('wp')! as HTMLIFrameElement
12
11
  );
12
+ // client is now a PlaygroundClient instance
13
13
  await client.isReady();
14
14
  await client.goTo('/wp-admin/');
15
15
 
16
- const result = await client.run({
16
+ const response = await client.run({
17
17
  code: '<?php echo "Hi!"; ',
18
18
  });
19
- console.log(new TextDecoder().decode(result.body));
19
+ console.log(response.text);
20
20
  ```
21
+
22
+ Using TypeScript is highly recommended as this package ships with comprehensive types – hit ctrl+space in your IDE after `client.` and you'll see all the available methods.
23
+
24
+ Once you have a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) instance, you can use it to control the playground:
25
+
26
+ ```ts
27
+ client.writeFile('/index.php', '<?php echo "Hi!"; ');
28
+ client.run({
29
+ scriptPath: '/index.php',
30
+ });
31
+
32
+ console.log(client.readFileAsText('/index.php'));
33
+
34
+ client.request({
35
+ url: '/index.php',
36
+ method: 'POST',
37
+ formData: {
38
+ foo: 'bar',
39
+ },
40
+ });
41
+ ```
42
+
43
+ To see all the available methods, check out the [PlaygroundClient](https://wordpress.github.io/wordpress-playground/interfaces/_wp_playground_client.PlaygroundClient.html) interface.
44
+
45
+ ## Helpers
46
+
47
+ The `@wp-playground/client` package also provides a few helpers:
48
+
49
+ - [login](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.login.html) - Logs the user in to wp-admin.
50
+ - [installPlugin](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installPlugin.html) - Installs a plugin from a given zip file.
51
+ - [installPluginsFromDirectory](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installPluginsFromDirectory.html) - Downloads and installs one or more plugins from the WordPress Plugin Directory.
52
+ - [activatePlugin](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.activatePlugin.html) - Activates a specific plugin.
53
+ - [installTheme](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installTheme.html) - Installs a theme from a given zip file.
54
+ - [installThemeFromDirectory](https://wordpress.github.io/wordpress-playground/functions/_wp_playground_client.installThemeFromDirectory.html) - Downloads and installs a theme with a specific name from the WordPress Theme Directory.