Skip to content

Commit

Permalink
Nested Condition re-implemented using fieldType 1 (#7)
Browse files Browse the repository at this point in the history
* fix for nested condition using fieldType 1

* refactor: unused code removed

* fix for conditional test

* fix: format added in .prettierrc and file changed accordingly

* version bumped
  • Loading branch information
kkc-dev authored and p-mag committed Dec 11, 2019
1 parent 6ac6ed1 commit ab37380
Show file tree
Hide file tree
Showing 10 changed files with 1,323 additions and 591 deletions.
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"arrowParens": "always",
"bracketSpacing": false,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": true,
"printWidth": 120,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": false,
"version": "0.3.1",
"version": "0.3.2",
"name": "@zegal/sfdt-utils",
"description": "SFDT Utils",
"author": "Adam Tombleson <rekarnar@gmail.com>",
Expand Down
52 changes: 26 additions & 26 deletions src/queryBookmark.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
import get from 'lodash/get'
import {inline} from '../types/sfdt'
import get from 'lodash/get';
import {inline} from '../types/sfdt';
type inlineObject = inline;

// is inlineObject a bookmark?
export const isBookmark: (inlineObject?: inlineObject) => inlineObject | boolean = (inlineObject) => {
if (!inlineObject) return false;

if (inlineObject.bookmarkType !== undefined) {
return inlineObject
return inlineObject;
}

return false
}
return false;
};

// see if inlineObject is a bookmark matching the one we are checking for
export const isMatchingBookmark = (inlineObject, name) => {
const matched = isBookmark(inlineObject)
const matched = isBookmark(inlineObject);

if (get(matched, 'name') === name) {
return matched
return matched;
}

return false
}
return false;
};

export const isConditionalBookmark = (inlineObject, prefix = 'COND') => {
const {name} = inlineObject
return (isBookmark(inlineObject) && name && name.split('::').includes(prefix)) ? true : false
}
const {name} = inlineObject;
return isBookmark(inlineObject) && name && name.split('::').includes(prefix) ? true : false;
};

// is inlineObject a bookmark start object
export const isBookmarkStart = (inlineObject) => {
const matched = isBookmark(inlineObject)
const matched = isBookmark(inlineObject);

if (get(matched, 'bookmarkType') === 0) {
return matched
return matched;
}

return false
}
return false;
};

// is inlineObject a bookmark end object
export const isBookmarkEnd = (inlineObject) => {
const matched = isBookmark(inlineObject)
const matched = isBookmark(inlineObject);

if (get(matched, 'bookmarkType') === 1) {
return matched
return matched;
}

return false
}
return false;
};

export const isToggleStart = (inlineObject) => {
return get(inlineObject, 'hasFieldEnd') ? true : false
}
return get(inlineObject, 'hasFieldEnd') ? true : false;
};

export const isToggleEnd = (inlineObject) => {
return get(inlineObject, 'fieldType') === 2 ? true : false
}
return get(inlineObject, 'fieldType') === 1 ? true : false;
};

export const isToggleObject = (inlineObject) => {
return isToggleStart(inlineObject) || isToggleEnd(inlineObject)
}
return isToggleStart(inlineObject) || isToggleEnd(inlineObject);
};
248 changes: 124 additions & 124 deletions src/sfdt/__tests__/fixtures/bookmarkEndingInMultipleInlineSfdt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,136 +9,136 @@
* name: COND::9e7d0dc1-b9ed-4baa-9399-a4c4c9be96d4
*/
const firstInline = [
{
"text": ""
},
{
"characterFormat": {
"highlightColor": ""
},
"bookmarkType": 0,
"name": "COND::9e7d0dc1-b9ed-4baa-9399-a4c4c9be96d4"
},
{
"hasFieldEnd": true,
"fieldType": 0
},
{
"characterFormat": {
"highlightColor": ""
},
"bookmarkType": 0,
"name": "COND::410a27f0-117d-491d-ba28-48cf2ba058f1"
},
{
"hasFieldEnd": true,
"fieldType": 0
},
{
"characterFormat": {
"highlightColor": ""
},
"text": "This is first paragraph."
},
{
"fieldType": 2
},
{
"characterFormat": {
"highlightColor": ""
},
"bookmarkType": 1,
"name": "COND::410a27f0-117d-491d-ba28-48cf2ba058f1"
}
]
{
text: ''
},
{
characterFormat: {
highlightColor: ''
},
bookmarkType: 0,
name: 'COND::9e7d0dc1-b9ed-4baa-9399-a4c4c9be96d4'
},
{
hasFieldEnd: true,
fieldType: 0
},
{
characterFormat: {
highlightColor: ''
},
bookmarkType: 0,
name: 'COND::410a27f0-117d-491d-ba28-48cf2ba058f1'
},
{
hasFieldEnd: true,
fieldType: 0
},
{
characterFormat: {
highlightColor: ''
},
text: 'This is first paragraph.'
},
{
fieldType: 1
},
{
characterFormat: {
highlightColor: ''
},
bookmarkType: 1,
name: 'COND::410a27f0-117d-491d-ba28-48cf2ba058f1'
}
];

