@lupinum/ginko-editor 0.0.0-stage → 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 +12 -0
- package/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/assets.d.ts +70 -0
- package/dist/assets.js +31 -0
- package/dist/core/component-props.d.ts +87 -0
- package/dist/core/component-props.js +134 -0
- package/dist/core/convert.d.ts +24 -0
- package/dist/core/convert.js +278 -0
- package/dist/core/editor.d.ts +60 -0
- package/dist/core/editor.js +85 -0
- package/dist/core/extensions.d.ts +38 -0
- package/dist/core/extensions.js +444 -0
- package/dist/core/file-images.d.ts +9 -0
- package/dist/core/file-images.js +54 -0
- package/dist/core/image-frame.d.ts +23 -0
- package/dist/core/image-frame.js +24 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.js +17 -0
- package/dist/core/link-card.d.ts +20 -0
- package/dist/core/link-card.js +70 -0
- package/dist/core/link.d.ts +3 -0
- package/dist/core/link.js +8 -0
- package/dist/core/move.d.ts +11 -0
- package/dist/core/move.js +37 -0
- package/dist/core/paste-html.d.ts +6 -0
- package/dist/core/paste-html.js +384 -0
- package/dist/core/paste.d.ts +21 -0
- package/dist/core/paste.js +108 -0
- package/dist/core/problems.d.ts +31 -0
- package/dist/core/problems.js +54 -0
- package/dist/core/search.d.ts +47 -0
- package/dist/core/search.js +148 -0
- package/dist/core/slash.d.ts +93 -0
- package/dist/core/slash.js +215 -0
- package/dist/core/table.d.ts +34 -0
- package/dist/core/table.js +141 -0
- package/dist/core/uploads.d.ts +23 -0
- package/dist/core/uploads.js +71 -0
- package/dist/core/use-editor.d.ts +19 -0
- package/dist/core/use-editor.js +53 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/issues.d.ts +49 -0
- package/dist/issues.js +9 -0
- package/dist/today.d.ts +6 -0
- package/dist/today.js +19 -0
- package/dist/useUpload.d.ts +48 -0
- package/dist/useUpload.js +59 -0
- package/dist/values.d.ts +14 -0
- package/dist/values.js +36 -0
- package/package.json +58 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @lupinum/ginko-editor
|
|
2
|
+
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#148](https://github.com/lupinum-dev/ginko/pull/148) [`38dd667`](https://github.com/lupinum-dev/ginko/commit/38dd667394ceb1134bcd7d0f627c7004cee08841) Thanks [@Mat4m0](https://github.com/Mat4m0)! - Add `@lupinum/ginko-server`, `@lupinum/ginko-studio` and `@lupinum/ginko-editor` to npm, so people can host the Ginko platform themselves.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`05c6945`](https://github.com/lupinum-dev/ginko/commit/05c69459b076ca87e9fee376098c10f3b15f66f7), [`ab3b70e`](https://github.com/lupinum-dev/ginko/commit/ab3b70e6ceb230f2de490c818553a4cde78d626c), [`ed2eb8e`](https://github.com/lupinum-dev/ginko/commit/ed2eb8ebc757f20bbfee8077fc6a3ecc690c38e5), [`d89413d`](https://github.com/lupinum-dev/ginko/commit/d89413d2b7ab21863e349bd91c3704587f44b808), [`ab3b70e`](https://github.com/lupinum-dev/ginko/commit/ab3b70e6ceb230f2de490c818553a4cde78d626c), [`103d424`](https://github.com/lupinum-dev/ginko/commit/103d4243c63e3ad0e9507a9efb0173eb1b3b4573), [`d89413d`](https://github.com/lupinum-dev/ginko/commit/d89413d2b7ab21863e349bd91c3704587f44b808), [`ab3b70e`](https://github.com/lupinum-dev/ginko/commit/ab3b70e6ceb230f2de490c818553a4cde78d626c), [`d89413d`](https://github.com/lupinum-dev/ginko/commit/d89413d2b7ab21863e349bd91c3704587f44b808), [`d89413d`](https://github.com/lupinum-dev/ginko/commit/d89413d2b7ab21863e349bd91c3704587f44b808)]:
|
|
12
|
+
- @lupinum/ginko@0.18.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Lupinum OG
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lupinum/ginko-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
You do not install this package by hand: the Studio ([`@lupinum/ginko-studio`](../ginko-studio)) depends on it. To
|
|
4
|
+
run the platform, see [Host the platform](https://ginko.lupinum.com/docs/host-the-platform).
|
|
5
|
+
|
|
6
|
+
The editing logic for [Ginko](https://github.com/lupinum-dev/ginko/tree/main/packages/ginko) bricks,
|
|
7
|
+
without any UI. The form components (one per field type, built on shadcn-vue) live in the Studio
|
|
8
|
+
layer, `@lupinum/ginko-studio`.
|
|
9
|
+
|
|
10
|
+
## What is in it
|
|
11
|
+
|
|
12
|
+
| Module | Purpose |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| `core/` | The headless Markdown editor: TipTap extensions per profile, Markdown to editor document and back (`toEditorDoc`, `fromEditorDoc`), `createGinkoEditor`, `useGinkoEditor`. Untouched blocks are saved byte for byte. |
|
|
15
|
+
| `assets.ts` | `GinkoAssets`, the upload adapter the host provides once (`provideGinkoAssets`, `useGinkoAssets`). |
|
|
16
|
+
| `useUpload.ts` | The upload flow image and file fields share: picker, cancel, error, retry, save blocking. |
|
|
17
|
+
| `issues.ts` | `BLOCKERS`, `TRANSLATION`, `ownIssues`, `issuesUnder`: server validation issues per field. |
|
|
18
|
+
| `values.ts`, `today.ts` | `textIn`, `newRowId`, `parseMoney`, `formatAmount`, `useToday`. |
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
MIT © Lupinum OG
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type InjectionKey, type Ref } from 'vue';
|
|
2
|
+
/** Processing state of one upload: the server checks (and for photos, converts) a file after it arrives. */
|
|
3
|
+
export interface UploadState {
|
|
4
|
+
status: 'processing' | 'ready' | 'failed';
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
/** What a ready upload offers the form: where to show it and the facts about the file. */
|
|
8
|
+
export interface UploadDetails {
|
|
9
|
+
url: string;
|
|
10
|
+
name: string;
|
|
11
|
+
size: number;
|
|
12
|
+
width: number | null;
|
|
13
|
+
height: number | null;
|
|
14
|
+
/** The library's description per language: it applies wherever a field has none of its own. */
|
|
15
|
+
alt?: Record<string, string>;
|
|
16
|
+
/** The focus point set in Files (0..1 from the top left): a crop keeps it in view. */
|
|
17
|
+
focus?: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
};
|
|
21
|
+
/** In the trash: a field keeps showing it, but a text may not name it (the save refuses), so a text shows it as missing. */
|
|
22
|
+
trashed?: true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* How image and file fields reach the host's storage. The host knows its site and its backend;
|
|
26
|
+
* the fields only ask for state, details and uploads.
|
|
27
|
+
*/
|
|
28
|
+
export interface GinkoAssets {
|
|
29
|
+
/** Live processing state of one upload; undefined while unknown or when id is undefined. */
|
|
30
|
+
state(id: Ref<string | undefined>): Ref<UploadState | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Live details (URL and file facts) for uploaded files; undefined while loading. An id that is
|
|
33
|
+
* not ready or not this site's maps to null.
|
|
34
|
+
*/
|
|
35
|
+
details(ids: Ref<string[]>): Ref<Record<string, UploadDetails | null> | undefined>;
|
|
36
|
+
/** Uploads a file and resolves with its id. Rejects when `signal` aborts. */
|
|
37
|
+
upload(kind: 'image' | 'file', file: File, signal: AbortSignal): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* The focus point of a library photo (0..1 from the top left), which every use of the photo shares. `allowed`: this
|
|
40
|
+
* person may change it (on the platform owner and admin). Absent: the host offers no way to set it.
|
|
41
|
+
*/
|
|
42
|
+
focus?: {
|
|
43
|
+
allowed: Ref<boolean>;
|
|
44
|
+
set(file: string, focus: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare const GINKO_ASSETS: InjectionKey<GinkoAssets>;
|
|
51
|
+
/** Call once in a parent of the forms. */
|
|
52
|
+
export declare function provideGinkoAssets(assets: GinkoAssets): void;
|
|
53
|
+
export declare function useGinkoAssets(): GinkoAssets;
|
|
54
|
+
/**
|
|
55
|
+
* The library files that the pictures of one Markdown editor name (``): the text keeps the
|
|
56
|
+
* reference, the editor shows the file. One query for all of them.
|
|
57
|
+
*/
|
|
58
|
+
export interface FileImages {
|
|
59
|
+
/** Starts loading the file of a `$file.<id>` source; any other source needs nothing. Call it outside a computed. */
|
|
60
|
+
want(src: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* The file of a `$file.<id>` source (reactive): undefined while it loads and for any other source, null when the
|
|
63
|
+
* library has no ready file with this ID or the file is in the trash.
|
|
64
|
+
*/
|
|
65
|
+
file(src: string): UploadDetails | null | undefined;
|
|
66
|
+
/** The text in place of a file the library does not have, in the UI language. */
|
|
67
|
+
missingText(): string;
|
|
68
|
+
}
|
|
69
|
+
/** Call once per editor, in setup. Files once seen stay known, so a picture does not flicker while a new one loads. */
|
|
70
|
+
export declare function useFileImages(assets: GinkoAssets, missingText: () => string): FileImages;
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { fileRefOf } from "@lupinum/ginko/internal";
|
|
2
|
+
import { inject, provide, reactive, ref, watch } from "vue";
|
|
3
|
+
export const GINKO_ASSETS = Symbol("ginko:assets");
|
|
4
|
+
export function provideGinkoAssets(assets) {
|
|
5
|
+
provide(GINKO_ASSETS, assets);
|
|
6
|
+
}
|
|
7
|
+
export function useGinkoAssets() {
|
|
8
|
+
const assets = inject(GINKO_ASSETS, void 0);
|
|
9
|
+
if (!assets) throw new Error("[ginko-editor] provideGinkoAssets(...) fehlt: Bild- und Dateifelder brauchen einen Upload-Adapter.");
|
|
10
|
+
return assets;
|
|
11
|
+
}
|
|
12
|
+
export function useFileImages(assets, missingText) {
|
|
13
|
+
const ids = ref([]);
|
|
14
|
+
const details = assets.details(ids);
|
|
15
|
+
const known = reactive(/* @__PURE__ */ Object.create(null));
|
|
16
|
+
watch(details, (next) => {
|
|
17
|
+
if (next) Object.assign(known, next);
|
|
18
|
+
}, { immediate: true });
|
|
19
|
+
return {
|
|
20
|
+
want(src) {
|
|
21
|
+
const id = fileRefOf(src);
|
|
22
|
+
if (id && !ids.value.includes(id)) ids.value = [...ids.value, id];
|
|
23
|
+
},
|
|
24
|
+
file(src) {
|
|
25
|
+
const id = fileRefOf(src);
|
|
26
|
+
if (id === void 0 || !(id in known)) return void 0;
|
|
27
|
+
return known[id]?.trashed ? null : known[id];
|
|
28
|
+
},
|
|
29
|
+
missingText
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Field, Label } from '@lupinum/ginko';
|
|
2
|
+
import type { ComponentDef, ComponentRegistry, Described } from '@lupinum/ginko/internal';
|
|
3
|
+
export type ComponentProps = Record<string, unknown>;
|
|
4
|
+
/** A prop as a form shows it: `undefined` = not set. */
|
|
5
|
+
export type PropValue = string | number | boolean | string[] | undefined;
|
|
6
|
+
/** The prop fields a component form can edit (the types the registry allows, see `componentProblems`). */
|
|
7
|
+
export type PropField = Extract<Field, {
|
|
8
|
+
type: 'text' | 'longtext' | 'number' | 'boolean' | 'choice' | 'choices' | 'image' | 'ref';
|
|
9
|
+
}>;
|
|
10
|
+
export type ComponentMode = 'live' | 'card';
|
|
11
|
+
/**
|
|
12
|
+
* What a registry entry may say in its `editor` field beyond the core's own type (`icon`, `group`, `example`).
|
|
13
|
+
* `hidden`: not offered in the slash menu (a short form that stays valid in existing texts). `keywords`: more
|
|
14
|
+
* words the slash menu finds the entry by. `aliasOf`: this tag is a short form of `tag` with `prop` = `value`;
|
|
15
|
+
* the settings of a short form offer that prop and turn the node into `tag` when it is changed.
|
|
16
|
+
*/
|
|
17
|
+
export interface EditorMeta {
|
|
18
|
+
hidden?: boolean;
|
|
19
|
+
keywords?: readonly string[];
|
|
20
|
+
aliasOf?: {
|
|
21
|
+
tag: string;
|
|
22
|
+
prop: string;
|
|
23
|
+
value: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare const editorMeta: (def: Pick<ComponentDef, "editor"> | undefined) => EditorMeta;
|
|
27
|
+
/** The long form a short-form tag stands for, or undefined when `tag` is not one. */
|
|
28
|
+
export declare function aliasOf(registry: ComponentRegistry | undefined, tag: string): (EditorMeta['aliasOf'] & {
|
|
29
|
+
field: PropField;
|
|
30
|
+
}) | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* How a `component` node is shown: `live` = the real Vue component with the editable content in its default
|
|
33
|
+
* slot; `card` = a frame with the registry label, a one-line summary of the props, and the content below.
|
|
34
|
+
* Live needs a Vue implementation in the Studio (`liveTags`), a block component, no named slots, no `children`
|
|
35
|
+
* restriction (the component reads its children, which the editor wraps), and no `parents` (it looks right
|
|
36
|
+
* only inside its parent).
|
|
37
|
+
*/
|
|
38
|
+
export declare function componentMode(tag: string, registry: ComponentRegistry | undefined, liveTags: ReadonlySet<string> | readonly string[]): ComponentMode;
|
|
39
|
+
/** The prop fields of a component in registry order. Retired props and types a form cannot show are left out. */
|
|
40
|
+
export declare function propFields(def: Pick<ComponentDef, 'props'>): Array<[key: string, field: PropField]>;
|
|
41
|
+
/** The raw value: the key or its bound form `:key`. */
|
|
42
|
+
export declare function rawProp(props: ComponentProps | undefined, key: string): unknown;
|
|
43
|
+
/** The value of a prop for the form. */
|
|
44
|
+
export declare function readProp(field: PropField, props: ComponentProps | undefined, key: string): PropValue;
|
|
45
|
+
/**
|
|
46
|
+
* `props` with one prop set, as a new object. `undefined` (or an empty list) removes it. A boolean that equals
|
|
47
|
+
* the registry default is removed too, so `Geöffnet` off leaves no `open="false"` behind; a boolean that is on
|
|
48
|
+
* is written bare. An empty text stays as an empty string, so the check can report it (a required text must not be empty).
|
|
49
|
+
*/
|
|
50
|
+
export declare function writeProp(field: PropField, props: ComponentProps | undefined, key: string, value: PropValue): ComponentProps;
|
|
51
|
+
/** Prop names the profile check of `parseMarkdown` requires to be a safe address, whatever the field says. */
|
|
52
|
+
/**
|
|
53
|
+
* Why `value` does not fit prop `key` of component `tag`, as a German sentence that starts with the label of the
|
|
54
|
+
* prop ("Titel ist zu lang (höchstens 120 Zeichen)."), or undefined. The messages are the core's (`componentPropProblem`),
|
|
55
|
+
* plus the profile check's rule for addresses. A required prop without value is reported.
|
|
56
|
+
*/
|
|
57
|
+
export declare function propProblem(registry: ComponentRegistry, tag: string, key: string, value: PropValue): string | undefined;
|
|
58
|
+
/** `propProblem` with catalog key and parameters (`coreMessage(locale, key, params)` gives the sentence in a language). */
|
|
59
|
+
export declare function propProblemMessage(registry: ComponentRegistry, tag: string, key: string, value: PropValue): Described | undefined;
|
|
60
|
+
/** The keys of required props that have no valid value in `props`. */
|
|
61
|
+
export declare function missingRequired(registry: ComponentRegistry, tag: string, props: ComponentProps | undefined): string[];
|
|
62
|
+
/** What a block card shows instead of its props: what it is about, a few choices in words, and its pictures. */
|
|
63
|
+
export interface BlockSummary {
|
|
64
|
+
/** The caption, title, description or name, else the first picture's file name; cut at 80 characters. */
|
|
65
|
+
title?: string;
|
|
66
|
+
/** Choices set to something else than their default, as their option labels ("Quadrat"); at most three. */
|
|
67
|
+
facts: string[];
|
|
68
|
+
/** The pictures of the image props in registry order: the stored address, the library file and the line under it. */
|
|
69
|
+
pictures: Array<{
|
|
70
|
+
key: string;
|
|
71
|
+
src: string;
|
|
72
|
+
file?: string;
|
|
73
|
+
note?: string;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The card summary of a block (`::figure{src="$file.k57" caption="Der Gastgarten" width="2756" aspect="square"}`
|
|
78
|
+
* → title "Der Gastgarten", facts ["Quadrat"], one picture). Numbers, addresses and on/off switches are settings
|
|
79
|
+
* for the look (pixel sizes, spacing, "wider than the text"): they stay in the settings, never on the card.
|
|
80
|
+
* `label` gives a registry label in the editor's language; `fileName` the name of a library file (undefined while it loads).
|
|
81
|
+
*/
|
|
82
|
+
export declare function blockSummary(props: ComponentProps | undefined, def: Pick<ComponentDef, 'props'> | undefined, { label, fileName }: {
|
|
83
|
+
label: (label: Label) => string;
|
|
84
|
+
fileName?: (id: string) => string | undefined;
|
|
85
|
+
}): BlockSummary;
|
|
86
|
+
/** Longest value the text input of a prop takes. */
|
|
87
|
+
export declare const propMax: (field: PropField) => number | undefined;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { componentPropMessage, msg, effectiveMax, fileRefOf, isSafeHref, labelOf, URL_PROPS } from "@lupinum/ginko/internal";
|
|
2
|
+
export const editorMeta = (def) => def?.editor ?? {};
|
|
3
|
+
export function aliasOf(registry, tag) {
|
|
4
|
+
const alias = registry && Object.hasOwn(registry, tag) ? editorMeta(registry[tag]).aliasOf : void 0;
|
|
5
|
+
const field = alias && registry && Object.hasOwn(registry, alias.tag) ? registry[alias.tag].props[alias.prop] : void 0;
|
|
6
|
+
return alias && field?.type === "choice" ? { ...alias, field } : void 0;
|
|
7
|
+
}
|
|
8
|
+
export function componentMode(tag, registry, liveTags) {
|
|
9
|
+
const def = registry && Object.hasOwn(registry, tag) ? registry[tag] : void 0;
|
|
10
|
+
if (!def || def.kind !== "block") return "card";
|
|
11
|
+
const live = Array.isArray(liveTags) ? liveTags.includes(tag) : liveTags.has(tag);
|
|
12
|
+
if (!live) return "card";
|
|
13
|
+
if (def.slots && Object.keys(def.slots).length) return "card";
|
|
14
|
+
if (def.children?.length || def.parents?.length) return "card";
|
|
15
|
+
return "live";
|
|
16
|
+
}
|
|
17
|
+
export function propFields(def) {
|
|
18
|
+
return Object.entries(def.props ?? {}).filter((entry) => !entry[1].retired && ["text", "longtext", "number", "boolean", "choice", "choices", "image", "ref"].includes(entry[1].type));
|
|
19
|
+
}
|
|
20
|
+
export function rawProp(props, key) {
|
|
21
|
+
if (!props) return void 0;
|
|
22
|
+
return Object.hasOwn(props, key) ? props[key] : props[`:${key}`];
|
|
23
|
+
}
|
|
24
|
+
const isOn = (raw) => raw === true || raw === "true" || raw === "";
|
|
25
|
+
export function readProp(field, props, key) {
|
|
26
|
+
const raw = rawProp(props, key);
|
|
27
|
+
switch (field.type) {
|
|
28
|
+
case "boolean":
|
|
29
|
+
return raw === void 0 ? field.default === true ? true : false : isOn(raw);
|
|
30
|
+
case "number": {
|
|
31
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
32
|
+
const n = Number(raw);
|
|
33
|
+
return Number.isFinite(n) ? n : void 0;
|
|
34
|
+
}
|
|
35
|
+
case "choices":
|
|
36
|
+
return typeof raw === "string" ? raw.split(",").map((v) => v.trim()).filter(Boolean) : void 0;
|
|
37
|
+
default:
|
|
38
|
+
return typeof raw === "string" ? raw : void 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function rawOf(field, value) {
|
|
42
|
+
if (value === void 0) return void 0;
|
|
43
|
+
if (field.type === "boolean") return value === true ? "true" : "false";
|
|
44
|
+
if (Array.isArray(value)) return value.length ? value.join(",") : void 0;
|
|
45
|
+
const text2 = String(value);
|
|
46
|
+
return text2 === "" ? "" : text2;
|
|
47
|
+
}
|
|
48
|
+
export function writeProp(field, props, key, value) {
|
|
49
|
+
const out = { ...props ?? {} };
|
|
50
|
+
const name = Object.hasOwn(out, key) ? key : Object.hasOwn(out, `:${key}`) ? `:${key}` : void 0;
|
|
51
|
+
let raw = rawOf(field, value);
|
|
52
|
+
if (field.type === "boolean") {
|
|
53
|
+
const on = value === true;
|
|
54
|
+
const asDefault = on === (field.default === true);
|
|
55
|
+
if (asDefault) {
|
|
56
|
+
if (name) delete out[name];
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
if (name) out[name] = on ? "true" : "false";
|
|
60
|
+
else if (on) out[`:${key}`] = "true";
|
|
61
|
+
else out[key] = "false";
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
if (raw === void 0) {
|
|
65
|
+
if (name) delete out[name];
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
if (name) out[name] = raw;
|
|
69
|
+
else out[key] = raw;
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
const text = (field) => labelOf(field.label, "", "");
|
|
73
|
+
export function propProblem(registry, tag, key, value) {
|
|
74
|
+
return propProblemMessage(registry, tag, key, value)?.message;
|
|
75
|
+
}
|
|
76
|
+
export function propProblemMessage(registry, tag, key, value) {
|
|
77
|
+
const field = registry[tag]?.props[key];
|
|
78
|
+
if (!field) return void 0;
|
|
79
|
+
const raw = rawOf(field, value);
|
|
80
|
+
const label = text(field);
|
|
81
|
+
if (raw === void 0) return field.optional ? void 0 : msg("editor.prop.missing", { label });
|
|
82
|
+
if (raw !== "" && (URL_PROPS.has(key) || field.type === "text" && field.format === "url") && !isSafeHref(raw)) return msg("markdown.unsafeLink");
|
|
83
|
+
if (!field.optional && (field.type === "text" || field.type === "longtext") && raw.trim() === "") return msg("editor.prop.empty", { label });
|
|
84
|
+
const problem = componentPropMessage(field, raw);
|
|
85
|
+
return problem === void 0 ? void 0 : msg("editor.prop.invalid", { label, problem: { key: problem.key, ...problem.params ? { params: problem.params } : {} } });
|
|
86
|
+
}
|
|
87
|
+
export function missingRequired(registry, tag, props) {
|
|
88
|
+
const def = registry[tag];
|
|
89
|
+
if (!def) return [];
|
|
90
|
+
return propFields(def).filter(([key, field]) => !field.optional && propProblem(registry, tag, key, readProp(field, props, key)) !== void 0).map(([key]) => key);
|
|
91
|
+
}
|
|
92
|
+
const TITLE_KEYS = ["caption", "title", "alt", "name", "label"];
|
|
93
|
+
const cut = (text2, max) => text2.length > max ? `${text2.slice(0, max - 1)}\u2026` : text2;
|
|
94
|
+
export function blockSummary(props, def, { label, fileName }) {
|
|
95
|
+
const fields = def ? propFields(def) : [];
|
|
96
|
+
const textOf = (key) => {
|
|
97
|
+
const raw = rawProp(props, key);
|
|
98
|
+
return typeof raw === "string" ? raw.trim() : "";
|
|
99
|
+
};
|
|
100
|
+
const texts = fields.filter(([, field]) => field.type === "text" && field.format !== "url" || field.type === "longtext").map(([key]) => key);
|
|
101
|
+
const titleKey = [...TITLE_KEYS.filter((key) => texts.includes(key) || !def && textOf(key)), ...texts].find((key) => textOf(key));
|
|
102
|
+
const pictures = fields.filter(([key, field]) => field.type === "image" && textOf(key)).map(([key]) => {
|
|
103
|
+
const src = textOf(key);
|
|
104
|
+
const file = fileRefOf(src);
|
|
105
|
+
return { key, src, ...file ? { file } : {} };
|
|
106
|
+
});
|
|
107
|
+
const nameOf = (picture) => (picture.file ? fileName?.(picture.file) : picture.src.split(/[?#]/)[0].split("/").pop()) || void 0;
|
|
108
|
+
const title = titleKey ? textOf(titleKey) : pictures[0] && nameOf(pictures[0]);
|
|
109
|
+
const one = pictures.length === 1 ? ["caption", "alt"].map(textOf).find((text2) => text2 && text2 !== title) ?? (titleKey ? nameOf(pictures[0]) : void 0) : void 0;
|
|
110
|
+
const facts = fields.flatMap(([key, field]) => {
|
|
111
|
+
if (field.type === "choice") {
|
|
112
|
+
const value = textOf(key);
|
|
113
|
+
const option = field.options.find((o) => o.value === value);
|
|
114
|
+
return value && value !== field.default && option ? [label(option.label)] : [];
|
|
115
|
+
}
|
|
116
|
+
if (field.type === "choices") {
|
|
117
|
+
const chosen = readProp(field, props, key);
|
|
118
|
+
return Array.isArray(chosen) && chosen.length ? [chosen.map((value) => label(field.options.find((o) => o.value === value)?.label ?? value)).join(", ")] : [];
|
|
119
|
+
}
|
|
120
|
+
return [];
|
|
121
|
+
}).slice(0, 3);
|
|
122
|
+
return {
|
|
123
|
+
...title ? { title: cut(title, 80) } : {},
|
|
124
|
+
facts,
|
|
125
|
+
pictures: pictures.map((picture) => {
|
|
126
|
+
const note = pictures.length === 1 ? one : nameOf(picture);
|
|
127
|
+
return { ...picture, ...note && note !== title ? { note: cut(note, 120) } : {} };
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export const propMax = (field) => {
|
|
132
|
+
const max = field.type === "text" || field.type === "longtext" ? effectiveMax(field) : void 0;
|
|
133
|
+
return max !== void 0 && Number.isFinite(max) ? max : void 0;
|
|
134
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ComponentRegistry } from '@lupinum/ginko/internal';
|
|
2
|
+
import type { Json } from '@lupinum/ginko';
|
|
3
|
+
/** A ProseMirror node as JSON (`editor.getJSON()`). */
|
|
4
|
+
export interface GinkoDocNode {
|
|
5
|
+
type: string;
|
|
6
|
+
attrs?: Record<string, any>;
|
|
7
|
+
content?: GinkoDocNode[];
|
|
8
|
+
marks?: Array<{
|
|
9
|
+
type: string;
|
|
10
|
+
attrs?: Record<string, any>;
|
|
11
|
+
}>;
|
|
12
|
+
text?: string;
|
|
13
|
+
}
|
|
14
|
+
export type GinkoDoc = GinkoDocNode & {
|
|
15
|
+
type: 'doc';
|
|
16
|
+
};
|
|
17
|
+
export interface ToDocOptions {
|
|
18
|
+
/** With a registry, a component of kind `inline` sits inside a paragraph, one of kind `block` stands alone. */
|
|
19
|
+
components?: ComponentRegistry;
|
|
20
|
+
/** The Markdown text of a node the editor cannot show (a `raw` node), for display. */
|
|
21
|
+
sourceOf?: (node: Json) => string | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function toEditorDoc(nodes: readonly Json[], options?: ToDocOptions): GinkoDoc;
|
|
24
|
+
export declare function fromEditorDoc(doc: GinkoDocNode): Json[];
|