@bigbinary/neeto-message-templates-frontend 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -10,10 +10,10 @@ var NeetoHeader = require('@bigbinary/neeto-molecules/Header');
10
10
  var SubHeader = require('@bigbinary/neeto-molecules/SubHeader');
11
11
  var neetoui = require('@bigbinary/neetoui');
12
12
  var ramda = require('ramda');
13
- var reactQuery = require('react-query');
14
- var devtools = require('react-query/devtools');
15
13
  var neetoIcons = require('@bigbinary/neeto-icons');
14
+ var constants = require('@bigbinary/neeto-commons-frontend/constants');
16
15
  var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
16
+ var reactQuery = require('react-query');
17
17
  var axios = require('axios');
18
18
  var zustand = require('zustand');
19
19
  var neetoEditor = require('@bigbinary/neeto-editor');
@@ -51,1599 +51,6 @@ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
51
51
  var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
52
52
  var TableWrapper__default = /*#__PURE__*/_interopDefaultLegacy(TableWrapper);
53
53
 
54
- /*! @license DOMPurify 3.0.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.2/LICENSE */
55
-
56
- const {
57
- entries,
58
- setPrototypeOf,
59
- isFrozen,
60
- getPrototypeOf,
61
- getOwnPropertyDescriptor
62
- } = Object;
63
- let {
64
- freeze,
65
- seal,
66
- create
67
- } = Object; // eslint-disable-line import/no-mutable-exports
68
-
69
- let {
70
- apply,
71
- construct
72
- } = typeof Reflect !== 'undefined' && Reflect;
73
-
74
- if (!apply) {
75
- apply = function apply(fun, thisValue, args) {
76
- return fun.apply(thisValue, args);
77
- };
78
- }
79
-
80
- if (!freeze) {
81
- freeze = function freeze(x) {
82
- return x;
83
- };
84
- }
85
-
86
- if (!seal) {
87
- seal = function seal(x) {
88
- return x;
89
- };
90
- }
91
-
92
- if (!construct) {
93
- construct = function construct(Func, args) {
94
- return new Func(...args);
95
- };
96
- }
97
-
98
- const arrayForEach = unapply(Array.prototype.forEach);
99
- const arrayPop = unapply(Array.prototype.pop);
100
- const arrayPush = unapply(Array.prototype.push);
101
- const stringToLowerCase = unapply(String.prototype.toLowerCase);
102
- const stringToString = unapply(String.prototype.toString);
103
- const stringMatch = unapply(String.prototype.match);
104
- const stringReplace = unapply(String.prototype.replace);
105
- const stringIndexOf = unapply(String.prototype.indexOf);
106
- const stringTrim = unapply(String.prototype.trim);
107
- const regExpTest = unapply(RegExp.prototype.test);
108
- const typeErrorCreate = unconstruct(TypeError);
109
- function unapply(func) {
110
- return function (thisArg) {
111
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
112
- args[_key - 1] = arguments[_key];
113
- }
114
-
115
- return apply(func, thisArg, args);
116
- };
117
- }
118
- function unconstruct(func) {
119
- return function () {
120
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
121
- args[_key2] = arguments[_key2];
122
- }
123
-
124
- return construct(func, args);
125
- };
126
- }
127
- /* Add properties to a lookup table */
128
-
129
- function addToSet(set, array, transformCaseFunc) {
130
- transformCaseFunc = transformCaseFunc ? transformCaseFunc : stringToLowerCase;
131
-
132
- if (setPrototypeOf) {
133
- // Make 'in' and truthy checks like Boolean(set.constructor)
134
- // independent of any properties defined on Object.prototype.
135
- // Prevent prototype setters from intercepting set as a this value.
136
- setPrototypeOf(set, null);
137
- }
138
-
139
- let l = array.length;
140
-
141
- while (l--) {
142
- let element = array[l];
143
-
144
- if (typeof element === 'string') {
145
- const lcElement = transformCaseFunc(element);
146
-
147
- if (lcElement !== element) {
148
- // Config presets (e.g. tags.js, attrs.js) are immutable.
149
- if (!isFrozen(array)) {
150
- array[l] = lcElement;
151
- }
152
-
153
- element = lcElement;
154
- }
155
- }
156
-
157
- set[element] = true;
158
- }
159
-
160
- return set;
161
- }
162
- /* Shallow clone an object */
163
-
164
- function clone(object) {
165
- const newObject = create(null);
166
-
167
- for (const [property, value] of entries(object)) {
168
- newObject[property] = value;
169
- }
170
-
171
- return newObject;
172
- }
173
- /* This method automatically checks if the prop is function
174
- * or getter and behaves accordingly. */
175
-
176
- function lookupGetter(object, prop) {
177
- while (object !== null) {
178
- const desc = getOwnPropertyDescriptor(object, prop);
179
-
180
- if (desc) {
181
- if (desc.get) {
182
- return unapply(desc.get);
183
- }
184
-
185
- if (typeof desc.value === 'function') {
186
- return unapply(desc.value);
187
- }
188
- }
189
-
190
- object = getPrototypeOf(object);
191
- }
192
-
193
- function fallbackValue(element) {
194
- console.warn('fallback value for', element);
195
- return null;
196
- }
197
-
198
- return fallbackValue;
199
- }
200
-
201
- const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); // SVG
202
-
203
- const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
204
- const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']); // List of SVG elements that are disallowed by default.
205
- // We still need to know them so that we can do namespace
206
- // checks properly in case one wants to add them to
207
- // allow-list.
208
-
209
- const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'fedropshadow', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
210
- const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']); // Similarly to SVG, we want to know all MathML elements,
211
- // even those that we disallow by default.
212
-
213
- const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
214
- const text = freeze(['#text']);
215
-
216
- const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns', 'slot']);
217
- const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
218
- const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
219
- const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
220
-
221
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
222
-
223
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
224
- const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
225
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
226
-
227
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
228
-
229
- const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
230
- );
231
- const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
232
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
233
- );
234
- const DOCTYPE_NAME = seal(/^html$/i);
235
-
236
- var EXPRESSIONS = /*#__PURE__*/Object.freeze({
237
- __proto__: null,
238
- MUSTACHE_EXPR: MUSTACHE_EXPR,
239
- ERB_EXPR: ERB_EXPR,
240
- TMPLIT_EXPR: TMPLIT_EXPR,
241
- DATA_ATTR: DATA_ATTR,
242
- ARIA_ATTR: ARIA_ATTR,
243
- IS_ALLOWED_URI: IS_ALLOWED_URI,
244
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
245
- ATTR_WHITESPACE: ATTR_WHITESPACE,
246
- DOCTYPE_NAME: DOCTYPE_NAME
247
- });
248
-
249
- const getGlobal = () => typeof window === 'undefined' ? null : window;
250
- /**
251
- * Creates a no-op policy for internal use only.
252
- * Don't export this function outside this module!
253
- * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
254
- * @param {Document} document The document object (to determine policy name suffix)
255
- * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
256
- * are not supported).
257
- */
258
-
259
-
260
- const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
261
- if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
262
- return null;
263
- } // Allow the callers to control the unique policy name
264
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
265
- // Policy creation with duplicate names throws in Trusted Types.
266
-
267
-
268
- let suffix = null;
269
- const ATTR_NAME = 'data-tt-policy-suffix';
270
-
271
- if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
272
- suffix = document.currentScript.getAttribute(ATTR_NAME);
273
- }
274
-
275
- const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
276
-
277
- try {
278
- return trustedTypes.createPolicy(policyName, {
279
- createHTML(html) {
280
- return html;
281
- },
282
-
283
- createScriptURL(scriptUrl) {
284
- return scriptUrl;
285
- }
286
-
287
- });
288
- } catch (_) {
289
- // Policy creation failed (most likely another DOMPurify script has
290
- // already run). Skip creating the policy, as this will only cause errors
291
- // if TT are enforced.
292
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
293
- return null;
294
- }
295
- };
296
-
297
- function createDOMPurify() {
298
- let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
299
-
300
- const DOMPurify = root => createDOMPurify(root);
301
- /**
302
- * Version label, exposed for easier checks
303
- * if DOMPurify is up to date or not
304
- */
305
-
306
-
307
- DOMPurify.version = '3.0.2';
308
- /**
309
- * Array of elements that DOMPurify removed during sanitation.
310
- * Empty if nothing was removed.
311
- */
312
-
313
- DOMPurify.removed = [];
314
-
315
- if (!window || !window.document || window.document.nodeType !== 9) {
316
- // Not running in a browser, provide a factory function
317
- // so that you can pass your own Window
318
- DOMPurify.isSupported = false;
319
- return DOMPurify;
320
- }
321
-
322
- const originalDocument = window.document;
323
- let {
324
- document
325
- } = window;
326
- const {
327
- DocumentFragment,
328
- HTMLTemplateElement,
329
- Node,
330
- Element,
331
- NodeFilter,
332
- NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
333
- HTMLFormElement,
334
- DOMParser,
335
- trustedTypes
336
- } = window;
337
- const ElementPrototype = Element.prototype;
338
- const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
339
- const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
340
- const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
341
- const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); // As per issue #47, the web-components registry is inherited by a
342
- // new document created via createHTMLDocument. As per the spec
343
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
344
- // a new empty registry is used when creating a template contents owner
345
- // document, so we use that as our parent document to ensure nothing
346
- // is inherited.
347
-
348
- if (typeof HTMLTemplateElement === 'function') {
349
- const template = document.createElement('template');
350
-
351
- if (template.content && template.content.ownerDocument) {
352
- document = template.content.ownerDocument;
353
- }
354
- }
355
-
356
- const trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
357
-
358
- const emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML('') : '';
359
- const {
360
- implementation,
361
- createNodeIterator,
362
- createDocumentFragment,
363
- getElementsByTagName
364
- } = document;
365
- const {
366
- importNode
367
- } = originalDocument;
368
- let hooks = {};
369
- /**
370
- * Expose whether this browser supports running the full DOMPurify.
371
- */
372
-
373
- DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined';
374
- const {
375
- MUSTACHE_EXPR,
376
- ERB_EXPR,
377
- TMPLIT_EXPR,
378
- DATA_ATTR,
379
- ARIA_ATTR,
380
- IS_SCRIPT_OR_DATA,
381
- ATTR_WHITESPACE
382
- } = EXPRESSIONS;
383
- let {
384
- IS_ALLOWED_URI: IS_ALLOWED_URI$1
385
- } = EXPRESSIONS;
386
- /**
387
- * We consider the elements and attributes below to be safe. Ideally
388
- * don't add any new ones but feel free to remove unwanted ones.
389
- */
390
-
391
- /* allowed element names */
392
-
393
- let ALLOWED_TAGS = null;
394
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
395
- /* Allowed attribute names */
396
-
397
- let ALLOWED_ATTR = null;
398
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
399
- /*
400
- * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
401
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
402
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
403
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
404
- */
405
-
406
- let CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
407
- tagNameCheck: {
408
- writable: true,
409
- configurable: false,
410
- enumerable: true,
411
- value: null
412
- },
413
- attributeNameCheck: {
414
- writable: true,
415
- configurable: false,
416
- enumerable: true,
417
- value: null
418
- },
419
- allowCustomizedBuiltInElements: {
420
- writable: true,
421
- configurable: false,
422
- enumerable: true,
423
- value: false
424
- }
425
- }));
426
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
427
-
428
- let FORBID_TAGS = null;
429
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
430
-
431
- let FORBID_ATTR = null;
432
- /* Decide if ARIA attributes are okay */
433
-
434
- let ALLOW_ARIA_ATTR = true;
435
- /* Decide if custom data attributes are okay */
436
-
437
- let ALLOW_DATA_ATTR = true;
438
- /* Decide if unknown protocols are okay */
439
-
440
- let ALLOW_UNKNOWN_PROTOCOLS = false;
441
- /* Decide if self-closing tags in attributes are allowed.
442
- * Usually removed due to a mXSS issue in jQuery 3.0 */
443
-
444
- let ALLOW_SELF_CLOSE_IN_ATTR = true;
445
- /* Output should be safe for common template engines.
446
- * This means, DOMPurify removes data attributes, mustaches and ERB
447
- */
448
-
449
- let SAFE_FOR_TEMPLATES = false;
450
- /* Decide if document with <html>... should be returned */
451
-
452
- let WHOLE_DOCUMENT = false;
453
- /* Track whether config is already set on this instance of DOMPurify. */
454
-
455
- let SET_CONFIG = false;
456
- /* Decide if all elements (e.g. style, script) must be children of
457
- * document.body. By default, browsers might move them to document.head */
458
-
459
- let FORCE_BODY = false;
460
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
461
- * string (or a TrustedHTML object if Trusted Types are supported).
462
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
463
- */
464
-
465
- let RETURN_DOM = false;
466
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
467
- * string (or a TrustedHTML object if Trusted Types are supported) */
468
-
469
- let RETURN_DOM_FRAGMENT = false;
470
- /* Try to return a Trusted Type object instead of a string, return a string in
471
- * case Trusted Types are not supported */
472
-
473
- let RETURN_TRUSTED_TYPE = false;
474
- /* Output should be free from DOM clobbering attacks?
475
- * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
476
- */
477
-
478
- let SANITIZE_DOM = true;
479
- /* Achieve full DOM Clobbering protection by isolating the namespace of named
480
- * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
481
- *
482
- * HTML/DOM spec rules that enable DOM Clobbering:
483
- * - Named Access on Window (§7.3.3)
484
- * - DOM Tree Accessors (§3.1.5)
485
- * - Form Element Parent-Child Relations (§4.10.3)
486
- * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
487
- * - HTMLCollection (§4.2.10.2)
488
- *
489
- * Namespace isolation is implemented by prefixing `id` and `name` attributes
490
- * with a constant string, i.e., `user-content-`
491
- */
492
-
493
- let SANITIZE_NAMED_PROPS = false;
494
- const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
495
- /* Keep element content when removing element? */
496
-
497
- let KEEP_CONTENT = true;
498
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
499
- * of importing it into a new Document and returning a sanitized copy */
500
-
501
- let IN_PLACE = false;
502
- /* Allow usage of profiles like html, svg and mathMl */
503
-
504
- let USE_PROFILES = {};
505
- /* Tags to ignore content of when KEEP_CONTENT is true */
506
-
507
- let FORBID_CONTENTS = null;
508
- const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
509
- /* Tags that are safe for data: URIs */
510
-
511
- let DATA_URI_TAGS = null;
512
- const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
513
- /* Attributes safe for values like "javascript:" */
514
-
515
- let URI_SAFE_ATTRIBUTES = null;
516
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
517
- const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
518
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
519
- const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
520
- /* Document namespace */
521
-
522
- let NAMESPACE = HTML_NAMESPACE;
523
- let IS_EMPTY_INPUT = false;
524
- /* Allowed XHTML+XML namespaces */
525
-
526
- let ALLOWED_NAMESPACES = null;
527
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
528
- /* Parsing of strict XHTML documents */
529
-
530
- let PARSER_MEDIA_TYPE;
531
- const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
532
- const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
533
- let transformCaseFunc;
534
- /* Keep a reference to config to pass to hooks */
535
-
536
- let CONFIG = null;
537
- /* Ideally, do not touch anything below this line */
538
-
539
- /* ______________________________________________ */
540
-
541
- const formElement = document.createElement('form');
542
-
543
- const isRegexOrFunction = function isRegexOrFunction(testValue) {
544
- return testValue instanceof RegExp || testValue instanceof Function;
545
- };
546
- /**
547
- * _parseConfig
548
- *
549
- * @param {Object} cfg optional config literal
550
- */
551
- // eslint-disable-next-line complexity
552
-
553
-
554
- const _parseConfig = function _parseConfig(cfg) {
555
- if (CONFIG && CONFIG === cfg) {
556
- return;
557
- }
558
- /* Shield configuration object from tampering */
559
-
560
-
561
- if (!cfg || typeof cfg !== 'object') {
562
- cfg = {};
563
- }
564
- /* Shield configuration object from prototype pollution */
565
-
566
-
567
- cfg = clone(cfg);
568
- PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
569
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE; // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
570
-
571
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
572
- /* Set configuration parameters */
573
-
574
- ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
575
- ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
576
- ALLOWED_NAMESPACES = 'ALLOWED_NAMESPACES' in cfg ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
577
- URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
578
- cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
579
- transformCaseFunc // eslint-disable-line indent
580
- ) // eslint-disable-line indent
581
- : DEFAULT_URI_SAFE_ATTRIBUTES;
582
- DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent
583
- cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent
584
- transformCaseFunc // eslint-disable-line indent
585
- ) // eslint-disable-line indent
586
- : DEFAULT_DATA_URI_TAGS;
587
- FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
588
- FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
589
- FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
590
- USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
591
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
592
-
593
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
594
-
595
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
596
-
597
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
598
-
599
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
600
-
601
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
602
-
603
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
604
-
605
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
606
-
607
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
608
-
609
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
610
-
611
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
612
-
613
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
614
-
615
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
616
-
617
- IN_PLACE = cfg.IN_PLACE || false; // Default false
618
-
619
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
620
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
621
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
622
-
623
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
624
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
625
- }
626
-
627
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
628
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
629
- }
630
-
631
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
632
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
633
- }
634
-
635
- if (SAFE_FOR_TEMPLATES) {
636
- ALLOW_DATA_ATTR = false;
637
- }
638
-
639
- if (RETURN_DOM_FRAGMENT) {
640
- RETURN_DOM = true;
641
- }
642
- /* Parse profile info */
643
-
644
-
645
- if (USE_PROFILES) {
646
- ALLOWED_TAGS = addToSet({}, [...text]);
647
- ALLOWED_ATTR = [];
648
-
649
- if (USE_PROFILES.html === true) {
650
- addToSet(ALLOWED_TAGS, html$1);
651
- addToSet(ALLOWED_ATTR, html);
652
- }
653
-
654
- if (USE_PROFILES.svg === true) {
655
- addToSet(ALLOWED_TAGS, svg$1);
656
- addToSet(ALLOWED_ATTR, svg);
657
- addToSet(ALLOWED_ATTR, xml);
658
- }
659
-
660
- if (USE_PROFILES.svgFilters === true) {
661
- addToSet(ALLOWED_TAGS, svgFilters);
662
- addToSet(ALLOWED_ATTR, svg);
663
- addToSet(ALLOWED_ATTR, xml);
664
- }
665
-
666
- if (USE_PROFILES.mathMl === true) {
667
- addToSet(ALLOWED_TAGS, mathMl$1);
668
- addToSet(ALLOWED_ATTR, mathMl);
669
- addToSet(ALLOWED_ATTR, xml);
670
- }
671
- }
672
- /* Merge configuration parameters */
673
-
674
-
675
- if (cfg.ADD_TAGS) {
676
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
677
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
678
- }
679
-
680
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
681
- }
682
-
683
- if (cfg.ADD_ATTR) {
684
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
685
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
686
- }
687
-
688
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
689
- }
690
-
691
- if (cfg.ADD_URI_SAFE_ATTR) {
692
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
693
- }
694
-
695
- if (cfg.FORBID_CONTENTS) {
696
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
697
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
698
- }
699
-
700
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
701
- }
702
- /* Add #text in case KEEP_CONTENT is set to true */
703
-
704
-
705
- if (KEEP_CONTENT) {
706
- ALLOWED_TAGS['#text'] = true;
707
- }
708
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
709
-
710
-
711
- if (WHOLE_DOCUMENT) {
712
- addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
713
- }
714
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
715
-
716
-
717
- if (ALLOWED_TAGS.table) {
718
- addToSet(ALLOWED_TAGS, ['tbody']);
719
- delete FORBID_TAGS.tbody;
720
- } // Prevent further manipulation of configuration.
721
- // Not available in IE8, Safari 5, etc.
722
-
723
-
724
- if (freeze) {
725
- freeze(cfg);
726
- }
727
-
728
- CONFIG = cfg;
729
- };
730
-
731
- const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
732
- const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']); // Certain elements are allowed in both SVG and HTML
733
- // namespace. We need to specify them explicitly
734
- // so that they don't get erroneously deleted from
735
- // HTML namespace.
736
-
737
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
738
- /* Keep track of all possible SVG and MathML tags
739
- * so that we can perform the namespace checks
740
- * correctly. */
741
-
742
- const ALL_SVG_TAGS = addToSet({}, svg$1);
743
- addToSet(ALL_SVG_TAGS, svgFilters);
744
- addToSet(ALL_SVG_TAGS, svgDisallowed);
745
- const ALL_MATHML_TAGS = addToSet({}, mathMl$1);
746
- addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
747
- /**
748
- *
749
- *
750
- * @param {Element} element a DOM element whose namespace is being checked
751
- * @returns {boolean} Return false if the element has a
752
- * namespace that a spec-compliant parser would never
753
- * return. Return true otherwise.
754
- */
755
-
756
- const _checkValidNamespace = function _checkValidNamespace(element) {
757
- let parent = getParentNode(element); // In JSDOM, if we're inside shadow DOM, then parentNode
758
- // can be null. We just simulate parent in this case.
759
-
760
- if (!parent || !parent.tagName) {
761
- parent = {
762
- namespaceURI: NAMESPACE,
763
- tagName: 'template'
764
- };
765
- }
766
-
767
- const tagName = stringToLowerCase(element.tagName);
768
- const parentTagName = stringToLowerCase(parent.tagName);
769
-
770
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
771
- return false;
772
- }
773
-
774
- if (element.namespaceURI === SVG_NAMESPACE) {
775
- // The only way to switch from HTML namespace to SVG
776
- // is via <svg>. If it happens via any other tag, then
777
- // it should be killed.
778
- if (parent.namespaceURI === HTML_NAMESPACE) {
779
- return tagName === 'svg';
780
- } // The only way to switch from MathML to SVG is via`
781
- // svg if parent is either <annotation-xml> or MathML
782
- // text integration points.
783
-
784
-
785
- if (parent.namespaceURI === MATHML_NAMESPACE) {
786
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
787
- } // We only allow elements that are defined in SVG
788
- // spec. All others are disallowed in SVG namespace.
789
-
790
-
791
- return Boolean(ALL_SVG_TAGS[tagName]);
792
- }
793
-
794
- if (element.namespaceURI === MATHML_NAMESPACE) {
795
- // The only way to switch from HTML namespace to MathML
796
- // is via <math>. If it happens via any other tag, then
797
- // it should be killed.
798
- if (parent.namespaceURI === HTML_NAMESPACE) {
799
- return tagName === 'math';
800
- } // The only way to switch from SVG to MathML is via
801
- // <math> and HTML integration points
802
-
803
-
804
- if (parent.namespaceURI === SVG_NAMESPACE) {
805
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
806
- } // We only allow elements that are defined in MathML
807
- // spec. All others are disallowed in MathML namespace.
808
-
809
-
810
- return Boolean(ALL_MATHML_TAGS[tagName]);
811
- }
812
-
813
- if (element.namespaceURI === HTML_NAMESPACE) {
814
- // The only way to switch from SVG to HTML is via
815
- // HTML integration points, and from MathML to HTML
816
- // is via MathML text integration points
817
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
818
- return false;
819
- }
820
-
821
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
822
- return false;
823
- } // We disallow tags that are specific for MathML
824
- // or SVG and should never appear in HTML namespace
825
-
826
-
827
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
828
- } // For XHTML and XML documents that support custom namespaces
829
-
830
-
831
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
832
- return true;
833
- } // The code should never reach this place (this means
834
- // that the element somehow got namespace that is not
835
- // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
836
- // Return false just in case.
837
-
838
-
839
- return false;
840
- };
841
- /**
842
- * _forceRemove
843
- *
844
- * @param {Node} node a DOM node
845
- */
846
-
847
-
848
- const _forceRemove = function _forceRemove(node) {
849
- arrayPush(DOMPurify.removed, {
850
- element: node
851
- });
852
-
853
- try {
854
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
855
- node.parentNode.removeChild(node);
856
- } catch (_) {
857
- node.remove();
858
- }
859
- };
860
- /**
861
- * _removeAttribute
862
- *
863
- * @param {String} name an Attribute name
864
- * @param {Node} node a DOM node
865
- */
866
-
867
-
868
- const _removeAttribute = function _removeAttribute(name, node) {
869
- try {
870
- arrayPush(DOMPurify.removed, {
871
- attribute: node.getAttributeNode(name),
872
- from: node
873
- });
874
- } catch (_) {
875
- arrayPush(DOMPurify.removed, {
876
- attribute: null,
877
- from: node
878
- });
879
- }
880
-
881
- node.removeAttribute(name); // We void attribute values for unremovable "is"" attributes
882
-
883
- if (name === 'is' && !ALLOWED_ATTR[name]) {
884
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
885
- try {
886
- _forceRemove(node);
887
- } catch (_) {}
888
- } else {
889
- try {
890
- node.setAttribute(name, '');
891
- } catch (_) {}
892
- }
893
- }
894
- };
895
- /**
896
- * _initDocument
897
- *
898
- * @param {String} dirty a string of dirty markup
899
- * @return {Document} a DOM, filled with the dirty markup
900
- */
901
-
902
-
903
- const _initDocument = function _initDocument(dirty) {
904
- /* Create a HTML document */
905
- let doc;
906
- let leadingWhitespace;
907
-
908
- if (FORCE_BODY) {
909
- dirty = '<remove></remove>' + dirty;
910
- } else {
911
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
912
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
913
- leadingWhitespace = matches && matches[0];
914
- }
915
-
916
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
917
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
918
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
919
- }
920
-
921
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
922
- /*
923
- * Use the DOMParser API by default, fallback later if needs be
924
- * DOMParser not work for svg when has multiple root element.
925
- */
926
-
927
- if (NAMESPACE === HTML_NAMESPACE) {
928
- try {
929
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
930
- } catch (_) {}
931
- }
932
- /* Use createHTMLDocument in case DOMParser is not available */
933
-
934
-
935
- if (!doc || !doc.documentElement) {
936
- doc = implementation.createDocument(NAMESPACE, 'template', null);
937
-
938
- try {
939
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
940
- } catch (_) {// Syntax error if dirtyPayload is invalid xml
941
- }
942
- }
943
-
944
- const body = doc.body || doc.documentElement;
945
-
946
- if (dirty && leadingWhitespace) {
947
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
948
- }
949
- /* Work on whole document or just its body */
950
-
951
-
952
- if (NAMESPACE === HTML_NAMESPACE) {
953
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
954
- }
955
-
956
- return WHOLE_DOCUMENT ? doc.documentElement : body;
957
- };
958
- /**
959
- * _createIterator
960
- *
961
- * @param {Document} root document/fragment to create iterator for
962
- * @return {Iterator} iterator instance
963
- */
964
-
965
-
966
- const _createIterator = function _createIterator(root) {
967
- return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
968
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
969
- };
970
- /**
971
- * _isClobbered
972
- *
973
- * @param {Node} elm element to check for clobbering attacks
974
- * @return {Boolean} true if clobbered, false if safe
975
- */
976
-
977
-
978
- const _isClobbered = function _isClobbered(elm) {
979
- return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
980
- };
981
- /**
982
- * _isNode
983
- *
984
- * @param {Node} obj object to check whether it's a DOM node
985
- * @return {Boolean} true is object is a DOM node
986
- */
987
-
988
-
989
- const _isNode = function _isNode(object) {
990
- return typeof Node === 'object' ? object instanceof Node : object && typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
991
- };
992
- /**
993
- * _executeHook
994
- * Execute user configurable hooks
995
- *
996
- * @param {String} entryPoint Name of the hook's entry point
997
- * @param {Node} currentNode node to work on with the hook
998
- * @param {Object} data additional hook parameters
999
- */
1000
-
1001
-
1002
- const _executeHook = function _executeHook(entryPoint, currentNode, data) {
1003
- if (!hooks[entryPoint]) {
1004
- return;
1005
- }
1006
-
1007
- arrayForEach(hooks[entryPoint], hook => {
1008
- hook.call(DOMPurify, currentNode, data, CONFIG);
1009
- });
1010
- };
1011
- /**
1012
- * _sanitizeElements
1013
- *
1014
- * @protect nodeName
1015
- * @protect textContent
1016
- * @protect removeChild
1017
- *
1018
- * @param {Node} currentNode to check for permission to exist
1019
- * @return {Boolean} true if node was killed, false if left alive
1020
- */
1021
-
1022
-
1023
- const _sanitizeElements = function _sanitizeElements(currentNode) {
1024
- let content;
1025
- /* Execute a hook if present */
1026
-
1027
- _executeHook('beforeSanitizeElements', currentNode, null);
1028
- /* Check if element is clobbered or can clobber */
1029
-
1030
-
1031
- if (_isClobbered(currentNode)) {
1032
- _forceRemove(currentNode);
1033
-
1034
- return true;
1035
- }
1036
- /* Now let's check the element's type and name */
1037
-
1038
-
1039
- const tagName = transformCaseFunc(currentNode.nodeName);
1040
- /* Execute a hook if present */
1041
-
1042
- _executeHook('uponSanitizeElement', currentNode, {
1043
- tagName,
1044
- allowedTags: ALLOWED_TAGS
1045
- });
1046
- /* Detect mXSS attempts abusing namespace confusion */
1047
-
1048
-
1049
- if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
1050
- _forceRemove(currentNode);
1051
-
1052
- return true;
1053
- }
1054
- /* Remove element if anything forbids its presence */
1055
-
1056
-
1057
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1058
- /* Check if we have a custom element to handle */
1059
- if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
1060
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
1061
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
1062
- }
1063
- /* Keep content except for bad-listed elements */
1064
-
1065
-
1066
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1067
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
1068
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1069
-
1070
- if (childNodes && parentNode) {
1071
- const childCount = childNodes.length;
1072
-
1073
- for (let i = childCount - 1; i >= 0; --i) {
1074
- parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1075
- }
1076
- }
1077
- }
1078
-
1079
- _forceRemove(currentNode);
1080
-
1081
- return true;
1082
- }
1083
- /* Check whether element has a valid namespace */
1084
-
1085
-
1086
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1087
- _forceRemove(currentNode);
1088
-
1089
- return true;
1090
- }
1091
- /* Make sure that older browsers don't get noscript mXSS */
1092
-
1093
-
1094
- if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1095
- _forceRemove(currentNode);
1096
-
1097
- return true;
1098
- }
1099
- /* Sanitize element content to be template-safe */
1100
-
1101
-
1102
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
1103
- /* Get the element's text content */
1104
- content = currentNode.textContent;
1105
- content = stringReplace(content, MUSTACHE_EXPR, ' ');
1106
- content = stringReplace(content, ERB_EXPR, ' ');
1107
- content = stringReplace(content, TMPLIT_EXPR, ' ');
1108
-
1109
- if (currentNode.textContent !== content) {
1110
- arrayPush(DOMPurify.removed, {
1111
- element: currentNode.cloneNode()
1112
- });
1113
- currentNode.textContent = content;
1114
- }
1115
- }
1116
- /* Execute a hook if present */
1117
-
1118
-
1119
- _executeHook('afterSanitizeElements', currentNode, null);
1120
-
1121
- return false;
1122
- };
1123
- /**
1124
- * _isValidAttribute
1125
- *
1126
- * @param {string} lcTag Lowercase tag name of containing element.
1127
- * @param {string} lcName Lowercase attribute name.
1128
- * @param {string} value Attribute value.
1129
- * @return {Boolean} Returns true if `value` is valid, otherwise false.
1130
- */
1131
- // eslint-disable-next-line complexity
1132
-
1133
-
1134
- const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1135
- /* Make sure attribute cannot clobber */
1136
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1137
- return false;
1138
- }
1139
- /* Allow valid data-* attributes: At least one character after "-"
1140
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1141
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1142
- We don't need to check the value; it's always URI safe. */
1143
-
1144
-
1145
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1146
- if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1147
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1148
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1149
- _basicCustomElementTest(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
1150
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1151
- lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1152
- return false;
1153
- }
1154
- /* Check value is safe. First, is attr inert? If so, is safe */
1155
-
1156
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (!value) ; else {
1157
- return false;
1158
- }
1159
-
1160
- return true;
1161
- };
1162
- /**
1163
- * _basicCustomElementCheck
1164
- * checks if at least one dash is included in tagName, and it's not the first char
1165
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1166
- * @param {string} tagName name of the tag of the node to sanitize
1167
- */
1168
-
1169
-
1170
- const _basicCustomElementTest = function _basicCustomElementTest(tagName) {
1171
- return tagName.indexOf('-') > 0;
1172
- };
1173
- /**
1174
- * _sanitizeAttributes
1175
- *
1176
- * @protect attributes
1177
- * @protect nodeName
1178
- * @protect removeAttribute
1179
- * @protect setAttribute
1180
- *
1181
- * @param {Node} currentNode to sanitize
1182
- */
1183
-
1184
-
1185
- const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1186
- let attr;
1187
- let value;
1188
- let lcName;
1189
- let l;
1190
- /* Execute a hook if present */
1191
-
1192
- _executeHook('beforeSanitizeAttributes', currentNode, null);
1193
-
1194
- const {
1195
- attributes
1196
- } = currentNode;
1197
- /* Check if we have attributes; if not we might have a text node */
1198
-
1199
- if (!attributes) {
1200
- return;
1201
- }
1202
-
1203
- const hookEvent = {
1204
- attrName: '',
1205
- attrValue: '',
1206
- keepAttr: true,
1207
- allowedAttributes: ALLOWED_ATTR
1208
- };
1209
- l = attributes.length;
1210
- /* Go backwards over all attributes; safely remove bad ones */
1211
-
1212
- while (l--) {
1213
- attr = attributes[l];
1214
- const {
1215
- name,
1216
- namespaceURI
1217
- } = attr;
1218
- value = name === 'value' ? attr.value : stringTrim(attr.value);
1219
- lcName = transformCaseFunc(name);
1220
- /* Execute a hook if present */
1221
-
1222
- hookEvent.attrName = lcName;
1223
- hookEvent.attrValue = value;
1224
- hookEvent.keepAttr = true;
1225
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1226
-
1227
- _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1228
-
1229
- value = hookEvent.attrValue;
1230
- /* Did the hooks approve of the attribute? */
1231
-
1232
- if (hookEvent.forceKeepAttr) {
1233
- continue;
1234
- }
1235
- /* Remove attribute */
1236
-
1237
-
1238
- _removeAttribute(name, currentNode);
1239
- /* Did the hooks approve of the attribute? */
1240
-
1241
-
1242
- if (!hookEvent.keepAttr) {
1243
- continue;
1244
- }
1245
- /* Work around a security issue in jQuery 3.0 */
1246
-
1247
-
1248
- if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1249
- _removeAttribute(name, currentNode);
1250
-
1251
- continue;
1252
- }
1253
- /* Sanitize attribute content to be template-safe */
1254
-
1255
-
1256
- if (SAFE_FOR_TEMPLATES) {
1257
- value = stringReplace(value, MUSTACHE_EXPR, ' ');
1258
- value = stringReplace(value, ERB_EXPR, ' ');
1259
- value = stringReplace(value, TMPLIT_EXPR, ' ');
1260
- }
1261
- /* Is `value` valid for this attribute? */
1262
-
1263
-
1264
- const lcTag = transformCaseFunc(currentNode.nodeName);
1265
-
1266
- if (!_isValidAttribute(lcTag, lcName, value)) {
1267
- continue;
1268
- }
1269
- /* Full DOM Clobbering protection via namespace isolation,
1270
- * Prefix id and name attributes with `user-content-`
1271
- */
1272
-
1273
-
1274
- if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1275
- // Remove the attribute with this value
1276
- _removeAttribute(name, currentNode); // Prefix the value and later re-create the attribute with the sanitized value
1277
-
1278
-
1279
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
1280
- }
1281
- /* Handle attributes that require Trusted Types */
1282
-
1283
-
1284
- if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1285
- if (namespaceURI) ; else {
1286
- switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1287
- case 'TrustedHTML':
1288
- value = trustedTypesPolicy.createHTML(value);
1289
- break;
1290
-
1291
- case 'TrustedScriptURL':
1292
- value = trustedTypesPolicy.createScriptURL(value);
1293
- break;
1294
- }
1295
- }
1296
- }
1297
- /* Handle invalid data-* attribute set by try-catching it */
1298
-
1299
-
1300
- try {
1301
- if (namespaceURI) {
1302
- currentNode.setAttributeNS(namespaceURI, name, value);
1303
- } else {
1304
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1305
- currentNode.setAttribute(name, value);
1306
- }
1307
-
1308
- arrayPop(DOMPurify.removed);
1309
- } catch (_) {}
1310
- }
1311
- /* Execute a hook if present */
1312
-
1313
-
1314
- _executeHook('afterSanitizeAttributes', currentNode, null);
1315
- };
1316
- /**
1317
- * _sanitizeShadowDOM
1318
- *
1319
- * @param {DocumentFragment} fragment to iterate over recursively
1320
- */
1321
-
1322
-
1323
- const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1324
- let shadowNode;
1325
-
1326
- const shadowIterator = _createIterator(fragment);
1327
- /* Execute a hook if present */
1328
-
1329
-
1330
- _executeHook('beforeSanitizeShadowDOM', fragment, null);
1331
-
1332
- while (shadowNode = shadowIterator.nextNode()) {
1333
- /* Execute a hook if present */
1334
- _executeHook('uponSanitizeShadowNode', shadowNode, null);
1335
- /* Sanitize tags and elements */
1336
-
1337
-
1338
- if (_sanitizeElements(shadowNode)) {
1339
- continue;
1340
- }
1341
- /* Deep shadow DOM detected */
1342
-
1343
-
1344
- if (shadowNode.content instanceof DocumentFragment) {
1345
- _sanitizeShadowDOM(shadowNode.content);
1346
- }
1347
- /* Check attributes, sanitize if necessary */
1348
-
1349
-
1350
- _sanitizeAttributes(shadowNode);
1351
- }
1352
- /* Execute a hook if present */
1353
-
1354
-
1355
- _executeHook('afterSanitizeShadowDOM', fragment, null);
1356
- };
1357
- /**
1358
- * Sanitize
1359
- * Public method providing core sanitation functionality
1360
- *
1361
- * @param {String|Node} dirty string or DOM node
1362
- * @param {Object} configuration object
1363
- */
1364
- // eslint-disable-next-line complexity
1365
-
1366
-
1367
- DOMPurify.sanitize = function (dirty) {
1368
- let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1369
- let body;
1370
- let importedNode;
1371
- let currentNode;
1372
- let returnNode;
1373
- /* Make sure we have a string to sanitize.
1374
- DO NOT return early, as this will return the wrong type if
1375
- the user has requested a DOM object rather than a string */
1376
-
1377
- IS_EMPTY_INPUT = !dirty;
1378
-
1379
- if (IS_EMPTY_INPUT) {
1380
- dirty = '<!-->';
1381
- }
1382
- /* Stringify, in case dirty is an object */
1383
-
1384
-
1385
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
1386
- // eslint-disable-next-line no-negated-condition
1387
- if (typeof dirty.toString !== 'function') {
1388
- throw typeErrorCreate('toString is not a function');
1389
- } else {
1390
- dirty = dirty.toString();
1391
-
1392
- if (typeof dirty !== 'string') {
1393
- throw typeErrorCreate('dirty is not a string, aborting');
1394
- }
1395
- }
1396
- }
1397
- /* Return dirty HTML if DOMPurify cannot run */
1398
-
1399
-
1400
- if (!DOMPurify.isSupported) {
1401
- return dirty;
1402
- }
1403
- /* Assign config vars */
1404
-
1405
-
1406
- if (!SET_CONFIG) {
1407
- _parseConfig(cfg);
1408
- }
1409
- /* Clean up removed elements */
1410
-
1411
-
1412
- DOMPurify.removed = [];
1413
- /* Check if dirty is correctly typed for IN_PLACE */
1414
-
1415
- if (typeof dirty === 'string') {
1416
- IN_PLACE = false;
1417
- }
1418
-
1419
- if (IN_PLACE) {
1420
- /* Do some early pre-sanitization to avoid unsafe root nodes */
1421
- if (dirty.nodeName) {
1422
- const tagName = transformCaseFunc(dirty.nodeName);
1423
-
1424
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1425
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1426
- }
1427
- }
1428
- } else if (dirty instanceof Node) {
1429
- /* If dirty is a DOM element, append to an empty document to avoid
1430
- elements being stripped by the parser */
1431
- body = _initDocument('<!---->');
1432
- importedNode = body.ownerDocument.importNode(dirty, true);
1433
-
1434
- if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
1435
- /* Node is already a body, use as is */
1436
- body = importedNode;
1437
- } else if (importedNode.nodeName === 'HTML') {
1438
- body = importedNode;
1439
- } else {
1440
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1441
- body.appendChild(importedNode);
1442
- }
1443
- } else {
1444
- /* Exit directly if we have nothing to do */
1445
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1446
- dirty.indexOf('<') === -1) {
1447
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1448
- }
1449
- /* Initialize the document to work on */
1450
-
1451
-
1452
- body = _initDocument(dirty);
1453
- /* Check we have a DOM node from the data */
1454
-
1455
- if (!body) {
1456
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1457
- }
1458
- }
1459
- /* Remove first element node (ours) if FORCE_BODY is set */
1460
-
1461
-
1462
- if (body && FORCE_BODY) {
1463
- _forceRemove(body.firstChild);
1464
- }
1465
- /* Get node iterator */
1466
-
1467
-
1468
- const nodeIterator = _createIterator(IN_PLACE ? dirty : body);
1469
- /* Now start iterating over the created document */
1470
-
1471
-
1472
- while (currentNode = nodeIterator.nextNode()) {
1473
- /* Sanitize tags and elements */
1474
- if (_sanitizeElements(currentNode)) {
1475
- continue;
1476
- }
1477
- /* Shadow DOM detected, sanitize it */
1478
-
1479
-
1480
- if (currentNode.content instanceof DocumentFragment) {
1481
- _sanitizeShadowDOM(currentNode.content);
1482
- }
1483
- /* Check attributes, sanitize if necessary */
1484
-
1485
-
1486
- _sanitizeAttributes(currentNode);
1487
- }
1488
- /* If we sanitized `dirty` in-place, return it. */
1489
-
1490
-
1491
- if (IN_PLACE) {
1492
- return dirty;
1493
- }
1494
- /* Return sanitized string or DOM */
1495
-
1496
-
1497
- if (RETURN_DOM) {
1498
- if (RETURN_DOM_FRAGMENT) {
1499
- returnNode = createDocumentFragment.call(body.ownerDocument);
1500
-
1501
- while (body.firstChild) {
1502
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1503
- returnNode.appendChild(body.firstChild);
1504
- }
1505
- } else {
1506
- returnNode = body;
1507
- }
1508
-
1509
- if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmod) {
1510
- /*
1511
- AdoptNode() is not used because internal state is not reset
1512
- (e.g. the past names map of a HTMLFormElement), this is safe
1513
- in theory but we would rather not risk another attack vector.
1514
- The state that is cloned by importNode() is explicitly defined
1515
- by the specs.
1516
- */
1517
- returnNode = importNode.call(originalDocument, returnNode, true);
1518
- }
1519
-
1520
- return returnNode;
1521
- }
1522
-
1523
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1524
- /* Serialize doctype if allowed */
1525
-
1526
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1527
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1528
- }
1529
- /* Sanitize final string template-safe */
1530
-
1531
-
1532
- if (SAFE_FOR_TEMPLATES) {
1533
- serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR, ' ');
1534
- serializedHTML = stringReplace(serializedHTML, ERB_EXPR, ' ');
1535
- serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR, ' ');
1536
- }
1537
-
1538
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1539
- };
1540
- /**
1541
- * Public method to set the configuration once
1542
- * setConfig
1543
- *
1544
- * @param {Object} cfg configuration object
1545
- */
1546
-
1547
-
1548
- DOMPurify.setConfig = function (cfg) {
1549
- _parseConfig(cfg);
1550
-
1551
- SET_CONFIG = true;
1552
- };
1553
- /**
1554
- * Public method to remove the configuration
1555
- * clearConfig
1556
- *
1557
- */
1558
-
1559
-
1560
- DOMPurify.clearConfig = function () {
1561
- CONFIG = null;
1562
- SET_CONFIG = false;
1563
- };
1564
- /**
1565
- * Public method to check if an attribute value is valid.
1566
- * Uses last set config, if any. Otherwise, uses config defaults.
1567
- * isValidAttribute
1568
- *
1569
- * @param {string} tag Tag name of containing element.
1570
- * @param {string} attr Attribute name.
1571
- * @param {string} value Attribute value.
1572
- * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1573
- */
1574
-
1575
-
1576
- DOMPurify.isValidAttribute = function (tag, attr, value) {
1577
- /* Initialize shared config vars if necessary. */
1578
- if (!CONFIG) {
1579
- _parseConfig({});
1580
- }
1581
-
1582
- const lcTag = transformCaseFunc(tag);
1583
- const lcName = transformCaseFunc(attr);
1584
- return _isValidAttribute(lcTag, lcName, value);
1585
- };
1586
- /**
1587
- * AddHook
1588
- * Public method to add DOMPurify hooks
1589
- *
1590
- * @param {String} entryPoint entry point for the hook to add
1591
- * @param {Function} hookFunction function to execute
1592
- */
1593
-
1594
-
1595
- DOMPurify.addHook = function (entryPoint, hookFunction) {
1596
- if (typeof hookFunction !== 'function') {
1597
- return;
1598
- }
1599
-
1600
- hooks[entryPoint] = hooks[entryPoint] || [];
1601
- arrayPush(hooks[entryPoint], hookFunction);
1602
- };
1603
- /**
1604
- * RemoveHook
1605
- * Public method to remove a DOMPurify hook at a given entryPoint
1606
- * (pops it from the stack of hooks if more are present)
1607
- *
1608
- * @param {String} entryPoint entry point for the hook to remove
1609
- * @return {Function} removed(popped) hook
1610
- */
1611
-
1612
-
1613
- DOMPurify.removeHook = function (entryPoint) {
1614
- if (hooks[entryPoint]) {
1615
- return arrayPop(hooks[entryPoint]);
1616
- }
1617
- };
1618
- /**
1619
- * RemoveHooks
1620
- * Public method to remove all DOMPurify hooks at a given entryPoint
1621
- *
1622
- * @param {String} entryPoint entry point for the hooks to remove
1623
- */
1624
-
1625
-
1626
- DOMPurify.removeHooks = function (entryPoint) {
1627
- if (hooks[entryPoint]) {
1628
- hooks[entryPoint] = [];
1629
- }
1630
- };
1631
- /**
1632
- * RemoveAllHooks
1633
- * Public method to remove all DOMPurify hooks
1634
- *
1635
- */
1636
-
1637
-
1638
- DOMPurify.removeAllHooks = function () {
1639
- hooks = {};
1640
- };
1641
-
1642
- return DOMPurify;
1643
- }
1644
-
1645
- var purify = createDOMPurify();
1646
-
1647
54
  function _typeof$1(obj) {
1648
55
  "@babel/helpers - typeof";
1649
56
 
@@ -5342,45 +3749,6 @@ instance.use(Browser).use(initReactI18next).init({
5342
3749
  order: ["navigator"]
5343
3750
  }
5344
3751
  });
