@fiduswriter/document 0.1.0-alpha.1 → 0.1.0-alpha.3

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.
Files changed (41) hide show
  1. package/README.md +4 -0
  2. package/jest.config.js +2 -1
  3. package/package.json +3 -4
  4. package/src/citations/format.js +1 -1
  5. package/src/exporter/docx/comments.js +1 -1
  6. package/src/exporter/docx/images.js +1 -1
  7. package/src/exporter/docx/index.js +1 -1
  8. package/src/exporter/docx/metadata.js +1 -1
  9. package/src/exporter/docx/rels.js +1 -1
  10. package/src/exporter/docx/render.js +1 -1
  11. package/src/exporter/docx/richtext.js +1 -1
  12. package/src/exporter/epub/templates.js +1 -1
  13. package/src/exporter/html/citations.js +1 -1
  14. package/src/exporter/html/convert.js +1 -1
  15. package/src/exporter/html/index.js +1 -1
  16. package/src/exporter/html/templates.js +1 -1
  17. package/src/exporter/jats/bibliography.js +1 -1
  18. package/src/exporter/jats/convert.js +1 -1
  19. package/src/exporter/jats/index.js +1 -1
  20. package/src/exporter/jats/templates.js +1 -1
  21. package/src/exporter/jats/text.js +1 -1
  22. package/src/exporter/latex/index.js +1 -1
  23. package/src/exporter/native/shrink.js +1 -1
  24. package/src/exporter/odt/images.js +1 -1
  25. package/src/exporter/odt/index.js +1 -1
  26. package/src/exporter/odt/metadata.js +1 -1
  27. package/src/exporter/odt/render.js +1 -1
  28. package/src/exporter/odt/richtext.js +1 -1
  29. package/src/exporter/odt/track.js +1 -1
  30. package/src/exporter/pandoc/index.js +1 -1
  31. package/src/exporter/print/index.js +1 -1
  32. package/src/exporter/tools/svg.js +1 -1
  33. package/src/exporter/tools/xml_zip.js +1 -1
  34. package/src/exporter/tools/zip.js +1 -1
  35. package/src/importer/native/get_images.js +1 -1
  36. package/src/schema/document/content.js +1 -1
  37. package/src/common/blob.js +0 -10
  38. package/src/common/file.js +0 -25
  39. package/src/common/index.js +0 -12
  40. package/src/common/network.js +0 -79
  41. package/src/common/text.js +0 -44
package/README.md CHANGED
@@ -10,6 +10,10 @@ import {DocxConvert} from "@fiduswriter/document/importer/docx/convert.js"
10
10
  import {ExportFidusFile} from "@fiduswriter/document/exporter/native/file.js"
