@bagelink/vue 0.0.992 → 0.0.996
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/components/form/inputs/CodeEditor/Index.vue.d.ts +7 -11
- package/dist/components/form/inputs/CodeEditor/Index.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/components/Toolbar.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/composables/useEditor.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/config.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/index.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/formatting.d.ts +1 -0
- package/dist/components/form/inputs/RichText/utils/formatting.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/media.d.ts +3 -3
- package/dist/components/form/inputs/RichText/utils/media.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/selection.d.ts.map +1 -1
- package/dist/index.cjs +285 -102
- package/dist/index.mjs +285 -102
- package/dist/style.css +16 -14
- package/package.json +2 -1
- package/src/components/form/inputs/CodeEditor/Index.vue +26 -10
- package/src/components/form/inputs/RichText/components/Toolbar.vue +1 -1
- package/src/components/form/inputs/RichText/composables/useEditor.ts +17 -4
- package/src/components/form/inputs/RichText/config.ts +5 -1
- package/src/components/form/inputs/RichText/index.vue +1 -0
- package/src/components/form/inputs/RichText/richTextTypes.d.ts +2 -0
- package/src/components/form/inputs/RichText/utils/formatting.ts +281 -34
- package/src/components/form/inputs/RichText/utils/media.ts +9 -6
- package/src/components/form/inputs/RichText/utils/selection.ts +6 -22
package/dist/index.mjs
CHANGED
|
@@ -6515,7 +6515,7 @@ const _hoisted_1$1$1 = {
|
|
|
6515
6515
|
};
|
|
6516
6516
|
const _hoisted_2$1$1 = ["width", "height", "viewBox"];
|
|
6517
6517
|
const _hoisted_3$m = { class: "layer-rectangles" };
|
|
6518
|
-
const _hoisted_4$
|
|
6518
|
+
const _hoisted_4$d = ["transform", "onMouseover"];
|
|
6519
6519
|
const _hoisted_5$d = ["width", "height"];
|
|
6520
6520
|
const _hoisted_6$a = {
|
|
6521
6521
|
x: 0 + 10,
|
|
@@ -6567,7 +6567,7 @@ function render$1(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
6567
6567
|
)
|
|
6568
6568
|
])
|
|
6569
6569
|
])
|
|
6570
|
-
], 42, _hoisted_4$
|
|
6570
|
+
], 42, _hoisted_4$d);
|
|
6571
6571
|
}),
|
|
6572
6572
|
128
|
|
6573
6573
|
/* KEYED_FRAGMENT */
|
|
@@ -6791,7 +6791,7 @@ const _hoisted_2$q = {
|
|
|
6791
6791
|
class: "data-row m_py-05"
|
|
6792
6792
|
};
|
|
6793
6793
|
const _hoisted_3$l = { class: "key" };
|
|
6794
|
-
const _hoisted_4$
|
|
6794
|
+
const _hoisted_4$c = { class: "m-0" };
|
|
6795
6795
|
const _hoisted_5$c = { key: 1 };
|
|
6796
6796
|
const _hoisted_6$9 = {
|
|
6797
6797
|
key: 0,
|
|
@@ -6850,7 +6850,7 @@ const _sfc_main$R = /* @__PURE__ */ defineComponent({
|
|
|
6850
6850
|
}, [
|
|
6851
6851
|
unref(iffer)(field, itemData.value) ? (openBlock(), createElementBlock("div", _hoisted_2$q, [
|
|
6852
6852
|
createElementVNode("div", _hoisted_3$l, [
|
|
6853
|
-
createElementVNode("p", _hoisted_4$
|
|
6853
|
+
createElementVNode("p", _hoisted_4$c, toDisplayString((field == null ? void 0 : field.label) || unref(keyToLabel)(field.id)), 1)
|
|
6854
6854
|
]),
|
|
6855
6855
|
createVNode(unref(_sfc_main$N), {
|
|
6856
6856
|
modelValue: itemData.value,
|
|
@@ -24236,28 +24236,18 @@ function requireCommon() {
|
|
|
24236
24236
|
return common;
|
|
24237
24237
|
}
|
|
24238
24238
|
requireCommon();
|
|
24239
|
-
const _hoisted_1$A = {
|
|
24240
|
-
const _hoisted_2$o = {
|
|
24241
|
-
|
|
24242
|
-
style: { "height": "800px" }
|
|
24243
|
-
};
|
|
24244
|
-
const _hoisted_3$j = { class: "numbers absolute inset-0 py-1 px-05 txt16 line-height-15 overflow-hidden z-999 w50px txt-start opacity-3 color-gray" };
|
|
24245
|
-
const _hoisted_4$c = ["onKeydown"];
|
|
24239
|
+
const _hoisted_1$A = { class: "code-editor-wrap ltr radius-1" };
|
|
24240
|
+
const _hoisted_2$o = { class: "numbers absolute inset-0 py-1 px-05 txt16 line-height-15 overflow-hidden z-1 w50px txt-start opacity-3 color-gray" };
|
|
24241
|
+
const _hoisted_3$j = ["onKeydown"];
|
|
24246
24242
|
const _sfc_main$I = /* @__PURE__ */ defineComponent({
|
|
24247
24243
|
__name: "Index",
|
|
24248
|
-
props:
|
|
24244
|
+
props: {
|
|
24249
24245
|
language: {},
|
|
24250
|
-
readonly: { type: Boolean, default: false }
|
|
24251
|
-
|
|
24252
|
-
|
|
24253
|
-
type: String,
|
|
24254
|
-
default: ""
|
|
24255
|
-
},
|
|
24256
|
-
"modelModifiers": {}
|
|
24257
|
-
}),
|
|
24258
|
-
emits: ["update:modelValue"],
|
|
24246
|
+
readonly: { type: Boolean, default: false },
|
|
24247
|
+
modelValue: { default: "" }
|
|
24248
|
+
},
|
|
24259
24249
|
setup(__props) {
|
|
24260
|
-
|
|
24250
|
+
let code = ref("");
|
|
24261
24251
|
function tabKeyDown(event) {
|
|
24262
24252
|
const target = event.target;
|
|
24263
24253
|
const start = target.selectionStart;
|
|
@@ -24268,12 +24258,26 @@ const _sfc_main$I = /* @__PURE__ */ defineComponent({
|
|
|
24268
24258
|
target.selectionStart = target.selectionEnd = start + 2;
|
|
24269
24259
|
});
|
|
24270
24260
|
}
|
|
24261
|
+
const textarea = ref();
|
|
24262
|
+
let height = ref("300px");
|
|
24263
|
+
function setHeight() {
|
|
24264
|
+
if (!textarea.value) return;
|
|
24265
|
+
const { scrollHeight } = textarea.value;
|
|
24266
|
+
height.value = `${scrollHeight}px`;
|
|
24267
|
+
}
|
|
24271
24268
|
const Highlightjs = o.component;
|
|
24269
|
+
watch(() => code.value, setHeight, { immediate: true });
|
|
24270
|
+
watch(() => __props.modelValue, (value) => {
|
|
24271
|
+
if (value !== code.value) code.value = value;
|
|
24272
|
+
}, { immediate: true });
|
|
24272
24273
|
return (_ctx, _cache) => {
|
|
24273
24274
|
return openBlock(), createElementBlock("div", _hoisted_1$A, [
|
|
24274
|
-
createElementVNode("div",
|
|
24275
|
-
|
|
24276
|
-
|
|
24275
|
+
createElementVNode("div", {
|
|
24276
|
+
class: "relative block h-100",
|
|
24277
|
+
style: normalizeStyle({ height: unref(height) })
|
|
24278
|
+
}, [
|
|
24279
|
+
createElementVNode("div", _hoisted_2$o, [
|
|
24280
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(code).split("\n"), (_2, index2) => {
|
|
24277
24281
|
return openBlock(), createElementBlock("div", {
|
|
24278
24282
|
key: index2,
|
|
24279
24283
|
class: "number txt-end"
|
|
@@ -24283,23 +24287,26 @@ const _sfc_main$I = /* @__PURE__ */ defineComponent({
|
|
|
24283
24287
|
createVNode(unref(Highlightjs), {
|
|
24284
24288
|
class: "highlighted-code absolute inset-0",
|
|
24285
24289
|
autodetect: !_ctx.language,
|
|
24286
|
-
code: code
|
|
24290
|
+
code: unref(code),
|
|
24287
24291
|
wrap: true,
|
|
24288
24292
|
language: _ctx.language
|
|
24289
24293
|
}, null, 8, ["autodetect", "code", "language"]),
|
|
24290
24294
|
!_ctx.readonly ? withDirectives((openBlock(), createElementBlock("textarea", {
|
|
24291
24295
|
key: 0,
|
|
24292
|
-
|
|
24296
|
+
ref_key: "textarea",
|
|
24297
|
+
ref: textarea,
|
|
24298
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(code) ? code.value = $event : code = $event),
|
|
24293
24299
|
spellcheck: false,
|
|
24294
24300
|
class: "code-editor absolute inset-0 overflow-hidden bg-transparent line-height-15 border-none m-0",
|
|
24295
24301
|
placeholder: "Write your code here",
|
|
24296
24302
|
"aria-label": "Code Editor",
|
|
24297
24303
|
"data-gramm": "false",
|
|
24304
|
+
onInput: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("update:modelValue", unref(code))),
|
|
24298
24305
|
onKeydown: withKeys(withModifiers(tabKeyDown, ["prevent"]), ["tab"])
|
|
24299
|
-
}, null, 40,
|
|
24300
|
-
[vModelText, code
|
|
24306
|
+
}, null, 40, _hoisted_3$j)), [
|
|
24307
|
+
[vModelText, unref(code)]
|
|
24301
24308
|
]) : createCommentVNode("", true)
|
|
24302
|
-
])
|
|
24309
|
+
], 4)
|
|
24303
24310
|
]);
|
|
24304
24311
|
};
|
|
24305
24312
|
}
|
|
@@ -34942,12 +34949,14 @@ const defaultToolbarConfig = [
|
|
|
34942
34949
|
"italic",
|
|
34943
34950
|
"underline",
|
|
34944
34951
|
"separator",
|
|
34952
|
+
"p",
|
|
34953
|
+
"blockquote",
|
|
34945
34954
|
"orderedList",
|
|
34946
34955
|
"unorderedList",
|
|
34947
34956
|
"separator",
|
|
34948
34957
|
"link",
|
|
34949
34958
|
"image",
|
|
34950
|
-
|
|
34959
|
+
// 'youtube',
|
|
34951
34960
|
"separator",
|
|
34952
34961
|
"splitView",
|
|
34953
34962
|
"clear",
|
|
@@ -34961,6 +34970,8 @@ const toolbarOptions = [
|
|
|
34961
34970
|
{ name: "h4", label: "h4", icon: "format_h4" },
|
|
34962
34971
|
{ name: "h5", label: "h5", icon: "format_h5" },
|
|
34963
34972
|
{ name: "h6", label: "h6", icon: "format_h6" },
|
|
34973
|
+
{ name: "p", label: "Paragraph", icon: "format_paragraph" },
|
|
34974
|
+
{ name: "blockquote", label: "Blockquote", icon: "format_quote" },
|
|
34964
34975
|
{ name: "bold", label: "Bold", icon: "format_bold" },
|
|
34965
34976
|
{ name: "italic", label: "Italic", icon: "format_italic" },
|
|
34966
34977
|
{ name: "underline", label: "Underline", icon: "format_underlined" },
|
|
@@ -35092,8 +35103,7 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
|
|
|
35092
35103
|
}, null, 8, ["onSelect"])
|
|
35093
35104
|
]),
|
|
35094
35105
|
_: 1
|
|
35095
|
-
})) :
|
|
35096
|
-
action.name !== "separator" ? withDirectives((openBlock(), createBlock(unref(Btn), {
|
|
35106
|
+
})) : action.name !== "separator" ? withDirectives((openBlock(), createBlock(unref(Btn), {
|
|
35097
35107
|
key: 1,
|
|
35098
35108
|
icon: action.icon,
|
|
35099
35109
|
thin: "",
|
|
@@ -35113,12 +35123,91 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
|
|
|
35113
35123
|
};
|
|
35114
35124
|
}
|
|
35115
35125
|
});
|
|
35116
|
-
const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$v, [["__scopeId", "data-v-
|
|
35126
|
+
const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$v, [["__scopeId", "data-v-9688758a"]]);
|
|
35117
35127
|
function formatting(state2) {
|
|
35128
|
+
const { doc, range: range2, selection } = state2;
|
|
35129
|
+
function setRangeAndSelect(node, start, end) {
|
|
35130
|
+
if (!range2) return;
|
|
35131
|
+
range2.setStart(node, start);
|
|
35132
|
+
range2.setEnd(node, end);
|
|
35133
|
+
}
|
|
35134
|
+
const wrapWithTag = (content, tag) => {
|
|
35135
|
+
const wrapper = doc.createElement(tag);
|
|
35136
|
+
wrapper.textContent = content;
|
|
35137
|
+
return wrapper;
|
|
35138
|
+
};
|
|
35139
|
+
const createBlockElement = (tag, content) => {
|
|
35140
|
+
const block2 = doc.createElement(tag);
|
|
35141
|
+
block2.appendChild(content);
|
|
35142
|
+
return block2;
|
|
35143
|
+
};
|
|
35144
|
+
const clear = () => {
|
|
35145
|
+
if (!doc || !range2 || !selection) return;
|
|
35146
|
+
const inlineTags = ["b", "i", "u", "strong", "em"];
|
|
35147
|
+
const isInlineTag = (el) => el && inlineTags.includes(el.tagName.toLowerCase());
|
|
35148
|
+
if (range2.collapsed) {
|
|
35149
|
+
return;
|
|
35150
|
+
}
|
|
35151
|
+
const selectedContent = range2.extractContents();
|
|
35152
|
+
const cleanInlineTags = (node) => {
|
|
35153
|
+
if (node.nodeType === 1 && isInlineTag(node)) {
|
|
35154
|
+
const fragment2 = doc.createDocumentFragment();
|
|
35155
|
+
let child = node.firstChild;
|
|
35156
|
+
while (child) {
|
|
35157
|
+
const { nextSibling } = child;
|
|
35158
|
+
fragment2.appendChild(cleanInlineTags(child));
|
|
35159
|
+
child = nextSibling;
|
|
35160
|
+
}
|
|
35161
|
+
return fragment2;
|
|
35162
|
+
} else if (node.nodeType === 1) {
|
|
35163
|
+
const element = node.cloneNode(false);
|
|
35164
|
+
let child = node.firstChild;
|
|
35165
|
+
while (child) {
|
|
35166
|
+
const { nextSibling } = child;
|
|
35167
|
+
element.appendChild(cleanInlineTags(child));
|
|
35168
|
+
child = nextSibling;
|
|
35169
|
+
}
|
|
35170
|
+
return element;
|
|
35171
|
+
} else if (node.nodeType === 3) {
|
|
35172
|
+
return node;
|
|
35173
|
+
}
|
|
35174
|
+
return doc.createTextNode("");
|
|
35175
|
+
};
|
|
35176
|
+
const fragment = doc.createDocumentFragment();
|
|
35177
|
+
Array.from(selectedContent.childNodes).forEach((child) => {
|
|
35178
|
+
const cleanedChild = cleanInlineTags(child);
|
|
35179
|
+
if (cleanedChild.nodeType === 11) {
|
|
35180
|
+
fragment.appendChild(cleanedChild);
|
|
35181
|
+
} else {
|
|
35182
|
+
fragment.appendChild(cleanedChild);
|
|
35183
|
+
}
|
|
35184
|
+
});
|
|
35185
|
+
range2.deleteContents();
|
|
35186
|
+
range2.insertNode(fragment);
|
|
35187
|
+
const normalizeDom = (node) => {
|
|
35188
|
+
var _a2, _b;
|
|
35189
|
+
if (node.nodeType === 3 && ((_a2 = node.nextSibling) == null ? void 0 : _a2.nodeType) === 3) {
|
|
35190
|
+
if (node.textContent && node.nextSibling.textContent) {
|
|
35191
|
+
node.textContent += node.nextSibling.textContent;
|
|
35192
|
+
}
|
|
35193
|
+
(_b = node.parentNode) == null ? void 0 : _b.removeChild(node.nextSibling);
|
|
35194
|
+
} else if (node.nodeType === 1) {
|
|
35195
|
+
Array.from(node.childNodes).forEach((child) => {
|
|
35196
|
+
normalizeDom(child);
|
|
35197
|
+
});
|
|
35198
|
+
}
|
|
35199
|
+
};
|
|
35200
|
+
Array.from(fragment.childNodes).forEach((child) => {
|
|
35201
|
+
normalizeDom(child);
|
|
35202
|
+
});
|
|
35203
|
+
selection.removeAllRanges();
|
|
35204
|
+
range2.selectNodeContents(fragment);
|
|
35205
|
+
selection.addRange(range2);
|
|
35206
|
+
};
|
|
35118
35207
|
const text = (command) => {
|
|
35119
|
-
var _a2, _b;
|
|
35120
|
-
const { doc, range: range2, selection } = state2;
|
|
35208
|
+
var _a2, _b, _c, _d, _e2;
|
|
35121
35209
|
if (!doc || !range2 || !selection) return;
|
|
35210
|
+
const { startOffset, endOffset } = range2;
|
|
35122
35211
|
let tag = "";
|
|
35123
35212
|
if (command === "bold") tag = "b";
|
|
35124
35213
|
if (command === "italic") tag = "i";
|
|
@@ -35128,84 +35217,179 @@ function formatting(state2) {
|
|
|
35128
35217
|
const relatedTags = {
|
|
35129
35218
|
b: ["strong"],
|
|
35130
35219
|
i: ["em"],
|
|
35131
|
-
u: [],
|
|
35220
|
+
u: ["u"],
|
|
35132
35221
|
em: ["i"],
|
|
35133
35222
|
strong: ["b"]
|
|
35134
35223
|
};
|
|
35135
|
-
const
|
|
35136
|
-
|
|
35137
|
-
|
|
35224
|
+
const isTagMatch = (el) => el && (el.tagName.toLowerCase() === tag || relatedTags[tag].includes(el.tagName.toLowerCase()));
|
|
35225
|
+
if (range2.collapsed) {
|
|
35226
|
+
const container2 = range2.commonAncestorContainer;
|
|
35227
|
+
const parent2 = container2.parentElement;
|
|
35228
|
+
if (parent2 && isTagMatch(parent2)) {
|
|
35229
|
+
const textNode = doc.createTextNode(parent2.textContent || "");
|
|
35230
|
+
(_a2 = parent2.parentNode) == null ? void 0 : _a2.replaceChild(textNode, parent2);
|
|
35231
|
+
range2.selectNodeContents(textNode);
|
|
35232
|
+
selection.removeAllRanges();
|
|
35233
|
+
setRangeAndSelect(textNode, startOffset, endOffset);
|
|
35234
|
+
selection.addRange(range2);
|
|
35235
|
+
}
|
|
35236
|
+
return;
|
|
35237
|
+
}
|
|
35138
35238
|
const container = range2.commonAncestorContainer;
|
|
35139
35239
|
const parent = container.parentElement;
|
|
35140
|
-
if (parent && (parent
|
|
35141
|
-
|
|
35142
|
-
|
|
35143
|
-
|
|
35144
|
-
|
|
35240
|
+
if (parent && isTagMatch(parent)) {
|
|
35241
|
+
const parentText = parent.textContent || "";
|
|
35242
|
+
const beforeText = parentText.substring(0, range2.startOffset - parentText.indexOf(parent.textContent || ""));
|
|
35243
|
+
const selectedText = parentText.substring(range2.startOffset, range2.endOffset);
|
|
35244
|
+
const afterText = parentText.substring(range2.endOffset);
|
|
35245
|
+
if (beforeText) {
|
|
35246
|
+
const beforeNode = wrapWithTag(beforeText, tag);
|
|
35247
|
+
(_b = parent.parentNode) == null ? void 0 : _b.insertBefore(beforeNode, parent);
|
|
35248
|
+
}
|
|
35249
|
+
const unwrappedTextNode = doc.createTextNode(selectedText);
|
|
35250
|
+
(_c = parent.parentNode) == null ? void 0 : _c.insertBefore(unwrappedTextNode, parent);
|
|
35251
|
+
if (afterText) {
|
|
35252
|
+
const afterNode = wrapWithTag(afterText, tag);
|
|
35253
|
+
(_d = parent.parentNode) == null ? void 0 : _d.insertBefore(afterNode, parent);
|
|
35254
|
+
}
|
|
35255
|
+
(_e2 = parent.parentNode) == null ? void 0 : _e2.removeChild(parent);
|
|
35256
|
+
range2.selectNode(unwrappedTextNode);
|
|
35145
35257
|
} else {
|
|
35258
|
+
const selectedContent = range2.extractContents();
|
|
35259
|
+
const wrapper = doc.createElement(tag);
|
|
35260
|
+
wrapper.appendChild(selectedContent);
|
|
35146
35261
|
range2.insertNode(wrapper);
|
|
35262
|
+
const nestedTags = wrapper.querySelectorAll(`${tag},${(relatedTags[tag] || []).join(",")}`);
|
|
35263
|
+
nestedTags.forEach((nestedTag) => {
|
|
35264
|
+
var _a3, _b2;
|
|
35265
|
+
while (nestedTag.firstChild) {
|
|
35266
|
+
(_a3 = nestedTag.parentNode) == null ? void 0 : _a3.insertBefore(nestedTag.firstChild, nestedTag);
|
|
35267
|
+
}
|
|
35268
|
+
(_b2 = nestedTag.parentNode) == null ? void 0 : _b2.removeChild(nestedTag);
|
|
35269
|
+
});
|
|
35270
|
+
range2.selectNodeContents(wrapper);
|
|
35147
35271
|
}
|
|
35148
|
-
const nestedTags = wrapper.querySelectorAll(`${tag},${(relatedTags[tag] || []).join(",")}`);
|
|
35149
|
-
nestedTags.forEach((nestedTag) => {
|
|
35150
|
-
var _a3, _b2;
|
|
35151
|
-
while (nestedTag.firstChild) {
|
|
35152
|
-
(_a3 = nestedTag.parentNode) == null ? void 0 : _a3.insertBefore(nestedTag.firstChild, nestedTag);
|
|
35153
|
-
}
|
|
35154
|
-
(_b2 = nestedTag.parentNode) == null ? void 0 : _b2.removeChild(nestedTag);
|
|
35155
|
-
});
|
|
35156
35272
|
selection.removeAllRanges();
|
|
35157
35273
|
selection.addRange(range2);
|
|
35158
35274
|
};
|
|
35159
35275
|
const block = (command, value) => {
|
|
35160
35276
|
var _a2;
|
|
35161
|
-
const { doc, range: range2, selection } = state2;
|
|
35162
35277
|
if (!doc || !range2 || !selection) return;
|
|
35163
35278
|
const container = range2.commonAncestorContainer;
|
|
35164
35279
|
const parent = container.nodeType === 3 ? container.parentElement : container;
|
|
35165
35280
|
if (!parent) return;
|
|
35166
|
-
const currentHeading = parent.closest("p,h1,h2,h3,h4,h5,h6");
|
|
35281
|
+
const currentHeading = parent.closest("p,h1,h2,h3,h4,h5,h6,blockquote");
|
|
35167
35282
|
const { startOffset, endOffset } = range2;
|
|
35168
35283
|
const blockEl = currentHeading || parent.closest("p,h1,h2,h3,h4,h5,h6") || parent;
|
|
35169
35284
|
range2.selectNodeContents(blockEl);
|
|
35170
35285
|
const content = range2.extractContents();
|
|
35171
|
-
const newElement =
|
|
35172
|
-
newElement.appendChild(content);
|
|
35286
|
+
const newElement = createBlockElement(value, content);
|
|
35173
35287
|
if (currentHeading) {
|
|
35174
35288
|
(_a2 = currentHeading.parentNode) == null ? void 0 : _a2.replaceChild(newElement, currentHeading);
|
|
35175
35289
|
} else {
|
|
35176
35290
|
range2.insertNode(newElement);
|
|
35177
35291
|
}
|
|
35178
35292
|
selection.removeAllRanges();
|
|
35179
|
-
|
|
35180
|
-
range2.setEnd(container, endOffset);
|
|
35293
|
+
setRangeAndSelect(container, startOffset, endOffset);
|
|
35181
35294
|
selection.addRange(range2);
|
|
35182
35295
|
};
|
|
35183
35296
|
const list = (command) => {
|
|
35184
35297
|
var _a2;
|
|
35185
|
-
|
|
35186
|
-
if (!doc || !range2) return;
|
|
35298
|
+
if (!doc || !range2 || !selection) return;
|
|
35187
35299
|
const listTag = command === "orderedList" ? "ol" : "ul";
|
|
35188
35300
|
const container = range2.commonAncestorContainer;
|
|
35189
35301
|
const parent = container.nodeType === 3 ? container.parentElement : container;
|
|
35190
35302
|
const currentList = parent == null ? void 0 : parent.closest("ul,ol");
|
|
35303
|
+
if (!parent) return;
|
|
35304
|
+
const listItem = parent.closest("li");
|
|
35305
|
+
if (listItem) {
|
|
35306
|
+
const listParent = listItem.parentElement;
|
|
35307
|
+
if (!listParent) return;
|
|
35308
|
+
const beforeFragment = doc.createDocumentFragment();
|
|
35309
|
+
const afterFragment = doc.createDocumentFragment();
|
|
35310
|
+
let currentNode = listParent.firstChild;
|
|
35311
|
+
let isBefore2 = true;
|
|
35312
|
+
while (currentNode) {
|
|
35313
|
+
if (currentNode === listItem) {
|
|
35314
|
+
isBefore2 = false;
|
|
35315
|
+
} else if (isBefore2) {
|
|
35316
|
+
beforeFragment.appendChild(currentNode.cloneNode(true));
|
|
35317
|
+
} else {
|
|
35318
|
+
afterFragment.appendChild(currentNode.cloneNode(true));
|
|
35319
|
+
}
|
|
35320
|
+
currentNode = currentNode.nextSibling;
|
|
35321
|
+
}
|
|
35322
|
+
const standaloneBlock = doc.createElement("p");
|
|
35323
|
+
while (listItem.firstChild) {
|
|
35324
|
+
standaloneBlock.appendChild(listItem.firstChild);
|
|
35325
|
+
}
|
|
35326
|
+
const grandParent = listParent.parentNode;
|
|
35327
|
+
if (!grandParent) return;
|
|
35328
|
+
if (beforeFragment.childNodes.length > 0) {
|
|
35329
|
+
const newListBefore = doc.createElement(listParent.tagName.toLowerCase());
|
|
35330
|
+
newListBefore.appendChild(beforeFragment);
|
|
35331
|
+
grandParent.insertBefore(newListBefore, listParent);
|
|
35332
|
+
}
|
|
35333
|
+
grandParent.insertBefore(standaloneBlock, listParent);
|
|
35334
|
+
if (afterFragment.childNodes.length > 0) {
|
|
35335
|
+
const newListAfter = doc.createElement(listParent.tagName.toLowerCase());
|
|
35336
|
+
newListAfter.appendChild(afterFragment);
|
|
35337
|
+
grandParent.insertBefore(newListAfter, listParent.nextSibling);
|
|
35338
|
+
}
|
|
35339
|
+
grandParent.removeChild(listParent);
|
|
35340
|
+
selection.removeAllRanges();
|
|
35341
|
+
range2.selectNodeContents(standaloneBlock);
|
|
35342
|
+
selection.addRange(range2);
|
|
35343
|
+
return;
|
|
35344
|
+
}
|
|
35345
|
+
const startBlock = parent.closest("p,h1,h2,h3,h4,h5,h6,blockquote") || parent;
|
|
35346
|
+
const endBlock = range2.endContainer.nodeType === 3 ? ((_a2 = range2.endContainer.parentElement) == null ? void 0 : _a2.closest("p,h1,h2,h3,h4,h5,h6,blockquote")) || range2.endContainer.parentElement : range2.endContainer;
|
|
35347
|
+
const blocks = [];
|
|
35348
|
+
let currentBlock = startBlock;
|
|
35349
|
+
while (currentBlock) {
|
|
35350
|
+
blocks.push(currentBlock);
|
|
35351
|
+
if (currentBlock === endBlock) break;
|
|
35352
|
+
currentBlock = currentBlock.nextElementSibling;
|
|
35353
|
+
}
|
|
35191
35354
|
if (currentList) {
|
|
35192
|
-
const
|
|
35193
|
-
|
|
35194
|
-
|
|
35195
|
-
|
|
35355
|
+
const fragment = doc.createDocumentFragment();
|
|
35356
|
+
blocks.forEach((block2) => {
|
|
35357
|
+
const paragraph = doc.createElement("p");
|
|
35358
|
+
while (block2.firstChild) {
|
|
35359
|
+
paragraph.appendChild(block2.firstChild);
|
|
35360
|
+
}
|
|
35361
|
+
fragment.appendChild(paragraph);
|
|
35362
|
+
});
|
|
35363
|
+
const listParent = currentList.parentNode;
|
|
35364
|
+
if (listParent) {
|
|
35365
|
+
listParent.insertBefore(fragment, currentList.nextSibling);
|
|
35366
|
+
if (!currentList.querySelector("li")) {
|
|
35367
|
+
listParent.removeChild(currentList);
|
|
35368
|
+
}
|
|
35369
|
+
}
|
|
35370
|
+
selection.removeAllRanges();
|
|
35371
|
+
range2.selectNodeContents(fragment);
|
|
35372
|
+
selection.addRange(range2);
|
|
35196
35373
|
} else {
|
|
35197
35374
|
const listEl = doc.createElement(listTag);
|
|
35198
|
-
|
|
35199
|
-
|
|
35200
|
-
|
|
35201
|
-
|
|
35375
|
+
blocks.forEach((block2) => {
|
|
35376
|
+
const li = doc.createElement("li");
|
|
35377
|
+
while (block2.firstChild) {
|
|
35378
|
+
li.appendChild(block2.firstChild);
|
|
35379
|
+
}
|
|
35380
|
+
listEl.appendChild(li);
|
|
35381
|
+
});
|
|
35202
35382
|
range2.insertNode(listEl);
|
|
35383
|
+
selection.removeAllRanges();
|
|
35384
|
+
range2.selectNodeContents(listEl);
|
|
35385
|
+
selection.addRange(range2);
|
|
35203
35386
|
}
|
|
35204
35387
|
};
|
|
35205
|
-
return { text, block, list };
|
|
35388
|
+
return { text, block, list, clear };
|
|
35206
35389
|
}
|
|
35207
|
-
function insertImage(modal,
|
|
35208
|
-
|
|
35390
|
+
function insertImage(modal, state2) {
|
|
35391
|
+
const { range: range2, doc } = state2;
|
|
35392
|
+
if (!range2 || !doc) return;
|
|
35209
35393
|
modal.showModalForm({
|
|
35210
35394
|
title: "Upload Image",
|
|
35211
35395
|
schema: [
|
|
@@ -35217,14 +35401,15 @@ function insertImage(modal, doc, range2) {
|
|
|
35217
35401
|
const img = doc.createElement("img");
|
|
35218
35402
|
img.src = data2.src;
|
|
35219
35403
|
img.alt = data2.alt;
|
|
35220
|
-
range2.
|
|
35404
|
+
range2.collapse(false);
|
|
35221
35405
|
range2.insertNode(img);
|
|
35222
35406
|
}
|
|
35223
35407
|
}
|
|
35224
35408
|
});
|
|
35225
35409
|
}
|
|
35226
|
-
function insertLink(modal,
|
|
35227
|
-
|
|
35410
|
+
function insertLink(modal, state2) {
|
|
35411
|
+
const { range: range2, doc } = state2;
|
|
35412
|
+
if (!range2 || !doc) return;
|
|
35228
35413
|
modal.showModalForm({
|
|
35229
35414
|
title: "Insert Link",
|
|
35230
35415
|
schema: [
|
|
@@ -35253,28 +35438,12 @@ function isStyleActive(style, doc) {
|
|
|
35253
35438
|
if (tags.includes(element.tagName.toLowerCase())) return true;
|
|
35254
35439
|
return checkParent(element.parentElement, tags);
|
|
35255
35440
|
};
|
|
35256
|
-
|
|
35257
|
-
|
|
35258
|
-
|
|
35259
|
-
|
|
35260
|
-
|
|
35261
|
-
|
|
35262
|
-
return checkParent(parent, ["u"]);
|
|
35263
|
-
case "h1":
|
|
35264
|
-
return checkParent(parent, ["h1"]);
|
|
35265
|
-
case "h2":
|
|
35266
|
-
return checkParent(parent, ["h2"]);
|
|
35267
|
-
case "h3":
|
|
35268
|
-
return checkParent(parent, ["h3"]);
|
|
35269
|
-
case "h4":
|
|
35270
|
-
return checkParent(parent, ["h4"]);
|
|
35271
|
-
case "h5":
|
|
35272
|
-
return checkParent(parent, ["h5"]);
|
|
35273
|
-
case "h6":
|
|
35274
|
-
return checkParent(parent, ["h6"]);
|
|
35275
|
-
default:
|
|
35276
|
-
return false;
|
|
35277
|
-
}
|
|
35441
|
+
const styleTags = {
|
|
35442
|
+
bold: ["strong", "b"],
|
|
35443
|
+
italic: ["em", "i"],
|
|
35444
|
+
underline: ["u"]
|
|
35445
|
+
};
|
|
35446
|
+
return checkParent(parent, styleTags[style] ?? [style]);
|
|
35278
35447
|
}
|
|
35279
35448
|
function insertTable(rows, cols, state2) {
|
|
35280
35449
|
if (!state2.doc) return;
|
|
@@ -35381,7 +35550,12 @@ function useEditor() {
|
|
|
35381
35550
|
"h3",
|
|
35382
35551
|
"h4",
|
|
35383
35552
|
"h5",
|
|
35384
|
-
"h6"
|
|
35553
|
+
"h6",
|
|
35554
|
+
"blockquote",
|
|
35555
|
+
"table",
|
|
35556
|
+
"p",
|
|
35557
|
+
"ol",
|
|
35558
|
+
"li"
|
|
35385
35559
|
];
|
|
35386
35560
|
styleTypes.forEach((style) => {
|
|
35387
35561
|
if (state2.doc && isStyleActive(style, state2.doc)) {
|
|
@@ -35449,7 +35623,7 @@ function useEditor() {
|
|
|
35449
35623
|
if (!state2.doc.body.contains(selection.anchorNode)) {
|
|
35450
35624
|
state2.doc.body.focus();
|
|
35451
35625
|
}
|
|
35452
|
-
console.log(command);
|
|
35626
|
+
console.log("command", command, value2);
|
|
35453
35627
|
switch (command) {
|
|
35454
35628
|
case "insertTable": {
|
|
35455
35629
|
const [rows, cols] = (value2 == null ? void 0 : value2.split("x").map(Number)) || [3, 3];
|
|
@@ -35482,12 +35656,16 @@ function useEditor() {
|
|
|
35482
35656
|
case "underline":
|
|
35483
35657
|
format2().text(command);
|
|
35484
35658
|
break;
|
|
35659
|
+
case "clear": {
|
|
35660
|
+
format2().clear();
|
|
35661
|
+
break;
|
|
35662
|
+
}
|
|
35485
35663
|
case "orderedList":
|
|
35486
35664
|
case "unorderedList":
|
|
35487
35665
|
format2().list(command);
|
|
35488
35666
|
break;
|
|
35489
35667
|
case "image":
|
|
35490
|
-
insertImage(state2.modal, state2
|
|
35668
|
+
insertImage(state2.modal, state2);
|
|
35491
35669
|
break;
|
|
35492
35670
|
// case 'youtube':
|
|
35493
35671
|
// if (isCaret) return
|
|
@@ -35495,7 +35673,11 @@ function useEditor() {
|
|
|
35495
35673
|
// break
|
|
35496
35674
|
case "link":
|
|
35497
35675
|
if (isCaret) return;
|
|
35498
|
-
insertLink(state2.modal, state2
|
|
35676
|
+
insertLink(state2.modal, state2);
|
|
35677
|
+
break;
|
|
35678
|
+
case "blockquote":
|
|
35679
|
+
case "p":
|
|
35680
|
+
format2().block(command, value2 || command);
|
|
35499
35681
|
break;
|
|
35500
35682
|
default:
|
|
35501
35683
|
if (/^h[1-6]$/.test(command)) {
|
|
@@ -35596,6 +35778,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
35596
35778
|
watch(() => props2.modelValue, (newValue) => {
|
|
35597
35779
|
if (newValue !== editor.state.content) {
|
|
35598
35780
|
editor.state.content = newValue;
|
|
35781
|
+
editor.updateContent("html");
|
|
35599
35782
|
}
|
|
35600
35783
|
});
|
|
35601
35784
|
watch(() => editor.state.content, (newValue) => {
|
|
@@ -35639,7 +35822,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
35639
35822
|
};
|
|
35640
35823
|
}
|
|
35641
35824
|
});
|
|
35642
|
-
const RichText = /* @__PURE__ */ _export_sfc(_sfc_main$u, [["__scopeId", "data-v-
|
|
35825
|
+
const RichText = /* @__PURE__ */ _export_sfc(_sfc_main$u, [["__scopeId", "data-v-e274dd3b"]]);
|
|
35643
35826
|
const _hoisted_1$m = { class: "flex gap-05" };
|
|
35644
35827
|
const _hoisted_2$e = ["disabled"];
|
|
35645
35828
|
const _hoisted_3$b = { key: 1 };
|