phoenix_duskmoon 9.13.1 → 9.16.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.
@@ -0,0 +1,53 @@
1
+ import React from "react";
2
+ import { JsonSchemaForm } from "@duskmoon-dev/components/json-schema-form";
3
+ import { pathOf } from "./values.js";
4
+
5
+ export function ReactSchemaForm({ disabled, ...props }) {
6
+ return React.createElement(
7
+ "fieldset",
8
+ { disabled },
9
+ React.createElement(JsonSchemaForm, props),
10
+ );
11
+ }
12
+
13
+ // The public renderer reports a whole value tree; preserve the narrowest changed path.
14
+ export function changedPath(previous, next, path = []) {
15
+ if (
16
+ !previous ||
17
+ !next ||
18
+ typeof previous !== "object" ||
19
+ typeof next !== "object"
20
+ )
21
+ return path;
22
+ const keys = [
23
+ ...new Set([...Object.keys(previous), ...Object.keys(next)]),
24
+ ].filter(
25
+ (key) => JSON.stringify(previous[key]) !== JSON.stringify(next[key]),
26
+ );
27
+ return keys.length === 1
28
+ ? changedPath(previous[keys[0]], next[keys[0]], [...path, keys[0]])
29
+ : path;
30
+ }
31
+
32
+ // Accept existing nested/dotted LiveView errors and the renderer's JSON Pointer errors.
33
+ export function schemaErrors(errors, path = [], result = {}) {
34
+ Object.entries(errors || {}).forEach(([key, value]) => {
35
+ const parts = [
36
+ ...path,
37
+ ...(!path.length && !key.startsWith("/") ? pathOf(key) : [key]),
38
+ ];
39
+ const pointer =
40
+ !path.length && (key === "" || key.startsWith("/"))
41
+ ? key
42
+ : `/${parts.map((part) => String(part).replaceAll("~", "~0").replaceAll("/", "~1")).join("/")}`;
43
+ if (typeof value === "string") result[pointer] = value;
44
+ else if (
45
+ Array.isArray(value) &&
46
+ value.every((message) => typeof message === "string")
47
+ ) {
48
+ if (value.length) result[pointer] = value.join("; ");
49
+ } else if (value && typeof value === "object")
50
+ schemaErrors(value, parts, result);
51
+ });
52
+ return result;
53
+ }
@@ -0,0 +1,29 @@
1
+ export function pathOf(name) {
2
+ return Array.isArray(name) ? name : String(name).replace(/\]/g, "").split(/[.[\]]/).filter(Boolean);
3
+ }
4
+
5
+ export function fieldKey(name) { return pathOf(name).join("."); }
6
+
7
+ export function getAt(values, name) {
8
+ return pathOf(name).reduce((current, key) => current?.[key], values);
9
+ }
10
+
11
+ export function setAt(values, name, value) {
12
+ const path = pathOf(name);
13
+ const result = structuredClone(values);
14
+ let current = result;
15
+ path.slice(0, -1).forEach((key) => { current[key] ??= {}; current = current[key]; });
16
+ current[path.at(-1)] = value;
17
+ return result;
18
+ }
19
+
20
+ export function collectValues(elements) {
21
+ return elements.reduce((values, element) => {
22
+ let value;
23
+ if (element.type === "checkbox") value = Boolean(element.checked);
24
+ else if (element.type === "number") value = element.value === "" ? null : Number(element.value);
25
+ else if (element.multiple) value = [...element.selectedOptions].map((option) => option.value);
26
+ else value = element.value;
27
+ return setAt(values, element.name, value);
28
+ }, {});
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phoenix_duskmoon",
3
- "version": "9.13.1",
3
+ "version": "9.16.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./priv/static/assets/js/phoenix_duskmoon.js",
@@ -8,7 +8,9 @@
8
8
  "./css": "./priv/static/assets/css/app.css",
9
9
  "./components": "./priv/static/assets/css/app.css",
10
10
  "./svg/mdi/*.svg": "./priv/mdi/svg/*.svg",
11
- "./svg/bsi/*.svg": "./priv/bsi/svg/*.svg"
11
+ "./svg/bsi/*.svg": "./priv/bsi/svg/*.svg",
12
+ "./react-form": "./assets/js/react_form/index.js",
13
+ "./react-chat": "./assets/js/react_chat/index.js"
12
14
  },
13
15
  "scripts": {
14
16
  "build": "mix duskmoon_bundler.build phoenix_duskmoon",
@@ -35,15 +37,18 @@
35
37
  "registry": "https://registry.npmjs.org/"
36
38
  },
37
39
  "dependencies": {
38
- "@duskmoon-dev/art-elements": "1.7.2",
39
- "@duskmoon-dev/core": "1.18.1",
40
- "@duskmoon-dev/css-art": "1.18.1",
41
- "@duskmoon-dev/elements": "1.7.2"
40
+ "@duskmoon-dev/art-elements": "1.8.1",
41
+ "@duskmoon-dev/components": "0.4.1",
42
+ "@duskmoon-dev/core": "1.20.3",
43
+ "@duskmoon-dev/css-art": "1.20.3",
44
+ "@duskmoon-dev/elements": "1.8.1",
45
+ "react": "19.3.0",
46
+ "react-dom": "19.3.0"
42
47
  },
43
48
  "devDependencies": {
44
49
  "@mdi/svg": "7.4.47",
45
50
  "bootstrap-icons": "1.13.1",
46
- "postcss": "8.5.26"
51
+ "postcss": "8.5.28"
47
52
  },
48
53
  "peerDependencies": {
49
54
  "tailwindcss": "^4.3.2"