Skip to content

Commit

Permalink
feat(AdfEqual): Updates to make the ADF closer to what Confluence ret…
Browse files Browse the repository at this point in the history
…urns
  • Loading branch information
andymac4182 committed Apr 17, 2023
1 parent a64a176 commit 348f00e
Show file tree
Hide file tree
Showing 10 changed files with 451 additions and 88 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/pr-check.yml
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- main

concurrency:
group: "ci-check"
cancel-in-progress: false

jobs:
build-and-lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -40,6 +44,10 @@ jobs:
id: tests
continue-on-error: true
run: npm run test
env:
ATLASSIAN_SITE_URL: ${{ secrets.ATLASSIAN_SITE_URL }}
ATLASSIAN_USERNAME: ${{ secrets.ATLASSIAN_USERNAME }}
ATLASSIAN_API_TOKEN: ${{ secrets.ATLASSIAN_API_TOKEN }}

- name: Run npm build
id: build
Expand Down
41 changes: 37 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -20,6 +20,7 @@
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/deep-equal": "^1.0.1",
"@types/lodash": "^4.14.194",
"@types/markdown-it": "^12.2.3",
"@types/mime-types": "^2.1.1",
"@types/node": "^16.11.6",
Expand Down Expand Up @@ -57,6 +58,7 @@
"deep-equal": "^2.2.0",
"formdata-node": "^5.0.0",
"gray-matter": "^4.0.3",
"lodash": "^4.17.21",
"markdown-it-table": "^2.0.4",
"mermaid": "^10.1.0",
"mime-types": "^2.1.35",
Expand All @@ -66,6 +68,7 @@
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-intl-next": "npm:react-intl@^5.18.1",
"sort-any": "^4.0.5",
"spark-md5": "^3.0.2",
"uuid": "^9.0.0"
},
Expand Down
40 changes: 40 additions & 0 deletions src/AdfEqual.ts
@@ -0,0 +1,40 @@
import sortAny from "sort-any";
import { mapValues } from "lodash";
import { traverse } from "@atlaskit/adf-utils/traverse";
import { JSONDocNode } from "@atlaskit/editor-json-transformer";
import deepEqual from "deep-equal";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sortDeep = (object: unknown): any => {
if (object instanceof Map) {
return sortAny([...object]);
}
if (!Array.isArray(object)) {
if (
typeof object !== "object" ||
object === null ||
object instanceof Date
) {
return object;
}

return mapValues(object, sortDeep);
}

return sortAny(object.map(sortDeep));
};

export function orderMarks(adf: JSONDocNode) {
return traverse(adf, {
any: (node, __parent) => {
if (node.marks) {
node.marks = sortDeep(node.marks);
return node;
}
},
});
}

export function adfEqual(first: JSONDocNode, second: JSONDocNode): boolean {
return deepEqual(orderMarks(first), orderMarks(second));
}
21 changes: 0 additions & 21 deletions src/AdfPostProcess.ts
Expand Up @@ -48,27 +48,6 @@ export function prepareAdf(
}
}
},
table: (node, _parent) => {
if (
node.attrs &&
"isNumberColumnEnabled" in node.attrs &&
node.attrs["isNumberColumnEnabled"] === false
) {
delete node.attrs["isNumberColumnEnabled"];
}
return node;
},
tableRow: (node, _parent) => {
return node;
},
tableHeader: (node, _parent) => {
node.attrs = { colspan: 1, rowspan: 1, colwidth: [340] };
return node;
},
tableCell: (node, _parent) => {
node.attrs = { colspan: 1, rowspan: 1, colwidth: [340] };
return node;
},
}) as JSONDocNode;
});
}

0 comments on commit 348f00e

Please sign in to comment.