From a860f42486b7e339155931d004e00a2ad7e21316 Mon Sep 17 00:00:00 2001 From: Kristin Valentine Date: Mon, 20 Jul 2020 16:08:48 -0700 Subject: [PATCH 1/7] add layout format --- lib/formats/layout.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/formats/layout.js diff --git a/lib/formats/layout.js b/lib/formats/layout.js new file mode 100644 index 0000000..dbb5008 --- /dev/null +++ b/lib/formats/layout.js @@ -0,0 +1,28 @@ +exports.private = { + type: 'line', + attribute: 'data-position' + }; + + exports.public = { + type: 'line', + add: function(node, value, dom) { + var container = node.ownerDocument.createElement('div'); + dom(node).wrap(container); + + switch (value) { + case 'default': + container.classList.add('default'); + break; + case 'default2': + container.classList.add('default2'); + break; + case 'default3': + container.classList.add('default3'); + break; + } + + // Return the original node, not the wrapper + return node; + } + }; + \ No newline at end of file From 93075590f1ec225a074759bbaff07424875ed9a7 Mon Sep 17 00:00:00 2001 From: Kristin Valentine Date: Wed, 12 Aug 2020 17:02:12 -0700 Subject: [PATCH 2/7] add component layout to doc object --- lib/formats/doc.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/formats/doc.js b/lib/formats/doc.js index b3f0dac..825adfd 100644 --- a/lib/formats/doc.js +++ b/lib/formats/doc.js @@ -4,6 +4,9 @@ exports.public = { var div = node.ownerDocument.createElement('div'); div.setAttribute('data-anthem-component', value.type + ':' + value.id); + if (value.product && value.product.layout) { + div.setAttribute('data-component-layout', value.product.layout); + } dom(node).replace(div); return div; From 4f26ccb498ca9495b0e0182296302c1178cde742 Mon Sep 17 00:00:00 2001 From: Kristin Valentine Date: Wed, 12 Aug 2020 17:27:06 -0700 Subject: [PATCH 3/7] use -data --- lib/formats/doc.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/formats/doc.js b/lib/formats/doc.js index 825adfd..af6b9b6 100644 --- a/lib/formats/doc.js +++ b/lib/formats/doc.js @@ -2,11 +2,14 @@ exports.public = { add: function(node, value, dom) { dom(node.parentNode).switchTag('div'); - var div = node.ownerDocument.createElement('div'); - div.setAttribute('data-anthem-component', value.type + ':' + value.id); + var data = {}; if (value.product && value.product.layout) { - div.setAttribute('data-component-layout', value.product.layout); + data.layout = value.product.layout; } + + var div = node.ownerDocument.createElement('div'); + div.setAttribute('data-anthem-component', value.type + ':' + value.id); + div.setAttribute('data-anthem-component-data', JSON.stringify(data)); dom(node).replace(div); return div; From 795dcd37d0683c361bad3f09ba175d4ff7a9c65d Mon Sep 17 00:00:00 2001 From: Kristin Valentine Date: Thu, 13 Aug 2020 17:54:31 -0700 Subject: [PATCH 4/7] don't pass empty data object --- lib/formats/doc.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/formats/doc.js b/lib/formats/doc.js index af6b9b6..144eb3f 100644 --- a/lib/formats/doc.js +++ b/lib/formats/doc.js @@ -2,14 +2,12 @@ exports.public = { add: function(node, value, dom) { dom(node.parentNode).switchTag('div'); - var data = {}; - if (value.product && value.product.layout) { - data.layout = value.product.layout; - } - var div = node.ownerDocument.createElement('div'); div.setAttribute('data-anthem-component', value.type + ':' + value.id); - div.setAttribute('data-anthem-component-data', JSON.stringify(data)); + if (value.product && value.product.layout) { + var data = { layout: value.product.layout }; + div.setAttribute('data-anthem-component-data', JSON.stringify(data)); + } dom(node).replace(div); return div; From 20d02f242855b01875695922437d117fdd214f7d Mon Sep 17 00:00:00 2001 From: Kristin Valentine Date: Tue, 18 Aug 2020 11:11:06 -0700 Subject: [PATCH 5/7] allow subdoc to pass any data param object --- lib/formats/doc.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/formats/doc.js b/lib/formats/doc.js index 144eb3f..9f92c83 100644 --- a/lib/formats/doc.js +++ b/lib/formats/doc.js @@ -4,8 +4,9 @@ exports.public = { var div = node.ownerDocument.createElement('div'); div.setAttribute('data-anthem-component', value.type + ':' + value.id); - if (value.product && value.product.layout) { - var data = { layout: value.product.layout }; + // if doc has data params object + if (value[value.type]) { + var data = value[value.type]; div.setAttribute('data-anthem-component-data', JSON.stringify(data)); } dom(node).replace(div); @@ -14,4 +15,5 @@ exports.public = { } }; -exports.private = require('./object')('doc'); +exports.private = require('./object')('doc') +; \ No newline at end of file From b95c2d50c30487ff46260b6c36a08ab2c4495e38 Mon Sep 17 00:00:00 2001 From: Kristin Valentine Date: Mon, 24 Aug 2020 12:06:39 -0700 Subject: [PATCH 6/7] cleanup --- lib/formats/doc.js | 4 ++-- lib/formats/layout.js | 28 ---------------------------- 2 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 lib/formats/layout.js diff --git a/lib/formats/doc.js b/lib/formats/doc.js index 9f92c83..e615202 100644 --- a/lib/formats/doc.js +++ b/lib/formats/doc.js @@ -6,6 +6,7 @@ exports.public = { div.setAttribute('data-anthem-component', value.type + ':' + value.id); // if doc has data params object if (value[value.type]) { + // should be an object var data = value[value.type]; div.setAttribute('data-anthem-component-data', JSON.stringify(data)); } @@ -15,5 +16,4 @@ exports.public = { } }; -exports.private = require('./object')('doc') -; \ No newline at end of file +exports.private = require('./object')('doc'); \ No newline at end of file diff --git a/lib/formats/layout.js b/lib/formats/layout.js deleted file mode 100644 index dbb5008..0000000 --- a/lib/formats/layout.js +++ /dev/null @@ -1,28 +0,0 @@ -exports.private = { - type: 'line', - attribute: 'data-position' - }; - - exports.public = { - type: 'line', - add: function(node, value, dom) { - var container = node.ownerDocument.createElement('div'); - dom(node).wrap(container); - - switch (value) { - case 'default': - container.classList.add('default'); - break; - case 'default2': - container.classList.add('default2'); - break; - case 'default3': - container.classList.add('default3'); - break; - } - - // Return the original node, not the wrapper - return node; - } - }; - \ No newline at end of file From eda50b90e7682baed57ad986ee0fcf4a8a38a548 Mon Sep 17 00:00:00 2001 From: Kristin Valentine Date: Tue, 25 Aug 2020 09:38:50 -0700 Subject: [PATCH 7/7] bump version --- README.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ccf3a8a..b1d7454 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ convert(delta, formats, { blockTag: 'FIGURE', inlineTag: 'INS' }); ## Changelog +- `5.5.0` Add support for data params in doc component - `5.4.1` Update dev dependencies to address security vulnerabilities - `5.4.0` Update jsdom and lodash dependencies - `5.3.0` Add support for Pym.js component diff --git a/package.json b/package.json index 56d8d97..c001f36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "convert-rich-text", - "version": "5.4.1", + "version": "5.5.0", "description": "Convert an insert-only rich-text delta into HTML", "main": "index.js", "browser": "browser.js",