@segnavia/markdown-editor 0.42.0 → 0.44.0

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.
@@ -0,0 +1,8 @@
1
+ //#region src/element-properties.d.ts
2
+ export declare const MARKDOWN_EDITOR_TAG = "segnavia-markdown-editor";
3
+ export declare const MARKDOWN_EDITOR_PROPERTIES: {
4
+ readonly tag: "segnavia-markdown-editor";
5
+ readonly properties: readonly ["markdown", "mode", "title", "titleSource", "lockedFences", "css", "fonts", "fontReferences", "linkOrigins", "alertLabels"];
6
+ readonly events: readonly ["segnavia-markdown-change", "segnavia-title-change", "segnavia-mode-change", "segnavia-save", "segnavia-editor-state", "segnavia-link-request"];
7
+ };
8
+ //#endregion
@@ -0,0 +1,27 @@
1
+ //#region src/element-properties.ts
2
+ const MARKDOWN_EDITOR_TAG = "segnavia-markdown-editor";
3
+ const MARKDOWN_EDITOR_PROPERTIES = {
4
+ tag: MARKDOWN_EDITOR_TAG,
5
+ properties: [
6
+ "markdown",
7
+ "mode",
8
+ "title",
9
+ "titleSource",
10
+ "lockedFences",
11
+ "css",
12
+ "fonts",
13
+ "fontReferences",
14
+ "linkOrigins",
15
+ "alertLabels"
16
+ ],
17
+ events: [
18
+ "segnavia-markdown-change",
19
+ "segnavia-title-change",
20
+ "segnavia-mode-change",
21
+ "segnavia-save",
22
+ "segnavia-editor-state",
23
+ "segnavia-link-request"
24
+ ]
25
+ };
26
+ //#endregion
27
+ export { MARKDOWN_EDITOR_PROPERTIES, MARKDOWN_EDITOR_TAG };
@@ -0,0 +1,14 @@
1
+ import { setModelTitle } from "./markdown-editor-model.js";
2
+ //#region src/markdown-editor-title.ts
3
+ function updateMarkdownEditorTitle(model, value, source) {
4
+ return {
5
+ model: setModelTitle(model, value),
6
+ removeTitleAttribute: source === "attribute"
7
+ };
8
+ }
9
+ function renderMarkdownEditorTitle(field, model) {
10
+ field.hidden = model.titleSource === "separate" && model.title === null;
11
+ field.value = model.title ?? "";
12
+ }
13
+ //#endregion
14
+ export { renderMarkdownEditorTitle, updateMarkdownEditorTitle };
@@ -1,6 +1,7 @@
1
1
  import { MarkdownTitleSource } from "./markdown-editor-model.js";
2
2
  import { MARKDOWN_EDITOR_COMMANDS, MARKDOWN_EDITOR_MODES, MarkdownEditorCommand, MarkdownEditorMode } from "./markdown-editor-policy.js";
3
3
  import { MarkdownEditorStateDetail, SegnaviaMarkdownEditor as SegnaviaMarkdownEditor$1 } from "./markdown-editor-types.js";
4
+ import { MARKDOWN_EDITOR_PROPERTIES, MARKDOWN_EDITOR_TAG } from "./element-properties.js";
4
5
  import { joinLeadingHeading, normalizeMarkdownTitle, splitLeadingHeading } from "./markdown-title.js";
5
6
  import { FontsOptions } from "@segnavia/frame/fonts";
6
7
  //#region src/markdown-editor.d.ts
@@ -9,4 +10,4 @@ export declare const SegnaviaMarkdownEditor: {
9
10
  new (): SegnaviaMarkdownEditor;
10
11
  };
11
12
  //#endregion
12
- export { type FontsOptions, MARKDOWN_EDITOR_COMMANDS, MARKDOWN_EDITOR_MODES, type MarkdownEditorCommand, type MarkdownEditorMode, type MarkdownEditorStateDetail, type MarkdownTitleSource, joinLeadingHeading, normalizeMarkdownTitle, splitLeadingHeading };
13
+ export { type FontsOptions, MARKDOWN_EDITOR_COMMANDS, MARKDOWN_EDITOR_MODES, MARKDOWN_EDITOR_PROPERTIES, MARKDOWN_EDITOR_TAG, type MarkdownEditorCommand, type MarkdownEditorMode, type MarkdownEditorStateDetail, type MarkdownTitleSource, joinLeadingHeading, normalizeMarkdownTitle, splitLeadingHeading };
@@ -1,24 +1,27 @@
1
1
  import { ensureEditorStyle } from "./editor-style.js";
2
+ import { MARKDOWN_EDITOR_PROPERTIES, MARKDOWN_EDITOR_TAG } from "./element-properties.js";
2
3
  import { MarkdownEditorFontRegistration } from "./markdown-editor-font-registration.js";
3
4
  import { validateMarkdownLink } from "./markdown-editor-link.js";
