@freedom-code-compliance/fcc-redesign 0.1.26 → 0.1.27
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/index.cjs +1 -1
- package/dist/index.js +669 -838
- package/dist/rich-text-editor.cjs +1 -0
- package/dist/rich-text-editor.js +173 -0
- package/package.json +5 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`),l=require(`lucide-react`),u=require(`react/jsx-runtime`),d=require(`@tiptap/react`),f=require(`@tiptap/extension-placeholder`);f=s(f,1);let p=require(`@tiptap/extension-underline`);p=s(p,1);let m=require(`@tiptap/starter-kit`);m=s(m,1);function h(e){let t=String(e??``).trim();return!t||t===`<p></p>`||t===`<p><br></p>`?``:t}function g({active:e,disabled:t,label:n,onClick:r,children:i}){return(0,u.jsx)(`button`,{type:`button`,className:[`fcc-rich-text-toolbar-button`,e?`is-active`:``].filter(Boolean).join(` `),"aria-label":n,title:n,onMouseDown:e=>e.preventDefault(),onClick:r,disabled:t,children:i})}function _({id:e,label:t,description:n,error:r,placeholder:i=`Write a note...`,value:a,defaultValue:o=``,onChange:s,disabled:_=!1,minHeight:v=160,showToolbar:y=!0,className:b=``,editorClassName:x=``,toolbarClassName:S=``,"aria-describedby":C,"aria-invalid":w}){let T=(0,c.useId)(),E=e||T,D=r&&r!==!0?r:n,O=D?`${E}-helper`:void 0,k=[C,O].filter(Boolean).join(` `)||void 0,A=!!(r||w),j=a!==void 0,[M,N]=(0,c.useState)(()=>h(o)),P=j?h(a):M,F=(0,d.useEditor)({immediatelyRender:!1,editable:!_,extensions:[m.default.configure({heading:!1,codeBlock:!1,horizontalRule:!1}),p.default,f.default.configure({placeholder:i})],content:P||`<p></p>`,editorProps:{attributes:{class:[`fcc-rich-text-content`,x].filter(Boolean).join(` `)}},onUpdate:({editor:e})=>{let t=h(e.getHTML());j||N(t),s?.(t,{editor:e,text:e.getText(),isEmpty:e.isEmpty})}});(0,c.useEffect)(()=>{F&&F.setEditable(!_)},[_,F]),(0,c.useEffect)(()=>{F&&F.setOptions({editorProps:{attributes:{id:E,role:`textbox`,"aria-multiline":`true`,"aria-describedby":k,"aria-invalid":A?`true`:`false`,class:[`fcc-rich-text-content`,x].filter(Boolean).join(` `)}}})},[k,F,x,E,A]),(0,c.useEffect)(()=>{F&&P!==h(F.getHTML())&&F.commands.setContent(P||`<p></p>`,!1)},[P,F]);let I=[{key:`bold`,label:`Bold`,active:F?.isActive(`bold`),onClick:()=>F?.chain().focus().toggleBold().run(),icon:(0,u.jsx)(l.Bold,{size:14})},{key:`italic`,label:`Italic`,active:F?.isActive(`italic`),onClick:()=>F?.chain().focus().toggleItalic().run(),icon:(0,u.jsx)(l.Italic,{size:14})},{key:`underline`,label:`Underline`,active:F?.isActive(`underline`),onClick:()=>F?.chain().focus().toggleUnderline().run(),icon:(0,u.jsx)(l.Underline,{size:14})},{key:`bulletList`,label:`Bullet list`,active:F?.isActive(`bulletList`),onClick:()=>F?.chain().focus().toggleBulletList().run(),icon:(0,u.jsx)(l.List,{size:14})},{key:`orderedList`,label:`Numbered list`,active:F?.isActive(`orderedList`),onClick:()=>F?.chain().focus().toggleOrderedList().run(),icon:(0,u.jsx)(l.ListOrdered,{size:14})},{key:`blockquote`,label:`Block quote`,active:F?.isActive(`blockquote`),onClick:()=>F?.chain().focus().toggleBlockquote().run(),icon:(0,u.jsx)(l.Quote,{size:14})}];return(0,u.jsxs)(`div`,{className:[`fcc-rich-text-field`,b].filter(Boolean).join(` `),children:[t?(0,u.jsx)(`label`,{className:`fcc-rich-text-label`,htmlFor:E,children:t}):null,(0,u.jsxs)(`div`,{className:[`fcc-rich-text-shell`,A?`is-invalid`:``,_?`is-disabled`:``].filter(Boolean).join(` `),style:{"--fcc-rich-text-min-height":`${v}px`},children:[y?(0,u.jsxs)(`div`,{className:[`fcc-rich-text-toolbar`,S].filter(Boolean).join(` `),children:[(0,u.jsx)(`div`,{className:`fcc-rich-text-toolbar-group`,children:I.map(e=>(0,u.jsx)(g,{label:e.label,active:!!e.active,onClick:e.onClick,disabled:_||!F,children:e.icon},e.key))}),(0,u.jsx)(`div`,{className:`fcc-rich-text-toolbar-divider`}),(0,u.jsxs)(`div`,{className:`fcc-rich-text-toolbar-group`,children:[(0,u.jsx)(g,{label:`Undo`,active:!1,onClick:()=>F?.chain().focus().undo().run(),disabled:_||!F?.can().chain().focus().undo().run(),children:(0,u.jsx)(l.Undo2,{size:14})}),(0,u.jsx)(g,{label:`Redo`,active:!1,onClick:()=>F?.chain().focus().redo().run(),disabled:_||!F?.can().chain().focus().redo().run(),children:(0,u.jsx)(l.Redo2,{size:14})})]})]}):null,(0,u.jsx)(d.EditorContent,{editor:F,className:`fcc-rich-text-editor`})]}),D?(0,u.jsx)(`div`,{id:O,className:[`fcc-rich-text-helper`,A?`is-error`:``].filter(Boolean).join(` `),children:D}):null]})}exports.RichTextEditor=_,exports.t=s;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useEffect as e, useId as t, useState as n } from "react";
|
|
2
|
+
import { Bold as r, Italic as i, List as a, ListOrdered as o, Quote as s, Redo2 as c, Underline as l, Undo2 as u } from "lucide-react";
|
|
3
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
4
|
+
import { EditorContent as p, useEditor as m } from "@tiptap/react";
|
|
5
|
+
import h from "@tiptap/extension-placeholder";
|
|
6
|
+
import g from "@tiptap/extension-underline";
|
|
7
|
+
import _ from "@tiptap/starter-kit";
|
|
8
|
+
//#region src/components/ui/RichTextEditor.jsx
|
|
9
|
+
function v(e) {
|
|
10
|
+
let t = String(e ?? "").trim();
|
|
11
|
+
return !t || t === "<p></p>" || t === "<p><br></p>" ? "" : t;
|
|
12
|
+
}
|
|
13
|
+
function y({ active: e, disabled: t, label: n, onClick: r, children: i }) {
|
|
14
|
+
return /* @__PURE__ */ d("button", {
|
|
15
|
+
type: "button",
|
|
16
|
+
className: ["fcc-rich-text-toolbar-button", e ? "is-active" : ""].filter(Boolean).join(" "),
|
|
17
|
+
"aria-label": n,
|
|
18
|
+
title: n,
|
|
19
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
20
|
+
onClick: r,
|
|
21
|
+
disabled: t,
|
|
22
|
+
children: i
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function b({ id: b, label: x, description: S, error: C, placeholder: w = "Write a note...", value: T, defaultValue: E = "", onChange: D, disabled: O = !1, minHeight: k = 160, showToolbar: A = !0, className: j = "", editorClassName: M = "", toolbarClassName: N = "", "aria-describedby": P, "aria-invalid": F }) {
|
|
26
|
+
let I = t(), L = b || I, R = C && C !== !0 ? C : S, z = R ? `${L}-helper` : void 0, B = [P, z].filter(Boolean).join(" ") || void 0, V = !!(C || F), H = T !== void 0, [U, W] = n(() => v(E)), G = H ? v(T) : U, K = m({
|
|
27
|
+
immediatelyRender: !1,
|
|
28
|
+
editable: !O,
|
|
29
|
+
extensions: [
|
|
30
|
+
_.configure({
|
|
31
|
+
heading: !1,
|
|
32
|
+
codeBlock: !1,
|
|
33
|
+
horizontalRule: !1
|
|
34
|
+
}),
|
|
35
|
+
g,
|
|
36
|
+
h.configure({ placeholder: w })
|
|
37
|
+
],
|
|
38
|
+
content: G || "<p></p>",
|
|
39
|
+
editorProps: { attributes: { class: ["fcc-rich-text-content", M].filter(Boolean).join(" ") } },
|
|
40
|
+
onUpdate: ({ editor: e }) => {
|
|
41
|
+
let t = v(e.getHTML());
|
|
42
|
+
H || W(t), D?.(t, {
|
|
43
|
+
editor: e,
|
|
44
|
+
text: e.getText(),
|
|
45
|
+
isEmpty: e.isEmpty
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
e(() => {
|
|
50
|
+
K && K.setEditable(!O);
|
|
51
|
+
}, [O, K]), e(() => {
|
|
52
|
+
K && K.setOptions({ editorProps: { attributes: {
|
|
53
|
+
id: L,
|
|
54
|
+
role: "textbox",
|
|
55
|
+
"aria-multiline": "true",
|
|
56
|
+
"aria-describedby": B,
|
|
57
|
+
"aria-invalid": V ? "true" : "false",
|
|
58
|
+
class: ["fcc-rich-text-content", M].filter(Boolean).join(" ")
|
|
59
|
+
} } });
|
|
60
|
+
}, [
|
|
61
|
+
B,
|
|
62
|
+
K,
|
|
63
|
+
M,
|
|
64
|
+
L,
|
|
65
|
+
V
|
|
66
|
+
]), e(() => {
|
|
67
|
+
K && G !== v(K.getHTML()) && K.commands.setContent(G || "<p></p>", !1);
|
|
68
|
+
}, [G, K]);
|
|
69
|
+
let q = [
|
|
70
|
+
{
|
|
71
|
+
key: "bold",
|
|
72
|
+
label: "Bold",
|
|
73
|
+
active: K?.isActive("bold"),
|
|
74
|
+
onClick: () => K?.chain().focus().toggleBold().run(),
|
|
75
|
+
icon: /* @__PURE__ */ d(r, { size: 14 })
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
key: "italic",
|
|
79
|
+
label: "Italic",
|
|
80
|
+
active: K?.isActive("italic"),
|
|
81
|
+
onClick: () => K?.chain().focus().toggleItalic().run(),
|
|
82
|
+
icon: /* @__PURE__ */ d(i, { size: 14 })
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: "underline",
|
|
86
|
+
label: "Underline",
|
|
87
|
+
active: K?.isActive("underline"),
|
|
88
|
+
onClick: () => K?.chain().focus().toggleUnderline().run(),
|
|
89
|
+
icon: /* @__PURE__ */ d(l, { size: 14 })
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
key: "bulletList",
|
|
93
|
+
label: "Bullet list",
|
|
94
|
+
active: K?.isActive("bulletList"),
|
|
95
|
+
onClick: () => K?.chain().focus().toggleBulletList().run(),
|
|
96
|
+
icon: /* @__PURE__ */ d(a, { size: 14 })
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
key: "orderedList",
|
|
100
|
+
label: "Numbered list",
|
|
101
|
+
active: K?.isActive("orderedList"),
|
|
102
|
+
onClick: () => K?.chain().focus().toggleOrderedList().run(),
|
|
103
|
+
icon: /* @__PURE__ */ d(o, { size: 14 })
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: "blockquote",
|
|
107
|
+
label: "Block quote",
|
|
108
|
+
active: K?.isActive("blockquote"),
|
|
109
|
+
onClick: () => K?.chain().focus().toggleBlockquote().run(),
|
|
110
|
+
icon: /* @__PURE__ */ d(s, { size: 14 })
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
return /* @__PURE__ */ f("div", {
|
|
114
|
+
className: ["fcc-rich-text-field", j].filter(Boolean).join(" "),
|
|
115
|
+
children: [
|
|
116
|
+
x ? /* @__PURE__ */ d("label", {
|
|
117
|
+
className: "fcc-rich-text-label",
|
|
118
|
+
htmlFor: L,
|
|
119
|
+
children: x
|
|
120
|
+
}) : null,
|
|
121
|
+
/* @__PURE__ */ f("div", {
|
|
122
|
+
className: [
|
|
123
|
+
"fcc-rich-text-shell",
|
|
124
|
+
V ? "is-invalid" : "",
|
|
125
|
+
O ? "is-disabled" : ""
|
|
126
|
+
].filter(Boolean).join(" "),
|
|
127
|
+
style: { "--fcc-rich-text-min-height": `${k}px` },
|
|
128
|
+
children: [A ? /* @__PURE__ */ f("div", {
|
|
129
|
+
className: ["fcc-rich-text-toolbar", N].filter(Boolean).join(" "),
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ d("div", {
|
|
132
|
+
className: "fcc-rich-text-toolbar-group",
|
|
133
|
+
children: q.map((e) => /* @__PURE__ */ d(y, {
|
|
134
|
+
label: e.label,
|
|
135
|
+
active: !!e.active,
|
|
136
|
+
onClick: e.onClick,
|
|
137
|
+
disabled: O || !K,
|
|
138
|
+
children: e.icon
|
|
139
|
+
}, e.key))
|
|
140
|
+
}),
|
|
141
|
+
/* @__PURE__ */ d("div", { className: "fcc-rich-text-toolbar-divider" }),
|
|
142
|
+
/* @__PURE__ */ f("div", {
|
|
143
|
+
className: "fcc-rich-text-toolbar-group",
|
|
144
|
+
children: [/* @__PURE__ */ d(y, {
|
|
145
|
+
label: "Undo",
|
|
146
|
+
active: !1,
|
|
147
|
+
onClick: () => K?.chain().focus().undo().run(),
|
|
148
|
+
disabled: O || !K?.can().chain().focus().undo().run(),
|
|
149
|
+
children: /* @__PURE__ */ d(u, { size: 14 })
|
|
150
|
+
}), /* @__PURE__ */ d(y, {
|
|
151
|
+
label: "Redo",
|
|
152
|
+
active: !1,
|
|
153
|
+
onClick: () => K?.chain().focus().redo().run(),
|
|
154
|
+
disabled: O || !K?.can().chain().focus().redo().run(),
|
|
155
|
+
children: /* @__PURE__ */ d(c, { size: 14 })
|
|
156
|
+
})]
|
|
157
|
+
})
|
|
158
|
+
]
|
|
159
|
+
}) : null, /* @__PURE__ */ d(p, {
|
|
160
|
+
editor: K,
|
|
161
|
+
className: "fcc-rich-text-editor"
|
|
162
|
+
})]
|
|
163
|
+
}),
|
|
164
|
+
R ? /* @__PURE__ */ d("div", {
|
|
165
|
+
id: z,
|
|
166
|
+
className: ["fcc-rich-text-helper", V ? "is-error" : ""].filter(Boolean).join(" "),
|
|
167
|
+
children: R
|
|
168
|
+
}) : null
|
|
169
|
+
]
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { b as RichTextEditor };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@freedom-code-compliance/fcc-redesign",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.27",
|
|
5
5
|
"description": "Reusable FCC design system components and theme for fccPRO and fccOPS.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"require": "./dist/index.cjs"
|
|
21
21
|
},
|
|
22
|
+
"./rich-text-editor": {
|
|
23
|
+
"import": "./dist/rich-text-editor.js",
|
|
24
|
+
"require": "./dist/rich-text-editor.cjs"
|
|
25
|
+
},
|
|
22
26
|
"./styles.css": "./dist/styles.css"
|
|
23
27
|
},
|
|
24
28
|
"files": [
|