markdown-up 3.3.6 → 3.3.8
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/lib/app.js +6 -7
- package/lib/dataTable.js +7 -2
- package/lib/scriptLibrary.js +0 -82
- package/package.json +3 -3
package/lib/app.js
CHANGED
|
@@ -108,7 +108,7 @@ export class MarkdownUp {
|
|
|
108
108
|
this.url = (options !== null ? options.url : null) ?? 'README.md';
|
|
109
109
|
this.runtimeWindowResize = null;
|
|
110
110
|
this.runtimeTimeoutId = null;
|
|
111
|
-
this.
|
|
111
|
+
this.runtimeCount = 0;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
|
|
@@ -122,9 +122,6 @@ export class MarkdownUp {
|
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
async render(forceRender = false) {
|
|
125
|
-
// Increase the render count enable so we can detect a render the middle of a runtime update
|
|
126
|
-
this.renderCount += 1;
|
|
127
|
-
|
|
128
125
|
// Parse the hash parameters and render the application element model
|
|
129
126
|
let result;
|
|
130
127
|
let isError = false;
|
|
@@ -158,6 +155,7 @@ export class MarkdownUp {
|
|
|
158
155
|
this.window.document.documentElement.style.setProperty('--markdown-model-line-height', `${lineHeight}em`);
|
|
159
156
|
|
|
160
157
|
// Call the application main and validate the result
|
|
158
|
+
this.runtimeCount += 1;
|
|
161
159
|
this.clearRuntimeCallbacks();
|
|
162
160
|
if (!isError) {
|
|
163
161
|
result = await this.main();
|
|
@@ -431,15 +429,16 @@ export class MarkdownUp {
|
|
|
431
429
|
|
|
432
430
|
// Create the markdown-script runtime
|
|
433
431
|
const runtime = new MarkdownScriptRuntime(scriptOptions);
|
|
434
|
-
const {
|
|
432
|
+
const {runtimeCount} = this;
|
|
435
433
|
scriptOptions.globals = {...markdownScriptFunctions};
|
|
436
434
|
if (this.globals !== null) {
|
|
437
435
|
Object.assign(scriptOptions.globals, this.globals);
|
|
438
436
|
}
|
|
439
437
|
scriptOptions.runtime = runtime;
|
|
440
438
|
scriptOptions.runtimeUpdateFn = () => {
|
|
441
|
-
// Did a render occur in the middle of this runtime update?
|
|
442
|
-
if (this.
|
|
439
|
+
// Did a render occur in the middle of this runtime update? If so, just reset the runtime.
|
|
440
|
+
if (this.runtimeCount !== runtimeCount) {
|
|
441
|
+
runtime.reset();
|
|
443
442
|
return;
|
|
444
443
|
}
|
|
445
444
|
|
package/lib/dataTable.js
CHANGED
|
@@ -50,6 +50,9 @@ struct DataTableFieldFormat
|
|
|
50
50
|
# If true, format the field as Markdown
|
|
51
51
|
optional bool markdown
|
|
52
52
|
|
|
53
|
+
# The field header (default is the field name)
|
|
54
|
+
optional string header
|
|
55
|
+
|
|
53
56
|
|
|
54
57
|
# A field alignment
|
|
55
58
|
enum DataTableFieldAlignment
|
|
@@ -140,18 +143,20 @@ export function dataTableElements(data, dataTable = null, options = null) {
|
|
|
140
143
|
'elem': [
|
|
141
144
|
categories.map((field) => {
|
|
142
145
|
const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
|
|
146
|
+
const formatHeader = (fieldFormat !== null ? (fieldFormat.header ?? null) : null);
|
|
143
147
|
return {
|
|
144
148
|
'html': 'th',
|
|
145
149
|
'attr': createFieldAttr(fieldFormat),
|
|
146
|
-
'elem': {'text': field}
|
|
150
|
+
'elem': {'text': formatHeader ?? field}
|
|
147
151
|
};
|
|
148
152
|
}),
|
|
149
153
|
tableFields.map((field) => {
|
|
150
154
|
const fieldFormat = (fieldFormats !== null ? (fieldFormats[field] ?? null) : null);
|
|
155
|
+
const formatHeader = (fieldFormat !== null ? (fieldFormat.header ?? null) : null);
|
|
151
156
|
return {
|
|
152
157
|
'html': 'th',
|
|
153
158
|
'attr': createFieldAttr(fieldFormat),
|
|
154
|
-
'elem': {'text': field}
|
|
159
|
+
'elem': {'text': formatHeader ?? field}
|
|
155
160
|
};
|
|
156
161
|
})
|
|
157
162
|
]
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -75,23 +75,6 @@ const dataTableArgs = valueArgsModel([
|
|
|
75
75
|
//
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
// $function: documentElementClick
|
|
79
|
-
// $group: Document
|
|
80
|
-
// $doc: Click an element
|
|
81
|
-
// $arg id: The element ID
|
|
82
|
-
function documentElementClick(args, options) {
|
|
83
|
-
const [id] = valueArgsValidate(documentElementClickArgs, args);
|
|
84
|
-
const element = options.window.document.getElementById(id) ?? null;
|
|
85
|
-
if (element !== null) {
|
|
86
|
-
element.click();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const documentElementClickArgs = valueArgsModel([
|
|
91
|
-
{'name': 'id', 'type': 'string'}
|
|
92
|
-
]);
|
|
93
|
-
|
|
94
|
-
|
|
95
78
|
// $function: documentFontSize
|
|
96
79
|
// $group: Document
|
|
97
80
|
// $doc: Get the document font size
|
|
@@ -101,68 +84,6 @@ function documentFontSize(unusedArgs, options) {
|
|
|
101
84
|
}
|
|
102
85
|
|
|
103
86
|
|
|
104
|
-
// $function: documentInputFileText
|
|
105
|
-
// $group: Document
|
|
106
|
-
// $doc: Read files as text from a file input element
|
|
107
|
-
// $arg id: The input element ID
|
|
108
|
-
// $return: The array of file text, or null if the element does not exist
|
|
109
|
-
async function documentInputFileText(args, options) {
|
|
110
|
-
const [id] = valueArgsValidate(documentInputFileTextArgs, args);
|
|
111
|
-
const element = options.window.document.getElementById(id) ?? null;
|
|
112
|
-
if (element === null) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Read the files
|
|
117
|
-
const files = [];
|
|
118
|
-
for (const file of element.files) {
|
|
119
|
-
const reader = new options.window.FileReader();
|
|
120
|
-
const text = await new Promise((resolve, reject) => {
|
|
121
|
-
reader.onload = () => resolve(reader.result);
|
|
122
|
-
reader.onerror = () => reject(reader.error);
|
|
123
|
-
reader.readAsText(file);
|
|
124
|
-
});
|
|
125
|
-
files.push(text);
|
|
126
|
-
}
|
|
127
|
-
return files;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const documentInputFileTextArgs = valueArgsModel([
|
|
131
|
-
{'name': 'id', 'type': 'string'}
|
|
132
|
-
]);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// $function: documentInputFileURL
|
|
136
|
-
// $group: Document
|
|
137
|
-
// $doc: Read files as data URLs from a file input element
|
|
138
|
-
// $arg id: The input element ID
|
|
139
|
-
// $return: The array of file data URL strings, or null if the element does not exist
|
|
140
|
-
async function documentInputFileURL(args, options) {
|
|
141
|
-
const [id] = valueArgsValidate(documentInputFileURLArgs, args);
|
|
142
|
-
const element = options.window.document.getElementById(id) ?? null;
|
|
143
|
-
if (element === null) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Read the files
|
|
148
|
-
const files = [];
|
|
149
|
-
for (const file of element.files) {
|
|
150
|
-
const reader = new options.window.FileReader();
|
|
151
|
-
const dataURL = await new Promise((resolve, reject) => {
|
|
152
|
-
reader.onload = () => resolve(reader.result);
|
|
153
|
-
reader.onerror = () => reject(reader.error);
|
|
154
|
-
reader.readAsDataURL(file);
|
|
155
|
-
});
|
|
156
|
-
files.push(dataURL);
|
|
157
|
-
}
|
|
158
|
-
return files;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const documentInputFileURLArgs = valueArgsModel([
|
|
162
|
-
{'name': 'id', 'type': 'string'}
|
|
163
|
-
]);
|
|
164
|
-
|
|
165
|
-
|
|
166
87
|
// $function: documentInputValue
|
|
167
88
|
// $group: Document
|
|
168
89
|
// $doc: Get an input element's value
|
|
@@ -1164,10 +1085,7 @@ function windowWidth(unusedArgs, options) {
|
|
|
1164
1085
|
export const markdownScriptFunctions = {
|
|
1165
1086
|
dataLineChart,
|
|
1166
1087
|
dataTable,
|
|
1167
|
-
documentElementClick,
|
|
1168
1088
|
documentFontSize,
|
|
1169
|
-
documentInputFileText,
|
|
1170
|
-
documentInputFileURL,
|
|
1171
1089
|
documentInputValue,
|
|
1172
1090
|
documentSetFocus,
|
|
1173
1091
|
documentSetReset,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.8",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"c8": "~10.1",
|
|
33
|
-
"eslint": "~9.
|
|
33
|
+
"eslint": "~9.18",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
|
-
"jsdom": "~
|
|
35
|
+
"jsdom": "~26.0"
|
|
36
36
|
}
|
|
37
37
|
}
|