@paroicms/public-admin-ui-lib 0.25.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/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @paroicms/public-admin-ui-lib
2
+
3
+ Common utilitaries for paroicms plugins (admin-ui side).
4
+
5
+ This package is part of [ParoiCMS](https://www.npmjs.com/package/@paroicms/server).
6
+
7
+ ## License
8
+
9
+ Released under the [MIT license](https://gitlab.com/paroi/opensource/paroicms/-/blob/main/LICENSE.md).
@@ -0,0 +1 @@
1
+ export * from "../types/admin-ui-plugin-types.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "../types/admin-ui-plugin-types.js";
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@paroicms/public-admin-ui-lib",
3
+ "version": "0.25.0",
4
+ "description": "Common utilitaries for paroicms plugins (admin UI side).",
5
+ "author": "Paroi Team",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://gitlab.com/paroi/opensource/paroicms.git",
9
+ "directory": "packages/public-admin-ui-lib"
10
+ },
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "module": "dist/index.js",
14
+ "typings": "dist/index.d.ts",
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "clear": "rimraf dist/*",
18
+ "dev": "tsc --watch --preserveWatchOutput"
19
+ },
20
+ "dependencies": {
21
+ "@paroicms/public-anywhere-lib": "0.24.0"
22
+ },
23
+ "devDependencies": {
24
+ "rimraf": "~6.0.1",
25
+ "typescript": "~5.8.3"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "types"
30
+ ]
31
+ }
@@ -0,0 +1,156 @@
1
+ import type {
2
+ MImageVariant,
3
+ MSourceImage,
4
+ MSourceMedia,
5
+ OrderByItem,
6
+ ReadFieldValue,
7
+ ResizeRule,
8
+ ScFieldType,
9
+ ThemeConf,
10
+ UpdateFieldValue,
11
+ } from "@paroicms/public-anywhere-lib";
12
+
13
+ export type AdminUiPlugin = {
14
+ init: (service: AdminUiPluginInitService) => void | Promise<void>;
15
+ create: (service: AdminUiPluginFieldService) => AdminUiPluginInstance;
16
+ };
17
+
18
+ export interface AdminUiPluginInitService {
19
+ logger: AdminUiLogger;
20
+ themeConf: ThemeConf;
21
+ publicSiteUrl: string;
22
+ configuration: {
23
+ [key: string]: unknown;
24
+ };
25
+ pluginBaseUrl: string;
26
+ registerHook(
27
+ hookName: string,
28
+ handler: AdminUiPluginHookHandler,
29
+ options?: { unique?: boolean },
30
+ ): void;
31
+ addAfterInitListener(listener: AdminUiPluginAfterInitListener): void;
32
+ }
33
+
34
+ export type AdminUiPluginAfterInitListener = (
35
+ service: AdminUiPluginService,
36
+ ) => void | Promise<void>;
37
+
38
+ export type AdminUiPluginHookHandler = (service: AdminUiPluginService, params?: any) => any;
39
+
40
+ export interface AdminUiPluginInstance {
41
+ element: HTMLElement;
42
+ setValue(value: ReadFieldValue | undefined): void;
43
+ setLanguage(language: string): void;
44
+ getValue(): UpdateFieldValue | undefined;
45
+ dispose(): void;
46
+ insertMedia?(media: MSourceMedia): Promise<void>;
47
+ }
48
+
49
+ export interface AdminUiPluginService {
50
+ themeConf: ThemeConf;
51
+ publicSiteUrl: string;
52
+ logger: AdminUiLogger;
53
+ configuration: {
54
+ [key: string]: unknown;
55
+ };
56
+ pluginBaseUrl: string;
57
+ createModalDialog<T = undefined>(dialog: PluginDialog): PluginDialogHandler<T>;
58
+ /**
59
+ * Notice: it's not safe to use admin-ui image variant URLs in a rendered web page. Use these
60
+ * variants only in the admin-ui. Image variants for rendered web pages must be re-rendered
61
+ * from the backend every time the web page is re-rendered. Look at the Quill plugin for an
62
+ * example. If you need to use an image variant from the admin-ui in a rendered web page, then
63
+ * pick `useFTextImage`.
64
+ */
65
+ useAdminUiImage(
66
+ image: string | MSourceImage,
67
+ options: {
68
+ resizeRule: ResizeRule;
69
+ pixelRatio?: number;
70
+ mediaType?: string;
71
+ },
72
+ ): Promise<AdminUiImageVariant | undefined>;
73
+ useFTextImage(
74
+ image: string | MSourceImage,
75
+ options: {
76
+ /** Must exists in the theme configuration. */
77
+ resizeRule: ResizeRule;
78
+ },
79
+ ): Promise<AdminUiImageVariant | undefined>;
80
+ showToast(message: string, options?: AdminUiToastOptions): void;
81
+ executeHook<T = unknown>(hookName: string, params?: any): T[];
82
+ searchDocuments(payload: PluginDocumentSearchPayload): Promise<PluginDocumentResult[]>;
83
+ getDocument(nodelId: string): Promise<PluginDocumentResult | undefined>;
84
+ openDocumentEdition(documentId: string, typeName: string): void;
85
+ }
86
+
87
+ export interface PluginDocumentResult {
88
+ id: string;
89
+ title?: string;
90
+ url?: string;
91
+ typeName: string;
92
+ ready?: boolean;
93
+ publishDate?: string;
94
+ }
95
+
96
+ export interface PluginDocumentSearchPayload {
97
+ searchString: string;
98
+ language?: string;
99
+ limit?: number;
100
+ start?: number;
101
+ orderBy?: OrderByItem[];
102
+ }
103
+
104
+ export interface AdminUiLogger {
105
+ error(...messages: any[]): void;
106
+ warn(...messages: any[]): void;
107
+ info(...messages: any[]): void;
108
+ debug(...messages: any[]): void;
109
+ }
110
+
111
+ export interface AdminUiPluginFieldService extends AdminUiPluginService {
112
+ fieldType: ScFieldType;
113
+ setModifiedValue: (value: UpdateFieldValue | (() => UpdateFieldValue)) => void;
114
+ cancelModifiedValue: () => void;
115
+ /**
116
+ * Initial UI language. The admin-ui can update it later using `instance.setLanguage(...)`.
117
+ */
118
+ language: string;
119
+ /**
120
+ * If the field value is localized (like a text), then it's the content language.
121
+ */
122
+ contentLanguage: string;
123
+ /**
124
+ * Initial value. The admin-ui can update it later using `instance.setValue(...)`.
125
+ */
126
+ initialValue: ReadFieldValue | undefined;
127
+ uploadMedia?(file: File): Promise<MSourceMedia | undefined>;
128
+ }
129
+
130
+ export interface PluginDialog {
131
+ content?: PluginHTMLElement;
132
+ footer?: PluginHTMLElement;
133
+ header?: string | PluginHTMLElement;
134
+ /**
135
+ * The `handler` is called when the user clicks on the `x` button
136
+ */
137
+ onCancel?: () => void;
138
+ }
139
+
140
+ export type PluginHTMLElement = HTMLElement | false | PluginHTMLElement[];
141
+
142
+ export interface PluginDialogHandler<T = undefined> {
143
+ open(): Promise<T | undefined>;
144
+ close(returnValue?: T): void;
145
+ show(): void;
146
+ hide(): void;
147
+ }
148
+
149
+ export interface AdminUiToastOptions {
150
+ severity?: "success" | "info" | "warn" | "error" | "secondary";
151
+ }
152
+
153
+ export interface AdminUiImageVariant {
154
+ source: MSourceImage;
155
+ variant: MImageVariant;
156
+ }