@haluo/biz 1.0.5 → 1.0.7

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/haluo-biz.js CHANGED
@@ -2020,7 +2020,7 @@ const _sfc_main = {
2020
2020
  return;
2021
2021
  }
2022
2022
  children.forEach((child) => {
2023
- if (child.nodeType === 1 && !child.className.includes("halo")) {
2023
+ if (child.nodeType === 1 && (child.tagName !== "svg" && !child.className.includes("halo") || child.tagName === "svg")) {
2024
2024
  const parent = child.parentNode;
2025
2025
  parent.removeChild(child);
2026
2026
  }
@@ -2237,6 +2237,7 @@ const _sfc_main = {
2237
2237
  });
2238
2238
  },
2239
2239
  imgUploadHandler(type, imgSrc) {
2240
+ const me = this;
2240
2241
  if (type && imgSrc) {
2241
2242
  if (type === "uploadAgainImages") {
2242
2243
  this.updateImage(imgSrc, this.currentImg);
@@ -2248,7 +2249,7 @@ const _sfc_main = {
2248
2249
  src: imgSrc,
2249
2250
  img: imgSrc,
2250
2251
  selected: false,
2251
- seamlessFlag: this.replaceSeamless,
2252
+ seamlessFlag: me.replaceSeamless,
2252
2253
  type: "2"
2253
2254
  }, this.range);
2254
2255
  } else {
@@ -2315,7 +2316,7 @@ const _sfc_main = {
2315
2316
  return;
2316
2317
  const current = me.findParentByClass(e.target, "halo-img-content");
2317
2318
  const range = document.createRange();
2318
- range.setEnd(current.previousElementSibling || current, 1);
2319
+ range.setEnd(current.previousElementSibling, 1);
2319
2320
  range.collapse(false);
2320
2321
  me.range = range;
2321
2322
  me.replaceSeamless = data.seamlessFlag || "0";
@@ -2323,6 +2324,30 @@ const _sfc_main = {
2323
2324
  me.removePreviousImg = () => me.removeParentByClass(e.target, "halo-img-content");
2324
2325
  replaceInput.click();
2325
2326
  };
2327
+ delBtn.onclick = function(e) {
2328
+ if (me.disabled)
2329
+ return;
2330
+ const cur = me.findParentByClass(e.target, "halo-img-content");
2331
+ const currentImg = cur.getElementsByClassName("halo-picture-area")[0];
2332
+ const currentData = JSON.parse(currentImg.getAttribute("data"));
2333
+ if (currentData.seamlessFlag === "0") {
2334
+ if (!cur.previousElementSibling)
2335
+ return;
2336
+ try {
2337
+ const imgcont = cur.previousElementSibling.previousElementSibling;
2338
+ const input = imgcont.getElementsByClassName("desc-input-wrap")[0];
2339
+ const pic = imgcont.getElementsByClassName("halo-picture-area")[0];
2340
+ const data2 = JSON.parse(pic.getAttribute("data"));
2341
+ data2.seamlessFlag = "0";
2342
+ pic.setAttribute("data", JSON.stringify(data2));
2343
+ input.style.display = "";
2344
+ } catch (e2) {
2345
+ console.log(e2);
2346
+ }
2347
+ }
2348
+ me.removeParentByClass(e.target, "halo-img-content");
2349
+ me.updateData(true);
2350
+ };
2326
2351
  replaceBtn.innerHTML = "\u66FF\u6362";
2327
2352
  return [replaceBtn, delBtn, descInputWrap];
2328
2353
  },
@@ -2424,6 +2449,7 @@ const _sfc_main = {
2424
2449
  window.Squire.prototype.insertImages = function(src, data = {}, range) {
2425
2450
  var isHaloImage = me.isHaloImage(src);
2426
2451
  var scrollTop = document.documentElement.scrollTop;
2452
+ const isSeameless = data.seamlessFlag === "1";
2427
2453
  var loading = this.createElement("div", {
2428
2454
  "class": "img-loading",
2429
2455
  "contenteditable": "false"
@@ -2451,7 +2477,7 @@ const _sfc_main = {
2451
2477
  "src": src,
2452
2478
  "class": isHaloImage ? "halo-picture-area" : "halo-picture-area no-upload",
2453
2479
  "data": JSON.stringify(data),
2454
- "style": data.seamlessFlag === "1" ? "margin: 0" : "margin-top: 0",
2480
+ "style": isSeameless ? "margin: 0" : "margin-top: 0",
2455
2481
  "data-content": data.content || "",
2456
2482
  "contenteditable": "false"
2457
2483
  });
@@ -2466,16 +2492,11 @@ const _sfc_main = {
2466
2492
  "class": "halo-img-content",
2467
2493
  "contenteditable": "false"
2468
2494
  }, [...childList]);
2469
- if (me.imgType === "seamless") {
2470
- me.countList.push(p);
2471
- if (me.countList.length === me.imgList.length) {
2472
- var ct = this.createElement("div", {}, [...me.countList]);
2473
- this.insertElement(ct, range);
2474
- this.imgType = "normal";
2475
- }
2476
- return;
2477
- }
2478
2495
  this.insertElement(p, range);
2496
+ if (isSeameless) {
2497
+ me.removeDefault(p, "nextElementSibling");
2498
+ me.removeDefault(p, "previousElementSibling");
2499
+ }
2479
2500
  setTimeout(() => {
2480
2501
  document.documentElement.scrollTop = scrollTop;
2481
2502
  }, 50);
@@ -2550,6 +2571,23 @@ const _sfc_main = {
2550
2571
  };
2551
2572
  me.sticky();
2552
2573
  },
2574
+ removeDefault(next, key) {
2575
+ const me = this;
2576
+ const cur = next[key];
2577
+ if (!cur || cur.innerText !== "\n")
2578
+ return;
2579
+ const blockDefault = cur.classList.contains("halo-paragraph") || false;
2580
+ const isLasterBlock = next.classList.contains("halo-paragraph") || false;
2581
+ if (blockDefault && isLasterBlock) {
2582
+ cur.remove();
2583
+ me.removeDefault(cur, key);
2584
+ } else {
2585
+ if (blockDefault) {
2586
+ cur.style.display = "none";
2587
+ me.removeDefault(cur, key);
2588
+ }
2589
+ }
2590
+ },
2553
2591
  generateDelLinkIcon() {
2554
2592
  const me = this;
2555
2593
  const del = this.editor.createElement("img", {
@@ -2024,7 +2024,7 @@
2024
2024
  return;
2025
2025
  }
2026
2026
  children.forEach((child) => {
2027
- if (child.nodeType === 1 && !child.className.includes("halo")) {
2027
+ if (child.nodeType === 1 && (child.tagName !== "svg" && !child.className.includes("halo") || child.tagName === "svg")) {
2028
2028
  const parent = child.parentNode;
2029
2029
  parent.removeChild(child);
2030
2030
  }
@@ -2241,6 +2241,7 @@
2241
2241
  });
2242
2242
  },
2243
2243
  imgUploadHandler(type, imgSrc) {
2244
+ const me = this;
2244
2245
  if (type && imgSrc) {
2245
2246
  if (type === "uploadAgainImages") {
2246
2247
  this.updateImage(imgSrc, this.currentImg);
@@ -2252,7 +2253,7 @@
2252
2253
  src: imgSrc,
2253
2254
  img: imgSrc,
2254
2255
  selected: false,
2255
- seamlessFlag: this.replaceSeamless,
2256
+ seamlessFlag: me.replaceSeamless,
2256
2257
  type: "2"
2257
2258
  }, this.range);
2258
2259
  } else {
@@ -2319,7 +2320,7 @@
2319
2320
  return;
2320
2321
  const current = me.findParentByClass(e.target, "halo-img-content");
2321
2322
  const range = document.createRange();
2322
- range.setEnd(current.previousElementSibling || current, 1);
2323
+ range.setEnd(current.previousElementSibling, 1);
2323
2324
  range.collapse(false);
2324
2325
  me.range = range;
2325
2326
  me.replaceSeamless = data.seamlessFlag || "0";
@@ -2327,6 +2328,30 @@
2327
2328
  me.removePreviousImg = () => me.removeParentByClass(e.target, "halo-img-content");
2328
2329
  replaceInput.click();
2329
2330
  };
2331
+ delBtn.onclick = function(e) {
2332
+ if (me.disabled)
2333
+ return;
2334
+ const cur = me.findParentByClass(e.target, "halo-img-content");
2335
+ const currentImg = cur.getElementsByClassName("halo-picture-area")[0];
2336
+ const currentData = JSON.parse(currentImg.getAttribute("data"));
2337
+ if (currentData.seamlessFlag === "0") {
2338
+ if (!cur.previousElementSibling)
2339
+ return;
2340
+ try {
2341
+ const imgcont = cur.previousElementSibling.previousElementSibling;
2342
+ const input = imgcont.getElementsByClassName("desc-input-wrap")[0];
2343
+ const pic = imgcont.getElementsByClassName("halo-picture-area")[0];
2344
+ const data2 = JSON.parse(pic.getAttribute("data"));
2345
+ data2.seamlessFlag = "0";
2346
+ pic.setAttribute("data", JSON.stringify(data2));
2347
+ input.style.display = "";
2348
+ } catch (e2) {
2349
+ console.log(e2);
2350
+ }
2351
+ }
2352
+ me.removeParentByClass(e.target, "halo-img-content");
2353
+ me.updateData(true);
2354
+ };
2330
2355
  replaceBtn.innerHTML = "\u66FF\u6362";
2331
2356
  return [replaceBtn, delBtn, descInputWrap];
2332
2357
  },
@@ -2428,6 +2453,7 @@
2428
2453
  window.Squire.prototype.insertImages = function(src, data = {}, range) {
2429
2454
  var isHaloImage = me.isHaloImage(src);
2430
2455
  var scrollTop = document.documentElement.scrollTop;
2456
+ const isSeameless = data.seamlessFlag === "1";
2431
2457
  var loading = this.createElement("div", {
2432
2458
  "class": "img-loading",
2433
2459
  "contenteditable": "false"
@@ -2455,7 +2481,7 @@
2455
2481
  "src": src,
2456
2482
  "class": isHaloImage ? "halo-picture-area" : "halo-picture-area no-upload",
2457
2483
  "data": JSON.stringify(data),
2458
- "style": data.seamlessFlag === "1" ? "margin: 0" : "margin-top: 0",
2484
+ "style": isSeameless ? "margin: 0" : "margin-top: 0",
2459
2485
  "data-content": data.content || "",
2460
2486
  "contenteditable": "false"
2461
2487
  });
@@ -2470,16 +2496,11 @@
2470
2496
  "class": "halo-img-content",
2471
2497
  "contenteditable": "false"
2472
2498
  }, [...childList]);
2473
- if (me.imgType === "seamless") {
2474
- me.countList.push(p);
2475
- if (me.countList.length === me.imgList.length) {
2476
- var ct = this.createElement("div", {}, [...me.countList]);
2477
- this.insertElement(ct, range);
2478
- this.imgType = "normal";
2479
- }
2480
- return;
2481
- }
2482
2499
  this.insertElement(p, range);
2500
+ if (isSeameless) {
2501
+ me.removeDefault(p, "nextElementSibling");
2502
+ me.removeDefault(p, "previousElementSibling");
2503
+ }
2483
2504
  setTimeout(() => {
2484
2505
  document.documentElement.scrollTop = scrollTop;
2485
2506
  }, 50);
@@ -2554,6 +2575,23 @@
2554
2575
  };
2555
2576
  me.sticky();
2556
2577
  },
2578
+ removeDefault(next, key) {
2579
+ const me = this;
2580
+ const cur = next[key];
2581
+ if (!cur || cur.innerText !== "\n")
2582
+ return;
2583
+ const blockDefault = cur.classList.contains("halo-paragraph") || false;
2584
+ const isLasterBlock = next.classList.contains("halo-paragraph") || false;
2585
+ if (blockDefault && isLasterBlock) {
2586
+ cur.remove();
2587
+ me.removeDefault(cur, key);
2588
+ } else {
2589
+ if (blockDefault) {
2590
+ cur.style.display = "none";
2591
+ me.removeDefault(cur, key);
2592
+ }
2593
+ }
2594
+ },
2557
2595
  generateDelLinkIcon() {
2558
2596
  const me = this;
2559
2597
  const del = this.editor.createElement("img", {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@haluo/biz",
3
3
  "description": "rich text",
4
- "version": "1.0.5",
4
+ "version": "1.0.7",
5
5
  "type": "module",
6
6
  "module": "./dist/haluo-biz.js",
7
7
  "main": "./dist/haluo-biz.umd.cjs",