5345
- instance.services.formatter.addCached("boldList", function (lng, options) {
5346
- var formatter = new Intl.ListFormat(lng, options);
5347
- var sanitizer = function sanitizer(value) {
5348
- return purify.sanitize(value, {
5349
- USE_PROFILES: {
5350
- html: true
5351
- }
5352
- });
5353
- };
5354
- return function (value) {
5355
- var boldEmails = value.map(function (email) {
5356
- return "<strong>".concat(email, "</strong>");
5357
- });
5358
- var sanitizedEmails = sanitizer(boldEmails).split(",");
5359
- return formatter.format(sanitizedEmails);
5360
- };
5361
- });
5362
-
5363
- var queryClient = new reactQuery.QueryClient({
5364
- queryCache: new reactQuery.QueryCache(),
5365
- defaultOptions: {
5366
- queries: {
5367
- refetchOnWindowFocus: false,
5368
- keepPreviousData: true
5369
- }
5370
- }
5371
- });
5372
-
5373
- var withReactQuery = function withReactQuery(Component) {
5374
- var QueryWrapper = function QueryWrapper(props) {
5375
- return /*#__PURE__*/React__default["default"].createElement(reactQuery.QueryClientProvider, {
5376
- client: queryClient
5377
- }, /*#__PURE__*/React__default["default"].createElement(Component, props), /*#__PURE__*/React__default["default"].createElement(devtools.ReactQueryDevtools, {
5378
- initialIsOpen: false,
5379
- position: "bottom-right"
5380
- }));
5381
- };
5382
- return QueryWrapper;
5383
- };
5384
3752
 
