@jihua/bytemd-vue-next 0.0.0-stage → 1.22.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Rongjian Zhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,6 @@
1
- # Temporary Holding Version
1
+ # ByteMD
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Unofficial fork.** This package is an unofficial fork of ByteMD, not the official `bytemd` package, and is not affiliated with or endorsed by the original project.
4
+
5
+
6
+ https://github.com/bytedance/bytemd
package/async.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/async'
package/async.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/async.js')
package/async.mjs ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/async.mjs'
@@ -0,0 +1,111 @@
1
+ import { type Component } from 'vue';
2
+ export interface AsyncEditorLoaderResult {
3
+ default: Component;
4
+ }
5
+ export interface AsyncEditorOptions {
6
+ /** Custom module loader, mainly for tests or pre-bundled builds. */
7
+ loader?: () => Promise<any>;
8
+ /** Load timeout in milliseconds. Defaults to 30000. */
9
+ timeout?: number;
10
+ }
11
+ /**
12
+ * Editor loader that never runs during SSR: `onMounted` starts the request,
13
+ * so the server only renders the sized placeholder below.
14
+ */
15
+ export declare function createAsyncEditor({ loader, timeout, }?: AsyncEditorOptions): import("vue").DefineComponent<import("vue").ExtractPropTypes<{
16
+ /** Reserved height while the editor chunk loads; avoids layout shift. */
17
+ placeholderHeight: {
18
+ type: (NumberConstructor | StringConstructor)[];
19
+ default: number;
20
+ };
21
+ loadingText: {
22
+ type: StringConstructor;
23
+ default: string;
24
+ };
25
+ errorText: {
26
+ type: StringConstructor;
27
+ default: string;
28
+ };
29
+ retryText: {
30
+ type: StringConstructor;
31
+ default: string;
32
+ };
33
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
34
+ [key: string]: any;
35
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("ready" | "error")[], "ready" | "error", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
36
+ /** Reserved height while the editor chunk loads; avoids layout shift. */
37
+ placeholderHeight: {
38
+ type: (NumberConstructor | StringConstructor)[];
39
+ default: number;
40
+ };
41
+ loadingText: {
42
+ type: StringConstructor;
43
+ default: string;
44
+ };
45
+ errorText: {
46
+ type: StringConstructor;
47
+ default: string;
48
+ };
49
+ retryText: {
50
+ type: StringConstructor;
51
+ default: string;
52
+ };
53
+ }>> & Readonly<{
54
+ onReady?: ((...args: any[]) => any) | undefined;
55
+ onError?: ((...args: any[]) => any) | undefined;
56
+ }>, {
57
+ placeholderHeight: string | number;
58
+ loadingText: string;
59
+ errorText: string;
60
+ retryText: string;
61
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
62
+ /** Lazy-loaded Editor. Import from `@jihua/bytemd-vue-next/async` to keep it out
63
+ * of the initial bundle; the placeholder reserves space during the request. */
64
+ export declare const AsyncEditor: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
65
+ /** Reserved height while the editor chunk loads; avoids layout shift. */
66
+ placeholderHeight: {
67
+ type: (NumberConstructor | StringConstructor)[];
68
+ default: number;
69
+ };
70
+ loadingText: {
71
+ type: StringConstructor;
72
+ default: string;
73
+ };
74
+ errorText: {
75
+ type: StringConstructor;
76
+ default: string;
77
+ };
78
+ retryText: {
79
+ type: StringConstructor;
80
+ default: string;
81
+ };
82
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
83
+ [key: string]: any;
84
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("ready" | "error")[], "ready" | "error", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
85
+ /** Reserved height while the editor chunk loads; avoids layout shift. */
86
+ placeholderHeight: {
87
+ type: (NumberConstructor | StringConstructor)[];
88
+ default: number;
89
+ };
90
+ loadingText: {
91
+ type: StringConstructor;
92
+ default: string;
93
+ };
94
+ errorText: {
95
+ type: StringConstructor;
96
+ default: string;
97
+ };
98
+ retryText: {
99
+ type: StringConstructor;
100
+ default: string;
101
+ };
102
+ }>> & Readonly<{
103
+ onReady?: ((...args: any[]) => any) | undefined;
104
+ onError?: ((...args: any[]) => any) | undefined;
105
+ }>, {
106
+ placeholderHeight: string | number;
107
+ loadingText: string;
108
+ errorText: string;
109
+ retryText: string;
110
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
111
+ export default AsyncEditor;
package/dist/async.js ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const vue = require("vue");
4
+ function createAsyncEditor({
5
+ loader = () => Promise.resolve().then(() => require("./chunks/editor-D69QOIpJ.js")),
6
+ timeout = 3e4
7
+ } = {}) {
8
+ return vue.defineComponent({
9
+ name: "AsyncByteMDEditor",
10
+ inheritAttrs: false,
11
+ props: {
12
+ /** Reserved height while the editor chunk loads; avoids layout shift. */
13
+ placeholderHeight: { type: [Number, String], default: 360 },
14
+ loadingText: { type: String, default: "Loading editor…" },
15
+ errorText: { type: String, default: "Editor failed to load." },
16
+ retryText: { type: String, default: "Retry" }
17
+ },
18
+ emits: ["ready", "error"],
19
+ setup(props, { attrs, emit, slots }) {
20
+ const component = vue.shallowRef();
21
+ const failed = vue.ref();
22
+ let active = true;
23
+ let timer;
24
+ let request = 0;
25
+ const clearTimer = () => {
26
+ if (timer) clearTimeout(timer);
27
+ timer = void 0;
28
+ };
29
+ const start = () => {
30
+ if (component.value || !active) return;
31
+ failed.value = void 0;
32
+ const current = ++request;
33
+ clearTimer();
34
+ timer = setTimeout(() => {
35
+ if (active && current === request && !component.value) {
36
+ request++;
37
+ failed.value = new Error("Editor load timed out.");
38
+ emit("error", failed.value);
39
+ }
40
+ }, timeout);
41
+ Promise.resolve().then(loader).then((module2) => {
42
+ if (!active || current !== request) return;
43
+ clearTimer();
44
+ component.value = module2.default;
45
+ emit("ready");
46
+ }).catch((error) => {
47
+ if (!active || current !== request) return;
48
+ clearTimer();
49
+ failed.value = error;
50
+ emit("error", error);
51
+ });
52
+ };
53
+ const retry = () => {
54
+ if (!active) return;
55
+ failed.value = void 0;
56
+ start();
57
+ };
58
+ vue.onMounted(start);
59
+ vue.onBeforeUnmount(() => {
60
+ active = false;
61
+ request++;
62
+ clearTimer();
63
+ });
64
+ return () => {
65
+ if (component.value)
66
+ return vue.h(component.value, { ...attrs, key: "editor" });
67
+ if (failed.value) {
68
+ return vue.h(
69
+ "div",
70
+ {
71
+ class: "bytemd-async-error",
72
+ role: "alert",
73
+ style: {
74
+ minHeight: typeof props.placeholderHeight === "number" ? `${props.placeholderHeight}px` : props.placeholderHeight
75
+ }
76
+ },
77
+ [
78
+ vue.h("p", props.errorText),
79
+ vue.h(
80
+ "button",
81
+ {
82
+ type: "button",
83
+ class: "bytemd-async-retry",
84
+ onClick: retry
85
+ },
86
+ props.retryText
87
+ )
88
+ ]
89
+ );
90
+ }
91
+ return vue.h(
92
+ "div",
93
+ {
94
+ class: "bytemd-async-placeholder",
95
+ role: "status",
96
+ "aria-busy": "true",
97
+ style: {
98
+ minHeight: typeof props.placeholderHeight === "number" ? `${props.placeholderHeight}px` : props.placeholderHeight
99
+ }
100
+ },
101
+ slots.loading ? slots.loading() : [vue.h("p", props.loadingText)]
102
+ );
103
+ };
104
+ }
105
+ });
106
+ }
107
+ const AsyncEditor = createAsyncEditor();
108
+ exports.AsyncEditor = AsyncEditor;
109
+ exports.createAsyncEditor = createAsyncEditor;
110
+ exports.default = AsyncEditor;
package/dist/async.mjs ADDED
@@ -0,0 +1,110 @@
1
+ import { defineComponent, shallowRef, ref, onMounted, onBeforeUnmount, h } from "vue";
2
+ function createAsyncEditor({
3
+ loader = () => import("./chunks/editor-DDwhN-P8.mjs"),
4
+ timeout = 3e4
5
+ } = {}) {
6
+ return defineComponent({
7
+ name: "AsyncByteMDEditor",
8
+ inheritAttrs: false,
9
+ props: {
10
+ /** Reserved height while the editor chunk loads; avoids layout shift. */
11
+ placeholderHeight: { type: [Number, String], default: 360 },
12
+ loadingText: { type: String, default: "Loading editor…" },
13
+ errorText: { type: String, default: "Editor failed to load." },
14
+ retryText: { type: String, default: "Retry" }
15
+ },
16
+ emits: ["ready", "error"],
17
+ setup(props, { attrs, emit, slots }) {
18
+ const component = shallowRef();
19
+ const failed = ref();
20
+ let active = true;
21
+ let timer;
22
+ let request = 0;
23
+ const clearTimer = () => {
24
+ if (timer) clearTimeout(timer);
25
+ timer = void 0;
26
+ };
27
+ const start = () => {
28
+ if (component.value || !active) return;
29
+ failed.value = void 0;
30
+ const current = ++request;
31
+ clearTimer();
32
+ timer = setTimeout(() => {
33
+ if (active && current === request && !component.value) {
34
+ request++;
35
+ failed.value = new Error("Editor load timed out.");
36
+ emit("error", failed.value);
37
+ }
38
+ }, timeout);
39
+ Promise.resolve().then(loader).then((module) => {
40
+ if (!active || current !== request) return;
41
+ clearTimer();
42
+ component.value = module.default;
43
+ emit("ready");
44
+ }).catch((error) => {
45
+ if (!active || current !== request) return;
46
+ clearTimer();
47
+ failed.value = error;
48
+ emit("error", error);
49
+ });
50
+ };
51
+ const retry = () => {
52
+ if (!active) return;
53
+ failed.value = void 0;
54
+ start();
55
+ };
56
+ onMounted(start);
57
+ onBeforeUnmount(() => {
58
+ active = false;
59
+ request++;
60
+ clearTimer();
61
+ });
62
+ return () => {
63
+ if (component.value)
64
+ return h(component.value, { ...attrs, key: "editor" });
65
+ if (failed.value) {
66
+ return h(
67
+ "div",
68
+ {
69
+ class: "bytemd-async-error",
70
+ role: "alert",
71
+ style: {
72
+ minHeight: typeof props.placeholderHeight === "number" ? `${props.placeholderHeight}px` : props.placeholderHeight
73
+ }
74
+ },
75
+ [
76
+ h("p", props.errorText),
77
+ h(
78
+ "button",
79
+ {
80
+ type: "button",
81
+ class: "bytemd-async-retry",
82
+ onClick: retry
83
+ },
84
+ props.retryText
85
+ )
86
+ ]
87
+ );
88
+ }
89
+ return h(
90
+ "div",
91
+ {
92
+ class: "bytemd-async-placeholder",
93
+ role: "status",
94
+ "aria-busy": "true",
95
+ style: {
96
+ minHeight: typeof props.placeholderHeight === "number" ? `${props.placeholderHeight}px` : props.placeholderHeight
97
+ }
98
+ },
99
+ slots.loading ? slots.loading() : [h("p", props.loadingText)]
100
+ );
101
+ };
102
+ }
103
+ });
104
+ }
105
+ const AsyncEditor = createAsyncEditor();
106
+ export {
107
+ AsyncEditor,
108
+ createAsyncEditor,
109
+ AsyncEditor as default
110
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vue = require("vue");
4
+ const bytemd = require("@jihua/bytemd");
5
+ const _sfc_main = vue.defineComponent({
6
+ props: {
7
+ value: { type: String, default: "" },
8
+ plugins: { type: Array, default: () => [] },
9
+ sanitize: Function,
10
+ remarkRehype: Object,
11
+ headingIds: { type: [Boolean, Object], default: true },
12
+ mode: { type: String, default: "auto" },
13
+ previewDebounce: { type: Number, default: 300 },
14
+ layoutContainment: { type: Boolean, default: false },
15
+ placeholder: String,
16
+ editorConfig: Object,
17
+ locale: Object,
18
+ uploadImages: Function,
19
+ maxLength: { type: Number, default: Infinity },
20
+ overridePreview: Function,
21
+ renderer: Function
22
+ },
23
+ emits: ["change"],
24
+ setup(props, { emit }) {
25
+ const el = vue.ref(null);
26
+ let editor2 = null;
27
+ let unsubscribe;
28
+ vue.watch(
29
+ () => props,
30
+ (newValue) => {
31
+ editor2 == null ? void 0 : editor2.$set({ ...newValue });
32
+ },
33
+ { deep: true }
34
+ );
35
+ vue.onMounted(() => {
36
+ const instance = new bytemd.Editor({
37
+ target: el.value,
38
+ props
39
+ });
40
+ unsubscribe = instance.$on("change", (e) => {
41
+ emit("change", e.detail.value);
42
+ });
43
+ editor2 = instance;
44
+ });
45
+ vue.onBeforeUnmount(() => {
46
+ unsubscribe == null ? void 0 : unsubscribe();
47
+ editor2 == null ? void 0 : editor2.$destroy();
48
+ editor2 = null;
49
+ });
50
+ return { el };
51
+ }
52
+ });
53
+ const _export_sfc = (sfc, props) => {
54
+ const target = sfc.__vccOpts || sfc;
55
+ for (const [key, val] of props) {
56
+ target[key] = val;
57
+ }
58
+ return target;
59
+ };
60
+ const _hoisted_1 = { ref: "el" };
61
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
62
+ return vue.openBlock(), vue.createElementBlock(
63
+ "div",
64
+ _hoisted_1,
65
+ null,
66
+ 512
67
+ /* NEED_PATCH */
68
+ );
69
+ }
70
+ const editor = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
71
+ exports.default = editor;
@@ -0,0 +1,71 @@
1
+ import { defineComponent, ref, watch, onMounted, onBeforeUnmount, openBlock, createElementBlock } from "vue";
2
+ import { Editor } from "@jihua/bytemd";
3
+ const _sfc_main = defineComponent({
4
+ props: {
5
+ value: { type: String, default: "" },
6
+ plugins: { type: Array, default: () => [] },
7
+ sanitize: Function,
8
+ remarkRehype: Object,
9
+ headingIds: { type: [Boolean, Object], default: true },
10
+ mode: { type: String, default: "auto" },
11
+ previewDebounce: { type: Number, default: 300 },
12
+ layoutContainment: { type: Boolean, default: false },
13
+ placeholder: String,
14
+ editorConfig: Object,
15
+ locale: Object,
16
+ uploadImages: Function,
17
+ maxLength: { type: Number, default: Infinity },
18
+ overridePreview: Function,
19
+ renderer: Function
20
+ },
21
+ emits: ["change"],
22
+ setup(props, { emit }) {
23
+ const el = ref(null);
24
+ let editor2 = null;
25
+ let unsubscribe;
26
+ watch(
27
+ () => props,
28
+ (newValue) => {
29
+ editor2 == null ? void 0 : editor2.$set({ ...newValue });
30
+ },
31
+ { deep: true }
32
+ );
33
+ onMounted(() => {
34
+ const instance = new Editor({
35
+ target: el.value,
36
+ props
37
+ });
38
+ unsubscribe = instance.$on("change", (e) => {
39
+ emit("change", e.detail.value);
40
+ });
41
+ editor2 = instance;
42
+ });
43
+ onBeforeUnmount(() => {
44
+ unsubscribe == null ? void 0 : unsubscribe();
45
+ editor2 == null ? void 0 : editor2.$destroy();
46
+ editor2 = null;
47
+ });
48
+ return { el };
49
+ }
50
+ });
51
+ const _export_sfc = (sfc, props) => {
52
+ const target = sfc.__vccOpts || sfc;
53
+ for (const [key, val] of props) {
54
+ target[key] = val;
55
+ }
56
+ return target;
57
+ };
58
+ const _hoisted_1 = { ref: "el" };
59
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
60
+ return openBlock(), createElementBlock(
61
+ "div",
62
+ _hoisted_1,
63
+ null,
64
+ 512
65
+ /* NEED_PATCH */
66
+ );
67
+ }
68
+ const editor = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
69
+ export {
70
+ editor as default
71
+ };
@@ -0,0 +1 @@
1
+ export { DefineComponent as default } from 'vue';
@@ -0,0 +1,2 @@
1
+ export { default as Editor } from './editor.vue';
2
+ export { default as Viewer } from './viewer.vue';
package/dist/index.js ADDED
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vue = require("vue");
4
+ const bytemd = require("@jihua/bytemd");
5
+ const viewer$1 = require("@jihua/bytemd/viewer");
6
+ const _sfc_main$1 = vue.defineComponent({
7
+ props: {
8
+ value: { type: String, default: "" },
9
+ plugins: { type: Array, default: () => [] },
10
+ sanitize: Function,
11
+ remarkRehype: Object,
12
+ headingIds: { type: [Boolean, Object], default: true },
13
+ mode: { type: String, default: "auto" },
14
+ previewDebounce: { type: Number, default: 300 },
15
+ layoutContainment: { type: Boolean, default: false },
16
+ placeholder: String,
17
+ editorConfig: Object,
18
+ locale: Object,
19
+ uploadImages: Function,
20
+ maxLength: { type: Number, default: Infinity },
21
+ overridePreview: Function,
22
+ renderer: Function
23
+ },
24
+ emits: ["change"],
25
+ setup(props, { emit }) {
26
+ const el = vue.ref(null);
27
+ let editor2 = null;
28
+ let unsubscribe;
29
+ vue.watch(
30
+ () => props,
31
+ (newValue) => {
32
+ editor2 == null ? void 0 : editor2.$set({ ...newValue });
33
+ },
34
+ { deep: true }
35
+ );
36
+ vue.onMounted(() => {
37
+ const instance = new bytemd.Editor({
38
+ target: el.value,
39
+ props
40
+ });
41
+ unsubscribe = instance.$on("change", (e) => {
42
+ emit("change", e.detail.value);
43
+ });
44
+ editor2 = instance;
45
+ });
46
+ vue.onBeforeUnmount(() => {
47
+ unsubscribe == null ? void 0 : unsubscribe();
48
+ editor2 == null ? void 0 : editor2.$destroy();
49
+ editor2 = null;
50
+ });
51
+ return { el };
52
+ }
53
+ });
54
+ const _export_sfc = (sfc, props) => {
55
+ const target = sfc.__vccOpts || sfc;
56
+ for (const [key, val] of props) {
57
+ target[key] = val;
58
+ }
59
+ return target;
60
+ };
61
+ const _hoisted_1$1 = { ref: "el" };
62
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
63
+ return vue.openBlock(), vue.createElementBlock(
64
+ "div",
65
+ _hoisted_1$1,
66
+ null,
67
+ 512
68
+ /* NEED_PATCH */
69
+ );
70
+ }
71
+ const editor = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
72
+ const _sfc_main = vue.defineComponent({
73
+ props: [
74
+ "value",
75
+ "plugins",
76
+ "sanitize",
77
+ "remarkRehype",
78
+ "headingIds",
79
+ "locale",
80
+ "renderer"
81
+ ],
82
+ setup(props, ctx) {
83
+ const markdownBody = vue.ref(null);
84
+ let cleanupEffects;
85
+ let active = true;
86
+ let effectVersion = 0;
87
+ let mounted = false;
88
+ let controller;
89
+ const asyncState = vue.shallowRef();
90
+ const asyncRequest = vue.shallowRef();
91
+ const request = vue.computed(() => ({
92
+ value: props.value,
93
+ plugins: props.plugins,
94
+ sanitize: props.sanitize,
95
+ remarkRehype: props.remarkRehype,
96
+ headingIds: props.headingIds,
97
+ renderer: props.renderer
98
+ }));
99
+ const pending = vue.computed(
100
+ () => !!props.renderer && (asyncRequest.value !== request.value || !asyncState.value || asyncState.value.status === "pending")
101
+ );
102
+ const file = vue.computed(() => {
103
+ var _a;
104
+ if (props.renderer)
105
+ return asyncRequest.value === request.value && ((_a = asyncState.value) == null ? void 0 : _a.status) === "ready" ? asyncState.value.result.file : void 0;
106
+ try {
107
+ return viewer$1.renderMarkdown(request.value).file;
108
+ } catch (error) {
109
+ console.error(error);
110
+ }
111
+ });
112
+ const html = vue.computed(
113
+ () => {
114
+ var _a, _b;
115
+ return (_b = (_a = file.value) == null ? void 0 : _a.toString()) != null ? _b : pending.value ? viewer$1.renderPendingHtml(props.locale) : viewer$1.renderErrorHtml(props.locale);
116
+ }
117
+ );
118
+ const needUpdate = vue.computed(() => {
119
+ return [
120
+ file.value,
121
+ props.plugins,
122
+ props.sanitize,
123
+ props.remarkRehype,
124
+ props.locale
125
+ ];
126
+ });
127
+ vue.watch(
128
+ request,
129
+ () => {
130
+ if (!mounted) return;
131
+ controller == null ? void 0 : controller.destroy();
132
+ if (props.renderer) startRender();
133
+ },
134
+ { deep: true }
135
+ );
136
+ function startRender() {
137
+ off();
138
+ asyncRequest.value = request.value;
139
+ controller = viewer$1.createRenderController((state) => {
140
+ if (state.status === "error") console.error(state.error);
141
+ asyncState.value = state;
142
+ });
143
+ controller.render(request.value, props.renderer);
144
+ }
145
+ vue.watch(
146
+ needUpdate,
147
+ () => {
148
+ off();
149
+ const version = ++effectVersion;
150
+ vue.nextTick(() => {
151
+ if (active && version === effectVersion) on();
152
+ });
153
+ },
154
+ { deep: true }
155
+ );
156
+ vue.onMounted(() => {
157
+ mounted = true;
158
+ if (props.renderer) startRender();
159
+ else on();
160
+ });
161
+ vue.onUnmounted(() => {
162
+ active = false;
163
+ effectVersion++;
164
+ controller == null ? void 0 : controller.destroy();
165
+ off();
166
+ });
167
+ const handleClick = (e) => {
168
+ var _a;
169
+ const $ = e.target;
170
+ if ((_a = $.classList) == null ? void 0 : _a.contains("bytemd-copy-btn")) {
171
+ viewer$1.copyCodeFromButton($);
172
+ return;
173
+ }
174
+ if (markdownBody.value) viewer$1.scrollToAnchor(markdownBody.value, e);
175
+ };
176
+ const off = () => {
177
+ cleanupEffects == null ? void 0 : cleanupEffects();
178
+ cleanupEffects = void 0;
179
+ };
180
+ const on = () => {
181
+ if (!active || !markdownBody.value || !file.value) return;
182
+ viewer$1.addCopyButtons(markdownBody.value, props.locale);
183
+ cleanupEffects = viewer$1.runViewerEffects(
184
+ markdownBody.value,
185
+ file.value,
186
+ props.plugins,
187
+ props.locale
188
+ );
189
+ };
190
+ return { markdownBody, html, handleClick, pending };
191
+ }
192
+ });
193
+ const _hoisted_1 = ["innerHTML", "aria-busy"];
194
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
195
+ return vue.openBlock(), vue.createElementBlock("div", {
196
+ innerHTML: _ctx.html,
197
+ class: "markdown-body",
198
+ "aria-busy": _ctx.pending,
199
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)),
200
+ ref: "markdownBody"
201
+ }, null, 8, _hoisted_1);
202
+ }
203
+ const viewer = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
204
+ exports.Editor = editor;
205
+ exports.Viewer = viewer;
package/dist/index.mjs ADDED
@@ -0,0 +1,205 @@
1
+ import { defineComponent, ref, watch, onMounted, onBeforeUnmount, openBlock, createElementBlock, shallowRef, computed, nextTick, onUnmounted } from "vue";
2
+ import { Editor } from "@jihua/bytemd";
3
+ import { renderMarkdown, renderPendingHtml, renderErrorHtml, addCopyButtons, runViewerEffects, createRenderController, copyCodeFromButton, scrollToAnchor } from "@jihua/bytemd/viewer";
4
+ const _sfc_main$1 = defineComponent({
5
+ props: {
6
+ value: { type: String, default: "" },
7
+ plugins: { type: Array, default: () => [] },
8
+ sanitize: Function,
9
+ remarkRehype: Object,
10
+ headingIds: { type: [Boolean, Object], default: true },
11
+ mode: { type: String, default: "auto" },
12
+ previewDebounce: { type: Number, default: 300 },
13
+ layoutContainment: { type: Boolean, default: false },
14
+ placeholder: String,
15
+ editorConfig: Object,
16
+ locale: Object,
17
+ uploadImages: Function,
18
+ maxLength: { type: Number, default: Infinity },
19
+ overridePreview: Function,
20
+ renderer: Function
21
+ },
22
+ emits: ["change"],
23
+ setup(props, { emit }) {
24
+ const el = ref(null);
25
+ let editor2 = null;
26
+ let unsubscribe;
27
+ watch(
28
+ () => props,
29
+ (newValue) => {
30
+ editor2 == null ? void 0 : editor2.$set({ ...newValue });
31
+ },
32
+ { deep: true }
33
+ );
34
+ onMounted(() => {
35
+ const instance = new Editor({
36
+ target: el.value,
37
+ props
38
+ });
39
+ unsubscribe = instance.$on("change", (e) => {
40
+ emit("change", e.detail.value);
41
+ });
42
+ editor2 = instance;
43
+ });
44
+ onBeforeUnmount(() => {
45
+ unsubscribe == null ? void 0 : unsubscribe();
46
+ editor2 == null ? void 0 : editor2.$destroy();
47
+ editor2 = null;
48
+ });
49
+ return { el };
50
+ }
51
+ });
52
+ const _export_sfc = (sfc, props) => {
53
+ const target = sfc.__vccOpts || sfc;
54
+ for (const [key, val] of props) {
55
+ target[key] = val;
56
+ }
57
+ return target;
58
+ };
59
+ const _hoisted_1$1 = { ref: "el" };
60
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
61
+ return openBlock(), createElementBlock(
62
+ "div",
63
+ _hoisted_1$1,
64
+ null,
65
+ 512
66
+ /* NEED_PATCH */
67
+ );
68
+ }
69
+ const editor = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
70
+ const _sfc_main = defineComponent({
71
+ props: [
72
+ "value",
73
+ "plugins",
74
+ "sanitize",
75
+ "remarkRehype",
76
+ "headingIds",
77
+ "locale",
78
+ "renderer"
79
+ ],
80
+ setup(props, ctx) {
81
+ const markdownBody = ref(null);
82
+ let cleanupEffects;
83
+ let active = true;
84
+ let effectVersion = 0;
85
+ let mounted = false;
86
+ let controller;
87
+ const asyncState = shallowRef();
88
+ const asyncRequest = shallowRef();
89
+ const request = computed(() => ({
90
+ value: props.value,
91
+ plugins: props.plugins,
92
+ sanitize: props.sanitize,
93
+ remarkRehype: props.remarkRehype,
94
+ headingIds: props.headingIds,
95
+ renderer: props.renderer
96
+ }));
97
+ const pending = computed(
98
+ () => !!props.renderer && (asyncRequest.value !== request.value || !asyncState.value || asyncState.value.status === "pending")
99
+ );
100
+ const file = computed(() => {
101
+ var _a;
102
+ if (props.renderer)
103
+ return asyncRequest.value === request.value && ((_a = asyncState.value) == null ? void 0 : _a.status) === "ready" ? asyncState.value.result.file : void 0;
104
+ try {
105
+ return renderMarkdown(request.value).file;
106
+ } catch (error) {
107
+ console.error(error);
108
+ }
109
+ });
110
+ const html = computed(
111
+ () => {
112
+ var _a, _b;
113
+ return (_b = (_a = file.value) == null ? void 0 : _a.toString()) != null ? _b : pending.value ? renderPendingHtml(props.locale) : renderErrorHtml(props.locale);
114
+ }
115
+ );
116
+ const needUpdate = computed(() => {
117
+ return [
118
+ file.value,
119
+ props.plugins,
120
+ props.sanitize,
121
+ props.remarkRehype,
122
+ props.locale
123
+ ];
124
+ });
125
+ watch(
126
+ request,
127
+ () => {
128
+ if (!mounted) return;
129
+ controller == null ? void 0 : controller.destroy();
130
+ if (props.renderer) startRender();
131
+ },
132
+ { deep: true }
133
+ );
134
+ function startRender() {
135
+ off();
136
+ asyncRequest.value = request.value;
137
+ controller = createRenderController((state) => {
138
+ if (state.status === "error") console.error(state.error);
139
+ asyncState.value = state;
140
+ });
141
+ controller.render(request.value, props.renderer);
142
+ }
143
+ watch(
144
+ needUpdate,
145
+ () => {
146
+ off();
147
+ const version = ++effectVersion;
148
+ nextTick(() => {
149
+ if (active && version === effectVersion) on();
150
+ });
151
+ },
152
+ { deep: true }
153
+ );
154
+ onMounted(() => {
155
+ mounted = true;
156
+ if (props.renderer) startRender();
157
+ else on();
158
+ });
159
+ onUnmounted(() => {
160
+ active = false;
161
+ effectVersion++;
162
+ controller == null ? void 0 : controller.destroy();
163
+ off();
164
+ });
165
+ const handleClick = (e) => {
166
+ var _a;
167
+ const $ = e.target;
168
+ if ((_a = $.classList) == null ? void 0 : _a.contains("bytemd-copy-btn")) {
169
+ copyCodeFromButton($);
170
+ return;
171
+ }
172
+ if (markdownBody.value) scrollToAnchor(markdownBody.value, e);
173
+ };
174
+ const off = () => {
175
+ cleanupEffects == null ? void 0 : cleanupEffects();
176
+ cleanupEffects = void 0;
177
+ };
178
+ const on = () => {
179
+ if (!active || !markdownBody.value || !file.value) return;
180
+ addCopyButtons(markdownBody.value, props.locale);
181
+ cleanupEffects = runViewerEffects(
182
+ markdownBody.value,
183
+ file.value,
184
+ props.plugins,
185
+ props.locale
186
+ );
187
+ };
188
+ return { markdownBody, html, handleClick, pending };
189
+ }
190
+ });
191
+ const _hoisted_1 = ["innerHTML", "aria-busy"];
192
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
193
+ return openBlock(), createElementBlock("div", {
194
+ innerHTML: _ctx.html,
195
+ class: "markdown-body",
196
+ "aria-busy": _ctx.pending,
197
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)),
198
+ ref: "markdownBody"
199
+ }, null, 8, _hoisted_1);
200
+ }
201
+ const viewer = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
202
+ export {
203
+ editor as Editor,
204
+ viewer as Viewer
205
+ };
@@ -0,0 +1,2 @@
1
+ export { default as Viewer } from './viewer.vue';
2
+ export type { ViewerProps } from '@jihua/bytemd/viewer';
package/dist/viewer.js ADDED
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const vue = require("vue");
4
+ const viewer$1 = require("@jihua/bytemd/viewer");
5
+ const _sfc_main = vue.defineComponent({
6
+ props: [
7
+ "value",
8
+ "plugins",
9
+ "sanitize",
10
+ "remarkRehype",
11
+ "headingIds",
12
+ "locale",
13
+ "renderer"
14
+ ],
15
+ setup(props, ctx) {
16
+ const markdownBody = vue.ref(null);
17
+ let cleanupEffects;
18
+ let active = true;
19
+ let effectVersion = 0;
20
+ let mounted = false;
21
+ let controller;
22
+ const asyncState = vue.shallowRef();
23
+ const asyncRequest = vue.shallowRef();
24
+ const request = vue.computed(() => ({
25
+ value: props.value,
26
+ plugins: props.plugins,
27
+ sanitize: props.sanitize,
28
+ remarkRehype: props.remarkRehype,
29
+ headingIds: props.headingIds,
30
+ renderer: props.renderer
31
+ }));
32
+ const pending = vue.computed(
33
+ () => !!props.renderer && (asyncRequest.value !== request.value || !asyncState.value || asyncState.value.status === "pending")
34
+ );
35
+ const file = vue.computed(() => {
36
+ var _a;
37
+ if (props.renderer)
38
+ return asyncRequest.value === request.value && ((_a = asyncState.value) == null ? void 0 : _a.status) === "ready" ? asyncState.value.result.file : void 0;
39
+ try {
40
+ return viewer$1.renderMarkdown(request.value).file;
41
+ } catch (error) {
42
+ console.error(error);
43
+ }
44
+ });
45
+ const html = vue.computed(
46
+ () => {
47
+ var _a, _b;
48
+ return (_b = (_a = file.value) == null ? void 0 : _a.toString()) != null ? _b : pending.value ? viewer$1.renderPendingHtml(props.locale) : viewer$1.renderErrorHtml(props.locale);
49
+ }
50
+ );
51
+ const needUpdate = vue.computed(() => {
52
+ return [
53
+ file.value,
54
+ props.plugins,
55
+ props.sanitize,
56
+ props.remarkRehype,
57
+ props.locale
58
+ ];
59
+ });
60
+ vue.watch(
61
+ request,
62
+ () => {
63
+ if (!mounted) return;
64
+ controller == null ? void 0 : controller.destroy();
65
+ if (props.renderer) startRender();
66
+ },
67
+ { deep: true }
68
+ );
69
+ function startRender() {
70
+ off();
71
+ asyncRequest.value = request.value;
72
+ controller = viewer$1.createRenderController((state) => {
73
+ if (state.status === "error") console.error(state.error);
74
+ asyncState.value = state;
75
+ });
76
+ controller.render(request.value, props.renderer);
77
+ }
78
+ vue.watch(
79
+ needUpdate,
80
+ () => {
81
+ off();
82
+ const version = ++effectVersion;
83
+ vue.nextTick(() => {
84
+ if (active && version === effectVersion) on();
85
+ });
86
+ },
87
+ { deep: true }
88
+ );
89
+ vue.onMounted(() => {
90
+ mounted = true;
91
+ if (props.renderer) startRender();
92
+ else on();
93
+ });
94
+ vue.onUnmounted(() => {
95
+ active = false;
96
+ effectVersion++;
97
+ controller == null ? void 0 : controller.destroy();
98
+ off();
99
+ });
100
+ const handleClick = (e) => {
101
+ var _a;
102
+ const $ = e.target;
103
+ if ((_a = $.classList) == null ? void 0 : _a.contains("bytemd-copy-btn")) {
104
+ viewer$1.copyCodeFromButton($);
105
+ return;
106
+ }
107
+ if (markdownBody.value) viewer$1.scrollToAnchor(markdownBody.value, e);
108
+ };
109
+ const off = () => {
110
+ cleanupEffects == null ? void 0 : cleanupEffects();
111
+ cleanupEffects = void 0;
112
+ };
113
+ const on = () => {
114
+ if (!active || !markdownBody.value || !file.value) return;
115
+ viewer$1.addCopyButtons(markdownBody.value, props.locale);
116
+ cleanupEffects = viewer$1.runViewerEffects(
117
+ markdownBody.value,
118
+ file.value,
119
+ props.plugins,
120
+ props.locale
121
+ );
122
+ };
123
+ return { markdownBody, html, handleClick, pending };
124
+ }
125
+ });
126
+ const _export_sfc = (sfc, props) => {
127
+ const target = sfc.__vccOpts || sfc;
128
+ for (const [key, val] of props) {
129
+ target[key] = val;
130
+ }
131
+ return target;
132
+ };
133
+ const _hoisted_1 = ["innerHTML", "aria-busy"];
134
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
135
+ return vue.openBlock(), vue.createElementBlock("div", {
136
+ innerHTML: _ctx.html,
137
+ class: "markdown-body",
138
+ "aria-busy": _ctx.pending,
139
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)),
140
+ ref: "markdownBody"
141
+ }, null, 8, _hoisted_1);
142
+ }
143
+ const viewer = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
144
+ exports.Viewer = viewer;
@@ -0,0 +1,144 @@
1
+ import { defineComponent, ref, shallowRef, computed, watch, nextTick, onMounted, onUnmounted, openBlock, createElementBlock } from "vue";
2
+ import { renderMarkdown, renderPendingHtml, renderErrorHtml, addCopyButtons, runViewerEffects, createRenderController, copyCodeFromButton, scrollToAnchor } from "@jihua/bytemd/viewer";
3
+ const _sfc_main = defineComponent({
4
+ props: [
5
+ "value",
6
+ "plugins",
7
+ "sanitize",
8
+ "remarkRehype",
9
+ "headingIds",
10
+ "locale",
11
+ "renderer"
12
+ ],
13
+ setup(props, ctx) {
14
+ const markdownBody = ref(null);
15
+ let cleanupEffects;
16
+ let active = true;
17
+ let effectVersion = 0;
18
+ let mounted = false;
19
+ let controller;
20
+ const asyncState = shallowRef();
21
+ const asyncRequest = shallowRef();
22
+ const request = computed(() => ({
23
+ value: props.value,
24
+ plugins: props.plugins,
25
+ sanitize: props.sanitize,
26
+ remarkRehype: props.remarkRehype,
27
+ headingIds: props.headingIds,
28
+ renderer: props.renderer
29
+ }));
30
+ const pending = computed(
31
+ () => !!props.renderer && (asyncRequest.value !== request.value || !asyncState.value || asyncState.value.status === "pending")
32
+ );
33
+ const file = computed(() => {
34
+ var _a;
35
+ if (props.renderer)
36
+ return asyncRequest.value === request.value && ((_a = asyncState.value) == null ? void 0 : _a.status) === "ready" ? asyncState.value.result.file : void 0;
37
+ try {
38
+ return renderMarkdown(request.value).file;
39
+ } catch (error) {
40
+ console.error(error);
41
+ }
42
+ });
43
+ const html = computed(
44
+ () => {
45
+ var _a, _b;
46
+ return (_b = (_a = file.value) == null ? void 0 : _a.toString()) != null ? _b : pending.value ? renderPendingHtml(props.locale) : renderErrorHtml(props.locale);
47
+ }
48
+ );
49
+ const needUpdate = computed(() => {
50
+ return [
51
+ file.value,
52
+ props.plugins,
53
+ props.sanitize,
54
+ props.remarkRehype,
55
+ props.locale
56
+ ];
57
+ });
58
+ watch(
59
+ request,
60
+ () => {
61
+ if (!mounted) return;
62
+ controller == null ? void 0 : controller.destroy();
63
+ if (props.renderer) startRender();
64
+ },
65
+ { deep: true }
66
+ );
67
+ function startRender() {
68
+ off();
69
+ asyncRequest.value = request.value;
70
+ controller = createRenderController((state) => {
71
+ if (state.status === "error") console.error(state.error);
72
+ asyncState.value = state;
73
+ });
74
+ controller.render(request.value, props.renderer);
75
+ }
76
+ watch(
77
+ needUpdate,
78
+ () => {
79
+ off();
80
+ const version = ++effectVersion;
81
+ nextTick(() => {
82
+ if (active && version === effectVersion) on();
83
+ });
84
+ },
85
+ { deep: true }
86
+ );
87
+ onMounted(() => {
88
+ mounted = true;
89
+ if (props.renderer) startRender();
90
+ else on();
91
+ });
92
+ onUnmounted(() => {
93
+ active = false;
94
+ effectVersion++;
95
+ controller == null ? void 0 : controller.destroy();
96
+ off();
97
+ });
98
+ const handleClick = (e) => {
99
+ var _a;
100
+ const $ = e.target;
101
+ if ((_a = $.classList) == null ? void 0 : _a.contains("bytemd-copy-btn")) {
102
+ copyCodeFromButton($);
103
+ return;
104
+ }
105
+ if (markdownBody.value) scrollToAnchor(markdownBody.value, e);
106
+ };
107
+ const off = () => {
108
+ cleanupEffects == null ? void 0 : cleanupEffects();
109
+ cleanupEffects = void 0;
110
+ };
111
+ const on = () => {
112
+ if (!active || !markdownBody.value || !file.value) return;
113
+ addCopyButtons(markdownBody.value, props.locale);
114
+ cleanupEffects = runViewerEffects(
115
+ markdownBody.value,
116
+ file.value,
117
+ props.plugins,
118
+ props.locale
119
+ );
120
+ };
121
+ return { markdownBody, html, handleClick, pending };
122
+ }
123
+ });
124
+ const _export_sfc = (sfc, props) => {
125
+ const target = sfc.__vccOpts || sfc;
126
+ for (const [key, val] of props) {
127
+ target[key] = val;
128
+ }
129
+ return target;
130
+ };
131
+ const _hoisted_1 = ["innerHTML", "aria-busy"];
132
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
133
+ return openBlock(), createElementBlock("div", {
134
+ innerHTML: _ctx.html,
135
+ class: "markdown-body",
136
+ "aria-busy": _ctx.pending,
137
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)),
138
+ ref: "markdownBody"
139
+ }, null, 8, _hoisted_1);
140
+ }
141
+ const viewer = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
142
+ export {
143
+ viewer as Viewer
144
+ };
@@ -0,0 +1 @@
1
+ export { DefineComponent as default } from 'vue';
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@jihua/bytemd-vue-next",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.22.0",
4
+ "description": "Unofficial ByteMD fork (not the official bytemd package). Hackable Markdown Editor and Viewer",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/bigJiHua/bytemd.git",
8
+ "directory": "packages/vue-next"
9
+ },
10
+ "license": "MIT",
11
+ "author": "Rongjian Zhang",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.js"
17
+ },
18
+ "./async": {
19
+ "types": "./dist/async.d.ts",
20
+ "import": "./dist/async.mjs",
21
+ "require": "./dist/async.js"
22
+ },
23
+ "./viewer": {
24
+ "types": "./dist/viewer.d.ts",
25
+ "import": "./dist/viewer.mjs",
26
+ "require": "./dist/viewer.js"
27
+ }
28
+ },
29
+ "main": "./dist/index.js",
30
+ "module": "./dist/index.mjs",
31
+ "types": "./dist/index.d.ts",
32
+ "files": [
33
+ "dist",
34
+ "async.mjs",
35
+ "async.js",
36
+ "async.d.ts",
37
+ "viewer.mjs",
38
+ "viewer.js",
39
+ "viewer.d.ts"
40
+ ],
41
+ "dependencies": {
42
+ "@jihua/bytemd": "workspace:*"
43
+ },
44
+ "devDependencies": {
45
+ "@vitejs/plugin-vue": "^5.2.4",
46
+ "@vue/server-renderer": "^3.5.13",
47
+ "vue": "^3.5.13"
48
+ },
49
+ "peerDependencies": {
50
+ "vue": "^3.0.0"
51
+ }
52
+ }
package/viewer.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/viewer'
package/viewer.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/viewer.js')
package/viewer.mjs ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/viewer.mjs'