opacacms 0.1.11 → 0.1.13
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/admin/index.js +9464 -21
- package/dist/admin/webcomponent.d.ts +1 -1
- package/dist/admin/webcomponent.js +9620 -6
- package/dist/admin.css +1 -0
- package/dist/{chunk-6dhs73zq.js → chunk-0am1m47g.js} +1 -1
- package/dist/{chunk-0nf7fe26.js → chunk-0d9aqz6z.js} +1 -1
- package/dist/{chunk-cvdd4eqh.js → chunk-2kyhqvhc.js} +5 -1
- package/dist/{chunk-gjjcc4hm.js → chunk-2z8wxx9g.js} +21 -6
- package/dist/{chunk-xg35h5a3.js → chunk-7fyepksb.js} +1 -1
- package/dist/{chunk-njytmdb4.js → chunk-pxh5encs.js} +34 -24
- package/dist/{chunk-n8aekdnr.js → chunk-qkn1ykrj.js} +33 -23
- package/dist/{chunk-kwp83w8b.js → chunk-wmvjvn7b.js} +4 -4
- package/dist/{chunk-qrt22f6e.js → chunk-wq314kkx.js} +35 -25
- package/dist/{chunk-eqtsfyjf.js → chunk-x2ejaftz.js} +52 -28
- package/dist/{chunk-6ew02s0c.js → chunk-xtwc125q.js} +18 -18
- package/dist/cli/index.js +5 -5
- package/dist/db/better-sqlite.d.ts +1 -0
- package/dist/db/better-sqlite.js +3 -3
- package/dist/db/bun-sqlite.d.ts +1 -0
- package/dist/db/bun-sqlite.js +3 -3
- package/dist/db/d1.js +3 -3
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.js +17 -13
- package/dist/db/postgres.js +3 -3
- package/dist/db/sqlite.js +3 -3
- package/dist/runtimes/bun.js +2 -2
- package/dist/runtimes/cloudflare-workers.js +2 -2
- package/dist/runtimes/next.js +2 -2
- package/dist/runtimes/node.js +2 -2
- package/dist/server.js +2 -2
- package/package.json +8 -2
- package/bun.lock +0 -34
- package/dist/admin/index.css +0 -47
- package/dist/api.d.ts +0 -6
- package/dist/api.js +0 -27
- package/dist/chunk-2zm8cy1w.js +0 -9482
- package/global.d.ts +0 -11
- package/src/admin/api-client.ts +0 -63
- package/src/admin/auth-client.ts +0 -40
- package/src/admin/custom-field.ts +0 -179
- package/src/admin/index.ts +0 -15
- package/src/admin/react.tsx +0 -72
- package/src/admin/router.ts +0 -9
- package/src/admin/stores/admin-queries.ts +0 -121
- package/src/admin/stores/auth.ts +0 -61
- package/src/admin/stores/column-visibility.ts +0 -67
- package/src/admin/stores/config.ts +0 -15
- package/src/admin/stores/media.ts +0 -95
- package/src/admin/stores/query.ts +0 -13
- package/src/admin/stores/ui.ts +0 -29
- package/src/admin/ui/admin-client.tsx +0 -283
- package/src/admin/ui/admin-layout.tsx +0 -276
- package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
- package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
- package/src/admin/ui/components/DataDetailView.tsx +0 -175
- package/src/admin/ui/components/Table.tsx +0 -67
- package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
- package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
- package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
- package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
- package/src/admin/ui/components/fields/DateField.tsx +0 -45
- package/src/admin/ui/components/fields/FileField.tsx +0 -322
- package/src/admin/ui/components/fields/GroupField.tsx +0 -50
- package/src/admin/ui/components/fields/JoinField.tsx +0 -23
- package/src/admin/ui/components/fields/NumberField.tsx +0 -46
- package/src/admin/ui/components/fields/RadioField.tsx +0 -62
- package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
- package/src/admin/ui/components/fields/RowField.tsx +0 -40
- package/src/admin/ui/components/fields/SelectField.tsx +0 -59
- package/src/admin/ui/components/fields/TabsField.tsx +0 -101
- package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
- package/src/admin/ui/components/fields/TextField.tsx +0 -49
- package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
- package/src/admin/ui/components/fields/index.tsx +0 -371
- package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
- package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
- package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
- package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
- package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
- package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
- package/src/admin/ui/components/fields/utils.ts +0 -1
- package/src/admin/ui/components/link.tsx +0 -41
- package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
- package/src/admin/ui/components/toast.tsx +0 -72
- package/src/admin/ui/components/ui/accordion.tsx +0 -51
- package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
- package/src/admin/ui/components/ui/blocks.tsx +0 -32
- package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
- package/src/admin/ui/components/ui/button.tsx +0 -26
- package/src/admin/ui/components/ui/collapsible.tsx +0 -124
- package/src/admin/ui/components/ui/dialog.tsx +0 -79
- package/src/admin/ui/components/ui/group.tsx +0 -20
- package/src/admin/ui/components/ui/index.ts +0 -17
- package/src/admin/ui/components/ui/input.tsx +0 -12
- package/src/admin/ui/components/ui/join.tsx +0 -53
- package/src/admin/ui/components/ui/label.tsx +0 -11
- package/src/admin/ui/components/ui/radio-group.tsx +0 -75
- package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
- package/src/admin/ui/components/ui/relationship.tsx +0 -58
- package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
- package/src/admin/ui/components/ui/select.tsx +0 -187
- package/src/admin/ui/components/ui/separator.tsx +0 -21
- package/src/admin/ui/components/ui/sheet.tsx +0 -106
- package/src/admin/ui/components/ui/tabs.tsx +0 -116
- package/src/admin/ui/components/ui/utils.ts +0 -3
- package/src/admin/ui/hooks/use-debounce.ts +0 -15
- package/src/admin/ui/styles/_locale-switcher.scss +0 -33
- package/src/admin/ui/styles/accordion.scss +0 -60
- package/src/admin/ui/styles/animations.scss +0 -41
- package/src/admin/ui/styles/asset-manager.scss +0 -547
- package/src/admin/ui/styles/badge.scss +0 -13
- package/src/admin/ui/styles/base.scss +0 -22
- package/src/admin/ui/styles/button.scss +0 -161
- package/src/admin/ui/styles/card.scss +0 -13
- package/src/admin/ui/styles/collapsible.scss +0 -75
- package/src/admin/ui/styles/data-detail.scss +0 -92
- package/src/admin/ui/styles/dialog.scss +0 -102
- package/src/admin/ui/styles/empty-state.scss +0 -22
- package/src/admin/ui/styles/group.scss +0 -19
- package/src/admin/ui/styles/index.scss +0 -33
- package/src/admin/ui/styles/input.scss +0 -80
- package/src/admin/ui/styles/label.scss +0 -12
- package/src/admin/ui/styles/layout.scss +0 -56
- package/src/admin/ui/styles/lexical.scss +0 -469
- package/src/admin/ui/styles/loading.scss +0 -102
- package/src/admin/ui/styles/media-registry.scss +0 -597
- package/src/admin/ui/styles/pagination.scss +0 -20
- package/src/admin/ui/styles/radio-group.scss +0 -66
- package/src/admin/ui/styles/row.scss +0 -17
- package/src/admin/ui/styles/scrollbar.scss +0 -36
- package/src/admin/ui/styles/select.scss +0 -121
- package/src/admin/ui/styles/separator.scss +0 -14
- package/src/admin/ui/styles/sheet.scss +0 -152
- package/src/admin/ui/styles/sidebar.scss +0 -148
- package/src/admin/ui/styles/switch.scss +0 -59
- package/src/admin/ui/styles/table.scss +0 -207
- package/src/admin/ui/styles/tabs.scss +0 -62
- package/src/admin/ui/styles/toast.scss +0 -45
- package/src/admin/ui/styles/variables.scss +0 -24
- package/src/admin/ui/views/collection-list-view.tsx +0 -720
- package/src/admin/ui/views/dashboard-view.tsx +0 -263
- package/src/admin/ui/views/document-edit-view.tsx +0 -384
- package/src/admin/ui/views/global-edit-view.tsx +0 -226
- package/src/admin/ui/views/init-view.tsx +0 -182
- package/src/admin/ui/views/login-view.tsx +0 -123
- package/src/admin/ui/views/media-registry-view.tsx +0 -1104
- package/src/admin/ui/views/settings-view.tsx +0 -729
- package/src/admin/webcomponent.tsx +0 -15
- package/src/api.ts +0 -9
- package/src/auth/index.ts +0 -194
- package/src/auth/migrations.ts +0 -87
- package/src/auth/premissions.ts +0 -46
- package/src/cli/commands/generate-types.ts +0 -116
- package/src/cli/commands/init.ts +0 -95
- package/src/cli/commands/migrate-commands.ts +0 -160
- package/src/cli/commands/seed-command.ts +0 -11
- package/src/cli/d1-mock.ts +0 -101
- package/src/cli/index.test.ts +0 -84
- package/src/cli/index.ts +0 -183
- package/src/cli/r2-mock.ts +0 -217
- package/src/cli/seeding.ts +0 -409
- package/src/client.ts +0 -181
- package/src/config-utils.ts +0 -102
- package/src/config.ts +0 -49
- package/src/db/adapter.ts +0 -53
- package/src/db/better-sqlite.ts +0 -632
- package/src/db/bun-sqlite.ts +0 -646
- package/src/db/d1.ts +0 -711
- package/src/db/index.ts +0 -6
- package/src/db/kysely/data-mapper.ts +0 -142
- package/src/db/kysely/field-mapper.ts +0 -148
- package/src/db/kysely/migration-generator.ts +0 -223
- package/src/db/kysely/query-builder.ts +0 -92
- package/src/db/kysely/schema-builder.ts +0 -439
- package/src/db/kysely/sql-utils.ts +0 -13
- package/src/db/postgres.ts +0 -621
- package/src/db/sqlite.ts +0 -660
- package/src/db/system-schema.ts +0 -121
- package/src/index.ts +0 -13
- package/src/runtimes/README.md +0 -59
- package/src/runtimes/bun.ts +0 -49
- package/src/runtimes/cloudflare-workers.ts +0 -38
- package/src/runtimes/next.ts +0 -26
- package/src/runtimes/node.ts +0 -52
- package/src/schema/collection.ts +0 -184
- package/src/schema/fields/base.ts +0 -164
- package/src/schema/fields/index.ts +0 -427
- package/src/schema/global.ts +0 -145
- package/src/schema/index.ts +0 -4
- package/src/schema/infer.ts +0 -72
- package/src/server/admin-router.ts +0 -20
- package/src/server/admin.ts +0 -142
- package/src/server/assets.ts +0 -306
- package/src/server/collection-router.ts +0 -55
- package/src/server/handlers.ts +0 -722
- package/src/server/middlewares/admin.ts +0 -27
- package/src/server/middlewares/auth.ts +0 -89
- package/src/server/middlewares/context.ts +0 -17
- package/src/server/middlewares/cors.ts +0 -24
- package/src/server/middlewares/database-init.ts +0 -74
- package/src/server/middlewares/rate-limit.ts +0 -77
- package/src/server/router.ts +0 -47
- package/src/server/setup-middlewares.ts +0 -58
- package/src/server/system-router.ts +0 -35
- package/src/server.ts +0 -9
- package/src/storage/adapters/cloudflare-r2.ts +0 -136
- package/src/storage/adapters/local.ts +0 -146
- package/src/storage/adapters/s3.ts +0 -186
- package/src/storage/errors.ts +0 -46
- package/src/storage/index.ts +0 -5
- package/src/storage/types.ts +0 -39
- package/src/types.ts +0 -577
- package/src/utils/lexical.ts +0 -37
- package/src/utils/logger.ts +0 -73
- package/src/validation.ts +0 -429
- package/src/validator.ts +0 -179
- package/test/admin-custom-field.test.ts +0 -162
- package/test/admin-react-field.test.tsx +0 -134
- package/test/api-features.test.ts +0 -78
- package/test/api.test.ts +0 -178
- package/test/auth.test.ts +0 -62
- package/test/cli-integration.test.ts +0 -148
- package/test/cli.test.ts +0 -25
- package/test/db/postgres.test.ts +0 -95
- package/test/db/sqlite-filter.test.ts +0 -53
- package/test/db/sqlite.test.ts +0 -82
- package/test/engine-features.test.ts +0 -79
- package/test/globals.test.ts +0 -74
- package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
- package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
- package/test/integration-tmp/my-test-app/index.ts +0 -8
- package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
- package/test/integration-tmp/my-test-app/package.json +0 -12
- package/test/populate.test.ts +0 -79
- package/test/runtimes.test.ts +0 -43
- package/test/schema-builder.test.ts +0 -107
- package/test/schema-features.test.ts +0 -63
- package/test/seeding.test.ts +0 -68
- package/test/storage/local.test.ts +0 -72
- package/test/storage/s3.test.ts +0 -60
- package/test/structural-data.test.ts +0 -100
- package/test/test-setup.ts +0 -11
- package/test/validation.test.ts +0 -162
- package/tsconfig.json +0 -42
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { TOGGLE_LINK_COMMAND } from "@lexical/link";
|
|
2
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
-
import type { RangeSelection } from "lexical";
|
|
4
|
-
import {
|
|
5
|
-
$getSelection,
|
|
6
|
-
$insertNodes,
|
|
7
|
-
$isRangeSelection,
|
|
8
|
-
COMMAND_PRIORITY_CRITICAL,
|
|
9
|
-
FORMAT_TEXT_COMMAND,
|
|
10
|
-
SELECTION_CHANGE_COMMAND,
|
|
11
|
-
} from "lexical";
|
|
12
|
-
import { Bold, Image as ImageIcon, Italic, LinkIcon, Strikethrough } from "lucide-react";
|
|
13
|
-
import * as React from "react";
|
|
14
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
15
|
-
import * as ReactDOM from "react-dom";
|
|
16
|
-
import { getCurrentBaseURL } from "../../../../../api-client";
|
|
17
|
-
import { AssetManagerModal } from "../../../media/AssetManagerModal";
|
|
18
|
-
import { $createImageNode } from "../nodes/ImageNode";
|
|
19
|
-
|
|
20
|
-
export function NotionToolbarPlugin() {
|
|
21
|
-
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
22
|
-
const [editor] = useLexicalComposerContext();
|
|
23
|
-
const [isBold, setIsBold] = useState(false);
|
|
24
|
-
const [isItalic, setIsItalic] = useState(false);
|
|
25
|
-
const [isStrikethrough, setIsStrikethrough] = useState(false);
|
|
26
|
-
const [showToolbar, setShowToolbar] = useState(false);
|
|
27
|
-
const toolbarRef = useRef<HTMLDivElement>(null);
|
|
28
|
-
|
|
29
|
-
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
30
|
-
|
|
31
|
-
const updateToolbar = useCallback(() => {
|
|
32
|
-
const selection = $getSelection();
|
|
33
|
-
if ($isRangeSelection(selection)) {
|
|
34
|
-
setIsBold(selection.hasFormat("bold"));
|
|
35
|
-
setIsItalic(selection.hasFormat("italic"));
|
|
36
|
-
setIsStrikethrough(selection.hasFormat("strikethrough"));
|
|
37
|
-
|
|
38
|
-
const nativeSelection = window.getSelection();
|
|
39
|
-
const rootElement = editor.getRootElement();
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
nativeSelection !== null &&
|
|
43
|
-
!nativeSelection.isCollapsed &&
|
|
44
|
-
rootElement !== null &&
|
|
45
|
-
rootElement.contains(nativeSelection.anchorNode)
|
|
46
|
-
) {
|
|
47
|
-
const range = nativeSelection.getRangeAt(0);
|
|
48
|
-
const rect = range.getBoundingClientRect();
|
|
49
|
-
|
|
50
|
-
// Calculate position relative to the document or a parent container
|
|
51
|
-
// To keep it simple, we use fixed positioning for the portal if needed,
|
|
52
|
-
// but here we'll try to position it above the selection.
|
|
53
|
-
setPosition({
|
|
54
|
-
top: rect.top - 45, // 45px above the selection
|
|
55
|
-
left: rect.left + rect.width / 2,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
setShowToolbar(true);
|
|
59
|
-
} else {
|
|
60
|
-
setShowToolbar(false);
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
setShowToolbar(false);
|
|
64
|
-
}
|
|
65
|
-
}, [editor]);
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
return editor.registerUpdateListener(({ editorState }) => {
|
|
69
|
-
editorState.read(() => {
|
|
70
|
-
updateToolbar();
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}, [editor, updateToolbar]);
|
|
74
|
-
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
return editor.registerCommand(
|
|
77
|
-
SELECTION_CHANGE_COMMAND,
|
|
78
|
-
(_payload) => {
|
|
79
|
-
updateToolbar();
|
|
80
|
-
return false;
|
|
81
|
-
},
|
|
82
|
-
COMMAND_PRIORITY_CRITICAL,
|
|
83
|
-
);
|
|
84
|
-
}, [editor, updateToolbar]);
|
|
85
|
-
|
|
86
|
-
// Also update on scroll/resize to keep it attached (optional but good)
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
const handleUpdate = () => {
|
|
89
|
-
if (showToolbar) {
|
|
90
|
-
updateToolbar();
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
window.addEventListener("resize", handleUpdate);
|
|
94
|
-
window.addEventListener("scroll", handleUpdate);
|
|
95
|
-
return () => {
|
|
96
|
-
window.removeEventListener("resize", handleUpdate);
|
|
97
|
-
window.removeEventListener("scroll", handleUpdate);
|
|
98
|
-
};
|
|
99
|
-
}, [showToolbar, updateToolbar]);
|
|
100
|
-
|
|
101
|
-
const handleInsertImage = (asset: any) => {
|
|
102
|
-
const url = asset.url || `${getCurrentBaseURL()}/api/assets/${asset.id || asset.assetId}/view`;
|
|
103
|
-
editor.update(() => {
|
|
104
|
-
const imageNode = $createImageNode(url, asset.filename || "Image");
|
|
105
|
-
$insertNodes([imageNode]);
|
|
106
|
-
});
|
|
107
|
-
setIsModalOpen(false);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
if (!showToolbar && !isModalOpen) return null;
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<>
|
|
114
|
-
{showToolbar &&
|
|
115
|
-
ReactDOM.createPortal(
|
|
116
|
-
<div
|
|
117
|
-
ref={toolbarRef}
|
|
118
|
-
className="opaca-lexical-bubble-menu"
|
|
119
|
-
style={{
|
|
120
|
-
position: "fixed",
|
|
121
|
-
top: position.top - (typeof window !== "undefined" ? window.scrollY : 0),
|
|
122
|
-
left: position.left,
|
|
123
|
-
transform: "translateX(-50%)",
|
|
124
|
-
zIndex: 1000,
|
|
125
|
-
pointerEvents: "auto",
|
|
126
|
-
}}
|
|
127
|
-
>
|
|
128
|
-
<button
|
|
129
|
-
type="button"
|
|
130
|
-
onClick={() => {
|
|
131
|
-
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
|
|
132
|
-
}}
|
|
133
|
-
className={`opaca-lexical-btn ${isBold ? "is-active" : ""}`}
|
|
134
|
-
>
|
|
135
|
-
<Bold size={16} />
|
|
136
|
-
</button>
|
|
137
|
-
<button
|
|
138
|
-
type="button"
|
|
139
|
-
onClick={() => {
|
|
140
|
-
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
|
|
141
|
-
}}
|
|
142
|
-
className={`opaca-lexical-btn ${isItalic ? "is-active" : ""}`}
|
|
143
|
-
>
|
|
144
|
-
<Italic size={16} />
|
|
145
|
-
</button>
|
|
146
|
-
<button
|
|
147
|
-
type="button"
|
|
148
|
-
onClick={() => {
|
|
149
|
-
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "strikethrough");
|
|
150
|
-
}}
|
|
151
|
-
className={`opaca-lexical-btn ${isStrikethrough ? "is-active" : ""}`}
|
|
152
|
-
>
|
|
153
|
-
<Strikethrough size={16} />
|
|
154
|
-
</button>
|
|
155
|
-
<button
|
|
156
|
-
type="button"
|
|
157
|
-
onClick={() => {
|
|
158
|
-
editor.dispatchCommand(TOGGLE_LINK_COMMAND, "https://");
|
|
159
|
-
}}
|
|
160
|
-
className={`opaca-lexical-btn`}
|
|
161
|
-
>
|
|
162
|
-
<LinkIcon size={16} />
|
|
163
|
-
</button>
|
|
164
|
-
<button
|
|
165
|
-
type="button"
|
|
166
|
-
onClick={() => setIsModalOpen(true)}
|
|
167
|
-
className={`opaca-lexical-btn`}
|
|
168
|
-
>
|
|
169
|
-
<ImageIcon size={16} />
|
|
170
|
-
</button>
|
|
171
|
-
</div>,
|
|
172
|
-
document.body,
|
|
173
|
-
)}
|
|
174
|
-
|
|
175
|
-
{isModalOpen && (
|
|
176
|
-
<AssetManagerModal
|
|
177
|
-
bucket={"default"}
|
|
178
|
-
onClose={() => setIsModalOpen(false)}
|
|
179
|
-
onSelect={handleInsertImage}
|
|
180
|
-
/>
|
|
181
|
-
)}
|
|
182
|
-
</>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { $createCodeNode } from "@lexical/code";
|
|
2
|
-
import { TOGGLE_LINK_COMMAND } from "@lexical/link";
|
|
3
|
-
import {
|
|
4
|
-
INSERT_ORDERED_LIST_COMMAND,
|
|
5
|
-
INSERT_UNORDERED_LIST_COMMAND,
|
|
6
|
-
REMOVE_LIST_COMMAND,
|
|
7
|
-
} from "@lexical/list";
|
|
8
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
9
|
-
import { $createHeadingNode, $createQuoteNode, $isHeadingNode } from "@lexical/rich-text";
|
|
10
|
-
import { $setBlocksType } from "@lexical/selection";
|
|
11
|
-
import {
|
|
12
|
-
$getSelection,
|
|
13
|
-
$insertNodes,
|
|
14
|
-
$isRangeSelection,
|
|
15
|
-
COMMAND_PRIORITY_CRITICAL,
|
|
16
|
-
FORMAT_ELEMENT_COMMAND,
|
|
17
|
-
FORMAT_TEXT_COMMAND,
|
|
18
|
-
SELECTION_CHANGE_COMMAND,
|
|
19
|
-
} from "lexical";
|
|
20
|
-
import {
|
|
21
|
-
Bold,
|
|
22
|
-
Code,
|
|
23
|
-
Heading1,
|
|
24
|
-
Heading2,
|
|
25
|
-
Image as ImageIcon,
|
|
26
|
-
Italic,
|
|
27
|
-
Link as LinkIcon,
|
|
28
|
-
List,
|
|
29
|
-
ListOrdered,
|
|
30
|
-
Quote,
|
|
31
|
-
Strikethrough,
|
|
32
|
-
} from "lucide-react";
|
|
33
|
-
import { useCallback, useEffect, useState } from "react";
|
|
34
|
-
import { getCurrentBaseURL } from "../../../../../api-client";
|
|
35
|
-
import { AssetManagerModal } from "../../../media/AssetManagerModal";
|
|
36
|
-
import { $createImageNode } from "../nodes/ImageNode";
|
|
37
|
-
|
|
38
|
-
export function SimpleToolbarPlugin() {
|
|
39
|
-
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
40
|
-
const [editor] = useLexicalComposerContext();
|
|
41
|
-
const [isBold, setIsBold] = useState(false);
|
|
42
|
-
const [isItalic, setIsItalic] = useState(false);
|
|
43
|
-
const [isStrikethrough, setIsStrikethrough] = useState(false);
|
|
44
|
-
const [blockType, setBlockType] = useState("paragraph");
|
|
45
|
-
|
|
46
|
-
const updateToolbar = useCallback(() => {
|
|
47
|
-
const selection = $getSelection();
|
|
48
|
-
if ($isRangeSelection(selection)) {
|
|
49
|
-
setIsBold(selection.hasFormat("bold"));
|
|
50
|
-
setIsItalic(selection.hasFormat("italic"));
|
|
51
|
-
setIsStrikethrough(selection.hasFormat("strikethrough"));
|
|
52
|
-
|
|
53
|
-
const anchorNode = selection.anchor.getNode();
|
|
54
|
-
const element =
|
|
55
|
-
anchorNode.getKey() === "root" ? anchorNode : anchorNode.getTopLevelElementOrThrow();
|
|
56
|
-
const elementKey = element.getKey();
|
|
57
|
-
const elementDOM = editor.getElementByKey(elementKey);
|
|
58
|
-
|
|
59
|
-
if (elementDOM !== null) {
|
|
60
|
-
if ($isHeadingNode(element)) {
|
|
61
|
-
const tag = element.getTag();
|
|
62
|
-
setBlockType(tag);
|
|
63
|
-
} else {
|
|
64
|
-
const type = element.getType();
|
|
65
|
-
setBlockType(type);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}, [editor]);
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
return editor.registerCommand(
|
|
73
|
-
SELECTION_CHANGE_COMMAND,
|
|
74
|
-
(_payload) => {
|
|
75
|
-
updateToolbar();
|
|
76
|
-
return false;
|
|
77
|
-
},
|
|
78
|
-
COMMAND_PRIORITY_CRITICAL,
|
|
79
|
-
);
|
|
80
|
-
}, [editor, updateToolbar]);
|
|
81
|
-
|
|
82
|
-
const formatHeading = (level: "h1" | "h2") => {
|
|
83
|
-
if (blockType !== level) {
|
|
84
|
-
editor.update(() => {
|
|
85
|
-
const selection = $getSelection();
|
|
86
|
-
if ($isRangeSelection(selection)) {
|
|
87
|
-
$setBlocksType(selection, () => $createHeadingNode(level));
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
} else {
|
|
91
|
-
editor.update(() => {
|
|
92
|
-
const selection = $getSelection();
|
|
93
|
-
if ($isRangeSelection(selection)) {
|
|
94
|
-
$setBlocksType(selection, () => $createHeadingNode("h1")); // Default to paragraph logic generally, simplify for now
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const formatQuote = () => {
|
|
101
|
-
if (blockType !== "quote") {
|
|
102
|
-
editor.update(() => {
|
|
103
|
-
const selection = $getSelection();
|
|
104
|
-
if ($isRangeSelection(selection)) {
|
|
105
|
-
$setBlocksType(selection, () => $createQuoteNode());
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const formatCode = () => {
|
|
112
|
-
if (blockType !== "code") {
|
|
113
|
-
editor.update(() => {
|
|
114
|
-
const selection = $getSelection();
|
|
115
|
-
if ($isRangeSelection(selection)) {
|
|
116
|
-
$setBlocksType(selection, () => $createCodeNode());
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const formatList = (type: "bullet" | "number") => {
|
|
123
|
-
if (type === "bullet") {
|
|
124
|
-
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
|
|
125
|
-
} else {
|
|
126
|
-
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const insertLink = useCallback(() => {
|
|
131
|
-
editor.dispatchCommand(TOGGLE_LINK_COMMAND, "https://");
|
|
132
|
-
}, [editor]);
|
|
133
|
-
|
|
134
|
-
const handleInsertImage = (asset: any) => {
|
|
135
|
-
const url = asset.url || `${getCurrentBaseURL()}/api/assets/${asset.id || asset.assetId}/view`;
|
|
136
|
-
editor.update(() => {
|
|
137
|
-
const imageNode = $createImageNode(url, asset.filename || "Image");
|
|
138
|
-
$insertNodes([imageNode]);
|
|
139
|
-
});
|
|
140
|
-
setIsModalOpen(false);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return (
|
|
144
|
-
<>
|
|
145
|
-
<div className="opaca-lexical-toolbar">
|
|
146
|
-
<button
|
|
147
|
-
type="button"
|
|
148
|
-
onClick={() => {
|
|
149
|
-
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
|
|
150
|
-
}}
|
|
151
|
-
className={`opaca-lexical-btn ${isBold ? "is-active" : ""}`}
|
|
152
|
-
>
|
|
153
|
-
<Bold size={16} />
|
|
154
|
-
</button>
|
|
155
|
-
<button
|
|
156
|
-
type="button"
|
|
157
|
-
onClick={() => {
|
|
158
|
-
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
|
|
159
|
-
}}
|
|
160
|
-
className={`opaca-lexical-btn ${isItalic ? "is-active" : ""}`}
|
|
161
|
-
>
|
|
162
|
-
<Italic size={16} />
|
|
163
|
-
</button>
|
|
164
|
-
<button
|
|
165
|
-
type="button"
|
|
166
|
-
onClick={() => {
|
|
167
|
-
editor.dispatchCommand(FORMAT_TEXT_COMMAND, "strikethrough");
|
|
168
|
-
}}
|
|
169
|
-
className={`opaca-lexical-btn ${isStrikethrough ? "is-active" : ""}`}
|
|
170
|
-
>
|
|
171
|
-
<Strikethrough size={16} />
|
|
172
|
-
</button>
|
|
173
|
-
|
|
174
|
-
<div className="opaca-lexical-divider" />
|
|
175
|
-
|
|
176
|
-
<button
|
|
177
|
-
type="button"
|
|
178
|
-
onClick={() => formatHeading("h1")}
|
|
179
|
-
className={`opaca-lexical-btn ${blockType === "h1" ? "is-active" : ""}`}
|
|
180
|
-
>
|
|
181
|
-
<Heading1 size={16} />
|
|
182
|
-
</button>
|
|
183
|
-
<button
|
|
184
|
-
type="button"
|
|
185
|
-
onClick={() => formatHeading("h2")}
|
|
186
|
-
className={`opaca-lexical-btn ${blockType === "h2" ? "is-active" : ""}`}
|
|
187
|
-
>
|
|
188
|
-
<Heading2 size={16} />
|
|
189
|
-
</button>
|
|
190
|
-
|
|
191
|
-
<button
|
|
192
|
-
type="button"
|
|
193
|
-
onClick={() => formatList("bullet")}
|
|
194
|
-
className={`opaca-lexical-btn ${blockType === "ul" ? "is-active" : ""}`}
|
|
195
|
-
>
|
|
196
|
-
<List size={16} />
|
|
197
|
-
</button>
|
|
198
|
-
<button
|
|
199
|
-
type="button"
|
|
200
|
-
onClick={() => formatList("number")}
|
|
201
|
-
className={`opaca-lexical-btn ${blockType === "ol" ? "is-active" : ""}`}
|
|
202
|
-
>
|
|
203
|
-
<ListOrdered size={16} />
|
|
204
|
-
</button>
|
|
205
|
-
|
|
206
|
-
<button
|
|
207
|
-
type="button"
|
|
208
|
-
onClick={formatQuote}
|
|
209
|
-
className={`opaca-lexical-btn ${blockType === "quote" ? "is-active" : ""}`}
|
|
210
|
-
>
|
|
211
|
-
<Quote size={16} />
|
|
212
|
-
</button>
|
|
213
|
-
<button
|
|
214
|
-
type="button"
|
|
215
|
-
onClick={formatCode}
|
|
216
|
-
className={`opaca-lexical-btn ${blockType === "code" ? "is-active" : ""}`}
|
|
217
|
-
>
|
|
218
|
-
<Code size={16} />
|
|
219
|
-
</button>
|
|
220
|
-
|
|
221
|
-
<div className="opaca-lexical-divider" />
|
|
222
|
-
|
|
223
|
-
<button type="button" onClick={insertLink} className={`opaca-lexical-btn`}>
|
|
224
|
-
<LinkIcon size={16} />
|
|
225
|
-
</button>
|
|
226
|
-
<button type="button" onClick={() => setIsModalOpen(true)} className={`opaca-lexical-btn`}>
|
|
227
|
-
<ImageIcon size={16} />
|
|
228
|
-
</button>
|
|
229
|
-
</div>
|
|
230
|
-
|
|
231
|
-
{isModalOpen && (
|
|
232
|
-
<AssetManagerModal
|
|
233
|
-
bucket={"default"}
|
|
234
|
-
onClose={() => setIsModalOpen(false)}
|
|
235
|
-
onSelect={handleInsertImage}
|
|
236
|
-
/>
|
|
237
|
-
)}
|
|
238
|
-
</>
|
|
239
|
-
);
|
|
240
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
3
|
-
import { normalizeEditorState } from "..";
|
|
4
|
-
|
|
5
|
-
interface ValueSyncPluginProps {
|
|
6
|
-
value: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function ValueSyncPlugin({ value }: ValueSyncPluginProps) {
|
|
10
|
-
const [editor] = useLexicalComposerContext();
|
|
11
|
-
const isFirstRender = useRef(true);
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
// We only want to sync if the value actually changed from the outside
|
|
15
|
-
// and specifically when we're moving from empty/initial to having real data.
|
|
16
|
-
// Lexical's initialConfig.editorState only works once.
|
|
17
|
-
if (isFirstRender.current) {
|
|
18
|
-
isFirstRender.current = false;
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (normalizeEditorState(value)) {
|
|
23
|
-
editor.update(() => {
|
|
24
|
-
const currentContent = JSON.stringify(editor.getEditorState().toJSON());
|
|
25
|
-
|
|
26
|
-
// If the external value is different from internal state, and internal is essentially empty or this is the first real load
|
|
27
|
-
if (currentContent !== value) {
|
|
28
|
-
try {
|
|
29
|
-
const newState = editor.parseEditorState(value);
|
|
30
|
-
editor.setEditorState(newState);
|
|
31
|
-
} catch (e) {
|
|
32
|
-
console.error("Failed to parse editor state in ValueSyncPlugin:", e);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}, [editor, value]);
|
|
38
|
-
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getPagePath, openPage } from "@nanostores/router";
|
|
2
|
-
import type React from "react";
|
|
3
|
-
import { $router } from "../../router";
|
|
4
|
-
|
|
5
|
-
interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
6
|
-
href: string;
|
|
7
|
-
params?: any;
|
|
8
|
-
search?: any;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function Link({ href, params, search, children, onClick, ...props }: LinkProps) {
|
|
12
|
-
const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
13
|
-
if (onClick) onClick(e);
|
|
14
|
-
|
|
15
|
-
// Check if it's a normal click (no meta keys, left button)
|
|
16
|
-
if (
|
|
17
|
-
!e.defaultPrevented &&
|
|
18
|
-
e.button === 0 &&
|
|
19
|
-
!e.metaKey &&
|
|
20
|
-
!e.ctrlKey &&
|
|
21
|
-
!e.shiftKey &&
|
|
22
|
-
!e.altKey &&
|
|
23
|
-
!props.target
|
|
24
|
-
) {
|
|
25
|
-
e.preventDefault();
|
|
26
|
-
// If href starts with /admin, we use the router
|
|
27
|
-
if (href.startsWith("/admin")) {
|
|
28
|
-
// We can either pass the path directly or try to find a route
|
|
29
|
-
$router.open(href);
|
|
30
|
-
} else {
|
|
31
|
-
window.location.href = href;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<a href={href} onClick={handleClick} {...props}>
|
|
38
|
-
{children}
|
|
39
|
-
</a>
|
|
40
|
-
);
|
|
41
|
-
}
|