Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@editora/direction

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@editora/direction - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+1
dist/index.cjs.js
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE","PRE"]),a=e=>f.has(e.tagName)&&e.getAttribute("contenteditable")!=="true",h=()=>{const e=window.getSelection();if(e&&e.rangeCount>0){let t=e.getRangeAt(0).startContainer;for(;t&&t!==document.body;){if(t.nodeType===Node.ELEMENT_NODE){const r=t;if(r.getAttribute("contenteditable")==="true")return r}t=t.parentNode}}const n=document.activeElement;if(n){if(n.getAttribute("contenteditable")==="true")return n;const t=n.closest('[contenteditable="true"]');if(t)return t}return document.querySelector('[contenteditable="true"]')},u=e=>{let n=e;for(;n&&n!==document.body;){if(n.nodeType===Node.ELEMENT_NODE){const t=n;if(a(t))return t;if(t.getAttribute("contenteditable")==="true")break}n=n.parentNode}return null},C=(e,n)=>{const t=[],r=new Set,i=o=>{!o||r.has(o)||n.contains(o)&&a(o)&&(r.add(o),t.push(o))};if(e.collapsed)return i(u(e.startContainer)),t;const s=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:o=>{const d=o;if(!a(d))return NodeFilter.FILTER_SKIP;if(typeof e.intersectsNode=="function")return e.intersectsNode(d)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;const l=document.createRange();return l.selectNodeContents(d),e.compareBoundaryPoints(Range.END_TO_START,l)>0&&e.compareBoundaryPoints(Range.START_TO_END,l)<0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let c=s.nextNode();for(;c;)i(c),c=s.nextNode();return t.length===0&&i(u(e.commonAncestorContainer)),t},T=(e,n)=>{if(n===e.innerHTML)return;const t=window.execEditorCommand||window.executeEditorCommand;if(typeof t=="function")try{t("recordDomTransaction",e,n,e.innerHTML)}catch{}},g=e=>{const n=h();if(!n)return!1;const t=window.getSelection();if(!t||t.rangeCount===0)return!1;const r=t.getRangeAt(0);if(!n.contains(r.commonAncestorContainer))return!1;const i=C(r,n);if(i.length===0)return!1;const s=n.innerHTML;return i.forEach(c=>{e==="rtl"?c.setAttribute("dir","rtl"):c.removeAttribute("dir")}),T(n,s),n.dispatchEvent(new Event("input",{bubbles:!0})),!0},p=()=>({name:"direction",toolbar:[{label:"Left to Right",command:"setDirectionLTR",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M21 18H3M21 18L18 21M21 18L18 15M13 3V12M13 3H7M13 3C13.4596 3 13.9148 3.0776 14.3394 3.22836C14.764 3.37913 15.1499 3.6001 15.4749 3.87868C15.7999 4.15726 16.0577 4.48797 16.2336 4.85195C16.4095 5.21593 16.5 5.60603 16.5 6C16.5 6.39397 16.4095 6.78407 16.2336 7.14805C16.0577 7.51203 15.7999 7.84274 15.4749 8.12132C15.1499 8.3999 14.764 8.62087 14.3394 8.77164C13.9148 8.9224 13.4596 9 13 9V3ZM9 3V12" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-l"},{label:"Right to Left",command:"setDirectionRTL",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M3 18H21M3 18L6 21M3 18L6 15M11 12V3H17M15 3V12M10.5 3C10.0404 3 9.58525 3.0776 9.16061 3.22836C8.73597 3.37913 8.35013 3.6001 8.02513 3.87868C7.70012 4.15726 7.44231 4.48797 7.26642 4.85195C7.09053 5.21593 7 5.60603 7 6C7 6.39397 7.09053 6.78407 7.26642 7.14805C7.44231 7.51203 7.70012 7.84274 8.02513 8.12132C8.35013 8.3999 8.73597 8.62087 9.16061 8.77164C9.58525 8.9224 10.0404 9 10.5 9L10.5 3Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-r"}],commands:{setDirectionLTR:()=>{try{return g(null)}catch(e){return console.error("Failed to set LTR direction:",e),!1}},setDirectionRTL:()=>{try{return g("rtl")}catch(e){return console.error("Failed to set RTL direction:",e),!1}}},keymap:{"Mod-Shift-l":"setDirectionLTR","Mod-Shift-r":"setDirectionRTL"}});exports.DirectionPlugin=p;
const g = /* @__PURE__ */ new Set([
"P",
"DIV",
"H1",
"H2",
"H3",
"H4",
"H5",
"H6",
"LI",
"BLOCKQUOTE",
"PRE"
]), l = (e) => g.has(e.tagName) && e.getAttribute("contenteditable") !== "true", h = () => {
const e = window.getSelection();
if (e && e.rangeCount > 0) {
let t = e.getRangeAt(0).startContainer;
for (; t && t !== document.body; ) {
if (t.nodeType === Node.ELEMENT_NODE) {
const r = t;
if (r.getAttribute("contenteditable") === "true")
return r;
}
t = t.parentNode;
}
}
const n = document.activeElement;
if (n) {
if (n.getAttribute("contenteditable") === "true")
return n;
const t = n.closest('[contenteditable="true"]');
if (t) return t;
}
return document.querySelector('[contenteditable="true"]');
}, u = (e) => {
let n = e;
for (; n && n !== document.body; ) {
if (n.nodeType === Node.ELEMENT_NODE) {
const t = n;
if (l(t)) return t;
if (t.getAttribute("contenteditable") === "true") break;
}
n = n.parentNode;
}
return null;
}, C = (e, n) => {
const t = [], r = /* @__PURE__ */ new Set(), i = (o) => {
!o || r.has(o) || n.contains(o) && l(o) && (r.add(o), t.push(o));
};
if (e.collapsed)
return i(u(e.startContainer)), t;
const s = document.createTreeWalker(
n,
NodeFilter.SHOW_ELEMENT,
{
acceptNode: (o) => {
const d = o;
if (!l(d)) return NodeFilter.FILTER_SKIP;
if (typeof e.intersectsNode == "function")
return e.intersectsNode(d) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
const a = document.createRange();
return a.selectNodeContents(d), e.compareBoundaryPoints(Range.END_TO_START, a) > 0 && e.compareBoundaryPoints(Range.START_TO_END, a) < 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
}
}
);
let c = s.nextNode();
for (; c; )
i(c), c = s.nextNode();
return t.length === 0 && i(u(e.commonAncestorContainer)), t;
}, T = (e, n) => {
if (n === e.innerHTML) return;
const t = window.execEditorCommand || window.executeEditorCommand;
if (typeof t == "function")
try {
t("recordDomTransaction", e, n, e.innerHTML);
} catch {
}
}, f = (e) => {
const n = h();
if (!n) return !1;
const t = window.getSelection();
if (!t || t.rangeCount === 0) return !1;
const r = t.getRangeAt(0);
if (!n.contains(r.commonAncestorContainer)) return !1;
const i = C(r, n);
if (i.length === 0) return !1;
const s = n.innerHTML;
return i.forEach((c) => {
e === "rtl" ? c.setAttribute("dir", "rtl") : c.removeAttribute("dir");
}), T(n, s), n.dispatchEvent(new Event("input", { bubbles: !0 })), !0;
}, E = () => ({
name: "direction",
toolbar: [
{
label: "Left to Right",
command: "setDirectionLTR",
icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M21 18H3M21 18L18 21M21 18L18 15M13 3V12M13 3H7M13 3C13.4596 3 13.9148 3.0776 14.3394 3.22836C14.764 3.37913 15.1499 3.6001 15.4749 3.87868C15.7999 4.15726 16.0577 4.48797 16.2336 4.85195C16.4095 5.21593 16.5 5.60603 16.5 6C16.5 6.39397 16.4095 6.78407 16.2336 7.14805C16.0577 7.51203 15.7999 7.84274 15.4749 8.12132C15.1499 8.3999 14.764 8.62087 14.3394 8.77164C13.9148 8.9224 13.4596 9 13 9V3ZM9 3V12" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',
shortcut: "Mod-Shift-l"
},
{
label: "Right to Left",
command: "setDirectionRTL",
icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M3 18H21M3 18L6 21M3 18L6 15M11 12V3H17M15 3V12M10.5 3C10.0404 3 9.58525 3.0776 9.16061 3.22836C8.73597 3.37913 8.35013 3.6001 8.02513 3.87868C7.70012 4.15726 7.44231 4.48797 7.26642 4.85195C7.09053 5.21593 7 5.60603 7 6C7 6.39397 7.09053 6.78407 7.26642 7.14805C7.44231 7.51203 7.70012 7.84274 8.02513 8.12132C8.35013 8.3999 8.73597 8.62087 9.16061 8.77164C9.58525 8.9224 10.0404 9 10.5 9L10.5 3Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',
shortcut: "Mod-Shift-r"
}
],
commands: {
setDirectionLTR: () => {
try {
return f(null);
} catch (e) {
return console.error("Failed to set LTR direction:", e), !1;
}
},
setDirectionRTL: () => {
try {
return f("rtl");
} catch (e) {
return console.error("Failed to set RTL direction:", e), !1;
}
}
},
keymap: {
"Mod-Shift-l": "setDirectionLTR",
"Mod-Shift-r": "setDirectionRTL"
}
});
export {
E as DirectionPlugin
};
+11
-3
{
"name": "@editora/direction",
"version": "1.0.1",
"version": "1.0.2",
"description": "Direction plugin for Rich Text Editor",

@@ -20,3 +20,3 @@ "authors": [

"peerDependencies": {
"@editora/core": "^1.0.5"
"@editora/core": "^1.0.6"
},

@@ -37,3 +37,11 @@ "devDependencies": {

"author": "",
"license": "MIT"
"license": "MIT",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js",
"default": "./dist/index.esm.js"
}
}
}
const o = ["P", "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "LI", "BLOCKQUOTE"], i = () => ({
name: "direction",
toolbar: [
{
label: "Left to Right",
command: "setDirectionLTR",
icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M21 18H3M21 18L18 21M21 18L18 15M13 3V12M13 3H7M13 3C13.4596 3 13.9148 3.0776 14.3394 3.22836C14.764 3.37913 15.1499 3.6001 15.4749 3.87868C15.7999 4.15726 16.0577 4.48797 16.2336 4.85195C16.4095 5.21593 16.5 5.60603 16.5 6C16.5 6.39397 16.4095 6.78407 16.2336 7.14805C16.0577 7.51203 15.7999 7.84274 15.4749 8.12132C15.1499 8.3999 14.764 8.62087 14.3394 8.77164C13.9148 8.9224 13.4596 9 13 9V3ZM9 3V12" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',
shortcut: "Mod-Shift-l"
},
{
label: "Right to Left",
command: "setDirectionRTL",
icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M3 18H21M3 18L6 21M3 18L6 15M11 12V3H17M15 3V12M10.5 3C10.0404 3 9.58525 3.0776 9.16061 3.22836C8.73597 3.37913 8.35013 3.6001 8.02513 3.87868C7.70012 4.15726 7.44231 4.48797 7.26642 4.85195C7.09053 5.21593 7 5.60603 7 6C7 6.39397 7.09053 6.78407 7.26642 7.14805C7.44231 7.51203 7.70012 7.84274 8.02513 8.12132C8.35013 8.3999 8.73597 8.62087 9.16061 8.77164C9.58525 8.9224 10.0404 9 10.5 9L10.5 3Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',
shortcut: "Mod-Shift-r"
}
],
commands: {
setDirectionLTR: () => {
try {
const t = window.getSelection();
if (!t || t.rangeCount === 0) return !1;
let e = t.getRangeAt(0).commonAncestorContainer;
for (e && e.nodeType === Node.TEXT_NODE && (e = e.parentElement); e && e !== document.body; ) {
const r = e;
if (r.tagName && o.includes(r.tagName))
return r.removeAttribute("dir"), !0;
e = r.parentElement;
}
return !1;
} catch (t) {
return console.error("Failed to set LTR direction:", t), !1;
}
},
setDirectionRTL: () => {
try {
const t = window.getSelection();
if (!t || t.rangeCount === 0) return !1;
let e = t.getRangeAt(0).commonAncestorContainer;
for (e && e.nodeType === Node.TEXT_NODE && (e = e.parentElement); e && e !== document.body; ) {
const r = e;
if (r.tagName && o.includes(r.tagName))
return r.setAttribute("dir", "rtl"), !0;
e = r.parentElement;
}
return !1;
} catch (t) {
return console.error("Failed to set RTL direction:", t), !1;
}
}
},
keymap: {
"Mod-Shift-l": "setDirectionLTR",
"Mod-Shift-r": "setDirectionRTL"
}
});
export {
i as DirectionPlugin
};
(function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.line_heightPlugin={}))})(this,(function(o){"use strict";const r=["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE"],i=()=>({name:"direction",toolbar:[{label:"Left to Right",command:"setDirectionLTR",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M21 18H3M21 18L18 21M21 18L18 15M13 3V12M13 3H7M13 3C13.4596 3 13.9148 3.0776 14.3394 3.22836C14.764 3.37913 15.1499 3.6001 15.4749 3.87868C15.7999 4.15726 16.0577 4.48797 16.2336 4.85195C16.4095 5.21593 16.5 5.60603 16.5 6C16.5 6.39397 16.4095 6.78407 16.2336 7.14805C16.0577 7.51203 15.7999 7.84274 15.4749 8.12132C15.1499 8.3999 14.764 8.62087 14.3394 8.77164C13.9148 8.9224 13.4596 9 13 9V3ZM9 3V12" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-l"},{label:"Right to Left",command:"setDirectionRTL",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M3 18H21M3 18L6 21M3 18L6 15M11 12V3H17M15 3V12M10.5 3C10.0404 3 9.58525 3.0776 9.16061 3.22836C8.73597 3.37913 8.35013 3.6001 8.02513 3.87868C7.70012 4.15726 7.44231 4.48797 7.26642 4.85195C7.09053 5.21593 7 5.60603 7 6C7 6.39397 7.09053 6.78407 7.26642 7.14805C7.44231 7.51203 7.70012 7.84274 8.02513 8.12132C8.35013 8.3999 8.73597 8.62087 9.16061 8.77164C9.58525 8.9224 10.0404 9 10.5 9L10.5 3Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-r"}],commands:{setDirectionLTR:()=>{try{const t=window.getSelection();if(!t||t.rangeCount===0)return!1;let e=t.getRangeAt(0).commonAncestorContainer;for(e&&e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){const n=e;if(n.tagName&&r.includes(n.tagName))return n.removeAttribute("dir"),!0;e=n.parentElement}return!1}catch(t){return console.error("Failed to set LTR direction:",t),!1}},setDirectionRTL:()=>{try{const t=window.getSelection();if(!t||t.rangeCount===0)return!1;let e=t.getRangeAt(0).commonAncestorContainer;for(e&&e.nodeType===Node.TEXT_NODE&&(e=e.parentElement);e&&e!==document.body;){const n=e;if(n.tagName&&r.includes(n.tagName))return n.setAttribute("dir","rtl"),!0;e=n.parentElement}return!1}catch(t){return console.error("Failed to set RTL direction:",t),!1}}},keymap:{"Mod-Shift-l":"setDirectionLTR","Mod-Shift-r":"setDirectionRTL"}});o.DirectionPlugin=i,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));