/**
* Conditional bookmark which start in firstInline end here
* name: COND::9e7d0dc1-b9ed-4baa-9399-a4c4c9be96d4
*/
const lastInline = [
{
"characterFormat": {
"highlightColor": ""
},
"text": "This is third paragraph."
},
{
"fieldType": 2
},
{
"characterFormat": {
"highlightColor": ""
},
"bookmarkType": 1,
"name": "COND::9e7d0dc1-b9ed-4baa-9399-a4c4c9be96d4"
}
]
{
characterFormat: {
highlightColor: ''
},
text: 'This is third paragraph.'
},
{
fieldType: 1
},
{
characterFormat: {
highlightColor: ''
},
bookmarkType: 1,
name: 'COND::9e7d0dc1-b9ed-4baa-9399-a4c4c9be96d4'
}
];

const sfdt = {
"sections": [
{
"sectionFormat": {
"pageWidth": 612,
"pageHeight": 792,
"leftMargin": 72,
"rightMargin": 72,
"topMargin": 72,
"bottomMargin": 72,
"differentFirstPage": false,
"differentOddAndEvenPages": false,
"headerDistance": 36,
"footerDistance": 36,
"bidi": false
},
"blocks": [
{
"paragraphFormat": {
"styleName": "Normal"
},
"inlines": firstInline
},
{
"paragraphFormat": {
"styleName": "Normal"
},
"characterFormat": {
"highlightColor": ""
},
"inlines": [
{
"characterFormat": {
"highlightColor": ""
},
"text": "This is second paragraph."
}
]
},
{
"paragraphFormat": {
"styleName": "Normal"
},
"characterFormat": {
"highlightColor": ""
},
"inlines": lastInline
},
{
"paragraphFormat": {
"styleName": "Normal"
},
"inlines": [
{
"characterFormat": {
"bidi": false
},
"text": "Keep Distance with me."
}
]
}
]
}
]
}
sections: [
{
sectionFormat: {
pageWidth: 612,
pageHeight: 792,
leftMargin: 72,
rightMargin: 72,
topMargin: 72,
bottomMargin: 72,
differentFirstPage: false,
differentOddAndEvenPages: false,
headerDistance: 36,
footerDistance: 36,
bidi: false
},
blocks: [
{
paragraphFormat: {
styleName: 'Normal'
},
inlines: firstInline
},
{
paragraphFormat: {
styleName: 'Normal'
},
characterFormat: {
highlightColor: ''
},
inlines: [
{
characterFormat: {
highlightColor: ''
},
text: 'This is second paragraph.'
}
]
},
{
paragraphFormat: {
styleName: 'Normal'
},
characterFormat: {
highlightColor: ''
},
inlines: lastInline
},
{
paragraphFormat: {
styleName: 'Normal'
},
inlines: [
{
characterFormat: {
bidi: false
},
text: 'Keep Distance with me.'
}
]
}
]
}
]
};

export default sfdt
export default sfdt;
Loading

0 comments on commit ab37380

Please sign in to comment.