diff --git a/CHANGES.md b/CHANGES.md index 867574a86..1d60ce32e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,10 +18,12 @@ - pat tooltip: Remove undocumented "souce: auto" parameter. This parameter should not be used as it is not explicit enough and would lead to unintuitive behavior. - Remove outdated pre IE9 browser compatibility polyfill `core/compat`. - Remove unused `lib/htmlparser`. +- Remove obsolete library `prefixfree`. ### Features +- Implenent lazy loading for external libraries via dynamic imports. Leads to significantly reduced bundle sizes. - Upgrade pat-calendar to use lates fullcalendar version (5.3.0). - pat tooltip: Use tippy v6 based implementation. diff --git a/index.html b/index.html index f754b99e9..e7c90f4bb 100644 --- a/index.html +++ b/index.html @@ -4,11 +4,6 @@
)?/gi, function (
+ match,
+ pre
+ ) {
+ if (pre) {
+ return '';
+ } else {
+ return '';
+ }
+ });
+ },
+ },
+ ];
+ };
+
+ const $rendering = $("");
+ const converter = new Showdown.Converter({
+ tables: true,
+ extensions: ["prettify"],
+ });
$rendering.html(converter.makeHtml(text));
return $rendering;
},
- renderForInjection: function (cfg, data) {
+ async renderForInjection(cfg, data) {
var header,
source = data;
if (cfg.source && (header = /^#+\s*(.*)/.exec(cfg.source)) !== null) {
@@ -48,13 +76,14 @@ var Markdown = Base.extend({
}
source += "\n"; // Needed for some markdown syntax
}
- return this.render(source).attr(
+ const rendered = await this.render(source);
+ return rendered.attr(
"data-src",
cfg.source ? cfg.url + cfg.source : cfg.url
);
},
- extractSection: function (text, header) {
+ extractSection(text, header) {
var pattern, level;
header = utils.escapeRegExp(header);
var matcher = new RegExp(
@@ -95,27 +124,6 @@ var Markdown = Base.extend({
},
});
-// Add support for syntax highlighting via pat-syntax-highlight
-Showdown.extensions.prettify = function () {
- return [
- {
- type: "output",
- filter: function (source) {
- return source.replace(/()?/gi, function (
- match,
- pre
- ) {
- if (pre) {
- return '';
- } else {
- return '';
- }
- });
- },
- },
- ];
-};
-
$(document).ready(function () {
$(document.body).on(
"patterns-inject-triggered.pat-markdown",
@@ -135,11 +143,14 @@ $(document).ready(function () {
});
inject.registerTypeHandler("markdown", {
- sources: function (cfgs, data) {
- return cfgs.map(function (cfg) {
- var pat = Markdown.init(cfg.$target);
- return pat.renderForInjection(cfg, data);
- });
+ async sources(cfgs, data) {
+ return await Promise.all(
+ cfgs.map(async function (cfg) {
+ var pat = Markdown.init(cfg.$target);
+ const rendered = await pat.renderForInjection(cfg, data);
+ return rendered;
+ })
+ );
},
});
diff --git a/src/pat/markdown/markdown.test.js b/src/pat/markdown/markdown.test.js
index 7426d4584..5d1050f63 100644
--- a/src/pat/markdown/markdown.test.js
+++ b/src/pat/markdown/markdown.test.js
@@ -1,5 +1,6 @@
-import pattern from "./markdown";
import $ from "jquery";
+import pattern from "./markdown";
+import utils from "../../core/utils";
describe("pat-markdown", function () {
beforeEach(function () {
@@ -11,22 +12,26 @@ describe("pat-markdown", function () {
});
describe("when initialized", function () {
- it("replaces the DOM element with the rendered Markdown content.", function () {
+ afterEach(() => {
+ jest.restoreAllMocks();
+ });
+ it("replaces the DOM element with the rendered Markdown content.", async function () {
var $el = $('');
$el.appendTo("#lab");
- spyOn(pattern.prototype, "render").and.returnValue(
- $("Rendering
")
- );
+ jest.spyOn(pattern.prototype, "render").mockImplementation(() => {
+ return $("Rendering
");
+ });
pattern.init($el);
+ await utils.timeout(1); // wait a tick for async to settle.
expect($("#lab").html()).toBe("Rendering
");
});
it("does not replace the DOM element if it doesn't have the pattern trigger", function () {
var $el = $("");
$el.appendTo("#lab");
- spyOn(pattern.prototype, "render").and.returnValue(
- $("Rendering
")
- );
+ jest.spyOn(pattern.prototype, "render").mockImplementation(() => {
+ return $("Rendering
");
+ });
pattern.init($el);
expect($("#lab").html()).toBe("");
});
@@ -34,9 +39,11 @@ describe("pat-markdown", function () {
it("uses content for non-input elements", function () {
var $el = $('').text("This is markdown");
$el.appendTo("#lab");
- var spy_render = spyOn(pattern.prototype, "render").and.returnValue(
- $("")
- );
+ const spy_render = jest
+ .spyOn(pattern.prototype, "render")
+ .mockImplementation(() => {
+ return $("");
+ });
pattern.init($el);
expect(spy_render).toHaveBeenCalledWith("This is markdown");
});
@@ -46,22 +53,28 @@ describe("pat-markdown", function () {
"This is markdown"
);
$el.appendTo("#lab");
- var spy_render = spyOn(pattern.prototype, "render").and.returnValue(
- $("")
- );
+ const spy_render = jest
+ .spyOn(pattern.prototype, "render")
+ .mockImplementation(() => {
+ return $("");
+ });
pattern.init($el);
expect(spy_render).toHaveBeenCalledWith("This is markdown");
});
});
describe("when rendering", function () {
- it("wraps rendering in a div", function () {
- var $rendering = pattern.prototype.render("*This is markdown*");
+ it("wraps rendering in a div", async function () {
+ const $rendering = await pattern.prototype.render(
+ "*This is markdown*"
+ );
expect($rendering[0].tagName).toBe("DIV");
});
- it("converts markdown into HTML", function () {
- var $rendering = pattern.prototype.render("*This is markdown*");
+ it("converts markdown into HTML", async function () {
+ const $rendering = await pattern.prototype.render(
+ "*This is markdown*"
+ );
expect($rendering.html()).toBe("This is markdown
");
});
});
diff --git a/src/pat/markdown/standalone-test.html b/src/pat/markdown/standalone-test.html
index 5c5a797ab..ec261b767 100644
--- a/src/pat/markdown/standalone-test.html
+++ b/src/pat/markdown/standalone-test.html
@@ -5,11 +5,6 @@
-
Masonry Pattern demo
-
pat-colour-picker demo page
-
Minimalpattern Demo
-
Demo page
-
Navigation demo
-
Notification demo page
-
Demo page
-
Injection pattern
-
Demo for pat-scroll
-
Scroll demo
-
Scroll demo
-
", { id: "lab" }).appendTo(document.body);
- });
- afterEach(function () {
- $("#lab").remove();
- });
+ beforeEach(function () {
+ $("", { id: "lab" }).appendTo(document.body);
+ });
+ afterEach(function () {
+ $("#lab").remove();
+ jest.restoreAllMocks();
+ });
- it("will automatically scroll to an anchor if the trigger is set to 'auto'", function (done) {
+ describe("If the trigger is set to 'auto", function () {
+ it("will automatically scroll to an anchor if the trigger is set to 'auto'", async function (done) {
$("#lab").html(
[
'p1',
'',
].join("\n")
);
- // var spy_animate = spyOn($.fn, 'animate');
+ const spy_animate = jest.spyOn($.fn, "animate");
pattern.init($(".pat-scroll"));
- setTimeout(function () {
- // heisenbug: expect(spy_animate).toHaveBeenCalled();
- done();
- }, 2000);
+ await utils.timeout(10); // wait some ticks for async to settle.
+ expect(spy_animate).toHaveBeenCalled();
+ done();
});
});
describe("If the trigger is set to 'click'", function () {
- beforeEach(function () {
- $("", { id: "lab" }).appendTo(document.body);
- });
- afterEach(function () {
- $("#lab").remove();
- });
-
- it("will scroll to an anchor on click", function (done) {
+ it("will scroll to an anchor on click", async function (done) {
$("#lab").html(
[
'p1',
'',
].join("\n")
);
- var $el = $(".pat-scroll");
- // var spy_animate = spyOn($.fn, 'animate');
+ const $el = $(".pat-scroll");
+ const spy_animate = spyOn($.fn, "animate");
pattern.init($el);
- setTimeout(function () {
- $el.click();
- setTimeout(function () {
- // wait for scrolling via click to be done.
- // heisenbug: expect(spy_animate).toHaveBeenCalled();
- done();
- }, 2000);
- }, 2000);
+ await utils.timeout(1); // wait a tick for async to settle.
+ $el.click();
+ await utils.timeout(1); // wait a tick for async to settle.
+ // wait for scrolling via click to be done.
+ expect(spy_animate).toHaveBeenCalled();
+ done();
});
- it("will scroll to an anchor on pat-update with originalEvent of click", function (done) {
+ it("will scroll to an anchor on pat-update with originalEvent of click", async function (done) {
$("#lab").html(
[
'p1',
'',
].join("\n")
);
- var $el = $(".pat-scroll");
- // var spy_animate = spyOn($.fn, 'animate');
+ const $el = $(".pat-scroll");
+ const spy_animate = spyOn($.fn, "animate");
pattern.init($el);
+ await utils.timeout(1); // wait a tick for async to settle.
$el.trigger("pat-update", {
pattern: "stacks",
originalEvent: {
type: "click",
},
});
- setTimeout(function () {
- // heisenbug: expect(spy_animate).toHaveBeenCalled();
- console.log("Heisenbug");
- done();
- }, 3000);
+ expect(spy_animate).toHaveBeenCalled();
+ done();
});
});
});
diff --git a/src/pat/slides/composed-injection-test.html b/src/pat/slides/composed-injection-test.html
index 747bd0842..7e39ef166 100644
--- a/src/pat/slides/composed-injection-test.html
+++ b/src/pat/slides/composed-injection-test.html
@@ -5,11 +5,6 @@
-
Slideshows
-
-
", { id: "lab" }).appendTo(document.body);
- });
-
afterEach(function () {
- $("#lab").remove();
- });
-
- describe("init", function () {
- it("Return result from _hook", function () {
- var spy_hook = spyOn(pattern, "_hook").and.callFake(function () {
- return "jq";
- });
- var elements = $();
- expect(pattern.init(elements)).toBe("jq");
- expect(spy_hook).toHaveBeenCalledWith(elements);
- });
- });
-
- describe("_hook", function () {
- it("Return jQuery object", function () {
- const mock = {
- on: function () {
- return this;
- },
- off: function () {
- return this;
- },
- };
- expect(pattern._hook(mock)).toBe(mock);
- });
+ jest.restoreAllMocks();
});
describe("_collapse_ids", function () {
@@ -81,16 +52,17 @@ describe("pat-slides", function () {
expect(ids).toEqual(["slide1", "slide3"]);
});
- xit("Trigger reset when removing slides", function () {
+ it.skip("Trigger reset when removing slides", function () {
var $show = $("", { class: "pat-slides" });
- for (var i = 1; i <= 4; i++)
+ for (var i = 1; i <= 4; i++) {
$("", { class: "slide", id: "slide" + i }).appendTo(
$show
);
- spyOn(utils, "debounce").and.callFake(function (func) {
+ }
+ jest.spyOn(utils, "debounce").mockImplementation((func) => {
return func;
});
- var spy_reset = spyOn(pattern, "_reset");
+ var spy_reset = jest.spyOn(pattern, "_reset");
pattern._hook($show);
pattern._remove_slides($show, ["slide1", "slide3"]);
expect(spy_reset).toHaveBeenCalled();
diff --git a/src/pat/slides/standalone-test.html b/src/pat/slides/standalone-test.html
index dacdd550a..66207b800 100644
--- a/src/pat/slides/standalone-test.html
+++ b/src/pat/slides/standalone-test.html
@@ -5,11 +5,6 @@
-
Sortable demo page
-
Sticky
-
Subform
-
Switch demo page
-
pat-syntax-highlight demo page
-
Tabs demo
-
Toggle
-
pat-tooltip demo
-