11
11
  ```
12
12
 
13
+ ## Dependencies
14
+
15
+ - `fwtoolkit` — shared utilities (text helpers, network helpers, etc.)
16
+
13
17
  ## Schema JSON
14
18
 
15
19
  A JSON serialization of the schema is exported as `schema.json` and regenerated
package/jest.config.js CHANGED
@@ -12,7 +12,8 @@ export default {
12
12
  "^biblatex-csl-converter$": "<rootDir>/test/exporter/mocks/biblatex-csl-converter.js",
13
13
  "^jszip$": "<rootDir>/test/importer/mocks/jszip.js",
14
14
  "^mathml-to-latex$": "<rootDir>/test/importer/mocks/mathml-to-latex.js",
15
- "^@fiduswriter/document/common$": "<rootDir>/test/exporter/mocks/common.js",
15
+ "^fwtoolkit$": "<rootDir>/test/exporter/mocks/common.js",
16
+ "^fwtoolkit/.*": "<rootDir>/test/exporter/mocks/common.js",
16
17
  "^@fiduswriter/document/citations/format$": "<rootDir>/test/exporter/mocks/citations-format.js",
17
18
  "^@fiduswriter/document/bibliography/csl_bib$": "<rootDir>/test/exporter/mocks/csl-bib-schema.js",
18
19
  "^@fiduswriter/document/mathlive/opf_includes$": "<rootDir>/test/exporter/mocks/empty-module.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiduswriter/document",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Fidus Writer document schema, importers and exporters",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,9 +16,7 @@
16
16
  "./importer/*": "./src/importer/*",
17
17
  "./exporter/*": "./src/exporter/*",
18
18
  "./citations/*": "./src/citations/*",
19
- "./bibliography/*": "./src/bibliography/*",
20
- "./common": "./src/common/index.js",
21
- "./common/*": "./src/common/*"
19
+ "./bibliography/*": "./src/bibliography/*"
22
20
  },
23
21
  "main": "jest.config.js",
24
22
  "directories": {
@@ -38,6 +36,7 @@
38
36
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js"
39
37
  },
40
38
  "dependencies": {
39
+ "fwtoolkit": "^0.1.1",
41
40
  "biblatex-csl-converter": "^3.0.0",
42
41
  "downloadjs": "^1.4.7",
43
42
  "fast-deep-equal": "^3.1.3",
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {citeprocSys} from "./citeproc_sys.js"
3
3
  /*
4
4
  * Use CSL and bibDB to format all citations for the given prosemirror json citation nodes
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {descendantNodes} from "../tools/doc_content.js"
3
3
 
4
4
  const DEFAULT_COMMENTS_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -1,4 +1,4 @@
1
- import {get} from "../../common/index.js"
1
+ import {get} from "fwtoolkit"
2
2
  import {descendantNodes} from "../tools/doc_content.js"
3
3
  import {svg2png} from "../tools/svg.js"
4
4
 
@@ -1,6 +1,6 @@
1
1
  import download from "downloadjs"
2
2
 
3
- import {shortFileTitle} from "../../common/index.js"
3
+ import {shortFileTitle} from "fwtoolkit"
4
4
  import {fixTables, removeHidden, textContent} from "../tools/doc_content.js"
5
5
  import {createSlug} from "../tools/file.js"
6
6
  import {XmlZip} from "../tools/xml_zip.js"
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
 
3
3
  export class DOCXExporterMetadata {
4
4
  constructor(xml, metadata, csl = null) {
@@ -1,5 +1,5 @@
1
1
  // manages the .rels files. Need to initialize one for each of document.xml and footnotes.xml
2
- import {escapeText} from "../../common/index.js"
2
+ import {escapeText} from "fwtoolkit"
3
3
 
4
4
  const DEFAULT_XML = `<?xml version="1.0" encoding="UTF-8"?>
5
5
  <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {BIBLIOGRAPHY_HEADERS} from "../../schema/i18n.js"
3
3
  import {textContent} from "../tools/doc_content.js"
4
4
  import {xmlDOM} from "../tools/xml.js"
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {CATS} from "../../schema/i18n.js"
3
3
 
4
4
  import {xmlDOM} from "../tools/xml.js"
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {mathliveOpfIncludes} from "../../mathlive/opf_includes.js"
3
3
 
4
4
  /** A template for the OPF file of an epub. */
@@ -1,5 +1,5 @@
1
1
  import {FormatCitations} from "../../citations/format.js"
2
- import {escapeText} from "../../common/index.js"
2
+ import {escapeText} from "fwtoolkit"
3
3
  import {BIBLIOGRAPHY_HEADERS} from "../../schema/i18n.js"
4
4
 
