@velora-cms/plugin-sdk 0.9.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/LICENSE +202 -0
- package/README.md +27 -0
- package/dist/admin-section-registry.d.ts +4 -0
- package/dist/admin-section-registry.js +17 -0
- package/dist/built-in-serializers.d.ts +3 -0
- package/dist/built-in-serializers.js +18 -0
- package/dist/built-in-settings-schemas.d.ts +6 -0
- package/dist/built-in-settings-schemas.js +37 -0
- package/dist/built-ins.d.ts +1 -0
- package/dist/built-ins.js +142 -0
- package/dist/data-type-plugin.d.ts +21 -0
- package/dist/data-type-plugin.js +1 -0
- package/dist/datatypes-entry.d.ts +2 -0
- package/dist/datatypes-entry.js +10 -0
- package/dist/define-plugin.d.ts +25 -0
- package/dist/define-plugin.js +51 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +27 -0
- package/dist/manifest-entry.d.ts +6 -0
- package/dist/manifest-entry.js +9 -0
- package/dist/manifest-schema.d.ts +728 -0
- package/dist/manifest-schema.js +348 -0
- package/dist/manifest.d.ts +370 -0
- package/dist/manifest.js +12 -0
- package/dist/plugin-context.d.ts +30 -0
- package/dist/plugin-context.js +58 -0
- package/dist/registry.d.ts +4 -0
- package/dist/registry.js +17 -0
- package/dist/simple-storage-value-provider.d.ts +9 -0
- package/dist/simple-storage-value-provider.js +58 -0
- package/dist/structured-storage-types.d.ts +53 -0
- package/dist/structured-storage-types.js +11 -0
- package/dist/views/image-view.d.ts +3 -0
- package/dist/views/image-view.js +108 -0
- package/dist/views/rich-text-view.d.ts +2 -0
- package/dist/views/rich-text-view.js +58 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @velora-cms/plugin-sdk
|
|
2
|
+
|
|
3
|
+
The SDK for building Velora plugins: `definePlugin` for declaring a
|
|
4
|
+
manifest, registries for data types and admin sections, storage-value
|
|
5
|
+
providers for reading/writing plugin data, and a curated set of
|
|
6
|
+
`@velora-cms/ui` components (`Panel`, `Input`, `Button`, and more) so
|
|
7
|
+
plugin UIs match the host admin theme automatically.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @velora-cms/plugin-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { definePlugin } from "@velora-cms/plugin-sdk";
|
|
19
|
+
|
|
20
|
+
export default definePlugin({
|
|
21
|
+
id: "my-plugin",
|
|
22
|
+
type: "datatype",
|
|
23
|
+
// ...
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Part of [Velora](https://github.com/velora-cms/velora). Apache-2.0.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AdminSectionContribution } from "./manifest.js";
|
|
2
|
+
export declare function registerAdminSection(section: AdminSectionContribution): void;
|
|
3
|
+
export declare function getAdminSection(id: string): AdminSectionContribution | undefined;
|
|
4
|
+
export declare function listAdminSections(): AdminSectionContribution[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Static registry, same shape as registry.ts's dataTypes map: built-ins
|
|
2
|
+
// have none of these (only section plugins declare adminSections), so
|
|
3
|
+
// every entry here comes from a dynamically-loaded remote (Month 8,
|
|
4
|
+
// Session 91 — the first real consumer of this contribution).
|
|
5
|
+
const adminSections = new Map();
|
|
6
|
+
export function registerAdminSection(section) {
|
|
7
|
+
if (adminSections.has(section.id)) {
|
|
8
|
+
throw new Error(`An admin section with id "${section.id}" is already registered`);
|
|
9
|
+
}
|
|
10
|
+
adminSections.set(section.id, section);
|
|
11
|
+
}
|
|
12
|
+
export function getAdminSection(id) {
|
|
13
|
+
return adminSections.get(id);
|
|
14
|
+
}
|
|
15
|
+
export function listAdminSections() {
|
|
16
|
+
return [...adminSections.values()];
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The built-in datatypes' serialize/deserialize implementations, in a
|
|
2
|
+
// deliberately React-free module: apps/server invokes these through the
|
|
3
|
+
// ./datatypes subpath (Session 69's "no browser weight in the server
|
|
4
|
+
// process" boundary), while built-ins.tsx re-imports them so the browser
|
|
5
|
+
// registry contract is unchanged. All six are identity today (Session
|
|
6
|
+
// 111 wires the PIPELINE, not new output shapes) — a built-in that needs
|
|
7
|
+
// a real serialized projection later changes its entry here and nowhere
|
|
8
|
+
// else. Keys are editor ids (DataTypeConfig.editorId), matching
|
|
9
|
+
// BUILT_IN_DATA_TYPE_CONFIGS in @velora-cms/api-schemas.
|
|
10
|
+
export const identitySerializer = (value) => value;
|
|
11
|
+
export const BUILT_IN_SERIALIZERS = {
|
|
12
|
+
"com.velora.text": identitySerializer,
|
|
13
|
+
"com.velora.number": identitySerializer,
|
|
14
|
+
"com.velora.boolean": identitySerializer,
|
|
15
|
+
"com.velora.date": identitySerializer,
|
|
16
|
+
"com.velora.image": identitySerializer,
|
|
17
|
+
"com.velora.richtext": identitySerializer,
|
|
18
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
export declare const TEXT_SETTINGS_SCHEMA: JSONSchema7;
|
|
3
|
+
export declare const TEXT_DEFAULT_SETTINGS: Record<string, unknown>;
|
|
4
|
+
export declare const IMAGE_SETTINGS_SCHEMA: JSONSchema7;
|
|
5
|
+
export declare const IMAGE_DEFAULT_SETTINGS: Record<string, unknown>;
|
|
6
|
+
export declare const BUILT_IN_SETTINGS_SCHEMAS: Readonly<Record<string, JSONSchema7>>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Settings schemas for built-in editors that have real, validated settings
|
|
2
|
+
// (Session 69) — keyed by the SAME id built-ins.tsx registers under
|
|
3
|
+
// (com.velora.<name>). Editors with no entry here have no server-side
|
|
4
|
+
// settings validation: either they have no settings at all (empty
|
|
5
|
+
// settingsSchema, e.g. number/boolean/date), or they're a third-party/
|
|
6
|
+
// remote plugin the server has no way to load code for (Module Federation
|
|
7
|
+
// remotes only ever run in the browser — see manifest-entry.ts). This is a
|
|
8
|
+
// deliberate, documented scope boundary, not an oversight.
|
|
9
|
+
//
|
|
10
|
+
// Zero React import — this file (and the @velora-cms/plugin-sdk/datatypes
|
|
11
|
+
// subpath that re-exports it) must stay importable from apps/server.
|
|
12
|
+
export const TEXT_SETTINGS_SCHEMA = {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
placeholder: { type: "string" },
|
|
16
|
+
maxLength: { type: "integer", minimum: 1 },
|
|
17
|
+
},
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
};
|
|
20
|
+
// Deliberately {} — resolve-data-type.ts falls back to editor.defaultSettings
|
|
21
|
+
// for any config with empty settings (all six seeded built-ins today), so a
|
|
22
|
+
// non-empty default here would silently change every existing Text field's
|
|
23
|
+
// behavior the moment this ships.
|
|
24
|
+
export const TEXT_DEFAULT_SETTINGS = {};
|
|
25
|
+
export const IMAGE_SETTINGS_SCHEMA = {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
acceptedTypes: { type: "array", items: { type: "string" } },
|
|
29
|
+
maxSizeBytes: { type: "integer", minimum: 1 },
|
|
30
|
+
},
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
};
|
|
33
|
+
export const IMAGE_DEFAULT_SETTINGS = {};
|
|
34
|
+
export const BUILT_IN_SETTINGS_SCHEMAS = {
|
|
35
|
+
"com.velora.text": TEXT_SETTINGS_SCHEMA,
|
|
36
|
+
"com.velora.image": IMAGE_SETTINGS_SCHEMA,
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Checkbox, Input, PropertyField } from "@velora-cms/ui";
|
|
3
|
+
import { IMAGE_DEFAULT_SETTINGS, IMAGE_SETTINGS_SCHEMA, TEXT_DEFAULT_SETTINGS, TEXT_SETTINGS_SCHEMA, } from "./built-in-settings-schemas.js";
|
|
4
|
+
import { BUILT_IN_SERIALIZERS, identitySerializer } from "./built-in-serializers.js";
|
|
5
|
+
import { definePlugin } from "./define-plugin.js";
|
|
6
|
+
import { usePluginSettings, usePluginSettingsValue, usePluginValue } from "./plugin-context.js";
|
|
7
|
+
import { registerDataType } from "./registry.js";
|
|
8
|
+
import { ImageInputView, ImageReadOnlyView, ImageSettingsView } from "./views/image-view.js";
|
|
9
|
+
import { RichTextInputView, RichTextReadOnlyView } from "./views/rich-text-view.js";
|
|
10
|
+
// Direct @velora-cms/ui dependency is TEMPORARY (Session 35) — built-ins are
|
|
11
|
+
// statically compiled into the same admin bundle as @velora-cms/ui today, so
|
|
12
|
+
// this is harmless. Must become the SDK's own curated re-export of
|
|
13
|
+
// @velora-cms/ui before plugin-sdk is ever published standalone (Module
|
|
14
|
+
// Federation, Month 4-5) — @velora-cms/ui is meant to stay private.
|
|
15
|
+
function NotImplementedView() {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function TextInputView() {
|
|
19
|
+
const { value, onChange } = usePluginValue();
|
|
20
|
+
const settings = usePluginSettings();
|
|
21
|
+
return (_jsx(Input, { value: value ?? "", placeholder: settings.placeholder,
|
|
22
|
+
// Hard limit: the browser physically blocks keystrokes past this —
|
|
23
|
+
// a different, config-level concept from FieldValidation.maxLength
|
|
24
|
+
// (field-row.tsx), which is a soft, validated-on-blur field rule.
|
|
25
|
+
maxLength: settings.maxLength, onChange: (e) => onChange(e.target.value) }));
|
|
26
|
+
}
|
|
27
|
+
function TextReadOnlyView() {
|
|
28
|
+
const { value } = usePluginValue();
|
|
29
|
+
return _jsx("p", { children: value ?? "" });
|
|
30
|
+
}
|
|
31
|
+
// Rendered by the Data Types editor only (data-type-editor.tsx) — a
|
|
32
|
+
// settings-EDITING view, so it uses usePluginSettingsValue() (write path),
|
|
33
|
+
// not usePluginSettings() (read-only, used by the input/readOnly views
|
|
34
|
+
// above). Hardcoded English strings: this file has no access to
|
|
35
|
+
// admin-ui's react-i18next instance — plugin-sdk views' i18n is a
|
|
36
|
+
// separately-tracked, deliberately deferred SDK story (see SESSION_LOG.md),
|
|
37
|
+
// matching ImageInputView's existing "Remove"/"Loading…" precedent.
|
|
38
|
+
function TextSettingsView() {
|
|
39
|
+
const { value: settings, onChange } = usePluginSettingsValue();
|
|
40
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(PropertyField, { label: "Placeholder text", htmlFor: "text-settings-placeholder", children: _jsx(Input, { id: "text-settings-placeholder", value: settings.placeholder ?? "", onChange: (e) => onChange({ ...settings, placeholder: e.target.value || undefined }) }) }), _jsx(PropertyField, { label: "Max length", htmlFor: "text-settings-max-length", helpText: "Blocks typing past this many characters. Leave blank for no limit.", children: _jsx(Input, { id: "text-settings-max-length", type: "number", min: 1, value: settings.maxLength ?? "", onChange: (e) => onChange({ ...settings, maxLength: e.target.value === "" ? undefined : Number(e.target.value) }) }) })] }));
|
|
41
|
+
}
|
|
42
|
+
function NumberInputView() {
|
|
43
|
+
const { value, onChange } = usePluginValue();
|
|
44
|
+
return (_jsx(Input, { type: "number", value: value ?? "", onChange: (e) => onChange(e.target.value === "" ? null : Number(e.target.value)) }));
|
|
45
|
+
}
|
|
46
|
+
function NumberReadOnlyView() {
|
|
47
|
+
const { value } = usePluginValue();
|
|
48
|
+
return _jsx("p", { children: value ?? "" });
|
|
49
|
+
}
|
|
50
|
+
function BooleanInputView() {
|
|
51
|
+
const { value, onChange } = usePluginValue();
|
|
52
|
+
return _jsx(Checkbox, { checked: !!value, onCheckedChange: (checked) => onChange(checked === true) });
|
|
53
|
+
}
|
|
54
|
+
function BooleanReadOnlyView() {
|
|
55
|
+
const { value } = usePluginValue();
|
|
56
|
+
return _jsx("p", { children: value ? "Yes" : "No" });
|
|
57
|
+
}
|
|
58
|
+
function DateInputView() {
|
|
59
|
+
const { value, onChange } = usePluginValue();
|
|
60
|
+
return _jsx(Input, { type: "date", value: value ?? "", onChange: (e) => onChange(e.target.value) });
|
|
61
|
+
}
|
|
62
|
+
function DateReadOnlyView() {
|
|
63
|
+
const { value } = usePluginValue();
|
|
64
|
+
return _jsx("p", { children: value ?? "" });
|
|
65
|
+
}
|
|
66
|
+
const NOT_IMPLEMENTED_VIEWS = {
|
|
67
|
+
input: NotImplementedView,
|
|
68
|
+
readOnly: NotImplementedView,
|
|
69
|
+
settings: NotImplementedView,
|
|
70
|
+
};
|
|
71
|
+
const NO_SETTINGS = { type: "object", properties: {} };
|
|
72
|
+
function builtIn(id, name, icon, schema, views = NOT_IMPLEMENTED_VIEWS, options = {}) {
|
|
73
|
+
// Through definePlugin (Session 61) so built-ins take the exact
|
|
74
|
+
// validation path external plugins do — a regression in any built-in
|
|
75
|
+
// definition fails loudly at module load, not silently at render.
|
|
76
|
+
return definePlugin({
|
|
77
|
+
id: `com.velora.${id}`,
|
|
78
|
+
name,
|
|
79
|
+
icon,
|
|
80
|
+
version: "1.0.0",
|
|
81
|
+
type: "datatype",
|
|
82
|
+
schema,
|
|
83
|
+
settingsSchema: options.settingsSchema ?? NO_SETTINGS,
|
|
84
|
+
defaultSettings: options.defaultSettings ?? {},
|
|
85
|
+
views,
|
|
86
|
+
serialize: BUILT_IN_SERIALIZERS[`com.velora.${id}`] ?? identitySerializer,
|
|
87
|
+
deserialize: identitySerializer,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Real views (Session 35) — settings stays NotImplementedView for four
|
|
91
|
+
// of six (number/boolean/date/richtext) since they have no configurable
|
|
92
|
+
// settings yet (empty settingsSchema). text and image gained real
|
|
93
|
+
// settings + settingsSchema in Session 69, proving the settings pipeline
|
|
94
|
+
// before Google Maps uses the exact same path.
|
|
95
|
+
// `preview` is aliased to the same `readOnly` view (Session 41) — used by
|
|
96
|
+
// the document type builder's per-field live preview while designing a
|
|
97
|
+
// field, deliberately not a `disabled`-attribute wrapper around `input`:
|
|
98
|
+
// the rich text view is TipTap/contenteditable, which a native `disabled`
|
|
99
|
+
// cascade doesn't stop from being edited, but readOnly views render inert
|
|
100
|
+
// markup regardless of datatype.
|
|
101
|
+
registerDataType(builtIn("text", "Text", "type", { type: "string" }, {
|
|
102
|
+
input: TextInputView,
|
|
103
|
+
readOnly: TextReadOnlyView,
|
|
104
|
+
settings: TextSettingsView,
|
|
105
|
+
preview: TextReadOnlyView,
|
|
106
|
+
}, { settingsSchema: TEXT_SETTINGS_SCHEMA, defaultSettings: TEXT_DEFAULT_SETTINGS }));
|
|
107
|
+
registerDataType(builtIn("number", "Number", "hash", { type: "number" }, {
|
|
108
|
+
input: NumberInputView,
|
|
109
|
+
readOnly: NumberReadOnlyView,
|
|
110
|
+
settings: NotImplementedView,
|
|
111
|
+
preview: NumberReadOnlyView,
|
|
112
|
+
}));
|
|
113
|
+
registerDataType(builtIn("boolean", "Boolean", "toggle-left", { type: "boolean" }, {
|
|
114
|
+
input: BooleanInputView,
|
|
115
|
+
readOnly: BooleanReadOnlyView,
|
|
116
|
+
settings: NotImplementedView,
|
|
117
|
+
preview: BooleanReadOnlyView,
|
|
118
|
+
}));
|
|
119
|
+
registerDataType(builtIn("date", "Date", "calendar", { type: "string", format: "date" }, {
|
|
120
|
+
input: DateInputView,
|
|
121
|
+
readOnly: DateReadOnlyView,
|
|
122
|
+
settings: NotImplementedView,
|
|
123
|
+
preview: DateReadOnlyView,
|
|
124
|
+
}));
|
|
125
|
+
// Stores a media reference id — the Media Library item itself is
|
|
126
|
+
// fetched separately (GET /api/media/:id), not embedded in the field
|
|
127
|
+
// value. Full library browsing/picking from existing uploads is
|
|
128
|
+
// Session 42; this view only uploads a new file.
|
|
129
|
+
registerDataType(builtIn("image", "Image", "image", { type: "string" }, {
|
|
130
|
+
input: ImageInputView,
|
|
131
|
+
readOnly: ImageReadOnlyView,
|
|
132
|
+
settings: ImageSettingsView,
|
|
133
|
+
preview: ImageReadOnlyView,
|
|
134
|
+
}, { settingsSchema: IMAGE_SETTINGS_SCHEMA, defaultSettings: IMAGE_DEFAULT_SETTINGS }));
|
|
135
|
+
// TipTap's native JSON document shape, provisional until the full
|
|
136
|
+
// content editor (Session 40/41) needs something more specific.
|
|
137
|
+
registerDataType(builtIn("richtext", "Rich Text", "file-text", { type: "object" }, {
|
|
138
|
+
input: RichTextInputView,
|
|
139
|
+
readOnly: RichTextReadOnlyView,
|
|
140
|
+
settings: NotImplementedView,
|
|
141
|
+
preview: RichTextReadOnlyView,
|
|
142
|
+
}));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
export interface DataTypePluginViews {
|
|
4
|
+
input: ComponentType;
|
|
5
|
+
readOnly: ComponentType;
|
|
6
|
+
settings: ComponentType;
|
|
7
|
+
preview?: ComponentType;
|
|
8
|
+
}
|
|
9
|
+
export interface DataTypePlugin {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
icon: string;
|
|
13
|
+
version: string;
|
|
14
|
+
type: "datatype";
|
|
15
|
+
schema: JSONSchema7;
|
|
16
|
+
settingsSchema: JSONSchema7;
|
|
17
|
+
defaultSettings: Record<string, unknown>;
|
|
18
|
+
views: DataTypePluginViews;
|
|
19
|
+
serialize: (value: unknown, settings: Record<string, unknown>) => unknown;
|
|
20
|
+
deserialize: (raw: unknown, settings: Record<string, unknown>) => unknown;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The `@velora-cms/plugin-sdk/datatypes` subpath: server-safe settings-schema
|
|
2
|
+
// DATA for built-in editors only — no React, no side-effect registration,
|
|
3
|
+
// same "no browser weight in the server process" boundary as ./manifest
|
|
4
|
+
// (Session 60). Exists so apps/server's Data Type routes can validate
|
|
5
|
+
// config.settings against a built-in editor's settingsSchema without
|
|
6
|
+
// importing built-ins.tsx (React/@velora-cms/ui). Third-party/remote plugin
|
|
7
|
+
// settingsSchemas are NOT coverable here — Module Federation remotes only
|
|
8
|
+
// ever load in the browser, so the server has no way to see one.
|
|
9
|
+
export { BUILT_IN_SETTINGS_SCHEMAS } from "./built-in-settings-schemas.js";
|
|
10
|
+
export { BUILT_IN_SERIALIZERS, identitySerializer, } from "./built-in-serializers.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DataTypePlugin } from "./data-type-plugin.js";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a plugin definition fails validation — catchable by the
|
|
4
|
+
* registry's install() (Session 62) and `velora-plugin validate`
|
|
5
|
+
* (Month 7), which want to report rather than crash.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PluginDefinitionError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validate a datatype plugin definition and hand it back. This is the
|
|
12
|
+
* one code path into the registry: built-ins construct their plugin
|
|
13
|
+
* objects through it (see built-ins.tsx), and external plugins do the
|
|
14
|
+
* same — so a missing required view fails LOUDLY at definition time,
|
|
15
|
+
* never silently at render time (plugin-sdk.md).
|
|
16
|
+
*
|
|
17
|
+
* Deliberately does NOT register: Module Federation remotes (Session 66)
|
|
18
|
+
* export the defined plugin object, and the HOST decides when it enters
|
|
19
|
+
* the registry (install/activate lifecycle) — a define-time side effect
|
|
20
|
+
* would take that control away. Pass the result to registerDataType.
|
|
21
|
+
*
|
|
22
|
+
* Returns the ORIGINAL object (not a parsed clone) — a plugin carries
|
|
23
|
+
* React components and closures whose identity should survive.
|
|
24
|
+
*/
|
|
25
|
+
export declare function definePlugin(plugin: DataTypePlugin): DataTypePlugin;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DataTypePluginSchema, formatIssues } from "./manifest-schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when a plugin definition fails validation — catchable by the
|
|
4
|
+
* registry's install() (Session 62) and `velora-plugin validate`
|
|
5
|
+
* (Month 7), which want to report rather than crash.
|
|
6
|
+
*/
|
|
7
|
+
export class PluginDefinitionError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "PluginDefinitionError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const REQUIRED_VIEWS = ["input", "readOnly", "settings"];
|
|
14
|
+
/**
|
|
15
|
+
* Validate a datatype plugin definition and hand it back. This is the
|
|
16
|
+
* one code path into the registry: built-ins construct their plugin
|
|
17
|
+
* objects through it (see built-ins.tsx), and external plugins do the
|
|
18
|
+
* same — so a missing required view fails LOUDLY at definition time,
|
|
19
|
+
* never silently at render time (plugin-sdk.md).
|
|
20
|
+
*
|
|
21
|
+
* Deliberately does NOT register: Module Federation remotes (Session 66)
|
|
22
|
+
* export the defined plugin object, and the HOST decides when it enters
|
|
23
|
+
* the registry (install/activate lifecycle) — a define-time side effect
|
|
24
|
+
* would take that control away. Pass the result to registerDataType.
|
|
25
|
+
*
|
|
26
|
+
* Returns the ORIGINAL object (not a parsed clone) — a plugin carries
|
|
27
|
+
* React components and closures whose identity should survive.
|
|
28
|
+
*/
|
|
29
|
+
export function definePlugin(plugin) {
|
|
30
|
+
const id = typeof plugin === "object" && plugin !== null && typeof plugin.id === "string"
|
|
31
|
+
? plugin.id
|
|
32
|
+
: "(unknown id)";
|
|
33
|
+
// Required views first, with purpose-built messages — Zod's generic
|
|
34
|
+
// "expected custom, received undefined" doesn't tell a plugin author
|
|
35
|
+
// what to fix.
|
|
36
|
+
const views = typeof plugin === "object" && plugin !== null ? plugin.views : undefined;
|
|
37
|
+
for (const viewName of REQUIRED_VIEWS) {
|
|
38
|
+
if (!views || views[viewName] == null) {
|
|
39
|
+
throw new PluginDefinitionError(`definePlugin: datatype plugin "${id}" is missing required view "${viewName}" ` +
|
|
40
|
+
`(input, readOnly and settings are required; preview is optional)`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const result = DataTypePluginSchema.safeParse(plugin);
|
|
44
|
+
if (!result.success) {
|
|
45
|
+
throw new PluginDefinitionError(`definePlugin: datatype plugin "${id}" is invalid:\n` +
|
|
46
|
+
formatIssues(result.error.issues)
|
|
47
|
+
.map((line) => ` - ${line}`)
|
|
48
|
+
.join("\n"));
|
|
49
|
+
}
|
|
50
|
+
return plugin;
|
|
51
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type { DataTypePlugin, DataTypePluginViews } from "./data-type-plugin.js";
|
|
2
|
+
export type { PluginType, DatabaseDialect, DatabaseCompatibility, PluginPermissions, PluginMigrationContext, PluginMigration, PluginMigrationValidation, PluginMigrationHooks, HookEvent, HookHandler, PluginHooks, ContentLifecycleHookPayload, PluginHookContext, AdminSectionContribution, DashboardWidgetContribution, ApiRouteContribution, ScheduledTaskContribution, MediaProcessorContribution, SettingsPageContribution, ContentTreeActionContribution, EditorToolbarContribution, ExposedServiceContribution, BundledTemplateContribution, SerializerContext, CustomFormatContribution, SerializerContribution, DataTypePluginContributions, SectionPluginContributions, TemplatePluginContributions, ThemePluginContributions, IntegrationPluginContributions, UtilityPluginContributions, BundlePluginContributions, PluginManifestBase, DataTypePluginManifest, SectionPluginManifest, TemplatePluginManifest, ThemePluginManifest, IntegrationPluginManifest, UtilityPluginManifest, BundlePluginManifest, CMSPlugin, } from "./manifest.js";
|
|
3
|
+
export { CMSPluginSchema, DataTypePluginSchema, validatePluginManifest, type ValidatePluginManifestResult, } from "./manifest-schema.js";
|
|
4
|
+
export { definePlugin, PluginDefinitionError } from "./define-plugin.js";
|
|
5
|
+
export { registerDataType, getDataType, listDataTypes } from "./registry.js";
|
|
6
|
+
export { registerAdminSection, getAdminSection, listAdminSections } from "./admin-section-registry.js";
|
|
7
|
+
export { PluginValueProvider, PluginSettingsProvider, PluginApiProvider, usePluginValue, usePluginSettings, usePluginSettingsValue, usePluginApi, type PluginFetch, } from "./plugin-context.js";
|
|
8
|
+
export { SimpleStorageValueProvider } from "./simple-storage-value-provider.js";
|
|
9
|
+
export { Panel, type PanelProps } from "@velora-cms/ui";
|
|
10
|
+
export { PropertyField, type PropertyFieldProps } from "@velora-cms/ui";
|
|
11
|
+
export { Input, type InputProps } from "@velora-cms/ui";
|
|
12
|
+
export { Button, type ButtonProps } from "@velora-cms/ui";
|
|
13
|
+
export { Switch, type SwitchProps } from "@velora-cms/ui";
|
|
14
|
+
export { Badge, type BadgeProps } from "@velora-cms/ui";
|
|
15
|
+
export { cn } from "@velora-cms/ui";
|
|
16
|
+
import "./built-ins.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { CMSPluginSchema, DataTypePluginSchema, validatePluginManifest, } from "./manifest-schema.js";
|
|
2
|
+
export { definePlugin, PluginDefinitionError } from "./define-plugin.js";
|
|
3
|
+
export { registerDataType, getDataType, listDataTypes } from "./registry.js";
|
|
4
|
+
export { registerAdminSection, getAdminSection, listAdminSections } from "./admin-section-registry.js";
|
|
5
|
+
export { PluginValueProvider, PluginSettingsProvider, PluginApiProvider, usePluginValue, usePluginSettings, usePluginSettingsValue, usePluginApi, } from "./plugin-context.js";
|
|
6
|
+
export { SimpleStorageValueProvider } from "./simple-storage-value-provider.js";
|
|
7
|
+
// The SDK's curated re-export of @velora-cms/ui. @velora-cms/ui is published
|
|
8
|
+
// (not private) because @velora-cms/plugin-sdk has a runtime dependency on
|
|
9
|
+
// it — a registry install of the SDK would be unresolvable otherwise. This
|
|
10
|
+
// is the first consumer to actually need it — built-ins.tsx
|
|
11
|
+
// still imports @velora-cms/ui directly, a documented TEMPORARY shortcut valid
|
|
12
|
+
// only because built-ins are compiled into the same admin bundle. Google
|
|
13
|
+
// Maps (Session 74) is a separate package on the real public SDK surface, so
|
|
14
|
+
// it goes through here instead, proving the boundary external plugin authors
|
|
15
|
+
// will actually use. Grow this list as plugins need more of @velora-cms/ui, not
|
|
16
|
+
// preemptively.
|
|
17
|
+
export { Panel } from "@velora-cms/ui";
|
|
18
|
+
export { PropertyField } from "@velora-cms/ui";
|
|
19
|
+
export { Input } from "@velora-cms/ui";
|
|
20
|
+
export { Button } from "@velora-cms/ui";
|
|
21
|
+
export { Switch } from "@velora-cms/ui";
|
|
22
|
+
export { Badge } from "@velora-cms/ui";
|
|
23
|
+
export { cn } from "@velora-cms/ui";
|
|
24
|
+
// Import for its registration side effect — loading this package's
|
|
25
|
+
// entrypoint is what populates the registry with the six built-ins, no
|
|
26
|
+
// separate manual init step for consumers.
|
|
27
|
+
import "./built-ins.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { DataTypePlugin, DataTypePluginViews } from "./data-type-plugin.js";
|
|
2
|
+
export type { PluginType, DatabaseDialect, DatabaseCompatibility, PluginPermissions, PluginMigrationContext, PluginMigration, PluginMigrationValidation, PluginMigrationHooks, HookEvent, HookHandler, PluginHooks, ContentLifecycleHookPayload, PluginHookContext, AdminSectionContribution, DashboardWidgetContribution, ApiRouteContribution, ScheduledTaskContribution, MediaProcessorContribution, SettingsPageContribution, ContentTreeActionContribution, EditorToolbarContribution, ExposedServiceContribution, BundledTemplateContribution, SerializerContext, CustomFormatContribution, SerializerContribution, DataTypePluginContributions, SectionPluginContributions, TemplatePluginContributions, ThemePluginContributions, IntegrationPluginContributions, UtilityPluginContributions, BundlePluginContributions, PluginManifestBase, DataTypePluginManifest, SectionPluginManifest, TemplatePluginManifest, ThemePluginManifest, IntegrationPluginManifest, UtilityPluginManifest, BundlePluginManifest, CMSPlugin, } from "./manifest.js";
|
|
3
|
+
export { CLIENT_BUNDLE_TYPES, hasClientBundle } from "./manifest.js";
|
|
4
|
+
export { CMSPluginSchema, DataTypePluginSchema, formatIssues, validatePluginManifest, type ValidatePluginManifestResult, } from "./manifest-schema.js";
|
|
5
|
+
export type { PluginColumnType, PluginColumnSchema, PluginIndexSchema, PluginTableSchema, StructuredQueryBuilder, StructuredStorageTransaction, ScopedStructuredStorage, PublishedContent, PluginApiRouteContext, } from "./structured-storage-types.js";
|
|
6
|
+
export { definePlugin, PluginDefinitionError } from "./define-plugin.js";
|