k3-plugin-api 1.4.5 → 1.5.0
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.
- package/dist/index.cjs +73 -0
- package/{index.ts → dist/index.d.cts} +164 -202
- package/dist/index.d.ts +674 -656
- package/dist/index.js +69 -0
- package/package.json +17 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Internal getter function injected by K3 at runtime.
|
|
5
|
+
*/
|
|
6
|
+
let _getSettings = null;
|
|
7
|
+
/**
|
|
8
|
+
* Internal reactive hook injected by K3 at runtime.
|
|
9
|
+
*/
|
|
10
|
+
let _usePluginSettings = null;
|
|
11
|
+
/**
|
|
12
|
+
* Get plugin-specific settings from the K3 store.
|
|
13
|
+
* Returns a snapshot of the current settings - not reactive.
|
|
14
|
+
* Use this in plugin components that need access to settings configured in the admin.
|
|
15
|
+
*
|
|
16
|
+
* @param pluginId - The unique plugin ID (e.g. "acme.my-plugin")
|
|
17
|
+
* @returns The settings object for this plugin, or `{}` if none are configured
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const settings = getSettings("acme.my-plugin") as { apiKey?: string };
|
|
22
|
+
* if (settings.apiKey) {
|
|
23
|
+
* // Use API key
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function getSettings(pluginId) {
|
|
28
|
+
if (!_getSettings) throw new Error("k3-plugin-api not initialized. Make sure K3 calls init() before using getSettings().");
|
|
29
|
+
return _getSettings(pluginId);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get plugin-specific settings from the K3 store as a reactive hook.
|
|
33
|
+
* Re-renders the component whenever the settings change.
|
|
34
|
+
* Use this in plugin React components.
|
|
35
|
+
*
|
|
36
|
+
* @param pluginId - The unique plugin ID (e.g. "acme.my-plugin")
|
|
37
|
+
* @returns The settings object for this plugin, or `{}` if none are configured
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const settings = useK3PluginSettings("acme.my-plugin") as { apiKey?: string };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function useK3PluginSettings(pluginId) {
|
|
45
|
+
if (!_usePluginSettings) throw new Error("k3-plugin-api not initialized. Make sure K3 calls init() before using useK3PluginSettings().");
|
|
46
|
+
return _usePluginSettings(pluginId);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Called by K3 when the plugin is loaded to inject runtime API functions.
|
|
50
|
+
* @internal This function is called by K3 automatically - plugins should not call it directly.
|
|
51
|
+
*/
|
|
52
|
+
function init(api) {
|
|
53
|
+
_getSettings = api.getSettings;
|
|
54
|
+
_usePluginSettings = api.usePluginSettings;
|
|
55
|
+
}
|
|
56
|
+
/** All variable type string literals. */
|
|
57
|
+
const VariableType = {
|
|
58
|
+
List: "list",
|
|
59
|
+
Color: "color",
|
|
60
|
+
Number: "number",
|
|
61
|
+
Text: "text",
|
|
62
|
+
MultiSelect: "multiSelect",
|
|
63
|
+
Boolean: "boolean",
|
|
64
|
+
Image: "image",
|
|
65
|
+
Upload: "upload",
|
|
66
|
+
Components: "components",
|
|
67
|
+
Information: "information"
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
exports.VariableType = VariableType;
|
|
71
|
+
exports.getSettings = getSettings;
|
|
72
|
+
exports.init = init;
|
|
73
|
+
exports.useK3PluginSettings = useK3PluginSettings;
|