4
5
  import { joinLeadingHeading, normalizeMarkdownTitle, splitLeadingHeading } from "./markdown-title.js";
5
6
  import { markdownEditorModel, setModelEditable, setModelMarkdown, setModelTitle, setModelTitleSource } from "./markdown-editor-model.js";
6
7
  import { equalAlertLabels, equalFontReferences, equalFonts, equalLockedFences, normalizeAlertLabels, normalizeFontReferences, normalizeLockedFences } from "./markdown-editor-options.js";
7
8
  import { MARKDOWN_EDITOR_COMMANDS, MARKDOWN_EDITOR_MODES, availableMarkdownMode, markdownEditorKeyAction, richModeCommandRefusal } from "./markdown-editor-policy.js";
9
+ import { renderMarkdownEditorTitle, updateMarkdownEditorTitle } from "./markdown-editor-title.js";
8
10
  import { RICH_COMMANDS, lockedBlockSourceOffset, richEditorState, selectedLockedBlock } from "./markdown-rich-commands.js";
9
11
  import { mountRichEditor } from "./markdown-rich-editor.js";
10
12
  import { parseRichDocument, saveRichDocument } from "./markdown-rich-save.js";
11
13
  import { markdownSourceState } from "./markdown-source.js";
12
14
  import { redo, redoDepth, undo, undoDepth } from "@codemirror/commands";
13
15
  import { EditorView } from "@codemirror/view";
16
+ import { upgradeProperties } from "@segnavia/frame/element-properties";
14
17
  import { sanitizeBookCss } from "@segnavia/html";
15
18
  //#region src/markdown-editor.ts
16
- const TAG = "segnavia-markdown-editor";
17
19
  const COMMAND_NAMES = new Set(MARKDOWN_EDITOR_COMMANDS.map(({ name }) => name));
