@threadlabs/looma 0.53.11 → 0.53.12

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/docs/catalog.json CHANGED
@@ -780,7 +780,7 @@
780
780
  ],
781
781
  "schemaVersion": 1,
782
782
  "package": "@threadlabs/looma",
783
- "version": "0.53.11",
783
+ "version": "0.53.12",
784
784
  "groups": [
785
785
  {
786
786
  "id": "layout",
@@ -10432,7 +10432,7 @@ function getLoomaTableExtensions() {
10432
10432
  * the code and explicit language stay in the document schema.
10433
10433
  */
10434
10434
  function getDefaultEditorExtensions(options = {}) {
10435
- const { placeholder = "Type “/” for commands, or start writing…", linkOpenOnClick = false, linkBaseUrl, imageInline = false, imageNodeView, inlineImageNodeView, dividerNodeView, mention = createLoomaMentionExtension(), disableHighlight = false, codeLanguages, codeLowlight, codeBlockNodeView, tableOfContentsNodeView, expandNodeView, calloutNodeView } = options;
10435
+ const { placeholder = "Type “/” for commands, or start writing…", linkOpenOnClick = false, linkBaseUrl, imageInline = false, imageNodeView, inlineImageNodeView, dividerNodeView, headingNodeView, mention = createLoomaMentionExtension(), disableHighlight = false, codeLanguages, codeLowlight, codeBlockNodeView, tableOfContentsNodeView, expandNodeView, calloutNodeView } = options;
10436
10436
  const image = LoomaImage.configure({ inline: imageInline });
10437
10437
  const codeBlock = LoomaCodeBlock.configure({ lowlight: codeLowlight ?? createLowlight(codeLanguages) });
10438
10438
  return [
@@ -10450,7 +10450,7 @@ function getDefaultEditorExtensions(options = {}) {
10450
10450
  Italic,
10451
10451
  Strike,
10452
10452
  Underline,
10453
- LoomaHeading.configure({ levels: [
10453
+ (headingNodeView ? LoomaHeading.extend({ addNodeView: () => documentContentNodeView(headingNodeView) }) : LoomaHeading).configure({ levels: [
10454
10454
  1,
10455
10455
  2,
10456
10456
  3,
@@ -29,6 +29,8 @@ export interface DefaultEditorExtensionsOptions {
29
29
  inlineImageNodeView?: NodeViewRenderer;
30
30
  /** Optional selected-state UI for document dividers. */
31
31
  dividerNodeView?: NodeViewRenderer;
32
+ /** Optional copy-link presentation for headings with document anchors. */
33
+ headingNodeView?: NodeViewRenderer;
32
34
  /** Custom mention extension, the Looma default, or false to omit mentions. */
33
35
  mention?: AnyExtension | false;
34
36
  /**
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copy affordance for an existing heading anchor.
3
+ * @ownership The caller appends `dom` beside heading content and calls `destroy` on removal.
4
+ * The current ID and page URL are read at activation, so edits and client navigation cannot leave a stale link.
5
+ */
6
+ export declare function createHeadingLink(heading: HTMLElement): {
7
+ dom: HTMLElement;
8
+ destroy(): void;
9
+ };
package/editor/index.js CHANGED
@@ -11930,6 +11930,126 @@ var tableOfContentsNodeView = ({ editor, node, getPos }) => {
11930
11930
  };
11931
11931
  };
11932
11932
  //#endregion
11933
+ //#region src/editor/heading-link.ts
11934
+ var sequence = 0;
11935
+ /**
11936
+ * Copy affordance for an existing heading anchor.
11937
+ * @ownership The caller appends `dom` beside heading content and calls `destroy` on removal.
11938
+ * The current ID and page URL are read at activation, so edits and client navigation cannot leave a stale link.
11939
+ */
11940
+ function createHeadingLink(heading) {
11941
+ const id = `looma-heading-link-${++sequence}`;
11942
+ const icon = element(createUiIcon({
11943
+ name: "link",
11944
+ attributes: { "aria-hidden": "true" }
11945
+ }));
11946
+ const button = element(createUiIconButton({
11947
+ label: "Copy link",
11948
+ size: "sm",
11949
+ variant: "ghost",
11950
+ tone: "neutral",
11951
+ anticipatory: true,
11952
+ attributes: { id },
11953
+ children: [icon]
11954
+ }));
11955
+ const label = heading.ownerDocument.createTextNode("Copy link");
11956
+ const tooltip = element(createUiTooltip({
11957
+ for: id,
11958
+ children: [label],
11959
+ attributes: { "aria-live": "polite" }
11960
+ }));
11961
+ const dom = element(createUiAffordanceScope({
11962
+ guide: "none",
11963
+ attributes: {
11964
+ contenteditable: "false",
11965
+ "data-looma-heading-link": ""
11966
+ },
11967
+ children: [button, tooltip]
11968
+ }));
11969
+ let timer;
11970
+ let destroyed = false;
11971
+ let copying = false;
11972
+ const reveal = () => componentRegistry.update(button, { revealed: true });
11973
+ const conceal = () => componentRegistry.update(button, { revealed: false });
11974
+ const feedback = (copied) => {
11975
+ const text = copied ? "Link copied" : "Could not copy link";
11976
+ label.textContent = text;
11977
+ componentRegistry.update(button, { label: text });
11978
+ componentRegistry.update(icon, { name: copied ? "check" : "link" });
11979
+ componentRegistry.update(tooltip, { open: true });
11980
+ clearTimeout(timer);
11981
+ timer = setTimeout(() => {
11982
+ label.textContent = "Copy link";
11983
+ componentRegistry.update(button, { label: "Copy link" });
11984
+ componentRegistry.update(icon, { name: "link" });
11985
+ componentRegistry.update(tooltip, { open: false });
11986
+ }, 2e3);
11987
+ };
11988
+ const copy = async (event) => {
11989
+ event.preventDefault();
11990
+ event.stopPropagation();
11991
+ if (copying || !heading.id) return;
11992
+ copying = true;
11993
+ try {
11994
+ const url = new URL(heading.ownerDocument.defaultView.location.href);
11995
+ url.hash = encodeURIComponent(heading.id);
11996
+ await heading.ownerDocument.defaultView.navigator.clipboard.writeText(url.href);
11997
+ if (!destroyed) feedback(true);
11998
+ } catch {
11999
+ if (!destroyed) feedback(false);
12000
+ } finally {
12001
+ copying = false;
12002
+ }
12003
+ };
12004
+ const preserveSelection = (event) => event.preventDefault();
12005
+ heading.addEventListener("pointerenter", reveal);
12006
+ heading.addEventListener("pointerleave", conceal);
12007
+ button.addEventListener("pointerdown", preserveSelection);
12008
+ button.addEventListener("click", copy);
12009
+ return {
12010
+ dom,
12011
+ destroy() {
12012
+ destroyed = true;
12013
+ clearTimeout(timer);
12014
+ heading.removeEventListener("pointerenter", reveal);
12015
+ heading.removeEventListener("pointerleave", conceal);
12016
+ button.removeEventListener("pointerdown", preserveSelection);
12017
+ button.removeEventListener("click", copy);
12018
+ }
12019
+ };
12020
+ }
12021
+ //#endregion
12022
+ //#region src/editor/node-views/heading.ts
12023
+ /** The content span belongs to ProseMirror; the copy control never enters saved HTML or JSON. */
12024
+ var headingNodeView = ({ node }) => {
12025
+ let current = node;
12026
+ const dom = document.createElement(`h${node.attrs.level}`);
12027
+ const contentDOM = document.createElement("span");
12028
+ const link = createHeadingLink(dom);
12029
+ const updateAnchor = () => {
12030
+ if (current.attrs.id) dom.id = String(current.attrs.id);
12031
+ else dom.removeAttribute("id");
12032
+ if (current.attrs.align) dom.setAttribute("align", String(current.attrs.align));
12033
+ else dom.removeAttribute("align");
12034
+ link.dom.hidden = !current.attrs.id;
12035
+ };
12036
+ updateAnchor();
12037
+ dom.append(contentDOM, link.dom);
12038
+ return {
12039
+ dom,
12040
+ contentDOM,
12041
+ update(next) {
12042
+ if (next.type !== current.type || next.attrs.level !== current.attrs.level) return false;
12043
+ current = next;
12044
+ updateAnchor();
12045
+ return true;
12046
+ },
12047
+ stopEvent: (event) => event.target instanceof Node && link.dom.contains(event.target),
12048
+ ignoreMutation: (mutation) => mutation.type !== "selection" && link.dom.contains(mutation.target),
12049
+ destroy: link.destroy
12050
+ };
12051
+ };
12052
+ //#endregion
11933
12053
  //#region components/shared/form-reset.js
11934
12054
  /**
11935
12055
  * Calls back once a form reset has restored `control`'s form to its defaults. The browser restores
@@ -15651,6 +15771,7 @@ function createDocumentEditorSession(props, options) {
15651
15771
  codeLanguages: props.codeLanguages ?? void 0,
15652
15772
  codeLowlight: highlighting.lowlight,
15653
15773
  tableOfContentsNodeView,
15774
+ headingNodeView,
15654
15775
  expandNodeView,
15655
15776
  dividerNodeView,
15656
15777
  calloutNodeView,
@@ -0,0 +1,3 @@
1
+ import type { NodeViewRenderer } from "@tiptap/core";
2
+ /** The content span belongs to ProseMirror; the copy control never enters saved HTML or JSON. */
3
+ export declare const headingNodeView: NodeViewRenderer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadlabs/looma",
3
- "version": "0.53.11",
3
+ "version": "0.53.12",
4
4
  "type": "module",
5
5
  "description": "HTML Next UI components, native DOM support and design tokens.",
6
6
  "license": "MIT",