@kardalum/plugin-sdk 0.17.0 → 0.18.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/CHANGELOG.md +67 -0
- package/README.md +4 -3
- package/dist/assets/asset-picker.d.ts +11 -0
- package/dist/assets/asset-picker.js +109 -0
- package/dist/assets/asset-tree.d.ts +30 -0
- package/dist/assets/asset-tree.js +150 -0
- package/dist/built-in-editor-ids.d.ts +1 -0
- package/dist/built-in-editor-ids.js +20 -0
- package/dist/built-in-settings-schemas.d.ts +2 -0
- package/dist/built-in-settings-schemas.js +27 -0
- package/dist/built-in-value-schemas.js +3 -0
- package/dist/built-ins.js +10 -1
- package/dist/capabilities.js +5 -0
- package/dist/datatype-validation.js +18 -4
- package/dist/datatypes-entry.d.ts +1 -0
- package/dist/datatypes-entry.js +1 -0
- package/dist/entitlement-entry.d.ts +3 -2
- package/dist/entitlement-entry.js +13 -1
- package/dist/entitlement-gate.d.ts +18 -0
- package/dist/entitlement-gate.js +95 -21
- package/dist/entitlement-plan.d.ts +21 -0
- package/dist/entitlement-plan.js +26 -0
- package/dist/entitlement-types.d.ts +21 -4
- package/dist/entitlement.d.ts +29 -1
- package/dist/entitlement.js +39 -0
- package/dist/grid-arrow-step.d.ts +7 -0
- package/dist/grid-arrow-step.js +20 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +7 -12
- package/dist/manifest-entry.d.ts +4 -0
- package/dist/manifest-entry.js +4 -0
- package/dist/manifest-schema.d.ts +5 -1
- package/dist/manifest-schema.js +7 -1
- package/dist/manifest.d.ts +21 -1
- package/dist/media/media-picker.js +32 -32
- package/dist/notify.d.ts +17 -0
- package/dist/notify.js +17 -0
- package/dist/richtext/block-panel.js +17 -18
- package/dist/richtext/extensions.js +10 -1
- package/dist/richtext/insert-menu.js +1 -1
- package/dist/richtext/kardalum-block.js +17 -17
- package/dist/richtext/style-listbox.js +1 -1
- package/dist/richtext-html-entry.d.ts +35 -0
- package/dist/richtext-html-entry.js +73 -0
- package/dist/structured-storage-types.d.ts +11 -0
- package/dist/tailwind.js +10 -3
- package/dist/tokens/tailwind-theme.css +176 -0
- package/dist/tokens/tokens.css +1 -0
- package/dist/tokens/tokens.json +2 -1
- package/dist/vendor-check.d.ts +39 -0
- package/dist/vendor-check.js +79 -0
- package/dist/vendor-entry.d.ts +3 -0
- package/dist/vendor-entry.js +9 -0
- package/dist/vendor-service.d.ts +20 -0
- package/dist/vendor-service.js +20 -0
- package/dist/views/asset-view.d.ts +6 -0
- package/dist/views/asset-view.js +55 -0
- package/dist/views/content-list-settings-view.js +1 -1
- package/dist/views/content-list-view.js +1 -1
- package/dist/views/html-code-editor.js +0 -1
- package/dist/views/image-view.js +1 -1
- package/dist/views/rich-text-view.js +30 -30
- package/node_modules/@kardalum/api-schemas/README.md +1 -1
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +16 -14
- package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.d.ts +21 -0
- package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.js +42 -0
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +10 -3
- package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.d.ts +36 -0
- package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.js +46 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +16 -1
- package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +12 -6
- package/node_modules/@kardalum/api-schemas/dist/core-actions.js +11 -6
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +50 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +25 -5
- package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +3 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.d.ts +11 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.js +28 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +42 -2
- package/node_modules/@kardalum/api-schemas/dist/home.schema.d.ts +130 -0
- package/node_modules/@kardalum/api-schemas/dist/home.schema.js +87 -0
- package/node_modules/@kardalum/api-schemas/dist/index.d.ts +41 -15
- package/node_modules/@kardalum/api-schemas/dist/index.js +30 -10
- package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.d.ts +7 -0
- package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.js +9 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +115 -1
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +102 -1
- package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.d.ts +17 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.js +16 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +26 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +6 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +10 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +4 -4
- package/node_modules/@kardalum/api-schemas/dist/news.schema.d.ts +93 -0
- package/node_modules/@kardalum/api-schemas/dist/news.schema.js +86 -0
- package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +13 -0
- package/node_modules/@kardalum/api-schemas/dist/notification.schema.d.ts +410 -0
- package/node_modules/@kardalum/api-schemas/dist/notification.schema.js +193 -0
- package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.d.ts +86 -0
- package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.js +92 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +7 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +7 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +227 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +157 -31
- package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.d.ts +19 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.js +33 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +10 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +24 -4
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +5 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +23 -20
- package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.d.ts +83 -0
- package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.js +73 -0
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +14 -0
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +7 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +3 -3
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +10 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +26 -11
- package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +7 -0
- package/node_modules/@kardalum/api-schemas/dist/template.schema.js +22 -10
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +5 -0
- package/node_modules/@kardalum/api-schemas/dist/uuid.schema.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/uuid.schema.js +4 -0
- package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.d.ts +88 -0
- package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.js +100 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +13 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +5 -0
- package/node_modules/@kardalum/design-tokens/README.md +1 -1
- package/node_modules/@kardalum/design-tokens/dist/build-theme-css.d.ts +16 -0
- package/node_modules/@kardalum/design-tokens/dist/build-theme-css.js +76 -0
- package/node_modules/@kardalum/design-tokens/dist/generate.js +4 -1
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.css +176 -0
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -1
- package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.js +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
- package/node_modules/@kardalum/design-tokens/dist/types.d.ts +1 -0
- package/node_modules/@kardalum/design-tokens/package.json +6 -3
- package/node_modules/@kardalum/plugin-package/README.md +1 -1
- package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +4 -4
- package/node_modules/@kardalum/plugin-package/dist/capabilities.js +54 -6
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +1 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +18 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +1 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +1 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +8 -4
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +58 -1
- package/node_modules/@kardalum/plugin-package/dist/extract.js +1 -1
- package/node_modules/@kardalum/plugin-package/dist/index.d.ts +4 -2
- package/node_modules/@kardalum/plugin-package/dist/index.js +3 -1
- package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +56 -19
- package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +119 -25
- package/node_modules/@kardalum/plugin-package/dist/vendor-token.d.ts +24 -0
- package/node_modules/@kardalum/plugin-package/dist/vendor-token.js +118 -0
- package/node_modules/@kardalum/ui/README.md +1 -1
- package/node_modules/@kardalum/ui/dist/components/button.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/checkbox.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/dialog.js +5 -2
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +2 -2
- package/node_modules/@kardalum/ui/dist/components/input.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/popover-panel.d.ts +4 -0
- package/node_modules/@kardalum/ui/dist/components/popover-panel.js +13 -0
- package/node_modules/@kardalum/ui/dist/components/sheet.js +5 -4
- package/node_modules/@kardalum/ui/dist/components/switch.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/tab-strip.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/toast.js +1 -1
- package/node_modules/@kardalum/ui/dist/index.d.ts +1 -0
- package/node_modules/@kardalum/ui/dist/index.js +1 -0
- package/package.json +17 -4
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,73 @@ Subpaths are noted per entry. `.` is the package index; `./manifest` is the
|
|
|
8
8
|
server-safe manifest contract subpath, which pulls in no React and no
|
|
9
9
|
`@kardalum/ui`.
|
|
10
10
|
|
|
11
|
+
## 0.18.0
|
|
12
|
+
|
|
13
|
+
Plugins can be sold on plans with a term they can read, and a plugin can call its
|
|
14
|
+
author's own server with a short-lived licence token. The release also adds a
|
|
15
|
+
vendor-side licence check, rich text from HTML for the server, notifications
|
|
16
|
+
from a plugin, and the Tailwind 4 theme.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `./vendor`: a new subpath for the author's own server (any Node server).
|
|
21
|
+
`createVendorLicenceCheck({ pluginId, origin })` checks the licence token
|
|
22
|
+
the CMS sends with a call and answers `check(authorization)` or throws
|
|
23
|
+
`VendorLicenceError` (status 401 or 402) from `requireLive(authorization)`.
|
|
24
|
+
It also exports `VENDOR_AUTH_SCHEME`, `isVendorLicenceError`, the
|
|
25
|
+
`VendorLicence*` types and `LICENSE_VERDICT_PUBLIC_KEYS`.
|
|
26
|
+
- `./manifest` and `.`: the manifest may declare `vendorService`, the origin of
|
|
27
|
+
the author's server. A plugin that declares it gets
|
|
28
|
+
`context.vendorService.fetch(path, init?)` in its routes and hooks, which
|
|
29
|
+
calls that origin with a 5-minute licence token and never sends the key.
|
|
30
|
+
It throws `VendorServiceError` (check it with `isVendorServiceError`) with
|
|
31
|
+
one of the codes in `VENDOR_SERVICE_ERROR_CODES`. Declaring it is declaring
|
|
32
|
+
outbound network use.
|
|
33
|
+
- `./manifest` and `.`: the manifest may declare
|
|
34
|
+
`contributions.notifications: true`, which derives the
|
|
35
|
+
`admin.notifications` capability. The plugin then gets `context.notify(input)`
|
|
36
|
+
in its routes and hooks, which answers how many people it reached and
|
|
37
|
+
throws `NotificationRefusedError` (check it with
|
|
38
|
+
`isNotificationRefusedError`) with one of `NOTIFICATION_REFUSAL_REASONS`.
|
|
39
|
+
Those three come from `./manifest`; `.` carries their types only.
|
|
40
|
+
- `./richtext-html`: `richtextFromHtml(html)` turns a rich text value given as
|
|
41
|
+
HTML into the editor's stored JSON, using the editor's own extensions. It
|
|
42
|
+
refuses (`RichtextHtmlError`, check it with `isRichtextHtmlError`) a value
|
|
43
|
+
over `MAX_RICHTEXT_HTML_BYTES` (1 MiB), an image that names no media item,
|
|
44
|
+
and HTML it cannot parse. It is Node-safe and imports no React.
|
|
45
|
+
- `./datatypes`: `BUILT_IN_EDITOR_IDS`, the ids of the built-in editors. A
|
|
46
|
+
plugin may not contribute an editor under one of them.
|
|
47
|
+
- `.` and `./manifest`: route and hook contexts, and the structured storage
|
|
48
|
+
context, gain the optional `notify` and `vendorService` members described
|
|
49
|
+
above, and `readOnly` described below.
|
|
50
|
+
- `./entitlement`: `entitlementPlan(entitlement, { pluginId, listingPlans?, trustedKeys? })`,
|
|
51
|
+
the plan key
|
|
52
|
+
and the term (`active`, `renewing`, `past_due`, `lapsed`, with its end, the
|
|
53
|
+
next charge and whether it was cancelled) of a verdict whose signature and
|
|
54
|
+
new `termSignature` verify. A verdict from before this release reads as
|
|
55
|
+
plan unknown, term active. On a non-production install it answers the
|
|
56
|
+
listing's highest plan when the host or the caller hands the listing's
|
|
57
|
+
plans. `EntitlementVerdict` gains an optional `termSignature`, `exempt` an
|
|
58
|
+
optional `listingPlans`. A lapsed term still comes with a `valid` verdict,
|
|
59
|
+
so `requireEntitlement` keeps passing for reads. `entitlementPlan` checks
|
|
60
|
+
the plugin id and the `valid` status like `requireEntitlement` and answers
|
|
61
|
+
null otherwise.
|
|
62
|
+
- `.`: `useEntitlement` answers `readOnly`, true while the verified term is
|
|
63
|
+
lapsed.
|
|
64
|
+
- `./manifest`: route and hook contexts carry `readOnly`, the host's own
|
|
65
|
+
decision; the host refuses a lapsed plugin's writes with 403
|
|
66
|
+
`plugin_read_only` whatever the plugin does.
|
|
67
|
+
- `.`: `EntitlementPlan`, `ListingPlanSummary`, `LicenseVerdictTerm`,
|
|
68
|
+
`highestListingPlan`, `planFromEnvelope` and `UNKNOWN_TERM`.
|
|
69
|
+
- `./tailwind/theme.css`: the design tokens' scales as a Tailwind 4 `@theme`
|
|
70
|
+
block, generated from the same source as `tailwindTheme`. Import it after
|
|
71
|
+
`@import "tailwindcss"`. `./tailwind` keeps exporting the Tailwind 3
|
|
72
|
+
`tailwindTheme` unchanged.
|
|
73
|
+
- `.`: `gridArrowStep(key, rtl)`, how far an arrow key moves in an option
|
|
74
|
+
grid read in the page direction (Right goes back in a right-to-left page;
|
|
75
|
+
Up and Down move back and forward in both). The media and asset pickers
|
|
76
|
+
have used it since S314c4.
|
|
77
|
+
|
|
11
78
|
## 0.17.0
|
|
12
79
|
|
|
13
80
|
The licence verdict key set shrinks to one, three manifest contributions that
|
package/README.md
CHANGED
|
@@ -50,7 +50,8 @@ the root; the subpaths below are bundled into whatever imports them.
|
|
|
50
50
|
| `@kardalum/plugin-sdk/tokens.css` | Every token as a CSS custom property, light theme by default. |
|
|
51
51
|
| `@kardalum/plugin-sdk/tokens/system-dark.css` | The dark theme's custom properties under `prefers-color-scheme: dark`. |
|
|
52
52
|
| `@kardalum/plugin-sdk/tokens.json` | The same tokens as JSON, for build tools. |
|
|
53
|
-
| `@kardalum/plugin-sdk/tailwind` | `tailwindTheme`, the Tailwind
|
|
53
|
+
| `@kardalum/plugin-sdk/tailwind` | `tailwindTheme`, the Tailwind 3 theme generated from the tokens (use it as `theme` in a `tailwind.config`). |
|
|
54
|
+
| `@kardalum/plugin-sdk/tailwind/theme.css` | The same scales for Tailwind 4, as an `@theme` block reference. In the plugin's stylesheet: `@import "tailwindcss/theme.css" layer(theme);`, then `@import "@kardalum/plugin-sdk/tailwind/theme.css";`, then `@import "tailwindcss/utilities.css" layer(utilities);` and an `@source` line for the plugin's own files. Never `@import "tailwindcss";` (it brings Tailwind's base reset into the admin). The theme is reference-only (values are `var(--x)`), so a standalone preview outside the admin also needs `@kardalum/plugin-sdk/tokens.css`. |
|
|
54
55
|
| `@kardalum/plugin-sdk/icons` | The Lucide icons the admin draws with, and the `IconName` type a manifest's `icon` takes. |
|
|
55
56
|
| `@kardalum/plugin-sdk/entitlement` | A paid plugin's licence check (`requireEntitlement`), for plugin server code only. |
|
|
56
57
|
| `@kardalum/plugin-sdk/datatypes` | The built-in data types' settings schemas and serializers, for server code. |
|
|
@@ -66,13 +67,13 @@ management API that the admin itself calls with the signed-in session. A plugin
|
|
|
66
67
|
view that calls a CMS family builds its path from it, for example the content
|
|
67
68
|
roots at `/api/manage/v1/content/roots`, and calls its own routes under
|
|
68
69
|
`/api/plugins/:pluginId/`. The
|
|
69
|
-
[management routes](https://
|
|
70
|
+
[management routes](https://dev.kardalum.com/docs/v1/reference/manage/) page lists
|
|
70
71
|
every operation.
|
|
71
72
|
|
|
72
73
|
## Docs
|
|
73
74
|
|
|
74
75
|
The plugin guide, the manifest reference and the storage reference are at
|
|
75
|
-
[
|
|
76
|
+
[dev.kardalum.com/docs](https://dev.kardalum.com/docs/v1/learn/build-a-plugin/).
|
|
76
77
|
|
|
77
78
|
## Support
|
|
78
79
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type AssetAccepts } from "@kardalum/api-schemas";
|
|
2
|
+
export interface AssetPickerProps {
|
|
3
|
+
accepts: AssetAccepts;
|
|
4
|
+
/** The folder the drawer opens in; the root when null or when it names no folder. */
|
|
5
|
+
startFolder: string | null;
|
|
6
|
+
/** The file the field holds now: the drawer opens in its folder with it selected, when it exists and is taken. */
|
|
7
|
+
currentPath?: string | null;
|
|
8
|
+
onPick: (path: string) => void;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function AssetPicker({ accepts, startFolder: rawStartFolder, currentPath, onPick, onClose }: AssetPickerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useRef, useState } from "react";
|
|
3
|
+
import { ChevronRight, Folder as FolderIcon } from "lucide-react";
|
|
4
|
+
import { assetPathAccepted, assetPathIsImage } from "@kardalum/api-schemas";
|
|
5
|
+
import { Button, cn, Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle } from "@kardalum/ui";
|
|
6
|
+
import { usePluginTranslate } from "../plugin-screen-context.js";
|
|
7
|
+
import { gridArrowStep } from "../grid-arrow-step.js";
|
|
8
|
+
import { assetBaseName, assetParent, normalizeStartFolder, useAssetThumbnail, useAssetTree } from "./asset-tree.js";
|
|
9
|
+
const NO_ENTRIES = [];
|
|
10
|
+
function inFolder(entries, folder, kind) {
|
|
11
|
+
return entries
|
|
12
|
+
.filter((entry) => entry.kind === kind && assetParent(entry.path) === folder)
|
|
13
|
+
.sort((a, b) => assetBaseName(a.path).localeCompare(assetBaseName(b.path)));
|
|
14
|
+
}
|
|
15
|
+
function formatSize(size) {
|
|
16
|
+
return size === null ? "" : `${Math.max(1, Math.round(size / 1024))} KiB`;
|
|
17
|
+
}
|
|
18
|
+
function TileThumbnail({ path }) {
|
|
19
|
+
const [element, setElement] = useState(null);
|
|
20
|
+
const url = useAssetThumbnail(assetPathIsImage(path) ? path : null, element);
|
|
21
|
+
return (_jsx("span", { ref: setElement, className: "block aspect-square overflow-hidden bg-background-subtle", children: url ? _jsx("img", { src: url, alt: "", className: "h-full w-full object-cover" }) : null }));
|
|
22
|
+
}
|
|
23
|
+
const LINK_CLASS = "rounded-md px-1 hover:text-primary-600 hover:underline focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-600";
|
|
24
|
+
export function AssetPicker({ accepts, startFolder: rawStartFolder, currentPath = null, onPick, onClose }) {
|
|
25
|
+
const t = usePluginTranslate();
|
|
26
|
+
const tree = useAssetTree(true, true);
|
|
27
|
+
const startFolder = normalizeStartFolder(rawStartFolder);
|
|
28
|
+
// Whatever had focus when the drawer mounted, read once during the first render (see MediaPicker).
|
|
29
|
+
const [opener] = useState(() => typeof document === "undefined" ? null : document.activeElement);
|
|
30
|
+
const [chosenFolder, setChosenFolder] = useState(null);
|
|
31
|
+
const [pending, setPending] = useState(currentPath);
|
|
32
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
33
|
+
const optionRefs = useRef([]);
|
|
34
|
+
const entries = tree.status === "ready" ? tree.entries : NO_ENTRIES;
|
|
35
|
+
const startExists = startFolder !== null && entries.some((entry) => entry.kind === "folder" && entry.path === startFolder);
|
|
36
|
+
const currentEntry = currentPath === null ? undefined : entries.find((entry) => entry.kind === "file" && entry.path === currentPath);
|
|
37
|
+
const currentUsable = currentEntry !== undefined && assetPathAccepted(currentEntry.path, accepts);
|
|
38
|
+
const folder = chosenFolder ?? (currentUsable && currentPath !== null ? assetParent(currentPath) : startExists && startFolder !== null ? startFolder : "");
|
|
39
|
+
// The held path is a selection only when the file is there and the type takes it.
|
|
40
|
+
const selectedPath = pending === currentPath && !currentUsable ? null : pending;
|
|
41
|
+
const folders = useMemo(() => inFolder(entries, folder, "folder"), [entries, folder]);
|
|
42
|
+
const files = useMemo(() => inFolder(entries, folder, "file"), [entries, folder]);
|
|
43
|
+
const crumbs = folder === "" ? [] : folder.split("/").map((name, index, all) => ({ name, path: all.slice(0, index + 1).join("/") }));
|
|
44
|
+
function openFolder(path) {
|
|
45
|
+
setChosenFolder(path);
|
|
46
|
+
setPending(null);
|
|
47
|
+
setActiveIndex(0);
|
|
48
|
+
}
|
|
49
|
+
function choose(entry) {
|
|
50
|
+
if (assetPathAccepted(entry.path, accepts))
|
|
51
|
+
setPending(entry.path);
|
|
52
|
+
}
|
|
53
|
+
function focusIndex(index) {
|
|
54
|
+
setActiveIndex(index);
|
|
55
|
+
optionRefs.current[index]?.focus();
|
|
56
|
+
}
|
|
57
|
+
function handleGridKeyDown(event) {
|
|
58
|
+
if (files.length === 0)
|
|
59
|
+
return;
|
|
60
|
+
// The grid reads in the page's direction (the compose sheet reads it the same way).
|
|
61
|
+
const step = gridArrowStep(event.key, event.currentTarget.closest('[dir="rtl"]') !== null);
|
|
62
|
+
let next = activeIndex;
|
|
63
|
+
if (step !== 0) {
|
|
64
|
+
next = Math.min(Math.max(activeIndex + step, 0), files.length - 1);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
switch (event.key) {
|
|
68
|
+
case "Home":
|
|
69
|
+
next = 0;
|
|
70
|
+
break;
|
|
71
|
+
case "End":
|
|
72
|
+
next = files.length - 1;
|
|
73
|
+
break;
|
|
74
|
+
case "Enter":
|
|
75
|
+
case " ": {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
const focused = files[activeIndex];
|
|
78
|
+
if (focused)
|
|
79
|
+
choose(focused);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
default:
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
focusIndex(next);
|
|
88
|
+
}
|
|
89
|
+
return (_jsx(Sheet, { open: true, onOpenChange: (next) => {
|
|
90
|
+
if (!next)
|
|
91
|
+
onClose();
|
|
92
|
+
}, children: _jsxs(SheetContent, { onCloseAutoFocus: (event) => {
|
|
93
|
+
if (opener?.isConnected) {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
opener.focus();
|
|
96
|
+
}
|
|
97
|
+
}, children: [_jsxs(SheetHeader, { className: "flex-col items-start gap-1", children: [_jsx(SheetTitle, { children: t("asset.pickerTitle") }), _jsx(SheetDescription, { children: t(accepts === "any" ? "asset.pickerAny" : "asset.pickerImages") })] }), _jsx("nav", { "aria-label": t("asset.location"), className: "shrink-0 border-b border-border-default px-4 py-2", children: _jsxs("ol", { className: "flex flex-wrap items-center gap-1 text-sm text-text-tertiary", children: [_jsx("li", { children: folder === "" ? (_jsx("span", { "aria-current": "page", className: "font-medium text-text-primary", children: t("asset.root") })) : (_jsx("button", { type: "button", onClick: () => openFolder(""), className: LINK_CLASS, children: t("asset.root") })) }), crumbs.map((crumb, index) => (_jsxs("li", { className: "flex min-w-0 items-center gap-1", children: [_jsx(ChevronRight, { "aria-hidden": "true", className: "size-3 shrink-0 rtl:rotate-180" }), index === crumbs.length - 1 ? (_jsx("span", { "aria-current": "page", className: "truncate font-medium text-text-primary", children: crumb.name })) : (_jsx("button", { type: "button", onClick: () => openFolder(crumb.path), className: cn("truncate", LINK_CLASS), children: crumb.name }))] }, crumb.path)))] }) }), _jsxs("div", { className: "flex flex-1 flex-col gap-4 overflow-y-auto p-4", children: [tree.status === "loading" && _jsx("p", { className: "text-sm text-text-secondary", children: t("asset.loading") }), tree.status === "forbidden" && _jsx("p", { className: "text-sm text-text-secondary", children: t("asset.noAccess") }), tree.status === "failed" && _jsx("p", { className: "text-sm text-danger-600", children: t("asset.loadFailed") }), tree.status === "ready" && tree.truncated && _jsx("p", { className: "text-sm text-text-tertiary", children: t("asset.truncated") }), folders.length > 0 && (_jsx("ul", { "aria-label": t("asset.folders"), className: "flex flex-wrap gap-2", children: folders.map((entry) => (_jsx("li", { className: "min-w-0", children: _jsxs("button", { type: "button", onClick: () => openFolder(entry.path), className: "flex max-w-full items-center gap-2 rounded-full border border-border-default bg-background-elevated px-3 py-1 text-xs text-text-secondary hover:bg-background-hover focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-600", children: [_jsx(FolderIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-text-tertiary" }), _jsx("span", { className: "truncate", children: assetBaseName(entry.path) })] }) }, entry.path))) })), tree.status === "ready" && files.length === 0 && folders.length === 0 && (_jsx("p", { className: "text-sm text-text-secondary", children: t("asset.empty") })), files.length > 0 && (_jsx("div", { role: "listbox", "aria-label": t("asset.files"), onKeyDown: handleGridKeyDown, className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: files.map((entry, index) => {
|
|
98
|
+
const accepted = assetPathAccepted(entry.path, accepts);
|
|
99
|
+
const selected = selectedPath === entry.path;
|
|
100
|
+
return (_jsxs("button", { type: "button", ref: (element) => {
|
|
101
|
+
optionRefs.current[index] = element;
|
|
102
|
+
}, role: "option", "aria-selected": selected, "aria-disabled": !accepted, tabIndex: index === activeIndex ? 0 : -1, onFocus: () => setActiveIndex(index), onClick: () => choose(entry), className: cn("flex flex-col overflow-hidden rounded-md border text-start focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-600", selected ? "border-primary-600 bg-primary-100" : "border-border-subtle hover:bg-background-elevated", !accepted && "cursor-not-allowed opacity-50 hover:bg-transparent"), children: [_jsx(TileThumbnail, { path: entry.path }), _jsxs("span", { className: "block min-w-0 px-2 py-1", children: [_jsx("span", { className: "block truncate font-mono text-xs text-text-primary", children: assetBaseName(entry.path) }), _jsx("span", { className: "block truncate text-xs text-text-tertiary", children: accepted ? formatSize(entry.size) : t("asset.notAnImage") })] })] }, entry.path));
|
|
103
|
+
}) }))] }), _jsxs(SheetFooter, { className: "items-center justify-end gap-2", children: [_jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: t("asset.cancel") }), _jsx(Button, { type: "button", disabled: selectedPath === null, onClick: () => {
|
|
104
|
+
if (selectedPath === null)
|
|
105
|
+
return;
|
|
106
|
+
onPick(selectedPath);
|
|
107
|
+
onClose();
|
|
108
|
+
}, children: selectedPath === null ? t("asset.confirmNone") : t("asset.confirm", { name: assetBaseName(selectedPath) }) })] })] }) }));
|
|
109
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AssetTreeEntry } from "@kardalum/api-schemas";
|
|
2
|
+
export type AssetTreeState = {
|
|
3
|
+
status: "loading";
|
|
4
|
+
} | {
|
|
5
|
+
status: "ready";
|
|
6
|
+
entries: AssetTreeEntry[];
|
|
7
|
+
truncated: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
status: "forbidden";
|
|
10
|
+
} | {
|
|
11
|
+
status: "failed";
|
|
12
|
+
};
|
|
13
|
+
/** The folder a path sits in, "" for the root. */
|
|
14
|
+
export declare function assetParent(path: string): string;
|
|
15
|
+
/** The last segment of a path. */
|
|
16
|
+
export declare function assetBaseName(path: string): string;
|
|
17
|
+
export declare function assetRawUrl(path: string): string;
|
|
18
|
+
/** A start folder as the tree spells it: trimmed, no leading or trailing slash; null when nothing is left. */
|
|
19
|
+
export declare function normalizeStartFolder(value: string | null): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Reads the tree (shared, see loadTree). `enabled` false makes no request. `fresh` skips the shared
|
|
22
|
+
* copy once, for the picker. A 403 is its own state.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useAssetTree(enabled?: boolean, fresh?: boolean): AssetTreeState;
|
|
25
|
+
/**
|
|
26
|
+
* An object URL for an image's bytes, or null (no path, not near the viewport yet, still loading, or the
|
|
27
|
+
* read failed). `element` is the tile to watch (null until it mounts); leave it undefined to fetch at once.
|
|
28
|
+
* At most 6 reads run at a time. Revoked when the path changes or the view goes.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useAssetThumbnail(path: string | null, element?: Element | null): string | null;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { MANAGE_API, usePluginApi } from "../plugin-context.js";
|
|
3
|
+
/** The folder a path sits in, "" for the root. */
|
|
4
|
+
export function assetParent(path) {
|
|
5
|
+
const slash = path.lastIndexOf("/");
|
|
6
|
+
return slash === -1 ? "" : path.slice(0, slash);
|
|
7
|
+
}
|
|
8
|
+
/** The last segment of a path. */
|
|
9
|
+
export function assetBaseName(path) {
|
|
10
|
+
return path.slice(path.lastIndexOf("/") + 1);
|
|
11
|
+
}
|
|
12
|
+
export function assetRawUrl(path) {
|
|
13
|
+
return `${MANAGE_API}/assets/raw?path=${encodeURIComponent(path)}`;
|
|
14
|
+
}
|
|
15
|
+
/** A start folder as the tree spells it: trimmed, no leading or trailing slash; null when nothing is left. */
|
|
16
|
+
export function normalizeStartFolder(value) {
|
|
17
|
+
if (value === null)
|
|
18
|
+
return null;
|
|
19
|
+
const folder = value
|
|
20
|
+
.trim()
|
|
21
|
+
.split("/")
|
|
22
|
+
.filter((part) => part !== "")
|
|
23
|
+
.join("/");
|
|
24
|
+
return folder === "" ? null : folder;
|
|
25
|
+
}
|
|
26
|
+
const TREE_LIFETIME_MS = 30_000;
|
|
27
|
+
const treeCache = new WeakMap();
|
|
28
|
+
function readTree(fetchApi) {
|
|
29
|
+
return fetchApi(`${MANAGE_API}/assets/tree`)
|
|
30
|
+
.then(async (response) => {
|
|
31
|
+
if (response.status === 403)
|
|
32
|
+
return { status: "forbidden" };
|
|
33
|
+
if (!response.ok)
|
|
34
|
+
return { status: "failed" };
|
|
35
|
+
const body = (await response.json());
|
|
36
|
+
return { status: "ready", entries: body.entries, truncated: body.truncated };
|
|
37
|
+
})
|
|
38
|
+
.catch(() => ({ status: "failed" }));
|
|
39
|
+
}
|
|
40
|
+
/** One read shared by every caller of the same API for a short while (and while in flight); a failed read is never kept. */
|
|
41
|
+
function loadTree(fetchApi, fresh) {
|
|
42
|
+
const cached = treeCache.get(fetchApi);
|
|
43
|
+
if (!fresh && cached && Date.now() - cached.at < TREE_LIFETIME_MS)
|
|
44
|
+
return cached.promise;
|
|
45
|
+
const entry = { at: Date.now(), promise: readTree(fetchApi) };
|
|
46
|
+
treeCache.set(fetchApi, entry);
|
|
47
|
+
void entry.promise.then((state) => {
|
|
48
|
+
if (state.status !== "ready" && treeCache.get(fetchApi) === entry)
|
|
49
|
+
treeCache.delete(fetchApi);
|
|
50
|
+
});
|
|
51
|
+
return entry.promise;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reads the tree (shared, see loadTree). `enabled` false makes no request. `fresh` skips the shared
|
|
55
|
+
* copy once, for the picker. A 403 is its own state.
|
|
56
|
+
*/
|
|
57
|
+
export function useAssetTree(enabled = true, fresh = false) {
|
|
58
|
+
const fetchApi = usePluginApi();
|
|
59
|
+
const [state, setState] = useState({ status: "loading" });
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!enabled)
|
|
62
|
+
return;
|
|
63
|
+
let cancelled = false;
|
|
64
|
+
void loadTree(fetchApi, fresh).then((next) => {
|
|
65
|
+
if (!cancelled)
|
|
66
|
+
setState(next);
|
|
67
|
+
});
|
|
68
|
+
return () => {
|
|
69
|
+
cancelled = true;
|
|
70
|
+
};
|
|
71
|
+
}, [fetchApi, enabled, fresh]);
|
|
72
|
+
return state;
|
|
73
|
+
}
|
|
74
|
+
const MAX_THUMBNAIL_FETCHES = 6;
|
|
75
|
+
let activeFetches = 0;
|
|
76
|
+
const waitingFetches = [];
|
|
77
|
+
function acquireSlot() {
|
|
78
|
+
if (activeFetches < MAX_THUMBNAIL_FETCHES) {
|
|
79
|
+
activeFetches += 1;
|
|
80
|
+
return Promise.resolve();
|
|
81
|
+
}
|
|
82
|
+
return new Promise((resolve) => waitingFetches.push(resolve));
|
|
83
|
+
}
|
|
84
|
+
function releaseSlot() {
|
|
85
|
+
const next = waitingFetches.shift();
|
|
86
|
+
if (next)
|
|
87
|
+
next();
|
|
88
|
+
else
|
|
89
|
+
activeFetches -= 1;
|
|
90
|
+
}
|
|
91
|
+
/** True once `element` has been near the viewport; always true where IntersectionObserver is absent. */
|
|
92
|
+
function useNearViewport(element) {
|
|
93
|
+
const supported = typeof IntersectionObserver !== "undefined";
|
|
94
|
+
const [seen, setSeen] = useState(false);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!supported || !element || seen)
|
|
97
|
+
return;
|
|
98
|
+
const observer = new IntersectionObserver((entries) => {
|
|
99
|
+
if (entries.some((entry) => entry.isIntersecting))
|
|
100
|
+
setSeen(true);
|
|
101
|
+
}, { rootMargin: "200px" });
|
|
102
|
+
observer.observe(element);
|
|
103
|
+
return () => observer.disconnect();
|
|
104
|
+
}, [supported, element, seen]);
|
|
105
|
+
return !supported || seen;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* An object URL for an image's bytes, or null (no path, not near the viewport yet, still loading, or the
|
|
109
|
+
* read failed). `element` is the tile to watch (null until it mounts); leave it undefined to fetch at once.
|
|
110
|
+
* At most 6 reads run at a time. Revoked when the path changes or the view goes.
|
|
111
|
+
*/
|
|
112
|
+
export function useAssetThumbnail(path, element) {
|
|
113
|
+
const fetchApi = usePluginApi();
|
|
114
|
+
const near = useNearViewport(element ?? null);
|
|
115
|
+
const ready = element === undefined || near;
|
|
116
|
+
const [url, setUrl] = useState(null);
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
setUrl(null);
|
|
119
|
+
if (path === null || !ready)
|
|
120
|
+
return;
|
|
121
|
+
let cancelled = false;
|
|
122
|
+
let objectUrl = null;
|
|
123
|
+
void acquireSlot().then(async () => {
|
|
124
|
+
try {
|
|
125
|
+
if (cancelled)
|
|
126
|
+
return;
|
|
127
|
+
const response = await fetchApi(assetRawUrl(path));
|
|
128
|
+
if (!response.ok || cancelled)
|
|
129
|
+
return;
|
|
130
|
+
const bytes = await response.blob();
|
|
131
|
+
if (cancelled)
|
|
132
|
+
return;
|
|
133
|
+
objectUrl = URL.createObjectURL(bytes);
|
|
134
|
+
setUrl(objectUrl);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// A failed read leaves the tile without a picture.
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
releaseSlot();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return () => {
|
|
144
|
+
cancelled = true;
|
|
145
|
+
if (objectUrl)
|
|
146
|
+
URL.revokeObjectURL(objectUrl);
|
|
147
|
+
};
|
|
148
|
+
}, [fetchApi, path, ready]);
|
|
149
|
+
return url;
|
|
150
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BUILT_IN_EDITOR_IDS: readonly string[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// S314o3 (D1): the ids of the built-in editors, as plain data the server can read without the
|
|
2
|
+
// React registry in built-ins.tsx. A plugin may not contribute an editor under one of these ids:
|
|
3
|
+
// the install refuses it, because the admin would refuse to register it and the server would
|
|
4
|
+
// validate the field by the built-in's rules. built-ins.test.tsx holds this list to what
|
|
5
|
+
// built-ins.tsx registers.
|
|
6
|
+
export const BUILT_IN_EDITOR_IDS = [
|
|
7
|
+
"com.kardalum.text",
|
|
8
|
+
"com.kardalum.number",
|
|
9
|
+
"com.kardalum.boolean",
|
|
10
|
+
"com.kardalum.date",
|
|
11
|
+
"com.kardalum.image",
|
|
12
|
+
"com.kardalum.fileupload",
|
|
13
|
+
"com.kardalum.richtext",
|
|
14
|
+
"com.kardalum.html",
|
|
15
|
+
"com.kardalum.daterange",
|
|
16
|
+
"com.kardalum.contentlist",
|
|
17
|
+
"com.kardalum.crop",
|
|
18
|
+
"com.kardalum.thumbnail",
|
|
19
|
+
"com.kardalum.asset",
|
|
20
|
+
];
|
|
@@ -11,4 +11,6 @@ export declare const CROP_SETTINGS_SCHEMA: JSONSchema7;
|
|
|
11
11
|
export declare const THUMBNAIL_SETTINGS_SCHEMA: JSONSchema7;
|
|
12
12
|
export declare const CROP_DEFAULT_SETTINGS: Record<string, unknown>;
|
|
13
13
|
export declare const THUMBNAIL_DEFAULT_SETTINGS: Record<string, unknown>;
|
|
14
|
+
export declare const ASSET_SETTINGS_SCHEMA: JSONSchema7;
|
|
15
|
+
export declare const ASSET_DEFAULT_SETTINGS: Record<string, unknown>;
|
|
14
16
|
export declare const BUILT_IN_SETTINGS_SCHEMAS: Readonly<Record<string, JSONSchema7>>;
|
|
@@ -208,6 +208,32 @@ export const THUMBNAIL_SETTINGS_SCHEMA = {
|
|
|
208
208
|
// not open and save back unchanged.
|
|
209
209
|
export const CROP_DEFAULT_SETTINGS = { ratio: "1:1", maxWidth: null };
|
|
210
210
|
export const THUMBNAIL_DEFAULT_SETTINGS = { longestEdge: 320 };
|
|
211
|
+
// S314p (D3). The hand-kept mirror of AssetFieldSettingsSchema in @kardalum/api-schemas, the
|
|
212
|
+
// generator's literal input-mode output (built-ins.test.tsx holds the two equal). Input mode for
|
|
213
|
+
// the crop's reason: both members carry defaults, and a client may send `{}`. The start folder's
|
|
214
|
+
// AssetPathSchema refinements have no JSON Schema form, so ajv checks its type and length only; a
|
|
215
|
+
// start folder that names no folder is harmless (the picker opens at the root).
|
|
216
|
+
export const ASSET_SETTINGS_SCHEMA = {
|
|
217
|
+
type: "object",
|
|
218
|
+
properties: {
|
|
219
|
+
accepts: { default: "images", type: "string", enum: ["images", "any"] },
|
|
220
|
+
startFolder: {
|
|
221
|
+
default: null,
|
|
222
|
+
anyOf: [
|
|
223
|
+
{
|
|
224
|
+
type: "string",
|
|
225
|
+
minLength: 1,
|
|
226
|
+
maxLength: 400,
|
|
227
|
+
description: "A path under public/: segments of letters, digits, spaces and _ - . ~ @ + , ( ) ! $ ' = ; & joined by /, none starting with a dot or ending with a dot or space, each at most 255 bytes, never under a reserved root.",
|
|
228
|
+
},
|
|
229
|
+
{ type: "null" },
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
additionalProperties: false,
|
|
234
|
+
};
|
|
235
|
+
// The settings migration 0033 seeds (ASSET_DATA_TYPE_CONFIG in @kardalum/api-schemas).
|
|
236
|
+
export const ASSET_DEFAULT_SETTINGS = { accepts: "images", startFolder: null };
|
|
211
237
|
// com.kardalum.contentlist is the first entry whose schema has a REQUIRED
|
|
212
238
|
// member (`columns`), so unlike the three above it cannot fall back to the
|
|
213
239
|
// "stored settings are {} until a webmaster edits them" convention: its
|
|
@@ -222,4 +248,5 @@ export const BUILT_IN_SETTINGS_SCHEMAS = {
|
|
|
222
248
|
"com.kardalum.fileupload": FILE_UPLOAD_SETTINGS_SCHEMA,
|
|
223
249
|
"com.kardalum.crop": CROP_SETTINGS_SCHEMA,
|
|
224
250
|
"com.kardalum.thumbnail": THUMBNAIL_SETTINGS_SCHEMA,
|
|
251
|
+
"com.kardalum.asset": ASSET_SETTINGS_SCHEMA,
|
|
225
252
|
};
|
|
@@ -44,4 +44,7 @@ export const BUILT_IN_VALUE_SCHEMAS = {
|
|
|
44
44
|
// and the rendition row records it. So this field, like the content list
|
|
45
45
|
// above, carries no value of its own.
|
|
46
46
|
"com.kardalum.thumbnail": { type: "null" },
|
|
47
|
+
// S314p (D3). A path under public/, as Settings, Assets names the file; the address a template
|
|
48
|
+
// prints is worked out at render.
|
|
49
|
+
"com.kardalum.asset": { type: "string" },
|
|
47
50
|
};
|
package/dist/built-ins.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CONTENT_LIST_DEFAULT_SETTINGS } from "@kardalum/api-schemas";
|
|
3
3
|
import { Checkbox, Input, PropertyField, usePropertyFieldControl } from "@kardalum/ui";
|
|
4
|
-
import { CONTENT_LIST_SETTINGS_SCHEMA, CROP_DEFAULT_SETTINGS, CROP_SETTINGS_SCHEMA, FILE_UPLOAD_SETTINGS_SCHEMA, HTML_DEFAULT_SETTINGS, HTML_SETTINGS_SCHEMA, IMAGE_DEFAULT_SETTINGS, IMAGE_SETTINGS_SCHEMA, TEXT_DEFAULT_SETTINGS, TEXT_SETTINGS_SCHEMA, THUMBNAIL_DEFAULT_SETTINGS, THUMBNAIL_SETTINGS_SCHEMA, } from "./built-in-settings-schemas.js";
|
|
4
|
+
import { ASSET_DEFAULT_SETTINGS, ASSET_SETTINGS_SCHEMA, CONTENT_LIST_SETTINGS_SCHEMA, CROP_DEFAULT_SETTINGS, CROP_SETTINGS_SCHEMA, FILE_UPLOAD_SETTINGS_SCHEMA, HTML_DEFAULT_SETTINGS, HTML_SETTINGS_SCHEMA, IMAGE_DEFAULT_SETTINGS, IMAGE_SETTINGS_SCHEMA, TEXT_DEFAULT_SETTINGS, TEXT_SETTINGS_SCHEMA, THUMBNAIL_DEFAULT_SETTINGS, THUMBNAIL_SETTINGS_SCHEMA, } from "./built-in-settings-schemas.js";
|
|
5
5
|
import { BUILT_IN_VALUE_SCHEMAS } from "./built-in-value-schemas.js";
|
|
6
6
|
import { BUILT_IN_SERIALIZERS, identitySerializer } from "./built-in-serializers.js";
|
|
7
7
|
import { BUILT_IN_DATATYPE_VALIDATORS } from "./datatype-validation.js";
|
|
8
8
|
import { definePlugin } from "./define-plugin.js";
|
|
9
9
|
import { usePluginSettings, usePluginSettingsValue, usePluginValue } from "./plugin-context.js";
|
|
10
10
|
import { registerDataType } from "./registry.js";
|
|
11
|
+
import { AssetInputView, AssetReadOnlyView, AssetSettingsView } from "./views/asset-view.js";
|
|
11
12
|
import { ContentListPreview } from "./views/content-list-preview.js";
|
|
12
13
|
import { ContentListSettingsView } from "./views/content-list-settings-view.js";
|
|
13
14
|
import { ContentListInputView, ContentListReadOnlyView } from "./views/content-list-view.js";
|
|
@@ -255,3 +256,11 @@ registerDataType(builtIn("thumbnail", "Thumbnail", "image-down", BUILT_IN_VALUE_
|
|
|
255
256
|
settings: ThumbnailSettingsView,
|
|
256
257
|
preview: ThumbnailReadOnlyView,
|
|
257
258
|
}, { settingsSchema: THUMBNAIL_SETTINGS_SCHEMA, defaultSettings: THUMBNAIL_DEFAULT_SETTINGS }));
|
|
259
|
+
// S314p (D3): the Asset editor, a file from Settings, Assets. Seeded as the "Asset" data type by
|
|
260
|
+
// migration 0033; its views read the asset tree through the host's fetch.
|
|
261
|
+
registerDataType(builtIn("asset", "Asset", "folder-open", BUILT_IN_VALUE_SCHEMAS["com.kardalum.asset"], {
|
|
262
|
+
input: AssetInputView,
|
|
263
|
+
readOnly: AssetReadOnlyView,
|
|
264
|
+
settings: AssetSettingsView,
|
|
265
|
+
preview: AssetReadOnlyView,
|
|
266
|
+
}, { settingsSchema: ASSET_SETTINGS_SCHEMA, defaultSettings: ASSET_DEFAULT_SETTINGS }));
|
package/dist/capabilities.js
CHANGED
|
@@ -35,6 +35,10 @@ export const CAPABILITY_LABELS = {
|
|
|
35
35
|
"admin.section": { operator: "Admin sections", shopper: "Adds admin screens" },
|
|
36
36
|
"admin.railEntry": { operator: "Admin rail entries", shopper: "Adds screens to built-in sections" },
|
|
37
37
|
"admin.dashboardWidget": { operator: "Dashboard widgets", shopper: "Adds dashboard widgets" },
|
|
38
|
+
"admin.notifications": {
|
|
39
|
+
operator: "Notifications",
|
|
40
|
+
shopper: "Sends notifications to people in the admin, for example to everyone who may publish.",
|
|
41
|
+
},
|
|
38
42
|
"render.template": { operator: "Render templates", shopper: "Ships render templates" },
|
|
39
43
|
"render.asset": { operator: "Editable assets", shopper: "Ships editable assets" },
|
|
40
44
|
"theme.tokens": { operator: "Theme tokens", shopper: "Restyles the admin" },
|
|
@@ -49,6 +53,7 @@ export const CAPABILITY_LABELS = {
|
|
|
49
53
|
"bundle.plugin": { operator: "Bundled plugins", shopper: "Installs other plugins with it" },
|
|
50
54
|
"bundle.template": { operator: "Bundled starter", shopper: "Comes with a frontend starter" },
|
|
51
55
|
"network.external": { operator: "External network", shopper: "Reaches the network" },
|
|
56
|
+
"network.vendorService": { operator: "Vendor service", shopper: "Serves its paid features from the author's server" },
|
|
52
57
|
"filesystem.access": { operator: "Filesystem access", shopper: "Reads or writes files" },
|
|
53
58
|
};
|
|
54
59
|
/**
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// dependency-free: the SERVER imports this module to build its validator
|
|
3
|
-
// lookup, and anything React-shaped here would drag the admin's UI graph
|
|
4
|
-
// into plugin artifacts (the S197 F5 lesson).
|
|
1
|
+
import { AssetPathSchema, assetPathAccepted } from "@kardalum/api-schemas";
|
|
5
2
|
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
6
3
|
// A member reads as its string, as null (absent), or as MALFORMED when it
|
|
7
4
|
// is present but not a string at all. Keeping the two failure modes apart
|
|
@@ -107,4 +104,21 @@ export const BUILT_IN_DATATYPE_VALIDATORS = {
|
|
|
107
104
|
"com.kardalum.thumbnail": {
|
|
108
105
|
isEmpty: () => true,
|
|
109
106
|
},
|
|
107
|
+
// S314p (D3). An Asset field holds a path under public/, the way Settings, Assets names a file.
|
|
108
|
+
// Its form is AssetPathSchema's (no "..", no hidden file, no reserved root); a type that takes
|
|
109
|
+
// images only also wants one of the image extensions. Whether the file exists is not asked
|
|
110
|
+
// (spec C6): a script may write the page before it uploads the kit's files, and the field shows a
|
|
111
|
+
// missing file instead.
|
|
112
|
+
"com.kardalum.asset": {
|
|
113
|
+
defaultSettings: { accepts: "images", startFolder: null },
|
|
114
|
+
isEmpty: (value) => value === null || value === undefined || value === "",
|
|
115
|
+
validate(value, { settings }) {
|
|
116
|
+
if (typeof value !== "string" || !AssetPathSchema.safeParse(value).success) {
|
|
117
|
+
return [{ key: "dataTypes.asset.errors.invalidPath" }];
|
|
118
|
+
}
|
|
119
|
+
if (!assetPathAccepted(value, settings.accepts))
|
|
120
|
+
return [{ key: "dataTypes.asset.errors.notAnImage" }];
|
|
121
|
+
return [];
|
|
122
|
+
},
|
|
123
|
+
},
|
|
110
124
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { BUILT_IN_SETTINGS_SCHEMAS } from "./built-in-settings-schemas.js";
|
|
2
2
|
export { BUILT_IN_VALUE_SCHEMAS } from "./built-in-value-schemas.js";
|
|
3
|
+
export { BUILT_IN_EDITOR_IDS } from "./built-in-editor-ids.js";
|
|
3
4
|
export { BUILT_IN_SERIALIZERS, identitySerializer, type DataTypeSerializer, } from "./built-in-serializers.js";
|
|
4
5
|
export { RENDITION_INELIGIBLE_TYPES, isRenditionIneligible } from "./rendition-eligibility.js";
|
package/dist/datatypes-entry.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// one.
|
|
10
10
|
export { BUILT_IN_SETTINGS_SCHEMAS } from "./built-in-settings-schemas.js";
|
|
11
11
|
export { BUILT_IN_VALUE_SCHEMAS } from "./built-in-value-schemas.js";
|
|
12
|
+
export { BUILT_IN_EDITOR_IDS } from "./built-in-editor-ids.js";
|
|
12
13
|
export { BUILT_IN_SERIALIZERS, identitySerializer, } from "./built-in-serializers.js";
|
|
13
14
|
// S234c fix wave: the "no GIF, no SVG" rule, read by the cut route so a
|
|
14
15
|
// signed-in caller cannot post a "crop" of a format the browser refuses to
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { EntitlementError, ENTITLEMENT_FLOOR_TABLE, isEntitlementError, requireEntitlement, structuredStorageFloor, type EntitlementFloor, type RequireEntitlementOptions, } from "./entitlement.js";
|
|
1
|
+
export { EntitlementError, ENTITLEMENT_FLOOR_TABLE, entitlementPlan, isEntitlementError, requireEntitlement, structuredStorageFloor, type EntitlementFloor, type EntitlementPlanOptions, type RequireEntitlementOptions, } from "./entitlement.js";
|
|
2
|
+
export { highestListingPlan, UNKNOWN_TERM, type EntitlementPlan } from "./entitlement-plan.js";
|
|
2
3
|
export { LICENSE_VERDICT_PUBLIC_KEYS } from "./license-verdict-keys.js";
|
|
3
4
|
export { isLocalHost } from "./local-host.js";
|
|
4
|
-
export type { Entitlement, EntitlementErrorCode, EntitlementVerdict, LicenseVerdictEnvelope, PluginTaskContext, } from "./entitlement-types.js";
|
|
5
|
+
export type { Entitlement, EntitlementErrorCode, EntitlementVerdict, LicenseVerdictEnvelope, LicenseVerdictTerm, ListingPlanSummary, PluginTaskContext, } from "./entitlement-types.js";
|
|
5
6
|
export type { TrustedKey } from "@kardalum/plugin-package";
|
|
@@ -19,6 +19,18 @@
|
|
|
19
19
|
//
|
|
20
20
|
// The host turns a thrown EntitlementError into a 403 for a route and skips
|
|
21
21
|
// a hook that throws it.
|
|
22
|
-
|
|
22
|
+
//
|
|
23
|
+
// S317: the plan and the term, after the check passed:
|
|
24
|
+
//
|
|
25
|
+
// const plan = entitlementPlan(context.entitlement, { pluginId: "com.acme.reports" });
|
|
26
|
+
// if (plan?.planId === "pro") { ... }
|
|
27
|
+
// if (plan?.term.state === "lapsed") { refuse writes, keep reads }
|
|
28
|
+
//
|
|
29
|
+
// S318: while the term is lapsed the host itself refuses the plugin's writes
|
|
30
|
+
// (403 plugin_read_only), and tells a route or hook so:
|
|
31
|
+
//
|
|
32
|
+
// if (context.readOnly) { skip writes }
|
|
33
|
+
export { EntitlementError, ENTITLEMENT_FLOOR_TABLE, entitlementPlan, isEntitlementError, requireEntitlement, structuredStorageFloor, } from "./entitlement.js";
|
|
34
|
+
export { highestListingPlan, UNKNOWN_TERM } from "./entitlement-plan.js";
|
|
23
35
|
export { LICENSE_VERDICT_PUBLIC_KEYS } from "./license-verdict-keys.js";
|
|
24
36
|
export { isLocalHost } from "./local-host.js";
|