18
20
  var MarkdownEditorElement = class extends HTMLElement {
19
21
  static observedAttributes = [
20
22
  "markdown",
21
23
  "mode",
24
+ "title",
22
25
  "title-source"
23
26
  ];
24
27
  root = this.attachShadow({ mode: "open" });
@@ -43,6 +46,7 @@ var MarkdownEditorElement = class extends HTMLElement {
43
46
  fontRegistration = new MarkdownEditorFontRegistration(this);
44
47
  constructor() {
45
48
  super();
49
+ upgradeProperties(this);
46
50
  this.container.part.add("editor");
47
51
  this.titleField.part.add("title");
48
52
  this.titleField.type = "text";
@@ -59,7 +63,7 @@ var MarkdownEditorElement = class extends HTMLElement {
59
63
  this.titleField.addEventListener("keydown", this.onTitleKeyDown);
60
64
  this.titleField.addEventListener("paste", this.onTitlePaste);
61
65
  this.mountMode();
62
- this.renderTitle();
66
+ renderMarkdownEditorTitle(this.titleField, this.model);
63
67
  }
64
68
  disconnectedCallback() {
65
69
  this.titleField.removeEventListener("input", this.onTitleInput);
@@ -75,7 +79,10 @@ var MarkdownEditorElement = class extends HTMLElement {
75
79
  if (this.reflecting) return;
76
80
  if (name === "markdown") this.markdown = value ?? "";
77
81
  else if (name === "mode") this.mode = value;
78
- else this.titleSource = value === "leading-heading" ? "leading-heading" : "separate";
82
+ else if (name === "title") {
83
+ if (value === null) return;
84
+ this.setTitle(value, "attribute");
85
+ } else this.titleSource = value === "leading-heading" ? "leading-heading" : "separate";
79
86
  }
80
87
  get markdown() {
81
88
  return this.model.markdown;
@@ -85,7 +92,7 @@ var MarkdownEditorElement = class extends HTMLElement {
85
92
  if (model === this.model) return;
86
93
  this.model = model;
87
94
  this.richOriginal = model.editable;
88
- this.renderTitle();
95
+ renderMarkdownEditorTitle(this.titleField, this.model);
89
96
  this.resetVisibleEditor();
90
97
  }
91
98
  get mode() {
@@ -101,11 +108,15 @@ var MarkdownEditorElement = class extends HTMLElement {
101
108
  return this.model.title;
102
109
  }
103
110
  set title(value) {
104
- const model = setModelTitle(this.model, value);
111
+ this.setTitle(value, "property");
112
+ }
113
+ setTitle(value, source) {
114
+ const { model, removeTitleAttribute } = updateMarkdownEditorTitle(this.model, value, source);
105
115
  if (model !== this.model) {
106
116
  this.model = model;
107
- this.renderTitle();
117
+ renderMarkdownEditorTitle(this.titleField, this.model);
108
118
  }
119
+ if (removeTitleAttribute) this.reflect("title", null);
109
120
  }
110
121
  get titleSource() {
111
122
  return this.model.titleSource;
@@ -117,7 +128,7 @@ var MarkdownEditorElement = class extends HTMLElement {
117
128
  this.reflect("title-source", next === "separate" ? null : next);
118
129
  this.model = model;
119
130
  this.richOriginal = model.editable;
120
- this.renderTitle();
131
+ renderMarkdownEditorTitle(this.titleField, this.model);
121
132
  this.resetVisibleEditor();
122
133
  }
123
134
  get lockedFences() {
@@ -305,10 +316,6 @@ var MarkdownEditorElement = class extends HTMLElement {
305
316
  this.titleField.setRangeText(normalizeMarkdownTitle(pasted), this.titleField.selectionStart ?? 0, this.titleField.selectionEnd ?? 0, "end");
306
317
  this.onTitleInput();
307
318
  };
308
- renderTitle() {
309
- this.titleField.hidden = this.model.titleSource === "separate" && this.model.title === null;
310
- this.titleField.value = this.model.title ?? "";
311
- }
312
319
  emitSourceState(canUndo = this.sourceView ? undoDepth(this.sourceView.state) > 0 : false, canRedo = this.sourceView ? redoDepth(this.sourceView.state) > 0 : false) {
313
320
  this.emitState({
314
321
  marks: [],
@@ -343,6 +350,6 @@ var MarkdownEditorElement = class extends HTMLElement {
343
350
  }
344
351
  };
345
352
  const SegnaviaMarkdownEditor = MarkdownEditorElement;
346
- if (!customElements.get(TAG)) customElements.define(TAG, SegnaviaMarkdownEditor);
353
+ if (!customElements.get("segnavia-markdown-editor")) customElements.define(MARKDOWN_EDITOR_TAG, SegnaviaMarkdownEditor);
347
354
  //#endregion
348
- export { MARKDOWN_EDITOR_COMMANDS, MARKDOWN_EDITOR_MODES, SegnaviaMarkdownEditor, joinLeadingHeading, normalizeMarkdownTitle, splitLeadingHeading };
355
+ export { MARKDOWN_EDITOR_COMMANDS, MARKDOWN_EDITOR_MODES, MARKDOWN_EDITOR_PROPERTIES, MARKDOWN_EDITOR_TAG, SegnaviaMarkdownEditor, joinLeadingHeading, normalizeMarkdownTitle, splitLeadingHeading };
package/dist/vue.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { MarkdownEditorMode } from "./markdown-editor-policy.js";
2
+ import { MarkdownEditorStateDetail } from "./markdown-editor-types.js";
3
+ import { MARKDOWN_EDITOR_PROPERTIES } from "./element-properties.js";
4
+ import { SegnaviaMarkdownEditor } from "./markdown-editor.js";
5
+ import { EventProps } from "@segnavia/frame/vue-types";
6
+ import { DefineComponent } from "vue";
7
+ //#region src/vue.d.ts
8
+ export interface MarkdownEditorVueEventDetails {
9
+ 'segnavia-markdown-change': {
10
+ markdown: string;
11
+ };
12
+ 'segnavia-title-change': {
13
+ title: string;
14
+ };
15
+ 'segnavia-mode-change': {
16
+ mode: MarkdownEditorMode;
17
+ };
18
+ 'segnavia-save': unknown;
19
+ 'segnavia-editor-state': MarkdownEditorStateDetail;
20
+ 'segnavia-link-request': {
21
+ href: string | null;
22
+ };
23
+ }
24
+ type MarkdownEditorComponent = Partial<Pick<SegnaviaMarkdownEditor, (typeof MARKDOWN_EDITOR_PROPERTIES.properties)[number]>> & EventProps<typeof MARKDOWN_EDITOR_PROPERTIES.events, MarkdownEditorVueEventDetails>;
25
+ type MarkdownEditorGlobalComponents = { [Tag in typeof MARKDOWN_EDITOR_PROPERTIES.tag]: DefineComponent<MarkdownEditorComponent>; };
26
+ declare module 'vue' {
27
+ interface GlobalComponents extends MarkdownEditorGlobalComponents {}
28
+ }
29
+ //#endregion
package/dist/vue.js ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segnavia/markdown-editor",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,12 +28,17 @@
28
28
  "@segnavia/source": "./src/markdown-editor.ts",
29
29
  "types": "./dist/markdown-editor.d.ts",
30
30
  "default": "./dist/markdown-editor.js"
31
+ },
32
+ "./vue": {
33
+ "@segnavia/source": "./src/vue.ts",
34
+ "types": "./dist/vue.d.ts",
35
+ "default": "./dist/vue.js"
31
36
  }
32
37
  },
33
38
  "dependencies": {
34
- "@segnavia/format": "0.42.0",
35
- "@segnavia/frame": "0.42.0",
36
- "@segnavia/html": "0.42.0"
39
+ "@segnavia/format": "0.44.0",
40
+ "@segnavia/frame": "0.44.0",
41
+ "@segnavia/html": "0.44.0"
37
42
  },
38
43
  "peerDependencies": {
39
44
  "@codemirror/commands": "^6.11.1",