diff --git a/blog/2024-05-06-symfony-libs.mdx b/blog/2024-05-06-symfony-libs.mdx index 92e7c5c..c8a90b7 100644 --- a/blog/2024-05-06-symfony-libs.mdx +++ b/blog/2024-05-06-symfony-libs.mdx @@ -22,7 +22,7 @@ Also the TS docs were updated: - [Dune DOM helpers] are now documented. -[Dune DOM helpers]: /docs/ts-scss/dune/dom +[Dune DOM helpers]: /docs/ts-scss/dune/helpers [HTML Builder]: /docs/php/library/html-builder [Simple Normalizer]: /docs/php/symfony/simple-normalizer [Task Manager]: /docs/php/symfony/task-manager diff --git a/blog/2024-05-07-dune-docs.mdx b/blog/2024-05-07-dune-docs.mdx index 8e189c0..355e697 100644 --- a/blog/2024-05-07-dune-docs.mdx +++ b/blog/2024-05-07-dune-docs.mdx @@ -7,6 +7,10 @@ tags: [dune] The [Dune] docs were finalized: - [DOM Attribute helpers] are now documented. +- [JSON helpers] are now documented. +- [Network helpers] are now documented. +- [Popup Interaction helpers] are now documented. +- [Timing helpers] are now documented. - [Usercentrics] component and hooks is documented. - [HTTP Basic Auth middleware] is documented. - [Media Query Hooks] are documented. @@ -14,8 +18,12 @@ The [Dune] docs were finalized: [Debounce Hook]: /docs/ts-scss/dune/react/debounce +[DOM Attribute helpers]: /docs/ts-scss/dune/helpers#dom-attribute [Dune]: /docs/ts-scss/dune -[DOM Attribute helpers]: /docs/ts-scss/dune/dom#html-attributes [HTTP Basic Auth middleware]: /docs/ts-scss/dune/react/http-auth +[JSON helpers]: /docs/ts-scss/dune/helpers#json [Media Query Hooks]: /docs/ts-scss/dune/react/media-query +[Network helpers]: /docs/ts-scss/dune/helpers#network +[Popup Interaction helpers]: /docs/ts-scss/dune/helpers#popup-interaction +[Timing helpers]: /docs/ts-scss/dune/helpers#timing [Usercentrics]: /docs/ts-scss/dune/react/usercentrics diff --git a/docs/ts-scss/dune/dom.mdx b/docs/ts-scss/dune/helpers.mdx similarity index 57% rename from docs/ts-scss/dune/dom.mdx rename to docs/ts-scss/dune/helpers.mdx index dadb736..a7f380e 100644 --- a/docs/ts-scss/dune/dom.mdx +++ b/docs/ts-scss/dune/helpers.mdx @@ -1,8 +1,7 @@ -# DOM Helpers +# Helpers -The library contains several helper functions for working with the DOM. -## HTML Attributes +## DOM Attribute ### `toggleClass()` @@ -17,7 +16,77 @@ A helper, where you can control via the `addClass` parameter whether to add or r -## Events +## DOM Traversal + +### `findFirst()` + +```typescript +findFirst(selector, context) +``` + +Small wrapper around `querySelector()`. Pass the container as `context` you want to search in, by default `document` is used. + + +### `find()` + +```typescript +find(selector, context) +``` + +Wrapper around `querySelectorAll`, always returns a (real) array. Pass the container as `context` you want to search in, by default `document` is used. + + +### `children()` + +```typescript +children(parent, selector = null) +``` + +Returns all children elements of the given `parent`. Can be directly filtered by the given selector. + + +### `prev()` + +```typescript +prev(element, selector = null) +``` + +Returns all previous siblings, optionally only those matching a given selector. Excludes the `element` itself. + + +### `next()` + +```typescript +next(element, selector = null) +``` + +Returns all following siblings, optionally only those matching a given selector. Excludes the `element` itself. + + +### `closest()` + +```typescript +closest(element, selector, rootElement = null) +``` + +Finds the nearest parent that matches the given selector. The element itself is **included**, if it matches. + +You can optionally pass a maximum root element, where the search should stop, so that you can contain the search to a specific subtree. + + +### `isChildOf()` + +```typescript +isChildOf(parent, node) +``` + +Checks, whether the given `node` is a child of the `parent`. + +Will return `true` if both parameters are the same node. + + + +## Event ### `on()` @@ -150,70 +219,145 @@ trigger(button, "click", { ``` -## DOM Traversal -### `findFirst()` +## JSON + +### `safeParseJson()` ```typescript -findFirst(selector, context) +safeParseJson(value) ``` -Small wrapper around `querySelector()`. Pass the container as `context` you want to search in, by default `document` is used. +Parses the given value as JSON and returns it cast as the `DataType`. +:::caution +This function doesn't validate the data in any way. It is recommended to use zod to validate the schema. +::: -### `find()` + +### `parseElementContentAsJson()` ```typescript -find(selector, context) +parseElementContentAsJson(element) ``` -Wrapper around `querySelectorAll`, always returns a (real) array. Pass the container as `context` you want to search in, by default `document` is used. +Uses the text content of the given element, parses it as JSON and returns the parsed json. +This is especially useful when hydrating `