@namroodinc/liquid-editorial 0.1.0 → 0.1.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/README.md +62 -1
- package/dist/chunks/EntryEditor-BF808OZR.js +181 -0
- package/dist/chunks/EntryEditor-BF808OZR.js.map +1 -0
- package/dist/chunks/EntryEditor-cjDk4vdH.cjs +2 -0
- package/dist/chunks/EntryEditor-cjDk4vdH.cjs.map +1 -0
- package/dist/chunks/RichTextEditor-DRt-kibg.js +248 -0
- package/dist/chunks/RichTextEditor-DRt-kibg.js.map +1 -0
- package/dist/chunks/RichTextEditor-tFkISOvq.cjs +2 -0
- package/dist/chunks/RichTextEditor-tFkISOvq.cjs.map +1 -0
- package/dist/components/EntryEditor/index.cjs +1 -0
- package/dist/components/EntryEditor/index.d.cts +21 -0
- package/dist/components/EntryEditor/index.d.cts.map +1 -0
- package/dist/components/EntryEditor/index.d.ts +21 -0
- package/dist/components/EntryEditor/index.d.ts.map +1 -0
- package/dist/components/EntryEditor/index.js +6 -0
- package/dist/components/EntryEditor/model.d.cts +33 -0
- package/dist/components/EntryEditor/model.d.cts.map +1 -0
- package/dist/components/EntryEditor/model.d.ts +33 -0
- package/dist/components/EntryEditor/model.d.ts.map +1 -0
- package/dist/components/EntryEditor/style.css +8 -0
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.cjs.map +1 -1
- package/dist/components/EntryPicker/index.d.cts.map +1 -1
- package/dist/components/EntryPicker/index.d.ts.map +1 -1
- package/dist/components/EntryPicker/index.js +15 -12
- package/dist/components/EntryPicker/index.js.map +1 -1
- package/dist/components/Field/index.cjs +1 -1
- package/dist/components/Field/index.cjs.map +1 -1
- package/dist/components/Field/index.d.cts +4 -1
- package/dist/components/Field/index.d.cts.map +1 -1
- package/dist/components/Field/index.d.ts +4 -1
- package/dist/components/Field/index.d.ts.map +1 -1
- package/dist/components/Field/index.js +29 -23
- package/dist/components/Field/index.js.map +1 -1
- package/dist/components/Field/style.css +12 -0
- package/dist/components/Modal/style.css +1 -0
- package/dist/components/NumberField/index.cjs +1 -1
- package/dist/components/NumberField/index.cjs.map +1 -1
- package/dist/components/NumberField/index.d.cts +1 -1
- package/dist/components/NumberField/index.d.cts.map +1 -1
- package/dist/components/NumberField/index.d.ts +1 -1
- package/dist/components/NumberField/index.d.ts.map +1 -1
- package/dist/components/NumberField/index.js +1 -1
- package/dist/components/NumberField/index.js.map +1 -1
- package/dist/components/RichTextEditor/document.d.cts +10 -0
- package/dist/components/RichTextEditor/document.d.cts.map +1 -0
- package/dist/components/RichTextEditor/document.d.ts +10 -0
- package/dist/components/RichTextEditor/document.d.ts.map +1 -0
- package/dist/components/RichTextEditor/index.cjs +1 -2
- package/dist/components/RichTextEditor/index.d.cts +21 -6
- package/dist/components/RichTextEditor/index.d.cts.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts +21 -6
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +1 -175
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.cjs.map +1 -1
- package/dist/components/SortableList/index.d.cts +4 -3
- package/dist/components/SortableList/index.d.cts.map +1 -1
- package/dist/components/SortableList/index.d.ts +4 -3
- package/dist/components/SortableList/index.d.ts.map +1 -1
- package/dist/components/SortableList/index.js +55 -48
- package/dist/components/SortableList/index.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -35
- package/dist/styles.css +1 -0
- package/package.json +37 -11
- package/dist/components/RichTextEditor/index.cjs.map +0 -1
- package/dist/components/RichTextEditor/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
import { n as e, r as t, t as n } from "./chunks/Icon-CGY1FNXT.js";
|
|
2
2
|
import { Button as r } from "./components/Button/index.js";
|
|
3
3
|
import { ButtonGroup as i } from "./components/ButtonGroup/index.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
|
|
4
|
+
import { t as a } from "./chunks/RichTextEditor-DRt-kibg.js";
|
|
5
|
+
import { Badge as o } from "./components/Badge/index.js";
|
|
6
|
+
import { Modal as s } from "./components/Modal/index.js";
|
|
7
|
+
import { FieldAffix as c } from "./components/FieldAffix/index.js";
|
|
8
|
+
import { SearchField as l } from "./components/SearchField/index.js";
|
|
9
|
+
import { SortableList as u, SortableListItem as d } from "./components/SortableList/index.js";
|
|
10
|
+
import { EntryPicker as f } from "./components/EntryPicker/index.js";
|
|
11
|
+
import { Field as p } from "./components/Field/index.js";
|
|
12
|
+
import { NumberField as m, NumberRangeField as h } from "./components/NumberField/index.js";
|
|
13
|
+
import { Switch as g } from "./components/Switch/index.js";
|
|
14
|
+
import { TextArea as _, TextField as v } from "./components/TextField/index.js";
|
|
15
|
+
import { n as y, t as b } from "./chunks/EntryEditor-BF808OZR.js";
|
|
16
|
+
import { Board as x, BoardCard as S, BoardColumn as C } from "./components/Board/index.js";
|
|
17
|
+
import { Drawer as w } from "./components/Drawer/index.js";
|
|
18
|
+
import { Avatar as T, AvatarGroup as E } from "./components/Avatar/index.js";
|
|
19
|
+
import { Grid as D, GridItem as O, Stack as k } from "./components/Grid/index.js";
|
|
20
|
+
import { Checkbox as A, ChoiceGroup as j, Radio as M } from "./components/Choice/index.js";
|
|
21
|
+
import { Table as N, TableBody as P, TableCell as F, TableEmpty as I, TableFrame as L, TableHead as R, TableHeaderCell as z, TableRow as B, TableToolbar as V } from "./components/Table/index.js";
|
|
22
|
+
import { Popover as H } from "./components/Popover/index.js";
|
|
23
|
+
import { Menu as U, MenuItem as W, MenuLabel as G, MenuSeparator as K } from "./components/Menu/index.js";
|
|
24
|
+
import { Toast as q, ToastProvider as J, useToast as Y } from "./components/Toast/index.js";
|
|
25
|
+
import { Skeleton as X, SkeletonText as Z } from "./components/Skeleton/index.js";
|
|
26
|
+
import { SideNav as Q, SideNavFooter as $, SideNavHeader as ee, SideNavItem as te, SideNavSection as ne, useSideNavCollapsed as re } from "./components/SideNav/index.js";
|
|
27
|
+
import { TopNav as ie, TopNavItem as ae } from "./components/TopNav/index.js";
|
|
28
|
+
import { SubNav as oe, SubNavButton as se, SubNavItem as ce } from "./components/SubNav/index.js";
|
|
29
|
+
import { CheckboxCard as le, RadioCard as ue, SelectionCardGroup as de } from "./components/SelectionCard/index.js";
|
|
30
|
+
import { Stepper as fe } from "./components/Stepper/index.js";
|
|
31
|
+
import { AssetGrid as pe, AssetGridEmpty as me, AssetTile as he, AssetTileSkeleton as ge } from "./components/AssetGrid/index.js";
|
|
32
|
+
import { ImageCropper as _e, cropRatios as ve, cropToBlob as ye } from "./components/ImageCropper/index.js";
|
|
33
|
+
import { Container as be } from "./components/Container/index.js";
|
|
34
|
+
import { Select as xe } from "./components/Select/index.js";
|
|
35
|
+
import { RangeSlider as Se, Slider as Ce } from "./components/Slider/index.js";
|
|
36
|
+
import { Calendar as we, DateField as Te, DateRangeField as Ee, formatIsoDate as De } from "./components/DatePicker/index.js";
|
|
37
|
+
import { TagsInput as Oe } from "./components/TagsInput/index.js";
|
|
38
|
+
import { Time as ke, formatAbsoluteDate as Ae, formatAbsoluteTime as je, formatRelativeTime as Me } from "./components/Time/index.js";
|
|
39
|
+
export { pe as AssetGrid, me as AssetGridEmpty, he as AssetTile, ge as AssetTileSkeleton, T as Avatar, E as AvatarGroup, o as Badge, x as Board, S as BoardCard, C as BoardColumn, r as Button, i as ButtonGroup, we as Calendar, A as Checkbox, le as CheckboxCard, j as ChoiceGroup, be as Container, Te as DateField, Ee as DateRangeField, w as Drawer, b as EntryEditor, f as EntryPicker, p as Field, c as FieldAffix, D as Grid, O as GridItem, n as Icon, _e as ImageCropper, U as Menu, W as MenuItem, G as MenuLabel, K as MenuSeparator, s as Modal, m as NumberField, h as NumberRangeField, H as Popover, M as Radio, ue as RadioCard, Se as RangeSlider, a as RichTextEditor, l as SearchField, xe as Select, de as SelectionCardGroup, Q as SideNav, $ as SideNavFooter, ee as SideNavHeader, te as SideNavItem, ne as SideNavSection, X as Skeleton, Z as SkeletonText, Ce as Slider, u as SortableList, d as SortableListItem, k as Stack, fe as Stepper, oe as SubNav, se as SubNavButton, ce as SubNavItem, g as Switch, N as Table, P as TableBody, F as TableCell, I as TableEmpty, L as TableFrame, R as TableHead, z as TableHeaderCell, B as TableRow, V as TableToolbar, Oe as TagsInput, _ as TextArea, v as TextField, ke as Time, q as Toast, J as ToastProvider, ie as TopNav, ae as TopNavItem, ve as cropRatios, ye as cropToBlob, Ae as formatAbsoluteDate, je as formatAbsoluteTime, De as formatIsoDate, Me as formatRelativeTime, e as iconNames, t as icons, re as useSideNavCollapsed, Y as useToast, y as validateEntryValues };
|
package/dist/styles.css
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
@import "./components/DatePicker/style.css";
|
|
12
12
|
@import "./components/Drawer/style.css";
|
|
13
13
|
@import "./components/EntryPicker/style.css";
|
|
14
|
+
@import "./components/EntryEditor/style.css";
|
|
14
15
|
@import "./components/Field/style.css";
|
|
15
16
|
@import "./components/FieldAffix/style.css";
|
|
16
17
|
@import "./components/Grid/style.css";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namroodinc/liquid-editorial",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A bold, accessible React component library for editorial products.",
|
|
5
5
|
"author": "Namrood Inc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,14 +10,28 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"typesVersions": {
|
|
12
12
|
"*": {
|
|
13
|
-
"components/*": [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
13
|
+
"components/*": [
|
|
14
|
+
"dist/components/*/index.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"styles.css": [
|
|
17
|
+
"dist/styles.css.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"tokens.css": [
|
|
20
|
+
"dist/tokens.css.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"reset.css": [
|
|
23
|
+
"dist/reset.css.d.ts"
|
|
24
|
+
]
|
|
17
25
|
}
|
|
18
26
|
},
|
|
19
|
-
"files": [
|
|
20
|
-
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": [
|
|
33
|
+
"**/*.css"
|
|
34
|
+
],
|
|
21
35
|
"exports": {
|
|
22
36
|
".": {
|
|
23
37
|
"import": {
|
|
@@ -57,10 +71,20 @@
|
|
|
57
71
|
"type": "git",
|
|
58
72
|
"url": "git+https://github.com/namroodinc/liquid-editorial.git"
|
|
59
73
|
},
|
|
60
|
-
"bugs": {
|
|
74
|
+
"bugs": {
|
|
75
|
+
"url": "https://github.com/namroodinc/liquid-editorial/issues"
|
|
76
|
+
},
|
|
61
77
|
"homepage": "https://github.com/namroodinc/liquid-editorial#readme",
|
|
62
|
-
"keywords": [
|
|
63
|
-
|
|
78
|
+
"keywords": [
|
|
79
|
+
"react",
|
|
80
|
+
"components",
|
|
81
|
+
"design-system",
|
|
82
|
+
"editorial",
|
|
83
|
+
"typescript"
|
|
84
|
+
],
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public"
|
|
87
|
+
},
|
|
64
88
|
"scripts": {
|
|
65
89
|
"clean": "node scripts/clean.mjs",
|
|
66
90
|
"dev": "storybook dev -p 6006",
|
|
@@ -128,5 +152,7 @@
|
|
|
128
152
|
"vite": "^8.0.16",
|
|
129
153
|
"vitest": "^4.0.0"
|
|
130
154
|
},
|
|
131
|
-
"engines": {
|
|
155
|
+
"engines": {
|
|
156
|
+
"node": ">=22"
|
|
157
|
+
}
|
|
132
158
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useEditor","StarterKit","Link","Placeholder","useEditorState","useCallback","ButtonGroup","Button","EditorContent","__create","__defProp","__getOwnPropDesc","__getOwnPropNames","__getProtoOf","__hasOwnProp","__copyProps","from","keys","i","n","key","to","except","k","desc","__toESM","mod","isNodeMode","target","require_components_Button_index","require_components_ButtonGroup_index","react","react_jsx_runtime","_tiptap_react","_tiptap_starter_kit","_tiptap_extension_link","_tiptap_extension_placeholder","GROUPS","RichTextEditor","isFocused","setIsFocused","editor","isDisabled","defaultValue","label","onChange","state","toggleLink","href","className","isInvalid","group","tool","toolbarExtra","size"],"sources":["../../../src/components/RichTextEditor/index.tsx"],"sourcesContent":["import { forwardRef, useCallback, useState, type ReactNode } from \"react\";\nimport { EditorContent, useEditor, useEditorState, type Editor } from \"@tiptap/react\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport Link from \"@tiptap/extension-link\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { Button } from \"../Button\";\nimport { ButtonGroup } from \"../ButtonGroup\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport type RichTextEditorSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface RichTextEditorProps {\n /** Initial HTML. The editor is uncontrolled: read changes from `onChange`. */\n defaultValue?: string;\n /** Fired with the document's HTML on every change. */\n onChange?: (html: string) => void;\n placeholder?: string;\n size?: RichTextEditorSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Accessible name for the editing surface. */\n label?: string;\n className?: string;\n /** Extra controls appended to the toolbar, e.g. a word count. */\n toolbarExtra?: ReactNode;\n}\n\ninterface ToolItem {\n id: string;\n icon: IconName;\n label: string;\n run: (editor: Editor) => void;\n active?: (editor: Editor) => boolean;\n}\n\nconst GROUPS: ToolItem[][] = [\n [\n {\n id: \"bold\",\n icon: \"bold\",\n label: \"Bold\",\n run: (e) => e.chain().focus().toggleBold().run(),\n active: (e) => e.isActive(\"bold\"),\n },\n {\n id: \"italic\",\n icon: \"italic\",\n label: \"Italic\",\n run: (e) => e.chain().focus().toggleItalic().run(),\n active: (e) => e.isActive(\"italic\"),\n },\n {\n id: \"strike\",\n icon: \"strikethrough\",\n label: \"Strikethrough\",\n run: (e) => e.chain().focus().toggleStrike().run(),\n active: (e) => e.isActive(\"strike\"),\n },\n {\n id: \"code\",\n icon: \"code\",\n label: \"Inline code\",\n run: (e) => e.chain().focus().toggleCode().run(),\n active: (e) => e.isActive(\"code\"),\n },\n ],\n [\n {\n id: \"h2\",\n icon: \"heading-2\",\n label: \"Heading\",\n run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run(),\n active: (e) => e.isActive(\"heading\", { level: 2 }),\n },\n {\n id: \"h3\",\n icon: \"heading-3\",\n label: \"Subheading\",\n run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run(),\n active: (e) => e.isActive(\"heading\", { level: 3 }),\n },\n {\n id: \"quote\",\n icon: \"quote\",\n label: \"Quote\",\n run: (e) => e.chain().focus().toggleBlockquote().run(),\n active: (e) => e.isActive(\"blockquote\"),\n },\n ],\n [\n {\n id: \"ul\",\n icon: \"list\",\n label: \"Bulleted list\",\n run: (e) => e.chain().focus().toggleBulletList().run(),\n active: (e) => e.isActive(\"bulletList\"),\n },\n {\n id: \"ol\",\n icon: \"list-ordered\",\n label: \"Numbered list\",\n run: (e) => e.chain().focus().toggleOrderedList().run(),\n active: (e) => e.isActive(\"orderedList\"),\n },\n ],\n [\n {\n id: \"undo\",\n icon: \"undo\",\n label: \"Undo\",\n run: (e) => e.chain().focus().undo().run(),\n },\n {\n id: \"redo\",\n icon: \"redo\",\n label: \"Redo\",\n run: (e) => e.chain().focus().redo().run(),\n },\n ],\n];\n\n/**\n * The editorial writing surface. Rich text plus links — the same field skin,\n * radius and states as `TextField`, with the toolbar inside the frame.\n */\nexport const RichTextEditor = forwardRef<HTMLDivElement, RichTextEditorProps>(\n function RichTextEditor(\n {\n defaultValue = \"\",\n onChange,\n placeholder = \"Write something…\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n label = \"Rich text editor\",\n className,\n toolbarExtra,\n },\n ref,\n ) {\n const [isFocused, setIsFocused] = useState(false);\n\n const editor = useEditor({\n immediatelyRender: false,\n editable: !isDisabled,\n content: defaultValue,\n extensions: [\n StarterKit.configure({ link: false }),\n Link.configure({ openOnClick: false, autolink: true }),\n Placeholder.configure({ placeholder }),\n ],\n editorProps: {\n attributes: { role: \"textbox\", \"aria-label\": label, \"aria-multiline\": \"true\" },\n },\n onFocus: () => setIsFocused(true),\n onBlur: () => setIsFocused(false),\n onUpdate: ({ editor: e }) => onChange?.(e.getHTML()),\n });\n\n const state = useEditorState({\n editor,\n selector: ({ editor: e }) =>\n e\n ? {\n active: Object.fromEntries(\n GROUPS.flat().map((t) => [t.id, t.active?.(e) ?? false]),\n ),\n linkActive: e.isActive(\"link\"),\n }\n : null,\n });\n\n const toggleLink = useCallback(() => {\n if (!editor) return;\n if (editor.isActive(\"link\")) {\n editor.chain().focus().unsetLink().run();\n return;\n }\n const href = window.prompt(\"Link to\");\n if (!href) return;\n editor.chain().focus().extendMarkRange(\"link\").setLink({ href }).run();\n }, [editor]);\n\n return (\n <div\n ref={ref}\n className={[\"ds-rte\", className].filter(Boolean).join(\" \")}\n data-focused={isFocused || undefined}\n data-disabled={isDisabled || undefined}\n aria-invalid={isInvalid || undefined}\n >\n <div className=\"ds-rte__toolbar\" role=\"toolbar\" aria-label={`${label} formatting`}>\n {GROUPS.map((group, i) => (\n <ButtonGroup key={i} aria-label={`Formatting ${i + 1}`}>\n {group.map((tool) => (\n <Button\n key={tool.id}\n size=\"sm\"\n isIconOnly\n iconStart={tool.icon}\n aria-label={tool.label}\n title={tool.label}\n aria-pressed={tool.active ? state?.active[tool.id] : undefined}\n variant={state?.active[tool.id] ? \"active\" : \"neutral\"}\n isDisabled={isDisabled || !editor}\n onClick={() => editor && tool.run(editor)}\n />\n ))}\n </ButtonGroup>\n ))}\n <ButtonGroup aria-label=\"Link\">\n <Button\n size=\"sm\"\n isIconOnly\n iconStart={state?.linkActive ? \"link-off\" : \"link\"}\n aria-label={state?.linkActive ? \"Remove link\" : \"Add link\"}\n title={state?.linkActive ? \"Remove link\" : \"Add link\"}\n variant={state?.linkActive ? \"active\" : \"neutral\"}\n isDisabled={isDisabled || !editor}\n onClick={toggleLink}\n />\n </ButtonGroup>\n {toolbarExtra}\n </div>\n <div className=\"ds-rte__content\" data-size={size}>\n <EditorContent editor={editor} />\n </div>\n </div>\n );\n },\n);\n"],"mappings":"A,m5BAqCA,IAAMuC,EAAuB,CAC3B,CACE,CACE,GAAI,OACJ,KAAM,OACN,MAAO,OACP,IAAM,GAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI,EAC/C,OAAS,GAAM,EAAE,SAAS,MAAM,CAClC,EACA,CACE,GAAI,SACJ,KAAM,SACN,MAAO,SACP,IAAM,GAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,EACjD,OAAS,GAAM,EAAE,SAAS,QAAQ,CACpC,E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AAAA,YAAD,CAAa,aAAW,OACtB,UAAA,EAAA0B,EAAA,IAAA,CAACzB,EAAAA,OAAD,CACE,KAAK,KACL,WAAA,GACA,UAAWuC,GAAO,WAAa,WAAa,OAC5C,aAAYA,GAAO,WAAa,cAAgB,WAChD,MAAOA,GAAO,WAAa,cAAgB,WAC3C,QAASA,GAAO,WAAa,SAAW,UACxC,WAAYJ,GAAc,CAACD,EAC3B,QAASM,CACV,CAAA,CACU,CAAA,EACZM,CACE,CACL,CAAA,GAAA,EAAArB,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,kBAAkB,YAAWsB,EAC1C,UAAA,EAAAtB,EAAA,IAAA,CAACxB,EAAAA,cAAD,CAAuB,QAAS,CAAA,CAC7B,CAAA,CACF,C,EAET,CACF,E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["StarterKit","Link","Placeholder","GROUPS","RichTextEditor","forwardRef","isFocused","setIsFocused","useState","editor","useEditor","isDisabled","defaultValue","label","onChange","state","useEditorState","toggleLink","useCallback","href","className","isInvalid","ButtonGroup","i","group","Button","tool","toolbarExtra","size","EditorContent"],"sources":["../../../src/components/RichTextEditor/index.tsx"],"sourcesContent":["import { forwardRef, useCallback, useState, type ReactNode } from \"react\";\nimport { EditorContent, useEditor, useEditorState, type Editor } from \"@tiptap/react\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport Link from \"@tiptap/extension-link\";\nimport Placeholder from \"@tiptap/extension-placeholder\";\nimport { Button } from \"../Button\";\nimport { ButtonGroup } from \"../ButtonGroup\";\nimport type { IconName } from \"../Icon/icons\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport type RichTextEditorSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface RichTextEditorProps {\n /** Initial HTML. The editor is uncontrolled: read changes from `onChange`. */\n defaultValue?: string;\n /** Fired with the document's HTML on every change. */\n onChange?: (html: string) => void;\n placeholder?: string;\n size?: RichTextEditorSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Accessible name for the editing surface. */\n label?: string;\n className?: string;\n /** Extra controls appended to the toolbar, e.g. a word count. */\n toolbarExtra?: ReactNode;\n}\n\ninterface ToolItem {\n id: string;\n icon: IconName;\n label: string;\n run: (editor: Editor) => void;\n active?: (editor: Editor) => boolean;\n}\n\nconst GROUPS: ToolItem[][] = [\n [\n {\n id: \"bold\",\n icon: \"bold\",\n label: \"Bold\",\n run: (e) => e.chain().focus().toggleBold().run(),\n active: (e) => e.isActive(\"bold\"),\n },\n {\n id: \"italic\",\n icon: \"italic\",\n label: \"Italic\",\n run: (e) => e.chain().focus().toggleItalic().run(),\n active: (e) => e.isActive(\"italic\"),\n },\n {\n id: \"strike\",\n icon: \"strikethrough\",\n label: \"Strikethrough\",\n run: (e) => e.chain().focus().toggleStrike().run(),\n active: (e) => e.isActive(\"strike\"),\n },\n {\n id: \"code\",\n icon: \"code\",\n label: \"Inline code\",\n run: (e) => e.chain().focus().toggleCode().run(),\n active: (e) => e.isActive(\"code\"),\n },\n ],\n [\n {\n id: \"h2\",\n icon: \"heading-2\",\n label: \"Heading\",\n run: (e) => e.chain().focus().toggleHeading({ level: 2 }).run(),\n active: (e) => e.isActive(\"heading\", { level: 2 }),\n },\n {\n id: \"h3\",\n icon: \"heading-3\",\n label: \"Subheading\",\n run: (e) => e.chain().focus().toggleHeading({ level: 3 }).run(),\n active: (e) => e.isActive(\"heading\", { level: 3 }),\n },\n {\n id: \"quote\",\n icon: \"quote\",\n label: \"Quote\",\n run: (e) => e.chain().focus().toggleBlockquote().run(),\n active: (e) => e.isActive(\"blockquote\"),\n },\n ],\n [\n {\n id: \"ul\",\n icon: \"list\",\n label: \"Bulleted list\",\n run: (e) => e.chain().focus().toggleBulletList().run(),\n active: (e) => e.isActive(\"bulletList\"),\n },\n {\n id: \"ol\",\n icon: \"list-ordered\",\n label: \"Numbered list\",\n run: (e) => e.chain().focus().toggleOrderedList().run(),\n active: (e) => e.isActive(\"orderedList\"),\n },\n ],\n [\n {\n id: \"undo\",\n icon: \"undo\",\n label: \"Undo\",\n run: (e) => e.chain().focus().undo().run(),\n },\n {\n id: \"redo\",\n icon: \"redo\",\n label: \"Redo\",\n run: (e) => e.chain().focus().redo().run(),\n },\n ],\n];\n\n/**\n * The editorial writing surface. Rich text plus links — the same field skin,\n * radius and states as `TextField`, with the toolbar inside the frame.\n */\nexport const RichTextEditor = forwardRef<HTMLDivElement, RichTextEditorProps>(\n function RichTextEditor(\n {\n defaultValue = \"\",\n onChange,\n placeholder = \"Write something…\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n label = \"Rich text editor\",\n className,\n toolbarExtra,\n },\n ref,\n ) {\n const [isFocused, setIsFocused] = useState(false);\n\n const editor = useEditor({\n immediatelyRender: false,\n editable: !isDisabled,\n content: defaultValue,\n extensions: [\n StarterKit.configure({ link: false }),\n Link.configure({ openOnClick: false, autolink: true }),\n Placeholder.configure({ placeholder }),\n ],\n editorProps: {\n attributes: { role: \"textbox\", \"aria-label\": label, \"aria-multiline\": \"true\" },\n },\n onFocus: () => setIsFocused(true),\n onBlur: () => setIsFocused(false),\n onUpdate: ({ editor: e }) => onChange?.(e.getHTML()),\n });\n\n const state = useEditorState({\n editor,\n selector: ({ editor: e }) =>\n e\n ? {\n active: Object.fromEntries(\n GROUPS.flat().map((t) => [t.id, t.active?.(e) ?? false]),\n ),\n linkActive: e.isActive(\"link\"),\n }\n : null,\n });\n\n const toggleLink = useCallback(() => {\n if (!editor) return;\n if (editor.isActive(\"link\")) {\n editor.chain().focus().unsetLink().run();\n return;\n }\n const href = window.prompt(\"Link to\");\n if (!href) return;\n editor.chain().focus().extendMarkRange(\"link\").setLink({ href }).run();\n }, [editor]);\n\n return (\n <div\n ref={ref}\n className={[\"ds-rte\", className].filter(Boolean).join(\" \")}\n data-focused={isFocused || undefined}\n data-disabled={isDisabled || undefined}\n aria-invalid={isInvalid || undefined}\n >\n <div className=\"ds-rte__toolbar\" role=\"toolbar\" aria-label={`${label} formatting`}>\n {GROUPS.map((group, i) => (\n <ButtonGroup key={i} aria-label={`Formatting ${i + 1}`}>\n {group.map((tool) => (\n <Button\n key={tool.id}\n size=\"sm\"\n isIconOnly\n iconStart={tool.icon}\n aria-label={tool.label}\n title={tool.label}\n aria-pressed={tool.active ? state?.active[tool.id] : undefined}\n variant={state?.active[tool.id] ? \"active\" : \"neutral\"}\n isDisabled={isDisabled || !editor}\n onClick={() => editor && tool.run(editor)}\n />\n ))}\n </ButtonGroup>\n ))}\n <ButtonGroup aria-label=\"Link\">\n <Button\n size=\"sm\"\n isIconOnly\n iconStart={state?.linkActive ? \"link-off\" : \"link\"}\n aria-label={state?.linkActive ? \"Remove link\" : \"Add link\"}\n title={state?.linkActive ? \"Remove link\" : \"Add link\"}\n variant={state?.linkActive ? \"active\" : \"neutral\"}\n isDisabled={isDisabled || !editor}\n onClick={toggleLink}\n />\n </ButtonGroup>\n {toolbarExtra}\n </div>\n <div className=\"ds-rte__content\" data-size={size}>\n <EditorContent editor={editor} />\n </div>\n </div>\n );\n },\n);\n"],"mappings":";;;;;;;;;;AAqCA,IAAMG,IAAuB;CAC3B;EACE;GACE,IAAI;GACJ,MAAM;GACN,OAAO;GACP,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,IAAI;GAC/C,SAAS,MAAM,EAAE,SAAS,MAAM;EAClC;EACA;GACE,IAAI;GACJ,MAAM;GACN,OAAO;GACP,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI;GACjD,SAAS,MAAM,EAAE,SAAS,QAAQ;EACpC;EACA;GACE,IAAI;GACJ,MAAM;GACN,OAAO;GACP,MAAM,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI;GACjD,SAAS,MAAM,EAAE,SAAS,QAAQ;EACpC;EACA;GACE,IAAI;GACJ,MAAM;GACN,O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