5
5
  export class HTMLExporterCitations {
@@ -1,7 +1,7 @@
1
1
  import {convertLatexToMathMl} from "mathlive"
2
2
  import pretty from "pretty"
3
3
 
4
- import {escapeText} from "../../common/index.js"
4
+ import {escapeText} from "fwtoolkit"
5
5
  import {CATS} from "../../schema/i18n.js"
6
6
  import {HTMLExporterCitations} from "./citations.js"
7
7
  import {displayNumber} from "./tools.js"
@@ -1,7 +1,7 @@
1
1
  import download from "downloadjs"
2
2
  import pretty from "pretty"
3
3
 
4
- import {shortFileTitle} from "../../common/index.js"
4
+ import {shortFileTitle} from "fwtoolkit"
5
5
  import {removeHidden} from "../tools/doc_content.js"
6
6
  import {createSlug} from "../tools/file.js"
7
7
  import {ZipFileCreator} from "../tools/zip.js"
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
 
3
3
  /** A template for HTML export of a document. */
4
4
  export const htmlExportTemplate = ({
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {convertTexts} from "./text.js"
3
3
 
4
4
  // This list is based on values listed at https://jats.nlm.nih.gov/archiving/tag-library/1.2/attribute/publication-type.html
@@ -1,6 +1,6 @@
1
1
  import {convertLatexToMathMl} from "mathlive"
2
2
 
3
- import {escapeText} from "../../common/index.js"
3
+ import {escapeText} from "fwtoolkit"
4
4
  import {CATS} from "../../schema/i18n.js"
5
5
 
6
6
  import {removeHidden} from "../tools/doc_content.js"
@@ -1,7 +1,7 @@
1
1
  import download from "downloadjs"
2
2
  import pretty from "pretty"
3
3
 
4
- import {shortFileTitle} from "../../common/index.js"
4
+ import {shortFileTitle} from "fwtoolkit"
5
5
  import {createSlug} from "../tools/file.js"
6
6
  import {ZipFileCreator} from "../tools/zip.js"
7
7
  import {JATSExporterConverter} from "./convert.js"
@@ -1,4 +1,4 @@
1
- import {escapeText, noSpaceTmp} from "../../common/index.js"
1
+ import {escapeText, noSpaceTmp} from "fwtoolkit"
2
2
 
3
3
  export const articleTemplate = ({front, body, back}) =>
4
4
  `<?xml version="1.0" encoding="UTF-8"?>
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
 
3
3
  export function convertTexts(nodeList) {
4
4
  return nodeList.map(node => convertText(node)).join("")
@@ -1,7 +1,7 @@
1
1
  import {BibLatexExporter} from "biblatex-csl-converter"
2
2
  import download from "downloadjs"
3
3
 
4
- import {shortFileTitle} from "../../common/index.js"
4
+ import {shortFileTitle} from "fwtoolkit"
5
5
  import {fixTables, removeHidden} from "../tools/doc_content.js"
6
6
  import {createSlug} from "../tools/file.js"
7
7
  import {ZipFileCreator} from "../tools/zip.js"
@@ -1,4 +1,4 @@
1
- import {addAlert} from "../../common/index.js"
1
+ import {addAlert} from "fwtoolkit"
2
2
  import {docSchema} from "../../schema/document/index.js"
3
3
  import {toMiniJSON} from "../../schema/mini_json.js"
4
4
  // Generate a copy of the fidus doc, imageDB and bibDB with all clutter removed.
@@ -1,4 +1,4 @@
1
- import {get} from "../../common/index.js"
1
+ import {get} from "fwtoolkit"
2
2
  import {descendantNodes} from "../tools/doc_content.js"
3
3
  import {svg2png} from "../tools/svg.js"
4
4
 
@@ -1,6 +1,6 @@
1
1
  import download from "downloadjs"
2
2
 
3
- import {shortFileTitle} from "../../common/index.js"
3
+ import {shortFileTitle} from "fwtoolkit"
4
4
 
5
5
  import {fixTables, removeHidden, textContent} from "../tools/doc_content.js"
6
6
  import {createSlug} from "../tools/file.js"
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
 
3
3
  export class ODTExporterMetadata {
4
4
  constructor(xml, styles, metadata, csl = null) {
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {BIBLIOGRAPHY_HEADERS} from "../../schema/i18n.js"
3
3
  import {textContent} from "../tools/doc_content.js"
4
4
  import {xmlDOM} from "../tools/xml.js"
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {CATS} from "../../schema/i18n.js"
3
3
  import {createZoteroCitation} from "../tools/zotero_csl.js"
4
4
 
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
 
3
3
  export class ODTExporterTracks {
4
4
  constructor(xml) {
@@ -1,7 +1,7 @@
1
1
  import {BibLatexExporter} from "biblatex-csl-converter"
2
2
  import download from "downloadjs"
3
3
 
4
- import {shortFileTitle} from "../../common/index.js"
4
+ import {shortFileTitle} from "fwtoolkit"
5
5
  import {fixTables, removeHidden} from "../tools/doc_content.js"
6
6
  import {createSlug} from "../tools/file.js"
7
7
  import {ZipFileCreator} from "../tools/zip.js"
@@ -1,5 +1,5 @@
1
1
  import {printHTML} from "@vivliostyle/print"
2
- import {addAlert, shortFileTitle} from "../../common/index.js"
2
+ import {addAlert, shortFileTitle} from "fwtoolkit"
3
3
  import {PAPER_SIZES} from "../../schema/const.js"
4
4
  import {HTMLExporter} from "../html/index.js"
5
5
  import {HTMLExporterConvert} from "../html/convert.js"
@@ -1,4 +1,4 @@
1
- import {convertDataURIToBlob} from "../../common/index.js"
1
+ import {convertDataURIToBlob} from "fwtoolkit"
2
2
 
3
3
  export function svg2png(blob) {
4
4
  const img = document.createElement("img")
@@ -1,6 +1,6 @@
1
1
  import {xmlDOM} from "./xml.js"
2
2
 
3
- import {get} from "../../common/index.js"
3
+ import {get} from "fwtoolkit"
4
4
  // Handle a zip file containing XML files. Make sure files are only opened once,
5
5
  // and provide a mechanism to save the file.
6
6
 
@@ -1,4 +1,4 @@
1
- import {convertDataURIToBlob, get} from "../../common/index.js"
1
+ import {convertDataURIToBlob, get} from "fwtoolkit"
2
2
 
3
3
  /** Creates a zip file.
4
4
  * @function zipFileCreator
@@ -1,4 +1,4 @@
1
- import {get} from "../../common/index.js"
1
+ import {get} from "fwtoolkit"
2
2
 
3
3
  export class GetImages {
4
4
  constructor(images, entries) {
@@ -1,4 +1,4 @@
1
- import {escapeText} from "../../common/index.js"
1
+ import {escapeText} from "fwtoolkit"
2
2
  import {parseTracks} from "../common/index.js"
3
3
  import {fnNodeToHtml, htmlToFnNode} from "../footnotes_convert.js"
4
4
 
@@ -1,10 +0,0 @@
1
- export const convertDataURIToBlob = dataURI => {
2
- const byteString = atob(dataURI.split(",")[1])
3
- const mimeString = dataURI.split(",")[0].split(":")[1].split(";")[0]
4
- const ab = new ArrayBuffer(byteString.length)
5
- const ia = new Uint8Array(ab)
6
- for (let i = 0; i < byteString.length; i++) {
7
- ia[i] = byteString.charCodeAt(i)
8
- }
9
- return new Blob([ab], {type: mimeString})
10
- }
@@ -1,25 +0,0 @@
1
- import {escapeText} from "./text.js"
2
-
3
- export const shortFileTitle = (title, path) => {
4
- if (!path.length || path.endsWith("/")) {
5
- return escapeText(title || gettext("Untitled"))
6
- }
7
- return escapeText(path.split("/").pop())
8
- }
9
-
10
- export const longFilePath = (title, path, prefix = "") => {
11
- if (!path.length) {
12
- path = "/"
13
- }
14
- if (path.endsWith("/")) {
15
- path += title.replace(/\//g, "") || gettext("Untitled")
16
- }
17
- if (prefix.length) {
18
- const pathParts = path.split("/")
19
- const fileName = pathParts.pop()
20
- pathParts.push(prefix + fileName)
21
- path = pathParts.join("/")
22
- }
23
-
24
- return path
25
- }
@@ -1,12 +0,0 @@
1
- export {escapeText, unescapeText, noSpaceTmp} from "./text.js"
2
- export {convertDataURIToBlob} from "./blob.js"
3
- export {shortFileTitle, longFilePath} from "./file.js"
4
- export {get, post, postJson} from "./network.js"
5
-
6
- export const addAlert = (type, message) => {
7
- if (typeof console !== "undefined") {
8
- console.log(`[@fiduswriter/document alert][${type}] ${message}`)
9
- }
10
- }
11
-
12
- export const deactivateWait = () => {}
@@ -1,79 +0,0 @@
1
- const getCookie = name => {
2
- if (typeof document === "undefined" || !document.cookie) {
3
- return ""
4
- }
5
- const cookie = document.cookie
6
- .split(";")
7
- .map(cookie => cookie.trim())
8
- .find(cookie => cookie.substring(0, name.length + 1) === `${name}=`)
9
- return cookie ? decodeURIComponent(cookie.substring(name.length + 1)) : ""
10
- }
11
-
12
- const handleFetchErrors = response => {
13
- if (!response.ok) {
14
- throw response
15
- }
16
- return response
17
- }
18
-
19
- export const get = (url, params = {}) => {
20
- const csrfToken = getCookie("csrftoken")
21
- const queryString = Object.keys(params)
22
- .map(
23
- key =>
24
- `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
25
- )
26
- .join("&")
27
- if (queryString.length) {
28
- url = `${url}?${queryString}`
29
- }
30
- return fetch(url, {
31
- method: "GET",
32
- headers: {
33
- "X-CSRFToken": csrfToken,
34
- Accept: "application/json",
35
- "X-Requested-With": "XMLHttpRequest"
36
- },
37
- credentials: "include"
38
- }).then(handleFetchErrors)
39
- }
40
-
41
- export const post = (url, object = {}, files = {}) => {
42
- const csrfToken = getCookie("csrftoken")
43
- const fetchOptions = {
44
- method: "POST",
45
- headers: {
46
- "X-CSRFToken": csrfToken,
47
- Accept: "application/json",
48
- "X-Requested-With": "XMLHttpRequest"
49
- },
50
- credentials: "include"
51
- }
52
-
53
- if (Object.keys(files).length) {
54
- const body = new FormData()
55
- body.append("csrfmiddlewaretoken", csrfToken)
56
- body.append("json", JSON.stringify(object))
57
- Object.keys(files).forEach(key => {
58
- const value = files[key]
59
- if (typeof value === "object" && value.file && value.filename) {
60
- body.append(key, value.file, value.filename)
61
- } else if (Array.isArray(value)) {
62
- value.forEach(item => body.append(`${key}[]`, item))
63
- } else {
64
- body.append(key, value)
65
- }
66
- })
67
- fetchOptions.body = body
68
- } else {
69
- fetchOptions.headers["Content-Type"] = "application/json"
70
- fetchOptions.body = JSON.stringify(object)
71
- }
72
-
73
- return fetch(url, fetchOptions).then(handleFetchErrors)
74
- }
75
-
76
- export const postJson = (url, object = {}, files = {}) =>
77
- post(url, object, files).then(response =>
78
- response.json().then(json => ({json, status: response.status}))
79
- )
@@ -1,44 +0,0 @@
1
- export const escapeText = text => {
2
- if (typeof text !== "string") {
3
- return String(text)
4
- }
5
- return text
6
- .replace(/&/g, "&amp;")
7
- .replace(/</g, "&lt;")
8
- .replace(/>/g, "&gt;")
9
- .replace(/"/g, "&quot;")
10
- .replace(
11
- /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]/g,
12
- ""
13
- ) // invalid in XML chars
14
- }
15
-
16
- export const unescapeText = text =>
17
- text
18
- .replace(/&lt;/g, "<")
19
- .replace(/&gt;/g, ">")
20
- .replace(/&quot;/g, '"')
21
- .replace(/&amp;/g, "&")
22
-
23
- /**
24
- * Turn string literals into single line, removing spaces at start of line
25
- */
26
- export const noSpaceTmp = (strings, ...values) => {
27
- const tmpStrings = Array.from(strings)
28
-
29
- let combined = ""
30
- while (tmpStrings.length > 0 || values.length > 0) {
31
- if (tmpStrings.length > 0) {
32
- combined += tmpStrings.shift()
33
- }
34
- if (values.length > 0) {
35
- combined += values.shift()
36
- }
37
- }
38
-
39
- let out = ""
40
- combined.split("\n").forEach(line => {
41
- out += line.replace(/^\s*/g, "")
42
- })
43
- return out
44
- }