alinea 2.0.0-preview.1 → 2.0.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.init/content/pages/welcome.json +1 -1
- package/dist/LICENSES.md +61 -34
- package/dist/adapter/next/DevRemote.d.ts +3 -0
- package/dist/adapter/next/DevRemote.js +37 -0
- package/dist/adapter/next/ForwardCredentials.d.ts +1 -0
- package/dist/adapter/next/ForwardCredentials.js +17 -0
- package/dist/adapter/next/cms.js +86 -38
- package/dist/adapter/next/context.d.ts +1 -1
- package/dist/adapter/next/context.js +11 -3
- package/dist/adapter/next/handler.d.ts +2 -0
- package/dist/adapter/next/handler.js +23 -16
- package/dist/adapter/next/with-alinea.js +18 -16
- package/dist/backend/Handler.d.ts +14 -13
- package/dist/backend/Handler.js +53 -22
- package/dist/backend/resolver/ParsePreview.d.ts +8 -4
- package/dist/backend/resolver/ParsePreview.js +40 -43
- package/dist/bundled.d.ts +255 -60
- package/dist/chunks/{chunk-LUBOGJCG.js → chunk-6V4TAD2N.js} +1 -1
- package/dist/chunks/{chunk-TL7ZW6BX.js → chunk-A3XXZBOQ.js} +2535 -2999
- package/dist/chunks/chunk-AC5ATYI3.js +1434 -0
- package/dist/chunks/{chunk-7ORQ7BYK.js → chunk-KMLLLZ6X.js} +202 -269
- package/dist/chunks/{chunk-IWN3T3FL.js → chunk-O7XWTMCB.js} +1 -1
- package/dist/chunks/{chunk-53DZYORR.js → chunk-PAYSVIYI.js} +76 -176
- package/dist/chunks/{chunk-YK3OSMDM.js → chunk-S4AU6SRS.js} +188 -158
- package/dist/chunks/{chunk-FRYHNUEK.js → chunk-UVOEM4AH.js} +6 -3
- package/dist/chunks/{chunk-I7X64JTZ.js → chunk-VXZM6V4P.js} +4 -4
- package/dist/cli/Generate.js +3 -13
- package/dist/cli/Serve.js +7 -3
- package/dist/cli/bin.js +8 -5
- package/dist/cli/generate/CopyStaticFiles.js +2 -3
- package/dist/cli/generate/DevDB.d.ts +1 -1
- package/dist/cli/generate/DevDB.js +3 -5
- package/dist/cli/serve/CreateLocalServer.d.ts +1 -1
- package/dist/cli/serve/CreateLocalServer.js +3 -2
- package/dist/cli/serve/DevServer.d.ts +3 -2
- package/dist/cli/serve/DevServer.js +60 -3
- package/dist/cli/serve/ServeContext.d.ts +1 -0
- package/dist/cli/serve/StartServer.d.ts +1 -0
- package/dist/cli/serve/StartServer.js +6 -1
- package/dist/cli/util/EnsureLibs.js +2 -2
- package/dist/cli/util/EnsureNode.js +2 -2
- package/dist/cloud/CloudRemote.js +1 -1
- package/dist/components/Breadcrumbs.js +8 -8
- package/dist/components/Button.js +6 -6
- package/dist/components/Calendar.js +9 -9
- package/dist/components/Checkbox.js +9 -9
- package/dist/components/CheckboxGroup.js +6 -6
- package/dist/components/ColorSwatch.js +6 -6
- package/dist/components/ColorSwatchPicker.js +6 -6
- package/dist/components/ComboBox.js +16 -16
- package/dist/components/DateField.js +9 -9
- package/dist/components/DatePicker.js +11 -11
- package/dist/components/DateRangePicker.js +14 -14
- package/dist/components/Dialog.js +6 -6
- package/dist/components/Disclosure.js +14 -14
- package/dist/components/DropZone.js +6 -6
- package/dist/components/Label.js +14 -14
- package/dist/components/Link.js +6 -6
- package/dist/components/List.js +32 -32
- package/dist/components/Menu.js +10 -10
- package/dist/components/Modal.js +8 -8
- package/dist/components/MultipleSelect.js +25 -25
- package/dist/components/NumberField.d.ts +2 -1
- package/dist/components/NumberField.js +25 -15
- package/dist/components/Popover.js +6 -6
- package/dist/components/ProgressCircle.js +9 -9
- package/dist/components/RadioGroup.js +8 -8
- package/dist/components/SearchField.js +15 -15
- package/dist/components/Select.js +14 -14
- package/dist/components/Surface.js +2 -2
- package/dist/components/Switch.js +8 -8
- package/dist/components/Table.js +14 -14
- package/dist/components/Tabs.js +7 -7
- package/dist/components/TagGroup.js +8 -8
- package/dist/components/TextField.js +10 -10
- package/dist/components/TimeField.js +8 -8
- package/dist/components/Toggle.js +8 -8
- package/dist/components/Toolbar.js +9 -9
- package/dist/components/Tooltip.js +7 -7
- package/dist/components/Tree.js +10 -10
- package/dist/core/Client.js +3 -2
- package/dist/core/Config.d.ts +4 -0
- package/dist/core/Config.js +6 -0
- package/dist/core/Connection.d.ts +2 -2
- package/dist/core/Connection.js +7 -0
- package/dist/core/Graph.d.ts +3 -4
- package/dist/core/ListRow.d.ts +2 -0
- package/dist/core/OrderBy.d.ts +7 -3
- package/dist/core/TextDoc.d.ts +11 -0
- package/dist/core/Trace.d.ts +8 -0
- package/dist/core/Trace.js +32 -0
- package/dist/core/db/CommitRequest.d.ts +0 -3
- package/dist/core/db/CommitRequest.js +0 -9
- package/dist/core/db/EntryDB.js +1 -1
- package/dist/core/db/EntryIndex.d.ts +10 -0
- package/dist/core/db/EntryIndex.js +117 -9
- package/dist/core/db/EntryResolver.js +104 -29
- package/dist/core/db/EntryTransaction.d.ts +1 -2
- package/dist/core/db/EntryTransaction.js +25 -13
- package/dist/core/db/LocalDB.d.ts +2 -3
- package/dist/core/db/LocalDB.js +24 -19
- package/dist/core/field/RichTextField.d.ts +30 -3
- package/dist/core/field/RichTextField.js +125 -41
- package/dist/core/media/MediaAltField.d.ts +1 -0
- package/dist/core/media/MediaAltField.js +9 -1
- package/dist/core/source/OverlaySource.d.ts +12 -0
- package/dist/core/source/OverlaySource.js +50 -0
- package/dist/core/source/Source.d.ts +1 -1
- package/dist/core/source/Source.js +3 -3
- package/dist/dashboard/App.css +158 -0
- package/dist/dashboard/App.js +3 -3
- package/dist/dashboard/app/AccessDenied.js +1 -1
- package/dist/dashboard/app/ActivityStatus.js +14 -14
- package/dist/dashboard/app/AppShell.js +2 -2
- package/dist/dashboard/app/AuthView.js +12 -12
- package/dist/dashboard/app/Badge.js +2 -2
- package/dist/dashboard/app/CompactField.js +13 -13
- package/dist/dashboard/app/DashboardErrorBoundary.js +6 -6
- package/dist/dashboard/app/DashboardLayout.js +22 -19
- package/dist/dashboard/app/EntryHeader.js +10 -10
- package/dist/dashboard/app/EntryReferences.js +9 -9
- package/dist/dashboard/app/EntrySidebar.d.ts +1 -1
- package/dist/dashboard/app/EntrySidebar.js +19 -18
- package/dist/dashboard/app/EntrySidebarPreview.d.ts +1 -1
- package/dist/dashboard/app/EntrySidebarPreview.js +20 -15
- package/dist/dashboard/app/EntryTranslationBanner.js +6 -6
- package/dist/dashboard/app/Explorer.js +46 -46
- package/dist/dashboard/app/ExplorerCards.js +42 -42
- package/dist/dashboard/app/ExplorerFileCard.js +16 -16
- package/dist/dashboard/app/ExplorerList.js +15 -15
- package/dist/dashboard/app/ExplorerModal.js +5 -5
- package/dist/dashboard/app/ExplorerTable.js +54 -54
- package/dist/dashboard/app/ExternalLinkPicker.js +15 -4
- package/dist/dashboard/app/LinkPicker.js +6 -6
- package/dist/dashboard/app/LocaleMenu.js +11 -11
- package/dist/dashboard/app/SidebarLayout.d.ts +8 -0
- package/dist/dashboard/app/SidebarLayout.js +1169 -0
- package/dist/dashboard/app/SidebarTree.js +44 -44
- package/dist/dashboard/app/WorkspaceMenu.js +17 -17
- package/dist/dashboard/app/WorkspaceRoots.js +26 -26
- package/dist/dashboard/app/editor/FileEditor.js +28 -29
- package/dist/dashboard/app/editor/FilePreview.js +2 -2
- package/dist/dashboard/app/editor/MediaAltField.view.d.ts +1 -1
- package/dist/dashboard/app/editor/MediaAltField.view.js +6 -9
- package/dist/dashboard/app/modals/CreateEntry.js +4 -4
- package/dist/dashboard/app/pages/EntryPage.js +49 -25
- package/dist/dashboard/app/pages/UsersPage.js +38 -38
- package/dist/dashboard/app/ui/DashboardModal.js +22 -22
- package/dist/dashboard/app/ui/Rail.js +2 -2
- package/dist/dashboard/app/ui/Sidebar.js +2 -2
- package/dist/dashboard/atoms/auth.js +2 -0
- package/dist/dashboard/atoms/dashboard.d.ts +9 -0
- package/dist/dashboard/atoms/dashboard.js +17 -0
- package/dist/dashboard/atoms/editor.d.ts +7 -1
- package/dist/dashboard/atoms/editor.js +4 -1
- package/dist/dashboard/atoms/entry.d.ts +3 -1
- package/dist/dashboard/atoms/entry.js +55 -15
- package/dist/dashboard/atoms/explorer.js +3 -8
- package/dist/dashboard/atoms/preview.d.ts +3 -0
- package/dist/dashboard/atoms/preview.js +18 -1
- package/dist/dashboard/hooks.d.ts +4 -2
- package/dist/dashboard/hooks.js +9 -5
- package/dist/dashboard/icons.d.ts +1 -0
- package/dist/dashboard/icons.js +10 -0
- package/dist/field/check/CheckField.view.js +2 -2
- package/dist/field/code/CodeField.view.js +13 -13
- package/dist/field/date/DateField.view.js +12 -2
- package/dist/field/link/Link.js +2 -2
- package/dist/field/link/LinkField.view.js +88 -77
- package/dist/field/list/ListField.view.js +22 -33
- package/dist/field/metadata/MetadataField.view.js +20 -20
- package/dist/field/number/NumberField.d.ts +2 -0
- package/dist/field/number/NumberField.view.js +4 -2
- package/dist/field/richtext/PickTextLink.d.ts +7 -0
- package/dist/field/richtext/PickTextLink.js +104 -2
- package/dist/field/richtext/ReferenceLink.d.ts +4 -1
- package/dist/field/richtext/ReferenceLink.js +18 -4
- package/dist/field/richtext/RichTextDocument.d.ts +7 -2
- package/dist/field/richtext/RichTextDocument.js +34 -5
- package/dist/field/richtext/RichTextExtensions.d.ts +3 -1
- package/dist/field/richtext/RichTextExtensions.js +2704 -7467
- package/dist/field/richtext/RichTextField.d.ts +4 -0
- package/dist/field/richtext/RichTextField.story.d.ts +4 -0
- package/dist/field/richtext/RichTextField.view.js +44 -21
- package/dist/field/richtext/RichTextInsertMenu.js +281 -495
- package/dist/field/richtext/RichTextToolbar.d.ts +5 -2
- package/dist/field/richtext/RichTextToolbar.js +38 -3
- package/dist/field/richtext/Toolbar.d.ts +19 -1
- package/dist/field/richtext/Toolbar.js +18 -13
- package/dist/field/richtext/extensions/Anchor.js +1 -1
- package/dist/field/richtext/extensions/Link.js +1 -1
- package/dist/field/richtext/extensions/Small.js +1 -1
- package/dist/field/select/SelectField.view.js +8 -6
- package/dist/index.css +219 -14
- package/dist/next.cjs +18 -16
- package/dist/next.d.ts +2 -1
- package/dist/next.edge.d.ts +2 -1
- package/dist/ui/RichText.d.ts +1 -0
- package/dist/ui/RichText.js +29 -2
- package/package.json +6 -3
- package/dist/chunks/{chunk-JFROOUG6.js → chunk-NIVGVRDS.js} +17 -17
|
@@ -8,11 +8,20 @@ import {
|
|
|
8
8
|
import "../../chunks/chunk-CQ52GEHY.js";
|
|
9
9
|
|
|
10
10
|
// src/field/richtext/PickTextLink.tsx
|
|
11
|
-
import { Button, TextField } from "alinea/components";
|
|
11
|
+
import { Button, DialogTrigger, TextField } from "alinea/components";
|
|
12
|
+
import { Config } from "alinea/core/Config";
|
|
13
|
+
import { Entry } from "alinea/core/Entry";
|
|
14
|
+
import { createId } from "alinea/core/Id";
|
|
15
|
+
import { imageExtensions } from "alinea/core/media/IsImage";
|
|
16
|
+
import { mediaAltText } from "alinea/core/media/MediaAltField";
|
|
17
|
+
import { MediaFile } from "alinea/core/media/MediaTypes";
|
|
12
18
|
import { Reference } from "alinea/core/Reference";
|
|
13
19
|
import { type as createType, Type } from "alinea/core/Type";
|
|
14
20
|
import { NodeEditor } from "alinea/dashboard/app/EntryFields";
|
|
15
21
|
import { ReactiveNode } from "alinea/dashboard/atoms/ReactiveNode";
|
|
22
|
+
import { configAtom, graphAtom } from "alinea/dashboard/atoms/core";
|
|
23
|
+
import { useDashboardContext } from "alinea/dashboard/hooks";
|
|
24
|
+
import { ImagePicker } from "alinea/dashboard/app/ImagePicker";
|
|
16
25
|
import {
|
|
17
26
|
DashboardModal,
|
|
18
27
|
DashboardModalCloseButton,
|
|
@@ -28,6 +37,7 @@ import { link as createLink } from "alinea/field/link";
|
|
|
28
37
|
import {
|
|
29
38
|
useCallback,
|
|
30
39
|
useMemo,
|
|
40
|
+
useRef,
|
|
31
41
|
useState
|
|
32
42
|
} from "react";
|
|
33
43
|
|
|
@@ -43,7 +53,12 @@ function usePickTextLink() {
|
|
|
43
53
|
const [pending, setPending] = useState();
|
|
44
54
|
const pickLink = useCallback((options) => {
|
|
45
55
|
return new Promise((resolve) => {
|
|
46
|
-
setPending({ options, resolve });
|
|
56
|
+
setPending({ kind: "link", options, resolve });
|
|
57
|
+
});
|
|
58
|
+
}, []);
|
|
59
|
+
const pickImage = useCallback((options) => {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
setPending({ kind: "image", options, resolve });
|
|
47
62
|
});
|
|
48
63
|
}, []);
|
|
49
64
|
const cancel = useCallback(() => {
|
|
@@ -60,7 +75,9 @@ function usePickTextLink() {
|
|
|
60
75
|
}, []);
|
|
61
76
|
return {
|
|
62
77
|
isOpen: Boolean(pending),
|
|
78
|
+
kind: pending?.kind ?? "link",
|
|
63
79
|
options: pending?.options ?? {},
|
|
80
|
+
pickImage,
|
|
64
81
|
pickLink,
|
|
65
82
|
cancel,
|
|
66
83
|
confirm
|
|
@@ -68,6 +85,7 @@ function usePickTextLink() {
|
|
|
68
85
|
}
|
|
69
86
|
function PickTextLink({ picker }) {
|
|
70
87
|
if (!picker.isOpen) return null;
|
|
88
|
+
if (picker.kind === "image") return /* @__PURE__ */ jsx(PickRichTextImage, { picker });
|
|
71
89
|
return /* @__PURE__ */ jsx(
|
|
72
90
|
DashboardModal,
|
|
73
91
|
{
|
|
@@ -79,6 +97,90 @@ function PickTextLink({ picker }) {
|
|
|
79
97
|
}
|
|
80
98
|
);
|
|
81
99
|
}
|
|
100
|
+
function PickRichTextImage({ picker }) {
|
|
101
|
+
const config = useAtomValue(configAtom);
|
|
102
|
+
const graph = useAtomValue(graphAtom);
|
|
103
|
+
const locale = useDashboardContext().page.locale ?? void 0;
|
|
104
|
+
const confirming = useRef(false);
|
|
105
|
+
const initialEntry = imageReferenceEntryId(picker.options.link);
|
|
106
|
+
const initialSelection = initialEntry ? [initialEntry] : [];
|
|
107
|
+
function onConfirm(selection) {
|
|
108
|
+
const [entryId] = selection;
|
|
109
|
+
if (!entryId) {
|
|
110
|
+
picker.confirm({ link: void 0 });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
confirming.current = true;
|
|
114
|
+
void resolveRichTextImage(
|
|
115
|
+
config,
|
|
116
|
+
graph,
|
|
117
|
+
entryId,
|
|
118
|
+
picker.options.link,
|
|
119
|
+
locale
|
|
120
|
+
).then(picker.confirm, (error) => {
|
|
121
|
+
console.error(error);
|
|
122
|
+
picker.cancel();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return /* @__PURE__ */ jsxs(
|
|
126
|
+
DialogTrigger,
|
|
127
|
+
{
|
|
128
|
+
isOpen: true,
|
|
129
|
+
onOpenChange: (isOpen) => {
|
|
130
|
+
if (!isOpen && !confirming.current) picker.cancel();
|
|
131
|
+
},
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ jsx(Button, { style: { display: "none" }, children: "Pick image" }),
|
|
134
|
+
/* @__PURE__ */ jsx(
|
|
135
|
+
ImagePicker,
|
|
136
|
+
{
|
|
137
|
+
condition: richTextImageCondition,
|
|
138
|
+
initialSelection,
|
|
139
|
+
label: "Pick image",
|
|
140
|
+
selectionBehavior: "replace",
|
|
141
|
+
selectionMode: "single",
|
|
142
|
+
onConfirm
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
async function resolveRichTextImage(config, graph, entryId, existing, locale) {
|
|
150
|
+
const image = await graph.first({
|
|
151
|
+
id: entryId,
|
|
152
|
+
status: "preferDraft",
|
|
153
|
+
select: {
|
|
154
|
+
url: Entry.url,
|
|
155
|
+
alt: MediaFile.alt
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
if (!image) throw new Error(`Image entry not found: ${entryId}`);
|
|
159
|
+
const link = {
|
|
160
|
+
[Reference.id]: existing?._id ?? createId(),
|
|
161
|
+
[Reference.type]: "image",
|
|
162
|
+
_entry: entryId
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
165
|
+
alt: mediaAltText(image.alt, locale),
|
|
166
|
+
link,
|
|
167
|
+
src: URL.parse(image.url, Config.baseUrl(config) ?? window.location.href)?.href
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
var richTextImageCondition = {
|
|
171
|
+
_type: "MediaFile",
|
|
172
|
+
extension: {
|
|
173
|
+
in: [
|
|
174
|
+
...imageExtensions,
|
|
175
|
+
...imageExtensions.map((extension) => extension.toUpperCase())
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
function imageReferenceEntryId(reference) {
|
|
180
|
+
if (!reference || reference._type !== "image" || !("_entry" in reference))
|
|
181
|
+
return;
|
|
182
|
+
return typeof reference._entry === "string" ? reference._entry : void 0;
|
|
183
|
+
}
|
|
82
184
|
function PickTextLinkForm({ picker }) {
|
|
83
185
|
const modal = useDashboardModal();
|
|
84
186
|
const options = picker.options;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Reference } from 'alinea/core/Reference';
|
|
2
2
|
import type { HTMLProps } from 'react';
|
|
3
3
|
interface Anchor extends HTMLProps<HTMLAnchorElement> {
|
|
4
|
+
_id?: string;
|
|
5
|
+
_entry?: string;
|
|
6
|
+
_link?: 'entry' | 'file' | 'image' | 'url';
|
|
4
7
|
'data-id'?: string;
|
|
5
8
|
'data-entry'?: string;
|
|
6
9
|
'data-anchor'?: string;
|
|
7
|
-
'data-link'?: 'entry' | 'file' | 'url';
|
|
10
|
+
'data-link'?: 'entry' | 'file' | 'image' | 'url';
|
|
8
11
|
'data-suffix'?: string;
|
|
9
12
|
}
|
|
10
13
|
export declare function referenceToAttributes(reference: Reference): Anchor;
|
|
@@ -42,12 +42,26 @@ function referenceToAttributes(reference) {
|
|
|
42
42
|
target: void 0
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
case "image": {
|
|
46
|
+
const ref = reference;
|
|
47
|
+
return {
|
|
48
|
+
"data-id": ref[Reference.id],
|
|
49
|
+
"data-entry": ref[EntryReference.entry],
|
|
50
|
+
"data-anchor": void 0,
|
|
51
|
+
"data-link": "image",
|
|
52
|
+
"data-suffix": void 0,
|
|
53
|
+
href: void 0,
|
|
54
|
+
target: void 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
45
57
|
default:
|
|
46
58
|
throw new Error(`Unexpected reference type: ${reference[Reference.type]}`);
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
61
|
function attributesToReference(attributes) {
|
|
50
|
-
const id = attributes["data-id"];
|
|
62
|
+
const id = attributes["data-id"] ?? attributes._id;
|
|
63
|
+
const entry = attributes["data-entry"] ?? attributes._entry;
|
|
64
|
+
const link = attributes["data-link"] ?? attributes._link;
|
|
51
65
|
if (!id) {
|
|
52
66
|
if (attributes.href)
|
|
53
67
|
return {
|
|
@@ -58,12 +72,12 @@ function attributesToReference(attributes) {
|
|
|
58
72
|
};
|
|
59
73
|
return;
|
|
60
74
|
}
|
|
61
|
-
if (
|
|
62
|
-
const type =
|
|
75
|
+
if (entry) {
|
|
76
|
+
const type = link === "file" ? "file" : link === "image" ? "image" : "entry";
|
|
63
77
|
return {
|
|
64
78
|
[Reference.id]: id,
|
|
65
79
|
[Reference.type]: type,
|
|
66
|
-
[EntryReference.entry]:
|
|
80
|
+
[EntryReference.entry]: entry,
|
|
67
81
|
[EntryReference.anchor]: type === "entry" ? attributes["data-anchor"] : void 0,
|
|
68
82
|
[EntryReference.suffix]: type === "entry" ? attributes["data-suffix"] : void 0
|
|
69
83
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { BlockNode, type TextDoc } from 'alinea/core/TextDoc';
|
|
2
|
-
import type
|
|
3
|
-
|
|
2
|
+
import { type Editor, type JSONContent } from '@tiptap/core';
|
|
3
|
+
/** Include data attributes produced by custom extensions in the stored document. */
|
|
4
|
+
export declare function editorDocument(editor: Editor): JSONContent;
|
|
5
|
+
export declare function editorContent(nodes: TextDoc, images?: ReadonlyMap<string, {
|
|
6
|
+
src: string;
|
|
7
|
+
alt: string;
|
|
8
|
+
}>): JSONContent;
|
|
4
9
|
export declare function editorNodes(content: JSONContent, resolveBlock?: (id: string, typeName: string, snapshot: BlockNode | undefined) => BlockNode | undefined): TextDoc;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRenderedAttributes
|
|
3
|
+
} from "../../chunks/chunk-A3XXZBOQ.js";
|
|
1
4
|
import "../../chunks/chunk-CQ52GEHY.js";
|
|
2
5
|
|
|
3
6
|
// src/field/richtext/RichTextDocument.ts
|
|
@@ -14,17 +17,37 @@ import {
|
|
|
14
17
|
richTextBlockValueAttribute
|
|
15
18
|
} from "./RichTextBlockValue.js";
|
|
16
19
|
import { isRecord } from "alinea/core/util/Objects";
|
|
17
|
-
function
|
|
20
|
+
function editorDocument(editor) {
|
|
21
|
+
function serialize(node) {
|
|
22
|
+
const content = node.toJSON();
|
|
23
|
+
if (!node.isText) {
|
|
24
|
+
const dataAttributes = Object.fromEntries(
|
|
25
|
+
Object.entries(
|
|
26
|
+
getRenderedAttributes(node, editor.extensionManager.attributes)
|
|
27
|
+
).filter(([key, value]) => key.startsWith("data-") && value != null)
|
|
28
|
+
);
|
|
29
|
+
if (Object.keys(dataAttributes).length)
|
|
30
|
+
content.attrs = { ...content.attrs, ...dataAttributes };
|
|
31
|
+
if (node.childCount) {
|
|
32
|
+
content.content = [];
|
|
33
|
+
node.forEach((child) => content.content.push(serialize(child)));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return content;
|
|
37
|
+
}
|
|
38
|
+
return serialize(editor.state.doc);
|
|
39
|
+
}
|
|
40
|
+
function editorContent(nodes, images) {
|
|
18
41
|
return {
|
|
19
42
|
type: "doc",
|
|
20
|
-
content: nodes.map(nodeToContent)
|
|
43
|
+
content: nodes.length ? nodes.map((node) => nodeToContent(node, images)) : [{ type: "paragraph" }]
|
|
21
44
|
};
|
|
22
45
|
}
|
|
23
46
|
function editorNodes(content, resolveBlock) {
|
|
24
47
|
const nodes = content.content?.flatMap((node) => contentToNodes(node, resolveBlock)) ?? [];
|
|
25
48
|
return isEmptyDocument(nodes) ? [] : nodes;
|
|
26
49
|
}
|
|
27
|
-
function nodeToContent(node) {
|
|
50
|
+
function nodeToContent(node, images) {
|
|
28
51
|
if (isBlock(node)) {
|
|
29
52
|
return {
|
|
30
53
|
type: node[Node.type],
|
|
@@ -40,6 +63,7 @@ function nodeToContent(node) {
|
|
|
40
63
|
}
|
|
41
64
|
if (isElement(node)) {
|
|
42
65
|
const { [Node.type]: type, [ElementNode.content]: content, ...attrs } = node;
|
|
66
|
+
const resolvedImage = type === "image" && typeof attrs._entry === "string" ? images?.get(attrs._entry) : void 0;
|
|
43
67
|
let editorContent2 = content;
|
|
44
68
|
if (type === "listItem" && content?.some(isText)) {
|
|
45
69
|
let flushInline2 = function() {
|
|
@@ -66,8 +90,8 @@ function nodeToContent(node) {
|
|
|
66
90
|
}
|
|
67
91
|
return {
|
|
68
92
|
type,
|
|
69
|
-
attrs: withoutNullish(attrs),
|
|
70
|
-
content: editorContent2?.map(nodeToContent)
|
|
93
|
+
attrs: withoutNullish({ ...attrs, ...resolvedImage }),
|
|
94
|
+
content: editorContent2?.map((child) => nodeToContent(child, images))
|
|
71
95
|
};
|
|
72
96
|
}
|
|
73
97
|
throw new TypeError(
|
|
@@ -98,6 +122,10 @@ function contentToNodes(content, resolveBlock) {
|
|
|
98
122
|
return [node];
|
|
99
123
|
}
|
|
100
124
|
const { [richTextBlockValueAttribute]: _blockSnapshot, ...elementAttributes } = attrs ?? {};
|
|
125
|
+
if (type === "image" && elementAttributes._link === "image" && typeof elementAttributes._entry === "string") {
|
|
126
|
+
delete elementAttributes.src;
|
|
127
|
+
delete elementAttributes.alt;
|
|
128
|
+
}
|
|
101
129
|
const children = content.content?.flatMap(
|
|
102
130
|
(node) => contentToNodes(node, resolveBlock)
|
|
103
131
|
);
|
|
@@ -158,5 +186,6 @@ function isMatchingBlock(value, id, typeName) {
|
|
|
158
186
|
}
|
|
159
187
|
export {
|
|
160
188
|
editorContent,
|
|
189
|
+
editorDocument,
|
|
161
190
|
editorNodes
|
|
162
191
|
};
|
|
@@ -13,6 +13,7 @@ export declare const extensions: {
|
|
|
13
13
|
Italic: import("@tiptap/core").Mark<import("@tiptap/extension-italic").ItalicOptions, any>;
|
|
14
14
|
Strike: import("@tiptap/core").Mark<import("@tiptap/extension-strike").StrikeOptions, any>;
|
|
15
15
|
HorizontalRule: TipTapNode<import("@tiptap/extension-horizontal-rule").HorizontalRuleOptions, any>;
|
|
16
|
+
Image: TipTapNode<import("@tiptap/extension-image").ImageOptions, any>;
|
|
16
17
|
BulletList: TipTapNode<import("@tiptap/extension-list").BulletListOptions, any>;
|
|
17
18
|
OrderedList: TipTapNode<import("@tiptap/extension-list").OrderedListOptions, any>;
|
|
18
19
|
ListItem: TipTapNode<import("@tiptap/extension-list").ListItemOptions, any>;
|
|
@@ -33,7 +34,7 @@ export declare const extensions: {
|
|
|
33
34
|
Highlight: import("@tiptap/core").Mark<import("@tiptap/extension-highlight").HighlightOptions, any>;
|
|
34
35
|
UndoRedo: Extension<import("@tiptap/extensions").UndoRedoOptions, any>;
|
|
35
36
|
};
|
|
36
|
-
export declare function defaultExtensionConfig(getEntryAnchors?: () => Iterable<string
|
|
37
|
+
export declare function defaultExtensionConfig(getEntryAnchors?: () => Iterable<string>, enableImageResize?: boolean): {
|
|
37
38
|
Document: TipTapNode<any, any>;
|
|
38
39
|
Text: TipTapNode<any, any>;
|
|
39
40
|
Paragraph: TipTapNode<import("@tiptap/extension-paragraph").ParagraphOptions, any>;
|
|
@@ -43,6 +44,7 @@ export declare function defaultExtensionConfig(getEntryAnchors?: () => Iterable<
|
|
|
43
44
|
Italic: import("@tiptap/core").Mark<import("@tiptap/extension-italic").ItalicOptions, any>;
|
|
44
45
|
Strike: import("@tiptap/core").Mark<import("@tiptap/extension-strike").StrikeOptions, any>;
|
|
45
46
|
HorizontalRule: TipTapNode<import("@tiptap/extension-horizontal-rule").HorizontalRuleOptions, any>;
|
|
47
|
+
Image: TipTapNode<import("@tiptap/extension-image").ImageOptions, any>;
|
|
46
48
|
BulletList: TipTapNode<import("@tiptap/extension-list").BulletListOptions, any>;
|
|
47
49
|
OrderedList: TipTapNode<import("@tiptap/extension-list").OrderedListOptions, any>;
|
|
48
50
|
ListItem: TipTapNode<import("@tiptap/extension-list").ListItemOptions, any>;
|