@oiij/markdown-it 0.0.8 → 0.0.9

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.
@@ -1,15 +1,16 @@
1
1
  import markdownIt, { Options } from "markdown-it";
2
- import { Ref } from "vue";
2
+ import * as vue0 from "vue";
3
+ import { Ref, TemplateRef } from "vue";
3
4
 
4
5
  //#region src/index.d.ts
5
6
  type MarkDownItOptions = Options & {
6
7
  manual?: boolean;
7
8
  domPurify?: boolean;
8
9
  };
9
- declare function useMarkdownIt(defaultValue?: Ref<string> | string, options?: MarkDownItOptions): {
10
+ declare function useMarkdownIt(templateRef?: TemplateRef<HTMLElement>, defaultValue?: Ref<string> | string, options?: MarkDownItOptions): {
10
11
  value: Ref<string | undefined, string | undefined>;
11
12
  html: Ref<string, string>;
12
- domRef: Ref<HTMLElement | undefined, HTMLElement | undefined>;
13
+ templateRef: Readonly<vue0.ShallowRef<HTMLElement | null>> | undefined;
13
14
  md: markdownIt;
14
15
  render: (value: string) => string;
15
16
  };
@@ -3,27 +3,18 @@ import markdownIt from "markdown-it";
3
3
  import { isReactive, isRef, ref, toValue, watch, watchEffect } from "vue";
4
4
 
5
5
  //#region src/index.ts
6
- function useMarkdownIt(defaultValue, options) {
7
- const { manual = false, domPurify = true,..._options } = options ?? {};
6
+ function useMarkdownIt(templateRef, defaultValue, options) {
7
+ const { manual = false, domPurify = true, ..._options } = options ?? {};
8
8
  const value = ref(isRef(defaultValue) ? toValue(defaultValue.value) : isReactive(defaultValue) ? toValue(defaultValue) : defaultValue);
9
9
  if (isRef(defaultValue)) watchEffect(() => {
10
10
  value.value = toValue(defaultValue.value);
11
11
  });
12
12
  const html = ref("");
13
- const domRef = ref();
14
13
  const md = markdownIt({ ..._options });
15
14
  function render(value$1) {
16
15
  const mdValue = md.render(value$1);
17
16
  html.value = domPurify ? DOMPurify.sanitize(mdValue) : mdValue;
18
- if (domRef.value) domRef.value.innerHTML = html.value;
19
- else {
20
- const unWatch = watch(domRef, (v) => {
21
- if (v) {
22
- v.innerHTML = html.value;
23
- unWatch();
24
- }
25
- });
26
- }
17
+ if (templateRef && templateRef.value) templateRef.value.innerHTML = html.value;
27
18
  return html.value;
28
19
  }
29
20
  if (!manual) {
@@ -35,7 +26,7 @@ function useMarkdownIt(defaultValue, options) {
35
26
  return {
36
27
  value,
37
28
  html,
38
- domRef,
29
+ templateRef,
39
30
  md,
40
31
  render
41
32
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oiij/markdown-it",
3
3
  "type": "module",
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "description": "A Vue Composable for markdown-it",
6
6
  "author": "oiij",
7
7
  "license": "MIT",
@@ -16,16 +16,9 @@
16
16
  "markdown-it"
17
17
  ],
18
18
  "sideEffects": false,
19
- "exports": {
20
- ".": {
21
- "types": "./dist/index.d.ts",
22
- "import": "./dist/index.js",
23
- "require": "./dist/index.cjs"
24
- }
25
- },
26
- "main": "./dist/index.js",
27
- "module": "./dist/index.js",
28
- "types": "./dist/index.d.ts",
19
+ "main": "./dist/index.mjs",
20
+ "module": "./dist/index.mjs",
21
+ "types": "./dist/index.d.mts",
29
22
  "files": [
30
23
  "LICENSE",
31
24
  "README.md",
@@ -33,17 +26,17 @@
33
26
  "package.json"
34
27
  ],
35
28
  "peerDependencies": {
36
- "@vueuse/core": "^14.0.0",
37
- "dompurify": "^3.3.0",
29
+ "@vueuse/core": "^14.1.0",
30
+ "dompurify": "^3.3.1",
38
31
  "markdown-it": "^14.1.0",
39
- "vue": "^3.5.22"
32
+ "vue": "^3.5.25"
40
33
  },
41
34
  "devDependencies": {
42
35
  "@types/markdown-it": "^14.1.2",
43
- "@vueuse/core": "^14.0.0",
44
- "dompurify": "^3.3.0",
36
+ "@vueuse/core": "^14.1.0",
37
+ "dompurify": "^3.3.1",
45
38
  "markdown-it": "^14.1.0",
46
- "vue": "^3.5.22"
39
+ "vue": "^3.5.25"
47
40
  },
48
41
  "publishConfig": {
49
42
  "access": "public"
package/dist/index.cjs DELETED
@@ -1,71 +0,0 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- let dompurify = require("dompurify");
25
- dompurify = __toESM(dompurify);
26
- let markdown_it = require("markdown-it");
27
- markdown_it = __toESM(markdown_it);
28
- let vue = require("vue");
29
- vue = __toESM(vue);
30
-
31
- //#region src/index.ts
32
- function useMarkdownIt(defaultValue, options) {
33
- const { manual = false, domPurify = true,..._options } = options ?? {};
34
- const value = (0, vue.ref)((0, vue.isRef)(defaultValue) ? (0, vue.toValue)(defaultValue.value) : (0, vue.isReactive)(defaultValue) ? (0, vue.toValue)(defaultValue) : defaultValue);
35
- if ((0, vue.isRef)(defaultValue)) (0, vue.watchEffect)(() => {
36
- value.value = (0, vue.toValue)(defaultValue.value);
37
- });
38
- const html = (0, vue.ref)("");
39
- const domRef = (0, vue.ref)();
40
- const md = (0, markdown_it.default)({ ..._options });
41
- function render(value$1) {
42
- const mdValue = md.render(value$1);
43
- html.value = domPurify ? dompurify.default.sanitize(mdValue) : mdValue;
44
- if (domRef.value) domRef.value.innerHTML = html.value;
45
- else {
46
- const unWatch = (0, vue.watch)(domRef, (v) => {
47
- if (v) {
48
- v.innerHTML = html.value;
49
- unWatch();
50
- }
51
- });
52
- }
53
- return html.value;
54
- }
55
- if (!manual) {
56
- render(value.value ?? "");
57
- (0, vue.watch)(value, (v) => {
58
- render(v ?? "");
59
- });
60
- }
61
- return {
62
- value,
63
- html,
64
- domRef,
65
- md,
66
- render
67
- };
68
- }
69
-
70
- //#endregion
71
- exports.useMarkdownIt = useMarkdownIt;
package/dist/index.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import markdownIt, { Options } from "markdown-it";
2
- import { Ref } from "vue";
3
-
4
- //#region src/index.d.ts
5
- type MarkDownItOptions = Options & {
6
- manual?: boolean;
7
- domPurify?: boolean;
8
- };
9
- declare function useMarkdownIt(defaultValue?: Ref<string> | string, options?: MarkDownItOptions): {
10
- value: Ref<string | undefined, string | undefined>;
11
- html: Ref<string, string>;
12
- domRef: Ref<HTMLElement | undefined, HTMLElement | undefined>;
13
- md: markdownIt;
14
- render: (value: string) => string;
15
- };
16
- type MarkdownItReturns = ReturnType<typeof useMarkdownIt>;
17
- //#endregion
18
- export { MarkDownItOptions, MarkdownItReturns, useMarkdownIt };