@seamlet/astro 0.8.0 → 0.8.1

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/bridge.js +65 -3
  2. package/package.json +1 -1
package/dist/bridge.js CHANGED
@@ -25,9 +25,36 @@ import {
25
25
  REVEAL_ATTRIBUTE,
26
26
  REVEAL_EVENT,
27
27
  asOneParagraph,
28
- readRichText
28
+ readRichText,
29
+ resolveFieldPath
29
30
  } from "./chunk-ZUJEM3P7.js";
30
31
 
32
+ // src/bridge/typed-fields.ts
33
+ function typedKindAt(schema, path) {
34
+ const target = resolveFieldPath(schema, path);
35
+ if (target?.kind !== "field") return void 0;
36
+ switch (target.field.kind) {
37
+ case "text":
38
+ return "plain";
39
+ case "richText":
40
+ return "rich";
41
+ case "number":
42
+ case "date":
43
+ case "time":
44
+ case "image":
45
+ case "link":
46
+ case "url":
47
+ case "toggle":
48
+ case "choice":
49
+ case "choices":
50
+ case "reference":
51
+ case "references":
52
+ case "group":
53
+ case "collection":
54
+ return void 0;
55
+ }
56
+ }
57
+
31
58
  // src/bridge/page-markers.ts
32
59
  var MARKER_SELECTOR = `[${FIELD_PATH_ATTRIBUTE}]`;
33
60
  var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
@@ -524,7 +551,7 @@ function caretRangeAt(document2, point) {
524
551
  }
525
552
 
526
553
  // src/bridge/rich-text-editing.ts
527
- var EDITABLE = "true";
554
+ var EDITABLE_AS_RICH_TEXT = "true";
528
555
  var PASTED_LINE_BREAKS = /\s*\n\s*/gu;
529
556
  var SPACE = " ";
530
557
  function canEditRichTextInPlace(element, value, isInline) {
@@ -636,7 +663,7 @@ function startRichTextEditing(element, options) {
636
663
  options.onSelect(void 0);
637
664
  options.onEnd(outcome);
638
665
  };
639
- element.setAttribute("contenteditable", EDITABLE);
666
+ element.setAttribute("contenteditable", EDITABLE_AS_RICH_TEXT);
640
667
  element.addEventListener("input", reportInput);
641
668
  element.addEventListener("keydown", pressKey);
642
669
  element.addEventListener("paste", pastePlainText);
@@ -708,9 +735,35 @@ function formatShortcutOf(event) {
708
735
  }
709
736
 
710
737
  // src/bridge/page-typing.ts
738
+ var PREPARED_TYPING_TIMEOUT_MS = 3e3;
739
+ var EDITABLE_VALUES = {
740
+ plain: EDITABLE_AS_PLAIN_TEXT,
741
+ rich: EDITABLE_AS_RICH_TEXT
742
+ };
711
743
  function createPageTyping(options) {
712
744
  let stopEditing;
713
745
  let richEditing;
746
+ let prepared;
747
+ const takePrepared = (isTyped) => {
748
+ if (prepared === void 0) return;
749
+ clearTimeout(prepared.timer);
750
+ if (!isTyped && stopEditing === void 0) {
751
+ prepared.element.blur();
752
+ prepared.element.removeAttribute("contenteditable");
753
+ }
754
+ prepared = void 0;
755
+ };
756
+ const prepare = (element, kind) => {
757
+ const isTypedAlready = element.hasAttribute("contenteditable");
758
+ if (isTypedAlready) return;
759
+ takePrepared(false);
760
+ element.setAttribute("contenteditable", EDITABLE_VALUES[kind]);
761
+ element.focus({ preventScroll: true });
762
+ const timer = setTimeout(() => {
763
+ takePrepared(false);
764
+ }, PREPARED_TYPING_TIMEOUT_MS);
765
+ prepared = { element, timer };
766
+ };
714
767
  const stop = () => {
715
768
  stopEditing?.();
716
769
  };
@@ -725,9 +778,11 @@ function createPageTyping(options) {
725
778
  const element = findMarkedElement(options.document, path);
726
779
  const canType = element !== void 0 && canEditTextInPlace(element, request.text);
727
780
  if (!canType) {
781
+ takePrepared(false);
728
782
  options.send({ type: "typing-refused", path });
729
783
  return;
730
784
  }
785
+ takePrepared(true);
731
786
  options.send({ type: "typing-started", path });
732
787
  stopEditing = startInlineTextEditing(element, {
733
788
  isSingleLine: request.isSingleLine,
@@ -745,9 +800,11 @@ function createPageTyping(options) {
745
800
  const element = findMarkedElement(options.document, path);
746
801
  const canType = element !== void 0 && canEditRichTextInPlace(element, request.text, isInline);
747
802
  if (!canType) {
803
+ takePrepared(false);
748
804
  options.send({ type: "typing-refused", path });
749
805
  return;
750
806
  }
807
+ takePrepared(true);
751
808
  options.send({ type: "typing-started", path });
752
809
  const editing = startRichTextEditing(element, {
753
810
  isInline,
@@ -765,6 +822,7 @@ function createPageTyping(options) {
765
822
  placeCaretAt(element, request.point);
766
823
  };
767
824
  return {
825
+ prepare,
768
826
  isTyping: () => stopEditing !== void 0,
769
827
  start,
770
828
  startRich,
@@ -832,6 +890,10 @@ function connectPage(document2, schema, send) {
832
890
  send({ type: "hover", path });
833
891
  },
834
892
  onClick: (pointer) => {
893
+ const kind = pointer === void 0 ? void 0 : typedKindAt(schema, pointer.path);
894
+ if (pointer !== void 0 && kind !== void 0) {
895
+ typing.prepare(pointer.element, kind);
896
+ }
835
897
  const target = pointer === void 0 ? void 0 : { path: pointer.path, point: pointer.point };
836
898
  send({ type: "click", target });
837
899
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamlet/astro",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
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",