5385
3753
  var MESSAGE_TEMPLATES = {
5386
3754
  email: {
@@ -5414,10 +3782,9 @@ var MESSAGE_TEMPLATE_INITIAL_STATE = {
5414
3782
  template: {}
5415
3783
  };
5416
3784
  var DEFAULT_PAGE_SIZE = 10;
5417
- var DEFAULT_PAGE_INDEX = 1;
5418
3785
  var DEFAULT_PAGE_PROPERTIES = {
5419
3786
  size: DEFAULT_PAGE_SIZE,
5420
- index: DEFAULT_PAGE_INDEX
3787
+ index: constants.DEFAULT_PAGE_INDEX
5421
3788
  };
5422
3789
 
5423
3790
  var MESSAGE_TEMPLATE_BASE_URL = "/neeto_message_templates_engine/api/v1/message_templates";
@@ -5461,14 +3828,14 @@ var messageTemplatesApi = {
5461
3828
  };
5462
3829
 
5463
3830
  var QUERY_KEYS = {
5464
- MESSAGE_TEMPLATE: "message-templates"
3831
+ NEETO_MESSAGE_TEMPLATES: "neeto-message-templates"
5465
3832
  };
5466
3833
 
5467
3834
  var ownerIdValue = function ownerIdValue(ownerId) {
5468
3835
  return ramda.isEmpty(ownerId) ? undefined : ownerId;
5469
3836
  };
5470
3837
  var useFetchTemplates = function useFetchTemplates(params) {
5471
- return reactQuery.useQuery([QUERY_KEYS.MESSAGE_TEMPLATE, params], function () {
3838
+ return reactQuery.useQuery([QUERY_KEYS.NEETO_MESSAGE_TEMPLATES, params], function () {
5472
3839
  return messageTemplatesApi.fetchAll(params);
5473
3840
  });
5474
3841
  };
@@ -5479,7 +3846,7 @@ var useCreateTemplate = function useCreateTemplate(ownerId, options) {
5479
3846
  ownerId: ownerIdValue(ownerId)
5480
3847
  });
5481
3848
  }, {
5482
- keysToInvalidate: [QUERY_KEYS.MESSAGE_TEMPLATE],
3849
+ keysToInvalidate: [QUERY_KEYS.NEETO_MESSAGE_TEMPLATES],
5483
3850
  onSuccess: options === null || options === void 0 ? void 0 : options.onSuccess
5484
3851
  });
5485
3852
  };
