From 73446623425cf8be5e211650c03b71e5b0ba9908 Mon Sep 17 00:00:00 2001 From: caub Date: Thu, 22 Sep 2022 12:23:40 +0200 Subject: [PATCH 1/2] Pass inline prop to block.markdown() --- dist/wurd-react.cjs.js | 4 ++-- dist/wurd-react.esm.js | 4 ++-- dist/wurd-react.js | 7 +++++-- dist/wurd-react.min.js | 2 +- src/markdown.js | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dist/wurd-react.cjs.js b/dist/wurd-react.cjs.js index 2b757b8..88259e3 100644 --- a/dist/wurd-react.cjs.js +++ b/dist/wurd-react.cjs.js @@ -36,12 +36,12 @@ function WurdMarkdown({ block, id, sid, type = 'div', component: Component = type, - vars, + vars, inline, ...rest }) { block = block || wurd__default["default"].content; - const text = block.markdown(id, vars); + const text = block.markdown(id, vars, { inline }); const elProps = { ...rest, diff --git a/dist/wurd-react.esm.js b/dist/wurd-react.esm.js index 8792729..5e28a9e 100644 --- a/dist/wurd-react.esm.js +++ b/dist/wurd-react.esm.js @@ -28,12 +28,12 @@ function WurdMarkdown({ block, id, sid, type = 'div', component: Component = type, - vars, + vars, inline, ...rest }) { block = block || wurd.content; - const text = block.markdown(id, vars); + const text = block.markdown(id, vars, { inline }); const elProps = { ...rest, diff --git a/dist/wurd-react.js b/dist/wurd-react.js index 2d83e5c..60aea44 100644 --- a/dist/wurd-react.js +++ b/dist/wurd-react.js @@ -730,7 +730,7 @@ return /*#__PURE__*/React__default["default"].createElement(Component, elProps, text); } - var _excluded$3 = ["block", "id", "sid", "type", "component", "vars"]; + var _excluded$3 = ["block", "id", "sid", "type", "component", "vars", "inline"]; function WurdMarkdown(_ref) { var block = _ref.block, id = _ref.id, @@ -740,10 +740,13 @@ _ref$component = _ref.component, Component = _ref$component === void 0 ? type : _ref$component, vars = _ref.vars, + inline = _ref.inline, rest = _objectWithoutProperties(_ref, _excluded$3); block = block || instance.content; - var text = block.markdown(id, vars); + var text = block.markdown(id, vars, { + inline: inline + }); var elProps = _objectSpread2(_objectSpread2({}, rest), {}, { dangerouslySetInnerHTML: { diff --git a/dist/wurd-react.min.js b/dist/wurd-react.min.js index 00aaf6c..4f637ae 100644 --- a/dist/wurd-react.min.js +++ b/dist/wurd-react.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).wurd={},t.React)}(this,function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var f=r(e);function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function h(e){for(var t=1;t').concat(i,"")}return i}}]),o}(),d=function(){function n(t){var e=this,r=1').concat(t,"")):t}}]),r}(),e=function(){function r(t){var e=this,n=1 Date: Thu, 22 Sep 2022 12:28:49 +0200 Subject: [PATCH 2/2] update deps --- dist/wurd-react.min.js | 2 +- package.json | 10 +++++----- rollup.config.js | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/wurd-react.min.js b/dist/wurd-react.min.js index 4f637ae..a8b8b2d 100644 --- a/dist/wurd-react.min.js +++ b/dist/wurd-react.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).wurd={},t.React)}(this,function(t,e){"use strict";function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var c=n(e);function r(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function s(e){for(var t=1;t').concat(t,"")):t}}]),r}(),e=function(){function r(t){var e=this,n=1=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}var l=function(){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a(this,t),this.rawContent=n,this.storageKey=r.storageKey||"wurdContent",this.ttl=null!==(e=r.ttl)&&void 0!==e?e:36e5}return s(t,[{key:"get",value:function(t){return t?t.split(".").reduce((function(t,e){return t&&t[e]}),this.rawContent):this.rawContent}},{key:"load",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.lang,r=this.rawContent,o=this.storageKey,i=this.ttl;try{var a=JSON.parse(localStorage.getItem(o)),c=a&&a._wurd;return!a||!c||c.savedAt+i1&&void 0!==arguments[1]?arguments[1]:{},n=e.lang,r=this.rawContent,o=this.storageKey;Object.assign(r,t),localStorage.setItem(o,JSON.stringify(i(i({},r),{},{_wurd:{savedAt:Date.now(),lang:n}})))}},{key:"clear",value:function(){localStorage.removeItem(this.storageKey)}}]),t}(),f=function(){function t(e,n){var r=this;a(this,t),this.wurd=e,this.path=n,this._get=e.store.get.bind(e.store),Object.getOwnPropertyNames(Object.getPrototypeOf(this)).forEach((function(t){r[t]=r[t].bind(r)}))}return s(t,[{key:"id",value:function(t){return t?this.path?[this.path,t].join("."):t:this.path}},{key:"get",value:function(t){var e=this._get(this.id(t));if(void 0===e&&this.wurd.draft){var n=t.split(".")[0];this._get(n)||console.warn("Tried to access unloaded section: ".concat(n))}return e}},{key:"text",value:function(t,e){var n=this.get(t);return void 0===n?this.wurd.draft?"[".concat(t,"]"):"":"string"!=typeof n?(console.warn("Tried to get object as string: ".concat(t)),this.wurd.draft?"[".concat(t,"]"):""):(e&&(n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"string"!=typeof t?t:t.replace(/{{([\w.-]+)}}/g,(function(t,n){return e[n]||""}))}(n,e)),n)}},{key:"markdown",value:function(t,e,n){var r=this.wurd.markdown,o=r.parse,i=r.parseInline,a=this.text(t,e);return null!=n&&n.inline&&i?i(a):o?o(a):a}},{key:"map",value:function(t,e){var n=this,r=this.get(t)||u({},Date.now(),{}),o=0;return Object.keys(r).sort().map((function(r){var i=o;o++;var a=[t,r].join("."),c=n.block(a);return e.call(void 0,c,i)}))}},{key:"block",value:function(e,n){var r=this.id(e),o=new t(this.wurd,r);return"function"==typeof n?n.call(void 0,o):o}},{key:"el",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=this.id(t),o=n.markdown?this.markdown(t,e):this.text(t,e),i=e||n.markdown?"data-wurd-md":"data-wurd";if(this.wurd.draft){var a=n.type||"span";return n.markdown&&(a="div"),"<".concat(a," ").concat(i,'="').concat(r,'">').concat(o,"")}return o}}]),t}(),h=function(){function t(e){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a(this,t),this.widgetUrl="https://widget.wurd.io/widget.js",this.apiUrl="https://api.wurd.io",this.store=new l,this.content=new f(this,null);var o=Object.getOwnPropertyNames(Object.getPrototypeOf(this.content));o.forEach((function(t){n[t]=n.content[t].bind(n.content)})),this.connect(e,r)}return s(t,[{key:"connect",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};switch(this.app=t,this.draft=!1,this.editMode=!1,["draft","lang","markdown","debug","onLoad"].forEach((function(t){var r=n[t];void 0!==r&&(e[t]=r)})),n.editMode){case!0:this.startEditor();break;case"querystring":/[?&]edit(&|$)/.test(location.search)&&this.startEditor()}return n.rawContent&&this.store.save(n.rawContent,{lang:n.lang}),n.storageKey&&(this.store.storageKey=n.storageKey),n.ttl&&(this.store.ttl=n.ttl),n.blockHelpers&&this.setBlockHelpers(n.blockHelpers),this}},{key:"load",value:function(t){var e=this.app,n=this.store,r=this.lang,o=this.editMode,i=this.debug,a=this.onLoad,c=this.content;if(!e)return Promise.reject(new Error("Use wurd.connect(appName) before wurd.load()"));var s="string"==typeof t?t.split(","):t;if(o)return this._fetchSections(s).then((function(t){return n.save(t,{lang:r}),n.clear(),a&&a(c),c}));var u=n.load(s,{lang:r}),d=s.filter((function(t){return void 0===u[t]}));return i&&console.info("Wurd: from cache:",s.filter((function(t){return void 0!==u[t]}))),0===d.length?(a&&a(c),Promise.resolve(c)):this._fetchSections(d).then((function(t){return n.save(t,{lang:r}),a&&a(c),c}))}},{key:"_fetchSections",value:function(t){var e=this,n=this.app;this.debug&&console.info("Wurd: from server:",t);var r,o=["draft","lang"].reduce((function(t,n){return e[n]&&(t[n]=e[n]),t}),{}),i="".concat(this.apiUrl,"/apps/").concat(n,"/content/").concat(t,"?").concat((r=o,Object.keys(r).map((function(t){var e=r[t];return encodeURIComponent(t)+"="+encodeURIComponent(e)})).join("&")));return this._fetch(i).then((function(e){if(e.error)throw e.error.message?new Error(e.error.message):new Error("Error loading ".concat(t));return e}))}},{key:"_fetch",value:function(t){return fetch(t).then((function(e){if(!e.ok)throw new Error("Error loading ".concat(t,": ").concat(e.statusText));return e.json()}))}},{key:"startEditor",value:function(){var t=this.app,e=this.lang;this.editMode=!0,this.draft=!0;var n=document.createElement("script");n.src=this.widgetUrl,n.async=!0,n.setAttribute("data-app",t),e&&n.setAttribute("data-lang",e);var r=document.body.querySelector('script[src="'.concat(this.widgetUrl,'"]'));r&&document.body.removeChild(r),document.body.appendChild(n)}},{key:"setBlockHelpers",value:function(t){Object.assign(f.prototype,t)}}]),t}(),p=new h;p.Wurd=h;var v=["block","id","sid","type","component","vars"];function g(t){var e=t.block,n=t.id,o=t.sid,a=t.type,c=void 0===a?"span":a,s=t.component,u=void 0===s?c:s,l=t.vars,f=d(t,v),h=(e=e||p.content).text(n,l),g=i({},f);p.editMode&&(g[l?"data-wurd-md":"data-wurd"]=e.id(o||n));return r.default.createElement(u,g,h)}var y=["block","id","sid","type","component","vars","inline"];function b(t){var e=t.block,n=t.id,o=t.sid,a=t.type,c=void 0===a?"div":a,s=t.component,u=void 0===s?c:s,l=t.vars,f=t.inline,h=d(t,y),v=(e=e||p.content).markdown(n,l,{inline:f}),g=i(i({},h),{},{dangerouslySetInnerHTML:{__html:v}});return p.editMode&&(g["data-wurd-md"]=e.id(o||n)),r.default.createElement(u,g)}var w=["block","id","sid"];function m(t){var e=t.block,n=t.id,o=t.sid,a=d(t,w),c=(e=e||p.content).text(n),s=i(i({},a),{},{src:c});return p.editMode&&(s["data-wurd-img"]=e.id(o||n)),r.default.createElement("img",s)}var k=["block","id","children","type","component","keys"];function O(t){var e=t.block,n=t.id,o=t.children,a=t.type,c=void 0===a?"ul":a,s=t.component,u=void 0===s?c:s,l=t.keys,f=void 0===l?"title":l,h=d(t,k);e=e||p.content;var v=i({},h);return p.editMode&&(v["data-wurd-list"]=e.id(n),v["data-wurd-list-props"]=f),r.default.createElement(u,v,e.map(n,(function(t,e){return o(t,e)})))}var j=["block","id","sid","keys","type","component","children"];function E(t){var e=t.block,n=t.id,o=t.sid,a=t.keys,c=t.type,s=void 0===c?"span":c,u=t.component,l=void 0===u?s:u,f=t.children,h=d(t,j);e=e||p.content;var v=i({},h);return p.editMode&&(v["data-wurd-obj"]=e.id(o||n),v["data-wurd-obj-props"]=Array.isArray(a)?a.join(","):a),r.default.createElement(l,v,f)}p.setBlockHelpers({Text:function(t){return r.default.createElement(g,i({block:this},t))},Markdown:function(t){return r.default.createElement(b,i({block:this},t))},Image:function(t){return r.default.createElement(m,i({block:this},t))},List:function(t){return r.default.createElement(O,i({block:this},t))},Object:function(t){return r.default.createElement(E,i({block:this},t))}}),t.WurdImage=m,t.WurdList=O,t.WurdMarkdown=b,t.WurdObject=E,t.WurdText=g,t.default=p,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/package.json b/package.json index 47e7933..c016bbf 100644 --- a/package.json +++ b/package.json @@ -13,15 +13,15 @@ "@babel/core": "^7.19.0", "@babel/preset-env": "^7.19.0", "@babel/preset-react": "^7.18.6", + "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-commonjs": "^22.0.2", + "@rollup/plugin-eslint": "^8.0.2", + "@rollup/plugin-node-resolve": "^14.1.0", "eslint-plugin-react": "^7.31.7", "mocha": "^10.0.0", "rollup": "^2.79.0", - "rollup-plugin-babel": "^4.4.0", - "rollup-plugin-commonjs": "^10.1.0", - "rollup-plugin-eslint": "^7.0.0", "rollup-plugin-filesize": "^9.1.2", - "rollup-plugin-node-resolve": "^5.2.0", - "rollup-plugin-uglify": "^6.0.4" + "rollup-plugin-terser": "^7.0.2" }, "keywords": [ "cms", diff --git a/rollup.config.js b/rollup.config.js index 760c659..3311326 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,9 +1,9 @@ -import resolve from 'rollup-plugin-node-resolve'; -import commonjs from 'rollup-plugin-commonjs'; -import babel from 'rollup-plugin-babel'; -import { uglify } from 'rollup-plugin-uglify'; +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import babel from '@rollup/plugin-babel'; +import { terser } from 'rollup-plugin-terser'; import filesize from 'rollup-plugin-filesize'; -import { eslint } from 'rollup-plugin-eslint'; +import eslint from '@rollup/plugin-eslint'; import pkg from './package.json'; export default [ @@ -30,7 +30,7 @@ export default [ globals: { 'react': 'React', }, - plugins: [uglify()], + plugins: [terser()], } ], plugins: [