@luna-park/plugin 1.0.2 → 1.0.4

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 (2) hide show
  1. package/README.md +139 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # @luna-park/plugin
2
+
3
+ This package provides the core types and helper functions for creating plugins for **Luna Park**, a visual scripting platform.
4
+
5
+ It exports the necessary interfaces to define plugin configurations, editor components, logic nodes, and lifecycle hooks.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @luna-park/plugin
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ The primary way to define a plugin is using the `makePlugin` helper function. This ensures type safety for your plugin configuration.
16
+
17
+ ```typescript
18
+ import { makePlugin, ELogicType } from "@luna-park/plugin";
19
+ import awesomeIcon from "./awesome-icon.svg"; // Icon URL
20
+
21
+ export default makePlugin({
22
+ id: "my-awesome-plugin",
23
+ name: "My Awesome Plugin",
24
+ icon: awesomeIcon, // Icon URL
25
+ description: "Adds amazing capabilities to Luna Park.",
26
+
27
+ // Plugin configuration schema (optional)
28
+ config: LogicType.object({
29
+ apiKey: LogicType.string(),
30
+ theme: LogicType.string({enum: ["light", "dark"], default: "dark"}),
31
+ }),
32
+
33
+ // Lifecycle hooks (optional)
34
+ lifecycle: {
35
+ mount: async (env) => {
36
+ console.log("Plugin mounted", env.config.apiKey);
37
+ },
38
+ update: async ({config}) => {
39
+ console.log("Config updated", config);
40
+ },
41
+ unmount: (env) => {
42
+ console.log("Plugin unmounted");
43
+ },
44
+ },
45
+
46
+ // Extend the editor
47
+ editor: {
48
+ // Register custom Vue components for the editor (optional)
49
+ components: [
50
+ {
51
+ name: "Element/Avatar",
52
+ component: MyAvatarComponent,
53
+ properties: {
54
+ src: LogicType.string({ name: "Avatar URL" }),
55
+ name: LogicType.string({ name: "Name" }),
56
+ },
57
+ slots: {
58
+ default: LogicType.void()
59
+ }
60
+ }
61
+ // ... component definitions
62
+ ],
63
+
64
+ // Register custom logic nodes (optional)
65
+ nodes: [
66
+ makeLogicNode({
67
+ name: "log/stuff",
68
+ inputs: {
69
+ in_exec: LogicType.exec(),
70
+ in_stuff: LogicType.string({ name: "Stuff" })
71
+ },
72
+ outputs: {
73
+ out_exec: LogicType.exec()
74
+ },
75
+ methods: {
76
+ async in_exec() {
77
+ console.log(this.in_stuff);
78
+ await this.out_exec();
79
+ }
80
+ },
81
+ display: {
82
+ name: "Log stuff"
83
+ }
84
+ })
85
+ // ... node definitions
86
+ ],
87
+
88
+ // Register wrapper for the editor (optional)
89
+ wrapper : MyWrapperComponent,
90
+ },
91
+
92
+ // Code injection options (optional)
93
+ inject: {
94
+ css: "body { background-color: #000; }",
95
+ js: "console.log('Hello world!')"
96
+ }
97
+ });
98
+ ```
99
+
100
+ ## API Reference
101
+
102
+ ### `makePlugin(plugin)`
103
+
104
+ A helper identity function that takes a `TPlugin` object and returns it. It is used to infer types for the configuration and internal state.
105
+
106
+ ### `TPlugin<TConfig, TInternal>`
107
+
108
+ The main interface for defining a plugin.
109
+
110
+ | Property | Type | Description |
111
+ | :--- | :--- | :--- |
112
+ | `id` | `string` | **Required**. Unique identifier for the plugin. |
113
+ | `name` | `string` | **Required**. Display name of the plugin. |
114
+ | `icon` | `string` | **Required**. Icon for the plugin. |
115
+ | `description` | `string` | Brief description of what the plugin does. |
116
+ | `config` | `TSchema` | Schema definition for the plugin's configuration settings. |
117
+ | `lifecycle` | `object` | Lifecycle hooks (`mount`, `unmount`, `update`). |
118
+ | `editor` | `object` | Extensions for the editor (components, nodes, tokens, wrapper). |
119
+ | `build` | `object` | Build-time configurations (Vite plugins, imports). |
120
+ | `inject` | `object` | CSS/JS injection options. |
121
+
122
+ ### `TEnv<TConfig, TInternal>`
123
+
124
+ The environment object passed to lifecycle hooks and dynamic options.
125
+
126
+ | Property | Type | Description |
127
+ | :--- | :--- | :--- |
128
+ | `app` | `TApplicationExport` | Access to the core application instance. |
129
+ | `config` | `Static<TConfig>` | The resolved configuration values based on the schema. |
130
+ | `mode` | `"build" \| "editor"` | The current running mode. |
131
+ | `internal` | `TInternal` | Internal state (if defined). |
132
+
133
+ ### `TOption<TEnv, T>`
134
+
135
+ Many properties in `TPlugin` can be either a static value `T` or a function that returns `T` (or `Promise<T>`). This allows for dynamic configuration based on the environment.
136
+
137
+ ```typescript
138
+ type TOption<TEnv, T> = T | ((env: TEnv) => T | Promise<T>);
139
+ ```
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@luna-park/plugin",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "description": "Plugin helper for Luna Park.",
6
6
  "homepage": "https://luna-park.app",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/lunapark"
9
+ "url": "https://github.com/lunapark/lunapark"
10
10
  },
11
11
  "author": {
12
12
  "name": "Luna Park",