@@ -5493,7 +3860,7 @@ var useUpdateTemplate = function useUpdateTemplate(ownerId) {
5493
3860
  ownerId: ownerIdValue(ownerId)
5494
3861
  });
5495
3862
  }, {
5496
- keysToInvalidate: [QUERY_KEYS.MESSAGE_TEMPLATE]
3863
+ keysToInvalidate: [QUERY_KEYS.NEETO_MESSAGE_TEMPLATES]
5497
3864
  });
5498
3865
  };
5499
3866
  var useDeleteTemplate = function useDeleteTemplate(ownerId) {
@@ -5503,7 +3870,7 @@ var useDeleteTemplate = function useDeleteTemplate(ownerId) {
5503
3870
  ownerId: ownerIdValue(ownerId)
5504
3871
  });
5505
3872
  }, {
5506
- keysToInvalidate: [QUERY_KEYS.MESSAGE_TEMPLATE]
3873
+ keysToInvalidate: [QUERY_KEYS.NEETO_MESSAGE_TEMPLATES]
5507
3874
  });
5508
3875
  };
5509
3876
 
@@ -6502,7 +4869,6 @@ var MessageTemplates = function MessageTemplates(_ref) {
6502
4869
  }
6503
4870
  }));
6504
4871
  };
6505
- var index$1 = withReactQuery(MessageTemplates);
6506
4872
 
