@seamlet/astro 0.11.0 → 0.11.2

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/README.md CHANGED
@@ -29,7 +29,7 @@ npx astro add @seamlet/astro node # the integration, and an ad
29
29
  }
30
30
  ```
31
31
 
32
- The environment variable `CMS_ORIGIN` takes the place of `cms` when it is set: a build for a CMS in development, or the CMS's own builder. A build without the file, or with a field it cannot read, stops and says which field to fix.
32
+ The environment variable `CMS_ORIGIN` takes the place of `cms` when it is set and not empty: a build for a CMS in development, or the CMS's own builder. A build without the file, or with a field it cannot read, stops and says which field to fix.
33
33
 
34
34
  3. Describe the content with a schema, and mark the elements that show it:
35
35
 
package/dist/bridge.js CHANGED
@@ -426,6 +426,38 @@ function replacePageBody(document2, html) {
426
426
  restoreRevealedParts(document2, revealed);
427
427
  }
428
428
 
429
+ // src/bridge/editable-elements.ts
430
+ var OUTLINE = "outline";
431
+ var NO_OUTLINE = "none";
432
+ var IMPORTANT = "important";
433
+ var keptOutlines = /* @__PURE__ */ new WeakMap();
434
+ function makeEditable(element, editable) {
435
+ element.setAttribute("contenteditable", editable);
436
+ if (keptOutlines.has(element)) return;
437
+ const { style } = element;
438
+ keptOutlines.set(element, {
439
+ value: style.getPropertyValue(OUTLINE),
440
+ priority: style.getPropertyPriority(OUTLINE)
441
+ });
442
+ style.setProperty(OUTLINE, NO_OUTLINE, IMPORTANT);
443
+ }
444
+ function makeUneditable(element) {
445
+ element.removeAttribute("contenteditable");
446
+ const kept = keptOutlines.get(element);
447
+ if (kept === void 0) return;
448
+ keptOutlines.delete(element);
449
+ restoreOutline(element, kept);
450
+ }
451
+ function restoreOutline(element, kept) {
452
+ const { style } = element;
453
+ if (kept.value === "") {
454
+ style.removeProperty(OUTLINE);
455
+ } else {
456
+ style.setProperty(OUTLINE, kept.value, kept.priority);
457
+ }
458
+ if (style.length === 0) element.removeAttribute("style");
459
+ }
460
+
429
461
  // src/bridge/element-text.ts
430
462
  var LINE_BREAK = "\n";
431
463
  var NO_BREAK_SPACE = /\u00a0/gu;
@@ -505,7 +537,7 @@ function startInlineTextEditing(element, options) {
505
537
  element.removeEventListener("input", reportInput);
506
538
  element.removeEventListener("keydown", endOnKey);
507
539
  element.removeEventListener("blur", endOnBlur);
508
- element.removeAttribute("contenteditable");
540
+ makeUneditable(element);
509
541
  };
510
542
  let hasEnded = false;
511
543
  const end = (outcome) => {
@@ -514,7 +546,7 @@ function startInlineTextEditing(element, options) {
514
546
  stop();
515
547
  options.onEnd(outcome);
516
548
  };
517
- element.setAttribute("contenteditable", EDITABLE_AS_PLAIN_TEXT);
549
+ makeEditable(element, EDITABLE_AS_PLAIN_TEXT);
518
550
  element.addEventListener("input", reportInput);
519
551
  element.addEventListener("keydown", endOnKey);
520
552
  element.addEventListener("blur", endOnBlur);
@@ -653,7 +685,7 @@ function startRichTextEditing(element, options) {
653
685
  document2.removeEventListener("selectionchange", followSelection);
654
686
  document2.removeEventListener("scroll", scheduleReport, true);
655
687
  view?.removeEventListener("resize", scheduleReport);
656
- element.removeAttribute("contenteditable");
688
+ makeUneditable(element);
657
689
  };
658
690
  let hasEnded = false;
659
691
  const end = (outcome) => {
@@ -663,7 +695,7 @@ function startRichTextEditing(element, options) {
663
695
  options.onSelect(void 0);
664
696
  options.onEnd(outcome);
665
697
  };
666
- element.setAttribute("contenteditable", EDITABLE_AS_RICH_TEXT);
698
+ makeEditable(element, EDITABLE_AS_RICH_TEXT);
667
699
  element.addEventListener("input", reportInput);
668
700
  element.addEventListener("keydown", pressKey);
669
701
  element.addEventListener("paste", pastePlainText);
@@ -749,7 +781,7 @@ function createPageTyping(options) {
749
781
  clearTimeout(prepared.timer);
750
782
  if (!isTyped && stopEditing === void 0) {
751
783
  prepared.element.blur();
752
- prepared.element.removeAttribute("contenteditable");
784
+ makeUneditable(prepared.element);
753
785
  }
754
786
  prepared = void 0;
755
787
  };
@@ -757,7 +789,7 @@ function createPageTyping(options) {
757
789
  const isTypedAlready = element.hasAttribute("contenteditable");
758
790
  if (isTypedAlready) return;
759
791
  takePrepared(false);
760
- element.setAttribute("contenteditable", EDITABLE_VALUES[kind]);
792
+ makeEditable(element, EDITABLE_VALUES[kind]);
761
793
  element.focus({ preventScroll: true });
762
794
  const timer = setTimeout(() => {
763
795
  takePrepared(false);
package/dist/index.js CHANGED
@@ -67,7 +67,8 @@ var FIELD_RULES = {
67
67
  async function loadSiteConfig(root, cmsOverride) {
68
68
  const file = new URL(SITE_CONFIG_FILE, root);
69
69
  const parsed = await readJsonFile(file);
70
- const input = cmsOverride === void 0 ? parsed : { ...asObject(parsed), cms: cmsOverride };
70
+ const isOverridden = cmsOverride !== void 0 && cmsOverride !== "";
71
+ const input = isOverridden ? { ...asObject(parsed), cms: cmsOverride } : parsed;
71
72
  const reading = readSiteConfig(input);
72
73
  if (reading.status === "read") return reading.config;
73
74
  throw new Error(invalidFieldsMessage(file, reading.invalidFields));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamlet/astro",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "Connects an Astro site to the Seamlet CMS: the schema of its content, the preview the editor frames, and its published content.",
5
5
  "license": "MIT",
6
6
  "type": "module",