@adobe/helix-importer 2.6.0 → 2.8.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [2.8.0](https://github.com/adobe/helix-importer/compare/v2.7.0...v2.8.0) (2023-02-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * add waitForElement DOMUtils ([#94](https://github.com/adobe/helix-importer/issues/94)) ([ca041f3](https://github.com/adobe/helix-importer/commit/ca041f30f39b0d511fbbe30a1410b2c013826a0d))
7
+
8
+ # [2.7.0](https://github.com/adobe/helix-importer/compare/v2.6.0...v2.7.0) (2023-02-06)
9
+
10
+
11
+ ### Features
12
+
13
+ * allow from property ([#92](https://github.com/adobe/helix-importer/issues/92)) ([91f9681](https://github.com/adobe/helix-importer/commit/91f96812ce8062d860f57fa38d1795b8df242c55))
14
+
1
15
  # [2.6.0](https://github.com/adobe/helix-importer/compare/v2.5.16...v2.6.0) (2023-01-31)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-importer",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "description": "Helix Importer tool: create md / docx from html",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -26,25 +26,25 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@adobe/eslint-config-helix": "2.0.1",
29
- "@adobe/helix-docx2md": "1.3.13",
30
- "@adobe/helix-mediahandler": "2.0.4",
29
+ "@adobe/helix-docx2md": "1.3.14",
30
+ "@adobe/helix-mediahandler": "2.0.6",
31
31
  "@semantic-release/changelog": "6.0.2",
32
32
  "@semantic-release/exec": "6.0.3",
33
33
  "@semantic-release/git": "10.0.1",
34
34
  "c8": "7.12.0",
35
35
  "dirname-filename-esm": "1.1.1",
36
- "eslint": "8.32.0",
36
+ "eslint": "8.33.0",
37
37
  "husky": "8.0.3",
38
38
  "lint-staged": "13.1.0",
39
39
  "mocha": "10.2.0",
40
40
  "mocha-multi-reporters": "1.5.1",
41
41
  "mock-fs": "5.2.0",
42
- "semantic-release": "19.0.5"
42
+ "semantic-release": "20.1.0"
43
43
  },
44
44
  "license": "Apache-2.0",
45
45
  "dependencies": {
46
46
  "@adobe/helix-markdown-support": "6.1.1",
47
- "@adobe/helix-md2docx": "2.0.37",
47
+ "@adobe/helix-md2docx": "2.0.39",
48
48
  "@adobe/mdast-util-gridtables": "1.0.6",
49
49
  "@adobe/remark-gridtables": "1.0.2",
50
50
  "form-data": "4.0.0",
@@ -120,6 +120,8 @@ async function html2x(
120
120
 
121
121
  if (result.element) {
122
122
  extra.html = result.element.outerHTML;
123
+ } else if (result.from) {
124
+ extra.from = result.from;
123
125
  }
124
126
 
125
127
  if (result.report) {
@@ -190,6 +192,10 @@ async function html2x(
190
192
  res.html = pir.extra.html;
191
193
  }
192
194
 
195
+ if (pir.extra.from) {
196
+ res.from = pir.extra.from;
197
+ }
198
+
193
199
  if (pir.extra.report) {
194
200
  res.report = pir.extra.report;
195
201
  }
package/src/index.js CHANGED
@@ -23,6 +23,7 @@ import Blocks from './utils/Blocks.js';
23
23
  import CSV from './utils/CSV.js';
24
24
  import DOMUtils from './utils/DOMUtils.js';
25
25
  import FileUtils from './utils/FileUtils.js';
26
+ import Loader from './utils/Loader.js';
26
27
  import Utils from './utils/Utils.js';
27
28
 
28
29
  import WPUtils from './wp/WPUtils.js';
@@ -44,6 +45,7 @@ export {
44
45
  CSV,
45
46
  DOMUtils,
46
47
  FileUtils,
48
+ Loader,
47
49
  Utils,
48
50
  WPUtils,
49
51
  WPAdminAjaxPager,
@@ -263,4 +263,19 @@ export default class DOMUtils {
263
263
  }
264
264
  return null;
265
265
  }
266
+
267
+ static async waitForElement(selector, document, timeout = 5000, interval = 250) {
268
+ return new Promise((resolve, reject) => {
269
+ const timeWas = new Date();
270
+ const wait = setInterval(() => {
271
+ if (document.querySelector(selector)) {
272
+ clearInterval(wait);
273
+ resolve();
274
+ } else if (new Date() - timeWas > timeout) { // Timeout
275
+ clearInterval(wait);
276
+ reject();
277
+ }
278
+ }, interval);
279
+ });
280
+ }
266
281
  }
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default class Loader {
14
+ static async waitForElement(selector, document, timeout = 5000, interval = 250) {
15
+ return new Promise((resolve, reject) => {
16
+ const timeWas = new Date();
17
+ const wait = setInterval(() => {
18
+ if (document.querySelector(selector)) {
19
+ clearInterval(wait);
20
+ resolve();
21
+ } else if (new Date() - timeWas > timeout) { // Timeout
22
+ clearInterval(wait);
23
+ reject();
24
+ }
25
+ }, interval);
26
+ });
27
+ }
28
+ }
@@ -234,6 +234,7 @@ describe('html2md tests', () => {
234
234
  const out = await html2md('https://www.sample.com/page.html', '<html><body><h1>Hello World</h1></body></html>', {
235
235
  transform: () => [{
236
236
  path: '/my-custom-path-p1',
237
+ from: 'https://www.sample.com/page.html',
237
238
  report: {
238
239
  custom: 'A custom property',
239
240
  customArray: ['a', 'b', 'c'],
@@ -253,6 +254,7 @@ describe('html2md tests', () => {
253
254
  strictEqual(out.md, undefined);
254
255
  strictEqual(out.docx, undefined);
255
256
  strictEqual(out.path, '/my-custom-path-p1');
257
+ strictEqual(out.from, 'https://www.sample.com/page.html');
256
258
  ok(out.report);
257
259
  strictEqual(out.report.custom, 'A custom property');
258
260
  deepStrictEqual(out.report.customArray, ['a', 'b', 'c']);
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ /* eslint-disable no-shadow */
14
+
15
+ import { rejects, doesNotReject } from 'assert';
16
+ import { describe, it } from 'mocha';
17
+
18
+ import { JSDOM } from 'jsdom';
19
+
20
+ import Loader from '../../src/utils/Loader.js';
21
+
22
+ describe('Loader#waitForElement', () => {
23
+ it('should fail for non existing element', async () => {
24
+ const { document } = (new JSDOM()).window;
25
+ const div = document.createElement('div');
26
+ document.body.appendChild(div);
27
+ await rejects(async () => {
28
+ await Loader.waitForElement('.dummy', document, 25, 20);
29
+ });
30
+ });
31
+
32
+ it('should find existing element', async () => {
33
+ const { document } = (new JSDOM()).window;
34
+ const div = document.createElement('div');
35
+ div.classList.add('dummy');
36
+ document.body.appendChild(div);
37
+ await doesNotReject(async () => {
38
+ await Loader.waitForElement('.dummy', document, 100, 20);
39
+ });
40
+ });
41
+
42
+ it('should wait for element to appear in the DOM', async () => {
43
+ const { document } = (new JSDOM()).window;
44
+ setTimeout(() => {
45
+ const div = document.createElement('div');
46
+ div.classList.add('dummy');
47
+ document.body.appendChild(div);
48
+ }, 50);
49
+ await doesNotReject(async () => {
50
+ await Loader.waitForElement('.dummy', document, 100, 20);
51
+ });
52
+ });
53
+ });