forge-edit 0.1.0-beta.12 → 0.1.0-beta.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.
Files changed (2) hide show
  1. package/dist/index.js +69 -45
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3865,7 +3865,23 @@ function Lt({ logic: e }) {
3865
3865
  }
3866
3866
  //#endregion
3867
3867
  //#region src/components/shared/toolbar/View/Hooks/viewLogic.jsx
3868
- function Rt() {
3868
+ function Rt(e) {
3869
+ let t = "", n = 0;
3870
+ return e.replace(/></g, ">\n<").split("\n").forEach((e) => {
3871
+ let r = e.trim();
3872
+ if (!r) return;
3873
+ let i = /^<\/\w/.test(r), a = /\/>$/.test(r) || /^<(br|hr|img|input|meta|link)\b[^>]*>$/i.test(r), o = /^<\w[^>]*>$/.test(r) && !i && !a, s = /^<(\w+)[^>]*>.*<\/\1>$/.test(r);
3874
+ i && !s && (n = Math.max(0, n - 1)), t += " ".repeat(n) + r + "\n", o && !s && (n += 1);
3875
+ }), t.trim();
3876
+ }
3877
+ function zt(e) {
3878
+ e.focus();
3879
+ let t = document.createRange();
3880
+ t.selectNodeContents(e), t.collapse(!1);
3881
+ let n = window.getSelection();
3882
+ n && (n.removeAllRanges(), n.addRange(t));
3883
+ }
3884
+ function Bt() {
3869
3885
  return {
3870
3886
  toggleFullscreen: () => {
3871
3887
  let e = document.querySelector(".forge-editor");
@@ -3873,7 +3889,15 @@ function Rt() {
3873
3889
  },
3874
3890
  toggleCodeView: () => {
3875
3891
  let e = document.querySelector(".forge-editor__content");
3876
- e && (e.contentEditable === "true" ? (e.contentEditable = "false", e.textContent = e.innerHTML) : (e.contentEditable = "true", e.innerHTML = e.textContent), e.focus());
3892
+ if (e) {
3893
+ if (e.getAttribute("data-code-view") !== "true") {
3894
+ let t = e.innerHTML, n = Rt(t);
3895
+ e.setAttribute("data-code-view", "true"), e.contentEditable = "false", e.style.whiteSpace = "pre", e.style.fontFamily = "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace", e.style.fontSize = "13px", e.style.lineHeight = "1.6", e.style.tabSize = "2", e.textContent = n;
3896
+ } else {
3897
+ let t = e.textContent;
3898
+ e.removeAttribute("data-code-view"), e.style.whiteSpace = "", e.style.fontFamily = "", e.style.fontSize = "", e.style.lineHeight = "", e.style.tabSize = "", e.innerHTML = t, e.contentEditable = "true", zt(e);
3899
+ }
3900
+ }
3877
3901
  },
3878
3902
  showHelp: () => {
3879
3903
  let e = [
@@ -3893,12 +3917,12 @@ function Rt() {
3893
3917
  }
3894
3918
  //#endregion
3895
3919
  //#region src/components/shared/toolbar/View/Components/index.jsx
3896
- function zt() {
3897
- return /* @__PURE__ */ R(Lt, { logic: Rt() });
3920
+ function Vt() {
3921
+ return /* @__PURE__ */ R(Lt, { logic: Bt() });
3898
3922
  }
3899
3923
  //#endregion
3900
3924
  //#region src/components/shared/toolbar/Index/index.jsx
3901
- function Bt({ editorRef: e }) {
3925
+ function Ht({ editorRef: e }) {
3902
3926
  return /* @__PURE__ */ R("div", {
3903
3927
  className: "forge-editor__toolbar sticky top-0 z-10 m-0 flex flex-shrink-0 flex-wrap items-center justify-between gap-[4px] rounded-t-[3px] border-b border-[#ddd] bg-[#f5f5f5] p-[5px] text-[#333]",
3904
3928
  role: "toolbar",
@@ -3910,13 +3934,13 @@ function Bt({ editorRef: e }) {
3910
3934
  /* @__PURE__ */ R(St, {}),
3911
3935
  /* @__PURE__ */ R(Ot, {}),
3912
3936
  /* @__PURE__ */ R(It, {}),
3913
- /* @__PURE__ */ R(zt, {})
3937
+ /* @__PURE__ */ R(Vt, {})
3914
3938
  ]
3915
3939
  });
3916
3940
  }
3917
3941
  //#endregion
3918
3942
  //#region src/components/shared/statusbar/Components/index.jsx
3919
- function Vt() {
3943
+ function Ut() {
3920
3944
  return /* @__PURE__ */ R("div", {
3921
3945
  className: "forge-statusbar box-border flex h-2.5 w-full flex-shrink-0 cursor-s-resize items-center justify-center rounded-b-[3px] border-t border-[#ccc] bg-[#f0f0f0]",
3922
3946
  role: "status",
@@ -3933,10 +3957,10 @@ function Vt() {
3933
3957
  }
3934
3958
  //#endregion
3935
3959
  //#region src/components/shared/statusbar/Hooks/resize.js
3936
- var Ht = 100;
3937
- function Ut(e, t, n = {}) {
3960
+ var Wt = 100;
3961
+ function Gt(e, t, n = {}) {
3938
3962
  if (!e || !t) return () => {};
3939
- let r = n.minHeight ?? Ht, i = n.maxHeight ?? Infinity, a = 0, o = 0;
3963
+ let r = n.minHeight ?? Wt, i = n.maxHeight ?? Infinity, a = 0, o = 0;
3940
3964
  function s(e) {
3941
3965
  let n = e.clientY - a, s = o + n;
3942
3966
  s = Math.min(Math.max(s, r), i), t.style.height = `${s}px`;
@@ -3953,7 +3977,7 @@ function Ut(e, t, n = {}) {
3953
3977
  }
3954
3978
  //#endregion
3955
3979
  //#region src/components/shared/toolbar/Style/Hooks/styleLogic.jsx
3956
- function Wt(e) {
3980
+ function Kt(e) {
3957
3981
  let t = window.getSelection();
3958
3982
  if (!t || !t.rangeCount) return;
3959
3983
  let n = t.getRangeAt(0).commonAncestorContainer;
@@ -3967,20 +3991,20 @@ function Wt(e) {
3967
3991
  i.selectNodeContents(n), i.collapse(!1), t.removeAllRanges(), t.addRange(i);
3968
3992
  }
3969
3993
  }
3970
- function Gt(e) {
3994
+ function qt(e) {
3971
3995
  if (!e) return;
3972
3996
  let t = e.querySelector("[data-command='style']"), n = e.querySelector(".forge-dropdown-style");
3973
3997
  !t || !n || (Je(t, n), n.querySelectorAll(".forge-dropdown-item").forEach((e) => {
3974
3998
  e.addEventListener("mousedown", (r) => {
3975
3999
  r.preventDefault(), r.stopPropagation();
3976
4000
  let i = e.dataset.value || e.getAttribute("data-value");
3977
- i && Wt(i), n.classList.remove("is-open"), t.classList.remove("is-active");
4001
+ i && Kt(i), n.classList.remove("is-open"), t.classList.remove("is-active");
3978
4002
  });
3979
4003
  }));
3980
4004
  }
3981
4005
  //#endregion
3982
4006
  //#region src/components/shared/i18n/index.js
3983
- var Kt = {
4007
+ var Jt = {
3984
4008
  en: {
3985
4009
  style: "Style",
3986
4010
  normal: "Normal",
@@ -4053,20 +4077,20 @@ var Kt = {
4053
4077
  codeview: "عرض الكود",
4054
4078
  help: "مساعدة"
4055
4079
  }
4056
- }, qt = "en";
4057
- function Jt(e, t) {
4058
- return (Kt[e] || Kt[qt])[t] || Kt[qt][t] || t;
4080
+ }, Yt = "en";
4081
+ function Xt(e, t) {
4082
+ return (Jt[e] || Jt[Yt])[t] || Jt[Yt][t] || t;
4059
4083
  }
4060
4084
  //#endregion
4061
4085
  //#region src/components/shared/i18n/apply.js
4062
- function Yt(e, t) {
4086
+ function Zt(e, t) {
4063
4087
  e.querySelectorAll("[data-i18n]").forEach((e) => {
4064
- e.textContent = Jt(t, e.getAttribute("data-i18n"));
4088
+ e.textContent = Xt(t, e.getAttribute("data-i18n"));
4065
4089
  });
4066
4090
  }
4067
4091
  //#endregion
4068
4092
  //#region src/components/shared/toolbar/Style/Utils/ensureParagraph.jsx
4069
- function Xt(e) {
4093
+ function Qt(e) {
4070
4094
  if (e && !(e.children.length > 0 || e.textContent.trim().length > 0)) {
4071
4095
  let t = document.createElement("p");
4072
4096
  t.innerHTML = "<br>", e.appendChild(t);
@@ -4074,7 +4098,7 @@ function Xt(e) {
4074
4098
  }
4075
4099
  //#endregion
4076
4100
  //#region src/components/shared/toolbar/Hooks/contentClick.js
4077
- function Zt(e) {
4101
+ function $t(e) {
4078
4102
  e.addEventListener("click", (t) => {
4079
4103
  if (t.target === e) {
4080
4104
  let t = window.getSelection();
@@ -4091,7 +4115,7 @@ function Zt(e) {
4091
4115
  }
4092
4116
  //#endregion
4093
4117
  //#region src/components/shared/toolbar/ImagePopover/Components/ImagePopover.jsx
4094
- function Qt({ target: e, onClose: t, onResize: n, onFloat: r, onRemove: i }) {
4118
+ function en({ target: e, onClose: t, onResize: n, onFloat: r, onRemove: i }) {
4095
4119
  let a = q(null);
4096
4120
  if (!e) return null;
4097
4121
  let o = e.getBoundingClientRect(), s = {
@@ -4226,7 +4250,7 @@ function Qt({ target: e, onClose: t, onResize: n, onFloat: r, onRemove: i }) {
4226
4250
  }
4227
4251
  //#endregion
4228
4252
  //#region src/components/shared/toolbar/ImagePopover/Hooks/useImagePopover.jsx
4229
- function $t() {
4253
+ function tn() {
4230
4254
  let [e, t] = G(null), [n, r] = G(!1);
4231
4255
  return K(() => {
4232
4256
  let e = (e) => {
@@ -4261,12 +4285,12 @@ function $t() {
4261
4285
  }
4262
4286
  //#endregion
4263
4287
  //#region src/components/shared/toolbar/ImagePopover/Components/index.jsx
4264
- function en() {
4265
- return /* @__PURE__ */ R(Qt, { ...$t() });
4288
+ function nn() {
4289
+ return /* @__PURE__ */ R(en, { ...tn() });
4266
4290
  }
4267
4291
  //#endregion
4268
4292
  //#region src/components/light/index.jsx
4269
- function tn(e) {
4293
+ function rn(e) {
4270
4294
  return {
4271
4295
  getHTML() {
4272
4296
  return e.innerHTML;
@@ -4283,41 +4307,41 @@ function tn(e) {
4283
4307
  }
4284
4308
  };
4285
4309
  }
4286
- function nn(e) {
4310
+ function an(e) {
4287
4311
  let t = e.lang || "en", n = e.dir || "ltr", r = { current: null }, i = /* @__PURE__ */ R("div", {
4288
4312
  className: "forge-editor forge-editor--light flex flex-col w-full rounded-[3px] border border-[#ddd] bg-white box-border align-top min-h-[120px]",
4289
4313
  lang: t,
4290
4314
  dir: n,
4291
4315
  children: [
4292
- /* @__PURE__ */ R(Bt, { editorRef: r }),
4316
+ /* @__PURE__ */ R(Ht, { editorRef: r }),
4293
4317
  /* @__PURE__ */ R("div", {
4294
4318
  className: "forge-editor__content flex-1 min-h-[60px] overflow-auto p-[10px] pb-12 outline-none box-border [&_blockquote]:my-2 [&_blockquote]:border-l-4 [&_blockquote]:border-[#ccc] [&_blockquote]:pl-4 [&_blockquote]:italic [&_pre]:bg-[#f4f4f4] [&_pre]:p-2 [&_pre]:rounded [&_h1]:text-2xl [&_h1]:font-bold [&_h2]:text-xl [&_h2]:font-bold [&_h3]:text-lg [&_h3]:font-bold",
4295
4319
  contentEditable: "true",
4296
4320
  "data-placeholder": e.placeholder || ""
4297
4321
  }),
4298
- /* @__PURE__ */ R(Vt, {}),
4299
- /* @__PURE__ */ R(en, {})
4322
+ /* @__PURE__ */ R(Ut, {}),
4323
+ /* @__PURE__ */ R(nn, {})
4300
4324
  ]
4301
4325
  }), a = document.createElement("div");
4302
4326
  I(i, a);
4303
4327
  let o = a.firstElementChild, s = o.querySelector(".forge-editor__content");
4304
- r.current = s, Xt(s), Zt(s);
4328
+ r.current = s, Qt(s), $t(s);
4305
4329
  let c = o.querySelector(".forge-toolbar-style");
4306
- c && Gt(c);
4330
+ c && qt(c);
4307
4331
  let l = o.querySelector(".forge-editor__toolbar");
4308
- l && Yt(l, t);
4332
+ l && Zt(l, t);
4309
4333
  let u = o.querySelector(".forge-statusbar");
4310
- return u && Ut(u, o, { minHeight: 120 }), {
4334
+ return u && Gt(u, o, { minHeight: 120 }), {
4311
4335
  element: o,
4312
- ...tn(s)
4336
+ ...rn(s)
4313
4337
  };
4314
4338
  }
4315
4339
  //#endregion
4316
4340
  //#region src/main/index.jsx
4317
- function rn(e) {
4341
+ function on(e) {
4318
4342
  let t = l(e);
4319
4343
  if (t.type === "light") {
4320
- let { element: n, getHTML: r, setHTML: i, getText: a, getSelection: o } = nn(t);
4344
+ let { element: n, getHTML: r, setHTML: i, getText: a, getSelection: o } = an(t);
4321
4345
  return e.innerHTML = "", e.appendChild(n), n.style.width = t.width, n.style.height = t.height, {
4322
4346
  element: n,
4323
4347
  getHTML: r,
@@ -4330,13 +4354,13 @@ function rn(e) {
4330
4354
  }
4331
4355
  //#endregion
4332
4356
  //#region src/main/main.jsx
4333
- var an = document.querySelectorAll("forge-editor"), on = [];
4334
- an.forEach((e) => {
4335
- let t = rn(e);
4336
- t && on.push(t);
4337
- }), window.forgeEditors = on;
4338
- var sn = document.getElementById("get-html-btn"), cn = document.getElementById("html-output");
4339
- sn && cn && on[0] && sn.addEventListener("click", () => {
4340
- cn.value = on[0].getHTML();
4357
+ var sn = document.querySelectorAll("forge-editor"), cn = [];
4358
+ sn.forEach((e) => {
4359
+ let t = on(e);
4360
+ t && cn.push(t);
4361
+ }), window.forgeEditors = cn;
4362
+ var ln = document.getElementById("get-html-btn"), un = document.getElementById("html-output");
4363
+ ln && un && cn[0] && ln.addEventListener("click", () => {
4364
+ un.value = cn[0].getHTML();
4341
4365
  });
4342
4366
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-edit",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.13",
4
4
  "description": "A lightweight WYSIWYG editor built with Preact",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",