Skip to content

Commit fb4539e

Browse files
authored
Merge pull request #13 from contentstack/feature/live-preview
Feature/live preview
2 parents b82f996 + 7805082 commit fb4539e

File tree

8 files changed

+2741
-3252
lines changed

8 files changed

+2741
-3252
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.1.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.1.0) (2021-10-19)
4+
- Live preview edit tags support added
5+
36
## [1.0.1](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.0.1) (2021-05-26)
47
- Dependency update
58
## [1.0.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.0.0) (2021-04-05)

badges/badge-branches.svg

Lines changed: 1 addition & 1 deletion
Loading

jestconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"transform": {
33
"^.+\\.(t|j)sx?$": "ts-jest"
44
},
5-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
5+
"testMatch": [
6+
"**/__test__/**/?(*.)+(spec|test).[jt]s?(x)"
7+
],
68
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
79

810
"collectCoverage": true,

package-lock.json

Lines changed: 2684 additions & 3245 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/utils",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "Contentstack utilities for Javascript",
55
"main": "dist/index.es.js",
66
"types": "dist/types/index.d.ts",
@@ -39,8 +39,8 @@
3939
"babel-core": "^6.26.3",
4040
"babel-loader": "8.1.0",
4141
"babel-preset-es2015": "^6.24.1",
42-
"eslint": "^7.9.0",
43-
"jest": "^26.4.2",
42+
"eslint": "^8.0.1",
43+
"jest": "^27.2.5",
4444
"jest-coverage-badges": "^1.1.2",
4545
"jest-html-reporters": "^2.0.4",
4646
"jsdoc": "^3.6.7",
@@ -50,7 +50,7 @@
5050
"rollup-plugin-node-resolve": "^5.2.0",
5151
"rollup-plugin-sourcemaps": "^0.6.3",
5252
"rollup-plugin-typescript2": "^0.28.0",
53-
"ts-jest": "^26.3.0",
53+
"ts-jest": "^27.0.0-next.12",
5454
"tslint": "^6.1.3",
5555
"tslint-config-prettier": "^1.18.0",
5656
"typescript": "^4.0.5"

src/entry-editable.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { EntryModel } from ".";
2+
3+
export function addTags(entry: EntryModel, contentTypeUid: string, tagsAsObject: boolean, locale: string = 'en-us') : void {
4+
if (entry)
5+
entry["$"] = getTag(entry, `${contentTypeUid}.${entry.uid}.${locale}`, tagsAsObject, locale)
6+
}
7+
8+
function getTag(content: object, prefix: string, tagsAsObject: boolean, locale: string): object {
9+
let tags: any = {}
10+
Object.entries(content).forEach(([key, value]) => {
11+
switch (typeof value) {
12+
case "object":
13+
if (Array.isArray(value)) {
14+
value.forEach((obj, index) => {
15+
if ((typeof obj !== 'undefined' || obj !== null) && obj._content_type_uid !== undefined && obj.uid !== undefined) {
16+
value[index]['$'] = getTag(obj, `${obj._content_type_uid}.${obj.uid}.${obj.locale || locale}`, tagsAsObject, locale)
17+
}else {
18+
if (typeof obj === "object") {
19+
obj['$'] = getTag(obj, `${prefix}.${key}.${index}`, tagsAsObject, locale)
20+
} else {
21+
tags[key] = getTagsValue(`${prefix}.${key}`, tagsAsObject)
22+
}
23+
}
24+
})
25+
}else {
26+
if (value) {
27+
value["$"] = getTag(value, `${prefix}.${key}`, tagsAsObject, locale)
28+
}
29+
}
30+
break;
31+
default:
32+
tags[key] = getTagsValue(`${prefix}.${key}`, tagsAsObject)
33+
}
34+
})
35+
return tags
36+
}
37+
38+
function getTagsValue (dataValue:string, tagsAsObject: boolean): any {
39+
if (tagsAsObject) {
40+
return { "data-cslp": dataValue };
41+
} else {
42+
return `data-cslp=${dataValue}`;
43+
}
44+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export { default as Document } from './nodes/document'
1212
export { default as TextNode } from './nodes/text';
1313
export { jsonToHTML } from './json-to-html'
1414
export { GQL } from './gql'
15+
export { addTags as addEditableTags } from './entry-editable'

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"sourceMap": true,
2020
},
2121
"include": ["src"],
22-
"exclude": ["node_modules", "__tests__"]
22+
"exclude": ["node_modules", "__test__"]
2323
}

0 commit comments

Comments
 (0)