6507
4873
  var formatEditorContent = function formatEditorContent(value) {
6508
4874
  return value === null || value === void 0 ? void 0 : value.replaceAll(/<\/?(?!img)\w*\b[^>]*>/gi, "").trim();
@@ -6531,18 +4897,19 @@ var WHATSAPP_MESSAGE_FORM_VALIDATIONS_SCHEMA = yup__namespace.object().shape({
6531
4897
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6532
4898
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6533
4899
  var EmailAndSms = function EmailAndSms(_ref) {
6534
- var isEmailTemplate = _ref.isEmailTemplate,
6535
- onClose = _ref.onClose,
4900
+ var onClose = _ref.onClose,
6536
4901
  templates = _ref.templates,
6537
- handleSubmit = _ref.handleSubmit,
6538
4902
  setInitialFocusField = _ref.setInitialFocusField,
6539
4903
  templateVariables = _ref.templateVariables,
6540
4904
  customFields = _ref.customFields,
6541
4905
  customFieldsInitialValues = _ref.customFieldsInitialValues,
6542
- customFieldsValidationSchema = _ref.customFieldsValidationSchema;
4906
+ customFieldsValidationSchema = _ref.customFieldsValidationSchema,
4907
+ type = _ref.type,
4908
+ handleSubmit = _ref.handleSubmit;
6543
4909
  var editorRef = React.useRef(null);
6544
4910
  var _useTranslation = useTranslation(),
6545
4911
  t = _useTranslation.t;
4912
+ var isEmailTemplate = type === "email";
6546
4913
  var _ref2 = isEmailTemplate ? [SEND_MESSAGE_INITIAL_VALUES, EMAIL_MESSAGE_FORM_SCHEMA] : [ramda.pick(["body"], SEND_MESSAGE_INITIAL_VALUES), SMS_MESSAGE_FORM_VALIDATION_SCHEMA],
6547
4914
  _ref3 = _slicedToArray(_ref2, 2),
6548
4915
  INITIAL_VALUES = _ref3[0],
@@ -6561,8 +4928,7 @@ var EmailAndSms = function EmailAndSms(_ref) {
6561
4928
  onSubmit: handleSubmit
6562
4929
  }
6563
4930
  }, function (_ref4) {
6564
- var dirty = _ref4.dirty,
6565
- isSubmitting = _ref4.isSubmitting,
4931
+ var isSubmitting = _ref4.isSubmitting,
6566
4932
  setValues = _ref4.setValues,
6567
4933
  values = _ref4.values;
6568
4934
  var handleTemplateChange = function handleTemplateChange(value) {
@@ -6579,15 +4945,11 @@ var EmailAndSms = function EmailAndSms(_ref) {
6579
4945
  isSearchable: true,
6580
4946
  innerRef: setInitialFocusField,
6581
4947
  label: t("template.title"),
4948
+ options: pure.renameKeys({
4949
+ name: "label",
4950
+ id: "value"
4951
+ }, templates),
6582
4952
  placeholder: t("sendMessage.selectTemplate"),
6583
- options: templates.map(function (_ref5) {
6584
- var name = _ref5.name,
6585
- id = _ref5.id;
6586
- return {
6587
- label: name,
6588
- value: id
6589
- };
6590
- }),
6591
4953
  onChange: handleTemplateChange
6592
4954
  }), customFields, isEmailTemplate && /*#__PURE__*/React__default["default"].createElement(formik$1.Input, {
6593
4955
  required: true,
@@ -6606,7 +4968,7 @@ var EmailAndSms = function EmailAndSms(_ref) {
6606
4968
  }), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Footer, {
6607
4969
  className: "absolute bottom-0 left-0 flex gap-x-2"
6608
4970
  }, /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
6609
- disabled: !dirty || isSubmitting,
4971
+ disabled: isSubmitting,
6610
4972
  label: t("template.send"),
6611
4973
  loading: isSubmitting,
6612
4974
  type: "submit"
@@ -6667,8 +5029,7 @@ var Whatsapp = function Whatsapp(_ref) {
6667
5029
  onSubmit: handleSubmit
6668
5030
  }
6669
5031
  }, function (_ref3) {
6670
- var dirty = _ref3.dirty,
6671
- isSubmitting = _ref3.isSubmitting,
5032
+ var isSubmitting = _ref3.isSubmitting,
6672
5033
  values = _ref3.values,
6673
5034
  setValues = _ref3.setValues;
6674
5035
  var handleTemplateChange = function handleTemplateChange(value) {
@@ -6690,14 +5051,10 @@ var Whatsapp = function Whatsapp(_ref) {
6690
5051
  defaultValue: initialFormValues.selectedTemplate,
6691
5052
  label: t("template.title"),
6692
5053
  name: "selectedTemplate",
6693
- options: templates.map(function (_ref4) {
6694
- var name = _ref4.name,
6695
- id = _ref4.id;
6696
- return {
6697
- label: name,
6698
- value: id
6699
- };
6700
- }),
5054
+ options: pure.renameKeys({
5055
+ name: "label",
5056
+ id: "value"
5057
+ }, templates),
6701
5058
  onChange: handleTemplateChange
6702
5059
  }), /*#__PURE__*/React__default["default"].createElement(neetoui.Textarea, {
6703
5060
  disabled: true,
@@ -6725,7 +5082,7 @@ var Whatsapp = function Whatsapp(_ref) {
6725
5082
  })), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Footer, {
6726
5083
  className: "absolute bottom-0 left-0 flex gap-x-2"
6727
5084
  }, /*#__PURE__*/React__default["default"].createElement(formik$1.Button, {
6728
- disabled: !dirty || isSubmitting,
5085
+ disabled: isSubmitting,
6729
5086
  label: t("template.send"),
6730
5087
  loading: isSubmitting,
6731
5088
  type: "submit"
@@ -6764,6 +5121,7 @@ var SendMessagePane = function SendMessagePane(_ref) {
6764
5121
  return initialFocusField.current = fieldRef;
6765
5122
  };
6766
5123
  var value = MESSAGE_TEMPLATES[type].value;
5124
+ var isWhatsappTemplate = type === "whatsapp";
6767
5125
  var templateParams = {
6768
5126
  status: "active",
6769
5127
  templateType: value,
@@ -6774,8 +5132,6 @@ var SendMessagePane = function SendMessagePane(_ref) {
6774
5132
  _useFetchTemplates$da2 = _useFetchTemplates$da === void 0 ? {} : _useFetchTemplates$da,
6775
5133
  _useFetchTemplates$da3 = _useFetchTemplates$da2.templates,
6776
5134
  templates = _useFetchTemplates$da3 === void 0 ? [] : _useFetchTemplates$da3;
6777
- var isEmailTemplate = type === "email";
6778
- var isWhatsappTemplate = type === "whatsapp";
6779
5135
  return /*#__PURE__*/React__default["default"].createElement(neetoui.Pane, {
6780
5136
  initialFocusRef: initialFocusField,
6781
5137
  isOpen: isOpen,
@@ -6785,22 +5141,21 @@ var SendMessagePane = function SendMessagePane(_ref) {
6785
5141
  weight: "semibold"
6786
5142
  }, t("common.send"), " ", type)), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Body, null, isWhatsappTemplate ? /*#__PURE__*/React__default["default"].createElement(Whatsapp, {
6787
5143
  handleSubmit: handleSubmit,
6788
- templates: templates,
6789
- onClose: onClose
5144
+ onClose: onClose,
5145
+ templates: templates
6790
5146
  }) : /*#__PURE__*/React__default["default"].createElement(EmailAndSms, {
6791
5147
  customFields: customFields,
6792
5148
  customFieldsInitialValues: customFieldsInitialValues,
6793
5149
  customFieldsValidationSchema: customFieldsValidationSchema,
6794
5150
  handleSubmit: handleSubmit,
6795
- isEmailTemplate: isEmailTemplate,
5151
+ onClose: onClose,
6796
5152
  setInitialFocusField: setInitialFocusField,
6797
5153
  templateVariables: templateVariables,
6798
5154
  templates: templates,
6799
- onClose: onClose
5155
+ type: type
6800
5156
  })));
6801
5157
  };
6802
- var index = withReactQuery(SendMessagePane);
6803
5158
 
6804
- exports.MessageTemplates = index$1;
6805
- exports.SendMessagePane = index;
5159
+ exports.MessageTemplates = MessageTemplates;
5160
+ exports.SendMessagePane = SendMessagePane;
6806
5161
  //# sourceMappingURL=index.cjs.js.map