aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/templates/__mocks__/template-renderer-proxy.js53
-rw-r--r--ext/js/templates/sandbox/anki-template-renderer-content-manager.js6
-rw-r--r--ext/js/templates/sandbox/anki-template-renderer.js8
-rw-r--r--ext/js/templates/sandbox/template-renderer-frame-api.js4
-rw-r--r--ext/js/templates/sandbox/template-renderer.js8
5 files changed, 31 insertions, 48 deletions
diff --git a/ext/js/templates/__mocks__/template-renderer-proxy.js b/ext/js/templates/__mocks__/template-renderer-proxy.js
index bcacf13b..8823e8f3 100644
--- a/ext/js/templates/__mocks__/template-renderer-proxy.js
+++ b/ext/js/templates/__mocks__/template-renderer-proxy.js
@@ -20,20 +20,35 @@ import {AnkiTemplateRenderer} from '../sandbox/anki-template-renderer.js';
export class TemplateRendererProxy {
constructor() {
+ /** @type {?Promise<void>} */
this._preparePromise = null;
+ /** @type {AnkiTemplateRenderer} */
this._ankiTemplateRenderer = new AnkiTemplateRenderer();
}
+ /**
+ * @param {string} template
+ * @param {import('template-renderer').PartialOrCompositeRenderData} data
+ * @param {import('anki-templates').RenderMode} type
+ * @returns {Promise<import('template-renderer').RenderResult>}
+ */
async render(template, data, type) {
await this._prepare();
- return await this._ankiTemplateRenderer.templateRenderer.render(template, data, type);
+ return this._ankiTemplateRenderer.templateRenderer.render(template, data, type);
}
+ /**
+ * @param {import('template-renderer').RenderMultiItem[]} items
+ * @returns {Promise<import('core').Response<import('template-renderer').RenderResult>[]>}
+ */
async renderMulti(items) {
await this._prepare();
- return await this._serializeMulti(this._ankiTemplateRenderer.templateRenderer.renderMulti(items));
+ return this._ankiTemplateRenderer.templateRenderer.renderMulti(items);
}
+ /**
+ * @returns {Promise<void>}
+ */
_prepare() {
if (this._preparePromise === null) {
this._preparePromise = this._prepareInternal();
@@ -41,40 +56,8 @@ export class TemplateRendererProxy {
return this._preparePromise;
}
+ /** */
async _prepareInternal() {
await this._ankiTemplateRenderer.prepare();
}
-
- _serializeError(error) {
- try {
- if (typeof error === 'object' && error !== null) {
- const result = {
- name: error.name,
- message: error.message,
- stack: error.stack
- };
- if (Object.prototype.hasOwnProperty.call(error, 'data')) {
- result.data = error.data;
- }
- return result;
- }
- } catch (e) {
- // NOP
- }
- return {
- value: error,
- hasValue: true
- };
- }
-
- _serializeMulti(array) {
- for (let i = 0, ii = array.length; i < ii; ++i) {
- const value = array[i];
- const {error} = value;
- if (typeof error !== 'undefined') {
- value.error = this._serializeError(error);
- }
- }
- return array;
- }
}
diff --git a/ext/js/templates/sandbox/anki-template-renderer-content-manager.js b/ext/js/templates/sandbox/anki-template-renderer-content-manager.js
index be80c211..4989ced3 100644
--- a/ext/js/templates/sandbox/anki-template-renderer-content-manager.js
+++ b/ext/js/templates/sandbox/anki-template-renderer-content-manager.js
@@ -22,12 +22,12 @@
export class AnkiTemplateRendererContentManager {
/**
* Creates a new instance of the class.
- * @param {TemplateRendererMediaProvider} mediaProvider The media provider for the object.
+ * @param {import('./template-renderer-media-provider.js').TemplateRendererMediaProvider} mediaProvider The media provider for the object.
* @param {import('anki-templates').NoteData} data The data object passed to the Handlebars template renderer.
- * See {@link AnkiNoteDataCreator.create}'s return value for structure information.
+ * See AnkiNoteDataCreator.create's return value for structure information.
*/
constructor(mediaProvider, data) {
- /** @type {TemplateRendererMediaProvider} */
+ /** @type {import('./template-renderer-media-provider.js').TemplateRendererMediaProvider} */
this._mediaProvider = mediaProvider;
/** @type {import('anki-templates').NoteData} */
this._data = data;
diff --git a/ext/js/templates/sandbox/anki-template-renderer.js b/ext/js/templates/sandbox/anki-template-renderer.js
index ce8e3200..9f4bf6ff 100644
--- a/ext/js/templates/sandbox/anki-template-renderer.js
+++ b/ext/js/templates/sandbox/anki-template-renderer.js
@@ -151,8 +151,8 @@ export class AnkiTemplateRenderer {
}
/**
- *
- * @param text
+ * @param {string} text
+ * @returns {string}
*/
_safeString(text) {
return new Handlebars.SafeString(text);
@@ -221,8 +221,8 @@ export class AnkiTemplateRenderer {
}
/**
- *
- * @param string
+ * @param {string} string
+ * @returns {string}
*/
_stringToMultiLineHtml(string) {
return string.split('\n').join('<br>');
diff --git a/ext/js/templates/sandbox/template-renderer-frame-api.js b/ext/js/templates/sandbox/template-renderer-frame-api.js
index 91400ab8..94ebf7fe 100644
--- a/ext/js/templates/sandbox/template-renderer-frame-api.js
+++ b/ext/js/templates/sandbox/template-renderer-frame-api.js
@@ -20,10 +20,10 @@ import {ExtensionError} from '../../core/extension-error.js';
export class TemplateRendererFrameApi {
/**
- * @param {TemplateRenderer} templateRenderer
+ * @param {import('./template-renderer.js').TemplateRenderer} templateRenderer
*/
constructor(templateRenderer) {
- /** @type {TemplateRenderer} */
+ /** @type {import('./template-renderer.js').TemplateRenderer} */
this._templateRenderer = templateRenderer;
/** @type {import('core').MessageHandlerMap} */
this._windowMessageHandlers = new Map(/** @type {import('core').MessageHandlerArray} */ ([
diff --git a/ext/js/templates/sandbox/template-renderer.js b/ext/js/templates/sandbox/template-renderer.js
index 716e3ccc..fe240b5f 100644
--- a/ext/js/templates/sandbox/template-renderer.js
+++ b/ext/js/templates/sandbox/template-renderer.js
@@ -21,7 +21,7 @@ import {ExtensionError} from '../../core/extension-error.js';
export class TemplateRenderer {
constructor() {
- /** @type {Map<string, HandlebarsTemplateDelegate<import('anki-templates').NoteData>>} */
+ /** @type {Map<string, import('handlebars').TemplateDelegate<import('anki-templates').NoteData>>} */
this._cache = new Map();
/** @type {number} */
this._cacheMaxSize = 5;
@@ -110,14 +110,14 @@ export class TemplateRenderer {
/**
* @param {string} template
- * @returns {HandlebarsTemplateDelegate<import('anki-templates').NoteData>}
+ * @returns {import('handlebars').TemplateDelegate<import('anki-templates').NoteData>}
*/
_getTemplateInstance(template) {
const cache = this._cache;
let instance = cache.get(template);
if (typeof instance === 'undefined') {
this._updateCacheSize(this._cacheMaxSize - 1);
- instance = /** @type {HandlebarsTemplateDelegate<import('anki-templates').NoteData>} */ (Handlebars.compileAST(template));
+ instance = /** @type {import('handlebars').TemplateDelegate<import('anki-templates').NoteData>} */ (Handlebars.compileAST(template));
cache.set(template, instance);
}
@@ -125,7 +125,7 @@ export class TemplateRenderer {
}
/**
- * @param {HandlebarsTemplateDelegate<import('anki-templates').NoteData>} instance
+ * @param {import('handlebars').TemplateDelegate<import('anki-templates').NoteData>} instance
* @param {import('anki-templates').NoteData} data
* @returns {import('template-renderer').RenderResult}
*/