Skip to content
Snippets Groups Projects
Verified Commit 7e63f288 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new calendar control #296

parent 3b9b2861
No related branches found
No related tags found
No related merge requests found
...@@ -33,19 +33,19 @@ class DataFetchError extends Error { ...@@ -33,19 +33,19 @@ class DataFetchError extends Error {
constructor(message, response) { constructor(message, response) {
super(message); super(message);
let body = null let body = null;
if (response instanceof Response) { if (response instanceof Response) {
body = response.text(); body = response.text();
} }
if(!(body instanceof Promise)) { if (!(body instanceof Promise)) {
body = Promise.resolve(body); body = Promise.resolve(body);
} }
this[internalSymbol] = { this[internalSymbol] = {
response: response, response: response,
body : body body: body,
}; };
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* SPDX-License-Identifier: AGPL-3.0 * SPDX-License-Identifier: AGPL-3.0
*/ */
export {parseBracketedKeyValueHash, createBracketedKeyValueHash}; export { parseBracketedKeyValueHash, createBracketedKeyValueHash };
/** /**
* Parses a string containing bracketed key-value pairs and returns an object representing the parsed result. * Parses a string containing bracketed key-value pairs and returns an object representing the parsed result.
...@@ -51,155 +51,155 @@ export {parseBracketedKeyValueHash, createBracketedKeyValueHash}; ...@@ -51,155 +51,155 @@ export {parseBracketedKeyValueHash, createBracketedKeyValueHash};
* @return {Object} - An object representing the parsed result, with keys representing the selectors and values representing the key-value pairs associated with each selector. * @return {Object} - An object representing the parsed result, with keys representing the selectors and values representing the key-value pairs associated with each selector.
* - Returns an empty object if there was an error during parsing. */ * - Returns an empty object if there was an error during parsing. */
function parseBracketedKeyValueHash(hashString) { function parseBracketedKeyValueHash(hashString) {
const selectors = {}; const selectors = {};
//const selectorStack = []; //const selectorStack = [];
//const keyValueStack = []; //const keyValueStack = [];
const trimmedHashString = hashString.trim(); const trimmedHashString = hashString.trim();
const cleanedHashString = const cleanedHashString =
trimmedHashString.charAt(0) === "#" trimmedHashString.charAt(0) === "#"
? trimmedHashString.slice(1) ? trimmedHashString.slice(1)
: trimmedHashString; : trimmedHashString;
//const selectors = (keyValueStack.length > 0) ? result[selectorStack[selectorStack.length - 1]] : result; //const selectors = (keyValueStack.length > 0) ? result[selectorStack[selectorStack.length - 1]] : result;
let currentSelector = ""; let currentSelector = "";
function addToResult(key, value) { function addToResult(key, value) {
if (currentSelector && key) { if (currentSelector && key) {
if (!selectors[currentSelector]) { if (!selectors[currentSelector]) {
selectors[currentSelector] = {}; selectors[currentSelector] = {};
} }
selectors[currentSelector][key] = value; selectors[currentSelector][key] = value;
} }
} }
let currentKey = ""; let currentKey = "";
let currentValue = ""; let currentValue = "";
let inKey = true; let inKey = true;
let inValue = false; let inValue = false;
let inQuotedValue = false; let inQuotedValue = false;
let inSelector = true; let inSelector = true;
let escaped = false; let escaped = false;
let quotedValueStartChar = ""; let quotedValueStartChar = "";
for (let i = 0; i < cleanedHashString.length; i++) { for (let i = 0; i < cleanedHashString.length; i++) {
const c = cleanedHashString[i]; const c = cleanedHashString[i];
const nextChar = cleanedHashString?.[i + 1]; const nextChar = cleanedHashString?.[i + 1];
if (c === "\\" && !escaped) { if (c === "\\" && !escaped) {
escaped = true; escaped = true;
continue; continue;
} }
if (escaped) { if (escaped) {
if (inSelector) { if (inSelector) {
currentSelector += c; currentSelector += c;
} else if (inKey) { } else if (inKey) {
currentKey += c; currentKey += c;
} else if (inValue) { } else if (inValue) {
currentValue += c; currentValue += c;
} }
escaped = false; escaped = false;
continue; continue;
} }
if (inQuotedValue && quotedValueStartChar !== c) { if (inQuotedValue && quotedValueStartChar !== c) {
if (inSelector) { if (inSelector) {
currentSelector += c; currentSelector += c;
} else if (inKey) { } else if (inKey) {
currentKey += c; currentKey += c;
} else if (inValue) { } else if (inValue) {
currentValue += c; currentValue += c;
} }
continue; continue;
} }
if (c === ";" && inSelector) { if (c === ";" && inSelector) {
inSelector = true; inSelector = true;
currentSelector = ""; currentSelector = "";
continue; continue;
} }
if (inSelector === true && c !== "(") { if (inSelector === true && c !== "(") {
currentSelector += c; currentSelector += c;
continue; continue;
} }
if (c === "(" && inSelector) { if (c === "(" && inSelector) {
inSelector = false; inSelector = false;
inKey = true; inKey = true;
currentKey = ""; currentKey = "";
continue; continue;
} }
if (inKey === true && c !== "=") { if (inKey === true && c !== "=") {
currentKey += c; currentKey += c;
continue; continue;
} }
if (c === "=" && inKey) { if (c === "=" && inKey) {
inKey = false; inKey = false;
inValue = true; inValue = true;
if (nextChar === '"' || nextChar === "'") { if (nextChar === '"' || nextChar === "'") {
inQuotedValue = true; inQuotedValue = true;
quotedValueStartChar = nextChar; quotedValueStartChar = nextChar;
i++; i++;
continue; continue;
} }
currentValue = ""; currentValue = "";
continue; continue;
} }
if (inValue === true) { if (inValue === true) {
if (inQuotedValue) { if (inQuotedValue) {
if (c === quotedValueStartChar) { if (c === quotedValueStartChar) {
inQuotedValue = false; inQuotedValue = false;
continue; continue;
} }
currentValue += c; currentValue += c;
continue; continue;
} }
if (c === ",") { if (c === ",") {
inValue = false; inValue = false;
inKey = true; inKey = true;
const decodedCurrentValue = decodeURIComponent(currentValue); const decodedCurrentValue = decodeURIComponent(currentValue);
addToResult(currentKey, decodedCurrentValue); addToResult(currentKey, decodedCurrentValue);
currentKey = ""; currentKey = "";
currentValue = ""; currentValue = "";
continue; continue;
} }
if (c === ")") { if (c === ")") {
inValue = false; inValue = false;
//inKey = true; //inKey = true;
inSelector = true; inSelector = true;
const decodedCurrentValue = decodeURIComponent(currentValue); const decodedCurrentValue = decodeURIComponent(currentValue);
addToResult(currentKey, decodedCurrentValue); addToResult(currentKey, decodedCurrentValue);
currentKey = ""; currentKey = "";
currentValue = ""; currentValue = "";
currentSelector = ""; currentSelector = "";
continue; continue;
} }
currentValue += c; currentValue += c;
continue; continue;
} }
} }
if (inSelector) { if (inSelector) {
return selectors; return selectors;
} }
return {}; return {};
} }
/** /**
...@@ -211,41 +211,41 @@ function parseBracketedKeyValueHash(hashString) { ...@@ -211,41 +211,41 @@ function parseBracketedKeyValueHash(hashString) {
* @since 3.37.0 * @since 3.37.0
*/ */
function createBracketedKeyValueHash(object, addHashPrefix = true) { function createBracketedKeyValueHash(object, addHashPrefix = true) {
if (!object) { if (!object) {
return addHashPrefix ? "#" : ""; return addHashPrefix ? "#" : "";
} }
let hashString = ""; let hashString = "";
function encodeKeyValue(key, value) { function encodeKeyValue(key, value) {
return encodeURIComponent(key) + "=" + encodeURIComponent(value); return encodeURIComponent(key) + "=" + encodeURIComponent(value);
} }
for (const selector in object) { for (const selector in object) {
if (object.hasOwnProperty(selector)) { if (object.hasOwnProperty(selector)) {
const keyValuePairs = object[selector]; const keyValuePairs = object[selector];
let selectorString = selector; let selectorString = selector;
let keyValueString = ""; let keyValueString = "";
for (const key in keyValuePairs) { for (const key in keyValuePairs) {
if (keyValuePairs.hasOwnProperty(key)) { if (keyValuePairs.hasOwnProperty(key)) {
const value = keyValuePairs[key]; const value = keyValuePairs[key];
keyValueString += keyValueString.length === 0 ? "" : ","; keyValueString += keyValueString.length === 0 ? "" : ",";
keyValueString += encodeKeyValue(key, value); keyValueString += encodeKeyValue(key, value);
} }
} }
if (keyValueString.length > 0) { if (keyValueString.length > 0) {
selectorString += "(" + keyValueString + ")"; selectorString += "(" + keyValueString + ")";
hashString += hashString.length === 0 ? "" : ";"; hashString += hashString.length === 0 ? "" : ";";
hashString += selectorString; hashString += selectorString;
} }
} }
} }
if (hashString.length>0 && addHashPrefix) { if (hashString.length > 0 && addHashPrefix) {
hashString = "#" + hashString; hashString = "#" + hashString;
} }
return hashString; return hashString;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment